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;;
62 let checkerstexid = ref None
;;
64 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
70 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
73 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
76 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
77 && (state
.w
> state
.winw
))
84 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
85 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
91 else Printf.kprintf ignore fmt
95 if emptystr conf
.pathlauncher
96 then dolog
"%s" state
.path
99 Str.global_replace
Utils.Re.percent state
.path conf
.pathlauncher
in
100 match spawn
command [] with
102 | exception exn
-> 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
143 let g opaque l
px py
=
146 match rectofblock opaque
px py
with
147 | Some
[|x0;x1;y0;y1|] ->
148 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
149 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
150 state
.rects
<- [l
.pageno
, color, rect];
151 postRedisplay
"getunder";
154 let under = whatsunder opaque
px py
in
155 if under = Unone
then None
else Some
under
157 onppundermouse g x y Unone
162 match unproject opaque
x y with
163 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
166 onppundermouse g x y None
;
170 state
.text
<- Printf.sprintf
"%c%s" c s
;
171 postRedisplay
"showtext";
174 let impmsg fmt
= Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;;
176 let pipesel opaque cmd
=
178 then pipef ~closew
:false "pipesel"
181 postRedisplay
"pipesel"
186 let g opaque l
px py
=
187 if markunder opaque
px py conf
.paxmark
190 match getopaque l
.pageno
with
192 | Some opaque
-> pipesel opaque conf
.paxcmd
196 postRedisplay
"paxunder";
197 if conf
.paxmark
= Mark_page
200 match getopaque l
.pageno
with
202 | Some opaque
-> clearmark opaque
) state
.layout
;
203 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
206 let undertext = function
209 | Utext s
-> "font: " ^ s
210 | Uannotation
(opaque
, slinkindex
) ->
211 "annotation: " ^ getannotcontents opaque slinkindex
214 let updateunder x y =
215 match getunder x y with
216 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
218 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
219 Wsi.setcursor
Wsi.CURSOR_INFO
221 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
222 Wsi.setcursor
Wsi.CURSOR_TEXT
224 if conf
.underinfo
then showtext 'a'
"nnotation";
225 Wsi.setcursor
Wsi.CURSOR_INFO
228 let showlinktype under =
229 if conf
.underinfo
&& under != Unone
230 then showtext ' '
@@ undertext under
233 let intentry_with_suffix text key
=
235 match [@warning
"-4"] key
with
236 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
237 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
238 addchar
text @@ asciilower c
240 state
.text <- "invalid key";
247 let b = Buffer.create
16 in
250 let b = Buffer.to_bytes
b in
251 wcmd state
.ss
b @@ Bytes.length
b
255 let nogeomcmds cmds
=
257 | s
, [] -> emptystr s
261 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
262 let rec fold accu n
=
263 if n
= Array.length
b
266 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n
) in
269 || n
= state
.pagecount
- coverB
270 || (n
- coverA
) mod columns
= columns
- 1)
276 let pagey = max
0 (y - vy
) in
277 let pagedispy = if pagey > 0 then 0 else vy
- y in
278 let pagedispx, pagex
=
280 if n
= coverA
- 1 || n
= state
.pagecount
- coverB
281 then x + (sw
- w
) / 2
289 let vw = sw
- pagedispx in
290 let pw = w
- pagex
in
293 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
294 if pagevw > 0 && pagevh > 0
305 ; pagedispx = pagedispx
306 ; pagedispy = pagedispy
316 if Array.length
b = 0
318 else List.rev
(fold [] (page_of_y
y))
321 let layoutS (columns
, b) x y sw sh
=
322 let rec fold accu n
=
323 if n
= Array.length
b
326 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n
) in
334 let pagey = max
0 (y - vy
) in
335 let pagedispy = if pagey > 0 then 0 else vy
- y in
336 let pagedispx, pagex
=
350 let pagecolw = pagew
/columns
in
353 then pagedispx + ((sw
- pagecolw) / 2)
357 let vw = sw
- pagedispx in
358 let pw = pagew
- pagex
in
361 let pagevw = min
pagevw pagecolw in
362 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
363 if pagevw > 0 && pagevh > 0
374 ; pagedispx = pagedispx
375 ; pagedispy = pagedispy
376 ; pagecol
= n
mod columns
388 let layout x y sw sh
=
389 if nogeomcmds state
.geomcmds
391 match conf
.columns
with
392 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
393 | Cmulti c
-> layoutN c
x y sw sh
394 | Csplit s
-> layoutS s
x y sw sh
398 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
399 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
402 let tilex = l
.pagex
mod conf
.tilew
in
403 let tiley = l
.pagey mod conf
.tileh
in
405 let col = l
.pagex
/ conf
.tilew
in
406 let row = l
.pagey / conf
.tileh
in
408 let rec rowloop row y0 dispy h
=
411 let dh = conf
.tileh
- y0 in
413 let rec colloop col x0 dispx w
=
416 let dw = conf
.tilew
- x0 in
418 f col row dispx dispy
x0 y0 dw dh;
419 colloop (col+1) 0 (dispx
+dw) (w
-dw)
421 colloop col tilex l
.pagedispx l
.pagevw;
422 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
424 if l
.pagevw > 0 && l
.pagevh > 0
425 then rowloop row tiley l
.pagedispy l
.pagevh;
428 let gettileopaque l
col row =
429 let key = l
.pageno
, state
.gen
, conf
.colorspace
,
430 conf
.angle
, l
.pagew
, l
.pageh
, col, row in
431 try Some
(Hashtbl.find state
.tilemap
key)
432 with Not_found
-> None
435 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
436 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
437 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
440 let drawtiles l
color =
443 let f col row x y tilex tiley w h
=
444 match gettileopaque l
col row with
445 | Some
(opaque
, _
, t
) ->
446 let params = x, y, w
, h
, tilex, tiley in
448 then GlTex.env
(`mode `blend
);
449 drawtile
params opaque
;
451 then GlTex.env
(`mode `modulate
);
455 let s = Printf.sprintf
"%d[%d,%d] %f sec" l
.pageno
col row t
in
456 let w = measurestr fstate
.fontsize
s in
457 GlDraw.color (0.0, 0.0, 0.0);
462 (float (y + fstate
.fontsize
+ 2));
464 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
470 let w = let lw = state
.winw
- x in min
lw w
471 and h
= let lh = state
.winh
- y in min
lh h
474 then GlTex.env
(`mode `blend
);
475 begin match !checkerstexid with
477 Gl.enable `texture_2d
;
478 GlTex.bind_texture ~target
:`texture_2d id
;
482 and y1 = float (y+h
) in
484 let tw = float w /. 16.0
485 and th
= float h
/. 16.0 in
486 let tx0 = float tilex /. 16.0
487 and ty0
= float tiley /. 16.0 in
489 and ty1
= ty0
+. th
in
490 Raw.sets_float
Glutils.vraw ~pos
:0
491 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
492 Raw.sets_float
Glutils.traw ~pos
:0
493 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
494 GlArray.vertex `two
Glutils.vraw
;
495 GlArray.tex_coord `two
Glutils.traw
;
496 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
497 Gl.disable `texture_2d
;
500 GlDraw.color (1.0, 1.0, 1.0);
501 filledrect
(float x) (float y) (float (x+w)) (float (y+h
));
504 then GlTex.env
(`mode `modulate
);
505 if w > 128 && h
> fstate
.fontsize
+ 10
507 let c = if conf
.invert
then 1.0 else 0.0 in
508 GlDraw.color (c, c, c);
511 then (col*conf
.tilew
, row*conf
.tileh
)
514 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
523 let pagevisible layout n
= List.exists
(fun l
-> l
.pageno
= n
) layout;;
525 let tilevisible1 l
x y =
527 and ax1
= l
.pagex
+ l
.pagevw
529 and ay1
= l
.pagey + l
.pagevh in
533 let bx1 = min
(bx0 + conf
.tilew
) l
.pagew
534 and by1
= min
(by0
+ conf
.tileh
) l
.pageh
in
536 let rx0 = max
ax0 bx0
537 and ry0
= max ay0 by0
538 and rx1
= min ax1
bx1
539 and ry1
= min ay1 by1
in
541 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
545 let tilevisible layout n
x y =
546 let rec findpageinlayout m
= function
547 | l
:: rest
when l
.pageno
= n
->
548 tilevisible1 l
x y || (
549 match conf
.columns
with
550 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
551 | Csplit _
| Csingle _
| Cmulti _
-> false
553 | _
:: rest
-> findpageinlayout 0 rest
556 findpageinlayout 0 layout;
559 let tileready l
x y =
560 tilevisible1 l
x y &&
561 gettileopaque l
(x/conf
.tilew
) (y/conf
.tileh
) != None
564 let tilepage n p
layout =
565 let rec loop = function
569 let f col row _ _ _ _ _ _
=
570 if state
.currently
= Idle
572 match gettileopaque l
col row with
575 let x = col*conf
.tilew
576 and y = row*conf
.tileh
in
578 let w = l
.pagew
- x in
582 let h = l
.pageh
- y in
587 then getpbo
w h conf
.colorspace
590 wcmd "tile %s %d %d %d %d %s" (~
> p
) x y w h (~
> pbo);
593 l
, p
, conf
.colorspace
, conf
.angle
,
594 state
.gen
, col, row, conf
.tilew
, conf
.tileh
603 if nogeomcmds state
.geomcmds
607 let preloadlayout x y sw sh
=
608 let y = if y < sh
then 0 else y - sh
in
609 let x = min
0 (x + sw
) in
617 if state
.currently
= Idle
621 begin match getopaque l
.pageno
with
623 wcmd "page %d %d" l
.pageno l
.pagedimno
;
624 state
.currently
<- Loading
(l
, state
.gen
);
626 tilepage l
.pageno opaque pages
;
631 if nogeomcmds state
.geomcmds
637 if conf
.preload && state
.currently
= Idle
638 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
641 let layoutready layout =
642 let rec fold all ls
=
645 let seen = ref false in
646 let allvisible = ref true in
647 let foo col row _ _ _ _ _ _
=
649 allvisible := !allvisible &&
650 begin match gettileopaque l
col row with
656 fold (!seen && !allvisible) rest
659 let alltilesvisible = fold true layout in
664 let y = bound
y 0 state
.maxy in
666 let layout = layout x y state
.winw state
.winh
in
667 postRedisplay
"gotoxy ready";
672 state
.layout <- layout;
673 begin match state
.mode
with
676 | Ltexact
(pageno
, linkno
) ->
677 let rec loop = function
679 state
.lnava
<- Some
(pageno
, linkno
);
680 state
.mode
<- LinkNav
(Ltgendir
0)
681 | l
:: _
when l
.pageno
= pageno
->
682 begin match getopaque pageno
with
683 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
685 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
686 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
687 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
688 then state
.mode
<- LinkNav
(Ltgendir
0)
690 | _
:: rest
-> loop rest
693 | Ltnotready _
| Ltgendir _
-> ()
695 | Birdseye _
| Textentry _
| View
-> ()
697 begin match state
.mode
with
698 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
699 if not
(pagevisible layout pageno
)
701 match state
.layout with
704 state
.mode
<- Birdseye
(conf
, leftx
, l
.pageno
, hooverpageno
, anchor
)
708 | Ltnotready
(_
, dir
)
711 let rec loop = function
714 match getopaque l
.pageno
with
715 | None
-> Ltnotready
(l
.pageno
, dir
)
720 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
722 if dir
> 0 then LDfirst
else LDlast
728 | Lnotfound
-> loop rest
730 showlinktype (getlink opaque n
);
731 Ltexact
(l
.pageno
, n
)
735 state
.mode
<- LinkNav
linknav
738 | Textentry _
| View
-> ()
743 let mx, my
= state
.mpos
in
748 let conttiling pageno opaque
=
749 tilepage pageno opaque
751 then preloadlayout state
.x state
.y state
.winw state
.winh
756 if not conf
.verbose
then state
.text <- E.s;
760 let getanchory (n
, top
, dtop
) =
761 let y, h = getpageyh n
in
764 let ips = calcips
h in
765 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
766 else y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
769 let gotoanchor anchor
= gotoxy state
.x (getanchory anchor
);;
770 let addnav () = getanchor
() |> cbput state
.hists
.nav
;;
771 let addnavnorc () = getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;;
774 let anchor = cbgetc state
.hists
.nav dir
in
779 let y, h = getpageyh n
in
780 let y = y + (truncate
(top
*. float h)) in
784 let gotopage1 n top
=
785 let y = getpagey n
in
791 Glutils.redisplay
:= false;
796 match state
.geomcmds
with
797 | ps
, [] when emptystr ps
->
799 state
.geomcmds
<- s, [];
800 | ps
, [] -> state
.geomcmds
<- ps
, [s, f];
801 | ps
, (s'
, _
) :: rest
when s'
= s -> state
.geomcmds
<- ps
, ((s, f) :: rest
);
802 | ps
, cmds
-> state
.geomcmds
<- ps
, ((s, f) :: cmds
);
806 Hashtbl.iter
(fun _ opaque
-> wcmd "freepage %s" (~
> opaque
)) state
.pagemap
;
807 Hashtbl.clear state
.pagemap
;
811 if not
(Queue.is_empty state
.tilelru
)
813 Queue.iter
(fun (k
, p
, s) ->
814 wcmd "freetile %s" (~
> p
);
815 state
.memused
<- state
.memused
- s;
816 Hashtbl.remove state
.tilemap k
;
818 state
.uioh#infochanged Memused
;
819 Queue.clear state
.tilelru
;
825 let h = truncate
(float h*.conf
.zoom
) in
826 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
832 let sl = keystostrlist conf
in
834 function | [] -> accu
835 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
836 in Help.makehelp conf
.urilauncher
837 @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
840 let opendoc path password
=
842 state
.password
<- password
;
843 state
.gen
<- state
.gen
+ 1;
845 state
.outlines
<- [||];
848 setaalevel conf
.aalevel
;
850 if emptystr state
.origin
854 Wsi.settitle
("llpp " ^ mbtoutf8
(Filename.basename
titlepath));
855 wcmd "open %d %d %s\000%s\000%s\000"
856 (btod conf
.usedoccss
) !layouth
857 path password conf
.css
;
858 invalidate "reqlayout"
860 wcmd "reqlayout %d %d %d %s\000"
861 conf
.angle
(FMTE.to_int conf
.fitmodel
)
862 (stateh state
.winh
) state
.nameddest
868 state
.anchor <- getanchor
();
869 opendoc state
.path state
.password
;
873 let c = c *. conf
.colorscale
in
877 let scalecolor2 (r
, g, b) =
878 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
881 let docolumns columns
=
884 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
885 let rec loop pageno
pdimno pdim
y ph pdims
=
886 if pageno
!= state
.pagecount
888 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
890 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
895 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
897 y + (if conf
.presentation
898 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
899 else (if pageno
= 0 then 0 else conf
.interpagespace
))
901 a.(pageno
) <- (pdimno, x, y, pdim
);
902 loop (pageno
+1) pdimno pdim
(y + h) h pdims
904 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
905 conf
.columns
<- Csingle
a;
907 | Cmulti
((columns
, coverA
, coverB
), _
) ->
908 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
909 let rec loop pageno
pdimno pdim
x y rowh pdims
=
911 if m
= pageno
then () else
912 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
915 let y = y + (rowh
- h) / 2 in
916 a.(m
) <- (pdimno, x, y, pdim
);
920 if pageno
= state
.pagecount
921 then fixrow (((pageno
- 1) / columns
) * columns
)
923 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
925 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
927 | _
-> pdimno, pdim
, pdims
930 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
932 let x = (state
.winw
- w) / 2 in
934 if conf
.presentation
then calcips
h else conf
.interpagespace
in
938 if (pageno
- coverA
) mod columns
= 0
940 let x = max
0 (state
.winw
- state
.w) / 2 in
944 let ips = calcips
h in
945 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
947 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
951 else x, y, max rowh
h
955 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
958 if pageno
= columns
&& conf
.presentation
960 let ips = calcips rowh
in
961 for i
= 0 to pred columns
963 let (pdimno, x, y, pdim
) = a.(i
) in
964 a.(i
) <- (pdimno, x, y+ips, pdim
)
970 fixrow (pageno
- columns
);
975 a.(pageno
) <- (pdimno, x, y, pdim
);
976 let x = x + w + xoff
*2 + conf
.interpagespace
in
977 loop (pageno
+1) pdimno pdim
x y rowh' pdims
979 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
980 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
983 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
984 let rec loop pageno
pdimno pdim
y pdims
=
985 if pageno
!= state
.pagecount
987 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
989 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
991 | _
-> pdimno, pdim
, pdims
994 let rec loop1 n
x y =
995 if n
= c then y else (
996 a.(pageno
*c + n
) <- (pdimno, x, y, pdim
);
997 loop1 (n
+1) (x+cw) (y + h + conf
.interpagespace
)
1000 let y = loop1 0 0 y in
1001 loop (pageno
+1) pdimno pdim
y pdims
1003 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1004 conf
.columns
<- Csplit
(c, a);
1008 docolumns conf
.columns
;
1009 state
.maxy <- calcheight
();
1010 if state
.reprf
== noreprf
1012 match state
.mode
with
1013 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1014 let y, h = getpageyh pageno
in
1015 let top = (state
.winh
- h) / 2 in
1016 gotoxy state
.x (max
0 (y - top))
1017 | Textentry _
| View
| LinkNav _
->
1018 let y = getanchory state
.anchor in
1019 let y = min
y (state
.maxy - state
.winh
) in
1024 state
.reprf
<- noreprf
;
1028 let reshape ?
(firsttime
=false) w h =
1029 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1030 if not firsttime
&& nogeomcmds state
.geomcmds
1031 then state
.anchor <- getanchor
();
1034 let w = truncate
(float w *. conf
.zoom
) in
1037 setfontsize fstate
.fontsize
;
1038 GlMat.mode `modelview
;
1039 GlMat.load_identity
();
1041 GlMat.mode `projection
;
1042 GlMat.load_identity
();
1043 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1044 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1045 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1050 else float state
.x /. float state
.w
1052 invalidate "geometry"
1056 then state
.x <- truncate
(relx *. float w);
1058 match conf
.columns
with
1060 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1061 | Csplit
(c, _
) -> w * c
1063 wcmd "geometry %d %d %d" w (stateh h) (FMTE.to_int conf
.fitmodel
)
1068 let len = Queue.length state
.tilelru
in
1069 let layout = lazy (if conf
.preload
1070 then preloadlayout state
.x state
.y state
.winw state
.winh
1071 else state
.layout) in
1073 if state
.memused
> conf
.memlimit
1077 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1078 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1079 let (_
, pw, ph
, _
) = getpagedim
n in
1081 && colorspace
= conf
.colorspace
1082 && angle
= conf
.angle
1086 let x = col*conf
.tilew
and y = row*conf
.tileh
in
1087 tilevisible (Lazy.force_val
layout) n x y
1089 then Queue.push lruitem state
.tilelru
1092 wcmd "freetile %s" (~
> p
);
1093 state
.memused
<- state
.memused
- s;
1094 state
.uioh#infochanged Memused
;
1095 Hashtbl.remove state
.tilemap k
;
1103 let onpagerect pageno
f =
1105 match conf
.columns
with
1106 | Cmulti
(_
, b) -> b
1108 | Csplit
(_
, b) -> b
1110 if pageno
>= 0 && pageno
< Array.length
b
1112 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1116 let gotopagexy1 pageno
x y =
1117 let _,w1
,h1
,leftx
= getpagedim pageno
in
1118 let top = y /. (float h1
) in
1119 let left = x /. (float w1
) in
1120 let py, w, h = getpageywh pageno
in
1121 let wh = state
.winh
in
1122 let x = left *. (float w) in
1123 let x = leftx
+ state
.x + truncate
x in
1125 if x < 0 || x >= state
.winw
1129 let pdy = truncate
(top *. float h) in
1130 let y'
= py + pdy in
1131 let dy = y'
- state
.y in
1133 if x != state
.x || not
(dy > 0 && dy < wh)
1135 if conf
.presentation
1137 if abs
(py - y'
) > wh
1144 if state
.x != sx || state
.y != sy
1146 else gotoxy state
.x state
.y;
1149 let gotopagexy pageno
x y =
1150 match state
.mode
with
1151 | Birdseye
_ -> gotopage pageno
0.0
1152 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 pageno
x y
1155 let getpassword () =
1156 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1161 impmsg "error getting password: %s" s;
1162 dolog
"%s" s) passcmd;
1165 let pgoto opaque pageno
x y =
1166 let pdimno = getpdimno pageno
in
1167 let x, y = project opaque pageno
pdimno x y in
1168 gotopagexy pageno
x y;
1172 (* dolog "%S" cmds; *)
1173 let spl = splitatchar cmds ' '
in
1175 try Scanf.sscanf
s fmt
f
1177 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1180 let addoutline outline
=
1181 match state
.currently
with
1182 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1183 | Idle
-> state
.currently
<- Outlining
[outline
]
1184 | Loading
_ | Tiling
_ ->
1185 dolog
"invalid outlining state";
1186 logcurrently state
.currently
1191 state
.uioh#infochanged Pdim
;
1193 | "clearrects", "" ->
1194 state
.rects
<- state
.rects1
;
1195 postRedisplay
"clearrects";
1197 | "continue", args
->
1198 let n = scan args
"%u" (fun n -> n) in
1199 state
.pagecount
<- n;
1200 begin match state
.currently
with
1202 state
.currently
<- Idle
;
1203 state
.outlines
<- Array.of_list
(List.rev l
)
1204 | Idle
| Loading
_ | Tiling
_ -> ()
1207 let cur, cmds
= state
.geomcmds
in
1209 then error
"empty geomcmd";
1211 begin match List.rev cmds
with
1213 state
.geomcmds
<- E.s, [];
1217 state
.geomcmds
<- s, List.rev rest
;
1219 postRedisplay
"continue";
1226 then showtext ' ' args
1229 Buffer.add_string state
.errmsgs args
;
1230 state
.newerrmsgs
<- true;
1231 postRedisplay
"error message"
1233 | "progress", args
->
1234 let progress, text =
1237 f, String.sub args pos
(String.length args
- pos
))
1240 state
.progress <- progress;
1241 postRedisplay
"progress"
1243 | "firstmatch", args
->
1244 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1245 scan args
"%u %d %f %f %f %f %f %f %f %f"
1246 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1247 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1249 let y = (getpagey
pageno) + truncate
y0 in
1251 if (state
.x < - truncate
x0) || (state
.x > state
.winw
- truncate
x1)
1252 then state
.winw
/2 - truncate
(x0 /. 2. +. x1 /. 2.)
1257 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1258 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1261 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1262 scan args
"%u %d %f %f %f %f %f %f %f %f"
1263 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1264 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1266 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1268 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1271 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1272 let pageopaque = ~
< pageopaques in
1273 begin match state
.currently
with
1274 | Loading
(l
, gen
) ->
1275 vlog "page %d took %f sec" l
.pageno t
;
1276 Hashtbl.replace state
.pagemap
(l
.pageno, gen
) pageopaque;
1277 let preloadedpages =
1279 then preloadlayout state
.x state
.y state
.winw state
.winh
1283 let set = List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
1284 IntSet.empty
preloadedpages
1287 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1288 if not
(IntSet.mem
pageno set)
1290 wcmd "freepage %s" (~
> opaque
);
1296 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1299 state
.currently
<- Idle
;
1302 tilepage l
.pageno pageopaque state
.layout;
1304 load preloadedpages;
1305 let visible = pagevisible state
.layout l
.pageno in
1308 match state
.mode
with
1309 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1310 if pageno = l
.pageno
1315 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1317 if dir
> 0 then LDfirst
else LDlast
1320 findlink
pageopaque ld
1325 showlinktype (getlink
pageopaque n);
1326 state
.mode
<- LinkNav
(Ltexact
(l
.pageno, n))
1328 | LinkNav
(Ltgendir
_)
1329 | LinkNav
(Ltexact
_)
1335 if visible && layoutready state
.layout
1337 postRedisplay
"page";
1341 | Idle
| Tiling
_ | Outlining
_ ->
1342 dolog
"Inconsistent loading state";
1343 logcurrently state
.currently
;
1348 let (x, y, opaques
, size
, t
) =
1349 scan args
"%u %u %s %u %f"
1350 (fun x y p size t
-> (x, y, p
, size
, t
))
1352 let opaque = ~
< opaques
in
1353 begin match state
.currently
with
1354 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1355 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
1358 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1360 wcmd "freetile %s" (~
> opaque);
1361 state
.currently
<- Idle
;
1365 puttileopaque l
col row gen cs angle
opaque size t
;
1366 state
.memused
<- state
.memused
+ size
;
1367 state
.uioh#infochanged Memused
;
1369 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
1370 opaque, size
) state
.tilelru
;
1372 state
.currently
<- Idle
;
1374 && conf
.colorspace
= cs
1375 && conf
.angle
= angle
1376 && tilevisible state
.layout l
.pageno x y
1377 then conttiling l
.pageno pageopaque;
1379 preload state
.layout;
1381 && conf
.colorspace
= cs
1382 && conf
.angle
= angle
1383 && tilevisible state
.layout l
.pageno x y
1384 && layoutready state
.layout
1385 then postRedisplay
"tile nothrottle";
1388 | Idle
| Loading
_ | Outlining
_ ->
1389 dolog
"Inconsistent tiling state";
1390 logcurrently state
.currently
;
1395 let (n, w, h, _) as pdim
=
1396 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1399 match conf
.fitmodel
with
1401 | FitPage
| FitProportional
->
1402 match conf
.columns
with
1403 | Csplit
_ -> (n, w, h, 0)
1404 | Csingle
_ | Cmulti
_ -> pdim
1406 state
.pdims
<- pdim :: state
.pdims
;
1407 state
.uioh#infochanged Pdim
1410 let (l
, n, t
, h, pos
) =
1411 scan args
"%u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
1413 let s = String.sub args pos
(String.length args
- pos
) in
1414 addoutline (s, l
, Oanchor
(n, float t
/. float h, 0.0))
1417 let (l
, len, pos
) = scan args
"%u %u %n" (fun l
len pos
-> l
, len, pos
) in
1418 let s = String.sub args pos
len in
1419 let pos2 = pos
+ len + 1 in
1420 let uri = String.sub args
pos2 (String.length args
- pos2) in
1421 addoutline (s, l
, Ouri
uri)
1424 let (l
, pos
) = scan args
"%u %n" (fun l pos
-> l
, pos
) in
1425 let s = String.sub args pos
(String.length args
- pos
) in
1426 addoutline (s, l
, Onone
)
1429 let (n, l
, t
) = scan args
"%u %d %d" (fun n l t
-> n, l
, t
) in
1430 state
.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
1433 let c, v
= splitatchar args '
\t'
in
1440 if not
!ignoredoctitlte
1441 then Wsi.settitle v
;
1445 if let len = String.length
c in
1446 len > 6 && ((String.sub
c (len-4) 4) = "date")
1448 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1450 let b = Buffer.create
10 in
1451 Printf.bprintf
b "%s\t" c;
1454 Buffer.add_substring
b v p l
;
1455 Buffer.add_char
b c;
1456 with exn
-> Buffer.add_string
b @@ exntos exn
1464 Buffer.add_char
b '
['
;
1465 Buffer.add_string
b v
;
1466 Buffer.add_char
b '
]'
;
1473 state
.docinfo
<- (1, s) :: state
.docinfo
1476 state
.docinfo
<- List.rev state
.docinfo
;
1477 state
.uioh#infochanged Docinfo
1481 then Wsi.settitle
"Wrong password";
1482 let password = getpassword () in
1483 if emptystr
password
1484 then error
"document is password protected"
1485 else opendoc state
.path
password
1487 | _ -> error
"unknown cmd `%S'" cmds
1492 let action = function
1493 | HCprev
-> cbget cb ~
-1
1494 | HCnext
-> cbget cb
1
1495 | HCfirst
-> cbget cb ~
-(cb
.rc)
1496 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1497 and cancel
() = cb
.rc <- rc
1501 let search pattern forward
=
1502 match conf
.columns
with
1503 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1504 | Csingle
_ | Cmulti
_ ->
1505 if nonemptystr pattern
1508 match state
.layout with
1510 | l
:: _ -> l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
1512 wcmd "search %d %d %d %d,%s\000"
1513 (btod conf
.icase
) pn py (btod forward
) pattern
;
1516 let intentry text key =
1518 if emptystr
text && key = Keys.Ascii '
-'
1519 then addchar
text '
-'
1521 match [@warning
"-4"] key with
1522 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1524 state
.text <- "invalid key";
1534 let l = String.length
s in
1535 let rec loop pos
n =
1539 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1540 loop (pos
+1) (n*26 + m)
1543 let rec loop n = function
1546 match getopaque l.pageno with
1547 | None
-> loop n rest
1549 let m = getlinkcount
opaque in
1552 let under = getlink
opaque n in
1555 else loop (n-m) rest
1557 loop n state
.layout;
1561 let linknentry text key = match [@warning
"-4"] key with
1563 let text = addchar
text c in
1564 linknact (fun under -> state
.text <- undertext under) text;
1567 state
.text <- Printf.sprintf
"invalid key";
1571 let textentry text key = match [@warning
"-4"] key with
1572 | Keys.Ascii
c -> TEcont
(addchar
text c)
1573 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1577 let reqlayout angle fitmodel
=
1578 if nogeomcmds state
.geomcmds
1579 then state
.anchor <- getanchor
();
1580 conf
.angle
<- angle
mod 360;
1583 match state
.mode
with
1584 | LinkNav
_ -> state
.mode
<- View
1585 | Birdseye
_ | Textentry
_ | View
-> ()
1587 conf
.fitmodel
<- fitmodel
;
1588 invalidate "reqlayout"
1590 wcmd "reqlayout %d %d %d"
1591 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1595 let settrim trimmargins trimfuzz
=
1596 if nogeomcmds state
.geomcmds
1597 then state
.anchor <- getanchor
();
1598 conf
.trimmargins
<- trimmargins
;
1599 conf
.trimfuzz
<- trimfuzz
;
1600 let x0, y0, x1, y1 = trimfuzz
in
1601 invalidate "settrim"
1602 (fun () -> wcmd "settrim %d %d %d %d %d"
1603 (btod conf
.trimmargins
) x0 y0 x1 y1);
1608 let zoom = max
0.0001 zoom in
1609 if zoom <> conf
.zoom
1611 state
.prevzoom
<- (conf
.zoom, state
.x);
1613 reshape state
.winw state
.winh
;
1614 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
1618 let pivotzoom ?
(vw=min state
.w state
.winw
)
1619 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
1620 ?
(x=vw/2) ?
(y=vh
/2) zoom =
1621 let w = float state
.w /. zoom in
1622 let hw = w /. 2.0 in
1623 let ratio = float vh
/. float vw in
1624 let hh = hw *. ratio in
1625 let x0 = float x -. hw
1626 and y0 = float y -. hh in
1627 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
1631 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
1632 if nogeomcmds state
.geomcmds
1635 then pivotzoom ?
vw ?vh ?
x ?
y zoom
1639 let setcolumns mode columns coverA coverB
=
1640 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
1644 then impmsg "split mode doesn't work in bird's eye"
1646 conf
.columns
<- Csplit
(-columns
, E.a);
1654 conf
.columns
<- Csingle
E.a;
1659 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
1663 reshape state
.winw state
.winh
;
1666 let resetmstate () =
1667 state
.mstate
<- Mnone
;
1668 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
1671 let enterbirdseye () =
1672 let zoom = float conf
.thumbw
/. float state
.winw
in
1673 let birdseyepageno =
1674 let cy = state
.winh
/ 2 in
1678 let rec fold best
= function
1681 let d = cy - (l.pagedispy + l.pagevh/2)
1682 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
1683 if abs
d < abs dbest
1692 { conf
with zoom = conf
.zoom },
1693 state
.x, birdseyepageno, -1, getanchor
()
1697 conf
.presentation
<- false;
1698 conf
.interpagespace
<- 10;
1699 conf
.hlinks
<- false;
1700 conf
.fitmodel
<- FitPage
;
1703 match conf
.beyecolumns
with
1706 Cmulti
((c, 0, 0), E.a)
1707 | None
-> Csingle
E.a
1711 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1713 else state
.text <- E.s;
1714 reshape state
.winw state
.winh
;
1717 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1719 conf
.zoom <- c.zoom;
1720 conf
.presentation
<- c.presentation
;
1721 conf
.interpagespace
<- c.interpagespace
;
1722 conf
.hlinks
<- c.hlinks
;
1723 conf
.fitmodel
<- c.fitmodel
;
1724 conf
.beyecolumns
<- (
1725 match conf
.columns
with
1726 | Cmulti
((c, _, _), _) -> Some
c
1728 | Csplit
_ -> error
"leaving bird's eye split mode"
1731 match c.columns
with
1732 | Cmulti
(c, _) -> Cmulti
(c, E.a)
1733 | Csingle
_ -> Csingle
E.a
1734 | Csplit
(c, _) -> Csplit
(c, E.a)
1738 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1740 reshape state
.winw state
.winh
;
1741 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
1745 let togglebirdseye () =
1746 match state
.mode
with
1747 | Birdseye vals
-> leavebirdseye vals
true
1748 | View
-> enterbirdseye ()
1749 | Textentry
_ | LinkNav
_ -> ()
1752 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1753 let pageno = max
0 (pageno - incr
) in
1754 let rec loop = function
1755 | [] -> gotopage1 pageno 0
1756 | l :: _ when l.pageno = pageno ->
1757 if l.pagedispy >= 0 && l.pagey = 0
1758 then postRedisplay
"upbirdseye"
1759 else gotopage1 pageno 0
1760 | _ :: rest
-> loop rest
1764 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
1767 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1768 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
1769 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
1770 let rec loop = function
1772 let y, h = getpageyh
pageno in
1773 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
1774 gotoxy state
.x (clamp dy)
1775 | l :: _ when l.pageno = pageno ->
1776 if l.pagevh != l.pageh
1777 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
1778 else postRedisplay
"downbirdseye"
1779 | _ :: rest
-> loop rest
1785 let optentry mode
_ key =
1786 let btos b = if b then "on" else "off" in
1787 match [@warning
"-4"] key with
1791 let n, a, b = multicolumns_of_string
s in
1792 setcolumns mode
n a b;
1794 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
1796 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
1801 let zoom = float (int_of_string
s) /. 100.0 in
1804 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1806 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
1809 conf
.icase
<- not conf
.icase
;
1810 TEdone
("case insensitive search " ^
(btos conf
.icase
))
1813 conf
.verbose
<- not conf
.verbose
;
1814 TEdone
("verbose " ^
(btos conf
.verbose
))
1817 conf
.debug
<- not conf
.debug
;
1818 TEdone
("debug " ^
(btos conf
.debug
))
1821 conf
.underinfo
<- not conf
.underinfo
;
1822 TEdone
("underinfo " ^
btos conf
.underinfo
)
1825 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
1826 TEdone
("trim margins " ^
btos conf
.trimmargins
)
1829 conf
.invert
<- not conf
.invert
;
1830 TEdone
("invert colors " ^
btos conf
.invert
)
1834 cbput state
.hists
.sel
s;
1837 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
1838 textentry, ondone, true)
1842 then conf
.pax
<- Some
0.0
1843 else conf
.pax
<- None
;
1844 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
1847 state
.text <- Printf.sprintf
"bad option %d `%c'" (Char.code
c) c;
1850 | _ -> TEcont state
.text
1853 let adderrmsg src msg
=
1854 Buffer.add_string state
.errmsgs msg
;
1855 state
.newerrmsgs
<- true;
1859 let adderrfmt src fmt
= Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;;
1861 class outlinelistview ~zebra ~source
=
1862 let settext autonarrow
s =
1865 let ss = source#statestr
in
1869 else "{" ^
ss ^
"} [" ^
s ^
"]"
1870 else state
.text <- s
1876 ~source
:(source
:> lvsource
)
1878 ~modehash
:(findkeyhash conf
"outline")
1881 val m_autonarrow
= false
1883 method! key key mask
=
1885 if emptystr state
.text
1887 else fstate
.maxrows - 2
1889 let calcfirst first active
=
1892 let rows = active
- first
in
1893 if rows > maxrows then active
- maxrows else first
1897 let active = m_active
+ incr
in
1898 let active = bound
active 0 (source#getitemcount
- 1) in
1899 let first = calcfirst m_first
active in
1900 postRedisplay
"outline navigate";
1901 coe
{< m_active
= active; m_first
= first >}
1903 let navscroll first =
1905 let dist = m_active
- first in
1911 else first + maxrows
1914 postRedisplay
"outline navscroll";
1915 coe
{< m_first
= first; m_active
= active >}
1917 let ctrl = Wsi.withctrl mask
in
1919 match Wsi.kc2kt
key with
1920 | Ascii '
a'
when ctrl ->
1928 let pattern = source#renarrow
in
1929 if nonemptystr m_qsearch
1930 then (source#narrow m_qsearch
; m_qsearch
)
1934 settext (not m_autonarrow
) text;
1935 postRedisplay
"toggle auto narrowing";
1936 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
1938 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
1940 postRedisplay
"toggle auto narrowing";
1941 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
1943 | Ascii '
n'
when ctrl ->
1944 source#narrow m_qsearch
;
1946 then source#add_narrow_pattern m_qsearch
;
1947 postRedisplay
"outline ctrl-n";
1948 coe
{< m_first
= 0; m_active
= 0 >}
1950 | Ascii 'S'
when ctrl ->
1951 let active = source#calcactive
(getanchor
()) in
1952 let first = firstof m_first
active in
1953 postRedisplay
"outline ctrl-s";
1954 coe
{< m_first
= first; m_active
= active >}
1956 | Ascii 'u'
when ctrl ->
1957 postRedisplay
"outline ctrl-u";
1958 if m_autonarrow
&& nonemptystr m_qsearch
1960 ignore
(source#renarrow
);
1961 settext m_autonarrow
E.s;
1962 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1965 source#del_narrow_pattern
;
1966 let pattern = source#renarrow
in
1968 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
1970 settext m_autonarrow
text;
1971 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1974 | Ascii '
l'
when ctrl ->
1975 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
1976 postRedisplay
"outline ctrl-l";
1977 coe
{< m_first
= first >}
1979 | Ascii '
\t'
when m_autonarrow
->
1980 if nonemptystr m_qsearch
1982 postRedisplay
"outline list view tab";
1983 source#add_narrow_pattern m_qsearch
;
1985 coe
{< m_qsearch
= E.s >}
1989 | Escape
when m_autonarrow
->
1990 if nonemptystr m_qsearch
1991 then source#add_narrow_pattern m_qsearch
;
1994 | Enter
when m_autonarrow
->
1995 if nonemptystr m_qsearch
1996 then source#add_narrow_pattern m_qsearch
;
1999 | (Ascii
_ | Code
_) when m_autonarrow
->
2000 let pattern = m_qsearch ^ toutf8
key in
2001 postRedisplay
"outlinelistview autonarrow add";
2002 source#narrow
pattern;
2003 settext true pattern;
2004 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2006 | Backspace
when m_autonarrow
->
2007 if emptystr m_qsearch
2010 let pattern = withoutlastutf8 m_qsearch
in
2011 postRedisplay
"outlinelistview autonarrow backspace";
2012 ignore
(source#renarrow
);
2013 source#narrow
pattern;
2014 settext true pattern;
2015 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2017 | Up
when ctrl -> navscroll (max
0 (m_first
- 1))
2020 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
2022 | Up
-> navigate ~
-1
2023 | Down
-> navigate 1
2024 | Prior
-> navigate ~
-(fstate
.maxrows)
2025 | Next
-> navigate fstate
.maxrows
2031 postRedisplay
"outline ctrl right";
2032 {< m_pan
= m_pan
+ 1 >}
2034 else self#updownlevel
1
2042 postRedisplay
"outline ctrl left";
2043 {< m_pan
= m_pan
- 1 >}
2045 else self#updownlevel ~
-1
2050 postRedisplay
"outline home";
2051 coe
{< m_first
= 0; m_active
= 0 >}
2054 let active = source#getitemcount
- 1 in
2055 let first = max
0 (active - fstate
.maxrows) in
2056 postRedisplay
"outline end";
2057 coe
{< m_active
= active; m_first
= first >}
2059 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
2063 let genhistoutlines () =
2065 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
2066 compare c2
.lastvisit c1
.lastvisit
)
2067 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
2068 let path = if nonemptystr origin
then origin
else path in
2069 let base = mbtoutf8
@@ Filename.basename
path in
2070 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
2074 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
2075 Config.save
leavebirdseye;
2076 state
.anchor <- anchor;
2077 state
.bookmarks
<- bookmarks
;
2078 state
.origin
<- origin
;
2081 let x0, y0, x1, y1 = conf
.trimfuzz
in
2082 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
2083 reshape ~firsttime
:true state
.winw state
.winh
;
2084 opendoc path origin
;
2088 let setcheckers enabled
=
2089 match !checkerstexid with
2090 | None
-> if enabled
then checkerstexid := Some
(makecheckers
())
2095 GlTex.delete_texture id
;
2096 checkerstexid := None
;
2100 let describe_layout layout =
2104 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
2107 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
2108 else Printf.sprintf
"%d%s%d" (a.pageno+1)
2109 (if a.pageno+1 = b.pageno then ", " else Utf8syms.ellipsis
)
2112 let rec fold s la lb
= function
2113 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
2114 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
2115 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
2117 fold "Pages" l l rest
2120 let maxy = maxy () in
2123 else 100. *. (float state
.y /. float maxy)
2125 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
2128 let setpresentationmode v
=
2129 let n = page_of_y state
.y in
2130 state
.anchor <- (n, 0.0, 1.0);
2131 conf
.presentation
<- v
;
2132 if conf
.fitmodel
= FitPage
2133 then reqlayout conf
.angle conf
.fitmodel
;
2138 let btos b = if b then Utf8syms.radical
else E.s in
2139 let showextended = ref false in
2140 let showcolors = ref false in
2141 let leave mode
_ = state
.mode
<- mode
in
2144 val mutable m_l
= []
2145 val mutable m_a
= E.a
2146 val mutable m_prev_uioh
= nouioh
2147 val mutable m_prev_mode
= View
2149 inherit lvsourcebase
2151 method reset prev_mode prev_uioh
=
2152 m_a
<- Array.of_list
(List.rev m_l
);
2154 m_prev_mode
<- prev_mode
;
2155 m_prev_uioh
<- prev_uioh
;
2157 method int name get
set =
2163 try set (int_of_string
s)
2165 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2169 let te = name ^
": ", E.s, None
, intentry, ondone, true in
2170 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2174 method int_with_suffix name get
set =
2176 (name
, `intws get
, 1,
2180 try set (int_of_string_with_suffix
s)
2182 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2187 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
2189 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2193 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2195 (name
, `
bool (btos, get
), offset
, Action
(
2202 method color name get
set =
2204 (name
, `
color get
, 1,
2207 let invalid = (nan
, nan
, nan
) in
2210 try color_of_string
s
2212 state
.text <- Printf.sprintf
"bad color `%s': %s"
2219 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2220 state
.text <- color_to_string
(get
());
2221 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2225 method string name get
set =
2227 (name
, `
string get
, 1,
2230 let ondone s = set s in
2231 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2232 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2236 method colorspace name get
set =
2238 (name
, `
string get
, 1,
2243 inherit lvsourcebase
2246 m_active
<- CSTE.to_int conf
.colorspace
;
2249 method getitemcount
=
2250 Array.length
CSTE.names
2253 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2254 ignore
(uioh
, first, pan
);
2255 if not cancel
then set active;
2257 method hasaction
_ = true
2261 let modehash = findkeyhash conf
"info" in
2262 coe
(new listview ~zebra
:false ~helpmode
:false
2263 ~
source ~trusted
:true ~
modehash)
2266 method paxmark name get
set =
2268 (name
, `
string get
, 1,
2273 inherit lvsourcebase
2276 m_active
<- MTE.to_int conf
.paxmark
;
2279 method getitemcount
= Array.length
MTE.names
2280 method getitem
n = (MTE.names
.(n), 0)
2281 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2282 ignore
(uioh
, first, pan
);
2283 if not cancel
then set active;
2285 method hasaction
_ = true
2289 let modehash = findkeyhash conf
"info" in
2290 coe
(new listview ~zebra
:false ~helpmode
:false
2291 ~
source ~trusted
:true ~
modehash)
2294 method fitmodel name get
set =
2296 (name
, `
string get
, 1,
2301 inherit lvsourcebase
2304 m_active
<- FMTE.to_int conf
.fitmodel
;
2307 method getitemcount
= Array.length
FMTE.names
2308 method getitem
n = (FMTE.names
.(n), 0)
2309 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2310 ignore
(uioh
, first, pan
);
2311 if not cancel
then set active;
2313 method hasaction
_ = true
2317 let modehash = findkeyhash conf
"info" in
2318 coe
(new listview ~zebra
:false ~helpmode
:false
2319 ~
source ~trusted
:true ~
modehash)
2322 method caption
s offset
=
2323 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
2325 method caption2
s f offset
=
2326 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
2328 method getitemcount
= Array.length m_a
2331 let tostr = function
2332 | `
int f -> string_of_int
(f ())
2333 | `intws
f -> string_with_suffix_of_int
(f ())
2335 | `
color f -> color_to_string
(f ())
2336 | `
bool (btos, f) -> btos (f ())
2339 let name, t
, offset
, _ = m_a
.(n) in
2340 ((let s = tostr t
in
2342 then Printf.sprintf
"%s\t%s" name s
2346 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2351 match m_a
.(active) with
2352 | _, _, _, Action
f -> f uioh
2353 | _, _, _, Noaction
-> uioh
2364 method hasaction
n =
2366 | _, _, _, Action
_ -> true
2367 | _, _, _, Noaction
-> false
2369 initializer m_active
<- 1
2372 let rec fillsrc prevmode prevuioh
=
2373 let sep () = src#caption
E.s 0 in
2374 let colorp name get
set =
2376 (fun () -> color_to_string
(get
()))
2378 try set @@ color_of_string
v
2381 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2384 let rgba name get
set =
2386 (fun () -> get
() |> rgba_to_string
)
2388 try set @@ rgba_of_string
v
2391 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2394 let oldmode = state
.mode
in
2395 let birdseye = isbirdseye state
.mode
in
2397 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
2399 src#
bool "presentation mode"
2400 (fun () -> conf
.presentation
)
2401 (fun v -> setpresentationmode v);
2403 src#
bool "ignore case in searches"
2404 (fun () -> conf
.icase
)
2405 (fun v -> conf
.icase
<- v);
2408 (fun () -> conf
.preload)
2409 (fun v -> conf
.preload <- v);
2411 src#
bool "highlight links"
2412 (fun () -> conf
.hlinks
)
2413 (fun v -> conf
.hlinks
<- v);
2415 src#
bool "under info"
2416 (fun () -> conf
.underinfo
)
2417 (fun v -> conf
.underinfo
<- v);
2419 src#fitmodel
"fit model"
2420 (fun () -> FMTE.to_string conf
.fitmodel
)
2421 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
2423 src#
bool "trim margins"
2424 (fun () -> conf
.trimmargins
)
2425 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
2428 src#
int "inter-page space"
2429 (fun () -> conf
.interpagespace
)
2431 conf
.interpagespace
<- n;
2432 docolumns conf
.columns
;
2434 match state
.layout with
2436 | l :: _ -> l.pageno, l.pagey
2438 state
.maxy <- calcheight
();
2439 let y = getpagey
pageno in
2440 gotoxy state
.x (y + py)
2444 (fun () -> conf
.pagebias
)
2445 (fun v -> conf
.pagebias
<- v);
2447 src#
int "scroll step"
2448 (fun () -> conf
.scrollstep
)
2449 (fun n -> conf
.scrollstep
<- n);
2451 src#
int "horizontal scroll step"
2452 (fun () -> conf
.hscrollstep
)
2453 (fun v -> conf
.hscrollstep
<- v);
2455 src#
int "auto scroll step"
2457 match state
.autoscroll
with
2459 | _ -> conf
.autoscrollstep
)
2461 let n = boundastep state
.winh
n in
2462 if state
.autoscroll
<> None
2463 then state
.autoscroll
<- Some
n;
2464 conf
.autoscrollstep
<- n);
2467 (fun () -> truncate
(conf
.zoom *. 100.))
2468 (fun v -> pivotzoom ((float v) /. 100.));
2471 (fun () -> conf
.angle
)
2472 (fun v -> reqlayout v conf
.fitmodel
);
2474 src#
int "scroll bar width"
2475 (fun () -> conf
.scrollbw
)
2478 reshape state
.winw state
.winh
;
2481 src#
int "scroll handle height"
2482 (fun () -> conf
.scrollh
)
2483 (fun v -> conf
.scrollh
<- v;);
2485 src#
int "thumbnail width"
2486 (fun () -> conf
.thumbw
)
2488 conf
.thumbw
<- min
4096 v;
2491 leavebirdseye beye
false;
2498 let mode = state
.mode in
2499 src#
string "columns"
2501 match conf
.columns
with
2503 | Cmulti
(multi
, _) -> multicolumns_to_string multi
2504 | Csplit
(count
, _) -> "-" ^ string_of_int count
2507 let n, a, b = multicolumns_of_string
v in
2508 setcolumns mode n a b);
2511 src#caption
"Pixmap cache" 0;
2512 src#int_with_suffix
"size (advisory)"
2513 (fun () -> conf
.memlimit
)
2514 (fun v -> conf
.memlimit
<- v);
2518 Printf.sprintf
"%s bytes, %d tiles"
2519 (string_with_suffix_of_int state
.memused
)
2520 (Hashtbl.length state
.tilemap
)) 1;
2523 src#caption
"Layout" 0;
2524 src#caption2
"Dimension"
2525 (fun () -> Printf.sprintf
"%dx%d (virtual %dx%d)"
2526 state
.winw state
.winh
2530 then src#caption2
"Position" (fun () ->
2531 Printf.sprintf
"%dx%d" state
.x state
.y
2533 else src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
2536 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
2537 "Save these parameters as global defaults at exit"
2538 (fun () -> conf
.bedefault
)
2539 (fun v -> conf
.bedefault
<- v);
2542 let btos b = Utf8syms.(if b then lguillemet
else rguillemet
) in
2543 src#
bool ~offset
:0 ~
btos "Extended parameters"
2544 (fun () -> !showextended)
2545 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
2549 (fun () -> conf
.checkers
)
2550 (fun v -> conf
.checkers
<- v; setcheckers v);
2551 src#
bool "update cursor"
2552 (fun () -> conf
.updatecurs
)
2553 (fun v -> conf
.updatecurs
<- v);
2554 src#
bool "scroll-bar on the left"
2555 (fun () -> conf
.leftscroll
)
2556 (fun v -> conf
.leftscroll
<- v);
2558 (fun () -> conf
.verbose
)
2559 (fun v -> conf
.verbose
<- v);
2560 src#
bool "invert colors"
2561 (fun () -> conf
.invert
)
2562 (fun v -> conf
.invert
<- v);
2564 (fun () -> conf
.maxhfit
)
2565 (fun v -> conf
.maxhfit
<- v);
2567 (fun () -> conf
.pax
!= None
)
2570 then conf
.pax
<- Some
(now
())
2571 else conf
.pax
<- None
);
2572 src#
string "uri launcher"
2573 (fun () -> conf
.urilauncher
)
2574 (fun v -> conf
.urilauncher
<- v);
2575 src#
string "path launcher"
2576 (fun () -> conf
.pathlauncher
)
2577 (fun v -> conf
.pathlauncher
<- v);
2578 src#
string "tile size"
2579 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
2582 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
2583 conf
.tilew
<- max
64 w;
2584 conf
.tileh
<- max
64 h;
2587 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
2590 src#
int "texture count"
2591 (fun () -> conf
.texcount
)
2594 then conf
.texcount
<- v
2595 else impmsg "failed to set texture count please retry later"
2597 src#
int "slice height"
2598 (fun () -> conf
.sliceheight
)
2600 conf
.sliceheight
<- v;
2601 wcmd "sliceh %d" conf
.sliceheight
;
2603 src#
int "anti-aliasing level"
2604 (fun () -> conf
.aalevel
)
2606 conf
.aalevel
<- bound
v 0 8;
2607 state
.anchor <- getanchor
();
2608 opendoc state
.path state
.password;
2610 src#
string "page scroll scaling factor"
2611 (fun () -> string_of_float conf
.pgscale)
2613 try conf
.pgscale <- float_of_string
v
2616 Printf.sprintf
"bad page scroll scaling factor `%s': %s" v
2619 src#
int "ui font size"
2620 (fun () -> fstate
.fontsize
)
2621 (fun v -> setfontsize (bound
v 5 100));
2622 src#
int "hint font size"
2623 (fun () -> conf
.hfsize
)
2624 (fun v -> conf
.hfsize
<- bound
v 5 100);
2625 src#
string "trim fuzz"
2626 (fun () -> irect_to_string conf
.trimfuzz
)
2629 conf
.trimfuzz
<- irect_of_string
v;
2631 then settrim true conf
.trimfuzz
;
2633 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
2636 src#
string "selection command"
2637 (fun () -> conf
.selcmd
)
2638 (fun v -> conf
.selcmd
<- v);
2639 src#
string "synctex command"
2640 (fun () -> conf
.stcmd
)
2641 (fun v -> conf
.stcmd
<- v);
2642 src#
string "pax command"
2643 (fun () -> conf
.paxcmd
)
2644 (fun v -> conf
.paxcmd
<- v);
2645 src#
string "ask password command"
2646 (fun () -> conf
.passcmd)
2647 (fun v -> conf
.passcmd <- v);
2648 src#
string "save path command"
2649 (fun () -> conf
.savecmd
)
2650 (fun v -> conf
.savecmd
<- v);
2651 src#colorspace
"color space"
2652 (fun () -> CSTE.to_string conf
.colorspace
)
2654 conf
.colorspace
<- CSTE.of_int
v;
2658 src#paxmark
"pax mark method"
2659 (fun () -> MTE.to_string conf
.paxmark
)
2660 (fun v -> conf
.paxmark
<- MTE.of_int
v);
2661 if bousable
() && !opengl_has_pbo
2664 (fun () -> conf
.usepbo
)
2665 (fun v -> conf
.usepbo
<- v);
2666 src#
bool "mouse wheel scrolls pages"
2667 (fun () -> conf
.wheelbypage
)
2668 (fun v -> conf
.wheelbypage
<- v);
2669 src#
bool "open remote links in a new instance"
2670 (fun () -> conf
.riani
)
2671 (fun v -> conf
.riani
<- v);
2672 src#
bool "edit annotations inline"
2673 (fun () -> conf
.annotinline
)
2674 (fun v -> conf
.annotinline
<- v);
2675 src#
bool "coarse positioning in presentation mode"
2676 (fun () -> conf
.coarseprespos
)
2677 (fun v -> conf
.coarseprespos
<- v);
2678 src#
bool "use document CSS"
2679 (fun () -> conf
.usedoccss
)
2681 conf
.usedoccss
<- v;
2682 state
.anchor <- getanchor
();
2683 opendoc state
.path state
.password;
2685 src#
bool ~
btos "colors"
2686 (fun () -> !showcolors)
2687 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
2690 colorp " background"
2691 (fun () -> conf
.bgcolor
)
2692 (fun v -> conf
.bgcolor
<- v);
2694 (fun () -> conf
.sbarcolor
)
2695 (fun v -> conf
.sbarcolor
<- v);
2696 rgba " scrollbar handle"
2697 (fun () -> conf
.sbarhndlcolor
)
2698 (fun v -> conf
.sbarhndlcolor
<- v);
2703 src#caption
"Document" 0;
2704 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
2705 src#caption2
"Pages"
2706 (fun () -> string_of_int state
.pagecount
) 1;
2707 src#caption2
"Dimensions"
2708 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2709 if nonemptystr conf
.css
2710 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
2714 src#caption
"Trimmed margins" 0;
2715 src#caption2
"Dimensions"
2716 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2720 src#caption
"OpenGL" 0;
2721 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
2722 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
2725 src#caption
"Location" 0;
2726 if nonemptystr state
.origin
2727 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
2728 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
2730 src#reset prevmode prevuioh
;
2735 let prevmode = state
.mode
2736 and prevuioh
= state
.uioh in
2737 fillsrc prevmode prevuioh
;
2738 let source = (src :> lvsource
) in
2739 let modehash = findkeyhash conf
"info" in
2742 inherit listview ~zebra
:false ~helpmode
:false
2743 ~
source ~trusted
:true ~
modehash as super
2744 val mutable m_prevmemused
= 0
2745 method! infochanged
= function
2747 if m_prevmemused
!= state
.memused
2749 m_prevmemused
<- state
.memused
;
2750 postRedisplay
"memusedchanged";
2752 | Pdim
-> postRedisplay
"pdimchanged"
2753 | Docinfo
-> fillsrc prevmode prevuioh
2755 method! key key mask
=
2756 if not
(Wsi.withctrl mask
)
2758 match [@warning
"-4"] Wsi.kc2kt
key with
2759 | Keys.Left
-> coe
(self#updownlevel ~
-1)
2760 | Keys.Right
-> coe
(self#updownlevel
1)
2761 | _ -> super#
key key mask
2762 else super#
key key mask
2764 postRedisplay
"info";
2770 inherit lvsourcebase
2771 method getitemcount
= Array.length state
.help
2773 let s, l, _ = state
.help
.(n) in
2776 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2780 match state
.help
.(active) with
2781 | _, _, Action
f -> Some
(f uioh)
2782 | _, _, Noaction
-> Some
uioh
2791 method hasaction
n =
2792 match state
.help
.(n) with
2793 | _, _, Action
_ -> true
2794 | _, _, Noaction
-> false
2800 let modehash = findkeyhash conf
"help" in
2802 state
.uioh <- coe
(new listview
2803 ~zebra
:false ~helpmode
:true
2804 ~
source ~trusted
:true ~
modehash);
2805 postRedisplay
"help";
2811 inherit lvsourcebase
2812 val mutable m_items
= E.a
2814 method getitemcount
= 1 + Array.length m_items
2819 else m_items
.(n-1), 0
2821 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2826 then Buffer.clear state
.errmsgs
;
2833 method hasaction
n =
2837 state
.newerrmsgs
<- false;
2838 let l = Str.split
Utils.Re.crlf
(Buffer.contents state
.errmsgs
) in
2839 m_items
<- Array.of_list
l
2848 let source = (msgsource :> lvsource
) in
2849 let modehash = findkeyhash conf
"listview" in
2852 inherit listview ~zebra
:false ~helpmode
:false
2853 ~
source ~trusted
:false ~
modehash as super
2856 then msgsource#reset
;
2859 postRedisplay
"msgs";
2863 let editor = getenvwithdef
"EDITOR" E.s in
2867 let tmppath = Filename.temp_file
"llpp" "note" in
2870 let oc = open_out
tmppath in
2874 let execstr = editor ^
" " ^
tmppath in
2876 match spawn
execstr [] with
2878 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
2881 match Unix.waitpid
[] pid
with
2883 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
2887 | Unix.WEXITED
0 -> filecontents
tmppath
2889 impmsg "editor process(%s) exited abnormally: %d" execstr n;
2891 | Unix.WSIGNALED
n ->
2892 impmsg "editor process(%s) was killed by signal %d" execstr n;
2894 | Unix.WSTOPPED
n ->
2895 impmsg "editor(%s) process was stopped by signal %d" execstr n;
2898 match Unix.unlink
tmppath with
2900 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
2905 let enterannotmode opaque slinkindex
=
2908 inherit lvsourcebase
2909 val mutable m_text
= E.s
2910 val mutable m_items
= E.a
2912 method getitemcount
= Array.length m_items
2915 let label, _func
= m_items
.(n) in
2918 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2919 ignore
(uioh, first, pan
);
2922 let _label, func
= m_items
.(active) in
2927 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
2930 let rec split accu b i
=
2932 if p = String.length
s
2933 then (String.sub s b (p-b), unit) :: accu
2935 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
2937 let ss = if i
= 0 then E.s else String.sub s b i
in
2938 split ((ss, unit)::accu) (p+1) 0
2939 else split accu b (i
+1)
2942 wcmd "freepage %s" (~
> opaque);
2944 Hashtbl.fold (fun key opaque'
accu ->
2945 if opaque'
= opaque'
2946 then key :: accu else accu) state
.pagemap
[]
2948 List.iter
(Hashtbl.remove state
.pagemap
) keys;
2950 gotoxy state
.x state
.y
2953 delannot
opaque slinkindex
;
2956 let edit inline
() =
2961 modannot
opaque slinkindex
s;
2967 let mode = state
.mode in
2970 ("annotation: ", m_text
, None
, textentry, update, true),
2971 fun _ -> state
.mode <- mode
2976 let s = getusertext m_text
in
2981 ( "[Copy]", fun () -> selstring conf
.selcmd m_text
)
2982 :: ("[Delete]", dele)
2983 :: ("[Edit]", edit conf
.annotinline
)
2985 :: split [] 0 0 |> List.rev
|> Array.of_list
2992 let s = getannotcontents
opaque slinkindex
in
2995 let source = (msgsource :> lvsource
) in
2996 let modehash = findkeyhash conf
"listview" in
2997 state
.uioh <- coe
(object
2998 inherit listview ~zebra
:false ~helpmode
:false
2999 ~
source ~trusted
:false ~
modehash
3001 postRedisplay
"enterannotmode";
3004 let gotoremote spec
=
3005 let filename, dest
= splitatchar spec '#'
in
3006 let getpath filename =
3008 if nonemptystr
filename
3010 if Filename.is_relative
filename
3012 let dir = Filename.dirname state
.path in
3014 if Filename.is_implicit
dir
3015 then Filename.concat
(Sys.getcwd
()) dir
3018 Filename.concat
dir filename
3022 if Sys.file_exists
path
3026 let path = getpath filename in
3030 let cmd = Lazy.force_val lcmd
in
3031 match spawn
cmd with
3033 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
3035 let anchor = getanchor
() in
3036 let ranchor = state
.path, state
.password, anchor, state
.origin
in
3037 state
.origin
<- E.s;
3038 state
.ranchors
<- ranchor :: state
.ranchors
;
3041 if substratis spec
0 "page="
3043 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
3045 state
.anchor <- (pageno, 0.0, 0.0);
3046 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
3048 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
3050 state
.nameddest
<- dest
;
3051 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
3055 let gotounder = function
3056 | Ulinkuri
s when isexternallink
s ->
3057 if substratis
s 0 "file://"
3058 then gotoremote @@ String.sub s 7 (String.length
s - 7)
3059 else Help.gotouri conf
.urilauncher
s
3061 let pageno, x, y = uritolocation
s in
3063 gotopagexy pageno x y
3064 | Utext
_ | Unone
-> ()
3065 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
3068 let gotooutline (_, _, kind
) =
3072 let (pageno, y, _) = anchor in
3074 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3078 | Ouri
uri -> gotounder (Ulinkuri
uri)
3079 | Olaunch
cmd -> error
"gotounder (Ulaunch %S)" cmd
3080 | Oremote
(remote
, pageno) ->
3081 error
"gotounder (Uremote (%S,%d) )" remote
pageno
3082 | Ohistory hist
-> gotohist hist
3083 | Oremotedest
(path, dest
) ->
3084 error
"gotounder (Uremotedest (%S, %S))" path dest
3087 class outlinesoucebase fetchoutlines
= object (self
)
3088 inherit lvsourcebase
3089 val mutable m_items
= E.a
3090 val mutable m_minfo
= E.a
3091 val mutable m_orig_items
= E.a
3092 val mutable m_orig_minfo
= E.a
3093 val mutable m_narrow_patterns
= []
3094 val mutable m_gen
= -1
3096 method getitemcount
= Array.length m_items
3099 let s, n, _ = m_items
.(n) in
3102 method exit ~
(uioh:uioh) ~cancel ~
active ~
(first:int) ~pan
: uioh option =
3103 ignore
(uioh, first);
3105 if m_narrow_patterns
= []
3106 then m_orig_items
, m_orig_minfo
3107 else m_items
, m_minfo
3114 gotooutline m_items
.(active);
3122 method hasaction
(_:int) = true
3125 if Array.length m_items
!= Array.length m_orig_items
3128 match m_narrow_patterns
with
3130 | many
-> String.concat
Utf8syms.ellipsis
(List.rev many
)
3132 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3136 match m_narrow_patterns
with
3139 | head
:: _ -> Utf8syms.ellipsis ^ head
3141 method narrow
pattern =
3142 match Str.regexp_case_fold
pattern with
3145 let rec loop accu minfo
n =
3148 m_items
<- Array.of_list
accu;
3149 m_minfo
<- Array.of_list minfo
;
3152 let (s, _, _) as o = m_items
.(n) in
3154 match Str.search_forward re
s 0 with
3155 | exception Not_found
-> accu, minfo
3156 | first -> o :: accu, (first, Str.match_end
()) :: minfo
3158 loop accu minfo
(n-1)
3160 loop [] [] (Array.length m_items
- 1)
3162 method! getminfo
= m_minfo
3165 m_orig_items
<- fetchoutlines
();
3166 m_minfo
<- m_orig_minfo
;
3167 m_items
<- m_orig_items
3169 method add_narrow_pattern
pattern =
3170 m_narrow_patterns
<- pattern :: m_narrow_patterns
3172 method del_narrow_pattern
=
3173 match m_narrow_patterns
with
3174 | _ :: rest
-> m_narrow_patterns
<- rest
3179 match m_narrow_patterns
with
3180 | pattern :: [] -> self#narrow
pattern; pattern
3182 List.fold_left
(fun accu pattern ->
3183 self#narrow
pattern;
3184 pattern ^
Utf8syms.ellipsis ^
accu) E.s list
3186 method calcactive
(_:anchor) = 0
3188 method reset
anchor items =
3189 if state
.gen
!= m_gen
3191 m_orig_items
<- items;
3193 m_narrow_patterns
<- [];
3195 m_orig_minfo
<- E.a;
3199 if items != m_orig_items
3201 m_orig_items
<- items;
3202 if m_narrow_patterns
== []
3203 then m_items
<- items;
3206 let active = self#calcactive
anchor in
3208 m_first
<- firstof m_first
active
3212 let outlinesource fetchoutlines
=
3214 inherit outlinesoucebase fetchoutlines
3215 method! calcactive
anchor =
3216 let rely = getanchory anchor in
3217 let rec loop n best bestd
=
3218 if n = Array.length m_items
3221 let _, _, kind
= m_items
.(n) in
3224 let orely = getanchory anchor in
3225 let d = abs
(orely - rely) in
3228 else loop (n+1) best bestd
3229 | Onone
| Oremote
_ | Olaunch
_
3230 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
3231 loop (n+1) best bestd
3237 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
3238 let mkselector sourcetype
=
3239 let fetchoutlines () =
3240 match sourcetype
with
3241 | `bookmarks
-> Array.of_list state
.bookmarks
3242 | `outlines
-> state
.outlines
3243 | `history
-> genhistoutlines () |> Array.of_list
3246 if sourcetype
= `history
3247 then new outlinesoucebase
fetchoutlines
3248 else outlinesource fetchoutlines
3251 let outlines = fetchoutlines () in
3252 if Array.length
outlines = 0
3253 then showtext ' ' errmsg
3256 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3257 let anchor = getanchor
() in
3258 source#reset
anchor outlines;
3259 state
.text <- source#greetmsg
;
3261 coe
(new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
3262 postRedisplay
"enter selector";
3266 let mkenter sourcetype errmsg
= fun () -> mkselector sourcetype errmsg
in
3267 ( mkenter `
outlines "document has no outline"
3268 , mkenter `bookmarks
"document has no bookmarks (yet)"
3269 , mkenter `history
"history is empty" )
3272 let quickbookmark ?title
() =
3273 match state
.layout with
3280 let tm = localtime
(now
()) in
3282 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
3284 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
3286 | Some
title -> title
3288 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3291 let setautoscrollspeed step goingdown
=
3292 let incr = max
1 ((abs step
) / 2) in
3293 let incr = if goingdown
then incr else -incr in
3294 let astep = boundastep state
.winh
(step
+ incr) in
3295 state
.autoscroll
<- Some
astep;
3299 match conf
.columns
with
3301 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
3304 let panbound x = bound
x (-state
.w) state
.winw
;;
3306 let existsinrow pageno (columns
, coverA
, coverB
) p =
3307 let last = ((pageno - coverA
) mod columns
) + columns
in
3308 let rec any = function
3311 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
3315 then (if l.pageno = last then false else any rest
)
3323 match state
.layout with
3325 let pageno = page_of_y state
.y in
3326 gotoxy state
.x (getpagey
(pageno+1))
3328 match conf
.columns
with
3330 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
3332 let y = clamp (pgscale state
.winh
) in
3335 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
3336 gotoxy state
.x (getpagey
pageno)
3337 | Cmulti
((c, _, _) as cl
, _) ->
3338 if conf
.presentation
3339 && (existsinrow l.pageno cl
3340 (fun l -> l.pageh
> l.pagey + l.pagevh))
3342 let y = clamp (pgscale state
.winh
) in
3345 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
3346 gotoxy state
.x (getpagey
pageno)
3348 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
3350 let pagey, pageh
= getpageyh
l.pageno in
3351 let pagey = pagey + pageh
* l.pagecol
in
3352 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
3353 gotoxy state
.x (pagey + pageh
+ ips)
3357 match state
.layout with
3359 let pageno = page_of_y state
.y in
3360 gotoxy state
.x (getpagey
(pageno-1))
3362 match conf
.columns
with
3364 if conf
.presentation
&& l.pagey != 0
3366 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3368 let pageno = max
0 (l.pageno-1) in
3369 gotoxy state
.x (getpagey
pageno)
3370 | Cmulti
((c, _, coverB
) as cl
, _) ->
3371 if conf
.presentation
&&
3372 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
3374 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3377 if l.pageno = state
.pagecount
- coverB
3381 let pageno = max
0 (l.pageno-decr) in
3382 gotoxy state
.x (getpagey
pageno)
3390 let pageno = max
0 (l.pageno-1) in
3391 let pagey, pageh
= getpageyh
pageno in
3394 let pagey, pageh
= getpageyh
l.pageno in
3395 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
3401 if emptystr conf
.savecmd
3402 then adderrmsg "savepath-command is empty"
3403 "don't know where to save modified document"
3405 let savecmd = Str.global_replace
Utils.Re.percent state
.path conf
.savecmd in
3409 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
3414 let tmp = path ^
".tmp" in
3416 Unix.rename
tmp path;
3419 let viewkeyboard key mask
=
3421 let mode = state
.mode in
3422 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
3425 postRedisplay
"view:enttext"
3427 let ctrl = Wsi.withctrl mask
in
3429 match Wsi.kc2kt
key with
3430 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
3432 | Ascii 'Q'
-> exit
0
3435 if hasunsavedchanges
()
3439 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
3442 match state
.lnava
with
3443 | None
-> LinkNav
(Ltgendir
0)
3444 | Some
pn -> LinkNav
(Ltexact
pn)
3446 gotoxy state
.x state
.y;
3448 else impmsg "keyboard link navigation does not work under rotation"
3450 | Escape
| Ascii 'q'
->
3451 begin match state
.mstate
with
3454 postRedisplay
"kill rect";
3457 | Mscrolly
| Mscrollx
3460 begin match state
.mode with
3463 | Ltexact pl
-> state
.lnava
<- Some pl
3464 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
3467 postRedisplay
"esc leave linknav"
3468 | Birdseye
_ | Textentry
_ | View
->
3469 match state
.ranchors
with
3471 | (path, password, anchor, origin
) :: rest
->
3472 state
.ranchors
<- rest
;
3473 state
.anchor <- anchor;
3474 state
.origin
<- origin
;
3475 state
.nameddest
<- E.s;
3476 opendoc path password
3482 gotoxy state
.x (getnav ~
-1)
3493 Hashtbl.iter
(fun _ opaque ->
3495 Hashtbl.clear state
.prects
) state
.pagemap
;
3496 postRedisplay
"dehighlight";
3498 | Ascii
(('
/'
| '?'
) as c) ->
3499 let ondone isforw
s =
3500 cbput state
.hists
.pat
s;
3501 state
.searchpattern
<- s;
3504 let s = String.make
1 c in
3505 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
3506 textentry, ondone (c = '
/'
), true)
3508 | Ascii '
+'
| Ascii '
='
when ctrl ->
3509 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3510 pivotzoom (conf
.zoom +. incr)
3515 try int_of_string
s with exn
->
3517 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3523 state
.text <- "page bias is now " ^ string_of_int
n;
3526 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
3528 | Ascii '
-'
when ctrl ->
3529 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3530 pivotzoom (max
0.01 (conf
.zoom -. decr))
3533 let ondone msg
= state
.text <- msg
in
3534 enttext ("option: ", E.s, None
,
3535 optentry state
.mode, ondone, true)
3537 | Ascii '
0'
when ctrl ->
3539 then gotoxy 0 state
.y
3542 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
3544 match conf
.columns
with
3545 | Csingle
_ | Cmulti
_ -> 1
3546 | Csplit
(n, _) -> n
3548 let h = state
.winh
-
3549 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
3551 let zoom = zoomforh state
.winw
h 0 cols in
3552 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
3555 | Ascii '
3'
when ctrl ->
3557 match conf
.fitmodel
with
3558 | FitWidth
-> FitProportional
3559 | FitProportional
-> FitPage
3560 | FitPage
-> FitWidth
3562 state
.text <- "fit model: " ^
FMTE.to_string
fm;
3563 reqlayout conf
.angle
fm
3565 | Ascii '
4'
when ctrl ->
3566 let zoom = getmaxw
() /. float state
.winw
in
3567 if zoom > 0.0 then setzoom zoom
3569 | Fn
9 | Ascii '
9'
when ctrl -> togglebirdseye ()
3571 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
3574 try int_of_string
s with exn
->
3575 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3581 cbput state
.hists
.pag
(string_of_int
n);
3582 gotopage1 (n + conf
.pagebias
- 1) 0;
3585 let pageentry text = function [@warning
"-4"]
3586 | Keys.Ascii '
g'
-> TEdone
text
3587 | key -> intentry text key
3589 let text = String.make
1 c in
3590 enttext (":", text, Some
(onhist state
.hists
.pag
),
3591 pageentry, ondone, true)
3594 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
3595 postRedisplay
"toggle scrollbar";
3598 state
.bzoom
<- not state
.bzoom
;
3600 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
3603 conf
.hlinks
<- not conf
.hlinks
;
3604 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
3605 postRedisplay
"toggle highlightlinks";
3608 if conf
.angle
mod 360 = 0
3610 state
.glinks
<- true;
3611 let mode = state
.mode in
3614 (":", E.s, None
, linknentry, linknact gotounder, false),
3616 state
.glinks
<- false;
3620 postRedisplay
"view:linkent(F)"
3622 else impmsg "hint mode does not work under rotation"
3625 state
.glinks
<- true;
3626 let mode = state
.mode in
3629 (":", E.s, None
, linknentry,
3630 linknact (fun under ->
3631 selstring conf
.selcmd
(undertext under)), false),
3633 state
.glinks
<- false;
3637 postRedisplay
"view:linkent"
3640 begin match state
.autoscroll
with
3642 conf
.autoscrollstep
<- step
;
3643 state
.autoscroll
<- None
3645 state
.autoscroll
<- Some conf
.autoscrollstep
;
3646 state
.slideshow
<- state
.slideshow
land lnot
2
3649 | Ascii '
p'
when ctrl ->
3650 launchpath () (* XXX where do error messages go? *)
3653 setpresentationmode (not conf
.presentation
);
3654 showtext ' '
("presentation mode " ^
3655 if conf
.presentation
then "on" else "off");
3658 if List.mem
Wsi.Fullscreen state
.winstate
3659 then Wsi.reshape conf
.cwinw conf
.cwinh
3660 else Wsi.fullscreen
()
3662 | Ascii
('
p'
|'N'
) ->
3663 search state
.searchpattern
false
3665 | Ascii '
n'
| Fn
3 ->
3666 search state
.searchpattern
true
3669 begin match state
.layout with
3671 | l :: _ -> gotoxy state
.x (getpagey
l.pageno)
3674 | Ascii ' '
-> nextpage ()
3675 | Delete
-> prevpage ()
3676 | Ascii '
='
-> showtext ' '
(describe_layout state
.layout);
3679 begin match state
.layout with
3682 Wsi.reshape l.pagew
l.pageh
;
3686 | Ascii '
\''
-> enterbookmarkmode
()
3687 | Ascii '
h'
| Fn
1 -> enterhelpmode ()
3688 | Ascii 'i'
-> enterinfomode ()
3689 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 -> entermsgsmode ()
3693 match state
.layout with
3694 | l :: _ when nonemptystr
s ->
3695 state
.bookmarks
<- (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3698 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
3702 showtext ' '
"Quick bookmark added";
3704 | Ascii '
x'
-> state
.roam
()
3706 | Ascii
('
<'
|'
>'
as c) ->
3707 reqlayout (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
3709 | Ascii
('
['
|'
]'
as c) ->
3711 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
3712 postRedisplay
"brightness";
3714 | Ascii '
c'
when state
.mode = View
->
3719 let m = (state
.winw
- state
.w) / 2 in
3724 match state
.prevcolumns
with
3725 | None
-> (1, 0, 0), 1.0
3726 | Some
(columns
, z
) ->
3729 | Csplit
(c, _) -> -c, 0, 0
3730 | Cmulti
((c, a, b), _) -> c, a, b
3731 | Csingle
_ -> 1, 0, 0
3735 setcolumns View
c a b;
3738 | Down
| Up
when ctrl && Wsi.withshift mask
->
3739 let zoom, x = state
.prevzoom
in
3744 begin match state
.autoscroll
with
3746 begin match state
.mode with
3747 | Birdseye beye
-> upbirdseye 1 beye
3748 | Textentry
_ | View
| LinkNav
_ ->
3750 then gotoxy state
.x (clamp ~
-(state
.winh
/2))
3752 if not
(Wsi.withshift mask
) && conf
.presentation
3754 else gotoxy state
.x (clamp (-conf
.scrollstep
))
3757 | Some
n -> setautoscrollspeed n false
3760 | Ascii 'j'
| Down
->
3761 begin match state
.autoscroll
with
3763 begin match state
.mode with
3764 | Birdseye beye
-> downbirdseye 1 beye
3765 | Textentry
_ | View
| LinkNav
_ ->
3767 then gotoxy state
.x (clamp (state
.winh
/2))
3769 if not
(Wsi.withshift mask
) && conf
.presentation
3771 else gotoxy state
.x (clamp (conf
.scrollstep
))
3774 | Some
n -> setautoscrollspeed n true
3777 | Left
| Right
when not
(Wsi.withalt mask
) ->
3783 else conf
.hscrollstep
3786 let pv = Wsi.kc2kt
key in
3787 if pv = Keys.Left
then dx else -dx
3789 gotoxy (panbound (state
.x + dx)) state
.y
3792 postRedisplay
"left/right"
3799 match state
.layout with
3801 | l :: _ -> state
.y - l.pagey
3802 else clamp (pgscale (-state
.winh
))
3810 match List.rev state
.layout with
3812 | l :: _ -> getpagey
l.pageno
3813 else clamp (pgscale state
.winh
)
3817 | Ascii '
g'
| Home
->
3820 | Ascii 'G'
| End
->
3822 gotoxy 0 (clamp state
.maxy)
3824 | Right
when Wsi.withalt mask
->
3826 gotoxy state
.x (getnav 1)
3827 | Left
when Wsi.withalt mask
->
3829 gotoxy state
.x (getnav ~
-1)
3834 | Ascii '
v'
when conf
.debug
->
3837 match getopaque l.pageno with
3840 let x0, y0, x1, y1 = pagebbox
opaque in
3841 let rect = (float x0, float y0,
3844 float x0, float y1) in
3846 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
3847 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
3852 let mode = state
.mode in
3853 let cmd = ref E.s in
3854 let onleave = function
3855 | Cancel
-> state
.mode <- mode
3858 match getopaque l.pageno with
3859 | Some
opaque -> pipesel opaque !cmd
3860 | None
-> ()) state
.layout;
3864 cbput state
.hists
.sel
s;
3868 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
3871 state
.mode <- Textentry
(te, onleave);
3873 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
3874 vlog "huh? %s" (Wsi.keyname
key)
3877 let linknavkeyboard key mask
linknav =
3878 let pv = Wsi.kc2kt
key in
3879 let getpage pageno =
3880 let rec loop = function
3882 | l :: _ when l.pageno = pageno -> Some
l
3883 | _ :: rest
-> loop rest
3884 in loop state
.layout
3886 let doexact (pageno, n) =
3887 match getopaque pageno, getpage pageno with
3888 | Some
opaque, Some
l ->
3891 let under = getlink
opaque n in
3892 postRedisplay
"link gotounder";
3899 | Home
-> Some
(findlink
opaque LDfirst
), -1
3900 | End
-> Some
(findlink
opaque LDlast
), 1
3901 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
3902 | Right
-> Some
(findlink
opaque (LDright
n)), 1
3903 | Up
-> Some
(findlink
opaque (LDup
n)), -1
3904 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
3905 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
3906 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
3909 begin match findpwl
l.pageno dir with
3913 state
.mode <- LinkNav
(Ltgendir
dir);
3914 let y, h = getpageyh
pageno in
3917 then y + h - state
.winh
3922 begin match getopaque pageno, getpage pageno with
3923 | Some
opaque, Some
_ ->
3925 let ld = if dir > 0 then LDfirst
else LDlast
in
3928 begin match link with
3930 showlinktype (getlink
opaque m);
3931 state
.mode <- LinkNav
(Ltexact
(pageno, m));
3932 postRedisplay
"linknav jpage";
3933 | Lnotfound
-> notfound dir
3939 begin match opt with
3940 | Some Lnotfound
-> pwl l dir;
3941 | Some
(Lfound
m) ->
3945 let _, y0, _, y1 = getlinkrect
opaque m in
3947 then gotopage1 l.pageno y0
3949 let d = fstate
.fontsize
+ 1 in
3950 if y1 - l.pagey > l.pagevh - d
3951 then gotopage1 l.pageno (y1 - state
.winh
+ d)
3952 else postRedisplay
"linknav";
3954 showlinktype (getlink
opaque m);
3955 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
3958 | None
-> viewkeyboard key mask
3960 | _ -> viewkeyboard key mask
3964 begin match linknav with
3965 | Ltexact pa
-> state
.lnava
<- Some pa
3966 | Ltgendir
_ | Ltnotready
_ -> ()
3969 postRedisplay
"leave linknav"
3973 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
3974 | Ltexact exact
-> doexact exact
3977 let keyboard key mask
=
3978 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
3979 then wcmd "interrupt"
3980 else state
.uioh <- state
.uioh#
key key mask
3983 let birdseyekeyboard key mask
3984 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
3986 match conf
.columns
with
3988 | Cmulti
((c, _, _), _) -> c
3989 | Csplit
_ -> error
"bird's eye split mode"
3991 let pgh layout = List.fold_left
3992 (fun m l -> max
l.pageh
m) state
.winh
layout in
3994 match Wsi.kc2kt
key with
3995 | Ascii '
l'
when Wsi.withctrl mask
->
3996 let y, h = getpageyh
pageno in
3997 let top = (state
.winh
- h) / 2 in
3998 gotoxy state
.x (max
0 (y - top))
3999 | Enter
-> leavebirdseye beye
false
4000 | Escape
-> leavebirdseye beye
true
4001 | Up
-> upbirdseye incr beye
4002 | Down
-> downbirdseye incr beye
4003 | Left
-> upbirdseye 1 beye
4004 | Right
-> downbirdseye 1 beye
4007 begin match state
.layout with
4011 state
.mode <- Birdseye
(
4012 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4014 gotopage1 l.pageno 0;
4017 let layout = layout state
.x (state
.y-state
.winh
)
4019 (pgh state
.layout) in
4021 | [] -> gotoxy state
.x (clamp (-state
.winh
))
4023 state
.mode <- Birdseye
(
4024 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4026 gotopage1 l.pageno 0
4029 | [] -> gotoxy state
.x (clamp (-state
.winh
))
4033 begin match List.rev state
.layout with
4035 let layout = layout state
.x
4036 (state
.y + (pgh state
.layout))
4037 state
.winw state
.winh
in
4038 begin match layout with
4040 let incr = l.pageh
- l.pagevh in
4045 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
4047 postRedisplay
"birdseye pagedown";
4049 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
4053 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4054 gotopage1 l.pageno 0;
4057 | [] -> gotoxy state
.x (clamp state
.winh
)
4061 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4065 let pageno = state
.pagecount
- 1 in
4066 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4067 if not
(pagevisible state
.layout pageno)
4070 match List.rev state
.pdims
with
4072 | (_, _, h, _) :: _ -> h
4076 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
4077 else postRedisplay
"birdseye end";
4079 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
4084 match state
.mode with
4085 | Textentry
_ -> scalecolor 0.4
4086 | LinkNav
_ | View
-> scalecolor 1.0
4087 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4088 if l.pageno = hooverpageno
4091 if l.pageno = pageno
4093 let c = scalecolor 1.0 in
4095 GlDraw.line_width
3.0;
4096 let dispx = l.pagedispx in
4098 (float (dispx-1)) (float (l.pagedispy-1))
4099 (float (dispx+l.pagevw+1))
4100 (float (l.pagedispy+l.pagevh+1));
4101 GlDraw.line_width
1.0;
4110 let postdrawpage l linkindexbase
=
4111 match getopaque l.pageno with
4113 if tileready l l.pagex
l.pagey
4115 let x = l.pagedispx - l.pagex
4116 and y = l.pagedispy - l.pagey in
4118 match conf
.columns
with
4119 | Csingle
_ | Cmulti
_ ->
4120 (if conf
.hlinks
then 1 else 0)
4122 && not
(isbirdseye state
.mode) then 2 else 0)
4126 match state
.mode with
4127 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
4133 Hashtbl.find_all state
.prects
l.pageno |>
4134 List.iter
(fun vals
-> drawprect
opaque x y vals
);
4135 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
4137 then (Glutils.redisplay
:= true; 0)
4143 let scrollindicator () =
4144 let sbw, ph
, sh
= state
.uioh#scrollph
in
4145 let sbh, pw, sw
= state
.uioh#scrollpw
in
4150 else ((state
.winw
- sbw), state
.winw
, 0)
4154 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4155 let (r
, g, b, alpha
) = conf
.sbarcolor
in
4156 GlDraw.color (r
, g, b) ~alpha
;
4157 filledrect
(float x0) 0. (float x1) (float state
.winh
);
4159 (float hx0
) (float (state
.winh
- sbh))
4160 (float (hx0
+ state
.winw
)) (float state
.winh
);
4161 let (r
, g, b, alpha
) = conf
.sbarhndlcolor
in
4162 GlDraw.color (r
, g, b) ~alpha
;
4164 filledrect
(float x0) ph
(float x1) (ph
+. sh
);
4165 let pw = pw +. float hx0
in
4166 filledrect
pw (float (state
.winh
- sbh)) (pw +. sw
) (float state
.winh
);
4171 match state
.mstate
with
4172 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ -> ()
4173 | Msel
((x0, y0), (x1, y1)) ->
4174 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
4175 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
4176 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
4177 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
4180 let showrects = function
4184 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4185 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4187 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4189 if l.pageno = pageno
4191 let dx = float (l.pagedispx - l.pagex
) in
4192 let dy = float (l.pagedispy - l.pagey) in
4193 let r, g, b, alpha
= c in
4194 GlDraw.color (r, g, b) ~alpha
;
4207 GlDraw.color (scalecolor2 conf
.bgcolor
);
4208 GlClear.color (scalecolor2 conf
.bgcolor
);
4209 GlClear.clear
[`
color];
4210 List.iter
drawpage state
.layout;
4212 match state
.mode with
4213 | LinkNav
(Ltexact
(pageno, linkno
)) ->
4214 begin match getopaque pageno with
4216 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
4217 let color = (0.0, 0.0, 0.5, 0.5) in
4219 (float x0, float y0,
4224 | None
-> state
.rects
4226 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
4229 | View
-> state
.rects
4232 let rec postloop linkindexbase
= function
4234 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
4235 postloop linkindexbase rest
4239 postloop 0 state
.layout;
4241 begin match state
.mstate
with
4242 | Mzoomrect
((x0, y0), (x1, y1)) ->
4244 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4245 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4246 filledrect
(float x0) (float y0) (float x1) (float y1);
4250 | Mscrolly
| Mscrollx
4259 let zoomrect x y x1 y1 =
4262 and y0 = min
y y1 in
4263 let zoom = (float state
.w) /. float (x1 - x0) in
4266 if state
.w < state
.winw
4267 then (state
.winw
- state
.w) / 2
4270 match conf
.fitmodel
with
4271 | FitWidth
| FitProportional
-> simple ()
4273 match conf
.columns
with
4275 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
4276 | Cmulti
_ | Csingle
_ -> simple ()
4278 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
4279 state
.anchor <- getanchor
();
4284 let annot inline
x y =
4285 match unproject x y with
4286 | Some
(opaque, n, ux
, uy
) ->
4288 addannot
opaque ux uy
text;
4289 wcmd "freepage %s" (~
> opaque);
4290 Hashtbl.remove state
.pagemap
(n, state
.gen
);
4292 gotoxy state
.x state
.y
4296 let ondone s = add s in
4297 let mode = state
.mode in
4298 state
.mode <- Textentry
(
4299 ("annotation: ", E.s, None
, textentry, ondone, true),
4300 fun _ -> state
.mode <- mode);
4303 postRedisplay
"annot"
4304 else add @@ getusertext E.s
4309 let g opaque l px py =
4310 match rectofblock
opaque px py with
4312 let x0 = a.(0) -. 20. in
4313 let x1 = a.(1) +. 20. in
4314 let y0 = a.(2) -. 20. in
4315 let zoom = (float state
.w) /. (x1 -. x0) in
4316 let pagey = getpagey
l.pageno in
4317 let margin = (state
.w - l.pagew
)/2 in
4318 let nx = -truncate
x0 - margin in
4319 gotoxy nx (pagey + truncate
y0);
4320 state
.anchor <- getanchor
();
4325 match conf
.columns
with
4327 impmsg "block zooming does not work properly in split columns mode"
4328 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
4332 let winw = state
.winw - 1 in
4333 let s = float x /. float winw in
4334 let destx = truncate
(float (state
.w + winw) *. s) in
4335 gotoxy (winw - destx) state
.y;
4336 state
.mstate
<- Mscrollx
;
4340 let s = float y /. float state
.winh
in
4341 let desty = truncate
(s *. float (maxy ())) in
4342 gotoxy state
.x desty;
4343 state
.mstate
<- Mscrolly
;
4346 let viewmulticlick clicks
x y mask
=
4347 let g opaque l px py =
4355 if markunder
opaque px py mark
4359 match getopaque l.pageno with
4361 | Some
opaque -> pipesel opaque cmd
4363 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
4364 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
4369 postRedisplay
"viewmulticlick";
4370 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
4374 match conf
.columns
with
4376 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
4379 let viewmouse button down
x y mask
=
4381 | n when (n == 4 || n == 5) && not down
->
4382 if Wsi.withctrl mask
4386 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4387 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4390 match state
.mstate
with
4391 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
4392 | Mzoomrect
_ | Mnone
| Mpan
_
4393 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
4395 let zoom = conf
.zoom -. incr in
4396 state
.mstate
<- Mzoom
(n, 0, (x, y));
4397 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
4398 then pivotzoom ~
x ~
y zoom
4402 match state
.autoscroll
with
4403 | Some step
-> setautoscrollspeed step
(n=4)
4405 if conf
.wheelbypage
|| conf
.presentation
4412 let incr = if n = 4 then -conf
.scrollstep
else conf
.scrollstep
in
4413 let incr = incr * 2 in
4414 let y = clamp incr in
4418 | n when (n = 6 || n = 7) && not down
&& canpan () ->
4420 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
4423 | 1 when Wsi.withshift mask
->
4424 state
.mstate
<- Mnone
;
4427 match unproject x y with
4429 | Some
(_, pageno, ux
, uy
) ->
4430 let cmd = Printf.sprintf
4432 conf
.stcmd state
.path pageno ux uy
4434 match spawn
cmd [] with
4436 impmsg "execution of synctex command(%S) failed: %S"
4437 conf
.stcmd
@@ exntos exn
4441 | 1 when Wsi.withctrl mask
->
4444 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4445 state
.mstate
<- Mpan
(x, y)
4447 else state
.mstate
<- Mnone
4452 if Wsi.withshift mask
4454 annot conf
.annotinline
x y;
4455 postRedisplay
"addannot"
4459 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4460 state
.mstate
<- Mzoomrect
(p, p)
4463 match state
.mstate
with
4464 | Mzoomrect
((x0, y0), _) ->
4465 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4466 then zoomrect x0 y0 x y
4469 postRedisplay
"kill accidental zoom rect";
4473 | Mscrolly
| Mscrollx
4475 | Mnone
-> resetmstate ()
4478 | 1 when vscrollhit
x ->
4481 let _, position
, sh
= state
.uioh#scrollph
in
4482 if y > truncate position
&& y < truncate
(position
+. sh
)
4483 then state
.mstate
<- Mscrolly
4485 else state
.mstate
<- Mnone
4487 | 1 when y > state
.winh
- hscrollh () ->
4490 let _, position
, sw
= state
.uioh#scrollpw
in
4491 if x > truncate position
&& x < truncate
(position
+. sw
)
4492 then state
.mstate
<- Mscrollx
4494 else state
.mstate
<- Mnone
4496 | 1 when state
.bzoom
-> if not down
then zoomblock x y
4499 let dest = if down
then getunder x y else Unone
in
4500 begin match dest with
4501 | Ulinkuri
_ -> gotounder dest
4502 | Unone
when down
->
4503 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4504 state
.mstate
<- Mpan
(x, y);
4505 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4506 | Unone
| Utext
_ ->
4511 state
.mstate
<- Msel
((x, y), (x, y));
4512 postRedisplay
"mouse select";
4516 match state
.mstate
with
4518 | Mzoom
_ | Mscrollx
| Mscrolly
-> state
.mstate
<- Mnone
4519 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4521 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4522 state
.mstate
<- Mnone
4523 | Msel
((x0, y0), (x1, y1)) ->
4524 let rec loop = function
4528 let a0 = l.pagedispy in
4529 let a1 = a0 + l.pagevh in
4530 let b0 = l.pagedispx in
4531 let b1 = b0 + l.pagevw in
4532 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
4533 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
4537 match getopaque l.pageno with
4540 pipef ~closew
:false "Msel"
4543 postRedisplay
"Msel") cmd
4545 dosel conf
.selcmd
();
4546 state
.roam
<- dosel conf
.paxcmd
;
4557 let birdseyemouse button down
x y mask
4558 (conf
, leftx
, _, hooverpageno
, anchor) =
4561 let rec loop = function
4564 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4565 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4567 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
4573 | _ -> viewmouse button down
x y mask
4579 method key key mask
=
4580 begin match state
.mode with
4581 | Textentry
textentry -> textentrykeyboard
key mask
textentry
4582 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
4583 | View
-> viewkeyboard key mask
4584 | LinkNav
linknav -> linknavkeyboard key mask
linknav
4588 method button button bstate
x y mask
=
4589 begin match state
.mode with
4590 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
4591 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
4596 method multiclick clicks
x y mask
=
4597 begin match state
.mode with
4598 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
4599 | Birdseye
_ | Textentry
_ -> ()
4604 begin match state
.mode with
4606 | View
| Birdseye
_ | LinkNav
_ ->
4607 match state
.mstate
with
4608 | Mzoom
_ | Mnone
-> ()
4612 state
.mstate
<- Mpan
(x, y);
4613 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4618 state
.mstate
<- Msel
(a, (x, y));
4619 postRedisplay
"motion select";
4622 let y = min state
.winh
(max
0 y) in
4626 let x = min state
.winw (max
0 x) in
4629 | Mzoomrect
(p0
, _) ->
4630 state
.mstate
<- Mzoomrect
(p0
, (x, y));
4631 postRedisplay
"motion zoomrect";
4635 method pmotion
x y =
4636 begin match state
.mode with
4637 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
4638 let rec loop = function
4640 if hooverpageno
!= -1
4642 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
4643 postRedisplay
"pmotion birdseye no hoover";
4646 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4647 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4649 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
4650 postRedisplay
"pmotion birdseye hoover";
4658 | LinkNav
_ | View
->
4659 match state
.mstate
with
4660 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
4669 let delta = now -. past
in
4672 else conf
.pax
<- Some
now
4676 method infochanged
_ = ()
4679 let maxy = maxy () in
4682 then 0.0, float state
.winh
4683 else scrollph state
.y maxy
4688 let fwinw = float (state
.winw - vscrollw
()) in
4690 let sw = fwinw /. float state
.w in
4691 let sw = fwinw *. sw in
4692 max
sw (float conf
.scrollh
)
4695 let maxx = state
.w + state
.winw in
4696 let x = state
.winw - state
.x in
4697 let percent = float x /. float maxx in
4698 (fwinw -. sw) *. percent
4700 hscrollh (), position, sw
4704 match state
.mode with
4705 | LinkNav
_ -> "links"
4706 | Textentry
_ -> "textentry"
4707 | Birdseye
_ -> "birdseye"
4710 findkeyhash conf
modename
4712 method eformsgs
= true
4713 method alwaysscrolly
= false
4714 method scroll
dx dy =
4715 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4716 gotoxy x (clamp (2 * dy));
4719 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
4722 let addrect pageno r g b a x0 y0 x1 y1 =
4723 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
4727 let cl = splitatchar cmds ' '
in
4729 try Scanf.sscanf
s fmt
f
4730 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
4733 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
4734 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
4735 s pageno r g b a x0 y0 x1 y1;
4739 let _,w1
,h1
,_ = getpagedim
pageno in
4740 let sw = float w1
/. float w
4741 and sh
= float h1
/. float h in
4745 and y1s
= y1 *. sh
in
4746 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
4747 let color = (r, g, b, a) in
4748 if conf
.verbose
then debugrect rect;
4749 state
.rects <- (pageno, color, rect) :: state
.rects;
4754 | "reload", "" -> reload ()
4756 scan args
"%u %f %f"
4758 let cmd, _ = state
.geomcmds
in
4760 then gotopagexy pageno x y
4763 gotopagexy pageno x y;
4766 state
.reprf
<- f state
.reprf
4768 | "goto1", args
-> scan args
"%u %f" gotopage
4769 | "gotor", args
-> scan args
"%S" gotoremote
4771 scan args
"%u %u %f %f %f %f"
4772 (fun pageno c x0 y0 x1 y1 ->
4773 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
4774 rectx "rect" pageno color x0 y0 x1 y1;
4777 scan args
"%u %f %f %f %f %f %f %f %f"
4778 (fun pageno r g b alpha
x0 y0 x1 y1 ->
4779 addrect pageno r g b alpha
x0 y0 x1 y1;
4780 postRedisplay
"prect"
4783 scan args
"%u %f %f"
4786 match getopaque pageno with
4787 | Some
opaque -> opaque
4790 pgoto optopaque pageno x y;
4791 let rec fixx = function
4794 if l.pageno = pageno
4795 then gotoxy (state
.x - l.pagedispx) state
.y
4800 match conf
.columns
with
4801 | Csingle
_ | Csplit
_ -> 1
4802 | Cmulti
((n, _, _), _) -> n
4804 layout 0 state
.y (state
.winw * mult) state
.winh
4808 | "activatewin", "" -> Wsi.activatewin
()
4809 | "quit", "" -> raise Quit
4812 let l = Config.keys_of_string
keys in
4813 List.iter
(fun (k
, m) -> keyboard k
m) l
4814 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
4817 | "clearrects", "" ->
4818 Hashtbl.clear state
.prects
;
4819 postRedisplay
"clearrects"
4821 adderrfmt "remote command"
4822 "error processing remote command: %S\n" cmds
;
4826 let scratch = Bytes.create
80 in
4827 let buf = Buffer.create
80 in
4829 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
4830 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
4833 if Buffer.length
buf > 0
4835 let s = Buffer.contents
buf in
4843 match Bytes.index_from
scratch ppos '
\n'
with
4844 | pos
-> if pos
>= n then -1 else pos
4845 | exception Not_found
-> -1
4849 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
4850 let s = Buffer.contents
buf in
4856 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
4862 let remoteopen path =
4863 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
4865 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
4870 let gcconfig = ref false in
4871 let trimcachepath = ref E.s in
4872 let rcmdpath = ref E.s in
4873 let pageno = ref None
in
4874 let openlast = ref false in
4875 let doreap = ref false in
4876 let csspath = ref None
in
4877 selfexec := Sys.executable_name
;
4880 [("-p", Arg.String
(fun s -> state
.password <- s),
4881 "<password> Set password");
4885 Config.fontpath
:= s;
4886 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
4888 "<path> Set path to the user interface font");
4892 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
4893 Config.confpath
:= s),
4894 "<path> Set path to the configuration file");
4896 ("-last", Arg.Set
openlast, " Open last document");
4898 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
4899 "<page-number> Jump to page");
4901 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
4902 "<path> Set path to the trim cache file");
4904 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
4905 "<named-destination> Set named destination");
4907 ("-remote", Arg.String
(fun s -> rcmdpath := s),
4908 "<path> Set path to the source of remote commands");
4910 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
4912 ("-v", Arg.Unit
(fun () ->
4914 "%s\nconfiguration file: %s\n"
4917 exit
0), " Print version and exit");
4919 ("-css", Arg.String
(fun s -> csspath := Some
s),
4920 "<path> Set path to the style sheet to use with EPUB/HTML");
4922 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
4923 "<origin> <undocumented>");
4925 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title");
4926 ("-layout-height", Arg.Set_int
layouth,
4927 "<height> layout height html/epub/etc (-1, 0, N)");
4930 (fun s -> state
.path <- s)
4931 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
4933 let histmode = emptystr state
.path && not
!openlast in
4935 if not
(Config.load !openlast)
4936 then dolog
"failed to load configuration";
4938 begin match !pageno with
4939 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
4952 val mutable m_clicks
= 0
4953 val mutable m_click_x
= 0
4954 val mutable m_click_y
= 0
4955 val mutable m_lastclicktime
= infinity
4957 method private cleanup =
4958 state
.roam
<- noroam
;
4959 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
4960 method expose
= postRedisplay
"expose"
4964 | Wsi.Unobscured
-> "unobscured"
4965 | Wsi.PartiallyObscured
-> "partiallyobscured"
4966 | Wsi.FullyObscured
-> "fullyobscured"
4968 vlog "visibility change %s" name
4969 method display = display ()
4970 method map mapped
= vlog "mapped %b" mapped
4971 method reshape w h =
4974 method mouse
b d x y m =
4975 if d && canselect ()
4978 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
4985 if abs
x - m_click_x
> 10
4986 || abs
y - m_click_y
> 10
4987 || abs_float
(t -. m_lastclicktime
) > 0.3
4989 m_clicks
<- m_clicks
+ 1;
4990 m_lastclicktime
<- t;
4994 postRedisplay
"cleanup";
4995 state
.uioh <- state
.uioh#button
b d x y m;
4997 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
5002 m_lastclicktime
<- infinity
;
5003 state
.uioh <- state
.uioh#button
b d x y m
5006 else state
.uioh <- state
.uioh#button
b d x y m
5008 state
.mpos
<- (x, y);
5009 state
.uioh <- state
.uioh#motion
x y
5010 method pmotion
x y =
5011 state
.mpos
<- (x, y);
5012 state
.uioh <- state
.uioh#pmotion
x y
5014 vlog "k=%#x m=%#x" k
m;
5015 let mascm = m land (
5016 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
5019 let x = state
.x and y = state
.y in
5021 if x != state
.x || y != state
.y then self#
cleanup
5023 match state
.keystate
with
5025 let km = k
, mascm in
5028 let modehash = state
.uioh#
modehash in
5029 try Hashtbl.find
modehash km
5031 try Hashtbl.find
(findkeyhash conf
"global") km
5032 with Not_found
-> KMinsrt
(k
, m)
5034 | KMinsrt
(k
, m) -> keyboard k
m
5035 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
5036 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
5038 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
5039 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
5040 state
.keystate
<- KSnone
5041 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
5042 state
.keystate
<- KSinto
(keys, insrt
)
5043 | KSinto
_ -> state
.keystate
<- KSnone
5046 state
.mpos
<- (x, y);
5047 state
.uioh <- state
.uioh#pmotion
x y
5048 method leave = state
.mpos
<- (-1, -1)
5049 method winstate wsl
= state
.winstate
<- wsl
5050 method quit
: '
a. '
a = raise Quit
5051 method scroll
dx dy = state
.uioh <- state
.uioh#scroll
dx dy
5052 method zoom z
x y = state
.uioh#
zoom z
x y
5053 method opendoc path =
5056 postRedisplay
"opendoc";
5057 opendoc path state
.password
5060 let wsfd, winw, winh
= Wsi.init
mu conf
.cwinw conf
.cwinh platform
in
5063 if not
@@ List.exists
GlMisc.check_extension
5064 [ "GL_ARB_texture_rectangle"
5065 ; "GL_EXT_texture_recangle"
5066 ; "GL_NV_texture_rectangle" ]
5067 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
5069 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
5071 defconf
.sliceheight
<- 1024;
5072 defconf
.texcount
<- 32;
5073 defconf
.usepbo
<- true;
5077 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
5079 dolog
"socketpair failed: %s" @@ exntos exn
;
5087 setcheckers conf
.checkers
;
5089 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
5091 begin match !csspath with
5093 | Some
"" -> conf
.css
<- E.s
5095 let css = filecontents
path in
5096 let l = String.length
css in
5098 if substratis
css (l-2) "\r\n"
5099 then String.sub css 0 (l-2)
5100 else (if css.[l-1] = '
\n'
then String.sub css 0 (l-1) else css)
5103 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
5104 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
5105 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
5107 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
5109 reshape ~firsttime
:true winw winh
;
5113 Wsi.settitle
"llpp (history)";
5117 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
5118 opendoc state
.path state
.password;
5122 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5123 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
5126 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
5127 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
5128 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
5130 | _pid
, _status
-> reap ()
5132 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
5135 ref (if nonemptystr
!rcmdpath then remoteopen !rcmdpath else None
)
5138 let rec loop deadline
=
5144 let r = [state
.ss; state
.wsfd] in
5148 | Some fd
-> fd
:: r
5152 Glutils.redisplay
:= false;
5159 if deadline
= infinity
5161 else max
0.0 (deadline
-. now)
5166 try Unix.select
r [] [] timeout
5167 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5172 match state
.autoscroll
with
5173 | Some step
when step
!= 0 ->
5174 if state
.slideshow
land 1 = 1
5176 if state
.slideshow
land 2 = 0
5177 then state
.slideshow
<- state
.slideshow
lor 2
5178 else if step
< 0 then prevpage () else nextpage ();
5179 deadline
+. (float (abs step
))
5182 let y = state
.y + step
in
5183 let fy = if conf
.maxhfit
then state
.winh
else 0 in
5186 then state
.maxy - fy
5187 else if y >= state
.maxy - fy then 0 else y
5196 let rec checkfds = function
5198 | fd
:: rest
when fd
= state
.ss ->
5199 let cmd = rcmd state
.ss in
5203 | fd
:: rest
when fd
= state
.wsfd ->
5207 | fd
:: rest
when Some fd
= !optrfd ->
5208 begin match remote fd
with
5209 | None
-> optrfd := remoteopen !rcmdpath;
5210 | opt -> optrfd := opt
5215 dolog
"select returned unknown descriptor";
5221 if deadline
= infinity
5225 match state
.autoscroll
with
5226 | Some step
when step
!= 0 -> deadline1
5232 match loop infinity
with
5234 Config.save leavebirdseye;
5235 if hasunsavedchanges
()
5237 | _ -> error
"umpossible - infinity reached"