6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
10 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
11 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
12 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
13 external clearmark
: opaque
-> unit = "ml_clearmark";;
14 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
15 external getmaxw
: unit -> float = "ml_getmaxw";;
16 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
17 external measurestr
: int -> string -> float = "ml_measure_string";;
18 external postprocess
:
19 opaque
-> int -> int -> int -> (int * string * int) -> int
21 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
22 external setaalevel
: int -> unit = "ml_setaalevel";;
23 external realloctexts
: int -> bool = "ml_realloctexts";;
24 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
25 external getlink
: opaque
-> int -> under
= "ml_getlink";;
26 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
27 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
28 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
29 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
30 external freepbo
: opaque
-> unit = "ml_freepbo";;
31 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
32 external bousable
: unit -> bool = "ml_bo_usable";;
33 external unproject
: opaque
-> int -> int -> (int * int) option
35 external project
: opaque
-> int -> int -> float -> float -> (float * float)
37 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
38 external rectofblock
: opaque
-> int -> int -> float array
option
40 external begintiles
: unit -> unit = "ml_begintiles";;
41 external endtiles
: unit -> unit = "ml_endtiles";;
42 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
43 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
44 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
45 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
46 external savedoc
: string -> unit = "ml_savedoc";;
47 external getannotcontents
: opaque
-> slinkindex
-> string
48 = "ml_getannotcontents";;
49 external drawprect
: opaque
-> int -> int -> float array
-> unit
51 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
52 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
53 external uritolocation
: string -> (pageno
* float * float)
54 = "ml_uritolocation";;
55 external isexternallink
: string -> bool = "ml_isexternallink";;
57 let selfexec = ref E.s
;;
58 let opengl_has_pbo = ref false;;
60 let drawstring size x y s
=
62 Gl.enable `texture_2d
;
63 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
64 ignore
(drawstr size x y s
);
66 Gl.disable `texture_2d
;
69 let drawstring1 size x y s
=
73 let drawstring2 size x y fmt
=
74 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
77 module UniSyms
= struct
78 let ellipsis = "\xe2\x80\xa6";;
79 let radical = "\xe2\x88\x9a";;
80 let lguillemet = "\xc2\xab";;
81 let rguillemet = "\xc2\xbb";;
96 l
.pagedispx l
.pagedispy
100 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
106 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
109 let isbirdseye = function
111 | Textentry _
| View
| LinkNav _
-> false
114 let istextentry = function
115 | Textentry _
-> true
116 | Birdseye _
| View
| LinkNav _
-> false
119 let wtmode = ref false;;
120 let cxack = ref false;;
122 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
125 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
126 && (state
.w
> state
.winw
))
132 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
133 && (state
.maxy
> state
.winh
))
141 else x
> state
.winw
- vscrollw ()
145 fstate
.fontsize
<- n
;
146 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
147 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
153 else Printf.kprintf ignore fmt
157 if emptystr conf
.pathlauncher
158 then dolog
"%s" state
.path
160 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
161 match spawn
command [] with
164 dolog
"failed to execute `%s': %s" command @@ exntos exn
170 let postRedisplay who
=
171 vlog "redisplay for [%S]" who
;
172 state
.redisplay
<- true;
176 let getopaque pageno
=
177 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
178 with Not_found
-> None
181 let pagetranslatepoint l x y
=
182 let dy = y
- l
.pagedispy
in
183 let y = dy + l
.pagey
in
184 let dx = x
- l
.pagedispx
in
185 let x = dx + l
.pagex
in
189 let onppundermouse g
x y d
=
192 begin match getopaque l
.pageno
with
194 let x0 = l
.pagedispx
in
195 let x1 = x0 + l
.pagevw
in
196 let y0 = l
.pagedispy
in
197 let y1 = y0 + l
.pagevh
in
198 if y >= y0 && y <= y1 && x >= x0 && x <= x1
200 let px, py
= pagetranslatepoint l
x y in
201 match g opaque l
px py
with
214 let g opaque l
px py
=
217 match rectofblock opaque
px py
with
218 | Some
[|x0;x1;y0;y1|] ->
219 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
220 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
221 state
.rects
<- [l
.pageno
, color, rect];
222 G.postRedisplay "getunder";
225 let under = whatsunder opaque
px py
in
226 if under = Unone
then None
else Some
under
228 onppundermouse g x y Unone
233 match unproject opaque
x y with
234 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
237 onppundermouse g x y None
;
241 state
.text
<- Printf.sprintf
"%c%s" c s
;
242 G.postRedisplay "showtext";
246 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
249 let pipesel opaque cmd
=
252 match Unix.pipe
() with
253 | exception exn
-> dolog
"pipesel cannot create pipe: %S" @@ exntos exn
;
255 let doclose what fd
=
256 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
258 begin match spawn cmd
[r
, 0; w
, -1] with
260 doclose "pipesel pipe/w" w
;
261 dolog
"cannot execute %S: %s" cmd
@@ exntos exn
264 G.postRedisplay "pipesel";
266 doclose "pipesel pipe/r" r
;
270 let g opaque l
px py
=
271 if markunder opaque
px py conf
.paxmark
274 match getopaque l
.pageno
with
276 | Some opaque
-> pipesel opaque conf
.paxcmd
281 G.postRedisplay "paxunder";
282 if conf
.paxmark
= Mark_page
285 match getopaque l
.pageno
with
287 | Some opaque
-> clearmark opaque
) state
.layout
;
288 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
292 match Unix.pipe
() with
293 | exception exn
-> impmsg "pipe failed: %s" @@ exntos exn
296 Ne.clo fd
(fun msg
-> impmsg "failed to close %s: %s" cap msg
)
298 begin match spawn conf
.selcmd
[r
, 0; w
, -1] with
300 clo "selstring pipe/w" w
;
301 impmsg "failed to execute %s: %s" conf
.selcmd
@@ exntos exn
304 let l = String.length s
in
305 let bytes = Bytes.unsafe_of_string s
in
306 let n = tempfailureretry
(Unix.write w
bytes 0) l in
308 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n
309 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
311 clo "selstring pipe/r" r
;
314 let undertext = function
317 | Utext s
-> "font: " ^ s
318 | Uannotation
(opaque
, slinkindex
) ->
319 "annotation: " ^ getannotcontents opaque slinkindex
322 let updateunder x y =
323 match getunder x y with
324 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
326 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
327 Wsi.setcursor
Wsi.CURSOR_INFO
329 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
330 Wsi.setcursor
Wsi.CURSOR_TEXT
332 if conf
.underinfo
then showtext 'a'
"nnotation";
333 Wsi.setcursor
Wsi.CURSOR_INFO
336 let showlinktype under =
337 if conf
.underinfo
&& under != Unone
338 then showtext ' '
@@ undertext under
341 let intentry_with_suffix text key
=
343 if key
>= 32 && key
< 127
345 let c = Char.chr key
in
350 | 'k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
->
351 addchar
text @@ asciilower
c
353 state
.text <- Printf.sprintf
"invalid key (%d, `%c')" key
c;
356 state
.text <- Printf.sprintf
"invalid key %d" key
;
364 let b = Buffer.create
16 in
367 let b = Buffer.to_bytes
b in
368 wcmd state
.ss
b @@ Bytes.length
b
372 let nogeomcmds cmds
=
374 | s
, [] -> emptystr s
378 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
379 let rec fold accu
n =
380 if n = Array.length
b
383 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
386 || n = state
.pagecount
- coverB
387 || (n - coverA
) mod columns
= columns
- 1)
393 let pagey = max
0 (y - vy
) in
394 let pagedispy = if pagey > 0 then 0 else vy
- y in
395 let pagedispx, pagex
=
397 if n = coverA
- 1 || n = state
.pagecount
- coverB
398 then x + (sw
- w
) / 2
406 let vw = sw
- pagedispx in
407 let pw = w
- pagex
in
410 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
411 if pagevw > 0 && pagevh > 0
422 ; pagedispx = pagedispx
423 ; pagedispy = pagedispy
435 if Array.length
b = 0
437 else List.rev
(fold [] (page_of_y
y))
440 let layoutS (columns
, b) x y sw sh
=
441 let rec fold accu n =
442 if n = Array.length
b
445 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
453 let pagey = max
0 (y - vy
) in
454 let pagedispy = if pagey > 0 then 0 else vy
- y in
455 let pagedispx, pagex
=
469 let pagecolw = pagew
/columns
in
472 then pagedispx + ((sw
- pagecolw) / 2)
476 let vw = sw
- pagedispx in
477 let pw = pagew
- pagex
in
480 let pagevw = min
pagevw pagecolw in
481 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
482 if pagevw > 0 && pagevh > 0
493 ; pagedispx = pagedispx
494 ; pagedispy = pagedispy
495 ; pagecol
= n mod columns
509 let layout x y sw sh
=
510 if nogeomcmds state
.geomcmds
512 match conf
.columns
with
513 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
514 | Cmulti
c -> layoutN c x y sw sh
515 | Csplit s
-> layoutS s
x y sw sh
520 let y = state
.y + incr
in
522 let y = min
y (state
.maxy
- (if conf
.maxhfit
then state
.winh
else 0)) in
527 let tilex = l.pagex
mod conf
.tilew
in
528 let tiley = l.pagey mod conf
.tileh
in
530 let col = l.pagex
/ conf
.tilew
in
531 let row = l.pagey / conf
.tileh
in
533 let rec rowloop row y0 dispy h
=
537 let dh = conf
.tileh
- y0 in
539 let rec colloop col x0 dispx w
=
543 let dw = conf
.tilew
- x0 in
545 f col row dispx dispy
x0 y0 dw dh;
546 colloop (col+1) 0 (dispx
+dw) (w
-dw)
549 colloop col tilex l.pagedispx l.pagevw;
550 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
553 if l.pagevw > 0 && l.pagevh > 0
554 then rowloop row tiley l.pagedispy l.pagevh;
557 let gettileopaque l col row =
559 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
561 try Some
(Hashtbl.find state
.tilemap
key)
562 with Not_found
-> None
565 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
566 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
567 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
570 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
571 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
572 GlArray.vertex `two state
.vraw
;
573 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
576 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
578 let filledrect x0 y0 x1 y1 =
579 GlArray.disable `texture_coord
;
580 filledrect1 x0 y0 x1 y1;
581 GlArray.enable `texture_coord
;
584 let linerect x0 y0 x1 y1 =
585 GlArray.disable `texture_coord
;
586 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
587 GlArray.vertex `two state
.vraw
;
588 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
589 GlArray.enable `texture_coord
;
592 let drawtiles l color =
595 let f col row x y tilex tiley w h
=
596 match gettileopaque l col row with
597 | Some
(opaque
, _
, t
) ->
598 let params = x, y, w
, h
, tilex, tiley in
600 then GlTex.env
(`mode `blend
);
601 drawtile
params opaque
;
603 then GlTex.env
(`mode `modulate
);
607 let s = Printf.sprintf
611 let w = measurestr fstate
.fontsize
s in
612 GlDraw.color (0.0, 0.0, 0.0);
613 filledrect (float (x-2))
616 (float (y + fstate
.fontsize
+ 2));
618 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
625 let lw = state
.winw
- x in
628 let lh = state
.winh
- y in
632 then GlTex.env
(`mode `blend
);
633 begin match state
.checkerstexid
with
635 Gl.enable `texture_2d
;
636 GlTex.bind_texture ~target
:`texture_2d id
;
640 and y1 = float (y+h
) in
642 let tw = float w /. 16.0
643 and th
= float h
/. 16.0 in
644 let tx0 = float tilex /. 16.0
645 and ty0
= float tiley /. 16.0 in
647 and ty1
= ty0
+. th
in
648 Raw.sets_float state
.vraw ~pos
:0
649 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
650 Raw.sets_float state
.traw ~pos
:0
651 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
652 GlArray.vertex `two state
.vraw
;
653 GlArray.tex_coord `two state
.traw
;
654 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
655 Gl.disable `texture_2d
;
658 GlDraw.color (1.0, 1.0, 1.0);
659 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
662 then GlTex.env
(`mode `modulate
);
663 if w > 128 && h
> fstate
.fontsize
+ 10
665 let c = if conf
.invert
then 1.0 else 0.0 in
666 GlDraw.color (c, c, c);
669 then (col*conf
.tilew
, row*conf
.tileh
)
672 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
681 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
683 let tilevisible1 l x y =
685 and ax1
= l.pagex
+ l.pagevw
687 and ay1
= l.pagey + l.pagevh in
691 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
692 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
694 let rx0 = max
ax0 bx0
695 and ry0
= max ay0 by0
696 and rx1
= min ax1
bx1
697 and ry1
= min ay1 by1
in
699 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
703 let tilevisible layout n x y =
704 let rec findpageinlayout m
= function
705 | l :: rest
when l.pageno
= n ->
706 tilevisible1 l x y || (
707 match conf
.columns
with
708 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
709 | Csplit _
| Csingle _
| Cmulti _
-> false
711 | _
:: rest
-> findpageinlayout 0 rest
714 findpageinlayout 0 layout;
717 let tileready l x y =
718 tilevisible1 l x y &&
719 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
722 let tilepage n p
layout =
723 let rec loop = function
727 let f col row _ _ _ _ _ _
=
728 if state
.currently
= Idle
730 match gettileopaque l col row with
733 let x = col*conf
.tilew
734 and y = row*conf
.tileh
in
736 let w = l.pagew
- x in
740 let h = l.pageh
- y in
745 then getpbo
w h conf
.colorspace
748 wcmd "tile %s %d %d %d %d %s"
749 (~
> p
) x y w h (~
> pbo);
752 l, p
, conf
.colorspace
, conf
.angle
,
753 state
.gen
, col, row, conf
.tilew
, conf
.tileh
762 if nogeomcmds state
.geomcmds
766 let preloadlayout x y sw sh
=
767 let y = if y < sh
then 0 else y - sh
in
768 let x = min
0 (x + sw
) in
776 if state
.currently
!= Idle
781 begin match getopaque l.pageno
with
783 wcmd "page %d %d" l.pageno
l.pagedimno
;
784 state
.currently
<- Loading
(l, state
.gen
);
786 tilepage l.pageno opaque pages
;
791 if nogeomcmds state
.geomcmds
797 if conf
.preload && state
.currently
= Idle
798 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
801 let layoutready layout =
802 let rec fold all ls
=
805 let seen = ref false in
806 let allvisible = ref true in
807 let foo col row _ _ _ _ _ _
=
809 allvisible := !allvisible &&
810 begin match gettileopaque l col row with
816 fold (!seen && !allvisible) rest
819 let alltilesvisible = fold true layout in
824 let y = bound
y 0 state
.maxy
in
825 let y, layout, proceed
=
826 match conf
.maxwait
with
827 | Some time
when state
.ghyll
== noghyll
->
828 begin match state
.throttle
with
830 let layout = layout x y state
.winw state
.winh
in
831 let ready = layoutready layout in
835 state
.throttle
<- Some
(layout, y, now
());
837 else G.postRedisplay "gotoxy showall (None)";
839 | Some
(_
, _
, started
) ->
840 let dt = now
() -. started
in
843 state
.throttle
<- None
;
844 let layout = layout x y state
.winw state
.winh
in
846 G.postRedisplay "maxwait";
853 let layout = layout x y state
.winw state
.winh
in
854 if not
!wtmode || layoutready layout
855 then G.postRedisplay "gotoxy ready";
862 state
.layout <- layout;
863 begin match state
.mode
with
866 | Ltexact
(pageno
, linkno
) ->
867 let rec loop = function
869 state
.lnava
<- Some
(pageno
, linkno
);
870 state
.mode
<- LinkNav
(Ltgendir
0)
871 | l :: _
when l.pageno
= pageno
->
872 begin match getopaque pageno
with
873 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
875 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
876 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
877 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
878 then state
.mode
<- LinkNav
(Ltgendir
0)
880 | _
:: rest
-> loop rest
883 | Ltnotready _
| Ltgendir _
-> ()
885 | Birdseye _
| Textentry _
| View
-> ()
887 begin match state
.mode
with
888 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
889 if not
(pagevisible layout pageno
)
891 match state
.layout with
894 state
.mode
<- Birdseye
(
895 conf
, leftx
, l.pageno
, hooverpageno
, anchor
900 | Ltnotready
(_
, dir
)
903 let rec loop = function
906 match getopaque l.pageno
with
907 | None
-> Ltnotready
(l.pageno
, dir
)
912 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
914 if dir
> 0 then LDfirst
else LDlast
920 | Lnotfound
-> loop rest
922 showlinktype (getlink opaque
n);
923 Ltexact
(l.pageno
, n)
927 state
.mode
<- LinkNav
linknav
930 | Textentry _
| View
-> ()
934 state
.ghyll
<- noghyll
;
937 let mx, my
= state
.mpos
in
942 let conttiling pageno opaque
=
943 tilepage pageno opaque
945 then preloadlayout state
.x state
.y state
.winw state
.winh
949 let gotoxy_and_clear_text x y =
950 if not conf
.verbose
then state
.text <- E.s;
954 let getanchory (n, top
, dtop
) =
955 let y, h = getpageyh
n in
958 let ips = calcips
h in
959 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
961 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
964 let gotoanchor anchor
=
965 gotoxy state
.x (getanchory anchor
);
969 cbput state
.hists
.nav
(getanchor
());
973 let anchor = cbgetc state
.hists
.nav dir
in
977 let gotoghyll1 single
y =
979 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
981 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
983 then s (float f /. float a
)
986 then 1.0 -. s ((float (f-b) /. float (n-b)))
992 let ins = float a
*. 0.5
993 and outs
= float (n-b) *. 0.5 in
995 ins +. outs
+. float ones
997 let rec set nab
y sy
=
998 let (_N
, _A
, _B
), y =
1001 let scl = if y > sy
then 2 else -2 in
1002 let _N, _
, _
= nab
in
1003 (_N,0,_N), y+conf
.scrollstep
*scl
1005 let sum = summa
_N _A _B
in
1006 let dy = float (y - sy
) in
1010 then state
.ghyll
<- noghyll
1013 let s = scroll n _N _A _B
in
1014 let y1 = y1 +. ((s *. dy) /. sum) in
1015 gotoxy_and_clear_text state
.x (truncate
y1);
1016 state
.ghyll
<- gf (n+1) y1;
1020 | Some
y'
when single
-> set nab
y' state
.y
1021 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1023 gf 0 (float state
.y)
1026 match conf
.ghyllscroll
with
1027 | Some nab
when not conf
.presentation
->
1028 if state
.ghyll
== noghyll
1029 then set nab
y state
.y
1030 else state
.ghyll
(Some
y)
1032 gotoxy_and_clear_text state
.x y
1035 let gotoghyll = gotoghyll1 false;;
1037 let gotopage n top
=
1038 let y, h = getpageyh
n in
1039 let y = y + (truncate
(top
*. float h)) in
1043 let gotopage1 n top
=
1044 let y = getpagey
n in
1049 let invalidate s f =
1050 state
.redisplay
<- false;
1055 match state
.geomcmds
with
1056 | ps
, [] when emptystr ps
->
1058 state
.geomcmds
<- s, [];
1061 state
.geomcmds
<- ps
, [s, f];
1063 | ps
, (s'
, _
) :: rest
when s'
= s ->
1064 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1067 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1071 Hashtbl.iter
(fun _ opaque
->
1072 wcmd "freepage %s" (~
> opaque
);
1074 Hashtbl.clear state
.pagemap
;
1078 if not
(Queue.is_empty state
.tilelru
)
1080 Queue.iter
(fun (k
, p
, s) ->
1081 wcmd "freetile %s" (~
> p
);
1082 state
.memused
<- state
.memused
- s;
1083 Hashtbl.remove state
.tilemap k
;
1085 state
.uioh#infochanged Memused
;
1086 Queue.clear state
.tilelru
;
1092 let h = truncate
(float h*.conf
.zoom
) in
1093 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1097 let opendoc path password
=
1099 state
.password
<- password
;
1100 state
.gen
<- state
.gen
+ 1;
1101 state
.docinfo
<- [];
1102 state
.outlines
<- [||];
1105 setaalevel conf
.aalevel
;
1107 if emptystr state
.origin
1111 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1112 wcmd "open %d %d %d %s\000%s\000%s\000"
1113 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1114 path password conf
.css
;
1115 invalidate "reqlayout"
1117 wcmd "reqlayout %d %d %d %s\000"
1118 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1119 (stateh state
.winh
) state
.nameddest
1122 let sl = keystostrlist conf
in
1124 function | [] -> accu
1125 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1126 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1130 state
.anchor <- getanchor
();
1131 opendoc state
.path state
.password
;
1135 let c = c *. conf
.colorscale
in
1139 let scalecolor2 (r
, g, b) =
1140 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1143 let docolumns columns
=
1146 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1147 let rec loop pageno
pdimno pdim
y ph pdims
=
1148 if pageno
= state
.pagecount
1151 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1153 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1154 pdimno+1, pdim
, rest
1158 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1160 y + (if conf
.presentation
1161 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1162 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1165 a.(pageno
) <- (pdimno, x, y, pdim
);
1166 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1168 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1169 conf
.columns
<- Csingle
a;
1171 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1172 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1173 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1175 if m
= pageno
then () else
1176 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1179 let y = y + (rowh
- h) / 2 in
1180 a.(m
) <- (pdimno, x, y, pdim
);
1184 if pageno
= state
.pagecount
1185 then fixrow (((pageno
- 1) / columns
) * columns
)
1187 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1189 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1190 pdimno+1, pdim
, rest
1195 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1197 let x = (state
.winw
- w) / 2 in
1199 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1200 x, y + ips + rowh
, h
1203 if (pageno
- coverA
) mod columns
= 0
1205 let x = max
0 (state
.winw
- state
.w) / 2 in
1207 if conf
.presentation
1209 let ips = calcips
h in
1210 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1212 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1216 else x, y, max rowh
h
1220 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1223 if pageno
= columns
&& conf
.presentation
1225 let ips = calcips rowh
in
1226 for i
= 0 to pred columns
1228 let (pdimno, x, y, pdim
) = a.(i
) in
1229 a.(i
) <- (pdimno, x, y+ips, pdim
)
1235 fixrow (pageno
- columns
);
1240 a.(pageno
) <- (pdimno, x, y, pdim
);
1241 let x = x + w + xoff
*2 + conf
.interpagespace
in
1242 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1244 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1245 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1248 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1249 let rec loop pageno
pdimno pdim
y pdims
=
1250 if pageno
= state
.pagecount
1253 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1255 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1256 pdimno+1, pdim
, rest
1261 let rec loop1 n x y =
1262 if n = c then y else (
1263 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1264 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1267 let y = loop1 0 0 y in
1268 loop (pageno
+1) pdimno pdim
y pdims
1270 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1271 conf
.columns
<- Csplit
(c, a);
1275 docolumns conf
.columns
;
1276 state
.maxy
<- calcheight
();
1277 if state
.reprf
== noreprf
1279 match state
.mode
with
1280 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1281 let y, h = getpageyh pageno
in
1282 let top = (state
.winh
- h) / 2 in
1283 gotoxy state
.x (max
0 (y - top))
1284 | Textentry _
| View
| LinkNav _
->
1285 let y = getanchory state
.anchor in
1286 let y = min
y (state
.maxy
- state
.winh
) in
1291 state
.reprf
<- noreprf
;
1295 let reshape ?
(firsttime
=false) w h =
1296 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1297 if not firsttime
&& nogeomcmds state
.geomcmds
1298 then state
.anchor <- getanchor
();
1301 let w = truncate
(float w *. conf
.zoom
) in
1304 setfontsize fstate
.fontsize
;
1305 GlMat.mode `modelview
;
1306 GlMat.load_identity
();
1308 GlMat.mode `projection
;
1309 GlMat.load_identity
();
1310 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1311 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1312 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1317 else float state
.x /. float state
.w
1319 invalidate "geometry"
1323 then state
.x <- truncate
(relx *. float w);
1325 match conf
.columns
with
1327 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1328 | Csplit
(c, _
) -> w * c
1330 wcmd "geometry %d %d %d"
1331 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1336 let len = String.length state
.text in
1337 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1340 match state
.mode
with
1341 | Textentry _
| View
| LinkNav _
->
1342 let h, _
, _
= state
.uioh#scrollpw
in
1348 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1349 (x+.w) (float (state
.winh
- hscrollh))
1352 let w = float (state
.winw
- 1 - vscrollw ()) in
1353 if state
.progress
>= 0.0 && state
.progress
< 1.0
1355 GlDraw.color (0.3, 0.3, 0.3);
1356 let w1 = w *. state
.progress
in
1358 GlDraw.color (0.0, 0.0, 0.0);
1359 rect (float x0+.w1) (float x0+.w-.w1)
1362 GlDraw.color (0.0, 0.0, 0.0);
1366 GlDraw.color (1.0, 1.0, 1.0);
1369 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1370 (state
.winh
- hscrollh - 5) s;
1373 match state
.mode
with
1374 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1377 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1378 else Printf.sprintf
"%s%s_" prefix
text
1382 | Birdseye _
| View
| LinkNav _
-> state
.text
1387 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1389 let s1 = "(press 'e' to review error messasges)" in
1390 if nonemptystr
s then s ^
" " ^
s1 else s1
1400 let len = Queue.length state
.tilelru
in
1402 match state
.throttle
with
1405 then preloadlayout state
.x state
.y state
.winw state
.winh
1407 | Some
(layout, _
, _
) ->
1411 if state
.memused
> conf
.memlimit
1415 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1416 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1417 let (_
, pw, ph
, _
) = getpagedim
n in
1419 && colorspace
= conf
.colorspace
1420 && angle
= conf
.angle
1424 let x = col*conf
.tilew
1425 and y = row*conf
.tileh
in
1426 tilevisible (Lazy.force_val
layout) n x y
1428 then Queue.push lruitem state
.tilelru
1431 wcmd "freetile %s" (~
> p
);
1432 state
.memused
<- state
.memused
- s;
1433 state
.uioh#infochanged Memused
;
1434 Hashtbl.remove state
.tilemap k
;
1442 let onpagerect pageno
f =
1444 match conf
.columns
with
1445 | Cmulti
(_
, b) -> b
1447 | Csplit
(_
, b) -> b
1449 if pageno
>= 0 && pageno
< Array.length
b
1451 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1455 let gotopagexy1 wtmode pageno
x y =
1456 let _,w1,h1
,leftx
= getpagedim pageno
in
1457 let top = y /. (float h1
) in
1458 let left = x /. (float w1) in
1459 let py, w, h = getpageywh pageno
in
1460 let wh = state
.winh
in
1461 let x = left *. (float w) in
1462 let x = leftx
+ state
.x + truncate
x in
1464 if x < 0 || x >= state
.winw
1468 let pdy = truncate
(top *. float h) in
1469 let y'
= py + pdy in
1470 let dy = y'
- state
.y in
1472 if x != state
.x || not
(dy > 0 && dy < wh)
1474 if conf
.presentation
1476 if abs
(py - y'
) > wh
1483 if state
.x != sx || state
.y != sy
1488 let ww = state
.winw
in
1490 and qy
= pdy / wh in
1492 and y = py + qy
* wh in
1493 let x = if -x + ww > w1 then -(w1-ww) else x
1494 and y'
= if y + wh > state
.maxy
then state
.maxy
- wh else y in
1496 if conf
.presentation
1498 if abs
(py - y'
) > wh
1507 gotoxy_and_clear_text x y;
1509 else gotoxy_and_clear_text state
.x state
.y;
1512 let gotopagexy wtmode pageno
x y =
1513 match state
.mode
with
1514 | Birdseye
_ -> gotopage pageno
0.0
1515 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1518 let getpassword () =
1519 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1524 impmsg "error getting password: %s" s;
1525 dolog
"%s" s) passcmd;
1528 let pgoto opaque pageno
x y =
1529 let pdimno = getpdimno pageno
in
1530 let x, y = project opaque pageno
pdimno x y in
1531 gotopagexy false pageno
x y;
1535 (* dolog "%S" cmds; *)
1536 let spl = splitatchar cmds ' '
in
1538 try Scanf.sscanf
s fmt
f
1540 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1543 let addoutline outline
=
1544 match state
.currently
with
1545 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1546 | Idle
-> state
.currently
<- Outlining
[outline
]
1547 | Loading
_ | Tiling
_ ->
1548 dolog
"invalid outlining state";
1549 logcurrently state
.currently
1554 state
.uioh#infochanged Pdim
;
1556 | "clearrects", "" ->
1557 state
.rects
<- state
.rects1
;
1558 G.postRedisplay "clearrects";
1560 | "continue", args
->
1561 let n = scan args
"%u" (fun n -> n) in
1562 state
.pagecount
<- n;
1563 begin match state
.currently
with
1565 state
.currently
<- Idle
;
1566 state
.outlines
<- Array.of_list
(List.rev
l)
1567 | Idle
| Loading
_ | Tiling
_ -> ()
1570 let cur, cmds
= state
.geomcmds
in
1572 then failwith
"umpossible";
1574 begin match List.rev cmds
with
1576 state
.geomcmds
<- E.s, [];
1577 state
.throttle
<- None
;
1581 state
.geomcmds
<- s, List.rev rest
;
1583 if conf
.maxwait
= None
&& not
!wtmode
1584 then G.postRedisplay "continue";
1591 then showtext ' ' args
1594 Buffer.add_string state
.errmsgs args
;
1595 state
.newerrmsgs
<- true;
1596 G.postRedisplay "error message"
1598 | "progress", args
->
1599 let progress, text =
1602 f, String.sub args pos
(String.length args
- pos
))
1605 state
.progress <- progress;
1606 G.postRedisplay "progress"
1608 | "firstmatch", args
->
1609 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1610 scan args
"%u %d %f %f %f %f %f %f %f %f"
1611 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1612 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1614 let y = (getpagey
pageno) + truncate
y0 in
1622 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1623 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1626 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1627 scan args
"%u %d %f %f %f %f %f %f %f %f"
1628 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1629 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1631 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1633 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1636 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1637 let pageopaque = ~
< pageopaques in
1638 begin match state
.currently
with
1639 | Loading
(l, gen
) ->
1640 vlog "page %d took %f sec" l.pageno t
;
1641 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1642 begin match state
.throttle
with
1644 let preloadedpages =
1646 then preloadlayout state
.x state
.y state
.winw state
.winh
1651 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1652 IntSet.empty
preloadedpages
1655 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1656 if not
(IntSet.mem
pageno set)
1658 wcmd "freepage %s" (~
> opaque
);
1664 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1667 state
.currently
<- Idle
;
1670 tilepage l.pageno pageopaque state
.layout;
1672 load preloadedpages;
1673 let visible = pagevisible state
.layout l.pageno in
1676 match state
.mode
with
1677 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1678 if pageno = l.pageno
1683 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1685 if dir
> 0 then LDfirst
else LDlast
1688 findlink
pageopaque ld
1693 showlinktype (getlink
pageopaque n);
1694 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1696 | LinkNav
(Ltgendir
_)
1697 | LinkNav
(Ltexact
_)
1703 if visible && layoutready state
.layout
1705 G.postRedisplay "page";
1709 | Some
(layout, _, _) ->
1710 state
.currently
<- Idle
;
1711 tilepage l.pageno pageopaque layout;
1715 | Idle
| Tiling
_ | Outlining
_ ->
1716 dolog
"Inconsistent loading state";
1717 logcurrently state
.currently
;
1722 let (x, y, opaques
, size
, t
) =
1723 scan args
"%u %u %s %u %f"
1724 (fun x y p size t
-> (x, y, p
, size
, t
))
1726 let opaque = ~
< opaques
in
1727 begin match state
.currently
with
1728 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1729 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1732 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1734 wcmd "freetile %s" (~
> opaque);
1735 state
.currently
<- Idle
;
1739 puttileopaque l col row gen cs angle
opaque size t
;
1740 state
.memused
<- state
.memused
+ size
;
1741 state
.uioh#infochanged Memused
;
1743 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1744 opaque, size
) state
.tilelru
;
1747 match state
.throttle
with
1748 | None
-> state
.layout
1749 | Some
(layout, _, _) -> layout
1752 state
.currently
<- Idle
;
1754 && conf
.colorspace
= cs
1755 && conf
.angle
= angle
1756 && tilevisible layout l.pageno x y
1757 then conttiling l.pageno pageopaque;
1759 begin match state
.throttle
with
1761 preload state
.layout;
1763 && conf
.colorspace
= cs
1764 && conf
.angle
= angle
1765 && tilevisible state
.layout l.pageno x y
1766 && (not
!wtmode || layoutready state
.layout)
1767 then G.postRedisplay "tile nothrottle";
1769 | Some
(layout, y, _) ->
1770 let ready = layoutready layout in
1774 state
.layout <- layout;
1775 state
.throttle
<- None
;
1776 G.postRedisplay "throttle";
1782 | Idle
| Loading
_ | Outlining
_ ->
1783 dolog
"Inconsistent tiling state";
1784 logcurrently state
.currently
;
1789 let (n, w, h, _) as pdim
=
1790 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1793 match conf
.fitmodel
with
1795 | FitPage
| FitProportional
->
1796 match conf
.columns
with
1797 | Csplit
_ -> (n, w, h, 0)
1798 | Csingle
_ | Cmulti
_ -> pdim
1800 state
.pdims
<- pdim :: state
.pdims
;
1801 state
.uioh#infochanged Pdim
1804 let (l, n, t
, h, pos
) =
1805 scan args
"%u %u %d %u %n"
1806 (fun l n t
h pos
-> l, n, t
, h, pos
)
1808 let s = String.sub args pos
(String.length args
- pos
) in
1809 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1812 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1813 let s = String.sub args pos
len in
1814 let pos2 = pos
+ len + 1 in
1815 let uri = String.sub args
pos2 (String.length args
- pos2) in
1816 addoutline (s, l, Ouri
uri)
1819 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1820 let s = String.sub args pos
(String.length args
- pos
) in
1821 addoutline (s, l, Onone
)
1825 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1827 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1830 let c, v
= splitatchar args '
\t'
in
1841 if let len = String.length
c in
1842 len > 6 && ((String.sub
c (len-4) 4) = "date")
1844 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1846 let b = Buffer.create
10 in
1847 Printf.bprintf
b "%s\t" c;
1850 Buffer.add_substring
b v p
l;
1851 Buffer.add_char
b c;
1852 with exn
-> Buffer.add_string
b @@ exntos exn
1860 Buffer.add_char
b '
['
;
1861 Buffer.add_string
b v
;
1862 Buffer.add_char
b '
]'
;
1869 state
.docinfo
<- (1, s) :: state
.docinfo
1872 state
.docinfo
<- List.rev state
.docinfo
;
1873 state
.uioh#infochanged Docinfo
1877 then Wsi.settitle
"Wrong password";
1878 let password = getpassword () in
1879 if emptystr
password
1880 then error
"document is password protected"
1881 else opendoc state
.path
password
1884 error
"unknown cmd `%S'" cmds
1889 let action = function
1890 | HCprev
-> cbget cb ~
-1
1891 | HCnext
-> cbget cb
1
1892 | HCfirst
-> cbget cb ~
-(cb
.rc)
1893 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1894 and cancel
() = cb
.rc <- rc
1898 let search pattern forward
=
1899 match conf
.columns
with
1900 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1901 | Csingle
_ | Cmulti
_ ->
1902 if nonemptystr pattern
1905 match state
.layout with
1908 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1910 wcmd "search %d %d %d %d,%s\000"
1911 (btod conf
.icase
) pn py (btod forward
) pattern
;
1914 let intentry text key =
1916 if key >= 32 && key < 127
1918 let c = Char.chr
key in
1920 | '
0'
.. '
9'
-> addchar
text c
1922 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1925 state
.text <- Printf.sprintf
"invalid key (%d)" key;
1936 let l = String.length
s in
1937 let rec loop pos
n =
1941 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1942 loop (pos
+1) (n*26 + m)
1945 let rec loop n = function
1948 match getopaque l.pageno with
1949 | None
-> loop n rest
1951 let m = getlinkcount
opaque in
1954 let under = getlink
opaque n in
1957 else loop (n-m) rest
1959 loop n state
.layout;
1963 let linknentry text key =
1964 if key >= 32 && key < 127
1966 let text = addchar
text (Char.chr
key) in
1967 linknact (fun under -> state
.text <- undertext under) text;
1970 state
.text <- Printf.sprintf
"invalid key %d" key;
1975 let textentry text key =
1976 if Wsi.isspecialkey
key
1978 else TEcont
(text ^ toutf8
key)
1981 let reqlayout angle fitmodel
=
1982 match state
.throttle
with
1984 if nogeomcmds state
.geomcmds
1985 then state
.anchor <- getanchor
();
1986 conf
.angle
<- angle
mod 360;
1989 match state
.mode
with
1990 | LinkNav
_ -> state
.mode
<- View
1991 | Birdseye
_ | Textentry
_ | View
-> ()
1993 conf
.fitmodel
<- fitmodel
;
1997 wcmd "reqlayout %d %d %d"
1998 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
2003 let settrim trimmargins trimfuzz
=
2004 if nogeomcmds state
.geomcmds
2005 then state
.anchor <- getanchor
();
2006 conf
.trimmargins
<- trimmargins
;
2007 conf
.trimfuzz
<- trimfuzz
;
2008 let x0, y0, x1, y1 = trimfuzz
in
2010 "settrim" (fun () ->
2011 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
2016 match state
.throttle
with
2018 let zoom = max
0.0001 zoom in
2019 if zoom <> conf
.zoom
2021 state
.prevzoom
<- (conf
.zoom, state
.x);
2023 reshape state
.winw state
.winh
;
2024 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2027 | Some
(layout, y, started
) ->
2029 match conf
.maxwait
with
2033 let dt = now
() -. started
in
2041 let pivotzoom ?
(vw=min state
.w state
.winw
)
2042 ?
(vh
=min
(state
.maxy
-state
.y) state
.winh
)
2043 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2044 let w = float state
.w /. zoom in
2045 let hw = w /. 2.0 in
2046 let ratio = float vh
/. float vw in
2047 let hh = hw *. ratio in
2048 let x0 = if zoom < 1.0 then 0.0 else float x -. hw in
2049 let y0 = float y -. hh in
2050 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2054 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2055 if nogeomcmds state
.geomcmds
then pivotzoom ?
vw ?vh ?
x ?
y zoom
2058 let setcolumns mode columns coverA coverB
=
2059 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2063 then impmsg "split mode doesn't work in bird's eye"
2065 conf
.columns
<- Csplit
(-columns
, E.a);
2073 conf
.columns
<- Csingle
E.a;
2078 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2082 reshape state
.winw state
.winh
;
2085 let resetmstate () =
2086 state
.mstate
<- Mnone
;
2087 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2090 let enterbirdseye () =
2091 let zoom = float conf
.thumbw
/. float state
.winw
in
2092 let birdseyepageno =
2093 let cy = state
.winh
/ 2 in
2097 let rec fold best
= function
2100 let d = cy - (l.pagedispy + l.pagevh/2)
2101 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2102 if abs
d < abs dbest
2111 { conf
with zoom = conf
.zoom },
2112 state
.x, birdseyepageno, -1, getanchor
()
2116 conf
.presentation
<- false;
2117 conf
.interpagespace
<- 10;
2118 conf
.hlinks
<- false;
2119 conf
.fitmodel
<- FitPage
;
2121 conf
.maxwait
<- None
;
2123 match conf
.beyecolumns
with
2126 Cmulti
((c, 0, 0), E.a)
2127 | None
-> Csingle
E.a
2131 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2136 reshape state
.winw state
.winh
;
2139 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2141 conf
.zoom <- c.zoom;
2142 conf
.presentation
<- c.presentation
;
2143 conf
.interpagespace
<- c.interpagespace
;
2144 conf
.maxwait
<- c.maxwait
;
2145 conf
.hlinks
<- c.hlinks
;
2146 conf
.fitmodel
<- c.fitmodel
;
2147 conf
.beyecolumns
<- (
2148 match conf
.columns
with
2149 | Cmulti
((c, _, _), _) -> Some
c
2151 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2154 match c.columns
with
2155 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2156 | Csingle
_ -> Csingle
E.a
2157 | Csplit
(c, _) -> Csplit
(c, E.a)
2161 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2164 reshape state
.winw state
.winh
;
2165 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2169 let togglebirdseye () =
2170 match state
.mode
with
2171 | Birdseye vals
-> leavebirdseye vals
true
2172 | View
-> enterbirdseye ()
2173 | Textentry
_ | LinkNav
_ -> ()
2176 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2177 let pageno = max
0 (pageno - incr
) in
2178 let rec loop = function
2179 | [] -> gotopage1 pageno 0
2180 | l :: _ when l.pageno = pageno ->
2181 if l.pagedispy >= 0 && l.pagey = 0
2182 then G.postRedisplay "upbirdseye"
2183 else gotopage1 pageno 0
2184 | _ :: rest
-> loop rest
2188 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2191 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2192 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2193 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2194 let rec loop = function
2196 let y, h = getpageyh
pageno in
2197 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2198 gotoxy state
.x (clamp dy)
2199 | l :: _ when l.pageno = pageno ->
2200 if l.pagevh != l.pageh
2201 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2202 else G.postRedisplay "downbirdseye"
2203 | _ :: rest
-> loop rest
2209 let optentry mode
_ key =
2210 let btos b = if b then "on" else "off" in
2211 if key >= 32 && key < 127
2213 let c = Char.chr
key in
2217 try conf
.scrollstep
<- int_of_string
s with exn
->
2218 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2220 TEswitch
("scroll step: ", E.s, None
, intentry, ondone, true)
2225 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2226 if state
.autoscroll
<> None
2227 then state
.autoscroll
<- Some conf
.autoscrollstep
2229 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2231 TEswitch
("auto scroll step: ", E.s, None
, intentry, ondone, true)
2236 let n, a, b = multicolumns_of_string
s in
2237 setcolumns mode
n a b;
2239 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2241 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
2246 let zoom = float (int_of_string
s) /. 100.0 in
2249 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2251 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
2256 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2258 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2259 begin match mode
with
2261 leavebirdseye beye
false;
2263 | Textentry
_ | View
| LinkNav
_ -> ();
2266 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2268 TEswitch
("thumbnail width: ", E.s, None
, intentry, ondone, true)
2272 match int_of_string
s with
2273 | angle
-> reqlayout angle conf
.fitmodel
2276 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2278 TEswitch
("rotation: ", E.s, None
, intentry, ondone, true)
2281 conf
.icase
<- not conf
.icase
;
2282 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2285 conf
.preload <- not conf
.preload;
2286 gotoxy state
.x state
.y;
2287 TEdone
("preload " ^
(btos conf
.preload))
2290 conf
.verbose
<- not conf
.verbose
;
2291 TEdone
("verbose " ^
(btos conf
.verbose
))
2294 conf
.debug
<- not conf
.debug
;
2295 TEdone
("debug " ^
(btos conf
.debug
))
2298 conf
.maxhfit
<- not conf
.maxhfit
;
2299 state
.maxy
<- calcheight
();
2300 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2303 conf
.crophack
<- not conf
.crophack
;
2304 TEdone
("crophack " ^
btos conf
.crophack
)
2308 match conf
.maxwait
with
2310 conf
.maxwait
<- Some infinity
;
2311 "always wait for page to complete"
2313 conf
.maxwait
<- None
;
2314 "show placeholder if page is not ready"
2319 conf
.underinfo
<- not conf
.underinfo
;
2320 TEdone
("underinfo " ^
btos conf
.underinfo
)
2323 conf
.savebmarks
<- not conf
.savebmarks
;
2324 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2330 match state
.layout with
2335 conf
.interpagespace
<- int_of_string
s;
2336 docolumns conf
.columns
;
2337 state
.maxy
<- calcheight
();
2338 let y = getpagey
pageno in
2339 gotoxy state
.x (y + py)
2341 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2343 TEswitch
("vertical margin: ", E.s, None
, intentry, ondone, true)
2347 match conf
.fitmodel
with
2348 | FitProportional
-> FitWidth
2349 | FitWidth
| FitPage
-> FitProportional
2351 reqlayout conf
.angle
fm;
2352 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2355 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2356 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2359 conf
.invert
<- not conf
.invert
;
2360 TEdone
("invert colors " ^
btos conf
.invert
)
2364 cbput state
.hists
.sel
s;
2367 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2368 textentry, ondone, true)
2372 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2373 else conf
.pax
<- None
;
2374 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2377 state
.text <- Printf.sprintf
"bad option %d `%c'" key c;
2383 class type lvsource
=
2385 method getitemcount
: int
2386 method getitem
: int -> (string * int)
2387 method hasaction
: int -> bool
2388 method exit
: uioh
:uioh
->
2394 method getactive
: int
2395 method getfirst
: int
2397 method getminfo
: (int * int) array
2400 class virtual lvsourcebase
= object
2401 val mutable m_active
= 0
2402 val mutable m_first
= 0
2403 val mutable m_pan
= 0
2404 method getactive
= m_active
2405 method getfirst
= m_first
2406 method getpan
= m_pan
2407 method getminfo
: (int * int) array
= E.a
2410 let textentrykeyboard
2411 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2414 state
.mode
<- Textentry
(te
, onleave
);
2416 G.postRedisplay "textentrykeyboard enttext";
2418 let histaction cmd
=
2421 | Some
(action, _) ->
2424 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2426 G.postRedisplay "textentry histaction"
2429 match Wsi.kc2kt
key with
2431 if emptystr
text && cancelonempty
2434 G.postRedisplay "textentrykeyboard after cancel";
2437 let s = withoutlastutf8
text in
2438 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2440 | Enter
| KPenter
->
2443 G.postRedisplay "textentrykeyboard after confirm"
2445 | Up
| KPup
-> histaction HCprev
2446 | Down
| KPdown
-> histaction HCnext
2447 | Home
| KPhome
-> histaction HCfirst
2448 | End
| KPend
-> histaction HClast
2453 begin match opthist
with
2455 | Some
(_, onhistcancel
) -> onhistcancel
()
2459 G.postRedisplay "textentrykeyboard after cancel2"
2462 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2465 | Delete
| KPdelete
-> ()
2467 | Code
_ | Ascii
_->
2468 begin match onkey
text key with
2472 G.postRedisplay "textentrykeyboard after confirm2";
2475 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2479 G.postRedisplay "textentrykeyboard after cancel3"
2482 state
.mode
<- Textentry
(te
, onleave
);
2483 G.postRedisplay "textentrykeyboard switch";
2485 | Insert
|KPleft
|KPminus
|KPnext
|KPplus
|KPprior
|KPright
|Left
|Right
|Next
|Prior
2487 vlog "unhandled key %s" (Wsi.keyname
key)
2490 let firstof first active
=
2491 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2492 then max
0 (active
- (fstate
.maxrows
/2))
2496 let calcfirst first active
=
2499 let rows = active
- first
in
2500 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2504 let scrollph y maxy
=
2505 let sh = float (maxy
+ state
.winh
) /. float state
.winh
in
2506 let sh = float state
.winh
/. sh in
2507 let sh = max
sh (float conf
.scrollh
) in
2509 let percent = float y /. float maxy
in
2510 let position = (float state
.winh
-. sh) *. percent in
2513 if position +. sh > float state
.winh
2514 then float state
.winh
-. sh
2520 let adderrmsg src msg
=
2521 Buffer.add_string state
.errmsgs msg
;
2522 state
.newerrmsgs
<- true;
2526 let adderrfmt src fmt
=
2527 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2530 let coe s = (s :> uioh
);;
2532 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2534 val m_pan
= source#getpan
2535 val m_first
= source#getfirst
2536 val m_active
= source#getactive
2538 val m_prev_uioh
= state
.uioh
2540 method private elemunder
y =
2544 let n = y / (fstate
.fontsize
+1) in
2545 if m_first
+ n < source#getitemcount
2547 if source#hasaction
(m_first
+ n)
2548 then Some
(m_first
+ n)
2555 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2556 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2557 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2558 GlDraw.color (1., 1., 1.);
2559 Gl.enable `texture_2d
;
2560 let fs = fstate
.fontsize
in
2562 let hw = state
.winw
/3 in
2563 let ww = fstate
.wwidth
in
2564 let tabw = 17.0*.ww in
2565 let itemcount = source#getitemcount
in
2566 let minfo = source#getminfo
in
2570 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2572 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2574 if (row - m_first
) > fstate
.maxrows
2577 if row >= 0 && row < itemcount
2579 let (s, level
) = source#getitem
row in
2580 let y = (row - m_first
) * nfs in
2581 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2584 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2588 Gl.disable `texture_2d
;
2589 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2590 GlDraw.color (1., 1., 1.) ~
alpha;
2591 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2592 Gl.enable `texture_2d
;
2595 if zebra
&& row land 1 = 1
2599 GlDraw.color (c,c,c);
2600 let drawtabularstring s =
2602 let x'
= truncate
(x0 +. x) in
2603 let s1, s2
= splitatchar
s '
\000'
in
2605 then drawstring1 fs x'
(y+nfs) s
2611 let s'
= withoutlastutf8
s in
2612 let s = s' ^
UniSyms.ellipsis in
2613 let w = measurestr
fs s in
2614 if float x'
+. w +. ww < float (hw + x'
)
2619 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2623 ignore
(drawstring1 fs x'
(y+nfs) s1);
2624 drawstring1 fs (hw + x'
) (y+nfs) s2
2628 let x = if helpmode
&& row > 0 then x +. ww else x in
2629 let s1, s2
= splitatchar
s '
\t'
in
2632 let nx = drawstr x s1 in
2634 let x = x +. (max
tabw sw) in
2637 let len = String.length
s - 2 in
2638 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2640 let s = String.sub s 2 len in
2641 let x = if not helpmode
then x +. ww else x in
2642 GlDraw.color (1.2, 1.2, 1.2);
2643 let vinc = drawstring1 (fs+fs/4)
2644 (truncate
(x -. ww)) (y+nfs) s in
2645 GlDraw.color (1., 1., 1.);
2646 vinc +. (float fs *. 0.8)
2652 ignore
(drawtabularstring s);
2658 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2661 if (row - m_first
) <= fstate
.maxrows
2663 if row >= 0 && row < itemcount
2665 let (s, level
) = source#getitem
row in
2666 let pos0 = nindex
s '
\000'
in
2667 let y = (row - m_first
) * nfs in
2668 let x = float (level
+ m_pan
) *. ww in
2669 let (first
, last
) = minfo.(row) in
2671 if pos0 > 0 && first
> pos0
2672 then String.sub s (pos0+1) (first
-pos0-1)
2673 else String.sub s 0 first
2675 let suffix = String.sub s first
(last
- first
) in
2676 let w1 = measurestr fstate
.fontsize
prefix in
2677 let w2 = measurestr fstate
.fontsize
suffix in
2678 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2679 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2681 and y0 = float (y+2) in
2683 and y1 = float (y+fs+3) in
2684 filledrect x0 y0 x1 y1;
2688 Gl.disable `texture_2d
;
2689 if Array.length
minfo > 0 then loop m_first
;
2694 method updownlevel incr
=
2695 let len = source#getitemcount
in
2697 if m_active
>= 0 && m_active
< len
2698 then snd
(source#getitem m_active
)
2702 if i
= len then i
-1 else if i
= -1 then 0 else
2703 let _, l = source#getitem i
in
2704 if l != curlevel then i
else flow (i
+incr
)
2706 let active = flow m_active
in
2707 let first = calcfirst m_first
active in
2708 G.postRedisplay "outline updownlevel";
2709 {< m_active
= active; m_first
= first >}
2711 method private key1
key mask
=
2712 let set1 active first qsearch
=
2713 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2715 let search active pattern incr
=
2716 let active = if active = -1 then m_first
else active in
2719 if n >= 0 && n < source#getitemcount
2721 let s, _ = source#getitem
n in
2722 match Str.search_forward re
s 0 with
2723 | exception Not_found
-> loop (n + incr
)
2730 let qpat = Str.quote pattern
in
2731 match Str.regexp_case_fold
qpat with
2734 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2735 qpat @@ Printexc.to_string exn
;
2738 let itemcount = source#getitemcount
in
2739 let find start incr
=
2741 if i
= -1 || i
= itemcount
2744 if source#hasaction i
2746 else find (i
+ incr
)
2751 let set active first =
2752 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2754 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2757 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2759 let incr1 = if incr
> 0 then 1 else -1 in
2760 if isvisible m_first m_active
2763 let next = m_active
+ incr
in
2765 if next < 0 || next >= itemcount
2767 else find next incr1
2769 if abs
(m_active
- next) > fstate
.maxrows
2775 let first = m_first
+ incr
in
2776 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2778 let next = m_active
+ incr
in
2779 let next = bound
next 0 (itemcount - 1) in
2786 if isvisible first next
2793 let first = min
next m_first
in
2795 if abs
(next - first) > fstate
.maxrows
2801 let first = m_first
+ incr
in
2802 let first = bound
first 0 (itemcount - 1) in
2804 let next = m_active
+ incr
in
2805 let next = bound
next 0 (itemcount - 1) in
2806 let next = find next incr1 in
2808 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2810 let active = if m_active
= -1 then next else m_active
in
2815 if isvisible first active
2821 G.postRedisplay "listview navigate";
2825 match Wsi.kc2kt
key with
2826 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2827 let incr = if c = 'r'
then -1 else 1 in
2829 match search (m_active
+ incr) m_qsearch
incr with
2831 state
.text <- m_qsearch ^
" [not found]";
2834 state
.text <- m_qsearch
;
2835 active, firstof m_first
active
2837 G.postRedisplay "listview ctrl-r/s";
2838 set1 active first m_qsearch
;
2840 | Insert
when Wsi.withctrl mask
->
2841 if m_active
>= 0 && m_active
< source#getitemcount
2843 let s, _ = source#getitem m_active
in
2849 if emptystr m_qsearch
2852 let qsearch = withoutlastutf8 m_qsearch
in
2856 G.postRedisplay "listview empty qsearch";
2857 set1 m_active m_first
E.s;
2861 match search m_active
qsearch ~
-1 with
2863 state
.text <- qsearch ^
" [not found]";
2866 state
.text <- qsearch;
2867 active, firstof m_first
active
2869 G.postRedisplay "listview backspace qsearch";
2870 set1 active first qsearch
2873 | _ when not
(Wsi.isspecialkey
key) ->
2874 let pattern = m_qsearch ^ toutf8
key in
2876 match search m_active
pattern 1 with
2878 state
.text <- pattern ^
" [not found]";
2881 state
.text <- pattern;
2882 active, firstof m_first
active
2884 G.postRedisplay "listview qsearch add";
2885 set1 active first pattern;
2889 if emptystr m_qsearch
2891 G.postRedisplay "list view escape";
2892 let mx, my
= state
.mpos
in
2896 source#exit ~uioh
:(coe self
)
2897 ~cancel
:true ~
active:m_active ~
first:m_first ~pan
:m_pan
2899 | None
-> m_prev_uioh
2904 G.postRedisplay "list view kill qsearch";
2905 coe {< m_qsearch
= E.s >}
2908 | Enter
| KPenter
->
2910 let self = {< m_qsearch
= E.s >} in
2912 G.postRedisplay "listview enter";
2913 if m_active
>= 0 && m_active
< source#getitemcount
2915 source#exit ~uioh
:(coe self) ~cancel
:false
2916 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2919 source#exit ~uioh
:(coe self) ~cancel
:true
2920 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2923 begin match opt with
2924 | None
-> m_prev_uioh
2928 | Delete
| KPdelete
->
2931 | Up
| KPup
-> navigate ~
-1
2932 | Down
| KPdown
-> navigate 1
2933 | Prior
| KPprior
-> navigate ~
-(fstate
.maxrows
)
2934 | Next
| KPnext
-> navigate fstate
.maxrows
2936 | Right
| KPright
->
2938 G.postRedisplay "listview right";
2939 coe {< m_pan
= m_pan
- 1 >}
2943 G.postRedisplay "listview left";
2944 coe {< m_pan
= m_pan
+ 1 >}
2947 let active = find 0 1 in
2948 G.postRedisplay "listview home";
2952 let first = max
0 (itemcount - fstate
.maxrows
) in
2953 let active = find (itemcount - 1) ~
-1 in
2954 G.postRedisplay "listview end";
2957 | _ when (key = 0 || Wsi.isspecialkey
key) ->
2960 | (Insert
|KPminus
|KPplus
|Ascii
_|Code
_|Fn
_) ->
2961 dolog
"listview unknown key %#x" key; coe self
2963 method key key mask
=
2964 match state
.mode
with
2966 textentrykeyboard key mask te
;
2968 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2970 method button button down
x y _ =
2973 | 1 when vscrollhit x ->
2974 G.postRedisplay "listview scroll";
2977 let _, position, sh = self#
scrollph in
2978 if y > truncate
position && y < truncate
(position +. sh)
2980 state
.mstate
<- Mscrolly
;
2984 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2985 let first = truncate
(s *. float source#getitemcount
) in
2986 let first = min source#getitemcount
first in
2987 Some
(coe {< m_first
= first; m_active
= first >})
2989 state
.mstate
<- Mnone
;
2993 begin match self#elemunder
y with
2995 G.postRedisplay "listview click";
2996 source#exit ~uioh
:(coe {< m_active
= n >})
2997 ~cancel
:false ~
active:n ~
first:m_first ~pan
:m_pan
3001 | n when (n == 4 || n == 5) && not down
->
3002 let len = source#getitemcount
in
3004 if n = 5 && m_first
+ fstate
.maxrows
>= len
3008 let first = m_first
+ (if n == 4 then -1 else 1) in
3009 bound
first 0 (len - 1)
3011 G.postRedisplay "listview wheel";
3012 Some
(coe {< m_first
= first >})
3013 | n when (n = 6 || n = 7) && not down
->
3014 let inc = if n = 7 then -1 else 1 in
3015 G.postRedisplay "listview hwheel";
3016 Some
(coe {< m_pan
= m_pan
+ inc >})
3021 | None
-> m_prev_uioh
3024 method multiclick
_ x y = self#button
1 true x y
3027 match state
.mstate
with
3029 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3030 let first = truncate
(s *. float source#getitemcount
) in
3031 let first = min source#getitemcount
first in
3032 G.postRedisplay "listview motion";
3033 coe {< m_first
= first; m_active
= first >}
3041 method pmotion
x y =
3042 if x < state
.winw
- conf
.scrollbw
3045 match self#elemunder
y with
3046 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3047 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3051 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3056 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3060 method infochanged
_ = ()
3062 method scrollpw
= (0, 0.0, 0.0)
3064 let nfs = fstate
.fontsize
+ 1 in
3065 let y = m_first
* nfs in
3066 let itemcount = source#getitemcount
in
3067 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3068 let maxy = maxi * nfs in
3069 let p, h = scrollph y maxy in
3072 method modehash
= modehash
3073 method eformsgs
= false
3074 method alwaysscrolly
= true
3077 class outlinelistview ~zebra ~source
=
3078 let settext autonarrow
s =
3081 let ss = source#statestr
in
3085 else "{" ^
ss ^
"} [" ^
s ^
"]"
3086 else state
.text <- s
3092 ~source
:(source
:> lvsource
)
3094 ~modehash
:(findkeyhash conf
"outline")
3097 val m_autonarrow
= false
3099 method! key key mask
=
3101 if emptystr state
.text
3103 else fstate
.maxrows - 2
3105 let calcfirst first active =
3108 let rows = active - first in
3109 if rows > maxrows then active - maxrows else first
3113 let active = m_active
+ incr in
3114 let active = bound
active 0 (source#getitemcount
- 1) in
3115 let first = calcfirst m_first
active in
3116 G.postRedisplay "outline navigate";
3117 coe {< m_active
= active; m_first
= first >}
3119 let navscroll first =
3121 let dist = m_active
- first in
3127 else first + maxrows
3130 G.postRedisplay "outline navscroll";
3131 coe {< m_first
= first; m_active
= active >}
3133 let ctrl = Wsi.withctrl mask
in
3135 match Wsi.kc2kt
key with
3136 | Ascii '
a'
when ctrl ->
3139 then (source#denarrow
; E.s)
3141 let pattern = source#renarrow
in
3142 if nonemptystr m_qsearch
3143 then (source#narrow m_qsearch
; m_qsearch
)
3147 settext (not m_autonarrow
) text;
3148 G.postRedisplay "toggle auto narrowing";
3149 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3151 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3153 G.postRedisplay "toggle auto narrowing";
3154 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3156 | Ascii '
n'
when ctrl ->
3157 source#narrow m_qsearch
;
3159 then source#add_narrow_pattern m_qsearch
;
3160 G.postRedisplay "outline ctrl-n";
3161 coe {< m_first
= 0; m_active
= 0 >}
3163 | Ascii 'S'
when ctrl ->
3164 let active = source#calcactive
(getanchor
()) in
3165 let first = firstof m_first
active in
3166 G.postRedisplay "outline ctrl-s";
3167 coe {< m_first
= first; m_active
= active >}
3169 | Ascii 'u'
when ctrl ->
3170 G.postRedisplay "outline ctrl-u";
3171 if m_autonarrow
&& nonemptystr m_qsearch
3173 ignore
(source#renarrow
);
3174 settext m_autonarrow
E.s;
3175 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3178 source#del_narrow_pattern
;
3179 let pattern = source#renarrow
in
3181 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3183 settext m_autonarrow
text;
3184 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3187 | Ascii '
l'
when ctrl ->
3188 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3189 G.postRedisplay "outline ctrl-l";
3190 coe {< m_first
= first >}
3192 | Ascii '
\t'
when m_autonarrow
->
3193 if nonemptystr m_qsearch
3195 G.postRedisplay "outline list view tab";
3196 source#add_narrow_pattern m_qsearch
;
3198 coe {< m_qsearch
= E.s >}
3202 | Escape
when m_autonarrow
->
3203 if nonemptystr m_qsearch
3204 then source#add_narrow_pattern m_qsearch
;
3207 | Enter
| KPenter
when m_autonarrow
->
3208 if nonemptystr m_qsearch
3209 then source#add_narrow_pattern m_qsearch
;
3212 | _ when m_autonarrow
&& (not
(Wsi.isspecialkey
key)) ->
3213 let pattern = m_qsearch ^ toutf8
key in
3214 G.postRedisplay "outlinelistview autonarrow add";
3215 source#narrow
pattern;
3216 settext true pattern;
3217 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3219 | key when m_autonarrow
&& key = Backspace
->
3220 if emptystr m_qsearch
3223 let pattern = withoutlastutf8 m_qsearch
in
3224 G.postRedisplay "outlinelistview autonarrow backspace";
3225 ignore
(source#renarrow
);
3226 source#narrow
pattern;
3227 settext true pattern;
3228 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3230 | Up
| KPup
when ctrl ->
3231 navscroll (max
0 (m_first
- 1))
3233 | Down
| KPdown
when ctrl ->
3234 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3236 | Up
| KPup
-> navigate ~
-1
3237 | Down
| KPdown
-> navigate 1
3238 | Prior
| KPprior
-> navigate ~
-(fstate
.maxrows)
3239 | Next
| KPnext
-> navigate fstate
.maxrows
3241 | Right
| KPright
->
3245 G.postRedisplay "outline ctrl right";
3246 {< m_pan
= m_pan
+ 1 >}
3248 else self#updownlevel
1
3256 G.postRedisplay "outline ctrl left";
3257 {< m_pan
= m_pan
- 1 >}
3259 else self#updownlevel ~
-1
3264 G.postRedisplay "outline home";
3265 coe {< m_first
= 0; m_active
= 0 >}
3268 let active = source#getitemcount
- 1 in
3269 let first = max
0 (active - fstate
.maxrows) in
3270 G.postRedisplay "outline end";
3271 coe {< m_active
= active; m_first
= first >}
3273 | Delete
|Escape
|Insert
|Enter
|KPdelete
|KPenter
|KPminus
3274 | KPplus
|Ascii
_|Code
_|Backspace
|Fn
_ -> super#
key key mask
3277 let genhistoutlines () =
3279 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3280 compare c2
.lastvisit c1
.lastvisit
)
3282 (fun ((path
, c, _, _, _, origin
) as hist
) ->
3283 let path = if nonemptystr origin
then origin
else path in
3284 let base = mbtoutf8
@@ Filename.basename
path in
3285 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3290 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3291 Config.save
leavebirdseye;
3292 state
.anchor <- anchor;
3293 state
.bookmarks
<- bookmarks
;
3294 state
.origin
<- origin
;
3297 let x0, y0, x1, y1 = conf
.trimfuzz
in
3298 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3299 reshape ~firsttime
:true state
.winw state
.winh
;
3300 opendoc path origin
;
3304 let makecheckers () =
3305 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3307 converted by Issac Trotts. July 25, 2002 *)
3308 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3309 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3310 let id = GlTex.gen_texture
() in
3311 GlTex.bind_texture ~target
:`texture_2d
id;
3312 GlPix.store
(`unpack_alignment
1);
3313 GlTex.image2d
image;
3314 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3315 [ `mag_filter `nearest
; `min_filter `nearest
];
3319 let setcheckers enabled
=
3320 match state
.checkerstexid
with
3322 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3324 | Some checkerstexid
->
3327 GlTex.delete_texture checkerstexid
;
3328 state
.checkerstexid
<- None
;
3332 let describe_location () =
3333 let fn = page_of_y state
.y in
3334 let ln = page_of_y
(state
.y + state
.winh
- 1) in
3335 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
3339 else (100. *. (float state
.y /. float maxy))
3343 Printf.sprintf
"page %d of %d [%.2f%%]"
3344 (fn+1) state
.pagecount
percent
3347 "pages %d-%d of %d [%.2f%%]"
3348 (fn+1) (ln+1) state
.pagecount
percent
3351 let setpresentationmode v
=
3352 let n = page_of_y state
.y in
3353 state
.anchor <- (n, 0.0, 1.0);
3354 conf
.presentation
<- v
;
3355 if conf
.fitmodel
= FitPage
3356 then reqlayout conf
.angle conf
.fitmodel
;
3360 let setbgcol (r
, g, b) =
3362 let r = r *. 255.0 |> truncate
3363 and g = g *. 255.0 |> truncate
3364 and b = b *. 255.0 |> truncate
in
3365 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3367 Wsi.setwinbgcol
col;
3371 let btos b = if b then UniSyms.radical else E.s in
3372 let showextended = ref false in
3373 let leave mode
_ = state
.mode
<- mode
in
3376 val mutable m_l
= []
3377 val mutable m_a
= E.a
3378 val mutable m_prev_uioh
= nouioh
3379 val mutable m_prev_mode
= View
3381 inherit lvsourcebase
3383 method reset prev_mode prev_uioh
=
3384 m_a
<- Array.of_list
(List.rev m_l
);
3386 m_prev_mode
<- prev_mode
;
3387 m_prev_uioh
<- prev_uioh
;
3389 method int name get
set =
3395 try set (int_of_string
s)
3397 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3401 let te = name ^
": ", E.s, None
, intentry, ondone, true in
3402 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3406 method int_with_suffix name get
set =
3408 (name
, `intws get
, 1,
3412 try set (int_of_string_with_suffix
s)
3414 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3419 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
3421 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3425 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3427 (name
, `
bool (btos, get
), offset
, Action
(
3434 method color name get
set =
3436 (name
, `
color get
, 1,
3439 let invalid = (nan
, nan
, nan
) in
3442 try color_of_string
s
3444 state
.text <- Printf.sprintf
"bad color `%s': %s"
3451 let te = name ^
": ", E.s, None
, textentry, ondone, true in
3452 state
.text <- color_to_string
(get
());
3453 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3457 method string name get
set =
3459 (name
, `
string get
, 1,
3462 let ondone s = set s in
3463 let te = name ^
": ", E.s, None
, textentry, ondone, true in
3464 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3468 method colorspace name get
set =
3470 (name
, `
string get
, 1,
3475 inherit lvsourcebase
3478 m_active
<- CSTE.to_int conf
.colorspace
;
3481 method getitemcount
=
3482 Array.length
CSTE.names
3485 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3486 ignore
(uioh
, first, pan
);
3487 if not cancel
then set active;
3489 method hasaction
_ = true
3493 let modehash = findkeyhash conf
"info" in
3494 coe (new listview ~zebra
:false ~helpmode
:false
3495 ~
source ~trusted
:true ~
modehash)
3498 method paxmark name get
set =
3500 (name
, `
string get
, 1,
3505 inherit lvsourcebase
3508 m_active
<- MTE.to_int conf
.paxmark
;
3511 method getitemcount
= Array.length
MTE.names
3512 method getitem
n = (MTE.names
.(n), 0)
3513 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3514 ignore
(uioh
, first, pan
);
3515 if not cancel
then set active;
3517 method hasaction
_ = true
3521 let modehash = findkeyhash conf
"info" in
3522 coe (new listview ~zebra
:false ~helpmode
:false
3523 ~
source ~trusted
:true ~
modehash)
3526 method fitmodel name get
set =
3528 (name
, `
string get
, 1,
3533 inherit lvsourcebase
3536 m_active
<- FMTE.to_int conf
.fitmodel
;
3539 method getitemcount
= Array.length
FMTE.names
3540 method getitem
n = (FMTE.names
.(n), 0)
3541 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3542 ignore
(uioh
, first, pan
);
3543 if not cancel
then set active;
3545 method hasaction
_ = true
3549 let modehash = findkeyhash conf
"info" in
3550 coe (new listview ~zebra
:false ~helpmode
:false
3551 ~
source ~trusted
:true ~
modehash)
3554 method caption
s offset
=
3555 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3557 method caption2
s f offset
=
3558 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3560 method getitemcount
= Array.length m_a
3563 let tostr = function
3564 | `
int f -> string_of_int
(f ())
3565 | `intws
f -> string_with_suffix_of_int
(f ())
3567 | `
color f -> color_to_string
(f ())
3568 | `
bool (btos, f) -> btos (f ())
3571 let name, t
, offset
, _ = m_a
.(n) in
3572 ((let s = tostr t
in
3574 then Printf.sprintf
"%s\t%s" name s
3578 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3583 match m_a
.(active) with
3584 | _, _, _, Action
f -> f uioh
3585 | _, _, _, Noaction
-> uioh
3596 method hasaction
n =
3598 | _, _, _, Action
_ -> true
3599 | _, _, _, Noaction
-> false
3601 initializer m_active
<- 1
3604 let rec fillsrc prevmode prevuioh
=
3605 let sep () = src#caption
E.s 0 in
3606 let colorp name get
set =
3608 (fun () -> color_to_string
(get
()))
3611 let c = color_of_string
v in
3615 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3618 let oldmode = state
.mode
in
3619 let birdseye = isbirdseye state
.mode
in
3621 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3623 src#
bool "presentation mode"
3624 (fun () -> conf
.presentation
)
3625 (fun v -> setpresentationmode v);
3627 src#
bool "ignore case in searches"
3628 (fun () -> conf
.icase
)
3629 (fun v -> conf
.icase
<- v);
3632 (fun () -> conf
.preload)
3633 (fun v -> conf
.preload <- v);
3635 src#
bool "highlight links"
3636 (fun () -> conf
.hlinks
)
3637 (fun v -> conf
.hlinks
<- v);
3639 src#
bool "under info"
3640 (fun () -> conf
.underinfo
)
3641 (fun v -> conf
.underinfo
<- v);
3643 src#
bool "persistent bookmarks"
3644 (fun () -> conf
.savebmarks
)
3645 (fun v -> conf
.savebmarks
<- v);
3647 src#fitmodel
"fit model"
3648 (fun () -> FMTE.to_string conf
.fitmodel
)
3649 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3651 src#
bool "trim margins"
3652 (fun () -> conf
.trimmargins
)
3653 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3655 src#
bool "persistent location"
3656 (fun () -> conf
.jumpback
)
3657 (fun v -> conf
.jumpback
<- v);
3660 src#
int "inter-page space"
3661 (fun () -> conf
.interpagespace
)
3663 conf
.interpagespace
<- n;
3664 docolumns conf
.columns
;
3666 match state
.layout with
3671 state
.maxy <- calcheight
();
3672 let y = getpagey
pageno in
3673 gotoxy state
.x (y + py)
3677 (fun () -> conf
.pagebias
)
3678 (fun v -> conf
.pagebias
<- v);
3680 src#
int "scroll step"
3681 (fun () -> conf
.scrollstep
)
3682 (fun n -> conf
.scrollstep
<- n);
3684 src#
int "horizontal scroll step"
3685 (fun () -> conf
.hscrollstep
)
3686 (fun v -> conf
.hscrollstep
<- v);
3688 src#
int "auto scroll step"
3690 match state
.autoscroll
with
3692 | _ -> conf
.autoscrollstep
)
3694 let n = boundastep state
.winh
n in
3695 if state
.autoscroll
<> None
3696 then state
.autoscroll
<- Some
n;
3697 conf
.autoscrollstep
<- n);
3700 (fun () -> truncate
(conf
.zoom *. 100.))
3701 (fun v -> pivotzoom ((float v) /. 100.));
3704 (fun () -> conf
.angle
)
3705 (fun v -> reqlayout v conf
.fitmodel
);
3707 src#
int "scroll bar width"
3708 (fun () -> conf
.scrollbw
)
3711 reshape state
.winw state
.winh
;
3714 src#
int "scroll handle height"
3715 (fun () -> conf
.scrollh
)
3716 (fun v -> conf
.scrollh
<- v;);
3718 src#
int "thumbnail width"
3719 (fun () -> conf
.thumbw
)
3721 conf
.thumbw
<- min
4096 v;
3724 leavebirdseye beye
false;
3731 let mode = state
.mode in
3732 src#
string "columns"
3734 match conf
.columns
with
3736 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3737 | Csplit
(count
, _) -> "-" ^ string_of_int count
3740 let n, a, b = multicolumns_of_string
v in
3741 setcolumns mode n a b);
3744 src#caption
"Pixmap cache" 0;
3745 src#int_with_suffix
"size (advisory)"
3746 (fun () -> conf
.memlimit
)
3747 (fun v -> conf
.memlimit
<- v);
3751 Printf.sprintf
"%s bytes, %d tiles"
3752 (string_with_suffix_of_int state
.memused
)
3753 (Hashtbl.length state
.tilemap
)) 1;
3756 src#caption
"Layout" 0;
3757 src#caption2
"Dimension"
3759 Printf.sprintf
"%dx%d (virtual %dx%d)"
3760 state
.winw state
.winh
3765 src#caption2
"Position" (fun () ->
3766 Printf.sprintf
"%dx%d" state
.x state
.y
3769 src#caption2
"Position" (fun () -> describe_location ()) 1
3773 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3774 "Save these parameters as global defaults at exit"
3775 (fun () -> conf
.bedefault
)
3776 (fun v -> conf
.bedefault
<- v)
3780 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3781 src#
bool ~offset
:0 ~
btos "Extended parameters"
3782 (fun () -> !showextended)
3783 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3787 (fun () -> conf
.checkers
)
3788 (fun v -> conf
.checkers
<- v; setcheckers v);
3789 src#
bool "update cursor"
3790 (fun () -> conf
.updatecurs
)
3791 (fun v -> conf
.updatecurs
<- v);
3792 src#
bool "scroll-bar on the left"
3793 (fun () -> conf
.leftscroll
)
3794 (fun v -> conf
.leftscroll
<- v);
3796 (fun () -> conf
.verbose
)
3797 (fun v -> conf
.verbose
<- v);
3798 src#
bool "invert colors"
3799 (fun () -> conf
.invert
)
3800 (fun v -> conf
.invert
<- v);
3802 (fun () -> conf
.maxhfit
)
3803 (fun v -> conf
.maxhfit
<- v);
3805 (fun () -> conf
.pax
!= None
)
3808 then conf
.pax
<- Some
(ref (now
(), 0, 0))
3809 else conf
.pax
<- None
);
3810 src#
string "uri launcher"
3811 (fun () -> conf
.urilauncher
)
3812 (fun v -> conf
.urilauncher
<- v);
3813 src#
string "path launcher"
3814 (fun () -> conf
.pathlauncher
)
3815 (fun v -> conf
.pathlauncher
<- v);
3816 src#
string "tile size"
3817 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3820 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3821 conf
.tilew
<- max
64 w;
3822 conf
.tileh
<- max
64 h;
3825 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3828 src#
int "texture count"
3829 (fun () -> conf
.texcount
)
3832 then conf
.texcount
<- v
3833 else impmsg "failed to set texture count please retry later"
3835 src#
int "slice height"
3836 (fun () -> conf
.sliceheight
)
3838 conf
.sliceheight
<- v;
3839 wcmd "sliceh %d" conf
.sliceheight
;
3841 src#
int "anti-aliasing level"
3842 (fun () -> conf
.aalevel
)
3844 conf
.aalevel
<- bound
v 0 8;
3845 state
.anchor <- getanchor
();
3846 opendoc state
.path state
.password;
3848 src#
string "page scroll scaling factor"
3849 (fun () -> string_of_float conf
.pgscale)
3852 let s = float_of_string
v in
3855 state
.text <- Printf.sprintf
3856 "bad page scroll scaling factor `%s': %s" v
3860 src#
int "ui font size"
3861 (fun () -> fstate
.fontsize
)
3862 (fun v -> setfontsize (bound
v 5 100));
3863 src#
int "hint font size"
3864 (fun () -> conf
.hfsize
)
3865 (fun v -> conf
.hfsize
<- bound
v 5 100);
3866 colorp "background color"
3867 (fun () -> conf
.bgcolor
)
3868 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3869 src#
bool "crop hack"
3870 (fun () -> conf
.crophack
)
3871 (fun v -> conf
.crophack
<- v);
3872 src#
string "trim fuzz"
3873 (fun () -> irect_to_string conf
.trimfuzz
)
3876 conf
.trimfuzz
<- irect_of_string
v;
3878 then settrim true conf
.trimfuzz
;
3880 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3883 src#
string "throttle"
3885 match conf
.maxwait
with
3886 | None
-> "show place holder if page is not ready"
3889 then "wait for page to fully render"
3891 "wait " ^ string_of_float
time
3892 ^
" seconds before showing placeholder"
3896 let f = float_of_string
v in
3898 then conf
.maxwait
<- None
3899 else conf
.maxwait
<- Some
f
3901 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3904 src#
string "ghyll scroll"
3906 match conf
.ghyllscroll
with
3908 | Some nab
-> ghyllscroll_to_string nab
3911 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3914 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3916 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3919 src#
string "selection command"
3920 (fun () -> conf
.selcmd
)
3921 (fun v -> conf
.selcmd
<- v);
3922 src#
string "synctex command"
3923 (fun () -> conf
.stcmd
)
3924 (fun v -> conf
.stcmd
<- v);
3925 src#
string "pax command"
3926 (fun () -> conf
.paxcmd
)
3927 (fun v -> conf
.paxcmd
<- v);
3928 src#
string "ask password command"
3929 (fun () -> conf
.passcmd)
3930 (fun v -> conf
.passcmd <- v);
3931 src#
string "save path command"
3932 (fun () -> conf
.savecmd
)
3933 (fun v -> conf
.savecmd
<- v);
3934 src#colorspace
"color space"
3935 (fun () -> CSTE.to_string conf
.colorspace
)
3937 conf
.colorspace
<- CSTE.of_int
v;
3941 src#paxmark
"pax mark method"
3942 (fun () -> MTE.to_string conf
.paxmark
)
3943 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3944 if bousable
() && !opengl_has_pbo
3947 (fun () -> conf
.usepbo
)
3948 (fun v -> conf
.usepbo
<- v);
3949 src#
bool "mouse wheel scrolls pages"
3950 (fun () -> conf
.wheelbypage
)
3951 (fun v -> conf
.wheelbypage
<- v);
3952 src#
bool "open remote links in a new instance"
3953 (fun () -> conf
.riani
)
3954 (fun v -> conf
.riani
<- v);
3955 src#
bool "edit annotations inline"
3956 (fun () -> conf
.annotinline
)
3957 (fun v -> conf
.annotinline
<- v);
3958 src#
bool "coarse positioning in presentation mode"
3959 (fun () -> conf
.coarseprespos
)
3960 (fun v -> conf
.coarseprespos
<- v);
3961 src#
bool "use document CSS"
3962 (fun () -> conf
.usedoccss
)
3964 conf
.usedoccss
<- v;
3965 state
.anchor <- getanchor
();
3966 opendoc state
.path state
.password;
3971 src#caption
"Document" 0;
3972 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3973 src#caption2
"Pages"
3974 (fun () -> string_of_int state
.pagecount
) 1;
3975 src#caption2
"Dimensions"
3976 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3977 if nonemptystr conf
.css
3978 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3982 src#caption
"Trimmed margins" 0;
3983 src#caption2
"Dimensions"
3984 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3988 src#caption
"OpenGL" 0;
3989 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3990 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3993 src#caption
"Location" 0;
3994 if nonemptystr state
.origin
3995 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3996 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3998 src#reset prevmode prevuioh
;
4003 let prevmode = state
.mode
4004 and prevuioh
= state
.uioh in
4005 fillsrc prevmode prevuioh
;
4006 let source = (src :> lvsource
) in
4007 let modehash = findkeyhash conf
"info" in
4010 inherit listview ~zebra
:false ~helpmode
:false
4011 ~
source ~trusted
:true ~
modehash as super
4012 val mutable m_prevmemused
= 0
4013 method! infochanged
= function
4015 if m_prevmemused
!= state
.memused
4017 m_prevmemused
<- state
.memused
;
4018 G.postRedisplay "memusedchanged";
4020 | Pdim
-> G.postRedisplay "pdimchanged"
4021 | Docinfo
-> fillsrc prevmode prevuioh
4023 method! key key mask
=
4024 if not
(Wsi.withctrl mask
)
4027 begin [@warning
"-4"]
4028 match Wsi.kc2kt
key with
4029 | Left
| KPleft
-> coe (self#updownlevel ~
-1)
4030 | Right
| KPright
-> coe (self#updownlevel
1)
4031 | _ -> super#
key key mask
4033 else super#
key key mask
4035 G.postRedisplay "info";
4041 inherit lvsourcebase
4042 method getitemcount
= Array.length state
.help
4044 let s, l, _ = state
.help
.(n) in
4047 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4051 match state
.help
.(active) with
4052 | _, _, Action
f -> Some
(f uioh)
4053 | _, _, Noaction
-> Some
uioh
4062 method hasaction
n =
4063 match state
.help
.(n) with
4064 | _, _, Action
_ -> true
4065 | _, _, Noaction
-> false
4071 let modehash = findkeyhash conf
"help" in
4073 state
.uioh <- coe (new listview
4074 ~zebra
:false ~helpmode
:true
4075 ~
source ~trusted
:true ~
modehash);
4076 G.postRedisplay "help";
4082 inherit lvsourcebase
4083 val mutable m_items
= E.a
4085 method getitemcount
= 1 + Array.length m_items
4090 else m_items
.(n-1), 0
4092 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4097 then Buffer.clear state
.errmsgs
;
4104 method hasaction
n =
4108 state
.newerrmsgs
<- false;
4109 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4110 m_items
<- Array.of_list
l
4119 let source = (msgsource :> lvsource
) in
4120 let modehash = findkeyhash conf
"listview" in
4123 inherit listview ~zebra
:false ~helpmode
:false
4124 ~
source ~trusted
:false ~
modehash as super
4127 then msgsource#reset
;
4130 G.postRedisplay "msgs";
4134 let editor = getenvwithdef
"EDITOR" E.s in
4138 let tmppath = Filename.temp_file
"llpp" "note" in
4141 let oc = open_out
tmppath in
4145 let execstr = editor ^
" " ^
tmppath in
4147 match spawn
execstr [] with
4149 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4152 match Unix.waitpid
[] pid
with
4154 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4158 | Unix.WEXITED
0 -> filecontents
tmppath
4160 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4162 | Unix.WSIGNALED
n ->
4163 impmsg "editor process(%s) was killed by signal %d" execstr n;
4165 | Unix.WSTOPPED
n ->
4166 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4169 match Unix.unlink
tmppath with
4171 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4176 let enterannotmode opaque slinkindex
=
4179 inherit lvsourcebase
4180 val mutable m_text
= E.s
4181 val mutable m_items
= E.a
4183 method getitemcount
= Array.length m_items
4186 let label, _func
= m_items
.(n) in
4189 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4190 ignore
(uioh, first, pan
);
4193 let _label, func
= m_items
.(active) in
4198 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4201 let rec split accu b i
=
4203 if p = String.length
s
4204 then (String.sub s b (p-b), unit) :: accu
4206 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4208 let ss = if i
= 0 then E.s else String.sub s b i
in
4209 split ((ss, unit)::accu) (p+1) 0
4214 wcmd "freepage %s" (~
> opaque);
4216 Hashtbl.fold (fun key opaque'
accu ->
4217 if opaque'
= opaque'
4218 then key :: accu else accu) state
.pagemap
[]
4220 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4222 gotoxy state
.x state
.y
4225 delannot
opaque slinkindex
;
4228 let edit inline
() =
4233 modannot
opaque slinkindex
s;
4239 let mode = state
.mode in
4242 ("annotation: ", m_text
, None
, textentry, update, true),
4243 fun _ -> state
.mode <- mode);
4247 let s = getusertext m_text
in
4252 ( "[Copy]", fun () -> selstring m_text
)
4253 :: ("[Delete]", dele)
4254 :: ("[Edit]", edit conf
.annotinline
)
4256 :: split [] 0 0 |> List.rev
|> Array.of_list
4263 let s = getannotcontents
opaque slinkindex
in
4266 let source = (msgsource :> lvsource
) in
4267 let modehash = findkeyhash conf
"listview" in
4268 state
.uioh <- coe (object
4269 inherit listview ~zebra
:false ~helpmode
:false
4270 ~
source ~trusted
:false ~
modehash
4272 G.postRedisplay "enterannotmode";
4275 let gotoremote spec
=
4276 let filename, dest
= splitatchar spec '#'
in
4277 let getpath filename =
4279 if nonemptystr
filename
4281 if Filename.is_relative
filename
4283 let dir = Filename.dirname state
.path in
4285 if Filename.is_implicit
dir
4286 then Filename.concat
(Sys.getcwd
()) dir
4289 Filename.concat
dir filename
4293 if Sys.file_exists
path
4297 let path = getpath filename in
4301 let cmd = Lazy.force_val lcmd
in
4302 match spawn
cmd with
4304 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4306 let anchor = getanchor
() in
4307 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4308 state
.origin
<- E.s;
4309 state
.ranchors
<- ranchor :: state
.ranchors
;
4312 if substratis spec
0 "page="
4314 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4316 state
.anchor <- (pageno, 0.0, 0.0);
4317 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4319 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4321 state
.nameddest
<- dest
;
4322 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4326 let gotounder = function
4327 | Ulinkuri
s when isexternallink
s ->
4328 if substratis
s 0 "file://"
4329 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4332 let pageno, x, y = uritolocation
s in
4334 gotopagexy !wtmode pageno x y
4335 | Utext
_ | Unone
-> ()
4336 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4339 let gotooutline (_, _, kind
) =
4343 let (pageno, y, _) = anchor in
4345 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4349 | Ouri
uri -> gotounder (Ulinkuri
uri)
4350 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4351 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4352 | Ohistory hist
-> gotohist hist
4353 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4356 class outlinesoucebase fetchoutlines
= object (self)
4357 inherit lvsourcebase
4358 val mutable m_items
= E.a
4359 val mutable m_minfo
= E.a
4360 val mutable m_orig_items
= E.a
4361 val mutable m_orig_minfo
= E.a
4362 val mutable m_narrow_patterns
= []
4363 val mutable m_gen
= -1
4365 method getitemcount
= Array.length m_items
4368 let s, n, _ = m_items
.(n) in
4371 method exit ~
(uioh:uioh) ~cancel ~
active ~
(first:int) ~pan
: uioh option =
4372 ignore
(uioh, first);
4374 if m_narrow_patterns
= []
4375 then m_orig_items
, m_orig_minfo
4376 else m_items
, m_minfo
4383 gotooutline m_items
.(active);
4391 method hasaction
(_:int) = true
4394 if Array.length m_items
!= Array.length m_orig_items
4397 match m_narrow_patterns
with
4399 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4401 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4405 match m_narrow_patterns
with
4408 | head
:: _ -> UniSyms.ellipsis ^ head
4410 method narrow
pattern =
4411 match Str.regexp_case_fold
pattern with
4414 let rec loop accu minfo n =
4417 m_items
<- Array.of_list
accu;
4418 m_minfo
<- Array.of_list
minfo;
4421 let (s, _, _) as o = m_items
.(n) in
4423 match Str.search_forward re
s 0 with
4424 | exception Not_found
-> accu, minfo
4425 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4427 loop accu minfo (n-1)
4429 loop [] [] (Array.length m_items
- 1)
4431 method! getminfo
= m_minfo
4434 m_orig_items
<- fetchoutlines
();
4435 m_minfo
<- m_orig_minfo
;
4436 m_items
<- m_orig_items
4438 method add_narrow_pattern
pattern =
4439 m_narrow_patterns
<- pattern :: m_narrow_patterns
4441 method del_narrow_pattern
=
4442 match m_narrow_patterns
with
4443 | _ :: rest
-> m_narrow_patterns
<- rest
4448 match m_narrow_patterns
with
4449 | pattern :: [] -> self#narrow
pattern; pattern
4451 List.fold_left
(fun accu pattern ->
4452 self#narrow
pattern;
4453 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4455 method calcactive
(_:anchor) = 0
4457 method reset
anchor items =
4458 if state
.gen
!= m_gen
4460 m_orig_items
<- items;
4462 m_narrow_patterns
<- [];
4464 m_orig_minfo
<- E.a;
4468 if items != m_orig_items
4470 m_orig_items
<- items;
4471 if m_narrow_patterns
== []
4472 then m_items
<- items;
4475 let active = self#calcactive
anchor in
4477 m_first
<- firstof m_first
active
4481 let outlinesource fetchoutlines
=
4483 inherit outlinesoucebase fetchoutlines
4484 method! calcactive
anchor =
4485 let rely = getanchory anchor in
4486 let rec loop n best bestd
=
4487 if n = Array.length m_items
4490 let _, _, kind
= m_items
.(n) in
4493 let orely = getanchory anchor in
4494 let d = abs
(orely - rely) in
4497 else loop (n+1) best bestd
4498 | Onone
| Oremote
_ | Olaunch
_
4499 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4500 loop (n+1) best bestd
4506 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4507 let mkselector sourcetype
=
4508 let fetchoutlines () =
4509 match sourcetype
with
4510 | `bookmarks
-> Array.of_list state
.bookmarks
4511 | `outlines
-> state
.outlines
4512 | `history
-> genhistoutlines ()
4515 if sourcetype
= `history
4516 then new outlinesoucebase
fetchoutlines
4517 else outlinesource fetchoutlines
4520 let outlines = fetchoutlines () in
4521 if Array.length
outlines = 0
4523 showtext ' ' errmsg
;
4527 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4528 let anchor = getanchor
() in
4529 source#reset
anchor outlines;
4530 state
.text <- source#greetmsg
;
4532 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4533 G.postRedisplay "enter selector";
4536 let mkenter sourcetype errmsg
=
4537 let enter = mkselector sourcetype
in
4538 fun () -> enter errmsg
4540 mkenter `
outlines "document has no outline"
4541 , mkenter `bookmarks
"document has no bookmarks (yet)"
4542 , mkenter `history
"history is empty"
4545 let quickbookmark ?title
() =
4546 match state
.layout with
4552 let tm = Unix.localtime
(now
()) in
4554 "Quick (page %d) (bookmarked at %02d/%02d/%d %02d:%02d)"
4558 (tm.Unix.tm_year
+ 1900)
4561 | Some
title -> title
4563 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4566 let setautoscrollspeed step goingdown
=
4567 let incr = max
1 ((abs step
) / 2) in
4568 let incr = if goingdown
then incr else -incr in
4569 let astep = boundastep state
.winh
(step
+ incr) in
4570 state
.autoscroll
<- Some
astep;
4574 match conf
.columns
with
4576 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4579 let panbound x = bound
x (-state
.w) state
.winw
;;
4581 let existsinrow pageno (columns
, coverA
, coverB
) p =
4582 let last = ((pageno - coverA
) mod columns
) + columns
in
4583 let rec any = function
4586 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4590 then (if l.pageno = last then false else any rest
)
4598 match state
.layout with
4600 let pageno = page_of_y state
.y in
4601 gotoghyll (getpagey
(pageno+1))
4603 match conf
.columns
with
4605 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4607 let y = clamp (pgscale state
.winh
) in
4610 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4611 gotoghyll (getpagey
pageno)
4612 | Cmulti
((c, _, _) as cl
, _) ->
4613 if conf
.presentation
4614 && (existsinrow l.pageno cl
4615 (fun l -> l.pageh
> l.pagey + l.pagevh))
4617 let y = clamp (pgscale state
.winh
) in
4620 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4621 gotoghyll (getpagey
pageno)
4623 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4625 let pagey, pageh
= getpageyh
l.pageno in
4626 let pagey = pagey + pageh
* l.pagecol
in
4627 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4628 gotoghyll (pagey + pageh
+ ips)
4632 match state
.layout with
4634 let pageno = page_of_y state
.y in
4635 gotoghyll (getpagey
(pageno-1))
4637 match conf
.columns
with
4639 if conf
.presentation
&& l.pagey != 0
4641 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4643 let pageno = max
0 (l.pageno-1) in
4644 gotoghyll (getpagey
pageno)
4645 | Cmulti
((c, _, coverB
) as cl
, _) ->
4646 if conf
.presentation
&&
4647 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4649 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4652 if l.pageno = state
.pagecount
- coverB
4656 let pageno = max
0 (l.pageno-decr) in
4657 gotoghyll (getpagey
pageno)
4665 let pageno = max
0 (l.pageno-1) in
4666 let pagey, pageh
= getpageyh
pageno in
4669 let pagey, pageh
= getpageyh
l.pageno in
4670 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4676 if emptystr conf
.savecmd
4677 then error
"don't know where to save modified document"
4679 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4682 (fun s -> error
"failed to obtain path to the saved copy: %s" s)
4687 let tmp = path ^
".tmp" in
4689 Unix.rename
tmp path;
4692 let viewkeyboard key mask
=
4694 let mode = state
.mode in
4695 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4698 G.postRedisplay "view:enttext"
4700 let ctrl = Wsi.withctrl mask
in
4701 let key = Wsi.keypadtodigitkey
key in
4703 match Wsi.kc2kt
key with
4704 | Ascii 'Q'
-> exit
0
4707 if hasunsavedchanges
()
4711 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4714 match state
.lnava
with
4715 | None
-> LinkNav
(Ltgendir
0)
4716 | Some
pn -> LinkNav
(Ltexact
pn)
4718 gotoxy state
.x state
.y;
4720 else impmsg "keyboard link navigation does not work under rotation"
4722 | Escape
| Ascii 'q'
->
4723 begin match state
.mstate
with
4726 G.postRedisplay "kill rect";
4729 | Mscrolly
| Mscrollx
4732 begin match state
.mode with
4735 | Ltexact pl
-> state
.lnava
<- Some pl
4736 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4739 G.postRedisplay "esc leave linknav"
4740 | Birdseye
_ | Textentry
_ | View
->
4741 match state
.ranchors
with
4743 | (path, password, anchor, origin
) :: rest
->
4744 state
.ranchors
<- rest
;
4745 state
.anchor <- anchor;
4746 state
.origin
<- origin
;
4747 state
.nameddest
<- E.s;
4748 opendoc path password
4753 gotoghyll (getnav ~
-1)
4764 Hashtbl.iter
(fun _ opaque ->
4766 Hashtbl.clear state
.prects
) state
.pagemap
;
4767 G.postRedisplay "dehighlight";
4769 | (Ascii '
/'
| Ascii '?'
) as pv
->
4770 let ondone isforw
s =
4771 cbput state
.hists
.pat
s;
4772 state
.searchpattern
<- s;
4775 let s = String.make
1 (Char.chr
key) in
4776 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4777 textentry, ondone (pv
= Ascii '
/'
), true)
4779 | Ascii '
+'
| KPplus
| Ascii '
='
when ctrl ->
4780 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4781 pivotzoom (conf
.zoom +. incr)
4783 | Ascii '
+'
| KPplus
->
4786 try int_of_string
s with exn
->
4787 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4793 state
.text <- "page bias is now " ^ string_of_int
n;
4796 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
4798 | Ascii '
-'
| KPminus
when ctrl ->
4799 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4800 pivotzoom (max
0.01 (conf
.zoom -. decr))
4802 | Ascii '
-'
| KPminus
->
4803 let ondone msg
= state
.text <- msg
in
4805 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4806 optentry state
.mode, ondone, true
4809 | Ascii '
0'
when ctrl ->
4811 then gotoxy 0 state
.y
4814 | Ascii
('
1'
|'
2'
as c)
4815 when ctrl && conf
.fitmodel
!= FitPage
->
4817 match conf
.columns
with
4818 | Csingle
_ | Cmulti
_ -> 1
4819 | Csplit
(n, _) -> n
4821 let h = state
.winh
-
4822 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4824 let zoom = zoomforh state
.winw
h 0 cols in
4825 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4828 | Ascii '
3'
when ctrl ->
4830 match conf
.fitmodel
with
4831 | FitWidth
-> FitProportional
4832 | FitProportional
-> FitPage
4833 | FitPage
-> FitWidth
4835 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4836 reqlayout conf
.angle
fm
4838 | Ascii '
4'
when ctrl ->
4839 let zoom = getmaxw
() /. float state
.winw
in
4840 if zoom > 0.0 then setzoom zoom
4845 | Ascii '
9'
when ctrl ->
4852 try int_of_string
s with exn
->
4853 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4859 cbput state
.hists
.pag
(string_of_int
n);
4860 gotopage1 (n + conf
.pagebias
- 1) 0;
4863 let pageentry text key =
4864 match Char.unsafe_chr
key with
4865 | '
g'
-> TEdone
text
4866 | _ -> intentry text key
4868 let text = String.make
1 (Char.chr
key) in
4869 enttext (":", text, Some
(onhist state
.hists
.pag
),
4870 pageentry, ondone, true)
4873 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4874 G.postRedisplay "toggle scrollbar";
4877 state
.bzoom
<- not state
.bzoom
;
4879 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4882 conf
.hlinks
<- not conf
.hlinks
;
4883 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4884 G.postRedisplay "toggle highlightlinks";
4887 if conf
.angle
mod 360 = 0
4889 state
.glinks
<- true;
4890 let mode = state
.mode in
4893 (":", E.s, None
, linknentry, linknact gotounder, false),
4895 state
.glinks
<- false;
4899 G.postRedisplay "view:linkent(F)"
4901 else impmsg "hint mode does not work under rotation"
4904 state
.glinks
<- true;
4905 let mode = state
.mode in
4909 ":", E.s, None
, linknentry, linknact (fun under ->
4910 selstring (undertext under);
4914 state
.glinks
<- false;
4918 G.postRedisplay "view:linkent"
4921 begin match state
.autoscroll
with
4923 conf
.autoscrollstep
<- step
;
4924 state
.autoscroll
<- None
4926 if conf
.autoscrollstep
= 0
4927 then state
.autoscroll
<- Some
1
4928 else state
.autoscroll
<- Some conf
.autoscrollstep
4931 | Ascii '
p'
when ctrl ->
4932 launchpath () (* XXX where do error messages go? *)
4935 setpresentationmode (not conf
.presentation
);
4936 showtext ' '
("presentation mode " ^
4937 if conf
.presentation
then "on" else "off");
4940 if List.mem
Wsi.Fullscreen state
.winstate
4941 then Wsi.reshape conf
.cwinw conf
.cwinh
4942 else Wsi.fullscreen
()
4944 | Ascii
('
p'
|'N'
) ->
4945 search state
.searchpattern
false
4947 | Ascii '
n'
| Fn
3 ->
4948 search state
.searchpattern
true
4951 begin match state
.layout with
4954 gotoghyll (getpagey
l.pageno)
4960 | Delete
| KPdelete
->
4964 showtext ' '
(describe_location ());
4967 begin match state
.layout with
4970 Wsi.reshape l.pagew
l.pageh
;
4975 enterbookmarkmode
()
4977 | Ascii '
h'
| Fn
1 ->
4983 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4988 match state
.layout with
4993 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4996 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
5000 showtext ' '
"Quick bookmark added";
5003 begin match state
.layout with
5005 let rect = getpdimrect
l.pagedimno
in
5009 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5010 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5012 (truncate
(rect.(1) -. rect.(0)),
5013 truncate
(rect.(3) -. rect.(0)))
5015 let w = truncate
((float w)*.conf
.zoom)
5016 and h = truncate
((float h)*.conf
.zoom) in
5019 state
.anchor <- getanchor
();
5020 Wsi.reshape w (h + conf
.interpagespace
)
5022 G.postRedisplay "z";
5027 | Ascii '
x'
-> state
.roam
()
5029 | Ascii
('
<'
|'
>'
as c) ->
5031 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5033 | Ascii
('
['
|'
]'
as c) ->
5035 bound
(conf
.colorscale
+. (if c = '
>'
then 0.1 else -0.1)) 0.0 1.0;
5036 G.postRedisplay "brightness";
5038 | Ascii '
c'
when state
.mode = View
->
5043 let m = (state
.winw
- state
.w) / 2 in
5044 gotoxy_and_clear_text m state
.y
5048 match state
.prevcolumns
with
5049 | None
-> (1, 0, 0), 1.0
5050 | Some
(columns
, z
) ->
5053 | Csplit
(c, _) -> -c, 0, 0
5054 | Cmulti
((c, a, b), _) -> c, a, b
5055 | Csingle
_ -> 1, 0, 0
5059 setcolumns View
c a b;
5062 | Down
| Up
when ctrl && Wsi.withshift mask
->
5063 let zoom, x = state
.prevzoom
in
5067 | Ascii 'k'
| Up
| KPup
->
5068 begin match state
.autoscroll
with
5070 begin match state
.mode with
5071 | Birdseye beye
-> upbirdseye 1 beye
5072 | Textentry
_ | View
| LinkNav
_ ->
5074 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5076 if not
(Wsi.withshift mask
) && conf
.presentation
5078 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5082 setautoscrollspeed n false
5085 | Ascii 'j'
| Down
| KPdown
->
5086 begin match state
.autoscroll
with
5088 begin match state
.mode with
5089 | Birdseye beye
-> downbirdseye 1 beye
5090 | Textentry
_ | View
| LinkNav
_ ->
5092 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5094 if not
(Wsi.withshift mask
) && conf
.presentation
5096 else gotoghyll1 true (clamp (conf
.scrollstep
))
5100 setautoscrollspeed n true
5103 | Left
| Right
| KPleft
| KPright
when not
(Wsi.withalt mask
) ->
5109 else conf
.hscrollstep
5112 let pv = Wsi.kc2kt
key in
5113 if pv = Keys.Left
|| pv = Keys.KPleft
then dx else -dx
5115 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5118 G.postRedisplay "left/right"
5121 | Prior
| KPprior
->
5125 match state
.layout with
5127 | l :: _ -> state
.y - l.pagey
5129 clamp (pgscale (-state
.winh
))
5137 match List.rev state
.layout with
5139 | l :: _ -> getpagey
l.pageno
5141 clamp (pgscale state
.winh
)
5145 | Ascii '
g'
| Home
| KPhome
->
5148 | Ascii 'G'
| End
| KPend
->
5150 gotoghyll (clamp state
.maxy)
5152 | Right
| KPright
when Wsi.withalt mask
->
5153 gotoghyll (getnav 1)
5154 | Left
| KPleft
when Wsi.withalt mask
->
5155 gotoghyll (getnav ~
-1)
5160 | Ascii '
v'
when conf
.debug
->
5163 match getopaque l.pageno with
5166 let x0, y0, x1, y1 = pagebbox
opaque in
5167 let rect = (float x0, float y0,
5170 float x0, float y1) in
5172 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5173 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5175 G.postRedisplay "v";
5178 let mode = state
.mode in
5179 let cmd = ref E.s in
5180 let onleave = function
5181 | Cancel
-> state
.mode <- mode
5184 match getopaque l.pageno with
5185 | Some
opaque -> pipesel opaque !cmd
5186 | None
-> ()) state
.layout;
5190 cbput state
.hists
.sel
s;
5194 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
5196 G.postRedisplay "|";
5197 state
.mode <- Textentry
(te, onleave);
5199 | (Ascii
_|Fn
_|Enter
|KPenter
|KPleft
|KPright
|Left
|Right
|Code
_) ->
5200 vlog "huh? %s" (Wsi.keyname
key)
5203 let linknavkeyboard key mask
linknav =
5204 let pv = Wsi.kc2kt
key in
5205 let getpage pageno =
5206 let rec loop = function
5208 | l :: _ when l.pageno = pageno -> Some
l
5209 | _ :: rest
-> loop rest
5210 in loop state
.layout
5212 let doexact (pageno, n) =
5213 match getopaque pageno, getpage pageno with
5214 | Some
opaque, Some
l ->
5215 if pv = Keys.Enter
|| pv = Keys.KPenter
5217 let under = getlink
opaque n in
5218 G.postRedisplay "link gotounder";
5226 Some
(findlink
opaque LDfirst
), -1
5229 Some
(findlink
opaque LDlast
), 1
5232 Some
(findlink
opaque (LDleft
n)), -1
5235 Some
(findlink
opaque (LDright
n)), 1
5238 Some
(findlink
opaque (LDup
n)), -1
5241 Some
(findlink
opaque (LDdown
n)), 1
5243 | Delete
|Escape
|Insert
|Enter
|KPdelete
|KPdown
|KPend
|KPenter
5244 | KPhome
|KPleft
|KPminus
|KPnext
|KPplus
|KPprior
|KPright
|KPup
5245 | Next
|Prior
|Ascii
_|Code
_|Fn
_|Backspace
-> None
, 0
5248 begin match findpwl
l.pageno dir with
5252 state
.mode <- LinkNav
(Ltgendir
dir);
5253 let y, h = getpageyh
pageno in
5256 then y + h - state
.winh
5261 begin match getopaque pageno, getpage pageno with
5262 | Some
opaque, Some
_ ->
5264 let ld = if dir > 0 then LDfirst
else LDlast
in
5267 begin match link with
5269 showlinktype (getlink
opaque m);
5270 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5271 G.postRedisplay "linknav jpage";
5272 | Lnotfound
-> notfound dir
5278 begin match opt with
5279 | Some Lnotfound
-> pwl l dir;
5280 | Some
(Lfound
m) ->
5284 let _, y0, _, y1 = getlinkrect
opaque m in
5286 then gotopage1 l.pageno y0
5288 let d = fstate
.fontsize
+ 1 in
5289 if y1 - l.pagey > l.pagevh - d
5290 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5291 else G.postRedisplay "linknav";
5293 showlinktype (getlink
opaque m);
5294 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5297 | None
-> viewkeyboard key mask
5299 | _ -> viewkeyboard key mask
5303 begin match linknav with
5304 | Ltexact pa
-> state
.lnava
<- Some pa
5305 | Ltgendir
_ | Ltnotready
_ -> ()
5308 G.postRedisplay "leave linknav"
5312 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5313 | Ltexact exact
-> doexact exact
5316 let keyboard key mask
=
5317 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5318 then wcmd "interrupt"
5319 else state
.uioh <- state
.uioh#
key key mask
5322 let birdseyekeyboard key mask
5323 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5325 match conf
.columns
with
5327 | Cmulti
((c, _, _), _) -> c
5328 | Csplit
_ -> failwith
"bird's eye split mode"
5330 let pgh layout = List.fold_left
5331 (fun m l -> max
l.pageh
m) state
.winh
layout in
5333 match Wsi.kc2kt
key with
5334 | Ascii '
l'
when Wsi.withctrl mask
->
5335 let y, h = getpageyh
pageno in
5336 let top = (state
.winh
- h) / 2 in
5337 gotoxy state
.x (max
0 (y - top))
5338 | Enter
| KPenter
-> leavebirdseye beye
false
5339 | Escape
-> leavebirdseye beye
true
5340 | Up
-> upbirdseye incr beye
5341 | Down
-> downbirdseye incr beye
5342 | Left
-> upbirdseye 1 beye
5343 | Right
-> downbirdseye 1 beye
5346 begin match state
.layout with
5350 state
.mode <- Birdseye
(
5351 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5353 gotopage1 l.pageno 0;
5356 let layout = layout state
.x (state
.y-state
.winh
)
5358 (pgh state
.layout) in
5360 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5362 state
.mode <- Birdseye
(
5363 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5365 gotopage1 l.pageno 0
5368 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5372 begin match List.rev state
.layout with
5374 let layout = layout state
.x
5375 (state
.y + (pgh state
.layout))
5376 state
.winw state
.winh
in
5377 begin match layout with
5379 let incr = l.pageh
- l.pagevh in
5384 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5386 G.postRedisplay "birdseye pagedown";
5388 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5392 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5393 gotopage1 l.pageno 0;
5396 | [] -> gotoxy state
.x (clamp state
.winh
)
5400 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5404 let pageno = state
.pagecount
- 1 in
5405 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5406 if not
(pagevisible state
.layout pageno)
5409 match List.rev state
.pdims
with
5411 | (_, _, h, _) :: _ -> h
5415 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5416 else G.postRedisplay "birdseye end";
5418 | Delete
|Insert
|KPdelete
|KPdown
|KPend
|KPhome
|KPleft
5419 | KPminus
|KPnext
|KPplus
|KPprior
|KPright
|KPup
|Ascii
_
5420 | Code
_|Fn
_|Backspace
-> viewkeyboard key mask
5425 match state
.mode with
5426 | Textentry
_ -> scalecolor 0.4
5427 | LinkNav
_ | View
-> scalecolor 1.0
5428 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5429 if l.pageno = hooverpageno
5432 if l.pageno = pageno
5434 let c = scalecolor 1.0 in
5436 GlDraw.line_width
3.0;
5437 let dispx = l.pagedispx in
5439 (float (dispx-1)) (float (l.pagedispy-1))
5440 (float (dispx+l.pagevw+1))
5441 (float (l.pagedispy+l.pagevh+1))
5443 GlDraw.line_width
1.0;
5452 let postdrawpage l linkindexbase
=
5453 match getopaque l.pageno with
5455 if tileready l l.pagex
l.pagey
5457 let x = l.pagedispx - l.pagex
5458 and y = l.pagedispy - l.pagey in
5460 match conf
.columns
with
5461 | Csingle
_ | Cmulti
_ ->
5462 (if conf
.hlinks
then 1 else 0)
5464 && not
(isbirdseye state
.mode) then 2 else 0)
5468 match state
.mode with
5469 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5475 Hashtbl.find_all state
.prects
l.pageno |>
5476 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5477 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5479 then (state
.redisplay
<- true; 0)
5485 let scrollindicator () =
5486 let sbw, ph
, sh = state
.uioh#
scrollph in
5487 let sbh, pw, sw = state
.uioh#scrollpw
in
5492 else ((state
.winw
- sbw), state
.winw
, 0)
5496 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5497 GlDraw.color (0.64, 0.64, 0.64) ~
alpha:0.7;
5498 filledrect (float x0) 0. (float x1) (float state
.winh
);
5500 (float hx0
) (float (state
.winh
- sbh))
5501 (float (hx0
+ state
.winw
)) (float state
.winh
)
5503 GlDraw.color (0.0, 0.0, 0.0) ~
alpha:0.7;
5505 filledrect (float x0) ph
(float x1) (ph
+. sh);
5506 let pw = pw +. float hx0
in
5507 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5512 match state
.mstate
with
5513 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5516 | Msel
((x0, y0), (x1, y1)) ->
5517 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5518 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5519 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5520 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5527 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5528 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5530 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5532 if l.pageno = pageno
5534 let dx = float (l.pagedispx - l.pagex
) in
5535 let dy = float (l.pagedispy - l.pagey) in
5536 let r, g, b, alpha = c in
5537 GlDraw.color (r, g, b) ~
alpha;
5538 filledrect2 (x0+.dx) (y0+.dy)
5550 begin match conf
.columns
, state
.layout with
5551 | Csingle
_, _ :: _ ->
5552 GlDraw.color (scalecolor2 conf
.bgcolor
);
5554 List.fold_left
(fun y l ->
5557 let x1 = l.pagedispx in
5558 let y1 = (l.pagedispy + l.pagevh) in
5559 filledrect (float x0) (float y0) (float x1) (float y1);
5560 let x0 = x1 + l.pagevw in
5561 let x1 = state
.winw
in
5562 filledrect1 (float x0) (float y0) (float x1) (float y1);
5566 and x1 = state
.winw
in
5568 and y1 = l.pagedispy in
5569 filledrect1 (float x0) (float y0) (float x1) (float y1);
5571 l.pagedispy + l.pagevh) 0 state
.layout
5574 and x1 = state
.winw
in
5576 and y1 = state
.winh
in
5577 filledrect1 (float x0) (float y0) (float x1) (float y1)
5578 | (Cmulti
_ | Csplit
_), _ | Csingle
_, [] ->
5579 GlClear.color (scalecolor2 conf
.bgcolor
);
5580 GlClear.clear
[`
color];
5582 List.iter
drawpage state
.layout;
5584 match state
.mode with
5585 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5586 begin match getopaque pageno with
5588 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5589 let color = (0.0, 0.0, 0.5, 0.5) in
5596 | None
-> state
.rects
5598 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5601 | View
-> state
.rects
5604 let rec postloop linkindexbase
= function
5606 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5607 postloop linkindexbase rest
5611 postloop 0 state
.layout;
5613 begin match state
.mstate
with
5614 | Mzoomrect
((x0, y0), (x1, y1)) ->
5616 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5617 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5618 filledrect (float x0) (float y0) (float x1) (float y1);
5622 | Mscrolly
| Mscrollx
5631 let zoomrect x y x1 y1 =
5634 and y0 = min
y y1 in
5635 let zoom = (float state
.w) /. float (x1 - x0) in
5638 if state
.w < state
.winw
5639 then (state
.winw
- state
.w) / 2
5642 match conf
.fitmodel
with
5643 | FitWidth
| FitProportional
-> simple ()
5645 match conf
.columns
with
5647 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5648 | Cmulti
_ | Csingle
_ -> simple ()
5650 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5651 state
.anchor <- getanchor
();
5656 let annot inline
x y =
5657 match unproject x y with
5658 | Some
(opaque, n, ux
, uy
) ->
5660 addannot
opaque ux uy
text;
5661 wcmd "freepage %s" (~
> opaque);
5662 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5664 gotoxy state
.x state
.y
5668 let ondone s = add s in
5669 let mode = state
.mode in
5670 state
.mode <- Textentry
(
5671 ("annotation: ", E.s, None
, textentry, ondone, true),
5672 fun _ -> state
.mode <- mode);
5675 G.postRedisplay "annot"
5677 add @@ getusertext E.s
5682 let g opaque l px py =
5683 match rectofblock
opaque px py with
5685 let x0 = a.(0) -. 20. in
5686 let x1 = a.(1) +. 20. in
5687 let y0 = a.(2) -. 20. in
5688 let zoom = (float state
.w) /. (x1 -. x0) in
5689 let pagey = getpagey
l.pageno in
5690 let margin = (state
.w - l.pagew
)/2 in
5691 let nx = -truncate
x0 - margin in
5692 gotoxy_and_clear_text nx (pagey + truncate
y0);
5693 state
.anchor <- getanchor
();
5698 match conf
.columns
with
5700 impmsg "block zooming does not work properly in split columns mode"
5701 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5705 let winw = state
.winw - 1 in
5706 let s = float x /. float winw in
5707 let destx = truncate
(float (state
.w + winw) *. s) in
5708 gotoxy_and_clear_text (winw - destx) state
.y;
5709 state
.mstate
<- Mscrollx
;
5713 let s = float y /. float state
.winh
in
5714 let desty = truncate
(float (state
.maxy -
5715 (if conf
.maxhfit
then state
.winh
else 0))
5717 gotoxy_and_clear_text state
.x desty;
5718 state
.mstate
<- Mscrolly
;
5721 let viewmulticlick clicks
x y mask
=
5722 let g opaque l px py =
5730 if markunder
opaque px py mark
5734 match getopaque l.pageno with
5736 | Some
opaque -> pipesel opaque cmd
5738 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5739 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5744 G.postRedisplay "viewmulticlick";
5745 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5749 match conf
.columns
with
5751 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5754 let viewmouse button down
x y mask
=
5756 | n when (n == 4 || n == 5) && not down
->
5757 if Wsi.withctrl mask
5759 match state
.mstate
with
5760 | Mzoom
(oldn
, i
, (ftx
, fty
)) ->
5763 then abs
(ftx
- x) > 5 || abs
(fty
- y) > 5
5773 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5775 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5777 let zoom = conf
.zoom -. incr in
5779 then pivotzoom ~
x ~
y zoom
5780 else pivotzoom zoom;
5781 state
.mstate
<- Mzoom
(n, 0, (x, y));
5783 state
.mstate
<- Mzoom
(n, i
+1, (ftx
, fty
));
5785 else state
.mstate
<- Mzoom
(n, 0, (ftx
, fty
))
5789 | Mscrolly
| Mscrollx
5791 | Mnone
-> state
.mstate
<- Mzoom
(n, 0, (0, 0))
5794 match state
.autoscroll
with
5795 | Some step
-> setautoscrollspeed step
(n=4)
5797 if conf
.wheelbypage
|| conf
.presentation
5806 then -conf
.scrollstep
5807 else conf
.scrollstep
5809 let incr = incr * 2 in
5810 let y = clamp incr in
5811 gotoxy_and_clear_text state
.x y
5814 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5816 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5817 gotoxy_and_clear_text x state
.y
5819 | 1 when Wsi.withshift mask
->
5820 state
.mstate
<- Mnone
;
5823 match unproject x y with
5825 | Some
(_, pageno, ux
, uy
) ->
5826 let cmd = Printf.sprintf
5828 conf
.stcmd state
.path pageno ux uy
5830 match spawn
cmd [] with
5832 impmsg "execution of synctex command(%S) failed: %S"
5833 conf
.stcmd
@@ exntos exn
5837 | 1 when Wsi.withctrl mask
->
5840 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5841 state
.mstate
<- Mpan
(x, y)
5844 state
.mstate
<- Mnone
5849 if Wsi.withshift mask
5851 annot conf
.annotinline
x y;
5852 G.postRedisplay "addannot"
5856 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5857 state
.mstate
<- Mzoomrect
(p, p)
5860 match state
.mstate
with
5861 | Mzoomrect
((x0, y0), _) ->
5862 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5863 then zoomrect x0 y0 x y
5866 G.postRedisplay "kill accidental zoom rect";
5870 | Mscrolly
| Mscrollx
5872 | Mnone
-> resetmstate ()
5875 | 1 when vscrollhit x ->
5878 let _, position, sh = state
.uioh#
scrollph in
5879 if y > truncate
position && y < truncate
(position +. sh)
5880 then state
.mstate
<- Mscrolly
5883 state
.mstate
<- Mnone
5885 | 1 when y > state
.winh
- hscrollh () ->
5888 let _, position, sw = state
.uioh#scrollpw
in
5889 if x > truncate
position && x < truncate
(position +. sw)
5890 then state
.mstate
<- Mscrollx
5893 state
.mstate
<- Mnone
5895 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5898 let dest = if down
then getunder x y else Unone
in
5899 begin match dest with
5903 | Unone
when down
->
5904 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5905 state
.mstate
<- Mpan
(x, y);
5907 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5909 | Unone
| Utext
_ ->
5914 state
.mstate
<- Msel
((x, y), (x, y));
5915 G.postRedisplay "mouse select";
5919 match state
.mstate
with
5922 | Mzoom
_ | Mscrollx
| Mscrolly
->
5923 state
.mstate
<- Mnone
5925 | Mzoomrect
((x0, y0), _) ->
5929 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5930 state
.mstate
<- Mnone
5932 | Msel
((x0, y0), (x1, y1)) ->
5933 let rec loop = function
5937 let a0 = l.pagedispy in
5938 let a1 = a0 + l.pagevh in
5939 let b0 = l.pagedispx in
5940 let b1 = b0 + l.pagevw in
5941 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5942 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5946 match getopaque l.pageno with
5949 match Unix.pipe
() with
5951 impmsg "cannot create sel pipe: %s" @@
5955 Ne.clo fd
(fun msg
->
5956 dolog
"%s close failed: %s" what msg
)
5958 begin match spawn
cmd [r, 0; w, -1] with
5960 clo "Msel pipe/w" w;
5961 dolog
"cannot execute %S: %s" cmd @@ exntos exn
5964 G.postRedisplay "copysel";
5966 clo "Msel pipe/r" r;
5968 dosel conf
.selcmd
();
5969 state
.roam
<- dosel conf
.paxcmd
;
5981 let birdseyemouse button down
x y mask
5982 (conf
, leftx
, _, hooverpageno
, anchor) =
5985 let rec loop = function
5988 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5989 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5991 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5997 | _ -> viewmouse button down
x y mask
6003 method key key mask
=
6004 begin match state
.mode with
6005 | Textentry
textentry -> textentrykeyboard key mask
textentry
6006 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6007 | View
-> viewkeyboard key mask
6008 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6012 method button button bstate
x y mask
=
6013 begin match state
.mode with
6014 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
6015 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6020 method multiclick clicks
x y mask
=
6021 begin match state
.mode with
6022 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
6023 | Birdseye
_ | Textentry
_ -> ()
6028 begin match state
.mode with
6030 | View
| Birdseye
_ | LinkNav
_ ->
6031 match state
.mstate
with
6032 | Mzoom
_ | Mnone
-> ()
6037 state
.mstate
<- Mpan
(x, y);
6038 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6040 gotoxy_and_clear_text x y
6043 state
.mstate
<- Msel
(a, (x, y));
6044 G.postRedisplay "motion select";
6047 let y = min state
.winh
(max
0 y) in
6051 let x = min state
.winw (max
0 x) in
6054 | Mzoomrect
(p0
, _) ->
6055 state
.mstate
<- Mzoomrect
(p0
, (x, y));
6056 G.postRedisplay "motion zoomrect";
6060 method pmotion
x y =
6061 begin match state
.mode with
6062 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6063 let rec loop = function
6065 if hooverpageno
!= -1
6067 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6068 G.postRedisplay "pmotion birdseye no hoover";
6071 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6072 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6074 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6075 G.postRedisplay "pmotion birdseye hoover";
6083 | LinkNav
_ | View
->
6084 match state
.mstate
with
6085 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6093 let past, _, _ = !r in
6095 let delta = now -. past in
6098 else r := (now, x, y)
6102 method infochanged
_ = ()
6105 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
6108 then 0.0, float state
.winh
6109 else scrollph state
.y maxy
6114 let fwinw = float (state
.winw - vscrollw ()) in
6116 let sw = fwinw /. float state
.w in
6117 let sw = fwinw *. sw in
6118 max
sw (float conf
.scrollh
)
6121 let maxx = state
.w + state
.winw in
6122 let x = state
.winw - state
.x in
6123 let percent = float x /. float maxx in
6124 (fwinw -. sw) *. percent
6126 hscrollh (), position, sw
6130 match state
.mode with
6131 | LinkNav
_ -> "links"
6132 | Textentry
_ -> "textentry"
6133 | Birdseye
_ -> "birdseye"
6136 findkeyhash conf
modename
6138 method eformsgs
= true
6139 method alwaysscrolly
= false
6142 let addrect pageno r g b a x0 y0 x1 y1 =
6143 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6147 let cl = splitatchar cmds ' '
in
6149 try Scanf.sscanf
s fmt
f
6150 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6153 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6154 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6155 s pageno r g b a x0 y0 x1 y1;
6159 let _,w1,h1
,_ = getpagedim
pageno in
6160 let sw = float w1 /. float w
6161 and sh = float h1
/. float h in
6165 and y1s
= y1 *. sh in
6166 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6167 let color = (r, g, b, a) in
6168 if conf
.verbose
then debugrect rect;
6169 state
.rects <- (pageno, color, rect) :: state
.rects;
6174 | "reload", "" -> reload ()
6176 scan args
"%u %f %f"
6178 let cmd, _ = state
.geomcmds
in
6180 then gotopagexy !wtmode pageno x y
6183 gotopagexy !wtmode pageno x y;
6186 state
.reprf
<- f state
.reprf
6188 | "goto1", args
-> scan args
"%u %f" gotopage
6191 (fun _filename _pageno
->
6192 failwith
"gotounder (Uremote (filename, pageno))")
6195 (fun _filename _dest
->
6196 failwith
"gotounder (Uremotedest (filename, dest))")
6198 scan args
"%u %u %f %f %f %f"
6199 (fun pageno c x0 y0 x1 y1 ->
6200 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6201 rectx "rect" pageno color x0 y0 x1 y1;
6204 scan args
"%u %f %f %f %f %f %f %f %f"
6205 (fun pageno r g b alpha x0 y0 x1 y1 ->
6206 addrect pageno r g b alpha x0 y0 x1 y1;
6207 G.postRedisplay "prect"
6210 scan args
"%u %f %f"
6213 match getopaque pageno with
6214 | Some
opaque -> opaque
6217 pgoto optopaque pageno x y;
6218 let rec fixx = function
6221 if l.pageno = pageno
6222 then gotoxy (state
.x - l.pagedispx) state
.y
6227 match conf
.columns
with
6228 | Csingle
_ | Csplit
_ -> 1
6229 | Cmulti
((n, _, _), _) -> n
6231 layout 0 state
.y (state
.winw * mult) state
.winh
6235 | "activatewin", "" -> Wsi.activatewin
()
6236 | "quit", "" -> raise Quit
6239 let l = Config.keys_of_string
keys in
6240 List.iter
(fun (k
, m) -> keyboard k
m) l
6241 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6244 | "clearrects", "" ->
6245 Hashtbl.clear state
.prects
;
6246 G.postRedisplay "clearrects"
6248 adderrfmt "remote command"
6249 "error processing remote command: %S\n" cmds
;
6253 let scratch = Bytes.create
80 in
6254 let buf = Buffer.create
80 in
6256 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6257 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6260 if Buffer.length
buf > 0
6262 let s = Buffer.contents
buf in
6270 match Bytes.index_from
scratch ppos '
\n'
with
6271 | pos
-> if pos
>= n then -1 else pos
6272 | exception Not_found
-> -1
6276 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6277 let s = Buffer.contents
buf in
6283 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6289 let remoteopen path =
6290 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6292 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6297 let gcconfig = ref E.s in
6298 let trimcachepath = ref E.s in
6299 let rcmdpath = ref E.s in
6300 let pageno = ref None
in
6301 let rootwid = ref 0 in
6302 let openlast = ref false in
6303 let nofc = ref false in
6304 let doreap = ref false in
6305 let csspath = ref None
in
6306 selfexec := Sys.executable_name
;
6309 [("-p", Arg.String
(fun s -> state
.password <- s),
6310 "<password> Set password");
6314 Config.fontpath
:= s;
6315 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6317 "<path> Set path to the user interface font");
6321 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6322 Config.confpath
:= s),
6323 "<path> Set path to the configuration file");
6325 ("-last", Arg.Set
openlast, " Open last document");
6327 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6328 "<page-number> Jump to page");
6330 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6331 "<path> Set path to the trim cache file");
6333 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6334 "<named-destination> Set named destination");
6336 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6337 ("-cxack", Arg.Set
cxack, " Cut corners");
6339 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6340 "<path> Set path to the source of remote commands");
6342 ("-gc", Arg.Set_string
gcconfig,
6343 "<path> Collect garbage with the help of a script");
6345 ("-nofc", Arg.Set
nofc, " Do not use fontconfig");
6347 ("-v", Arg.Unit
(fun () ->
6349 "%s\nconfiguration path: %s\n"
6352 exit
0), " Print version and exit");
6354 ("-css", Arg.String
(fun s -> csspath := Some
s),
6355 "<path> Set path to the style sheet to use with EPUB/HTML");
6357 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6359 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6360 "<origin> <undocumented>");
6363 (fun s -> state
.path <- s)
6364 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6367 then selfexec := !selfexec ^
" -wtmode";
6369 let histmode = emptystr state
.path && not
!openlast in
6371 if not
(Config.load !openlast)
6372 then dolog
"failed to load configuration";
6374 begin match !pageno with
6375 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6379 if nonemptystr
!gcconfig
6382 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6383 | exception exn
-> error
"socketpair for gc failed: %s" @@ exntos exn
6386 match spawn
!gcconfig [(c, 0); (c, 1); (s, -1)] with
6387 | exception exn
-> error
"failed to execute gc script: %s" @@ exntos exn
6389 Ne.clo c @@ (fun s -> error
"failed to close gc fd %s" s);
6396 val mutable m_clicks
= 0
6397 val mutable m_click_x
= 0
6398 val mutable m_click_y
= 0
6399 val mutable m_lastclicktime
= infinity
6401 method private cleanup =
6402 state
.roam
<- noroam
;
6403 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6404 method expose
= G.postRedisplay "expose"
6408 | Wsi.Unobscured
-> "unobscured"
6409 | Wsi.PartiallyObscured
-> "partiallyobscured"
6410 | Wsi.FullyObscured
-> "fullyobscured"
6412 vlog "visibility change %s" name
6413 method display = display ()
6414 method map mapped
= vlog "mapped %b" mapped
6415 method reshape w h =
6418 method mouse
b d x y m =
6419 if d && canselect ()
6422 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6429 if abs
x - m_click_x
> 10
6430 || abs
y - m_click_y
> 10
6431 || abs_float
(t -. m_lastclicktime
) > 0.3
6433 m_clicks
<- m_clicks
+ 1;
6434 m_lastclicktime
<- t;
6438 G.postRedisplay "cleanup";
6439 state
.uioh <- state
.uioh#button
b d x y m;
6441 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6446 m_lastclicktime
<- infinity
;
6447 state
.uioh <- state
.uioh#button
b d x y m
6451 state
.uioh <- state
.uioh#button
b d x y m
6454 state
.mpos
<- (x, y);
6455 state
.uioh <- state
.uioh#motion
x y
6456 method pmotion
x y =
6457 state
.mpos
<- (x, y);
6458 state
.uioh <- state
.uioh#pmotion
x y
6460 let mascm = m land (
6461 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6464 let x = state
.x and y = state
.y in
6466 if x != state
.x || y != state
.y then self#
cleanup
6468 match state
.keystate
with
6470 let km = k
, mascm in
6473 let modehash = state
.uioh#
modehash in
6474 try Hashtbl.find modehash km
6476 try Hashtbl.find (findkeyhash conf
"global") km
6477 with Not_found
-> KMinsrt
(k
, m)
6479 | KMinsrt
(k
, m) -> keyboard k
m
6480 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6481 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6483 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6484 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6485 state
.keystate
<- KSnone
6486 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6487 state
.keystate
<- KSinto
(keys, insrt
)
6488 | KSinto
_ -> state
.keystate
<- KSnone
6491 state
.mpos
<- (x, y);
6492 state
.uioh <- state
.uioh#pmotion
x y
6493 method leave = state
.mpos
<- (-1, -1)
6494 method winstate wsl
= state
.winstate
<- wsl
6495 method quit
= raise Quit
6498 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6500 setbgcol conf
.bgcolor
;
6503 if not
@@ List.exists
GlMisc.check_extension
6504 [ "GL_ARB_texture_rectangle"
6505 ; "GL_EXT_texture_recangle"
6506 ; "GL_NV_texture_rectangle" ]
6507 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6509 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6511 defconf
.sliceheight
<- 1024;
6512 defconf
.texcount
<- 32;
6513 defconf
.usepbo
<- true;
6517 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6519 dolog
"socketpair failed: %s" @@ exntos exn
;
6527 setcheckers conf
.checkers
;
6529 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6531 begin match !csspath with
6533 | Some
"" -> conf
.css
<- E.s
6535 let css = filecontents
path in
6536 let l = String.length
css in
6538 if substratis
css (l-2) "\r\n"
6539 then String.sub css 0 (l-2)
6540 else (if css.[l-1] = '
\n'
6541 then String.sub css 0 (l-1)
6545 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6546 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6547 !Config.fontpath
, !trimcachepath, !opengl_has_pbo, not
!nofc
6549 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6551 reshape ~firsttime
:true winw winh
;
6555 Wsi.settitle
"llpp (history)";
6559 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6560 opendoc state
.path state
.password;
6564 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6565 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6568 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6569 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6570 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6572 | _pid
, _status
-> reap ()
6574 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6578 if nonemptystr
!rcmdpath
6579 then remoteopen !rcmdpath
6584 let rec loop deadline
=
6590 let r = [state
.ss; state
.wsfd] in
6594 | Some fd
-> fd
:: r
6598 state
.redisplay
<- false;
6605 if deadline
= infinity
6607 else max
0.0 (deadline
-. now)
6612 try Unix.select
r [] [] timeout
6613 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6619 if state
.ghyll
== noghyll
6621 match state
.autoscroll
with
6622 | Some step
when step
!= 0 ->
6623 let y = state
.y + step
in
6624 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6627 then state
.maxy - fy
6628 else if y >= state
.maxy - fy then 0 else y
6630 if state
.mode = View
6631 then gotoxy_and_clear_text state
.x y
6632 else gotoxy state
.x y;
6635 else deadline
+. 0.01
6640 let rec checkfds = function
6642 | fd
:: rest
when fd
= state
.ss ->
6643 let cmd = rcmd state
.ss in
6647 | fd
:: rest
when fd
= state
.wsfd ->
6651 | fd
:: rest
when Some fd
= !optrfd ->
6652 begin match remote fd
with
6653 | None
-> optrfd := remoteopen !rcmdpath;
6654 | opt -> optrfd := opt
6659 dolog
"select returned unknown descriptor";
6665 if deadline
= infinity
6669 match state
.autoscroll
with
6670 | Some step
when step
!= 0 -> deadline1
6671 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6676 match loop infinity
with
6678 Config.save leavebirdseye;
6679 if hasunsavedchanges
()
6681 | _ -> error
"umpossible - infinity reached"