6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
10 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
11 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
12 external clearmark
: opaque
-> unit = "ml_clearmark";;
13 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
14 external getmaxw
: unit -> float = "ml_getmaxw";;
15 external postprocess
:
16 opaque
-> int -> int -> int -> (int * string * int) -> int
18 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
19 external setaalevel
: int -> unit = "ml_setaalevel";;
20 external realloctexts
: int -> bool = "ml_realloctexts";;
21 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
22 external getlink
: opaque
-> int -> under
= "ml_getlink";;
23 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
24 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
25 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
26 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
27 external freepbo
: opaque
-> unit = "ml_freepbo";;
28 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
29 external bousable
: unit -> bool = "ml_bo_usable";;
31 opaque
-> int -> int -> (int * int) option = "ml_unproject";;
33 opaque
-> int -> int -> float -> float -> (float * float) = "ml_project";;
35 tileparams
-> opaque
-> unit = "ml_drawtile";;
36 external rectofblock
:
37 opaque
-> int -> int -> float array
option = "ml_rectofblock";;
38 external begintiles
: unit -> unit = "ml_begintiles";;
39 external endtiles
: unit -> unit = "ml_endtiles";;
40 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
41 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
42 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
43 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
44 external savedoc
: string -> unit = "ml_savedoc";;
45 external getannotcontents
:
46 opaque
-> slinkindex
-> string = "ml_getannotcontents";;
48 opaque
-> int -> int -> float array
-> unit = "ml_drawprect";;
49 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
50 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
51 external uritolocation
:
52 string -> (pageno
* float * float) = "ml_uritolocation";;
53 external isexternallink
: string -> bool = "ml_isexternallink";;
55 (* copysel _will_ close the supplied descriptor *)
56 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
58 let selfexec = ref E.s
;;
59 let ignoredoctitlte = ref false;;
60 let opengl_has_pbo = ref false;;
61 let layouth = ref ~
-1;;
63 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
69 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
72 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
75 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
76 && (state
.w
> state
.winw
))
83 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
84 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
90 else Printf.kprintf ignore fmt
94 if emptystr conf
.pathlauncher
95 then dolog
"%s" state
.path
98 Str.global_replace
Utils.Re.percent state
.path conf
.pathlauncher
in
99 match spawn
command [] with
102 dolog
"failed to execute `%s': %s" command @@ exntos exn
106 let getopaque pageno
=
107 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
108 with Not_found
-> None
111 let pagetranslatepoint l x y
=
112 let dy = y
- l
.pagedispy
in
113 let y = dy + l
.pagey
in
114 let dx = x
- l
.pagedispx
in
115 let x = dx + l
.pagex
in
119 let onppundermouse g
x y d
=
122 begin match getopaque l
.pageno
with
124 let x0 = l
.pagedispx
in
125 let x1 = x0 + l
.pagevw
in
126 let y0 = l
.pagedispy
in
127 let y1 = y0 + l
.pagevh
in
128 if y >= y0 && y <= y1 && x >= x0 && x <= x1
130 let px, py
= pagetranslatepoint l
x y in
131 match g opaque l
px py
with
144 let g opaque l
px py
=
147 match rectofblock opaque
px py
with
148 | Some
[|x0;x1;y0;y1|] ->
149 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
150 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
151 state
.rects
<- [l
.pageno
, color, rect];
152 postRedisplay
"getunder";
155 let under = whatsunder opaque
px py
in
156 if under = Unone
then None
else Some
under
158 onppundermouse g x y Unone
163 match unproject opaque
x y with
164 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
167 onppundermouse g x y None
;
171 state
.text
<- Printf.sprintf
"%c%s" c s
;
172 postRedisplay
"showtext";
176 Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;
179 let pipesel opaque cmd
=
181 then pipef ~closew
:false "pipesel"
184 postRedisplay
"pipesel"
189 let g opaque l
px py
=
190 if markunder opaque
px py conf
.paxmark
193 match getopaque l
.pageno
with
195 | Some opaque
-> pipesel opaque conf
.paxcmd
200 postRedisplay
"paxunder";
201 if conf
.paxmark
= Mark_page
204 match getopaque l
.pageno
with
206 | Some opaque
-> clearmark opaque
) state
.layout
;
207 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
210 let undertext = function
213 | Utext s
-> "font: " ^ s
214 | Uannotation
(opaque
, slinkindex
) ->
215 "annotation: " ^ getannotcontents opaque slinkindex
218 let updateunder x y =
219 match getunder x y with
220 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
222 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
223 Wsi.setcursor
Wsi.CURSOR_INFO
225 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
226 Wsi.setcursor
Wsi.CURSOR_TEXT
228 if conf
.underinfo
then showtext 'a'
"nnotation";
229 Wsi.setcursor
Wsi.CURSOR_INFO
232 let showlinktype under =
233 if conf
.underinfo
&& under != Unone
234 then showtext ' '
@@ undertext under
237 let intentry_with_suffix text key
=
239 match [@warning
"-4"] key
with
240 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
241 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
242 addchar
text @@ asciilower c
244 state
.text <- Printf.sprintf
"invalid key";
251 let b = Buffer.create
16 in
254 let b = Buffer.to_bytes
b in
255 wcmd state
.ss
b @@ Bytes.length
b
259 let nogeomcmds cmds
=
261 | s
, [] -> emptystr s
265 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
266 let rec fold accu n
=
267 if n
= Array.length
b
270 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n
) in
273 || n
= state
.pagecount
- coverB
274 || (n
- coverA
) mod columns
= columns
- 1)
280 let pagey = max
0 (y - vy
) in
281 let pagedispy = if pagey > 0 then 0 else vy
- y in
282 let pagedispx, pagex
=
284 if n
= coverA
- 1 || n
= state
.pagecount
- coverB
285 then x + (sw
- w
) / 2
293 let vw = sw
- pagedispx in
294 let pw = w
- pagex
in
297 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
298 if pagevw > 0 && pagevh > 0
309 ; pagedispx = pagedispx
310 ; pagedispy = pagedispy
322 if Array.length
b = 0
324 else List.rev
(fold [] (page_of_y
y))
327 let layoutS (columns
, b) x y sw sh
=
328 let rec fold accu n
=
329 if n
= Array.length
b
332 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n
) in
340 let pagey = max
0 (y - vy
) in
341 let pagedispy = if pagey > 0 then 0 else vy
- y in
342 let pagedispx, pagex
=
356 let pagecolw = pagew
/columns
in
359 then pagedispx + ((sw
- pagecolw) / 2)
363 let vw = sw
- pagedispx in
364 let pw = pagew
- pagex
in
367 let pagevw = min
pagevw pagecolw in
368 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
369 if pagevw > 0 && pagevh > 0
380 ; pagedispx = pagedispx
381 ; pagedispy = pagedispy
382 ; pagecol
= n
mod columns
396 let layout x y sw sh
=
397 if nogeomcmds state
.geomcmds
399 match conf
.columns
with
400 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
401 | Cmulti c
-> layoutN c
x y sw sh
402 | Csplit s
-> layoutS s
x y sw sh
406 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
408 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
411 let tilex = l
.pagex
mod conf
.tilew
in
412 let tiley = l
.pagey mod conf
.tileh
in
414 let col = l
.pagex
/ conf
.tilew
in
415 let row = l
.pagey / conf
.tileh
in
417 let rec rowloop row y0 dispy h
=
421 let dh = conf
.tileh
- y0 in
423 let rec colloop col x0 dispx w
=
427 let dw = conf
.tilew
- x0 in
429 f col row dispx dispy
x0 y0 dw dh;
430 colloop (col+1) 0 (dispx
+dw) (w
-dw)
433 colloop col tilex l
.pagedispx l
.pagevw;
434 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
437 if l
.pagevw > 0 && l
.pagevh > 0
438 then rowloop row tiley l
.pagedispy l
.pagevh;
441 let gettileopaque l
col row =
443 l
.pageno
, state
.gen
, conf
.colorspace
, conf
.angle
, l
.pagew
, l
.pageh
, col, row
445 try Some
(Hashtbl.find state
.tilemap
key)
446 with Not_found
-> None
449 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
450 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
451 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
454 let drawtiles l
color =
457 let f col row x y tilex tiley w h
=
458 match gettileopaque l
col row with
459 | Some
(opaque
, _
, t
) ->
460 let params = x, y, w
, h
, tilex, tiley in
462 then GlTex.env
(`mode `blend
);
463 drawtile
params opaque
;
465 then GlTex.env
(`mode `modulate
);
469 let s = Printf.sprintf
473 let w = measurestr fstate
.fontsize
s in
474 GlDraw.color (0.0, 0.0, 0.0);
475 filledrect
(float (x-2))
478 (float (y + fstate
.fontsize
+ 2));
480 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
487 let lw = state
.winw
- x in
490 let lh = state
.winh
- y in
494 then GlTex.env
(`mode `blend
);
495 begin match state
.checkerstexid
with
497 Gl.enable `texture_2d
;
498 GlTex.bind_texture ~target
:`texture_2d id
;
502 and y1 = float (y+h
) in
504 let tw = float w /. 16.0
505 and th
= float h
/. 16.0 in
506 let tx0 = float tilex /. 16.0
507 and ty0
= float tiley /. 16.0 in
509 and ty1
= ty0
+. th
in
510 Raw.sets_float
Glutils.vraw ~pos
:0
511 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
512 Raw.sets_float
Glutils.traw ~pos
:0
513 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
514 GlArray.vertex `two
Glutils.vraw
;
515 GlArray.tex_coord `two
Glutils.traw
;
516 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
517 Gl.disable `texture_2d
;
520 GlDraw.color (1.0, 1.0, 1.0);
521 filledrect
(float x) (float y) (float (x+w)) (float (y+h
));
524 then GlTex.env
(`mode `modulate
);
525 if w > 128 && h
> fstate
.fontsize
+ 10
527 let c = if conf
.invert
then 1.0 else 0.0 in
528 GlDraw.color (c, c, c);
531 then (col*conf
.tilew
, row*conf
.tileh
)
534 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
543 let pagevisible layout n
= List.exists
(fun l
-> l
.pageno
= n
) layout;;
545 let tilevisible1 l
x y =
547 and ax1
= l
.pagex
+ l
.pagevw
549 and ay1
= l
.pagey + l
.pagevh in
553 let bx1 = min
(bx0 + conf
.tilew
) l
.pagew
554 and by1
= min
(by0
+ conf
.tileh
) l
.pageh
in
556 let rx0 = max
ax0 bx0
557 and ry0
= max ay0 by0
558 and rx1
= min ax1
bx1
559 and ry1
= min ay1 by1
in
561 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
565 let tilevisible layout n
x y =
566 let rec findpageinlayout m
= function
567 | l
:: rest
when l
.pageno
= n
->
568 tilevisible1 l
x y || (
569 match conf
.columns
with
570 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
571 | Csplit _
| Csingle _
| Cmulti _
-> false
573 | _
:: rest
-> findpageinlayout 0 rest
576 findpageinlayout 0 layout;
579 let tileready l
x y =
580 tilevisible1 l
x y &&
581 gettileopaque l
(x/conf
.tilew
) (y/conf
.tileh
) != None
584 let tilepage n p
layout =
585 let rec loop = function
589 let f col row _ _ _ _ _ _
=
590 if state
.currently
= Idle
592 match gettileopaque l
col row with
595 let x = col*conf
.tilew
596 and y = row*conf
.tileh
in
598 let w = l
.pagew
- x in
602 let h = l
.pageh
- y in
607 then getpbo
w h conf
.colorspace
610 wcmd "tile %s %d %d %d %d %s"
611 (~
> p
) x y w h (~
> pbo);
614 l
, p
, conf
.colorspace
, conf
.angle
,
615 state
.gen
, col, row, conf
.tilew
, conf
.tileh
624 if nogeomcmds state
.geomcmds
628 let preloadlayout x y sw sh
=
629 let y = if y < sh
then 0 else y - sh
in
630 let x = min
0 (x + sw
) in
638 if state
.currently
!= Idle
643 begin match getopaque l
.pageno
with
645 wcmd "page %d %d" l
.pageno l
.pagedimno
;
646 state
.currently
<- Loading
(l
, state
.gen
);
648 tilepage l
.pageno opaque pages
;
653 if nogeomcmds state
.geomcmds
659 if conf
.preload && state
.currently
= Idle
660 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
663 let layoutready layout =
664 let rec fold all ls
=
667 let seen = ref false in
668 let allvisible = ref true in
669 let foo col row _ _ _ _ _ _
=
671 allvisible := !allvisible &&
672 begin match gettileopaque l
col row with
678 fold (!seen && !allvisible) rest
681 let alltilesvisible = fold true layout in
686 let y = bound
y 0 state
.maxy in
688 let layout = layout x y state
.winw state
.winh
in
689 postRedisplay
"gotoxy ready";
694 state
.layout <- layout;
695 begin match state
.mode
with
698 | Ltexact
(pageno
, linkno
) ->
699 let rec loop = function
701 state
.lnava
<- Some
(pageno
, linkno
);
702 state
.mode
<- LinkNav
(Ltgendir
0)
703 | l
:: _
when l
.pageno
= pageno
->
704 begin match getopaque pageno
with
705 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
707 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
708 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
709 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
710 then state
.mode
<- LinkNav
(Ltgendir
0)
712 | _
:: rest
-> loop rest
715 | Ltnotready _
| Ltgendir _
-> ()
717 | Birdseye _
| Textentry _
| View
-> ()
719 begin match state
.mode
with
720 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
721 if not
(pagevisible layout pageno
)
723 match state
.layout with
726 state
.mode
<- Birdseye
(
727 conf
, leftx
, l
.pageno
, hooverpageno
, anchor
732 | Ltnotready
(_
, dir
)
735 let rec loop = function
738 match getopaque l
.pageno
with
739 | None
-> Ltnotready
(l
.pageno
, dir
)
744 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
746 if dir
> 0 then LDfirst
else LDlast
752 | Lnotfound
-> loop rest
754 showlinktype (getlink opaque n
);
755 Ltexact
(l
.pageno
, n
)
759 state
.mode
<- LinkNav
linknav
762 | Textentry _
| View
-> ()
767 let mx, my
= state
.mpos
in
772 let conttiling pageno opaque
=
773 tilepage pageno opaque
775 then preloadlayout state
.x state
.y state
.winw state
.winh
780 if not conf
.verbose
then state
.text <- E.s;
784 let getanchory (n
, top
, dtop
) =
785 let y, h = getpageyh n
in
788 let ips = calcips
h in
789 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
791 y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
794 let gotoanchor anchor
=
795 gotoxy state
.x (getanchory anchor
);
799 getanchor
() |> cbput state
.hists
.nav
;
803 getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;
807 let anchor = cbgetc state
.hists
.nav dir
in
812 let y, h = getpageyh n
in
813 let y = y + (truncate
(top
*. float h)) in
817 let gotopage1 n top
=
818 let y = getpagey n
in
824 Glutils.redisplay
:= false;
829 match state
.geomcmds
with
830 | ps
, [] when emptystr ps
->
832 state
.geomcmds
<- s, [];
835 state
.geomcmds
<- ps
, [s, f];
837 | ps
, (s'
, _
) :: rest
when s'
= s ->
838 state
.geomcmds
<- ps
, ((s, f) :: rest
);
841 state
.geomcmds
<- ps
, ((s, f) :: cmds
);
845 Hashtbl.iter
(fun _ opaque
->
846 wcmd "freepage %s" (~
> opaque
);
848 Hashtbl.clear state
.pagemap
;
852 if not
(Queue.is_empty state
.tilelru
)
854 Queue.iter
(fun (k
, p
, s) ->
855 wcmd "freetile %s" (~
> p
);
856 state
.memused
<- state
.memused
- s;
857 Hashtbl.remove state
.tilemap k
;
859 state
.uioh#infochanged Memused
;
860 Queue.clear state
.tilelru
;
866 let h = truncate
(float h*.conf
.zoom
) in
867 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
873 let sl = keystostrlist conf
in
875 function | [] -> accu
876 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
877 in Help.makehelp conf
.urilauncher
878 @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
881 let opendoc path password
=
883 state
.password
<- password
;
884 state
.gen
<- state
.gen
+ 1;
886 state
.outlines
<- [||];
889 setaalevel conf
.aalevel
;
891 if emptystr state
.origin
895 Wsi.settitle
("llpp " ^ mbtoutf8
(Filename.basename
titlepath));
896 wcmd "open %d %d %s\000%s\000%s\000"
897 (btod conf
.usedoccss
) !layouth
898 path password conf
.css
;
899 invalidate "reqlayout"
901 wcmd "reqlayout %d %d %d %s\000"
902 conf
.angle
(FMTE.to_int conf
.fitmodel
)
903 (stateh state
.winh
) state
.nameddest
909 state
.anchor <- getanchor
();
910 opendoc state
.path state
.password
;
914 let c = c *. conf
.colorscale
in
918 let scalecolor2 (r
, g, b) =
919 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
922 let docolumns columns
=
925 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
926 let rec loop pageno
pdimno pdim
y ph pdims
=
927 if pageno
= state
.pagecount
930 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
932 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
937 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
939 y + (if conf
.presentation
940 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
941 else (if pageno
= 0 then 0 else conf
.interpagespace
)
944 a.(pageno
) <- (pdimno, x, y, pdim
);
945 loop (pageno
+1) pdimno pdim
(y + h) h pdims
947 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
948 conf
.columns
<- Csingle
a;
950 | Cmulti
((columns
, coverA
, coverB
), _
) ->
951 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
952 let rec loop pageno
pdimno pdim
x y rowh pdims
=
954 if m
= pageno
then () else
955 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
958 let y = y + (rowh
- h) / 2 in
959 a.(m
) <- (pdimno, x, y, pdim
);
963 if pageno
= state
.pagecount
964 then fixrow (((pageno
- 1) / columns
) * columns
)
966 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
968 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
974 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
976 let x = (state
.winw
- w) / 2 in
978 if conf
.presentation
then calcips
h else conf
.interpagespace
in
982 if (pageno
- coverA
) mod columns
= 0
984 let x = max
0 (state
.winw
- state
.w) / 2 in
988 let ips = calcips
h in
989 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
991 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
995 else x, y, max rowh
h
999 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1002 if pageno
= columns
&& conf
.presentation
1004 let ips = calcips rowh
in
1005 for i
= 0 to pred columns
1007 let (pdimno, x, y, pdim
) = a.(i
) in
1008 a.(i
) <- (pdimno, x, y+ips, pdim
)
1014 fixrow (pageno
- columns
);
1019 a.(pageno
) <- (pdimno, x, y, pdim
);
1020 let x = x + w + xoff
*2 + conf
.interpagespace
in
1021 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1023 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
1024 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1027 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1028 let rec loop pageno
pdimno pdim
y pdims
=
1029 if pageno
= state
.pagecount
1032 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1034 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1035 pdimno+1, pdim
, rest
1040 let rec loop1 n
x y =
1041 if n
= c then y else (
1042 a.(pageno
*c + n
) <- (pdimno, x, y, pdim
);
1043 loop1 (n
+1) (x+cw) (y + h + conf
.interpagespace
)
1046 let y = loop1 0 0 y in
1047 loop (pageno
+1) pdimno pdim
y pdims
1049 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1050 conf
.columns
<- Csplit
(c, a);
1054 docolumns conf
.columns
;
1055 state
.maxy <- calcheight
();
1056 if state
.reprf
== noreprf
1058 match state
.mode
with
1059 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1060 let y, h = getpageyh pageno
in
1061 let top = (state
.winh
- h) / 2 in
1062 gotoxy state
.x (max
0 (y - top))
1063 | Textentry _
| View
| LinkNav _
->
1064 let y = getanchory state
.anchor in
1065 let y = min
y (state
.maxy - state
.winh
) in
1070 state
.reprf
<- noreprf
;
1074 let reshape ?
(firsttime
=false) w h =
1075 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1076 if not firsttime
&& nogeomcmds state
.geomcmds
1077 then state
.anchor <- getanchor
();
1080 let w = truncate
(float w *. conf
.zoom
) in
1083 setfontsize fstate
.fontsize
;
1084 GlMat.mode `modelview
;
1085 GlMat.load_identity
();
1087 GlMat.mode `projection
;
1088 GlMat.load_identity
();
1089 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1090 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1091 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1096 else float state
.x /. float state
.w
1098 invalidate "geometry"
1102 then state
.x <- truncate
(relx *. float w);
1104 match conf
.columns
with
1106 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1107 | Csplit
(c, _
) -> w * c
1109 wcmd "geometry %d %d %d"
1110 w (stateh h) (FMTE.to_int conf
.fitmodel
)
1115 let len = Queue.length state
.tilelru
in
1116 let layout = lazy (if conf
.preload
1117 then preloadlayout state
.x state
.y state
.winw state
.winh
1118 else state
.layout) in
1120 if state
.memused
> conf
.memlimit
1124 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1125 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1126 let (_
, pw, ph
, _
) = getpagedim
n in
1128 && colorspace
= conf
.colorspace
1129 && angle
= conf
.angle
1133 let x = col*conf
.tilew
1134 and y = row*conf
.tileh
in
1135 tilevisible (Lazy.force_val
layout) n x y
1137 then Queue.push lruitem state
.tilelru
1140 wcmd "freetile %s" (~
> p
);
1141 state
.memused
<- state
.memused
- s;
1142 state
.uioh#infochanged Memused
;
1143 Hashtbl.remove state
.tilemap k
;
1151 let onpagerect pageno
f =
1153 match conf
.columns
with
1154 | Cmulti
(_
, b) -> b
1156 | Csplit
(_
, b) -> b
1158 if pageno
>= 0 && pageno
< Array.length
b
1160 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1164 let gotopagexy1 pageno
x y =
1165 let _,w1
,h1
,leftx
= getpagedim pageno
in
1166 let top = y /. (float h1
) in
1167 let left = x /. (float w1
) in
1168 let py, w, h = getpageywh pageno
in
1169 let wh = state
.winh
in
1170 let x = left *. (float w) in
1171 let x = leftx
+ state
.x + truncate
x in
1173 if x < 0 || x >= state
.winw
1177 let pdy = truncate
(top *. float h) in
1178 let y'
= py + pdy in
1179 let dy = y'
- state
.y in
1181 if x != state
.x || not
(dy > 0 && dy < wh)
1183 if conf
.presentation
1185 if abs
(py - y'
) > wh
1192 if state
.x != sx || state
.y != sy
1194 else gotoxy state
.x state
.y;
1197 let gotopagexy pageno
x y =
1198 match state
.mode
with
1199 | Birdseye
_ -> gotopage pageno
0.0
1200 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 pageno
x y
1203 let getpassword () =
1204 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1209 impmsg "error getting password: %s" s;
1210 dolog
"%s" s) passcmd;
1213 let pgoto opaque pageno
x y =
1214 let pdimno = getpdimno pageno
in
1215 let x, y = project opaque pageno
pdimno x y in
1216 gotopagexy pageno
x y;
1220 (* dolog "%S" cmds; *)
1221 let spl = splitatchar cmds ' '
in
1223 try Scanf.sscanf
s fmt
f
1225 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1228 let addoutline outline
=
1229 match state
.currently
with
1230 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1231 | Idle
-> state
.currently
<- Outlining
[outline
]
1232 | Loading
_ | Tiling
_ ->
1233 dolog
"invalid outlining state";
1234 logcurrently state
.currently
1239 state
.uioh#infochanged Pdim
;
1241 | "clearrects", "" ->
1242 state
.rects
<- state
.rects1
;
1243 postRedisplay
"clearrects";
1245 | "continue", args
->
1246 let n = scan args
"%u" (fun n -> n) in
1247 state
.pagecount
<- n;
1248 begin match state
.currently
with
1250 state
.currently
<- Idle
;
1251 state
.outlines
<- Array.of_list
(List.rev l
)
1252 | Idle
| Loading
_ | Tiling
_ -> ()
1255 let cur, cmds
= state
.geomcmds
in
1257 then failwith
"umpossible";
1259 begin match List.rev cmds
with
1261 state
.geomcmds
<- E.s, [];
1265 state
.geomcmds
<- s, List.rev rest
;
1267 postRedisplay
"continue";
1274 then showtext ' ' args
1277 Buffer.add_string state
.errmsgs args
;
1278 state
.newerrmsgs
<- true;
1279 postRedisplay
"error message"
1281 | "progress", args
->
1282 let progress, text =
1285 f, String.sub args pos
(String.length args
- pos
))
1288 state
.progress <- progress;
1289 postRedisplay
"progress"
1291 | "firstmatch", args
->
1292 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1293 scan args
"%u %d %f %f %f %f %f %f %f %f"
1294 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1295 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1297 let y = (getpagey
pageno) + truncate
y0 in
1299 if (state
.x < - truncate
x0) || (state
.x > state
.winw
- truncate
x1)
1300 then state
.winw
/2 - truncate
(x0 /. 2. +. x1 /. 2.)
1305 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1306 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1309 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1310 scan args
"%u %d %f %f %f %f %f %f %f %f"
1311 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1312 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1314 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1316 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1319 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1320 let pageopaque = ~
< pageopaques in
1321 begin match state
.currently
with
1322 | Loading
(l
, gen
) ->
1323 vlog "page %d took %f sec" l
.pageno t
;
1324 Hashtbl.replace state
.pagemap
(l
.pageno, gen
) pageopaque;
1325 let preloadedpages =
1327 then preloadlayout state
.x state
.y state
.winw state
.winh
1331 let set = List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
1332 IntSet.empty
preloadedpages
1335 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1336 if not
(IntSet.mem
pageno set)
1338 wcmd "freepage %s" (~
> opaque
);
1344 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1347 state
.currently
<- Idle
;
1350 tilepage l
.pageno pageopaque state
.layout;
1352 load preloadedpages;
1353 let visible = pagevisible state
.layout l
.pageno in
1356 match state
.mode
with
1357 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1358 if pageno = l
.pageno
1363 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1365 if dir
> 0 then LDfirst
else LDlast
1368 findlink
pageopaque ld
1373 showlinktype (getlink
pageopaque n);
1374 state
.mode
<- LinkNav
(Ltexact
(l
.pageno, n))
1376 | LinkNav
(Ltgendir
_)
1377 | LinkNav
(Ltexact
_)
1383 if visible && layoutready state
.layout
1385 postRedisplay
"page";
1389 | Idle
| Tiling
_ | Outlining
_ ->
1390 dolog
"Inconsistent loading state";
1391 logcurrently state
.currently
;
1396 let (x, y, opaques
, size
, t
) =
1397 scan args
"%u %u %s %u %f"
1398 (fun x y p size t
-> (x, y, p
, size
, t
))
1400 let opaque = ~
< opaques
in
1401 begin match state
.currently
with
1402 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1403 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
1406 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1408 wcmd "freetile %s" (~
> opaque);
1409 state
.currently
<- Idle
;
1413 puttileopaque l
col row gen cs angle
opaque size t
;
1414 state
.memused
<- state
.memused
+ size
;
1415 state
.uioh#infochanged Memused
;
1417 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
1418 opaque, size
) state
.tilelru
;
1420 state
.currently
<- Idle
;
1422 && conf
.colorspace
= cs
1423 && conf
.angle
= angle
1424 && tilevisible state
.layout l
.pageno x y
1425 then conttiling l
.pageno pageopaque;
1427 preload state
.layout;
1429 && conf
.colorspace
= cs
1430 && conf
.angle
= angle
1431 && tilevisible state
.layout l
.pageno x y
1432 && layoutready state
.layout
1433 then postRedisplay
"tile nothrottle";
1436 | Idle
| Loading
_ | Outlining
_ ->
1437 dolog
"Inconsistent tiling state";
1438 logcurrently state
.currently
;
1443 let (n, w, h, _) as pdim
=
1444 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1447 match conf
.fitmodel
with
1449 | FitPage
| FitProportional
->
1450 match conf
.columns
with
1451 | Csplit
_ -> (n, w, h, 0)
1452 | Csingle
_ | Cmulti
_ -> pdim
1454 state
.pdims
<- pdim :: state
.pdims
;
1455 state
.uioh#infochanged Pdim
1458 let (l
, n, t
, h, pos
) =
1459 scan args
"%u %u %d %u %n"
1460 (fun l
n t
h pos
-> l
, n, t
, h, pos
)
1462 let s = String.sub args pos
(String.length args
- pos
) in
1463 addoutline (s, l
, Oanchor
(n, float t
/. float h, 0.0))
1466 let (l
, len, pos
) = scan args
"%u %u %n" (fun l
len pos
-> l
, len, pos
) in
1467 let s = String.sub args pos
len in
1468 let pos2 = pos
+ len + 1 in
1469 let uri = String.sub args
pos2 (String.length args
- pos2) in
1470 addoutline (s, l
, Ouri
uri)
1473 let (l
, pos
) = scan args
"%u %n" (fun l pos
-> l
, pos
) in
1474 let s = String.sub args pos
(String.length args
- pos
) in
1475 addoutline (s, l
, Onone
)
1479 scan args
"%u %d %d" (fun n l t
-> n, l
, t
)
1481 state
.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
1484 let c, v
= splitatchar args '
\t'
in
1491 if not
!ignoredoctitlte
1492 then Wsi.settitle v
;
1496 if let len = String.length
c in
1497 len > 6 && ((String.sub
c (len-4) 4) = "date")
1499 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1501 let b = Buffer.create
10 in
1502 Printf.bprintf
b "%s\t" c;
1505 Buffer.add_substring
b v p l
;
1506 Buffer.add_char
b c;
1507 with exn
-> Buffer.add_string
b @@ exntos exn
1515 Buffer.add_char
b '
['
;
1516 Buffer.add_string
b v
;
1517 Buffer.add_char
b '
]'
;
1524 state
.docinfo
<- (1, s) :: state
.docinfo
1527 state
.docinfo
<- List.rev state
.docinfo
;
1528 state
.uioh#infochanged Docinfo
1532 then Wsi.settitle
"Wrong password";
1533 let password = getpassword () in
1534 if emptystr
password
1535 then error
"document is password protected"
1536 else opendoc state
.path
password
1539 error
"unknown cmd `%S'" cmds
1544 let action = function
1545 | HCprev
-> cbget cb ~
-1
1546 | HCnext
-> cbget cb
1
1547 | HCfirst
-> cbget cb ~
-(cb
.rc)
1548 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1549 and cancel
() = cb
.rc <- rc
1553 let search pattern forward
=
1554 match conf
.columns
with
1555 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1556 | Csingle
_ | Cmulti
_ ->
1557 if nonemptystr pattern
1560 match state
.layout with
1563 l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
1565 wcmd "search %d %d %d %d,%s\000"
1566 (btod conf
.icase
) pn py (btod forward
) pattern
;
1569 let intentry text key =
1571 if emptystr
text && key = Keys.Ascii '
-'
1572 then addchar
text '
-'
1574 match [@warning
"-4"] key with
1575 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1577 state
.text <- "invalid key";
1587 let l = String.length
s in
1588 let rec loop pos
n =
1592 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1593 loop (pos
+1) (n*26 + m)
1596 let rec loop n = function
1599 match getopaque l.pageno with
1600 | None
-> loop n rest
1602 let m = getlinkcount
opaque in
1605 let under = getlink
opaque n in
1608 else loop (n-m) rest
1610 loop n state
.layout;
1614 let linknentry text =
1615 function [@warning
"-4"]
1617 let text = addchar
text c in
1618 linknact (fun under -> state
.text <- undertext under) text;
1621 state
.text <- Printf.sprintf
"invalid key";
1625 let textentry text = function [@warning
"-4"]
1626 | Keys.Ascii
c -> TEcont
(addchar
text c)
1627 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1631 let reqlayout angle fitmodel
=
1632 if nogeomcmds state
.geomcmds
1633 then state
.anchor <- getanchor
();
1634 conf
.angle
<- angle
mod 360;
1637 match state
.mode
with
1638 | LinkNav
_ -> state
.mode
<- View
1639 | Birdseye
_ | Textentry
_ | View
-> ()
1641 conf
.fitmodel
<- fitmodel
;
1645 wcmd "reqlayout %d %d %d"
1646 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1650 let settrim trimmargins trimfuzz
=
1651 if nogeomcmds state
.geomcmds
1652 then state
.anchor <- getanchor
();
1653 conf
.trimmargins
<- trimmargins
;
1654 conf
.trimfuzz
<- trimfuzz
;
1655 let x0, y0, x1, y1 = trimfuzz
in
1657 "settrim" (fun () ->
1658 wcmd "settrim %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1);
1663 let zoom = max
0.0001 zoom in
1664 if zoom <> conf
.zoom
1666 state
.prevzoom
<- (conf
.zoom, state
.x);
1668 reshape state
.winw state
.winh
;
1669 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
1673 let pivotzoom ?
(vw=min state
.w state
.winw
)
1674 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
1675 ?
(x=vw/2) ?
(y=vh
/2) zoom =
1676 let w = float state
.w /. zoom in
1677 let hw = w /. 2.0 in
1678 let ratio = float vh
/. float vw in
1679 let hh = hw *. ratio in
1680 let x0 = float x -. hw
1681 and y0 = float y -. hh in
1682 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
1686 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
1687 if nogeomcmds state
.geomcmds
1690 then pivotzoom ?
vw ?vh ?
x ?
y zoom
1694 let setcolumns mode columns coverA coverB
=
1695 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
1699 then impmsg "split mode doesn't work in bird's eye"
1701 conf
.columns
<- Csplit
(-columns
, E.a);
1709 conf
.columns
<- Csingle
E.a;
1714 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
1718 reshape state
.winw state
.winh
;
1721 let resetmstate () =
1722 state
.mstate
<- Mnone
;
1723 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
1726 let enterbirdseye () =
1727 let zoom = float conf
.thumbw
/. float state
.winw
in
1728 let birdseyepageno =
1729 let cy = state
.winh
/ 2 in
1733 let rec fold best
= function
1736 let d = cy - (l.pagedispy + l.pagevh/2)
1737 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
1738 if abs
d < abs dbest
1747 { conf
with zoom = conf
.zoom },
1748 state
.x, birdseyepageno, -1, getanchor
()
1752 conf
.presentation
<- false;
1753 conf
.interpagespace
<- 10;
1754 conf
.hlinks
<- false;
1755 conf
.fitmodel
<- FitPage
;
1758 match conf
.beyecolumns
with
1761 Cmulti
((c, 0, 0), E.a)
1762 | None
-> Csingle
E.a
1766 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1771 reshape state
.winw state
.winh
;
1774 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1776 conf
.zoom <- c.zoom;
1777 conf
.presentation
<- c.presentation
;
1778 conf
.interpagespace
<- c.interpagespace
;
1779 conf
.hlinks
<- c.hlinks
;
1780 conf
.fitmodel
<- c.fitmodel
;
1781 conf
.beyecolumns
<- (
1782 match conf
.columns
with
1783 | Cmulti
((c, _, _), _) -> Some
c
1785 | Csplit
_ -> failwith
"leaving bird's eye split mode"
1788 match c.columns
with
1789 | Cmulti
(c, _) -> Cmulti
(c, E.a)
1790 | Csingle
_ -> Csingle
E.a
1791 | Csplit
(c, _) -> Csplit
(c, E.a)
1795 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1798 reshape state
.winw state
.winh
;
1799 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
1803 let togglebirdseye () =
1804 match state
.mode
with
1805 | Birdseye vals
-> leavebirdseye vals
true
1806 | View
-> enterbirdseye ()
1807 | Textentry
_ | LinkNav
_ -> ()
1810 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1811 let pageno = max
0 (pageno - incr
) in
1812 let rec loop = function
1813 | [] -> gotopage1 pageno 0
1814 | l :: _ when l.pageno = pageno ->
1815 if l.pagedispy >= 0 && l.pagey = 0
1816 then postRedisplay
"upbirdseye"
1817 else gotopage1 pageno 0
1818 | _ :: rest
-> loop rest
1822 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
1825 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1826 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
1827 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
1828 let rec loop = function
1830 let y, h = getpageyh
pageno in
1831 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
1832 gotoxy state
.x (clamp dy)
1833 | l :: _ when l.pageno = pageno ->
1834 if l.pagevh != l.pageh
1835 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
1836 else postRedisplay
"downbirdseye"
1837 | _ :: rest
-> loop rest
1843 let optentry mode
_ key =
1844 let btos b = if b then "on" else "off" in
1845 match [@warning
"-4"] key with
1849 let n, a, b = multicolumns_of_string
s in
1850 setcolumns mode
n a b;
1852 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
1854 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
1859 let zoom = float (int_of_string
s) /. 100.0 in
1862 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1864 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
1867 conf
.icase
<- not conf
.icase
;
1868 TEdone
("case insensitive search " ^
(btos conf
.icase
))
1871 conf
.verbose
<- not conf
.verbose
;
1872 TEdone
("verbose " ^
(btos conf
.verbose
))
1875 conf
.debug
<- not conf
.debug
;
1876 TEdone
("debug " ^
(btos conf
.debug
))
1879 conf
.underinfo
<- not conf
.underinfo
;
1880 TEdone
("underinfo " ^
btos conf
.underinfo
)
1884 match conf
.fitmodel
with
1885 | FitProportional
-> FitWidth
1886 | FitWidth
| FitPage
-> FitProportional
1888 reqlayout conf
.angle
fm;
1889 TEdone
("proportional display " ^
btos (fm == FitProportional
))
1892 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
1893 TEdone
("trim margins " ^
btos conf
.trimmargins
)
1896 conf
.invert
<- not conf
.invert
;
1897 TEdone
("invert colors " ^
btos conf
.invert
)
1901 cbput state
.hists
.sel
s;
1904 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
1905 textentry, ondone, true)
1909 then conf
.pax
<- Some
0.0
1910 else conf
.pax
<- None
;
1911 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
1914 state
.text <- Printf.sprintf
"bad option %d `%c'" (Char.code
c) c;
1921 let adderrmsg src msg
=
1922 Buffer.add_string state
.errmsgs msg
;
1923 state
.newerrmsgs
<- true;
1927 let adderrfmt src fmt
=
1928 Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;
1931 class outlinelistview ~zebra ~source
=
1932 let settext autonarrow
s =
1935 let ss = source#statestr
in
1939 else "{" ^
ss ^
"} [" ^
s ^
"]"
1940 else state
.text <- s
1946 ~source
:(source
:> lvsource
)
1948 ~modehash
:(findkeyhash conf
"outline")
1951 val m_autonarrow
= false
1953 method! key key mask
=
1955 if emptystr state
.text
1957 else fstate
.maxrows - 2
1959 let calcfirst first active
=
1962 let rows = active
- first
in
1963 if rows > maxrows then active
- maxrows else first
1967 let active = m_active
+ incr
in
1968 let active = bound
active 0 (source#getitemcount
- 1) in
1969 let first = calcfirst m_first
active in
1970 postRedisplay
"outline navigate";
1971 coe
{< m_active
= active; m_first
= first >}
1973 let navscroll first =
1975 let dist = m_active
- first in
1981 else first + maxrows
1984 postRedisplay
"outline navscroll";
1985 coe
{< m_first
= first; m_active
= active >}
1987 let ctrl = Wsi.withctrl mask
in
1989 match Wsi.kc2kt
key with
1990 | Ascii '
a'
when ctrl ->
1993 then (source#denarrow
; E.s)
1995 let pattern = source#renarrow
in
1996 if nonemptystr m_qsearch
1997 then (source#narrow m_qsearch
; m_qsearch
)
2001 settext (not m_autonarrow
) text;
2002 postRedisplay
"toggle auto narrowing";
2003 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
2005 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
2007 postRedisplay
"toggle auto narrowing";
2008 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
2010 | Ascii '
n'
when ctrl ->
2011 source#narrow m_qsearch
;
2013 then source#add_narrow_pattern m_qsearch
;
2014 postRedisplay
"outline ctrl-n";
2015 coe
{< m_first
= 0; m_active
= 0 >}
2017 | Ascii 'S'
when ctrl ->
2018 let active = source#calcactive
(getanchor
()) in
2019 let first = firstof m_first
active in
2020 postRedisplay
"outline ctrl-s";
2021 coe
{< m_first
= first; m_active
= active >}
2023 | Ascii 'u'
when ctrl ->
2024 postRedisplay
"outline ctrl-u";
2025 if m_autonarrow
&& nonemptystr m_qsearch
2027 ignore
(source#renarrow
);
2028 settext m_autonarrow
E.s;
2029 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
2032 source#del_narrow_pattern
;
2033 let pattern = source#renarrow
in
2035 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
2037 settext m_autonarrow
text;
2038 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
2041 | Ascii '
l'
when ctrl ->
2042 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
2043 postRedisplay
"outline ctrl-l";
2044 coe
{< m_first
= first >}
2046 | Ascii '
\t'
when m_autonarrow
->
2047 if nonemptystr m_qsearch
2049 postRedisplay
"outline list view tab";
2050 source#add_narrow_pattern m_qsearch
;
2052 coe
{< m_qsearch
= E.s >}
2056 | Escape
when m_autonarrow
->
2057 if nonemptystr m_qsearch
2058 then source#add_narrow_pattern m_qsearch
;
2061 | Enter
when m_autonarrow
->
2062 if nonemptystr m_qsearch
2063 then source#add_narrow_pattern m_qsearch
;
2066 | (Ascii
_ | Code
_) when m_autonarrow
->
2067 let pattern = m_qsearch ^ toutf8
key in
2068 postRedisplay
"outlinelistview autonarrow add";
2069 source#narrow
pattern;
2070 settext true pattern;
2071 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2073 | Backspace
when m_autonarrow
->
2074 if emptystr m_qsearch
2077 let pattern = withoutlastutf8 m_qsearch
in
2078 postRedisplay
"outlinelistview autonarrow backspace";
2079 ignore
(source#renarrow
);
2080 source#narrow
pattern;
2081 settext true pattern;
2082 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2085 navscroll (max
0 (m_first
- 1))
2088 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
2090 | Up
-> navigate ~
-1
2091 | Down
-> navigate 1
2092 | Prior
-> navigate ~
-(fstate
.maxrows)
2093 | Next
-> navigate fstate
.maxrows
2099 postRedisplay
"outline ctrl right";
2100 {< m_pan
= m_pan
+ 1 >}
2102 else self#updownlevel
1
2110 postRedisplay
"outline ctrl left";
2111 {< m_pan
= m_pan
- 1 >}
2113 else self#updownlevel ~
-1
2118 postRedisplay
"outline home";
2119 coe
{< m_first
= 0; m_active
= 0 >}
2122 let active = source#getitemcount
- 1 in
2123 let first = max
0 (active - fstate
.maxrows) in
2124 postRedisplay
"outline end";
2125 coe
{< m_active
= active; m_first
= first >}
2127 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
2131 let genhistoutlines () =
2133 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
2134 compare c2
.lastvisit c1
.lastvisit
)
2135 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
2136 let path = if nonemptystr origin
then origin
else path in
2137 let base = mbtoutf8
@@ Filename.basename
path in
2138 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
2142 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
2143 Config.save
leavebirdseye;
2144 state
.anchor <- anchor;
2145 state
.bookmarks
<- bookmarks
;
2146 state
.origin
<- origin
;
2149 let x0, y0, x1, y1 = conf
.trimfuzz
in
2150 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
2151 reshape ~firsttime
:true state
.winw state
.winh
;
2152 opendoc path origin
;
2156 let setcheckers enabled
=
2157 match state
.checkerstexid
with
2159 if enabled
then state
.checkerstexid
<- Some
(makecheckers
())
2161 | Some checkerstexid
->
2164 GlTex.delete_texture checkerstexid
;
2165 state
.checkerstexid
<- None
;
2169 let describe_layout layout =
2173 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
2176 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
2178 let sep = if a.pageno+1 = b.pageno then ", " else Unisyms.ellipsis
in
2179 Printf.sprintf
"%d%s%d" (a.pageno+1) sep (b.pageno+1)
2181 let rec fold s la lb
= function
2182 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
2183 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
2184 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
2186 fold "Pages" l l rest
2189 let maxy = maxy () in
2192 else 100. *. (float state
.y /. float maxy)
2194 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
2197 let setpresentationmode v
=
2198 let n = page_of_y state
.y in
2199 state
.anchor <- (n, 0.0, 1.0);
2200 conf
.presentation
<- v
;
2201 if conf
.fitmodel
= FitPage
2202 then reqlayout conf
.angle conf
.fitmodel
;
2207 let btos b = if b then Unisyms.radical
else E.s in
2208 let showextended = ref false in
2209 let showcolors = ref false in
2210 let leave mode
_ = state
.mode
<- mode
in
2213 val mutable m_l
= []
2214 val mutable m_a
= E.a
2215 val mutable m_prev_uioh
= nouioh
2216 val mutable m_prev_mode
= View
2218 inherit lvsourcebase
2220 method reset prev_mode prev_uioh
=
2221 m_a
<- Array.of_list
(List.rev m_l
);
2223 m_prev_mode
<- prev_mode
;
2224 m_prev_uioh
<- prev_uioh
;
2226 method int name get
set =
2232 try set (int_of_string
s)
2234 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2238 let te = name ^
": ", E.s, None
, intentry, ondone, true in
2239 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2243 method int_with_suffix name get
set =
2245 (name
, `intws get
, 1,
2249 try set (int_of_string_with_suffix
s)
2251 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2256 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
2258 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2262 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2264 (name
, `
bool (btos, get
), offset
, Action
(
2271 method color name get
set =
2273 (name
, `
color get
, 1,
2276 let invalid = (nan
, nan
, nan
) in
2279 try color_of_string
s
2281 state
.text <- Printf.sprintf
"bad color `%s': %s"
2288 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2289 state
.text <- color_to_string
(get
());
2290 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2294 method string name get
set =
2296 (name
, `
string get
, 1,
2299 let ondone s = set s in
2300 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2301 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2305 method colorspace name get
set =
2307 (name
, `
string get
, 1,
2312 inherit lvsourcebase
2315 m_active
<- CSTE.to_int conf
.colorspace
;
2318 method getitemcount
=
2319 Array.length
CSTE.names
2322 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2323 ignore
(uioh
, first, pan
);
2324 if not cancel
then set active;
2326 method hasaction
_ = true
2330 let modehash = findkeyhash conf
"info" in
2331 coe
(new listview ~zebra
:false ~helpmode
:false
2332 ~
source ~trusted
:true ~
modehash)
2335 method paxmark name get
set =
2337 (name
, `
string get
, 1,
2342 inherit lvsourcebase
2345 m_active
<- MTE.to_int conf
.paxmark
;
2348 method getitemcount
= Array.length
MTE.names
2349 method getitem
n = (MTE.names
.(n), 0)
2350 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2351 ignore
(uioh
, first, pan
);
2352 if not cancel
then set active;
2354 method hasaction
_ = true
2358 let modehash = findkeyhash conf
"info" in
2359 coe
(new listview ~zebra
:false ~helpmode
:false
2360 ~
source ~trusted
:true ~
modehash)
2363 method fitmodel name get
set =
2365 (name
, `
string get
, 1,
2370 inherit lvsourcebase
2373 m_active
<- FMTE.to_int conf
.fitmodel
;
2376 method getitemcount
= Array.length
FMTE.names
2377 method getitem
n = (FMTE.names
.(n), 0)
2378 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2379 ignore
(uioh
, first, pan
);
2380 if not cancel
then set active;
2382 method hasaction
_ = true
2386 let modehash = findkeyhash conf
"info" in
2387 coe
(new listview ~zebra
:false ~helpmode
:false
2388 ~
source ~trusted
:true ~
modehash)
2391 method caption
s offset
=
2392 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
2394 method caption2
s f offset
=
2395 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
2397 method getitemcount
= Array.length m_a
2400 let tostr = function
2401 | `
int f -> string_of_int
(f ())
2402 | `intws
f -> string_with_suffix_of_int
(f ())
2404 | `
color f -> color_to_string
(f ())
2405 | `
bool (btos, f) -> btos (f ())
2408 let name, t
, offset
, _ = m_a
.(n) in
2409 ((let s = tostr t
in
2411 then Printf.sprintf
"%s\t%s" name s
2415 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2420 match m_a
.(active) with
2421 | _, _, _, Action
f -> f uioh
2422 | _, _, _, Noaction
-> uioh
2433 method hasaction
n =
2435 | _, _, _, Action
_ -> true
2436 | _, _, _, Noaction
-> false
2438 initializer m_active
<- 1
2441 let rec fillsrc prevmode prevuioh
=
2442 let sep () = src#caption
E.s 0 in
2443 let colorp name get
set =
2445 (fun () -> color_to_string
(get
()))
2448 let c = color_of_string
v in
2452 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2455 let rgba name get
set =
2457 (fun () -> rgba_to_string
(get
()))
2460 let c = rgba_of_string
v in
2464 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2467 let oldmode = state
.mode
in
2468 let birdseye = isbirdseye state
.mode
in
2470 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
2472 src#
bool "presentation mode"
2473 (fun () -> conf
.presentation
)
2474 (fun v -> setpresentationmode v);
2476 src#
bool "ignore case in searches"
2477 (fun () -> conf
.icase
)
2478 (fun v -> conf
.icase
<- v);
2481 (fun () -> conf
.preload)
2482 (fun v -> conf
.preload <- v);
2484 src#
bool "highlight links"
2485 (fun () -> conf
.hlinks
)
2486 (fun v -> conf
.hlinks
<- v);
2488 src#
bool "under info"
2489 (fun () -> conf
.underinfo
)
2490 (fun v -> conf
.underinfo
<- v);
2492 src#fitmodel
"fit model"
2493 (fun () -> FMTE.to_string conf
.fitmodel
)
2494 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
2496 src#
bool "trim margins"
2497 (fun () -> conf
.trimmargins
)
2498 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
2501 src#
int "inter-page space"
2502 (fun () -> conf
.interpagespace
)
2504 conf
.interpagespace
<- n;
2505 docolumns conf
.columns
;
2507 match state
.layout with
2512 state
.maxy <- calcheight
();
2513 let y = getpagey
pageno in
2514 gotoxy state
.x (y + py)
2518 (fun () -> conf
.pagebias
)
2519 (fun v -> conf
.pagebias
<- v);
2521 src#
int "scroll step"
2522 (fun () -> conf
.scrollstep
)
2523 (fun n -> conf
.scrollstep
<- n);
2525 src#
int "horizontal scroll step"
2526 (fun () -> conf
.hscrollstep
)
2527 (fun v -> conf
.hscrollstep
<- v);
2529 src#
int "auto scroll step"
2531 match state
.autoscroll
with
2533 | _ -> conf
.autoscrollstep
)
2535 let n = boundastep state
.winh
n in
2536 if state
.autoscroll
<> None
2537 then state
.autoscroll
<- Some
n;
2538 conf
.autoscrollstep
<- n);
2541 (fun () -> truncate
(conf
.zoom *. 100.))
2542 (fun v -> pivotzoom ((float v) /. 100.));
2545 (fun () -> conf
.angle
)
2546 (fun v -> reqlayout v conf
.fitmodel
);
2548 src#
int "scroll bar width"
2549 (fun () -> conf
.scrollbw
)
2552 reshape state
.winw state
.winh
;
2555 src#
int "scroll handle height"
2556 (fun () -> conf
.scrollh
)
2557 (fun v -> conf
.scrollh
<- v;);
2559 src#
int "thumbnail width"
2560 (fun () -> conf
.thumbw
)
2562 conf
.thumbw
<- min
4096 v;
2565 leavebirdseye beye
false;
2572 let mode = state
.mode in
2573 src#
string "columns"
2575 match conf
.columns
with
2577 | Cmulti
(multi
, _) -> multicolumns_to_string multi
2578 | Csplit
(count
, _) -> "-" ^ string_of_int count
2581 let n, a, b = multicolumns_of_string
v in
2582 setcolumns mode n a b);
2585 src#caption
"Pixmap cache" 0;
2586 src#int_with_suffix
"size (advisory)"
2587 (fun () -> conf
.memlimit
)
2588 (fun v -> conf
.memlimit
<- v);
2592 Printf.sprintf
"%s bytes, %d tiles"
2593 (string_with_suffix_of_int state
.memused
)
2594 (Hashtbl.length state
.tilemap
)) 1;
2597 src#caption
"Layout" 0;
2598 src#caption2
"Dimension"
2600 Printf.sprintf
"%dx%d (virtual %dx%d)"
2601 state
.winw state
.winh
2606 src#caption2
"Position" (fun () ->
2607 Printf.sprintf
"%dx%d" state
.x state
.y
2610 src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
2613 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
2614 "Save these parameters as global defaults at exit"
2615 (fun () -> conf
.bedefault
)
2616 (fun v -> conf
.bedefault
<- v);
2619 let btos b = if b then Unisyms.lguillemet
else Unisyms.rguillemet
in
2620 src#
bool ~offset
:0 ~
btos "Extended parameters"
2621 (fun () -> !showextended)
2622 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
2626 (fun () -> conf
.checkers
)
2627 (fun v -> conf
.checkers
<- v; setcheckers v);
2628 src#
bool "update cursor"
2629 (fun () -> conf
.updatecurs
)
2630 (fun v -> conf
.updatecurs
<- v);
2631 src#
bool "scroll-bar on the left"
2632 (fun () -> conf
.leftscroll
)
2633 (fun v -> conf
.leftscroll
<- v);
2635 (fun () -> conf
.verbose
)
2636 (fun v -> conf
.verbose
<- v);
2637 src#
bool "invert colors"
2638 (fun () -> conf
.invert
)
2639 (fun v -> conf
.invert
<- v);
2641 (fun () -> conf
.maxhfit
)
2642 (fun v -> conf
.maxhfit
<- v);
2644 (fun () -> conf
.pax
!= None
)
2647 then conf
.pax
<- Some
(now
())
2648 else conf
.pax
<- None
);
2649 src#
string "uri launcher"
2650 (fun () -> conf
.urilauncher
)
2651 (fun v -> conf
.urilauncher
<- v);
2652 src#
string "path launcher"
2653 (fun () -> conf
.pathlauncher
)
2654 (fun v -> conf
.pathlauncher
<- v);
2655 src#
string "tile size"
2656 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
2659 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
2660 conf
.tilew
<- max
64 w;
2661 conf
.tileh
<- max
64 h;
2664 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
2667 src#
int "texture count"
2668 (fun () -> conf
.texcount
)
2671 then conf
.texcount
<- v
2672 else impmsg "failed to set texture count please retry later"
2674 src#
int "slice height"
2675 (fun () -> conf
.sliceheight
)
2677 conf
.sliceheight
<- v;
2678 wcmd "sliceh %d" conf
.sliceheight
;
2680 src#
int "anti-aliasing level"
2681 (fun () -> conf
.aalevel
)
2683 conf
.aalevel
<- bound
v 0 8;
2684 state
.anchor <- getanchor
();
2685 opendoc state
.path state
.password;
2687 src#
string "page scroll scaling factor"
2688 (fun () -> string_of_float conf
.pgscale)
2691 let s = float_of_string
v in
2694 state
.text <- Printf.sprintf
2695 "bad page scroll scaling factor `%s': %s" v
2699 src#
int "ui font size"
2700 (fun () -> fstate
.fontsize
)
2701 (fun v -> setfontsize (bound
v 5 100));
2702 src#
int "hint font size"
2703 (fun () -> conf
.hfsize
)
2704 (fun v -> conf
.hfsize
<- bound
v 5 100);
2705 src#
string "trim fuzz"
2706 (fun () -> irect_to_string conf
.trimfuzz
)
2709 conf
.trimfuzz
<- irect_of_string
v;
2711 then settrim true conf
.trimfuzz
;
2713 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
2716 src#
string "selection command"
2717 (fun () -> conf
.selcmd
)
2718 (fun v -> conf
.selcmd
<- v);
2719 src#
string "synctex command"
2720 (fun () -> conf
.stcmd
)
2721 (fun v -> conf
.stcmd
<- v);
2722 src#
string "pax command"
2723 (fun () -> conf
.paxcmd
)
2724 (fun v -> conf
.paxcmd
<- v);
2725 src#
string "ask password command"
2726 (fun () -> conf
.passcmd)
2727 (fun v -> conf
.passcmd <- v);
2728 src#
string "save path command"
2729 (fun () -> conf
.savecmd
)
2730 (fun v -> conf
.savecmd
<- v);
2731 src#colorspace
"color space"
2732 (fun () -> CSTE.to_string conf
.colorspace
)
2734 conf
.colorspace
<- CSTE.of_int
v;
2738 src#paxmark
"pax mark method"
2739 (fun () -> MTE.to_string conf
.paxmark
)
2740 (fun v -> conf
.paxmark
<- MTE.of_int
v);
2741 if bousable
() && !opengl_has_pbo
2744 (fun () -> conf
.usepbo
)
2745 (fun v -> conf
.usepbo
<- v);
2746 src#
bool "mouse wheel scrolls pages"
2747 (fun () -> conf
.wheelbypage
)
2748 (fun v -> conf
.wheelbypage
<- v);
2749 src#
bool "open remote links in a new instance"
2750 (fun () -> conf
.riani
)
2751 (fun v -> conf
.riani
<- v);
2752 src#
bool "edit annotations inline"
2753 (fun () -> conf
.annotinline
)
2754 (fun v -> conf
.annotinline
<- v);
2755 src#
bool "coarse positioning in presentation mode"
2756 (fun () -> conf
.coarseprespos
)
2757 (fun v -> conf
.coarseprespos
<- v);
2758 src#
bool "use document CSS"
2759 (fun () -> conf
.usedoccss
)
2761 conf
.usedoccss
<- v;
2762 state
.anchor <- getanchor
();
2763 opendoc state
.path state
.password;
2765 src#
bool ~
btos "colors"
2766 (fun () -> !showcolors)
2767 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
2770 colorp " background"
2771 (fun () -> conf
.bgcolor
)
2772 (fun v -> conf
.bgcolor
<- v);
2774 (fun () -> conf
.sbarcolor
)
2775 (fun v -> conf
.sbarcolor
<- v);
2776 rgba " scrollbar handle"
2777 (fun () -> conf
.sbarhndlcolor
)
2778 (fun v -> conf
.sbarhndlcolor
<- v);
2783 src#caption
"Document" 0;
2784 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
2785 src#caption2
"Pages"
2786 (fun () -> string_of_int state
.pagecount
) 1;
2787 src#caption2
"Dimensions"
2788 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2789 if nonemptystr conf
.css
2790 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
2794 src#caption
"Trimmed margins" 0;
2795 src#caption2
"Dimensions"
2796 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2800 src#caption
"OpenGL" 0;
2801 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
2802 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
2805 src#caption
"Location" 0;
2806 if nonemptystr state
.origin
2807 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
2808 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
2810 src#reset prevmode prevuioh
;
2815 let prevmode = state
.mode
2816 and prevuioh
= state
.uioh in
2817 fillsrc prevmode prevuioh
;
2818 let source = (src :> lvsource
) in
2819 let modehash = findkeyhash conf
"info" in
2822 inherit listview ~zebra
:false ~helpmode
:false
2823 ~
source ~trusted
:true ~
modehash as super
2824 val mutable m_prevmemused
= 0
2825 method! infochanged
= function
2827 if m_prevmemused
!= state
.memused
2829 m_prevmemused
<- state
.memused
;
2830 postRedisplay
"memusedchanged";
2832 | Pdim
-> postRedisplay
"pdimchanged"
2833 | Docinfo
-> fillsrc prevmode prevuioh
2835 method! key key mask
=
2836 if not
(Wsi.withctrl mask
)
2838 match [@warning
"-4"] Wsi.kc2kt
key with
2839 | Keys.Left
-> coe
(self#updownlevel ~
-1)
2840 | Keys.Right
-> coe
(self#updownlevel
1)
2841 | _ -> super#
key key mask
2842 else super#
key key mask
2844 postRedisplay
"info";
2850 inherit lvsourcebase
2851 method getitemcount
= Array.length state
.help
2853 let s, l, _ = state
.help
.(n) in
2856 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2860 match state
.help
.(active) with
2861 | _, _, Action
f -> Some
(f uioh)
2862 | _, _, Noaction
-> Some
uioh
2871 method hasaction
n =
2872 match state
.help
.(n) with
2873 | _, _, Action
_ -> true
2874 | _, _, Noaction
-> false
2880 let modehash = findkeyhash conf
"help" in
2882 state
.uioh <- coe
(new listview
2883 ~zebra
:false ~helpmode
:true
2884 ~
source ~trusted
:true ~
modehash);
2885 postRedisplay
"help";
2891 inherit lvsourcebase
2892 val mutable m_items
= E.a
2894 method getitemcount
= 1 + Array.length m_items
2899 else m_items
.(n-1), 0
2901 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2906 then Buffer.clear state
.errmsgs
;
2913 method hasaction
n =
2917 state
.newerrmsgs
<- false;
2918 let l = Str.split
Utils.Re.crlf
(Buffer.contents state
.errmsgs
) in
2919 m_items
<- Array.of_list
l
2928 let source = (msgsource :> lvsource
) in
2929 let modehash = findkeyhash conf
"listview" in
2932 inherit listview ~zebra
:false ~helpmode
:false
2933 ~
source ~trusted
:false ~
modehash as super
2936 then msgsource#reset
;
2939 postRedisplay
"msgs";
2943 let editor = getenvwithdef
"EDITOR" E.s in
2947 let tmppath = Filename.temp_file
"llpp" "note" in
2950 let oc = open_out
tmppath in
2954 let execstr = editor ^
" " ^
tmppath in
2956 match spawn
execstr [] with
2958 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
2961 match Unix.waitpid
[] pid
with
2963 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
2967 | Unix.WEXITED
0 -> filecontents
tmppath
2969 impmsg "editor process(%s) exited abnormally: %d" execstr n;
2971 | Unix.WSIGNALED
n ->
2972 impmsg "editor process(%s) was killed by signal %d" execstr n;
2974 | Unix.WSTOPPED
n ->
2975 impmsg "editor(%s) process was stopped by signal %d" execstr n;
2978 match Unix.unlink
tmppath with
2980 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
2985 let enterannotmode opaque slinkindex
=
2988 inherit lvsourcebase
2989 val mutable m_text
= E.s
2990 val mutable m_items
= E.a
2992 method getitemcount
= Array.length m_items
2995 let label, _func
= m_items
.(n) in
2998 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2999 ignore
(uioh, first, pan
);
3002 let _label, func
= m_items
.(active) in
3007 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
3010 let rec split accu b i
=
3012 if p = String.length
s
3013 then (String.sub s b (p-b), unit) :: accu
3015 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
3017 let ss = if i
= 0 then E.s else String.sub s b i
in
3018 split ((ss, unit)::accu) (p+1) 0
3023 wcmd "freepage %s" (~
> opaque);
3025 Hashtbl.fold (fun key opaque'
accu ->
3026 if opaque'
= opaque'
3027 then key :: accu else accu) state
.pagemap
[]
3029 List.iter
(Hashtbl.remove state
.pagemap
) keys;
3031 gotoxy state
.x state
.y
3034 delannot
opaque slinkindex
;
3037 let edit inline
() =
3042 modannot
opaque slinkindex
s;
3048 let mode = state
.mode in
3051 ("annotation: ", m_text
, None
, textentry, update, true),
3052 fun _ -> state
.mode <- mode);
3056 let s = getusertext m_text
in
3061 ( "[Copy]", fun () -> selstring conf
.selcmd m_text
)
3062 :: ("[Delete]", dele)
3063 :: ("[Edit]", edit conf
.annotinline
)
3065 :: split [] 0 0 |> List.rev
|> Array.of_list
3072 let s = getannotcontents
opaque slinkindex
in
3075 let source = (msgsource :> lvsource
) in
3076 let modehash = findkeyhash conf
"listview" in
3077 state
.uioh <- coe
(object
3078 inherit listview ~zebra
:false ~helpmode
:false
3079 ~
source ~trusted
:false ~
modehash
3081 postRedisplay
"enterannotmode";
3084 let gotoremote spec
=
3085 let filename, dest
= splitatchar spec '#'
in
3086 let getpath filename =
3088 if nonemptystr
filename
3090 if Filename.is_relative
filename
3092 let dir = Filename.dirname state
.path in
3094 if Filename.is_implicit
dir
3095 then Filename.concat
(Sys.getcwd
()) dir
3098 Filename.concat
dir filename
3102 if Sys.file_exists
path
3106 let path = getpath filename in
3110 let cmd = Lazy.force_val lcmd
in
3111 match spawn
cmd with
3113 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
3115 let anchor = getanchor
() in
3116 let ranchor = state
.path, state
.password, anchor, state
.origin
in
3117 state
.origin
<- E.s;
3118 state
.ranchors
<- ranchor :: state
.ranchors
;
3121 if substratis spec
0 "page="
3123 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
3125 state
.anchor <- (pageno, 0.0, 0.0);
3126 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
3128 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
3130 state
.nameddest
<- dest
;
3131 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
3135 let gotounder = function
3136 | Ulinkuri
s when isexternallink
s ->
3137 if substratis
s 0 "file://"
3138 then gotoremote @@ String.sub s 7 (String.length
s - 7)
3139 else Help.gotouri conf
.urilauncher
s
3141 let pageno, x, y = uritolocation
s in
3143 gotopagexy pageno x y
3144 | Utext
_ | Unone
-> ()
3145 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
3148 let gotooutline (_, _, kind
) =
3152 let (pageno, y, _) = anchor in
3154 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3158 | Ouri
uri -> gotounder (Ulinkuri
uri)
3159 | Olaunch _cmd
-> failwith
"gotounder (Ulaunch cmd)"
3160 | Oremote _remote
-> failwith
"gotounder (Uremote remote)"
3161 | Ohistory hist
-> gotohist hist
3162 | Oremotedest _remotedest
-> failwith
"gotounder (Uremotedest remotedest)"
3165 class outlinesoucebase fetchoutlines
= object (self
)
3166 inherit lvsourcebase
3167 val mutable m_items
= E.a
3168 val mutable m_minfo
= E.a
3169 val mutable m_orig_items
= E.a
3170 val mutable m_orig_minfo
= E.a
3171 val mutable m_narrow_patterns
= []
3172 val mutable m_gen
= -1
3174 method getitemcount
= Array.length m_items
3177 let s, n, _ = m_items
.(n) in
3180 method exit ~
(uioh:uioh) ~cancel ~
active ~
(first:int) ~pan
: uioh option =
3181 ignore
(uioh, first);
3183 if m_narrow_patterns
= []
3184 then m_orig_items
, m_orig_minfo
3185 else m_items
, m_minfo
3192 gotooutline m_items
.(active);
3200 method hasaction
(_:int) = true
3203 if Array.length m_items
!= Array.length m_orig_items
3206 match m_narrow_patterns
with
3208 | many
-> String.concat
Unisyms.ellipsis
(List.rev many
)
3210 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3214 match m_narrow_patterns
with
3217 | head
:: _ -> Unisyms.ellipsis ^ head
3219 method narrow
pattern =
3220 match Str.regexp_case_fold
pattern with
3223 let rec loop accu minfo
n =
3226 m_items
<- Array.of_list
accu;
3227 m_minfo
<- Array.of_list minfo
;
3230 let (s, _, _) as o = m_items
.(n) in
3232 match Str.search_forward re
s 0 with
3233 | exception Not_found
-> accu, minfo
3234 | first -> o :: accu, (first, Str.match_end
()) :: minfo
3236 loop accu minfo
(n-1)
3238 loop [] [] (Array.length m_items
- 1)
3240 method! getminfo
= m_minfo
3243 m_orig_items
<- fetchoutlines
();
3244 m_minfo
<- m_orig_minfo
;
3245 m_items
<- m_orig_items
3247 method add_narrow_pattern
pattern =
3248 m_narrow_patterns
<- pattern :: m_narrow_patterns
3250 method del_narrow_pattern
=
3251 match m_narrow_patterns
with
3252 | _ :: rest
-> m_narrow_patterns
<- rest
3257 match m_narrow_patterns
with
3258 | pattern :: [] -> self#narrow
pattern; pattern
3260 List.fold_left
(fun accu pattern ->
3261 self#narrow
pattern;
3262 pattern ^
Unisyms.ellipsis ^
accu) E.s list
3264 method calcactive
(_:anchor) = 0
3266 method reset
anchor items =
3267 if state
.gen
!= m_gen
3269 m_orig_items
<- items;
3271 m_narrow_patterns
<- [];
3273 m_orig_minfo
<- E.a;
3277 if items != m_orig_items
3279 m_orig_items
<- items;
3280 if m_narrow_patterns
== []
3281 then m_items
<- items;
3284 let active = self#calcactive
anchor in
3286 m_first
<- firstof m_first
active
3290 let outlinesource fetchoutlines
=
3292 inherit outlinesoucebase fetchoutlines
3293 method! calcactive
anchor =
3294 let rely = getanchory anchor in
3295 let rec loop n best bestd
=
3296 if n = Array.length m_items
3299 let _, _, kind
= m_items
.(n) in
3302 let orely = getanchory anchor in
3303 let d = abs
(orely - rely) in
3306 else loop (n+1) best bestd
3307 | Onone
| Oremote
_ | Olaunch
_
3308 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
3309 loop (n+1) best bestd
3315 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
3316 let mkselector sourcetype
=
3317 let fetchoutlines () =
3318 match sourcetype
with
3319 | `bookmarks
-> Array.of_list state
.bookmarks
3320 | `outlines
-> state
.outlines
3321 | `history
-> genhistoutlines () |> Array.of_list
3324 if sourcetype
= `history
3325 then new outlinesoucebase
fetchoutlines
3326 else outlinesource fetchoutlines
3329 let outlines = fetchoutlines () in
3330 if Array.length
outlines = 0
3331 then showtext ' ' errmsg
3334 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3335 let anchor = getanchor
() in
3336 source#reset
anchor outlines;
3337 state
.text <- source#greetmsg
;
3339 coe
(new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
3340 postRedisplay
"enter selector";
3344 let mkenter sourcetype errmsg
=
3345 let enter = mkselector sourcetype
in
3346 fun () -> enter errmsg
3348 ( mkenter `
outlines "document has no outline"
3349 , mkenter `bookmarks
"document has no bookmarks (yet)"
3350 , mkenter `history
"history is empty" )
3353 let quickbookmark ?title
() =
3354 match state
.layout with
3361 let tm = localtime
(now
()) in
3363 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
3365 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
3367 | Some
title -> title
3369 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3372 let setautoscrollspeed step goingdown
=
3373 let incr = max
1 ((abs step
) / 2) in
3374 let incr = if goingdown
then incr else -incr in
3375 let astep = boundastep state
.winh
(step
+ incr) in
3376 state
.autoscroll
<- Some
astep;
3380 match conf
.columns
with
3382 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
3385 let panbound x = bound
x (-state
.w) state
.winw
;;
3387 let existsinrow pageno (columns
, coverA
, coverB
) p =
3388 let last = ((pageno - coverA
) mod columns
) + columns
in
3389 let rec any = function
3392 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
3396 then (if l.pageno = last then false else any rest
)
3404 match state
.layout with
3406 let pageno = page_of_y state
.y in
3407 gotoxy state
.x (getpagey
(pageno+1))
3409 match conf
.columns
with
3411 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
3413 let y = clamp (pgscale state
.winh
) in
3416 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
3417 gotoxy state
.x (getpagey
pageno)
3418 | Cmulti
((c, _, _) as cl
, _) ->
3419 if conf
.presentation
3420 && (existsinrow l.pageno cl
3421 (fun l -> l.pageh
> l.pagey + l.pagevh))
3423 let y = clamp (pgscale state
.winh
) in
3426 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
3427 gotoxy state
.x (getpagey
pageno)
3429 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
3431 let pagey, pageh
= getpageyh
l.pageno in
3432 let pagey = pagey + pageh
* l.pagecol
in
3433 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
3434 gotoxy state
.x (pagey + pageh
+ ips)
3438 match state
.layout with
3440 let pageno = page_of_y state
.y in
3441 gotoxy state
.x (getpagey
(pageno-1))
3443 match conf
.columns
with
3445 if conf
.presentation
&& l.pagey != 0
3447 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3449 let pageno = max
0 (l.pageno-1) in
3450 gotoxy state
.x (getpagey
pageno)
3451 | Cmulti
((c, _, coverB
) as cl
, _) ->
3452 if conf
.presentation
&&
3453 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
3455 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3458 if l.pageno = state
.pagecount
- coverB
3462 let pageno = max
0 (l.pageno-decr) in
3463 gotoxy state
.x (getpagey
pageno)
3471 let pageno = max
0 (l.pageno-1) in
3472 let pagey, pageh
= getpageyh
pageno in
3475 let pagey, pageh
= getpageyh
l.pageno in
3476 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
3482 if emptystr conf
.savecmd
3483 then adderrmsg "savepath-command is empty"
3484 "don't know where to save modified document"
3486 let savecmd = Str.global_replace
Utils.Re.percent state
.path conf
.savecmd in
3490 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
3495 let tmp = path ^
".tmp" in
3497 Unix.rename
tmp path;
3500 let viewkeyboard key mask
=
3502 let mode = state
.mode in
3503 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
3506 postRedisplay
"view:enttext"
3508 let ctrl = Wsi.withctrl mask
in
3510 match Wsi.kc2kt
key with
3511 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
3513 | Ascii 'Q'
-> exit
0
3516 if hasunsavedchanges
()
3520 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
3523 match state
.lnava
with
3524 | None
-> LinkNav
(Ltgendir
0)
3525 | Some
pn -> LinkNav
(Ltexact
pn)
3527 gotoxy state
.x state
.y;
3529 else impmsg "keyboard link navigation does not work under rotation"
3531 | Escape
| Ascii 'q'
->
3532 begin match state
.mstate
with
3535 postRedisplay
"kill rect";
3538 | Mscrolly
| Mscrollx
3541 begin match state
.mode with
3544 | Ltexact pl
-> state
.lnava
<- Some pl
3545 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
3548 postRedisplay
"esc leave linknav"
3549 | Birdseye
_ | Textentry
_ | View
->
3550 match state
.ranchors
with
3552 | (path, password, anchor, origin
) :: rest
->
3553 state
.ranchors
<- rest
;
3554 state
.anchor <- anchor;
3555 state
.origin
<- origin
;
3556 state
.nameddest
<- E.s;
3557 opendoc path password
3563 gotoxy state
.x (getnav ~
-1)
3574 Hashtbl.iter
(fun _ opaque ->
3576 Hashtbl.clear state
.prects
) state
.pagemap
;
3577 postRedisplay
"dehighlight";
3579 | Ascii
(('
/'
| '?'
) as c) ->
3580 let ondone isforw
s =
3581 cbput state
.hists
.pat
s;
3582 state
.searchpattern
<- s;
3585 let s = String.make
1 c in
3586 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
3587 textentry, ondone (c = '
/'
), true)
3589 | Ascii '
+'
| Ascii '
='
when ctrl ->
3590 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3591 pivotzoom (conf
.zoom +. incr)
3596 try int_of_string
s with exn
->
3598 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3604 state
.text <- "page bias is now " ^ string_of_int
n;
3607 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
3609 | Ascii '
-'
when ctrl ->
3610 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3611 pivotzoom (max
0.01 (conf
.zoom -. decr))
3614 let ondone msg
= state
.text <- msg
in
3615 enttext ("option: ", E.s, None
,
3616 optentry state
.mode, ondone, true)
3618 | Ascii '
0'
when ctrl ->
3620 then gotoxy 0 state
.y
3623 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
3625 match conf
.columns
with
3626 | Csingle
_ | Cmulti
_ -> 1
3627 | Csplit
(n, _) -> n
3629 let h = state
.winh
-
3630 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
3632 let zoom = zoomforh state
.winw
h 0 cols in
3633 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
3636 | Ascii '
3'
when ctrl ->
3638 match conf
.fitmodel
with
3639 | FitWidth
-> FitProportional
3640 | FitProportional
-> FitPage
3641 | FitPage
-> FitWidth
3643 state
.text <- "fit model: " ^
FMTE.to_string
fm;
3644 reqlayout conf
.angle
fm
3646 | Ascii '
4'
when ctrl ->
3647 let zoom = getmaxw
() /. float state
.winw
in
3648 if zoom > 0.0 then setzoom zoom
3653 | Ascii '
9'
when ctrl ->
3656 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
3659 try int_of_string
s with exn
->
3660 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3666 cbput state
.hists
.pag
(string_of_int
n);
3667 gotopage1 (n + conf
.pagebias
- 1) 0;
3670 let pageentry text = function [@warning
"-4"]
3671 | Keys.Ascii '
g'
-> TEdone
text
3672 | key -> intentry text key
3674 let text = String.make
1 c in
3675 enttext (":", text, Some
(onhist state
.hists
.pag
),
3676 pageentry, ondone, true)
3679 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
3680 postRedisplay
"toggle scrollbar";
3683 state
.bzoom
<- not state
.bzoom
;
3685 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
3688 conf
.hlinks
<- not conf
.hlinks
;
3689 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
3690 postRedisplay
"toggle highlightlinks";
3693 if conf
.angle
mod 360 = 0
3695 state
.glinks
<- true;
3696 let mode = state
.mode in
3699 (":", E.s, None
, linknentry, linknact gotounder, false),
3701 state
.glinks
<- false;
3705 postRedisplay
"view:linkent(F)"
3707 else impmsg "hint mode does not work under rotation"
3710 state
.glinks
<- true;
3711 let mode = state
.mode in
3714 (":", E.s, None
, linknentry,
3715 linknact (fun under ->
3716 selstring conf
.selcmd
(undertext under)), false),
3718 state
.glinks
<- false;
3722 postRedisplay
"view:linkent"
3725 begin match state
.autoscroll
with
3727 conf
.autoscrollstep
<- step
;
3728 state
.autoscroll
<- None
3730 state
.autoscroll
<- Some conf
.autoscrollstep
;
3731 state
.slideshow
<- state
.slideshow
land lnot
2
3734 | Ascii '
p'
when ctrl ->
3735 launchpath () (* XXX where do error messages go? *)
3738 setpresentationmode (not conf
.presentation
);
3739 showtext ' '
("presentation mode " ^
3740 if conf
.presentation
then "on" else "off");
3743 if List.mem
Wsi.Fullscreen state
.winstate
3744 then Wsi.reshape conf
.cwinw conf
.cwinh
3745 else Wsi.fullscreen
()
3747 | Ascii
('
p'
|'N'
) ->
3748 search state
.searchpattern
false
3750 | Ascii '
n'
| Fn
3 ->
3751 search state
.searchpattern
true
3754 begin match state
.layout with
3757 gotoxy state
.x (getpagey
l.pageno)
3767 showtext ' '
(describe_layout state
.layout);
3770 begin match state
.layout with
3773 Wsi.reshape l.pagew
l.pageh
;
3778 enterbookmarkmode
()
3780 | Ascii '
h'
| Fn
1 ->
3786 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 ->
3791 match state
.layout with
3796 (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3799 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
3803 showtext ' '
"Quick bookmark added";
3805 | Ascii '
x'
-> state
.roam
()
3807 | Ascii
('
<'
|'
>'
as c) ->
3809 (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
3811 | Ascii
('
['
|'
]'
as c) ->
3813 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
3814 postRedisplay
"brightness";
3816 | Ascii '
c'
when state
.mode = View
->
3821 let m = (state
.winw
- state
.w) / 2 in
3826 match state
.prevcolumns
with
3827 | None
-> (1, 0, 0), 1.0
3828 | Some
(columns
, z
) ->
3831 | Csplit
(c, _) -> -c, 0, 0
3832 | Cmulti
((c, a, b), _) -> c, a, b
3833 | Csingle
_ -> 1, 0, 0
3837 setcolumns View
c a b;
3840 | Down
| Up
when ctrl && Wsi.withshift mask
->
3841 let zoom, x = state
.prevzoom
in
3846 begin match state
.autoscroll
with
3848 begin match state
.mode with
3849 | Birdseye beye
-> upbirdseye 1 beye
3850 | Textentry
_ | View
| LinkNav
_ ->
3852 then gotoxy state
.x (clamp ~
-(state
.winh
/2))
3854 if not
(Wsi.withshift mask
) && conf
.presentation
3856 else gotoxy state
.x (clamp (-conf
.scrollstep
))
3860 setautoscrollspeed n false
3863 | Ascii 'j'
| Down
->
3864 begin match state
.autoscroll
with
3866 begin match state
.mode with
3867 | Birdseye beye
-> downbirdseye 1 beye
3868 | Textentry
_ | View
| LinkNav
_ ->
3870 then gotoxy state
.x (clamp (state
.winh
/2))
3872 if not
(Wsi.withshift mask
) && conf
.presentation
3874 else gotoxy state
.x (clamp (conf
.scrollstep
))
3878 setautoscrollspeed n true
3881 | Left
| Right
when not
(Wsi.withalt mask
) ->
3887 else conf
.hscrollstep
3890 let pv = Wsi.kc2kt
key in
3891 if pv = Keys.Left
then dx else -dx
3893 gotoxy (panbound (state
.x + dx)) state
.y
3896 postRedisplay
"left/right"
3903 match state
.layout with
3905 | l :: _ -> state
.y - l.pagey
3907 clamp (pgscale (-state
.winh
))
3915 match List.rev state
.layout with
3917 | l :: _ -> getpagey
l.pageno
3919 clamp (pgscale state
.winh
)
3923 | Ascii '
g'
| Home
->
3926 | Ascii 'G'
| End
->
3928 gotoxy 0 (clamp state
.maxy)
3930 | Right
when Wsi.withalt mask
->
3932 gotoxy state
.x (getnav 1)
3933 | Left
when Wsi.withalt mask
->
3935 gotoxy state
.x (getnav ~
-1)
3940 | Ascii '
v'
when conf
.debug
->
3943 match getopaque l.pageno with
3946 let x0, y0, x1, y1 = pagebbox
opaque in
3947 let rect = (float x0, float y0,
3950 float x0, float y1) in
3952 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
3953 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
3958 let mode = state
.mode in
3959 let cmd = ref E.s in
3960 let onleave = function
3961 | Cancel
-> state
.mode <- mode
3964 match getopaque l.pageno with
3965 | Some
opaque -> pipesel opaque !cmd
3966 | None
-> ()) state
.layout;
3970 cbput state
.hists
.sel
s;
3974 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
3977 state
.mode <- Textentry
(te, onleave);
3979 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
3980 vlog "huh? %s" (Wsi.keyname
key)
3983 let linknavkeyboard key mask
linknav =
3984 let pv = Wsi.kc2kt
key in
3985 let getpage pageno =
3986 let rec loop = function
3988 | l :: _ when l.pageno = pageno -> Some
l
3989 | _ :: rest
-> loop rest
3990 in loop state
.layout
3992 let doexact (pageno, n) =
3993 match getopaque pageno, getpage pageno with
3994 | Some
opaque, Some
l ->
3997 let under = getlink
opaque n in
3998 postRedisplay
"link gotounder";
4005 | Home
-> Some
(findlink
opaque LDfirst
), -1
4006 | End
-> Some
(findlink
opaque LDlast
), 1
4007 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
4008 | Right
-> Some
(findlink
opaque (LDright
n)), 1
4009 | Up
-> Some
(findlink
opaque (LDup
n)), -1
4010 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
4012 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
4013 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
4016 begin match findpwl
l.pageno dir with
4020 state
.mode <- LinkNav
(Ltgendir
dir);
4021 let y, h = getpageyh
pageno in
4024 then y + h - state
.winh
4029 begin match getopaque pageno, getpage pageno with
4030 | Some
opaque, Some
_ ->
4032 let ld = if dir > 0 then LDfirst
else LDlast
in
4035 begin match link with
4037 showlinktype (getlink
opaque m);
4038 state
.mode <- LinkNav
(Ltexact
(pageno, m));
4039 postRedisplay
"linknav jpage";
4040 | Lnotfound
-> notfound dir
4046 begin match opt with
4047 | Some Lnotfound
-> pwl l dir;
4048 | Some
(Lfound
m) ->
4052 let _, y0, _, y1 = getlinkrect
opaque m in
4054 then gotopage1 l.pageno y0
4056 let d = fstate
.fontsize
+ 1 in
4057 if y1 - l.pagey > l.pagevh - d
4058 then gotopage1 l.pageno (y1 - state
.winh
+ d)
4059 else postRedisplay
"linknav";
4061 showlinktype (getlink
opaque m);
4062 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
4065 | None
-> viewkeyboard key mask
4067 | _ -> viewkeyboard key mask
4071 begin match linknav with
4072 | Ltexact pa
-> state
.lnava
<- Some pa
4073 | Ltgendir
_ | Ltnotready
_ -> ()
4076 postRedisplay
"leave linknav"
4080 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
4081 | Ltexact exact
-> doexact exact
4084 let keyboard key mask
=
4085 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
4086 then wcmd "interrupt"
4087 else state
.uioh <- state
.uioh#
key key mask
4090 let birdseyekeyboard key mask
4091 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4093 match conf
.columns
with
4095 | Cmulti
((c, _, _), _) -> c
4096 | Csplit
_ -> failwith
"bird's eye split mode"
4098 let pgh layout = List.fold_left
4099 (fun m l -> max
l.pageh
m) state
.winh
layout in
4101 match Wsi.kc2kt
key with
4102 | Ascii '
l'
when Wsi.withctrl mask
->
4103 let y, h = getpageyh
pageno in
4104 let top = (state
.winh
- h) / 2 in
4105 gotoxy state
.x (max
0 (y - top))
4106 | Enter
-> leavebirdseye beye
false
4107 | Escape
-> leavebirdseye beye
true
4108 | Up
-> upbirdseye incr beye
4109 | Down
-> downbirdseye incr beye
4110 | Left
-> upbirdseye 1 beye
4111 | Right
-> downbirdseye 1 beye
4114 begin match state
.layout with
4118 state
.mode <- Birdseye
(
4119 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4121 gotopage1 l.pageno 0;
4124 let layout = layout state
.x (state
.y-state
.winh
)
4126 (pgh state
.layout) in
4128 | [] -> gotoxy state
.x (clamp (-state
.winh
))
4130 state
.mode <- Birdseye
(
4131 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4133 gotopage1 l.pageno 0
4136 | [] -> gotoxy state
.x (clamp (-state
.winh
))
4140 begin match List.rev state
.layout with
4142 let layout = layout state
.x
4143 (state
.y + (pgh state
.layout))
4144 state
.winw state
.winh
in
4145 begin match layout with
4147 let incr = l.pageh
- l.pagevh in
4152 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
4154 postRedisplay
"birdseye pagedown";
4156 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
4160 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4161 gotopage1 l.pageno 0;
4164 | [] -> gotoxy state
.x (clamp state
.winh
)
4168 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4172 let pageno = state
.pagecount
- 1 in
4173 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4174 if not
(pagevisible state
.layout pageno)
4177 match List.rev state
.pdims
with
4179 | (_, _, h, _) :: _ -> h
4183 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
4184 else postRedisplay
"birdseye end";
4186 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
4191 match state
.mode with
4192 | Textentry
_ -> scalecolor 0.4
4193 | LinkNav
_ | View
-> scalecolor 1.0
4194 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4195 if l.pageno = hooverpageno
4198 if l.pageno = pageno
4200 let c = scalecolor 1.0 in
4202 GlDraw.line_width
3.0;
4203 let dispx = l.pagedispx in
4205 (float (dispx-1)) (float (l.pagedispy-1))
4206 (float (dispx+l.pagevw+1))
4207 (float (l.pagedispy+l.pagevh+1));
4208 GlDraw.line_width
1.0;
4217 let postdrawpage l linkindexbase
=
4218 match getopaque l.pageno with
4220 if tileready l l.pagex
l.pagey
4222 let x = l.pagedispx - l.pagex
4223 and y = l.pagedispy - l.pagey in
4225 match conf
.columns
with
4226 | Csingle
_ | Cmulti
_ ->
4227 (if conf
.hlinks
then 1 else 0)
4229 && not
(isbirdseye state
.mode) then 2 else 0)
4233 match state
.mode with
4234 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
4240 Hashtbl.find_all state
.prects
l.pageno |>
4241 List.iter
(fun vals
-> drawprect
opaque x y vals
);
4242 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
4244 then (Glutils.redisplay
:= true; 0)
4250 let scrollindicator () =
4251 let sbw, ph
, sh
= state
.uioh#scrollph
in
4252 let sbh, pw, sw
= state
.uioh#scrollpw
in
4257 else ((state
.winw
- sbw), state
.winw
, 0)
4261 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4262 let (r
, g, b, alpha
) = conf
.sbarcolor
in
4263 GlDraw.color (r
, g, b) ~alpha
;
4264 filledrect
(float x0) 0. (float x1) (float state
.winh
);
4266 (float hx0
) (float (state
.winh
- sbh))
4267 (float (hx0
+ state
.winw
)) (float state
.winh
);
4268 let (r
, g, b, alpha
) = conf
.sbarhndlcolor
in
4269 GlDraw.color (r
, g, b) ~alpha
;
4271 filledrect
(float x0) ph
(float x1) (ph
+. sh
);
4272 let pw = pw +. float hx0
in
4273 filledrect
pw (float (state
.winh
- sbh)) (pw +. sw
) (float state
.winh
);
4278 match state
.mstate
with
4279 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4282 | Msel
((x0, y0), (x1, y1)) ->
4283 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
4284 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
4285 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
4286 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
4293 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4294 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4296 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4298 if l.pageno = pageno
4300 let dx = float (l.pagedispx - l.pagex
) in
4301 let dy = float (l.pagedispy - l.pagey) in
4302 let r, g, b, alpha
= c in
4303 GlDraw.color (r, g, b) ~alpha
;
4304 filledrect2
(x0+.dx) (y0+.dy)
4315 GlDraw.color (scalecolor2 conf
.bgcolor
);
4316 GlClear.color (scalecolor2 conf
.bgcolor
);
4317 GlClear.clear
[`
color];
4318 List.iter
drawpage state
.layout;
4320 match state
.mode with
4321 | LinkNav
(Ltexact
(pageno, linkno
)) ->
4322 begin match getopaque pageno with
4324 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
4325 let color = (0.0, 0.0, 0.5, 0.5) in
4327 (float x0, float y0,
4332 | None
-> state
.rects
4334 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
4337 | View
-> state
.rects
4340 let rec postloop linkindexbase
= function
4342 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
4343 postloop linkindexbase rest
4347 postloop 0 state
.layout;
4349 begin match state
.mstate
with
4350 | Mzoomrect
((x0, y0), (x1, y1)) ->
4352 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4353 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4354 filledrect
(float x0) (float y0) (float x1) (float y1);
4358 | Mscrolly
| Mscrollx
4367 let zoomrect x y x1 y1 =
4370 and y0 = min
y y1 in
4371 let zoom = (float state
.w) /. float (x1 - x0) in
4374 if state
.w < state
.winw
4375 then (state
.winw
- state
.w) / 2
4378 match conf
.fitmodel
with
4379 | FitWidth
| FitProportional
-> simple ()
4381 match conf
.columns
with
4383 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
4384 | Cmulti
_ | Csingle
_ -> simple ()
4386 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
4387 state
.anchor <- getanchor
();
4392 let annot inline
x y =
4393 match unproject x y with
4394 | Some
(opaque, n, ux
, uy
) ->
4396 addannot
opaque ux uy
text;
4397 wcmd "freepage %s" (~
> opaque);
4398 Hashtbl.remove state
.pagemap
(n, state
.gen
);
4400 gotoxy state
.x state
.y
4404 let ondone s = add s in
4405 let mode = state
.mode in
4406 state
.mode <- Textentry
(
4407 ("annotation: ", E.s, None
, textentry, ondone, true),
4408 fun _ -> state
.mode <- mode);
4411 postRedisplay
"annot"
4413 add @@ getusertext E.s
4418 let g opaque l px py =
4419 match rectofblock
opaque px py with
4421 let x0 = a.(0) -. 20. in
4422 let x1 = a.(1) +. 20. in
4423 let y0 = a.(2) -. 20. in
4424 let zoom = (float state
.w) /. (x1 -. x0) in
4425 let pagey = getpagey
l.pageno in
4426 let margin = (state
.w - l.pagew
)/2 in
4427 let nx = -truncate
x0 - margin in
4428 gotoxy nx (pagey + truncate
y0);
4429 state
.anchor <- getanchor
();
4434 match conf
.columns
with
4436 impmsg "block zooming does not work properly in split columns mode"
4437 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
4441 let winw = state
.winw - 1 in
4442 let s = float x /. float winw in
4443 let destx = truncate
(float (state
.w + winw) *. s) in
4444 gotoxy (winw - destx) state
.y;
4445 state
.mstate
<- Mscrollx
;
4449 let s = float y /. float state
.winh
in
4450 let desty = truncate
(s *. float (maxy ())) in
4451 gotoxy state
.x desty;
4452 state
.mstate
<- Mscrolly
;
4455 let viewmulticlick clicks
x y mask
=
4456 let g opaque l px py =
4464 if markunder
opaque px py mark
4468 match getopaque l.pageno with
4470 | Some
opaque -> pipesel opaque cmd
4472 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
4473 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
4478 postRedisplay
"viewmulticlick";
4479 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
4483 match conf
.columns
with
4485 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
4488 let viewmouse button down
x y mask
=
4490 | n when (n == 4 || n == 5) && not down
->
4491 if Wsi.withctrl mask
4495 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4496 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4499 match state
.mstate
with
4500 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
4501 | Mzoomrect
_ | Mnone
| Mpan
_
4502 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
4504 let zoom = conf
.zoom -. incr in
4505 state
.mstate
<- Mzoom
(n, 0, (x, y));
4506 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
4507 then pivotzoom ~
x ~
y zoom
4511 match state
.autoscroll
with
4512 | Some step
-> setautoscrollspeed step
(n=4)
4514 if conf
.wheelbypage
|| conf
.presentation
4523 then -conf
.scrollstep
4524 else conf
.scrollstep
4526 let incr = incr * 2 in
4527 let y = clamp incr in
4531 | n when (n = 6 || n = 7) && not down
&& canpan () ->
4533 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
4536 | 1 when Wsi.withshift mask
->
4537 state
.mstate
<- Mnone
;
4540 match unproject x y with
4542 | Some
(_, pageno, ux
, uy
) ->
4543 let cmd = Printf.sprintf
4545 conf
.stcmd state
.path pageno ux uy
4547 match spawn
cmd [] with
4549 impmsg "execution of synctex command(%S) failed: %S"
4550 conf
.stcmd
@@ exntos exn
4554 | 1 when Wsi.withctrl mask
->
4557 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4558 state
.mstate
<- Mpan
(x, y)
4561 state
.mstate
<- Mnone
4566 if Wsi.withshift mask
4568 annot conf
.annotinline
x y;
4569 postRedisplay
"addannot"
4573 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4574 state
.mstate
<- Mzoomrect
(p, p)
4577 match state
.mstate
with
4578 | Mzoomrect
((x0, y0), _) ->
4579 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4580 then zoomrect x0 y0 x y
4583 postRedisplay
"kill accidental zoom rect";
4587 | Mscrolly
| Mscrollx
4589 | Mnone
-> resetmstate ()
4592 | 1 when vscrollhit
x ->
4595 let _, position
, sh
= state
.uioh#scrollph
in
4596 if y > truncate position
&& y < truncate
(position
+. sh
)
4597 then state
.mstate
<- Mscrolly
4600 state
.mstate
<- Mnone
4602 | 1 when y > state
.winh
- hscrollh () ->
4605 let _, position
, sw
= state
.uioh#scrollpw
in
4606 if x > truncate position
&& x < truncate
(position
+. sw
)
4607 then state
.mstate
<- Mscrollx
4610 state
.mstate
<- Mnone
4612 | 1 when state
.bzoom
-> if not down
then zoomblock x y
4615 let dest = if down
then getunder x y else Unone
in
4616 begin match dest with
4620 | Unone
when down
->
4621 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4622 state
.mstate
<- Mpan
(x, y);
4624 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4626 | Unone
| Utext
_ ->
4631 state
.mstate
<- Msel
((x, y), (x, y));
4632 postRedisplay
"mouse select";
4636 match state
.mstate
with
4639 | Mzoom
_ | Mscrollx
| Mscrolly
->
4640 state
.mstate
<- Mnone
4642 | Mzoomrect
((x0, y0), _) ->
4646 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4647 state
.mstate
<- Mnone
4649 | Msel
((x0, y0), (x1, y1)) ->
4650 let rec loop = function
4654 let a0 = l.pagedispy in
4655 let a1 = a0 + l.pagevh in
4656 let b0 = l.pagedispx in
4657 let b1 = b0 + l.pagevw in
4658 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
4659 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
4663 match getopaque l.pageno with
4666 pipef ~closew
:false "Msel"
4669 postRedisplay
"Msel") cmd
4671 dosel conf
.selcmd
();
4672 state
.roam
<- dosel conf
.paxcmd
;
4684 let birdseyemouse button down
x y mask
4685 (conf
, leftx
, _, hooverpageno
, anchor) =
4688 let rec loop = function
4691 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4692 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4694 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
4700 | _ -> viewmouse button down
x y mask
4706 method key key mask
=
4707 begin match state
.mode with
4708 | Textentry
textentry -> textentrykeyboard
key mask
textentry
4709 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
4710 | View
-> viewkeyboard key mask
4711 | LinkNav
linknav -> linknavkeyboard key mask
linknav
4715 method button button bstate
x y mask
=
4716 begin match state
.mode with
4717 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
4718 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
4723 method multiclick clicks
x y mask
=
4724 begin match state
.mode with
4725 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
4726 | Birdseye
_ | Textentry
_ -> ()
4731 begin match state
.mode with
4733 | View
| Birdseye
_ | LinkNav
_ ->
4734 match state
.mstate
with
4735 | Mzoom
_ | Mnone
-> ()
4740 state
.mstate
<- Mpan
(x, y);
4741 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4746 state
.mstate
<- Msel
(a, (x, y));
4747 postRedisplay
"motion select";
4750 let y = min state
.winh
(max
0 y) in
4754 let x = min state
.winw (max
0 x) in
4757 | Mzoomrect
(p0
, _) ->
4758 state
.mstate
<- Mzoomrect
(p0
, (x, y));
4759 postRedisplay
"motion zoomrect";
4763 method pmotion
x y =
4764 begin match state
.mode with
4765 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
4766 let rec loop = function
4768 if hooverpageno
!= -1
4770 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
4771 postRedisplay
"pmotion birdseye no hoover";
4774 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4775 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4777 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
4778 postRedisplay
"pmotion birdseye hoover";
4786 | LinkNav
_ | View
->
4787 match state
.mstate
with
4788 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
4797 let delta = now -. past
in
4800 else conf
.pax
<- Some
now
4804 method infochanged
_ = ()
4807 let maxy = maxy () in
4810 then 0.0, float state
.winh
4811 else scrollph state
.y maxy
4816 let fwinw = float (state
.winw - vscrollw
()) in
4818 let sw = fwinw /. float state
.w in
4819 let sw = fwinw *. sw in
4820 max
sw (float conf
.scrollh
)
4823 let maxx = state
.w + state
.winw in
4824 let x = state
.winw - state
.x in
4825 let percent = float x /. float maxx in
4826 (fwinw -. sw) *. percent
4828 hscrollh (), position, sw
4832 match state
.mode with
4833 | LinkNav
_ -> "links"
4834 | Textentry
_ -> "textentry"
4835 | Birdseye
_ -> "birdseye"
4838 findkeyhash conf
modename
4840 method eformsgs
= true
4841 method alwaysscrolly
= false
4842 method scroll
dx dy =
4843 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4844 gotoxy x (clamp (2 * dy));
4847 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
4850 let addrect pageno r g b a x0 y0 x1 y1 =
4851 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
4855 let cl = splitatchar cmds ' '
in
4857 try Scanf.sscanf
s fmt
f
4858 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
4861 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
4862 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
4863 s pageno r g b a x0 y0 x1 y1;
4867 let _,w1
,h1
,_ = getpagedim
pageno in
4868 let sw = float w1
/. float w
4869 and sh
= float h1
/. float h in
4873 and y1s
= y1 *. sh
in
4874 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
4875 let color = (r, g, b, a) in
4876 if conf
.verbose
then debugrect rect;
4877 state
.rects <- (pageno, color, rect) :: state
.rects;
4882 | "reload", "" -> reload ()
4884 scan args
"%u %f %f"
4886 let cmd, _ = state
.geomcmds
in
4888 then gotopagexy pageno x y
4891 gotopagexy pageno x y;
4894 state
.reprf
<- f state
.reprf
4896 | "goto1", args
-> scan args
"%u %f" gotopage
4897 | "gotor", args
-> scan args
"%S" gotoremote
4899 scan args
"%u %u %f %f %f %f"
4900 (fun pageno c x0 y0 x1 y1 ->
4901 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
4902 rectx "rect" pageno color x0 y0 x1 y1;
4905 scan args
"%u %f %f %f %f %f %f %f %f"
4906 (fun pageno r g b alpha
x0 y0 x1 y1 ->
4907 addrect pageno r g b alpha
x0 y0 x1 y1;
4908 postRedisplay
"prect"
4911 scan args
"%u %f %f"
4914 match getopaque pageno with
4915 | Some
opaque -> opaque
4918 pgoto optopaque pageno x y;
4919 let rec fixx = function
4922 if l.pageno = pageno
4923 then gotoxy (state
.x - l.pagedispx) state
.y
4928 match conf
.columns
with
4929 | Csingle
_ | Csplit
_ -> 1
4930 | Cmulti
((n, _, _), _) -> n
4932 layout 0 state
.y (state
.winw * mult) state
.winh
4936 | "activatewin", "" -> Wsi.activatewin
()
4937 | "quit", "" -> raise Quit
4940 let l = Config.keys_of_string
keys in
4941 List.iter
(fun (k
, m) -> keyboard k
m) l
4942 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
4945 | "clearrects", "" ->
4946 Hashtbl.clear state
.prects
;
4947 postRedisplay
"clearrects"
4949 adderrfmt "remote command"
4950 "error processing remote command: %S\n" cmds
;
4954 let scratch = Bytes.create
80 in
4955 let buf = Buffer.create
80 in
4957 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
4958 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
4961 if Buffer.length
buf > 0
4963 let s = Buffer.contents
buf in
4971 match Bytes.index_from
scratch ppos '
\n'
with
4972 | pos
-> if pos
>= n then -1 else pos
4973 | exception Not_found
-> -1
4977 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
4978 let s = Buffer.contents
buf in
4984 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
4990 let remoteopen path =
4991 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
4993 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
4998 let gcconfig = ref false in
4999 let trimcachepath = ref E.s in
5000 let rcmdpath = ref E.s in
5001 let pageno = ref None
in
5002 let openlast = ref false in
5003 let doreap = ref false in
5004 let csspath = ref None
in
5005 selfexec := Sys.executable_name
;
5008 [("-p", Arg.String
(fun s -> state
.password <- s),
5009 "<password> Set password");
5013 Config.fontpath
:= s;
5014 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
5016 "<path> Set path to the user interface font");
5020 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
5021 Config.confpath
:= s),
5022 "<path> Set path to the configuration file");
5024 ("-last", Arg.Set
openlast, " Open last document");
5026 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
5027 "<page-number> Jump to page");
5029 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
5030 "<path> Set path to the trim cache file");
5032 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
5033 "<named-destination> Set named destination");
5035 ("-remote", Arg.String
(fun s -> rcmdpath := s),
5036 "<path> Set path to the source of remote commands");
5038 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
5040 ("-v", Arg.Unit
(fun () ->
5042 "%s\nconfiguration file: %s\n"
5045 exit
0), " Print version and exit");
5047 ("-css", Arg.String
(fun s -> csspath := Some
s),
5048 "<path> Set path to the style sheet to use with EPUB/HTML");
5050 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
5051 "<origin> <undocumented>");
5053 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title");
5054 ("-layout-height", Arg.Set_int
layouth,
5055 "<height> layout height html/epub/etc (-1, 0, N)");
5058 (fun s -> state
.path <- s)
5059 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
5061 let histmode = emptystr state
.path && not
!openlast in
5063 if not
(Config.load !openlast)
5064 then dolog
"failed to load configuration";
5066 begin match !pageno with
5067 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
5080 val mutable m_clicks
= 0
5081 val mutable m_click_x
= 0
5082 val mutable m_click_y
= 0
5083 val mutable m_lastclicktime
= infinity
5085 method private cleanup =
5086 state
.roam
<- noroam
;
5087 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
5088 method expose
= postRedisplay
"expose"
5092 | Wsi.Unobscured
-> "unobscured"
5093 | Wsi.PartiallyObscured
-> "partiallyobscured"
5094 | Wsi.FullyObscured
-> "fullyobscured"
5096 vlog "visibility change %s" name
5097 method display = display ()
5098 method map mapped
= vlog "mapped %b" mapped
5099 method reshape w h =
5102 method mouse
b d x y m =
5103 if d && canselect ()
5106 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
5113 if abs
x - m_click_x
> 10
5114 || abs
y - m_click_y
> 10
5115 || abs_float
(t -. m_lastclicktime
) > 0.3
5117 m_clicks
<- m_clicks
+ 1;
5118 m_lastclicktime
<- t;
5122 postRedisplay
"cleanup";
5123 state
.uioh <- state
.uioh#button
b d x y m;
5125 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
5130 m_lastclicktime
<- infinity
;
5131 state
.uioh <- state
.uioh#button
b d x y m
5135 state
.uioh <- state
.uioh#button
b d x y m
5138 state
.mpos
<- (x, y);
5139 state
.uioh <- state
.uioh#motion
x y
5140 method pmotion
x y =
5141 state
.mpos
<- (x, y);
5142 state
.uioh <- state
.uioh#pmotion
x y
5144 vlog "k=%#x m=%#x" k
m;
5145 let mascm = m land (
5146 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
5149 let x = state
.x and y = state
.y in
5151 if x != state
.x || y != state
.y then self#
cleanup
5153 match state
.keystate
with
5155 let km = k
, mascm in
5158 let modehash = state
.uioh#
modehash in
5159 try Hashtbl.find
modehash km
5161 try Hashtbl.find
(findkeyhash conf
"global") km
5162 with Not_found
-> KMinsrt
(k
, m)
5164 | KMinsrt
(k
, m) -> keyboard k
m
5165 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
5166 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
5168 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
5169 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
5170 state
.keystate
<- KSnone
5171 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
5172 state
.keystate
<- KSinto
(keys, insrt
)
5173 | KSinto
_ -> state
.keystate
<- KSnone
5176 state
.mpos
<- (x, y);
5177 state
.uioh <- state
.uioh#pmotion
x y
5178 method leave = state
.mpos
<- (-1, -1)
5179 method winstate wsl
= state
.winstate
<- wsl
5180 method quit
: '
a. '
a = raise Quit
5181 method scroll
dx dy = state
.uioh <- state
.uioh#scroll
dx dy
5182 method zoom z
x y = state
.uioh#
zoom z
x y
5183 method opendoc path =
5186 postRedisplay
"opendoc";
5187 opendoc path state
.password
5190 let wsfd, winw, winh
= Wsi.init
mu conf
.cwinw conf
.cwinh platform
in
5193 if not
@@ List.exists
GlMisc.check_extension
5194 [ "GL_ARB_texture_rectangle"
5195 ; "GL_EXT_texture_recangle"
5196 ; "GL_NV_texture_rectangle" ]
5197 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
5199 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
5201 defconf
.sliceheight
<- 1024;
5202 defconf
.texcount
<- 32;
5203 defconf
.usepbo
<- true;
5207 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
5209 dolog
"socketpair failed: %s" @@ exntos exn
;
5217 setcheckers conf
.checkers
;
5219 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
5221 begin match !csspath with
5223 | Some
"" -> conf
.css
<- E.s
5225 let css = filecontents
path in
5226 let l = String.length
css in
5228 if substratis
css (l-2) "\r\n"
5229 then String.sub css 0 (l-2)
5230 else (if css.[l-1] = '
\n'
5231 then String.sub css 0 (l-1)
5235 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
5236 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
5237 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
5239 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
5241 reshape ~firsttime
:true winw winh
;
5245 Wsi.settitle
"llpp (history)";
5249 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
5250 opendoc state
.path state
.password;
5254 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5255 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
5258 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
5259 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
5260 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
5262 | _pid
, _status
-> reap ()
5264 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
5268 if nonemptystr
!rcmdpath
5269 then remoteopen !rcmdpath
5274 let rec loop deadline
=
5280 let r = [state
.ss; state
.wsfd] in
5284 | Some fd
-> fd
:: r
5288 Glutils.redisplay
:= false;
5295 if deadline
= infinity
5297 else max
0.0 (deadline
-. now)
5302 try Unix.select
r [] [] timeout
5303 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5308 match state
.autoscroll
with
5309 | Some step
when step
!= 0 ->
5310 if state
.slideshow
land 1 = 1
5312 if state
.slideshow
land 2 = 0
5313 then state
.slideshow
<- state
.slideshow
lor 2
5314 else if step
< 0 then prevpage () else nextpage ();
5315 deadline
+. (float (abs step
))
5318 let y = state
.y + step
in
5319 let fy = if conf
.maxhfit
then state
.winh
else 0 in
5322 then state
.maxy - fy
5323 else if y >= state
.maxy - fy then 0 else y
5332 let rec checkfds = function
5334 | fd
:: rest
when fd
= state
.ss ->
5335 let cmd = rcmd state
.ss in
5339 | fd
:: rest
when fd
= state
.wsfd ->
5343 | fd
:: rest
when Some fd
= !optrfd ->
5344 begin match remote fd
with
5345 | None
-> optrfd := remoteopen !rcmdpath;
5346 | opt -> optrfd := opt
5351 dolog
"select returned unknown descriptor";
5357 if deadline
= infinity
5361 match state
.autoscroll
with
5362 | Some step
when step
!= 0 -> deadline1
5368 match loop infinity
with
5370 Config.save leavebirdseye;
5371 if hasunsavedchanges
()
5373 | _ -> error
"umpossible - infinity reached"