6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
10 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
11 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
12 external clearmark
: opaque
-> unit = "ml_clearmark";;
13 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
14 external getmaxw
: unit -> float = "ml_getmaxw";;
15 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
16 external measurestr
: int -> string -> float = "ml_measure_string";;
17 external postprocess
: opaque
-> int -> int -> int -> (int * string * int)
18 -> int = "ml_postprocess";;
19 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
20 external setaalevel
: int -> unit = "ml_setaalevel";;
21 external realloctexts
: int -> bool = "ml_realloctexts";;
22 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
23 external getlink
: opaque
-> int -> under
= "ml_getlink";;
24 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
25 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
26 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
27 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
28 external freepbo
: opaque
-> unit = "ml_freepbo";;
29 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
30 external bousable
: unit -> bool = "ml_bo_usable";;
31 external unproject
: opaque
-> int -> int
32 -> (int * int) option = "ml_unproject";;
33 external project
: opaque
-> int -> int -> float -> float
34 -> (float * float) = "ml_project";;
35 external drawtile
: tileparams
-> opaque
36 -> unit = "ml_drawtile";;
37 external rectofblock
: opaque
-> int -> int
38 -> float array
option = "ml_rectofblock";;
39 external begintiles
: unit -> unit = "ml_begintiles";;
40 external endtiles
: unit -> unit = "ml_endtiles";;
41 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
42 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
43 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
44 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
45 external savedoc
: string -> unit = "ml_savedoc";;
46 external getannotcontents
: opaque
-> slinkindex
47 -> string = "ml_getannotcontents";;
48 external drawprect
: opaque
-> int -> int -> float array
49 -> unit = "ml_drawprect";;
50 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
51 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
52 external uritolocation
: string
53 -> (pageno
* float * float) = "ml_uritolocation";;
54 external isexternallink
: string -> bool = "ml_isexternallink";;
56 (* copysel _will_ close the supplied descriptor *)
57 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
59 let selfexec = ref E.s
;;
60 let opengl_has_pbo = ref false;;
62 let drawstring size x y s
=
64 Gl.enable `texture_2d
;
65 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
66 ignore
(drawstr size x y s
);
68 Gl.disable `texture_2d
;
71 let drawstring1 size x y s
=
75 let drawstring2 size x y fmt
=
76 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
79 module UniSyms
= struct
80 let ellipsis = "\xe2\x80\xa6";;
81 let radical = "\xe2\x88\x9a";;
82 let lguillemet = "\xc2\xab";;
83 let rguillemet = "\xc2\xbb";;
98 l
.pagedispx l
.pagedispy
102 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
108 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
111 let isbirdseye = function
113 | Textentry _
| View
| LinkNav _
-> false
116 let istextentry = function
117 | Textentry _
-> true
118 | Birdseye _
| View
| LinkNav _
-> false
121 let wtmode = ref false;;
122 let cxack = ref false;;
124 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
127 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
128 && (state
.w
> state
.winw
))
134 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
135 && (state
.maxy
> state
.winh
))
143 else x
> state
.winw
- vscrollw ()
147 fstate
.fontsize
<- n
;
148 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
149 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
155 else Printf.kprintf ignore fmt
159 if emptystr conf
.pathlauncher
160 then dolog
"%s" state
.path
162 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
163 match spawn
command [] with
166 dolog
"failed to execute `%s': %s" command @@ exntos exn
172 let postRedisplay who
=
173 vlog "redisplay for [%S]" who
;
174 state
.redisplay
<- true;
178 let getopaque pageno
=
179 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
180 with Not_found
-> None
183 let pagetranslatepoint l x y
=
184 let dy = y
- l
.pagedispy
in
185 let y = dy + l
.pagey
in
186 let dx = x
- l
.pagedispx
in
187 let x = dx + l
.pagex
in
191 let onppundermouse g
x y d
=
194 begin match getopaque l
.pageno
with
196 let x0 = l
.pagedispx
in
197 let x1 = x0 + l
.pagevw
in
198 let y0 = l
.pagedispy
in
199 let y1 = y0 + l
.pagevh
in
200 if y >= y0 && y <= y1 && x >= x0 && x <= x1
202 let px, py
= pagetranslatepoint l
x y in
203 match g opaque l
px py
with
216 let g opaque l
px py
=
219 match rectofblock opaque
px py
with
220 | Some
[|x0;x1;y0;y1|] ->
221 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
222 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
223 state
.rects
<- [l
.pageno
, color, rect];
224 G.postRedisplay "getunder";
227 let under = whatsunder opaque
px py
in
228 if under = Unone
then None
else Some
under
230 onppundermouse g x y Unone
235 match unproject opaque
x y with
236 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
239 onppundermouse g x y None
;
243 state
.text
<- Printf.sprintf
"%c%s" c s
;
244 G.postRedisplay "showtext";
248 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
251 let pipef ?
(closew
=true) cap
f cmd
=
252 match Unix.pipe
() with
253 | exception exn
-> dolog
"%s cannot create pipe: %S" cap
@@ exntos exn
255 begin match spawn cmd
[r
, 0; w
, -1] with
256 | exception exn
-> dolog
"%s: cannot execute %S: %s" cap cmd
@@ exntos exn
259 Ne.clo r
(dolog
"%s failed to close r: %s" cap
);
260 if closew
then Ne.clo w
(dolog
"%s failed to close w: %s" cap
);
263 let pipesel opaque cmd
=
265 then pipef ~closew
:false "pipesel"
268 G.postRedisplay "pipesel"
273 let g opaque l
px py
=
274 if markunder opaque
px py conf
.paxmark
277 match getopaque l
.pageno
with
279 | Some opaque
-> pipesel opaque conf
.paxcmd
284 G.postRedisplay "paxunder";
285 if conf
.paxmark
= Mark_page
288 match getopaque l
.pageno
with
290 | Some opaque
-> clearmark opaque
) state
.layout
;
291 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
296 "selstring" (fun w
->
298 let l = String.length s
in
299 let bytes = Bytes.unsafe_of_string s
in
300 let n = tempfailureretry
(Unix.write w
bytes 0) l in
302 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n;
303 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
307 let undertext = function
310 | Utext s
-> "font: " ^ s
311 | Uannotation
(opaque
, slinkindex
) ->
312 "annotation: " ^ getannotcontents opaque slinkindex
315 let updateunder x y =
316 match getunder x y with
317 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
319 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
320 Wsi.setcursor
Wsi.CURSOR_INFO
322 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
323 Wsi.setcursor
Wsi.CURSOR_TEXT
325 if conf
.underinfo
then showtext 'a'
"nnotation";
326 Wsi.setcursor
Wsi.CURSOR_INFO
329 let showlinktype under =
330 if conf
.underinfo
&& under != Unone
331 then showtext ' '
@@ undertext under
334 let [@warning
"-4"] intentry_with_suffix text key
=
337 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
338 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
339 addchar
text @@ asciilower c
341 state
.text <- Printf.sprintf
"invalid key";
348 let b = Buffer.create
16 in
351 let b = Buffer.to_bytes
b in
352 wcmd state
.ss
b @@ Bytes.length
b
356 let nogeomcmds cmds
=
358 | s
, [] -> emptystr s
362 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
363 let rec fold accu
n =
364 if n = Array.length
b
367 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
370 || n = state
.pagecount
- coverB
371 || (n - coverA
) mod columns
= columns
- 1)
377 let pagey = max
0 (y - vy
) in
378 let pagedispy = if pagey > 0 then 0 else vy
- y in
379 let pagedispx, pagex
=
381 if n = coverA
- 1 || n = state
.pagecount
- coverB
382 then x + (sw
- w
) / 2
390 let vw = sw
- pagedispx in
391 let pw = w
- pagex
in
394 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
395 if pagevw > 0 && pagevh > 0
406 ; pagedispx = pagedispx
407 ; pagedispy = pagedispy
419 if Array.length
b = 0
421 else List.rev
(fold [] (page_of_y
y))
424 let layoutS (columns
, b) x y sw sh
=
425 let rec fold accu n =
426 if n = Array.length
b
429 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
437 let pagey = max
0 (y - vy
) in
438 let pagedispy = if pagey > 0 then 0 else vy
- y in
439 let pagedispx, pagex
=
453 let pagecolw = pagew
/columns
in
456 then pagedispx + ((sw
- pagecolw) / 2)
460 let vw = sw
- pagedispx in
461 let pw = pagew
- pagex
in
464 let pagevw = min
pagevw pagecolw in
465 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
466 if pagevw > 0 && pagevh > 0
477 ; pagedispx = pagedispx
478 ; pagedispy = pagedispy
479 ; pagecol
= n mod columns
493 let layout x y sw sh
=
494 if nogeomcmds state
.geomcmds
496 match conf
.columns
with
497 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
498 | Cmulti c
-> layoutN c
x y sw sh
499 | Csplit s
-> layoutS s
x y sw sh
503 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
505 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
508 let tilex = l.pagex
mod conf
.tilew
in
509 let tiley = l.pagey mod conf
.tileh
in
511 let col = l.pagex
/ conf
.tilew
in
512 let row = l.pagey / conf
.tileh
in
514 let rec rowloop row y0 dispy h
=
518 let dh = conf
.tileh
- y0 in
520 let rec colloop col x0 dispx w
=
524 let dw = conf
.tilew
- x0 in
526 f col row dispx dispy
x0 y0 dw dh;
527 colloop (col+1) 0 (dispx
+dw) (w
-dw)
530 colloop col tilex l.pagedispx l.pagevw;
531 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
534 if l.pagevw > 0 && l.pagevh > 0
535 then rowloop row tiley l.pagedispy l.pagevh;
538 let gettileopaque l col row =
540 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
542 try Some
(Hashtbl.find state
.tilemap
key)
543 with Not_found
-> None
546 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
547 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
548 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
551 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
552 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
553 GlArray.vertex `two state
.vraw
;
554 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
557 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
559 let filledrect x0 y0 x1 y1 =
560 GlArray.disable `texture_coord
;
561 filledrect1 x0 y0 x1 y1;
562 GlArray.enable `texture_coord
;
565 let linerect x0 y0 x1 y1 =
566 GlArray.disable `texture_coord
;
567 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
568 GlArray.vertex `two state
.vraw
;
569 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
570 GlArray.enable `texture_coord
;
573 let drawtiles l color =
576 let f col row x y tilex tiley w h
=
577 match gettileopaque l col row with
578 | Some
(opaque
, _
, t
) ->
579 let params = x, y, w
, h
, tilex, tiley in
581 then GlTex.env
(`mode `blend
);
582 drawtile
params opaque
;
584 then GlTex.env
(`mode `modulate
);
588 let s = Printf.sprintf
592 let w = measurestr fstate
.fontsize
s in
593 GlDraw.color (0.0, 0.0, 0.0);
594 filledrect (float (x-2))
597 (float (y + fstate
.fontsize
+ 2));
599 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
606 let lw = state
.winw
- x in
609 let lh = state
.winh
- y in
613 then GlTex.env
(`mode `blend
);
614 begin match state
.checkerstexid
with
616 Gl.enable `texture_2d
;
617 GlTex.bind_texture ~target
:`texture_2d id
;
621 and y1 = float (y+h
) in
623 let tw = float w /. 16.0
624 and th
= float h
/. 16.0 in
625 let tx0 = float tilex /. 16.0
626 and ty0
= float tiley /. 16.0 in
628 and ty1
= ty0
+. th
in
629 Raw.sets_float state
.vraw ~pos
:0
630 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
631 Raw.sets_float state
.traw ~pos
:0
632 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
633 GlArray.vertex `two state
.vraw
;
634 GlArray.tex_coord `two state
.traw
;
635 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
636 Gl.disable `texture_2d
;
639 GlDraw.color (1.0, 1.0, 1.0);
640 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
643 then GlTex.env
(`mode `modulate
);
644 if w > 128 && h
> fstate
.fontsize
+ 10
646 let c = if conf
.invert
then 1.0 else 0.0 in
647 GlDraw.color (c, c, c);
650 then (col*conf
.tilew
, row*conf
.tileh
)
653 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
662 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
664 let tilevisible1 l x y =
666 and ax1
= l.pagex
+ l.pagevw
668 and ay1
= l.pagey + l.pagevh in
672 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
673 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
675 let rx0 = max
ax0 bx0
676 and ry0
= max ay0 by0
677 and rx1
= min ax1
bx1
678 and ry1
= min ay1 by1
in
680 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
684 let tilevisible layout n x y =
685 let rec findpageinlayout m
= function
686 | l :: rest
when l.pageno
= n ->
687 tilevisible1 l x y || (
688 match conf
.columns
with
689 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
690 | Csplit _
| Csingle _
| Cmulti _
-> false
692 | _
:: rest
-> findpageinlayout 0 rest
695 findpageinlayout 0 layout;
698 let tileready l x y =
699 tilevisible1 l x y &&
700 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
703 let tilepage n p
layout =
704 let rec loop = function
708 let f col row _ _ _ _ _ _
=
709 if state
.currently
= Idle
711 match gettileopaque l col row with
714 let x = col*conf
.tilew
715 and y = row*conf
.tileh
in
717 let w = l.pagew
- x in
721 let h = l.pageh
- y in
726 then getpbo
w h conf
.colorspace
729 wcmd "tile %s %d %d %d %d %s"
730 (~
> p
) x y w h (~
> pbo);
733 l, p
, conf
.colorspace
, conf
.angle
,
734 state
.gen
, col, row, conf
.tilew
, conf
.tileh
743 if nogeomcmds state
.geomcmds
747 let preloadlayout x y sw sh
=
748 let y = if y < sh
then 0 else y - sh
in
749 let x = min
0 (x + sw
) in
757 if state
.currently
!= Idle
762 begin match getopaque l.pageno
with
764 wcmd "page %d %d" l.pageno
l.pagedimno
;
765 state
.currently
<- Loading
(l, state
.gen
);
767 tilepage l.pageno opaque pages
;
772 if nogeomcmds state
.geomcmds
778 if conf
.preload && state
.currently
= Idle
779 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
782 let layoutready layout =
783 let rec fold all ls
=
786 let seen = ref false in
787 let allvisible = ref true in
788 let foo col row _ _ _ _ _ _
=
790 allvisible := !allvisible &&
791 begin match gettileopaque l col row with
797 fold (!seen && !allvisible) rest
800 let alltilesvisible = fold true layout in
805 let y = bound
y 0 state
.maxy in
806 let y, layout, proceed
=
807 match conf
.maxwait
with
808 | Some time
when state
.ghyll
== noghyll
->
809 begin match state
.throttle
with
811 let layout = layout x y state
.winw state
.winh
in
812 let ready = layoutready layout in
816 state
.throttle
<- Some
(layout, y, now
());
818 else G.postRedisplay "gotoxy showall (None)";
820 | Some
(_
, _
, started
) ->
821 let dt = now
() -. started
in
824 state
.throttle
<- None
;
825 let layout = layout x y state
.winw state
.winh
in
827 G.postRedisplay "maxwait";
834 let layout = layout x y state
.winw state
.winh
in
835 if not
!wtmode || layoutready layout
836 then G.postRedisplay "gotoxy ready";
843 state
.layout <- layout;
844 begin match state
.mode
with
847 | Ltexact
(pageno
, linkno
) ->
848 let rec loop = function
850 state
.lnava
<- Some
(pageno
, linkno
);
851 state
.mode
<- LinkNav
(Ltgendir
0)
852 | l :: _
when l.pageno
= pageno
->
853 begin match getopaque pageno
with
854 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
856 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
857 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
858 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
859 then state
.mode
<- LinkNav
(Ltgendir
0)
861 | _
:: rest
-> loop rest
864 | Ltnotready _
| Ltgendir _
-> ()
866 | Birdseye _
| Textentry _
| View
-> ()
868 begin match state
.mode
with
869 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
870 if not
(pagevisible layout pageno
)
872 match state
.layout with
875 state
.mode
<- Birdseye
(
876 conf
, leftx
, l.pageno
, hooverpageno
, anchor
881 | Ltnotready
(_
, dir
)
884 let rec loop = function
887 match getopaque l.pageno
with
888 | None
-> Ltnotready
(l.pageno
, dir
)
893 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
895 if dir
> 0 then LDfirst
else LDlast
901 | Lnotfound
-> loop rest
903 showlinktype (getlink opaque
n);
904 Ltexact
(l.pageno
, n)
908 state
.mode
<- LinkNav
linknav
911 | Textentry _
| View
-> ()
915 state
.ghyll
<- noghyll
;
918 let mx, my
= state
.mpos
in
923 let conttiling pageno opaque
=
924 tilepage pageno opaque
926 then preloadlayout state
.x state
.y state
.winw state
.winh
930 let gotoxy_and_clear_text x y =
931 if not conf
.verbose
then state
.text <- E.s;
935 let getanchory (n, top
, dtop
) =
936 let y, h = getpageyh
n in
939 let ips = calcips
h in
940 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
942 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
945 let gotoanchor anchor
=
946 gotoxy state
.x (getanchory anchor
);
950 getanchor
() |> cbput state
.hists
.nav
;
954 getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;
958 let anchor = cbgetc state
.hists
.nav dir
in
962 let gotoghyll1 single
y =
964 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
966 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
968 then s (float f /. float a
)
971 then 1.0 -. s ((float (f-b) /. float (n-b)))
977 let ins = float a
*. 0.5
978 and outs
= float (n-b) *. 0.5 in
980 ins +. outs
+. float ones
982 let rec set nab
y sy
=
983 let (_N
, _A
, _B
), y =
986 let scl = if y > sy
then 2 else -2 in
987 let _N, _
, _
= nab
in
988 (_N,0,_N), y+conf
.scrollstep
*scl
990 let sum = summa
_N _A _B
in
991 let dy = float (y - sy
) in
995 then state
.ghyll
<- noghyll
998 let s = scroll n _N _A _B
in
999 let y1 = y1 +. ((s *. dy) /. sum) in
1000 gotoxy_and_clear_text state
.x (truncate
y1);
1001 state
.ghyll
<- gf (n+1) y1;
1005 | Some
y'
when single
-> set nab
y' state
.y
1006 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1008 gf 0 (float state
.y)
1011 match conf
.ghyllscroll
with
1012 | Some nab
when not conf
.presentation
->
1013 if state
.ghyll
== noghyll
1014 then set nab
y state
.y
1015 else state
.ghyll
(Some
y)
1017 gotoxy_and_clear_text state
.x y
1020 let gotoghyll = gotoghyll1 false;;
1022 let gotopage n top
=
1023 let y, h = getpageyh
n in
1024 let y = y + (truncate
(top
*. float h)) in
1028 let gotopage1 n top
=
1029 let y = getpagey
n in
1034 let invalidate ?
(redisplay
=false) s f =
1035 state
.redisplay
<- redisplay
;
1040 match state
.geomcmds
with
1041 | ps
, [] when emptystr ps
->
1043 state
.geomcmds
<- s, [];
1046 state
.geomcmds
<- ps
, [s, f];
1048 | ps
, (s'
, _
) :: rest
when s'
= s ->
1049 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1052 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1056 Hashtbl.iter
(fun _ opaque
->
1057 wcmd "freepage %s" (~
> opaque
);
1059 Hashtbl.clear state
.pagemap
;
1063 if not
(Queue.is_empty state
.tilelru
)
1065 Queue.iter
(fun (k
, p
, s) ->
1066 wcmd "freetile %s" (~
> p
);
1067 state
.memused
<- state
.memused
- s;
1068 Hashtbl.remove state
.tilemap k
;
1070 state
.uioh#infochanged Memused
;
1071 Queue.clear state
.tilelru
;
1077 let h = truncate
(float h*.conf
.zoom
) in
1078 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1082 let opendoc path password
=
1084 state
.password
<- password
;
1085 state
.gen
<- state
.gen
+ 1;
1086 state
.docinfo
<- [];
1087 state
.outlines
<- [||];
1090 setaalevel conf
.aalevel
;
1092 if emptystr state
.origin
1096 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1097 wcmd "open %d %d %d %s\000%s\000%s\000"
1098 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1099 path password conf
.css
;
1100 invalidate "reqlayout"
1102 wcmd "reqlayout %d %d %d %s\000"
1103 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1104 (stateh state
.winh
) state
.nameddest
1107 let sl = keystostrlist conf
in
1109 function | [] -> accu
1110 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1111 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1115 state
.anchor <- getanchor
();
1116 opendoc state
.path state
.password
;
1120 let c = c *. conf
.colorscale
in
1124 let scalecolor2 (r
, g, b) =
1125 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1128 let docolumns columns
=
1131 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1132 let rec loop pageno
pdimno pdim
y ph pdims
=
1133 if pageno
= state
.pagecount
1136 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1138 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1139 pdimno+1, pdim
, rest
1143 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1145 y + (if conf
.presentation
1146 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1147 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1150 a.(pageno
) <- (pdimno, x, y, pdim
);
1151 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1153 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1154 conf
.columns
<- Csingle
a;
1156 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1157 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1158 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1160 if m
= pageno
then () else
1161 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1164 let y = y + (rowh
- h) / 2 in
1165 a.(m
) <- (pdimno, x, y, pdim
);
1169 if pageno
= state
.pagecount
1170 then fixrow (((pageno
- 1) / columns
) * columns
)
1172 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1174 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1175 pdimno+1, pdim
, rest
1180 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1182 let x = (state
.winw
- w) / 2 in
1184 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1185 x, y + ips + rowh
, h
1188 if (pageno
- coverA
) mod columns
= 0
1190 let x = max
0 (state
.winw
- state
.w) / 2 in
1192 if conf
.presentation
1194 let ips = calcips
h in
1195 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1197 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1201 else x, y, max rowh
h
1205 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1208 if pageno
= columns
&& conf
.presentation
1210 let ips = calcips rowh
in
1211 for i
= 0 to pred columns
1213 let (pdimno, x, y, pdim
) = a.(i
) in
1214 a.(i
) <- (pdimno, x, y+ips, pdim
)
1220 fixrow (pageno
- columns
);
1225 a.(pageno
) <- (pdimno, x, y, pdim
);
1226 let x = x + w + xoff
*2 + conf
.interpagespace
in
1227 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1229 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1230 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1233 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1234 let rec loop pageno
pdimno pdim
y pdims
=
1235 if pageno
= state
.pagecount
1238 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1240 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1241 pdimno+1, pdim
, rest
1246 let rec loop1 n x y =
1247 if n = c then y else (
1248 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1249 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1252 let y = loop1 0 0 y in
1253 loop (pageno
+1) pdimno pdim
y pdims
1255 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1256 conf
.columns
<- Csplit
(c, a);
1260 docolumns conf
.columns
;
1261 state
.maxy <- calcheight
();
1262 if state
.reprf
== noreprf
1264 match state
.mode
with
1265 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1266 let y, h = getpageyh pageno
in
1267 let top = (state
.winh
- h) / 2 in
1268 gotoxy state
.x (max
0 (y - top))
1269 | Textentry _
| View
| LinkNav _
->
1270 let y = getanchory state
.anchor in
1271 let y = min
y (state
.maxy - state
.winh
) in
1276 state
.reprf
<- noreprf
;
1280 let reshape ?
(firsttime
=false) w h =
1281 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1282 if not firsttime
&& nogeomcmds state
.geomcmds
1283 then state
.anchor <- getanchor
();
1286 let w = truncate
(float w *. conf
.zoom
) in
1289 setfontsize fstate
.fontsize
;
1290 GlMat.mode `modelview
;
1291 GlMat.load_identity
();
1293 GlMat.mode `projection
;
1294 GlMat.load_identity
();
1295 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1296 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1297 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1302 else float state
.x /. float state
.w
1304 invalidate ~redisplay
:true "geometry"
1308 then state
.x <- truncate
(relx *. float w);
1310 match conf
.columns
with
1312 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1313 | Csplit
(c, _
) -> w * c
1315 wcmd "geometry %d %d %d"
1316 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1321 let len = String.length state
.text in
1322 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1325 match state
.mode
with
1326 | Textentry _
| View
| LinkNav _
->
1327 let h, _
, _
= state
.uioh#scrollpw
in
1333 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1334 (x+.w) (float (state
.winh
- hscrollh))
1337 let w = float (state
.winw
- 1 - vscrollw ()) in
1338 if state
.progress
>= 0.0 && state
.progress
< 1.0
1340 GlDraw.color (0.3, 0.3, 0.3);
1341 let w1 = w *. state
.progress
in
1343 GlDraw.color (0.0, 0.0, 0.0);
1344 rect (float x0+.w1) (float x0+.w-.w1)
1347 GlDraw.color (0.0, 0.0, 0.0);
1351 GlDraw.color (1.0, 1.0, 1.0);
1354 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1355 (state
.winh
- hscrollh - 5) s;
1358 match state
.mode
with
1359 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1362 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1363 else Printf.sprintf
"%s%s_" prefix
text
1367 | Birdseye _
| View
| LinkNav _
-> state
.text
1372 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1374 let s1 = "(press 'e' to review error messasges)" in
1375 if nonemptystr
s then s ^
" " ^
s1 else s1
1385 let len = Queue.length state
.tilelru
in
1387 match state
.throttle
with
1390 then preloadlayout state
.x state
.y state
.winw state
.winh
1392 | Some
(layout, _
, _
) ->
1396 if state
.memused
> conf
.memlimit
1400 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1401 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1402 let (_
, pw, ph
, _
) = getpagedim
n in
1404 && colorspace
= conf
.colorspace
1405 && angle
= conf
.angle
1409 let x = col*conf
.tilew
1410 and y = row*conf
.tileh
in
1411 tilevisible (Lazy.force_val
layout) n x y
1413 then Queue.push lruitem state
.tilelru
1416 wcmd "freetile %s" (~
> p
);
1417 state
.memused
<- state
.memused
- s;
1418 state
.uioh#infochanged Memused
;
1419 Hashtbl.remove state
.tilemap k
;
1427 let onpagerect pageno
f =
1429 match conf
.columns
with
1430 | Cmulti
(_
, b) -> b
1432 | Csplit
(_
, b) -> b
1434 if pageno
>= 0 && pageno
< Array.length
b
1436 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1440 let gotopagexy1 wtmode pageno
x y =
1441 let _,w1,h1
,leftx
= getpagedim pageno
in
1442 let top = y /. (float h1
) in
1443 let left = x /. (float w1) in
1444 let py, w, h = getpageywh pageno
in
1445 let wh = state
.winh
in
1446 let x = left *. (float w) in
1447 let x = leftx
+ state
.x + truncate
x in
1449 if x < 0 || x >= state
.winw
1453 let pdy = truncate
(top *. float h) in
1454 let y'
= py + pdy in
1455 let dy = y'
- state
.y in
1457 if x != state
.x || not
(dy > 0 && dy < wh)
1459 if conf
.presentation
1461 if abs
(py - y'
) > wh
1468 if state
.x != sx || state
.y != sy
1473 let ww = state
.winw
in
1475 and qy
= pdy / wh in
1477 and y = py + qy
* wh in
1478 let x = if -x + ww > w1 then -(w1-ww) else x
1479 and y'
= if y + wh > state
.maxy then state
.maxy - wh else y in
1481 if conf
.presentation
1483 if abs
(py - y'
) > wh
1492 gotoxy_and_clear_text x y;
1494 else gotoxy_and_clear_text state
.x state
.y;
1497 let gotopagexy wtmode pageno
x y =
1498 match state
.mode
with
1499 | Birdseye
_ -> gotopage pageno
0.0
1500 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1503 let getpassword () =
1504 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1509 impmsg "error getting password: %s" s;
1510 dolog
"%s" s) passcmd;
1513 let pgoto opaque pageno
x y =
1514 let pdimno = getpdimno pageno
in
1515 let x, y = project opaque pageno
pdimno x y in
1516 gotopagexy false pageno
x y;
1520 (* dolog "%S" cmds; *)
1521 let spl = splitatchar cmds ' '
in
1523 try Scanf.sscanf
s fmt
f
1525 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1528 let addoutline outline
=
1529 match state
.currently
with
1530 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1531 | Idle
-> state
.currently
<- Outlining
[outline
]
1532 | Loading
_ | Tiling
_ ->
1533 dolog
"invalid outlining state";
1534 logcurrently state
.currently
1539 state
.uioh#infochanged Pdim
;
1541 | "clearrects", "" ->
1542 state
.rects
<- state
.rects1
;
1543 G.postRedisplay "clearrects";
1545 | "continue", args
->
1546 let n = scan args
"%u" (fun n -> n) in
1547 state
.pagecount
<- n;
1548 begin match state
.currently
with
1550 state
.currently
<- Idle
;
1551 state
.outlines
<- Array.of_list
(List.rev
l)
1552 | Idle
| Loading
_ | Tiling
_ -> ()
1555 let cur, cmds
= state
.geomcmds
in
1557 then failwith
"umpossible";
1559 begin match List.rev cmds
with
1561 state
.geomcmds
<- E.s, [];
1562 state
.throttle
<- None
;
1566 state
.geomcmds
<- s, List.rev rest
;
1568 if conf
.maxwait
= None
&& not
!wtmode
1569 then G.postRedisplay "continue";
1576 then showtext ' ' args
1579 Buffer.add_string state
.errmsgs args
;
1580 state
.newerrmsgs
<- true;
1581 G.postRedisplay "error message"
1583 | "progress", args
->
1584 let progress, text =
1587 f, String.sub args pos
(String.length args
- pos
))
1590 state
.progress <- progress;
1591 G.postRedisplay "progress"
1593 | "firstmatch", args
->
1594 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1595 scan args
"%u %d %f %f %f %f %f %f %f %f"
1596 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1597 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1599 let y = (getpagey
pageno) + truncate
y0 in
1607 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1608 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1611 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1612 scan args
"%u %d %f %f %f %f %f %f %f %f"
1613 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1614 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1616 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1618 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1621 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1622 let pageopaque = ~
< pageopaques in
1623 begin match state
.currently
with
1624 | Loading
(l, gen
) ->
1625 vlog "page %d took %f sec" l.pageno t
;
1626 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1627 begin match state
.throttle
with
1629 let preloadedpages =
1631 then preloadlayout state
.x state
.y state
.winw state
.winh
1636 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1637 IntSet.empty
preloadedpages
1640 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1641 if not
(IntSet.mem
pageno set)
1643 wcmd "freepage %s" (~
> opaque
);
1649 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1652 state
.currently
<- Idle
;
1655 tilepage l.pageno pageopaque state
.layout;
1657 load preloadedpages;
1658 let visible = pagevisible state
.layout l.pageno in
1661 match state
.mode
with
1662 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1663 if pageno = l.pageno
1668 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1670 if dir
> 0 then LDfirst
else LDlast
1673 findlink
pageopaque ld
1678 showlinktype (getlink
pageopaque n);
1679 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1681 | LinkNav
(Ltgendir
_)
1682 | LinkNav
(Ltexact
_)
1688 if visible && layoutready state
.layout
1690 G.postRedisplay "page";
1694 | Some
(layout, _, _) ->
1695 state
.currently
<- Idle
;
1696 tilepage l.pageno pageopaque layout;
1700 | Idle
| Tiling
_ | Outlining
_ ->
1701 dolog
"Inconsistent loading state";
1702 logcurrently state
.currently
;
1707 let (x, y, opaques
, size
, t
) =
1708 scan args
"%u %u %s %u %f"
1709 (fun x y p size t
-> (x, y, p
, size
, t
))
1711 let opaque = ~
< opaques
in
1712 begin match state
.currently
with
1713 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1714 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1717 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1719 wcmd "freetile %s" (~
> opaque);
1720 state
.currently
<- Idle
;
1724 puttileopaque l col row gen cs angle
opaque size t
;
1725 state
.memused
<- state
.memused
+ size
;
1726 state
.uioh#infochanged Memused
;
1728 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1729 opaque, size
) state
.tilelru
;
1732 match state
.throttle
with
1733 | None
-> state
.layout
1734 | Some
(layout, _, _) -> layout
1737 state
.currently
<- Idle
;
1739 && conf
.colorspace
= cs
1740 && conf
.angle
= angle
1741 && tilevisible layout l.pageno x y
1742 then conttiling l.pageno pageopaque;
1744 begin match state
.throttle
with
1746 preload state
.layout;
1748 && conf
.colorspace
= cs
1749 && conf
.angle
= angle
1750 && tilevisible state
.layout l.pageno x y
1751 && (not
!wtmode || layoutready state
.layout)
1752 then G.postRedisplay "tile nothrottle";
1754 | Some
(layout, y, _) ->
1755 let ready = layoutready layout in
1759 state
.layout <- layout;
1760 state
.throttle
<- None
;
1761 G.postRedisplay "throttle";
1767 | Idle
| Loading
_ | Outlining
_ ->
1768 dolog
"Inconsistent tiling state";
1769 logcurrently state
.currently
;
1774 let (n, w, h, _) as pdim
=
1775 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1778 match conf
.fitmodel
with
1780 | FitPage
| FitProportional
->
1781 match conf
.columns
with
1782 | Csplit
_ -> (n, w, h, 0)
1783 | Csingle
_ | Cmulti
_ -> pdim
1785 state
.pdims
<- pdim :: state
.pdims
;
1786 state
.uioh#infochanged Pdim
1789 let (l, n, t
, h, pos
) =
1790 scan args
"%u %u %d %u %n"
1791 (fun l n t
h pos
-> l, n, t
, h, pos
)
1793 let s = String.sub args pos
(String.length args
- pos
) in
1794 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1797 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1798 let s = String.sub args pos
len in
1799 let pos2 = pos
+ len + 1 in
1800 let uri = String.sub args
pos2 (String.length args
- pos2) in
1801 addoutline (s, l, Ouri
uri)
1804 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1805 let s = String.sub args pos
(String.length args
- pos
) in
1806 addoutline (s, l, Onone
)
1810 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1812 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1815 let c, v
= splitatchar args '
\t'
in
1826 if let len = String.length
c in
1827 len > 6 && ((String.sub
c (len-4) 4) = "date")
1829 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1831 let b = Buffer.create
10 in
1832 Printf.bprintf
b "%s\t" c;
1835 Buffer.add_substring
b v p
l;
1836 Buffer.add_char
b c;
1837 with exn
-> Buffer.add_string
b @@ exntos exn
1845 Buffer.add_char
b '
['
;
1846 Buffer.add_string
b v
;
1847 Buffer.add_char
b '
]'
;
1854 state
.docinfo
<- (1, s) :: state
.docinfo
1857 state
.docinfo
<- List.rev state
.docinfo
;
1858 state
.uioh#infochanged Docinfo
1862 then Wsi.settitle
"Wrong password";
1863 let password = getpassword () in
1864 if emptystr
password
1865 then error
"document is password protected"
1866 else opendoc state
.path
password
1869 error
"unknown cmd `%S'" cmds
1874 let action = function
1875 | HCprev
-> cbget cb ~
-1
1876 | HCnext
-> cbget cb
1
1877 | HCfirst
-> cbget cb ~
-(cb
.rc)
1878 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1879 and cancel
() = cb
.rc <- rc
1883 let search pattern forward
=
1884 match conf
.columns
with
1885 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1886 | Csingle
_ | Cmulti
_ ->
1887 if nonemptystr pattern
1890 match state
.layout with
1893 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1895 wcmd "search %d %d %d %d,%s\000"
1896 (btod conf
.icase
) pn py (btod forward
) pattern
;
1899 let [@warning
"-4"] intentry
text key =
1901 if emptystr
text && key = Keys.Ascii '
-'
1902 then addchar
text '
-'
1905 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1907 state
.text <- "invalid key";
1917 let l = String.length
s in
1918 let rec loop pos
n =
1922 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1923 loop (pos
+1) (n*26 + m)
1926 let rec loop n = function
1929 match getopaque l.pageno with
1930 | None
-> loop n rest
1932 let m = getlinkcount
opaque in
1935 let under = getlink
opaque n in
1938 else loop (n-m) rest
1940 loop n state
.layout;
1944 let [@warning
"-4"] linknentry
text = function
1946 let text = addchar
text c in
1947 linknact (fun under -> state
.text <- undertext under) text;
1950 state
.text <- Printf.sprintf
"invalid key";
1954 let [@warning
"-4"] textentry
text = function
1955 | Keys.Ascii
c -> TEcont
(addchar
text c)
1956 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1960 let reqlayout angle fitmodel
=
1961 match state
.throttle
with
1963 if nogeomcmds state
.geomcmds
1964 then state
.anchor <- getanchor
();
1965 conf
.angle
<- angle
mod 360;
1968 match state
.mode
with
1969 | LinkNav
_ -> state
.mode
<- View
1970 | Birdseye
_ | Textentry
_ | View
-> ()
1972 conf
.fitmodel
<- fitmodel
;
1976 wcmd "reqlayout %d %d %d"
1977 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1982 let settrim trimmargins trimfuzz
=
1983 if nogeomcmds state
.geomcmds
1984 then state
.anchor <- getanchor
();
1985 conf
.trimmargins
<- trimmargins
;
1986 conf
.trimfuzz
<- trimfuzz
;
1987 let x0, y0, x1, y1 = trimfuzz
in
1989 "settrim" (fun () ->
1990 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1995 match state
.throttle
with
1997 let zoom = max
0.0001 zoom in
1998 if zoom <> conf
.zoom
2000 state
.prevzoom
<- (conf
.zoom, state
.x);
2002 reshape state
.winw state
.winh
;
2003 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2006 | Some
(layout, y, started
) ->
2008 match conf
.maxwait
with
2012 let dt = now
() -. started
in
2020 let pivotzoom ?
(vw=min state
.w state
.winw
)
2021 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
2022 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2023 let w = float state
.w /. zoom in
2024 let hw = w /. 2.0 in
2025 let ratio = float vh
/. float vw in
2026 let hh = hw *. ratio in
2027 let x0 = float x -. hw
2028 and y0 = float y -. hh in
2029 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2033 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2034 if nogeomcmds state
.geomcmds
2037 then pivotzoom ?
vw ?vh ?
x ?
y zoom
2041 let setcolumns mode columns coverA coverB
=
2042 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2046 then impmsg "split mode doesn't work in bird's eye"
2048 conf
.columns
<- Csplit
(-columns
, E.a);
2056 conf
.columns
<- Csingle
E.a;
2061 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2065 reshape state
.winw state
.winh
;
2068 let resetmstate () =
2069 state
.mstate
<- Mnone
;
2070 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2073 let enterbirdseye () =
2074 let zoom = float conf
.thumbw
/. float state
.winw
in
2075 let birdseyepageno =
2076 let cy = state
.winh
/ 2 in
2080 let rec fold best
= function
2083 let d = cy - (l.pagedispy + l.pagevh/2)
2084 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2085 if abs
d < abs dbest
2094 { conf
with zoom = conf
.zoom },
2095 state
.x, birdseyepageno, -1, getanchor
()
2099 conf
.presentation
<- false;
2100 conf
.interpagespace
<- 10;
2101 conf
.hlinks
<- false;
2102 conf
.fitmodel
<- FitPage
;
2104 conf
.maxwait
<- None
;
2106 match conf
.beyecolumns
with
2109 Cmulti
((c, 0, 0), E.a)
2110 | None
-> Csingle
E.a
2114 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2119 reshape state
.winw state
.winh
;
2122 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2124 conf
.zoom <- c.zoom;
2125 conf
.presentation
<- c.presentation
;
2126 conf
.interpagespace
<- c.interpagespace
;
2127 conf
.maxwait
<- c.maxwait
;
2128 conf
.hlinks
<- c.hlinks
;
2129 conf
.fitmodel
<- c.fitmodel
;
2130 conf
.beyecolumns
<- (
2131 match conf
.columns
with
2132 | Cmulti
((c, _, _), _) -> Some
c
2134 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2137 match c.columns
with
2138 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2139 | Csingle
_ -> Csingle
E.a
2140 | Csplit
(c, _) -> Csplit
(c, E.a)
2144 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2147 reshape state
.winw state
.winh
;
2148 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2152 let togglebirdseye () =
2153 match state
.mode
with
2154 | Birdseye vals
-> leavebirdseye vals
true
2155 | View
-> enterbirdseye ()
2156 | Textentry
_ | LinkNav
_ -> ()
2159 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2160 let pageno = max
0 (pageno - incr
) in
2161 let rec loop = function
2162 | [] -> gotopage1 pageno 0
2163 | l :: _ when l.pageno = pageno ->
2164 if l.pagedispy >= 0 && l.pagey = 0
2165 then G.postRedisplay "upbirdseye"
2166 else gotopage1 pageno 0
2167 | _ :: rest
-> loop rest
2171 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2174 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2175 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2176 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2177 let rec loop = function
2179 let y, h = getpageyh
pageno in
2180 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2181 gotoxy state
.x (clamp dy)
2182 | l :: _ when l.pageno = pageno ->
2183 if l.pagevh != l.pageh
2184 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2185 else G.postRedisplay "downbirdseye"
2186 | _ :: rest
-> loop rest
2192 let [@warning
"-4"] optentry mode
_ key =
2193 let btos b = if b then "on" else "off" in
2197 try conf
.scrollstep
<- int_of_string
s with exn
->
2198 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2200 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2205 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2206 if state
.autoscroll
<> None
2207 then state
.autoscroll
<- Some conf
.autoscrollstep
2209 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2211 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2216 let n, a, b = multicolumns_of_string
s in
2217 setcolumns mode
n a b;
2219 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2221 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2226 let zoom = float (int_of_string
s) /. 100.0 in
2229 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2231 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2236 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2238 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2239 begin match mode
with
2241 leavebirdseye beye
false;
2243 | Textentry
_ | View
| LinkNav
_ -> ();
2246 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2248 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2252 match int_of_string
s with
2253 | angle
-> reqlayout angle conf
.fitmodel
2255 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2257 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2260 conf
.icase
<- not conf
.icase
;
2261 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2264 conf
.preload <- not conf
.preload;
2265 gotoxy state
.x state
.y;
2266 TEdone
("preload " ^
(btos conf
.preload))
2269 conf
.verbose
<- not conf
.verbose
;
2270 TEdone
("verbose " ^
(btos conf
.verbose
))
2273 conf
.debug
<- not conf
.debug
;
2274 TEdone
("debug " ^
(btos conf
.debug
))
2277 conf
.maxhfit
<- not conf
.maxhfit
;
2278 state
.maxy <- calcheight
();
2279 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2282 conf
.crophack
<- not conf
.crophack
;
2283 TEdone
("crophack " ^
btos conf
.crophack
)
2287 match conf
.maxwait
with
2289 conf
.maxwait
<- Some infinity
;
2290 "always wait for page to complete"
2292 conf
.maxwait
<- None
;
2293 "show placeholder if page is not ready"
2298 conf
.underinfo
<- not conf
.underinfo
;
2299 TEdone
("underinfo " ^
btos conf
.underinfo
)
2302 conf
.savebmarks
<- not conf
.savebmarks
;
2303 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2309 match state
.layout with
2314 conf
.interpagespace
<- int_of_string
s;
2315 docolumns conf
.columns
;
2316 state
.maxy <- calcheight
();
2317 let y = getpagey
pageno in
2318 gotoxy state
.x (y + py)
2320 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2322 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2326 match conf
.fitmodel
with
2327 | FitProportional
-> FitWidth
2328 | FitWidth
| FitPage
-> FitProportional
2330 reqlayout conf
.angle
fm;
2331 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2334 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2335 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2338 conf
.invert
<- not conf
.invert
;
2339 TEdone
("invert colors " ^
btos conf
.invert
)
2343 cbput state
.hists
.sel
s;
2346 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2347 textentry
, ondone, true)
2351 then conf
.pax
<- Some
0.0
2352 else conf
.pax
<- None
;
2353 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2356 state
.text <- Printf.sprintf
"bad option %d `%c'"
2364 class type lvsource
=
2366 method getitemcount
: int
2367 method getitem
: int -> (string * int)
2368 method hasaction
: int -> bool
2369 method exit
: uioh
:uioh
->
2375 method getactive
: int
2376 method getfirst
: int
2378 method getminfo
: (int * int) array
2381 class virtual lvsourcebase
= object
2382 val mutable m_active
= 0
2383 val mutable m_first
= 0
2384 val mutable m_pan
= 0
2385 method getactive
= m_active
2386 method getfirst
= m_first
2387 method getpan
= m_pan
2388 method getminfo
: (int * int) array
= E.a
2393 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2396 state
.mode
<- Textentry
(te
, onleave
);
2398 G.postRedisplay "textentrykeyboard enttext";
2400 let histaction cmd
=
2403 | Some
(action, _) ->
2406 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2408 G.postRedisplay "textentry histaction"
2411 let kt = Wsi.kc2kt
key in
2414 if emptystr
text && cancelonempty
2417 G.postRedisplay "textentrykeyboard after cancel";
2420 let s = withoutlastutf8
text in
2421 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2426 G.postRedisplay "textentrykeyboard after confirm"
2428 | Up
-> histaction HCprev
2429 | Down
-> histaction HCnext
2430 | Home
-> histaction HCfirst
2431 | End
-> histaction HClast
2436 begin match opthist
with
2438 | Some
(_, onhistcancel
) -> onhistcancel
()
2442 G.postRedisplay "textentrykeyboard after cancel2"
2445 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2450 | Code
_ | Ascii
_ ->
2451 begin match onkey
text kt with
2455 G.postRedisplay "textentrykeyboard after confirm2";
2458 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2462 G.postRedisplay "textentrykeyboard after cancel3"
2465 state
.mode
<- Textentry
(te
, onleave
);
2466 G.postRedisplay "textentrykeyboard switch";
2468 | _ -> vlog "unhandled key"
2471 let firstof first active
=
2472 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2473 then max
0 (active
- (fstate
.maxrows
/2))
2477 let calcfirst first active
=
2480 let rows = active
- first
in
2481 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2485 let scrollph y maxy =
2486 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2487 let sh = float state
.winh
/. sh in
2488 let sh = max
sh (float conf
.scrollh
) in
2490 let percent = float y /. float maxy in
2491 let position = (float state
.winh
-. sh) *. percent in
2494 if position +. sh > float state
.winh
2495 then float state
.winh
-. sh
2501 let adderrmsg src msg
=
2502 Buffer.add_string state
.errmsgs msg
;
2503 state
.newerrmsgs
<- true;
2507 let adderrfmt src fmt
=
2508 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2511 let coe s = (s :> uioh
);;
2513 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2515 val m_pan
= source#getpan
2516 val m_first
= source#getfirst
2517 val m_active
= source#getactive
2519 val m_prev_uioh
= state
.uioh
2521 method private elemunder
y =
2525 let n = y / (fstate
.fontsize
+1) in
2526 if m_first
+ n < source#getitemcount
2528 if source#hasaction
(m_first
+ n)
2529 then Some
(m_first
+ n)
2536 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2537 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2538 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2539 GlDraw.color (1., 1., 1.);
2540 Gl.enable `texture_2d
;
2541 let fs = fstate
.fontsize
in
2543 let hw = state
.winw
/3 in
2544 let ww = fstate
.wwidth
in
2545 let tabw = 17.0*.ww in
2546 let itemcount = source#getitemcount
in
2547 let minfo = source#getminfo
in
2551 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2553 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2555 if (row - m_first
) > fstate
.maxrows
2558 if row >= 0 && row < itemcount
2560 let (s, level
) = source#getitem
row in
2561 let y = (row - m_first
) * nfs in
2562 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2565 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2569 Gl.disable `texture_2d
;
2570 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2571 GlDraw.color (1., 1., 1.) ~
alpha;
2572 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2573 Gl.enable `texture_2d
;
2576 if zebra
&& row land 1 = 1
2580 GlDraw.color (c,c,c);
2581 let drawtabularstring s =
2583 let x'
= truncate
(x0 +. x) in
2584 let s1, s2
= splitatchar
s '
\000'
in
2586 then drawstring1 fs x'
(y+nfs) s
2592 let s'
= withoutlastutf8
s in
2593 let s = s' ^
UniSyms.ellipsis in
2594 let w = measurestr
fs s in
2595 if float x'
+. w +. ww < float (hw + x'
)
2600 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2604 ignore
(drawstring1 fs x'
(y+nfs) s1);
2605 drawstring1 fs (hw + x'
) (y+nfs) s2
2609 let x = if helpmode
&& row > 0 then x +. ww else x in
2610 let s1, s2
= splitatchar
s '
\t'
in
2613 let nx = drawstr x s1 in
2615 let x = x +. (max
tabw sw) in
2618 let len = String.length
s - 2 in
2619 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2621 let s = String.sub s 2 len in
2622 let x = if not helpmode
then x +. ww else x in
2623 GlDraw.color (1.2, 1.2, 1.2);
2624 let vinc = drawstring1 (fs+fs/4)
2625 (truncate
(x -. ww)) (y+nfs) s in
2626 GlDraw.color (1., 1., 1.);
2627 vinc +. (float fs *. 0.8)
2633 ignore
(drawtabularstring s);
2639 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2642 if (row - m_first
) <= fstate
.maxrows
2644 if row >= 0 && row < itemcount
2646 let (s, level
) = source#getitem
row in
2647 let pos0 = nindex
s '
\000'
in
2648 let y = (row - m_first
) * nfs in
2649 let x = float (level
+ m_pan
) *. ww in
2650 let (first
, last
) = minfo.(row) in
2652 if pos0 > 0 && first
> pos0
2653 then String.sub s (pos0+1) (first
-pos0-1)
2654 else String.sub s 0 first
2656 let suffix = String.sub s first
(last
- first
) in
2657 let w1 = measurestr fstate
.fontsize
prefix in
2658 let w2 = measurestr fstate
.fontsize
suffix in
2659 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2660 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2662 and y0 = float (y+2) in
2664 and y1 = float (y+fs+3) in
2665 filledrect x0 y0 x1 y1;
2669 Gl.disable `texture_2d
;
2670 if Array.length
minfo > 0 then loop m_first
;
2675 method updownlevel incr
=
2676 let len = source#getitemcount
in
2678 if m_active
>= 0 && m_active
< len
2679 then snd
(source#getitem m_active
)
2683 if i
= len then i
-1 else if i
= -1 then 0 else
2684 let _, l = source#getitem i
in
2685 if l != curlevel then i
else flow (i
+incr
)
2687 let active = flow m_active
in
2688 let first = calcfirst m_first
active in
2689 G.postRedisplay "outline updownlevel";
2690 {< m_active
= active; m_first
= first >}
2692 method private key1
key mask
=
2693 let set1 active first qsearch
=
2694 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2696 let search active pattern incr
=
2697 let active = if active = -1 then m_first
else active in
2700 if n >= 0 && n < source#getitemcount
2702 let s, _ = source#getitem
n in
2703 match Str.search_forward re
s 0 with
2704 | exception Not_found
-> loop (n + incr
)
2711 let qpat = Str.quote pattern
in
2712 match Str.regexp_case_fold
qpat with
2715 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2716 qpat @@ Printexc.to_string exn
;
2719 let itemcount = source#getitemcount
in
2720 let find start incr
=
2722 if i
= -1 || i
= itemcount
2725 if source#hasaction i
2727 else find (i
+ incr
)
2732 let set active first =
2733 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2735 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2738 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2740 let incr1 = if incr
> 0 then 1 else -1 in
2741 if isvisible m_first m_active
2744 let next = m_active
+ incr
in
2746 if next < 0 || next >= itemcount
2748 else find next incr1
2750 if abs
(m_active
- next) > fstate
.maxrows
2756 let first = m_first
+ incr
in
2757 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2759 let next = m_active
+ incr
in
2760 let next = bound
next 0 (itemcount - 1) in
2767 if isvisible first next
2774 let first = min
next m_first
in
2776 if abs
(next - first) > fstate
.maxrows
2782 let first = m_first
+ incr
in
2783 let first = bound
first 0 (itemcount - 1) in
2785 let next = m_active
+ incr
in
2786 let next = bound
next 0 (itemcount - 1) in
2787 let next = find next incr1 in
2789 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2791 let active = if m_active
= -1 then next else m_active
in
2796 if isvisible first active
2802 G.postRedisplay "listview navigate";
2806 let kt = Wsi.kc2kt
key in
2807 match [@warning
"-4"] kt with
2808 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2809 let incr = if c = 'r'
then -1 else 1 in
2811 match search (m_active
+ incr) m_qsearch
incr with
2813 state
.text <- m_qsearch ^
" [not found]";
2816 state
.text <- m_qsearch
;
2817 active, firstof m_first
active
2819 G.postRedisplay "listview ctrl-r/s";
2820 set1 active first m_qsearch
;
2822 | Insert
when Wsi.withctrl mask
->
2823 if m_active
>= 0 && m_active
< source#getitemcount
2825 let s, _ = source#getitem m_active
in
2831 if emptystr m_qsearch
2834 let qsearch = withoutlastutf8 m_qsearch
in
2838 G.postRedisplay "listview empty qsearch";
2839 set1 m_active m_first
E.s;
2843 match search m_active
qsearch ~
-1 with
2845 state
.text <- qsearch ^
" [not found]";
2848 state
.text <- qsearch;
2849 active, firstof m_first
active
2851 G.postRedisplay "listview backspace qsearch";
2852 set1 active first qsearch
2855 | Ascii
_ | Code
_ ->
2857 match [@warning
"-8"] kt with
2858 | Ascii
c -> String.make
1 c
2859 | Code code
-> toutf8 code
2861 let pattern = m_qsearch ^
utf8 in
2863 match search m_active
pattern 1 with
2865 state
.text <- pattern ^
" [not found]";
2868 state
.text <- pattern;
2869 active, firstof m_first
active
2871 G.postRedisplay "listview qsearch add";
2872 set1 active first pattern;
2876 if emptystr m_qsearch
2878 G.postRedisplay "list view escape";
2879 let mx, my
= state
.mpos
in
2881 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2882 ~
first:m_first ~pan
:m_pan
with
2883 | None
-> m_prev_uioh
2887 G.postRedisplay "list view kill qsearch";
2888 coe {< m_qsearch
= E.s >}
2893 let self = {< m_qsearch
= E.s >} in
2895 G.postRedisplay "listview enter";
2896 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2897 source#exit ~uioh
:(coe self) ~
cancel
2898 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2900 begin match opt with
2901 | None
-> m_prev_uioh
2908 | Up
-> navigate ~
-1
2909 | Down
-> navigate 1
2910 | Prior
-> navigate ~
-(fstate
.maxrows
)
2911 | Next
-> navigate fstate
.maxrows
2915 G.postRedisplay "listview right";
2916 coe {< m_pan
= m_pan
- 1 >}
2920 G.postRedisplay "listview left";
2921 coe {< m_pan
= m_pan
+ 1 >}
2924 let active = find 0 1 in
2925 G.postRedisplay "listview home";
2929 let first = max
0 (itemcount - fstate
.maxrows
) in
2930 let active = find (itemcount - 1) ~
-1 in
2931 G.postRedisplay "listview end";
2936 method key key mask
=
2937 match state
.mode
with
2939 textentrykeyboard
key mask te
;
2941 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2943 method button button down
x y _ =
2946 | 1 when vscrollhit x ->
2947 G.postRedisplay "listview scroll";
2950 let _, position, sh = self#
scrollph in
2951 if y > truncate
position && y < truncate
(position +. sh)
2953 state
.mstate
<- Mscrolly
;
2957 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2958 let first = truncate
(s *. float source#getitemcount
) in
2959 let first = min source#getitemcount
first in
2960 Some
(coe {< m_first
= first; m_active
= first >})
2962 state
.mstate
<- Mnone
;
2966 begin match self#elemunder
y with
2968 G.postRedisplay "listview click";
2969 source#exit ~uioh
:(coe {< m_active
= n >})
2970 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2974 | n when (n == 4 || n == 5) && not down
->
2975 let len = source#getitemcount
in
2977 if n = 5 && m_first
+ fstate
.maxrows
>= len
2981 let first = m_first
+ (if n == 4 then -1 else 1) in
2982 bound
first 0 (len - 1)
2984 G.postRedisplay "listview wheel";
2985 Some
(coe {< m_first
= first >})
2986 | n when (n = 6 || n = 7) && not down
->
2987 let inc = if n = 7 then -1 else 1 in
2988 G.postRedisplay "listview hwheel";
2989 Some
(coe {< m_pan
= m_pan
+ inc >})
2994 | None
-> m_prev_uioh
2997 method multiclick
_ x y = self#button
1 true x y
3000 match state
.mstate
with
3002 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3003 let first = truncate
(s *. float source#getitemcount
) in
3004 let first = min source#getitemcount
first in
3005 G.postRedisplay "listview motion";
3006 coe {< m_first
= first; m_active
= first >}
3014 method pmotion
x y =
3015 if x < state
.winw
- conf
.scrollbw
3018 match self#elemunder
y with
3019 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3020 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3024 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3029 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3033 method infochanged
_ = ()
3035 method scrollpw
= (0, 0.0, 0.0)
3037 let nfs = fstate
.fontsize
+ 1 in
3038 let y = m_first
* nfs in
3039 let itemcount = source#getitemcount
in
3040 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3041 let maxy = maxi * nfs in
3042 let p, h = scrollph y maxy in
3045 method modehash
= modehash
3046 method eformsgs
= false
3047 method alwaysscrolly
= true
3048 method scroll _ dy =
3050 if dy != 0 then begin
3051 let len = source#getitemcount
in
3053 if dy > 0 && m_first
+ fstate
.maxrows
>= len
3057 let first = m_first
+ dy / 10 in
3058 bound
first 0 (len - 1)
3060 G.postRedisplay "listview wheel";
3061 {< m_first
= first >}
3067 method zoom _ _ _ = ()
3070 class outlinelistview ~zebra ~source
=
3071 let settext autonarrow
s =
3074 let ss = source#statestr
in
3078 else "{" ^
ss ^
"} [" ^
s ^
"]"
3079 else state
.text <- s
3085 ~source
:(source
:> lvsource
)
3087 ~modehash
:(findkeyhash conf
"outline")
3090 val m_autonarrow
= false
3092 method! key key mask
=
3094 if emptystr state
.text
3096 else fstate
.maxrows - 2
3098 let calcfirst first active =
3101 let rows = active - first in
3102 if rows > maxrows then active - maxrows else first
3106 let active = m_active
+ incr in
3107 let active = bound
active 0 (source#getitemcount
- 1) in
3108 let first = calcfirst m_first
active in
3109 G.postRedisplay "outline navigate";
3110 coe {< m_active
= active; m_first
= first >}
3112 let navscroll first =
3114 let dist = m_active
- first in
3120 else first + maxrows
3123 G.postRedisplay "outline navscroll";
3124 coe {< m_first
= first; m_active
= active >}
3126 let ctrl = Wsi.withctrl mask
in
3128 match Wsi.kc2kt
key with
3129 | Ascii '
a'
when ctrl ->
3132 then (source#denarrow
; E.s)
3134 let pattern = source#renarrow
in
3135 if nonemptystr m_qsearch
3136 then (source#narrow m_qsearch
; m_qsearch
)
3140 settext (not m_autonarrow
) text;
3141 G.postRedisplay "toggle auto narrowing";
3142 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3144 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3146 G.postRedisplay "toggle auto narrowing";
3147 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3149 | Ascii '
n'
when ctrl ->
3150 source#narrow m_qsearch
;
3152 then source#add_narrow_pattern m_qsearch
;
3153 G.postRedisplay "outline ctrl-n";
3154 coe {< m_first
= 0; m_active
= 0 >}
3156 | Ascii 'S'
when ctrl ->
3157 let active = source#calcactive
(getanchor
()) in
3158 let first = firstof m_first
active in
3159 G.postRedisplay "outline ctrl-s";
3160 coe {< m_first
= first; m_active
= active >}
3162 | Ascii 'u'
when ctrl ->
3163 G.postRedisplay "outline ctrl-u";
3164 if m_autonarrow
&& nonemptystr m_qsearch
3166 ignore
(source#renarrow
);
3167 settext m_autonarrow
E.s;
3168 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3171 source#del_narrow_pattern
;
3172 let pattern = source#renarrow
in
3174 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3176 settext m_autonarrow
text;
3177 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3180 | Ascii '
l'
when ctrl ->
3181 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3182 G.postRedisplay "outline ctrl-l";
3183 coe {< m_first
= first >}
3185 | Ascii '
\t'
when m_autonarrow
->
3186 if nonemptystr m_qsearch
3188 G.postRedisplay "outline list view tab";
3189 source#add_narrow_pattern m_qsearch
;
3191 coe {< m_qsearch
= E.s >}
3195 | Escape
when m_autonarrow
->
3196 if nonemptystr m_qsearch
3197 then source#add_narrow_pattern m_qsearch
;
3200 | Enter
when m_autonarrow
->
3201 if nonemptystr m_qsearch
3202 then source#add_narrow_pattern m_qsearch
;
3205 | (Ascii
_ | Code
_) when m_autonarrow
->
3206 let pattern = m_qsearch ^ toutf8
key in
3207 G.postRedisplay "outlinelistview autonarrow add";
3208 source#narrow
pattern;
3209 settext true pattern;
3210 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3212 | Backspace
when m_autonarrow
->
3213 if emptystr m_qsearch
3216 let pattern = withoutlastutf8 m_qsearch
in
3217 G.postRedisplay "outlinelistview autonarrow backspace";
3218 ignore
(source#renarrow
);
3219 source#narrow
pattern;
3220 settext true pattern;
3221 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3224 navscroll (max
0 (m_first
- 1))
3227 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3229 | Up
-> navigate ~
-1
3230 | Down
-> navigate 1
3231 | Prior
-> navigate ~
-(fstate
.maxrows)
3232 | Next
-> navigate fstate
.maxrows
3238 G.postRedisplay "outline ctrl right";
3239 {< m_pan
= m_pan
+ 1 >}
3241 else self#updownlevel
1
3249 G.postRedisplay "outline ctrl left";
3250 {< m_pan
= m_pan
- 1 >}
3252 else self#updownlevel ~
-1
3257 G.postRedisplay "outline home";
3258 coe {< m_first
= 0; m_active
= 0 >}
3261 let active = source#getitemcount
- 1 in
3262 let first = max
0 (active - fstate
.maxrows) in
3263 G.postRedisplay "outline end";
3264 coe {< m_active
= active; m_first
= first >}
3266 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
3270 let genhistoutlines () =
3272 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3273 compare c2
.lastvisit c1
.lastvisit
)
3274 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3275 let path = if nonemptystr origin
then origin
else path in
3276 let base = mbtoutf8
@@ Filename.basename
path in
3277 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3281 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3282 Config.save
leavebirdseye;
3283 state
.anchor <- anchor;
3284 state
.bookmarks
<- bookmarks
;
3285 state
.origin
<- origin
;
3288 let x0, y0, x1, y1 = conf
.trimfuzz
in
3289 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3290 reshape ~firsttime
:true state
.winw state
.winh
;
3291 opendoc path origin
;
3295 let makecheckers () =
3296 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3298 converted by Issac Trotts. July 25, 2002 *)
3299 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3300 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3301 let id = GlTex.gen_texture
() in
3302 GlTex.bind_texture ~target
:`texture_2d
id;
3303 GlPix.store
(`unpack_alignment
1);
3304 GlTex.image2d
image;
3305 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3306 [ `mag_filter `nearest
; `min_filter `nearest
];
3310 let setcheckers enabled
=
3311 match state
.checkerstexid
with
3313 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3315 | Some checkerstexid
->
3318 GlTex.delete_texture checkerstexid
;
3319 state
.checkerstexid
<- None
;
3323 let describe_layout layout =
3327 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
3330 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
3332 let sep = if a.pageno+1 = b.pageno then ", " else UniSyms.ellipsis in
3333 Printf.sprintf
"%d%s%d" (a.pageno+1) sep (b.pageno+1)
3335 let rec fold s la lb
= function
3336 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
3337 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
3338 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
3340 fold "Pages" l l rest
3343 let maxy = maxy () in
3346 else 100. *. (float state
.y /. float maxy)
3348 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
3351 let setpresentationmode v
=
3352 let n = page_of_y state
.y in
3353 state
.anchor <- (n, 0.0, 1.0);
3354 conf
.presentation
<- v
;
3355 if conf
.fitmodel
= FitPage
3356 then reqlayout conf
.angle conf
.fitmodel
;
3360 let setbgcol (r
, g, b) =
3362 let r = r *. 255.0 |> truncate
3363 and g = g *. 255.0 |> truncate
3364 and b = b *. 255.0 |> truncate
in
3365 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3367 Wsi.setwinbgcol
col;
3371 let btos b = if b then UniSyms.radical else E.s in
3372 let showextended = ref false in
3373 let showcolors = ref false in
3374 let leave mode
_ = state
.mode
<- mode
in
3377 val mutable m_l
= []
3378 val mutable m_a
= E.a
3379 val mutable m_prev_uioh
= nouioh
3380 val mutable m_prev_mode
= View
3382 inherit lvsourcebase
3384 method reset prev_mode prev_uioh
=
3385 m_a
<- Array.of_list
(List.rev m_l
);
3387 m_prev_mode
<- prev_mode
;
3388 m_prev_uioh
<- prev_uioh
;
3390 method int name get
set =
3396 try set (int_of_string
s)
3398 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3402 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3403 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3407 method int_with_suffix name get
set =
3409 (name
, `intws get
, 1,
3413 try set (int_of_string_with_suffix
s)
3415 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3420 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3422 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3426 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3428 (name
, `
bool (btos, get
), offset
, Action
(
3435 method color name get
set =
3437 (name
, `
color get
, 1,
3440 let invalid = (nan
, nan
, nan
) in
3443 try color_of_string
s
3445 state
.text <- Printf.sprintf
"bad color `%s': %s"
3452 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3453 state
.text <- color_to_string
(get
());
3454 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3458 method string name get
set =
3460 (name
, `
string get
, 1,
3463 let ondone s = set s in
3464 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3465 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3469 method colorspace name get
set =
3471 (name
, `
string get
, 1,
3476 inherit lvsourcebase
3479 m_active
<- CSTE.to_int conf
.colorspace
;
3482 method getitemcount
=
3483 Array.length
CSTE.names
3486 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3487 ignore
(uioh
, first, pan
);
3488 if not
cancel then set active;
3490 method hasaction
_ = true
3494 let modehash = findkeyhash conf
"info" in
3495 coe (new listview ~zebra
:false ~helpmode
:false
3496 ~
source ~trusted
:true ~
modehash)
3499 method paxmark name get
set =
3501 (name
, `
string get
, 1,
3506 inherit lvsourcebase
3509 m_active
<- MTE.to_int conf
.paxmark
;
3512 method getitemcount
= Array.length
MTE.names
3513 method getitem
n = (MTE.names
.(n), 0)
3514 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3515 ignore
(uioh
, first, pan
);
3516 if not
cancel then set active;
3518 method hasaction
_ = true
3522 let modehash = findkeyhash conf
"info" in
3523 coe (new listview ~zebra
:false ~helpmode
:false
3524 ~
source ~trusted
:true ~
modehash)
3527 method fitmodel name get
set =
3529 (name
, `
string get
, 1,
3534 inherit lvsourcebase
3537 m_active
<- FMTE.to_int conf
.fitmodel
;
3540 method getitemcount
= Array.length
FMTE.names
3541 method getitem
n = (FMTE.names
.(n), 0)
3542 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3543 ignore
(uioh
, first, pan
);
3544 if not
cancel then set active;
3546 method hasaction
_ = true
3550 let modehash = findkeyhash conf
"info" in
3551 coe (new listview ~zebra
:false ~helpmode
:false
3552 ~
source ~trusted
:true ~
modehash)
3555 method caption
s offset
=
3556 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3558 method caption2
s f offset
=
3559 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3561 method getitemcount
= Array.length m_a
3564 let tostr = function
3565 | `
int f -> string_of_int
(f ())
3566 | `intws
f -> string_with_suffix_of_int
(f ())
3568 | `
color f -> color_to_string
(f ())
3569 | `
bool (btos, f) -> btos (f ())
3572 let name, t
, offset
, _ = m_a
.(n) in
3573 ((let s = tostr t
in
3575 then Printf.sprintf
"%s\t%s" name s
3579 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3584 match m_a
.(active) with
3585 | _, _, _, Action
f -> f uioh
3586 | _, _, _, Noaction
-> uioh
3597 method hasaction
n =
3599 | _, _, _, Action
_ -> true
3600 | _, _, _, Noaction
-> false
3602 initializer m_active
<- 1
3605 let rec fillsrc prevmode prevuioh
=
3606 let sep () = src#caption
E.s 0 in
3607 let colorp name get
set =
3609 (fun () -> color_to_string
(get
()))
3612 let c = color_of_string
v in
3616 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3619 let rgba name get
set =
3621 (fun () -> rgba_to_string
(get
()))
3624 let c = rgba_of_string
v in
3628 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3631 let oldmode = state
.mode
in
3632 let birdseye = isbirdseye state
.mode
in
3634 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3636 src#
bool "presentation mode"
3637 (fun () -> conf
.presentation
)
3638 (fun v -> setpresentationmode v);
3640 src#
bool "ignore case in searches"
3641 (fun () -> conf
.icase
)
3642 (fun v -> conf
.icase
<- v);
3645 (fun () -> conf
.preload)
3646 (fun v -> conf
.preload <- v);
3648 src#
bool "highlight links"
3649 (fun () -> conf
.hlinks
)
3650 (fun v -> conf
.hlinks
<- v);
3652 src#
bool "under info"
3653 (fun () -> conf
.underinfo
)
3654 (fun v -> conf
.underinfo
<- v);
3656 src#
bool "persistent bookmarks"
3657 (fun () -> conf
.savebmarks
)
3658 (fun v -> conf
.savebmarks
<- v);
3660 src#fitmodel
"fit model"
3661 (fun () -> FMTE.to_string conf
.fitmodel
)
3662 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3664 src#
bool "trim margins"
3665 (fun () -> conf
.trimmargins
)
3666 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3668 src#
bool "persistent location"
3669 (fun () -> conf
.jumpback
)
3670 (fun v -> conf
.jumpback
<- v);
3673 src#
int "inter-page space"
3674 (fun () -> conf
.interpagespace
)
3676 conf
.interpagespace
<- n;
3677 docolumns conf
.columns
;
3679 match state
.layout with
3684 state
.maxy <- calcheight
();
3685 let y = getpagey
pageno in
3686 gotoxy state
.x (y + py)
3690 (fun () -> conf
.pagebias
)
3691 (fun v -> conf
.pagebias
<- v);
3693 src#
int "scroll step"
3694 (fun () -> conf
.scrollstep
)
3695 (fun n -> conf
.scrollstep
<- n);
3697 src#
int "horizontal scroll step"
3698 (fun () -> conf
.hscrollstep
)
3699 (fun v -> conf
.hscrollstep
<- v);
3701 src#
int "auto scroll step"
3703 match state
.autoscroll
with
3705 | _ -> conf
.autoscrollstep
)
3707 let n = boundastep state
.winh
n in
3708 if state
.autoscroll
<> None
3709 then state
.autoscroll
<- Some
n;
3710 conf
.autoscrollstep
<- n);
3713 (fun () -> truncate
(conf
.zoom *. 100.))
3714 (fun v -> pivotzoom ((float v) /. 100.));
3717 (fun () -> conf
.angle
)
3718 (fun v -> reqlayout v conf
.fitmodel
);
3720 src#
int "scroll bar width"
3721 (fun () -> conf
.scrollbw
)
3724 reshape state
.winw state
.winh
;
3727 src#
int "scroll handle height"
3728 (fun () -> conf
.scrollh
)
3729 (fun v -> conf
.scrollh
<- v;);
3731 src#
int "thumbnail width"
3732 (fun () -> conf
.thumbw
)
3734 conf
.thumbw
<- min
4096 v;
3737 leavebirdseye beye
false;
3744 let mode = state
.mode in
3745 src#
string "columns"
3747 match conf
.columns
with
3749 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3750 | Csplit
(count
, _) -> "-" ^ string_of_int count
3753 let n, a, b = multicolumns_of_string
v in
3754 setcolumns mode n a b);
3757 src#caption
"Pixmap cache" 0;
3758 src#int_with_suffix
"size (advisory)"
3759 (fun () -> conf
.memlimit
)
3760 (fun v -> conf
.memlimit
<- v);
3764 Printf.sprintf
"%s bytes, %d tiles"
3765 (string_with_suffix_of_int state
.memused
)
3766 (Hashtbl.length state
.tilemap
)) 1;
3769 src#caption
"Layout" 0;
3770 src#caption2
"Dimension"
3772 Printf.sprintf
"%dx%d (virtual %dx%d)"
3773 state
.winw state
.winh
3778 src#caption2
"Position" (fun () ->
3779 Printf.sprintf
"%dx%d" state
.x state
.y
3782 src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
3785 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3786 "Save these parameters as global defaults at exit"
3787 (fun () -> conf
.bedefault
)
3788 (fun v -> conf
.bedefault
<- v);
3791 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3792 src#
bool ~offset
:0 ~
btos "Extended parameters"
3793 (fun () -> !showextended)
3794 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3798 (fun () -> conf
.checkers
)
3799 (fun v -> conf
.checkers
<- v; setcheckers v);
3800 src#
bool "update cursor"
3801 (fun () -> conf
.updatecurs
)
3802 (fun v -> conf
.updatecurs
<- v);
3803 src#
bool "scroll-bar on the left"
3804 (fun () -> conf
.leftscroll
)
3805 (fun v -> conf
.leftscroll
<- v);
3807 (fun () -> conf
.verbose
)
3808 (fun v -> conf
.verbose
<- v);
3809 src#
bool "invert colors"
3810 (fun () -> conf
.invert
)
3811 (fun v -> conf
.invert
<- v);
3813 (fun () -> conf
.maxhfit
)
3814 (fun v -> conf
.maxhfit
<- v);
3816 (fun () -> conf
.pax
!= None
)
3819 then conf
.pax
<- Some
(now
())
3820 else conf
.pax
<- None
);
3821 src#
string "uri launcher"
3822 (fun () -> conf
.urilauncher
)
3823 (fun v -> conf
.urilauncher
<- v);
3824 src#
string "path launcher"
3825 (fun () -> conf
.pathlauncher
)
3826 (fun v -> conf
.pathlauncher
<- v);
3827 src#
string "tile size"
3828 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3831 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3832 conf
.tilew
<- max
64 w;
3833 conf
.tileh
<- max
64 h;
3836 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3839 src#
int "texture count"
3840 (fun () -> conf
.texcount
)
3843 then conf
.texcount
<- v
3844 else impmsg "failed to set texture count please retry later"
3846 src#
int "slice height"
3847 (fun () -> conf
.sliceheight
)
3849 conf
.sliceheight
<- v;
3850 wcmd "sliceh %d" conf
.sliceheight
;
3852 src#
int "anti-aliasing level"
3853 (fun () -> conf
.aalevel
)
3855 conf
.aalevel
<- bound
v 0 8;
3856 state
.anchor <- getanchor
();
3857 opendoc state
.path state
.password;
3859 src#
string "page scroll scaling factor"
3860 (fun () -> string_of_float conf
.pgscale)
3863 let s = float_of_string
v in
3866 state
.text <- Printf.sprintf
3867 "bad page scroll scaling factor `%s': %s" v
3871 src#
int "ui font size"
3872 (fun () -> fstate
.fontsize
)
3873 (fun v -> setfontsize (bound
v 5 100));
3874 src#
int "hint font size"
3875 (fun () -> conf
.hfsize
)
3876 (fun v -> conf
.hfsize
<- bound
v 5 100);
3877 src#
bool "crop hack"
3878 (fun () -> conf
.crophack
)
3879 (fun v -> conf
.crophack
<- v);
3880 src#
string "trim fuzz"
3881 (fun () -> irect_to_string conf
.trimfuzz
)
3884 conf
.trimfuzz
<- irect_of_string
v;
3886 then settrim true conf
.trimfuzz
;
3888 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3891 src#
string "throttle"
3893 match conf
.maxwait
with
3894 | None
-> "show place holder if page is not ready"
3897 then "wait for page to fully render"
3899 "wait " ^ string_of_float
time
3900 ^
" seconds before showing placeholder"
3904 let f = float_of_string
v in
3906 then conf
.maxwait
<- None
3907 else conf
.maxwait
<- Some
f
3909 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3912 src#
string "ghyll scroll"
3914 match conf
.ghyllscroll
with
3916 | Some nab
-> ghyllscroll_to_string nab
3919 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3922 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3924 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3927 src#
string "selection command"
3928 (fun () -> conf
.selcmd
)
3929 (fun v -> conf
.selcmd
<- v);
3930 src#
string "synctex command"
3931 (fun () -> conf
.stcmd
)
3932 (fun v -> conf
.stcmd
<- v);
3933 src#
string "pax command"
3934 (fun () -> conf
.paxcmd
)
3935 (fun v -> conf
.paxcmd
<- v);
3936 src#
string "ask password command"
3937 (fun () -> conf
.passcmd)
3938 (fun v -> conf
.passcmd <- v);
3939 src#
string "save path command"
3940 (fun () -> conf
.savecmd
)
3941 (fun v -> conf
.savecmd
<- v);
3942 src#colorspace
"color space"
3943 (fun () -> CSTE.to_string conf
.colorspace
)
3945 conf
.colorspace
<- CSTE.of_int
v;
3949 src#paxmark
"pax mark method"
3950 (fun () -> MTE.to_string conf
.paxmark
)
3951 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3952 if bousable
() && !opengl_has_pbo
3955 (fun () -> conf
.usepbo
)
3956 (fun v -> conf
.usepbo
<- v);
3957 src#
bool "mouse wheel scrolls pages"
3958 (fun () -> conf
.wheelbypage
)
3959 (fun v -> conf
.wheelbypage
<- v);
3960 src#
bool "open remote links in a new instance"
3961 (fun () -> conf
.riani
)
3962 (fun v -> conf
.riani
<- v);
3963 src#
bool "edit annotations inline"
3964 (fun () -> conf
.annotinline
)
3965 (fun v -> conf
.annotinline
<- v);
3966 src#
bool "coarse positioning in presentation mode"
3967 (fun () -> conf
.coarseprespos
)
3968 (fun v -> conf
.coarseprespos
<- v);
3969 src#
bool "use document CSS"
3970 (fun () -> conf
.usedoccss
)
3972 conf
.usedoccss
<- v;
3973 state
.anchor <- getanchor
();
3974 opendoc state
.path state
.password;
3976 src#
bool ~
btos "colors"
3977 (fun () -> !showcolors)
3978 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
3981 colorp " background"
3982 (fun () -> conf
.bgcolor
)
3983 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3985 (fun () -> conf
.sbarcolor
)
3986 (fun v -> conf
.sbarcolor
<- v);
3987 rgba " scrollbar handle"
3988 (fun () -> conf
.sbarhndlcolor
)
3989 (fun v -> conf
.sbarhndlcolor
<- v);
3994 src#caption
"Document" 0;
3995 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3996 src#caption2
"Pages"
3997 (fun () -> string_of_int state
.pagecount
) 1;
3998 src#caption2
"Dimensions"
3999 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4000 if nonemptystr conf
.css
4001 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
4005 src#caption
"Trimmed margins" 0;
4006 src#caption2
"Dimensions"
4007 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4011 src#caption
"OpenGL" 0;
4012 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4013 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4016 src#caption
"Location" 0;
4017 if nonemptystr state
.origin
4018 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
4019 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
4021 src#reset prevmode prevuioh
;
4026 let prevmode = state
.mode
4027 and prevuioh
= state
.uioh in
4028 fillsrc prevmode prevuioh
;
4029 let source = (src :> lvsource
) in
4030 let modehash = findkeyhash conf
"info" in
4033 inherit listview ~zebra
:false ~helpmode
:false
4034 ~
source ~trusted
:true ~
modehash as super
4035 val mutable m_prevmemused
= 0
4036 method! infochanged
= function
4038 if m_prevmemused
!= state
.memused
4040 m_prevmemused
<- state
.memused
;
4041 G.postRedisplay "memusedchanged";
4043 | Pdim
-> G.postRedisplay "pdimchanged"
4044 | Docinfo
-> fillsrc prevmode prevuioh
4046 method! key key mask
=
4047 if not
(Wsi.withctrl mask
)
4049 match [@warning
"-4"] Wsi.kc2kt
key with
4050 | Keys.Left
-> coe (self#updownlevel ~
-1)
4051 | Keys.Right
-> coe (self#updownlevel
1)
4052 | _ -> super#
key key mask
4053 else super#
key key mask
4055 G.postRedisplay "info";
4061 inherit lvsourcebase
4062 method getitemcount
= Array.length state
.help
4064 let s, l, _ = state
.help
.(n) in
4067 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4071 match state
.help
.(active) with
4072 | _, _, Action
f -> Some
(f uioh)
4073 | _, _, Noaction
-> Some
uioh
4082 method hasaction
n =
4083 match state
.help
.(n) with
4084 | _, _, Action
_ -> true
4085 | _, _, Noaction
-> false
4091 let modehash = findkeyhash conf
"help" in
4093 state
.uioh <- coe (new listview
4094 ~zebra
:false ~helpmode
:true
4095 ~
source ~trusted
:true ~
modehash);
4096 G.postRedisplay "help";
4102 inherit lvsourcebase
4103 val mutable m_items
= E.a
4105 method getitemcount
= 1 + Array.length m_items
4110 else m_items
.(n-1), 0
4112 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4117 then Buffer.clear state
.errmsgs
;
4124 method hasaction
n =
4128 state
.newerrmsgs
<- false;
4129 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4130 m_items
<- Array.of_list
l
4139 let source = (msgsource :> lvsource
) in
4140 let modehash = findkeyhash conf
"listview" in
4143 inherit listview ~zebra
:false ~helpmode
:false
4144 ~
source ~trusted
:false ~
modehash as super
4147 then msgsource#reset
;
4150 G.postRedisplay "msgs";
4154 let editor = getenvwithdef
"EDITOR" E.s in
4158 let tmppath = Filename.temp_file
"llpp" "note" in
4161 let oc = open_out
tmppath in
4165 let execstr = editor ^
" " ^
tmppath in
4167 match spawn
execstr [] with
4169 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4172 match Unix.waitpid
[] pid
with
4174 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4178 | Unix.WEXITED
0 -> filecontents
tmppath
4180 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4182 | Unix.WSIGNALED
n ->
4183 impmsg "editor process(%s) was killed by signal %d" execstr n;
4185 | Unix.WSTOPPED
n ->
4186 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4189 match Unix.unlink
tmppath with
4191 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4196 let enterannotmode opaque slinkindex
=
4199 inherit lvsourcebase
4200 val mutable m_text
= E.s
4201 val mutable m_items
= E.a
4203 method getitemcount
= Array.length m_items
4206 let label, _func
= m_items
.(n) in
4209 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4210 ignore
(uioh, first, pan
);
4213 let _label, func
= m_items
.(active) in
4218 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4221 let rec split accu b i
=
4223 if p = String.length
s
4224 then (String.sub s b (p-b), unit) :: accu
4226 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4228 let ss = if i
= 0 then E.s else String.sub s b i
in
4229 split ((ss, unit)::accu) (p+1) 0
4234 wcmd "freepage %s" (~
> opaque);
4236 Hashtbl.fold (fun key opaque'
accu ->
4237 if opaque'
= opaque'
4238 then key :: accu else accu) state
.pagemap
[]
4240 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4242 gotoxy state
.x state
.y
4245 delannot
opaque slinkindex
;
4248 let edit inline
() =
4253 modannot
opaque slinkindex
s;
4259 let mode = state
.mode in
4262 ("annotation: ", m_text
, None
, textentry
, update, true),
4263 fun _ -> state
.mode <- mode);
4267 let s = getusertext m_text
in
4272 ( "[Copy]", fun () -> selstring m_text
)
4273 :: ("[Delete]", dele)
4274 :: ("[Edit]", edit conf
.annotinline
)
4276 :: split [] 0 0 |> List.rev
|> Array.of_list
4283 let s = getannotcontents
opaque slinkindex
in
4286 let source = (msgsource :> lvsource
) in
4287 let modehash = findkeyhash conf
"listview" in
4288 state
.uioh <- coe (object
4289 inherit listview ~zebra
:false ~helpmode
:false
4290 ~
source ~trusted
:false ~
modehash
4292 G.postRedisplay "enterannotmode";
4295 let gotoremote spec
=
4296 let filename, dest
= splitatchar spec '#'
in
4297 let getpath filename =
4299 if nonemptystr
filename
4301 if Filename.is_relative
filename
4303 let dir = Filename.dirname state
.path in
4305 if Filename.is_implicit
dir
4306 then Filename.concat
(Sys.getcwd
()) dir
4309 Filename.concat
dir filename
4313 if Sys.file_exists
path
4317 let path = getpath filename in
4321 let cmd = Lazy.force_val lcmd
in
4322 match spawn
cmd with
4324 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4326 let anchor = getanchor
() in
4327 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4328 state
.origin
<- E.s;
4329 state
.ranchors
<- ranchor :: state
.ranchors
;
4332 if substratis spec
0 "page="
4334 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4336 state
.anchor <- (pageno, 0.0, 0.0);
4337 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4339 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4341 state
.nameddest
<- dest
;
4342 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4346 let gotounder = function
4347 | Ulinkuri
s when isexternallink
s ->
4348 if substratis
s 0 "file://"
4349 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4352 let pageno, x, y = uritolocation
s in
4354 gotopagexy !wtmode pageno x y
4355 | Utext
_ | Unone
-> ()
4356 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4359 let gotooutline (_, _, kind
) =
4363 let (pageno, y, _) = anchor in
4365 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4369 | Ouri
uri -> gotounder (Ulinkuri
uri)
4370 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4371 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4372 | Ohistory hist
-> gotohist hist
4373 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4376 class outlinesoucebase fetchoutlines
= object (self)
4377 inherit lvsourcebase
4378 val mutable m_items
= E.a
4379 val mutable m_minfo
= E.a
4380 val mutable m_orig_items
= E.a
4381 val mutable m_orig_minfo
= E.a
4382 val mutable m_narrow_patterns
= []
4383 val mutable m_gen
= -1
4385 method getitemcount
= Array.length m_items
4388 let s, n, _ = m_items
.(n) in
4391 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4392 ignore
(uioh, first);
4394 if m_narrow_patterns
= []
4395 then m_orig_items
, m_orig_minfo
4396 else m_items
, m_minfo
4403 gotooutline m_items
.(active);
4411 method hasaction
(_:int) = true
4414 if Array.length m_items
!= Array.length m_orig_items
4417 match m_narrow_patterns
with
4419 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4421 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4425 match m_narrow_patterns
with
4428 | head
:: _ -> UniSyms.ellipsis ^ head
4430 method narrow
pattern =
4431 match Str.regexp_case_fold
pattern with
4434 let rec loop accu minfo n =
4437 m_items
<- Array.of_list
accu;
4438 m_minfo
<- Array.of_list
minfo;
4441 let (s, _, _) as o = m_items
.(n) in
4443 match Str.search_forward re
s 0 with
4444 | exception Not_found
-> accu, minfo
4445 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4447 loop accu minfo (n-1)
4449 loop [] [] (Array.length m_items
- 1)
4451 method! getminfo
= m_minfo
4454 m_orig_items
<- fetchoutlines
();
4455 m_minfo
<- m_orig_minfo
;
4456 m_items
<- m_orig_items
4458 method add_narrow_pattern
pattern =
4459 m_narrow_patterns
<- pattern :: m_narrow_patterns
4461 method del_narrow_pattern
=
4462 match m_narrow_patterns
with
4463 | _ :: rest
-> m_narrow_patterns
<- rest
4468 match m_narrow_patterns
with
4469 | pattern :: [] -> self#narrow
pattern; pattern
4471 List.fold_left
(fun accu pattern ->
4472 self#narrow
pattern;
4473 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4475 method calcactive
(_:anchor) = 0
4477 method reset
anchor items =
4478 if state
.gen
!= m_gen
4480 m_orig_items
<- items;
4482 m_narrow_patterns
<- [];
4484 m_orig_minfo
<- E.a;
4488 if items != m_orig_items
4490 m_orig_items
<- items;
4491 if m_narrow_patterns
== []
4492 then m_items
<- items;
4495 let active = self#calcactive
anchor in
4497 m_first
<- firstof m_first
active
4501 let outlinesource fetchoutlines
=
4503 inherit outlinesoucebase fetchoutlines
4504 method! calcactive
anchor =
4505 let rely = getanchory anchor in
4506 let rec loop n best bestd
=
4507 if n = Array.length m_items
4510 let _, _, kind
= m_items
.(n) in
4513 let orely = getanchory anchor in
4514 let d = abs
(orely - rely) in
4517 else loop (n+1) best bestd
4518 | Onone
| Oremote
_ | Olaunch
_
4519 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4520 loop (n+1) best bestd
4526 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4527 let mkselector sourcetype
=
4528 let fetchoutlines () =
4529 match sourcetype
with
4530 | `bookmarks
-> Array.of_list state
.bookmarks
4531 | `outlines
-> state
.outlines
4532 | `history
-> genhistoutlines () |> Array.of_list
4535 if sourcetype
= `history
4536 then new outlinesoucebase
fetchoutlines
4537 else outlinesource fetchoutlines
4540 let outlines = fetchoutlines () in
4541 if Array.length
outlines = 0
4542 then showtext ' ' errmsg
4545 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4546 let anchor = getanchor
() in
4547 source#reset
anchor outlines;
4548 state
.text <- source#greetmsg
;
4550 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4551 G.postRedisplay "enter selector";
4555 let mkenter sourcetype errmsg
=
4556 let enter = mkselector sourcetype
in
4557 fun () -> enter errmsg
4559 ( mkenter `
outlines "document has no outline"
4560 , mkenter `bookmarks
"document has no bookmarks (yet)"
4561 , mkenter `history
"history is empty" )
4564 let quickbookmark ?title
() =
4565 match state
.layout with
4572 let tm = localtime
(now
()) in
4574 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4576 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4578 | Some
title -> title
4580 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4583 let setautoscrollspeed step goingdown
=
4584 let incr = max
1 ((abs step
) / 2) in
4585 let incr = if goingdown
then incr else -incr in
4586 let astep = boundastep state
.winh
(step
+ incr) in
4587 state
.autoscroll
<- Some
astep;
4591 match conf
.columns
with
4593 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4596 let panbound x = bound
x (-state
.w) state
.winw
;;
4598 let existsinrow pageno (columns
, coverA
, coverB
) p =
4599 let last = ((pageno - coverA
) mod columns
) + columns
in
4600 let rec any = function
4603 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4607 then (if l.pageno = last then false else any rest
)
4615 match state
.layout with
4617 let pageno = page_of_y state
.y in
4618 gotoghyll (getpagey
(pageno+1))
4620 match conf
.columns
with
4622 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4624 let y = clamp (pgscale state
.winh
) in
4627 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4628 gotoghyll (getpagey
pageno)
4629 | Cmulti
((c, _, _) as cl
, _) ->
4630 if conf
.presentation
4631 && (existsinrow l.pageno cl
4632 (fun l -> l.pageh
> l.pagey + l.pagevh))
4634 let y = clamp (pgscale state
.winh
) in
4637 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4638 gotoghyll (getpagey
pageno)
4640 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4642 let pagey, pageh
= getpageyh
l.pageno in
4643 let pagey = pagey + pageh
* l.pagecol
in
4644 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4645 gotoghyll (pagey + pageh
+ ips)
4649 match state
.layout with
4651 let pageno = page_of_y state
.y in
4652 gotoghyll (getpagey
(pageno-1))
4654 match conf
.columns
with
4656 if conf
.presentation
&& l.pagey != 0
4658 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4660 let pageno = max
0 (l.pageno-1) in
4661 gotoghyll (getpagey
pageno)
4662 | Cmulti
((c, _, coverB
) as cl
, _) ->
4663 if conf
.presentation
&&
4664 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4666 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4669 if l.pageno = state
.pagecount
- coverB
4673 let pageno = max
0 (l.pageno-decr) in
4674 gotoghyll (getpagey
pageno)
4682 let pageno = max
0 (l.pageno-1) in
4683 let pagey, pageh
= getpageyh
pageno in
4686 let pagey, pageh
= getpageyh
l.pageno in
4687 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4693 if emptystr conf
.savecmd
4694 then adderrmsg "savepath-command is empty"
4695 "don't know where to save modified document"
4697 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4701 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
4706 let tmp = path ^
".tmp" in
4708 Unix.rename
tmp path;
4711 let viewkeyboard key mask
=
4713 let mode = state
.mode in
4714 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4717 G.postRedisplay "view:enttext"
4719 let ctrl = Wsi.withctrl mask
in
4721 match Wsi.kc2kt
key with
4722 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
4724 | Ascii 'Q'
-> exit
0
4727 if hasunsavedchanges
()
4731 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4734 match state
.lnava
with
4735 | None
-> LinkNav
(Ltgendir
0)
4736 | Some
pn -> LinkNav
(Ltexact
pn)
4738 gotoxy state
.x state
.y;
4740 else impmsg "keyboard link navigation does not work under rotation"
4742 | Escape
| Ascii 'q'
->
4743 begin match state
.mstate
with
4746 G.postRedisplay "kill rect";
4749 | Mscrolly
| Mscrollx
4752 begin match state
.mode with
4755 | Ltexact pl
-> state
.lnava
<- Some pl
4756 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4759 G.postRedisplay "esc leave linknav"
4760 | Birdseye
_ | Textentry
_ | View
->
4761 match state
.ranchors
with
4763 | (path, password, anchor, origin
) :: rest
->
4764 state
.ranchors
<- rest
;
4765 state
.anchor <- anchor;
4766 state
.origin
<- origin
;
4767 state
.nameddest
<- E.s;
4768 opendoc path password
4774 gotoghyll (getnav ~
-1)
4785 Hashtbl.iter
(fun _ opaque ->
4787 Hashtbl.clear state
.prects
) state
.pagemap
;
4788 G.postRedisplay "dehighlight";
4790 | Ascii
(('
/'
| '?'
) as c) ->
4791 let ondone isforw
s =
4792 cbput state
.hists
.pat
s;
4793 state
.searchpattern
<- s;
4796 let s = String.make
1 c in
4797 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4798 textentry
, ondone (c = '
/'
), true)
4800 | Ascii '
+'
| Ascii '
='
when ctrl ->
4801 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4802 pivotzoom (conf
.zoom +. incr)
4807 try int_of_string
s with exn
->
4809 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4815 state
.text <- "page bias is now " ^ string_of_int
n;
4818 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4820 | Ascii '
-'
when ctrl ->
4821 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4822 pivotzoom (max
0.01 (conf
.zoom -. decr))
4825 let ondone msg
= state
.text <- msg
in
4827 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4828 optentry state
.mode, ondone, true
4831 | Ascii '
0'
when ctrl ->
4833 then gotoxy 0 state
.y
4836 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4838 match conf
.columns
with
4839 | Csingle
_ | Cmulti
_ -> 1
4840 | Csplit
(n, _) -> n
4842 let h = state
.winh
-
4843 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4845 let zoom = zoomforh state
.winw
h 0 cols in
4846 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4849 | Ascii '
3'
when ctrl ->
4851 match conf
.fitmodel
with
4852 | FitWidth
-> FitProportional
4853 | FitProportional
-> FitPage
4854 | FitPage
-> FitWidth
4856 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4857 reqlayout conf
.angle
fm
4859 | Ascii '
4'
when ctrl ->
4860 let zoom = getmaxw
() /. float state
.winw
in
4861 if zoom > 0.0 then setzoom zoom
4866 | Ascii '
9'
when ctrl ->
4869 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
4872 try int_of_string
s with exn
->
4873 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4879 cbput state
.hists
.pag
(string_of_int
n);
4880 gotopage1 (n + conf
.pagebias
- 1) 0;
4883 let [@warning
"-4"] pageentry
text = function
4884 | Keys.Ascii '
g'
-> TEdone
text
4885 | key -> intentry
text key
4887 let text = String.make
1 c in
4888 enttext (":", text, Some
(onhist state
.hists
.pag
),
4889 pageentry
, ondone, true)
4892 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4893 G.postRedisplay "toggle scrollbar";
4896 state
.bzoom
<- not state
.bzoom
;
4898 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4901 conf
.hlinks
<- not conf
.hlinks
;
4902 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4903 G.postRedisplay "toggle highlightlinks";
4906 if conf
.angle
mod 360 = 0
4908 state
.glinks
<- true;
4909 let mode = state
.mode in
4912 (":", E.s, None
, linknentry
, linknact gotounder, false),
4914 state
.glinks
<- false;
4918 G.postRedisplay "view:linkent(F)"
4920 else impmsg "hint mode does not work under rotation"
4923 state
.glinks
<- true;
4924 let mode = state
.mode in
4927 (":", E.s, None
, linknentry
,
4928 linknact (fun under -> selstring (undertext under)), false),
4930 state
.glinks
<- false;
4934 G.postRedisplay "view:linkent"
4937 begin match state
.autoscroll
with
4939 conf
.autoscrollstep
<- step
;
4940 state
.autoscroll
<- None
4942 state
.autoscroll
<- Some conf
.autoscrollstep
;
4943 state
.slideshow
<- state
.slideshow
land lnot
2
4946 | Ascii '
p'
when ctrl ->
4947 launchpath () (* XXX where do error messages go? *)
4950 setpresentationmode (not conf
.presentation
);
4951 showtext ' '
("presentation mode " ^
4952 if conf
.presentation
then "on" else "off");
4955 if List.mem
Wsi.Fullscreen state
.winstate
4956 then Wsi.reshape conf
.cwinw conf
.cwinh
4957 else Wsi.fullscreen
()
4959 | Ascii
('
p'
|'N'
) ->
4960 search state
.searchpattern
false
4962 | Ascii '
n'
| Fn
3 ->
4963 search state
.searchpattern
true
4966 begin match state
.layout with
4969 gotoghyll (getpagey
l.pageno)
4979 showtext ' '
(describe_layout state
.layout);
4982 begin match state
.layout with
4985 Wsi.reshape l.pagew
l.pageh
;
4990 enterbookmarkmode
()
4992 | Ascii '
h'
| Fn
1 ->
4998 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
5003 match state
.layout with
5008 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
5011 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
5015 showtext ' '
"Quick bookmark added";
5018 begin match state
.layout with
5020 let rect = getpdimrect
l.pagedimno
in
5024 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5025 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5027 (truncate
(rect.(1) -. rect.(0)),
5028 truncate
(rect.(3) -. rect.(0)))
5030 let w = truncate
((float w)*.conf
.zoom)
5031 and h = truncate
((float h)*.conf
.zoom) in
5034 state
.anchor <- getanchor
();
5035 Wsi.reshape w (h + conf
.interpagespace
)
5037 G.postRedisplay "z";
5042 | Ascii '
x'
-> state
.roam
()
5044 | Ascii
('
<'
|'
>'
as c) ->
5046 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5048 | Ascii
('
['
|'
]'
as c) ->
5050 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
5051 G.postRedisplay "brightness";
5053 | Ascii '
c'
when state
.mode = View
->
5058 let m = (state
.winw
- state
.w) / 2 in
5059 gotoxy_and_clear_text m state
.y
5063 match state
.prevcolumns
with
5064 | None
-> (1, 0, 0), 1.0
5065 | Some
(columns
, z
) ->
5068 | Csplit
(c, _) -> -c, 0, 0
5069 | Cmulti
((c, a, b), _) -> c, a, b
5070 | Csingle
_ -> 1, 0, 0
5074 setcolumns View
c a b;
5077 | Down
| Up
when ctrl && Wsi.withshift mask
->
5078 let zoom, x = state
.prevzoom
in
5083 begin match state
.autoscroll
with
5085 begin match state
.mode with
5086 | Birdseye beye
-> upbirdseye 1 beye
5087 | Textentry
_ | View
| LinkNav
_ ->
5089 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5091 if not
(Wsi.withshift mask
) && conf
.presentation
5093 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5097 setautoscrollspeed n false
5100 | Ascii 'j'
| Down
->
5101 begin match state
.autoscroll
with
5103 begin match state
.mode with
5104 | Birdseye beye
-> downbirdseye 1 beye
5105 | Textentry
_ | View
| LinkNav
_ ->
5107 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5109 if not
(Wsi.withshift mask
) && conf
.presentation
5111 else gotoghyll1 true (clamp (conf
.scrollstep
))
5115 setautoscrollspeed n true
5118 | Left
| Right
when not
(Wsi.withalt mask
) ->
5124 else conf
.hscrollstep
5127 let pv = Wsi.kc2kt
key in
5128 if pv = Keys.Left
then dx else -dx
5130 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5133 G.postRedisplay "left/right"
5140 match state
.layout with
5142 | l :: _ -> state
.y - l.pagey
5144 clamp (pgscale (-state
.winh
))
5152 match List.rev state
.layout with
5154 | l :: _ -> getpagey
l.pageno
5156 clamp (pgscale state
.winh
)
5160 | Ascii '
g'
| Home
->
5163 | Ascii 'G'
| End
->
5165 gotoghyll (clamp state
.maxy)
5167 | Right
when Wsi.withalt mask
->
5169 gotoghyll (getnav 1)
5170 | Left
when Wsi.withalt mask
->
5172 gotoghyll (getnav ~
-1)
5177 | Ascii '
v'
when conf
.debug
->
5180 match getopaque l.pageno with
5183 let x0, y0, x1, y1 = pagebbox
opaque in
5184 let rect = (float x0, float y0,
5187 float x0, float y1) in
5189 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5190 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5192 G.postRedisplay "v";
5195 let mode = state
.mode in
5196 let cmd = ref E.s in
5197 let onleave = function
5198 | Cancel
-> state
.mode <- mode
5201 match getopaque l.pageno with
5202 | Some
opaque -> pipesel opaque !cmd
5203 | None
-> ()) state
.layout;
5207 cbput state
.hists
.sel
s;
5211 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
5213 G.postRedisplay "|";
5214 state
.mode <- Textentry
(te, onleave);
5216 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
5217 vlog "huh? %s" (Wsi.keyname
key)
5220 let linknavkeyboard key mask
linknav =
5221 let pv = Wsi.kc2kt
key in
5222 let getpage pageno =
5223 let rec loop = function
5225 | l :: _ when l.pageno = pageno -> Some
l
5226 | _ :: rest
-> loop rest
5227 in loop state
.layout
5229 let doexact (pageno, n) =
5230 match getopaque pageno, getpage pageno with
5231 | Some
opaque, Some
l ->
5234 let under = getlink
opaque n in
5235 G.postRedisplay "link gotounder";
5242 | Home
-> Some
(findlink
opaque LDfirst
), -1
5243 | End
-> Some
(findlink
opaque LDlast
), 1
5244 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
5245 | Right
-> Some
(findlink
opaque (LDright
n)), 1
5246 | Up
-> Some
(findlink
opaque (LDup
n)), -1
5247 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
5249 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
5250 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
5253 begin match findpwl
l.pageno dir with
5257 state
.mode <- LinkNav
(Ltgendir
dir);
5258 let y, h = getpageyh
pageno in
5261 then y + h - state
.winh
5266 begin match getopaque pageno, getpage pageno with
5267 | Some
opaque, Some
_ ->
5269 let ld = if dir > 0 then LDfirst
else LDlast
in
5272 begin match link with
5274 showlinktype (getlink
opaque m);
5275 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5276 G.postRedisplay "linknav jpage";
5277 | Lnotfound
-> notfound dir
5283 begin match opt with
5284 | Some Lnotfound
-> pwl l dir;
5285 | Some
(Lfound
m) ->
5289 let _, y0, _, y1 = getlinkrect
opaque m in
5291 then gotopage1 l.pageno y0
5293 let d = fstate
.fontsize
+ 1 in
5294 if y1 - l.pagey > l.pagevh - d
5295 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5296 else G.postRedisplay "linknav";
5298 showlinktype (getlink
opaque m);
5299 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5302 | None
-> viewkeyboard key mask
5304 | _ -> viewkeyboard key mask
5308 begin match linknav with
5309 | Ltexact pa
-> state
.lnava
<- Some pa
5310 | Ltgendir
_ | Ltnotready
_ -> ()
5313 G.postRedisplay "leave linknav"
5317 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5318 | Ltexact exact
-> doexact exact
5321 let keyboard key mask
=
5322 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5323 then wcmd "interrupt"
5324 else state
.uioh <- state
.uioh#
key key mask
5327 let birdseyekeyboard key mask
5328 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5330 match conf
.columns
with
5332 | Cmulti
((c, _, _), _) -> c
5333 | Csplit
_ -> failwith
"bird's eye split mode"
5335 let pgh layout = List.fold_left
5336 (fun m l -> max
l.pageh
m) state
.winh
layout in
5338 match Wsi.kc2kt
key with
5339 | Ascii '
l'
when Wsi.withctrl mask
->
5340 let y, h = getpageyh
pageno in
5341 let top = (state
.winh
- h) / 2 in
5342 gotoxy state
.x (max
0 (y - top))
5343 | Enter
-> leavebirdseye beye
false
5344 | Escape
-> leavebirdseye beye
true
5345 | Up
-> upbirdseye incr beye
5346 | Down
-> downbirdseye incr beye
5347 | Left
-> upbirdseye 1 beye
5348 | Right
-> downbirdseye 1 beye
5351 begin match state
.layout with
5355 state
.mode <- Birdseye
(
5356 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5358 gotopage1 l.pageno 0;
5361 let layout = layout state
.x (state
.y-state
.winh
)
5363 (pgh state
.layout) in
5365 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5367 state
.mode <- Birdseye
(
5368 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5370 gotopage1 l.pageno 0
5373 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5377 begin match List.rev state
.layout with
5379 let layout = layout state
.x
5380 (state
.y + (pgh state
.layout))
5381 state
.winw state
.winh
in
5382 begin match layout with
5384 let incr = l.pageh
- l.pagevh in
5389 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5391 G.postRedisplay "birdseye pagedown";
5393 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5397 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5398 gotopage1 l.pageno 0;
5401 | [] -> gotoxy state
.x (clamp state
.winh
)
5405 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5409 let pageno = state
.pagecount
- 1 in
5410 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5411 if not
(pagevisible state
.layout pageno)
5414 match List.rev state
.pdims
with
5416 | (_, _, h, _) :: _ -> h
5420 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5421 else G.postRedisplay "birdseye end";
5423 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
5428 match state
.mode with
5429 | Textentry
_ -> scalecolor 0.4
5430 | LinkNav
_ | View
-> scalecolor 1.0
5431 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5432 if l.pageno = hooverpageno
5435 if l.pageno = pageno
5437 let c = scalecolor 1.0 in
5439 GlDraw.line_width
3.0;
5440 let dispx = l.pagedispx in
5442 (float (dispx-1)) (float (l.pagedispy-1))
5443 (float (dispx+l.pagevw+1))
5444 (float (l.pagedispy+l.pagevh+1))
5446 GlDraw.line_width
1.0;
5455 let postdrawpage l linkindexbase
=
5456 match getopaque l.pageno with
5458 if tileready l l.pagex
l.pagey
5460 let x = l.pagedispx - l.pagex
5461 and y = l.pagedispy - l.pagey in
5463 match conf
.columns
with
5464 | Csingle
_ | Cmulti
_ ->
5465 (if conf
.hlinks
then 1 else 0)
5467 && not
(isbirdseye state
.mode) then 2 else 0)
5471 match state
.mode with
5472 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5478 Hashtbl.find_all state
.prects
l.pageno |>
5479 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5480 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5482 then (state
.redisplay
<- true; 0)
5488 let scrollindicator () =
5489 let sbw, ph
, sh = state
.uioh#
scrollph in
5490 let sbh, pw, sw = state
.uioh#scrollpw
in
5495 else ((state
.winw
- sbw), state
.winw
, 0)
5499 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5500 let (r, g, b, alpha) = conf
.sbarcolor
in
5501 GlDraw.color (r, g, b) ~
alpha;
5502 filledrect (float x0) 0. (float x1) (float state
.winh
);
5504 (float hx0
) (float (state
.winh
- sbh))
5505 (float (hx0
+ state
.winw
)) (float state
.winh
);
5506 let (r, g, b, alpha) = conf
.sbarhndlcolor
in
5507 GlDraw.color (r, g, b) ~
alpha;
5509 filledrect (float x0) ph
(float x1) (ph
+. sh);
5510 let pw = pw +. float hx0
in
5511 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5516 match state
.mstate
with
5517 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5520 | Msel
((x0, y0), (x1, y1)) ->
5521 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5522 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5523 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5524 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5531 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5532 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5534 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5536 if l.pageno = pageno
5538 let dx = float (l.pagedispx - l.pagex
) in
5539 let dy = float (l.pagedispy - l.pagey) in
5540 let r, g, b, alpha = c in
5541 GlDraw.color (r, g, b) ~
alpha;
5542 filledrect2 (x0+.dx) (y0+.dy)
5553 GlDraw.color (scalecolor2 conf
.bgcolor
);
5554 GlClear.color (scalecolor2 conf
.bgcolor
);
5555 GlClear.clear
[`
color];
5556 List.iter
drawpage state
.layout;
5558 match state
.mode with
5559 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5560 begin match getopaque pageno with
5562 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5563 let color = (0.0, 0.0, 0.5, 0.5) in
5565 (float x0, float y0,
5570 | None
-> state
.rects
5572 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5575 | View
-> state
.rects
5578 let rec postloop linkindexbase
= function
5580 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5581 postloop linkindexbase rest
5585 postloop 0 state
.layout;
5587 begin match state
.mstate
with
5588 | Mzoomrect
((x0, y0), (x1, y1)) ->
5590 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5591 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5592 filledrect (float x0) (float y0) (float x1) (float y1);
5596 | Mscrolly
| Mscrollx
5605 let zoomrect x y x1 y1 =
5608 and y0 = min
y y1 in
5609 let zoom = (float state
.w) /. float (x1 - x0) in
5612 if state
.w < state
.winw
5613 then (state
.winw
- state
.w) / 2
5616 match conf
.fitmodel
with
5617 | FitWidth
| FitProportional
-> simple ()
5619 match conf
.columns
with
5621 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5622 | Cmulti
_ | Csingle
_ -> simple ()
5624 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5625 state
.anchor <- getanchor
();
5630 let annot inline
x y =
5631 match unproject x y with
5632 | Some
(opaque, n, ux
, uy
) ->
5634 addannot
opaque ux uy
text;
5635 wcmd "freepage %s" (~
> opaque);
5636 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5638 gotoxy state
.x state
.y
5642 let ondone s = add s in
5643 let mode = state
.mode in
5644 state
.mode <- Textentry
(
5645 ("annotation: ", E.s, None
, textentry
, ondone, true),
5646 fun _ -> state
.mode <- mode);
5649 G.postRedisplay "annot"
5651 add @@ getusertext E.s
5656 let g opaque l px py =
5657 match rectofblock
opaque px py with
5659 let x0 = a.(0) -. 20. in
5660 let x1 = a.(1) +. 20. in
5661 let y0 = a.(2) -. 20. in
5662 let zoom = (float state
.w) /. (x1 -. x0) in
5663 let pagey = getpagey
l.pageno in
5664 let margin = (state
.w - l.pagew
)/2 in
5665 let nx = -truncate
x0 - margin in
5666 gotoxy_and_clear_text nx (pagey + truncate
y0);
5667 state
.anchor <- getanchor
();
5672 match conf
.columns
with
5674 impmsg "block zooming does not work properly in split columns mode"
5675 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5679 let winw = state
.winw - 1 in
5680 let s = float x /. float winw in
5681 let destx = truncate
(float (state
.w + winw) *. s) in
5682 gotoxy_and_clear_text (winw - destx) state
.y;
5683 state
.mstate
<- Mscrollx
;
5687 let s = float y /. float state
.winh
in
5688 let desty = truncate
(s *. float (maxy ())) in
5689 gotoxy_and_clear_text state
.x desty;
5690 state
.mstate
<- Mscrolly
;
5693 let viewmulticlick clicks
x y mask
=
5694 let g opaque l px py =
5702 if markunder
opaque px py mark
5706 match getopaque l.pageno with
5708 | Some
opaque -> pipesel opaque cmd
5710 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5711 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5716 G.postRedisplay "viewmulticlick";
5717 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5721 match conf
.columns
with
5723 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5726 let viewmouse button down
x y mask
=
5728 | n when (n == 4 || n == 5) && not down
->
5729 if Wsi.withctrl mask
5733 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5734 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5737 match state
.mstate
with
5738 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
5739 | Mzoomrect
_ | Mnone
| Mpan
_
5740 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
5742 let zoom = conf
.zoom -. incr in
5743 state
.mstate
<- Mzoom
(n, 0, (x, y));
5744 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
5745 then pivotzoom ~
x ~
y zoom
5749 match state
.autoscroll
with
5750 | Some step
-> setautoscrollspeed step
(n=4)
5752 if conf
.wheelbypage
|| conf
.presentation
5761 then -conf
.scrollstep
5762 else conf
.scrollstep
5764 let incr = incr * 2 in
5765 let y = clamp incr in
5766 gotoxy_and_clear_text state
.x y
5769 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5771 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5772 gotoxy_and_clear_text x state
.y
5774 | 1 when Wsi.withshift mask
->
5775 state
.mstate
<- Mnone
;
5778 match unproject x y with
5780 | Some
(_, pageno, ux
, uy
) ->
5781 let cmd = Printf.sprintf
5783 conf
.stcmd state
.path pageno ux uy
5785 match spawn
cmd [] with
5787 impmsg "execution of synctex command(%S) failed: %S"
5788 conf
.stcmd
@@ exntos exn
5792 | 1 when Wsi.withctrl mask
->
5795 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5796 state
.mstate
<- Mpan
(x, y)
5799 state
.mstate
<- Mnone
5804 if Wsi.withshift mask
5806 annot conf
.annotinline
x y;
5807 G.postRedisplay "addannot"
5811 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5812 state
.mstate
<- Mzoomrect
(p, p)
5815 match state
.mstate
with
5816 | Mzoomrect
((x0, y0), _) ->
5817 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5818 then zoomrect x0 y0 x y
5821 G.postRedisplay "kill accidental zoom rect";
5825 | Mscrolly
| Mscrollx
5827 | Mnone
-> resetmstate ()
5830 | 1 when vscrollhit x ->
5833 let _, position, sh = state
.uioh#
scrollph in
5834 if y > truncate
position && y < truncate
(position +. sh)
5835 then state
.mstate
<- Mscrolly
5838 state
.mstate
<- Mnone
5840 | 1 when y > state
.winh
- hscrollh () ->
5843 let _, position, sw = state
.uioh#scrollpw
in
5844 if x > truncate
position && x < truncate
(position +. sw)
5845 then state
.mstate
<- Mscrollx
5848 state
.mstate
<- Mnone
5850 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5853 let dest = if down
then getunder x y else Unone
in
5854 begin match dest with
5858 | Unone
when down
->
5859 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5860 state
.mstate
<- Mpan
(x, y);
5862 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5864 | Unone
| Utext
_ ->
5869 state
.mstate
<- Msel
((x, y), (x, y));
5870 G.postRedisplay "mouse select";
5874 match state
.mstate
with
5877 | Mzoom
_ | Mscrollx
| Mscrolly
->
5878 state
.mstate
<- Mnone
5880 | Mzoomrect
((x0, y0), _) ->
5884 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5885 state
.mstate
<- Mnone
5887 | Msel
((x0, y0), (x1, y1)) ->
5888 let rec loop = function
5892 let a0 = l.pagedispy in
5893 let a1 = a0 + l.pagevh in
5894 let b0 = l.pagedispx in
5895 let b1 = b0 + l.pagevw in
5896 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5897 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5901 match getopaque l.pageno with
5904 pipef ~closew
:false "Msel"
5907 G.postRedisplay "Msel") cmd
5909 dosel conf
.selcmd
();
5910 state
.roam
<- dosel conf
.paxcmd
;
5922 let birdseyemouse button down
x y mask
5923 (conf
, leftx
, _, hooverpageno
, anchor) =
5926 let rec loop = function
5929 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5930 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5932 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5938 | _ -> viewmouse button down
x y mask
5944 method key key mask
=
5945 begin match state
.mode with
5946 | Textentry textentry
-> textentrykeyboard
key mask textentry
5947 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5948 | View
-> viewkeyboard key mask
5949 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5953 method button button bstate
x y mask
=
5954 begin match state
.mode with
5955 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5956 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5961 method multiclick clicks
x y mask
=
5962 begin match state
.mode with
5963 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5964 | Birdseye
_ | Textentry
_ -> ()
5969 begin match state
.mode with
5971 | View
| Birdseye
_ | LinkNav
_ ->
5972 match state
.mstate
with
5973 | Mzoom
_ | Mnone
-> ()
5978 state
.mstate
<- Mpan
(x, y);
5979 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5981 gotoxy_and_clear_text x y
5984 state
.mstate
<- Msel
(a, (x, y));
5985 G.postRedisplay "motion select";
5988 let y = min state
.winh
(max
0 y) in
5992 let x = min state
.winw (max
0 x) in
5995 | Mzoomrect
(p0
, _) ->
5996 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5997 G.postRedisplay "motion zoomrect";
6001 method pmotion
x y =
6002 begin match state
.mode with
6003 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6004 let rec loop = function
6006 if hooverpageno
!= -1
6008 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6009 G.postRedisplay "pmotion birdseye no hoover";
6012 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6013 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6015 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6016 G.postRedisplay "pmotion birdseye hoover";
6024 | LinkNav
_ | View
->
6025 match state
.mstate
with
6026 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6035 let delta = now -. past
in
6038 else conf
.pax
<- Some
now
6042 method infochanged
_ = ()
6045 let maxy = maxy () in
6048 then 0.0, float state
.winh
6049 else scrollph state
.y maxy
6054 let fwinw = float (state
.winw - vscrollw ()) in
6056 let sw = fwinw /. float state
.w in
6057 let sw = fwinw *. sw in
6058 max
sw (float conf
.scrollh
)
6061 let maxx = state
.w + state
.winw in
6062 let x = state
.winw - state
.x in
6063 let percent = float x /. float maxx in
6064 (fwinw -. sw) *. percent
6066 hscrollh (), position, sw
6070 match state
.mode with
6071 | LinkNav
_ -> "links"
6072 | Textentry
_ -> "textentry"
6073 | Birdseye
_ -> "birdseye"
6076 findkeyhash conf
modename
6078 method eformsgs
= true
6079 method alwaysscrolly
= false
6080 method scroll dx dy =
6081 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6082 gotoxy_and_clear_text x (clamp (2 * dy));
6085 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
6088 let addrect pageno r g b a x0 y0 x1 y1 =
6089 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6093 let cl = splitatchar cmds ' '
in
6095 try Scanf.sscanf
s fmt
f
6096 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6099 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6100 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6101 s pageno r g b a x0 y0 x1 y1;
6105 let _,w1,h1
,_ = getpagedim
pageno in
6106 let sw = float w1 /. float w
6107 and sh = float h1
/. float h in
6111 and y1s
= y1 *. sh in
6112 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6113 let color = (r, g, b, a) in
6114 if conf
.verbose
then debugrect rect;
6115 state
.rects <- (pageno, color, rect) :: state
.rects;
6120 | "reload", "" -> reload ()
6122 scan args
"%u %f %f"
6124 let cmd, _ = state
.geomcmds
in
6126 then gotopagexy !wtmode pageno x y
6129 gotopagexy !wtmode pageno x y;
6132 state
.reprf
<- f state
.reprf
6134 | "goto1", args
-> scan args
"%u %f" gotopage
6135 | "gotor", args
-> scan args
"%S" gotoremote
6137 scan args
"%u %u %f %f %f %f"
6138 (fun pageno c x0 y0 x1 y1 ->
6139 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6140 rectx "rect" pageno color x0 y0 x1 y1;
6143 scan args
"%u %f %f %f %f %f %f %f %f"
6144 (fun pageno r g b alpha x0 y0 x1 y1 ->
6145 addrect pageno r g b alpha x0 y0 x1 y1;
6146 G.postRedisplay "prect"
6149 scan args
"%u %f %f"
6152 match getopaque pageno with
6153 | Some
opaque -> opaque
6156 pgoto optopaque pageno x y;
6157 let rec fixx = function
6160 if l.pageno = pageno
6161 then gotoxy (state
.x - l.pagedispx) state
.y
6166 match conf
.columns
with
6167 | Csingle
_ | Csplit
_ -> 1
6168 | Cmulti
((n, _, _), _) -> n
6170 layout 0 state
.y (state
.winw * mult) state
.winh
6174 | "activatewin", "" -> Wsi.activatewin
()
6175 | "quit", "" -> raise Quit
6178 let l = Config.keys_of_string
keys in
6179 List.iter
(fun (k
, m) -> keyboard k
m) l
6180 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6183 | "clearrects", "" ->
6184 Hashtbl.clear state
.prects
;
6185 G.postRedisplay "clearrects"
6187 adderrfmt "remote command"
6188 "error processing remote command: %S\n" cmds
;
6192 let scratch = Bytes.create
80 in
6193 let buf = Buffer.create
80 in
6195 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6196 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6199 if Buffer.length
buf > 0
6201 let s = Buffer.contents
buf in
6209 match Bytes.index_from
scratch ppos '
\n'
with
6210 | pos
-> if pos
>= n then -1 else pos
6211 | exception Not_found
-> -1
6215 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6216 let s = Buffer.contents
buf in
6222 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6228 let remoteopen path =
6229 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6231 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6236 let gcconfig = ref false in
6237 let trimcachepath = ref E.s in
6238 let rcmdpath = ref E.s in
6239 let pageno = ref None
in
6240 let rootwid = ref 0 in
6241 let openlast = ref false in
6242 let doreap = ref false in
6243 let csspath = ref None
in
6244 selfexec := Sys.executable_name
;
6247 [("-p", Arg.String
(fun s -> state
.password <- s),
6248 "<password> Set password");
6252 Config.fontpath
:= s;
6253 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6255 "<path> Set path to the user interface font");
6259 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6260 Config.confpath
:= s),
6261 "<path> Set path to the configuration file");
6263 ("-last", Arg.Set
openlast, " Open last document");
6265 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6266 "<page-number> Jump to page");
6268 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6269 "<path> Set path to the trim cache file");
6271 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6272 "<named-destination> Set named destination");
6274 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6275 ("-cxack", Arg.Set
cxack, " Cut corners");
6277 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6278 "<path> Set path to the source of remote commands");
6280 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
6282 ("-v", Arg.Unit
(fun () ->
6284 "%s\nconfiguration path: %s\n"
6287 exit
0), " Print version and exit");
6289 ("-css", Arg.String
(fun s -> csspath := Some
s),
6290 "<path> Set path to the style sheet to use with EPUB/HTML");
6292 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6294 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6295 "<origin> <undocumented>");
6298 (fun s -> state
.path <- s)
6299 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6302 then selfexec := !selfexec ^
" -wtmode";
6304 let histmode = emptystr state
.path && not
!openlast in
6306 if not
(Config.load !openlast)
6307 then dolog
"failed to load configuration";
6309 begin match !pageno with
6310 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6322 val mutable m_clicks
= 0
6323 val mutable m_click_x
= 0
6324 val mutable m_click_y
= 0
6325 val mutable m_lastclicktime
= infinity
6327 method private cleanup =
6328 state
.roam
<- noroam
;
6329 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6330 method expose
= G.postRedisplay "expose"
6334 | Wsi.Unobscured
-> "unobscured"
6335 | Wsi.PartiallyObscured
-> "partiallyobscured"
6336 | Wsi.FullyObscured
-> "fullyobscured"
6338 vlog "visibility change %s" name
6339 method display = display ()
6340 method map mapped
= vlog "mapped %b" mapped
6341 method reshape w h =
6344 method mouse
b d x y m =
6345 if d && canselect ()
6348 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6355 if abs
x - m_click_x
> 10
6356 || abs
y - m_click_y
> 10
6357 || abs_float
(t -. m_lastclicktime
) > 0.3
6359 m_clicks
<- m_clicks
+ 1;
6360 m_lastclicktime
<- t;
6364 G.postRedisplay "cleanup";
6365 state
.uioh <- state
.uioh#button
b d x y m;
6367 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6372 m_lastclicktime
<- infinity
;
6373 state
.uioh <- state
.uioh#button
b d x y m
6377 state
.uioh <- state
.uioh#button
b d x y m
6380 state
.mpos
<- (x, y);
6381 state
.uioh <- state
.uioh#motion
x y
6382 method pmotion
x y =
6383 state
.mpos
<- (x, y);
6384 state
.uioh <- state
.uioh#pmotion
x y
6386 vlog "k=%#x m=%#x" k
m;
6387 let mascm = m land (
6388 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6391 let x = state
.x and y = state
.y in
6393 if x != state
.x || y != state
.y then self#
cleanup
6395 match state
.keystate
with
6397 let km = k
, mascm in
6400 let modehash = state
.uioh#
modehash in
6401 try Hashtbl.find modehash km
6403 try Hashtbl.find (findkeyhash conf
"global") km
6404 with Not_found
-> KMinsrt
(k
, m)
6406 | KMinsrt
(k
, m) -> keyboard k
m
6407 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6408 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6410 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6411 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6412 state
.keystate
<- KSnone
6413 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6414 state
.keystate
<- KSinto
(keys, insrt
)
6415 | KSinto
_ -> state
.keystate
<- KSnone
6418 state
.mpos
<- (x, y);
6419 state
.uioh <- state
.uioh#pmotion
x y
6420 method leave = state
.mpos
<- (-1, -1)
6421 method winstate wsl
= state
.winstate
<- wsl
6422 method quit
: '
a. '
a = raise Quit
6423 method scroll dx dy = state
.uioh <- state
.uioh#
scroll dx dy
6424 method zoom z
x y = state
.uioh#
zoom z
x y
6425 method opendoc path =
6428 G.postRedisplay "opendoc";
6429 opendoc path state
.password
6432 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6434 setbgcol conf
.bgcolor
;
6437 if not
@@ List.exists
GlMisc.check_extension
6438 [ "GL_ARB_texture_rectangle"
6439 ; "GL_EXT_texture_recangle"
6440 ; "GL_NV_texture_rectangle" ]
6441 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6443 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6445 defconf
.sliceheight
<- 1024;
6446 defconf
.texcount
<- 32;
6447 defconf
.usepbo
<- true;
6451 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6453 dolog
"socketpair failed: %s" @@ exntos exn
;
6461 setcheckers conf
.checkers
;
6463 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6465 begin match !csspath with
6467 | Some
"" -> conf
.css
<- E.s
6469 let css = filecontents
path in
6470 let l = String.length
css in
6472 if substratis
css (l-2) "\r\n"
6473 then String.sub css 0 (l-2)
6474 else (if css.[l-1] = '
\n'
6475 then String.sub css 0 (l-1)
6479 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6480 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6481 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6483 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6485 reshape ~firsttime
:true winw winh
;
6489 Wsi.settitle
"llpp (history)";
6493 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6494 opendoc state
.path state
.password;
6498 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6499 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6502 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6503 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6504 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6506 | _pid
, _status
-> reap ()
6508 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6512 if nonemptystr
!rcmdpath
6513 then remoteopen !rcmdpath
6518 let rec loop deadline
=
6524 let r = [state
.ss; state
.wsfd] in
6528 | Some fd
-> fd
:: r
6532 state
.redisplay
<- false;
6539 if deadline
= infinity
6541 else max
0.0 (deadline
-. now)
6546 try Unix.select
r [] [] timeout
6547 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6553 if state
.ghyll
== noghyll
6555 match state
.autoscroll
with
6556 | Some step
when step
!= 0 ->
6557 if state
.slideshow
land 1 = 1
6559 if state
.slideshow
land 2 = 0
6560 then state
.slideshow
<- state
.slideshow
lor 2
6561 else if step
< 0 then prevpage () else nextpage ();
6562 deadline
+. (float (abs step
))
6565 let y = state
.y + step
in
6566 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6569 then state
.maxy - fy
6570 else if y >= state
.maxy - fy then 0 else y
6572 if state
.mode = View
6573 then gotoxy_and_clear_text state
.x y
6574 else gotoxy state
.x y;
6577 else deadline
+. 0.01
6582 let rec checkfds = function
6584 | fd
:: rest
when fd
= state
.ss ->
6585 let cmd = rcmd state
.ss in
6589 | fd
:: rest
when fd
= state
.wsfd ->
6593 | fd
:: rest
when Some fd
= !optrfd ->
6594 begin match remote fd
with
6595 | None
-> optrfd := remoteopen !rcmdpath;
6596 | opt -> optrfd := opt
6601 dolog
"select returned unknown descriptor";
6607 if deadline
= infinity
6611 match state
.autoscroll
with
6612 | Some step
when step
!= 0 -> deadline1
6613 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6618 match loop infinity
with
6620 Config.save leavebirdseye;
6621 if hasunsavedchanges
()
6623 | _ -> error
"umpossible - infinity reached"