7 let selfexec = ref E.s
;;
8 let ignoredoctitlte = ref false;;
9 let layouth = ref ~
-1;;
10 let checkerstexid = ref None
;;
12 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
18 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
21 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
24 if ((conf
.scrollb
land scrollbhv
!= 0) && (state
.w
> state
.winw
))
25 || state
.uioh#alwaysscrolly
32 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
33 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
37 if emptystr conf
.pathlauncher
38 then dolog
"%s" state
.path
41 Str.global_replace
Utils.Re.percent state
.path conf
.pathlauncher
in
42 match spawn
command [] with
44 | exception exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
48 let getopaque pageno
=
49 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
50 with Not_found
-> None
53 let pagetranslatepoint l x y
=
54 let dy = y
- l
.pagedispy
in
55 let y = dy + l
.pagey
in
56 let dx = x
- l
.pagedispx
in
57 let x = dx + l
.pagex
in
61 let onppundermouse g
x y d
=
64 begin match getopaque l
.pageno
with
66 let x0 = l
.pagedispx
in
67 let x1 = x0 + l
.pagevw
in
68 let y0 = l
.pagedispy
in
69 let y1 = y0 + l
.pagevh
in
70 if y >= y0 && y <= y1 && x >= x0 && x <= x1
72 let px, py
= pagetranslatepoint l
x y in
73 match g opaque l
px py
with
85 let g opaque l
px py
=
88 match rectofblock opaque
px py
with
89 | Some
[|x0;x1;y0;y1|] ->
90 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
91 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
92 state
.rects
<- [l
.pageno
, color, rect];
93 postRedisplay
"getunder";
96 let under = whatsunder opaque
px py
in
97 if under = Unone
then None
else Some
under
99 onppundermouse g x y Unone
104 match unproject opaque
x y with
105 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
108 onppundermouse g x y None
;
112 state
.text
<- Printf.sprintf
"%c%s" c s
;
113 postRedisplay
"showtext";
116 let impmsg fmt
= Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;;
118 let pipesel opaque cmd
=
120 then pipef ~closew
:false "pipesel"
123 postRedisplay
"pipesel"
128 let g opaque l
px py
=
129 if markunder opaque
px py conf
.paxmark
132 match getopaque l
.pageno
with
134 | Some opaque
-> pipesel opaque conf
.paxcmd
138 postRedisplay
"paxunder";
139 if conf
.paxmark
= Mark_page
142 match getopaque l
.pageno
with
144 | Some opaque
-> clearmark opaque
) state
.layout
;
145 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
148 let undertext = function
151 | Utext s
-> "font: " ^ s
152 | Uannotation
(opaque
, slinkindex
) ->
153 "annotation: " ^ getannotcontents opaque slinkindex
156 let updateunder x y =
157 match getunder x y with
158 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
160 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
161 Wsi.setcursor
Wsi.CURSOR_INFO
163 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
164 Wsi.setcursor
Wsi.CURSOR_TEXT
166 if conf
.underinfo
then showtext 'a'
"nnotation";
167 Wsi.setcursor
Wsi.CURSOR_INFO
170 let showlinktype under =
171 if conf
.underinfo
&& under != Unone
172 then showtext ' '
@@ undertext under
175 let intentry_with_suffix text key
=
177 match [@warning
"-4"] key
with
178 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
179 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
180 addchar
text @@ asciilower c
182 state
.text <- "invalid key";
189 let b = Buffer.create
16 in
192 let b = Buffer.to_bytes
b in
193 wcmd state
.ss
b @@ Bytes.length
b
197 let nogeomcmds = function
198 | s
, [] -> emptystr s
202 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
203 let rec fold accu n
=
204 if n
= Array.length
b
207 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n
) in
210 || n
= state
.pagecount
- coverB
211 || (n
- coverA
) mod columns
= columns
- 1)
217 let pagey = max
0 (y - vy
) in
218 let pagedispy = if pagey > 0 then 0 else vy
- y in
219 let pagedispx, pagex
=
221 if n
= coverA
- 1 || n
= state
.pagecount
- coverB
222 then x + (sw
- w
) / 2
230 let vw = sw
- pagedispx in
231 let pw = w
- pagex
in
234 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
235 if pagevw > 0 && pagevh > 0
245 ; pagedispx = pagedispx
246 ; pagedispy = pagedispy
254 if Array.length
b = 0
256 else List.rev
(fold [] (page_of_y
y))
259 let layoutS (columns
, b) x y sw sh
=
260 let rec fold accu n
=
261 if n
= Array.length
b
264 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n
) in
272 let pagey = max
0 (y - vy
) in
273 let pagedispy = if pagey > 0 then 0 else vy
- y in
274 let pagedispx, pagex
=
288 let pagecolw = pagew
/columns
in
291 then pagedispx + ((sw
- pagecolw) / 2)
295 let vw = sw
- pagedispx in
296 let pw = pagew
- pagex
in
299 let pagevw = min
pagevw pagecolw in
300 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
301 if pagevw > 0 && pagevh > 0
311 ; pagedispx = pagedispx
312 ; pagedispy = pagedispy
313 ; pagecol
= n
mod columns
323 let layout x y sw sh
=
324 if nogeomcmds state
.geomcmds
326 match conf
.columns
with
327 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
328 | Cmulti c
-> layoutN c
x y sw sh
329 | Csplit s
-> layoutS s
x y sw sh
333 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
334 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
337 let tilex = l
.pagex
mod conf
.tilew
in
338 let tiley = l
.pagey mod conf
.tileh
in
340 let col = l
.pagex
/ conf
.tilew
in
341 let row = l
.pagey / conf
.tileh
in
343 let rec rowloop row y0 dispy h
=
346 let dh = conf
.tileh
- y0 in
348 let rec colloop col x0 dispx w
=
351 let dw = conf
.tilew
- x0 in
353 f col row dispx dispy
x0 y0 dw dh;
354 colloop (col+1) 0 (dispx
+dw) (w
-dw)
356 colloop col tilex l
.pagedispx l
.pagevw;
357 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
359 if l
.pagevw > 0 && l
.pagevh > 0
360 then rowloop row tiley l
.pagedispy l
.pagevh;
363 let gettileopaque l
col row =
364 let key = l
.pageno
, state
.gen
, conf
.colorspace
,
365 conf
.angle
, l
.pagew
, l
.pageh
, col, row in
366 try Some
(Hashtbl.find state
.tilemap
key)
367 with Not_found
-> None
370 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
371 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
372 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
375 let drawtiles l
color =
378 let f col row x y tilex tiley w h
=
379 match gettileopaque l
col row with
380 | Some
(opaque
, _
, t
) ->
381 let params = x, y, w
, h
, tilex, tiley in
383 then GlTex.env
(`mode `blend
);
384 drawtile
params opaque
;
386 then GlTex.env
(`mode `modulate
);
390 let s = Printf.sprintf
"%d[%d,%d] %f sec" l
.pageno
col row t
in
391 let w = measurestr fstate
.fontsize
s in
392 GlDraw.color (0.0, 0.0, 0.0);
397 (float (y + fstate
.fontsize
+ 2));
399 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
405 let w = let lw = state
.winw
- x in min
lw w
406 and h
= let lh = state
.winh
- y in min
lh h
409 then GlTex.env
(`mode `blend
);
410 begin match !checkerstexid with
412 Gl.enable `texture_2d
;
413 GlTex.bind_texture ~target
:`texture_2d id
;
417 and y1 = float (y+h
) in
419 let tw = float w /. 16.0
420 and th
= float h
/. 16.0 in
421 let tx0 = float tilex /. 16.0
422 and ty0
= float tiley /. 16.0 in
424 and ty1
= ty0
+. th
in
425 Raw.sets_float
Glutils.vraw ~pos
:0
426 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
427 Raw.sets_float
Glutils.traw ~pos
:0
428 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
429 GlArray.vertex `two
Glutils.vraw
;
430 GlArray.tex_coord `two
Glutils.traw
;
431 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
432 Gl.disable `texture_2d
;
435 GlDraw.color (1.0, 1.0, 1.0);
436 filledrect
(float x) (float y) (float (x+w)) (float (y+h
));
439 then GlTex.env
(`mode `modulate
);
440 if w > 128 && h
> fstate
.fontsize
+ 10
442 let c = if conf
.invert
then 1.0 else 0.0 in
443 GlDraw.color (c, c, c);
446 then (col*conf
.tilew
, row*conf
.tileh
)
449 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
458 let pagevisible layout n
= List.exists
(fun l
-> l
.pageno
= n
) layout;;
460 let tilevisible1 l
x y =
462 and ax1
= l
.pagex
+ l
.pagevw
464 and ay1
= l
.pagey + l
.pagevh in
468 let bx1 = min
(bx0 + conf
.tilew
) l
.pagew
469 and by1
= min
(by0
+ conf
.tileh
) l
.pageh
in
471 let rx0 = max
ax0 bx0
472 and ry0
= max ay0 by0
473 and rx1
= min ax1
bx1
474 and ry1
= min ay1 by1
in
476 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
480 let tilevisible layout n
x y =
481 let rec findpageinlayout m
= function
482 | l
:: rest
when l
.pageno
= n
->
483 tilevisible1 l
x y || (
484 match conf
.columns
with
485 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
486 | Csplit _
| Csingle _
| Cmulti _
-> false
488 | _
:: rest
-> findpageinlayout 0 rest
491 findpageinlayout 0 layout;
494 let tileready l
x y =
495 tilevisible1 l
x y &&
496 gettileopaque l
(x/conf
.tilew
) (y/conf
.tileh
) != None
499 let tilepage n p
layout =
500 let rec loop = function
504 let f col row _ _ _ _ _ _
=
505 if state
.currently
= Idle
507 match gettileopaque l
col row with
510 let x = col*conf
.tilew
511 and y = row*conf
.tileh
in
513 let w = l
.pagew
- x in
517 let h = l
.pageh
- y in
522 then getpbo
w h conf
.colorspace
525 wcmd "tile %s %d %d %d %d %s" (~
> p
) x y w h (~
> pbo);
528 l
, p
, conf
.colorspace
, conf
.angle
,
529 state
.gen
, col, row, conf
.tilew
, conf
.tileh
538 if nogeomcmds state
.geomcmds
542 let preloadlayout x y sw sh
=
543 let y = if y < sh
then 0 else y - sh
in
544 let x = min
0 (x + sw
) in
552 if state
.currently
= Idle
556 begin match getopaque l
.pageno
with
558 wcmd "page %d %d" l
.pageno l
.pagedimno
;
559 state
.currently
<- Loading
(l
, state
.gen
);
561 tilepage l
.pageno opaque pages
;
566 if nogeomcmds state
.geomcmds
572 if conf
.preload && state
.currently
= Idle
573 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
576 let layoutready layout =
577 let rec fold all ls
=
580 let seen = ref false in
581 let allvisible = ref true in
582 let foo col row _ _ _ _ _ _
=
584 allvisible := !allvisible &&
585 begin match gettileopaque l
col row with
591 fold (!seen && !allvisible) rest
594 let alltilesvisible = fold true layout in
599 let y = bound
y 0 state
.maxy in
601 let layout = layout x y state
.winw state
.winh
in
602 postRedisplay
"gotoxy ready";
607 state
.layout <- layout;
608 begin match state
.mode
with
611 | Ltexact
(pageno
, linkno
) ->
612 let rec loop = function
614 state
.lnava
<- Some
(pageno
, linkno
);
615 state
.mode
<- LinkNav
(Ltgendir
0)
616 | l
:: _
when l
.pageno
= pageno
->
617 begin match getopaque pageno
with
618 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
620 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
621 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
622 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
623 then state
.mode
<- LinkNav
(Ltgendir
0)
625 | _
:: rest
-> loop rest
628 | Ltnotready _
| Ltgendir _
-> ()
630 | Birdseye _
| Textentry _
| View
-> ()
632 begin match state
.mode
with
633 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
634 if not
(pagevisible layout pageno
)
636 match state
.layout with
639 state
.mode
<- Birdseye
(conf
, leftx
, l
.pageno
, hooverpageno
, anchor
)
643 | Ltnotready
(_
, dir
)
646 let rec loop = function
649 match getopaque l
.pageno
with
650 | None
-> Ltnotready
(l
.pageno
, dir
)
655 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
656 else if dir
> 0 then LDfirst
else LDlast
661 | Lnotfound
-> loop rest
663 showlinktype (getlink opaque n
);
664 Ltexact
(l
.pageno
, n
)
668 state
.mode
<- LinkNav
linknav
671 | Textentry _
| View
-> ()
676 let mx, my
= state
.mpos
in
681 let conttiling pageno opaque
=
682 tilepage pageno opaque
684 then preloadlayout state
.x state
.y state
.winw state
.winh
689 if not conf
.verbose
then state
.text <- E.s;
693 let getanchory (n
, top
, dtop
) =
694 let y, h = getpageyh n
in
697 let ips = calcips
h in
698 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
699 else y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
702 let addnav () = getanchor
() |> cbput state
.hists
.nav
;;
703 let addnavnorc () = getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;;
706 let anchor = cbgetc state
.hists
.nav dir
in
711 let y, h = getpageyh n
in
712 let y = y + (truncate
(top
*. float h)) in
716 let gotopage1 n top
=
717 let y = getpagey n
in
723 Glutils.redisplay
:= false;
728 match state
.geomcmds
with
729 | ps
, [] when emptystr ps
->
731 state
.geomcmds
<- s, [];
732 | ps
, [] -> state
.geomcmds
<- ps
, [s, f];
733 | ps
, (s'
, _
) :: rest
when s'
= s -> state
.geomcmds
<- ps
, ((s, f) :: rest
);
734 | ps
, cmds
-> state
.geomcmds
<- ps
, ((s, f) :: cmds
);
738 Hashtbl.iter
(fun _ opaque
-> wcmd "freepage %s" (~
> opaque
)) state
.pagemap
;
739 Hashtbl.clear state
.pagemap
;
743 if not
(Queue.is_empty state
.tilelru
)
745 Queue.iter
(fun (k
, p
, s) ->
746 wcmd "freetile %s" (~
> p
);
747 state
.memused
<- state
.memused
- s;
748 Hashtbl.remove state
.tilemap k
;
750 state
.uioh#infochanged Memused
;
751 Queue.clear state
.tilelru
;
757 let h = truncate
(float h*.conf
.zoom
) in
758 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
764 let sl = keystostrlist conf
in
766 function | [] -> accu
767 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
768 in Help.makehelp conf
.urilauncher
769 @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
772 let opendoc path password
=
774 state
.password
<- password
;
775 state
.gen
<- state
.gen
+ 1;
777 state
.outlines
<- [||];
780 setaalevel conf
.aalevel
;
781 setpapercolor conf
.papercolor
;
783 if emptystr state
.origin
787 Wsi.settitle
("llpp " ^ mbtoutf8
(Filename.basename
titlepath));
788 wcmd "open %d %d %s\000%s\000%s\000"
789 (btod conf
.usedoccss
) !layouth
790 path password conf
.css
;
791 invalidate "reqlayout"
793 wcmd "reqlayout %d %d %d %s\000"
794 conf
.angle
(FMTE.to_int conf
.fitmodel
)
795 (stateh state
.winh
) state
.nameddest
801 state
.anchor <- getanchor
();
802 state
.reload <- Some
(state
.x, state
.y, now
());
803 opendoc state
.path state
.password
;
806 let scalecolor c = let c = c *. conf
.colorscale
in (c, c, c);;
807 let scalecolor2 (r
, g, b) =
808 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
811 let docolumns columns
=
814 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
815 let rec loop pageno
pdimno pdim
y ph pdims
=
816 if pageno
!= state
.pagecount
818 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
820 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
825 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
827 y + (if conf
.presentation
828 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
829 else (if pageno
= 0 then 0 else conf
.interpagespace
))
831 a.(pageno
) <- (pdimno, x, y, pdim
);
832 loop (pageno
+1) pdimno pdim
(y + h) h pdims
834 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
835 conf
.columns
<- Csingle
a;
837 | Cmulti
((columns
, coverA
, coverB
), _
) ->
838 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
839 let rec loop pageno
pdimno pdim
x y rowh pdims
=
841 if m
= pageno
then () else
842 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
845 let y = y + (rowh
- h) / 2 in
846 a.(m
) <- (pdimno, x, y, pdim
);
850 if pageno
= state
.pagecount
851 then fixrow (((pageno
- 1) / columns
) * columns
)
853 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
855 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
857 | _
-> pdimno, pdim
, pdims
860 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
862 let x = (state
.winw
- w) / 2 in
864 if conf
.presentation
then calcips
h else conf
.interpagespace
in
868 if (pageno
- coverA
) mod columns
= 0
870 let x = max
0 (state
.winw
- state
.w) / 2 in
874 let ips = calcips
h in
875 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
877 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
881 else x, y, max rowh
h
885 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
888 if pageno
= columns
&& conf
.presentation
890 let ips = calcips rowh
in
891 for i
= 0 to pred columns
893 let (pdimno, x, y, pdim
) = a.(i
) in
894 a.(i
) <- (pdimno, x, y+ips, pdim
)
900 fixrow (pageno
- columns
);
905 a.(pageno
) <- (pdimno, x, y, pdim
);
906 let x = x + w + xoff
*2 + conf
.interpagespace
in
907 loop (pageno
+1) pdimno pdim
x y rowh' pdims
909 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
910 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
913 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
914 let rec loop pageno
pdimno pdim
y pdims
=
915 if pageno
!= state
.pagecount
917 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
919 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
921 | _
-> pdimno, pdim
, pdims
924 let rec loop1 n
x y =
925 if n
= c then y else (
926 a.(pageno
*c + n
) <- (pdimno, x, y, pdim
);
927 loop1 (n
+1) (x+cw) (y + h + conf
.interpagespace
)
930 let y = loop1 0 0 y in
931 loop (pageno
+1) pdimno pdim
y pdims
933 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
934 conf
.columns
<- Csplit
(c, a);
938 docolumns conf
.columns
;
939 state
.maxy <- calcheight
();
940 if state
.reprf
== noreprf
942 match state
.mode
with
943 | Birdseye
(_
, _
, pageno
, _
, _
) ->
944 let y, h = getpageyh pageno
in
945 let top = (state
.winh
- h) / 2 in
946 gotoxy state
.x (max
0 (y - top))
947 | Textentry _
| View
| LinkNav _
->
948 let y = getanchory state
.anchor in
949 let y = min
y (state
.maxy - state
.winh
) in
954 state
.reprf
<- noreprf
;
958 let reshape ?
(firsttime
=false) w h =
959 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
960 if not firsttime
&& nogeomcmds state
.geomcmds
961 then state
.anchor <- getanchor
();
964 let w = truncate
(float w *. conf
.zoom
) in
967 setfontsize fstate
.fontsize
;
968 GlMat.mode `modelview
;
969 GlMat.load_identity
();
971 GlMat.mode `projection
;
972 GlMat.load_identity
();
973 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
974 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
975 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
980 else float state
.x /. float state
.w
982 invalidate "geometry"
986 then state
.x <- truncate
(relx *. float w);
988 match conf
.columns
with
990 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
991 | Csplit
(c, _
) -> w * c
993 wcmd "geometry %d %d %d" w (stateh h) (FMTE.to_int conf
.fitmodel
)
998 let len = Queue.length state
.tilelru
in
999 let layout = lazy (if conf
.preload
1000 then preloadlayout state
.x state
.y state
.winw state
.winh
1001 else state
.layout) in
1003 if state
.memused
> conf
.memlimit
1007 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1008 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1009 let (_
, pw, ph
, _
) = getpagedim
n in
1011 && colorspace
= conf
.colorspace
1012 && angle
= conf
.angle
1016 let x = col*conf
.tilew
and y = row*conf
.tileh
in
1017 tilevisible (Lazy.force_val
layout) n x y
1019 then Queue.push lruitem state
.tilelru
1022 wcmd "freetile %s" (~
> p
);
1023 state
.memused
<- state
.memused
- s;
1024 state
.uioh#infochanged Memused
;
1025 Hashtbl.remove state
.tilemap k
;
1033 let onpagerect pageno
f =
1035 match conf
.columns
with
1036 | Cmulti
(_
, b) -> b
1038 | Csplit
(_
, b) -> b
1040 if pageno
>= 0 && pageno
< Array.length
b
1042 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1046 let gotopagexy1 pageno
x y =
1047 let _,w1
,h1
,leftx
= getpagedim pageno
in
1048 let top = y /. (float h1
) in
1049 let left = x /. (float w1
) in
1050 let py, w, h = getpageywh pageno
in
1051 let wh = state
.winh
in
1052 let x = left *. (float w) in
1053 let x = leftx
+ state
.x + truncate
x in
1055 if x < 0 || x >= state
.winw
1059 let pdy = truncate
(top *. float h) in
1060 let y'
= py + pdy in
1061 let dy = y'
- state
.y in
1063 if x != state
.x || not
(dy > 0 && dy < wh)
1065 if conf
.presentation
1067 if abs
(py - y'
) > wh
1074 if state
.x != sx || state
.y != sy
1076 else gotoxy state
.x state
.y;
1079 let gotopagexy pageno
x y =
1080 match state
.mode
with
1081 | Birdseye
_ -> gotopage pageno
0.0
1082 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 pageno
x y
1085 let getpassword () =
1086 let passcmd = getenvdef
"LLPP_ASKPASS" conf
.passcmd in
1089 else getcmdoutput
(fun s ->
1090 impmsg "error getting password: %s" s;
1091 dolog
"%s" s) passcmd;
1094 let pgoto opaque pageno
x y =
1095 let pdimno = getpdimno pageno
in
1096 let x, y = project opaque pageno
pdimno x y in
1097 gotopagexy pageno
x y;
1101 (* dolog "%S" cmds; *)
1102 let spl = splitatchar cmds ' '
in
1104 try Scanf.sscanf
s fmt
f
1106 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1109 let addoutline outline
=
1110 match state
.currently
with
1111 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1112 | Idle
-> state
.currently
<- Outlining
[outline
]
1113 | Loading
_ | Tiling
_ ->
1114 dolog
"invalid outlining state";
1115 logcurrently state
.currently
1120 state
.uioh#infochanged Pdim
;
1122 | "clearrects", "" ->
1123 state
.rects
<- state
.rects1
;
1124 postRedisplay
"clearrects";
1126 | "continue", args
->
1127 let n = scan args
"%u" (fun n -> n) in
1128 state
.pagecount
<- n;
1129 begin match state
.currently
with
1131 state
.currently
<- Idle
;
1132 state
.outlines
<- Array.of_list
(List.rev l
)
1133 | Idle
| Loading
_ | Tiling
_ -> ()
1136 let cur, cmds
= state
.geomcmds
in
1137 if emptystr
cur then error
"empty geomcmd";
1139 begin match List.rev cmds
with
1141 state
.geomcmds
<- E.s, [];
1145 state
.geomcmds
<- s, List.rev rest
;
1147 postRedisplay
"continue";
1153 if conf
.verbose
then showtext ' ' args
1156 Buffer.add_string state
.errmsgs args
;
1157 state
.newerrmsgs
<- true;
1158 postRedisplay
"error message"
1160 | "progress", args
->
1161 let progress, text =
1163 (fun f pos
-> f, String.sub args pos
(String.length args
- pos
))
1166 state
.progress <- progress;
1167 postRedisplay
"progress"
1169 | "firstmatch", args
->
1170 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1171 scan args
"%u %d %f %f %f %f %f %f %f %f"
1172 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1173 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1175 let y = (getpagey
pageno) + truncate
y0 in
1177 if (state
.x < - truncate
x0) || (state
.x > state
.winw
- truncate
x1)
1178 then state
.winw
/2 - truncate
(x0 /. 2. +. x1 /. 2.)
1183 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1184 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1187 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1188 scan args
"%u %d %f %f %f %f %f %f %f %f"
1189 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1190 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1192 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1194 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1197 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1198 let pageopaque = ~
< pageopaques in
1199 begin match state
.currently
with
1200 | Loading
(l
, gen
) ->
1201 vlog
"page %d took %f sec" l
.pageno t
;
1202 Hashtbl.replace state
.pagemap
(l
.pageno, gen
) pageopaque;
1203 let preloadedpages =
1205 then preloadlayout state
.x state
.y state
.winw state
.winh
1209 let set = List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
1210 IntSet.empty
preloadedpages
1213 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1214 if not
(IntSet.mem
pageno set)
1216 wcmd "freepage %s" (~
> opaque
);
1222 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1225 state
.currently
<- Idle
;
1228 tilepage l
.pageno pageopaque state
.layout;
1230 load preloadedpages;
1231 let visible = pagevisible state
.layout l
.pageno in
1234 match state
.mode
with
1235 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1236 if pageno = l
.pageno
1241 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1242 else if dir
> 0 then LDfirst
else LDlast
1244 findlink
pageopaque ld
1249 showlinktype (getlink
pageopaque n);
1250 state
.mode
<- LinkNav
(Ltexact
(l
.pageno, n))
1252 | LinkNav
(Ltgendir
_)
1253 | LinkNav
(Ltexact
_)
1259 if visible && layoutready state
.layout
1260 then postRedisplay
"page";
1263 | Idle
| Tiling
_ | Outlining
_ ->
1264 dolog
"Inconsistent loading state";
1265 logcurrently state
.currently
;
1270 let (x, y, opaques
, size
, t
) =
1271 scan args
"%u %u %s %u %f" (fun x y p size t
-> (x, y, p
, size
, t
))
1273 let opaque = ~
< opaques
in
1274 begin match state
.currently
with
1275 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1276 vlog
"tile %d [%d,%d] took %f sec" l
.pageno col row t
;
1279 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1281 wcmd "freetile %s" (~
> opaque);
1282 state
.currently
<- Idle
;
1286 puttileopaque l
col row gen cs angle
opaque size t
;
1287 state
.memused
<- state
.memused
+ size
;
1288 state
.uioh#infochanged Memused
;
1290 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
1291 opaque, size
) state
.tilelru
;
1293 state
.currently
<- Idle
;
1295 && conf
.colorspace
= cs
1296 && conf
.angle
= angle
1297 && tilevisible state
.layout l
.pageno x y
1298 then conttiling l
.pageno pageopaque;
1300 preload state
.layout;
1302 && conf
.colorspace
= cs
1303 && conf
.angle
= angle
1304 && tilevisible state
.layout l
.pageno x y
1305 && layoutready state
.layout
1306 then postRedisplay
"tile nothrottle";
1309 | Idle
| Loading
_ | Outlining
_ ->
1310 dolog
"Inconsistent tiling state";
1311 logcurrently state
.currently
;
1316 let (n, w, h, _) as pdim
=
1317 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1320 match conf
.fitmodel
with
1322 | FitPage
| FitProportional
->
1323 match conf
.columns
with
1324 | Csplit
_ -> (n, w, h, 0)
1325 | Csingle
_ | Cmulti
_ -> pdim
1327 state
.pdims
<- pdim :: state
.pdims
;
1328 state
.uioh#infochanged Pdim
1331 let (l
, n, t
, h, pos
) =
1332 scan args
"%u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
1334 let s = String.sub args pos
(String.length args
- pos
) in
1335 addoutline (s, l
, Oanchor
(n, float t
/. float h, 0.0))
1338 let (l
, len, pos
) = scan args
"%u %u %n" (fun l
len pos
-> l
, len, pos
) in
1339 let s = String.sub args pos
len in
1340 let pos2 = pos
+ len + 1 in
1341 let uri = String.sub args
pos2 (String.length args
- pos2) in
1342 addoutline (s, l
, Ouri
uri)
1345 let (l
, pos
) = scan args
"%u %n" (fun l pos
-> l
, pos
) in
1346 let s = String.sub args pos
(String.length args
- pos
) in
1347 addoutline (s, l
, Onone
)
1350 let (n, l
, t
) = scan args
"%u %d %d" (fun n l t
-> n, l
, t
) in
1351 state
.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
1354 let c, v
= splitatchar args '
\t'
in
1361 if not
!ignoredoctitlte then Wsi.settitle v
;
1365 if let len = String.length
c in
1366 len > 6 && ((String.sub
c (len-4) 4) = "date")
1368 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1370 let b = Buffer.create
10 in
1371 Printf.bprintf
b "%s\t" c;
1374 Buffer.add_substring
b v p l
;
1375 Buffer.add_char
b c;
1376 with exn
-> Buffer.add_string
b @@ exntos exn
1384 Buffer.add_char
b '
['
;
1385 Buffer.add_string
b v
;
1386 Buffer.add_char
b '
]'
;
1393 state
.docinfo
<- (1, s) :: state
.docinfo
1396 state
.docinfo
<- List.rev state
.docinfo
;
1397 state
.uioh#infochanged Docinfo
1401 then Wsi.settitle
"Wrong password";
1402 let password = getpassword () in
1403 if emptystr
password
1404 then error
"document is password protected"
1405 else opendoc state
.path
password
1407 | _ -> error
"unknown cmd `%S'" cmds
1412 let action = function
1413 | HCprev
-> cbget cb ~
-1
1414 | HCnext
-> cbget cb
1
1415 | HCfirst
-> cbget cb ~
-(cb
.rc)
1416 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1417 and cancel
() = cb
.rc <- rc
1421 let search pattern forward
=
1422 match conf
.columns
with
1423 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1424 | Csingle
_ | Cmulti
_ ->
1425 if nonemptystr pattern
1428 match state
.layout with
1430 | l
:: _ -> l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
1432 wcmd "search %d %d %d %d,%s\000"
1433 (btod conf
.icase
) pn py (btod forward
) pattern
;
1436 let intentry text key =
1438 if emptystr
text && key = Keys.Ascii '
-'
1439 then addchar
text '
-'
1441 match [@warning
"-4"] key with
1442 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1444 state
.text <- "invalid key";
1454 let l = String.length
s in
1455 let rec loop pos
n =
1459 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1460 loop (pos
+1) (n*26 + m)
1463 let rec loop n = function
1466 match getopaque l.pageno with
1467 | None
-> loop n rest
1469 let m = getlinkcount
opaque in
1472 let under = getlink
opaque n in
1474 else loop (n-m) rest
1476 loop n state
.layout;
1479 let linknentry text key = match [@warning
"-4"] key with
1480 | Keys.Ascii
('
a'
.. 'z'
as c) ->
1481 let text = addchar
text c in
1482 linknact (fun under -> state
.text <- undertext under) text;
1485 state
.text <- Printf.sprintf
"invalid key %s" @@ Keys.to_string
key;
1489 let textentry text key = match [@warning
"-4"] key with
1490 | Keys.Ascii
c -> TEcont
(addchar
text c)
1491 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1495 let reqlayout angle fitmodel
=
1496 if nogeomcmds state
.geomcmds
1497 then state
.anchor <- getanchor
();
1498 conf
.angle
<- angle
mod 360;
1501 match state
.mode
with
1502 | LinkNav
_ -> state
.mode
<- View
1503 | Birdseye
_ | Textentry
_ | View
-> ()
1505 conf
.fitmodel
<- fitmodel
;
1506 invalidate "reqlayout"
1507 (fun () -> wcmd "reqlayout %d %d %d"
1508 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
));
1511 let settrim trimmargins trimfuzz
=
1512 if nogeomcmds state
.geomcmds
1513 then state
.anchor <- getanchor
();
1514 conf
.trimmargins
<- trimmargins
;
1515 conf
.trimfuzz
<- trimfuzz
;
1516 let x0, y0, x1, y1 = trimfuzz
in
1517 invalidate "settrim"
1518 (fun () -> wcmd "settrim %d %d %d %d %d"
1519 (btod conf
.trimmargins
) x0 y0 x1 y1);
1524 let zoom = max
0.0001 zoom in
1525 if zoom <> conf
.zoom
1527 state
.prevzoom
<- (conf
.zoom, state
.x);
1529 reshape state
.winw state
.winh
;
1530 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
1534 let pivotzoom ?
(vw=min state
.w state
.winw
)
1535 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
1536 ?
(x=vw/2) ?
(y=vh
/2) zoom =
1537 let w = float state
.w /. zoom in
1538 let hw = w /. 2.0 in
1539 let ratio = float vh
/. float vw in
1540 let hh = hw *. ratio in
1541 let x0 = float x -. hw
1542 and y0 = float y -. hh in
1543 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
1547 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
1548 if nogeomcmds state
.geomcmds
1551 then pivotzoom ?
vw ?vh ?
x ?
y zoom
1555 let setcolumns mode columns coverA coverB
=
1556 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
1560 then impmsg "split mode doesn't work in bird's eye"
1562 conf
.columns
<- Csplit
(-columns
, E.a);
1570 conf
.columns
<- Csingle
E.a;
1575 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
1579 reshape state
.winw state
.winh
;
1582 let resetmstate () =
1583 state
.mstate
<- Mnone
;
1584 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
1587 let enterbirdseye () =
1588 let zoom = float conf
.thumbw
/. float state
.winw
in
1589 let birdseyepageno =
1590 let cy = state
.winh
/ 2 in
1594 let rec fold best
= function
1597 let d = cy - (l.pagedispy + l.pagevh/2)
1598 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
1599 if abs
d < abs dbest
1608 { conf
with zoom = conf
.zoom },
1609 state
.x, birdseyepageno, -1, getanchor
()
1613 conf
.presentation
<- false;
1614 conf
.interpagespace
<- 10;
1615 conf
.hlinks
<- false;
1616 conf
.fitmodel
<- FitPage
;
1619 match conf
.beyecolumns
with
1622 Cmulti
((c, 0, 0), E.a)
1623 | None
-> Csingle
E.a
1626 then state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1628 else state
.text <- E.s;
1629 reshape state
.winw state
.winh
;
1632 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1634 conf
.zoom <- c.zoom;
1635 conf
.presentation
<- c.presentation
;
1636 conf
.interpagespace
<- c.interpagespace
;
1637 conf
.hlinks
<- c.hlinks
;
1638 conf
.fitmodel
<- c.fitmodel
;
1639 conf
.beyecolumns
<- (
1640 match conf
.columns
with
1641 | Cmulti
((c, _, _), _) -> Some
c
1643 | Csplit
_ -> error
"leaving bird's eye split mode"
1646 match c.columns
with
1647 | Cmulti
(c, _) -> Cmulti
(c, E.a)
1648 | Csingle
_ -> Csingle
E.a
1649 | Csplit
(c, _) -> Csplit
(c, E.a)
1652 then state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1654 reshape state
.winw state
.winh
;
1655 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
1659 let togglebirdseye () =
1660 match state
.mode
with
1661 | Birdseye vals
-> leavebirdseye vals
true
1662 | View
-> enterbirdseye ()
1663 | Textentry
_ | LinkNav
_ -> ()
1666 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1667 let pageno = max
0 (pageno - incr
) in
1668 let rec loop = function
1669 | [] -> gotopage1 pageno 0
1670 | l :: _ when l.pageno = pageno ->
1671 if l.pagedispy >= 0 && l.pagey = 0
1672 then postRedisplay
"upbirdseye"
1673 else gotopage1 pageno 0
1674 | _ :: rest
-> loop rest
1678 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
1681 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1682 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
1683 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
1684 let rec loop = function
1686 let y, h = getpageyh
pageno in
1687 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
1688 gotoxy state
.x (clamp dy)
1689 | l :: _ when l.pageno = pageno ->
1690 if l.pagevh != l.pageh
1691 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
1692 else postRedisplay
"downbirdseye"
1693 | _ :: rest
-> loop rest
1699 let optentry mode
_ key =
1700 let btos b = if b then "on" else "off" in
1701 match [@warning
"-4"] key with
1705 let n, a, b = multicolumns_of_string
s in
1706 setcolumns mode
n a b;
1708 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
1710 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
1715 let zoom = float (int_of_string
s) /. 100.0 in
1718 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1720 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
1723 conf
.icase
<- not conf
.icase
;
1724 TEdone
("case insensitive search " ^
(btos conf
.icase
))
1727 conf
.verbose
<- not conf
.verbose
;
1728 TEdone
("verbose " ^
(btos conf
.verbose
))
1731 conf
.debug
<- not conf
.debug
;
1732 TEdone
("debug " ^
(btos conf
.debug
))
1735 conf
.underinfo
<- not conf
.underinfo
;
1736 TEdone
("underinfo " ^
btos conf
.underinfo
)
1739 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
1740 TEdone
("trim margins " ^
btos conf
.trimmargins
)
1743 conf
.invert
<- not conf
.invert
;
1744 TEdone
("invert colors " ^
btos conf
.invert
)
1748 cbput state
.hists
.sel
s;
1751 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
1752 textentry, ondone, true)
1756 then conf
.pax
<- Some
0.0
1757 else conf
.pax
<- None
;
1758 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
1761 state
.text <- Printf.sprintf
"bad option %d `%c'" (Char.code
c) c;
1764 | _ -> TEcont state
.text
1767 let adderrmsg src msg
=
1768 Buffer.add_string state
.errmsgs msg
;
1769 state
.newerrmsgs
<- true;
1773 let adderrfmt src fmt
= Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;;
1775 class outlinelistview ~zebra ~source
=
1776 let settext autonarrow
s =
1779 let ss = source#statestr
in
1780 state
.text <- if emptystr
ss
1782 else "{" ^
ss ^
"} [" ^
s ^
"]"
1783 else state
.text <- s
1789 ~source
:(source
:> lvsource
)
1791 ~modehash
:(findkeyhash conf
"outline")
1794 val m_autonarrow
= false
1796 method! key key mask
=
1798 if emptystr state
.text
1800 else fstate
.maxrows - 2
1802 let calcfirst first active
=
1805 let rows = active
- first
in
1806 if rows > maxrows then active
- maxrows else first
1810 let active = m_active
+ incr
in
1811 let active = bound
active 0 (source#getitemcount
- 1) in
1812 let first = calcfirst m_first
active in
1813 postRedisplay
"outline navigate";
1814 coe
{< m_active
= active; m_first
= first >}
1816 let navscroll first =
1818 let dist = m_active
- first in
1824 else first + maxrows
1827 postRedisplay
"outline navscroll";
1828 coe
{< m_first
= first; m_active
= active >}
1830 let ctrl = Wsi.withctrl mask
in
1832 match Wsi.kc2kt
key with
1833 | Ascii '
a'
when ctrl ->
1841 let pattern = source#renarrow
in
1842 if nonemptystr m_qsearch
1843 then (source#narrow m_qsearch
; m_qsearch
)
1847 settext (not m_autonarrow
) text;
1848 postRedisplay
"toggle auto narrowing";
1849 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
1851 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
1853 postRedisplay
"toggle auto narrowing";
1854 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
1856 | Ascii '
n'
when ctrl ->
1857 source#narrow m_qsearch
;
1859 then source#add_narrow_pattern m_qsearch
;
1860 postRedisplay
"outline ctrl-n";
1861 coe
{< m_first
= 0; m_active
= 0 >}
1863 | Ascii 'S'
when ctrl ->
1864 let active = source#calcactive
(getanchor
()) in
1865 let first = firstof m_first
active in
1866 postRedisplay
"outline ctrl-s";
1867 coe
{< m_first
= first; m_active
= active >}
1869 | Ascii 'u'
when ctrl ->
1870 postRedisplay
"outline ctrl-u";
1871 if m_autonarrow
&& nonemptystr m_qsearch
1873 ignore
(source#renarrow
);
1874 settext m_autonarrow
E.s;
1875 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1878 source#del_narrow_pattern
;
1879 let pattern = source#renarrow
in
1881 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
1883 settext m_autonarrow
text;
1884 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1887 | Ascii '
l'
when ctrl ->
1888 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
1889 postRedisplay
"outline ctrl-l";
1890 coe
{< m_first
= first >}
1892 | Ascii '
\t'
when m_autonarrow
->
1893 if nonemptystr m_qsearch
1895 postRedisplay
"outline list view tab";
1896 source#add_narrow_pattern m_qsearch
;
1898 coe
{< m_qsearch
= E.s >}
1902 | Escape
when m_autonarrow
->
1903 if nonemptystr m_qsearch
1904 then source#add_narrow_pattern m_qsearch
;
1907 | Enter
when m_autonarrow
->
1908 if nonemptystr m_qsearch
1909 then source#add_narrow_pattern m_qsearch
;
1912 | (Ascii
_ | Code
_) when m_autonarrow
->
1913 let pattern = m_qsearch ^ toutf8
key in
1914 postRedisplay
"outlinelistview autonarrow add";
1915 source#narrow
pattern;
1916 settext true pattern;
1917 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
1919 | Backspace
when m_autonarrow
->
1920 if emptystr m_qsearch
1923 let pattern = withoutlastutf8 m_qsearch
in
1924 postRedisplay
"outlinelistview autonarrow backspace";
1925 ignore
(source#renarrow
);
1926 source#narrow
pattern;
1927 settext true pattern;
1928 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
1930 | Up
when ctrl -> navscroll (max
0 (m_first
- 1))
1933 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
1935 | Up
-> navigate ~
-1
1936 | Down
-> navigate 1
1937 | Prior
-> navigate ~
-(fstate
.maxrows)
1938 | Next
-> navigate fstate
.maxrows
1944 postRedisplay
"outline ctrl right";
1945 {< m_pan
= m_pan
+ 1 >}
1947 else self#updownlevel
1
1955 postRedisplay
"outline ctrl left";
1956 {< m_pan
= m_pan
- 1 >}
1958 else self#updownlevel ~
-1
1963 postRedisplay
"outline home";
1964 coe
{< m_first
= 0; m_active
= 0 >}
1967 let active = source#getitemcount
- 1 in
1968 let first = max
0 (active - fstate
.maxrows) in
1969 postRedisplay
"outline end";
1970 coe
{< m_active
= active; m_first
= first >}
1972 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
1976 let genhistoutlines () =
1978 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
1979 compare c2
.lastvisit c1
.lastvisit
)
1980 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
1981 let path = if nonemptystr origin
then origin
else path in
1982 let base = mbtoutf8
@@ Filename.basename
path in
1983 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
1987 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
1988 Config.save
leavebirdseye;
1989 state
.anchor <- anchor;
1990 state
.bookmarks
<- bookmarks
;
1991 state
.origin
<- origin
;
1994 let x0, y0, x1, y1 = conf
.trimfuzz
in
1995 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
1996 reshape ~firsttime
:true state
.winw state
.winh
;
1997 opendoc path origin
;
2001 let setcheckers enabled
=
2002 match !checkerstexid with
2003 | None
-> if enabled
then checkerstexid := Some
(makecheckers
())
2007 GlTex.delete_texture id
;
2008 checkerstexid := None
;
2012 let describe_layout layout =
2016 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
2019 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
2020 else Printf.sprintf
"%d%s%d" (a.pageno+1)
2021 (if a.pageno+1 = b.pageno then ", " else Utf8syms.ellipsis
)
2024 let rec fold s la lb
= function
2025 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
2026 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
2027 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
2029 fold "Pages" l l rest
2032 let maxy = maxy () in
2035 else 100. *. (float state
.y /. float maxy)
2037 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
2040 let setpresentationmode v
=
2041 let n = page_of_y state
.y in
2042 state
.anchor <- (n, 0.0, 1.0);
2043 conf
.presentation
<- v
;
2044 if conf
.fitmodel
= FitPage
2045 then reqlayout conf
.angle conf
.fitmodel
;
2050 let btos b = if b then Utf8syms.radical
else E.s in
2051 let showextended = ref false in
2052 let showcolors = ref false in
2053 let leave mode
_ = state
.mode
<- mode
in
2056 val mutable m_l
= []
2057 val mutable m_a
= E.a
2058 val mutable m_prev_uioh
= nouioh
2059 val mutable m_prev_mode
= View
2061 inherit lvsourcebase
2063 method reset prev_mode prev_uioh
=
2064 m_a
<- Array.of_list
(List.rev m_l
);
2066 m_prev_mode
<- prev_mode
;
2067 m_prev_uioh
<- prev_uioh
;
2069 method int name get
set =
2075 try set (int_of_string
s)
2077 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2081 let te = name ^
": ", E.s, None
, intentry, ondone, true in
2082 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2086 method int_with_suffix name get
set =
2088 (name
, `intws get
, 1,
2092 try set (int_of_string_with_suffix
s)
2094 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2099 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
2101 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2105 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2107 (name
, `
bool (btos, get
), offset
, Action
(
2114 method color name get
set =
2116 (name
, `
color get
, 1,
2119 let invalid = (nan
, nan
, nan
) in
2122 try color_of_string
s
2124 state
.text <- Printf.sprintf
"bad color `%s': %s"
2131 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2132 state
.text <- color_to_string
(get
());
2133 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2137 method string name get
set =
2139 (name
, `
string get
, 1,
2142 let ondone s = set s in
2143 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2144 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2148 method colorspace name get
set =
2150 (name
, `
string get
, 1,
2155 inherit lvsourcebase
2158 m_active
<- CSTE.to_int conf
.colorspace
;
2161 method getitemcount
=
2162 Array.length
CSTE.names
2165 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2166 ignore
(uioh
, first, pan
);
2167 if not cancel
then set active;
2169 method hasaction
_ = true
2173 let modehash = findkeyhash conf
"info" in
2174 coe
(new listview ~zebra
:false ~helpmode
:false
2175 ~
source ~trusted
:true ~
modehash)
2178 method paxmark name get
set =
2180 (name
, `
string get
, 1,
2185 inherit lvsourcebase
2188 m_active
<- MTE.to_int conf
.paxmark
;
2191 method getitemcount
= Array.length
MTE.names
2192 method getitem
n = (MTE.names
.(n), 0)
2193 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2194 ignore
(uioh
, first, pan
);
2195 if not cancel
then set active;
2197 method hasaction
_ = true
2201 let modehash = findkeyhash conf
"info" in
2202 coe
(new listview ~zebra
:false ~helpmode
:false
2203 ~
source ~trusted
:true ~
modehash)
2206 method fitmodel name get
set =
2208 (name
, `
string get
, 1,
2213 inherit lvsourcebase
2216 m_active
<- FMTE.to_int conf
.fitmodel
;
2219 method getitemcount
= Array.length
FMTE.names
2220 method getitem
n = (FMTE.names
.(n), 0)
2221 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2222 ignore
(uioh
, first, pan
);
2223 if not cancel
then set active;
2225 method hasaction
_ = true
2229 let modehash = findkeyhash conf
"info" in
2230 coe
(new listview ~zebra
:false ~helpmode
:false
2231 ~
source ~trusted
:true ~
modehash)
2234 method caption
s offset
=
2235 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
2237 method caption2
s f offset
=
2238 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
2240 method getitemcount
= Array.length m_a
2243 let tostr = function
2244 | `
int f -> string_of_int
(f ())
2245 | `intws
f -> string_with_suffix_of_int
(f ())
2247 | `
color f -> color_to_string
(f ())
2248 | `
bool (btos, f) -> btos (f ())
2251 let name, t
, offset
, _ = m_a
.(n) in
2252 ((let s = tostr t
in
2254 then Printf.sprintf
"%s\t%s" name s
2258 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2263 match m_a
.(active) with
2264 | _, _, _, Action
f -> f uioh
2265 | _, _, _, Noaction
-> uioh
2276 method hasaction
n =
2278 | _, _, _, Action
_ -> true
2279 | _, _, _, Noaction
-> false
2281 initializer m_active
<- 1
2284 let rec fillsrc prevmode prevuioh
=
2285 let sep () = src#caption
E.s 0 in
2286 let colorp name get
set =
2288 (fun () -> color_to_string
(get
()))
2290 try set @@ color_of_string
v
2293 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2296 let rgba name get
set =
2298 (fun () -> get
() |> rgba_to_string
)
2300 try set @@ rgba_of_string
v
2303 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2306 let oldmode = state
.mode
in
2307 let birdseye = isbirdseye state
.mode
in
2309 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
2311 src#
bool "presentation mode"
2312 (fun () -> conf
.presentation
)
2313 (fun v -> setpresentationmode v);
2315 src#
bool "ignore case in searches"
2316 (fun () -> conf
.icase
)
2317 (fun v -> conf
.icase
<- v);
2320 (fun () -> conf
.preload)
2321 (fun v -> conf
.preload <- v);
2323 src#
bool "highlight links"
2324 (fun () -> conf
.hlinks
)
2325 (fun v -> conf
.hlinks
<- v);
2327 src#
bool "under info"
2328 (fun () -> conf
.underinfo
)
2329 (fun v -> conf
.underinfo
<- v);
2331 src#fitmodel
"fit model"
2332 (fun () -> FMTE.to_string conf
.fitmodel
)
2333 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
2335 src#
bool "trim margins"
2336 (fun () -> conf
.trimmargins
)
2337 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
2340 src#
int "inter-page space"
2341 (fun () -> conf
.interpagespace
)
2343 conf
.interpagespace
<- n;
2344 docolumns conf
.columns
;
2346 match state
.layout with
2348 | l :: _ -> l.pageno, l.pagey
2350 state
.maxy <- calcheight
();
2351 let y = getpagey
pageno in
2352 gotoxy state
.x (y + py)
2356 (fun () -> conf
.pagebias
)
2357 (fun v -> conf
.pagebias
<- v);
2359 src#
int "scroll step"
2360 (fun () -> conf
.scrollstep
)
2361 (fun n -> conf
.scrollstep
<- n);
2363 src#
int "horizontal scroll step"
2364 (fun () -> conf
.hscrollstep
)
2365 (fun v -> conf
.hscrollstep
<- v);
2367 src#
int "auto scroll step"
2369 match state
.autoscroll
with
2371 | _ -> conf
.autoscrollstep
)
2373 let n = boundastep state
.winh
n in
2374 if state
.autoscroll
<> None
2375 then state
.autoscroll
<- Some
n;
2376 conf
.autoscrollstep
<- n);
2379 (fun () -> truncate
(conf
.zoom *. 100.))
2380 (fun v -> pivotzoom ((float v) /. 100.));
2383 (fun () -> conf
.angle
)
2384 (fun v -> reqlayout v conf
.fitmodel
);
2386 src#
int "scroll bar width"
2387 (fun () -> conf
.scrollbw
)
2390 reshape state
.winw state
.winh
;
2393 src#
int "scroll handle height"
2394 (fun () -> conf
.scrollh
)
2395 (fun v -> conf
.scrollh
<- v;);
2397 src#
int "thumbnail width"
2398 (fun () -> conf
.thumbw
)
2400 conf
.thumbw
<- min
4096 v;
2403 leavebirdseye beye
false;
2410 let mode = state
.mode in
2411 src#
string "columns"
2413 match conf
.columns
with
2415 | Cmulti
(multi
, _) -> multicolumns_to_string multi
2416 | Csplit
(count
, _) -> "-" ^ string_of_int count
2419 let n, a, b = multicolumns_of_string
v in
2420 setcolumns mode n a b);
2423 src#caption
"Pixmap cache" 0;
2424 src#int_with_suffix
"size (advisory)"
2425 (fun () -> conf
.memlimit
)
2426 (fun v -> conf
.memlimit
<- v);
2430 Printf.sprintf
"%s bytes, %d tiles"
2431 (string_with_suffix_of_int state
.memused
)
2432 (Hashtbl.length state
.tilemap
)) 1;
2435 src#caption
"Layout" 0;
2436 src#caption2
"Dimension"
2437 (fun () -> Printf.sprintf
"%dx%d (virtual %dx%d)"
2438 state
.winw state
.winh
2442 then src#caption2
"Position" (fun () ->
2443 Printf.sprintf
"%dx%d" state
.x state
.y
2445 else src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
2448 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
2449 "Save these parameters as global defaults at exit"
2450 (fun () -> conf
.bedefault
)
2451 (fun v -> conf
.bedefault
<- v);
2454 let btos b = Utf8syms.(if b then lguillemet
else rguillemet
) in
2455 src#
bool ~offset
:0 ~
btos "Extended parameters"
2456 (fun () -> !showextended)
2457 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
2461 (fun () -> conf
.checkers
)
2462 (fun v -> conf
.checkers
<- v; setcheckers v);
2463 src#
bool "update cursor"
2464 (fun () -> conf
.updatecurs
)
2465 (fun v -> conf
.updatecurs
<- v);
2466 src#
bool "scroll-bar on the left"
2467 (fun () -> conf
.leftscroll
)
2468 (fun v -> conf
.leftscroll
<- v);
2470 (fun () -> conf
.verbose
)
2471 (fun v -> conf
.verbose
<- v);
2472 src#
bool "invert colors"
2473 (fun () -> conf
.invert
)
2474 (fun v -> conf
.invert
<- v);
2476 (fun () -> conf
.maxhfit
)
2477 (fun v -> conf
.maxhfit
<- v);
2479 (fun () -> conf
.pax
!= None
)
2482 then conf
.pax
<- Some
(now
())
2483 else conf
.pax
<- None
);
2484 src#
string "uri launcher"
2485 (fun () -> conf
.urilauncher
)
2486 (fun v -> conf
.urilauncher
<- v);
2487 src#
string "path launcher"
2488 (fun () -> conf
.pathlauncher
)
2489 (fun v -> conf
.pathlauncher
<- v);
2490 src#
string "tile size"
2491 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
2494 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
2495 conf
.tilew
<- max
64 w;
2496 conf
.tileh
<- max
64 h;
2499 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
2502 src#
int "texture count"
2503 (fun () -> conf
.texcount
)
2506 then conf
.texcount
<- v
2507 else impmsg "failed to set texture count please retry later"
2509 src#
int "slice height"
2510 (fun () -> conf
.sliceheight
)
2512 conf
.sliceheight
<- v;
2513 wcmd "sliceh %d" conf
.sliceheight
;
2515 src#
int "anti-aliasing level"
2516 (fun () -> conf
.aalevel
)
2518 conf
.aalevel
<- bound
v 0 8;
2519 state
.anchor <- getanchor
();
2520 opendoc state
.path state
.password;
2522 src#
string "page scroll scaling factor"
2523 (fun () -> string_of_float conf
.pgscale)
2525 try conf
.pgscale <- float_of_string
v
2528 Printf.sprintf
"bad page scroll scaling factor `%s': %s" v
2531 src#
int "ui font size"
2532 (fun () -> fstate
.fontsize
)
2533 (fun v -> setfontsize (bound
v 5 100));
2534 src#
int "hint font size"
2535 (fun () -> conf
.hfsize
)
2536 (fun v -> conf
.hfsize
<- bound
v 5 100);
2537 src#
string "trim fuzz"
2538 (fun () -> irect_to_string conf
.trimfuzz
)
2541 conf
.trimfuzz
<- irect_of_string
v;
2543 then settrim true conf
.trimfuzz
;
2545 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
2548 src#
string "selection command"
2549 (fun () -> conf
.selcmd
)
2550 (fun v -> conf
.selcmd
<- v);
2551 src#
string "synctex command"
2552 (fun () -> conf
.stcmd
)
2553 (fun v -> conf
.stcmd
<- v);
2554 src#
string "pax command"
2555 (fun () -> conf
.paxcmd
)
2556 (fun v -> conf
.paxcmd
<- v);
2557 src#
string "ask password command"
2558 (fun () -> conf
.passcmd)
2559 (fun v -> conf
.passcmd <- v);
2560 src#
string "save path command"
2561 (fun () -> conf
.savecmd
)
2562 (fun v -> conf
.savecmd
<- v);
2563 src#colorspace
"color space"
2564 (fun () -> CSTE.to_string conf
.colorspace
)
2566 conf
.colorspace
<- CSTE.of_int
v;
2570 src#paxmark
"pax mark method"
2571 (fun () -> MTE.to_string conf
.paxmark
)
2572 (fun v -> conf
.paxmark
<- MTE.of_int
v);
2576 (fun () -> conf
.usepbo
)
2577 (fun v -> conf
.usepbo
<- v);
2578 src#
bool "mouse wheel scrolls pages"
2579 (fun () -> conf
.wheelbypage
)
2580 (fun v -> conf
.wheelbypage
<- v);
2581 src#
bool "open remote links in a new instance"
2582 (fun () -> conf
.riani
)
2583 (fun v -> conf
.riani
<- v);
2584 src#
bool "edit annotations inline"
2585 (fun () -> conf
.annotinline
)
2586 (fun v -> conf
.annotinline
<- v);
2587 src#
bool "coarse positioning in presentation mode"
2588 (fun () -> conf
.coarseprespos
)
2589 (fun v -> conf
.coarseprespos
<- v);
2590 src#
bool "use document CSS"
2591 (fun () -> conf
.usedoccss
)
2593 conf
.usedoccss
<- v;
2594 state
.anchor <- getanchor
();
2595 opendoc state
.path state
.password;
2597 src#
bool ~
btos "colors"
2598 (fun () -> !showcolors)
2599 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
2602 colorp " background"
2603 (fun () -> conf
.bgcolor
)
2604 (fun v -> conf
.bgcolor
<- v);
2607 (fun () -> conf
.papercolor
)
2609 conf
.papercolor
<- v;
2610 setpapercolor conf
.papercolor
;
2614 (fun () -> conf
.sbarcolor
)
2615 (fun v -> conf
.sbarcolor
<- v);
2616 rgba " scrollbar handle"
2617 (fun () -> conf
.sbarhndlcolor
)
2618 (fun v -> conf
.sbarhndlcolor
<- v);
2619 rgba " texture color"
2620 (fun () -> conf
.texturecolor
)
2622 GlTex.env
(`
color v);
2623 conf
.texturecolor
<- v;
2629 src#caption
"Document" 0;
2630 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
2631 src#caption2
"Pages" (fun () -> string_of_int state
.pagecount
) 1;
2632 src#caption2
"Dimensions"
2633 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2634 if nonemptystr conf
.css
2635 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
2639 src#caption
"Trimmed margins" 0;
2640 src#caption2
"Dimensions"
2641 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2645 src#caption
"OpenGL" 0;
2646 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
2647 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
2650 src#caption
"Location" 0;
2651 if nonemptystr state
.origin
2652 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
2653 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
2655 src#reset prevmode prevuioh
;
2660 let prevmode = state
.mode
2661 and prevuioh
= state
.uioh in
2662 fillsrc prevmode prevuioh
;
2663 let source = (src :> lvsource
) in
2664 let modehash = findkeyhash conf
"info" in
2667 inherit listview ~zebra
:false ~helpmode
:false
2668 ~
source ~trusted
:true ~
modehash as super
2669 val mutable m_prevmemused
= 0
2670 method! infochanged
= function
2672 if m_prevmemused
!= state
.memused
2674 m_prevmemused
<- state
.memused
;
2675 postRedisplay
"memusedchanged";
2677 | Pdim
-> postRedisplay
"pdimchanged"
2678 | Docinfo
-> fillsrc prevmode prevuioh
2680 method! key key mask
=
2681 if not
(Wsi.withctrl mask
)
2683 match [@warning
"-4"] Wsi.kc2kt
key with
2684 | Keys.Left
-> coe
(self#updownlevel ~
-1)
2685 | Keys.Right
-> coe
(self#updownlevel
1)
2686 | _ -> super#
key key mask
2687 else super#
key key mask
2689 postRedisplay
"info";
2696 inherit lvsourcebase
2697 method getitemcount
= Array.length state
.help
2699 let s, l, _ = state
.help
.(n) in
2702 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2706 match state
.help
.(active) with
2707 | _, _, Action
f -> Some
(f uioh)
2708 | _, _, Noaction
-> Some
uioh
2717 method hasaction
n =
2718 match state
.help
.(n) with
2719 | _, _, Action
_ -> true
2720 | _, _, Noaction
-> false
2727 let modehash = findkeyhash conf
"help" in
2729 state
.uioh <- coe
(new listview
2730 ~zebra
:false ~helpmode
:true
2731 ~
source ~trusted
:true ~
modehash);
2732 postRedisplay
"help";
2738 inherit lvsourcebase
2739 val mutable m_items
= E.a
2741 method getitemcount
= 1 + Array.length m_items
2746 else m_items
.(n-1), 0
2748 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2753 then Buffer.clear state
.errmsgs
;
2760 method hasaction
n =
2764 state
.newerrmsgs
<- false;
2765 let l = Str.split
Utils.Re.crlf
(Buffer.contents state
.errmsgs
) in
2766 m_items
<- Array.of_list
l
2775 let source = (msgsource :> lvsource
) in
2776 let modehash = findkeyhash conf
"listview" in
2779 inherit listview ~zebra
:false ~helpmode
:false
2780 ~
source ~trusted
:false ~
modehash as super
2783 then msgsource#reset
;
2786 postRedisplay
"msgs";
2790 let editor = getenvdef
"EDITOR" E.s in
2794 let tmppath = Filename.temp_file
"llpp" "note" in
2797 let oc = open_out
tmppath in
2801 let execstr = editor ^
" " ^
tmppath in
2803 match spawn
execstr [] with
2805 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
2808 match Unix.waitpid
[] pid
with
2810 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
2814 | Unix.WEXITED
0 -> filecontents
tmppath
2816 impmsg "editor process(%s) exited abnormally: %d" execstr n;
2818 | Unix.WSIGNALED
n ->
2819 impmsg "editor process(%s) was killed by signal %d" execstr n;
2821 | Unix.WSTOPPED
n ->
2822 impmsg "editor(%s) process was stopped by signal %d" execstr n;
2825 match Unix.unlink
tmppath with
2827 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
2832 let enterannotmode opaque slinkindex
=
2835 inherit lvsourcebase
2836 val mutable m_text
= E.s
2837 val mutable m_items
= E.a
2839 method getitemcount
= Array.length m_items
2842 let label, _func
= m_items
.(n) in
2845 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2846 ignore
(uioh, first, pan
);
2849 let _label, func
= m_items
.(active) in
2854 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
2857 let rec split accu b i
=
2859 if p = String.length
s
2860 then (String.sub s b (p-b), fun () -> ()) :: accu
2862 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
2864 let ss = if i
= 0 then E.s else String.sub s b i
in
2865 split ((ss, fun () -> ())::accu) (p+1) 0
2866 else split accu b (i
+1)
2869 wcmd "freepage %s" (~
> opaque);
2871 Hashtbl.fold (fun key opaque'
accu ->
2872 if opaque'
= opaque'
2873 then key :: accu else accu) state
.pagemap
[]
2875 List.iter
(Hashtbl.remove state
.pagemap
) keys;
2877 gotoxy state
.x state
.y
2880 delannot
opaque slinkindex
;
2883 let edit inline
() =
2888 modannot
opaque slinkindex
s;
2894 let mode = state
.mode in
2897 ("annotation: ", m_text
, None
, textentry, update, true),
2898 fun _ -> state
.mode <- mode
2903 let s = getusertext m_text
in
2908 ( "[Copy]", fun () -> selstring conf
.selcmd m_text
)
2909 :: ("[Delete]", dele)
2910 :: ("[Edit]", edit conf
.annotinline
)
2911 :: (E.s, fun () -> ())
2912 :: split [] 0 0 |> List.rev
|> Array.of_list
2919 let s = getannotcontents
opaque slinkindex
in
2922 let source = (msgsource :> lvsource
) in
2923 let modehash = findkeyhash conf
"listview" in
2924 state
.uioh <- coe
(object
2925 inherit listview ~zebra
:false ~helpmode
:false
2926 ~
source ~trusted
:false ~
modehash
2928 postRedisplay
"enterannotmode";
2931 let gotoremote spec
=
2932 let filename, dest
= splitatchar spec '#'
in
2933 let getpath filename =
2935 if nonemptystr
filename
2937 if Filename.is_relative
filename
2939 let dir = Filename.dirname state
.path in
2941 if Filename.is_implicit
dir
2942 then Filename.concat
(Sys.getcwd
()) dir
2945 Filename.concat
dir filename
2949 if Sys.file_exists
path
2953 let path = getpath filename in
2957 let cmd = Lazy.force_val lcmd
in
2958 match spawn
cmd with
2960 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
2962 let anchor = getanchor
() in
2963 let ranchor = state
.path, state
.password, anchor, state
.origin
in
2964 state
.origin
<- E.s;
2965 state
.ranchors
<- ranchor :: state
.ranchors
;
2968 if substratis spec
0 "page="
2970 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
2972 state
.anchor <- (pageno, 0.0, 0.0);
2973 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
2975 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
2977 state
.nameddest
<- dest
;
2978 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
2982 let gotounder = function
2983 | Ulinkuri
s when isexternallink
s ->
2984 if substratis
s 0 "file://"
2985 then gotoremote @@ String.sub s 7 (String.length
s - 7)
2986 else Help.gotouri conf
.urilauncher
s
2988 let pageno, x, y = uritolocation
s in
2990 gotopagexy pageno x y
2991 | Utext
_ | Unone
-> ()
2992 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
2995 let gotooutline (_, _, kind
) =
2998 | Oanchor
((pageno, y, _) as anchor) ->
3001 getanchory (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3002 | Ouri
uri -> gotounder (Ulinkuri
uri)
3003 | Olaunch
cmd -> error
"gotounder (Ulaunch %S)" cmd
3004 | Oremote
(remote
, pageno) ->
3005 error
"gotounder (Uremote (%S,%d) )" remote
pageno
3006 | Ohistory hist
-> gotohist hist
3007 | Oremotedest
(path, dest
) ->
3008 error
"gotounder (Uremotedest (%S, %S))" path dest
3011 class outlinesoucebase fetchoutlines
= object (self
)
3012 inherit lvsourcebase
3013 val mutable m_items
= E.a
3014 val mutable m_minfo
= E.a
3015 val mutable m_orig_items
= E.a
3016 val mutable m_orig_minfo
= E.a
3017 val mutable m_narrow_patterns
= []
3018 val mutable m_gen
= -1
3020 method getitemcount
= Array.length m_items
3023 let s, n, _ = m_items
.(n) in
3026 method exit ~
(uioh:uioh) ~cancel ~
active ~
(first:int) ~pan
: uioh option =
3027 ignore
(uioh, first);
3029 if m_narrow_patterns
= []
3030 then m_orig_items
, m_orig_minfo
3031 else m_items
, m_minfo
3038 gotooutline m_items
.(active);
3046 method hasaction
(_:int) = true
3049 if Array.length m_items
!= Array.length m_orig_items
3052 match m_narrow_patterns
with
3054 | many
-> String.concat
Utf8syms.ellipsis
(List.rev many
)
3056 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3060 match m_narrow_patterns
with
3063 | head
:: _ -> Utf8syms.ellipsis ^ head
3065 method narrow
pattern =
3066 match Str.regexp_case_fold
pattern with
3069 let rec loop accu minfo
n =
3072 m_items
<- Array.of_list
accu;
3073 m_minfo
<- Array.of_list minfo
;
3076 let (s, _, _) as o = m_items
.(n) in
3078 match Str.search_forward re
s 0 with
3079 | exception Not_found
-> accu, minfo
3080 | first -> o :: accu, (first, Str.match_end
()) :: minfo
3082 loop accu minfo
(n-1)
3084 loop [] [] (Array.length m_items
- 1)
3086 method! getminfo
= m_minfo
3089 m_orig_items
<- fetchoutlines
();
3090 m_minfo
<- m_orig_minfo
;
3091 m_items
<- m_orig_items
3093 method add_narrow_pattern
pattern =
3094 m_narrow_patterns
<- pattern :: m_narrow_patterns
3096 method del_narrow_pattern
=
3097 match m_narrow_patterns
with
3098 | _ :: rest
-> m_narrow_patterns
<- rest
3103 match m_narrow_patterns
with
3104 | pattern :: [] -> self#narrow
pattern; pattern
3106 List.fold_left
(fun accu pattern ->
3107 self#narrow
pattern;
3108 pattern ^
Utf8syms.ellipsis ^
accu) E.s list
3110 method calcactive
(_:anchor) = 0
3112 method reset
anchor items =
3113 if state
.gen
!= m_gen
3115 m_orig_items
<- items;
3117 m_narrow_patterns
<- [];
3119 m_orig_minfo
<- E.a;
3123 if items != m_orig_items
3125 m_orig_items
<- items;
3126 if m_narrow_patterns
== []
3127 then m_items
<- items;
3130 let active = self#calcactive
anchor in
3132 m_first
<- firstof m_first
active
3136 let outlinesource fetchoutlines
=
3138 inherit outlinesoucebase fetchoutlines
3139 method! calcactive
anchor =
3140 let rely = getanchory anchor in
3141 let rec loop n best bestd
=
3142 if n = Array.length m_items
3145 let _, _, kind
= m_items
.(n) in
3148 let orely = getanchory anchor in
3149 let d = abs
(orely - rely) in
3152 else loop (n+1) best bestd
3153 | Onone
| Oremote
_ | Olaunch
_
3154 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
3155 loop (n+1) best bestd
3161 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
3162 let fetchoutlines sourcetype
() =
3163 match sourcetype
with
3164 | `bookmarks
-> Array.of_list state
.bookmarks
3165 | `outlines
-> state
.outlines
3166 | `history
-> genhistoutlines () |> Array.of_list
3168 let so = outlinesource (fetchoutlines `outlines
) in
3169 let sb = outlinesource (fetchoutlines `bookmarks
) in
3170 let sh = outlinesource (fetchoutlines `history
) in
3171 let mkselector sourcetype
source =
3173 let outlines = fetchoutlines sourcetype
() in
3174 if Array.length
outlines = 0
3175 then showtext ' ' errmsg
3178 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3179 let anchor = getanchor
() in
3180 source#reset
anchor outlines;
3181 state
.text <- source#greetmsg
;
3183 coe
(new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
3184 postRedisplay
"enter selector";
3188 let mkenter sourcetype errmsg
s = fun () -> mkselector sourcetype
s errmsg
in
3189 ( mkenter `
outlines "document has no outline" so
3190 , mkenter `bookmarks
"document has no bookmarks (yet)" sb
3191 , mkenter `history
"history is empty" sh )
3194 let quickbookmark ?title
() =
3195 match state
.layout with
3202 let tm = localtime
(now
()) in
3204 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
3206 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
3208 | Some
title -> title
3210 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3213 let setautoscrollspeed step goingdown
=
3214 let incr = max
1 ((abs step
) / 2) in
3215 let incr = if goingdown
then incr else -incr in
3216 let astep = boundastep state
.winh
(step
+ incr) in
3217 state
.autoscroll
<- Some
astep;
3221 match conf
.columns
with
3223 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
3226 let panbound x = bound
x (-state
.w) state
.winw
;;
3228 let existsinrow pageno (columns
, coverA
, coverB
) p =
3229 let last = ((pageno - coverA
) mod columns
) + columns
in
3230 let rec any = function
3233 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
3237 then (if l.pageno = last then false else any rest
)
3245 match state
.layout with
3247 let pageno = page_of_y state
.y in
3248 gotoxy state
.x (getpagey
(pageno+1))
3250 match conf
.columns
with
3252 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
3254 let y = clamp (pgscale state
.winh
) in
3257 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
3258 gotoxy state
.x (getpagey
pageno)
3259 | Cmulti
((c, _, _) as cl
, _) ->
3260 if conf
.presentation
3261 && (existsinrow l.pageno cl
3262 (fun l -> l.pageh
> l.pagey + l.pagevh))
3264 let y = clamp (pgscale state
.winh
) in
3267 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
3268 gotoxy state
.x (getpagey
pageno)
3270 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
3272 let pagey, pageh
= getpageyh
l.pageno in
3273 let pagey = pagey + pageh
* l.pagecol
in
3274 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
3275 gotoxy state
.x (pagey + pageh
+ ips)
3279 match state
.layout with
3281 let pageno = page_of_y state
.y in
3282 gotoxy state
.x (getpagey
(pageno-1))
3284 match conf
.columns
with
3286 if conf
.presentation
&& l.pagey != 0
3287 then gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3289 let pageno = max
0 (l.pageno-1) in
3290 gotoxy state
.x (getpagey
pageno)
3291 | Cmulti
((c, _, coverB
) as cl
, _) ->
3292 if conf
.presentation
&&
3293 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
3294 then gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3297 if l.pageno = state
.pagecount
- coverB
3301 let pageno = max
0 (l.pageno-decr) in
3302 gotoxy state
.x (getpagey
pageno)
3310 let pageno = max
0 (l.pageno-1) in
3311 let pagey, pageh
= getpageyh
pageno in
3314 let pagey, pageh
= getpageyh
l.pageno in
3315 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
3321 if emptystr conf
.savecmd
3322 then adderrmsg "savepath-command is empty"
3323 "don't know where to save modified document"
3325 let savecmd = Str.global_replace
Utils.Re.percent state
.path conf
.savecmd in
3329 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
3334 let tmp = path ^
".tmp" in
3336 Unix.rename
tmp path;
3339 let viewkeyboard key mask
=
3341 let mode = state
.mode in
3342 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
3345 postRedisplay
"view:enttext"
3347 let ctrl = Wsi.withctrl mask
in
3349 match Wsi.kc2kt
key with
3350 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
3352 | Ascii 'Q'
-> exit
0
3356 match List.rev state
.rects
with
3358 | (pageno, _, (_, y0, _, y1, _, y2
, _, y3
)) :: _ ->
3359 f pageno (y0, y1, y2
, y3
)
3360 and yminmax
(y0, y1, y2
, y3
) =
3361 let ym = min
y0 y1 |> min y2
|> min y3
|> truncate
in
3362 let yM = max
y0 y1 |> max y2
|> max y3
|> truncate
in
3365 let ondone msg
= state
.text <- msg
3367 match [@warning
"-4"] k
with
3370 let ym, yM = yminmax ys
in
3371 let hh = (yM - ym)/2 in
3372 gotopage1 pageno (ym + hh - state
.winh
/2)
3378 let ym, _ = yminmax ys
in
3385 let _, yM = yminmax ys
in
3386 gotopage1 pageno (yM - state
.winh
)
3392 enttext (": ", E.s, None
, zmod state
.mode, ondone, true)
3395 if hasunsavedchanges
()
3399 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
3402 match state
.lnava
with
3403 | None
-> LinkNav
(Ltgendir
0)
3404 | Some
pn -> LinkNav
(Ltexact
pn)
3406 gotoxy state
.x state
.y;
3408 else impmsg "keyboard link navigation does not work under rotation"
3410 | Escape
| Ascii 'q'
->
3411 begin match state
.mstate
with
3414 postRedisplay
"kill rect";
3417 | Mscrolly
| Mscrollx
3420 begin match state
.mode with
3423 | Ltexact pl
-> state
.lnava
<- Some pl
3424 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
3427 postRedisplay
"esc leave linknav"
3428 | Birdseye
_ | Textentry
_ | View
->
3429 match state
.ranchors
with
3431 | (path, password, anchor, origin
) :: rest
->
3432 state
.ranchors
<- rest
;
3433 state
.anchor <- anchor;
3434 state
.origin
<- origin
;
3435 state
.nameddest
<- E.s;
3436 opendoc path password
3442 gotoxy state
.x (getnav ~
-1)
3444 | Ascii '
o'
-> enteroutlinemode ()
3445 | Ascii 'H'
-> enterhistmode
()
3450 Hashtbl.iter
(fun _ opaque ->
3452 Hashtbl.clear state
.prects
) state
.pagemap
;
3453 postRedisplay
"dehighlight";
3455 | Ascii
(('
/'
| '?'
) as c) ->
3456 let ondone isforw
s =
3457 cbput state
.hists
.pat
s;
3458 state
.searchpattern
<- s;
3461 let s = String.make
1 c in
3462 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
3463 textentry, ondone (c = '
/'
), true)
3465 | Ascii '
+'
| Ascii '
='
when ctrl ->
3466 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3467 pivotzoom (conf
.zoom +. incr)
3472 try int_of_string
s with exn
->
3474 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3480 state
.text <- "page bias is now " ^ string_of_int
n;
3483 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
3485 | Ascii '
-'
when ctrl ->
3486 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3487 pivotzoom (max
0.01 (conf
.zoom -. decr))
3490 let ondone msg
= state
.text <- msg
in
3491 enttext ("option: ", E.s, None
,
3492 optentry state
.mode, ondone, true)
3494 | Ascii '
0'
when ctrl ->
3496 then gotoxy 0 state
.y
3499 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
3501 match conf
.columns
with
3502 | Csingle
_ | Cmulti
_ -> 1
3503 | Csplit
(n, _) -> n
3505 let h = state
.winh
-
3506 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
3508 let zoom = zoomforh state
.winw
h 0 cols in
3509 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
3512 | Ascii '
3'
when ctrl ->
3514 match conf
.fitmodel
with
3515 | FitWidth
-> FitProportional
3516 | FitProportional
-> FitPage
3517 | FitPage
-> FitWidth
3519 state
.text <- "fit model: " ^
FMTE.to_string
fm;
3520 reqlayout conf
.angle
fm
3522 | Ascii '
4'
when ctrl ->
3523 let zoom = getmaxw
() /. float state
.winw
in
3524 if zoom > 0.0 then setzoom zoom
3526 | Fn
9 | Ascii '
9'
when ctrl -> togglebirdseye ()
3528 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
3531 try int_of_string
s with exn
->
3532 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3538 cbput state
.hists
.pag
(string_of_int
n);
3539 gotopage1 (n + conf
.pagebias
- 1) 0;
3542 let pageentry text = function [@warning
"-4"]
3543 | Keys.Ascii '
g'
-> TEdone
text
3544 | key -> intentry text key
3546 let text = String.make
1 c in
3547 enttext (":", text, Some
(onhist state
.hists
.pag
),
3548 pageentry, ondone, true)
3551 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
3552 postRedisplay
"toggle scrollbar";
3555 state
.bzoom
<- not state
.bzoom
;
3557 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
3560 conf
.hlinks
<- not conf
.hlinks
;
3561 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
3562 postRedisplay
"toggle highlightlinks";
3565 if conf
.angle
mod 360 = 0
3567 state
.glinks
<- true;
3568 let mode = state
.mode in
3571 ("goto: ", E.s, None
, linknentry, linknact gotounder, false),
3573 state
.glinks
<- false;
3577 postRedisplay
"view:linkent(F)"
3579 else impmsg "hint mode does not work under rotation"
3582 state
.glinks
<- true;
3583 let mode = state
.mode in
3586 ("copy: ", E.s, None
, linknentry,
3587 linknact (fun under ->
3588 selstring conf
.selcmd
(undertext under)), false),
3590 state
.glinks
<- false;
3594 postRedisplay
"view:linkent"
3597 begin match state
.autoscroll
with
3599 conf
.autoscrollstep
<- step
;
3600 state
.autoscroll
<- None
3602 state
.autoscroll
<- Some conf
.autoscrollstep
;
3603 state
.slideshow
<- state
.slideshow
land lnot
2
3606 | Ascii '
p'
when ctrl ->
3607 launchpath () (* XXX where do error messages go? *)
3610 setpresentationmode (not conf
.presentation
);
3611 showtext ' '
("presentation mode " ^
3612 if conf
.presentation
then "on" else "off");
3615 if List.mem
Wsi.Fullscreen state
.winstate
3616 then Wsi.reshape conf
.cwinw conf
.cwinh
3617 else Wsi.fullscreen
()
3619 | Ascii
('
p'
|'N'
) -> search state
.searchpattern
false
3620 | Ascii '
n'
| Fn
3 -> search state
.searchpattern
true
3623 begin match state
.layout with
3625 | l :: _ -> gotoxy state
.x (getpagey
l.pageno)
3628 | Ascii ' '
-> nextpage ()
3629 | Delete
-> prevpage ()
3630 | Ascii '
='
-> showtext ' '
(describe_layout state
.layout);
3633 begin match state
.layout with
3636 Wsi.reshape l.pagew
l.pageh
;
3640 | Ascii '
\''
-> enterbookmarkmode
()
3641 | Ascii '
h'
| Fn
1 -> enterhelpmode ()
3642 | Ascii 'i'
-> enterinfomode ()
3643 | Ascii 'e'
when Buffer.length state
.errmsgs
> 0 -> entermsgsmode ()
3647 match state
.layout with
3648 | l :: _ when nonemptystr
s ->
3649 state
.bookmarks
<- (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3652 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
3656 showtext ' '
"Quick bookmark added";
3658 | Ascii '
x'
-> state
.roam
()
3660 | Ascii
('
<'
|'
>'
as c) ->
3661 reqlayout (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
3663 | Ascii
('
['
|'
]'
as c) ->
3665 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
3666 postRedisplay
"brightness";
3668 | Ascii '
c'
when state
.mode = View
->
3673 let m = (state
.winw
- state
.w) / 2 in
3678 match state
.prevcolumns
with
3679 | None
-> (1, 0, 0), 1.0
3680 | Some
(columns
, z
) ->
3683 | Csplit
(c, _) -> -c, 0, 0
3684 | Cmulti
((c, a, b), _) -> c, a, b
3685 | Csingle
_ -> 1, 0, 0
3689 setcolumns View
c a b;
3692 | Down
| Up
when ctrl && Wsi.withshift mask
->
3693 let zoom, x = state
.prevzoom
in
3698 begin match state
.autoscroll
with
3700 begin match state
.mode with
3701 | Birdseye beye
-> upbirdseye 1 beye
3702 | Textentry
_ | View
| LinkNav
_ ->
3704 then gotoxy state
.x (clamp ~
-(state
.winh
/2))
3706 if not
(Wsi.withshift mask
) && conf
.presentation
3708 else gotoxy state
.x (clamp (-conf
.scrollstep
))
3711 | Some
n -> setautoscrollspeed n false
3715 begin match state
.autoscroll
with
3717 begin match state
.mode with
3718 | Birdseye beye
-> downbirdseye 1 beye
3719 | Textentry
_ | View
| LinkNav
_ ->
3721 then gotoxy state
.x (clamp (state
.winh
/2))
3723 if not
(Wsi.withshift mask
) && conf
.presentation
3725 else gotoxy state
.x (clamp (conf
.scrollstep
))
3728 | Some
n -> setautoscrollspeed n true
3731 | Left
| Right
when not
(Wsi.withalt mask
) ->
3737 else conf
.hscrollstep
3740 let pv = Wsi.kc2kt
key in
3741 if pv = Keys.Left
then dx else -dx
3743 gotoxy (panbound (state
.x + dx)) state
.y
3746 postRedisplay
"left/right"
3753 match state
.layout with
3755 | l :: _ -> state
.y - l.pagey
3756 else clamp (pgscale (-state
.winh
))
3764 match List.rev state
.layout with
3766 | l :: _ -> getpagey
l.pageno
3767 else clamp (pgscale state
.winh
)
3771 | Ascii '
g'
| Home
->
3774 | Ascii 'G'
| End
->
3776 gotoxy 0 (clamp state
.maxy)
3778 | Right
when Wsi.withalt mask
->
3780 gotoxy state
.x (getnav 1)
3781 | Left
when Wsi.withalt mask
->
3783 gotoxy state
.x (getnav ~
-1)
3788 | Ascii '
v'
when conf
.debug
->
3791 match getopaque l.pageno with
3794 let x0, y0, x1, y1 = pagebbox
opaque in
3795 let rect = (float x0, float y0,
3798 float x0, float y1) in
3800 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
3801 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
3806 let mode = state
.mode in
3807 let cmd = ref E.s in
3808 let onleave = function
3809 | Cancel
-> state
.mode <- mode
3812 match getopaque l.pageno with
3813 | Some
opaque -> pipesel opaque !cmd
3814 | None
-> ()) state
.layout;
3818 cbput state
.hists
.sel
s;
3822 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
3825 state
.mode <- Textentry
(te, onleave);
3827 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
3828 vlog
"huh? %s" (Wsi.keyname
key)
3831 let linknavkeyboard key mask
linknav =
3832 let pv = Wsi.kc2kt
key in
3833 let getpage pageno =
3834 let rec loop = function
3836 | l :: _ when l.pageno = pageno -> Some
l
3837 | _ :: rest
-> loop rest
3838 in loop state
.layout
3840 let doexact (pageno, n) =
3841 match getopaque pageno, getpage pageno with
3842 | Some
opaque, Some
l ->
3845 let under = getlink
opaque n in
3846 postRedisplay
"link gotounder";
3853 | Home
-> Some
(findlink
opaque LDfirst
), -1
3854 | End
-> Some
(findlink
opaque LDlast
), 1
3855 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
3856 | Right
-> Some
(findlink
opaque (LDright
n)), 1
3857 | Up
-> Some
(findlink
opaque (LDup
n)), -1
3858 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
3859 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
3860 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
3863 begin match findpwl
l.pageno dir with
3867 state
.mode <- LinkNav
(Ltgendir
dir);
3868 let y, h = getpageyh
pageno in
3871 then y + h - state
.winh
3876 begin match getopaque pageno, getpage pageno with
3877 | Some
opaque, Some
_ ->
3879 let ld = if dir > 0 then LDfirst
else LDlast
in
3882 begin match link with
3884 showlinktype (getlink
opaque m);
3885 state
.mode <- LinkNav
(Ltexact
(pageno, m));
3886 postRedisplay
"linknav jpage";
3887 | Lnotfound
-> notfound dir
3893 begin match opt with
3894 | Some Lnotfound
-> pwl l dir;
3895 | Some
(Lfound
m) ->
3899 let _, y0, _, y1 = getlinkrect
opaque m in
3901 then gotopage1 l.pageno y0
3903 let d = fstate
.fontsize
+ 1 in
3904 if y1 - l.pagey > l.pagevh - d
3905 then gotopage1 l.pageno (y1 - state
.winh
+ d)
3906 else postRedisplay
"linknav";
3908 showlinktype (getlink
opaque m);
3909 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
3912 | None
-> viewkeyboard key mask
3914 | _ -> viewkeyboard key mask
3918 begin match linknav with
3919 | Ltexact pa
-> state
.lnava
<- Some pa
3920 | Ltgendir
_ | Ltnotready
_ -> ()
3923 postRedisplay
"leave linknav"
3927 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
3928 | Ltexact exact
-> doexact exact
3931 let keyboard key mask
=
3932 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
3933 then wcmd "interrupt"
3934 else state
.uioh <- state
.uioh#
key key mask
3937 let birdseyekeyboard key mask
3938 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
3940 match conf
.columns
with
3942 | Cmulti
((c, _, _), _) -> c
3943 | Csplit
_ -> error
"bird's eye split mode"
3945 let pgh layout = List.fold_left
3946 (fun m l -> max
l.pageh
m) state
.winh
layout in
3948 match Wsi.kc2kt
key with
3949 | Ascii '
l'
when Wsi.withctrl mask
->
3950 let y, h = getpageyh
pageno in
3951 let top = (state
.winh
- h) / 2 in
3952 gotoxy state
.x (max
0 (y - top))
3953 | Enter
-> leavebirdseye beye
false
3954 | Escape
-> leavebirdseye beye
true
3955 | Up
-> upbirdseye incr beye
3956 | Down
-> downbirdseye incr beye
3957 | Left
-> upbirdseye 1 beye
3958 | Right
-> downbirdseye 1 beye
3961 begin match state
.layout with
3965 state
.mode <- Birdseye
(
3966 oconf
, leftx
, l.pageno, hooverpageno
, anchor
3968 gotopage1 l.pageno 0;
3971 let layout = layout state
.x (state
.y-state
.winh
)
3973 (pgh state
.layout) in
3975 | [] -> gotoxy state
.x (clamp (-state
.winh
))
3977 state
.mode <- Birdseye
(
3978 oconf
, leftx
, l.pageno, hooverpageno
, anchor
3980 gotopage1 l.pageno 0
3983 | [] -> gotoxy state
.x (clamp (-state
.winh
))
3987 begin match List.rev state
.layout with
3989 let layout = layout state
.x
3990 (state
.y + (pgh state
.layout))
3991 state
.winw state
.winh
in
3992 begin match layout with
3994 let incr = l.pageh
- l.pagevh in
3999 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
4001 postRedisplay
"birdseye pagedown";
4003 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
4007 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4008 gotopage1 l.pageno 0;
4011 | [] -> gotoxy state
.x (clamp state
.winh
)
4015 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4019 let pageno = state
.pagecount
- 1 in
4020 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4021 if not
(pagevisible state
.layout pageno)
4024 match List.rev state
.pdims
with
4026 | (_, _, h, _) :: _ -> h
4030 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
4031 else postRedisplay
"birdseye end";
4033 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
4038 match state
.mode with
4039 | Textentry
_ -> scalecolor 0.4
4040 | LinkNav
_ | View
-> scalecolor 1.0
4041 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4042 if l.pageno = hooverpageno
4045 if l.pageno = pageno
4047 let c = scalecolor 1.0 in
4049 GlDraw.line_width
3.0;
4050 let dispx = l.pagedispx in
4052 (float (dispx-1)) (float (l.pagedispy-1))
4053 (float (dispx+l.pagevw+1))
4054 (float (l.pagedispy+l.pagevh+1));
4055 GlDraw.line_width
1.0;
4064 let postdrawpage l linkindexbase
=
4065 match getopaque l.pageno with
4067 if tileready l l.pagex
l.pagey
4069 let x = l.pagedispx - l.pagex
4070 and y = l.pagedispy - l.pagey in
4072 match conf
.columns
with
4073 | Csingle
_ | Cmulti
_ ->
4074 (if conf
.hlinks
then 1 else 0)
4076 && not
(isbirdseye state
.mode) then 2 else 0)
4080 match state
.mode with
4081 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
4087 Hashtbl.find_all state
.prects
l.pageno |>
4088 List.iter
(fun vals
-> drawprect
opaque x y vals
);
4089 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
4091 then (Glutils.redisplay
:= true; 0)
4097 let scrollindicator () =
4098 let sbw, ph
, sh = state
.uioh#scrollph
in
4099 let sbh, pw, sw
= state
.uioh#scrollpw
in
4104 else ((state
.winw
- sbw), state
.winw
, 0)
4108 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4109 let (r
, g, b, alpha
) = conf
.sbarcolor
in
4110 GlDraw.color (r
, g, b) ~alpha
;
4111 filledrect
(float x0) 0. (float x1) (float state
.winh
);
4113 (float hx0
) (float (state
.winh
- sbh))
4114 (float (hx0
+ state
.winw
)) (float state
.winh
);
4115 let (r
, g, b, alpha
) = conf
.sbarhndlcolor
in
4116 GlDraw.color (r
, g, b) ~alpha
;
4118 filledrect
(float x0) ph
(float x1) (ph
+. sh);
4119 let pw = pw +. float hx0
in
4120 filledrect
pw (float (state
.winh
- sbh)) (pw +. sw
) (float state
.winh
);
4125 match state
.mstate
with
4126 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ -> ()
4127 | Msel
((x0, y0), (x1, y1)) ->
4128 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
4129 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
4130 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
4131 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
4134 let showrects = function
4138 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4139 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4141 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4143 if l.pageno = pageno
4145 let dx = float (l.pagedispx - l.pagex
) in
4146 let dy = float (l.pagedispy - l.pagey) in
4147 let r, g, b, alpha
= c in
4148 GlDraw.color (r, g, b) ~alpha
;
4160 GlDraw.color (scalecolor2 conf
.bgcolor
);
4161 GlClear.color (scalecolor2 conf
.bgcolor
);
4162 GlClear.clear
[`
color];
4163 List.iter
drawpage state
.layout;
4165 match state
.mode with
4166 | LinkNav
(Ltexact
(pageno, linkno
)) ->
4167 begin match getopaque pageno with
4169 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
4170 let color = (0.0, 0.0, 0.5, 0.5) in
4172 (float x0, float y0,
4177 | None
-> state
.rects
4179 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
4182 | View
-> state
.rects
4185 let rec postloop linkindexbase
= function
4187 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
4188 postloop linkindexbase rest
4192 postloop 0 state
.layout;
4194 begin match state
.mstate
with
4195 | Mzoomrect
((x0, y0), (x1, y1)) ->
4197 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4198 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4199 filledrect
(float x0) (float y0) (float x1) (float y1);
4203 | Mscrolly
| Mscrollx
4213 match state
.reload with
4215 if x != state
.x || y != state
.y || abs_float
@@ now
() -. t
> 0.5
4216 || (state
.layout != [] && layoutready state
.layout)
4218 state
.reload <- None
;
4221 | None
-> display ()
4224 let zoomrect x y x1 y1 =
4227 and y0 = min
y y1 in
4228 let zoom = (float state
.w) /. float (x1 - x0) in
4231 if state
.w < state
.winw
4232 then (state
.winw
- state
.w) / 2
4235 match conf
.fitmodel
with
4236 | FitWidth
| FitProportional
-> simple ()
4238 match conf
.columns
with
4240 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
4241 | Cmulti
_ | Csingle
_ -> simple ()
4243 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
4244 state
.anchor <- getanchor
();
4249 let annot inline
x y =
4250 match unproject x y with
4251 | Some
(opaque, n, ux
, uy
) ->
4253 addannot
opaque ux uy
text;
4254 wcmd "freepage %s" (~
> opaque);
4255 Hashtbl.remove state
.pagemap
(n, state
.gen
);
4257 gotoxy state
.x state
.y
4261 let ondone s = add s in
4262 let mode = state
.mode in
4263 state
.mode <- Textentry
(
4264 ("annotation: ", E.s, None
, textentry, ondone, true),
4265 fun _ -> state
.mode <- mode);
4268 postRedisplay
"annot"
4269 else add @@ getusertext E.s
4274 let g opaque l px py =
4275 match rectofblock
opaque px py with
4277 let x0 = a.(0) -. 20. in
4278 let x1 = a.(1) +. 20. in
4279 let y0 = a.(2) -. 20. in
4280 let zoom = (float state
.w) /. (x1 -. x0) in
4281 let pagey = getpagey
l.pageno in
4282 let margin = (state
.w - l.pagew
)/2 in
4283 let nx = -truncate
x0 - margin in
4284 gotoxy nx (pagey + truncate
y0);
4285 state
.anchor <- getanchor
();
4290 match conf
.columns
with
4292 impmsg "block zooming does not work properly in split columns mode"
4293 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
4297 let winw = state
.winw - 1 in
4298 let s = float x /. float winw in
4299 let destx = truncate
(float (state
.w + winw) *. s) in
4300 gotoxy (winw - destx) state
.y;
4301 state
.mstate
<- Mscrollx
;
4305 let s = float y /. float state
.winh
in
4306 let desty = truncate
(s *. float (maxy ())) in
4307 gotoxy state
.x desty;
4308 state
.mstate
<- Mscrolly
;
4311 let viewmulticlick clicks
x y mask
=
4312 let g opaque l px py =
4320 if markunder
opaque px py mark
4324 match getopaque l.pageno with
4326 | Some
opaque -> pipesel opaque cmd
4328 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
4329 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
4334 postRedisplay
"viewmulticlick";
4335 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
4339 match conf
.columns
with
4341 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
4344 let viewmouse button down
x y mask
=
4346 | n when (n == 4 || n == 5) && not down
->
4347 if Wsi.withctrl mask
4351 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4352 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4355 match state
.mstate
with
4356 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
4357 | Mzoomrect
_ | Mnone
| Mpan
_
4358 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
4360 let zoom = conf
.zoom -. incr in
4361 state
.mstate
<- Mzoom
(n, 0, (x, y));
4362 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
4363 then pivotzoom ~
x ~
y zoom
4367 match state
.autoscroll
with
4368 | Some step
-> setautoscrollspeed step
(n=4)
4370 if conf
.wheelbypage
|| conf
.presentation
4377 let incr = if n = 4 then -conf
.scrollstep
else conf
.scrollstep
in
4378 let incr = incr * 2 in
4379 let y = clamp incr in
4383 | n when (n = 6 || n = 7) && not down
&& canpan () ->
4385 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
4388 | 1 when Wsi.withshift mask
->
4389 state
.mstate
<- Mnone
;
4392 match unproject x y with
4394 | Some
(_, pageno, ux
, uy
) ->
4395 let cmd = Printf.sprintf
4397 conf
.stcmd state
.path pageno ux uy
4399 match spawn
cmd [] with
4401 impmsg "execution of synctex command(%S) failed: %S"
4402 conf
.stcmd
@@ exntos exn
4406 | 1 when Wsi.withctrl mask
->
4409 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4410 state
.mstate
<- Mpan
(x, y)
4412 else state
.mstate
<- Mnone
4417 if Wsi.withshift mask
4419 annot conf
.annotinline
x y;
4420 postRedisplay
"addannot"
4424 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4425 state
.mstate
<- Mzoomrect
(p, p)
4428 match state
.mstate
with
4429 | Mzoomrect
((x0, y0), _) ->
4430 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4431 then zoomrect x0 y0 x y
4434 postRedisplay
"kill accidental zoom rect";
4438 | Mscrolly
| Mscrollx
4440 | Mnone
-> resetmstate ()
4443 | 1 when vscrollhit
x ->
4446 let _, position
, sh = state
.uioh#scrollph
in
4447 if y > truncate position
&& y < truncate
(position
+. sh)
4448 then state
.mstate
<- Mscrolly
4450 else state
.mstate
<- Mnone
4452 | 1 when y > state
.winh
- hscrollh () ->
4455 let _, position
, sw
= state
.uioh#scrollpw
in
4456 if x > truncate position
&& x < truncate
(position
+. sw
)
4457 then state
.mstate
<- Mscrollx
4459 else state
.mstate
<- Mnone
4461 | 1 when state
.bzoom
-> if not down
then zoomblock x y
4464 let dest = if down
then getunder x y else Unone
in
4465 begin match dest with
4466 | Ulinkuri
_ -> gotounder dest
4467 | Unone
when down
->
4468 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4469 state
.mstate
<- Mpan
(x, y);
4470 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4471 | Unone
| Utext
_ ->
4476 state
.mstate
<- Msel
((x, y), (x, y));
4477 postRedisplay
"mouse select";
4481 match state
.mstate
with
4483 | Mzoom
_ | Mscrollx
| Mscrolly
-> state
.mstate
<- Mnone
4484 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4486 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4487 state
.mstate
<- Mnone
4488 | Msel
((x0, y0), (x1, y1)) ->
4489 let rec loop = function
4493 let a0 = l.pagedispy in
4494 let a1 = a0 + l.pagevh in
4495 let b0 = l.pagedispx in
4496 let b1 = b0 + l.pagevw in
4497 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
4498 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
4502 match getopaque l.pageno with
4505 pipef ~closew
:false "Msel"
4508 postRedisplay
"Msel") cmd
4510 dosel conf
.selcmd
();
4511 state
.roam
<- dosel conf
.paxcmd
;
4522 let birdseyemouse button down
x y mask
4523 (conf
, leftx
, _, hooverpageno
, anchor) =
4526 let rec loop = function
4529 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4530 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4532 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false
4537 | _ -> viewmouse button down
x y mask
4543 method key key mask
=
4544 begin match state
.mode with
4545 | Textentry
textentry -> textentrykeyboard
key mask
textentry
4546 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
4547 | View
-> viewkeyboard key mask
4548 | LinkNav
linknav -> linknavkeyboard key mask
linknav
4552 method button button bstate
x y mask
=
4553 begin match state
.mode with
4554 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
4555 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
4560 method multiclick clicks
x y mask
=
4561 begin match state
.mode with
4562 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
4563 | Birdseye
_ | Textentry
_ -> ()
4568 begin match state
.mode with
4570 | View
| Birdseye
_ | LinkNav
_ ->
4571 match state
.mstate
with
4572 | Mzoom
_ | Mnone
-> ()
4576 state
.mstate
<- Mpan
(x, y);
4577 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4582 state
.mstate
<- Msel
(a, (x, y));
4583 postRedisplay
"motion select";
4586 let y = min state
.winh
(max
0 y) in
4590 let x = min state
.winw (max
0 x) in
4593 | Mzoomrect
(p0
, _) ->
4594 state
.mstate
<- Mzoomrect
(p0
, (x, y));
4595 postRedisplay
"motion zoomrect";
4599 method pmotion
x y =
4600 begin match state
.mode with
4601 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
4602 let rec loop = function
4604 if hooverpageno
!= -1
4606 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
4607 postRedisplay
"pmotion birdseye no hoover";
4610 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4611 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4613 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
4614 postRedisplay
"pmotion birdseye hoover";
4622 | LinkNav
_ | View
->
4623 match state
.mstate
with
4624 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
4633 let delta = now -. past
in
4636 else conf
.pax
<- Some
now
4640 method infochanged
_ = ()
4643 let maxy = maxy () in
4646 then 0.0, float state
.winh
4647 else scrollph state
.y maxy
4652 let fwinw = float (state
.winw - vscrollw
()) in
4654 let sw = fwinw /. float state
.w in
4655 let sw = fwinw *. sw in
4656 max
sw (float conf
.scrollh
)
4659 let maxx = state
.w + state
.winw in
4660 let x = state
.winw - state
.x in
4661 let percent = float x /. float maxx in
4662 (fwinw -. sw) *. percent
4664 hscrollh (), position, sw
4668 match state
.mode with
4669 | LinkNav
_ -> "links"
4670 | Textentry
_ -> "textentry"
4671 | Birdseye
_ -> "birdseye"
4674 findkeyhash conf
modename
4676 method eformsgs
= true
4677 method alwaysscrolly
= false
4678 method scroll
dx dy =
4679 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4680 gotoxy x (clamp (2 * dy));
4683 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
4686 let addrect pageno r g b a x0 y0 x1 y1 =
4687 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
4691 let cl = splitatchar cmds ' '
in
4693 try Scanf.sscanf
s fmt
f
4694 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
4697 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
4698 vlog
"%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
4699 s pageno r g b a x0 y0 x1 y1;
4703 let _,w1
,h1
,_ = getpagedim
pageno in
4704 let sw = float w1
/. float w
4705 and sh = float h1
/. float h in
4709 and y1s
= y1 *. sh in
4710 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
4711 let color = (r, g, b, a) in
4712 if conf
.verbose
then debugrect rect;
4713 state
.rects <- (pageno, color, rect) :: state
.rects;
4718 | "reload", "" -> reload ()
4720 scan args
"%u %f %f"
4722 let cmd, _ = state
.geomcmds
in
4724 then gotopagexy pageno x y
4727 gotopagexy pageno x y;
4730 state
.reprf
<- f state
.reprf
4732 | "goto1", args
-> scan args
"%u %f" gotopage
4733 | "gotor", args
-> scan args
"%S" gotoremote
4735 scan args
"%u %u %f %f %f %f"
4736 (fun pageno c x0 y0 x1 y1 ->
4737 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
4738 rectx "rect" pageno color x0 y0 x1 y1;
4741 scan args
"%u %f %f %f %f %f %f %f %f"
4742 (fun pageno r g b alpha
x0 y0 x1 y1 ->
4743 addrect pageno r g b alpha
x0 y0 x1 y1;
4744 postRedisplay
"prect"
4747 scan args
"%u %f %f"
4750 match getopaque pageno with
4751 | Some
opaque -> opaque
4754 pgoto optopaque pageno x y;
4755 let rec fixx = function
4758 if l.pageno = pageno
4759 then gotoxy (state
.x - l.pagedispx) state
.y
4764 match conf
.columns
with
4765 | Csingle
_ | Csplit
_ -> 1
4766 | Cmulti
((n, _, _), _) -> n
4768 layout 0 state
.y (state
.winw * mult) state
.winh
4772 | "activatewin", "" -> Wsi.activatewin
()
4773 | "quit", "" -> raise Quit
4776 let l = Config.keys_of_string
keys in
4777 List.iter
(fun (k
, m) -> keyboard k
m) l
4778 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
4781 | "clearrects", "" ->
4782 Hashtbl.clear state
.prects
;
4783 postRedisplay
"clearrects"
4785 adderrfmt "remote command"
4786 "error processing remote command: %S\n" cmds
;
4790 let scratch = Bytes.create
80 in
4791 let buf = Buffer.create
80 in
4793 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
4794 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
4797 if Buffer.length
buf > 0
4799 let s = Buffer.contents
buf in
4807 match Bytes.index_from
scratch ppos '
\n'
with
4808 | pos
-> if pos
>= n then -1 else pos
4809 | exception Not_found
-> -1
4813 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
4814 let s = Buffer.contents
buf in
4820 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
4826 let remoteopen path =
4827 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
4829 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
4834 Utils.vlogf
:= (fun s -> if conf
.verbose
then prerr_endline
s else ignore
s);
4835 let gcconfig = ref false in
4836 let trimcachepath = ref E.s in
4837 let rcmdpath = ref E.s in
4838 let pageno = ref None
in
4839 let openlast = ref false in
4840 let doreap = ref false in
4841 let csspath = ref None
in
4842 selfexec := Sys.executable_name
;
4845 [("-p", Arg.String
(fun s -> state
.password <- s),
4846 "<password> Set password");
4850 Config.fontpath
:= s;
4851 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
4853 "<path> Set path to the user interface font");
4857 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
4858 Config.confpath
:= s),
4859 "<path> Set path to the configuration file");
4861 ("-last", Arg.Set
openlast, " Open last document");
4863 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
4864 "<page-number> Jump to page");
4866 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
4867 "<path> Set path to the trim cache file");
4869 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
4870 "<named-destination> Set named destination");
4872 ("-remote", Arg.String
(fun s -> rcmdpath := s),
4873 "<path> Set path to the source of remote commands");
4875 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
4877 ("-v", Arg.Unit
(fun () ->
4879 "%s\nconfiguration file: %s\n"
4882 exit
0), " Print version and exit");
4884 ("-css", Arg.String
(fun s -> csspath := Some
s),
4885 "<path> Set path to the style sheet to use with EPUB/HTML");
4887 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
4888 "<origin> <undocumented>");
4890 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title");
4891 ("-layout-height", Arg.Set_int
layouth,
4892 "<height> layout height html/epub/etc (-1, 0, N)");
4895 (fun s -> state
.path <- s)
4896 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
4898 let histmode = emptystr state
.path && not
!openlast in
4900 if not
(Config.load !openlast)
4901 then dolog
"failed to load configuration";
4903 begin match !pageno with
4904 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
4917 val mutable m_clicks
= 0
4918 val mutable m_click_x
= 0
4919 val mutable m_click_y
= 0
4920 val mutable m_lastclicktime
= infinity
4922 method private cleanup =
4923 state
.roam
<- noroam
;
4924 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
4925 method expose
= postRedisplay
"expose"
4929 | Wsi.Unobscured
-> "unobscured"
4930 | Wsi.PartiallyObscured
-> "partiallyobscured"
4931 | Wsi.FullyObscured
-> "fullyobscured"
4933 vlog
"visibility change %s" name
4934 method display = display ()
4935 method map mapped
= vlog
"mapped %b" mapped
4936 method reshape w h =
4939 method mouse
b d x y m =
4940 if d && canselect ()
4943 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
4950 if abs
x - m_click_x
> 10
4951 || abs
y - m_click_y
> 10
4952 || abs_float
(t -. m_lastclicktime
) > 0.3
4954 m_clicks
<- m_clicks
+ 1;
4955 m_lastclicktime
<- t;
4959 postRedisplay
"cleanup";
4960 state
.uioh <- state
.uioh#button
b d x y m;
4962 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
4967 m_lastclicktime
<- infinity
;
4968 state
.uioh <- state
.uioh#button
b d x y m
4971 else state
.uioh <- state
.uioh#button
b d x y m
4973 state
.mpos
<- (x, y);
4974 state
.uioh <- state
.uioh#motion
x y
4975 method pmotion
x y =
4976 state
.mpos
<- (x, y);
4977 state
.uioh <- state
.uioh#pmotion
x y
4979 vlog
"k=%#x m=%#x" k
m;
4980 let mascm = m land (
4981 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
4984 let x = state
.x and y = state
.y in
4986 if x != state
.x || y != state
.y then self#
cleanup
4988 match state
.keystate
with
4990 let km = k
, mascm in
4993 let modehash = state
.uioh#
modehash in
4994 try Hashtbl.find
modehash km
4996 try Hashtbl.find
(findkeyhash conf
"global") km
4997 with Not_found
-> KMinsrt
(k
, m)
4999 | KMinsrt
(k
, m) -> keyboard k
m
5000 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
5001 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
5003 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
5004 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
5005 state
.keystate
<- KSnone
5006 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
5007 state
.keystate
<- KSinto
(keys, insrt
)
5008 | KSinto
_ -> state
.keystate
<- KSnone
5011 state
.mpos
<- (x, y);
5012 state
.uioh <- state
.uioh#pmotion
x y
5013 method leave = state
.mpos
<- (-1, -1)
5014 method winstate wsl
= state
.winstate
<- wsl
5015 method quit
: '
a. '
a = raise Quit
5016 method scroll
dx dy = state
.uioh <- state
.uioh#scroll
dx dy
5017 method zoom z
x y = state
.uioh#
zoom z
x y
5018 method opendoc path =
5021 postRedisplay
"opendoc";
5022 opendoc path state
.password
5025 let wsfd, winw, winh
= Wsi.init
mu conf
.cwinw conf
.cwinh platform
in
5028 if not
@@ List.exists
GlMisc.check_extension
5029 [ "GL_ARB_texture_rectangle"
5030 ; "GL_EXT_texture_recangle"
5031 ; "GL_NV_texture_rectangle" ]
5032 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
5035 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
5037 dolog
"socketpair failed: %s" @@ exntos exn
;
5045 setcheckers conf
.checkers
;
5046 begin match !csspath with
5048 | Some
"" -> conf
.css
<- E.s
5050 let css = filecontents
path in
5051 let l = String.length
css in
5053 if substratis
css (l-2) "\r\n"
5054 then String.sub css 0 (l-2)
5055 else (if css.[l-1] = '
\n'
then String.sub css 0 (l-1) else css)
5058 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
5059 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
5060 !Config.fontpath
, !trimcachepath
5062 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
5063 GlTex.env
(`
color conf
.texturecolor
);
5065 reshape ~firsttime
:true winw winh
;
5069 Wsi.settitle
"llpp (history)";
5073 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
5074 opendoc state
.path state
.password;
5078 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5079 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
5082 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
5083 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
5084 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
5086 | _pid
, _status
-> reap ()
5088 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
5091 ref (if nonemptystr
!rcmdpath then remoteopen !rcmdpath else None
)
5094 let rec loop deadline
=
5100 let r = [state
.ss; state
.wsfd] in
5104 | Some fd
-> fd
:: r
5108 Glutils.redisplay
:= false;
5115 if deadline
= infinity
5117 else max
0.0 (deadline
-. now)
5122 try Unix.select
r [] [] timeout
5123 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5128 match state
.autoscroll
with
5129 | Some step
when step
!= 0 ->
5130 if state
.slideshow
land 1 = 1
5132 if state
.slideshow
land 2 = 0
5133 then state
.slideshow
<- state
.slideshow
lor 2
5134 else if step
< 0 then prevpage () else nextpage ();
5135 deadline
+. (float (abs step
))
5138 let y = state
.y + step
in
5139 let fy = if conf
.maxhfit
then state
.winh
else 0 in
5142 then state
.maxy - fy
5143 else if y >= state
.maxy - fy then 0 else y
5152 let rec checkfds = function
5154 | fd
:: rest
when fd
= state
.ss ->
5155 let cmd = rcmd state
.ss in
5159 | fd
:: rest
when fd
= state
.wsfd ->
5163 | fd
:: rest
when Some fd
= !optrfd ->
5164 begin match remote fd
with
5165 | None
-> optrfd := remoteopen !rcmdpath;
5166 | opt -> optrfd := opt
5171 dolog
"select returned unknown descriptor";
5177 if deadline
= infinity
5181 match state
.autoscroll
with
5182 | Some step
when step
!= 0 -> deadline1
5188 match loop infinity
with
5190 Config.save leavebirdseye;
5191 if hasunsavedchanges
()
5193 | _ -> error
"umpossible - infinity reached"