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 "";;
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 ();;
104 fstate
.fontsize
<- n
;
105 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
106 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
112 Printf.kprintf prerr_endline fmt
114 Printf.kprintf ignore fmt
118 if emptystr conf
.pathlauncher
119 then print_endline state
.path
121 let re = Str.regexp
"%s" in
122 let command = Str.global_replace
re state
.path conf
.pathlauncher
in
125 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
131 type 'a t
= | Res
of 'a
| Exn
of exn
;;
139 try tempfailureretry
Unix.close fd
140 with exn
-> f
(exntos exn
)
144 try Res
(tempfailureretry
Unix.dup fd
)
149 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
154 let redirectstderr () =
155 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
156 if conf
.redirectstderr
158 match Ne.res Unix.pipe
with
160 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
163 begin match Ne.dup Unix.stderr
with
165 dolog
"failed to dup stderr: %s" (exntos exn
);
166 Ne.clo r
(clofail "pipe/r");
167 Ne.clo w
(clofail "pipe/w");
169 | Ne.Res dupstderr
->
170 begin match Ne.dup2 w
Unix.stderr
with
172 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
173 Ne.clo dupstderr
(clofail "stderr duplicate");
174 Ne.clo r
(clofail "redir pipe/r");
175 Ne.clo w
(clofail "redir pipe/w");
178 state
.stderr
<- dupstderr
;
179 state
.errfd
<- Some r
;
183 state
.newerrmsgs
<- false;
184 begin match state
.errfd
with
186 begin match Ne.dup2 state
.stderr
Unix.stderr
with
188 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
190 Ne.clo fd
(clofail "dup of stderr");
195 prerr_string
(Buffer.contents state
.errmsgs
);
197 Buffer.clear state
.errmsgs
;
203 let postRedisplay who
=
205 then prerr_endline
("redisplay for " ^ who
);
206 state
.redisplay
<- true;
210 let getopaque pageno
=
211 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
212 with Not_found
-> None
215 let putopaque pageno opaque
=
216 Hashtbl.replace state
.pagemap
(pageno
, state
.gen
) opaque
219 let pagetranslatepoint l x y
=
220 let dy = y
- l
.pagedispy
in
221 let y = dy + l
.pagey
in
222 let dx = x
- l
.pagedispx
in
223 let x = dx + l
.pagex
in
227 let onppundermouse g
x y d
=
230 begin match getopaque l
.pageno
with
232 let x0 = l
.pagedispx
in
233 let x1 = x0 + l
.pagevw
in
234 let y0 = l
.pagedispy
in
235 let y1 = y0 + l
.pagevh
in
236 if y >= y0 && y <= y1 && x >= x0 && x <= x1
238 let px, py
= pagetranslatepoint l
x y in
239 match g opaque l
px py
with
252 let g opaque l
px py
=
255 match rectofblock opaque
px py
with
257 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
258 state
.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
259 G.postRedisplay "getunder";
262 match whatsunder opaque
px py
with
264 | under
-> Some under
266 onppundermouse g x y Unone
271 match unproject opaque
x y with
272 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
275 onppundermouse g x y None
;
279 state
.text
<- Printf.sprintf
"%c%s" c s
;
280 G.postRedisplay "showtext";
283 let pipesel opaque cmd
=
286 match Ne.res Unix.pipe
with
289 (Printf.sprintf
"pipesel can not create pipe: %s" (exntos exn
));
291 let doclose what fd
=
292 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
295 try popen cmd
[r
, 0; w
, -1]; true
297 dolog
"can not execute %S: %s" cmd
(exntos exn
);
303 G.postRedisplay "pipesel";
305 else doclose "pipesel pipe/w" w
;
306 doclose "pipesel pipe/r" r
;
310 let g opaque l
px py
=
311 if markunder opaque
px py conf
.paxmark
314 match getopaque l
.pageno
with
316 | Some opaque
-> pipesel opaque conf
.paxcmd
321 G.postRedisplay "paxunder";
322 if conf
.paxmark
= Mark_page
325 match getopaque l
.pageno
with
327 | Some opaque
-> clearmark opaque
) state
.layout
;
329 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
333 match Ne.res Unix.pipe
with
335 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
338 Ne.clo fd
(fun msg
->
339 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
343 try popen conf
.selcmd
[r
, 0; w
, -1]; true
346 (Printf.sprintf
"failed to execute %s: %s"
347 conf
.selcmd
(exntos exn
));
353 let l = String.length s
in
354 let n = tempfailureretry
(Unix.write w s
0) l in
359 "failed to write %d characters to sel pipe, wrote %d"
364 (Printf.sprintf
"failed to write to sel pipe: %s"
369 clo "selstring pipe/r" r
;
370 clo "selstring pipe/w" w
;
373 let undertext = function
376 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state
.path
(pageno
+1)
377 | Utext s
-> "font: " ^ s
378 | Uunexpected s
-> "unexpected: " ^ s
379 | Ulaunch s
-> "launch: " ^ s
380 | Unamed s
-> "named: " ^ s
381 | Uremote
(filename
, pageno
) ->
382 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
383 | Uremotedest
(filename
, destname
) ->
384 Printf.sprintf
"%s: destination %S" filename destname
387 let updateunder x y =
388 match getunder x y with
389 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
391 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
392 Wsi.setcursor
Wsi.CURSOR_INFO
393 | Ulinkgoto
(pageno
, _
) ->
395 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
396 Wsi.setcursor
Wsi.CURSOR_INFO
398 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
399 Wsi.setcursor
Wsi.CURSOR_TEXT
401 if conf
.underinfo
then showtext 'u'
("nexpected: " ^ s
);
402 Wsi.setcursor
Wsi.CURSOR_INHERIT
404 if conf
.underinfo
then showtext '
l'
("aunch: " ^ s
);
405 Wsi.setcursor
Wsi.CURSOR_INHERIT
407 if conf
.underinfo
then showtext '
n'
("amed: " ^ s
);
408 Wsi.setcursor
Wsi.CURSOR_INHERIT
409 | Uremote
(filename
, pageno
) ->
410 if conf
.underinfo
then showtext 'r'
411 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
412 Wsi.setcursor
Wsi.CURSOR_INFO
413 | Uremotedest
(filename
, destname
) ->
414 if conf
.underinfo
then showtext 'r'
415 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
416 Wsi.setcursor
Wsi.CURSOR_INFO
419 let showlinktype under
=
425 let s = undertext under
in
430 let b = Buffer.create
(String.length
s + 1) in
431 Buffer.add_string
b s;
436 let intentry_with_suffix text key
=
438 if key
>= 32 && key
< 127
442 match Char.lowercase
c with
444 let text = addchar text c in
448 let text = addchar text c in
452 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
458 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
459 if n != 4 then error
"incomplete read(len) = %d" n;
461 lor (Char.code
s.[0] lsl 24)
462 lor (Char.code
s.[1] lsl 16)
463 lor (Char.code
s.[2] lsl 8)
464 lor (Char.code
s.[3] lsl 0)
466 let s = String.create
len in
467 let n = tempfailureretry
(Unix.read fd
s 0) len in
468 if n != len then error
"incomplete read(data) %d vs %d" n len;
472 let btod b = if b then 1 else 0;;
475 let b = Buffer.create
16 in
476 Buffer.add_string
b "llll";
479 let s = Buffer.contents
b in
480 let n = String.length
s in
482 (* dolog "wcmd %S" (String.sub s 4 len); *)
483 s.[0] <- Char.chr
((len lsr 24) land 0xff);
484 s.[1] <- Char.chr
((len lsr 16) land 0xff);
485 s.[2] <- Char.chr
((len lsr 8) land 0xff);
486 s.[3] <- Char.chr
(len land 0xff);
487 let n'
= tempfailureretry
(Unix.write state
.sw
s 0) n in
488 if n'
!= n then error
"write failed %d vs %d" n'
n;
492 let nogeomcmds cmds
=
494 | s, [] -> emptystr
s
498 let layoutN ((columns
, coverA
, coverB
), b) y sh
=
499 let sh = sh - (hscrollh ()) in
500 let rec fold accu
n =
501 if n = Array.length
b
504 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
507 || n = state
.pagecount
- coverB
508 || (n - coverA
) mod columns
= columns
- 1)
514 let pagey = max
0 (y - vy
) in
515 let pagedispy = if pagey > 0 then 0 else vy
- y in
516 let pagedispx, pagex
=
518 if n = coverA
- 1 || n = state
.pagecount
- coverB
519 then state
.x + (wadjsb state
.winw
- w
) / 2
520 else dx + xoff
+ state
.x
527 let vw = wadjsb state
.winw
- pagedispx in
528 let pw = w
- pagex
in
531 let pagevh = min
(h
- pagey) (sh - pagedispy) in
532 if pagevw > 0 && pagevh > 0
543 ; pagedispx = pagedispx
544 ; pagedispy = pagedispy
556 if Array.length
b = 0
558 else List.rev
(fold [] (page_of_y
y))
561 let layoutS (columns
, b) y sh =
562 let sh = sh - hscrollh () in
563 let rec fold accu n =
564 if n = Array.length
b
567 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
574 let x = xoff
+ state
.x in
575 let pagey = max
0 (y - vy
) in
576 let pagedispy = if pagey > 0 then 0 else vy
- y in
577 let pagedispx, pagex
=
591 let pagecolw = pagew
/columns
in
593 if pagecolw < state
.winw
594 then pagedispx + ((wadjsb state
.winw
- pagecolw) / 2)
598 let vw = wadjsb state
.winw
- pagedispx in
599 let pw = pagew
- pagex
in
602 let pagevw = min
pagevw pagecolw in
603 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
604 if pagevw > 0 && pagevh > 0
615 ; pagedispx = pagedispx
616 ; pagedispy = pagedispy
617 ; pagecol
= n mod columns
632 if nogeomcmds state
.geomcmds
634 match conf
.columns
with
635 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
636 | Cmulti
c -> layoutN c y sh
637 | Csplit
s -> layoutS s y sh
642 let y = state
.y + incr
in
644 let y = min
y (state
.maxy
- (if conf
.maxhfit
then state
.winh
else 0)) in
649 let tilex = l.pagex
mod conf
.tilew
in
650 let tiley = l.pagey mod conf
.tileh
in
652 let col = l.pagex
/ conf
.tilew
in
653 let row = l.pagey / conf
.tileh
in
655 let rec rowloop row y0 dispy h
=
659 let dh = conf
.tileh
- y0 in
661 let rec colloop col x0 dispx w
=
665 let dw = conf
.tilew
- x0 in
669 then dispx+conf
.scrollbw
672 f col row dispx' dispy
x0 y0 dw dh;
673 colloop (col+1) 0 (dispx+dw) (w
-dw)
676 colloop col tilex l.pagedispx l.pagevw;
677 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
680 if l.pagevw > 0 && l.pagevh > 0
681 then rowloop row tiley l.pagedispy l.pagevh;
684 let gettileopaque l col row =
686 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
688 try Some
(Hashtbl.find state
.tilemap
key)
689 with Not_found
-> None
692 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
693 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
694 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
697 let filledrect x0 y0 x1 y1 =
698 GlArray.disable `texture_coord
;
699 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
700 GlArray.vertex `two state
.vraw
;
701 GlArray.draw_arrays `triangle_strip
0 4;
702 GlArray.enable `texture_coord
;
705 let linerect x0 y0 x1 y1 =
706 GlArray.disable `texture_coord
;
707 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
708 GlArray.vertex `two state
.vraw
;
709 GlArray.draw_arrays `line_loop
0 4;
710 GlArray.enable `texture_coord
;
713 let drawtiles l color
=
716 let f col row x y tilex tiley w h
=
717 match gettileopaque l col row with
718 | Some
(opaque
, _
, t
) ->
719 let params = x, y, w
, h
, tilex, tiley in
721 then GlTex.env
(`mode `blend
);
722 drawtile
params opaque
;
724 then GlTex.env
(`mode `modulate
);
728 let s = Printf.sprintf
732 let w = measurestr fstate
.fontsize
s in
733 GlDraw.color
(0.0, 0.0, 0.0);
734 filledrect (float (x-2))
737 (float (y + fstate
.fontsize
+ 2));
738 GlDraw.color
(1.0, 1.0, 1.0);
739 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
749 let lw = wadjsb state
.winw
- x in
752 let lh = state
.winh
- y in
756 then GlTex.env
(`mode `blend
);
757 begin match state
.checkerstexid
with
759 Gl.enable `texture_2d
;
760 GlTex.bind_texture `texture_2d id
;
764 and y1 = float (y+h
) in
766 let tw = float w /. 16.0
767 and th
= float h
/. 16.0 in
768 let tx0 = float tilex /. 16.0
769 and ty0
= float tiley /. 16.0 in
771 and ty1
= ty0
+. th
in
772 Raw.sets_float state
.vraw ~pos
:0
773 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
774 Raw.sets_float state
.traw ~pos
:0
775 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
776 GlArray.vertex `two state
.vraw
;
777 GlArray.tex_coord `two state
.traw
;
778 GlArray.draw_arrays `triangle_strip
0 4;
779 Gl.disable `texture_2d
;
782 GlDraw.color
(1.0, 1.0, 1.0);
783 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
786 then GlTex.env
(`mode `modulate
);
787 if w > 128 && h
> fstate
.fontsize
+ 10
789 let c = if conf
.invert
then 1.0 else 0.0 in
790 GlDraw.color
(c, c, c);
793 then (col*conf
.tilew
, row*conf
.tileh
)
796 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
805 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
807 let tilevisible1 l x y =
809 and ax1
= l.pagex
+ l.pagevw
811 and ay1
= l.pagey + l.pagevh in
815 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
816 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
818 let rx0 = max
ax0 bx0
819 and ry0
= max ay0 by0
820 and rx1
= min ax1
bx1
821 and ry1
= min ay1 by1
in
823 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
827 let tilevisible layout n x y =
828 let rec findpageinlayout m
= function
829 | l :: rest
when l.pageno
= n ->
830 tilevisible1 l x y || (
831 match conf
.columns
with
832 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
835 | _
:: rest
-> findpageinlayout 0 rest
838 findpageinlayout 0 layout;
841 let tileready l x y =
842 tilevisible1 l x y &&
843 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
846 let tilepage n p
layout =
847 let rec loop = function
851 let f col row _ _ _ _ _ _
=
852 if state
.currently
= Idle
854 match gettileopaque l col row with
857 let x = col*conf
.tilew
858 and y = row*conf
.tileh
in
860 let w = l.pagew
- x in
864 let h = l.pageh
- y in
869 then getpbo
w h conf
.colorspace
872 wcmd "tile %s %d %d %d %d %s"
873 (~
> p
) x y w h (~
> pbo);
876 l, p
, conf
.colorspace
, conf
.angle
,
877 state
.gen
, col, row, conf
.tilew
, conf
.tileh
886 if nogeomcmds state
.geomcmds
890 let preloadlayout y =
891 let y = if y < state
.winh
then 0 else y - state
.winh
in
892 let h = state
.winh
*3 in
898 if state
.currently
!= Idle
903 begin match getopaque l.pageno
with
905 wcmd "page %d %d" l.pageno
l.pagedimno
;
906 state
.currently
<- Loading
(l, state
.gen
);
908 tilepage l.pageno opaque pages
;
913 if nogeomcmds state
.geomcmds
919 if conf
.preload && state
.currently
= Idle
920 then load (preloadlayout state
.y);
923 let layoutready layout =
924 let rec fold all ls
=
927 let seen = ref false in
928 let allvisible = ref true in
929 let foo col row _ _ _ _ _ _
=
931 allvisible := !allvisible &&
932 begin match gettileopaque l col row with
938 fold (!seen && !allvisible) rest
941 let alltilesvisible = fold true layout in
946 let y = bound
y 0 state
.maxy
in
947 let y, layout, proceed
=
948 match conf
.maxwait
with
949 | Some time
when state
.ghyll
== noghyll
->
950 begin match state
.throttle
with
952 let layout = layout y state
.winh
in
953 let ready = layoutready layout in
957 state
.throttle
<- Some
(layout, y, now
());
959 else G.postRedisplay "gotoy showall (None)";
961 | Some
(_
, _
, started
) ->
962 let dt = now
() -. started
in
965 state
.throttle
<- None
;
966 let layout = layout y state
.winh
in
968 G.postRedisplay "maxwait";
975 let layout = layout y state
.winh
in
976 if not
!wtmode || layoutready layout
977 then G.postRedisplay "gotoy ready";
983 state
.layout <- layout;
984 begin match state
.mode
with
985 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
986 let rec loop = function
988 state
.mode
<- LinkNav
(Ltgendir
0)
989 | l :: _
when l.pageno
= pageno
->
990 begin match getopaque pageno
with
992 state
.mode
<- LinkNav
(Ltgendir
0)
994 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
995 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
996 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
997 then state
.mode
<- LinkNav
(Ltgendir
0)
999 | _
:: rest
-> loop rest
1004 begin match state
.mode
with
1005 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
1006 if not
(pagevisible layout pageno
)
1008 match state
.layout with
1011 state
.mode
<- Birdseye
(
1012 conf
, leftx
, l.pageno
, hooverpageno
, anchor
1015 | LinkNav
(Ltgendir dir
as lt
) ->
1017 let rec loop = function
1020 match getopaque l.pageno
with
1026 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1028 if dir
> 0 then LDfirst
else LDlast
1034 | Lnotfound
-> loop rest
1036 showlinktype (getlink opaque
n);
1037 Ltexact
(l.pageno
, n)
1041 state
.mode
<- LinkNav
linknav
1046 state
.ghyll
<- noghyll
;
1049 let mx, my
= state
.mpos
in
1054 let conttiling pageno opaque
=
1055 tilepage pageno opaque
1056 (if conf
.preload then preloadlayout state
.y else state
.layout)
1059 let gotoy_and_clear_text y =
1060 if not conf
.verbose
then state
.text <- "";
1064 let getanchory (n, top
, dtop
) =
1065 let y, h = getpageyh
n in
1066 if conf
.presentation
1068 let ips = calcips
h in
1069 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
1071 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
1074 let gotoanchor anchor
=
1075 gotoy (getanchory anchor
);
1079 cbput state
.hists
.nav
(getanchor
());
1083 let anchor = cbgetc state
.hists
.nav dir
in
1087 let gotoghyll1 single
y =
1088 let scroll f n a
b =
1089 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1091 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1093 then s (float f /. float a
)
1096 then 1.0 -. s ((float (f-b) /. float (n-b)))
1102 let ins = float a
*. 0.5
1103 and outs
= float (n-b) *. 0.5 in
1105 ins +. outs
+. float ones
1107 let rec set nab
y sy
=
1108 let (_N
, _A
, _B
), y =
1111 let scl = if y > sy
then 2 else -2 in
1112 let _N, _
, _
= nab
in
1113 (_N,0,_N), y+conf
.scrollstep
*scl
1115 let sum = summa
_N _A _B
in
1116 let dy = float (y - sy
) in
1120 then state
.ghyll
<- noghyll
1123 let s = scroll n _N _A _B
in
1124 let y1 = y1 +. ((s *. dy) /. sum) in
1125 gotoy_and_clear_text (truncate
y1);
1126 state
.ghyll
<- gf (n+1) y1;
1130 | Some
y'
when single
-> set nab
y' state
.y
1131 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1133 gf 0 (float state
.y)
1136 match conf
.ghyllscroll
with
1137 | Some nab
when not conf
.presentation
->
1138 if state
.ghyll
== noghyll
1139 then set nab
y state
.y
1140 else state
.ghyll
(Some
y)
1142 gotoy_and_clear_text y
1145 let gotoghyll = gotoghyll1 false;;
1147 let gotopage n top
=
1148 let y, h = getpageyh
n in
1149 let y = y + (truncate
(top
*. float h)) in
1153 let gotopage1 n top
=
1154 let y = getpagey
n in
1159 let invalidate s f =
1164 match state
.geomcmds
with
1165 | ps
, [] when emptystr ps
->
1167 state
.geomcmds
<- s, [];
1170 state
.geomcmds
<- ps
, [s, f];
1172 | ps
, (s'
, _
) :: rest
when s'
= s ->
1173 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1176 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1180 Hashtbl.iter
(fun _ opaque
->
1181 wcmd "freepage %s" (~
> opaque
);
1183 Hashtbl.clear state
.pagemap
;
1187 if not
(Queue.is_empty state
.tilelru
)
1189 Queue.iter
(fun (k
, p
, s) ->
1190 wcmd "freetile %s" (~
> p
);
1191 state
.memused
<- state
.memused
- s;
1192 Hashtbl.remove state
.tilemap k
;
1194 state
.uioh#infochanged Memused
;
1195 Queue.clear state
.tilelru
;
1201 let h = truncate
(float h*.conf
.zoom
) in
1202 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1206 let opendoc path password
=
1208 state
.password
<- password
;
1209 state
.gen
<- state
.gen
+ 1;
1210 state
.docinfo
<- [];
1213 setaalevel conf
.aalevel
;
1215 if emptystr state
.origin
1219 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1220 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
1221 invalidate "reqlayout"
1223 wcmd "reqlayout %d %d %d %s\000"
1224 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1225 (stateh state
.winh
) state
.nameddest
1230 state
.anchor <- getanchor
();
1231 opendoc state
.path state
.password
;
1235 let c = c *. conf
.colorscale
in
1239 let scalecolor2 (r
, g, b) =
1240 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1243 let docolumns = function
1245 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1246 let rec loop pageno
pdimno pdim
y ph pdims
=
1247 if pageno
= state
.pagecount
1250 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1252 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1253 pdimno+1, pdim
, rest
1257 let x = max
0 (((wadjsb state
.winw
- w) / 2) - xoff
) in
1259 (if conf
.presentation
1260 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1261 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1264 a.(pageno
) <- (pdimno, x, y, pdim
);
1265 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1267 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1268 conf
.columns
<- Csingle
a;
1270 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1271 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1272 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1273 let rec fixrow m
= if m
= pageno
then () else
1274 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1277 let y = y + (rowh
- h) / 2 in
1278 a.(m
) <- (pdimno, x, y, pdim
);
1282 if pageno
= state
.pagecount
1283 then fixrow (((pageno
- 1) / columns
) * columns
)
1285 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1287 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1288 pdimno+1, pdim
, rest
1293 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1295 let x = (wadjsb state
.winw
- w) / 2 in
1297 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1298 x, y + ips + rowh
, h
1301 if (pageno
- coverA
) mod columns
= 0
1303 let x = max
0 (wadjsb state
.winw
- state
.w) / 2 in
1305 if conf
.presentation
1307 let ips = calcips
h in
1308 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1310 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1314 else x, y, max rowh
h
1318 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1321 if pageno
= columns
&& conf
.presentation
1323 let ips = calcips rowh
in
1324 for i
= 0 to pred columns
1326 let (pdimno, x, y, pdim
) = a.(i
) in
1327 a.(i
) <- (pdimno, x, y+ips, pdim
)
1333 fixrow (pageno
- columns
);
1338 a.(pageno
) <- (pdimno, x, y, pdim
);
1339 let x = x + w + xoff
*2 + conf
.interpagespace
in
1340 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1342 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1343 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1346 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1347 let rec loop pageno
pdimno pdim
y pdims
=
1348 if pageno
= state
.pagecount
1351 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1353 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1354 pdimno+1, pdim
, rest
1359 let rec loop1 n x y =
1360 if n = c then y else (
1361 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1362 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1365 let y = loop1 0 0 y in
1366 loop (pageno
+1) pdimno pdim
y pdims
1368 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1369 conf
.columns
<- Csplit
(c, a);
1373 docolumns conf
.columns
;
1374 state
.maxy
<- calcheight
();
1375 if state
.reprf
== noreprf
1377 match state
.mode
with
1378 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1379 let y, h = getpageyh pageno
in
1380 let top = (state
.winh
- h) / 2 in
1381 gotoy (max
0 (y - top))
1382 | _
-> gotoanchor state
.anchor
1386 state
.reprf
<- noreprf
;
1391 GlDraw.viewport
0 0 w h;
1392 let firsttime = state
.geomcmds
== firstgeomcmds
in
1393 if not
firsttime && nogeomcmds state
.geomcmds
1394 then state
.anchor <- getanchor
();
1397 let w = wadjsb (truncate
(float w *. conf
.zoom
)) in
1400 setfontsize fstate
.fontsize
;
1401 GlMat.mode `modelview
;
1402 GlMat.load_identity
();
1404 GlMat.mode `projection
;
1405 GlMat.load_identity
();
1406 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1407 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1408 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1413 else float state
.x /. float state
.w
1415 invalidate "geometry"
1419 then state
.x <- truncate
(relx *. float w);
1421 match conf
.columns
with
1423 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1424 | Csplit
(c, _
) -> w * c
1426 wcmd "geometry %d %d %d"
1427 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1432 let len = String.length state
.text in
1433 let x0 = if conf
.leftscroll
then conf
.scrollbw
else 0 in
1436 match state
.mode
with
1437 | Textentry _
| View
| LinkNav _
->
1438 let h, _
, _
= state
.uioh#scrollpw
in
1443 filledrect x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1444 (x+.w) (float (state
.winh
- hscrollh))
1447 let w = float (wadjsb state
.winw
- 1) in
1448 if state
.progress
>= 0.0 && state
.progress
< 1.0
1450 GlDraw.color
(0.3, 0.3, 0.3);
1451 let w1 = w *. state
.progress
in
1453 GlDraw.color
(0.0, 0.0, 0.0);
1454 rect (float x0+.w1) (float x0+.w-.w1)
1457 GlDraw.color
(0.0, 0.0, 0.0);
1461 GlDraw.color
(1.0, 1.0, 1.0);
1462 drawstring fstate
.fontsize
1463 (if conf
.leftscroll
then x0 else x0 + if len > 0 then 8 else 2)
1464 (state
.winh
- hscrollh - 5) s;
1467 match state
.mode
with
1468 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1472 Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1474 Printf.sprintf
"%s%s_" prefix
text
1483 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1485 let s1 = "(press 'e' to review error messasges)" in
1486 if nonemptystr
s then s ^
" " ^
s1 else s1
1496 let len = Queue.length state
.tilelru
in
1498 match state
.throttle
with
1501 then preloadlayout state
.y
1503 | Some
(layout, _
, _
) ->
1507 if state
.memused
<= conf
.memlimit
1512 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1513 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1514 let (_
, pw, ph
, _
) = getpagedim
n in
1517 && colorspace
= conf
.colorspace
1518 && angle
= conf
.angle
1522 let x = col*conf
.tilew
1523 and y = row*conf
.tileh
in
1524 tilevisible (Lazy.force_val
layout) n x y
1526 then Queue.push lruitem state
.tilelru
1529 wcmd "freetile %s" (~
> p
);
1530 state
.memused
<- state
.memused
- s;
1531 state
.uioh#infochanged Memused
;
1532 Hashtbl.remove state
.tilemap k
;
1540 let logcurrently = function
1541 | Idle
-> dolog
"Idle"
1542 | Loading
(l, gen
) ->
1543 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen state
.gen
1544 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1546 "Tiling %d[%d,%d] page=%s cs=%s angle"
1547 l.pageno
col row (~
> pageopaque
)
1548 (CSTE.to_string colorspace
)
1550 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1551 angle gen conf
.angle state
.gen
1553 conf
.tilew conf
.tileh
1560 let r = Str.regexp
" " in
1561 fun s -> Str.bounded_split
r s 2;
1564 let onpagerect pageno
f =
1566 match conf
.columns
with
1567 | Cmulti
(_
, b) -> b
1569 | Csplit
(_
, b) -> b
1571 if pageno
>= 0 && pageno
< Array.length
b
1573 let (_
, _
, _
, (w, h, _
, _
)) = b.(pageno
) in
1577 let gotopagexy1 pageno
x y =
1578 let _,w1,h1
,leftx
= getpagedim pageno
in
1579 let top = y /. (float h1
) in
1580 let left = x /. (float w1) in
1581 let py, w, h = getpageywh pageno
in
1582 let wh = state
.winh
- hscrollh () in
1583 let x = left *. (float w) in
1584 let x = leftx
+ state
.x + truncate
x in
1586 if x < 0 || x >= wadjsb state
.winw
1590 let pdy = truncate
(top *. float h) in
1591 let y'
= py + pdy in
1592 let dy = y'
- state
.y in
1594 if x != state
.x || not
(dy > 0 && dy < wh)
1596 if conf
.presentation
1598 if abs
(py - y'
) > wh
1605 if state
.x != sx || state
.y != sy
1610 let ww = wadjsb state
.winw
in
1612 and qy
= pdy / wh in
1614 and y = py + qy
* wh in
1615 let x = if -x + ww > w1 then -(w1-ww) else x
1616 and y'
= if y + wh > state
.maxy
then state
.maxy
- wh else y in
1618 if conf
.presentation
1620 if abs
(py - y'
) > wh
1630 gotoy_and_clear_text y;
1632 else gotoy_and_clear_text state
.y;
1635 let gotopagexy pageno
x y =
1636 match state
.mode
with
1637 | Birdseye
_ -> gotopage pageno
0.0
1638 | _ -> gotopagexy1 pageno
x y
1642 (* dolog "%S" cmds; *)
1643 let cl = splitatspace cmds
in
1645 try Scanf.sscanf
s fmt
f
1647 dolog
"error processing '%S': %s" cmds
(exntos exn
);
1650 let addoutline outline
=
1651 match state
.currently
with
1652 | Outlining outlines
->
1653 state
.currently
<- Outlining
(outline
:: outlines
)
1654 | Idle
-> state
.currently
<- Outlining
[outline
]
1656 dolog
"invalid outlining state";
1657 logcurrently currently
1661 state
.uioh#infochanged Pdim
;
1664 | "clearrects" :: [] ->
1665 state
.rects
<- state
.rects1
;
1666 G.postRedisplay "clearrects";
1668 | "continue" :: args
:: [] ->
1669 let n = scan args
"%u" (fun n -> n) in
1670 state
.pagecount
<- n;
1671 begin match state
.currently
with
1673 state
.currently
<- Idle
;
1674 state
.outlines
<- Array.of_list
(List.rev
l)
1678 let cur, cmds
= state
.geomcmds
in
1680 then failwith
"umpossible";
1682 begin match List.rev cmds
with
1684 state
.geomcmds
<- "", [];
1685 state
.throttle
<- None
;
1689 state
.geomcmds
<- s, List.rev rest
;
1691 if conf
.maxwait
= None
&& not
!wtmode
1692 then G.postRedisplay "continue";
1694 | "title" :: args
:: [] ->
1697 | "msg" :: args
:: [] ->
1700 | "vmsg" :: args
:: [] ->
1702 then showtext ' ' args
1704 | "emsg" :: args
:: [] ->
1705 Buffer.add_string state
.errmsgs args
;
1706 state
.newerrmsgs
<- true;
1707 G.postRedisplay "error message"
1709 | "progress" :: args
:: [] ->
1710 let progress, text =
1713 f, String.sub args pos
(String.length args
- pos
))
1716 state
.progress <- progress;
1717 G.postRedisplay "progress"
1719 | "firstmatch" :: args
:: [] ->
1720 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1721 scan args
"%u %d %f %f %f %f %f %f %f %f"
1722 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1723 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1725 let y = (getpagey
pageno) + truncate
y0 in
1728 state
.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1730 | "match" :: args
:: [] ->
1731 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1732 scan args
"%u %d %f %f %f %f %f %f %f %f"
1733 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1734 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1737 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1739 | "page" :: args
:: [] ->
1740 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1741 let pageopaque = ~
< pageopaques in
1742 begin match state
.currently
with
1743 | Loading
(l, gen
) ->
1744 vlog "page %d took %f sec" l.pageno t
;
1745 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1746 begin match state
.throttle
with
1748 let preloadedpages =
1750 then preloadlayout state
.y
1755 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1756 IntSet.empty
preloadedpages
1759 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1760 if not
(IntSet.mem
pageno set)
1762 wcmd "freepage %s" (~
> opaque
);
1768 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1771 state
.currently
<- Idle
;
1774 tilepage l.pageno pageopaque state
.layout;
1776 load preloadedpages;
1777 if pagevisible state
.layout l.pageno
1778 && layoutready state
.layout
1779 then G.postRedisplay "page";
1782 | Some
(layout, _, _) ->
1783 state
.currently
<- Idle
;
1784 tilepage l.pageno pageopaque layout;
1789 dolog
"Inconsistent loading state";
1790 logcurrently state
.currently
;
1794 | "tile" :: args
:: [] ->
1795 let (x, y, opaques
, size
, t
) =
1796 scan args
"%u %u %s %u %f"
1797 (fun x y p size t
-> (x, y, p
, size
, t
))
1799 let opaque = ~
< opaques
in
1800 begin match state
.currently
with
1801 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1802 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1805 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1807 wcmd "freetile %s" (~
> opaque);
1808 state
.currently
<- Idle
;
1812 puttileopaque l col row gen cs angle
opaque size t
;
1813 state
.memused
<- state
.memused
+ size
;
1814 state
.uioh#infochanged Memused
;
1816 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1817 opaque, size
) state
.tilelru
;
1820 match state
.throttle
with
1821 | None
-> state
.layout
1822 | Some
(layout, _, _) -> layout
1825 state
.currently
<- Idle
;
1827 && conf
.colorspace
= cs
1828 && conf
.angle
= angle
1829 && tilevisible layout l.pageno x y
1830 then conttiling l.pageno pageopaque;
1832 begin match state
.throttle
with
1834 preload state
.layout;
1836 && conf
.colorspace
= cs
1837 && conf
.angle
= angle
1838 && tilevisible state
.layout l.pageno x y
1839 && (not
!wtmode || layoutready state
.layout)
1840 then G.postRedisplay "tile nothrottle";
1842 | Some
(layout, y, _) ->
1843 let ready = layoutready layout in
1847 state
.layout <- layout;
1848 state
.throttle
<- None
;
1849 G.postRedisplay "throttle";
1856 dolog
"Inconsistent tiling state";
1857 logcurrently state
.currently
;
1861 | "pdim" :: args
:: [] ->
1862 let (n, w, h, _) as pdim
=
1863 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1866 match conf
.fitmodel
, conf
.columns
with
1867 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
1870 state
.uioh#infochanged Pdim
;
1871 state
.pdims
<- pdim :: state
.pdims
1873 | "o" :: args
:: [] ->
1874 let (l, n, t
, h, pos
) =
1875 scan args
"%u %u %d %u %n"
1876 (fun l n t
h pos
-> l, n, t
, h, pos
)
1878 let s = String.sub args pos
(String.length args
- pos
) in
1879 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1881 | "ou" :: args
:: [] ->
1882 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1883 let s = String.sub args pos
len in
1884 let pos2 = pos
+ len + 1 in
1885 let uri = String.sub args
pos2 (String.length args
- pos2) in
1886 addoutline (s, l, Ouri
uri)
1888 | "on" :: args
:: [] ->
1889 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1890 let s = String.sub args pos
(String.length args
- pos
) in
1891 addoutline (s, l, Onone
)
1893 | "a" :: args
:: [] ->
1895 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1897 state
.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
1899 | "info" :: args
:: [] ->
1900 state
.docinfo
<- (1, args
) :: state
.docinfo
1902 | "infoend" :: [] ->
1903 state
.uioh#infochanged Docinfo
;
1904 state
.docinfo
<- List.rev state
.docinfo
1907 error
"unknown cmd `%S'" cmds
1912 let action = function
1913 | HCprev
-> cbget cb ~
-1
1914 | HCnext
-> cbget cb
1
1915 | HCfirst
-> cbget cb ~
-(cb
.rc)
1916 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1917 and cancel
() = cb
.rc <- rc
1921 let search pattern forward
=
1922 match conf
.columns
with
1924 showtext '
!'
"searching does not work properly in split columns mode"
1926 if nonemptystr pattern
1929 match state
.layout with
1932 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1934 wcmd "search %d %d %d %d,%s\000"
1935 (btod conf
.icase
) pn py (btod forward
) pattern
;
1938 let intentry text key =
1940 if key >= 32 && key < 127
1946 let text = addchar text c in
1950 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1954 let linknentry text key =
1956 if key >= 32 && key < 127
1962 let text = addchar text c in
1966 state
.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1974 let l = String.length
s in
1975 let rec loop pos
n = if pos
= l then n else
1976 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1977 loop (pos
+1) (n*26 + m)
1980 let rec loop n = function
1983 match getopaque l.pageno with
1984 | None
-> loop n rest
1986 let m = getlinkcount
opaque in
1989 let under = getlink
opaque n in
1992 else loop (n-m) rest
1994 loop n state
.layout;
1998 let textentry text key =
1999 if key land 0xff00 = 0xff00
2001 else TEcont
(text ^ toutf8
key)
2004 let reqlayout angle fitmodel
=
2005 match state
.throttle
with
2007 if nogeomcmds state
.geomcmds
2008 then state
.anchor <- getanchor
();
2009 conf
.angle
<- angle
mod 360;
2012 match state
.mode
with
2013 | LinkNav
_ -> state
.mode
<- View
2016 conf
.fitmodel
<- fitmodel
;
2017 invalidate "reqlayout"
2019 wcmd "reqlayout %d %d %d"
2020 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
2025 let settrim trimmargins trimfuzz
=
2026 if nogeomcmds state
.geomcmds
2027 then state
.anchor <- getanchor
();
2028 conf
.trimmargins
<- trimmargins
;
2029 conf
.trimfuzz
<- trimfuzz
;
2030 let x0, y0, x1, y1 = trimfuzz
in
2031 invalidate "settrim"
2033 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
2038 match state
.throttle
with
2040 let zoom = max
0.0001 zoom in
2041 if zoom <> conf
.zoom
2043 state
.prevzoom
<- (conf
.zoom, state
.x);
2045 reshape state
.winw state
.winh
;
2046 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2049 | Some
(layout, y, started
) ->
2051 match conf
.maxwait
with
2055 let dt = now
() -. started
in
2063 let setcolumns mode columns coverA coverB
=
2064 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2068 then showtext '
!'
"split mode doesn't work in bird's eye"
2070 conf
.columns
<- Csplit
(-columns
, [||]);
2078 conf
.columns
<- Csingle
[||];
2083 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2087 reshape state
.winw state
.winh
;
2090 let resetmstate () =
2091 state
.mstate
<- Mnone
;
2092 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2095 let enterbirdseye () =
2096 let zoom = float conf
.thumbw
/. float state
.winw
in
2097 let birdseyepageno =
2098 let cy = state
.winh
/ 2 in
2102 let rec fold best
= function
2105 let d = cy - (l.pagedispy + l.pagevh/2)
2106 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2107 if abs
d < abs dbest
2114 state
.mode
<- Birdseye
(
2115 { conf
with zoom = conf
.zoom }, state
.x, birdseyepageno, -1, getanchor
()
2119 conf
.presentation
<- false;
2120 conf
.interpagespace
<- 10;
2121 conf
.hlinks
<- false;
2122 conf
.fitmodel
<- FitProportional
;
2124 conf
.maxwait
<- None
;
2126 match conf
.beyecolumns
with
2129 Cmulti
((c, 0, 0), [||])
2130 | None
-> Csingle
[||]
2134 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2139 reshape state
.winw state
.winh
;
2142 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2144 conf
.zoom <- c.zoom;
2145 conf
.presentation
<- c.presentation
;
2146 conf
.interpagespace
<- c.interpagespace
;
2147 conf
.maxwait
<- c.maxwait
;
2148 conf
.hlinks
<- c.hlinks
;
2149 conf
.fitmodel
<- c.fitmodel
;
2150 conf
.beyecolumns
<- (
2151 match conf
.columns
with
2152 | Cmulti
((c, _, _), _) -> Some
c
2154 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2157 match c.columns
with
2158 | Cmulti
(c, _) -> Cmulti
(c, [||])
2159 | Csingle
_ -> Csingle
[||]
2160 | Csplit
(c, _) -> Csplit
(c, [||])
2164 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2167 reshape state
.winw state
.winh
;
2168 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2172 let togglebirdseye () =
2173 match state
.mode
with
2174 | Birdseye vals
-> leavebirdseye vals
true
2175 | View
-> enterbirdseye ()
2179 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2180 let pageno = max
0 (pageno - incr
) in
2181 let rec loop = function
2182 | [] -> gotopage1 pageno 0
2183 | l :: _ when l.pageno = pageno ->
2184 if l.pagedispy >= 0 && l.pagey = 0
2185 then G.postRedisplay "upbirdseye"
2186 else gotopage1 pageno 0
2187 | _ :: rest
-> loop rest
2190 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2193 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2194 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2195 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2196 let rec loop = function
2198 let y, h = getpageyh
pageno in
2199 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2201 | l :: _ when l.pageno = pageno ->
2202 if l.pagevh != l.pageh
2203 then gotoy (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2204 else G.postRedisplay "downbirdseye"
2205 | _ :: rest
-> loop rest
2210 let boundastep h step
=
2212 then bound step ~
-h 0
2216 let optentry mode
_ key =
2217 let btos b = if b then "on" else "off" in
2218 if key >= 32 && key < 127
2220 let c = Char.chr
key in
2224 try conf
.scrollstep
<- int_of_string
s with exc
->
2225 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2227 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2232 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2233 if state
.autoscroll
<> None
2234 then state
.autoscroll
<- Some conf
.autoscrollstep
2236 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2238 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2243 let n, a, b = multicolumns_of_string
s in
2244 setcolumns mode
n a b;
2246 state
.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
2248 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2253 let zoom = float (int_of_string
s) /. 100.0 in
2256 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2258 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2263 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2265 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2266 begin match mode
with
2268 leavebirdseye beye
false;
2273 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2275 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2280 Some
(int_of_string
s)
2282 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2286 | Some angle
-> reqlayout angle conf
.fitmodel
2289 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2292 conf
.icase
<- not conf
.icase
;
2293 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2296 conf
.preload <- not conf
.preload;
2298 TEdone
("preload " ^
(btos conf
.preload))
2301 conf
.verbose
<- not conf
.verbose
;
2302 TEdone
("verbose " ^
(btos conf
.verbose
))
2305 conf
.debug
<- not conf
.debug
;
2306 TEdone
("debug " ^
(btos conf
.debug
))
2309 conf
.maxhfit
<- not conf
.maxhfit
;
2310 state
.maxy
<- calcheight
();
2311 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2314 conf
.crophack
<- not conf
.crophack
;
2315 TEdone
("crophack " ^
btos conf
.crophack
)
2319 match conf
.maxwait
with
2321 conf
.maxwait
<- Some infinity
;
2322 "always wait for page to complete"
2324 conf
.maxwait
<- None
;
2325 "show placeholder if page is not ready"
2330 conf
.underinfo
<- not conf
.underinfo
;
2331 TEdone
("underinfo " ^
btos conf
.underinfo
)
2334 conf
.savebmarks
<- not conf
.savebmarks
;
2335 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2341 match state
.layout with
2346 conf
.interpagespace
<- int_of_string
s;
2347 docolumns conf
.columns
;
2348 state
.maxy
<- calcheight
();
2349 let y = getpagey
pageno in
2352 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2354 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2358 match conf
.fitmodel
with
2359 | FitProportional
-> FitWidth
2360 | _ -> FitProportional
2362 reqlayout conf
.angle
fm;
2363 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2366 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2367 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2370 conf
.invert
<- not conf
.invert
;
2371 TEdone
("invert colors " ^
btos conf
.invert
)
2375 cbput state
.hists
.sel
s;
2378 TEswitch
("selection command: ", "", Some
(onhist state
.hists
.sel
),
2379 textentry, ondone, true)
2383 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2384 else conf
.pax
<- None
;
2385 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2388 state
.text <- Printf.sprintf
"bad option %d `%c'" key c;
2394 class type lvsource
= object
2395 method getitemcount
: int
2396 method getitem
: int -> (string * int)
2397 method hasaction
: int -> bool
2405 method getactive
: int
2406 method getfirst
: int
2408 method getminfo
: (int * int) array
2411 class virtual lvsourcebase
= object
2412 val mutable m_active
= 0
2413 val mutable m_first
= 0
2414 val mutable m_pan
= 0
2415 method getactive
= m_active
2416 method getfirst
= m_first
2417 method getpan
= m_pan
2418 method getminfo
: (int * int) array
= [||]
2421 let withoutlastutf8 s =
2422 let len = String.length
s in
2430 let b = Char.code
s.[pos
] in
2431 if b land 0b11000000 = 0b11000000
2436 if Char.code
s.[len-1] land 0x80 = 0
2440 String.sub
s 0 first;
2443 let textentrykeyboard
2444 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2446 if key >= 0xffb0 && key <= 0xffb9
2447 then key - 0xffb0 + 48 else key
2450 state
.mode
<- Textentry
(te
, onleave
);
2453 G.postRedisplay "textentrykeyboard enttext";
2455 let histaction cmd
=
2458 | Some
(action, _) ->
2459 state
.mode
<- Textentry
(
2460 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2462 G.postRedisplay "textentry histaction"
2465 | 0xff08 -> (* backspace *)
2466 if emptystr
text && cancelonempty
2469 G.postRedisplay "textentrykeyboard after cancel";
2472 let s = withoutlastutf8 text in
2473 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2475 | 0xff0d | 0xff8d -> (* (kp) enter *)
2478 G.postRedisplay "textentrykeyboard after confirm"
2480 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
2481 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
2482 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
2483 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
2485 | 0xff1b -> (* escape*)
2488 begin match opthist
with
2490 | Some
(_, onhistcancel
) -> onhistcancel
()
2494 G.postRedisplay "textentrykeyboard after cancel2"
2497 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
2500 | 0xff9f | 0xffff -> () (* delete *)
2503 && key land 0xff00 != 0xff00 (* keyboard *)
2504 && key land 0xfe00 != 0xfe00 (* xkb *)
2505 && key land 0xfd00 != 0xfd00 (* 3270 *)
2507 begin match onkey
text key with
2511 G.postRedisplay "textentrykeyboard after confirm2";
2514 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2518 G.postRedisplay "textentrykeyboard after cancel3"
2521 state
.mode
<- Textentry
(te
, onleave
);
2522 G.postRedisplay "textentrykeyboard switch";
2526 vlog "unhandled key %s" (Wsi.keyname
key)
2529 let firstof first active
=
2530 if first > active
|| abs
(first - active
) > fstate
.maxrows
- 1
2531 then max
0 (active
- (fstate
.maxrows
/2))
2535 let calcfirst first active
=
2538 let rows = active
- first in
2539 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2543 let scrollph y maxy
=
2544 let sh = float (maxy
+ state
.winh
) /. float state
.winh
in
2545 let sh = float state
.winh
/. sh in
2546 let sh = max
sh (float conf
.scrollh
) in
2548 let percent = float y /. float maxy
in
2549 let position = (float state
.winh
-. sh) *. percent in
2552 if position +. sh > float state
.winh
2553 then float state
.winh
-. sh
2559 let coe s = (s :> uioh
);;
2561 class listview ?
(helpmode
=false) ~
(source
:lvsource
) ~trusted ~modehash
=
2563 val m_pan
= source#getpan
2564 val m_first
= source#getfirst
2565 val m_active
= source#getactive
2567 val m_prev_uioh
= state
.uioh
2569 method private elemunder
y =
2573 let n = y / (fstate
.fontsize
+1) in
2574 if m_first
+ n < source#getitemcount
2576 if source#hasaction
(m_first
+ n)
2577 then Some
(m_first
+ n)
2584 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2585 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2586 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2587 GlDraw.color
(1., 1., 1.);
2588 Gl.enable `texture_2d
;
2589 let fs = fstate
.fontsize
in
2591 let ww = fstate
.wwidth
in
2592 let tabw = 17.0*.ww in
2593 let itemcount = source#getitemcount
in
2594 let minfo = source#getminfo
in
2597 then float conf
.scrollbw
, float (state
.winw
- 1)
2598 else 0.0, float (state
.winw
- conf
.scrollbw
- 1)
2601 if (row - m_first
) > fstate
.maxrows
2604 if row >= 0 && row < itemcount
2606 let (s, level
) = source#getitem
row in
2607 let y = (row - m_first
) * nfs in
2608 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2611 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2615 Gl.disable `texture_2d
;
2616 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2617 GlDraw.color
(1., 1., 1.) ~
alpha;
2618 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2619 Gl.enable `texture_2d
;
2620 GlDraw.color
(1., 1., 1.);
2622 let drawtabularstring s =
2623 let drawstr x s = drawstring1 fs (truncate
(x +. x0)) (y+nfs) s in
2626 let x = if helpmode
&& row > 0 then x +. ww else x in
2627 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2630 let len = String.length
s - tabpos - 1 in
2631 let s1 = String.sub
s 0 tabpos
2632 and s2
= String.sub
s (tabpos + 1) len in
2633 let nx = drawstr x s1 in
2635 let x = x +. (max
tabw sw) in
2638 let len = String.length
s - 2 in
2639 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2641 let s = String.sub
s 2 len in
2642 let x = if not helpmode
then x +. ww else x in
2643 GlDraw.color
(1.2, 1.2, 1.2);
2644 let vinc = drawstring1 (fs+fs/4)
2645 (truncate
(x -. ww)) (y+nfs) s in
2646 GlDraw.color
(1., 1., 1.);
2647 vinc +. (float fs *. 0.8)
2653 let _ = drawtabularstring s in
2659 GlDraw.color
(1.0, 1.0, 1.0) ~
alpha:0.5;
2661 if (row - m_first
) > fstate
.maxrows
2664 if row >= 0 && row < itemcount
2666 let (s, level
) = source#getitem
row in
2667 let y = (row - m_first
) * nfs in
2668 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2669 let (first, last
) = minfo.(row) in
2670 let prefix = String.sub
s 0 first in
2671 let suffix = String.sub
s first (last
- first) in
2672 let w1 = measurestr fstate
.fontsize
prefix in
2673 let w2 = measurestr fstate
.fontsize
suffix in
2675 and y0 = (float (y+2)) in
2677 and y1 = (float (y+fs+3)) in
2678 filledrect x0 y0 x1 y1;
2683 Gl.disable `texture_2d
;
2684 if Array.length
minfo > 0 then loop m_first
;
2687 method updownlevel incr
=
2688 let len = source#getitemcount
in
2690 if m_active
>= 0 && m_active
< len
2691 then snd
(source#getitem m_active
)
2695 if i
= len then i
-1 else if i
= -1 then 0 else
2696 let _, l = source#getitem i
in
2697 if l != curlevel then i
else flow (i
+incr
)
2699 let active = flow m_active
in
2700 let first = calcfirst m_first
active in
2701 G.postRedisplay "outline updownlevel";
2702 {< m_active
= active; m_first
= first >}
2704 method private key1
key mask
=
2705 let set1 active first qsearch
=
2706 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2708 let search active pattern incr
=
2709 let active = if active = -1 then m_first
else active in
2712 if n >= 0 && n < source#getitemcount
2714 let s, _ = source#getitem
n in
2716 (try ignore
(Str.search_forward
re s 0); true
2717 with Not_found
-> false)
2719 else loop (n + incr
)
2726 let re = Str.regexp_case_fold pattern
in
2732 let itemcount = source#getitemcount
in
2733 let find start incr
=
2735 if i
= -1 || i
= itemcount
2738 if source#hasaction i
2740 else find (i
+ incr
)
2745 let set active first =
2746 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2748 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
2751 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2753 let incr1 = if incr
> 0 then 1 else -1 in
2754 if isvisible m_first m_active
2757 let next = m_active
+ incr
in
2759 if next < 0 || next >= itemcount
2761 else find next incr1
2763 if abs
(m_active
- next) > fstate
.maxrows
2769 let first = m_first
+ incr
in
2770 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2772 let next = m_active
+ incr
in
2773 let next = bound
next 0 (itemcount - 1) in
2780 if isvisible first next
2787 let first = min
next m_first
in
2789 if abs
(next - first) > fstate
.maxrows
2795 let first = m_first
+ incr
in
2796 let first = bound
first 0 (itemcount - 1) in
2798 let next = m_active
+ incr
in
2799 let next = bound
next 0 (itemcount - 1) in
2800 let next = find next incr1 in
2802 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2804 let active = if m_active
= -1 then next else m_active
in
2809 if isvisible first active
2815 G.postRedisplay "listview navigate";
2819 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2820 let incr = if key = 0x72 then -1 else 1 in
2822 match search (m_active
+ incr) m_qsearch
incr with
2824 state
.text <- m_qsearch ^
" [not found]";
2827 state
.text <- m_qsearch
;
2828 active, firstof m_first
active
2830 G.postRedisplay "listview ctrl-r/s";
2831 set1 active first m_qsearch
;
2833 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
2834 if m_active
>= 0 && m_active
< source#getitemcount
2836 let s, _ = source#getitem m_active
in
2841 | 0xff08 -> (* backspace *)
2842 if emptystr m_qsearch
2845 let qsearch = withoutlastutf8 m_qsearch
in
2849 G.postRedisplay "listview empty qsearch";
2850 set1 m_active m_first
"";
2854 match search m_active
qsearch ~
-1 with
2856 state
.text <- qsearch ^
" [not found]";
2859 state
.text <- qsearch;
2860 active, firstof m_first
active
2862 G.postRedisplay "listview backspace qsearch";
2863 set1 active first qsearch
2866 | key when (key != 0 && key land 0xff00 != 0xff00) ->
2867 let pattern = m_qsearch ^ toutf8
key in
2869 match search m_active
pattern 1 with
2871 state
.text <- pattern ^
" [not found]";
2874 state
.text <- pattern;
2875 active, firstof m_first
active
2877 G.postRedisplay "listview qsearch add";
2878 set1 active first pattern;
2880 | 0xff1b -> (* escape *)
2882 if emptystr m_qsearch
2884 G.postRedisplay "list view escape";
2887 source#exit
(coe self
) true m_active m_first m_pan
2889 | None
-> m_prev_uioh
2894 G.postRedisplay "list view kill qsearch";
2895 coe {< m_qsearch
= "" >}
2898 | 0xff0d | 0xff8d -> (* (kp) enter *)
2900 let self = {< m_qsearch
= "" >} in
2902 G.postRedisplay "listview enter";
2903 if m_active
>= 0 && m_active
< source#getitemcount
2905 source#exit
(coe self) false m_active m_first m_pan
;
2908 source#exit
(coe self) true m_active m_first m_pan
;
2911 begin match opt with
2912 | None
-> m_prev_uioh
2916 | 0xff9f | 0xffff -> (* (kp) delete *)
2919 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
2920 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
2921 | 0xff55 | 0xff9a -> navigate ~
-(fstate
.maxrows
) (* (kp) prior *)
2922 | 0xff56 | 0xff9b -> navigate fstate
.maxrows
(* (kp) next *)
2924 | 0xff53 | 0xff98 -> (* (kp) right *)
2926 G.postRedisplay "listview right";
2927 coe {< m_pan
= m_pan
- 1 >}
2929 | 0xff51 | 0xff96 -> (* (kp) left *)
2931 G.postRedisplay "listview left";
2932 coe {< m_pan
= m_pan
+ 1 >}
2934 | 0xff50 | 0xff95 -> (* (kp) home *)
2935 let active = find 0 1 in
2936 G.postRedisplay "listview home";
2939 | 0xff57 | 0xff9c -> (* (kp) end *)
2940 let first = max
0 (itemcount - fstate
.maxrows
) in
2941 let active = find (itemcount - 1) ~
-1 in
2942 G.postRedisplay "listview end";
2945 | key when (key = 0 || key land 0xff00 = 0xff00) ->
2949 dolog
"listview unknown key %#x" key; coe self
2951 method key key mask
=
2952 match state
.mode
with
2953 | Textentry te
-> textentrykeyboard key mask te
; coe self
2954 | _ -> self#key1
key mask
2956 method button button down
x y _ =
2959 | 1 when x > state
.winw
- conf
.scrollbw
->
2960 G.postRedisplay "listview scroll";
2963 let _, position, sh = self#
scrollph in
2964 if y > truncate
position && y < truncate
(position +. sh)
2966 state
.mstate
<- Mscrolly
;
2970 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2971 let first = truncate
(s *. float source#getitemcount
) in
2972 let first = min source#getitemcount
first in
2973 Some
(coe {< m_first
= first; m_active
= first >})
2975 state
.mstate
<- Mnone
;
2978 | 1 when not down
->
2979 begin match self#elemunder
y with
2981 G.postRedisplay "listview click";
2982 source#exit
(coe {< m_active
= n >}) false n m_first m_pan
2986 | n when (n == 4 || n == 5) && not down
->
2987 let len = source#getitemcount
in
2989 if n = 5 && m_first
+ fstate
.maxrows
>= len
2993 let first = m_first
+ (if n == 4 then -1 else 1) in
2994 bound
first 0 (len - 1)
2996 G.postRedisplay "listview wheel";
2997 Some
(coe {< m_first
= first >})
2998 | n when (n = 6 || n = 7) && not down
->
2999 let inc = if n = 7 then -1 else 1 in
3000 G.postRedisplay "listview hwheel";
3001 Some
(coe {< m_pan
= m_pan
+ inc >})
3006 | None
-> m_prev_uioh
3009 method multiclick
_ x y = self#button
1 true x y
3012 match state
.mstate
with
3014 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3015 let first = truncate
(s *. float source#getitemcount
) in
3016 let first = min source#getitemcount
first in
3017 G.postRedisplay "listview motion";
3018 coe {< m_first
= first; m_active
= first >}
3021 method pmotion
x y =
3022 if x < state
.winw
- conf
.scrollbw
3025 match self#elemunder
y with
3026 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3027 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3031 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3036 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3040 method infochanged
_ = ()
3042 method scrollpw
= (0, 0.0, 0.0)
3044 let nfs = fstate
.fontsize
+ 1 in
3045 let y = m_first
* nfs in
3046 let itemcount = source#getitemcount
in
3047 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3048 let maxy = maxi * nfs in
3049 let p, h = scrollph y maxy in
3052 method modehash
= modehash
3053 method eformsgs
= false
3056 class outlinelistview ~source
=
3057 let settext autonarrow
s =
3060 let ss = source#statestr
in
3064 else "{" ^
ss ^
"} [" ^
s ^
"]"
3065 else state
.text <- s
3070 ~source
:(source
:> lvsource
)
3072 ~modehash
:(findkeyhash conf
"outline")
3075 val m_autonarrow
= false
3077 method display
= super#display
3079 method key key mask
=
3081 if emptystr state
.text
3083 else fstate
.maxrows - 2
3085 let calcfirst first active =
3088 let rows = active - first in
3089 if rows > maxrows then active - maxrows else first
3093 let active = m_active
+ incr in
3094 let active = bound
active 0 (source#getitemcount
- 1) in
3095 let first = calcfirst m_first
active in
3096 G.postRedisplay "outline navigate";
3097 coe {< m_active
= active; m_first
= first >}
3099 let navscroll first =
3101 let dist = m_active
- first in
3107 else first + maxrows
3110 G.postRedisplay "outline navscroll";
3111 coe {< m_first
= first; m_active
= active >}
3113 let ctrl = Wsi.withctrl mask
in
3115 | 97 when ctrl -> (* ctrl-a *)
3118 then (source#denarrow
; "")
3120 let pattern = source#renarrow
in
3121 if nonemptystr m_qsearch
3122 then (source#narrow m_qsearch
; m_qsearch
)
3126 settext (not m_autonarrow
) text;
3127 G.postRedisplay "toggle auto narrowing";
3128 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3130 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3132 G.postRedisplay "toggle auto narrowing";
3133 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3135 | 110 when ctrl -> (* ctrl-n *)
3136 source#narrow m_qsearch
;
3138 then source#add_narrow_pattern m_qsearch
;
3139 G.postRedisplay "outline ctrl-n";
3140 coe {< m_first
= 0; m_active
= 0 >}
3142 | 83 when ctrl -> (* ctrl-S *)
3143 let active = source#calcactive
(getanchor
()) in
3144 let first = firstof m_first
active in
3145 G.postRedisplay "outline ctrl-s";
3146 coe {< m_first
= first; m_active
= active >}
3148 | 117 when ctrl -> (* ctrl-u *)
3149 G.postRedisplay "outline ctrl-u";
3150 if m_autonarrow
&& nonemptystr m_qsearch
3152 ignore
(source#renarrow
);
3153 settext m_autonarrow
"";
3154 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3157 source#del_narrow_pattern
;
3158 let pattern = source#renarrow
in
3160 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3162 settext m_autonarrow
text;
3163 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3166 | 108 when ctrl -> (* ctrl-l *)
3167 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3168 G.postRedisplay "outline ctrl-l";
3169 coe {< m_first
= first >}
3171 | 0xff09 when m_autonarrow
-> (* tab *)
3172 if nonemptystr m_qsearch
3174 G.postRedisplay "outline list view tab";
3175 source#add_narrow_pattern m_qsearch
;
3177 coe {< m_qsearch
= "" >}
3181 | 0xff1b when m_autonarrow
-> (* escape *)
3182 if nonemptystr m_qsearch
3183 then source#add_narrow_pattern m_qsearch
;
3186 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3187 if nonemptystr m_qsearch
3188 then source#add_narrow_pattern m_qsearch
;
3191 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3192 let pattern = m_qsearch ^ toutf8
key in
3193 G.postRedisplay "outlinelistview autonarrow add";
3194 source#narrow
pattern;
3195 settext true pattern;
3196 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3198 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3199 if emptystr m_qsearch
3202 let pattern = withoutlastutf8 m_qsearch
in
3203 G.postRedisplay "outlinelistview autonarrow backspace";
3204 ignore
(source#renarrow
);
3205 source#narrow
pattern;
3206 settext true pattern;
3207 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3209 | 0xff9f | 0xffff -> (* (kp) delete *)
3210 source#remove m_active
;
3211 G.postRedisplay "outline delete";
3212 let active = max
0 (m_active
-1) in
3213 coe {< m_first
= firstof m_first
active;
3214 m_active
= active >}
3216 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3217 navscroll (max
0 (m_first
- 1))
3219 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3220 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3222 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3223 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3224 | 0xff55 | 0xff9a -> (* (kp) prior *)
3225 navigate ~
-(fstate
.maxrows)
3226 | 0xff56 | 0xff9b -> (* (kp) next *)
3227 navigate fstate
.maxrows
3229 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3233 G.postRedisplay "outline ctrl right";
3234 {< m_pan
= m_pan
+ 1 >}
3236 else self#updownlevel
1
3240 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3244 G.postRedisplay "outline ctrl left";
3245 {< m_pan
= m_pan
- 1 >}
3247 else self#updownlevel ~
-1
3251 | 0xff50 | 0xff95 -> (* (kp) home *)
3252 G.postRedisplay "outline home";
3253 coe {< m_first
= 0; m_active
= 0 >}
3255 | 0xff57 | 0xff9c -> (* (kp) end *)
3256 let active = source#getitemcount
- 1 in
3257 let first = max
0 (active - fstate
.maxrows) in
3258 G.postRedisplay "outline end";
3259 coe {< m_active
= active; m_first
= first >}
3261 | _ -> super#
key key mask
3264 let gotounder under =
3265 let getpath filename
=
3267 if nonemptystr filename
3269 if Filename.is_relative filename
3271 let dir = Filename.dirname state
.path in
3273 if Filename.is_implicit
dir
3274 then Filename.concat
(Sys.getcwd
()) dir
3277 Filename.concat
dir filename
3281 if Sys.file_exists
path
3286 | Ulinkgoto
(pageno, top) ->
3290 gotopage1 pageno top;
3296 | Uremote
(filename
, pageno) ->
3297 let path = getpath filename
in
3302 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
3303 try popen
command []
3305 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
3308 let anchor = getanchor
() in
3309 let ranchor = state
.path, state
.password
, anchor, state
.origin
in
3311 state
.anchor <- (pageno, 0.0, 0.0);
3312 state
.ranchors
<- ranchor :: state
.ranchors
;
3315 else showtext '
!'
("Could not find " ^ filename
)
3317 | Uremotedest
(filename
, destname
) ->
3318 let path = getpath filename
in
3323 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
3324 try popen
command []
3327 "failed to execute `%s': %s\n" command (exntos exn
);
3330 let anchor = getanchor
() in
3331 let ranchor = state
.path, state
.password
, anchor, state
.origin
in
3333 state
.nameddest
<- destname
;
3334 state
.ranchors
<- ranchor :: state
.ranchors
;
3337 else showtext '
!'
("Could not find " ^ filename
)
3339 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
3342 let gotooutline (_, _, kind
) =
3346 let (pageno, y, _) = anchor in
3348 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3352 | Ouri
uri -> gotounder (Ulinkuri
uri)
3353 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
3354 | Oremote remote
-> gotounder (Uremote remote
)
3355 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
3358 let outlinesource usebookmarks
=
3361 inherit lvsourcebase
3362 val mutable m_items
= empty
3363 val mutable m_minfo
= empty
3364 val mutable m_orig_items
= empty
3365 val mutable m_orig_minfo
= empty
3366 val mutable m_narrow_patterns
= []
3367 val mutable m_hadremovals
= false
3368 val mutable m_gen
= -1
3370 method getitemcount
=
3371 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3374 if n == Array.length m_items
&& m_hadremovals
3376 ("[Confirm removal]", 0)
3378 let s, n, _ = m_items
.(n) in
3381 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3382 ignore
(uioh
, first);
3383 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3385 if m_narrow_patterns
= []
3386 then m_orig_items
, m_orig_minfo
3387 else m_items
, m_minfo
3391 if not
confrimremoval
3393 gotooutline m_items
.(active);
3398 state
.bookmarks
<- Array.to_list m_items
;
3399 m_orig_items
<- m_items
;
3400 m_orig_minfo
<- m_minfo
;
3410 method hasaction
_ = true
3413 if Array.length m_items
!= Array.length m_orig_items
3416 match m_narrow_patterns
with
3418 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
3420 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3424 match m_narrow_patterns
with
3427 | head
:: _ -> "\xe2\x80\xa6" ^ head
3429 method narrow
pattern =
3430 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3434 let rec loop accu minfo n =
3437 m_items
<- Array.of_list
accu;
3438 m_minfo
<- Array.of_list
minfo;
3441 let (s, _, _) as o = m_items
.(n) in
3444 try Str.search_forward
re s 0
3445 with Not_found
-> -1
3448 then o :: accu, (first, Str.match_end
()) :: minfo
3451 loop accu minfo (n-1)
3453 loop [] [] (Array.length m_items
- 1)
3455 method getminfo
= m_minfo
3460 then Array.of_list state
.bookmarks
3463 m_minfo
<- m_orig_minfo
;
3464 m_items
<- m_orig_items
3469 if m >= 0 && m < Array.length m_items
3471 m_hadremovals
<- true;
3472 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3473 let n = if n >= m then n+1 else n in
3478 method add_narrow_pattern
pattern =
3479 m_narrow_patterns
<- pattern :: m_narrow_patterns
3481 method del_narrow_pattern
=
3482 match m_narrow_patterns
with
3483 | _ :: rest
-> m_narrow_patterns
<- rest
3488 match m_narrow_patterns
with
3489 | pattern :: [] -> self#narrow
pattern; pattern
3491 List.fold_left
(fun accu pattern ->
3492 self#narrow
pattern;
3493 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
3495 method calcactive
anchor =
3496 let rely = getanchory anchor in
3497 let rec loop n best bestd
=
3498 if n = Array.length m_items
3501 let _, _, kind
= m_items
.(n) in
3504 let orely = getanchory anchor in
3505 let d = abs
(orely - rely) in
3508 else loop (n+1) best bestd
3509 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
3510 loop (n+1) best bestd
3514 method reset
anchor items =
3515 m_hadremovals
<- false;
3516 if state
.gen
!= m_gen
3518 m_orig_items
<- items;
3520 m_narrow_patterns
<- [];
3522 m_orig_minfo
<- empty;
3526 if items != m_orig_items
3528 m_orig_items
<- items;
3529 if m_narrow_patterns
== []
3530 then m_items
<- items;
3533 let active = self#calcactive
anchor in
3535 m_first
<- firstof m_first
active
3539 let enterselector usebookmarks
=
3541 let source = outlinesource usebookmarks
in
3545 then Array.of_list state
.bookmarks
3548 if Array.length
outlines = 0
3550 showtext ' ' errmsg
;
3553 state
.text <- source#greetmsg
;
3554 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3555 let anchor = getanchor
() in
3556 source#reset
anchor outlines;
3557 state
.uioh
<- coe (new outlinelistview ~
source);
3558 G.postRedisplay "enter selector";
3562 let enteroutlinemode =
3563 let f = enterselector false in
3564 fun () -> f "Document has no outline";
3567 let enterbookmarkmode =
3568 let f = enterselector true in
3569 fun () -> f "Document has no bookmarks (yet)";
3572 let makecheckers () =
3573 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3575 converted by Issac Trotts. July 25, 2002 *)
3576 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3577 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3578 let id = GlTex.gen_texture
() in
3579 GlTex.bind_texture `texture_2d
id;
3580 GlPix.store
(`unpack_alignment
1);
3581 GlTex.image2d
image;
3582 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3583 [ `mag_filter `nearest
; `min_filter `nearest
];
3587 let setcheckers enabled
=
3588 match state
.checkerstexid
with
3590 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3592 | Some checkerstexid
->
3595 GlTex.delete_texture checkerstexid
;
3596 state
.checkerstexid
<- None
;
3600 let describe_location () =
3601 let fn = page_of_y state
.y in
3602 let ln = page_of_y
(state
.y + state
.winh
- hscrollh () - 1) in
3603 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
3607 else (100. *. (float state
.y /. float maxy))
3611 Printf.sprintf
"page %d of %d [%.2f%%]"
3612 (fn+1) state
.pagecount
percent
3615 "pages %d-%d of %d [%.2f%%]"
3616 (fn+1) (ln+1) state
.pagecount
percent
3619 let setpresentationmode v
=
3620 let n = page_of_y state
.y in
3621 state
.anchor <- (n, 0.0, 1.0);
3622 conf
.presentation
<- v
;
3623 if conf
.fitmodel
= FitPage
3624 then reqlayout conf
.angle conf
.fitmodel
;
3629 let btos b = if b then "\xe2\x88\x9a" else "" in
3630 let showextended = ref false in
3631 let leave mode
= function
3632 | Confirm
-> state
.mode
<- mode
3633 | Cancel
-> state
.mode
<- mode
in
3636 val mutable m_first_time
= true
3637 val mutable m_l
= []
3638 val mutable m_a
= [||]
3639 val mutable m_prev_uioh
= nouioh
3640 val mutable m_prev_mode
= View
3642 inherit lvsourcebase
3644 method reset prev_mode prev_uioh
=
3645 m_a
<- Array.of_list
(List.rev m_l
);
3647 m_prev_mode
<- prev_mode
;
3648 m_prev_uioh
<- prev_uioh
;
3652 if n >= Array.length m_a
3656 | _, _, _, Action
_ -> m_active
<- n
3660 m_first_time
<- false;
3663 method int name get
set =
3665 (name
, `
int get
, 1, Action
(
3668 try set (int_of_string
s)
3670 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3674 let te = name ^
": ", "", None
, intentry, ondone, true in
3675 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3679 method int_with_suffix name get
set =
3681 (name
, `intws get
, 1, Action
(
3684 try set (int_of_string_with_suffix
s)
3686 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3691 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3693 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3697 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3699 (name
, `
bool (btos, get
), offset
, Action
(
3706 method color name get
set =
3708 (name
, `color get
, 1, Action
(
3710 let invalid = (nan
, nan
, nan
) in
3713 try color_of_string
s
3715 state
.text <- Printf.sprintf
"bad color `%s': %s"
3722 let te = name ^
": ", "", None
, textentry, ondone, true in
3723 state
.text <- color_to_string
(get
());
3724 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3728 method string name get
set =
3730 (name
, `
string get
, 1, Action
(
3732 let ondone s = set s in
3733 let te = name ^
": ", "", None
, textentry, ondone, true in
3734 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3738 method colorspace name get
set =
3740 (name
, `
string get
, 1, Action
(
3744 inherit lvsourcebase
3747 m_active
<- CSTE.to_int conf
.colorspace
;
3750 method getitemcount
=
3751 Array.length
CSTE.names
3754 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3755 ignore
(uioh
, first, pan
);
3756 if not cancel
then set active;
3758 method hasaction
_ = true
3762 let modehash = findkeyhash conf
"info" in
3763 coe (new listview ~helpmode
:false ~
source ~trusted
:true ~
modehash)
3766 method paxmark name get
set =
3768 (name
, `
string get
, 1, Action
(
3772 inherit lvsourcebase
3775 m_active
<- MTE.to_int conf
.paxmark
;
3778 method getitemcount
= Array.length
MTE.names
3779 method getitem
n = (MTE.names
.(n), 0)
3780 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3781 ignore
(uioh
, first, pan
);
3782 if not cancel
then set active;
3784 method hasaction
_ = true
3788 let modehash = findkeyhash conf
"info" in
3789 coe (new listview ~helpmode
:false ~
source ~trusted
:true ~
modehash)
3792 method fitmodel name get
set =
3794 (name
, `
string get
, 1, Action
(
3798 inherit lvsourcebase
3801 m_active
<- FMTE.to_int conf
.fitmodel
;
3804 method getitemcount
= Array.length
FMTE.names
3805 method getitem
n = (FMTE.names
.(n), 0)
3806 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3807 ignore
(uioh
, first, pan
);
3808 if not cancel
then set active;
3810 method hasaction
_ = true
3814 let modehash = findkeyhash conf
"info" in
3815 coe (new listview ~helpmode
:false ~
source ~trusted
:true ~
modehash)
3818 method caption
s offset
=
3819 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3821 method caption2
s f offset
=
3822 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3824 method getitemcount
= Array.length m_a
3827 let tostr = function
3828 | `
int f -> string_of_int
(f ())
3829 | `intws
f -> string_with_suffix_of_int
(f ())
3831 | `color
f -> color_to_string
(f ())
3832 | `
bool (btos, f) -> btos (f ())
3835 let name, t
, offset
, _ = m_a
.(n) in
3836 ((let s = tostr t
in
3838 then Printf.sprintf
"%s\t%s" name s
3842 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3847 match m_a
.(active) with
3848 | _, _, _, Action
f -> f uioh
3860 method hasaction
n =
3862 | _, _, _, Action
_ -> true
3866 let rec fillsrc prevmode prevuioh
=
3867 let sep () = src#caption
"" 0 in
3868 let colorp name get
set =
3870 (fun () -> color_to_string
(get
()))
3873 let c = color_of_string
v in
3876 state
.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
3879 let oldmode = state
.mode
in
3880 let birdseye = isbirdseye state
.mode
in
3882 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3884 src#
bool "presentation mode"
3885 (fun () -> conf
.presentation
)
3886 (fun v -> setpresentationmode v);
3888 src#
bool "ignore case in searches"
3889 (fun () -> conf
.icase
)
3890 (fun v -> conf
.icase
<- v);
3893 (fun () -> conf
.preload)
3894 (fun v -> conf
.preload <- v);
3896 src#
bool "highlight links"
3897 (fun () -> conf
.hlinks
)
3898 (fun v -> conf
.hlinks
<- v);
3900 src#
bool "under info"
3901 (fun () -> conf
.underinfo
)
3902 (fun v -> conf
.underinfo
<- v);
3904 src#
bool "persistent bookmarks"
3905 (fun () -> conf
.savebmarks
)
3906 (fun v -> conf
.savebmarks
<- v);
3908 src#fitmodel
"fit model"
3909 (fun () -> FMTE.to_string conf
.fitmodel
)
3910 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3912 src#
bool "trim margins"
3913 (fun () -> conf
.trimmargins
)
3914 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3916 src#
bool "persistent location"
3917 (fun () -> conf
.jumpback
)
3918 (fun v -> conf
.jumpback
<- v);
3921 src#
int "inter-page space"
3922 (fun () -> conf
.interpagespace
)
3924 conf
.interpagespace
<- n;
3925 docolumns conf
.columns
;
3927 match state
.layout with
3932 state
.maxy <- calcheight
();
3933 let y = getpagey
pageno in
3938 (fun () -> conf
.pagebias
)
3939 (fun v -> conf
.pagebias
<- v);
3941 src#
int "scroll step"
3942 (fun () -> conf
.scrollstep
)
3943 (fun n -> conf
.scrollstep
<- n);
3945 src#
int "horizontal scroll step"
3946 (fun () -> conf
.hscrollstep
)
3947 (fun v -> conf
.hscrollstep
<- v);
3949 src#
int "auto scroll step"
3951 match state
.autoscroll
with
3953 | _ -> conf
.autoscrollstep
)
3955 let n = boundastep state
.winh
n in
3956 if state
.autoscroll
<> None
3957 then state
.autoscroll
<- Some
n;
3958 conf
.autoscrollstep
<- n);
3961 (fun () -> truncate
(conf
.zoom *. 100.))
3962 (fun v -> setzoom ((float v) /. 100.));
3965 (fun () -> conf
.angle
)
3966 (fun v -> reqlayout v conf
.fitmodel
);
3968 src#
int "scroll bar width"
3969 (fun () -> conf
.scrollbw
)
3972 reshape state
.winw state
.winh
;
3975 src#
int "scroll handle height"
3976 (fun () -> conf
.scrollh
)
3977 (fun v -> conf
.scrollh
<- v;);
3979 src#
int "thumbnail width"
3980 (fun () -> conf
.thumbw
)
3982 conf
.thumbw
<- min
4096 v;
3985 leavebirdseye beye
false;
3990 let mode = state
.mode in
3991 src#
string "columns"
3993 match conf
.columns
with
3995 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3996 | Csplit
(count
, _) -> "-" ^ string_of_int count
3999 let n, a, b = multicolumns_of_string
v in
4000 setcolumns mode n a b);
4003 src#caption
"Pixmap cache" 0;
4004 src#int_with_suffix
"size (advisory)"
4005 (fun () -> conf
.memlimit
)
4006 (fun v -> conf
.memlimit
<- v);
4009 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4010 (string_with_suffix_of_int state
.memused
)
4011 (Hashtbl.length state
.tilemap
)) 1;
4014 src#caption
"Layout" 0;
4015 src#caption2
"Dimension"
4017 Printf.sprintf
"%dx%d (virtual %dx%d)"
4018 state
.winw state
.winh
4023 src#caption2
"Position" (fun () ->
4024 Printf.sprintf
"%dx%d" state
.x state
.y
4027 src#caption2
"Position" (fun () -> describe_location ()) 1
4031 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4032 "Save these parameters as global defaults at exit"
4033 (fun () -> conf
.bedefault
)
4034 (fun v -> conf
.bedefault
<- v)
4038 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4039 src#
bool ~offset
:0 ~
btos "Extended parameters"
4040 (fun () -> !showextended)
4041 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4045 (fun () -> conf
.checkers
)
4046 (fun v -> conf
.checkers
<- v; setcheckers v);
4047 src#
bool "update cursor"
4048 (fun () -> conf
.updatecurs
)
4049 (fun v -> conf
.updatecurs
<- v);
4050 src#
bool "scroll-bar on the left"
4051 (fun () -> conf
.leftscroll
)
4052 (fun v -> conf
.leftscroll
<- v);
4054 (fun () -> conf
.verbose
)
4055 (fun v -> conf
.verbose
<- v);
4056 src#
bool "invert colors"
4057 (fun () -> conf
.invert
)
4058 (fun v -> conf
.invert
<- v);
4060 (fun () -> conf
.maxhfit
)
4061 (fun v -> conf
.maxhfit
<- v);
4062 src#
bool "redirect stderr"
4063 (fun () -> conf
.redirectstderr)
4064 (fun v -> conf
.redirectstderr <- v; redirectstderr ());
4066 (fun () -> conf
.pax
!= None
)
4069 then conf
.pax
<- Some
(ref (now
(), 0, 0))
4070 else conf
.pax
<- None
);
4071 src#
string "uri launcher"
4072 (fun () -> conf
.urilauncher
)
4073 (fun v -> conf
.urilauncher
<- v);
4074 src#
string "path launcher"
4075 (fun () -> conf
.pathlauncher
)
4076 (fun v -> conf
.pathlauncher
<- v);
4077 src#
string "tile size"
4078 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
4081 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4082 conf
.tilew
<- max
64 w;
4083 conf
.tileh
<- max
64 h;
4086 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
4089 src#
int "texture count"
4090 (fun () -> conf
.texcount
)
4093 then conf
.texcount
<- v
4094 else showtext '
!'
" Failed to set texture count please retry later"
4096 src#
int "slice height"
4097 (fun () -> conf
.sliceheight
)
4099 conf
.sliceheight
<- v;
4100 wcmd "sliceh %d" conf
.sliceheight
;
4102 src#
int "anti-aliasing level"
4103 (fun () -> conf
.aalevel
)
4105 conf
.aalevel
<- bound
v 0 8;
4106 state
.anchor <- getanchor
();
4107 opendoc state
.path state
.password
;
4109 src#
string "page scroll scaling factor"
4110 (fun () -> string_of_float conf
.pgscale)
4113 let s = float_of_string
v in
4116 state
.text <- Printf.sprintf
4117 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4120 src#
int "ui font size"
4121 (fun () -> fstate
.fontsize
)
4122 (fun v -> setfontsize (bound
v 5 100));
4123 src#
int "hint font size"
4124 (fun () -> conf
.hfsize
)
4125 (fun v -> conf
.hfsize
<- bound
v 5 100);
4126 colorp "background color"
4127 (fun () -> conf
.bgcolor
)
4128 (fun v -> conf
.bgcolor
<- v);
4129 src#
bool "crop hack"
4130 (fun () -> conf
.crophack
)
4131 (fun v -> conf
.crophack
<- v);
4132 src#
string "trim fuzz"
4133 (fun () -> irect_to_string conf
.trimfuzz
)
4136 conf
.trimfuzz
<- irect_of_string
v;
4138 then settrim true conf
.trimfuzz
;
4140 state
.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4142 src#
string "throttle"
4144 match conf
.maxwait
with
4145 | None
-> "show place holder if page is not ready"
4148 then "wait for page to fully render"
4150 "wait " ^ string_of_float
time
4151 ^
" seconds before showing placeholder"
4155 let f = float_of_string
v in
4157 then conf
.maxwait
<- None
4158 else conf
.maxwait
<- Some
f
4160 state
.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4162 src#
string "ghyll scroll"
4164 match conf
.ghyllscroll
with
4166 | Some nab
-> ghyllscroll_to_string nab
4169 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
4171 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4173 src#
string "selection command"
4174 (fun () -> conf
.selcmd
)
4175 (fun v -> conf
.selcmd
<- v);
4176 src#
string "synctex command"
4177 (fun () -> conf
.stcmd
)
4178 (fun v -> conf
.stcmd
<- v);
4179 src#
string "pax command"
4180 (fun () -> conf
.paxcmd
)
4181 (fun v -> conf
.paxcmd
<- v);
4182 src#colorspace
"color space"
4183 (fun () -> CSTE.to_string conf
.colorspace
)
4185 conf
.colorspace
<- CSTE.of_int
v;
4189 src#paxmark
"pax mark method"
4190 (fun () -> MTE.to_string conf
.paxmark
)
4191 (fun v -> conf
.paxmark
<- MTE.of_int
v);
4195 (fun () -> conf
.usepbo
)
4196 (fun v -> conf
.usepbo
<- v);
4197 src#
bool "mouse wheel scrolls pages"
4198 (fun () -> conf
.wheelbypage
)
4199 (fun v -> conf
.wheelbypage
<- v);
4200 src#
bool "open remote links in a new instance"
4201 (fun () -> conf
.riani
)
4202 (fun v -> conf
.riani
<- v);
4206 src#caption
"Document" 0;
4207 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
4208 src#caption2
"Pages"
4209 (fun () -> string_of_int state
.pagecount
) 1;
4210 src#caption2
"Dimensions"
4211 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4215 src#caption
"Trimmed margins" 0;
4216 src#caption2
"Dimensions"
4217 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4221 src#caption
"OpenGL" 0;
4222 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4223 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4226 src#caption
"Location" 0;
4227 if nonemptystr state
.origin
4228 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
4229 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
4231 src#reset prevmode prevuioh
;
4236 let prevmode = state
.mode
4237 and prevuioh
= state
.uioh in
4238 fillsrc prevmode prevuioh
;
4239 let source = (src :> lvsource
) in
4240 let modehash = findkeyhash conf
"info" in
4241 state
.uioh <- coe (object (self)
4242 inherit listview ~helpmode
:false ~
source ~trusted
:true ~
modehash as super
4243 val mutable m_prevmemused
= 0
4244 method infochanged
= function
4246 if m_prevmemused
!= state
.memused
4248 m_prevmemused
<- state
.memused
;
4249 G.postRedisplay "memusedchanged";
4251 | Pdim
-> G.postRedisplay "pdimchanged"
4252 | Docinfo
-> fillsrc prevmode prevuioh
4254 method key key mask
=
4255 if not
(Wsi.withctrl mask
)
4258 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4259 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4260 | _ -> super#
key key mask
4261 else super#
key key mask
4263 G.postRedisplay "info";
4269 inherit lvsourcebase
4270 method getitemcount
= Array.length state
.help
4272 let s, l, _ = state
.help
.(n) in
4275 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4279 match state
.help
.(active) with
4280 | _, _, Action
f -> Some
(f uioh)
4290 method hasaction
n =
4291 match state
.help
.(n) with
4292 | _, _, Action
_ -> true
4299 let modehash = findkeyhash conf
"help" in
4301 state
.uioh <- coe (new listview
4302 ~helpmode
:true ~
source ~trusted
:true ~
modehash);
4303 G.postRedisplay "help";
4308 let re = Str.regexp
"[\r\n]" in
4310 inherit lvsourcebase
4311 val mutable m_items
= [||]
4313 method getitemcount
= 1 + Array.length m_items
4318 else m_items
.(n-1), 0
4320 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4325 then Buffer.clear state
.errmsgs
;
4332 method hasaction
n =
4336 state
.newerrmsgs
<- false;
4337 let l = Str.split
re (Buffer.contents state
.errmsgs
) in
4338 m_items
<- Array.of_list
l
4347 let source = (msgsource :> lvsource
) in
4348 let modehash = findkeyhash conf
"listview" in
4349 state
.uioh <- coe (object
4350 inherit listview ~helpmode
:false ~
source ~trusted
:false ~
modehash as super
4353 then msgsource#reset
;
4356 G.postRedisplay "msgs";
4359 let quickbookmark ?title
() =
4360 match state
.layout with
4366 let tm = Unix.localtime
(now
()) in
4367 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4371 (tm.Unix.tm_year
+ 1900)
4374 | Some
title -> title
4376 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4379 let setautoscrollspeed step goingdown
=
4380 let incr = max
1 ((abs step
) / 2) in
4381 let incr = if goingdown
then incr else -incr in
4382 let astep = boundastep state
.winh
(step
+ incr) in
4383 state
.autoscroll
<- Some
astep;
4387 match conf
.columns
with
4389 | _ -> state
.x != 0 || conf
.zoom > 1.0
4392 let panbound x = bound
x (-state
.w) (wadjsb state
.winw
);;
4394 let existsinrow pageno (columns
, coverA
, coverB
) p =
4395 let last = ((pageno - coverA
) mod columns
) + columns
in
4396 let rec any = function
4399 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4403 then (if l.pageno = last then false else any rest
)
4411 match state
.layout with
4413 let pageno = page_of_y state
.y in
4414 gotoghyll (getpagey
(pageno+1))
4416 match conf
.columns
with
4418 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4420 let y = clamp (pgscale state
.winh
) in
4423 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4424 gotoghyll (getpagey
pageno)
4425 | Cmulti
((c, _, _) as cl, _) ->
4426 if conf
.presentation
4427 && (existsinrow l.pageno cl
4428 (fun l -> l.pageh
> l.pagey + l.pagevh))
4430 let y = clamp (pgscale state
.winh
) in
4433 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4434 gotoghyll (getpagey
pageno)
4436 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4438 let pagey, pageh
= getpageyh
l.pageno in
4439 let pagey = pagey + pageh
* l.pagecol
in
4440 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4441 gotoghyll (pagey + pageh
+ ips)
4445 match state
.layout with
4447 let pageno = page_of_y state
.y in
4448 gotoghyll (getpagey
(pageno-1))
4450 match conf
.columns
with
4452 if conf
.presentation
&& l.pagey != 0
4454 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4456 let pageno = max
0 (l.pageno-1) in
4457 gotoghyll (getpagey
pageno)
4458 | Cmulti
((c, _, coverB
) as cl, _) ->
4459 if conf
.presentation
&&
4460 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4462 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4465 if l.pageno = state
.pagecount
- coverB
4469 let pageno = max
0 (l.pageno-decr) in
4470 gotoghyll (getpagey
pageno)
4478 let pageno = max
0 (l.pageno-1) in
4479 let pagey, pageh
= getpageyh
pageno in
4482 let pagey, pageh
= getpageyh
l.pageno in
4483 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4488 let viewkeyboard key mask
=
4490 let mode = state
.mode in
4491 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4494 G.postRedisplay "view:enttext"
4496 let ctrl = Wsi.withctrl mask
in
4498 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4504 | 0xff63 -> (* insert *)
4505 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4507 state
.mode <- LinkNav
(Ltgendir
0);
4510 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4512 | 0xff1b | 113 -> (* escape / q *)
4513 begin match state
.mstate
with
4516 G.postRedisplay "kill zoom rect";
4518 begin match state
.mode with
4521 G.postRedisplay "esc leave linknav"
4523 match state
.ranchors
with
4525 | (path, password
, anchor, origin
) :: rest
->
4526 state
.ranchors
<- rest
;
4527 state
.anchor <- anchor;
4528 state
.origin
<- origin
;
4529 state
.nameddest
<- "";
4530 opendoc path password
4534 | 0xff08 -> (* backspace *)
4535 gotoghyll (getnav ~
-1)
4543 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
;
4544 G.postRedisplay "dehighlight";
4546 | 47 | 63 -> (* / ? *)
4547 let ondone isforw
s =
4548 cbput state
.hists
.pat
s;
4549 state
.searchpattern
<- s;
4552 let s = String.create
1 in
4553 s.[0] <- Char.chr
key;
4554 enttext (s, "", Some
(onhist state
.hists
.pat
),
4555 textentry, ondone (key = 47), true)
4557 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4558 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4559 setzoom (conf
.zoom +. incr)
4561 | 43 | 0xffab -> (* + *)
4564 try int_of_string
s with exc
->
4565 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4571 state
.text <- "page bias is now " ^ string_of_int
n;
4574 enttext ("page bias: ", "", None
, intentry, ondone, true)
4576 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4577 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4578 setzoom (max
0.01 (conf
.zoom -. decr))
4580 | 45 | 0xffad -> (* - *)
4581 let ondone msg
= state
.text <- msg
in
4583 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
4584 optentry state
.mode, ondone, true
4587 | 48 when ctrl -> (* ctrl-0 *)
4595 | (49 | 50) when ctrl && conf
.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
4597 match conf
.columns
with
4598 | Csingle
_ | Cmulti
_ -> 1
4599 | Csplit
(n, _) -> n
4601 let h = state
.winh
-
4602 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4604 let zoom = zoomforh state
.winw
h (vscrollw ()) cols in
4605 if zoom > 0.0 && (key = 50 || zoom < 1.0)
4608 | 51 when ctrl -> (* ctrl-3 *)
4610 match conf
.fitmodel
with
4611 | FitWidth
-> FitProportional
4612 | FitProportional
-> FitPage
4613 | FitPage
-> FitWidth
4615 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4616 reqlayout conf
.angle
fm
4618 | 0xffc6 -> (* f9 *)
4621 | 57 when ctrl -> (* ctrl-9 *)
4624 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4625 when not
ctrl -> (* 0..9 *)
4628 try int_of_string
s with exc
->
4629 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4635 cbput state
.hists
.pag
(string_of_int
n);
4636 gotopage1 (n + conf
.pagebias
- 1) 0;
4639 let pageentry text key =
4640 match Char.unsafe_chr
key with
4641 | '
g'
-> TEdone
text
4642 | _ -> intentry text key
4644 let text = "x" in text.[0] <- Char.chr
key;
4645 enttext (":", text, Some
(onhist state
.hists
.pag
), pageentry, ondone, true)
4648 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4649 reshape state
.winw state
.winh
;
4652 state
.bzoom
<- not state
.bzoom
;
4654 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4657 conf
.hlinks
<- not conf
.hlinks
;
4658 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4659 G.postRedisplay "toggle highlightlinks";
4662 state
.glinks
<- true;
4663 let mode = state
.mode in
4664 state
.mode <- Textentry
(
4665 (":", "", None
, linknentry, linkndone gotounder, false),
4667 state
.glinks
<- false;
4671 G.postRedisplay "view:linkent(F)"
4674 state
.glinks
<- true;
4675 let mode = state
.mode in
4676 state
.mode <- Textentry
(
4678 ":", "", None
, linknentry, linkndone (fun under ->
4679 selstring (undertext under);
4683 state
.glinks
<- false;
4687 G.postRedisplay "view:linkent"
4690 begin match state
.autoscroll
with
4692 conf
.autoscrollstep
<- step
;
4693 state
.autoscroll
<- None
4695 if conf
.autoscrollstep
= 0
4696 then state
.autoscroll
<- Some
1
4697 else state
.autoscroll
<- Some conf
.autoscrollstep
4700 | 112 when ctrl -> (* ctrl-p *)
4704 setpresentationmode (not conf
.presentation
);
4705 showtext ' '
("presentation mode " ^
4706 if conf
.presentation
then "on" else "off");
4709 if List.mem
Wsi.Fullscreen state
.winstate
4710 then Wsi.reshape conf
.cwinw conf
.cwinh
4711 else Wsi.fullscreen
()
4713 | 112 | 78 -> (* p|N *)
4714 search state
.searchpattern
false
4716 | 110 | 0xffc0 -> (* n|F3 *)
4717 search state
.searchpattern
true
4720 begin match state
.layout with
4723 gotoghyll (getpagey
l.pageno)
4729 | 0xff9f | 0xffff -> (* delete *)
4733 showtext ' '
(describe_location ());
4736 begin match state
.layout with
4739 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
4744 enterbookmarkmode ()
4746 | 104 | 0xffbe -> (* h|F1 *)
4752 | 101 when Buffer.length state
.errmsgs
> 0 -> (* e *)
4757 match state
.layout with
4762 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4765 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4769 showtext ' '
"Quick bookmark added";
4772 begin match state
.layout with
4774 let rect = getpdimrect
l.pagedimno
in
4778 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4779 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4781 (truncate
(rect.(1) -. rect.(0)),
4782 truncate
(rect.(3) -. rect.(0)))
4784 let w = truncate
((float w)*.conf
.zoom)
4785 and h = truncate
((float h)*.conf
.zoom) in
4788 state
.anchor <- getanchor
();
4789 Wsi.reshape (w + vscrollw ()) (h + conf
.interpagespace
)
4791 G.postRedisplay "z";
4798 | 60 | 62 -> (* < > *)
4799 reqlayout (conf
.angle
+ (if key = 62 then 30 else -30)) conf
.fitmodel
4801 | 91 | 93 -> (* [ ] *)
4803 bound
(conf
.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4805 G.postRedisplay "brightness";
4807 | 99 when state
.mode = View
-> (* [alt-]c *)
4812 let m = (wadjsb state
.winw
- state
.w) / 2 in
4814 gotoy_and_clear_text state
.y
4818 match state
.prevcolumns
with
4819 | None
-> (1, 0, 0), 1.0
4820 | Some
(columns
, z
) ->
4823 | Csplit
(c, _) -> -c, 0, 0
4824 | Cmulti
((c, a, b), _) -> c, a, b
4825 | Csingle
_ -> 1, 0, 0
4829 setcolumns View
c a b;
4832 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
4833 -> (* ctrl-shift- (kp) [up|down] *)
4834 let zoom, x = state
.prevzoom
in
4838 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
4839 begin match state
.autoscroll
with
4841 begin match state
.mode with
4842 | Birdseye beye
-> upbirdseye 1 beye
4845 then gotoy_and_clear_text (clamp ~
-(state
.winh
/2))
4847 if not
(Wsi.withshift mask
) && conf
.presentation
4849 else gotoghyll1 true (clamp (-conf
.scrollstep
))
4853 setautoscrollspeed n false
4856 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
4857 begin match state
.autoscroll
with
4859 begin match state
.mode with
4860 | Birdseye beye
-> downbirdseye 1 beye
4863 then gotoy_and_clear_text (clamp (state
.winh
/2))
4865 if not
(Wsi.withshift mask
) && conf
.presentation
4867 else gotoghyll1 true (clamp (conf
.scrollstep
))
4871 setautoscrollspeed n true
4874 | 0xff51 | 0xff53 | 0xff96 | 0xff98
4875 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
4881 else conf
.hscrollstep
4883 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
4884 state
.x <- panbound (state
.x + dx);
4885 gotoy_and_clear_text state
.y
4888 G.postRedisplay "left/right"
4891 | 0xff55 | 0xff9a -> (* (kp) prior *)
4895 match state
.layout with
4897 | l :: _ -> state
.y - l.pagey
4899 clamp (pgscale (-state
.winh
))
4903 | 0xff56 | 0xff9b -> (* (kp) next *)
4907 match List.rev state
.layout with
4909 | l :: _ -> getpagey
l.pageno
4911 clamp (pgscale state
.winh
)
4915 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
4917 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
4918 gotoghyll (clamp state
.maxy)
4921 when Wsi.withalt mask
-> (* alt-(kp) right *)
4922 gotoghyll (getnav 1)
4924 when Wsi.withalt mask
-> (* alt-(kp) left *)
4925 gotoghyll (getnav ~
-1)
4930 | 118 when conf
.debug
-> (* v *)
4933 match getopaque l.pageno with
4936 let x0, y0, x1, y1 = pagebbox
opaque in
4937 let a,b = float x0, float y0 in
4938 let c,d = float x1, float y0 in
4939 let e,f = float x1, float y1 in
4940 let h,j
= float x0, float y1 in
4941 let rect = (a,b,c,d,e,f,h,j
) in
4943 state
.rects
<- (l.pageno, l.pageno mod 3, rect) :: state
.rects
;
4945 G.postRedisplay "v";
4948 let mode = state
.mode in
4950 let onleave = function
4951 | Cancel
-> state
.mode <- mode
4954 match getopaque l.pageno with
4955 | Some
opaque -> pipesel opaque !cmd
4956 | None
-> ()) state
.layout;
4960 cbput state
.hists
.sel
s;
4964 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
4966 G.postRedisplay "|";
4967 state
.mode <- Textentry
(te, onleave);
4970 vlog "huh? %s" (Wsi.keyname
key)
4973 let linknavkeyboard key mask
linknav =
4974 let getpage pageno =
4975 let rec loop = function
4977 | l :: _ when l.pageno = pageno -> Some
l
4978 | _ :: rest
-> loop rest
4979 in loop state
.layout
4981 let doexact (pageno, n) =
4982 match getopaque pageno, getpage pageno with
4983 | Some
opaque, Some
l ->
4984 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
4986 let under = getlink
opaque n in
4987 G.postRedisplay "link gotounder";
4993 | 0xff50 -> (* home *)
4994 Some
(findlink
opaque LDfirst
), -1
4996 | 0xff57 -> (* end *)
4997 Some
(findlink
opaque LDlast
), 1
4999 | 0xff51 -> (* left *)
5000 Some
(findlink
opaque (LDleft
n)), -1
5002 | 0xff53 -> (* right *)
5003 Some
(findlink
opaque (LDright
n)), 1
5005 | 0xff52 -> (* up *)
5006 Some
(findlink
opaque (LDup
n)), -1
5008 | 0xff54 -> (* down *)
5009 Some
(findlink
opaque (LDdown
n)), 1
5014 begin match findpwl
l.pageno dir with
5018 state
.mode <- LinkNav
(Ltgendir
dir);
5019 let y, h = getpageyh
pageno in
5022 then y + h - state
.winh
5027 begin match getopaque pageno, getpage pageno with
5028 | Some
opaque, Some
_ ->
5030 let ld = if dir > 0 then LDfirst
else LDlast
in
5033 begin match link with
5035 showlinktype (getlink
opaque m);
5036 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5037 G.postRedisplay "linknav jpage";
5044 begin match opt with
5045 | Some Lnotfound
-> pwl l dir;
5046 | Some
(Lfound
m) ->
5050 let _, y0, _, y1 = getlinkrect
opaque m in
5052 then gotopage1 l.pageno y0
5054 let d = fstate
.fontsize
+ 1 in
5055 if y1 - l.pagey > l.pagevh - d
5056 then gotopage1 l.pageno (y1 - state
.winh
- hscrollh () + d)
5057 else G.postRedisplay "linknav";
5059 showlinktype (getlink
opaque m);
5060 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5063 | None
-> viewkeyboard key mask
5065 | _ -> viewkeyboard key mask
5070 G.postRedisplay "leave linknav"
5074 | Ltgendir
_ -> viewkeyboard key mask
5075 | Ltexact exact
-> doexact exact
5078 let keyboard key mask
=
5079 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state
.mode)
5080 then wcmd "interrupt"
5081 else state
.uioh <- state
.uioh#
key key mask
5084 let birdseyekeyboard key mask
5085 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5087 match conf
.columns
with
5089 | Cmulti
((c, _, _), _) -> c
5090 | Csplit
_ -> failwith
"bird's eye split mode"
5092 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state
.winh
layout in
5094 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5095 let y, h = getpageyh
pageno in
5096 let top = (state
.winh
- h) / 2 in
5097 gotoy (max
0 (y - top))
5098 | 0xff0d (* enter *)
5099 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5100 | 0xff1b -> leavebirdseye beye
true (* escape *)
5101 | 0xff52 -> upbirdseye incr beye
(* up *)
5102 | 0xff54 -> downbirdseye incr beye
(* down *)
5103 | 0xff51 -> upbirdseye 1 beye
(* left *)
5104 | 0xff53 -> downbirdseye 1 beye
(* right *)
5106 | 0xff55 -> (* prior *)
5107 begin match state
.layout with
5111 state
.mode <- Birdseye
(
5112 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5114 gotopage1 l.pageno 0;
5117 let layout = layout (state
.y-state
.winh
) (pgh state
.layout) in
5119 | [] -> gotoy (clamp (-state
.winh
))
5121 state
.mode <- Birdseye
(
5122 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5124 gotopage1 l.pageno 0
5127 | [] -> gotoy (clamp (-state
.winh
))
5130 | 0xff56 -> (* next *)
5131 begin match List.rev state
.layout with
5133 let layout = layout (state
.y + (pgh state
.layout)) state
.winh
in
5134 begin match layout with
5136 let incr = l.pageh
- l.pagevh in
5141 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5143 G.postRedisplay "birdseye pagedown";
5145 else gotoy (clamp (incr + conf
.interpagespace
*2));
5149 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5150 gotopage1 l.pageno 0;
5153 | [] -> gotoy (clamp state
.winh
)
5156 | 0xff50 -> (* home *)
5157 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5160 | 0xff57 -> (* end *)
5161 let pageno = state
.pagecount
- 1 in
5162 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5163 if not
(pagevisible state
.layout pageno)
5166 match List.rev state
.pdims
with
5168 | (_, _, h, _) :: _ -> h
5170 gotoy (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5171 else G.postRedisplay "birdseye end";
5172 | _ -> viewkeyboard key mask
5177 match state
.mode with
5178 | Textentry
_ -> scalecolor 0.4
5180 | View
-> scalecolor 1.0
5181 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5182 if l.pageno = hooverpageno
5185 if l.pageno = pageno
5193 let postdrawpage l linkindexbase
=
5194 match getopaque l.pageno with
5196 if tileready l l.pagex
l.pagey
5198 let x = l.pagedispx - l.pagex
5199 and y = l.pagedispy - l.pagey in
5201 match conf
.columns
with
5202 | Csingle
_ | Cmulti
_ ->
5203 (if conf
.hlinks
then 1 else 0)
5205 && not
(isbirdseye state
.mode) then 2 else 0)
5209 match state
.mode with
5210 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5213 postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
);
5218 let scrollindicator () =
5219 let sbw, ph
, sh = state
.uioh#
scrollph in
5220 let sbh, pw, sw = state
.uioh#scrollpw
in
5225 else (state
.winw
- sbw), state
.winw
5228 GlDraw.color (0.64, 0.64, 0.64);
5229 filledrect (float x0) 0. (float x1) (float state
.winh
);
5231 0. (float (state
.winh
- sbh))
5232 (float (wadjsb state
.winw
- 1)) (float state
.winh
)
5234 GlDraw.color (0.0, 0.0, 0.0);
5236 filledrect (float x0) ph
(float x1) (ph
+. sh);
5237 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5241 match state
.mstate
with
5242 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5245 | Msel
((x0, y0), (x1, y1)) ->
5246 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5247 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< "", -1, 0, 0) in
5248 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< "", -1, 0, 0) in
5249 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5252 let showrects = function [] -> () | rects
->
5254 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5255 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5257 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5259 if l.pageno = pageno
5261 let dx = float (l.pagedispx - l.pagex
) in
5262 let dy = float (l.pagedispy - l.pagey) in
5263 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5264 Raw.sets_float state
.vraw ~pos
:0
5269 GlArray.vertex `two state
.vraw
;
5270 GlArray.draw_arrays `triangle_strip
0 4;
5279 GlClear.color (scalecolor2 conf
.bgcolor
);
5280 GlClear.clear
[`
color];
5281 List.iter
drawpage state
.layout;
5283 match state
.mode with
5284 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5285 begin match getopaque pageno with
5287 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5294 | None
-> state
.rects
5299 let rec postloop linkindexbase
= function
5301 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5302 postloop linkindexbase rest
5306 postloop 0 state
.layout;
5308 begin match state
.mstate
with
5309 | Mzoomrect
((x0, y0), (x1, y1)) ->
5311 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5312 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5313 filledrect (float x0) (float y0) (float x1) (float y1);
5322 let zoomrect x y x1 y1 =
5325 and y0 = min
y y1 in
5326 gotoy (state
.y + y0);
5327 state
.anchor <- getanchor
();
5328 let zoom = (float state
.w) /. float (x1 - x0) in
5330 match conf
.fitmodel
, conf
.columns
with
5331 | FitPage
, Csplit
_ ->
5332 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5335 let adjw = wadjsb state
.winw
in
5337 then (adjw - state
.w) / 2
5340 state
.x <- (state
.x + margin) - x0;
5346 let g opaque l px py =
5347 match rectofblock
opaque px py with
5349 let x0 = a.(0) -. 20. in
5350 let x1 = a.(1) +. 20. in
5351 let y0 = a.(2) -. 20. in
5352 let zoom = (float state
.w) /. (x1 -. x0) in
5353 let pagey = getpagey
l.pageno in
5354 gotoy_and_clear_text (pagey + truncate
y0);
5355 state
.anchor <- getanchor
();
5356 let margin = (state
.w - l.pagew
)/2 in
5357 state
.x <- -truncate
x0 - margin;
5362 match conf
.columns
with
5364 showtext '
!'
"block zooming does not work properly in split columns mode"
5365 | _ -> onppundermouse g x y ()
5369 let winw = wadjsb state
.winw - 1 in
5370 let s = float x /. float winw in
5371 let destx = truncate
(float (state
.w + winw) *. s) in
5372 state
.x <- winw - destx;
5373 gotoy_and_clear_text state
.y;
5374 state
.mstate
<- Mscrollx
;
5378 let s = float y /. float state
.winh
in
5379 let desty = truncate
(float (state
.maxy - state
.winh
) *. s) in
5380 gotoy_and_clear_text desty;
5381 state
.mstate
<- Mscrolly
;
5384 let viewmulticlick clicks
x y mask
=
5385 let g opaque l px py =
5393 if markunder
opaque px py mark
5397 match getopaque l.pageno with
5399 | Some
opaque -> pipesel opaque cmd
5401 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5402 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5407 G.postRedisplay "viewmulticlick";
5408 onppundermouse g x y (fun () -> showtext '
!'
"Nothing to select") ();
5412 match conf
.columns
with
5414 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5417 let viewmouse button down
x y mask
=
5419 | n when (n == 4 || n == 5) && not down
->
5420 if Wsi.withctrl mask
5422 match state
.mstate
with
5423 | Mzoom
(oldn
, i
) ->
5431 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5433 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5435 let zoom = conf
.zoom -. incr in
5437 state
.mstate
<- Mzoom
(n, 0);
5439 state
.mstate
<- Mzoom
(n, i
+1);
5441 else state
.mstate
<- Mzoom
(n, 0)
5443 | _ -> state
.mstate
<- Mzoom
(n, 0)
5446 match state
.autoscroll
with
5447 | Some step
-> setautoscrollspeed step
(n=4)
5449 if conf
.wheelbypage
|| conf
.presentation
5458 then -conf
.scrollstep
5459 else conf
.scrollstep
5461 let incr = incr * 2 in
5462 let y = clamp incr in
5463 gotoy_and_clear_text y
5466 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5468 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
);
5469 gotoy_and_clear_text state
.y
5471 | 1 when Wsi.withshift mask
->
5472 state
.mstate
<- Mnone
;
5475 match unproject x y with
5476 | Some
(pageno, ux
, uy
) ->
5477 let cmd = Printf.sprintf
5479 conf
.stcmd state
.path pageno ux uy
5485 | 1 when Wsi.withctrl mask
->
5488 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5489 state
.mstate
<- Mpan
(x, y)
5492 state
.mstate
<- Mnone
5497 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5499 state
.mstate
<- Mzoomrect
(p, p)
5502 match state
.mstate
with
5503 | Mzoomrect
((x0, y0), _) ->
5504 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5505 then zoomrect x0 y0 x y
5508 G.postRedisplay "kill accidental zoom rect";
5514 | 1 when x > state
.winw - vscrollw () ->
5517 let _, position, sh = state
.uioh#
scrollph in
5518 if y > truncate
position && y < truncate
(position +. sh)
5519 then state
.mstate
<- Mscrolly
5522 state
.mstate
<- Mnone
5524 | 1 when y > state
.winh
- hscrollh () ->
5527 let _, position, sw = state
.uioh#scrollpw
in
5528 if x > truncate
position && x < truncate
(position +. sw)
5529 then state
.mstate
<- Mscrollx
5532 state
.mstate
<- Mnone
5534 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5537 let dest = if down
then getunder x y else Unone
in
5538 begin match dest with
5541 | Uremote
_ | Uremotedest
_
5542 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5545 | Unone
when down
->
5546 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5547 state
.mstate
<- Mpan
(x, y);
5549 | Unone
| Utext
_ ->
5554 state
.mstate
<- Msel
((x, y), (x, y));
5555 G.postRedisplay "mouse select";
5559 match state
.mstate
with
5562 | Mzoom
_ | Mscrollx
| Mscrolly
->
5563 state
.mstate
<- Mnone
5565 | Mzoomrect
((x0, y0), _) ->
5569 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5570 state
.mstate
<- Mnone
5572 | Msel
((x0, y0), (x1, y1)) ->
5573 let rec loop = function
5577 let a0 = l.pagedispy in
5578 let a1 = a0 + l.pagevh in
5579 let b0 = l.pagedispx in
5580 let b1 = b0 + l.pagevw in
5581 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5582 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5586 match getopaque l.pageno with
5589 match Ne.res Unix.pipe
with
5593 "can not create sel pipe: %s"
5597 Ne.clo fd
(fun msg
->
5598 dolog
"%s close failed: %s" what msg
)
5601 try popen
cmd [r, 0; w, -1]; true
5603 dolog
"can not execute %S: %s"
5610 G.postRedisplay "copysel";
5612 else clo "Msel pipe/w" w;
5613 clo "Msel pipe/r" r;
5615 dosel conf
.selcmd
();
5616 state
.roam
<- dosel conf
.paxcmd
;
5628 let birdseyemouse button down
x y mask
5629 (conf
, leftx
, _, hooverpageno
, anchor) =
5632 let rec loop = function
5635 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5636 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5638 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5644 | _ -> viewmouse button down
x y mask
5650 method key key mask
=
5651 begin match state
.mode with
5652 | Textentry
textentry -> textentrykeyboard key mask
textentry
5653 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5654 | View
-> viewkeyboard key mask
5655 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5659 method button button bstate
x y mask
=
5660 begin match state
.mode with
5662 | View
-> viewmouse button bstate
x y mask
5663 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5668 method multiclick clicks
x y mask
=
5669 begin match state
.mode with
5671 | View
-> viewmulticlick clicks
x y mask
5678 begin match state
.mode with
5680 | View
| Birdseye
_ | LinkNav
_ ->
5681 match state
.mstate
with
5682 | Mzoom
_ | Mnone
-> ()
5687 state
.mstate
<- Mpan
(x, y);
5689 then state
.x <- panbound (state
.x + dx);
5691 gotoy_and_clear_text y
5694 state
.mstate
<- Msel
(a, (x, y));
5695 G.postRedisplay "motion select";
5698 let y = min state
.winh
(max
0 y) in
5702 let x = min state
.winw (max
0 x) in
5705 | Mzoomrect
(p0
, _) ->
5706 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5707 G.postRedisplay "motion zoomrect";
5711 method pmotion
x y =
5712 begin match state
.mode with
5713 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
5714 let rec loop = function
5716 if hooverpageno
!= -1
5718 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
5719 G.postRedisplay "pmotion birdseye no hoover";
5722 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5723 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5725 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
5726 G.postRedisplay "pmotion birdseye hoover";
5736 match state
.mstate
with
5737 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5746 let past, _, _ = !r in
5748 let delta = now -. past in
5751 else r := (now, x, y)
5755 method infochanged
_ = ()
5758 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
5761 then 0.0, float state
.winh
5762 else scrollph state
.y maxy
5767 let winw = wadjsb state
.winw in
5768 let fwinw = float winw in
5770 let sw = fwinw /. float state
.w in
5771 let sw = fwinw *. sw in
5772 max
sw (float conf
.scrollh
)
5775 let maxx = state
.w + winw in
5776 let x = winw - state
.x in
5777 let percent = float x /. float maxx in
5778 (fwinw -. sw) *. percent
5780 hscrollh (), position, sw
5784 match state
.mode with
5785 | LinkNav
_ -> "links"
5786 | Textentry
_ -> "textentry"
5787 | Birdseye
_ -> "birdseye"
5790 findkeyhash conf
modename
5792 method eformsgs
= true
5795 let adderrmsg src msg
=
5796 Buffer.add_string state
.errmsgs msg
;
5797 state
.newerrmsgs
<- true;
5801 let adderrfmt src fmt
=
5802 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
5806 let cl = splitatspace cmds
in
5808 try Scanf.sscanf
s fmt
f
5810 adderrfmt "remote exec"
5811 "error processing '%S': %s\n" cmds
(exntos exn
)
5814 | "reload" :: [] -> reload ()
5815 | "goto" :: args
:: [] ->
5816 scan args
"%u %f %f"
5818 let cmd, _ = state
.geomcmds
in
5820 then gotopagexy pageno x y
5823 gotopagexy pageno x y;
5826 state
.reprf
<- f state
.reprf
5828 | "goto1" :: args
:: [] -> scan args
"%u %f" gotopage
5829 | "gotor" :: args
:: [] ->
5831 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
5832 | "gotord" :: args
:: [] ->
5834 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
5835 | "rect" :: args
:: [] ->
5836 scan args
"%u %u %f %f %f %f"
5837 (fun pageno color x0 y0 x1 y1 ->
5838 onpagerect pageno (fun w h ->
5839 let _,w1,h1
,_ = getpagedim
pageno in
5840 let sw = float w1 /. float w
5841 and sh = float h1
/. float h in
5845 and y1s
= y1 *. sh in
5846 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
5848 state
.rects <- (pageno, color, rect) :: state
.rects;
5849 G.postRedisplay "rect";
5852 | "activatewin" :: [] -> Wsi.activatewin
()
5853 | "quit" :: [] -> raise Quit
5855 adderrfmt "remote command"
5856 "error processing remote command: %S\n" cmds
;
5860 let scratch = String.create
80 in
5861 let buf = Buffer.create
80 in
5864 try Some
(Unix.read fd
scratch 0 80)
5866 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
5867 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
5870 match tempfr () with
5876 if Buffer.length
buf > 0
5878 let s = Buffer.contents
buf in
5888 let pos = String.index_from
scratch ppos '
\n'
in
5889 if pos >= n then -1 else pos
5890 with Not_found
-> -1
5894 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
5895 let s = Buffer.contents
buf in
5901 Buffer.add_substring
buf scratch ppos
(n-ppos
);
5907 let remoteopen path =
5908 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
5910 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
5915 let trimcachepath = ref "" in
5916 let rcmdpath = ref "" in
5917 let pageno = ref None
in
5918 selfexec := Sys.executable_name
;
5921 [("-p", Arg.String
(fun s -> state
.password
<- s),
5922 "<password> Set password");
5926 Config.fontpath
:= s;
5927 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
5929 "<path> Set path to the user interface font");
5933 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
5934 Config.confpath
:= s),
5935 "<path> Set path to the configuration file");
5937 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
5938 "<page-number> Jump to page");
5940 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
5941 "<path> Set path to the trim cache file");
5943 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
5944 "<named-destination> Set named destination");
5946 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
5947 ("-cxack", Arg.Set
cxack, " Cut corners");
5949 ("-remote", Arg.String
(fun s -> rcmdpath := s),
5950 "<path> Set path to the remote commands source");
5952 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
5953 "<original-path> Set original path");
5955 ("-v", Arg.Unit
(fun () ->
5957 "%s\nconfiguration path: %s\n"
5961 exit
0), " Print version and exit");
5964 (fun s -> state
.path <- s)
5965 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5968 then selfexec := !selfexec ^
" -wtmode";
5970 if emptystr state
.path
5971 then (prerr_endline
"file name missing"; exit
1);
5973 if not
(Config.load ())
5974 then prerr_endline
"failed to load configuration";
5975 begin match !pageno with
5976 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
5980 let wsfd, winw, winh
= Wsi.init
(object (self)
5981 val mutable m_hack
= false
5982 val mutable m_clicks
= 0
5983 val mutable m_click_x
= 0
5984 val mutable m_click_y
= 0
5985 val mutable m_lastclicktime
= infinity
5987 method private cleanup
=
5988 state
.roam
<- noroam
;
5989 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
;
5990 method expose
= if not m_hack
then G.postRedisplay "expose"
5991 method visible
= G.postRedisplay "visible"
5992 method display = m_hack
<- false; display ()
5993 method reshape w h =
5995 m_hack
<- w < state
.winw && h < state
.winh
;
5997 method mouse
b d x y m =
5998 if d && canselect ()
6000 (* http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx *)
6006 if abs
x - m_click_x
> 10
6007 || abs
y - m_click_y
> 10
6008 || abs_float
(t -. m_lastclicktime
) > 0.3
6010 m_clicks
<- m_clicks
+ 1;
6011 m_lastclicktime
<- t;
6015 G.postRedisplay "cleanup";
6016 state
.uioh <- state
.uioh#button
b d x y m;
6018 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6023 m_lastclicktime
<- infinity
;
6024 state
.uioh <- state
.uioh#button
b d x y m
6028 state
.uioh <- state
.uioh#button
b d x y m
6031 state
.mpos
<- (x, y);
6032 state
.uioh <- state
.uioh#motion
x y
6033 method pmotion
x y =
6034 state
.mpos
<- (x, y);
6035 state
.uioh <- state
.uioh#pmotion
x y
6037 let mascm = m land (
6038 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6041 let x = state
.x and y = state
.y in
6043 if x != state
.x || y != state
.y then self#cleanup
6045 match state
.keystate
with
6047 let km = k
, mascm in
6050 let modehash = state
.uioh#
modehash in
6051 try Hashtbl.find modehash km
6053 try Hashtbl.find (findkeyhash conf
"global") km
6054 with Not_found
-> KMinsrt
(k
, m)
6056 | KMinsrt
(k
, m) -> keyboard k
m
6057 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6058 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6060 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6061 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6062 state
.keystate
<- KSnone
6063 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k
&& m'
land mascm = m'
->
6064 state
.keystate
<- KSinto
(keys
, insrt
)
6066 state
.keystate
<- KSnone
6069 state
.mpos
<- (x, y);
6070 state
.uioh <- state
.uioh#pmotion
x y
6071 method leave = state
.mpos
<- (-1, -1)
6072 method winstate wsl
= state
.winstate
<- wsl
; m_hack
<- false
6073 method quit
= raise Quit
6074 end) conf
.cwinw conf
.cwinh
(platform
= Posx
) in
6079 List.exists
GlMisc.check_extension
6080 [ "GL_ARB_texture_rectangle"
6081 ; "GL_EXT_texture_recangle"
6082 ; "GL_NV_texture_rectangle" ]
6084 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6087 let r = GlMisc.get_string `renderer
in
6088 let p = "Mesa DRI Intel(" in
6089 let l = String.length
p in
6090 String.length
r > l && String.sub
r 0 l = p
6093 defconf
.sliceheight
<- 1024;
6094 defconf
.texcount
<- 32;
6095 defconf
.usepbo
<- true;
6099 match Ne.res Unix.pipe
with
6101 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
6105 match Ne.res Unix.pipe
with
6107 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
6117 setcheckers conf
.checkers
;
6119 if conf
.redirectstderr
6122 let s = Buffer.contents state
.errmsgs ^
6123 (match state
.errfd
with
6125 let s = String.create
(80*24) in
6128 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
6130 then Unix.read fd
s 0 (String.length
s)
6136 else String.sub
s 0 n
6140 try ignore
(Unix.write state
.stderr
s 0 (String.length
s))
6141 with exn
-> print_endline
(exntos exn
)
6146 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6147 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6148 !Config.fontpath
, !trimcachepath,
6149 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
6151 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6154 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6156 opendoc state
.path state
.password
;
6160 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6163 if nonemptystr
!rcmdpath
6164 then remoteopen !rcmdpath
6169 let rec loop deadline
=
6171 match state
.errfd
with
6172 | None
-> [state
.sr
; state
.wsfd]
6173 | Some fd
-> [state
.sr
; state
.wsfd; fd
]
6178 | Some fd
-> fd
:: r
6182 state
.redisplay
<- false;
6189 if deadline
= infinity
6191 else max
0.0 (deadline
-. now)
6196 try Unix.select
r [] [] timeout
6197 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6203 if state
.ghyll
== noghyll
6205 match state
.autoscroll
with
6206 | Some step
when step
!= 0 ->
6207 let y = state
.y + step
in
6211 else if y >= state
.maxy then 0 else y
6214 if state
.mode = View
6215 then state
.text <- "";
6218 else deadline
+. 0.01
6223 let rec checkfds = function
6225 | fd
:: rest
when fd
= state
.sr
->
6226 let cmd = readcmd state
.sr
in
6230 | fd
:: rest
when fd
= state
.wsfd ->
6234 | fd
:: rest
when Some fd
= !optrfd ->
6235 begin match remote fd
with
6236 | None
-> optrfd := remoteopen !rcmdpath;
6237 | opt -> optrfd := opt
6242 let s = String.create
80 in
6243 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
6244 if conf
.redirectstderr
6246 Buffer.add_substring state
.errmsgs
s 0 n;
6247 state
.newerrmsgs
<- true;
6248 state
.redisplay
<- true;
6251 prerr_string
(String.sub
s 0 n);
6259 if deadline
= infinity
6263 match state
.autoscroll
with
6264 | Some step
when step
!= 0 -> deadline1
6265 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6273 Config.save
leavebirdseye;