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
: opaque
-> int -> int -> int -> (int * string * int)
19 -> int = "ml_postprocess";;
20 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
21 external setaalevel
: int -> unit = "ml_setaalevel";;
22 external realloctexts
: int -> bool = "ml_realloctexts";;
23 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
24 external getlink
: opaque
-> int -> under
= "ml_getlink";;
25 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
26 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
27 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
28 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
29 external freepbo
: opaque
-> unit = "ml_freepbo";;
30 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
31 external bousable
: unit -> bool = "ml_bo_usable";;
32 external unproject
: opaque
-> int -> int
33 -> (int * int) option = "ml_unproject";;
34 external project
: opaque
-> int -> int -> float -> float
35 -> (float * float) = "ml_project";;
36 external drawtile
: tileparams
-> opaque
37 -> unit = "ml_drawtile";;
38 external rectofblock
: opaque
-> int -> int
39 -> float array
option = "ml_rectofblock";;
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
48 -> string = "ml_getannotcontents";;
49 external drawprect
: opaque
-> int -> int -> float array
50 -> unit = "ml_drawprect";;
51 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
52 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
53 external uritolocation
: string
54 -> (pageno
* float * float) = "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 clo "selstring pipe/w" w
;
310 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
312 clo "selstring pipe/r" r
;
315 let undertext = function
318 | Utext s
-> "font: " ^ s
319 | Uannotation
(opaque
, slinkindex
) ->
320 "annotation: " ^ getannotcontents opaque slinkindex
323 let updateunder x y =
324 match getunder x y with
325 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
327 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
328 Wsi.setcursor
Wsi.CURSOR_INFO
330 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
331 Wsi.setcursor
Wsi.CURSOR_TEXT
333 if conf
.underinfo
then showtext 'a'
"nnotation";
334 Wsi.setcursor
Wsi.CURSOR_INFO
337 let showlinktype under =
338 if conf
.underinfo
&& under != Unone
339 then showtext ' '
@@ undertext under
342 let [@warning
"-4"] intentry_with_suffix text key
=
345 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
346 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
347 addchar
text @@ asciilower c
349 state
.text <- Printf.sprintf
"invalid key";
356 let b = Buffer.create
16 in
359 let b = Buffer.to_bytes
b in
360 wcmd state
.ss
b @@ Bytes.length
b
364 let nogeomcmds cmds
=
366 | s
, [] -> emptystr s
370 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
371 let rec fold accu
n =
372 if n = Array.length
b
375 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
378 || n = state
.pagecount
- coverB
379 || (n - coverA
) mod columns
= columns
- 1)
385 let pagey = max
0 (y - vy
) in
386 let pagedispy = if pagey > 0 then 0 else vy
- y in
387 let pagedispx, pagex
=
389 if n = coverA
- 1 || n = state
.pagecount
- coverB
390 then x + (sw
- w
) / 2
398 let vw = sw
- pagedispx in
399 let pw = w
- pagex
in
402 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
403 if pagevw > 0 && pagevh > 0
414 ; pagedispx = pagedispx
415 ; pagedispy = pagedispy
427 if Array.length
b = 0
429 else List.rev
(fold [] (page_of_y
y))
432 let layoutS (columns
, b) x y sw sh
=
433 let rec fold accu n =
434 if n = Array.length
b
437 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
445 let pagey = max
0 (y - vy
) in
446 let pagedispy = if pagey > 0 then 0 else vy
- y in
447 let pagedispx, pagex
=
461 let pagecolw = pagew
/columns
in
464 then pagedispx + ((sw
- pagecolw) / 2)
468 let vw = sw
- pagedispx in
469 let pw = pagew
- pagex
in
472 let pagevw = min
pagevw pagecolw in
473 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
474 if pagevw > 0 && pagevh > 0
485 ; pagedispx = pagedispx
486 ; pagedispy = pagedispy
487 ; pagecol
= n mod columns
501 let layout x y sw sh
=
502 if nogeomcmds state
.geomcmds
504 match conf
.columns
with
505 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
506 | Cmulti c
-> layoutN c
x y sw sh
507 | Csplit s
-> layoutS s
x y sw sh
511 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
513 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
516 let tilex = l.pagex
mod conf
.tilew
in
517 let tiley = l.pagey mod conf
.tileh
in
519 let col = l.pagex
/ conf
.tilew
in
520 let row = l.pagey / conf
.tileh
in
522 let rec rowloop row y0 dispy h
=
526 let dh = conf
.tileh
- y0 in
528 let rec colloop col x0 dispx w
=
532 let dw = conf
.tilew
- x0 in
534 f col row dispx dispy
x0 y0 dw dh;
535 colloop (col+1) 0 (dispx
+dw) (w
-dw)
538 colloop col tilex l.pagedispx l.pagevw;
539 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
542 if l.pagevw > 0 && l.pagevh > 0
543 then rowloop row tiley l.pagedispy l.pagevh;
546 let gettileopaque l col row =
548 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
550 try Some
(Hashtbl.find state
.tilemap
key)
551 with Not_found
-> None
554 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
555 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
556 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
559 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
560 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
561 GlArray.vertex `two state
.vraw
;
562 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
565 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
567 let filledrect x0 y0 x1 y1 =
568 GlArray.disable `texture_coord
;
569 filledrect1 x0 y0 x1 y1;
570 GlArray.enable `texture_coord
;
573 let linerect x0 y0 x1 y1 =
574 GlArray.disable `texture_coord
;
575 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
576 GlArray.vertex `two state
.vraw
;
577 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
578 GlArray.enable `texture_coord
;
581 let drawtiles l color =
584 let f col row x y tilex tiley w h
=
585 match gettileopaque l col row with
586 | Some
(opaque
, _
, t
) ->
587 let params = x, y, w
, h
, tilex, tiley in
589 then GlTex.env
(`mode `blend
);
590 drawtile
params opaque
;
592 then GlTex.env
(`mode `modulate
);
596 let s = Printf.sprintf
600 let w = measurestr fstate
.fontsize
s in
601 GlDraw.color (0.0, 0.0, 0.0);
602 filledrect (float (x-2))
605 (float (y + fstate
.fontsize
+ 2));
607 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
614 let lw = state
.winw
- x in
617 let lh = state
.winh
- y in
621 then GlTex.env
(`mode `blend
);
622 begin match state
.checkerstexid
with
624 Gl.enable `texture_2d
;
625 GlTex.bind_texture ~target
:`texture_2d id
;
629 and y1 = float (y+h
) in
631 let tw = float w /. 16.0
632 and th
= float h
/. 16.0 in
633 let tx0 = float tilex /. 16.0
634 and ty0
= float tiley /. 16.0 in
636 and ty1
= ty0
+. th
in
637 Raw.sets_float state
.vraw ~pos
:0
638 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
639 Raw.sets_float state
.traw ~pos
:0
640 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
641 GlArray.vertex `two state
.vraw
;
642 GlArray.tex_coord `two state
.traw
;
643 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
644 Gl.disable `texture_2d
;
647 GlDraw.color (1.0, 1.0, 1.0);
648 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
651 then GlTex.env
(`mode `modulate
);
652 if w > 128 && h
> fstate
.fontsize
+ 10
654 let c = if conf
.invert
then 1.0 else 0.0 in
655 GlDraw.color (c, c, c);
658 then (col*conf
.tilew
, row*conf
.tileh
)
661 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
670 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
672 let tilevisible1 l x y =
674 and ax1
= l.pagex
+ l.pagevw
676 and ay1
= l.pagey + l.pagevh in
680 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
681 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
683 let rx0 = max
ax0 bx0
684 and ry0
= max ay0 by0
685 and rx1
= min ax1
bx1
686 and ry1
= min ay1 by1
in
688 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
692 let tilevisible layout n x y =
693 let rec findpageinlayout m
= function
694 | l :: rest
when l.pageno
= n ->
695 tilevisible1 l x y || (
696 match conf
.columns
with
697 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
698 | Csplit _
| Csingle _
| Cmulti _
-> false
700 | _
:: rest
-> findpageinlayout 0 rest
703 findpageinlayout 0 layout;
706 let tileready l x y =
707 tilevisible1 l x y &&
708 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
711 let tilepage n p
layout =
712 let rec loop = function
716 let f col row _ _ _ _ _ _
=
717 if state
.currently
= Idle
719 match gettileopaque l col row with
722 let x = col*conf
.tilew
723 and y = row*conf
.tileh
in
725 let w = l.pagew
- x in
729 let h = l.pageh
- y in
734 then getpbo
w h conf
.colorspace
737 wcmd "tile %s %d %d %d %d %s"
738 (~
> p
) x y w h (~
> pbo);
741 l, p
, conf
.colorspace
, conf
.angle
,
742 state
.gen
, col, row, conf
.tilew
, conf
.tileh
751 if nogeomcmds state
.geomcmds
755 let preloadlayout x y sw sh
=
756 let y = if y < sh
then 0 else y - sh
in
757 let x = min
0 (x + sw
) in
765 if state
.currently
!= Idle
770 begin match getopaque l.pageno
with
772 wcmd "page %d %d" l.pageno
l.pagedimno
;
773 state
.currently
<- Loading
(l, state
.gen
);
775 tilepage l.pageno opaque pages
;
780 if nogeomcmds state
.geomcmds
786 if conf
.preload && state
.currently
= Idle
787 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
790 let layoutready layout =
791 let rec fold all ls
=
794 let seen = ref false in
795 let allvisible = ref true in
796 let foo col row _ _ _ _ _ _
=
798 allvisible := !allvisible &&
799 begin match gettileopaque l col row with
805 fold (!seen && !allvisible) rest
808 let alltilesvisible = fold true layout in
813 let y = bound
y 0 state
.maxy in
814 let y, layout, proceed
=
815 match conf
.maxwait
with
816 | Some time
when state
.ghyll
== noghyll
->
817 begin match state
.throttle
with
819 let layout = layout x y state
.winw state
.winh
in
820 let ready = layoutready layout in
824 state
.throttle
<- Some
(layout, y, now
());
826 else G.postRedisplay "gotoxy showall (None)";
828 | Some
(_
, _
, started
) ->
829 let dt = now
() -. started
in
832 state
.throttle
<- None
;
833 let layout = layout x y state
.winw state
.winh
in
835 G.postRedisplay "maxwait";
842 let layout = layout x y state
.winw state
.winh
in
843 if not
!wtmode || layoutready layout
844 then G.postRedisplay "gotoxy ready";
851 state
.layout <- layout;
852 begin match state
.mode
with
855 | Ltexact
(pageno
, linkno
) ->
856 let rec loop = function
858 state
.lnava
<- Some
(pageno
, linkno
);
859 state
.mode
<- LinkNav
(Ltgendir
0)
860 | l :: _
when l.pageno
= pageno
->
861 begin match getopaque pageno
with
862 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
864 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
865 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
866 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
867 then state
.mode
<- LinkNav
(Ltgendir
0)
869 | _
:: rest
-> loop rest
872 | Ltnotready _
| Ltgendir _
-> ()
874 | Birdseye _
| Textentry _
| View
-> ()
876 begin match state
.mode
with
877 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
878 if not
(pagevisible layout pageno
)
880 match state
.layout with
883 state
.mode
<- Birdseye
(
884 conf
, leftx
, l.pageno
, hooverpageno
, anchor
889 | Ltnotready
(_
, dir
)
892 let rec loop = function
895 match getopaque l.pageno
with
896 | None
-> Ltnotready
(l.pageno
, dir
)
901 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
903 if dir
> 0 then LDfirst
else LDlast
909 | Lnotfound
-> loop rest
911 showlinktype (getlink opaque
n);
912 Ltexact
(l.pageno
, n)
916 state
.mode
<- LinkNav
linknav
919 | Textentry _
| View
-> ()
923 state
.ghyll
<- noghyll
;
926 let mx, my
= state
.mpos
in
931 let conttiling pageno opaque
=
932 tilepage pageno opaque
934 then preloadlayout state
.x state
.y state
.winw state
.winh
938 let gotoxy_and_clear_text x y =
939 if not conf
.verbose
then state
.text <- E.s;
943 let getanchory (n, top
, dtop
) =
944 let y, h = getpageyh
n in
947 let ips = calcips
h in
948 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
950 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
953 let gotoanchor anchor
=
954 gotoxy state
.x (getanchory anchor
);
958 cbput state
.hists
.nav
(getanchor
());
962 let anchor = cbgetc state
.hists
.nav dir
in
966 let gotoghyll1 single
y =
968 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
970 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
972 then s (float f /. float a
)
975 then 1.0 -. s ((float (f-b) /. float (n-b)))
981 let ins = float a
*. 0.5
982 and outs
= float (n-b) *. 0.5 in
984 ins +. outs
+. float ones
986 let rec set nab
y sy
=
987 let (_N
, _A
, _B
), y =
990 let scl = if y > sy
then 2 else -2 in
991 let _N, _
, _
= nab
in
992 (_N,0,_N), y+conf
.scrollstep
*scl
994 let sum = summa
_N _A _B
in
995 let dy = float (y - sy
) in
999 then state
.ghyll
<- noghyll
1002 let s = scroll n _N _A _B
in
1003 let y1 = y1 +. ((s *. dy) /. sum) in
1004 gotoxy_and_clear_text state
.x (truncate
y1);
1005 state
.ghyll
<- gf (n+1) y1;
1009 | Some
y'
when single
-> set nab
y' state
.y
1010 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1012 gf 0 (float state
.y)
1015 match conf
.ghyllscroll
with
1016 | Some nab
when not conf
.presentation
->
1017 if state
.ghyll
== noghyll
1018 then set nab
y state
.y
1019 else state
.ghyll
(Some
y)
1021 gotoxy_and_clear_text state
.x y
1024 let gotoghyll = gotoghyll1 false;;
1026 let gotopage n top
=
1027 let y, h = getpageyh
n in
1028 let y = y + (truncate
(top
*. float h)) in
1032 let gotopage1 n top
=
1033 let y = getpagey
n in
1038 let invalidate ?
(redisplay
=false) s f =
1039 state
.redisplay
<- redisplay
;
1044 match state
.geomcmds
with
1045 | ps
, [] when emptystr ps
->
1047 state
.geomcmds
<- s, [];
1050 state
.geomcmds
<- ps
, [s, f];
1052 | ps
, (s'
, _
) :: rest
when s'
= s ->
1053 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1056 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1060 Hashtbl.iter
(fun _ opaque
->
1061 wcmd "freepage %s" (~
> opaque
);
1063 Hashtbl.clear state
.pagemap
;
1067 if not
(Queue.is_empty state
.tilelru
)
1069 Queue.iter
(fun (k
, p
, s) ->
1070 wcmd "freetile %s" (~
> p
);
1071 state
.memused
<- state
.memused
- s;
1072 Hashtbl.remove state
.tilemap k
;
1074 state
.uioh#infochanged Memused
;
1075 Queue.clear state
.tilelru
;
1081 let h = truncate
(float h*.conf
.zoom
) in
1082 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1086 let opendoc path password
=
1088 state
.password
<- password
;
1089 state
.gen
<- state
.gen
+ 1;
1090 state
.docinfo
<- [];
1091 state
.outlines
<- [||];
1094 setaalevel conf
.aalevel
;
1096 if emptystr state
.origin
1100 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1101 wcmd "open %d %d %d %s\000%s\000%s\000"
1102 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1103 path password conf
.css
;
1104 invalidate "reqlayout"
1106 wcmd "reqlayout %d %d %d %s\000"
1107 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1108 (stateh state
.winh
) state
.nameddest
1111 let sl = keystostrlist conf
in
1113 function | [] -> accu
1114 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1115 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1119 state
.anchor <- getanchor
();
1120 opendoc state
.path state
.password
;
1124 let c = c *. conf
.colorscale
in
1128 let scalecolor2 (r
, g, b) =
1129 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1132 let docolumns columns
=
1135 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1136 let rec loop pageno
pdimno pdim
y ph pdims
=
1137 if pageno
= state
.pagecount
1140 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1142 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1143 pdimno+1, pdim
, rest
1147 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1149 y + (if conf
.presentation
1150 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1151 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1154 a.(pageno
) <- (pdimno, x, y, pdim
);
1155 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1157 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1158 conf
.columns
<- Csingle
a;
1160 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1161 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1162 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1164 if m
= pageno
then () else
1165 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1168 let y = y + (rowh
- h) / 2 in
1169 a.(m
) <- (pdimno, x, y, pdim
);
1173 if pageno
= state
.pagecount
1174 then fixrow (((pageno
- 1) / columns
) * columns
)
1176 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1178 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1179 pdimno+1, pdim
, rest
1184 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1186 let x = (state
.winw
- w) / 2 in
1188 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1189 x, y + ips + rowh
, h
1192 if (pageno
- coverA
) mod columns
= 0
1194 let x = max
0 (state
.winw
- state
.w) / 2 in
1196 if conf
.presentation
1198 let ips = calcips
h in
1199 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1201 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1205 else x, y, max rowh
h
1209 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1212 if pageno
= columns
&& conf
.presentation
1214 let ips = calcips rowh
in
1215 for i
= 0 to pred columns
1217 let (pdimno, x, y, pdim
) = a.(i
) in
1218 a.(i
) <- (pdimno, x, y+ips, pdim
)
1224 fixrow (pageno
- columns
);
1229 a.(pageno
) <- (pdimno, x, y, pdim
);
1230 let x = x + w + xoff
*2 + conf
.interpagespace
in
1231 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1233 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1234 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1237 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1238 let rec loop pageno
pdimno pdim
y pdims
=
1239 if pageno
= state
.pagecount
1242 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1244 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1245 pdimno+1, pdim
, rest
1250 let rec loop1 n x y =
1251 if n = c then y else (
1252 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1253 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1256 let y = loop1 0 0 y in
1257 loop (pageno
+1) pdimno pdim
y pdims
1259 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1260 conf
.columns
<- Csplit
(c, a);
1264 docolumns conf
.columns
;
1265 state
.maxy <- calcheight
();
1266 if state
.reprf
== noreprf
1268 match state
.mode
with
1269 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1270 let y, h = getpageyh pageno
in
1271 let top = (state
.winh
- h) / 2 in
1272 gotoxy state
.x (max
0 (y - top))
1273 | Textentry _
| View
| LinkNav _
->
1274 let y = getanchory state
.anchor in
1275 let y = min
y (state
.maxy - state
.winh
) in
1280 state
.reprf
<- noreprf
;
1284 let reshape ?
(firsttime
=false) w h =
1285 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1286 if not firsttime
&& nogeomcmds state
.geomcmds
1287 then state
.anchor <- getanchor
();
1290 let w = truncate
(float w *. conf
.zoom
) in
1293 setfontsize fstate
.fontsize
;
1294 GlMat.mode `modelview
;
1295 GlMat.load_identity
();
1297 GlMat.mode `projection
;
1298 GlMat.load_identity
();
1299 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1300 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1301 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1306 else float state
.x /. float state
.w
1308 invalidate ~redisplay
:true "geometry"
1312 then state
.x <- truncate
(relx *. float w);
1314 match conf
.columns
with
1316 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1317 | Csplit
(c, _
) -> w * c
1319 wcmd "geometry %d %d %d"
1320 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1325 let len = String.length state
.text in
1326 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1329 match state
.mode
with
1330 | Textentry _
| View
| LinkNav _
->
1331 let h, _
, _
= state
.uioh#scrollpw
in
1337 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1338 (x+.w) (float (state
.winh
- hscrollh))
1341 let w = float (state
.winw
- 1 - vscrollw ()) in
1342 if state
.progress
>= 0.0 && state
.progress
< 1.0
1344 GlDraw.color (0.3, 0.3, 0.3);
1345 let w1 = w *. state
.progress
in
1347 GlDraw.color (0.0, 0.0, 0.0);
1348 rect (float x0+.w1) (float x0+.w-.w1)
1351 GlDraw.color (0.0, 0.0, 0.0);
1355 GlDraw.color (1.0, 1.0, 1.0);
1358 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1359 (state
.winh
- hscrollh - 5) s;
1362 match state
.mode
with
1363 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1366 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1367 else Printf.sprintf
"%s%s_" prefix
text
1371 | Birdseye _
| View
| LinkNav _
-> state
.text
1376 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1378 let s1 = "(press 'e' to review error messasges)" in
1379 if nonemptystr
s then s ^
" " ^
s1 else s1
1389 let len = Queue.length state
.tilelru
in
1391 match state
.throttle
with
1394 then preloadlayout state
.x state
.y state
.winw state
.winh
1396 | Some
(layout, _
, _
) ->
1400 if state
.memused
> conf
.memlimit
1404 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1405 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1406 let (_
, pw, ph
, _
) = getpagedim
n in
1408 && colorspace
= conf
.colorspace
1409 && angle
= conf
.angle
1413 let x = col*conf
.tilew
1414 and y = row*conf
.tileh
in
1415 tilevisible (Lazy.force_val
layout) n x y
1417 then Queue.push lruitem state
.tilelru
1420 wcmd "freetile %s" (~
> p
);
1421 state
.memused
<- state
.memused
- s;
1422 state
.uioh#infochanged Memused
;
1423 Hashtbl.remove state
.tilemap k
;
1431 let onpagerect pageno
f =
1433 match conf
.columns
with
1434 | Cmulti
(_
, b) -> b
1436 | Csplit
(_
, b) -> b
1438 if pageno
>= 0 && pageno
< Array.length
b
1440 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1444 let gotopagexy1 wtmode pageno
x y =
1445 let _,w1,h1
,leftx
= getpagedim pageno
in
1446 let top = y /. (float h1
) in
1447 let left = x /. (float w1) in
1448 let py, w, h = getpageywh pageno
in
1449 let wh = state
.winh
in
1450 let x = left *. (float w) in
1451 let x = leftx
+ state
.x + truncate
x in
1453 if x < 0 || x >= state
.winw
1457 let pdy = truncate
(top *. float h) in
1458 let y'
= py + pdy in
1459 let dy = y'
- state
.y in
1461 if x != state
.x || not
(dy > 0 && dy < wh)
1463 if conf
.presentation
1465 if abs
(py - y'
) > wh
1472 if state
.x != sx || state
.y != sy
1477 let ww = state
.winw
in
1479 and qy
= pdy / wh in
1481 and y = py + qy
* wh in
1482 let x = if -x + ww > w1 then -(w1-ww) else x
1483 and y'
= if y + wh > state
.maxy then state
.maxy - wh else y in
1485 if conf
.presentation
1487 if abs
(py - y'
) > wh
1496 gotoxy_and_clear_text x y;
1498 else gotoxy_and_clear_text state
.x state
.y;
1501 let gotopagexy wtmode pageno
x y =
1502 match state
.mode
with
1503 | Birdseye
_ -> gotopage pageno
0.0
1504 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1507 let getpassword () =
1508 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1513 impmsg "error getting password: %s" s;
1514 dolog
"%s" s) passcmd;
1517 let pgoto opaque pageno
x y =
1518 let pdimno = getpdimno pageno
in
1519 let x, y = project opaque pageno
pdimno x y in
1520 gotopagexy false pageno
x y;
1524 (* dolog "%S" cmds; *)
1525 let spl = splitatchar cmds ' '
in
1527 try Scanf.sscanf
s fmt
f
1529 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1532 let addoutline outline
=
1533 match state
.currently
with
1534 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1535 | Idle
-> state
.currently
<- Outlining
[outline
]
1536 | Loading
_ | Tiling
_ ->
1537 dolog
"invalid outlining state";
1538 logcurrently state
.currently
1543 state
.uioh#infochanged Pdim
;
1545 | "clearrects", "" ->
1546 state
.rects
<- state
.rects1
;
1547 G.postRedisplay "clearrects";
1549 | "continue", args
->
1550 let n = scan args
"%u" (fun n -> n) in
1551 state
.pagecount
<- n;
1552 begin match state
.currently
with
1554 state
.currently
<- Idle
;
1555 state
.outlines
<- Array.of_list
(List.rev
l)
1556 | Idle
| Loading
_ | Tiling
_ -> ()
1559 let cur, cmds
= state
.geomcmds
in
1561 then failwith
"umpossible";
1563 begin match List.rev cmds
with
1565 state
.geomcmds
<- E.s, [];
1566 state
.throttle
<- None
;
1570 state
.geomcmds
<- s, List.rev rest
;
1572 if conf
.maxwait
= None
&& not
!wtmode
1573 then G.postRedisplay "continue";
1580 then showtext ' ' args
1583 Buffer.add_string state
.errmsgs args
;
1584 state
.newerrmsgs
<- true;
1585 G.postRedisplay "error message"
1587 | "progress", args
->
1588 let progress, text =
1591 f, String.sub args pos
(String.length args
- pos
))
1594 state
.progress <- progress;
1595 G.postRedisplay "progress"
1597 | "firstmatch", args
->
1598 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1599 scan args
"%u %d %f %f %f %f %f %f %f %f"
1600 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1601 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1603 let y = (getpagey
pageno) + truncate
y0 in
1611 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1612 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1615 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1616 scan args
"%u %d %f %f %f %f %f %f %f %f"
1617 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1618 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1620 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1622 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1625 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1626 let pageopaque = ~
< pageopaques in
1627 begin match state
.currently
with
1628 | Loading
(l, gen
) ->
1629 vlog "page %d took %f sec" l.pageno t
;
1630 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1631 begin match state
.throttle
with
1633 let preloadedpages =
1635 then preloadlayout state
.x state
.y state
.winw state
.winh
1640 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1641 IntSet.empty
preloadedpages
1644 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1645 if not
(IntSet.mem
pageno set)
1647 wcmd "freepage %s" (~
> opaque
);
1653 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1656 state
.currently
<- Idle
;
1659 tilepage l.pageno pageopaque state
.layout;
1661 load preloadedpages;
1662 let visible = pagevisible state
.layout l.pageno in
1665 match state
.mode
with
1666 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1667 if pageno = l.pageno
1672 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1674 if dir
> 0 then LDfirst
else LDlast
1677 findlink
pageopaque ld
1682 showlinktype (getlink
pageopaque n);
1683 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1685 | LinkNav
(Ltgendir
_)
1686 | LinkNav
(Ltexact
_)
1692 if visible && layoutready state
.layout
1694 G.postRedisplay "page";
1698 | Some
(layout, _, _) ->
1699 state
.currently
<- Idle
;
1700 tilepage l.pageno pageopaque layout;
1704 | Idle
| Tiling
_ | Outlining
_ ->
1705 dolog
"Inconsistent loading state";
1706 logcurrently state
.currently
;
1711 let (x, y, opaques
, size
, t
) =
1712 scan args
"%u %u %s %u %f"
1713 (fun x y p size t
-> (x, y, p
, size
, t
))
1715 let opaque = ~
< opaques
in
1716 begin match state
.currently
with
1717 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1718 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1721 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1723 wcmd "freetile %s" (~
> opaque);
1724 state
.currently
<- Idle
;
1728 puttileopaque l col row gen cs angle
opaque size t
;
1729 state
.memused
<- state
.memused
+ size
;
1730 state
.uioh#infochanged Memused
;
1732 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1733 opaque, size
) state
.tilelru
;
1736 match state
.throttle
with
1737 | None
-> state
.layout
1738 | Some
(layout, _, _) -> layout
1741 state
.currently
<- Idle
;
1743 && conf
.colorspace
= cs
1744 && conf
.angle
= angle
1745 && tilevisible layout l.pageno x y
1746 then conttiling l.pageno pageopaque;
1748 begin match state
.throttle
with
1750 preload state
.layout;
1752 && conf
.colorspace
= cs
1753 && conf
.angle
= angle
1754 && tilevisible state
.layout l.pageno x y
1755 && (not
!wtmode || layoutready state
.layout)
1756 then G.postRedisplay "tile nothrottle";
1758 | Some
(layout, y, _) ->
1759 let ready = layoutready layout in
1763 state
.layout <- layout;
1764 state
.throttle
<- None
;
1765 G.postRedisplay "throttle";
1771 | Idle
| Loading
_ | Outlining
_ ->
1772 dolog
"Inconsistent tiling state";
1773 logcurrently state
.currently
;
1778 let (n, w, h, _) as pdim
=
1779 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1782 match conf
.fitmodel
with
1784 | FitPage
| FitProportional
->
1785 match conf
.columns
with
1786 | Csplit
_ -> (n, w, h, 0)
1787 | Csingle
_ | Cmulti
_ -> pdim
1789 state
.pdims
<- pdim :: state
.pdims
;
1790 state
.uioh#infochanged Pdim
1793 let (l, n, t
, h, pos
) =
1794 scan args
"%u %u %d %u %n"
1795 (fun l n t
h pos
-> l, n, t
, h, pos
)
1797 let s = String.sub args pos
(String.length args
- pos
) in
1798 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1801 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1802 let s = String.sub args pos
len in
1803 let pos2 = pos
+ len + 1 in
1804 let uri = String.sub args
pos2 (String.length args
- pos2) in
1805 addoutline (s, l, Ouri
uri)
1808 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1809 let s = String.sub args pos
(String.length args
- pos
) in
1810 addoutline (s, l, Onone
)
1814 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1816 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1819 let c, v
= splitatchar args '
\t'
in
1830 if let len = String.length
c in
1831 len > 6 && ((String.sub
c (len-4) 4) = "date")
1833 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1835 let b = Buffer.create
10 in
1836 Printf.bprintf
b "%s\t" c;
1839 Buffer.add_substring
b v p
l;
1840 Buffer.add_char
b c;
1841 with exn
-> Buffer.add_string
b @@ exntos exn
1849 Buffer.add_char
b '
['
;
1850 Buffer.add_string
b v
;
1851 Buffer.add_char
b '
]'
;
1858 state
.docinfo
<- (1, s) :: state
.docinfo
1861 state
.docinfo
<- List.rev state
.docinfo
;
1862 state
.uioh#infochanged Docinfo
1866 then Wsi.settitle
"Wrong password";
1867 let password = getpassword () in
1868 if emptystr
password
1869 then error
"document is password protected"
1870 else opendoc state
.path
password
1873 error
"unknown cmd `%S'" cmds
1878 let action = function
1879 | HCprev
-> cbget cb ~
-1
1880 | HCnext
-> cbget cb
1
1881 | HCfirst
-> cbget cb ~
-(cb
.rc)
1882 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1883 and cancel
() = cb
.rc <- rc
1887 let search pattern forward
=
1888 match conf
.columns
with
1889 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1890 | Csingle
_ | Cmulti
_ ->
1891 if nonemptystr pattern
1894 match state
.layout with
1897 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1899 wcmd "search %d %d %d %d,%s\000"
1900 (btod conf
.icase
) pn py (btod forward
) pattern
;
1903 let [@warning
"-4"] intentry
text key =
1906 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1908 state
.text <- "invalid key";
1918 let l = String.length
s in
1919 let rec loop pos
n =
1923 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1924 loop (pos
+1) (n*26 + m)
1927 let rec loop n = function
1930 match getopaque l.pageno with
1931 | None
-> loop n rest
1933 let m = getlinkcount
opaque in
1936 let under = getlink
opaque n in
1939 else loop (n-m) rest
1941 loop n state
.layout;
1945 let [@warning
"-4"] linknentry
text = function
1947 let text = addchar
text c in
1948 linknact (fun under -> state
.text <- undertext under) text;
1951 state
.text <- Printf.sprintf
"invalid key";
1955 let [@warning
"-4"] textentry
text = function
1956 | Keys.Ascii
c -> TEcont
(addchar
text c)
1957 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1961 let reqlayout angle fitmodel
=
1962 match state
.throttle
with
1964 if nogeomcmds state
.geomcmds
1965 then state
.anchor <- getanchor
();
1966 conf
.angle
<- angle
mod 360;
1969 match state
.mode
with
1970 | LinkNav
_ -> state
.mode
<- View
1971 | Birdseye
_ | Textentry
_ | View
-> ()
1973 conf
.fitmodel
<- fitmodel
;
1977 wcmd "reqlayout %d %d %d"
1978 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1983 let settrim trimmargins trimfuzz
=
1984 if nogeomcmds state
.geomcmds
1985 then state
.anchor <- getanchor
();
1986 conf
.trimmargins
<- trimmargins
;
1987 conf
.trimfuzz
<- trimfuzz
;
1988 let x0, y0, x1, y1 = trimfuzz
in
1990 "settrim" (fun () ->
1991 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1996 match state
.throttle
with
1998 let zoom = max
0.0001 zoom in
1999 if zoom <> conf
.zoom
2001 state
.prevzoom
<- (conf
.zoom, state
.x);
2003 reshape state
.winw state
.winh
;
2004 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2007 | Some
(layout, y, started
) ->
2009 match conf
.maxwait
with
2013 let dt = now
() -. started
in
2021 let pivotzoom ?
(vw=min state
.w state
.winw
)
2022 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
2023 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2024 let w = float state
.w /. zoom in
2025 let hw = w /. 2.0 in
2026 let ratio = float vh
/. float vw in
2027 let hh = hw *. ratio in
2028 let x0 = if zoom < 1.0 then 0.0 else float x -. hw in
2029 let y0 = float y -. hh in
2030 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2034 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2035 if nogeomcmds state
.geomcmds
then pivotzoom ?
vw ?vh ?
x ?
y zoom
2038 let setcolumns mode columns coverA coverB
=
2039 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2043 then impmsg "split mode doesn't work in bird's eye"
2045 conf
.columns
<- Csplit
(-columns
, E.a);
2053 conf
.columns
<- Csingle
E.a;
2058 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2062 reshape state
.winw state
.winh
;
2065 let resetmstate () =
2066 state
.mstate
<- Mnone
;
2067 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2070 let enterbirdseye () =
2071 let zoom = float conf
.thumbw
/. float state
.winw
in
2072 let birdseyepageno =
2073 let cy = state
.winh
/ 2 in
2077 let rec fold best
= function
2080 let d = cy - (l.pagedispy + l.pagevh/2)
2081 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2082 if abs
d < abs dbest
2091 { conf
with zoom = conf
.zoom },
2092 state
.x, birdseyepageno, -1, getanchor
()
2096 conf
.presentation
<- false;
2097 conf
.interpagespace
<- 10;
2098 conf
.hlinks
<- false;
2099 conf
.fitmodel
<- FitPage
;
2101 conf
.maxwait
<- None
;
2103 match conf
.beyecolumns
with
2106 Cmulti
((c, 0, 0), E.a)
2107 | None
-> Csingle
E.a
2111 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2116 reshape state
.winw state
.winh
;
2119 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2121 conf
.zoom <- c.zoom;
2122 conf
.presentation
<- c.presentation
;
2123 conf
.interpagespace
<- c.interpagespace
;
2124 conf
.maxwait
<- c.maxwait
;
2125 conf
.hlinks
<- c.hlinks
;
2126 conf
.fitmodel
<- c.fitmodel
;
2127 conf
.beyecolumns
<- (
2128 match conf
.columns
with
2129 | Cmulti
((c, _, _), _) -> Some
c
2131 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2134 match c.columns
with
2135 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2136 | Csingle
_ -> Csingle
E.a
2137 | Csplit
(c, _) -> Csplit
(c, E.a)
2141 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2144 reshape state
.winw state
.winh
;
2145 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2149 let togglebirdseye () =
2150 match state
.mode
with
2151 | Birdseye vals
-> leavebirdseye vals
true
2152 | View
-> enterbirdseye ()
2153 | Textentry
_ | LinkNav
_ -> ()
2156 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2157 let pageno = max
0 (pageno - incr
) in
2158 let rec loop = function
2159 | [] -> gotopage1 pageno 0
2160 | l :: _ when l.pageno = pageno ->
2161 if l.pagedispy >= 0 && l.pagey = 0
2162 then G.postRedisplay "upbirdseye"
2163 else gotopage1 pageno 0
2164 | _ :: rest
-> loop rest
2168 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2171 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2172 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2173 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2174 let rec loop = function
2176 let y, h = getpageyh
pageno in
2177 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2178 gotoxy state
.x (clamp dy)
2179 | l :: _ when l.pageno = pageno ->
2180 if l.pagevh != l.pageh
2181 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2182 else G.postRedisplay "downbirdseye"
2183 | _ :: rest
-> loop rest
2189 let [@warning
"-4"] optentry mode
_ key =
2190 let btos b = if b then "on" else "off" in
2194 try conf
.scrollstep
<- int_of_string
s with exn
->
2195 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2197 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2202 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2203 if state
.autoscroll
<> None
2204 then state
.autoscroll
<- Some conf
.autoscrollstep
2206 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2208 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2213 let n, a, b = multicolumns_of_string
s in
2214 setcolumns mode
n a b;
2216 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2218 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2223 let zoom = float (int_of_string
s) /. 100.0 in
2226 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2228 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2233 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2235 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2236 begin match mode
with
2238 leavebirdseye beye
false;
2240 | Textentry
_ | View
| LinkNav
_ -> ();
2243 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2245 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2249 match int_of_string
s with
2250 | angle
-> reqlayout angle conf
.fitmodel
2252 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2254 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2257 conf
.icase
<- not conf
.icase
;
2258 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2261 conf
.preload <- not conf
.preload;
2262 gotoxy state
.x state
.y;
2263 TEdone
("preload " ^
(btos conf
.preload))
2266 conf
.verbose
<- not conf
.verbose
;
2267 TEdone
("verbose " ^
(btos conf
.verbose
))
2270 conf
.debug
<- not conf
.debug
;
2271 TEdone
("debug " ^
(btos conf
.debug
))
2274 conf
.maxhfit
<- not conf
.maxhfit
;
2275 state
.maxy <- calcheight
();
2276 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2279 conf
.crophack
<- not conf
.crophack
;
2280 TEdone
("crophack " ^
btos conf
.crophack
)
2284 match conf
.maxwait
with
2286 conf
.maxwait
<- Some infinity
;
2287 "always wait for page to complete"
2289 conf
.maxwait
<- None
;
2290 "show placeholder if page is not ready"
2295 conf
.underinfo
<- not conf
.underinfo
;
2296 TEdone
("underinfo " ^
btos conf
.underinfo
)
2299 conf
.savebmarks
<- not conf
.savebmarks
;
2300 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2306 match state
.layout with
2311 conf
.interpagespace
<- int_of_string
s;
2312 docolumns conf
.columns
;
2313 state
.maxy <- calcheight
();
2314 let y = getpagey
pageno in
2315 gotoxy state
.x (y + py)
2317 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2319 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2323 match conf
.fitmodel
with
2324 | FitProportional
-> FitWidth
2325 | FitWidth
| FitPage
-> FitProportional
2327 reqlayout conf
.angle
fm;
2328 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2331 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2332 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2335 conf
.invert
<- not conf
.invert
;
2336 TEdone
("invert colors " ^
btos conf
.invert
)
2340 cbput state
.hists
.sel
s;
2343 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2344 textentry
, ondone, true)
2348 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2349 else conf
.pax
<- None
;
2350 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2353 state
.text <- Printf.sprintf
"bad option %d `%c'"
2361 class type lvsource
=
2363 method getitemcount
: int
2364 method getitem
: int -> (string * int)
2365 method hasaction
: int -> bool
2366 method exit
: uioh
:uioh
->
2372 method getactive
: int
2373 method getfirst
: int
2375 method getminfo
: (int * int) array
2378 class virtual lvsourcebase
= object
2379 val mutable m_active
= 0
2380 val mutable m_first
= 0
2381 val mutable m_pan
= 0
2382 method getactive
= m_active
2383 method getfirst
= m_first
2384 method getpan
= m_pan
2385 method getminfo
: (int * int) array
= E.a
2388 let [@warning
"-4"] textentrykeyboard
2389 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2392 state
.mode
<- Textentry
(te
, onleave
);
2394 G.postRedisplay "textentrykeyboard enttext";
2396 let histaction cmd
=
2399 | Some
(action, _) ->
2402 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2404 G.postRedisplay "textentry histaction"
2406 let open Keys
in let kt = Wsi.kc2kt
key in
2409 if emptystr
text && cancelonempty
2412 G.postRedisplay "textentrykeyboard after cancel";
2415 let s = withoutlastutf8
text in
2416 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2421 G.postRedisplay "textentrykeyboard after confirm"
2423 | Up
-> histaction HCprev
2424 | Down
-> histaction HCnext
2425 | Home
-> histaction HCfirst
2426 | End
-> histaction HClast
2431 begin match opthist
with
2433 | Some
(_, onhistcancel
) -> onhistcancel
()
2437 G.postRedisplay "textentrykeyboard after cancel2"
2440 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2445 | Code
_ | Ascii
_ ->
2446 begin match onkey
text kt with
2450 G.postRedisplay "textentrykeyboard after confirm2";
2453 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2457 G.postRedisplay "textentrykeyboard after cancel3"
2460 state
.mode
<- Textentry
(te
, onleave
);
2461 G.postRedisplay "textentrykeyboard switch";
2463 | _ -> vlog "unhandled key"
2466 let firstof first active
=
2467 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2468 then max
0 (active
- (fstate
.maxrows
/2))
2472 let calcfirst first active
=
2475 let rows = active
- first
in
2476 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2480 let scrollph y maxy =
2481 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2482 let sh = float state
.winh
/. sh in
2483 let sh = max
sh (float conf
.scrollh
) in
2485 let percent = float y /. float maxy in
2486 let position = (float state
.winh
-. sh) *. percent in
2489 if position +. sh > float state
.winh
2490 then float state
.winh
-. sh
2496 let adderrmsg src msg
=
2497 Buffer.add_string state
.errmsgs msg
;
2498 state
.newerrmsgs
<- true;
2502 let adderrfmt src fmt
=
2503 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2506 let coe s = (s :> uioh
);;
2508 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2510 val m_pan
= source#getpan
2511 val m_first
= source#getfirst
2512 val m_active
= source#getactive
2514 val m_prev_uioh
= state
.uioh
2516 method private elemunder
y =
2520 let n = y / (fstate
.fontsize
+1) in
2521 if m_first
+ n < source#getitemcount
2523 if source#hasaction
(m_first
+ n)
2524 then Some
(m_first
+ n)
2531 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2532 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2533 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2534 GlDraw.color (1., 1., 1.);
2535 Gl.enable `texture_2d
;
2536 let fs = fstate
.fontsize
in
2538 let hw = state
.winw
/3 in
2539 let ww = fstate
.wwidth
in
2540 let tabw = 17.0*.ww in
2541 let itemcount = source#getitemcount
in
2542 let minfo = source#getminfo
in
2546 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2548 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2550 if (row - m_first
) > fstate
.maxrows
2553 if row >= 0 && row < itemcount
2555 let (s, level
) = source#getitem
row in
2556 let y = (row - m_first
) * nfs in
2557 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2560 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2564 Gl.disable `texture_2d
;
2565 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2566 GlDraw.color (1., 1., 1.) ~
alpha;
2567 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2568 Gl.enable `texture_2d
;
2571 if zebra
&& row land 1 = 1
2575 GlDraw.color (c,c,c);
2576 let drawtabularstring s =
2578 let x'
= truncate
(x0 +. x) in
2579 let s1, s2
= splitatchar
s '
\000'
in
2581 then drawstring1 fs x'
(y+nfs) s
2587 let s'
= withoutlastutf8
s in
2588 let s = s' ^
UniSyms.ellipsis in
2589 let w = measurestr
fs s in
2590 if float x'
+. w +. ww < float (hw + x'
)
2595 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2599 ignore
(drawstring1 fs x'
(y+nfs) s1);
2600 drawstring1 fs (hw + x'
) (y+nfs) s2
2604 let x = if helpmode
&& row > 0 then x +. ww else x in
2605 let s1, s2
= splitatchar
s '
\t'
in
2608 let nx = drawstr x s1 in
2610 let x = x +. (max
tabw sw) in
2613 let len = String.length
s - 2 in
2614 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2616 let s = String.sub s 2 len in
2617 let x = if not helpmode
then x +. ww else x in
2618 GlDraw.color (1.2, 1.2, 1.2);
2619 let vinc = drawstring1 (fs+fs/4)
2620 (truncate
(x -. ww)) (y+nfs) s in
2621 GlDraw.color (1., 1., 1.);
2622 vinc +. (float fs *. 0.8)
2628 ignore
(drawtabularstring s);
2634 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2637 if (row - m_first
) <= fstate
.maxrows
2639 if row >= 0 && row < itemcount
2641 let (s, level
) = source#getitem
row in
2642 let pos0 = nindex
s '
\000'
in
2643 let y = (row - m_first
) * nfs in
2644 let x = float (level
+ m_pan
) *. ww in
2645 let (first
, last
) = minfo.(row) in
2647 if pos0 > 0 && first
> pos0
2648 then String.sub s (pos0+1) (first
-pos0-1)
2649 else String.sub s 0 first
2651 let suffix = String.sub s first
(last
- first
) in
2652 let w1 = measurestr fstate
.fontsize
prefix in
2653 let w2 = measurestr fstate
.fontsize
suffix in
2654 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2655 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2657 and y0 = float (y+2) in
2659 and y1 = float (y+fs+3) in
2660 filledrect x0 y0 x1 y1;
2664 Gl.disable `texture_2d
;
2665 if Array.length
minfo > 0 then loop m_first
;
2670 method updownlevel incr
=
2671 let len = source#getitemcount
in
2673 if m_active
>= 0 && m_active
< len
2674 then snd
(source#getitem m_active
)
2678 if i
= len then i
-1 else if i
= -1 then 0 else
2679 let _, l = source#getitem i
in
2680 if l != curlevel then i
else flow (i
+incr
)
2682 let active = flow m_active
in
2683 let first = calcfirst m_first
active in
2684 G.postRedisplay "outline updownlevel";
2685 {< m_active
= active; m_first
= first >}
2687 method private key1
key mask
=
2688 let set1 active first qsearch
=
2689 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2691 let search active pattern incr
=
2692 let active = if active = -1 then m_first
else active in
2695 if n >= 0 && n < source#getitemcount
2697 let s, _ = source#getitem
n in
2698 match Str.search_forward re
s 0 with
2699 | exception Not_found
-> loop (n + incr
)
2706 let qpat = Str.quote pattern
in
2707 match Str.regexp_case_fold
qpat with
2710 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2711 qpat @@ Printexc.to_string exn
;
2714 let itemcount = source#getitemcount
in
2715 let find start incr
=
2717 if i
= -1 || i
= itemcount
2720 if source#hasaction i
2722 else find (i
+ incr
)
2727 let set active first =
2728 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2730 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2733 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2735 let incr1 = if incr
> 0 then 1 else -1 in
2736 if isvisible m_first m_active
2739 let next = m_active
+ incr
in
2741 if next < 0 || next >= itemcount
2743 else find next incr1
2745 if abs
(m_active
- next) > fstate
.maxrows
2751 let first = m_first
+ incr
in
2752 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2754 let next = m_active
+ incr
in
2755 let next = bound
next 0 (itemcount - 1) in
2762 if isvisible first next
2769 let first = min
next m_first
in
2771 if abs
(next - first) > fstate
.maxrows
2777 let first = m_first
+ incr
in
2778 let first = bound
first 0 (itemcount - 1) in
2780 let next = m_active
+ incr
in
2781 let next = bound
next 0 (itemcount - 1) in
2782 let next = find next incr1 in
2784 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2786 let active = if m_active
= -1 then next else m_active
in
2791 if isvisible first active
2797 G.postRedisplay "listview navigate";
2801 let kt = Wsi.kc2kt
key in
2802 match [@warning
"-4"] kt with
2803 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2804 let incr = if c = 'r'
then -1 else 1 in
2806 match search (m_active
+ incr) m_qsearch
incr with
2808 state
.text <- m_qsearch ^
" [not found]";
2811 state
.text <- m_qsearch
;
2812 active, firstof m_first
active
2814 G.postRedisplay "listview ctrl-r/s";
2815 set1 active first m_qsearch
;
2817 | Insert
when Wsi.withctrl mask
->
2818 if m_active
>= 0 && m_active
< source#getitemcount
2820 let s, _ = source#getitem m_active
in
2826 if emptystr m_qsearch
2829 let qsearch = withoutlastutf8 m_qsearch
in
2833 G.postRedisplay "listview empty qsearch";
2834 set1 m_active m_first
E.s;
2838 match search m_active
qsearch ~
-1 with
2840 state
.text <- qsearch ^
" [not found]";
2843 state
.text <- qsearch;
2844 active, firstof m_first
active
2846 G.postRedisplay "listview backspace qsearch";
2847 set1 active first qsearch
2850 | Ascii
_ | Code
_ ->
2852 match [@warning
"-4"] kt with
2853 | Ascii
c -> String.make
1 c
2854 | Code code
-> toutf8 code
2857 let pattern = m_qsearch ^
utf8 in
2859 match search m_active
pattern 1 with
2861 state
.text <- pattern ^
" [not found]";
2864 state
.text <- pattern;
2865 active, firstof m_first
active
2867 G.postRedisplay "listview qsearch add";
2868 set1 active first pattern;
2872 if emptystr m_qsearch
2874 G.postRedisplay "list view escape";
2875 let mx, my
= state
.mpos
in
2877 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2878 ~
first:m_first ~pan
:m_pan
with
2879 | None
-> m_prev_uioh
2883 G.postRedisplay "list view kill qsearch";
2884 coe {< m_qsearch
= E.s >}
2889 let self = {< m_qsearch
= E.s >} in
2891 G.postRedisplay "listview enter";
2892 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2893 source#exit ~uioh
:(coe self) ~
cancel
2894 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2896 begin match opt with
2897 | None
-> m_prev_uioh
2904 | Up
-> navigate ~
-1
2905 | Down
-> navigate 1
2906 | Prior
-> navigate ~
-(fstate
.maxrows
)
2907 | Next
-> navigate fstate
.maxrows
2911 G.postRedisplay "listview right";
2912 coe {< m_pan
= m_pan
- 1 >}
2916 G.postRedisplay "listview left";
2917 coe {< m_pan
= m_pan
+ 1 >}
2920 let active = find 0 1 in
2921 G.postRedisplay "listview home";
2925 let first = max
0 (itemcount - fstate
.maxrows
) in
2926 let active = find (itemcount - 1) ~
-1 in
2927 G.postRedisplay "listview end";
2932 method key key mask
=
2933 match state
.mode
with
2935 textentrykeyboard
key mask te
;
2937 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2939 method button button down
x y _ =
2942 | 1 when vscrollhit x ->
2943 G.postRedisplay "listview scroll";
2946 let _, position, sh = self#
scrollph in
2947 if y > truncate
position && y < truncate
(position +. sh)
2949 state
.mstate
<- Mscrolly
;
2953 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2954 let first = truncate
(s *. float source#getitemcount
) in
2955 let first = min source#getitemcount
first in
2956 Some
(coe {< m_first
= first; m_active
= first >})
2958 state
.mstate
<- Mnone
;
2962 begin match self#elemunder
y with
2964 G.postRedisplay "listview click";
2965 source#exit ~uioh
:(coe {< m_active
= n >})
2966 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2970 | n when (n == 4 || n == 5) && not down
->
2971 let len = source#getitemcount
in
2973 if n = 5 && m_first
+ fstate
.maxrows
>= len
2977 let first = m_first
+ (if n == 4 then -1 else 1) in
2978 bound
first 0 (len - 1)
2980 G.postRedisplay "listview wheel";
2981 Some
(coe {< m_first
= first >})
2982 | n when (n = 6 || n = 7) && not down
->
2983 let inc = if n = 7 then -1 else 1 in
2984 G.postRedisplay "listview hwheel";
2985 Some
(coe {< m_pan
= m_pan
+ inc >})
2990 | None
-> m_prev_uioh
2993 method multiclick
_ x y = self#button
1 true x y
2996 match state
.mstate
with
2998 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2999 let first = truncate
(s *. float source#getitemcount
) in
3000 let first = min source#getitemcount
first in
3001 G.postRedisplay "listview motion";
3002 coe {< m_first
= first; m_active
= first >}
3010 method pmotion
x y =
3011 if x < state
.winw
- conf
.scrollbw
3014 match self#elemunder
y with
3015 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3016 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3020 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3025 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3029 method infochanged
_ = ()
3031 method scrollpw
= (0, 0.0, 0.0)
3033 let nfs = fstate
.fontsize
+ 1 in
3034 let y = m_first
* nfs in
3035 let itemcount = source#getitemcount
in
3036 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3037 let maxy = maxi * nfs in
3038 let p, h = scrollph y maxy in
3041 method modehash
= modehash
3042 method eformsgs
= false
3043 method alwaysscrolly
= true
3046 class outlinelistview ~zebra ~source
=
3047 let settext autonarrow
s =
3050 let ss = source#statestr
in
3054 else "{" ^
ss ^
"} [" ^
s ^
"]"
3055 else state
.text <- s
3061 ~source
:(source
:> lvsource
)
3063 ~modehash
:(findkeyhash conf
"outline")
3066 val m_autonarrow
= false
3068 method! key key mask
=
3070 if emptystr state
.text
3072 else fstate
.maxrows - 2
3074 let calcfirst first active =
3077 let rows = active - first in
3078 if rows > maxrows then active - maxrows else first
3082 let active = m_active
+ incr in
3083 let active = bound
active 0 (source#getitemcount
- 1) in
3084 let first = calcfirst m_first
active in
3085 G.postRedisplay "outline navigate";
3086 coe {< m_active
= active; m_first
= first >}
3088 let navscroll first =
3090 let dist = m_active
- first in
3096 else first + maxrows
3099 G.postRedisplay "outline navscroll";
3100 coe {< m_first
= first; m_active
= active >}
3102 let ctrl = Wsi.withctrl mask
in
3104 match Wsi.kc2kt
key with
3105 | Ascii '
a'
when ctrl ->
3108 then (source#denarrow
; E.s)
3110 let pattern = source#renarrow
in
3111 if nonemptystr m_qsearch
3112 then (source#narrow m_qsearch
; m_qsearch
)
3116 settext (not m_autonarrow
) text;
3117 G.postRedisplay "toggle auto narrowing";
3118 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3120 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3122 G.postRedisplay "toggle auto narrowing";
3123 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3125 | Ascii '
n'
when ctrl ->
3126 source#narrow m_qsearch
;
3128 then source#add_narrow_pattern m_qsearch
;
3129 G.postRedisplay "outline ctrl-n";
3130 coe {< m_first
= 0; m_active
= 0 >}
3132 | Ascii 'S'
when ctrl ->
3133 let active = source#calcactive
(getanchor
()) in
3134 let first = firstof m_first
active in
3135 G.postRedisplay "outline ctrl-s";
3136 coe {< m_first
= first; m_active
= active >}
3138 | Ascii 'u'
when ctrl ->
3139 G.postRedisplay "outline ctrl-u";
3140 if m_autonarrow
&& nonemptystr m_qsearch
3142 ignore
(source#renarrow
);
3143 settext m_autonarrow
E.s;
3144 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3147 source#del_narrow_pattern
;
3148 let pattern = source#renarrow
in
3150 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3152 settext m_autonarrow
text;
3153 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3156 | Ascii '
l'
when ctrl ->
3157 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3158 G.postRedisplay "outline ctrl-l";
3159 coe {< m_first
= first >}
3161 | Ascii '
\t'
when m_autonarrow
->
3162 if nonemptystr m_qsearch
3164 G.postRedisplay "outline list view tab";
3165 source#add_narrow_pattern m_qsearch
;
3167 coe {< m_qsearch
= E.s >}
3171 | Escape
when m_autonarrow
->
3172 if nonemptystr m_qsearch
3173 then source#add_narrow_pattern m_qsearch
;
3176 | Enter
when m_autonarrow
->
3177 if nonemptystr m_qsearch
3178 then source#add_narrow_pattern m_qsearch
;
3181 | (Ascii
_ | Code
_) when m_autonarrow
->
3182 let pattern = m_qsearch ^ toutf8
key in
3183 G.postRedisplay "outlinelistview autonarrow add";
3184 source#narrow
pattern;
3185 settext true pattern;
3186 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3188 | Backspace
when m_autonarrow
->
3189 if emptystr m_qsearch
3192 let pattern = withoutlastutf8 m_qsearch
in
3193 G.postRedisplay "outlinelistview autonarrow backspace";
3194 ignore
(source#renarrow
);
3195 source#narrow
pattern;
3196 settext true pattern;
3197 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3200 navscroll (max
0 (m_first
- 1))
3203 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3205 | Up
-> navigate ~
-1
3206 | Down
-> navigate 1
3207 | Prior
-> navigate ~
-(fstate
.maxrows)
3208 | Next
-> navigate fstate
.maxrows
3214 G.postRedisplay "outline ctrl right";
3215 {< m_pan
= m_pan
+ 1 >}
3217 else self#updownlevel
1
3225 G.postRedisplay "outline ctrl left";
3226 {< m_pan
= m_pan
- 1 >}
3228 else self#updownlevel ~
-1
3233 G.postRedisplay "outline home";
3234 coe {< m_first
= 0; m_active
= 0 >}
3237 let active = source#getitemcount
- 1 in
3238 let first = max
0 (active - fstate
.maxrows) in
3239 G.postRedisplay "outline end";
3240 coe {< m_active
= active; m_first
= first >}
3242 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
3246 let genhistoutlines () =
3248 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3249 compare c2
.lastvisit c1
.lastvisit
)
3250 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3251 let path = if nonemptystr origin
then origin
else path in
3252 let base = mbtoutf8
@@ Filename.basename
path in
3253 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3257 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3258 Config.save
leavebirdseye;
3259 state
.anchor <- anchor;
3260 state
.bookmarks
<- bookmarks
;
3261 state
.origin
<- origin
;
3264 let x0, y0, x1, y1 = conf
.trimfuzz
in
3265 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3266 reshape ~firsttime
:true state
.winw state
.winh
;
3267 opendoc path origin
;
3271 let makecheckers () =
3272 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3274 converted by Issac Trotts. July 25, 2002 *)
3275 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3276 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3277 let id = GlTex.gen_texture
() in
3278 GlTex.bind_texture ~target
:`texture_2d
id;
3279 GlPix.store
(`unpack_alignment
1);
3280 GlTex.image2d
image;
3281 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3282 [ `mag_filter `nearest
; `min_filter `nearest
];
3286 let setcheckers enabled
=
3287 match state
.checkerstexid
with
3289 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3291 | Some checkerstexid
->
3294 GlTex.delete_texture checkerstexid
;
3295 state
.checkerstexid
<- None
;
3299 let describe_location () =
3300 let fn = page_of_y state
.y in
3301 let ln = page_of_y
(state
.y + state
.winh
- 1) in
3302 let maxy = maxy () in
3306 else 100. *. (float state
.y /. float maxy)
3310 Printf.sprintf
"page %d of %d [%.2f%%]"
3311 (fn+1) state
.pagecount
percent
3314 "pages %d-%d of %d [%.2f%%]"
3315 (fn+1) (ln+1) state
.pagecount
percent
3318 let setpresentationmode v
=
3319 let n = page_of_y state
.y in
3320 state
.anchor <- (n, 0.0, 1.0);
3321 conf
.presentation
<- v
;
3322 if conf
.fitmodel
= FitPage
3323 then reqlayout conf
.angle conf
.fitmodel
;
3327 let setbgcol (r
, g, b) =
3329 let r = r *. 255.0 |> truncate
3330 and g = g *. 255.0 |> truncate
3331 and b = b *. 255.0 |> truncate
in
3332 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3334 Wsi.setwinbgcol
col;
3338 let btos b = if b then UniSyms.radical else E.s in
3339 let showextended = ref false in
3340 let leave mode
_ = state
.mode
<- mode
in
3343 val mutable m_l
= []
3344 val mutable m_a
= E.a
3345 val mutable m_prev_uioh
= nouioh
3346 val mutable m_prev_mode
= View
3348 inherit lvsourcebase
3350 method reset prev_mode prev_uioh
=
3351 m_a
<- Array.of_list
(List.rev m_l
);
3353 m_prev_mode
<- prev_mode
;
3354 m_prev_uioh
<- prev_uioh
;
3356 method int name get
set =
3362 try set (int_of_string
s)
3364 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3368 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3369 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3373 method int_with_suffix name get
set =
3375 (name
, `intws get
, 1,
3379 try set (int_of_string_with_suffix
s)
3381 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3386 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3388 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3392 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3394 (name
, `
bool (btos, get
), offset
, Action
(
3401 method color name get
set =
3403 (name
, `
color get
, 1,
3406 let invalid = (nan
, nan
, nan
) in
3409 try color_of_string
s
3411 state
.text <- Printf.sprintf
"bad color `%s': %s"
3418 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3419 state
.text <- color_to_string
(get
());
3420 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3424 method string name get
set =
3426 (name
, `
string get
, 1,
3429 let ondone s = set s in
3430 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3431 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3435 method colorspace name get
set =
3437 (name
, `
string get
, 1,
3442 inherit lvsourcebase
3445 m_active
<- CSTE.to_int conf
.colorspace
;
3448 method getitemcount
=
3449 Array.length
CSTE.names
3452 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3453 ignore
(uioh
, first, pan
);
3454 if not
cancel then set active;
3456 method hasaction
_ = true
3460 let modehash = findkeyhash conf
"info" in
3461 coe (new listview ~zebra
:false ~helpmode
:false
3462 ~
source ~trusted
:true ~
modehash)
3465 method paxmark name get
set =
3467 (name
, `
string get
, 1,
3472 inherit lvsourcebase
3475 m_active
<- MTE.to_int conf
.paxmark
;
3478 method getitemcount
= Array.length
MTE.names
3479 method getitem
n = (MTE.names
.(n), 0)
3480 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3481 ignore
(uioh
, first, pan
);
3482 if not
cancel then set active;
3484 method hasaction
_ = true
3488 let modehash = findkeyhash conf
"info" in
3489 coe (new listview ~zebra
:false ~helpmode
:false
3490 ~
source ~trusted
:true ~
modehash)
3493 method fitmodel name get
set =
3495 (name
, `
string get
, 1,
3500 inherit lvsourcebase
3503 m_active
<- FMTE.to_int conf
.fitmodel
;
3506 method getitemcount
= Array.length
FMTE.names
3507 method getitem
n = (FMTE.names
.(n), 0)
3508 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3509 ignore
(uioh
, first, pan
);
3510 if not
cancel then set active;
3512 method hasaction
_ = true
3516 let modehash = findkeyhash conf
"info" in
3517 coe (new listview ~zebra
:false ~helpmode
:false
3518 ~
source ~trusted
:true ~
modehash)
3521 method caption
s offset
=
3522 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3524 method caption2
s f offset
=
3525 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3527 method getitemcount
= Array.length m_a
3530 let tostr = function
3531 | `
int f -> string_of_int
(f ())
3532 | `intws
f -> string_with_suffix_of_int
(f ())
3534 | `
color f -> color_to_string
(f ())
3535 | `
bool (btos, f) -> btos (f ())
3538 let name, t
, offset
, _ = m_a
.(n) in
3539 ((let s = tostr t
in
3541 then Printf.sprintf
"%s\t%s" name s
3545 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3550 match m_a
.(active) with
3551 | _, _, _, Action
f -> f uioh
3552 | _, _, _, Noaction
-> uioh
3563 method hasaction
n =
3565 | _, _, _, Action
_ -> true
3566 | _, _, _, Noaction
-> false
3568 initializer m_active
<- 1
3571 let rec fillsrc prevmode prevuioh
=
3572 let sep () = src#caption
E.s 0 in
3573 let colorp name get
set =
3575 (fun () -> color_to_string
(get
()))
3578 let c = color_of_string
v in
3582 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3585 let oldmode = state
.mode
in
3586 let birdseye = isbirdseye state
.mode
in
3588 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3590 src#
bool "presentation mode"
3591 (fun () -> conf
.presentation
)
3592 (fun v -> setpresentationmode v);
3594 src#
bool "ignore case in searches"
3595 (fun () -> conf
.icase
)
3596 (fun v -> conf
.icase
<- v);
3599 (fun () -> conf
.preload)
3600 (fun v -> conf
.preload <- v);
3602 src#
bool "highlight links"
3603 (fun () -> conf
.hlinks
)
3604 (fun v -> conf
.hlinks
<- v);
3606 src#
bool "under info"
3607 (fun () -> conf
.underinfo
)
3608 (fun v -> conf
.underinfo
<- v);
3610 src#
bool "persistent bookmarks"
3611 (fun () -> conf
.savebmarks
)
3612 (fun v -> conf
.savebmarks
<- v);
3614 src#fitmodel
"fit model"
3615 (fun () -> FMTE.to_string conf
.fitmodel
)
3616 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3618 src#
bool "trim margins"
3619 (fun () -> conf
.trimmargins
)
3620 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3622 src#
bool "persistent location"
3623 (fun () -> conf
.jumpback
)
3624 (fun v -> conf
.jumpback
<- v);
3627 src#
int "inter-page space"
3628 (fun () -> conf
.interpagespace
)
3630 conf
.interpagespace
<- n;
3631 docolumns conf
.columns
;
3633 match state
.layout with
3638 state
.maxy <- calcheight
();
3639 let y = getpagey
pageno in
3640 gotoxy state
.x (y + py)
3644 (fun () -> conf
.pagebias
)
3645 (fun v -> conf
.pagebias
<- v);
3647 src#
int "scroll step"
3648 (fun () -> conf
.scrollstep
)
3649 (fun n -> conf
.scrollstep
<- n);
3651 src#
int "horizontal scroll step"
3652 (fun () -> conf
.hscrollstep
)
3653 (fun v -> conf
.hscrollstep
<- v);
3655 src#
int "auto scroll step"
3657 match state
.autoscroll
with
3659 | _ -> conf
.autoscrollstep
)
3661 let n = boundastep state
.winh
n in
3662 if state
.autoscroll
<> None
3663 then state
.autoscroll
<- Some
n;
3664 conf
.autoscrollstep
<- n);
3667 (fun () -> truncate
(conf
.zoom *. 100.))
3668 (fun v -> pivotzoom ((float v) /. 100.));
3671 (fun () -> conf
.angle
)
3672 (fun v -> reqlayout v conf
.fitmodel
);
3674 src#
int "scroll bar width"
3675 (fun () -> conf
.scrollbw
)
3678 reshape state
.winw state
.winh
;
3681 src#
int "scroll handle height"
3682 (fun () -> conf
.scrollh
)
3683 (fun v -> conf
.scrollh
<- v;);
3685 src#
int "thumbnail width"
3686 (fun () -> conf
.thumbw
)
3688 conf
.thumbw
<- min
4096 v;
3691 leavebirdseye beye
false;
3698 let mode = state
.mode in
3699 src#
string "columns"
3701 match conf
.columns
with
3703 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3704 | Csplit
(count
, _) -> "-" ^ string_of_int count
3707 let n, a, b = multicolumns_of_string
v in
3708 setcolumns mode n a b);
3711 src#caption
"Pixmap cache" 0;
3712 src#int_with_suffix
"size (advisory)"
3713 (fun () -> conf
.memlimit
)
3714 (fun v -> conf
.memlimit
<- v);
3718 Printf.sprintf
"%s bytes, %d tiles"
3719 (string_with_suffix_of_int state
.memused
)
3720 (Hashtbl.length state
.tilemap
)) 1;
3723 src#caption
"Layout" 0;
3724 src#caption2
"Dimension"
3726 Printf.sprintf
"%dx%d (virtual %dx%d)"
3727 state
.winw state
.winh
3732 src#caption2
"Position" (fun () ->
3733 Printf.sprintf
"%dx%d" state
.x state
.y
3736 src#caption2
"Position" (fun () -> describe_location ()) 1
3740 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3741 "Save these parameters as global defaults at exit"
3742 (fun () -> conf
.bedefault
)
3743 (fun v -> conf
.bedefault
<- v)
3747 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3748 src#
bool ~offset
:0 ~
btos "Extended parameters"
3749 (fun () -> !showextended)
3750 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3754 (fun () -> conf
.checkers
)
3755 (fun v -> conf
.checkers
<- v; setcheckers v);
3756 src#
bool "update cursor"
3757 (fun () -> conf
.updatecurs
)
3758 (fun v -> conf
.updatecurs
<- v);
3759 src#
bool "scroll-bar on the left"
3760 (fun () -> conf
.leftscroll
)
3761 (fun v -> conf
.leftscroll
<- v);
3763 (fun () -> conf
.verbose
)
3764 (fun v -> conf
.verbose
<- v);
3765 src#
bool "invert colors"
3766 (fun () -> conf
.invert
)
3767 (fun v -> conf
.invert
<- v);
3769 (fun () -> conf
.maxhfit
)
3770 (fun v -> conf
.maxhfit
<- v);
3772 (fun () -> conf
.pax
!= None
)
3775 then conf
.pax
<- Some
(ref (now
(), 0, 0))
3776 else conf
.pax
<- None
);
3777 src#
string "uri launcher"
3778 (fun () -> conf
.urilauncher
)
3779 (fun v -> conf
.urilauncher
<- v);
3780 src#
string "path launcher"
3781 (fun () -> conf
.pathlauncher
)
3782 (fun v -> conf
.pathlauncher
<- v);
3783 src#
string "tile size"
3784 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3787 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3788 conf
.tilew
<- max
64 w;
3789 conf
.tileh
<- max
64 h;
3792 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3795 src#
int "texture count"
3796 (fun () -> conf
.texcount
)
3799 then conf
.texcount
<- v
3800 else impmsg "failed to set texture count please retry later"
3802 src#
int "slice height"
3803 (fun () -> conf
.sliceheight
)
3805 conf
.sliceheight
<- v;
3806 wcmd "sliceh %d" conf
.sliceheight
;
3808 src#
int "anti-aliasing level"
3809 (fun () -> conf
.aalevel
)
3811 conf
.aalevel
<- bound
v 0 8;
3812 state
.anchor <- getanchor
();
3813 opendoc state
.path state
.password;
3815 src#
string "page scroll scaling factor"
3816 (fun () -> string_of_float conf
.pgscale)
3819 let s = float_of_string
v in
3822 state
.text <- Printf.sprintf
3823 "bad page scroll scaling factor `%s': %s" v
3827 src#
int "ui font size"
3828 (fun () -> fstate
.fontsize
)
3829 (fun v -> setfontsize (bound
v 5 100));
3830 src#
int "hint font size"
3831 (fun () -> conf
.hfsize
)
3832 (fun v -> conf
.hfsize
<- bound
v 5 100);
3833 colorp "background color"
3834 (fun () -> conf
.bgcolor
)
3835 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3836 src#
bool "crop hack"
3837 (fun () -> conf
.crophack
)
3838 (fun v -> conf
.crophack
<- v);
3839 src#
string "trim fuzz"
3840 (fun () -> irect_to_string conf
.trimfuzz
)
3843 conf
.trimfuzz
<- irect_of_string
v;
3845 then settrim true conf
.trimfuzz
;
3847 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3850 src#
string "throttle"
3852 match conf
.maxwait
with
3853 | None
-> "show place holder if page is not ready"
3856 then "wait for page to fully render"
3858 "wait " ^ string_of_float
time
3859 ^
" seconds before showing placeholder"
3863 let f = float_of_string
v in
3865 then conf
.maxwait
<- None
3866 else conf
.maxwait
<- Some
f
3868 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3871 src#
string "ghyll scroll"
3873 match conf
.ghyllscroll
with
3875 | Some nab
-> ghyllscroll_to_string nab
3878 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3881 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3883 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3886 src#
string "selection command"
3887 (fun () -> conf
.selcmd
)
3888 (fun v -> conf
.selcmd
<- v);
3889 src#
string "synctex command"
3890 (fun () -> conf
.stcmd
)
3891 (fun v -> conf
.stcmd
<- v);
3892 src#
string "pax command"
3893 (fun () -> conf
.paxcmd
)
3894 (fun v -> conf
.paxcmd
<- v);
3895 src#
string "ask password command"
3896 (fun () -> conf
.passcmd)
3897 (fun v -> conf
.passcmd <- v);
3898 src#
string "save path command"
3899 (fun () -> conf
.savecmd
)
3900 (fun v -> conf
.savecmd
<- v);
3901 src#colorspace
"color space"
3902 (fun () -> CSTE.to_string conf
.colorspace
)
3904 conf
.colorspace
<- CSTE.of_int
v;
3908 src#paxmark
"pax mark method"
3909 (fun () -> MTE.to_string conf
.paxmark
)
3910 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3911 if bousable
() && !opengl_has_pbo
3914 (fun () -> conf
.usepbo
)
3915 (fun v -> conf
.usepbo
<- v);
3916 src#
bool "mouse wheel scrolls pages"
3917 (fun () -> conf
.wheelbypage
)
3918 (fun v -> conf
.wheelbypage
<- v);
3919 src#
bool "open remote links in a new instance"
3920 (fun () -> conf
.riani
)
3921 (fun v -> conf
.riani
<- v);
3922 src#
bool "edit annotations inline"
3923 (fun () -> conf
.annotinline
)
3924 (fun v -> conf
.annotinline
<- v);
3925 src#
bool "coarse positioning in presentation mode"
3926 (fun () -> conf
.coarseprespos
)
3927 (fun v -> conf
.coarseprespos
<- v);
3928 src#
bool "use document CSS"
3929 (fun () -> conf
.usedoccss
)
3931 conf
.usedoccss
<- v;
3932 state
.anchor <- getanchor
();
3933 opendoc state
.path state
.password;
3938 src#caption
"Document" 0;
3939 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3940 src#caption2
"Pages"
3941 (fun () -> string_of_int state
.pagecount
) 1;
3942 src#caption2
"Dimensions"
3943 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3944 if nonemptystr conf
.css
3945 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3949 src#caption
"Trimmed margins" 0;
3950 src#caption2
"Dimensions"
3951 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3955 src#caption
"OpenGL" 0;
3956 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3957 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3960 src#caption
"Location" 0;
3961 if nonemptystr state
.origin
3962 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3963 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3965 src#reset prevmode prevuioh
;
3970 let prevmode = state
.mode
3971 and prevuioh
= state
.uioh in
3972 fillsrc prevmode prevuioh
;
3973 let source = (src :> lvsource
) in
3974 let modehash = findkeyhash conf
"info" in
3977 inherit listview ~zebra
:false ~helpmode
:false
3978 ~
source ~trusted
:true ~
modehash as super
3979 val mutable m_prevmemused
= 0
3980 method! infochanged
= function
3982 if m_prevmemused
!= state
.memused
3984 m_prevmemused
<- state
.memused
;
3985 G.postRedisplay "memusedchanged";
3987 | Pdim
-> G.postRedisplay "pdimchanged"
3988 | Docinfo
-> fillsrc prevmode prevuioh
3990 method! key key mask
=
3991 if not
(Wsi.withctrl mask
)
3993 match [@warning
"-4"] Wsi.kc2kt
key with
3994 | Keys.Left
-> coe (self#updownlevel ~
-1)
3995 | Keys.Right
-> coe (self#updownlevel
1)
3996 | _ -> super#
key key mask
3997 else super#
key key mask
3999 G.postRedisplay "info";
4005 inherit lvsourcebase
4006 method getitemcount
= Array.length state
.help
4008 let s, l, _ = state
.help
.(n) in
4011 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4015 match state
.help
.(active) with
4016 | _, _, Action
f -> Some
(f uioh)
4017 | _, _, Noaction
-> Some
uioh
4026 method hasaction
n =
4027 match state
.help
.(n) with
4028 | _, _, Action
_ -> true
4029 | _, _, Noaction
-> false
4035 let modehash = findkeyhash conf
"help" in
4037 state
.uioh <- coe (new listview
4038 ~zebra
:false ~helpmode
:true
4039 ~
source ~trusted
:true ~
modehash);
4040 G.postRedisplay "help";
4046 inherit lvsourcebase
4047 val mutable m_items
= E.a
4049 method getitemcount
= 1 + Array.length m_items
4054 else m_items
.(n-1), 0
4056 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4061 then Buffer.clear state
.errmsgs
;
4068 method hasaction
n =
4072 state
.newerrmsgs
<- false;
4073 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4074 m_items
<- Array.of_list
l
4083 let source = (msgsource :> lvsource
) in
4084 let modehash = findkeyhash conf
"listview" in
4087 inherit listview ~zebra
:false ~helpmode
:false
4088 ~
source ~trusted
:false ~
modehash as super
4091 then msgsource#reset
;
4094 G.postRedisplay "msgs";
4098 let editor = getenvwithdef
"EDITOR" E.s in
4102 let tmppath = Filename.temp_file
"llpp" "note" in
4105 let oc = open_out
tmppath in
4109 let execstr = editor ^
" " ^
tmppath in
4111 match spawn
execstr [] with
4113 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4116 match Unix.waitpid
[] pid
with
4118 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4122 | Unix.WEXITED
0 -> filecontents
tmppath
4124 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4126 | Unix.WSIGNALED
n ->
4127 impmsg "editor process(%s) was killed by signal %d" execstr n;
4129 | Unix.WSTOPPED
n ->
4130 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4133 match Unix.unlink
tmppath with
4135 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4140 let enterannotmode opaque slinkindex
=
4143 inherit lvsourcebase
4144 val mutable m_text
= E.s
4145 val mutable m_items
= E.a
4147 method getitemcount
= Array.length m_items
4150 let label, _func
= m_items
.(n) in
4153 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4154 ignore
(uioh, first, pan
);
4157 let _label, func
= m_items
.(active) in
4162 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4165 let rec split accu b i
=
4167 if p = String.length
s
4168 then (String.sub s b (p-b), unit) :: accu
4170 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4172 let ss = if i
= 0 then E.s else String.sub s b i
in
4173 split ((ss, unit)::accu) (p+1) 0
4178 wcmd "freepage %s" (~
> opaque);
4180 Hashtbl.fold (fun key opaque'
accu ->
4181 if opaque'
= opaque'
4182 then key :: accu else accu) state
.pagemap
[]
4184 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4186 gotoxy state
.x state
.y
4189 delannot
opaque slinkindex
;
4192 let edit inline
() =
4197 modannot
opaque slinkindex
s;
4203 let mode = state
.mode in
4206 ("annotation: ", m_text
, None
, textentry
, update, true),
4207 fun _ -> state
.mode <- mode);
4211 let s = getusertext m_text
in
4216 ( "[Copy]", fun () -> selstring m_text
)
4217 :: ("[Delete]", dele)
4218 :: ("[Edit]", edit conf
.annotinline
)
4220 :: split [] 0 0 |> List.rev
|> Array.of_list
4227 let s = getannotcontents
opaque slinkindex
in
4230 let source = (msgsource :> lvsource
) in
4231 let modehash = findkeyhash conf
"listview" in
4232 state
.uioh <- coe (object
4233 inherit listview ~zebra
:false ~helpmode
:false
4234 ~
source ~trusted
:false ~
modehash
4236 G.postRedisplay "enterannotmode";
4239 let gotoremote spec
=
4240 let filename, dest
= splitatchar spec '#'
in
4241 let getpath filename =
4243 if nonemptystr
filename
4245 if Filename.is_relative
filename
4247 let dir = Filename.dirname state
.path in
4249 if Filename.is_implicit
dir
4250 then Filename.concat
(Sys.getcwd
()) dir
4253 Filename.concat
dir filename
4257 if Sys.file_exists
path
4261 let path = getpath filename in
4265 let cmd = Lazy.force_val lcmd
in
4266 match spawn
cmd with
4268 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4270 let anchor = getanchor
() in
4271 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4272 state
.origin
<- E.s;
4273 state
.ranchors
<- ranchor :: state
.ranchors
;
4276 if substratis spec
0 "page="
4278 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4280 state
.anchor <- (pageno, 0.0, 0.0);
4281 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4283 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4285 state
.nameddest
<- dest
;
4286 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4290 let gotounder = function
4291 | Ulinkuri
s when isexternallink
s ->
4292 if substratis
s 0 "file://"
4293 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4296 let pageno, x, y = uritolocation
s in
4298 gotopagexy !wtmode pageno x y
4299 | Utext
_ | Unone
-> ()
4300 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4303 let gotooutline (_, _, kind
) =
4307 let (pageno, y, _) = anchor in
4309 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4313 | Ouri
uri -> gotounder (Ulinkuri
uri)
4314 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4315 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4316 | Ohistory hist
-> gotohist hist
4317 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4320 class outlinesoucebase fetchoutlines
= object (self)
4321 inherit lvsourcebase
4322 val mutable m_items
= E.a
4323 val mutable m_minfo
= E.a
4324 val mutable m_orig_items
= E.a
4325 val mutable m_orig_minfo
= E.a
4326 val mutable m_narrow_patterns
= []
4327 val mutable m_gen
= -1
4329 method getitemcount
= Array.length m_items
4332 let s, n, _ = m_items
.(n) in
4335 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4336 ignore
(uioh, first);
4338 if m_narrow_patterns
= []
4339 then m_orig_items
, m_orig_minfo
4340 else m_items
, m_minfo
4347 gotooutline m_items
.(active);
4355 method hasaction
(_:int) = true
4358 if Array.length m_items
!= Array.length m_orig_items
4361 match m_narrow_patterns
with
4363 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4365 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4369 match m_narrow_patterns
with
4372 | head
:: _ -> UniSyms.ellipsis ^ head
4374 method narrow
pattern =
4375 match Str.regexp_case_fold
pattern with
4378 let rec loop accu minfo n =
4381 m_items
<- Array.of_list
accu;
4382 m_minfo
<- Array.of_list
minfo;
4385 let (s, _, _) as o = m_items
.(n) in
4387 match Str.search_forward re
s 0 with
4388 | exception Not_found
-> accu, minfo
4389 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4391 loop accu minfo (n-1)
4393 loop [] [] (Array.length m_items
- 1)
4395 method! getminfo
= m_minfo
4398 m_orig_items
<- fetchoutlines
();
4399 m_minfo
<- m_orig_minfo
;
4400 m_items
<- m_orig_items
4402 method add_narrow_pattern
pattern =
4403 m_narrow_patterns
<- pattern :: m_narrow_patterns
4405 method del_narrow_pattern
=
4406 match m_narrow_patterns
with
4407 | _ :: rest
-> m_narrow_patterns
<- rest
4412 match m_narrow_patterns
with
4413 | pattern :: [] -> self#narrow
pattern; pattern
4415 List.fold_left
(fun accu pattern ->
4416 self#narrow
pattern;
4417 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4419 method calcactive
(_:anchor) = 0
4421 method reset
anchor items =
4422 if state
.gen
!= m_gen
4424 m_orig_items
<- items;
4426 m_narrow_patterns
<- [];
4428 m_orig_minfo
<- E.a;
4432 if items != m_orig_items
4434 m_orig_items
<- items;
4435 if m_narrow_patterns
== []
4436 then m_items
<- items;
4439 let active = self#calcactive
anchor in
4441 m_first
<- firstof m_first
active
4445 let outlinesource fetchoutlines
=
4447 inherit outlinesoucebase fetchoutlines
4448 method! calcactive
anchor =
4449 let rely = getanchory anchor in
4450 let rec loop n best bestd
=
4451 if n = Array.length m_items
4454 let _, _, kind
= m_items
.(n) in
4457 let orely = getanchory anchor in
4458 let d = abs
(orely - rely) in
4461 else loop (n+1) best bestd
4462 | Onone
| Oremote
_ | Olaunch
_
4463 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4464 loop (n+1) best bestd
4470 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4471 let mkselector sourcetype
=
4472 let fetchoutlines () =
4473 match sourcetype
with
4474 | `bookmarks
-> Array.of_list state
.bookmarks
4475 | `outlines
-> state
.outlines
4476 | `history
-> genhistoutlines () |> Array.of_list
4479 if sourcetype
= `history
4480 then new outlinesoucebase
fetchoutlines
4481 else outlinesource fetchoutlines
4484 let outlines = fetchoutlines () in
4485 if Array.length
outlines = 0
4486 then showtext ' ' errmsg
4489 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4490 let anchor = getanchor
() in
4491 source#reset
anchor outlines;
4492 state
.text <- source#greetmsg
;
4494 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4495 G.postRedisplay "enter selector";
4499 let mkenter sourcetype errmsg
=
4500 let enter = mkselector sourcetype
in
4501 fun () -> enter errmsg
4503 ( mkenter `
outlines "document has no outline"
4504 , mkenter `bookmarks
"document has no bookmarks (yet)"
4505 , mkenter `history
"history is empty" )
4508 let quickbookmark ?title
() =
4509 match state
.layout with
4516 let tm = localtime
(now
()) in
4518 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4520 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4522 | Some
title -> title
4524 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4527 let setautoscrollspeed step goingdown
=
4528 let incr = max
1 ((abs step
) / 2) in
4529 let incr = if goingdown
then incr else -incr in
4530 let astep = boundastep state
.winh
(step
+ incr) in
4531 state
.autoscroll
<- Some
astep;
4535 match conf
.columns
with
4537 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4540 let panbound x = bound
x (-state
.w) state
.winw
;;
4542 let existsinrow pageno (columns
, coverA
, coverB
) p =
4543 let last = ((pageno - coverA
) mod columns
) + columns
in
4544 let rec any = function
4547 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4551 then (if l.pageno = last then false else any rest
)
4559 match state
.layout with
4561 let pageno = page_of_y state
.y in
4562 gotoghyll (getpagey
(pageno+1))
4564 match conf
.columns
with
4566 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4568 let y = clamp (pgscale state
.winh
) in
4571 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4572 gotoghyll (getpagey
pageno)
4573 | Cmulti
((c, _, _) as cl
, _) ->
4574 if conf
.presentation
4575 && (existsinrow l.pageno cl
4576 (fun l -> l.pageh
> l.pagey + l.pagevh))
4578 let y = clamp (pgscale state
.winh
) in
4581 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4582 gotoghyll (getpagey
pageno)
4584 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4586 let pagey, pageh
= getpageyh
l.pageno in
4587 let pagey = pagey + pageh
* l.pagecol
in
4588 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4589 gotoghyll (pagey + pageh
+ ips)
4593 match state
.layout with
4595 let pageno = page_of_y state
.y in
4596 gotoghyll (getpagey
(pageno-1))
4598 match conf
.columns
with
4600 if conf
.presentation
&& l.pagey != 0
4602 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4604 let pageno = max
0 (l.pageno-1) in
4605 gotoghyll (getpagey
pageno)
4606 | Cmulti
((c, _, coverB
) as cl
, _) ->
4607 if conf
.presentation
&&
4608 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4610 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4613 if l.pageno = state
.pagecount
- coverB
4617 let pageno = max
0 (l.pageno-decr) in
4618 gotoghyll (getpagey
pageno)
4626 let pageno = max
0 (l.pageno-1) in
4627 let pagey, pageh
= getpageyh
pageno in
4630 let pagey, pageh
= getpageyh
l.pageno in
4631 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4637 if emptystr conf
.savecmd
4638 then adderrmsg "savepath-command is empty"
4639 "don't know where to save modified document"
4641 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4645 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
4650 let tmp = path ^
".tmp" in
4652 Unix.rename
tmp path;
4655 let viewkeyboard key mask
=
4657 let mode = state
.mode in
4658 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4661 G.postRedisplay "view:enttext"
4663 let ctrl = Wsi.withctrl mask
in
4665 match Wsi.kc2kt
key with
4666 | Ascii 'Q'
-> exit
0
4669 if hasunsavedchanges
()
4673 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4676 match state
.lnava
with
4677 | None
-> LinkNav
(Ltgendir
0)
4678 | Some
pn -> LinkNav
(Ltexact
pn)
4680 gotoxy state
.x state
.y;
4682 else impmsg "keyboard link navigation does not work under rotation"
4684 | Escape
| Ascii 'q'
->
4685 begin match state
.mstate
with
4688 G.postRedisplay "kill rect";
4691 | Mscrolly
| Mscrollx
4694 begin match state
.mode with
4697 | Ltexact pl
-> state
.lnava
<- Some pl
4698 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4701 G.postRedisplay "esc leave linknav"
4702 | Birdseye
_ | Textentry
_ | View
->
4703 match state
.ranchors
with
4705 | (path, password, anchor, origin
) :: rest
->
4706 state
.ranchors
<- rest
;
4707 state
.anchor <- anchor;
4708 state
.origin
<- origin
;
4709 state
.nameddest
<- E.s;
4710 opendoc path password
4715 gotoghyll (getnav ~
-1)
4726 Hashtbl.iter
(fun _ opaque ->
4728 Hashtbl.clear state
.prects
) state
.pagemap
;
4729 G.postRedisplay "dehighlight";
4731 | (Ascii '
/'
| Ascii '?'
) as pv
->
4732 let ondone isforw
s =
4733 cbput state
.hists
.pat
s;
4734 state
.searchpattern
<- s;
4737 let s = String.make
1 (Char.chr
key) in
4738 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4739 textentry
, ondone (pv
= Ascii '
/'
), true)
4741 | Ascii '
+'
| Ascii '
='
when ctrl ->
4742 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4743 pivotzoom (conf
.zoom +. incr)
4748 try int_of_string
s with exn
->
4749 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4755 state
.text <- "page bias is now " ^ string_of_int
n;
4758 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4760 | Ascii '
-'
when ctrl ->
4761 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4762 pivotzoom (max
0.01 (conf
.zoom -. decr))
4765 let ondone msg
= state
.text <- msg
in
4767 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4768 optentry state
.mode, ondone, true
4771 | Ascii '
0'
when ctrl ->
4773 then gotoxy 0 state
.y
4776 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4778 match conf
.columns
with
4779 | Csingle
_ | Cmulti
_ -> 1
4780 | Csplit
(n, _) -> n
4782 let h = state
.winh
-
4783 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4785 let zoom = zoomforh state
.winw
h 0 cols in
4786 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4789 | Ascii '
3'
when ctrl ->
4791 match conf
.fitmodel
with
4792 | FitWidth
-> FitProportional
4793 | FitProportional
-> FitPage
4794 | FitPage
-> FitWidth
4796 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4797 reqlayout conf
.angle
fm
4799 | Ascii '
4'
when ctrl ->
4800 let zoom = getmaxw
() /. float state
.winw
in
4801 if zoom > 0.0 then setzoom zoom
4806 | Ascii '
9'
when ctrl ->
4813 try int_of_string
s with exn
->
4814 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4820 cbput state
.hists
.pag
(string_of_int
n);
4821 gotopage1 (n + conf
.pagebias
- 1) 0;
4824 let [@warning
"-4"] pageentry
text = function
4825 | Keys.Ascii '
g'
-> TEdone
text
4826 | key -> intentry
text key
4828 let text = String.make
1 (Char.chr
key) in
4829 enttext (":", text, Some
(onhist state
.hists
.pag
),
4830 pageentry
, ondone, true)
4833 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4834 G.postRedisplay "toggle scrollbar";
4837 state
.bzoom
<- not state
.bzoom
;
4839 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4842 conf
.hlinks
<- not conf
.hlinks
;
4843 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4844 G.postRedisplay "toggle highlightlinks";
4847 if conf
.angle
mod 360 = 0
4849 state
.glinks
<- true;
4850 let mode = state
.mode in
4853 (":", E.s, None
, linknentry
, linknact gotounder, false),
4855 state
.glinks
<- false;
4859 G.postRedisplay "view:linkent(F)"
4861 else impmsg "hint mode does not work under rotation"
4864 state
.glinks
<- true;
4865 let mode = state
.mode in
4868 (":", E.s, None
, linknentry
,
4869 linknact (fun under -> selstring (undertext under)), false),
4871 state
.glinks
<- false;
4875 G.postRedisplay "view:linkent"
4878 begin match state
.autoscroll
with
4880 conf
.autoscrollstep
<- step
;
4881 state
.autoscroll
<- None
4883 if conf
.autoscrollstep
= 0
4884 then state
.autoscroll
<- Some
1
4885 else state
.autoscroll
<- Some conf
.autoscrollstep
4888 | Ascii '
p'
when ctrl ->
4889 launchpath () (* XXX where do error messages go? *)
4892 setpresentationmode (not conf
.presentation
);
4893 showtext ' '
("presentation mode " ^
4894 if conf
.presentation
then "on" else "off");
4897 if List.mem
Wsi.Fullscreen state
.winstate
4898 then Wsi.reshape conf
.cwinw conf
.cwinh
4899 else Wsi.fullscreen
()
4901 | Ascii
('
p'
|'N'
) ->
4902 search state
.searchpattern
false
4904 | Ascii '
n'
| Fn
3 ->
4905 search state
.searchpattern
true
4908 begin match state
.layout with
4911 gotoghyll (getpagey
l.pageno)
4921 showtext ' '
(describe_location ());
4924 begin match state
.layout with
4927 Wsi.reshape l.pagew
l.pageh
;
4932 enterbookmarkmode
()
4934 | Ascii '
h'
| Fn
1 ->
4940 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4945 match state
.layout with
4950 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4953 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
4957 showtext ' '
"Quick bookmark added";
4960 begin match state
.layout with
4962 let rect = getpdimrect
l.pagedimno
in
4966 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4967 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4969 (truncate
(rect.(1) -. rect.(0)),
4970 truncate
(rect.(3) -. rect.(0)))
4972 let w = truncate
((float w)*.conf
.zoom)
4973 and h = truncate
((float h)*.conf
.zoom) in
4976 state
.anchor <- getanchor
();
4977 Wsi.reshape w (h + conf
.interpagespace
)
4979 G.postRedisplay "z";
4984 | Ascii '
x'
-> state
.roam
()
4986 | Ascii
('
<'
|'
>'
as c) ->
4988 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
4990 | Ascii
('
['
|'
]'
as c) ->
4992 bound
(conf
.colorscale
+. (if c = '
>'
then 0.1 else -0.1)) 0.0 1.0;
4993 G.postRedisplay "brightness";
4995 | Ascii '
c'
when state
.mode = View
->
5000 let m = (state
.winw
- state
.w) / 2 in
5001 gotoxy_and_clear_text m state
.y
5005 match state
.prevcolumns
with
5006 | None
-> (1, 0, 0), 1.0
5007 | Some
(columns
, z
) ->
5010 | Csplit
(c, _) -> -c, 0, 0
5011 | Cmulti
((c, a, b), _) -> c, a, b
5012 | Csingle
_ -> 1, 0, 0
5016 setcolumns View
c a b;
5019 | Down
| Up
when ctrl && Wsi.withshift mask
->
5020 let zoom, x = state
.prevzoom
in
5025 begin match state
.autoscroll
with
5027 begin match state
.mode with
5028 | Birdseye beye
-> upbirdseye 1 beye
5029 | Textentry
_ | View
| LinkNav
_ ->
5031 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5033 if not
(Wsi.withshift mask
) && conf
.presentation
5035 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5039 setautoscrollspeed n false
5042 | Ascii 'j'
| Down
->
5043 begin match state
.autoscroll
with
5045 begin match state
.mode with
5046 | Birdseye beye
-> downbirdseye 1 beye
5047 | Textentry
_ | View
| LinkNav
_ ->
5049 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5051 if not
(Wsi.withshift mask
) && conf
.presentation
5053 else gotoghyll1 true (clamp (conf
.scrollstep
))
5057 setautoscrollspeed n true
5060 | Left
| Right
when not
(Wsi.withalt mask
) ->
5066 else conf
.hscrollstep
5069 let pv = Wsi.kc2kt
key in
5070 if pv = Keys.Left
then dx else -dx
5072 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5075 G.postRedisplay "left/right"
5082 match state
.layout with
5084 | l :: _ -> state
.y - l.pagey
5086 clamp (pgscale (-state
.winh
))
5094 match List.rev state
.layout with
5096 | l :: _ -> getpagey
l.pageno
5098 clamp (pgscale state
.winh
)
5102 | Ascii '
g'
| Home
->
5105 | Ascii 'G'
| End
->
5107 gotoghyll (clamp state
.maxy)
5109 | Right
when Wsi.withalt mask
->
5110 gotoghyll (getnav 1)
5111 | Left
when Wsi.withalt mask
->
5112 gotoghyll (getnav ~
-1)
5117 | Ascii '
v'
when conf
.debug
->
5120 match getopaque l.pageno with
5123 let x0, y0, x1, y1 = pagebbox
opaque in
5124 let rect = (float x0, float y0,
5127 float x0, float y1) in
5129 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5130 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5132 G.postRedisplay "v";
5135 let mode = state
.mode in
5136 let cmd = ref E.s in
5137 let onleave = function
5138 | Cancel
-> state
.mode <- mode
5141 match getopaque l.pageno with
5142 | Some
opaque -> pipesel opaque !cmd
5143 | None
-> ()) state
.layout;
5147 cbput state
.hists
.sel
s;
5151 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
5153 G.postRedisplay "|";
5154 state
.mode <- Textentry
(te, onleave);
5156 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
5157 vlog "huh? %s" (Wsi.keyname
key)
5160 let linknavkeyboard key mask
linknav =
5161 let pv = Wsi.kc2kt
key in
5162 let getpage pageno =
5163 let rec loop = function
5165 | l :: _ when l.pageno = pageno -> Some
l
5166 | _ :: rest
-> loop rest
5167 in loop state
.layout
5169 let doexact (pageno, n) =
5170 match getopaque pageno, getpage pageno with
5171 | Some
opaque, Some
l ->
5174 let under = getlink
opaque n in
5175 G.postRedisplay "link gotounder";
5183 Some
(findlink
opaque LDfirst
), -1
5186 Some
(findlink
opaque LDlast
), 1
5189 Some
(findlink
opaque (LDleft
n)), -1
5192 Some
(findlink
opaque (LDright
n)), 1
5195 Some
(findlink
opaque (LDup
n)), -1
5198 Some
(findlink
opaque (LDdown
n)), 1
5200 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
5201 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
5204 begin match findpwl
l.pageno dir with
5208 state
.mode <- LinkNav
(Ltgendir
dir);
5209 let y, h = getpageyh
pageno in
5212 then y + h - state
.winh
5217 begin match getopaque pageno, getpage pageno with
5218 | Some
opaque, Some
_ ->
5220 let ld = if dir > 0 then LDfirst
else LDlast
in
5223 begin match link with
5225 showlinktype (getlink
opaque m);
5226 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5227 G.postRedisplay "linknav jpage";
5228 | Lnotfound
-> notfound dir
5234 begin match opt with
5235 | Some Lnotfound
-> pwl l dir;
5236 | Some
(Lfound
m) ->
5240 let _, y0, _, y1 = getlinkrect
opaque m in
5242 then gotopage1 l.pageno y0
5244 let d = fstate
.fontsize
+ 1 in
5245 if y1 - l.pagey > l.pagevh - d
5246 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5247 else G.postRedisplay "linknav";
5249 showlinktype (getlink
opaque m);
5250 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5253 | None
-> viewkeyboard key mask
5255 | _ -> viewkeyboard key mask
5259 begin match linknav with
5260 | Ltexact pa
-> state
.lnava
<- Some pa
5261 | Ltgendir
_ | Ltnotready
_ -> ()
5264 G.postRedisplay "leave linknav"
5268 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5269 | Ltexact exact
-> doexact exact
5272 let keyboard key mask
=
5273 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5274 then wcmd "interrupt"
5275 else state
.uioh <- state
.uioh#
key key mask
5278 let birdseyekeyboard key mask
5279 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5281 match conf
.columns
with
5283 | Cmulti
((c, _, _), _) -> c
5284 | Csplit
_ -> failwith
"bird's eye split mode"
5286 let pgh layout = List.fold_left
5287 (fun m l -> max
l.pageh
m) state
.winh
layout in
5289 match Wsi.kc2kt
key with
5290 | Ascii '
l'
when Wsi.withctrl mask
->
5291 let y, h = getpageyh
pageno in
5292 let top = (state
.winh
- h) / 2 in
5293 gotoxy state
.x (max
0 (y - top))
5294 | Enter
-> leavebirdseye beye
false
5295 | Escape
-> leavebirdseye beye
true
5296 | Up
-> upbirdseye incr beye
5297 | Down
-> downbirdseye incr beye
5298 | Left
-> upbirdseye 1 beye
5299 | Right
-> downbirdseye 1 beye
5302 begin match state
.layout with
5306 state
.mode <- Birdseye
(
5307 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5309 gotopage1 l.pageno 0;
5312 let layout = layout state
.x (state
.y-state
.winh
)
5314 (pgh state
.layout) in
5316 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5318 state
.mode <- Birdseye
(
5319 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5321 gotopage1 l.pageno 0
5324 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5328 begin match List.rev state
.layout with
5330 let layout = layout state
.x
5331 (state
.y + (pgh state
.layout))
5332 state
.winw state
.winh
in
5333 begin match layout with
5335 let incr = l.pageh
- l.pagevh in
5340 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5342 G.postRedisplay "birdseye pagedown";
5344 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5348 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5349 gotopage1 l.pageno 0;
5352 | [] -> gotoxy state
.x (clamp state
.winh
)
5356 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5360 let pageno = state
.pagecount
- 1 in
5361 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5362 if not
(pagevisible state
.layout pageno)
5365 match List.rev state
.pdims
with
5367 | (_, _, h, _) :: _ -> h
5371 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5372 else G.postRedisplay "birdseye end";
5374 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
5379 match state
.mode with
5380 | Textentry
_ -> scalecolor 0.4
5381 | LinkNav
_ | View
-> scalecolor 1.0
5382 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5383 if l.pageno = hooverpageno
5386 if l.pageno = pageno
5388 let c = scalecolor 1.0 in
5390 GlDraw.line_width
3.0;
5391 let dispx = l.pagedispx in
5393 (float (dispx-1)) (float (l.pagedispy-1))
5394 (float (dispx+l.pagevw+1))
5395 (float (l.pagedispy+l.pagevh+1))
5397 GlDraw.line_width
1.0;
5406 let postdrawpage l linkindexbase
=
5407 match getopaque l.pageno with
5409 if tileready l l.pagex
l.pagey
5411 let x = l.pagedispx - l.pagex
5412 and y = l.pagedispy - l.pagey in
5414 match conf
.columns
with
5415 | Csingle
_ | Cmulti
_ ->
5416 (if conf
.hlinks
then 1 else 0)
5418 && not
(isbirdseye state
.mode) then 2 else 0)
5422 match state
.mode with
5423 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5429 Hashtbl.find_all state
.prects
l.pageno |>
5430 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5431 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5433 then (state
.redisplay
<- true; 0)
5439 let scrollindicator () =
5440 let sbw, ph
, sh = state
.uioh#
scrollph in
5441 let sbh, pw, sw = state
.uioh#scrollpw
in
5446 else ((state
.winw
- sbw), state
.winw
, 0)
5450 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5451 GlDraw.color (0.64, 0.64, 0.64) ~
alpha:0.7;
5452 filledrect (float x0) 0. (float x1) (float state
.winh
);
5454 (float hx0
) (float (state
.winh
- sbh))
5455 (float (hx0
+ state
.winw
)) (float state
.winh
)
5457 GlDraw.color (0.0, 0.0, 0.0) ~
alpha:0.7;
5459 filledrect (float x0) ph
(float x1) (ph
+. sh);
5460 let pw = pw +. float hx0
in
5461 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5466 match state
.mstate
with
5467 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5470 | Msel
((x0, y0), (x1, y1)) ->
5471 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5472 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5473 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5474 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5481 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5482 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5484 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5486 if l.pageno = pageno
5488 let dx = float (l.pagedispx - l.pagex
) in
5489 let dy = float (l.pagedispy - l.pagey) in
5490 let r, g, b, alpha = c in
5491 GlDraw.color (r, g, b) ~
alpha;
5492 filledrect2 (x0+.dx) (y0+.dy)
5504 GlDraw.color (scalecolor2 conf
.bgcolor
);
5505 GlClear.color (scalecolor2 conf
.bgcolor
);
5506 GlClear.clear
[`
color];
5507 List.iter
drawpage state
.layout;
5509 match state
.mode with
5510 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5511 begin match getopaque pageno with
5513 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5514 let color = (0.0, 0.0, 0.5, 0.5) in
5521 | None
-> state
.rects
5523 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5526 | View
-> state
.rects
5529 let rec postloop linkindexbase
= function
5531 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5532 postloop linkindexbase rest
5536 postloop 0 state
.layout;
5538 begin match state
.mstate
with
5539 | Mzoomrect
((x0, y0), (x1, y1)) ->
5541 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5542 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5543 filledrect (float x0) (float y0) (float x1) (float y1);
5547 | Mscrolly
| Mscrollx
5556 let zoomrect x y x1 y1 =
5559 and y0 = min
y y1 in
5560 let zoom = (float state
.w) /. float (x1 - x0) in
5563 if state
.w < state
.winw
5564 then (state
.winw
- state
.w) / 2
5567 match conf
.fitmodel
with
5568 | FitWidth
| FitProportional
-> simple ()
5570 match conf
.columns
with
5572 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5573 | Cmulti
_ | Csingle
_ -> simple ()
5575 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5576 state
.anchor <- getanchor
();
5581 let annot inline
x y =
5582 match unproject x y with
5583 | Some
(opaque, n, ux
, uy
) ->
5585 addannot
opaque ux uy
text;
5586 wcmd "freepage %s" (~
> opaque);
5587 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5589 gotoxy state
.x state
.y
5593 let ondone s = add s in
5594 let mode = state
.mode in
5595 state
.mode <- Textentry
(
5596 ("annotation: ", E.s, None
, textentry
, ondone, true),
5597 fun _ -> state
.mode <- mode);
5600 G.postRedisplay "annot"
5602 add @@ getusertext E.s
5607 let g opaque l px py =
5608 match rectofblock
opaque px py with
5610 let x0 = a.(0) -. 20. in
5611 let x1 = a.(1) +. 20. in
5612 let y0 = a.(2) -. 20. in
5613 let zoom = (float state
.w) /. (x1 -. x0) in
5614 let pagey = getpagey
l.pageno in
5615 let margin = (state
.w - l.pagew
)/2 in
5616 let nx = -truncate
x0 - margin in
5617 gotoxy_and_clear_text nx (pagey + truncate
y0);
5618 state
.anchor <- getanchor
();
5623 match conf
.columns
with
5625 impmsg "block zooming does not work properly in split columns mode"
5626 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5630 let winw = state
.winw - 1 in
5631 let s = float x /. float winw in
5632 let destx = truncate
(float (state
.w + winw) *. s) in
5633 gotoxy_and_clear_text (winw - destx) state
.y;
5634 state
.mstate
<- Mscrollx
;
5638 let s = float y /. float state
.winh
in
5639 let desty = truncate
(s *. float (maxy ())) in
5640 gotoxy_and_clear_text state
.x desty;
5641 state
.mstate
<- Mscrolly
;
5644 let viewmulticlick clicks
x y mask
=
5645 let g opaque l px py =
5653 if markunder
opaque px py mark
5657 match getopaque l.pageno with
5659 | Some
opaque -> pipesel opaque cmd
5661 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5662 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5667 G.postRedisplay "viewmulticlick";
5668 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5672 match conf
.columns
with
5674 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5677 let viewmouse button down
x y mask
=
5679 | n when (n == 4 || n == 5) && not down
->
5680 if Wsi.withctrl mask
5682 match state
.mstate
with
5683 | Mzoom
(oldn
, i
, (ftx
, fty
)) ->
5686 then abs
(ftx
- x) > 5 || abs
(fty
- y) > 5
5696 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5698 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5700 let zoom = conf
.zoom -. incr in
5702 then pivotzoom ~
x ~
y zoom
5703 else pivotzoom zoom;
5704 state
.mstate
<- Mzoom
(n, 0, (x, y));
5706 state
.mstate
<- Mzoom
(n, i
+1, (ftx
, fty
));
5708 else state
.mstate
<- Mzoom
(n, 0, (ftx
, fty
))
5712 | Mscrolly
| Mscrollx
5714 | Mnone
-> state
.mstate
<- Mzoom
(n, 0, (0, 0))
5717 match state
.autoscroll
with
5718 | Some step
-> setautoscrollspeed step
(n=4)
5720 if conf
.wheelbypage
|| conf
.presentation
5729 then -conf
.scrollstep
5730 else conf
.scrollstep
5732 let incr = incr * 2 in
5733 let y = clamp incr in
5734 gotoxy_and_clear_text state
.x y
5737 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5739 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5740 gotoxy_and_clear_text x state
.y
5742 | 1 when Wsi.withshift mask
->
5743 state
.mstate
<- Mnone
;
5746 match unproject x y with
5748 | Some
(_, pageno, ux
, uy
) ->
5749 let cmd = Printf.sprintf
5751 conf
.stcmd state
.path pageno ux uy
5753 match spawn
cmd [] with
5755 impmsg "execution of synctex command(%S) failed: %S"
5756 conf
.stcmd
@@ exntos exn
5760 | 1 when Wsi.withctrl mask
->
5763 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5764 state
.mstate
<- Mpan
(x, y)
5767 state
.mstate
<- Mnone
5772 if Wsi.withshift mask
5774 annot conf
.annotinline
x y;
5775 G.postRedisplay "addannot"
5779 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5780 state
.mstate
<- Mzoomrect
(p, p)
5783 match state
.mstate
with
5784 | Mzoomrect
((x0, y0), _) ->
5785 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5786 then zoomrect x0 y0 x y
5789 G.postRedisplay "kill accidental zoom rect";
5793 | Mscrolly
| Mscrollx
5795 | Mnone
-> resetmstate ()
5798 | 1 when vscrollhit x ->
5801 let _, position, sh = state
.uioh#
scrollph in
5802 if y > truncate
position && y < truncate
(position +. sh)
5803 then state
.mstate
<- Mscrolly
5806 state
.mstate
<- Mnone
5808 | 1 when y > state
.winh
- hscrollh () ->
5811 let _, position, sw = state
.uioh#scrollpw
in
5812 if x > truncate
position && x < truncate
(position +. sw)
5813 then state
.mstate
<- Mscrollx
5816 state
.mstate
<- Mnone
5818 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5821 let dest = if down
then getunder x y else Unone
in
5822 begin match dest with
5826 | Unone
when down
->
5827 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5828 state
.mstate
<- Mpan
(x, y);
5830 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5832 | Unone
| Utext
_ ->
5837 state
.mstate
<- Msel
((x, y), (x, y));
5838 G.postRedisplay "mouse select";
5842 match state
.mstate
with
5845 | Mzoom
_ | Mscrollx
| Mscrolly
->
5846 state
.mstate
<- Mnone
5848 | Mzoomrect
((x0, y0), _) ->
5852 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5853 state
.mstate
<- Mnone
5855 | Msel
((x0, y0), (x1, y1)) ->
5856 let rec loop = function
5860 let a0 = l.pagedispy in
5861 let a1 = a0 + l.pagevh in
5862 let b0 = l.pagedispx in
5863 let b1 = b0 + l.pagevw in
5864 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5865 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5869 match getopaque l.pageno with
5872 match Unix.pipe
() with
5874 impmsg "cannot create sel pipe: %s" @@
5878 Ne.clo fd
(fun msg
->
5879 dolog
"%s close failed: %s" what msg
)
5881 begin match spawn
cmd [r, 0; w, -1] with
5883 clo "Msel pipe/w" w;
5884 dolog
"cannot execute %S: %s" cmd @@ exntos exn
5887 G.postRedisplay "copysel";
5889 clo "Msel pipe/r" r;
5891 dosel conf
.selcmd
();
5892 state
.roam
<- dosel conf
.paxcmd
;
5904 let birdseyemouse button down
x y mask
5905 (conf
, leftx
, _, hooverpageno
, anchor) =
5908 let rec loop = function
5911 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5912 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5914 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5920 | _ -> viewmouse button down
x y mask
5926 method key key mask
=
5927 begin match state
.mode with
5928 | Textentry textentry
-> textentrykeyboard
key mask textentry
5929 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5930 | View
-> viewkeyboard key mask
5931 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5935 method button button bstate
x y mask
=
5936 begin match state
.mode with
5937 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5938 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5943 method multiclick clicks
x y mask
=
5944 begin match state
.mode with
5945 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5946 | Birdseye
_ | Textentry
_ -> ()
5951 begin match state
.mode with
5953 | View
| Birdseye
_ | LinkNav
_ ->
5954 match state
.mstate
with
5955 | Mzoom
_ | Mnone
-> ()
5960 state
.mstate
<- Mpan
(x, y);
5961 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5963 gotoxy_and_clear_text x y
5966 state
.mstate
<- Msel
(a, (x, y));
5967 G.postRedisplay "motion select";
5970 let y = min state
.winh
(max
0 y) in
5974 let x = min state
.winw (max
0 x) in
5977 | Mzoomrect
(p0
, _) ->
5978 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5979 G.postRedisplay "motion zoomrect";
5983 method pmotion
x y =
5984 begin match state
.mode with
5985 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
5986 let rec loop = function
5988 if hooverpageno
!= -1
5990 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
5991 G.postRedisplay "pmotion birdseye no hoover";
5994 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5995 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5997 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
5998 G.postRedisplay "pmotion birdseye hoover";
6006 | LinkNav
_ | View
->
6007 match state
.mstate
with
6008 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6016 let past, _, _ = !r in
6018 let delta = now -. past in
6021 else r := (now, x, y)
6025 method infochanged
_ = ()
6028 let maxy = maxy () in
6031 then 0.0, float state
.winh
6032 else scrollph state
.y maxy
6037 let fwinw = float (state
.winw - vscrollw ()) in
6039 let sw = fwinw /. float state
.w in
6040 let sw = fwinw *. sw in
6041 max
sw (float conf
.scrollh
)
6044 let maxx = state
.w + state
.winw in
6045 let x = state
.winw - state
.x in
6046 let percent = float x /. float maxx in
6047 (fwinw -. sw) *. percent
6049 hscrollh (), position, sw
6053 match state
.mode with
6054 | LinkNav
_ -> "links"
6055 | Textentry
_ -> "textentry"
6056 | Birdseye
_ -> "birdseye"
6059 findkeyhash conf
modename
6061 method eformsgs
= true
6062 method alwaysscrolly
= false
6065 let addrect pageno r g b a x0 y0 x1 y1 =
6066 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6070 let cl = splitatchar cmds ' '
in
6072 try Scanf.sscanf
s fmt
f
6073 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6076 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6077 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6078 s pageno r g b a x0 y0 x1 y1;
6082 let _,w1,h1
,_ = getpagedim
pageno in
6083 let sw = float w1 /. float w
6084 and sh = float h1
/. float h in
6088 and y1s
= y1 *. sh in
6089 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6090 let color = (r, g, b, a) in
6091 if conf
.verbose
then debugrect rect;
6092 state
.rects <- (pageno, color, rect) :: state
.rects;
6097 | "reload", "" -> reload ()
6099 scan args
"%u %f %f"
6101 let cmd, _ = state
.geomcmds
in
6103 then gotopagexy !wtmode pageno x y
6106 gotopagexy !wtmode pageno x y;
6109 state
.reprf
<- f state
.reprf
6111 | "goto1", args
-> scan args
"%u %f" gotopage
6114 (fun _filename _pageno
->
6115 failwith
"gotounder (Uremote (filename, pageno))")
6118 (fun _filename _dest
->
6119 failwith
"gotounder (Uremotedest (filename, dest))")
6121 scan args
"%u %u %f %f %f %f"
6122 (fun pageno c x0 y0 x1 y1 ->
6123 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6124 rectx "rect" pageno color x0 y0 x1 y1;
6127 scan args
"%u %f %f %f %f %f %f %f %f"
6128 (fun pageno r g b alpha x0 y0 x1 y1 ->
6129 addrect pageno r g b alpha x0 y0 x1 y1;
6130 G.postRedisplay "prect"
6133 scan args
"%u %f %f"
6136 match getopaque pageno with
6137 | Some
opaque -> opaque
6140 pgoto optopaque pageno x y;
6141 let rec fixx = function
6144 if l.pageno = pageno
6145 then gotoxy (state
.x - l.pagedispx) state
.y
6150 match conf
.columns
with
6151 | Csingle
_ | Csplit
_ -> 1
6152 | Cmulti
((n, _, _), _) -> n
6154 layout 0 state
.y (state
.winw * mult) state
.winh
6158 | "activatewin", "" -> Wsi.activatewin
()
6159 | "quit", "" -> raise Quit
6162 let l = Config.keys_of_string
keys in
6163 List.iter
(fun (k
, m) -> keyboard k
m) l
6164 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6167 | "clearrects", "" ->
6168 Hashtbl.clear state
.prects
;
6169 G.postRedisplay "clearrects"
6171 adderrfmt "remote command"
6172 "error processing remote command: %S\n" cmds
;
6176 let scratch = Bytes.create
80 in
6177 let buf = Buffer.create
80 in
6179 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6180 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6183 if Buffer.length
buf > 0
6185 let s = Buffer.contents
buf in
6193 match Bytes.index_from
scratch ppos '
\n'
with
6194 | pos
-> if pos
>= n then -1 else pos
6195 | exception Not_found
-> -1
6199 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6200 let s = Buffer.contents
buf in
6206 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6212 let remoteopen path =
6213 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6215 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6220 let gcconfig = ref E.s in
6221 let trimcachepath = ref E.s in
6222 let rcmdpath = ref E.s in
6223 let pageno = ref None
in
6224 let rootwid = ref 0 in
6225 let openlast = ref false in
6226 let doreap = ref false in
6227 let csspath = ref None
in
6228 selfexec := Sys.executable_name
;
6231 [("-p", Arg.String
(fun s -> state
.password <- s),
6232 "<password> Set password");
6236 Config.fontpath
:= s;
6237 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6239 "<path> Set path to the user interface font");
6243 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6244 Config.confpath
:= s),
6245 "<path> Set path to the configuration file");
6247 ("-last", Arg.Set
openlast, " Open last document");
6249 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6250 "<page-number> Jump to page");
6252 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6253 "<path> Set path to the trim cache file");
6255 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6256 "<named-destination> Set named destination");
6258 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6259 ("-cxack", Arg.Set
cxack, " Cut corners");
6261 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6262 "<path> Set path to the source of remote commands");
6264 ("-gc", Arg.Set_string
gcconfig,
6265 "<path> Collect garbage with the help of a script");
6267 ("-v", Arg.Unit
(fun () ->
6269 "%s\nconfiguration path: %s\n"
6272 exit
0), " Print version and exit");
6274 ("-css", Arg.String
(fun s -> csspath := Some
s),
6275 "<path> Set path to the style sheet to use with EPUB/HTML");
6277 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6279 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6280 "<origin> <undocumented>");
6283 (fun s -> state
.path <- s)
6284 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6287 then selfexec := !selfexec ^
" -wtmode";
6289 let histmode = emptystr state
.path && not
!openlast in
6291 if not
(Config.load !openlast)
6292 then dolog
"failed to load configuration";
6294 begin match !pageno with
6295 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6299 if nonemptystr
!gcconfig
6302 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6303 | exception exn
-> error
"socketpair for gc failed: %s" @@ exntos exn
6306 match spawn
!gcconfig [(c, 0); (c, 1); (s, -1)] with
6307 | exception exn
-> error
"failed to execute gc script: %s" @@ exntos exn
6309 Ne.clo c @@ (fun s -> error
"failed to close gc fd %s" s);
6316 val mutable m_clicks
= 0
6317 val mutable m_click_x
= 0
6318 val mutable m_click_y
= 0
6319 val mutable m_lastclicktime
= infinity
6321 method private cleanup =
6322 state
.roam
<- noroam
;
6323 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6324 method expose
= G.postRedisplay "expose"
6328 | Wsi.Unobscured
-> "unobscured"
6329 | Wsi.PartiallyObscured
-> "partiallyobscured"
6330 | Wsi.FullyObscured
-> "fullyobscured"
6332 vlog "visibility change %s" name
6333 method display = display ()
6334 method map mapped
= vlog "mapped %b" mapped
6335 method reshape w h =
6338 method mouse
b d x y m =
6339 if d && canselect ()
6342 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6349 if abs
x - m_click_x
> 10
6350 || abs
y - m_click_y
> 10
6351 || abs_float
(t -. m_lastclicktime
) > 0.3
6353 m_clicks
<- m_clicks
+ 1;
6354 m_lastclicktime
<- t;
6358 G.postRedisplay "cleanup";
6359 state
.uioh <- state
.uioh#button
b d x y m;
6361 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6366 m_lastclicktime
<- infinity
;
6367 state
.uioh <- state
.uioh#button
b d x y m
6371 state
.uioh <- state
.uioh#button
b d x y m
6374 state
.mpos
<- (x, y);
6375 state
.uioh <- state
.uioh#motion
x y
6376 method pmotion
x y =
6377 state
.mpos
<- (x, y);
6378 state
.uioh <- state
.uioh#pmotion
x y
6380 vlog "k=%#x m=%#x" k
m;
6381 let mascm = m land (
6382 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6385 let x = state
.x and y = state
.y in
6387 if x != state
.x || y != state
.y then self#
cleanup
6389 match state
.keystate
with
6391 let km = k
, mascm in
6394 let modehash = state
.uioh#
modehash in
6395 try Hashtbl.find modehash km
6397 try Hashtbl.find (findkeyhash conf
"global") km
6398 with Not_found
-> KMinsrt
(k
, m)
6400 | KMinsrt
(k
, m) -> keyboard k
m
6401 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6402 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6404 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6405 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6406 state
.keystate
<- KSnone
6407 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6408 state
.keystate
<- KSinto
(keys, insrt
)
6409 | KSinto
_ -> state
.keystate
<- KSnone
6412 state
.mpos
<- (x, y);
6413 state
.uioh <- state
.uioh#pmotion
x y
6414 method leave = state
.mpos
<- (-1, -1)
6415 method winstate wsl
= state
.winstate
<- wsl
6416 method quit
= raise Quit
6419 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6421 setbgcol conf
.bgcolor
;
6424 if not
@@ List.exists
GlMisc.check_extension
6425 [ "GL_ARB_texture_rectangle"
6426 ; "GL_EXT_texture_recangle"
6427 ; "GL_NV_texture_rectangle" ]
6428 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6430 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6432 defconf
.sliceheight
<- 1024;
6433 defconf
.texcount
<- 32;
6434 defconf
.usepbo
<- true;
6438 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6440 dolog
"socketpair failed: %s" @@ exntos exn
;
6448 setcheckers conf
.checkers
;
6450 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6452 begin match !csspath with
6454 | Some
"" -> conf
.css
<- E.s
6456 let css = filecontents
path in
6457 let l = String.length
css in
6459 if substratis
css (l-2) "\r\n"
6460 then String.sub css 0 (l-2)
6461 else (if css.[l-1] = '
\n'
6462 then String.sub css 0 (l-1)
6466 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6467 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6468 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6470 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6472 reshape ~firsttime
:true winw winh
;
6476 Wsi.settitle
"llpp (history)";
6480 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6481 opendoc state
.path state
.password;
6485 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6486 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6489 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6490 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6491 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6493 | _pid
, _status
-> reap ()
6495 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6499 if nonemptystr
!rcmdpath
6500 then remoteopen !rcmdpath
6505 let rec loop deadline
=
6511 let r = [state
.ss; state
.wsfd] in
6515 | Some fd
-> fd
:: r
6519 state
.redisplay
<- false;
6526 if deadline
= infinity
6528 else max
0.0 (deadline
-. now)
6533 try Unix.select
r [] [] timeout
6534 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6540 if state
.ghyll
== noghyll
6542 match state
.autoscroll
with
6543 | Some step
when step
!= 0 ->
6544 let y = state
.y + step
in
6545 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6548 then state
.maxy - fy
6549 else if y >= state
.maxy - fy then 0 else y
6551 if state
.mode = View
6552 then gotoxy_and_clear_text state
.x y
6553 else gotoxy state
.x y;
6556 else deadline
+. 0.01
6561 let rec checkfds = function
6563 | fd
:: rest
when fd
= state
.ss ->
6564 let cmd = rcmd state
.ss in
6568 | fd
:: rest
when fd
= state
.wsfd ->
6572 | fd
:: rest
when Some fd
= !optrfd ->
6573 begin match remote fd
with
6574 | None
-> optrfd := remoteopen !rcmdpath;
6575 | opt -> optrfd := opt
6580 dolog
"select returned unknown descriptor";
6586 if deadline
= infinity
6590 match state
.autoscroll
with
6591 | Some step
when step
!= 0 -> deadline1
6592 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6597 match loop infinity
with
6599 Config.save leavebirdseye;
6600 if hasunsavedchanges
()
6602 | _ -> error
"umpossible - infinity reached"