6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
10 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
11 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
12 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
13 external clearmark
: opaque
-> unit = "ml_clearmark";;
14 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
15 external getmaxw
: unit -> float = "ml_getmaxw";;
16 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
17 external measurestr
: int -> string -> float = "ml_measure_string";;
18 external postprocess
:
19 opaque
-> int -> int -> int -> (int * string * int) -> int
21 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
22 external setaalevel
: int -> unit = "ml_setaalevel";;
23 external realloctexts
: int -> bool = "ml_realloctexts";;
24 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
25 external getlink
: opaque
-> int -> under
= "ml_getlink";;
26 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
27 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
28 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
29 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
30 external freepbo
: opaque
-> unit = "ml_freepbo";;
31 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
32 external bousable
: unit -> bool = "ml_bo_usable";;
33 external unproject
: opaque
-> int -> int -> (int * int) option
35 external project
: opaque
-> int -> int -> float -> float -> (float * float)
37 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
38 external rectofblock
: opaque
-> int -> int -> float array
option
40 external begintiles
: unit -> unit = "ml_begintiles";;
41 external endtiles
: unit -> unit = "ml_endtiles";;
42 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
43 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
44 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
45 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
46 external savedoc
: string -> unit = "ml_savedoc";;
47 external getannotcontents
: opaque
-> slinkindex
-> string
48 = "ml_getannotcontents";;
49 external drawprect
: opaque
-> int -> int -> float array
-> unit
51 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
52 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
53 external uritolocation
: string -> (pageno
* float * float)
54 = "ml_uritolocation";;
55 external isexternallink
: string -> bool = "ml_isexternallink";;
57 let selfexec = ref E.s
;;
58 let opengl_has_pbo = ref false;;
60 let drawstring size x y s
=
62 Gl.enable `texture_2d
;
63 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
64 ignore
(drawstr size x y s
);
66 Gl.disable `texture_2d
;
69 let drawstring1 size x y s
=
73 let drawstring2 size x y fmt
=
74 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
77 module UniSyms
= struct
78 let ellipsis = "\xe2\x80\xa6";;
79 let radical = "\xe2\x88\x9a";;
80 let lguillemet = "\xc2\xab";;
81 let rguillemet = "\xc2\xbb";;
96 l
.pagedispx l
.pagedispy
100 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
106 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
109 let isbirdseye = function
111 | Textentry _
| View
| LinkNav _
-> false
114 let istextentry = function
115 | Textentry _
-> true
116 | Birdseye _
| View
| LinkNav _
-> false
119 let wtmode = ref false;;
120 let cxack = ref false;;
122 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
125 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
126 && (state
.w
> state
.winw
))
132 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
133 && (state
.maxy
> state
.winh
))
141 else x
> state
.winw
- vscrollw ()
145 fstate
.fontsize
<- n
;
146 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
147 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
153 else Printf.kprintf ignore fmt
157 if emptystr conf
.pathlauncher
158 then dolog
"%s" state
.path
160 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
161 match spawn
command [] with
164 dolog
"failed to execute `%s': %s" command @@ exntos exn
170 let postRedisplay who
=
171 vlog "redisplay for [%S]" who
;
172 state
.redisplay
<- true;
176 let getopaque pageno
=
177 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
178 with Not_found
-> None
181 let pagetranslatepoint l x y
=
182 let dy = y
- l
.pagedispy
in
183 let y = dy + l
.pagey
in
184 let dx = x
- l
.pagedispx
in
185 let x = dx + l
.pagex
in
189 let onppundermouse g
x y d
=
192 begin match getopaque l
.pageno
with
194 let x0 = l
.pagedispx
in
195 let x1 = x0 + l
.pagevw
in
196 let y0 = l
.pagedispy
in
197 let y1 = y0 + l
.pagevh
in
198 if y >= y0 && y <= y1 && x >= x0 && x <= x1
200 let px, py
= pagetranslatepoint l
x y in
201 match g opaque l
px py
with
214 let g opaque l
px py
=
217 match rectofblock opaque
px py
with
218 | Some
[|x0;x1;y0;y1|] ->
219 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
220 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
221 state
.rects
<- [l
.pageno
, color, rect];
222 G.postRedisplay "getunder";
225 let under = whatsunder opaque
px py
in
226 if under = Unone
then None
else Some
under
228 onppundermouse g x y Unone
233 match unproject opaque
x y with
234 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
237 onppundermouse g x y None
;
241 state
.text
<- Printf.sprintf
"%c%s" c s
;
242 G.postRedisplay "showtext";
246 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
249 let pipesel opaque cmd
=
252 match Unix.pipe
() with
253 | exception exn
-> dolog
"pipesel cannot create pipe: %S" @@ exntos exn
;
255 let doclose what fd
=
256 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
258 begin match spawn cmd
[r
, 0; w
, -1] with
260 doclose "pipesel pipe/w" w
;
261 dolog
"cannot execute %S: %s" cmd
@@ exntos exn
264 G.postRedisplay "pipesel";
266 doclose "pipesel pipe/r" r
;
270 let g opaque l
px py
=
271 if markunder opaque
px py conf
.paxmark
274 match getopaque l
.pageno
with
276 | Some opaque
-> pipesel opaque conf
.paxcmd
281 G.postRedisplay "paxunder";
282 if conf
.paxmark
= Mark_page
285 match getopaque l
.pageno
with
287 | Some opaque
-> clearmark opaque
) state
.layout
;
288 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
292 match Unix.pipe
() with
293 | exception exn
-> impmsg "pipe failed: %s" @@ exntos exn
296 Ne.clo fd
(fun msg
-> impmsg "failed to close %s: %s" cap msg
)
298 begin match spawn conf
.selcmd
[r
, 0; w
, -1] with
300 clo "selstring pipe/w" w
;
301 impmsg "failed to execute %s: %s" conf
.selcmd
@@ exntos exn
304 let l = String.length s
in
305 let bytes = Bytes.unsafe_of_string s
in
306 let n = tempfailureretry
(Unix.write w
bytes 0) l in
308 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n
309 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
311 clo "selstring pipe/r" r
;
314 let undertext = function
317 | Utext s
-> "font: " ^ s
318 | Uannotation
(opaque
, slinkindex
) ->
319 "annotation: " ^ getannotcontents opaque slinkindex
322 let updateunder x y =
323 match getunder x y with
324 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
326 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
327 Wsi.setcursor
Wsi.CURSOR_INFO
329 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
330 Wsi.setcursor
Wsi.CURSOR_TEXT
332 if conf
.underinfo
then showtext 'a'
"nnotation";
333 Wsi.setcursor
Wsi.CURSOR_INFO
336 let showlinktype under =
337 if conf
.underinfo
&& under != Unone
338 then showtext ' '
@@ undertext under
341 let [@warning
"-4"] intentry_with_suffix text key
=
344 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
345 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
346 addchar
text @@ asciilower c
348 state
.text <- Printf.sprintf
"invalid key";
355 let b = Buffer.create
16 in
358 let b = Buffer.to_bytes
b in
359 wcmd state
.ss
b @@ Bytes.length
b
363 let nogeomcmds cmds
=
365 | s
, [] -> emptystr s
369 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
370 let rec fold accu
n =
371 if n = Array.length
b
374 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
377 || n = state
.pagecount
- coverB
378 || (n - coverA
) mod columns
= columns
- 1)
384 let pagey = max
0 (y - vy
) in
385 let pagedispy = if pagey > 0 then 0 else vy
- y in
386 let pagedispx, pagex
=
388 if n = coverA
- 1 || n = state
.pagecount
- coverB
389 then x + (sw
- w
) / 2
397 let vw = sw
- pagedispx in
398 let pw = w
- pagex
in
401 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
402 if pagevw > 0 && pagevh > 0
413 ; pagedispx = pagedispx
414 ; pagedispy = pagedispy
426 if Array.length
b = 0
428 else List.rev
(fold [] (page_of_y
y))
431 let layoutS (columns
, b) x y sw sh
=
432 let rec fold accu n =
433 if n = Array.length
b
436 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
444 let pagey = max
0 (y - vy
) in
445 let pagedispy = if pagey > 0 then 0 else vy
- y in
446 let pagedispx, pagex
=
460 let pagecolw = pagew
/columns
in
463 then pagedispx + ((sw
- pagecolw) / 2)
467 let vw = sw
- pagedispx in
468 let pw = pagew
- pagex
in
471 let pagevw = min
pagevw pagecolw in
472 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
473 if pagevw > 0 && pagevh > 0
484 ; pagedispx = pagedispx
485 ; pagedispy = pagedispy
486 ; pagecol
= n mod columns
500 let layout x y sw sh
=
501 if nogeomcmds state
.geomcmds
503 match conf
.columns
with
504 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
505 | Cmulti c
-> layoutN c
x y sw sh
506 | Csplit s
-> layoutS s
x y sw sh
510 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
512 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
515 let tilex = l.pagex
mod conf
.tilew
in
516 let tiley = l.pagey mod conf
.tileh
in
518 let col = l.pagex
/ conf
.tilew
in
519 let row = l.pagey / conf
.tileh
in
521 let rec rowloop row y0 dispy h
=
525 let dh = conf
.tileh
- y0 in
527 let rec colloop col x0 dispx w
=
531 let dw = conf
.tilew
- x0 in
533 f col row dispx dispy
x0 y0 dw dh;
534 colloop (col+1) 0 (dispx
+dw) (w
-dw)
537 colloop col tilex l.pagedispx l.pagevw;
538 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
541 if l.pagevw > 0 && l.pagevh > 0
542 then rowloop row tiley l.pagedispy l.pagevh;
545 let gettileopaque l col row =
547 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
549 try Some
(Hashtbl.find state
.tilemap
key)
550 with Not_found
-> None
553 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
554 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
555 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
558 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
559 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
560 GlArray.vertex `two state
.vraw
;
561 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
564 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
566 let filledrect x0 y0 x1 y1 =
567 GlArray.disable `texture_coord
;
568 filledrect1 x0 y0 x1 y1;
569 GlArray.enable `texture_coord
;
572 let linerect x0 y0 x1 y1 =
573 GlArray.disable `texture_coord
;
574 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
575 GlArray.vertex `two state
.vraw
;
576 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
577 GlArray.enable `texture_coord
;
580 let drawtiles l color =
583 let f col row x y tilex tiley w h
=
584 match gettileopaque l col row with
585 | Some
(opaque
, _
, t
) ->
586 let params = x, y, w
, h
, tilex, tiley in
588 then GlTex.env
(`mode `blend
);
589 drawtile
params opaque
;
591 then GlTex.env
(`mode `modulate
);
595 let s = Printf.sprintf
599 let w = measurestr fstate
.fontsize
s in
600 GlDraw.color (0.0, 0.0, 0.0);
601 filledrect (float (x-2))
604 (float (y + fstate
.fontsize
+ 2));
606 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
613 let lw = state
.winw
- x in
616 let lh = state
.winh
- y in
620 then GlTex.env
(`mode `blend
);
621 begin match state
.checkerstexid
with
623 Gl.enable `texture_2d
;
624 GlTex.bind_texture ~target
:`texture_2d id
;
628 and y1 = float (y+h
) in
630 let tw = float w /. 16.0
631 and th
= float h
/. 16.0 in
632 let tx0 = float tilex /. 16.0
633 and ty0
= float tiley /. 16.0 in
635 and ty1
= ty0
+. th
in
636 Raw.sets_float state
.vraw ~pos
:0
637 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
638 Raw.sets_float state
.traw ~pos
:0
639 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
640 GlArray.vertex `two state
.vraw
;
641 GlArray.tex_coord `two state
.traw
;
642 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
643 Gl.disable `texture_2d
;
646 GlDraw.color (1.0, 1.0, 1.0);
647 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
650 then GlTex.env
(`mode `modulate
);
651 if w > 128 && h
> fstate
.fontsize
+ 10
653 let c = if conf
.invert
then 1.0 else 0.0 in
654 GlDraw.color (c, c, c);
657 then (col*conf
.tilew
, row*conf
.tileh
)
660 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
669 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
671 let tilevisible1 l x y =
673 and ax1
= l.pagex
+ l.pagevw
675 and ay1
= l.pagey + l.pagevh in
679 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
680 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
682 let rx0 = max
ax0 bx0
683 and ry0
= max ay0 by0
684 and rx1
= min ax1
bx1
685 and ry1
= min ay1 by1
in
687 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
691 let tilevisible layout n x y =
692 let rec findpageinlayout m
= function
693 | l :: rest
when l.pageno
= n ->
694 tilevisible1 l x y || (
695 match conf
.columns
with
696 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
697 | Csplit _
| Csingle _
| Cmulti _
-> false
699 | _
:: rest
-> findpageinlayout 0 rest
702 findpageinlayout 0 layout;
705 let tileready l x y =
706 tilevisible1 l x y &&
707 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
710 let tilepage n p
layout =
711 let rec loop = function
715 let f col row _ _ _ _ _ _
=
716 if state
.currently
= Idle
718 match gettileopaque l col row with
721 let x = col*conf
.tilew
722 and y = row*conf
.tileh
in
724 let w = l.pagew
- x in
728 let h = l.pageh
- y in
733 then getpbo
w h conf
.colorspace
736 wcmd "tile %s %d %d %d %d %s"
737 (~
> p
) x y w h (~
> pbo);
740 l, p
, conf
.colorspace
, conf
.angle
,
741 state
.gen
, col, row, conf
.tilew
, conf
.tileh
750 if nogeomcmds state
.geomcmds
754 let preloadlayout x y sw sh
=
755 let y = if y < sh
then 0 else y - sh
in
756 let x = min
0 (x + sw
) in
764 if state
.currently
!= Idle
769 begin match getopaque l.pageno
with
771 wcmd "page %d %d" l.pageno
l.pagedimno
;
772 state
.currently
<- Loading
(l, state
.gen
);
774 tilepage l.pageno opaque pages
;
779 if nogeomcmds state
.geomcmds
785 if conf
.preload && state
.currently
= Idle
786 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
789 let layoutready layout =
790 let rec fold all ls
=
793 let seen = ref false in
794 let allvisible = ref true in
795 let foo col row _ _ _ _ _ _
=
797 allvisible := !allvisible &&
798 begin match gettileopaque l col row with
804 fold (!seen && !allvisible) rest
807 let alltilesvisible = fold true layout in
812 let y = bound
y 0 state
.maxy in
813 let y, layout, proceed
=
814 match conf
.maxwait
with
815 | Some time
when state
.ghyll
== noghyll
->
816 begin match state
.throttle
with
818 let layout = layout x y state
.winw state
.winh
in
819 let ready = layoutready layout in
823 state
.throttle
<- Some
(layout, y, now
());
825 else G.postRedisplay "gotoxy showall (None)";
827 | Some
(_
, _
, started
) ->
828 let dt = now
() -. started
in
831 state
.throttle
<- None
;
832 let layout = layout x y state
.winw state
.winh
in
834 G.postRedisplay "maxwait";
841 let layout = layout x y state
.winw state
.winh
in
842 if not
!wtmode || layoutready layout
843 then G.postRedisplay "gotoxy ready";
850 state
.layout <- layout;
851 begin match state
.mode
with
854 | Ltexact
(pageno
, linkno
) ->
855 let rec loop = function
857 state
.lnava
<- Some
(pageno
, linkno
);
858 state
.mode
<- LinkNav
(Ltgendir
0)
859 | l :: _
when l.pageno
= pageno
->
860 begin match getopaque pageno
with
861 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
863 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
864 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
865 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
866 then state
.mode
<- LinkNav
(Ltgendir
0)
868 | _
:: rest
-> loop rest
871 | Ltnotready _
| Ltgendir _
-> ()
873 | Birdseye _
| Textentry _
| View
-> ()
875 begin match state
.mode
with
876 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
877 if not
(pagevisible layout pageno
)
879 match state
.layout with
882 state
.mode
<- Birdseye
(
883 conf
, leftx
, l.pageno
, hooverpageno
, anchor
888 | Ltnotready
(_
, dir
)
891 let rec loop = function
894 match getopaque l.pageno
with
895 | None
-> Ltnotready
(l.pageno
, dir
)
900 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
902 if dir
> 0 then LDfirst
else LDlast
908 | Lnotfound
-> loop rest
910 showlinktype (getlink opaque
n);
911 Ltexact
(l.pageno
, n)
915 state
.mode
<- LinkNav
linknav
918 | Textentry _
| View
-> ()
922 state
.ghyll
<- noghyll
;
925 let mx, my
= state
.mpos
in
930 let conttiling pageno opaque
=
931 tilepage pageno opaque
933 then preloadlayout state
.x state
.y state
.winw state
.winh
937 let gotoxy_and_clear_text x y =
938 if not conf
.verbose
then state
.text <- E.s;
942 let getanchory (n, top
, dtop
) =
943 let y, h = getpageyh
n in
946 let ips = calcips
h in
947 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
949 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
952 let gotoanchor anchor
=
953 gotoxy state
.x (getanchory anchor
);
957 cbput state
.hists
.nav
(getanchor
());
961 let anchor = cbgetc state
.hists
.nav dir
in
965 let gotoghyll1 single
y =
967 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
969 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
971 then s (float f /. float a
)
974 then 1.0 -. s ((float (f-b) /. float (n-b)))
980 let ins = float a
*. 0.5
981 and outs
= float (n-b) *. 0.5 in
983 ins +. outs
+. float ones
985 let rec set nab
y sy
=
986 let (_N
, _A
, _B
), y =
989 let scl = if y > sy
then 2 else -2 in
990 let _N, _
, _
= nab
in
991 (_N,0,_N), y+conf
.scrollstep
*scl
993 let sum = summa
_N _A _B
in
994 let dy = float (y - sy
) in
998 then state
.ghyll
<- noghyll
1001 let s = scroll n _N _A _B
in
1002 let y1 = y1 +. ((s *. dy) /. sum) in
1003 gotoxy_and_clear_text state
.x (truncate
y1);
1004 state
.ghyll
<- gf (n+1) y1;
1008 | Some
y'
when single
-> set nab
y' state
.y
1009 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1011 gf 0 (float state
.y)
1014 match conf
.ghyllscroll
with
1015 | Some nab
when not conf
.presentation
->
1016 if state
.ghyll
== noghyll
1017 then set nab
y state
.y
1018 else state
.ghyll
(Some
y)
1020 gotoxy_and_clear_text state
.x y
1023 let gotoghyll = gotoghyll1 false;;
1025 let gotopage n top
=
1026 let y, h = getpageyh
n in
1027 let y = y + (truncate
(top
*. float h)) in
1031 let gotopage1 n top
=
1032 let y = getpagey
n in
1037 let invalidate ?
(redisplay
=false) s f =
1038 state
.redisplay
<- redisplay
;
1043 match state
.geomcmds
with
1044 | ps
, [] when emptystr ps
->
1046 state
.geomcmds
<- s, [];
1049 state
.geomcmds
<- ps
, [s, f];
1051 | ps
, (s'
, _
) :: rest
when s'
= s ->
1052 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1055 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1059 Hashtbl.iter
(fun _ opaque
->
1060 wcmd "freepage %s" (~
> opaque
);
1062 Hashtbl.clear state
.pagemap
;
1066 if not
(Queue.is_empty state
.tilelru
)
1068 Queue.iter
(fun (k
, p
, s) ->
1069 wcmd "freetile %s" (~
> p
);
1070 state
.memused
<- state
.memused
- s;
1071 Hashtbl.remove state
.tilemap k
;
1073 state
.uioh#infochanged Memused
;
1074 Queue.clear state
.tilelru
;
1080 let h = truncate
(float h*.conf
.zoom
) in
1081 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1085 let opendoc path password
=
1087 state
.password
<- password
;
1088 state
.gen
<- state
.gen
+ 1;
1089 state
.docinfo
<- [];
1090 state
.outlines
<- [||];
1093 setaalevel conf
.aalevel
;
1095 if emptystr state
.origin
1099 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1100 wcmd "open %d %d %d %s\000%s\000%s\000"
1101 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1102 path password conf
.css
;
1103 invalidate "reqlayout"
1105 wcmd "reqlayout %d %d %d %s\000"
1106 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1107 (stateh state
.winh
) state
.nameddest
1110 let sl = keystostrlist conf
in
1112 function | [] -> accu
1113 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1114 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1118 state
.anchor <- getanchor
();
1119 opendoc state
.path state
.password
;
1123 let c = c *. conf
.colorscale
in
1127 let scalecolor2 (r
, g, b) =
1128 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1131 let docolumns columns
=
1134 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1135 let rec loop pageno
pdimno pdim
y ph pdims
=
1136 if pageno
= state
.pagecount
1139 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1141 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1142 pdimno+1, pdim
, rest
1146 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1148 y + (if conf
.presentation
1149 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1150 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1153 a.(pageno
) <- (pdimno, x, y, pdim
);
1154 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1156 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1157 conf
.columns
<- Csingle
a;
1159 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1160 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1161 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1163 if m
= pageno
then () else
1164 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1167 let y = y + (rowh
- h) / 2 in
1168 a.(m
) <- (pdimno, x, y, pdim
);
1172 if pageno
= state
.pagecount
1173 then fixrow (((pageno
- 1) / columns
) * columns
)
1175 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1177 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1178 pdimno+1, pdim
, rest
1183 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1185 let x = (state
.winw
- w) / 2 in
1187 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1188 x, y + ips + rowh
, h
1191 if (pageno
- coverA
) mod columns
= 0
1193 let x = max
0 (state
.winw
- state
.w) / 2 in
1195 if conf
.presentation
1197 let ips = calcips
h in
1198 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1200 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1204 else x, y, max rowh
h
1208 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1211 if pageno
= columns
&& conf
.presentation
1213 let ips = calcips rowh
in
1214 for i
= 0 to pred columns
1216 let (pdimno, x, y, pdim
) = a.(i
) in
1217 a.(i
) <- (pdimno, x, y+ips, pdim
)
1223 fixrow (pageno
- columns
);
1228 a.(pageno
) <- (pdimno, x, y, pdim
);
1229 let x = x + w + xoff
*2 + conf
.interpagespace
in
1230 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1232 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1233 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1236 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1237 let rec loop pageno
pdimno pdim
y pdims
=
1238 if pageno
= state
.pagecount
1241 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1243 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1244 pdimno+1, pdim
, rest
1249 let rec loop1 n x y =
1250 if n = c then y else (
1251 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1252 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1255 let y = loop1 0 0 y in
1256 loop (pageno
+1) pdimno pdim
y pdims
1258 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1259 conf
.columns
<- Csplit
(c, a);
1263 docolumns conf
.columns
;
1264 state
.maxy <- calcheight
();
1265 if state
.reprf
== noreprf
1267 match state
.mode
with
1268 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1269 let y, h = getpageyh pageno
in
1270 let top = (state
.winh
- h) / 2 in
1271 gotoxy state
.x (max
0 (y - top))
1272 | Textentry _
| View
| LinkNav _
->
1273 let y = getanchory state
.anchor in
1274 let y = min
y (state
.maxy - state
.winh
) in
1279 state
.reprf
<- noreprf
;
1283 let reshape ?
(firsttime
=false) w h =
1284 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1285 if not firsttime
&& nogeomcmds state
.geomcmds
1286 then state
.anchor <- getanchor
();
1289 let w = truncate
(float w *. conf
.zoom
) in
1292 setfontsize fstate
.fontsize
;
1293 GlMat.mode `modelview
;
1294 GlMat.load_identity
();
1296 GlMat.mode `projection
;
1297 GlMat.load_identity
();
1298 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1299 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1300 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1305 else float state
.x /. float state
.w
1307 invalidate ~redisplay
:true "geometry"
1311 then state
.x <- truncate
(relx *. float w);
1313 match conf
.columns
with
1315 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1316 | Csplit
(c, _
) -> w * c
1318 wcmd "geometry %d %d %d"
1319 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1324 let len = String.length state
.text in
1325 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1328 match state
.mode
with
1329 | Textentry _
| View
| LinkNav _
->
1330 let h, _
, _
= state
.uioh#scrollpw
in
1336 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1337 (x+.w) (float (state
.winh
- hscrollh))
1340 let w = float (state
.winw
- 1 - vscrollw ()) in
1341 if state
.progress
>= 0.0 && state
.progress
< 1.0
1343 GlDraw.color (0.3, 0.3, 0.3);
1344 let w1 = w *. state
.progress
in
1346 GlDraw.color (0.0, 0.0, 0.0);
1347 rect (float x0+.w1) (float x0+.w-.w1)
1350 GlDraw.color (0.0, 0.0, 0.0);
1354 GlDraw.color (1.0, 1.0, 1.0);
1357 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1358 (state
.winh
- hscrollh - 5) s;
1361 match state
.mode
with
1362 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1365 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1366 else Printf.sprintf
"%s%s_" prefix
text
1370 | Birdseye _
| View
| LinkNav _
-> state
.text
1375 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1377 let s1 = "(press 'e' to review error messasges)" in
1378 if nonemptystr
s then s ^
" " ^
s1 else s1
1388 let len = Queue.length state
.tilelru
in
1390 match state
.throttle
with
1393 then preloadlayout state
.x state
.y state
.winw state
.winh
1395 | Some
(layout, _
, _
) ->
1399 if state
.memused
> conf
.memlimit
1403 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1404 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1405 let (_
, pw, ph
, _
) = getpagedim
n in
1407 && colorspace
= conf
.colorspace
1408 && angle
= conf
.angle
1412 let x = col*conf
.tilew
1413 and y = row*conf
.tileh
in
1414 tilevisible (Lazy.force_val
layout) n x y
1416 then Queue.push lruitem state
.tilelru
1419 wcmd "freetile %s" (~
> p
);
1420 state
.memused
<- state
.memused
- s;
1421 state
.uioh#infochanged Memused
;
1422 Hashtbl.remove state
.tilemap k
;
1430 let onpagerect pageno
f =
1432 match conf
.columns
with
1433 | Cmulti
(_
, b) -> b
1435 | Csplit
(_
, b) -> b
1437 if pageno
>= 0 && pageno
< Array.length
b
1439 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1443 let gotopagexy1 wtmode pageno
x y =
1444 let _,w1,h1
,leftx
= getpagedim pageno
in
1445 let top = y /. (float h1
) in
1446 let left = x /. (float w1) in
1447 let py, w, h = getpageywh pageno
in
1448 let wh = state
.winh
in
1449 let x = left *. (float w) in
1450 let x = leftx
+ state
.x + truncate
x in
1452 if x < 0 || x >= state
.winw
1456 let pdy = truncate
(top *. float h) in
1457 let y'
= py + pdy in
1458 let dy = y'
- state
.y in
1460 if x != state
.x || not
(dy > 0 && dy < wh)
1462 if conf
.presentation
1464 if abs
(py - y'
) > wh
1471 if state
.x != sx || state
.y != sy
1476 let ww = state
.winw
in
1478 and qy
= pdy / wh in
1480 and y = py + qy
* wh in
1481 let x = if -x + ww > w1 then -(w1-ww) else x
1482 and y'
= if y + wh > state
.maxy then state
.maxy - wh else y in
1484 if conf
.presentation
1486 if abs
(py - y'
) > wh
1495 gotoxy_and_clear_text x y;
1497 else gotoxy_and_clear_text state
.x state
.y;
1500 let gotopagexy wtmode pageno
x y =
1501 match state
.mode
with
1502 | Birdseye
_ -> gotopage pageno
0.0
1503 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1506 let getpassword () =
1507 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1512 impmsg "error getting password: %s" s;
1513 dolog
"%s" s) passcmd;
1516 let pgoto opaque pageno
x y =
1517 let pdimno = getpdimno pageno
in
1518 let x, y = project opaque pageno
pdimno x y in
1519 gotopagexy false pageno
x y;
1523 (* dolog "%S" cmds; *)
1524 let spl = splitatchar cmds ' '
in
1526 try Scanf.sscanf
s fmt
f
1528 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1531 let addoutline outline
=
1532 match state
.currently
with
1533 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1534 | Idle
-> state
.currently
<- Outlining
[outline
]
1535 | Loading
_ | Tiling
_ ->
1536 dolog
"invalid outlining state";
1537 logcurrently state
.currently
1542 state
.uioh#infochanged Pdim
;
1544 | "clearrects", "" ->
1545 state
.rects
<- state
.rects1
;
1546 G.postRedisplay "clearrects";
1548 | "continue", args
->
1549 let n = scan args
"%u" (fun n -> n) in
1550 state
.pagecount
<- n;
1551 begin match state
.currently
with
1553 state
.currently
<- Idle
;
1554 state
.outlines
<- Array.of_list
(List.rev
l)
1555 | Idle
| Loading
_ | Tiling
_ -> ()
1558 let cur, cmds
= state
.geomcmds
in
1560 then failwith
"umpossible";
1562 begin match List.rev cmds
with
1564 state
.geomcmds
<- E.s, [];
1565 state
.throttle
<- None
;
1569 state
.geomcmds
<- s, List.rev rest
;
1571 if conf
.maxwait
= None
&& not
!wtmode
1572 then G.postRedisplay "continue";
1579 then showtext ' ' args
1582 Buffer.add_string state
.errmsgs args
;
1583 state
.newerrmsgs
<- true;
1584 G.postRedisplay "error message"
1586 | "progress", args
->
1587 let progress, text =
1590 f, String.sub args pos
(String.length args
- pos
))
1593 state
.progress <- progress;
1594 G.postRedisplay "progress"
1596 | "firstmatch", args
->
1597 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1598 scan args
"%u %d %f %f %f %f %f %f %f %f"
1599 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1600 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1602 let y = (getpagey
pageno) + truncate
y0 in
1610 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1611 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1614 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1615 scan args
"%u %d %f %f %f %f %f %f %f %f"
1616 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1617 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1619 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1621 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1624 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1625 let pageopaque = ~
< pageopaques in
1626 begin match state
.currently
with
1627 | Loading
(l, gen
) ->
1628 vlog "page %d took %f sec" l.pageno t
;
1629 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1630 begin match state
.throttle
with
1632 let preloadedpages =
1634 then preloadlayout state
.x state
.y state
.winw state
.winh
1639 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1640 IntSet.empty
preloadedpages
1643 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1644 if not
(IntSet.mem
pageno set)
1646 wcmd "freepage %s" (~
> opaque
);
1652 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1655 state
.currently
<- Idle
;
1658 tilepage l.pageno pageopaque state
.layout;
1660 load preloadedpages;
1661 let visible = pagevisible state
.layout l.pageno in
1664 match state
.mode
with
1665 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1666 if pageno = l.pageno
1671 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1673 if dir
> 0 then LDfirst
else LDlast
1676 findlink
pageopaque ld
1681 showlinktype (getlink
pageopaque n);
1682 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1684 | LinkNav
(Ltgendir
_)
1685 | LinkNav
(Ltexact
_)
1691 if visible && layoutready state
.layout
1693 G.postRedisplay "page";
1697 | Some
(layout, _, _) ->
1698 state
.currently
<- Idle
;
1699 tilepage l.pageno pageopaque layout;
1703 | Idle
| Tiling
_ | Outlining
_ ->
1704 dolog
"Inconsistent loading state";
1705 logcurrently state
.currently
;
1710 let (x, y, opaques
, size
, t
) =
1711 scan args
"%u %u %s %u %f"
1712 (fun x y p size t
-> (x, y, p
, size
, t
))
1714 let opaque = ~
< opaques
in
1715 begin match state
.currently
with
1716 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1717 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1720 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1722 wcmd "freetile %s" (~
> opaque);
1723 state
.currently
<- Idle
;
1727 puttileopaque l col row gen cs angle
opaque size t
;
1728 state
.memused
<- state
.memused
+ size
;
1729 state
.uioh#infochanged Memused
;
1731 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1732 opaque, size
) state
.tilelru
;
1735 match state
.throttle
with
1736 | None
-> state
.layout
1737 | Some
(layout, _, _) -> layout
1740 state
.currently
<- Idle
;
1742 && conf
.colorspace
= cs
1743 && conf
.angle
= angle
1744 && tilevisible layout l.pageno x y
1745 then conttiling l.pageno pageopaque;
1747 begin match state
.throttle
with
1749 preload state
.layout;
1751 && conf
.colorspace
= cs
1752 && conf
.angle
= angle
1753 && tilevisible state
.layout l.pageno x y
1754 && (not
!wtmode || layoutready state
.layout)
1755 then G.postRedisplay "tile nothrottle";
1757 | Some
(layout, y, _) ->
1758 let ready = layoutready layout in
1762 state
.layout <- layout;
1763 state
.throttle
<- None
;
1764 G.postRedisplay "throttle";
1770 | Idle
| Loading
_ | Outlining
_ ->
1771 dolog
"Inconsistent tiling state";
1772 logcurrently state
.currently
;
1777 let (n, w, h, _) as pdim
=
1778 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1781 match conf
.fitmodel
with
1783 | FitPage
| FitProportional
->
1784 match conf
.columns
with
1785 | Csplit
_ -> (n, w, h, 0)
1786 | Csingle
_ | Cmulti
_ -> pdim
1788 state
.pdims
<- pdim :: state
.pdims
;
1789 state
.uioh#infochanged Pdim
1792 let (l, n, t
, h, pos
) =
1793 scan args
"%u %u %d %u %n"
1794 (fun l n t
h pos
-> l, n, t
, h, pos
)
1796 let s = String.sub args pos
(String.length args
- pos
) in
1797 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1800 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1801 let s = String.sub args pos
len in
1802 let pos2 = pos
+ len + 1 in
1803 let uri = String.sub args
pos2 (String.length args
- pos2) in
1804 addoutline (s, l, Ouri
uri)
1807 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1808 let s = String.sub args pos
(String.length args
- pos
) in
1809 addoutline (s, l, Onone
)
1813 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1815 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1818 let c, v
= splitatchar args '
\t'
in
1829 if let len = String.length
c in
1830 len > 6 && ((String.sub
c (len-4) 4) = "date")
1832 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1834 let b = Buffer.create
10 in
1835 Printf.bprintf
b "%s\t" c;
1838 Buffer.add_substring
b v p
l;
1839 Buffer.add_char
b c;
1840 with exn
-> Buffer.add_string
b @@ exntos exn
1848 Buffer.add_char
b '
['
;
1849 Buffer.add_string
b v
;
1850 Buffer.add_char
b '
]'
;
1857 state
.docinfo
<- (1, s) :: state
.docinfo
1860 state
.docinfo
<- List.rev state
.docinfo
;
1861 state
.uioh#infochanged Docinfo
1865 then Wsi.settitle
"Wrong password";
1866 let password = getpassword () in
1867 if emptystr
password
1868 then error
"document is password protected"
1869 else opendoc state
.path
password
1872 error
"unknown cmd `%S'" cmds
1877 let action = function
1878 | HCprev
-> cbget cb ~
-1
1879 | HCnext
-> cbget cb
1
1880 | HCfirst
-> cbget cb ~
-(cb
.rc)
1881 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1882 and cancel
() = cb
.rc <- rc
1886 let search pattern forward
=
1887 match conf
.columns
with
1888 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1889 | Csingle
_ | Cmulti
_ ->
1890 if nonemptystr pattern
1893 match state
.layout with
1896 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1898 wcmd "search %d %d %d %d,%s\000"
1899 (btod conf
.icase
) pn py (btod forward
) pattern
;
1902 let [@warning
"-4"] intentry
text key =
1905 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1907 state
.text <- "invalid key";
1917 let l = String.length
s in
1918 let rec loop pos
n =
1922 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1923 loop (pos
+1) (n*26 + m)
1926 let rec loop n = function
1929 match getopaque l.pageno with
1930 | None
-> loop n rest
1932 let m = getlinkcount
opaque in
1935 let under = getlink
opaque n in
1938 else loop (n-m) rest
1940 loop n state
.layout;
1944 let [@warning
"-4"] linknentry
text = function
1946 let text = addchar
text c in
1947 linknact (fun under -> state
.text <- undertext under) text;
1950 state
.text <- Printf.sprintf
"invalid key";
1954 let [@warning
"-4"] textentry
text = function
1955 | Keys.Ascii
c -> TEcont
(addchar
text c)
1956 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1960 let reqlayout angle fitmodel
=
1961 match state
.throttle
with
1963 if nogeomcmds state
.geomcmds
1964 then state
.anchor <- getanchor
();
1965 conf
.angle
<- angle
mod 360;
1968 match state
.mode
with
1969 | LinkNav
_ -> state
.mode
<- View
1970 | Birdseye
_ | Textentry
_ | View
-> ()
1972 conf
.fitmodel
<- fitmodel
;
1976 wcmd "reqlayout %d %d %d"
1977 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1982 let settrim trimmargins trimfuzz
=
1983 if nogeomcmds state
.geomcmds
1984 then state
.anchor <- getanchor
();
1985 conf
.trimmargins
<- trimmargins
;
1986 conf
.trimfuzz
<- trimfuzz
;
1987 let x0, y0, x1, y1 = trimfuzz
in
1989 "settrim" (fun () ->
1990 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1995 match state
.throttle
with
1997 let zoom = max
0.0001 zoom in
1998 if zoom <> conf
.zoom
2000 state
.prevzoom
<- (conf
.zoom, state
.x);
2002 reshape state
.winw state
.winh
;
2003 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2006 | Some
(layout, y, started
) ->
2008 match conf
.maxwait
with
2012 let dt = now
() -. started
in
2020 let pivotzoom ?
(vw=min state
.w state
.winw
)
2021 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
2022 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2023 let w = float state
.w /. zoom in
2024 let hw = w /. 2.0 in
2025 let ratio = float vh
/. float vw in
2026 let hh = hw *. ratio in
2027 let x0 = if zoom < 1.0 then 0.0 else float x -. hw in
2028 let y0 = float y -. hh in
2029 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2033 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2034 if nogeomcmds state
.geomcmds
then pivotzoom ?
vw ?vh ?
x ?
y zoom
2037 let setcolumns mode columns coverA coverB
=
2038 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2042 then impmsg "split mode doesn't work in bird's eye"
2044 conf
.columns
<- Csplit
(-columns
, E.a);
2052 conf
.columns
<- Csingle
E.a;
2057 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2061 reshape state
.winw state
.winh
;
2064 let resetmstate () =
2065 state
.mstate
<- Mnone
;
2066 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2069 let enterbirdseye () =
2070 let zoom = float conf
.thumbw
/. float state
.winw
in
2071 let birdseyepageno =
2072 let cy = state
.winh
/ 2 in
2076 let rec fold best
= function
2079 let d = cy - (l.pagedispy + l.pagevh/2)
2080 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2081 if abs
d < abs dbest
2090 { conf
with zoom = conf
.zoom },
2091 state
.x, birdseyepageno, -1, getanchor
()
2095 conf
.presentation
<- false;
2096 conf
.interpagespace
<- 10;
2097 conf
.hlinks
<- false;
2098 conf
.fitmodel
<- FitPage
;
2100 conf
.maxwait
<- None
;
2102 match conf
.beyecolumns
with
2105 Cmulti
((c, 0, 0), E.a)
2106 | None
-> Csingle
E.a
2110 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2115 reshape state
.winw state
.winh
;
2118 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2120 conf
.zoom <- c.zoom;
2121 conf
.presentation
<- c.presentation
;
2122 conf
.interpagespace
<- c.interpagespace
;
2123 conf
.maxwait
<- c.maxwait
;
2124 conf
.hlinks
<- c.hlinks
;
2125 conf
.fitmodel
<- c.fitmodel
;
2126 conf
.beyecolumns
<- (
2127 match conf
.columns
with
2128 | Cmulti
((c, _, _), _) -> Some
c
2130 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2133 match c.columns
with
2134 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2135 | Csingle
_ -> Csingle
E.a
2136 | Csplit
(c, _) -> Csplit
(c, E.a)
2140 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2143 reshape state
.winw state
.winh
;
2144 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2148 let togglebirdseye () =
2149 match state
.mode
with
2150 | Birdseye vals
-> leavebirdseye vals
true
2151 | View
-> enterbirdseye ()
2152 | Textentry
_ | LinkNav
_ -> ()
2155 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2156 let pageno = max
0 (pageno - incr
) in
2157 let rec loop = function
2158 | [] -> gotopage1 pageno 0
2159 | l :: _ when l.pageno = pageno ->
2160 if l.pagedispy >= 0 && l.pagey = 0
2161 then G.postRedisplay "upbirdseye"
2162 else gotopage1 pageno 0
2163 | _ :: rest
-> loop rest
2167 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2170 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2171 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2172 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2173 let rec loop = function
2175 let y, h = getpageyh
pageno in
2176 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2177 gotoxy state
.x (clamp dy)
2178 | l :: _ when l.pageno = pageno ->
2179 if l.pagevh != l.pageh
2180 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2181 else G.postRedisplay "downbirdseye"
2182 | _ :: rest
-> loop rest
2188 let [@warning
"-4"] optentry mode
_ key =
2189 let btos b = if b then "on" else "off" in
2193 try conf
.scrollstep
<- int_of_string
s with exn
->
2194 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2196 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2201 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2202 if state
.autoscroll
<> None
2203 then state
.autoscroll
<- Some conf
.autoscrollstep
2205 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2207 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2212 let n, a, b = multicolumns_of_string
s in
2213 setcolumns mode
n a b;
2215 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2217 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2222 let zoom = float (int_of_string
s) /. 100.0 in
2225 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2227 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2232 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2234 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2235 begin match mode
with
2237 leavebirdseye beye
false;
2239 | Textentry
_ | View
| LinkNav
_ -> ();
2242 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2244 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2248 match int_of_string
s with
2249 | angle
-> reqlayout angle conf
.fitmodel
2251 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2253 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2256 conf
.icase
<- not conf
.icase
;
2257 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2260 conf
.preload <- not conf
.preload;
2261 gotoxy state
.x state
.y;
2262 TEdone
("preload " ^
(btos conf
.preload))
2265 conf
.verbose
<- not conf
.verbose
;
2266 TEdone
("verbose " ^
(btos conf
.verbose
))
2269 conf
.debug
<- not conf
.debug
;
2270 TEdone
("debug " ^
(btos conf
.debug
))
2273 conf
.maxhfit
<- not conf
.maxhfit
;
2274 state
.maxy <- calcheight
();
2275 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2278 conf
.crophack
<- not conf
.crophack
;
2279 TEdone
("crophack " ^
btos conf
.crophack
)
2283 match conf
.maxwait
with
2285 conf
.maxwait
<- Some infinity
;
2286 "always wait for page to complete"
2288 conf
.maxwait
<- None
;
2289 "show placeholder if page is not ready"
2294 conf
.underinfo
<- not conf
.underinfo
;
2295 TEdone
("underinfo " ^
btos conf
.underinfo
)
2298 conf
.savebmarks
<- not conf
.savebmarks
;
2299 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2305 match state
.layout with
2310 conf
.interpagespace
<- int_of_string
s;
2311 docolumns conf
.columns
;
2312 state
.maxy <- calcheight
();
2313 let y = getpagey
pageno in
2314 gotoxy state
.x (y + py)
2316 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2318 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2322 match conf
.fitmodel
with
2323 | FitProportional
-> FitWidth
2324 | FitWidth
| FitPage
-> FitProportional
2326 reqlayout conf
.angle
fm;
2327 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2330 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2331 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2334 conf
.invert
<- not conf
.invert
;
2335 TEdone
("invert colors " ^
btos conf
.invert
)
2339 cbput state
.hists
.sel
s;
2342 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2343 textentry
, ondone, true)
2347 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2348 else conf
.pax
<- None
;
2349 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2352 state
.text <- Printf.sprintf
"bad option %d `%c'"
2360 class type lvsource
=
2362 method getitemcount
: int
2363 method getitem
: int -> (string * int)
2364 method hasaction
: int -> bool
2365 method exit
: uioh
:uioh
->
2371 method getactive
: int
2372 method getfirst
: int
2374 method getminfo
: (int * int) array
2377 class virtual lvsourcebase
= object
2378 val mutable m_active
= 0
2379 val mutable m_first
= 0
2380 val mutable m_pan
= 0
2381 method getactive
= m_active
2382 method getfirst
= m_first
2383 method getpan
= m_pan
2384 method getminfo
: (int * int) array
= E.a
2387 let [@warning
"-4"] textentrykeyboard
2388 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2391 state
.mode
<- Textentry
(te
, onleave
);
2393 G.postRedisplay "textentrykeyboard enttext";
2395 let histaction cmd
=
2398 | Some
(action, _) ->
2401 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2403 G.postRedisplay "textentry histaction"
2405 let open Keys
in let kt = Wsi.kc2kt
key in
2408 if emptystr
text && cancelonempty
2411 G.postRedisplay "textentrykeyboard after cancel";
2414 let s = withoutlastutf8
text in
2415 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2420 G.postRedisplay "textentrykeyboard after confirm"
2422 | Up
-> histaction HCprev
2423 | Down
-> histaction HCnext
2424 | Home
-> histaction HCfirst
2425 | End
-> histaction HClast
2430 begin match opthist
with
2432 | Some
(_, onhistcancel
) -> onhistcancel
()
2436 G.postRedisplay "textentrykeyboard after cancel2"
2439 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2444 | Code
_ | Ascii
_ ->
2445 begin match onkey
text kt with
2449 G.postRedisplay "textentrykeyboard after confirm2";
2452 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2456 G.postRedisplay "textentrykeyboard after cancel3"
2459 state
.mode
<- Textentry
(te
, onleave
);
2460 G.postRedisplay "textentrykeyboard switch";
2462 | _ -> vlog "unhandled key"
2465 let firstof first active
=
2466 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2467 then max
0 (active
- (fstate
.maxrows
/2))
2471 let calcfirst first active
=
2474 let rows = active
- first
in
2475 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2479 let scrollph y maxy =
2480 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2481 let sh = float state
.winh
/. sh in
2482 let sh = max
sh (float conf
.scrollh
) in
2484 let percent = float y /. float maxy in
2485 let position = (float state
.winh
-. sh) *. percent in
2488 if position +. sh > float state
.winh
2489 then float state
.winh
-. sh
2495 let adderrmsg src msg
=
2496 Buffer.add_string state
.errmsgs msg
;
2497 state
.newerrmsgs
<- true;
2501 let adderrfmt src fmt
=
2502 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2505 let coe s = (s :> uioh
);;
2507 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2509 val m_pan
= source#getpan
2510 val m_first
= source#getfirst
2511 val m_active
= source#getactive
2513 val m_prev_uioh
= state
.uioh
2515 method private elemunder
y =
2519 let n = y / (fstate
.fontsize
+1) in
2520 if m_first
+ n < source#getitemcount
2522 if source#hasaction
(m_first
+ n)
2523 then Some
(m_first
+ n)
2530 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2531 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2532 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2533 GlDraw.color (1., 1., 1.);
2534 Gl.enable `texture_2d
;
2535 let fs = fstate
.fontsize
in
2537 let hw = state
.winw
/3 in
2538 let ww = fstate
.wwidth
in
2539 let tabw = 17.0*.ww in
2540 let itemcount = source#getitemcount
in
2541 let minfo = source#getminfo
in
2545 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2547 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2549 if (row - m_first
) > fstate
.maxrows
2552 if row >= 0 && row < itemcount
2554 let (s, level
) = source#getitem
row in
2555 let y = (row - m_first
) * nfs in
2556 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2559 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2563 Gl.disable `texture_2d
;
2564 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2565 GlDraw.color (1., 1., 1.) ~
alpha;
2566 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2567 Gl.enable `texture_2d
;
2570 if zebra
&& row land 1 = 1
2574 GlDraw.color (c,c,c);
2575 let drawtabularstring s =
2577 let x'
= truncate
(x0 +. x) in
2578 let s1, s2
= splitatchar
s '
\000'
in
2580 then drawstring1 fs x'
(y+nfs) s
2586 let s'
= withoutlastutf8
s in
2587 let s = s' ^
UniSyms.ellipsis in
2588 let w = measurestr
fs s in
2589 if float x'
+. w +. ww < float (hw + x'
)
2594 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2598 ignore
(drawstring1 fs x'
(y+nfs) s1);
2599 drawstring1 fs (hw + x'
) (y+nfs) s2
2603 let x = if helpmode
&& row > 0 then x +. ww else x in
2604 let s1, s2
= splitatchar
s '
\t'
in
2607 let nx = drawstr x s1 in
2609 let x = x +. (max
tabw sw) in
2612 let len = String.length
s - 2 in
2613 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2615 let s = String.sub s 2 len in
2616 let x = if not helpmode
then x +. ww else x in
2617 GlDraw.color (1.2, 1.2, 1.2);
2618 let vinc = drawstring1 (fs+fs/4)
2619 (truncate
(x -. ww)) (y+nfs) s in
2620 GlDraw.color (1., 1., 1.);
2621 vinc +. (float fs *. 0.8)
2627 ignore
(drawtabularstring s);
2633 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2636 if (row - m_first
) <= fstate
.maxrows
2638 if row >= 0 && row < itemcount
2640 let (s, level
) = source#getitem
row in
2641 let pos0 = nindex
s '
\000'
in
2642 let y = (row - m_first
) * nfs in
2643 let x = float (level
+ m_pan
) *. ww in
2644 let (first
, last
) = minfo.(row) in
2646 if pos0 > 0 && first
> pos0
2647 then String.sub s (pos0+1) (first
-pos0-1)
2648 else String.sub s 0 first
2650 let suffix = String.sub s first
(last
- first
) in
2651 let w1 = measurestr fstate
.fontsize
prefix in
2652 let w2 = measurestr fstate
.fontsize
suffix in
2653 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2654 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2656 and y0 = float (y+2) in
2658 and y1 = float (y+fs+3) in
2659 filledrect x0 y0 x1 y1;
2663 Gl.disable `texture_2d
;
2664 if Array.length
minfo > 0 then loop m_first
;
2669 method updownlevel incr
=
2670 let len = source#getitemcount
in
2672 if m_active
>= 0 && m_active
< len
2673 then snd
(source#getitem m_active
)
2677 if i
= len then i
-1 else if i
= -1 then 0 else
2678 let _, l = source#getitem i
in
2679 if l != curlevel then i
else flow (i
+incr
)
2681 let active = flow m_active
in
2682 let first = calcfirst m_first
active in
2683 G.postRedisplay "outline updownlevel";
2684 {< m_active
= active; m_first
= first >}
2686 method private key1
key mask
=
2687 let set1 active first qsearch
=
2688 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2690 let search active pattern incr
=
2691 let active = if active = -1 then m_first
else active in
2694 if n >= 0 && n < source#getitemcount
2696 let s, _ = source#getitem
n in
2697 match Str.search_forward re
s 0 with
2698 | exception Not_found
-> loop (n + incr
)
2705 let qpat = Str.quote pattern
in
2706 match Str.regexp_case_fold
qpat with
2709 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2710 qpat @@ Printexc.to_string exn
;
2713 let itemcount = source#getitemcount
in
2714 let find start incr
=
2716 if i
= -1 || i
= itemcount
2719 if source#hasaction i
2721 else find (i
+ incr
)
2726 let set active first =
2727 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2729 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2732 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2734 let incr1 = if incr
> 0 then 1 else -1 in
2735 if isvisible m_first m_active
2738 let next = m_active
+ incr
in
2740 if next < 0 || next >= itemcount
2742 else find next incr1
2744 if abs
(m_active
- next) > fstate
.maxrows
2750 let first = m_first
+ incr
in
2751 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2753 let next = m_active
+ incr
in
2754 let next = bound
next 0 (itemcount - 1) in
2761 if isvisible first next
2768 let first = min
next m_first
in
2770 if abs
(next - first) > fstate
.maxrows
2776 let first = m_first
+ incr
in
2777 let first = bound
first 0 (itemcount - 1) in
2779 let next = m_active
+ incr
in
2780 let next = bound
next 0 (itemcount - 1) in
2781 let next = find next incr1 in
2783 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2785 let active = if m_active
= -1 then next else m_active
in
2790 if isvisible first active
2796 G.postRedisplay "listview navigate";
2800 let kt = Wsi.kc2kt
key in
2801 match [@warning
"-4"] kt with
2802 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2803 let incr = if c = 'r'
then -1 else 1 in
2805 match search (m_active
+ incr) m_qsearch
incr with
2807 state
.text <- m_qsearch ^
" [not found]";
2810 state
.text <- m_qsearch
;
2811 active, firstof m_first
active
2813 G.postRedisplay "listview ctrl-r/s";
2814 set1 active first m_qsearch
;
2816 | Insert
when Wsi.withctrl mask
->
2817 if m_active
>= 0 && m_active
< source#getitemcount
2819 let s, _ = source#getitem m_active
in
2825 if emptystr m_qsearch
2828 let qsearch = withoutlastutf8 m_qsearch
in
2832 G.postRedisplay "listview empty qsearch";
2833 set1 m_active m_first
E.s;
2837 match search m_active
qsearch ~
-1 with
2839 state
.text <- qsearch ^
" [not found]";
2842 state
.text <- qsearch;
2843 active, firstof m_first
active
2845 G.postRedisplay "listview backspace qsearch";
2846 set1 active first qsearch
2849 | Ascii
_ | Code
_ ->
2851 match [@warning
"-4"] kt with
2852 | Ascii
c -> String.make
1 c
2853 | Code code
-> toutf8 code
2856 let pattern = m_qsearch ^
utf8 in
2858 match search m_active
pattern 1 with
2860 state
.text <- pattern ^
" [not found]";
2863 state
.text <- pattern;
2864 active, firstof m_first
active
2866 G.postRedisplay "listview qsearch add";
2867 set1 active first pattern;
2871 if emptystr m_qsearch
2873 G.postRedisplay "list view escape";
2874 let mx, my
= state
.mpos
in
2876 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2877 ~
first:m_first ~pan
:m_pan
with
2878 | None
-> m_prev_uioh
2882 G.postRedisplay "list view kill qsearch";
2883 coe {< m_qsearch
= E.s >}
2888 let self = {< m_qsearch
= E.s >} in
2890 G.postRedisplay "listview enter";
2891 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2892 source#exit ~uioh
:(coe self) ~
cancel
2893 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2895 begin match opt with
2896 | None
-> m_prev_uioh
2903 | Up
-> navigate ~
-1
2904 | Down
-> navigate 1
2905 | Prior
-> navigate ~
-(fstate
.maxrows
)
2906 | Next
-> navigate fstate
.maxrows
2910 G.postRedisplay "listview right";
2911 coe {< m_pan
= m_pan
- 1 >}
2915 G.postRedisplay "listview left";
2916 coe {< m_pan
= m_pan
+ 1 >}
2919 let active = find 0 1 in
2920 G.postRedisplay "listview home";
2924 let first = max
0 (itemcount - fstate
.maxrows
) in
2925 let active = find (itemcount - 1) ~
-1 in
2926 G.postRedisplay "listview end";
2931 method key key mask
=
2932 match state
.mode
with
2934 textentrykeyboard
key mask te
;
2936 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2938 method button button down
x y _ =
2941 | 1 when vscrollhit x ->
2942 G.postRedisplay "listview scroll";
2945 let _, position, sh = self#
scrollph in
2946 if y > truncate
position && y < truncate
(position +. sh)
2948 state
.mstate
<- Mscrolly
;
2952 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2953 let first = truncate
(s *. float source#getitemcount
) in
2954 let first = min source#getitemcount
first in
2955 Some
(coe {< m_first
= first; m_active
= first >})
2957 state
.mstate
<- Mnone
;
2961 begin match self#elemunder
y with
2963 G.postRedisplay "listview click";
2964 source#exit ~uioh
:(coe {< m_active
= n >})
2965 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2969 | n when (n == 4 || n == 5) && not down
->
2970 let len = source#getitemcount
in
2972 if n = 5 && m_first
+ fstate
.maxrows
>= len
2976 let first = m_first
+ (if n == 4 then -1 else 1) in
2977 bound
first 0 (len - 1)
2979 G.postRedisplay "listview wheel";
2980 Some
(coe {< m_first
= first >})
2981 | n when (n = 6 || n = 7) && not down
->
2982 let inc = if n = 7 then -1 else 1 in
2983 G.postRedisplay "listview hwheel";
2984 Some
(coe {< m_pan
= m_pan
+ inc >})
2989 | None
-> m_prev_uioh
2992 method multiclick
_ x y = self#button
1 true x y
2995 match state
.mstate
with
2997 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2998 let first = truncate
(s *. float source#getitemcount
) in
2999 let first = min source#getitemcount
first in
3000 G.postRedisplay "listview motion";
3001 coe {< m_first
= first; m_active
= first >}
3009 method pmotion
x y =
3010 if x < state
.winw
- conf
.scrollbw
3013 match self#elemunder
y with
3014 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3015 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3019 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3024 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3028 method infochanged
_ = ()
3030 method scrollpw
= (0, 0.0, 0.0)
3032 let nfs = fstate
.fontsize
+ 1 in
3033 let y = m_first
* nfs in
3034 let itemcount = source#getitemcount
in
3035 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3036 let maxy = maxi * nfs in
3037 let p, h = scrollph y maxy in
3040 method modehash
= modehash
3041 method eformsgs
= false
3042 method alwaysscrolly
= true
3045 class outlinelistview ~zebra ~source
=
3046 let settext autonarrow
s =
3049 let ss = source#statestr
in
3053 else "{" ^
ss ^
"} [" ^
s ^
"]"
3054 else state
.text <- s
3060 ~source
:(source
:> lvsource
)
3062 ~modehash
:(findkeyhash conf
"outline")
3065 val m_autonarrow
= false
3067 method! key key mask
=
3069 if emptystr state
.text
3071 else fstate
.maxrows - 2
3073 let calcfirst first active =
3076 let rows = active - first in
3077 if rows > maxrows then active - maxrows else first
3081 let active = m_active
+ incr in
3082 let active = bound
active 0 (source#getitemcount
- 1) in
3083 let first = calcfirst m_first
active in
3084 G.postRedisplay "outline navigate";
3085 coe {< m_active
= active; m_first
= first >}
3087 let navscroll first =
3089 let dist = m_active
- first in
3095 else first + maxrows
3098 G.postRedisplay "outline navscroll";
3099 coe {< m_first
= first; m_active
= active >}
3101 let ctrl = Wsi.withctrl mask
in
3103 match Wsi.kc2kt
key with
3104 | Ascii '
a'
when ctrl ->
3107 then (source#denarrow
; E.s)
3109 let pattern = source#renarrow
in
3110 if nonemptystr m_qsearch
3111 then (source#narrow m_qsearch
; m_qsearch
)
3115 settext (not m_autonarrow
) text;
3116 G.postRedisplay "toggle auto narrowing";
3117 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3119 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3121 G.postRedisplay "toggle auto narrowing";
3122 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3124 | Ascii '
n'
when ctrl ->
3125 source#narrow m_qsearch
;
3127 then source#add_narrow_pattern m_qsearch
;
3128 G.postRedisplay "outline ctrl-n";
3129 coe {< m_first
= 0; m_active
= 0 >}
3131 | Ascii 'S'
when ctrl ->
3132 let active = source#calcactive
(getanchor
()) in
3133 let first = firstof m_first
active in
3134 G.postRedisplay "outline ctrl-s";
3135 coe {< m_first
= first; m_active
= active >}
3137 | Ascii 'u'
when ctrl ->
3138 G.postRedisplay "outline ctrl-u";
3139 if m_autonarrow
&& nonemptystr m_qsearch
3141 ignore
(source#renarrow
);
3142 settext m_autonarrow
E.s;
3143 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3146 source#del_narrow_pattern
;
3147 let pattern = source#renarrow
in
3149 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3151 settext m_autonarrow
text;
3152 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3155 | Ascii '
l'
when ctrl ->
3156 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3157 G.postRedisplay "outline ctrl-l";
3158 coe {< m_first
= first >}
3160 | Ascii '
\t'
when m_autonarrow
->
3161 if nonemptystr m_qsearch
3163 G.postRedisplay "outline list view tab";
3164 source#add_narrow_pattern m_qsearch
;
3166 coe {< m_qsearch
= E.s >}
3170 | Escape
when m_autonarrow
->
3171 if nonemptystr m_qsearch
3172 then source#add_narrow_pattern m_qsearch
;
3175 | Enter
when m_autonarrow
->
3176 if nonemptystr m_qsearch
3177 then source#add_narrow_pattern m_qsearch
;
3180 | (Ascii
_ | Code
_) when m_autonarrow
->
3181 let pattern = m_qsearch ^ toutf8
key in
3182 G.postRedisplay "outlinelistview autonarrow add";
3183 source#narrow
pattern;
3184 settext true pattern;
3185 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3187 | Backspace
when m_autonarrow
->
3188 if emptystr m_qsearch
3191 let pattern = withoutlastutf8 m_qsearch
in
3192 G.postRedisplay "outlinelistview autonarrow backspace";
3193 ignore
(source#renarrow
);
3194 source#narrow
pattern;
3195 settext true pattern;
3196 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3199 navscroll (max
0 (m_first
- 1))
3202 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3204 | Up
-> navigate ~
-1
3205 | Down
-> navigate 1
3206 | Prior
-> navigate ~
-(fstate
.maxrows)
3207 | Next
-> navigate fstate
.maxrows
3213 G.postRedisplay "outline ctrl right";
3214 {< m_pan
= m_pan
+ 1 >}
3216 else self#updownlevel
1
3224 G.postRedisplay "outline ctrl left";
3225 {< m_pan
= m_pan
- 1 >}
3227 else self#updownlevel ~
-1
3232 G.postRedisplay "outline home";
3233 coe {< m_first
= 0; m_active
= 0 >}
3236 let active = source#getitemcount
- 1 in
3237 let first = max
0 (active - fstate
.maxrows) in
3238 G.postRedisplay "outline end";
3239 coe {< m_active
= active; m_first
= first >}
3241 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Backspace
|Fn
_ ->
3245 let genhistoutlines () =
3247 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3248 compare c2
.lastvisit c1
.lastvisit
)
3249 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3250 let path = if nonemptystr origin
then origin
else path in
3251 let base = mbtoutf8
@@ Filename.basename
path in
3252 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3256 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3257 Config.save
leavebirdseye;
3258 state
.anchor <- anchor;
3259 state
.bookmarks
<- bookmarks
;
3260 state
.origin
<- origin
;
3263 let x0, y0, x1, y1 = conf
.trimfuzz
in
3264 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3265 reshape ~firsttime
:true state
.winw state
.winh
;
3266 opendoc path origin
;
3270 let makecheckers () =
3271 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3273 converted by Issac Trotts. July 25, 2002 *)
3274 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3275 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3276 let id = GlTex.gen_texture
() in
3277 GlTex.bind_texture ~target
:`texture_2d
id;
3278 GlPix.store
(`unpack_alignment
1);
3279 GlTex.image2d
image;
3280 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3281 [ `mag_filter `nearest
; `min_filter `nearest
];
3285 let setcheckers enabled
=
3286 match state
.checkerstexid
with
3288 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3290 | Some checkerstexid
->
3293 GlTex.delete_texture checkerstexid
;
3294 state
.checkerstexid
<- None
;
3298 let describe_location () =
3299 let fn = page_of_y state
.y in
3300 let ln = page_of_y
(state
.y + state
.winh
- 1) in
3301 let maxy = maxy () in
3305 else 100. *. (float state
.y /. float maxy)
3309 Printf.sprintf
"page %d of %d [%.2f%%]"
3310 (fn+1) state
.pagecount
percent
3313 "pages %d-%d of %d [%.2f%%]"
3314 (fn+1) (ln+1) state
.pagecount
percent
3317 let setpresentationmode v
=
3318 let n = page_of_y state
.y in
3319 state
.anchor <- (n, 0.0, 1.0);
3320 conf
.presentation
<- v
;
3321 if conf
.fitmodel
= FitPage
3322 then reqlayout conf
.angle conf
.fitmodel
;
3326 let setbgcol (r
, g, b) =
3328 let r = r *. 255.0 |> truncate
3329 and g = g *. 255.0 |> truncate
3330 and b = b *. 255.0 |> truncate
in
3331 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3333 Wsi.setwinbgcol
col;
3337 let btos b = if b then UniSyms.radical else E.s in
3338 let showextended = ref false in
3339 let leave mode
_ = state
.mode
<- mode
in
3342 val mutable m_l
= []
3343 val mutable m_a
= E.a
3344 val mutable m_prev_uioh
= nouioh
3345 val mutable m_prev_mode
= View
3347 inherit lvsourcebase
3349 method reset prev_mode prev_uioh
=
3350 m_a
<- Array.of_list
(List.rev m_l
);
3352 m_prev_mode
<- prev_mode
;
3353 m_prev_uioh
<- prev_uioh
;
3355 method int name get
set =
3361 try set (int_of_string
s)
3363 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3367 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3368 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3372 method int_with_suffix name get
set =
3374 (name
, `intws get
, 1,
3378 try set (int_of_string_with_suffix
s)
3380 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3385 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3387 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3391 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3393 (name
, `
bool (btos, get
), offset
, Action
(
3400 method color name get
set =
3402 (name
, `
color get
, 1,
3405 let invalid = (nan
, nan
, nan
) in
3408 try color_of_string
s
3410 state
.text <- Printf.sprintf
"bad color `%s': %s"
3417 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3418 state
.text <- color_to_string
(get
());
3419 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3423 method string name get
set =
3425 (name
, `
string get
, 1,
3428 let ondone s = set s in
3429 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3430 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3434 method colorspace name get
set =
3436 (name
, `
string get
, 1,
3441 inherit lvsourcebase
3444 m_active
<- CSTE.to_int conf
.colorspace
;
3447 method getitemcount
=
3448 Array.length
CSTE.names
3451 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3452 ignore
(uioh
, first, pan
);
3453 if not
cancel then set active;
3455 method hasaction
_ = true
3459 let modehash = findkeyhash conf
"info" in
3460 coe (new listview ~zebra
:false ~helpmode
:false
3461 ~
source ~trusted
:true ~
modehash)
3464 method paxmark name get
set =
3466 (name
, `
string get
, 1,
3471 inherit lvsourcebase
3474 m_active
<- MTE.to_int conf
.paxmark
;
3477 method getitemcount
= Array.length
MTE.names
3478 method getitem
n = (MTE.names
.(n), 0)
3479 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3480 ignore
(uioh
, first, pan
);
3481 if not
cancel then set active;
3483 method hasaction
_ = true
3487 let modehash = findkeyhash conf
"info" in
3488 coe (new listview ~zebra
:false ~helpmode
:false
3489 ~
source ~trusted
:true ~
modehash)
3492 method fitmodel name get
set =
3494 (name
, `
string get
, 1,
3499 inherit lvsourcebase
3502 m_active
<- FMTE.to_int conf
.fitmodel
;
3505 method getitemcount
= Array.length
FMTE.names
3506 method getitem
n = (FMTE.names
.(n), 0)
3507 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3508 ignore
(uioh
, first, pan
);
3509 if not
cancel then set active;
3511 method hasaction
_ = true
3515 let modehash = findkeyhash conf
"info" in
3516 coe (new listview ~zebra
:false ~helpmode
:false
3517 ~
source ~trusted
:true ~
modehash)
3520 method caption
s offset
=
3521 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3523 method caption2
s f offset
=
3524 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3526 method getitemcount
= Array.length m_a
3529 let tostr = function
3530 | `
int f -> string_of_int
(f ())
3531 | `intws
f -> string_with_suffix_of_int
(f ())
3533 | `
color f -> color_to_string
(f ())
3534 | `
bool (btos, f) -> btos (f ())
3537 let name, t
, offset
, _ = m_a
.(n) in
3538 ((let s = tostr t
in
3540 then Printf.sprintf
"%s\t%s" name s
3544 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3549 match m_a
.(active) with
3550 | _, _, _, Action
f -> f uioh
3551 | _, _, _, Noaction
-> uioh
3562 method hasaction
n =
3564 | _, _, _, Action
_ -> true
3565 | _, _, _, Noaction
-> false
3567 initializer m_active
<- 1
3570 let rec fillsrc prevmode prevuioh
=
3571 let sep () = src#caption
E.s 0 in
3572 let colorp name get
set =
3574 (fun () -> color_to_string
(get
()))
3577 let c = color_of_string
v in
3581 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3584 let oldmode = state
.mode
in
3585 let birdseye = isbirdseye state
.mode
in
3587 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3589 src#
bool "presentation mode"
3590 (fun () -> conf
.presentation
)
3591 (fun v -> setpresentationmode v);
3593 src#
bool "ignore case in searches"
3594 (fun () -> conf
.icase
)
3595 (fun v -> conf
.icase
<- v);
3598 (fun () -> conf
.preload)
3599 (fun v -> conf
.preload <- v);
3601 src#
bool "highlight links"
3602 (fun () -> conf
.hlinks
)
3603 (fun v -> conf
.hlinks
<- v);
3605 src#
bool "under info"
3606 (fun () -> conf
.underinfo
)
3607 (fun v -> conf
.underinfo
<- v);
3609 src#
bool "persistent bookmarks"
3610 (fun () -> conf
.savebmarks
)
3611 (fun v -> conf
.savebmarks
<- v);
3613 src#fitmodel
"fit model"
3614 (fun () -> FMTE.to_string conf
.fitmodel
)
3615 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3617 src#
bool "trim margins"
3618 (fun () -> conf
.trimmargins
)
3619 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3621 src#
bool "persistent location"
3622 (fun () -> conf
.jumpback
)
3623 (fun v -> conf
.jumpback
<- v);
3626 src#
int "inter-page space"
3627 (fun () -> conf
.interpagespace
)
3629 conf
.interpagespace
<- n;
3630 docolumns conf
.columns
;
3632 match state
.layout with
3637 state
.maxy <- calcheight
();
3638 let y = getpagey
pageno in
3639 gotoxy state
.x (y + py)
3643 (fun () -> conf
.pagebias
)
3644 (fun v -> conf
.pagebias
<- v);
3646 src#
int "scroll step"
3647 (fun () -> conf
.scrollstep
)
3648 (fun n -> conf
.scrollstep
<- n);
3650 src#
int "horizontal scroll step"
3651 (fun () -> conf
.hscrollstep
)
3652 (fun v -> conf
.hscrollstep
<- v);
3654 src#
int "auto scroll step"
3656 match state
.autoscroll
with
3658 | _ -> conf
.autoscrollstep
)
3660 let n = boundastep state
.winh
n in
3661 if state
.autoscroll
<> None
3662 then state
.autoscroll
<- Some
n;
3663 conf
.autoscrollstep
<- n);
3666 (fun () -> truncate
(conf
.zoom *. 100.))
3667 (fun v -> pivotzoom ((float v) /. 100.));
3670 (fun () -> conf
.angle
)
3671 (fun v -> reqlayout v conf
.fitmodel
);
3673 src#
int "scroll bar width"
3674 (fun () -> conf
.scrollbw
)
3677 reshape state
.winw state
.winh
;
3680 src#
int "scroll handle height"
3681 (fun () -> conf
.scrollh
)
3682 (fun v -> conf
.scrollh
<- v;);
3684 src#
int "thumbnail width"
3685 (fun () -> conf
.thumbw
)
3687 conf
.thumbw
<- min
4096 v;
3690 leavebirdseye beye
false;
3697 let mode = state
.mode in
3698 src#
string "columns"
3700 match conf
.columns
with
3702 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3703 | Csplit
(count
, _) -> "-" ^ string_of_int count
3706 let n, a, b = multicolumns_of_string
v in
3707 setcolumns mode n a b);
3710 src#caption
"Pixmap cache" 0;
3711 src#int_with_suffix
"size (advisory)"
3712 (fun () -> conf
.memlimit
)
3713 (fun v -> conf
.memlimit
<- v);
3717 Printf.sprintf
"%s bytes, %d tiles"
3718 (string_with_suffix_of_int state
.memused
)
3719 (Hashtbl.length state
.tilemap
)) 1;
3722 src#caption
"Layout" 0;
3723 src#caption2
"Dimension"
3725 Printf.sprintf
"%dx%d (virtual %dx%d)"
3726 state
.winw state
.winh
3731 src#caption2
"Position" (fun () ->
3732 Printf.sprintf
"%dx%d" state
.x state
.y
3735 src#caption2
"Position" (fun () -> describe_location ()) 1
3739 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3740 "Save these parameters as global defaults at exit"
3741 (fun () -> conf
.bedefault
)
3742 (fun v -> conf
.bedefault
<- v)
3746 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3747 src#
bool ~offset
:0 ~
btos "Extended parameters"
3748 (fun () -> !showextended)
3749 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3753 (fun () -> conf
.checkers
)
3754 (fun v -> conf
.checkers
<- v; setcheckers v);
3755 src#
bool "update cursor"
3756 (fun () -> conf
.updatecurs
)
3757 (fun v -> conf
.updatecurs
<- v);
3758 src#
bool "scroll-bar on the left"
3759 (fun () -> conf
.leftscroll
)
3760 (fun v -> conf
.leftscroll
<- v);
3762 (fun () -> conf
.verbose
)
3763 (fun v -> conf
.verbose
<- v);
3764 src#
bool "invert colors"
3765 (fun () -> conf
.invert
)
3766 (fun v -> conf
.invert
<- v);
3768 (fun () -> conf
.maxhfit
)
3769 (fun v -> conf
.maxhfit
<- v);
3771 (fun () -> conf
.pax
!= None
)
3774 then conf
.pax
<- Some
(ref (now
(), 0, 0))
3775 else conf
.pax
<- None
);
3776 src#
string "uri launcher"
3777 (fun () -> conf
.urilauncher
)
3778 (fun v -> conf
.urilauncher
<- v);
3779 src#
string "path launcher"
3780 (fun () -> conf
.pathlauncher
)
3781 (fun v -> conf
.pathlauncher
<- v);
3782 src#
string "tile size"
3783 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3786 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3787 conf
.tilew
<- max
64 w;
3788 conf
.tileh
<- max
64 h;
3791 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3794 src#
int "texture count"
3795 (fun () -> conf
.texcount
)
3798 then conf
.texcount
<- v
3799 else impmsg "failed to set texture count please retry later"
3801 src#
int "slice height"
3802 (fun () -> conf
.sliceheight
)
3804 conf
.sliceheight
<- v;
3805 wcmd "sliceh %d" conf
.sliceheight
;
3807 src#
int "anti-aliasing level"
3808 (fun () -> conf
.aalevel
)
3810 conf
.aalevel
<- bound
v 0 8;
3811 state
.anchor <- getanchor
();
3812 opendoc state
.path state
.password;
3814 src#
string "page scroll scaling factor"
3815 (fun () -> string_of_float conf
.pgscale)
3818 let s = float_of_string
v in
3821 state
.text <- Printf.sprintf
3822 "bad page scroll scaling factor `%s': %s" v
3826 src#
int "ui font size"
3827 (fun () -> fstate
.fontsize
)
3828 (fun v -> setfontsize (bound
v 5 100));
3829 src#
int "hint font size"
3830 (fun () -> conf
.hfsize
)
3831 (fun v -> conf
.hfsize
<- bound
v 5 100);
3832 colorp "background color"
3833 (fun () -> conf
.bgcolor
)
3834 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3835 src#
bool "crop hack"
3836 (fun () -> conf
.crophack
)
3837 (fun v -> conf
.crophack
<- v);
3838 src#
string "trim fuzz"
3839 (fun () -> irect_to_string conf
.trimfuzz
)
3842 conf
.trimfuzz
<- irect_of_string
v;
3844 then settrim true conf
.trimfuzz
;
3846 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3849 src#
string "throttle"
3851 match conf
.maxwait
with
3852 | None
-> "show place holder if page is not ready"
3855 then "wait for page to fully render"
3857 "wait " ^ string_of_float
time
3858 ^
" seconds before showing placeholder"
3862 let f = float_of_string
v in
3864 then conf
.maxwait
<- None
3865 else conf
.maxwait
<- Some
f
3867 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3870 src#
string "ghyll scroll"
3872 match conf
.ghyllscroll
with
3874 | Some nab
-> ghyllscroll_to_string nab
3877 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3880 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3882 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3885 src#
string "selection command"
3886 (fun () -> conf
.selcmd
)
3887 (fun v -> conf
.selcmd
<- v);
3888 src#
string "synctex command"
3889 (fun () -> conf
.stcmd
)
3890 (fun v -> conf
.stcmd
<- v);
3891 src#
string "pax command"
3892 (fun () -> conf
.paxcmd
)
3893 (fun v -> conf
.paxcmd
<- v);
3894 src#
string "ask password command"
3895 (fun () -> conf
.passcmd)
3896 (fun v -> conf
.passcmd <- v);
3897 src#
string "save path command"
3898 (fun () -> conf
.savecmd
)
3899 (fun v -> conf
.savecmd
<- v);
3900 src#colorspace
"color space"
3901 (fun () -> CSTE.to_string conf
.colorspace
)
3903 conf
.colorspace
<- CSTE.of_int
v;
3907 src#paxmark
"pax mark method"
3908 (fun () -> MTE.to_string conf
.paxmark
)
3909 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3910 if bousable
() && !opengl_has_pbo
3913 (fun () -> conf
.usepbo
)
3914 (fun v -> conf
.usepbo
<- v);
3915 src#
bool "mouse wheel scrolls pages"
3916 (fun () -> conf
.wheelbypage
)
3917 (fun v -> conf
.wheelbypage
<- v);
3918 src#
bool "open remote links in a new instance"
3919 (fun () -> conf
.riani
)
3920 (fun v -> conf
.riani
<- v);
3921 src#
bool "edit annotations inline"
3922 (fun () -> conf
.annotinline
)
3923 (fun v -> conf
.annotinline
<- v);
3924 src#
bool "coarse positioning in presentation mode"
3925 (fun () -> conf
.coarseprespos
)
3926 (fun v -> conf
.coarseprespos
<- v);
3927 src#
bool "use document CSS"
3928 (fun () -> conf
.usedoccss
)
3930 conf
.usedoccss
<- v;
3931 state
.anchor <- getanchor
();
3932 opendoc state
.path state
.password;
3937 src#caption
"Document" 0;
3938 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3939 src#caption2
"Pages"
3940 (fun () -> string_of_int state
.pagecount
) 1;
3941 src#caption2
"Dimensions"
3942 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3943 if nonemptystr conf
.css
3944 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3948 src#caption
"Trimmed margins" 0;
3949 src#caption2
"Dimensions"
3950 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3954 src#caption
"OpenGL" 0;
3955 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3956 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3959 src#caption
"Location" 0;
3960 if nonemptystr state
.origin
3961 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3962 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3964 src#reset prevmode prevuioh
;
3969 let prevmode = state
.mode
3970 and prevuioh
= state
.uioh in
3971 fillsrc prevmode prevuioh
;
3972 let source = (src :> lvsource
) in
3973 let modehash = findkeyhash conf
"info" in
3976 inherit listview ~zebra
:false ~helpmode
:false
3977 ~
source ~trusted
:true ~
modehash as super
3978 val mutable m_prevmemused
= 0
3979 method! infochanged
= function
3981 if m_prevmemused
!= state
.memused
3983 m_prevmemused
<- state
.memused
;
3984 G.postRedisplay "memusedchanged";
3986 | Pdim
-> G.postRedisplay "pdimchanged"
3987 | Docinfo
-> fillsrc prevmode prevuioh
3989 method! key key mask
=
3990 if not
(Wsi.withctrl mask
)
3992 match [@warning
"-4"] Wsi.kc2kt
key with
3993 | Keys.Left
-> coe (self#updownlevel ~
-1)
3994 | Keys.Right
-> coe (self#updownlevel
1)
3995 | _ -> super#
key key mask
3996 else super#
key key mask
3998 G.postRedisplay "info";
4004 inherit lvsourcebase
4005 method getitemcount
= Array.length state
.help
4007 let s, l, _ = state
.help
.(n) in
4010 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4014 match state
.help
.(active) with
4015 | _, _, Action
f -> Some
(f uioh)
4016 | _, _, Noaction
-> Some
uioh
4025 method hasaction
n =
4026 match state
.help
.(n) with
4027 | _, _, Action
_ -> true
4028 | _, _, Noaction
-> false
4034 let modehash = findkeyhash conf
"help" in
4036 state
.uioh <- coe (new listview
4037 ~zebra
:false ~helpmode
:true
4038 ~
source ~trusted
:true ~
modehash);
4039 G.postRedisplay "help";
4045 inherit lvsourcebase
4046 val mutable m_items
= E.a
4048 method getitemcount
= 1 + Array.length m_items
4053 else m_items
.(n-1), 0
4055 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4060 then Buffer.clear state
.errmsgs
;
4067 method hasaction
n =
4071 state
.newerrmsgs
<- false;
4072 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4073 m_items
<- Array.of_list
l
4082 let source = (msgsource :> lvsource
) in
4083 let modehash = findkeyhash conf
"listview" in
4086 inherit listview ~zebra
:false ~helpmode
:false
4087 ~
source ~trusted
:false ~
modehash as super
4090 then msgsource#reset
;
4093 G.postRedisplay "msgs";
4097 let editor = getenvwithdef
"EDITOR" E.s in
4101 let tmppath = Filename.temp_file
"llpp" "note" in
4104 let oc = open_out
tmppath in
4108 let execstr = editor ^
" " ^
tmppath in
4110 match spawn
execstr [] with
4112 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4115 match Unix.waitpid
[] pid
with
4117 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4121 | Unix.WEXITED
0 -> filecontents
tmppath
4123 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4125 | Unix.WSIGNALED
n ->
4126 impmsg "editor process(%s) was killed by signal %d" execstr n;
4128 | Unix.WSTOPPED
n ->
4129 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4132 match Unix.unlink
tmppath with
4134 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4139 let enterannotmode opaque slinkindex
=
4142 inherit lvsourcebase
4143 val mutable m_text
= E.s
4144 val mutable m_items
= E.a
4146 method getitemcount
= Array.length m_items
4149 let label, _func
= m_items
.(n) in
4152 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4153 ignore
(uioh, first, pan
);
4156 let _label, func
= m_items
.(active) in
4161 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4164 let rec split accu b i
=
4166 if p = String.length
s
4167 then (String.sub s b (p-b), unit) :: accu
4169 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4171 let ss = if i
= 0 then E.s else String.sub s b i
in
4172 split ((ss, unit)::accu) (p+1) 0
4177 wcmd "freepage %s" (~
> opaque);
4179 Hashtbl.fold (fun key opaque'
accu ->
4180 if opaque'
= opaque'
4181 then key :: accu else accu) state
.pagemap
[]
4183 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4185 gotoxy state
.x state
.y
4188 delannot
opaque slinkindex
;
4191 let edit inline
() =
4196 modannot
opaque slinkindex
s;
4202 let mode = state
.mode in
4205 ("annotation: ", m_text
, None
, textentry
, update, true),
4206 fun _ -> state
.mode <- mode);
4210 let s = getusertext m_text
in
4215 ( "[Copy]", fun () -> selstring m_text
)
4216 :: ("[Delete]", dele)
4217 :: ("[Edit]", edit conf
.annotinline
)
4219 :: split [] 0 0 |> List.rev
|> Array.of_list
4226 let s = getannotcontents
opaque slinkindex
in
4229 let source = (msgsource :> lvsource
) in
4230 let modehash = findkeyhash conf
"listview" in
4231 state
.uioh <- coe (object
4232 inherit listview ~zebra
:false ~helpmode
:false
4233 ~
source ~trusted
:false ~
modehash
4235 G.postRedisplay "enterannotmode";
4238 let gotoremote spec
=
4239 let filename, dest
= splitatchar spec '#'
in
4240 let getpath filename =
4242 if nonemptystr
filename
4244 if Filename.is_relative
filename
4246 let dir = Filename.dirname state
.path in
4248 if Filename.is_implicit
dir
4249 then Filename.concat
(Sys.getcwd
()) dir
4252 Filename.concat
dir filename
4256 if Sys.file_exists
path
4260 let path = getpath filename in
4264 let cmd = Lazy.force_val lcmd
in
4265 match spawn
cmd with
4267 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4269 let anchor = getanchor
() in
4270 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4271 state
.origin
<- E.s;
4272 state
.ranchors
<- ranchor :: state
.ranchors
;
4275 if substratis spec
0 "page="
4277 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4279 state
.anchor <- (pageno, 0.0, 0.0);
4280 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4282 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4284 state
.nameddest
<- dest
;
4285 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4289 let gotounder = function
4290 | Ulinkuri
s when isexternallink
s ->
4291 if substratis
s 0 "file://"
4292 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4295 let pageno, x, y = uritolocation
s in
4297 gotopagexy !wtmode pageno x y
4298 | Utext
_ | Unone
-> ()
4299 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4302 let gotooutline (_, _, kind
) =
4306 let (pageno, y, _) = anchor in
4308 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4312 | Ouri
uri -> gotounder (Ulinkuri
uri)
4313 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4314 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4315 | Ohistory hist
-> gotohist hist
4316 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4319 class outlinesoucebase fetchoutlines
= object (self)
4320 inherit lvsourcebase
4321 val mutable m_items
= E.a
4322 val mutable m_minfo
= E.a
4323 val mutable m_orig_items
= E.a
4324 val mutable m_orig_minfo
= E.a
4325 val mutable m_narrow_patterns
= []
4326 val mutable m_gen
= -1
4328 method getitemcount
= Array.length m_items
4331 let s, n, _ = m_items
.(n) in
4334 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4335 ignore
(uioh, first);
4337 if m_narrow_patterns
= []
4338 then m_orig_items
, m_orig_minfo
4339 else m_items
, m_minfo
4346 gotooutline m_items
.(active);
4354 method hasaction
(_:int) = true
4357 if Array.length m_items
!= Array.length m_orig_items
4360 match m_narrow_patterns
with
4362 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4364 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4368 match m_narrow_patterns
with
4371 | head
:: _ -> UniSyms.ellipsis ^ head
4373 method narrow
pattern =
4374 match Str.regexp_case_fold
pattern with
4377 let rec loop accu minfo n =
4380 m_items
<- Array.of_list
accu;
4381 m_minfo
<- Array.of_list
minfo;
4384 let (s, _, _) as o = m_items
.(n) in
4386 match Str.search_forward re
s 0 with
4387 | exception Not_found
-> accu, minfo
4388 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4390 loop accu minfo (n-1)
4392 loop [] [] (Array.length m_items
- 1)
4394 method! getminfo
= m_minfo
4397 m_orig_items
<- fetchoutlines
();
4398 m_minfo
<- m_orig_minfo
;
4399 m_items
<- m_orig_items
4401 method add_narrow_pattern
pattern =
4402 m_narrow_patterns
<- pattern :: m_narrow_patterns
4404 method del_narrow_pattern
=
4405 match m_narrow_patterns
with
4406 | _ :: rest
-> m_narrow_patterns
<- rest
4411 match m_narrow_patterns
with
4412 | pattern :: [] -> self#narrow
pattern; pattern
4414 List.fold_left
(fun accu pattern ->
4415 self#narrow
pattern;
4416 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4418 method calcactive
(_:anchor) = 0
4420 method reset
anchor items =
4421 if state
.gen
!= m_gen
4423 m_orig_items
<- items;
4425 m_narrow_patterns
<- [];
4427 m_orig_minfo
<- E.a;
4431 if items != m_orig_items
4433 m_orig_items
<- items;
4434 if m_narrow_patterns
== []
4435 then m_items
<- items;
4438 let active = self#calcactive
anchor in
4440 m_first
<- firstof m_first
active
4444 let outlinesource fetchoutlines
=
4446 inherit outlinesoucebase fetchoutlines
4447 method! calcactive
anchor =
4448 let rely = getanchory anchor in
4449 let rec loop n best bestd
=
4450 if n = Array.length m_items
4453 let _, _, kind
= m_items
.(n) in
4456 let orely = getanchory anchor in
4457 let d = abs
(orely - rely) in
4460 else loop (n+1) best bestd
4461 | Onone
| Oremote
_ | Olaunch
_
4462 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4463 loop (n+1) best bestd
4469 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4470 let mkselector sourcetype
=
4471 let fetchoutlines () =
4472 match sourcetype
with
4473 | `bookmarks
-> Array.of_list state
.bookmarks
4474 | `outlines
-> state
.outlines
4475 | `history
-> genhistoutlines () |> Array.of_list
4478 if sourcetype
= `history
4479 then new outlinesoucebase
fetchoutlines
4480 else outlinesource fetchoutlines
4483 let outlines = fetchoutlines () in
4484 if Array.length
outlines = 0
4485 then showtext ' ' errmsg
4488 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4489 let anchor = getanchor
() in
4490 source#reset
anchor outlines;
4491 state
.text <- source#greetmsg
;
4493 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4494 G.postRedisplay "enter selector";
4498 let mkenter sourcetype errmsg
=
4499 let enter = mkselector sourcetype
in
4500 fun () -> enter errmsg
4502 ( mkenter `
outlines "document has no outline"
4503 , mkenter `bookmarks
"document has no bookmarks (yet)"
4504 , mkenter `history
"history is empty" )
4507 let quickbookmark ?title
() =
4508 match state
.layout with
4515 let tm = localtime
(now
()) in
4517 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4519 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4521 | Some
title -> title
4523 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4526 let setautoscrollspeed step goingdown
=
4527 let incr = max
1 ((abs step
) / 2) in
4528 let incr = if goingdown
then incr else -incr in
4529 let astep = boundastep state
.winh
(step
+ incr) in
4530 state
.autoscroll
<- Some
astep;
4534 match conf
.columns
with
4536 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4539 let panbound x = bound
x (-state
.w) state
.winw
;;
4541 let existsinrow pageno (columns
, coverA
, coverB
) p =
4542 let last = ((pageno - coverA
) mod columns
) + columns
in
4543 let rec any = function
4546 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4550 then (if l.pageno = last then false else any rest
)
4558 match state
.layout with
4560 let pageno = page_of_y state
.y in
4561 gotoghyll (getpagey
(pageno+1))
4563 match conf
.columns
with
4565 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4567 let y = clamp (pgscale state
.winh
) in
4570 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4571 gotoghyll (getpagey
pageno)
4572 | Cmulti
((c, _, _) as cl
, _) ->
4573 if conf
.presentation
4574 && (existsinrow l.pageno cl
4575 (fun l -> l.pageh
> l.pagey + l.pagevh))
4577 let y = clamp (pgscale state
.winh
) in
4580 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4581 gotoghyll (getpagey
pageno)
4583 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4585 let pagey, pageh
= getpageyh
l.pageno in
4586 let pagey = pagey + pageh
* l.pagecol
in
4587 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4588 gotoghyll (pagey + pageh
+ ips)
4592 match state
.layout with
4594 let pageno = page_of_y state
.y in
4595 gotoghyll (getpagey
(pageno-1))
4597 match conf
.columns
with
4599 if conf
.presentation
&& l.pagey != 0
4601 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4603 let pageno = max
0 (l.pageno-1) in
4604 gotoghyll (getpagey
pageno)
4605 | Cmulti
((c, _, coverB
) as cl
, _) ->
4606 if conf
.presentation
&&
4607 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4609 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4612 if l.pageno = state
.pagecount
- coverB
4616 let pageno = max
0 (l.pageno-decr) in
4617 gotoghyll (getpagey
pageno)
4625 let pageno = max
0 (l.pageno-1) in
4626 let pagey, pageh
= getpageyh
pageno in
4629 let pagey, pageh
= getpageyh
l.pageno in
4630 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4636 if emptystr conf
.savecmd
4637 then error
"don't know where to save modified document"
4639 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4642 (fun s -> error
"failed to obtain path to the saved copy: %s" s)
4647 let tmp = path ^
".tmp" in
4649 Unix.rename
tmp path;
4652 let viewkeyboard key mask
=
4654 let mode = state
.mode in
4655 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4658 G.postRedisplay "view:enttext"
4660 let ctrl = Wsi.withctrl mask
in
4662 match Wsi.kc2kt
key with
4663 | Ascii 'Q'
-> exit
0
4666 if hasunsavedchanges
()
4670 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4673 match state
.lnava
with
4674 | None
-> LinkNav
(Ltgendir
0)
4675 | Some
pn -> LinkNav
(Ltexact
pn)
4677 gotoxy state
.x state
.y;
4679 else impmsg "keyboard link navigation does not work under rotation"
4681 | Escape
| Ascii 'q'
->
4682 begin match state
.mstate
with
4685 G.postRedisplay "kill rect";
4688 | Mscrolly
| Mscrollx
4691 begin match state
.mode with
4694 | Ltexact pl
-> state
.lnava
<- Some pl
4695 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4698 G.postRedisplay "esc leave linknav"
4699 | Birdseye
_ | Textentry
_ | View
->
4700 match state
.ranchors
with
4702 | (path, password, anchor, origin
) :: rest
->
4703 state
.ranchors
<- rest
;
4704 state
.anchor <- anchor;
4705 state
.origin
<- origin
;
4706 state
.nameddest
<- E.s;
4707 opendoc path password
4712 gotoghyll (getnav ~
-1)
4723 Hashtbl.iter
(fun _ opaque ->
4725 Hashtbl.clear state
.prects
) state
.pagemap
;
4726 G.postRedisplay "dehighlight";
4728 | (Ascii '
/'
| Ascii '?'
) as pv
->
4729 let ondone isforw
s =
4730 cbput state
.hists
.pat
s;
4731 state
.searchpattern
<- s;
4734 let s = String.make
1 (Char.chr
key) in
4735 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4736 textentry
, ondone (pv
= Ascii '
/'
), true)
4738 | Ascii '
+'
| Ascii '
='
when ctrl ->
4739 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4740 pivotzoom (conf
.zoom +. incr)
4745 try int_of_string
s with exn
->
4746 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4752 state
.text <- "page bias is now " ^ string_of_int
n;
4755 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4757 | Ascii '
-'
when ctrl ->
4758 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4759 pivotzoom (max
0.01 (conf
.zoom -. decr))
4762 let ondone msg
= state
.text <- msg
in
4764 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4765 optentry state
.mode, ondone, true
4768 | Ascii '
0'
when ctrl ->
4770 then gotoxy 0 state
.y
4773 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4775 match conf
.columns
with
4776 | Csingle
_ | Cmulti
_ -> 1
4777 | Csplit
(n, _) -> n
4779 let h = state
.winh
-
4780 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4782 let zoom = zoomforh state
.winw
h 0 cols in
4783 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4786 | Ascii '
3'
when ctrl ->
4788 match conf
.fitmodel
with
4789 | FitWidth
-> FitProportional
4790 | FitProportional
-> FitPage
4791 | FitPage
-> FitWidth
4793 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4794 reqlayout conf
.angle
fm
4796 | Ascii '
4'
when ctrl ->
4797 let zoom = getmaxw
() /. float state
.winw
in
4798 if zoom > 0.0 then setzoom zoom
4803 | Ascii '
9'
when ctrl ->
4810 try int_of_string
s with exn
->
4811 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4817 cbput state
.hists
.pag
(string_of_int
n);
4818 gotopage1 (n + conf
.pagebias
- 1) 0;
4821 let [@warning
"-4"] pageentry
text = function
4822 | Keys.Ascii '
g'
-> TEdone
text
4823 | key -> intentry
text key
4825 let text = String.make
1 (Char.chr
key) in
4826 enttext (":", text, Some
(onhist state
.hists
.pag
),
4827 pageentry
, ondone, true)
4830 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4831 G.postRedisplay "toggle scrollbar";
4834 state
.bzoom
<- not state
.bzoom
;
4836 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4839 conf
.hlinks
<- not conf
.hlinks
;
4840 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4841 G.postRedisplay "toggle highlightlinks";
4844 if conf
.angle
mod 360 = 0
4846 state
.glinks
<- true;
4847 let mode = state
.mode in
4850 (":", E.s, None
, linknentry
, linknact gotounder, false),
4852 state
.glinks
<- false;
4856 G.postRedisplay "view:linkent(F)"
4858 else impmsg "hint mode does not work under rotation"
4861 state
.glinks
<- true;
4862 let mode = state
.mode in
4866 ":", E.s, None
, linknentry
, linknact (fun under ->
4867 selstring (undertext under);
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
_) ->
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
_|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
_|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 begin match conf
.columns
, state
.layout with
5505 | Csingle
_, _ :: _ ->
5506 GlDraw.color (scalecolor2 conf
.bgcolor
);
5508 List.fold_left
(fun y l ->
5511 let x1 = l.pagedispx in
5512 let y1 = (l.pagedispy + l.pagevh) in
5513 filledrect (float x0) (float y0) (float x1) (float y1);
5514 let x0 = x1 + l.pagevw in
5515 let x1 = state
.winw
in
5516 filledrect1 (float x0) (float y0) (float x1) (float y1);
5520 and x1 = state
.winw
in
5522 and y1 = l.pagedispy in
5523 filledrect1 (float x0) (float y0) (float x1) (float y1);
5525 l.pagedispy + l.pagevh) 0 state
.layout
5528 and x1 = state
.winw
in
5530 and y1 = state
.winh
in
5531 filledrect1 (float x0) (float y0) (float x1) (float y1)
5532 | (Cmulti
_ | Csplit
_), _ | Csingle
_, [] ->
5533 GlClear.color (scalecolor2 conf
.bgcolor
);
5534 GlClear.clear
[`
color];
5536 List.iter
drawpage state
.layout;
5538 match state
.mode with
5539 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5540 begin match getopaque pageno with
5542 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5543 let color = (0.0, 0.0, 0.5, 0.5) in
5550 | None
-> state
.rects
5552 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5555 | View
-> state
.rects
5558 let rec postloop linkindexbase
= function
5560 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5561 postloop linkindexbase rest
5565 postloop 0 state
.layout;
5567 begin match state
.mstate
with
5568 | Mzoomrect
((x0, y0), (x1, y1)) ->
5570 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5571 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5572 filledrect (float x0) (float y0) (float x1) (float y1);
5576 | Mscrolly
| Mscrollx
5585 let zoomrect x y x1 y1 =
5588 and y0 = min
y y1 in
5589 let zoom = (float state
.w) /. float (x1 - x0) in
5592 if state
.w < state
.winw
5593 then (state
.winw
- state
.w) / 2
5596 match conf
.fitmodel
with
5597 | FitWidth
| FitProportional
-> simple ()
5599 match conf
.columns
with
5601 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5602 | Cmulti
_ | Csingle
_ -> simple ()
5604 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5605 state
.anchor <- getanchor
();
5610 let annot inline
x y =
5611 match unproject x y with
5612 | Some
(opaque, n, ux
, uy
) ->
5614 addannot
opaque ux uy
text;
5615 wcmd "freepage %s" (~
> opaque);
5616 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5618 gotoxy state
.x state
.y
5622 let ondone s = add s in
5623 let mode = state
.mode in
5624 state
.mode <- Textentry
(
5625 ("annotation: ", E.s, None
, textentry
, ondone, true),
5626 fun _ -> state
.mode <- mode);
5629 G.postRedisplay "annot"
5631 add @@ getusertext E.s
5636 let g opaque l px py =
5637 match rectofblock
opaque px py with
5639 let x0 = a.(0) -. 20. in
5640 let x1 = a.(1) +. 20. in
5641 let y0 = a.(2) -. 20. in
5642 let zoom = (float state
.w) /. (x1 -. x0) in
5643 let pagey = getpagey
l.pageno in
5644 let margin = (state
.w - l.pagew
)/2 in
5645 let nx = -truncate
x0 - margin in
5646 gotoxy_and_clear_text nx (pagey + truncate
y0);
5647 state
.anchor <- getanchor
();
5652 match conf
.columns
with
5654 impmsg "block zooming does not work properly in split columns mode"
5655 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5659 let winw = state
.winw - 1 in
5660 let s = float x /. float winw in
5661 let destx = truncate
(float (state
.w + winw) *. s) in
5662 gotoxy_and_clear_text (winw - destx) state
.y;
5663 state
.mstate
<- Mscrollx
;
5667 let s = float y /. float state
.winh
in
5668 let desty = truncate
(s *. float (maxy ())) in
5669 gotoxy_and_clear_text state
.x desty;
5670 state
.mstate
<- Mscrolly
;
5673 let viewmulticlick clicks
x y mask
=
5674 let g opaque l px py =
5682 if markunder
opaque px py mark
5686 match getopaque l.pageno with
5688 | Some
opaque -> pipesel opaque cmd
5690 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5691 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5696 G.postRedisplay "viewmulticlick";
5697 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5701 match conf
.columns
with
5703 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5706 let viewmouse button down
x y mask
=
5708 | n when (n == 4 || n == 5) && not down
->
5709 if Wsi.withctrl mask
5711 match state
.mstate
with
5712 | Mzoom
(oldn
, i
, (ftx
, fty
)) ->
5715 then abs
(ftx
- x) > 5 || abs
(fty
- y) > 5
5725 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5727 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5729 let zoom = conf
.zoom -. incr in
5731 then pivotzoom ~
x ~
y zoom
5732 else pivotzoom zoom;
5733 state
.mstate
<- Mzoom
(n, 0, (x, y));
5735 state
.mstate
<- Mzoom
(n, i
+1, (ftx
, fty
));
5737 else state
.mstate
<- Mzoom
(n, 0, (ftx
, fty
))
5741 | Mscrolly
| Mscrollx
5743 | Mnone
-> state
.mstate
<- Mzoom
(n, 0, (0, 0))
5746 match state
.autoscroll
with
5747 | Some step
-> setautoscrollspeed step
(n=4)
5749 if conf
.wheelbypage
|| conf
.presentation
5758 then -conf
.scrollstep
5759 else conf
.scrollstep
5761 let incr = incr * 2 in
5762 let y = clamp incr in
5763 gotoxy_and_clear_text state
.x y
5766 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5768 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5769 gotoxy_and_clear_text x state
.y
5771 | 1 when Wsi.withshift mask
->
5772 state
.mstate
<- Mnone
;
5775 match unproject x y with
5777 | Some
(_, pageno, ux
, uy
) ->
5778 let cmd = Printf.sprintf
5780 conf
.stcmd state
.path pageno ux uy
5782 match spawn
cmd [] with
5784 impmsg "execution of synctex command(%S) failed: %S"
5785 conf
.stcmd
@@ exntos exn
5789 | 1 when Wsi.withctrl mask
->
5792 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5793 state
.mstate
<- Mpan
(x, y)
5796 state
.mstate
<- Mnone
5801 if Wsi.withshift mask
5803 annot conf
.annotinline
x y;
5804 G.postRedisplay "addannot"
5808 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5809 state
.mstate
<- Mzoomrect
(p, p)
5812 match state
.mstate
with
5813 | Mzoomrect
((x0, y0), _) ->
5814 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5815 then zoomrect x0 y0 x y
5818 G.postRedisplay "kill accidental zoom rect";
5822 | Mscrolly
| Mscrollx
5824 | Mnone
-> resetmstate ()
5827 | 1 when vscrollhit x ->
5830 let _, position, sh = state
.uioh#
scrollph in
5831 if y > truncate
position && y < truncate
(position +. sh)
5832 then state
.mstate
<- Mscrolly
5835 state
.mstate
<- Mnone
5837 | 1 when y > state
.winh
- hscrollh () ->
5840 let _, position, sw = state
.uioh#scrollpw
in
5841 if x > truncate
position && x < truncate
(position +. sw)
5842 then state
.mstate
<- Mscrollx
5845 state
.mstate
<- Mnone
5847 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5850 let dest = if down
then getunder x y else Unone
in
5851 begin match dest with
5855 | Unone
when down
->
5856 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5857 state
.mstate
<- Mpan
(x, y);
5859 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5861 | Unone
| Utext
_ ->
5866 state
.mstate
<- Msel
((x, y), (x, y));
5867 G.postRedisplay "mouse select";
5871 match state
.mstate
with
5874 | Mzoom
_ | Mscrollx
| Mscrolly
->
5875 state
.mstate
<- Mnone
5877 | Mzoomrect
((x0, y0), _) ->
5881 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5882 state
.mstate
<- Mnone
5884 | Msel
((x0, y0), (x1, y1)) ->
5885 let rec loop = function
5889 let a0 = l.pagedispy in
5890 let a1 = a0 + l.pagevh in
5891 let b0 = l.pagedispx in
5892 let b1 = b0 + l.pagevw in
5893 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5894 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5898 match getopaque l.pageno with
5901 match Unix.pipe
() with
5903 impmsg "cannot create sel pipe: %s" @@
5907 Ne.clo fd
(fun msg
->
5908 dolog
"%s close failed: %s" what msg
)
5910 begin match spawn
cmd [r, 0; w, -1] with
5912 clo "Msel pipe/w" w;
5913 dolog
"cannot execute %S: %s" cmd @@ exntos exn
5916 G.postRedisplay "copysel";
5918 clo "Msel pipe/r" r;
5920 dosel conf
.selcmd
();
5921 state
.roam
<- dosel conf
.paxcmd
;
5933 let birdseyemouse button down
x y mask
5934 (conf
, leftx
, _, hooverpageno
, anchor) =
5937 let rec loop = function
5940 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5941 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5943 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5949 | _ -> viewmouse button down
x y mask
5955 method key key mask
=
5956 begin match state
.mode with
5957 | Textentry textentry
-> textentrykeyboard
key mask textentry
5958 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5959 | View
-> viewkeyboard key mask
5960 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5964 method button button bstate
x y mask
=
5965 begin match state
.mode with
5966 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5967 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5972 method multiclick clicks
x y mask
=
5973 begin match state
.mode with
5974 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5975 | Birdseye
_ | Textentry
_ -> ()
5980 begin match state
.mode with
5982 | View
| Birdseye
_ | LinkNav
_ ->
5983 match state
.mstate
with
5984 | Mzoom
_ | Mnone
-> ()
5989 state
.mstate
<- Mpan
(x, y);
5990 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5992 gotoxy_and_clear_text x y
5995 state
.mstate
<- Msel
(a, (x, y));
5996 G.postRedisplay "motion select";
5999 let y = min state
.winh
(max
0 y) in
6003 let x = min state
.winw (max
0 x) in
6006 | Mzoomrect
(p0
, _) ->
6007 state
.mstate
<- Mzoomrect
(p0
, (x, y));
6008 G.postRedisplay "motion zoomrect";
6012 method pmotion
x y =
6013 begin match state
.mode with
6014 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
6015 let rec loop = function
6017 if hooverpageno
!= -1
6019 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
6020 G.postRedisplay "pmotion birdseye no hoover";
6023 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6024 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6026 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6027 G.postRedisplay "pmotion birdseye hoover";
6035 | LinkNav
_ | View
->
6036 match state
.mstate
with
6037 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6045 let past, _, _ = !r in
6047 let delta = now -. past in
6050 else r := (now, x, y)
6054 method infochanged
_ = ()
6057 let maxy = maxy () in
6060 then 0.0, float state
.winh
6061 else scrollph state
.y maxy
6066 let fwinw = float (state
.winw - vscrollw ()) in
6068 let sw = fwinw /. float state
.w in
6069 let sw = fwinw *. sw in
6070 max
sw (float conf
.scrollh
)
6073 let maxx = state
.w + state
.winw in
6074 let x = state
.winw - state
.x in
6075 let percent = float x /. float maxx in
6076 (fwinw -. sw) *. percent
6078 hscrollh (), position, sw
6082 match state
.mode with
6083 | LinkNav
_ -> "links"
6084 | Textentry
_ -> "textentry"
6085 | Birdseye
_ -> "birdseye"
6088 findkeyhash conf
modename
6090 method eformsgs
= true
6091 method alwaysscrolly
= false
6094 let addrect pageno r g b a x0 y0 x1 y1 =
6095 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6099 let cl = splitatchar cmds ' '
in
6101 try Scanf.sscanf
s fmt
f
6102 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6105 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6106 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6107 s pageno r g b a x0 y0 x1 y1;
6111 let _,w1,h1
,_ = getpagedim
pageno in
6112 let sw = float w1 /. float w
6113 and sh = float h1
/. float h in
6117 and y1s
= y1 *. sh in
6118 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6119 let color = (r, g, b, a) in
6120 if conf
.verbose
then debugrect rect;
6121 state
.rects <- (pageno, color, rect) :: state
.rects;
6126 | "reload", "" -> reload ()
6128 scan args
"%u %f %f"
6130 let cmd, _ = state
.geomcmds
in
6132 then gotopagexy !wtmode pageno x y
6135 gotopagexy !wtmode pageno x y;
6138 state
.reprf
<- f state
.reprf
6140 | "goto1", args
-> scan args
"%u %f" gotopage
6143 (fun _filename _pageno
->
6144 failwith
"gotounder (Uremote (filename, pageno))")
6147 (fun _filename _dest
->
6148 failwith
"gotounder (Uremotedest (filename, dest))")
6150 scan args
"%u %u %f %f %f %f"
6151 (fun pageno c x0 y0 x1 y1 ->
6152 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6153 rectx "rect" pageno color x0 y0 x1 y1;
6156 scan args
"%u %f %f %f %f %f %f %f %f"
6157 (fun pageno r g b alpha x0 y0 x1 y1 ->
6158 addrect pageno r g b alpha x0 y0 x1 y1;
6159 G.postRedisplay "prect"
6162 scan args
"%u %f %f"
6165 match getopaque pageno with
6166 | Some
opaque -> opaque
6169 pgoto optopaque pageno x y;
6170 let rec fixx = function
6173 if l.pageno = pageno
6174 then gotoxy (state
.x - l.pagedispx) state
.y
6179 match conf
.columns
with
6180 | Csingle
_ | Csplit
_ -> 1
6181 | Cmulti
((n, _, _), _) -> n
6183 layout 0 state
.y (state
.winw * mult) state
.winh
6187 | "activatewin", "" -> Wsi.activatewin
()
6188 | "quit", "" -> raise Quit
6191 let l = Config.keys_of_string
keys in
6192 List.iter
(fun (k
, m) -> keyboard k
m) l
6193 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6196 | "clearrects", "" ->
6197 Hashtbl.clear state
.prects
;
6198 G.postRedisplay "clearrects"
6200 adderrfmt "remote command"
6201 "error processing remote command: %S\n" cmds
;
6205 let scratch = Bytes.create
80 in
6206 let buf = Buffer.create
80 in
6208 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6209 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6212 if Buffer.length
buf > 0
6214 let s = Buffer.contents
buf in
6222 match Bytes.index_from
scratch ppos '
\n'
with
6223 | pos
-> if pos
>= n then -1 else pos
6224 | exception Not_found
-> -1
6228 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6229 let s = Buffer.contents
buf in
6235 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6241 let remoteopen path =
6242 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6244 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6249 let gcconfig = ref E.s in
6250 let trimcachepath = ref E.s in
6251 let rcmdpath = ref E.s in
6252 let pageno = ref None
in
6253 let rootwid = ref 0 in
6254 let openlast = ref false in
6255 let doreap = ref false in
6256 let csspath = ref None
in
6257 selfexec := Sys.executable_name
;
6260 [("-p", Arg.String
(fun s -> state
.password <- s),
6261 "<password> Set password");
6265 Config.fontpath
:= s;
6266 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6268 "<path> Set path to the user interface font");
6272 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6273 Config.confpath
:= s),
6274 "<path> Set path to the configuration file");
6276 ("-last", Arg.Set
openlast, " Open last document");
6278 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6279 "<page-number> Jump to page");
6281 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6282 "<path> Set path to the trim cache file");
6284 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6285 "<named-destination> Set named destination");
6287 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6288 ("-cxack", Arg.Set
cxack, " Cut corners");
6290 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6291 "<path> Set path to the source of remote commands");
6293 ("-gc", Arg.Set_string
gcconfig,
6294 "<path> Collect garbage with the help of a script");
6296 ("-v", Arg.Unit
(fun () ->
6298 "%s\nconfiguration path: %s\n"
6301 exit
0), " Print version and exit");
6303 ("-css", Arg.String
(fun s -> csspath := Some
s),
6304 "<path> Set path to the style sheet to use with EPUB/HTML");
6306 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6308 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6309 "<origin> <undocumented>");
6312 (fun s -> state
.path <- s)
6313 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6316 then selfexec := !selfexec ^
" -wtmode";
6318 let histmode = emptystr state
.path && not
!openlast in
6320 if not
(Config.load !openlast)
6321 then dolog
"failed to load configuration";
6323 begin match !pageno with
6324 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6328 if nonemptystr
!gcconfig
6331 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6332 | exception exn
-> error
"socketpair for gc failed: %s" @@ exntos exn
6335 match spawn
!gcconfig [(c, 0); (c, 1); (s, -1)] with
6336 | exception exn
-> error
"failed to execute gc script: %s" @@ exntos exn
6338 Ne.clo c @@ (fun s -> error
"failed to close gc fd %s" s);
6345 val mutable m_clicks
= 0
6346 val mutable m_click_x
= 0
6347 val mutable m_click_y
= 0
6348 val mutable m_lastclicktime
= infinity
6350 method private cleanup =
6351 state
.roam
<- noroam
;
6352 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6353 method expose
= G.postRedisplay "expose"
6357 | Wsi.Unobscured
-> "unobscured"
6358 | Wsi.PartiallyObscured
-> "partiallyobscured"
6359 | Wsi.FullyObscured
-> "fullyobscured"
6361 vlog "visibility change %s" name
6362 method display = display ()
6363 method map mapped
= vlog "mapped %b" mapped
6364 method reshape w h =
6367 method mouse
b d x y m =
6368 if d && canselect ()
6371 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6378 if abs
x - m_click_x
> 10
6379 || abs
y - m_click_y
> 10
6380 || abs_float
(t -. m_lastclicktime
) > 0.3
6382 m_clicks
<- m_clicks
+ 1;
6383 m_lastclicktime
<- t;
6387 G.postRedisplay "cleanup";
6388 state
.uioh <- state
.uioh#button
b d x y m;
6390 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6395 m_lastclicktime
<- infinity
;
6396 state
.uioh <- state
.uioh#button
b d x y m
6400 state
.uioh <- state
.uioh#button
b d x y m
6403 state
.mpos
<- (x, y);
6404 state
.uioh <- state
.uioh#motion
x y
6405 method pmotion
x y =
6406 state
.mpos
<- (x, y);
6407 state
.uioh <- state
.uioh#pmotion
x y
6409 let mascm = m land (
6410 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6413 let x = state
.x and y = state
.y in
6415 if x != state
.x || y != state
.y then self#
cleanup
6417 match state
.keystate
with
6419 let km = k
, mascm in
6422 let modehash = state
.uioh#
modehash in
6423 try Hashtbl.find modehash km
6425 try Hashtbl.find (findkeyhash conf
"global") km
6426 with Not_found
-> KMinsrt
(k
, m)
6428 | KMinsrt
(k
, m) -> keyboard k
m
6429 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6430 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6432 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6433 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6434 state
.keystate
<- KSnone
6435 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6436 state
.keystate
<- KSinto
(keys, insrt
)
6437 | KSinto
_ -> state
.keystate
<- KSnone
6440 state
.mpos
<- (x, y);
6441 state
.uioh <- state
.uioh#pmotion
x y
6442 method leave = state
.mpos
<- (-1, -1)
6443 method winstate wsl
= state
.winstate
<- wsl
6444 method quit
= raise Quit
6447 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6449 setbgcol conf
.bgcolor
;
6452 if not
@@ List.exists
GlMisc.check_extension
6453 [ "GL_ARB_texture_rectangle"
6454 ; "GL_EXT_texture_recangle"
6455 ; "GL_NV_texture_rectangle" ]
6456 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6458 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6460 defconf
.sliceheight
<- 1024;
6461 defconf
.texcount
<- 32;
6462 defconf
.usepbo
<- true;
6466 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6468 dolog
"socketpair failed: %s" @@ exntos exn
;
6476 setcheckers conf
.checkers
;
6478 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6480 begin match !csspath with
6482 | Some
"" -> conf
.css
<- E.s
6484 let css = filecontents
path in
6485 let l = String.length
css in
6487 if substratis
css (l-2) "\r\n"
6488 then String.sub css 0 (l-2)
6489 else (if css.[l-1] = '
\n'
6490 then String.sub css 0 (l-1)
6494 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6495 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6496 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6498 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6500 reshape ~firsttime
:true winw winh
;
6504 Wsi.settitle
"llpp (history)";
6508 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6509 opendoc state
.path state
.password;
6513 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6514 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6517 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6518 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6519 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6521 | _pid
, _status
-> reap ()
6523 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6527 if nonemptystr
!rcmdpath
6528 then remoteopen !rcmdpath
6533 let rec loop deadline
=
6539 let r = [state
.ss; state
.wsfd] in
6543 | Some fd
-> fd
:: r
6547 state
.redisplay
<- false;
6554 if deadline
= infinity
6556 else max
0.0 (deadline
-. now)
6561 try Unix.select
r [] [] timeout
6562 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6568 if state
.ghyll
== noghyll
6570 match state
.autoscroll
with
6571 | Some step
when step
!= 0 ->
6572 let y = state
.y + step
in
6573 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6576 then state
.maxy - fy
6577 else if y >= state
.maxy - fy then 0 else y
6579 if state
.mode = View
6580 then gotoxy_and_clear_text state
.x y
6581 else gotoxy state
.x y;
6584 else deadline
+. 0.01
6589 let rec checkfds = function
6591 | fd
:: rest
when fd
= state
.ss ->
6592 let cmd = rcmd state
.ss in
6596 | fd
:: rest
when fd
= state
.wsfd ->
6600 | fd
:: rest
when Some fd
= !optrfd ->
6601 begin match remote fd
with
6602 | None
-> optrfd := remoteopen !rcmdpath;
6603 | opt -> optrfd := opt
6608 dolog
"select returned unknown descriptor";
6614 if deadline
= infinity
6618 match state
.autoscroll
with
6619 | Some step
when step
!= 0 -> deadline1
6620 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6625 match loop infinity
with
6627 Config.save leavebirdseye;
6628 if hasunsavedchanges
()
6630 | _ -> error
"umpossible - infinity reached"