6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
10 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
11 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
12 external clearmark
: opaque
-> unit = "ml_clearmark";;
13 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
14 external getmaxw
: unit -> float = "ml_getmaxw";;
15 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
16 external measurestr
: int -> string -> float = "ml_measure_string";;
17 external postprocess
: opaque
-> int -> int -> int -> (int * string * int)
18 -> int = "ml_postprocess";;
19 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
20 external setaalevel
: int -> unit = "ml_setaalevel";;
21 external realloctexts
: int -> bool = "ml_realloctexts";;
22 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
23 external getlink
: opaque
-> int -> under
= "ml_getlink";;
24 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
25 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
26 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
27 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
28 external freepbo
: opaque
-> unit = "ml_freepbo";;
29 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
30 external bousable
: unit -> bool = "ml_bo_usable";;
31 external unproject
: opaque
-> int -> int
32 -> (int * int) option = "ml_unproject";;
33 external project
: opaque
-> int -> int -> float -> float
34 -> (float * float) = "ml_project";;
35 external drawtile
: tileparams
-> opaque
36 -> unit = "ml_drawtile";;
37 external rectofblock
: opaque
-> int -> int
38 -> float array
option = "ml_rectofblock";;
39 external begintiles
: unit -> unit = "ml_begintiles";;
40 external endtiles
: unit -> unit = "ml_endtiles";;
41 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
42 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
43 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
44 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
45 external savedoc
: string -> unit = "ml_savedoc";;
46 external getannotcontents
: opaque
-> slinkindex
47 -> string = "ml_getannotcontents";;
48 external drawprect
: opaque
-> int -> int -> float array
49 -> unit = "ml_drawprect";;
50 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
51 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
52 external uritolocation
: string
53 -> (pageno
* float * float) = "ml_uritolocation";;
54 external isexternallink
: string -> bool = "ml_isexternallink";;
56 (* copysel _will_ close the supplied descriptor *)
57 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
59 let selfexec = ref E.s
;;
60 let ignoredoctitlte = ref false;;
61 let opengl_has_pbo = ref false;;
63 let drawstring size x y s
=
65 Gl.enable `texture_2d
;
66 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
67 ignore
(drawstr size x y s
);
69 Gl.disable `texture_2d
;
72 let drawstring1 size x y s
=
76 let drawstring2 size x y fmt
=
77 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
80 module UniSyms
= struct
81 let ellipsis = "\xe2\x80\xa6";;
82 let radical = "\xe2\x88\x9a";;
83 let lguillemet = "\xc2\xab";;
84 let rguillemet = "\xc2\xbb";;
99 l
.pagedispx l
.pagedispy
103 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
109 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
112 let isbirdseye = function
114 | Textentry _
| View
| LinkNav _
-> false
117 let istextentry = function
118 | Textentry _
-> true
119 | Birdseye _
| View
| LinkNav _
-> false
122 let wtmode = ref false;;
123 let cxack = ref false;;
125 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
128 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
129 && (state
.w
> state
.winw
))
135 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
136 && (state
.maxy
> state
.winh
))
144 else x
> state
.winw
- vscrollw ()
148 fstate
.fontsize
<- n
;
149 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
150 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
156 else Printf.kprintf ignore fmt
160 if emptystr conf
.pathlauncher
161 then dolog
"%s" state
.path
163 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
164 match spawn
command [] with
167 dolog
"failed to execute `%s': %s" command @@ exntos exn
173 let postRedisplay who
=
174 vlog "redisplay for [%S]" who
;
175 state
.redisplay
<- true;
179 let getopaque pageno
=
180 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
181 with Not_found
-> None
184 let pagetranslatepoint l x y
=
185 let dy = y
- l
.pagedispy
in
186 let y = dy + l
.pagey
in
187 let dx = x
- l
.pagedispx
in
188 let x = dx + l
.pagex
in
192 let onppundermouse g
x y d
=
195 begin match getopaque l
.pageno
with
197 let x0 = l
.pagedispx
in
198 let x1 = x0 + l
.pagevw
in
199 let y0 = l
.pagedispy
in
200 let y1 = y0 + l
.pagevh
in
201 if y >= y0 && y <= y1 && x >= x0 && x <= x1
203 let px, py
= pagetranslatepoint l
x y in
204 match g opaque l
px py
with
217 let g opaque l
px py
=
220 match rectofblock opaque
px py
with
221 | Some
[|x0;x1;y0;y1|] ->
222 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
223 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
224 state
.rects
<- [l
.pageno
, color, rect];
225 G.postRedisplay "getunder";
228 let under = whatsunder opaque
px py
in
229 if under = Unone
then None
else Some
under
231 onppundermouse g x y Unone
236 match unproject opaque
x y with
237 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
240 onppundermouse g x y None
;
244 state
.text
<- Printf.sprintf
"%c%s" c s
;
245 G.postRedisplay "showtext";
249 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
252 let pipef ?
(closew
=true) cap
f cmd
=
253 match Unix.pipe
() with
254 | exception exn
-> dolog
"%s cannot create pipe: %S" cap
@@ exntos exn
256 begin match spawn cmd
[r
, 0; w
, -1] with
257 | exception exn
-> dolog
"%s: cannot execute %S: %s" cap cmd
@@ exntos exn
260 Ne.clo r
(dolog
"%s failed to close r: %s" cap
);
261 if closew
then Ne.clo w
(dolog
"%s failed to close w: %s" cap
);
264 let pipesel opaque cmd
=
266 then pipef ~closew
:false "pipesel"
269 G.postRedisplay "pipesel"
274 let g opaque l
px py
=
275 if markunder opaque
px py conf
.paxmark
278 match getopaque l
.pageno
with
280 | Some opaque
-> pipesel opaque conf
.paxcmd
285 G.postRedisplay "paxunder";
286 if conf
.paxmark
= Mark_page
289 match getopaque l
.pageno
with
291 | Some opaque
-> clearmark opaque
) state
.layout
;
292 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
297 "selstring" (fun w
->
299 let l = String.length s
in
300 let bytes = Bytes.unsafe_of_string s
in
301 let n = tempfailureretry
(Unix.write w
bytes 0) l in
303 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n;
304 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
308 let undertext = function
311 | Utext s
-> "font: " ^ s
312 | Uannotation
(opaque
, slinkindex
) ->
313 "annotation: " ^ getannotcontents opaque slinkindex
316 let updateunder x y =
317 match getunder x y with
318 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
320 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
321 Wsi.setcursor
Wsi.CURSOR_INFO
323 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
324 Wsi.setcursor
Wsi.CURSOR_TEXT
326 if conf
.underinfo
then showtext 'a'
"nnotation";
327 Wsi.setcursor
Wsi.CURSOR_INFO
330 let showlinktype under =
331 if conf
.underinfo
&& under != Unone
332 then showtext ' '
@@ undertext under
335 let [@warning
"-4"] intentry_with_suffix text key
=
338 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
339 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
340 addchar
text @@ asciilower c
342 state
.text <- Printf.sprintf
"invalid key";
349 let b = Buffer.create
16 in
352 let b = Buffer.to_bytes
b in
353 wcmd state
.ss
b @@ Bytes.length
b
357 let nogeomcmds cmds
=
359 | s
, [] -> emptystr s
363 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
364 let rec fold accu
n =
365 if n = Array.length
b
368 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
371 || n = state
.pagecount
- coverB
372 || (n - coverA
) mod columns
= columns
- 1)
378 let pagey = max
0 (y - vy
) in
379 let pagedispy = if pagey > 0 then 0 else vy
- y in
380 let pagedispx, pagex
=
382 if n = coverA
- 1 || n = state
.pagecount
- coverB
383 then x + (sw
- w
) / 2
391 let vw = sw
- pagedispx in
392 let pw = w
- pagex
in
395 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
396 if pagevw > 0 && pagevh > 0
407 ; pagedispx = pagedispx
408 ; pagedispy = pagedispy
420 if Array.length
b = 0
422 else List.rev
(fold [] (page_of_y
y))
425 let layoutS (columns
, b) x y sw sh
=
426 let rec fold accu n =
427 if n = Array.length
b
430 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
438 let pagey = max
0 (y - vy
) in
439 let pagedispy = if pagey > 0 then 0 else vy
- y in
440 let pagedispx, pagex
=
454 let pagecolw = pagew
/columns
in
457 then pagedispx + ((sw
- pagecolw) / 2)
461 let vw = sw
- pagedispx in
462 let pw = pagew
- pagex
in
465 let pagevw = min
pagevw pagecolw in
466 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
467 if pagevw > 0 && pagevh > 0
478 ; pagedispx = pagedispx
479 ; pagedispy = pagedispy
480 ; pagecol
= n mod columns
494 let layout x y sw sh
=
495 if nogeomcmds state
.geomcmds
497 match conf
.columns
with
498 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
499 | Cmulti c
-> layoutN c
x y sw sh
500 | Csplit s
-> layoutS s
x y sw sh
504 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
506 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
509 let tilex = l.pagex
mod conf
.tilew
in
510 let tiley = l.pagey mod conf
.tileh
in
512 let col = l.pagex
/ conf
.tilew
in
513 let row = l.pagey / conf
.tileh
in
515 let rec rowloop row y0 dispy h
=
519 let dh = conf
.tileh
- y0 in
521 let rec colloop col x0 dispx w
=
525 let dw = conf
.tilew
- x0 in
527 f col row dispx dispy
x0 y0 dw dh;
528 colloop (col+1) 0 (dispx
+dw) (w
-dw)
531 colloop col tilex l.pagedispx l.pagevw;
532 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
535 if l.pagevw > 0 && l.pagevh > 0
536 then rowloop row tiley l.pagedispy l.pagevh;
539 let gettileopaque l col row =
541 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
543 try Some
(Hashtbl.find state
.tilemap
key)
544 with Not_found
-> None
547 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
548 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
549 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
552 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
553 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
554 GlArray.vertex `two state
.vraw
;
555 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
558 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
560 let filledrect x0 y0 x1 y1 =
561 GlArray.disable `texture_coord
;
562 filledrect1 x0 y0 x1 y1;
563 GlArray.enable `texture_coord
;
566 let linerect x0 y0 x1 y1 =
567 GlArray.disable `texture_coord
;
568 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
569 GlArray.vertex `two state
.vraw
;
570 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
571 GlArray.enable `texture_coord
;
574 let drawtiles l color =
577 let f col row x y tilex tiley w h
=
578 match gettileopaque l col row with
579 | Some
(opaque
, _
, t
) ->
580 let params = x, y, w
, h
, tilex, tiley in
582 then GlTex.env
(`mode `blend
);
583 drawtile
params opaque
;
585 then GlTex.env
(`mode `modulate
);
589 let s = Printf.sprintf
593 let w = measurestr fstate
.fontsize
s in
594 GlDraw.color (0.0, 0.0, 0.0);
595 filledrect (float (x-2))
598 (float (y + fstate
.fontsize
+ 2));
600 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
607 let lw = state
.winw
- x in
610 let lh = state
.winh
- y in
614 then GlTex.env
(`mode `blend
);
615 begin match state
.checkerstexid
with
617 Gl.enable `texture_2d
;
618 GlTex.bind_texture ~target
:`texture_2d id
;
622 and y1 = float (y+h
) in
624 let tw = float w /. 16.0
625 and th
= float h
/. 16.0 in
626 let tx0 = float tilex /. 16.0
627 and ty0
= float tiley /. 16.0 in
629 and ty1
= ty0
+. th
in
630 Raw.sets_float state
.vraw ~pos
:0
631 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
632 Raw.sets_float state
.traw ~pos
:0
633 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
634 GlArray.vertex `two state
.vraw
;
635 GlArray.tex_coord `two state
.traw
;
636 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
637 Gl.disable `texture_2d
;
640 GlDraw.color (1.0, 1.0, 1.0);
641 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
644 then GlTex.env
(`mode `modulate
);
645 if w > 128 && h
> fstate
.fontsize
+ 10
647 let c = if conf
.invert
then 1.0 else 0.0 in
648 GlDraw.color (c, c, c);
651 then (col*conf
.tilew
, row*conf
.tileh
)
654 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
663 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
665 let tilevisible1 l x y =
667 and ax1
= l.pagex
+ l.pagevw
669 and ay1
= l.pagey + l.pagevh in
673 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
674 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
676 let rx0 = max
ax0 bx0
677 and ry0
= max ay0 by0
678 and rx1
= min ax1
bx1
679 and ry1
= min ay1 by1
in
681 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
685 let tilevisible layout n x y =
686 let rec findpageinlayout m
= function
687 | l :: rest
when l.pageno
= n ->
688 tilevisible1 l x y || (
689 match conf
.columns
with
690 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
691 | Csplit _
| Csingle _
| Cmulti _
-> false
693 | _
:: rest
-> findpageinlayout 0 rest
696 findpageinlayout 0 layout;
699 let tileready l x y =
700 tilevisible1 l x y &&
701 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
704 let tilepage n p
layout =
705 let rec loop = function
709 let f col row _ _ _ _ _ _
=
710 if state
.currently
= Idle
712 match gettileopaque l col row with
715 let x = col*conf
.tilew
716 and y = row*conf
.tileh
in
718 let w = l.pagew
- x in
722 let h = l.pageh
- y in
727 then getpbo
w h conf
.colorspace
730 wcmd "tile %s %d %d %d %d %s"
731 (~
> p
) x y w h (~
> pbo);
734 l, p
, conf
.colorspace
, conf
.angle
,
735 state
.gen
, col, row, conf
.tilew
, conf
.tileh
744 if nogeomcmds state
.geomcmds
748 let preloadlayout x y sw sh
=
749 let y = if y < sh
then 0 else y - sh
in
750 let x = min
0 (x + sw
) in
758 if state
.currently
!= Idle
763 begin match getopaque l.pageno
with
765 wcmd "page %d %d" l.pageno
l.pagedimno
;
766 state
.currently
<- Loading
(l, state
.gen
);
768 tilepage l.pageno opaque pages
;
773 if nogeomcmds state
.geomcmds
779 if conf
.preload && state
.currently
= Idle
780 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
783 let layoutready layout =
784 let rec fold all ls
=
787 let seen = ref false in
788 let allvisible = ref true in
789 let foo col row _ _ _ _ _ _
=
791 allvisible := !allvisible &&
792 begin match gettileopaque l col row with
798 fold (!seen && !allvisible) rest
801 let alltilesvisible = fold true layout in
806 let y = bound
y 0 state
.maxy in
807 let y, layout, proceed
=
808 match conf
.maxwait
with
809 | Some time
when state
.ghyll
== noghyll
->
810 begin match state
.throttle
with
812 let layout = layout x y state
.winw state
.winh
in
813 let ready = layoutready layout in
817 state
.throttle
<- Some
(layout, y, now
());
819 else G.postRedisplay "gotoxy showall (None)";
821 | Some
(_
, _
, started
) ->
822 let dt = now
() -. started
in
825 state
.throttle
<- None
;
826 let layout = layout x y state
.winw state
.winh
in
828 G.postRedisplay "maxwait";
835 let layout = layout x y state
.winw state
.winh
in
836 if not
!wtmode || layoutready layout
837 then G.postRedisplay "gotoxy ready";
844 state
.layout <- layout;
845 begin match state
.mode
with
848 | Ltexact
(pageno
, linkno
) ->
849 let rec loop = function
851 state
.lnava
<- Some
(pageno
, linkno
);
852 state
.mode
<- LinkNav
(Ltgendir
0)
853 | l :: _
when l.pageno
= pageno
->
854 begin match getopaque pageno
with
855 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
857 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
858 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
859 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
860 then state
.mode
<- LinkNav
(Ltgendir
0)
862 | _
:: rest
-> loop rest
865 | Ltnotready _
| Ltgendir _
-> ()
867 | Birdseye _
| Textentry _
| View
-> ()
869 begin match state
.mode
with
870 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
871 if not
(pagevisible layout pageno
)
873 match state
.layout with
876 state
.mode
<- Birdseye
(
877 conf
, leftx
, l.pageno
, hooverpageno
, anchor
882 | Ltnotready
(_
, dir
)
885 let rec loop = function
888 match getopaque l.pageno
with
889 | None
-> Ltnotready
(l.pageno
, dir
)
894 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
896 if dir
> 0 then LDfirst
else LDlast
902 | Lnotfound
-> loop rest
904 showlinktype (getlink opaque
n);
905 Ltexact
(l.pageno
, n)
909 state
.mode
<- LinkNav
linknav
912 | Textentry _
| View
-> ()
916 state
.ghyll
<- noghyll
;
919 let mx, my
= state
.mpos
in
924 let conttiling pageno opaque
=
925 tilepage pageno opaque
927 then preloadlayout state
.x state
.y state
.winw state
.winh
931 let gotoxy_and_clear_text x y =
932 if not conf
.verbose
then state
.text <- E.s;
936 let getanchory (n, top
, dtop
) =
937 let y, h = getpageyh
n in
940 let ips = calcips
h in
941 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
943 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
946 let gotoanchor anchor
=
947 gotoxy state
.x (getanchory anchor
);
951 getanchor
() |> cbput state
.hists
.nav
;
955 getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;
959 let anchor = cbgetc state
.hists
.nav dir
in
963 let gotoghyll1 single
y =
965 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
967 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
969 then s (float f /. float a
)
972 then 1.0 -. s ((float (f-b) /. float (n-b)))
978 let ins = float a
*. 0.5
979 and outs
= float (n-b) *. 0.5 in
981 ins +. outs
+. float ones
983 let rec set nab
y sy
=
984 let (_N
, _A
, _B
), y =
987 let scl = if y > sy
then 2 else -2 in
988 let _N, _
, _
= nab
in
989 (_N,0,_N), y+conf
.scrollstep
*scl
991 let sum = summa
_N _A _B
in
992 let dy = float (y - sy
) in
996 then state
.ghyll
<- noghyll
999 let s = scroll n _N _A _B
in
1000 let y1 = y1 +. ((s *. dy) /. sum) in
1001 gotoxy_and_clear_text state
.x (truncate
y1);
1002 state
.ghyll
<- gf (n+1) y1;
1006 | Some
y'
when single
-> set nab
y' state
.y
1007 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1009 gf 0 (float state
.y)
1012 match conf
.ghyllscroll
with
1013 | Some nab
when not conf
.presentation
->
1014 if state
.ghyll
== noghyll
1015 then set nab
y state
.y
1016 else state
.ghyll
(Some
y)
1018 gotoxy_and_clear_text state
.x y
1021 let gotoghyll = gotoghyll1 false;;
1023 let gotopage n top
=
1024 let y, h = getpageyh
n in
1025 let y = y + (truncate
(top
*. float h)) in
1029 let gotopage1 n top
=
1030 let y = getpagey
n in
1035 let invalidate ?
(redisplay
=false) s f =
1036 state
.redisplay
<- redisplay
;
1041 match state
.geomcmds
with
1042 | ps
, [] when emptystr ps
->
1044 state
.geomcmds
<- s, [];
1047 state
.geomcmds
<- ps
, [s, f];
1049 | ps
, (s'
, _
) :: rest
when s'
= s ->
1050 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1053 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1057 Hashtbl.iter
(fun _ opaque
->
1058 wcmd "freepage %s" (~
> opaque
);
1060 Hashtbl.clear state
.pagemap
;
1064 if not
(Queue.is_empty state
.tilelru
)
1066 Queue.iter
(fun (k
, p
, s) ->
1067 wcmd "freetile %s" (~
> p
);
1068 state
.memused
<- state
.memused
- s;
1069 Hashtbl.remove state
.tilemap k
;
1071 state
.uioh#infochanged Memused
;
1072 Queue.clear state
.tilelru
;
1078 let h = truncate
(float h*.conf
.zoom
) in
1079 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1083 let opendoc path password
=
1085 state
.password
<- password
;
1086 state
.gen
<- state
.gen
+ 1;
1087 state
.docinfo
<- [];
1088 state
.outlines
<- [||];
1091 setaalevel conf
.aalevel
;
1093 if emptystr state
.origin
1097 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1098 wcmd "open %d %d %d %s\000%s\000%s\000"
1099 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1100 path password conf
.css
;
1101 invalidate "reqlayout"
1103 wcmd "reqlayout %d %d %d %s\000"
1104 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1105 (stateh state
.winh
) state
.nameddest
1108 let sl = keystostrlist conf
in
1110 function | [] -> accu
1111 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1112 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1116 state
.anchor <- getanchor
();
1117 opendoc state
.path state
.password
;
1121 let c = c *. conf
.colorscale
in
1125 let scalecolor2 (r
, g, b) =
1126 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1129 let docolumns columns
=
1132 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1133 let rec loop pageno
pdimno pdim
y ph pdims
=
1134 if pageno
= state
.pagecount
1137 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1139 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1140 pdimno+1, pdim
, rest
1144 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1146 y + (if conf
.presentation
1147 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1148 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1151 a.(pageno
) <- (pdimno, x, y, pdim
);
1152 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1154 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1155 conf
.columns
<- Csingle
a;
1157 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1158 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1159 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1161 if m
= pageno
then () else
1162 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1165 let y = y + (rowh
- h) / 2 in
1166 a.(m
) <- (pdimno, x, y, pdim
);
1170 if pageno
= state
.pagecount
1171 then fixrow (((pageno
- 1) / columns
) * columns
)
1173 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1175 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1176 pdimno+1, pdim
, rest
1181 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1183 let x = (state
.winw
- w) / 2 in
1185 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1186 x, y + ips + rowh
, h
1189 if (pageno
- coverA
) mod columns
= 0
1191 let x = max
0 (state
.winw
- state
.w) / 2 in
1193 if conf
.presentation
1195 let ips = calcips
h in
1196 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1198 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1202 else x, y, max rowh
h
1206 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1209 if pageno
= columns
&& conf
.presentation
1211 let ips = calcips rowh
in
1212 for i
= 0 to pred columns
1214 let (pdimno, x, y, pdim
) = a.(i
) in
1215 a.(i
) <- (pdimno, x, y+ips, pdim
)
1221 fixrow (pageno
- columns
);
1226 a.(pageno
) <- (pdimno, x, y, pdim
);
1227 let x = x + w + xoff
*2 + conf
.interpagespace
in
1228 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1230 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1231 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1234 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1235 let rec loop pageno
pdimno pdim
y pdims
=
1236 if pageno
= state
.pagecount
1239 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1241 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1242 pdimno+1, pdim
, rest
1247 let rec loop1 n x y =
1248 if n = c then y else (
1249 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1250 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1253 let y = loop1 0 0 y in
1254 loop (pageno
+1) pdimno pdim
y pdims
1256 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1257 conf
.columns
<- Csplit
(c, a);
1261 docolumns conf
.columns
;
1262 state
.maxy <- calcheight
();
1263 if state
.reprf
== noreprf
1265 match state
.mode
with
1266 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1267 let y, h = getpageyh pageno
in
1268 let top = (state
.winh
- h) / 2 in
1269 gotoxy state
.x (max
0 (y - top))
1270 | Textentry _
| View
| LinkNav _
->
1271 let y = getanchory state
.anchor in
1272 let y = min
y (state
.maxy - state
.winh
) in
1277 state
.reprf
<- noreprf
;
1281 let reshape ?
(firsttime
=false) w h =
1282 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1283 if not firsttime
&& nogeomcmds state
.geomcmds
1284 then state
.anchor <- getanchor
();
1287 let w = truncate
(float w *. conf
.zoom
) in
1290 setfontsize fstate
.fontsize
;
1291 GlMat.mode `modelview
;
1292 GlMat.load_identity
();
1294 GlMat.mode `projection
;
1295 GlMat.load_identity
();
1296 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1297 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1298 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1303 else float state
.x /. float state
.w
1305 invalidate ~redisplay
:true "geometry"
1309 then state
.x <- truncate
(relx *. float w);
1311 match conf
.columns
with
1313 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1314 | Csplit
(c, _
) -> w * c
1316 wcmd "geometry %d %d %d"
1317 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1322 let len = String.length state
.text in
1323 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1326 match state
.mode
with
1327 | Textentry _
| View
| LinkNav _
->
1328 let h, _
, _
= state
.uioh#scrollpw
in
1334 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1335 (x+.w) (float (state
.winh
- hscrollh))
1338 let w = float (state
.winw
- 1 - vscrollw ()) in
1339 if state
.progress
>= 0.0 && state
.progress
< 1.0
1341 GlDraw.color (0.3, 0.3, 0.3);
1342 let w1 = w *. state
.progress
in
1344 GlDraw.color (0.0, 0.0, 0.0);
1345 rect (float x0+.w1) (float x0+.w-.w1)
1348 GlDraw.color (0.0, 0.0, 0.0);
1352 GlDraw.color (1.0, 1.0, 1.0);
1355 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1356 (state
.winh
- hscrollh - 5) s;
1359 match state
.mode
with
1360 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1363 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1364 else Printf.sprintf
"%s%s_" prefix
text
1368 | Birdseye _
| View
| LinkNav _
-> state
.text
1373 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1375 let s1 = "(press 'e' to review error messasges)" in
1376 if nonemptystr
s then s ^
" " ^
s1 else s1
1386 let len = Queue.length state
.tilelru
in
1388 match state
.throttle
with
1391 then preloadlayout state
.x state
.y state
.winw state
.winh
1393 | Some
(layout, _
, _
) ->
1397 if state
.memused
> conf
.memlimit
1401 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1402 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1403 let (_
, pw, ph
, _
) = getpagedim
n in
1405 && colorspace
= conf
.colorspace
1406 && angle
= conf
.angle
1410 let x = col*conf
.tilew
1411 and y = row*conf
.tileh
in
1412 tilevisible (Lazy.force_val
layout) n x y
1414 then Queue.push lruitem state
.tilelru
1417 wcmd "freetile %s" (~
> p
);
1418 state
.memused
<- state
.memused
- s;
1419 state
.uioh#infochanged Memused
;
1420 Hashtbl.remove state
.tilemap k
;
1428 let onpagerect pageno
f =
1430 match conf
.columns
with
1431 | Cmulti
(_
, b) -> b
1433 | Csplit
(_
, b) -> b
1435 if pageno
>= 0 && pageno
< Array.length
b
1437 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1441 let gotopagexy1 wtmode pageno
x y =
1442 let _,w1,h1
,leftx
= getpagedim pageno
in
1443 let top = y /. (float h1
) in
1444 let left = x /. (float w1) in
1445 let py, w, h = getpageywh pageno
in
1446 let wh = state
.winh
in
1447 let x = left *. (float w) in
1448 let x = leftx
+ state
.x + truncate
x in
1450 if x < 0 || x >= state
.winw
1454 let pdy = truncate
(top *. float h) in
1455 let y'
= py + pdy in
1456 let dy = y'
- state
.y in
1458 if x != state
.x || not
(dy > 0 && dy < wh)
1460 if conf
.presentation
1462 if abs
(py - y'
) > wh
1469 if state
.x != sx || state
.y != sy
1474 let ww = state
.winw
in
1476 and qy
= pdy / wh in
1478 and y = py + qy
* wh in
1479 let x = if -x + ww > w1 then -(w1-ww) else x
1480 and y'
= if y + wh > state
.maxy then state
.maxy - wh else y in
1482 if conf
.presentation
1484 if abs
(py - y'
) > wh
1493 gotoxy_and_clear_text x y;
1495 else gotoxy_and_clear_text state
.x state
.y;
1498 let gotopagexy wtmode pageno
x y =
1499 match state
.mode
with
1500 | Birdseye
_ -> gotopage pageno
0.0
1501 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1504 let getpassword () =
1505 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1510 impmsg "error getting password: %s" s;
1511 dolog
"%s" s) passcmd;
1514 let pgoto opaque pageno
x y =
1515 let pdimno = getpdimno pageno
in
1516 let x, y = project opaque pageno
pdimno x y in
1517 gotopagexy false pageno
x y;
1521 (* dolog "%S" cmds; *)
1522 let spl = splitatchar cmds ' '
in
1524 try Scanf.sscanf
s fmt
f
1526 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1529 let addoutline outline
=
1530 match state
.currently
with
1531 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1532 | Idle
-> state
.currently
<- Outlining
[outline
]
1533 | Loading
_ | Tiling
_ ->
1534 dolog
"invalid outlining state";
1535 logcurrently state
.currently
1540 state
.uioh#infochanged Pdim
;
1542 | "clearrects", "" ->
1543 state
.rects
<- state
.rects1
;
1544 G.postRedisplay "clearrects";
1546 | "continue", args
->
1547 let n = scan args
"%u" (fun n -> n) in
1548 state
.pagecount
<- n;
1549 begin match state
.currently
with
1551 state
.currently
<- Idle
;
1552 state
.outlines
<- Array.of_list
(List.rev
l)
1553 | Idle
| Loading
_ | Tiling
_ -> ()
1556 let cur, cmds
= state
.geomcmds
in
1558 then failwith
"umpossible";
1560 begin match List.rev cmds
with
1562 state
.geomcmds
<- E.s, [];
1563 state
.throttle
<- None
;
1567 state
.geomcmds
<- s, List.rev rest
;
1569 if conf
.maxwait
= None
&& not
!wtmode
1570 then G.postRedisplay "continue";
1577 then showtext ' ' args
1580 Buffer.add_string state
.errmsgs args
;
1581 state
.newerrmsgs
<- true;
1582 G.postRedisplay "error message"
1584 | "progress", args
->
1585 let progress, text =
1588 f, String.sub args pos
(String.length args
- pos
))
1591 state
.progress <- progress;
1592 G.postRedisplay "progress"
1594 | "firstmatch", args
->
1595 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1596 scan args
"%u %d %f %f %f %f %f %f %f %f"
1597 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1598 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1600 let y = (getpagey
pageno) + truncate
y0 in
1608 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1609 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1612 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1613 scan args
"%u %d %f %f %f %f %f %f %f %f"
1614 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1615 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1617 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1619 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1622 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1623 let pageopaque = ~
< pageopaques in
1624 begin match state
.currently
with
1625 | Loading
(l, gen
) ->
1626 vlog "page %d took %f sec" l.pageno t
;
1627 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1628 begin match state
.throttle
with
1630 let preloadedpages =
1632 then preloadlayout state
.x state
.y state
.winw state
.winh
1637 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1638 IntSet.empty
preloadedpages
1641 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1642 if not
(IntSet.mem
pageno set)
1644 wcmd "freepage %s" (~
> opaque
);
1650 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1653 state
.currently
<- Idle
;
1656 tilepage l.pageno pageopaque state
.layout;
1658 load preloadedpages;
1659 let visible = pagevisible state
.layout l.pageno in
1662 match state
.mode
with
1663 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1664 if pageno = l.pageno
1669 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1671 if dir
> 0 then LDfirst
else LDlast
1674 findlink
pageopaque ld
1679 showlinktype (getlink
pageopaque n);
1680 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1682 | LinkNav
(Ltgendir
_)
1683 | LinkNav
(Ltexact
_)
1689 if visible && layoutready state
.layout
1691 G.postRedisplay "page";
1695 | Some
(layout, _, _) ->
1696 state
.currently
<- Idle
;
1697 tilepage l.pageno pageopaque layout;
1701 | Idle
| Tiling
_ | Outlining
_ ->
1702 dolog
"Inconsistent loading state";
1703 logcurrently state
.currently
;
1708 let (x, y, opaques
, size
, t
) =
1709 scan args
"%u %u %s %u %f"
1710 (fun x y p size t
-> (x, y, p
, size
, t
))
1712 let opaque = ~
< opaques
in
1713 begin match state
.currently
with
1714 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1715 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1718 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1720 wcmd "freetile %s" (~
> opaque);
1721 state
.currently
<- Idle
;
1725 puttileopaque l col row gen cs angle
opaque size t
;
1726 state
.memused
<- state
.memused
+ size
;
1727 state
.uioh#infochanged Memused
;
1729 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1730 opaque, size
) state
.tilelru
;
1733 match state
.throttle
with
1734 | None
-> state
.layout
1735 | Some
(layout, _, _) -> layout
1738 state
.currently
<- Idle
;
1740 && conf
.colorspace
= cs
1741 && conf
.angle
= angle
1742 && tilevisible layout l.pageno x y
1743 then conttiling l.pageno pageopaque;
1745 begin match state
.throttle
with
1747 preload state
.layout;
1749 && conf
.colorspace
= cs
1750 && conf
.angle
= angle
1751 && tilevisible state
.layout l.pageno x y
1752 && (not
!wtmode || layoutready state
.layout)
1753 then G.postRedisplay "tile nothrottle";
1755 | Some
(layout, y, _) ->
1756 let ready = layoutready layout in
1760 state
.layout <- layout;
1761 state
.throttle
<- None
;
1762 G.postRedisplay "throttle";
1768 | Idle
| Loading
_ | Outlining
_ ->
1769 dolog
"Inconsistent tiling state";
1770 logcurrently state
.currently
;
1775 let (n, w, h, _) as pdim
=
1776 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1779 match conf
.fitmodel
with
1781 | FitPage
| FitProportional
->
1782 match conf
.columns
with
1783 | Csplit
_ -> (n, w, h, 0)
1784 | Csingle
_ | Cmulti
_ -> pdim
1786 state
.pdims
<- pdim :: state
.pdims
;
1787 state
.uioh#infochanged Pdim
1790 let (l, n, t
, h, pos
) =
1791 scan args
"%u %u %d %u %n"
1792 (fun l n t
h pos
-> l, n, t
, h, pos
)
1794 let s = String.sub args pos
(String.length args
- pos
) in
1795 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1798 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1799 let s = String.sub args pos
len in
1800 let pos2 = pos
+ len + 1 in
1801 let uri = String.sub args
pos2 (String.length args
- pos2) in
1802 addoutline (s, l, Ouri
uri)
1805 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1806 let s = String.sub args pos
(String.length args
- pos
) in
1807 addoutline (s, l, Onone
)
1811 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1813 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1816 let c, v
= splitatchar args '
\t'
in
1823 if not
!ignoredoctitlte
1824 then Wsi.settitle v
;
1828 if let len = String.length
c in
1829 len > 6 && ((String.sub
c (len-4) 4) = "date")
1831 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1833 let b = Buffer.create
10 in
1834 Printf.bprintf
b "%s\t" c;
1837 Buffer.add_substring
b v p
l;
1838 Buffer.add_char
b c;
1839 with exn
-> Buffer.add_string
b @@ exntos exn
1847 Buffer.add_char
b '
['
;
1848 Buffer.add_string
b v
;
1849 Buffer.add_char
b '
]'
;
1856 state
.docinfo
<- (1, s) :: state
.docinfo
1859 state
.docinfo
<- List.rev state
.docinfo
;
1860 state
.uioh#infochanged Docinfo
1864 then Wsi.settitle
"Wrong password";
1865 let password = getpassword () in
1866 if emptystr
password
1867 then error
"document is password protected"
1868 else opendoc state
.path
password
1871 error
"unknown cmd `%S'" cmds
1876 let action = function
1877 | HCprev
-> cbget cb ~
-1
1878 | HCnext
-> cbget cb
1
1879 | HCfirst
-> cbget cb ~
-(cb
.rc)
1880 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1881 and cancel
() = cb
.rc <- rc
1885 let search pattern forward
=
1886 match conf
.columns
with
1887 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1888 | Csingle
_ | Cmulti
_ ->
1889 if nonemptystr pattern
1892 match state
.layout with
1895 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1897 wcmd "search %d %d %d %d,%s\000"
1898 (btod conf
.icase
) pn py (btod forward
) pattern
;
1901 let [@warning
"-4"] intentry
text key =
1903 if emptystr
text && key = Keys.Ascii '
-'
1904 then addchar
text '
-'
1907 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1909 state
.text <- "invalid key";
1919 let l = String.length
s in
1920 let rec loop pos
n =
1924 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1925 loop (pos
+1) (n*26 + m)
1928 let rec loop n = function
1931 match getopaque l.pageno with
1932 | None
-> loop n rest
1934 let m = getlinkcount
opaque in
1937 let under = getlink
opaque n in
1940 else loop (n-m) rest
1942 loop n state
.layout;
1946 let [@warning
"-4"] linknentry
text = function
1948 let text = addchar
text c in
1949 linknact (fun under -> state
.text <- undertext under) text;
1952 state
.text <- Printf.sprintf
"invalid key";
1956 let [@warning
"-4"] textentry
text = function
1957 | Keys.Ascii
c -> TEcont
(addchar
text c)
1958 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1962 let reqlayout angle fitmodel
=
1963 match state
.throttle
with
1965 if nogeomcmds state
.geomcmds
1966 then state
.anchor <- getanchor
();
1967 conf
.angle
<- angle
mod 360;
1970 match state
.mode
with
1971 | LinkNav
_ -> state
.mode
<- View
1972 | Birdseye
_ | Textentry
_ | View
-> ()
1974 conf
.fitmodel
<- fitmodel
;
1978 wcmd "reqlayout %d %d %d"
1979 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1984 let settrim trimmargins trimfuzz
=
1985 if nogeomcmds state
.geomcmds
1986 then state
.anchor <- getanchor
();
1987 conf
.trimmargins
<- trimmargins
;
1988 conf
.trimfuzz
<- trimfuzz
;
1989 let x0, y0, x1, y1 = trimfuzz
in
1991 "settrim" (fun () ->
1992 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1997 match state
.throttle
with
1999 let zoom = max
0.0001 zoom in
2000 if zoom <> conf
.zoom
2002 state
.prevzoom
<- (conf
.zoom, state
.x);
2004 reshape state
.winw state
.winh
;
2005 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2008 | Some
(layout, y, started
) ->
2010 match conf
.maxwait
with
2014 let dt = now
() -. started
in
2022 let pivotzoom ?
(vw=min state
.w state
.winw
)
2023 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
2024 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2025 let w = float state
.w /. zoom in
2026 let hw = w /. 2.0 in
2027 let ratio = float vh
/. float vw in
2028 let hh = hw *. ratio in
2029 let x0 = float x -. hw
2030 and y0 = float y -. hh in
2031 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2035 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2036 if nogeomcmds state
.geomcmds
2039 then pivotzoom ?
vw ?vh ?
x ?
y zoom
2043 let setcolumns mode columns coverA coverB
=
2044 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2048 then impmsg "split mode doesn't work in bird's eye"
2050 conf
.columns
<- Csplit
(-columns
, E.a);
2058 conf
.columns
<- Csingle
E.a;
2063 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2067 reshape state
.winw state
.winh
;
2070 let resetmstate () =
2071 state
.mstate
<- Mnone
;
2072 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2075 let enterbirdseye () =
2076 let zoom = float conf
.thumbw
/. float state
.winw
in
2077 let birdseyepageno =
2078 let cy = state
.winh
/ 2 in
2082 let rec fold best
= function
2085 let d = cy - (l.pagedispy + l.pagevh/2)
2086 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2087 if abs
d < abs dbest
2096 { conf
with zoom = conf
.zoom },
2097 state
.x, birdseyepageno, -1, getanchor
()
2101 conf
.presentation
<- false;
2102 conf
.interpagespace
<- 10;
2103 conf
.hlinks
<- false;
2104 conf
.fitmodel
<- FitPage
;
2106 conf
.maxwait
<- None
;
2108 match conf
.beyecolumns
with
2111 Cmulti
((c, 0, 0), E.a)
2112 | None
-> Csingle
E.a
2116 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2121 reshape state
.winw state
.winh
;
2124 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2126 conf
.zoom <- c.zoom;
2127 conf
.presentation
<- c.presentation
;
2128 conf
.interpagespace
<- c.interpagespace
;
2129 conf
.maxwait
<- c.maxwait
;
2130 conf
.hlinks
<- c.hlinks
;
2131 conf
.fitmodel
<- c.fitmodel
;
2132 conf
.beyecolumns
<- (
2133 match conf
.columns
with
2134 | Cmulti
((c, _, _), _) -> Some
c
2136 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2139 match c.columns
with
2140 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2141 | Csingle
_ -> Csingle
E.a
2142 | Csplit
(c, _) -> Csplit
(c, E.a)
2146 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2149 reshape state
.winw state
.winh
;
2150 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2154 let togglebirdseye () =
2155 match state
.mode
with
2156 | Birdseye vals
-> leavebirdseye vals
true
2157 | View
-> enterbirdseye ()
2158 | Textentry
_ | LinkNav
_ -> ()
2161 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2162 let pageno = max
0 (pageno - incr
) in
2163 let rec loop = function
2164 | [] -> gotopage1 pageno 0
2165 | l :: _ when l.pageno = pageno ->
2166 if l.pagedispy >= 0 && l.pagey = 0
2167 then G.postRedisplay "upbirdseye"
2168 else gotopage1 pageno 0
2169 | _ :: rest
-> loop rest
2173 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2176 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2177 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2178 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2179 let rec loop = function
2181 let y, h = getpageyh
pageno in
2182 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2183 gotoxy state
.x (clamp dy)
2184 | l :: _ when l.pageno = pageno ->
2185 if l.pagevh != l.pageh
2186 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2187 else G.postRedisplay "downbirdseye"
2188 | _ :: rest
-> loop rest
2194 let [@warning
"-4"] optentry mode
_ key =
2195 let btos b = if b then "on" else "off" in
2199 try conf
.scrollstep
<- int_of_string
s with exn
->
2200 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2202 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2207 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2208 if state
.autoscroll
<> None
2209 then state
.autoscroll
<- Some conf
.autoscrollstep
2211 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2213 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2218 let n, a, b = multicolumns_of_string
s in
2219 setcolumns mode
n a b;
2221 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2223 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2228 let zoom = float (int_of_string
s) /. 100.0 in
2231 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2233 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2238 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2240 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2241 begin match mode
with
2243 leavebirdseye beye
false;
2245 | Textentry
_ | View
| LinkNav
_ -> ();
2248 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2250 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2254 match int_of_string
s with
2255 | angle
-> reqlayout angle conf
.fitmodel
2257 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2259 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2262 conf
.icase
<- not conf
.icase
;
2263 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2266 conf
.preload <- not conf
.preload;
2267 gotoxy state
.x state
.y;
2268 TEdone
("preload " ^
(btos conf
.preload))
2271 conf
.verbose
<- not conf
.verbose
;
2272 TEdone
("verbose " ^
(btos conf
.verbose
))
2275 conf
.debug
<- not conf
.debug
;
2276 TEdone
("debug " ^
(btos conf
.debug
))
2279 conf
.maxhfit
<- not conf
.maxhfit
;
2280 state
.maxy <- calcheight
();
2281 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2284 conf
.crophack
<- not conf
.crophack
;
2285 TEdone
("crophack " ^
btos conf
.crophack
)
2289 match conf
.maxwait
with
2291 conf
.maxwait
<- Some infinity
;
2292 "always wait for page to complete"
2294 conf
.maxwait
<- None
;
2295 "show placeholder if page is not ready"
2300 conf
.underinfo
<- not conf
.underinfo
;
2301 TEdone
("underinfo " ^
btos conf
.underinfo
)
2304 conf
.savebmarks
<- not conf
.savebmarks
;
2305 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2311 match state
.layout with
2316 conf
.interpagespace
<- int_of_string
s;
2317 docolumns conf
.columns
;
2318 state
.maxy <- calcheight
();
2319 let y = getpagey
pageno in
2320 gotoxy state
.x (y + py)
2322 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2324 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2328 match conf
.fitmodel
with
2329 | FitProportional
-> FitWidth
2330 | FitWidth
| FitPage
-> FitProportional
2332 reqlayout conf
.angle
fm;
2333 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2336 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2337 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2340 conf
.invert
<- not conf
.invert
;
2341 TEdone
("invert colors " ^
btos conf
.invert
)
2345 cbput state
.hists
.sel
s;
2348 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2349 textentry
, ondone, true)
2353 then conf
.pax
<- Some
0.0
2354 else conf
.pax
<- None
;
2355 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2358 state
.text <- Printf.sprintf
"bad option %d `%c'"
2366 class type lvsource
=
2368 method getitemcount
: int
2369 method getitem
: int -> (string * int)
2370 method hasaction
: int -> bool
2371 method exit
: uioh
:uioh
->
2377 method getactive
: int
2378 method getfirst
: int
2380 method getminfo
: (int * int) array
2383 class virtual lvsourcebase
= object
2384 val mutable m_active
= 0
2385 val mutable m_first
= 0
2386 val mutable m_pan
= 0
2387 method getactive
= m_active
2388 method getfirst
= m_first
2389 method getpan
= m_pan
2390 method getminfo
: (int * int) array
= E.a
2395 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2398 state
.mode
<- Textentry
(te
, onleave
);
2400 G.postRedisplay "textentrykeyboard enttext";
2402 let histaction cmd
=
2405 | Some
(action, _) ->
2408 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2410 G.postRedisplay "textentry histaction"
2413 let kt = Wsi.kc2kt
key in
2416 if emptystr
text && cancelonempty
2419 G.postRedisplay "textentrykeyboard after cancel";
2422 let s = withoutlastutf8
text in
2423 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2428 G.postRedisplay "textentrykeyboard after confirm"
2430 | Up
-> histaction HCprev
2431 | Down
-> histaction HCnext
2432 | Home
-> histaction HCfirst
2433 | End
-> histaction HClast
2438 begin match opthist
with
2440 | Some
(_, onhistcancel
) -> onhistcancel
()
2444 G.postRedisplay "textentrykeyboard after cancel2"
2447 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2452 | Code
_ | Ascii
_ ->
2453 begin match onkey
text kt with
2457 G.postRedisplay "textentrykeyboard after confirm2";
2460 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2464 G.postRedisplay "textentrykeyboard after cancel3"
2467 state
.mode
<- Textentry
(te
, onleave
);
2468 G.postRedisplay "textentrykeyboard switch";
2470 | _ -> vlog "unhandled key"
2473 let firstof first active
=
2474 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2475 then max
0 (active
- (fstate
.maxrows
/2))
2479 let calcfirst first active
=
2482 let rows = active
- first
in
2483 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2487 let scrollph y maxy =
2488 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2489 let sh = float state
.winh
/. sh in
2490 let sh = max
sh (float conf
.scrollh
) in
2492 let percent = float y /. float maxy in
2493 let position = (float state
.winh
-. sh) *. percent in
2496 if position +. sh > float state
.winh
2497 then float state
.winh
-. sh
2503 let adderrmsg src msg
=
2504 Buffer.add_string state
.errmsgs msg
;
2505 state
.newerrmsgs
<- true;
2509 let adderrfmt src fmt
=
2510 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2513 let coe s = (s :> uioh
);;
2515 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2517 val m_pan
= source#getpan
2518 val m_first
= source#getfirst
2519 val m_active
= source#getactive
2521 val m_prev_uioh
= state
.uioh
2523 method private elemunder
y =
2527 let n = y / (fstate
.fontsize
+1) in
2528 if m_first
+ n < source#getitemcount
2530 if source#hasaction
(m_first
+ n)
2531 then Some
(m_first
+ n)
2538 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2539 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2540 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2541 GlDraw.color (1., 1., 1.);
2542 Gl.enable `texture_2d
;
2543 let fs = fstate
.fontsize
in
2545 let hw = state
.winw
/3 in
2546 let ww = fstate
.wwidth
in
2547 let tabw = 17.0*.ww in
2548 let itemcount = source#getitemcount
in
2549 let minfo = source#getminfo
in
2553 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2555 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2557 if (row - m_first
) > fstate
.maxrows
2560 if row >= 0 && row < itemcount
2562 let (s, level
) = source#getitem
row in
2563 let y = (row - m_first
) * nfs in
2564 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2567 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2571 Gl.disable `texture_2d
;
2572 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2573 GlDraw.color (1., 1., 1.) ~
alpha;
2574 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2575 Gl.enable `texture_2d
;
2578 if zebra
&& row land 1 = 1
2582 GlDraw.color (c,c,c);
2583 let drawtabularstring s =
2585 let x'
= truncate
(x0 +. x) in
2586 let s1, s2
= splitatchar
s '
\000'
in
2588 then drawstring1 fs x'
(y+nfs) s
2594 let s'
= withoutlastutf8
s in
2595 let s = s' ^
UniSyms.ellipsis in
2596 let w = measurestr
fs s in
2597 if float x'
+. w +. ww < float (hw + x'
)
2602 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2606 ignore
(drawstring1 fs x'
(y+nfs) s1);
2607 drawstring1 fs (hw + x'
) (y+nfs) s2
2611 let x = if helpmode
&& row > 0 then x +. ww else x in
2612 let s1, s2
= splitatchar
s '
\t'
in
2615 let nx = drawstr x s1 in
2617 let x = x +. (max
tabw sw) in
2620 let len = String.length
s - 2 in
2621 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2623 let s = String.sub s 2 len in
2624 let x = if not helpmode
then x +. ww else x in
2625 GlDraw.color (1.2, 1.2, 1.2);
2626 let vinc = drawstring1 (fs+fs/4)
2627 (truncate
(x -. ww)) (y+nfs) s in
2628 GlDraw.color (1., 1., 1.);
2629 vinc +. (float fs *. 0.8)
2635 ignore
(drawtabularstring s);
2641 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2644 if (row - m_first
) <= fstate
.maxrows
2646 if row >= 0 && row < itemcount
2648 let (s, level
) = source#getitem
row in
2649 let pos0 = nindex
s '
\000'
in
2650 let y = (row - m_first
) * nfs in
2651 let x = float (level
+ m_pan
) *. ww in
2652 let (first
, last
) = minfo.(row) in
2654 if pos0 > 0 && first
> pos0
2655 then String.sub s (pos0+1) (first
-pos0-1)
2656 else String.sub s 0 first
2658 let suffix = String.sub s first
(last
- first
) in
2659 let w1 = measurestr fstate
.fontsize
prefix in
2660 let w2 = measurestr fstate
.fontsize
suffix in
2661 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2662 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2664 and y0 = float (y+2) in
2666 and y1 = float (y+fs+3) in
2667 filledrect x0 y0 x1 y1;
2671 Gl.disable `texture_2d
;
2672 if Array.length
minfo > 0 then loop m_first
;
2677 method updownlevel incr
=
2678 let len = source#getitemcount
in
2680 if m_active
>= 0 && m_active
< len
2681 then snd
(source#getitem m_active
)
2685 if i
= len then i
-1 else if i
= -1 then 0 else
2686 let _, l = source#getitem i
in
2687 if l != curlevel then i
else flow (i
+incr
)
2689 let active = flow m_active
in
2690 let first = calcfirst m_first
active in
2691 G.postRedisplay "outline updownlevel";
2692 {< m_active
= active; m_first
= first >}
2694 method private key1
key mask
=
2695 let set1 active first qsearch
=
2696 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2698 let search active pattern incr
=
2699 let active = if active = -1 then m_first
else active in
2702 if n >= 0 && n < source#getitemcount
2704 let s, _ = source#getitem
n in
2705 match Str.search_forward re
s 0 with
2706 | exception Not_found
-> loop (n + incr
)
2713 let qpat = Str.quote pattern
in
2714 match Str.regexp_case_fold
qpat with
2717 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2718 qpat @@ Printexc.to_string exn
;
2721 let itemcount = source#getitemcount
in
2722 let find start incr
=
2724 if i
= -1 || i
= itemcount
2727 if source#hasaction i
2729 else find (i
+ incr
)
2734 let set active first =
2735 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2737 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2740 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2742 let incr1 = if incr
> 0 then 1 else -1 in
2743 if isvisible m_first m_active
2746 let next = m_active
+ incr
in
2748 if next < 0 || next >= itemcount
2750 else find next incr1
2752 if abs
(m_active
- next) > fstate
.maxrows
2758 let first = m_first
+ incr
in
2759 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2761 let next = m_active
+ incr
in
2762 let next = bound
next 0 (itemcount - 1) in
2769 if isvisible first next
2776 let first = min
next m_first
in
2778 if abs
(next - first) > fstate
.maxrows
2784 let first = m_first
+ incr
in
2785 let first = bound
first 0 (itemcount - 1) in
2787 let next = m_active
+ incr
in
2788 let next = bound
next 0 (itemcount - 1) in
2789 let next = find next incr1 in
2791 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2793 let active = if m_active
= -1 then next else m_active
in
2798 if isvisible first active
2804 G.postRedisplay "listview navigate";
2808 let kt = Wsi.kc2kt
key in
2809 match [@warning
"-4"] kt with
2810 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2811 let incr = if c = 'r'
then -1 else 1 in
2813 match search (m_active
+ incr) m_qsearch
incr with
2815 state
.text <- m_qsearch ^
" [not found]";
2818 state
.text <- m_qsearch
;
2819 active, firstof m_first
active
2821 G.postRedisplay "listview ctrl-r/s";
2822 set1 active first m_qsearch
;
2824 | Insert
when Wsi.withctrl mask
->
2825 if m_active
>= 0 && m_active
< source#getitemcount
2827 let s, _ = source#getitem m_active
in
2833 if emptystr m_qsearch
2836 let qsearch = withoutlastutf8 m_qsearch
in
2840 G.postRedisplay "listview empty qsearch";
2841 set1 m_active m_first
E.s;
2845 match search m_active
qsearch ~
-1 with
2847 state
.text <- qsearch ^
" [not found]";
2850 state
.text <- qsearch;
2851 active, firstof m_first
active
2853 G.postRedisplay "listview backspace qsearch";
2854 set1 active first qsearch
2857 | Ascii
_ | Code
_ ->
2859 match [@warning
"-8"] kt with
2860 | Ascii
c -> String.make
1 c
2861 | Code code
-> toutf8 code
2863 let pattern = m_qsearch ^
utf8 in
2865 match search m_active
pattern 1 with
2867 state
.text <- pattern ^
" [not found]";
2870 state
.text <- pattern;
2871 active, firstof m_first
active
2873 G.postRedisplay "listview qsearch add";
2874 set1 active first pattern;
2878 if emptystr m_qsearch
2880 G.postRedisplay "list view escape";
2881 let mx, my
= state
.mpos
in
2883 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2884 ~
first:m_first ~pan
:m_pan
with
2885 | None
-> m_prev_uioh
2889 G.postRedisplay "list view kill qsearch";
2890 coe {< m_qsearch
= E.s >}
2895 let self = {< m_qsearch
= E.s >} in
2897 G.postRedisplay "listview enter";
2898 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2899 source#exit ~uioh
:(coe self) ~
cancel
2900 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2902 begin match opt with
2903 | None
-> m_prev_uioh
2910 | Up
-> navigate ~
-1
2911 | Down
-> navigate 1
2912 | Prior
-> navigate ~
-(fstate
.maxrows
)
2913 | Next
-> navigate fstate
.maxrows
2917 G.postRedisplay "listview right";
2918 coe {< m_pan
= m_pan
- 1 >}
2922 G.postRedisplay "listview left";
2923 coe {< m_pan
= m_pan
+ 1 >}
2926 let active = find 0 1 in
2927 G.postRedisplay "listview home";
2931 let first = max
0 (itemcount - fstate
.maxrows
) in
2932 let active = find (itemcount - 1) ~
-1 in
2933 G.postRedisplay "listview end";
2938 method key key mask
=
2939 match state
.mode
with
2941 textentrykeyboard
key mask te
;
2943 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2945 method button button down
x y _ =
2948 | 1 when vscrollhit x ->
2949 G.postRedisplay "listview scroll";
2952 let _, position, sh = self#
scrollph in
2953 if y > truncate
position && y < truncate
(position +. sh)
2955 state
.mstate
<- Mscrolly
;
2959 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2960 let first = truncate
(s *. float source#getitemcount
) in
2961 let first = min source#getitemcount
first in
2962 Some
(coe {< m_first
= first; m_active
= first >})
2964 state
.mstate
<- Mnone
;
2968 begin match self#elemunder
y with
2970 G.postRedisplay "listview click";
2971 source#exit ~uioh
:(coe {< m_active
= n >})
2972 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2976 | n when (n == 4 || n == 5) && not down
->
2977 let len = source#getitemcount
in
2979 if n = 5 && m_first
+ fstate
.maxrows
>= len
2983 let first = m_first
+ (if n == 4 then -1 else 1) in
2984 bound
first 0 (len - 1)
2986 G.postRedisplay "listview wheel";
2987 Some
(coe {< m_first
= first >})
2988 | n when (n = 6 || n = 7) && not down
->
2989 let inc = if n = 7 then -1 else 1 in
2990 G.postRedisplay "listview hwheel";
2991 Some
(coe {< m_pan
= m_pan
+ inc >})
2996 | None
-> m_prev_uioh
2999 method multiclick
_ x y = self#button
1 true x y
3002 match state
.mstate
with
3004 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3005 let first = truncate
(s *. float source#getitemcount
) in
3006 let first = min source#getitemcount
first in
3007 G.postRedisplay "listview motion";
3008 coe {< m_first
= first; m_active
= first >}
3016 method pmotion
x y =
3017 if x < state
.winw
- conf
.scrollbw
3020 match self#elemunder
y with
3021 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3022 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3026 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3031 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3035 method infochanged
_ = ()
3037 method scrollpw
= (0, 0.0, 0.0)
3039 let nfs = fstate
.fontsize
+ 1 in
3040 let y = m_first
* nfs in
3041 let itemcount = source#getitemcount
in
3042 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3043 let maxy = maxi * nfs in
3044 let p, h = scrollph y maxy in
3047 method modehash
= modehash
3048 method eformsgs
= false
3049 method alwaysscrolly
= true
3050 method scroll _ dy =
3052 if dy != 0 then begin
3053 let len = source#getitemcount
in
3055 if dy > 0 && m_first
+ fstate
.maxrows
>= len
3059 let first = m_first
+ dy / 10 in
3060 bound
first 0 (len - 1)
3062 G.postRedisplay "listview wheel";
3063 {< m_first
= first >}
3069 method zoom _ _ _ = ()
3072 class outlinelistview ~zebra ~source
=
3073 let settext autonarrow
s =
3076 let ss = source#statestr
in
3080 else "{" ^
ss ^
"} [" ^
s ^
"]"
3081 else state
.text <- s
3087 ~source
:(source
:> lvsource
)
3089 ~modehash
:(findkeyhash conf
"outline")
3092 val m_autonarrow
= false
3094 method! key key mask
=
3096 if emptystr state
.text
3098 else fstate
.maxrows - 2
3100 let calcfirst first active =
3103 let rows = active - first in
3104 if rows > maxrows then active - maxrows else first
3108 let active = m_active
+ incr in
3109 let active = bound
active 0 (source#getitemcount
- 1) in
3110 let first = calcfirst m_first
active in
3111 G.postRedisplay "outline navigate";
3112 coe {< m_active
= active; m_first
= first >}
3114 let navscroll first =
3116 let dist = m_active
- first in
3122 else first + maxrows
3125 G.postRedisplay "outline navscroll";
3126 coe {< m_first
= first; m_active
= active >}
3128 let ctrl = Wsi.withctrl mask
in
3130 match Wsi.kc2kt
key with
3131 | Ascii '
a'
when ctrl ->
3134 then (source#denarrow
; E.s)
3136 let pattern = source#renarrow
in
3137 if nonemptystr m_qsearch
3138 then (source#narrow m_qsearch
; m_qsearch
)
3142 settext (not m_autonarrow
) text;
3143 G.postRedisplay "toggle auto narrowing";
3144 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3146 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3148 G.postRedisplay "toggle auto narrowing";
3149 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3151 | Ascii '
n'
when ctrl ->
3152 source#narrow m_qsearch
;
3154 then source#add_narrow_pattern m_qsearch
;
3155 G.postRedisplay "outline ctrl-n";
3156 coe {< m_first
= 0; m_active
= 0 >}
3158 | Ascii 'S'
when ctrl ->
3159 let active = source#calcactive
(getanchor
()) in
3160 let first = firstof m_first
active in
3161 G.postRedisplay "outline ctrl-s";
3162 coe {< m_first
= first; m_active
= active >}
3164 | Ascii 'u'
when ctrl ->
3165 G.postRedisplay "outline ctrl-u";
3166 if m_autonarrow
&& nonemptystr m_qsearch
3168 ignore
(source#renarrow
);
3169 settext m_autonarrow
E.s;
3170 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3173 source#del_narrow_pattern
;
3174 let pattern = source#renarrow
in
3176 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3178 settext m_autonarrow
text;
3179 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3182 | Ascii '
l'
when ctrl ->
3183 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3184 G.postRedisplay "outline ctrl-l";
3185 coe {< m_first
= first >}
3187 | Ascii '
\t'
when m_autonarrow
->
3188 if nonemptystr m_qsearch
3190 G.postRedisplay "outline list view tab";
3191 source#add_narrow_pattern m_qsearch
;
3193 coe {< m_qsearch
= E.s >}
3197 | Escape
when m_autonarrow
->
3198 if nonemptystr m_qsearch
3199 then source#add_narrow_pattern m_qsearch
;
3202 | Enter
when m_autonarrow
->
3203 if nonemptystr m_qsearch
3204 then source#add_narrow_pattern m_qsearch
;
3207 | (Ascii
_ | Code
_) when m_autonarrow
->
3208 let pattern = m_qsearch ^ toutf8
key in
3209 G.postRedisplay "outlinelistview autonarrow add";
3210 source#narrow
pattern;
3211 settext true pattern;
3212 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3214 | Backspace
when m_autonarrow
->
3215 if emptystr m_qsearch
3218 let pattern = withoutlastutf8 m_qsearch
in
3219 G.postRedisplay "outlinelistview autonarrow backspace";
3220 ignore
(source#renarrow
);
3221 source#narrow
pattern;
3222 settext true pattern;
3223 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3226 navscroll (max
0 (m_first
- 1))
3229 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3231 | Up
-> navigate ~
-1
3232 | Down
-> navigate 1
3233 | Prior
-> navigate ~
-(fstate
.maxrows)
3234 | Next
-> navigate fstate
.maxrows
3240 G.postRedisplay "outline ctrl right";
3241 {< m_pan
= m_pan
+ 1 >}
3243 else self#updownlevel
1
3251 G.postRedisplay "outline ctrl left";
3252 {< m_pan
= m_pan
- 1 >}
3254 else self#updownlevel ~
-1
3259 G.postRedisplay "outline home";
3260 coe {< m_first
= 0; m_active
= 0 >}
3263 let active = source#getitemcount
- 1 in
3264 let first = max
0 (active - fstate
.maxrows) in
3265 G.postRedisplay "outline end";
3266 coe {< m_active
= active; m_first
= first >}
3268 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
3272 let genhistoutlines () =
3274 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3275 compare c2
.lastvisit c1
.lastvisit
)
3276 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3277 let path = if nonemptystr origin
then origin
else path in
3278 let base = mbtoutf8
@@ Filename.basename
path in
3279 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3283 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3284 Config.save
leavebirdseye;
3285 state
.anchor <- anchor;
3286 state
.bookmarks
<- bookmarks
;
3287 state
.origin
<- origin
;
3290 let x0, y0, x1, y1 = conf
.trimfuzz
in
3291 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3292 reshape ~firsttime
:true state
.winw state
.winh
;
3293 opendoc path origin
;
3297 let makecheckers () =
3298 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3300 converted by Issac Trotts. July 25, 2002 *)
3301 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3302 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3303 let id = GlTex.gen_texture
() in
3304 GlTex.bind_texture ~target
:`texture_2d
id;
3305 GlPix.store
(`unpack_alignment
1);
3306 GlTex.image2d
image;
3307 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3308 [ `mag_filter `nearest
; `min_filter `nearest
];
3312 let setcheckers enabled
=
3313 match state
.checkerstexid
with
3315 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3317 | Some checkerstexid
->
3320 GlTex.delete_texture checkerstexid
;
3321 state
.checkerstexid
<- None
;
3325 let describe_layout layout =
3329 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
3332 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
3334 let sep = if a.pageno+1 = b.pageno then ", " else UniSyms.ellipsis in
3335 Printf.sprintf
"%d%s%d" (a.pageno+1) sep (b.pageno+1)
3337 let rec fold s la lb
= function
3338 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
3339 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
3340 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
3342 fold "Pages" l l rest
3345 let maxy = maxy () in
3348 else 100. *. (float state
.y /. float maxy)
3350 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
3353 let setpresentationmode v
=
3354 let n = page_of_y state
.y in
3355 state
.anchor <- (n, 0.0, 1.0);
3356 conf
.presentation
<- v
;
3357 if conf
.fitmodel
= FitPage
3358 then reqlayout conf
.angle conf
.fitmodel
;
3362 let setbgcol (r
, g, b) =
3364 let r = r *. 255.0 |> truncate
3365 and g = g *. 255.0 |> truncate
3366 and b = b *. 255.0 |> truncate
in
3367 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3369 Wsi.setwinbgcol
col;
3373 let btos b = if b then UniSyms.radical else E.s in
3374 let showextended = ref false in
3375 let showcolors = ref false in
3376 let leave mode
_ = state
.mode
<- mode
in
3379 val mutable m_l
= []
3380 val mutable m_a
= E.a
3381 val mutable m_prev_uioh
= nouioh
3382 val mutable m_prev_mode
= View
3384 inherit lvsourcebase
3386 method reset prev_mode prev_uioh
=
3387 m_a
<- Array.of_list
(List.rev m_l
);
3389 m_prev_mode
<- prev_mode
;
3390 m_prev_uioh
<- prev_uioh
;
3392 method int name get
set =
3398 try set (int_of_string
s)
3400 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3404 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3405 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3409 method int_with_suffix name get
set =
3411 (name
, `intws get
, 1,
3415 try set (int_of_string_with_suffix
s)
3417 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3422 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3424 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3428 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3430 (name
, `
bool (btos, get
), offset
, Action
(
3437 method color name get
set =
3439 (name
, `
color get
, 1,
3442 let invalid = (nan
, nan
, nan
) in
3445 try color_of_string
s
3447 state
.text <- Printf.sprintf
"bad color `%s': %s"
3454 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3455 state
.text <- color_to_string
(get
());
3456 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3460 method string name get
set =
3462 (name
, `
string get
, 1,
3465 let ondone s = set s in
3466 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3467 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3471 method colorspace name get
set =
3473 (name
, `
string get
, 1,
3478 inherit lvsourcebase
3481 m_active
<- CSTE.to_int conf
.colorspace
;
3484 method getitemcount
=
3485 Array.length
CSTE.names
3488 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3489 ignore
(uioh
, first, pan
);
3490 if not
cancel then set active;
3492 method hasaction
_ = true
3496 let modehash = findkeyhash conf
"info" in
3497 coe (new listview ~zebra
:false ~helpmode
:false
3498 ~
source ~trusted
:true ~
modehash)
3501 method paxmark name get
set =
3503 (name
, `
string get
, 1,
3508 inherit lvsourcebase
3511 m_active
<- MTE.to_int conf
.paxmark
;
3514 method getitemcount
= Array.length
MTE.names
3515 method getitem
n = (MTE.names
.(n), 0)
3516 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3517 ignore
(uioh
, first, pan
);
3518 if not
cancel then set active;
3520 method hasaction
_ = true
3524 let modehash = findkeyhash conf
"info" in
3525 coe (new listview ~zebra
:false ~helpmode
:false
3526 ~
source ~trusted
:true ~
modehash)
3529 method fitmodel name get
set =
3531 (name
, `
string get
, 1,
3536 inherit lvsourcebase
3539 m_active
<- FMTE.to_int conf
.fitmodel
;
3542 method getitemcount
= Array.length
FMTE.names
3543 method getitem
n = (FMTE.names
.(n), 0)
3544 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3545 ignore
(uioh
, first, pan
);
3546 if not
cancel then set active;
3548 method hasaction
_ = true
3552 let modehash = findkeyhash conf
"info" in
3553 coe (new listview ~zebra
:false ~helpmode
:false
3554 ~
source ~trusted
:true ~
modehash)
3557 method caption
s offset
=
3558 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3560 method caption2
s f offset
=
3561 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3563 method getitemcount
= Array.length m_a
3566 let tostr = function
3567 | `
int f -> string_of_int
(f ())
3568 | `intws
f -> string_with_suffix_of_int
(f ())
3570 | `
color f -> color_to_string
(f ())
3571 | `
bool (btos, f) -> btos (f ())
3574 let name, t
, offset
, _ = m_a
.(n) in
3575 ((let s = tostr t
in
3577 then Printf.sprintf
"%s\t%s" name s
3581 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3586 match m_a
.(active) with
3587 | _, _, _, Action
f -> f uioh
3588 | _, _, _, Noaction
-> uioh
3599 method hasaction
n =
3601 | _, _, _, Action
_ -> true
3602 | _, _, _, Noaction
-> false
3604 initializer m_active
<- 1
3607 let rec fillsrc prevmode prevuioh
=
3608 let sep () = src#caption
E.s 0 in
3609 let colorp name get
set =
3611 (fun () -> color_to_string
(get
()))
3614 let c = color_of_string
v in
3618 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3621 let rgba name get
set =
3623 (fun () -> rgba_to_string
(get
()))
3626 let c = rgba_of_string
v in
3630 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3633 let oldmode = state
.mode
in
3634 let birdseye = isbirdseye state
.mode
in
3636 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3638 src#
bool "presentation mode"
3639 (fun () -> conf
.presentation
)
3640 (fun v -> setpresentationmode v);
3642 src#
bool "ignore case in searches"
3643 (fun () -> conf
.icase
)
3644 (fun v -> conf
.icase
<- v);
3647 (fun () -> conf
.preload)
3648 (fun v -> conf
.preload <- v);
3650 src#
bool "highlight links"
3651 (fun () -> conf
.hlinks
)
3652 (fun v -> conf
.hlinks
<- v);
3654 src#
bool "under info"
3655 (fun () -> conf
.underinfo
)
3656 (fun v -> conf
.underinfo
<- v);
3658 src#
bool "persistent bookmarks"
3659 (fun () -> conf
.savebmarks
)
3660 (fun v -> conf
.savebmarks
<- v);
3662 src#fitmodel
"fit model"
3663 (fun () -> FMTE.to_string conf
.fitmodel
)
3664 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3666 src#
bool "trim margins"
3667 (fun () -> conf
.trimmargins
)
3668 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3670 src#
bool "persistent location"
3671 (fun () -> conf
.jumpback
)
3672 (fun v -> conf
.jumpback
<- v);
3675 src#
int "inter-page space"
3676 (fun () -> conf
.interpagespace
)
3678 conf
.interpagespace
<- n;
3679 docolumns conf
.columns
;
3681 match state
.layout with
3686 state
.maxy <- calcheight
();
3687 let y = getpagey
pageno in
3688 gotoxy state
.x (y + py)
3692 (fun () -> conf
.pagebias
)
3693 (fun v -> conf
.pagebias
<- v);
3695 src#
int "scroll step"
3696 (fun () -> conf
.scrollstep
)
3697 (fun n -> conf
.scrollstep
<- n);
3699 src#
int "horizontal scroll step"
3700 (fun () -> conf
.hscrollstep
)
3701 (fun v -> conf
.hscrollstep
<- v);
3703 src#
int "auto scroll step"
3705 match state
.autoscroll
with
3707 | _ -> conf
.autoscrollstep
)
3709 let n = boundastep state
.winh
n in
3710 if state
.autoscroll
<> None
3711 then state
.autoscroll
<- Some
n;
3712 conf
.autoscrollstep
<- n);
3715 (fun () -> truncate
(conf
.zoom *. 100.))
3716 (fun v -> pivotzoom ((float v) /. 100.));
3719 (fun () -> conf
.angle
)
3720 (fun v -> reqlayout v conf
.fitmodel
);
3722 src#
int "scroll bar width"
3723 (fun () -> conf
.scrollbw
)
3726 reshape state
.winw state
.winh
;
3729 src#
int "scroll handle height"
3730 (fun () -> conf
.scrollh
)
3731 (fun v -> conf
.scrollh
<- v;);
3733 src#
int "thumbnail width"
3734 (fun () -> conf
.thumbw
)
3736 conf
.thumbw
<- min
4096 v;
3739 leavebirdseye beye
false;
3746 let mode = state
.mode in
3747 src#
string "columns"
3749 match conf
.columns
with
3751 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3752 | Csplit
(count
, _) -> "-" ^ string_of_int count
3755 let n, a, b = multicolumns_of_string
v in
3756 setcolumns mode n a b);
3759 src#caption
"Pixmap cache" 0;
3760 src#int_with_suffix
"size (advisory)"
3761 (fun () -> conf
.memlimit
)
3762 (fun v -> conf
.memlimit
<- v);
3766 Printf.sprintf
"%s bytes, %d tiles"
3767 (string_with_suffix_of_int state
.memused
)
3768 (Hashtbl.length state
.tilemap
)) 1;
3771 src#caption
"Layout" 0;
3772 src#caption2
"Dimension"
3774 Printf.sprintf
"%dx%d (virtual %dx%d)"
3775 state
.winw state
.winh
3780 src#caption2
"Position" (fun () ->
3781 Printf.sprintf
"%dx%d" state
.x state
.y
3784 src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
3787 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3788 "Save these parameters as global defaults at exit"
3789 (fun () -> conf
.bedefault
)
3790 (fun v -> conf
.bedefault
<- v);
3793 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3794 src#
bool ~offset
:0 ~
btos "Extended parameters"
3795 (fun () -> !showextended)
3796 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3800 (fun () -> conf
.checkers
)
3801 (fun v -> conf
.checkers
<- v; setcheckers v);
3802 src#
bool "update cursor"
3803 (fun () -> conf
.updatecurs
)
3804 (fun v -> conf
.updatecurs
<- v);
3805 src#
bool "scroll-bar on the left"
3806 (fun () -> conf
.leftscroll
)
3807 (fun v -> conf
.leftscroll
<- v);
3809 (fun () -> conf
.verbose
)
3810 (fun v -> conf
.verbose
<- v);
3811 src#
bool "invert colors"
3812 (fun () -> conf
.invert
)
3813 (fun v -> conf
.invert
<- v);
3815 (fun () -> conf
.maxhfit
)
3816 (fun v -> conf
.maxhfit
<- v);
3818 (fun () -> conf
.pax
!= None
)
3821 then conf
.pax
<- Some
(now
())
3822 else conf
.pax
<- None
);
3823 src#
string "uri launcher"
3824 (fun () -> conf
.urilauncher
)
3825 (fun v -> conf
.urilauncher
<- v);
3826 src#
string "path launcher"
3827 (fun () -> conf
.pathlauncher
)
3828 (fun v -> conf
.pathlauncher
<- v);
3829 src#
string "tile size"
3830 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3833 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3834 conf
.tilew
<- max
64 w;
3835 conf
.tileh
<- max
64 h;
3838 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3841 src#
int "texture count"
3842 (fun () -> conf
.texcount
)
3845 then conf
.texcount
<- v
3846 else impmsg "failed to set texture count please retry later"
3848 src#
int "slice height"
3849 (fun () -> conf
.sliceheight
)
3851 conf
.sliceheight
<- v;
3852 wcmd "sliceh %d" conf
.sliceheight
;
3854 src#
int "anti-aliasing level"
3855 (fun () -> conf
.aalevel
)
3857 conf
.aalevel
<- bound
v 0 8;
3858 state
.anchor <- getanchor
();
3859 opendoc state
.path state
.password;
3861 src#
string "page scroll scaling factor"
3862 (fun () -> string_of_float conf
.pgscale)
3865 let s = float_of_string
v in
3868 state
.text <- Printf.sprintf
3869 "bad page scroll scaling factor `%s': %s" v
3873 src#
int "ui font size"
3874 (fun () -> fstate
.fontsize
)
3875 (fun v -> setfontsize (bound
v 5 100));
3876 src#
int "hint font size"
3877 (fun () -> conf
.hfsize
)
3878 (fun v -> conf
.hfsize
<- bound
v 5 100);
3879 src#
bool "crop hack"
3880 (fun () -> conf
.crophack
)
3881 (fun v -> conf
.crophack
<- v);
3882 src#
string "trim fuzz"
3883 (fun () -> irect_to_string conf
.trimfuzz
)
3886 conf
.trimfuzz
<- irect_of_string
v;
3888 then settrim true conf
.trimfuzz
;
3890 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3893 src#
string "throttle"
3895 match conf
.maxwait
with
3896 | None
-> "show place holder if page is not ready"
3899 then "wait for page to fully render"
3901 "wait " ^ string_of_float
time
3902 ^
" seconds before showing placeholder"
3906 let f = float_of_string
v in
3908 then conf
.maxwait
<- None
3909 else conf
.maxwait
<- Some
f
3911 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3914 src#
string "ghyll scroll"
3916 match conf
.ghyllscroll
with
3918 | Some nab
-> ghyllscroll_to_string nab
3921 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3924 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3926 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3929 src#
string "selection command"
3930 (fun () -> conf
.selcmd
)
3931 (fun v -> conf
.selcmd
<- v);
3932 src#
string "synctex command"
3933 (fun () -> conf
.stcmd
)
3934 (fun v -> conf
.stcmd
<- v);
3935 src#
string "pax command"
3936 (fun () -> conf
.paxcmd
)
3937 (fun v -> conf
.paxcmd
<- v);
3938 src#
string "ask password command"
3939 (fun () -> conf
.passcmd)
3940 (fun v -> conf
.passcmd <- v);
3941 src#
string "save path command"
3942 (fun () -> conf
.savecmd
)
3943 (fun v -> conf
.savecmd
<- v);
3944 src#colorspace
"color space"
3945 (fun () -> CSTE.to_string conf
.colorspace
)
3947 conf
.colorspace
<- CSTE.of_int
v;
3951 src#paxmark
"pax mark method"
3952 (fun () -> MTE.to_string conf
.paxmark
)
3953 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3954 if bousable
() && !opengl_has_pbo
3957 (fun () -> conf
.usepbo
)
3958 (fun v -> conf
.usepbo
<- v);
3959 src#
bool "mouse wheel scrolls pages"
3960 (fun () -> conf
.wheelbypage
)
3961 (fun v -> conf
.wheelbypage
<- v);
3962 src#
bool "open remote links in a new instance"
3963 (fun () -> conf
.riani
)
3964 (fun v -> conf
.riani
<- v);
3965 src#
bool "edit annotations inline"
3966 (fun () -> conf
.annotinline
)
3967 (fun v -> conf
.annotinline
<- v);
3968 src#
bool "coarse positioning in presentation mode"
3969 (fun () -> conf
.coarseprespos
)
3970 (fun v -> conf
.coarseprespos
<- v);
3971 src#
bool "use document CSS"
3972 (fun () -> conf
.usedoccss
)
3974 conf
.usedoccss
<- v;
3975 state
.anchor <- getanchor
();
3976 opendoc state
.path state
.password;
3978 src#
bool ~
btos "colors"
3979 (fun () -> !showcolors)
3980 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
3983 colorp " background"
3984 (fun () -> conf
.bgcolor
)
3985 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3987 (fun () -> conf
.sbarcolor
)
3988 (fun v -> conf
.sbarcolor
<- v);
3989 rgba " scrollbar handle"
3990 (fun () -> conf
.sbarhndlcolor
)
3991 (fun v -> conf
.sbarhndlcolor
<- v);
3996 src#caption
"Document" 0;
3997 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3998 src#caption2
"Pages"
3999 (fun () -> string_of_int state
.pagecount
) 1;
4000 src#caption2
"Dimensions"
4001 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4002 if nonemptystr conf
.css
4003 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
4007 src#caption
"Trimmed margins" 0;
4008 src#caption2
"Dimensions"
4009 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4013 src#caption
"OpenGL" 0;
4014 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4015 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4018 src#caption
"Location" 0;
4019 if nonemptystr state
.origin
4020 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
4021 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
4023 src#reset prevmode prevuioh
;
4028 let prevmode = state
.mode
4029 and prevuioh
= state
.uioh in
4030 fillsrc prevmode prevuioh
;
4031 let source = (src :> lvsource
) in
4032 let modehash = findkeyhash conf
"info" in
4035 inherit listview ~zebra
:false ~helpmode
:false
4036 ~
source ~trusted
:true ~
modehash as super
4037 val mutable m_prevmemused
= 0
4038 method! infochanged
= function
4040 if m_prevmemused
!= state
.memused
4042 m_prevmemused
<- state
.memused
;
4043 G.postRedisplay "memusedchanged";
4045 | Pdim
-> G.postRedisplay "pdimchanged"
4046 | Docinfo
-> fillsrc prevmode prevuioh
4048 method! key key mask
=
4049 if not
(Wsi.withctrl mask
)
4051 match [@warning
"-4"] Wsi.kc2kt
key with
4052 | Keys.Left
-> coe (self#updownlevel ~
-1)
4053 | Keys.Right
-> coe (self#updownlevel
1)
4054 | _ -> super#
key key mask
4055 else super#
key key mask
4057 G.postRedisplay "info";
4063 inherit lvsourcebase
4064 method getitemcount
= Array.length state
.help
4066 let s, l, _ = state
.help
.(n) in
4069 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4073 match state
.help
.(active) with
4074 | _, _, Action
f -> Some
(f uioh)
4075 | _, _, Noaction
-> Some
uioh
4084 method hasaction
n =
4085 match state
.help
.(n) with
4086 | _, _, Action
_ -> true
4087 | _, _, Noaction
-> false
4093 let modehash = findkeyhash conf
"help" in
4095 state
.uioh <- coe (new listview
4096 ~zebra
:false ~helpmode
:true
4097 ~
source ~trusted
:true ~
modehash);
4098 G.postRedisplay "help";
4104 inherit lvsourcebase
4105 val mutable m_items
= E.a
4107 method getitemcount
= 1 + Array.length m_items
4112 else m_items
.(n-1), 0
4114 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4119 then Buffer.clear state
.errmsgs
;
4126 method hasaction
n =
4130 state
.newerrmsgs
<- false;
4131 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4132 m_items
<- Array.of_list
l
4141 let source = (msgsource :> lvsource
) in
4142 let modehash = findkeyhash conf
"listview" in
4145 inherit listview ~zebra
:false ~helpmode
:false
4146 ~
source ~trusted
:false ~
modehash as super
4149 then msgsource#reset
;
4152 G.postRedisplay "msgs";
4156 let editor = getenvwithdef
"EDITOR" E.s in
4160 let tmppath = Filename.temp_file
"llpp" "note" in
4163 let oc = open_out
tmppath in
4167 let execstr = editor ^
" " ^
tmppath in
4169 match spawn
execstr [] with
4171 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4174 match Unix.waitpid
[] pid
with
4176 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4180 | Unix.WEXITED
0 -> filecontents
tmppath
4182 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4184 | Unix.WSIGNALED
n ->
4185 impmsg "editor process(%s) was killed by signal %d" execstr n;
4187 | Unix.WSTOPPED
n ->
4188 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4191 match Unix.unlink
tmppath with
4193 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4198 let enterannotmode opaque slinkindex
=
4201 inherit lvsourcebase
4202 val mutable m_text
= E.s
4203 val mutable m_items
= E.a
4205 method getitemcount
= Array.length m_items
4208 let label, _func
= m_items
.(n) in
4211 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4212 ignore
(uioh, first, pan
);
4215 let _label, func
= m_items
.(active) in
4220 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4223 let rec split accu b i
=
4225 if p = String.length
s
4226 then (String.sub s b (p-b), unit) :: accu
4228 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4230 let ss = if i
= 0 then E.s else String.sub s b i
in
4231 split ((ss, unit)::accu) (p+1) 0
4236 wcmd "freepage %s" (~
> opaque);
4238 Hashtbl.fold (fun key opaque'
accu ->
4239 if opaque'
= opaque'
4240 then key :: accu else accu) state
.pagemap
[]
4242 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4244 gotoxy state
.x state
.y
4247 delannot
opaque slinkindex
;
4250 let edit inline
() =
4255 modannot
opaque slinkindex
s;
4261 let mode = state
.mode in
4264 ("annotation: ", m_text
, None
, textentry
, update, true),
4265 fun _ -> state
.mode <- mode);
4269 let s = getusertext m_text
in
4274 ( "[Copy]", fun () -> selstring m_text
)
4275 :: ("[Delete]", dele)
4276 :: ("[Edit]", edit conf
.annotinline
)
4278 :: split [] 0 0 |> List.rev
|> Array.of_list
4285 let s = getannotcontents
opaque slinkindex
in
4288 let source = (msgsource :> lvsource
) in
4289 let modehash = findkeyhash conf
"listview" in
4290 state
.uioh <- coe (object
4291 inherit listview ~zebra
:false ~helpmode
:false
4292 ~
source ~trusted
:false ~
modehash
4294 G.postRedisplay "enterannotmode";
4297 let gotoremote spec
=
4298 let filename, dest
= splitatchar spec '#'
in
4299 let getpath filename =
4301 if nonemptystr
filename
4303 if Filename.is_relative
filename
4305 let dir = Filename.dirname state
.path in
4307 if Filename.is_implicit
dir
4308 then Filename.concat
(Sys.getcwd
()) dir
4311 Filename.concat
dir filename
4315 if Sys.file_exists
path
4319 let path = getpath filename in
4323 let cmd = Lazy.force_val lcmd
in
4324 match spawn
cmd with
4326 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4328 let anchor = getanchor
() in
4329 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4330 state
.origin
<- E.s;
4331 state
.ranchors
<- ranchor :: state
.ranchors
;
4334 if substratis spec
0 "page="
4336 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4338 state
.anchor <- (pageno, 0.0, 0.0);
4339 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4341 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4343 state
.nameddest
<- dest
;
4344 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4348 let gotounder = function
4349 | Ulinkuri
s when isexternallink
s ->
4350 if substratis
s 0 "file://"
4351 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4354 let pageno, x, y = uritolocation
s in
4356 gotopagexy !wtmode pageno x y
4357 | Utext
_ | Unone
-> ()
4358 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4361 let gotooutline (_, _, kind
) =
4365 let (pageno, y, _) = anchor in
4367 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4371 | Ouri
uri -> gotounder (Ulinkuri
uri)
4372 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4373 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4374 | Ohistory hist
-> gotohist hist
4375 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4378 class outlinesoucebase fetchoutlines
= object (self)
4379 inherit lvsourcebase
4380 val mutable m_items
= E.a
4381 val mutable m_minfo
= E.a
4382 val mutable m_orig_items
= E.a
4383 val mutable m_orig_minfo
= E.a
4384 val mutable m_narrow_patterns
= []
4385 val mutable m_gen
= -1
4387 method getitemcount
= Array.length m_items
4390 let s, n, _ = m_items
.(n) in
4393 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4394 ignore
(uioh, first);
4396 if m_narrow_patterns
= []
4397 then m_orig_items
, m_orig_minfo
4398 else m_items
, m_minfo
4405 gotooutline m_items
.(active);
4413 method hasaction
(_:int) = true
4416 if Array.length m_items
!= Array.length m_orig_items
4419 match m_narrow_patterns
with
4421 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4423 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4427 match m_narrow_patterns
with
4430 | head
:: _ -> UniSyms.ellipsis ^ head
4432 method narrow
pattern =
4433 match Str.regexp_case_fold
pattern with
4436 let rec loop accu minfo n =
4439 m_items
<- Array.of_list
accu;
4440 m_minfo
<- Array.of_list
minfo;
4443 let (s, _, _) as o = m_items
.(n) in
4445 match Str.search_forward re
s 0 with
4446 | exception Not_found
-> accu, minfo
4447 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4449 loop accu minfo (n-1)
4451 loop [] [] (Array.length m_items
- 1)
4453 method! getminfo
= m_minfo
4456 m_orig_items
<- fetchoutlines
();
4457 m_minfo
<- m_orig_minfo
;
4458 m_items
<- m_orig_items
4460 method add_narrow_pattern
pattern =
4461 m_narrow_patterns
<- pattern :: m_narrow_patterns
4463 method del_narrow_pattern
=
4464 match m_narrow_patterns
with
4465 | _ :: rest
-> m_narrow_patterns
<- rest
4470 match m_narrow_patterns
with
4471 | pattern :: [] -> self#narrow
pattern; pattern
4473 List.fold_left
(fun accu pattern ->
4474 self#narrow
pattern;
4475 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4477 method calcactive
(_:anchor) = 0
4479 method reset
anchor items =
4480 if state
.gen
!= m_gen
4482 m_orig_items
<- items;
4484 m_narrow_patterns
<- [];
4486 m_orig_minfo
<- E.a;
4490 if items != m_orig_items
4492 m_orig_items
<- items;
4493 if m_narrow_patterns
== []
4494 then m_items
<- items;
4497 let active = self#calcactive
anchor in
4499 m_first
<- firstof m_first
active
4503 let outlinesource fetchoutlines
=
4505 inherit outlinesoucebase fetchoutlines
4506 method! calcactive
anchor =
4507 let rely = getanchory anchor in
4508 let rec loop n best bestd
=
4509 if n = Array.length m_items
4512 let _, _, kind
= m_items
.(n) in
4515 let orely = getanchory anchor in
4516 let d = abs
(orely - rely) in
4519 else loop (n+1) best bestd
4520 | Onone
| Oremote
_ | Olaunch
_
4521 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4522 loop (n+1) best bestd
4528 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4529 let mkselector sourcetype
=
4530 let fetchoutlines () =
4531 match sourcetype
with
4532 | `bookmarks
-> Array.of_list state
.bookmarks
4533 | `outlines
-> state
.outlines
4534 | `history
-> genhistoutlines () |> Array.of_list
4537 if sourcetype
= `history
4538 then new outlinesoucebase
fetchoutlines
4539 else outlinesource fetchoutlines
4542 let outlines = fetchoutlines () in
4543 if Array.length
outlines = 0
4544 then showtext ' ' errmsg
4547 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4548 let anchor = getanchor
() in
4549 source#reset
anchor outlines;
4550 state
.text <- source#greetmsg
;
4552 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4553 G.postRedisplay "enter selector";
4557 let mkenter sourcetype errmsg
=
4558 let enter = mkselector sourcetype
in
4559 fun () -> enter errmsg
4561 ( mkenter `
outlines "document has no outline"
4562 , mkenter `bookmarks
"document has no bookmarks (yet)"
4563 , mkenter `history
"history is empty" )
4566 let quickbookmark ?title
() =
4567 match state
.layout with
4574 let tm = localtime
(now
()) in
4576 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4578 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4580 | Some
title -> title
4582 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4585 let setautoscrollspeed step goingdown
=
4586 let incr = max
1 ((abs step
) / 2) in
4587 let incr = if goingdown
then incr else -incr in
4588 let astep = boundastep state
.winh
(step
+ incr) in
4589 state
.autoscroll
<- Some
astep;
4593 match conf
.columns
with
4595 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4598 let panbound x = bound
x (-state
.w) state
.winw
;;
4600 let existsinrow pageno (columns
, coverA
, coverB
) p =
4601 let last = ((pageno - coverA
) mod columns
) + columns
in
4602 let rec any = function
4605 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4609 then (if l.pageno = last then false else any rest
)
4617 match state
.layout with
4619 let pageno = page_of_y state
.y in
4620 gotoghyll (getpagey
(pageno+1))
4622 match conf
.columns
with
4624 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4626 let y = clamp (pgscale state
.winh
) in
4629 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4630 gotoghyll (getpagey
pageno)
4631 | Cmulti
((c, _, _) as cl
, _) ->
4632 if conf
.presentation
4633 && (existsinrow l.pageno cl
4634 (fun l -> l.pageh
> l.pagey + l.pagevh))
4636 let y = clamp (pgscale state
.winh
) in
4639 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4640 gotoghyll (getpagey
pageno)
4642 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4644 let pagey, pageh
= getpageyh
l.pageno in
4645 let pagey = pagey + pageh
* l.pagecol
in
4646 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4647 gotoghyll (pagey + pageh
+ ips)
4651 match state
.layout with
4653 let pageno = page_of_y state
.y in
4654 gotoghyll (getpagey
(pageno-1))
4656 match conf
.columns
with
4658 if conf
.presentation
&& l.pagey != 0
4660 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4662 let pageno = max
0 (l.pageno-1) in
4663 gotoghyll (getpagey
pageno)
4664 | Cmulti
((c, _, coverB
) as cl
, _) ->
4665 if conf
.presentation
&&
4666 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4668 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4671 if l.pageno = state
.pagecount
- coverB
4675 let pageno = max
0 (l.pageno-decr) in
4676 gotoghyll (getpagey
pageno)
4684 let pageno = max
0 (l.pageno-1) in
4685 let pagey, pageh
= getpageyh
pageno in
4688 let pagey, pageh
= getpageyh
l.pageno in
4689 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4695 if emptystr conf
.savecmd
4696 then adderrmsg "savepath-command is empty"
4697 "don't know where to save modified document"
4699 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4703 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
4708 let tmp = path ^
".tmp" in
4710 Unix.rename
tmp path;
4713 let viewkeyboard key mask
=
4715 let mode = state
.mode in
4716 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4719 G.postRedisplay "view:enttext"
4721 let ctrl = Wsi.withctrl mask
in
4723 match Wsi.kc2kt
key with
4724 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
4726 | Ascii 'Q'
-> exit
0
4729 if hasunsavedchanges
()
4733 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4736 match state
.lnava
with
4737 | None
-> LinkNav
(Ltgendir
0)
4738 | Some
pn -> LinkNav
(Ltexact
pn)
4740 gotoxy state
.x state
.y;
4742 else impmsg "keyboard link navigation does not work under rotation"
4744 | Escape
| Ascii 'q'
->
4745 begin match state
.mstate
with
4748 G.postRedisplay "kill rect";
4751 | Mscrolly
| Mscrollx
4754 begin match state
.mode with
4757 | Ltexact pl
-> state
.lnava
<- Some pl
4758 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4761 G.postRedisplay "esc leave linknav"
4762 | Birdseye
_ | Textentry
_ | View
->
4763 match state
.ranchors
with
4765 | (path, password, anchor, origin
) :: rest
->
4766 state
.ranchors
<- rest
;
4767 state
.anchor <- anchor;
4768 state
.origin
<- origin
;
4769 state
.nameddest
<- E.s;
4770 opendoc path password
4776 gotoghyll (getnav ~
-1)
4787 Hashtbl.iter
(fun _ opaque ->
4789 Hashtbl.clear state
.prects
) state
.pagemap
;
4790 G.postRedisplay "dehighlight";
4792 | Ascii
(('
/'
| '?'
) as c) ->
4793 let ondone isforw
s =
4794 cbput state
.hists
.pat
s;
4795 state
.searchpattern
<- s;
4798 let s = String.make
1 c in
4799 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4800 textentry
, ondone (c = '
/'
), true)
4802 | Ascii '
+'
| Ascii '
='
when ctrl ->
4803 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4804 pivotzoom (conf
.zoom +. incr)
4809 try int_of_string
s with exn
->
4811 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4817 state
.text <- "page bias is now " ^ string_of_int
n;
4820 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4822 | Ascii '
-'
when ctrl ->
4823 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4824 pivotzoom (max
0.01 (conf
.zoom -. decr))
4827 let ondone msg
= state
.text <- msg
in
4829 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4830 optentry state
.mode, ondone, true
4833 | Ascii '
0'
when ctrl ->
4835 then gotoxy 0 state
.y
4838 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4840 match conf
.columns
with
4841 | Csingle
_ | Cmulti
_ -> 1
4842 | Csplit
(n, _) -> n
4844 let h = state
.winh
-
4845 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4847 let zoom = zoomforh state
.winw
h 0 cols in
4848 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4851 | Ascii '
3'
when ctrl ->
4853 match conf
.fitmodel
with
4854 | FitWidth
-> FitProportional
4855 | FitProportional
-> FitPage
4856 | FitPage
-> FitWidth
4858 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4859 reqlayout conf
.angle
fm
4861 | Ascii '
4'
when ctrl ->
4862 let zoom = getmaxw
() /. float state
.winw
in
4863 if zoom > 0.0 then setzoom zoom
4868 | Ascii '
9'
when ctrl ->
4871 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
4874 try int_of_string
s with exn
->
4875 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4881 cbput state
.hists
.pag
(string_of_int
n);
4882 gotopage1 (n + conf
.pagebias
- 1) 0;
4885 let [@warning
"-4"] pageentry
text = function
4886 | Keys.Ascii '
g'
-> TEdone
text
4887 | key -> intentry
text key
4889 let text = String.make
1 c in
4890 enttext (":", text, Some
(onhist state
.hists
.pag
),
4891 pageentry
, ondone, true)
4894 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4895 G.postRedisplay "toggle scrollbar";
4898 state
.bzoom
<- not state
.bzoom
;
4900 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4903 conf
.hlinks
<- not conf
.hlinks
;
4904 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4905 G.postRedisplay "toggle highlightlinks";
4908 if conf
.angle
mod 360 = 0
4910 state
.glinks
<- true;
4911 let mode = state
.mode in
4914 (":", E.s, None
, linknentry
, linknact gotounder, false),
4916 state
.glinks
<- false;
4920 G.postRedisplay "view:linkent(F)"
4922 else impmsg "hint mode does not work under rotation"
4925 state
.glinks
<- true;
4926 let mode = state
.mode in
4929 (":", E.s, None
, linknentry
,
4930 linknact (fun under -> selstring (undertext under)), false),
4932 state
.glinks
<- false;
4936 G.postRedisplay "view:linkent"
4939 begin match state
.autoscroll
with
4941 conf
.autoscrollstep
<- step
;
4942 state
.autoscroll
<- None
4944 state
.autoscroll
<- Some conf
.autoscrollstep
;
4945 state
.slideshow
<- state
.slideshow
land lnot
2
4948 | Ascii '
p'
when ctrl ->
4949 launchpath () (* XXX where do error messages go? *)
4952 setpresentationmode (not conf
.presentation
);
4953 showtext ' '
("presentation mode " ^
4954 if conf
.presentation
then "on" else "off");
4957 if List.mem
Wsi.Fullscreen state
.winstate
4958 then Wsi.reshape conf
.cwinw conf
.cwinh
4959 else Wsi.fullscreen
()
4961 | Ascii
('
p'
|'N'
) ->
4962 search state
.searchpattern
false
4964 | Ascii '
n'
| Fn
3 ->
4965 search state
.searchpattern
true
4968 begin match state
.layout with
4971 gotoghyll (getpagey
l.pageno)
4981 showtext ' '
(describe_layout state
.layout);
4984 begin match state
.layout with
4987 Wsi.reshape l.pagew
l.pageh
;
4992 enterbookmarkmode
()
4994 | Ascii '
h'
| Fn
1 ->
5000 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
5005 match state
.layout with
5010 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
5013 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
5017 showtext ' '
"Quick bookmark added";
5020 begin match state
.layout with
5022 let rect = getpdimrect
l.pagedimno
in
5026 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5027 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5029 (truncate
(rect.(1) -. rect.(0)),
5030 truncate
(rect.(3) -. rect.(0)))
5032 let w = truncate
((float w)*.conf
.zoom)
5033 and h = truncate
((float h)*.conf
.zoom) in
5036 state
.anchor <- getanchor
();
5037 Wsi.reshape w (h + conf
.interpagespace
)
5039 G.postRedisplay "z";
5044 | Ascii '
x'
-> state
.roam
()
5046 | Ascii
('
<'
|'
>'
as c) ->
5048 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5050 | Ascii
('
['
|'
]'
as c) ->
5052 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
5053 G.postRedisplay "brightness";
5055 | Ascii '
c'
when state
.mode = View
->
5060 let m = (state
.winw
- state
.w) / 2 in
5061 gotoxy_and_clear_text m state
.y
5065 match state
.prevcolumns
with
5066 | None
-> (1, 0, 0), 1.0
5067 | Some
(columns
, z
) ->
5070 | Csplit
(c, _) -> -c, 0, 0
5071 | Cmulti
((c, a, b), _) -> c, a, b
5072 | Csingle
_ -> 1, 0, 0
5076 setcolumns View
c a b;
5079 | Down
| Up
when ctrl && Wsi.withshift mask
->
5080 let zoom, x = state
.prevzoom
in
5085 begin match state
.autoscroll
with
5087 begin match state
.mode with
5088 | Birdseye beye
-> upbirdseye 1 beye
5089 | Textentry
_ | View
| LinkNav
_ ->
5091 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5093 if not
(Wsi.withshift mask
) && conf
.presentation
5095 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5099 setautoscrollspeed n false
5102 | Ascii 'j'
| Down
->
5103 begin match state
.autoscroll
with
5105 begin match state
.mode with
5106 | Birdseye beye
-> downbirdseye 1 beye
5107 | Textentry
_ | View
| LinkNav
_ ->
5109 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5111 if not
(Wsi.withshift mask
) && conf
.presentation
5113 else gotoghyll1 true (clamp (conf
.scrollstep
))
5117 setautoscrollspeed n true
5120 | Left
| Right
when not
(Wsi.withalt mask
) ->
5126 else conf
.hscrollstep
5129 let pv = Wsi.kc2kt
key in
5130 if pv = Keys.Left
then dx else -dx
5132 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5135 G.postRedisplay "left/right"
5142 match state
.layout with
5144 | l :: _ -> state
.y - l.pagey
5146 clamp (pgscale (-state
.winh
))
5154 match List.rev state
.layout with
5156 | l :: _ -> getpagey
l.pageno
5158 clamp (pgscale state
.winh
)
5162 | Ascii '
g'
| Home
->
5165 | Ascii 'G'
| End
->
5167 gotoghyll (clamp state
.maxy)
5169 | Right
when Wsi.withalt mask
->
5171 gotoghyll (getnav 1)
5172 | Left
when Wsi.withalt mask
->
5174 gotoghyll (getnav ~
-1)
5179 | Ascii '
v'
when conf
.debug
->
5182 match getopaque l.pageno with
5185 let x0, y0, x1, y1 = pagebbox
opaque in
5186 let rect = (float x0, float y0,
5189 float x0, float y1) in
5191 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5192 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5194 G.postRedisplay "v";
5197 let mode = state
.mode in
5198 let cmd = ref E.s in
5199 let onleave = function
5200 | Cancel
-> state
.mode <- mode
5203 match getopaque l.pageno with
5204 | Some
opaque -> pipesel opaque !cmd
5205 | None
-> ()) state
.layout;
5209 cbput state
.hists
.sel
s;
5213 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
5215 G.postRedisplay "|";
5216 state
.mode <- Textentry
(te, onleave);
5218 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
5219 vlog "huh? %s" (Wsi.keyname
key)
5222 let linknavkeyboard key mask
linknav =
5223 let pv = Wsi.kc2kt
key in
5224 let getpage pageno =
5225 let rec loop = function
5227 | l :: _ when l.pageno = pageno -> Some
l
5228 | _ :: rest
-> loop rest
5229 in loop state
.layout
5231 let doexact (pageno, n) =
5232 match getopaque pageno, getpage pageno with
5233 | Some
opaque, Some
l ->
5236 let under = getlink
opaque n in
5237 G.postRedisplay "link gotounder";
5244 | Home
-> Some
(findlink
opaque LDfirst
), -1
5245 | End
-> Some
(findlink
opaque LDlast
), 1
5246 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
5247 | Right
-> Some
(findlink
opaque (LDright
n)), 1
5248 | Up
-> Some
(findlink
opaque (LDup
n)), -1
5249 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
5251 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
5252 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
5255 begin match findpwl
l.pageno dir with
5259 state
.mode <- LinkNav
(Ltgendir
dir);
5260 let y, h = getpageyh
pageno in
5263 then y + h - state
.winh
5268 begin match getopaque pageno, getpage pageno with
5269 | Some
opaque, Some
_ ->
5271 let ld = if dir > 0 then LDfirst
else LDlast
in
5274 begin match link with
5276 showlinktype (getlink
opaque m);
5277 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5278 G.postRedisplay "linknav jpage";
5279 | Lnotfound
-> notfound dir
5285 begin match opt with
5286 | Some Lnotfound
-> pwl l dir;
5287 | Some
(Lfound
m) ->
5291 let _, y0, _, y1 = getlinkrect
opaque m in
5293 then gotopage1 l.pageno y0
5295 let d = fstate
.fontsize
+ 1 in
5296 if y1 - l.pagey > l.pagevh - d
5297 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5298 else G.postRedisplay "linknav";
5300 showlinktype (getlink
opaque m);
5301 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5304 | None
-> viewkeyboard key mask
5306 | _ -> viewkeyboard key mask
5310 begin match linknav with
5311 | Ltexact pa
-> state
.lnava
<- Some pa
5312 | Ltgendir
_ | Ltnotready
_ -> ()
5315 G.postRedisplay "leave linknav"
5319 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5320 | Ltexact exact
-> doexact exact
5323 let keyboard key mask
=
5324 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5325 then wcmd "interrupt"
5326 else state
.uioh <- state
.uioh#
key key mask
5329 let birdseyekeyboard key mask
5330 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5332 match conf
.columns
with
5334 | Cmulti
((c, _, _), _) -> c
5335 | Csplit
_ -> failwith
"bird's eye split mode"
5337 let pgh layout = List.fold_left
5338 (fun m l -> max
l.pageh
m) state
.winh
layout in
5340 match Wsi.kc2kt
key with
5341 | Ascii '
l'
when Wsi.withctrl mask
->
5342 let y, h = getpageyh
pageno in
5343 let top = (state
.winh
- h) / 2 in
5344 gotoxy state
.x (max
0 (y - top))
5345 | Enter
-> leavebirdseye beye
false
5346 | Escape
-> leavebirdseye beye
true
5347 | Up
-> upbirdseye incr beye
5348 | Down
-> downbirdseye incr beye
5349 | Left
-> upbirdseye 1 beye
5350 | Right
-> downbirdseye 1 beye
5353 begin match state
.layout with
5357 state
.mode <- Birdseye
(
5358 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5360 gotopage1 l.pageno 0;
5363 let layout = layout state
.x (state
.y-state
.winh
)
5365 (pgh state
.layout) in
5367 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5369 state
.mode <- Birdseye
(
5370 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5372 gotopage1 l.pageno 0
5375 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5379 begin match List.rev state
.layout with
5381 let layout = layout state
.x
5382 (state
.y + (pgh state
.layout))
5383 state
.winw state
.winh
in
5384 begin match layout with
5386 let incr = l.pageh
- l.pagevh in
5391 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5393 G.postRedisplay "birdseye pagedown";
5395 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5399 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5400 gotopage1 l.pageno 0;
5403 | [] -> gotoxy state
.x (clamp state
.winh
)
5407 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5411 let pageno = state
.pagecount
- 1 in
5412 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5413 if not
(pagevisible state
.layout pageno)
5416 match List.rev state
.pdims
with
5418 | (_, _, h, _) :: _ -> h
5422 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5423 else G.postRedisplay "birdseye end";
5425 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
5430 match state
.mode with
5431 | Textentry
_ -> scalecolor 0.4
5432 | LinkNav
_ | View
-> scalecolor 1.0
5433 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5434 if l.pageno = hooverpageno
5437 if l.pageno = pageno
5439 let c = scalecolor 1.0 in
5441 GlDraw.line_width
3.0;
5442 let dispx = l.pagedispx in
5444 (float (dispx-1)) (float (l.pagedispy-1))
5445 (float (dispx+l.pagevw+1))
5446 (float (l.pagedispy+l.pagevh+1))
5448 GlDraw.line_width
1.0;
5457 let postdrawpage l linkindexbase
=
5458 match getopaque l.pageno with
5460 if tileready l l.pagex
l.pagey
5462 let x = l.pagedispx - l.pagex
5463 and y = l.pagedispy - l.pagey in
5465 match conf
.columns
with
5466 | Csingle
_ | Cmulti
_ ->
5467 (if conf
.hlinks
then 1 else 0)
5469 && not
(isbirdseye state
.mode) then 2 else 0)
5473 match state
.mode with
5474 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5480 Hashtbl.find_all state
.prects
l.pageno |>
5481 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5482 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5484 then (state
.redisplay
<- true; 0)
5490 let scrollindicator () =
5491 let sbw, ph
, sh = state
.uioh#
scrollph in
5492 let sbh, pw, sw = state
.uioh#scrollpw
in
5497 else ((state
.winw
- sbw), state
.winw
, 0)
5501 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5502 let (r, g, b, alpha) = conf
.sbarcolor
in
5503 GlDraw.color (r, g, b) ~
alpha;
5504 filledrect (float x0) 0. (float x1) (float state
.winh
);
5506 (float hx0
) (float (state
.winh
- sbh))
5507 (float (hx0
+ state
.winw
)) (float state
.winh
);
5508 let (r, g, b, alpha) = conf
.sbarhndlcolor
in
5509 GlDraw.color (r, g, b) ~
alpha;
5511 filledrect (float x0) ph
(float x1) (ph
+. sh);
5512 let pw = pw +. float hx0
in
5513 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5518 match state
.mstate
with
5519 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5522 | Msel
((x0, y0), (x1, y1)) ->
5523 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5524 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5525 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5526 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5533 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5534 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5536 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5538 if l.pageno = pageno
5540 let dx = float (l.pagedispx - l.pagex
) in
5541 let dy = float (l.pagedispy - l.pagey) in
5542 let r, g, b, alpha = c in
5543 GlDraw.color (r, g, b) ~
alpha;
5544 filledrect2 (x0+.dx) (y0+.dy)
5555 GlDraw.color (scalecolor2 conf
.bgcolor
);
5556 GlClear.color (scalecolor2 conf
.bgcolor
);
5557 GlClear.clear
[`
color];
5558 List.iter
drawpage state
.layout;
5560 match state
.mode with
5561 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5562 begin match getopaque pageno with
5564 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5565 let color = (0.0, 0.0, 0.5, 0.5) in
5567 (float x0, float y0,
5572 | None
-> state
.rects
5574 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5577 | View
-> state
.rects
5580 let rec postloop linkindexbase
= function
5582 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5583 postloop linkindexbase rest
5587 postloop 0 state
.layout;
5589 begin match state
.mstate
with
5590 | Mzoomrect
((x0, y0), (x1, y1)) ->
5592 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5593 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5594 filledrect (float x0) (float y0) (float x1) (float y1);
5598 | Mscrolly
| Mscrollx
5607 let zoomrect x y x1 y1 =
5610 and y0 = min
y y1 in
5611 let zoom = (float state
.w) /. float (x1 - x0) in
5614 if state
.w < state
.winw
5615 then (state
.winw
- state
.w) / 2
5618 match conf
.fitmodel
with
5619 | FitWidth
| FitProportional
-> simple ()
5621 match conf
.columns
with
5623 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5624 | Cmulti
_ | Csingle
_ -> simple ()
5626 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5627 state
.anchor <- getanchor
();
5632 let annot inline
x y =
5633 match unproject x y with
5634 | Some
(opaque, n, ux
, uy
) ->
5636 addannot
opaque ux uy
text;
5637 wcmd "freepage %s" (~
> opaque);
5638 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5640 gotoxy state
.x state
.y
5644 let ondone s = add s in
5645 let mode = state
.mode in
5646 state
.mode <- Textentry
(
5647 ("annotation: ", E.s, None
, textentry
, ondone, true),
5648 fun _ -> state
.mode <- mode);
5651 G.postRedisplay "annot"
5653 add @@ getusertext E.s
5658 let g opaque l px py =
5659 match rectofblock
opaque px py with
5661 let x0 = a.(0) -. 20. in
5662 let x1 = a.(1) +. 20. in
5663 let y0 = a.(2) -. 20. in
5664 let zoom = (float state
.w) /. (x1 -. x0) in
5665 let pagey = getpagey
l.pageno in
5666 let margin = (state
.w - l.pagew
)/2 in
5667 let nx = -truncate
x0 - margin in
5668 gotoxy_and_clear_text nx (pagey + truncate
y0);
5669 state
.anchor <- getanchor
();
5674 match conf
.columns
with
5676 impmsg "block zooming does not work properly in split columns mode"
5677 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5681 let winw = state
.winw - 1 in
5682 let s = float x /. float winw in
5683 let destx = truncate
(float (state
.w + winw) *. s) in
5684 gotoxy_and_clear_text (winw - destx) state
.y;
5685 state
.mstate
<- Mscrollx
;
5689 let s = float y /. float state
.winh
in
5690 let desty = truncate
(s *. float (maxy ())) in
5691 gotoxy_and_clear_text state
.x desty;
5692 state
.mstate
<- Mscrolly
;
5695 let viewmulticlick clicks
x y mask
=
5696 let g opaque l px py =
5704 if markunder
opaque px py mark
5708 match getopaque l.pageno with
5710 | Some
opaque -> pipesel opaque cmd
5712 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5713 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5718 G.postRedisplay "viewmulticlick";
5719 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5723 match conf
.columns
with
5725 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5728 let viewmouse button down
x y mask
=
5730 | n when (n == 4 || n == 5) && not down
->
5731 if Wsi.withctrl mask
5735 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5736 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5739 match state
.mstate
with
5740 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
5741 | Mzoomrect
_ | Mnone
| Mpan
_
5742 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
5744 let zoom = conf
.zoom -. incr in
5745 state
.mstate
<- Mzoom
(n, 0, (x, y));
5746 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
5747 then pivotzoom ~
x ~
y zoom
5751 match state
.autoscroll
with
5752 | Some step
-> setautoscrollspeed step
(n=4)
5754 if conf
.wheelbypage
|| conf
.presentation
5763 then -conf
.scrollstep
5764 else conf
.scrollstep
5766 let incr = incr * 2 in
5767 let y = clamp incr in
5768 gotoxy_and_clear_text state
.x y
5771 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5773 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5774 gotoxy_and_clear_text x state
.y
5776 | 1 when Wsi.withshift mask
->
5777 state
.mstate
<- Mnone
;
5780 match unproject x y with
5782 | Some
(_, pageno, ux
, uy
) ->
5783 let cmd = Printf.sprintf
5785 conf
.stcmd state
.path pageno ux uy
5787 match spawn
cmd [] with
5789 impmsg "execution of synctex command(%S) failed: %S"
5790 conf
.stcmd
@@ exntos exn
5794 | 1 when Wsi.withctrl mask
->
5797 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5798 state
.mstate
<- Mpan
(x, y)
5801 state
.mstate
<- Mnone
5806 if Wsi.withshift mask
5808 annot conf
.annotinline
x y;
5809 G.postRedisplay "addannot"
5813 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5814 state
.mstate
<- Mzoomrect
(p, p)
5817 match state
.mstate
with
5818 | Mzoomrect
((x0, y0), _) ->
5819 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5820 then zoomrect x0 y0 x y
5823 G.postRedisplay "kill accidental zoom rect";
5827 | Mscrolly
| Mscrollx
5829 | Mnone
-> resetmstate ()
5832 | 1 when vscrollhit x ->
5835 let _, position, sh = state
.uioh#
scrollph in
5836 if y > truncate
position && y < truncate
(position +. sh)
5837 then state
.mstate
<- Mscrolly
5840 state
.mstate
<- Mnone
5842 | 1 when y > state
.winh
- hscrollh () ->
5845 let _, position, sw = state
.uioh#scrollpw
in
5846 if x > truncate
position && x < truncate
(position +. sw)
5847 then state
.mstate
<- Mscrollx
5850 state
.mstate
<- Mnone
5852 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5855 let dest = if down
then getunder x y else Unone
in
5856 begin match dest with
5860 | Unone
when down
->
5861 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5862 state
.mstate
<- Mpan
(x, y);
5864 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5866 | Unone
| Utext
_ ->
5871 state
.mstate
<- Msel
((x, y), (x, y));
5872 G.postRedisplay "mouse select";
5876 match state
.mstate
with
5879 | Mzoom
_ | Mscrollx
| Mscrolly
->
5880 state
.mstate
<- Mnone
5882 | Mzoomrect
((x0, y0), _) ->
5886 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5887 state
.mstate
<- Mnone
5889 | Msel
((x0, y0), (x1, y1)) ->
5890 let rec loop = function
5894 let a0 = l.pagedispy in
5895 let a1 = a0 + l.pagevh in
5896 let b0 = l.pagedispx in
5897 let b1 = b0 + l.pagevw in
5898 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5899 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5903 match getopaque l.pageno with
5906 pipef ~closew
:false "Msel"
5909 G.postRedisplay "Msel") cmd
5911 dosel conf
.selcmd
();
5912 state
.roam
<- dosel conf
.paxcmd
;
5924 let birdseyemouse button down
x y mask
5925 (conf
, leftx
, _, hooverpageno
, anchor) =
5928 let rec loop = function
5931 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5932 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5934 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5940 | _ -> viewmouse button down
x y mask
5946 method key key mask
=
5947 begin match state
.mode with
5948 | Textentry textentry
-> textentrykeyboard
key mask textentry
5949 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5950 | View
-> viewkeyboard key mask
5951 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5955 method button button bstate
x y mask
=
5956 begin match state
.mode with
5957 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5958 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5963 method multiclick clicks
x y mask
=
5964 begin match state
.mode with
5965 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5966 | Birdseye
_ | Textentry
_ -> ()
5971 begin match state
.mode with
5973 | View
| Birdseye
_ | LinkNav
_ ->
5974 match state
.mstate
with
5975 | Mzoom
_ | Mnone
-> ()
5980 state
.mstate
<- Mpan
(x, y);
5981 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5983 gotoxy_and_clear_text x y
5986 state
.mstate
<- Msel
(a, (x, y));
5987 G.postRedisplay "motion select";
5990 let y = min state
.winh
(max
0 y) in
5994 let x = min state
.winw (max
0 x) in
5997 | Mzoomrect
(p0
, _) ->
5998 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5999 G.postRedisplay "motion zoomrect";
6003 method pmotion
x y =
6004 begin match state
.mode with
6005 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6006 let rec loop = function
6008 if hooverpageno
!= -1
6010 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6011 G.postRedisplay "pmotion birdseye no hoover";
6014 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6015 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6017 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6018 G.postRedisplay "pmotion birdseye hoover";
6026 | LinkNav
_ | View
->
6027 match state
.mstate
with
6028 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6037 let delta = now -. past
in
6040 else conf
.pax
<- Some
now
6044 method infochanged
_ = ()
6047 let maxy = maxy () in
6050 then 0.0, float state
.winh
6051 else scrollph state
.y maxy
6056 let fwinw = float (state
.winw - vscrollw ()) in
6058 let sw = fwinw /. float state
.w in
6059 let sw = fwinw *. sw in
6060 max
sw (float conf
.scrollh
)
6063 let maxx = state
.w + state
.winw in
6064 let x = state
.winw - state
.x in
6065 let percent = float x /. float maxx in
6066 (fwinw -. sw) *. percent
6068 hscrollh (), position, sw
6072 match state
.mode with
6073 | LinkNav
_ -> "links"
6074 | Textentry
_ -> "textentry"
6075 | Birdseye
_ -> "birdseye"
6078 findkeyhash conf
modename
6080 method eformsgs
= true
6081 method alwaysscrolly
= false
6082 method scroll dx dy =
6083 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6084 gotoxy_and_clear_text x (clamp (2 * dy));
6087 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
6090 let addrect pageno r g b a x0 y0 x1 y1 =
6091 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6095 let cl = splitatchar cmds ' '
in
6097 try Scanf.sscanf
s fmt
f
6098 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6101 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6102 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6103 s pageno r g b a x0 y0 x1 y1;
6107 let _,w1,h1
,_ = getpagedim
pageno in
6108 let sw = float w1 /. float w
6109 and sh = float h1
/. float h in
6113 and y1s
= y1 *. sh in
6114 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6115 let color = (r, g, b, a) in
6116 if conf
.verbose
then debugrect rect;
6117 state
.rects <- (pageno, color, rect) :: state
.rects;
6122 | "reload", "" -> reload ()
6124 scan args
"%u %f %f"
6126 let cmd, _ = state
.geomcmds
in
6128 then gotopagexy !wtmode pageno x y
6131 gotopagexy !wtmode pageno x y;
6134 state
.reprf
<- f state
.reprf
6136 | "goto1", args
-> scan args
"%u %f" gotopage
6137 | "gotor", args
-> scan args
"%S" gotoremote
6139 scan args
"%u %u %f %f %f %f"
6140 (fun pageno c x0 y0 x1 y1 ->
6141 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6142 rectx "rect" pageno color x0 y0 x1 y1;
6145 scan args
"%u %f %f %f %f %f %f %f %f"
6146 (fun pageno r g b alpha x0 y0 x1 y1 ->
6147 addrect pageno r g b alpha x0 y0 x1 y1;
6148 G.postRedisplay "prect"
6151 scan args
"%u %f %f"
6154 match getopaque pageno with
6155 | Some
opaque -> opaque
6158 pgoto optopaque pageno x y;
6159 let rec fixx = function
6162 if l.pageno = pageno
6163 then gotoxy (state
.x - l.pagedispx) state
.y
6168 match conf
.columns
with
6169 | Csingle
_ | Csplit
_ -> 1
6170 | Cmulti
((n, _, _), _) -> n
6172 layout 0 state
.y (state
.winw * mult) state
.winh
6176 | "activatewin", "" -> Wsi.activatewin
()
6177 | "quit", "" -> raise Quit
6180 let l = Config.keys_of_string
keys in
6181 List.iter
(fun (k
, m) -> keyboard k
m) l
6182 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6185 | "clearrects", "" ->
6186 Hashtbl.clear state
.prects
;
6187 G.postRedisplay "clearrects"
6189 adderrfmt "remote command"
6190 "error processing remote command: %S\n" cmds
;
6194 let scratch = Bytes.create
80 in
6195 let buf = Buffer.create
80 in
6197 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6198 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6201 if Buffer.length
buf > 0
6203 let s = Buffer.contents
buf in
6211 match Bytes.index_from
scratch ppos '
\n'
with
6212 | pos
-> if pos
>= n then -1 else pos
6213 | exception Not_found
-> -1
6217 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6218 let s = Buffer.contents
buf in
6224 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6230 let remoteopen path =
6231 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6233 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6238 let gcconfig = ref false in
6239 let trimcachepath = ref E.s in
6240 let rcmdpath = ref E.s in
6241 let pageno = ref None
in
6242 let rootwid = ref 0 in
6243 let openlast = ref false in
6244 let doreap = ref false in
6245 let csspath = ref None
in
6246 selfexec := Sys.executable_name
;
6249 [("-p", Arg.String
(fun s -> state
.password <- s),
6250 "<password> Set password");
6254 Config.fontpath
:= s;
6255 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6257 "<path> Set path to the user interface font");
6261 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6262 Config.confpath
:= s),
6263 "<path> Set path to the configuration file");
6265 ("-last", Arg.Set
openlast, " Open last document");
6267 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6268 "<page-number> Jump to page");
6270 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6271 "<path> Set path to the trim cache file");
6273 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6274 "<named-destination> Set named destination");
6276 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6277 ("-cxack", Arg.Set
cxack, " Cut corners");
6279 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6280 "<path> Set path to the source of remote commands");
6282 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
6284 ("-v", Arg.Unit
(fun () ->
6286 "%s\nconfiguration path: %s\n"
6289 exit
0), " Print version and exit");
6291 ("-css", Arg.String
(fun s -> csspath := Some
s),
6292 "<path> Set path to the style sheet to use with EPUB/HTML");
6294 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6296 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6297 "<origin> <undocumented>");
6299 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title")
6302 (fun s -> state
.path <- s)
6303 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6306 then selfexec := !selfexec ^
" -wtmode";
6308 let histmode = emptystr state
.path && not
!openlast in
6310 if not
(Config.load !openlast)
6311 then dolog
"failed to load configuration";
6313 begin match !pageno with
6314 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6326 val mutable m_clicks
= 0
6327 val mutable m_click_x
= 0
6328 val mutable m_click_y
= 0
6329 val mutable m_lastclicktime
= infinity
6331 method private cleanup =
6332 state
.roam
<- noroam
;
6333 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6334 method expose
= G.postRedisplay "expose"
6338 | Wsi.Unobscured
-> "unobscured"
6339 | Wsi.PartiallyObscured
-> "partiallyobscured"
6340 | Wsi.FullyObscured
-> "fullyobscured"
6342 vlog "visibility change %s" name
6343 method display = display ()
6344 method map mapped
= vlog "mapped %b" mapped
6345 method reshape w h =
6348 method mouse
b d x y m =
6349 if d && canselect ()
6352 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6359 if abs
x - m_click_x
> 10
6360 || abs
y - m_click_y
> 10
6361 || abs_float
(t -. m_lastclicktime
) > 0.3
6363 m_clicks
<- m_clicks
+ 1;
6364 m_lastclicktime
<- t;
6368 G.postRedisplay "cleanup";
6369 state
.uioh <- state
.uioh#button
b d x y m;
6371 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6376 m_lastclicktime
<- infinity
;
6377 state
.uioh <- state
.uioh#button
b d x y m
6381 state
.uioh <- state
.uioh#button
b d x y m
6384 state
.mpos
<- (x, y);
6385 state
.uioh <- state
.uioh#motion
x y
6386 method pmotion
x y =
6387 state
.mpos
<- (x, y);
6388 state
.uioh <- state
.uioh#pmotion
x y
6390 vlog "k=%#x m=%#x" k
m;
6391 let mascm = m land (
6392 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6395 let x = state
.x and y = state
.y in
6397 if x != state
.x || y != state
.y then self#
cleanup
6399 match state
.keystate
with
6401 let km = k
, mascm in
6404 let modehash = state
.uioh#
modehash in
6405 try Hashtbl.find modehash km
6407 try Hashtbl.find (findkeyhash conf
"global") km
6408 with Not_found
-> KMinsrt
(k
, m)
6410 | KMinsrt
(k
, m) -> keyboard k
m
6411 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6412 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6414 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6415 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6416 state
.keystate
<- KSnone
6417 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6418 state
.keystate
<- KSinto
(keys, insrt
)
6419 | KSinto
_ -> state
.keystate
<- KSnone
6422 state
.mpos
<- (x, y);
6423 state
.uioh <- state
.uioh#pmotion
x y
6424 method leave = state
.mpos
<- (-1, -1)
6425 method winstate wsl
= state
.winstate
<- wsl
6426 method quit
: '
a. '
a = raise Quit
6427 method scroll dx dy = state
.uioh <- state
.uioh#
scroll dx dy
6428 method zoom z
x y = state
.uioh#
zoom z
x y
6429 method opendoc path =
6432 G.postRedisplay "opendoc";
6433 opendoc path state
.password
6436 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6438 setbgcol conf
.bgcolor
;
6441 if not
@@ List.exists
GlMisc.check_extension
6442 [ "GL_ARB_texture_rectangle"
6443 ; "GL_EXT_texture_recangle"
6444 ; "GL_NV_texture_rectangle" ]
6445 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6447 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6449 defconf
.sliceheight
<- 1024;
6450 defconf
.texcount
<- 32;
6451 defconf
.usepbo
<- true;
6455 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6457 dolog
"socketpair failed: %s" @@ exntos exn
;
6465 setcheckers conf
.checkers
;
6467 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6469 begin match !csspath with
6471 | Some
"" -> conf
.css
<- E.s
6473 let css = filecontents
path in
6474 let l = String.length
css in
6476 if substratis
css (l-2) "\r\n"
6477 then String.sub css 0 (l-2)
6478 else (if css.[l-1] = '
\n'
6479 then String.sub css 0 (l-1)
6483 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6484 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6485 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6487 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6489 reshape ~firsttime
:true winw winh
;
6493 Wsi.settitle
"llpp (history)";
6497 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6498 opendoc state
.path state
.password;
6502 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6503 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6506 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6507 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6508 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6510 | _pid
, _status
-> reap ()
6512 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6516 if nonemptystr
!rcmdpath
6517 then remoteopen !rcmdpath
6522 let rec loop deadline
=
6528 let r = [state
.ss; state
.wsfd] in
6532 | Some fd
-> fd
:: r
6536 state
.redisplay
<- false;
6543 if deadline
= infinity
6545 else max
0.0 (deadline
-. now)
6550 try Unix.select
r [] [] timeout
6551 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6557 if state
.ghyll
== noghyll
6559 match state
.autoscroll
with
6560 | Some step
when step
!= 0 ->
6561 if state
.slideshow
land 1 = 1
6563 if state
.slideshow
land 2 = 0
6564 then state
.slideshow
<- state
.slideshow
lor 2
6565 else if step
< 0 then prevpage () else nextpage ();
6566 deadline
+. (float (abs step
))
6569 let y = state
.y + step
in
6570 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6573 then state
.maxy - fy
6574 else if y >= state
.maxy - fy then 0 else y
6576 if state
.mode = View
6577 then gotoxy_and_clear_text state
.x y
6578 else gotoxy state
.x y;
6581 else deadline
+. 0.01
6586 let rec checkfds = function
6588 | fd
:: rest
when fd
= state
.ss ->
6589 let cmd = rcmd state
.ss in
6593 | fd
:: rest
when fd
= state
.wsfd ->
6597 | fd
:: rest
when Some fd
= !optrfd ->
6598 begin match remote fd
with
6599 | None
-> optrfd := remoteopen !rcmdpath;
6600 | opt -> optrfd := opt
6605 dolog
"select returned unknown descriptor";
6611 if deadline
= infinity
6615 match state
.autoscroll
with
6616 | Some step
when step
!= 0 -> deadline1
6617 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6622 match loop infinity
with
6624 Config.save leavebirdseye;
6625 if hasunsavedchanges
()
6627 | _ -> error
"umpossible - infinity reached"