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 state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
25 && (state
.w
> state
.winw
))
32 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
33 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
39 else Printf.kprintf ignore fmt
43 if emptystr conf
.pathlauncher
44 then dolog
"%s" state
.path
47 Str.global_replace
Utils.Re.percent state
.path conf
.pathlauncher
in
48 match spawn
command [] with
50 | exception exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
54 let getopaque pageno
=
55 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
56 with Not_found
-> None
59 let pagetranslatepoint l x y
=
60 let dy = y
- l
.pagedispy
in
61 let y = dy + l
.pagey
in
62 let dx = x
- l
.pagedispx
in
63 let x = dx + l
.pagex
in
67 let onppundermouse g
x y d
=
70 begin match getopaque l
.pageno
with
72 let x0 = l
.pagedispx
in
73 let x1 = x0 + l
.pagevw
in
74 let y0 = l
.pagedispy
in
75 let y1 = y0 + l
.pagevh
in
76 if y >= y0 && y <= y1 && x >= x0 && x <= x1
78 let px, py
= pagetranslatepoint l
x y in
79 match g opaque l
px py
with
91 let g opaque l
px py
=
94 match rectofblock opaque
px py
with
95 | Some
[|x0;x1;y0;y1|] ->
96 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
97 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
98 state
.rects
<- [l
.pageno
, color, rect];
99 postRedisplay
"getunder";
102 let under = whatsunder opaque
px py
in
103 if under = Unone
then None
else Some
under
105 onppundermouse g x y Unone
110 match unproject opaque
x y with
111 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
114 onppundermouse g x y None
;
118 state
.text
<- Printf.sprintf
"%c%s" c s
;
119 postRedisplay
"showtext";
122 let impmsg fmt
= Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;;
124 let pipesel opaque cmd
=
126 then pipef ~closew
:false "pipesel"
129 postRedisplay
"pipesel"
134 let g opaque l
px py
=
135 if markunder opaque
px py conf
.paxmark
138 match getopaque l
.pageno
with
140 | Some opaque
-> pipesel opaque conf
.paxcmd
144 postRedisplay
"paxunder";
145 if conf
.paxmark
= Mark_page
148 match getopaque l
.pageno
with
150 | Some opaque
-> clearmark opaque
) state
.layout
;
151 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
154 let undertext = function
157 | Utext s
-> "font: " ^ s
158 | Uannotation
(opaque
, slinkindex
) ->
159 "annotation: " ^ getannotcontents opaque slinkindex
162 let updateunder x y =
163 match getunder x y with
164 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
166 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
167 Wsi.setcursor
Wsi.CURSOR_INFO
169 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
170 Wsi.setcursor
Wsi.CURSOR_TEXT
172 if conf
.underinfo
then showtext 'a'
"nnotation";
173 Wsi.setcursor
Wsi.CURSOR_INFO
176 let showlinktype under =
177 if conf
.underinfo
&& under != Unone
178 then showtext ' '
@@ undertext under
181 let intentry_with_suffix text key
=
183 match [@warning
"-4"] key
with
184 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
185 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
186 addchar
text @@ asciilower c
188 state
.text <- "invalid key";
195 let b = Buffer.create
16 in
198 let b = Buffer.to_bytes
b in
199 wcmd state
.ss
b @@ Bytes.length
b
203 let nogeomcmds = function
204 | s
, [] -> emptystr s
208 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
209 let rec fold accu n
=
210 if n
= Array.length
b
213 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n
) in
216 || n
= state
.pagecount
- coverB
217 || (n
- coverA
) mod columns
= columns
- 1)
223 let pagey = max
0 (y - vy
) in
224 let pagedispy = if pagey > 0 then 0 else vy
- y in
225 let pagedispx, pagex
=
227 if n
= coverA
- 1 || n
= state
.pagecount
- coverB
228 then x + (sw
- w
) / 2
236 let vw = sw
- pagedispx in
237 let pw = w
- pagex
in
240 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
241 if pagevw > 0 && pagevh > 0
252 ; pagedispx = pagedispx
253 ; pagedispy = pagedispy
263 if Array.length
b = 0
265 else List.rev
(fold [] (page_of_y
y))
268 let layoutS (columns
, b) x y sw sh
=
269 let rec fold accu n
=
270 if n
= Array.length
b
273 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n
) in
281 let pagey = max
0 (y - vy
) in
282 let pagedispy = if pagey > 0 then 0 else vy
- y in
283 let pagedispx, pagex
=
297 let pagecolw = pagew
/columns
in
300 then pagedispx + ((sw
- pagecolw) / 2)
304 let vw = sw
- pagedispx in
305 let pw = pagew
- pagex
in
308 let pagevw = min
pagevw pagecolw in
309 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
310 if pagevw > 0 && pagevh > 0
321 ; pagedispx = pagedispx
322 ; pagedispy = pagedispy
323 ; pagecol
= n
mod columns
335 let layout x y sw sh
=
336 if nogeomcmds state
.geomcmds
338 match conf
.columns
with
339 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
340 | Cmulti c
-> layoutN c
x y sw sh
341 | Csplit s
-> layoutS s
x y sw sh
345 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
346 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
349 let tilex = l
.pagex
mod conf
.tilew
in
350 let tiley = l
.pagey mod conf
.tileh
in
352 let col = l
.pagex
/ conf
.tilew
in
353 let row = l
.pagey / conf
.tileh
in
355 let rec rowloop row y0 dispy h
=
358 let dh = conf
.tileh
- y0 in
360 let rec colloop col x0 dispx w
=
363 let dw = conf
.tilew
- x0 in
365 f col row dispx dispy
x0 y0 dw dh;
366 colloop (col+1) 0 (dispx
+dw) (w
-dw)
368 colloop col tilex l
.pagedispx l
.pagevw;
369 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
371 if l
.pagevw > 0 && l
.pagevh > 0
372 then rowloop row tiley l
.pagedispy l
.pagevh;
375 let gettileopaque l
col row =
376 let key = l
.pageno
, state
.gen
, conf
.colorspace
,
377 conf
.angle
, l
.pagew
, l
.pageh
, col, row in
378 try Some
(Hashtbl.find state
.tilemap
key)
379 with Not_found
-> None
382 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
383 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
384 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
387 let drawtiles l
color =
390 let f col row x y tilex tiley w h
=
391 match gettileopaque l
col row with
392 | Some
(opaque
, _
, t
) ->
393 let params = x, y, w
, h
, tilex, tiley in
395 then GlTex.env
(`mode `blend
);
396 drawtile
params opaque
;
398 then GlTex.env
(`mode `modulate
);
402 let s = Printf.sprintf
"%d[%d,%d] %f sec" l
.pageno
col row t
in
403 let w = measurestr fstate
.fontsize
s in
404 GlDraw.color (0.0, 0.0, 0.0);
409 (float (y + fstate
.fontsize
+ 2));
411 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
417 let w = let lw = state
.winw
- x in min
lw w
418 and h
= let lh = state
.winh
- y in min
lh h
421 then GlTex.env
(`mode `blend
);
422 begin match !checkerstexid with
424 Gl.enable `texture_2d
;
425 GlTex.bind_texture ~target
:`texture_2d id
;
429 and y1 = float (y+h
) in
431 let tw = float w /. 16.0
432 and th
= float h
/. 16.0 in
433 let tx0 = float tilex /. 16.0
434 and ty0
= float tiley /. 16.0 in
436 and ty1
= ty0
+. th
in
437 Raw.sets_float
Glutils.vraw ~pos
:0
438 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
439 Raw.sets_float
Glutils.traw ~pos
:0
440 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
441 GlArray.vertex `two
Glutils.vraw
;
442 GlArray.tex_coord `two
Glutils.traw
;
443 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
444 Gl.disable `texture_2d
;
447 GlDraw.color (1.0, 1.0, 1.0);
448 filledrect
(float x) (float y) (float (x+w)) (float (y+h
));
451 then GlTex.env
(`mode `modulate
);
452 if w > 128 && h
> fstate
.fontsize
+ 10
454 let c = if conf
.invert
then 1.0 else 0.0 in
455 GlDraw.color (c, c, c);
458 then (col*conf
.tilew
, row*conf
.tileh
)
461 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
470 let pagevisible layout n
= List.exists
(fun l
-> l
.pageno
= n
) layout;;
472 let tilevisible1 l
x y =
474 and ax1
= l
.pagex
+ l
.pagevw
476 and ay1
= l
.pagey + l
.pagevh in
480 let bx1 = min
(bx0 + conf
.tilew
) l
.pagew
481 and by1
= min
(by0
+ conf
.tileh
) l
.pageh
in
483 let rx0 = max
ax0 bx0
484 and ry0
= max ay0 by0
485 and rx1
= min ax1
bx1
486 and ry1
= min ay1 by1
in
488 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
492 let tilevisible layout n
x y =
493 let rec findpageinlayout m
= function
494 | l
:: rest
when l
.pageno
= n
->
495 tilevisible1 l
x y || (
496 match conf
.columns
with
497 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
498 | Csplit _
| Csingle _
| Cmulti _
-> false
500 | _
:: rest
-> findpageinlayout 0 rest
503 findpageinlayout 0 layout;
506 let tileready l
x y =
507 tilevisible1 l
x y &&
508 gettileopaque l
(x/conf
.tilew
) (y/conf
.tileh
) != None
511 let tilepage n p
layout =
512 let rec loop = function
516 let f col row _ _ _ _ _ _
=
517 if state
.currently
= Idle
519 match gettileopaque l
col row with
522 let x = col*conf
.tilew
523 and y = row*conf
.tileh
in
525 let w = l
.pagew
- x in
529 let h = l
.pageh
- y in
534 then getpbo
w h conf
.colorspace
537 wcmd "tile %s %d %d %d %d %s" (~
> p
) x y w h (~
> pbo);
540 l
, p
, conf
.colorspace
, conf
.angle
,
541 state
.gen
, col, row, conf
.tilew
, conf
.tileh
550 if nogeomcmds state
.geomcmds
554 let preloadlayout x y sw sh
=
555 let y = if y < sh
then 0 else y - sh
in
556 let x = min
0 (x + sw
) in
564 if state
.currently
= Idle
568 begin match getopaque l
.pageno
with
570 wcmd "page %d %d" l
.pageno l
.pagedimno
;
571 state
.currently
<- Loading
(l
, state
.gen
);
573 tilepage l
.pageno opaque pages
;
578 if nogeomcmds state
.geomcmds
584 if conf
.preload && state
.currently
= Idle
585 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
588 let layoutready layout =
589 let rec fold all ls
=
592 let seen = ref false in
593 let allvisible = ref true in
594 let foo col row _ _ _ _ _ _
=
596 allvisible := !allvisible &&
597 begin match gettileopaque l
col row with
603 fold (!seen && !allvisible) rest
606 let alltilesvisible = fold true layout in
611 let y = bound
y 0 state
.maxy in
613 let layout = layout x y state
.winw state
.winh
in
614 postRedisplay
"gotoxy ready";
619 state
.layout <- layout;
620 begin match state
.mode
with
623 | Ltexact
(pageno
, linkno
) ->
624 let rec loop = function
626 state
.lnava
<- Some
(pageno
, linkno
);
627 state
.mode
<- LinkNav
(Ltgendir
0)
628 | l
:: _
when l
.pageno
= pageno
->
629 begin match getopaque pageno
with
630 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
632 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
633 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
634 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
635 then state
.mode
<- LinkNav
(Ltgendir
0)
637 | _
:: rest
-> loop rest
640 | Ltnotready _
| Ltgendir _
-> ()
642 | Birdseye _
| Textentry _
| View
-> ()
644 begin match state
.mode
with
645 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
646 if not
(pagevisible layout pageno
)
648 match state
.layout with
651 state
.mode
<- Birdseye
(conf
, leftx
, l
.pageno
, hooverpageno
, anchor
)
655 | Ltnotready
(_
, dir
)
658 let rec loop = function
661 match getopaque l
.pageno
with
662 | None
-> Ltnotready
(l
.pageno
, dir
)
667 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
669 if dir
> 0 then LDfirst
else LDlast
675 | Lnotfound
-> loop rest
677 showlinktype (getlink opaque n
);
678 Ltexact
(l
.pageno
, n
)
682 state
.mode
<- LinkNav
linknav
685 | Textentry _
| View
-> ()
690 let mx, my
= state
.mpos
in
695 let conttiling pageno opaque
=
696 tilepage pageno opaque
698 then preloadlayout state
.x state
.y state
.winw state
.winh
703 if not conf
.verbose
then state
.text <- E.s;
707 let getanchory (n
, top
, dtop
) =
708 let y, h = getpageyh n
in
711 let ips = calcips
h in
712 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
713 else y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
716 let gotoanchor anchor
= gotoxy state
.x (getanchory anchor
);;
717 let addnav () = getanchor
() |> cbput state
.hists
.nav
;;
718 let addnavnorc () = getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;;
721 let anchor = cbgetc state
.hists
.nav dir
in
726 let y, h = getpageyh n
in
727 let y = y + (truncate
(top
*. float h)) in
731 let gotopage1 n top
=
732 let y = getpagey n
in
738 Glutils.redisplay
:= false;
743 match state
.geomcmds
with
744 | ps
, [] when emptystr ps
->
746 state
.geomcmds
<- s, [];
747 | ps
, [] -> state
.geomcmds
<- ps
, [s, f];
748 | ps
, (s'
, _
) :: rest
when s'
= s -> state
.geomcmds
<- ps
, ((s, f) :: rest
);
749 | ps
, cmds
-> state
.geomcmds
<- ps
, ((s, f) :: cmds
);
753 Hashtbl.iter
(fun _ opaque
-> wcmd "freepage %s" (~
> opaque
)) state
.pagemap
;
754 Hashtbl.clear state
.pagemap
;
758 if not
(Queue.is_empty state
.tilelru
)
760 Queue.iter
(fun (k
, p
, s) ->
761 wcmd "freetile %s" (~
> p
);
762 state
.memused
<- state
.memused
- s;
763 Hashtbl.remove state
.tilemap k
;
765 state
.uioh#infochanged Memused
;
766 Queue.clear state
.tilelru
;
772 let h = truncate
(float h*.conf
.zoom
) in
773 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
779 let sl = keystostrlist conf
in
781 function | [] -> accu
782 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
783 in Help.makehelp conf
.urilauncher
784 @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
787 let opendoc path password
=
789 state
.password
<- password
;
790 state
.gen
<- state
.gen
+ 1;
792 state
.outlines
<- [||];
795 setaalevel conf
.aalevel
;
797 if emptystr state
.origin
801 Wsi.settitle
("llpp " ^ mbtoutf8
(Filename.basename
titlepath));
802 wcmd "open %d %d %s\000%s\000%s\000"
803 (btod conf
.usedoccss
) !layouth
804 path password conf
.css
;
805 invalidate "reqlayout"
807 wcmd "reqlayout %d %d %d %s\000"
808 conf
.angle
(FMTE.to_int conf
.fitmodel
)
809 (stateh state
.winh
) state
.nameddest
815 state
.anchor <- getanchor
();
816 opendoc state
.path state
.password
;
820 let c = c *. conf
.colorscale
in
824 let scalecolor2 (r
, g, b) =
825 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
828 let docolumns columns
=
831 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
832 let rec loop pageno
pdimno pdim
y ph pdims
=
833 if pageno
!= state
.pagecount
835 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
837 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
842 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
844 y + (if conf
.presentation
845 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
846 else (if pageno
= 0 then 0 else conf
.interpagespace
))
848 a.(pageno
) <- (pdimno, x, y, pdim
);
849 loop (pageno
+1) pdimno pdim
(y + h) h pdims
851 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
852 conf
.columns
<- Csingle
a;
854 | Cmulti
((columns
, coverA
, coverB
), _
) ->
855 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
856 let rec loop pageno
pdimno pdim
x y rowh pdims
=
858 if m
= pageno
then () else
859 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
862 let y = y + (rowh
- h) / 2 in
863 a.(m
) <- (pdimno, x, y, pdim
);
867 if pageno
= state
.pagecount
868 then fixrow (((pageno
- 1) / columns
) * columns
)
870 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
872 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
874 | _
-> pdimno, pdim
, pdims
877 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
879 let x = (state
.winw
- w) / 2 in
881 if conf
.presentation
then calcips
h else conf
.interpagespace
in
885 if (pageno
- coverA
) mod columns
= 0
887 let x = max
0 (state
.winw
- state
.w) / 2 in
891 let ips = calcips
h in
892 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
894 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
898 else x, y, max rowh
h
902 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
905 if pageno
= columns
&& conf
.presentation
907 let ips = calcips rowh
in
908 for i
= 0 to pred columns
910 let (pdimno, x, y, pdim
) = a.(i
) in
911 a.(i
) <- (pdimno, x, y+ips, pdim
)
917 fixrow (pageno
- columns
);
922 a.(pageno
) <- (pdimno, x, y, pdim
);
923 let x = x + w + xoff
*2 + conf
.interpagespace
in
924 loop (pageno
+1) pdimno pdim
x y rowh' pdims
926 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
927 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
930 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
931 let rec loop pageno
pdimno pdim
y pdims
=
932 if pageno
!= state
.pagecount
934 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
936 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
938 | _
-> pdimno, pdim
, pdims
941 let rec loop1 n
x y =
942 if n
= c then y else (
943 a.(pageno
*c + n
) <- (pdimno, x, y, pdim
);
944 loop1 (n
+1) (x+cw) (y + h + conf
.interpagespace
)
947 let y = loop1 0 0 y in
948 loop (pageno
+1) pdimno pdim
y pdims
950 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
951 conf
.columns
<- Csplit
(c, a);
955 docolumns conf
.columns
;
956 state
.maxy <- calcheight
();
957 if state
.reprf
== noreprf
959 match state
.mode
with
960 | Birdseye
(_
, _
, pageno
, _
, _
) ->
961 let y, h = getpageyh pageno
in
962 let top = (state
.winh
- h) / 2 in
963 gotoxy state
.x (max
0 (y - top))
964 | Textentry _
| View
| LinkNav _
->
965 let y = getanchory state
.anchor in
966 let y = min
y (state
.maxy - state
.winh
) in
971 state
.reprf
<- noreprf
;
975 let reshape ?
(firsttime
=false) w h =
976 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
977 if not firsttime
&& nogeomcmds state
.geomcmds
978 then state
.anchor <- getanchor
();
981 let w = truncate
(float w *. conf
.zoom
) in
984 setfontsize fstate
.fontsize
;
985 GlMat.mode `modelview
;
986 GlMat.load_identity
();
988 GlMat.mode `projection
;
989 GlMat.load_identity
();
990 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
991 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
992 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
997 else float state
.x /. float state
.w
999 invalidate "geometry"
1003 then state
.x <- truncate
(relx *. float w);
1005 match conf
.columns
with
1007 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1008 | Csplit
(c, _
) -> w * c
1010 wcmd "geometry %d %d %d" w (stateh h) (FMTE.to_int conf
.fitmodel
)
1015 let len = Queue.length state
.tilelru
in
1016 let layout = lazy (if conf
.preload
1017 then preloadlayout state
.x state
.y state
.winw state
.winh
1018 else state
.layout) in
1020 if state
.memused
> conf
.memlimit
1024 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1025 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1026 let (_
, pw, ph
, _
) = getpagedim
n in
1028 && colorspace
= conf
.colorspace
1029 && angle
= conf
.angle
1033 let x = col*conf
.tilew
and y = row*conf
.tileh
in
1034 tilevisible (Lazy.force_val
layout) n x y
1036 then Queue.push lruitem state
.tilelru
1039 wcmd "freetile %s" (~
> p
);
1040 state
.memused
<- state
.memused
- s;
1041 state
.uioh#infochanged Memused
;
1042 Hashtbl.remove state
.tilemap k
;
1050 let onpagerect pageno
f =
1052 match conf
.columns
with
1053 | Cmulti
(_
, b) -> b
1055 | Csplit
(_
, b) -> b
1057 if pageno
>= 0 && pageno
< Array.length
b
1059 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1063 let gotopagexy1 pageno
x y =
1064 let _,w1
,h1
,leftx
= getpagedim pageno
in
1065 let top = y /. (float h1
) in
1066 let left = x /. (float w1
) in
1067 let py, w, h = getpageywh pageno
in
1068 let wh = state
.winh
in
1069 let x = left *. (float w) in
1070 let x = leftx
+ state
.x + truncate
x in
1072 if x < 0 || x >= state
.winw
1076 let pdy = truncate
(top *. float h) in
1077 let y'
= py + pdy in
1078 let dy = y'
- state
.y in
1080 if x != state
.x || not
(dy > 0 && dy < wh)
1082 if conf
.presentation
1084 if abs
(py - y'
) > wh
1091 if state
.x != sx || state
.y != sy
1093 else gotoxy state
.x state
.y;
1096 let gotopagexy pageno
x y =
1097 match state
.mode
with
1098 | Birdseye
_ -> gotopage pageno
0.0
1099 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 pageno
x y
1102 let getpassword () =
1103 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1108 impmsg "error getting password: %s" s;
1109 dolog
"%s" s) passcmd;
1112 let pgoto opaque pageno
x y =
1113 let pdimno = getpdimno pageno
in
1114 let x, y = project opaque pageno
pdimno x y in
1115 gotopagexy pageno
x y;
1119 (* dolog "%S" cmds; *)
1120 let spl = splitatchar cmds ' '
in
1122 try Scanf.sscanf
s fmt
f
1124 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1127 let addoutline outline
=
1128 match state
.currently
with
1129 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1130 | Idle
-> state
.currently
<- Outlining
[outline
]
1131 | Loading
_ | Tiling
_ ->
1132 dolog
"invalid outlining state";
1133 logcurrently state
.currently
1138 state
.uioh#infochanged Pdim
;
1140 | "clearrects", "" ->
1141 state
.rects
<- state
.rects1
;
1142 postRedisplay
"clearrects";
1144 | "continue", args
->
1145 let n = scan args
"%u" (fun n -> n) in
1146 state
.pagecount
<- n;
1147 begin match state
.currently
with
1149 state
.currently
<- Idle
;
1150 state
.outlines
<- Array.of_list
(List.rev l
)
1151 | Idle
| Loading
_ | Tiling
_ -> ()
1154 let cur, cmds
= state
.geomcmds
in
1156 then error
"empty geomcmd";
1158 begin match List.rev cmds
with
1160 state
.geomcmds
<- E.s, [];
1164 state
.geomcmds
<- s, List.rev rest
;
1166 postRedisplay
"continue";
1173 then showtext ' ' args
1176 Buffer.add_string state
.errmsgs args
;
1177 state
.newerrmsgs
<- true;
1178 postRedisplay
"error message"
1180 | "progress", args
->
1181 let progress, text =
1184 f, String.sub args pos
(String.length args
- pos
))
1187 state
.progress <- progress;
1188 postRedisplay
"progress"
1190 | "firstmatch", args
->
1191 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1192 scan args
"%u %d %f %f %f %f %f %f %f %f"
1193 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1194 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1196 let y = (getpagey
pageno) + truncate
y0 in
1198 if (state
.x < - truncate
x0) || (state
.x > state
.winw
- truncate
x1)
1199 then state
.winw
/2 - truncate
(x0 /. 2. +. x1 /. 2.)
1204 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1205 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1208 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1209 scan args
"%u %d %f %f %f %f %f %f %f %f"
1210 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1211 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1213 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1215 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1218 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1219 let pageopaque = ~
< pageopaques in
1220 begin match state
.currently
with
1221 | Loading
(l
, gen
) ->
1222 vlog "page %d took %f sec" l
.pageno t
;
1223 Hashtbl.replace state
.pagemap
(l
.pageno, gen
) pageopaque;
1224 let preloadedpages =
1226 then preloadlayout state
.x state
.y state
.winw state
.winh
1230 let set = List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
1231 IntSet.empty
preloadedpages
1234 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1235 if not
(IntSet.mem
pageno set)
1237 wcmd "freepage %s" (~
> opaque
);
1243 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1246 state
.currently
<- Idle
;
1249 tilepage l
.pageno pageopaque state
.layout;
1251 load preloadedpages;
1252 let visible = pagevisible state
.layout l
.pageno in
1255 match state
.mode
with
1256 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1257 if pageno = l
.pageno
1262 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1264 if dir
> 0 then LDfirst
else LDlast
1267 findlink
pageopaque ld
1272 showlinktype (getlink
pageopaque n);
1273 state
.mode
<- LinkNav
(Ltexact
(l
.pageno, n))
1275 | LinkNav
(Ltgendir
_)
1276 | LinkNav
(Ltexact
_)
1282 if visible && layoutready state
.layout
1284 postRedisplay
"page";
1288 | Idle
| Tiling
_ | Outlining
_ ->
1289 dolog
"Inconsistent loading state";
1290 logcurrently state
.currently
;
1295 let (x, y, opaques
, size
, t
) =
1296 scan args
"%u %u %s %u %f"
1297 (fun x y p size t
-> (x, y, p
, size
, t
))
1299 let opaque = ~
< opaques
in
1300 begin match state
.currently
with
1301 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1302 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
1305 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1307 wcmd "freetile %s" (~
> opaque);
1308 state
.currently
<- Idle
;
1312 puttileopaque l
col row gen cs angle
opaque size t
;
1313 state
.memused
<- state
.memused
+ size
;
1314 state
.uioh#infochanged Memused
;
1316 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
1317 opaque, size
) state
.tilelru
;
1319 state
.currently
<- Idle
;
1321 && conf
.colorspace
= cs
1322 && conf
.angle
= angle
1323 && tilevisible state
.layout l
.pageno x y
1324 then conttiling l
.pageno pageopaque;
1326 preload state
.layout;
1328 && conf
.colorspace
= cs
1329 && conf
.angle
= angle
1330 && tilevisible state
.layout l
.pageno x y
1331 && layoutready state
.layout
1332 then postRedisplay
"tile nothrottle";
1335 | Idle
| Loading
_ | Outlining
_ ->
1336 dolog
"Inconsistent tiling state";
1337 logcurrently state
.currently
;
1342 let (n, w, h, _) as pdim
=
1343 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1346 match conf
.fitmodel
with
1348 | FitPage
| FitProportional
->
1349 match conf
.columns
with
1350 | Csplit
_ -> (n, w, h, 0)
1351 | Csingle
_ | Cmulti
_ -> pdim
1353 state
.pdims
<- pdim :: state
.pdims
;
1354 state
.uioh#infochanged Pdim
1357 let (l
, n, t
, h, pos
) =
1358 scan args
"%u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
1360 let s = String.sub args pos
(String.length args
- pos
) in
1361 addoutline (s, l
, Oanchor
(n, float t
/. float h, 0.0))
1364 let (l
, len, pos
) = scan args
"%u %u %n" (fun l
len pos
-> l
, len, pos
) in
1365 let s = String.sub args pos
len in
1366 let pos2 = pos
+ len + 1 in
1367 let uri = String.sub args
pos2 (String.length args
- pos2) in
1368 addoutline (s, l
, Ouri
uri)
1371 let (l
, pos
) = scan args
"%u %n" (fun l pos
-> l
, pos
) in
1372 let s = String.sub args pos
(String.length args
- pos
) in
1373 addoutline (s, l
, Onone
)
1376 let (n, l
, t
) = scan args
"%u %d %d" (fun n l t
-> n, l
, t
) in
1377 state
.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
1380 let c, v
= splitatchar args '
\t'
in
1387 if not
!ignoredoctitlte
1388 then Wsi.settitle v
;
1392 if let len = String.length
c in
1393 len > 6 && ((String.sub
c (len-4) 4) = "date")
1395 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1397 let b = Buffer.create
10 in
1398 Printf.bprintf
b "%s\t" c;
1401 Buffer.add_substring
b v p l
;
1402 Buffer.add_char
b c;
1403 with exn
-> Buffer.add_string
b @@ exntos exn
1411 Buffer.add_char
b '
['
;
1412 Buffer.add_string
b v
;
1413 Buffer.add_char
b '
]'
;
1420 state
.docinfo
<- (1, s) :: state
.docinfo
1423 state
.docinfo
<- List.rev state
.docinfo
;
1424 state
.uioh#infochanged Docinfo
1428 then Wsi.settitle
"Wrong password";
1429 let password = getpassword () in
1430 if emptystr
password
1431 then error
"document is password protected"
1432 else opendoc state
.path
password
1434 | _ -> error
"unknown cmd `%S'" cmds
1439 let action = function
1440 | HCprev
-> cbget cb ~
-1
1441 | HCnext
-> cbget cb
1
1442 | HCfirst
-> cbget cb ~
-(cb
.rc)
1443 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1444 and cancel
() = cb
.rc <- rc
1448 let search pattern forward
=
1449 match conf
.columns
with
1450 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1451 | Csingle
_ | Cmulti
_ ->
1452 if nonemptystr pattern
1455 match state
.layout with
1457 | l
:: _ -> l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
1459 wcmd "search %d %d %d %d,%s\000"
1460 (btod conf
.icase
) pn py (btod forward
) pattern
;
1463 let intentry text key =
1465 if emptystr
text && key = Keys.Ascii '
-'
1466 then addchar
text '
-'
1468 match [@warning
"-4"] key with
1469 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1471 state
.text <- "invalid key";
1481 let l = String.length
s in
1482 let rec loop pos
n =
1486 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1487 loop (pos
+1) (n*26 + m)
1490 let rec loop n = function
1493 match getopaque l.pageno with
1494 | None
-> loop n rest
1496 let m = getlinkcount
opaque in
1499 let under = getlink
opaque n in
1502 else loop (n-m) rest
1504 loop n state
.layout;
1507 let linknentry text key = match [@warning
"-4"] key with
1509 let text = addchar
text c in
1510 linknact (fun under -> state
.text <- undertext under) text;
1513 state
.text <- Printf.sprintf
"invalid key";
1517 let textentry text key = match [@warning
"-4"] key with
1518 | Keys.Ascii
c -> TEcont
(addchar
text c)
1519 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1523 let reqlayout angle fitmodel
=
1524 if nogeomcmds state
.geomcmds
1525 then state
.anchor <- getanchor
();
1526 conf
.angle
<- angle
mod 360;
1529 match state
.mode
with
1530 | LinkNav
_ -> state
.mode
<- View
1531 | Birdseye
_ | Textentry
_ | View
-> ()
1533 conf
.fitmodel
<- fitmodel
;
1534 invalidate "reqlayout"
1535 (fun () -> wcmd "reqlayout %d %d %d"
1536 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1540 let settrim trimmargins trimfuzz
=
1541 if nogeomcmds state
.geomcmds
1542 then state
.anchor <- getanchor
();
1543 conf
.trimmargins
<- trimmargins
;
1544 conf
.trimfuzz
<- trimfuzz
;
1545 let x0, y0, x1, y1 = trimfuzz
in
1546 invalidate "settrim"
1547 (fun () -> wcmd "settrim %d %d %d %d %d"
1548 (btod conf
.trimmargins
) x0 y0 x1 y1);
1553 let zoom = max
0.0001 zoom in
1554 if zoom <> conf
.zoom
1556 state
.prevzoom
<- (conf
.zoom, state
.x);
1558 reshape state
.winw state
.winh
;
1559 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
1563 let pivotzoom ?
(vw=min state
.w state
.winw
)
1564 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
1565 ?
(x=vw/2) ?
(y=vh
/2) zoom =
1566 let w = float state
.w /. zoom in
1567 let hw = w /. 2.0 in
1568 let ratio = float vh
/. float vw in
1569 let hh = hw *. ratio in
1570 let x0 = float x -. hw
1571 and y0 = float y -. hh in
1572 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
1576 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
1577 if nogeomcmds state
.geomcmds
1580 then pivotzoom ?
vw ?vh ?
x ?
y zoom
1584 let setcolumns mode columns coverA coverB
=
1585 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
1589 then impmsg "split mode doesn't work in bird's eye"
1591 conf
.columns
<- Csplit
(-columns
, E.a);
1599 conf
.columns
<- Csingle
E.a;
1604 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
1608 reshape state
.winw state
.winh
;
1611 let resetmstate () =
1612 state
.mstate
<- Mnone
;
1613 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
1616 let enterbirdseye () =
1617 let zoom = float conf
.thumbw
/. float state
.winw
in
1618 let birdseyepageno =
1619 let cy = state
.winh
/ 2 in
1623 let rec fold best
= function
1626 let d = cy - (l.pagedispy + l.pagevh/2)
1627 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
1628 if abs
d < abs dbest
1637 { conf
with zoom = conf
.zoom },
1638 state
.x, birdseyepageno, -1, getanchor
()
1642 conf
.presentation
<- false;
1643 conf
.interpagespace
<- 10;
1644 conf
.hlinks
<- false;
1645 conf
.fitmodel
<- FitPage
;
1648 match conf
.beyecolumns
with
1651 Cmulti
((c, 0, 0), E.a)
1652 | None
-> Csingle
E.a
1655 then state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1657 else state
.text <- E.s;
1658 reshape state
.winw state
.winh
;
1661 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1663 conf
.zoom <- c.zoom;
1664 conf
.presentation
<- c.presentation
;
1665 conf
.interpagespace
<- c.interpagespace
;
1666 conf
.hlinks
<- c.hlinks
;
1667 conf
.fitmodel
<- c.fitmodel
;
1668 conf
.beyecolumns
<- (
1669 match conf
.columns
with
1670 | Cmulti
((c, _, _), _) -> Some
c
1672 | Csplit
_ -> error
"leaving bird's eye split mode"
1675 match c.columns
with
1676 | Cmulti
(c, _) -> Cmulti
(c, E.a)
1677 | Csingle
_ -> Csingle
E.a
1678 | Csplit
(c, _) -> Csplit
(c, E.a)
1682 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1684 reshape state
.winw state
.winh
;
1685 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
1689 let togglebirdseye () =
1690 match state
.mode
with
1691 | Birdseye vals
-> leavebirdseye vals
true
1692 | View
-> enterbirdseye ()
1693 | Textentry
_ | LinkNav
_ -> ()
1696 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1697 let pageno = max
0 (pageno - incr
) in
1698 let rec loop = function
1699 | [] -> gotopage1 pageno 0
1700 | l :: _ when l.pageno = pageno ->
1701 if l.pagedispy >= 0 && l.pagey = 0
1702 then postRedisplay
"upbirdseye"
1703 else gotopage1 pageno 0
1704 | _ :: rest
-> loop rest
1708 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
1711 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1712 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
1713 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
1714 let rec loop = function
1716 let y, h = getpageyh
pageno in
1717 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
1718 gotoxy state
.x (clamp dy)
1719 | l :: _ when l.pageno = pageno ->
1720 if l.pagevh != l.pageh
1721 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
1722 else postRedisplay
"downbirdseye"
1723 | _ :: rest
-> loop rest
1729 let optentry mode
_ key =
1730 let btos b = if b then "on" else "off" in
1731 match [@warning
"-4"] key with
1735 let n, a, b = multicolumns_of_string
s in
1736 setcolumns mode
n a b;
1738 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
1740 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
1745 let zoom = float (int_of_string
s) /. 100.0 in
1748 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1750 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
1753 conf
.icase
<- not conf
.icase
;
1754 TEdone
("case insensitive search " ^
(btos conf
.icase
))
1757 conf
.verbose
<- not conf
.verbose
;
1758 TEdone
("verbose " ^
(btos conf
.verbose
))
1761 conf
.debug
<- not conf
.debug
;
1762 TEdone
("debug " ^
(btos conf
.debug
))
1765 conf
.underinfo
<- not conf
.underinfo
;
1766 TEdone
("underinfo " ^
btos conf
.underinfo
)
1769 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
1770 TEdone
("trim margins " ^
btos conf
.trimmargins
)
1773 conf
.invert
<- not conf
.invert
;
1774 TEdone
("invert colors " ^
btos conf
.invert
)
1778 cbput state
.hists
.sel
s;
1781 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
1782 textentry, ondone, true)
1786 then conf
.pax
<- Some
0.0
1787 else conf
.pax
<- None
;
1788 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
1791 state
.text <- Printf.sprintf
"bad option %d `%c'" (Char.code
c) c;
1794 | _ -> TEcont state
.text
1797 let adderrmsg src msg
=
1798 Buffer.add_string state
.errmsgs msg
;
1799 state
.newerrmsgs
<- true;
1803 let adderrfmt src fmt
= Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;;
1805 class outlinelistview ~zebra ~source
=
1806 let settext autonarrow
s =
1809 let ss = source#statestr
in
1810 state
.text <- if emptystr
ss
1812 else "{" ^
ss ^
"} [" ^
s ^
"]"
1813 else state
.text <- s
1819 ~source
:(source
:> lvsource
)
1821 ~modehash
:(findkeyhash conf
"outline")
1824 val m_autonarrow
= false
1826 method! key key mask
=
1828 if emptystr state
.text
1830 else fstate
.maxrows - 2
1832 let calcfirst first active
=
1835 let rows = active
- first
in
1836 if rows > maxrows then active
- maxrows else first
1840 let active = m_active
+ incr
in
1841 let active = bound
active 0 (source#getitemcount
- 1) in
1842 let first = calcfirst m_first
active in
1843 postRedisplay
"outline navigate";
1844 coe
{< m_active
= active; m_first
= first >}
1846 let navscroll first =
1848 let dist = m_active
- first in
1854 else first + maxrows
1857 postRedisplay
"outline navscroll";
1858 coe
{< m_first
= first; m_active
= active >}
1860 let ctrl = Wsi.withctrl mask
in
1862 match Wsi.kc2kt
key with
1863 | Ascii '
a'
when ctrl ->
1871 let pattern = source#renarrow
in
1872 if nonemptystr m_qsearch
1873 then (source#narrow m_qsearch
; m_qsearch
)
1877 settext (not m_autonarrow
) text;
1878 postRedisplay
"toggle auto narrowing";
1879 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
1881 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
1883 postRedisplay
"toggle auto narrowing";
1884 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
1886 | Ascii '
n'
when ctrl ->
1887 source#narrow m_qsearch
;
1889 then source#add_narrow_pattern m_qsearch
;
1890 postRedisplay
"outline ctrl-n";
1891 coe
{< m_first
= 0; m_active
= 0 >}
1893 | Ascii 'S'
when ctrl ->
1894 let active = source#calcactive
(getanchor
()) in
1895 let first = firstof m_first
active in
1896 postRedisplay
"outline ctrl-s";
1897 coe
{< m_first
= first; m_active
= active >}
1899 | Ascii 'u'
when ctrl ->
1900 postRedisplay
"outline ctrl-u";
1901 if m_autonarrow
&& nonemptystr m_qsearch
1903 ignore
(source#renarrow
);
1904 settext m_autonarrow
E.s;
1905 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1908 source#del_narrow_pattern
;
1909 let pattern = source#renarrow
in
1911 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
1913 settext m_autonarrow
text;
1914 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1917 | Ascii '
l'
when ctrl ->
1918 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
1919 postRedisplay
"outline ctrl-l";
1920 coe
{< m_first
= first >}
1922 | Ascii '
\t'
when m_autonarrow
->
1923 if nonemptystr m_qsearch
1925 postRedisplay
"outline list view tab";
1926 source#add_narrow_pattern m_qsearch
;
1928 coe
{< m_qsearch
= E.s >}
1932 | Escape
when m_autonarrow
->
1933 if nonemptystr m_qsearch
1934 then source#add_narrow_pattern m_qsearch
;
1937 | Enter
when m_autonarrow
->
1938 if nonemptystr m_qsearch
1939 then source#add_narrow_pattern m_qsearch
;
1942 | (Ascii
_ | Code
_) when m_autonarrow
->
1943 let pattern = m_qsearch ^ toutf8
key in
1944 postRedisplay
"outlinelistview autonarrow add";
1945 source#narrow
pattern;
1946 settext true pattern;
1947 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
1949 | Backspace
when m_autonarrow
->
1950 if emptystr m_qsearch
1953 let pattern = withoutlastutf8 m_qsearch
in
1954 postRedisplay
"outlinelistview autonarrow backspace";
1955 ignore
(source#renarrow
);
1956 source#narrow
pattern;
1957 settext true pattern;
1958 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
1960 | Up
when ctrl -> navscroll (max
0 (m_first
- 1))
1963 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
1965 | Up
-> navigate ~
-1
1966 | Down
-> navigate 1
1967 | Prior
-> navigate ~
-(fstate
.maxrows)
1968 | Next
-> navigate fstate
.maxrows
1974 postRedisplay
"outline ctrl right";
1975 {< m_pan
= m_pan
+ 1 >}
1977 else self#updownlevel
1
1985 postRedisplay
"outline ctrl left";
1986 {< m_pan
= m_pan
- 1 >}
1988 else self#updownlevel ~
-1
1993 postRedisplay
"outline home";
1994 coe
{< m_first
= 0; m_active
= 0 >}
1997 let active = source#getitemcount
- 1 in
1998 let first = max
0 (active - fstate
.maxrows) in
1999 postRedisplay
"outline end";
2000 coe
{< m_active
= active; m_first
= first >}
2002 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
2006 let genhistoutlines () =
2008 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
2009 compare c2
.lastvisit c1
.lastvisit
)
2010 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
2011 let path = if nonemptystr origin
then origin
else path in
2012 let base = mbtoutf8
@@ Filename.basename
path in
2013 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
2017 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
2018 Config.save
leavebirdseye;
2019 state
.anchor <- anchor;
2020 state
.bookmarks
<- bookmarks
;
2021 state
.origin
<- origin
;
2024 let x0, y0, x1, y1 = conf
.trimfuzz
in
2025 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
2026 reshape ~firsttime
:true state
.winw state
.winh
;
2027 opendoc path origin
;
2031 let setcheckers enabled
=
2032 match !checkerstexid with
2033 | None
-> if enabled
then checkerstexid := Some
(makecheckers
())
2037 GlTex.delete_texture id
;
2038 checkerstexid := None
;
2042 let describe_layout layout =
2046 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
2049 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
2050 else Printf.sprintf
"%d%s%d" (a.pageno+1)
2051 (if a.pageno+1 = b.pageno then ", " else Utf8syms.ellipsis
)
2054 let rec fold s la lb
= function
2055 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
2056 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
2057 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
2059 fold "Pages" l l rest
2062 let maxy = maxy () in
2065 else 100. *. (float state
.y /. float maxy)
2067 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
2070 let setpresentationmode v
=
2071 let n = page_of_y state
.y in
2072 state
.anchor <- (n, 0.0, 1.0);
2073 conf
.presentation
<- v
;
2074 if conf
.fitmodel
= FitPage
2075 then reqlayout conf
.angle conf
.fitmodel
;
2080 let btos b = if b then Utf8syms.radical
else E.s in
2081 let showextended = ref false in
2082 let showcolors = ref false in
2083 let leave mode
_ = state
.mode
<- mode
in
2086 val mutable m_l
= []
2087 val mutable m_a
= E.a
2088 val mutable m_prev_uioh
= nouioh
2089 val mutable m_prev_mode
= View
2091 inherit lvsourcebase
2093 method reset prev_mode prev_uioh
=
2094 m_a
<- Array.of_list
(List.rev m_l
);
2096 m_prev_mode
<- prev_mode
;
2097 m_prev_uioh
<- prev_uioh
;
2099 method int name get
set =
2105 try set (int_of_string
s)
2107 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2111 let te = name ^
": ", E.s, None
, intentry, ondone, true in
2112 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2116 method int_with_suffix name get
set =
2118 (name
, `intws get
, 1,
2122 try set (int_of_string_with_suffix
s)
2124 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2129 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
2131 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2135 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2137 (name
, `
bool (btos, get
), offset
, Action
(
2144 method color name get
set =
2146 (name
, `
color get
, 1,
2149 let invalid = (nan
, nan
, nan
) in
2152 try color_of_string
s
2154 state
.text <- Printf.sprintf
"bad color `%s': %s"
2161 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2162 state
.text <- color_to_string
(get
());
2163 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2167 method string name get
set =
2169 (name
, `
string get
, 1,
2172 let ondone s = set s in
2173 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2174 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2178 method colorspace name get
set =
2180 (name
, `
string get
, 1,
2185 inherit lvsourcebase
2188 m_active
<- CSTE.to_int conf
.colorspace
;
2191 method getitemcount
=
2192 Array.length
CSTE.names
2195 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2196 ignore
(uioh
, first, pan
);
2197 if not cancel
then set active;
2199 method hasaction
_ = true
2203 let modehash = findkeyhash conf
"info" in
2204 coe
(new listview ~zebra
:false ~helpmode
:false
2205 ~
source ~trusted
:true ~
modehash)
2208 method paxmark name get
set =
2210 (name
, `
string get
, 1,
2215 inherit lvsourcebase
2218 m_active
<- MTE.to_int conf
.paxmark
;
2221 method getitemcount
= Array.length
MTE.names
2222 method getitem
n = (MTE.names
.(n), 0)
2223 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2224 ignore
(uioh
, first, pan
);
2225 if not cancel
then set active;
2227 method hasaction
_ = true
2231 let modehash = findkeyhash conf
"info" in
2232 coe
(new listview ~zebra
:false ~helpmode
:false
2233 ~
source ~trusted
:true ~
modehash)
2236 method fitmodel name get
set =
2238 (name
, `
string get
, 1,
2243 inherit lvsourcebase
2246 m_active
<- FMTE.to_int conf
.fitmodel
;
2249 method getitemcount
= Array.length
FMTE.names
2250 method getitem
n = (FMTE.names
.(n), 0)
2251 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2252 ignore
(uioh
, first, pan
);
2253 if not cancel
then set active;
2255 method hasaction
_ = true
2259 let modehash = findkeyhash conf
"info" in
2260 coe
(new listview ~zebra
:false ~helpmode
:false
2261 ~
source ~trusted
:true ~
modehash)
2264 method caption
s offset
=
2265 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
2267 method caption2
s f offset
=
2268 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
2270 method getitemcount
= Array.length m_a
2273 let tostr = function
2274 | `
int f -> string_of_int
(f ())
2275 | `intws
f -> string_with_suffix_of_int
(f ())
2277 | `
color f -> color_to_string
(f ())
2278 | `
bool (btos, f) -> btos (f ())
2281 let name, t
, offset
, _ = m_a
.(n) in
2282 ((let s = tostr t
in
2284 then Printf.sprintf
"%s\t%s" name s
2288 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2293 match m_a
.(active) with
2294 | _, _, _, Action
f -> f uioh
2295 | _, _, _, Noaction
-> uioh
2306 method hasaction
n =
2308 | _, _, _, Action
_ -> true
2309 | _, _, _, Noaction
-> false
2311 initializer m_active
<- 1
2314 let rec fillsrc prevmode prevuioh
=
2315 let sep () = src#caption
E.s 0 in
2316 let colorp name get
set =
2318 (fun () -> color_to_string
(get
()))
2320 try set @@ color_of_string
v
2323 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2326 let rgba name get
set =
2328 (fun () -> get
() |> rgba_to_string
)
2330 try set @@ rgba_of_string
v
2333 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2336 let oldmode = state
.mode
in
2337 let birdseye = isbirdseye state
.mode
in
2339 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
2341 src#
bool "presentation mode"
2342 (fun () -> conf
.presentation
)
2343 (fun v -> setpresentationmode v);
2345 src#
bool "ignore case in searches"
2346 (fun () -> conf
.icase
)
2347 (fun v -> conf
.icase
<- v);
2350 (fun () -> conf
.preload)
2351 (fun v -> conf
.preload <- v);
2353 src#
bool "highlight links"
2354 (fun () -> conf
.hlinks
)
2355 (fun v -> conf
.hlinks
<- v);
2357 src#
bool "under info"
2358 (fun () -> conf
.underinfo
)
2359 (fun v -> conf
.underinfo
<- v);
2361 src#fitmodel
"fit model"
2362 (fun () -> FMTE.to_string conf
.fitmodel
)
2363 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
2365 src#
bool "trim margins"
2366 (fun () -> conf
.trimmargins
)
2367 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
2370 src#
int "inter-page space"
2371 (fun () -> conf
.interpagespace
)
2373 conf
.interpagespace
<- n;
2374 docolumns conf
.columns
;
2376 match state
.layout with
2378 | l :: _ -> l.pageno, l.pagey
2380 state
.maxy <- calcheight
();
2381 let y = getpagey
pageno in
2382 gotoxy state
.x (y + py)
2386 (fun () -> conf
.pagebias
)
2387 (fun v -> conf
.pagebias
<- v);
2389 src#
int "scroll step"
2390 (fun () -> conf
.scrollstep
)
2391 (fun n -> conf
.scrollstep
<- n);
2393 src#
int "horizontal scroll step"
2394 (fun () -> conf
.hscrollstep
)
2395 (fun v -> conf
.hscrollstep
<- v);
2397 src#
int "auto scroll step"
2399 match state
.autoscroll
with
2401 | _ -> conf
.autoscrollstep
)
2403 let n = boundastep state
.winh
n in
2404 if state
.autoscroll
<> None
2405 then state
.autoscroll
<- Some
n;
2406 conf
.autoscrollstep
<- n);
2409 (fun () -> truncate
(conf
.zoom *. 100.))
2410 (fun v -> pivotzoom ((float v) /. 100.));
2413 (fun () -> conf
.angle
)
2414 (fun v -> reqlayout v conf
.fitmodel
);
2416 src#
int "scroll bar width"
2417 (fun () -> conf
.scrollbw
)
2420 reshape state
.winw state
.winh
;
2423 src#
int "scroll handle height"
2424 (fun () -> conf
.scrollh
)
2425 (fun v -> conf
.scrollh
<- v;);
2427 src#
int "thumbnail width"
2428 (fun () -> conf
.thumbw
)
2430 conf
.thumbw
<- min
4096 v;
2433 leavebirdseye beye
false;
2440 let mode = state
.mode in
2441 src#
string "columns"
2443 match conf
.columns
with
2445 | Cmulti
(multi
, _) -> multicolumns_to_string multi
2446 | Csplit
(count
, _) -> "-" ^ string_of_int count
2449 let n, a, b = multicolumns_of_string
v in
2450 setcolumns mode n a b);
2453 src#caption
"Pixmap cache" 0;
2454 src#int_with_suffix
"size (advisory)"
2455 (fun () -> conf
.memlimit
)
2456 (fun v -> conf
.memlimit
<- v);
2460 Printf.sprintf
"%s bytes, %d tiles"
2461 (string_with_suffix_of_int state
.memused
)
2462 (Hashtbl.length state
.tilemap
)) 1;
2465 src#caption
"Layout" 0;
2466 src#caption2
"Dimension"
2467 (fun () -> Printf.sprintf
"%dx%d (virtual %dx%d)"
2468 state
.winw state
.winh
2472 then src#caption2
"Position" (fun () ->
2473 Printf.sprintf
"%dx%d" state
.x state
.y
2475 else src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
2478 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
2479 "Save these parameters as global defaults at exit"
2480 (fun () -> conf
.bedefault
)
2481 (fun v -> conf
.bedefault
<- v);
2484 let btos b = Utf8syms.(if b then lguillemet
else rguillemet
) in
2485 src#
bool ~offset
:0 ~
btos "Extended parameters"
2486 (fun () -> !showextended)
2487 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
2491 (fun () -> conf
.checkers
)
2492 (fun v -> conf
.checkers
<- v; setcheckers v);
2493 src#
bool "update cursor"
2494 (fun () -> conf
.updatecurs
)
2495 (fun v -> conf
.updatecurs
<- v);
2496 src#
bool "scroll-bar on the left"
2497 (fun () -> conf
.leftscroll
)
2498 (fun v -> conf
.leftscroll
<- v);
2500 (fun () -> conf
.verbose
)
2501 (fun v -> conf
.verbose
<- v);
2502 src#
bool "invert colors"
2503 (fun () -> conf
.invert
)
2504 (fun v -> conf
.invert
<- v);
2506 (fun () -> conf
.maxhfit
)
2507 (fun v -> conf
.maxhfit
<- v);
2509 (fun () -> conf
.pax
!= None
)
2512 then conf
.pax
<- Some
(now
())
2513 else conf
.pax
<- None
);
2514 src#
string "uri launcher"
2515 (fun () -> conf
.urilauncher
)
2516 (fun v -> conf
.urilauncher
<- v);
2517 src#
string "path launcher"
2518 (fun () -> conf
.pathlauncher
)
2519 (fun v -> conf
.pathlauncher
<- v);
2520 src#
string "tile size"
2521 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
2524 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
2525 conf
.tilew
<- max
64 w;
2526 conf
.tileh
<- max
64 h;
2529 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
2532 src#
int "texture count"
2533 (fun () -> conf
.texcount
)
2536 then conf
.texcount
<- v
2537 else impmsg "failed to set texture count please retry later"
2539 src#
int "slice height"
2540 (fun () -> conf
.sliceheight
)
2542 conf
.sliceheight
<- v;
2543 wcmd "sliceh %d" conf
.sliceheight
;
2545 src#
int "anti-aliasing level"
2546 (fun () -> conf
.aalevel
)
2548 conf
.aalevel
<- bound
v 0 8;
2549 state
.anchor <- getanchor
();
2550 opendoc state
.path state
.password;
2552 src#
string "page scroll scaling factor"
2553 (fun () -> string_of_float conf
.pgscale)
2555 try conf
.pgscale <- float_of_string
v
2558 Printf.sprintf
"bad page scroll scaling factor `%s': %s" v
2561 src#
int "ui font size"
2562 (fun () -> fstate
.fontsize
)
2563 (fun v -> setfontsize (bound
v 5 100));
2564 src#
int "hint font size"
2565 (fun () -> conf
.hfsize
)
2566 (fun v -> conf
.hfsize
<- bound
v 5 100);
2567 src#
string "trim fuzz"
2568 (fun () -> irect_to_string conf
.trimfuzz
)
2571 conf
.trimfuzz
<- irect_of_string
v;
2573 then settrim true conf
.trimfuzz
;
2575 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
2578 src#
string "selection command"
2579 (fun () -> conf
.selcmd
)
2580 (fun v -> conf
.selcmd
<- v);
2581 src#
string "synctex command"
2582 (fun () -> conf
.stcmd
)
2583 (fun v -> conf
.stcmd
<- v);
2584 src#
string "pax command"
2585 (fun () -> conf
.paxcmd
)
2586 (fun v -> conf
.paxcmd
<- v);
2587 src#
string "ask password command"
2588 (fun () -> conf
.passcmd)
2589 (fun v -> conf
.passcmd <- v);
2590 src#
string "save path command"
2591 (fun () -> conf
.savecmd
)
2592 (fun v -> conf
.savecmd
<- v);
2593 src#colorspace
"color space"
2594 (fun () -> CSTE.to_string conf
.colorspace
)
2596 conf
.colorspace
<- CSTE.of_int
v;
2600 src#paxmark
"pax mark method"
2601 (fun () -> MTE.to_string conf
.paxmark
)
2602 (fun v -> conf
.paxmark
<- MTE.of_int
v);
2606 (fun () -> conf
.usepbo
)
2607 (fun v -> conf
.usepbo
<- v);
2608 src#
bool "mouse wheel scrolls pages"
2609 (fun () -> conf
.wheelbypage
)
2610 (fun v -> conf
.wheelbypage
<- v);
2611 src#
bool "open remote links in a new instance"
2612 (fun () -> conf
.riani
)
2613 (fun v -> conf
.riani
<- v);
2614 src#
bool "edit annotations inline"
2615 (fun () -> conf
.annotinline
)
2616 (fun v -> conf
.annotinline
<- v);
2617 src#
bool "coarse positioning in presentation mode"
2618 (fun () -> conf
.coarseprespos
)
2619 (fun v -> conf
.coarseprespos
<- v);
2620 src#
bool "use document CSS"
2621 (fun () -> conf
.usedoccss
)
2623 conf
.usedoccss
<- v;
2624 state
.anchor <- getanchor
();
2625 opendoc state
.path state
.password;
2627 src#
bool ~
btos "colors"
2628 (fun () -> !showcolors)
2629 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
2632 colorp " background"
2633 (fun () -> conf
.bgcolor
)
2634 (fun v -> conf
.bgcolor
<- v);
2636 (fun () -> conf
.sbarcolor
)
2637 (fun v -> conf
.sbarcolor
<- v);
2638 rgba " scrollbar handle"
2639 (fun () -> conf
.sbarhndlcolor
)
2640 (fun v -> conf
.sbarhndlcolor
<- v);
2645 src#caption
"Document" 0;
2646 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
2647 src#caption2
"Pages"
2648 (fun () -> string_of_int state
.pagecount
) 1;
2649 src#caption2
"Dimensions"
2650 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2651 if nonemptystr conf
.css
2652 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
2656 src#caption
"Trimmed margins" 0;
2657 src#caption2
"Dimensions"
2658 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2662 src#caption
"OpenGL" 0;
2663 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
2664 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
2667 src#caption
"Location" 0;
2668 if nonemptystr state
.origin
2669 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
2670 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
2672 src#reset prevmode prevuioh
;
2677 let prevmode = state
.mode
2678 and prevuioh
= state
.uioh in
2679 fillsrc prevmode prevuioh
;
2680 let source = (src :> lvsource
) in
2681 let modehash = findkeyhash conf
"info" in
2684 inherit listview ~zebra
:false ~helpmode
:false
2685 ~
source ~trusted
:true ~
modehash as super
2686 val mutable m_prevmemused
= 0
2687 method! infochanged
= function
2689 if m_prevmemused
!= state
.memused
2691 m_prevmemused
<- state
.memused
;
2692 postRedisplay
"memusedchanged";
2694 | Pdim
-> postRedisplay
"pdimchanged"
2695 | Docinfo
-> fillsrc prevmode prevuioh
2697 method! key key mask
=
2698 if not
(Wsi.withctrl mask
)
2700 match [@warning
"-4"] Wsi.kc2kt
key with
2701 | Keys.Left
-> coe
(self#updownlevel ~
-1)
2702 | Keys.Right
-> coe
(self#updownlevel
1)
2703 | _ -> super#
key key mask
2704 else super#
key key mask
2706 postRedisplay
"info";
2712 inherit lvsourcebase
2713 method getitemcount
= Array.length state
.help
2715 let s, l, _ = state
.help
.(n) in
2718 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2722 match state
.help
.(active) with
2723 | _, _, Action
f -> Some
(f uioh)
2724 | _, _, Noaction
-> Some
uioh
2733 method hasaction
n =
2734 match state
.help
.(n) with
2735 | _, _, Action
_ -> true
2736 | _, _, Noaction
-> false
2742 let modehash = findkeyhash conf
"help" in
2744 state
.uioh <- coe
(new listview
2745 ~zebra
:false ~helpmode
:true
2746 ~
source ~trusted
:true ~
modehash);
2747 postRedisplay
"help";
2753 inherit lvsourcebase
2754 val mutable m_items
= E.a
2756 method getitemcount
= 1 + Array.length m_items
2761 else m_items
.(n-1), 0
2763 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2768 then Buffer.clear state
.errmsgs
;
2775 method hasaction
n =
2779 state
.newerrmsgs
<- false;
2780 let l = Str.split
Utils.Re.crlf
(Buffer.contents state
.errmsgs
) in
2781 m_items
<- Array.of_list
l
2790 let source = (msgsource :> lvsource
) in
2791 let modehash = findkeyhash conf
"listview" in
2794 inherit listview ~zebra
:false ~helpmode
:false
2795 ~
source ~trusted
:false ~
modehash as super
2798 then msgsource#reset
;
2801 postRedisplay
"msgs";
2805 let editor = getenvwithdef
"EDITOR" E.s in
2809 let tmppath = Filename.temp_file
"llpp" "note" in
2812 let oc = open_out
tmppath in
2816 let execstr = editor ^
" " ^
tmppath in
2818 match spawn
execstr [] with
2820 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
2823 match Unix.waitpid
[] pid
with
2825 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
2829 | Unix.WEXITED
0 -> filecontents
tmppath
2831 impmsg "editor process(%s) exited abnormally: %d" execstr n;
2833 | Unix.WSIGNALED
n ->
2834 impmsg "editor process(%s) was killed by signal %d" execstr n;
2836 | Unix.WSTOPPED
n ->
2837 impmsg "editor(%s) process was stopped by signal %d" execstr n;
2840 match Unix.unlink
tmppath with
2842 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
2847 let enterannotmode opaque slinkindex
=
2850 inherit lvsourcebase
2851 val mutable m_text
= E.s
2852 val mutable m_items
= E.a
2854 method getitemcount
= Array.length m_items
2857 let label, _func
= m_items
.(n) in
2860 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2861 ignore
(uioh, first, pan
);
2864 let _label, func
= m_items
.(active) in
2869 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
2872 let rec split accu b i
=
2874 if p = String.length
s
2875 then (String.sub s b (p-b), unit) :: accu
2877 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
2879 let ss = if i
= 0 then E.s else String.sub s b i
in
2880 split ((ss, unit)::accu) (p+1) 0
2881 else split accu b (i
+1)
2884 wcmd "freepage %s" (~
> opaque);
2886 Hashtbl.fold (fun key opaque'
accu ->
2887 if opaque'
= opaque'
2888 then key :: accu else accu) state
.pagemap
[]
2890 List.iter
(Hashtbl.remove state
.pagemap
) keys;
2892 gotoxy state
.x state
.y
2895 delannot
opaque slinkindex
;
2898 let edit inline
() =
2903 modannot
opaque slinkindex
s;
2909 let mode = state
.mode in
2912 ("annotation: ", m_text
, None
, textentry, update, true),
2913 fun _ -> state
.mode <- mode
2918 let s = getusertext m_text
in
2923 ( "[Copy]", fun () -> selstring conf
.selcmd m_text
)
2924 :: ("[Delete]", dele)
2925 :: ("[Edit]", edit conf
.annotinline
)
2927 :: split [] 0 0 |> List.rev
|> Array.of_list
2934 let s = getannotcontents
opaque slinkindex
in
2937 let source = (msgsource :> lvsource
) in
2938 let modehash = findkeyhash conf
"listview" in
2939 state
.uioh <- coe
(object
2940 inherit listview ~zebra
:false ~helpmode
:false
2941 ~
source ~trusted
:false ~
modehash
2943 postRedisplay
"enterannotmode";
2946 let gotoremote spec
=
2947 let filename, dest
= splitatchar spec '#'
in
2948 let getpath filename =
2950 if nonemptystr
filename
2952 if Filename.is_relative
filename
2954 let dir = Filename.dirname state
.path in
2956 if Filename.is_implicit
dir
2957 then Filename.concat
(Sys.getcwd
()) dir
2960 Filename.concat
dir filename
2964 if Sys.file_exists
path
2968 let path = getpath filename in
2972 let cmd = Lazy.force_val lcmd
in
2973 match spawn
cmd with
2975 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
2977 let anchor = getanchor
() in
2978 let ranchor = state
.path, state
.password, anchor, state
.origin
in
2979 state
.origin
<- E.s;
2980 state
.ranchors
<- ranchor :: state
.ranchors
;
2983 if substratis spec
0 "page="
2985 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
2987 state
.anchor <- (pageno, 0.0, 0.0);
2988 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
2990 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
2992 state
.nameddest
<- dest
;
2993 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
2997 let gotounder = function
2998 | Ulinkuri
s when isexternallink
s ->
2999 if substratis
s 0 "file://"
3000 then gotoremote @@ String.sub s 7 (String.length
s - 7)
3001 else Help.gotouri conf
.urilauncher
s
3003 let pageno, x, y = uritolocation
s in
3005 gotopagexy pageno x y
3006 | Utext
_ | Unone
-> ()
3007 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
3010 let gotooutline (_, _, kind
) =
3014 let (pageno, y, _) = anchor in
3016 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3020 | Ouri
uri -> gotounder (Ulinkuri
uri)
3021 | Olaunch
cmd -> error
"gotounder (Ulaunch %S)" cmd
3022 | Oremote
(remote
, pageno) ->
3023 error
"gotounder (Uremote (%S,%d) )" remote
pageno
3024 | Ohistory hist
-> gotohist hist
3025 | Oremotedest
(path, dest
) ->
3026 error
"gotounder (Uremotedest (%S, %S))" path dest
3029 class outlinesoucebase fetchoutlines
= object (self
)
3030 inherit lvsourcebase
3031 val mutable m_items
= E.a
3032 val mutable m_minfo
= E.a
3033 val mutable m_orig_items
= E.a
3034 val mutable m_orig_minfo
= E.a
3035 val mutable m_narrow_patterns
= []
3036 val mutable m_gen
= -1
3038 method getitemcount
= Array.length m_items
3041 let s, n, _ = m_items
.(n) in
3044 method exit ~
(uioh:uioh) ~cancel ~
active ~
(first:int) ~pan
: uioh option =
3045 ignore
(uioh, first);
3047 if m_narrow_patterns
= []
3048 then m_orig_items
, m_orig_minfo
3049 else m_items
, m_minfo
3056 gotooutline m_items
.(active);
3064 method hasaction
(_:int) = true
3067 if Array.length m_items
!= Array.length m_orig_items
3070 match m_narrow_patterns
with
3072 | many
-> String.concat
Utf8syms.ellipsis
(List.rev many
)
3074 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3078 match m_narrow_patterns
with
3081 | head
:: _ -> Utf8syms.ellipsis ^ head
3083 method narrow
pattern =
3084 match Str.regexp_case_fold
pattern with
3087 let rec loop accu minfo
n =
3090 m_items
<- Array.of_list
accu;
3091 m_minfo
<- Array.of_list minfo
;
3094 let (s, _, _) as o = m_items
.(n) in
3096 match Str.search_forward re
s 0 with
3097 | exception Not_found
-> accu, minfo
3098 | first -> o :: accu, (first, Str.match_end
()) :: minfo
3100 loop accu minfo
(n-1)
3102 loop [] [] (Array.length m_items
- 1)
3104 method! getminfo
= m_minfo
3107 m_orig_items
<- fetchoutlines
();
3108 m_minfo
<- m_orig_minfo
;
3109 m_items
<- m_orig_items
3111 method add_narrow_pattern
pattern =
3112 m_narrow_patterns
<- pattern :: m_narrow_patterns
3114 method del_narrow_pattern
=
3115 match m_narrow_patterns
with
3116 | _ :: rest
-> m_narrow_patterns
<- rest
3121 match m_narrow_patterns
with
3122 | pattern :: [] -> self#narrow
pattern; pattern
3124 List.fold_left
(fun accu pattern ->
3125 self#narrow
pattern;
3126 pattern ^
Utf8syms.ellipsis ^
accu) E.s list
3128 method calcactive
(_:anchor) = 0
3130 method reset
anchor items =
3131 if state
.gen
!= m_gen
3133 m_orig_items
<- items;
3135 m_narrow_patterns
<- [];
3137 m_orig_minfo
<- E.a;
3141 if items != m_orig_items
3143 m_orig_items
<- items;
3144 if m_narrow_patterns
== []
3145 then m_items
<- items;
3148 let active = self#calcactive
anchor in
3150 m_first
<- firstof m_first
active
3154 let outlinesource fetchoutlines
=
3156 inherit outlinesoucebase fetchoutlines
3157 method! calcactive
anchor =
3158 let rely = getanchory anchor in
3159 let rec loop n best bestd
=
3160 if n = Array.length m_items
3163 let _, _, kind
= m_items
.(n) in
3166 let orely = getanchory anchor in
3167 let d = abs
(orely - rely) in
3170 else loop (n+1) best bestd
3171 | Onone
| Oremote
_ | Olaunch
_
3172 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
3173 loop (n+1) best bestd
3179 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
3180 let mkselector sourcetype
=
3181 let fetchoutlines () =
3182 match sourcetype
with
3183 | `bookmarks
-> Array.of_list state
.bookmarks
3184 | `outlines
-> state
.outlines
3185 | `history
-> genhistoutlines () |> Array.of_list
3188 if sourcetype
= `history
3189 then new outlinesoucebase
fetchoutlines
3190 else outlinesource fetchoutlines
3193 let outlines = fetchoutlines () in
3194 if Array.length
outlines = 0
3195 then showtext ' ' errmsg
3198 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3199 let anchor = getanchor
() in
3200 source#reset
anchor outlines;
3201 state
.text <- source#greetmsg
;
3203 coe
(new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
3204 postRedisplay
"enter selector";
3208 let mkenter sourcetype errmsg
= fun () -> mkselector sourcetype errmsg
in
3209 ( mkenter `
outlines "document has no outline"
3210 , mkenter `bookmarks
"document has no bookmarks (yet)"
3211 , mkenter `history
"history is empty" )
3214 let quickbookmark ?title
() =
3215 match state
.layout with
3222 let tm = localtime
(now
()) in
3224 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
3226 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
3228 | Some
title -> title
3230 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3233 let setautoscrollspeed step goingdown
=
3234 let incr = max
1 ((abs step
) / 2) in
3235 let incr = if goingdown
then incr else -incr in
3236 let astep = boundastep state
.winh
(step
+ incr) in
3237 state
.autoscroll
<- Some
astep;
3241 match conf
.columns
with
3243 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
3246 let panbound x = bound
x (-state
.w) state
.winw
;;
3248 let existsinrow pageno (columns
, coverA
, coverB
) p =
3249 let last = ((pageno - coverA
) mod columns
) + columns
in
3250 let rec any = function
3253 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
3257 then (if l.pageno = last then false else any rest
)
3265 match state
.layout with
3267 let pageno = page_of_y state
.y in
3268 gotoxy state
.x (getpagey
(pageno+1))
3270 match conf
.columns
with
3272 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
3274 let y = clamp (pgscale state
.winh
) in
3277 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
3278 gotoxy state
.x (getpagey
pageno)
3279 | Cmulti
((c, _, _) as cl
, _) ->
3280 if conf
.presentation
3281 && (existsinrow l.pageno cl
3282 (fun l -> l.pageh
> l.pagey + l.pagevh))
3284 let y = clamp (pgscale state
.winh
) in
3287 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
3288 gotoxy state
.x (getpagey
pageno)
3290 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
3292 let pagey, pageh
= getpageyh
l.pageno in
3293 let pagey = pagey + pageh
* l.pagecol
in
3294 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
3295 gotoxy state
.x (pagey + pageh
+ ips)
3299 match state
.layout with
3301 let pageno = page_of_y state
.y in
3302 gotoxy state
.x (getpagey
(pageno-1))
3304 match conf
.columns
with
3306 if conf
.presentation
&& l.pagey != 0
3308 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3310 let pageno = max
0 (l.pageno-1) in
3311 gotoxy state
.x (getpagey
pageno)
3312 | Cmulti
((c, _, coverB
) as cl
, _) ->
3313 if conf
.presentation
&&
3314 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
3316 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3319 if l.pageno = state
.pagecount
- coverB
3323 let pageno = max
0 (l.pageno-decr) in
3324 gotoxy state
.x (getpagey
pageno)
3332 let pageno = max
0 (l.pageno-1) in
3333 let pagey, pageh
= getpageyh
pageno in
3336 let pagey, pageh
= getpageyh
l.pageno in
3337 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
3343 if emptystr conf
.savecmd
3344 then adderrmsg "savepath-command is empty"
3345 "don't know where to save modified document"
3347 let savecmd = Str.global_replace
Utils.Re.percent state
.path conf
.savecmd in
3351 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
3356 let tmp = path ^
".tmp" in
3358 Unix.rename
tmp path;
3361 let viewkeyboard key mask
=
3363 let mode = state
.mode in
3364 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
3367 postRedisplay
"view:enttext"
3369 let ctrl = Wsi.withctrl mask
in
3371 match Wsi.kc2kt
key with
3372 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
3374 | Ascii 'Q'
-> exit
0
3377 if hasunsavedchanges
()
3381 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
3384 match state
.lnava
with
3385 | None
-> LinkNav
(Ltgendir
0)
3386 | Some
pn -> LinkNav
(Ltexact
pn)
3388 gotoxy state
.x state
.y;
3390 else impmsg "keyboard link navigation does not work under rotation"
3392 | Escape
| Ascii 'q'
->
3393 begin match state
.mstate
with
3396 postRedisplay
"kill rect";
3399 | Mscrolly
| Mscrollx
3402 begin match state
.mode with
3405 | Ltexact pl
-> state
.lnava
<- Some pl
3406 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
3409 postRedisplay
"esc leave linknav"
3410 | Birdseye
_ | Textentry
_ | View
->
3411 match state
.ranchors
with
3413 | (path, password, anchor, origin
) :: rest
->
3414 state
.ranchors
<- rest
;
3415 state
.anchor <- anchor;
3416 state
.origin
<- origin
;
3417 state
.nameddest
<- E.s;
3418 opendoc path password
3424 gotoxy state
.x (getnav ~
-1)
3435 Hashtbl.iter
(fun _ opaque ->
3437 Hashtbl.clear state
.prects
) state
.pagemap
;
3438 postRedisplay
"dehighlight";
3440 | Ascii
(('
/'
| '?'
) as c) ->
3441 let ondone isforw
s =
3442 cbput state
.hists
.pat
s;
3443 state
.searchpattern
<- s;
3446 let s = String.make
1 c in
3447 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
3448 textentry, ondone (c = '
/'
), true)
3450 | Ascii '
+'
| Ascii '
='
when ctrl ->
3451 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3452 pivotzoom (conf
.zoom +. incr)
3457 try int_of_string
s with exn
->
3459 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3465 state
.text <- "page bias is now " ^ string_of_int
n;
3468 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
3470 | Ascii '
-'
when ctrl ->
3471 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3472 pivotzoom (max
0.01 (conf
.zoom -. decr))
3475 let ondone msg
= state
.text <- msg
in
3476 enttext ("option: ", E.s, None
,
3477 optentry state
.mode, ondone, true)
3479 | Ascii '
0'
when ctrl ->
3481 then gotoxy 0 state
.y
3484 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
3486 match conf
.columns
with
3487 | Csingle
_ | Cmulti
_ -> 1
3488 | Csplit
(n, _) -> n
3490 let h = state
.winh
-
3491 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
3493 let zoom = zoomforh state
.winw
h 0 cols in
3494 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
3497 | Ascii '
3'
when ctrl ->
3499 match conf
.fitmodel
with
3500 | FitWidth
-> FitProportional
3501 | FitProportional
-> FitPage
3502 | FitPage
-> FitWidth
3504 state
.text <- "fit model: " ^
FMTE.to_string
fm;
3505 reqlayout conf
.angle
fm
3507 | Ascii '
4'
when ctrl ->
3508 let zoom = getmaxw
() /. float state
.winw
in
3509 if zoom > 0.0 then setzoom zoom
3511 | Fn
9 | Ascii '
9'
when ctrl -> togglebirdseye ()
3513 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
3516 try int_of_string
s with exn
->
3517 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3523 cbput state
.hists
.pag
(string_of_int
n);
3524 gotopage1 (n + conf
.pagebias
- 1) 0;
3527 let pageentry text = function [@warning
"-4"]
3528 | Keys.Ascii '
g'
-> TEdone
text
3529 | key -> intentry text key
3531 let text = String.make
1 c in
3532 enttext (":", text, Some
(onhist state
.hists
.pag
),
3533 pageentry, ondone, true)
3536 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
3537 postRedisplay
"toggle scrollbar";
3540 state
.bzoom
<- not state
.bzoom
;
3542 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
3545 conf
.hlinks
<- not conf
.hlinks
;
3546 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
3547 postRedisplay
"toggle highlightlinks";
3550 if conf
.angle
mod 360 = 0
3552 state
.glinks
<- true;
3553 let mode = state
.mode in
3556 (":", E.s, None
, linknentry, linknact gotounder, false),
3558 state
.glinks
<- false;
3562 postRedisplay
"view:linkent(F)"
3564 else impmsg "hint mode does not work under rotation"
3567 state
.glinks
<- true;
3568 let mode = state
.mode in
3571 (":", E.s, None
, linknentry,
3572 linknact (fun under ->
3573 selstring conf
.selcmd
(undertext under)), false),
3575 state
.glinks
<- false;
3579 postRedisplay
"view:linkent"
3582 begin match state
.autoscroll
with
3584 conf
.autoscrollstep
<- step
;
3585 state
.autoscroll
<- None
3587 state
.autoscroll
<- Some conf
.autoscrollstep
;
3588 state
.slideshow
<- state
.slideshow
land lnot
2
3591 | Ascii '
p'
when ctrl ->
3592 launchpath () (* XXX where do error messages go? *)
3595 setpresentationmode (not conf
.presentation
);
3596 showtext ' '
("presentation mode " ^
3597 if conf
.presentation
then "on" else "off");
3600 if List.mem
Wsi.Fullscreen state
.winstate
3601 then Wsi.reshape conf
.cwinw conf
.cwinh
3602 else Wsi.fullscreen
()
3604 | Ascii
('
p'
|'N'
) ->
3605 search state
.searchpattern
false
3607 | Ascii '
n'
| Fn
3 ->
3608 search state
.searchpattern
true
3611 begin match state
.layout with
3613 | l :: _ -> gotoxy state
.x (getpagey
l.pageno)
3616 | Ascii ' '
-> nextpage ()
3617 | Delete
-> prevpage ()
3618 | Ascii '
='
-> showtext ' '
(describe_layout state
.layout);
3621 begin match state
.layout with
3624 Wsi.reshape l.pagew
l.pageh
;
3628 | Ascii '
\''
-> enterbookmarkmode
()
3629 | Ascii '
h'
| Fn
1 -> enterhelpmode ()
3630 | Ascii 'i'
-> enterinfomode ()
3631 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 -> entermsgsmode ()
3635 match state
.layout with
3636 | l :: _ when nonemptystr
s ->
3637 state
.bookmarks
<- (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3640 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
3644 showtext ' '
"Quick bookmark added";
3646 | Ascii '
x'
-> state
.roam
()
3648 | Ascii
('
<'
|'
>'
as c) ->
3649 reqlayout (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
3651 | Ascii
('
['
|'
]'
as c) ->
3653 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
3654 postRedisplay
"brightness";
3656 | Ascii '
c'
when state
.mode = View
->
3661 let m = (state
.winw
- state
.w) / 2 in
3666 match state
.prevcolumns
with
3667 | None
-> (1, 0, 0), 1.0
3668 | Some
(columns
, z
) ->
3671 | Csplit
(c, _) -> -c, 0, 0
3672 | Cmulti
((c, a, b), _) -> c, a, b
3673 | Csingle
_ -> 1, 0, 0
3677 setcolumns View
c a b;
3680 | Down
| Up
when ctrl && Wsi.withshift mask
->
3681 let zoom, x = state
.prevzoom
in
3686 begin match state
.autoscroll
with
3688 begin match state
.mode with
3689 | Birdseye beye
-> upbirdseye 1 beye
3690 | Textentry
_ | View
| LinkNav
_ ->
3692 then gotoxy state
.x (clamp ~
-(state
.winh
/2))
3694 if not
(Wsi.withshift mask
) && conf
.presentation
3696 else gotoxy state
.x (clamp (-conf
.scrollstep
))
3699 | Some
n -> setautoscrollspeed n false
3702 | Ascii 'j'
| Down
->
3703 begin match state
.autoscroll
with
3705 begin match state
.mode with
3706 | Birdseye beye
-> downbirdseye 1 beye
3707 | Textentry
_ | View
| LinkNav
_ ->
3709 then gotoxy state
.x (clamp (state
.winh
/2))
3711 if not
(Wsi.withshift mask
) && conf
.presentation
3713 else gotoxy state
.x (clamp (conf
.scrollstep
))
3716 | Some
n -> setautoscrollspeed n true
3719 | Left
| Right
when not
(Wsi.withalt mask
) ->
3725 else conf
.hscrollstep
3728 let pv = Wsi.kc2kt
key in
3729 if pv = Keys.Left
then dx else -dx
3731 gotoxy (panbound (state
.x + dx)) state
.y
3734 postRedisplay
"left/right"
3741 match state
.layout with
3743 | l :: _ -> state
.y - l.pagey
3744 else clamp (pgscale (-state
.winh
))
3752 match List.rev state
.layout with
3754 | l :: _ -> getpagey
l.pageno
3755 else clamp (pgscale state
.winh
)
3759 | Ascii '
g'
| Home
->
3762 | Ascii 'G'
| End
->
3764 gotoxy 0 (clamp state
.maxy)
3766 | Right
when Wsi.withalt mask
->
3768 gotoxy state
.x (getnav 1)
3769 | Left
when Wsi.withalt mask
->
3771 gotoxy state
.x (getnav ~
-1)
3776 | Ascii '
v'
when conf
.debug
->
3779 match getopaque l.pageno with
3782 let x0, y0, x1, y1 = pagebbox
opaque in
3783 let rect = (float x0, float y0,
3786 float x0, float y1) in
3788 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
3789 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
3794 let mode = state
.mode in
3795 let cmd = ref E.s in
3796 let onleave = function
3797 | Cancel
-> state
.mode <- mode
3800 match getopaque l.pageno with
3801 | Some
opaque -> pipesel opaque !cmd
3802 | None
-> ()) state
.layout;
3806 cbput state
.hists
.sel
s;
3810 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
3813 state
.mode <- Textentry
(te, onleave);
3815 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
3816 vlog "huh? %s" (Wsi.keyname
key)
3819 let linknavkeyboard key mask
linknav =
3820 let pv = Wsi.kc2kt
key in
3821 let getpage pageno =
3822 let rec loop = function
3824 | l :: _ when l.pageno = pageno -> Some
l
3825 | _ :: rest
-> loop rest
3826 in loop state
.layout
3828 let doexact (pageno, n) =
3829 match getopaque pageno, getpage pageno with
3830 | Some
opaque, Some
l ->
3833 let under = getlink
opaque n in
3834 postRedisplay
"link gotounder";
3841 | Home
-> Some
(findlink
opaque LDfirst
), -1
3842 | End
-> Some
(findlink
opaque LDlast
), 1
3843 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
3844 | Right
-> Some
(findlink
opaque (LDright
n)), 1
3845 | Up
-> Some
(findlink
opaque (LDup
n)), -1
3846 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
3847 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
3848 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
3851 begin match findpwl
l.pageno dir with
3855 state
.mode <- LinkNav
(Ltgendir
dir);
3856 let y, h = getpageyh
pageno in
3859 then y + h - state
.winh
3864 begin match getopaque pageno, getpage pageno with
3865 | Some
opaque, Some
_ ->
3867 let ld = if dir > 0 then LDfirst
else LDlast
in
3870 begin match link with
3872 showlinktype (getlink
opaque m);
3873 state
.mode <- LinkNav
(Ltexact
(pageno, m));
3874 postRedisplay
"linknav jpage";
3875 | Lnotfound
-> notfound dir
3881 begin match opt with
3882 | Some Lnotfound
-> pwl l dir;
3883 | Some
(Lfound
m) ->
3887 let _, y0, _, y1 = getlinkrect
opaque m in
3889 then gotopage1 l.pageno y0
3891 let d = fstate
.fontsize
+ 1 in
3892 if y1 - l.pagey > l.pagevh - d
3893 then gotopage1 l.pageno (y1 - state
.winh
+ d)
3894 else postRedisplay
"linknav";
3896 showlinktype (getlink
opaque m);
3897 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
3900 | None
-> viewkeyboard key mask
3902 | _ -> viewkeyboard key mask
3906 begin match linknav with
3907 | Ltexact pa
-> state
.lnava
<- Some pa
3908 | Ltgendir
_ | Ltnotready
_ -> ()
3911 postRedisplay
"leave linknav"
3915 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
3916 | Ltexact exact
-> doexact exact
3919 let keyboard key mask
=
3920 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
3921 then wcmd "interrupt"
3922 else state
.uioh <- state
.uioh#
key key mask
3925 let birdseyekeyboard key mask
3926 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
3928 match conf
.columns
with
3930 | Cmulti
((c, _, _), _) -> c
3931 | Csplit
_ -> error
"bird's eye split mode"
3933 let pgh layout = List.fold_left
3934 (fun m l -> max
l.pageh
m) state
.winh
layout in
3936 match Wsi.kc2kt
key with
3937 | Ascii '
l'
when Wsi.withctrl mask
->
3938 let y, h = getpageyh
pageno in
3939 let top = (state
.winh
- h) / 2 in
3940 gotoxy state
.x (max
0 (y - top))
3941 | Enter
-> leavebirdseye beye
false
3942 | Escape
-> leavebirdseye beye
true
3943 | Up
-> upbirdseye incr beye
3944 | Down
-> downbirdseye incr beye
3945 | Left
-> upbirdseye 1 beye
3946 | Right
-> downbirdseye 1 beye
3949 begin match state
.layout with
3953 state
.mode <- Birdseye
(
3954 oconf
, leftx
, l.pageno, hooverpageno
, anchor
3956 gotopage1 l.pageno 0;
3959 let layout = layout state
.x (state
.y-state
.winh
)
3961 (pgh state
.layout) in
3963 | [] -> gotoxy state
.x (clamp (-state
.winh
))
3965 state
.mode <- Birdseye
(
3966 oconf
, leftx
, l.pageno, hooverpageno
, anchor
3968 gotopage1 l.pageno 0
3971 | [] -> gotoxy state
.x (clamp (-state
.winh
))
3975 begin match List.rev state
.layout with
3977 let layout = layout state
.x
3978 (state
.y + (pgh state
.layout))
3979 state
.winw state
.winh
in
3980 begin match layout with
3982 let incr = l.pageh
- l.pagevh in
3987 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
3989 postRedisplay
"birdseye pagedown";
3991 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
3995 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
3996 gotopage1 l.pageno 0;
3999 | [] -> gotoxy state
.x (clamp state
.winh
)
4003 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4007 let pageno = state
.pagecount
- 1 in
4008 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4009 if not
(pagevisible state
.layout pageno)
4012 match List.rev state
.pdims
with
4014 | (_, _, h, _) :: _ -> h
4018 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
4019 else postRedisplay
"birdseye end";
4021 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
4026 match state
.mode with
4027 | Textentry
_ -> scalecolor 0.4
4028 | LinkNav
_ | View
-> scalecolor 1.0
4029 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4030 if l.pageno = hooverpageno
4033 if l.pageno = pageno
4035 let c = scalecolor 1.0 in
4037 GlDraw.line_width
3.0;
4038 let dispx = l.pagedispx in
4040 (float (dispx-1)) (float (l.pagedispy-1))
4041 (float (dispx+l.pagevw+1))
4042 (float (l.pagedispy+l.pagevh+1));
4043 GlDraw.line_width
1.0;
4052 let postdrawpage l linkindexbase
=
4053 match getopaque l.pageno with
4055 if tileready l l.pagex
l.pagey
4057 let x = l.pagedispx - l.pagex
4058 and y = l.pagedispy - l.pagey in
4060 match conf
.columns
with
4061 | Csingle
_ | Cmulti
_ ->
4062 (if conf
.hlinks
then 1 else 0)
4064 && not
(isbirdseye state
.mode) then 2 else 0)
4068 match state
.mode with
4069 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
4075 Hashtbl.find_all state
.prects
l.pageno |>
4076 List.iter
(fun vals
-> drawprect
opaque x y vals
);
4077 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
4079 then (Glutils.redisplay
:= true; 0)
4085 let scrollindicator () =
4086 let sbw, ph
, sh
= state
.uioh#scrollph
in
4087 let sbh, pw, sw
= state
.uioh#scrollpw
in
4092 else ((state
.winw
- sbw), state
.winw
, 0)
4096 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4097 let (r
, g, b, alpha
) = conf
.sbarcolor
in
4098 GlDraw.color (r
, g, b) ~alpha
;
4099 filledrect
(float x0) 0. (float x1) (float state
.winh
);
4101 (float hx0
) (float (state
.winh
- sbh))
4102 (float (hx0
+ state
.winw
)) (float state
.winh
);
4103 let (r
, g, b, alpha
) = conf
.sbarhndlcolor
in
4104 GlDraw.color (r
, g, b) ~alpha
;
4106 filledrect
(float x0) ph
(float x1) (ph
+. sh
);
4107 let pw = pw +. float hx0
in
4108 filledrect
pw (float (state
.winh
- sbh)) (pw +. sw
) (float state
.winh
);
4113 match state
.mstate
with
4114 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ -> ()
4115 | Msel
((x0, y0), (x1, y1)) ->
4116 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
4117 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
4118 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
4119 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
4122 let showrects = function
4126 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4127 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4129 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4131 if l.pageno = pageno
4133 let dx = float (l.pagedispx - l.pagex
) in
4134 let dy = float (l.pagedispy - l.pagey) in
4135 let r, g, b, alpha
= c in
4136 GlDraw.color (r, g, b) ~alpha
;
4149 GlDraw.color (scalecolor2 conf
.bgcolor
);
4150 GlClear.color (scalecolor2 conf
.bgcolor
);
4151 GlClear.clear
[`
color];
4152 List.iter
drawpage state
.layout;
4154 match state
.mode with
4155 | LinkNav
(Ltexact
(pageno, linkno
)) ->
4156 begin match getopaque pageno with
4158 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
4159 let color = (0.0, 0.0, 0.5, 0.5) in
4161 (float x0, float y0,
4166 | None
-> state
.rects
4168 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
4171 | View
-> state
.rects
4174 let rec postloop linkindexbase
= function
4176 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
4177 postloop linkindexbase rest
4181 postloop 0 state
.layout;
4183 begin match state
.mstate
with
4184 | Mzoomrect
((x0, y0), (x1, y1)) ->
4186 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4187 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4188 filledrect
(float x0) (float y0) (float x1) (float y1);
4192 | Mscrolly
| Mscrollx
4201 let zoomrect x y x1 y1 =
4204 and y0 = min
y y1 in
4205 let zoom = (float state
.w) /. float (x1 - x0) in
4208 if state
.w < state
.winw
4209 then (state
.winw
- state
.w) / 2
4212 match conf
.fitmodel
with
4213 | FitWidth
| FitProportional
-> simple ()
4215 match conf
.columns
with
4217 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
4218 | Cmulti
_ | Csingle
_ -> simple ()
4220 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
4221 state
.anchor <- getanchor
();
4226 let annot inline
x y =
4227 match unproject x y with
4228 | Some
(opaque, n, ux
, uy
) ->
4230 addannot
opaque ux uy
text;
4231 wcmd "freepage %s" (~
> opaque);
4232 Hashtbl.remove state
.pagemap
(n, state
.gen
);
4234 gotoxy state
.x state
.y
4238 let ondone s = add s in
4239 let mode = state
.mode in
4240 state
.mode <- Textentry
(
4241 ("annotation: ", E.s, None
, textentry, ondone, true),
4242 fun _ -> state
.mode <- mode);
4245 postRedisplay
"annot"
4246 else add @@ getusertext E.s
4251 let g opaque l px py =
4252 match rectofblock
opaque px py with
4254 let x0 = a.(0) -. 20. in
4255 let x1 = a.(1) +. 20. in
4256 let y0 = a.(2) -. 20. in
4257 let zoom = (float state
.w) /. (x1 -. x0) in
4258 let pagey = getpagey
l.pageno in
4259 let margin = (state
.w - l.pagew
)/2 in
4260 let nx = -truncate
x0 - margin in
4261 gotoxy nx (pagey + truncate
y0);
4262 state
.anchor <- getanchor
();
4267 match conf
.columns
with
4269 impmsg "block zooming does not work properly in split columns mode"
4270 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
4274 let winw = state
.winw - 1 in
4275 let s = float x /. float winw in
4276 let destx = truncate
(float (state
.w + winw) *. s) in
4277 gotoxy (winw - destx) state
.y;
4278 state
.mstate
<- Mscrollx
;
4282 let s = float y /. float state
.winh
in
4283 let desty = truncate
(s *. float (maxy ())) in
4284 gotoxy state
.x desty;
4285 state
.mstate
<- Mscrolly
;
4288 let viewmulticlick clicks
x y mask
=
4289 let g opaque l px py =
4297 if markunder
opaque px py mark
4301 match getopaque l.pageno with
4303 | Some
opaque -> pipesel opaque cmd
4305 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
4306 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
4311 postRedisplay
"viewmulticlick";
4312 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
4316 match conf
.columns
with
4318 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
4321 let viewmouse button down
x y mask
=
4323 | n when (n == 4 || n == 5) && not down
->
4324 if Wsi.withctrl mask
4328 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4329 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4332 match state
.mstate
with
4333 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
4334 | Mzoomrect
_ | Mnone
| Mpan
_
4335 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
4337 let zoom = conf
.zoom -. incr in
4338 state
.mstate
<- Mzoom
(n, 0, (x, y));
4339 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
4340 then pivotzoom ~
x ~
y zoom
4344 match state
.autoscroll
with
4345 | Some step
-> setautoscrollspeed step
(n=4)
4347 if conf
.wheelbypage
|| conf
.presentation
4354 let incr = if n = 4 then -conf
.scrollstep
else conf
.scrollstep
in
4355 let incr = incr * 2 in
4356 let y = clamp incr in
4360 | n when (n = 6 || n = 7) && not down
&& canpan () ->
4362 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
4365 | 1 when Wsi.withshift mask
->
4366 state
.mstate
<- Mnone
;
4369 match unproject x y with
4371 | Some
(_, pageno, ux
, uy
) ->
4372 let cmd = Printf.sprintf
4374 conf
.stcmd state
.path pageno ux uy
4376 match spawn
cmd [] with
4378 impmsg "execution of synctex command(%S) failed: %S"
4379 conf
.stcmd
@@ exntos exn
4383 | 1 when Wsi.withctrl mask
->
4386 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4387 state
.mstate
<- Mpan
(x, y)
4389 else state
.mstate
<- Mnone
4394 if Wsi.withshift mask
4396 annot conf
.annotinline
x y;
4397 postRedisplay
"addannot"
4401 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4402 state
.mstate
<- Mzoomrect
(p, p)
4405 match state
.mstate
with
4406 | Mzoomrect
((x0, y0), _) ->
4407 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4408 then zoomrect x0 y0 x y
4411 postRedisplay
"kill accidental zoom rect";
4415 | Mscrolly
| Mscrollx
4417 | Mnone
-> resetmstate ()
4420 | 1 when vscrollhit
x ->
4423 let _, position
, sh
= state
.uioh#scrollph
in
4424 if y > truncate position
&& y < truncate
(position
+. sh
)
4425 then state
.mstate
<- Mscrolly
4427 else state
.mstate
<- Mnone
4429 | 1 when y > state
.winh
- hscrollh () ->
4432 let _, position
, sw
= state
.uioh#scrollpw
in
4433 if x > truncate position
&& x < truncate
(position
+. sw
)
4434 then state
.mstate
<- Mscrollx
4436 else state
.mstate
<- Mnone
4438 | 1 when state
.bzoom
-> if not down
then zoomblock x y
4441 let dest = if down
then getunder x y else Unone
in
4442 begin match dest with
4443 | Ulinkuri
_ -> gotounder dest
4444 | Unone
when down
->
4445 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4446 state
.mstate
<- Mpan
(x, y);
4447 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4448 | Unone
| Utext
_ ->
4453 state
.mstate
<- Msel
((x, y), (x, y));
4454 postRedisplay
"mouse select";
4458 match state
.mstate
with
4460 | Mzoom
_ | Mscrollx
| Mscrolly
-> state
.mstate
<- Mnone
4461 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4463 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4464 state
.mstate
<- Mnone
4465 | Msel
((x0, y0), (x1, y1)) ->
4466 let rec loop = function
4470 let a0 = l.pagedispy in
4471 let a1 = a0 + l.pagevh in
4472 let b0 = l.pagedispx in
4473 let b1 = b0 + l.pagevw in
4474 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
4475 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
4479 match getopaque l.pageno with
4482 pipef ~closew
:false "Msel"
4485 postRedisplay
"Msel") cmd
4487 dosel conf
.selcmd
();
4488 state
.roam
<- dosel conf
.paxcmd
;
4499 let birdseyemouse button down
x y mask
4500 (conf
, leftx
, _, hooverpageno
, anchor) =
4503 let rec loop = function
4506 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4507 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4509 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
4515 | _ -> viewmouse button down
x y mask
4521 method key key mask
=
4522 begin match state
.mode with
4523 | Textentry
textentry -> textentrykeyboard
key mask
textentry
4524 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
4525 | View
-> viewkeyboard key mask
4526 | LinkNav
linknav -> linknavkeyboard key mask
linknav
4530 method button button bstate
x y mask
=
4531 begin match state
.mode with
4532 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
4533 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
4538 method multiclick clicks
x y mask
=
4539 begin match state
.mode with
4540 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
4541 | Birdseye
_ | Textentry
_ -> ()
4546 begin match state
.mode with
4548 | View
| Birdseye
_ | LinkNav
_ ->
4549 match state
.mstate
with
4550 | Mzoom
_ | Mnone
-> ()
4554 state
.mstate
<- Mpan
(x, y);
4555 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4560 state
.mstate
<- Msel
(a, (x, y));
4561 postRedisplay
"motion select";
4564 let y = min state
.winh
(max
0 y) in
4568 let x = min state
.winw (max
0 x) in
4571 | Mzoomrect
(p0
, _) ->
4572 state
.mstate
<- Mzoomrect
(p0
, (x, y));
4573 postRedisplay
"motion zoomrect";
4577 method pmotion
x y =
4578 begin match state
.mode with
4579 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
4580 let rec loop = function
4582 if hooverpageno
!= -1
4584 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
4585 postRedisplay
"pmotion birdseye no hoover";
4588 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4589 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4591 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
4592 postRedisplay
"pmotion birdseye hoover";
4600 | LinkNav
_ | View
->
4601 match state
.mstate
with
4602 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
4611 let delta = now -. past
in
4614 else conf
.pax
<- Some
now
4618 method infochanged
_ = ()
4621 let maxy = maxy () in
4624 then 0.0, float state
.winh
4625 else scrollph state
.y maxy
4630 let fwinw = float (state
.winw - vscrollw
()) in
4632 let sw = fwinw /. float state
.w in
4633 let sw = fwinw *. sw in
4634 max
sw (float conf
.scrollh
)
4637 let maxx = state
.w + state
.winw in
4638 let x = state
.winw - state
.x in
4639 let percent = float x /. float maxx in
4640 (fwinw -. sw) *. percent
4642 hscrollh (), position, sw
4646 match state
.mode with
4647 | LinkNav
_ -> "links"
4648 | Textentry
_ -> "textentry"
4649 | Birdseye
_ -> "birdseye"
4652 findkeyhash conf
modename
4654 method eformsgs
= true
4655 method alwaysscrolly
= false
4656 method scroll
dx dy =
4657 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4658 gotoxy x (clamp (2 * dy));
4661 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
4664 let addrect pageno r g b a x0 y0 x1 y1 =
4665 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
4669 let cl = splitatchar cmds ' '
in
4671 try Scanf.sscanf
s fmt
f
4672 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
4675 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
4676 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
4677 s pageno r g b a x0 y0 x1 y1;
4681 let _,w1
,h1
,_ = getpagedim
pageno in
4682 let sw = float w1
/. float w
4683 and sh
= float h1
/. float h in
4687 and y1s
= y1 *. sh
in
4688 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
4689 let color = (r, g, b, a) in
4690 if conf
.verbose
then debugrect rect;
4691 state
.rects <- (pageno, color, rect) :: state
.rects;
4696 | "reload", "" -> reload ()
4698 scan args
"%u %f %f"
4700 let cmd, _ = state
.geomcmds
in
4702 then gotopagexy pageno x y
4705 gotopagexy pageno x y;
4708 state
.reprf
<- f state
.reprf
4710 | "goto1", args
-> scan args
"%u %f" gotopage
4711 | "gotor", args
-> scan args
"%S" gotoremote
4713 scan args
"%u %u %f %f %f %f"
4714 (fun pageno c x0 y0 x1 y1 ->
4715 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
4716 rectx "rect" pageno color x0 y0 x1 y1;
4719 scan args
"%u %f %f %f %f %f %f %f %f"
4720 (fun pageno r g b alpha
x0 y0 x1 y1 ->
4721 addrect pageno r g b alpha
x0 y0 x1 y1;
4722 postRedisplay
"prect"
4725 scan args
"%u %f %f"
4728 match getopaque pageno with
4729 | Some
opaque -> opaque
4732 pgoto optopaque pageno x y;
4733 let rec fixx = function
4736 if l.pageno = pageno
4737 then gotoxy (state
.x - l.pagedispx) state
.y
4742 match conf
.columns
with
4743 | Csingle
_ | Csplit
_ -> 1
4744 | Cmulti
((n, _, _), _) -> n
4746 layout 0 state
.y (state
.winw * mult) state
.winh
4750 | "activatewin", "" -> Wsi.activatewin
()
4751 | "quit", "" -> raise Quit
4754 let l = Config.keys_of_string
keys in
4755 List.iter
(fun (k
, m) -> keyboard k
m) l
4756 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
4759 | "clearrects", "" ->
4760 Hashtbl.clear state
.prects
;
4761 postRedisplay
"clearrects"
4763 adderrfmt "remote command"
4764 "error processing remote command: %S\n" cmds
;
4768 let scratch = Bytes.create
80 in
4769 let buf = Buffer.create
80 in
4771 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
4772 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
4775 if Buffer.length
buf > 0
4777 let s = Buffer.contents
buf in
4785 match Bytes.index_from
scratch ppos '
\n'
with
4786 | pos
-> if pos
>= n then -1 else pos
4787 | exception Not_found
-> -1
4791 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
4792 let s = Buffer.contents
buf in
4798 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
4804 let remoteopen path =
4805 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
4807 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
4812 let gcconfig = ref false in
4813 let trimcachepath = ref E.s in
4814 let rcmdpath = ref E.s in
4815 let pageno = ref None
in
4816 let openlast = ref false in
4817 let doreap = ref false in
4818 let csspath = ref None
in
4819 selfexec := Sys.executable_name
;
4822 [("-p", Arg.String
(fun s -> state
.password <- s),
4823 "<password> Set password");
4827 Config.fontpath
:= s;
4828 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
4830 "<path> Set path to the user interface font");
4834 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
4835 Config.confpath
:= s),
4836 "<path> Set path to the configuration file");
4838 ("-last", Arg.Set
openlast, " Open last document");
4840 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
4841 "<page-number> Jump to page");
4843 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
4844 "<path> Set path to the trim cache file");
4846 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
4847 "<named-destination> Set named destination");
4849 ("-remote", Arg.String
(fun s -> rcmdpath := s),
4850 "<path> Set path to the source of remote commands");
4852 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
4854 ("-v", Arg.Unit
(fun () ->
4856 "%s\nconfiguration file: %s\n"
4859 exit
0), " Print version and exit");
4861 ("-css", Arg.String
(fun s -> csspath := Some
s),
4862 "<path> Set path to the style sheet to use with EPUB/HTML");
4864 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
4865 "<origin> <undocumented>");
4867 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title");
4868 ("-layout-height", Arg.Set_int
layouth,
4869 "<height> layout height html/epub/etc (-1, 0, N)");
4872 (fun s -> state
.path <- s)
4873 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
4875 let histmode = emptystr state
.path && not
!openlast in
4877 if not
(Config.load !openlast)
4878 then dolog
"failed to load configuration";
4880 begin match !pageno with
4881 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
4894 val mutable m_clicks
= 0
4895 val mutable m_click_x
= 0
4896 val mutable m_click_y
= 0
4897 val mutable m_lastclicktime
= infinity
4899 method private cleanup =
4900 state
.roam
<- noroam
;
4901 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
4902 method expose
= postRedisplay
"expose"
4906 | Wsi.Unobscured
-> "unobscured"
4907 | Wsi.PartiallyObscured
-> "partiallyobscured"
4908 | Wsi.FullyObscured
-> "fullyobscured"
4910 vlog "visibility change %s" name
4911 method display = display ()
4912 method map mapped
= vlog "mapped %b" mapped
4913 method reshape w h =
4916 method mouse
b d x y m =
4917 if d && canselect ()
4920 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
4927 if abs
x - m_click_x
> 10
4928 || abs
y - m_click_y
> 10
4929 || abs_float
(t -. m_lastclicktime
) > 0.3
4931 m_clicks
<- m_clicks
+ 1;
4932 m_lastclicktime
<- t;
4936 postRedisplay
"cleanup";
4937 state
.uioh <- state
.uioh#button
b d x y m;
4939 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
4944 m_lastclicktime
<- infinity
;
4945 state
.uioh <- state
.uioh#button
b d x y m
4948 else state
.uioh <- state
.uioh#button
b d x y m
4950 state
.mpos
<- (x, y);
4951 state
.uioh <- state
.uioh#motion
x y
4952 method pmotion
x y =
4953 state
.mpos
<- (x, y);
4954 state
.uioh <- state
.uioh#pmotion
x y
4956 vlog "k=%#x m=%#x" k
m;
4957 let mascm = m land (
4958 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
4961 let x = state
.x and y = state
.y in
4963 if x != state
.x || y != state
.y then self#
cleanup
4965 match state
.keystate
with
4967 let km = k
, mascm in
4970 let modehash = state
.uioh#
modehash in
4971 try Hashtbl.find
modehash km
4973 try Hashtbl.find
(findkeyhash conf
"global") km
4974 with Not_found
-> KMinsrt
(k
, m)
4976 | KMinsrt
(k
, m) -> keyboard k
m
4977 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
4978 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
4980 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
4981 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
4982 state
.keystate
<- KSnone
4983 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
4984 state
.keystate
<- KSinto
(keys, insrt
)
4985 | KSinto
_ -> state
.keystate
<- KSnone
4988 state
.mpos
<- (x, y);
4989 state
.uioh <- state
.uioh#pmotion
x y
4990 method leave = state
.mpos
<- (-1, -1)
4991 method winstate wsl
= state
.winstate
<- wsl
4992 method quit
: '
a. '
a = raise Quit
4993 method scroll
dx dy = state
.uioh <- state
.uioh#scroll
dx dy
4994 method zoom z
x y = state
.uioh#
zoom z
x y
4995 method opendoc path =
4998 postRedisplay
"opendoc";
4999 opendoc path state
.password
5002 let wsfd, winw, winh
= Wsi.init
mu conf
.cwinw conf
.cwinh platform
in
5005 if not
@@ List.exists
GlMisc.check_extension
5006 [ "GL_ARB_texture_rectangle"
5007 ; "GL_EXT_texture_recangle"
5008 ; "GL_NV_texture_rectangle" ]
5009 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
5011 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
5013 defconf
.sliceheight
<- 1024;
5014 defconf
.texcount
<- 32;
5015 defconf
.usepbo
<- true;
5019 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
5021 dolog
"socketpair failed: %s" @@ exntos exn
;
5029 setcheckers conf
.checkers
;
5030 begin match !csspath with
5032 | Some
"" -> conf
.css
<- E.s
5034 let css = filecontents
path in
5035 let l = String.length
css in
5037 if substratis
css (l-2) "\r\n"
5038 then String.sub css 0 (l-2)
5039 else (if css.[l-1] = '
\n'
then String.sub css 0 (l-1) else css)
5042 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
5043 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
5044 !Config.fontpath
, !trimcachepath
5046 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
5048 reshape ~firsttime
:true winw winh
;
5052 Wsi.settitle
"llpp (history)";
5056 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
5057 opendoc state
.path state
.password;
5061 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5062 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
5065 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
5066 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
5067 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
5069 | _pid
, _status
-> reap ()
5071 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
5074 ref (if nonemptystr
!rcmdpath then remoteopen !rcmdpath else None
)
5077 let rec loop deadline
=
5083 let r = [state
.ss; state
.wsfd] in
5087 | Some fd
-> fd
:: r
5091 Glutils.redisplay
:= false;
5098 if deadline
= infinity
5100 else max
0.0 (deadline
-. now)
5105 try Unix.select
r [] [] timeout
5106 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5111 match state
.autoscroll
with
5112 | Some step
when step
!= 0 ->
5113 if state
.slideshow
land 1 = 1
5115 if state
.slideshow
land 2 = 0
5116 then state
.slideshow
<- state
.slideshow
lor 2
5117 else if step
< 0 then prevpage () else nextpage ();
5118 deadline
+. (float (abs step
))
5121 let y = state
.y + step
in
5122 let fy = if conf
.maxhfit
then state
.winh
else 0 in
5125 then state
.maxy - fy
5126 else if y >= state
.maxy - fy then 0 else y
5135 let rec checkfds = function
5137 | fd
:: rest
when fd
= state
.ss ->
5138 let cmd = rcmd state
.ss in
5142 | fd
:: rest
when fd
= state
.wsfd ->
5146 | fd
:: rest
when Some fd
= !optrfd ->
5147 begin match remote fd
with
5148 | None
-> optrfd := remoteopen !rcmdpath;
5149 | opt -> optrfd := opt
5154 dolog
"select returned unknown descriptor";
5160 if deadline
= infinity
5164 match state
.autoscroll
with
5165 | Some step
when step
!= 0 -> deadline1
5171 match loop infinity
with
5173 Config.save leavebirdseye;
5174 if hasunsavedchanges
()
5176 | _ -> error
"umpossible - infinity reached"