6 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
8 external init
: pipe
-> params
-> unit = "ml_init";;
9 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
10 external hassel
: opaque
-> bool = "ml_hassel";;
11 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
12 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
13 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
14 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
15 external clearmark
: opaque
-> unit = "ml_clearmark";;
16 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
17 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
18 external measurestr
: int -> string -> float = "ml_measure_string";;
19 external postprocess
:
20 opaque
-> int -> int -> int -> (int * string * int) -> int
22 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
23 external setaalevel
: int -> unit = "ml_setaalevel";;
24 external realloctexts
: int -> bool = "ml_realloctexts";;
25 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
26 external getlink
: opaque
-> int -> under
= "ml_getlink";;
27 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
28 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
29 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
30 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
31 external freepbo
: opaque
-> unit = "ml_freepbo";;
32 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
33 external pbousable
: unit -> bool = "ml_pbo_usable";;
34 external unproject
: opaque
-> int -> int -> (int * int) option
36 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
37 external rectofblock
: opaque
-> int -> int -> float array
option
39 external begintiles
: unit -> unit = "ml_begintiles";;
40 external endtiles
: unit -> unit = "ml_endtiles";;
42 let selfexec = ref E.s
;;
44 let drawstring size x y s
=
46 Gl.enable `texture_2d
;
47 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
48 ignore
(drawstr size x y s
);
50 Gl.disable `texture_2d
;
53 let drawstring1 size x y s
=
57 let drawstring2 size x y fmt
=
58 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
62 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
63 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
64 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
65 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
66 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
67 dolog
" column %d" l
.pagecol
;
71 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
73 dolog
" x0,y0=(% f, % f)" x0 y0
;
74 dolog
" x1,y1=(% f, % f)" x1 y1
;
75 dolog
" x2,y2=(% f, % f)" x2 y2
;
76 dolog
" x3,y3=(% f, % f)" x3 y3
;
80 let isbirdseye = function Birdseye _
-> true | _
-> false;;
81 let istextentry = function Textentry _
-> true | _
-> false;;
83 let wtmode = ref false;;
84 let cxack = ref false;;
86 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
89 if (conf
.scrollb
land scrollbhv
= 0)
90 || (state
.x
= 0 && state
.w
<= state
.winw
- conf
.scrollbw
)
96 if (conf
.scrollb
land scrollbvv
= 0)
101 let wadjsb w
= w
- vscrollw ();;
102 let xadjsb x
= if conf
.leftscroll
then x
+ vscrollw () else x
;;
105 fstate
.fontsize
<- n
;
106 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
107 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
113 Printf.kprintf prerr_endline fmt
115 Printf.kprintf ignore fmt
119 if emptystr conf
.pathlauncher
120 then print_endline state
.path
122 let re = Str.regexp
"%s" in
123 let command = Str.global_replace
re state
.path conf
.pathlauncher
in
126 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
132 type 'a t
= | Res
of 'a
| Exn
of exn
;;
140 try tempfailureretry
Unix.close fd
141 with exn
-> f
(exntos exn
)
145 try Res
(tempfailureretry
Unix.dup fd
)
150 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
155 let redirectstderr () =
156 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
157 if conf
.redirectstderr
159 match Ne.res Unix.pipe
with
161 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
164 begin match Ne.dup Unix.stderr
with
166 dolog
"failed to dup stderr: %s" (exntos exn
);
167 Ne.clo r
(clofail "pipe/r");
168 Ne.clo w
(clofail "pipe/w");
170 | Ne.Res dupstderr
->
171 begin match Ne.dup2 w
Unix.stderr
with
173 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
174 Ne.clo dupstderr
(clofail "stderr duplicate");
175 Ne.clo r
(clofail "redir pipe/r");
176 Ne.clo w
(clofail "redir pipe/w");
179 state
.stderr
<- dupstderr
;
180 state
.errfd
<- Some r
;
184 state
.newerrmsgs
<- false;
185 begin match state
.errfd
with
187 begin match Ne.dup2 state
.stderr
Unix.stderr
with
189 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
191 Ne.clo fd
(clofail "dup of stderr");
196 prerr_string
(Buffer.contents state
.errmsgs
);
198 Buffer.clear state
.errmsgs
;
204 let postRedisplay who
=
206 then prerr_endline
("redisplay for " ^ who
);
207 state
.redisplay
<- true;
211 let getopaque pageno
=
212 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
213 with Not_found
-> None
216 let putopaque pageno opaque
=
217 Hashtbl.replace state
.pagemap
(pageno
, state
.gen
) opaque
220 let pagetranslatepoint l x y
=
221 let dy = y
- l
.pagedispy
in
222 let y = dy + l
.pagey
in
223 let dx = x
- l
.pagedispx
in
224 let x = dx + l
.pagex
in
228 let onppundermouse g
x y d
=
231 begin match getopaque l
.pageno
with
233 let x0 = l
.pagedispx
in
234 let x1 = x0 + l
.pagevw
in
235 let y0 = l
.pagedispy
in
236 let y1 = y0 + l
.pagevh
in
237 if y >= y0 && y <= y1 && x >= x0 && x <= x1
239 let px, py
= pagetranslatepoint l
x y in
240 match g opaque l
px py
with
253 let g opaque l
px py
=
256 match rectofblock opaque
px py
with
258 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
259 state
.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
260 G.postRedisplay "getunder";
263 match whatsunder opaque
px py
with
265 | under
-> Some under
267 onppundermouse g x y Unone
272 match unproject opaque
x y with
273 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
276 onppundermouse g x y None
;
280 state
.text
<- Printf.sprintf
"%c%s" c s
;
281 G.postRedisplay "showtext";
284 let pipesel opaque cmd
=
287 match Ne.res Unix.pipe
with
290 (Printf.sprintf
"pipesel can not create pipe: %s" (exntos exn
));
292 let doclose what fd
=
293 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
296 try popen cmd
[r
, 0; w
, -1]; true
298 dolog
"can not execute %S: %s" cmd
(exntos exn
);
304 G.postRedisplay "pipesel";
306 else doclose "pipesel pipe/w" w
;
307 doclose "pipesel pipe/r" r
;
311 let g opaque l
px py
=
312 if markunder opaque
px py conf
.paxmark
315 match getopaque l
.pageno
with
317 | Some opaque
-> pipesel opaque conf
.paxcmd
322 G.postRedisplay "paxunder";
323 if conf
.paxmark
= Mark_page
326 match getopaque l
.pageno
with
328 | Some opaque
-> clearmark opaque
) state
.layout
;
330 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
334 match Ne.res Unix.pipe
with
336 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
339 Ne.clo fd
(fun msg
->
340 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
344 try popen conf
.selcmd
[r
, 0; w
, -1]; true
347 (Printf.sprintf
"failed to execute %s: %s"
348 conf
.selcmd
(exntos exn
));
354 let l = String.length s
in
355 let n = tempfailureretry
(Unix.write w s
0) l in
360 "failed to write %d characters to sel pipe, wrote %d"
365 (Printf.sprintf
"failed to write to sel pipe: %s"
370 clo "selstring pipe/r" r
;
371 clo "selstring pipe/w" w
;
374 let undertext = function
377 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state
.path
(pageno
+1)
378 | Utext s
-> "font: " ^ s
379 | Uunexpected s
-> "unexpected: " ^ s
380 | Ulaunch s
-> "launch: " ^ s
381 | Unamed s
-> "named: " ^ s
382 | Uremote
(filename
, pageno
) ->
383 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
384 | Uremotedest
(filename
, destname
) ->
385 Printf.sprintf
"%s: destination %S" filename destname
388 let updateunder x y =
389 match getunder x y with
390 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
392 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
393 Wsi.setcursor
Wsi.CURSOR_INFO
394 | Ulinkgoto
(pageno
, _
) ->
396 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
397 Wsi.setcursor
Wsi.CURSOR_INFO
399 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
400 Wsi.setcursor
Wsi.CURSOR_TEXT
402 if conf
.underinfo
then showtext 'u'
("nexpected: " ^ s
);
403 Wsi.setcursor
Wsi.CURSOR_INHERIT
405 if conf
.underinfo
then showtext '
l'
("aunch: " ^ s
);
406 Wsi.setcursor
Wsi.CURSOR_INHERIT
408 if conf
.underinfo
then showtext '
n'
("amed: " ^ s
);
409 Wsi.setcursor
Wsi.CURSOR_INHERIT
410 | Uremote
(filename
, pageno
) ->
411 if conf
.underinfo
then showtext 'r'
412 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
413 Wsi.setcursor
Wsi.CURSOR_INFO
414 | Uremotedest
(filename
, destname
) ->
415 if conf
.underinfo
then showtext 'r'
416 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
417 Wsi.setcursor
Wsi.CURSOR_INFO
420 let showlinktype under
=
426 let s = undertext under
in
431 let b = Buffer.create
(String.length
s + 1) in
432 Buffer.add_string
b s;
437 let intentry_with_suffix text key
=
439 if key
>= 32 && key
< 127
443 match Char.lowercase
c with
445 let text = addchar text c in
449 let text = addchar text c in
453 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
459 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
460 if n != 4 then error
"incomplete read(len) = %d" n;
462 lor (Char.code
s.[0] lsl 24)
463 lor (Char.code
s.[1] lsl 16)
464 lor (Char.code
s.[2] lsl 8)
465 lor (Char.code
s.[3] lsl 0)
467 let s = String.create
len in
468 let n = tempfailureretry
(Unix.read fd
s 0) len in
469 if n != len then error
"incomplete read(data) %d vs %d" n len;
473 let btod b = if b then 1 else 0;;
476 let b = Buffer.create
16 in
477 Buffer.add_string
b "llll";
480 let s = Buffer.contents
b in
481 let n = String.length
s in
483 (* dolog "wcmd %S" (String.sub s 4 len); *)
484 s.[0] <- Char.chr
((len lsr 24) land 0xff);
485 s.[1] <- Char.chr
((len lsr 16) land 0xff);
486 s.[2] <- Char.chr
((len lsr 8) land 0xff);
487 s.[3] <- Char.chr
(len land 0xff);
488 let n'
= tempfailureretry
(Unix.write state
.sw
s 0) n in
489 if n'
!= n then error
"write failed %d vs %d" n'
n;
493 let nogeomcmds cmds
=
495 | s, [] -> emptystr
s
499 let layoutN ((columns
, coverA
, coverB
), b) y sh
=
500 let sh = sh - (hscrollh ()) in
501 let rec fold accu
n =
502 if n = Array.length
b
505 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
508 || n = state
.pagecount
- coverB
509 || (n - coverA
) mod columns
= columns
- 1)
515 let pagey = max
0 (y - vy
) in
516 let pagedispy = if pagey > 0 then 0 else vy
- y in
517 let pagedispx, pagex
=
519 if n = coverA
- 1 || n = state
.pagecount
- coverB
520 then state
.x + (wadjsb state
.winw
- w
) / 2
521 else dx + xoff
+ state
.x
528 let vw = wadjsb state
.winw
- pagedispx in
529 let pw = w
- pagex
in
532 let pagevh = min
(h
- pagey) (sh - pagedispy) in
533 if pagevw > 0 && pagevh > 0
544 ; pagedispx = pagedispx
545 ; pagedispy = pagedispy
557 if Array.length
b = 0
559 else List.rev
(fold [] (page_of_y
y))
562 let layoutS (columns
, b) y sh =
563 let sh = sh - hscrollh () in
564 let rec fold accu n =
565 if n = Array.length
b
568 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
575 let x = xoff
+ state
.x in
576 let pagey = max
0 (y - vy
) in
577 let pagedispy = if pagey > 0 then 0 else vy
- y in
578 let pagedispx, pagex
=
592 let pagecolw = pagew
/columns
in
594 if pagecolw < state
.winw
595 then pagedispx + ((wadjsb state
.winw
- pagecolw) / 2)
599 let vw = wadjsb state
.winw
- pagedispx in
600 let pw = pagew
- pagex
in
603 let pagevw = min
pagevw pagecolw in
604 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
605 if pagevw > 0 && pagevh > 0
616 ; pagedispx = pagedispx
617 ; pagedispy = pagedispy
618 ; pagecol
= n mod columns
633 if nogeomcmds state
.geomcmds
635 match conf
.columns
with
636 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
637 | Cmulti
c -> layoutN c y sh
638 | Csplit
s -> layoutS s y sh
643 let y = state
.y + incr
in
645 let y = min
y (state
.maxy
- (if conf
.maxhfit
then state
.winh
else 0)) in
650 let tilex = l.pagex
mod conf
.tilew
in
651 let tiley = l.pagey mod conf
.tileh
in
653 let col = l.pagex
/ conf
.tilew
in
654 let row = l.pagey / conf
.tileh
in
656 let rec rowloop row y0 dispy h
=
660 let dh = conf
.tileh
- y0 in
662 let rec colloop col x0 dispx w
=
666 let dw = conf
.tilew
- x0 in
668 let dispx'
= xadjsb dispx in
669 f col row dispx' dispy
x0 y0 dw dh;
670 colloop (col+1) 0 (dispx+dw) (w
-dw)
673 colloop col tilex l.pagedispx l.pagevw;
674 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
677 if l.pagevw > 0 && l.pagevh > 0
678 then rowloop row tiley l.pagedispy l.pagevh;
681 let gettileopaque l col row =
683 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
685 try Some
(Hashtbl.find state
.tilemap
key)
686 with Not_found
-> None
689 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
690 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
691 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
694 let filledrect x0 y0 x1 y1 =
695 GlArray.disable `texture_coord
;
696 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
697 GlArray.vertex `two state
.vraw
;
698 GlArray.draw_arrays `triangle_strip
0 4;
699 GlArray.enable `texture_coord
;
702 let linerect x0 y0 x1 y1 =
703 GlArray.disable `texture_coord
;
704 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
705 GlArray.vertex `two state
.vraw
;
706 GlArray.draw_arrays `line_loop
0 4;
707 GlArray.enable `texture_coord
;
710 let drawtiles l color
=
713 let f col row x y tilex tiley w h
=
714 match gettileopaque l col row with
715 | Some
(opaque
, _
, t
) ->
716 let params = x, y, w
, h
, tilex, tiley in
718 then GlTex.env
(`mode `blend
);
719 drawtile
params opaque
;
721 then GlTex.env
(`mode `modulate
);
725 let s = Printf.sprintf
729 let w = measurestr fstate
.fontsize
s in
730 GlDraw.color
(0.0, 0.0, 0.0);
731 filledrect (float (x-2))
734 (float (y + fstate
.fontsize
+ 2));
735 GlDraw.color
(1.0, 1.0, 1.0);
736 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
746 let lw = wadjsb state
.winw
- x in
749 let lh = state
.winh
- y in
753 then GlTex.env
(`mode `blend
);
754 begin match state
.checkerstexid
with
756 Gl.enable `texture_2d
;
757 GlTex.bind_texture `texture_2d id
;
761 and y1 = float (y+h
) in
763 let tw = float w /. 16.0
764 and th
= float h
/. 16.0 in
765 let tx0 = float tilex /. 16.0
766 and ty0
= float tiley /. 16.0 in
768 and ty1
= ty0
+. th
in
769 Raw.sets_float state
.vraw ~pos
:0
770 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
771 Raw.sets_float state
.traw ~pos
:0
772 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
773 GlArray.vertex `two state
.vraw
;
774 GlArray.tex_coord `two state
.traw
;
775 GlArray.draw_arrays `triangle_strip
0 4;
776 Gl.disable `texture_2d
;
779 GlDraw.color
(1.0, 1.0, 1.0);
780 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
783 then GlTex.env
(`mode `modulate
);
784 if w > 128 && h
> fstate
.fontsize
+ 10
786 let c = if conf
.invert
then 1.0 else 0.0 in
787 GlDraw.color
(c, c, c);
790 then (col*conf
.tilew
, row*conf
.tileh
)
793 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
802 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
804 let tilevisible1 l x y =
806 and ax1
= l.pagex
+ l.pagevw
808 and ay1
= l.pagey + l.pagevh in
812 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
813 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
815 let rx0 = max
ax0 bx0
816 and ry0
= max ay0 by0
817 and rx1
= min ax1
bx1
818 and ry1
= min ay1 by1
in
820 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
824 let tilevisible layout n x y =
825 let rec findpageinlayout m
= function
826 | l :: rest
when l.pageno
= n ->
827 tilevisible1 l x y || (
828 match conf
.columns
with
829 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
832 | _
:: rest
-> findpageinlayout 0 rest
835 findpageinlayout 0 layout;
838 let tileready l x y =
839 tilevisible1 l x y &&
840 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
843 let tilepage n p
layout =
844 let rec loop = function
848 let f col row _ _ _ _ _ _
=
849 if state
.currently
= Idle
851 match gettileopaque l col row with
854 let x = col*conf
.tilew
855 and y = row*conf
.tileh
in
857 let w = l.pagew
- x in
861 let h = l.pageh
- y in
866 then getpbo
w h conf
.colorspace
869 wcmd "tile %s %d %d %d %d %s"
870 (~
> p
) x y w h (~
> pbo);
873 l, p
, conf
.colorspace
, conf
.angle
,
874 state
.gen
, col, row, conf
.tilew
, conf
.tileh
883 if nogeomcmds state
.geomcmds
887 let preloadlayout y =
888 let y = if y < state
.winh
then 0 else y - state
.winh
in
889 let h = state
.winh
*3 in
895 if state
.currently
!= Idle
900 begin match getopaque l.pageno
with
902 wcmd "page %d %d" l.pageno
l.pagedimno
;
903 state
.currently
<- Loading
(l, state
.gen
);
905 tilepage l.pageno opaque pages
;
910 if nogeomcmds state
.geomcmds
916 if conf
.preload && state
.currently
= Idle
917 then load (preloadlayout state
.y);
920 let layoutready layout =
921 let rec fold all ls
=
924 let seen = ref false in
925 let allvisible = ref true in
926 let foo col row _ _ _ _ _ _
=
928 allvisible := !allvisible &&
929 begin match gettileopaque l col row with
935 fold (!seen && !allvisible) rest
938 let alltilesvisible = fold true layout in
943 let y = bound
y 0 state
.maxy
in
944 let y, layout, proceed
=
945 match conf
.maxwait
with
946 | Some time
when state
.ghyll
== noghyll
->
947 begin match state
.throttle
with
949 let layout = layout y state
.winh
in
950 let ready = layoutready layout in
954 state
.throttle
<- Some
(layout, y, now
());
956 else G.postRedisplay "gotoy showall (None)";
958 | Some
(_
, _
, started
) ->
959 let dt = now
() -. started
in
962 state
.throttle
<- None
;
963 let layout = layout y state
.winh
in
965 G.postRedisplay "maxwait";
972 let layout = layout y state
.winh
in
973 if not
!wtmode || layoutready layout
974 then G.postRedisplay "gotoy ready";
980 state
.layout <- layout;
981 begin match state
.mode
with
982 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
983 let rec loop = function
985 state
.mode
<- LinkNav
(Ltgendir
0)
986 | l :: _
when l.pageno
= pageno
->
987 begin match getopaque pageno
with
989 state
.mode
<- LinkNav
(Ltgendir
0)
991 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
992 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
993 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
994 then state
.mode
<- LinkNav
(Ltgendir
0)
996 | _
:: rest
-> loop rest
1001 begin match state
.mode
with
1002 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
1003 if not
(pagevisible layout pageno
)
1005 match state
.layout with
1008 state
.mode
<- Birdseye
(
1009 conf
, leftx
, l.pageno
, hooverpageno
, anchor
1012 | LinkNav
(Ltgendir dir
as lt
) ->
1014 let rec loop = function
1017 match getopaque l.pageno
with
1023 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1025 if dir
> 0 then LDfirst
else LDlast
1031 | Lnotfound
-> loop rest
1033 showlinktype (getlink opaque
n);
1034 Ltexact
(l.pageno
, n)
1038 state
.mode
<- LinkNav
linknav
1043 state
.ghyll
<- noghyll
;
1046 let mx, my
= state
.mpos
in
1051 let conttiling pageno opaque
=
1052 tilepage pageno opaque
1053 (if conf
.preload then preloadlayout state
.y else state
.layout)
1056 let gotoy_and_clear_text y =
1057 if not conf
.verbose
then state
.text <- E.s;
1061 let getanchory (n, top
, dtop
) =
1062 let y, h = getpageyh
n in
1063 if conf
.presentation
1065 let ips = calcips
h in
1066 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
1068 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
1071 let gotoanchor anchor
=
1072 gotoy (getanchory anchor
);
1076 cbput state
.hists
.nav
(getanchor
());
1080 let anchor = cbgetc state
.hists
.nav dir
in
1084 let gotoghyll1 single
y =
1085 let scroll f n a
b =
1086 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1088 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1090 then s (float f /. float a
)
1093 then 1.0 -. s ((float (f-b) /. float (n-b)))
1099 let ins = float a
*. 0.5
1100 and outs
= float (n-b) *. 0.5 in
1102 ins +. outs
+. float ones
1104 let rec set nab
y sy
=
1105 let (_N
, _A
, _B
), y =
1108 let scl = if y > sy
then 2 else -2 in
1109 let _N, _
, _
= nab
in
1110 (_N,0,_N), y+conf
.scrollstep
*scl
1112 let sum = summa
_N _A _B
in
1113 let dy = float (y - sy
) in
1117 then state
.ghyll
<- noghyll
1120 let s = scroll n _N _A _B
in
1121 let y1 = y1 +. ((s *. dy) /. sum) in
1122 gotoy_and_clear_text (truncate
y1);
1123 state
.ghyll
<- gf (n+1) y1;
1127 | Some
y'
when single
-> set nab
y' state
.y
1128 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1130 gf 0 (float state
.y)
1133 match conf
.ghyllscroll
with
1134 | Some nab
when not conf
.presentation
->
1135 if state
.ghyll
== noghyll
1136 then set nab
y state
.y
1137 else state
.ghyll
(Some
y)
1139 gotoy_and_clear_text y
1142 let gotoghyll = gotoghyll1 false;;
1144 let gotopage n top
=
1145 let y, h = getpageyh
n in
1146 let y = y + (truncate
(top
*. float h)) in
1150 let gotopage1 n top
=
1151 let y = getpagey
n in
1156 let invalidate s f =
1161 match state
.geomcmds
with
1162 | ps
, [] when emptystr ps
->
1164 state
.geomcmds
<- s, [];
1167 state
.geomcmds
<- ps
, [s, f];
1169 | ps
, (s'
, _
) :: rest
when s'
= s ->
1170 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1173 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1177 Hashtbl.iter
(fun _ opaque
->
1178 wcmd "freepage %s" (~
> opaque
);
1180 Hashtbl.clear state
.pagemap
;
1184 if not
(Queue.is_empty state
.tilelru
)
1186 Queue.iter
(fun (k
, p
, s) ->
1187 wcmd "freetile %s" (~
> p
);
1188 state
.memused
<- state
.memused
- s;
1189 Hashtbl.remove state
.tilemap k
;
1191 state
.uioh#infochanged Memused
;
1192 Queue.clear state
.tilelru
;
1198 let h = truncate
(float h*.conf
.zoom
) in
1199 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1203 let opendoc path password
=
1205 state
.password
<- password
;
1206 state
.gen
<- state
.gen
+ 1;
1207 state
.docinfo
<- [];
1210 setaalevel conf
.aalevel
;
1212 if emptystr state
.origin
1216 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1217 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
1218 invalidate "reqlayout"
1220 wcmd "reqlayout %d %d %d %s\000"
1221 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1222 (stateh state
.winh
) state
.nameddest
1227 state
.anchor <- getanchor
();
1228 opendoc state
.path state
.password
;
1232 let c = c *. conf
.colorscale
in
1236 let scalecolor2 (r
, g, b) =
1237 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1240 let docolumns = function
1242 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1243 let rec loop pageno
pdimno pdim
y ph pdims
=
1244 if pageno
= state
.pagecount
1247 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1249 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1250 pdimno+1, pdim
, rest
1254 let x = max
0 (((wadjsb state
.winw
- w) / 2) - xoff
) in
1256 (if conf
.presentation
1257 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1258 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1261 a.(pageno
) <- (pdimno, x, y, pdim
);
1262 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1264 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1265 conf
.columns
<- Csingle
a;
1267 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1268 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1269 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1270 let rec fixrow m
= if m
= pageno
then () else
1271 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1274 let y = y + (rowh
- h) / 2 in
1275 a.(m
) <- (pdimno, x, y, pdim
);
1279 if pageno
= state
.pagecount
1280 then fixrow (((pageno
- 1) / columns
) * columns
)
1282 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1284 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1285 pdimno+1, pdim
, rest
1290 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1292 let x = (wadjsb state
.winw
- w) / 2 in
1294 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1295 x, y + ips + rowh
, h
1298 if (pageno
- coverA
) mod columns
= 0
1300 let x = max
0 (wadjsb state
.winw
- state
.w) / 2 in
1302 if conf
.presentation
1304 let ips = calcips
h in
1305 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1307 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1311 else x, y, max rowh
h
1315 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1318 if pageno
= columns
&& conf
.presentation
1320 let ips = calcips rowh
in
1321 for i
= 0 to pred columns
1323 let (pdimno, x, y, pdim
) = a.(i
) in
1324 a.(i
) <- (pdimno, x, y+ips, pdim
)
1330 fixrow (pageno
- columns
);
1335 a.(pageno
) <- (pdimno, x, y, pdim
);
1336 let x = x + w + xoff
*2 + conf
.interpagespace
in
1337 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1339 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1340 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1343 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1344 let rec loop pageno
pdimno pdim
y pdims
=
1345 if pageno
= state
.pagecount
1348 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1350 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1351 pdimno+1, pdim
, rest
1356 let rec loop1 n x y =
1357 if n = c then y else (
1358 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1359 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1362 let y = loop1 0 0 y in
1363 loop (pageno
+1) pdimno pdim
y pdims
1365 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1366 conf
.columns
<- Csplit
(c, a);
1370 docolumns conf
.columns
;
1371 state
.maxy
<- calcheight
();
1372 if state
.reprf
== noreprf
1374 match state
.mode
with
1375 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1376 let y, h = getpageyh pageno
in
1377 let top = (state
.winh
- h) / 2 in
1378 gotoy (max
0 (y - top))
1379 | _
-> gotoanchor state
.anchor
1383 state
.reprf
<- noreprf
;
1388 GlDraw.viewport
0 0 w h;
1389 let firsttime = state
.geomcmds
== firstgeomcmds
in
1390 if not
firsttime && nogeomcmds state
.geomcmds
1391 then state
.anchor <- getanchor
();
1394 let w = wadjsb (truncate
(float w *. conf
.zoom
)) in
1397 setfontsize fstate
.fontsize
;
1398 GlMat.mode `modelview
;
1399 GlMat.load_identity
();
1401 GlMat.mode `projection
;
1402 GlMat.load_identity
();
1403 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1404 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1405 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1410 else float state
.x /. float state
.w
1412 invalidate "geometry"
1416 then state
.x <- truncate
(relx *. float w);
1418 match conf
.columns
with
1420 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1421 | Csplit
(c, _
) -> w * c
1423 wcmd "geometry %d %d %d"
1424 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1429 let len = String.length state
.text in
1430 let x0 = xadjsb 0 in
1433 match state
.mode
with
1434 | Textentry _
| View
| LinkNav _
->
1435 let h, _
, _
= state
.uioh#scrollpw
in
1440 filledrect x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1441 (x+.w) (float (state
.winh
- hscrollh))
1444 let w = float (wadjsb state
.winw
- 1) in
1445 if state
.progress
>= 0.0 && state
.progress
< 1.0
1447 GlDraw.color
(0.3, 0.3, 0.3);
1448 let w1 = w *. state
.progress
in
1450 GlDraw.color
(0.0, 0.0, 0.0);
1451 rect (float x0+.w1) (float x0+.w-.w1)
1454 GlDraw.color
(0.0, 0.0, 0.0);
1458 GlDraw.color
(1.0, 1.0, 1.0);
1459 drawstring fstate
.fontsize
1460 (if conf
.leftscroll
then x0 else x0 + if len > 0 then 8 else 2)
1461 (state
.winh
- hscrollh - 5) s;
1464 match state
.mode
with
1465 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1469 Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1471 Printf.sprintf
"%s%s_" prefix
text
1480 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1482 let s1 = "(press 'e' to review error messasges)" in
1483 if nonemptystr
s then s ^
" " ^
s1 else s1
1493 let len = Queue.length state
.tilelru
in
1495 match state
.throttle
with
1498 then preloadlayout state
.y
1500 | Some
(layout, _
, _
) ->
1504 if state
.memused
<= conf
.memlimit
1509 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1510 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1511 let (_
, pw, ph
, _
) = getpagedim
n in
1514 && colorspace
= conf
.colorspace
1515 && angle
= conf
.angle
1519 let x = col*conf
.tilew
1520 and y = row*conf
.tileh
in
1521 tilevisible (Lazy.force_val
layout) n x y
1523 then Queue.push lruitem state
.tilelru
1526 wcmd "freetile %s" (~
> p
);
1527 state
.memused
<- state
.memused
- s;
1528 state
.uioh#infochanged Memused
;
1529 Hashtbl.remove state
.tilemap k
;
1537 let logcurrently = function
1538 | Idle
-> dolog
"Idle"
1539 | Loading
(l, gen
) ->
1540 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen state
.gen
1541 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1543 "Tiling %d[%d,%d] page=%s cs=%s angle"
1544 l.pageno
col row (~
> pageopaque
)
1545 (CSTE.to_string colorspace
)
1547 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1548 angle gen conf
.angle state
.gen
1550 conf
.tilew conf
.tileh
1557 let r = Str.regexp
" " in
1558 fun s -> Str.bounded_split
r s 2;
1561 let onpagerect pageno
f =
1563 match conf
.columns
with
1564 | Cmulti
(_
, b) -> b
1566 | Csplit
(_
, b) -> b
1568 if pageno
>= 0 && pageno
< Array.length
b
1570 let (_
, _
, _
, (w, h, _
, _
)) = b.(pageno
) in
1574 let gotopagexy1 pageno
x y =
1575 let _,w1,h1
,leftx
= getpagedim pageno
in
1576 let top = y /. (float h1
) in
1577 let left = x /. (float w1) in
1578 let py, w, h = getpageywh pageno
in
1579 let wh = state
.winh
- hscrollh () in
1580 let x = left *. (float w) in
1581 let x = leftx
+ state
.x + truncate
x in
1583 if x < 0 || x >= wadjsb state
.winw
1587 let pdy = truncate
(top *. float h) in
1588 let y'
= py + pdy in
1589 let dy = y'
- state
.y in
1591 if x != state
.x || not
(dy > 0 && dy < wh)
1593 if conf
.presentation
1595 if abs
(py - y'
) > wh
1602 if state
.x != sx || state
.y != sy
1607 let ww = wadjsb state
.winw
in
1609 and qy
= pdy / wh in
1611 and y = py + qy
* wh in
1612 let x = if -x + ww > w1 then -(w1-ww) else x
1613 and y'
= if y + wh > state
.maxy
then state
.maxy
- wh else y in
1615 if conf
.presentation
1617 if abs
(py - y'
) > wh
1627 gotoy_and_clear_text y;
1629 else gotoy_and_clear_text state
.y;
1632 let gotopagexy pageno
x y =
1633 match state
.mode
with
1634 | Birdseye
_ -> gotopage pageno
0.0
1635 | _ -> gotopagexy1 pageno
x y
1639 (* dolog "%S" cmds; *)
1640 let cl = splitatspace cmds
in
1642 try Scanf.sscanf
s fmt
f
1644 dolog
"error processing '%S': %s" cmds
(exntos exn
);
1647 let addoutline outline
=
1648 match state
.currently
with
1649 | Outlining outlines
->
1650 state
.currently
<- Outlining
(outline
:: outlines
)
1651 | Idle
-> state
.currently
<- Outlining
[outline
]
1653 dolog
"invalid outlining state";
1654 logcurrently currently
1658 state
.uioh#infochanged Pdim
;
1661 | "clearrects" :: [] ->
1662 state
.rects
<- state
.rects1
;
1663 G.postRedisplay "clearrects";
1665 | "continue" :: args
:: [] ->
1666 let n = scan args
"%u" (fun n -> n) in
1667 state
.pagecount
<- n;
1668 begin match state
.currently
with
1670 state
.currently
<- Idle
;
1671 state
.outlines
<- Array.of_list
(List.rev
l)
1675 let cur, cmds
= state
.geomcmds
in
1677 then failwith
"umpossible";
1679 begin match List.rev cmds
with
1681 state
.geomcmds
<- E.s, [];
1682 state
.throttle
<- None
;
1686 state
.geomcmds
<- s, List.rev rest
;
1688 if conf
.maxwait
= None
&& not
!wtmode
1689 then G.postRedisplay "continue";
1691 | "title" :: args
:: [] ->
1695 | "msg" :: args
:: [] ->
1698 | "vmsg" :: args
:: [] ->
1700 then showtext ' ' args
1702 | "emsg" :: args
:: [] ->
1703 Buffer.add_string state
.errmsgs args
;
1704 state
.newerrmsgs
<- true;
1705 G.postRedisplay "error message"
1707 | "progress" :: args
:: [] ->
1708 let progress, text =
1711 f, String.sub args pos
(String.length args
- pos
))
1714 state
.progress <- progress;
1715 G.postRedisplay "progress"
1717 | "firstmatch" :: args
:: [] ->
1718 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1719 scan args
"%u %d %f %f %f %f %f %f %f %f"
1720 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1721 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1723 let xoff = float (xadjsb 0) in
1727 and x3
= x3
+. xoff in
1728 let y = (getpagey
pageno) + truncate
y0 in
1731 state
.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1733 | "match" :: args
:: [] ->
1734 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1735 scan args
"%u %d %f %f %f %f %f %f %f %f"
1736 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1737 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1739 let xoff = float (xadjsb 0) in
1743 and x3
= x3
+. xoff in
1745 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1747 | "page" :: args
:: [] ->
1748 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1749 let pageopaque = ~
< pageopaques in
1750 begin match state
.currently
with
1751 | Loading
(l, gen
) ->
1752 vlog "page %d took %f sec" l.pageno t
;
1753 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1754 begin match state
.throttle
with
1756 let preloadedpages =
1758 then preloadlayout state
.y
1763 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1764 IntSet.empty
preloadedpages
1767 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1768 if not
(IntSet.mem
pageno set)
1770 wcmd "freepage %s" (~
> opaque
);
1776 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1779 state
.currently
<- Idle
;
1782 tilepage l.pageno pageopaque state
.layout;
1784 load preloadedpages;
1785 if pagevisible state
.layout l.pageno
1786 && layoutready state
.layout
1787 then G.postRedisplay "page";
1790 | Some
(layout, _, _) ->
1791 state
.currently
<- Idle
;
1792 tilepage l.pageno pageopaque layout;
1797 dolog
"Inconsistent loading state";
1798 logcurrently state
.currently
;
1802 | "tile" :: args
:: [] ->
1803 let (x, y, opaques
, size
, t
) =
1804 scan args
"%u %u %s %u %f"
1805 (fun x y p size t
-> (x, y, p
, size
, t
))
1807 let opaque = ~
< opaques
in
1808 begin match state
.currently
with
1809 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1810 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1813 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1815 wcmd "freetile %s" (~
> opaque);
1816 state
.currently
<- Idle
;
1820 puttileopaque l col row gen cs angle
opaque size t
;
1821 state
.memused
<- state
.memused
+ size
;
1822 state
.uioh#infochanged Memused
;
1824 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1825 opaque, size
) state
.tilelru
;
1828 match state
.throttle
with
1829 | None
-> state
.layout
1830 | Some
(layout, _, _) -> layout
1833 state
.currently
<- Idle
;
1835 && conf
.colorspace
= cs
1836 && conf
.angle
= angle
1837 && tilevisible layout l.pageno x y
1838 then conttiling l.pageno pageopaque;
1840 begin match state
.throttle
with
1842 preload state
.layout;
1844 && conf
.colorspace
= cs
1845 && conf
.angle
= angle
1846 && tilevisible state
.layout l.pageno x y
1847 && (not
!wtmode || layoutready state
.layout)
1848 then G.postRedisplay "tile nothrottle";
1850 | Some
(layout, y, _) ->
1851 let ready = layoutready layout in
1855 state
.layout <- layout;
1856 state
.throttle
<- None
;
1857 G.postRedisplay "throttle";
1864 dolog
"Inconsistent tiling state";
1865 logcurrently state
.currently
;
1869 | "pdim" :: args
:: [] ->
1870 let (n, w, h, _) as pdim
=
1871 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1874 match conf
.fitmodel
, conf
.columns
with
1875 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
1878 state
.uioh#infochanged Pdim
;
1879 state
.pdims
<- pdim :: state
.pdims
1881 | "o" :: args
:: [] ->
1882 let (l, n, t
, h, pos
) =
1883 scan args
"%u %u %d %u %n"
1884 (fun l n t
h pos
-> l, n, t
, h, pos
)
1886 let s = String.sub args pos
(String.length args
- pos
) in
1887 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1889 | "ou" :: args
:: [] ->
1890 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1891 let s = String.sub args pos
len in
1892 let pos2 = pos
+ len + 1 in
1893 let uri = String.sub args
pos2 (String.length args
- pos2) in
1894 addoutline (s, l, Ouri
uri)
1896 | "on" :: args
:: [] ->
1897 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1898 let s = String.sub args pos
(String.length args
- pos
) in
1899 addoutline (s, l, Onone
)
1901 | "a" :: args
:: [] ->
1903 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1905 state
.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
1907 | "info" :: args
:: [] ->
1908 state
.docinfo
<- (1, args
) :: state
.docinfo
1910 | "infoend" :: [] ->
1911 state
.uioh#infochanged Docinfo
;
1912 state
.docinfo
<- List.rev state
.docinfo
1915 error
"unknown cmd `%S'" cmds
1920 let action = function
1921 | HCprev
-> cbget cb ~
-1
1922 | HCnext
-> cbget cb
1
1923 | HCfirst
-> cbget cb ~
-(cb
.rc)
1924 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1925 and cancel
() = cb
.rc <- rc
1929 let search pattern forward
=
1930 match conf
.columns
with
1932 showtext '
!'
"searching does not work properly in split columns mode"
1934 if nonemptystr pattern
1937 match state
.layout with
1940 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1942 wcmd "search %d %d %d %d,%s\000"
1943 (btod conf
.icase
) pn py (btod forward
) pattern
;
1946 let intentry text key =
1948 if key >= 32 && key < 127
1954 let text = addchar text c in
1958 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1962 let linknentry text key =
1964 if key >= 32 && key < 127
1970 let text = addchar text c in
1974 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1982 let l = String.length
s in
1983 let rec loop pos
n = if pos
= l then n else
1984 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1985 loop (pos
+1) (n*26 + m)
1988 let rec loop n = function
1991 match getopaque l.pageno with
1992 | None
-> loop n rest
1994 let m = getlinkcount
opaque in
1997 let under = getlink
opaque n in
2000 else loop (n-m) rest
2002 loop n state
.layout;
2006 let textentry text key =
2007 if key land 0xff00 = 0xff00
2009 else TEcont
(text ^ toutf8
key)
2012 let reqlayout angle fitmodel
=
2013 match state
.throttle
with
2015 if nogeomcmds state
.geomcmds
2016 then state
.anchor <- getanchor
();
2017 conf
.angle
<- angle
mod 360;
2020 match state
.mode
with
2021 | LinkNav
_ -> state
.mode
<- View
2024 conf
.fitmodel
<- fitmodel
;
2025 invalidate "reqlayout"
2027 wcmd "reqlayout %d %d %d"
2028 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
2033 let settrim trimmargins trimfuzz
=
2034 if nogeomcmds state
.geomcmds
2035 then state
.anchor <- getanchor
();
2036 conf
.trimmargins
<- trimmargins
;
2037 conf
.trimfuzz
<- trimfuzz
;
2038 let x0, y0, x1, y1 = trimfuzz
in
2039 invalidate "settrim"
2041 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
2046 match state
.throttle
with
2048 let zoom = max
0.0001 zoom in
2049 if zoom <> conf
.zoom
2051 state
.prevzoom
<- (conf
.zoom, state
.x);
2053 reshape state
.winw state
.winh
;
2054 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2057 | Some
(layout, y, started
) ->
2059 match conf
.maxwait
with
2063 let dt = now
() -. started
in
2071 let setcolumns mode columns coverA coverB
=
2072 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2076 then showtext '
!'
"split mode doesn't work in bird's eye"
2078 conf
.columns
<- Csplit
(-columns
, E.a);
2086 conf
.columns
<- Csingle
E.a;
2091 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2095 reshape state
.winw state
.winh
;
2098 let resetmstate () =
2099 state
.mstate
<- Mnone
;
2100 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2103 let enterbirdseye () =
2104 let zoom = float conf
.thumbw
/. float state
.winw
in
2105 let birdseyepageno =
2106 let cy = state
.winh
/ 2 in
2110 let rec fold best
= function
2113 let d = cy - (l.pagedispy + l.pagevh/2)
2114 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2115 if abs
d < abs dbest
2122 state
.mode
<- Birdseye
(
2123 { conf
with zoom = conf
.zoom }, state
.x, birdseyepageno, -1, getanchor
()
2127 conf
.presentation
<- false;
2128 conf
.interpagespace
<- 10;
2129 conf
.hlinks
<- false;
2130 conf
.fitmodel
<- FitProportional
;
2132 conf
.maxwait
<- None
;
2134 match conf
.beyecolumns
with
2137 Cmulti
((c, 0, 0), E.a)
2138 | None
-> Csingle
E.a
2142 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2147 reshape state
.winw state
.winh
;
2150 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2152 conf
.zoom <- c.zoom;
2153 conf
.presentation
<- c.presentation
;
2154 conf
.interpagespace
<- c.interpagespace
;
2155 conf
.maxwait
<- c.maxwait
;
2156 conf
.hlinks
<- c.hlinks
;
2157 conf
.fitmodel
<- c.fitmodel
;
2158 conf
.beyecolumns
<- (
2159 match conf
.columns
with
2160 | Cmulti
((c, _, _), _) -> Some
c
2162 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2165 match c.columns
with
2166 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2167 | Csingle
_ -> Csingle
E.a
2168 | Csplit
(c, _) -> Csplit
(c, E.a)
2172 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2175 reshape state
.winw state
.winh
;
2176 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2180 let togglebirdseye () =
2181 match state
.mode
with
2182 | Birdseye vals
-> leavebirdseye vals
true
2183 | View
-> enterbirdseye ()
2187 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2188 let pageno = max
0 (pageno - incr
) in
2189 let rec loop = function
2190 | [] -> gotopage1 pageno 0
2191 | l :: _ when l.pageno = pageno ->
2192 if l.pagedispy >= 0 && l.pagey = 0
2193 then G.postRedisplay "upbirdseye"
2194 else gotopage1 pageno 0
2195 | _ :: rest
-> loop rest
2198 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2201 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2202 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2203 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2204 let rec loop = function
2206 let y, h = getpageyh
pageno in
2207 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2209 | l :: _ when l.pageno = pageno ->
2210 if l.pagevh != l.pageh
2211 then gotoy (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2212 else G.postRedisplay "downbirdseye"
2213 | _ :: rest
-> loop rest
2218 let boundastep h step
=
2220 then bound step ~
-h 0
2224 let optentry mode
_ key =
2225 let btos b = if b then "on" else "off" in
2226 if key >= 32 && key < 127
2228 let c = Char.chr
key in
2232 try conf
.scrollstep
<- int_of_string
s with exc
->
2233 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2235 TEswitch
("scroll step: ", E.s, None
, intentry, ondone, true)
2240 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2241 if state
.autoscroll
<> None
2242 then state
.autoscroll
<- Some conf
.autoscrollstep
2244 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2246 TEswitch
("auto scroll step: ", E.s, None
, intentry, ondone, true)
2251 let n, a, b = multicolumns_of_string
s in
2252 setcolumns mode
n a b;
2254 state
.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
2256 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
2261 let zoom = float (int_of_string
s) /. 100.0 in
2264 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2266 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
2271 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2273 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2274 begin match mode
with
2276 leavebirdseye beye
false;
2281 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2283 TEswitch
("thumbnail width: ", E.s, None
, intentry, ondone, true)
2288 Some
(int_of_string
s)
2290 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2294 | Some angle
-> reqlayout angle conf
.fitmodel
2297 TEswitch
("rotation: ", E.s, None
, intentry, ondone, true)
2300 conf
.icase
<- not conf
.icase
;
2301 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2304 conf
.preload <- not conf
.preload;
2306 TEdone
("preload " ^
(btos conf
.preload))
2309 conf
.verbose
<- not conf
.verbose
;
2310 TEdone
("verbose " ^
(btos conf
.verbose
))
2313 conf
.debug
<- not conf
.debug
;
2314 TEdone
("debug " ^
(btos conf
.debug
))
2317 conf
.maxhfit
<- not conf
.maxhfit
;
2318 state
.maxy
<- calcheight
();
2319 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2322 conf
.crophack
<- not conf
.crophack
;
2323 TEdone
("crophack " ^
btos conf
.crophack
)
2327 match conf
.maxwait
with
2329 conf
.maxwait
<- Some infinity
;
2330 "always wait for page to complete"
2332 conf
.maxwait
<- None
;
2333 "show placeholder if page is not ready"
2338 conf
.underinfo
<- not conf
.underinfo
;
2339 TEdone
("underinfo " ^
btos conf
.underinfo
)
2342 conf
.savebmarks
<- not conf
.savebmarks
;
2343 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2349 match state
.layout with
2354 conf
.interpagespace
<- int_of_string
s;
2355 docolumns conf
.columns
;
2356 state
.maxy
<- calcheight
();
2357 let y = getpagey
pageno in
2360 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2362 TEswitch
("vertical margin: ", E.s, None
, intentry, ondone, true)
2366 match conf
.fitmodel
with
2367 | FitProportional
-> FitWidth
2368 | _ -> FitProportional
2370 reqlayout conf
.angle
fm;
2371 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2374 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2375 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2378 conf
.invert
<- not conf
.invert
;
2379 TEdone
("invert colors " ^
btos conf
.invert
)
2383 cbput state
.hists
.sel
s;
2386 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2387 textentry, ondone, true)
2391 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2392 else conf
.pax
<- None
;
2393 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2396 state
.text <- Printf.sprintf
"bad option %d `%c'" key c;
2402 class type lvsource
= object
2403 method getitemcount
: int
2404 method getitem
: int -> (string * int)
2405 method hasaction
: int -> bool
2413 method getactive
: int
2414 method getfirst
: int
2416 method getminfo
: (int * int) array
2419 class virtual lvsourcebase
= object
2420 val mutable m_active
= 0
2421 val mutable m_first
= 0
2422 val mutable m_pan
= 0
2423 method getactive
= m_active
2424 method getfirst
= m_first
2425 method getpan
= m_pan
2426 method getminfo
: (int * int) array
= E.a
2429 let withoutlastutf8 s =
2430 let len = String.length
s in
2438 let b = Char.code
s.[pos
] in
2439 if b land 0b11000000 = 0b11000000
2444 if Char.code
s.[len-1] land 0x80 = 0
2448 String.sub
s 0 first;
2451 let textentrykeyboard
2452 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2454 if key >= 0xffb0 && key <= 0xffb9
2455 then key - 0xffb0 + 48 else key
2458 state
.mode
<- Textentry
(te
, onleave
);
2461 G.postRedisplay "textentrykeyboard enttext";
2463 let histaction cmd
=
2466 | Some
(action, _) ->
2467 state
.mode
<- Textentry
(
2468 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2470 G.postRedisplay "textentry histaction"
2473 | 0xff08 -> (* backspace *)
2474 if emptystr
text && cancelonempty
2477 G.postRedisplay "textentrykeyboard after cancel";
2480 let s = withoutlastutf8 text in
2481 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2483 | 0xff0d | 0xff8d -> (* (kp) enter *)
2486 G.postRedisplay "textentrykeyboard after confirm"
2488 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
2489 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
2490 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
2491 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
2493 | 0xff1b -> (* escape*)
2496 begin match opthist
with
2498 | Some
(_, onhistcancel
) -> onhistcancel
()
2502 G.postRedisplay "textentrykeyboard after cancel2"
2505 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2508 | 0xff9f | 0xffff -> () (* delete *)
2511 && key land 0xff00 != 0xff00 (* keyboard *)
2512 && key land 0xfe00 != 0xfe00 (* xkb *)
2513 && key land 0xfd00 != 0xfd00 (* 3270 *)
2515 begin match onkey
text key with
2519 G.postRedisplay "textentrykeyboard after confirm2";
2522 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2526 G.postRedisplay "textentrykeyboard after cancel3"
2529 state
.mode
<- Textentry
(te
, onleave
);
2530 G.postRedisplay "textentrykeyboard switch";
2534 vlog "unhandled key %s" (Wsi.keyname
key)
2537 let firstof first active
=
2538 if first > active
|| abs
(first - active
) > fstate
.maxrows
- 1
2539 then max
0 (active
- (fstate
.maxrows
/2))
2543 let calcfirst first active
=
2546 let rows = active
- first in
2547 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2551 let scrollph y maxy
=
2552 let sh = float (maxy
+ state
.winh
) /. float state
.winh
in
2553 let sh = float state
.winh
/. sh in
2554 let sh = max
sh (float conf
.scrollh
) in
2556 let percent = float y /. float maxy
in
2557 let position = (float state
.winh
-. sh) *. percent in
2560 if position +. sh > float state
.winh
2561 then float state
.winh
-. sh
2567 let coe s = (s :> uioh
);;
2569 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2571 val m_pan
= source#getpan
2572 val m_first
= source#getfirst
2573 val m_active
= source#getactive
2575 val m_prev_uioh
= state
.uioh
2577 method private elemunder
y =
2581 let n = y / (fstate
.fontsize
+1) in
2582 if m_first
+ n < source#getitemcount
2584 if source#hasaction
(m_first
+ n)
2585 then Some
(m_first
+ n)
2592 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2593 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2594 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2595 GlDraw.color
(1., 1., 1.);
2596 Gl.enable `texture_2d
;
2597 let fs = fstate
.fontsize
in
2599 let ww = fstate
.wwidth
in
2600 let tabw = 17.0*.ww in
2601 let itemcount = source#getitemcount
in
2602 let minfo = source#getminfo
in
2605 then float (xadjsb 0), float (state
.winw
- 1)
2606 else 0.0, float (state
.winw
- conf
.scrollbw
- 1)
2609 if (row - m_first
) > fstate
.maxrows
2612 if row >= 0 && row < itemcount
2614 let (s, level
) = source#getitem
row in
2615 let y = (row - m_first
) * nfs in
2617 (if conf
.leftscroll
then float (xadjsb 0) else 5.0)
2618 +. (float (level
+ m_pan
)) *. ww in
2621 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2625 Gl.disable `texture_2d
;
2626 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2627 GlDraw.color
(1., 1., 1.) ~
alpha;
2628 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2629 Gl.enable `texture_2d
;
2632 if zebra
&& row land 1 = 1
2636 GlDraw.color
(c,c,c);
2637 let drawtabularstring s =
2640 try String.index
s '
\000'
2641 with Not_found
-> -1
2644 then drawstring1 fs (truncate
(x +. x0)) (y+nfs) s
2646 let s1 = String.sub
s 0 pos
2647 and s2
= String.sub
s (pos+1) (String.length
s - pos - 1) in
2648 let xx = ww +. drawstring1 fs (truncate
(x+.x0)) (y+nfs) s1 in
2649 let x2 = (wadjsb (xadjsb state
.winw
))/2 in
2650 let x = max
x2 (truncate
xx) in
2651 drawstring1 fs x (y+nfs) s2
2655 let x = if helpmode
&& row > 0 then x +. ww else x in
2656 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2659 let len = String.length
s - tabpos - 1 in
2660 let s1 = String.sub
s 0 tabpos
2661 and s2
= String.sub
s (tabpos + 1) len in
2662 let nx = drawstr x s1 in
2664 let x = x +. (max
tabw sw) in
2667 let len = String.length
s - 2 in
2668 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2670 let s = String.sub
s 2 len in
2671 let x = if not helpmode
then x +. ww else x in
2672 GlDraw.color
(1.2, 1.2, 1.2);
2673 let vinc = drawstring1 (fs+fs/4)
2674 (truncate
(x -. ww)) (y+nfs) s in
2675 GlDraw.color
(1., 1., 1.);
2676 vinc +. (float fs *. 0.8)
2682 let _ = drawtabularstring s in
2688 GlDraw.color
(1.0, 1.0, 1.0) ~
alpha:0.5;
2690 if (row - m_first
) > fstate
.maxrows
2693 if row >= 0 && row < itemcount
2695 let (s, level
) = source#getitem
row in
2696 let y = (row - m_first
) * nfs in
2697 let x = float (level
+ m_pan
) *. ww in
2698 let (first, last
) = minfo.(row) in
2699 let prefix = String.sub
s 0 first in
2700 let suffix = String.sub
s first (last
- first) in
2701 let w1 = measurestr fstate
.fontsize
prefix in
2702 let w2 = measurestr fstate
.fontsize
suffix in
2703 let x = x +. if conf
.leftscroll
then float (xadjsb 5) else 5.0 in
2705 and y0 = float (y+2) in
2707 and y1 = float (y+fs+3) in
2708 filledrect x0 y0 x1 y1;
2713 Gl.disable `texture_2d
;
2714 if Array.length
minfo > 0 then loop m_first
;
2717 method updownlevel incr
=
2718 let len = source#getitemcount
in
2720 if m_active
>= 0 && m_active
< len
2721 then snd
(source#getitem m_active
)
2725 if i
= len then i
-1 else if i
= -1 then 0 else
2726 let _, l = source#getitem i
in
2727 if l != curlevel then i
else flow (i
+incr
)
2729 let active = flow m_active
in
2730 let first = calcfirst m_first
active in
2731 G.postRedisplay "outline updownlevel";
2732 {< m_active
= active; m_first
= first >}
2734 method private key1
key mask
=
2735 let set1 active first qsearch
=
2736 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2738 let search active pattern incr
=
2739 let active = if active = -1 then m_first
else active in
2742 if n >= 0 && n < source#getitemcount
2744 let s, _ = source#getitem
n in
2746 (try ignore
(Str.search_forward
re s 0); true
2747 with Not_found
-> false)
2749 else loop (n + incr
)
2756 let re = Str.regexp_case_fold pattern
in
2762 let itemcount = source#getitemcount
in
2763 let find start incr
=
2765 if i
= -1 || i
= itemcount
2768 if source#hasaction i
2770 else find (i
+ incr
)
2775 let set active first =
2776 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2778 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2781 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2783 let incr1 = if incr
> 0 then 1 else -1 in
2784 if isvisible m_first m_active
2787 let next = m_active
+ incr
in
2789 if next < 0 || next >= itemcount
2791 else find next incr1
2793 if abs
(m_active
- next) > fstate
.maxrows
2799 let first = m_first
+ incr
in
2800 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2802 let next = m_active
+ incr
in
2803 let next = bound
next 0 (itemcount - 1) in
2810 if isvisible first next
2817 let first = min
next m_first
in
2819 if abs
(next - first) > fstate
.maxrows
2825 let first = m_first
+ incr
in
2826 let first = bound
first 0 (itemcount - 1) in
2828 let next = m_active
+ incr
in
2829 let next = bound
next 0 (itemcount - 1) in
2830 let next = find next incr1 in
2832 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2834 let active = if m_active
= -1 then next else m_active
in
2839 if isvisible first active
2845 G.postRedisplay "listview navigate";
2849 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2850 let incr = if key = 0x72 then -1 else 1 in
2852 match search (m_active
+ incr) m_qsearch
incr with
2854 state
.text <- m_qsearch ^
" [not found]";
2857 state
.text <- m_qsearch
;
2858 active, firstof m_first
active
2860 G.postRedisplay "listview ctrl-r/s";
2861 set1 active first m_qsearch
;
2863 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
2864 if m_active
>= 0 && m_active
< source#getitemcount
2866 let s, _ = source#getitem m_active
in
2871 | 0xff08 -> (* backspace *)
2872 if emptystr m_qsearch
2875 let qsearch = withoutlastutf8 m_qsearch
in
2879 G.postRedisplay "listview empty qsearch";
2880 set1 m_active m_first
E.s;
2884 match search m_active
qsearch ~
-1 with
2886 state
.text <- qsearch ^
" [not found]";
2889 state
.text <- qsearch;
2890 active, firstof m_first
active
2892 G.postRedisplay "listview backspace qsearch";
2893 set1 active first qsearch
2896 | key when (key != 0 && key land 0xff00 != 0xff00) ->
2897 let pattern = m_qsearch ^ toutf8
key in
2899 match search m_active
pattern 1 with
2901 state
.text <- pattern ^
" [not found]";
2904 state
.text <- pattern;
2905 active, firstof m_first
active
2907 G.postRedisplay "listview qsearch add";
2908 set1 active first pattern;
2910 | 0xff1b -> (* escape *)
2912 if emptystr m_qsearch
2914 G.postRedisplay "list view escape";
2917 source#exit
(coe self
) true m_active m_first m_pan
2919 | None
-> m_prev_uioh
2924 G.postRedisplay "list view kill qsearch";
2925 coe {< m_qsearch
= E.s >}
2928 | 0xff0d | 0xff8d -> (* (kp) enter *)
2930 let self = {< m_qsearch
= E.s >} in
2932 G.postRedisplay "listview enter";
2933 if m_active
>= 0 && m_active
< source#getitemcount
2935 source#exit
(coe self) false m_active m_first m_pan
;
2938 source#exit
(coe self) true m_active m_first m_pan
;
2941 begin match opt with
2942 | None
-> m_prev_uioh
2946 | 0xff9f | 0xffff -> (* (kp) delete *)
2949 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
2950 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
2951 | 0xff55 | 0xff9a -> navigate ~
-(fstate
.maxrows
) (* (kp) prior *)
2952 | 0xff56 | 0xff9b -> navigate fstate
.maxrows
(* (kp) next *)
2954 | 0xff53 | 0xff98 -> (* (kp) right *)
2956 G.postRedisplay "listview right";
2957 coe {< m_pan
= m_pan
- 1 >}
2959 | 0xff51 | 0xff96 -> (* (kp) left *)
2961 G.postRedisplay "listview left";
2962 coe {< m_pan
= m_pan
+ 1 >}
2964 | 0xff50 | 0xff95 -> (* (kp) home *)
2965 let active = find 0 1 in
2966 G.postRedisplay "listview home";
2969 | 0xff57 | 0xff9c -> (* (kp) end *)
2970 let first = max
0 (itemcount - fstate
.maxrows
) in
2971 let active = find (itemcount - 1) ~
-1 in
2972 G.postRedisplay "listview end";
2975 | key when (key = 0 || key land 0xff00 = 0xff00) ->
2979 dolog
"listview unknown key %#x" key; coe self
2981 method key key mask
=
2982 match state
.mode
with
2983 | Textentry te
-> textentrykeyboard key mask te
; coe self
2984 | _ -> self#key1
key mask
2986 method button button down
x y _ =
2989 | 1 when x > state
.winw
- conf
.scrollbw
->
2990 G.postRedisplay "listview scroll";
2993 let _, position, sh = self#
scrollph in
2994 if y > truncate
position && y < truncate
(position +. sh)
2996 state
.mstate
<- Mscrolly
;
3000 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3001 let first = truncate
(s *. float source#getitemcount
) in
3002 let first = min source#getitemcount
first in
3003 Some
(coe {< m_first
= first; m_active
= first >})
3005 state
.mstate
<- Mnone
;
3008 | 1 when not down
->
3009 begin match self#elemunder
y with
3011 G.postRedisplay "listview click";
3012 source#exit
(coe {< m_active
= n >}) false n m_first m_pan
3016 | n when (n == 4 || n == 5) && not down
->
3017 let len = source#getitemcount
in
3019 if n = 5 && m_first
+ fstate
.maxrows
>= len
3023 let first = m_first
+ (if n == 4 then -1 else 1) in
3024 bound
first 0 (len - 1)
3026 G.postRedisplay "listview wheel";
3027 Some
(coe {< m_first
= first >})
3028 | n when (n = 6 || n = 7) && not down
->
3029 let inc = if n = 7 then -1 else 1 in
3030 G.postRedisplay "listview hwheel";
3031 Some
(coe {< m_pan
= m_pan
+ inc >})
3036 | None
-> m_prev_uioh
3039 method multiclick
_ x y = self#button
1 true x y
3042 match state
.mstate
with
3044 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3045 let first = truncate
(s *. float source#getitemcount
) in
3046 let first = min source#getitemcount
first in
3047 G.postRedisplay "listview motion";
3048 coe {< m_first
= first; m_active
= first >}
3051 method pmotion
x y =
3052 if x < state
.winw
- conf
.scrollbw
3055 match self#elemunder
y with
3056 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3057 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3061 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3066 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3070 method infochanged
_ = ()
3072 method scrollpw
= (0, 0.0, 0.0)
3074 let nfs = fstate
.fontsize
+ 1 in
3075 let y = m_first
* nfs in
3076 let itemcount = source#getitemcount
in
3077 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3078 let maxy = maxi * nfs in
3079 let p, h = scrollph y maxy in
3082 method modehash
= modehash
3083 method eformsgs
= false
3086 class outlinelistview ~zebra ~source
=
3087 let settext autonarrow
s =
3090 let ss = source#statestr
in
3094 else "{" ^
ss ^
"} [" ^
s ^
"]"
3095 else state
.text <- s
3101 ~source
:(source
:> lvsource
)
3103 ~modehash
:(findkeyhash conf
"outline")
3106 val m_autonarrow
= false
3108 method key key mask
=
3110 if emptystr state
.text
3112 else fstate
.maxrows - 2
3114 let calcfirst first active =
3117 let rows = active - first in
3118 if rows > maxrows then active - maxrows else first
3122 let active = m_active
+ incr in
3123 let active = bound
active 0 (source#getitemcount
- 1) in
3124 let first = calcfirst m_first
active in
3125 G.postRedisplay "outline navigate";
3126 coe {< m_active
= active; m_first
= first >}
3128 let navscroll first =
3130 let dist = m_active
- first in
3136 else first + maxrows
3139 G.postRedisplay "outline navscroll";
3140 coe {< m_first
= first; m_active
= active >}
3142 let ctrl = Wsi.withctrl mask
in
3144 | 97 when ctrl -> (* ctrl-a *)
3147 then (source#denarrow
; E.s)
3149 let pattern = source#renarrow
in
3150 if nonemptystr m_qsearch
3151 then (source#narrow m_qsearch
; m_qsearch
)
3155 settext (not m_autonarrow
) text;
3156 G.postRedisplay "toggle auto narrowing";
3157 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3159 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3161 G.postRedisplay "toggle auto narrowing";
3162 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3164 | 110 when ctrl -> (* ctrl-n *)
3165 source#narrow m_qsearch
;
3167 then source#add_narrow_pattern m_qsearch
;
3168 G.postRedisplay "outline ctrl-n";
3169 coe {< m_first
= 0; m_active
= 0 >}
3171 | 83 when ctrl -> (* ctrl-S *)
3172 let active = source#calcactive
(getanchor
()) in
3173 let first = firstof m_first
active in
3174 G.postRedisplay "outline ctrl-s";
3175 coe {< m_first
= first; m_active
= active >}
3177 | 117 when ctrl -> (* ctrl-u *)
3178 G.postRedisplay "outline ctrl-u";
3179 if m_autonarrow
&& nonemptystr m_qsearch
3181 ignore
(source#renarrow
);
3182 settext m_autonarrow
E.s;
3183 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3186 source#del_narrow_pattern
;
3187 let pattern = source#renarrow
in
3189 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3191 settext m_autonarrow
text;
3192 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3195 | 108 when ctrl -> (* ctrl-l *)
3196 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3197 G.postRedisplay "outline ctrl-l";
3198 coe {< m_first
= first >}
3200 | 0xff09 when m_autonarrow
-> (* tab *)
3201 if nonemptystr m_qsearch
3203 G.postRedisplay "outline list view tab";
3204 source#add_narrow_pattern m_qsearch
;
3206 coe {< m_qsearch
= E.s >}
3210 | 0xff1b when m_autonarrow
-> (* escape *)
3211 if nonemptystr m_qsearch
3212 then source#add_narrow_pattern m_qsearch
;
3215 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3216 if nonemptystr m_qsearch
3217 then source#add_narrow_pattern m_qsearch
;
3220 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3221 let pattern = m_qsearch ^ toutf8
key in
3222 G.postRedisplay "outlinelistview autonarrow add";
3223 source#narrow
pattern;
3224 settext true pattern;
3225 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3227 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3228 if emptystr m_qsearch
3231 let pattern = withoutlastutf8 m_qsearch
in
3232 G.postRedisplay "outlinelistview autonarrow backspace";
3233 ignore
(source#renarrow
);
3234 source#narrow
pattern;
3235 settext true pattern;
3236 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3238 | 0xff9f | 0xffff -> (* (kp) delete *)
3239 source#remove m_active
;
3240 G.postRedisplay "outline delete";
3241 let active = max
0 (m_active
-1) in
3242 coe {< m_first
= firstof m_first
active;
3243 m_active
= active >}
3245 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3246 navscroll (max
0 (m_first
- 1))
3248 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3249 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3251 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3252 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3253 | 0xff55 | 0xff9a -> (* (kp) prior *)
3254 navigate ~
-(fstate
.maxrows)
3255 | 0xff56 | 0xff9b -> (* (kp) next *)
3256 navigate fstate
.maxrows
3258 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3262 G.postRedisplay "outline ctrl right";
3263 {< m_pan
= m_pan
+ 1 >}
3265 else self#updownlevel
1
3269 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3273 G.postRedisplay "outline ctrl left";
3274 {< m_pan
= m_pan
- 1 >}
3276 else self#updownlevel ~
-1
3280 | 0xff50 | 0xff95 -> (* (kp) home *)
3281 G.postRedisplay "outline home";
3282 coe {< m_first
= 0; m_active
= 0 >}
3284 | 0xff57 | 0xff9c -> (* (kp) end *)
3285 let active = source#getitemcount
- 1 in
3286 let first = max
0 (active - fstate
.maxrows) in
3287 G.postRedisplay "outline end";
3288 coe {< m_active
= active; m_first
= first >}
3290 | _ -> super#
key key mask
3293 let gotounder under =
3294 let getpath filename
=
3296 if nonemptystr filename
3298 if Filename.is_relative filename
3300 let dir = Filename.dirname state
.path in
3302 if Filename.is_implicit
dir
3303 then Filename.concat
(Sys.getcwd
()) dir
3306 Filename.concat
dir filename
3310 if Sys.file_exists
path
3315 | Ulinkgoto
(pageno, top) ->
3319 gotopage1 pageno top;
3325 | Uremote
(filename
, pageno) ->
3326 let path = getpath filename
in
3331 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
3332 try popen
command []
3334 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
3337 let anchor = getanchor
() in
3338 let ranchor = state
.path, state
.password
, anchor, state
.origin
in
3339 state
.origin
<- E.s;
3340 state
.anchor <- (pageno, 0.0, 0.0);
3341 state
.ranchors
<- ranchor :: state
.ranchors
;
3344 else showtext '
!'
("Could not find " ^ filename
)
3346 | Uremotedest
(filename
, destname
) ->
3347 let path = getpath filename
in
3352 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
3353 try popen
command []
3356 "failed to execute `%s': %s\n" command (exntos exn
);
3359 let anchor = getanchor
() in
3360 let ranchor = state
.path, state
.password
, anchor, state
.origin
in
3361 state
.origin
<- E.s;
3362 state
.nameddest
<- destname
;
3363 state
.ranchors
<- ranchor :: state
.ranchors
;
3366 else showtext '
!'
("Could not find " ^ filename
)
3368 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
3371 let gotohist (path, (c, bookmarks
, x, anchor)) =
3372 Config.save
leavebirdseye;
3373 state
.anchor <- anchor;
3375 state
.bookmarks
<- bookmarks
;
3376 state
.origin
<- E.s;
3378 conf
.presentation
<- c.presentation
;
3381 let gotooutline (_, _, kind
) =
3385 let (pageno, y, _) = anchor in
3387 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3391 | Ouri
uri -> gotounder (Ulinkuri
uri)
3392 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
3393 | Oremote remote
-> gotounder (Uremote remote
)
3394 | Ohistory hist
-> gotohist hist
3395 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
3398 let genhistoutlines =
3399 let order ty
(p1
, c1
, _, _, _) (p2
, c2
, _, _, _) =
3401 | `lastvisit
-> compare c1
.lastvisit c2
.lastvisit
3402 | `
path -> compare p1 p2
3403 | `file
-> compare
(Filename.basename p1
) (Filename.basename p2
)
3404 | `title
-> compare c1
.title c2
.title
3407 let list = ref [] in
3408 if Config.gethist
list
3412 (fun accu (path, c, b, x, a) ->
3413 let hist = (path, (c, b, x, a)) in
3414 let base = mbtoutf8
(Filename.basename
path) in
3415 (base ^
"\000" ^
c.title
, 1, Ohistory
hist) :: accu
3417 [] (List.sort
(order orderty
) !list)
3423 let outlinesource sourcetype
=
3426 inherit lvsourcebase
3427 val mutable m_items
= empty
3428 val mutable m_minfo
= empty
3429 val mutable m_orig_items
= empty
3430 val mutable m_orig_minfo
= empty
3431 val mutable m_narrow_patterns
= []
3432 val mutable m_hadremovals
= false
3433 val mutable m_gen
= -1
3435 method getitemcount
=
3436 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3439 if n == Array.length m_items
&& m_hadremovals
3441 ("[Confirm removal]", 0)
3443 let s, n, _ = m_items
.(n) in
3446 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3447 ignore
(uioh
, first);
3448 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3450 if m_narrow_patterns
= []
3451 then m_orig_items
, m_orig_minfo
3452 else m_items
, m_minfo
3456 if not
confrimremoval
3458 gotooutline m_items
.(active);
3463 state
.bookmarks
<- Array.to_list m_items
;
3464 m_orig_items
<- m_items
;
3465 m_orig_minfo
<- m_minfo
;
3475 method hasaction
_ = true
3478 if Array.length m_items
!= Array.length m_orig_items
3481 match m_narrow_patterns
with
3483 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
3485 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3489 match m_narrow_patterns
with
3492 | head
:: _ -> "\xe2\x80\xa6" ^ head
3494 method narrow
pattern =
3495 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3499 let rec loop accu minfo n =
3502 m_items
<- Array.of_list
accu;
3503 m_minfo
<- Array.of_list
minfo;
3506 let (s, _, _) as o = m_items
.(n) in
3509 try Str.search_forward
re s 0
3510 with Not_found
-> -1
3513 then o :: accu, (first, Str.match_end
()) :: minfo
3516 loop accu minfo (n-1)
3518 loop [] [] (Array.length m_items
- 1)
3520 method getminfo
= m_minfo
3524 match sourcetype
with
3525 | `bookmarks
-> Array.of_list state
.bookmarks
3526 | `outlines
-> state
.outlines
3527 | `history
-> genhistoutlines !Config.historder
3529 m_minfo
<- m_orig_minfo
;
3530 m_items
<- m_orig_items
3533 if sourcetype
= `bookmarks
3535 if m >= 0 && m < Array.length m_items
3537 m_hadremovals
<- true;
3538 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3539 let n = if n >= m then n+1 else n in
3544 method add_narrow_pattern
pattern =
3545 m_narrow_patterns
<- pattern :: m_narrow_patterns
3547 method del_narrow_pattern
=
3548 match m_narrow_patterns
with
3549 | _ :: rest
-> m_narrow_patterns
<- rest
3554 match m_narrow_patterns
with
3555 | pattern :: [] -> self#narrow
pattern; pattern
3557 List.fold_left
(fun accu pattern ->
3558 self#narrow
pattern;
3559 pattern ^
"\xe2\x80\xa6" ^
accu) E.s list
3561 method calcactive
anchor =
3562 let rely = getanchory anchor in
3563 let rec loop n best bestd
=
3564 if n = Array.length m_items
3567 let _, _, kind
= m_items
.(n) in
3570 let orely = getanchory anchor in
3571 let d = abs
(orely - rely) in
3574 else loop (n+1) best bestd
3575 | Onone
| Oremote
_ | Olaunch
_
3576 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
3577 loop (n+1) best bestd
3581 method reset
anchor items =
3582 m_hadremovals
<- false;
3583 if state
.gen
!= m_gen
3585 m_orig_items
<- items;
3587 m_narrow_patterns
<- [];
3589 m_orig_minfo
<- empty;
3593 if items != m_orig_items
3595 m_orig_items
<- items;
3596 if m_narrow_patterns
== []
3597 then m_items
<- items;
3600 let active = self#calcactive
anchor in
3602 m_first
<- firstof m_first
active
3606 let enterselector sourcetype
=
3608 let source = outlinesource sourcetype
in
3611 match sourcetype
with
3612 | `bookmarks
-> Array.of_list state
.bookmarks
3613 | `
outlines -> state
.outlines
3614 | `history
-> genhistoutlines !Config.historder
3616 if Array.length
outlines = 0
3618 showtext ' ' errmsg
;
3621 state
.text <- source#greetmsg
;
3622 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3623 let anchor = getanchor
() in
3624 source#reset
anchor outlines;
3626 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
3627 G.postRedisplay "enter selector";
3631 let enteroutlinemode =
3632 let f = enterselector `
outlines in
3633 fun () -> f "Document has no outline";
3636 let enterbookmarkmode =
3637 let f = enterselector `bookmarks
in
3638 fun () -> f "Document has no bookmarks (yet)";
3641 let enterhistmode () = enterselector `history
"No history (yet)";;
3643 let makecheckers () =
3644 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3646 converted by Issac Trotts. July 25, 2002 *)
3647 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3648 Raw.sets_string
(GlPix.to_raw
image) ~
pos:0 "\255\200\200\255";
3649 let id = GlTex.gen_texture
() in
3650 GlTex.bind_texture `texture_2d
id;
3651 GlPix.store
(`unpack_alignment
1);
3652 GlTex.image2d
image;
3653 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3654 [ `mag_filter `nearest
; `min_filter `nearest
];
3658 let setcheckers enabled
=
3659 match state
.checkerstexid
with
3661 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3663 | Some checkerstexid
->
3666 GlTex.delete_texture checkerstexid
;
3667 state
.checkerstexid
<- None
;
3671 let describe_location () =
3672 let fn = page_of_y state
.y in
3673 let ln = page_of_y
(state
.y + state
.winh
- hscrollh () - 1) in
3674 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
3678 else (100. *. (float state
.y /. float maxy))
3682 Printf.sprintf
"page %d of %d [%.2f%%]"
3683 (fn+1) state
.pagecount
percent
3686 "pages %d-%d of %d [%.2f%%]"
3687 (fn+1) (ln+1) state
.pagecount
percent
3690 let setpresentationmode v
=
3691 let n = page_of_y state
.y in
3692 state
.anchor <- (n, 0.0, 1.0);
3693 conf
.presentation
<- v
;
3694 if conf
.fitmodel
= FitPage
3695 then reqlayout conf
.angle conf
.fitmodel
;
3700 let btos b = if b then "\xe2\x88\x9a" else E.s in
3701 let showextended = ref false in
3702 let leave mode
= function
3703 | Confirm
-> state
.mode
<- mode
3704 | Cancel
-> state
.mode
<- mode
in
3707 val mutable m_first_time
= true
3708 val mutable m_l
= []
3709 val mutable m_a
= E.a
3710 val mutable m_prev_uioh
= nouioh
3711 val mutable m_prev_mode
= View
3713 inherit lvsourcebase
3715 method reset prev_mode prev_uioh
=
3716 m_a
<- Array.of_list
(List.rev m_l
);
3718 m_prev_mode
<- prev_mode
;
3719 m_prev_uioh
<- prev_uioh
;
3723 if n >= Array.length m_a
3727 | _, _, _, Action
_ -> m_active
<- n
3731 m_first_time
<- false;
3734 method int name get
set =
3736 (name
, `
int get
, 1, Action
(
3739 try set (int_of_string
s)
3741 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3745 let te = name ^
": ", E.s, None
, intentry, ondone, true in
3746 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3750 method int_with_suffix name get
set =
3752 (name
, `intws get
, 1, Action
(
3755 try set (int_of_string_with_suffix
s)
3757 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3762 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
3764 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3768 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3770 (name
, `
bool (btos, get
), offset
, Action
(
3777 method color name get
set =
3779 (name
, `color get
, 1, Action
(
3781 let invalid = (nan
, nan
, nan
) in
3784 try color_of_string
s
3786 state
.text <- Printf.sprintf
"bad color `%s': %s"
3793 let te = name ^
": ", E.s, None
, textentry, ondone, true in
3794 state
.text <- color_to_string
(get
());
3795 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3799 method string name get
set =
3801 (name
, `
string get
, 1, Action
(
3803 let ondone s = set s in
3804 let te = name ^
": ", E.s, None
, textentry, ondone, true in
3805 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3809 method colorspace name get
set =
3811 (name
, `
string get
, 1, Action
(
3815 inherit lvsourcebase
3818 m_active
<- CSTE.to_int conf
.colorspace
;
3821 method getitemcount
=
3822 Array.length
CSTE.names
3825 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3826 ignore
(uioh
, first, pan
);
3827 if not cancel
then set active;
3829 method hasaction
_ = true
3833 let modehash = findkeyhash conf
"info" in
3834 coe (new listview ~zebra
:false ~helpmode
:false
3835 ~
source ~trusted
:true ~
modehash)
3838 method paxmark name get
set =
3840 (name
, `
string get
, 1, Action
(
3844 inherit lvsourcebase
3847 m_active
<- MTE.to_int conf
.paxmark
;
3850 method getitemcount
= Array.length
MTE.names
3851 method getitem
n = (MTE.names
.(n), 0)
3852 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3853 ignore
(uioh
, first, pan
);
3854 if not cancel
then set active;
3856 method hasaction
_ = true
3860 let modehash = findkeyhash conf
"info" in
3861 coe (new listview ~zebra
:false ~helpmode
:false
3862 ~
source ~trusted
:true ~
modehash)
3865 method fitmodel name get
set =
3867 (name
, `
string get
, 1, Action
(
3871 inherit lvsourcebase
3874 m_active
<- FMTE.to_int conf
.fitmodel
;
3877 method getitemcount
= Array.length
FMTE.names
3878 method getitem
n = (FMTE.names
.(n), 0)
3879 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3880 ignore
(uioh
, first, pan
);
3881 if not cancel
then set active;
3883 method hasaction
_ = true
3887 let modehash = findkeyhash conf
"info" in
3888 coe (new listview ~zebra
:false ~helpmode
:false
3889 ~
source ~trusted
:true ~
modehash)
3892 method caption
s offset
=
3893 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3895 method caption2
s f offset
=
3896 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3898 method getitemcount
= Array.length m_a
3901 let tostr = function
3902 | `
int f -> string_of_int
(f ())
3903 | `intws
f -> string_with_suffix_of_int
(f ())
3905 | `color
f -> color_to_string
(f ())
3906 | `
bool (btos, f) -> btos (f ())
3909 let name, t
, offset
, _ = m_a
.(n) in
3910 ((let s = tostr t
in
3912 then Printf.sprintf
"%s\t%s" name s
3916 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3921 match m_a
.(active) with
3922 | _, _, _, Action
f -> f uioh
3934 method hasaction
n =
3936 | _, _, _, Action
_ -> true
3940 let rec fillsrc prevmode prevuioh
=
3941 let sep () = src#caption
E.s 0 in
3942 let colorp name get
set =
3944 (fun () -> color_to_string
(get
()))
3947 let c = color_of_string
v in
3950 state
.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
3953 let oldmode = state
.mode
in
3954 let birdseye = isbirdseye state
.mode
in
3956 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3958 src#
bool "presentation mode"
3959 (fun () -> conf
.presentation
)
3960 (fun v -> setpresentationmode v);
3962 src#
bool "ignore case in searches"
3963 (fun () -> conf
.icase
)
3964 (fun v -> conf
.icase
<- v);
3967 (fun () -> conf
.preload)
3968 (fun v -> conf
.preload <- v);
3970 src#
bool "highlight links"
3971 (fun () -> conf
.hlinks
)
3972 (fun v -> conf
.hlinks
<- v);
3974 src#
bool "under info"
3975 (fun () -> conf
.underinfo
)
3976 (fun v -> conf
.underinfo
<- v);
3978 src#
bool "persistent bookmarks"
3979 (fun () -> conf
.savebmarks
)
3980 (fun v -> conf
.savebmarks
<- v);
3982 src#fitmodel
"fit model"
3983 (fun () -> FMTE.to_string conf
.fitmodel
)
3984 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3986 src#
bool "trim margins"
3987 (fun () -> conf
.trimmargins
)
3988 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3990 src#
bool "persistent location"
3991 (fun () -> conf
.jumpback
)
3992 (fun v -> conf
.jumpback
<- v);
3995 src#
int "inter-page space"
3996 (fun () -> conf
.interpagespace
)
3998 conf
.interpagespace
<- n;
3999 docolumns conf
.columns
;
4001 match state
.layout with
4006 state
.maxy <- calcheight
();
4007 let y = getpagey
pageno in
4012 (fun () -> conf
.pagebias
)
4013 (fun v -> conf
.pagebias
<- v);
4015 src#
int "scroll step"
4016 (fun () -> conf
.scrollstep
)
4017 (fun n -> conf
.scrollstep
<- n);
4019 src#
int "horizontal scroll step"
4020 (fun () -> conf
.hscrollstep
)
4021 (fun v -> conf
.hscrollstep
<- v);
4023 src#
int "auto scroll step"
4025 match state
.autoscroll
with
4027 | _ -> conf
.autoscrollstep
)
4029 let n = boundastep state
.winh
n in
4030 if state
.autoscroll
<> None
4031 then state
.autoscroll
<- Some
n;
4032 conf
.autoscrollstep
<- n);
4035 (fun () -> truncate
(conf
.zoom *. 100.))
4036 (fun v -> setzoom ((float v) /. 100.));
4039 (fun () -> conf
.angle
)
4040 (fun v -> reqlayout v conf
.fitmodel
);
4042 src#
int "scroll bar width"
4043 (fun () -> conf
.scrollbw
)
4046 reshape state
.winw state
.winh
;
4049 src#
int "scroll handle height"
4050 (fun () -> conf
.scrollh
)
4051 (fun v -> conf
.scrollh
<- v;);
4053 src#
int "thumbnail width"
4054 (fun () -> conf
.thumbw
)
4056 conf
.thumbw
<- min
4096 v;
4059 leavebirdseye beye
false;
4064 let mode = state
.mode in
4065 src#
string "columns"
4067 match conf
.columns
with
4069 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4070 | Csplit
(count
, _) -> "-" ^ string_of_int count
4073 let n, a, b = multicolumns_of_string
v in
4074 setcolumns mode n a b);
4077 src#caption
"Pixmap cache" 0;
4078 src#int_with_suffix
"size (advisory)"
4079 (fun () -> conf
.memlimit
)
4080 (fun v -> conf
.memlimit
<- v);
4083 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4084 (string_with_suffix_of_int state
.memused
)
4085 (Hashtbl.length state
.tilemap
)) 1;
4088 src#caption
"Layout" 0;
4089 src#caption2
"Dimension"
4091 Printf.sprintf
"%dx%d (virtual %dx%d)"
4092 state
.winw state
.winh
4097 src#caption2
"Position" (fun () ->
4098 Printf.sprintf
"%dx%d" state
.x state
.y
4101 src#caption2
"Position" (fun () -> describe_location ()) 1
4105 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4106 "Save these parameters as global defaults at exit"
4107 (fun () -> conf
.bedefault
)
4108 (fun v -> conf
.bedefault
<- v)
4112 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4113 src#
bool ~offset
:0 ~
btos "Extended parameters"
4114 (fun () -> !showextended)
4115 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4119 (fun () -> conf
.checkers
)
4120 (fun v -> conf
.checkers
<- v; setcheckers v);
4121 src#
bool "update cursor"
4122 (fun () -> conf
.updatecurs
)
4123 (fun v -> conf
.updatecurs
<- v);
4124 src#
bool "scroll-bar on the left"
4125 (fun () -> conf
.leftscroll
)
4126 (fun v -> conf
.leftscroll
<- v);
4128 (fun () -> conf
.verbose
)
4129 (fun v -> conf
.verbose
<- v);
4130 src#
bool "invert colors"
4131 (fun () -> conf
.invert
)
4132 (fun v -> conf
.invert
<- v);
4134 (fun () -> conf
.maxhfit
)
4135 (fun v -> conf
.maxhfit
<- v);
4136 src#
bool "redirect stderr"
4137 (fun () -> conf
.redirectstderr)
4138 (fun v -> conf
.redirectstderr <- v; redirectstderr ());
4140 (fun () -> conf
.pax
!= None
)
4143 then conf
.pax
<- Some
(ref (now
(), 0, 0))
4144 else conf
.pax
<- None
);
4145 src#
string "uri launcher"
4146 (fun () -> conf
.urilauncher
)
4147 (fun v -> conf
.urilauncher
<- v);
4148 src#
string "path launcher"
4149 (fun () -> conf
.pathlauncher
)
4150 (fun v -> conf
.pathlauncher
<- v);
4151 src#
string "tile size"
4152 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
4155 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4156 conf
.tilew
<- max
64 w;
4157 conf
.tileh
<- max
64 h;
4160 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
4163 src#
int "texture count"
4164 (fun () -> conf
.texcount
)
4167 then conf
.texcount
<- v
4168 else showtext '
!'
" Failed to set texture count please retry later"
4170 src#
int "slice height"
4171 (fun () -> conf
.sliceheight
)
4173 conf
.sliceheight
<- v;
4174 wcmd "sliceh %d" conf
.sliceheight
;
4176 src#
int "anti-aliasing level"
4177 (fun () -> conf
.aalevel
)
4179 conf
.aalevel
<- bound
v 0 8;
4180 state
.anchor <- getanchor
();
4181 opendoc state
.path state
.password
;
4183 src#
string "page scroll scaling factor"
4184 (fun () -> string_of_float conf
.pgscale)
4187 let s = float_of_string
v in
4190 state
.text <- Printf.sprintf
4191 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4194 src#
int "ui font size"
4195 (fun () -> fstate
.fontsize
)
4196 (fun v -> setfontsize (bound
v 5 100));
4197 src#
int "hint font size"
4198 (fun () -> conf
.hfsize
)
4199 (fun v -> conf
.hfsize
<- bound
v 5 100);
4200 colorp "background color"
4201 (fun () -> conf
.bgcolor
)
4202 (fun v -> conf
.bgcolor
<- v);
4203 src#
bool "crop hack"
4204 (fun () -> conf
.crophack
)
4205 (fun v -> conf
.crophack
<- v);
4206 src#
string "trim fuzz"
4207 (fun () -> irect_to_string conf
.trimfuzz
)
4210 conf
.trimfuzz
<- irect_of_string
v;
4212 then settrim true conf
.trimfuzz
;
4214 state
.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4216 src#
string "throttle"
4218 match conf
.maxwait
with
4219 | None
-> "show place holder if page is not ready"
4222 then "wait for page to fully render"
4224 "wait " ^ string_of_float
time
4225 ^
" seconds before showing placeholder"
4229 let f = float_of_string
v in
4231 then conf
.maxwait
<- None
4232 else conf
.maxwait
<- Some
f
4234 state
.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4236 src#
string "ghyll scroll"
4238 match conf
.ghyllscroll
with
4240 | Some nab
-> ghyllscroll_to_string nab
4243 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
4245 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4247 src#
string "selection command"
4248 (fun () -> conf
.selcmd
)
4249 (fun v -> conf
.selcmd
<- v);
4250 src#
string "synctex command"
4251 (fun () -> conf
.stcmd
)
4252 (fun v -> conf
.stcmd
<- v);
4253 src#
string "pax command"
4254 (fun () -> conf
.paxcmd
)
4255 (fun v -> conf
.paxcmd
<- v);
4256 src#colorspace
"color space"
4257 (fun () -> CSTE.to_string conf
.colorspace
)
4259 conf
.colorspace
<- CSTE.of_int
v;
4263 src#paxmark
"pax mark method"
4264 (fun () -> MTE.to_string conf
.paxmark
)
4265 (fun v -> conf
.paxmark
<- MTE.of_int
v);
4269 (fun () -> conf
.usepbo
)
4270 (fun v -> conf
.usepbo
<- v);
4271 src#
bool "mouse wheel scrolls pages"
4272 (fun () -> conf
.wheelbypage
)
4273 (fun v -> conf
.wheelbypage
<- v);
4274 src#
bool "open remote links in a new instance"
4275 (fun () -> conf
.riani
)
4276 (fun v -> conf
.riani
<- v);
4280 src#caption
"Document" 0;
4281 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
4282 src#caption2
"Pages"
4283 (fun () -> string_of_int state
.pagecount
) 1;
4284 src#caption2
"Dimensions"
4285 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4289 src#caption
"Trimmed margins" 0;
4290 src#caption2
"Dimensions"
4291 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4295 src#caption
"OpenGL" 0;
4296 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4297 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4300 src#caption
"Location" 0;
4301 if nonemptystr state
.origin
4302 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
4303 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
4305 src#reset prevmode prevuioh
;
4310 let prevmode = state
.mode
4311 and prevuioh
= state
.uioh in
4312 fillsrc prevmode prevuioh
;
4313 let source = (src :> lvsource
) in
4314 let modehash = findkeyhash conf
"info" in
4315 state
.uioh <- coe (object (self)
4316 inherit listview ~zebra
:false ~helpmode
:false
4317 ~
source ~trusted
:true ~
modehash as super
4318 val mutable m_prevmemused
= 0
4319 method infochanged
= function
4321 if m_prevmemused
!= state
.memused
4323 m_prevmemused
<- state
.memused
;
4324 G.postRedisplay "memusedchanged";
4326 | Pdim
-> G.postRedisplay "pdimchanged"
4327 | Docinfo
-> fillsrc prevmode prevuioh
4329 method key key mask
=
4330 if not
(Wsi.withctrl mask
)
4333 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4334 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4335 | _ -> super#
key key mask
4336 else super#
key key mask
4338 G.postRedisplay "info";
4344 inherit lvsourcebase
4345 method getitemcount
= Array.length state
.help
4347 let s, l, _ = state
.help
.(n) in
4350 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4354 match state
.help
.(active) with
4355 | _, _, Action
f -> Some
(f uioh)
4365 method hasaction
n =
4366 match state
.help
.(n) with
4367 | _, _, Action
_ -> true
4374 let modehash = findkeyhash conf
"help" in
4376 state
.uioh <- coe (new listview
4377 ~zebra
:false ~helpmode
:true
4378 ~
source ~trusted
:true ~
modehash);
4379 G.postRedisplay "help";
4384 let re = Str.regexp
"[\r\n]" in
4386 inherit lvsourcebase
4387 val mutable m_items
= E.a
4389 method getitemcount
= 1 + Array.length m_items
4394 else m_items
.(n-1), 0
4396 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4401 then Buffer.clear state
.errmsgs
;
4408 method hasaction
n =
4412 state
.newerrmsgs
<- false;
4413 let l = Str.split
re (Buffer.contents state
.errmsgs
) in
4414 m_items
<- Array.of_list
l
4423 let source = (msgsource :> lvsource
) in
4424 let modehash = findkeyhash conf
"listview" in
4425 state
.uioh <- coe (object
4426 inherit listview ~zebra
:false ~helpmode
:false
4427 ~
source ~trusted
:false ~
modehash as super
4430 then msgsource#reset
;
4433 G.postRedisplay "msgs";
4436 let quickbookmark ?title
() =
4437 match state
.layout with
4443 let tm = Unix.localtime
(now
()) in
4444 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4448 (tm.Unix.tm_year
+ 1900)
4451 | Some
title -> title
4453 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4456 let setautoscrollspeed step goingdown
=
4457 let incr = max
1 ((abs step
) / 2) in
4458 let incr = if goingdown
then incr else -incr in
4459 let astep = boundastep state
.winh
(step
+ incr) in
4460 state
.autoscroll
<- Some
astep;
4464 match conf
.columns
with
4466 | _ -> state
.x != 0 || conf
.zoom > 1.0
4469 let panbound x = bound
x (-state
.w) (wadjsb state
.winw
);;
4471 let existsinrow pageno (columns
, coverA
, coverB
) p =
4472 let last = ((pageno - coverA
) mod columns
) + columns
in
4473 let rec any = function
4476 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4480 then (if l.pageno = last then false else any rest
)
4488 match state
.layout with
4490 let pageno = page_of_y state
.y in
4491 gotoghyll (getpagey
(pageno+1))
4493 match conf
.columns
with
4495 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4497 let y = clamp (pgscale state
.winh
) in
4500 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4501 gotoghyll (getpagey
pageno)
4502 | Cmulti
((c, _, _) as cl, _) ->
4503 if conf
.presentation
4504 && (existsinrow l.pageno cl
4505 (fun l -> l.pageh
> l.pagey + l.pagevh))
4507 let y = clamp (pgscale state
.winh
) in
4510 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4511 gotoghyll (getpagey
pageno)
4513 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4515 let pagey, pageh
= getpageyh
l.pageno in
4516 let pagey = pagey + pageh
* l.pagecol
in
4517 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4518 gotoghyll (pagey + pageh
+ ips)
4522 match state
.layout with
4524 let pageno = page_of_y state
.y in
4525 gotoghyll (getpagey
(pageno-1))
4527 match conf
.columns
with
4529 if conf
.presentation
&& l.pagey != 0
4531 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4533 let pageno = max
0 (l.pageno-1) in
4534 gotoghyll (getpagey
pageno)
4535 | Cmulti
((c, _, coverB
) as cl, _) ->
4536 if conf
.presentation
&&
4537 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4539 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4542 if l.pageno = state
.pagecount
- coverB
4546 let pageno = max
0 (l.pageno-decr) in
4547 gotoghyll (getpagey
pageno)
4555 let pageno = max
0 (l.pageno-1) in
4556 let pagey, pageh
= getpageyh
pageno in
4559 let pagey, pageh
= getpageyh
l.pageno in
4560 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4565 let viewkeyboard key mask
=
4567 let mode = state
.mode in
4568 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4571 G.postRedisplay "view:enttext"
4573 let ctrl = Wsi.withctrl mask
in
4575 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4581 | 0xff63 -> (* insert *)
4582 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4584 state
.mode <- LinkNav
(Ltgendir
0);
4587 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4589 | 0xff1b | 113 -> (* escape / q *)
4590 begin match state
.mstate
with
4593 G.postRedisplay "kill zoom rect";
4595 begin match state
.mode with
4598 G.postRedisplay "esc leave linknav"
4600 match state
.ranchors
with
4602 | (path, password
, anchor, origin
) :: rest
->
4603 state
.ranchors
<- rest
;
4604 state
.anchor <- anchor;
4605 state
.origin
<- origin
;
4606 state
.nameddest
<- E.s;
4607 opendoc path password
4611 | 0xff08 -> (* backspace *)
4612 gotoghyll (getnav ~
-1)
4623 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
;
4624 G.postRedisplay "dehighlight";
4626 | 47 | 63 -> (* / ? *)
4627 let ondone isforw
s =
4628 cbput state
.hists
.pat
s;
4629 state
.searchpattern
<- s;
4632 let s = String.create
1 in
4633 s.[0] <- Char.chr
key;
4634 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4635 textentry, ondone (key = 47), true)
4637 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4638 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4639 setzoom (conf
.zoom +. incr)
4641 | 43 | 0xffab -> (* + *)
4644 try int_of_string
s with exc
->
4645 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4651 state
.text <- "page bias is now " ^ string_of_int
n;
4654 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
4656 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4657 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4658 setzoom (max
0.01 (conf
.zoom -. decr))
4660 | 45 | 0xffad -> (* - *)
4661 let ondone msg
= state
.text <- msg
in
4663 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4664 optentry state
.mode, ondone, true
4667 | 48 when ctrl -> (* ctrl-0 *)
4675 | (49 | 50) when ctrl && conf
.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
4677 match conf
.columns
with
4678 | Csingle
_ | Cmulti
_ -> 1
4679 | Csplit
(n, _) -> n
4681 let h = state
.winh
-
4682 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4684 let zoom = zoomforh state
.winw
h (vscrollw ()) cols in
4685 if zoom > 0.0 && (key = 50 || zoom < 1.0)
4688 | 51 when ctrl -> (* ctrl-3 *)
4690 match conf
.fitmodel
with
4691 | FitWidth
-> FitProportional
4692 | FitProportional
-> FitPage
4693 | FitPage
-> FitWidth
4695 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4696 reqlayout conf
.angle
fm
4698 | 0xffc6 -> (* f9 *)
4701 | 57 when ctrl -> (* ctrl-9 *)
4704 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4705 when not
ctrl -> (* 0..9 *)
4708 try int_of_string
s with exc
->
4709 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4715 cbput state
.hists
.pag
(string_of_int
n);
4716 gotopage1 (n + conf
.pagebias
- 1) 0;
4719 let pageentry text key =
4720 match Char.unsafe_chr
key with
4721 | '
g'
-> TEdone
text
4722 | _ -> intentry text key
4724 let text = "x" in text.[0] <- Char.chr
key;
4725 enttext (":", text, Some
(onhist state
.hists
.pag
), pageentry, ondone, true)
4728 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4729 reshape state
.winw state
.winh
;
4732 state
.bzoom
<- not state
.bzoom
;
4734 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4737 conf
.hlinks
<- not conf
.hlinks
;
4738 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4739 G.postRedisplay "toggle highlightlinks";
4742 state
.glinks
<- true;
4743 let mode = state
.mode in
4744 state
.mode <- Textentry
(
4745 (":", E.s, None
, linknentry, linkndone gotounder, false),
4747 state
.glinks
<- false;
4751 G.postRedisplay "view:linkent(F)"
4754 state
.glinks
<- true;
4755 let mode = state
.mode in
4756 state
.mode <- Textentry
(
4758 ":", E.s, None
, linknentry, linkndone (fun under ->
4759 selstring (undertext under);
4763 state
.glinks
<- false;
4767 G.postRedisplay "view:linkent"
4770 begin match state
.autoscroll
with
4772 conf
.autoscrollstep
<- step
;
4773 state
.autoscroll
<- None
4775 if conf
.autoscrollstep
= 0
4776 then state
.autoscroll
<- Some
1
4777 else state
.autoscroll
<- Some conf
.autoscrollstep
4780 | 112 when ctrl -> (* ctrl-p *)
4784 setpresentationmode (not conf
.presentation
);
4785 showtext ' '
("presentation mode " ^
4786 if conf
.presentation
then "on" else "off");
4789 if List.mem
Wsi.Fullscreen state
.winstate
4790 then Wsi.reshape conf
.cwinw conf
.cwinh
4791 else Wsi.fullscreen
()
4793 | 112 | 78 -> (* p|N *)
4794 search state
.searchpattern
false
4796 | 110 | 0xffc0 -> (* n|F3 *)
4797 search state
.searchpattern
true
4800 begin match state
.layout with
4803 gotoghyll (getpagey
l.pageno)
4809 | 0xff9f | 0xffff -> (* delete *)
4813 showtext ' '
(describe_location ());
4816 begin match state
.layout with
4819 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
4824 enterbookmarkmode ()
4826 | 104 | 0xffbe -> (* h|F1 *)
4832 | 101 when Buffer.length state
.errmsgs
> 0 -> (* e *)
4837 match state
.layout with
4842 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4845 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
4849 showtext ' '
"Quick bookmark added";
4852 begin match state
.layout with
4854 let rect = getpdimrect
l.pagedimno
in
4858 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4859 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4861 (truncate
(rect.(1) -. rect.(0)),
4862 truncate
(rect.(3) -. rect.(0)))
4864 let w = truncate
((float w)*.conf
.zoom)
4865 and h = truncate
((float h)*.conf
.zoom) in
4868 state
.anchor <- getanchor
();
4869 Wsi.reshape (w + vscrollw ()) (h + conf
.interpagespace
)
4871 G.postRedisplay "z";
4878 | 60 | 62 -> (* < > *)
4879 reqlayout (conf
.angle
+ (if key = 62 then 30 else -30)) conf
.fitmodel
4881 | 91 | 93 -> (* [ ] *)
4883 bound
(conf
.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4885 G.postRedisplay "brightness";
4887 | 99 when state
.mode = View
-> (* [alt-]c *)
4892 let m = (wadjsb state
.winw
- state
.w) / 2 in
4894 gotoy_and_clear_text state
.y
4898 match state
.prevcolumns
with
4899 | None
-> (1, 0, 0), 1.0
4900 | Some
(columns
, z
) ->
4903 | Csplit
(c, _) -> -c, 0, 0
4904 | Cmulti
((c, a, b), _) -> c, a, b
4905 | Csingle
_ -> 1, 0, 0
4909 setcolumns View
c a b;
4912 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
4913 -> (* ctrl-shift- (kp) [up|down] *)
4914 let zoom, x = state
.prevzoom
in
4918 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
4919 begin match state
.autoscroll
with
4921 begin match state
.mode with
4922 | Birdseye beye
-> upbirdseye 1 beye
4925 then gotoy_and_clear_text (clamp ~
-(state
.winh
/2))
4927 if not
(Wsi.withshift mask
) && conf
.presentation
4929 else gotoghyll1 true (clamp (-conf
.scrollstep
))
4933 setautoscrollspeed n false
4936 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
4937 begin match state
.autoscroll
with
4939 begin match state
.mode with
4940 | Birdseye beye
-> downbirdseye 1 beye
4943 then gotoy_and_clear_text (clamp (state
.winh
/2))
4945 if not
(Wsi.withshift mask
) && conf
.presentation
4947 else gotoghyll1 true (clamp (conf
.scrollstep
))
4951 setautoscrollspeed n true
4954 | 0xff51 | 0xff53 | 0xff96 | 0xff98
4955 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
4961 else conf
.hscrollstep
4963 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
4964 state
.x <- panbound (state
.x + dx);
4965 gotoy_and_clear_text state
.y
4968 G.postRedisplay "left/right"
4971 | 0xff55 | 0xff9a -> (* (kp) prior *)
4975 match state
.layout with
4977 | l :: _ -> state
.y - l.pagey
4979 clamp (pgscale (-state
.winh
))
4983 | 0xff56 | 0xff9b -> (* (kp) next *)
4987 match List.rev state
.layout with
4989 | l :: _ -> getpagey
l.pageno
4991 clamp (pgscale state
.winh
)
4995 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
4997 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
4998 gotoghyll (clamp state
.maxy)
5001 when Wsi.withalt mask
-> (* alt-(kp) right *)
5002 gotoghyll (getnav 1)
5004 when Wsi.withalt mask
-> (* alt-(kp) left *)
5005 gotoghyll (getnav ~
-1)
5010 | 118 when conf
.debug
-> (* v *)
5013 match getopaque l.pageno with
5016 let x0, y0, x1, y1 = pagebbox
opaque in
5017 let a,b = float x0, float y0 in
5018 let c,d = float x1, float y0 in
5019 let e,f = float x1, float y1 in
5020 let h,j
= float x0, float y1 in
5021 let rect = (a,b,c,d,e,f,h,j
) in
5023 state
.rects
<- (l.pageno, l.pageno mod 3, rect) :: state
.rects
;
5025 G.postRedisplay "v";
5028 let mode = state
.mode in
5029 let cmd = ref E.s in
5030 let onleave = function
5031 | Cancel
-> state
.mode <- mode
5034 match getopaque l.pageno with
5035 | Some
opaque -> pipesel opaque !cmd
5036 | None
-> ()) state
.layout;
5040 cbput state
.hists
.sel
s;
5044 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
5046 G.postRedisplay "|";
5047 state
.mode <- Textentry
(te, onleave);
5050 vlog "huh? %s" (Wsi.keyname
key)
5053 let linknavkeyboard key mask
linknav =
5054 let getpage pageno =
5055 let rec loop = function
5057 | l :: _ when l.pageno = pageno -> Some
l
5058 | _ :: rest
-> loop rest
5059 in loop state
.layout
5061 let doexact (pageno, n) =
5062 match getopaque pageno, getpage pageno with
5063 | Some
opaque, Some
l ->
5064 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5066 let under = getlink
opaque n in
5067 G.postRedisplay "link gotounder";
5073 | 0xff50 -> (* home *)
5074 Some
(findlink
opaque LDfirst
), -1
5076 | 0xff57 -> (* end *)
5077 Some
(findlink
opaque LDlast
), 1
5079 | 0xff51 -> (* left *)
5080 Some
(findlink
opaque (LDleft
n)), -1
5082 | 0xff53 -> (* right *)
5083 Some
(findlink
opaque (LDright
n)), 1
5085 | 0xff52 -> (* up *)
5086 Some
(findlink
opaque (LDup
n)), -1
5088 | 0xff54 -> (* down *)
5089 Some
(findlink
opaque (LDdown
n)), 1
5094 begin match findpwl
l.pageno dir with
5098 state
.mode <- LinkNav
(Ltgendir
dir);
5099 let y, h = getpageyh
pageno in
5102 then y + h - state
.winh
5107 begin match getopaque pageno, getpage pageno with
5108 | Some
opaque, Some
_ ->
5110 let ld = if dir > 0 then LDfirst
else LDlast
in
5113 begin match link with
5115 showlinktype (getlink
opaque m);
5116 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5117 G.postRedisplay "linknav jpage";
5124 begin match opt with
5125 | Some Lnotfound
-> pwl l dir;
5126 | Some
(Lfound
m) ->
5130 let _, y0, _, y1 = getlinkrect
opaque m in
5132 then gotopage1 l.pageno y0
5134 let d = fstate
.fontsize
+ 1 in
5135 if y1 - l.pagey > l.pagevh - d
5136 then gotopage1 l.pageno (y1 - state
.winh
- hscrollh () + d)
5137 else G.postRedisplay "linknav";
5139 showlinktype (getlink
opaque m);
5140 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5143 | None
-> viewkeyboard key mask
5145 | _ -> viewkeyboard key mask
5150 G.postRedisplay "leave linknav"
5154 | Ltgendir
_ -> viewkeyboard key mask
5155 | Ltexact exact
-> doexact exact
5158 let keyboard key mask
=
5159 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state
.mode)
5160 then wcmd "interrupt"
5161 else state
.uioh <- state
.uioh#
key key mask
5164 let birdseyekeyboard key mask
5165 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5167 match conf
.columns
with
5169 | Cmulti
((c, _, _), _) -> c
5170 | Csplit
_ -> failwith
"bird's eye split mode"
5172 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state
.winh
layout in
5174 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5175 let y, h = getpageyh
pageno in
5176 let top = (state
.winh
- h) / 2 in
5177 gotoy (max
0 (y - top))
5178 | 0xff0d (* enter *)
5179 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5180 | 0xff1b -> leavebirdseye beye
true (* escape *)
5181 | 0xff52 -> upbirdseye incr beye
(* up *)
5182 | 0xff54 -> downbirdseye incr beye
(* down *)
5183 | 0xff51 -> upbirdseye 1 beye
(* left *)
5184 | 0xff53 -> downbirdseye 1 beye
(* right *)
5186 | 0xff55 -> (* prior *)
5187 begin match state
.layout with
5191 state
.mode <- Birdseye
(
5192 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5194 gotopage1 l.pageno 0;
5197 let layout = layout (state
.y-state
.winh
) (pgh state
.layout) in
5199 | [] -> gotoy (clamp (-state
.winh
))
5201 state
.mode <- Birdseye
(
5202 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5204 gotopage1 l.pageno 0
5207 | [] -> gotoy (clamp (-state
.winh
))
5210 | 0xff56 -> (* next *)
5211 begin match List.rev state
.layout with
5213 let layout = layout (state
.y + (pgh state
.layout)) state
.winh
in
5214 begin match layout with
5216 let incr = l.pageh
- l.pagevh in
5221 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5223 G.postRedisplay "birdseye pagedown";
5225 else gotoy (clamp (incr + conf
.interpagespace
*2));
5229 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5230 gotopage1 l.pageno 0;
5233 | [] -> gotoy (clamp state
.winh
)
5236 | 0xff50 -> (* home *)
5237 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5240 | 0xff57 -> (* end *)
5241 let pageno = state
.pagecount
- 1 in
5242 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5243 if not
(pagevisible state
.layout pageno)
5246 match List.rev state
.pdims
with
5248 | (_, _, h, _) :: _ -> h
5250 gotoy (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5251 else G.postRedisplay "birdseye end";
5252 | _ -> viewkeyboard key mask
5257 match state
.mode with
5258 | Textentry
_ -> scalecolor 0.4
5260 | View
-> scalecolor 1.0
5261 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5262 if l.pageno = hooverpageno
5265 if l.pageno = pageno
5273 let postdrawpage l linkindexbase
=
5274 match getopaque l.pageno with
5276 if tileready l l.pagex
l.pagey
5278 let x = l.pagedispx - l.pagex
+ xadjsb 0
5279 and y = l.pagedispy - l.pagey in
5281 match conf
.columns
with
5282 | Csingle
_ | Cmulti
_ ->
5283 (if conf
.hlinks
then 1 else 0)
5285 && not
(isbirdseye state
.mode) then 2 else 0)
5289 match state
.mode with
5290 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5293 postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
);
5298 let scrollindicator () =
5299 let sbw, ph
, sh = state
.uioh#
scrollph in
5300 let sbh, pw, sw = state
.uioh#scrollpw
in
5305 else (state
.winw
- sbw), state
.winw
5308 GlDraw.color (0.64, 0.64, 0.64);
5309 filledrect (float x0) 0. (float x1) (float state
.winh
);
5311 0. (float (state
.winh
- sbh))
5312 (float (wadjsb state
.winw
- 1)) (float state
.winh
)
5314 GlDraw.color (0.0, 0.0, 0.0);
5316 filledrect (float x0) ph
(float x1) (ph
+. sh);
5317 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5321 match state
.mstate
with
5322 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5325 | Msel
((x0, y0), (x1, y1)) ->
5326 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5327 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5328 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5329 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5332 let showrects = function [] -> () | rects
->
5334 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5335 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5337 (fun (pageno, c, (x0, y0, x1, y1, x2, y2
, x3
, y3
)) ->
5339 if l.pageno = pageno
5341 let dx = float (l.pagedispx - l.pagex
) in
5342 let dy = float (l.pagedispy - l.pagey) in
5343 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5344 Raw.sets_float state
.vraw ~
pos:0
5349 GlArray.vertex `two state
.vraw
;
5350 GlArray.draw_arrays `triangle_strip
0 4;
5359 GlClear.color (scalecolor2 conf
.bgcolor
);
5360 GlClear.clear
[`
color];
5361 List.iter
drawpage state
.layout;
5363 match state
.mode with
5364 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5365 begin match getopaque pageno with
5367 let dx = xadjsb 0 in
5368 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5369 let x0 = x0 + dx and x1 = x1 + dx in
5376 | None
-> state
.rects
5381 let rec postloop linkindexbase
= function
5383 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5384 postloop linkindexbase rest
5388 postloop 0 state
.layout;
5390 begin match state
.mstate
with
5391 | Mzoomrect
((x0, y0), (x1, y1)) ->
5393 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5394 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5395 filledrect (float x0) (float y0) (float x1) (float y1);
5404 let zoomrect x y x1 y1 =
5407 and y0 = min
y y1 in
5408 gotoy (state
.y + y0);
5409 state
.anchor <- getanchor
();
5410 let zoom = (float state
.w) /. float (x1 - x0) in
5412 match conf
.fitmodel
, conf
.columns
with
5413 | FitPage
, Csplit
_ ->
5414 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5417 let adjw = wadjsb state
.winw
in
5419 then (adjw - state
.w) / 2
5422 state
.x <- (state
.x + margin) - x0;
5428 let g opaque l px py =
5429 match rectofblock
opaque px py with
5431 let x0 = a.(0) -. 20. in
5432 let x1 = a.(1) +. 20. in
5433 let y0 = a.(2) -. 20. in
5434 let zoom = (float state
.w) /. (x1 -. x0) in
5435 let pagey = getpagey
l.pageno in
5436 gotoy_and_clear_text (pagey + truncate
y0);
5437 state
.anchor <- getanchor
();
5438 let margin = (state
.w - l.pagew
)/2 in
5439 state
.x <- -truncate
x0 - margin;
5444 match conf
.columns
with
5446 showtext '
!'
"block zooming does not work properly in split columns mode"
5447 | _ -> onppundermouse g x y ()
5451 let winw = wadjsb state
.winw - 1 in
5452 let s = float x /. float winw in
5453 let destx = truncate
(float (state
.w + winw) *. s) in
5454 state
.x <- winw - destx;
5455 gotoy_and_clear_text state
.y;
5456 state
.mstate
<- Mscrollx
;
5460 let s = float y /. float state
.winh
in
5461 let desty = truncate
(float (state
.maxy - state
.winh
) *. s) in
5462 gotoy_and_clear_text desty;
5463 state
.mstate
<- Mscrolly
;
5466 let viewmulticlick clicks
x y mask
=
5467 let g opaque l px py =
5475 if markunder
opaque px py mark
5479 match getopaque l.pageno with
5481 | Some
opaque -> pipesel opaque cmd
5483 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5484 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5489 G.postRedisplay "viewmulticlick";
5490 onppundermouse g x y (fun () -> showtext '
!'
"Nothing to select") ();
5494 match conf
.columns
with
5496 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5499 let viewmouse button down
x y mask
=
5501 | n when (n == 4 || n == 5) && not down
->
5502 if Wsi.withctrl mask
5504 match state
.mstate
with
5505 | Mzoom
(oldn
, i
) ->
5513 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5515 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5517 let zoom = conf
.zoom -. incr in
5519 state
.mstate
<- Mzoom
(n, 0);
5521 state
.mstate
<- Mzoom
(n, i
+1);
5523 else state
.mstate
<- Mzoom
(n, 0)
5525 | _ -> state
.mstate
<- Mzoom
(n, 0)
5528 match state
.autoscroll
with
5529 | Some step
-> setautoscrollspeed step
(n=4)
5531 if conf
.wheelbypage
|| conf
.presentation
5540 then -conf
.scrollstep
5541 else conf
.scrollstep
5543 let incr = incr * 2 in
5544 let y = clamp incr in
5545 gotoy_and_clear_text y
5548 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5550 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
);
5551 gotoy_and_clear_text state
.y
5553 | 1 when Wsi.withshift mask
->
5554 state
.mstate
<- Mnone
;
5557 match unproject x y with
5558 | Some
(pageno, ux
, uy
) ->
5559 let cmd = Printf.sprintf
5561 conf
.stcmd state
.path pageno ux uy
5567 | 1 when Wsi.withctrl mask
->
5570 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5571 state
.mstate
<- Mpan
(x, y)
5574 state
.mstate
<- Mnone
5579 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5581 state
.mstate
<- Mzoomrect
(p, p)
5584 match state
.mstate
with
5585 | Mzoomrect
((x0, y0), _) ->
5586 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5587 then zoomrect x0 y0 x y
5590 G.postRedisplay "kill accidental zoom rect";
5596 | 1 when x > state
.winw - vscrollw () ->
5599 let _, position, sh = state
.uioh#
scrollph in
5600 if y > truncate
position && y < truncate
(position +. sh)
5601 then state
.mstate
<- Mscrolly
5604 state
.mstate
<- Mnone
5606 | 1 when y > state
.winh
- hscrollh () ->
5609 let _, position, sw = state
.uioh#scrollpw
in
5610 if x > truncate
position && x < truncate
(position +. sw)
5611 then state
.mstate
<- Mscrollx
5614 state
.mstate
<- Mnone
5616 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5619 let dest = if down
then getunder x y else Unone
in
5620 begin match dest with
5623 | Uremote
_ | Uremotedest
_
5624 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5627 | Unone
when down
->
5628 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5629 state
.mstate
<- Mpan
(x, y);
5631 | Unone
| Utext
_ ->
5636 state
.mstate
<- Msel
((x, y), (x, y));
5637 G.postRedisplay "mouse select";
5641 match state
.mstate
with
5644 | Mzoom
_ | Mscrollx
| Mscrolly
->
5645 state
.mstate
<- Mnone
5647 | Mzoomrect
((x0, y0), _) ->
5651 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5652 state
.mstate
<- Mnone
5654 | Msel
((x0, y0), (x1, y1)) ->
5655 let rec loop = function
5659 let a0 = l.pagedispy in
5660 let a1 = a0 + l.pagevh in
5661 let b0 = l.pagedispx in
5662 let b1 = b0 + l.pagevw in
5663 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5664 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5668 match getopaque l.pageno with
5671 match Ne.res Unix.pipe
with
5675 "can not create sel pipe: %s"
5679 Ne.clo fd
(fun msg
->
5680 dolog
"%s close failed: %s" what msg
)
5683 try popen
cmd [r, 0; w, -1]; true
5685 dolog
"can not execute %S: %s"
5692 G.postRedisplay "copysel";
5694 else clo "Msel pipe/w" w;
5695 clo "Msel pipe/r" r;
5697 dosel conf
.selcmd
();
5698 state
.roam
<- dosel conf
.paxcmd
;
5710 let birdseyemouse button down
x y mask
5711 (conf
, leftx
, _, hooverpageno
, anchor) =
5714 let rec loop = function
5717 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5718 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5720 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5726 | _ -> viewmouse button down
x y mask
5732 method key key mask
=
5733 begin match state
.mode with
5734 | Textentry
textentry -> textentrykeyboard key mask
textentry
5735 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5736 | View
-> viewkeyboard key mask
5737 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5741 method button button bstate
x y mask
=
5742 begin match state
.mode with
5744 | View
-> viewmouse button bstate
x y mask
5745 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5750 method multiclick clicks
x y mask
=
5751 begin match state
.mode with
5753 | View
-> viewmulticlick clicks
x y mask
5760 begin match state
.mode with
5762 | View
| Birdseye
_ | LinkNav
_ ->
5763 match state
.mstate
with
5764 | Mzoom
_ | Mnone
-> ()
5769 state
.mstate
<- Mpan
(x, y);
5771 then state
.x <- panbound (state
.x + dx);
5773 gotoy_and_clear_text y
5776 state
.mstate
<- Msel
(a, (x, y));
5777 G.postRedisplay "motion select";
5780 let y = min state
.winh
(max
0 y) in
5784 let x = min state
.winw (max
0 x) in
5787 | Mzoomrect
(p0
, _) ->
5788 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5789 G.postRedisplay "motion zoomrect";
5793 method pmotion
x y =
5794 begin match state
.mode with
5795 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
5796 let rec loop = function
5798 if hooverpageno
!= -1
5800 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
5801 G.postRedisplay "pmotion birdseye no hoover";
5804 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5805 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5807 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
5808 G.postRedisplay "pmotion birdseye hoover";
5818 match state
.mstate
with
5819 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5828 let past, _, _ = !r in
5830 let delta = now -. past in
5833 else r := (now, x, y)
5837 method infochanged
_ = ()
5840 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
5843 then 0.0, float state
.winh
5844 else scrollph state
.y maxy
5849 let winw = wadjsb state
.winw in
5850 let fwinw = float winw in
5852 let sw = fwinw /. float state
.w in
5853 let sw = fwinw *. sw in
5854 max
sw (float conf
.scrollh
)
5857 let maxx = state
.w + winw in
5858 let x = winw - state
.x in
5859 let percent = float x /. float maxx in
5860 (fwinw -. sw) *. percent
5862 hscrollh (), position, sw
5866 match state
.mode with
5867 | LinkNav
_ -> "links"
5868 | Textentry
_ -> "textentry"
5869 | Birdseye
_ -> "birdseye"
5872 findkeyhash conf
modename
5874 method eformsgs
= true
5877 let adderrmsg src msg
=
5878 Buffer.add_string state
.errmsgs msg
;
5879 state
.newerrmsgs
<- true;
5883 let adderrfmt src fmt
=
5884 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
5888 let cl = splitatspace cmds
in
5890 try Scanf.sscanf
s fmt
f
5892 adderrfmt "remote exec"
5893 "error processing '%S': %s\n" cmds
(exntos exn
)
5896 | "reload" :: [] -> reload ()
5897 | "goto" :: args
:: [] ->
5898 scan args
"%u %f %f"
5900 let cmd, _ = state
.geomcmds
in
5902 then gotopagexy pageno x y
5905 gotopagexy pageno x y;
5908 state
.reprf
<- f state
.reprf
5910 | "goto1" :: args
:: [] -> scan args
"%u %f" gotopage
5911 | "gotor" :: args
:: [] ->
5913 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
5914 | "gotord" :: args
:: [] ->
5916 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
5917 | "rect" :: args
:: [] ->
5918 scan args
"%u %u %f %f %f %f"
5919 (fun pageno color x0 y0 x1 y1 ->
5920 onpagerect pageno (fun w h ->
5921 let _,w1,h1
,_ = getpagedim
pageno in
5922 let sw = float w1 /. float w
5923 and sh = float h1
/. float h in
5927 and y1s
= y1 *. sh in
5928 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
5930 state
.rects <- (pageno, color, rect) :: state
.rects;
5931 G.postRedisplay "rect";
5934 | "activatewin" :: [] -> Wsi.activatewin
()
5935 | "quit" :: [] -> raise Quit
5937 adderrfmt "remote command"
5938 "error processing remote command: %S\n" cmds
;
5942 let scratch = String.create
80 in
5943 let buf = Buffer.create
80 in
5946 try Some
(Unix.read fd
scratch 0 80)
5948 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
5949 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
5952 match tempfr () with
5958 if Buffer.length
buf > 0
5960 let s = Buffer.contents
buf in
5970 let pos = String.index_from
scratch ppos '
\n'
in
5971 if pos >= n then -1 else pos
5972 with Not_found
-> -1
5976 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
5977 let s = Buffer.contents
buf in
5983 Buffer.add_substring
buf scratch ppos
(n-ppos
);
5989 let remoteopen path =
5990 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
5992 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
5997 let trimcachepath = ref E.s in
5998 let rcmdpath = ref E.s in
5999 let pageno = ref None
in
6000 selfexec := Sys.executable_name
;
6003 [("-p", Arg.String
(fun s -> state
.password
<- s),
6004 "<password> Set password");
6008 Config.fontpath
:= s;
6009 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6011 "<path> Set path to the user interface font");
6015 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6016 Config.confpath
:= s),
6017 "<path> Set path to the configuration file");
6019 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6020 "<page-number> Jump to page");
6022 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6023 "<path> Set path to the trim cache file");
6025 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6026 "<named-destination> Set named destination");
6028 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6029 ("-cxack", Arg.Set
cxack, " Cut corners");
6031 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6032 "<path> Set path to the remote commands source");
6034 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6035 "<original-path> Set original path");
6037 ("-v", Arg.Unit
(fun () ->
6039 "%s\nconfiguration path: %s\n"
6043 exit
0), " Print version and exit");
6046 (fun s -> state
.path <- s)
6047 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6050 then selfexec := !selfexec ^
" -wtmode";
6052 let histmode = emptystr state
.path in
6054 if not
(Config.load ())
6055 then prerr_endline
"failed to load configuration";
6056 begin match !pageno with
6057 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6061 let wsfd, winw, winh
= Wsi.init
(object (self)
6062 val mutable m_hack
= false
6063 val mutable m_clicks
= 0
6064 val mutable m_click_x
= 0
6065 val mutable m_click_y
= 0
6066 val mutable m_lastclicktime
= infinity
6068 method private cleanup
=
6069 state
.roam
<- noroam
;
6070 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
;
6071 method expose
= if not m_hack
then G.postRedisplay "expose"
6072 method visible
= G.postRedisplay "visible"
6073 method display = m_hack
<- false; display ()
6074 method reshape w h =
6076 m_hack
<- w < state
.winw && h < state
.winh
;
6078 method mouse
b d x y m =
6079 if d && canselect ()
6081 (* http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx *)
6087 if abs
x - m_click_x
> 10
6088 || abs
y - m_click_y
> 10
6089 || abs_float
(t -. m_lastclicktime
) > 0.3
6091 m_clicks
<- m_clicks
+ 1;
6092 m_lastclicktime
<- t;
6096 G.postRedisplay "cleanup";
6097 state
.uioh <- state
.uioh#button
b d x y m;
6099 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6104 m_lastclicktime
<- infinity
;
6105 state
.uioh <- state
.uioh#button
b d x y m
6109 state
.uioh <- state
.uioh#button
b d x y m
6112 state
.mpos
<- (x, y);
6113 state
.uioh <- state
.uioh#motion
x y
6114 method pmotion
x y =
6115 state
.mpos
<- (x, y);
6116 state
.uioh <- state
.uioh#pmotion
x y
6118 let mascm = m land (
6119 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6122 let x = state
.x and y = state
.y in
6124 if x != state
.x || y != state
.y then self#cleanup
6126 match state
.keystate
with
6128 let km = k
, mascm in
6131 let modehash = state
.uioh#
modehash in
6132 try Hashtbl.find modehash km
6134 try Hashtbl.find (findkeyhash conf
"global") km
6135 with Not_found
-> KMinsrt
(k
, m)
6137 | KMinsrt
(k
, m) -> keyboard k
m
6138 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6139 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6141 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6142 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6143 state
.keystate
<- KSnone
6144 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k
&& m'
land mascm = m'
->
6145 state
.keystate
<- KSinto
(keys
, insrt
)
6147 state
.keystate
<- KSnone
6150 state
.mpos
<- (x, y);
6151 state
.uioh <- state
.uioh#pmotion
x y
6152 method leave = state
.mpos
<- (-1, -1)
6153 method winstate wsl
= state
.winstate
<- wsl
; m_hack
<- false
6154 method quit
= raise Quit
6155 end) conf
.cwinw conf
.cwinh
(platform
= Posx
) in
6160 List.exists
GlMisc.check_extension
6161 [ "GL_ARB_texture_rectangle"
6162 ; "GL_EXT_texture_recangle"
6163 ; "GL_NV_texture_rectangle" ]
6165 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6168 let r = GlMisc.get_string `renderer
in
6169 let p = "Mesa DRI Intel(" in
6170 let l = String.length
p in
6171 String.length
r > l && String.sub
r 0 l = p
6174 defconf
.sliceheight
<- 1024;
6175 defconf
.texcount
<- 32;
6176 defconf
.usepbo
<- true;
6180 match Ne.res Unix.pipe
with
6182 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
6186 match Ne.res Unix.pipe
with
6188 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
6198 setcheckers conf
.checkers
;
6200 if conf
.redirectstderr
6203 let s = Buffer.contents state
.errmsgs ^
6204 (match state
.errfd
with
6206 let s = String.create
(80*24) in
6209 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
6211 then Unix.read fd
s 0 (String.length
s)
6217 else String.sub
s 0 n
6221 try ignore
(Unix.write state
.stderr
s 0 (String.length
s))
6222 with exn
-> print_endline
(exntos exn
)
6227 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6228 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6229 !Config.fontpath
, !trimcachepath,
6230 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
6232 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6242 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6243 opendoc state
.path state
.password
;
6248 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6251 if nonemptystr
!rcmdpath
6252 then remoteopen !rcmdpath
6257 let rec loop deadline
=
6259 match state
.errfd
with
6260 | None
-> [state
.sr
; state
.wsfd]
6261 | Some fd
-> [state
.sr
; state
.wsfd; fd
]
6266 | Some fd
-> fd
:: r
6270 state
.redisplay
<- false;
6277 if deadline
= infinity
6279 else max
0.0 (deadline
-. now)
6284 try Unix.select
r [] [] timeout
6285 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6291 if state
.ghyll
== noghyll
6293 match state
.autoscroll
with
6294 | Some step
when step
!= 0 ->
6295 let y = state
.y + step
in
6299 else if y >= state
.maxy then 0 else y
6302 if state
.mode = View
6303 then state
.text <- E.s;
6306 else deadline
+. 0.01
6311 let rec checkfds = function
6313 | fd
:: rest
when fd
= state
.sr
->
6314 let cmd = readcmd state
.sr
in
6318 | fd
:: rest
when fd
= state
.wsfd ->
6322 | fd
:: rest
when Some fd
= !optrfd ->
6323 begin match remote fd
with
6324 | None
-> optrfd := remoteopen !rcmdpath;
6325 | opt -> optrfd := opt
6330 let s = String.create
80 in
6331 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
6332 if conf
.redirectstderr
6334 Buffer.add_substring state
.errmsgs
s 0 n;
6335 state
.newerrmsgs
<- true;
6336 state
.redisplay
<- true;
6339 prerr_string
(String.sub
s 0 n);
6347 if deadline
= infinity
6351 match state
.autoscroll
with
6352 | Some step
when step
!= 0 -> deadline1
6353 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6361 Config.save
leavebirdseye;