6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
10 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
11 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
12 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
13 external clearmark
: opaque
-> unit = "ml_clearmark";;
14 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
15 external getmaxw
: unit -> float = "ml_getmaxw";;
16 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
17 external measurestr
: int -> string -> float = "ml_measure_string";;
18 external postprocess
:
19 opaque
-> int -> int -> int -> (int * string * int) -> int
21 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
22 external setaalevel
: int -> unit = "ml_setaalevel";;
23 external realloctexts
: int -> bool = "ml_realloctexts";;
24 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
25 external getlink
: opaque
-> int -> under
= "ml_getlink";;
26 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
27 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
28 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
29 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
30 external freepbo
: opaque
-> unit = "ml_freepbo";;
31 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
32 external bousable
: unit -> bool = "ml_bo_usable";;
33 external unproject
: opaque
-> int -> int -> (int * int) option
35 external project
: opaque
-> int -> int -> float -> float -> (float * float)
37 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
38 external rectofblock
: opaque
-> int -> int -> float array
option
40 external begintiles
: unit -> unit = "ml_begintiles";;
41 external endtiles
: unit -> unit = "ml_endtiles";;
42 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
43 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
44 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
45 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
46 external savedoc
: string -> unit = "ml_savedoc";;
47 external getannotcontents
: opaque
-> slinkindex
-> string
48 = "ml_getannotcontents";;
49 external drawprect
: opaque
-> int -> int -> float array
-> unit
51 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
52 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
53 external uritolocation
: string -> (pageno
* float * float)
54 = "ml_uritolocation";;
55 external isexternallink
: string -> bool = "ml_isexternallink";;
57 let selfexec = ref E.s
;;
58 let opengl_has_pbo = ref false;;
60 let drawstring size x y s
=
62 Gl.enable `texture_2d
;
63 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
64 ignore
(drawstr size x y s
);
66 Gl.disable `texture_2d
;
69 let drawstring1 size x y s
=
73 let drawstring2 size x y fmt
=
74 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
77 module UniSyms
= struct
78 let ellipsis = "\xe2\x80\xa6";;
79 let radical = "\xe2\x88\x9a";;
80 let lguillemet = "\xc2\xab";;
81 let rguillemet = "\xc2\xbb";;
96 l
.pagedispx l
.pagedispy
100 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
106 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
109 let isbirdseye = function
111 | Textentry _
| View
| LinkNav _
-> false
114 let istextentry = function
115 | Textentry _
-> true
116 | Birdseye _
| View
| LinkNav _
-> false
119 let wtmode = ref false;;
120 let cxack = ref false;;
122 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
125 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
126 && (state
.w
> state
.winw
))
132 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
133 && (state
.maxy
> state
.winh
))
141 else x
> state
.winw
- vscrollw ()
145 fstate
.fontsize
<- n
;
146 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
147 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
153 else Printf.kprintf ignore fmt
157 if emptystr conf
.pathlauncher
158 then dolog
"%s" state
.path
160 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
161 match spawn
command [] with
164 dolog
"failed to execute `%s': %s" command @@ exntos exn
170 let postRedisplay who
=
171 vlog "redisplay for [%S]" who
;
172 state
.redisplay
<- true;
176 let getopaque pageno
=
177 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
178 with Not_found
-> None
181 let pagetranslatepoint l x y
=
182 let dy = y
- l
.pagedispy
in
183 let y = dy + l
.pagey
in
184 let dx = x
- l
.pagedispx
in
185 let x = dx + l
.pagex
in
189 let onppundermouse g
x y d
=
192 begin match getopaque l
.pageno
with
194 let x0 = l
.pagedispx
in
195 let x1 = x0 + l
.pagevw
in
196 let y0 = l
.pagedispy
in
197 let y1 = y0 + l
.pagevh
in
198 if y >= y0 && y <= y1 && x >= x0 && x <= x1
200 let px, py
= pagetranslatepoint l
x y in
201 match g opaque l
px py
with
214 let g opaque l
px py
=
217 match rectofblock opaque
px py
with
218 | Some
[|x0;x1;y0;y1|] ->
219 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
220 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
221 state
.rects
<- [l
.pageno
, color, rect];
222 G.postRedisplay "getunder";
225 let under = whatsunder opaque
px py
in
226 if under = Unone
then None
else Some
under
228 onppundermouse g x y Unone
233 match unproject opaque
x y with
234 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
237 onppundermouse g x y None
;
241 state
.text
<- Printf.sprintf
"%c%s" c s
;
242 G.postRedisplay "showtext";
246 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
249 let pipesel opaque cmd
=
252 match Unix.pipe
() with
253 | exception exn
-> dolog
"pipesel cannot create pipe: %S" @@ exntos exn
;
255 let doclose what fd
=
256 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
258 begin match spawn cmd
[r
, 0; w
, -1] with
260 doclose "pipesel pipe/w" w
;
261 dolog
"cannot execute %S: %s" cmd
@@ exntos exn
264 G.postRedisplay "pipesel";
266 doclose "pipesel pipe/r" r
;
270 let g opaque l
px py
=
271 if markunder opaque
px py conf
.paxmark
274 match getopaque l
.pageno
with
276 | Some opaque
-> pipesel opaque conf
.paxcmd
281 G.postRedisplay "paxunder";
282 if conf
.paxmark
= Mark_page
285 match getopaque l
.pageno
with
287 | Some opaque
-> clearmark opaque
) state
.layout
;
288 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
292 match Unix.pipe
() with
293 | exception exn
-> impmsg "pipe failed: %s" @@ exntos exn
296 Ne.clo fd
(fun msg
-> impmsg "failed to close %s: %s" cap msg
)
298 begin match spawn conf
.selcmd
[r
, 0; w
, -1] with
300 clo "selstring pipe/w" w
;
301 impmsg "failed to execute %s: %s" conf
.selcmd
@@ exntos exn
304 let l = String.length s
in
305 let bytes = Bytes.unsafe_of_string s
in
306 let n = tempfailureretry
(Unix.write w
bytes 0) l in
308 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n
309 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
311 clo "selstring pipe/r" r
;
314 let undertext = function
317 | Utext s
-> "font: " ^ s
318 | Uannotation
(opaque
, slinkindex
) ->
319 "annotation: " ^ getannotcontents opaque slinkindex
322 let updateunder x y =
323 match getunder x y with
324 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
326 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
327 Wsi.setcursor
Wsi.CURSOR_INFO
329 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
330 Wsi.setcursor
Wsi.CURSOR_TEXT
332 if conf
.underinfo
then showtext 'a'
"nnotation";
333 Wsi.setcursor
Wsi.CURSOR_INFO
336 let showlinktype under =
337 if conf
.underinfo
&& under != Unone
338 then showtext ' '
@@ undertext under
341 let [@warning
"-4"] intentry_with_suffix text key
=
344 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
345 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
346 addchar
text @@ asciilower c
348 state
.text <- Printf.sprintf
"invalid key";
355 let b = Buffer.create
16 in
358 let b = Buffer.to_bytes
b in
359 wcmd state
.ss
b @@ Bytes.length
b
363 let nogeomcmds cmds
=
365 | s
, [] -> emptystr s
369 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
370 let rec fold accu
n =
371 if n = Array.length
b
374 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
377 || n = state
.pagecount
- coverB
378 || (n - coverA
) mod columns
= columns
- 1)
384 let pagey = max
0 (y - vy
) in
385 let pagedispy = if pagey > 0 then 0 else vy
- y in
386 let pagedispx, pagex
=
388 if n = coverA
- 1 || n = state
.pagecount
- coverB
389 then x + (sw
- w
) / 2
397 let vw = sw
- pagedispx in
398 let pw = w
- pagex
in
401 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
402 if pagevw > 0 && pagevh > 0
413 ; pagedispx = pagedispx
414 ; pagedispy = pagedispy
426 if Array.length
b = 0
428 else List.rev
(fold [] (page_of_y
y))
431 let layoutS (columns
, b) x y sw sh
=
432 let rec fold accu n =
433 if n = Array.length
b
436 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
444 let pagey = max
0 (y - vy
) in
445 let pagedispy = if pagey > 0 then 0 else vy
- y in
446 let pagedispx, pagex
=
460 let pagecolw = pagew
/columns
in
463 then pagedispx + ((sw
- pagecolw) / 2)
467 let vw = sw
- pagedispx in
468 let pw = pagew
- pagex
in
471 let pagevw = min
pagevw pagecolw in
472 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
473 if pagevw > 0 && pagevh > 0
484 ; pagedispx = pagedispx
485 ; pagedispy = pagedispy
486 ; pagecol
= n mod columns
500 let layout x y sw sh
=
501 if nogeomcmds state
.geomcmds
503 match conf
.columns
with
504 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
505 | Cmulti c
-> layoutN c
x y sw sh
506 | Csplit s
-> layoutS s
x y sw sh
511 let y = state
.y + incr
in
513 let y = min
y (state
.maxy
- (if conf
.maxhfit
then state
.winh
else 0)) in
518 let tilex = l.pagex
mod conf
.tilew
in
519 let tiley = l.pagey mod conf
.tileh
in
521 let col = l.pagex
/ conf
.tilew
in
522 let row = l.pagey / conf
.tileh
in
524 let rec rowloop row y0 dispy h
=
528 let dh = conf
.tileh
- y0 in
530 let rec colloop col x0 dispx w
=
534 let dw = conf
.tilew
- x0 in
536 f col row dispx dispy
x0 y0 dw dh;
537 colloop (col+1) 0 (dispx
+dw) (w
-dw)
540 colloop col tilex l.pagedispx l.pagevw;
541 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
544 if l.pagevw > 0 && l.pagevh > 0
545 then rowloop row tiley l.pagedispy l.pagevh;
548 let gettileopaque l col row =
550 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
552 try Some
(Hashtbl.find state
.tilemap
key)
553 with Not_found
-> None
556 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
557 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
558 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
561 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
562 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
563 GlArray.vertex `two state
.vraw
;
564 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
567 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
569 let filledrect x0 y0 x1 y1 =
570 GlArray.disable `texture_coord
;
571 filledrect1 x0 y0 x1 y1;
572 GlArray.enable `texture_coord
;
575 let linerect x0 y0 x1 y1 =
576 GlArray.disable `texture_coord
;
577 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
578 GlArray.vertex `two state
.vraw
;
579 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
580 GlArray.enable `texture_coord
;
583 let drawtiles l color =
586 let f col row x y tilex tiley w h
=
587 match gettileopaque l col row with
588 | Some
(opaque
, _
, t
) ->
589 let params = x, y, w
, h
, tilex, tiley in
591 then GlTex.env
(`mode `blend
);
592 drawtile
params opaque
;
594 then GlTex.env
(`mode `modulate
);
598 let s = Printf.sprintf
602 let w = measurestr fstate
.fontsize
s in
603 GlDraw.color (0.0, 0.0, 0.0);
604 filledrect (float (x-2))
607 (float (y + fstate
.fontsize
+ 2));
609 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
616 let lw = state
.winw
- x in
619 let lh = state
.winh
- y in
623 then GlTex.env
(`mode `blend
);
624 begin match state
.checkerstexid
with
626 Gl.enable `texture_2d
;
627 GlTex.bind_texture ~target
:`texture_2d id
;
631 and y1 = float (y+h
) in
633 let tw = float w /. 16.0
634 and th
= float h
/. 16.0 in
635 let tx0 = float tilex /. 16.0
636 and ty0
= float tiley /. 16.0 in
638 and ty1
= ty0
+. th
in
639 Raw.sets_float state
.vraw ~pos
:0
640 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
641 Raw.sets_float state
.traw ~pos
:0
642 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
643 GlArray.vertex `two state
.vraw
;
644 GlArray.tex_coord `two state
.traw
;
645 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
646 Gl.disable `texture_2d
;
649 GlDraw.color (1.0, 1.0, 1.0);
650 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
653 then GlTex.env
(`mode `modulate
);
654 if w > 128 && h
> fstate
.fontsize
+ 10
656 let c = if conf
.invert
then 1.0 else 0.0 in
657 GlDraw.color (c, c, c);
660 then (col*conf
.tilew
, row*conf
.tileh
)
663 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
672 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
674 let tilevisible1 l x y =
676 and ax1
= l.pagex
+ l.pagevw
678 and ay1
= l.pagey + l.pagevh in
682 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
683 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
685 let rx0 = max
ax0 bx0
686 and ry0
= max ay0 by0
687 and rx1
= min ax1
bx1
688 and ry1
= min ay1 by1
in
690 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
694 let tilevisible layout n x y =
695 let rec findpageinlayout m
= function
696 | l :: rest
when l.pageno
= n ->
697 tilevisible1 l x y || (
698 match conf
.columns
with
699 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
700 | Csplit _
| Csingle _
| Cmulti _
-> false
702 | _
:: rest
-> findpageinlayout 0 rest
705 findpageinlayout 0 layout;
708 let tileready l x y =
709 tilevisible1 l x y &&
710 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
713 let tilepage n p
layout =
714 let rec loop = function
718 let f col row _ _ _ _ _ _
=
719 if state
.currently
= Idle
721 match gettileopaque l col row with
724 let x = col*conf
.tilew
725 and y = row*conf
.tileh
in
727 let w = l.pagew
- x in
731 let h = l.pageh
- y in
736 then getpbo
w h conf
.colorspace
739 wcmd "tile %s %d %d %d %d %s"
740 (~
> p
) x y w h (~
> pbo);
743 l, p
, conf
.colorspace
, conf
.angle
,
744 state
.gen
, col, row, conf
.tilew
, conf
.tileh
753 if nogeomcmds state
.geomcmds
757 let preloadlayout x y sw sh
=
758 let y = if y < sh
then 0 else y - sh
in
759 let x = min
0 (x + sw
) in
767 if state
.currently
!= Idle
772 begin match getopaque l.pageno
with
774 wcmd "page %d %d" l.pageno
l.pagedimno
;
775 state
.currently
<- Loading
(l, state
.gen
);
777 tilepage l.pageno opaque pages
;
782 if nogeomcmds state
.geomcmds
788 if conf
.preload && state
.currently
= Idle
789 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
792 let layoutready layout =
793 let rec fold all ls
=
796 let seen = ref false in
797 let allvisible = ref true in
798 let foo col row _ _ _ _ _ _
=
800 allvisible := !allvisible &&
801 begin match gettileopaque l col row with
807 fold (!seen && !allvisible) rest
810 let alltilesvisible = fold true layout in
815 let y = bound
y 0 state
.maxy
in
816 let y, layout, proceed
=
817 match conf
.maxwait
with
818 | Some time
when state
.ghyll
== noghyll
->
819 begin match state
.throttle
with
821 let layout = layout x y state
.winw state
.winh
in
822 let ready = layoutready layout in
826 state
.throttle
<- Some
(layout, y, now
());
828 else G.postRedisplay "gotoxy showall (None)";
830 | Some
(_
, _
, started
) ->
831 let dt = now
() -. started
in
834 state
.throttle
<- None
;
835 let layout = layout x y state
.winw state
.winh
in
837 G.postRedisplay "maxwait";
844 let layout = layout x y state
.winw state
.winh
in
845 if not
!wtmode || layoutready layout
846 then G.postRedisplay "gotoxy ready";
853 state
.layout <- layout;
854 begin match state
.mode
with
857 | Ltexact
(pageno
, linkno
) ->
858 let rec loop = function
860 state
.lnava
<- Some
(pageno
, linkno
);
861 state
.mode
<- LinkNav
(Ltgendir
0)
862 | l :: _
when l.pageno
= pageno
->
863 begin match getopaque pageno
with
864 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
866 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
867 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
868 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
869 then state
.mode
<- LinkNav
(Ltgendir
0)
871 | _
:: rest
-> loop rest
874 | Ltnotready _
| Ltgendir _
-> ()
876 | Birdseye _
| Textentry _
| View
-> ()
878 begin match state
.mode
with
879 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
880 if not
(pagevisible layout pageno
)
882 match state
.layout with
885 state
.mode
<- Birdseye
(
886 conf
, leftx
, l.pageno
, hooverpageno
, anchor
891 | Ltnotready
(_
, dir
)
894 let rec loop = function
897 match getopaque l.pageno
with
898 | None
-> Ltnotready
(l.pageno
, dir
)
903 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
905 if dir
> 0 then LDfirst
else LDlast
911 | Lnotfound
-> loop rest
913 showlinktype (getlink opaque
n);
914 Ltexact
(l.pageno
, n)
918 state
.mode
<- LinkNav
linknav
921 | Textentry _
| View
-> ()
925 state
.ghyll
<- noghyll
;
928 let mx, my
= state
.mpos
in
933 let conttiling pageno opaque
=
934 tilepage pageno opaque
936 then preloadlayout state
.x state
.y state
.winw state
.winh
940 let gotoxy_and_clear_text x y =
941 if not conf
.verbose
then state
.text <- E.s;
945 let getanchory (n, top
, dtop
) =
946 let y, h = getpageyh
n in
949 let ips = calcips
h in
950 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
952 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
955 let gotoanchor anchor
=
956 gotoxy state
.x (getanchory anchor
);
960 cbput state
.hists
.nav
(getanchor
());
964 let anchor = cbgetc state
.hists
.nav dir
in
968 let gotoghyll1 single
y =
970 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
972 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
974 then s (float f /. float a
)
977 then 1.0 -. s ((float (f-b) /. float (n-b)))
983 let ins = float a
*. 0.5
984 and outs
= float (n-b) *. 0.5 in
986 ins +. outs
+. float ones
988 let rec set nab
y sy
=
989 let (_N
, _A
, _B
), y =
992 let scl = if y > sy
then 2 else -2 in
993 let _N, _
, _
= nab
in
994 (_N,0,_N), y+conf
.scrollstep
*scl
996 let sum = summa
_N _A _B
in
997 let dy = float (y - sy
) in
1001 then state
.ghyll
<- noghyll
1004 let s = scroll n _N _A _B
in
1005 let y1 = y1 +. ((s *. dy) /. sum) in
1006 gotoxy_and_clear_text state
.x (truncate
y1);
1007 state
.ghyll
<- gf (n+1) y1;
1011 | Some
y'
when single
-> set nab
y' state
.y
1012 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1014 gf 0 (float state
.y)
1017 match conf
.ghyllscroll
with
1018 | Some nab
when not conf
.presentation
->
1019 if state
.ghyll
== noghyll
1020 then set nab
y state
.y
1021 else state
.ghyll
(Some
y)
1023 gotoxy_and_clear_text state
.x y
1026 let gotoghyll = gotoghyll1 false;;
1028 let gotopage n top
=
1029 let y, h = getpageyh
n in
1030 let y = y + (truncate
(top
*. float h)) in
1034 let gotopage1 n top
=
1035 let y = getpagey
n in
1040 let invalidate s f =
1041 state
.redisplay
<- false;
1046 match state
.geomcmds
with
1047 | ps
, [] when emptystr ps
->
1049 state
.geomcmds
<- s, [];
1052 state
.geomcmds
<- ps
, [s, f];
1054 | ps
, (s'
, _
) :: rest
when s'
= s ->
1055 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1058 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1062 Hashtbl.iter
(fun _ opaque
->
1063 wcmd "freepage %s" (~
> opaque
);
1065 Hashtbl.clear state
.pagemap
;
1069 if not
(Queue.is_empty state
.tilelru
)
1071 Queue.iter
(fun (k
, p
, s) ->
1072 wcmd "freetile %s" (~
> p
);
1073 state
.memused
<- state
.memused
- s;
1074 Hashtbl.remove state
.tilemap k
;
1076 state
.uioh#infochanged Memused
;
1077 Queue.clear state
.tilelru
;
1083 let h = truncate
(float h*.conf
.zoom
) in
1084 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1088 let opendoc path password
=
1090 state
.password
<- password
;
1091 state
.gen
<- state
.gen
+ 1;
1092 state
.docinfo
<- [];
1093 state
.outlines
<- [||];
1096 setaalevel conf
.aalevel
;
1098 if emptystr state
.origin
1102 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1103 wcmd "open %d %d %d %s\000%s\000%s\000"
1104 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1105 path password conf
.css
;
1106 invalidate "reqlayout"
1108 wcmd "reqlayout %d %d %d %s\000"
1109 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1110 (stateh state
.winh
) state
.nameddest
1113 let sl = keystostrlist conf
in
1115 function | [] -> accu
1116 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1117 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1121 state
.anchor <- getanchor
();
1122 opendoc state
.path state
.password
;
1126 let c = c *. conf
.colorscale
in
1130 let scalecolor2 (r
, g, b) =
1131 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1134 let docolumns columns
=
1137 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1138 let rec loop pageno
pdimno pdim
y ph pdims
=
1139 if pageno
= state
.pagecount
1142 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1144 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1145 pdimno+1, pdim
, rest
1149 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1151 y + (if conf
.presentation
1152 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1153 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1156 a.(pageno
) <- (pdimno, x, y, pdim
);
1157 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1159 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1160 conf
.columns
<- Csingle
a;
1162 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1163 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1164 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1166 if m
= pageno
then () else
1167 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1170 let y = y + (rowh
- h) / 2 in
1171 a.(m
) <- (pdimno, x, y, pdim
);
1175 if pageno
= state
.pagecount
1176 then fixrow (((pageno
- 1) / columns
) * columns
)
1178 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1180 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1181 pdimno+1, pdim
, rest
1186 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1188 let x = (state
.winw
- w) / 2 in
1190 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1191 x, y + ips + rowh
, h
1194 if (pageno
- coverA
) mod columns
= 0
1196 let x = max
0 (state
.winw
- state
.w) / 2 in
1198 if conf
.presentation
1200 let ips = calcips
h in
1201 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1203 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1207 else x, y, max rowh
h
1211 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1214 if pageno
= columns
&& conf
.presentation
1216 let ips = calcips rowh
in
1217 for i
= 0 to pred columns
1219 let (pdimno, x, y, pdim
) = a.(i
) in
1220 a.(i
) <- (pdimno, x, y+ips, pdim
)
1226 fixrow (pageno
- columns
);
1231 a.(pageno
) <- (pdimno, x, y, pdim
);
1232 let x = x + w + xoff
*2 + conf
.interpagespace
in
1233 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1235 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1236 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1239 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1240 let rec loop pageno
pdimno pdim
y pdims
=
1241 if pageno
= state
.pagecount
1244 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1246 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1247 pdimno+1, pdim
, rest
1252 let rec loop1 n x y =
1253 if n = c then y else (
1254 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1255 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1258 let y = loop1 0 0 y in
1259 loop (pageno
+1) pdimno pdim
y pdims
1261 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1262 conf
.columns
<- Csplit
(c, a);
1266 docolumns conf
.columns
;
1267 state
.maxy
<- calcheight
();
1268 if state
.reprf
== noreprf
1270 match state
.mode
with
1271 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1272 let y, h = getpageyh pageno
in
1273 let top = (state
.winh
- h) / 2 in
1274 gotoxy state
.x (max
0 (y - top))
1275 | Textentry _
| View
| LinkNav _
->
1276 let y = getanchory state
.anchor in
1277 let y = min
y (state
.maxy
- state
.winh
) in
1282 state
.reprf
<- noreprf
;
1286 let reshape ?
(firsttime
=false) w h =
1287 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1288 if not firsttime
&& nogeomcmds state
.geomcmds
1289 then state
.anchor <- getanchor
();
1292 let w = truncate
(float w *. conf
.zoom
) in
1295 setfontsize fstate
.fontsize
;
1296 GlMat.mode `modelview
;
1297 GlMat.load_identity
();
1299 GlMat.mode `projection
;
1300 GlMat.load_identity
();
1301 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1302 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1303 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1308 else float state
.x /. float state
.w
1310 invalidate "geometry"
1314 then state
.x <- truncate
(relx *. float w);
1316 match conf
.columns
with
1318 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1319 | Csplit
(c, _
) -> w * c
1321 wcmd "geometry %d %d %d"
1322 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1327 let len = String.length state
.text in
1328 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1331 match state
.mode
with
1332 | Textentry _
| View
| LinkNav _
->
1333 let h, _
, _
= state
.uioh#scrollpw
in
1339 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1340 (x+.w) (float (state
.winh
- hscrollh))
1343 let w = float (state
.winw
- 1 - vscrollw ()) in
1344 if state
.progress
>= 0.0 && state
.progress
< 1.0
1346 GlDraw.color (0.3, 0.3, 0.3);
1347 let w1 = w *. state
.progress
in
1349 GlDraw.color (0.0, 0.0, 0.0);
1350 rect (float x0+.w1) (float x0+.w-.w1)
1353 GlDraw.color (0.0, 0.0, 0.0);
1357 GlDraw.color (1.0, 1.0, 1.0);
1360 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1361 (state
.winh
- hscrollh - 5) s;
1364 match state
.mode
with
1365 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1368 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1369 else Printf.sprintf
"%s%s_" prefix
text
1373 | Birdseye _
| View
| LinkNav _
-> state
.text
1378 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1380 let s1 = "(press 'e' to review error messasges)" in
1381 if nonemptystr
s then s ^
" " ^
s1 else s1
1391 let len = Queue.length state
.tilelru
in
1393 match state
.throttle
with
1396 then preloadlayout state
.x state
.y state
.winw state
.winh
1398 | Some
(layout, _
, _
) ->
1402 if state
.memused
> conf
.memlimit
1406 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1407 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1408 let (_
, pw, ph
, _
) = getpagedim
n in
1410 && colorspace
= conf
.colorspace
1411 && angle
= conf
.angle
1415 let x = col*conf
.tilew
1416 and y = row*conf
.tileh
in
1417 tilevisible (Lazy.force_val
layout) n x y
1419 then Queue.push lruitem state
.tilelru
1422 wcmd "freetile %s" (~
> p
);
1423 state
.memused
<- state
.memused
- s;
1424 state
.uioh#infochanged Memused
;
1425 Hashtbl.remove state
.tilemap k
;
1433 let onpagerect pageno
f =
1435 match conf
.columns
with
1436 | Cmulti
(_
, b) -> b
1438 | Csplit
(_
, b) -> b
1440 if pageno
>= 0 && pageno
< Array.length
b
1442 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1446 let gotopagexy1 wtmode pageno
x y =
1447 let _,w1,h1
,leftx
= getpagedim pageno
in
1448 let top = y /. (float h1
) in
1449 let left = x /. (float w1) in
1450 let py, w, h = getpageywh pageno
in
1451 let wh = state
.winh
in
1452 let x = left *. (float w) in
1453 let x = leftx
+ state
.x + truncate
x in
1455 if x < 0 || x >= state
.winw
1459 let pdy = truncate
(top *. float h) in
1460 let y'
= py + pdy in
1461 let dy = y'
- state
.y in
1463 if x != state
.x || not
(dy > 0 && dy < wh)
1465 if conf
.presentation
1467 if abs
(py - y'
) > wh
1474 if state
.x != sx || state
.y != sy
1479 let ww = state
.winw
in
1481 and qy
= pdy / wh in
1483 and y = py + qy
* wh in
1484 let x = if -x + ww > w1 then -(w1-ww) else x
1485 and y'
= if y + wh > state
.maxy
then state
.maxy
- wh else y in
1487 if conf
.presentation
1489 if abs
(py - y'
) > wh
1498 gotoxy_and_clear_text x y;
1500 else gotoxy_and_clear_text state
.x state
.y;
1503 let gotopagexy wtmode pageno
x y =
1504 match state
.mode
with
1505 | Birdseye
_ -> gotopage pageno
0.0
1506 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1509 let getpassword () =
1510 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1515 impmsg "error getting password: %s" s;
1516 dolog
"%s" s) passcmd;
1519 let pgoto opaque pageno
x y =
1520 let pdimno = getpdimno pageno
in
1521 let x, y = project opaque pageno
pdimno x y in
1522 gotopagexy false pageno
x y;
1526 (* dolog "%S" cmds; *)
1527 let spl = splitatchar cmds ' '
in
1529 try Scanf.sscanf
s fmt
f
1531 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1534 let addoutline outline
=
1535 match state
.currently
with
1536 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1537 | Idle
-> state
.currently
<- Outlining
[outline
]
1538 | Loading
_ | Tiling
_ ->
1539 dolog
"invalid outlining state";
1540 logcurrently state
.currently
1545 state
.uioh#infochanged Pdim
;
1547 | "clearrects", "" ->
1548 state
.rects
<- state
.rects1
;
1549 G.postRedisplay "clearrects";
1551 | "continue", args
->
1552 let n = scan args
"%u" (fun n -> n) in
1553 state
.pagecount
<- n;
1554 begin match state
.currently
with
1556 state
.currently
<- Idle
;
1557 state
.outlines
<- Array.of_list
(List.rev
l)
1558 | Idle
| Loading
_ | Tiling
_ -> ()
1561 let cur, cmds
= state
.geomcmds
in
1563 then failwith
"umpossible";
1565 begin match List.rev cmds
with
1567 state
.geomcmds
<- E.s, [];
1568 state
.throttle
<- None
;
1572 state
.geomcmds
<- s, List.rev rest
;
1574 if conf
.maxwait
= None
&& not
!wtmode
1575 then G.postRedisplay "continue";
1582 then showtext ' ' args
1585 Buffer.add_string state
.errmsgs args
;
1586 state
.newerrmsgs
<- true;
1587 G.postRedisplay "error message"
1589 | "progress", args
->
1590 let progress, text =
1593 f, String.sub args pos
(String.length args
- pos
))
1596 state
.progress <- progress;
1597 G.postRedisplay "progress"
1599 | "firstmatch", args
->
1600 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1601 scan args
"%u %d %f %f %f %f %f %f %f %f"
1602 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1603 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1605 let y = (getpagey
pageno) + truncate
y0 in
1613 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1614 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1617 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1618 scan args
"%u %d %f %f %f %f %f %f %f %f"
1619 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1620 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1622 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1624 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1627 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1628 let pageopaque = ~
< pageopaques in
1629 begin match state
.currently
with
1630 | Loading
(l, gen
) ->
1631 vlog "page %d took %f sec" l.pageno t
;
1632 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1633 begin match state
.throttle
with
1635 let preloadedpages =
1637 then preloadlayout state
.x state
.y state
.winw state
.winh
1642 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1643 IntSet.empty
preloadedpages
1646 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1647 if not
(IntSet.mem
pageno set)
1649 wcmd "freepage %s" (~
> opaque
);
1655 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1658 state
.currently
<- Idle
;
1661 tilepage l.pageno pageopaque state
.layout;
1663 load preloadedpages;
1664 let visible = pagevisible state
.layout l.pageno in
1667 match state
.mode
with
1668 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1669 if pageno = l.pageno
1674 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1676 if dir
> 0 then LDfirst
else LDlast
1679 findlink
pageopaque ld
1684 showlinktype (getlink
pageopaque n);
1685 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1687 | LinkNav
(Ltgendir
_)
1688 | LinkNav
(Ltexact
_)
1694 if visible && layoutready state
.layout
1696 G.postRedisplay "page";
1700 | Some
(layout, _, _) ->
1701 state
.currently
<- Idle
;
1702 tilepage l.pageno pageopaque layout;
1706 | Idle
| Tiling
_ | Outlining
_ ->
1707 dolog
"Inconsistent loading state";
1708 logcurrently state
.currently
;
1713 let (x, y, opaques
, size
, t
) =
1714 scan args
"%u %u %s %u %f"
1715 (fun x y p size t
-> (x, y, p
, size
, t
))
1717 let opaque = ~
< opaques
in
1718 begin match state
.currently
with
1719 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1720 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1723 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1725 wcmd "freetile %s" (~
> opaque);
1726 state
.currently
<- Idle
;
1730 puttileopaque l col row gen cs angle
opaque size t
;
1731 state
.memused
<- state
.memused
+ size
;
1732 state
.uioh#infochanged Memused
;
1734 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1735 opaque, size
) state
.tilelru
;
1738 match state
.throttle
with
1739 | None
-> state
.layout
1740 | Some
(layout, _, _) -> layout
1743 state
.currently
<- Idle
;
1745 && conf
.colorspace
= cs
1746 && conf
.angle
= angle
1747 && tilevisible layout l.pageno x y
1748 then conttiling l.pageno pageopaque;
1750 begin match state
.throttle
with
1752 preload state
.layout;
1754 && conf
.colorspace
= cs
1755 && conf
.angle
= angle
1756 && tilevisible state
.layout l.pageno x y
1757 && (not
!wtmode || layoutready state
.layout)
1758 then G.postRedisplay "tile nothrottle";
1760 | Some
(layout, y, _) ->
1761 let ready = layoutready layout in
1765 state
.layout <- layout;
1766 state
.throttle
<- None
;
1767 G.postRedisplay "throttle";
1773 | Idle
| Loading
_ | Outlining
_ ->
1774 dolog
"Inconsistent tiling state";
1775 logcurrently state
.currently
;
1780 let (n, w, h, _) as pdim
=
1781 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1784 match conf
.fitmodel
with
1786 | FitPage
| FitProportional
->
1787 match conf
.columns
with
1788 | Csplit
_ -> (n, w, h, 0)
1789 | Csingle
_ | Cmulti
_ -> pdim
1791 state
.pdims
<- pdim :: state
.pdims
;
1792 state
.uioh#infochanged Pdim
1795 let (l, n, t
, h, pos
) =
1796 scan args
"%u %u %d %u %n"
1797 (fun l n t
h pos
-> l, n, t
, h, pos
)
1799 let s = String.sub args pos
(String.length args
- pos
) in
1800 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1803 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1804 let s = String.sub args pos
len in
1805 let pos2 = pos
+ len + 1 in
1806 let uri = String.sub args
pos2 (String.length args
- pos2) in
1807 addoutline (s, l, Ouri
uri)
1810 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1811 let s = String.sub args pos
(String.length args
- pos
) in
1812 addoutline (s, l, Onone
)
1816 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1818 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1821 let c, v
= splitatchar args '
\t'
in
1832 if let len = String.length
c in
1833 len > 6 && ((String.sub
c (len-4) 4) = "date")
1835 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1837 let b = Buffer.create
10 in
1838 Printf.bprintf
b "%s\t" c;
1841 Buffer.add_substring
b v p
l;
1842 Buffer.add_char
b c;
1843 with exn
-> Buffer.add_string
b @@ exntos exn
1851 Buffer.add_char
b '
['
;
1852 Buffer.add_string
b v
;
1853 Buffer.add_char
b '
]'
;
1860 state
.docinfo
<- (1, s) :: state
.docinfo
1863 state
.docinfo
<- List.rev state
.docinfo
;
1864 state
.uioh#infochanged Docinfo
1868 then Wsi.settitle
"Wrong password";
1869 let password = getpassword () in
1870 if emptystr
password
1871 then error
"document is password protected"
1872 else opendoc state
.path
password
1875 error
"unknown cmd `%S'" cmds
1880 let action = function
1881 | HCprev
-> cbget cb ~
-1
1882 | HCnext
-> cbget cb
1
1883 | HCfirst
-> cbget cb ~
-(cb
.rc)
1884 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1885 and cancel
() = cb
.rc <- rc
1889 let search pattern forward
=
1890 match conf
.columns
with
1891 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1892 | Csingle
_ | Cmulti
_ ->
1893 if nonemptystr pattern
1896 match state
.layout with
1899 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1901 wcmd "search %d %d %d %d,%s\000"
1902 (btod conf
.icase
) pn py (btod forward
) pattern
;
1905 let [@warning
"-4"] intentry
text key =
1908 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1910 state
.text <- "invalid key";
1920 let l = String.length
s in
1921 let rec loop pos
n =
1925 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1926 loop (pos
+1) (n*26 + m)
1929 let rec loop n = function
1932 match getopaque l.pageno with
1933 | None
-> loop n rest
1935 let m = getlinkcount
opaque in
1938 let under = getlink
opaque n in
1941 else loop (n-m) rest
1943 loop n state
.layout;
1947 let [@warning
"-4"] linknentry
text = function
1949 let text = addchar
text c in
1950 linknact (fun under -> state
.text <- undertext under) text;
1953 state
.text <- Printf.sprintf
"invalid key";
1957 let [@warning
"-4"] textentry
text = function
1958 | Keys.Ascii
c -> TEcont
(addchar
text c)
1959 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1963 let reqlayout angle fitmodel
=
1964 match state
.throttle
with
1966 if nogeomcmds state
.geomcmds
1967 then state
.anchor <- getanchor
();
1968 conf
.angle
<- angle
mod 360;
1971 match state
.mode
with
1972 | LinkNav
_ -> state
.mode
<- View
1973 | Birdseye
_ | Textentry
_ | View
-> ()
1975 conf
.fitmodel
<- fitmodel
;
1979 wcmd "reqlayout %d %d %d"
1980 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1985 let settrim trimmargins trimfuzz
=
1986 if nogeomcmds state
.geomcmds
1987 then state
.anchor <- getanchor
();
1988 conf
.trimmargins
<- trimmargins
;
1989 conf
.trimfuzz
<- trimfuzz
;
1990 let x0, y0, x1, y1 = trimfuzz
in
1992 "settrim" (fun () ->
1993 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1998 match state
.throttle
with
2000 let zoom = max
0.0001 zoom in
2001 if zoom <> conf
.zoom
2003 state
.prevzoom
<- (conf
.zoom, state
.x);
2005 reshape state
.winw state
.winh
;
2006 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2009 | Some
(layout, y, started
) ->
2011 match conf
.maxwait
with
2015 let dt = now
() -. started
in
2023 let pivotzoom ?
(vw=min state
.w state
.winw
)
2024 ?
(vh
=min
(state
.maxy
-state
.y) state
.winh
)
2025 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2026 let w = float state
.w /. zoom in
2027 let hw = w /. 2.0 in
2028 let ratio = float vh
/. float vw in
2029 let hh = hw *. ratio in
2030 let x0 = if zoom < 1.0 then 0.0 else float x -. hw in
2031 let y0 = float y -. hh in
2032 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2036 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2037 if nogeomcmds state
.geomcmds
then pivotzoom ?
vw ?vh ?
x ?
y zoom
2040 let setcolumns mode columns coverA coverB
=
2041 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2045 then impmsg "split mode doesn't work in bird's eye"
2047 conf
.columns
<- Csplit
(-columns
, E.a);
2055 conf
.columns
<- Csingle
E.a;
2060 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2064 reshape state
.winw state
.winh
;
2067 let resetmstate () =
2068 state
.mstate
<- Mnone
;
2069 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2072 let enterbirdseye () =
2073 let zoom = float conf
.thumbw
/. float state
.winw
in
2074 let birdseyepageno =
2075 let cy = state
.winh
/ 2 in
2079 let rec fold best
= function
2082 let d = cy - (l.pagedispy + l.pagevh/2)
2083 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2084 if abs
d < abs dbest
2093 { conf
with zoom = conf
.zoom },
2094 state
.x, birdseyepageno, -1, getanchor
()
2098 conf
.presentation
<- false;
2099 conf
.interpagespace
<- 10;
2100 conf
.hlinks
<- false;
2101 conf
.fitmodel
<- FitPage
;
2103 conf
.maxwait
<- None
;
2105 match conf
.beyecolumns
with
2108 Cmulti
((c, 0, 0), E.a)
2109 | None
-> Csingle
E.a
2113 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2118 reshape state
.winw state
.winh
;
2121 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2123 conf
.zoom <- c.zoom;
2124 conf
.presentation
<- c.presentation
;
2125 conf
.interpagespace
<- c.interpagespace
;
2126 conf
.maxwait
<- c.maxwait
;
2127 conf
.hlinks
<- c.hlinks
;
2128 conf
.fitmodel
<- c.fitmodel
;
2129 conf
.beyecolumns
<- (
2130 match conf
.columns
with
2131 | Cmulti
((c, _, _), _) -> Some
c
2133 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2136 match c.columns
with
2137 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2138 | Csingle
_ -> Csingle
E.a
2139 | Csplit
(c, _) -> Csplit
(c, E.a)
2143 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2146 reshape state
.winw state
.winh
;
2147 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2151 let togglebirdseye () =
2152 match state
.mode
with
2153 | Birdseye vals
-> leavebirdseye vals
true
2154 | View
-> enterbirdseye ()
2155 | Textentry
_ | LinkNav
_ -> ()
2158 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2159 let pageno = max
0 (pageno - incr
) in
2160 let rec loop = function
2161 | [] -> gotopage1 pageno 0
2162 | l :: _ when l.pageno = pageno ->
2163 if l.pagedispy >= 0 && l.pagey = 0
2164 then G.postRedisplay "upbirdseye"
2165 else gotopage1 pageno 0
2166 | _ :: rest
-> loop rest
2170 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2173 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2174 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2175 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2176 let rec loop = function
2178 let y, h = getpageyh
pageno in
2179 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2180 gotoxy state
.x (clamp dy)
2181 | l :: _ when l.pageno = pageno ->
2182 if l.pagevh != l.pageh
2183 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2184 else G.postRedisplay "downbirdseye"
2185 | _ :: rest
-> loop rest
2191 let [@warning
"-4"] optentry mode
_ key =
2192 let btos b = if b then "on" else "off" in
2196 try conf
.scrollstep
<- int_of_string
s with exn
->
2197 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2199 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2204 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2205 if state
.autoscroll
<> None
2206 then state
.autoscroll
<- Some conf
.autoscrollstep
2208 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2210 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2215 let n, a, b = multicolumns_of_string
s in
2216 setcolumns mode
n a b;
2218 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2220 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2225 let zoom = float (int_of_string
s) /. 100.0 in
2228 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2230 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2235 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2237 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2238 begin match mode
with
2240 leavebirdseye beye
false;
2242 | Textentry
_ | View
| LinkNav
_ -> ();
2245 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2247 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2251 match int_of_string
s with
2252 | angle
-> reqlayout angle conf
.fitmodel
2254 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2256 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2259 conf
.icase
<- not conf
.icase
;
2260 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2263 conf
.preload <- not conf
.preload;
2264 gotoxy state
.x state
.y;
2265 TEdone
("preload " ^
(btos conf
.preload))
2268 conf
.verbose
<- not conf
.verbose
;
2269 TEdone
("verbose " ^
(btos conf
.verbose
))
2272 conf
.debug
<- not conf
.debug
;
2273 TEdone
("debug " ^
(btos conf
.debug
))
2276 conf
.maxhfit
<- not conf
.maxhfit
;
2277 state
.maxy
<- calcheight
();
2278 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2281 conf
.crophack
<- not conf
.crophack
;
2282 TEdone
("crophack " ^
btos conf
.crophack
)
2286 match conf
.maxwait
with
2288 conf
.maxwait
<- Some infinity
;
2289 "always wait for page to complete"
2291 conf
.maxwait
<- None
;
2292 "show placeholder if page is not ready"
2297 conf
.underinfo
<- not conf
.underinfo
;
2298 TEdone
("underinfo " ^
btos conf
.underinfo
)
2301 conf
.savebmarks
<- not conf
.savebmarks
;
2302 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2308 match state
.layout with
2313 conf
.interpagespace
<- int_of_string
s;
2314 docolumns conf
.columns
;
2315 state
.maxy
<- calcheight
();
2316 let y = getpagey
pageno in
2317 gotoxy state
.x (y + py)
2319 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2321 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2325 match conf
.fitmodel
with
2326 | FitProportional
-> FitWidth
2327 | FitWidth
| FitPage
-> FitProportional
2329 reqlayout conf
.angle
fm;
2330 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2333 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2334 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2337 conf
.invert
<- not conf
.invert
;
2338 TEdone
("invert colors " ^
btos conf
.invert
)
2342 cbput state
.hists
.sel
s;
2345 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2346 textentry
, ondone, true)
2350 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2351 else conf
.pax
<- None
;
2352 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2355 state
.text <- Printf.sprintf
"bad option %d `%c'"
2363 class type lvsource
=
2365 method getitemcount
: int
2366 method getitem
: int -> (string * int)
2367 method hasaction
: int -> bool
2368 method exit
: uioh
:uioh
->
2374 method getactive
: int
2375 method getfirst
: int
2377 method getminfo
: (int * int) array
2380 class virtual lvsourcebase
= object
2381 val mutable m_active
= 0
2382 val mutable m_first
= 0
2383 val mutable m_pan
= 0
2384 method getactive
= m_active
2385 method getfirst
= m_first
2386 method getpan
= m_pan
2387 method getminfo
: (int * int) array
= E.a
2390 let [@warning
"-4"] textentrykeyboard
2391 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2394 state
.mode
<- Textentry
(te
, onleave
);
2396 G.postRedisplay "textentrykeyboard enttext";
2398 let histaction cmd
=
2401 | Some
(action, _) ->
2404 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2406 G.postRedisplay "textentry histaction"
2408 let open Keys
in let kt = Wsi.kc2kt
key in
2411 if emptystr
text && cancelonempty
2414 G.postRedisplay "textentrykeyboard after cancel";
2417 let s = withoutlastutf8
text in
2418 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2420 | Enter
| KPenter
->
2423 G.postRedisplay "textentrykeyboard after confirm"
2425 | Up
| KPup
-> histaction HCprev
2426 | Down
| KPdown
-> histaction HCnext
2427 | Home
| KPhome
-> histaction HCfirst
2428 | End
| KPend
-> histaction HClast
2433 begin match opthist
with
2435 | Some
(_, onhistcancel
) -> onhistcancel
()
2439 G.postRedisplay "textentrykeyboard after cancel2"
2442 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2445 | Delete
| KPdelete
-> ()
2447 | Code
_ | Ascii
_ ->
2448 begin match onkey
text kt with
2452 G.postRedisplay "textentrykeyboard after confirm2";
2455 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2459 G.postRedisplay "textentrykeyboard after cancel3"
2462 state
.mode
<- Textentry
(te
, onleave
);
2463 G.postRedisplay "textentrykeyboard switch";
2465 | _ -> vlog "unhandled key"
2468 let firstof first active
=
2469 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2470 then max
0 (active
- (fstate
.maxrows
/2))
2474 let calcfirst first active
=
2477 let rows = active
- first
in
2478 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2482 let scrollph y maxy
=
2483 let sh = float (maxy
+ state
.winh
) /. float state
.winh
in
2484 let sh = float state
.winh
/. sh in
2485 let sh = max
sh (float conf
.scrollh
) in
2487 let percent = float y /. float maxy
in
2488 let position = (float state
.winh
-. sh) *. percent in
2491 if position +. sh > float state
.winh
2492 then float state
.winh
-. sh
2498 let adderrmsg src msg
=
2499 Buffer.add_string state
.errmsgs msg
;
2500 state
.newerrmsgs
<- true;
2504 let adderrfmt src fmt
=
2505 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2508 let coe s = (s :> uioh
);;
2510 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2512 val m_pan
= source#getpan
2513 val m_first
= source#getfirst
2514 val m_active
= source#getactive
2516 val m_prev_uioh
= state
.uioh
2518 method private elemunder
y =
2522 let n = y / (fstate
.fontsize
+1) in
2523 if m_first
+ n < source#getitemcount
2525 if source#hasaction
(m_first
+ n)
2526 then Some
(m_first
+ n)
2533 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2534 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2535 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2536 GlDraw.color (1., 1., 1.);
2537 Gl.enable `texture_2d
;
2538 let fs = fstate
.fontsize
in
2540 let hw = state
.winw
/3 in
2541 let ww = fstate
.wwidth
in
2542 let tabw = 17.0*.ww in
2543 let itemcount = source#getitemcount
in
2544 let minfo = source#getminfo
in
2548 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2550 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2552 if (row - m_first
) > fstate
.maxrows
2555 if row >= 0 && row < itemcount
2557 let (s, level
) = source#getitem
row in
2558 let y = (row - m_first
) * nfs in
2559 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2562 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2566 Gl.disable `texture_2d
;
2567 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2568 GlDraw.color (1., 1., 1.) ~
alpha;
2569 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2570 Gl.enable `texture_2d
;
2573 if zebra
&& row land 1 = 1
2577 GlDraw.color (c,c,c);
2578 let drawtabularstring s =
2580 let x'
= truncate
(x0 +. x) in
2581 let s1, s2
= splitatchar
s '
\000'
in
2583 then drawstring1 fs x'
(y+nfs) s
2589 let s'
= withoutlastutf8
s in
2590 let s = s' ^
UniSyms.ellipsis in
2591 let w = measurestr
fs s in
2592 if float x'
+. w +. ww < float (hw + x'
)
2597 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2601 ignore
(drawstring1 fs x'
(y+nfs) s1);
2602 drawstring1 fs (hw + x'
) (y+nfs) s2
2606 let x = if helpmode
&& row > 0 then x +. ww else x in
2607 let s1, s2
= splitatchar
s '
\t'
in
2610 let nx = drawstr x s1 in
2612 let x = x +. (max
tabw sw) in
2615 let len = String.length
s - 2 in
2616 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2618 let s = String.sub s 2 len in
2619 let x = if not helpmode
then x +. ww else x in
2620 GlDraw.color (1.2, 1.2, 1.2);
2621 let vinc = drawstring1 (fs+fs/4)
2622 (truncate
(x -. ww)) (y+nfs) s in
2623 GlDraw.color (1., 1., 1.);
2624 vinc +. (float fs *. 0.8)
2630 ignore
(drawtabularstring s);
2636 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2639 if (row - m_first
) <= fstate
.maxrows
2641 if row >= 0 && row < itemcount
2643 let (s, level
) = source#getitem
row in
2644 let pos0 = nindex
s '
\000'
in
2645 let y = (row - m_first
) * nfs in
2646 let x = float (level
+ m_pan
) *. ww in
2647 let (first
, last
) = minfo.(row) in
2649 if pos0 > 0 && first
> pos0
2650 then String.sub s (pos0+1) (first
-pos0-1)
2651 else String.sub s 0 first
2653 let suffix = String.sub s first
(last
- first
) in
2654 let w1 = measurestr fstate
.fontsize
prefix in
2655 let w2 = measurestr fstate
.fontsize
suffix in
2656 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2657 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2659 and y0 = float (y+2) in
2661 and y1 = float (y+fs+3) in
2662 filledrect x0 y0 x1 y1;
2666 Gl.disable `texture_2d
;
2667 if Array.length
minfo > 0 then loop m_first
;
2672 method updownlevel incr
=
2673 let len = source#getitemcount
in
2675 if m_active
>= 0 && m_active
< len
2676 then snd
(source#getitem m_active
)
2680 if i
= len then i
-1 else if i
= -1 then 0 else
2681 let _, l = source#getitem i
in
2682 if l != curlevel then i
else flow (i
+incr
)
2684 let active = flow m_active
in
2685 let first = calcfirst m_first
active in
2686 G.postRedisplay "outline updownlevel";
2687 {< m_active
= active; m_first
= first >}
2689 method private key1
key mask
=
2690 let set1 active first qsearch
=
2691 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2693 let search active pattern incr
=
2694 let active = if active = -1 then m_first
else active in
2697 if n >= 0 && n < source#getitemcount
2699 let s, _ = source#getitem
n in
2700 match Str.search_forward re
s 0 with
2701 | exception Not_found
-> loop (n + incr
)
2708 let qpat = Str.quote pattern
in
2709 match Str.regexp_case_fold
qpat with
2712 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2713 qpat @@ Printexc.to_string exn
;
2716 let itemcount = source#getitemcount
in
2717 let find start incr
=
2719 if i
= -1 || i
= itemcount
2722 if source#hasaction i
2724 else find (i
+ incr
)
2729 let set active first =
2730 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2732 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2735 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2737 let incr1 = if incr
> 0 then 1 else -1 in
2738 if isvisible m_first m_active
2741 let next = m_active
+ incr
in
2743 if next < 0 || next >= itemcount
2745 else find next incr1
2747 if abs
(m_active
- next) > fstate
.maxrows
2753 let first = m_first
+ incr
in
2754 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2756 let next = m_active
+ incr
in
2757 let next = bound
next 0 (itemcount - 1) in
2764 if isvisible first next
2771 let first = min
next m_first
in
2773 if abs
(next - first) > fstate
.maxrows
2779 let first = m_first
+ incr
in
2780 let first = bound
first 0 (itemcount - 1) in
2782 let next = m_active
+ incr
in
2783 let next = bound
next 0 (itemcount - 1) in
2784 let next = find next incr1 in
2786 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2788 let active = if m_active
= -1 then next else m_active
in
2793 if isvisible first active
2799 G.postRedisplay "listview navigate";
2803 let kt = Wsi.kc2kt
key in
2804 match [@warning
"-4"] kt with
2805 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2806 let incr = if c = 'r'
then -1 else 1 in
2808 match search (m_active
+ incr) m_qsearch
incr with
2810 state
.text <- m_qsearch ^
" [not found]";
2813 state
.text <- m_qsearch
;
2814 active, firstof m_first
active
2816 G.postRedisplay "listview ctrl-r/s";
2817 set1 active first m_qsearch
;
2819 | Insert
when Wsi.withctrl mask
->
2820 if m_active
>= 0 && m_active
< source#getitemcount
2822 let s, _ = source#getitem m_active
in
2828 if emptystr m_qsearch
2831 let qsearch = withoutlastutf8 m_qsearch
in
2835 G.postRedisplay "listview empty qsearch";
2836 set1 m_active m_first
E.s;
2840 match search m_active
qsearch ~
-1 with
2842 state
.text <- qsearch ^
" [not found]";
2845 state
.text <- qsearch;
2846 active, firstof m_first
active
2848 G.postRedisplay "listview backspace qsearch";
2849 set1 active first qsearch
2852 | Ascii
_ | Code
_ ->
2854 match [@warning
"-4"] kt with
2855 | Ascii
c -> String.make
1 c
2856 | Code code
-> toutf8 code
2859 let pattern = m_qsearch ^
utf8 in
2861 match search m_active
pattern 1 with
2863 state
.text <- pattern ^
" [not found]";
2866 state
.text <- pattern;
2867 active, firstof m_first
active
2869 G.postRedisplay "listview qsearch add";
2870 set1 active first pattern;
2874 if emptystr m_qsearch
2876 G.postRedisplay "list view escape";
2877 let mx, my
= state
.mpos
in
2879 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2880 ~
first:m_first ~pan
:m_pan
with
2881 | None
-> m_prev_uioh
2885 G.postRedisplay "list view kill qsearch";
2886 coe {< m_qsearch
= E.s >}
2889 | Enter
| KPenter
->
2891 let self = {< m_qsearch
= E.s >} in
2893 G.postRedisplay "listview enter";
2894 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2895 source#exit ~uioh
:(coe self) ~
cancel
2896 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2898 begin match opt with
2899 | None
-> m_prev_uioh
2903 | Delete
| KPdelete
->
2906 | Up
| KPup
-> navigate ~
-1
2907 | Down
| KPdown
-> navigate 1
2908 | Prior
| KPprior
-> navigate ~
-(fstate
.maxrows
)
2909 | Next
| KPnext
-> navigate fstate
.maxrows
2911 | Right
| KPright
->
2913 G.postRedisplay "listview right";
2914 coe {< m_pan
= m_pan
- 1 >}
2918 G.postRedisplay "listview left";
2919 coe {< m_pan
= m_pan
+ 1 >}
2922 let active = find 0 1 in
2923 G.postRedisplay "listview home";
2927 let first = max
0 (itemcount - fstate
.maxrows
) in
2928 let active = find (itemcount - 1) ~
-1 in
2929 G.postRedisplay "listview end";
2934 method key key mask
=
2935 match state
.mode
with
2937 textentrykeyboard
key mask te
;
2939 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2941 method button button down
x y _ =
2944 | 1 when vscrollhit x ->
2945 G.postRedisplay "listview scroll";
2948 let _, position, sh = self#
scrollph in
2949 if y > truncate
position && y < truncate
(position +. sh)
2951 state
.mstate
<- Mscrolly
;
2955 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2956 let first = truncate
(s *. float source#getitemcount
) in
2957 let first = min source#getitemcount
first in
2958 Some
(coe {< m_first
= first; m_active
= first >})
2960 state
.mstate
<- Mnone
;
2964 begin match self#elemunder
y with
2966 G.postRedisplay "listview click";
2967 source#exit ~uioh
:(coe {< m_active
= n >})
2968 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2972 | n when (n == 4 || n == 5) && not down
->
2973 let len = source#getitemcount
in
2975 if n = 5 && m_first
+ fstate
.maxrows
>= len
2979 let first = m_first
+ (if n == 4 then -1 else 1) in
2980 bound
first 0 (len - 1)
2982 G.postRedisplay "listview wheel";
2983 Some
(coe {< m_first
= first >})
2984 | n when (n = 6 || n = 7) && not down
->
2985 let inc = if n = 7 then -1 else 1 in
2986 G.postRedisplay "listview hwheel";
2987 Some
(coe {< m_pan
= m_pan
+ inc >})
2992 | None
-> m_prev_uioh
2995 method multiclick
_ x y = self#button
1 true x y
2998 match state
.mstate
with
3000 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3001 let first = truncate
(s *. float source#getitemcount
) in
3002 let first = min source#getitemcount
first in
3003 G.postRedisplay "listview motion";
3004 coe {< m_first
= first; m_active
= first >}
3012 method pmotion
x y =
3013 if x < state
.winw
- conf
.scrollbw
3016 match self#elemunder
y with
3017 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3018 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3022 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3027 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3031 method infochanged
_ = ()
3033 method scrollpw
= (0, 0.0, 0.0)
3035 let nfs = fstate
.fontsize
+ 1 in
3036 let y = m_first
* nfs in
3037 let itemcount = source#getitemcount
in
3038 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3039 let maxy = maxi * nfs in
3040 let p, h = scrollph y maxy in
3043 method modehash
= modehash
3044 method eformsgs
= false
3045 method alwaysscrolly
= true
3048 class outlinelistview ~zebra ~source
=
3049 let settext autonarrow
s =
3052 let ss = source#statestr
in
3056 else "{" ^
ss ^
"} [" ^
s ^
"]"
3057 else state
.text <- s
3063 ~source
:(source
:> lvsource
)
3065 ~modehash
:(findkeyhash conf
"outline")
3068 val m_autonarrow
= false
3070 method! key key mask
=
3072 if emptystr state
.text
3074 else fstate
.maxrows - 2
3076 let calcfirst first active =
3079 let rows = active - first in
3080 if rows > maxrows then active - maxrows else first
3084 let active = m_active
+ incr in
3085 let active = bound
active 0 (source#getitemcount
- 1) in
3086 let first = calcfirst m_first
active in
3087 G.postRedisplay "outline navigate";
3088 coe {< m_active
= active; m_first
= first >}
3090 let navscroll first =
3092 let dist = m_active
- first in
3098 else first + maxrows
3101 G.postRedisplay "outline navscroll";
3102 coe {< m_first
= first; m_active
= active >}
3104 let ctrl = Wsi.withctrl mask
in
3106 match Wsi.kc2kt
key with
3107 | Ascii '
a'
when ctrl ->
3110 then (source#denarrow
; E.s)
3112 let pattern = source#renarrow
in
3113 if nonemptystr m_qsearch
3114 then (source#narrow m_qsearch
; m_qsearch
)
3118 settext (not m_autonarrow
) text;
3119 G.postRedisplay "toggle auto narrowing";
3120 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3122 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3124 G.postRedisplay "toggle auto narrowing";
3125 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3127 | Ascii '
n'
when ctrl ->
3128 source#narrow m_qsearch
;
3130 then source#add_narrow_pattern m_qsearch
;
3131 G.postRedisplay "outline ctrl-n";
3132 coe {< m_first
= 0; m_active
= 0 >}
3134 | Ascii 'S'
when ctrl ->
3135 let active = source#calcactive
(getanchor
()) in
3136 let first = firstof m_first
active in
3137 G.postRedisplay "outline ctrl-s";
3138 coe {< m_first
= first; m_active
= active >}
3140 | Ascii 'u'
when ctrl ->
3141 G.postRedisplay "outline ctrl-u";
3142 if m_autonarrow
&& nonemptystr m_qsearch
3144 ignore
(source#renarrow
);
3145 settext m_autonarrow
E.s;
3146 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3149 source#del_narrow_pattern
;
3150 let pattern = source#renarrow
in
3152 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3154 settext m_autonarrow
text;
3155 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3158 | Ascii '
l'
when ctrl ->
3159 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3160 G.postRedisplay "outline ctrl-l";
3161 coe {< m_first
= first >}
3163 | Ascii '
\t'
when m_autonarrow
->
3164 if nonemptystr m_qsearch
3166 G.postRedisplay "outline list view tab";
3167 source#add_narrow_pattern m_qsearch
;
3169 coe {< m_qsearch
= E.s >}
3173 | Escape
when m_autonarrow
->
3174 if nonemptystr m_qsearch
3175 then source#add_narrow_pattern m_qsearch
;
3178 | Enter
| KPenter
when m_autonarrow
->
3179 if nonemptystr m_qsearch
3180 then source#add_narrow_pattern m_qsearch
;
3183 | _ when m_autonarrow
->
3184 let pattern = m_qsearch ^ toutf8
key in
3185 G.postRedisplay "outlinelistview autonarrow add";
3186 source#narrow
pattern;
3187 settext true pattern;
3188 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3190 | key when m_autonarrow
&& key = Backspace
->
3191 if emptystr m_qsearch
3194 let pattern = withoutlastutf8 m_qsearch
in
3195 G.postRedisplay "outlinelistview autonarrow backspace";
3196 ignore
(source#renarrow
);
3197 source#narrow
pattern;
3198 settext true pattern;
3199 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3201 | Up
| KPup
when ctrl ->
3202 navscroll (max
0 (m_first
- 1))
3204 | Down
| KPdown
when ctrl ->
3205 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3207 | Up
| KPup
-> navigate ~
-1
3208 | Down
| KPdown
-> navigate 1
3209 | Prior
| KPprior
-> navigate ~
-(fstate
.maxrows)
3210 | Next
| KPnext
-> navigate fstate
.maxrows
3212 | Right
| KPright
->
3216 G.postRedisplay "outline ctrl right";
3217 {< m_pan
= m_pan
+ 1 >}
3219 else self#updownlevel
1
3227 G.postRedisplay "outline ctrl left";
3228 {< m_pan
= m_pan
- 1 >}
3230 else self#updownlevel ~
-1
3235 G.postRedisplay "outline home";
3236 coe {< m_first
= 0; m_active
= 0 >}
3239 let active = source#getitemcount
- 1 in
3240 let first = max
0 (active - fstate
.maxrows) in
3241 G.postRedisplay "outline end";
3242 coe {< m_active
= active; m_first
= first >}
3244 | Delete
|Escape
|Insert
|Enter
|KPdelete
|KPenter
|KPminus
3245 | KPplus
|Ascii
_|Code
_|Backspace
|Fn
_ -> super#
key key mask
3248 let genhistoutlines () =
3250 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3251 compare c2
.lastvisit c1
.lastvisit
)
3253 (fun ((path
, c, _, _, _, origin
) as hist
) ->
3254 let path = if nonemptystr origin
then origin
else path in
3255 let base = mbtoutf8
@@ Filename.basename
path in
3256 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3261 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3262 Config.save
leavebirdseye;
3263 state
.anchor <- anchor;
3264 state
.bookmarks
<- bookmarks
;
3265 state
.origin
<- origin
;
3268 let x0, y0, x1, y1 = conf
.trimfuzz
in
3269 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3270 reshape ~firsttime
:true state
.winw state
.winh
;
3271 opendoc path origin
;
3275 let makecheckers () =
3276 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3278 converted by Issac Trotts. July 25, 2002 *)
3279 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3280 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3281 let id = GlTex.gen_texture
() in
3282 GlTex.bind_texture ~target
:`texture_2d
id;
3283 GlPix.store
(`unpack_alignment
1);
3284 GlTex.image2d
image;
3285 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3286 [ `mag_filter `nearest
; `min_filter `nearest
];
3290 let setcheckers enabled
=
3291 match state
.checkerstexid
with
3293 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3295 | Some checkerstexid
->
3298 GlTex.delete_texture checkerstexid
;
3299 state
.checkerstexid
<- None
;
3303 let describe_location () =
3304 let fn = page_of_y state
.y in
3305 let ln = page_of_y
(state
.y + state
.winh
- 1) in
3306 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
3310 else (100. *. (float state
.y /. float maxy))
3314 Printf.sprintf
"page %d of %d [%.2f%%]"
3315 (fn+1) state
.pagecount
percent
3318 "pages %d-%d of %d [%.2f%%]"
3319 (fn+1) (ln+1) state
.pagecount
percent
3322 let setpresentationmode v
=
3323 let n = page_of_y state
.y in
3324 state
.anchor <- (n, 0.0, 1.0);
3325 conf
.presentation
<- v
;
3326 if conf
.fitmodel
= FitPage
3327 then reqlayout conf
.angle conf
.fitmodel
;
3331 let setbgcol (r
, g, b) =
3333 let r = r *. 255.0 |> truncate
3334 and g = g *. 255.0 |> truncate
3335 and b = b *. 255.0 |> truncate
in
3336 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3338 Wsi.setwinbgcol
col;
3342 let btos b = if b then UniSyms.radical else E.s in
3343 let showextended = ref false in
3344 let leave mode
_ = state
.mode
<- mode
in
3347 val mutable m_l
= []
3348 val mutable m_a
= E.a
3349 val mutable m_prev_uioh
= nouioh
3350 val mutable m_prev_mode
= View
3352 inherit lvsourcebase
3354 method reset prev_mode prev_uioh
=
3355 m_a
<- Array.of_list
(List.rev m_l
);
3357 m_prev_mode
<- prev_mode
;
3358 m_prev_uioh
<- prev_uioh
;
3360 method int name get
set =
3366 try set (int_of_string
s)
3368 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3372 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3373 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3377 method int_with_suffix name get
set =
3379 (name
, `intws get
, 1,
3383 try set (int_of_string_with_suffix
s)
3385 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3390 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3392 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3396 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3398 (name
, `
bool (btos, get
), offset
, Action
(
3405 method color name get
set =
3407 (name
, `
color get
, 1,
3410 let invalid = (nan
, nan
, nan
) in
3413 try color_of_string
s
3415 state
.text <- Printf.sprintf
"bad color `%s': %s"
3422 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3423 state
.text <- color_to_string
(get
());
3424 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3428 method string name get
set =
3430 (name
, `
string get
, 1,
3433 let ondone s = set s in
3434 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3435 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3439 method colorspace name get
set =
3441 (name
, `
string get
, 1,
3446 inherit lvsourcebase
3449 m_active
<- CSTE.to_int conf
.colorspace
;
3452 method getitemcount
=
3453 Array.length
CSTE.names
3456 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3457 ignore
(uioh
, first, pan
);
3458 if not
cancel then set active;
3460 method hasaction
_ = true
3464 let modehash = findkeyhash conf
"info" in
3465 coe (new listview ~zebra
:false ~helpmode
:false
3466 ~
source ~trusted
:true ~
modehash)
3469 method paxmark name get
set =
3471 (name
, `
string get
, 1,
3476 inherit lvsourcebase
3479 m_active
<- MTE.to_int conf
.paxmark
;
3482 method getitemcount
= Array.length
MTE.names
3483 method getitem
n = (MTE.names
.(n), 0)
3484 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3485 ignore
(uioh
, first, pan
);
3486 if not
cancel then set active;
3488 method hasaction
_ = true
3492 let modehash = findkeyhash conf
"info" in
3493 coe (new listview ~zebra
:false ~helpmode
:false
3494 ~
source ~trusted
:true ~
modehash)
3497 method fitmodel name get
set =
3499 (name
, `
string get
, 1,
3504 inherit lvsourcebase
3507 m_active
<- FMTE.to_int conf
.fitmodel
;
3510 method getitemcount
= Array.length
FMTE.names
3511 method getitem
n = (FMTE.names
.(n), 0)
3512 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3513 ignore
(uioh
, first, pan
);
3514 if not
cancel then set active;
3516 method hasaction
_ = true
3520 let modehash = findkeyhash conf
"info" in
3521 coe (new listview ~zebra
:false ~helpmode
:false
3522 ~
source ~trusted
:true ~
modehash)
3525 method caption
s offset
=
3526 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3528 method caption2
s f offset
=
3529 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3531 method getitemcount
= Array.length m_a
3534 let tostr = function
3535 | `
int f -> string_of_int
(f ())
3536 | `intws
f -> string_with_suffix_of_int
(f ())
3538 | `
color f -> color_to_string
(f ())
3539 | `
bool (btos, f) -> btos (f ())
3542 let name, t
, offset
, _ = m_a
.(n) in
3543 ((let s = tostr t
in
3545 then Printf.sprintf
"%s\t%s" name s
3549 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3554 match m_a
.(active) with
3555 | _, _, _, Action
f -> f uioh
3556 | _, _, _, Noaction
-> uioh
3567 method hasaction
n =
3569 | _, _, _, Action
_ -> true
3570 | _, _, _, Noaction
-> false
3572 initializer m_active
<- 1
3575 let rec fillsrc prevmode prevuioh
=
3576 let sep () = src#caption
E.s 0 in
3577 let colorp name get
set =
3579 (fun () -> color_to_string
(get
()))
3582 let c = color_of_string
v in
3586 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3589 let oldmode = state
.mode
in
3590 let birdseye = isbirdseye state
.mode
in
3592 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3594 src#
bool "presentation mode"
3595 (fun () -> conf
.presentation
)
3596 (fun v -> setpresentationmode v);
3598 src#
bool "ignore case in searches"
3599 (fun () -> conf
.icase
)
3600 (fun v -> conf
.icase
<- v);
3603 (fun () -> conf
.preload)
3604 (fun v -> conf
.preload <- v);
3606 src#
bool "highlight links"
3607 (fun () -> conf
.hlinks
)
3608 (fun v -> conf
.hlinks
<- v);
3610 src#
bool "under info"
3611 (fun () -> conf
.underinfo
)
3612 (fun v -> conf
.underinfo
<- v);
3614 src#
bool "persistent bookmarks"
3615 (fun () -> conf
.savebmarks
)
3616 (fun v -> conf
.savebmarks
<- v);
3618 src#fitmodel
"fit model"
3619 (fun () -> FMTE.to_string conf
.fitmodel
)
3620 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3622 src#
bool "trim margins"
3623 (fun () -> conf
.trimmargins
)
3624 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3626 src#
bool "persistent location"
3627 (fun () -> conf
.jumpback
)
3628 (fun v -> conf
.jumpback
<- v);
3631 src#
int "inter-page space"
3632 (fun () -> conf
.interpagespace
)
3634 conf
.interpagespace
<- n;
3635 docolumns conf
.columns
;
3637 match state
.layout with
3642 state
.maxy <- calcheight
();
3643 let y = getpagey
pageno in
3644 gotoxy state
.x (y + py)
3648 (fun () -> conf
.pagebias
)
3649 (fun v -> conf
.pagebias
<- v);
3651 src#
int "scroll step"
3652 (fun () -> conf
.scrollstep
)
3653 (fun n -> conf
.scrollstep
<- n);
3655 src#
int "horizontal scroll step"
3656 (fun () -> conf
.hscrollstep
)
3657 (fun v -> conf
.hscrollstep
<- v);
3659 src#
int "auto scroll step"
3661 match state
.autoscroll
with
3663 | _ -> conf
.autoscrollstep
)
3665 let n = boundastep state
.winh
n in
3666 if state
.autoscroll
<> None
3667 then state
.autoscroll
<- Some
n;
3668 conf
.autoscrollstep
<- n);
3671 (fun () -> truncate
(conf
.zoom *. 100.))
3672 (fun v -> pivotzoom ((float v) /. 100.));
3675 (fun () -> conf
.angle
)
3676 (fun v -> reqlayout v conf
.fitmodel
);
3678 src#
int "scroll bar width"
3679 (fun () -> conf
.scrollbw
)
3682 reshape state
.winw state
.winh
;
3685 src#
int "scroll handle height"
3686 (fun () -> conf
.scrollh
)
3687 (fun v -> conf
.scrollh
<- v;);
3689 src#
int "thumbnail width"
3690 (fun () -> conf
.thumbw
)
3692 conf
.thumbw
<- min
4096 v;
3695 leavebirdseye beye
false;
3702 let mode = state
.mode in
3703 src#
string "columns"
3705 match conf
.columns
with
3707 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3708 | Csplit
(count
, _) -> "-" ^ string_of_int count
3711 let n, a, b = multicolumns_of_string
v in
3712 setcolumns mode n a b);
3715 src#caption
"Pixmap cache" 0;
3716 src#int_with_suffix
"size (advisory)"
3717 (fun () -> conf
.memlimit
)
3718 (fun v -> conf
.memlimit
<- v);
3722 Printf.sprintf
"%s bytes, %d tiles"
3723 (string_with_suffix_of_int state
.memused
)
3724 (Hashtbl.length state
.tilemap
)) 1;
3727 src#caption
"Layout" 0;
3728 src#caption2
"Dimension"
3730 Printf.sprintf
"%dx%d (virtual %dx%d)"
3731 state
.winw state
.winh
3736 src#caption2
"Position" (fun () ->
3737 Printf.sprintf
"%dx%d" state
.x state
.y
3740 src#caption2
"Position" (fun () -> describe_location ()) 1
3744 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3745 "Save these parameters as global defaults at exit"
3746 (fun () -> conf
.bedefault
)
3747 (fun v -> conf
.bedefault
<- v)
3751 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3752 src#
bool ~offset
:0 ~
btos "Extended parameters"
3753 (fun () -> !showextended)
3754 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3758 (fun () -> conf
.checkers
)
3759 (fun v -> conf
.checkers
<- v; setcheckers v);
3760 src#
bool "update cursor"
3761 (fun () -> conf
.updatecurs
)
3762 (fun v -> conf
.updatecurs
<- v);
3763 src#
bool "scroll-bar on the left"
3764 (fun () -> conf
.leftscroll
)
3765 (fun v -> conf
.leftscroll
<- v);
3767 (fun () -> conf
.verbose
)
3768 (fun v -> conf
.verbose
<- v);
3769 src#
bool "invert colors"
3770 (fun () -> conf
.invert
)
3771 (fun v -> conf
.invert
<- v);
3773 (fun () -> conf
.maxhfit
)
3774 (fun v -> conf
.maxhfit
<- v);
3776 (fun () -> conf
.pax
!= None
)
3779 then conf
.pax
<- Some
(ref (now
(), 0, 0))
3780 else conf
.pax
<- None
);
3781 src#
string "uri launcher"
3782 (fun () -> conf
.urilauncher
)
3783 (fun v -> conf
.urilauncher
<- v);
3784 src#
string "path launcher"
3785 (fun () -> conf
.pathlauncher
)
3786 (fun v -> conf
.pathlauncher
<- v);
3787 src#
string "tile size"
3788 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3791 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3792 conf
.tilew
<- max
64 w;
3793 conf
.tileh
<- max
64 h;
3796 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3799 src#
int "texture count"
3800 (fun () -> conf
.texcount
)
3803 then conf
.texcount
<- v
3804 else impmsg "failed to set texture count please retry later"
3806 src#
int "slice height"
3807 (fun () -> conf
.sliceheight
)
3809 conf
.sliceheight
<- v;
3810 wcmd "sliceh %d" conf
.sliceheight
;
3812 src#
int "anti-aliasing level"
3813 (fun () -> conf
.aalevel
)
3815 conf
.aalevel
<- bound
v 0 8;
3816 state
.anchor <- getanchor
();
3817 opendoc state
.path state
.password;
3819 src#
string "page scroll scaling factor"
3820 (fun () -> string_of_float conf
.pgscale)
3823 let s = float_of_string
v in
3826 state
.text <- Printf.sprintf
3827 "bad page scroll scaling factor `%s': %s" v
3831 src#
int "ui font size"
3832 (fun () -> fstate
.fontsize
)
3833 (fun v -> setfontsize (bound
v 5 100));
3834 src#
int "hint font size"
3835 (fun () -> conf
.hfsize
)
3836 (fun v -> conf
.hfsize
<- bound
v 5 100);
3837 colorp "background color"
3838 (fun () -> conf
.bgcolor
)
3839 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3840 src#
bool "crop hack"
3841 (fun () -> conf
.crophack
)
3842 (fun v -> conf
.crophack
<- v);
3843 src#
string "trim fuzz"
3844 (fun () -> irect_to_string conf
.trimfuzz
)
3847 conf
.trimfuzz
<- irect_of_string
v;
3849 then settrim true conf
.trimfuzz
;
3851 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3854 src#
string "throttle"
3856 match conf
.maxwait
with
3857 | None
-> "show place holder if page is not ready"
3860 then "wait for page to fully render"
3862 "wait " ^ string_of_float
time
3863 ^
" seconds before showing placeholder"
3867 let f = float_of_string
v in
3869 then conf
.maxwait
<- None
3870 else conf
.maxwait
<- Some
f
3872 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3875 src#
string "ghyll scroll"
3877 match conf
.ghyllscroll
with
3879 | Some nab
-> ghyllscroll_to_string nab
3882 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3885 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3887 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3890 src#
string "selection command"
3891 (fun () -> conf
.selcmd
)
3892 (fun v -> conf
.selcmd
<- v);
3893 src#
string "synctex command"
3894 (fun () -> conf
.stcmd
)
3895 (fun v -> conf
.stcmd
<- v);
3896 src#
string "pax command"
3897 (fun () -> conf
.paxcmd
)
3898 (fun v -> conf
.paxcmd
<- v);
3899 src#
string "ask password command"
3900 (fun () -> conf
.passcmd)
3901 (fun v -> conf
.passcmd <- v);
3902 src#
string "save path command"
3903 (fun () -> conf
.savecmd
)
3904 (fun v -> conf
.savecmd
<- v);
3905 src#colorspace
"color space"
3906 (fun () -> CSTE.to_string conf
.colorspace
)
3908 conf
.colorspace
<- CSTE.of_int
v;
3912 src#paxmark
"pax mark method"
3913 (fun () -> MTE.to_string conf
.paxmark
)
3914 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3915 if bousable
() && !opengl_has_pbo
3918 (fun () -> conf
.usepbo
)
3919 (fun v -> conf
.usepbo
<- v);
3920 src#
bool "mouse wheel scrolls pages"
3921 (fun () -> conf
.wheelbypage
)
3922 (fun v -> conf
.wheelbypage
<- v);
3923 src#
bool "open remote links in a new instance"
3924 (fun () -> conf
.riani
)
3925 (fun v -> conf
.riani
<- v);
3926 src#
bool "edit annotations inline"
3927 (fun () -> conf
.annotinline
)
3928 (fun v -> conf
.annotinline
<- v);
3929 src#
bool "coarse positioning in presentation mode"
3930 (fun () -> conf
.coarseprespos
)
3931 (fun v -> conf
.coarseprespos
<- v);
3932 src#
bool "use document CSS"
3933 (fun () -> conf
.usedoccss
)
3935 conf
.usedoccss
<- v;
3936 state
.anchor <- getanchor
();
3937 opendoc state
.path state
.password;
3942 src#caption
"Document" 0;
3943 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3944 src#caption2
"Pages"
3945 (fun () -> string_of_int state
.pagecount
) 1;
3946 src#caption2
"Dimensions"
3947 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3948 if nonemptystr conf
.css
3949 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3953 src#caption
"Trimmed margins" 0;
3954 src#caption2
"Dimensions"
3955 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3959 src#caption
"OpenGL" 0;
3960 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3961 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3964 src#caption
"Location" 0;
3965 if nonemptystr state
.origin
3966 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3967 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3969 src#reset prevmode prevuioh
;
3974 let prevmode = state
.mode
3975 and prevuioh
= state
.uioh in
3976 fillsrc prevmode prevuioh
;
3977 let source = (src :> lvsource
) in
3978 let modehash = findkeyhash conf
"info" in
3981 inherit listview ~zebra
:false ~helpmode
:false
3982 ~
source ~trusted
:true ~
modehash as super
3983 val mutable m_prevmemused
= 0
3984 method! infochanged
= function
3986 if m_prevmemused
!= state
.memused
3988 m_prevmemused
<- state
.memused
;
3989 G.postRedisplay "memusedchanged";
3991 | Pdim
-> G.postRedisplay "pdimchanged"
3992 | Docinfo
-> fillsrc prevmode prevuioh
3994 method! key key mask
=
3995 if not
(Wsi.withctrl mask
)
3998 match [@warning
"-4"] Wsi.kc2kt
key with
3999 | Left
| KPleft
-> coe (self#updownlevel ~
-1)
4000 | Right
| KPright
-> coe (self#updownlevel
1)
4001 | _ -> super#
key key mask
4002 else super#
key key mask
4004 G.postRedisplay "info";
4010 inherit lvsourcebase
4011 method getitemcount
= Array.length state
.help
4013 let s, l, _ = state
.help
.(n) in
4016 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4020 match state
.help
.(active) with
4021 | _, _, Action
f -> Some
(f uioh)
4022 | _, _, Noaction
-> Some
uioh
4031 method hasaction
n =
4032 match state
.help
.(n) with
4033 | _, _, Action
_ -> true
4034 | _, _, Noaction
-> false
4040 let modehash = findkeyhash conf
"help" in
4042 state
.uioh <- coe (new listview
4043 ~zebra
:false ~helpmode
:true
4044 ~
source ~trusted
:true ~
modehash);
4045 G.postRedisplay "help";
4051 inherit lvsourcebase
4052 val mutable m_items
= E.a
4054 method getitemcount
= 1 + Array.length m_items
4059 else m_items
.(n-1), 0
4061 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4066 then Buffer.clear state
.errmsgs
;
4073 method hasaction
n =
4077 state
.newerrmsgs
<- false;
4078 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4079 m_items
<- Array.of_list
l
4088 let source = (msgsource :> lvsource
) in
4089 let modehash = findkeyhash conf
"listview" in
4092 inherit listview ~zebra
:false ~helpmode
:false
4093 ~
source ~trusted
:false ~
modehash as super
4096 then msgsource#reset
;
4099 G.postRedisplay "msgs";
4103 let editor = getenvwithdef
"EDITOR" E.s in
4107 let tmppath = Filename.temp_file
"llpp" "note" in
4110 let oc = open_out
tmppath in
4114 let execstr = editor ^
" " ^
tmppath in
4116 match spawn
execstr [] with
4118 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4121 match Unix.waitpid
[] pid
with
4123 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4127 | Unix.WEXITED
0 -> filecontents
tmppath
4129 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4131 | Unix.WSIGNALED
n ->
4132 impmsg "editor process(%s) was killed by signal %d" execstr n;
4134 | Unix.WSTOPPED
n ->
4135 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4138 match Unix.unlink
tmppath with
4140 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4145 let enterannotmode opaque slinkindex
=
4148 inherit lvsourcebase
4149 val mutable m_text
= E.s
4150 val mutable m_items
= E.a
4152 method getitemcount
= Array.length m_items
4155 let label, _func
= m_items
.(n) in
4158 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4159 ignore
(uioh, first, pan
);
4162 let _label, func
= m_items
.(active) in
4167 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4170 let rec split accu b i
=
4172 if p = String.length
s
4173 then (String.sub s b (p-b), unit) :: accu
4175 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4177 let ss = if i
= 0 then E.s else String.sub s b i
in
4178 split ((ss, unit)::accu) (p+1) 0
4183 wcmd "freepage %s" (~
> opaque);
4185 Hashtbl.fold (fun key opaque'
accu ->
4186 if opaque'
= opaque'
4187 then key :: accu else accu) state
.pagemap
[]
4189 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4191 gotoxy state
.x state
.y
4194 delannot
opaque slinkindex
;
4197 let edit inline
() =
4202 modannot
opaque slinkindex
s;
4208 let mode = state
.mode in
4211 ("annotation: ", m_text
, None
, textentry
, update, true),
4212 fun _ -> state
.mode <- mode);
4216 let s = getusertext m_text
in
4221 ( "[Copy]", fun () -> selstring m_text
)
4222 :: ("[Delete]", dele)
4223 :: ("[Edit]", edit conf
.annotinline
)
4225 :: split [] 0 0 |> List.rev
|> Array.of_list
4232 let s = getannotcontents
opaque slinkindex
in
4235 let source = (msgsource :> lvsource
) in
4236 let modehash = findkeyhash conf
"listview" in
4237 state
.uioh <- coe (object
4238 inherit listview ~zebra
:false ~helpmode
:false
4239 ~
source ~trusted
:false ~
modehash
4241 G.postRedisplay "enterannotmode";
4244 let gotoremote spec
=
4245 let filename, dest
= splitatchar spec '#'
in
4246 let getpath filename =
4248 if nonemptystr
filename
4250 if Filename.is_relative
filename
4252 let dir = Filename.dirname state
.path in
4254 if Filename.is_implicit
dir
4255 then Filename.concat
(Sys.getcwd
()) dir
4258 Filename.concat
dir filename
4262 if Sys.file_exists
path
4266 let path = getpath filename in
4270 let cmd = Lazy.force_val lcmd
in
4271 match spawn
cmd with
4273 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4275 let anchor = getanchor
() in
4276 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4277 state
.origin
<- E.s;
4278 state
.ranchors
<- ranchor :: state
.ranchors
;
4281 if substratis spec
0 "page="
4283 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4285 state
.anchor <- (pageno, 0.0, 0.0);
4286 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4288 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4290 state
.nameddest
<- dest
;
4291 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4295 let gotounder = function
4296 | Ulinkuri
s when isexternallink
s ->
4297 if substratis
s 0 "file://"
4298 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4301 let pageno, x, y = uritolocation
s in
4303 gotopagexy !wtmode pageno x y
4304 | Utext
_ | Unone
-> ()
4305 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4308 let gotooutline (_, _, kind
) =
4312 let (pageno, y, _) = anchor in
4314 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4318 | Ouri
uri -> gotounder (Ulinkuri
uri)
4319 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4320 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4321 | Ohistory hist
-> gotohist hist
4322 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4325 class outlinesoucebase fetchoutlines
= object (self)
4326 inherit lvsourcebase
4327 val mutable m_items
= E.a
4328 val mutable m_minfo
= E.a
4329 val mutable m_orig_items
= E.a
4330 val mutable m_orig_minfo
= E.a
4331 val mutable m_narrow_patterns
= []
4332 val mutable m_gen
= -1
4334 method getitemcount
= Array.length m_items
4337 let s, n, _ = m_items
.(n) in
4340 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4341 ignore
(uioh, first);
4343 if m_narrow_patterns
= []
4344 then m_orig_items
, m_orig_minfo
4345 else m_items
, m_minfo
4352 gotooutline m_items
.(active);
4360 method hasaction
(_:int) = true
4363 if Array.length m_items
!= Array.length m_orig_items
4366 match m_narrow_patterns
with
4368 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4370 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4374 match m_narrow_patterns
with
4377 | head
:: _ -> UniSyms.ellipsis ^ head
4379 method narrow
pattern =
4380 match Str.regexp_case_fold
pattern with
4383 let rec loop accu minfo n =
4386 m_items
<- Array.of_list
accu;
4387 m_minfo
<- Array.of_list
minfo;
4390 let (s, _, _) as o = m_items
.(n) in
4392 match Str.search_forward re
s 0 with
4393 | exception Not_found
-> accu, minfo
4394 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4396 loop accu minfo (n-1)
4398 loop [] [] (Array.length m_items
- 1)
4400 method! getminfo
= m_minfo
4403 m_orig_items
<- fetchoutlines
();
4404 m_minfo
<- m_orig_minfo
;
4405 m_items
<- m_orig_items
4407 method add_narrow_pattern
pattern =
4408 m_narrow_patterns
<- pattern :: m_narrow_patterns
4410 method del_narrow_pattern
=
4411 match m_narrow_patterns
with
4412 | _ :: rest
-> m_narrow_patterns
<- rest
4417 match m_narrow_patterns
with
4418 | pattern :: [] -> self#narrow
pattern; pattern
4420 List.fold_left
(fun accu pattern ->
4421 self#narrow
pattern;
4422 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4424 method calcactive
(_:anchor) = 0
4426 method reset
anchor items =
4427 if state
.gen
!= m_gen
4429 m_orig_items
<- items;
4431 m_narrow_patterns
<- [];
4433 m_orig_minfo
<- E.a;
4437 if items != m_orig_items
4439 m_orig_items
<- items;
4440 if m_narrow_patterns
== []
4441 then m_items
<- items;
4444 let active = self#calcactive
anchor in
4446 m_first
<- firstof m_first
active
4450 let outlinesource fetchoutlines
=
4452 inherit outlinesoucebase fetchoutlines
4453 method! calcactive
anchor =
4454 let rely = getanchory anchor in
4455 let rec loop n best bestd
=
4456 if n = Array.length m_items
4459 let _, _, kind
= m_items
.(n) in
4462 let orely = getanchory anchor in
4463 let d = abs
(orely - rely) in
4466 else loop (n+1) best bestd
4467 | Onone
| Oremote
_ | Olaunch
_
4468 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4469 loop (n+1) best bestd
4475 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4476 let mkselector sourcetype
=
4477 let fetchoutlines () =
4478 match sourcetype
with
4479 | `bookmarks
-> Array.of_list state
.bookmarks
4480 | `outlines
-> state
.outlines
4481 | `history
-> genhistoutlines ()
4484 if sourcetype
= `history
4485 then new outlinesoucebase
fetchoutlines
4486 else outlinesource fetchoutlines
4489 let outlines = fetchoutlines () in
4490 if Array.length
outlines = 0
4492 showtext ' ' errmsg
;
4496 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4497 let anchor = getanchor
() in
4498 source#reset
anchor outlines;
4499 state
.text <- source#greetmsg
;
4501 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4502 G.postRedisplay "enter selector";
4505 let mkenter sourcetype errmsg
=
4506 let enter = mkselector sourcetype
in
4507 fun () -> enter errmsg
4509 mkenter `
outlines "document has no outline"
4510 , mkenter `bookmarks
"document has no bookmarks (yet)"
4511 , mkenter `history
"history is empty"
4514 let quickbookmark ?title
() =
4515 match state
.layout with
4521 let tm = Unix.localtime
(now
()) in
4523 "Quick (page %d) (bookmarked at %02d/%02d/%d %02d:%02d)"
4527 (tm.Unix.tm_year
+ 1900)
4530 | Some
title -> title
4532 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4535 let setautoscrollspeed step goingdown
=
4536 let incr = max
1 ((abs step
) / 2) in
4537 let incr = if goingdown
then incr else -incr in
4538 let astep = boundastep state
.winh
(step
+ incr) in
4539 state
.autoscroll
<- Some
astep;
4543 match conf
.columns
with
4545 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4548 let panbound x = bound
x (-state
.w) state
.winw
;;
4550 let existsinrow pageno (columns
, coverA
, coverB
) p =
4551 let last = ((pageno - coverA
) mod columns
) + columns
in
4552 let rec any = function
4555 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4559 then (if l.pageno = last then false else any rest
)
4567 match state
.layout with
4569 let pageno = page_of_y state
.y in
4570 gotoghyll (getpagey
(pageno+1))
4572 match conf
.columns
with
4574 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4576 let y = clamp (pgscale state
.winh
) in
4579 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4580 gotoghyll (getpagey
pageno)
4581 | Cmulti
((c, _, _) as cl
, _) ->
4582 if conf
.presentation
4583 && (existsinrow l.pageno cl
4584 (fun l -> l.pageh
> l.pagey + l.pagevh))
4586 let y = clamp (pgscale state
.winh
) in
4589 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4590 gotoghyll (getpagey
pageno)
4592 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4594 let pagey, pageh
= getpageyh
l.pageno in
4595 let pagey = pagey + pageh
* l.pagecol
in
4596 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4597 gotoghyll (pagey + pageh
+ ips)
4601 match state
.layout with
4603 let pageno = page_of_y state
.y in
4604 gotoghyll (getpagey
(pageno-1))
4606 match conf
.columns
with
4608 if conf
.presentation
&& l.pagey != 0
4610 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4612 let pageno = max
0 (l.pageno-1) in
4613 gotoghyll (getpagey
pageno)
4614 | Cmulti
((c, _, coverB
) as cl
, _) ->
4615 if conf
.presentation
&&
4616 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4618 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4621 if l.pageno = state
.pagecount
- coverB
4625 let pageno = max
0 (l.pageno-decr) in
4626 gotoghyll (getpagey
pageno)
4634 let pageno = max
0 (l.pageno-1) in
4635 let pagey, pageh
= getpageyh
pageno in
4638 let pagey, pageh
= getpageyh
l.pageno in
4639 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4645 if emptystr conf
.savecmd
4646 then error
"don't know where to save modified document"
4648 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4651 (fun s -> error
"failed to obtain path to the saved copy: %s" s)
4656 let tmp = path ^
".tmp" in
4658 Unix.rename
tmp path;
4661 let viewkeyboard key mask
=
4663 let mode = state
.mode in
4664 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4667 G.postRedisplay "view:enttext"
4669 let ctrl = Wsi.withctrl mask
in
4671 match Wsi.kc2kt
key with
4672 | Ascii 'Q'
-> exit
0
4675 if hasunsavedchanges
()
4679 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4682 match state
.lnava
with
4683 | None
-> LinkNav
(Ltgendir
0)
4684 | Some
pn -> LinkNav
(Ltexact
pn)
4686 gotoxy state
.x state
.y;
4688 else impmsg "keyboard link navigation does not work under rotation"
4690 | Escape
| Ascii 'q'
->
4691 begin match state
.mstate
with
4694 G.postRedisplay "kill rect";
4697 | Mscrolly
| Mscrollx
4700 begin match state
.mode with
4703 | Ltexact pl
-> state
.lnava
<- Some pl
4704 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4707 G.postRedisplay "esc leave linknav"
4708 | Birdseye
_ | Textentry
_ | View
->
4709 match state
.ranchors
with
4711 | (path, password, anchor, origin
) :: rest
->
4712 state
.ranchors
<- rest
;
4713 state
.anchor <- anchor;
4714 state
.origin
<- origin
;
4715 state
.nameddest
<- E.s;
4716 opendoc path password
4721 gotoghyll (getnav ~
-1)
4732 Hashtbl.iter
(fun _ opaque ->
4734 Hashtbl.clear state
.prects
) state
.pagemap
;
4735 G.postRedisplay "dehighlight";
4737 | (Ascii '
/'
| Ascii '?'
) as pv
->
4738 let ondone isforw
s =
4739 cbput state
.hists
.pat
s;
4740 state
.searchpattern
<- s;
4743 let s = String.make
1 (Char.chr
key) in
4744 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4745 textentry
, ondone (pv
= Ascii '
/'
), true)
4747 | Ascii '
+'
| KPplus
| Ascii '
='
when ctrl ->
4748 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4749 pivotzoom (conf
.zoom +. incr)
4751 | Ascii '
+'
| KPplus
->
4754 try int_of_string
s with exn
->
4755 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4761 state
.text <- "page bias is now " ^ string_of_int
n;
4764 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4766 | Ascii '
-'
| KPminus
when ctrl ->
4767 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4768 pivotzoom (max
0.01 (conf
.zoom -. decr))
4770 | Ascii '
-'
| KPminus
->
4771 let ondone msg
= state
.text <- msg
in
4773 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4774 optentry state
.mode, ondone, true
4777 | Ascii '
0'
when ctrl ->
4779 then gotoxy 0 state
.y
4782 | Ascii
('
1'
|'
2'
as c)
4783 when ctrl && conf
.fitmodel
!= FitPage
->
4785 match conf
.columns
with
4786 | Csingle
_ | Cmulti
_ -> 1
4787 | Csplit
(n, _) -> n
4789 let h = state
.winh
-
4790 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4792 let zoom = zoomforh state
.winw
h 0 cols in
4793 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4796 | Ascii '
3'
when ctrl ->
4798 match conf
.fitmodel
with
4799 | FitWidth
-> FitProportional
4800 | FitProportional
-> FitPage
4801 | FitPage
-> FitWidth
4803 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4804 reqlayout conf
.angle
fm
4806 | Ascii '
4'
when ctrl ->
4807 let zoom = getmaxw
() /. float state
.winw
in
4808 if zoom > 0.0 then setzoom zoom
4813 | Ascii '
9'
when ctrl ->
4820 try int_of_string
s with exn
->
4821 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4827 cbput state
.hists
.pag
(string_of_int
n);
4828 gotopage1 (n + conf
.pagebias
- 1) 0;
4831 let [@warning
"-4"] pageentry
text = function
4832 | Keys.Ascii '
g'
-> TEdone
text
4833 | key -> intentry
text key
4835 let text = String.make
1 (Char.chr
key) in
4836 enttext (":", text, Some
(onhist state
.hists
.pag
),
4837 pageentry
, ondone, true)
4840 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4841 G.postRedisplay "toggle scrollbar";
4844 state
.bzoom
<- not state
.bzoom
;
4846 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4849 conf
.hlinks
<- not conf
.hlinks
;
4850 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4851 G.postRedisplay "toggle highlightlinks";
4854 if conf
.angle
mod 360 = 0
4856 state
.glinks
<- true;
4857 let mode = state
.mode in
4860 (":", E.s, None
, linknentry
, linknact gotounder, false),
4862 state
.glinks
<- false;
4866 G.postRedisplay "view:linkent(F)"
4868 else impmsg "hint mode does not work under rotation"
4871 state
.glinks
<- true;
4872 let mode = state
.mode in
4876 ":", E.s, None
, linknentry
, linknact (fun under ->
4877 selstring (undertext under);
4881 state
.glinks
<- false;
4885 G.postRedisplay "view:linkent"
4888 begin match state
.autoscroll
with
4890 conf
.autoscrollstep
<- step
;
4891 state
.autoscroll
<- None
4893 if conf
.autoscrollstep
= 0
4894 then state
.autoscroll
<- Some
1
4895 else state
.autoscroll
<- Some conf
.autoscrollstep
4898 | Ascii '
p'
when ctrl ->
4899 launchpath () (* XXX where do error messages go? *)
4902 setpresentationmode (not conf
.presentation
);
4903 showtext ' '
("presentation mode " ^
4904 if conf
.presentation
then "on" else "off");
4907 if List.mem
Wsi.Fullscreen state
.winstate
4908 then Wsi.reshape conf
.cwinw conf
.cwinh
4909 else Wsi.fullscreen
()
4911 | Ascii
('
p'
|'N'
) ->
4912 search state
.searchpattern
false
4914 | Ascii '
n'
| Fn
3 ->
4915 search state
.searchpattern
true
4918 begin match state
.layout with
4921 gotoghyll (getpagey
l.pageno)
4927 | Delete
| KPdelete
->
4931 showtext ' '
(describe_location ());
4934 begin match state
.layout with
4937 Wsi.reshape l.pagew
l.pageh
;
4942 enterbookmarkmode
()
4944 | Ascii '
h'
| Fn
1 ->
4950 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4955 match state
.layout with
4960 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4963 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
4967 showtext ' '
"Quick bookmark added";
4970 begin match state
.layout with
4972 let rect = getpdimrect
l.pagedimno
in
4976 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4977 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4979 (truncate
(rect.(1) -. rect.(0)),
4980 truncate
(rect.(3) -. rect.(0)))
4982 let w = truncate
((float w)*.conf
.zoom)
4983 and h = truncate
((float h)*.conf
.zoom) in
4986 state
.anchor <- getanchor
();
4987 Wsi.reshape w (h + conf
.interpagespace
)
4989 G.postRedisplay "z";
4994 | Ascii '
x'
-> state
.roam
()
4996 | Ascii
('
<'
|'
>'
as c) ->
4998 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5000 | Ascii
('
['
|'
]'
as c) ->
5002 bound
(conf
.colorscale
+. (if c = '
>'
then 0.1 else -0.1)) 0.0 1.0;
5003 G.postRedisplay "brightness";
5005 | Ascii '
c'
when state
.mode = View
->
5010 let m = (state
.winw
- state
.w) / 2 in
5011 gotoxy_and_clear_text m state
.y
5015 match state
.prevcolumns
with
5016 | None
-> (1, 0, 0), 1.0
5017 | Some
(columns
, z
) ->
5020 | Csplit
(c, _) -> -c, 0, 0
5021 | Cmulti
((c, a, b), _) -> c, a, b
5022 | Csingle
_ -> 1, 0, 0
5026 setcolumns View
c a b;
5029 | Down
| Up
when ctrl && Wsi.withshift mask
->
5030 let zoom, x = state
.prevzoom
in
5034 | Ascii 'k'
| Up
| KPup
->
5035 begin match state
.autoscroll
with
5037 begin match state
.mode with
5038 | Birdseye beye
-> upbirdseye 1 beye
5039 | Textentry
_ | View
| LinkNav
_ ->
5041 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5043 if not
(Wsi.withshift mask
) && conf
.presentation
5045 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5049 setautoscrollspeed n false
5052 | Ascii 'j'
| Down
| KPdown
->
5053 begin match state
.autoscroll
with
5055 begin match state
.mode with
5056 | Birdseye beye
-> downbirdseye 1 beye
5057 | Textentry
_ | View
| LinkNav
_ ->
5059 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5061 if not
(Wsi.withshift mask
) && conf
.presentation
5063 else gotoghyll1 true (clamp (conf
.scrollstep
))
5067 setautoscrollspeed n true
5070 | Left
| Right
| KPleft
| KPright
when not
(Wsi.withalt mask
) ->
5076 else conf
.hscrollstep
5079 let pv = Wsi.kc2kt
key in
5080 if pv = Keys.Left
|| pv = Keys.KPleft
then dx else -dx
5082 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5085 G.postRedisplay "left/right"
5088 | Prior
| KPprior
->
5092 match state
.layout with
5094 | l :: _ -> state
.y - l.pagey
5096 clamp (pgscale (-state
.winh
))
5104 match List.rev state
.layout with
5106 | l :: _ -> getpagey
l.pageno
5108 clamp (pgscale state
.winh
)
5112 | Ascii '
g'
| Home
| KPhome
->
5115 | Ascii 'G'
| End
| KPend
->
5117 gotoghyll (clamp state
.maxy)
5119 | Right
| KPright
when Wsi.withalt mask
->
5120 gotoghyll (getnav 1)
5121 | Left
| KPleft
when Wsi.withalt mask
->
5122 gotoghyll (getnav ~
-1)
5127 | Ascii '
v'
when conf
.debug
->
5130 match getopaque l.pageno with
5133 let x0, y0, x1, y1 = pagebbox
opaque in
5134 let rect = (float x0, float y0,
5137 float x0, float y1) in
5139 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5140 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5142 G.postRedisplay "v";
5145 let mode = state
.mode in
5146 let cmd = ref E.s in
5147 let onleave = function
5148 | Cancel
-> state
.mode <- mode
5151 match getopaque l.pageno with
5152 | Some
opaque -> pipesel opaque !cmd
5153 | None
-> ()) state
.layout;
5157 cbput state
.hists
.sel
s;
5161 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
5163 G.postRedisplay "|";
5164 state
.mode <- Textentry
(te, onleave);
5166 | (Ascii
_|Fn
_|Enter
|KPenter
|KPleft
|KPright
|Left
|Right
|Code
_) ->
5167 vlog "huh? %s" (Wsi.keyname
key)
5170 let linknavkeyboard key mask
linknav =
5171 let pv = Wsi.kc2kt
key in
5172 let getpage pageno =
5173 let rec loop = function
5175 | l :: _ when l.pageno = pageno -> Some
l
5176 | _ :: rest
-> loop rest
5177 in loop state
.layout
5179 let doexact (pageno, n) =
5180 match getopaque pageno, getpage pageno with
5181 | Some
opaque, Some
l ->
5182 if pv = Keys.Enter
|| pv = Keys.KPenter
5184 let under = getlink
opaque n in
5185 G.postRedisplay "link gotounder";
5193 Some
(findlink
opaque LDfirst
), -1
5196 Some
(findlink
opaque LDlast
), 1
5199 Some
(findlink
opaque (LDleft
n)), -1
5202 Some
(findlink
opaque (LDright
n)), 1
5205 Some
(findlink
opaque (LDup
n)), -1
5208 Some
(findlink
opaque (LDdown
n)), 1
5210 | Delete
|Escape
|Insert
|Enter
|KPdelete
|KPdown
|KPend
|KPenter
5211 | KPhome
|KPleft
|KPminus
|KPnext
|KPplus
|KPprior
|KPright
|KPup
5212 | Next
|Prior
|Ascii
_|Code
_|Fn
_|Backspace
-> None
, 0
5215 begin match findpwl
l.pageno dir with
5219 state
.mode <- LinkNav
(Ltgendir
dir);
5220 let y, h = getpageyh
pageno in
5223 then y + h - state
.winh
5228 begin match getopaque pageno, getpage pageno with
5229 | Some
opaque, Some
_ ->
5231 let ld = if dir > 0 then LDfirst
else LDlast
in
5234 begin match link with
5236 showlinktype (getlink
opaque m);
5237 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5238 G.postRedisplay "linknav jpage";
5239 | Lnotfound
-> notfound dir
5245 begin match opt with
5246 | Some Lnotfound
-> pwl l dir;
5247 | Some
(Lfound
m) ->
5251 let _, y0, _, y1 = getlinkrect
opaque m in
5253 then gotopage1 l.pageno y0
5255 let d = fstate
.fontsize
+ 1 in
5256 if y1 - l.pagey > l.pagevh - d
5257 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5258 else G.postRedisplay "linknav";
5260 showlinktype (getlink
opaque m);
5261 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5264 | None
-> viewkeyboard key mask
5266 | _ -> viewkeyboard key mask
5270 begin match linknav with
5271 | Ltexact pa
-> state
.lnava
<- Some pa
5272 | Ltgendir
_ | Ltnotready
_ -> ()
5275 G.postRedisplay "leave linknav"
5279 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5280 | Ltexact exact
-> doexact exact
5283 let keyboard key mask
=
5284 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5285 then wcmd "interrupt"
5286 else state
.uioh <- state
.uioh#
key key mask
5289 let birdseyekeyboard key mask
5290 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5292 match conf
.columns
with
5294 | Cmulti
((c, _, _), _) -> c
5295 | Csplit
_ -> failwith
"bird's eye split mode"
5297 let pgh layout = List.fold_left
5298 (fun m l -> max
l.pageh
m) state
.winh
layout in
5300 match Wsi.kc2kt
key with
5301 | Ascii '
l'
when Wsi.withctrl mask
->
5302 let y, h = getpageyh
pageno in
5303 let top = (state
.winh
- h) / 2 in
5304 gotoxy state
.x (max
0 (y - top))
5305 | Enter
| KPenter
-> leavebirdseye beye
false
5306 | Escape
-> leavebirdseye beye
true
5307 | Up
-> upbirdseye incr beye
5308 | Down
-> downbirdseye incr beye
5309 | Left
-> upbirdseye 1 beye
5310 | Right
-> downbirdseye 1 beye
5313 begin match state
.layout with
5317 state
.mode <- Birdseye
(
5318 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5320 gotopage1 l.pageno 0;
5323 let layout = layout state
.x (state
.y-state
.winh
)
5325 (pgh state
.layout) in
5327 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5329 state
.mode <- Birdseye
(
5330 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5332 gotopage1 l.pageno 0
5335 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5339 begin match List.rev state
.layout with
5341 let layout = layout state
.x
5342 (state
.y + (pgh state
.layout))
5343 state
.winw state
.winh
in
5344 begin match layout with
5346 let incr = l.pageh
- l.pagevh in
5351 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5353 G.postRedisplay "birdseye pagedown";
5355 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5359 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5360 gotopage1 l.pageno 0;
5363 | [] -> gotoxy state
.x (clamp state
.winh
)
5367 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5371 let pageno = state
.pagecount
- 1 in
5372 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5373 if not
(pagevisible state
.layout pageno)
5376 match List.rev state
.pdims
with
5378 | (_, _, h, _) :: _ -> h
5382 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5383 else G.postRedisplay "birdseye end";
5385 | Delete
|Insert
|KPdelete
|KPdown
|KPend
|KPhome
|KPleft
5386 | KPminus
|KPnext
|KPplus
|KPprior
|KPright
|KPup
|Ascii
_
5387 | Code
_|Fn
_|Backspace
-> viewkeyboard key mask
5392 match state
.mode with
5393 | Textentry
_ -> scalecolor 0.4
5394 | LinkNav
_ | View
-> scalecolor 1.0
5395 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5396 if l.pageno = hooverpageno
5399 if l.pageno = pageno
5401 let c = scalecolor 1.0 in
5403 GlDraw.line_width
3.0;
5404 let dispx = l.pagedispx in
5406 (float (dispx-1)) (float (l.pagedispy-1))
5407 (float (dispx+l.pagevw+1))
5408 (float (l.pagedispy+l.pagevh+1))
5410 GlDraw.line_width
1.0;
5419 let postdrawpage l linkindexbase
=
5420 match getopaque l.pageno with
5422 if tileready l l.pagex
l.pagey
5424 let x = l.pagedispx - l.pagex
5425 and y = l.pagedispy - l.pagey in
5427 match conf
.columns
with
5428 | Csingle
_ | Cmulti
_ ->
5429 (if conf
.hlinks
then 1 else 0)
5431 && not
(isbirdseye state
.mode) then 2 else 0)
5435 match state
.mode with
5436 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5442 Hashtbl.find_all state
.prects
l.pageno |>
5443 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5444 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5446 then (state
.redisplay
<- true; 0)
5452 let scrollindicator () =
5453 let sbw, ph
, sh = state
.uioh#
scrollph in
5454 let sbh, pw, sw = state
.uioh#scrollpw
in
5459 else ((state
.winw
- sbw), state
.winw
, 0)
5463 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5464 GlDraw.color (0.64, 0.64, 0.64) ~
alpha:0.7;
5465 filledrect (float x0) 0. (float x1) (float state
.winh
);
5467 (float hx0
) (float (state
.winh
- sbh))
5468 (float (hx0
+ state
.winw
)) (float state
.winh
)
5470 GlDraw.color (0.0, 0.0, 0.0) ~
alpha:0.7;
5472 filledrect (float x0) ph
(float x1) (ph
+. sh);
5473 let pw = pw +. float hx0
in
5474 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5479 match state
.mstate
with
5480 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5483 | Msel
((x0, y0), (x1, y1)) ->
5484 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5485 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5486 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5487 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5494 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5495 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5497 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5499 if l.pageno = pageno
5501 let dx = float (l.pagedispx - l.pagex
) in
5502 let dy = float (l.pagedispy - l.pagey) in
5503 let r, g, b, alpha = c in
5504 GlDraw.color (r, g, b) ~
alpha;
5505 filledrect2 (x0+.dx) (y0+.dy)
5517 begin match conf
.columns
, state
.layout with
5518 | Csingle
_, _ :: _ ->
5519 GlDraw.color (scalecolor2 conf
.bgcolor
);
5521 List.fold_left
(fun y l ->
5524 let x1 = l.pagedispx in
5525 let y1 = (l.pagedispy + l.pagevh) in
5526 filledrect (float x0) (float y0) (float x1) (float y1);
5527 let x0 = x1 + l.pagevw in
5528 let x1 = state
.winw
in
5529 filledrect1 (float x0) (float y0) (float x1) (float y1);
5533 and x1 = state
.winw
in
5535 and y1 = l.pagedispy in
5536 filledrect1 (float x0) (float y0) (float x1) (float y1);
5538 l.pagedispy + l.pagevh) 0 state
.layout
5541 and x1 = state
.winw
in
5543 and y1 = state
.winh
in
5544 filledrect1 (float x0) (float y0) (float x1) (float y1)
5545 | (Cmulti
_ | Csplit
_), _ | Csingle
_, [] ->
5546 GlClear.color (scalecolor2 conf
.bgcolor
);
5547 GlClear.clear
[`
color];
5549 List.iter
drawpage state
.layout;
5551 match state
.mode with
5552 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5553 begin match getopaque pageno with
5555 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5556 let color = (0.0, 0.0, 0.5, 0.5) in
5563 | None
-> state
.rects
5565 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5568 | View
-> state
.rects
5571 let rec postloop linkindexbase
= function
5573 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5574 postloop linkindexbase rest
5578 postloop 0 state
.layout;
5580 begin match state
.mstate
with
5581 | Mzoomrect
((x0, y0), (x1, y1)) ->
5583 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5584 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5585 filledrect (float x0) (float y0) (float x1) (float y1);
5589 | Mscrolly
| Mscrollx
5598 let zoomrect x y x1 y1 =
5601 and y0 = min
y y1 in
5602 let zoom = (float state
.w) /. float (x1 - x0) in
5605 if state
.w < state
.winw
5606 then (state
.winw
- state
.w) / 2
5609 match conf
.fitmodel
with
5610 | FitWidth
| FitProportional
-> simple ()
5612 match conf
.columns
with
5614 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5615 | Cmulti
_ | Csingle
_ -> simple ()
5617 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5618 state
.anchor <- getanchor
();
5623 let annot inline
x y =
5624 match unproject x y with
5625 | Some
(opaque, n, ux
, uy
) ->
5627 addannot
opaque ux uy
text;
5628 wcmd "freepage %s" (~
> opaque);
5629 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5631 gotoxy state
.x state
.y
5635 let ondone s = add s in
5636 let mode = state
.mode in
5637 state
.mode <- Textentry
(
5638 ("annotation: ", E.s, None
, textentry
, ondone, true),
5639 fun _ -> state
.mode <- mode);
5642 G.postRedisplay "annot"
5644 add @@ getusertext E.s
5649 let g opaque l px py =
5650 match rectofblock
opaque px py with
5652 let x0 = a.(0) -. 20. in
5653 let x1 = a.(1) +. 20. in
5654 let y0 = a.(2) -. 20. in
5655 let zoom = (float state
.w) /. (x1 -. x0) in
5656 let pagey = getpagey
l.pageno in
5657 let margin = (state
.w - l.pagew
)/2 in
5658 let nx = -truncate
x0 - margin in
5659 gotoxy_and_clear_text nx (pagey + truncate
y0);
5660 state
.anchor <- getanchor
();
5665 match conf
.columns
with
5667 impmsg "block zooming does not work properly in split columns mode"
5668 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5672 let winw = state
.winw - 1 in
5673 let s = float x /. float winw in
5674 let destx = truncate
(float (state
.w + winw) *. s) in
5675 gotoxy_and_clear_text (winw - destx) state
.y;
5676 state
.mstate
<- Mscrollx
;
5680 let s = float y /. float state
.winh
in
5681 let desty = truncate
(float (state
.maxy -
5682 (if conf
.maxhfit
then state
.winh
else 0))
5684 gotoxy_and_clear_text state
.x desty;
5685 state
.mstate
<- Mscrolly
;
5688 let viewmulticlick clicks
x y mask
=
5689 let g opaque l px py =
5697 if markunder
opaque px py mark
5701 match getopaque l.pageno with
5703 | Some
opaque -> pipesel opaque cmd
5705 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5706 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5711 G.postRedisplay "viewmulticlick";
5712 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5716 match conf
.columns
with
5718 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5721 let viewmouse button down
x y mask
=
5723 | n when (n == 4 || n == 5) && not down
->
5724 if Wsi.withctrl mask
5726 match state
.mstate
with
5727 | Mzoom
(oldn
, i
, (ftx
, fty
)) ->
5730 then abs
(ftx
- x) > 5 || abs
(fty
- y) > 5
5740 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5742 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5744 let zoom = conf
.zoom -. incr in
5746 then pivotzoom ~
x ~
y zoom
5747 else pivotzoom zoom;
5748 state
.mstate
<- Mzoom
(n, 0, (x, y));
5750 state
.mstate
<- Mzoom
(n, i
+1, (ftx
, fty
));
5752 else state
.mstate
<- Mzoom
(n, 0, (ftx
, fty
))
5756 | Mscrolly
| Mscrollx
5758 | Mnone
-> state
.mstate
<- Mzoom
(n, 0, (0, 0))
5761 match state
.autoscroll
with
5762 | Some step
-> setautoscrollspeed step
(n=4)
5764 if conf
.wheelbypage
|| conf
.presentation
5773 then -conf
.scrollstep
5774 else conf
.scrollstep
5776 let incr = incr * 2 in
5777 let y = clamp incr in
5778 gotoxy_and_clear_text state
.x y
5781 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5783 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5784 gotoxy_and_clear_text x state
.y
5786 | 1 when Wsi.withshift mask
->
5787 state
.mstate
<- Mnone
;
5790 match unproject x y with
5792 | Some
(_, pageno, ux
, uy
) ->
5793 let cmd = Printf.sprintf
5795 conf
.stcmd state
.path pageno ux uy
5797 match spawn
cmd [] with
5799 impmsg "execution of synctex command(%S) failed: %S"
5800 conf
.stcmd
@@ exntos exn
5804 | 1 when Wsi.withctrl mask
->
5807 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5808 state
.mstate
<- Mpan
(x, y)
5811 state
.mstate
<- Mnone
5816 if Wsi.withshift mask
5818 annot conf
.annotinline
x y;
5819 G.postRedisplay "addannot"
5823 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5824 state
.mstate
<- Mzoomrect
(p, p)
5827 match state
.mstate
with
5828 | Mzoomrect
((x0, y0), _) ->
5829 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5830 then zoomrect x0 y0 x y
5833 G.postRedisplay "kill accidental zoom rect";
5837 | Mscrolly
| Mscrollx
5839 | Mnone
-> resetmstate ()
5842 | 1 when vscrollhit x ->
5845 let _, position, sh = state
.uioh#
scrollph in
5846 if y > truncate
position && y < truncate
(position +. sh)
5847 then state
.mstate
<- Mscrolly
5850 state
.mstate
<- Mnone
5852 | 1 when y > state
.winh
- hscrollh () ->
5855 let _, position, sw = state
.uioh#scrollpw
in
5856 if x > truncate
position && x < truncate
(position +. sw)
5857 then state
.mstate
<- Mscrollx
5860 state
.mstate
<- Mnone
5862 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5865 let dest = if down
then getunder x y else Unone
in
5866 begin match dest with
5870 | Unone
when down
->
5871 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5872 state
.mstate
<- Mpan
(x, y);
5874 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5876 | Unone
| Utext
_ ->
5881 state
.mstate
<- Msel
((x, y), (x, y));
5882 G.postRedisplay "mouse select";
5886 match state
.mstate
with
5889 | Mzoom
_ | Mscrollx
| Mscrolly
->
5890 state
.mstate
<- Mnone
5892 | Mzoomrect
((x0, y0), _) ->
5896 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5897 state
.mstate
<- Mnone
5899 | Msel
((x0, y0), (x1, y1)) ->
5900 let rec loop = function
5904 let a0 = l.pagedispy in
5905 let a1 = a0 + l.pagevh in
5906 let b0 = l.pagedispx in
5907 let b1 = b0 + l.pagevw in
5908 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5909 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5913 match getopaque l.pageno with
5916 match Unix.pipe
() with
5918 impmsg "cannot create sel pipe: %s" @@
5922 Ne.clo fd
(fun msg
->
5923 dolog
"%s close failed: %s" what msg
)
5925 begin match spawn
cmd [r, 0; w, -1] with
5927 clo "Msel pipe/w" w;
5928 dolog
"cannot execute %S: %s" cmd @@ exntos exn
5931 G.postRedisplay "copysel";
5933 clo "Msel pipe/r" r;
5935 dosel conf
.selcmd
();
5936 state
.roam
<- dosel conf
.paxcmd
;
5948 let birdseyemouse button down
x y mask
5949 (conf
, leftx
, _, hooverpageno
, anchor) =
5952 let rec loop = function
5955 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5956 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5958 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5964 | _ -> viewmouse button down
x y mask
5970 method key key mask
=
5971 begin match state
.mode with
5972 | Textentry textentry
-> textentrykeyboard
key mask textentry
5973 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5974 | View
-> viewkeyboard key mask
5975 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5979 method button button bstate
x y mask
=
5980 begin match state
.mode with
5981 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5982 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5987 method multiclick clicks
x y mask
=
5988 begin match state
.mode with
5989 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5990 | Birdseye
_ | Textentry
_ -> ()
5995 begin match state
.mode with
5997 | View
| Birdseye
_ | LinkNav
_ ->
5998 match state
.mstate
with
5999 | Mzoom
_ | Mnone
-> ()
6004 state
.mstate
<- Mpan
(x, y);
6005 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6007 gotoxy_and_clear_text x y
6010 state
.mstate
<- Msel
(a, (x, y));
6011 G.postRedisplay "motion select";
6014 let y = min state
.winh
(max
0 y) in
6018 let x = min state
.winw (max
0 x) in
6021 | Mzoomrect
(p0
, _) ->
6022 state
.mstate
<- Mzoomrect
(p0
, (x, y));
6023 G.postRedisplay "motion zoomrect";
6027 method pmotion
x y =
6028 begin match state
.mode with
6029 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6030 let rec loop = function
6032 if hooverpageno
!= -1
6034 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6035 G.postRedisplay "pmotion birdseye no hoover";
6038 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6039 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6041 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6042 G.postRedisplay "pmotion birdseye hoover";
6050 | LinkNav
_ | View
->
6051 match state
.mstate
with
6052 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6060 let past, _, _ = !r in
6062 let delta = now -. past in
6065 else r := (now, x, y)
6069 method infochanged
_ = ()
6072 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
6075 then 0.0, float state
.winh
6076 else scrollph state
.y maxy
6081 let fwinw = float (state
.winw - vscrollw ()) in
6083 let sw = fwinw /. float state
.w in
6084 let sw = fwinw *. sw in
6085 max
sw (float conf
.scrollh
)
6088 let maxx = state
.w + state
.winw in
6089 let x = state
.winw - state
.x in
6090 let percent = float x /. float maxx in
6091 (fwinw -. sw) *. percent
6093 hscrollh (), position, sw
6097 match state
.mode with
6098 | LinkNav
_ -> "links"
6099 | Textentry
_ -> "textentry"
6100 | Birdseye
_ -> "birdseye"
6103 findkeyhash conf
modename
6105 method eformsgs
= true
6106 method alwaysscrolly
= false
6109 let addrect pageno r g b a x0 y0 x1 y1 =
6110 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6114 let cl = splitatchar cmds ' '
in
6116 try Scanf.sscanf
s fmt
f
6117 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6120 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6121 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6122 s pageno r g b a x0 y0 x1 y1;
6126 let _,w1,h1
,_ = getpagedim
pageno in
6127 let sw = float w1 /. float w
6128 and sh = float h1
/. float h in
6132 and y1s
= y1 *. sh in
6133 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6134 let color = (r, g, b, a) in
6135 if conf
.verbose
then debugrect rect;
6136 state
.rects <- (pageno, color, rect) :: state
.rects;
6141 | "reload", "" -> reload ()
6143 scan args
"%u %f %f"
6145 let cmd, _ = state
.geomcmds
in
6147 then gotopagexy !wtmode pageno x y
6150 gotopagexy !wtmode pageno x y;
6153 state
.reprf
<- f state
.reprf
6155 | "goto1", args
-> scan args
"%u %f" gotopage
6158 (fun _filename _pageno
->
6159 failwith
"gotounder (Uremote (filename, pageno))")
6162 (fun _filename _dest
->
6163 failwith
"gotounder (Uremotedest (filename, dest))")
6165 scan args
"%u %u %f %f %f %f"
6166 (fun pageno c x0 y0 x1 y1 ->
6167 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6168 rectx "rect" pageno color x0 y0 x1 y1;
6171 scan args
"%u %f %f %f %f %f %f %f %f"
6172 (fun pageno r g b alpha x0 y0 x1 y1 ->
6173 addrect pageno r g b alpha x0 y0 x1 y1;
6174 G.postRedisplay "prect"
6177 scan args
"%u %f %f"
6180 match getopaque pageno with
6181 | Some
opaque -> opaque
6184 pgoto optopaque pageno x y;
6185 let rec fixx = function
6188 if l.pageno = pageno
6189 then gotoxy (state
.x - l.pagedispx) state
.y
6194 match conf
.columns
with
6195 | Csingle
_ | Csplit
_ -> 1
6196 | Cmulti
((n, _, _), _) -> n
6198 layout 0 state
.y (state
.winw * mult) state
.winh
6202 | "activatewin", "" -> Wsi.activatewin
()
6203 | "quit", "" -> raise Quit
6206 let l = Config.keys_of_string
keys in
6207 List.iter
(fun (k
, m) -> keyboard k
m) l
6208 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6211 | "clearrects", "" ->
6212 Hashtbl.clear state
.prects
;
6213 G.postRedisplay "clearrects"
6215 adderrfmt "remote command"
6216 "error processing remote command: %S\n" cmds
;
6220 let scratch = Bytes.create
80 in
6221 let buf = Buffer.create
80 in
6223 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6224 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6227 if Buffer.length
buf > 0
6229 let s = Buffer.contents
buf in
6237 match Bytes.index_from
scratch ppos '
\n'
with
6238 | pos
-> if pos
>= n then -1 else pos
6239 | exception Not_found
-> -1
6243 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6244 let s = Buffer.contents
buf in
6250 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6256 let remoteopen path =
6257 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6259 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6264 let gcconfig = ref E.s in
6265 let trimcachepath = ref E.s in
6266 let rcmdpath = ref E.s in
6267 let pageno = ref None
in
6268 let rootwid = ref 0 in
6269 let openlast = ref false in
6270 let nofc = ref false in
6271 let doreap = ref false in
6272 let csspath = ref None
in
6273 selfexec := Sys.executable_name
;
6276 [("-p", Arg.String
(fun s -> state
.password <- s),
6277 "<password> Set password");
6281 Config.fontpath
:= s;
6282 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6284 "<path> Set path to the user interface font");
6288 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6289 Config.confpath
:= s),
6290 "<path> Set path to the configuration file");
6292 ("-last", Arg.Set
openlast, " Open last document");
6294 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6295 "<page-number> Jump to page");
6297 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6298 "<path> Set path to the trim cache file");
6300 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6301 "<named-destination> Set named destination");
6303 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6304 ("-cxack", Arg.Set
cxack, " Cut corners");
6306 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6307 "<path> Set path to the source of remote commands");
6309 ("-gc", Arg.Set_string
gcconfig,
6310 "<path> Collect garbage with the help of a script");
6312 ("-nofc", Arg.Set
nofc, " Do not use fontconfig");
6314 ("-v", Arg.Unit
(fun () ->
6316 "%s\nconfiguration path: %s\n"
6319 exit
0), " Print version and exit");
6321 ("-css", Arg.String
(fun s -> csspath := Some
s),
6322 "<path> Set path to the style sheet to use with EPUB/HTML");
6324 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6326 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6327 "<origin> <undocumented>");
6330 (fun s -> state
.path <- s)
6331 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6334 then selfexec := !selfexec ^
" -wtmode";
6336 let histmode = emptystr state
.path && not
!openlast in
6338 if not
(Config.load !openlast)
6339 then dolog
"failed to load configuration";
6341 begin match !pageno with
6342 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6346 if nonemptystr
!gcconfig
6349 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6350 | exception exn
-> error
"socketpair for gc failed: %s" @@ exntos exn
6353 match spawn
!gcconfig [(c, 0); (c, 1); (s, -1)] with
6354 | exception exn
-> error
"failed to execute gc script: %s" @@ exntos exn
6356 Ne.clo c @@ (fun s -> error
"failed to close gc fd %s" s);
6363 val mutable m_clicks
= 0
6364 val mutable m_click_x
= 0
6365 val mutable m_click_y
= 0
6366 val mutable m_lastclicktime
= infinity
6368 method private cleanup =
6369 state
.roam
<- noroam
;
6370 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6371 method expose
= G.postRedisplay "expose"
6375 | Wsi.Unobscured
-> "unobscured"
6376 | Wsi.PartiallyObscured
-> "partiallyobscured"
6377 | Wsi.FullyObscured
-> "fullyobscured"
6379 vlog "visibility change %s" name
6380 method display = display ()
6381 method map mapped
= vlog "mapped %b" mapped
6382 method reshape w h =
6385 method mouse
b d x y m =
6386 if d && canselect ()
6389 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6396 if abs
x - m_click_x
> 10
6397 || abs
y - m_click_y
> 10
6398 || abs_float
(t -. m_lastclicktime
) > 0.3
6400 m_clicks
<- m_clicks
+ 1;
6401 m_lastclicktime
<- t;
6405 G.postRedisplay "cleanup";
6406 state
.uioh <- state
.uioh#button
b d x y m;
6408 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6413 m_lastclicktime
<- infinity
;
6414 state
.uioh <- state
.uioh#button
b d x y m
6418 state
.uioh <- state
.uioh#button
b d x y m
6421 state
.mpos
<- (x, y);
6422 state
.uioh <- state
.uioh#motion
x y
6423 method pmotion
x y =
6424 state
.mpos
<- (x, y);
6425 state
.uioh <- state
.uioh#pmotion
x y
6427 let mascm = m land (
6428 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6431 let x = state
.x and y = state
.y in
6433 if x != state
.x || y != state
.y then self#
cleanup
6435 match state
.keystate
with
6437 let km = k
, mascm in
6440 let modehash = state
.uioh#
modehash in
6441 try Hashtbl.find modehash km
6443 try Hashtbl.find (findkeyhash conf
"global") km
6444 with Not_found
-> KMinsrt
(k
, m)
6446 | KMinsrt
(k
, m) -> keyboard k
m
6447 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6448 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6450 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6451 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6452 state
.keystate
<- KSnone
6453 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6454 state
.keystate
<- KSinto
(keys, insrt
)
6455 | KSinto
_ -> state
.keystate
<- KSnone
6458 state
.mpos
<- (x, y);
6459 state
.uioh <- state
.uioh#pmotion
x y
6460 method leave = state
.mpos
<- (-1, -1)
6461 method winstate wsl
= state
.winstate
<- wsl
6462 method quit
= raise Quit
6465 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6467 setbgcol conf
.bgcolor
;
6470 if not
@@ List.exists
GlMisc.check_extension
6471 [ "GL_ARB_texture_rectangle"
6472 ; "GL_EXT_texture_recangle"
6473 ; "GL_NV_texture_rectangle" ]
6474 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6476 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6478 defconf
.sliceheight
<- 1024;
6479 defconf
.texcount
<- 32;
6480 defconf
.usepbo
<- true;
6484 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6486 dolog
"socketpair failed: %s" @@ exntos exn
;
6494 setcheckers conf
.checkers
;
6496 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6498 begin match !csspath with
6500 | Some
"" -> conf
.css
<- E.s
6502 let css = filecontents
path in
6503 let l = String.length
css in
6505 if substratis
css (l-2) "\r\n"
6506 then String.sub css 0 (l-2)
6507 else (if css.[l-1] = '
\n'
6508 then String.sub css 0 (l-1)
6512 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6513 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6514 !Config.fontpath
, !trimcachepath, !opengl_has_pbo, not
!nofc
6516 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6518 reshape ~firsttime
:true winw winh
;
6522 Wsi.settitle
"llpp (history)";
6526 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6527 opendoc state
.path state
.password;
6531 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6532 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6535 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6536 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6537 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6539 | _pid
, _status
-> reap ()
6541 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6545 if nonemptystr
!rcmdpath
6546 then remoteopen !rcmdpath
6551 let rec loop deadline
=
6557 let r = [state
.ss; state
.wsfd] in
6561 | Some fd
-> fd
:: r
6565 state
.redisplay
<- false;
6572 if deadline
= infinity
6574 else max
0.0 (deadline
-. now)
6579 try Unix.select
r [] [] timeout
6580 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6586 if state
.ghyll
== noghyll
6588 match state
.autoscroll
with
6589 | Some step
when step
!= 0 ->
6590 let y = state
.y + step
in
6591 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6594 then state
.maxy - fy
6595 else if y >= state
.maxy - fy then 0 else y
6597 if state
.mode = View
6598 then gotoxy_and_clear_text state
.x y
6599 else gotoxy state
.x y;
6602 else deadline
+. 0.01
6607 let rec checkfds = function
6609 | fd
:: rest
when fd
= state
.ss ->
6610 let cmd = rcmd state
.ss in
6614 | fd
:: rest
when fd
= state
.wsfd ->
6618 | fd
:: rest
when Some fd
= !optrfd ->
6619 begin match remote fd
with
6620 | None
-> optrfd := remoteopen !rcmdpath;
6621 | opt -> optrfd := opt
6626 dolog
"select returned unknown descriptor";
6632 if deadline
= infinity
6636 match state
.autoscroll
with
6637 | Some step
when step
!= 0 -> deadline1
6638 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6643 match loop infinity
with
6645 Config.save leavebirdseye;
6646 if hasunsavedchanges
()
6648 | _ -> error
"umpossible - infinity reached"