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 = 30.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 Gl.disable `texture_2d
;
2612 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2613 GlDraw.color
(1., 1., 1.) ~
alpha;
2614 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2615 Gl.enable `texture_2d
;
2616 GlDraw.color
(1., 1., 1.);
2618 let drawtabularstring s =
2619 let drawstr x s = drawstring1 fs (truncate
(x +. x0)) (y+nfs) s in
2622 let x = if helpmode
&& row > 0 then x +. ww else x in
2623 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2626 let len = String.length
s - tabpos - 1 in
2627 let s1 = String.sub
s 0 tabpos
2628 and s2
= String.sub
s (tabpos + 1) len in
2629 let nx = drawstr x s1 in
2631 let x = x +. (max
tabw sw) in
2634 let len = String.length
s - 2 in
2635 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2637 let s = String.sub
s 2 len in
2638 let x = if not helpmode
then x +. ww else x in
2639 GlDraw.color
(1.2, 1.2, 1.2);
2640 let vinc = drawstring1 (fs+fs/4)
2641 (truncate
(x -. ww)) (y+nfs) s in
2642 GlDraw.color
(1., 1., 1.);
2643 vinc +. (float fs *. 0.8)
2649 let _ = drawtabularstring s in
2655 GlDraw.color
(1.0, 1.0, 1.0) ~
alpha:0.5;
2657 if (row - m_first
) > fstate
.maxrows
2660 if row >= 0 && row < itemcount
2662 let (s, level
) = source#getitem
row in
2663 let y = (row - m_first
) * nfs in
2664 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2665 let (first, last
) = minfo.(row) in
2666 let prefix = String.sub
s 0 first in
2667 let suffix = String.sub
s first (last
- first) in
2668 let w1 = measurestr fstate
.fontsize
prefix in
2669 let w2 = measurestr fstate
.fontsize
suffix in
2671 and y0 = (float (y+2)) in
2673 and y1 = (float (y+fs+3)) in
2674 filledrect x0 y0 x1 y1;
2679 Gl.disable `texture_2d
;
2680 if Array.length
minfo > 0 then loop m_first
;
2683 method updownlevel incr
=
2684 let len = source#getitemcount
in
2686 if m_active
>= 0 && m_active
< len
2687 then snd
(source#getitem m_active
)
2691 if i
= len then i
-1 else if i
= -1 then 0 else
2692 let _, l = source#getitem i
in
2693 if l != curlevel then i
else flow (i
+incr
)
2695 let active = flow m_active
in
2696 let first = calcfirst m_first
active in
2697 G.postRedisplay "outline updownlevel";
2698 {< m_active
= active; m_first
= first >}
2700 method private key1
key mask
=
2701 let set1 active first qsearch
=
2702 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2704 let search active pattern incr
=
2705 let active = if active = -1 then m_first
else active in
2708 if n >= 0 && n < source#getitemcount
2710 let s, _ = source#getitem
n in
2712 (try ignore
(Str.search_forward
re s 0); true
2713 with Not_found
-> false)
2715 else loop (n + incr
)
2722 let re = Str.regexp_case_fold pattern
in
2728 let itemcount = source#getitemcount
in
2729 let find start incr
=
2731 if i
= -1 || i
= itemcount
2734 if source#hasaction i
2736 else find (i
+ incr
)
2741 let set active first =
2742 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2744 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
2747 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2749 let incr1 = if incr
> 0 then 1 else -1 in
2750 if isvisible m_first m_active
2753 let next = m_active
+ incr
in
2755 if next < 0 || next >= itemcount
2757 else find next incr1
2759 if abs
(m_active
- next) > fstate
.maxrows
2765 let first = m_first
+ incr
in
2766 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2768 let next = m_active
+ incr
in
2769 let next = bound
next 0 (itemcount - 1) in
2776 if isvisible first next
2783 let first = min
next m_first
in
2785 if abs
(next - first) > fstate
.maxrows
2791 let first = m_first
+ incr
in
2792 let first = bound
first 0 (itemcount - 1) in
2794 let next = m_active
+ incr
in
2795 let next = bound
next 0 (itemcount - 1) in
2796 let next = find next incr1 in
2798 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2800 let active = if m_active
= -1 then next else m_active
in
2805 if isvisible first active
2811 G.postRedisplay "listview navigate";
2815 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2816 let incr = if key = 0x72 then -1 else 1 in
2818 match search (m_active
+ incr) m_qsearch
incr with
2820 state
.text <- m_qsearch ^
" [not found]";
2823 state
.text <- m_qsearch
;
2824 active, firstof m_first
active
2826 G.postRedisplay "listview ctrl-r/s";
2827 set1 active first m_qsearch
;
2829 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
2830 if m_active
>= 0 && m_active
< source#getitemcount
2832 let s, _ = source#getitem m_active
in
2837 | 0xff08 -> (* backspace *)
2838 if emptystr m_qsearch
2841 let qsearch = withoutlastutf8 m_qsearch
in
2845 G.postRedisplay "listview empty qsearch";
2846 set1 m_active m_first
"";
2850 match search m_active
qsearch ~
-1 with
2852 state
.text <- qsearch ^
" [not found]";
2855 state
.text <- qsearch;
2856 active, firstof m_first
active
2858 G.postRedisplay "listview backspace qsearch";
2859 set1 active first qsearch
2862 | key when (key != 0 && key land 0xff00 != 0xff00) ->
2863 let pattern = m_qsearch ^ toutf8
key in
2865 match search m_active
pattern 1 with
2867 state
.text <- pattern ^
" [not found]";
2870 state
.text <- pattern;
2871 active, firstof m_first
active
2873 G.postRedisplay "listview qsearch add";
2874 set1 active first pattern;
2876 | 0xff1b -> (* escape *)
2878 if emptystr m_qsearch
2880 G.postRedisplay "list view escape";
2883 source#exit
(coe self
) true m_active m_first m_pan
2885 | None
-> m_prev_uioh
2890 G.postRedisplay "list view kill qsearch";
2891 coe {< m_qsearch
= "" >}
2894 | 0xff0d | 0xff8d -> (* (kp) enter *)
2896 let self = {< m_qsearch
= "" >} in
2898 G.postRedisplay "listview enter";
2899 if m_active
>= 0 && m_active
< source#getitemcount
2901 source#exit
(coe self) false m_active m_first m_pan
;
2904 source#exit
(coe self) true m_active m_first m_pan
;
2907 begin match opt with
2908 | None
-> m_prev_uioh
2912 | 0xff9f | 0xffff -> (* (kp) delete *)
2915 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
2916 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
2917 | 0xff55 | 0xff9a -> navigate ~
-(fstate
.maxrows
) (* (kp) prior *)
2918 | 0xff56 | 0xff9b -> navigate fstate
.maxrows
(* (kp) next *)
2920 | 0xff53 | 0xff98 -> (* (kp) right *)
2922 G.postRedisplay "listview right";
2923 coe {< m_pan
= m_pan
- 1 >}
2925 | 0xff51 | 0xff96 -> (* (kp) left *)
2927 G.postRedisplay "listview left";
2928 coe {< m_pan
= m_pan
+ 1 >}
2930 | 0xff50 | 0xff95 -> (* (kp) home *)
2931 let active = find 0 1 in
2932 G.postRedisplay "listview home";
2935 | 0xff57 | 0xff9c -> (* (kp) end *)
2936 let first = max
0 (itemcount - fstate
.maxrows
) in
2937 let active = find (itemcount - 1) ~
-1 in
2938 G.postRedisplay "listview end";
2941 | key when (key = 0 || key land 0xff00 = 0xff00) ->
2945 dolog
"listview unknown key %#x" key; coe self
2947 method key key mask
=
2948 match state
.mode
with
2949 | Textentry te
-> textentrykeyboard key mask te
; coe self
2950 | _ -> self#key1
key mask
2952 method button button down
x y _ =
2955 | 1 when x > state
.winw
- conf
.scrollbw
->
2956 G.postRedisplay "listview scroll";
2959 let _, position, sh = self#
scrollph in
2960 if y > truncate
position && y < truncate
(position +. sh)
2962 state
.mstate
<- Mscrolly
;
2966 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2967 let first = truncate
(s *. float source#getitemcount
) in
2968 let first = min source#getitemcount
first in
2969 Some
(coe {< m_first
= first; m_active
= first >})
2971 state
.mstate
<- Mnone
;
2974 | 1 when not down
->
2975 begin match self#elemunder
y with
2977 G.postRedisplay "listview click";
2978 source#exit
(coe {< m_active
= n >}) false n m_first m_pan
2982 | n when (n == 4 || n == 5) && not down
->
2983 let len = source#getitemcount
in
2985 if n = 5 && m_first
+ fstate
.maxrows
>= len
2989 let first = m_first
+ (if n == 4 then -1 else 1) in
2990 bound
first 0 (len - 1)
2992 G.postRedisplay "listview wheel";
2993 Some
(coe {< m_first
= first >})
2994 | n when (n = 6 || n = 7) && not down
->
2995 let inc = if n = 7 then -1 else 1 in
2996 G.postRedisplay "listview hwheel";
2997 Some
(coe {< m_pan
= m_pan
+ inc >})
3002 | None
-> m_prev_uioh
3005 method multiclick
_ x y = self#button
1 true x y
3008 match state
.mstate
with
3010 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
3011 let first = truncate
(s *. float source#getitemcount
) in
3012 let first = min source#getitemcount
first in
3013 G.postRedisplay "listview motion";
3014 coe {< m_first
= first; m_active
= first >}
3017 method pmotion
x y =
3018 if x < state
.winw
- conf
.scrollbw
3021 match self#elemunder
y with
3022 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3023 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3027 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3032 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3036 method infochanged
_ = ()
3038 method scrollpw
= (0, 0.0, 0.0)
3040 let nfs = fstate
.fontsize
+ 1 in
3041 let y = m_first
* nfs in
3042 let itemcount = source#getitemcount
in
3043 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3044 let maxy = maxi * nfs in
3045 let p, h = scrollph y maxy in
3048 method modehash
= modehash
3049 method eformsgs
= false
3052 class outlinelistview ~source
=
3053 let settext autonarrow
s =
3056 let ss = source#statestr
in
3060 else "{" ^
ss ^
"} [" ^
s ^
"]"
3061 else state
.text <- s
3066 ~source
:(source
:> lvsource
)
3068 ~modehash
:(findkeyhash conf
"outline")
3071 val m_autonarrow
= false
3073 method display
= super#display
3075 method key key mask
=
3077 if emptystr state
.text
3079 else fstate
.maxrows - 2
3081 let calcfirst first active =
3084 let rows = active - first in
3085 if rows > maxrows then active - maxrows else first
3089 let active = m_active
+ incr in
3090 let active = bound
active 0 (source#getitemcount
- 1) in
3091 let first = calcfirst m_first
active in
3092 G.postRedisplay "outline navigate";
3093 coe {< m_active
= active; m_first
= first >}
3095 let navscroll first =
3097 let dist = m_active
- first in
3103 else first + maxrows
3106 G.postRedisplay "outline navscroll";
3107 coe {< m_first
= first; m_active
= active >}
3109 let ctrl = Wsi.withctrl mask
in
3111 | 97 when ctrl -> (* ctrl-a *)
3114 then (source#denarrow
; "")
3116 let pattern = source#renarrow
in
3117 if nonemptystr m_qsearch
3118 then (source#narrow m_qsearch
; m_qsearch
)
3122 settext (not m_autonarrow
) text;
3123 G.postRedisplay "toggle auto narrowing";
3124 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3126 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3128 G.postRedisplay "toggle auto narrowing";
3129 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3131 | 110 when ctrl -> (* ctrl-n *)
3132 source#narrow m_qsearch
;
3134 then source#add_narrow_pattern m_qsearch
;
3135 G.postRedisplay "outline ctrl-n";
3136 coe {< m_first
= 0; m_active
= 0 >}
3138 | 83 when ctrl -> (* ctrl-S *)
3139 let active = source#calcactive
(getanchor
()) in
3140 let first = firstof m_first
active in
3141 G.postRedisplay "outline ctrl-s";
3142 coe {< m_first
= first; m_active
= active >}
3144 | 117 when ctrl -> (* ctrl-u *)
3145 G.postRedisplay "outline ctrl-u";
3146 if m_autonarrow
&& nonemptystr m_qsearch
3148 ignore
(source#renarrow
);
3149 settext m_autonarrow
"";
3150 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3153 source#del_narrow_pattern
;
3154 let pattern = source#renarrow
in
3156 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3158 settext m_autonarrow
text;
3159 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3162 | 108 when ctrl -> (* ctrl-l *)
3163 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3164 G.postRedisplay "outline ctrl-l";
3165 coe {< m_first
= first >}
3167 | 0xff09 when m_autonarrow
-> (* tab *)
3168 if nonemptystr m_qsearch
3170 G.postRedisplay "outline list view tab";
3171 source#add_narrow_pattern m_qsearch
;
3173 coe {< m_qsearch
= "" >}
3177 | 0xff1b when m_autonarrow
-> (* escape *)
3178 if nonemptystr m_qsearch
3179 then source#add_narrow_pattern m_qsearch
;
3182 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3183 if nonemptystr m_qsearch
3184 then source#add_narrow_pattern m_qsearch
;
3187 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3188 let pattern = m_qsearch ^ toutf8
key in
3189 G.postRedisplay "outlinelistview autonarrow add";
3190 source#narrow
pattern;
3191 settext true pattern;
3192 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3194 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3195 if emptystr m_qsearch
3198 let pattern = withoutlastutf8 m_qsearch
in
3199 G.postRedisplay "outlinelistview autonarrow backspace";
3200 ignore
(source#renarrow
);
3201 source#narrow
pattern;
3202 settext true pattern;
3203 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3205 | 0xff9f | 0xffff -> (* (kp) delete *)
3206 source#remove m_active
;
3207 G.postRedisplay "outline delete";
3208 let active = max
0 (m_active
-1) in
3209 coe {< m_first
= firstof m_first
active;
3210 m_active
= active >}
3212 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3213 navscroll (max
0 (m_first
- 1))
3215 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3216 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3218 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3219 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3220 | 0xff55 | 0xff9a -> (* (kp) prior *)
3221 navigate ~
-(fstate
.maxrows)
3222 | 0xff56 | 0xff9b -> (* (kp) next *)
3223 navigate fstate
.maxrows
3225 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3229 G.postRedisplay "outline ctrl right";
3230 {< m_pan
= m_pan
+ 1 >}
3232 else self#updownlevel
1
3236 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3240 G.postRedisplay "outline ctrl left";
3241 {< m_pan
= m_pan
- 1 >}
3243 else self#updownlevel ~
-1
3247 | 0xff50 | 0xff95 -> (* (kp) home *)
3248 G.postRedisplay "outline home";
3249 coe {< m_first
= 0; m_active
= 0 >}
3251 | 0xff57 | 0xff9c -> (* (kp) end *)
3252 let active = source#getitemcount
- 1 in
3253 let first = max
0 (active - fstate
.maxrows) in
3254 G.postRedisplay "outline end";
3255 coe {< m_active
= active; m_first
= first >}
3257 | _ -> super#
key key mask
3260 let gotounder under =
3261 let getpath filename
=
3263 if nonemptystr filename
3265 if Filename.is_relative filename
3267 let dir = Filename.dirname state
.path in
3269 if Filename.is_implicit
dir
3270 then Filename.concat
(Sys.getcwd
()) dir
3273 Filename.concat
dir filename
3277 if Sys.file_exists
path
3282 | Ulinkgoto
(pageno, top) ->
3286 gotopage1 pageno top;
3292 | Uremote
(filename
, pageno) ->
3293 let path = getpath filename
in
3298 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
3299 try popen
command []
3301 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
3304 let anchor = getanchor
() in
3305 let ranchor = state
.path, state
.password
, anchor, state
.origin
in
3307 state
.anchor <- (pageno, 0.0, 0.0);
3308 state
.ranchors
<- ranchor :: state
.ranchors
;
3311 else showtext '
!'
("Could not find " ^ filename
)
3313 | Uremotedest
(filename
, destname
) ->
3314 let path = getpath filename
in
3319 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
3320 try popen
command []
3323 "failed to execute `%s': %s\n" command (exntos exn
);
3326 let anchor = getanchor
() in
3327 let ranchor = state
.path, state
.password
, anchor, state
.origin
in
3329 state
.nameddest
<- destname
;
3330 state
.ranchors
<- ranchor :: state
.ranchors
;
3333 else showtext '
!'
("Could not find " ^ filename
)
3335 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
3338 let gotooutline (_, _, kind
) =
3342 let (pageno, y, _) = anchor in
3344 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3348 | Ouri
uri -> gotounder (Ulinkuri
uri)
3349 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
3350 | Oremote remote
-> gotounder (Uremote remote
)
3351 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
3354 let outlinesource usebookmarks
=
3357 inherit lvsourcebase
3358 val mutable m_items
= empty
3359 val mutable m_minfo
= empty
3360 val mutable m_orig_items
= empty
3361 val mutable m_orig_minfo
= empty
3362 val mutable m_narrow_patterns
= []
3363 val mutable m_hadremovals
= false
3364 val mutable m_gen
= -1
3366 method getitemcount
=
3367 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3370 if n == Array.length m_items
&& m_hadremovals
3372 ("[Confirm removal]", 0)
3374 let s, n, _ = m_items
.(n) in
3377 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3378 ignore
(uioh
, first);
3379 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3381 if m_narrow_patterns
= []
3382 then m_orig_items
, m_orig_minfo
3383 else m_items
, m_minfo
3387 if not
confrimremoval
3389 gotooutline m_items
.(active);
3394 state
.bookmarks
<- Array.to_list m_items
;
3395 m_orig_items
<- m_items
;
3396 m_orig_minfo
<- m_minfo
;
3406 method hasaction
_ = true
3409 if Array.length m_items
!= Array.length m_orig_items
3412 match m_narrow_patterns
with
3414 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
3416 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3420 match m_narrow_patterns
with
3423 | head
:: _ -> "\xe2\x80\xa6" ^ head
3425 method narrow
pattern =
3426 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3430 let rec loop accu minfo n =
3433 m_items
<- Array.of_list
accu;
3434 m_minfo
<- Array.of_list
minfo;
3437 let (s, _, _) as o = m_items
.(n) in
3440 try Str.search_forward
re s 0
3441 with Not_found
-> -1
3444 then o :: accu, (first, Str.match_end
()) :: minfo
3447 loop accu minfo (n-1)
3449 loop [] [] (Array.length m_items
- 1)
3451 method getminfo
= m_minfo
3456 then Array.of_list state
.bookmarks
3459 m_minfo
<- m_orig_minfo
;
3460 m_items
<- m_orig_items
3465 if m >= 0 && m < Array.length m_items
3467 m_hadremovals
<- true;
3468 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3469 let n = if n >= m then n+1 else n in
3474 method add_narrow_pattern
pattern =
3475 m_narrow_patterns
<- pattern :: m_narrow_patterns
3477 method del_narrow_pattern
=
3478 match m_narrow_patterns
with
3479 | _ :: rest
-> m_narrow_patterns
<- rest
3484 match m_narrow_patterns
with
3485 | pattern :: [] -> self#narrow
pattern; pattern
3487 List.fold_left
(fun accu pattern ->
3488 self#narrow
pattern;
3489 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
3491 method calcactive
anchor =
3492 let rely = getanchory anchor in
3493 let rec loop n best bestd
=
3494 if n = Array.length m_items
3497 let _, _, kind
= m_items
.(n) in
3500 let orely = getanchory anchor in
3501 let d = abs
(orely - rely) in
3504 else loop (n+1) best bestd
3505 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
3506 loop (n+1) best bestd
3510 method reset
anchor items =
3511 m_hadremovals
<- false;
3512 if state
.gen
!= m_gen
3514 m_orig_items
<- items;
3516 m_narrow_patterns
<- [];
3518 m_orig_minfo
<- empty;
3522 if items != m_orig_items
3524 m_orig_items
<- items;
3525 if m_narrow_patterns
== []
3526 then m_items
<- items;
3529 let active = self#calcactive
anchor in
3531 m_first
<- firstof m_first
active
3535 let enterselector usebookmarks
=
3537 let source = outlinesource usebookmarks
in
3541 then Array.of_list state
.bookmarks
3544 if Array.length
outlines = 0
3546 showtext ' ' errmsg
;
3549 state
.text <- source#greetmsg
;
3550 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3551 let anchor = getanchor
() in
3552 source#reset
anchor outlines;
3553 state
.uioh
<- coe (new outlinelistview ~
source);
3554 G.postRedisplay "enter selector";
3558 let enteroutlinemode =
3559 let f = enterselector false in
3560 fun () -> f "Document has no outline";
3563 let enterbookmarkmode =
3564 let f = enterselector true in
3565 fun () -> f "Document has no bookmarks (yet)";
3568 let makecheckers () =
3569 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3571 converted by Issac Trotts. July 25, 2002 *)
3572 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3573 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3574 let id = GlTex.gen_texture
() in
3575 GlTex.bind_texture `texture_2d
id;
3576 GlPix.store
(`unpack_alignment
1);
3577 GlTex.image2d
image;
3578 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3579 [ `mag_filter `nearest
; `min_filter `nearest
];
3583 let setcheckers enabled
=
3584 match state
.checkerstexid
with
3586 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3588 | Some checkerstexid
->
3591 GlTex.delete_texture checkerstexid
;
3592 state
.checkerstexid
<- None
;
3596 let describe_location () =
3597 let fn = page_of_y state
.y in
3598 let ln = page_of_y
(state
.y + state
.winh
- hscrollh () - 1) in
3599 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
3603 else (100. *. (float state
.y /. float maxy))
3607 Printf.sprintf
"page %d of %d [%.2f%%]"
3608 (fn+1) state
.pagecount
percent
3611 "pages %d-%d of %d [%.2f%%]"
3612 (fn+1) (ln+1) state
.pagecount
percent
3615 let setpresentationmode v
=
3616 let n = page_of_y state
.y in
3617 state
.anchor <- (n, 0.0, 1.0);
3618 conf
.presentation
<- v
;
3619 if conf
.fitmodel
= FitPage
3620 then reqlayout conf
.angle conf
.fitmodel
;
3625 let btos b = if b then "\xe2\x88\x9a" else "" in
3626 let showextended = ref false in
3627 let leave mode
= function
3628 | Confirm
-> state
.mode
<- mode
3629 | Cancel
-> state
.mode
<- mode
in
3632 val mutable m_first_time
= true
3633 val mutable m_l
= []
3634 val mutable m_a
= [||]
3635 val mutable m_prev_uioh
= nouioh
3636 val mutable m_prev_mode
= View
3638 inherit lvsourcebase
3640 method reset prev_mode prev_uioh
=
3641 m_a
<- Array.of_list
(List.rev m_l
);
3643 m_prev_mode
<- prev_mode
;
3644 m_prev_uioh
<- prev_uioh
;
3648 if n >= Array.length m_a
3652 | _, _, _, Action
_ -> m_active
<- n
3656 m_first_time
<- false;
3659 method int name get
set =
3661 (name
, `
int get
, 1, Action
(
3664 try set (int_of_string
s)
3666 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3670 let te = name ^
": ", "", None
, intentry, ondone, true in
3671 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3675 method int_with_suffix name get
set =
3677 (name
, `intws get
, 1, Action
(
3680 try set (int_of_string_with_suffix
s)
3682 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3687 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3689 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3693 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3695 (name
, `
bool (btos, get
), offset
, Action
(
3702 method color name get
set =
3704 (name
, `color get
, 1, Action
(
3706 let invalid = (nan
, nan
, nan
) in
3709 try color_of_string
s
3711 state
.text <- Printf.sprintf
"bad color `%s': %s"
3718 let te = name ^
": ", "", None
, textentry, ondone, true in
3719 state
.text <- color_to_string
(get
());
3720 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3724 method string name get
set =
3726 (name
, `
string get
, 1, Action
(
3728 let ondone s = set s in
3729 let te = name ^
": ", "", None
, textentry, ondone, true in
3730 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3734 method colorspace name get
set =
3736 (name
, `
string get
, 1, Action
(
3740 inherit lvsourcebase
3743 m_active
<- CSTE.to_int conf
.colorspace
;
3746 method getitemcount
=
3747 Array.length
CSTE.names
3750 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3751 ignore
(uioh
, first, pan
);
3752 if not cancel
then set active;
3754 method hasaction
_ = true
3758 let modehash = findkeyhash conf
"info" in
3759 coe (new listview ~helpmode
:false ~
source ~trusted
:true ~
modehash)
3762 method paxmark name get
set =
3764 (name
, `
string get
, 1, Action
(
3768 inherit lvsourcebase
3771 m_active
<- MTE.to_int conf
.paxmark
;
3774 method getitemcount
= Array.length
MTE.names
3775 method getitem
n = (MTE.names
.(n), 0)
3776 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3777 ignore
(uioh
, first, pan
);
3778 if not cancel
then set active;
3780 method hasaction
_ = true
3784 let modehash = findkeyhash conf
"info" in
3785 coe (new listview ~helpmode
:false ~
source ~trusted
:true ~
modehash)
3788 method fitmodel name get
set =
3790 (name
, `
string get
, 1, Action
(
3794 inherit lvsourcebase
3797 m_active
<- FMTE.to_int conf
.fitmodel
;
3800 method getitemcount
= Array.length
FMTE.names
3801 method getitem
n = (FMTE.names
.(n), 0)
3802 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3803 ignore
(uioh
, first, pan
);
3804 if not cancel
then set active;
3806 method hasaction
_ = true
3810 let modehash = findkeyhash conf
"info" in
3811 coe (new listview ~helpmode
:false ~
source ~trusted
:true ~
modehash)
3814 method caption
s offset
=
3815 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3817 method caption2
s f offset
=
3818 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3820 method getitemcount
= Array.length m_a
3823 let tostr = function
3824 | `
int f -> string_of_int
(f ())
3825 | `intws
f -> string_with_suffix_of_int
(f ())
3827 | `color
f -> color_to_string
(f ())
3828 | `
bool (btos, f) -> btos (f ())
3831 let name, t
, offset
, _ = m_a
.(n) in
3832 ((let s = tostr t
in
3834 then Printf.sprintf
"%s\t%s" name s
3838 method exit ~uioh ~cancel ~
active ~
first ~pan
=
3843 match m_a
.(active) with
3844 | _, _, _, Action
f -> f uioh
3856 method hasaction
n =
3858 | _, _, _, Action
_ -> true
3862 let rec fillsrc prevmode prevuioh
=
3863 let sep () = src#caption
"" 0 in
3864 let colorp name get
set =
3866 (fun () -> color_to_string
(get
()))
3869 let c = color_of_string
v in
3872 state
.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
3875 let oldmode = state
.mode
in
3876 let birdseye = isbirdseye state
.mode
in
3878 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3880 src#
bool "presentation mode"
3881 (fun () -> conf
.presentation
)
3882 (fun v -> setpresentationmode v);
3884 src#
bool "ignore case in searches"
3885 (fun () -> conf
.icase
)
3886 (fun v -> conf
.icase
<- v);
3889 (fun () -> conf
.preload)
3890 (fun v -> conf
.preload <- v);
3892 src#
bool "highlight links"
3893 (fun () -> conf
.hlinks
)
3894 (fun v -> conf
.hlinks
<- v);
3896 src#
bool "under info"
3897 (fun () -> conf
.underinfo
)
3898 (fun v -> conf
.underinfo
<- v);
3900 src#
bool "persistent bookmarks"
3901 (fun () -> conf
.savebmarks
)
3902 (fun v -> conf
.savebmarks
<- v);
3904 src#fitmodel
"fit model"
3905 (fun () -> FMTE.to_string conf
.fitmodel
)
3906 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3908 src#
bool "trim margins"
3909 (fun () -> conf
.trimmargins
)
3910 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3912 src#
bool "persistent location"
3913 (fun () -> conf
.jumpback
)
3914 (fun v -> conf
.jumpback
<- v);
3917 src#
int "inter-page space"
3918 (fun () -> conf
.interpagespace
)
3920 conf
.interpagespace
<- n;
3921 docolumns conf
.columns
;
3923 match state
.layout with
3928 state
.maxy <- calcheight
();
3929 let y = getpagey
pageno in
3934 (fun () -> conf
.pagebias
)
3935 (fun v -> conf
.pagebias
<- v);
3937 src#
int "scroll step"
3938 (fun () -> conf
.scrollstep
)
3939 (fun n -> conf
.scrollstep
<- n);
3941 src#
int "horizontal scroll step"
3942 (fun () -> conf
.hscrollstep
)
3943 (fun v -> conf
.hscrollstep
<- v);
3945 src#
int "auto scroll step"
3947 match state
.autoscroll
with
3949 | _ -> conf
.autoscrollstep
)
3951 let n = boundastep state
.winh
n in
3952 if state
.autoscroll
<> None
3953 then state
.autoscroll
<- Some
n;
3954 conf
.autoscrollstep
<- n);
3957 (fun () -> truncate
(conf
.zoom *. 100.))
3958 (fun v -> setzoom ((float v) /. 100.));
3961 (fun () -> conf
.angle
)
3962 (fun v -> reqlayout v conf
.fitmodel
);
3964 src#
int "scroll bar width"
3965 (fun () -> conf
.scrollbw
)
3968 reshape state
.winw state
.winh
;
3971 src#
int "scroll handle height"
3972 (fun () -> conf
.scrollh
)
3973 (fun v -> conf
.scrollh
<- v;);
3975 src#
int "thumbnail width"
3976 (fun () -> conf
.thumbw
)
3978 conf
.thumbw
<- min
4096 v;
3981 leavebirdseye beye
false;
3986 let mode = state
.mode in
3987 src#
string "columns"
3989 match conf
.columns
with
3991 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3992 | Csplit
(count
, _) -> "-" ^ string_of_int count
3995 let n, a, b = multicolumns_of_string
v in
3996 setcolumns mode n a b);
3999 src#caption
"Pixmap cache" 0;
4000 src#int_with_suffix
"size (advisory)"
4001 (fun () -> conf
.memlimit
)
4002 (fun v -> conf
.memlimit
<- v);
4005 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4006 (string_with_suffix_of_int state
.memused
)
4007 (Hashtbl.length state
.tilemap
)) 1;
4010 src#caption
"Layout" 0;
4011 src#caption2
"Dimension"
4013 Printf.sprintf
"%dx%d (virtual %dx%d)"
4014 state
.winw state
.winh
4019 src#caption2
"Position" (fun () ->
4020 Printf.sprintf
"%dx%d" state
.x state
.y
4023 src#caption2
"Position" (fun () -> describe_location ()) 1
4027 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4028 "Save these parameters as global defaults at exit"
4029 (fun () -> conf
.bedefault
)
4030 (fun v -> conf
.bedefault
<- v)
4034 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4035 src#
bool ~offset
:0 ~
btos "Extended parameters"
4036 (fun () -> !showextended)
4037 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4041 (fun () -> conf
.checkers
)
4042 (fun v -> conf
.checkers
<- v; setcheckers v);
4043 src#
bool "update cursor"
4044 (fun () -> conf
.updatecurs
)
4045 (fun v -> conf
.updatecurs
<- v);
4046 src#
bool "scroll-bar on the left"
4047 (fun () -> conf
.leftscroll
)
4048 (fun v -> conf
.leftscroll
<- v);
4050 (fun () -> conf
.verbose
)
4051 (fun v -> conf
.verbose
<- v);
4052 src#
bool "invert colors"
4053 (fun () -> conf
.invert
)
4054 (fun v -> conf
.invert
<- v);
4056 (fun () -> conf
.maxhfit
)
4057 (fun v -> conf
.maxhfit
<- v);
4058 src#
bool "redirect stderr"
4059 (fun () -> conf
.redirectstderr)
4060 (fun v -> conf
.redirectstderr <- v; redirectstderr ());
4062 (fun () -> conf
.pax
!= None
)
4065 then conf
.pax
<- Some
(ref (now
(), 0, 0))
4066 else conf
.pax
<- None
);
4067 src#
string "uri launcher"
4068 (fun () -> conf
.urilauncher
)
4069 (fun v -> conf
.urilauncher
<- v);
4070 src#
string "path launcher"
4071 (fun () -> conf
.pathlauncher
)
4072 (fun v -> conf
.pathlauncher
<- v);
4073 src#
string "tile size"
4074 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
4077 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4078 conf
.tilew
<- max
64 w;
4079 conf
.tileh
<- max
64 h;
4082 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
4085 src#
int "texture count"
4086 (fun () -> conf
.texcount
)
4089 then conf
.texcount
<- v
4090 else showtext '
!'
" Failed to set texture count please retry later"
4092 src#
int "slice height"
4093 (fun () -> conf
.sliceheight
)
4095 conf
.sliceheight
<- v;
4096 wcmd "sliceh %d" conf
.sliceheight
;
4098 src#
int "anti-aliasing level"
4099 (fun () -> conf
.aalevel
)
4101 conf
.aalevel
<- bound
v 0 8;
4102 state
.anchor <- getanchor
();
4103 opendoc state
.path state
.password
;
4105 src#
string "page scroll scaling factor"
4106 (fun () -> string_of_float conf
.pgscale)
4109 let s = float_of_string
v in
4112 state
.text <- Printf.sprintf
4113 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4116 src#
int "ui font size"
4117 (fun () -> fstate
.fontsize
)
4118 (fun v -> setfontsize (bound
v 5 100));
4119 src#
int "hint font size"
4120 (fun () -> conf
.hfsize
)
4121 (fun v -> conf
.hfsize
<- bound
v 5 100);
4122 colorp "background color"
4123 (fun () -> conf
.bgcolor
)
4124 (fun v -> conf
.bgcolor
<- v);
4125 src#
bool "crop hack"
4126 (fun () -> conf
.crophack
)
4127 (fun v -> conf
.crophack
<- v);
4128 src#
string "trim fuzz"
4129 (fun () -> irect_to_string conf
.trimfuzz
)
4132 conf
.trimfuzz
<- irect_of_string
v;
4134 then settrim true conf
.trimfuzz
;
4136 state
.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4138 src#
string "throttle"
4140 match conf
.maxwait
with
4141 | None
-> "show place holder if page is not ready"
4144 then "wait for page to fully render"
4146 "wait " ^ string_of_float
time
4147 ^
" seconds before showing placeholder"
4151 let f = float_of_string
v in
4153 then conf
.maxwait
<- None
4154 else conf
.maxwait
<- Some
f
4156 state
.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4158 src#
string "ghyll scroll"
4160 match conf
.ghyllscroll
with
4162 | Some nab
-> ghyllscroll_to_string nab
4165 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
4167 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4169 src#
string "selection command"
4170 (fun () -> conf
.selcmd
)
4171 (fun v -> conf
.selcmd
<- v);
4172 src#
string "synctex command"
4173 (fun () -> conf
.stcmd
)
4174 (fun v -> conf
.stcmd
<- v);
4175 src#
string "pax command"
4176 (fun () -> conf
.paxcmd
)
4177 (fun v -> conf
.paxcmd
<- v);
4178 src#colorspace
"color space"
4179 (fun () -> CSTE.to_string conf
.colorspace
)
4181 conf
.colorspace
<- CSTE.of_int
v;
4185 src#paxmark
"pax mark method"
4186 (fun () -> MTE.to_string conf
.paxmark
)
4187 (fun v -> conf
.paxmark
<- MTE.of_int
v);
4191 (fun () -> conf
.usepbo
)
4192 (fun v -> conf
.usepbo
<- v);
4193 src#
bool "mouse wheel scrolls pages"
4194 (fun () -> conf
.wheelbypage
)
4195 (fun v -> conf
.wheelbypage
<- v);
4196 src#
bool "open remote links in a new instance"
4197 (fun () -> conf
.riani
)
4198 (fun v -> conf
.riani
<- v);
4202 src#caption
"Document" 0;
4203 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
4204 src#caption2
"Pages"
4205 (fun () -> string_of_int state
.pagecount
) 1;
4206 src#caption2
"Dimensions"
4207 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4211 src#caption
"Trimmed margins" 0;
4212 src#caption2
"Dimensions"
4213 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
4217 src#caption
"OpenGL" 0;
4218 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4219 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4222 src#caption
"Location" 0;
4223 if nonemptystr state
.origin
4224 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
4225 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
4227 src#reset prevmode prevuioh
;
4232 let prevmode = state
.mode
4233 and prevuioh
= state
.uioh in
4234 fillsrc prevmode prevuioh
;
4235 let source = (src :> lvsource
) in
4236 let modehash = findkeyhash conf
"info" in
4237 state
.uioh <- coe (object (self)
4238 inherit listview ~helpmode
:false ~
source ~trusted
:true ~
modehash as super
4239 val mutable m_prevmemused
= 0
4240 method infochanged
= function
4242 if m_prevmemused
!= state
.memused
4244 m_prevmemused
<- state
.memused
;
4245 G.postRedisplay "memusedchanged";
4247 | Pdim
-> G.postRedisplay "pdimchanged"
4248 | Docinfo
-> fillsrc prevmode prevuioh
4250 method key key mask
=
4251 if not
(Wsi.withctrl mask
)
4254 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4255 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4256 | _ -> super#
key key mask
4257 else super#
key key mask
4259 G.postRedisplay "info";
4265 inherit lvsourcebase
4266 method getitemcount
= Array.length state
.help
4268 let s, l, _ = state
.help
.(n) in
4271 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4275 match state
.help
.(active) with
4276 | _, _, Action
f -> Some
(f uioh)
4286 method hasaction
n =
4287 match state
.help
.(n) with
4288 | _, _, Action
_ -> true
4295 let modehash = findkeyhash conf
"help" in
4297 state
.uioh <- coe (new listview
4298 ~helpmode
:true ~
source ~trusted
:true ~
modehash);
4299 G.postRedisplay "help";
4304 let re = Str.regexp
"[\r\n]" in
4306 inherit lvsourcebase
4307 val mutable m_items
= [||]
4309 method getitemcount
= 1 + Array.length m_items
4314 else m_items
.(n-1), 0
4316 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
4321 then Buffer.clear state
.errmsgs
;
4328 method hasaction
n =
4332 state
.newerrmsgs
<- false;
4333 let l = Str.split
re (Buffer.contents state
.errmsgs
) in
4334 m_items
<- Array.of_list
l
4343 let source = (msgsource :> lvsource
) in
4344 let modehash = findkeyhash conf
"listview" in
4345 state
.uioh <- coe (object
4346 inherit listview ~helpmode
:false ~
source ~trusted
:false ~
modehash as super
4349 then msgsource#reset
;
4352 G.postRedisplay "msgs";
4355 let quickbookmark ?title
() =
4356 match state
.layout with
4362 let tm = Unix.localtime
(now
()) in
4363 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4367 (tm.Unix.tm_year
+ 1900)
4370 | Some
title -> title
4372 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4375 let setautoscrollspeed step goingdown
=
4376 let incr = max
1 ((abs step
) / 2) in
4377 let incr = if goingdown
then incr else -incr in
4378 let astep = boundastep state
.winh
(step
+ incr) in
4379 state
.autoscroll
<- Some
astep;
4383 match conf
.columns
with
4385 | _ -> state
.x != 0 || conf
.zoom > 1.0
4388 let panbound x = bound
x (-state
.w) (wadjsb state
.winw
);;
4390 let existsinrow pageno (columns
, coverA
, coverB
) p =
4391 let last = ((pageno - coverA
) mod columns
) + columns
in
4392 let rec any = function
4395 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4399 then (if l.pageno = last then false else any rest
)
4407 match state
.layout with
4409 let pageno = page_of_y state
.y in
4410 gotoghyll (getpagey
(pageno+1))
4412 match conf
.columns
with
4414 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4416 let y = clamp (pgscale state
.winh
) in
4419 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4420 gotoghyll (getpagey
pageno)
4421 | Cmulti
((c, _, _) as cl, _) ->
4422 if conf
.presentation
4423 && (existsinrow l.pageno cl
4424 (fun l -> l.pageh
> l.pagey + l.pagevh))
4426 let y = clamp (pgscale state
.winh
) in
4429 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4430 gotoghyll (getpagey
pageno)
4432 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4434 let pagey, pageh
= getpageyh
l.pageno in
4435 let pagey = pagey + pageh
* l.pagecol
in
4436 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4437 gotoghyll (pagey + pageh
+ ips)
4441 match state
.layout with
4443 let pageno = page_of_y state
.y in
4444 gotoghyll (getpagey
(pageno-1))
4446 match conf
.columns
with
4448 if conf
.presentation
&& l.pagey != 0
4450 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4452 let pageno = max
0 (l.pageno-1) in
4453 gotoghyll (getpagey
pageno)
4454 | Cmulti
((c, _, coverB
) as cl, _) ->
4455 if conf
.presentation
&&
4456 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4458 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4461 if l.pageno = state
.pagecount
- coverB
4465 let pageno = max
0 (l.pageno-decr) in
4466 gotoghyll (getpagey
pageno)
4474 let pageno = max
0 (l.pageno-1) in
4475 let pagey, pageh
= getpageyh
pageno in
4478 let pagey, pageh
= getpageyh
l.pageno in
4479 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4484 let viewkeyboard key mask
=
4486 let mode = state
.mode in
4487 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4490 G.postRedisplay "view:enttext"
4492 let ctrl = Wsi.withctrl mask
in
4494 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4500 | 0xff63 -> (* insert *)
4501 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4503 state
.mode <- LinkNav
(Ltgendir
0);
4506 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4508 | 0xff1b | 113 -> (* escape / q *)
4509 begin match state
.mstate
with
4512 G.postRedisplay "kill zoom rect";
4514 begin match state
.mode with
4517 G.postRedisplay "esc leave linknav"
4519 match state
.ranchors
with
4521 | (path, password
, anchor, origin
) :: rest
->
4522 state
.ranchors
<- rest
;
4523 state
.anchor <- anchor;
4524 state
.origin
<- origin
;
4525 state
.nameddest
<- "";
4526 opendoc path password
4530 | 0xff08 -> (* backspace *)
4531 gotoghyll (getnav ~
-1)
4539 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
;
4540 G.postRedisplay "dehighlight";
4542 | 47 | 63 -> (* / ? *)
4543 let ondone isforw
s =
4544 cbput state
.hists
.pat
s;
4545 state
.searchpattern
<- s;
4548 let s = String.create
1 in
4549 s.[0] <- Char.chr
key;
4550 enttext (s, "", Some
(onhist state
.hists
.pat
),
4551 textentry, ondone (key = 47), true)
4553 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4554 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4555 setzoom (conf
.zoom +. incr)
4557 | 43 | 0xffab -> (* + *)
4560 try int_of_string
s with exc
->
4561 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4567 state
.text <- "page bias is now " ^ string_of_int
n;
4570 enttext ("page bias: ", "", None
, intentry, ondone, true)
4572 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4573 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4574 setzoom (max
0.01 (conf
.zoom -. decr))
4576 | 45 | 0xffad -> (* - *)
4577 let ondone msg
= state
.text <- msg
in
4579 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
4580 optentry state
.mode, ondone, true
4583 | 48 when ctrl -> (* ctrl-0 *)
4591 | (49 | 50) when ctrl && conf
.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
4593 match conf
.columns
with
4594 | Csingle
_ | Cmulti
_ -> 1
4595 | Csplit
(n, _) -> n
4597 let h = state
.winh
-
4598 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4600 let zoom = zoomforh state
.winw
h (vscrollw ()) cols in
4601 if zoom > 0.0 && (key = 50 || zoom < 1.0)
4604 | 51 when ctrl -> (* ctrl-3 *)
4606 match conf
.fitmodel
with
4607 | FitWidth
-> FitProportional
4608 | FitProportional
-> FitPage
4609 | FitPage
-> FitWidth
4611 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4612 reqlayout conf
.angle
fm
4614 | 0xffc6 -> (* f9 *)
4617 | 57 when ctrl -> (* ctrl-9 *)
4620 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4621 when not
ctrl -> (* 0..9 *)
4624 try int_of_string
s with exc
->
4625 state
.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4631 cbput state
.hists
.pag
(string_of_int
n);
4632 gotopage1 (n + conf
.pagebias
- 1) 0;
4635 let pageentry text key =
4636 match Char.unsafe_chr
key with
4637 | '
g'
-> TEdone
text
4638 | _ -> intentry text key
4640 let text = "x" in text.[0] <- Char.chr
key;
4641 enttext (":", text, Some
(onhist state
.hists
.pag
), pageentry, ondone, true)
4644 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4645 reshape state
.winw state
.winh
;
4648 state
.bzoom
<- not state
.bzoom
;
4650 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4653 conf
.hlinks
<- not conf
.hlinks
;
4654 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4655 G.postRedisplay "toggle highlightlinks";
4658 state
.glinks
<- true;
4659 let mode = state
.mode in
4660 state
.mode <- Textentry
(
4661 (":", "", None
, linknentry, linkndone gotounder, false),
4663 state
.glinks
<- false;
4667 G.postRedisplay "view:linkent(F)"
4670 state
.glinks
<- true;
4671 let mode = state
.mode in
4672 state
.mode <- Textentry
(
4674 ":", "", None
, linknentry, linkndone (fun under ->
4675 selstring (undertext under);
4679 state
.glinks
<- false;
4683 G.postRedisplay "view:linkent"
4686 begin match state
.autoscroll
with
4688 conf
.autoscrollstep
<- step
;
4689 state
.autoscroll
<- None
4691 if conf
.autoscrollstep
= 0
4692 then state
.autoscroll
<- Some
1
4693 else state
.autoscroll
<- Some conf
.autoscrollstep
4696 | 112 when ctrl -> (* ctrl-p *)
4700 setpresentationmode (not conf
.presentation
);
4701 showtext ' '
("presentation mode " ^
4702 if conf
.presentation
then "on" else "off");
4705 if List.mem
Wsi.Fullscreen state
.winstate
4706 then Wsi.reshape conf
.cwinw conf
.cwinh
4707 else Wsi.fullscreen
()
4709 | 112 | 78 -> (* p|N *)
4710 search state
.searchpattern
false
4712 | 110 | 0xffc0 -> (* n|F3 *)
4713 search state
.searchpattern
true
4716 begin match state
.layout with
4719 gotoghyll (getpagey
l.pageno)
4725 | 0xff9f | 0xffff -> (* delete *)
4729 showtext ' '
(describe_location ());
4732 begin match state
.layout with
4735 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
4740 enterbookmarkmode ()
4742 | 104 | 0xffbe -> (* h|F1 *)
4748 | 101 when Buffer.length state
.errmsgs
> 0 -> (* e *)
4753 match state
.layout with
4758 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4761 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4765 showtext ' '
"Quick bookmark added";
4768 begin match state
.layout with
4770 let rect = getpdimrect
l.pagedimno
in
4774 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4775 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4777 (truncate
(rect.(1) -. rect.(0)),
4778 truncate
(rect.(3) -. rect.(0)))
4780 let w = truncate
((float w)*.conf
.zoom)
4781 and h = truncate
((float h)*.conf
.zoom) in
4784 state
.anchor <- getanchor
();
4785 Wsi.reshape (w + vscrollw ()) (h + conf
.interpagespace
)
4787 G.postRedisplay "z";
4794 | 60 | 62 -> (* < > *)
4795 reqlayout (conf
.angle
+ (if key = 62 then 30 else -30)) conf
.fitmodel
4797 | 91 | 93 -> (* [ ] *)
4799 bound
(conf
.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4801 G.postRedisplay "brightness";
4803 | 99 when state
.mode = View
-> (* [alt-]c *)
4808 let m = (wadjsb state
.winw
- state
.w) / 2 in
4810 gotoy_and_clear_text state
.y
4814 match state
.prevcolumns
with
4815 | None
-> (1, 0, 0), 1.0
4816 | Some
(columns
, z
) ->
4819 | Csplit
(c, _) -> -c, 0, 0
4820 | Cmulti
((c, a, b), _) -> c, a, b
4821 | Csingle
_ -> 1, 0, 0
4825 setcolumns View
c a b;
4828 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
4829 -> (* ctrl-shift- (kp) [up|down] *)
4830 let zoom, x = state
.prevzoom
in
4834 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
4835 begin match state
.autoscroll
with
4837 begin match state
.mode with
4838 | Birdseye beye
-> upbirdseye 1 beye
4841 then gotoy_and_clear_text (clamp ~
-(state
.winh
/2))
4843 if not
(Wsi.withshift mask
) && conf
.presentation
4845 else gotoghyll1 true (clamp (-conf
.scrollstep
))
4849 setautoscrollspeed n false
4852 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
4853 begin match state
.autoscroll
with
4855 begin match state
.mode with
4856 | Birdseye beye
-> downbirdseye 1 beye
4859 then gotoy_and_clear_text (clamp (state
.winh
/2))
4861 if not
(Wsi.withshift mask
) && conf
.presentation
4863 else gotoghyll1 true (clamp (conf
.scrollstep
))
4867 setautoscrollspeed n true
4870 | 0xff51 | 0xff53 | 0xff96 | 0xff98
4871 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
4877 else conf
.hscrollstep
4879 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
4880 state
.x <- panbound (state
.x + dx);
4881 gotoy_and_clear_text state
.y
4884 G.postRedisplay "left/right"
4887 | 0xff55 | 0xff9a -> (* (kp) prior *)
4891 match state
.layout with
4893 | l :: _ -> state
.y - l.pagey
4895 clamp (pgscale (-state
.winh
))
4899 | 0xff56 | 0xff9b -> (* (kp) next *)
4903 match List.rev state
.layout with
4905 | l :: _ -> getpagey
l.pageno
4907 clamp (pgscale state
.winh
)
4911 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
4913 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
4914 gotoghyll (clamp state
.maxy)
4917 when Wsi.withalt mask
-> (* alt-(kp) right *)
4918 gotoghyll (getnav 1)
4920 when Wsi.withalt mask
-> (* alt-(kp) left *)
4921 gotoghyll (getnav ~
-1)
4926 | 118 when conf
.debug
-> (* v *)
4929 match getopaque l.pageno with
4932 let x0, y0, x1, y1 = pagebbox
opaque in
4933 let a,b = float x0, float y0 in
4934 let c,d = float x1, float y0 in
4935 let e,f = float x1, float y1 in
4936 let h,j
= float x0, float y1 in
4937 let rect = (a,b,c,d,e,f,h,j
) in
4939 state
.rects
<- (l.pageno, l.pageno mod 3, rect) :: state
.rects
;
4941 G.postRedisplay "v";
4944 let mode = state
.mode in
4946 let onleave = function
4947 | Cancel
-> state
.mode <- mode
4950 match getopaque l.pageno with
4951 | Some
opaque -> pipesel opaque !cmd
4952 | None
-> ()) state
.layout;
4956 cbput state
.hists
.sel
s;
4960 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
4962 G.postRedisplay "|";
4963 state
.mode <- Textentry
(te, onleave);
4966 vlog "huh? %s" (Wsi.keyname
key)
4969 let linknavkeyboard key mask
linknav =
4970 let getpage pageno =
4971 let rec loop = function
4973 | l :: _ when l.pageno = pageno -> Some
l
4974 | _ :: rest
-> loop rest
4975 in loop state
.layout
4977 let doexact (pageno, n) =
4978 match getopaque pageno, getpage pageno with
4979 | Some
opaque, Some
l ->
4980 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
4982 let under = getlink
opaque n in
4983 G.postRedisplay "link gotounder";
4989 | 0xff50 -> (* home *)
4990 Some
(findlink
opaque LDfirst
), -1
4992 | 0xff57 -> (* end *)
4993 Some
(findlink
opaque LDlast
), 1
4995 | 0xff51 -> (* left *)
4996 Some
(findlink
opaque (LDleft
n)), -1
4998 | 0xff53 -> (* right *)
4999 Some
(findlink
opaque (LDright
n)), 1
5001 | 0xff52 -> (* up *)
5002 Some
(findlink
opaque (LDup
n)), -1
5004 | 0xff54 -> (* down *)
5005 Some
(findlink
opaque (LDdown
n)), 1
5010 begin match findpwl
l.pageno dir with
5014 state
.mode <- LinkNav
(Ltgendir
dir);
5015 let y, h = getpageyh
pageno in
5018 then y + h - state
.winh
5023 begin match getopaque pageno, getpage pageno with
5024 | Some
opaque, Some
_ ->
5026 let ld = if dir > 0 then LDfirst
else LDlast
in
5029 begin match link with
5031 showlinktype (getlink
opaque m);
5032 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5033 G.postRedisplay "linknav jpage";
5040 begin match opt with
5041 | Some Lnotfound
-> pwl l dir;
5042 | Some
(Lfound
m) ->
5046 let _, y0, _, y1 = getlinkrect
opaque m in
5048 then gotopage1 l.pageno y0
5050 let d = fstate
.fontsize
+ 1 in
5051 if y1 - l.pagey > l.pagevh - d
5052 then gotopage1 l.pageno (y1 - state
.winh
- hscrollh () + d)
5053 else G.postRedisplay "linknav";
5055 showlinktype (getlink
opaque m);
5056 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5059 | None
-> viewkeyboard key mask
5061 | _ -> viewkeyboard key mask
5066 G.postRedisplay "leave linknav"
5070 | Ltgendir
_ -> viewkeyboard key mask
5071 | Ltexact exact
-> doexact exact
5074 let keyboard key mask
=
5075 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state
.mode)
5076 then wcmd "interrupt"
5077 else state
.uioh <- state
.uioh#
key key mask
5080 let birdseyekeyboard key mask
5081 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5083 match conf
.columns
with
5085 | Cmulti
((c, _, _), _) -> c
5086 | Csplit
_ -> failwith
"bird's eye split mode"
5088 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state
.winh
layout in
5090 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5091 let y, h = getpageyh
pageno in
5092 let top = (state
.winh
- h) / 2 in
5093 gotoy (max
0 (y - top))
5094 | 0xff0d (* enter *)
5095 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5096 | 0xff1b -> leavebirdseye beye
true (* escape *)
5097 | 0xff52 -> upbirdseye incr beye
(* up *)
5098 | 0xff54 -> downbirdseye incr beye
(* down *)
5099 | 0xff51 -> upbirdseye 1 beye
(* left *)
5100 | 0xff53 -> downbirdseye 1 beye
(* right *)
5102 | 0xff55 -> (* prior *)
5103 begin match state
.layout with
5107 state
.mode <- Birdseye
(
5108 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5110 gotopage1 l.pageno 0;
5113 let layout = layout (state
.y-state
.winh
) (pgh state
.layout) in
5115 | [] -> gotoy (clamp (-state
.winh
))
5117 state
.mode <- Birdseye
(
5118 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5120 gotopage1 l.pageno 0
5123 | [] -> gotoy (clamp (-state
.winh
))
5126 | 0xff56 -> (* next *)
5127 begin match List.rev state
.layout with
5129 let layout = layout (state
.y + (pgh state
.layout)) state
.winh
in
5130 begin match layout with
5132 let incr = l.pageh
- l.pagevh in
5137 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5139 G.postRedisplay "birdseye pagedown";
5141 else gotoy (clamp (incr + conf
.interpagespace
*2));
5145 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5146 gotopage1 l.pageno 0;
5149 | [] -> gotoy (clamp state
.winh
)
5152 | 0xff50 -> (* home *)
5153 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5156 | 0xff57 -> (* end *)
5157 let pageno = state
.pagecount
- 1 in
5158 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5159 if not
(pagevisible state
.layout pageno)
5162 match List.rev state
.pdims
with
5164 | (_, _, h, _) :: _ -> h
5166 gotoy (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5167 else G.postRedisplay "birdseye end";
5168 | _ -> viewkeyboard key mask
5173 match state
.mode with
5174 | Textentry
_ -> scalecolor 0.4
5176 | View
-> scalecolor 1.0
5177 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5178 if l.pageno = hooverpageno
5181 if l.pageno = pageno
5189 let postdrawpage l linkindexbase
=
5190 match getopaque l.pageno with
5192 if tileready l l.pagex
l.pagey
5194 let x = l.pagedispx - l.pagex
5195 and y = l.pagedispy - l.pagey in
5197 match conf
.columns
with
5198 | Csingle
_ | Cmulti
_ ->
5199 (if conf
.hlinks
then 1 else 0)
5201 && not
(isbirdseye state
.mode) then 2 else 0)
5205 match state
.mode with
5206 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5209 postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
);
5214 let scrollindicator () =
5215 let sbw, ph
, sh = state
.uioh#
scrollph in
5216 let sbh, pw, sw = state
.uioh#scrollpw
in
5221 else (state
.winw
- sbw), state
.winw
5224 GlDraw.color (0.64, 0.64, 0.64);
5225 filledrect (float x0) 0. (float x1) (float state
.winh
);
5227 0. (float (state
.winh
- sbh))
5228 (float (wadjsb state
.winw
- 1)) (float state
.winh
)
5230 GlDraw.color (0.0, 0.0, 0.0);
5232 filledrect (float x0) ph
(float x1) (ph
+. sh);
5233 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5237 match state
.mstate
with
5238 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5241 | Msel
((x0, y0), (x1, y1)) ->
5242 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5243 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< "", -1, 0, 0) in
5244 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< "", -1, 0, 0) in
5245 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5248 let showrects = function [] -> () | rects
->
5250 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5251 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5253 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5255 if l.pageno = pageno
5257 let dx = float (l.pagedispx - l.pagex
) in
5258 let dy = float (l.pagedispy - l.pagey) in
5259 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5260 Raw.sets_float state
.vraw ~pos
:0
5265 GlArray.vertex `two state
.vraw
;
5266 GlArray.draw_arrays `triangle_strip
0 4;
5275 GlClear.color (scalecolor2 conf
.bgcolor
);
5276 GlClear.clear
[`
color];
5277 List.iter
drawpage state
.layout;
5279 match state
.mode with
5280 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5281 begin match getopaque pageno with
5283 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5290 | None
-> state
.rects
5295 let rec postloop linkindexbase
= function
5297 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5298 postloop linkindexbase rest
5302 postloop 0 state
.layout;
5304 begin match state
.mstate
with
5305 | Mzoomrect
((x0, y0), (x1, y1)) ->
5307 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5308 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5309 filledrect (float x0) (float y0) (float x1) (float y1);
5318 let zoomrect x y x1 y1 =
5321 and y0 = min
y y1 in
5322 gotoy (state
.y + y0);
5323 state
.anchor <- getanchor
();
5324 let zoom = (float state
.w) /. float (x1 - x0) in
5326 match conf
.fitmodel
, conf
.columns
with
5327 | FitPage
, Csplit
_ ->
5328 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5331 let adjw = wadjsb state
.winw
in
5333 then (adjw - state
.w) / 2
5336 state
.x <- (state
.x + margin) - x0;
5342 let g opaque l px py =
5343 match rectofblock
opaque px py with
5345 let x0 = a.(0) -. 20. in
5346 let x1 = a.(1) +. 20. in
5347 let y0 = a.(2) -. 20. in
5348 let zoom = (float state
.w) /. (x1 -. x0) in
5349 let pagey = getpagey
l.pageno in
5350 gotoy_and_clear_text (pagey + truncate
y0);
5351 state
.anchor <- getanchor
();
5352 let margin = (state
.w - l.pagew
)/2 in
5353 state
.x <- -truncate
x0 - margin;
5358 match conf
.columns
with
5360 showtext '
!'
"block zooming does not work properly in split columns mode"
5361 | _ -> onppundermouse g x y ()
5365 let winw = wadjsb state
.winw - 1 in
5366 let s = float x /. float winw in
5367 let destx = truncate
(float (state
.w + winw) *. s) in
5368 state
.x <- winw - destx;
5369 gotoy_and_clear_text state
.y;
5370 state
.mstate
<- Mscrollx
;
5374 let s = float y /. float state
.winh
in
5375 let desty = truncate
(float (state
.maxy - state
.winh
) *. s) in
5376 gotoy_and_clear_text desty;
5377 state
.mstate
<- Mscrolly
;
5380 let viewmulticlick clicks
x y mask
=
5381 let g opaque l px py =
5389 if markunder
opaque px py mark
5393 match getopaque l.pageno with
5395 | Some
opaque -> pipesel opaque cmd
5397 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5398 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5403 G.postRedisplay "viewmulticlick";
5404 onppundermouse g x y (fun () -> showtext '
!'
"Nothing to select") ();
5408 match conf
.columns
with
5410 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5413 let viewmouse button down
x y mask
=
5415 | n when (n == 4 || n == 5) && not down
->
5416 if Wsi.withctrl mask
5418 match state
.mstate
with
5419 | Mzoom
(oldn
, i
) ->
5427 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5429 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5431 let zoom = conf
.zoom -. incr in
5433 state
.mstate
<- Mzoom
(n, 0);
5435 state
.mstate
<- Mzoom
(n, i
+1);
5437 else state
.mstate
<- Mzoom
(n, 0)
5439 | _ -> state
.mstate
<- Mzoom
(n, 0)
5442 match state
.autoscroll
with
5443 | Some step
-> setautoscrollspeed step
(n=4)
5445 if conf
.wheelbypage
|| conf
.presentation
5454 then -conf
.scrollstep
5455 else conf
.scrollstep
5457 let incr = incr * 2 in
5458 let y = clamp incr in
5459 gotoy_and_clear_text y
5462 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5464 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
);
5465 gotoy_and_clear_text state
.y
5467 | 1 when Wsi.withshift mask
->
5468 state
.mstate
<- Mnone
;
5471 match unproject x y with
5472 | Some
(pageno, ux
, uy
) ->
5473 let cmd = Printf.sprintf
5475 conf
.stcmd state
.path pageno ux uy
5481 | 1 when Wsi.withctrl mask
->
5484 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5485 state
.mstate
<- Mpan
(x, y)
5488 state
.mstate
<- Mnone
5493 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5495 state
.mstate
<- Mzoomrect
(p, p)
5498 match state
.mstate
with
5499 | Mzoomrect
((x0, y0), _) ->
5500 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5501 then zoomrect x0 y0 x y
5504 G.postRedisplay "kill accidental zoom rect";
5510 | 1 when x > state
.winw - vscrollw () ->
5513 let _, position, sh = state
.uioh#
scrollph in
5514 if y > truncate
position && y < truncate
(position +. sh)
5515 then state
.mstate
<- Mscrolly
5518 state
.mstate
<- Mnone
5520 | 1 when y > state
.winh
- hscrollh () ->
5523 let _, position, sw = state
.uioh#scrollpw
in
5524 if x > truncate
position && x < truncate
(position +. sw)
5525 then state
.mstate
<- Mscrollx
5528 state
.mstate
<- Mnone
5530 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5533 let dest = if down
then getunder x y else Unone
in
5534 begin match dest with
5537 | Uremote
_ | Uremotedest
_
5538 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5541 | Unone
when down
->
5542 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5543 state
.mstate
<- Mpan
(x, y);
5545 | Unone
| Utext
_ ->
5550 state
.mstate
<- Msel
((x, y), (x, y));
5551 G.postRedisplay "mouse select";
5555 match state
.mstate
with
5558 | Mzoom
_ | Mscrollx
| Mscrolly
->
5559 state
.mstate
<- Mnone
5561 | Mzoomrect
((x0, y0), _) ->
5565 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5566 state
.mstate
<- Mnone
5568 | Msel
((x0, y0), (x1, y1)) ->
5569 let rec loop = function
5573 let a0 = l.pagedispy in
5574 let a1 = a0 + l.pagevh in
5575 let b0 = l.pagedispx in
5576 let b1 = b0 + l.pagevw in
5577 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5578 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5582 match getopaque l.pageno with
5585 match Ne.res Unix.pipe
with
5589 "can not create sel pipe: %s"
5593 Ne.clo fd
(fun msg
->
5594 dolog
"%s close failed: %s" what msg
)
5597 try popen
cmd [r, 0; w, -1]; true
5599 dolog
"can not execute %S: %s"
5606 G.postRedisplay "copysel";
5608 else clo "Msel pipe/w" w;
5609 clo "Msel pipe/r" r;
5611 dosel conf
.selcmd
();
5612 state
.roam
<- dosel conf
.paxcmd
;
5624 let birdseyemouse button down
x y mask
5625 (conf
, leftx
, _, hooverpageno
, anchor) =
5628 let rec loop = function
5631 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5632 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5634 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5640 | _ -> viewmouse button down
x y mask
5646 method key key mask
=
5647 begin match state
.mode with
5648 | Textentry
textentry -> textentrykeyboard key mask
textentry
5649 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5650 | View
-> viewkeyboard key mask
5651 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5655 method button button bstate
x y mask
=
5656 begin match state
.mode with
5658 | View
-> viewmouse button bstate
x y mask
5659 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5664 method multiclick clicks
x y mask
=
5665 begin match state
.mode with
5667 | View
-> viewmulticlick clicks
x y mask
5674 begin match state
.mode with
5676 | View
| Birdseye
_ | LinkNav
_ ->
5677 match state
.mstate
with
5678 | Mzoom
_ | Mnone
-> ()
5683 state
.mstate
<- Mpan
(x, y);
5685 then state
.x <- panbound (state
.x + dx);
5687 gotoy_and_clear_text y
5690 state
.mstate
<- Msel
(a, (x, y));
5691 G.postRedisplay "motion select";
5694 let y = min state
.winh
(max
0 y) in
5698 let x = min state
.winw (max
0 x) in
5701 | Mzoomrect
(p0
, _) ->
5702 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5703 G.postRedisplay "motion zoomrect";
5707 method pmotion
x y =
5708 begin match state
.mode with
5709 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
5710 let rec loop = function
5712 if hooverpageno
!= -1
5714 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
5715 G.postRedisplay "pmotion birdseye no hoover";
5718 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5719 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5721 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
5722 G.postRedisplay "pmotion birdseye hoover";
5732 match state
.mstate
with
5733 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5742 let past, _, _ = !r in
5744 let delta = now -. past in
5747 else r := (now, x, y)
5751 method infochanged
_ = ()
5754 let maxy = state
.maxy - (if conf
.maxhfit
then state
.winh
else 0) in
5757 then 0.0, float state
.winh
5758 else scrollph state
.y maxy
5763 let winw = wadjsb state
.winw in
5764 let fwinw = float winw in
5766 let sw = fwinw /. float state
.w in
5767 let sw = fwinw *. sw in
5768 max
sw (float conf
.scrollh
)
5771 let maxx = state
.w + winw in
5772 let x = winw - state
.x in
5773 let percent = float x /. float maxx in
5774 (fwinw -. sw) *. percent
5776 hscrollh (), position, sw
5780 match state
.mode with
5781 | LinkNav
_ -> "links"
5782 | Textentry
_ -> "textentry"
5783 | Birdseye
_ -> "birdseye"
5786 findkeyhash conf
modename
5788 method eformsgs
= true
5791 let adderrmsg src msg
=
5792 Buffer.add_string state
.errmsgs msg
;
5793 state
.newerrmsgs
<- true;
5797 let adderrfmt src fmt
=
5798 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
5802 let cl = splitatspace cmds
in
5804 try Scanf.sscanf
s fmt
f
5806 adderrfmt "remote exec"
5807 "error processing '%S': %s\n" cmds
(exntos exn
)
5810 | "reload" :: [] -> reload ()
5811 | "goto" :: args
:: [] ->
5812 scan args
"%u %f %f"
5814 let cmd, _ = state
.geomcmds
in
5816 then gotopagexy pageno x y
5819 gotopagexy pageno x y;
5822 state
.reprf
<- f state
.reprf
5824 | "goto1" :: args
:: [] -> scan args
"%u %f" gotopage
5825 | "gotor" :: args
:: [] ->
5827 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
5828 | "gotord" :: args
:: [] ->
5830 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
5831 | "rect" :: args
:: [] ->
5832 scan args
"%u %u %f %f %f %f"
5833 (fun pageno color x0 y0 x1 y1 ->
5834 onpagerect pageno (fun w h ->
5835 let _,w1,h1
,_ = getpagedim
pageno in
5836 let sw = float w1 /. float w
5837 and sh = float h1
/. float h in
5841 and y1s
= y1 *. sh in
5842 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
5844 state
.rects <- (pageno, color, rect) :: state
.rects;
5845 G.postRedisplay "rect";
5848 | "activatewin" :: [] -> Wsi.activatewin
()
5849 | "quit" :: [] -> raise Quit
5851 adderrfmt "remote command"
5852 "error processing remote command: %S\n" cmds
;
5856 let scratch = String.create
80 in
5857 let buf = Buffer.create
80 in
5860 try Some
(Unix.read fd
scratch 0 80)
5862 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
5863 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
5866 match tempfr () with
5872 if Buffer.length
buf > 0
5874 let s = Buffer.contents
buf in
5884 let pos = String.index_from
scratch ppos '
\n'
in
5885 if pos >= n then -1 else pos
5886 with Not_found
-> -1
5890 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
5891 let s = Buffer.contents
buf in
5897 Buffer.add_substring
buf scratch ppos
(n-ppos
);
5903 let remoteopen path =
5904 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
5906 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
5911 let trimcachepath = ref "" in
5912 let rcmdpath = ref "" in
5913 let pageno = ref None
in
5914 selfexec := Sys.executable_name
;
5917 [("-p", Arg.String
(fun s -> state
.password
<- s),
5918 "<password> Set password");
5922 Config.fontpath
:= s;
5923 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
5925 "<path> Set path to the user interface font");
5929 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
5930 Config.confpath
:= s),
5931 "<path> Set path to the configuration file");
5933 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
5934 "<page-number> Jump to page");
5936 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
5937 "<path> Set path to the trim cache file");
5939 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
5940 "<named-destination> Set named destination");
5942 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
5943 ("-cxack", Arg.Set
cxack, " Cut corners");
5945 ("-remote", Arg.String
(fun s -> rcmdpath := s),
5946 "<path> Set path to the remote commands source");
5948 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
5949 "<original-path> Set original path");
5951 ("-v", Arg.Unit
(fun () ->
5953 "%s\nconfiguration path: %s\n"
5957 exit
0), " Print version and exit");
5960 (fun s -> state
.path <- s)
5961 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5964 then selfexec := !selfexec ^
" -wtmode";
5966 if emptystr state
.path
5967 then (prerr_endline
"file name missing"; exit
1);
5969 if not
(Config.load ())
5970 then prerr_endline
"failed to load configuration";
5971 begin match !pageno with
5972 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
5976 let wsfd, winw, winh
= Wsi.init
(object (self)
5977 val mutable m_hack
= false
5978 val mutable m_clicks
= 0
5979 val mutable m_click_x
= 0
5980 val mutable m_click_y
= 0
5981 val mutable m_lastclicktime
= infinity
5983 method private cleanup
=
5984 state
.roam
<- noroam
;
5985 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
;
5986 method expose
= if not m_hack
then G.postRedisplay "expose"
5987 method visible
= G.postRedisplay "visible"
5988 method display = m_hack
<- false; display ()
5989 method reshape w h =
5991 m_hack
<- w < state
.winw && h < state
.winh
;
5993 method mouse
b d x y m =
5994 if d && canselect ()
5996 (* http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx *)
6002 if abs
x - m_click_x
> 10
6003 || abs
y - m_click_y
> 10
6004 || abs_float
(t -. m_lastclicktime
) > 0.3
6006 m_clicks
<- m_clicks
+ 1;
6007 m_lastclicktime
<- t;
6011 G.postRedisplay "cleanup";
6012 state
.uioh <- state
.uioh#button
b d x y m;
6014 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6019 m_lastclicktime
<- infinity
;
6020 state
.uioh <- state
.uioh#button
b d x y m
6024 state
.uioh <- state
.uioh#button
b d x y m
6027 state
.mpos
<- (x, y);
6028 state
.uioh <- state
.uioh#motion
x y
6029 method pmotion
x y =
6030 state
.mpos
<- (x, y);
6031 state
.uioh <- state
.uioh#pmotion
x y
6033 let mascm = m land (
6034 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6037 let x = state
.x and y = state
.y in
6039 if x != state
.x || y != state
.y then self#cleanup
6041 match state
.keystate
with
6043 let km = k
, mascm in
6046 let modehash = state
.uioh#
modehash in
6047 try Hashtbl.find modehash km
6049 try Hashtbl.find (findkeyhash conf
"global") km
6050 with Not_found
-> KMinsrt
(k
, m)
6052 | KMinsrt
(k
, m) -> keyboard k
m
6053 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6054 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6056 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6057 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6058 state
.keystate
<- KSnone
6059 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k
&& m'
land mascm = m'
->
6060 state
.keystate
<- KSinto
(keys
, insrt
)
6062 state
.keystate
<- KSnone
6065 state
.mpos
<- (x, y);
6066 state
.uioh <- state
.uioh#pmotion
x y
6067 method leave = state
.mpos
<- (-1, -1)
6068 method winstate wsl
= state
.winstate
<- wsl
; m_hack
<- false
6069 method quit
= raise Quit
6070 end) conf
.cwinw conf
.cwinh
(platform
= Posx
) in
6075 List.exists
GlMisc.check_extension
6076 [ "GL_ARB_texture_rectangle"
6077 ; "GL_EXT_texture_recangle"
6078 ; "GL_NV_texture_rectangle" ]
6080 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6083 let r = GlMisc.get_string `renderer
in
6084 let p = "Mesa DRI Intel(" in
6085 let l = String.length
p in
6086 String.length
r > l && String.sub
r 0 l = p
6089 defconf
.sliceheight
<- 1024;
6090 defconf
.texcount
<- 32;
6091 defconf
.usepbo
<- true;
6095 match Ne.res Unix.pipe
with
6097 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
6101 match Ne.res Unix.pipe
with
6103 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
6113 setcheckers conf
.checkers
;
6115 if conf
.redirectstderr
6118 let s = Buffer.contents state
.errmsgs ^
6119 (match state
.errfd
with
6121 let s = String.create
(80*24) in
6124 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
6126 then Unix.read fd
s 0 (String.length
s)
6132 else String.sub
s 0 n
6136 try ignore
(Unix.write state
.stderr
s 0 (String.length
s))
6137 with exn
-> print_endline
(exntos exn
)
6142 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6143 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6144 !Config.fontpath
, !trimcachepath,
6145 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
6147 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6150 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6152 opendoc state
.path state
.password
;
6156 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6159 if nonemptystr
!rcmdpath
6160 then remoteopen !rcmdpath
6165 let rec loop deadline
=
6167 match state
.errfd
with
6168 | None
-> [state
.sr
; state
.wsfd]
6169 | Some fd
-> [state
.sr
; state
.wsfd; fd
]
6174 | Some fd
-> fd
:: r
6178 state
.redisplay
<- false;
6185 if deadline
= infinity
6187 else max
0.0 (deadline
-. now)
6192 try Unix.select
r [] [] timeout
6193 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6199 if state
.ghyll
== noghyll
6201 match state
.autoscroll
with
6202 | Some step
when step
!= 0 ->
6203 let y = state
.y + step
in
6207 else if y >= state
.maxy then 0 else y
6210 if state
.mode = View
6211 then state
.text <- "";
6214 else deadline
+. 0.01
6219 let rec checkfds = function
6221 | fd
:: rest
when fd
= state
.sr
->
6222 let cmd = readcmd state
.sr
in
6226 | fd
:: rest
when fd
= state
.wsfd ->
6230 | fd
:: rest
when Some fd
= !optrfd ->
6231 begin match remote fd
with
6232 | None
-> optrfd := remoteopen !rcmdpath;
6233 | opt -> optrfd := opt
6238 let s = String.create
80 in
6239 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
6240 if conf
.redirectstderr
6242 Buffer.add_substring state
.errmsgs
s 0 n;
6243 state
.newerrmsgs
<- true;
6244 state
.redisplay
<- true;
6247 prerr_string
(String.sub
s 0 n);
6255 if deadline
= infinity
6259 match state
.autoscroll
with
6260 | Some step
when step
!= 0 -> deadline1
6261 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6269 Config.save
leavebirdseye;