6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
10 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
11 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
12 external clearmark
: opaque
-> unit = "ml_clearmark";;
13 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
14 external getmaxw
: unit -> float = "ml_getmaxw";;
15 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
16 external measurestr
: int -> string -> float = "ml_measure_string";;
17 external postprocess
: opaque
-> int -> int -> int -> (int * string * int)
18 -> int = "ml_postprocess";;
19 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
20 external setaalevel
: int -> unit = "ml_setaalevel";;
21 external realloctexts
: int -> bool = "ml_realloctexts";;
22 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
23 external getlink
: opaque
-> int -> under
= "ml_getlink";;
24 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
25 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
26 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
27 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
28 external freepbo
: opaque
-> unit = "ml_freepbo";;
29 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
30 external bousable
: unit -> bool = "ml_bo_usable";;
31 external unproject
: opaque
-> int -> int
32 -> (int * int) option = "ml_unproject";;
33 external project
: opaque
-> int -> int -> float -> float
34 -> (float * float) = "ml_project";;
35 external drawtile
: tileparams
-> opaque
36 -> unit = "ml_drawtile";;
37 external rectofblock
: opaque
-> int -> int
38 -> float array
option = "ml_rectofblock";;
39 external begintiles
: unit -> unit = "ml_begintiles";;
40 external endtiles
: unit -> unit = "ml_endtiles";;
41 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
42 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
43 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
44 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
45 external savedoc
: string -> unit = "ml_savedoc";;
46 external getannotcontents
: opaque
-> slinkindex
47 -> string = "ml_getannotcontents";;
48 external drawprect
: opaque
-> int -> int -> float array
49 -> unit = "ml_drawprect";;
50 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
51 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
52 external uritolocation
: string
53 -> (pageno
* float * float) = "ml_uritolocation";;
54 external isexternallink
: string -> bool = "ml_isexternallink";;
56 (* copysel _will_ close the supplied descriptor *)
57 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
59 let selfexec = ref E.s
;;
60 let ignoredoctitlte = ref false;;
61 let opengl_has_pbo = ref false;;
63 let drawstring size x y s
=
65 Gl.enable `texture_2d
;
66 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
67 ignore
(drawstr size x y s
);
69 Gl.disable `texture_2d
;
72 let drawstring1 size x y s
=
76 let drawstring2 size x y fmt
=
77 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
80 module UniSyms
= struct
81 let ellipsis = "\xe2\x80\xa6";;
82 let radical = "\xe2\x88\x9a";;
83 let lguillemet = "\xc2\xab";;
84 let rguillemet = "\xc2\xbb";;
99 l
.pagedispx l
.pagedispy
103 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
109 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
112 let isbirdseye = function
114 | Textentry _
| View
| LinkNav _
-> false
117 let istextentry = function
118 | Textentry _
-> true
119 | Birdseye _
| View
| LinkNav _
-> false
122 let cxack = ref false;;
124 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
127 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
128 && (state
.w
> state
.winw
))
134 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
135 && (state
.maxy
> state
.winh
))
143 else x
> state
.winw
- vscrollw ()
147 fstate
.fontsize
<- n
;
148 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
149 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
155 else Printf.kprintf ignore fmt
159 if emptystr conf
.pathlauncher
160 then dolog
"%s" state
.path
162 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
163 match spawn
command [] with
166 dolog
"failed to execute `%s': %s" command @@ exntos exn
172 let postRedisplay who
=
173 vlog "redisplay for [%S]" who
;
174 state
.redisplay
<- true;
178 let getopaque pageno
=
179 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
180 with Not_found
-> None
183 let pagetranslatepoint l x y
=
184 let dy = y
- l
.pagedispy
in
185 let y = dy + l
.pagey
in
186 let dx = x
- l
.pagedispx
in
187 let x = dx + l
.pagex
in
191 let onppundermouse g
x y d
=
194 begin match getopaque l
.pageno
with
196 let x0 = l
.pagedispx
in
197 let x1 = x0 + l
.pagevw
in
198 let y0 = l
.pagedispy
in
199 let y1 = y0 + l
.pagevh
in
200 if y >= y0 && y <= y1 && x >= x0 && x <= x1
202 let px, py
= pagetranslatepoint l
x y in
203 match g opaque l
px py
with
216 let g opaque l
px py
=
219 match rectofblock opaque
px py
with
220 | Some
[|x0;x1;y0;y1|] ->
221 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
222 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
223 state
.rects
<- [l
.pageno
, color, rect];
224 G.postRedisplay "getunder";
227 let under = whatsunder opaque
px py
in
228 if under = Unone
then None
else Some
under
230 onppundermouse g x y Unone
235 match unproject opaque
x y with
236 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
239 onppundermouse g x y None
;
243 state
.text
<- Printf.sprintf
"%c%s" c s
;
244 G.postRedisplay "showtext";
248 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
251 let pipef ?
(closew
=true) cap
f cmd
=
252 match Unix.pipe
() with
253 | exception exn
-> dolog
"%s cannot create pipe: %S" cap
@@ exntos exn
255 begin match spawn cmd
[r
, 0; w
, -1] with
256 | exception exn
-> dolog
"%s: cannot execute %S: %s" cap cmd
@@ exntos exn
259 Ne.clo r
(dolog
"%s failed to close r: %s" cap
);
260 if closew
then Ne.clo w
(dolog
"%s failed to close w: %s" cap
);
263 let pipesel opaque cmd
=
265 then pipef ~closew
:false "pipesel"
268 G.postRedisplay "pipesel"
273 let g opaque l
px py
=
274 if markunder opaque
px py conf
.paxmark
277 match getopaque l
.pageno
with
279 | Some opaque
-> pipesel opaque conf
.paxcmd
284 G.postRedisplay "paxunder";
285 if conf
.paxmark
= Mark_page
288 match getopaque l
.pageno
with
290 | Some opaque
-> clearmark opaque
) state
.layout
;
291 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
296 "selstring" (fun w
->
298 let l = String.length s
in
299 let bytes = Bytes.unsafe_of_string s
in
300 let n = tempfailureretry
(Unix.write w
bytes 0) l in
302 then impmsg "failed to write %d characters to sel pipe, wrote %d" l n;
303 with exn
-> impmsg "failed to write to sel pipe: %s" @@ exntos exn
307 let undertext = function
310 | Utext s
-> "font: " ^ s
311 | Uannotation
(opaque
, slinkindex
) ->
312 "annotation: " ^ getannotcontents opaque slinkindex
315 let updateunder x y =
316 match getunder x y with
317 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
319 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
320 Wsi.setcursor
Wsi.CURSOR_INFO
322 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
323 Wsi.setcursor
Wsi.CURSOR_TEXT
325 if conf
.underinfo
then showtext 'a'
"nnotation";
326 Wsi.setcursor
Wsi.CURSOR_INFO
329 let showlinktype under =
330 if conf
.underinfo
&& under != Unone
331 then showtext ' '
@@ undertext under
334 let [@warning
"-4"] intentry_with_suffix text key
=
337 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
338 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
339 addchar
text @@ asciilower c
341 state
.text <- Printf.sprintf
"invalid key";
348 let b = Buffer.create
16 in
351 let b = Buffer.to_bytes
b in
352 wcmd state
.ss
b @@ Bytes.length
b
356 let nogeomcmds cmds
=
358 | s
, [] -> emptystr s
362 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
363 let rec fold accu
n =
364 if n = Array.length
b
367 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
370 || n = state
.pagecount
- coverB
371 || (n - coverA
) mod columns
= columns
- 1)
377 let pagey = max
0 (y - vy
) in
378 let pagedispy = if pagey > 0 then 0 else vy
- y in
379 let pagedispx, pagex
=
381 if n = coverA
- 1 || n = state
.pagecount
- coverB
382 then x + (sw
- w
) / 2
390 let vw = sw
- pagedispx in
391 let pw = w
- pagex
in
394 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
395 if pagevw > 0 && pagevh > 0
406 ; pagedispx = pagedispx
407 ; pagedispy = pagedispy
419 if Array.length
b = 0
421 else List.rev
(fold [] (page_of_y
y))
424 let layoutS (columns
, b) x y sw sh
=
425 let rec fold accu n =
426 if n = Array.length
b
429 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
437 let pagey = max
0 (y - vy
) in
438 let pagedispy = if pagey > 0 then 0 else vy
- y in
439 let pagedispx, pagex
=
453 let pagecolw = pagew
/columns
in
456 then pagedispx + ((sw
- pagecolw) / 2)
460 let vw = sw
- pagedispx in
461 let pw = pagew
- pagex
in
464 let pagevw = min
pagevw pagecolw in
465 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
466 if pagevw > 0 && pagevh > 0
477 ; pagedispx = pagedispx
478 ; pagedispy = pagedispy
479 ; pagecol
= n mod columns
493 let layout x y sw sh
=
494 if nogeomcmds state
.geomcmds
496 match conf
.columns
with
497 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
498 | Cmulti c
-> layoutN c
x y sw sh
499 | Csplit s
-> layoutS s
x y sw sh
503 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
505 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
508 let tilex = l.pagex
mod conf
.tilew
in
509 let tiley = l.pagey mod conf
.tileh
in
511 let col = l.pagex
/ conf
.tilew
in
512 let row = l.pagey / conf
.tileh
in
514 let rec rowloop row y0 dispy h
=
518 let dh = conf
.tileh
- y0 in
520 let rec colloop col x0 dispx w
=
524 let dw = conf
.tilew
- x0 in
526 f col row dispx dispy
x0 y0 dw dh;
527 colloop (col+1) 0 (dispx
+dw) (w
-dw)
530 colloop col tilex l.pagedispx l.pagevw;
531 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
534 if l.pagevw > 0 && l.pagevh > 0
535 then rowloop row tiley l.pagedispy l.pagevh;
538 let gettileopaque l col row =
540 l.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l.pagew
, l.pageh
, col, row
542 try Some
(Hashtbl.find state
.tilemap
key)
543 with Not_found
-> None
546 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
547 let key = l.pageno
, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
548 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
551 let filledrect2 x0 y0 x1 y1 x2 y2 x3 y3
=
552 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x1; y1; x2
; y2
; x3
; y3
|];
553 GlArray.vertex `two state
.vraw
;
554 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
557 let filledrect1 x0 y0 x1 y1 = filledrect2 x0 y0 x0 y1 x1 y0 x1 y1;;
559 let filledrect x0 y0 x1 y1 =
560 GlArray.disable `texture_coord
;
561 filledrect1 x0 y0 x1 y1;
562 GlArray.enable `texture_coord
;
565 let linerect x0 y0 x1 y1 =
566 GlArray.disable `texture_coord
;
567 Raw.sets_float state
.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
568 GlArray.vertex `two state
.vraw
;
569 GlArray.draw_arrays `line_loop ~first
:0 ~count
:4;
570 GlArray.enable `texture_coord
;
573 let drawtiles l color =
576 let f col row x y tilex tiley w h
=
577 match gettileopaque l col row with
578 | Some
(opaque
, _
, t
) ->
579 let params = x, y, w
, h
, tilex, tiley in
581 then GlTex.env
(`mode `blend
);
582 drawtile
params opaque
;
584 then GlTex.env
(`mode `modulate
);
588 let s = Printf.sprintf
592 let w = measurestr fstate
.fontsize
s in
593 GlDraw.color (0.0, 0.0, 0.0);
594 filledrect (float (x-2))
597 (float (y + fstate
.fontsize
+ 2));
599 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
606 let lw = state
.winw
- x in
609 let lh = state
.winh
- y in
613 then GlTex.env
(`mode `blend
);
614 begin match state
.checkerstexid
with
616 Gl.enable `texture_2d
;
617 GlTex.bind_texture ~target
:`texture_2d id
;
621 and y1 = float (y+h
) in
623 let tw = float w /. 16.0
624 and th
= float h
/. 16.0 in
625 let tx0 = float tilex /. 16.0
626 and ty0
= float tiley /. 16.0 in
628 and ty1
= ty0
+. th
in
629 Raw.sets_float state
.vraw ~pos
:0
630 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
631 Raw.sets_float state
.traw ~pos
:0
632 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
633 GlArray.vertex `two state
.vraw
;
634 GlArray.tex_coord `two state
.traw
;
635 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
636 Gl.disable `texture_2d
;
639 GlDraw.color (1.0, 1.0, 1.0);
640 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
643 then GlTex.env
(`mode `modulate
);
644 if w > 128 && h
> fstate
.fontsize
+ 10
646 let c = if conf
.invert
then 1.0 else 0.0 in
647 GlDraw.color (c, c, c);
650 then (col*conf
.tilew
, row*conf
.tileh
)
653 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l.pageno
c r
;
662 let pagevisible layout n = List.exists
(fun l -> l.pageno
= n) layout;;
664 let tilevisible1 l x y =
666 and ax1
= l.pagex
+ l.pagevw
668 and ay1
= l.pagey + l.pagevh in
672 let bx1 = min
(bx0 + conf
.tilew
) l.pagew
673 and by1
= min
(by0
+ conf
.tileh
) l.pageh
in
675 let rx0 = max
ax0 bx0
676 and ry0
= max ay0 by0
677 and rx1
= min ax1
bx1
678 and ry1
= min ay1 by1
in
680 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
684 let tilevisible layout n x y =
685 let rec findpageinlayout m
= function
686 | l :: rest
when l.pageno
= n ->
687 tilevisible1 l x y || (
688 match conf
.columns
with
689 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
690 | Csplit _
| Csingle _
| Cmulti _
-> false
692 | _
:: rest
-> findpageinlayout 0 rest
695 findpageinlayout 0 layout;
698 let tileready l x y =
699 tilevisible1 l x y &&
700 gettileopaque l (x/conf
.tilew
) (y/conf
.tileh
) != None
703 let tilepage n p
layout =
704 let rec loop = function
708 let f col row _ _ _ _ _ _
=
709 if state
.currently
= Idle
711 match gettileopaque l col row with
714 let x = col*conf
.tilew
715 and y = row*conf
.tileh
in
717 let w = l.pagew
- x in
721 let h = l.pageh
- y in
726 then getpbo
w h conf
.colorspace
729 wcmd "tile %s %d %d %d %d %s"
730 (~
> p
) x y w h (~
> pbo);
733 l, p
, conf
.colorspace
, conf
.angle
,
734 state
.gen
, col, row, conf
.tilew
, conf
.tileh
743 if nogeomcmds state
.geomcmds
747 let preloadlayout x y sw sh
=
748 let y = if y < sh
then 0 else y - sh
in
749 let x = min
0 (x + sw
) in
757 if state
.currently
!= Idle
762 begin match getopaque l.pageno
with
764 wcmd "page %d %d" l.pageno
l.pagedimno
;
765 state
.currently
<- Loading
(l, state
.gen
);
767 tilepage l.pageno opaque pages
;
772 if nogeomcmds state
.geomcmds
778 if conf
.preload && state
.currently
= Idle
779 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
782 let layoutready layout =
783 let rec fold all ls
=
786 let seen = ref false in
787 let allvisible = ref true in
788 let foo col row _ _ _ _ _ _
=
790 allvisible := !allvisible &&
791 begin match gettileopaque l col row with
797 fold (!seen && !allvisible) rest
800 let alltilesvisible = fold true layout in
805 let y = bound
y 0 state
.maxy in
806 let y, layout, proceed
=
807 match conf
.maxwait
with
808 | Some time
when state
.ghyll
== noghyll
->
809 begin match state
.throttle
with
811 let layout = layout x y state
.winw state
.winh
in
812 let ready = layoutready layout in
816 state
.throttle
<- Some
(layout, y, now
());
818 else G.postRedisplay "gotoxy showall (None)";
820 | Some
(_
, _
, started
) ->
821 let dt = now
() -. started
in
824 state
.throttle
<- None
;
825 let layout = layout x y state
.winw state
.winh
in
827 G.postRedisplay "maxwait";
834 let layout = layout x y state
.winw state
.winh
in
835 G.postRedisplay "gotoxy ready";
842 state
.layout <- layout;
843 begin match state
.mode
with
846 | Ltexact
(pageno
, linkno
) ->
847 let rec loop = function
849 state
.lnava
<- Some
(pageno
, linkno
);
850 state
.mode
<- LinkNav
(Ltgendir
0)
851 | l :: _
when l.pageno
= pageno
->
852 begin match getopaque pageno
with
853 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
855 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
856 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
857 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
858 then state
.mode
<- LinkNav
(Ltgendir
0)
860 | _
:: rest
-> loop rest
863 | Ltnotready _
| Ltgendir _
-> ()
865 | Birdseye _
| Textentry _
| View
-> ()
867 begin match state
.mode
with
868 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
869 if not
(pagevisible layout pageno
)
871 match state
.layout with
874 state
.mode
<- Birdseye
(
875 conf
, leftx
, l.pageno
, hooverpageno
, anchor
880 | Ltnotready
(_
, dir
)
883 let rec loop = function
886 match getopaque l.pageno
with
887 | None
-> Ltnotready
(l.pageno
, dir
)
892 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
894 if dir
> 0 then LDfirst
else LDlast
900 | Lnotfound
-> loop rest
902 showlinktype (getlink opaque
n);
903 Ltexact
(l.pageno
, n)
907 state
.mode
<- LinkNav
linknav
910 | Textentry _
| View
-> ()
914 state
.ghyll
<- noghyll
;
917 let mx, my
= state
.mpos
in
922 let conttiling pageno opaque
=
923 tilepage pageno opaque
925 then preloadlayout state
.x state
.y state
.winw state
.winh
929 let gotoxy_and_clear_text x y =
930 if not conf
.verbose
then state
.text <- E.s;
934 let getanchory (n, top
, dtop
) =
935 let y, h = getpageyh
n in
938 let ips = calcips
h in
939 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
941 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
944 let gotoanchor anchor
=
945 gotoxy state
.x (getanchory anchor
);
949 getanchor
() |> cbput state
.hists
.nav
;
953 getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;
957 let anchor = cbgetc state
.hists
.nav dir
in
961 let gotoghyll1 single
y =
963 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
965 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
967 then s (float f /. float a
)
970 then 1.0 -. s ((float (f-b) /. float (n-b)))
976 let ins = float a
*. 0.5
977 and outs
= float (n-b) *. 0.5 in
979 ins +. outs
+. float ones
981 let rec set nab
y sy
=
982 let (_N
, _A
, _B
), y =
985 let scl = if y > sy
then 2 else -2 in
986 let _N, _
, _
= nab
in
987 (_N,0,_N), y+conf
.scrollstep
*scl
989 let sum = summa
_N _A _B
in
990 let dy = float (y - sy
) in
994 then state
.ghyll
<- noghyll
997 let s = scroll n _N _A _B
in
998 let y1 = y1 +. ((s *. dy) /. sum) in
999 gotoxy_and_clear_text state
.x (truncate
y1);
1000 state
.ghyll
<- gf (n+1) y1;
1004 | Some
y'
when single
-> set nab
y' state
.y
1005 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1007 gf 0 (float state
.y)
1010 match conf
.ghyllscroll
with
1011 | Some nab
when not conf
.presentation
->
1012 if state
.ghyll
== noghyll
1013 then set nab
y state
.y
1014 else state
.ghyll
(Some
y)
1016 gotoxy_and_clear_text state
.x y
1019 let gotoghyll = gotoghyll1 false;;
1021 let gotopage n top
=
1022 let y, h = getpageyh
n in
1023 let y = y + (truncate
(top
*. float h)) in
1027 let gotopage1 n top
=
1028 let y = getpagey
n in
1033 let invalidate s f =
1034 state
.redisplay
<- false;
1039 match state
.geomcmds
with
1040 | ps
, [] when emptystr ps
->
1042 state
.geomcmds
<- s, [];
1045 state
.geomcmds
<- ps
, [s, f];
1047 | ps
, (s'
, _
) :: rest
when s'
= s ->
1048 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1051 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1055 Hashtbl.iter
(fun _ opaque
->
1056 wcmd "freepage %s" (~
> opaque
);
1058 Hashtbl.clear state
.pagemap
;
1062 if not
(Queue.is_empty state
.tilelru
)
1064 Queue.iter
(fun (k
, p
, s) ->
1065 wcmd "freetile %s" (~
> p
);
1066 state
.memused
<- state
.memused
- s;
1067 Hashtbl.remove state
.tilemap k
;
1069 state
.uioh#infochanged Memused
;
1070 Queue.clear state
.tilelru
;
1076 let h = truncate
(float h*.conf
.zoom
) in
1077 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1083 let sl = keystostrlist conf
in
1085 function | [] -> accu
1086 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1087 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1090 let opendoc path password
=
1092 state
.password
<- password
;
1093 state
.gen
<- state
.gen
+ 1;
1094 state
.docinfo
<- [];
1095 state
.outlines
<- [||];
1098 setaalevel conf
.aalevel
;
1100 if emptystr state
.origin
1104 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1105 wcmd "open %d %d %s\000%s\000%s\000"
1106 (btod
!cxack) (btod conf
.usedoccss
)
1107 path password conf
.css
;
1108 invalidate "reqlayout"
1110 wcmd "reqlayout %d %d %d %s\000"
1111 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1112 (stateh state
.winh
) state
.nameddest
1118 state
.anchor <- getanchor
();
1119 opendoc state
.path state
.password
;
1123 let c = c *. conf
.colorscale
in
1127 let scalecolor2 (r
, g, b) =
1128 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1131 let docolumns columns
=
1134 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1135 let rec loop pageno
pdimno pdim
y ph pdims
=
1136 if pageno
= state
.pagecount
1139 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1141 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1142 pdimno+1, pdim
, rest
1146 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1148 y + (if conf
.presentation
1149 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1150 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1153 a.(pageno
) <- (pdimno, x, y, pdim
);
1154 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1156 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1157 conf
.columns
<- Csingle
a;
1159 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1160 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1161 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1163 if m
= pageno
then () else
1164 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1167 let y = y + (rowh
- h) / 2 in
1168 a.(m
) <- (pdimno, x, y, pdim
);
1172 if pageno
= state
.pagecount
1173 then fixrow (((pageno
- 1) / columns
) * columns
)
1175 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1177 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1178 pdimno+1, pdim
, rest
1183 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1185 let x = (state
.winw
- w) / 2 in
1187 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1188 x, y + ips + rowh
, h
1191 if (pageno
- coverA
) mod columns
= 0
1193 let x = max
0 (state
.winw
- state
.w) / 2 in
1195 if conf
.presentation
1197 let ips = calcips
h in
1198 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1200 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1204 else x, y, max rowh
h
1208 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1211 if pageno
= columns
&& conf
.presentation
1213 let ips = calcips rowh
in
1214 for i
= 0 to pred columns
1216 let (pdimno, x, y, pdim
) = a.(i
) in
1217 a.(i
) <- (pdimno, x, y+ips, pdim
)
1223 fixrow (pageno
- columns
);
1228 a.(pageno
) <- (pdimno, x, y, pdim
);
1229 let x = x + w + xoff
*2 + conf
.interpagespace
in
1230 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1232 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1233 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1236 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1237 let rec loop pageno
pdimno pdim
y pdims
=
1238 if pageno
= state
.pagecount
1241 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1243 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1244 pdimno+1, pdim
, rest
1249 let rec loop1 n x y =
1250 if n = c then y else (
1251 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1252 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1255 let y = loop1 0 0 y in
1256 loop (pageno
+1) pdimno pdim
y pdims
1258 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1259 conf
.columns
<- Csplit
(c, a);
1263 docolumns conf
.columns
;
1264 state
.maxy <- calcheight
();
1265 if state
.reprf
== noreprf
1267 match state
.mode
with
1268 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1269 let y, h = getpageyh pageno
in
1270 let top = (state
.winh
- h) / 2 in
1271 gotoxy state
.x (max
0 (y - top))
1272 | Textentry _
| View
| LinkNav _
->
1273 let y = getanchory state
.anchor in
1274 let y = min
y (state
.maxy - state
.winh
) in
1279 state
.reprf
<- noreprf
;
1283 let reshape ?
(firsttime
=false) w h =
1284 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1285 if not firsttime
&& nogeomcmds state
.geomcmds
1286 then state
.anchor <- getanchor
();
1289 let w = truncate
(float w *. conf
.zoom
) in
1292 setfontsize fstate
.fontsize
;
1293 GlMat.mode `modelview
;
1294 GlMat.load_identity
();
1296 GlMat.mode `projection
;
1297 GlMat.load_identity
();
1298 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1299 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1300 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1305 else float state
.x /. float state
.w
1307 invalidate "geometry"
1311 then state
.x <- truncate
(relx *. float w);
1313 match conf
.columns
with
1315 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1316 | Csplit
(c, _
) -> w * c
1318 wcmd "geometry %d %d %d"
1319 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1324 let len = String.length state
.text in
1325 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1328 match state
.mode
with
1329 | Textentry _
| View
| LinkNav _
->
1330 let h, _
, _
= state
.uioh#scrollpw
in
1336 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1337 (x+.w) (float (state
.winh
- hscrollh))
1340 let w = float (state
.winw
- 1 - vscrollw ()) in
1341 if state
.progress
>= 0.0 && state
.progress
< 1.0
1343 GlDraw.color (0.3, 0.3, 0.3);
1344 let w1 = w *. state
.progress
in
1346 GlDraw.color (0.0, 0.0, 0.0);
1347 rect (float x0+.w1) (float x0+.w-.w1)
1350 GlDraw.color (0.0, 0.0, 0.0);
1354 GlDraw.color (1.0, 1.0, 1.0);
1357 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1358 (state
.winh
- hscrollh - 5) s;
1361 match state
.mode
with
1362 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1365 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1366 else Printf.sprintf
"%s%s_" prefix
text
1370 | Birdseye _
| View
| LinkNav _
-> state
.text
1375 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1377 let s1 = "(press 'e' to review error messasges)" in
1378 if nonemptystr
s then s ^
" " ^
s1 else s1
1388 let len = Queue.length state
.tilelru
in
1390 match state
.throttle
with
1393 then preloadlayout state
.x state
.y state
.winw state
.winh
1395 | Some
(layout, _
, _
) ->
1399 if state
.memused
> conf
.memlimit
1403 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1404 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1405 let (_
, pw, ph
, _
) = getpagedim
n in
1407 && colorspace
= conf
.colorspace
1408 && angle
= conf
.angle
1412 let x = col*conf
.tilew
1413 and y = row*conf
.tileh
in
1414 tilevisible (Lazy.force_val
layout) n x y
1416 then Queue.push lruitem state
.tilelru
1419 wcmd "freetile %s" (~
> p
);
1420 state
.memused
<- state
.memused
- s;
1421 state
.uioh#infochanged Memused
;
1422 Hashtbl.remove state
.tilemap k
;
1430 let onpagerect pageno
f =
1432 match conf
.columns
with
1433 | Cmulti
(_
, b) -> b
1435 | Csplit
(_
, b) -> b
1437 if pageno
>= 0 && pageno
< Array.length
b
1439 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1443 let gotopagexy1 pageno
x y =
1444 let _,w1,h1
,leftx
= getpagedim pageno
in
1445 let top = y /. (float h1
) in
1446 let left = x /. (float w1) in
1447 let py, w, h = getpageywh pageno
in
1448 let wh = state
.winh
in
1449 let x = left *. (float w) in
1450 let x = leftx
+ state
.x + truncate
x in
1452 if x < 0 || x >= state
.winw
1456 let pdy = truncate
(top *. float h) in
1457 let y'
= py + pdy in
1458 let dy = y'
- state
.y in
1460 if x != state
.x || not
(dy > 0 && dy < wh)
1462 if conf
.presentation
1464 if abs
(py - y'
) > wh
1471 if state
.x != sx || state
.y != sy
1472 then gotoxy_and_clear_text sx sy
1473 else gotoxy_and_clear_text state
.x state
.y;
1476 let gotopagexy pageno
x y =
1477 match state
.mode
with
1478 | Birdseye
_ -> gotopage pageno
0.0
1479 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 pageno
x y
1482 let getpassword () =
1483 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1488 impmsg "error getting password: %s" s;
1489 dolog
"%s" s) passcmd;
1492 let pgoto opaque pageno
x y =
1493 let pdimno = getpdimno pageno
in
1494 let x, y = project opaque pageno
pdimno x y in
1495 gotopagexy pageno
x y;
1499 (* dolog "%S" cmds; *)
1500 let spl = splitatchar cmds ' '
in
1502 try Scanf.sscanf
s fmt
f
1504 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1507 let addoutline outline
=
1508 match state
.currently
with
1509 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1510 | Idle
-> state
.currently
<- Outlining
[outline
]
1511 | Loading
_ | Tiling
_ ->
1512 dolog
"invalid outlining state";
1513 logcurrently state
.currently
1518 state
.uioh#infochanged Pdim
;
1520 | "clearrects", "" ->
1521 state
.rects
<- state
.rects1
;
1522 G.postRedisplay "clearrects";
1524 | "continue", args
->
1525 let n = scan args
"%u" (fun n -> n) in
1526 state
.pagecount
<- n;
1527 begin match state
.currently
with
1529 state
.currently
<- Idle
;
1530 state
.outlines
<- Array.of_list
(List.rev
l)
1531 | Idle
| Loading
_ | Tiling
_ -> ()
1534 let cur, cmds
= state
.geomcmds
in
1536 then failwith
"umpossible";
1538 begin match List.rev cmds
with
1540 state
.geomcmds
<- E.s, [];
1541 state
.throttle
<- None
;
1545 state
.geomcmds
<- s, List.rev rest
;
1547 if conf
.maxwait
= None
1548 then G.postRedisplay "continue";
1555 then showtext ' ' args
1558 Buffer.add_string state
.errmsgs args
;
1559 state
.newerrmsgs
<- true;
1560 G.postRedisplay "error message"
1562 | "progress", args
->
1563 let progress, text =
1566 f, String.sub args pos
(String.length args
- pos
))
1569 state
.progress <- progress;
1570 G.postRedisplay "progress"
1572 | "firstmatch", args
->
1573 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1574 scan args
"%u %d %f %f %f %f %f %f %f %f"
1575 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1576 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1578 let y = (getpagey
pageno) + truncate
y0 in
1580 if (state
.x < - truncate
x0) || (state
.x > state
.winw
- truncate
x1)
1581 then state
.winw
/2 - truncate
(x0 /. 2. +. x1 /. 2.)
1586 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1587 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1590 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1591 scan args
"%u %d %f %f %f %f %f %f %f %f"
1592 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1593 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1595 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1597 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1600 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1601 let pageopaque = ~
< pageopaques in
1602 begin match state
.currently
with
1603 | Loading
(l, gen
) ->
1604 vlog "page %d took %f sec" l.pageno t
;
1605 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1606 begin match state
.throttle
with
1608 let preloadedpages =
1610 then preloadlayout state
.x state
.y state
.winw state
.winh
1615 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1616 IntSet.empty
preloadedpages
1619 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1620 if not
(IntSet.mem
pageno set)
1622 wcmd "freepage %s" (~
> opaque
);
1628 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1631 state
.currently
<- Idle
;
1634 tilepage l.pageno pageopaque state
.layout;
1636 load preloadedpages;
1637 let visible = pagevisible state
.layout l.pageno in
1640 match state
.mode
with
1641 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1642 if pageno = l.pageno
1647 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1649 if dir
> 0 then LDfirst
else LDlast
1652 findlink
pageopaque ld
1657 showlinktype (getlink
pageopaque n);
1658 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1660 | LinkNav
(Ltgendir
_)
1661 | LinkNav
(Ltexact
_)
1667 if visible && layoutready state
.layout
1669 G.postRedisplay "page";
1673 | Some
(layout, _, _) ->
1674 state
.currently
<- Idle
;
1675 tilepage l.pageno pageopaque layout;
1679 | Idle
| Tiling
_ | Outlining
_ ->
1680 dolog
"Inconsistent loading state";
1681 logcurrently state
.currently
;
1686 let (x, y, opaques
, size
, t
) =
1687 scan args
"%u %u %s %u %f"
1688 (fun x y p size t
-> (x, y, p
, size
, t
))
1690 let opaque = ~
< opaques
in
1691 begin match state
.currently
with
1692 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1693 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1696 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1698 wcmd "freetile %s" (~
> opaque);
1699 state
.currently
<- Idle
;
1703 puttileopaque l col row gen cs angle
opaque size t
;
1704 state
.memused
<- state
.memused
+ size
;
1705 state
.uioh#infochanged Memused
;
1707 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1708 opaque, size
) state
.tilelru
;
1711 match state
.throttle
with
1712 | None
-> state
.layout
1713 | Some
(layout, _, _) -> layout
1716 state
.currently
<- Idle
;
1718 && conf
.colorspace
= cs
1719 && conf
.angle
= angle
1720 && tilevisible layout l.pageno x y
1721 then conttiling l.pageno pageopaque;
1723 begin match state
.throttle
with
1725 preload state
.layout;
1727 && conf
.colorspace
= cs
1728 && conf
.angle
= angle
1729 && tilevisible state
.layout l.pageno x y
1730 && layoutready state
.layout
1731 then G.postRedisplay "tile nothrottle";
1733 | Some
(layout, y, _) ->
1734 let ready = layoutready layout in
1738 state
.layout <- layout;
1739 state
.throttle
<- None
;
1740 G.postRedisplay "throttle";
1746 | Idle
| Loading
_ | Outlining
_ ->
1747 dolog
"Inconsistent tiling state";
1748 logcurrently state
.currently
;
1753 let (n, w, h, _) as pdim
=
1754 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1757 match conf
.fitmodel
with
1759 | FitPage
| FitProportional
->
1760 match conf
.columns
with
1761 | Csplit
_ -> (n, w, h, 0)
1762 | Csingle
_ | Cmulti
_ -> pdim
1764 state
.pdims
<- pdim :: state
.pdims
;
1765 state
.uioh#infochanged Pdim
1768 let (l, n, t
, h, pos
) =
1769 scan args
"%u %u %d %u %n"
1770 (fun l n t
h pos
-> l, n, t
, h, pos
)
1772 let s = String.sub args pos
(String.length args
- pos
) in
1773 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1776 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1777 let s = String.sub args pos
len in
1778 let pos2 = pos
+ len + 1 in
1779 let uri = String.sub args
pos2 (String.length args
- pos2) in
1780 addoutline (s, l, Ouri
uri)
1783 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1784 let s = String.sub args pos
(String.length args
- pos
) in
1785 addoutline (s, l, Onone
)
1789 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1791 state
.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
1794 let c, v
= splitatchar args '
\t'
in
1801 if not
!ignoredoctitlte
1802 then Wsi.settitle v
;
1806 if let len = String.length
c in
1807 len > 6 && ((String.sub
c (len-4) 4) = "date")
1809 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1811 let b = Buffer.create
10 in
1812 Printf.bprintf
b "%s\t" c;
1815 Buffer.add_substring
b v p
l;
1816 Buffer.add_char
b c;
1817 with exn
-> Buffer.add_string
b @@ exntos exn
1825 Buffer.add_char
b '
['
;
1826 Buffer.add_string
b v
;
1827 Buffer.add_char
b '
]'
;
1834 state
.docinfo
<- (1, s) :: state
.docinfo
1837 state
.docinfo
<- List.rev state
.docinfo
;
1838 state
.uioh#infochanged Docinfo
1842 then Wsi.settitle
"Wrong password";
1843 let password = getpassword () in
1844 if emptystr
password
1845 then error
"document is password protected"
1846 else opendoc state
.path
password
1849 error
"unknown cmd `%S'" cmds
1854 let action = function
1855 | HCprev
-> cbget cb ~
-1
1856 | HCnext
-> cbget cb
1
1857 | HCfirst
-> cbget cb ~
-(cb
.rc)
1858 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1859 and cancel
() = cb
.rc <- rc
1863 let search pattern forward
=
1864 match conf
.columns
with
1865 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1866 | Csingle
_ | Cmulti
_ ->
1867 if nonemptystr pattern
1870 match state
.layout with
1873 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1875 wcmd "search %d %d %d %d,%s\000"
1876 (btod conf
.icase
) pn py (btod forward
) pattern
;
1879 let [@warning
"-4"] intentry
text key =
1881 if emptystr
text && key = Keys.Ascii '
-'
1882 then addchar
text '
-'
1885 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1887 state
.text <- "invalid key";
1897 let l = String.length
s in
1898 let rec loop pos
n =
1902 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1903 loop (pos
+1) (n*26 + m)
1906 let rec loop n = function
1909 match getopaque l.pageno with
1910 | None
-> loop n rest
1912 let m = getlinkcount
opaque in
1915 let under = getlink
opaque n in
1918 else loop (n-m) rest
1920 loop n state
.layout;
1924 let [@warning
"-4"] linknentry
text = function
1926 let text = addchar
text c in
1927 linknact (fun under -> state
.text <- undertext under) text;
1930 state
.text <- Printf.sprintf
"invalid key";
1934 let [@warning
"-4"] textentry
text = function
1935 | Keys.Ascii
c -> TEcont
(addchar
text c)
1936 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1940 let reqlayout angle fitmodel
=
1941 match state
.throttle
with
1943 if nogeomcmds state
.geomcmds
1944 then state
.anchor <- getanchor
();
1945 conf
.angle
<- angle
mod 360;
1948 match state
.mode
with
1949 | LinkNav
_ -> state
.mode
<- View
1950 | Birdseye
_ | Textentry
_ | View
-> ()
1952 conf
.fitmodel
<- fitmodel
;
1956 wcmd "reqlayout %d %d %d"
1957 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1962 let settrim trimmargins trimfuzz
=
1963 if nogeomcmds state
.geomcmds
1964 then state
.anchor <- getanchor
();
1965 conf
.trimmargins
<- trimmargins
;
1966 conf
.trimfuzz
<- trimfuzz
;
1967 let x0, y0, x1, y1 = trimfuzz
in
1969 "settrim" (fun () ->
1970 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1975 match state
.throttle
with
1977 let zoom = max
0.0001 zoom in
1978 if zoom <> conf
.zoom
1980 state
.prevzoom
<- (conf
.zoom, state
.x);
1982 reshape state
.winw state
.winh
;
1983 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
1986 | Some
(layout, y, started
) ->
1988 match conf
.maxwait
with
1992 let dt = now
() -. started
in
2000 let pivotzoom ?
(vw=min state
.w state
.winw
)
2001 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
2002 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2003 let w = float state
.w /. zoom in
2004 let hw = w /. 2.0 in
2005 let ratio = float vh
/. float vw in
2006 let hh = hw *. ratio in
2007 let x0 = float x -. hw
2008 and y0 = float y -. hh in
2009 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2013 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2014 if nogeomcmds state
.geomcmds
2017 then pivotzoom ?
vw ?vh ?
x ?
y zoom
2021 let setcolumns mode columns coverA coverB
=
2022 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2026 then impmsg "split mode doesn't work in bird's eye"
2028 conf
.columns
<- Csplit
(-columns
, E.a);
2036 conf
.columns
<- Csingle
E.a;
2041 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2045 reshape state
.winw state
.winh
;
2048 let resetmstate () =
2049 state
.mstate
<- Mnone
;
2050 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2053 let enterbirdseye () =
2054 let zoom = float conf
.thumbw
/. float state
.winw
in
2055 let birdseyepageno =
2056 let cy = state
.winh
/ 2 in
2060 let rec fold best
= function
2063 let d = cy - (l.pagedispy + l.pagevh/2)
2064 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2065 if abs
d < abs dbest
2074 { conf
with zoom = conf
.zoom },
2075 state
.x, birdseyepageno, -1, getanchor
()
2079 conf
.presentation
<- false;
2080 conf
.interpagespace
<- 10;
2081 conf
.hlinks
<- false;
2082 conf
.fitmodel
<- FitPage
;
2084 conf
.maxwait
<- None
;
2086 match conf
.beyecolumns
with
2089 Cmulti
((c, 0, 0), E.a)
2090 | None
-> Csingle
E.a
2094 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2099 reshape state
.winw state
.winh
;
2102 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2104 conf
.zoom <- c.zoom;
2105 conf
.presentation
<- c.presentation
;
2106 conf
.interpagespace
<- c.interpagespace
;
2107 conf
.maxwait
<- c.maxwait
;
2108 conf
.hlinks
<- c.hlinks
;
2109 conf
.fitmodel
<- c.fitmodel
;
2110 conf
.beyecolumns
<- (
2111 match conf
.columns
with
2112 | Cmulti
((c, _, _), _) -> Some
c
2114 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2117 match c.columns
with
2118 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2119 | Csingle
_ -> Csingle
E.a
2120 | Csplit
(c, _) -> Csplit
(c, E.a)
2124 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2127 reshape state
.winw state
.winh
;
2128 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2132 let togglebirdseye () =
2133 match state
.mode
with
2134 | Birdseye vals
-> leavebirdseye vals
true
2135 | View
-> enterbirdseye ()
2136 | Textentry
_ | LinkNav
_ -> ()
2139 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2140 let pageno = max
0 (pageno - incr
) in
2141 let rec loop = function
2142 | [] -> gotopage1 pageno 0
2143 | l :: _ when l.pageno = pageno ->
2144 if l.pagedispy >= 0 && l.pagey = 0
2145 then G.postRedisplay "upbirdseye"
2146 else gotopage1 pageno 0
2147 | _ :: rest
-> loop rest
2151 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2154 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2155 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2156 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2157 let rec loop = function
2159 let y, h = getpageyh
pageno in
2160 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2161 gotoxy state
.x (clamp dy)
2162 | l :: _ when l.pageno = pageno ->
2163 if l.pagevh != l.pageh
2164 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2165 else G.postRedisplay "downbirdseye"
2166 | _ :: rest
-> loop rest
2172 let [@warning
"-4"] optentry mode
_ key =
2173 let btos b = if b then "on" else "off" in
2177 try conf
.scrollstep
<- int_of_string
s with exn
->
2178 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2180 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2185 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2186 if state
.autoscroll
<> None
2187 then state
.autoscroll
<- Some conf
.autoscrollstep
2189 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2191 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2196 let n, a, b = multicolumns_of_string
s in
2197 setcolumns mode
n a b;
2199 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2201 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2206 let zoom = float (int_of_string
s) /. 100.0 in
2209 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2211 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2216 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2218 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2219 begin match mode
with
2221 leavebirdseye beye
false;
2223 | Textentry
_ | View
| LinkNav
_ -> ();
2226 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2228 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2232 match int_of_string
s with
2233 | angle
-> reqlayout angle conf
.fitmodel
2235 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2237 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2240 conf
.icase
<- not conf
.icase
;
2241 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2244 conf
.preload <- not conf
.preload;
2245 gotoxy state
.x state
.y;
2246 TEdone
("preload " ^
(btos conf
.preload))
2249 conf
.verbose
<- not conf
.verbose
;
2250 TEdone
("verbose " ^
(btos conf
.verbose
))
2253 conf
.debug
<- not conf
.debug
;
2254 TEdone
("debug " ^
(btos conf
.debug
))
2257 conf
.maxhfit
<- not conf
.maxhfit
;
2258 state
.maxy <- calcheight
();
2259 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2262 conf
.crophack
<- not conf
.crophack
;
2263 TEdone
("crophack " ^
btos conf
.crophack
)
2267 match conf
.maxwait
with
2269 conf
.maxwait
<- Some infinity
;
2270 "always wait for page to complete"
2272 conf
.maxwait
<- None
;
2273 "show placeholder if page is not ready"
2278 conf
.underinfo
<- not conf
.underinfo
;
2279 TEdone
("underinfo " ^
btos conf
.underinfo
)
2282 conf
.savebmarks
<- not conf
.savebmarks
;
2283 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2289 match state
.layout with
2294 conf
.interpagespace
<- int_of_string
s;
2295 docolumns conf
.columns
;
2296 state
.maxy <- calcheight
();
2297 let y = getpagey
pageno in
2298 gotoxy state
.x (y + py)
2300 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2302 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2306 match conf
.fitmodel
with
2307 | FitProportional
-> FitWidth
2308 | FitWidth
| FitPage
-> FitProportional
2310 reqlayout conf
.angle
fm;
2311 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2314 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2315 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2318 conf
.invert
<- not conf
.invert
;
2319 TEdone
("invert colors " ^
btos conf
.invert
)
2323 cbput state
.hists
.sel
s;
2326 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2327 textentry
, ondone, true)
2331 then conf
.pax
<- Some
0.0
2332 else conf
.pax
<- None
;
2333 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2336 state
.text <- Printf.sprintf
"bad option %d `%c'"
2344 class type lvsource
=
2346 method getitemcount
: int
2347 method getitem
: int -> (string * int)
2348 method hasaction
: int -> bool
2349 method exit
: uioh
:uioh
->
2355 method getactive
: int
2356 method getfirst
: int
2358 method getminfo
: (int * int) array
2361 class virtual lvsourcebase
= object
2362 val mutable m_active
= 0
2363 val mutable m_first
= 0
2364 val mutable m_pan
= 0
2365 method getactive
= m_active
2366 method getfirst
= m_first
2367 method getpan
= m_pan
2368 method getminfo
: (int * int) array
= E.a
2373 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2376 state
.mode
<- Textentry
(te
, onleave
);
2378 G.postRedisplay "textentrykeyboard enttext";
2380 let histaction cmd
=
2383 | Some
(action, _) ->
2386 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2388 G.postRedisplay "textentry histaction"
2391 let kt = Wsi.kc2kt
key in
2394 if emptystr
text && cancelonempty
2397 G.postRedisplay "textentrykeyboard after cancel";
2400 let s = withoutlastutf8
text in
2401 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2406 G.postRedisplay "textentrykeyboard after confirm"
2408 | Up
-> histaction HCprev
2409 | Down
-> histaction HCnext
2410 | Home
-> histaction HCfirst
2411 | End
-> histaction HClast
2416 begin match opthist
with
2418 | Some
(_, onhistcancel
) -> onhistcancel
()
2422 G.postRedisplay "textentrykeyboard after cancel2"
2425 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2430 | Code
_ | Ascii
_ ->
2431 begin match onkey
text kt with
2435 G.postRedisplay "textentrykeyboard after confirm2";
2438 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2442 G.postRedisplay "textentrykeyboard after cancel3"
2445 state
.mode
<- Textentry
(te
, onleave
);
2446 G.postRedisplay "textentrykeyboard switch";
2448 | _ -> vlog "unhandled key"
2451 let firstof first active
=
2452 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2453 then max
0 (active
- (fstate
.maxrows
/2))
2457 let calcfirst first active
=
2460 let rows = active
- first
in
2461 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2465 let scrollph y maxy =
2466 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2467 let sh = float state
.winh
/. sh in
2468 let sh = max
sh (float conf
.scrollh
) in
2470 let percent = float y /. float maxy in
2471 let position = (float state
.winh
-. sh) *. percent in
2474 if position +. sh > float state
.winh
2475 then float state
.winh
-. sh
2481 let adderrmsg src msg
=
2482 Buffer.add_string state
.errmsgs msg
;
2483 state
.newerrmsgs
<- true;
2487 let adderrfmt src fmt
=
2488 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2491 let coe s = (s :> uioh
);;
2493 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2495 val m_pan
= source#getpan
2496 val m_first
= source#getfirst
2497 val m_active
= source#getactive
2499 val m_prev_uioh
= state
.uioh
2501 method private elemunder
y =
2505 let n = y / (fstate
.fontsize
+1) in
2506 if m_first
+ n < source#getitemcount
2508 if source#hasaction
(m_first
+ n)
2509 then Some
(m_first
+ n)
2516 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2517 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2518 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2519 GlDraw.color (1., 1., 1.);
2520 Gl.enable `texture_2d
;
2521 let fs = fstate
.fontsize
in
2523 let hw = state
.winw
/3 in
2524 let ww = fstate
.wwidth
in
2525 let tabw = 17.0*.ww in
2526 let itemcount = source#getitemcount
in
2527 let minfo = source#getminfo
in
2531 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2533 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2535 if (row - m_first
) > fstate
.maxrows
2538 if row >= 0 && row < itemcount
2540 let (s, level
) = source#getitem
row in
2541 let y = (row - m_first
) * nfs in
2542 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2545 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2549 Gl.disable `texture_2d
;
2550 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2551 GlDraw.color (1., 1., 1.) ~
alpha;
2552 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2553 Gl.enable `texture_2d
;
2556 if zebra
&& row land 1 = 1
2560 GlDraw.color (c,c,c);
2561 let drawtabularstring s =
2563 let x'
= truncate
(x0 +. x) in
2564 let s1, s2
= splitatchar
s '
\000'
in
2566 then drawstring1 fs x'
(y+nfs) s
2572 let s'
= withoutlastutf8
s in
2573 let s = s' ^
UniSyms.ellipsis in
2574 let w = measurestr
fs s in
2575 if float x'
+. w +. ww < float (hw + x'
)
2580 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2584 ignore
(drawstring1 fs x'
(y+nfs) s1);
2585 drawstring1 fs (hw + x'
) (y+nfs) s2
2589 let x = if helpmode
&& row > 0 then x +. ww else x in
2590 let s1, s2
= splitatchar
s '
\t'
in
2593 let nx = drawstr x s1 in
2595 let x = x +. (max
tabw sw) in
2598 let len = String.length
s - 2 in
2599 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2601 let s = String.sub s 2 len in
2602 let x = if not helpmode
then x +. ww else x in
2603 GlDraw.color (1.2, 1.2, 1.2);
2604 let vinc = drawstring1 (fs+fs/4)
2605 (truncate
(x -. ww)) (y+nfs) s in
2606 GlDraw.color (1., 1., 1.);
2607 vinc +. (float fs *. 0.8)
2613 ignore
(drawtabularstring s);
2619 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2622 if (row - m_first
) <= fstate
.maxrows
2624 if row >= 0 && row < itemcount
2626 let (s, level
) = source#getitem
row in
2627 let pos0 = nindex
s '
\000'
in
2628 let y = (row - m_first
) * nfs in
2629 let x = float (level
+ m_pan
) *. ww in
2630 let (first
, last
) = minfo.(row) in
2632 if pos0 > 0 && first
> pos0
2633 then String.sub s (pos0+1) (first
-pos0-1)
2634 else String.sub s 0 first
2636 let suffix = String.sub s first
(last
- first
) in
2637 let w1 = measurestr fstate
.fontsize
prefix in
2638 let w2 = measurestr fstate
.fontsize
suffix in
2639 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2640 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2642 and y0 = float (y+2) in
2644 and y1 = float (y+fs+3) in
2645 filledrect x0 y0 x1 y1;
2649 Gl.disable `texture_2d
;
2650 if Array.length
minfo > 0 then loop m_first
;
2655 method updownlevel incr
=
2656 let len = source#getitemcount
in
2658 if m_active
>= 0 && m_active
< len
2659 then snd
(source#getitem m_active
)
2663 if i
= len then i
-1 else if i
= -1 then 0 else
2664 let _, l = source#getitem i
in
2665 if l != curlevel then i
else flow (i
+incr
)
2667 let active = flow m_active
in
2668 let first = calcfirst m_first
active in
2669 G.postRedisplay "outline updownlevel";
2670 {< m_active
= active; m_first
= first >}
2672 method private key1
key mask
=
2673 let set1 active first qsearch
=
2674 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2676 let search active pattern incr
=
2677 let active = if active = -1 then m_first
else active in
2680 if n >= 0 && n < source#getitemcount
2682 let s, _ = source#getitem
n in
2683 match Str.search_forward re
s 0 with
2684 | exception Not_found
-> loop (n + incr
)
2691 let qpat = Str.quote pattern
in
2692 match Str.regexp_case_fold
qpat with
2695 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2696 qpat @@ Printexc.to_string exn
;
2699 let itemcount = source#getitemcount
in
2700 let find start incr
=
2702 if i
= -1 || i
= itemcount
2705 if source#hasaction i
2707 else find (i
+ incr
)
2712 let set active first =
2713 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2715 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2718 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2720 let incr1 = if incr
> 0 then 1 else -1 in
2721 if isvisible m_first m_active
2724 let next = m_active
+ incr
in
2726 if next < 0 || next >= itemcount
2728 else find next incr1
2730 if abs
(m_active
- next) > fstate
.maxrows
2736 let first = m_first
+ incr
in
2737 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2739 let next = m_active
+ incr
in
2740 let next = bound
next 0 (itemcount - 1) in
2747 if isvisible first next
2754 let first = min
next m_first
in
2756 if abs
(next - first) > fstate
.maxrows
2762 let first = m_first
+ incr
in
2763 let first = bound
first 0 (itemcount - 1) in
2765 let next = m_active
+ incr
in
2766 let next = bound
next 0 (itemcount - 1) in
2767 let next = find next incr1 in
2769 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2771 let active = if m_active
= -1 then next else m_active
in
2776 if isvisible first active
2782 G.postRedisplay "listview navigate";
2786 let kt = Wsi.kc2kt
key in
2787 match [@warning
"-4"] kt with
2788 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2789 let incr = if c = 'r'
then -1 else 1 in
2791 match search (m_active
+ incr) m_qsearch
incr with
2793 state
.text <- m_qsearch ^
" [not found]";
2796 state
.text <- m_qsearch
;
2797 active, firstof m_first
active
2799 G.postRedisplay "listview ctrl-r/s";
2800 set1 active first m_qsearch
;
2802 | Insert
when Wsi.withctrl mask
->
2803 if m_active
>= 0 && m_active
< source#getitemcount
2805 let s, _ = source#getitem m_active
in
2811 if emptystr m_qsearch
2814 let qsearch = withoutlastutf8 m_qsearch
in
2818 G.postRedisplay "listview empty qsearch";
2819 set1 m_active m_first
E.s;
2823 match search m_active
qsearch ~
-1 with
2825 state
.text <- qsearch ^
" [not found]";
2828 state
.text <- qsearch;
2829 active, firstof m_first
active
2831 G.postRedisplay "listview backspace qsearch";
2832 set1 active first qsearch
2835 | Ascii
_ | Code
_ ->
2837 match [@warning
"-8"] kt with
2838 | Ascii
c -> String.make
1 c
2839 | Code code
-> toutf8 code
2841 let pattern = m_qsearch ^
utf8 in
2843 match search m_active
pattern 1 with
2845 state
.text <- pattern ^
" [not found]";
2848 state
.text <- pattern;
2849 active, firstof m_first
active
2851 G.postRedisplay "listview qsearch add";
2852 set1 active first pattern;
2856 if emptystr m_qsearch
2858 G.postRedisplay "list view escape";
2859 let mx, my
= state
.mpos
in
2861 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2862 ~
first:m_first ~pan
:m_pan
with
2863 | None
-> m_prev_uioh
2867 G.postRedisplay "list view kill qsearch";
2868 coe {< m_qsearch
= E.s >}
2873 let self = {< m_qsearch
= E.s >} in
2875 G.postRedisplay "listview enter";
2876 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2877 source#exit ~uioh
:(coe self) ~
cancel
2878 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2880 begin match opt with
2881 | None
-> m_prev_uioh
2888 | Up
-> navigate ~
-1
2889 | Down
-> navigate 1
2890 | Prior
-> navigate ~
-(fstate
.maxrows
)
2891 | Next
-> navigate fstate
.maxrows
2895 G.postRedisplay "listview right";
2896 coe {< m_pan
= m_pan
- 1 >}
2900 G.postRedisplay "listview left";
2901 coe {< m_pan
= m_pan
+ 1 >}
2904 let active = find 0 1 in
2905 G.postRedisplay "listview home";
2909 let first = max
0 (itemcount - fstate
.maxrows
) in
2910 let active = find (itemcount - 1) ~
-1 in
2911 G.postRedisplay "listview end";
2916 method key key mask
=
2917 match state
.mode
with
2919 textentrykeyboard
key mask te
;
2921 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2923 method button button down
x y _ =
2926 | 1 when vscrollhit x ->
2927 G.postRedisplay "listview scroll";
2930 let _, position, sh = self#
scrollph in
2931 if y > truncate
position && y < truncate
(position +. sh)
2933 state
.mstate
<- Mscrolly
;
2937 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2938 let first = truncate
(s *. float source#getitemcount
) in
2939 let first = min source#getitemcount
first in
2940 Some
(coe {< m_first
= first; m_active
= first >})
2942 state
.mstate
<- Mnone
;
2946 begin match self#elemunder
y with
2948 G.postRedisplay "listview click";
2949 source#exit ~uioh
:(coe {< m_active
= n >})
2950 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2954 | n when (n == 4 || n == 5) && not down
->
2955 let len = source#getitemcount
in
2957 if n = 5 && m_first
+ fstate
.maxrows
>= len
2961 let first = m_first
+ (if n == 4 then -1 else 1) in
2962 bound
first 0 (len - 1)
2964 G.postRedisplay "listview wheel";
2965 Some
(coe {< m_first
= first >})
2966 | n when (n = 6 || n = 7) && not down
->
2967 let inc = if n = 7 then -1 else 1 in
2968 G.postRedisplay "listview hwheel";
2969 Some
(coe {< m_pan
= m_pan
+ inc >})
2974 | None
-> m_prev_uioh
2977 method multiclick
_ x y = self#button
1 true x y
2980 match state
.mstate
with
2982 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2983 let first = truncate
(s *. float source#getitemcount
) in
2984 let first = min source#getitemcount
first in
2985 G.postRedisplay "listview motion";
2986 coe {< m_first
= first; m_active
= first >}
2994 method pmotion
x y =
2995 if x < state
.winw
- conf
.scrollbw
2998 match self#elemunder
y with
2999 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3000 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3004 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3009 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3013 method infochanged
_ = ()
3015 method scrollpw
= (0, 0.0, 0.0)
3017 let nfs = fstate
.fontsize
+ 1 in
3018 let y = m_first
* nfs in
3019 let itemcount = source#getitemcount
in
3020 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3021 let maxy = maxi * nfs in
3022 let p, h = scrollph y maxy in
3025 method modehash
= modehash
3026 method eformsgs
= false
3027 method alwaysscrolly
= true
3028 method scroll _ dy =
3030 if dy != 0 then begin
3031 let len = source#getitemcount
in
3033 if dy > 0 && m_first
+ fstate
.maxrows
>= len
3037 let first = m_first
+ dy / 10 in
3038 bound
first 0 (len - 1)
3040 G.postRedisplay "listview wheel";
3041 {< m_first
= first >}
3047 method zoom _ _ _ = ()
3050 class outlinelistview ~zebra ~source
=
3051 let settext autonarrow
s =
3054 let ss = source#statestr
in
3058 else "{" ^
ss ^
"} [" ^
s ^
"]"
3059 else state
.text <- s
3065 ~source
:(source
:> lvsource
)
3067 ~modehash
:(findkeyhash conf
"outline")
3070 val m_autonarrow
= false
3072 method! key key mask
=
3074 if emptystr state
.text
3076 else fstate
.maxrows - 2
3078 let calcfirst first active =
3081 let rows = active - first in
3082 if rows > maxrows then active - maxrows else first
3086 let active = m_active
+ incr in
3087 let active = bound
active 0 (source#getitemcount
- 1) in
3088 let first = calcfirst m_first
active in
3089 G.postRedisplay "outline navigate";
3090 coe {< m_active
= active; m_first
= first >}
3092 let navscroll first =
3094 let dist = m_active
- first in
3100 else first + maxrows
3103 G.postRedisplay "outline navscroll";
3104 coe {< m_first
= first; m_active
= active >}
3106 let ctrl = Wsi.withctrl mask
in
3108 match Wsi.kc2kt
key with
3109 | Ascii '
a'
when ctrl ->
3112 then (source#denarrow
; E.s)
3114 let pattern = source#renarrow
in
3115 if nonemptystr m_qsearch
3116 then (source#narrow m_qsearch
; m_qsearch
)
3120 settext (not m_autonarrow
) text;
3121 G.postRedisplay "toggle auto narrowing";
3122 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3124 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3126 G.postRedisplay "toggle auto narrowing";
3127 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3129 | Ascii '
n'
when ctrl ->
3130 source#narrow m_qsearch
;
3132 then source#add_narrow_pattern m_qsearch
;
3133 G.postRedisplay "outline ctrl-n";
3134 coe {< m_first
= 0; m_active
= 0 >}
3136 | Ascii 'S'
when ctrl ->
3137 let active = source#calcactive
(getanchor
()) in
3138 let first = firstof m_first
active in
3139 G.postRedisplay "outline ctrl-s";
3140 coe {< m_first
= first; m_active
= active >}
3142 | Ascii 'u'
when ctrl ->
3143 G.postRedisplay "outline ctrl-u";
3144 if m_autonarrow
&& nonemptystr m_qsearch
3146 ignore
(source#renarrow
);
3147 settext m_autonarrow
E.s;
3148 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3151 source#del_narrow_pattern
;
3152 let pattern = source#renarrow
in
3154 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3156 settext m_autonarrow
text;
3157 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3160 | Ascii '
l'
when ctrl ->
3161 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3162 G.postRedisplay "outline ctrl-l";
3163 coe {< m_first
= first >}
3165 | Ascii '
\t'
when m_autonarrow
->
3166 if nonemptystr m_qsearch
3168 G.postRedisplay "outline list view tab";
3169 source#add_narrow_pattern m_qsearch
;
3171 coe {< m_qsearch
= E.s >}
3175 | Escape
when m_autonarrow
->
3176 if nonemptystr m_qsearch
3177 then source#add_narrow_pattern m_qsearch
;
3180 | Enter
when m_autonarrow
->
3181 if nonemptystr m_qsearch
3182 then source#add_narrow_pattern m_qsearch
;
3185 | (Ascii
_ | Code
_) when m_autonarrow
->
3186 let pattern = m_qsearch ^ toutf8
key in
3187 G.postRedisplay "outlinelistview autonarrow add";
3188 source#narrow
pattern;
3189 settext true pattern;
3190 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3192 | Backspace
when m_autonarrow
->
3193 if emptystr m_qsearch
3196 let pattern = withoutlastutf8 m_qsearch
in
3197 G.postRedisplay "outlinelistview autonarrow backspace";
3198 ignore
(source#renarrow
);
3199 source#narrow
pattern;
3200 settext true pattern;
3201 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3204 navscroll (max
0 (m_first
- 1))
3207 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3209 | Up
-> navigate ~
-1
3210 | Down
-> navigate 1
3211 | Prior
-> navigate ~
-(fstate
.maxrows)
3212 | Next
-> navigate fstate
.maxrows
3218 G.postRedisplay "outline ctrl right";
3219 {< m_pan
= m_pan
+ 1 >}
3221 else self#updownlevel
1
3229 G.postRedisplay "outline ctrl left";
3230 {< m_pan
= m_pan
- 1 >}
3232 else self#updownlevel ~
-1
3237 G.postRedisplay "outline home";
3238 coe {< m_first
= 0; m_active
= 0 >}
3241 let active = source#getitemcount
- 1 in
3242 let first = max
0 (active - fstate
.maxrows) in
3243 G.postRedisplay "outline end";
3244 coe {< m_active
= active; m_first
= first >}
3246 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
3250 let genhistoutlines () =
3252 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3253 compare c2
.lastvisit c1
.lastvisit
)
3254 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3255 let path = if nonemptystr origin
then origin
else path in
3256 let base = mbtoutf8
@@ Filename.basename
path in
3257 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3261 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3262 Config.save
leavebirdseye;
3263 state
.anchor <- anchor;
3264 state
.bookmarks
<- bookmarks
;
3265 state
.origin
<- origin
;
3268 let x0, y0, x1, y1 = conf
.trimfuzz
in
3269 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3270 reshape ~firsttime
:true state
.winw state
.winh
;
3271 opendoc path origin
;
3275 let makecheckers () =
3276 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3278 converted by Issac Trotts. July 25, 2002 *)
3279 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3280 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3281 let id = GlTex.gen_texture
() in
3282 GlTex.bind_texture ~target
:`texture_2d
id;
3283 GlPix.store
(`unpack_alignment
1);
3284 GlTex.image2d
image;
3285 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3286 [ `mag_filter `nearest
; `min_filter `nearest
];
3290 let setcheckers enabled
=
3291 match state
.checkerstexid
with
3293 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3295 | Some checkerstexid
->
3298 GlTex.delete_texture checkerstexid
;
3299 state
.checkerstexid
<- None
;
3303 let describe_layout layout =
3307 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
3310 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
3312 let sep = if a.pageno+1 = b.pageno then ", " else UniSyms.ellipsis in
3313 Printf.sprintf
"%d%s%d" (a.pageno+1) sep (b.pageno+1)
3315 let rec fold s la lb
= function
3316 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
3317 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
3318 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
3320 fold "Pages" l l rest
3323 let maxy = maxy () in
3326 else 100. *. (float state
.y /. float maxy)
3328 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
3331 let setpresentationmode v
=
3332 let n = page_of_y state
.y in
3333 state
.anchor <- (n, 0.0, 1.0);
3334 conf
.presentation
<- v
;
3335 if conf
.fitmodel
= FitPage
3336 then reqlayout conf
.angle conf
.fitmodel
;
3341 let btos b = if b then UniSyms.radical else E.s in
3342 let showextended = ref false in
3343 let showcolors = ref false in
3344 let leave mode
_ = state
.mode
<- mode
in
3347 val mutable m_l
= []
3348 val mutable m_a
= E.a
3349 val mutable m_prev_uioh
= nouioh
3350 val mutable m_prev_mode
= View
3352 inherit lvsourcebase
3354 method reset prev_mode prev_uioh
=
3355 m_a
<- Array.of_list
(List.rev m_l
);
3357 m_prev_mode
<- prev_mode
;
3358 m_prev_uioh
<- prev_uioh
;
3360 method int name get
set =
3366 try set (int_of_string
s)
3368 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3372 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3373 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3377 method int_with_suffix name get
set =
3379 (name
, `intws get
, 1,
3383 try set (int_of_string_with_suffix
s)
3385 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3390 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3392 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3396 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3398 (name
, `
bool (btos, get
), offset
, Action
(
3405 method color name get
set =
3407 (name
, `
color get
, 1,
3410 let invalid = (nan
, nan
, nan
) in
3413 try color_of_string
s
3415 state
.text <- Printf.sprintf
"bad color `%s': %s"
3422 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3423 state
.text <- color_to_string
(get
());
3424 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3428 method string name get
set =
3430 (name
, `
string get
, 1,
3433 let ondone s = set s in
3434 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3435 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3439 method colorspace name get
set =
3441 (name
, `
string get
, 1,
3446 inherit lvsourcebase
3449 m_active
<- CSTE.to_int conf
.colorspace
;
3452 method getitemcount
=
3453 Array.length
CSTE.names
3456 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3457 ignore
(uioh
, first, pan
);
3458 if not
cancel then set active;
3460 method hasaction
_ = true
3464 let modehash = findkeyhash conf
"info" in
3465 coe (new listview ~zebra
:false ~helpmode
:false
3466 ~
source ~trusted
:true ~
modehash)
3469 method paxmark name get
set =
3471 (name
, `
string get
, 1,
3476 inherit lvsourcebase
3479 m_active
<- MTE.to_int conf
.paxmark
;
3482 method getitemcount
= Array.length
MTE.names
3483 method getitem
n = (MTE.names
.(n), 0)
3484 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3485 ignore
(uioh
, first, pan
);
3486 if not
cancel then set active;
3488 method hasaction
_ = true
3492 let modehash = findkeyhash conf
"info" in
3493 coe (new listview ~zebra
:false ~helpmode
:false
3494 ~
source ~trusted
:true ~
modehash)
3497 method fitmodel name get
set =
3499 (name
, `
string get
, 1,
3504 inherit lvsourcebase
3507 m_active
<- FMTE.to_int conf
.fitmodel
;
3510 method getitemcount
= Array.length
FMTE.names
3511 method getitem
n = (FMTE.names
.(n), 0)
3512 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3513 ignore
(uioh
, first, pan
);
3514 if not
cancel then set active;
3516 method hasaction
_ = true
3520 let modehash = findkeyhash conf
"info" in
3521 coe (new listview ~zebra
:false ~helpmode
:false
3522 ~
source ~trusted
:true ~
modehash)
3525 method caption
s offset
=
3526 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3528 method caption2
s f offset
=
3529 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3531 method getitemcount
= Array.length m_a
3534 let tostr = function
3535 | `
int f -> string_of_int
(f ())
3536 | `intws
f -> string_with_suffix_of_int
(f ())
3538 | `
color f -> color_to_string
(f ())
3539 | `
bool (btos, f) -> btos (f ())
3542 let name, t
, offset
, _ = m_a
.(n) in
3543 ((let s = tostr t
in
3545 then Printf.sprintf
"%s\t%s" name s
3549 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3554 match m_a
.(active) with
3555 | _, _, _, Action
f -> f uioh
3556 | _, _, _, Noaction
-> uioh
3567 method hasaction
n =
3569 | _, _, _, Action
_ -> true
3570 | _, _, _, Noaction
-> false
3572 initializer m_active
<- 1
3575 let rec fillsrc prevmode prevuioh
=
3576 let sep () = src#caption
E.s 0 in
3577 let colorp name get
set =
3579 (fun () -> color_to_string
(get
()))
3582 let c = color_of_string
v in
3586 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3589 let rgba name get
set =
3591 (fun () -> rgba_to_string
(get
()))
3594 let c = rgba_of_string
v in
3598 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3601 let oldmode = state
.mode
in
3602 let birdseye = isbirdseye state
.mode
in
3604 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3606 src#
bool "presentation mode"
3607 (fun () -> conf
.presentation
)
3608 (fun v -> setpresentationmode v);
3610 src#
bool "ignore case in searches"
3611 (fun () -> conf
.icase
)
3612 (fun v -> conf
.icase
<- v);
3615 (fun () -> conf
.preload)
3616 (fun v -> conf
.preload <- v);
3618 src#
bool "highlight links"
3619 (fun () -> conf
.hlinks
)
3620 (fun v -> conf
.hlinks
<- v);
3622 src#
bool "under info"
3623 (fun () -> conf
.underinfo
)
3624 (fun v -> conf
.underinfo
<- v);
3626 src#
bool "persistent bookmarks"
3627 (fun () -> conf
.savebmarks
)
3628 (fun v -> conf
.savebmarks
<- v);
3630 src#fitmodel
"fit model"
3631 (fun () -> FMTE.to_string conf
.fitmodel
)
3632 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3634 src#
bool "trim margins"
3635 (fun () -> conf
.trimmargins
)
3636 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3638 src#
bool "persistent location"
3639 (fun () -> conf
.jumpback
)
3640 (fun v -> conf
.jumpback
<- v);
3643 src#
int "inter-page space"
3644 (fun () -> conf
.interpagespace
)
3646 conf
.interpagespace
<- n;
3647 docolumns conf
.columns
;
3649 match state
.layout with
3654 state
.maxy <- calcheight
();
3655 let y = getpagey
pageno in
3656 gotoxy state
.x (y + py)
3660 (fun () -> conf
.pagebias
)
3661 (fun v -> conf
.pagebias
<- v);
3663 src#
int "scroll step"
3664 (fun () -> conf
.scrollstep
)
3665 (fun n -> conf
.scrollstep
<- n);
3667 src#
int "horizontal scroll step"
3668 (fun () -> conf
.hscrollstep
)
3669 (fun v -> conf
.hscrollstep
<- v);
3671 src#
int "auto scroll step"
3673 match state
.autoscroll
with
3675 | _ -> conf
.autoscrollstep
)
3677 let n = boundastep state
.winh
n in
3678 if state
.autoscroll
<> None
3679 then state
.autoscroll
<- Some
n;
3680 conf
.autoscrollstep
<- n);
3683 (fun () -> truncate
(conf
.zoom *. 100.))
3684 (fun v -> pivotzoom ((float v) /. 100.));
3687 (fun () -> conf
.angle
)
3688 (fun v -> reqlayout v conf
.fitmodel
);
3690 src#
int "scroll bar width"
3691 (fun () -> conf
.scrollbw
)
3694 reshape state
.winw state
.winh
;
3697 src#
int "scroll handle height"
3698 (fun () -> conf
.scrollh
)
3699 (fun v -> conf
.scrollh
<- v;);
3701 src#
int "thumbnail width"
3702 (fun () -> conf
.thumbw
)
3704 conf
.thumbw
<- min
4096 v;
3707 leavebirdseye beye
false;
3714 let mode = state
.mode in
3715 src#
string "columns"
3717 match conf
.columns
with
3719 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3720 | Csplit
(count
, _) -> "-" ^ string_of_int count
3723 let n, a, b = multicolumns_of_string
v in
3724 setcolumns mode n a b);
3727 src#caption
"Pixmap cache" 0;
3728 src#int_with_suffix
"size (advisory)"
3729 (fun () -> conf
.memlimit
)
3730 (fun v -> conf
.memlimit
<- v);
3734 Printf.sprintf
"%s bytes, %d tiles"
3735 (string_with_suffix_of_int state
.memused
)
3736 (Hashtbl.length state
.tilemap
)) 1;
3739 src#caption
"Layout" 0;
3740 src#caption2
"Dimension"
3742 Printf.sprintf
"%dx%d (virtual %dx%d)"
3743 state
.winw state
.winh
3748 src#caption2
"Position" (fun () ->
3749 Printf.sprintf
"%dx%d" state
.x state
.y
3752 src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
3755 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3756 "Save these parameters as global defaults at exit"
3757 (fun () -> conf
.bedefault
)
3758 (fun v -> conf
.bedefault
<- v);
3761 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3762 src#
bool ~offset
:0 ~
btos "Extended parameters"
3763 (fun () -> !showextended)
3764 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3768 (fun () -> conf
.checkers
)
3769 (fun v -> conf
.checkers
<- v; setcheckers v);
3770 src#
bool "update cursor"
3771 (fun () -> conf
.updatecurs
)
3772 (fun v -> conf
.updatecurs
<- v);
3773 src#
bool "scroll-bar on the left"
3774 (fun () -> conf
.leftscroll
)
3775 (fun v -> conf
.leftscroll
<- v);
3777 (fun () -> conf
.verbose
)
3778 (fun v -> conf
.verbose
<- v);
3779 src#
bool "invert colors"
3780 (fun () -> conf
.invert
)
3781 (fun v -> conf
.invert
<- v);
3783 (fun () -> conf
.maxhfit
)
3784 (fun v -> conf
.maxhfit
<- v);
3786 (fun () -> conf
.pax
!= None
)
3789 then conf
.pax
<- Some
(now
())
3790 else conf
.pax
<- None
);
3791 src#
string "uri launcher"
3792 (fun () -> conf
.urilauncher
)
3793 (fun v -> conf
.urilauncher
<- v);
3794 src#
string "path launcher"
3795 (fun () -> conf
.pathlauncher
)
3796 (fun v -> conf
.pathlauncher
<- v);
3797 src#
string "tile size"
3798 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3801 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3802 conf
.tilew
<- max
64 w;
3803 conf
.tileh
<- max
64 h;
3806 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3809 src#
int "texture count"
3810 (fun () -> conf
.texcount
)
3813 then conf
.texcount
<- v
3814 else impmsg "failed to set texture count please retry later"
3816 src#
int "slice height"
3817 (fun () -> conf
.sliceheight
)
3819 conf
.sliceheight
<- v;
3820 wcmd "sliceh %d" conf
.sliceheight
;
3822 src#
int "anti-aliasing level"
3823 (fun () -> conf
.aalevel
)
3825 conf
.aalevel
<- bound
v 0 8;
3826 state
.anchor <- getanchor
();
3827 opendoc state
.path state
.password;
3829 src#
string "page scroll scaling factor"
3830 (fun () -> string_of_float conf
.pgscale)
3833 let s = float_of_string
v in
3836 state
.text <- Printf.sprintf
3837 "bad page scroll scaling factor `%s': %s" v
3841 src#
int "ui font size"
3842 (fun () -> fstate
.fontsize
)
3843 (fun v -> setfontsize (bound
v 5 100));
3844 src#
int "hint font size"
3845 (fun () -> conf
.hfsize
)
3846 (fun v -> conf
.hfsize
<- bound
v 5 100);
3847 src#
bool "crop hack"
3848 (fun () -> conf
.crophack
)
3849 (fun v -> conf
.crophack
<- v);
3850 src#
string "trim fuzz"
3851 (fun () -> irect_to_string conf
.trimfuzz
)
3854 conf
.trimfuzz
<- irect_of_string
v;
3856 then settrim true conf
.trimfuzz
;
3858 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3861 src#
string "throttle"
3863 match conf
.maxwait
with
3864 | None
-> "show place holder if page is not ready"
3867 then "wait for page to fully render"
3869 "wait " ^ string_of_float
time
3870 ^
" seconds before showing placeholder"
3874 let f = float_of_string
v in
3876 then conf
.maxwait
<- None
3877 else conf
.maxwait
<- Some
f
3879 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3882 src#
string "ghyll scroll"
3884 match conf
.ghyllscroll
with
3886 | Some nab
-> ghyllscroll_to_string nab
3889 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3892 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3894 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3897 src#
string "selection command"
3898 (fun () -> conf
.selcmd
)
3899 (fun v -> conf
.selcmd
<- v);
3900 src#
string "synctex command"
3901 (fun () -> conf
.stcmd
)
3902 (fun v -> conf
.stcmd
<- v);
3903 src#
string "pax command"
3904 (fun () -> conf
.paxcmd
)
3905 (fun v -> conf
.paxcmd
<- v);
3906 src#
string "ask password command"
3907 (fun () -> conf
.passcmd)
3908 (fun v -> conf
.passcmd <- v);
3909 src#
string "save path command"
3910 (fun () -> conf
.savecmd
)
3911 (fun v -> conf
.savecmd
<- v);
3912 src#colorspace
"color space"
3913 (fun () -> CSTE.to_string conf
.colorspace
)
3915 conf
.colorspace
<- CSTE.of_int
v;
3919 src#paxmark
"pax mark method"
3920 (fun () -> MTE.to_string conf
.paxmark
)
3921 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3922 if bousable
() && !opengl_has_pbo
3925 (fun () -> conf
.usepbo
)
3926 (fun v -> conf
.usepbo
<- v);
3927 src#
bool "mouse wheel scrolls pages"
3928 (fun () -> conf
.wheelbypage
)
3929 (fun v -> conf
.wheelbypage
<- v);
3930 src#
bool "open remote links in a new instance"
3931 (fun () -> conf
.riani
)
3932 (fun v -> conf
.riani
<- v);
3933 src#
bool "edit annotations inline"
3934 (fun () -> conf
.annotinline
)
3935 (fun v -> conf
.annotinline
<- v);
3936 src#
bool "coarse positioning in presentation mode"
3937 (fun () -> conf
.coarseprespos
)
3938 (fun v -> conf
.coarseprespos
<- v);
3939 src#
bool "use document CSS"
3940 (fun () -> conf
.usedoccss
)
3942 conf
.usedoccss
<- v;
3943 state
.anchor <- getanchor
();
3944 opendoc state
.path state
.password;
3946 src#
bool ~
btos "colors"
3947 (fun () -> !showcolors)
3948 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
3951 colorp " background"
3952 (fun () -> conf
.bgcolor
)
3953 (fun v -> conf
.bgcolor
<- v);
3955 (fun () -> conf
.sbarcolor
)
3956 (fun v -> conf
.sbarcolor
<- v);
3957 rgba " scrollbar handle"
3958 (fun () -> conf
.sbarhndlcolor
)
3959 (fun v -> conf
.sbarhndlcolor
<- v);
3964 src#caption
"Document" 0;
3965 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3966 src#caption2
"Pages"
3967 (fun () -> string_of_int state
.pagecount
) 1;
3968 src#caption2
"Dimensions"
3969 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3970 if nonemptystr conf
.css
3971 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3975 src#caption
"Trimmed margins" 0;
3976 src#caption2
"Dimensions"
3977 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3981 src#caption
"OpenGL" 0;
3982 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3983 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3986 src#caption
"Location" 0;
3987 if nonemptystr state
.origin
3988 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3989 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3991 src#reset prevmode prevuioh
;
3996 let prevmode = state
.mode
3997 and prevuioh
= state
.uioh in
3998 fillsrc prevmode prevuioh
;
3999 let source = (src :> lvsource
) in
4000 let modehash = findkeyhash conf
"info" in
4003 inherit listview ~zebra
:false ~helpmode
:false
4004 ~
source ~trusted
:true ~
modehash as super
4005 val mutable m_prevmemused
= 0
4006 method! infochanged
= function
4008 if m_prevmemused
!= state
.memused
4010 m_prevmemused
<- state
.memused
;
4011 G.postRedisplay "memusedchanged";
4013 | Pdim
-> G.postRedisplay "pdimchanged"
4014 | Docinfo
-> fillsrc prevmode prevuioh
4016 method! key key mask
=
4017 if not
(Wsi.withctrl mask
)
4019 match [@warning
"-4"] Wsi.kc2kt
key with
4020 | Keys.Left
-> coe (self#updownlevel ~
-1)
4021 | Keys.Right
-> coe (self#updownlevel
1)
4022 | _ -> super#
key key mask
4023 else super#
key key mask
4025 G.postRedisplay "info";
4031 inherit lvsourcebase
4032 method getitemcount
= Array.length state
.help
4034 let s, l, _ = state
.help
.(n) in
4037 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4041 match state
.help
.(active) with
4042 | _, _, Action
f -> Some
(f uioh)
4043 | _, _, Noaction
-> Some
uioh
4052 method hasaction
n =
4053 match state
.help
.(n) with
4054 | _, _, Action
_ -> true
4055 | _, _, Noaction
-> false
4061 let modehash = findkeyhash conf
"help" in
4063 state
.uioh <- coe (new listview
4064 ~zebra
:false ~helpmode
:true
4065 ~
source ~trusted
:true ~
modehash);
4066 G.postRedisplay "help";
4072 inherit lvsourcebase
4073 val mutable m_items
= E.a
4075 method getitemcount
= 1 + Array.length m_items
4080 else m_items
.(n-1), 0
4082 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4087 then Buffer.clear state
.errmsgs
;
4094 method hasaction
n =
4098 state
.newerrmsgs
<- false;
4099 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4100 m_items
<- Array.of_list
l
4109 let source = (msgsource :> lvsource
) in
4110 let modehash = findkeyhash conf
"listview" in
4113 inherit listview ~zebra
:false ~helpmode
:false
4114 ~
source ~trusted
:false ~
modehash as super
4117 then msgsource#reset
;
4120 G.postRedisplay "msgs";
4124 let editor = getenvwithdef
"EDITOR" E.s in
4128 let tmppath = Filename.temp_file
"llpp" "note" in
4131 let oc = open_out
tmppath in
4135 let execstr = editor ^
" " ^
tmppath in
4137 match spawn
execstr [] with
4139 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4142 match Unix.waitpid
[] pid
with
4144 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4148 | Unix.WEXITED
0 -> filecontents
tmppath
4150 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4152 | Unix.WSIGNALED
n ->
4153 impmsg "editor process(%s) was killed by signal %d" execstr n;
4155 | Unix.WSTOPPED
n ->
4156 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4159 match Unix.unlink
tmppath with
4161 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4166 let enterannotmode opaque slinkindex
=
4169 inherit lvsourcebase
4170 val mutable m_text
= E.s
4171 val mutable m_items
= E.a
4173 method getitemcount
= Array.length m_items
4176 let label, _func
= m_items
.(n) in
4179 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4180 ignore
(uioh, first, pan
);
4183 let _label, func
= m_items
.(active) in
4188 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4191 let rec split accu b i
=
4193 if p = String.length
s
4194 then (String.sub s b (p-b), unit) :: accu
4196 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4198 let ss = if i
= 0 then E.s else String.sub s b i
in
4199 split ((ss, unit)::accu) (p+1) 0
4204 wcmd "freepage %s" (~
> opaque);
4206 Hashtbl.fold (fun key opaque'
accu ->
4207 if opaque'
= opaque'
4208 then key :: accu else accu) state
.pagemap
[]
4210 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4212 gotoxy state
.x state
.y
4215 delannot
opaque slinkindex
;
4218 let edit inline
() =
4223 modannot
opaque slinkindex
s;
4229 let mode = state
.mode in
4232 ("annotation: ", m_text
, None
, textentry
, update, true),
4233 fun _ -> state
.mode <- mode);
4237 let s = getusertext m_text
in
4242 ( "[Copy]", fun () -> selstring m_text
)
4243 :: ("[Delete]", dele)
4244 :: ("[Edit]", edit conf
.annotinline
)
4246 :: split [] 0 0 |> List.rev
|> Array.of_list
4253 let s = getannotcontents
opaque slinkindex
in
4256 let source = (msgsource :> lvsource
) in
4257 let modehash = findkeyhash conf
"listview" in
4258 state
.uioh <- coe (object
4259 inherit listview ~zebra
:false ~helpmode
:false
4260 ~
source ~trusted
:false ~
modehash
4262 G.postRedisplay "enterannotmode";
4265 let gotoremote spec
=
4266 let filename, dest
= splitatchar spec '#'
in
4267 let getpath filename =
4269 if nonemptystr
filename
4271 if Filename.is_relative
filename
4273 let dir = Filename.dirname state
.path in
4275 if Filename.is_implicit
dir
4276 then Filename.concat
(Sys.getcwd
()) dir
4279 Filename.concat
dir filename
4283 if Sys.file_exists
path
4287 let path = getpath filename in
4291 let cmd = Lazy.force_val lcmd
in
4292 match spawn
cmd with
4294 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4296 let anchor = getanchor
() in
4297 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4298 state
.origin
<- E.s;
4299 state
.ranchors
<- ranchor :: state
.ranchors
;
4302 if substratis spec
0 "page="
4304 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4306 state
.anchor <- (pageno, 0.0, 0.0);
4307 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4309 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4311 state
.nameddest
<- dest
;
4312 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4316 let gotounder = function
4317 | Ulinkuri
s when isexternallink
s ->
4318 if substratis
s 0 "file://"
4319 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4322 let pageno, x, y = uritolocation
s in
4324 gotopagexy pageno x y
4325 | Utext
_ | Unone
-> ()
4326 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4329 let gotooutline (_, _, kind
) =
4333 let (pageno, y, _) = anchor in
4335 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4339 | Ouri
uri -> gotounder (Ulinkuri
uri)
4340 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4341 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4342 | Ohistory hist
-> gotohist hist
4343 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4346 class outlinesoucebase fetchoutlines
= object (self)
4347 inherit lvsourcebase
4348 val mutable m_items
= E.a
4349 val mutable m_minfo
= E.a
4350 val mutable m_orig_items
= E.a
4351 val mutable m_orig_minfo
= E.a
4352 val mutable m_narrow_patterns
= []
4353 val mutable m_gen
= -1
4355 method getitemcount
= Array.length m_items
4358 let s, n, _ = m_items
.(n) in
4361 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4362 ignore
(uioh, first);
4364 if m_narrow_patterns
= []
4365 then m_orig_items
, m_orig_minfo
4366 else m_items
, m_minfo
4373 gotooutline m_items
.(active);
4381 method hasaction
(_:int) = true
4384 if Array.length m_items
!= Array.length m_orig_items
4387 match m_narrow_patterns
with
4389 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4391 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4395 match m_narrow_patterns
with
4398 | head
:: _ -> UniSyms.ellipsis ^ head
4400 method narrow
pattern =
4401 match Str.regexp_case_fold
pattern with
4404 let rec loop accu minfo n =
4407 m_items
<- Array.of_list
accu;
4408 m_minfo
<- Array.of_list
minfo;
4411 let (s, _, _) as o = m_items
.(n) in
4413 match Str.search_forward re
s 0 with
4414 | exception Not_found
-> accu, minfo
4415 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4417 loop accu minfo (n-1)
4419 loop [] [] (Array.length m_items
- 1)
4421 method! getminfo
= m_minfo
4424 m_orig_items
<- fetchoutlines
();
4425 m_minfo
<- m_orig_minfo
;
4426 m_items
<- m_orig_items
4428 method add_narrow_pattern
pattern =
4429 m_narrow_patterns
<- pattern :: m_narrow_patterns
4431 method del_narrow_pattern
=
4432 match m_narrow_patterns
with
4433 | _ :: rest
-> m_narrow_patterns
<- rest
4438 match m_narrow_patterns
with
4439 | pattern :: [] -> self#narrow
pattern; pattern
4441 List.fold_left
(fun accu pattern ->
4442 self#narrow
pattern;
4443 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4445 method calcactive
(_:anchor) = 0
4447 method reset
anchor items =
4448 if state
.gen
!= m_gen
4450 m_orig_items
<- items;
4452 m_narrow_patterns
<- [];
4454 m_orig_minfo
<- E.a;
4458 if items != m_orig_items
4460 m_orig_items
<- items;
4461 if m_narrow_patterns
== []
4462 then m_items
<- items;
4465 let active = self#calcactive
anchor in
4467 m_first
<- firstof m_first
active
4471 let outlinesource fetchoutlines
=
4473 inherit outlinesoucebase fetchoutlines
4474 method! calcactive
anchor =
4475 let rely = getanchory anchor in
4476 let rec loop n best bestd
=
4477 if n = Array.length m_items
4480 let _, _, kind
= m_items
.(n) in
4483 let orely = getanchory anchor in
4484 let d = abs
(orely - rely) in
4487 else loop (n+1) best bestd
4488 | Onone
| Oremote
_ | Olaunch
_
4489 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4490 loop (n+1) best bestd
4496 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4497 let mkselector sourcetype
=
4498 let fetchoutlines () =
4499 match sourcetype
with
4500 | `bookmarks
-> Array.of_list state
.bookmarks
4501 | `outlines
-> state
.outlines
4502 | `history
-> genhistoutlines () |> Array.of_list
4505 if sourcetype
= `history
4506 then new outlinesoucebase
fetchoutlines
4507 else outlinesource fetchoutlines
4510 let outlines = fetchoutlines () in
4511 if Array.length
outlines = 0
4512 then showtext ' ' errmsg
4515 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4516 let anchor = getanchor
() in
4517 source#reset
anchor outlines;
4518 state
.text <- source#greetmsg
;
4520 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4521 G.postRedisplay "enter selector";
4525 let mkenter sourcetype errmsg
=
4526 let enter = mkselector sourcetype
in
4527 fun () -> enter errmsg
4529 ( mkenter `
outlines "document has no outline"
4530 , mkenter `bookmarks
"document has no bookmarks (yet)"
4531 , mkenter `history
"history is empty" )
4534 let quickbookmark ?title
() =
4535 match state
.layout with
4542 let tm = localtime
(now
()) in
4544 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4546 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4548 | Some
title -> title
4550 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4553 let setautoscrollspeed step goingdown
=
4554 let incr = max
1 ((abs step
) / 2) in
4555 let incr = if goingdown
then incr else -incr in
4556 let astep = boundastep state
.winh
(step
+ incr) in
4557 state
.autoscroll
<- Some
astep;
4561 match conf
.columns
with
4563 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4566 let panbound x = bound
x (-state
.w) state
.winw
;;
4568 let existsinrow pageno (columns
, coverA
, coverB
) p =
4569 let last = ((pageno - coverA
) mod columns
) + columns
in
4570 let rec any = function
4573 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4577 then (if l.pageno = last then false else any rest
)
4585 match state
.layout with
4587 let pageno = page_of_y state
.y in
4588 gotoghyll (getpagey
(pageno+1))
4590 match conf
.columns
with
4592 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4594 let y = clamp (pgscale state
.winh
) in
4597 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4598 gotoghyll (getpagey
pageno)
4599 | Cmulti
((c, _, _) as cl
, _) ->
4600 if conf
.presentation
4601 && (existsinrow l.pageno cl
4602 (fun l -> l.pageh
> l.pagey + l.pagevh))
4604 let y = clamp (pgscale state
.winh
) in
4607 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4608 gotoghyll (getpagey
pageno)
4610 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4612 let pagey, pageh
= getpageyh
l.pageno in
4613 let pagey = pagey + pageh
* l.pagecol
in
4614 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4615 gotoghyll (pagey + pageh
+ ips)
4619 match state
.layout with
4621 let pageno = page_of_y state
.y in
4622 gotoghyll (getpagey
(pageno-1))
4624 match conf
.columns
with
4626 if conf
.presentation
&& l.pagey != 0
4628 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4630 let pageno = max
0 (l.pageno-1) in
4631 gotoghyll (getpagey
pageno)
4632 | Cmulti
((c, _, coverB
) as cl
, _) ->
4633 if conf
.presentation
&&
4634 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4636 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4639 if l.pageno = state
.pagecount
- coverB
4643 let pageno = max
0 (l.pageno-decr) in
4644 gotoghyll (getpagey
pageno)
4652 let pageno = max
0 (l.pageno-1) in
4653 let pagey, pageh
= getpageyh
pageno in
4656 let pagey, pageh
= getpageyh
l.pageno in
4657 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4663 if emptystr conf
.savecmd
4664 then adderrmsg "savepath-command is empty"
4665 "don't know where to save modified document"
4667 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4671 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
4676 let tmp = path ^
".tmp" in
4678 Unix.rename
tmp path;
4681 let viewkeyboard key mask
=
4683 let mode = state
.mode in
4684 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4687 G.postRedisplay "view:enttext"
4689 let ctrl = Wsi.withctrl mask
in
4691 match Wsi.kc2kt
key with
4692 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
4694 | Ascii 'Q'
-> exit
0
4697 if hasunsavedchanges
()
4701 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4704 match state
.lnava
with
4705 | None
-> LinkNav
(Ltgendir
0)
4706 | Some
pn -> LinkNav
(Ltexact
pn)
4708 gotoxy state
.x state
.y;
4710 else impmsg "keyboard link navigation does not work under rotation"
4712 | Escape
| Ascii 'q'
->
4713 begin match state
.mstate
with
4716 G.postRedisplay "kill rect";
4719 | Mscrolly
| Mscrollx
4722 begin match state
.mode with
4725 | Ltexact pl
-> state
.lnava
<- Some pl
4726 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4729 G.postRedisplay "esc leave linknav"
4730 | Birdseye
_ | Textentry
_ | View
->
4731 match state
.ranchors
with
4733 | (path, password, anchor, origin
) :: rest
->
4734 state
.ranchors
<- rest
;
4735 state
.anchor <- anchor;
4736 state
.origin
<- origin
;
4737 state
.nameddest
<- E.s;
4738 opendoc path password
4744 gotoghyll (getnav ~
-1)
4755 Hashtbl.iter
(fun _ opaque ->
4757 Hashtbl.clear state
.prects
) state
.pagemap
;
4758 G.postRedisplay "dehighlight";
4760 | Ascii
(('
/'
| '?'
) as c) ->
4761 let ondone isforw
s =
4762 cbput state
.hists
.pat
s;
4763 state
.searchpattern
<- s;
4766 let s = String.make
1 c in
4767 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4768 textentry
, ondone (c = '
/'
), true)
4770 | Ascii '
+'
| Ascii '
='
when ctrl ->
4771 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4772 pivotzoom (conf
.zoom +. incr)
4777 try int_of_string
s with exn
->
4779 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4785 state
.text <- "page bias is now " ^ string_of_int
n;
4788 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4790 | Ascii '
-'
when ctrl ->
4791 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4792 pivotzoom (max
0.01 (conf
.zoom -. decr))
4795 let ondone msg
= state
.text <- msg
in
4797 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4798 optentry state
.mode, ondone, true
4801 | Ascii '
0'
when ctrl ->
4803 then gotoxy 0 state
.y
4806 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4808 match conf
.columns
with
4809 | Csingle
_ | Cmulti
_ -> 1
4810 | Csplit
(n, _) -> n
4812 let h = state
.winh
-
4813 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4815 let zoom = zoomforh state
.winw
h 0 cols in
4816 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4819 | Ascii '
3'
when ctrl ->
4821 match conf
.fitmodel
with
4822 | FitWidth
-> FitProportional
4823 | FitProportional
-> FitPage
4824 | FitPage
-> FitWidth
4826 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4827 reqlayout conf
.angle
fm
4829 | Ascii '
4'
when ctrl ->
4830 let zoom = getmaxw
() /. float state
.winw
in
4831 if zoom > 0.0 then setzoom zoom
4836 | Ascii '
9'
when ctrl ->
4839 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
4842 try int_of_string
s with exn
->
4843 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4849 cbput state
.hists
.pag
(string_of_int
n);
4850 gotopage1 (n + conf
.pagebias
- 1) 0;
4853 let [@warning
"-4"] pageentry
text = function
4854 | Keys.Ascii '
g'
-> TEdone
text
4855 | key -> intentry
text key
4857 let text = String.make
1 c in
4858 enttext (":", text, Some
(onhist state
.hists
.pag
),
4859 pageentry
, ondone, true)
4862 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4863 G.postRedisplay "toggle scrollbar";
4866 state
.bzoom
<- not state
.bzoom
;
4868 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4871 conf
.hlinks
<- not conf
.hlinks
;
4872 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4873 G.postRedisplay "toggle highlightlinks";
4876 if conf
.angle
mod 360 = 0
4878 state
.glinks
<- true;
4879 let mode = state
.mode in
4882 (":", E.s, None
, linknentry
, linknact gotounder, false),
4884 state
.glinks
<- false;
4888 G.postRedisplay "view:linkent(F)"
4890 else impmsg "hint mode does not work under rotation"
4893 state
.glinks
<- true;
4894 let mode = state
.mode in
4897 (":", E.s, None
, linknentry
,
4898 linknact (fun under -> selstring (undertext under)), false),
4900 state
.glinks
<- false;
4904 G.postRedisplay "view:linkent"
4907 begin match state
.autoscroll
with
4909 conf
.autoscrollstep
<- step
;
4910 state
.autoscroll
<- None
4912 state
.autoscroll
<- Some conf
.autoscrollstep
;
4913 state
.slideshow
<- state
.slideshow
land lnot
2
4916 | Ascii '
p'
when ctrl ->
4917 launchpath () (* XXX where do error messages go? *)
4920 setpresentationmode (not conf
.presentation
);
4921 showtext ' '
("presentation mode " ^
4922 if conf
.presentation
then "on" else "off");
4925 if List.mem
Wsi.Fullscreen state
.winstate
4926 then Wsi.reshape conf
.cwinw conf
.cwinh
4927 else Wsi.fullscreen
()
4929 | Ascii
('
p'
|'N'
) ->
4930 search state
.searchpattern
false
4932 | Ascii '
n'
| Fn
3 ->
4933 search state
.searchpattern
true
4936 begin match state
.layout with
4939 gotoghyll (getpagey
l.pageno)
4949 showtext ' '
(describe_layout state
.layout);
4952 begin match state
.layout with
4955 Wsi.reshape l.pagew
l.pageh
;
4960 enterbookmarkmode
()
4962 | Ascii '
h'
| Fn
1 ->
4968 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4973 match state
.layout with
4978 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4981 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
4985 showtext ' '
"Quick bookmark added";
4988 begin match state
.layout with
4990 let rect = getpdimrect
l.pagedimno
in
4994 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4995 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4997 (truncate
(rect.(1) -. rect.(0)),
4998 truncate
(rect.(3) -. rect.(0)))
5000 let w = truncate
((float w)*.conf
.zoom)
5001 and h = truncate
((float h)*.conf
.zoom) in
5004 state
.anchor <- getanchor
();
5005 Wsi.reshape w (h + conf
.interpagespace
)
5007 G.postRedisplay "z";
5012 | Ascii '
x'
-> state
.roam
()
5014 | Ascii
('
<'
|'
>'
as c) ->
5016 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5018 | Ascii
('
['
|'
]'
as c) ->
5020 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
5021 G.postRedisplay "brightness";
5023 | Ascii '
c'
when state
.mode = View
->
5028 let m = (state
.winw
- state
.w) / 2 in
5029 gotoxy_and_clear_text m state
.y
5033 match state
.prevcolumns
with
5034 | None
-> (1, 0, 0), 1.0
5035 | Some
(columns
, z
) ->
5038 | Csplit
(c, _) -> -c, 0, 0
5039 | Cmulti
((c, a, b), _) -> c, a, b
5040 | Csingle
_ -> 1, 0, 0
5044 setcolumns View
c a b;
5047 | Down
| Up
when ctrl && Wsi.withshift mask
->
5048 let zoom, x = state
.prevzoom
in
5053 begin match state
.autoscroll
with
5055 begin match state
.mode with
5056 | Birdseye beye
-> upbirdseye 1 beye
5057 | Textentry
_ | View
| LinkNav
_ ->
5059 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5061 if not
(Wsi.withshift mask
) && conf
.presentation
5063 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5067 setautoscrollspeed n false
5070 | Ascii 'j'
| Down
->
5071 begin match state
.autoscroll
with
5073 begin match state
.mode with
5074 | Birdseye beye
-> downbirdseye 1 beye
5075 | Textentry
_ | View
| LinkNav
_ ->
5077 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5079 if not
(Wsi.withshift mask
) && conf
.presentation
5081 else gotoghyll1 true (clamp (conf
.scrollstep
))
5085 setautoscrollspeed n true
5088 | Left
| Right
when not
(Wsi.withalt mask
) ->
5094 else conf
.hscrollstep
5097 let pv = Wsi.kc2kt
key in
5098 if pv = Keys.Left
then dx else -dx
5100 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5103 G.postRedisplay "left/right"
5110 match state
.layout with
5112 | l :: _ -> state
.y - l.pagey
5114 clamp (pgscale (-state
.winh
))
5122 match List.rev state
.layout with
5124 | l :: _ -> getpagey
l.pageno
5126 clamp (pgscale state
.winh
)
5130 | Ascii '
g'
| Home
->
5133 | Ascii 'G'
| End
->
5135 gotoghyll (clamp state
.maxy)
5137 | Right
when Wsi.withalt mask
->
5139 gotoghyll (getnav 1)
5140 | Left
when Wsi.withalt mask
->
5142 gotoghyll (getnav ~
-1)
5147 | Ascii '
v'
when conf
.debug
->
5150 match getopaque l.pageno with
5153 let x0, y0, x1, y1 = pagebbox
opaque in
5154 let rect = (float x0, float y0,
5157 float x0, float y1) in
5159 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
5160 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
5162 G.postRedisplay "v";
5165 let mode = state
.mode in
5166 let cmd = ref E.s in
5167 let onleave = function
5168 | Cancel
-> state
.mode <- mode
5171 match getopaque l.pageno with
5172 | Some
opaque -> pipesel opaque !cmd
5173 | None
-> ()) state
.layout;
5177 cbput state
.hists
.sel
s;
5181 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
5183 G.postRedisplay "|";
5184 state
.mode <- Textentry
(te, onleave);
5186 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
5187 vlog "huh? %s" (Wsi.keyname
key)
5190 let linknavkeyboard key mask
linknav =
5191 let pv = Wsi.kc2kt
key in
5192 let getpage pageno =
5193 let rec loop = function
5195 | l :: _ when l.pageno = pageno -> Some
l
5196 | _ :: rest
-> loop rest
5197 in loop state
.layout
5199 let doexact (pageno, n) =
5200 match getopaque pageno, getpage pageno with
5201 | Some
opaque, Some
l ->
5204 let under = getlink
opaque n in
5205 G.postRedisplay "link gotounder";
5212 | Home
-> Some
(findlink
opaque LDfirst
), -1
5213 | End
-> Some
(findlink
opaque LDlast
), 1
5214 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
5215 | Right
-> Some
(findlink
opaque (LDright
n)), 1
5216 | Up
-> Some
(findlink
opaque (LDup
n)), -1
5217 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
5219 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
5220 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
5223 begin match findpwl
l.pageno dir with
5227 state
.mode <- LinkNav
(Ltgendir
dir);
5228 let y, h = getpageyh
pageno in
5231 then y + h - state
.winh
5236 begin match getopaque pageno, getpage pageno with
5237 | Some
opaque, Some
_ ->
5239 let ld = if dir > 0 then LDfirst
else LDlast
in
5242 begin match link with
5244 showlinktype (getlink
opaque m);
5245 state
.mode <- LinkNav
(Ltexact
(pageno, m));
5246 G.postRedisplay "linknav jpage";
5247 | Lnotfound
-> notfound dir
5253 begin match opt with
5254 | Some Lnotfound
-> pwl l dir;
5255 | Some
(Lfound
m) ->
5259 let _, y0, _, y1 = getlinkrect
opaque m in
5261 then gotopage1 l.pageno y0
5263 let d = fstate
.fontsize
+ 1 in
5264 if y1 - l.pagey > l.pagevh - d
5265 then gotopage1 l.pageno (y1 - state
.winh
+ d)
5266 else G.postRedisplay "linknav";
5268 showlinktype (getlink
opaque m);
5269 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
5272 | None
-> viewkeyboard key mask
5274 | _ -> viewkeyboard key mask
5278 begin match linknav with
5279 | Ltexact pa
-> state
.lnava
<- Some pa
5280 | Ltgendir
_ | Ltnotready
_ -> ()
5283 G.postRedisplay "leave linknav"
5287 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5288 | Ltexact exact
-> doexact exact
5291 let keyboard key mask
=
5292 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5293 then wcmd "interrupt"
5294 else state
.uioh <- state
.uioh#
key key mask
5297 let birdseyekeyboard key mask
5298 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5300 match conf
.columns
with
5302 | Cmulti
((c, _, _), _) -> c
5303 | Csplit
_ -> failwith
"bird's eye split mode"
5305 let pgh layout = List.fold_left
5306 (fun m l -> max
l.pageh
m) state
.winh
layout in
5308 match Wsi.kc2kt
key with
5309 | Ascii '
l'
when Wsi.withctrl mask
->
5310 let y, h = getpageyh
pageno in
5311 let top = (state
.winh
- h) / 2 in
5312 gotoxy state
.x (max
0 (y - top))
5313 | Enter
-> leavebirdseye beye
false
5314 | Escape
-> leavebirdseye beye
true
5315 | Up
-> upbirdseye incr beye
5316 | Down
-> downbirdseye incr beye
5317 | Left
-> upbirdseye 1 beye
5318 | Right
-> downbirdseye 1 beye
5321 begin match state
.layout with
5325 state
.mode <- Birdseye
(
5326 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5328 gotopage1 l.pageno 0;
5331 let layout = layout state
.x (state
.y-state
.winh
)
5333 (pgh state
.layout) in
5335 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5337 state
.mode <- Birdseye
(
5338 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5340 gotopage1 l.pageno 0
5343 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5347 begin match List.rev state
.layout with
5349 let layout = layout state
.x
5350 (state
.y + (pgh state
.layout))
5351 state
.winw state
.winh
in
5352 begin match layout with
5354 let incr = l.pageh
- l.pagevh in
5359 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5361 G.postRedisplay "birdseye pagedown";
5363 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5367 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5368 gotopage1 l.pageno 0;
5371 | [] -> gotoxy state
.x (clamp state
.winh
)
5375 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5379 let pageno = state
.pagecount
- 1 in
5380 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5381 if not
(pagevisible state
.layout pageno)
5384 match List.rev state
.pdims
with
5386 | (_, _, h, _) :: _ -> h
5390 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5391 else G.postRedisplay "birdseye end";
5393 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
5398 match state
.mode with
5399 | Textentry
_ -> scalecolor 0.4
5400 | LinkNav
_ | View
-> scalecolor 1.0
5401 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5402 if l.pageno = hooverpageno
5405 if l.pageno = pageno
5407 let c = scalecolor 1.0 in
5409 GlDraw.line_width
3.0;
5410 let dispx = l.pagedispx in
5412 (float (dispx-1)) (float (l.pagedispy-1))
5413 (float (dispx+l.pagevw+1))
5414 (float (l.pagedispy+l.pagevh+1))
5416 GlDraw.line_width
1.0;
5425 let postdrawpage l linkindexbase
=
5426 match getopaque l.pageno with
5428 if tileready l l.pagex
l.pagey
5430 let x = l.pagedispx - l.pagex
5431 and y = l.pagedispy - l.pagey in
5433 match conf
.columns
with
5434 | Csingle
_ | Cmulti
_ ->
5435 (if conf
.hlinks
then 1 else 0)
5437 && not
(isbirdseye state
.mode) then 2 else 0)
5441 match state
.mode with
5442 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5448 Hashtbl.find_all state
.prects
l.pageno |>
5449 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5450 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5452 then (state
.redisplay
<- true; 0)
5458 let scrollindicator () =
5459 let sbw, ph
, sh = state
.uioh#
scrollph in
5460 let sbh, pw, sw = state
.uioh#scrollpw
in
5465 else ((state
.winw
- sbw), state
.winw
, 0)
5469 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5470 let (r
, g, b, alpha) = conf
.sbarcolor
in
5471 GlDraw.color (r
, g, b) ~
alpha;
5472 filledrect (float x0) 0. (float x1) (float state
.winh
);
5474 (float hx0
) (float (state
.winh
- sbh))
5475 (float (hx0
+ state
.winw
)) (float state
.winh
);
5476 let (r
, g, b, alpha) = conf
.sbarhndlcolor
in
5477 GlDraw.color (r
, g, b) ~
alpha;
5479 filledrect (float x0) ph
(float x1) (ph
+. sh);
5480 let pw = pw +. float hx0
in
5481 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5486 match state
.mstate
with
5487 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5490 | Msel
((x0, y0), (x1, y1)) ->
5491 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5492 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5493 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5494 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5501 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5502 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5504 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5506 if l.pageno = pageno
5508 let dx = float (l.pagedispx - l.pagex
) in
5509 let dy = float (l.pagedispy - l.pagey) in
5510 let r, g, b, alpha = c in
5511 GlDraw.color (r, g, b) ~
alpha;
5512 filledrect2 (x0+.dx) (y0+.dy)
5523 GlDraw.color (scalecolor2 conf
.bgcolor
);
5524 GlClear.color (scalecolor2 conf
.bgcolor
);
5525 GlClear.clear
[`
color];
5526 List.iter
drawpage state
.layout;
5528 match state
.mode with
5529 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5530 begin match getopaque pageno with
5532 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5533 let color = (0.0, 0.0, 0.5, 0.5) in
5535 (float x0, float y0,
5540 | None
-> state
.rects
5542 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5545 | View
-> state
.rects
5548 let rec postloop linkindexbase
= function
5550 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5551 postloop linkindexbase rest
5555 postloop 0 state
.layout;
5557 begin match state
.mstate
with
5558 | Mzoomrect
((x0, y0), (x1, y1)) ->
5560 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5561 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5562 filledrect (float x0) (float y0) (float x1) (float y1);
5566 | Mscrolly
| Mscrollx
5575 let zoomrect x y x1 y1 =
5578 and y0 = min
y y1 in
5579 let zoom = (float state
.w) /. float (x1 - x0) in
5582 if state
.w < state
.winw
5583 then (state
.winw
- state
.w) / 2
5586 match conf
.fitmodel
with
5587 | FitWidth
| FitProportional
-> simple ()
5589 match conf
.columns
with
5591 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5592 | Cmulti
_ | Csingle
_ -> simple ()
5594 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5595 state
.anchor <- getanchor
();
5600 let annot inline
x y =
5601 match unproject x y with
5602 | Some
(opaque, n, ux
, uy
) ->
5604 addannot
opaque ux uy
text;
5605 wcmd "freepage %s" (~
> opaque);
5606 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5608 gotoxy state
.x state
.y
5612 let ondone s = add s in
5613 let mode = state
.mode in
5614 state
.mode <- Textentry
(
5615 ("annotation: ", E.s, None
, textentry
, ondone, true),
5616 fun _ -> state
.mode <- mode);
5619 G.postRedisplay "annot"
5621 add @@ getusertext E.s
5626 let g opaque l px py =
5627 match rectofblock
opaque px py with
5629 let x0 = a.(0) -. 20. in
5630 let x1 = a.(1) +. 20. in
5631 let y0 = a.(2) -. 20. in
5632 let zoom = (float state
.w) /. (x1 -. x0) in
5633 let pagey = getpagey
l.pageno in
5634 let margin = (state
.w - l.pagew
)/2 in
5635 let nx = -truncate
x0 - margin in
5636 gotoxy_and_clear_text nx (pagey + truncate
y0);
5637 state
.anchor <- getanchor
();
5642 match conf
.columns
with
5644 impmsg "block zooming does not work properly in split columns mode"
5645 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5649 let winw = state
.winw - 1 in
5650 let s = float x /. float winw in
5651 let destx = truncate
(float (state
.w + winw) *. s) in
5652 gotoxy_and_clear_text (winw - destx) state
.y;
5653 state
.mstate
<- Mscrollx
;
5657 let s = float y /. float state
.winh
in
5658 let desty = truncate
(s *. float (maxy ())) in
5659 gotoxy_and_clear_text state
.x desty;
5660 state
.mstate
<- Mscrolly
;
5663 let viewmulticlick clicks
x y mask
=
5664 let g opaque l px py =
5672 if markunder
opaque px py mark
5676 match getopaque l.pageno with
5678 | Some
opaque -> pipesel opaque cmd
5680 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5681 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5686 G.postRedisplay "viewmulticlick";
5687 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5691 match conf
.columns
with
5693 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5696 let viewmouse button down
x y mask
=
5698 | n when (n == 4 || n == 5) && not down
->
5699 if Wsi.withctrl mask
5703 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5704 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5707 match state
.mstate
with
5708 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
5709 | Mzoomrect
_ | Mnone
| Mpan
_
5710 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
5712 let zoom = conf
.zoom -. incr in
5713 state
.mstate
<- Mzoom
(n, 0, (x, y));
5714 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
5715 then pivotzoom ~
x ~
y zoom
5719 match state
.autoscroll
with
5720 | Some step
-> setautoscrollspeed step
(n=4)
5722 if conf
.wheelbypage
|| conf
.presentation
5731 then -conf
.scrollstep
5732 else conf
.scrollstep
5734 let incr = incr * 2 in
5735 let y = clamp incr in
5736 gotoxy_and_clear_text state
.x y
5739 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5741 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5742 gotoxy_and_clear_text x state
.y
5744 | 1 when Wsi.withshift mask
->
5745 state
.mstate
<- Mnone
;
5748 match unproject x y with
5750 | Some
(_, pageno, ux
, uy
) ->
5751 let cmd = Printf.sprintf
5753 conf
.stcmd state
.path pageno ux uy
5755 match spawn
cmd [] with
5757 impmsg "execution of synctex command(%S) failed: %S"
5758 conf
.stcmd
@@ exntos exn
5762 | 1 when Wsi.withctrl mask
->
5765 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5766 state
.mstate
<- Mpan
(x, y)
5769 state
.mstate
<- Mnone
5774 if Wsi.withshift mask
5776 annot conf
.annotinline
x y;
5777 G.postRedisplay "addannot"
5781 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5782 state
.mstate
<- Mzoomrect
(p, p)
5785 match state
.mstate
with
5786 | Mzoomrect
((x0, y0), _) ->
5787 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5788 then zoomrect x0 y0 x y
5791 G.postRedisplay "kill accidental zoom rect";
5795 | Mscrolly
| Mscrollx
5797 | Mnone
-> resetmstate ()
5800 | 1 when vscrollhit x ->
5803 let _, position, sh = state
.uioh#
scrollph in
5804 if y > truncate
position && y < truncate
(position +. sh)
5805 then state
.mstate
<- Mscrolly
5808 state
.mstate
<- Mnone
5810 | 1 when y > state
.winh
- hscrollh () ->
5813 let _, position, sw = state
.uioh#scrollpw
in
5814 if x > truncate
position && x < truncate
(position +. sw)
5815 then state
.mstate
<- Mscrollx
5818 state
.mstate
<- Mnone
5820 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5823 let dest = if down
then getunder x y else Unone
in
5824 begin match dest with
5828 | Unone
when down
->
5829 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5830 state
.mstate
<- Mpan
(x, y);
5832 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5834 | Unone
| Utext
_ ->
5839 state
.mstate
<- Msel
((x, y), (x, y));
5840 G.postRedisplay "mouse select";
5844 match state
.mstate
with
5847 | Mzoom
_ | Mscrollx
| Mscrolly
->
5848 state
.mstate
<- Mnone
5850 | Mzoomrect
((x0, y0), _) ->
5854 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5855 state
.mstate
<- Mnone
5857 | Msel
((x0, y0), (x1, y1)) ->
5858 let rec loop = function
5862 let a0 = l.pagedispy in
5863 let a1 = a0 + l.pagevh in
5864 let b0 = l.pagedispx in
5865 let b1 = b0 + l.pagevw in
5866 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5867 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5871 match getopaque l.pageno with
5874 pipef ~closew
:false "Msel"
5877 G.postRedisplay "Msel") cmd
5879 dosel conf
.selcmd
();
5880 state
.roam
<- dosel conf
.paxcmd
;
5892 let birdseyemouse button down
x y mask
5893 (conf
, leftx
, _, hooverpageno
, anchor) =
5896 let rec loop = function
5899 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5900 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5902 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5908 | _ -> viewmouse button down
x y mask
5914 method key key mask
=
5915 begin match state
.mode with
5916 | Textentry textentry
-> textentrykeyboard
key mask textentry
5917 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5918 | View
-> viewkeyboard key mask
5919 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5923 method button button bstate
x y mask
=
5924 begin match state
.mode with
5925 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5926 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5931 method multiclick clicks
x y mask
=
5932 begin match state
.mode with
5933 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5934 | Birdseye
_ | Textentry
_ -> ()
5939 begin match state
.mode with
5941 | View
| Birdseye
_ | LinkNav
_ ->
5942 match state
.mstate
with
5943 | Mzoom
_ | Mnone
-> ()
5948 state
.mstate
<- Mpan
(x, y);
5949 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5951 gotoxy_and_clear_text x y
5954 state
.mstate
<- Msel
(a, (x, y));
5955 G.postRedisplay "motion select";
5958 let y = min state
.winh
(max
0 y) in
5962 let x = min state
.winw (max
0 x) in
5965 | Mzoomrect
(p0
, _) ->
5966 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5967 G.postRedisplay "motion zoomrect";
5971 method pmotion
x y =
5972 begin match state
.mode with
5973 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
5974 let rec loop = function
5976 if hooverpageno
!= -1
5978 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
5979 G.postRedisplay "pmotion birdseye no hoover";
5982 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5983 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5985 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
5986 G.postRedisplay "pmotion birdseye hoover";
5994 | LinkNav
_ | View
->
5995 match state
.mstate
with
5996 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6005 let delta = now -. past
in
6008 else conf
.pax
<- Some
now
6012 method infochanged
_ = ()
6015 let maxy = maxy () in
6018 then 0.0, float state
.winh
6019 else scrollph state
.y maxy
6024 let fwinw = float (state
.winw - vscrollw ()) in
6026 let sw = fwinw /. float state
.w in
6027 let sw = fwinw *. sw in
6028 max
sw (float conf
.scrollh
)
6031 let maxx = state
.w + state
.winw in
6032 let x = state
.winw - state
.x in
6033 let percent = float x /. float maxx in
6034 (fwinw -. sw) *. percent
6036 hscrollh (), position, sw
6040 match state
.mode with
6041 | LinkNav
_ -> "links"
6042 | Textentry
_ -> "textentry"
6043 | Birdseye
_ -> "birdseye"
6046 findkeyhash conf
modename
6048 method eformsgs
= true
6049 method alwaysscrolly
= false
6050 method scroll dx dy =
6051 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6052 gotoxy_and_clear_text x (clamp (2 * dy));
6055 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
6058 let addrect pageno r g b a x0 y0 x1 y1 =
6059 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6063 let cl = splitatchar cmds ' '
in
6065 try Scanf.sscanf
s fmt
f
6066 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6069 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6070 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6071 s pageno r g b a x0 y0 x1 y1;
6075 let _,w1,h1
,_ = getpagedim
pageno in
6076 let sw = float w1 /. float w
6077 and sh = float h1
/. float h in
6081 and y1s
= y1 *. sh in
6082 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6083 let color = (r, g, b, a) in
6084 if conf
.verbose
then debugrect rect;
6085 state
.rects <- (pageno, color, rect) :: state
.rects;
6090 | "reload", "" -> reload ()
6092 scan args
"%u %f %f"
6094 let cmd, _ = state
.geomcmds
in
6096 then gotopagexy pageno x y
6099 gotopagexy pageno x y;
6102 state
.reprf
<- f state
.reprf
6104 | "goto1", args
-> scan args
"%u %f" gotopage
6105 | "gotor", args
-> scan args
"%S" gotoremote
6107 scan args
"%u %u %f %f %f %f"
6108 (fun pageno c x0 y0 x1 y1 ->
6109 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6110 rectx "rect" pageno color x0 y0 x1 y1;
6113 scan args
"%u %f %f %f %f %f %f %f %f"
6114 (fun pageno r g b alpha x0 y0 x1 y1 ->
6115 addrect pageno r g b alpha x0 y0 x1 y1;
6116 G.postRedisplay "prect"
6119 scan args
"%u %f %f"
6122 match getopaque pageno with
6123 | Some
opaque -> opaque
6126 pgoto optopaque pageno x y;
6127 let rec fixx = function
6130 if l.pageno = pageno
6131 then gotoxy (state
.x - l.pagedispx) state
.y
6136 match conf
.columns
with
6137 | Csingle
_ | Csplit
_ -> 1
6138 | Cmulti
((n, _, _), _) -> n
6140 layout 0 state
.y (state
.winw * mult) state
.winh
6144 | "activatewin", "" -> Wsi.activatewin
()
6145 | "quit", "" -> raise Quit
6148 let l = Config.keys_of_string
keys in
6149 List.iter
(fun (k
, m) -> keyboard k
m) l
6150 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6153 | "clearrects", "" ->
6154 Hashtbl.clear state
.prects
;
6155 G.postRedisplay "clearrects"
6157 adderrfmt "remote command"
6158 "error processing remote command: %S\n" cmds
;
6162 let scratch = Bytes.create
80 in
6163 let buf = Buffer.create
80 in
6165 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6166 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6169 if Buffer.length
buf > 0
6171 let s = Buffer.contents
buf in
6179 match Bytes.index_from
scratch ppos '
\n'
with
6180 | pos
-> if pos
>= n then -1 else pos
6181 | exception Not_found
-> -1
6185 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6186 let s = Buffer.contents
buf in
6192 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6198 let remoteopen path =
6199 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6201 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6206 let gcconfig = ref false in
6207 let trimcachepath = ref E.s in
6208 let rcmdpath = ref E.s in
6209 let pageno = ref None
in
6210 let rootwid = ref 0 in
6211 let openlast = ref false in
6212 let doreap = ref false in
6213 let csspath = ref None
in
6214 selfexec := Sys.executable_name
;
6217 [("-p", Arg.String
(fun s -> state
.password <- s),
6218 "<password> Set password");
6222 Config.fontpath
:= s;
6223 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6225 "<path> Set path to the user interface font");
6229 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6230 Config.confpath
:= s),
6231 "<path> Set path to the configuration file");
6233 ("-last", Arg.Set
openlast, " Open last document");
6235 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6236 "<page-number> Jump to page");
6238 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6239 "<path> Set path to the trim cache file");
6241 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6242 "<named-destination> Set named destination");
6244 ("-cxack", Arg.Set
cxack, " Cut corners");
6246 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6247 "<path> Set path to the source of remote commands");
6249 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
6251 ("-v", Arg.Unit
(fun () ->
6253 "%s\nconfiguration path: %s\n"
6256 exit
0), " Print version and exit");
6258 ("-css", Arg.String
(fun s -> csspath := Some
s),
6259 "<path> Set path to the style sheet to use with EPUB/HTML");
6261 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6263 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6264 "<origin> <undocumented>");
6266 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title")
6269 (fun s -> state
.path <- s)
6270 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6272 let histmode = emptystr state
.path && not
!openlast in
6274 if not
(Config.load !openlast)
6275 then dolog
"failed to load configuration";
6277 begin match !pageno with
6278 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6291 val mutable m_clicks
= 0
6292 val mutable m_click_x
= 0
6293 val mutable m_click_y
= 0
6294 val mutable m_lastclicktime
= infinity
6296 method private cleanup =
6297 state
.roam
<- noroam
;
6298 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6299 method expose
= G.postRedisplay "expose"
6303 | Wsi.Unobscured
-> "unobscured"
6304 | Wsi.PartiallyObscured
-> "partiallyobscured"
6305 | Wsi.FullyObscured
-> "fullyobscured"
6307 vlog "visibility change %s" name
6308 method display = display ()
6309 method map mapped
= vlog "mapped %b" mapped
6310 method reshape w h =
6313 method mouse
b d x y m =
6314 if d && canselect ()
6317 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6324 if abs
x - m_click_x
> 10
6325 || abs
y - m_click_y
> 10
6326 || abs_float
(t -. m_lastclicktime
) > 0.3
6328 m_clicks
<- m_clicks
+ 1;
6329 m_lastclicktime
<- t;
6333 G.postRedisplay "cleanup";
6334 state
.uioh <- state
.uioh#button
b d x y m;
6336 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6341 m_lastclicktime
<- infinity
;
6342 state
.uioh <- state
.uioh#button
b d x y m
6346 state
.uioh <- state
.uioh#button
b d x y m
6349 state
.mpos
<- (x, y);
6350 state
.uioh <- state
.uioh#motion
x y
6351 method pmotion
x y =
6352 state
.mpos
<- (x, y);
6353 state
.uioh <- state
.uioh#pmotion
x y
6355 vlog "k=%#x m=%#x" k
m;
6356 let mascm = m land (
6357 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6360 let x = state
.x and y = state
.y in
6362 if x != state
.x || y != state
.y then self#
cleanup
6364 match state
.keystate
with
6366 let km = k
, mascm in
6369 let modehash = state
.uioh#
modehash in
6370 try Hashtbl.find modehash km
6372 try Hashtbl.find (findkeyhash conf
"global") km
6373 with Not_found
-> KMinsrt
(k
, m)
6375 | KMinsrt
(k
, m) -> keyboard k
m
6376 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6377 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6379 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6380 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6381 state
.keystate
<- KSnone
6382 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6383 state
.keystate
<- KSinto
(keys, insrt
)
6384 | KSinto
_ -> state
.keystate
<- KSnone
6387 state
.mpos
<- (x, y);
6388 state
.uioh <- state
.uioh#pmotion
x y
6389 method leave = state
.mpos
<- (-1, -1)
6390 method winstate wsl
= state
.winstate
<- wsl
6391 method quit
: '
a. '
a = raise Quit
6392 method scroll dx dy = state
.uioh <- state
.uioh#
scroll dx dy
6393 method zoom z
x y = state
.uioh#
zoom z
x y
6394 method opendoc path =
6397 G.postRedisplay "opendoc";
6398 opendoc path state
.password
6401 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6404 if not
@@ List.exists
GlMisc.check_extension
6405 [ "GL_ARB_texture_rectangle"
6406 ; "GL_EXT_texture_recangle"
6407 ; "GL_NV_texture_rectangle" ]
6408 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6410 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6412 defconf
.sliceheight
<- 1024;
6413 defconf
.texcount
<- 32;
6414 defconf
.usepbo
<- true;
6418 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6420 dolog
"socketpair failed: %s" @@ exntos exn
;
6428 setcheckers conf
.checkers
;
6430 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6432 begin match !csspath with
6434 | Some
"" -> conf
.css
<- E.s
6436 let css = filecontents
path in
6437 let l = String.length
css in
6439 if substratis
css (l-2) "\r\n"
6440 then String.sub css 0 (l-2)
6441 else (if css.[l-1] = '
\n'
6442 then String.sub css 0 (l-1)
6446 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6447 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6448 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6450 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6452 reshape ~firsttime
:true winw winh
;
6456 Wsi.settitle
"llpp (history)";
6460 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6461 opendoc state
.path state
.password;
6465 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6466 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6469 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6470 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6471 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6473 | _pid
, _status
-> reap ()
6475 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6479 if nonemptystr
!rcmdpath
6480 then remoteopen !rcmdpath
6485 let rec loop deadline
=
6491 let r = [state
.ss; state
.wsfd] in
6495 | Some fd
-> fd
:: r
6499 state
.redisplay
<- false;
6506 if deadline
= infinity
6508 else max
0.0 (deadline
-. now)
6513 try Unix.select
r [] [] timeout
6514 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6520 if state
.ghyll
== noghyll
6522 match state
.autoscroll
with
6523 | Some step
when step
!= 0 ->
6524 if state
.slideshow
land 1 = 1
6526 if state
.slideshow
land 2 = 0
6527 then state
.slideshow
<- state
.slideshow
lor 2
6528 else if step
< 0 then prevpage () else nextpage ();
6529 deadline
+. (float (abs step
))
6532 let y = state
.y + step
in
6533 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6536 then state
.maxy - fy
6537 else if y >= state
.maxy - fy then 0 else y
6539 if state
.mode = View
6540 then gotoxy_and_clear_text state
.x y
6541 else gotoxy state
.x y;
6544 else deadline
+. 0.01
6549 let rec checkfds = function
6551 | fd
:: rest
when fd
= state
.ss ->
6552 let cmd = rcmd state
.ss in
6556 | fd
:: rest
when fd
= state
.wsfd ->
6560 | fd
:: rest
when Some fd
= !optrfd ->
6561 begin match remote fd
with
6562 | None
-> optrfd := remoteopen !rcmdpath;
6563 | opt -> optrfd := opt
6568 dolog
"select returned unknown descriptor";
6574 if deadline
= infinity
6578 match state
.autoscroll
with
6579 | Some step
when step
!= 0 -> deadline1
6580 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6585 match loop infinity
with
6587 Config.save leavebirdseye;
6588 if hasunsavedchanges
()
6590 | _ -> error
"umpossible - infinity reached"