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 getpdimrect
: int -> float array
= "ml_getpdimrect";;
10 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
11 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
12 external clearmark
: opaque
-> unit = "ml_clearmark";;
13 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
14 external getmaxw
: unit -> float = "ml_getmaxw";;
15 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
16 external measurestr
: int -> string -> float = "ml_measure_string";;
17 external postprocess
: opaque
-> int -> int -> int -> (int * string * int)
18 -> int = "ml_postprocess";;
19 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
20 external setaalevel
: int -> unit = "ml_setaalevel";;
21 external realloctexts
: int -> bool = "ml_realloctexts";;
22 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
23 external getlink
: opaque
-> int -> under
= "ml_getlink";;
24 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
25 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
26 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
27 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
28 external freepbo
: opaque
-> unit = "ml_freepbo";;
29 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
30 external bousable
: unit -> bool = "ml_bo_usable";;
31 external unproject
: opaque
-> int -> int
32 -> (int * int) option = "ml_unproject";;
33 external project
: opaque
-> int -> int -> float -> float
34 -> (float * float) = "ml_project";;
35 external drawtile
: tileparams
-> opaque
36 -> unit = "ml_drawtile";;
37 external rectofblock
: opaque
-> int -> int
38 -> float array
option = "ml_rectofblock";;
39 external begintiles
: unit -> unit = "ml_begintiles";;
40 external endtiles
: unit -> unit = "ml_endtiles";;
41 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
42 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
43 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
44 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
45 external savedoc
: string -> unit = "ml_savedoc";;
46 external getannotcontents
: opaque
-> slinkindex
47 -> string = "ml_getannotcontents";;
48 external drawprect
: opaque
-> int -> int -> float array
49 -> unit = "ml_drawprect";;
50 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
51 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
52 external uritolocation
: string
53 -> (pageno
* float * float) = "ml_uritolocation";;
54 external isexternallink
: string -> bool = "ml_isexternallink";;
56 (* copysel _will_ close the supplied descriptor *)
57 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
59 let selfexec = ref E.s
;;
60 let ignoredoctitlte = ref false;;
61 let opengl_has_pbo = ref false;;
63 let drawstring size x y s
=
65 Gl.enable `texture_2d
;
66 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
67 ignore
(drawstr size x y s
);
69 Gl.disable `texture_2d
;
72 let drawstring1 size x y s
=
76 let drawstring2 size x y fmt
=
77 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
80 module UniSyms
= struct
81 let ellipsis = "\xe2\x80\xa6";;
82 let radical = "\xe2\x88\x9a";;
83 let lguillemet = "\xc2\xab";;
84 let rguillemet = "\xc2\xbb";;
99 l
.pagedispx l
.pagedispy
103 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
109 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
112 let isbirdseye = function
114 | Textentry _
| View
| LinkNav _
-> false
117 let istextentry = function
118 | Textentry _
-> true
119 | Birdseye _
| View
| LinkNav _
-> false
122 let wtmode = ref false;;
123 let cxack = ref false;;
125 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
128 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
129 && (state
.w
> state
.winw
))
135 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
136 && (state
.maxy
> state
.winh
))
144 else x
> state
.winw
- vscrollw ()
148 fstate
.fontsize
<- n
;
149 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
150 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
156 else Printf.kprintf ignore fmt
160 if emptystr conf
.pathlauncher
161 then dolog
"%s" state
.path
163 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
164 match spawn
command [] with
167 dolog
"failed to execute `%s': %s" command @@ exntos exn
173 let postRedisplay who
=
174 vlog "redisplay for [%S]" who
;
175 state
.redisplay
<- true;
179 let getopaque pageno
=
180 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
181 with Not_found
-> None
184 let pagetranslatepoint l x y
=
185 let dy = y
- l
.pagedispy
in
186 let y = dy + l
.pagey
in
187 let dx = x
- l
.pagedispx
in
188 let x = dx + l
.pagex
in
192 let onppundermouse g
x y d
=
195 begin match getopaque l
.pageno
with
197 let x0 = l
.pagedispx
in
198 let x1 = x0 + l
.pagevw
in
199 let y0 = l
.pagedispy
in
200 let y1 = y0 + l
.pagevh
in
201 if y >= y0 && y <= y1 && x >= x0 && x <= x1
203 let px, py
= pagetranslatepoint l
x y in
204 match g opaque l
px py
with
217 let g opaque l
px py
=
220 match rectofblock opaque
px py
with
221 | Some
[|x0;x1;y0;y1|] ->
222 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
223 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
224 state
.rects
<- [l
.pageno
, color, rect];
225 G.postRedisplay "getunder";
228 let under = whatsunder opaque
px py
in
229 if under = Unone
then None
else Some
under
231 onppundermouse g x y Unone
236 match unproject opaque
x y with
237 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
240 onppundermouse g x y None
;
244 state
.text
<- Printf.sprintf
"%c%s" c s
;
245 G.postRedisplay "showtext";
249 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
252 let pipef ?
(closew
=true) cap
f cmd
=
253 match Unix.pipe
() with
254 | exception exn
-> dolog
"%s cannot create pipe: %S" cap
@@ exntos exn
256 begin match spawn cmd
[r
, 0; w
, -1] with
257 | exception exn
-> dolog
"%s: cannot execute %S: %s" cap cmd
@@ exntos exn
260 Ne.clo r
(dolog
"%s failed to close r: %s" cap
);
261 if closew
then Ne.clo w
(dolog
"%s failed to close w: %s" cap
);
264 let pipesel opaque cmd
=
266 then pipef ~closew
:false "pipesel"
269 G.postRedisplay "pipesel"
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");
297 "selstring" (fun w
->
299 let l = String.length s
in
300 let bytes = Bytes.unsafe_of_string s
in
301 let n = tempfailureretry
(Unix.write w
bytes 0) l in
303 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n;
304 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
308 let undertext = function
311 | Utext s
-> "font: " ^ s
312 | Uannotation
(opaque
, slinkindex
) ->
313 "annotation: " ^ getannotcontents opaque slinkindex
316 let updateunder x y =
317 match getunder x y with
318 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
320 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
321 Wsi.setcursor
Wsi.CURSOR_INFO
323 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
324 Wsi.setcursor
Wsi.CURSOR_TEXT
326 if conf
.underinfo
then showtext 'a'
"nnotation";
327 Wsi.setcursor
Wsi.CURSOR_INFO
330 let showlinktype under =
331 if conf
.underinfo
&& under != Unone
332 then showtext ' '
@@ undertext under
335 let [@warning
"-4"] intentry_with_suffix text key
=
338 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
339 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
340 addchar
text @@ asciilower c
342 state
.text <- Printf.sprintf
"invalid key";
349 let b = Buffer.create
16 in
352 let b = Buffer.to_bytes
b in
353 wcmd state
.ss
b @@ Bytes.length
b
357 let nogeomcmds cmds
=
359 | s
, [] -> emptystr s
363 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
364 let rec fold accu
n =
365 if n = Array.length
b
368 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
371 || n = state
.pagecount
- coverB
372 || (n - coverA
) mod columns
= columns
- 1)
378 let pagey = max
0 (y - vy
) in
379 let pagedispy = if pagey > 0 then 0 else vy
- y in
380 let pagedispx, pagex
=
382 if n = coverA
- 1 || n = state
.pagecount
- coverB
383 then x + (sw
- w
) / 2
391 let vw = sw
- pagedispx in
392 let pw = w
- pagex
in
395 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
396 if pagevw > 0 && pagevh > 0
407 ; pagedispx = pagedispx
408 ; pagedispy = pagedispy
420 if Array.length
b = 0
422 else List.rev
(fold [] (page_of_y
y))
425 let layoutS (columns
, b) x y sw sh
=
426 let rec fold accu n =
427 if n = Array.length
b
430 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
438 let pagey = max
0 (y - vy
) in
439 let pagedispy = if pagey > 0 then 0 else vy
- y in
440 let pagedispx, pagex
=
454 let pagecolw = pagew
/columns
in
457 then pagedispx + ((sw
- pagecolw) / 2)
461 let vw = sw
- pagedispx in
462 let pw = pagew
- pagex
in
465 let pagevw = min
pagevw pagecolw in
466 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
467 if pagevw > 0 && pagevh > 0
478 ; pagedispx = pagedispx
479 ; pagedispy = pagedispy
480 ; pagecol
= n mod columns
494 let layout x y sw sh
=
495 if nogeomcmds state
.geomcmds
497 match conf
.columns
with
498 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
499 | Cmulti c
-> layoutN c
x y sw sh
500 | Csplit s
-> layoutS s
x y sw sh
504 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
506 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
509 let tilex = l.pagex
mod conf
.tilew
in
510 let tiley = l.pagey mod conf
.tileh
in
512 let col = l.pagex
/ conf
.tilew
in
513 let row = l.pagey / conf
.tileh
in
515 let rec rowloop row y0 dispy h
=
519 let dh = conf
.tileh
- y0 in
521 let rec colloop col x0 dispx w
=
525 let dw = conf
.tilew
- x0 in
527 f col row dispx dispy
x0 y0 dw dh;
528 colloop (col+1) 0 (dispx
+dw) (w
-dw)
531 colloop col tilex l.pagedispx l.pagevw;
532 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
535 if l.pagevw > 0 && l.pagevh > 0
536 then rowloop row tiley l.pagedispy l.pagevh;
539 let gettileopaque l col row =
541 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
543 try Some
(Hashtbl.find state
.tilemap
key)
544 with Not_found
-> None
547 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
548 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
549 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
552 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
553 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
554 GlArray.vertex `two state
.vraw
;
555 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
558 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
560 let filledrect x0 y0 x1 y1 =
561 GlArray.disable `texture_coord
;
562 filledrect1 x0 y0 x1 y1;
563 GlArray.enable `texture_coord
;
566 let linerect x0 y0 x1 y1 =
567 GlArray.disable `texture_coord
;
568 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
569 GlArray.vertex `two state
.vraw
;
570 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
571 GlArray.enable `texture_coord
;
574 let drawtiles l color =
577 let f col row x y tilex tiley w h
=
578 match gettileopaque l col row with
579 | Some
(opaque
, _
, t
) ->
580 let params = x, y, w
, h
, tilex, tiley in
582 then GlTex.env
(`mode `blend
);
583 drawtile
params opaque
;
585 then GlTex.env
(`mode `modulate
);
589 let s = Printf.sprintf
593 let w = measurestr fstate
.fontsize
s in
594 GlDraw.color (0.0, 0.0, 0.0);
595 filledrect (float (x-2))
598 (float (y + fstate
.fontsize
+ 2));
600 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
607 let lw = state
.winw
- x in
610 let lh = state
.winh
- y in
614 then GlTex.env
(`mode `blend
);
615 begin match state
.checkerstexid
with
617 Gl.enable `texture_2d
;
618 GlTex.bind_texture ~target
:`texture_2d id
;
622 and y1 = float (y+h
) in
624 let tw = float w /. 16.0
625 and th
= float h
/. 16.0 in
626 let tx0 = float tilex /. 16.0
627 and ty0
= float tiley /. 16.0 in
629 and ty1
= ty0
+. th
in
630 Raw.sets_float state
.vraw ~pos
:0
631 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
632 Raw.sets_float state
.traw ~pos
:0
633 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
634 GlArray.vertex `two state
.vraw
;
635 GlArray.tex_coord `two state
.traw
;
636 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
637 Gl.disable `texture_2d
;
640 GlDraw.color (1.0, 1.0, 1.0);
641 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
644 then GlTex.env
(`mode `modulate
);
645 if w > 128 && h
> fstate
.fontsize
+ 10
647 let c = if conf
.invert
then 1.0 else 0.0 in
648 GlDraw.color (c, c, c);
651 then (col*conf
.tilew
, row*conf
.tileh
)
654 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
663 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
665 let tilevisible1 l x y =
667 and ax1
= l.pagex
+ l.pagevw
669 and ay1
= l.pagey + l.pagevh in
673 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
674 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
676 let rx0 = max
ax0 bx0
677 and ry0
= max ay0 by0
678 and rx1
= min ax1
bx1
679 and ry1
= min ay1 by1
in
681 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
685 let tilevisible layout n x y =
686 let rec findpageinlayout m
= function
687 | l :: rest
when l.pageno
= n ->
688 tilevisible1 l x y || (
689 match conf
.columns
with
690 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
691 | Csplit _
| Csingle _
| Cmulti _
-> false
693 | _
:: rest
-> findpageinlayout 0 rest
696 findpageinlayout 0 layout;
699 let tileready l x y =
700 tilevisible1 l x y &&
701 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
704 let tilepage n p
layout =
705 let rec loop = function
709 let f col row _ _ _ _ _ _
=
710 if state
.currently
= Idle
712 match gettileopaque l col row with
715 let x = col*conf
.tilew
716 and y = row*conf
.tileh
in
718 let w = l.pagew
- x in
722 let h = l.pageh
- y in
727 then getpbo
w h conf
.colorspace
730 wcmd "tile %s %d %d %d %d %s"
731 (~
> p
) x y w h (~
> pbo);
734 l, p
, conf
.colorspace
, conf
.angle
,
735 state
.gen
, col, row, conf
.tilew
, conf
.tileh
744 if nogeomcmds state
.geomcmds
748 let preloadlayout x y sw sh
=
749 let y = if y < sh
then 0 else y - sh
in
750 let x = min
0 (x + sw
) in
758 if state
.currently
!= Idle
763 begin match getopaque l.pageno
with
765 wcmd "page %d %d" l.pageno
l.pagedimno
;
766 state
.currently
<- Loading
(l, state
.gen
);
768 tilepage l.pageno opaque pages
;
773 if nogeomcmds state
.geomcmds
779 if conf
.preload && state
.currently
= Idle
780 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
783 let layoutready layout =
784 let rec fold all ls
=
787 let seen = ref false in
788 let allvisible = ref true in
789 let foo col row _ _ _ _ _ _
=
791 allvisible := !allvisible &&
792 begin match gettileopaque l col row with
798 fold (!seen && !allvisible) rest
801 let alltilesvisible = fold true layout in
806 let y = bound
y 0 state
.maxy in
807 let y, layout, proceed
=
808 match conf
.maxwait
with
809 | Some time
when state
.ghyll
== noghyll
->
810 begin match state
.throttle
with
812 let layout = layout x y state
.winw state
.winh
in
813 let ready = layoutready layout in
817 state
.throttle
<- Some
(layout, y, now
());
819 else G.postRedisplay "gotoxy showall (None)";
821 | Some
(_
, _
, started
) ->
822 let dt = now
() -. started
in
825 state
.throttle
<- None
;
826 let layout = layout x y state
.winw state
.winh
in
828 G.postRedisplay "maxwait";
835 let layout = layout x y state
.winw state
.winh
in
836 if not
!wtmode || layoutready layout
837 then G.postRedisplay "gotoxy ready";
844 state
.layout <- layout;
845 begin match state
.mode
with
848 | Ltexact
(pageno
, linkno
) ->
849 let rec loop = function
851 state
.lnava
<- Some
(pageno
, linkno
);
852 state
.mode
<- LinkNav
(Ltgendir
0)
853 | l :: _
when l.pageno
= pageno
->
854 begin match getopaque pageno
with
855 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
857 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
858 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
859 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
860 then state
.mode
<- LinkNav
(Ltgendir
0)
862 | _
:: rest
-> loop rest
865 | Ltnotready _
| Ltgendir _
-> ()
867 | Birdseye _
| Textentry _
| View
-> ()
869 begin match state
.mode
with
870 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
871 if not
(pagevisible layout pageno
)
873 match state
.layout with
876 state
.mode
<- Birdseye
(
877 conf
, leftx
, l.pageno
, hooverpageno
, anchor
882 | Ltnotready
(_
, dir
)
885 let rec loop = function
888 match getopaque l.pageno
with
889 | None
-> Ltnotready
(l.pageno
, dir
)
894 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
896 if dir
> 0 then LDfirst
else LDlast
902 | Lnotfound
-> loop rest
904 showlinktype (getlink opaque
n);
905 Ltexact
(l.pageno
, n)
909 state
.mode
<- LinkNav
linknav
912 | Textentry _
| View
-> ()
916 state
.ghyll
<- noghyll
;
919 let mx, my
= state
.mpos
in
924 let conttiling pageno opaque
=
925 tilepage pageno opaque
927 then preloadlayout state
.x state
.y state
.winw state
.winh
931 let gotoxy_and_clear_text x y =
932 if not conf
.verbose
then state
.text <- E.s;
936 let getanchory (n, top
, dtop
) =
937 let y, h = getpageyh
n in
940 let ips = calcips
h in
941 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
943 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
946 let gotoanchor anchor
=
947 gotoxy state
.x (getanchory anchor
);
951 getanchor
() |> cbput state
.hists
.nav
;
955 getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;
959 let anchor = cbgetc state
.hists
.nav dir
in
963 let gotoghyll1 single
y =
965 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
967 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
969 then s (float f /. float a
)
972 then 1.0 -. s ((float (f-b) /. float (n-b)))
978 let ins = float a
*. 0.5
979 and outs
= float (n-b) *. 0.5 in
981 ins +. outs
+. float ones
983 let rec set nab
y sy
=
984 let (_N
, _A
, _B
), y =
987 let scl = if y > sy
then 2 else -2 in
988 let _N, _
, _
= nab
in
989 (_N,0,_N), y+conf
.scrollstep
*scl
991 let sum = summa
_N _A _B
in
992 let dy = float (y - sy
) in
996 then state
.ghyll
<- noghyll
999 let s = scroll n _N _A _B
in
1000 let y1 = y1 +. ((s *. dy) /. sum) in
1001 gotoxy_and_clear_text state
.x (truncate
y1);
1002 state
.ghyll
<- gf (n+1) y1;
1006 | Some
y'
when single
-> set nab
y' state
.y
1007 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1009 gf 0 (float state
.y)
1012 match conf
.ghyllscroll
with
1013 | Some nab
when not conf
.presentation
->
1014 if state
.ghyll
== noghyll
1015 then set nab
y state
.y
1016 else state
.ghyll
(Some
y)
1018 gotoxy_and_clear_text state
.x y
1021 let gotoghyll = gotoghyll1 false;;
1023 let gotopage n top
=
1024 let y, h = getpageyh
n in
1025 let y = y + (truncate
(top
*. float h)) in
1029 let gotopage1 n top
=
1030 let y = getpagey
n in
1035 let invalidate s f =
1036 state
.redisplay
<- false;
1041 match state
.geomcmds
with
1042 | ps
, [] when emptystr ps
->
1044 state
.geomcmds
<- s, [];
1047 state
.geomcmds
<- ps
, [s, f];
1049 | ps
, (s'
, _
) :: rest
when s'
= s ->
1050 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1053 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1057 Hashtbl.iter
(fun _ opaque
->
1058 wcmd "freepage %s" (~
> opaque
);
1060 Hashtbl.clear state
.pagemap
;
1064 if not
(Queue.is_empty state
.tilelru
)
1066 Queue.iter
(fun (k
, p
, s) ->
1067 wcmd "freetile %s" (~
> p
);
1068 state
.memused
<- state
.memused
- s;
1069 Hashtbl.remove state
.tilemap k
;
1071 state
.uioh#infochanged Memused
;
1072 Queue.clear state
.tilelru
;
1078 let h = truncate
(float h*.conf
.zoom
) in
1079 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1085 let sl = keystostrlist conf
in
1087 function | [] -> accu
1088 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1089 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1092 let opendoc path password
=
1094 state
.password
<- password
;
1095 state
.gen
<- state
.gen
+ 1;
1096 state
.docinfo
<- [];
1097 state
.outlines
<- [||];
1100 setaalevel conf
.aalevel
;
1102 if emptystr state
.origin
1106 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1107 wcmd "open %d %d %d %s\000%s\000%s\000"
1108 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1109 path password conf
.css
;
1110 invalidate "reqlayout"
1112 wcmd "reqlayout %d %d %d %s\000"
1113 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1114 (stateh state
.winh
) state
.nameddest
1120 state
.anchor <- getanchor
();
1121 opendoc state
.path state
.password
;
1125 let c = c *. conf
.colorscale
in
1129 let scalecolor2 (r
, g, b) =
1130 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1133 let docolumns columns
=
1136 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1137 let rec loop pageno
pdimno pdim
y ph pdims
=
1138 if pageno
= state
.pagecount
1141 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1143 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1144 pdimno+1, pdim
, rest
1148 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1150 y + (if conf
.presentation
1151 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1152 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1155 a.(pageno
) <- (pdimno, x, y, pdim
);
1156 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1158 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1159 conf
.columns
<- Csingle
a;
1161 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1162 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1163 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1165 if m
= pageno
then () else
1166 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1169 let y = y + (rowh
- h) / 2 in
1170 a.(m
) <- (pdimno, x, y, pdim
);
1174 if pageno
= state
.pagecount
1175 then fixrow (((pageno
- 1) / columns
) * columns
)
1177 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1179 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1180 pdimno+1, pdim
, rest
1185 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1187 let x = (state
.winw
- w) / 2 in
1189 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1190 x, y + ips + rowh
, h
1193 if (pageno
- coverA
) mod columns
= 0
1195 let x = max
0 (state
.winw
- state
.w) / 2 in
1197 if conf
.presentation
1199 let ips = calcips
h in
1200 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1202 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1206 else x, y, max rowh
h
1210 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1213 if pageno
= columns
&& conf
.presentation
1215 let ips = calcips rowh
in
1216 for i
= 0 to pred columns
1218 let (pdimno, x, y, pdim
) = a.(i
) in
1219 a.(i
) <- (pdimno, x, y+ips, pdim
)
1225 fixrow (pageno
- columns
);
1230 a.(pageno
) <- (pdimno, x, y, pdim
);
1231 let x = x + w + xoff
*2 + conf
.interpagespace
in
1232 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1234 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1235 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1238 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1239 let rec loop pageno
pdimno pdim
y pdims
=
1240 if pageno
= state
.pagecount
1243 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1245 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1246 pdimno+1, pdim
, rest
1251 let rec loop1 n x y =
1252 if n = c then y else (
1253 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1254 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1257 let y = loop1 0 0 y in
1258 loop (pageno
+1) pdimno pdim
y pdims
1260 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1261 conf
.columns
<- Csplit
(c, a);
1265 docolumns conf
.columns
;
1266 state
.maxy <- calcheight
();
1267 if state
.reprf
== noreprf
1269 match state
.mode
with
1270 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1271 let y, h = getpageyh pageno
in
1272 let top = (state
.winh
- h) / 2 in
1273 gotoxy state
.x (max
0 (y - top))
1274 | Textentry _
| View
| LinkNav _
->
1275 let y = getanchory state
.anchor in
1276 let y = min
y (state
.maxy - state
.winh
) in
1281 state
.reprf
<- noreprf
;
1285 let reshape ?
(firsttime
=false) w h =
1286 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1287 if not firsttime
&& nogeomcmds state
.geomcmds
1288 then state
.anchor <- getanchor
();
1291 let w = truncate
(float w *. conf
.zoom
) in
1294 setfontsize fstate
.fontsize
;
1295 GlMat.mode `modelview
;
1296 GlMat.load_identity
();
1298 GlMat.mode `projection
;
1299 GlMat.load_identity
();
1300 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1301 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1302 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1307 else float state
.x /. float state
.w
1309 invalidate "geometry"
1313 then state
.x <- truncate
(relx *. float w);
1315 match conf
.columns
with
1317 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1318 | Csplit
(c, _
) -> w * c
1320 wcmd "geometry %d %d %d"
1321 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1326 let len = String.length state
.text in
1327 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1330 match state
.mode
with
1331 | Textentry _
| View
| LinkNav _
->
1332 let h, _
, _
= state
.uioh#scrollpw
in
1338 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1339 (x+.w) (float (state
.winh
- hscrollh))
1342 let w = float (state
.winw
- 1 - vscrollw ()) in
1343 if state
.progress
>= 0.0 && state
.progress
< 1.0
1345 GlDraw.color (0.3, 0.3, 0.3);
1346 let w1 = w *. state
.progress
in
1348 GlDraw.color (0.0, 0.0, 0.0);
1349 rect (float x0+.w1) (float x0+.w-.w1)
1352 GlDraw.color (0.0, 0.0, 0.0);
1356 GlDraw.color (1.0, 1.0, 1.0);
1359 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1360 (state
.winh
- hscrollh - 5) s;
1363 match state
.mode
with
1364 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1367 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1368 else Printf.sprintf
"%s%s_" prefix
text
1372 | Birdseye _
| View
| LinkNav _
-> state
.text
1377 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1379 let s1 = "(press 'e' to review error messasges)" in
1380 if nonemptystr
s then s ^
" " ^
s1 else s1
1390 let len = Queue.length state
.tilelru
in
1392 match state
.throttle
with
1395 then preloadlayout state
.x state
.y state
.winw state
.winh
1397 | Some
(layout, _
, _
) ->
1401 if state
.memused
> conf
.memlimit
1405 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1406 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1407 let (_
, pw, ph
, _
) = getpagedim
n in
1409 && colorspace
= conf
.colorspace
1410 && angle
= conf
.angle
1414 let x = col*conf
.tilew
1415 and y = row*conf
.tileh
in
1416 tilevisible (Lazy.force_val
layout) n x y
1418 then Queue.push lruitem state
.tilelru
1421 wcmd "freetile %s" (~
> p
);
1422 state
.memused
<- state
.memused
- s;
1423 state
.uioh#infochanged Memused
;
1424 Hashtbl.remove state
.tilemap k
;
1432 let onpagerect pageno
f =
1434 match conf
.columns
with
1435 | Cmulti
(_
, b) -> b
1437 | Csplit
(_
, b) -> b
1439 if pageno
>= 0 && pageno
< Array.length
b
1441 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1445 let gotopagexy1 wtmode pageno
x y =
1446 let _,w1,h1
,leftx
= getpagedim pageno
in
1447 let top = y /. (float h1
) in
1448 let left = x /. (float w1) in
1449 let py, w, h = getpageywh pageno
in
1450 let wh = state
.winh
in
1451 let x = left *. (float w) in
1452 let x = leftx
+ state
.x + truncate
x in
1454 if x < 0 || x >= state
.winw
1458 let pdy = truncate
(top *. float h) in
1459 let y'
= py + pdy in
1460 let dy = y'
- state
.y in
1462 if x != state
.x || not
(dy > 0 && dy < wh)
1464 if conf
.presentation
1466 if abs
(py - y'
) > wh
1473 if state
.x != sx || state
.y != sy
1478 let ww = state
.winw
in
1480 and qy
= pdy / wh in
1482 and y = py + qy
* wh in
1483 let x = if -x + ww > w1 then -(w1-ww) else x
1484 and y'
= if y + wh > state
.maxy then state
.maxy - wh else y in
1486 if conf
.presentation
1488 if abs
(py - y'
) > wh
1497 gotoxy_and_clear_text x y;
1499 else gotoxy_and_clear_text state
.x state
.y;
1502 let gotopagexy wtmode pageno
x y =
1503 match state
.mode
with
1504 | Birdseye
_ -> gotopage pageno
0.0
1505 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1508 let getpassword () =
1509 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1514 impmsg "error getting password: %s" s;
1515 dolog
"%s" s) passcmd;
1518 let pgoto opaque pageno
x y =
1519 let pdimno = getpdimno pageno
in
1520 let x, y = project opaque pageno
pdimno x y in
1521 gotopagexy false pageno
x y;
1525 (* dolog "%S" cmds; *)
1526 let spl = splitatchar cmds ' '
in
1528 try Scanf.sscanf
s fmt
f
1530 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1533 let addoutline outline
=
1534 match state
.currently
with
1535 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1536 | Idle
-> state
.currently
<- Outlining
[outline
]
1537 | Loading
_ | Tiling
_ ->
1538 dolog
"invalid outlining state";
1539 logcurrently state
.currently
1544 state
.uioh#infochanged Pdim
;
1546 | "clearrects", "" ->
1547 state
.rects
<- state
.rects1
;
1548 G.postRedisplay "clearrects";
1550 | "continue", args
->
1551 let n = scan args
"%u" (fun n -> n) in
1552 state
.pagecount
<- n;
1553 begin match state
.currently
with
1555 state
.currently
<- Idle
;
1556 state
.outlines
<- Array.of_list
(List.rev
l)
1557 | Idle
| Loading
_ | Tiling
_ -> ()
1560 let cur, cmds
= state
.geomcmds
in
1562 then failwith
"umpossible";
1564 begin match List.rev cmds
with
1566 state
.geomcmds
<- E.s, [];
1567 state
.throttle
<- None
;
1571 state
.geomcmds
<- s, List.rev rest
;
1573 if conf
.maxwait
= None
&& not
!wtmode
1574 then G.postRedisplay "continue";
1581 then showtext ' ' args
1584 Buffer.add_string state
.errmsgs args
;
1585 state
.newerrmsgs
<- true;
1586 G.postRedisplay "error message"
1588 | "progress", args
->
1589 let progress, text =
1592 f, String.sub args pos
(String.length args
- pos
))
1595 state
.progress <- progress;
1596 G.postRedisplay "progress"
1598 | "firstmatch", args
->
1599 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1600 scan args
"%u %d %f %f %f %f %f %f %f %f"
1601 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1602 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1604 let y = (getpagey
pageno) + truncate
y0 in
1612 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1613 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1616 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1617 scan args
"%u %d %f %f %f %f %f %f %f %f"
1618 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1619 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1621 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1623 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1626 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1627 let pageopaque = ~
< pageopaques in
1628 begin match state
.currently
with
1629 | Loading
(l, gen
) ->
1630 vlog "page %d took %f sec" l.pageno t
;
1631 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1632 begin match state
.throttle
with
1634 let preloadedpages =
1636 then preloadlayout state
.x state
.y state
.winw state
.winh
1641 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1642 IntSet.empty
preloadedpages
1645 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1646 if not
(IntSet.mem
pageno set)
1648 wcmd "freepage %s" (~
> opaque
);
1654 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1657 state
.currently
<- Idle
;
1660 tilepage l.pageno pageopaque state
.layout;
1662 load preloadedpages;
1663 let visible = pagevisible state
.layout l.pageno in
1666 match state
.mode
with
1667 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1668 if pageno = l.pageno
1673 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1675 if dir
> 0 then LDfirst
else LDlast
1678 findlink
pageopaque ld
1683 showlinktype (getlink
pageopaque n);
1684 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1686 | LinkNav
(Ltgendir
_)
1687 | LinkNav
(Ltexact
_)
1693 if visible && layoutready state
.layout
1695 G.postRedisplay "page";
1699 | Some
(layout, _, _) ->
1700 state
.currently
<- Idle
;
1701 tilepage l.pageno pageopaque layout;
1705 | Idle
| Tiling
_ | Outlining
_ ->
1706 dolog
"Inconsistent loading state";
1707 logcurrently state
.currently
;
1712 let (x, y, opaques
, size
, t
) =
1713 scan args
"%u %u %s %u %f"
1714 (fun x y p size t
-> (x, y, p
, size
, t
))
1716 let opaque = ~
< opaques
in
1717 begin match state
.currently
with
1718 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1719 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1722 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1724 wcmd "freetile %s" (~
> opaque);
1725 state
.currently
<- Idle
;
1729 puttileopaque l col row gen cs angle
opaque size t
;
1730 state
.memused
<- state
.memused
+ size
;
1731 state
.uioh#infochanged Memused
;
1733 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1734 opaque, size
) state
.tilelru
;
1737 match state
.throttle
with
1738 | None
-> state
.layout
1739 | Some
(layout, _, _) -> layout
1742 state
.currently
<- Idle
;
1744 && conf
.colorspace
= cs
1745 && conf
.angle
= angle
1746 && tilevisible layout l.pageno x y
1747 then conttiling l.pageno pageopaque;
1749 begin match state
.throttle
with
1751 preload state
.layout;
1753 && conf
.colorspace
= cs
1754 && conf
.angle
= angle
1755 && tilevisible state
.layout l.pageno x y
1756 && (not
!wtmode || layoutready state
.layout)
1757 then G.postRedisplay "tile nothrottle";
1759 | Some
(layout, y, _) ->
1760 let ready = layoutready layout in
1764 state
.layout <- layout;
1765 state
.throttle
<- None
;
1766 G.postRedisplay "throttle";
1772 | Idle
| Loading
_ | Outlining
_ ->
1773 dolog
"Inconsistent tiling state";
1774 logcurrently state
.currently
;
1779 let (n, w, h, _) as pdim
=
1780 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1783 match conf
.fitmodel
with
1785 | FitPage
| FitProportional
->
1786 match conf
.columns
with
1787 | Csplit
_ -> (n, w, h, 0)
1788 | Csingle
_ | Cmulti
_ -> pdim
1790 state
.pdims
<- pdim :: state
.pdims
;
1791 state
.uioh#infochanged Pdim
1794 let (l, n, t
, h, pos
) =
1795 scan args
"%u %u %d %u %n"
1796 (fun l n t
h pos
-> l, n, t
, h, pos
)
1798 let s = String.sub args pos
(String.length args
- pos
) in
1799 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1802 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1803 let s = String.sub args pos
len in
1804 let pos2 = pos
+ len + 1 in
1805 let uri = String.sub args
pos2 (String.length args
- pos2) in
1806 addoutline (s, l, Ouri
uri)
1809 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1810 let s = String.sub args pos
(String.length args
- pos
) in
1811 addoutline (s, l, Onone
)
1815 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1817 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1820 let c, v
= splitatchar args '
\t'
in
1827 if not
!ignoredoctitlte
1828 then Wsi.settitle v
;
1832 if let len = String.length
c in
1833 len > 6 && ((String.sub
c (len-4) 4) = "date")
1835 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1837 let b = Buffer.create
10 in
1838 Printf.bprintf
b "%s\t" c;
1841 Buffer.add_substring
b v p
l;
1842 Buffer.add_char
b c;
1843 with exn
-> Buffer.add_string
b @@ exntos exn
1851 Buffer.add_char
b '
['
;
1852 Buffer.add_string
b v
;
1853 Buffer.add_char
b '
]'
;
1860 state
.docinfo
<- (1, s) :: state
.docinfo
1863 state
.docinfo
<- List.rev state
.docinfo
;
1864 state
.uioh#infochanged Docinfo
1868 then Wsi.settitle
"Wrong password";
1869 let password = getpassword () in
1870 if emptystr
password
1871 then error
"document is password protected"
1872 else opendoc state
.path
password
1875 error
"unknown cmd `%S'" cmds
1880 let action = function
1881 | HCprev
-> cbget cb ~
-1
1882 | HCnext
-> cbget cb
1
1883 | HCfirst
-> cbget cb ~
-(cb
.rc)
1884 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1885 and cancel
() = cb
.rc <- rc
1889 let search pattern forward
=
1890 match conf
.columns
with
1891 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1892 | Csingle
_ | Cmulti
_ ->
1893 if nonemptystr pattern
1896 match state
.layout with
1899 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1901 wcmd "search %d %d %d %d,%s\000"
1902 (btod conf
.icase
) pn py (btod forward
) pattern
;
1905 let [@warning
"-4"] intentry
text key =
1907 if emptystr
text && key = Keys.Ascii '
-'
1908 then addchar
text '
-'
1911 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1913 state
.text <- "invalid key";
1923 let l = String.length
s in
1924 let rec loop pos
n =
1928 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1929 loop (pos
+1) (n*26 + m)
1932 let rec loop n = function
1935 match getopaque l.pageno with
1936 | None
-> loop n rest
1938 let m = getlinkcount
opaque in
1941 let under = getlink
opaque n in
1944 else loop (n-m) rest
1946 loop n state
.layout;
1950 let [@warning
"-4"] linknentry
text = function
1952 let text = addchar
text c in
1953 linknact (fun under -> state
.text <- undertext under) text;
1956 state
.text <- Printf.sprintf
"invalid key";
1960 let [@warning
"-4"] textentry
text = function
1961 | Keys.Ascii
c -> TEcont
(addchar
text c)
1962 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1966 let reqlayout angle fitmodel
=
1967 match state
.throttle
with
1969 if nogeomcmds state
.geomcmds
1970 then state
.anchor <- getanchor
();
1971 conf
.angle
<- angle
mod 360;
1974 match state
.mode
with
1975 | LinkNav
_ -> state
.mode
<- View
1976 | Birdseye
_ | Textentry
_ | View
-> ()
1978 conf
.fitmodel
<- fitmodel
;
1982 wcmd "reqlayout %d %d %d"
1983 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1988 let settrim trimmargins trimfuzz
=
1989 if nogeomcmds state
.geomcmds
1990 then state
.anchor <- getanchor
();
1991 conf
.trimmargins
<- trimmargins
;
1992 conf
.trimfuzz
<- trimfuzz
;
1993 let x0, y0, x1, y1 = trimfuzz
in
1995 "settrim" (fun () ->
1996 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
2001 match state
.throttle
with
2003 let zoom = max
0.0001 zoom in
2004 if zoom <> conf
.zoom
2006 state
.prevzoom
<- (conf
.zoom, state
.x);
2008 reshape state
.winw state
.winh
;
2009 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2012 | Some
(layout, y, started
) ->
2014 match conf
.maxwait
with
2018 let dt = now
() -. started
in
2026 let pivotzoom ?
(vw=min state
.w state
.winw
)
2027 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
2028 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2029 let w = float state
.w /. zoom in
2030 let hw = w /. 2.0 in
2031 let ratio = float vh
/. float vw in
2032 let hh = hw *. ratio in
2033 let x0 = float x -. hw
2034 and y0 = float y -. hh in
2035 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2039 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2040 if nogeomcmds state
.geomcmds
2043 then pivotzoom ?
vw ?vh ?
x ?
y zoom
2047 let setcolumns mode columns coverA coverB
=
2048 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2052 then impmsg "split mode doesn't work in bird's eye"
2054 conf
.columns
<- Csplit
(-columns
, E.a);
2062 conf
.columns
<- Csingle
E.a;
2067 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2071 reshape state
.winw state
.winh
;
2074 let resetmstate () =
2075 state
.mstate
<- Mnone
;
2076 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2079 let enterbirdseye () =
2080 let zoom = float conf
.thumbw
/. float state
.winw
in
2081 let birdseyepageno =
2082 let cy = state
.winh
/ 2 in
2086 let rec fold best
= function
2089 let d = cy - (l.pagedispy + l.pagevh/2)
2090 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2091 if abs
d < abs dbest
2100 { conf
with zoom = conf
.zoom },
2101 state
.x, birdseyepageno, -1, getanchor
()
2105 conf
.presentation
<- false;
2106 conf
.interpagespace
<- 10;
2107 conf
.hlinks
<- false;
2108 conf
.fitmodel
<- FitPage
;
2110 conf
.maxwait
<- None
;
2112 match conf
.beyecolumns
with
2115 Cmulti
((c, 0, 0), E.a)
2116 | None
-> Csingle
E.a
2120 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2125 reshape state
.winw state
.winh
;
2128 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2130 conf
.zoom <- c.zoom;
2131 conf
.presentation
<- c.presentation
;
2132 conf
.interpagespace
<- c.interpagespace
;
2133 conf
.maxwait
<- c.maxwait
;
2134 conf
.hlinks
<- c.hlinks
;
2135 conf
.fitmodel
<- c.fitmodel
;
2136 conf
.beyecolumns
<- (
2137 match conf
.columns
with
2138 | Cmulti
((c, _, _), _) -> Some
c
2140 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2143 match c.columns
with
2144 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2145 | Csingle
_ -> Csingle
E.a
2146 | Csplit
(c, _) -> Csplit
(c, E.a)
2150 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2153 reshape state
.winw state
.winh
;
2154 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2158 let togglebirdseye () =
2159 match state
.mode
with
2160 | Birdseye vals
-> leavebirdseye vals
true
2161 | View
-> enterbirdseye ()
2162 | Textentry
_ | LinkNav
_ -> ()
2165 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2166 let pageno = max
0 (pageno - incr
) in
2167 let rec loop = function
2168 | [] -> gotopage1 pageno 0
2169 | l :: _ when l.pageno = pageno ->
2170 if l.pagedispy >= 0 && l.pagey = 0
2171 then G.postRedisplay "upbirdseye"
2172 else gotopage1 pageno 0
2173 | _ :: rest
-> loop rest
2177 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2180 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2181 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2182 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2183 let rec loop = function
2185 let y, h = getpageyh
pageno in
2186 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2187 gotoxy state
.x (clamp dy)
2188 | l :: _ when l.pageno = pageno ->
2189 if l.pagevh != l.pageh
2190 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2191 else G.postRedisplay "downbirdseye"
2192 | _ :: rest
-> loop rest
2198 let [@warning
"-4"] optentry mode
_ key =
2199 let btos b = if b then "on" else "off" in
2203 try conf
.scrollstep
<- int_of_string
s with exn
->
2204 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2206 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2211 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2212 if state
.autoscroll
<> None
2213 then state
.autoscroll
<- Some conf
.autoscrollstep
2215 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2217 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2222 let n, a, b = multicolumns_of_string
s in
2223 setcolumns mode
n a b;
2225 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2227 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2232 let zoom = float (int_of_string
s) /. 100.0 in
2235 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2237 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2242 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2244 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2245 begin match mode
with
2247 leavebirdseye beye
false;
2249 | Textentry
_ | View
| LinkNav
_ -> ();
2252 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2254 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2258 match int_of_string
s with
2259 | angle
-> reqlayout angle conf
.fitmodel
2261 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2263 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2266 conf
.icase
<- not conf
.icase
;
2267 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2270 conf
.preload <- not conf
.preload;
2271 gotoxy state
.x state
.y;
2272 TEdone
("preload " ^
(btos conf
.preload))
2275 conf
.verbose
<- not conf
.verbose
;
2276 TEdone
("verbose " ^
(btos conf
.verbose
))
2279 conf
.debug
<- not conf
.debug
;
2280 TEdone
("debug " ^
(btos conf
.debug
))
2283 conf
.maxhfit
<- not conf
.maxhfit
;
2284 state
.maxy <- calcheight
();
2285 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2288 conf
.crophack
<- not conf
.crophack
;
2289 TEdone
("crophack " ^
btos conf
.crophack
)
2293 match conf
.maxwait
with
2295 conf
.maxwait
<- Some infinity
;
2296 "always wait for page to complete"
2298 conf
.maxwait
<- None
;
2299 "show placeholder if page is not ready"
2304 conf
.underinfo
<- not conf
.underinfo
;
2305 TEdone
("underinfo " ^
btos conf
.underinfo
)
2308 conf
.savebmarks
<- not conf
.savebmarks
;
2309 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2315 match state
.layout with
2320 conf
.interpagespace
<- int_of_string
s;
2321 docolumns conf
.columns
;
2322 state
.maxy <- calcheight
();
2323 let y = getpagey
pageno in
2324 gotoxy state
.x (y + py)
2326 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2328 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2332 match conf
.fitmodel
with
2333 | FitProportional
-> FitWidth
2334 | FitWidth
| FitPage
-> FitProportional
2336 reqlayout conf
.angle
fm;
2337 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2340 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2341 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2344 conf
.invert
<- not conf
.invert
;
2345 TEdone
("invert colors " ^
btos conf
.invert
)
2349 cbput state
.hists
.sel
s;
2352 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2353 textentry
, ondone, true)
2357 then conf
.pax
<- Some
0.0
2358 else conf
.pax
<- None
;
2359 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2362 state
.text <- Printf.sprintf
"bad option %d `%c'"
2370 class type lvsource
=
2372 method getitemcount
: int
2373 method getitem
: int -> (string * int)
2374 method hasaction
: int -> bool
2375 method exit
: uioh
:uioh
->
2381 method getactive
: int
2382 method getfirst
: int
2384 method getminfo
: (int * int) array
2387 class virtual lvsourcebase
= object
2388 val mutable m_active
= 0
2389 val mutable m_first
= 0
2390 val mutable m_pan
= 0
2391 method getactive
= m_active
2392 method getfirst
= m_first
2393 method getpan
= m_pan
2394 method getminfo
: (int * int) array
= E.a
2399 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2402 state
.mode
<- Textentry
(te
, onleave
);
2404 G.postRedisplay "textentrykeyboard enttext";
2406 let histaction cmd
=
2409 | Some
(action, _) ->
2412 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2414 G.postRedisplay "textentry histaction"
2417 let kt = Wsi.kc2kt
key in
2420 if emptystr
text && cancelonempty
2423 G.postRedisplay "textentrykeyboard after cancel";
2426 let s = withoutlastutf8
text in
2427 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2432 G.postRedisplay "textentrykeyboard after confirm"
2434 | Up
-> histaction HCprev
2435 | Down
-> histaction HCnext
2436 | Home
-> histaction HCfirst
2437 | End
-> histaction HClast
2442 begin match opthist
with
2444 | Some
(_, onhistcancel
) -> onhistcancel
()
2448 G.postRedisplay "textentrykeyboard after cancel2"
2451 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2456 | Code
_ | Ascii
_ ->
2457 begin match onkey
text kt with
2461 G.postRedisplay "textentrykeyboard after confirm2";
2464 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2468 G.postRedisplay "textentrykeyboard after cancel3"
2471 state
.mode
<- Textentry
(te
, onleave
);
2472 G.postRedisplay "textentrykeyboard switch";
2474 | _ -> vlog "unhandled key"
2477 let firstof first active
=
2478 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2479 then max
0 (active
- (fstate
.maxrows
/2))
2483 let calcfirst first active
=
2486 let rows = active
- first
in
2487 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2491 let scrollph y maxy =
2492 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2493 let sh = float state
.winh
/. sh in
2494 let sh = max
sh (float conf
.scrollh
) in
2496 let percent = float y /. float maxy in
2497 let position = (float state
.winh
-. sh) *. percent in
2500 if position +. sh > float state
.winh
2501 then float state
.winh
-. sh
2507 let adderrmsg src msg
=
2508 Buffer.add_string state
.errmsgs msg
;
2509 state
.newerrmsgs
<- true;
2513 let adderrfmt src fmt
=
2514 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2517 let coe s = (s :> uioh
);;
2519 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2521 val m_pan
= source#getpan
2522 val m_first
= source#getfirst
2523 val m_active
= source#getactive
2525 val m_prev_uioh
= state
.uioh
2527 method private elemunder
y =
2531 let n = y / (fstate
.fontsize
+1) in
2532 if m_first
+ n < source#getitemcount
2534 if source#hasaction
(m_first
+ n)
2535 then Some
(m_first
+ n)
2542 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2543 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2544 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2545 GlDraw.color (1., 1., 1.);
2546 Gl.enable `texture_2d
;
2547 let fs = fstate
.fontsize
in
2549 let hw = state
.winw
/3 in
2550 let ww = fstate
.wwidth
in
2551 let tabw = 17.0*.ww in
2552 let itemcount = source#getitemcount
in
2553 let minfo = source#getminfo
in
2557 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2559 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2561 if (row - m_first
) > fstate
.maxrows
2564 if row >= 0 && row < itemcount
2566 let (s, level
) = source#getitem
row in
2567 let y = (row - m_first
) * nfs in
2568 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2571 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2575 Gl.disable `texture_2d
;
2576 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2577 GlDraw.color (1., 1., 1.) ~
alpha;
2578 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2579 Gl.enable `texture_2d
;
2582 if zebra
&& row land 1 = 1
2586 GlDraw.color (c,c,c);
2587 let drawtabularstring s =
2589 let x'
= truncate
(x0 +. x) in
2590 let s1, s2
= splitatchar
s '
\000'
in
2592 then drawstring1 fs x'
(y+nfs) s
2598 let s'
= withoutlastutf8
s in
2599 let s = s' ^
UniSyms.ellipsis in
2600 let w = measurestr
fs s in
2601 if float x'
+. w +. ww < float (hw + x'
)
2606 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2610 ignore
(drawstring1 fs x'
(y+nfs) s1);
2611 drawstring1 fs (hw + x'
) (y+nfs) s2
2615 let x = if helpmode
&& row > 0 then x +. ww else x in
2616 let s1, s2
= splitatchar
s '
\t'
in
2619 let nx = drawstr x s1 in
2621 let x = x +. (max
tabw sw) in
2624 let len = String.length
s - 2 in
2625 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2627 let s = String.sub s 2 len in
2628 let x = if not helpmode
then x +. ww else x in
2629 GlDraw.color (1.2, 1.2, 1.2);
2630 let vinc = drawstring1 (fs+fs/4)
2631 (truncate
(x -. ww)) (y+nfs) s in
2632 GlDraw.color (1., 1., 1.);
2633 vinc +. (float fs *. 0.8)
2639 ignore
(drawtabularstring s);
2645 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2648 if (row - m_first
) <= fstate
.maxrows
2650 if row >= 0 && row < itemcount
2652 let (s, level
) = source#getitem
row in
2653 let pos0 = nindex
s '
\000'
in
2654 let y = (row - m_first
) * nfs in
2655 let x = float (level
+ m_pan
) *. ww in
2656 let (first
, last
) = minfo.(row) in
2658 if pos0 > 0 && first
> pos0
2659 then String.sub s (pos0+1) (first
-pos0-1)
2660 else String.sub s 0 first
2662 let suffix = String.sub s first
(last
- first
) in
2663 let w1 = measurestr fstate
.fontsize
prefix in
2664 let w2 = measurestr fstate
.fontsize
suffix in
2665 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2666 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2668 and y0 = float (y+2) in
2670 and y1 = float (y+fs+3) in
2671 filledrect x0 y0 x1 y1;
2675 Gl.disable `texture_2d
;
2676 if Array.length
minfo > 0 then loop m_first
;
2681 method updownlevel incr
=
2682 let len = source#getitemcount
in
2684 if m_active
>= 0 && m_active
< len
2685 then snd
(source#getitem m_active
)
2689 if i
= len then i
-1 else if i
= -1 then 0 else
2690 let _, l = source#getitem i
in
2691 if l != curlevel then i
else flow (i
+incr
)
2693 let active = flow m_active
in
2694 let first = calcfirst m_first
active in
2695 G.postRedisplay "outline updownlevel";
2696 {< m_active
= active; m_first
= first >}
2698 method private key1
key mask
=
2699 let set1 active first qsearch
=
2700 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2702 let search active pattern incr
=
2703 let active = if active = -1 then m_first
else active in
2706 if n >= 0 && n < source#getitemcount
2708 let s, _ = source#getitem
n in
2709 match Str.search_forward re
s 0 with
2710 | exception Not_found
-> loop (n + incr
)
2717 let qpat = Str.quote pattern
in
2718 match Str.regexp_case_fold
qpat with
2721 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2722 qpat @@ Printexc.to_string exn
;
2725 let itemcount = source#getitemcount
in
2726 let find start incr
=
2728 if i
= -1 || i
= itemcount
2731 if source#hasaction i
2733 else find (i
+ incr
)
2738 let set active first =
2739 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2741 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2744 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2746 let incr1 = if incr
> 0 then 1 else -1 in
2747 if isvisible m_first m_active
2750 let next = m_active
+ incr
in
2752 if next < 0 || next >= itemcount
2754 else find next incr1
2756 if abs
(m_active
- next) > fstate
.maxrows
2762 let first = m_first
+ incr
in
2763 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2765 let next = m_active
+ incr
in
2766 let next = bound
next 0 (itemcount - 1) in
2773 if isvisible first next
2780 let first = min
next m_first
in
2782 if abs
(next - first) > fstate
.maxrows
2788 let first = m_first
+ incr
in
2789 let first = bound
first 0 (itemcount - 1) in
2791 let next = m_active
+ incr
in
2792 let next = bound
next 0 (itemcount - 1) in
2793 let next = find next incr1 in
2795 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2797 let active = if m_active
= -1 then next else m_active
in
2802 if isvisible first active
2808 G.postRedisplay "listview navigate";
2812 let kt = Wsi.kc2kt
key in
2813 match [@warning
"-4"] kt with
2814 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2815 let incr = if c = 'r'
then -1 else 1 in
2817 match search (m_active
+ incr) m_qsearch
incr with
2819 state
.text <- m_qsearch ^
" [not found]";
2822 state
.text <- m_qsearch
;
2823 active, firstof m_first
active
2825 G.postRedisplay "listview ctrl-r/s";
2826 set1 active first m_qsearch
;
2828 | Insert
when Wsi.withctrl mask
->
2829 if m_active
>= 0 && m_active
< source#getitemcount
2831 let s, _ = source#getitem m_active
in
2837 if emptystr m_qsearch
2840 let qsearch = withoutlastutf8 m_qsearch
in
2844 G.postRedisplay "listview empty qsearch";
2845 set1 m_active m_first
E.s;
2849 match search m_active
qsearch ~
-1 with
2851 state
.text <- qsearch ^
" [not found]";
2854 state
.text <- qsearch;
2855 active, firstof m_first
active
2857 G.postRedisplay "listview backspace qsearch";
2858 set1 active first qsearch
2861 | Ascii
_ | Code
_ ->
2863 match [@warning
"-8"] kt with
2864 | Ascii
c -> String.make
1 c
2865 | Code code
-> toutf8 code
2867 let pattern = m_qsearch ^
utf8 in
2869 match search m_active
pattern 1 with
2871 state
.text <- pattern ^
" [not found]";
2874 state
.text <- pattern;
2875 active, firstof m_first
active
2877 G.postRedisplay "listview qsearch add";
2878 set1 active first pattern;
2882 if emptystr m_qsearch
2884 G.postRedisplay "list view escape";
2885 let mx, my
= state
.mpos
in
2887 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2888 ~
first:m_first ~pan
:m_pan
with
2889 | None
-> m_prev_uioh
2893 G.postRedisplay "list view kill qsearch";
2894 coe {< m_qsearch
= E.s >}
2899 let self = {< m_qsearch
= E.s >} in
2901 G.postRedisplay "listview enter";
2902 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2903 source#exit ~uioh
:(coe self) ~
cancel
2904 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2906 begin match opt with
2907 | None
-> m_prev_uioh
2914 | Up
-> navigate ~
-1
2915 | Down
-> navigate 1
2916 | Prior
-> navigate ~
-(fstate
.maxrows
)
2917 | Next
-> navigate fstate
.maxrows
2921 G.postRedisplay "listview right";
2922 coe {< m_pan
= m_pan
- 1 >}
2926 G.postRedisplay "listview left";
2927 coe {< m_pan
= m_pan
+ 1 >}
2930 let active = find 0 1 in
2931 G.postRedisplay "listview home";
2935 let first = max
0 (itemcount - fstate
.maxrows
) in
2936 let active = find (itemcount - 1) ~
-1 in
2937 G.postRedisplay "listview end";
2942 method key key mask
=
2943 match state
.mode
with
2945 textentrykeyboard
key mask te
;
2947 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2949 method button button down
x y _ =
2952 | 1 when vscrollhit x ->
2953 G.postRedisplay "listview scroll";
2956 let _, position, sh = self#
scrollph in
2957 if y > truncate
position && y < truncate
(position +. sh)
2959 state
.mstate
<- Mscrolly
;
2963 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2964 let first = truncate
(s *. float source#getitemcount
) in
2965 let first = min source#getitemcount
first in
2966 Some
(coe {< m_first
= first; m_active
= first >})
2968 state
.mstate
<- Mnone
;
2972 begin match self#elemunder
y with
2974 G.postRedisplay "listview click";
2975 source#exit ~uioh
:(coe {< m_active
= n >})
2976 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2980 | n when (n == 4 || n == 5) && not down
->
2981 let len = source#getitemcount
in
2983 if n = 5 && m_first
+ fstate
.maxrows
>= len
2987 let first = m_first
+ (if n == 4 then -1 else 1) in
2988 bound
first 0 (len - 1)
2990 G.postRedisplay "listview wheel";
2991 Some
(coe {< m_first
= first >})
2992 | n when (n = 6 || n = 7) && not down
->
2993 let inc = if n = 7 then -1 else 1 in
2994 G.postRedisplay "listview hwheel";
2995 Some
(coe {< m_pan
= m_pan
+ inc >})
3000 | None
-> m_prev_uioh
3003 method multiclick
_ x y = self#button
1 true x y
3006 match state
.mstate
with
3008 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3009 let first = truncate
(s *. float source#getitemcount
) in
3010 let first = min source#getitemcount
first in
3011 G.postRedisplay "listview motion";
3012 coe {< m_first
= first; m_active
= first >}
3020 method pmotion
x y =
3021 if x < state
.winw
- conf
.scrollbw
3024 match self#elemunder
y with
3025 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3026 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3030 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3035 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3039 method infochanged
_ = ()
3041 method scrollpw
= (0, 0.0, 0.0)
3043 let nfs = fstate
.fontsize
+ 1 in
3044 let y = m_first
* nfs in
3045 let itemcount = source#getitemcount
in
3046 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3047 let maxy = maxi * nfs in
3048 let p, h = scrollph y maxy in
3051 method modehash
= modehash
3052 method eformsgs
= false
3053 method alwaysscrolly
= true
3054 method scroll _ dy =
3056 if dy != 0 then begin
3057 let len = source#getitemcount
in
3059 if dy > 0 && m_first
+ fstate
.maxrows
>= len
3063 let first = m_first
+ dy / 10 in
3064 bound
first 0 (len - 1)
3066 G.postRedisplay "listview wheel";
3067 {< m_first
= first >}
3073 method zoom _ _ _ = ()
3076 class outlinelistview ~zebra ~source
=
3077 let settext autonarrow
s =
3080 let ss = source#statestr
in
3084 else "{" ^
ss ^
"} [" ^
s ^
"]"
3085 else state
.text <- s
3091 ~source
:(source
:> lvsource
)
3093 ~modehash
:(findkeyhash conf
"outline")
3096 val m_autonarrow
= false
3098 method! key key mask
=
3100 if emptystr state
.text
3102 else fstate
.maxrows - 2
3104 let calcfirst first active =
3107 let rows = active - first in
3108 if rows > maxrows then active - maxrows else first
3112 let active = m_active
+ incr in
3113 let active = bound
active 0 (source#getitemcount
- 1) in
3114 let first = calcfirst m_first
active in
3115 G.postRedisplay "outline navigate";
3116 coe {< m_active
= active; m_first
= first >}
3118 let navscroll first =
3120 let dist = m_active
- first in
3126 else first + maxrows
3129 G.postRedisplay "outline navscroll";
3130 coe {< m_first
= first; m_active
= active >}
3132 let ctrl = Wsi.withctrl mask
in
3134 match Wsi.kc2kt
key with
3135 | Ascii '
a'
when ctrl ->
3138 then (source#denarrow
; E.s)
3140 let pattern = source#renarrow
in
3141 if nonemptystr m_qsearch
3142 then (source#narrow m_qsearch
; m_qsearch
)
3146 settext (not m_autonarrow
) text;
3147 G.postRedisplay "toggle auto narrowing";
3148 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3150 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3152 G.postRedisplay "toggle auto narrowing";
3153 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3155 | Ascii '
n'
when ctrl ->
3156 source#narrow m_qsearch
;
3158 then source#add_narrow_pattern m_qsearch
;
3159 G.postRedisplay "outline ctrl-n";
3160 coe {< m_first
= 0; m_active
= 0 >}
3162 | Ascii 'S'
when ctrl ->
3163 let active = source#calcactive
(getanchor
()) in
3164 let first = firstof m_first
active in
3165 G.postRedisplay "outline ctrl-s";
3166 coe {< m_first
= first; m_active
= active >}
3168 | Ascii 'u'
when ctrl ->
3169 G.postRedisplay "outline ctrl-u";
3170 if m_autonarrow
&& nonemptystr m_qsearch
3172 ignore
(source#renarrow
);
3173 settext m_autonarrow
E.s;
3174 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3177 source#del_narrow_pattern
;
3178 let pattern = source#renarrow
in
3180 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3182 settext m_autonarrow
text;
3183 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3186 | Ascii '
l'
when ctrl ->
3187 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3188 G.postRedisplay "outline ctrl-l";
3189 coe {< m_first
= first >}
3191 | Ascii '
\t'
when m_autonarrow
->
3192 if nonemptystr m_qsearch
3194 G.postRedisplay "outline list view tab";
3195 source#add_narrow_pattern m_qsearch
;
3197 coe {< m_qsearch
= E.s >}
3201 | Escape
when m_autonarrow
->
3202 if nonemptystr m_qsearch
3203 then source#add_narrow_pattern m_qsearch
;
3206 | Enter
when m_autonarrow
->
3207 if nonemptystr m_qsearch
3208 then source#add_narrow_pattern m_qsearch
;
3211 | (Ascii
_ | Code
_) when m_autonarrow
->
3212 let pattern = m_qsearch ^ toutf8
key in
3213 G.postRedisplay "outlinelistview autonarrow add";
3214 source#narrow
pattern;
3215 settext true pattern;
3216 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3218 | Backspace
when m_autonarrow
->
3219 if emptystr m_qsearch
3222 let pattern = withoutlastutf8 m_qsearch
in
3223 G.postRedisplay "outlinelistview autonarrow backspace";
3224 ignore
(source#renarrow
);
3225 source#narrow
pattern;
3226 settext true pattern;
3227 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3230 navscroll (max
0 (m_first
- 1))
3233 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3235 | Up
-> navigate ~
-1
3236 | Down
-> navigate 1
3237 | Prior
-> navigate ~
-(fstate
.maxrows)
3238 | Next
-> navigate fstate
.maxrows
3244 G.postRedisplay "outline ctrl right";
3245 {< m_pan
= m_pan
+ 1 >}
3247 else self#updownlevel
1
3255 G.postRedisplay "outline ctrl left";
3256 {< m_pan
= m_pan
- 1 >}
3258 else self#updownlevel ~
-1
3263 G.postRedisplay "outline home";
3264 coe {< m_first
= 0; m_active
= 0 >}
3267 let active = source#getitemcount
- 1 in
3268 let first = max
0 (active - fstate
.maxrows) in
3269 G.postRedisplay "outline end";
3270 coe {< m_active
= active; m_first
= first >}
3272 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
3276 let genhistoutlines () =
3278 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3279 compare c2
.lastvisit c1
.lastvisit
)
3280 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3281 let path = if nonemptystr origin
then origin
else path in
3282 let base = mbtoutf8
@@ Filename.basename
path in
3283 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3287 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3288 Config.save
leavebirdseye;
3289 state
.anchor <- anchor;
3290 state
.bookmarks
<- bookmarks
;
3291 state
.origin
<- origin
;
3294 let x0, y0, x1, y1 = conf
.trimfuzz
in
3295 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3296 reshape ~firsttime
:true state
.winw state
.winh
;
3297 opendoc path origin
;
3301 let makecheckers () =
3302 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3304 converted by Issac Trotts. July 25, 2002 *)
3305 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3306 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3307 let id = GlTex.gen_texture
() in
3308 GlTex.bind_texture ~target
:`texture_2d
id;
3309 GlPix.store
(`unpack_alignment
1);
3310 GlTex.image2d
image;
3311 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3312 [ `mag_filter `nearest
; `min_filter `nearest
];
3316 let setcheckers enabled
=
3317 match state
.checkerstexid
with
3319 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3321 | Some checkerstexid
->
3324 GlTex.delete_texture checkerstexid
;
3325 state
.checkerstexid
<- None
;
3329 let describe_layout layout =
3333 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
3336 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
3338 let sep = if a.pageno+1 = b.pageno then ", " else UniSyms.ellipsis in
3339 Printf.sprintf
"%d%s%d" (a.pageno+1) sep (b.pageno+1)
3341 let rec fold s la lb
= function
3342 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
3343 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
3344 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
3346 fold "Pages" l l rest
3349 let maxy = maxy () in
3352 else 100. *. (float state
.y /. float maxy)
3354 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
3357 let setpresentationmode v
=
3358 let n = page_of_y state
.y in
3359 state
.anchor <- (n, 0.0, 1.0);
3360 conf
.presentation
<- v
;
3361 if conf
.fitmodel
= FitPage
3362 then reqlayout conf
.angle conf
.fitmodel
;
3367 let btos b = if b then UniSyms.radical else E.s in
3368 let showextended = ref false in
3369 let showcolors = ref false in
3370 let leave mode
_ = state
.mode
<- mode
in
3373 val mutable m_l
= []
3374 val mutable m_a
= E.a
3375 val mutable m_prev_uioh
= nouioh
3376 val mutable m_prev_mode
= View
3378 inherit lvsourcebase
3380 method reset prev_mode prev_uioh
=
3381 m_a
<- Array.of_list
(List.rev m_l
);
3383 m_prev_mode
<- prev_mode
;
3384 m_prev_uioh
<- prev_uioh
;
3386 method int name get
set =
3392 try set (int_of_string
s)
3394 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3398 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3399 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3403 method int_with_suffix name get
set =
3405 (name
, `intws get
, 1,
3409 try set (int_of_string_with_suffix
s)
3411 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3416 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3418 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3422 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3424 (name
, `
bool (btos, get
), offset
, Action
(
3431 method color name get
set =
3433 (name
, `
color get
, 1,
3436 let invalid = (nan
, nan
, nan
) in
3439 try color_of_string
s
3441 state
.text <- Printf.sprintf
"bad color `%s': %s"
3448 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3449 state
.text <- color_to_string
(get
());
3450 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3454 method string name get
set =
3456 (name
, `
string get
, 1,
3459 let ondone s = set s in
3460 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3461 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3465 method colorspace name get
set =
3467 (name
, `
string get
, 1,
3472 inherit lvsourcebase
3475 m_active
<- CSTE.to_int conf
.colorspace
;
3478 method getitemcount
=
3479 Array.length
CSTE.names
3482 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3483 ignore
(uioh
, first, pan
);
3484 if not
cancel then set active;
3486 method hasaction
_ = true
3490 let modehash = findkeyhash conf
"info" in
3491 coe (new listview ~zebra
:false ~helpmode
:false
3492 ~
source ~trusted
:true ~
modehash)
3495 method paxmark name get
set =
3497 (name
, `
string get
, 1,
3502 inherit lvsourcebase
3505 m_active
<- MTE.to_int conf
.paxmark
;
3508 method getitemcount
= Array.length
MTE.names
3509 method getitem
n = (MTE.names
.(n), 0)
3510 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3511 ignore
(uioh
, first, pan
);
3512 if not
cancel then set active;
3514 method hasaction
_ = true
3518 let modehash = findkeyhash conf
"info" in
3519 coe (new listview ~zebra
:false ~helpmode
:false
3520 ~
source ~trusted
:true ~
modehash)
3523 method fitmodel name get
set =
3525 (name
, `
string get
, 1,
3530 inherit lvsourcebase
3533 m_active
<- FMTE.to_int conf
.fitmodel
;
3536 method getitemcount
= Array.length
FMTE.names
3537 method getitem
n = (FMTE.names
.(n), 0)
3538 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3539 ignore
(uioh
, first, pan
);
3540 if not
cancel then set active;
3542 method hasaction
_ = true
3546 let modehash = findkeyhash conf
"info" in
3547 coe (new listview ~zebra
:false ~helpmode
:false
3548 ~
source ~trusted
:true ~
modehash)
3551 method caption
s offset
=
3552 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3554 method caption2
s f offset
=
3555 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3557 method getitemcount
= Array.length m_a
3560 let tostr = function
3561 | `
int f -> string_of_int
(f ())
3562 | `intws
f -> string_with_suffix_of_int
(f ())
3564 | `
color f -> color_to_string
(f ())
3565 | `
bool (btos, f) -> btos (f ())
3568 let name, t
, offset
, _ = m_a
.(n) in
3569 ((let s = tostr t
in
3571 then Printf.sprintf
"%s\t%s" name s
3575 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3580 match m_a
.(active) with
3581 | _, _, _, Action
f -> f uioh
3582 | _, _, _, Noaction
-> uioh
3593 method hasaction
n =
3595 | _, _, _, Action
_ -> true
3596 | _, _, _, Noaction
-> false
3598 initializer m_active
<- 1
3601 let rec fillsrc prevmode prevuioh
=
3602 let sep () = src#caption
E.s 0 in
3603 let colorp name get
set =
3605 (fun () -> color_to_string
(get
()))
3608 let c = color_of_string
v in
3612 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3615 let rgba name get
set =
3617 (fun () -> rgba_to_string
(get
()))
3620 let c = rgba_of_string
v in
3624 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3627 let oldmode = state
.mode
in
3628 let birdseye = isbirdseye state
.mode
in
3630 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3632 src#
bool "presentation mode"
3633 (fun () -> conf
.presentation
)
3634 (fun v -> setpresentationmode v);
3636 src#
bool "ignore case in searches"
3637 (fun () -> conf
.icase
)
3638 (fun v -> conf
.icase
<- v);
3641 (fun () -> conf
.preload)
3642 (fun v -> conf
.preload <- v);
3644 src#
bool "highlight links"
3645 (fun () -> conf
.hlinks
)
3646 (fun v -> conf
.hlinks
<- v);
3648 src#
bool "under info"
3649 (fun () -> conf
.underinfo
)
3650 (fun v -> conf
.underinfo
<- v);
3652 src#
bool "persistent bookmarks"
3653 (fun () -> conf
.savebmarks
)
3654 (fun v -> conf
.savebmarks
<- v);
3656 src#fitmodel
"fit model"
3657 (fun () -> FMTE.to_string conf
.fitmodel
)
3658 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3660 src#
bool "trim margins"
3661 (fun () -> conf
.trimmargins
)
3662 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3664 src#
bool "persistent location"
3665 (fun () -> conf
.jumpback
)
3666 (fun v -> conf
.jumpback
<- v);
3669 src#
int "inter-page space"
3670 (fun () -> conf
.interpagespace
)
3672 conf
.interpagespace
<- n;
3673 docolumns conf
.columns
;
3675 match state
.layout with
3680 state
.maxy <- calcheight
();
3681 let y = getpagey
pageno in
3682 gotoxy state
.x (y + py)
3686 (fun () -> conf
.pagebias
)
3687 (fun v -> conf
.pagebias
<- v);
3689 src#
int "scroll step"
3690 (fun () -> conf
.scrollstep
)
3691 (fun n -> conf
.scrollstep
<- n);
3693 src#
int "horizontal scroll step"
3694 (fun () -> conf
.hscrollstep
)
3695 (fun v -> conf
.hscrollstep
<- v);
3697 src#
int "auto scroll step"
3699 match state
.autoscroll
with
3701 | _ -> conf
.autoscrollstep
)
3703 let n = boundastep state
.winh
n in
3704 if state
.autoscroll
<> None
3705 then state
.autoscroll
<- Some
n;
3706 conf
.autoscrollstep
<- n);
3709 (fun () -> truncate
(conf
.zoom *. 100.))
3710 (fun v -> pivotzoom ((float v) /. 100.));
3713 (fun () -> conf
.angle
)
3714 (fun v -> reqlayout v conf
.fitmodel
);
3716 src#
int "scroll bar width"
3717 (fun () -> conf
.scrollbw
)
3720 reshape state
.winw state
.winh
;
3723 src#
int "scroll handle height"
3724 (fun () -> conf
.scrollh
)
3725 (fun v -> conf
.scrollh
<- v;);
3727 src#
int "thumbnail width"
3728 (fun () -> conf
.thumbw
)
3730 conf
.thumbw
<- min
4096 v;
3733 leavebirdseye beye
false;
3740 let mode = state
.mode in
3741 src#
string "columns"
3743 match conf
.columns
with
3745 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3746 | Csplit
(count
, _) -> "-" ^ string_of_int count
3749 let n, a, b = multicolumns_of_string
v in
3750 setcolumns mode n a b);
3753 src#caption
"Pixmap cache" 0;
3754 src#int_with_suffix
"size (advisory)"
3755 (fun () -> conf
.memlimit
)
3756 (fun v -> conf
.memlimit
<- v);
3760 Printf.sprintf
"%s bytes, %d tiles"
3761 (string_with_suffix_of_int state
.memused
)
3762 (Hashtbl.length state
.tilemap
)) 1;
3765 src#caption
"Layout" 0;
3766 src#caption2
"Dimension"
3768 Printf.sprintf
"%dx%d (virtual %dx%d)"
3769 state
.winw state
.winh
3774 src#caption2
"Position" (fun () ->
3775 Printf.sprintf
"%dx%d" state
.x state
.y
3778 src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
3781 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3782 "Save these parameters as global defaults at exit"
3783 (fun () -> conf
.bedefault
)
3784 (fun v -> conf
.bedefault
<- v);
3787 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3788 src#
bool ~offset
:0 ~
btos "Extended parameters"
3789 (fun () -> !showextended)
3790 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3794 (fun () -> conf
.checkers
)
3795 (fun v -> conf
.checkers
<- v; setcheckers v);
3796 src#
bool "update cursor"
3797 (fun () -> conf
.updatecurs
)
3798 (fun v -> conf
.updatecurs
<- v);
3799 src#
bool "scroll-bar on the left"
3800 (fun () -> conf
.leftscroll
)
3801 (fun v -> conf
.leftscroll
<- v);
3803 (fun () -> conf
.verbose
)
3804 (fun v -> conf
.verbose
<- v);
3805 src#
bool "invert colors"
3806 (fun () -> conf
.invert
)
3807 (fun v -> conf
.invert
<- v);
3809 (fun () -> conf
.maxhfit
)
3810 (fun v -> conf
.maxhfit
<- v);
3812 (fun () -> conf
.pax
!= None
)
3815 then conf
.pax
<- Some
(now
())
3816 else conf
.pax
<- None
);
3817 src#
string "uri launcher"
3818 (fun () -> conf
.urilauncher
)
3819 (fun v -> conf
.urilauncher
<- v);
3820 src#
string "path launcher"
3821 (fun () -> conf
.pathlauncher
)
3822 (fun v -> conf
.pathlauncher
<- v);
3823 src#
string "tile size"
3824 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3827 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3828 conf
.tilew
<- max
64 w;
3829 conf
.tileh
<- max
64 h;
3832 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3835 src#
int "texture count"
3836 (fun () -> conf
.texcount
)
3839 then conf
.texcount
<- v
3840 else impmsg "failed to set texture count please retry later"
3842 src#
int "slice height"
3843 (fun () -> conf
.sliceheight
)
3845 conf
.sliceheight
<- v;
3846 wcmd "sliceh %d" conf
.sliceheight
;
3848 src#
int "anti-aliasing level"
3849 (fun () -> conf
.aalevel
)
3851 conf
.aalevel
<- bound
v 0 8;
3852 state
.anchor <- getanchor
();
3853 opendoc state
.path state
.password;
3855 src#
string "page scroll scaling factor"
3856 (fun () -> string_of_float conf
.pgscale)
3859 let s = float_of_string
v in
3862 state
.text <- Printf.sprintf
3863 "bad page scroll scaling factor `%s': %s" v
3867 src#
int "ui font size"
3868 (fun () -> fstate
.fontsize
)
3869 (fun v -> setfontsize (bound
v 5 100));
3870 src#
int "hint font size"
3871 (fun () -> conf
.hfsize
)
3872 (fun v -> conf
.hfsize
<- bound
v 5 100);
3873 src#
bool "crop hack"
3874 (fun () -> conf
.crophack
)
3875 (fun v -> conf
.crophack
<- v);
3876 src#
string "trim fuzz"
3877 (fun () -> irect_to_string conf
.trimfuzz
)
3880 conf
.trimfuzz
<- irect_of_string
v;
3882 then settrim true conf
.trimfuzz
;
3884 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3887 src#
string "throttle"
3889 match conf
.maxwait
with
3890 | None
-> "show place holder if page is not ready"
3893 then "wait for page to fully render"
3895 "wait " ^ string_of_float
time
3896 ^
" seconds before showing placeholder"
3900 let f = float_of_string
v in
3902 then conf
.maxwait
<- None
3903 else conf
.maxwait
<- Some
f
3905 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3908 src#
string "ghyll scroll"
3910 match conf
.ghyllscroll
with
3912 | Some nab
-> ghyllscroll_to_string nab
3915 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3918 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3920 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3923 src#
string "selection command"
3924 (fun () -> conf
.selcmd
)
3925 (fun v -> conf
.selcmd
<- v);
3926 src#
string "synctex command"
3927 (fun () -> conf
.stcmd
)
3928 (fun v -> conf
.stcmd
<- v);
3929 src#
string "pax command"
3930 (fun () -> conf
.paxcmd
)
3931 (fun v -> conf
.paxcmd
<- v);
3932 src#
string "ask password command"
3933 (fun () -> conf
.passcmd)
3934 (fun v -> conf
.passcmd <- v);
3935 src#
string "save path command"
3936 (fun () -> conf
.savecmd
)
3937 (fun v -> conf
.savecmd
<- v);
3938 src#colorspace
"color space"
3939 (fun () -> CSTE.to_string conf
.colorspace
)
3941 conf
.colorspace
<- CSTE.of_int
v;
3945 src#paxmark
"pax mark method"
3946 (fun () -> MTE.to_string conf
.paxmark
)
3947 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3948 if bousable
() && !opengl_has_pbo
3951 (fun () -> conf
.usepbo
)
3952 (fun v -> conf
.usepbo
<- v);
3953 src#
bool "mouse wheel scrolls pages"
3954 (fun () -> conf
.wheelbypage
)
3955 (fun v -> conf
.wheelbypage
<- v);
3956 src#
bool "open remote links in a new instance"
3957 (fun () -> conf
.riani
)
3958 (fun v -> conf
.riani
<- v);
3959 src#
bool "edit annotations inline"
3960 (fun () -> conf
.annotinline
)
3961 (fun v -> conf
.annotinline
<- v);
3962 src#
bool "coarse positioning in presentation mode"
3963 (fun () -> conf
.coarseprespos
)
3964 (fun v -> conf
.coarseprespos
<- v);
3965 src#
bool "use document CSS"
3966 (fun () -> conf
.usedoccss
)
3968 conf
.usedoccss
<- v;
3969 state
.anchor <- getanchor
();
3970 opendoc state
.path state
.password;
3972 src#
bool ~
btos "colors"
3973 (fun () -> !showcolors)
3974 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
3977 colorp " background"
3978 (fun () -> conf
.bgcolor
)
3979 (fun v -> conf
.bgcolor
<- v);
3981 (fun () -> conf
.sbarcolor
)
3982 (fun v -> conf
.sbarcolor
<- v);
3983 rgba " scrollbar handle"
3984 (fun () -> conf
.sbarhndlcolor
)
3985 (fun v -> conf
.sbarhndlcolor
<- v);
3990 src#caption
"Document" 0;
3991 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3992 src#caption2
"Pages"
3993 (fun () -> string_of_int state
.pagecount
) 1;
3994 src#caption2
"Dimensions"
3995 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3996 if nonemptystr conf
.css
3997 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
4001 src#caption
"Trimmed margins" 0;
4002 src#caption2
"Dimensions"
4003 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4007 src#caption
"OpenGL" 0;
4008 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4009 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4012 src#caption
"Location" 0;
4013 if nonemptystr state
.origin
4014 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
4015 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
4017 src#reset prevmode prevuioh
;
4022 let prevmode = state
.mode
4023 and prevuioh
= state
.uioh in
4024 fillsrc prevmode prevuioh
;
4025 let source = (src :> lvsource
) in
4026 let modehash = findkeyhash conf
"info" in
4029 inherit listview ~zebra
:false ~helpmode
:false
4030 ~
source ~trusted
:true ~
modehash as super
4031 val mutable m_prevmemused
= 0
4032 method! infochanged
= function
4034 if m_prevmemused
!= state
.memused
4036 m_prevmemused
<- state
.memused
;
4037 G.postRedisplay "memusedchanged";
4039 | Pdim
-> G.postRedisplay "pdimchanged"
4040 | Docinfo
-> fillsrc prevmode prevuioh
4042 method! key key mask
=
4043 if not
(Wsi.withctrl mask
)
4045 match [@warning
"-4"] Wsi.kc2kt
key with
4046 | Keys.Left
-> coe (self#updownlevel ~
-1)
4047 | Keys.Right
-> coe (self#updownlevel
1)
4048 | _ -> super#
key key mask
4049 else super#
key key mask
4051 G.postRedisplay "info";
4057 inherit lvsourcebase
4058 method getitemcount
= Array.length state
.help
4060 let s, l, _ = state
.help
.(n) in
4063 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4067 match state
.help
.(active) with
4068 | _, _, Action
f -> Some
(f uioh)
4069 | _, _, Noaction
-> Some
uioh
4078 method hasaction
n =
4079 match state
.help
.(n) with
4080 | _, _, Action
_ -> true
4081 | _, _, Noaction
-> false
4087 let modehash = findkeyhash conf
"help" in
4089 state
.uioh <- coe (new listview
4090 ~zebra
:false ~helpmode
:true
4091 ~
source ~trusted
:true ~
modehash);
4092 G.postRedisplay "help";
4098 inherit lvsourcebase
4099 val mutable m_items
= E.a
4101 method getitemcount
= 1 + Array.length m_items
4106 else m_items
.(n-1), 0
4108 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4113 then Buffer.clear state
.errmsgs
;
4120 method hasaction
n =
4124 state
.newerrmsgs
<- false;
4125 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4126 m_items
<- Array.of_list
l
4135 let source = (msgsource :> lvsource
) in
4136 let modehash = findkeyhash conf
"listview" in
4139 inherit listview ~zebra
:false ~helpmode
:false
4140 ~
source ~trusted
:false ~
modehash as super
4143 then msgsource#reset
;
4146 G.postRedisplay "msgs";
4150 let editor = getenvwithdef
"EDITOR" E.s in
4154 let tmppath = Filename.temp_file
"llpp" "note" in
4157 let oc = open_out
tmppath in
4161 let execstr = editor ^
" " ^
tmppath in
4163 match spawn
execstr [] with
4165 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4168 match Unix.waitpid
[] pid
with
4170 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4174 | Unix.WEXITED
0 -> filecontents
tmppath
4176 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4178 | Unix.WSIGNALED
n ->
4179 impmsg "editor process(%s) was killed by signal %d" execstr n;
4181 | Unix.WSTOPPED
n ->
4182 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4185 match Unix.unlink
tmppath with
4187 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4192 let enterannotmode opaque slinkindex
=
4195 inherit lvsourcebase
4196 val mutable m_text
= E.s
4197 val mutable m_items
= E.a
4199 method getitemcount
= Array.length m_items
4202 let label, _func
= m_items
.(n) in
4205 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4206 ignore
(uioh, first, pan
);
4209 let _label, func
= m_items
.(active) in
4214 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4217 let rec split accu b i
=
4219 if p = String.length
s
4220 then (String.sub s b (p-b), unit) :: accu
4222 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4224 let ss = if i
= 0 then E.s else String.sub s b i
in
4225 split ((ss, unit)::accu) (p+1) 0
4230 wcmd "freepage %s" (~
> opaque);
4232 Hashtbl.fold (fun key opaque'
accu ->
4233 if opaque'
= opaque'
4234 then key :: accu else accu) state
.pagemap
[]
4236 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4238 gotoxy state
.x state
.y
4241 delannot
opaque slinkindex
;
4244 let edit inline
() =
4249 modannot
opaque slinkindex
s;
4255 let mode = state
.mode in
4258 ("annotation: ", m_text
, None
, textentry
, update, true),
4259 fun _ -> state
.mode <- mode);
4263 let s = getusertext m_text
in
4268 ( "[Copy]", fun () -> selstring m_text
)
4269 :: ("[Delete]", dele)
4270 :: ("[Edit]", edit conf
.annotinline
)
4272 :: split [] 0 0 |> List.rev
|> Array.of_list
4279 let s = getannotcontents
opaque slinkindex
in
4282 let source = (msgsource :> lvsource
) in
4283 let modehash = findkeyhash conf
"listview" in
4284 state
.uioh <- coe (object
4285 inherit listview ~zebra
:false ~helpmode
:false
4286 ~
source ~trusted
:false ~
modehash
4288 G.postRedisplay "enterannotmode";
4291 let gotoremote spec
=
4292 let filename, dest
= splitatchar spec '#'
in
4293 let getpath filename =
4295 if nonemptystr
filename
4297 if Filename.is_relative
filename
4299 let dir = Filename.dirname state
.path in
4301 if Filename.is_implicit
dir
4302 then Filename.concat
(Sys.getcwd
()) dir
4305 Filename.concat
dir filename
4309 if Sys.file_exists
path
4313 let path = getpath filename in
4317 let cmd = Lazy.force_val lcmd
in
4318 match spawn
cmd with
4320 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4322 let anchor = getanchor
() in
4323 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4324 state
.origin
<- E.s;
4325 state
.ranchors
<- ranchor :: state
.ranchors
;
4328 if substratis spec
0 "page="
4330 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4332 state
.anchor <- (pageno, 0.0, 0.0);
4333 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4335 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4337 state
.nameddest
<- dest
;
4338 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4342 let gotounder = function
4343 | Ulinkuri
s when isexternallink
s ->
4344 if substratis
s 0 "file://"
4345 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4348 let pageno, x, y = uritolocation
s in
4350 gotopagexy !wtmode pageno x y
4351 | Utext
_ | Unone
-> ()
4352 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4355 let gotooutline (_, _, kind
) =
4359 let (pageno, y, _) = anchor in
4361 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4365 | Ouri
uri -> gotounder (Ulinkuri
uri)
4366 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4367 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4368 | Ohistory hist
-> gotohist hist
4369 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4372 class outlinesoucebase fetchoutlines
= object (self)
4373 inherit lvsourcebase
4374 val mutable m_items
= E.a
4375 val mutable m_minfo
= E.a
4376 val mutable m_orig_items
= E.a
4377 val mutable m_orig_minfo
= E.a
4378 val mutable m_narrow_patterns
= []
4379 val mutable m_gen
= -1
4381 method getitemcount
= Array.length m_items
4384 let s, n, _ = m_items
.(n) in
4387 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4388 ignore
(uioh, first);
4390 if m_narrow_patterns
= []
4391 then m_orig_items
, m_orig_minfo
4392 else m_items
, m_minfo
4399 gotooutline m_items
.(active);
4407 method hasaction
(_:int) = true
4410 if Array.length m_items
!= Array.length m_orig_items
4413 match m_narrow_patterns
with
4415 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4417 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4421 match m_narrow_patterns
with
4424 | head
:: _ -> UniSyms.ellipsis ^ head
4426 method narrow
pattern =
4427 match Str.regexp_case_fold
pattern with
4430 let rec loop accu minfo n =
4433 m_items
<- Array.of_list
accu;
4434 m_minfo
<- Array.of_list
minfo;
4437 let (s, _, _) as o = m_items
.(n) in
4439 match Str.search_forward re
s 0 with
4440 | exception Not_found
-> accu, minfo
4441 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4443 loop accu minfo (n-1)
4445 loop [] [] (Array.length m_items
- 1)
4447 method! getminfo
= m_minfo
4450 m_orig_items
<- fetchoutlines
();
4451 m_minfo
<- m_orig_minfo
;
4452 m_items
<- m_orig_items
4454 method add_narrow_pattern
pattern =
4455 m_narrow_patterns
<- pattern :: m_narrow_patterns
4457 method del_narrow_pattern
=
4458 match m_narrow_patterns
with
4459 | _ :: rest
-> m_narrow_patterns
<- rest
4464 match m_narrow_patterns
with
4465 | pattern :: [] -> self#narrow
pattern; pattern
4467 List.fold_left
(fun accu pattern ->
4468 self#narrow
pattern;
4469 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4471 method calcactive
(_:anchor) = 0
4473 method reset
anchor items =
4474 if state
.gen
!= m_gen
4476 m_orig_items
<- items;
4478 m_narrow_patterns
<- [];
4480 m_orig_minfo
<- E.a;
4484 if items != m_orig_items
4486 m_orig_items
<- items;
4487 if m_narrow_patterns
== []
4488 then m_items
<- items;
4491 let active = self#calcactive
anchor in
4493 m_first
<- firstof m_first
active
4497 let outlinesource fetchoutlines
=
4499 inherit outlinesoucebase fetchoutlines
4500 method! calcactive
anchor =
4501 let rely = getanchory anchor in
4502 let rec loop n best bestd
=
4503 if n = Array.length m_items
4506 let _, _, kind
= m_items
.(n) in
4509 let orely = getanchory anchor in
4510 let d = abs
(orely - rely) in
4513 else loop (n+1) best bestd
4514 | Onone
| Oremote
_ | Olaunch
_
4515 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4516 loop (n+1) best bestd
4522 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4523 let mkselector sourcetype
=
4524 let fetchoutlines () =
4525 match sourcetype
with
4526 | `bookmarks
-> Array.of_list state
.bookmarks
4527 | `outlines
-> state
.outlines
4528 | `history
-> genhistoutlines () |> Array.of_list
4531 if sourcetype
= `history
4532 then new outlinesoucebase
fetchoutlines
4533 else outlinesource fetchoutlines
4536 let outlines = fetchoutlines () in
4537 if Array.length
outlines = 0
4538 then showtext ' ' errmsg
4541 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4542 let anchor = getanchor
() in
4543 source#reset
anchor outlines;
4544 state
.text <- source#greetmsg
;
4546 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4547 G.postRedisplay "enter selector";
4551 let mkenter sourcetype errmsg
=
4552 let enter = mkselector sourcetype
in
4553 fun () -> enter errmsg
4555 ( mkenter `
outlines "document has no outline"
4556 , mkenter `bookmarks
"document has no bookmarks (yet)"
4557 , mkenter `history
"history is empty" )
4560 let quickbookmark ?title
() =
4561 match state
.layout with
4568 let tm = localtime
(now
()) in
4570 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4572 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4574 | Some
title -> title
4576 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4579 let setautoscrollspeed step goingdown
=
4580 let incr = max
1 ((abs step
) / 2) in
4581 let incr = if goingdown
then incr else -incr in
4582 let astep = boundastep state
.winh
(step
+ incr) in
4583 state
.autoscroll
<- Some
astep;
4587 match conf
.columns
with
4589 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4592 let panbound x = bound
x (-state
.w) state
.winw
;;
4594 let existsinrow pageno (columns
, coverA
, coverB
) p =
4595 let last = ((pageno - coverA
) mod columns
) + columns
in
4596 let rec any = function
4599 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4603 then (if l.pageno = last then false else any rest
)
4611 match state
.layout with
4613 let pageno = page_of_y state
.y in
4614 gotoghyll (getpagey
(pageno+1))
4616 match conf
.columns
with
4618 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4620 let y = clamp (pgscale state
.winh
) in
4623 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4624 gotoghyll (getpagey
pageno)
4625 | Cmulti
((c, _, _) as cl
, _) ->
4626 if conf
.presentation
4627 && (existsinrow l.pageno cl
4628 (fun l -> l.pageh
> l.pagey + l.pagevh))
4630 let y = clamp (pgscale state
.winh
) in
4633 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4634 gotoghyll (getpagey
pageno)
4636 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4638 let pagey, pageh
= getpageyh
l.pageno in
4639 let pagey = pagey + pageh
* l.pagecol
in
4640 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4641 gotoghyll (pagey + pageh
+ ips)
4645 match state
.layout with
4647 let pageno = page_of_y state
.y in
4648 gotoghyll (getpagey
(pageno-1))
4650 match conf
.columns
with
4652 if conf
.presentation
&& l.pagey != 0
4654 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4656 let pageno = max
0 (l.pageno-1) in
4657 gotoghyll (getpagey
pageno)
4658 | Cmulti
((c, _, coverB
) as cl
, _) ->
4659 if conf
.presentation
&&
4660 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4662 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4665 if l.pageno = state
.pagecount
- coverB
4669 let pageno = max
0 (l.pageno-decr) in
4670 gotoghyll (getpagey
pageno)
4678 let pageno = max
0 (l.pageno-1) in
4679 let pagey, pageh
= getpageyh
pageno in
4682 let pagey, pageh
= getpageyh
l.pageno in
4683 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4689 if emptystr conf
.savecmd
4690 then adderrmsg "savepath-command is empty"
4691 "don't know where to save modified document"
4693 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4697 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
4702 let tmp = path ^
".tmp" in
4704 Unix.rename
tmp path;
4707 let viewkeyboard key mask
=
4709 let mode = state
.mode in
4710 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4713 G.postRedisplay "view:enttext"
4715 let ctrl = Wsi.withctrl mask
in
4717 match Wsi.kc2kt
key with
4718 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
4720 | Ascii 'Q'
-> exit
0
4723 if hasunsavedchanges
()
4727 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4730 match state
.lnava
with
4731 | None
-> LinkNav
(Ltgendir
0)
4732 | Some
pn -> LinkNav
(Ltexact
pn)
4734 gotoxy state
.x state
.y;
4736 else impmsg "keyboard link navigation does not work under rotation"
4738 | Escape
| Ascii 'q'
->
4739 begin match state
.mstate
with
4742 G.postRedisplay "kill rect";
4745 | Mscrolly
| Mscrollx
4748 begin match state
.mode with
4751 | Ltexact pl
-> state
.lnava
<- Some pl
4752 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4755 G.postRedisplay "esc leave linknav"
4756 | Birdseye
_ | Textentry
_ | View
->
4757 match state
.ranchors
with
4759 | (path, password, anchor, origin
) :: rest
->
4760 state
.ranchors
<- rest
;
4761 state
.anchor <- anchor;
4762 state
.origin
<- origin
;
4763 state
.nameddest
<- E.s;
4764 opendoc path password
4770 gotoghyll (getnav ~
-1)
4781 Hashtbl.iter
(fun _ opaque ->
4783 Hashtbl.clear state
.prects
) state
.pagemap
;
4784 G.postRedisplay "dehighlight";
4786 | Ascii
(('
/'
| '?'
) as c) ->
4787 let ondone isforw
s =
4788 cbput state
.hists
.pat
s;
4789 state
.searchpattern
<- s;
4792 let s = String.make
1 c in
4793 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4794 textentry
, ondone (c = '
/'
), true)
4796 | Ascii '
+'
| Ascii '
='
when ctrl ->
4797 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4798 pivotzoom (conf
.zoom +. incr)
4803 try int_of_string
s with exn
->
4805 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4811 state
.text <- "page bias is now " ^ string_of_int
n;
4814 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4816 | Ascii '
-'
when ctrl ->
4817 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4818 pivotzoom (max
0.01 (conf
.zoom -. decr))
4821 let ondone msg
= state
.text <- msg
in
4823 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4824 optentry state
.mode, ondone, true
4827 | Ascii '
0'
when ctrl ->
4829 then gotoxy 0 state
.y
4832 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4834 match conf
.columns
with
4835 | Csingle
_ | Cmulti
_ -> 1
4836 | Csplit
(n, _) -> n
4838 let h = state
.winh
-
4839 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4841 let zoom = zoomforh state
.winw
h 0 cols in
4842 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4845 | Ascii '
3'
when ctrl ->
4847 match conf
.fitmodel
with
4848 | FitWidth
-> FitProportional
4849 | FitProportional
-> FitPage
4850 | FitPage
-> FitWidth
4852 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4853 reqlayout conf
.angle
fm
4855 | Ascii '
4'
when ctrl ->
4856 let zoom = getmaxw
() /. float state
.winw
in
4857 if zoom > 0.0 then setzoom zoom
4862 | Ascii '
9'
when ctrl ->
4865 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
4868 try int_of_string
s with exn
->
4869 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4875 cbput state
.hists
.pag
(string_of_int
n);
4876 gotopage1 (n + conf
.pagebias
- 1) 0;
4879 let [@warning
"-4"] pageentry
text = function
4880 | Keys.Ascii '
g'
-> TEdone
text
4881 | key -> intentry
text key
4883 let text = String.make
1 c in
4884 enttext (":", text, Some
(onhist state
.hists
.pag
),
4885 pageentry
, ondone, true)
4888 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4889 G.postRedisplay "toggle scrollbar";
4892 state
.bzoom
<- not state
.bzoom
;
4894 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4897 conf
.hlinks
<- not conf
.hlinks
;
4898 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4899 G.postRedisplay "toggle highlightlinks";
4902 if conf
.angle
mod 360 = 0
4904 state
.glinks
<- true;
4905 let mode = state
.mode in
4908 (":", E.s, None
, linknentry
, linknact gotounder, false),
4910 state
.glinks
<- false;
4914 G.postRedisplay "view:linkent(F)"
4916 else impmsg "hint mode does not work under rotation"
4919 state
.glinks
<- true;
4920 let mode = state
.mode in
4923 (":", E.s, None
, linknentry
,
4924 linknact (fun under -> selstring (undertext under)), false),
4926 state
.glinks
<- false;
4930 G.postRedisplay "view:linkent"
4933 begin match state
.autoscroll
with
4935 conf
.autoscrollstep
<- step
;
4936 state
.autoscroll
<- None
4938 state
.autoscroll
<- Some conf
.autoscrollstep
;
4939 state
.slideshow
<- state
.slideshow
land lnot
2
4942 | Ascii '
p'
when ctrl ->
4943 launchpath () (* XXX where do error messages go? *)
4946 setpresentationmode (not conf
.presentation
);
4947 showtext ' '
("presentation mode " ^
4948 if conf
.presentation
then "on" else "off");
4951 if List.mem
Wsi.Fullscreen state
.winstate
4952 then Wsi.reshape conf
.cwinw conf
.cwinh
4953 else Wsi.fullscreen
()
4955 | Ascii
('
p'
|'N'
) ->
4956 search state
.searchpattern
false
4958 | Ascii '
n'
| Fn
3 ->
4959 search state
.searchpattern
true
4962 begin match state
.layout with
4965 gotoghyll (getpagey
l.pageno)
4975 showtext ' '
(describe_layout state
.layout);
4978 begin match state
.layout with
4981 Wsi.reshape l.pagew
l.pageh
;
4986 enterbookmarkmode
()
4988 | Ascii '
h'
| Fn
1 ->
4994 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4999 match state
.layout with
5004 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
5007 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
5011 showtext ' '
"Quick bookmark added";
5014 begin match state
.layout with
5016 let rect = getpdimrect
l.pagedimno
in
5020 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5021 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5023 (truncate
(rect.(1) -. rect.(0)),
5024 truncate
(rect.(3) -. rect.(0)))
5026 let w = truncate
((float w)*.conf
.zoom)
5027 and h = truncate
((float h)*.conf
.zoom) in
5030 state
.anchor <- getanchor
();
5031 Wsi.reshape w (h + conf
.interpagespace
)
5033 G.postRedisplay "z";
5038 | Ascii '
x'
-> state
.roam
()
5040 | Ascii
('
<'
|'
>'
as c) ->
5042 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5044 | Ascii
('
['
|'
]'
as c) ->
5046 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
5047 G.postRedisplay "brightness";
5049 | Ascii '
c'
when state
.mode = View
->
5054 let m = (state
.winw
- state
.w) / 2 in
5055 gotoxy_and_clear_text m state
.y
5059 match state
.prevcolumns
with
5060 | None
-> (1, 0, 0), 1.0
5061 | Some
(columns
, z
) ->
5064 | Csplit
(c, _) -> -c, 0, 0
5065 | Cmulti
((c, a, b), _) -> c, a, b
5066 | Csingle
_ -> 1, 0, 0
5070 setcolumns View
c a b;
5073 | Down
| Up
when ctrl && Wsi.withshift mask
->
5074 let zoom, x = state
.prevzoom
in
5079 begin match state
.autoscroll
with
5081 begin match state
.mode with
5082 | Birdseye beye
-> upbirdseye 1 beye
5083 | Textentry
_ | View
| LinkNav
_ ->
5085 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5087 if not
(Wsi.withshift mask
) && conf
.presentation
5089 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5093 setautoscrollspeed n false
5096 | Ascii 'j'
| Down
->
5097 begin match state
.autoscroll
with
5099 begin match state
.mode with
5100 | Birdseye beye
-> downbirdseye 1 beye
5101 | Textentry
_ | View
| LinkNav
_ ->
5103 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5105 if not
(Wsi.withshift mask
) && conf
.presentation
5107 else gotoghyll1 true (clamp (conf
.scrollstep
))
5111 setautoscrollspeed n true
5114 | Left
| Right
when not
(Wsi.withalt mask
) ->
5120 else conf
.hscrollstep
5123 let pv = Wsi.kc2kt
key in
5124 if pv = Keys.Left
then dx else -dx
5126 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5129 G.postRedisplay "left/right"
5136 match state
.layout with
5138 | l :: _ -> state
.y - l.pagey
5140 clamp (pgscale (-state
.winh
))
5148 match List.rev state
.layout with
5150 | l :: _ -> getpagey
l.pageno
5152 clamp (pgscale state
.winh
)
5156 | Ascii '
g'
| Home
->
5159 | Ascii 'G'
| End
->
5161 gotoghyll (clamp state
.maxy)
5163 | Right
when Wsi.withalt mask
->
5165 gotoghyll (getnav 1)
5166 | Left
when Wsi.withalt mask
->
5168 gotoghyll (getnav ~
-1)
5173 | Ascii '
v'
when conf
.debug
->
5176 match getopaque l.pageno with
5179 let x0, y0, x1, y1 = pagebbox
opaque in
5180 let rect = (float x0, float y0,
5183 float x0, float y1) in
5185 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5186 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5188 G.postRedisplay "v";
5191 let mode = state
.mode in
5192 let cmd = ref E.s in
5193 let onleave = function
5194 | Cancel
-> state
.mode <- mode
5197 match getopaque l.pageno with
5198 | Some
opaque -> pipesel opaque !cmd
5199 | None
-> ()) state
.layout;
5203 cbput state
.hists
.sel
s;
5207 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
5209 G.postRedisplay "|";
5210 state
.mode <- Textentry
(te, onleave);
5212 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
5213 vlog "huh? %s" (Wsi.keyname
key)
5216 let linknavkeyboard key mask
linknav =
5217 let pv = Wsi.kc2kt
key in
5218 let getpage pageno =
5219 let rec loop = function
5221 | l :: _ when l.pageno = pageno -> Some
l
5222 | _ :: rest
-> loop rest
5223 in loop state
.layout
5225 let doexact (pageno, n) =
5226 match getopaque pageno, getpage pageno with
5227 | Some
opaque, Some
l ->
5230 let under = getlink
opaque n in
5231 G.postRedisplay "link gotounder";
5238 | Home
-> Some
(findlink
opaque LDfirst
), -1
5239 | End
-> Some
(findlink
opaque LDlast
), 1
5240 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
5241 | Right
-> Some
(findlink
opaque (LDright
n)), 1
5242 | Up
-> Some
(findlink
opaque (LDup
n)), -1
5243 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
5245 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
5246 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
5249 begin match findpwl
l.pageno dir with
5253 state
.mode <- LinkNav
(Ltgendir
dir);
5254 let y, h = getpageyh
pageno in
5257 then y + h - state
.winh
5262 begin match getopaque pageno, getpage pageno with
5263 | Some
opaque, Some
_ ->
5265 let ld = if dir > 0 then LDfirst
else LDlast
in
5268 begin match link with
5270 showlinktype (getlink
opaque m);
5271 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5272 G.postRedisplay "linknav jpage";
5273 | Lnotfound
-> notfound dir
5279 begin match opt with
5280 | Some Lnotfound
-> pwl l dir;
5281 | Some
(Lfound
m) ->
5285 let _, y0, _, y1 = getlinkrect
opaque m in
5287 then gotopage1 l.pageno y0
5289 let d = fstate
.fontsize
+ 1 in
5290 if y1 - l.pagey > l.pagevh - d
5291 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5292 else G.postRedisplay "linknav";
5294 showlinktype (getlink
opaque m);
5295 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5298 | None
-> viewkeyboard key mask
5300 | _ -> viewkeyboard key mask
5304 begin match linknav with
5305 | Ltexact pa
-> state
.lnava
<- Some pa
5306 | Ltgendir
_ | Ltnotready
_ -> ()
5309 G.postRedisplay "leave linknav"
5313 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5314 | Ltexact exact
-> doexact exact
5317 let keyboard key mask
=
5318 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5319 then wcmd "interrupt"
5320 else state
.uioh <- state
.uioh#
key key mask
5323 let birdseyekeyboard key mask
5324 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5326 match conf
.columns
with
5328 | Cmulti
((c, _, _), _) -> c
5329 | Csplit
_ -> failwith
"bird's eye split mode"
5331 let pgh layout = List.fold_left
5332 (fun m l -> max
l.pageh
m) state
.winh
layout in
5334 match Wsi.kc2kt
key with
5335 | Ascii '
l'
when Wsi.withctrl mask
->
5336 let y, h = getpageyh
pageno in
5337 let top = (state
.winh
- h) / 2 in
5338 gotoxy state
.x (max
0 (y - top))
5339 | Enter
-> leavebirdseye beye
false
5340 | Escape
-> leavebirdseye beye
true
5341 | Up
-> upbirdseye incr beye
5342 | Down
-> downbirdseye incr beye
5343 | Left
-> upbirdseye 1 beye
5344 | Right
-> downbirdseye 1 beye
5347 begin match state
.layout with
5351 state
.mode <- Birdseye
(
5352 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5354 gotopage1 l.pageno 0;
5357 let layout = layout state
.x (state
.y-state
.winh
)
5359 (pgh state
.layout) in
5361 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5363 state
.mode <- Birdseye
(
5364 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5366 gotopage1 l.pageno 0
5369 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5373 begin match List.rev state
.layout with
5375 let layout = layout state
.x
5376 (state
.y + (pgh state
.layout))
5377 state
.winw state
.winh
in
5378 begin match layout with
5380 let incr = l.pageh
- l.pagevh in
5385 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5387 G.postRedisplay "birdseye pagedown";
5389 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5393 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5394 gotopage1 l.pageno 0;
5397 | [] -> gotoxy state
.x (clamp state
.winh
)
5401 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5405 let pageno = state
.pagecount
- 1 in
5406 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5407 if not
(pagevisible state
.layout pageno)
5410 match List.rev state
.pdims
with
5412 | (_, _, h, _) :: _ -> h
5416 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5417 else G.postRedisplay "birdseye end";
5419 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
5424 match state
.mode with
5425 | Textentry
_ -> scalecolor 0.4
5426 | LinkNav
_ | View
-> scalecolor 1.0
5427 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5428 if l.pageno = hooverpageno
5431 if l.pageno = pageno
5433 let c = scalecolor 1.0 in
5435 GlDraw.line_width
3.0;
5436 let dispx = l.pagedispx in
5438 (float (dispx-1)) (float (l.pagedispy-1))
5439 (float (dispx+l.pagevw+1))
5440 (float (l.pagedispy+l.pagevh+1))
5442 GlDraw.line_width
1.0;
5451 let postdrawpage l linkindexbase
=
5452 match getopaque l.pageno with
5454 if tileready l l.pagex
l.pagey
5456 let x = l.pagedispx - l.pagex
5457 and y = l.pagedispy - l.pagey in
5459 match conf
.columns
with
5460 | Csingle
_ | Cmulti
_ ->
5461 (if conf
.hlinks
then 1 else 0)
5463 && not
(isbirdseye state
.mode) then 2 else 0)
5467 match state
.mode with
5468 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5474 Hashtbl.find_all state
.prects
l.pageno |>
5475 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5476 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5478 then (state
.redisplay
<- true; 0)
5484 let scrollindicator () =
5485 let sbw, ph
, sh = state
.uioh#
scrollph in
5486 let sbh, pw, sw = state
.uioh#scrollpw
in
5491 else ((state
.winw
- sbw), state
.winw
, 0)
5495 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5496 let (r
, g, b, alpha) = conf
.sbarcolor
in
5497 GlDraw.color (r
, g, b) ~
alpha;
5498 filledrect (float x0) 0. (float x1) (float state
.winh
);
5500 (float hx0
) (float (state
.winh
- sbh))
5501 (float (hx0
+ state
.winw
)) (float state
.winh
);
5502 let (r
, g, b, alpha) = conf
.sbarhndlcolor
in
5503 GlDraw.color (r
, g, b) ~
alpha;
5505 filledrect (float x0) ph
(float x1) (ph
+. sh);
5506 let pw = pw +. float hx0
in
5507 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5512 match state
.mstate
with
5513 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5516 | Msel
((x0, y0), (x1, y1)) ->
5517 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5518 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5519 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5520 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5527 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5528 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5530 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5532 if l.pageno = pageno
5534 let dx = float (l.pagedispx - l.pagex
) in
5535 let dy = float (l.pagedispy - l.pagey) in
5536 let r, g, b, alpha = c in
5537 GlDraw.color (r, g, b) ~
alpha;
5538 filledrect2 (x0+.dx) (y0+.dy)
5549 GlDraw.color (scalecolor2 conf
.bgcolor
);
5550 GlClear.color (scalecolor2 conf
.bgcolor
);
5551 GlClear.clear
[`
color];
5552 List.iter
drawpage state
.layout;
5554 match state
.mode with
5555 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5556 begin match getopaque pageno with
5558 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5559 let color = (0.0, 0.0, 0.5, 0.5) in
5561 (float x0, float y0,
5566 | None
-> state
.rects
5568 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5571 | View
-> state
.rects
5574 let rec postloop linkindexbase
= function
5576 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5577 postloop linkindexbase rest
5581 postloop 0 state
.layout;
5583 begin match state
.mstate
with
5584 | Mzoomrect
((x0, y0), (x1, y1)) ->
5586 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5587 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5588 filledrect (float x0) (float y0) (float x1) (float y1);
5592 | Mscrolly
| Mscrollx
5601 let zoomrect x y x1 y1 =
5604 and y0 = min
y y1 in
5605 let zoom = (float state
.w) /. float (x1 - x0) in
5608 if state
.w < state
.winw
5609 then (state
.winw
- state
.w) / 2
5612 match conf
.fitmodel
with
5613 | FitWidth
| FitProportional
-> simple ()
5615 match conf
.columns
with
5617 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5618 | Cmulti
_ | Csingle
_ -> simple ()
5620 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5621 state
.anchor <- getanchor
();
5626 let annot inline
x y =
5627 match unproject x y with
5628 | Some
(opaque, n, ux
, uy
) ->
5630 addannot
opaque ux uy
text;
5631 wcmd "freepage %s" (~
> opaque);
5632 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5634 gotoxy state
.x state
.y
5638 let ondone s = add s in
5639 let mode = state
.mode in
5640 state
.mode <- Textentry
(
5641 ("annotation: ", E.s, None
, textentry
, ondone, true),
5642 fun _ -> state
.mode <- mode);
5645 G.postRedisplay "annot"
5647 add @@ getusertext E.s
5652 let g opaque l px py =
5653 match rectofblock
opaque px py with
5655 let x0 = a.(0) -. 20. in
5656 let x1 = a.(1) +. 20. in
5657 let y0 = a.(2) -. 20. in
5658 let zoom = (float state
.w) /. (x1 -. x0) in
5659 let pagey = getpagey
l.pageno in
5660 let margin = (state
.w - l.pagew
)/2 in
5661 let nx = -truncate
x0 - margin in
5662 gotoxy_and_clear_text nx (pagey + truncate
y0);
5663 state
.anchor <- getanchor
();
5668 match conf
.columns
with
5670 impmsg "block zooming does not work properly in split columns mode"
5671 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5675 let winw = state
.winw - 1 in
5676 let s = float x /. float winw in
5677 let destx = truncate
(float (state
.w + winw) *. s) in
5678 gotoxy_and_clear_text (winw - destx) state
.y;
5679 state
.mstate
<- Mscrollx
;
5683 let s = float y /. float state
.winh
in
5684 let desty = truncate
(s *. float (maxy ())) in
5685 gotoxy_and_clear_text state
.x desty;
5686 state
.mstate
<- Mscrolly
;
5689 let viewmulticlick clicks
x y mask
=
5690 let g opaque l px py =
5698 if markunder
opaque px py mark
5702 match getopaque l.pageno with
5704 | Some
opaque -> pipesel opaque cmd
5706 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5707 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5712 G.postRedisplay "viewmulticlick";
5713 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5717 match conf
.columns
with
5719 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5722 let viewmouse button down
x y mask
=
5724 | n when (n == 4 || n == 5) && not down
->
5725 if Wsi.withctrl mask
5729 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5730 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5733 match state
.mstate
with
5734 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
5735 | Mzoomrect
_ | Mnone
| Mpan
_
5736 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
5738 let zoom = conf
.zoom -. incr in
5739 state
.mstate
<- Mzoom
(n, 0, (x, y));
5740 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
5741 then pivotzoom ~
x ~
y zoom
5745 match state
.autoscroll
with
5746 | Some step
-> setautoscrollspeed step
(n=4)
5748 if conf
.wheelbypage
|| conf
.presentation
5757 then -conf
.scrollstep
5758 else conf
.scrollstep
5760 let incr = incr * 2 in
5761 let y = clamp incr in
5762 gotoxy_and_clear_text state
.x y
5765 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5767 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5768 gotoxy_and_clear_text x state
.y
5770 | 1 when Wsi.withshift mask
->
5771 state
.mstate
<- Mnone
;
5774 match unproject x y with
5776 | Some
(_, pageno, ux
, uy
) ->
5777 let cmd = Printf.sprintf
5779 conf
.stcmd state
.path pageno ux uy
5781 match spawn
cmd [] with
5783 impmsg "execution of synctex command(%S) failed: %S"
5784 conf
.stcmd
@@ exntos exn
5788 | 1 when Wsi.withctrl mask
->
5791 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5792 state
.mstate
<- Mpan
(x, y)
5795 state
.mstate
<- Mnone
5800 if Wsi.withshift mask
5802 annot conf
.annotinline
x y;
5803 G.postRedisplay "addannot"
5807 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5808 state
.mstate
<- Mzoomrect
(p, p)
5811 match state
.mstate
with
5812 | Mzoomrect
((x0, y0), _) ->
5813 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5814 then zoomrect x0 y0 x y
5817 G.postRedisplay "kill accidental zoom rect";
5821 | Mscrolly
| Mscrollx
5823 | Mnone
-> resetmstate ()
5826 | 1 when vscrollhit x ->
5829 let _, position, sh = state
.uioh#
scrollph in
5830 if y > truncate
position && y < truncate
(position +. sh)
5831 then state
.mstate
<- Mscrolly
5834 state
.mstate
<- Mnone
5836 | 1 when y > state
.winh
- hscrollh () ->
5839 let _, position, sw = state
.uioh#scrollpw
in
5840 if x > truncate
position && x < truncate
(position +. sw)
5841 then state
.mstate
<- Mscrollx
5844 state
.mstate
<- Mnone
5846 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5849 let dest = if down
then getunder x y else Unone
in
5850 begin match dest with
5854 | Unone
when down
->
5855 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5856 state
.mstate
<- Mpan
(x, y);
5858 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5860 | Unone
| Utext
_ ->
5865 state
.mstate
<- Msel
((x, y), (x, y));
5866 G.postRedisplay "mouse select";
5870 match state
.mstate
with
5873 | Mzoom
_ | Mscrollx
| Mscrolly
->
5874 state
.mstate
<- Mnone
5876 | Mzoomrect
((x0, y0), _) ->
5880 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5881 state
.mstate
<- Mnone
5883 | Msel
((x0, y0), (x1, y1)) ->
5884 let rec loop = function
5888 let a0 = l.pagedispy in
5889 let a1 = a0 + l.pagevh in
5890 let b0 = l.pagedispx in
5891 let b1 = b0 + l.pagevw in
5892 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5893 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5897 match getopaque l.pageno with
5900 pipef ~closew
:false "Msel"
5903 G.postRedisplay "Msel") cmd
5905 dosel conf
.selcmd
();
5906 state
.roam
<- dosel conf
.paxcmd
;
5918 let birdseyemouse button down
x y mask
5919 (conf
, leftx
, _, hooverpageno
, anchor) =
5922 let rec loop = function
5925 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5926 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5928 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5934 | _ -> viewmouse button down
x y mask
5940 method key key mask
=
5941 begin match state
.mode with
5942 | Textentry textentry
-> textentrykeyboard
key mask textentry
5943 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5944 | View
-> viewkeyboard key mask
5945 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5949 method button button bstate
x y mask
=
5950 begin match state
.mode with
5951 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5952 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5957 method multiclick clicks
x y mask
=
5958 begin match state
.mode with
5959 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5960 | Birdseye
_ | Textentry
_ -> ()
5965 begin match state
.mode with
5967 | View
| Birdseye
_ | LinkNav
_ ->
5968 match state
.mstate
with
5969 | Mzoom
_ | Mnone
-> ()
5974 state
.mstate
<- Mpan
(x, y);
5975 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5977 gotoxy_and_clear_text x y
5980 state
.mstate
<- Msel
(a, (x, y));
5981 G.postRedisplay "motion select";
5984 let y = min state
.winh
(max
0 y) in
5988 let x = min state
.winw (max
0 x) in
5991 | Mzoomrect
(p0
, _) ->
5992 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5993 G.postRedisplay "motion zoomrect";
5997 method pmotion
x y =
5998 begin match state
.mode with
5999 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6000 let rec loop = function
6002 if hooverpageno
!= -1
6004 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6005 G.postRedisplay "pmotion birdseye no hoover";
6008 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6009 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6011 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6012 G.postRedisplay "pmotion birdseye hoover";
6020 | LinkNav
_ | View
->
6021 match state
.mstate
with
6022 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6031 let delta = now -. past
in
6034 else conf
.pax
<- Some
now
6038 method infochanged
_ = ()
6041 let maxy = maxy () in
6044 then 0.0, float state
.winh
6045 else scrollph state
.y maxy
6050 let fwinw = float (state
.winw - vscrollw ()) in
6052 let sw = fwinw /. float state
.w in
6053 let sw = fwinw *. sw in
6054 max
sw (float conf
.scrollh
)
6057 let maxx = state
.w + state
.winw in
6058 let x = state
.winw - state
.x in
6059 let percent = float x /. float maxx in
6060 (fwinw -. sw) *. percent
6062 hscrollh (), position, sw
6066 match state
.mode with
6067 | LinkNav
_ -> "links"
6068 | Textentry
_ -> "textentry"
6069 | Birdseye
_ -> "birdseye"
6072 findkeyhash conf
modename
6074 method eformsgs
= true
6075 method alwaysscrolly
= false
6076 method scroll dx dy =
6077 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6078 gotoxy_and_clear_text x (clamp (2 * dy));
6081 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
6084 let addrect pageno r g b a x0 y0 x1 y1 =
6085 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6089 let cl = splitatchar cmds ' '
in
6091 try Scanf.sscanf
s fmt
f
6092 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6095 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6096 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6097 s pageno r g b a x0 y0 x1 y1;
6101 let _,w1,h1
,_ = getpagedim
pageno in
6102 let sw = float w1 /. float w
6103 and sh = float h1
/. float h in
6107 and y1s
= y1 *. sh in
6108 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6109 let color = (r, g, b, a) in
6110 if conf
.verbose
then debugrect rect;
6111 state
.rects <- (pageno, color, rect) :: state
.rects;
6116 | "reload", "" -> reload ()
6118 scan args
"%u %f %f"
6120 let cmd, _ = state
.geomcmds
in
6122 then gotopagexy !wtmode pageno x y
6125 gotopagexy !wtmode pageno x y;
6128 state
.reprf
<- f state
.reprf
6130 | "goto1", args
-> scan args
"%u %f" gotopage
6131 | "gotor", args
-> scan args
"%S" gotoremote
6133 scan args
"%u %u %f %f %f %f"
6134 (fun pageno c x0 y0 x1 y1 ->
6135 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6136 rectx "rect" pageno color x0 y0 x1 y1;
6139 scan args
"%u %f %f %f %f %f %f %f %f"
6140 (fun pageno r g b alpha x0 y0 x1 y1 ->
6141 addrect pageno r g b alpha x0 y0 x1 y1;
6142 G.postRedisplay "prect"
6145 scan args
"%u %f %f"
6148 match getopaque pageno with
6149 | Some
opaque -> opaque
6152 pgoto optopaque pageno x y;
6153 let rec fixx = function
6156 if l.pageno = pageno
6157 then gotoxy (state
.x - l.pagedispx) state
.y
6162 match conf
.columns
with
6163 | Csingle
_ | Csplit
_ -> 1
6164 | Cmulti
((n, _, _), _) -> n
6166 layout 0 state
.y (state
.winw * mult) state
.winh
6170 | "activatewin", "" -> Wsi.activatewin
()
6171 | "quit", "" -> raise Quit
6174 let l = Config.keys_of_string
keys in
6175 List.iter
(fun (k
, m) -> keyboard k
m) l
6176 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6179 | "clearrects", "" ->
6180 Hashtbl.clear state
.prects
;
6181 G.postRedisplay "clearrects"
6183 adderrfmt "remote command"
6184 "error processing remote command: %S\n" cmds
;
6188 let scratch = Bytes.create
80 in
6189 let buf = Buffer.create
80 in
6191 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6192 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6195 if Buffer.length
buf > 0
6197 let s = Buffer.contents
buf in
6205 match Bytes.index_from
scratch ppos '
\n'
with
6206 | pos
-> if pos
>= n then -1 else pos
6207 | exception Not_found
-> -1
6211 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6212 let s = Buffer.contents
buf in
6218 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6224 let remoteopen path =
6225 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6227 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6232 let gcconfig = ref false in
6233 let trimcachepath = ref E.s in
6234 let rcmdpath = ref E.s in
6235 let pageno = ref None
in
6236 let rootwid = ref 0 in
6237 let openlast = ref false in
6238 let doreap = ref false in
6239 let csspath = ref None
in
6240 selfexec := Sys.executable_name
;
6243 [("-p", Arg.String
(fun s -> state
.password <- s),
6244 "<password> Set password");
6248 Config.fontpath
:= s;
6249 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6251 "<path> Set path to the user interface font");
6255 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6256 Config.confpath
:= s),
6257 "<path> Set path to the configuration file");
6259 ("-last", Arg.Set
openlast, " Open last document");
6261 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6262 "<page-number> Jump to page");
6264 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6265 "<path> Set path to the trim cache file");
6267 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6268 "<named-destination> Set named destination");
6270 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6271 ("-cxack", Arg.Set
cxack, " Cut corners");
6273 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6274 "<path> Set path to the source of remote commands");
6276 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
6278 ("-v", Arg.Unit
(fun () ->
6280 "%s\nconfiguration path: %s\n"
6283 exit
0), " Print version and exit");
6285 ("-css", Arg.String
(fun s -> csspath := Some
s),
6286 "<path> Set path to the style sheet to use with EPUB/HTML");
6288 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6290 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6291 "<origin> <undocumented>");
6293 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title")
6296 (fun s -> state
.path <- s)
6297 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6300 then selfexec := !selfexec ^
" -wtmode";
6302 let histmode = emptystr state
.path && not
!openlast in
6304 if not
(Config.load !openlast)
6305 then dolog
"failed to load configuration";
6307 begin match !pageno with
6308 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6321 val mutable m_clicks
= 0
6322 val mutable m_click_x
= 0
6323 val mutable m_click_y
= 0
6324 val mutable m_lastclicktime
= infinity
6326 method private cleanup =
6327 state
.roam
<- noroam
;
6328 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6329 method expose
= G.postRedisplay "expose"
6333 | Wsi.Unobscured
-> "unobscured"
6334 | Wsi.PartiallyObscured
-> "partiallyobscured"
6335 | Wsi.FullyObscured
-> "fullyobscured"
6337 vlog "visibility change %s" name
6338 method display = display ()
6339 method map mapped
= vlog "mapped %b" mapped
6340 method reshape w h =
6343 method mouse
b d x y m =
6344 if d && canselect ()
6347 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6354 if abs
x - m_click_x
> 10
6355 || abs
y - m_click_y
> 10
6356 || abs_float
(t -. m_lastclicktime
) > 0.3
6358 m_clicks
<- m_clicks
+ 1;
6359 m_lastclicktime
<- t;
6363 G.postRedisplay "cleanup";
6364 state
.uioh <- state
.uioh#button
b d x y m;
6366 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6371 m_lastclicktime
<- infinity
;
6372 state
.uioh <- state
.uioh#button
b d x y m
6376 state
.uioh <- state
.uioh#button
b d x y m
6379 state
.mpos
<- (x, y);
6380 state
.uioh <- state
.uioh#motion
x y
6381 method pmotion
x y =
6382 state
.mpos
<- (x, y);
6383 state
.uioh <- state
.uioh#pmotion
x y
6385 vlog "k=%#x m=%#x" k
m;
6386 let mascm = m land (
6387 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6390 let x = state
.x and y = state
.y in
6392 if x != state
.x || y != state
.y then self#
cleanup
6394 match state
.keystate
with
6396 let km = k
, mascm in
6399 let modehash = state
.uioh#
modehash in
6400 try Hashtbl.find modehash km
6402 try Hashtbl.find (findkeyhash conf
"global") km
6403 with Not_found
-> KMinsrt
(k
, m)
6405 | KMinsrt
(k
, m) -> keyboard k
m
6406 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6407 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6409 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6410 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6411 state
.keystate
<- KSnone
6412 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6413 state
.keystate
<- KSinto
(keys, insrt
)
6414 | KSinto
_ -> state
.keystate
<- KSnone
6417 state
.mpos
<- (x, y);
6418 state
.uioh <- state
.uioh#pmotion
x y
6419 method leave = state
.mpos
<- (-1, -1)
6420 method winstate wsl
= state
.winstate
<- wsl
6421 method quit
: '
a. '
a = raise Quit
6422 method scroll dx dy = state
.uioh <- state
.uioh#
scroll dx dy
6423 method zoom z
x y = state
.uioh#
zoom z
x y
6424 method opendoc path =
6427 G.postRedisplay "opendoc";
6428 opendoc path state
.password
6431 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6434 if not
@@ List.exists
GlMisc.check_extension
6435 [ "GL_ARB_texture_rectangle"
6436 ; "GL_EXT_texture_recangle"
6437 ; "GL_NV_texture_rectangle" ]
6438 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6440 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6442 defconf
.sliceheight
<- 1024;
6443 defconf
.texcount
<- 32;
6444 defconf
.usepbo
<- true;
6448 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6450 dolog
"socketpair failed: %s" @@ exntos exn
;
6458 setcheckers conf
.checkers
;
6460 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6462 begin match !csspath with
6464 | Some
"" -> conf
.css
<- E.s
6466 let css = filecontents
path in
6467 let l = String.length
css in
6469 if substratis
css (l-2) "\r\n"
6470 then String.sub css 0 (l-2)
6471 else (if css.[l-1] = '
\n'
6472 then String.sub css 0 (l-1)
6476 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6477 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6478 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6480 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6482 reshape ~firsttime
:true winw winh
;
6486 Wsi.settitle
"llpp (history)";
6490 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6491 opendoc state
.path state
.password;
6495 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6496 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6499 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6500 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6501 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6503 | _pid
, _status
-> reap ()
6505 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6509 if nonemptystr
!rcmdpath
6510 then remoteopen !rcmdpath
6515 let rec loop deadline
=
6521 let r = [state
.ss; state
.wsfd] in
6525 | Some fd
-> fd
:: r
6529 state
.redisplay
<- false;
6536 if deadline
= infinity
6538 else max
0.0 (deadline
-. now)
6543 try Unix.select
r [] [] timeout
6544 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6550 if state
.ghyll
== noghyll
6552 match state
.autoscroll
with
6553 | Some step
when step
!= 0 ->
6554 if state
.slideshow
land 1 = 1
6556 if state
.slideshow
land 2 = 0
6557 then state
.slideshow
<- state
.slideshow
lor 2
6558 else if step
< 0 then prevpage () else nextpage ();
6559 deadline
+. (float (abs step
))
6562 let y = state
.y + step
in
6563 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6566 then state
.maxy - fy
6567 else if y >= state
.maxy - fy then 0 else y
6569 if state
.mode = View
6570 then gotoxy_and_clear_text state
.x y
6571 else gotoxy state
.x y;
6574 else deadline
+. 0.01
6579 let rec checkfds = function
6581 | fd
:: rest
when fd
= state
.ss ->
6582 let cmd = rcmd state
.ss in
6586 | fd
:: rest
when fd
= state
.wsfd ->
6590 | fd
:: rest
when Some fd
= !optrfd ->
6591 begin match remote fd
with
6592 | None
-> optrfd := remoteopen !rcmdpath;
6593 | opt -> optrfd := opt
6598 dolog
"select returned unknown descriptor";
6604 if deadline
= infinity
6608 match state
.autoscroll
with
6609 | Some step
when step
!= 0 -> deadline1
6610 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6615 match loop infinity
with
6617 Config.save leavebirdseye;
6618 if hasunsavedchanges
()
6620 | _ -> error
"umpossible - infinity reached"