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 opengl_has_pbo = ref false;;
62 let drawstring size x y s
=
64 Gl.enable `texture_2d
;
65 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
66 ignore
(drawstr size x y s
);
68 Gl.disable `texture_2d
;
71 let drawstring1 size x y s
=
75 let drawstring2 size x y fmt
=
76 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
79 module UniSyms
= struct
80 let ellipsis = "\xe2\x80\xa6";;
81 let radical = "\xe2\x88\x9a";;
82 let lguillemet = "\xc2\xab";;
83 let rguillemet = "\xc2\xbb";;
98 l
.pagedispx l
.pagedispy
102 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
108 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
111 let isbirdseye = function
113 | Textentry _
| View
| LinkNav _
-> false
116 let istextentry = function
117 | Textentry _
-> true
118 | Birdseye _
| View
| LinkNav _
-> false
121 let wtmode = ref 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 if not
!wtmode || layoutready layout
836 then G.postRedisplay "gotoxy ready";
843 state
.layout <- layout;
844 begin match state
.mode
with
847 | Ltexact
(pageno
, linkno
) ->
848 let rec loop = function
850 state
.lnava
<- Some
(pageno
, linkno
);
851 state
.mode
<- LinkNav
(Ltgendir
0)
852 | l :: _
when l.pageno
= pageno
->
853 begin match getopaque pageno
with
854 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
856 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
857 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
858 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
859 then state
.mode
<- LinkNav
(Ltgendir
0)
861 | _
:: rest
-> loop rest
864 | Ltnotready _
| Ltgendir _
-> ()
866 | Birdseye _
| Textentry _
| View
-> ()
868 begin match state
.mode
with
869 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
870 if not
(pagevisible layout pageno
)
872 match state
.layout with
875 state
.mode
<- Birdseye
(
876 conf
, leftx
, l.pageno
, hooverpageno
, anchor
881 | Ltnotready
(_
, dir
)
884 let rec loop = function
887 match getopaque l.pageno
with
888 | None
-> Ltnotready
(l.pageno
, dir
)
893 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
895 if dir
> 0 then LDfirst
else LDlast
901 | Lnotfound
-> loop rest
903 showlinktype (getlink opaque
n);
904 Ltexact
(l.pageno
, n)
908 state
.mode
<- LinkNav
linknav
911 | Textentry _
| View
-> ()
915 state
.ghyll
<- noghyll
;
918 let mx, my
= state
.mpos
in
923 let conttiling pageno opaque
=
924 tilepage pageno opaque
926 then preloadlayout state
.x state
.y state
.winw state
.winh
930 let gotoxy_and_clear_text x y =
931 if not conf
.verbose
then state
.text <- E.s;
935 let getanchory (n, top
, dtop
) =
936 let y, h = getpageyh
n in
939 let ips = calcips
h in
940 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
942 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
945 let gotoanchor anchor
=
946 gotoxy state
.x (getanchory anchor
);
950 cbput state
.hists
.nav
(getanchor
());
954 let anchor = cbgetc state
.hists
.nav dir
in
958 let gotoghyll1 single
y =
960 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
962 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
964 then s (float f /. float a
)
967 then 1.0 -. s ((float (f-b) /. float (n-b)))
973 let ins = float a
*. 0.5
974 and outs
= float (n-b) *. 0.5 in
976 ins +. outs
+. float ones
978 let rec set nab
y sy
=
979 let (_N
, _A
, _B
), y =
982 let scl = if y > sy
then 2 else -2 in
983 let _N, _
, _
= nab
in
984 (_N,0,_N), y+conf
.scrollstep
*scl
986 let sum = summa
_N _A _B
in
987 let dy = float (y - sy
) in
991 then state
.ghyll
<- noghyll
994 let s = scroll n _N _A _B
in
995 let y1 = y1 +. ((s *. dy) /. sum) in
996 gotoxy_and_clear_text state
.x (truncate
y1);
997 state
.ghyll
<- gf (n+1) y1;
1001 | Some
y'
when single
-> set nab
y' state
.y
1002 | Some
y'
-> set (_N/2, 1, 1) y' state
.y
1004 gf 0 (float state
.y)
1007 match conf
.ghyllscroll
with
1008 | Some nab
when not conf
.presentation
->
1009 if state
.ghyll
== noghyll
1010 then set nab
y state
.y
1011 else state
.ghyll
(Some
y)
1013 gotoxy_and_clear_text state
.x y
1016 let gotoghyll = gotoghyll1 false;;
1018 let gotopage n top
=
1019 let y, h = getpageyh
n in
1020 let y = y + (truncate
(top
*. float h)) in
1024 let gotopage1 n top
=
1025 let y = getpagey
n in
1030 let invalidate ?
(redisplay
=false) s f =
1031 state
.redisplay
<- redisplay
;
1036 match state
.geomcmds
with
1037 | ps
, [] when emptystr ps
->
1039 state
.geomcmds
<- s, [];
1042 state
.geomcmds
<- ps
, [s, f];
1044 | ps
, (s'
, _
) :: rest
when s'
= s ->
1045 state
.geomcmds
<- ps
, ((s, f) :: rest
);
1048 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
1052 Hashtbl.iter
(fun _ opaque
->
1053 wcmd "freepage %s" (~
> opaque
);
1055 Hashtbl.clear state
.pagemap
;
1059 if not
(Queue.is_empty state
.tilelru
)
1061 Queue.iter
(fun (k
, p
, s) ->
1062 wcmd "freetile %s" (~
> p
);
1063 state
.memused
<- state
.memused
- s;
1064 Hashtbl.remove state
.tilemap k
;
1066 state
.uioh#infochanged Memused
;
1067 Queue.clear state
.tilelru
;
1073 let h = truncate
(float h*.conf
.zoom
) in
1074 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
1078 let opendoc path password
=
1080 state
.password
<- password
;
1081 state
.gen
<- state
.gen
+ 1;
1082 state
.docinfo
<- [];
1083 state
.outlines
<- [||];
1086 setaalevel conf
.aalevel
;
1088 if emptystr state
.origin
1092 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1093 wcmd "open %d %d %d %s\000%s\000%s\000"
1094 (btod
!wtmode) (btod
!cxack) (btod conf
.usedoccss
)
1095 path password conf
.css
;
1096 invalidate "reqlayout"
1098 wcmd "reqlayout %d %d %d %s\000"
1099 conf
.angle
(FMTE.to_int conf
.fitmodel
)
1100 (stateh state
.winh
) state
.nameddest
1103 let sl = keystostrlist conf
in
1105 function | [] -> accu
1106 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
1107 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
1111 state
.anchor <- getanchor
();
1112 opendoc state
.path state
.password
;
1116 let c = c *. conf
.colorscale
in
1120 let scalecolor2 (r
, g, b) =
1121 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
1124 let docolumns columns
=
1127 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1128 let rec loop pageno
pdimno pdim
y ph pdims
=
1129 if pageno
= state
.pagecount
1132 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1134 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1135 pdimno+1, pdim
, rest
1139 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
1141 y + (if conf
.presentation
1142 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
1143 else (if pageno
= 0 then 0 else conf
.interpagespace
)
1146 a.(pageno
) <- (pdimno, x, y, pdim
);
1147 loop (pageno
+1) pdimno pdim
(y + h) h pdims
1149 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
1150 conf
.columns
<- Csingle
a;
1152 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1153 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1154 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1156 if m
= pageno
then () else
1157 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1160 let y = y + (rowh
- h) / 2 in
1161 a.(m
) <- (pdimno, x, y, pdim
);
1165 if pageno
= state
.pagecount
1166 then fixrow (((pageno
- 1) / columns
) * columns
)
1168 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1170 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1171 pdimno+1, pdim
, rest
1176 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1178 let x = (state
.winw
- w) / 2 in
1180 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1181 x, y + ips + rowh
, h
1184 if (pageno
- coverA
) mod columns
= 0
1186 let x = max
0 (state
.winw
- state
.w) / 2 in
1188 if conf
.presentation
1190 let ips = calcips
h in
1191 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1193 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1197 else x, y, max rowh
h
1201 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1204 if pageno
= columns
&& conf
.presentation
1206 let ips = calcips rowh
in
1207 for i
= 0 to pred columns
1209 let (pdimno, x, y, pdim
) = a.(i
) in
1210 a.(i
) <- (pdimno, x, y+ips, pdim
)
1216 fixrow (pageno
- columns
);
1221 a.(pageno
) <- (pdimno, x, y, pdim
);
1222 let x = x + w + xoff
*2 + conf
.interpagespace
in
1223 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1225 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1226 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1229 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1230 let rec loop pageno
pdimno pdim
y pdims
=
1231 if pageno
= state
.pagecount
1234 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1236 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1237 pdimno+1, pdim
, rest
1242 let rec loop1 n x y =
1243 if n = c then y else (
1244 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1245 loop1 (n+1) (x+cw) (y + h + conf
.interpagespace
)
1248 let y = loop1 0 0 y in
1249 loop (pageno
+1) pdimno pdim
y pdims
1251 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1252 conf
.columns
<- Csplit
(c, a);
1256 docolumns conf
.columns
;
1257 state
.maxy <- calcheight
();
1258 if state
.reprf
== noreprf
1260 match state
.mode
with
1261 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1262 let y, h = getpageyh pageno
in
1263 let top = (state
.winh
- h) / 2 in
1264 gotoxy state
.x (max
0 (y - top))
1265 | Textentry _
| View
| LinkNav _
->
1266 let y = getanchory state
.anchor in
1267 let y = min
y (state
.maxy - state
.winh
) in
1272 state
.reprf
<- noreprf
;
1276 let reshape ?
(firsttime
=false) w h =
1277 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1278 if not firsttime
&& nogeomcmds state
.geomcmds
1279 then state
.anchor <- getanchor
();
1282 let w = truncate
(float w *. conf
.zoom
) in
1285 setfontsize fstate
.fontsize
;
1286 GlMat.mode `modelview
;
1287 GlMat.load_identity
();
1289 GlMat.mode `projection
;
1290 GlMat.load_identity
();
1291 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1292 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1293 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1298 else float state
.x /. float state
.w
1300 invalidate ~redisplay
:true "geometry"
1304 then state
.x <- truncate
(relx *. float w);
1306 match conf
.columns
with
1308 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1309 | Csplit
(c, _
) -> w * c
1311 wcmd "geometry %d %d %d"
1312 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1317 let len = String.length state
.text in
1318 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1321 match state
.mode
with
1322 | Textentry _
| View
| LinkNav _
->
1323 let h, _
, _
= state
.uioh#scrollpw
in
1329 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1330 (x+.w) (float (state
.winh
- hscrollh))
1333 let w = float (state
.winw
- 1 - vscrollw ()) in
1334 if state
.progress
>= 0.0 && state
.progress
< 1.0
1336 GlDraw.color (0.3, 0.3, 0.3);
1337 let w1 = w *. state
.progress
in
1339 GlDraw.color (0.0, 0.0, 0.0);
1340 rect (float x0+.w1) (float x0+.w-.w1)
1343 GlDraw.color (0.0, 0.0, 0.0);
1347 GlDraw.color (1.0, 1.0, 1.0);
1350 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1351 (state
.winh
- hscrollh - 5) s;
1354 match state
.mode
with
1355 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1358 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1359 else Printf.sprintf
"%s%s_" prefix
text
1363 | Birdseye _
| View
| LinkNav _
-> state
.text
1368 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1370 let s1 = "(press 'e' to review error messasges)" in
1371 if nonemptystr
s then s ^
" " ^
s1 else s1
1381 let len = Queue.length state
.tilelru
in
1383 match state
.throttle
with
1386 then preloadlayout state
.x state
.y state
.winw state
.winh
1388 | Some
(layout, _
, _
) ->
1392 if state
.memused
> conf
.memlimit
1396 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1397 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1398 let (_
, pw, ph
, _
) = getpagedim
n in
1400 && colorspace
= conf
.colorspace
1401 && angle
= conf
.angle
1405 let x = col*conf
.tilew
1406 and y = row*conf
.tileh
in
1407 tilevisible (Lazy.force_val
layout) n x y
1409 then Queue.push lruitem state
.tilelru
1412 wcmd "freetile %s" (~
> p
);
1413 state
.memused
<- state
.memused
- s;
1414 state
.uioh#infochanged Memused
;
1415 Hashtbl.remove state
.tilemap k
;
1423 let onpagerect pageno
f =
1425 match conf
.columns
with
1426 | Cmulti
(_
, b) -> b
1428 | Csplit
(_
, b) -> b
1430 if pageno
>= 0 && pageno
< Array.length
b
1432 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1436 let gotopagexy1 wtmode pageno
x y =
1437 let _,w1,h1
,leftx
= getpagedim pageno
in
1438 let top = y /. (float h1
) in
1439 let left = x /. (float w1) in
1440 let py, w, h = getpageywh pageno
in
1441 let wh = state
.winh
in
1442 let x = left *. (float w) in
1443 let x = leftx
+ state
.x + truncate
x in
1445 if x < 0 || x >= state
.winw
1449 let pdy = truncate
(top *. float h) in
1450 let y'
= py + pdy in
1451 let dy = y'
- state
.y in
1453 if x != state
.x || not
(dy > 0 && dy < wh)
1455 if conf
.presentation
1457 if abs
(py - y'
) > wh
1464 if state
.x != sx || state
.y != sy
1469 let ww = state
.winw
in
1471 and qy
= pdy / wh in
1473 and y = py + qy
* wh in
1474 let x = if -x + ww > w1 then -(w1-ww) else x
1475 and y'
= if y + wh > state
.maxy then state
.maxy - wh else y in
1477 if conf
.presentation
1479 if abs
(py - y'
) > wh
1488 gotoxy_and_clear_text x y;
1490 else gotoxy_and_clear_text state
.x state
.y;
1493 let gotopagexy wtmode pageno
x y =
1494 match state
.mode
with
1495 | Birdseye
_ -> gotopage pageno
0.0
1496 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 wtmode pageno
x y
1499 let getpassword () =
1500 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1505 impmsg "error getting password: %s" s;
1506 dolog
"%s" s) passcmd;
1509 let pgoto opaque pageno
x y =
1510 let pdimno = getpdimno pageno
in
1511 let x, y = project opaque pageno
pdimno x y in
1512 gotopagexy false pageno
x y;
1516 (* dolog "%S" cmds; *)
1517 let spl = splitatchar cmds ' '
in
1519 try Scanf.sscanf
s fmt
f
1521 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1524 let addoutline outline
=
1525 match state
.currently
with
1526 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1527 | Idle
-> state
.currently
<- Outlining
[outline
]
1528 | Loading
_ | Tiling
_ ->
1529 dolog
"invalid outlining state";
1530 logcurrently state
.currently
1535 state
.uioh#infochanged Pdim
;
1537 | "clearrects", "" ->
1538 state
.rects
<- state
.rects1
;
1539 G.postRedisplay "clearrects";
1541 | "continue", args
->
1542 let n = scan args
"%u" (fun n -> n) in
1543 state
.pagecount
<- n;
1544 begin match state
.currently
with
1546 state
.currently
<- Idle
;
1547 state
.outlines
<- Array.of_list
(List.rev
l)
1548 | Idle
| Loading
_ | Tiling
_ -> ()
1551 let cur, cmds
= state
.geomcmds
in
1553 then failwith
"umpossible";
1555 begin match List.rev cmds
with
1557 state
.geomcmds
<- E.s, [];
1558 state
.throttle
<- None
;
1562 state
.geomcmds
<- s, List.rev rest
;
1564 if conf
.maxwait
= None
&& not
!wtmode
1565 then G.postRedisplay "continue";
1572 then showtext ' ' args
1575 Buffer.add_string state
.errmsgs args
;
1576 state
.newerrmsgs
<- true;
1577 G.postRedisplay "error message"
1579 | "progress", args
->
1580 let progress, text =
1583 f, String.sub args pos
(String.length args
- pos
))
1586 state
.progress <- progress;
1587 G.postRedisplay "progress"
1589 | "firstmatch", args
->
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 y = (getpagey
pageno) + truncate
y0 in
1603 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1604 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1607 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1608 scan args
"%u %d %f %f %f %f %f %f %f %f"
1609 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1610 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1612 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1614 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1617 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1618 let pageopaque = ~
< pageopaques in
1619 begin match state
.currently
with
1620 | Loading
(l, gen
) ->
1621 vlog "page %d took %f sec" l.pageno t
;
1622 Hashtbl.replace state
.pagemap
(l.pageno, gen
) pageopaque;
1623 begin match state
.throttle
with
1625 let preloadedpages =
1627 then preloadlayout state
.x state
.y state
.winw state
.winh
1632 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1633 IntSet.empty
preloadedpages
1636 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1637 if not
(IntSet.mem
pageno set)
1639 wcmd "freepage %s" (~
> opaque
);
1645 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1648 state
.currently
<- Idle
;
1651 tilepage l.pageno pageopaque state
.layout;
1653 load preloadedpages;
1654 let visible = pagevisible state
.layout l.pageno in
1657 match state
.mode
with
1658 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1659 if pageno = l.pageno
1664 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1666 if dir
> 0 then LDfirst
else LDlast
1669 findlink
pageopaque ld
1674 showlinktype (getlink
pageopaque n);
1675 state
.mode
<- LinkNav
(Ltexact
(l.pageno, n))
1677 | LinkNav
(Ltgendir
_)
1678 | LinkNav
(Ltexact
_)
1684 if visible && layoutready state
.layout
1686 G.postRedisplay "page";
1690 | Some
(layout, _, _) ->
1691 state
.currently
<- Idle
;
1692 tilepage l.pageno pageopaque layout;
1696 | Idle
| Tiling
_ | Outlining
_ ->
1697 dolog
"Inconsistent loading state";
1698 logcurrently state
.currently
;
1703 let (x, y, opaques
, size
, t
) =
1704 scan args
"%u %u %s %u %f"
1705 (fun x y p size t
-> (x, y, p
, size
, t
))
1707 let opaque = ~
< opaques
in
1708 begin match state
.currently
with
1709 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1710 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1713 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1715 wcmd "freetile %s" (~
> opaque);
1716 state
.currently
<- Idle
;
1720 puttileopaque l col row gen cs angle
opaque size t
;
1721 state
.memused
<- state
.memused
+ size
;
1722 state
.uioh#infochanged Memused
;
1724 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1725 opaque, size
) state
.tilelru
;
1728 match state
.throttle
with
1729 | None
-> state
.layout
1730 | Some
(layout, _, _) -> layout
1733 state
.currently
<- Idle
;
1735 && conf
.colorspace
= cs
1736 && conf
.angle
= angle
1737 && tilevisible layout l.pageno x y
1738 then conttiling l.pageno pageopaque;
1740 begin match state
.throttle
with
1742 preload state
.layout;
1744 && conf
.colorspace
= cs
1745 && conf
.angle
= angle
1746 && tilevisible state
.layout l.pageno x y
1747 && (not
!wtmode || layoutready state
.layout)
1748 then G.postRedisplay "tile nothrottle";
1750 | Some
(layout, y, _) ->
1751 let ready = layoutready layout in
1755 state
.layout <- layout;
1756 state
.throttle
<- None
;
1757 G.postRedisplay "throttle";
1763 | Idle
| Loading
_ | Outlining
_ ->
1764 dolog
"Inconsistent tiling state";
1765 logcurrently state
.currently
;
1770 let (n, w, h, _) as pdim
=
1771 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1774 match conf
.fitmodel
with
1776 | FitPage
| FitProportional
->
1777 match conf
.columns
with
1778 | Csplit
_ -> (n, w, h, 0)
1779 | Csingle
_ | Cmulti
_ -> pdim
1781 state
.pdims
<- pdim :: state
.pdims
;
1782 state
.uioh#infochanged Pdim
1785 let (l, n, t
, h, pos
) =
1786 scan args
"%u %u %d %u %n"
1787 (fun l n t
h pos
-> l, n, t
, h, pos
)
1789 let s = String.sub args pos
(String.length args
- pos
) in
1790 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
1793 let (l, len, pos
) = scan args
"%u %u %n" (fun l len pos
-> l, len, pos
) in
1794 let s = String.sub args pos
len in
1795 let pos2 = pos
+ len + 1 in
1796 let uri = String.sub args
pos2 (String.length args
- pos2) in
1797 addoutline (s, l, Ouri
uri)
1800 let (l, pos
) = scan args
"%u %n" (fun l pos
-> l, pos
) in
1801 let s = String.sub args pos
(String.length args
- pos
) in
1802 addoutline (s, l, Onone
)
1806 scan args
"%u %d %d" (fun n l t
-> n, l, t
)
1808 state
.reprf
<- (fun () -> gotopagexy !wtmode n (float l) (float t
))
1811 let c, v
= splitatchar args '
\t'
in
1822 if let len = String.length
c in
1823 len > 6 && ((String.sub
c (len-4) 4) = "date")
1825 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1827 let b = Buffer.create
10 in
1828 Printf.bprintf
b "%s\t" c;
1831 Buffer.add_substring
b v p
l;
1832 Buffer.add_char
b c;
1833 with exn
-> Buffer.add_string
b @@ exntos exn
1841 Buffer.add_char
b '
['
;
1842 Buffer.add_string
b v
;
1843 Buffer.add_char
b '
]'
;
1850 state
.docinfo
<- (1, s) :: state
.docinfo
1853 state
.docinfo
<- List.rev state
.docinfo
;
1854 state
.uioh#infochanged Docinfo
1858 then Wsi.settitle
"Wrong password";
1859 let password = getpassword () in
1860 if emptystr
password
1861 then error
"document is password protected"
1862 else opendoc state
.path
password
1865 error
"unknown cmd `%S'" cmds
1870 let action = function
1871 | HCprev
-> cbget cb ~
-1
1872 | HCnext
-> cbget cb
1
1873 | HCfirst
-> cbget cb ~
-(cb
.rc)
1874 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1875 and cancel
() = cb
.rc <- rc
1879 let search pattern forward
=
1880 match conf
.columns
with
1881 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1882 | Csingle
_ | Cmulti
_ ->
1883 if nonemptystr pattern
1886 match state
.layout with
1889 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1891 wcmd "search %d %d %d %d,%s\000"
1892 (btod conf
.icase
) pn py (btod forward
) pattern
;
1895 let [@warning
"-4"] intentry
text key =
1897 if emptystr
text && key = Keys.Ascii '
-'
1898 then addchar
text '
-'
1901 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1903 state
.text <- "invalid key";
1913 let l = String.length
s in
1914 let rec loop pos
n =
1918 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1919 loop (pos
+1) (n*26 + m)
1922 let rec loop n = function
1925 match getopaque l.pageno with
1926 | None
-> loop n rest
1928 let m = getlinkcount
opaque in
1931 let under = getlink
opaque n in
1934 else loop (n-m) rest
1936 loop n state
.layout;
1940 let [@warning
"-4"] linknentry
text = function
1942 let text = addchar
text c in
1943 linknact (fun under -> state
.text <- undertext under) text;
1946 state
.text <- Printf.sprintf
"invalid key";
1950 let [@warning
"-4"] textentry
text = function
1951 | Keys.Ascii
c -> TEcont
(addchar
text c)
1952 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1956 let reqlayout angle fitmodel
=
1957 match state
.throttle
with
1959 if nogeomcmds state
.geomcmds
1960 then state
.anchor <- getanchor
();
1961 conf
.angle
<- angle
mod 360;
1964 match state
.mode
with
1965 | LinkNav
_ -> state
.mode
<- View
1966 | Birdseye
_ | Textentry
_ | View
-> ()
1968 conf
.fitmodel
<- fitmodel
;
1972 wcmd "reqlayout %d %d %d"
1973 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1978 let settrim trimmargins trimfuzz
=
1979 if nogeomcmds state
.geomcmds
1980 then state
.anchor <- getanchor
();
1981 conf
.trimmargins
<- trimmargins
;
1982 conf
.trimfuzz
<- trimfuzz
;
1983 let x0, y0, x1, y1 = trimfuzz
in
1985 "settrim" (fun () ->
1986 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1991 match state
.throttle
with
1993 let zoom = max
0.0001 zoom in
1994 if zoom <> conf
.zoom
1996 state
.prevzoom
<- (conf
.zoom, state
.x);
1998 reshape state
.winw state
.winh
;
1999 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2002 | Some
(layout, y, started
) ->
2004 match conf
.maxwait
with
2008 let dt = now
() -. started
in
2016 let pivotzoom ?
(vw=min state
.w state
.winw
)
2017 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
2018 ?
(x=vw/2) ?
(y=vh
/2) zoom =
2019 let w = float state
.w /. zoom in
2020 let hw = w /. 2.0 in
2021 let ratio = float vh
/. float vw in
2022 let hh = hw *. ratio in
2023 let x0 = float x -. hw
2024 and y0 = float y -. hh in
2025 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
2029 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
2030 if nogeomcmds state
.geomcmds
2033 then pivotzoom ?
vw ?vh ?
x ?
y zoom
2037 let setcolumns mode columns coverA coverB
=
2038 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
2042 then impmsg "split mode doesn't work in bird's eye"
2044 conf
.columns
<- Csplit
(-columns
, E.a);
2052 conf
.columns
<- Csingle
E.a;
2057 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
2061 reshape state
.winw state
.winh
;
2064 let resetmstate () =
2065 state
.mstate
<- Mnone
;
2066 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2069 let enterbirdseye () =
2070 let zoom = float conf
.thumbw
/. float state
.winw
in
2071 let birdseyepageno =
2072 let cy = state
.winh
/ 2 in
2076 let rec fold best
= function
2079 let d = cy - (l.pagedispy + l.pagevh/2)
2080 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2081 if abs
d < abs dbest
2090 { conf
with zoom = conf
.zoom },
2091 state
.x, birdseyepageno, -1, getanchor
()
2095 conf
.presentation
<- false;
2096 conf
.interpagespace
<- 10;
2097 conf
.hlinks
<- false;
2098 conf
.fitmodel
<- FitPage
;
2100 conf
.maxwait
<- None
;
2102 match conf
.beyecolumns
with
2105 Cmulti
((c, 0, 0), E.a)
2106 | None
-> Csingle
E.a
2110 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2115 reshape state
.winw state
.winh
;
2118 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2120 conf
.zoom <- c.zoom;
2121 conf
.presentation
<- c.presentation
;
2122 conf
.interpagespace
<- c.interpagespace
;
2123 conf
.maxwait
<- c.maxwait
;
2124 conf
.hlinks
<- c.hlinks
;
2125 conf
.fitmodel
<- c.fitmodel
;
2126 conf
.beyecolumns
<- (
2127 match conf
.columns
with
2128 | Cmulti
((c, _, _), _) -> Some
c
2130 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2133 match c.columns
with
2134 | Cmulti
(c, _) -> Cmulti
(c, E.a)
2135 | Csingle
_ -> Csingle
E.a
2136 | Csplit
(c, _) -> Csplit
(c, E.a)
2140 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2143 reshape state
.winw state
.winh
;
2144 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2148 let togglebirdseye () =
2149 match state
.mode
with
2150 | Birdseye vals
-> leavebirdseye vals
true
2151 | View
-> enterbirdseye ()
2152 | Textentry
_ | LinkNav
_ -> ()
2155 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2156 let pageno = max
0 (pageno - incr
) in
2157 let rec loop = function
2158 | [] -> gotopage1 pageno 0
2159 | l :: _ when l.pageno = pageno ->
2160 if l.pagedispy >= 0 && l.pagey = 0
2161 then G.postRedisplay "upbirdseye"
2162 else gotopage1 pageno 0
2163 | _ :: rest
-> loop rest
2167 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
2170 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
2171 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
2172 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
2173 let rec loop = function
2175 let y, h = getpageyh
pageno in
2176 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
2177 gotoxy state
.x (clamp dy)
2178 | l :: _ when l.pageno = pageno ->
2179 if l.pagevh != l.pageh
2180 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
2181 else G.postRedisplay "downbirdseye"
2182 | _ :: rest
-> loop rest
2188 let [@warning
"-4"] optentry mode
_ key =
2189 let btos b = if b then "on" else "off" in
2193 try conf
.scrollstep
<- int_of_string
s with exn
->
2194 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2196 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
2201 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
2202 if state
.autoscroll
<> None
2203 then state
.autoscroll
<- Some conf
.autoscrollstep
2205 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2207 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
2212 let n, a, b = multicolumns_of_string
s in
2213 setcolumns mode
n a b;
2215 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
2217 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
2222 let zoom = float (int_of_string
s) /. 100.0 in
2225 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2227 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
2232 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
2234 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
2235 begin match mode
with
2237 leavebirdseye beye
false;
2239 | Textentry
_ | View
| LinkNav
_ -> ();
2242 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2244 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2248 match int_of_string
s with
2249 | angle
-> reqlayout angle conf
.fitmodel
2251 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2253 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2256 conf
.icase
<- not conf
.icase
;
2257 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2260 conf
.preload <- not conf
.preload;
2261 gotoxy state
.x state
.y;
2262 TEdone
("preload " ^
(btos conf
.preload))
2265 conf
.verbose
<- not conf
.verbose
;
2266 TEdone
("verbose " ^
(btos conf
.verbose
))
2269 conf
.debug
<- not conf
.debug
;
2270 TEdone
("debug " ^
(btos conf
.debug
))
2273 conf
.maxhfit
<- not conf
.maxhfit
;
2274 state
.maxy <- calcheight
();
2275 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2278 conf
.crophack
<- not conf
.crophack
;
2279 TEdone
("crophack " ^
btos conf
.crophack
)
2283 match conf
.maxwait
with
2285 conf
.maxwait
<- Some infinity
;
2286 "always wait for page to complete"
2288 conf
.maxwait
<- None
;
2289 "show placeholder if page is not ready"
2294 conf
.underinfo
<- not conf
.underinfo
;
2295 TEdone
("underinfo " ^
btos conf
.underinfo
)
2298 conf
.savebmarks
<- not conf
.savebmarks
;
2299 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2305 match state
.layout with
2310 conf
.interpagespace
<- int_of_string
s;
2311 docolumns conf
.columns
;
2312 state
.maxy <- calcheight
();
2313 let y = getpagey
pageno in
2314 gotoxy state
.x (y + py)
2316 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2318 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2322 match conf
.fitmodel
with
2323 | FitProportional
-> FitWidth
2324 | FitWidth
| FitPage
-> FitProportional
2326 reqlayout conf
.angle
fm;
2327 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2330 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2331 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2334 conf
.invert
<- not conf
.invert
;
2335 TEdone
("invert colors " ^
btos conf
.invert
)
2339 cbput state
.hists
.sel
s;
2342 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2343 textentry
, ondone, true)
2347 then conf
.pax
<- Some
(ref (0.0, 0, 0))
2348 else conf
.pax
<- None
;
2349 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2352 state
.text <- Printf.sprintf
"bad option %d `%c'"
2360 class type lvsource
=
2362 method getitemcount
: int
2363 method getitem
: int -> (string * int)
2364 method hasaction
: int -> bool
2365 method exit
: uioh
:uioh
->
2371 method getactive
: int
2372 method getfirst
: int
2374 method getminfo
: (int * int) array
2377 class virtual lvsourcebase
= object
2378 val mutable m_active
= 0
2379 val mutable m_first
= 0
2380 val mutable m_pan
= 0
2381 method getactive
= m_active
2382 method getfirst
= m_first
2383 method getpan
= m_pan
2384 method getminfo
: (int * int) array
= E.a
2389 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2392 state
.mode
<- Textentry
(te
, onleave
);
2394 G.postRedisplay "textentrykeyboard enttext";
2396 let histaction cmd
=
2399 | Some
(action, _) ->
2402 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2404 G.postRedisplay "textentry histaction"
2407 let kt = Wsi.kc2kt
key in
2410 if emptystr
text && cancelonempty
2413 G.postRedisplay "textentrykeyboard after cancel";
2416 let s = withoutlastutf8
text in
2417 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2422 G.postRedisplay "textentrykeyboard after confirm"
2424 | Up
-> histaction HCprev
2425 | Down
-> histaction HCnext
2426 | Home
-> histaction HCfirst
2427 | End
-> histaction HClast
2432 begin match opthist
with
2434 | Some
(_, onhistcancel
) -> onhistcancel
()
2438 G.postRedisplay "textentrykeyboard after cancel2"
2441 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2446 | Code
_ | Ascii
_ ->
2447 begin match onkey
text kt with
2451 G.postRedisplay "textentrykeyboard after confirm2";
2454 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2458 G.postRedisplay "textentrykeyboard after cancel3"
2461 state
.mode
<- Textentry
(te
, onleave
);
2462 G.postRedisplay "textentrykeyboard switch";
2464 | _ -> vlog "unhandled key"
2467 let firstof first active
=
2468 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2469 then max
0 (active
- (fstate
.maxrows
/2))
2473 let calcfirst first active
=
2476 let rows = active
- first
in
2477 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2481 let scrollph y maxy =
2482 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2483 let sh = float state
.winh
/. sh in
2484 let sh = max
sh (float conf
.scrollh
) in
2486 let percent = float y /. float maxy in
2487 let position = (float state
.winh
-. sh) *. percent in
2490 if position +. sh > float state
.winh
2491 then float state
.winh
-. sh
2497 let adderrmsg src msg
=
2498 Buffer.add_string state
.errmsgs msg
;
2499 state
.newerrmsgs
<- true;
2503 let adderrfmt src fmt
=
2504 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2507 let coe s = (s :> uioh
);;
2509 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2511 val m_pan
= source#getpan
2512 val m_first
= source#getfirst
2513 val m_active
= source#getactive
2515 val m_prev_uioh
= state
.uioh
2517 method private elemunder
y =
2521 let n = y / (fstate
.fontsize
+1) in
2522 if m_first
+ n < source#getitemcount
2524 if source#hasaction
(m_first
+ n)
2525 then Some
(m_first
+ n)
2532 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2533 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2534 filledrect 0. 0. (float state
.winw
) (float state
.winh
);
2535 GlDraw.color (1., 1., 1.);
2536 Gl.enable `texture_2d
;
2537 let fs = fstate
.fontsize
in
2539 let hw = state
.winw
/3 in
2540 let ww = fstate
.wwidth
in
2541 let tabw = 17.0*.ww in
2542 let itemcount = source#getitemcount
in
2543 let minfo = source#getminfo
in
2547 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2549 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2551 if (row - m_first
) > fstate
.maxrows
2554 if row >= 0 && row < itemcount
2556 let (s, level
) = source#getitem
row in
2557 let y = (row - m_first
) * nfs in
2558 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2561 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2565 Gl.disable `texture_2d
;
2566 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2567 GlDraw.color (1., 1., 1.) ~
alpha;
2568 linerect (x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2569 Gl.enable `texture_2d
;
2572 if zebra
&& row land 1 = 1
2576 GlDraw.color (c,c,c);
2577 let drawtabularstring s =
2579 let x'
= truncate
(x0 +. x) in
2580 let s1, s2
= splitatchar
s '
\000'
in
2582 then drawstring1 fs x'
(y+nfs) s
2588 let s'
= withoutlastutf8
s in
2589 let s = s' ^
UniSyms.ellipsis in
2590 let w = measurestr
fs s in
2591 if float x'
+. w +. ww < float (hw + x'
)
2596 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2600 ignore
(drawstring1 fs x'
(y+nfs) s1);
2601 drawstring1 fs (hw + x'
) (y+nfs) s2
2605 let x = if helpmode
&& row > 0 then x +. ww else x in
2606 let s1, s2
= splitatchar
s '
\t'
in
2609 let nx = drawstr x s1 in
2611 let x = x +. (max
tabw sw) in
2614 let len = String.length
s - 2 in
2615 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2617 let s = String.sub s 2 len in
2618 let x = if not helpmode
then x +. ww else x in
2619 GlDraw.color (1.2, 1.2, 1.2);
2620 let vinc = drawstring1 (fs+fs/4)
2621 (truncate
(x -. ww)) (y+nfs) s in
2622 GlDraw.color (1., 1., 1.);
2623 vinc +. (float fs *. 0.8)
2629 ignore
(drawtabularstring s);
2635 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2638 if (row - m_first
) <= fstate
.maxrows
2640 if row >= 0 && row < itemcount
2642 let (s, level
) = source#getitem
row in
2643 let pos0 = nindex
s '
\000'
in
2644 let y = (row - m_first
) * nfs in
2645 let x = float (level
+ m_pan
) *. ww in
2646 let (first
, last
) = minfo.(row) in
2648 if pos0 > 0 && first
> pos0
2649 then String.sub s (pos0+1) (first
-pos0-1)
2650 else String.sub s 0 first
2652 let suffix = String.sub s first
(last
- first
) in
2653 let w1 = measurestr fstate
.fontsize
prefix in
2654 let w2 = measurestr fstate
.fontsize
suffix in
2655 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2656 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2658 and y0 = float (y+2) in
2660 and y1 = float (y+fs+3) in
2661 filledrect x0 y0 x1 y1;
2665 Gl.disable `texture_2d
;
2666 if Array.length
minfo > 0 then loop m_first
;
2671 method updownlevel incr
=
2672 let len = source#getitemcount
in
2674 if m_active
>= 0 && m_active
< len
2675 then snd
(source#getitem m_active
)
2679 if i
= len then i
-1 else if i
= -1 then 0 else
2680 let _, l = source#getitem i
in
2681 if l != curlevel then i
else flow (i
+incr
)
2683 let active = flow m_active
in
2684 let first = calcfirst m_first
active in
2685 G.postRedisplay "outline updownlevel";
2686 {< m_active
= active; m_first
= first >}
2688 method private key1
key mask
=
2689 let set1 active first qsearch
=
2690 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2692 let search active pattern incr
=
2693 let active = if active = -1 then m_first
else active in
2696 if n >= 0 && n < source#getitemcount
2698 let s, _ = source#getitem
n in
2699 match Str.search_forward re
s 0 with
2700 | exception Not_found
-> loop (n + incr
)
2707 let qpat = Str.quote pattern
in
2708 match Str.regexp_case_fold
qpat with
2711 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2712 qpat @@ Printexc.to_string exn
;
2715 let itemcount = source#getitemcount
in
2716 let find start incr
=
2718 if i
= -1 || i
= itemcount
2721 if source#hasaction i
2723 else find (i
+ incr
)
2728 let set active first =
2729 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2731 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2734 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2736 let incr1 = if incr
> 0 then 1 else -1 in
2737 if isvisible m_first m_active
2740 let next = m_active
+ incr
in
2742 if next < 0 || next >= itemcount
2744 else find next incr1
2746 if abs
(m_active
- next) > fstate
.maxrows
2752 let first = m_first
+ incr
in
2753 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2755 let next = m_active
+ incr
in
2756 let next = bound
next 0 (itemcount - 1) in
2763 if isvisible first next
2770 let first = min
next m_first
in
2772 if abs
(next - first) > fstate
.maxrows
2778 let first = m_first
+ incr
in
2779 let first = bound
first 0 (itemcount - 1) in
2781 let next = m_active
+ incr
in
2782 let next = bound
next 0 (itemcount - 1) in
2783 let next = find next incr1 in
2785 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2787 let active = if m_active
= -1 then next else m_active
in
2792 if isvisible first active
2798 G.postRedisplay "listview navigate";
2802 let kt = Wsi.kc2kt
key in
2803 match [@warning
"-4"] kt with
2804 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2805 let incr = if c = 'r'
then -1 else 1 in
2807 match search (m_active
+ incr) m_qsearch
incr with
2809 state
.text <- m_qsearch ^
" [not found]";
2812 state
.text <- m_qsearch
;
2813 active, firstof m_first
active
2815 G.postRedisplay "listview ctrl-r/s";
2816 set1 active first m_qsearch
;
2818 | Insert
when Wsi.withctrl mask
->
2819 if m_active
>= 0 && m_active
< source#getitemcount
2821 let s, _ = source#getitem m_active
in
2827 if emptystr m_qsearch
2830 let qsearch = withoutlastutf8 m_qsearch
in
2834 G.postRedisplay "listview empty qsearch";
2835 set1 m_active m_first
E.s;
2839 match search m_active
qsearch ~
-1 with
2841 state
.text <- qsearch ^
" [not found]";
2844 state
.text <- qsearch;
2845 active, firstof m_first
active
2847 G.postRedisplay "listview backspace qsearch";
2848 set1 active first qsearch
2851 | Ascii
_ | Code
_ ->
2853 match [@warning
"-8"] kt with
2854 | Ascii
c -> String.make
1 c
2855 | Code code
-> toutf8 code
2857 let pattern = m_qsearch ^
utf8 in
2859 match search m_active
pattern 1 with
2861 state
.text <- pattern ^
" [not found]";
2864 state
.text <- pattern;
2865 active, firstof m_first
active
2867 G.postRedisplay "listview qsearch add";
2868 set1 active first pattern;
2872 if emptystr m_qsearch
2874 G.postRedisplay "list view escape";
2875 let mx, my
= state
.mpos
in
2877 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2878 ~
first:m_first ~pan
:m_pan
with
2879 | None
-> m_prev_uioh
2883 G.postRedisplay "list view kill qsearch";
2884 coe {< m_qsearch
= E.s >}
2889 let self = {< m_qsearch
= E.s >} in
2891 G.postRedisplay "listview enter";
2892 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2893 source#exit ~uioh
:(coe self) ~
cancel
2894 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2896 begin match opt with
2897 | None
-> m_prev_uioh
2904 | Up
-> navigate ~
-1
2905 | Down
-> navigate 1
2906 | Prior
-> navigate ~
-(fstate
.maxrows
)
2907 | Next
-> navigate fstate
.maxrows
2911 G.postRedisplay "listview right";
2912 coe {< m_pan
= m_pan
- 1 >}
2916 G.postRedisplay "listview left";
2917 coe {< m_pan
= m_pan
+ 1 >}
2920 let active = find 0 1 in
2921 G.postRedisplay "listview home";
2925 let first = max
0 (itemcount - fstate
.maxrows
) in
2926 let active = find (itemcount - 1) ~
-1 in
2927 G.postRedisplay "listview end";
2932 method key key mask
=
2933 match state
.mode
with
2935 textentrykeyboard
key mask te
;
2937 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2939 method button button down
x y _ =
2942 | 1 when vscrollhit x ->
2943 G.postRedisplay "listview scroll";
2946 let _, position, sh = self#
scrollph in
2947 if y > truncate
position && y < truncate
(position +. sh)
2949 state
.mstate
<- Mscrolly
;
2953 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2954 let first = truncate
(s *. float source#getitemcount
) in
2955 let first = min source#getitemcount
first in
2956 Some
(coe {< m_first
= first; m_active
= first >})
2958 state
.mstate
<- Mnone
;
2962 begin match self#elemunder
y with
2964 G.postRedisplay "listview click";
2965 source#exit ~uioh
:(coe {< m_active
= n >})
2966 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2970 | n when (n == 4 || n == 5) && not down
->
2971 let len = source#getitemcount
in
2973 if n = 5 && m_first
+ fstate
.maxrows
>= len
2977 let first = m_first
+ (if n == 4 then -1 else 1) in
2978 bound
first 0 (len - 1)
2980 G.postRedisplay "listview wheel";
2981 Some
(coe {< m_first
= first >})
2982 | n when (n = 6 || n = 7) && not down
->
2983 let inc = if n = 7 then -1 else 1 in
2984 G.postRedisplay "listview hwheel";
2985 Some
(coe {< m_pan
= m_pan
+ inc >})
2990 | None
-> m_prev_uioh
2993 method multiclick
_ x y = self#button
1 true x y
2996 match state
.mstate
with
2998 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2999 let first = truncate
(s *. float source#getitemcount
) in
3000 let first = min source#getitemcount
first in
3001 G.postRedisplay "listview motion";
3002 coe {< m_first
= first; m_active
= first >}
3010 method pmotion
x y =
3011 if x < state
.winw
- conf
.scrollbw
3014 match self#elemunder
y with
3015 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3016 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3020 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3025 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3029 method infochanged
_ = ()
3031 method scrollpw
= (0, 0.0, 0.0)
3033 let nfs = fstate
.fontsize
+ 1 in
3034 let y = m_first
* nfs in
3035 let itemcount = source#getitemcount
in
3036 let maxi = max
0 (itemcount - fstate
.maxrows
) in
3037 let maxy = maxi * nfs in
3038 let p, h = scrollph y maxy in
3041 method modehash
= modehash
3042 method eformsgs
= false
3043 method alwaysscrolly
= true
3044 method scroll _ dy =
3046 if dy != 0 then begin
3047 let len = source#getitemcount
in
3049 if dy > 0 && m_first
+ fstate
.maxrows
>= len
3053 let first = m_first
+ dy / 10 in
3054 bound
first 0 (len - 1)
3056 G.postRedisplay "listview wheel";
3057 {< m_first
= first >}
3063 method zoom _ _ _ = ()
3066 class outlinelistview ~zebra ~source
=
3067 let settext autonarrow
s =
3070 let ss = source#statestr
in
3074 else "{" ^
ss ^
"} [" ^
s ^
"]"
3075 else state
.text <- s
3081 ~source
:(source
:> lvsource
)
3083 ~modehash
:(findkeyhash conf
"outline")
3086 val m_autonarrow
= false
3088 method! key key mask
=
3090 if emptystr state
.text
3092 else fstate
.maxrows - 2
3094 let calcfirst first active =
3097 let rows = active - first in
3098 if rows > maxrows then active - maxrows else first
3102 let active = m_active
+ incr in
3103 let active = bound
active 0 (source#getitemcount
- 1) in
3104 let first = calcfirst m_first
active in
3105 G.postRedisplay "outline navigate";
3106 coe {< m_active
= active; m_first
= first >}
3108 let navscroll first =
3110 let dist = m_active
- first in
3116 else first + maxrows
3119 G.postRedisplay "outline navscroll";
3120 coe {< m_first
= first; m_active
= active >}
3122 let ctrl = Wsi.withctrl mask
in
3124 match Wsi.kc2kt
key with
3125 | Ascii '
a'
when ctrl ->
3128 then (source#denarrow
; E.s)
3130 let pattern = source#renarrow
in
3131 if nonemptystr m_qsearch
3132 then (source#narrow m_qsearch
; m_qsearch
)
3136 settext (not m_autonarrow
) text;
3137 G.postRedisplay "toggle auto narrowing";
3138 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3140 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
3142 G.postRedisplay "toggle auto narrowing";
3143 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3145 | Ascii '
n'
when ctrl ->
3146 source#narrow m_qsearch
;
3148 then source#add_narrow_pattern m_qsearch
;
3149 G.postRedisplay "outline ctrl-n";
3150 coe {< m_first
= 0; m_active
= 0 >}
3152 | Ascii 'S'
when ctrl ->
3153 let active = source#calcactive
(getanchor
()) in
3154 let first = firstof m_first
active in
3155 G.postRedisplay "outline ctrl-s";
3156 coe {< m_first
= first; m_active
= active >}
3158 | Ascii 'u'
when ctrl ->
3159 G.postRedisplay "outline ctrl-u";
3160 if m_autonarrow
&& nonemptystr m_qsearch
3162 ignore
(source#renarrow
);
3163 settext m_autonarrow
E.s;
3164 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3167 source#del_narrow_pattern
;
3168 let pattern = source#renarrow
in
3170 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
3172 settext m_autonarrow
text;
3173 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
3176 | Ascii '
l'
when ctrl ->
3177 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
3178 G.postRedisplay "outline ctrl-l";
3179 coe {< m_first
= first >}
3181 | Ascii '
\t'
when m_autonarrow
->
3182 if nonemptystr m_qsearch
3184 G.postRedisplay "outline list view tab";
3185 source#add_narrow_pattern m_qsearch
;
3187 coe {< m_qsearch
= E.s >}
3191 | Escape
when m_autonarrow
->
3192 if nonemptystr m_qsearch
3193 then source#add_narrow_pattern m_qsearch
;
3196 | Enter
when m_autonarrow
->
3197 if nonemptystr m_qsearch
3198 then source#add_narrow_pattern m_qsearch
;
3201 | (Ascii
_ | Code
_) when m_autonarrow
->
3202 let pattern = m_qsearch ^ toutf8
key in
3203 G.postRedisplay "outlinelistview autonarrow add";
3204 source#narrow
pattern;
3205 settext true pattern;
3206 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3208 | Backspace
when m_autonarrow
->
3209 if emptystr m_qsearch
3212 let pattern = withoutlastutf8 m_qsearch
in
3213 G.postRedisplay "outlinelistview autonarrow backspace";
3214 ignore
(source#renarrow
);
3215 source#narrow
pattern;
3216 settext true pattern;
3217 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3220 navscroll (max
0 (m_first
- 1))
3223 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3225 | Up
-> navigate ~
-1
3226 | Down
-> navigate 1
3227 | Prior
-> navigate ~
-(fstate
.maxrows)
3228 | Next
-> navigate fstate
.maxrows
3234 G.postRedisplay "outline ctrl right";
3235 {< m_pan
= m_pan
+ 1 >}
3237 else self#updownlevel
1
3245 G.postRedisplay "outline ctrl left";
3246 {< m_pan
= m_pan
- 1 >}
3248 else self#updownlevel ~
-1
3253 G.postRedisplay "outline home";
3254 coe {< m_first
= 0; m_active
= 0 >}
3257 let active = source#getitemcount
- 1 in
3258 let first = max
0 (active - fstate
.maxrows) in
3259 G.postRedisplay "outline end";
3260 coe {< m_active
= active; m_first
= first >}
3262 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
3266 let genhistoutlines () =
3268 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3269 compare c2
.lastvisit c1
.lastvisit
)
3270 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3271 let path = if nonemptystr origin
then origin
else path in
3272 let base = mbtoutf8
@@ Filename.basename
path in
3273 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3277 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3278 Config.save
leavebirdseye;
3279 state
.anchor <- anchor;
3280 state
.bookmarks
<- bookmarks
;
3281 state
.origin
<- origin
;
3284 let x0, y0, x1, y1 = conf
.trimfuzz
in
3285 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3286 reshape ~firsttime
:true state
.winw state
.winh
;
3287 opendoc path origin
;
3291 let makecheckers () =
3292 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3294 converted by Issac Trotts. July 25, 2002 *)
3295 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3296 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3297 let id = GlTex.gen_texture
() in
3298 GlTex.bind_texture ~target
:`texture_2d
id;
3299 GlPix.store
(`unpack_alignment
1);
3300 GlTex.image2d
image;
3301 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3302 [ `mag_filter `nearest
; `min_filter `nearest
];
3306 let setcheckers enabled
=
3307 match state
.checkerstexid
with
3309 if enabled
then state
.checkerstexid
<- Some
(makecheckers ())
3311 | Some checkerstexid
->
3314 GlTex.delete_texture checkerstexid
;
3315 state
.checkerstexid
<- None
;
3319 let describe_location () =
3320 let layout = layout state
.x state
.y state
.winw state
.winh
in
3324 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
3327 let sep = if a.pageno+1 = b.pageno then " " else ".." in
3328 Printf.sprintf
"%d%s%d" (a.pageno+1) sep (b.pageno+1)
3330 let rec fold s la lb
= function
3331 | [] when la
== lb
-> Printf.sprintf
"%s %d" s (la
.pageno+1)
3332 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
3333 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
3334 | l :: rest
-> fold (s ^
" " ^
rangestr la lb
) l l rest
3336 fold "Pages" l l rest
3339 let maxy = maxy () in
3342 else 100. *. (float state
.y /. float maxy)
3344 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
3347 let setpresentationmode v
=
3348 let n = page_of_y state
.y in
3349 state
.anchor <- (n, 0.0, 1.0);
3350 conf
.presentation
<- v
;
3351 if conf
.fitmodel
= FitPage
3352 then reqlayout conf
.angle conf
.fitmodel
;
3356 let setbgcol (r
, g, b) =
3358 let r = r *. 255.0 |> truncate
3359 and g = g *. 255.0 |> truncate
3360 and b = b *. 255.0 |> truncate
in
3361 r lsl 16 |> (lor) (g lsl 8) |> (lor) b
3363 Wsi.setwinbgcol
col;
3367 let btos b = if b then UniSyms.radical else E.s in
3368 let showextended = ref false in
3369 let leave mode
_ = state
.mode
<- mode
in
3372 val mutable m_l
= []
3373 val mutable m_a
= E.a
3374 val mutable m_prev_uioh
= nouioh
3375 val mutable m_prev_mode
= View
3377 inherit lvsourcebase
3379 method reset prev_mode prev_uioh
=
3380 m_a
<- Array.of_list
(List.rev m_l
);
3382 m_prev_mode
<- prev_mode
;
3383 m_prev_uioh
<- prev_uioh
;
3385 method int name get
set =
3391 try set (int_of_string
s)
3393 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3397 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3398 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3402 method int_with_suffix name get
set =
3404 (name
, `intws get
, 1,
3408 try set (int_of_string_with_suffix
s)
3410 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3415 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3417 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3421 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3423 (name
, `
bool (btos, get
), offset
, Action
(
3430 method color name get
set =
3432 (name
, `
color get
, 1,
3435 let invalid = (nan
, nan
, nan
) in
3438 try color_of_string
s
3440 state
.text <- Printf.sprintf
"bad color `%s': %s"
3447 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3448 state
.text <- color_to_string
(get
());
3449 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3453 method string name get
set =
3455 (name
, `
string get
, 1,
3458 let ondone s = set s in
3459 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3460 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3464 method colorspace name get
set =
3466 (name
, `
string get
, 1,
3471 inherit lvsourcebase
3474 m_active
<- CSTE.to_int conf
.colorspace
;
3477 method getitemcount
=
3478 Array.length
CSTE.names
3481 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3482 ignore
(uioh
, first, pan
);
3483 if not
cancel then set active;
3485 method hasaction
_ = true
3489 let modehash = findkeyhash conf
"info" in
3490 coe (new listview ~zebra
:false ~helpmode
:false
3491 ~
source ~trusted
:true ~
modehash)
3494 method paxmark name get
set =
3496 (name
, `
string get
, 1,
3501 inherit lvsourcebase
3504 m_active
<- MTE.to_int conf
.paxmark
;
3507 method getitemcount
= Array.length
MTE.names
3508 method getitem
n = (MTE.names
.(n), 0)
3509 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3510 ignore
(uioh
, first, pan
);
3511 if not
cancel then set active;
3513 method hasaction
_ = true
3517 let modehash = findkeyhash conf
"info" in
3518 coe (new listview ~zebra
:false ~helpmode
:false
3519 ~
source ~trusted
:true ~
modehash)
3522 method fitmodel name get
set =
3524 (name
, `
string get
, 1,
3529 inherit lvsourcebase
3532 m_active
<- FMTE.to_int conf
.fitmodel
;
3535 method getitemcount
= Array.length
FMTE.names
3536 method getitem
n = (FMTE.names
.(n), 0)
3537 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3538 ignore
(uioh
, first, pan
);
3539 if not
cancel then set active;
3541 method hasaction
_ = true
3545 let modehash = findkeyhash conf
"info" in
3546 coe (new listview ~zebra
:false ~helpmode
:false
3547 ~
source ~trusted
:true ~
modehash)
3550 method caption
s offset
=
3551 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3553 method caption2
s f offset
=
3554 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3556 method getitemcount
= Array.length m_a
3559 let tostr = function
3560 | `
int f -> string_of_int
(f ())
3561 | `intws
f -> string_with_suffix_of_int
(f ())
3563 | `
color f -> color_to_string
(f ())
3564 | `
bool (btos, f) -> btos (f ())
3567 let name, t
, offset
, _ = m_a
.(n) in
3568 ((let s = tostr t
in
3570 then Printf.sprintf
"%s\t%s" name s
3574 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3579 match m_a
.(active) with
3580 | _, _, _, Action
f -> f uioh
3581 | _, _, _, Noaction
-> uioh
3592 method hasaction
n =
3594 | _, _, _, Action
_ -> true
3595 | _, _, _, Noaction
-> false
3597 initializer m_active
<- 1
3600 let rec fillsrc prevmode prevuioh
=
3601 let sep () = src#caption
E.s 0 in
3602 let colorp name get
set =
3604 (fun () -> color_to_string
(get
()))
3607 let c = color_of_string
v in
3611 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3614 let oldmode = state
.mode
in
3615 let birdseye = isbirdseye state
.mode
in
3617 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3619 src#
bool "presentation mode"
3620 (fun () -> conf
.presentation
)
3621 (fun v -> setpresentationmode v);
3623 src#
bool "ignore case in searches"
3624 (fun () -> conf
.icase
)
3625 (fun v -> conf
.icase
<- v);
3628 (fun () -> conf
.preload)
3629 (fun v -> conf
.preload <- v);
3631 src#
bool "highlight links"
3632 (fun () -> conf
.hlinks
)
3633 (fun v -> conf
.hlinks
<- v);
3635 src#
bool "under info"
3636 (fun () -> conf
.underinfo
)
3637 (fun v -> conf
.underinfo
<- v);
3639 src#
bool "persistent bookmarks"
3640 (fun () -> conf
.savebmarks
)
3641 (fun v -> conf
.savebmarks
<- v);
3643 src#fitmodel
"fit model"
3644 (fun () -> FMTE.to_string conf
.fitmodel
)
3645 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3647 src#
bool "trim margins"
3648 (fun () -> conf
.trimmargins
)
3649 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3651 src#
bool "persistent location"
3652 (fun () -> conf
.jumpback
)
3653 (fun v -> conf
.jumpback
<- v);
3656 src#
int "inter-page space"
3657 (fun () -> conf
.interpagespace
)
3659 conf
.interpagespace
<- n;
3660 docolumns conf
.columns
;
3662 match state
.layout with
3667 state
.maxy <- calcheight
();
3668 let y = getpagey
pageno in
3669 gotoxy state
.x (y + py)
3673 (fun () -> conf
.pagebias
)
3674 (fun v -> conf
.pagebias
<- v);
3676 src#
int "scroll step"
3677 (fun () -> conf
.scrollstep
)
3678 (fun n -> conf
.scrollstep
<- n);
3680 src#
int "horizontal scroll step"
3681 (fun () -> conf
.hscrollstep
)
3682 (fun v -> conf
.hscrollstep
<- v);
3684 src#
int "auto scroll step"
3686 match state
.autoscroll
with
3688 | _ -> conf
.autoscrollstep
)
3690 let n = boundastep state
.winh
n in
3691 if state
.autoscroll
<> None
3692 then state
.autoscroll
<- Some
n;
3693 conf
.autoscrollstep
<- n);
3696 (fun () -> truncate
(conf
.zoom *. 100.))
3697 (fun v -> pivotzoom ((float v) /. 100.));
3700 (fun () -> conf
.angle
)
3701 (fun v -> reqlayout v conf
.fitmodel
);
3703 src#
int "scroll bar width"
3704 (fun () -> conf
.scrollbw
)
3707 reshape state
.winw state
.winh
;
3710 src#
int "scroll handle height"
3711 (fun () -> conf
.scrollh
)
3712 (fun v -> conf
.scrollh
<- v;);
3714 src#
int "thumbnail width"
3715 (fun () -> conf
.thumbw
)
3717 conf
.thumbw
<- min
4096 v;
3720 leavebirdseye beye
false;
3727 let mode = state
.mode in
3728 src#
string "columns"
3730 match conf
.columns
with
3732 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3733 | Csplit
(count
, _) -> "-" ^ string_of_int count
3736 let n, a, b = multicolumns_of_string
v in
3737 setcolumns mode n a b);
3740 src#caption
"Pixmap cache" 0;
3741 src#int_with_suffix
"size (advisory)"
3742 (fun () -> conf
.memlimit
)
3743 (fun v -> conf
.memlimit
<- v);
3747 Printf.sprintf
"%s bytes, %d tiles"
3748 (string_with_suffix_of_int state
.memused
)
3749 (Hashtbl.length state
.tilemap
)) 1;
3752 src#caption
"Layout" 0;
3753 src#caption2
"Dimension"
3755 Printf.sprintf
"%dx%d (virtual %dx%d)"
3756 state
.winw state
.winh
3761 src#caption2
"Position" (fun () ->
3762 Printf.sprintf
"%dx%d" state
.x state
.y
3765 src#caption2
"Position" (fun () -> describe_location ()) 1
3769 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3770 "Save these parameters as global defaults at exit"
3771 (fun () -> conf
.bedefault
)
3772 (fun v -> conf
.bedefault
<- v)
3776 let btos b = if b then UniSyms.lguillemet else UniSyms.rguillemet in
3777 src#
bool ~offset
:0 ~
btos "Extended parameters"
3778 (fun () -> !showextended)
3779 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3783 (fun () -> conf
.checkers
)
3784 (fun v -> conf
.checkers
<- v; setcheckers v);
3785 src#
bool "update cursor"
3786 (fun () -> conf
.updatecurs
)
3787 (fun v -> conf
.updatecurs
<- v);
3788 src#
bool "scroll-bar on the left"
3789 (fun () -> conf
.leftscroll
)
3790 (fun v -> conf
.leftscroll
<- v);
3792 (fun () -> conf
.verbose
)
3793 (fun v -> conf
.verbose
<- v);
3794 src#
bool "invert colors"
3795 (fun () -> conf
.invert
)
3796 (fun v -> conf
.invert
<- v);
3798 (fun () -> conf
.maxhfit
)
3799 (fun v -> conf
.maxhfit
<- v);
3801 (fun () -> conf
.pax
!= None
)
3804 then conf
.pax
<- Some
(ref (now
(), 0, 0))
3805 else conf
.pax
<- None
);
3806 src#
string "uri launcher"
3807 (fun () -> conf
.urilauncher
)
3808 (fun v -> conf
.urilauncher
<- v);
3809 src#
string "path launcher"
3810 (fun () -> conf
.pathlauncher
)
3811 (fun v -> conf
.pathlauncher
<- v);
3812 src#
string "tile size"
3813 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3816 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3817 conf
.tilew
<- max
64 w;
3818 conf
.tileh
<- max
64 h;
3821 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3824 src#
int "texture count"
3825 (fun () -> conf
.texcount
)
3828 then conf
.texcount
<- v
3829 else impmsg "failed to set texture count please retry later"
3831 src#
int "slice height"
3832 (fun () -> conf
.sliceheight
)
3834 conf
.sliceheight
<- v;
3835 wcmd "sliceh %d" conf
.sliceheight
;
3837 src#
int "anti-aliasing level"
3838 (fun () -> conf
.aalevel
)
3840 conf
.aalevel
<- bound
v 0 8;
3841 state
.anchor <- getanchor
();
3842 opendoc state
.path state
.password;
3844 src#
string "page scroll scaling factor"
3845 (fun () -> string_of_float conf
.pgscale)
3848 let s = float_of_string
v in
3851 state
.text <- Printf.sprintf
3852 "bad page scroll scaling factor `%s': %s" v
3856 src#
int "ui font size"
3857 (fun () -> fstate
.fontsize
)
3858 (fun v -> setfontsize (bound
v 5 100));
3859 src#
int "hint font size"
3860 (fun () -> conf
.hfsize
)
3861 (fun v -> conf
.hfsize
<- bound
v 5 100);
3862 colorp "background color"
3863 (fun () -> conf
.bgcolor
)
3864 (fun v -> conf
.bgcolor
<- v; setbgcol v);
3865 src#
bool "crop hack"
3866 (fun () -> conf
.crophack
)
3867 (fun v -> conf
.crophack
<- v);
3868 src#
string "trim fuzz"
3869 (fun () -> irect_to_string conf
.trimfuzz
)
3872 conf
.trimfuzz
<- irect_of_string
v;
3874 then settrim true conf
.trimfuzz
;
3876 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3879 src#
string "throttle"
3881 match conf
.maxwait
with
3882 | None
-> "show place holder if page is not ready"
3885 then "wait for page to fully render"
3887 "wait " ^ string_of_float
time
3888 ^
" seconds before showing placeholder"
3892 let f = float_of_string
v in
3894 then conf
.maxwait
<- None
3895 else conf
.maxwait
<- Some
f
3897 state
.text <- Printf.sprintf
"bad time `%s': %s" v
3900 src#
string "ghyll scroll"
3902 match conf
.ghyllscroll
with
3904 | Some nab
-> ghyllscroll_to_string nab
3907 try conf
.ghyllscroll
<- ghyllscroll_of_string
v
3910 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v msg
3912 state
.text <- Printf.sprintf
"bad ghyll `%s': %s" v
3915 src#
string "selection command"
3916 (fun () -> conf
.selcmd
)
3917 (fun v -> conf
.selcmd
<- v);
3918 src#
string "synctex command"
3919 (fun () -> conf
.stcmd
)
3920 (fun v -> conf
.stcmd
<- v);
3921 src#
string "pax command"
3922 (fun () -> conf
.paxcmd
)
3923 (fun v -> conf
.paxcmd
<- v);
3924 src#
string "ask password command"
3925 (fun () -> conf
.passcmd)
3926 (fun v -> conf
.passcmd <- v);
3927 src#
string "save path command"
3928 (fun () -> conf
.savecmd
)
3929 (fun v -> conf
.savecmd
<- v);
3930 src#colorspace
"color space"
3931 (fun () -> CSTE.to_string conf
.colorspace
)
3933 conf
.colorspace
<- CSTE.of_int
v;
3937 src#paxmark
"pax mark method"
3938 (fun () -> MTE.to_string conf
.paxmark
)
3939 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3940 if bousable
() && !opengl_has_pbo
3943 (fun () -> conf
.usepbo
)
3944 (fun v -> conf
.usepbo
<- v);
3945 src#
bool "mouse wheel scrolls pages"
3946 (fun () -> conf
.wheelbypage
)
3947 (fun v -> conf
.wheelbypage
<- v);
3948 src#
bool "open remote links in a new instance"
3949 (fun () -> conf
.riani
)
3950 (fun v -> conf
.riani
<- v);
3951 src#
bool "edit annotations inline"
3952 (fun () -> conf
.annotinline
)
3953 (fun v -> conf
.annotinline
<- v);
3954 src#
bool "coarse positioning in presentation mode"
3955 (fun () -> conf
.coarseprespos
)
3956 (fun v -> conf
.coarseprespos
<- v);
3957 src#
bool "use document CSS"
3958 (fun () -> conf
.usedoccss
)
3960 conf
.usedoccss
<- v;
3961 state
.anchor <- getanchor
();
3962 opendoc state
.path state
.password;
3967 src#caption
"Document" 0;
3968 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3969 src#caption2
"Pages"
3970 (fun () -> string_of_int state
.pagecount
) 1;
3971 src#caption2
"Dimensions"
3972 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3973 if nonemptystr conf
.css
3974 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3978 src#caption
"Trimmed margins" 0;
3979 src#caption2
"Dimensions"
3980 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3984 src#caption
"OpenGL" 0;
3985 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3986 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3989 src#caption
"Location" 0;
3990 if nonemptystr state
.origin
3991 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3992 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3994 src#reset prevmode prevuioh
;
3999 let prevmode = state
.mode
4000 and prevuioh
= state
.uioh in
4001 fillsrc prevmode prevuioh
;
4002 let source = (src :> lvsource
) in
4003 let modehash = findkeyhash conf
"info" in
4006 inherit listview ~zebra
:false ~helpmode
:false
4007 ~
source ~trusted
:true ~
modehash as super
4008 val mutable m_prevmemused
= 0
4009 method! infochanged
= function
4011 if m_prevmemused
!= state
.memused
4013 m_prevmemused
<- state
.memused
;
4014 G.postRedisplay "memusedchanged";
4016 | Pdim
-> G.postRedisplay "pdimchanged"
4017 | Docinfo
-> fillsrc prevmode prevuioh
4019 method! key key mask
=
4020 if not
(Wsi.withctrl mask
)
4022 match [@warning
"-4"] Wsi.kc2kt
key with
4023 | Keys.Left
-> coe (self#updownlevel ~
-1)
4024 | Keys.Right
-> coe (self#updownlevel
1)
4025 | _ -> super#
key key mask
4026 else super#
key key mask
4028 G.postRedisplay "info";
4034 inherit lvsourcebase
4035 method getitemcount
= Array.length state
.help
4037 let s, l, _ = state
.help
.(n) in
4040 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4044 match state
.help
.(active) with
4045 | _, _, Action
f -> Some
(f uioh)
4046 | _, _, Noaction
-> Some
uioh
4055 method hasaction
n =
4056 match state
.help
.(n) with
4057 | _, _, Action
_ -> true
4058 | _, _, Noaction
-> false
4064 let modehash = findkeyhash conf
"help" in
4066 state
.uioh <- coe (new listview
4067 ~zebra
:false ~helpmode
:true
4068 ~
source ~trusted
:true ~
modehash);
4069 G.postRedisplay "help";
4075 inherit lvsourcebase
4076 val mutable m_items
= E.a
4078 method getitemcount
= 1 + Array.length m_items
4083 else m_items
.(n-1), 0
4085 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4090 then Buffer.clear state
.errmsgs
;
4097 method hasaction
n =
4101 state
.newerrmsgs
<- false;
4102 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
4103 m_items
<- Array.of_list
l
4112 let source = (msgsource :> lvsource
) in
4113 let modehash = findkeyhash conf
"listview" in
4116 inherit listview ~zebra
:false ~helpmode
:false
4117 ~
source ~trusted
:false ~
modehash as super
4120 then msgsource#reset
;
4123 G.postRedisplay "msgs";
4127 let editor = getenvwithdef
"EDITOR" E.s in
4131 let tmppath = Filename.temp_file
"llpp" "note" in
4134 let oc = open_out
tmppath in
4138 let execstr = editor ^
" " ^
tmppath in
4140 match spawn
execstr [] with
4142 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
4145 match Unix.waitpid
[] pid
with
4147 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
4151 | Unix.WEXITED
0 -> filecontents
tmppath
4153 impmsg "editor process(%s) exited abnormally: %d" execstr n;
4155 | Unix.WSIGNALED
n ->
4156 impmsg "editor process(%s) was killed by signal %d" execstr n;
4158 | Unix.WSTOPPED
n ->
4159 impmsg "editor(%s) process was stopped by signal %d" execstr n;
4162 match Unix.unlink
tmppath with
4164 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
4169 let enterannotmode opaque slinkindex
=
4172 inherit lvsourcebase
4173 val mutable m_text
= E.s
4174 val mutable m_items
= E.a
4176 method getitemcount
= Array.length m_items
4179 let label, _func
= m_items
.(n) in
4182 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
4183 ignore
(uioh, first, pan
);
4186 let _label, func
= m_items
.(active) in
4191 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
4194 let rec split accu b i
=
4196 if p = String.length
s
4197 then (String.sub s b (p-b), unit) :: accu
4199 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
4201 let ss = if i
= 0 then E.s else String.sub s b i
in
4202 split ((ss, unit)::accu) (p+1) 0
4207 wcmd "freepage %s" (~
> opaque);
4209 Hashtbl.fold (fun key opaque'
accu ->
4210 if opaque'
= opaque'
4211 then key :: accu else accu) state
.pagemap
[]
4213 List.iter
(Hashtbl.remove state
.pagemap
) keys;
4215 gotoxy state
.x state
.y
4218 delannot
opaque slinkindex
;
4221 let edit inline
() =
4226 modannot
opaque slinkindex
s;
4232 let mode = state
.mode in
4235 ("annotation: ", m_text
, None
, textentry
, update, true),
4236 fun _ -> state
.mode <- mode);
4240 let s = getusertext m_text
in
4245 ( "[Copy]", fun () -> selstring m_text
)
4246 :: ("[Delete]", dele)
4247 :: ("[Edit]", edit conf
.annotinline
)
4249 :: split [] 0 0 |> List.rev
|> Array.of_list
4256 let s = getannotcontents
opaque slinkindex
in
4259 let source = (msgsource :> lvsource
) in
4260 let modehash = findkeyhash conf
"listview" in
4261 state
.uioh <- coe (object
4262 inherit listview ~zebra
:false ~helpmode
:false
4263 ~
source ~trusted
:false ~
modehash
4265 G.postRedisplay "enterannotmode";
4268 let gotoremote spec
=
4269 let filename, dest
= splitatchar spec '#'
in
4270 let getpath filename =
4272 if nonemptystr
filename
4274 if Filename.is_relative
filename
4276 let dir = Filename.dirname state
.path in
4278 if Filename.is_implicit
dir
4279 then Filename.concat
(Sys.getcwd
()) dir
4282 Filename.concat
dir filename
4286 if Sys.file_exists
path
4290 let path = getpath filename in
4294 let cmd = Lazy.force_val lcmd
in
4295 match spawn
cmd with
4297 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4299 let anchor = getanchor
() in
4300 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4301 state
.origin
<- E.s;
4302 state
.ranchors
<- ranchor :: state
.ranchors
;
4305 if substratis spec
0 "page="
4307 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4309 state
.anchor <- (pageno, 0.0, 0.0);
4310 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4312 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4314 state
.nameddest
<- dest
;
4315 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4319 let gotounder = function
4320 | Ulinkuri
s when isexternallink
s ->
4321 if substratis
s 0 "file://"
4322 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4325 let pageno, x, y = uritolocation
s in
4327 gotopagexy !wtmode pageno x y
4328 | Utext
_ | Unone
-> ()
4329 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4332 let gotooutline (_, _, kind
) =
4336 let (pageno, y, _) = anchor in
4338 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4342 | Ouri
uri -> gotounder (Ulinkuri
uri)
4343 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4344 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4345 | Ohistory hist
-> gotohist hist
4346 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4349 class outlinesoucebase fetchoutlines
= object (self)
4350 inherit lvsourcebase
4351 val mutable m_items
= E.a
4352 val mutable m_minfo
= E.a
4353 val mutable m_orig_items
= E.a
4354 val mutable m_orig_minfo
= E.a
4355 val mutable m_narrow_patterns
= []
4356 val mutable m_gen
= -1
4358 method getitemcount
= Array.length m_items
4361 let s, n, _ = m_items
.(n) in
4364 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4365 ignore
(uioh, first);
4367 if m_narrow_patterns
= []
4368 then m_orig_items
, m_orig_minfo
4369 else m_items
, m_minfo
4376 gotooutline m_items
.(active);
4384 method hasaction
(_:int) = true
4387 if Array.length m_items
!= Array.length m_orig_items
4390 match m_narrow_patterns
with
4392 | many
-> String.concat
UniSyms.ellipsis (List.rev many
)
4394 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4398 match m_narrow_patterns
with
4401 | head
:: _ -> UniSyms.ellipsis ^ head
4403 method narrow
pattern =
4404 match Str.regexp_case_fold
pattern with
4407 let rec loop accu minfo n =
4410 m_items
<- Array.of_list
accu;
4411 m_minfo
<- Array.of_list
minfo;
4414 let (s, _, _) as o = m_items
.(n) in
4416 match Str.search_forward re
s 0 with
4417 | exception Not_found
-> accu, minfo
4418 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4420 loop accu minfo (n-1)
4422 loop [] [] (Array.length m_items
- 1)
4424 method! getminfo
= m_minfo
4427 m_orig_items
<- fetchoutlines
();
4428 m_minfo
<- m_orig_minfo
;
4429 m_items
<- m_orig_items
4431 method add_narrow_pattern
pattern =
4432 m_narrow_patterns
<- pattern :: m_narrow_patterns
4434 method del_narrow_pattern
=
4435 match m_narrow_patterns
with
4436 | _ :: rest
-> m_narrow_patterns
<- rest
4441 match m_narrow_patterns
with
4442 | pattern :: [] -> self#narrow
pattern; pattern
4444 List.fold_left
(fun accu pattern ->
4445 self#narrow
pattern;
4446 pattern ^
UniSyms.ellipsis ^
accu) E.s list
4448 method calcactive
(_:anchor) = 0
4450 method reset
anchor items =
4451 if state
.gen
!= m_gen
4453 m_orig_items
<- items;
4455 m_narrow_patterns
<- [];
4457 m_orig_minfo
<- E.a;
4461 if items != m_orig_items
4463 m_orig_items
<- items;
4464 if m_narrow_patterns
== []
4465 then m_items
<- items;
4468 let active = self#calcactive
anchor in
4470 m_first
<- firstof m_first
active
4474 let outlinesource fetchoutlines
=
4476 inherit outlinesoucebase fetchoutlines
4477 method! calcactive
anchor =
4478 let rely = getanchory anchor in
4479 let rec loop n best bestd
=
4480 if n = Array.length m_items
4483 let _, _, kind
= m_items
.(n) in
4486 let orely = getanchory anchor in
4487 let d = abs
(orely - rely) in
4490 else loop (n+1) best bestd
4491 | Onone
| Oremote
_ | Olaunch
_
4492 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4493 loop (n+1) best bestd
4499 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4500 let mkselector sourcetype
=
4501 let fetchoutlines () =
4502 match sourcetype
with
4503 | `bookmarks
-> Array.of_list state
.bookmarks
4504 | `outlines
-> state
.outlines
4505 | `history
-> genhistoutlines () |> Array.of_list
4508 if sourcetype
= `history
4509 then new outlinesoucebase
fetchoutlines
4510 else outlinesource fetchoutlines
4513 let outlines = fetchoutlines () in
4514 if Array.length
outlines = 0
4515 then showtext ' ' errmsg
4518 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4519 let anchor = getanchor
() in
4520 source#reset
anchor outlines;
4521 state
.text <- source#greetmsg
;
4523 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4524 G.postRedisplay "enter selector";
4528 let mkenter sourcetype errmsg
=
4529 let enter = mkselector sourcetype
in
4530 fun () -> enter errmsg
4532 ( mkenter `
outlines "document has no outline"
4533 , mkenter `bookmarks
"document has no bookmarks (yet)"
4534 , mkenter `history
"history is empty" )
4537 let quickbookmark ?title
() =
4538 match state
.layout with
4545 let tm = localtime
(now
()) in
4547 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4549 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4551 | Some
title -> title
4553 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4556 let setautoscrollspeed step goingdown
=
4557 let incr = max
1 ((abs step
) / 2) in
4558 let incr = if goingdown
then incr else -incr in
4559 let astep = boundastep state
.winh
(step
+ incr) in
4560 state
.autoscroll
<- Some
astep;
4564 match conf
.columns
with
4566 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4569 let panbound x = bound
x (-state
.w) state
.winw
;;
4571 let existsinrow pageno (columns
, coverA
, coverB
) p =
4572 let last = ((pageno - coverA
) mod columns
) + columns
in
4573 let rec any = function
4576 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4580 then (if l.pageno = last then false else any rest
)
4588 match state
.layout with
4590 let pageno = page_of_y state
.y in
4591 gotoghyll (getpagey
(pageno+1))
4593 match conf
.columns
with
4595 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4597 let y = clamp (pgscale state
.winh
) in
4600 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4601 gotoghyll (getpagey
pageno)
4602 | Cmulti
((c, _, _) as cl
, _) ->
4603 if conf
.presentation
4604 && (existsinrow l.pageno cl
4605 (fun l -> l.pageh
> l.pagey + l.pagevh))
4607 let y = clamp (pgscale state
.winh
) in
4610 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4611 gotoghyll (getpagey
pageno)
4613 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4615 let pagey, pageh
= getpageyh
l.pageno in
4616 let pagey = pagey + pageh
* l.pagecol
in
4617 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4618 gotoghyll (pagey + pageh
+ ips)
4622 match state
.layout with
4624 let pageno = page_of_y state
.y in
4625 gotoghyll (getpagey
(pageno-1))
4627 match conf
.columns
with
4629 if conf
.presentation
&& l.pagey != 0
4631 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4633 let pageno = max
0 (l.pageno-1) in
4634 gotoghyll (getpagey
pageno)
4635 | Cmulti
((c, _, coverB
) as cl
, _) ->
4636 if conf
.presentation
&&
4637 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4639 gotoghyll (clamp (pgscale ~
-(state
.winh
)))
4642 if l.pageno = state
.pagecount
- coverB
4646 let pageno = max
0 (l.pageno-decr) in
4647 gotoghyll (getpagey
pageno)
4655 let pageno = max
0 (l.pageno-1) in
4656 let pagey, pageh
= getpageyh
pageno in
4659 let pagey, pageh
= getpageyh
l.pageno in
4660 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4666 if emptystr conf
.savecmd
4667 then adderrmsg "savepath-command is empty"
4668 "don't know where to save modified document"
4670 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4674 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
4679 let tmp = path ^
".tmp" in
4681 Unix.rename
tmp path;
4684 let viewkeyboard key mask
=
4686 let mode = state
.mode in
4687 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4690 G.postRedisplay "view:enttext"
4692 let ctrl = Wsi.withctrl mask
in
4694 match Wsi.kc2kt
key with
4695 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
4697 | Ascii 'Q'
-> exit
0
4700 if hasunsavedchanges
()
4704 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4707 match state
.lnava
with
4708 | None
-> LinkNav
(Ltgendir
0)
4709 | Some
pn -> LinkNav
(Ltexact
pn)
4711 gotoxy state
.x state
.y;
4713 else impmsg "keyboard link navigation does not work under rotation"
4715 | Escape
| Ascii 'q'
->
4716 begin match state
.mstate
with
4719 G.postRedisplay "kill rect";
4722 | Mscrolly
| Mscrollx
4725 begin match state
.mode with
4728 | Ltexact pl
-> state
.lnava
<- Some pl
4729 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4732 G.postRedisplay "esc leave linknav"
4733 | Birdseye
_ | Textentry
_ | View
->
4734 match state
.ranchors
with
4736 | (path, password, anchor, origin
) :: rest
->
4737 state
.ranchors
<- rest
;
4738 state
.anchor <- anchor;
4739 state
.origin
<- origin
;
4740 state
.nameddest
<- E.s;
4741 opendoc path password
4746 gotoghyll (getnav ~
-1)
4757 Hashtbl.iter
(fun _ opaque ->
4759 Hashtbl.clear state
.prects
) state
.pagemap
;
4760 G.postRedisplay "dehighlight";
4762 | Ascii
(('
/'
| '?'
) as c) ->
4763 let ondone isforw
s =
4764 cbput state
.hists
.pat
s;
4765 state
.searchpattern
<- s;
4768 let s = String.make
1 c in
4769 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4770 textentry
, ondone (c = '
/'
), true)
4772 | Ascii '
+'
| Ascii '
='
when ctrl ->
4773 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4774 pivotzoom (conf
.zoom +. incr)
4779 try int_of_string
s with exn
->
4781 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4787 state
.text <- "page bias is now " ^ string_of_int
n;
4790 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4792 | Ascii '
-'
when ctrl ->
4793 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4794 pivotzoom (max
0.01 (conf
.zoom -. decr))
4797 let ondone msg
= state
.text <- msg
in
4799 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4800 optentry state
.mode, ondone, true
4803 | Ascii '
0'
when ctrl ->
4805 then gotoxy 0 state
.y
4808 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4810 match conf
.columns
with
4811 | Csingle
_ | Cmulti
_ -> 1
4812 | Csplit
(n, _) -> n
4814 let h = state
.winh
-
4815 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4817 let zoom = zoomforh state
.winw
h 0 cols in
4818 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4821 | Ascii '
3'
when ctrl ->
4823 match conf
.fitmodel
with
4824 | FitWidth
-> FitProportional
4825 | FitProportional
-> FitPage
4826 | FitPage
-> FitWidth
4828 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4829 reqlayout conf
.angle
fm
4831 | Ascii '
4'
when ctrl ->
4832 let zoom = getmaxw
() /. float state
.winw
in
4833 if zoom > 0.0 then setzoom zoom
4838 | Ascii '
9'
when ctrl ->
4841 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
4844 try int_of_string
s with exn
->
4845 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4851 cbput state
.hists
.pag
(string_of_int
n);
4852 gotopage1 (n + conf
.pagebias
- 1) 0;
4855 let [@warning
"-4"] pageentry
text = function
4856 | Keys.Ascii '
g'
-> TEdone
text
4857 | key -> intentry
text key
4859 let text = String.make
1 c in
4860 enttext (":", text, Some
(onhist state
.hists
.pag
),
4861 pageentry
, ondone, true)
4864 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4865 G.postRedisplay "toggle scrollbar";
4868 state
.bzoom
<- not state
.bzoom
;
4870 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4873 conf
.hlinks
<- not conf
.hlinks
;
4874 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4875 G.postRedisplay "toggle highlightlinks";
4878 if conf
.angle
mod 360 = 0
4880 state
.glinks
<- true;
4881 let mode = state
.mode in
4884 (":", E.s, None
, linknentry
, linknact gotounder, false),
4886 state
.glinks
<- false;
4890 G.postRedisplay "view:linkent(F)"
4892 else impmsg "hint mode does not work under rotation"
4895 state
.glinks
<- true;
4896 let mode = state
.mode in
4899 (":", E.s, None
, linknentry
,
4900 linknact (fun under -> selstring (undertext under)), false),
4902 state
.glinks
<- false;
4906 G.postRedisplay "view:linkent"
4909 begin match state
.autoscroll
with
4911 conf
.autoscrollstep
<- step
;
4912 state
.autoscroll
<- None
4914 state
.autoscroll
<- Some conf
.autoscrollstep
;
4915 state
.slideshow
<- state
.slideshow
land lnot
2
4918 | Ascii '
p'
when ctrl ->
4919 launchpath () (* XXX where do error messages go? *)
4922 setpresentationmode (not conf
.presentation
);
4923 showtext ' '
("presentation mode " ^
4924 if conf
.presentation
then "on" else "off");
4927 if List.mem
Wsi.Fullscreen state
.winstate
4928 then Wsi.reshape conf
.cwinw conf
.cwinh
4929 else Wsi.fullscreen
()
4931 | Ascii
('
p'
|'N'
) ->
4932 search state
.searchpattern
false
4934 | Ascii '
n'
| Fn
3 ->
4935 search state
.searchpattern
true
4938 begin match state
.layout with
4941 gotoghyll (getpagey
l.pageno)
4951 showtext ' '
(describe_location ());
4954 begin match state
.layout with
4957 Wsi.reshape l.pagew
l.pageh
;
4962 enterbookmarkmode
()
4964 | Ascii '
h'
| Fn
1 ->
4970 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4975 match state
.layout with
4980 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4983 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
4987 showtext ' '
"Quick bookmark added";
4990 begin match state
.layout with
4992 let rect = getpdimrect
l.pagedimno
in
4996 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4997 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4999 (truncate
(rect.(1) -. rect.(0)),
5000 truncate
(rect.(3) -. rect.(0)))
5002 let w = truncate
((float w)*.conf
.zoom)
5003 and h = truncate
((float h)*.conf
.zoom) in
5006 state
.anchor <- getanchor
();
5007 Wsi.reshape w (h + conf
.interpagespace
)
5009 G.postRedisplay "z";
5014 | Ascii '
x'
-> state
.roam
()
5016 | Ascii
('
<'
|'
>'
as c) ->
5018 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
5020 | Ascii
('
['
|'
]'
as c) ->
5022 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
5023 G.postRedisplay "brightness";
5025 | Ascii '
c'
when state
.mode = View
->
5030 let m = (state
.winw
- state
.w) / 2 in
5031 gotoxy_and_clear_text m state
.y
5035 match state
.prevcolumns
with
5036 | None
-> (1, 0, 0), 1.0
5037 | Some
(columns
, z
) ->
5040 | Csplit
(c, _) -> -c, 0, 0
5041 | Cmulti
((c, a, b), _) -> c, a, b
5042 | Csingle
_ -> 1, 0, 0
5046 setcolumns View
c a b;
5049 | Down
| Up
when ctrl && Wsi.withshift mask
->
5050 let zoom, x = state
.prevzoom
in
5055 begin match state
.autoscroll
with
5057 begin match state
.mode with
5058 | Birdseye beye
-> upbirdseye 1 beye
5059 | Textentry
_ | View
| LinkNav
_ ->
5061 then gotoxy_and_clear_text state
.x (clamp ~
-(state
.winh
/2))
5063 if not
(Wsi.withshift mask
) && conf
.presentation
5065 else gotoghyll1 true (clamp (-conf
.scrollstep
))
5069 setautoscrollspeed n false
5072 | Ascii 'j'
| Down
->
5073 begin match state
.autoscroll
with
5075 begin match state
.mode with
5076 | Birdseye beye
-> downbirdseye 1 beye
5077 | Textentry
_ | View
| LinkNav
_ ->
5079 then gotoxy_and_clear_text state
.x (clamp (state
.winh
/2))
5081 if not
(Wsi.withshift mask
) && conf
.presentation
5083 else gotoghyll1 true (clamp (conf
.scrollstep
))
5087 setautoscrollspeed n true
5090 | Left
| Right
when not
(Wsi.withalt mask
) ->
5096 else conf
.hscrollstep
5099 let pv = Wsi.kc2kt
key in
5100 if pv = Keys.Left
then dx else -dx
5102 gotoxy_and_clear_text (panbound (state
.x + dx)) state
.y
5105 G.postRedisplay "left/right"
5112 match state
.layout with
5114 | l :: _ -> state
.y - l.pagey
5116 clamp (pgscale (-state
.winh
))
5124 match List.rev state
.layout with
5126 | l :: _ -> getpagey
l.pageno
5128 clamp (pgscale state
.winh
)
5132 | Ascii '
g'
| Home
->
5135 | Ascii 'G'
| End
->
5137 gotoghyll (clamp state
.maxy)
5139 | Right
when Wsi.withalt mask
->
5140 gotoghyll (getnav 1)
5141 | 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 GlDraw.color (0.64, 0.64, 0.64) ~
alpha:0.7;
5471 filledrect (float x0) 0. (float x1) (float state
.winh
);
5473 (float hx0
) (float (state
.winh
- sbh))
5474 (float (hx0
+ state
.winw
)) (float state
.winh
)
5476 GlDraw.color (0.0, 0.0, 0.0) ~
alpha:0.7;
5478 filledrect (float x0) ph
(float x1) (ph
+. sh);
5479 let pw = pw +. float hx0
in
5480 filledrect pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5485 match state
.mstate
with
5486 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5489 | Msel
((x0, y0), (x1, y1)) ->
5490 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5491 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5492 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5493 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5500 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5501 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5503 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5505 if l.pageno = pageno
5507 let dx = float (l.pagedispx - l.pagex
) in
5508 let dy = float (l.pagedispy - l.pagey) in
5509 let r, g, b, alpha = c in
5510 GlDraw.color (r, g, b) ~
alpha;
5511 filledrect2 (x0+.dx) (y0+.dy)
5522 GlDraw.color (scalecolor2 conf
.bgcolor
);
5523 GlClear.color (scalecolor2 conf
.bgcolor
);
5524 GlClear.clear
[`
color];
5525 List.iter
drawpage state
.layout;
5527 match state
.mode with
5528 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5529 begin match getopaque pageno with
5531 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5532 let color = (0.0, 0.0, 0.5, 0.5) in
5534 (float x0, float y0,
5539 | None
-> state
.rects
5541 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5544 | View
-> state
.rects
5547 let rec postloop linkindexbase
= function
5549 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5550 postloop linkindexbase rest
5554 postloop 0 state
.layout;
5556 begin match state
.mstate
with
5557 | Mzoomrect
((x0, y0), (x1, y1)) ->
5559 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5560 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5561 filledrect (float x0) (float y0) (float x1) (float y1);
5565 | Mscrolly
| Mscrollx
5574 let zoomrect x y x1 y1 =
5577 and y0 = min
y y1 in
5578 let zoom = (float state
.w) /. float (x1 - x0) in
5581 if state
.w < state
.winw
5582 then (state
.winw
- state
.w) / 2
5585 match conf
.fitmodel
with
5586 | FitWidth
| FitProportional
-> simple ()
5588 match conf
.columns
with
5590 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5591 | Cmulti
_ | Csingle
_ -> simple ()
5593 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5594 state
.anchor <- getanchor
();
5599 let annot inline
x y =
5600 match unproject x y with
5601 | Some
(opaque, n, ux
, uy
) ->
5603 addannot
opaque ux uy
text;
5604 wcmd "freepage %s" (~
> opaque);
5605 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5607 gotoxy state
.x state
.y
5611 let ondone s = add s in
5612 let mode = state
.mode in
5613 state
.mode <- Textentry
(
5614 ("annotation: ", E.s, None
, textentry
, ondone, true),
5615 fun _ -> state
.mode <- mode);
5618 G.postRedisplay "annot"
5620 add @@ getusertext E.s
5625 let g opaque l px py =
5626 match rectofblock
opaque px py with
5628 let x0 = a.(0) -. 20. in
5629 let x1 = a.(1) +. 20. in
5630 let y0 = a.(2) -. 20. in
5631 let zoom = (float state
.w) /. (x1 -. x0) in
5632 let pagey = getpagey
l.pageno in
5633 let margin = (state
.w - l.pagew
)/2 in
5634 let nx = -truncate
x0 - margin in
5635 gotoxy_and_clear_text nx (pagey + truncate
y0);
5636 state
.anchor <- getanchor
();
5641 match conf
.columns
with
5643 impmsg "block zooming does not work properly in split columns mode"
5644 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5648 let winw = state
.winw - 1 in
5649 let s = float x /. float winw in
5650 let destx = truncate
(float (state
.w + winw) *. s) in
5651 gotoxy_and_clear_text (winw - destx) state
.y;
5652 state
.mstate
<- Mscrollx
;
5656 let s = float y /. float state
.winh
in
5657 let desty = truncate
(s *. float (maxy ())) in
5658 gotoxy_and_clear_text state
.x desty;
5659 state
.mstate
<- Mscrolly
;
5662 let viewmulticlick clicks
x y mask
=
5663 let g opaque l px py =
5671 if markunder
opaque px py mark
5675 match getopaque l.pageno with
5677 | Some
opaque -> pipesel opaque cmd
5679 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5680 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5685 G.postRedisplay "viewmulticlick";
5686 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5690 match conf
.columns
with
5692 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5695 let viewmouse button down
x y mask
=
5697 | n when (n == 4 || n == 5) && not down
->
5698 if Wsi.withctrl mask
5700 match state
.mstate
with
5701 | Mzoom
(oldn
, i
, (ftx
, fty
)) ->
5704 then abs
(ftx
- x) > 5 || abs
(fty
- y) > 5
5714 if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5716 if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5718 let zoom = conf
.zoom -. incr in
5720 then pivotzoom ~
x ~
y zoom
5721 else pivotzoom zoom;
5722 state
.mstate
<- Mzoom
(n, 0, (x, y));
5724 state
.mstate
<- Mzoom
(n, i
+1, (ftx
, fty
));
5726 else state
.mstate
<- Mzoom
(n, 0, (ftx
, fty
))
5730 | Mscrolly
| Mscrollx
5732 | Mnone
-> state
.mstate
<- Mzoom
(n, 0, (0, 0))
5735 match state
.autoscroll
with
5736 | Some step
-> setautoscrollspeed step
(n=4)
5738 if conf
.wheelbypage
|| conf
.presentation
5747 then -conf
.scrollstep
5748 else conf
.scrollstep
5750 let incr = incr * 2 in
5751 let y = clamp incr in
5752 gotoxy_and_clear_text state
.x y
5755 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5757 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5758 gotoxy_and_clear_text x state
.y
5760 | 1 when Wsi.withshift mask
->
5761 state
.mstate
<- Mnone
;
5764 match unproject x y with
5766 | Some
(_, pageno, ux
, uy
) ->
5767 let cmd = Printf.sprintf
5769 conf
.stcmd state
.path pageno ux uy
5771 match spawn
cmd [] with
5773 impmsg "execution of synctex command(%S) failed: %S"
5774 conf
.stcmd
@@ exntos exn
5778 | 1 when Wsi.withctrl mask
->
5781 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5782 state
.mstate
<- Mpan
(x, y)
5785 state
.mstate
<- Mnone
5790 if Wsi.withshift mask
5792 annot conf
.annotinline
x y;
5793 G.postRedisplay "addannot"
5797 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5798 state
.mstate
<- Mzoomrect
(p, p)
5801 match state
.mstate
with
5802 | Mzoomrect
((x0, y0), _) ->
5803 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5804 then zoomrect x0 y0 x y
5807 G.postRedisplay "kill accidental zoom rect";
5811 | Mscrolly
| Mscrollx
5813 | Mnone
-> resetmstate ()
5816 | 1 when vscrollhit x ->
5819 let _, position, sh = state
.uioh#
scrollph in
5820 if y > truncate
position && y < truncate
(position +. sh)
5821 then state
.mstate
<- Mscrolly
5824 state
.mstate
<- Mnone
5826 | 1 when y > state
.winh
- hscrollh () ->
5829 let _, position, sw = state
.uioh#scrollpw
in
5830 if x > truncate
position && x < truncate
(position +. sw)
5831 then state
.mstate
<- Mscrollx
5834 state
.mstate
<- Mnone
5836 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5839 let dest = if down
then getunder x y else Unone
in
5840 begin match dest with
5844 | Unone
when down
->
5845 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5846 state
.mstate
<- Mpan
(x, y);
5848 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5850 | Unone
| Utext
_ ->
5855 state
.mstate
<- Msel
((x, y), (x, y));
5856 G.postRedisplay "mouse select";
5860 match state
.mstate
with
5863 | Mzoom
_ | Mscrollx
| Mscrolly
->
5864 state
.mstate
<- Mnone
5866 | Mzoomrect
((x0, y0), _) ->
5870 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5871 state
.mstate
<- Mnone
5873 | Msel
((x0, y0), (x1, y1)) ->
5874 let rec loop = function
5878 let a0 = l.pagedispy in
5879 let a1 = a0 + l.pagevh in
5880 let b0 = l.pagedispx in
5881 let b1 = b0 + l.pagevw in
5882 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5883 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5887 match getopaque l.pageno with
5890 pipef ~closew
:false "Msel"
5893 G.postRedisplay "Msel") cmd
5895 dosel conf
.selcmd
();
5896 state
.roam
<- dosel conf
.paxcmd
;
5908 let birdseyemouse button down
x y mask
5909 (conf
, leftx
, _, hooverpageno
, anchor) =
5912 let rec loop = function
5915 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5916 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5918 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5924 | _ -> viewmouse button down
x y mask
5930 method key key mask
=
5931 begin match state
.mode with
5932 | Textentry textentry
-> textentrykeyboard
key mask textentry
5933 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5934 | View
-> viewkeyboard key mask
5935 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5939 method button button bstate
x y mask
=
5940 begin match state
.mode with
5941 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5942 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5947 method multiclick clicks
x y mask
=
5948 begin match state
.mode with
5949 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5950 | Birdseye
_ | Textentry
_ -> ()
5955 begin match state
.mode with
5957 | View
| Birdseye
_ | LinkNav
_ ->
5958 match state
.mstate
with
5959 | Mzoom
_ | Mnone
-> ()
5964 state
.mstate
<- Mpan
(x, y);
5965 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5967 gotoxy_and_clear_text x y
5970 state
.mstate
<- Msel
(a, (x, y));
5971 G.postRedisplay "motion select";
5974 let y = min state
.winh
(max
0 y) in
5978 let x = min state
.winw (max
0 x) in
5981 | Mzoomrect
(p0
, _) ->
5982 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5983 G.postRedisplay "motion zoomrect";
5987 method pmotion
x y =
5988 begin match state
.mode with
5989 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
5990 let rec loop = function
5992 if hooverpageno
!= -1
5994 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
5995 G.postRedisplay "pmotion birdseye no hoover";
5998 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5999 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6001 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
6002 G.postRedisplay "pmotion birdseye hoover";
6010 | LinkNav
_ | View
->
6011 match state
.mstate
with
6012 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
6020 let past, _, _ = !r in
6022 let delta = now -. past in
6025 else r := (now, x, y)
6029 method infochanged
_ = ()
6032 let maxy = maxy () in
6035 then 0.0, float state
.winh
6036 else scrollph state
.y maxy
6041 let fwinw = float (state
.winw - vscrollw ()) in
6043 let sw = fwinw /. float state
.w in
6044 let sw = fwinw *. sw in
6045 max
sw (float conf
.scrollh
)
6048 let maxx = state
.w + state
.winw in
6049 let x = state
.winw - state
.x in
6050 let percent = float x /. float maxx in
6051 (fwinw -. sw) *. percent
6053 hscrollh (), position, sw
6057 match state
.mode with
6058 | LinkNav
_ -> "links"
6059 | Textentry
_ -> "textentry"
6060 | Birdseye
_ -> "birdseye"
6063 findkeyhash conf
modename
6065 method eformsgs
= true
6066 method alwaysscrolly
= false
6067 method scroll dx dy =
6068 let x = if canpan () then panbound (state
.x + dx) else state
.x in
6069 gotoxy_and_clear_text x (clamp (2 * dy));
6072 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
6075 let addrect pageno r g b a x0 y0 x1 y1 =
6076 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
6080 let cl = splitatchar cmds ' '
in
6082 try Scanf.sscanf
s fmt
f
6083 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
6086 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
6087 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
6088 s pageno r g b a x0 y0 x1 y1;
6092 let _,w1,h1
,_ = getpagedim
pageno in
6093 let sw = float w1 /. float w
6094 and sh = float h1
/. float h in
6098 and y1s
= y1 *. sh in
6099 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
6100 let color = (r, g, b, a) in
6101 if conf
.verbose
then debugrect rect;
6102 state
.rects <- (pageno, color, rect) :: state
.rects;
6107 | "reload", "" -> reload ()
6109 scan args
"%u %f %f"
6111 let cmd, _ = state
.geomcmds
in
6113 then gotopagexy !wtmode pageno x y
6116 gotopagexy !wtmode pageno x y;
6119 state
.reprf
<- f state
.reprf
6121 | "goto1", args
-> scan args
"%u %f" gotopage
6122 | "gotor", args
-> scan args
"%S" gotoremote
6124 scan args
"%u %u %f %f %f %f"
6125 (fun pageno c x0 y0 x1 y1 ->
6126 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
6127 rectx "rect" pageno color x0 y0 x1 y1;
6130 scan args
"%u %f %f %f %f %f %f %f %f"
6131 (fun pageno r g b alpha x0 y0 x1 y1 ->
6132 addrect pageno r g b alpha x0 y0 x1 y1;
6133 G.postRedisplay "prect"
6136 scan args
"%u %f %f"
6139 match getopaque pageno with
6140 | Some
opaque -> opaque
6143 pgoto optopaque pageno x y;
6144 let rec fixx = function
6147 if l.pageno = pageno
6148 then gotoxy (state
.x - l.pagedispx) state
.y
6153 match conf
.columns
with
6154 | Csingle
_ | Csplit
_ -> 1
6155 | Cmulti
((n, _, _), _) -> n
6157 layout 0 state
.y (state
.winw * mult) state
.winh
6161 | "activatewin", "" -> Wsi.activatewin
()
6162 | "quit", "" -> raise Quit
6165 let l = Config.keys_of_string
keys in
6166 List.iter
(fun (k
, m) -> keyboard k
m) l
6167 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
6170 | "clearrects", "" ->
6171 Hashtbl.clear state
.prects
;
6172 G.postRedisplay "clearrects"
6174 adderrfmt "remote command"
6175 "error processing remote command: %S\n" cmds
;
6179 let scratch = Bytes.create
80 in
6180 let buf = Buffer.create
80 in
6182 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
6183 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
6186 if Buffer.length
buf > 0
6188 let s = Buffer.contents
buf in
6196 match Bytes.index_from
scratch ppos '
\n'
with
6197 | pos
-> if pos
>= n then -1 else pos
6198 | exception Not_found
-> -1
6202 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
6203 let s = Buffer.contents
buf in
6209 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
6215 let remoteopen path =
6216 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
6218 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
6223 let gcconfig = ref false in
6224 let trimcachepath = ref E.s in
6225 let rcmdpath = ref E.s in
6226 let pageno = ref None
in
6227 let rootwid = ref 0 in
6228 let openlast = ref false in
6229 let doreap = ref false in
6230 let csspath = ref None
in
6231 selfexec := Sys.executable_name
;
6234 [("-p", Arg.String
(fun s -> state
.password <- s),
6235 "<password> Set password");
6239 Config.fontpath
:= s;
6240 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
6242 "<path> Set path to the user interface font");
6246 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
6247 Config.confpath
:= s),
6248 "<path> Set path to the configuration file");
6250 ("-last", Arg.Set
openlast, " Open last document");
6252 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
6253 "<page-number> Jump to page");
6255 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6256 "<path> Set path to the trim cache file");
6258 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
6259 "<named-destination> Set named destination");
6261 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
6262 ("-cxack", Arg.Set
cxack, " Cut corners");
6264 ("-remote", Arg.String
(fun s -> rcmdpath := s),
6265 "<path> Set path to the source of remote commands");
6267 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
6269 ("-v", Arg.Unit
(fun () ->
6271 "%s\nconfiguration path: %s\n"
6274 exit
0), " Print version and exit");
6276 ("-css", Arg.String
(fun s -> csspath := Some
s),
6277 "<path> Set path to the style sheet to use with EPUB/HTML");
6279 ("-embed", Arg.Set_int
rootwid, "<window-id> Embed into window");
6281 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
6282 "<origin> <undocumented>");
6285 (fun s -> state
.path <- s)
6286 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
6289 then selfexec := !selfexec ^
" -wtmode";
6291 let histmode = emptystr state
.path && not
!openlast in
6293 if not
(Config.load !openlast)
6294 then dolog
"failed to load configuration";
6296 begin match !pageno with
6297 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6309 val mutable m_clicks
= 0
6310 val mutable m_click_x
= 0
6311 val mutable m_click_y
= 0
6312 val mutable m_lastclicktime
= infinity
6314 method private cleanup =
6315 state
.roam
<- noroam
;
6316 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6317 method expose
= G.postRedisplay "expose"
6321 | Wsi.Unobscured
-> "unobscured"
6322 | Wsi.PartiallyObscured
-> "partiallyobscured"
6323 | Wsi.FullyObscured
-> "fullyobscured"
6325 vlog "visibility change %s" name
6326 method display = display ()
6327 method map mapped
= vlog "mapped %b" mapped
6328 method reshape w h =
6331 method mouse
b d x y m =
6332 if d && canselect ()
6335 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6342 if abs
x - m_click_x
> 10
6343 || abs
y - m_click_y
> 10
6344 || abs_float
(t -. m_lastclicktime
) > 0.3
6346 m_clicks
<- m_clicks
+ 1;
6347 m_lastclicktime
<- t;
6351 G.postRedisplay "cleanup";
6352 state
.uioh <- state
.uioh#button
b d x y m;
6354 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6359 m_lastclicktime
<- infinity
;
6360 state
.uioh <- state
.uioh#button
b d x y m
6364 state
.uioh <- state
.uioh#button
b d x y m
6367 state
.mpos
<- (x, y);
6368 state
.uioh <- state
.uioh#motion
x y
6369 method pmotion
x y =
6370 state
.mpos
<- (x, y);
6371 state
.uioh <- state
.uioh#pmotion
x y
6373 vlog "k=%#x m=%#x" k
m;
6374 let mascm = m land (
6375 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6378 let x = state
.x and y = state
.y in
6380 if x != state
.x || y != state
.y then self#
cleanup
6382 match state
.keystate
with
6384 let km = k
, mascm in
6387 let modehash = state
.uioh#
modehash in
6388 try Hashtbl.find modehash km
6390 try Hashtbl.find (findkeyhash conf
"global") km
6391 with Not_found
-> KMinsrt
(k
, m)
6393 | KMinsrt
(k
, m) -> keyboard k
m
6394 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6395 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6397 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6398 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6399 state
.keystate
<- KSnone
6400 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6401 state
.keystate
<- KSinto
(keys, insrt
)
6402 | KSinto
_ -> state
.keystate
<- KSnone
6405 state
.mpos
<- (x, y);
6406 state
.uioh <- state
.uioh#pmotion
x y
6407 method leave = state
.mpos
<- (-1, -1)
6408 method winstate wsl
= state
.winstate
<- wsl
6409 method quit
: '
a. '
a = raise Quit
6410 method scroll dx dy = state
.uioh <- state
.uioh#
scroll dx dy
6411 method zoom z
x y = state
.uioh#
zoom z
x y
6412 method opendoc path =
6415 G.postRedisplay "opendoc";
6416 opendoc path state
.password
6419 let wsfd, winw, winh
= Wsi.init
mu !rootwid conf
.cwinw conf
.cwinh platform
in
6421 setbgcol conf
.bgcolor
;
6424 if not
@@ List.exists
GlMisc.check_extension
6425 [ "GL_ARB_texture_rectangle"
6426 ; "GL_EXT_texture_recangle"
6427 ; "GL_NV_texture_rectangle" ]
6428 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6430 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6432 defconf
.sliceheight
<- 1024;
6433 defconf
.texcount
<- 32;
6434 defconf
.usepbo
<- true;
6438 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6440 dolog
"socketpair failed: %s" @@ exntos exn
;
6448 setcheckers conf
.checkers
;
6450 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6452 begin match !csspath with
6454 | Some
"" -> conf
.css
<- E.s
6456 let css = filecontents
path in
6457 let l = String.length
css in
6459 if substratis
css (l-2) "\r\n"
6460 then String.sub css 0 (l-2)
6461 else (if css.[l-1] = '
\n'
6462 then String.sub css 0 (l-1)
6466 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6467 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6468 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6470 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6472 reshape ~firsttime
:true winw winh
;
6476 Wsi.settitle
"llpp (history)";
6480 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6481 opendoc state
.path state
.password;
6485 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6486 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6489 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6490 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6491 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6493 | _pid
, _status
-> reap ()
6495 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6499 if nonemptystr
!rcmdpath
6500 then remoteopen !rcmdpath
6505 let rec loop deadline
=
6511 let r = [state
.ss; state
.wsfd] in
6515 | Some fd
-> fd
:: r
6519 state
.redisplay
<- false;
6526 if deadline
= infinity
6528 else max
0.0 (deadline
-. now)
6533 try Unix.select
r [] [] timeout
6534 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6540 if state
.ghyll
== noghyll
6542 match state
.autoscroll
with
6543 | Some step
when step
!= 0 ->
6544 if state
.slideshow
land 1 = 1
6546 if state
.slideshow
land 2 = 0
6547 then state
.slideshow
<- state
.slideshow
lor 2
6548 else if step
< 0 then prevpage () else nextpage ();
6549 deadline
+. (float (abs step
))
6552 let y = state
.y + step
in
6553 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6556 then state
.maxy - fy
6557 else if y >= state
.maxy - fy then 0 else y
6559 if state
.mode = View
6560 then gotoxy_and_clear_text state
.x y
6561 else gotoxy state
.x y;
6564 else deadline
+. 0.01
6569 let rec checkfds = function
6571 | fd
:: rest
when fd
= state
.ss ->
6572 let cmd = rcmd state
.ss in
6576 | fd
:: rest
when fd
= state
.wsfd ->
6580 | fd
:: rest
when Some fd
= !optrfd ->
6581 begin match remote fd
with
6582 | None
-> optrfd := remoteopen !rcmdpath;
6583 | opt -> optrfd := opt
6588 dolog
"select returned unknown descriptor";
6594 if deadline
= infinity
6598 match state
.autoscroll
with
6599 | Some step
when step
!= 0 -> deadline1
6600 | _ -> if state
.ghyll
== noghyll
then infinity
else deadline1
6605 match loop infinity
with
6607 Config.save leavebirdseye;
6608 if hasunsavedchanges
()
6610 | _ -> error
"umpossible - infinity reached"