5 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
6 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
7 external hassel
: opaque
-> bool = "ml_hassel";;
8 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
9 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
10 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
11 external clearmark
: opaque
-> unit = "ml_clearmark";;
12 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
13 external getmaxw
: unit -> float = "ml_getmaxw";;
14 external postprocess
: opaque
-> int -> int -> int -> (int * string * int)
15 -> int = "ml_postprocess";;
16 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
17 external setaalevel
: int -> unit = "ml_setaalevel";;
18 external realloctexts
: int -> bool = "ml_realloctexts";;
19 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
20 external getlink
: opaque
-> int -> under
= "ml_getlink";;
21 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
22 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
23 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
24 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
25 external freepbo
: opaque
-> unit = "ml_freepbo";;
26 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
27 external bousable
: unit -> bool = "ml_bo_usable";;
28 external unproject
: opaque
-> int -> int
29 -> (int * int) option = "ml_unproject";;
30 external project
: opaque
-> int -> int -> float -> float
31 -> (float * float) = "ml_project";;
32 external drawtile
: tileparams
-> opaque
33 -> unit = "ml_drawtile";;
34 external rectofblock
: opaque
-> int -> int
35 -> float array
option = "ml_rectofblock";;
36 external begintiles
: unit -> unit = "ml_begintiles";;
37 external endtiles
: unit -> unit = "ml_endtiles";;
38 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
39 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
40 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
41 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
42 external savedoc
: string -> unit = "ml_savedoc";;
43 external getannotcontents
: opaque
-> slinkindex
44 -> string = "ml_getannotcontents";;
45 external drawprect
: opaque
-> int -> int -> float array
46 -> unit = "ml_drawprect";;
47 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
48 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
49 external uritolocation
: string
50 -> (pageno
* float * float) = "ml_uritolocation";;
51 external isexternallink
: string -> bool = "ml_isexternallink";;
53 (* copysel _will_ close the supplied descriptor *)
54 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
56 let selfexec = ref E.s
;;
57 let ignoredoctitlte = ref false;;
58 let opengl_has_pbo = ref false;;
59 let layouth = ref ~
-1;;
73 l
.pagedispx l
.pagedispy
77 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
83 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
86 let isbirdseye = function
88 | Textentry _
| View
| LinkNav _
-> false
91 let istextentry = function
93 | Birdseye _
| View
| LinkNav _
-> false
96 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
99 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
100 && (state
.w
> state
.winw
))
106 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbvv
!= 0)
107 && (state
.maxy
> state
.winh
))
115 else x
> state
.winw
- vscrollw ()
119 fstate
.fontsize
<- n
;
120 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
121 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
127 else Printf.kprintf ignore fmt
131 if emptystr conf
.pathlauncher
132 then dolog
"%s" state
.path
134 let command = Str.global_replace percentsre state
.path conf
.pathlauncher
in
135 match spawn
command [] with
138 dolog
"failed to execute `%s': %s" command @@ exntos exn
144 let postRedisplay who
=
145 vlog "redisplay for [%S]" who
;
146 state
.redisplay
<- true;
151 let getopaque pageno
=
152 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
153 with Not_found
-> None
156 let pagetranslatepoint l x y
=
157 let dy = y
- l
.pagedispy
in
158 let y = dy + l
.pagey
in
159 let dx = x
- l
.pagedispx
in
160 let x = dx + l
.pagex
in
164 let onppundermouse g
x y d
=
167 begin match getopaque l
.pageno
with
169 let x0 = l
.pagedispx
in
170 let x1 = x0 + l
.pagevw
in
171 let y0 = l
.pagedispy
in
172 let y1 = y0 + l
.pagevh
in
173 if y >= y0 && y <= y1 && x >= x0 && x <= x1
175 let px, py
= pagetranslatepoint l
x y in
176 match g opaque l
px py
with
189 let g opaque l
px py
=
192 match rectofblock opaque
px py
with
193 | Some
[|x0;x1;y0;y1|] ->
194 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
195 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
196 state
.rects
<- [l
.pageno
, color, rect];
197 G.postRedisplay "getunder";
200 let under = whatsunder opaque
px py
in
201 if under = Unone
then None
else Some
under
203 onppundermouse g x y Unone
208 match unproject opaque
x y with
209 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
212 onppundermouse g x y None
;
216 state
.text
<- Printf.sprintf
"%c%s" c s
;
217 G.postRedisplay "showtext";
221 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
224 let pipesel opaque cmd
=
226 then pipef ~closew
:false "pipesel"
229 G.postRedisplay "pipesel"
234 let g opaque l
px py
=
235 if markunder opaque
px py conf
.paxmark
238 match getopaque l
.pageno
with
240 | Some opaque
-> pipesel opaque conf
.paxcmd
245 G.postRedisplay "paxunder";
246 if conf
.paxmark
= Mark_page
249 match getopaque l
.pageno
with
251 | Some opaque
-> clearmark opaque
) state
.layout
;
252 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
255 let undertext = function
258 | Utext s
-> "font: " ^ s
259 | Uannotation
(opaque
, slinkindex
) ->
260 "annotation: " ^ getannotcontents opaque slinkindex
263 let updateunder x y =
264 match getunder x y with
265 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
267 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
268 Wsi.setcursor
Wsi.CURSOR_INFO
270 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
271 Wsi.setcursor
Wsi.CURSOR_TEXT
273 if conf
.underinfo
then showtext 'a'
"nnotation";
274 Wsi.setcursor
Wsi.CURSOR_INFO
277 let showlinktype under =
278 if conf
.underinfo
&& under != Unone
279 then showtext ' '
@@ undertext under
282 let [@warning
"-4"] intentry_with_suffix text key
=
285 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
286 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
287 addchar
text @@ asciilower c
289 state
.text <- Printf.sprintf
"invalid key";
296 let b = Buffer.create
16 in
299 let b = Buffer.to_bytes
b in
300 wcmd state
.ss
b @@ Bytes.length
b
304 let nogeomcmds cmds
=
306 | s
, [] -> emptystr s
310 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
311 let rec fold accu n
=
312 if n
= Array.length
b
315 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n
) in
318 || n
= state
.pagecount
- coverB
319 || (n
- coverA
) mod columns
= columns
- 1)
325 let pagey = max
0 (y - vy
) in
326 let pagedispy = if pagey > 0 then 0 else vy
- y in
327 let pagedispx, pagex
=
329 if n
= coverA
- 1 || n
= state
.pagecount
- coverB
330 then x + (sw
- w
) / 2
338 let vw = sw
- pagedispx in
339 let pw = w
- pagex
in
342 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
343 if pagevw > 0 && pagevh > 0
354 ; pagedispx = pagedispx
355 ; pagedispy = pagedispy
367 if Array.length
b = 0
369 else List.rev
(fold [] (page_of_y
y))
372 let layoutS (columns
, b) x y sw sh
=
373 let rec fold accu n
=
374 if n
= Array.length
b
377 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n
) in
385 let pagey = max
0 (y - vy
) in
386 let pagedispy = if pagey > 0 then 0 else vy
- y in
387 let pagedispx, pagex
=
401 let pagecolw = pagew
/columns
in
404 then pagedispx + ((sw
- pagecolw) / 2)
408 let vw = sw
- pagedispx in
409 let pw = pagew
- pagex
in
412 let pagevw = min
pagevw pagecolw in
413 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
414 if pagevw > 0 && pagevh > 0
425 ; pagedispx = pagedispx
426 ; pagedispy = pagedispy
427 ; pagecol
= n
mod columns
441 let layout x y sw sh
=
442 if nogeomcmds state
.geomcmds
444 match conf
.columns
with
445 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
446 | Cmulti c
-> layoutN c
x y sw sh
447 | Csplit s
-> layoutS s
x y sw sh
451 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
453 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
456 let tilex = l
.pagex
mod conf
.tilew
in
457 let tiley = l
.pagey mod conf
.tileh
in
459 let col = l
.pagex
/ conf
.tilew
in
460 let row = l
.pagey / conf
.tileh
in
462 let rec rowloop row y0 dispy h
=
466 let dh = conf
.tileh
- y0 in
468 let rec colloop col x0 dispx w
=
472 let dw = conf
.tilew
- x0 in
474 f col row dispx dispy
x0 y0 dw dh;
475 colloop (col+1) 0 (dispx
+dw) (w
-dw)
478 colloop col tilex l
.pagedispx l
.pagevw;
479 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
482 if l
.pagevw > 0 && l
.pagevh > 0
483 then rowloop row tiley l
.pagedispy l
.pagevh;
486 let gettileopaque l
col row =
488 l
.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l
.pagew
, l
.pageh
, col, row
490 try Some
(Hashtbl.find state
.tilemap
key)
491 with Not_found
-> None
494 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
495 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
496 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
499 let drawtiles l
color =
502 let f col row x y tilex tiley w h
=
503 match gettileopaque l
col row with
504 | Some
(opaque
, _
, t
) ->
505 let params = x, y, w
, h
, tilex, tiley in
507 then GlTex.env
(`mode `blend
);
508 drawtile
params opaque
;
510 then GlTex.env
(`mode `modulate
);
514 let s = Printf.sprintf
518 let w = measurestr fstate
.fontsize
s in
519 GlDraw.color (0.0, 0.0, 0.0);
520 filledrect
(float (x-2))
523 (float (y + fstate
.fontsize
+ 2));
525 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
532 let lw = state
.winw
- x in
535 let lh = state
.winh
- y in
539 then GlTex.env
(`mode `blend
);
540 begin match state
.checkerstexid
with
542 Gl.enable `texture_2d
;
543 GlTex.bind_texture ~target
:`texture_2d id
;
547 and y1 = float (y+h
) in
549 let tw = float w /. 16.0
550 and th
= float h
/. 16.0 in
551 let tx0 = float tilex /. 16.0
552 and ty0
= float tiley /. 16.0 in
554 and ty1
= ty0
+. th
in
555 Raw.sets_float
Glutils.vraw ~pos
:0
556 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
557 Raw.sets_float
Glutils.traw ~pos
:0
558 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
559 GlArray.vertex `two
Glutils.vraw
;
560 GlArray.tex_coord `two
Glutils.traw
;
561 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
562 Gl.disable `texture_2d
;
565 GlDraw.color (1.0, 1.0, 1.0);
566 filledrect
(float x) (float y) (float (x+w)) (float (y+h
));
569 then GlTex.env
(`mode `modulate
);
570 if w > 128 && h
> fstate
.fontsize
+ 10
572 let c = if conf
.invert
then 1.0 else 0.0 in
573 GlDraw.color (c, c, c);
576 then (col*conf
.tilew
, row*conf
.tileh
)
579 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
588 let pagevisible layout n
= List.exists
(fun l
-> l
.pageno
= n
) layout;;
590 let tilevisible1 l
x y =
592 and ax1
= l
.pagex
+ l
.pagevw
594 and ay1
= l
.pagey + l
.pagevh in
598 let bx1 = min
(bx0 + conf
.tilew
) l
.pagew
599 and by1
= min
(by0
+ conf
.tileh
) l
.pageh
in
601 let rx0 = max
ax0 bx0
602 and ry0
= max ay0 by0
603 and rx1
= min ax1
bx1
604 and ry1
= min ay1 by1
in
606 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
610 let tilevisible layout n
x y =
611 let rec findpageinlayout m
= function
612 | l
:: rest
when l
.pageno
= n
->
613 tilevisible1 l
x y || (
614 match conf
.columns
with
615 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
616 | Csplit _
| Csingle _
| Cmulti _
-> false
618 | _
:: rest
-> findpageinlayout 0 rest
621 findpageinlayout 0 layout;
624 let tileready l
x y =
625 tilevisible1 l
x y &&
626 gettileopaque l
(x/conf
.tilew
) (y/conf
.tileh
) != None
629 let tilepage n p
layout =
630 let rec loop = function
634 let f col row _ _ _ _ _ _
=
635 if state
.currently
= Idle
637 match gettileopaque l
col row with
640 let x = col*conf
.tilew
641 and y = row*conf
.tileh
in
643 let w = l
.pagew
- x in
647 let h = l
.pageh
- y in
652 then getpbo
w h conf
.colorspace
655 wcmd "tile %s %d %d %d %d %s"
656 (~
> p
) x y w h (~
> pbo);
659 l
, p
, conf
.colorspace
, conf
.angle
,
660 state
.gen
, col, row, conf
.tilew
, conf
.tileh
669 if nogeomcmds state
.geomcmds
673 let preloadlayout x y sw sh
=
674 let y = if y < sh
then 0 else y - sh
in
675 let x = min
0 (x + sw
) in
683 if state
.currently
!= Idle
688 begin match getopaque l
.pageno
with
690 wcmd "page %d %d" l
.pageno l
.pagedimno
;
691 state
.currently
<- Loading
(l
, state
.gen
);
693 tilepage l
.pageno opaque pages
;
698 if nogeomcmds state
.geomcmds
704 if conf
.preload && state
.currently
= Idle
705 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
708 let layoutready layout =
709 let rec fold all ls
=
712 let seen = ref false in
713 let allvisible = ref true in
714 let foo col row _ _ _ _ _ _
=
716 allvisible := !allvisible &&
717 begin match gettileopaque l
col row with
723 fold (!seen && !allvisible) rest
726 let alltilesvisible = fold true layout in
731 let y = bound
y 0 state
.maxy in
733 let layout = layout x y state
.winw state
.winh
in
734 G.postRedisplay "gotoxy ready";
739 state
.layout <- layout;
740 begin match state
.mode
with
743 | Ltexact
(pageno
, linkno
) ->
744 let rec loop = function
746 state
.lnava
<- Some
(pageno
, linkno
);
747 state
.mode
<- LinkNav
(Ltgendir
0)
748 | l
:: _
when l
.pageno
= pageno
->
749 begin match getopaque pageno
with
750 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
752 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
753 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
754 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
755 then state
.mode
<- LinkNav
(Ltgendir
0)
757 | _
:: rest
-> loop rest
760 | Ltnotready _
| Ltgendir _
-> ()
762 | Birdseye _
| Textentry _
| View
-> ()
764 begin match state
.mode
with
765 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
766 if not
(pagevisible layout pageno
)
768 match state
.layout with
771 state
.mode
<- Birdseye
(
772 conf
, leftx
, l
.pageno
, hooverpageno
, anchor
777 | Ltnotready
(_
, dir
)
780 let rec loop = function
783 match getopaque l
.pageno
with
784 | None
-> Ltnotready
(l
.pageno
, dir
)
789 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
791 if dir
> 0 then LDfirst
else LDlast
797 | Lnotfound
-> loop rest
799 showlinktype (getlink opaque n
);
800 Ltexact
(l
.pageno
, n
)
804 state
.mode
<- LinkNav
linknav
807 | Textentry _
| View
-> ()
812 let mx, my
= state
.mpos
in
817 let conttiling pageno opaque
=
818 tilepage pageno opaque
820 then preloadlayout state
.x state
.y state
.winw state
.winh
825 if not conf
.verbose
then state
.text <- E.s;
829 let getanchory (n
, top
, dtop
) =
830 let y, h = getpageyh n
in
833 let ips = calcips
h in
834 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
836 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
839 let gotoanchor anchor
=
840 gotoxy state
.x (getanchory anchor
);
844 getanchor
() |> cbput state
.hists
.nav
;
848 getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;
852 let anchor = cbgetc state
.hists
.nav dir
in
857 let y, h = getpageyh n
in
858 let y = y + (truncate
(top
*. float h)) in
862 let gotopage1 n top
=
863 let y = getpagey n
in
869 state
.redisplay
<- false;
874 match state
.geomcmds
with
875 | ps
, [] when emptystr ps
->
877 state
.geomcmds
<- s, [];
880 state
.geomcmds
<- ps
, [s, f];
882 | ps
, (s'
, _
) :: rest
when s'
= s ->
883 state
.geomcmds
<- ps
, ((s, f) :: rest
);
886 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
890 Hashtbl.iter
(fun _ opaque
->
891 wcmd "freepage %s" (~
> opaque
);
893 Hashtbl.clear state
.pagemap
;
897 if not
(Queue.is_empty state
.tilelru
)
899 Queue.iter
(fun (k
, p
, s) ->
900 wcmd "freetile %s" (~
> p
);
901 state
.memused
<- state
.memused
- s;
902 Hashtbl.remove state
.tilemap k
;
904 state
.uioh#infochanged Memused
;
905 Queue.clear state
.tilelru
;
911 let h = truncate
(float h*.conf
.zoom
) in
912 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
918 let sl = keystostrlist conf
in
920 function | [] -> accu
921 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
922 in makehelp
() @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
925 let opendoc path password
=
927 state
.password
<- password
;
928 state
.gen
<- state
.gen
+ 1;
930 state
.outlines
<- [||];
933 setaalevel conf
.aalevel
;
935 if emptystr state
.origin
939 Wsi.settitle
("llpp " ^ mbtoutf8
(Filename.basename
titlepath));
940 wcmd "open %d %d %s\000%s\000%s\000"
941 (btod conf
.usedoccss
) !layouth
942 path password conf
.css
;
943 invalidate "reqlayout"
945 wcmd "reqlayout %d %d %d %s\000"
946 conf
.angle
(FMTE.to_int conf
.fitmodel
)
947 (stateh state
.winh
) state
.nameddest
953 state
.anchor <- getanchor
();
954 opendoc state
.path state
.password
;
958 let c = c *. conf
.colorscale
in
962 let scalecolor2 (r
, g, b) =
963 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
966 let docolumns columns
=
969 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
970 let rec loop pageno
pdimno pdim
y ph pdims
=
971 if pageno
= state
.pagecount
974 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
976 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
981 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
983 y + (if conf
.presentation
984 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
985 else (if pageno
= 0 then 0 else conf
.interpagespace
)
988 a.(pageno
) <- (pdimno, x, y, pdim
);
989 loop (pageno
+1) pdimno pdim
(y + h) h pdims
991 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
992 conf
.columns
<- Csingle
a;
994 | Cmulti
((columns
, coverA
, coverB
), _
) ->
995 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
996 let rec loop pageno
pdimno pdim
x y rowh pdims
=
998 if m
= pageno
then () else
999 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1002 let y = y + (rowh
- h) / 2 in
1003 a.(m
) <- (pdimno, x, y, pdim
);
1007 if pageno
= state
.pagecount
1008 then fixrow (((pageno
- 1) / columns
) * columns
)
1010 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1012 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1013 pdimno+1, pdim
, rest
1018 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
1020 let x = (state
.winw
- w) / 2 in
1022 if conf
.presentation
then calcips
h else conf
.interpagespace
in
1023 x, y + ips + rowh
, h
1026 if (pageno
- coverA
) mod columns
= 0
1028 let x = max
0 (state
.winw
- state
.w) / 2 in
1030 if conf
.presentation
1032 let ips = calcips
h in
1033 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
1035 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
1039 else x, y, max rowh
h
1043 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1046 if pageno
= columns
&& conf
.presentation
1048 let ips = calcips rowh
in
1049 for i
= 0 to pred columns
1051 let (pdimno, x, y, pdim
) = a.(i
) in
1052 a.(i
) <- (pdimno, x, y+ips, pdim
)
1058 fixrow (pageno
- columns
);
1063 a.(pageno
) <- (pdimno, x, y, pdim
);
1064 let x = x + w + xoff
*2 + conf
.interpagespace
in
1065 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1067 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1068 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1071 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1072 let rec loop pageno
pdimno pdim
y pdims
=
1073 if pageno
= state
.pagecount
1076 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1078 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1079 pdimno+1, pdim
, rest
1084 let rec loop1 n
x y =
1085 if n
= c then y else (
1086 a.(pageno
*c + n
) <- (pdimno, x, y, pdim
);
1087 loop1 (n
+1) (x+cw) (y + h + conf
.interpagespace
)
1090 let y = loop1 0 0 y in
1091 loop (pageno
+1) pdimno pdim
y pdims
1093 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1094 conf
.columns
<- Csplit
(c, a);
1098 docolumns conf
.columns
;
1099 state
.maxy <- calcheight
();
1100 if state
.reprf
== noreprf
1102 match state
.mode
with
1103 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1104 let y, h = getpageyh pageno
in
1105 let top = (state
.winh
- h) / 2 in
1106 gotoxy state
.x (max
0 (y - top))
1107 | Textentry _
| View
| LinkNav _
->
1108 let y = getanchory state
.anchor in
1109 let y = min
y (state
.maxy - state
.winh
) in
1114 state
.reprf
<- noreprf
;
1118 let reshape ?
(firsttime
=false) w h =
1119 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1120 if not firsttime
&& nogeomcmds state
.geomcmds
1121 then state
.anchor <- getanchor
();
1124 let w = truncate
(float w *. conf
.zoom
) in
1127 setfontsize fstate
.fontsize
;
1128 GlMat.mode `modelview
;
1129 GlMat.load_identity
();
1131 GlMat.mode `projection
;
1132 GlMat.load_identity
();
1133 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1134 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1135 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1140 else float state
.x /. float state
.w
1142 invalidate "geometry"
1146 then state
.x <- truncate
(relx *. float w);
1148 match conf
.columns
with
1150 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1151 | Csplit
(c, _
) -> w * c
1153 wcmd "geometry %d %d %d"
1154 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1159 let len = String.length state
.text in
1160 let x0 = if conf
.leftscroll
then vscrollw () else 0 in
1163 match state
.mode
with
1164 | Textentry _
| View
| LinkNav _
->
1165 let h, _
, _
= state
.uioh#scrollpw
in
1171 x (float (state
.winh
- (fstate
.fontsize
+ 4) - hscrollh))
1172 (x+.w) (float (state
.winh
- hscrollh))
1175 let w = float (state
.winw
- 1 - vscrollw ()) in
1176 if state
.progress
>= 0.0 && state
.progress
< 1.0
1178 GlDraw.color (0.3, 0.3, 0.3);
1179 let w1 = w *. state
.progress
in
1181 GlDraw.color (0.0, 0.0, 0.0);
1182 rect (float x0+.w1) (float x0+.w-.w1)
1185 GlDraw.color (0.0, 0.0, 0.0);
1189 GlDraw.color (1.0, 1.0, 1.0);
1192 (if conf
.leftscroll
then x0 + 2 else x0 + if len > 0 then 8 else 2)
1193 (state
.winh
- hscrollh - 5) s;
1196 match state
.mode
with
1197 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1200 then Printf.sprintf
"%s%s_ [%s]" prefix
text state
.text
1201 else Printf.sprintf
"%s%s_" prefix
text
1205 | Birdseye _
| View
| LinkNav _
-> state
.text
1210 if not
(istextentry state
.mode
) && state
.uioh#eformsgs
1212 let s1 = "(press 'e' to review error messasges)" in
1213 if nonemptystr
s then s ^
" " ^
s1 else s1
1223 let len = Queue.length state
.tilelru
in
1224 let layout = lazy (if conf
.preload
1225 then preloadlayout state
.x state
.y state
.winw state
.winh
1226 else state
.layout) in
1228 if state
.memused
> conf
.memlimit
1232 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1233 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1234 let (_
, pw, ph
, _
) = getpagedim
n in
1236 && colorspace
= conf
.colorspace
1237 && angle
= conf
.angle
1241 let x = col*conf
.tilew
1242 and y = row*conf
.tileh
in
1243 tilevisible (Lazy.force_val
layout) n x y
1245 then Queue.push lruitem state
.tilelru
1248 wcmd "freetile %s" (~
> p
);
1249 state
.memused
<- state
.memused
- s;
1250 state
.uioh#infochanged Memused
;
1251 Hashtbl.remove state
.tilemap k
;
1259 let onpagerect pageno
f =
1261 match conf
.columns
with
1262 | Cmulti
(_
, b) -> b
1264 | Csplit
(_
, b) -> b
1266 if pageno
>= 0 && pageno
< Array.length
b
1268 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1272 let gotopagexy1 pageno
x y =
1273 let _,w1,h1
,leftx
= getpagedim pageno
in
1274 let top = y /. (float h1
) in
1275 let left = x /. (float w1) in
1276 let py, w, h = getpageywh pageno
in
1277 let wh = state
.winh
in
1278 let x = left *. (float w) in
1279 let x = leftx
+ state
.x + truncate
x in
1281 if x < 0 || x >= state
.winw
1285 let pdy = truncate
(top *. float h) in
1286 let y'
= py + pdy in
1287 let dy = y'
- state
.y in
1289 if x != state
.x || not
(dy > 0 && dy < wh)
1291 if conf
.presentation
1293 if abs
(py - y'
) > wh
1300 if state
.x != sx || state
.y != sy
1302 else gotoxy state
.x state
.y;
1305 let gotopagexy pageno
x y =
1306 match state
.mode
with
1307 | Birdseye
_ -> gotopage pageno
0.0
1308 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 pageno
x y
1311 let getpassword () =
1312 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1317 impmsg "error getting password: %s" s;
1318 dolog
"%s" s) passcmd;
1321 let pgoto opaque pageno
x y =
1322 let pdimno = getpdimno pageno
in
1323 let x, y = project opaque pageno
pdimno x y in
1324 gotopagexy pageno
x y;
1328 (* dolog "%S" cmds; *)
1329 let spl = splitatchar cmds ' '
in
1331 try Scanf.sscanf
s fmt
f
1333 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1336 let addoutline outline
=
1337 match state
.currently
with
1338 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1339 | Idle
-> state
.currently
<- Outlining
[outline
]
1340 | Loading
_ | Tiling
_ ->
1341 dolog
"invalid outlining state";
1342 logcurrently state
.currently
1347 state
.uioh#infochanged Pdim
;
1349 | "clearrects", "" ->
1350 state
.rects
<- state
.rects1
;
1351 G.postRedisplay "clearrects";
1353 | "continue", args
->
1354 let n = scan args
"%u" (fun n -> n) in
1355 state
.pagecount
<- n;
1356 begin match state
.currently
with
1358 state
.currently
<- Idle
;
1359 state
.outlines
<- Array.of_list
(List.rev l
)
1360 | Idle
| Loading
_ | Tiling
_ -> ()
1363 let cur, cmds
= state
.geomcmds
in
1365 then failwith
"umpossible";
1367 begin match List.rev cmds
with
1369 state
.geomcmds
<- E.s, [];
1373 state
.geomcmds
<- s, List.rev rest
;
1375 G.postRedisplay "continue";
1382 then showtext ' ' args
1385 Buffer.add_string state
.errmsgs args
;
1386 state
.newerrmsgs
<- true;
1387 G.postRedisplay "error message"
1389 | "progress", args
->
1390 let progress, text =
1393 f, String.sub args pos
(String.length args
- pos
))
1396 state
.progress <- progress;
1397 G.postRedisplay "progress"
1399 | "firstmatch", args
->
1400 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1401 scan args
"%u %d %f %f %f %f %f %f %f %f"
1402 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1403 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1405 let y = (getpagey
pageno) + truncate
y0 in
1407 if (state
.x < - truncate
x0) || (state
.x > state
.winw
- truncate
x1)
1408 then state
.winw
/2 - truncate
(x0 /. 2. +. x1 /. 2.)
1413 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1414 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1417 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1418 scan args
"%u %d %f %f %f %f %f %f %f %f"
1419 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1420 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1422 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1424 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1427 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1428 let pageopaque = ~
< pageopaques in
1429 begin match state
.currently
with
1430 | Loading
(l
, gen
) ->
1431 vlog "page %d took %f sec" l
.pageno t
;
1432 Hashtbl.replace state
.pagemap
(l
.pageno, gen
) pageopaque;
1433 let preloadedpages =
1435 then preloadlayout state
.x state
.y state
.winw state
.winh
1439 let set = List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
1440 IntSet.empty
preloadedpages
1443 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1444 if not
(IntSet.mem
pageno set)
1446 wcmd "freepage %s" (~
> opaque
);
1452 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1455 state
.currently
<- Idle
;
1458 tilepage l
.pageno pageopaque state
.layout;
1460 load preloadedpages;
1461 let visible = pagevisible state
.layout l
.pageno in
1464 match state
.mode
with
1465 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1466 if pageno = l
.pageno
1471 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1473 if dir
> 0 then LDfirst
else LDlast
1476 findlink
pageopaque ld
1481 showlinktype (getlink
pageopaque n);
1482 state
.mode
<- LinkNav
(Ltexact
(l
.pageno, n))
1484 | LinkNav
(Ltgendir
_)
1485 | LinkNav
(Ltexact
_)
1491 if visible && layoutready state
.layout
1493 G.postRedisplay "page";
1497 | Idle
| Tiling
_ | Outlining
_ ->
1498 dolog
"Inconsistent loading state";
1499 logcurrently state
.currently
;
1504 let (x, y, opaques
, size
, t
) =
1505 scan args
"%u %u %s %u %f"
1506 (fun x y p size t
-> (x, y, p
, size
, t
))
1508 let opaque = ~
< opaques
in
1509 begin match state
.currently
with
1510 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1511 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
1514 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1516 wcmd "freetile %s" (~
> opaque);
1517 state
.currently
<- Idle
;
1521 puttileopaque l
col row gen cs angle
opaque size t
;
1522 state
.memused
<- state
.memused
+ size
;
1523 state
.uioh#infochanged Memused
;
1525 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
1526 opaque, size
) state
.tilelru
;
1528 state
.currently
<- Idle
;
1530 && conf
.colorspace
= cs
1531 && conf
.angle
= angle
1532 && tilevisible state
.layout l
.pageno x y
1533 then conttiling l
.pageno pageopaque;
1535 preload state
.layout;
1537 && conf
.colorspace
= cs
1538 && conf
.angle
= angle
1539 && tilevisible state
.layout l
.pageno x y
1540 && layoutready state
.layout
1541 then G.postRedisplay "tile nothrottle";
1544 | Idle
| Loading
_ | Outlining
_ ->
1545 dolog
"Inconsistent tiling state";
1546 logcurrently state
.currently
;
1551 let (n, w, h, _) as pdim
=
1552 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1555 match conf
.fitmodel
with
1557 | FitPage
| FitProportional
->
1558 match conf
.columns
with
1559 | Csplit
_ -> (n, w, h, 0)
1560 | Csingle
_ | Cmulti
_ -> pdim
1562 state
.pdims
<- pdim :: state
.pdims
;
1563 state
.uioh#infochanged Pdim
1566 let (l
, n, t
, h, pos
) =
1567 scan args
"%u %u %d %u %n"
1568 (fun l
n t
h pos
-> l
, n, t
, h, pos
)
1570 let s = String.sub args pos
(String.length args
- pos
) in
1571 addoutline (s, l
, Oanchor
(n, float t
/. float h, 0.0))
1574 let (l
, len, pos
) = scan args
"%u %u %n" (fun l
len pos
-> l
, len, pos
) in
1575 let s = String.sub args pos
len in
1576 let pos2 = pos
+ len + 1 in
1577 let uri = String.sub args
pos2 (String.length args
- pos2) in
1578 addoutline (s, l
, Ouri
uri)
1581 let (l
, pos
) = scan args
"%u %n" (fun l pos
-> l
, pos
) in
1582 let s = String.sub args pos
(String.length args
- pos
) in
1583 addoutline (s, l
, Onone
)
1587 scan args
"%u %d %d" (fun n l t
-> n, l
, t
)
1589 state
.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
1592 let c, v
= splitatchar args '
\t'
in
1599 if not
!ignoredoctitlte
1600 then Wsi.settitle v
;
1604 if let len = String.length
c in
1605 len > 6 && ((String.sub
c (len-4) 4) = "date")
1607 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1609 let b = Buffer.create
10 in
1610 Printf.bprintf
b "%s\t" c;
1613 Buffer.add_substring
b v p l
;
1614 Buffer.add_char
b c;
1615 with exn
-> Buffer.add_string
b @@ exntos exn
1623 Buffer.add_char
b '
['
;
1624 Buffer.add_string
b v
;
1625 Buffer.add_char
b '
]'
;
1632 state
.docinfo
<- (1, s) :: state
.docinfo
1635 state
.docinfo
<- List.rev state
.docinfo
;
1636 state
.uioh#infochanged Docinfo
1640 then Wsi.settitle
"Wrong password";
1641 let password = getpassword () in
1642 if emptystr
password
1643 then error
"document is password protected"
1644 else opendoc state
.path
password
1647 error
"unknown cmd `%S'" cmds
1652 let action = function
1653 | HCprev
-> cbget cb ~
-1
1654 | HCnext
-> cbget cb
1
1655 | HCfirst
-> cbget cb ~
-(cb
.rc)
1656 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1657 and cancel
() = cb
.rc <- rc
1661 let search pattern forward
=
1662 match conf
.columns
with
1663 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1664 | Csingle
_ | Cmulti
_ ->
1665 if nonemptystr pattern
1668 match state
.layout with
1671 l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
1673 wcmd "search %d %d %d %d,%s\000"
1674 (btod conf
.icase
) pn py (btod forward
) pattern
;
1677 let [@warning
"-4"] intentry
text key =
1679 if emptystr
text && key = Keys.Ascii '
-'
1680 then addchar
text '
-'
1683 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1685 state
.text <- "invalid key";
1695 let l = String.length
s in
1696 let rec loop pos
n =
1700 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1701 loop (pos
+1) (n*26 + m)
1704 let rec loop n = function
1707 match getopaque l.pageno with
1708 | None
-> loop n rest
1710 let m = getlinkcount
opaque in
1713 let under = getlink
opaque n in
1716 else loop (n-m) rest
1718 loop n state
.layout;
1722 let [@warning
"-4"] linknentry
text = function
1724 let text = addchar
text c in
1725 linknact (fun under -> state
.text <- undertext under) text;
1728 state
.text <- Printf.sprintf
"invalid key";
1732 let [@warning
"-4"] textentry
text = function
1733 | Keys.Ascii
c -> TEcont
(addchar
text c)
1734 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1738 let reqlayout angle fitmodel
=
1739 if nogeomcmds state
.geomcmds
1740 then state
.anchor <- getanchor
();
1741 conf
.angle
<- angle
mod 360;
1744 match state
.mode
with
1745 | LinkNav
_ -> state
.mode
<- View
1746 | Birdseye
_ | Textentry
_ | View
-> ()
1748 conf
.fitmodel
<- fitmodel
;
1752 wcmd "reqlayout %d %d %d"
1753 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1757 let settrim trimmargins trimfuzz
=
1758 if nogeomcmds state
.geomcmds
1759 then state
.anchor <- getanchor
();
1760 conf
.trimmargins
<- trimmargins
;
1761 conf
.trimfuzz
<- trimfuzz
;
1762 let x0, y0, x1, y1 = trimfuzz
in
1764 "settrim" (fun () ->
1765 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1770 let zoom = max
0.0001 zoom in
1771 if zoom <> conf
.zoom
1773 state
.prevzoom
<- (conf
.zoom, state
.x);
1775 reshape state
.winw state
.winh
;
1776 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
1780 let pivotzoom ?
(vw=min state
.w state
.winw
)
1781 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
1782 ?
(x=vw/2) ?
(y=vh
/2) zoom =
1783 let w = float state
.w /. zoom in
1784 let hw = w /. 2.0 in
1785 let ratio = float vh
/. float vw in
1786 let hh = hw *. ratio in
1787 let x0 = float x -. hw
1788 and y0 = float y -. hh in
1789 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
1793 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
1794 if nogeomcmds state
.geomcmds
1797 then pivotzoom ?
vw ?vh ?
x ?
y zoom
1801 let setcolumns mode columns coverA coverB
=
1802 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
1806 then impmsg "split mode doesn't work in bird's eye"
1808 conf
.columns
<- Csplit
(-columns
, E.a);
1816 conf
.columns
<- Csingle
E.a;
1821 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
1825 reshape state
.winw state
.winh
;
1828 let resetmstate () =
1829 state
.mstate
<- Mnone
;
1830 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
1833 let enterbirdseye () =
1834 let zoom = float conf
.thumbw
/. float state
.winw
in
1835 let birdseyepageno =
1836 let cy = state
.winh
/ 2 in
1840 let rec fold best
= function
1843 let d = cy - (l.pagedispy + l.pagevh/2)
1844 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
1845 if abs
d < abs dbest
1854 { conf
with zoom = conf
.zoom },
1855 state
.x, birdseyepageno, -1, getanchor
()
1859 conf
.presentation
<- false;
1860 conf
.interpagespace
<- 10;
1861 conf
.hlinks
<- false;
1862 conf
.fitmodel
<- FitPage
;
1865 match conf
.beyecolumns
with
1868 Cmulti
((c, 0, 0), E.a)
1869 | None
-> Csingle
E.a
1873 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1878 reshape state
.winw state
.winh
;
1881 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1883 conf
.zoom <- c.zoom;
1884 conf
.presentation
<- c.presentation
;
1885 conf
.interpagespace
<- c.interpagespace
;
1886 conf
.hlinks
<- c.hlinks
;
1887 conf
.fitmodel
<- c.fitmodel
;
1888 conf
.beyecolumns
<- (
1889 match conf
.columns
with
1890 | Cmulti
((c, _, _), _) -> Some
c
1892 | Csplit
_ -> failwith
"leaving bird's eye split mode"
1895 match c.columns
with
1896 | Cmulti
(c, _) -> Cmulti
(c, E.a)
1897 | Csingle
_ -> Csingle
E.a
1898 | Csplit
(c, _) -> Csplit
(c, E.a)
1902 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1905 reshape state
.winw state
.winh
;
1906 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
1910 let togglebirdseye () =
1911 match state
.mode
with
1912 | Birdseye vals
-> leavebirdseye vals
true
1913 | View
-> enterbirdseye ()
1914 | Textentry
_ | LinkNav
_ -> ()
1917 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1918 let pageno = max
0 (pageno - incr
) in
1919 let rec loop = function
1920 | [] -> gotopage1 pageno 0
1921 | l :: _ when l.pageno = pageno ->
1922 if l.pagedispy >= 0 && l.pagey = 0
1923 then G.postRedisplay "upbirdseye"
1924 else gotopage1 pageno 0
1925 | _ :: rest
-> loop rest
1929 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
1932 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1933 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
1934 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
1935 let rec loop = function
1937 let y, h = getpageyh
pageno in
1938 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
1939 gotoxy state
.x (clamp dy)
1940 | l :: _ when l.pageno = pageno ->
1941 if l.pagevh != l.pageh
1942 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
1943 else G.postRedisplay "downbirdseye"
1944 | _ :: rest
-> loop rest
1950 let [@warning
"-4"] optentry mode
_ key =
1951 let btos b = if b then "on" else "off" in
1955 try conf
.scrollstep
<- int_of_string
s with exn
->
1956 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1958 TEswitch
("scroll step: ", E.s, None
, intentry
, ondone, true)
1963 conf
.autoscrollstep
<- boundastep state
.winh
(int_of_string
s);
1964 if state
.autoscroll
<> None
1965 then state
.autoscroll
<- Some conf
.autoscrollstep
1967 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1969 TEswitch
("auto scroll step: ", E.s, None
, intentry
, ondone, true)
1974 let n, a, b = multicolumns_of_string
s in
1975 setcolumns mode
n a b;
1977 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
1979 TEswitch
("columns: ", E.s, None
, textentry
, ondone, true)
1984 let zoom = float (int_of_string
s) /. 100.0 in
1987 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1989 TEswitch
("zoom: ", E.s, None
, intentry
, ondone, true)
1994 conf
.thumbw
<- bound
(int_of_string
s) 2 4096;
1996 Printf.sprintf
"thumbnail width is set to %d" conf
.thumbw
;
1997 begin match mode
with
1999 leavebirdseye beye
false;
2001 | Textentry
_ | View
| LinkNav
_ -> ();
2004 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2006 TEswitch
("thumbnail width: ", E.s, None
, intentry
, ondone, true)
2010 match int_of_string
s with
2011 | angle
-> reqlayout angle conf
.fitmodel
2013 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2015 TEswitch
("rotation: ", E.s, None
, intentry
, ondone, true)
2018 conf
.icase
<- not conf
.icase
;
2019 TEdone
("case insensitive search " ^
(btos conf
.icase
))
2022 conf
.preload <- not conf
.preload;
2023 gotoxy state
.x state
.y;
2024 TEdone
("preload " ^
(btos conf
.preload))
2027 conf
.verbose
<- not conf
.verbose
;
2028 TEdone
("verbose " ^
(btos conf
.verbose
))
2031 conf
.debug
<- not conf
.debug
;
2032 TEdone
("debug " ^
(btos conf
.debug
))
2035 conf
.maxhfit
<- not conf
.maxhfit
;
2036 state
.maxy <- calcheight
();
2037 TEdone
("maxhfit " ^
(btos conf
.maxhfit
))
2040 conf
.crophack
<- not conf
.crophack
;
2041 TEdone
("crophack " ^
btos conf
.crophack
)
2044 conf
.underinfo
<- not conf
.underinfo
;
2045 TEdone
("underinfo " ^
btos conf
.underinfo
)
2048 conf
.savebmarks
<- not conf
.savebmarks
;
2049 TEdone
("persistent bookmarks " ^
btos conf
.savebmarks
)
2055 match state
.layout with
2060 conf
.interpagespace
<- int_of_string
s;
2061 docolumns conf
.columns
;
2062 state
.maxy <- calcheight
();
2063 let y = getpagey
pageno in
2064 gotoxy state
.x (y + py)
2066 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
2068 TEswitch
("vertical margin: ", E.s, None
, intentry
, ondone, true)
2072 match conf
.fitmodel
with
2073 | FitProportional
-> FitWidth
2074 | FitWidth
| FitPage
-> FitProportional
2076 reqlayout conf
.angle
fm;
2077 TEdone
("proportional display " ^
btos (fm == FitProportional
))
2080 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
2081 TEdone
("trim margins " ^
btos conf
.trimmargins
)
2084 conf
.invert
<- not conf
.invert
;
2085 TEdone
("invert colors " ^
btos conf
.invert
)
2089 cbput state
.hists
.sel
s;
2092 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
2093 textentry
, ondone, true)
2097 then conf
.pax
<- Some
0.0
2098 else conf
.pax
<- None
;
2099 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
2102 state
.text <- Printf.sprintf
"bad option %d `%c'"
2110 class type lvsource
=
2112 method getitemcount
: int
2113 method getitem
: int -> (string * int)
2114 method hasaction
: int -> bool
2115 method exit
: uioh
:uioh
->
2121 method getactive
: int
2122 method getfirst
: int
2124 method getminfo
: (int * int) array
2127 class virtual lvsourcebase
= object
2128 val mutable m_active
= 0
2129 val mutable m_first
= 0
2130 val mutable m_pan
= 0
2131 method getactive
= m_active
2132 method getfirst
= m_first
2133 method getpan
= m_pan
2134 method getminfo
: (int * int) array
= E.a
2139 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2142 state
.mode
<- Textentry
(te
, onleave
);
2144 G.postRedisplay "textentrykeyboard enttext";
2146 let histaction cmd
=
2149 | Some
(action, _) ->
2152 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2154 G.postRedisplay "textentry histaction"
2157 let kt = Wsi.kc2kt
key in
2160 if emptystr
text && cancelonempty
2163 G.postRedisplay "textentrykeyboard after cancel";
2166 let s = withoutlastutf8
text in
2167 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2172 G.postRedisplay "textentrykeyboard after confirm"
2174 | Up
-> histaction HCprev
2175 | Down
-> histaction HCnext
2176 | Home
-> histaction HCfirst
2177 | End
-> histaction HClast
2182 begin match opthist
with
2184 | Some
(_, onhistcancel
) -> onhistcancel
()
2188 G.postRedisplay "textentrykeyboard after cancel2"
2191 enttext (c, E.s, opthist
, onkey
, ondone, cancelonempty
)
2196 | Code
_ | Ascii
_ ->
2197 begin match onkey
text kt with
2201 G.postRedisplay "textentrykeyboard after confirm2";
2204 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2208 G.postRedisplay "textentrykeyboard after cancel3"
2211 state
.mode
<- Textentry
(te
, onleave
);
2212 G.postRedisplay "textentrykeyboard switch";
2214 | _ -> vlog "unhandled key"
2217 let firstof first active
=
2218 if first
> active
|| abs
(first
- active
) > fstate
.maxrows
- 1
2219 then max
0 (active
- (fstate
.maxrows
/2))
2223 let calcfirst first active
=
2226 let rows = active
- first
in
2227 if rows > fstate
.maxrows
then active
- fstate
.maxrows
else first
2231 let scrollph y maxy =
2232 let sh = float (maxy + state
.winh
) /. float state
.winh
in
2233 let sh = float state
.winh
/. sh in
2234 let sh = max
sh (float conf
.scrollh
) in
2236 let percent = float y /. float maxy in
2237 let position = (float state
.winh
-. sh) *. percent in
2240 if position +. sh > float state
.winh
2241 then float state
.winh
-. sh
2247 let adderrmsg src msg
=
2248 Buffer.add_string state
.errmsgs msg
;
2249 state
.newerrmsgs
<- true;
2253 let adderrfmt src fmt
=
2254 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
2257 let coe s = (s :> uioh
);;
2259 class listview ~zebra ~helpmode ~
(source
:lvsource
) ~trusted ~modehash
=
2261 val m_pan
= source#getpan
2262 val m_first
= source#getfirst
2263 val m_active
= source#getactive
2265 val m_prev_uioh
= state
.uioh
2267 method private elemunder
y =
2271 let n = y / (fstate
.fontsize
+1) in
2272 if m_first
+ n < source#getitemcount
2274 if source#hasaction
(m_first
+ n)
2275 then Some
(m_first
+ n)
2282 GlFunc.blend_func ~src
:`src_alpha ~dst
:`one_minus_src_alpha
;
2283 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2284 filledrect
0. 0. (float state
.winw
) (float state
.winh
);
2285 GlDraw.color (1., 1., 1.);
2286 Gl.enable `texture_2d
;
2287 let fs = fstate
.fontsize
in
2289 let hw = state
.winw
/3 in
2290 let ww = fstate
.wwidth
in
2291 let tabw = 17.0*.ww in
2292 let itemcount = source#getitemcount
in
2293 let minfo = source#getminfo
in
2297 GlMat.translate ~
x:(float conf
.scrollbw
) ();
2299 let x0 = 0.0 and x1 = float (state
.winw
- conf
.scrollbw
- 1) in
2301 if (row - m_first
) > fstate
.maxrows
2304 if row >= 0 && row < itemcount
2306 let (s, level
) = source#getitem
row in
2307 let y = (row - m_first
) * nfs in
2308 let x = 5.0 +. (float (level
+ m_pan
)) *. ww in
2311 (let c = if row land 1 = 0 then 1.0 else 0.92 in (c,c,c));
2315 Gl.disable `texture_2d
;
2316 let alpha = if source#hasaction
row then 0.9 else 0.3 in
2317 GlDraw.color (1., 1., 1.) ~
alpha;
2318 linerect
(x0 +. 1.) (float (y + 1)) (x1) (float (y + fs + 3));
2319 Gl.enable `texture_2d
;
2322 if zebra
&& row land 1 = 1
2326 GlDraw.color (c,c,c);
2327 let drawtabularstring s =
2329 let x'
= truncate
(x0 +. x) in
2330 let s1, s2
= splitatchar
s '
\000'
in
2332 then drawstring1
fs x'
(y+nfs) s
2338 let s'
= withoutlastutf8
s in
2339 let s = s' ^
Unisyms.ellipsis
in
2340 let w = measurestr
fs s in
2341 if float x'
+. w +. ww < float (hw + x'
)
2346 if float x'
+. ww +. measurestr
fs s1 > float (hw + x'
)
2350 ignore
(drawstring1
fs x'
(y+nfs) s1);
2351 drawstring1
fs (hw + x'
) (y+nfs) s2
2355 let x = if helpmode
&& row > 0 then x +. ww else x in
2356 let s1, s2
= splitatchar
s '
\t'
in
2359 let nx = drawstr x s1 in
2361 let x = x +. (max
tabw sw) in
2364 let len = String.length
s - 2 in
2365 if len > 0 && s.[0] = '
\xc2'
&& s.[1] = '
\xb7'
2367 let s = String.sub s 2 len in
2368 let x = if not helpmode
then x +. ww else x in
2369 GlDraw.color (1.2, 1.2, 1.2);
2370 let vinc = drawstring1
(fs+fs/4)
2371 (truncate
(x -. ww)) (y+nfs) s in
2372 GlDraw.color (1., 1., 1.);
2373 vinc +. (float fs *. 0.8)
2379 ignore
(drawtabularstring s);
2385 GlDraw.color (1.0, 1.0, 1.0) ~
alpha:0.5;
2388 if (row - m_first
) <= fstate
.maxrows
2390 if row >= 0 && row < itemcount
2392 let (s, level
) = source#getitem
row in
2393 let pos0 = nindex
s '
\000'
in
2394 let y = (row - m_first
) * nfs in
2395 let x = float (level
+ m_pan
) *. ww in
2396 let (first
, last
) = minfo.(row) in
2398 if pos0 > 0 && first
> pos0
2399 then String.sub s (pos0+1) (first
-pos0-1)
2400 else String.sub s 0 first
2402 let suffix = String.sub s first
(last
- first
) in
2403 let w1 = measurestr fstate
.fontsize
prefix in
2404 let w2 = measurestr fstate
.fontsize
suffix in
2405 let x = x +. if conf
.leftscroll
then xadj else 5.0 in
2406 let x = if pos0 > 0 && first
> pos0 then x +. float hw else x in
2408 and y0 = float (y+2) in
2410 and y1 = float (y+fs+3) in
2411 filledrect
x0 y0 x1 y1;
2415 Gl.disable `texture_2d
;
2416 if Array.length
minfo > 0 then loop m_first
;
2421 method updownlevel incr
=
2422 let len = source#getitemcount
in
2424 if m_active
>= 0 && m_active
< len
2425 then snd
(source#getitem m_active
)
2429 if i
= len then i
-1 else if i
= -1 then 0 else
2430 let _, l = source#getitem i
in
2431 if l != curlevel then i
else flow (i
+incr
)
2433 let active = flow m_active
in
2434 let first = calcfirst m_first
active in
2435 G.postRedisplay "outline updownlevel";
2436 {< m_active
= active; m_first
= first >}
2438 method private key1
key mask
=
2439 let set1 active first qsearch
=
2440 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2442 let search active pattern incr
=
2443 let active = if active = -1 then m_first
else active in
2446 if n >= 0 && n < source#getitemcount
2448 let s, _ = source#getitem
n in
2449 match Str.search_forward re
s 0 with
2450 | exception Not_found
-> loop (n + incr
)
2457 let qpat = Str.quote pattern
in
2458 match Str.regexp_case_fold
qpat with
2461 adderrfmt "listview key1" "regexp_case_fold for `%S' failed: %S\n"
2462 qpat @@ Printexc.to_string exn
;
2465 let itemcount = source#getitemcount
in
2466 let find start incr
=
2468 if i
= -1 || i
= itemcount
2471 if source#hasaction i
2473 else find (i
+ incr
)
2478 let set active first =
2479 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2481 coe {< m_active
= active; m_first
= first; m_qsearch
= E.s >}
2484 let isvisible first n = n >= first && n - first <= fstate
.maxrows
in
2486 let incr1 = if incr
> 0 then 1 else -1 in
2487 if isvisible m_first m_active
2490 let next = m_active
+ incr
in
2492 if next < 0 || next >= itemcount
2494 else find next incr1
2496 if abs
(m_active
- next) > fstate
.maxrows
2502 let first = m_first
+ incr
in
2503 let first = bound
first 0 (itemcount - fstate
.maxrows
) in
2505 let next = m_active
+ incr
in
2506 let next = bound
next 0 (itemcount - 1) in
2513 if isvisible first next
2520 let first = min
next m_first
in
2522 if abs
(next - first) > fstate
.maxrows
2528 let first = m_first
+ incr
in
2529 let first = bound
first 0 (itemcount - 1) in
2531 let next = m_active
+ incr
in
2532 let next = bound
next 0 (itemcount - 1) in
2533 let next = find next incr1 in
2535 if next = -1 || abs
(m_active
- first) > fstate
.maxrows
2537 let active = if m_active
= -1 then next else m_active
in
2542 if isvisible first active
2548 G.postRedisplay "listview navigate";
2552 let kt = Wsi.kc2kt
key in
2553 match [@warning
"-4"] kt with
2554 | Ascii
(('r'
|'
s'
) as c) when Wsi.withctrl mask
->
2555 let incr = if c = 'r'
then -1 else 1 in
2557 match search (m_active
+ incr) m_qsearch
incr with
2559 state
.text <- m_qsearch ^
" [not found]";
2562 state
.text <- m_qsearch
;
2563 active, firstof m_first
active
2565 G.postRedisplay "listview ctrl-r/s";
2566 set1 active first m_qsearch
;
2568 | Insert
when Wsi.withctrl mask
->
2569 if m_active
>= 0 && m_active
< source#getitemcount
2571 let s, _ = source#getitem m_active
in
2572 selstring conf
.selcmd
s;
2577 if emptystr m_qsearch
2580 let qsearch = withoutlastutf8 m_qsearch
in
2584 G.postRedisplay "listview empty qsearch";
2585 set1 m_active m_first
E.s;
2589 match search m_active
qsearch ~
-1 with
2591 state
.text <- qsearch ^
" [not found]";
2594 state
.text <- qsearch;
2595 active, firstof m_first
active
2597 G.postRedisplay "listview backspace qsearch";
2598 set1 active first qsearch
2601 | Ascii
_ | Code
_ ->
2603 match [@warning
"-8"] kt with
2604 | Ascii
c -> String.make
1 c
2605 | Code code
-> toutf8 code
2607 let pattern = m_qsearch ^
utf8 in
2609 match search m_active
pattern 1 with
2611 state
.text <- pattern ^
" [not found]";
2614 state
.text <- pattern;
2615 active, firstof m_first
active
2617 G.postRedisplay "listview qsearch add";
2618 set1 active first pattern;
2622 if emptystr m_qsearch
2624 G.postRedisplay "list view escape";
2625 let mx, my
= state
.mpos
in
2627 match source#exit ~uioh
:(coe self
) ~cancel
:true ~
active:m_active
2628 ~
first:m_first ~pan
:m_pan
with
2629 | None
-> m_prev_uioh
2633 G.postRedisplay "list view kill qsearch";
2634 coe {< m_qsearch
= E.s >}
2639 let self = {< m_qsearch
= E.s >} in
2641 G.postRedisplay "listview enter";
2642 let cancel = not
(m_active
>= 0 && m_active
< source#getitemcount
) in
2643 source#exit ~uioh
:(coe self) ~
cancel
2644 ~
active:m_active ~
first:m_first ~pan
:m_pan
;
2646 begin match opt with
2647 | None
-> m_prev_uioh
2654 | Up
-> navigate ~
-1
2655 | Down
-> navigate 1
2656 | Prior
-> navigate ~
-(fstate
.maxrows
)
2657 | Next
-> navigate fstate
.maxrows
2661 G.postRedisplay "listview right";
2662 coe {< m_pan
= m_pan
- 1 >}
2666 G.postRedisplay "listview left";
2667 coe {< m_pan
= m_pan
+ 1 >}
2670 let active = find 0 1 in
2671 G.postRedisplay "listview home";
2675 let first = max
0 (itemcount - fstate
.maxrows
) in
2676 let active = find (itemcount - 1) ~
-1 in
2677 G.postRedisplay "listview end";
2682 method key key mask
=
2683 match state
.mode
with
2685 textentrykeyboard
key mask te
;
2687 | Birdseye
_ | View
| LinkNav
_ -> self#key1
key mask
2689 method button button down
x y _ =
2692 | 1 when vscrollhit x ->
2693 G.postRedisplay "listview scroll";
2696 let _, position, sh = self#
scrollph in
2697 if y > truncate
position && y < truncate
(position +. sh)
2699 state
.mstate
<- Mscrolly
;
2703 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2704 let first = truncate
(s *. float source#getitemcount
) in
2705 let first = min source#getitemcount
first in
2706 Some
(coe {< m_first
= first; m_active
= first >})
2708 state
.mstate
<- Mnone
;
2712 begin match self#elemunder
y with
2714 G.postRedisplay "listview click";
2715 source#exit ~uioh
:(coe {< m_active
= n >})
2716 ~
cancel:false ~
active:n ~
first:m_first ~pan
:m_pan
2720 | n when (n == 4 || n == 5) && not down
->
2721 let len = source#getitemcount
in
2723 if n = 5 && m_first
+ fstate
.maxrows
>= len
2727 let first = m_first
+ (if n == 4 then -1 else 1) in
2728 bound
first 0 (len - 1)
2730 G.postRedisplay "listview wheel";
2731 Some
(coe {< m_first
= first >})
2732 | n when (n = 6 || n = 7) && not down
->
2733 let inc = if n = 7 then -1 else 1 in
2734 G.postRedisplay "listview hwheel";
2735 Some
(coe {< m_pan
= m_pan
+ inc >})
2740 | None
-> m_prev_uioh
2743 method multiclick
_ x y = self#button
1 true x y
2746 match state
.mstate
with
2748 let s = float (max
0 (y - conf
.scrollh
)) /. float state
.winh
in
2749 let first = truncate
(s *. float source#getitemcount
) in
2750 let first = min source#getitemcount
first in
2751 G.postRedisplay "listview motion";
2752 coe {< m_first
= first; m_active
= first >}
2760 method pmotion
x y =
2761 if x < state
.winw
- conf
.scrollbw
2764 match self#elemunder
y with
2765 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
2766 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
2770 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2775 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2779 method infochanged
_ = ()
2781 method scrollpw
= (0, 0.0, 0.0)
2783 let nfs = fstate
.fontsize
+ 1 in
2784 let y = m_first
* nfs in
2785 let itemcount = source#getitemcount
in
2786 let maxi = max
0 (itemcount - fstate
.maxrows
) in
2787 let maxy = maxi * nfs in
2788 let p, h = scrollph y maxy in
2791 method modehash
= modehash
2792 method eformsgs
= false
2793 method alwaysscrolly
= true
2794 method scroll
_ dy =
2796 if dy != 0 then begin
2797 let len = source#getitemcount
in
2799 if dy > 0 && m_first
+ fstate
.maxrows
>= len
2803 let first = m_first
+ dy / 10 in
2804 bound
first 0 (len - 1)
2806 G.postRedisplay "listview wheel";
2807 {< m_first
= first >}
2813 method zoom _ _ _ = ()
2816 class outlinelistview ~zebra ~source
=
2817 let settext autonarrow
s =
2820 let ss = source#statestr
in
2824 else "{" ^
ss ^
"} [" ^
s ^
"]"
2825 else state
.text <- s
2831 ~source
:(source
:> lvsource
)
2833 ~modehash
:(findkeyhash conf
"outline")
2836 val m_autonarrow
= false
2838 method! key key mask
=
2840 if emptystr state
.text
2842 else fstate
.maxrows - 2
2844 let calcfirst first active =
2847 let rows = active - first in
2848 if rows > maxrows then active - maxrows else first
2852 let active = m_active
+ incr in
2853 let active = bound
active 0 (source#getitemcount
- 1) in
2854 let first = calcfirst m_first
active in
2855 G.postRedisplay "outline navigate";
2856 coe {< m_active
= active; m_first
= first >}
2858 let navscroll first =
2860 let dist = m_active
- first in
2866 else first + maxrows
2869 G.postRedisplay "outline navscroll";
2870 coe {< m_first
= first; m_active
= active >}
2872 let ctrl = Wsi.withctrl mask
in
2874 match Wsi.kc2kt
key with
2875 | Ascii '
a'
when ctrl ->
2878 then (source#denarrow
; E.s)
2880 let pattern = source#renarrow
in
2881 if nonemptystr m_qsearch
2882 then (source#narrow m_qsearch
; m_qsearch
)
2886 settext (not m_autonarrow
) text;
2887 G.postRedisplay "toggle auto narrowing";
2888 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
2890 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
2892 G.postRedisplay "toggle auto narrowing";
2893 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
2895 | Ascii '
n'
when ctrl ->
2896 source#narrow m_qsearch
;
2898 then source#add_narrow_pattern m_qsearch
;
2899 G.postRedisplay "outline ctrl-n";
2900 coe {< m_first
= 0; m_active
= 0 >}
2902 | Ascii 'S'
when ctrl ->
2903 let active = source#calcactive
(getanchor
()) in
2904 let first = firstof m_first
active in
2905 G.postRedisplay "outline ctrl-s";
2906 coe {< m_first
= first; m_active
= active >}
2908 | Ascii 'u'
when ctrl ->
2909 G.postRedisplay "outline ctrl-u";
2910 if m_autonarrow
&& nonemptystr m_qsearch
2912 ignore
(source#renarrow
);
2913 settext m_autonarrow
E.s;
2914 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
2917 source#del_narrow_pattern
;
2918 let pattern = source#renarrow
in
2920 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
2922 settext m_autonarrow
text;
2923 coe {< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
2926 | Ascii '
l'
when ctrl ->
2927 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
2928 G.postRedisplay "outline ctrl-l";
2929 coe {< m_first
= first >}
2931 | Ascii '
\t'
when m_autonarrow
->
2932 if nonemptystr m_qsearch
2934 G.postRedisplay "outline list view tab";
2935 source#add_narrow_pattern m_qsearch
;
2937 coe {< m_qsearch
= E.s >}
2941 | Escape
when m_autonarrow
->
2942 if nonemptystr m_qsearch
2943 then source#add_narrow_pattern m_qsearch
;
2946 | Enter
when m_autonarrow
->
2947 if nonemptystr m_qsearch
2948 then source#add_narrow_pattern m_qsearch
;
2951 | (Ascii
_ | Code
_) when m_autonarrow
->
2952 let pattern = m_qsearch ^ toutf8
key in
2953 G.postRedisplay "outlinelistview autonarrow add";
2954 source#narrow
pattern;
2955 settext true pattern;
2956 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2958 | Backspace
when m_autonarrow
->
2959 if emptystr m_qsearch
2962 let pattern = withoutlastutf8 m_qsearch
in
2963 G.postRedisplay "outlinelistview autonarrow backspace";
2964 ignore
(source#renarrow
);
2965 source#narrow
pattern;
2966 settext true pattern;
2967 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2970 navscroll (max
0 (m_first
- 1))
2973 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
2975 | Up
-> navigate ~
-1
2976 | Down
-> navigate 1
2977 | Prior
-> navigate ~
-(fstate
.maxrows)
2978 | Next
-> navigate fstate
.maxrows
2984 G.postRedisplay "outline ctrl right";
2985 {< m_pan
= m_pan
+ 1 >}
2987 else self#updownlevel
1
2995 G.postRedisplay "outline ctrl left";
2996 {< m_pan
= m_pan
- 1 >}
2998 else self#updownlevel ~
-1
3003 G.postRedisplay "outline home";
3004 coe {< m_first
= 0; m_active
= 0 >}
3007 let active = source#getitemcount
- 1 in
3008 let first = max
0 (active - fstate
.maxrows) in
3009 G.postRedisplay "outline end";
3010 coe {< m_active
= active; m_first
= first >}
3012 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
3016 let genhistoutlines () =
3018 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
3019 compare c2
.lastvisit c1
.lastvisit
)
3020 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
3021 let path = if nonemptystr origin
then origin
else path in
3022 let base = mbtoutf8
@@ Filename.basename
path in
3023 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
3027 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
3028 Config.save
leavebirdseye;
3029 state
.anchor <- anchor;
3030 state
.bookmarks
<- bookmarks
;
3031 state
.origin
<- origin
;
3034 let x0, y0, x1, y1 = conf
.trimfuzz
in
3035 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
3036 reshape ~firsttime
:true state
.winw state
.winh
;
3037 opendoc path origin
;
3041 let setcheckers enabled
=
3042 match state
.checkerstexid
with
3044 if enabled
then state
.checkerstexid
<- Some
(makecheckers
())
3046 | Some checkerstexid
->
3049 GlTex.delete_texture checkerstexid
;
3050 state
.checkerstexid
<- None
;
3054 let describe_layout layout =
3058 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
3061 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
3063 let sep = if a.pageno+1 = b.pageno then ", " else Unisyms.ellipsis
in
3064 Printf.sprintf
"%d%s%d" (a.pageno+1) sep (b.pageno+1)
3066 let rec fold s la lb
= function
3067 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
3068 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
3069 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
3071 fold "Pages" l l rest
3074 let maxy = maxy () in
3077 else 100. *. (float state
.y /. float maxy)
3079 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
3082 let setpresentationmode v
=
3083 let n = page_of_y state
.y in
3084 state
.anchor <- (n, 0.0, 1.0);
3085 conf
.presentation
<- v
;
3086 if conf
.fitmodel
= FitPage
3087 then reqlayout conf
.angle conf
.fitmodel
;
3092 let btos b = if b then Unisyms.radical
else E.s in
3093 let showextended = ref false in
3094 let showcolors = ref false in
3095 let leave mode
_ = state
.mode
<- mode
in
3098 val mutable m_l
= []
3099 val mutable m_a
= E.a
3100 val mutable m_prev_uioh
= nouioh
3101 val mutable m_prev_mode
= View
3103 inherit lvsourcebase
3105 method reset prev_mode prev_uioh
=
3106 m_a
<- Array.of_list
(List.rev m_l
);
3108 m_prev_mode
<- prev_mode
;
3109 m_prev_uioh
<- prev_uioh
;
3111 method int name get
set =
3117 try set (int_of_string
s)
3119 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3123 let te = name ^
": ", E.s, None
, intentry
, ondone, true in
3124 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3128 method int_with_suffix name get
set =
3130 (name
, `intws get
, 1,
3134 try set (int_of_string_with_suffix
s)
3136 state
.text <- Printf.sprintf
"bad integer `%s': %s"
3141 name ^
": ", E.s, None
, intentry_with_suffix
, ondone, true
3143 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3147 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3149 (name
, `
bool (btos, get
), offset
, Action
(
3156 method color name get
set =
3158 (name
, `
color get
, 1,
3161 let invalid = (nan
, nan
, nan
) in
3164 try color_of_string
s
3166 state
.text <- Printf.sprintf
"bad color `%s': %s"
3173 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3174 state
.text <- color_to_string
(get
());
3175 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3179 method string name get
set =
3181 (name
, `
string get
, 1,
3184 let ondone s = set s in
3185 let te = name ^
": ", E.s, None
, textentry
, ondone, true in
3186 state
.mode
<- Textentry
(te, leave m_prev_mode
);
3190 method colorspace name get
set =
3192 (name
, `
string get
, 1,
3197 inherit lvsourcebase
3200 m_active
<- CSTE.to_int conf
.colorspace
;
3203 method getitemcount
=
3204 Array.length
CSTE.names
3207 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3208 ignore
(uioh
, first, pan
);
3209 if not
cancel then set active;
3211 method hasaction
_ = true
3215 let modehash = findkeyhash conf
"info" in
3216 coe (new listview ~zebra
:false ~helpmode
:false
3217 ~
source ~trusted
:true ~
modehash)
3220 method paxmark name get
set =
3222 (name
, `
string get
, 1,
3227 inherit lvsourcebase
3230 m_active
<- MTE.to_int conf
.paxmark
;
3233 method getitemcount
= Array.length
MTE.names
3234 method getitem
n = (MTE.names
.(n), 0)
3235 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3236 ignore
(uioh
, first, pan
);
3237 if not
cancel then set active;
3239 method hasaction
_ = true
3243 let modehash = findkeyhash conf
"info" in
3244 coe (new listview ~zebra
:false ~helpmode
:false
3245 ~
source ~trusted
:true ~
modehash)
3248 method fitmodel name get
set =
3250 (name
, `
string get
, 1,
3255 inherit lvsourcebase
3258 m_active
<- FMTE.to_int conf
.fitmodel
;
3261 method getitemcount
= Array.length
FMTE.names
3262 method getitem
n = (FMTE.names
.(n), 0)
3263 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3264 ignore
(uioh
, first, pan
);
3265 if not
cancel then set active;
3267 method hasaction
_ = true
3271 let modehash = findkeyhash conf
"info" in
3272 coe (new listview ~zebra
:false ~helpmode
:false
3273 ~
source ~trusted
:true ~
modehash)
3276 method caption
s offset
=
3277 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
3279 method caption2
s f offset
=
3280 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3282 method getitemcount
= Array.length m_a
3285 let tostr = function
3286 | `
int f -> string_of_int
(f ())
3287 | `intws
f -> string_with_suffix_of_int
(f ())
3289 | `
color f -> color_to_string
(f ())
3290 | `
bool (btos, f) -> btos (f ())
3293 let name, t
, offset
, _ = m_a
.(n) in
3294 ((let s = tostr t
in
3296 then Printf.sprintf
"%s\t%s" name s
3300 method exit ~uioh ~
cancel ~
active ~
first ~pan
=
3305 match m_a
.(active) with
3306 | _, _, _, Action
f -> f uioh
3307 | _, _, _, Noaction
-> uioh
3318 method hasaction
n =
3320 | _, _, _, Action
_ -> true
3321 | _, _, _, Noaction
-> false
3323 initializer m_active
<- 1
3326 let rec fillsrc prevmode prevuioh
=
3327 let sep () = src#caption
E.s 0 in
3328 let colorp name get
set =
3330 (fun () -> color_to_string
(get
()))
3333 let c = color_of_string
v in
3337 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3340 let rgba name get
set =
3342 (fun () -> rgba_to_string
(get
()))
3345 let c = rgba_of_string
v in
3349 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
3352 let oldmode = state
.mode
in
3353 let birdseye = isbirdseye state
.mode
in
3355 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3357 src#
bool "presentation mode"
3358 (fun () -> conf
.presentation
)
3359 (fun v -> setpresentationmode v);
3361 src#
bool "ignore case in searches"
3362 (fun () -> conf
.icase
)
3363 (fun v -> conf
.icase
<- v);
3366 (fun () -> conf
.preload)
3367 (fun v -> conf
.preload <- v);
3369 src#
bool "highlight links"
3370 (fun () -> conf
.hlinks
)
3371 (fun v -> conf
.hlinks
<- v);
3373 src#
bool "under info"
3374 (fun () -> conf
.underinfo
)
3375 (fun v -> conf
.underinfo
<- v);
3377 src#
bool "persistent bookmarks"
3378 (fun () -> conf
.savebmarks
)
3379 (fun v -> conf
.savebmarks
<- v);
3381 src#fitmodel
"fit model"
3382 (fun () -> FMTE.to_string conf
.fitmodel
)
3383 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
3385 src#
bool "trim margins"
3386 (fun () -> conf
.trimmargins
)
3387 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
3389 src#
bool "persistent location"
3390 (fun () -> conf
.jumpback
)
3391 (fun v -> conf
.jumpback
<- v);
3394 src#
int "inter-page space"
3395 (fun () -> conf
.interpagespace
)
3397 conf
.interpagespace
<- n;
3398 docolumns conf
.columns
;
3400 match state
.layout with
3405 state
.maxy <- calcheight
();
3406 let y = getpagey
pageno in
3407 gotoxy state
.x (y + py)
3411 (fun () -> conf
.pagebias
)
3412 (fun v -> conf
.pagebias
<- v);
3414 src#
int "scroll step"
3415 (fun () -> conf
.scrollstep
)
3416 (fun n -> conf
.scrollstep
<- n);
3418 src#
int "horizontal scroll step"
3419 (fun () -> conf
.hscrollstep
)
3420 (fun v -> conf
.hscrollstep
<- v);
3422 src#
int "auto scroll step"
3424 match state
.autoscroll
with
3426 | _ -> conf
.autoscrollstep
)
3428 let n = boundastep state
.winh
n in
3429 if state
.autoscroll
<> None
3430 then state
.autoscroll
<- Some
n;
3431 conf
.autoscrollstep
<- n);
3434 (fun () -> truncate
(conf
.zoom *. 100.))
3435 (fun v -> pivotzoom ((float v) /. 100.));
3438 (fun () -> conf
.angle
)
3439 (fun v -> reqlayout v conf
.fitmodel
);
3441 src#
int "scroll bar width"
3442 (fun () -> conf
.scrollbw
)
3445 reshape state
.winw state
.winh
;
3448 src#
int "scroll handle height"
3449 (fun () -> conf
.scrollh
)
3450 (fun v -> conf
.scrollh
<- v;);
3452 src#
int "thumbnail width"
3453 (fun () -> conf
.thumbw
)
3455 conf
.thumbw
<- min
4096 v;
3458 leavebirdseye beye
false;
3465 let mode = state
.mode in
3466 src#
string "columns"
3468 match conf
.columns
with
3470 | Cmulti
(multi
, _) -> multicolumns_to_string multi
3471 | Csplit
(count
, _) -> "-" ^ string_of_int count
3474 let n, a, b = multicolumns_of_string
v in
3475 setcolumns mode n a b);
3478 src#caption
"Pixmap cache" 0;
3479 src#int_with_suffix
"size (advisory)"
3480 (fun () -> conf
.memlimit
)
3481 (fun v -> conf
.memlimit
<- v);
3485 Printf.sprintf
"%s bytes, %d tiles"
3486 (string_with_suffix_of_int state
.memused
)
3487 (Hashtbl.length state
.tilemap
)) 1;
3490 src#caption
"Layout" 0;
3491 src#caption2
"Dimension"
3493 Printf.sprintf
"%dx%d (virtual %dx%d)"
3494 state
.winw state
.winh
3499 src#caption2
"Position" (fun () ->
3500 Printf.sprintf
"%dx%d" state
.x state
.y
3503 src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
3506 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3507 "Save these parameters as global defaults at exit"
3508 (fun () -> conf
.bedefault
)
3509 (fun v -> conf
.bedefault
<- v);
3512 let btos b = if b then Unisyms.lguillemet
else Unisyms.rguillemet
in
3513 src#
bool ~offset
:0 ~
btos "Extended parameters"
3514 (fun () -> !showextended)
3515 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3519 (fun () -> conf
.checkers
)
3520 (fun v -> conf
.checkers
<- v; setcheckers v);
3521 src#
bool "update cursor"
3522 (fun () -> conf
.updatecurs
)
3523 (fun v -> conf
.updatecurs
<- v);
3524 src#
bool "scroll-bar on the left"
3525 (fun () -> conf
.leftscroll
)
3526 (fun v -> conf
.leftscroll
<- v);
3528 (fun () -> conf
.verbose
)
3529 (fun v -> conf
.verbose
<- v);
3530 src#
bool "invert colors"
3531 (fun () -> conf
.invert
)
3532 (fun v -> conf
.invert
<- v);
3534 (fun () -> conf
.maxhfit
)
3535 (fun v -> conf
.maxhfit
<- v);
3537 (fun () -> conf
.pax
!= None
)
3540 then conf
.pax
<- Some
(now
())
3541 else conf
.pax
<- None
);
3542 src#
string "uri launcher"
3543 (fun () -> conf
.urilauncher
)
3544 (fun v -> conf
.urilauncher
<- v);
3545 src#
string "path launcher"
3546 (fun () -> conf
.pathlauncher
)
3547 (fun v -> conf
.pathlauncher
<- v);
3548 src#
string "tile size"
3549 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
3552 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3553 conf
.tilew
<- max
64 w;
3554 conf
.tileh
<- max
64 h;
3557 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
3560 src#
int "texture count"
3561 (fun () -> conf
.texcount
)
3564 then conf
.texcount
<- v
3565 else impmsg "failed to set texture count please retry later"
3567 src#
int "slice height"
3568 (fun () -> conf
.sliceheight
)
3570 conf
.sliceheight
<- v;
3571 wcmd "sliceh %d" conf
.sliceheight
;
3573 src#
int "anti-aliasing level"
3574 (fun () -> conf
.aalevel
)
3576 conf
.aalevel
<- bound
v 0 8;
3577 state
.anchor <- getanchor
();
3578 opendoc state
.path state
.password;
3580 src#
string "page scroll scaling factor"
3581 (fun () -> string_of_float conf
.pgscale)
3584 let s = float_of_string
v in
3587 state
.text <- Printf.sprintf
3588 "bad page scroll scaling factor `%s': %s" v
3592 src#
int "ui font size"
3593 (fun () -> fstate
.fontsize
)
3594 (fun v -> setfontsize (bound
v 5 100));
3595 src#
int "hint font size"
3596 (fun () -> conf
.hfsize
)
3597 (fun v -> conf
.hfsize
<- bound
v 5 100);
3598 src#
bool "crop hack"
3599 (fun () -> conf
.crophack
)
3600 (fun v -> conf
.crophack
<- v);
3601 src#
string "trim fuzz"
3602 (fun () -> irect_to_string conf
.trimfuzz
)
3605 conf
.trimfuzz
<- irect_of_string
v;
3607 then settrim true conf
.trimfuzz
;
3609 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
3612 src#
string "selection command"
3613 (fun () -> conf
.selcmd
)
3614 (fun v -> conf
.selcmd
<- v);
3615 src#
string "synctex command"
3616 (fun () -> conf
.stcmd
)
3617 (fun v -> conf
.stcmd
<- v);
3618 src#
string "pax command"
3619 (fun () -> conf
.paxcmd
)
3620 (fun v -> conf
.paxcmd
<- v);
3621 src#
string "ask password command"
3622 (fun () -> conf
.passcmd)
3623 (fun v -> conf
.passcmd <- v);
3624 src#
string "save path command"
3625 (fun () -> conf
.savecmd
)
3626 (fun v -> conf
.savecmd
<- v);
3627 src#colorspace
"color space"
3628 (fun () -> CSTE.to_string conf
.colorspace
)
3630 conf
.colorspace
<- CSTE.of_int
v;
3634 src#paxmark
"pax mark method"
3635 (fun () -> MTE.to_string conf
.paxmark
)
3636 (fun v -> conf
.paxmark
<- MTE.of_int
v);
3637 if bousable
() && !opengl_has_pbo
3640 (fun () -> conf
.usepbo
)
3641 (fun v -> conf
.usepbo
<- v);
3642 src#
bool "mouse wheel scrolls pages"
3643 (fun () -> conf
.wheelbypage
)
3644 (fun v -> conf
.wheelbypage
<- v);
3645 src#
bool "open remote links in a new instance"
3646 (fun () -> conf
.riani
)
3647 (fun v -> conf
.riani
<- v);
3648 src#
bool "edit annotations inline"
3649 (fun () -> conf
.annotinline
)
3650 (fun v -> conf
.annotinline
<- v);
3651 src#
bool "coarse positioning in presentation mode"
3652 (fun () -> conf
.coarseprespos
)
3653 (fun v -> conf
.coarseprespos
<- v);
3654 src#
bool "use document CSS"
3655 (fun () -> conf
.usedoccss
)
3657 conf
.usedoccss
<- v;
3658 state
.anchor <- getanchor
();
3659 opendoc state
.path state
.password;
3661 src#
bool ~
btos "colors"
3662 (fun () -> !showcolors)
3663 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
3666 colorp " background"
3667 (fun () -> conf
.bgcolor
)
3668 (fun v -> conf
.bgcolor
<- v);
3670 (fun () -> conf
.sbarcolor
)
3671 (fun v -> conf
.sbarcolor
<- v);
3672 rgba " scrollbar handle"
3673 (fun () -> conf
.sbarhndlcolor
)
3674 (fun v -> conf
.sbarhndlcolor
<- v);
3679 src#caption
"Document" 0;
3680 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
3681 src#caption2
"Pages"
3682 (fun () -> string_of_int state
.pagecount
) 1;
3683 src#caption2
"Dimensions"
3684 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3685 if nonemptystr conf
.css
3686 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
3690 src#caption
"Trimmed margins" 0;
3691 src#caption2
"Dimensions"
3692 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
3696 src#caption
"OpenGL" 0;
3697 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
3698 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
3701 src#caption
"Location" 0;
3702 if nonemptystr state
.origin
3703 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
3704 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
3706 src#reset prevmode prevuioh
;
3711 let prevmode = state
.mode
3712 and prevuioh
= state
.uioh in
3713 fillsrc prevmode prevuioh
;
3714 let source = (src :> lvsource
) in
3715 let modehash = findkeyhash conf
"info" in
3718 inherit listview ~zebra
:false ~helpmode
:false
3719 ~
source ~trusted
:true ~
modehash as super
3720 val mutable m_prevmemused
= 0
3721 method! infochanged
= function
3723 if m_prevmemused
!= state
.memused
3725 m_prevmemused
<- state
.memused
;
3726 G.postRedisplay "memusedchanged";
3728 | Pdim
-> G.postRedisplay "pdimchanged"
3729 | Docinfo
-> fillsrc prevmode prevuioh
3731 method! key key mask
=
3732 if not
(Wsi.withctrl mask
)
3734 match [@warning
"-4"] Wsi.kc2kt
key with
3735 | Keys.Left
-> coe (self#updownlevel ~
-1)
3736 | Keys.Right
-> coe (self#updownlevel
1)
3737 | _ -> super#
key key mask
3738 else super#
key key mask
3740 G.postRedisplay "info";
3746 inherit lvsourcebase
3747 method getitemcount
= Array.length state
.help
3749 let s, l, _ = state
.help
.(n) in
3752 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
3756 match state
.help
.(active) with
3757 | _, _, Action
f -> Some
(f uioh)
3758 | _, _, Noaction
-> Some
uioh
3767 method hasaction
n =
3768 match state
.help
.(n) with
3769 | _, _, Action
_ -> true
3770 | _, _, Noaction
-> false
3776 let modehash = findkeyhash conf
"help" in
3778 state
.uioh <- coe (new listview
3779 ~zebra
:false ~helpmode
:true
3780 ~
source ~trusted
:true ~
modehash);
3781 G.postRedisplay "help";
3787 inherit lvsourcebase
3788 val mutable m_items
= E.a
3790 method getitemcount
= 1 + Array.length m_items
3795 else m_items
.(n-1), 0
3797 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
3802 then Buffer.clear state
.errmsgs
;
3809 method hasaction
n =
3813 state
.newerrmsgs
<- false;
3814 let l = Str.split newlinere
(Buffer.contents state
.errmsgs
) in
3815 m_items
<- Array.of_list
l
3824 let source = (msgsource :> lvsource
) in
3825 let modehash = findkeyhash conf
"listview" in
3828 inherit listview ~zebra
:false ~helpmode
:false
3829 ~
source ~trusted
:false ~
modehash as super
3832 then msgsource#reset
;
3835 G.postRedisplay "msgs";
3839 let editor = getenvwithdef
"EDITOR" E.s in
3843 let tmppath = Filename.temp_file
"llpp" "note" in
3846 let oc = open_out
tmppath in
3850 let execstr = editor ^
" " ^
tmppath in
3852 match spawn
execstr [] with
3854 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
3857 match Unix.waitpid
[] pid
with
3859 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
3863 | Unix.WEXITED
0 -> filecontents
tmppath
3865 impmsg "editor process(%s) exited abnormally: %d" execstr n;
3867 | Unix.WSIGNALED
n ->
3868 impmsg "editor process(%s) was killed by signal %d" execstr n;
3870 | Unix.WSTOPPED
n ->
3871 impmsg "editor(%s) process was stopped by signal %d" execstr n;
3874 match Unix.unlink
tmppath with
3876 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
3881 let enterannotmode opaque slinkindex
=
3884 inherit lvsourcebase
3885 val mutable m_text
= E.s
3886 val mutable m_items
= E.a
3888 method getitemcount
= Array.length m_items
3891 let label, _func
= m_items
.(n) in
3894 method exit ~
uioh ~
cancel ~
active ~
first ~pan
=
3895 ignore
(uioh, first, pan
);
3898 let _label, func
= m_items
.(active) in
3903 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
3906 let rec split accu b i
=
3908 if p = String.length
s
3909 then (String.sub s b (p-b), unit) :: accu
3911 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
3913 let ss = if i
= 0 then E.s else String.sub s b i
in
3914 split ((ss, unit)::accu) (p+1) 0
3919 wcmd "freepage %s" (~
> opaque);
3921 Hashtbl.fold (fun key opaque'
accu ->
3922 if opaque'
= opaque'
3923 then key :: accu else accu) state
.pagemap
[]
3925 List.iter
(Hashtbl.remove state
.pagemap
) keys;
3927 gotoxy state
.x state
.y
3930 delannot
opaque slinkindex
;
3933 let edit inline
() =
3938 modannot
opaque slinkindex
s;
3944 let mode = state
.mode in
3947 ("annotation: ", m_text
, None
, textentry
, update, true),
3948 fun _ -> state
.mode <- mode);
3952 let s = getusertext m_text
in
3957 ( "[Copy]", fun () -> selstring conf
.selcmd m_text
)
3958 :: ("[Delete]", dele)
3959 :: ("[Edit]", edit conf
.annotinline
)
3961 :: split [] 0 0 |> List.rev
|> Array.of_list
3968 let s = getannotcontents
opaque slinkindex
in
3971 let source = (msgsource :> lvsource
) in
3972 let modehash = findkeyhash conf
"listview" in
3973 state
.uioh <- coe (object
3974 inherit listview ~zebra
:false ~helpmode
:false
3975 ~
source ~trusted
:false ~
modehash
3977 G.postRedisplay "enterannotmode";
3980 let gotoremote spec
=
3981 let filename, dest
= splitatchar spec '#'
in
3982 let getpath filename =
3984 if nonemptystr
filename
3986 if Filename.is_relative
filename
3988 let dir = Filename.dirname state
.path in
3990 if Filename.is_implicit
dir
3991 then Filename.concat
(Sys.getcwd
()) dir
3994 Filename.concat
dir filename
3998 if Sys.file_exists
path
4002 let path = getpath filename in
4006 let cmd = Lazy.force_val lcmd
in
4007 match spawn
cmd with
4009 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
4011 let anchor = getanchor
() in
4012 let ranchor = state
.path, state
.password, anchor, state
.origin
in
4013 state
.origin
<- E.s;
4014 state
.ranchors
<- ranchor :: state
.ranchors
;
4017 if substratis spec
0 "page="
4019 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
4021 state
.anchor <- (pageno, 0.0, 0.0);
4022 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
4024 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
4026 state
.nameddest
<- dest
;
4027 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
4031 let gotounder = function
4032 | Ulinkuri
s when isexternallink
s ->
4033 if substratis
s 0 "file://"
4034 then gotoremote @@ String.sub s 7 (String.length
s - 7)
4037 let pageno, x, y = uritolocation
s in
4039 gotopagexy pageno x y
4040 | Utext
_ | Unone
-> ()
4041 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4044 let gotooutline (_, _, kind
) =
4048 let (pageno, y, _) = anchor in
4050 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
4054 | Ouri
uri -> gotounder (Ulinkuri
uri)
4055 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
4056 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
4057 | Ohistory hist
-> gotohist hist
4058 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
4061 class outlinesoucebase fetchoutlines
= object (self)
4062 inherit lvsourcebase
4063 val mutable m_items
= E.a
4064 val mutable m_minfo
= E.a
4065 val mutable m_orig_items
= E.a
4066 val mutable m_orig_minfo
= E.a
4067 val mutable m_narrow_patterns
= []
4068 val mutable m_gen
= -1
4070 method getitemcount
= Array.length m_items
4073 let s, n, _ = m_items
.(n) in
4076 method exit ~
(uioh:uioh) ~
cancel ~
active ~
(first:int) ~pan
: uioh option =
4077 ignore
(uioh, first);
4079 if m_narrow_patterns
= []
4080 then m_orig_items
, m_orig_minfo
4081 else m_items
, m_minfo
4088 gotooutline m_items
.(active);
4096 method hasaction
(_:int) = true
4099 if Array.length m_items
!= Array.length m_orig_items
4102 match m_narrow_patterns
with
4104 | many
-> String.concat
Unisyms.ellipsis
(List.rev many
)
4106 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4110 match m_narrow_patterns
with
4113 | head
:: _ -> Unisyms.ellipsis ^ head
4115 method narrow
pattern =
4116 match Str.regexp_case_fold
pattern with
4119 let rec loop accu minfo n =
4122 m_items
<- Array.of_list
accu;
4123 m_minfo
<- Array.of_list
minfo;
4126 let (s, _, _) as o = m_items
.(n) in
4128 match Str.search_forward re
s 0 with
4129 | exception Not_found
-> accu, minfo
4130 | first -> o :: accu, (first, Str.match_end
()) :: minfo
4132 loop accu minfo (n-1)
4134 loop [] [] (Array.length m_items
- 1)
4136 method! getminfo
= m_minfo
4139 m_orig_items
<- fetchoutlines
();
4140 m_minfo
<- m_orig_minfo
;
4141 m_items
<- m_orig_items
4143 method add_narrow_pattern
pattern =
4144 m_narrow_patterns
<- pattern :: m_narrow_patterns
4146 method del_narrow_pattern
=
4147 match m_narrow_patterns
with
4148 | _ :: rest
-> m_narrow_patterns
<- rest
4153 match m_narrow_patterns
with
4154 | pattern :: [] -> self#narrow
pattern; pattern
4156 List.fold_left
(fun accu pattern ->
4157 self#narrow
pattern;
4158 pattern ^
Unisyms.ellipsis ^
accu) E.s list
4160 method calcactive
(_:anchor) = 0
4162 method reset
anchor items =
4163 if state
.gen
!= m_gen
4165 m_orig_items
<- items;
4167 m_narrow_patterns
<- [];
4169 m_orig_minfo
<- E.a;
4173 if items != m_orig_items
4175 m_orig_items
<- items;
4176 if m_narrow_patterns
== []
4177 then m_items
<- items;
4180 let active = self#calcactive
anchor in
4182 m_first
<- firstof m_first
active
4186 let outlinesource fetchoutlines
=
4188 inherit outlinesoucebase fetchoutlines
4189 method! calcactive
anchor =
4190 let rely = getanchory anchor in
4191 let rec loop n best bestd
=
4192 if n = Array.length m_items
4195 let _, _, kind
= m_items
.(n) in
4198 let orely = getanchory anchor in
4199 let d = abs
(orely - rely) in
4202 else loop (n+1) best bestd
4203 | Onone
| Oremote
_ | Olaunch
_
4204 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
4205 loop (n+1) best bestd
4211 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
4212 let mkselector sourcetype
=
4213 let fetchoutlines () =
4214 match sourcetype
with
4215 | `bookmarks
-> Array.of_list state
.bookmarks
4216 | `outlines
-> state
.outlines
4217 | `history
-> genhistoutlines () |> Array.of_list
4220 if sourcetype
= `history
4221 then new outlinesoucebase
fetchoutlines
4222 else outlinesource fetchoutlines
4225 let outlines = fetchoutlines () in
4226 if Array.length
outlines = 0
4227 then showtext ' ' errmsg
4230 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4231 let anchor = getanchor
() in
4232 source#reset
anchor outlines;
4233 state
.text <- source#greetmsg
;
4235 coe (new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
4236 G.postRedisplay "enter selector";
4240 let mkenter sourcetype errmsg
=
4241 let enter = mkselector sourcetype
in
4242 fun () -> enter errmsg
4244 ( mkenter `
outlines "document has no outline"
4245 , mkenter `bookmarks
"document has no bookmarks (yet)"
4246 , mkenter `history
"history is empty" )
4249 let quickbookmark ?title
() =
4250 match state
.layout with
4257 let tm = localtime
(now
()) in
4259 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
4261 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
4263 | Some
title -> title
4265 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4268 let setautoscrollspeed step goingdown
=
4269 let incr = max
1 ((abs step
) / 2) in
4270 let incr = if goingdown
then incr else -incr in
4271 let astep = boundastep state
.winh
(step
+ incr) in
4272 state
.autoscroll
<- Some
astep;
4276 match conf
.columns
with
4278 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
4281 let panbound x = bound
x (-state
.w) state
.winw
;;
4283 let existsinrow pageno (columns
, coverA
, coverB
) p =
4284 let last = ((pageno - coverA
) mod columns
) + columns
in
4285 let rec any = function
4288 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
4292 then (if l.pageno = last then false else any rest
)
4300 match state
.layout with
4302 let pageno = page_of_y state
.y in
4303 gotoxy state
.x (getpagey
(pageno+1))
4305 match conf
.columns
with
4307 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4309 let y = clamp (pgscale state
.winh
) in
4312 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
4313 gotoxy state
.x (getpagey
pageno)
4314 | Cmulti
((c, _, _) as cl
, _) ->
4315 if conf
.presentation
4316 && (existsinrow l.pageno cl
4317 (fun l -> l.pageh
> l.pagey + l.pagevh))
4319 let y = clamp (pgscale state
.winh
) in
4322 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
4323 gotoxy state
.x (getpagey
pageno)
4325 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
4327 let pagey, pageh
= getpageyh
l.pageno in
4328 let pagey = pagey + pageh
* l.pagecol
in
4329 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
4330 gotoxy state
.x (pagey + pageh
+ ips)
4334 match state
.layout with
4336 let pageno = page_of_y state
.y in
4337 gotoxy state
.x (getpagey
(pageno-1))
4339 match conf
.columns
with
4341 if conf
.presentation
&& l.pagey != 0
4343 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
4345 let pageno = max
0 (l.pageno-1) in
4346 gotoxy state
.x (getpagey
pageno)
4347 | Cmulti
((c, _, coverB
) as cl
, _) ->
4348 if conf
.presentation
&&
4349 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4351 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
4354 if l.pageno = state
.pagecount
- coverB
4358 let pageno = max
0 (l.pageno-decr) in
4359 gotoxy state
.x (getpagey
pageno)
4367 let pageno = max
0 (l.pageno-1) in
4368 let pagey, pageh
= getpageyh
pageno in
4371 let pagey, pageh
= getpageyh
l.pageno in
4372 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
4378 if emptystr conf
.savecmd
4379 then adderrmsg "savepath-command is empty"
4380 "don't know where to save modified document"
4382 let savecmd = Str.global_replace percentsre state
.path conf
.savecmd in
4386 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
4391 let tmp = path ^
".tmp" in
4393 Unix.rename
tmp path;
4396 let viewkeyboard key mask
=
4398 let mode = state
.mode in
4399 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
4402 G.postRedisplay "view:enttext"
4404 let ctrl = Wsi.withctrl mask
in
4406 match Wsi.kc2kt
key with
4407 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
4409 | Ascii 'Q'
-> exit
0
4412 if hasunsavedchanges
()
4416 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
4419 match state
.lnava
with
4420 | None
-> LinkNav
(Ltgendir
0)
4421 | Some
pn -> LinkNav
(Ltexact
pn)
4423 gotoxy state
.x state
.y;
4425 else impmsg "keyboard link navigation does not work under rotation"
4427 | Escape
| Ascii 'q'
->
4428 begin match state
.mstate
with
4431 G.postRedisplay "kill rect";
4434 | Mscrolly
| Mscrollx
4437 begin match state
.mode with
4440 | Ltexact pl
-> state
.lnava
<- Some pl
4441 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
4444 G.postRedisplay "esc leave linknav"
4445 | Birdseye
_ | Textentry
_ | View
->
4446 match state
.ranchors
with
4448 | (path, password, anchor, origin
) :: rest
->
4449 state
.ranchors
<- rest
;
4450 state
.anchor <- anchor;
4451 state
.origin
<- origin
;
4452 state
.nameddest
<- E.s;
4453 opendoc path password
4459 gotoxy state
.x (getnav ~
-1)
4470 Hashtbl.iter
(fun _ opaque ->
4472 Hashtbl.clear state
.prects
) state
.pagemap
;
4473 G.postRedisplay "dehighlight";
4475 | Ascii
(('
/'
| '?'
) as c) ->
4476 let ondone isforw
s =
4477 cbput state
.hists
.pat
s;
4478 state
.searchpattern
<- s;
4481 let s = String.make
1 c in
4482 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
4483 textentry
, ondone (c = '
/'
), true)
4485 | Ascii '
+'
| Ascii '
='
when ctrl ->
4486 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4487 pivotzoom (conf
.zoom +. incr)
4492 try int_of_string
s with exn
->
4494 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4500 state
.text <- "page bias is now " ^ string_of_int
n;
4503 enttext ("page bias: ", E.s, None
, intentry
, ondone, true)
4505 | Ascii '
-'
when ctrl ->
4506 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4507 pivotzoom (max
0.01 (conf
.zoom -. decr))
4510 let ondone msg
= state
.text <- msg
in
4512 "option [acfhilpstvxACFPRSZTISM]: ", E.s, None
,
4513 optentry state
.mode, ondone, true
4516 | Ascii '
0'
when ctrl ->
4518 then gotoxy 0 state
.y
4521 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
4523 match conf
.columns
with
4524 | Csingle
_ | Cmulti
_ -> 1
4525 | Csplit
(n, _) -> n
4527 let h = state
.winh
-
4528 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
4530 let zoom = zoomforh state
.winw
h 0 cols in
4531 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
4534 | Ascii '
3'
when ctrl ->
4536 match conf
.fitmodel
with
4537 | FitWidth
-> FitProportional
4538 | FitProportional
-> FitPage
4539 | FitPage
-> FitWidth
4541 state
.text <- "fit model: " ^
FMTE.to_string
fm;
4542 reqlayout conf
.angle
fm
4544 | Ascii '
4'
when ctrl ->
4545 let zoom = getmaxw
() /. float state
.winw
in
4546 if zoom > 0.0 then setzoom zoom
4551 | Ascii '
9'
when ctrl ->
4554 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
4557 try int_of_string
s with exn
->
4558 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
4564 cbput state
.hists
.pag
(string_of_int
n);
4565 gotopage1 (n + conf
.pagebias
- 1) 0;
4568 let [@warning
"-4"] pageentry
text = function
4569 | Keys.Ascii '
g'
-> TEdone
text
4570 | key -> intentry
text key
4572 let text = String.make
1 c in
4573 enttext (":", text, Some
(onhist state
.hists
.pag
),
4574 pageentry
, ondone, true)
4577 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
4578 G.postRedisplay "toggle scrollbar";
4581 state
.bzoom
<- not state
.bzoom
;
4583 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
4586 conf
.hlinks
<- not conf
.hlinks
;
4587 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
4588 G.postRedisplay "toggle highlightlinks";
4591 if conf
.angle
mod 360 = 0
4593 state
.glinks
<- true;
4594 let mode = state
.mode in
4597 (":", E.s, None
, linknentry
, linknact gotounder, false),
4599 state
.glinks
<- false;
4603 G.postRedisplay "view:linkent(F)"
4605 else impmsg "hint mode does not work under rotation"
4608 state
.glinks
<- true;
4609 let mode = state
.mode in
4612 (":", E.s, None
, linknentry
,
4613 linknact (fun under ->
4614 selstring conf
.selcmd
(undertext under)), false),
4616 state
.glinks
<- false;
4620 G.postRedisplay "view:linkent"
4623 begin match state
.autoscroll
with
4625 conf
.autoscrollstep
<- step
;
4626 state
.autoscroll
<- None
4628 state
.autoscroll
<- Some conf
.autoscrollstep
;
4629 state
.slideshow
<- state
.slideshow
land lnot
2
4632 | Ascii '
p'
when ctrl ->
4633 launchpath () (* XXX where do error messages go? *)
4636 setpresentationmode (not conf
.presentation
);
4637 showtext ' '
("presentation mode " ^
4638 if conf
.presentation
then "on" else "off");
4641 if List.mem
Wsi.Fullscreen state
.winstate
4642 then Wsi.reshape conf
.cwinw conf
.cwinh
4643 else Wsi.fullscreen
()
4645 | Ascii
('
p'
|'N'
) ->
4646 search state
.searchpattern
false
4648 | Ascii '
n'
| Fn
3 ->
4649 search state
.searchpattern
true
4652 begin match state
.layout with
4655 gotoxy state
.x (getpagey
l.pageno)
4665 showtext ' '
(describe_layout state
.layout);
4668 begin match state
.layout with
4671 Wsi.reshape l.pagew
l.pageh
;
4676 enterbookmarkmode
()
4678 | Ascii '
h'
| Fn
1 ->
4684 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
4689 match state
.layout with
4694 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
4697 enttext ("bookmark: ", E.s, None
, textentry
, ondone, true)
4701 showtext ' '
"Quick bookmark added";
4704 begin match state
.layout with
4706 let rect = getpdimrect
l.pagedimno
in
4710 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4711 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4713 (truncate
(rect.(1) -. rect.(0)),
4714 truncate
(rect.(3) -. rect.(0)))
4716 let w = truncate
((float w)*.conf
.zoom)
4717 and h = truncate
((float h)*.conf
.zoom) in
4720 state
.anchor <- getanchor
();
4721 Wsi.reshape w (h + conf
.interpagespace
)
4723 G.postRedisplay "z";
4728 | Ascii '
x'
-> state
.roam
()
4730 | Ascii
('
<'
|'
>'
as c) ->
4732 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
4734 | Ascii
('
['
|'
]'
as c) ->
4736 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
4737 G.postRedisplay "brightness";
4739 | Ascii '
c'
when state
.mode = View
->
4744 let m = (state
.winw
- state
.w) / 2 in
4749 match state
.prevcolumns
with
4750 | None
-> (1, 0, 0), 1.0
4751 | Some
(columns
, z
) ->
4754 | Csplit
(c, _) -> -c, 0, 0
4755 | Cmulti
((c, a, b), _) -> c, a, b
4756 | Csingle
_ -> 1, 0, 0
4760 setcolumns View
c a b;
4763 | Down
| Up
when ctrl && Wsi.withshift mask
->
4764 let zoom, x = state
.prevzoom
in
4769 begin match state
.autoscroll
with
4771 begin match state
.mode with
4772 | Birdseye beye
-> upbirdseye 1 beye
4773 | Textentry
_ | View
| LinkNav
_ ->
4775 then gotoxy state
.x (clamp ~
-(state
.winh
/2))
4777 if not
(Wsi.withshift mask
) && conf
.presentation
4779 else gotoxy state
.x (clamp (-conf
.scrollstep
))
4783 setautoscrollspeed n false
4786 | Ascii 'j'
| Down
->
4787 begin match state
.autoscroll
with
4789 begin match state
.mode with
4790 | Birdseye beye
-> downbirdseye 1 beye
4791 | Textentry
_ | View
| LinkNav
_ ->
4793 then gotoxy state
.x (clamp (state
.winh
/2))
4795 if not
(Wsi.withshift mask
) && conf
.presentation
4797 else gotoxy state
.x (clamp (conf
.scrollstep
))
4801 setautoscrollspeed n true
4804 | Left
| Right
when not
(Wsi.withalt mask
) ->
4810 else conf
.hscrollstep
4813 let pv = Wsi.kc2kt
key in
4814 if pv = Keys.Left
then dx else -dx
4816 gotoxy (panbound (state
.x + dx)) state
.y
4819 G.postRedisplay "left/right"
4826 match state
.layout with
4828 | l :: _ -> state
.y - l.pagey
4830 clamp (pgscale (-state
.winh
))
4838 match List.rev state
.layout with
4840 | l :: _ -> getpagey
l.pageno
4842 clamp (pgscale state
.winh
)
4846 | Ascii '
g'
| Home
->
4849 | Ascii 'G'
| End
->
4851 gotoxy 0 (clamp state
.maxy)
4853 | Right
when Wsi.withalt mask
->
4855 gotoxy state
.x (getnav 1)
4856 | Left
when Wsi.withalt mask
->
4858 gotoxy state
.x (getnav ~
-1)
4863 | Ascii '
v'
when conf
.debug
->
4866 match getopaque l.pageno with
4869 let x0, y0, x1, y1 = pagebbox
opaque in
4870 let rect = (float x0, float y0,
4873 float x0, float y1) in
4875 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
4876 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
4878 G.postRedisplay "v";
4881 let mode = state
.mode in
4882 let cmd = ref E.s in
4883 let onleave = function
4884 | Cancel
-> state
.mode <- mode
4887 match getopaque l.pageno with
4888 | Some
opaque -> pipesel opaque !cmd
4889 | None
-> ()) state
.layout;
4893 cbput state
.hists
.sel
s;
4897 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry
, ondone, true
4899 G.postRedisplay "|";
4900 state
.mode <- Textentry
(te, onleave);
4902 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
4903 vlog "huh? %s" (Wsi.keyname
key)
4906 let linknavkeyboard key mask
linknav =
4907 let pv = Wsi.kc2kt
key in
4908 let getpage pageno =
4909 let rec loop = function
4911 | l :: _ when l.pageno = pageno -> Some
l
4912 | _ :: rest
-> loop rest
4913 in loop state
.layout
4915 let doexact (pageno, n) =
4916 match getopaque pageno, getpage pageno with
4917 | Some
opaque, Some
l ->
4920 let under = getlink
opaque n in
4921 G.postRedisplay "link gotounder";
4928 | Home
-> Some
(findlink
opaque LDfirst
), -1
4929 | End
-> Some
(findlink
opaque LDlast
), 1
4930 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
4931 | Right
-> Some
(findlink
opaque (LDright
n)), 1
4932 | Up
-> Some
(findlink
opaque (LDup
n)), -1
4933 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
4935 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
4936 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
4939 begin match findpwl
l.pageno dir with
4943 state
.mode <- LinkNav
(Ltgendir
dir);
4944 let y, h = getpageyh
pageno in
4947 then y + h - state
.winh
4952 begin match getopaque pageno, getpage pageno with
4953 | Some
opaque, Some
_ ->
4955 let ld = if dir > 0 then LDfirst
else LDlast
in
4958 begin match link with
4960 showlinktype (getlink
opaque m);
4961 state
.mode <- LinkNav
(Ltexact
(pageno, m));
4962 G.postRedisplay "linknav jpage";
4963 | Lnotfound
-> notfound dir
4969 begin match opt with
4970 | Some Lnotfound
-> pwl l dir;
4971 | Some
(Lfound
m) ->
4975 let _, y0, _, y1 = getlinkrect
opaque m in
4977 then gotopage1 l.pageno y0
4979 let d = fstate
.fontsize
+ 1 in
4980 if y1 - l.pagey > l.pagevh - d
4981 then gotopage1 l.pageno (y1 - state
.winh
+ d)
4982 else G.postRedisplay "linknav";
4984 showlinktype (getlink
opaque m);
4985 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
4988 | None
-> viewkeyboard key mask
4990 | _ -> viewkeyboard key mask
4994 begin match linknav with
4995 | Ltexact pa
-> state
.lnava
<- Some pa
4996 | Ltgendir
_ | Ltnotready
_ -> ()
4999 G.postRedisplay "leave linknav"
5003 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
5004 | Ltexact exact
-> doexact exact
5007 let keyboard key mask
=
5008 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
5009 then wcmd "interrupt"
5010 else state
.uioh <- state
.uioh#
key key mask
5013 let birdseyekeyboard key mask
5014 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5016 match conf
.columns
with
5018 | Cmulti
((c, _, _), _) -> c
5019 | Csplit
_ -> failwith
"bird's eye split mode"
5021 let pgh layout = List.fold_left
5022 (fun m l -> max
l.pageh
m) state
.winh
layout in
5024 match Wsi.kc2kt
key with
5025 | Ascii '
l'
when Wsi.withctrl mask
->
5026 let y, h = getpageyh
pageno in
5027 let top = (state
.winh
- h) / 2 in
5028 gotoxy state
.x (max
0 (y - top))
5029 | Enter
-> leavebirdseye beye
false
5030 | Escape
-> leavebirdseye beye
true
5031 | Up
-> upbirdseye incr beye
5032 | Down
-> downbirdseye incr beye
5033 | Left
-> upbirdseye 1 beye
5034 | Right
-> downbirdseye 1 beye
5037 begin match state
.layout with
5041 state
.mode <- Birdseye
(
5042 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5044 gotopage1 l.pageno 0;
5047 let layout = layout state
.x (state
.y-state
.winh
)
5049 (pgh state
.layout) in
5051 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5053 state
.mode <- Birdseye
(
5054 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5056 gotopage1 l.pageno 0
5059 | [] -> gotoxy state
.x (clamp (-state
.winh
))
5063 begin match List.rev state
.layout with
5065 let layout = layout state
.x
5066 (state
.y + (pgh state
.layout))
5067 state
.winw state
.winh
in
5068 begin match layout with
5070 let incr = l.pageh
- l.pagevh in
5075 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
5077 G.postRedisplay "birdseye pagedown";
5079 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
5083 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5084 gotopage1 l.pageno 0;
5087 | [] -> gotoxy state
.x (clamp state
.winh
)
5091 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5095 let pageno = state
.pagecount
- 1 in
5096 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5097 if not
(pagevisible state
.layout pageno)
5100 match List.rev state
.pdims
with
5102 | (_, _, h, _) :: _ -> h
5106 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
5107 else G.postRedisplay "birdseye end";
5109 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
5114 match state
.mode with
5115 | Textentry
_ -> scalecolor 0.4
5116 | LinkNav
_ | View
-> scalecolor 1.0
5117 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5118 if l.pageno = hooverpageno
5121 if l.pageno = pageno
5123 let c = scalecolor 1.0 in
5125 GlDraw.line_width
3.0;
5126 let dispx = l.pagedispx in
5128 (float (dispx-1)) (float (l.pagedispy-1))
5129 (float (dispx+l.pagevw+1))
5130 (float (l.pagedispy+l.pagevh+1))
5132 GlDraw.line_width
1.0;
5141 let postdrawpage l linkindexbase
=
5142 match getopaque l.pageno with
5144 if tileready l l.pagex
l.pagey
5146 let x = l.pagedispx - l.pagex
5147 and y = l.pagedispy - l.pagey in
5149 match conf
.columns
with
5150 | Csingle
_ | Cmulti
_ ->
5151 (if conf
.hlinks
then 1 else 0)
5153 && not
(isbirdseye state
.mode) then 2 else 0)
5157 match state
.mode with
5158 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
5164 Hashtbl.find_all state
.prects
l.pageno |>
5165 List.iter
(fun vals
-> drawprect
opaque x y vals
);
5166 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
5168 then (state
.redisplay
<- true; 0)
5174 let scrollindicator () =
5175 let sbw, ph
, sh = state
.uioh#
scrollph in
5176 let sbh, pw, sw = state
.uioh#scrollpw
in
5181 else ((state
.winw
- sbw), state
.winw
, 0)
5185 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5186 let (r
, g, b, alpha) = conf
.sbarcolor
in
5187 GlDraw.color (r
, g, b) ~
alpha;
5188 filledrect
(float x0) 0. (float x1) (float state
.winh
);
5190 (float hx0
) (float (state
.winh
- sbh))
5191 (float (hx0
+ state
.winw
)) (float state
.winh
);
5192 let (r
, g, b, alpha) = conf
.sbarhndlcolor
in
5193 GlDraw.color (r
, g, b) ~
alpha;
5195 filledrect
(float x0) ph
(float x1) (ph
+. sh);
5196 let pw = pw +. float hx0
in
5197 filledrect
pw (float (state
.winh
- sbh)) (pw +. sw) (float state
.winh
);
5202 match state
.mstate
with
5203 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5206 | Msel
((x0, y0), (x1, y1)) ->
5207 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
5208 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
5209 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
5210 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
5217 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5218 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5220 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5222 if l.pageno = pageno
5224 let dx = float (l.pagedispx - l.pagex
) in
5225 let dy = float (l.pagedispy - l.pagey) in
5226 let r, g, b, alpha = c in
5227 GlDraw.color (r, g, b) ~
alpha;
5228 filledrect2
(x0+.dx) (y0+.dy)
5239 GlDraw.color (scalecolor2 conf
.bgcolor
);
5240 GlClear.color (scalecolor2 conf
.bgcolor
);
5241 GlClear.clear
[`
color];
5242 List.iter
drawpage state
.layout;
5244 match state
.mode with
5245 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5246 begin match getopaque pageno with
5248 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
5249 let color = (0.0, 0.0, 0.5, 0.5) in
5251 (float x0, float y0,
5256 | None
-> state
.rects
5258 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
5261 | View
-> state
.rects
5264 let rec postloop linkindexbase
= function
5266 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5267 postloop linkindexbase rest
5271 postloop 0 state
.layout;
5273 begin match state
.mstate
with
5274 | Mzoomrect
((x0, y0), (x1, y1)) ->
5276 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5277 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
5278 filledrect
(float x0) (float y0) (float x1) (float y1);
5282 | Mscrolly
| Mscrollx
5291 let zoomrect x y x1 y1 =
5294 and y0 = min
y y1 in
5295 let zoom = (float state
.w) /. float (x1 - x0) in
5298 if state
.w < state
.winw
5299 then (state
.winw
- state
.w) / 2
5302 match conf
.fitmodel
with
5303 | FitWidth
| FitProportional
-> simple ()
5305 match conf
.columns
with
5307 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5308 | Cmulti
_ | Csingle
_ -> simple ()
5310 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
5311 state
.anchor <- getanchor
();
5316 let annot inline
x y =
5317 match unproject x y with
5318 | Some
(opaque, n, ux
, uy
) ->
5320 addannot
opaque ux uy
text;
5321 wcmd "freepage %s" (~
> opaque);
5322 Hashtbl.remove state
.pagemap
(n, state
.gen
);
5324 gotoxy state
.x state
.y
5328 let ondone s = add s in
5329 let mode = state
.mode in
5330 state
.mode <- Textentry
(
5331 ("annotation: ", E.s, None
, textentry
, ondone, true),
5332 fun _ -> state
.mode <- mode);
5335 G.postRedisplay "annot"
5337 add @@ getusertext E.s
5342 let g opaque l px py =
5343 match rectofblock
opaque px py with
5345 let x0 = a.(0) -. 20. in
5346 let x1 = a.(1) +. 20. in
5347 let y0 = a.(2) -. 20. in
5348 let zoom = (float state
.w) /. (x1 -. x0) in
5349 let pagey = getpagey
l.pageno in
5350 let margin = (state
.w - l.pagew
)/2 in
5351 let nx = -truncate
x0 - margin in
5352 gotoxy nx (pagey + truncate
y0);
5353 state
.anchor <- getanchor
();
5358 match conf
.columns
with
5360 impmsg "block zooming does not work properly in split columns mode"
5361 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
5365 let winw = state
.winw - 1 in
5366 let s = float x /. float winw in
5367 let destx = truncate
(float (state
.w + winw) *. s) in
5368 gotoxy (winw - destx) state
.y;
5369 state
.mstate
<- Mscrollx
;
5373 let s = float y /. float state
.winh
in
5374 let desty = truncate
(s *. float (maxy ())) in
5375 gotoxy state
.x desty;
5376 state
.mstate
<- Mscrolly
;
5379 let viewmulticlick clicks
x y mask
=
5380 let g opaque l px py =
5388 if markunder
opaque px py mark
5392 match getopaque l.pageno with
5394 | Some
opaque -> pipesel opaque cmd
5396 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
5397 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
5402 G.postRedisplay "viewmulticlick";
5403 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
5407 match conf
.columns
with
5409 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
5412 let viewmouse button down
x y mask
=
5414 | n when (n == 4 || n == 5) && not down
->
5415 if Wsi.withctrl mask
5419 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5420 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5423 match state
.mstate
with
5424 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
5425 | Mzoomrect
_ | Mnone
| Mpan
_
5426 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
5428 let zoom = conf
.zoom -. incr in
5429 state
.mstate
<- Mzoom
(n, 0, (x, y));
5430 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
5431 then pivotzoom ~
x ~
y zoom
5435 match state
.autoscroll
with
5436 | Some step
-> setautoscrollspeed step
(n=4)
5438 if conf
.wheelbypage
|| conf
.presentation
5447 then -conf
.scrollstep
5448 else conf
.scrollstep
5450 let incr = incr * 2 in
5451 let y = clamp incr in
5455 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5457 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
5460 | 1 when Wsi.withshift mask
->
5461 state
.mstate
<- Mnone
;
5464 match unproject x y with
5466 | Some
(_, pageno, ux
, uy
) ->
5467 let cmd = Printf.sprintf
5469 conf
.stcmd state
.path pageno ux uy
5471 match spawn
cmd [] with
5473 impmsg "execution of synctex command(%S) failed: %S"
5474 conf
.stcmd
@@ exntos exn
5478 | 1 when Wsi.withctrl mask
->
5481 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5482 state
.mstate
<- Mpan
(x, y)
5485 state
.mstate
<- Mnone
5490 if Wsi.withshift mask
5492 annot conf
.annotinline
x y;
5493 G.postRedisplay "addannot"
5497 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5498 state
.mstate
<- Mzoomrect
(p, p)
5501 match state
.mstate
with
5502 | Mzoomrect
((x0, y0), _) ->
5503 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5504 then zoomrect x0 y0 x y
5507 G.postRedisplay "kill accidental zoom rect";
5511 | Mscrolly
| Mscrollx
5513 | Mnone
-> resetmstate ()
5516 | 1 when vscrollhit x ->
5519 let _, position, sh = state
.uioh#
scrollph in
5520 if y > truncate
position && y < truncate
(position +. sh)
5521 then state
.mstate
<- Mscrolly
5524 state
.mstate
<- Mnone
5526 | 1 when y > state
.winh
- hscrollh () ->
5529 let _, position, sw = state
.uioh#scrollpw
in
5530 if x > truncate
position && x < truncate
(position +. sw)
5531 then state
.mstate
<- Mscrollx
5534 state
.mstate
<- Mnone
5536 | 1 when state
.bzoom
-> if not down
then zoomblock x y
5539 let dest = if down
then getunder x y else Unone
in
5540 begin match dest with
5544 | Unone
when down
->
5545 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
5546 state
.mstate
<- Mpan
(x, y);
5548 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
5550 | Unone
| Utext
_ ->
5555 state
.mstate
<- Msel
((x, y), (x, y));
5556 G.postRedisplay "mouse select";
5560 match state
.mstate
with
5563 | Mzoom
_ | Mscrollx
| Mscrolly
->
5564 state
.mstate
<- Mnone
5566 | Mzoomrect
((x0, y0), _) ->
5570 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5571 state
.mstate
<- Mnone
5573 | Msel
((x0, y0), (x1, y1)) ->
5574 let rec loop = function
5578 let a0 = l.pagedispy in
5579 let a1 = a0 + l.pagevh in
5580 let b0 = l.pagedispx in
5581 let b1 = b0 + l.pagevw in
5582 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5583 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5587 match getopaque l.pageno with
5590 pipef ~closew
:false "Msel"
5593 G.postRedisplay "Msel") cmd
5595 dosel conf
.selcmd
();
5596 state
.roam
<- dosel conf
.paxcmd
;
5608 let birdseyemouse button down
x y mask
5609 (conf
, leftx
, _, hooverpageno
, anchor) =
5612 let rec loop = function
5615 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5616 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5618 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
5624 | _ -> viewmouse button down
x y mask
5630 method key key mask
=
5631 begin match state
.mode with
5632 | Textentry textentry
-> textentrykeyboard
key mask textentry
5633 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5634 | View
-> viewkeyboard key mask
5635 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5639 method button button bstate
x y mask
=
5640 begin match state
.mode with
5641 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
5642 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5647 method multiclick clicks
x y mask
=
5648 begin match state
.mode with
5649 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
5650 | Birdseye
_ | Textentry
_ -> ()
5655 begin match state
.mode with
5657 | View
| Birdseye
_ | LinkNav
_ ->
5658 match state
.mstate
with
5659 | Mzoom
_ | Mnone
-> ()
5664 state
.mstate
<- Mpan
(x, y);
5665 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5670 state
.mstate
<- Msel
(a, (x, y));
5671 G.postRedisplay "motion select";
5674 let y = min state
.winh
(max
0 y) in
5678 let x = min state
.winw (max
0 x) in
5681 | Mzoomrect
(p0
, _) ->
5682 state
.mstate
<- Mzoomrect
(p0
, (x, y));
5683 G.postRedisplay "motion zoomrect";
5687 method pmotion
x y =
5688 begin match state
.mode with
5689 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
5690 let rec loop = function
5692 if hooverpageno
!= -1
5694 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
5695 G.postRedisplay "pmotion birdseye no hoover";
5698 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5699 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5701 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
5702 G.postRedisplay "pmotion birdseye hoover";
5710 | LinkNav
_ | View
->
5711 match state
.mstate
with
5712 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
5721 let delta = now -. past
in
5724 else conf
.pax
<- Some
now
5728 method infochanged
_ = ()
5731 let maxy = maxy () in
5734 then 0.0, float state
.winh
5735 else scrollph state
.y maxy
5740 let fwinw = float (state
.winw - vscrollw ()) in
5742 let sw = fwinw /. float state
.w in
5743 let sw = fwinw *. sw in
5744 max
sw (float conf
.scrollh
)
5747 let maxx = state
.w + state
.winw in
5748 let x = state
.winw - state
.x in
5749 let percent = float x /. float maxx in
5750 (fwinw -. sw) *. percent
5752 hscrollh (), position, sw
5756 match state
.mode with
5757 | LinkNav
_ -> "links"
5758 | Textentry
_ -> "textentry"
5759 | Birdseye
_ -> "birdseye"
5762 findkeyhash conf
modename
5764 method eformsgs
= true
5765 method alwaysscrolly
= false
5766 method scroll
dx dy =
5767 let x = if canpan () then panbound (state
.x + dx) else state
.x in
5768 gotoxy x (clamp (2 * dy));
5771 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
5774 let addrect pageno r g b a x0 y0 x1 y1 =
5775 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
5779 let cl = splitatchar cmds ' '
in
5781 try Scanf.sscanf
s fmt
f
5782 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
5785 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
5786 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
5787 s pageno r g b a x0 y0 x1 y1;
5791 let _,w1,h1
,_ = getpagedim
pageno in
5792 let sw = float w1 /. float w
5793 and sh = float h1
/. float h in
5797 and y1s
= y1 *. sh in
5798 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
5799 let color = (r, g, b, a) in
5800 if conf
.verbose
then debugrect rect;
5801 state
.rects <- (pageno, color, rect) :: state
.rects;
5806 | "reload", "" -> reload ()
5808 scan args
"%u %f %f"
5810 let cmd, _ = state
.geomcmds
in
5812 then gotopagexy pageno x y
5815 gotopagexy pageno x y;
5818 state
.reprf
<- f state
.reprf
5820 | "goto1", args
-> scan args
"%u %f" gotopage
5821 | "gotor", args
-> scan args
"%S" gotoremote
5823 scan args
"%u %u %f %f %f %f"
5824 (fun pageno c x0 y0 x1 y1 ->
5825 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
5826 rectx "rect" pageno color x0 y0 x1 y1;
5829 scan args
"%u %f %f %f %f %f %f %f %f"
5830 (fun pageno r g b alpha x0 y0 x1 y1 ->
5831 addrect pageno r g b alpha x0 y0 x1 y1;
5832 G.postRedisplay "prect"
5835 scan args
"%u %f %f"
5838 match getopaque pageno with
5839 | Some
opaque -> opaque
5842 pgoto optopaque pageno x y;
5843 let rec fixx = function
5846 if l.pageno = pageno
5847 then gotoxy (state
.x - l.pagedispx) state
.y
5852 match conf
.columns
with
5853 | Csingle
_ | Csplit
_ -> 1
5854 | Cmulti
((n, _, _), _) -> n
5856 layout 0 state
.y (state
.winw * mult) state
.winh
5860 | "activatewin", "" -> Wsi.activatewin
()
5861 | "quit", "" -> raise Quit
5864 let l = Config.keys_of_string
keys in
5865 List.iter
(fun (k
, m) -> keyboard k
m) l
5866 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
5869 | "clearrects", "" ->
5870 Hashtbl.clear state
.prects
;
5871 G.postRedisplay "clearrects"
5873 adderrfmt "remote command"
5874 "error processing remote command: %S\n" cmds
;
5878 let scratch = Bytes.create
80 in
5879 let buf = Buffer.create
80 in
5881 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
5882 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
5885 if Buffer.length
buf > 0
5887 let s = Buffer.contents
buf in
5895 match Bytes.index_from
scratch ppos '
\n'
with
5896 | pos
-> if pos
>= n then -1 else pos
5897 | exception Not_found
-> -1
5901 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
5902 let s = Buffer.contents
buf in
5908 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
5914 let remoteopen path =
5915 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
5917 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
5922 let gcconfig = ref false in
5923 let trimcachepath = ref E.s in
5924 let rcmdpath = ref E.s in
5925 let pageno = ref None
in
5926 let openlast = ref false in
5927 let doreap = ref false in
5928 let csspath = ref None
in
5929 selfexec := Sys.executable_name
;
5932 [("-p", Arg.String
(fun s -> state
.password <- s),
5933 "<password> Set password");
5937 Config.fontpath
:= s;
5938 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
5940 "<path> Set path to the user interface font");
5944 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
5945 Config.confpath
:= s),
5946 "<path> Set path to the configuration file");
5948 ("-last", Arg.Set
openlast, " Open last document");
5950 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
5951 "<page-number> Jump to page");
5953 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
5954 "<path> Set path to the trim cache file");
5956 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
5957 "<named-destination> Set named destination");
5959 ("-remote", Arg.String
(fun s -> rcmdpath := s),
5960 "<path> Set path to the source of remote commands");
5962 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
5964 ("-v", Arg.Unit
(fun () ->
5966 "%s\nconfiguration path: %s\n"
5969 exit
0), " Print version and exit");
5971 ("-css", Arg.String
(fun s -> csspath := Some
s),
5972 "<path> Set path to the style sheet to use with EPUB/HTML");
5974 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
5975 "<origin> <undocumented>");
5977 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title");
5978 ("-layout-height", Arg.Set_int
layouth,
5979 "<height> layout height html/epub/etc (-1, 0, N)");
5982 (fun s -> state
.path <- s)
5983 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
5985 let histmode = emptystr state
.path && not
!openlast in
5987 if not
(Config.load !openlast)
5988 then dolog
"failed to load configuration";
5990 begin match !pageno with
5991 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
6004 val mutable m_clicks
= 0
6005 val mutable m_click_x
= 0
6006 val mutable m_click_y
= 0
6007 val mutable m_lastclicktime
= infinity
6009 method private cleanup =
6010 state
.roam
<- noroam
;
6011 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
6012 method expose
= G.postRedisplay "expose"
6016 | Wsi.Unobscured
-> "unobscured"
6017 | Wsi.PartiallyObscured
-> "partiallyobscured"
6018 | Wsi.FullyObscured
-> "fullyobscured"
6020 vlog "visibility change %s" name
6021 method display = display ()
6022 method map mapped
= vlog "mapped %b" mapped
6023 method reshape w h =
6026 method mouse
b d x y m =
6027 if d && canselect ()
6030 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
6037 if abs
x - m_click_x
> 10
6038 || abs
y - m_click_y
> 10
6039 || abs_float
(t -. m_lastclicktime
) > 0.3
6041 m_clicks
<- m_clicks
+ 1;
6042 m_lastclicktime
<- t;
6046 G.postRedisplay "cleanup";
6047 state
.uioh <- state
.uioh#button
b d x y m;
6049 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
6054 m_lastclicktime
<- infinity
;
6055 state
.uioh <- state
.uioh#button
b d x y m
6059 state
.uioh <- state
.uioh#button
b d x y m
6062 state
.mpos
<- (x, y);
6063 state
.uioh <- state
.uioh#motion
x y
6064 method pmotion
x y =
6065 state
.mpos
<- (x, y);
6066 state
.uioh <- state
.uioh#pmotion
x y
6068 vlog "k=%#x m=%#x" k
m;
6069 let mascm = m land (
6070 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6073 let x = state
.x and y = state
.y in
6075 if x != state
.x || y != state
.y then self#
cleanup
6077 match state
.keystate
with
6079 let km = k
, mascm in
6082 let modehash = state
.uioh#
modehash in
6083 try Hashtbl.find modehash km
6085 try Hashtbl.find (findkeyhash conf
"global") km
6086 with Not_found
-> KMinsrt
(k
, m)
6088 | KMinsrt
(k
, m) -> keyboard k
m
6089 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
6090 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
6092 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
6093 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
6094 state
.keystate
<- KSnone
6095 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
6096 state
.keystate
<- KSinto
(keys, insrt
)
6097 | KSinto
_ -> state
.keystate
<- KSnone
6100 state
.mpos
<- (x, y);
6101 state
.uioh <- state
.uioh#pmotion
x y
6102 method leave = state
.mpos
<- (-1, -1)
6103 method winstate wsl
= state
.winstate
<- wsl
6104 method quit
: '
a. '
a = raise Quit
6105 method scroll
dx dy = state
.uioh <- state
.uioh#scroll
dx dy
6106 method zoom z
x y = state
.uioh#
zoom z
x y
6107 method opendoc path =
6110 G.postRedisplay "opendoc";
6111 opendoc path state
.password
6114 let wsfd, winw, winh
= Wsi.init
mu conf
.cwinw conf
.cwinh platform
in
6117 if not
@@ List.exists
GlMisc.check_extension
6118 [ "GL_ARB_texture_rectangle"
6119 ; "GL_EXT_texture_recangle"
6120 ; "GL_NV_texture_rectangle" ]
6121 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
6123 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
6125 defconf
.sliceheight
<- 1024;
6126 defconf
.texcount
<- 32;
6127 defconf
.usepbo
<- true;
6131 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
6133 dolog
"socketpair failed: %s" @@ exntos exn
;
6141 setcheckers conf
.checkers
;
6143 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
6145 begin match !csspath with
6147 | Some
"" -> conf
.css
<- E.s
6149 let css = filecontents
path in
6150 let l = String.length
css in
6152 if substratis
css (l-2) "\r\n"
6153 then String.sub css 0 (l-2)
6154 else (if css.[l-1] = '
\n'
6155 then String.sub css 0 (l-1)
6159 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
6160 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
6161 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
6163 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
6165 reshape ~firsttime
:true winw winh
;
6169 Wsi.settitle
"llpp (history)";
6173 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
6174 opendoc state
.path state
.password;
6178 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6179 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
6182 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
6183 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
6184 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
6186 | _pid
, _status
-> reap ()
6188 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
6192 if nonemptystr
!rcmdpath
6193 then remoteopen !rcmdpath
6198 let rec loop deadline
=
6204 let r = [state
.ss; state
.wsfd] in
6208 | Some fd
-> fd
:: r
6212 state
.redisplay
<- false;
6219 if deadline
= infinity
6221 else max
0.0 (deadline
-. now)
6226 try Unix.select
r [] [] timeout
6227 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6232 match state
.autoscroll
with
6233 | Some step
when step
!= 0 ->
6234 if state
.slideshow
land 1 = 1
6236 if state
.slideshow
land 2 = 0
6237 then state
.slideshow
<- state
.slideshow
lor 2
6238 else if step
< 0 then prevpage () else nextpage ();
6239 deadline
+. (float (abs step
))
6242 let y = state
.y + step
in
6243 let fy = if conf
.maxhfit
then state
.winh
else 0 in
6246 then state
.maxy - fy
6247 else if y >= state
.maxy - fy then 0 else y
6256 let rec checkfds = function
6258 | fd
:: rest
when fd
= state
.ss ->
6259 let cmd = rcmd state
.ss in
6263 | fd
:: rest
when fd
= state
.wsfd ->
6267 | fd
:: rest
when Some fd
= !optrfd ->
6268 begin match remote fd
with
6269 | None
-> optrfd := remoteopen !rcmdpath;
6270 | opt -> optrfd := opt
6275 dolog
"select returned unknown descriptor";
6281 if deadline
= infinity
6285 match state
.autoscroll
with
6286 | Some step
when step
!= 0 -> deadline1
6292 match loop infinity
with
6294 Config.save leavebirdseye;
6295 if hasunsavedchanges
()
6297 | _ -> error
"umpossible - infinity reached"