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
)
259 try spawn cmd
[r
, 0; w
, -1]
261 dolog
"cannot execute %S: %s" cmd
@@ exntos exn
;
267 G.postRedisplay "pipesel";
269 else doclose "pipesel pipe/w" w
;
270 doclose "pipesel pipe/r" r
;
274 let g opaque l
px py
=
275 if markunder opaque
px py conf
.paxmark
278 match getopaque l
.pageno
with
280 | Some opaque
-> pipesel opaque conf
.paxcmd
285 G.postRedisplay "paxunder";
286 if conf
.paxmark
= Mark_page
289 match getopaque l
.pageno
with
291 | Some opaque
-> clearmark opaque
) state
.layout
;
292 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
296 match Unix.pipe
() with
297 | (exception exn
) -> impmsg "pipe failed: %s" @@ exntos exn
300 Ne.clo fd
(fun msg
-> impmsg "failed to close %s: %s" cap msg
)
303 try spawn conf
.selcmd
[r
, 0; w
, -1]
305 impmsg "failed to execute %s: %s" conf
.selcmd
@@ exntos exn
;
311 let l = String.length s
in
312 let bytes = Bytes.unsafe_of_string s
in
313 let n = tempfailureretry
(Unix.write w
bytes 0) l in
315 then impmsg "failed to write %d characters to sel pipe, wrote %d"
318 impmsg "failed to write to sel pipe: %s" @@ exntos exn
321 clo "selstring pipe/r" r
;
322 clo "selstring pipe/w" w
;
325 let undertext = function
328 | Utext s
-> "font: " ^ s
329 | Uannotation
(opaque
, slinkindex
) ->
330 "annotation: " ^ getannotcontents opaque slinkindex
333 let updateunder x y =
334 match getunder x y with
335 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
337 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
338 Wsi.setcursor
Wsi.CURSOR_INFO
340 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
341 Wsi.setcursor
Wsi.CURSOR_TEXT
343 if conf
.underinfo
then showtext 'a'
"nnotation";
344 Wsi.setcursor
Wsi.CURSOR_INFO
347 let showlinktype under =
348 if conf
.underinfo
&& under != Unone
349 then showtext ' '
@@ undertext under
352 let intentry_with_suffix text key
=
354 if key
>= 32 && key
< 127
356 let c = Char.chr key
in
361 | 'k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
->
362 addchar
text @@ asciilower
c
364 state
.text <- Printf.sprintf
"invalid key (%d, `%c')" key
c;
367 state
.text <- Printf.sprintf
"invalid key %d" key
;
375 let b = Buffer.create
16 in
378 let b = Buffer.to_bytes
b in
379 wcmd state
.ss
b @@ Bytes.length
b
383 let nogeomcmds cmds
=
385 | s
, [] -> emptystr s
389 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
390 let rec fold accu
n =
391 if n = Array.length
b
394 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
397 || n = state
.pagecount
- coverB
398 || (n - coverA
) mod columns
= columns
- 1)
404 let pagey = max
0 (y - vy
) in
405 let pagedispy = if pagey > 0 then 0 else vy
- y in
406 let pagedispx, pagex
=
408 if n = coverA
- 1 || n = state
.pagecount
- coverB
409 then x + (sw
- w
) / 2
417 let vw = sw
- pagedispx in
418 let pw = w
- pagex
in
421 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
422 if pagevw > 0 && pagevh > 0
433 ; pagedispx = pagedispx
434 ; pagedispy = pagedispy
446 if Array.length
b = 0
448 else List.rev
(fold [] (page_of_y
y))
451 let layoutS (columns
, b) x y sw sh
=
452 let rec fold accu n =
453 if n = Array.length
b
456 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
464 let pagey = max
0 (y - vy
) in
465 let pagedispy = if pagey > 0 then 0 else vy
- y in
466 let pagedispx, pagex
=
480 let pagecolw = pagew
/columns
in
483 then pagedispx + ((sw
- pagecolw) / 2)
487 let vw = sw
- pagedispx in
488 let pw = pagew
- pagex
in
491 let pagevw = min
pagevw pagecolw in
492 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
493 if pagevw > 0 && pagevh > 0
504 ; pagedispx = pagedispx
505 ; pagedispy = pagedispy
506 ; pagecol
= n mod columns
520 let layout x y sw sh
=
521 if nogeomcmds state
.geomcmds
523 match conf
.columns
with
524 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
525 | Cmulti
c -> layoutN c x y sw sh
526 | Csplit s
-> layoutS s
x y sw sh
531 let y = state
.y + incr
in
533 let y = min
y (state
.maxy
- (if conf
.maxhfit
then state
.winh
else 0)) in
538 let tilex = l.pagex
mod conf
.tilew
in
539 let tiley = l.pagey mod conf
.tileh
in
541 let col = l.pagex
/ conf
.tilew
in
542 let row = l.pagey / conf
.tileh
in
544 let rec rowloop row y0 dispy h
=
548 let dh = conf
.tileh
- y0 in
550 let rec colloop col x0 dispx w
=
554 let dw = conf
.tilew
- x0 in
556 f col row dispx dispy
x0 y0 dw dh;
557 colloop (col+1) 0 (dispx
+dw) (w
-dw)
560 colloop col tilex l.pagedispx l.pagevw;
561 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
564 if l.pagevw > 0 && l.pagevh > 0
565 then rowloop row tiley l.pagedispy l.pagevh;
568 let gettileopaque l col row =
570 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
572 try Some
(Hashtbl.find state
.tilemap
key)
573 with Not_found
-> None
576 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
577 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
578 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
581 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
582 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
583 GlArray.vertex `two state
.vraw
;
584 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
587 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
589 let filledrect x0 y0 x1 y1 =
590 GlArray.disable `texture_coord
;
591 filledrect1 x0 y0 x1 y1;
592 GlArray.enable `texture_coord
;
595 let linerect x0 y0 x1 y1 =
596 GlArray.disable `texture_coord
;
597 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
598 GlArray.vertex `two state
.vraw
;
599 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
600 GlArray.enable `texture_coord
;
603 let drawtiles l color =
606 let f col row x y tilex tiley w h
=
607 match gettileopaque l col row with
608 | Some
(opaque
, _
, t
) ->
609 let params = x, y, w
, h
, tilex, tiley in
611 then GlTex.env
(`mode `blend
);
612 drawtile
params opaque
;
614 then GlTex.env
(`mode `modulate
);
618 let s = Printf.sprintf
622 let w = measurestr fstate
.fontsize
s in
623 GlDraw.color (0.0, 0.0, 0.0);
624 filledrect (float (x-2))
627 (float (y + fstate
.fontsize
+ 2));
629 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
636 let lw = state
.winw
- x in
639 let lh = state
.winh
- y in
643 then GlTex.env
(`mode `blend
);
644 begin match state
.checkerstexid
with
646 Gl.enable `texture_2d
;
647 GlTex.bind_texture ~target
:`texture_2d id
;
651 and y1 = float (y+h
) in
653 let tw = float w /. 16.0
654 and th
= float h
/. 16.0 in
655 let tx0 = float tilex /. 16.0
656 and ty0
= float tiley /. 16.0 in
658 and ty1
= ty0
+. th
in
659 Raw.sets_float state
.vraw ~pos
:0
660 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
661 Raw.sets_float state
.traw ~pos
:0
662 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
663 GlArray.vertex `two state
.vraw
;
664 GlArray.tex_coord `two state
.traw
;
665 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
666 Gl.disable `texture_2d
;
669 GlDraw.color (1.0, 1.0, 1.0);
670 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
673 then GlTex.env
(`mode `modulate
);
674 if w > 128 && h
> fstate
.fontsize
+ 10
676 let c = if conf
.invert
then 1.0 else 0.0 in
677 GlDraw.color (c, c, c);
680 then (col*conf
.tilew
, row*conf
.tileh
)
683 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
692 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
694 let tilevisible1 l x y =
696 and ax1
= l.pagex
+ l.pagevw
698 and ay1
= l.pagey + l.pagevh in
702 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
703 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
705 let rx0 = max
ax0 bx0
706 and ry0
= max ay0 by0
707 and rx1
= min ax1
bx1
708 and ry1
= min ay1 by1
in
710 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
714 let tilevisible layout n x y =
715 let rec findpageinlayout m
= function
716 | l :: rest
when l.pageno
= n ->
717 tilevisible1 l x y || (
718 match conf
.columns
with
719 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
724 | _
:: rest
-> findpageinlayout 0 rest
727 findpageinlayout 0 layout;
730 let tileready l x y =
731 tilevisible1 l x y &&
732 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
735 let tilepage n p
layout =
736 let rec loop = function
740 let f col row _ _ _ _ _ _
=
741 if state
.currently
= Idle
743 match gettileopaque l col row with
746 let x = col*conf
.tilew
747 and y = row*conf
.tileh
in
749 let w = l.pagew
- x in
753 let h = l.pageh
- y in
758 then getpbo
w h conf
.colorspace
761 wcmd "tile %s %d %d %d %d %s"
762 (~
> p
) x y w h (~
> pbo);
765 l, p
, conf
.colorspace
, conf
.angle
,
766 state
.gen
, col, row, conf
.tilew
, conf
.tileh
775 if nogeomcmds state
.geomcmds
779 let preloadlayout x y sw sh
=
780 let y = if y < sh
then 0 else y - sh
in
781 let x = min
0 (x + sw
) in
789 if state
.currently
!= Idle
794 begin match getopaque l.pageno
with
796 wcmd "page %d %d" l.pageno
l.pagedimno
;
797 state
.currently
<- Loading
(l, state
.gen
);
799 tilepage l.pageno opaque pages
;
804 if nogeomcmds state
.geomcmds
810 if conf
.preload && state
.currently
= Idle
811 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
814 let layoutready layout =
815 let rec fold all ls
=
818 let seen = ref false in
819 let allvisible = ref true in
820 let foo col row _ _ _ _ _ _
=
822 allvisible := !allvisible &&
823 begin match gettileopaque l col row with
829 fold (!seen && !allvisible) rest
832 let alltilesvisible = fold true layout in
837 let y = bound
y 0 state
.maxy
in
838 let y, layout, proceed
=
839 match conf
.maxwait
with
840 | Some time
when state
.ghyll
== noghyll
->
841 begin match state
.throttle
with
843 let layout = layout x y state
.winw state
.winh
in
844 let ready = layoutready layout in
848 state
.throttle
<- Some
(layout, y, now
());
850 else G.postRedisplay "gotoxy showall (None)";
852 | Some
(_
, _
, started
) ->
853 let dt = now
() -. started
in
856 state
.throttle
<- None
;
857 let layout = layout x y state
.winw state
.winh
in
859 G.postRedisplay "maxwait";
866 let layout = layout x y state
.winw state
.winh
in
867 if not
!wtmode || layoutready layout
868 then G.postRedisplay "gotoxy ready";
875 state
.layout <- layout;
876 begin match state
.mode
with
879 | Ltexact
(pageno
, linkno
) ->
880 let rec loop = function
882 state
.lnava
<- Some
(pageno
, linkno
);
883 state
.mode
<- LinkNav
(Ltgendir
0)
884 | l :: _
when l.pageno
= pageno
->
885 begin match getopaque pageno
with
886 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
888 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
889 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
890 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
891 then state
.mode
<- LinkNav
(Ltgendir
0)
893 | _
:: rest
-> loop rest
896 | Ltnotready _
| Ltgendir _
-> ()
898 | Birdseye _
| Textentry _
| View
-> ()
900 begin match state
.mode
with
901 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
902 if not
(pagevisible layout pageno
)
904 match state
.layout with
907 state
.mode
<- Birdseye
(
908 conf
, leftx
, l.pageno
, hooverpageno
, anchor
913 | Ltnotready
(_
, dir
)
916 let rec loop = function
919 match getopaque l.pageno
with
920 | None
-> Ltnotready
(l.pageno
, dir
)
925 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
927 if dir
> 0 then LDfirst
else LDlast
933 | Lnotfound
-> loop rest
935 showlinktype (getlink opaque
n);
936 Ltexact
(l.pageno
, n)
940 state
.mode
<- LinkNav
linknav
943 | Textentry _
| View
-> ()
947 state
.ghyll
<- noghyll
;
950 let mx, my
= state
.mpos
in
955 let conttiling pageno opaque
=
956 tilepage pageno opaque
958 then preloadlayout state
.x state
.y state
.winw state
.winh
962 let gotoxy_and_clear_text x y =
963 if not conf
.verbose
then state
.text <- E.s;
967 let getanchory (n, top
, dtop
) =
968 let y, h = getpageyh
n in
971 let ips = calcips
h in
972 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
974 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
977 let gotoanchor anchor
=
978 gotoxy state
.x (getanchory anchor
);
982 cbput state
.hists
.nav
(getanchor
());
986 let anchor = cbgetc state
.hists
.nav dir
in
990 let gotoghyll1 single
y =
992 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
994 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
996 then s (float f /. float a
)
999 then 1.0 -. s ((float (f-b) /. float (n-b)))
1005 let ins = float a
*. 0.5
1006 and outs
= float (n-b) *. 0.5 in
1008 ins +. outs
+. float ones
1010 let rec set nab
y sy
=
1011 let (_N
, _A
, _B
), y =
1014 let scl = if y > sy
then 2 else -2 in
1015 let _N, _
, _
= nab
in
1016 (_N,0,_N), y+conf
.scrollstep
*scl
1018 let sum = summa
_N _A _B
in
1019 let dy = float (y - sy
) in
1023 then state
.ghyll
<- noghyll
1026 let s = scroll n _N _A _B
in
1027 let y1 = y1 +. ((s *. dy) /. sum) in
1028 gotoxy_and_clear_text state
.x (truncate
y1);
1029 state
.ghyll
<- gf (n+1) y1;
1033 | Some
y'
when single
-> set nab
y' state
.y
1034 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1036 gf 0 (float state
.y)
1039 match conf
.ghyllscroll
with
1040 | Some nab
when not conf
.presentation
->
1041 if state
.ghyll
== noghyll
1042 then set nab
y state
.y
1043 else state
.ghyll
(Some
y)
1045 gotoxy_and_clear_text state
.x y
1048 let gotoghyll = gotoghyll1 false;;
1050 let gotopage n top
=
1051 let y, h = getpageyh
n in
1052 let y = y + (truncate
(top
*. float h)) in
1056 let gotopage1 n top
=
1057 let y = getpagey
n in
1062 let invalidate s f =
1063 state
.redisplay
<- false;
1068 match state
.geomcmds
with
1069 | ps
, [] when emptystr ps
->
1071 state
.geomcmds
<- s, [];
1074 state
.geomcmds
<- ps
, [s, f];
1076 | ps
, (s'
, _
) :: rest
when s'
= s ->
1077 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1080 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1084 Hashtbl.iter
(fun _ opaque
->
1085 wcmd "freepage %s" (~
> opaque
);
1087 Hashtbl.clear state
.pagemap
;
1091 if not
(Queue.is_empty state
.tilelru
)
1093 Queue.iter
(fun (k
, p
, s) ->
1094 wcmd "freetile %s" (~
> p
);
1095 state
.memused
<- state
.memused
- s;
1096 Hashtbl.remove state
.tilemap k
;
1098 state
.uioh#infochanged Memused
;
1099 Queue.clear state
.tilelru
;
1105 let h = truncate
(float h*.conf
.zoom
) in
1106 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1110 let opendoc path password
=
1112 state
.password
<- password
;
1113 state
.gen
<- state
.gen
+ 1;
1114 state
.docinfo
<- [];
1115 state
.outlines
<- [||];
1118 setaalevel conf
.aalevel
;
1120 if emptystr state
.origin
1124 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1125 wcmd "open %d %d %d %s\000%s\000%s\000"
1126 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1127 path password conf
.css
;
1128 invalidate "reqlayout"
1130 wcmd "reqlayout %d %d %d %s\000"
1131 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1132 (stateh state
.winh
) state
.nameddest
1135 let sl = keystostrlist conf
in
1137 function | [] -> accu
1138 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1139 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1143 state
.anchor <- getanchor
();
1144 opendoc state
.path state
.password
;
1148 let c = c *. conf
.colorscale
in
1152 let scalecolor2 (r
, g, b) =
1153 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1156 let docolumns columns
=
1159 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1160 let rec loop pageno
pdimno pdim
y ph pdims
=
1161 if pageno
= state
.pagecount
1164 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1166 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1167 pdimno+1, pdim
, rest
1171 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1173 y + (if conf
.presentation
1174 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1175 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1178 a.(pageno
) <- (pdimno, x, y, pdim
);
1179 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1181 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1182 conf
.columns
<- Csingle
a;
1184 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1185 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1186 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1188 if m
= pageno
then () else
1189 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1192 let y = y + (rowh
- h) / 2 in
1193 a.(m
) <- (pdimno, x, y, pdim
);
1197 if pageno
= state
.pagecount
1198 then fixrow (((pageno
- 1) / columns
) * columns
)
1200 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1202 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1203 pdimno+1, pdim
, rest
1208 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1210 let x = (state
.winw
- w) / 2 in
1212 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1213 x, y + ips + rowh
, h
1216 if (pageno
- coverA
) mod columns
= 0
1218 let x = max
0 (state
.winw
- state
.w) / 2 in
1220 if conf
.presentation
1222 let ips = calcips
h in
1223 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1225 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1229 else x, y, max rowh
h
1233 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1236 if pageno
= columns
&& conf
.presentation
1238 let ips = calcips rowh
in
1239 for i
= 0 to pred columns
1241 let (pdimno, x, y, pdim
) = a.(i
) in
1242 a.(i
) <- (pdimno, x, y+ips, pdim
)
1248 fixrow (pageno
- columns
);
1253 a.(pageno
) <- (pdimno, x, y, pdim
);
1254 let x = x + w + xoff
*2 + conf
.interpagespace
in
1255 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1257 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1258 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1261 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1262 let rec loop pageno
pdimno pdim
y pdims
=
1263 if pageno
= state
.pagecount
1266 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1268 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1269 pdimno+1, pdim
, rest
1274 let rec loop1 n x y =
1275 if n = c then y else (
1276 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1277 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1280 let y = loop1 0 0 y in
1281 loop (pageno
+1) pdimno pdim
y pdims
1283 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1284 conf
.columns
<- Csplit
(c, a);
1288 docolumns conf
.columns
;
1289 state
.maxy
<- calcheight
();
1290 if state
.reprf
== noreprf
1292 match state
.mode
with
1293 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1294 let y, h = getpageyh pageno
in
1295 let top = (state
.winh
- h) / 2 in
1296 gotoxy state
.x (max
0 (y - top))
1297 | Textentry _
| View
| LinkNav _
->
1298 let y = getanchory state
.anchor in
1299 let y = min
y (state
.maxy
- state
.winh
) in
1304 state
.reprf
<- noreprf
;
1308 let reshape ?
(firsttime
=false) w h =
1309 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1310 if not firsttime
&& nogeomcmds state
.geomcmds
1311 then state
.anchor <- getanchor
();
1314 let w = truncate
(float w *. conf
.zoom
) in
1317 setfontsize fstate
.fontsize
;
1318 GlMat.mode `modelview
;
1319 GlMat.load_identity
();
1321 GlMat.mode `projection
;
1322 GlMat.load_identity
();
1323 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1324 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1325 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1330 else float state
.x /. float state
.w
1332 invalidate "geometry"
1336 then state
.x <- truncate
(relx *. float w);
1338 match conf
.columns
with
1340 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1341 | Csplit
(c, _
) -> w * c
1343 wcmd "geometry %d %d %d"
1344 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1349 let len = String.length state
.text in
1350 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1353 match state
.mode
with
1354 | Textentry _
| View
| LinkNav _
->
1355 let h, _
, _
= state
.uioh#scrollpw
in
1361 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1362 (x+.w) (float (state
.winh
- hscrollh))
1365 let w = float (state
.winw
- 1 - vscrollw ()) in
1366 if state
.progress
>= 0.0 && state
.progress
< 1.0
1368 GlDraw.color (0.3, 0.3, 0.3);
1369 let w1 = w *. state
.progress
in
1371 GlDraw.color (0.0, 0.0, 0.0);
1372 rect (float x0+.w1) (float x0+.w-.w1)
1375 GlDraw.color (0.0, 0.0, 0.0);
1379 GlDraw.color (1.0, 1.0, 1.0);
1382 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1383 (state
.winh
- hscrollh - 5) s;
1386 match state
.mode
with
1387 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1390 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1391 else Printf.sprintf
"%s%s_" prefix
text
1395 | Birdseye _
| View
| LinkNav _
-> state
.text
1400 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1402 let s1 = "(press 'e' to review error messasges)" in
1403 if nonemptystr
s then s ^
" " ^
s1 else s1
1413 let len = Queue.length state
.tilelru
in
1415 match state
.throttle
with
1418 then preloadlayout state
.x state
.y state
.winw state
.winh
1420 | Some
(layout, _
, _
) ->
1424 if state
.memused
> conf
.memlimit
1428 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1429 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1430 let (_
, pw, ph
, _
) = getpagedim
n in
1432 && colorspace
= conf
.colorspace
1433 && angle
= conf
.angle
1437 let x = col*conf
.tilew
1438 and y = row*conf
.tileh
in
1439 tilevisible (Lazy.force_val
layout) n x y
1441 then Queue.push lruitem state
.tilelru
1444 wcmd "freetile %s" (~
> p
);
1445 state
.memused
<- state
.memused
- s;
1446 state
.uioh#infochanged Memused
;
1447 Hashtbl.remove state
.tilemap k
;
1455 let onpagerect pageno
f =
1457 match conf
.columns
with
1458 | Cmulti
(_
, b) -> b
1460 | Csplit
(_
, b) -> b
1462 if pageno
>= 0 && pageno
< Array.length
b
1464 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1468 let gotopagexy1 wtmode pageno
x y =
1469 let _,w1,h1
,leftx
= getpagedim pageno
in
1470 let top = y /. (float h1
) in
1471 let left = x /. (float w1) in
1472 let py, w, h = getpageywh pageno
in
1473 let wh = state
.winh
in
1474 let x = left *. (float w) in
1475 let x = leftx
+ state
.x + truncate
x in
1477 if x < 0 || x >= state
.winw
1481 let pdy = truncate
(top *. float h) in
1482 let y'
= py + pdy in
1483 let dy = y'
- state
.y in
1485 if x != state
.x || not
(dy > 0 && dy < wh)
1487 if conf
.presentation
1489 if abs
(py - y'
) > wh
1496 if state
.x != sx || state
.y != sy
1501 let ww = state
.winw
in
1503 and qy
= pdy / wh in
1505 and y = py + qy
* wh in
1506 let x = if -x + ww > w1 then -(w1-ww) else x
1507 and y'
= if y + wh > state
.maxy
then state
.maxy
- wh else y in
1509 if conf
.presentation
1511 if abs
(py - y'
) > wh
1520 gotoxy_and_clear_text x y;
1522 else gotoxy_and_clear_text state
.x state
.y;
1525 let gotopagexy wtmode pageno
x y =
1526 match state
.mode
with
1527 | Birdseye
_ -> gotopage pageno
0.0
1528 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1531 let getpassword () =
1532 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1537 impmsg "error getting password: %s" s;
1538 dolog
"%s" s) passcmd;
1541 let pgoto opaque pageno
x y =
1542 let pdimno = getpdimno pageno
in
1543 let x, y = project opaque pageno
pdimno x y in
1544 gotopagexy false pageno
x y;
1548 (* dolog "%S" cmds; *)
1549 let spl = splitatchar cmds ' '
in
1551 try Scanf.sscanf
s fmt
f
1553 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1556 let addoutline outline
=
1557 match state
.currently
with
1558 | Outlining outlines
->
1559 state
.currently
<- Outlining
(outline
:: outlines
)
1560 | Idle
-> state
.currently
<- Outlining
[outline
]
1563 dolog
"invalid outlining state";
1564 logcurrently state
.currently
1569 state
.uioh#infochanged Pdim
;
1571 | "clearrects", "" ->
1572 state
.rects
<- state
.rects1
;
1573 G.postRedisplay "clearrects";
1575 | "continue", args
->
1576 let n = scan args
"%u" (fun n -> n) in
1577 state
.pagecount
<- n;
1578 begin match state
.currently
with
1580 state
.currently
<- Idle
;
1581 state
.outlines
<- Array.of_list
(List.rev
l)
1587 let cur, cmds
= state
.geomcmds
in
1589 then failwith
"umpossible";
1591 begin match List.rev cmds
with
1593 state
.geomcmds
<- E.s, [];
1594 state
.throttle
<- None
;
1598 state
.geomcmds
<- s, List.rev rest
;
1600 if conf
.maxwait
= None
&& not
!wtmode
1601 then G.postRedisplay "continue";
1608 then showtext ' ' args
1611 Buffer.add_string state
.errmsgs args
;
1612 state
.newerrmsgs
<- true;
1613 G.postRedisplay "error message"
1615 | "progress", args
->
1616 let progress, text =
1619 f, String.sub args pos
(String.length args
- pos
))
1622 state
.progress <- progress;
1623 G.postRedisplay "progress"
1625 | "firstmatch", args
->
1626 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1627 scan args
"%u %d %f %f %f %f %f %f %f %f"
1628 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1629 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1631 let y = (getpagey
pageno) + truncate
y0 in
1639 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1640 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1643 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1644 scan args
"%u %d %f %f %f %f %f %f %f %f"
1645 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1646 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1648 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1650 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1653 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1654 let pageopaque = ~
< pageopaques in
1655 begin match state
.currently
with
1656 | Loading
(l, gen
) ->
1657 vlog "page %d took %f sec" l.pageno t
;
1658 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1659 begin match state
.throttle
with
1661 let preloadedpages =
1663 then preloadlayout state
.x state
.y state
.winw state
.winh
1668 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1669 IntSet.empty
preloadedpages
1672 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1673 if not
(IntSet.mem
pageno set)
1675 wcmd "freepage %s" (~
> opaque
);
1681 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1684 state
.currently
<- Idle
;
1687 tilepage l.pageno pageopaque state
.layout;
1689 load preloadedpages;
1690 let visible = pagevisible state
.layout l.pageno in
1693 match state
.mode
with
1694 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1695 if pageno = l.pageno
1700 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1702 if dir
> 0 then LDfirst
else LDlast
1705 findlink
pageopaque ld
1710 showlinktype (getlink
pageopaque n);
1711 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1713 | LinkNav
(Ltgendir
_)
1714 | LinkNav
(Ltexact
_)
1720 if visible && layoutready state
.layout
1722 G.postRedisplay "page";
1726 | Some
(layout, _, _) ->
1727 state
.currently
<- Idle
;
1728 tilepage l.pageno pageopaque layout;
1735 dolog
"Inconsistent loading state";
1736 logcurrently state
.currently
;
1741 let (x, y, opaques
, size
, t
) =
1742 scan args
"%u %u %s %u %f"
1743 (fun x y p size t
-> (x, y, p
, size
, t
))
1745 let opaque = ~
< opaques
in
1746 begin match state
.currently
with
1747 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1748 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1751 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1753 wcmd "freetile %s" (~
> opaque);
1754 state
.currently
<- Idle
;
1758 puttileopaque l col row gen cs angle
opaque size t
;
1759 state
.memused
<- state
.memused
+ size
;
1760 state
.uioh#infochanged Memused
;
1762 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1763 opaque, size
) state
.tilelru
;
1766 match state
.throttle
with
1767 | None
-> state
.layout
1768 | Some
(layout, _, _) -> layout
1771 state
.currently
<- Idle
;
1773 && conf
.colorspace
= cs
1774 && conf
.angle
= angle
1775 && tilevisible layout l.pageno x y
1776 then conttiling l.pageno pageopaque;
1778 begin match state
.throttle
with
1780 preload state
.layout;
1782 && conf
.colorspace
= cs
1783 && conf
.angle
= angle
1784 && tilevisible state
.layout l.pageno x y
1785 && (not
!wtmode || layoutready state
.layout)
1786 then G.postRedisplay "tile nothrottle";
1788 | Some
(layout, y, _) ->
1789 let ready = layoutready layout in
1793 state
.layout <- layout;
1794 state
.throttle
<- None
;
1795 G.postRedisplay "throttle";
1804 dolog
"Inconsistent tiling state";
1805 logcurrently state
.currently
;
1810 let (n, w, h, _) as pdim
=
1811 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1814 match conf
.fitmodel
with
1816 | FitPage
| FitProportional
->
1817 match conf
.columns
with
1818 | Csplit
_ -> (n, w, h, 0)
1819 | Csingle
_ | Cmulti
_ -> pdim
1821 state
.pdims
<- pdim :: state
.pdims
;
1822 state
.uioh#infochanged Pdim
1825 let (l, n, t
, h, pos
) =
1826 scan args
"%u %u %d %u %n"
1827 (fun l n t
h pos
-> l, n, t
, h, pos
)
1829 let s = String.sub args pos
(String.length args
- pos
) in
1830 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1833 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1834 let s = String.sub args pos
len in
1835 let pos2 = pos
+ len + 1 in
1836 let uri = String.sub args
pos2 (String.length args
- pos2) in
1837 addoutline (s, l, Ouri
uri)
1840 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1841 let s = String.sub args pos
(String.length args
- pos
) in
1842 addoutline (s, l, Onone
)
1846 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1848 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1851 let c, v
= splitatchar args '
\t'
in
1862 if let len = String.length
c in
1863 len > 6 && ((String.sub
c (len-4) 4) = "date")
1865 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1867 let b = Buffer.create
10 in
1868 Printf.bprintf
b "%s\t" c;
1871 Buffer.add_substring
b v p
l;
1872 Buffer.add_char
b c;
1873 with exn
-> Buffer.add_string
b @@ exntos exn
1881 Buffer.add_char
b '
['
;
1882 Buffer.add_string
b v
;
1883 Buffer.add_char
b '
]'
;
1890 state
.docinfo
<- (1, s) :: state
.docinfo
1893 state
.docinfo
<- List.rev state
.docinfo
;
1894 state
.uioh#infochanged Docinfo
1898 then Wsi.settitle
"Wrong password";
1899 let password = getpassword () in
1900 if emptystr
password
1901 then error
"document is password protected"
1902 else opendoc state
.path
password
1905 error
"unknown cmd `%S'" cmds
1910 let action = function
1911 | HCprev
-> cbget cb ~
-1
1912 | HCnext
-> cbget cb
1
1913 | HCfirst
-> cbget cb ~
-(cb
.rc)
1914 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1915 and cancel
() = cb
.rc <- rc
1919 let search pattern forward
=
1920 match conf
.columns
with
1921 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1922 | Csingle
_ | Cmulti
_ ->
1923 if nonemptystr pattern
1926 match state
.layout with
1929 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1931 wcmd "search %d %d %d %d,%s\000"
1932 (btod conf
.icase
) pn py (btod forward
) pattern
;
1935 let intentry text key =
1937 if key >= 32 && key < 127
1939 let c = Char.chr
key in
1941 | '
0'
.. '
9'
-> addchar
text c
1943 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1946 state
.text <- Printf.sprintf
"invalid key (%d)" key;
1957 let l = String.length
s in
1958 let rec loop pos
n =
1962 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1963 loop (pos
+1) (n*26 + m)
1966 let rec loop n = function
1969 match getopaque l.pageno with
1970 | None
-> loop n rest
1972 let m = getlinkcount
opaque in
1975 let under = getlink
opaque n in
1978 else loop (n-m) rest
1980 loop n state
.layout;
1984 let linknentry text key =
1985 if key >= 32 && key < 127
1987 let text = addchar
text (Char.chr
key) in
1988 linknact (fun under -> state
.text <- undertext under) text;
1991 state
.text <- Printf.sprintf
"invalid key %d" key;
1996 let textentry text key =
1997 if Wsi.isspecialkey
key
1999 else TEcont
(text ^ toutf8
key)
2002 let reqlayout angle fitmodel
=
2003 match state
.throttle
with
2005 if nogeomcmds state
.geomcmds
2006 then state
.anchor <- getanchor
();
2007 conf
.angle
<- angle
mod 360;
2010 match state
.mode
with
2011 | LinkNav
_ -> state
.mode
<- View
2012 | Birdseye
_ | Textentry
_ | View
-> ()
2014 conf
.fitmodel
<- fitmodel
;
2018 wcmd "reqlayout %d %d %d"
2019 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
2024 let settrim trimmargins trimfuzz
=
2025 if nogeomcmds state
.geomcmds
2026 then state
.anchor <- getanchor
();
2027 conf
.trimmargins
<- trimmargins
;
2028 conf
.trimfuzz
<- trimfuzz
;
2029 let x0, y0, x1, y1 = trimfuzz
in
2031 "settrim" (fun () ->
2032 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
2037 match state
.throttle
with
2039 let zoom = max
0.0001 zoom in
2040 if zoom <> conf
.zoom
2042 state
.prevzoom
<- (conf
.zoom, state
.x);
2044 reshape state
.winw state
.winh
;
2045 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2048 | Some
(layout, y, started
) ->
2050 match conf
.maxwait
with
2054 let dt = now
() -. started
in
2062 let pivotzoom ?
(vw=min state
.w state
.winw
)
2063 ?
(vh
=min
(state
.maxy
-state
.y) state
.winh
)
2064 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2065 let w = float state
.w /. zoom in
2066 let hw = w /. 2.0 in
2067 let ratio = float vh
/. float vw in
2068 let hh = hw *. ratio in
2069 let x0 = if zoom < 1.0 then 0.0 else float x -. hw in
2070 let y0 = float y -. hh in
2071 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2075 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2076 if nogeomcmds state
.geomcmds
then pivotzoom ?
vw ?vh ?
x ?
y zoom
2079 let setcolumns mode columns coverA coverB
=
2080 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2084 then impmsg "split mode doesn't work in bird's eye"
2086 conf
.columns
<- Csplit
(-columns
, E.a);
2094 conf
.columns
<- Csingle
E.a;
2099 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2103 reshape state
.winw state
.winh
;
2106 let resetmstate () =
2107 state
.mstate
<- Mnone
;
2108 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2111 let enterbirdseye () =
2112 let zoom = float conf
.thumbw
/. float state
.winw
in
2113 let birdseyepageno =
2114 let cy = state
.winh
/ 2 in
2118 let rec fold best
= function
2121 let d = cy - (l.pagedispy + l.pagevh/2)
2122 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2123 if abs
d < abs dbest
2132 { conf
with zoom = conf
.zoom },
2133 state
.x, birdseyepageno, -1, getanchor
()
2137 conf
.presentation
<- false;
2138 conf
.interpagespace
<- 10;
2139 conf
.hlinks
<- false;
2140 conf
.fitmodel
<- FitPage
;
2142 conf
.maxwait
<- None
;
2144 match conf
.beyecolumns
with
2147 Cmulti
((c, 0, 0), E.a)
2148 | None
-> Csingle
E.a
2152 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2157 reshape state
.winw state
.winh
;
2160 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2162 conf
.zoom <- c.zoom;
2163 conf
.presentation
<- c.presentation
;
2164 conf
.interpagespace
<- c.interpagespace
;
2165 conf
.maxwait
<- c.maxwait
;
2166 conf
.hlinks
<- c.hlinks
;
2167 conf
.fitmodel
<- c.fitmodel
;
2168 conf
.beyecolumns
<- (
2169 match conf
.columns
with
2170 | Cmulti
((c, _, _), _) -> Some
c
2172 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2175 match c.columns
with
2176 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2177 | Csingle
_ -> Csingle
E.a
2178 | Csplit
(c, _) -> Csplit
(c, E.a)
2182 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2185 reshape state
.winw state
.winh
;
2186 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2190 let togglebirdseye () =
2191 match state
.mode
with
2192 | Birdseye vals
-> leavebirdseye vals
true
2193 | View
-> enterbirdseye ()
2194 | Textentry
_ | LinkNav
_ -> ()
2197 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2198 let pageno = max
0 (pageno - incr
) in
2199 let rec loop = function
2200 | [] -> gotopage1 pageno 0
2201 | l :: _ when l.pageno = pageno ->
2202 if l.pagedispy >= 0 && l.pagey = 0
2203 then G.postRedisplay "upbirdseye"
2204 else gotopage1 pageno 0
2205 | _ :: rest
-> loop rest
2209 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2212 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2213 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2214 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2215 let rec loop = function
2217 let y, h = getpageyh
pageno in
2218 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2219 gotoxy state
.x (clamp dy)
2220 | l :: _ when l.pageno = pageno ->
2221 if l.pagevh != l.pageh
2222 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2223 else G.postRedisplay "downbirdseye"
2224 | _ :: rest
-> loop rest
2230 let optentry mode
_ key =
2231 let btos b = if b then "on" else "off" in
2232 if key >= 32 && key < 127
2234 let c = Char.chr
key in
2238 try conf
.scrollstep
<- int_of_string
s with exn
->
2239 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2241 TEswitch
("scroll step: ", E.s, None
, intentry, ondone, true)
2246 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2247 if state
.autoscroll
<> None
2248 then state
.autoscroll
<- Some conf
.autoscrollstep
2250 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2252 TEswitch
("auto scroll step: ", E.s, None
, intentry, ondone, true)
2257 let n, a, b = multicolumns_of_string
s in
2258 setcolumns mode
n a b;
2260 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2262 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
2267 let zoom = float (int_of_string
s) /. 100.0 in
2270 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2272 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
2277 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2279 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2280 begin match mode
with
2282 leavebirdseye beye
false;
2284 | Textentry
_ | View
| LinkNav
_ -> ();
2287 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2289 TEswitch
("thumbnail width: ", E.s, None
, intentry, ondone, true)
2293 match int_of_string
s with
2294 | angle
-> reqlayout angle conf
.fitmodel
2297 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2299 TEswitch
("rotation: ", E.s, None
, intentry, ondone, true)
2302 conf
.icase
<- not conf
.icase
;
2303 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2306 conf
.preload <- not conf
.preload;
2307 gotoxy state
.x state
.y;
2308 TEdone
("preload " ^
(btos conf
.preload))
2311 conf
.verbose
<- not conf
.verbose
;
2312 TEdone
("verbose " ^
(btos conf
.verbose
))
2315 conf
.debug
<- not conf
.debug
;
2316 TEdone
("debug " ^
(btos conf
.debug
))
2319 conf
.maxhfit
<- not conf
.maxhfit
;
2320 state
.maxy
<- calcheight
();
2321 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2324 conf
.crophack
<- not conf
.crophack
;
2325 TEdone
("crophack " ^
btos conf
.crophack
)
2329 match conf
.maxwait
with
2331 conf
.maxwait
<- Some infinity
;
2332 "always wait for page to complete"
2334 conf
.maxwait
<- None
;
2335 "show placeholder if page is not ready"
2340 conf
.underinfo
<- not conf
.underinfo
;
2341 TEdone
("underinfo " ^
btos conf
.underinfo
)
2344 conf
.savebmarks
<- not conf
.savebmarks
;
2345 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2351 match state
.layout with
2356 conf
.interpagespace
<- int_of_string
s;
2357 docolumns conf
.columns
;
2358 state
.maxy
<- calcheight
();
2359 let y = getpagey
pageno in
2360 gotoxy state
.x (y + py)
2363 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2365 TEswitch
("vertical margin: ", E.s, None
, intentry, ondone, true)
2369 match conf
.fitmodel
with
2370 | FitProportional
-> FitWidth
2371 | FitWidth
| FitPage
-> FitProportional
2373 reqlayout conf
.angle
fm;
2374 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2377 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2378 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2381 conf
.invert
<- not conf
.invert
;
2382 TEdone
("invert colors " ^
btos conf
.invert
)
2386 cbput state
.hists
.sel
s;
2389 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2390 textentry, ondone, true)
2394 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2395 else conf
.pax
<- None
;
2396 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2399 state
.text <- Printf.sprintf
"bad option %d `%c'" key c;
2405 class type lvsource
=
2407 method getitemcount
: int
2408 method getitem
: int -> (string * int)
2409 method hasaction
: int -> bool
2410 method exit
: uioh
:uioh
->
2416 method getactive
: int
2417 method getfirst
: int
2419 method getminfo
: (int * int) array
2422 class virtual lvsourcebase
= object
2423 val mutable m_active
= 0
2424 val mutable m_first
= 0
2425 val mutable m_pan
= 0
2426 method getactive
= m_active
2427 method getfirst
= m_first
2428 method getpan
= m_pan
2429 method getminfo
: (int * int) array
= E.a
2432 let textentrykeyboard
2433 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2436 state
.mode
<- Textentry
(te
, onleave
);
2438 G.postRedisplay "textentrykeyboard enttext";
2440 let histaction cmd
=
2443 | Some
(action, _) ->
2446 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2448 G.postRedisplay "textentry histaction"
2451 match Wsi.kc2pv
key with
2453 if emptystr
text && cancelonempty
2456 G.postRedisplay "textentrykeyboard after cancel";
2459 let s = withoutlastutf8
text in
2460 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2462 | Enter
| KPenter
->
2465 G.postRedisplay "textentrykeyboard after confirm"
2467 | Up
| KPup
-> histaction HCprev
2468 | Down
| KPdown
-> histaction HCnext
2469 | Home
| KPhome
-> histaction HCfirst
2470 | End
| KPend
-> histaction HClast
2475 begin match opthist
with
2477 | Some
(_, onhistcancel
) -> onhistcancel
()
2481 G.postRedisplay "textentrykeyboard after cancel2"
2484 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2487 | Delete
| KPdelete
-> ()
2489 | Code
_ | Ascii
_->
2490 begin match onkey
text key with
2494 G.postRedisplay "textentrykeyboard after confirm2";
2497 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2501 G.postRedisplay "textentrykeyboard after cancel3"
2504 state
.mode
<- Textentry
(te
, onleave
);
2505 G.postRedisplay "textentrykeyboard switch";
2507 | (Insert
|KPleft
|KPminus
|KPnext
2508 |KPplus
|KPprior
|KPright
|Left
|Right
|Next
|Prior
|Fn
_) ->
2509 vlog "unhandled key %s" (Wsi.keyname
key)
2512 let firstof first active
=
2513 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2514 then max
0 (active
- (fstate
.maxrows
/2))
2518 let calcfirst first active
=
2521 let rows = active
- first
in
2522 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2526 let scrollph y maxy
=
2527 let sh = float (maxy
+ state
.winh
) /. float state
.winh
in
2528 let sh = float state
.winh
/. sh in
2529 let sh = max
sh (float conf
.scrollh
) in
2531 let percent = float y /. float maxy
in
2532 let position = (float state
.winh
-. sh) *. percent in
2535 if position +. sh > float state
.winh
2536 then float state
.winh
-. sh
2542 let adderrmsg src msg
=
2543 Buffer.add_string state
.errmsgs msg
;
2544 state
.newerrmsgs
<- true;
2548 let adderrfmt src fmt
=
2549 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2552 let coe s = (s :> uioh
);;
2554 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2556 val m_pan
= source#getpan
2557 val m_first
= source#getfirst
2558 val m_active
= source#getactive
2560 val m_prev_uioh
= state
.uioh
2562 method private elemunder
y =
2566 let n = y / (fstate
.fontsize
+1) in
2567 if m_first
+ n < source#getitemcount
2569 if source#hasaction
(m_first
+ n)
2570 then Some
(m_first
+ n)
2577 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2578 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2579 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2580 GlDraw.color (1., 1., 1.);
2581 Gl.enable `texture_2d
;
2582 let fs = fstate
.fontsize
in
2584 let hw = state
.winw
/3 in
2585 let ww = fstate
.wwidth
in
2586 let tabw = 17.0*.ww in
2587 let itemcount = source#getitemcount
in
2588 let minfo = source#getminfo
in
2592 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2594 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2596 if (row - m_first
) > fstate
.maxrows
2599 if row >= 0 && row < itemcount
2601 let (s, level
) = source#getitem
row in
2602 let y = (row - m_first
) * nfs in
2603 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2606 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2610 Gl.disable `texture_2d
;
2611 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2612 GlDraw.color (1., 1., 1.) ~
alpha;
2613 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2614 Gl.enable `texture_2d
;
2617 if zebra
&& row land 1 = 1
2621 GlDraw.color (c,c,c);
2622 let drawtabularstring s =
2624 let x'
= truncate
(x0 +. x) in
2625 let s1, s2
= splitatchar
s '
\000'
in
2627 then drawstring1 fs x'
(y+nfs) s
2633 let s'
= withoutlastutf8
s in
2634 let s = s' ^
UniSyms.ellipsis in
2635 let w = measurestr
fs s in
2636 if float x'
+. w +. ww < float (hw + x'
)
2641 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2645 ignore
(drawstring1 fs x'
(y+nfs) s1);
2646 drawstring1 fs (hw + x'
) (y+nfs) s2
2650 let x = if helpmode
&& row > 0 then x +. ww else x in
2651 let s1, s2
= splitatchar
s '
\t'
in
2654 let nx = drawstr x s1 in
2656 let x = x +. (max
tabw sw) in
2659 let len = String.length
s - 2 in
2660 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2662 let s = String.sub s 2 len in
2663 let x = if not helpmode
then x +. ww else x in
2664 GlDraw.color (1.2, 1.2, 1.2);
2665 let vinc = drawstring1 (fs+fs/4)
2666 (truncate
(x -. ww)) (y+nfs) s in
2667 GlDraw.color (1., 1., 1.);
2668 vinc +. (float fs *. 0.8)
2674 ignore
(drawtabularstring s);
2680 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2683 if (row - m_first
) <= fstate
.maxrows
2685 if row >= 0 && row < itemcount
2687 let (s, level
) = source#getitem
row in
2688 let pos0 = nindex
s '
\000'
in
2689 let y = (row - m_first
) * nfs in
2690 let x = float (level
+ m_pan
) *. ww in
2691 let (first
, last
) = minfo.(row) in
2693 if pos0 > 0 && first
> pos0
2694 then String.sub s (pos0+1) (first
-pos0-1)
2695 else String.sub s 0 first
2697 let suffix = String.sub s first
(last
- first
) in
2698 let w1 = measurestr fstate
.fontsize
prefix in
2699 let w2 = measurestr fstate
.fontsize
suffix in
2700 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2701 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2703 and y0 = float (y+2) in
2705 and y1 = float (y+fs+3) in
2706 filledrect x0 y0 x1 y1;
2710 Gl.disable `texture_2d
;
2711 if Array.length
minfo > 0 then loop m_first
;
2716 method updownlevel incr
=
2717 let len = source#getitemcount
in
2719 if m_active
>= 0 && m_active
< len
2720 then snd
(source#getitem m_active
)
2724 if i
= len then i
-1 else if i
= -1 then 0 else
2725 let _, l = source#getitem i
in
2726 if l != curlevel then i
else flow (i
+incr
)
2728 let active = flow m_active
in
2729 let first = calcfirst m_first
active in
2730 G.postRedisplay "outline updownlevel";
2731 {< m_active
= active; m_first
= first >}
2733 method private key1
key mask
=
2734 let set1 active first qsearch
=
2735 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2737 let search active pattern incr
=
2738 let active = if active = -1 then m_first
else active in
2741 if n >= 0 && n < source#getitemcount
2743 let s, _ = source#getitem
n in
2744 match Str.search_forward re
s 0 with
2745 | (exception Not_found
) -> loop (n + incr
)
2752 let qpat = Str.quote pattern
in
2753 match Str.regexp_case_fold
qpat with
2756 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2757 qpat @@ Printexc.to_string exn
;
2760 let itemcount = source#getitemcount
in
2761 let find start incr
=
2763 if i
= -1 || i
= itemcount
2766 if source#hasaction i
2768 else find (i
+ incr
)
2773 let set active first =
2774 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2776 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2779 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2781 let incr1 = if incr
> 0 then 1 else -1 in
2782 if isvisible m_first m_active
2785 let next = m_active
+ incr
in
2787 if next < 0 || next >= itemcount
2789 else find next incr1
2791 if abs
(m_active
- next) > fstate
.maxrows
2797 let first = m_first
+ incr
in
2798 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2800 let next = m_active
+ incr
in
2801 let next = bound
next 0 (itemcount - 1) in
2808 if isvisible first next
2815 let first = min
next m_first
in
2817 if abs
(next - first) > fstate
.maxrows
2823 let first = m_first
+ incr
in
2824 let first = bound
first 0 (itemcount - 1) in
2826 let next = m_active
+ incr
in
2827 let next = bound
next 0 (itemcount - 1) in
2828 let next = find next incr1 in
2830 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2832 let active = if m_active
= -1 then next else m_active
in
2837 if isvisible first active
2843 G.postRedisplay "listview navigate";
2847 match Wsi.kc2pv
key with
2848 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2849 let incr = if c = 'r'
then -1 else 1 in
2851 match search (m_active
+ incr) m_qsearch
incr with
2853 state
.text <- m_qsearch ^
" [not found]";
2856 state
.text <- m_qsearch
;
2857 active, firstof m_first
active
2859 G.postRedisplay "listview ctrl-r/s";
2860 set1 active first m_qsearch
;
2862 | Insert
when Wsi.withctrl mask
->
2863 if m_active
>= 0 && m_active
< source#getitemcount
2865 let s, _ = source#getitem m_active
in
2871 if emptystr m_qsearch
2874 let qsearch = withoutlastutf8 m_qsearch
in
2878 G.postRedisplay "listview empty qsearch";
2879 set1 m_active m_first
E.s;
2883 match search m_active
qsearch ~
-1 with
2885 state
.text <- qsearch ^
" [not found]";
2888 state
.text <- qsearch;
2889 active, firstof m_first
active
2891 G.postRedisplay "listview backspace qsearch";
2892 set1 active first qsearch
2895 | _ when not
(Wsi.isspecialkey
key) ->
2896 let pattern = m_qsearch ^ toutf8
key in
2898 match search m_active
pattern 1 with
2900 state
.text <- pattern ^
" [not found]";
2903 state
.text <- pattern;
2904 active, firstof m_first
active
2906 G.postRedisplay "listview qsearch add";
2907 set1 active first pattern;
2911 if emptystr m_qsearch
2913 G.postRedisplay "list view escape";
2914 let mx, my
= state
.mpos
in
2918 source#exit ~uioh
:(coe self
)
2919 ~cancel
:true ~
active:m_active ~
first:m_first ~pan
:m_pan
2921 | None
-> m_prev_uioh
2926 G.postRedisplay "list view kill qsearch";
2927 coe {< m_qsearch
= E.s >}
2930 | Enter
| KPenter
->
2932 let self = {< m_qsearch
= E.s >} in
2934 G.postRedisplay "listview enter";
2935 if m_active
>= 0 && m_active
< source#getitemcount
2937 source#exit ~uioh
:(coe self) ~cancel
:false
2938 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2941 source#exit ~uioh
:(coe self) ~cancel
:true
2942 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2945 begin match opt with
2946 | None
-> m_prev_uioh
2950 | Delete
| KPdelete
->
2953 | Up
| KPup
-> navigate ~
-1
2954 | Down
| KPdown
-> navigate 1
2955 | Prior
| KPprior
-> navigate ~
-(fstate
.maxrows
)
2956 | Next
| KPnext
-> navigate fstate
.maxrows
2958 | Right
| KPright
->
2960 G.postRedisplay "listview right";
2961 coe {< m_pan
= m_pan
- 1 >}
2965 G.postRedisplay "listview left";
2966 coe {< m_pan
= m_pan
+ 1 >}
2969 let active = find 0 1 in
2970 G.postRedisplay "listview home";
2974 let first = max
0 (itemcount - fstate
.maxrows
) in
2975 let active = find (itemcount - 1) ~
-1 in
2976 G.postRedisplay "listview end";
2979 | _ when (key = 0 || Wsi.isspecialkey
key) ->
2982 | (Insert
|KPminus
|KPplus
|Ascii
_|Code
_|Fn
_) ->
2983 dolog
"listview unknown key %#x" key; coe self
2985 method key key mask
=
2986 match state
.mode
with
2988 textentrykeyboard key mask te
;
2990 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2992 method button button down
x y _ =
2995 | 1 when vscrollhit x ->
2996 G.postRedisplay "listview scroll";
2999 let _, position, sh = self#
scrollph in
3000 if y > truncate
position && y < truncate
(position +. sh)
3002 state
.mstate
<- Mscrolly
;
3006 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3007 let first = truncate
(s *. float source#getitemcount
) in
3008 let first = min source#getitemcount
first in
3009 Some
(coe {< m_first
= first; m_active
= first >})
3011 state
.mstate
<- Mnone
;
3015 begin match self#elemunder
y with
3017 G.postRedisplay "listview click";
3018 source#exit ~uioh
:(coe {< m_active
= n >})
3019 ~cancel
:false ~
active:n ~
first:m_first ~pan
:m_pan
3023 | n when (n == 4 || n == 5) && not down
->
3024 let len = source#getitemcount
in
3026 if n = 5 && m_first
+ fstate
.maxrows
>= len
3030 let first = m_first
+ (if n == 4 then -1 else 1) in
3031 bound
first 0 (len - 1)
3033 G.postRedisplay "listview wheel";
3034 Some
(coe {< m_first
= first >})
3035 | n when (n = 6 || n = 7) && not down
->
3036 let inc = if n = 7 then -1 else 1 in
3037 G.postRedisplay "listview hwheel";
3038 Some
(coe {< m_pan
= m_pan
+ inc >})
3043 | None
-> m_prev_uioh
3046 method multiclick
_ x y = self#button
1 true x y
3049 match state
.mstate
with
3051 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3052 let first = truncate
(s *. float source#getitemcount
) in
3053 let first = min source#getitemcount
first in
3054 G.postRedisplay "listview motion";
3055 coe {< m_first
= first; m_active
= first >}
3063 method pmotion
x y =
3064 if x < state
.winw
- conf
.scrollbw
3067 match self#elemunder
y with
3068 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3069 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3073 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3078 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3082 method infochanged
_ = ()
3084 method scrollpw
= (0, 0.0, 0.0)
3086 let nfs = fstate
.fontsize
+ 1 in
3087 let y = m_first
* nfs in
3088 let itemcount = source#getitemcount
in
3089 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3090 let maxy = maxi * nfs in
3091 let p, h = scrollph y maxy in
3094 method modehash
= modehash
3095 method eformsgs
= false
3096 method alwaysscrolly
= true
3099 class outlinelistview ~zebra ~source
=
3100 let settext autonarrow
s =
3103 let ss = source#statestr
in
3107 else "{" ^
ss ^
"} [" ^
s ^
"]"
3108 else state
.text <- s
3114 ~source
:(source
:> lvsource
)
3116 ~modehash
:(findkeyhash conf
"outline")
3119 val m_autonarrow
= false
3121 method! key key mask
=
3123 if emptystr state
.text
3125 else fstate
.maxrows - 2
3127 let calcfirst first active =
3130 let rows = active - first in
3131 if rows > maxrows then active - maxrows else first
3135 let active = m_active
+ incr in
3136 let active = bound
active 0 (source#getitemcount
- 1) in
3137 let first = calcfirst m_first
active in
3138 G.postRedisplay "outline navigate";
3139 coe {< m_active
= active; m_first
= first >}
3141 let navscroll first =
3143 let dist = m_active
- first in
3149 else first + maxrows
3152 G.postRedisplay "outline navscroll";
3153 coe {< m_first
= first; m_active
= active >}
3155 let ctrl = Wsi.withctrl mask
in
3157 match Wsi.kc2pv
key with
3158 | Ascii '
a'
when ctrl ->
3161 then (source#denarrow
; E.s)
3163 let pattern = source#renarrow
in
3164 if nonemptystr m_qsearch
3165 then (source#narrow m_qsearch
; m_qsearch
)
3169 settext (not m_autonarrow
) text;
3170 G.postRedisplay "toggle auto narrowing";
3171 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3173 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3175 G.postRedisplay "toggle auto narrowing";
3176 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3178 | Ascii '
n'
when ctrl ->
3179 source#narrow m_qsearch
;
3181 then source#add_narrow_pattern m_qsearch
;
3182 G.postRedisplay "outline ctrl-n";
3183 coe {< m_first
= 0; m_active
= 0 >}
3185 | Ascii 'S'
when ctrl ->
3186 let active = source#calcactive
(getanchor
()) in
3187 let first = firstof m_first
active in
3188 G.postRedisplay "outline ctrl-s";
3189 coe {< m_first
= first; m_active
= active >}
3191 | Ascii 'u'
when ctrl ->
3192 G.postRedisplay "outline ctrl-u";
3193 if m_autonarrow
&& nonemptystr m_qsearch
3195 ignore
(source#renarrow
);
3196 settext m_autonarrow
E.s;
3197 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3200 source#del_narrow_pattern
;
3201 let pattern = source#renarrow
in
3203 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3205 settext m_autonarrow
text;
3206 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3209 | Ascii '
l'
when ctrl ->
3210 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3211 G.postRedisplay "outline ctrl-l";
3212 coe {< m_first
= first >}
3214 | Ascii '
\t'
when m_autonarrow
->
3215 if nonemptystr m_qsearch
3217 G.postRedisplay "outline list view tab";
3218 source#add_narrow_pattern m_qsearch
;
3220 coe {< m_qsearch
= E.s >}
3224 | Escape
when m_autonarrow
->
3225 if nonemptystr m_qsearch
3226 then source#add_narrow_pattern m_qsearch
;
3229 | Enter
| KPenter
when m_autonarrow
->
3230 if nonemptystr m_qsearch
3231 then source#add_narrow_pattern m_qsearch
;
3234 | _ when m_autonarrow
&& (not
(Wsi.isspecialkey
key)) ->
3235 let pattern = m_qsearch ^ toutf8
key in
3236 G.postRedisplay "outlinelistview autonarrow add";
3237 source#narrow
pattern;
3238 settext true pattern;
3239 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3241 | key when m_autonarrow
&& key = Backspace
->
3242 if emptystr m_qsearch
3245 let pattern = withoutlastutf8 m_qsearch
in
3246 G.postRedisplay "outlinelistview autonarrow backspace";
3247 ignore
(source#renarrow
);
3248 source#narrow
pattern;
3249 settext true pattern;
3250 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3252 | Up
| KPup
when ctrl ->
3253 navscroll (max
0 (m_first
- 1))
3255 | Down
| KPdown
when ctrl ->
3256 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3258 | Up
| KPup
-> navigate ~
-1
3259 | Down
| KPdown
-> navigate 1
3260 | Prior
| KPprior
-> navigate ~
-(fstate
.maxrows)
3261 | Next
| KPnext
-> navigate fstate
.maxrows
3263 | Right
| KPright
->
3267 G.postRedisplay "outline ctrl right";
3268 {< m_pan
= m_pan
+ 1 >}
3270 else self#updownlevel
1
3278 G.postRedisplay "outline ctrl left";
3279 {< m_pan
= m_pan
- 1 >}
3281 else self#updownlevel ~
-1
3286 G.postRedisplay "outline home";
3287 coe {< m_first
= 0; m_active
= 0 >}
3290 let active = source#getitemcount
- 1 in
3291 let first = max
0 (active - fstate
.maxrows) in
3292 G.postRedisplay "outline end";
3293 coe {< m_active
= active; m_first
= first >}
3295 | (Delete
|Escape
|Insert
|Enter
|KPdelete
|KPenter
|KPminus
3296 |KPplus
|Ascii
_|Code
_|Backspace
|Fn
_) -> super#
key key mask
3299 let genhistoutlines () =
3301 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3302 compare c2
.lastvisit c1
.lastvisit
)
3304 (fun ((path
, c, _, _, _, origin
) as hist
) ->
3305 let path = if nonemptystr origin
then origin
else path in
3306 let base = mbtoutf8
@@ Filename.basename
path in
3307 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3312 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3313 Config.save
leavebirdseye;
3314 state
.anchor <- anchor;
3315 state
.bookmarks
<- bookmarks
;
3316 state
.origin
<- origin
;
3319 let x0, y0, x1, y1 = conf
.trimfuzz
in
3320 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3321 reshape ~firsttime
:true state
.winw state
.winh
;
3322 opendoc path origin
;
3326 let makecheckers () =
3327 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3329 converted by Issac Trotts. July 25, 2002 *)
3330 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3331 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3332 let id = GlTex.gen_texture
() in
3333 GlTex.bind_texture ~target
:`texture_2d
id;
3334 GlPix.store
(`unpack_alignment
1);
3335 GlTex.image2d
image;
3336 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3337 [ `mag_filter `nearest
; `min_filter `nearest
];
3341 let setcheckers enabled
=
3342 match state
.checkerstexid
with
3344 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3346 | Some checkerstexid
->
3349 GlTex.delete_texture checkerstexid
;
3350 state
.checkerstexid
<- None
;
3354 let describe_location () =
3355 let fn = page_of_y state
.y in
3356 let ln = page_of_y
(state
.y + state
.winh
- 1) in
3357 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
3361 else (100. *. (float state
.y /. float maxy))
3365 Printf.sprintf
"page %d of %d [%.2f%%]"
3366 (fn+1) state
.pagecount
percent
3369 "pages %d-%d of %d [%.2f%%]"
3370 (fn+1) (ln+1) state
.pagecount
percent
3373 let setpresentationmode v
=
3374 let n = page_of_y state
.y in
3375 state
.anchor <- (n, 0.0, 1.0);
3376 conf
.presentation
<- v
;
3377 if conf
.fitmodel
= FitPage
3378 then reqlayout conf
.angle conf
.fitmodel
;
3382 let setbgcol (r
, g, b) =
3384 let r = r *. 255.0 |> truncate
3385 and g = g *. 255.0 |> truncate
3386 and b = b *. 255.0 |> truncate
in
3387 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3389 Wsi.setwinbgcol
col;
3393 let btos b = if b then UniSyms.radical else E.s in
3394 let showextended = ref false in
3395 let leave mode
_ = state
.mode
<- mode
in
3398 val mutable m_l
= []
3399 val mutable m_a
= E.a
3400 val mutable m_prev_uioh
= nouioh
3401 val mutable m_prev_mode
= View
3403 inherit lvsourcebase
3405 method reset prev_mode prev_uioh
=
3406 m_a
<- Array.of_list
(List.rev m_l
);
3408 m_prev_mode
<- prev_mode
;
3409 m_prev_uioh
<- prev_uioh
;
3411 method int name get
set =
3417 try set (int_of_string
s)
3419 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3423 let te = name ^
": ", E.s, None
, intentry, ondone, true in
3424 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3428 method int_with_suffix name get
set =
3430 (name
, `intws get
, 1,
3434 try set (int_of_string_with_suffix
s)
3436 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3441 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
3443 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3447 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3449 (name
, `
bool (btos, get
), offset
, Action
(
3456 method color name get
set =
3458 (name
, `
color get
, 1,
3461 let invalid = (nan
, nan
, nan
) in
3464 try color_of_string
s
3466 state
.text <- Printf.sprintf
"bad color `%s': %s"
3473 let te = name ^
": ", E.s, None
, textentry, ondone, true in
3474 state
.text <- color_to_string
(get
());
3475 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3479 method string name get
set =
3481 (name
, `
string get
, 1,
3484 let ondone s = set s in
3485 let te = name ^
": ", E.s, None
, textentry, ondone, true in
3486 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3490 method colorspace name get
set =
3492 (name
, `
string get
, 1,
3497 inherit lvsourcebase
3500 m_active
<- CSTE.to_int conf
.colorspace
;
3503 method getitemcount
=
3504 Array.length
CSTE.names
3507 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3508 ignore
(uioh
, first, pan
);
3509 if not cancel
then set active;
3511 method hasaction
_ = true
3515 let modehash = findkeyhash conf
"info" in
3516 coe (new listview ~zebra
:false ~helpmode
:false
3517 ~
source ~trusted
:true ~
modehash)
3520 method paxmark name get
set =
3522 (name
, `
string get
, 1,
3527 inherit lvsourcebase
3530 m_active
<- MTE.to_int conf
.paxmark
;
3533 method getitemcount
= Array.length
MTE.names
3534 method getitem
n = (MTE.names
.(n), 0)
3535 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3536 ignore
(uioh
, first, pan
);
3537 if not cancel
then set active;
3539 method hasaction
_ = true
3543 let modehash = findkeyhash conf
"info" in
3544 coe (new listview ~zebra
:false ~helpmode
:false
3545 ~
source ~trusted
:true ~
modehash)
3548 method fitmodel name get
set =
3550 (name
, `
string get
, 1,
3555 inherit lvsourcebase
3558 m_active
<- FMTE.to_int conf
.fitmodel
;
3561 method getitemcount
= Array.length
FMTE.names
3562 method getitem
n = (FMTE.names
.(n), 0)
3563 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3564 ignore
(uioh
, first, pan
);
3565 if not cancel
then set active;
3567 method hasaction
_ = true
3571 let modehash = findkeyhash conf
"info" in
3572 coe (new listview ~zebra
:false ~helpmode
:false
3573 ~
source ~trusted
:true ~
modehash)
3576 method caption
s offset
=
3577 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3579 method caption2
s f offset
=
3580 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3582 method getitemcount
= Array.length m_a
3585 let tostr = function
3586 | `
int f -> string_of_int
(f ())
3587 | `intws
f -> string_with_suffix_of_int
(f ())
3589 | `
color f -> color_to_string
(f ())
3590 | `
bool (btos, f) -> btos (f ())
3593 let name, t
, offset
, _ = m_a
.(n) in
3594 ((let s = tostr t
in
3596 then Printf.sprintf
"%s\t%s" name s
3600 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3605 match m_a
.(active) with
3606 | _, _, _, Action
f -> f uioh
3607 | _, _, _, Noaction
-> uioh
3618 method hasaction
n =
3620 | _, _, _, Action
_ -> true
3621 | _, _, _, Noaction
-> false
3623 initializer m_active
<- 1
3626 let rec fillsrc prevmode prevuioh
=
3627 let sep () = src#caption
E.s 0 in
3628 let colorp name get
set =
3630 (fun () -> color_to_string
(get
()))
3633 let c = color_of_string
v in
3637 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3640 let oldmode = state
.mode
in
3641 let birdseye = isbirdseye state
.mode
in
3643 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3645 src#
bool "presentation mode"
3646 (fun () -> conf
.presentation
)
3647 (fun v -> setpresentationmode v);
3649 src#
bool "ignore case in searches"
3650 (fun () -> conf
.icase
)
3651 (fun v -> conf
.icase
<- v);
3654 (fun () -> conf
.preload)
3655 (fun v -> conf
.preload <- v);
3657 src#
bool "highlight links"
3658 (fun () -> conf
.hlinks
)
3659 (fun v -> conf
.hlinks
<- v);
3661 src#
bool "under info"
3662 (fun () -> conf
.underinfo
)
3663 (fun v -> conf
.underinfo
<- v);
3665 src#
bool "persistent bookmarks"
3666 (fun () -> conf
.savebmarks
)
3667 (fun v -> conf
.savebmarks
<- v);
3669 src#fitmodel
"fit model"
3670 (fun () -> FMTE.to_string conf
.fitmodel
)
3671 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3673 src#
bool "trim margins"
3674 (fun () -> conf
.trimmargins
)
3675 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3677 src#
bool "persistent location"
3678 (fun () -> conf
.jumpback
)
3679 (fun v -> conf
.jumpback
<- v);
3682 src#
int "inter-page space"
3683 (fun () -> conf
.interpagespace
)
3685 conf
.interpagespace
<- n;
3686 docolumns conf
.columns
;
3688 match state
.layout with
3693 state
.maxy <- calcheight
();
3694 let y = getpagey
pageno in
3695 gotoxy state
.x (y + py)
3699 (fun () -> conf
.pagebias
)
3700 (fun v -> conf
.pagebias
<- v);
3702 src#
int "scroll step"
3703 (fun () -> conf
.scrollstep
)
3704 (fun n -> conf
.scrollstep
<- n);
3706 src#
int "horizontal scroll step"
3707 (fun () -> conf
.hscrollstep
)
3708 (fun v -> conf
.hscrollstep
<- v);
3710 src#
int "auto scroll step"
3712 match state
.autoscroll
with
3714 | _ -> conf
.autoscrollstep
)
3716 let n = boundastep state
.winh
n in
3717 if state
.autoscroll
<> None
3718 then state
.autoscroll
<- Some
n;
3719 conf
.autoscrollstep
<- n);
3722 (fun () -> truncate
(conf
.zoom *. 100.))
3723 (fun v -> pivotzoom ((float v) /. 100.));
3726 (fun () -> conf
.angle
)
3727 (fun v -> reqlayout v conf
.fitmodel
);
3729 src#
int "scroll bar width"
3730 (fun () -> conf
.scrollbw
)
3733 reshape state
.winw state
.winh
;
3736 src#
int "scroll handle height"
3737 (fun () -> conf
.scrollh
)
3738 (fun v -> conf
.scrollh
<- v;);
3740 src#
int "thumbnail width"
3741 (fun () -> conf
.thumbw
)
3743 conf
.thumbw
<- min
4096 v;
3746 leavebirdseye beye
false;
3753 let mode = state
.mode in
3754 src#
string "columns"
3756 match conf
.columns
with
3758 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3759 | Csplit
(count
, _) -> "-" ^ string_of_int count
3762 let n, a, b = multicolumns_of_string
v in
3763 setcolumns mode n a b);
3766 src#caption
"Pixmap cache" 0;
3767 src#int_with_suffix
"size (advisory)"
3768 (fun () -> conf
.memlimit
)
3769 (fun v -> conf
.memlimit
<- v);
3773 Printf.sprintf
"%s bytes, %d tiles"
3774 (string_with_suffix_of_int state
.memused
)
3775 (Hashtbl.length state
.tilemap
)) 1;
3778 src#caption
"Layout" 0;
3779 src#caption2
"Dimension"
3781 Printf.sprintf
"%dx%d (virtual %dx%d)"
3782 state
.winw state
.winh
3787 src#caption2
"Position" (fun () ->
3788 Printf.sprintf
"%dx%d" state
.x state
.y
3791 src#caption2
"Position" (fun () -> describe_location ()) 1
3795 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3796 "Save these parameters as global defaults at exit"
3797 (fun () -> conf
.bedefault
)
3798 (fun v -> conf
.bedefault
<- v)
3802 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3803 src#
bool ~offset
:0 ~
btos "Extended parameters"
3804 (fun () -> !showextended)
3805 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3809 (fun () -> conf
.checkers
)
3810 (fun v -> conf
.checkers
<- v; setcheckers v);
3811 src#
bool "update cursor"
3812 (fun () -> conf
.updatecurs
)
3813 (fun v -> conf
.updatecurs
<- v);
3814 src#
bool "scroll-bar on the left"
3815 (fun () -> conf
.leftscroll
)
3816 (fun v -> conf
.leftscroll
<- v);
3818 (fun () -> conf
.verbose
)
3819 (fun v -> conf
.verbose
<- v);
3820 src#
bool "invert colors"
3821 (fun () -> conf
.invert
)
3822 (fun v -> conf
.invert
<- v);
3824 (fun () -> conf
.maxhfit
)
3825 (fun v -> conf
.maxhfit
<- v);
3827 (fun () -> conf
.pax
!= None
)
3830 then conf
.pax
<- Some
(ref (now
(), 0, 0))
3831 else conf
.pax
<- None
);
3832 src#
string "uri launcher"
3833 (fun () -> conf
.urilauncher
)
3834 (fun v -> conf
.urilauncher
<- v);
3835 src#
string "path launcher"
3836 (fun () -> conf
.pathlauncher
)
3837 (fun v -> conf
.pathlauncher
<- v);
3838 src#
string "tile size"
3839 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3842 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3843 conf
.tilew
<- max
64 w;
3844 conf
.tileh
<- max
64 h;
3847 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3850 src#
int "texture count"
3851 (fun () -> conf
.texcount
)
3854 then conf
.texcount
<- v
3855 else impmsg "failed to set texture count please retry later"
3857 src#
int "slice height"
3858 (fun () -> conf
.sliceheight
)
3860 conf
.sliceheight
<- v;
3861 wcmd "sliceh %d" conf
.sliceheight
;
3863 src#
int "anti-aliasing level"
3864 (fun () -> conf
.aalevel
)
3866 conf
.aalevel
<- bound
v 0 8;
3867 state
.anchor <- getanchor
();
3868 opendoc state
.path state
.password;
3870 src#
string "page scroll scaling factor"
3871 (fun () -> string_of_float conf
.pgscale)
3874 let s = float_of_string
v in
3877 state
.text <- Printf.sprintf
3878 "bad page scroll scaling factor `%s': %s" v
3882 src#
int "ui font size"
3883 (fun () -> fstate
.fontsize
)
3884 (fun v -> setfontsize (bound
v 5 100));
3885 src#
int "hint font size"
3886 (fun () -> conf
.hfsize
)
3887 (fun v -> conf
.hfsize
<- bound
v 5 100);
3888 colorp "background color"
3889 (fun () -> conf
.bgcolor
)
3890 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3891 src#
bool "crop hack"
3892 (fun () -> conf
.crophack
)
3893 (fun v -> conf
.crophack
<- v);
3894 src#
string "trim fuzz"
3895 (fun () -> irect_to_string conf
.trimfuzz
)
3898 conf
.trimfuzz
<- irect_of_string
v;
3900 then settrim true conf
.trimfuzz
;
3902 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3905 src#
string "throttle"
3907 match conf
.maxwait
with
3908 | None
-> "show place holder if page is not ready"
3911 then "wait for page to fully render"
3913 "wait " ^ string_of_float
time
3914 ^
" seconds before showing placeholder"
3918 let f = float_of_string
v in
3920 then conf
.maxwait
<- None
3921 else conf
.maxwait
<- Some
f
3923 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3926 src#
string "ghyll scroll"
3928 match conf
.ghyllscroll
with
3930 | Some nab
-> ghyllscroll_to_string nab
3933 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3936 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3938 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3941 src#
string "selection command"
3942 (fun () -> conf
.selcmd
)
3943 (fun v -> conf
.selcmd
<- v);
3944 src#
string "synctex command"
3945 (fun () -> conf
.stcmd
)
3946 (fun v -> conf
.stcmd
<- v);
3947 src#
string "pax command"
3948 (fun () -> conf
.paxcmd
)
3949 (fun v -> conf
.paxcmd
<- v);
3950 src#
string "ask password command"
3951 (fun () -> conf
.passcmd)
3952 (fun v -> conf
.passcmd <- v);
3953 src#
string "save path command"
3954 (fun () -> conf
.savecmd
)
3955 (fun v -> conf
.savecmd
<- v);
3956 src#colorspace
"color space"
3957 (fun () -> CSTE.to_string conf
.colorspace
)
3959 conf
.colorspace
<- CSTE.of_int
v;
3963 src#paxmark
"pax mark method"
3964 (fun () -> MTE.to_string conf
.paxmark
)
3965 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3966 if bousable
() && !opengl_has_pbo
3969 (fun () -> conf
.usepbo
)
3970 (fun v -> conf
.usepbo
<- v);
3971 src#
bool "mouse wheel scrolls pages"
3972 (fun () -> conf
.wheelbypage
)
3973 (fun v -> conf
.wheelbypage
<- v);
3974 src#
bool "open remote links in a new instance"
3975 (fun () -> conf
.riani
)
3976 (fun v -> conf
.riani
<- v);
3977 src#
bool "edit annotations inline"
3978 (fun () -> conf
.annotinline
)
3979 (fun v -> conf
.annotinline
<- v);
3980 src#
bool "coarse positioning in presentation mode"
3981 (fun () -> conf
.coarseprespos
)
3982 (fun v -> conf
.coarseprespos
<- v);
3983 src#
bool "use document CSS"
3984 (fun () -> conf
.usedoccss
)
3986 conf
.usedoccss
<- v;
3987 state
.anchor <- getanchor
();
3988 opendoc state
.path state
.password;
3993 src#caption
"Document" 0;
3994 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3995 src#caption2
"Pages"
3996 (fun () -> string_of_int state
.pagecount
) 1;
3997 src#caption2
"Dimensions"
3998 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3999 if nonemptystr conf
.css
4000 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
4004 src#caption
"Trimmed margins" 0;
4005 src#caption2
"Dimensions"
4006 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4010 src#caption
"OpenGL" 0;
4011 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4012 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4015 src#caption
"Location" 0;
4016 if nonemptystr state
.origin
4017 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
4018 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
4020 src#reset prevmode prevuioh
;
4025 let prevmode = state
.mode
4026 and prevuioh
= state
.uioh in
4027 fillsrc prevmode prevuioh
;
4028 let source = (src :> lvsource
) in
4029 let modehash = findkeyhash conf
"info" in
4032 inherit listview ~zebra
:false ~helpmode
:false
4033 ~
source ~trusted
:true ~
modehash as super
4034 val mutable m_prevmemused
= 0
4035 method! infochanged
= function
4037 if m_prevmemused
!= state
.memused
4039 m_prevmemused
<- state
.memused
;
4040 G.postRedisplay "memusedchanged";
4042 | Pdim
-> G.postRedisplay "pdimchanged"
4043 | Docinfo
-> fillsrc prevmode prevuioh
4045 method! key key mask
=
4046 if not
(Wsi.withctrl mask
)
4049 begin [@warning
"-4"]
4050 match Wsi.kc2pv
key with
4051 | Left
| KPleft
-> coe (self#updownlevel ~
-1)
4052 | Right
| KPright
-> coe (self#updownlevel
1)
4053 | _ -> super#
key key mask
4055 else super#
key key mask
4057 G.postRedisplay "info";
4063 inherit lvsourcebase
4064 method getitemcount
= Array.length state
.help
4066 let s, l, _ = state
.help
.(n) in
4069 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4073 match state
.help
.(active) with
4074 | _, _, Action
f -> Some
(f uioh)
4075 | _, _, Noaction
-> Some
uioh
4084 method hasaction
n =
4085 match state
.help
.(n) with
4086 | _, _, Action
_ -> true
4087 | _, _, Noaction
-> false
4093 let modehash = findkeyhash conf
"help" in
4095 state
.uioh <- coe (new listview
4096 ~zebra
:false ~helpmode
:true
4097 ~
source ~trusted
:true ~
modehash);
4098 G.postRedisplay "help";
4104 inherit lvsourcebase
4105 val mutable m_items
= E.a
4107 method getitemcount
= 1 + Array.length m_items
4112 else m_items
.(n-1), 0
4114 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4119 then Buffer.clear state
.errmsgs
;
4126 method hasaction
n =
4130 state
.newerrmsgs
<- false;
4131 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4132 m_items
<- Array.of_list
l
4141 let source = (msgsource :> lvsource
) in
4142 let modehash = findkeyhash conf
"listview" in
4145 inherit listview ~zebra
:false ~helpmode
:false
4146 ~
source ~trusted
:false ~
modehash as super
4149 then msgsource#reset
;
4152 G.postRedisplay "msgs";
4156 let editor = getenvwithdef
"EDITOR" E.s in
4160 let tmppath = Filename.temp_file
"llpp" "note" in
4163 let oc = open_out
tmppath in
4167 let execstr = editor ^
" " ^
tmppath in
4169 match spawn
execstr [] with
4170 | (exception exn
) ->
4171 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4174 match Unix.waitpid
[] pid with
4175 | (exception exn
) ->
4176 impmsg "waitpid(%d) failed: %s" pid @@ exntos exn
;
4180 | Unix.WEXITED
0 -> filecontents
tmppath
4182 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4184 | Unix.WSIGNALED
n ->
4185 impmsg "editor process(%s) was killed by signal %d" execstr n;
4187 | Unix.WSTOPPED
n ->
4188 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4191 match Unix.unlink
tmppath with
4192 | (exception exn
) ->
4193 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4198 let enterannotmode opaque slinkindex
=
4201 inherit lvsourcebase
4202 val mutable m_text
= E.s
4203 val mutable m_items
= E.a
4205 method getitemcount
= Array.length m_items
4208 let label, _func
= m_items
.(n) in
4211 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4212 ignore
(uioh, first, pan
);
4215 let _label, func
= m_items
.(active) in
4220 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4223 let rec split accu b i
=
4225 if p = String.length
s
4226 then (String.sub s b (p-b), unit) :: accu
4228 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4230 let ss = if i
= 0 then E.s else String.sub s b i
in
4231 split ((ss, unit)::accu) (p+1) 0
4236 wcmd "freepage %s" (~
> opaque);
4238 Hashtbl.fold (fun key opaque'
accu ->
4239 if opaque'
= opaque'
4240 then key :: accu else accu) state
.pagemap
[]
4242 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4244 gotoxy state
.x state
.y
4247 delannot
opaque slinkindex
;
4250 let edit inline
() =
4255 modannot
opaque slinkindex
s;
4261 let mode = state
.mode in
4264 ("annotation: ", m_text
, None
, textentry, update, true),
4265 fun _ -> state
.mode <- mode);
4269 let s = getusertext m_text
in
4274 ( "[Copy]", fun () -> selstring m_text
)
4275 :: ("[Delete]", dele)
4276 :: ("[Edit]", edit conf
.annotinline
)
4278 :: split [] 0 0 |> List.rev
|> Array.of_list
4285 let s = getannotcontents
opaque slinkindex
in
4288 let source = (msgsource :> lvsource
) in
4289 let modehash = findkeyhash conf
"listview" in
4290 state
.uioh <- coe (object
4291 inherit listview ~zebra
:false ~helpmode
:false
4292 ~
source ~trusted
:false ~
modehash
4294 G.postRedisplay "enterannotmode";
4297 let gotoremote spec
=
4298 let filename, dest
= splitatchar spec '#'
in
4299 let getpath filename =
4301 if nonemptystr
filename
4303 if Filename.is_relative
filename
4305 let dir = Filename.dirname state
.path in
4307 if Filename.is_implicit
dir
4308 then Filename.concat
(Sys.getcwd
()) dir
4311 Filename.concat
dir filename
4315 if Sys.file_exists
path
4319 let path = getpath filename in
4323 let cmd = Lazy.force_val lcmd
in
4324 match spawn
cmd with
4326 | (exception exn
) ->
4327 dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4329 let anchor = getanchor
() in
4330 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4331 state
.origin
<- E.s;
4332 state
.ranchors
<- ranchor :: state
.ranchors
;
4335 if substratis spec
0 "page="
4337 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4339 state
.anchor <- (pageno, 0.0, 0.0);
4340 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4342 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4344 state
.nameddest
<- dest
;
4345 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4349 let gotounder = function
4350 | Ulinkuri
s when isexternallink
s ->
4351 if substratis
s 0 "file://"
4352 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4355 let pageno, x, y = uritolocation
s in
4357 gotopagexy !wtmode pageno x y
4358 | Utext
_ | Unone
-> ()
4359 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4362 let gotooutline (_, _, kind
) =
4366 let (pageno, y, _) = anchor in
4368 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4372 | Ouri
uri -> gotounder (Ulinkuri
uri)
4373 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4374 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4375 | Ohistory hist
-> gotohist hist
4376 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4379 class outlinesoucebase fetchoutlines
= object (self)
4380 inherit lvsourcebase
4381 val mutable m_items
= E.a
4382 val mutable m_minfo
= E.a
4383 val mutable m_orig_items
= E.a
4384 val mutable m_orig_minfo
= E.a
4385 val mutable m_narrow_patterns
= []
4386 val mutable m_gen
= -1
4388 method getitemcount
= Array.length m_items
4391 let s, n, _ = m_items
.(n) in
4394 method exit ~
(uioh:uioh) ~cancel ~
active ~
(first:int) ~pan
: uioh option =
4395 ignore
(uioh, first);
4397 if m_narrow_patterns
= []
4398 then m_orig_items
, m_orig_minfo
4399 else m_items
, m_minfo
4406 gotooutline m_items
.(active);
4414 method hasaction
(_:int) = true
4417 if Array.length m_items
!= Array.length m_orig_items
4420 match m_narrow_patterns
with
4422 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4424 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4428 match m_narrow_patterns
with
4431 | head
:: _ -> UniSyms.ellipsis ^ head
4433 method narrow
pattern =
4434 match Str.regexp_case_fold
pattern with
4435 | (exception _) -> ()
4437 let rec loop accu minfo n =
4440 m_items
<- Array.of_list
accu;
4441 m_minfo
<- Array.of_list
minfo;
4444 let (s, _, _) as o = m_items
.(n) in
4446 match Str.search_forward re
s 0 with
4447 | (exception Not_found
) -> accu, minfo
4448 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4450 loop accu minfo (n-1)
4452 loop [] [] (Array.length m_items
- 1)
4454 method! getminfo
= m_minfo
4457 m_orig_items
<- fetchoutlines
();
4458 m_minfo
<- m_orig_minfo
;
4459 m_items
<- m_orig_items
4461 method add_narrow_pattern
pattern =
4462 m_narrow_patterns
<- pattern :: m_narrow_patterns
4464 method del_narrow_pattern
=
4465 match m_narrow_patterns
with
4466 | _ :: rest
-> m_narrow_patterns
<- rest
4471 match m_narrow_patterns
with
4472 | pattern :: [] -> self#narrow
pattern; pattern
4474 List.fold_left
(fun accu pattern ->
4475 self#narrow
pattern;
4476 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4478 method calcactive
(_:anchor) = 0
4480 method reset
anchor items =
4481 if state
.gen
!= m_gen
4483 m_orig_items
<- items;
4485 m_narrow_patterns
<- [];
4487 m_orig_minfo
<- E.a;
4491 if items != m_orig_items
4493 m_orig_items
<- items;
4494 if m_narrow_patterns
== []
4495 then m_items
<- items;
4498 let active = self#calcactive
anchor in
4500 m_first
<- firstof m_first
active
4504 let outlinesource fetchoutlines
=
4506 inherit outlinesoucebase fetchoutlines
4507 method! calcactive
anchor =
4508 let rely = getanchory anchor in
4509 let rec loop n best bestd
=
4510 if n = Array.length m_items
4513 let _, _, kind
= m_items
.(n) in
4516 let orely = getanchory anchor in
4517 let d = abs
(orely - rely) in
4520 else loop (n+1) best bestd
4521 | Onone
| Oremote
_ | Olaunch
_
4522 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4523 loop (n+1) best bestd
4529 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4530 let mkselector sourcetype
=
4531 let fetchoutlines () =
4532 match sourcetype
with
4533 | `bookmarks
-> Array.of_list state
.bookmarks
4534 | `outlines
-> state
.outlines
4535 | `history
-> genhistoutlines ()
4538 if sourcetype
= `history
4539 then new outlinesoucebase
fetchoutlines
4540 else outlinesource fetchoutlines
4543 let outlines = fetchoutlines () in
4544 if Array.length
outlines = 0
4546 showtext ' ' errmsg
;
4550 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4551 let anchor = getanchor
() in
4552 source#reset
anchor outlines;
4553 state
.text <- source#greetmsg
;
4555 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4556 G.postRedisplay "enter selector";
4559 let mkenter sourcetype errmsg
=
4560 let enter = mkselector sourcetype
in
4561 fun () -> enter errmsg
4563 mkenter `
outlines "document has no outline"
4564 , mkenter `bookmarks
"document has no bookmarks (yet)"
4565 , mkenter `history
"history is empty"
4568 let quickbookmark ?title
() =
4569 match state
.layout with
4575 let tm = Unix.localtime
(now
()) in
4577 "Quick (page %d) (bookmarked at %02d/%02d/%d %02d:%02d)"
4581 (tm.Unix.tm_year
+ 1900)
4584 | Some
title -> title
4586 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4589 let setautoscrollspeed step goingdown
=
4590 let incr = max
1 ((abs step
) / 2) in
4591 let incr = if goingdown
then incr else -incr in
4592 let astep = boundastep state
.winh
(step
+ incr) in
4593 state
.autoscroll
<- Some
astep;
4597 match conf
.columns
with
4599 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4602 let panbound x = bound
x (-state
.w) state
.winw
;;
4604 let existsinrow pageno (columns
, coverA
, coverB
) p =
4605 let last = ((pageno - coverA
) mod columns
) + columns
in
4606 let rec any = function
4609 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4613 then (if l.pageno = last then false else any rest
)
4621 match state
.layout with
4623 let pageno = page_of_y state
.y in
4624 gotoghyll (getpagey
(pageno+1))
4626 match conf
.columns
with
4628 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4630 let y = clamp (pgscale state
.winh
) in
4633 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4634 gotoghyll (getpagey
pageno)
4635 | Cmulti
((c, _, _) as cl
, _) ->
4636 if conf
.presentation
4637 && (existsinrow l.pageno cl
4638 (fun l -> l.pageh
> l.pagey + l.pagevh))
4640 let y = clamp (pgscale state
.winh
) in
4643 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4644 gotoghyll (getpagey
pageno)
4646 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4648 let pagey, pageh
= getpageyh
l.pageno in
4649 let pagey = pagey + pageh
* l.pagecol
in
4650 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4651 gotoghyll (pagey + pageh
+ ips)
4655 match state
.layout with
4657 let pageno = page_of_y state
.y in
4658 gotoghyll (getpagey
(pageno-1))
4660 match conf
.columns
with
4662 if conf
.presentation
&& l.pagey != 0
4664 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4666 let pageno = max
0 (l.pageno-1) in
4667 gotoghyll (getpagey
pageno)
4668 | Cmulti
((c, _, coverB
) as cl
, _) ->
4669 if conf
.presentation
&&
4670 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4672 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4675 if l.pageno = state
.pagecount
- coverB
4679 let pageno = max
0 (l.pageno-decr) in
4680 gotoghyll (getpagey
pageno)
4688 let pageno = max
0 (l.pageno-1) in
4689 let pagey, pageh
= getpageyh
pageno in
4692 let pagey, pageh
= getpageyh
l.pageno in
4693 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4699 if emptystr conf
.savecmd
4700 then error
"don't know where to save modified document"
4702 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4705 (fun s -> error
"failed to obtain path to the saved copy: %s" s)
4710 let tmp = path ^
".tmp" in
4712 Unix.rename
tmp path;
4715 let viewkeyboard key mask
=
4717 let mode = state
.mode in
4718 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4721 G.postRedisplay "view:enttext"
4723 let ctrl = Wsi.withctrl mask
in
4724 let key = Wsi.keypadtodigitkey
key in
4726 match Wsi.kc2pv
key with
4727 | Ascii 'Q'
-> exit
0
4730 if hasunsavedchanges
()
4734 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4737 match state
.lnava
with
4738 | None
-> LinkNav
(Ltgendir
0)
4739 | Some
pn -> LinkNav
(Ltexact
pn)
4741 gotoxy state
.x state
.y;
4743 else impmsg "keyboard link navigation does not work under rotation"
4745 | Escape
| Ascii 'q'
->
4746 begin match state
.mstate
with
4749 G.postRedisplay "kill rect";
4752 | Mscrolly
| Mscrollx
4755 begin match state
.mode with
4758 | Ltexact pl
-> state
.lnava
<- Some pl
4759 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4762 G.postRedisplay "esc leave linknav"
4766 match state
.ranchors
with
4768 | (path, password, anchor, origin
) :: rest
->
4769 state
.ranchors
<- rest
;
4770 state
.anchor <- anchor;
4771 state
.origin
<- origin
;
4772 state
.nameddest
<- E.s;
4773 opendoc path password
4778 gotoghyll (getnav ~
-1)
4789 Hashtbl.iter
(fun _ opaque ->
4791 Hashtbl.clear state
.prects
) state
.pagemap
;
4792 G.postRedisplay "dehighlight";
4794 | (Ascii '
/'
| Ascii '?'
) as pv
->
4795 let ondone isforw
s =
4796 cbput state
.hists
.pat
s;
4797 state
.searchpattern
<- s;
4800 let s = String.make
1 (Char.chr
key) in
4801 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4802 textentry, ondone (pv
= Ascii '
/'
), true)
4804 | Ascii '
+'
| KPplus
| Ascii '
='
when ctrl ->
4805 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4806 pivotzoom (conf
.zoom +. incr)
4808 | Ascii '
+'
| KPplus
->
4811 try int_of_string
s with exn
->
4812 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4818 state
.text <- "page bias is now " ^ string_of_int
n;
4821 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
4823 | Ascii '
-'
| KPminus
when ctrl ->
4824 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4825 pivotzoom (max
0.01 (conf
.zoom -. decr))
4827 | Ascii '
-'
| KPminus
->
4828 let ondone msg
= state
.text <- msg
in
4830 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4831 optentry state
.mode, ondone, true
4834 | Ascii '
0'
when ctrl ->
4836 then gotoxy 0 state
.y
4839 | Ascii
('
1'
|'
2'
as c)
4840 when ctrl && conf
.fitmodel
!= FitPage
->
4842 match conf
.columns
with
4843 | Csingle
_ | Cmulti
_ -> 1
4844 | Csplit
(n, _) -> n
4846 let h = state
.winh
-
4847 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4849 let zoom = zoomforh state
.winw
h 0 cols in
4850 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4853 | Ascii '
3'
when ctrl ->
4855 match conf
.fitmodel
with
4856 | FitWidth
-> FitProportional
4857 | FitProportional
-> FitPage
4858 | FitPage
-> FitWidth
4860 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4861 reqlayout conf
.angle
fm
4863 | Ascii '
4'
when ctrl ->
4864 let zoom = getmaxw
() /. float state
.winw
in
4865 if zoom > 0.0 then setzoom zoom
4870 | Ascii '
9'
when ctrl ->
4877 try int_of_string
s with exn
->
4878 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4884 cbput state
.hists
.pag
(string_of_int
n);
4885 gotopage1 (n + conf
.pagebias
- 1) 0;
4888 let pageentry text key =
4889 match Char.unsafe_chr
key with
4890 | '
g'
-> TEdone
text
4891 | _ -> intentry text key
4893 let text = String.make
1 (Char.chr
key) in
4894 enttext (":", text, Some
(onhist state
.hists
.pag
),
4895 pageentry, ondone, true)
4898 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4899 G.postRedisplay "toggle scrollbar";
4902 state
.bzoom
<- not state
.bzoom
;
4904 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4907 conf
.hlinks
<- not conf
.hlinks
;
4908 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4909 G.postRedisplay "toggle highlightlinks";
4912 if conf
.angle
mod 360 = 0
4914 state
.glinks
<- true;
4915 let mode = state
.mode in
4918 (":", E.s, None
, linknentry, linknact gotounder, false),
4920 state
.glinks
<- false;
4924 G.postRedisplay "view:linkent(F)"
4926 else impmsg "hint mode does not work under rotation"
4929 state
.glinks
<- true;
4930 let mode = state
.mode in
4934 ":", E.s, None
, linknentry, linknact (fun under ->
4935 selstring (undertext under);
4939 state
.glinks
<- false;
4943 G.postRedisplay "view:linkent"
4946 begin match state
.autoscroll
with
4948 conf
.autoscrollstep
<- step
;
4949 state
.autoscroll
<- None
4951 if conf
.autoscrollstep
= 0
4952 then state
.autoscroll
<- Some
1
4953 else state
.autoscroll
<- Some conf
.autoscrollstep
4956 | Ascii '
p'
when ctrl ->
4957 launchpath () (* XXX where do error messages go? *)
4960 setpresentationmode (not conf
.presentation
);
4961 showtext ' '
("presentation mode " ^
4962 if conf
.presentation
then "on" else "off");
4965 if List.mem
Wsi.Fullscreen state
.winstate
4966 then Wsi.reshape conf
.cwinw conf
.cwinh
4967 else Wsi.fullscreen
()
4969 | Ascii
('
p'
|'N'
) ->
4970 search state
.searchpattern
false
4972 | Ascii '
n'
| Fn
3 ->
4973 search state
.searchpattern
true
4976 begin match state
.layout with
4979 gotoghyll (getpagey
l.pageno)
4985 | Delete
| KPdelete
->
4989 showtext ' '
(describe_location ());
4992 begin match state
.layout with
4995 Wsi.reshape l.pagew
l.pageh
;
5000 enterbookmarkmode
()
5002 | Ascii '
h'
| Fn
1 ->
5008 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
5013 match state
.layout with
5018 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
5021 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
5025 showtext ' '
"Quick bookmark added";
5028 begin match state
.layout with
5030 let rect = getpdimrect
l.pagedimno
in
5034 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5035 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5037 (truncate
(rect.(1) -. rect.(0)),
5038 truncate
(rect.(3) -. rect.(0)))
5040 let w = truncate
((float w)*.conf
.zoom)
5041 and h = truncate
((float h)*.conf
.zoom) in
5044 state
.anchor <- getanchor
();
5045 Wsi.reshape w (h + conf
.interpagespace
)
5047 G.postRedisplay "z";
5052 | Ascii '
x'
-> state
.roam
()
5054 | Ascii
('
<'
|'
>'
as c) ->
5056 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5058 | Ascii
('
['
|'
]'
as c) ->
5060 bound
(conf
.colorscale
+. (if c = '
>'
then 0.1 else -0.1)) 0.0 1.0;
5061 G.postRedisplay "brightness";
5063 | Ascii '
c'
when state
.mode = View
->
5068 let m = (state
.winw
- state
.w) / 2 in
5069 gotoxy_and_clear_text m state
.y
5073 match state
.prevcolumns
with
5074 | None
-> (1, 0, 0), 1.0
5075 | Some
(columns
, z
) ->
5078 | Csplit
(c, _) -> -c, 0, 0
5079 | Cmulti
((c, a, b), _) -> c, a, b
5080 | Csingle
_ -> 1, 0, 0
5084 setcolumns View
c a b;
5087 | Down
| Up
when ctrl && Wsi.withshift mask
->
5088 let zoom, x = state
.prevzoom
in
5092 | Ascii 'k'
| Up
| KPup
->
5093 begin match state
.autoscroll
with
5095 begin match state
.mode with
5096 | Birdseye beye
-> upbirdseye 1 beye
5101 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5103 if not
(Wsi.withshift mask
) && conf
.presentation
5105 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5109 setautoscrollspeed n false
5112 | Ascii 'j'
| Down
| KPdown
->
5113 begin match state
.autoscroll
with
5115 begin match state
.mode with
5116 | Birdseye beye
-> downbirdseye 1 beye
5121 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5123 if not
(Wsi.withshift mask
) && conf
.presentation
5125 else gotoghyll1 true (clamp (conf
.scrollstep
))
5129 setautoscrollspeed n true
5132 | Left
| Right
| KPleft
| KPright
when not
(Wsi.withalt mask
) ->
5138 else conf
.hscrollstep
5141 let pv = Wsi.kc2pv
key in
5142 if pv = Keys.Left
|| pv = Keys.KPleft
then dx else -dx
5144 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5147 G.postRedisplay "left/right"
5150 | Prior
| KPprior
->
5154 match state
.layout with
5156 | l :: _ -> state
.y - l.pagey
5158 clamp (pgscale (-state
.winh
))
5166 match List.rev state
.layout with
5168 | l :: _ -> getpagey
l.pageno
5170 clamp (pgscale state
.winh
)
5174 | Ascii '
g'
| Home
| KPhome
->
5177 | Ascii 'G'
| End
| KPend
->
5179 gotoghyll (clamp state
.maxy)
5181 | Right
| KPright
when Wsi.withalt mask
->
5182 gotoghyll (getnav 1)
5183 | Left
| KPleft
when Wsi.withalt mask
->
5184 gotoghyll (getnav ~
-1)
5189 | Ascii '
v'
when conf
.debug
->
5192 match getopaque l.pageno with
5195 let x0, y0, x1, y1 = pagebbox
opaque in
5196 let rect = (float x0, float y0,
5199 float x0, float y1) in
5201 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5202 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5204 G.postRedisplay "v";
5207 let mode = state
.mode in
5208 let cmd = ref E.s in
5209 let onleave = function
5210 | Cancel
-> state
.mode <- mode
5213 match getopaque l.pageno with
5214 | Some
opaque -> pipesel opaque !cmd
5215 | None
-> ()) state
.layout;
5219 cbput state
.hists
.sel
s;
5223 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
5225 G.postRedisplay "|";
5226 state
.mode <- Textentry
(te, onleave);
5228 | (Ascii
_|Fn
_|Enter
|KPenter
|KPleft
|KPright
|Left
|Right
|Code
_) ->
5229 vlog "huh? %s" (Wsi.keyname
key)
5232 let linknavkeyboard key mask
linknav =
5233 let pv = Wsi.kc2pv
key in
5234 let getpage pageno =
5235 let rec loop = function
5237 | l :: _ when l.pageno = pageno -> Some
l
5238 | _ :: rest
-> loop rest
5239 in loop state
.layout
5241 let doexact (pageno, n) =
5242 match getopaque pageno, getpage pageno with
5243 | Some
opaque, Some
l ->
5244 if pv = Keys.Enter
|| pv = Keys.KPenter
5246 let under = getlink
opaque n in
5247 G.postRedisplay "link gotounder";
5255 Some
(findlink
opaque LDfirst
), -1
5258 Some
(findlink
opaque LDlast
), 1
5261 Some
(findlink
opaque (LDleft
n)), -1
5264 Some
(findlink
opaque (LDright
n)), 1
5267 Some
(findlink
opaque (LDup
n)), -1
5270 Some
(findlink
opaque (LDdown
n)), 1
5272 | (Delete
|Escape
|Insert
|Enter
|KPdelete
|KPdown
|KPend
|KPenter
5273 |KPhome
|KPleft
|KPminus
|KPnext
|KPplus
|KPprior
|KPright
|KPup
5274 |Next
|Prior
|Ascii
_|Code
_|Fn
_|Backspace
) -> None
, 0
5277 begin match findpwl
l.pageno dir with
5281 state
.mode <- LinkNav
(Ltgendir
dir);
5282 let y, h = getpageyh
pageno in
5285 then y + h - state
.winh
5290 begin match getopaque pageno, getpage pageno with
5291 | Some
opaque, Some
_ ->
5293 let ld = if dir > 0 then LDfirst
else LDlast
in
5296 begin match link with
5298 showlinktype (getlink
opaque m);
5299 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5300 G.postRedisplay "linknav jpage";
5301 | Lnotfound
-> notfound dir
5307 begin match opt with
5308 | Some Lnotfound
-> pwl l dir;
5309 | Some
(Lfound
m) ->
5313 let _, y0, _, y1 = getlinkrect
opaque m in
5315 then gotopage1 l.pageno y0
5317 let d = fstate
.fontsize
+ 1 in
5318 if y1 - l.pagey > l.pagevh - d
5319 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5320 else G.postRedisplay "linknav";
5322 showlinktype (getlink
opaque m);
5323 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5326 | None
-> viewkeyboard key mask
5328 | _ -> viewkeyboard key mask
5332 begin match linknav with
5333 | Ltexact pa
-> state
.lnava
<- Some pa
5334 | Ltgendir
_ | Ltnotready
_ -> ()
5337 G.postRedisplay "leave linknav"
5341 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5342 | Ltexact exact
-> doexact exact
5345 let keyboard key mask
=
5346 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5347 then wcmd "interrupt"
5348 else state
.uioh <- state
.uioh#
key key mask
5351 let birdseyekeyboard key mask
5352 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5354 match conf
.columns
with
5356 | Cmulti
((c, _, _), _) -> c
5357 | Csplit
_ -> failwith
"bird's eye split mode"
5359 let pgh layout = List.fold_left
5360 (fun m l -> max
l.pageh
m) state
.winh
layout in
5362 match Wsi.kc2pv
key with
5363 | Ascii '
l'
when Wsi.withctrl mask
->
5364 let y, h = getpageyh
pageno in
5365 let top = (state
.winh
- h) / 2 in
5366 gotoxy state
.x (max
0 (y - top))
5367 | Enter
| KPenter
-> leavebirdseye beye
false
5368 | Escape
-> leavebirdseye beye
true
5369 | Up
-> upbirdseye incr beye
5370 | Down
-> downbirdseye incr beye
5371 | Left
-> upbirdseye 1 beye
5372 | Right
-> downbirdseye 1 beye
5375 begin match state
.layout with
5379 state
.mode <- Birdseye
(
5380 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5382 gotopage1 l.pageno 0;
5385 let layout = layout state
.x (state
.y-state
.winh
)
5387 (pgh state
.layout) in
5389 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5391 state
.mode <- Birdseye
(
5392 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5394 gotopage1 l.pageno 0
5397 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5401 begin match List.rev state
.layout with
5403 let layout = layout state
.x
5404 (state
.y + (pgh state
.layout))
5405 state
.winw state
.winh
in
5406 begin match layout with
5408 let incr = l.pageh
- l.pagevh in
5413 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5415 G.postRedisplay "birdseye pagedown";
5417 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5421 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5422 gotopage1 l.pageno 0;
5425 | [] -> gotoxy state
.x (clamp state
.winh
)
5429 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5433 let pageno = state
.pagecount
- 1 in
5434 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5435 if not
(pagevisible state
.layout pageno)
5438 match List.rev state
.pdims
with
5440 | (_, _, h, _) :: _ -> h
5444 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5445 else G.postRedisplay "birdseye end";
5447 | (Delete
|Insert
|KPdelete
|KPdown
|KPend
|KPhome
|KPleft
5448 |KPminus
|KPnext
|KPplus
|KPprior
|KPright
|KPup
|Ascii
_
5449 |Code
_|Fn
_|Backspace
) -> viewkeyboard key mask
5454 match state
.mode with
5455 | Textentry
_ -> scalecolor 0.4
5457 | View
-> scalecolor 1.0
5458 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5459 if l.pageno = hooverpageno
5462 if l.pageno = pageno
5464 let c = scalecolor 1.0 in
5466 GlDraw.line_width
3.0;
5467 let dispx = l.pagedispx in
5469 (float (dispx-1)) (float (l.pagedispy-1))
5470 (float (dispx+l.pagevw+1))
5471 (float (l.pagedispy+l.pagevh+1))
5473 GlDraw.line_width
1.0;
5482 let postdrawpage l linkindexbase
=
5483 match getopaque l.pageno with
5485 if tileready l l.pagex
l.pagey
5487 let x = l.pagedispx - l.pagex
5488 and y = l.pagedispy - l.pagey in
5490 match conf
.columns
with
5491 | Csingle
_ | Cmulti
_ ->
5492 (if conf
.hlinks
then 1 else 0)
5494 && not
(isbirdseye state
.mode) then 2 else 0)
5498 match state
.mode with
5499 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5505 Hashtbl.find_all state
.prects
l.pageno |>
5506 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5507 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5509 then (state
.redisplay
<- true; 0)
5515 let scrollindicator () =
5516 let sbw, ph
, sh = state
.uioh#
scrollph in
5517 let sbh, pw, sw = state
.uioh#scrollpw
in
5522 else ((state
.winw
- sbw), state
.winw
, 0)
5526 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5527 GlDraw.color (0.64, 0.64, 0.64) ~
alpha:0.7;
5528 filledrect (float x0) 0. (float x1) (float state
.winh
);
5530 (float hx0
) (float (state
.winh
- sbh))
5531 (float (hx0
+ state
.winw
)) (float state
.winh
)
5533 GlDraw.color (0.0, 0.0, 0.0) ~
alpha:0.7;
5535 filledrect (float x0) ph
(float x1) (ph
+. sh);
5536 let pw = pw +. float hx0
in
5537 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5542 match state
.mstate
with
5543 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5546 | Msel
((x0, y0), (x1, y1)) ->
5547 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5548 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5549 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5550 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5557 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5558 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5560 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5562 if l.pageno = pageno
5564 let dx = float (l.pagedispx - l.pagex
) in
5565 let dy = float (l.pagedispy - l.pagey) in
5566 let r, g, b, alpha = c in
5567 GlDraw.color (r, g, b) ~
alpha;
5568 filledrect2 (x0+.dx) (y0+.dy)
5580 begin match conf
.columns
, state
.layout with
5581 | Csingle
_, _ :: _ ->
5582 GlDraw.color (scalecolor2 conf
.bgcolor
);
5584 List.fold_left
(fun y l ->
5587 let x1 = l.pagedispx in
5588 let y1 = (l.pagedispy + l.pagevh) in
5589 filledrect (float x0) (float y0) (float x1) (float y1);
5590 let x0 = x1 + l.pagevw in
5591 let x1 = state
.winw
in
5592 filledrect1 (float x0) (float y0) (float x1) (float y1);
5596 and x1 = state
.winw
in
5598 and y1 = l.pagedispy in
5599 filledrect1 (float x0) (float y0) (float x1) (float y1);
5601 l.pagedispy + l.pagevh) 0 state
.layout
5604 and x1 = state
.winw
in
5606 and y1 = state
.winh
in
5607 filledrect1 (float x0) (float y0) (float x1) (float y1)
5608 | (Cmulti
_ | Csplit
_), _ | Csingle
_, [] ->
5609 GlClear.color (scalecolor2 conf
.bgcolor
);
5610 GlClear.clear
[`
color];
5612 List.iter
drawpage state
.layout;
5614 match state
.mode with
5615 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5616 begin match getopaque pageno with
5618 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5619 let color = (0.0, 0.0, 0.5, 0.5) in
5626 | None
-> state
.rects
5628 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5631 | View
-> state
.rects
5634 let rec postloop linkindexbase
= function
5636 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5637 postloop linkindexbase rest
5641 postloop 0 state
.layout;
5643 begin match state
.mstate
with
5644 | Mzoomrect
((x0, y0), (x1, y1)) ->
5646 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5647 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5648 filledrect (float x0) (float y0) (float x1) (float y1);
5652 | Mscrolly
| Mscrollx
5661 let zoomrect x y x1 y1 =
5664 and y0 = min
y y1 in
5665 let zoom = (float state
.w) /. float (x1 - x0) in
5668 if state
.w < state
.winw
5669 then (state
.winw
- state
.w) / 2
5672 match conf
.fitmodel
with
5673 | FitWidth
| FitProportional
-> simple ()
5675 match conf
.columns
with
5677 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5678 | Cmulti
_ | Csingle
_ -> simple ()
5680 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5681 state
.anchor <- getanchor
();
5686 let annot inline
x y =
5687 match unproject x y with
5688 | Some
(opaque, n, ux
, uy
) ->
5690 addannot
opaque ux uy
text;
5691 wcmd "freepage %s" (~
> opaque);
5692 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5694 gotoxy state
.x state
.y
5698 let ondone s = add s in
5699 let mode = state
.mode in
5700 state
.mode <- Textentry
(
5701 ("annotation: ", E.s, None
, textentry, ondone, true),
5702 fun _ -> state
.mode <- mode);
5705 G.postRedisplay "annot"
5707 add @@ getusertext E.s
5712 let g opaque l px py =
5713 match rectofblock
opaque px py with
5715 let x0 = a.(0) -. 20. in
5716 let x1 = a.(1) +. 20. in
5717 let y0 = a.(2) -. 20. in
5718 let zoom = (float state
.w) /. (x1 -. x0) in
5719 let pagey = getpagey
l.pageno in
5720 let margin = (state
.w - l.pagew
)/2 in
5721 let nx = -truncate
x0 - margin in
5722 gotoxy_and_clear_text nx (pagey + truncate
y0);
5723 state
.anchor <- getanchor
();
5728 match conf
.columns
with
5730 impmsg "block zooming does not work properly in split columns mode"
5731 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5735 let winw = state
.winw - 1 in
5736 let s = float x /. float winw in
5737 let destx = truncate
(float (state
.w + winw) *. s) in
5738 gotoxy_and_clear_text (winw - destx) state
.y;
5739 state
.mstate
<- Mscrollx
;
5743 let s = float y /. float state
.winh
in
5744 let desty = truncate
(float (state
.maxy -
5745 (if conf
.maxhfit
then state
.winh
else 0))
5747 gotoxy_and_clear_text state
.x desty;
5748 state
.mstate
<- Mscrolly
;
5751 let viewmulticlick clicks
x y mask
=
5752 let g opaque l px py =
5760 if markunder
opaque px py mark
5764 match getopaque l.pageno with
5766 | Some
opaque -> pipesel opaque cmd
5768 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5769 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5774 G.postRedisplay "viewmulticlick";
5775 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5779 match conf
.columns
with
5781 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5784 let viewmouse button down
x y mask
=
5786 | n when (n == 4 || n == 5) && not down
->
5787 if Wsi.withctrl mask
5789 match state
.mstate
with
5790 | Mzoom
(oldn
, i
, (ftx
, fty
)) ->
5793 then abs
(ftx
- x) > 5 || abs
(fty
- y) > 5
5803 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5805 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5807 let zoom = conf
.zoom -. incr in
5809 then pivotzoom ~
x ~
y zoom
5810 else pivotzoom zoom;
5811 state
.mstate
<- Mzoom
(n, 0, (x, y));
5813 state
.mstate
<- Mzoom
(n, i
+1, (ftx
, fty
));
5815 else state
.mstate
<- Mzoom
(n, 0, (ftx
, fty
))
5819 | Mscrolly
| Mscrollx
5821 | Mnone
-> state
.mstate
<- Mzoom
(n, 0, (0, 0))
5824 match state
.autoscroll
with
5825 | Some step
-> setautoscrollspeed step
(n=4)
5827 if conf
.wheelbypage
|| conf
.presentation
5836 then -conf
.scrollstep
5837 else conf
.scrollstep
5839 let incr = incr * 2 in
5840 let y = clamp incr in
5841 gotoxy_and_clear_text state
.x y
5844 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5846 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5847 gotoxy_and_clear_text x state
.y
5849 | 1 when Wsi.withshift mask
->
5850 state
.mstate
<- Mnone
;
5853 match unproject x y with
5855 | Some
(_, pageno, ux
, uy
) ->
5856 let cmd = Printf.sprintf
5858 conf
.stcmd state
.path pageno ux uy
5860 match spawn
cmd [] with
5861 | (exception exn
) ->
5862 impmsg "execution of synctex command(%S) failed: %S"
5863 conf
.stcmd
@@ exntos exn
5867 | 1 when Wsi.withctrl mask
->
5870 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5871 state
.mstate
<- Mpan
(x, y)
5874 state
.mstate
<- Mnone
5879 if Wsi.withshift mask
5881 annot conf
.annotinline
x y;
5882 G.postRedisplay "addannot"
5886 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5887 state
.mstate
<- Mzoomrect
(p, p)
5890 match state
.mstate
with
5891 | Mzoomrect
((x0, y0), _) ->
5892 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5893 then zoomrect x0 y0 x y
5896 G.postRedisplay "kill accidental zoom rect";
5900 | Mscrolly
| Mscrollx
5906 | 1 when vscrollhit x ->
5909 let _, position, sh = state
.uioh#
scrollph in
5910 if y > truncate
position && y < truncate
(position +. sh)
5911 then state
.mstate
<- Mscrolly
5914 state
.mstate
<- Mnone
5916 | 1 when y > state
.winh
- hscrollh () ->
5919 let _, position, sw = state
.uioh#scrollpw
in
5920 if x > truncate
position && x < truncate
(position +. sw)
5921 then state
.mstate
<- Mscrollx
5924 state
.mstate
<- Mnone
5926 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5929 let dest = if down
then getunder x y else Unone
in
5930 begin match dest with
5934 | Unone
when down
->
5935 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5936 state
.mstate
<- Mpan
(x, y);
5938 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5940 | Unone
| Utext
_ ->
5945 state
.mstate
<- Msel
((x, y), (x, y));
5946 G.postRedisplay "mouse select";
5950 match state
.mstate
with
5953 | Mzoom
_ | Mscrollx
| Mscrolly
->
5954 state
.mstate
<- Mnone
5956 | Mzoomrect
((x0, y0), _) ->
5960 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5961 state
.mstate
<- Mnone
5963 | Msel
((x0, y0), (x1, y1)) ->
5964 let rec loop = function
5968 let a0 = l.pagedispy in
5969 let a1 = a0 + l.pagevh in
5970 let b0 = l.pagedispx in
5971 let b1 = b0 + l.pagevw in
5972 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5973 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5977 match getopaque l.pageno with
5980 match Unix.pipe
() with
5981 | (exception exn
) ->
5982 impmsg "cannot create sel pipe: %s" @@
5986 Ne.clo fd
(fun msg
->
5987 dolog
"%s close failed: %s" what msg
)
5990 try spawn
cmd [r, 0; w, -1]
5992 dolog
"cannot execute %S: %s"
5999 G.postRedisplay "copysel";
6001 else clo "Msel pipe/w" w;
6002 clo "Msel pipe/r" r;
6004 dosel conf
.selcmd
();
6005 state
.roam
<- dosel conf
.paxcmd
;
6017 let birdseyemouse button down
x y mask
6018 (conf
, leftx
, _, hooverpageno
, anchor) =
6021 let rec loop = function
6024 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6025 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6027 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
6033 | _ -> viewmouse button down
x y mask
6039 method key key mask
=
6040 begin match state
.mode with
6041 | Textentry
textentry -> textentrykeyboard key mask
textentry
6042 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6043 | View
-> viewkeyboard key mask
6044 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6048 method button button bstate
x y mask
=
6049 begin match state
.mode with
6051 | View
-> viewmouse button bstate
x y mask
6052 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6057 method multiclick clicks
x y mask
=
6058 begin match state
.mode with
6060 | View
-> viewmulticlick clicks
x y mask
6067 begin match state
.mode with
6069 | View
| Birdseye
_ | LinkNav
_ ->
6070 match state
.mstate
with
6071 | Mzoom
_ | Mnone
-> ()
6076 state
.mstate
<- Mpan
(x, y);
6077 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6079 gotoxy_and_clear_text x y
6082 state
.mstate
<- Msel
(a, (x, y));
6083 G.postRedisplay "motion select";
6086 let y = min state
.winh
(max
0 y) in
6090 let x = min state
.winw (max
0 x) in
6093 | Mzoomrect
(p0
, _) ->
6094 state
.mstate
<- Mzoomrect
(p0
, (x, y));
6095 G.postRedisplay "motion zoomrect";
6099 method pmotion
x y =
6100 begin match state
.mode with
6101 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6102 let rec loop = function
6104 if hooverpageno
!= -1
6106 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6107 G.postRedisplay "pmotion birdseye no hoover";
6110 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6111 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6113 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6114 G.postRedisplay "pmotion birdseye hoover";
6124 match state
.mstate
with
6125 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6133 let past, _, _ = !r in
6135 let delta = now -. past in
6138 else r := (now, x, y)
6142 method infochanged
_ = ()
6145 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
6148 then 0.0, float state
.winh
6149 else scrollph state
.y maxy
6154 let fwinw = float (state
.winw - vscrollw ()) in
6156 let sw = fwinw /. float state
.w in
6157 let sw = fwinw *. sw in
6158 max
sw (float conf
.scrollh
)
6161 let maxx = state
.w + state
.winw in
6162 let x = state
.winw - state
.x in
6163 let percent = float x /. float maxx in
6164 (fwinw -. sw) *. percent
6166 hscrollh (), position, sw
6170 match state
.mode with
6171 | LinkNav
_ -> "links"
6172 | Textentry
_ -> "textentry"
6173 | Birdseye
_ -> "birdseye"
6176 findkeyhash conf
modename
6178 method eformsgs
= true
6179 method alwaysscrolly
= false
6182 let addrect pageno r g b a x0 y0 x1 y1 =
6183 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6187 let cl = splitatchar cmds ' '
in
6189 try Scanf.sscanf
s fmt
f
6191 adderrfmt "remote exec"
6192 "error processing '%S': %s\n" cmds
@@ exntos exn
6194 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6195 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6196 s pageno r g b a x0 y0 x1 y1;
6200 let _,w1,h1
,_ = getpagedim
pageno in
6201 let sw = float w1 /. float w
6202 and sh = float h1
/. float h in
6206 and y1s
= y1 *. sh in
6207 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6208 let color = (r, g, b, a) in
6209 if conf
.verbose
then debugrect rect;
6210 state
.rects <- (pageno, color, rect) :: state
.rects;
6215 | "reload", "" -> reload ()
6217 scan args
"%u %f %f"
6219 let cmd, _ = state
.geomcmds
in
6221 then gotopagexy !wtmode pageno x y
6224 gotopagexy !wtmode pageno x y;
6227 state
.reprf
<- f state
.reprf
6229 | "goto1", args
-> scan args
"%u %f" gotopage
6232 (fun _filename _pageno
->
6233 failwith
"gotounder (Uremote (filename, pageno))")
6236 (fun _filename _dest
->
6237 failwith
"gotounder (Uremotedest (filename, dest))")
6239 scan args
"%u %u %f %f %f %f"
6240 (fun pageno c x0 y0 x1 y1 ->
6241 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6242 rectx "rect" pageno color x0 y0 x1 y1;
6245 scan args
"%u %f %f %f %f %f %f %f %f"
6246 (fun pageno r g b alpha x0 y0 x1 y1 ->
6247 addrect pageno r g b alpha x0 y0 x1 y1;
6248 G.postRedisplay "prect"
6251 scan args
"%u %f %f"
6254 match getopaque pageno with
6255 | Some
opaque -> opaque
6258 pgoto optopaque pageno x y;
6259 let rec fixx = function
6262 if l.pageno = pageno
6263 then gotoxy (state
.x - l.pagedispx) state
.y
6268 match conf
.columns
with
6269 | Csingle
_ | Csplit
_ -> 1
6270 | Cmulti
((n, _, _), _) -> n
6272 layout 0 state
.y (state
.winw * mult) state
.winh
6276 | "activatewin", "" -> Wsi.activatewin
()
6277 | "quit", "" -> raise Quit
6280 let l = Config.keys_of_string
keys in
6281 List.iter
(fun (k
, m) -> keyboard k
m) l
6283 adderrfmt "error processing keys" "`%S': %s\n" cmds
@@ exntos exn
6285 | "clearrects", "" ->
6286 Hashtbl.clear state
.prects
;
6287 G.postRedisplay "clearrects"
6289 adderrfmt "remote command"
6290 "error processing remote command: %S\n" cmds
;
6294 let scratch = Bytes.create
80 in
6295 let buf = Buffer.create
80 in
6297 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6298 | (exception Unix.Unix_error
(Unix.EAGAIN
, _, _)) -> None
6301 if Buffer.length
buf > 0
6303 let s = Buffer.contents
buf in
6311 match Bytes.index_from
scratch ppos '
\n'
with
6312 | pos
-> if pos
>= n then -1 else pos
6313 | (exception Not_found
) -> -1
6317 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6318 let s = Buffer.contents
buf in
6324 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6330 let remoteopen path =
6331 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6333 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6338 let gcconfig = ref E.s in
6339 let trimcachepath = ref E.s in
6340 let rcmdpath = ref E.s in
6341 let pageno = ref None
in
6342 let rootwid = ref 0 in
6343 let openlast = ref false in
6344 let nofc = ref false in
6345 let doreap = ref false in
6346 let csspath = ref None
in
6347 selfexec := Sys.executable_name
;
6350 [("-p", Arg.String
(fun s -> state
.password <- s),
6351 "<password> Set password");
6355 Config.fontpath
:= s;
6356 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6358 "<path> Set path to the user interface font");
6362 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6363 Config.confpath
:= s),
6364 "<path> Set path to the configuration file");
6366 ("-last", Arg.Set
openlast, " Open last document");
6368 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6369 "<page-number> Jump to page");
6371 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6372 "<path> Set path to the trim cache file");
6374 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6375 "<named-destination> Set named destination");
6377 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6378 ("-cxack", Arg.Set
cxack, " Cut corners");
6380 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6381 "<path> Set path to the source of remote commands");
6383 ("-gc", Arg.Set_string
gcconfig,
6384 "<path> Collect garbage with the help of a script");
6386 ("-nofc", Arg.Set
nofc, " Do not use fontconfig");
6388 ("-v", Arg.Unit
(fun () ->
6390 "%s\nconfiguration path: %s\n"
6393 exit
0), " Print version and exit");
6395 ("-css", Arg.String
(fun s -> csspath := Some
s),
6396 "<path> Set path to the style sheet to use with EPUB/HTML");
6398 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6400 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6401 "<origin> <undocumented>");
6404 (fun s -> state
.path <- s)
6405 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6408 then selfexec := !selfexec ^
" -wtmode";
6410 let histmode = emptystr state
.path && not
!openlast in
6412 if not
(Config.load !openlast)
6413 then dolog
"failed to load configuration";
6415 begin match !pageno with
6416 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6420 if nonemptystr
!gcconfig
6423 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6424 | (exception exn
) -> error
"socketpair for gc failed: %s" @@ exntos exn
6427 match spawn
!gcconfig [(c, 0); (c, 1); (s, -1)] with
6428 | (exception exn
) -> error
"failed to execute gc script: %s" @@ exntos exn
6430 Ne.clo c @@ (fun s -> error
"failed to close gc fd %s" s);
6437 val mutable m_clicks
= 0
6438 val mutable m_click_x
= 0
6439 val mutable m_click_y
= 0
6440 val mutable m_lastclicktime
= infinity
6442 method private cleanup =
6443 state
.roam
<- noroam
;
6444 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6445 method expose
= G.postRedisplay "expose"
6449 | Wsi.Unobscured
-> "unobscured"
6450 | Wsi.PartiallyObscured
-> "partiallyobscured"
6451 | Wsi.FullyObscured
-> "fullyobscured"
6453 vlog "visibility change %s" name
6454 method display = display ()
6455 method map mapped
= vlog "mapped %b" mapped
6456 method reshape w h =
6459 method mouse
b d x y m =
6460 if d && canselect ()
6463 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6470 if abs
x - m_click_x
> 10
6471 || abs
y - m_click_y
> 10
6472 || abs_float
(t -. m_lastclicktime
) > 0.3
6474 m_clicks
<- m_clicks
+ 1;
6475 m_lastclicktime
<- t;
6479 G.postRedisplay "cleanup";
6480 state
.uioh <- state
.uioh#button
b d x y m;
6482 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6487 m_lastclicktime
<- infinity
;
6488 state
.uioh <- state
.uioh#button
b d x y m
6492 state
.uioh <- state
.uioh#button
b d x y m
6495 state
.mpos
<- (x, y);
6496 state
.uioh <- state
.uioh#motion
x y
6497 method pmotion
x y =
6498 state
.mpos
<- (x, y);
6499 state
.uioh <- state
.uioh#pmotion
x y
6501 let mascm = m land (
6502 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6505 let x = state
.x and y = state
.y in
6507 if x != state
.x || y != state
.y then self#
cleanup
6509 match state
.keystate
with
6511 let km = k
, mascm in
6514 let modehash = state
.uioh#
modehash in
6515 try Hashtbl.find modehash km
6517 try Hashtbl.find (findkeyhash conf
"global") km
6518 with Not_found
-> KMinsrt
(k
, m)
6520 | KMinsrt
(k
, m) -> keyboard k
m
6521 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6522 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6524 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6525 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6526 state
.keystate
<- KSnone
6527 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6528 state
.keystate
<- KSinto
(keys, insrt
)
6529 | KSinto
_ -> state
.keystate
<- KSnone
6532 state
.mpos
<- (x, y);
6533 state
.uioh <- state
.uioh#pmotion
x y
6534 method leave = state
.mpos
<- (-1, -1)
6535 method winstate wsl
= state
.winstate
<- wsl
6536 method quit
= raise Quit
6539 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6541 setbgcol conf
.bgcolor
;
6544 if not
@@ List.exists
GlMisc.check_extension
6545 [ "GL_ARB_texture_rectangle"
6546 ; "GL_EXT_texture_recangle"
6547 ; "GL_NV_texture_rectangle" ]
6548 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6550 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6552 defconf
.sliceheight
<- 1024;
6553 defconf
.texcount
<- 32;
6554 defconf
.usepbo
<- true;
6558 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6559 | (exception exn
) ->
6560 dolog
"socketpair failed: %s" @@ exntos exn
;
6568 setcheckers conf
.checkers
;
6570 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6572 begin match !csspath with
6574 | Some
"" -> conf
.css
<- E.s
6576 let css = filecontents
path in
6577 let l = String.length
css in
6579 if substratis
css (l-2) "\r\n"
6580 then String.sub css 0 (l-2)
6581 else (if css.[l-1] = '
\n'
6582 then String.sub css 0 (l-1)
6586 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6587 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6588 !Config.fontpath
, !trimcachepath, !opengl_has_pbo, not
!nofc
6590 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6592 reshape ~firsttime
:true winw winh
;
6596 Wsi.settitle
"llpp (history)";
6600 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6601 opendoc state
.path state
.password;
6605 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6606 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6609 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6610 | (exception (Unix.Unix_error
(Unix.ECHILD
, _, _))) -> ()
6611 | (exception exn
) -> dolog
"Unix.waitpid: %s" @@ exntos exn
6613 | _pid
, _status
-> reap ()
6615 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6619 if nonemptystr
!rcmdpath
6620 then remoteopen !rcmdpath
6625 let rec loop deadline
=
6631 let r = [state
.ss; state
.wsfd] in
6635 | Some fd
-> fd
:: r
6639 state
.redisplay
<- false;
6646 if deadline
= infinity
6648 else max
0.0 (deadline
-. now)
6653 try Unix.select
r [] [] timeout
6654 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6660 if state
.ghyll
== noghyll
6662 match state
.autoscroll
with
6663 | Some step
when step
!= 0 ->
6664 let y = state
.y + step
in
6665 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6668 then state
.maxy - fy
6669 else if y >= state
.maxy - fy then 0 else y
6671 if state
.mode = View
6672 then gotoxy_and_clear_text state
.x y
6673 else gotoxy state
.x y;
6676 else deadline
+. 0.01
6681 let rec checkfds = function
6683 | fd
:: rest
when fd
= state
.ss ->
6684 let cmd = rcmd state
.ss in
6688 | fd
:: rest
when fd
= state
.wsfd ->
6692 | fd
:: rest
when Some fd
= !optrfd ->
6693 begin match remote fd
with
6694 | None
-> optrfd := remoteopen !rcmdpath;
6695 | opt -> optrfd := opt
6700 dolog
"select returned unknown descriptor";
6706 if deadline
= infinity
6710 match state
.autoscroll
with
6711 | Some step
when step
!= 0 -> deadline1
6712 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6717 match loop infinity
with
6719 Config.save leavebirdseye;
6720 if hasunsavedchanges
()
6722 | _ -> error
"umpossible - infinity reached"