6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
10 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
11 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
12 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
13 external clearmark
: opaque
-> unit = "ml_clearmark";;
14 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
15 external getmaxw
: unit -> float = "ml_getmaxw";;
16 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
17 external measurestr
: int -> string -> float = "ml_measure_string";;
18 external postprocess
:
19 opaque
-> int -> int -> int -> (int * string * int) -> int
21 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
22 external setaalevel
: int -> unit = "ml_setaalevel";;
23 external realloctexts
: int -> bool = "ml_realloctexts";;
24 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
25 external getlink
: opaque
-> int -> under
= "ml_getlink";;
26 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
27 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
28 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
29 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
30 external freepbo
: opaque
-> unit = "ml_freepbo";;
31 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
32 external bousable
: unit -> bool = "ml_bo_usable";;
33 external unproject
: opaque
-> int -> int -> (int * int) option
35 external project
: opaque
-> int -> int -> float -> float -> (float * float)
37 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
38 external rectofblock
: opaque
-> int -> int -> float array
option
40 external begintiles
: unit -> unit = "ml_begintiles";;
41 external endtiles
: unit -> unit = "ml_endtiles";;
42 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
43 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
44 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
45 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
46 external savedoc
: string -> unit = "ml_savedoc";;
47 external getannotcontents
: opaque
-> slinkindex
-> string
48 = "ml_getannotcontents";;
49 external drawprect
: opaque
-> int -> int -> float array
-> unit
51 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
52 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
53 external uritolocation
: string -> (pageno
* float * float)
54 = "ml_uritolocation";;
55 external isexternallink
: string -> bool = "ml_isexternallink";;
57 let selfexec = ref E.s
;;
58 let opengl_has_pbo = ref false;;
60 let drawstring size x y s
=
62 Gl.enable `texture_2d
;
63 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
64 ignore
(drawstr size x y s
);
66 Gl.disable `texture_2d
;
69 let drawstring1 size x y s
=
73 let drawstring2 size x y fmt
=
74 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
77 module UniSyms
= struct
78 let ellipsis = "\xe2\x80\xa6";;
79 let radical = "\xe2\x88\x9a";;
80 let lguillemet = "\xc2\xab";;
81 let rguillemet = "\xc2\xbb";;
96 l
.pagedispx l
.pagedispy
100 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
106 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
109 let isbirdseye = function
111 | Textentry _
| View
| LinkNav _
-> false
114 let istextentry = function
115 | Textentry _
-> true
116 | Birdseye _
| View
| LinkNav _
-> false
119 let wtmode = ref false;;
120 let cxack = ref false;;
122 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
125 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
126 && (state
.w
> state
.winw
))
132 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
133 && (state
.maxy
> state
.winh
))
141 else x
> state
.winw
- vscrollw ()
145 fstate
.fontsize
<- n
;
146 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
147 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
153 else Printf.kprintf ignore fmt
157 if emptystr conf
.pathlauncher
158 then dolog
"%s" state
.path
160 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
161 match spawn
command [] with
164 dolog
"failed to execute `%s': %s" command @@ exntos exn
170 let postRedisplay who
=
171 vlog "redisplay for [%S]" who
;
172 state
.redisplay
<- true;
176 let getopaque pageno
=
177 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
178 with Not_found
-> None
181 let pagetranslatepoint l x y
=
182 let dy = y
- l
.pagedispy
in
183 let y = dy + l
.pagey
in
184 let dx = x
- l
.pagedispx
in
185 let x = dx + l
.pagex
in
189 let onppundermouse g
x y d
=
192 begin match getopaque l
.pageno
with
194 let x0 = l
.pagedispx
in
195 let x1 = x0 + l
.pagevw
in
196 let y0 = l
.pagedispy
in
197 let y1 = y0 + l
.pagevh
in
198 if y >= y0 && y <= y1 && x >= x0 && x <= x1
200 let px, py
= pagetranslatepoint l
x y in
201 match g opaque l
px py
with
214 let g opaque l
px py
=
217 match rectofblock opaque
px py
with
218 | Some
[|x0;x1;y0;y1|] ->
219 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
220 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
221 state
.rects
<- [l
.pageno
, color, rect];
222 G.postRedisplay "getunder";
225 let under = whatsunder opaque
px py
in
226 if under = Unone
then None
else Some
under
228 onppundermouse g x y Unone
233 match unproject opaque
x y with
234 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
237 onppundermouse g x y None
;
241 state
.text
<- Printf.sprintf
"%c%s" c s
;
242 G.postRedisplay "showtext";
246 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
249 let pipesel opaque cmd
=
252 match Unix.pipe
() with
253 | exception exn
-> dolog
"pipesel cannot create pipe: %S" @@ exntos exn
;
255 let doclose what fd
=
256 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
258 begin match spawn cmd
[r
, 0; w
, -1] with
260 doclose "pipesel pipe/w" w
;
261 dolog
"cannot execute %S: %s" cmd
@@ exntos exn
264 G.postRedisplay "pipesel";
266 doclose "pipesel pipe/r" r
;
270 let g opaque l
px py
=
271 if markunder opaque
px py conf
.paxmark
274 match getopaque l
.pageno
with
276 | Some opaque
-> pipesel opaque conf
.paxcmd
281 G.postRedisplay "paxunder";
282 if conf
.paxmark
= Mark_page
285 match getopaque l
.pageno
with
287 | Some opaque
-> clearmark opaque
) state
.layout
;
288 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
292 match Unix.pipe
() with
293 | exception exn
-> impmsg "pipe failed: %s" @@ exntos exn
296 Ne.clo fd
(fun msg
-> impmsg "failed to close %s: %s" cap msg
)
298 begin match spawn conf
.selcmd
[r
, 0; w
, -1] with
300 clo "selstring pipe/w" w
;
301 impmsg "failed to execute %s: %s" conf
.selcmd
@@ exntos exn
304 let l = String.length s
in
305 let bytes = Bytes.unsafe_of_string s
in
306 let n = tempfailureretry
(Unix.write w
bytes 0) l in
308 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n
309 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
311 clo "selstring pipe/r" r
;
314 let undertext = function
317 | Utext s
-> "font: " ^ s
318 | Uannotation
(opaque
, slinkindex
) ->
319 "annotation: " ^ getannotcontents opaque slinkindex
322 let updateunder x y =
323 match getunder x y with
324 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
326 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
327 Wsi.setcursor
Wsi.CURSOR_INFO
329 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
330 Wsi.setcursor
Wsi.CURSOR_TEXT
332 if conf
.underinfo
then showtext 'a'
"nnotation";
333 Wsi.setcursor
Wsi.CURSOR_INFO
336 let showlinktype under =
337 if conf
.underinfo
&& under != Unone
338 then showtext ' '
@@ undertext under
341 let [@warning
"-4"] intentry_with_suffix text key
=
344 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
345 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
346 addchar
text @@ asciilower c
348 state
.text <- Printf.sprintf
"invalid key";
355 let b = Buffer.create
16 in
358 let b = Buffer.to_bytes
b in
359 wcmd state
.ss
b @@ Bytes.length
b
363 let nogeomcmds cmds
=
365 | s
, [] -> emptystr s
369 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
370 let rec fold accu
n =
371 if n = Array.length
b
374 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
377 || n = state
.pagecount
- coverB
378 || (n - coverA
) mod columns
= columns
- 1)
384 let pagey = max
0 (y - vy
) in
385 let pagedispy = if pagey > 0 then 0 else vy
- y in
386 let pagedispx, pagex
=
388 if n = coverA
- 1 || n = state
.pagecount
- coverB
389 then x + (sw
- w
) / 2
397 let vw = sw
- pagedispx in
398 let pw = w
- pagex
in
401 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
402 if pagevw > 0 && pagevh > 0
413 ; pagedispx = pagedispx
414 ; pagedispy = pagedispy
426 if Array.length
b = 0
428 else List.rev
(fold [] (page_of_y
y))
431 let layoutS (columns
, b) x y sw sh
=
432 let rec fold accu n =
433 if n = Array.length
b
436 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
444 let pagey = max
0 (y - vy
) in
445 let pagedispy = if pagey > 0 then 0 else vy
- y in
446 let pagedispx, pagex
=
460 let pagecolw = pagew
/columns
in
463 then pagedispx + ((sw
- pagecolw) / 2)
467 let vw = sw
- pagedispx in
468 let pw = pagew
- pagex
in
471 let pagevw = min
pagevw pagecolw in
472 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
473 if pagevw > 0 && pagevh > 0
484 ; pagedispx = pagedispx
485 ; pagedispy = pagedispy
486 ; pagecol
= n mod columns
500 let layout x y sw sh
=
501 if nogeomcmds state
.geomcmds
503 match conf
.columns
with
504 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
505 | Cmulti c
-> layoutN c
x y sw sh
506 | Csplit s
-> layoutS s
x y sw sh
511 let y = state
.y + incr
in
513 let y = min
y (state
.maxy
- (if conf
.maxhfit
then state
.winh
else 0)) in
518 let tilex = l.pagex
mod conf
.tilew
in
519 let tiley = l.pagey mod conf
.tileh
in
521 let col = l.pagex
/ conf
.tilew
in
522 let row = l.pagey / conf
.tileh
in
524 let rec rowloop row y0 dispy h
=
528 let dh = conf
.tileh
- y0 in
530 let rec colloop col x0 dispx w
=
534 let dw = conf
.tilew
- x0 in
536 f col row dispx dispy
x0 y0 dw dh;
537 colloop (col+1) 0 (dispx
+dw) (w
-dw)
540 colloop col tilex l.pagedispx l.pagevw;
541 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
544 if l.pagevw > 0 && l.pagevh > 0
545 then rowloop row tiley l.pagedispy l.pagevh;
548 let gettileopaque l col row =
550 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
552 try Some
(Hashtbl.find state
.tilemap
key)
553 with Not_found
-> None
556 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
557 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
558 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
561 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
562 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
563 GlArray.vertex `two state
.vraw
;
564 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
567 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
569 let filledrect x0 y0 x1 y1 =
570 GlArray.disable `texture_coord
;
571 filledrect1 x0 y0 x1 y1;
572 GlArray.enable `texture_coord
;
575 let linerect x0 y0 x1 y1 =
576 GlArray.disable `texture_coord
;
577 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
578 GlArray.vertex `two state
.vraw
;
579 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
580 GlArray.enable `texture_coord
;
583 let drawtiles l color =
586 let f col row x y tilex tiley w h
=
587 match gettileopaque l col row with
588 | Some
(opaque
, _
, t
) ->
589 let params = x, y, w
, h
, tilex, tiley in
591 then GlTex.env
(`mode `blend
);
592 drawtile
params opaque
;
594 then GlTex.env
(`mode `modulate
);
598 let s = Printf.sprintf
602 let w = measurestr fstate
.fontsize
s in
603 GlDraw.color (0.0, 0.0, 0.0);
604 filledrect (float (x-2))
607 (float (y + fstate
.fontsize
+ 2));
609 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
616 let lw = state
.winw
- x in
619 let lh = state
.winh
- y in
623 then GlTex.env
(`mode `blend
);
624 begin match state
.checkerstexid
with
626 Gl.enable `texture_2d
;
627 GlTex.bind_texture ~target
:`texture_2d id
;
631 and y1 = float (y+h
) in
633 let tw = float w /. 16.0
634 and th
= float h
/. 16.0 in
635 let tx0 = float tilex /. 16.0
636 and ty0
= float tiley /. 16.0 in
638 and ty1
= ty0
+. th
in
639 Raw.sets_float state
.vraw ~pos
:0
640 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
641 Raw.sets_float state
.traw ~pos
:0
642 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
643 GlArray.vertex `two state
.vraw
;
644 GlArray.tex_coord `two state
.traw
;
645 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
646 Gl.disable `texture_2d
;
649 GlDraw.color (1.0, 1.0, 1.0);
650 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
653 then GlTex.env
(`mode `modulate
);
654 if w > 128 && h
> fstate
.fontsize
+ 10
656 let c = if conf
.invert
then 1.0 else 0.0 in
657 GlDraw.color (c, c, c);
660 then (col*conf
.tilew
, row*conf
.tileh
)
663 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
672 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
674 let tilevisible1 l x y =
676 and ax1
= l.pagex
+ l.pagevw
678 and ay1
= l.pagey + l.pagevh in
682 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
683 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
685 let rx0 = max
ax0 bx0
686 and ry0
= max ay0 by0
687 and rx1
= min ax1
bx1
688 and ry1
= min ay1 by1
in
690 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
694 let tilevisible layout n x y =
695 let rec findpageinlayout m
= function
696 | l :: rest
when l.pageno
= n ->
697 tilevisible1 l x y || (
698 match conf
.columns
with
699 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
700 | Csplit _
| Csingle _
| Cmulti _
-> false
702 | _
:: rest
-> findpageinlayout 0 rest
705 findpageinlayout 0 layout;
708 let tileready l x y =
709 tilevisible1 l x y &&
710 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
713 let tilepage n p
layout =
714 let rec loop = function
718 let f col row _ _ _ _ _ _
=
719 if state
.currently
= Idle
721 match gettileopaque l col row with
724 let x = col*conf
.tilew
725 and y = row*conf
.tileh
in
727 let w = l.pagew
- x in
731 let h = l.pageh
- y in
736 then getpbo
w h conf
.colorspace
739 wcmd "tile %s %d %d %d %d %s"
740 (~
> p
) x y w h (~
> pbo);
743 l, p
, conf
.colorspace
, conf
.angle
,
744 state
.gen
, col, row, conf
.tilew
, conf
.tileh
753 if nogeomcmds state
.geomcmds
757 let preloadlayout x y sw sh
=
758 let y = if y < sh
then 0 else y - sh
in
759 let x = min
0 (x + sw
) in
767 if state
.currently
!= Idle
772 begin match getopaque l.pageno
with
774 wcmd "page %d %d" l.pageno
l.pagedimno
;
775 state
.currently
<- Loading
(l, state
.gen
);
777 tilepage l.pageno opaque pages
;
782 if nogeomcmds state
.geomcmds
788 if conf
.preload && state
.currently
= Idle
789 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
792 let layoutready layout =
793 let rec fold all ls
=
796 let seen = ref false in
797 let allvisible = ref true in
798 let foo col row _ _ _ _ _ _
=
800 allvisible := !allvisible &&
801 begin match gettileopaque l col row with
807 fold (!seen && !allvisible) rest
810 let alltilesvisible = fold true layout in
815 let y = bound
y 0 state
.maxy
in
816 let y, layout, proceed
=
817 match conf
.maxwait
with
818 | Some time
when state
.ghyll
== noghyll
->
819 begin match state
.throttle
with
821 let layout = layout x y state
.winw state
.winh
in
822 let ready = layoutready layout in
826 state
.throttle
<- Some
(layout, y, now
());
828 else G.postRedisplay "gotoxy showall (None)";
830 | Some
(_
, _
, started
) ->
831 let dt = now
() -. started
in
834 state
.throttle
<- None
;
835 let layout = layout x y state
.winw state
.winh
in
837 G.postRedisplay "maxwait";
844 let layout = layout x y state
.winw state
.winh
in
845 if not
!wtmode || layoutready layout
846 then G.postRedisplay "gotoxy ready";
853 state
.layout <- layout;
854 begin match state
.mode
with
857 | Ltexact
(pageno
, linkno
) ->
858 let rec loop = function
860 state
.lnava
<- Some
(pageno
, linkno
);
861 state
.mode
<- LinkNav
(Ltgendir
0)
862 | l :: _
when l.pageno
= pageno
->
863 begin match getopaque pageno
with
864 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
866 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
867 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
868 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
869 then state
.mode
<- LinkNav
(Ltgendir
0)
871 | _
:: rest
-> loop rest
874 | Ltnotready _
| Ltgendir _
-> ()
876 | Birdseye _
| Textentry _
| View
-> ()
878 begin match state
.mode
with
879 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
880 if not
(pagevisible layout pageno
)
882 match state
.layout with
885 state
.mode
<- Birdseye
(
886 conf
, leftx
, l.pageno
, hooverpageno
, anchor
891 | Ltnotready
(_
, dir
)
894 let rec loop = function
897 match getopaque l.pageno
with
898 | None
-> Ltnotready
(l.pageno
, dir
)
903 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
905 if dir
> 0 then LDfirst
else LDlast
911 | Lnotfound
-> loop rest
913 showlinktype (getlink opaque
n);
914 Ltexact
(l.pageno
, n)
918 state
.mode
<- LinkNav
linknav
921 | Textentry _
| View
-> ()
925 state
.ghyll
<- noghyll
;
928 let mx, my
= state
.mpos
in
933 let conttiling pageno opaque
=
934 tilepage pageno opaque
936 then preloadlayout state
.x state
.y state
.winw state
.winh
940 let gotoxy_and_clear_text x y =
941 if not conf
.verbose
then state
.text <- E.s;
945 let getanchory (n, top
, dtop
) =
946 let y, h = getpageyh
n in
949 let ips = calcips
h in
950 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
952 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
955 let gotoanchor anchor
=
956 gotoxy state
.x (getanchory anchor
);
960 cbput state
.hists
.nav
(getanchor
());
964 let anchor = cbgetc state
.hists
.nav dir
in
968 let gotoghyll1 single
y =
970 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
972 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
974 then s (float f /. float a
)
977 then 1.0 -. s ((float (f-b) /. float (n-b)))
983 let ins = float a
*. 0.5
984 and outs
= float (n-b) *. 0.5 in
986 ins +. outs
+. float ones
988 let rec set nab
y sy
=
989 let (_N
, _A
, _B
), y =
992 let scl = if y > sy
then 2 else -2 in
993 let _N, _
, _
= nab
in
994 (_N,0,_N), y+conf
.scrollstep
*scl
996 let sum = summa
_N _A _B
in
997 let dy = float (y - sy
) in
1001 then state
.ghyll
<- noghyll
1004 let s = scroll n _N _A _B
in
1005 let y1 = y1 +. ((s *. dy) /. sum) in
1006 gotoxy_and_clear_text state
.x (truncate
y1);
1007 state
.ghyll
<- gf (n+1) y1;
1011 | Some
y'
when single
-> set nab
y' state
.y
1012 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1014 gf 0 (float state
.y)
1017 match conf
.ghyllscroll
with
1018 | Some nab
when not conf
.presentation
->
1019 if state
.ghyll
== noghyll
1020 then set nab
y state
.y
1021 else state
.ghyll
(Some
y)
1023 gotoxy_and_clear_text state
.x y
1026 let gotoghyll = gotoghyll1 false;;
1028 let gotopage n top
=
1029 let y, h = getpageyh
n in
1030 let y = y + (truncate
(top
*. float h)) in
1034 let gotopage1 n top
=
1035 let y = getpagey
n in
1040 let invalidate s f =
1041 state
.redisplay
<- false;
1046 match state
.geomcmds
with
1047 | ps
, [] when emptystr ps
->
1049 state
.geomcmds
<- s, [];
1052 state
.geomcmds
<- ps
, [s, f];
1054 | ps
, (s'
, _
) :: rest
when s'
= s ->
1055 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1058 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1062 Hashtbl.iter
(fun _ opaque
->
1063 wcmd "freepage %s" (~
> opaque
);
1065 Hashtbl.clear state
.pagemap
;
1069 if not
(Queue.is_empty state
.tilelru
)
1071 Queue.iter
(fun (k
, p
, s) ->
1072 wcmd "freetile %s" (~
> p
);
1073 state
.memused
<- state
.memused
- s;
1074 Hashtbl.remove state
.tilemap k
;
1076 state
.uioh#infochanged Memused
;
1077 Queue.clear state
.tilelru
;
1083 let h = truncate
(float h*.conf
.zoom
) in
1084 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1088 let opendoc path password
=
1090 state
.password
<- password
;
1091 state
.gen
<- state
.gen
+ 1;
1092 state
.docinfo
<- [];
1093 state
.outlines
<- [||];
1096 setaalevel conf
.aalevel
;
1098 if emptystr state
.origin
1102 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1103 wcmd "open %d %d %d %s\000%s\000%s\000"
1104 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1105 path password conf
.css
;
1106 invalidate "reqlayout"
1108 wcmd "reqlayout %d %d %d %s\000"
1109 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1110 (stateh state
.winh
) state
.nameddest
1113 let sl = keystostrlist conf
in
1115 function | [] -> accu
1116 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1117 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1121 state
.anchor <- getanchor
();
1122 opendoc state
.path state
.password
;
1126 let c = c *. conf
.colorscale
in
1130 let scalecolor2 (r
, g, b) =
1131 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1134 let docolumns columns
=
1137 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1138 let rec loop pageno
pdimno pdim
y ph pdims
=
1139 if pageno
= state
.pagecount
1142 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1144 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1145 pdimno+1, pdim
, rest
1149 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1151 y + (if conf
.presentation
1152 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1153 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1156 a.(pageno
) <- (pdimno, x, y, pdim
);
1157 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1159 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1160 conf
.columns
<- Csingle
a;
1162 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1163 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1164 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1166 if m
= pageno
then () else
1167 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1170 let y = y + (rowh
- h) / 2 in
1171 a.(m
) <- (pdimno, x, y, pdim
);
1175 if pageno
= state
.pagecount
1176 then fixrow (((pageno
- 1) / columns
) * columns
)
1178 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1180 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1181 pdimno+1, pdim
, rest
1186 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1188 let x = (state
.winw
- w) / 2 in
1190 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1191 x, y + ips + rowh
, h
1194 if (pageno
- coverA
) mod columns
= 0
1196 let x = max
0 (state
.winw
- state
.w) / 2 in
1198 if conf
.presentation
1200 let ips = calcips
h in
1201 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1203 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1207 else x, y, max rowh
h
1211 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1214 if pageno
= columns
&& conf
.presentation
1216 let ips = calcips rowh
in
1217 for i
= 0 to pred columns
1219 let (pdimno, x, y, pdim
) = a.(i
) in
1220 a.(i
) <- (pdimno, x, y+ips, pdim
)
1226 fixrow (pageno
- columns
);
1231 a.(pageno
) <- (pdimno, x, y, pdim
);
1232 let x = x + w + xoff
*2 + conf
.interpagespace
in
1233 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1235 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1236 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1239 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1240 let rec loop pageno
pdimno pdim
y pdims
=
1241 if pageno
= state
.pagecount
1244 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1246 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1247 pdimno+1, pdim
, rest
1252 let rec loop1 n x y =
1253 if n = c then y else (
1254 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1255 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1258 let y = loop1 0 0 y in
1259 loop (pageno
+1) pdimno pdim
y pdims
1261 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1262 conf
.columns
<- Csplit
(c, a);
1266 docolumns conf
.columns
;
1267 state
.maxy
<- calcheight
();
1268 if state
.reprf
== noreprf
1270 match state
.mode
with
1271 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1272 let y, h = getpageyh pageno
in
1273 let top = (state
.winh
- h) / 2 in
1274 gotoxy state
.x (max
0 (y - top))
1275 | Textentry _
| View
| LinkNav _
->
1276 let y = getanchory state
.anchor in
1277 let y = min
y (state
.maxy
- state
.winh
) in
1282 state
.reprf
<- noreprf
;
1286 let reshape ?
(firsttime
=false) w h =
1287 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1288 if not firsttime
&& nogeomcmds state
.geomcmds
1289 then state
.anchor <- getanchor
();
1292 let w = truncate
(float w *. conf
.zoom
) in
1295 setfontsize fstate
.fontsize
;
1296 GlMat.mode `modelview
;
1297 GlMat.load_identity
();
1299 GlMat.mode `projection
;
1300 GlMat.load_identity
();
1301 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1302 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1303 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1308 else float state
.x /. float state
.w
1310 invalidate "geometry"
1314 then state
.x <- truncate
(relx *. float w);
1316 match conf
.columns
with
1318 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1319 | Csplit
(c, _
) -> w * c
1321 wcmd "geometry %d %d %d"
1322 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1327 let len = String.length state
.text in
1328 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1331 match state
.mode
with
1332 | Textentry _
| View
| LinkNav _
->
1333 let h, _
, _
= state
.uioh#scrollpw
in
1339 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1340 (x+.w) (float (state
.winh
- hscrollh))
1343 let w = float (state
.winw
- 1 - vscrollw ()) in
1344 if state
.progress
>= 0.0 && state
.progress
< 1.0
1346 GlDraw.color (0.3, 0.3, 0.3);
1347 let w1 = w *. state
.progress
in
1349 GlDraw.color (0.0, 0.0, 0.0);
1350 rect (float x0+.w1) (float x0+.w-.w1)
1353 GlDraw.color (0.0, 0.0, 0.0);
1357 GlDraw.color (1.0, 1.0, 1.0);
1360 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1361 (state
.winh
- hscrollh - 5) s;
1364 match state
.mode
with
1365 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1368 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1369 else Printf.sprintf
"%s%s_" prefix
text
1373 | Birdseye _
| View
| LinkNav _
-> state
.text
1378 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1380 let s1 = "(press 'e' to review error messasges)" in
1381 if nonemptystr
s then s ^
" " ^
s1 else s1
1391 let len = Queue.length state
.tilelru
in
1393 match state
.throttle
with
1396 then preloadlayout state
.x state
.y state
.winw state
.winh
1398 | Some
(layout, _
, _
) ->
1402 if state
.memused
> conf
.memlimit
1406 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1407 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1408 let (_
, pw, ph
, _
) = getpagedim
n in
1410 && colorspace
= conf
.colorspace
1411 && angle
= conf
.angle
1415 let x = col*conf
.tilew
1416 and y = row*conf
.tileh
in
1417 tilevisible (Lazy.force_val
layout) n x y
1419 then Queue.push lruitem state
.tilelru
1422 wcmd "freetile %s" (~
> p
);
1423 state
.memused
<- state
.memused
- s;
1424 state
.uioh#infochanged Memused
;
1425 Hashtbl.remove state
.tilemap k
;
1433 let onpagerect pageno
f =
1435 match conf
.columns
with
1436 | Cmulti
(_
, b) -> b
1438 | Csplit
(_
, b) -> b
1440 if pageno
>= 0 && pageno
< Array.length
b
1442 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1446 let gotopagexy1 wtmode pageno
x y =
1447 let _,w1,h1
,leftx
= getpagedim pageno
in
1448 let top = y /. (float h1
) in
1449 let left = x /. (float w1) in
1450 let py, w, h = getpageywh pageno
in
1451 let wh = state
.winh
in
1452 let x = left *. (float w) in
1453 let x = leftx
+ state
.x + truncate
x in
1455 if x < 0 || x >= state
.winw
1459 let pdy = truncate
(top *. float h) in
1460 let y'
= py + pdy in
1461 let dy = y'
- state
.y in
1463 if x != state
.x || not
(dy > 0 && dy < wh)
1465 if conf
.presentation
1467 if abs
(py - y'
) > wh
1474 if state
.x != sx || state
.y != sy
1479 let ww = state
.winw
in
1481 and qy
= pdy / wh in
1483 and y = py + qy
* wh in
1484 let x = if -x + ww > w1 then -(w1-ww) else x
1485 and y'
= if y + wh > state
.maxy
then state
.maxy
- wh else y in
1487 if conf
.presentation
1489 if abs
(py - y'
) > wh
1498 gotoxy_and_clear_text x y;
1500 else gotoxy_and_clear_text state
.x state
.y;
1503 let gotopagexy wtmode pageno
x y =
1504 match state
.mode
with
1505 | Birdseye
_ -> gotopage pageno
0.0
1506 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1509 let getpassword () =
1510 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1515 impmsg "error getting password: %s" s;
1516 dolog
"%s" s) passcmd;
1519 let pgoto opaque pageno
x y =
1520 let pdimno = getpdimno pageno
in
1521 let x, y = project opaque pageno
pdimno x y in
1522 gotopagexy false pageno
x y;
1526 (* dolog "%S" cmds; *)
1527 let spl = splitatchar cmds ' '
in
1529 try Scanf.sscanf
s fmt
f
1531 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1534 let addoutline outline
=
1535 match state
.currently
with
1536 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1537 | Idle
-> state
.currently
<- Outlining
[outline
]
1538 | Loading
_ | Tiling
_ ->
1539 dolog
"invalid outlining state";
1540 logcurrently state
.currently
1545 state
.uioh#infochanged Pdim
;
1547 | "clearrects", "" ->
1548 state
.rects
<- state
.rects1
;
1549 G.postRedisplay "clearrects";
1551 | "continue", args
->
1552 let n = scan args
"%u" (fun n -> n) in
1553 state
.pagecount
<- n;
1554 begin match state
.currently
with
1556 state
.currently
<- Idle
;
1557 state
.outlines
<- Array.of_list
(List.rev
l)
1558 | Idle
| Loading
_ | Tiling
_ -> ()
1561 let cur, cmds
= state
.geomcmds
in
1563 then failwith
"umpossible";
1565 begin match List.rev cmds
with
1567 state
.geomcmds
<- E.s, [];
1568 state
.throttle
<- None
;
1572 state
.geomcmds
<- s, List.rev rest
;
1574 if conf
.maxwait
= None
&& not
!wtmode
1575 then G.postRedisplay "continue";
1582 then showtext ' ' args
1585 Buffer.add_string state
.errmsgs args
;
1586 state
.newerrmsgs
<- true;
1587 G.postRedisplay "error message"
1589 | "progress", args
->
1590 let progress, text =
1593 f, String.sub args pos
(String.length args
- pos
))
1596 state
.progress <- progress;
1597 G.postRedisplay "progress"
1599 | "firstmatch", args
->
1600 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1601 scan args
"%u %d %f %f %f %f %f %f %f %f"
1602 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1603 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1605 let y = (getpagey
pageno) + truncate
y0 in
1613 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1614 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1617 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1618 scan args
"%u %d %f %f %f %f %f %f %f %f"
1619 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1620 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1622 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1624 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1627 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1628 let pageopaque = ~
< pageopaques in
1629 begin match state
.currently
with
1630 | Loading
(l, gen
) ->
1631 vlog "page %d took %f sec" l.pageno t
;
1632 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1633 begin match state
.throttle
with
1635 let preloadedpages =
1637 then preloadlayout state
.x state
.y state
.winw state
.winh
1642 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1643 IntSet.empty
preloadedpages
1646 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1647 if not
(IntSet.mem
pageno set)
1649 wcmd "freepage %s" (~
> opaque
);
1655 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1658 state
.currently
<- Idle
;
1661 tilepage l.pageno pageopaque state
.layout;
1663 load preloadedpages;
1664 let visible = pagevisible state
.layout l.pageno in
1667 match state
.mode
with
1668 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1669 if pageno = l.pageno
1674 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1676 if dir
> 0 then LDfirst
else LDlast
1679 findlink
pageopaque ld
1684 showlinktype (getlink
pageopaque n);
1685 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1687 | LinkNav
(Ltgendir
_)
1688 | LinkNav
(Ltexact
_)
1694 if visible && layoutready state
.layout
1696 G.postRedisplay "page";
1700 | Some
(layout, _, _) ->
1701 state
.currently
<- Idle
;
1702 tilepage l.pageno pageopaque layout;
1706 | Idle
| Tiling
_ | Outlining
_ ->
1707 dolog
"Inconsistent loading state";
1708 logcurrently state
.currently
;
1713 let (x, y, opaques
, size
, t
) =
1714 scan args
"%u %u %s %u %f"
1715 (fun x y p size t
-> (x, y, p
, size
, t
))
1717 let opaque = ~
< opaques
in
1718 begin match state
.currently
with
1719 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1720 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1723 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1725 wcmd "freetile %s" (~
> opaque);
1726 state
.currently
<- Idle
;
1730 puttileopaque l col row gen cs angle
opaque size t
;
1731 state
.memused
<- state
.memused
+ size
;
1732 state
.uioh#infochanged Memused
;
1734 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1735 opaque, size
) state
.tilelru
;
1738 match state
.throttle
with
1739 | None
-> state
.layout
1740 | Some
(layout, _, _) -> layout
1743 state
.currently
<- Idle
;
1745 && conf
.colorspace
= cs
1746 && conf
.angle
= angle
1747 && tilevisible layout l.pageno x y
1748 then conttiling l.pageno pageopaque;
1750 begin match state
.throttle
with
1752 preload state
.layout;
1754 && conf
.colorspace
= cs
1755 && conf
.angle
= angle
1756 && tilevisible state
.layout l.pageno x y
1757 && (not
!wtmode || layoutready state
.layout)
1758 then G.postRedisplay "tile nothrottle";
1760 | Some
(layout, y, _) ->
1761 let ready = layoutready layout in
1765 state
.layout <- layout;
1766 state
.throttle
<- None
;
1767 G.postRedisplay "throttle";
1773 | Idle
| Loading
_ | Outlining
_ ->
1774 dolog
"Inconsistent tiling state";
1775 logcurrently state
.currently
;
1780 let (n, w, h, _) as pdim
=
1781 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1784 match conf
.fitmodel
with
1786 | FitPage
| FitProportional
->
1787 match conf
.columns
with
1788 | Csplit
_ -> (n, w, h, 0)
1789 | Csingle
_ | Cmulti
_ -> pdim
1791 state
.pdims
<- pdim :: state
.pdims
;
1792 state
.uioh#infochanged Pdim
1795 let (l, n, t
, h, pos
) =
1796 scan args
"%u %u %d %u %n"
1797 (fun l n t
h pos
-> l, n, t
, h, pos
)
1799 let s = String.sub args pos
(String.length args
- pos
) in
1800 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1803 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1804 let s = String.sub args pos
len in
1805 let pos2 = pos
+ len + 1 in
1806 let uri = String.sub args
pos2 (String.length args
- pos2) in
1807 addoutline (s, l, Ouri
uri)
1810 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1811 let s = String.sub args pos
(String.length args
- pos
) in
1812 addoutline (s, l, Onone
)
1816 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1818 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1821 let c, v
= splitatchar args '
\t'
in
1832 if let len = String.length
c in
1833 len > 6 && ((String.sub
c (len-4) 4) = "date")
1835 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1837 let b = Buffer.create
10 in
1838 Printf.bprintf
b "%s\t" c;
1841 Buffer.add_substring
b v p
l;
1842 Buffer.add_char
b c;
1843 with exn
-> Buffer.add_string
b @@ exntos exn
1851 Buffer.add_char
b '
['
;
1852 Buffer.add_string
b v
;
1853 Buffer.add_char
b '
]'
;
1860 state
.docinfo
<- (1, s) :: state
.docinfo
1863 state
.docinfo
<- List.rev state
.docinfo
;
1864 state
.uioh#infochanged Docinfo
1868 then Wsi.settitle
"Wrong password";
1869 let password = getpassword () in
1870 if emptystr
password
1871 then error
"document is password protected"
1872 else opendoc state
.path
password
1875 error
"unknown cmd `%S'" cmds
1880 let action = function
1881 | HCprev
-> cbget cb ~
-1
1882 | HCnext
-> cbget cb
1
1883 | HCfirst
-> cbget cb ~
-(cb
.rc)
1884 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1885 and cancel
() = cb
.rc <- rc
1889 let search pattern forward
=
1890 match conf
.columns
with
1891 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1892 | Csingle
_ | Cmulti
_ ->
1893 if nonemptystr pattern
1896 match state
.layout with
1899 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1901 wcmd "search %d %d %d %d,%s\000"
1902 (btod conf
.icase
) pn py (btod forward
) pattern
;
1905 let [@warning
"-4"] intentry
text key =
1908 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1910 state
.text <- "invalid key";
1920 let l = String.length
s in
1921 let rec loop pos
n =
1925 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1926 loop (pos
+1) (n*26 + m)
1929 let rec loop n = function
1932 match getopaque l.pageno with
1933 | None
-> loop n rest
1935 let m = getlinkcount
opaque in
1938 let under = getlink
opaque n in
1941 else loop (n-m) rest
1943 loop n state
.layout;
1947 let [@warning
"-4"] linknentry
text = function
1949 let text = addchar
text c in
1950 linknact (fun under -> state
.text <- undertext under) text;
1953 state
.text <- Printf.sprintf
"invalid key";
1957 let [@warning
"-4"] textentry
text = function
1958 | Keys.Ascii
c -> TEcont
(addchar
text c)
1959 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1963 let reqlayout angle fitmodel
=
1964 match state
.throttle
with
1966 if nogeomcmds state
.geomcmds
1967 then state
.anchor <- getanchor
();
1968 conf
.angle
<- angle
mod 360;
1971 match state
.mode
with
1972 | LinkNav
_ -> state
.mode
<- View
1973 | Birdseye
_ | Textentry
_ | View
-> ()
1975 conf
.fitmodel
<- fitmodel
;
1979 wcmd "reqlayout %d %d %d"
1980 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1985 let settrim trimmargins trimfuzz
=
1986 if nogeomcmds state
.geomcmds
1987 then state
.anchor <- getanchor
();
1988 conf
.trimmargins
<- trimmargins
;
1989 conf
.trimfuzz
<- trimfuzz
;
1990 let x0, y0, x1, y1 = trimfuzz
in
1992 "settrim" (fun () ->
1993 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1998 match state
.throttle
with
2000 let zoom = max
0.0001 zoom in
2001 if zoom <> conf
.zoom
2003 state
.prevzoom
<- (conf
.zoom, state
.x);
2005 reshape state
.winw state
.winh
;
2006 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2009 | Some
(layout, y, started
) ->
2011 match conf
.maxwait
with
2015 let dt = now
() -. started
in
2023 let pivotzoom ?
(vw=min state
.w state
.winw
)
2024 ?
(vh
=min
(state
.maxy
-state
.y) state
.winh
)
2025 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2026 let w = float state
.w /. zoom in
2027 let hw = w /. 2.0 in
2028 let ratio = float vh
/. float vw in
2029 let hh = hw *. ratio in
2030 let x0 = if zoom < 1.0 then 0.0 else float x -. hw in
2031 let y0 = float y -. hh in
2032 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2036 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2037 if nogeomcmds state
.geomcmds
then pivotzoom ?
vw ?vh ?
x ?
y zoom
2040 let setcolumns mode columns coverA coverB
=
2041 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2045 then impmsg "split mode doesn't work in bird's eye"
2047 conf
.columns
<- Csplit
(-columns
, E.a);
2055 conf
.columns
<- Csingle
E.a;
2060 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2064 reshape state
.winw state
.winh
;
2067 let resetmstate () =
2068 state
.mstate
<- Mnone
;
2069 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2072 let enterbirdseye () =
2073 let zoom = float conf
.thumbw
/. float state
.winw
in
2074 let birdseyepageno =
2075 let cy = state
.winh
/ 2 in
2079 let rec fold best
= function
2082 let d = cy - (l.pagedispy + l.pagevh/2)
2083 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2084 if abs
d < abs dbest
2093 { conf
with zoom = conf
.zoom },
2094 state
.x, birdseyepageno, -1, getanchor
()
2098 conf
.presentation
<- false;
2099 conf
.interpagespace
<- 10;
2100 conf
.hlinks
<- false;
2101 conf
.fitmodel
<- FitPage
;
2103 conf
.maxwait
<- None
;
2105 match conf
.beyecolumns
with
2108 Cmulti
((c, 0, 0), E.a)
2109 | None
-> Csingle
E.a
2113 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2118 reshape state
.winw state
.winh
;
2121 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2123 conf
.zoom <- c.zoom;
2124 conf
.presentation
<- c.presentation
;
2125 conf
.interpagespace
<- c.interpagespace
;
2126 conf
.maxwait
<- c.maxwait
;
2127 conf
.hlinks
<- c.hlinks
;
2128 conf
.fitmodel
<- c.fitmodel
;
2129 conf
.beyecolumns
<- (
2130 match conf
.columns
with
2131 | Cmulti
((c, _, _), _) -> Some
c
2133 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2136 match c.columns
with
2137 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2138 | Csingle
_ -> Csingle
E.a
2139 | Csplit
(c, _) -> Csplit
(c, E.a)
2143 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2146 reshape state
.winw state
.winh
;
2147 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2151 let togglebirdseye () =
2152 match state
.mode
with
2153 | Birdseye vals
-> leavebirdseye vals
true
2154 | View
-> enterbirdseye ()
2155 | Textentry
_ | LinkNav
_ -> ()
2158 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2159 let pageno = max
0 (pageno - incr
) in
2160 let rec loop = function
2161 | [] -> gotopage1 pageno 0
2162 | l :: _ when l.pageno = pageno ->
2163 if l.pagedispy >= 0 && l.pagey = 0
2164 then G.postRedisplay "upbirdseye"
2165 else gotopage1 pageno 0
2166 | _ :: rest
-> loop rest
2170 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2173 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2174 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2175 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2176 let rec loop = function
2178 let y, h = getpageyh
pageno in
2179 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2180 gotoxy state
.x (clamp dy)
2181 | l :: _ when l.pageno = pageno ->
2182 if l.pagevh != l.pageh
2183 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2184 else G.postRedisplay "downbirdseye"
2185 | _ :: rest
-> loop rest
2191 let [@warning
"-4"] optentry mode
_ key =
2192 let btos b = if b then "on" else "off" in
2196 try conf
.scrollstep
<- int_of_string
s with exn
->
2197 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2199 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2204 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2205 if state
.autoscroll
<> None
2206 then state
.autoscroll
<- Some conf
.autoscrollstep
2208 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2210 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2215 let n, a, b = multicolumns_of_string
s in
2216 setcolumns mode
n a b;
2218 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2220 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2225 let zoom = float (int_of_string
s) /. 100.0 in
2228 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2230 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2235 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2237 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2238 begin match mode
with
2240 leavebirdseye beye
false;
2242 | Textentry
_ | View
| LinkNav
_ -> ();
2245 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2247 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2251 match int_of_string
s with
2252 | angle
-> reqlayout angle conf
.fitmodel
2254 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2256 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2259 conf
.icase
<- not conf
.icase
;
2260 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2263 conf
.preload <- not conf
.preload;
2264 gotoxy state
.x state
.y;
2265 TEdone
("preload " ^
(btos conf
.preload))
2268 conf
.verbose
<- not conf
.verbose
;
2269 TEdone
("verbose " ^
(btos conf
.verbose
))
2272 conf
.debug
<- not conf
.debug
;
2273 TEdone
("debug " ^
(btos conf
.debug
))
2276 conf
.maxhfit
<- not conf
.maxhfit
;
2277 state
.maxy
<- calcheight
();
2278 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2281 conf
.crophack
<- not conf
.crophack
;
2282 TEdone
("crophack " ^
btos conf
.crophack
)
2286 match conf
.maxwait
with
2288 conf
.maxwait
<- Some infinity
;
2289 "always wait for page to complete"
2291 conf
.maxwait
<- None
;
2292 "show placeholder if page is not ready"
2297 conf
.underinfo
<- not conf
.underinfo
;
2298 TEdone
("underinfo " ^
btos conf
.underinfo
)
2301 conf
.savebmarks
<- not conf
.savebmarks
;
2302 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2308 match state
.layout with
2313 conf
.interpagespace
<- int_of_string
s;
2314 docolumns conf
.columns
;
2315 state
.maxy
<- calcheight
();
2316 let y = getpagey
pageno in
2317 gotoxy state
.x (y + py)
2319 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2321 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2325 match conf
.fitmodel
with
2326 | FitProportional
-> FitWidth
2327 | FitWidth
| FitPage
-> FitProportional
2329 reqlayout conf
.angle
fm;
2330 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2333 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2334 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2337 conf
.invert
<- not conf
.invert
;
2338 TEdone
("invert colors " ^
btos conf
.invert
)
2342 cbput state
.hists
.sel
s;
2345 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2346 textentry
, ondone, true)
2350 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2351 else conf
.pax
<- None
;
2352 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2355 state
.text <- Printf.sprintf
"bad option %d `%c'"
2363 class type lvsource
=
2365 method getitemcount
: int
2366 method getitem
: int -> (string * int)
2367 method hasaction
: int -> bool
2368 method exit
: uioh
:uioh
->
2374 method getactive
: int
2375 method getfirst
: int
2377 method getminfo
: (int * int) array
2380 class virtual lvsourcebase
= object
2381 val mutable m_active
= 0
2382 val mutable m_first
= 0
2383 val mutable m_pan
= 0
2384 method getactive
= m_active
2385 method getfirst
= m_first
2386 method getpan
= m_pan
2387 method getminfo
: (int * int) array
= E.a
2390 let [@warning
"-4"] textentrykeyboard
2391 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2394 state
.mode
<- Textentry
(te
, onleave
);
2396 G.postRedisplay "textentrykeyboard enttext";
2398 let histaction cmd
=
2401 | Some
(action, _) ->
2404 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2406 G.postRedisplay "textentry histaction"
2408 let open Keys
in let kt = Wsi.kc2kt
key in
2411 if emptystr
text && cancelonempty
2414 G.postRedisplay "textentrykeyboard after cancel";
2417 let s = withoutlastutf8
text in
2418 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2423 G.postRedisplay "textentrykeyboard after confirm"
2425 | Up
-> histaction HCprev
2426 | Down
-> histaction HCnext
2427 | Home
-> histaction HCfirst
2428 | End
-> histaction HClast
2433 begin match opthist
with
2435 | Some
(_, onhistcancel
) -> onhistcancel
()
2439 G.postRedisplay "textentrykeyboard after cancel2"
2442 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2447 | Code
_ | Ascii
_ ->
2448 begin match onkey
text kt with
2452 G.postRedisplay "textentrykeyboard after confirm2";
2455 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2459 G.postRedisplay "textentrykeyboard after cancel3"
2462 state
.mode
<- Textentry
(te
, onleave
);
2463 G.postRedisplay "textentrykeyboard switch";
2465 | _ -> vlog "unhandled key"
2468 let firstof first active
=
2469 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2470 then max
0 (active
- (fstate
.maxrows
/2))
2474 let calcfirst first active
=
2477 let rows = active
- first
in
2478 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2482 let scrollph y maxy
=
2483 let sh = float (maxy
+ state
.winh
) /. float state
.winh
in
2484 let sh = float state
.winh
/. sh in
2485 let sh = max
sh (float conf
.scrollh
) in
2487 let percent = float y /. float maxy
in
2488 let position = (float state
.winh
-. sh) *. percent in
2491 if position +. sh > float state
.winh
2492 then float state
.winh
-. sh
2498 let adderrmsg src msg
=
2499 Buffer.add_string state
.errmsgs msg
;
2500 state
.newerrmsgs
<- true;
2504 let adderrfmt src fmt
=
2505 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2508 let coe s = (s :> uioh
);;
2510 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2512 val m_pan
= source#getpan
2513 val m_first
= source#getfirst
2514 val m_active
= source#getactive
2516 val m_prev_uioh
= state
.uioh
2518 method private elemunder
y =
2522 let n = y / (fstate
.fontsize
+1) in
2523 if m_first
+ n < source#getitemcount
2525 if source#hasaction
(m_first
+ n)
2526 then Some
(m_first
+ n)
2533 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2534 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2535 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2536 GlDraw.color (1., 1., 1.);
2537 Gl.enable `texture_2d
;
2538 let fs = fstate
.fontsize
in
2540 let hw = state
.winw
/3 in
2541 let ww = fstate
.wwidth
in
2542 let tabw = 17.0*.ww in
2543 let itemcount = source#getitemcount
in
2544 let minfo = source#getminfo
in
2548 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2550 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2552 if (row - m_first
) > fstate
.maxrows
2555 if row >= 0 && row < itemcount
2557 let (s, level
) = source#getitem
row in
2558 let y = (row - m_first
) * nfs in
2559 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2562 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2566 Gl.disable `texture_2d
;
2567 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2568 GlDraw.color (1., 1., 1.) ~
alpha;
2569 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2570 Gl.enable `texture_2d
;
2573 if zebra
&& row land 1 = 1
2577 GlDraw.color (c,c,c);
2578 let drawtabularstring s =
2580 let x'
= truncate
(x0 +. x) in
2581 let s1, s2
= splitatchar
s '
\000'
in
2583 then drawstring1 fs x'
(y+nfs) s
2589 let s'
= withoutlastutf8
s in
2590 let s = s' ^
UniSyms.ellipsis in
2591 let w = measurestr
fs s in
2592 if float x'
+. w +. ww < float (hw + x'
)
2597 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2601 ignore
(drawstring1 fs x'
(y+nfs) s1);
2602 drawstring1 fs (hw + x'
) (y+nfs) s2
2606 let x = if helpmode
&& row > 0 then x +. ww else x in
2607 let s1, s2
= splitatchar
s '
\t'
in
2610 let nx = drawstr x s1 in
2612 let x = x +. (max
tabw sw) in
2615 let len = String.length
s - 2 in
2616 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2618 let s = String.sub s 2 len in
2619 let x = if not helpmode
then x +. ww else x in
2620 GlDraw.color (1.2, 1.2, 1.2);
2621 let vinc = drawstring1 (fs+fs/4)
2622 (truncate
(x -. ww)) (y+nfs) s in
2623 GlDraw.color (1., 1., 1.);
2624 vinc +. (float fs *. 0.8)
2630 ignore
(drawtabularstring s);
2636 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2639 if (row - m_first
) <= fstate
.maxrows
2641 if row >= 0 && row < itemcount
2643 let (s, level
) = source#getitem
row in
2644 let pos0 = nindex
s '
\000'
in
2645 let y = (row - m_first
) * nfs in
2646 let x = float (level
+ m_pan
) *. ww in
2647 let (first
, last
) = minfo.(row) in
2649 if pos0 > 0 && first
> pos0
2650 then String.sub s (pos0+1) (first
-pos0-1)
2651 else String.sub s 0 first
2653 let suffix = String.sub s first
(last
- first
) in
2654 let w1 = measurestr fstate
.fontsize
prefix in
2655 let w2 = measurestr fstate
.fontsize
suffix in
2656 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2657 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2659 and y0 = float (y+2) in
2661 and y1 = float (y+fs+3) in
2662 filledrect x0 y0 x1 y1;
2666 Gl.disable `texture_2d
;
2667 if Array.length
minfo > 0 then loop m_first
;
2672 method updownlevel incr
=
2673 let len = source#getitemcount
in
2675 if m_active
>= 0 && m_active
< len
2676 then snd
(source#getitem m_active
)
2680 if i
= len then i
-1 else if i
= -1 then 0 else
2681 let _, l = source#getitem i
in
2682 if l != curlevel then i
else flow (i
+incr
)
2684 let active = flow m_active
in
2685 let first = calcfirst m_first
active in
2686 G.postRedisplay "outline updownlevel";
2687 {< m_active
= active; m_first
= first >}
2689 method private key1
key mask
=
2690 let set1 active first qsearch
=
2691 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2693 let search active pattern incr
=
2694 let active = if active = -1 then m_first
else active in
2697 if n >= 0 && n < source#getitemcount
2699 let s, _ = source#getitem
n in
2700 match Str.search_forward re
s 0 with
2701 | exception Not_found
-> loop (n + incr
)
2708 let qpat = Str.quote pattern
in
2709 match Str.regexp_case_fold
qpat with
2712 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2713 qpat @@ Printexc.to_string exn
;
2716 let itemcount = source#getitemcount
in
2717 let find start incr
=
2719 if i
= -1 || i
= itemcount
2722 if source#hasaction i
2724 else find (i
+ incr
)
2729 let set active first =
2730 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2732 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2735 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2737 let incr1 = if incr
> 0 then 1 else -1 in
2738 if isvisible m_first m_active
2741 let next = m_active
+ incr
in
2743 if next < 0 || next >= itemcount
2745 else find next incr1
2747 if abs
(m_active
- next) > fstate
.maxrows
2753 let first = m_first
+ incr
in
2754 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2756 let next = m_active
+ incr
in
2757 let next = bound
next 0 (itemcount - 1) in
2764 if isvisible first next
2771 let first = min
next m_first
in
2773 if abs
(next - first) > fstate
.maxrows
2779 let first = m_first
+ incr
in
2780 let first = bound
first 0 (itemcount - 1) in
2782 let next = m_active
+ incr
in
2783 let next = bound
next 0 (itemcount - 1) in
2784 let next = find next incr1 in
2786 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2788 let active = if m_active
= -1 then next else m_active
in
2793 if isvisible first active
2799 G.postRedisplay "listview navigate";
2803 let kt = Wsi.kc2kt
key in
2804 match [@warning
"-4"] kt with
2805 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2806 let incr = if c = 'r'
then -1 else 1 in
2808 match search (m_active
+ incr) m_qsearch
incr with
2810 state
.text <- m_qsearch ^
" [not found]";
2813 state
.text <- m_qsearch
;
2814 active, firstof m_first
active
2816 G.postRedisplay "listview ctrl-r/s";
2817 set1 active first m_qsearch
;
2819 | Insert
when Wsi.withctrl mask
->
2820 if m_active
>= 0 && m_active
< source#getitemcount
2822 let s, _ = source#getitem m_active
in
2828 if emptystr m_qsearch
2831 let qsearch = withoutlastutf8 m_qsearch
in
2835 G.postRedisplay "listview empty qsearch";
2836 set1 m_active m_first
E.s;
2840 match search m_active
qsearch ~
-1 with
2842 state
.text <- qsearch ^
" [not found]";
2845 state
.text <- qsearch;
2846 active, firstof m_first
active
2848 G.postRedisplay "listview backspace qsearch";
2849 set1 active first qsearch
2852 | Ascii
_ | Code
_ ->
2854 match [@warning
"-4"] kt with
2855 | Ascii
c -> String.make
1 c
2856 | Code code
-> toutf8 code
2859 let pattern = m_qsearch ^
utf8 in
2861 match search m_active
pattern 1 with
2863 state
.text <- pattern ^
" [not found]";
2866 state
.text <- pattern;
2867 active, firstof m_first
active
2869 G.postRedisplay "listview qsearch add";
2870 set1 active first pattern;
2874 if emptystr m_qsearch
2876 G.postRedisplay "list view escape";
2877 let mx, my
= state
.mpos
in
2879 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2880 ~
first:m_first ~pan
:m_pan
with
2881 | None
-> m_prev_uioh
2885 G.postRedisplay "list view kill qsearch";
2886 coe {< m_qsearch
= E.s >}
2891 let self = {< m_qsearch
= E.s >} in
2893 G.postRedisplay "listview enter";
2894 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2895 source#exit ~uioh
:(coe self) ~
cancel
2896 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2898 begin match opt with
2899 | None
-> m_prev_uioh
2906 | Up
-> navigate ~
-1
2907 | Down
-> navigate 1
2908 | Prior
-> navigate ~
-(fstate
.maxrows
)
2909 | Next
-> navigate fstate
.maxrows
2913 G.postRedisplay "listview right";
2914 coe {< m_pan
= m_pan
- 1 >}
2918 G.postRedisplay "listview left";
2919 coe {< m_pan
= m_pan
+ 1 >}
2922 let active = find 0 1 in
2923 G.postRedisplay "listview home";
2927 let first = max
0 (itemcount - fstate
.maxrows
) in
2928 let active = find (itemcount - 1) ~
-1 in
2929 G.postRedisplay "listview end";
2934 method key key mask
=
2935 match state
.mode
with
2937 textentrykeyboard
key mask te
;
2939 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2941 method button button down
x y _ =
2944 | 1 when vscrollhit x ->
2945 G.postRedisplay "listview scroll";
2948 let _, position, sh = self#
scrollph in
2949 if y > truncate
position && y < truncate
(position +. sh)
2951 state
.mstate
<- Mscrolly
;
2955 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2956 let first = truncate
(s *. float source#getitemcount
) in
2957 let first = min source#getitemcount
first in
2958 Some
(coe {< m_first
= first; m_active
= first >})
2960 state
.mstate
<- Mnone
;
2964 begin match self#elemunder
y with
2966 G.postRedisplay "listview click";
2967 source#exit ~uioh
:(coe {< m_active
= n >})
2968 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2972 | n when (n == 4 || n == 5) && not down
->
2973 let len = source#getitemcount
in
2975 if n = 5 && m_first
+ fstate
.maxrows
>= len
2979 let first = m_first
+ (if n == 4 then -1 else 1) in
2980 bound
first 0 (len - 1)
2982 G.postRedisplay "listview wheel";
2983 Some
(coe {< m_first
= first >})
2984 | n when (n = 6 || n = 7) && not down
->
2985 let inc = if n = 7 then -1 else 1 in
2986 G.postRedisplay "listview hwheel";
2987 Some
(coe {< m_pan
= m_pan
+ inc >})
2992 | None
-> m_prev_uioh
2995 method multiclick
_ x y = self#button
1 true x y
2998 match state
.mstate
with
3000 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3001 let first = truncate
(s *. float source#getitemcount
) in
3002 let first = min source#getitemcount
first in
3003 G.postRedisplay "listview motion";
3004 coe {< m_first
= first; m_active
= first >}
3012 method pmotion
x y =
3013 if x < state
.winw
- conf
.scrollbw
3016 match self#elemunder
y with
3017 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3018 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3022 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3027 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3031 method infochanged
_ = ()
3033 method scrollpw
= (0, 0.0, 0.0)
3035 let nfs = fstate
.fontsize
+ 1 in
3036 let y = m_first
* nfs in
3037 let itemcount = source#getitemcount
in
3038 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3039 let maxy = maxi * nfs in
3040 let p, h = scrollph y maxy in
3043 method modehash
= modehash
3044 method eformsgs
= false
3045 method alwaysscrolly
= true
3048 class outlinelistview ~zebra ~source
=
3049 let settext autonarrow
s =
3052 let ss = source#statestr
in
3056 else "{" ^
ss ^
"} [" ^
s ^
"]"
3057 else state
.text <- s
3063 ~source
:(source
:> lvsource
)
3065 ~modehash
:(findkeyhash conf
"outline")
3068 val m_autonarrow
= false
3070 method! key key mask
=
3072 if emptystr state
.text
3074 else fstate
.maxrows - 2
3076 let calcfirst first active =
3079 let rows = active - first in
3080 if rows > maxrows then active - maxrows else first
3084 let active = m_active
+ incr in
3085 let active = bound
active 0 (source#getitemcount
- 1) in
3086 let first = calcfirst m_first
active in
3087 G.postRedisplay "outline navigate";
3088 coe {< m_active
= active; m_first
= first >}
3090 let navscroll first =
3092 let dist = m_active
- first in
3098 else first + maxrows
3101 G.postRedisplay "outline navscroll";
3102 coe {< m_first
= first; m_active
= active >}
3104 let ctrl = Wsi.withctrl mask
in
3106 match Wsi.kc2kt
key with
3107 | Ascii '
a'
when ctrl ->
3110 then (source#denarrow
; E.s)
3112 let pattern = source#renarrow
in
3113 if nonemptystr m_qsearch
3114 then (source#narrow m_qsearch
; m_qsearch
)
3118 settext (not m_autonarrow
) text;
3119 G.postRedisplay "toggle auto narrowing";
3120 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3122 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3124 G.postRedisplay "toggle auto narrowing";
3125 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3127 | Ascii '
n'
when ctrl ->
3128 source#narrow m_qsearch
;
3130 then source#add_narrow_pattern m_qsearch
;
3131 G.postRedisplay "outline ctrl-n";
3132 coe {< m_first
= 0; m_active
= 0 >}
3134 | Ascii 'S'
when ctrl ->
3135 let active = source#calcactive
(getanchor
()) in
3136 let first = firstof m_first
active in
3137 G.postRedisplay "outline ctrl-s";
3138 coe {< m_first
= first; m_active
= active >}
3140 | Ascii 'u'
when ctrl ->
3141 G.postRedisplay "outline ctrl-u";
3142 if m_autonarrow
&& nonemptystr m_qsearch
3144 ignore
(source#renarrow
);
3145 settext m_autonarrow
E.s;
3146 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3149 source#del_narrow_pattern
;
3150 let pattern = source#renarrow
in
3152 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3154 settext m_autonarrow
text;
3155 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3158 | Ascii '
l'
when ctrl ->
3159 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3160 G.postRedisplay "outline ctrl-l";
3161 coe {< m_first
= first >}
3163 | Ascii '
\t'
when m_autonarrow
->
3164 if nonemptystr m_qsearch
3166 G.postRedisplay "outline list view tab";
3167 source#add_narrow_pattern m_qsearch
;
3169 coe {< m_qsearch
= E.s >}
3173 | Escape
when m_autonarrow
->
3174 if nonemptystr m_qsearch
3175 then source#add_narrow_pattern m_qsearch
;
3178 | Enter
when m_autonarrow
->
3179 if nonemptystr m_qsearch
3180 then source#add_narrow_pattern m_qsearch
;
3183 | _ when m_autonarrow
->
3184 let pattern = m_qsearch ^ toutf8
key in
3185 G.postRedisplay "outlinelistview autonarrow add";
3186 source#narrow
pattern;
3187 settext true pattern;
3188 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3190 | key when m_autonarrow
&& key = Backspace
->
3191 if emptystr m_qsearch
3194 let pattern = withoutlastutf8 m_qsearch
in
3195 G.postRedisplay "outlinelistview autonarrow backspace";
3196 ignore
(source#renarrow
);
3197 source#narrow
pattern;
3198 settext true pattern;
3199 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3202 navscroll (max
0 (m_first
- 1))
3205 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3207 | Up
-> navigate ~
-1
3208 | Down
-> navigate 1
3209 | Prior
-> navigate ~
-(fstate
.maxrows)
3210 | Next
-> navigate fstate
.maxrows
3216 G.postRedisplay "outline ctrl right";
3217 {< m_pan
= m_pan
+ 1 >}
3219 else self#updownlevel
1
3227 G.postRedisplay "outline ctrl left";
3228 {< m_pan
= m_pan
- 1 >}
3230 else self#updownlevel ~
-1
3235 G.postRedisplay "outline home";
3236 coe {< m_first
= 0; m_active
= 0 >}
3239 let active = source#getitemcount
- 1 in
3240 let first = max
0 (active - fstate
.maxrows) in
3241 G.postRedisplay "outline end";
3242 coe {< m_active
= active; m_first
= first >}
3244 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Backspace
|Fn
_ ->
3248 let genhistoutlines () =
3250 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3251 compare c2
.lastvisit c1
.lastvisit
)
3252 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3253 let path = if nonemptystr origin
then origin
else path in
3254 let base = mbtoutf8
@@ Filename.basename
path in
3255 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3259 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3260 Config.save
leavebirdseye;
3261 state
.anchor <- anchor;
3262 state
.bookmarks
<- bookmarks
;
3263 state
.origin
<- origin
;
3266 let x0, y0, x1, y1 = conf
.trimfuzz
in
3267 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3268 reshape ~firsttime
:true state
.winw state
.winh
;
3269 opendoc path origin
;
3273 let makecheckers () =
3274 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3276 converted by Issac Trotts. July 25, 2002 *)
3277 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3278 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3279 let id = GlTex.gen_texture
() in
3280 GlTex.bind_texture ~target
:`texture_2d
id;
3281 GlPix.store
(`unpack_alignment
1);
3282 GlTex.image2d
image;
3283 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3284 [ `mag_filter `nearest
; `min_filter `nearest
];
3288 let setcheckers enabled
=
3289 match state
.checkerstexid
with
3291 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3293 | Some checkerstexid
->
3296 GlTex.delete_texture checkerstexid
;
3297 state
.checkerstexid
<- None
;
3301 let describe_location () =
3302 let fn = page_of_y state
.y in
3303 let ln = page_of_y
(state
.y + state
.winh
- 1) in
3304 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
3308 else (100. *. (float state
.y /. float maxy))
3312 Printf.sprintf
"page %d of %d [%.2f%%]"
3313 (fn+1) state
.pagecount
percent
3316 "pages %d-%d of %d [%.2f%%]"
3317 (fn+1) (ln+1) state
.pagecount
percent
3320 let setpresentationmode v
=
3321 let n = page_of_y state
.y in
3322 state
.anchor <- (n, 0.0, 1.0);
3323 conf
.presentation
<- v
;
3324 if conf
.fitmodel
= FitPage
3325 then reqlayout conf
.angle conf
.fitmodel
;
3329 let setbgcol (r
, g, b) =
3331 let r = r *. 255.0 |> truncate
3332 and g = g *. 255.0 |> truncate
3333 and b = b *. 255.0 |> truncate
in
3334 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3336 Wsi.setwinbgcol
col;
3340 let btos b = if b then UniSyms.radical else E.s in
3341 let showextended = ref false in
3342 let leave mode
_ = state
.mode
<- mode
in
3345 val mutable m_l
= []
3346 val mutable m_a
= E.a
3347 val mutable m_prev_uioh
= nouioh
3348 val mutable m_prev_mode
= View
3350 inherit lvsourcebase
3352 method reset prev_mode prev_uioh
=
3353 m_a
<- Array.of_list
(List.rev m_l
);
3355 m_prev_mode
<- prev_mode
;
3356 m_prev_uioh
<- prev_uioh
;
3358 method int name get
set =
3364 try set (int_of_string
s)
3366 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3370 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3371 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3375 method int_with_suffix name get
set =
3377 (name
, `intws get
, 1,
3381 try set (int_of_string_with_suffix
s)
3383 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3388 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3390 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3394 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3396 (name
, `
bool (btos, get
), offset
, Action
(
3403 method color name get
set =
3405 (name
, `
color get
, 1,
3408 let invalid = (nan
, nan
, nan
) in
3411 try color_of_string
s
3413 state
.text <- Printf.sprintf
"bad color `%s': %s"
3420 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3421 state
.text <- color_to_string
(get
());
3422 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3426 method string name get
set =
3428 (name
, `
string get
, 1,
3431 let ondone s = set s in
3432 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3433 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3437 method colorspace name get
set =
3439 (name
, `
string get
, 1,
3444 inherit lvsourcebase
3447 m_active
<- CSTE.to_int conf
.colorspace
;
3450 method getitemcount
=
3451 Array.length
CSTE.names
3454 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3455 ignore
(uioh
, first, pan
);
3456 if not
cancel then set active;
3458 method hasaction
_ = true
3462 let modehash = findkeyhash conf
"info" in
3463 coe (new listview ~zebra
:false ~helpmode
:false
3464 ~
source ~trusted
:true ~
modehash)
3467 method paxmark name get
set =
3469 (name
, `
string get
, 1,
3474 inherit lvsourcebase
3477 m_active
<- MTE.to_int conf
.paxmark
;
3480 method getitemcount
= Array.length
MTE.names
3481 method getitem
n = (MTE.names
.(n), 0)
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 fitmodel name get
set =
3497 (name
, `
string get
, 1,
3502 inherit lvsourcebase
3505 m_active
<- FMTE.to_int conf
.fitmodel
;
3508 method getitemcount
= Array.length
FMTE.names
3509 method getitem
n = (FMTE.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 caption
s offset
=
3524 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3526 method caption2
s f offset
=
3527 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3529 method getitemcount
= Array.length m_a
3532 let tostr = function
3533 | `
int f -> string_of_int
(f ())
3534 | `intws
f -> string_with_suffix_of_int
(f ())
3536 | `
color f -> color_to_string
(f ())
3537 | `
bool (btos, f) -> btos (f ())
3540 let name, t
, offset
, _ = m_a
.(n) in
3541 ((let s = tostr t
in
3543 then Printf.sprintf
"%s\t%s" name s
3547 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3552 match m_a
.(active) with
3553 | _, _, _, Action
f -> f uioh
3554 | _, _, _, Noaction
-> uioh
3565 method hasaction
n =
3567 | _, _, _, Action
_ -> true
3568 | _, _, _, Noaction
-> false
3570 initializer m_active
<- 1
3573 let rec fillsrc prevmode prevuioh
=
3574 let sep () = src#caption
E.s 0 in
3575 let colorp name get
set =
3577 (fun () -> color_to_string
(get
()))
3580 let c = color_of_string
v in
3584 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3587 let oldmode = state
.mode
in
3588 let birdseye = isbirdseye state
.mode
in
3590 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3592 src#
bool "presentation mode"
3593 (fun () -> conf
.presentation
)
3594 (fun v -> setpresentationmode v);
3596 src#
bool "ignore case in searches"
3597 (fun () -> conf
.icase
)
3598 (fun v -> conf
.icase
<- v);
3601 (fun () -> conf
.preload)
3602 (fun v -> conf
.preload <- v);
3604 src#
bool "highlight links"
3605 (fun () -> conf
.hlinks
)
3606 (fun v -> conf
.hlinks
<- v);
3608 src#
bool "under info"
3609 (fun () -> conf
.underinfo
)
3610 (fun v -> conf
.underinfo
<- v);
3612 src#
bool "persistent bookmarks"
3613 (fun () -> conf
.savebmarks
)
3614 (fun v -> conf
.savebmarks
<- v);
3616 src#fitmodel
"fit model"
3617 (fun () -> FMTE.to_string conf
.fitmodel
)
3618 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3620 src#
bool "trim margins"
3621 (fun () -> conf
.trimmargins
)
3622 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3624 src#
bool "persistent location"
3625 (fun () -> conf
.jumpback
)
3626 (fun v -> conf
.jumpback
<- v);
3629 src#
int "inter-page space"
3630 (fun () -> conf
.interpagespace
)
3632 conf
.interpagespace
<- n;
3633 docolumns conf
.columns
;
3635 match state
.layout with
3640 state
.maxy <- calcheight
();
3641 let y = getpagey
pageno in
3642 gotoxy state
.x (y + py)
3646 (fun () -> conf
.pagebias
)
3647 (fun v -> conf
.pagebias
<- v);
3649 src#
int "scroll step"
3650 (fun () -> conf
.scrollstep
)
3651 (fun n -> conf
.scrollstep
<- n);
3653 src#
int "horizontal scroll step"
3654 (fun () -> conf
.hscrollstep
)
3655 (fun v -> conf
.hscrollstep
<- v);
3657 src#
int "auto scroll step"
3659 match state
.autoscroll
with
3661 | _ -> conf
.autoscrollstep
)
3663 let n = boundastep state
.winh
n in
3664 if state
.autoscroll
<> None
3665 then state
.autoscroll
<- Some
n;
3666 conf
.autoscrollstep
<- n);
3669 (fun () -> truncate
(conf
.zoom *. 100.))
3670 (fun v -> pivotzoom ((float v) /. 100.));
3673 (fun () -> conf
.angle
)
3674 (fun v -> reqlayout v conf
.fitmodel
);
3676 src#
int "scroll bar width"
3677 (fun () -> conf
.scrollbw
)
3680 reshape state
.winw state
.winh
;
3683 src#
int "scroll handle height"
3684 (fun () -> conf
.scrollh
)
3685 (fun v -> conf
.scrollh
<- v;);
3687 src#
int "thumbnail width"
3688 (fun () -> conf
.thumbw
)
3690 conf
.thumbw
<- min
4096 v;
3693 leavebirdseye beye
false;
3700 let mode = state
.mode in
3701 src#
string "columns"
3703 match conf
.columns
with
3705 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3706 | Csplit
(count
, _) -> "-" ^ string_of_int count
3709 let n, a, b = multicolumns_of_string
v in
3710 setcolumns mode n a b);
3713 src#caption
"Pixmap cache" 0;
3714 src#int_with_suffix
"size (advisory)"
3715 (fun () -> conf
.memlimit
)
3716 (fun v -> conf
.memlimit
<- v);
3720 Printf.sprintf
"%s bytes, %d tiles"
3721 (string_with_suffix_of_int state
.memused
)
3722 (Hashtbl.length state
.tilemap
)) 1;
3725 src#caption
"Layout" 0;
3726 src#caption2
"Dimension"
3728 Printf.sprintf
"%dx%d (virtual %dx%d)"
3729 state
.winw state
.winh
3734 src#caption2
"Position" (fun () ->
3735 Printf.sprintf
"%dx%d" state
.x state
.y
3738 src#caption2
"Position" (fun () -> describe_location ()) 1
3742 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3743 "Save these parameters as global defaults at exit"
3744 (fun () -> conf
.bedefault
)
3745 (fun v -> conf
.bedefault
<- v)
3749 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3750 src#
bool ~offset
:0 ~
btos "Extended parameters"
3751 (fun () -> !showextended)
3752 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3756 (fun () -> conf
.checkers
)
3757 (fun v -> conf
.checkers
<- v; setcheckers v);
3758 src#
bool "update cursor"
3759 (fun () -> conf
.updatecurs
)
3760 (fun v -> conf
.updatecurs
<- v);
3761 src#
bool "scroll-bar on the left"
3762 (fun () -> conf
.leftscroll
)
3763 (fun v -> conf
.leftscroll
<- v);
3765 (fun () -> conf
.verbose
)
3766 (fun v -> conf
.verbose
<- v);
3767 src#
bool "invert colors"
3768 (fun () -> conf
.invert
)
3769 (fun v -> conf
.invert
<- v);
3771 (fun () -> conf
.maxhfit
)
3772 (fun v -> conf
.maxhfit
<- v);
3774 (fun () -> conf
.pax
!= None
)
3777 then conf
.pax
<- Some
(ref (now
(), 0, 0))
3778 else conf
.pax
<- None
);
3779 src#
string "uri launcher"
3780 (fun () -> conf
.urilauncher
)
3781 (fun v -> conf
.urilauncher
<- v);
3782 src#
string "path launcher"
3783 (fun () -> conf
.pathlauncher
)
3784 (fun v -> conf
.pathlauncher
<- v);
3785 src#
string "tile size"
3786 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3789 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3790 conf
.tilew
<- max
64 w;
3791 conf
.tileh
<- max
64 h;
3794 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3797 src#
int "texture count"
3798 (fun () -> conf
.texcount
)
3801 then conf
.texcount
<- v
3802 else impmsg "failed to set texture count please retry later"
3804 src#
int "slice height"
3805 (fun () -> conf
.sliceheight
)
3807 conf
.sliceheight
<- v;
3808 wcmd "sliceh %d" conf
.sliceheight
;
3810 src#
int "anti-aliasing level"
3811 (fun () -> conf
.aalevel
)
3813 conf
.aalevel
<- bound
v 0 8;
3814 state
.anchor <- getanchor
();
3815 opendoc state
.path state
.password;
3817 src#
string "page scroll scaling factor"
3818 (fun () -> string_of_float conf
.pgscale)
3821 let s = float_of_string
v in
3824 state
.text <- Printf.sprintf
3825 "bad page scroll scaling factor `%s': %s" v
3829 src#
int "ui font size"
3830 (fun () -> fstate
.fontsize
)
3831 (fun v -> setfontsize (bound
v 5 100));
3832 src#
int "hint font size"
3833 (fun () -> conf
.hfsize
)
3834 (fun v -> conf
.hfsize
<- bound
v 5 100);
3835 colorp "background color"
3836 (fun () -> conf
.bgcolor
)
3837 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3838 src#
bool "crop hack"
3839 (fun () -> conf
.crophack
)
3840 (fun v -> conf
.crophack
<- v);
3841 src#
string "trim fuzz"
3842 (fun () -> irect_to_string conf
.trimfuzz
)
3845 conf
.trimfuzz
<- irect_of_string
v;
3847 then settrim true conf
.trimfuzz
;
3849 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3852 src#
string "throttle"
3854 match conf
.maxwait
with
3855 | None
-> "show place holder if page is not ready"
3858 then "wait for page to fully render"
3860 "wait " ^ string_of_float
time
3861 ^
" seconds before showing placeholder"
3865 let f = float_of_string
v in
3867 then conf
.maxwait
<- None
3868 else conf
.maxwait
<- Some
f
3870 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3873 src#
string "ghyll scroll"
3875 match conf
.ghyllscroll
with
3877 | Some nab
-> ghyllscroll_to_string nab
3880 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3883 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3885 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3888 src#
string "selection command"
3889 (fun () -> conf
.selcmd
)
3890 (fun v -> conf
.selcmd
<- v);
3891 src#
string "synctex command"
3892 (fun () -> conf
.stcmd
)
3893 (fun v -> conf
.stcmd
<- v);
3894 src#
string "pax command"
3895 (fun () -> conf
.paxcmd
)
3896 (fun v -> conf
.paxcmd
<- v);
3897 src#
string "ask password command"
3898 (fun () -> conf
.passcmd)
3899 (fun v -> conf
.passcmd <- v);
3900 src#
string "save path command"
3901 (fun () -> conf
.savecmd
)
3902 (fun v -> conf
.savecmd
<- v);
3903 src#colorspace
"color space"
3904 (fun () -> CSTE.to_string conf
.colorspace
)
3906 conf
.colorspace
<- CSTE.of_int
v;
3910 src#paxmark
"pax mark method"
3911 (fun () -> MTE.to_string conf
.paxmark
)
3912 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3913 if bousable
() && !opengl_has_pbo
3916 (fun () -> conf
.usepbo
)
3917 (fun v -> conf
.usepbo
<- v);
3918 src#
bool "mouse wheel scrolls pages"
3919 (fun () -> conf
.wheelbypage
)
3920 (fun v -> conf
.wheelbypage
<- v);
3921 src#
bool "open remote links in a new instance"
3922 (fun () -> conf
.riani
)
3923 (fun v -> conf
.riani
<- v);
3924 src#
bool "edit annotations inline"
3925 (fun () -> conf
.annotinline
)
3926 (fun v -> conf
.annotinline
<- v);
3927 src#
bool "coarse positioning in presentation mode"
3928 (fun () -> conf
.coarseprespos
)
3929 (fun v -> conf
.coarseprespos
<- v);
3930 src#
bool "use document CSS"
3931 (fun () -> conf
.usedoccss
)
3933 conf
.usedoccss
<- v;
3934 state
.anchor <- getanchor
();
3935 opendoc state
.path state
.password;
3940 src#caption
"Document" 0;
3941 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3942 src#caption2
"Pages"
3943 (fun () -> string_of_int state
.pagecount
) 1;
3944 src#caption2
"Dimensions"
3945 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3946 if nonemptystr conf
.css
3947 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3951 src#caption
"Trimmed margins" 0;
3952 src#caption2
"Dimensions"
3953 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3957 src#caption
"OpenGL" 0;
3958 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3959 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3962 src#caption
"Location" 0;
3963 if nonemptystr state
.origin
3964 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3965 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3967 src#reset prevmode prevuioh
;
3972 let prevmode = state
.mode
3973 and prevuioh
= state
.uioh in
3974 fillsrc prevmode prevuioh
;
3975 let source = (src :> lvsource
) in
3976 let modehash = findkeyhash conf
"info" in
3979 inherit listview ~zebra
:false ~helpmode
:false
3980 ~
source ~trusted
:true ~
modehash as super
3981 val mutable m_prevmemused
= 0
3982 method! infochanged
= function
3984 if m_prevmemused
!= state
.memused
3986 m_prevmemused
<- state
.memused
;
3987 G.postRedisplay "memusedchanged";
3989 | Pdim
-> G.postRedisplay "pdimchanged"
3990 | Docinfo
-> fillsrc prevmode prevuioh
3992 method! key key mask
=
3993 if not
(Wsi.withctrl mask
)
3995 match [@warning
"-4"] Wsi.kc2kt
key with
3996 | Keys.Left
-> coe (self#updownlevel ~
-1)
3997 | Keys.Right
-> coe (self#updownlevel
1)
3998 | _ -> super#
key key mask
3999 else super#
key key mask
4001 G.postRedisplay "info";
4007 inherit lvsourcebase
4008 method getitemcount
= Array.length state
.help
4010 let s, l, _ = state
.help
.(n) in
4013 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4017 match state
.help
.(active) with
4018 | _, _, Action
f -> Some
(f uioh)
4019 | _, _, Noaction
-> Some
uioh
4028 method hasaction
n =
4029 match state
.help
.(n) with
4030 | _, _, Action
_ -> true
4031 | _, _, Noaction
-> false
4037 let modehash = findkeyhash conf
"help" in
4039 state
.uioh <- coe (new listview
4040 ~zebra
:false ~helpmode
:true
4041 ~
source ~trusted
:true ~
modehash);
4042 G.postRedisplay "help";
4048 inherit lvsourcebase
4049 val mutable m_items
= E.a
4051 method getitemcount
= 1 + Array.length m_items
4056 else m_items
.(n-1), 0
4058 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4063 then Buffer.clear state
.errmsgs
;
4070 method hasaction
n =
4074 state
.newerrmsgs
<- false;
4075 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4076 m_items
<- Array.of_list
l
4085 let source = (msgsource :> lvsource
) in
4086 let modehash = findkeyhash conf
"listview" in
4089 inherit listview ~zebra
:false ~helpmode
:false
4090 ~
source ~trusted
:false ~
modehash as super
4093 then msgsource#reset
;
4096 G.postRedisplay "msgs";
4100 let editor = getenvwithdef
"EDITOR" E.s in
4104 let tmppath = Filename.temp_file
"llpp" "note" in
4107 let oc = open_out
tmppath in
4111 let execstr = editor ^
" " ^
tmppath in
4113 match spawn
execstr [] with
4115 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4118 match Unix.waitpid
[] pid
with
4120 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4124 | Unix.WEXITED
0 -> filecontents
tmppath
4126 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4128 | Unix.WSIGNALED
n ->
4129 impmsg "editor process(%s) was killed by signal %d" execstr n;
4131 | Unix.WSTOPPED
n ->
4132 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4135 match Unix.unlink
tmppath with
4137 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4142 let enterannotmode opaque slinkindex
=
4145 inherit lvsourcebase
4146 val mutable m_text
= E.s
4147 val mutable m_items
= E.a
4149 method getitemcount
= Array.length m_items
4152 let label, _func
= m_items
.(n) in
4155 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4156 ignore
(uioh, first, pan
);
4159 let _label, func
= m_items
.(active) in
4164 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4167 let rec split accu b i
=
4169 if p = String.length
s
4170 then (String.sub s b (p-b), unit) :: accu
4172 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4174 let ss = if i
= 0 then E.s else String.sub s b i
in
4175 split ((ss, unit)::accu) (p+1) 0
4180 wcmd "freepage %s" (~
> opaque);
4182 Hashtbl.fold (fun key opaque'
accu ->
4183 if opaque'
= opaque'
4184 then key :: accu else accu) state
.pagemap
[]
4186 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4188 gotoxy state
.x state
.y
4191 delannot
opaque slinkindex
;
4194 let edit inline
() =
4199 modannot
opaque slinkindex
s;
4205 let mode = state
.mode in
4208 ("annotation: ", m_text
, None
, textentry
, update, true),
4209 fun _ -> state
.mode <- mode);
4213 let s = getusertext m_text
in
4218 ( "[Copy]", fun () -> selstring m_text
)
4219 :: ("[Delete]", dele)
4220 :: ("[Edit]", edit conf
.annotinline
)
4222 :: split [] 0 0 |> List.rev
|> Array.of_list
4229 let s = getannotcontents
opaque slinkindex
in
4232 let source = (msgsource :> lvsource
) in
4233 let modehash = findkeyhash conf
"listview" in
4234 state
.uioh <- coe (object
4235 inherit listview ~zebra
:false ~helpmode
:false
4236 ~
source ~trusted
:false ~
modehash
4238 G.postRedisplay "enterannotmode";
4241 let gotoremote spec
=
4242 let filename, dest
= splitatchar spec '#'
in
4243 let getpath filename =
4245 if nonemptystr
filename
4247 if Filename.is_relative
filename
4249 let dir = Filename.dirname state
.path in
4251 if Filename.is_implicit
dir
4252 then Filename.concat
(Sys.getcwd
()) dir
4255 Filename.concat
dir filename
4259 if Sys.file_exists
path
4263 let path = getpath filename in
4267 let cmd = Lazy.force_val lcmd
in
4268 match spawn
cmd with
4270 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4272 let anchor = getanchor
() in
4273 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4274 state
.origin
<- E.s;
4275 state
.ranchors
<- ranchor :: state
.ranchors
;
4278 if substratis spec
0 "page="
4280 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4282 state
.anchor <- (pageno, 0.0, 0.0);
4283 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4285 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4287 state
.nameddest
<- dest
;
4288 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4292 let gotounder = function
4293 | Ulinkuri
s when isexternallink
s ->
4294 if substratis
s 0 "file://"
4295 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4298 let pageno, x, y = uritolocation
s in
4300 gotopagexy !wtmode pageno x y
4301 | Utext
_ | Unone
-> ()
4302 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4305 let gotooutline (_, _, kind
) =
4309 let (pageno, y, _) = anchor in
4311 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4315 | Ouri
uri -> gotounder (Ulinkuri
uri)
4316 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4317 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4318 | Ohistory hist
-> gotohist hist
4319 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4322 class outlinesoucebase fetchoutlines
= object (self)
4323 inherit lvsourcebase
4324 val mutable m_items
= E.a
4325 val mutable m_minfo
= E.a
4326 val mutable m_orig_items
= E.a
4327 val mutable m_orig_minfo
= E.a
4328 val mutable m_narrow_patterns
= []
4329 val mutable m_gen
= -1
4331 method getitemcount
= Array.length m_items
4334 let s, n, _ = m_items
.(n) in
4337 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4338 ignore
(uioh, first);
4340 if m_narrow_patterns
= []
4341 then m_orig_items
, m_orig_minfo
4342 else m_items
, m_minfo
4349 gotooutline m_items
.(active);
4357 method hasaction
(_:int) = true
4360 if Array.length m_items
!= Array.length m_orig_items
4363 match m_narrow_patterns
with
4365 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4367 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4371 match m_narrow_patterns
with
4374 | head
:: _ -> UniSyms.ellipsis ^ head
4376 method narrow
pattern =
4377 match Str.regexp_case_fold
pattern with
4380 let rec loop accu minfo n =
4383 m_items
<- Array.of_list
accu;
4384 m_minfo
<- Array.of_list
minfo;
4387 let (s, _, _) as o = m_items
.(n) in
4389 match Str.search_forward re
s 0 with
4390 | exception Not_found
-> accu, minfo
4391 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4393 loop accu minfo (n-1)
4395 loop [] [] (Array.length m_items
- 1)
4397 method! getminfo
= m_minfo
4400 m_orig_items
<- fetchoutlines
();
4401 m_minfo
<- m_orig_minfo
;
4402 m_items
<- m_orig_items
4404 method add_narrow_pattern
pattern =
4405 m_narrow_patterns
<- pattern :: m_narrow_patterns
4407 method del_narrow_pattern
=
4408 match m_narrow_patterns
with
4409 | _ :: rest
-> m_narrow_patterns
<- rest
4414 match m_narrow_patterns
with
4415 | pattern :: [] -> self#narrow
pattern; pattern
4417 List.fold_left
(fun accu pattern ->
4418 self#narrow
pattern;
4419 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4421 method calcactive
(_:anchor) = 0
4423 method reset
anchor items =
4424 if state
.gen
!= m_gen
4426 m_orig_items
<- items;
4428 m_narrow_patterns
<- [];
4430 m_orig_minfo
<- E.a;
4434 if items != m_orig_items
4436 m_orig_items
<- items;
4437 if m_narrow_patterns
== []
4438 then m_items
<- items;
4441 let active = self#calcactive
anchor in
4443 m_first
<- firstof m_first
active
4447 let outlinesource fetchoutlines
=
4449 inherit outlinesoucebase fetchoutlines
4450 method! calcactive
anchor =
4451 let rely = getanchory anchor in
4452 let rec loop n best bestd
=
4453 if n = Array.length m_items
4456 let _, _, kind
= m_items
.(n) in
4459 let orely = getanchory anchor in
4460 let d = abs
(orely - rely) in
4463 else loop (n+1) best bestd
4464 | Onone
| Oremote
_ | Olaunch
_
4465 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4466 loop (n+1) best bestd
4472 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4473 let mkselector sourcetype
=
4474 let fetchoutlines () =
4475 match sourcetype
with
4476 | `bookmarks
-> Array.of_list state
.bookmarks
4477 | `outlines
-> state
.outlines
4478 | `history
-> genhistoutlines () |> Array.of_list
4481 if sourcetype
= `history
4482 then new outlinesoucebase
fetchoutlines
4483 else outlinesource fetchoutlines
4486 let outlines = fetchoutlines () in
4487 if Array.length
outlines = 0
4488 then showtext ' ' errmsg
4491 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4492 let anchor = getanchor
() in
4493 source#reset
anchor outlines;
4494 state
.text <- source#greetmsg
;
4496 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4497 G.postRedisplay "enter selector";
4501 let mkenter sourcetype errmsg
=
4502 let enter = mkselector sourcetype
in
4503 fun () -> enter errmsg
4505 ( mkenter `
outlines "document has no outline"
4506 , mkenter `bookmarks
"document has no bookmarks (yet)"
4507 , mkenter `history
"history is empty" )
4510 let quickbookmark ?title
() =
4511 match state
.layout with
4518 let tm = localtime
(now
()) in
4520 "Quick (page %d) (bookmarked at %02d/%02d/%d %02d:%02d)"
4522 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4523 | Some
title -> title
4525 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4528 let setautoscrollspeed step goingdown
=
4529 let incr = max
1 ((abs step
) / 2) in
4530 let incr = if goingdown
then incr else -incr in
4531 let astep = boundastep state
.winh
(step
+ incr) in
4532 state
.autoscroll
<- Some
astep;
4536 match conf
.columns
with
4538 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4541 let panbound x = bound
x (-state
.w) state
.winw
;;
4543 let existsinrow pageno (columns
, coverA
, coverB
) p =
4544 let last = ((pageno - coverA
) mod columns
) + columns
in
4545 let rec any = function
4548 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4552 then (if l.pageno = last then false else any rest
)
4560 match state
.layout with
4562 let pageno = page_of_y state
.y in
4563 gotoghyll (getpagey
(pageno+1))
4565 match conf
.columns
with
4567 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4569 let y = clamp (pgscale state
.winh
) in
4572 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4573 gotoghyll (getpagey
pageno)
4574 | Cmulti
((c, _, _) as cl
, _) ->
4575 if conf
.presentation
4576 && (existsinrow l.pageno cl
4577 (fun l -> l.pageh
> l.pagey + l.pagevh))
4579 let y = clamp (pgscale state
.winh
) in
4582 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4583 gotoghyll (getpagey
pageno)
4585 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4587 let pagey, pageh
= getpageyh
l.pageno in
4588 let pagey = pagey + pageh
* l.pagecol
in
4589 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4590 gotoghyll (pagey + pageh
+ ips)
4594 match state
.layout with
4596 let pageno = page_of_y state
.y in
4597 gotoghyll (getpagey
(pageno-1))
4599 match conf
.columns
with
4601 if conf
.presentation
&& l.pagey != 0
4603 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4605 let pageno = max
0 (l.pageno-1) in
4606 gotoghyll (getpagey
pageno)
4607 | Cmulti
((c, _, coverB
) as cl
, _) ->
4608 if conf
.presentation
&&
4609 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4611 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4614 if l.pageno = state
.pagecount
- coverB
4618 let pageno = max
0 (l.pageno-decr) in
4619 gotoghyll (getpagey
pageno)
4627 let pageno = max
0 (l.pageno-1) in
4628 let pagey, pageh
= getpageyh
pageno in
4631 let pagey, pageh
= getpageyh
l.pageno in
4632 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4638 if emptystr conf
.savecmd
4639 then error
"don't know where to save modified document"
4641 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4644 (fun s -> error
"failed to obtain path to the saved copy: %s" s)
4649 let tmp = path ^
".tmp" in
4651 Unix.rename
tmp path;
4654 let viewkeyboard key mask
=
4656 let mode = state
.mode in
4657 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4660 G.postRedisplay "view:enttext"
4662 let ctrl = Wsi.withctrl mask
in
4664 match Wsi.kc2kt
key with
4665 | Ascii 'Q'
-> exit
0
4668 if hasunsavedchanges
()
4672 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4675 match state
.lnava
with
4676 | None
-> LinkNav
(Ltgendir
0)
4677 | Some
pn -> LinkNav
(Ltexact
pn)
4679 gotoxy state
.x state
.y;
4681 else impmsg "keyboard link navigation does not work under rotation"
4683 | Escape
| Ascii 'q'
->
4684 begin match state
.mstate
with
4687 G.postRedisplay "kill rect";
4690 | Mscrolly
| Mscrollx
4693 begin match state
.mode with
4696 | Ltexact pl
-> state
.lnava
<- Some pl
4697 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4700 G.postRedisplay "esc leave linknav"
4701 | Birdseye
_ | Textentry
_ | View
->
4702 match state
.ranchors
with
4704 | (path, password, anchor, origin
) :: rest
->
4705 state
.ranchors
<- rest
;
4706 state
.anchor <- anchor;
4707 state
.origin
<- origin
;
4708 state
.nameddest
<- E.s;
4709 opendoc path password
4714 gotoghyll (getnav ~
-1)
4725 Hashtbl.iter
(fun _ opaque ->
4727 Hashtbl.clear state
.prects
) state
.pagemap
;
4728 G.postRedisplay "dehighlight";
4730 | (Ascii '
/'
| Ascii '?'
) as pv
->
4731 let ondone isforw
s =
4732 cbput state
.hists
.pat
s;
4733 state
.searchpattern
<- s;
4736 let s = String.make
1 (Char.chr
key) in
4737 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4738 textentry
, ondone (pv
= Ascii '
/'
), true)
4740 | Ascii '
+'
| Ascii '
='
when ctrl ->
4741 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4742 pivotzoom (conf
.zoom +. incr)
4747 try int_of_string
s with exn
->
4748 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4754 state
.text <- "page bias is now " ^ string_of_int
n;
4757 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4759 | Ascii '
-'
when ctrl ->
4760 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4761 pivotzoom (max
0.01 (conf
.zoom -. decr))
4764 let ondone msg
= state
.text <- msg
in
4766 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4767 optentry state
.mode, ondone, true
4770 | Ascii '
0'
when ctrl ->
4772 then gotoxy 0 state
.y
4775 | Ascii
('
1'
|'
2'
as c)
4776 when ctrl && conf
.fitmodel
!= FitPage
->
4778 match conf
.columns
with
4779 | Csingle
_ | Cmulti
_ -> 1
4780 | Csplit
(n, _) -> n
4782 let h = state
.winh
-
4783 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4785 let zoom = zoomforh state
.winw
h 0 cols in
4786 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4789 | Ascii '
3'
when ctrl ->
4791 match conf
.fitmodel
with
4792 | FitWidth
-> FitProportional
4793 | FitProportional
-> FitPage
4794 | FitPage
-> FitWidth
4796 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4797 reqlayout conf
.angle
fm
4799 | Ascii '
4'
when ctrl ->
4800 let zoom = getmaxw
() /. float state
.winw
in
4801 if zoom > 0.0 then setzoom zoom
4806 | Ascii '
9'
when ctrl ->
4813 try int_of_string
s with exn
->
4814 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4820 cbput state
.hists
.pag
(string_of_int
n);
4821 gotopage1 (n + conf
.pagebias
- 1) 0;
4824 let [@warning
"-4"] pageentry
text = function
4825 | Keys.Ascii '
g'
-> TEdone
text
4826 | key -> intentry
text key
4828 let text = String.make
1 (Char.chr
key) in
4829 enttext (":", text, Some
(onhist state
.hists
.pag
),
4830 pageentry
, ondone, true)
4833 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4834 G.postRedisplay "toggle scrollbar";
4837 state
.bzoom
<- not state
.bzoom
;
4839 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4842 conf
.hlinks
<- not conf
.hlinks
;
4843 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4844 G.postRedisplay "toggle highlightlinks";
4847 if conf
.angle
mod 360 = 0
4849 state
.glinks
<- true;
4850 let mode = state
.mode in
4853 (":", E.s, None
, linknentry
, linknact gotounder, false),
4855 state
.glinks
<- false;
4859 G.postRedisplay "view:linkent(F)"
4861 else impmsg "hint mode does not work under rotation"
4864 state
.glinks
<- true;
4865 let mode = state
.mode in
4869 ":", E.s, None
, linknentry
, linknact (fun under ->
4870 selstring (undertext under);
4874 state
.glinks
<- false;
4878 G.postRedisplay "view:linkent"
4881 begin match state
.autoscroll
with
4883 conf
.autoscrollstep
<- step
;
4884 state
.autoscroll
<- None
4886 if conf
.autoscrollstep
= 0
4887 then state
.autoscroll
<- Some
1
4888 else state
.autoscroll
<- Some conf
.autoscrollstep
4891 | Ascii '
p'
when ctrl ->
4892 launchpath () (* XXX where do error messages go? *)
4895 setpresentationmode (not conf
.presentation
);
4896 showtext ' '
("presentation mode " ^
4897 if conf
.presentation
then "on" else "off");
4900 if List.mem
Wsi.Fullscreen state
.winstate
4901 then Wsi.reshape conf
.cwinw conf
.cwinh
4902 else Wsi.fullscreen
()
4904 | Ascii
('
p'
|'N'
) ->
4905 search state
.searchpattern
false
4907 | Ascii '
n'
| Fn
3 ->
4908 search state
.searchpattern
true
4911 begin match state
.layout with
4914 gotoghyll (getpagey
l.pageno)
4924 showtext ' '
(describe_location ());
4927 begin match state
.layout with
4930 Wsi.reshape l.pagew
l.pageh
;
4935 enterbookmarkmode
()
4937 | Ascii '
h'
| Fn
1 ->
4943 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4948 match state
.layout with
4953 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4956 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
4960 showtext ' '
"Quick bookmark added";
4963 begin match state
.layout with
4965 let rect = getpdimrect
l.pagedimno
in
4969 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4970 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4972 (truncate
(rect.(1) -. rect.(0)),
4973 truncate
(rect.(3) -. rect.(0)))
4975 let w = truncate
((float w)*.conf
.zoom)
4976 and h = truncate
((float h)*.conf
.zoom) in
4979 state
.anchor <- getanchor
();
4980 Wsi.reshape w (h + conf
.interpagespace
)
4982 G.postRedisplay "z";
4987 | Ascii '
x'
-> state
.roam
()
4989 | Ascii
('
<'
|'
>'
as c) ->
4991 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
4993 | Ascii
('
['
|'
]'
as c) ->
4995 bound
(conf
.colorscale
+. (if c = '
>'
then 0.1 else -0.1)) 0.0 1.0;
4996 G.postRedisplay "brightness";
4998 | Ascii '
c'
when state
.mode = View
->
5003 let m = (state
.winw
- state
.w) / 2 in
5004 gotoxy_and_clear_text m state
.y
5008 match state
.prevcolumns
with
5009 | None
-> (1, 0, 0), 1.0
5010 | Some
(columns
, z
) ->
5013 | Csplit
(c, _) -> -c, 0, 0
5014 | Cmulti
((c, a, b), _) -> c, a, b
5015 | Csingle
_ -> 1, 0, 0
5019 setcolumns View
c a b;
5022 | Down
| Up
when ctrl && Wsi.withshift mask
->
5023 let zoom, x = state
.prevzoom
in
5028 begin match state
.autoscroll
with
5030 begin match state
.mode with
5031 | Birdseye beye
-> upbirdseye 1 beye
5032 | Textentry
_ | View
| LinkNav
_ ->
5034 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5036 if not
(Wsi.withshift mask
) && conf
.presentation
5038 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5042 setautoscrollspeed n false
5045 | Ascii 'j'
| Down
->
5046 begin match state
.autoscroll
with
5048 begin match state
.mode with
5049 | Birdseye beye
-> downbirdseye 1 beye
5050 | Textentry
_ | View
| LinkNav
_ ->
5052 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5054 if not
(Wsi.withshift mask
) && conf
.presentation
5056 else gotoghyll1 true (clamp (conf
.scrollstep
))
5060 setautoscrollspeed n true
5063 | Left
| Right
when not
(Wsi.withalt mask
) ->
5069 else conf
.hscrollstep
5072 let pv = Wsi.kc2kt
key in
5073 if pv = Keys.Left
then dx else -dx
5075 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5078 G.postRedisplay "left/right"
5085 match state
.layout with
5087 | l :: _ -> state
.y - l.pagey
5089 clamp (pgscale (-state
.winh
))
5097 match List.rev state
.layout with
5099 | l :: _ -> getpagey
l.pageno
5101 clamp (pgscale state
.winh
)
5105 | Ascii '
g'
| Home
->
5108 | Ascii 'G'
| End
->
5110 gotoghyll (clamp state
.maxy)
5112 | Right
when Wsi.withalt mask
->
5113 gotoghyll (getnav 1)
5114 | Left
when Wsi.withalt mask
->
5115 gotoghyll (getnav ~
-1)
5120 | Ascii '
v'
when conf
.debug
->
5123 match getopaque l.pageno with
5126 let x0, y0, x1, y1 = pagebbox
opaque in
5127 let rect = (float x0, float y0,
5130 float x0, float y1) in
5132 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5133 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5135 G.postRedisplay "v";
5138 let mode = state
.mode in
5139 let cmd = ref E.s in
5140 let onleave = function
5141 | Cancel
-> state
.mode <- mode
5144 match getopaque l.pageno with
5145 | Some
opaque -> pipesel opaque !cmd
5146 | None
-> ()) state
.layout;
5150 cbput state
.hists
.sel
s;
5154 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
5156 G.postRedisplay "|";
5157 state
.mode <- Textentry
(te, onleave);
5159 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_) ->
5160 vlog "huh? %s" (Wsi.keyname
key)
5163 let linknavkeyboard key mask
linknav =
5164 let pv = Wsi.kc2kt
key in
5165 let getpage pageno =
5166 let rec loop = function
5168 | l :: _ when l.pageno = pageno -> Some
l
5169 | _ :: rest
-> loop rest
5170 in loop state
.layout
5172 let doexact (pageno, n) =
5173 match getopaque pageno, getpage pageno with
5174 | Some
opaque, Some
l ->
5177 let under = getlink
opaque n in
5178 G.postRedisplay "link gotounder";
5186 Some
(findlink
opaque LDfirst
), -1
5189 Some
(findlink
opaque LDlast
), 1
5192 Some
(findlink
opaque (LDleft
n)), -1
5195 Some
(findlink
opaque (LDright
n)), 1
5198 Some
(findlink
opaque (LDup
n)), -1
5201 Some
(findlink
opaque (LDdown
n)), 1
5203 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
5204 | Code
_|Fn
_|Backspace
-> None
, 0
5207 begin match findpwl
l.pageno dir with
5211 state
.mode <- LinkNav
(Ltgendir
dir);
5212 let y, h = getpageyh
pageno in
5215 then y + h - state
.winh
5220 begin match getopaque pageno, getpage pageno with
5221 | Some
opaque, Some
_ ->
5223 let ld = if dir > 0 then LDfirst
else LDlast
in
5226 begin match link with
5228 showlinktype (getlink
opaque m);
5229 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5230 G.postRedisplay "linknav jpage";
5231 | Lnotfound
-> notfound dir
5237 begin match opt with
5238 | Some Lnotfound
-> pwl l dir;
5239 | Some
(Lfound
m) ->
5243 let _, y0, _, y1 = getlinkrect
opaque m in
5245 then gotopage1 l.pageno y0
5247 let d = fstate
.fontsize
+ 1 in
5248 if y1 - l.pagey > l.pagevh - d
5249 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5250 else G.postRedisplay "linknav";
5252 showlinktype (getlink
opaque m);
5253 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5256 | None
-> viewkeyboard key mask
5258 | _ -> viewkeyboard key mask
5262 begin match linknav with
5263 | Ltexact pa
-> state
.lnava
<- Some pa
5264 | Ltgendir
_ | Ltnotready
_ -> ()
5267 G.postRedisplay "leave linknav"
5271 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5272 | Ltexact exact
-> doexact exact
5275 let keyboard key mask
=
5276 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5277 then wcmd "interrupt"
5278 else state
.uioh <- state
.uioh#
key key mask
5281 let birdseyekeyboard key mask
5282 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5284 match conf
.columns
with
5286 | Cmulti
((c, _, _), _) -> c
5287 | Csplit
_ -> failwith
"bird's eye split mode"
5289 let pgh layout = List.fold_left
5290 (fun m l -> max
l.pageh
m) state
.winh
layout in
5292 match Wsi.kc2kt
key with
5293 | Ascii '
l'
when Wsi.withctrl mask
->
5294 let y, h = getpageyh
pageno in
5295 let top = (state
.winh
- h) / 2 in
5296 gotoxy state
.x (max
0 (y - top))
5297 | Enter
-> leavebirdseye beye
false
5298 | Escape
-> leavebirdseye beye
true
5299 | Up
-> upbirdseye incr beye
5300 | Down
-> downbirdseye incr beye
5301 | Left
-> upbirdseye 1 beye
5302 | Right
-> downbirdseye 1 beye
5305 begin match state
.layout with
5309 state
.mode <- Birdseye
(
5310 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5312 gotopage1 l.pageno 0;
5315 let layout = layout state
.x (state
.y-state
.winh
)
5317 (pgh state
.layout) in
5319 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5321 state
.mode <- Birdseye
(
5322 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5324 gotopage1 l.pageno 0
5327 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5331 begin match List.rev state
.layout with
5333 let layout = layout state
.x
5334 (state
.y + (pgh state
.layout))
5335 state
.winw state
.winh
in
5336 begin match layout with
5338 let incr = l.pageh
- l.pagevh in
5343 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5345 G.postRedisplay "birdseye pagedown";
5347 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5351 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5352 gotopage1 l.pageno 0;
5355 | [] -> gotoxy state
.x (clamp state
.winh
)
5359 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5363 let pageno = state
.pagecount
- 1 in
5364 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5365 if not
(pagevisible state
.layout pageno)
5368 match List.rev state
.pdims
with
5370 | (_, _, h, _) :: _ -> h
5374 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5375 else G.postRedisplay "birdseye end";
5377 | Delete
|Insert
|Ascii
_|Code
_|Fn
_|Backspace
-> viewkeyboard key mask
5382 match state
.mode with
5383 | Textentry
_ -> scalecolor 0.4
5384 | LinkNav
_ | View
-> scalecolor 1.0
5385 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5386 if l.pageno = hooverpageno
5389 if l.pageno = pageno
5391 let c = scalecolor 1.0 in
5393 GlDraw.line_width
3.0;
5394 let dispx = l.pagedispx in
5396 (float (dispx-1)) (float (l.pagedispy-1))
5397 (float (dispx+l.pagevw+1))
5398 (float (l.pagedispy+l.pagevh+1))
5400 GlDraw.line_width
1.0;
5409 let postdrawpage l linkindexbase
=
5410 match getopaque l.pageno with
5412 if tileready l l.pagex
l.pagey
5414 let x = l.pagedispx - l.pagex
5415 and y = l.pagedispy - l.pagey in
5417 match conf
.columns
with
5418 | Csingle
_ | Cmulti
_ ->
5419 (if conf
.hlinks
then 1 else 0)
5421 && not
(isbirdseye state
.mode) then 2 else 0)
5425 match state
.mode with
5426 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5432 Hashtbl.find_all state
.prects
l.pageno |>
5433 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5434 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5436 then (state
.redisplay
<- true; 0)
5442 let scrollindicator () =
5443 let sbw, ph
, sh = state
.uioh#
scrollph in
5444 let sbh, pw, sw = state
.uioh#scrollpw
in
5449 else ((state
.winw
- sbw), state
.winw
, 0)
5453 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5454 GlDraw.color (0.64, 0.64, 0.64) ~
alpha:0.7;
5455 filledrect (float x0) 0. (float x1) (float state
.winh
);
5457 (float hx0
) (float (state
.winh
- sbh))
5458 (float (hx0
+ state
.winw
)) (float state
.winh
)
5460 GlDraw.color (0.0, 0.0, 0.0) ~
alpha:0.7;
5462 filledrect (float x0) ph
(float x1) (ph
+. sh);
5463 let pw = pw +. float hx0
in
5464 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5469 match state
.mstate
with
5470 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5473 | Msel
((x0, y0), (x1, y1)) ->
5474 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5475 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5476 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5477 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5484 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5485 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5487 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5489 if l.pageno = pageno
5491 let dx = float (l.pagedispx - l.pagex
) in
5492 let dy = float (l.pagedispy - l.pagey) in
5493 let r, g, b, alpha = c in
5494 GlDraw.color (r, g, b) ~
alpha;
5495 filledrect2 (x0+.dx) (y0+.dy)
5507 begin match conf
.columns
, state
.layout with
5508 | Csingle
_, _ :: _ ->
5509 GlDraw.color (scalecolor2 conf
.bgcolor
);
5511 List.fold_left
(fun y l ->
5514 let x1 = l.pagedispx in
5515 let y1 = (l.pagedispy + l.pagevh) in
5516 filledrect (float x0) (float y0) (float x1) (float y1);
5517 let x0 = x1 + l.pagevw in
5518 let x1 = state
.winw
in
5519 filledrect1 (float x0) (float y0) (float x1) (float y1);
5523 and x1 = state
.winw
in
5525 and y1 = l.pagedispy in
5526 filledrect1 (float x0) (float y0) (float x1) (float y1);
5528 l.pagedispy + l.pagevh) 0 state
.layout
5531 and x1 = state
.winw
in
5533 and y1 = state
.winh
in
5534 filledrect1 (float x0) (float y0) (float x1) (float y1)
5535 | (Cmulti
_ | Csplit
_), _ | Csingle
_, [] ->
5536 GlClear.color (scalecolor2 conf
.bgcolor
);
5537 GlClear.clear
[`
color];
5539 List.iter
drawpage state
.layout;
5541 match state
.mode with
5542 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5543 begin match getopaque pageno with
5545 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5546 let color = (0.0, 0.0, 0.5, 0.5) in
5553 | None
-> state
.rects
5555 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5558 | View
-> state
.rects
5561 let rec postloop linkindexbase
= function
5563 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5564 postloop linkindexbase rest
5568 postloop 0 state
.layout;
5570 begin match state
.mstate
with
5571 | Mzoomrect
((x0, y0), (x1, y1)) ->
5573 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5574 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5575 filledrect (float x0) (float y0) (float x1) (float y1);
5579 | Mscrolly
| Mscrollx
5588 let zoomrect x y x1 y1 =
5591 and y0 = min
y y1 in
5592 let zoom = (float state
.w) /. float (x1 - x0) in
5595 if state
.w < state
.winw
5596 then (state
.winw
- state
.w) / 2
5599 match conf
.fitmodel
with
5600 | FitWidth
| FitProportional
-> simple ()
5602 match conf
.columns
with
5604 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5605 | Cmulti
_ | Csingle
_ -> simple ()
5607 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5608 state
.anchor <- getanchor
();
5613 let annot inline
x y =
5614 match unproject x y with
5615 | Some
(opaque, n, ux
, uy
) ->
5617 addannot
opaque ux uy
text;
5618 wcmd "freepage %s" (~
> opaque);
5619 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5621 gotoxy state
.x state
.y
5625 let ondone s = add s in
5626 let mode = state
.mode in
5627 state
.mode <- Textentry
(
5628 ("annotation: ", E.s, None
, textentry
, ondone, true),
5629 fun _ -> state
.mode <- mode);
5632 G.postRedisplay "annot"
5634 add @@ getusertext E.s
5639 let g opaque l px py =
5640 match rectofblock
opaque px py with
5642 let x0 = a.(0) -. 20. in
5643 let x1 = a.(1) +. 20. in
5644 let y0 = a.(2) -. 20. in
5645 let zoom = (float state
.w) /. (x1 -. x0) in
5646 let pagey = getpagey
l.pageno in
5647 let margin = (state
.w - l.pagew
)/2 in
5648 let nx = -truncate
x0 - margin in
5649 gotoxy_and_clear_text nx (pagey + truncate
y0);
5650 state
.anchor <- getanchor
();
5655 match conf
.columns
with
5657 impmsg "block zooming does not work properly in split columns mode"
5658 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5662 let winw = state
.winw - 1 in
5663 let s = float x /. float winw in
5664 let destx = truncate
(float (state
.w + winw) *. s) in
5665 gotoxy_and_clear_text (winw - destx) state
.y;
5666 state
.mstate
<- Mscrollx
;
5670 let s = float y /. float state
.winh
in
5671 let desty = truncate
(float (state
.maxy -
5672 (if conf
.maxhfit
then state
.winh
else 0))
5674 gotoxy_and_clear_text state
.x desty;
5675 state
.mstate
<- Mscrolly
;
5678 let viewmulticlick clicks
x y mask
=
5679 let g opaque l px py =
5687 if markunder
opaque px py mark
5691 match getopaque l.pageno with
5693 | Some
opaque -> pipesel opaque cmd
5695 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5696 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5701 G.postRedisplay "viewmulticlick";
5702 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5706 match conf
.columns
with
5708 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5711 let viewmouse button down
x y mask
=
5713 | n when (n == 4 || n == 5) && not down
->
5714 if Wsi.withctrl mask
5716 match state
.mstate
with
5717 | Mzoom
(oldn
, i
, (ftx
, fty
)) ->
5720 then abs
(ftx
- x) > 5 || abs
(fty
- y) > 5
5730 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5732 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5734 let zoom = conf
.zoom -. incr in
5736 then pivotzoom ~
x ~
y zoom
5737 else pivotzoom zoom;
5738 state
.mstate
<- Mzoom
(n, 0, (x, y));
5740 state
.mstate
<- Mzoom
(n, i
+1, (ftx
, fty
));
5742 else state
.mstate
<- Mzoom
(n, 0, (ftx
, fty
))
5746 | Mscrolly
| Mscrollx
5748 | Mnone
-> state
.mstate
<- Mzoom
(n, 0, (0, 0))
5751 match state
.autoscroll
with
5752 | Some step
-> setautoscrollspeed step
(n=4)
5754 if conf
.wheelbypage
|| conf
.presentation
5763 then -conf
.scrollstep
5764 else conf
.scrollstep
5766 let incr = incr * 2 in
5767 let y = clamp incr in
5768 gotoxy_and_clear_text state
.x y
5771 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5773 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5774 gotoxy_and_clear_text x state
.y
5776 | 1 when Wsi.withshift mask
->
5777 state
.mstate
<- Mnone
;
5780 match unproject x y with
5782 | Some
(_, pageno, ux
, uy
) ->
5783 let cmd = Printf.sprintf
5785 conf
.stcmd state
.path pageno ux uy
5787 match spawn
cmd [] with
5789 impmsg "execution of synctex command(%S) failed: %S"
5790 conf
.stcmd
@@ exntos exn
5794 | 1 when Wsi.withctrl mask
->
5797 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5798 state
.mstate
<- Mpan
(x, y)
5801 state
.mstate
<- Mnone
5806 if Wsi.withshift mask
5808 annot conf
.annotinline
x y;
5809 G.postRedisplay "addannot"
5813 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5814 state
.mstate
<- Mzoomrect
(p, p)
5817 match state
.mstate
with
5818 | Mzoomrect
((x0, y0), _) ->
5819 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5820 then zoomrect x0 y0 x y
5823 G.postRedisplay "kill accidental zoom rect";
5827 | Mscrolly
| Mscrollx
5829 | Mnone
-> resetmstate ()
5832 | 1 when vscrollhit x ->
5835 let _, position, sh = state
.uioh#
scrollph in
5836 if y > truncate
position && y < truncate
(position +. sh)
5837 then state
.mstate
<- Mscrolly
5840 state
.mstate
<- Mnone
5842 | 1 when y > state
.winh
- hscrollh () ->
5845 let _, position, sw = state
.uioh#scrollpw
in
5846 if x > truncate
position && x < truncate
(position +. sw)
5847 then state
.mstate
<- Mscrollx
5850 state
.mstate
<- Mnone
5852 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5855 let dest = if down
then getunder x y else Unone
in
5856 begin match dest with
5860 | Unone
when down
->
5861 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5862 state
.mstate
<- Mpan
(x, y);
5864 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5866 | Unone
| Utext
_ ->
5871 state
.mstate
<- Msel
((x, y), (x, y));
5872 G.postRedisplay "mouse select";
5876 match state
.mstate
with
5879 | Mzoom
_ | Mscrollx
| Mscrolly
->
5880 state
.mstate
<- Mnone
5882 | Mzoomrect
((x0, y0), _) ->
5886 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5887 state
.mstate
<- Mnone
5889 | Msel
((x0, y0), (x1, y1)) ->
5890 let rec loop = function
5894 let a0 = l.pagedispy in
5895 let a1 = a0 + l.pagevh in
5896 let b0 = l.pagedispx in
5897 let b1 = b0 + l.pagevw in
5898 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5899 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5903 match getopaque l.pageno with
5906 match Unix.pipe
() with
5908 impmsg "cannot create sel pipe: %s" @@
5912 Ne.clo fd
(fun msg
->
5913 dolog
"%s close failed: %s" what msg
)
5915 begin match spawn
cmd [r, 0; w, -1] with
5917 clo "Msel pipe/w" w;
5918 dolog
"cannot execute %S: %s" cmd @@ exntos exn
5921 G.postRedisplay "copysel";
5923 clo "Msel pipe/r" r;
5925 dosel conf
.selcmd
();
5926 state
.roam
<- dosel conf
.paxcmd
;
5938 let birdseyemouse button down
x y mask
5939 (conf
, leftx
, _, hooverpageno
, anchor) =
5942 let rec loop = function
5945 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5946 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5948 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5954 | _ -> viewmouse button down
x y mask
5960 method key key mask
=
5961 begin match state
.mode with
5962 | Textentry textentry
-> textentrykeyboard
key mask textentry
5963 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5964 | View
-> viewkeyboard key mask
5965 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5969 method button button bstate
x y mask
=
5970 begin match state
.mode with
5971 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5972 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5977 method multiclick clicks
x y mask
=
5978 begin match state
.mode with
5979 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5980 | Birdseye
_ | Textentry
_ -> ()
5985 begin match state
.mode with
5987 | View
| Birdseye
_ | LinkNav
_ ->
5988 match state
.mstate
with
5989 | Mzoom
_ | Mnone
-> ()
5994 state
.mstate
<- Mpan
(x, y);
5995 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5997 gotoxy_and_clear_text x y
6000 state
.mstate
<- Msel
(a, (x, y));
6001 G.postRedisplay "motion select";
6004 let y = min state
.winh
(max
0 y) in
6008 let x = min state
.winw (max
0 x) in
6011 | Mzoomrect
(p0
, _) ->
6012 state
.mstate
<- Mzoomrect
(p0
, (x, y));
6013 G.postRedisplay "motion zoomrect";
6017 method pmotion
x y =
6018 begin match state
.mode with
6019 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6020 let rec loop = function
6022 if hooverpageno
!= -1
6024 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6025 G.postRedisplay "pmotion birdseye no hoover";
6028 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6029 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6031 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6032 G.postRedisplay "pmotion birdseye hoover";
6040 | LinkNav
_ | View
->
6041 match state
.mstate
with
6042 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6050 let past, _, _ = !r in
6052 let delta = now -. past in
6055 else r := (now, x, y)
6059 method infochanged
_ = ()
6062 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
6065 then 0.0, float state
.winh
6066 else scrollph state
.y maxy
6071 let fwinw = float (state
.winw - vscrollw ()) in
6073 let sw = fwinw /. float state
.w in
6074 let sw = fwinw *. sw in
6075 max
sw (float conf
.scrollh
)
6078 let maxx = state
.w + state
.winw in
6079 let x = state
.winw - state
.x in
6080 let percent = float x /. float maxx in
6081 (fwinw -. sw) *. percent
6083 hscrollh (), position, sw
6087 match state
.mode with
6088 | LinkNav
_ -> "links"
6089 | Textentry
_ -> "textentry"
6090 | Birdseye
_ -> "birdseye"
6093 findkeyhash conf
modename
6095 method eformsgs
= true
6096 method alwaysscrolly
= false
6099 let addrect pageno r g b a x0 y0 x1 y1 =
6100 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6104 let cl = splitatchar cmds ' '
in
6106 try Scanf.sscanf
s fmt
f
6107 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6110 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6111 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6112 s pageno r g b a x0 y0 x1 y1;
6116 let _,w1,h1
,_ = getpagedim
pageno in
6117 let sw = float w1 /. float w
6118 and sh = float h1
/. float h in
6122 and y1s
= y1 *. sh in
6123 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6124 let color = (r, g, b, a) in
6125 if conf
.verbose
then debugrect rect;
6126 state
.rects <- (pageno, color, rect) :: state
.rects;
6131 | "reload", "" -> reload ()
6133 scan args
"%u %f %f"
6135 let cmd, _ = state
.geomcmds
in
6137 then gotopagexy !wtmode pageno x y
6140 gotopagexy !wtmode pageno x y;
6143 state
.reprf
<- f state
.reprf
6145 | "goto1", args
-> scan args
"%u %f" gotopage
6148 (fun _filename _pageno
->
6149 failwith
"gotounder (Uremote (filename, pageno))")
6152 (fun _filename _dest
->
6153 failwith
"gotounder (Uremotedest (filename, dest))")
6155 scan args
"%u %u %f %f %f %f"
6156 (fun pageno c x0 y0 x1 y1 ->
6157 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6158 rectx "rect" pageno color x0 y0 x1 y1;
6161 scan args
"%u %f %f %f %f %f %f %f %f"
6162 (fun pageno r g b alpha x0 y0 x1 y1 ->
6163 addrect pageno r g b alpha x0 y0 x1 y1;
6164 G.postRedisplay "prect"
6167 scan args
"%u %f %f"
6170 match getopaque pageno with
6171 | Some
opaque -> opaque
6174 pgoto optopaque pageno x y;
6175 let rec fixx = function
6178 if l.pageno = pageno
6179 then gotoxy (state
.x - l.pagedispx) state
.y
6184 match conf
.columns
with
6185 | Csingle
_ | Csplit
_ -> 1
6186 | Cmulti
((n, _, _), _) -> n
6188 layout 0 state
.y (state
.winw * mult) state
.winh
6192 | "activatewin", "" -> Wsi.activatewin
()
6193 | "quit", "" -> raise Quit
6196 let l = Config.keys_of_string
keys in
6197 List.iter
(fun (k
, m) -> keyboard k
m) l
6198 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6201 | "clearrects", "" ->
6202 Hashtbl.clear state
.prects
;
6203 G.postRedisplay "clearrects"
6205 adderrfmt "remote command"
6206 "error processing remote command: %S\n" cmds
;
6210 let scratch = Bytes.create
80 in
6211 let buf = Buffer.create
80 in
6213 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6214 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6217 if Buffer.length
buf > 0
6219 let s = Buffer.contents
buf in
6227 match Bytes.index_from
scratch ppos '
\n'
with
6228 | pos
-> if pos
>= n then -1 else pos
6229 | exception Not_found
-> -1
6233 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6234 let s = Buffer.contents
buf in
6240 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6246 let remoteopen path =
6247 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6249 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6254 let gcconfig = ref E.s in
6255 let trimcachepath = ref E.s in
6256 let rcmdpath = ref E.s in
6257 let pageno = ref None
in
6258 let rootwid = ref 0 in
6259 let openlast = ref false in
6260 let nofc = ref false in
6261 let doreap = ref false in
6262 let csspath = ref None
in
6263 selfexec := Sys.executable_name
;
6266 [("-p", Arg.String
(fun s -> state
.password <- s),
6267 "<password> Set password");
6271 Config.fontpath
:= s;
6272 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6274 "<path> Set path to the user interface font");
6278 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6279 Config.confpath
:= s),
6280 "<path> Set path to the configuration file");
6282 ("-last", Arg.Set
openlast, " Open last document");
6284 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6285 "<page-number> Jump to page");
6287 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6288 "<path> Set path to the trim cache file");
6290 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6291 "<named-destination> Set named destination");
6293 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6294 ("-cxack", Arg.Set
cxack, " Cut corners");
6296 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6297 "<path> Set path to the source of remote commands");
6299 ("-gc", Arg.Set_string
gcconfig,
6300 "<path> Collect garbage with the help of a script");
6302 ("-nofc", Arg.Set
nofc, " Do not use fontconfig");
6304 ("-v", Arg.Unit
(fun () ->
6306 "%s\nconfiguration path: %s\n"
6309 exit
0), " Print version and exit");
6311 ("-css", Arg.String
(fun s -> csspath := Some
s),
6312 "<path> Set path to the style sheet to use with EPUB/HTML");
6314 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6316 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6317 "<origin> <undocumented>");
6320 (fun s -> state
.path <- s)
6321 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6324 then selfexec := !selfexec ^
" -wtmode";
6326 let histmode = emptystr state
.path && not
!openlast in
6328 if not
(Config.load !openlast)
6329 then dolog
"failed to load configuration";
6331 begin match !pageno with
6332 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6336 if nonemptystr
!gcconfig
6339 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6340 | exception exn
-> error
"socketpair for gc failed: %s" @@ exntos exn
6343 match spawn
!gcconfig [(c, 0); (c, 1); (s, -1)] with
6344 | exception exn
-> error
"failed to execute gc script: %s" @@ exntos exn
6346 Ne.clo c @@ (fun s -> error
"failed to close gc fd %s" s);
6353 val mutable m_clicks
= 0
6354 val mutable m_click_x
= 0
6355 val mutable m_click_y
= 0
6356 val mutable m_lastclicktime
= infinity
6358 method private cleanup =
6359 state
.roam
<- noroam
;
6360 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6361 method expose
= G.postRedisplay "expose"
6365 | Wsi.Unobscured
-> "unobscured"
6366 | Wsi.PartiallyObscured
-> "partiallyobscured"
6367 | Wsi.FullyObscured
-> "fullyobscured"
6369 vlog "visibility change %s" name
6370 method display = display ()
6371 method map mapped
= vlog "mapped %b" mapped
6372 method reshape w h =
6375 method mouse
b d x y m =
6376 if d && canselect ()
6379 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6386 if abs
x - m_click_x
> 10
6387 || abs
y - m_click_y
> 10
6388 || abs_float
(t -. m_lastclicktime
) > 0.3
6390 m_clicks
<- m_clicks
+ 1;
6391 m_lastclicktime
<- t;
6395 G.postRedisplay "cleanup";
6396 state
.uioh <- state
.uioh#button
b d x y m;
6398 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6403 m_lastclicktime
<- infinity
;
6404 state
.uioh <- state
.uioh#button
b d x y m
6408 state
.uioh <- state
.uioh#button
b d x y m
6411 state
.mpos
<- (x, y);
6412 state
.uioh <- state
.uioh#motion
x y
6413 method pmotion
x y =
6414 state
.mpos
<- (x, y);
6415 state
.uioh <- state
.uioh#pmotion
x y
6417 let mascm = m land (
6418 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6421 let x = state
.x and y = state
.y in
6423 if x != state
.x || y != state
.y then self#
cleanup
6425 match state
.keystate
with
6427 let km = k
, mascm in
6430 let modehash = state
.uioh#
modehash in
6431 try Hashtbl.find modehash km
6433 try Hashtbl.find (findkeyhash conf
"global") km
6434 with Not_found
-> KMinsrt
(k
, m)
6436 | KMinsrt
(k
, m) -> keyboard k
m
6437 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6438 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6440 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6441 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6442 state
.keystate
<- KSnone
6443 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6444 state
.keystate
<- KSinto
(keys, insrt
)
6445 | KSinto
_ -> state
.keystate
<- KSnone
6448 state
.mpos
<- (x, y);
6449 state
.uioh <- state
.uioh#pmotion
x y
6450 method leave = state
.mpos
<- (-1, -1)
6451 method winstate wsl
= state
.winstate
<- wsl
6452 method quit
= raise Quit
6455 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6457 setbgcol conf
.bgcolor
;
6460 if not
@@ List.exists
GlMisc.check_extension
6461 [ "GL_ARB_texture_rectangle"
6462 ; "GL_EXT_texture_recangle"
6463 ; "GL_NV_texture_rectangle" ]
6464 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6466 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6468 defconf
.sliceheight
<- 1024;
6469 defconf
.texcount
<- 32;
6470 defconf
.usepbo
<- true;
6474 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6476 dolog
"socketpair failed: %s" @@ exntos exn
;
6484 setcheckers conf
.checkers
;
6486 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6488 begin match !csspath with
6490 | Some
"" -> conf
.css
<- E.s
6492 let css = filecontents
path in
6493 let l = String.length
css in
6495 if substratis
css (l-2) "\r\n"
6496 then String.sub css 0 (l-2)
6497 else (if css.[l-1] = '
\n'
6498 then String.sub css 0 (l-1)
6502 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6503 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6504 !Config.fontpath
, !trimcachepath, !opengl_has_pbo, not
!nofc
6506 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6508 reshape ~firsttime
:true winw winh
;
6512 Wsi.settitle
"llpp (history)";
6516 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6517 opendoc state
.path state
.password;
6521 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6522 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6525 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6526 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6527 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6529 | _pid
, _status
-> reap ()
6531 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6535 if nonemptystr
!rcmdpath
6536 then remoteopen !rcmdpath
6541 let rec loop deadline
=
6547 let r = [state
.ss; state
.wsfd] in
6551 | Some fd
-> fd
:: r
6555 state
.redisplay
<- false;
6562 if deadline
= infinity
6564 else max
0.0 (deadline
-. now)
6569 try Unix.select
r [] [] timeout
6570 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6576 if state
.ghyll
== noghyll
6578 match state
.autoscroll
with
6579 | Some step
when step
!= 0 ->
6580 let y = state
.y + step
in
6581 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6584 then state
.maxy - fy
6585 else if y >= state
.maxy - fy then 0 else y
6587 if state
.mode = View
6588 then gotoxy_and_clear_text state
.x y
6589 else gotoxy state
.x y;
6592 else deadline
+. 0.01
6597 let rec checkfds = function
6599 | fd
:: rest
when fd
= state
.ss ->
6600 let cmd = rcmd state
.ss in
6604 | fd
:: rest
when fd
= state
.wsfd ->
6608 | fd
:: rest
when Some fd
= !optrfd ->
6609 begin match remote fd
with
6610 | None
-> optrfd := remoteopen !rcmdpath;
6611 | opt -> optrfd := opt
6616 dolog
"select returned unknown descriptor";
6622 if deadline
= infinity
6626 match state
.autoscroll
with
6627 | Some step
when step
!= 0 -> deadline1
6628 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6633 match loop infinity
with
6635 Config.save leavebirdseye;
6636 if hasunsavedchanges
()
6638 | _ -> error
"umpossible - infinity reached"