4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
9 | Uremote
of (string * int)
10 and facename
= string;;
12 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
13 let now = Unix.gettimeofday
;;
15 type params
= (angle
* proportional
* trimparams
16 * texcount
* sliceheight
* memsize
17 * colorspace
* fontpath
)
26 and proportional
= bool
27 and trimmargins
= bool
28 and interpagespace
= int
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
44 | KMmulti
of key list
* key list
46 and keyhash
= (key
, keymap
) Hashtbl.t
49 | KSinto
of (key list
* key list
)
52 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
53 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
55 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
57 external init
: pipe
-> params
-> unit = "ml_init";;
58 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
59 external copysel
: string -> opaque
-> unit = "ml_copysel";;
60 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
61 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
62 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
63 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
64 external measurestr
: int -> string -> float = "ml_measure_string";;
65 external getmaxw
: unit -> float = "ml_getmaxw";;
66 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
67 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
68 external platform
: unit -> platform
= "ml_platform";;
69 external setaalevel
: int -> unit = "ml_setaalevel";;
70 external realloctexts
: int -> bool = "ml_realloctexts";;
71 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
73 let platform_to_string = function
74 | Punknown
-> "unknown"
78 | Pfreebsd
-> "FreeBSD"
79 | Pdragonflybsd
-> "DragonflyBSD"
80 | Popenbsd
-> "OpenBSD"
85 let platform = platform ();;
91 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
94 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
98 | Msel
of (mpos
* mpos
)
100 | Mscrolly
| Mscrollx
101 | Mzoom
of (int * int)
102 | Mzoomrect
of (mpos
* mpos
)
106 type textentry
= string * string * onhist
option * onkey
* ondone
107 and onkey
= string -> int -> te
108 and ondone
= string -> unit
109 and histcancel
= unit -> unit
110 and onhist
= ((histcmd
-> string) * histcancel
)
111 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
116 | TEswitch
of textentry
127 let bound v minv maxv
=
128 max minv
(min maxv v
);
132 { store
= Array.create n v
139 let drawstring size x y s
=
141 Gl.enable `texture_2d
;
142 ignore
(drawstr size x y s
);
144 Gl.disable `texture_2d
;
147 let drawstring1 size x y s
=
151 let drawstring2 size x y fmt
=
152 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
155 let cbcap b
= Array.length b
.store
;;
160 b
.wc
<- (b
.wc
+ 1) mod cap;
162 b
.len
<- min
(b
.len
+ 1) cap;
165 let cbempty b
= b
.len
= 0;;
167 let cbgetg b circular dir
=
171 let rc = b
.rc + dir
in
183 else max
0 (min
rc (b
.len
-1))
189 let cbget b
= cbgetg b
false;;
190 let cbgetc b
= cbgetg b
true;;
207 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
208 dolog " WxH %dx%d" l
.pagew l
.pageh
;
209 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
210 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
211 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
215 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
217 dolog " x0,y0=(% f, % f)" x0 y0
;
218 dolog " x1,y1=(% f, % f)" x1 y1
;
219 dolog " x2,y2=(% f, % f)" x2 y2
;
220 dolog " x3,y3=(% f, % f)" x3 y3
;
225 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
226 and multicol
= columncount
* covercount
* covercount
228 and columncount
= int
229 and covercount
= int;;
232 { mutable scrollbw
: int
233 ; mutable scrollh
: int
234 ; mutable icase
: bool
235 ; mutable preload
: bool
236 ; mutable pagebias
: int
237 ; mutable verbose
: bool
238 ; mutable debug
: bool
239 ; mutable scrollstep
: int
240 ; mutable maxhfit
: bool
241 ; mutable crophack
: bool
242 ; mutable autoscrollstep
: int
243 ; mutable maxwait
: float option
244 ; mutable hlinks
: bool
245 ; mutable underinfo
: bool
246 ; mutable interpagespace
: interpagespace
247 ; mutable zoom
: float
248 ; mutable presentation
: bool
249 ; mutable angle
: angle
252 ; mutable savebmarks
: bool
253 ; mutable proportional
: proportional
254 ; mutable trimmargins
: trimmargins
255 ; mutable trimfuzz
: irect
256 ; mutable memlimit
: memsize
257 ; mutable texcount
: texcount
258 ; mutable sliceheight
: sliceheight
259 ; mutable thumbw
: width
260 ; mutable jumpback
: bool
261 ; mutable bgcolor
: float * float * float
262 ; mutable bedefault
: bool
263 ; mutable scrollbarinpm
: bool
264 ; mutable tilew
: int
265 ; mutable tileh
: int
266 ; mutable mustoresize
: memsize
267 ; mutable checkers
: bool
268 ; mutable aalevel
: int
269 ; mutable urilauncher
: string
270 ; mutable pathlauncher
: string
271 ; mutable colorspace
: colorspace
272 ; mutable invert
: bool
273 ; mutable colorscale
: float
274 ; mutable redirectstderr
: bool
275 ; mutable ghyllscroll
: (int * int * int) option
276 ; mutable columns
: columns
option
277 ; mutable beyecolumns
: columncount
option
278 ; mutable selcmd
: string
279 ; mutable updatecurs
: bool
280 ; mutable keyhashes
: (string * keyhash
) list
284 type anchor
= pageno
* top
;;
286 type outline
= string * int * anchor
;;
288 type rect
= float * float * float * float * float * float * float * float;;
290 type tile
= opaque
* pixmapsize
* elapsed
291 and elapsed
= float;;
292 type pagemapkey
= pageno
* gen
;;
293 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
297 let emptyanchor = (0, 0.0);;
299 type infochange
= | Memused
| Docinfo
| Pdim
;;
301 class type uioh
= object
302 method display
: unit
303 method key
: int -> int -> uioh
304 method button
: int -> bool -> int -> int -> int -> uioh
305 method motion
: int -> int -> uioh
306 method pmotion
: int -> int -> uioh
307 method infochanged
: infochange
-> unit
308 method scrollpw
: (int * float * float)
309 method scrollph
: (int * float * float)
310 method modehash
: keyhash
314 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
315 | Textentry
of (textentry
* onleave
)
317 and onleave
= leavetextentrystatus
-> unit
318 and leavetextentrystatus
= | Cancel
| Confirm
319 and helpitem
= string * int * action
322 | Action
of (uioh
-> uioh
)
325 let isbirdseye = function Birdseye _
-> true | _
-> false;;
326 let istextentry = function Textentry _
-> true | _
-> false;;
330 | Loading
of (page
* gen
)
332 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
334 | Outlining
of outline list
337 let emptykeyhash = Hashtbl.create
0;;
338 let nouioh : uioh
= object (self
)
340 method key _ _
= self
341 method button _ _ _ _ _
= self
342 method motion _ _
= self
343 method pmotion _ _
= self
344 method infochanged _
= ()
345 method scrollpw
= (0, nan
, nan
)
346 method scrollph
= (0, nan
, nan
)
347 method modehash
= emptykeyhash
351 { mutable sr
: Unix.file_descr
352 ; mutable sw
: Unix.file_descr
353 ; mutable wsfd
: Unix.file_descr
354 ; mutable errfd
: Unix.file_descr
option
355 ; mutable stderr
: Unix.file_descr
356 ; mutable errmsgs
: Buffer.t
357 ; mutable newerrmsgs
: bool
361 ; mutable scrollw
: int
362 ; mutable hscrollh
: int
363 ; mutable anchor
: anchor
364 ; mutable ranchors
: (string * string * anchor
) list
366 ; mutable layout
: page list
367 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
368 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
369 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
370 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
371 ; mutable pagecount
: int
372 ; mutable currently
: currently
373 ; mutable mstate
: mstate
374 ; mutable searchpattern
: string
375 ; mutable rects
: (pageno
* recttype
* rect
) list
376 ; mutable rects1
: (pageno
* recttype
* rect
) list
377 ; mutable text
: string
378 ; mutable fullscreen
: (width
* height
) option
379 ; mutable mode
: mode
380 ; mutable uioh
: uioh
381 ; mutable outlines
: outline array
382 ; mutable bookmarks
: outline list
383 ; mutable path
: string
384 ; mutable password
: string
385 ; mutable invalidated
: int
386 ; mutable memused
: memsize
388 ; mutable throttle
: (page list
* int * float) option
389 ; mutable autoscroll
: int option
390 ; mutable ghyll
: (int option -> unit)
391 ; mutable help
: helpitem array
392 ; mutable docinfo
: (int * string) list
393 ; mutable texid
: GlTex.texture_id
option
395 ; mutable prevzoom
: float
396 ; mutable progress
: float
397 ; mutable redisplay
: bool
398 ; mutable mpos
: mpos
399 ; mutable keystate
: keystate
402 { pat
: string circbuf
403 ; pag
: string circbuf
404 ; nav
: anchor circbuf
405 ; sel
: string circbuf
426 ; presentation
= false
431 ; proportional
= true
432 ; trimmargins
= false
433 ; trimfuzz
= (0,0,0,0)
434 ; memlimit
= 32 lsl 20
439 ; bgcolor
= (0.5, 0.5, 0.5)
441 ; scrollbarinpm
= true
444 ; mustoresize
= 128 lsl 20
449 | Plinux
| Pfreebsd
| Pdragonflybsd
450 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
451 | Posx
-> "open \"%s\""
452 | Pcygwin
-> "cygstart %s"
453 | Punknown
-> "echo %s")
454 ; pathlauncher
= "lp \"%s\""
457 | Plinux
| Pfreebsd
| Pdragonflybsd
458 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
465 ; redirectstderr
= false
471 let mk n
= (n
, Hashtbl.create
1) in
483 let findkeyhash c name
=
484 try List.assoc name c
.keyhashes
485 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
488 let conf = { defconf with angle
= defconf.angle
};;
491 { mutable fontsize
: int
492 ; mutable wwidth
: float
493 ; mutable maxrows
: int
505 fstate.fontsize
<- n
;
506 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
507 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
511 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
512 let len = String.length s
in
513 if colonpos >= 0 && colonpos + 3 < len
515 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
518 try String.rindex_from s
colonpos ' '
522 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
525 | "http" | "ftp" | "mailto" ->
527 try String.index_from s
colonpos ' '
528 with Not_found
-> len
530 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
538 let shell, farg
= "/bin/sh", "-c" in
540 let args = [|shell; farg
; s
|] in
541 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
545 if String.length
conf.urilauncher
= 0
546 then print_endline uri
548 let url = geturl uri
in
549 if String.length
url = 0
550 then print_endline uri
552 let re = Str.regexp
"%s" in
553 let command = Str.global_replace
re url conf.urilauncher
in
557 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
563 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
564 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
568 let strings = version () :: "" :: Help.keys
in
571 let url = geturl s
in
572 if String.length
url > 0
573 then (s
, 0, Action
(fun u
-> gotouri url; u
))
574 else (s
, 0, Noaction
)
585 ; stderr
= Unix.stderr
586 ; errmsgs
= Buffer.create
0
593 ; anchor
= emptyanchor
597 ; tilelru
= Queue.create
()
598 ; pagemap
= Hashtbl.create
10
599 ; tilemap
= Hashtbl.create
10
616 { nav
= cbnew 10 (0, 0.0)
641 Printf.kprintf prerr_endline fmt
643 Printf.kprintf ignore fmt
647 if String.length
conf.pathlauncher
= 0
648 then print_endline
state.path
650 let re = Str.regexp
"%s" in
651 let command = Str.global_replace
re state.path
conf.pathlauncher
in
655 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
660 let redirectstderr () =
661 if conf.redirectstderr
663 let rfd, wfd
= Unix.pipe
() in
664 state.stderr
<- Unix.dup
Unix.stderr
;
665 state.errfd
<- Some
rfd;
666 Unix.dup2 wfd
Unix.stderr
;
668 state.newerrmsgs
<- false;
669 begin match state.errfd
with
672 Unix.dup2
state.stderr
Unix.stderr
;
676 prerr_string
(Buffer.contents
state.errmsgs
);
678 Buffer.clear
state.errmsgs
;
684 let postRedisplay who
=
686 then prerr_endline
("redisplay for " ^ who
);
687 state.redisplay
<- true;
691 let getopaque pageno
=
692 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
693 with Not_found
-> None
696 let putopaque pageno opaque
=
697 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
700 let pagetranslatepoint l x y
=
701 let dy = y
- l
.pagedispy
in
702 let y = dy + l
.pagey
in
703 let dx = x
- l
.pagedispx
in
704 let x = dx + l
.pagex
in
711 begin match getopaque l
.pageno
with
713 let x0 = l
.pagedispx
in
714 let x1 = x0 + l
.pagevw
in
715 let y0 = l
.pagedispy
in
716 let y1 = y0 + l
.pagevh
in
717 if y >= y0 && y <= y1 && x >= x0 && x <= x1
719 let px, py
= pagetranslatepoint l
x y in
720 match whatsunder opaque
px py
with
733 state.text
<- Printf.sprintf
"%c%s" c s
;
734 G.postRedisplay "showtext";
737 let updateunder x y =
738 match getunder x y with
739 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
741 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
742 Wsi.setcursor
Wsi.CURSOR_INFO
743 | Ulinkgoto
(page
, _
) ->
745 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
746 Wsi.setcursor
Wsi.CURSOR_INFO
748 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
749 Wsi.setcursor
Wsi.CURSOR_TEXT
751 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
752 Wsi.setcursor
Wsi.CURSOR_INHERIT
754 if conf.underinfo
then showtext 'l'
("launch: " ^ s
);
755 Wsi.setcursor
Wsi.CURSOR_INHERIT
757 if conf.underinfo
then showtext 'n'
("named: " ^ s
);
758 Wsi.setcursor
Wsi.CURSOR_INHERIT
759 | Uremote
(filename
, pageno
) ->
760 if conf.underinfo
then showtext 'r'
761 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
762 Wsi.setcursor
Wsi.CURSOR_INFO
766 let b = Buffer.create
(String.length s
+ 1) in
767 Buffer.add_string
b s
;
772 let colorspace_of_string s
=
773 match String.lowercase s
with
777 | _
-> failwith
"invalid colorspace"
780 let int_of_colorspace = function
786 let colorspace_of_int = function
790 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
793 let colorspace_to_string = function
799 let intentry_with_suffix text key
=
801 if key
>= 32 && key
< 127
805 match Char.lowercase
c with
807 let text = addchar text c in
811 let text = addchar text c in
815 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
819 let columns_to_string (n
, a
, b) =
821 then Printf.sprintf
"%d" n
822 else Printf.sprintf
"%d,%d,%d" n a
b;
825 let columns_of_string s
=
827 (int_of_string s
, 0, 0)
829 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
833 let len = String.length s
in
835 let b = Buffer.create
n in
836 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
837 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
838 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
839 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
840 Buffer.add_string
b s
;
841 let s'
= Buffer.contents
b in
842 let n'
= Unix.write fd
s'
0 n in
843 if n'
!= n then failwith
"write failed";
848 let n = Unix.read fd
s 0 4 in
849 if n != 4 then failwith
"incomplete read(len)";
851 lor (Char.code
s.[0] lsl 24)
852 lor (Char.code
s.[1] lsl 16)
853 lor (Char.code
s.[2] lsl 8)
854 lor (Char.code
s.[3] lsl 0)
856 let s = String.create
len in
857 let n = Unix.read fd
s 0 len in
858 if n != len then failwith
"incomplete read(data)";
863 let b = Buffer.create
10 in
864 Buffer.add_string
b s;
865 let rec combine = function
868 Buffer.add_char
b ' '
;
871 | `
b b -> if b then "1" else "0"
873 | `i i
-> string_of_int i
874 | `
f f -> string_of_float
f
875 | `I
f -> string_of_int
(truncate
f)
877 Buffer.add_string
b s;
884 let cmd = Buffer.contents
(makecmd s l
) in
885 writecmd state.sw
cmd;
891 let d = conf.winh
- h
in
898 let rec f pn ph pi fh l
=
900 | (n, _
, h
, _
) :: rest
->
901 let ips = calcips h
in
906 if isbirdseye state.mode
&& pn
= 0
911 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
916 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
920 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
923 let fh = f 0 0 0 0 state.pdims
in
928 match conf.columns
with
929 | None
-> calcheight ()
931 if Array.length
b > 0
933 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
938 let getpageyh pageno
=
939 let rec f pn ph pi
y l
=
941 | (n, _
, h
, _
) :: rest
->
942 let ips = calcips h
in
945 let h = if n = pageno
then h else ph
in
946 if conf.presentation
&& n = pageno
948 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
950 y + (pageno
- pn
) * (ph
+ pi
), h
952 let y = y + (if conf.presentation
then pi
else 0) in
953 let y = y + (n - pn
) * (ph
+ pi
) in
957 y + (pageno
- pn
) * (ph
+ pi
), ph
959 f 0 0 0 0 state.pdims
962 let getpageyh pageno
=
963 match conf.columns
with
964 | None
-> getpageyh pageno
966 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
970 let getpagedim pageno
=
973 | (n, _
, _
, _
) as pdim
:: rest
->
975 then (if n = pageno
then pdim
else ppdim
)
980 f (-1, -1, -1, -1) state.pdims
983 let getpagey pageno
= fst
(getpageyh pageno
);;
986 let sh = sh - state.hscrollh
in
987 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
988 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
990 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
991 let ips = calcips h in
993 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
997 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
999 prev
, pdims
, pdimno
, 0
1001 let dy = dy + yinc in
1002 let py = py + yinc in
1003 if pageno
= state.pagecount
|| dy >= sh
1008 if py + h <= vy - yinc
1010 let py = py + h + ips in
1011 let dy = max
0 (py - y) in
1012 f ~pageno
:(pageno
+1)
1020 let pagey = vy - py in
1021 let pagevh = h - pagey in
1022 let pagevh = min
(sh - dy) pagevh in
1023 let off = if yinc > 0 then py - vy else 0 in
1024 let py = py + h + ips in
1027 if state.w
< conf.winw
- state.scrollw
1028 then (conf.winw
- state.scrollw
- state.w
) / 2
1031 let dispx = xoff + state.x in
1037 let lw = w
- pagex in
1038 min
lw (conf.winw
- state.scrollw
)
1042 ; pagedimno
= pdimno
1046 ; pagey = pagey + off
1048 ; pagevh = pagevh - off
1050 ; pagedispy
= dy + off
1053 let accu = e :: accu in
1054 f ~pageno
:(pageno
+1)
1062 if state.invalidated
= 0
1080 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1081 let sh = sh - state.hscrollh
in
1082 let rec fold accu n =
1083 if n = Array.length
b
1086 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1089 || n = state.pagecount
- coverB
1090 || (n - coverA
) mod columns
= columns
- 1)
1096 let pagey = max
0 (y - vy) in
1097 let pagedispy = if pagey > 0 then 0 else vy - y in
1098 let pagedispx, pagex, pagevw =
1100 if n = coverA
- 1 || n = state.pagecount
- coverB
1101 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1102 else dx + xoff + state.x
1105 then 0, -pdx, w
+ pdx
1106 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1108 let pagevh = min
(h - pagey) (sh - pagedispy) in
1109 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1113 ; pagedimno
= pdimno
1120 ; pagedispx = pagedispx
1121 ; pagedispy = pagedispy
1132 if state.invalidated
= 0
1133 then List.rev
(fold [] 0)
1138 match conf.columns
with
1139 | None
-> layout1 y sh
1140 | Some
c -> layoutN c y sh
1144 let y = state.y + incr
in
1146 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1151 let tilex = l
.pagex mod conf.tilew
in
1152 let tiley = l
.pagey mod conf.tileh
in
1154 let col = l
.pagex / conf.tilew
in
1155 let row = l
.pagey / conf.tileh
in
1158 let a = l
.pagew
- l
.pagex in
1159 let b = conf.winw
- state.scrollw
in
1161 and vh
= l
.pagevh in
1163 let rec rowloop row y0 dispy
h =
1167 let dh = conf.tileh
- y0 in
1168 let dh = min
h dh in
1169 let rec colloop col x0 dispx w
=
1173 let dw = conf.tilew
- x0 in
1174 let dw = min w
dw in
1176 f col row dispx dispy
x0 y0 dw dh;
1177 colloop (col+1) 0 (dispx+dw) (w
-dw)
1180 colloop col tilex l
.pagedispx vw;
1181 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1185 then rowloop row tiley l
.pagedispy vh
;
1188 let gettileopaque l
col row =
1190 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1192 try Some
(Hashtbl.find
state.tilemap
key)
1193 with Not_found
-> None
1196 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1197 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1198 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1201 let drawtiles l color
=
1203 let f col row x y tilex tiley w
h =
1204 match gettileopaque l
col row with
1205 | Some
(opaque
, _
, t
) ->
1206 let params = x, y, w
, h, tilex, tiley in
1210 GlFunc.blend_func `zero `one_minus_src_color
;
1212 drawtile
params opaque
;
1214 then Gl.disable `blend
;
1217 let s = Printf.sprintf
1221 let w = measurestr
fstate.fontsize
s in
1222 GlMisc.push_attrib
[`current
];
1223 GlDraw.color
(0.0, 0.0, 0.0);
1225 (float (x-2), float (y-2))
1226 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1227 GlDraw.color
(1.0, 1.0, 1.0);
1228 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1229 GlMisc.pop_attrib
();
1234 let lw = conf.winw
- state.scrollw
- x in
1237 let lh = conf.winh
- y in
1240 Gl.enable `texture_2d
;
1241 begin match state.texid
with
1243 GlTex.bind_texture `texture_2d id
;
1246 and x1 = float (x+w)
1247 and y1 = float (y+h) in
1249 let tw = float w /. 64.0
1250 and th
= float h /. 64.0 in
1251 let tx0 = float tilex /. 64.0
1252 and ty0
= float tiley /. 64.0 in
1254 and ty1
= ty0
+. th
in
1255 GlDraw.begins `quads
;
1256 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1257 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1258 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1259 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1262 Gl.disable `texture_2d
;
1264 GlDraw.color
(1.0, 1.0, 1.0);
1267 (float (x+w), float (y+h));
1269 if w > 128 && h > fstate.fontsize
+ 10
1271 GlDraw.color
(0.0, 0.0, 0.0);
1274 then (col*conf.tilew
, row*conf.tileh
)
1277 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1284 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1286 let tilevisible1 l
x y =
1288 and ax1
= l
.pagex + l
.pagevw
1290 and ay1
= l
.pagey + l
.pagevh in
1294 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1295 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1297 let rx0 = max
ax0 bx0
1298 and ry0
= max ay0 by0
1299 and rx1
= min ax1
bx1
1300 and ry1
= min ay1 by1
in
1302 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1303 nonemptyintersection
1306 let tilevisible layout n x y =
1307 let rec findpageinlayout = function
1308 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1309 | _
:: rest
-> findpageinlayout rest
1312 findpageinlayout layout
1315 let tileready l
x y =
1316 tilevisible1 l
x y &&
1317 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1320 let tilepage n p
layout =
1321 let rec loop = function
1325 let f col row _ _ _ _ _ _
=
1326 if state.currently
= Idle
1328 match gettileopaque l
col row with
1331 let x = col*conf.tilew
1332 and y = row*conf.tileh
in
1334 let w = l
.pagew
- x in
1338 let h = l
.pageh
- y in
1350 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1351 conf.tilew
, conf.tileh
1360 if state.invalidated
= 0 then loop layout;
1363 let preloadlayout visiblepages
=
1364 let presentation = conf.presentation in
1365 let interpagespace = conf.interpagespace in
1366 let maxy = state.maxy in
1367 conf.presentation <- false;
1368 conf.interpagespace <- 0;
1369 state.maxy <- calcheight ();
1371 match visiblepages
with
1373 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1375 let y = if y < conf.winh
then 0 else y - conf.winh
in
1376 let h = state.y - y + conf.winh
*3 in
1377 let pages = layout y h in
1378 conf.presentation <- presentation;
1379 conf.interpagespace <- interpagespace;
1385 let rec loop pages =
1386 if state.currently
!= Idle
1391 begin match getopaque l
.pageno
with
1393 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1394 state.currently
<- Loading
(l
, state.gen
);
1396 tilepage l
.pageno opaque
pages;
1401 if state.invalidated
= 0 then loop pages
1406 if conf.preload && state.currently
= Idle
1407 then load (preloadlayout pages);
1410 let layoutready layout =
1411 let rec fold all ls
=
1412 all
&& match ls
with
1414 let seen = ref false in
1415 let allvisible = ref true in
1416 let foo col row _ _ _ _ _ _
=
1418 allvisible := !allvisible &&
1419 begin match gettileopaque l
col row with
1425 fold (!seen && !allvisible) rest
1428 let alltilesvisible = fold true layout in
1433 let y = bound y 0 state.maxy in
1434 let y, layout, proceed
=
1435 match conf.maxwait
with
1436 | Some time
when state.ghyll
== noghyll ->
1437 begin match state.throttle
with
1439 let layout = layout y conf.winh
in
1440 let ready = layoutready layout in
1444 state.throttle
<- Some
(layout, y, now ());
1446 else G.postRedisplay "gotoy showall (None)";
1448 | Some
(_
, _
, started
) ->
1449 let dt = now () -. started
in
1452 state.throttle
<- None
;
1453 let layout = layout y conf.winh
in
1455 G.postRedisplay "maxwait";
1462 let layout = layout y conf.winh
in
1463 if true || layoutready layout
1464 then G.postRedisplay "gotoy ready";
1470 state.layout <- layout;
1471 begin match state.mode
with
1472 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1473 if not
(pagevisible layout pageno
)
1475 match state.layout with
1478 state.mode
<- Birdseye
(
1479 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1486 state.ghyll
<- noghyll;
1489 let conttiling pageno opaque
=
1490 tilepage pageno opaque
1491 (if conf.preload then preloadlayout state.layout else state.layout)
1494 let gotoy_and_clear_text y =
1496 if not
conf.verbose
then state.text <- "";
1500 match state.layout with
1502 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1505 let getanchory (n, top
) =
1506 let y, h = getpageyh n in
1507 y + (truncate
(top
*. float h));
1510 let gotoanchor anchor
=
1511 gotoy (getanchory anchor
);
1515 cbput state.hists
.nav
(getanchor ());
1519 let anchor = cbgetc state.hists
.nav dir
in
1524 let rec scroll f n a b =
1525 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1527 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1529 then s (float f /. float a)
1532 then 1.0 -. s ((float (f-b) /. float (n-b)))
1539 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1540 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1542 let ins = float a *. iv1
1543 and outs
= float (n-b) *. iv1 in
1545 ins +. outs
+. float ones
1547 let rec set (_N
, _A
, _B
) y sy
=
1548 let sum = summa
1.0 _N _A _B
in
1549 let dy = float (y - sy
) in
1553 then state.ghyll
<- noghyll
1556 let s = scroll n _N _A _B
in
1557 let y1 = y1 +. ((s *. dy) /. sum) in
1558 gotoy_and_clear_text (truncate
y1);
1559 state.ghyll
<- gf (n+1) y1;
1563 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1565 gf 0 (float state.y)
1568 match conf.ghyllscroll
with
1570 gotoy_and_clear_text y
1572 if state.ghyll
== noghyll
1573 then set nab
y state.y
1574 else state.ghyll
(Some
y)
1577 let gotopage n top
=
1578 let y, h = getpageyh n in
1579 let y = y + (truncate
(top
*. float h)) in
1583 let gotopage1 n top
=
1584 let y = getpagey n in
1594 state.invalidated
<- state.invalidated
+ 1;
1597 let writeopen path password
=
1598 writecmd state.sw
("open " ^ path ^
"\000" ^ password ^
"\000");
1601 let opendoc path password
=
1604 state.password
<- password
;
1605 state.gen
<- state.gen
+ 1;
1606 state.docinfo
<- [];
1608 setaalevel
conf.aalevel
;
1609 writeopen path password
;
1610 Wsi.settitle
("llpp " ^
Filename.basename path
);
1611 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1615 let c = c *. conf.colorscale
in
1619 let scalecolor2 (r
, g
, b) =
1620 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1624 let docolumns = function
1626 | Some
((columns
, coverA
, coverB
), _
) ->
1627 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1628 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1629 if pageno
= state.pagecount
1632 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1634 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1635 pdimno+1, pdim
, rest
1640 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1642 (conf.winw
- state.scrollw
- w) / 2,
1643 y + rowh
+ conf.interpagespace, h
1646 if (pageno
- coverA
) mod columns
= 0
1647 then 0, y + rowh
+ conf.interpagespace, h
1648 else x, y, max rowh
h
1651 let rec fixrow m
= if m
= pageno
then () else
1652 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1655 let y = y + (rowh
- h) / 2 in
1656 a.(m
) <- (pdimno, x, y, pdim
);
1660 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1661 then fixrow (pageno
- columns
);
1662 a.(pageno
) <- (pdimno, x, y, pdim
);
1663 let x = x + w + xoff*2 + conf.interpagespace in
1664 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1666 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1667 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1669 docolumns conf.columns
;
1670 state.maxy <- calcheight ();
1672 if state.w <= conf.winw
- state.scrollw
1676 match state.mode
with
1677 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1678 let y, h = getpageyh pageno
in
1679 let top = (conf.winh
- h) / 2 in
1680 gotoy (max
0 (y - top))
1681 | _
-> gotoanchor state.anchor
1685 let firsttime = ref true in
1687 GlDraw.viewport
0 0 w h;
1688 if state.invalidated
= 0 && not
!firsttime
1689 then state.anchor <- getanchor ();
1693 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1697 setfontsize fstate.fontsize
;
1698 GlMat.mode `modelview
;
1699 GlMat.load_identity
();
1701 GlMat.mode `projection
;
1702 GlMat.load_identity
();
1703 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1704 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1705 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1708 match conf.columns
with
1710 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1713 wcmd "geometry" [`i
w; `i
h];
1717 let len = String.length
state.text in
1720 match state.mode
with
1721 | View
-> state.hscrollh
1726 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1727 (x+.w, float (conf.winh
- hscrollh))
1730 let w = float (conf.winw
- state.scrollw
- 1) in
1731 if state.progress
>= 0.0 && state.progress
< 1.0
1733 GlDraw.color
(0.3, 0.3, 0.3);
1734 let w1 = w *. state.progress
in
1736 GlDraw.color
(0.0, 0.0, 0.0);
1740 GlDraw.color
(0.0, 0.0, 0.0);
1744 GlDraw.color
(1.0, 1.0, 1.0);
1745 drawstring fstate.fontsize
1746 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1749 match state.mode
with
1750 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1754 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1756 Printf.sprintf
"%s%s_" prefix
text
1765 if not
(istextentry state.mode
)
1767 let s1 = "(press 'e' to review error messasges)" in
1768 if String.length
s > 0 then s ^
" " ^
s1 else s1
1773 if String.length
s > 0
1778 let len = Queue.length
state.tilelru
in
1780 if state.memused
<= conf.memlimit
1785 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1786 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1787 let (_
, pw
, ph
, _
) = getpagedim n in
1790 && colorspace
= conf.colorspace
1791 && angle
= conf.angle
1796 match state.throttle
with
1799 then preloadlayout state.layout
1801 | Some
(layout, _
, _
) ->
1804 let x = col*conf.tilew
1805 and y = row*conf.tileh
in
1806 tilevisible layout n x y
1808 then Queue.push lruitem
state.tilelru
1810 wcmd "freetile" [`
s p
];
1811 state.memused
<- state.memused
- s;
1812 state.uioh#infochanged Memused
;
1813 Hashtbl.remove
state.tilemap k
;
1822 Queue.iter
(fun (k
, p
, s) ->
1823 wcmd "freetile" [`
s p
];
1824 state.memused
<- state.memused
- s;
1825 state.uioh#infochanged Memused
;
1826 Hashtbl.remove
state.tilemap k
;
1828 Queue.clear
state.tilelru
;
1832 let logcurrently = function
1833 | Idle
-> dolog "Idle"
1834 | Loading
(l
, gen
) ->
1835 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1836 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1838 "Tiling %d[%d,%d] page=%s cs=%s angle"
1839 l
.pageno
col row pageopaque
1840 (colorspace_to_string colorspace
)
1842 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1843 angle gen
conf.angle
state.gen
1845 conf.tilew
conf.tileh
1852 (* dolog "%S" cmds; *)
1855 try String.index cmds ' '
1856 with Not_found
-> -1
1861 let l = String.length cmds
in
1862 let op = String.sub cmds
0 spacepos in
1864 if l - spacepos < 2 then ""
1865 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1870 state.uioh#infochanged Pdim
;
1874 state.rects
<- state.rects1
;
1875 G.postRedisplay "clearrects";
1879 try Scanf.sscanf
args "%u" (fun n -> n)
1881 dolog "error processing 'continue' %S: %s"
1882 cmds
(Printexc.to_string exn
);
1885 state.pagecount
<- n;
1886 state.invalidated
<- state.invalidated
- 1;
1887 begin match state.currently
with
1889 state.currently
<- Idle
;
1890 state.outlines
<- Array.of_list
(List.rev
l)
1893 if state.invalidated
= 0
1895 if conf.maxwait
= None
1896 then G.postRedisplay "continue";
1906 then showtext ' '
args
1909 let progress, text =
1911 Scanf.sscanf
args "%f %n"
1913 f, String.sub
args pos
(String.length
args - pos
))
1915 dolog "error processing 'progress' %S: %s"
1916 cmds
(Printexc.to_string exn
);
1920 state.progress <- progress;
1921 G.postRedisplay "progress"
1924 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1926 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1927 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1928 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1930 dolog "error processing 'firstmatch' %S: %s"
1931 cmds
(Printexc.to_string exn
);
1934 let y = (getpagey pageno) + truncate
y0 in
1937 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1940 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1942 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1943 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1944 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1946 dolog "error processing 'match' %S: %s"
1947 cmds
(Printexc.to_string exn
);
1951 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1956 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1958 dolog "error processing 'page' %S: %s"
1959 cmds
(Printexc.to_string exn
);
1962 begin match state.currently
with
1963 | Loading
(l, gen
) ->
1964 vlog "page %d took %f sec" l.pageno t
;
1965 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1966 begin match state.throttle
with
1968 let preloadedpages =
1970 then preloadlayout state.layout
1975 Set.Make
(struct type t
= int let compare = (-) end) in
1977 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1978 IntSet.empty
preloadedpages
1981 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1982 if not
(IntSet.mem
pageno set)
1984 wcmd "freepage" [`
s opaque
];
1990 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1993 state.currently
<- Idle
;
1996 tilepage l.pageno pageopaque state.layout;
1998 load preloadedpages;
1999 if pagevisible state.layout l.pageno
2000 && layoutready state.layout
2001 then G.postRedisplay "page";
2004 | Some
(layout, _
, _
) ->
2005 state.currently
<- Idle
;
2006 tilepage l.pageno pageopaque layout;
2011 dolog "Inconsistent loading state";
2012 logcurrently state.currently
;
2017 let (x, y, opaque
, size
, t
) =
2019 Scanf.sscanf
args "%u %u %s %u %f"
2020 (fun x y p size t
-> (x, y, p
, size
, t
))
2022 dolog "error processing 'tile' %S: %s"
2023 cmds
(Printexc.to_string exn
);
2026 begin match state.currently
with
2027 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2028 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2030 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2032 wcmd "freetile" [`
s opaque
];
2033 state.currently
<- Idle
;
2037 puttileopaque l col row gen cs angle opaque size t
;
2038 state.memused
<- state.memused
+ size
;
2039 state.uioh#infochanged Memused
;
2041 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2042 opaque
, size
) state.tilelru
;
2045 match state.throttle
with
2046 | None
-> state.layout
2047 | Some
(layout, _
, _
) -> layout
2050 state.currently
<- Idle
;
2052 && conf.colorspace
= cs
2053 && conf.angle
= angle
2054 && tilevisible layout l.pageno x y
2055 then conttiling l.pageno pageopaque;
2057 begin match state.throttle
with
2059 preload state.layout;
2061 && conf.colorspace
= cs
2062 && conf.angle
= angle
2063 && tilevisible state.layout l.pageno x y
2064 then G.postRedisplay "tile nothrottle";
2066 | Some
(layout, y, _
) ->
2067 let ready = layoutready layout in
2071 state.layout <- layout;
2072 state.throttle
<- None
;
2073 G.postRedisplay "throttle";
2080 dolog "Inconsistent tiling state";
2081 logcurrently state.currently
;
2088 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2090 dolog "error processing 'pdim' %S: %s"
2091 cmds
(Printexc.to_string exn
);
2094 state.uioh#infochanged Pdim
;
2095 state.pdims
<- pdim :: state.pdims
2098 let (l, n, t
, h, pos
) =
2100 Scanf.sscanf
args "%u %u %d %u %n"
2101 (fun l n t
h pos
-> l, n, t
, h, pos
)
2103 dolog "error processing 'o' %S: %s"
2104 cmds
(Printexc.to_string exn
);
2107 let s = String.sub
args pos
(String.length
args - pos
) in
2108 let outline = (s, l, (n, float t
/. float h)) in
2109 begin match state.currently
with
2110 | Outlining outlines
->
2111 state.currently
<- Outlining
(outline :: outlines
)
2113 state.currently
<- Outlining
[outline]
2115 dolog "invalid outlining state";
2116 logcurrently currently
2120 state.docinfo
<- (1, args) :: state.docinfo
2123 state.uioh#infochanged Docinfo
;
2124 state.docinfo
<- List.rev
state.docinfo
2127 dolog "unknown cmd `%S'" cmds
2132 let action = function
2133 | HCprev
-> cbget cb ~
-1
2134 | HCnext
-> cbget cb
1
2135 | HCfirst
-> cbget cb ~
-(cb
.rc)
2136 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2137 and cancel
() = cb
.rc <- rc
2141 let search pattern forward
=
2142 if String.length pattern
> 0
2145 match state.layout with
2148 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2151 let b = makecmd "search"
2152 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2154 Buffer.add_char
b '
,'
;
2155 Buffer.add_string
b pattern
;
2156 Buffer.add_char
b '
\000'
;
2159 writecmd state.sw
cmd;
2162 let intentry text key =
2164 if key >= 32 && key < 127
2170 let text = addchar text c in
2174 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2178 let textentry text key =
2179 if key land 0xff00 = 0xff00
2181 else TEcont
(text ^
Wsi.toutf8
key)
2184 let reqlayout angle proportional
=
2185 match state.throttle
with
2187 if state.invalidated
= 0 then state.anchor <- getanchor ();
2188 conf.angle
<- angle
mod 360;
2189 conf.proportional
<- proportional
;
2191 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2195 let settrim trimmargins trimfuzz
=
2196 if state.invalidated
= 0 then state.anchor <- getanchor ();
2197 conf.trimmargins
<- trimmargins
;
2198 conf.trimfuzz
<- trimfuzz
;
2199 let x0, y0, x1, y1 = trimfuzz
in
2202 `
b conf.trimmargins
;
2208 Hashtbl.iter
(fun _ opaque
->
2209 wcmd "freepage" [`
s opaque
];
2211 Hashtbl.clear
state.pagemap
;
2215 match state.throttle
with
2217 let zoom = max
0.01 zoom in
2218 if zoom <> conf.zoom
2220 state.prevzoom
<- conf.zoom;
2223 then (state.x <- 0; 0.0)
2224 else float state.x /. float state.w
2227 reshape conf.winw
conf.winh
;
2230 let x = relx *. float state.w in
2231 state.x <- truncate
x;
2233 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2236 | Some
(layout, y, started
) ->
2238 match conf.maxwait
with
2242 let dt = now () -. started
in
2250 let setcolumns columns coverA coverB
=
2253 conf.columns
<- None
;
2258 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2261 reshape conf.winw
conf.winh
;
2264 let enterbirdseye () =
2265 let zoom = float conf.thumbw
/. float conf.winw
in
2266 let birdseyepageno =
2267 let cy = conf.winh
/ 2 in
2271 let rec fold best
= function
2274 let d = cy - (l.pagedispy + l.pagevh/2)
2275 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2276 if abs
d < abs dbest
2283 state.mode
<- Birdseye
(
2284 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2287 conf.presentation <- false;
2288 conf.interpagespace <- 10;
2289 conf.hlinks
<- false;
2291 state.mstate
<- Mnone
;
2292 conf.maxwait
<- None
;
2294 match conf.beyecolumns
with
2297 Some
((c, 0, 0), [||])
2300 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2303 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2308 reshape conf.winw
conf.winh
;
2311 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2313 conf.zoom <- c.zoom;
2314 conf.presentation <- c.presentation;
2315 conf.interpagespace <- c.interpagespace;
2316 conf.maxwait
<- c.maxwait
;
2317 conf.hlinks
<- c.hlinks
;
2318 conf.beyecolumns
<- (
2319 match conf.columns
with
2320 | Some
((c, _
, _
), _
) -> Some
c
2324 match c.columns
with
2325 | Some
(c, _
) -> Some
(c, [||])
2331 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2334 reshape conf.winw
conf.winh
;
2335 state.anchor <- if goback
then anchor else (pageno, 0.0);
2338 let togglebirdseye () =
2339 match state.mode
with
2340 | Birdseye vals
-> leavebirdseye vals
true
2341 | View
-> enterbirdseye ()
2345 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2346 let pageno = max
0 (pageno - incr
) in
2347 let rec loop = function
2348 | [] -> gotopage1 pageno 0
2349 | l :: _
when l.pageno = pageno ->
2350 if l.pagedispy >= 0 && l.pagey = 0
2351 then G.postRedisplay "upbirdseye"
2352 else gotopage1 pageno 0
2353 | _
:: rest
-> loop rest
2356 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2359 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2360 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2361 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2362 let rec loop = function
2364 let y, h = getpageyh pageno in
2365 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2367 | l :: _
when l.pageno = pageno ->
2368 if l.pagevh != l.pageh
2369 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2370 else G.postRedisplay "downbirdseye"
2371 | _
:: rest
-> loop rest
2376 let optentry mode _
key =
2377 let btos b = if b then "on" else "off" in
2378 if key >= 32 && key < 127
2380 let c = Char.chr
key in
2384 try conf.scrollstep
<- int_of_string
s with exc
->
2385 state.text <- Printf.sprintf
"bad integer `%s': %s"
2386 s (Printexc.to_string exc
)
2388 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2393 conf.autoscrollstep
<- int_of_string
s;
2394 if state.autoscroll
<> None
2395 then state.autoscroll
<- Some
conf.autoscrollstep
2397 state.text <- Printf.sprintf
"bad integer `%s': %s"
2398 s (Printexc.to_string exc
)
2400 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2405 let n, a, b = columns_of_string s in
2408 state.text <- Printf.sprintf
"bad columns `%s': %s"
2409 s (Printexc.to_string exc
)
2411 TEswitch
("columns: ", "", None
, textentry, ondone)
2416 let zoom = float (int_of_string
s) /. 100.0 in
2419 state.text <- Printf.sprintf
"bad integer `%s': %s"
2420 s (Printexc.to_string exc
)
2422 TEswitch
("zoom: ", "", None
, intentry, ondone)
2427 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2429 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2430 begin match mode
with
2432 leavebirdseye beye
false;
2437 state.text <- Printf.sprintf
"bad integer `%s': %s"
2438 s (Printexc.to_string exc
)
2440 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2445 Some
(int_of_string
s)
2447 state.text <- Printf.sprintf
"bad integer `%s': %s"
2448 s (Printexc.to_string exc
);
2451 | Some angle
-> reqlayout angle
conf.proportional
2454 TEswitch
("rotation: ", "", None
, intentry, ondone)
2457 conf.icase
<- not
conf.icase
;
2458 TEdone
("case insensitive search " ^
(btos conf.icase
))
2461 conf.preload <- not
conf.preload;
2463 TEdone
("preload " ^
(btos conf.preload))
2466 conf.verbose
<- not
conf.verbose
;
2467 TEdone
("verbose " ^
(btos conf.verbose
))
2470 conf.debug
<- not
conf.debug
;
2471 TEdone
("debug " ^
(btos conf.debug
))
2474 conf.maxhfit
<- not
conf.maxhfit
;
2476 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2477 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2480 conf.crophack
<- not
conf.crophack
;
2481 TEdone
("crophack " ^
btos conf.crophack
)
2485 match conf.maxwait
with
2487 conf.maxwait
<- Some infinity
;
2488 "always wait for page to complete"
2490 conf.maxwait
<- None
;
2491 "show placeholder if page is not ready"
2496 conf.underinfo
<- not
conf.underinfo
;
2497 TEdone
("underinfo " ^
btos conf.underinfo
)
2500 conf.savebmarks
<- not
conf.savebmarks
;
2501 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2507 match state.layout with
2512 conf.interpagespace <- int_of_string
s;
2513 state.maxy <- calcheight ();
2514 let y = getpagey pageno in
2517 state.text <- Printf.sprintf
"bad integer `%s': %s"
2518 s (Printexc.to_string exc
)
2520 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2523 reqlayout conf.angle
(not
conf.proportional
);
2524 TEdone
("proportional display " ^
btos conf.proportional
)
2527 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2528 TEdone
("trim margins " ^
btos conf.trimmargins
)
2531 conf.invert
<- not
conf.invert
;
2532 TEdone
("invert colors " ^
btos conf.invert
)
2536 cbput state.hists
.sel
s;
2539 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2543 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2549 class type lvsource
= object
2550 method getitemcount
: int
2551 method getitem
: int -> (string * int)
2552 method hasaction
: int -> bool
2561 method getactive
: int
2562 method getfirst
: int
2563 method getqsearch
: string
2564 method setqsearch
: string -> unit
2568 class virtual lvsourcebase
= object
2569 val mutable m_active
= 0
2570 val mutable m_first
= 0
2571 val mutable m_qsearch
= ""
2572 val mutable m_pan
= 0
2573 method getactive
= m_active
2574 method getfirst
= m_first
2575 method getqsearch
= m_qsearch
2576 method getpan
= m_pan
2577 method setqsearch
s = m_qsearch
<- s
2580 let withoutlastutf8 s =
2581 let len = String.length
s in
2589 let b = Char.code
s.[pos
] in
2590 if b land 0b110000 = 0b11000000
2595 if Char.code
s.[len-1] land 0x80 = 0
2599 String.sub
s 0 first;
2602 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2604 state.mode
<- Textentry
(te
, onleave
);
2607 G.postRedisplay "textentrykeyboard enttext";
2609 let histaction cmd =
2612 | Some
(action, _
) ->
2613 state.mode
<- Textentry
(
2614 (c, action cmd, opthist
, onkey
, ondone), onleave
2616 G.postRedisplay "textentry histaction"
2619 | 0xff08 -> (* backspace *)
2620 let s = withoutlastutf8 text in
2621 let len = String.length
s in
2625 G.postRedisplay "textentrykeyboard after cancel";
2628 enttext (c, s, opthist
, onkey
, ondone)
2634 G.postRedisplay "textentrykeyboard after confirm"
2636 | 0xff52 -> histaction HCprev
2637 | 0xff54 -> histaction HCnext
2638 | 0xff50 -> histaction HCfirst
2639 | 0xff57 -> histaction HClast
2641 | 0xff1b -> (* escape*)
2642 if String.length
text = 0
2644 begin match opthist
with
2646 | Some
(_
, onhistcancel
) -> onhistcancel
()
2650 G.postRedisplay "textentrykeyboard after cancel2"
2653 enttext (c, "", opthist
, onkey
, ondone)
2656 | 0xff9f | 0xffff -> () (* delete *)
2658 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2659 begin match onkey
text key with
2663 G.postRedisplay "textentrykeyboard after confirm2";
2666 enttext (c, text, opthist
, onkey
, ondone);
2670 G.postRedisplay "textentrykeyboard after cancel3"
2673 state.mode
<- Textentry
(te
, onleave
);
2674 G.postRedisplay "textentrykeyboard switch";
2678 vlog "unhandled key %#x" key
2681 let firstof first active
=
2682 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2683 then max
0 (active
- (fstate.maxrows
/2))
2687 let calcfirst first active
=
2690 let rows = active
- first in
2691 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2695 let scrollph y maxy =
2696 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2697 let sh = float conf.winh
/. sh in
2698 let sh = max
sh (float conf.scrollh
) in
2703 else float y /. float maxy
2705 let position = (float conf.winh
-. sh) *. percent in
2708 if position +. sh > float conf.winh
2709 then float conf.winh
-. sh
2715 let coe s = (s :> uioh
);;
2717 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2719 val m_pan
= source#getpan
2720 val m_first
= source#getfirst
2721 val m_active
= source#getactive
2722 val m_qsearch
= source#getqsearch
2723 val m_prev_uioh
= state.uioh
2725 method private elemunder
y =
2726 let n = y / (fstate.fontsize
+1) in
2727 if m_first
+ n < source#getitemcount
2729 if source#hasaction
(m_first
+ n)
2730 then Some
(m_first
+ n)
2737 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2738 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2739 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2740 GlDraw.color
(1., 1., 1.);
2741 Gl.enable `texture_2d
;
2742 let fs = fstate.fontsize
in
2744 let ww = fstate.wwidth
in
2745 let tabw = 30.0*.ww in
2746 let itemcount = source#getitemcount
in
2748 if (row - m_first
) * nfs > conf.winh
2751 if row >= 0 && row < itemcount
2753 let (s, level
) = source#getitem
row in
2754 let y = (row - m_first
) * nfs in
2755 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2758 Gl.disable `texture_2d
;
2759 GlDraw.polygon_mode `both `line
;
2760 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2761 GlDraw.rect (1., float (y + 1))
2762 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2763 GlDraw.polygon_mode `both `fill
;
2764 GlDraw.color
(1., 1., 1.);
2765 Gl.enable `texture_2d
;
2768 let drawtabularstring s =
2769 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2772 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2775 let len = String.length
s - tabpos - 1 in
2776 let s1 = String.sub
s 0 tabpos
2777 and s2
= String.sub
s (tabpos + 1) len in
2778 let nx = drawstr x s1 in
2780 let x = x +. (max
tabw sw) in
2787 let _ = drawtabularstring s in
2794 Gl.disable `texture_2d
;
2796 method updownlevel incr
=
2797 let len = source#getitemcount
in
2799 if m_active
>= 0 && m_active
< len
2800 then snd
(source#getitem m_active
)
2804 if i
= len then i
-1 else if i
= -1 then 0 else
2805 let _, l = source#getitem i
in
2806 if l != curlevel then i
else flow (i
+incr
)
2808 let active = flow m_active
in
2809 let first = calcfirst m_first
active in
2810 G.postRedisplay "outline updownlevel";
2811 {< m_active
= active; m_first
= first >}
2813 method private key1
key mask
=
2814 let set1 active first qsearch
=
2815 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2817 let search active pattern incr
=
2820 if n >= 0 && n < source#getitemcount
2822 let s, _ = source#getitem
n in
2824 (try ignore
(Str.search_forward
re s 0); true
2825 with Not_found
-> false)
2827 else loop (n + incr
)
2834 let re = Str.regexp_case_fold pattern
in
2840 let itemcount = source#getitemcount
in
2841 let find start incr
=
2843 if i
= -1 || i
= itemcount
2846 if source#hasaction i
2848 else find (i
+ incr
)
2853 let set active first =
2854 let first = bound first 0 (itemcount - fstate.maxrows
) in
2856 coe {< m_active
= active; m_first
= first >}
2859 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2861 let incr1 = if incr
> 0 then 1 else -1 in
2862 if isvisible m_first m_active
2865 let next = m_active
+ incr
in
2867 if next < 0 || next >= itemcount
2869 else find next incr1
2871 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2877 let first = m_first
+ incr
in
2878 let first = bound first 0 (itemcount - 1) in
2880 let next = m_active
+ incr
in
2881 let next = bound next 0 (itemcount - 1) in
2884 let active = if next = -1 then m_active
else next in
2887 let first = min
next m_first
in
2889 if abs
(next - first) > fstate.maxrows
2895 let first = m_first
+ incr
in
2896 let first = bound first 0 (itemcount - 1) in
2898 let next = m_active
+ incr
in
2899 let next = bound next 0 (itemcount - 1) in
2900 let next = find next incr1 in
2902 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2904 let active = if m_active
= -1 then next else m_active
in
2909 if isvisible first active
2915 G.postRedisplay "listview navigate";
2919 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2920 let incr = if key = 0x72 then -1 else 1 in
2922 match search (m_active
+ incr) m_qsearch
incr with
2924 state.text <- m_qsearch ^
" [not found]";
2927 state.text <- m_qsearch
;
2928 active, firstof m_first
active
2930 G.postRedisplay "listview ctrl-r/s";
2931 set1 active first m_qsearch
;
2933 | 0xff08 -> (* backspace *)
2934 if String.length m_qsearch
= 0
2937 let qsearch = withoutlastutf8 m_qsearch
in
2938 let len = String.length
qsearch in
2942 G.postRedisplay "listview empty qsearch";
2943 set1 m_active m_first
"";
2947 match search m_active
qsearch ~
-1 with
2949 state.text <- qsearch ^
" [not found]";
2952 state.text <- qsearch;
2953 active, firstof m_first
active
2955 G.postRedisplay "listview backspace qsearch";
2956 set1 active first qsearch
2959 | key when ((key >= 32 && key < 127)
2960 || (key != 0 && key land 0xff00 != 0xff00)) ->
2962 if key >= 32 && key < 127
2963 then addchar m_qsearch
(Char.chr
key)
2964 else m_qsearch ^
Wsi.toutf8
key
2967 match search m_active
pattern 1 with
2969 state.text <- pattern ^
" [not found]";
2972 state.text <- pattern;
2973 active, firstof m_first
active
2975 G.postRedisplay "listview qsearch add";
2976 set1 active first pattern;
2978 | 0xff1b -> (* escape *)
2980 if String.length m_qsearch
= 0
2982 G.postRedisplay "list view escape";
2985 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2987 | None
-> m_prev_uioh
2992 G.postRedisplay "list view kill qsearch";
2993 source#setqsearch
"";
2994 coe {< m_qsearch
= "" >}
2997 | 0xff0d -> (* return *)
2999 let self = {< m_qsearch
= "" >} in
3000 source#setqsearch
"";
3002 G.postRedisplay "listview enter";
3003 if m_active
>= 0 && m_active
< source#getitemcount
3005 source#exit
(coe self) false m_active m_first m_pan
"";
3008 source#exit
(coe self) true m_active m_first m_pan
"";
3011 begin match opt with
3012 | None
-> m_prev_uioh
3016 | 0xff9f | 0xffff -> (* delete *)
3019 | 0xff52 -> navigate ~
-1 (* up *)
3020 | 0xff54 -> navigate 1 (* down *)
3021 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3022 | 0xff56 -> navigate fstate.maxrows
(* next *)
3024 | 0xff53 -> (* right *)
3026 G.postRedisplay "listview right";
3027 coe {< m_pan
= m_pan
- 1 >}
3029 | 0xff51 -> (* left *)
3031 G.postRedisplay "listview left";
3032 coe {< m_pan
= m_pan
+ 1 >}
3034 | 0xff50 -> (* home *)
3035 let active = find 0 1 in
3036 G.postRedisplay "listview home";
3039 | 0xff57 -> (* end *)
3040 let first = max
0 (itemcount - fstate.maxrows
) in
3041 let active = find (itemcount - 1) ~
-1 in
3042 G.postRedisplay "listview end";
3045 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3049 dolog "listview unknown key %#x" key; coe self
3051 method key key mask
=
3052 match state.mode
with
3053 | Textentry te
-> textentrykeyboard key mask te
; coe self
3054 | _ -> self#key1
key mask
3056 method button button down
x y _ =
3059 | 1 when x > conf.winw
- conf.scrollbw
->
3060 G.postRedisplay "listview scroll";
3063 let _, position, sh = self#
scrollph in
3064 if y > truncate
position && y < truncate
(position +. sh)
3066 state.mstate
<- Mscrolly
;
3070 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3071 let first = truncate
(s *. float source#getitemcount
) in
3072 let first = min source#getitemcount
first in
3073 Some
(coe {< m_first
= first; m_active
= first >})
3075 state.mstate
<- Mnone
;
3078 | 1 when not down
->
3079 begin match self#elemunder
y with
3081 G.postRedisplay "listview click";
3083 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3087 | n when (n == 4 || n == 5) && not down
->
3088 let len = source#getitemcount
in
3090 if n = 5 && m_first
+ fstate.maxrows
>= len
3094 let first = m_first
+ (if n == 4 then -1 else 1) in
3095 bound first 0 (len - 1)
3097 G.postRedisplay "listview wheel";
3098 Some
(coe {< m_first
= first >})
3103 | None
-> m_prev_uioh
3107 match state.mstate
with
3109 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3110 let first = truncate
(s *. float source#getitemcount
) in
3111 let first = min source#getitemcount
first in
3112 G.postRedisplay "listview motion";
3113 coe {< m_first
= first; m_active
= first >}
3116 method pmotion
x y =
3117 if x < conf.winw
- conf.scrollbw
3120 match self#elemunder
y with
3121 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3122 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3126 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3131 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3135 method infochanged
_ = ()
3137 method scrollpw
= (0, 0.0, 0.0)
3139 let nfs = fstate.fontsize
+ 1 in
3140 let y = m_first
* nfs in
3141 let itemcount = source#getitemcount
in
3142 let maxi = max
0 (itemcount - fstate.maxrows
) in
3143 let maxy = maxi * nfs in
3144 let p, h = scrollph y maxy in
3147 method modehash
= modehash
3150 class outlinelistview ~source
=
3153 ~source
:(source
:> lvsource
)
3155 ~modehash
:(findkeyhash conf "outline")
3158 method key key mask
=
3159 let calcfirst first active =
3162 let rows = active - first in
3163 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3167 let active = m_active
+ incr in
3168 let active = bound active 0 (source#getitemcount
- 1) in
3169 let first = calcfirst m_first
active in
3170 G.postRedisplay "outline navigate";
3171 coe {< m_active
= active; m_first
= first >}
3173 let ctrl = Wsi.withctrl mask
in
3175 | 110 when ctrl -> (* ctrl-n *)
3176 source#narrow m_qsearch
;
3177 G.postRedisplay "outline ctrl-n";
3178 coe {< m_first
= 0; m_active
= 0 >}
3180 | 117 when ctrl -> (* ctrl-u *)
3182 G.postRedisplay "outline ctrl-u";
3184 coe {< m_first
= 0; m_active
= 0 >}
3186 | 108 when ctrl -> (* ctrl-l *)
3187 let first = m_active
- (fstate.maxrows
/ 2) in
3188 G.postRedisplay "outline ctrl-l";
3189 coe {< m_first
= first >}
3191 | 0xff9f | 0xffff -> (* delete *)
3192 source#remove m_active
;
3193 G.postRedisplay "outline delete";
3194 let active = max
0 (m_active
-1) in
3195 coe {< m_first
= firstof m_first
active;
3196 m_active
= active >}
3198 | 0xff52 -> navigate ~
-1 (* up *)
3199 | 0xff54 -> navigate 1 (* down *)
3200 | 0xff55 -> (* prior *)
3201 navigate ~
-(fstate.maxrows
)
3202 | 0xff56 -> (* next *)
3203 navigate fstate.maxrows
3205 | 0xff53 -> (* [ctrl-]right *)
3209 G.postRedisplay "outline ctrl right";
3210 {< m_pan
= m_pan
+ 1 >}
3212 else self#updownlevel
1
3216 | 0xff51 -> (* [ctrl-]left *)
3220 G.postRedisplay "outline ctrl left";
3221 {< m_pan
= m_pan
- 1 >}
3223 else self#updownlevel ~
-1
3227 | 0xff50 -> (* home *)
3228 G.postRedisplay "outline home";
3229 coe {< m_first
= 0; m_active
= 0 >}
3231 | 0xff57 -> (* end *)
3232 let active = source#getitemcount
- 1 in
3233 let first = max
0 (active - fstate.maxrows
) in
3234 G.postRedisplay "outline end";
3235 coe {< m_active
= active; m_first
= first >}
3237 | _ -> super#
key key mask
3240 let outlinesource usebookmarks
=
3243 inherit lvsourcebase
3244 val mutable m_items
= empty
3245 val mutable m_orig_items
= empty
3246 val mutable m_prev_items
= empty
3247 val mutable m_narrow_pattern
= ""
3248 val mutable m_hadremovals
= false
3250 method getitemcount
=
3251 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3254 if n == Array.length m_items
&& m_hadremovals
3256 ("[Confirm removal]", 0)
3258 let s, n, _ = m_items
.(n) in
3261 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3262 ignore
(uioh
, first, qsearch);
3263 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3265 if String.length m_narrow_pattern
= 0
3271 if not
confrimremoval
3273 let _, _, anchor = m_items
.(active) in
3278 state.bookmarks
<- Array.to_list m_items
;
3279 m_orig_items
<- m_items
;
3282 else m_items
<- items;
3286 method hasaction
_ = true
3289 if Array.length m_items
!= Array.length m_orig_items
3290 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3293 method narrow
pattern =
3294 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3298 let rec loop accu n =
3301 m_narrow_pattern
<- pattern;
3302 m_items
<- Array.of_list
accu
3305 let (s, _, _) as o = m_items
.(n) in
3307 if (try ignore
(Str.search_forward
re s 0); true
3308 with Not_found
-> false)
3314 loop [] (Array.length m_items
- 1)
3319 then Array.of_list
state.bookmarks
3322 m_items
<- m_orig_items
3327 if m
>= 0 && m
< Array.length m_items
3329 m_hadremovals
<- true;
3330 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3331 let n = if n >= m
then n+1 else n in
3336 method reset
anchor items =
3337 m_hadremovals
<- false;
3338 if m_orig_items
== empty || m_prev_items
!= items
3340 m_orig_items
<- items;
3341 if String.length m_narrow_pattern
= 0
3342 then m_items
<- items;
3344 m_prev_items
<- items;
3345 let rely = getanchory anchor in
3347 let rec loop n best bestd
=
3348 if n = Array.length m_items
3351 let (_, _, anchor) = m_items
.(n) in
3352 let orely = getanchory anchor in
3353 let d = abs
(orely - rely) in
3356 else loop (n+1) best bestd
3361 m_first
<- firstof m_first
active
3365 let enterselector usebookmarks
=
3366 let source = outlinesource usebookmarks
in
3370 then Array.of_list
state.bookmarks
3373 if Array.length
outlines = 0
3375 showtext ' ' errmsg
;
3378 state.text <- source#greetmsg
;
3379 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3380 let anchor = getanchor () in
3381 source#reset
anchor outlines;
3382 state.uioh
<- coe (new outlinelistview ~
source);
3383 G.postRedisplay "enter selector";
3387 let enteroutlinemode =
3388 let f = enterselector false in
3389 fun ()-> f "Document has no outline";
3392 let enterbookmarkmode =
3393 let f = enterselector true in
3394 fun () -> f "Document has no bookmarks (yet)";
3397 let color_of_string s =
3398 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3399 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3403 let color_to_string (r
, g
, b) =
3404 let r = truncate
(r *. 256.0)
3405 and g
= truncate
(g
*. 256.0)
3406 and b = truncate
(b *. 256.0) in
3407 Printf.sprintf
"%d/%d/%d" r g
b
3410 let irect_of_string s =
3411 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3414 let irect_to_string (x0,y0,x1,y1) =
3415 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3418 let makecheckers () =
3419 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3421 converted by Issac Trotts. July 25, 2002 *)
3422 let image_height = 64
3423 and image_width
= 64 in
3427 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3429 for i
= 0 to image_width
- 1 do
3430 for j
= 0 to image_height - 1 do
3431 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3432 (if (i
land 8 ) lxor (j
land 8) = 0
3433 then [|255;255;255|] else [|200;200;200|])
3438 let image = make_image () in
3439 let id = GlTex.gen_texture
() in
3440 GlTex.bind_texture `texture_2d
id;
3441 GlPix.store
(`unpack_alignment
1);
3442 GlTex.image2d
image;
3443 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3446 `mag_filter `nearest
;
3447 `min_filter `nearest
];
3451 let setcheckers enabled
=
3452 match state.texid
with
3454 if enabled
then state.texid
<- Some
(makecheckers ())
3459 GlTex.delete_texture texid
;
3460 state.texid
<- None
;
3464 let int_of_string_with_suffix s =
3465 let l = String.length
s in
3469 let suffix = Char.lowercase
s.[l-1] in
3471 | 'k'
-> String.sub
s 0 (l-1), 10
3472 | 'm'
-> String.sub
s 0 (l-1), 20
3473 | 'g'
-> String.sub
s 0 (l-1), 30
3477 let n = int_of_string
s1 in
3478 let m = n lsl shift
in
3480 then raise
(Failure
"value too large")
3484 let string_with_suffix_of_int n =
3492 if n land ((1 lsl 20) - 1) = 0
3495 if n land ((1 lsl 10) - 1) = 0
3502 let h = n mod 1000 in
3505 then string_of_int
h ^
s
3507 let s = Printf.sprintf
"_%03d%s" h s in
3514 let defghyllscroll = (40, 8, 32);;
3515 let ghyllscroll_of_string s =
3516 let (n, a, b) as nab
=
3519 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3521 if n <= a || n <= b || a >= b
3522 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3526 let ghyllscroll_to_string ((n, a, b) as nab
) =
3527 if nab
= defghyllscroll
3529 else Printf.sprintf
"%d,%d,%d" n a b;
3532 let describe_location () =
3534 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3536 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3537 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3541 else (100. *. (float state.y /. float maxy))
3545 Printf.sprintf
"page %d of %d [%.2f%%]"
3546 (fn+1) state.pagecount
percent
3549 "pages %d-%d of %d [%.2f%%]"
3550 (fn+1) (ln
+1) state.pagecount
percent
3554 let btos b = if b then "\xe2\x88\x9a" else "" in
3555 let showextended = ref false in
3556 let leave mode
= function
3557 | Confirm
-> state.mode
<- mode
3558 | Cancel
-> state.mode
<- mode
in
3561 val mutable m_first_time
= true
3562 val mutable m_l
= []
3563 val mutable m_a
= [||]
3564 val mutable m_prev_uioh
= nouioh
3565 val mutable m_prev_mode
= View
3567 inherit lvsourcebase
3569 method reset prev_mode prev_uioh
=
3570 m_a
<- Array.of_list
(List.rev m_l
);
3572 m_prev_mode
<- prev_mode
;
3573 m_prev_uioh
<- prev_uioh
;
3577 if n >= Array.length m_a
3581 | _, _, _, Action
_ -> m_active
<- n
3585 m_first_time
<- false;
3588 method int name get
set =
3590 (name
, `
int get
, 1, Action
(
3593 try set (int_of_string
s)
3595 state.text <- Printf.sprintf
"bad integer `%s': %s"
3596 s (Printexc.to_string exn
)
3599 let te = name ^
": ", "", None
, intentry, ondone in
3600 state.mode
<- Textentry
(te, leave m_prev_mode
);
3604 method int_with_suffix name get
set =
3606 (name
, `intws get
, 1, Action
(
3609 try set (int_of_string_with_suffix s)
3611 state.text <- Printf.sprintf
"bad integer `%s': %s"
3612 s (Printexc.to_string exn
)
3616 name ^
": ", "", None
, intentry_with_suffix, ondone
3618 state.mode
<- Textentry
(te, leave m_prev_mode
);
3622 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3624 (name
, `
bool (btos, get
), offset
, Action
(
3631 method color name get
set =
3633 (name
, `color get
, 1, Action
(
3635 let invalid = (nan
, nan
, nan
) in
3638 try color_of_string s
3640 state.text <- Printf.sprintf
"bad color `%s': %s"
3641 s (Printexc.to_string exn
);
3647 let te = name ^
": ", "", None
, textentry, ondone in
3648 state.text <- color_to_string (get
());
3649 state.mode
<- Textentry
(te, leave m_prev_mode
);
3653 method string name get
set =
3655 (name
, `
string get
, 1, Action
(
3657 let ondone s = set s in
3658 let te = name ^
": ", "", None
, textentry, ondone in
3659 state.mode
<- Textentry
(te, leave m_prev_mode
);
3663 method colorspace name get
set =
3665 (name
, `
string get
, 1, Action
(
3668 let vals = [| "rgb"; "bgr"; "gray" |] in
3670 inherit lvsourcebase
3673 m_active
<- int_of_colorspace conf.colorspace
;
3676 method getitemcount
= Array.length
vals
3677 method getitem
n = (vals.(n), 0)
3678 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3679 ignore
(uioh
, first, pan
, qsearch);
3680 if not cancel
then set active;
3682 method hasaction
_ = true
3686 let modehash = findkeyhash conf "info" in
3687 coe (new listview ~
source ~trusted
:true ~
modehash)
3690 method caption
s offset
=
3691 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3693 method caption2
s f offset
=
3694 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3696 method getitemcount
= Array.length m_a
3699 let tostr = function
3700 | `
int f -> string_of_int
(f ())
3701 | `intws
f -> string_with_suffix_of_int (f ())
3703 | `color
f -> color_to_string (f ())
3704 | `
bool (btos, f) -> btos (f ())
3707 let name, t
, offset
, _ = m_a
.(n) in
3708 ((let s = tostr t
in
3709 if String.length
s > 0
3710 then Printf.sprintf
"%s\t%s" name s
3714 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3718 m_qsearch
<- qsearch;
3720 match m_a
.(active) with
3721 | _, _, _, Action
f -> f uioh
3733 method hasaction
n =
3735 | _, _, _, Action
_ -> true
3739 let rec fillsrc prevmode prevuioh
=
3740 let sep () = src#caption
"" 0 in
3741 let colorp name get
set =
3743 (fun () -> color_to_string (get
()))
3746 let c = color_of_string v in
3749 state.text <- Printf.sprintf
"bad color `%s': %s"
3750 v (Printexc.to_string exn
);
3753 let oldmode = state.mode
in
3754 let birdseye = isbirdseye state.mode
in
3756 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3758 src#
bool "presentation mode"
3759 (fun () -> conf.presentation)
3761 conf.presentation <- v;
3762 state.anchor <- getanchor ();
3765 src#
bool "ignore case in searches"
3766 (fun () -> conf.icase
)
3767 (fun v -> conf.icase
<- v);
3770 (fun () -> conf.preload)
3771 (fun v -> conf.preload <- v);
3773 src#
bool "highlight links"
3774 (fun () -> conf.hlinks
)
3775 (fun v -> conf.hlinks
<- v);
3777 src#
bool "under info"
3778 (fun () -> conf.underinfo
)
3779 (fun v -> conf.underinfo
<- v);
3781 src#
bool "persistent bookmarks"
3782 (fun () -> conf.savebmarks
)
3783 (fun v -> conf.savebmarks
<- v);
3785 src#
bool "proportional display"
3786 (fun () -> conf.proportional
)
3787 (fun v -> reqlayout conf.angle
v);
3789 src#
bool "trim margins"
3790 (fun () -> conf.trimmargins
)
3791 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3793 src#
bool "persistent location"
3794 (fun () -> conf.jumpback
)
3795 (fun v -> conf.jumpback
<- v);
3798 src#
int "inter-page space"
3799 (fun () -> conf.interpagespace)
3801 conf.interpagespace <- n;
3803 match state.layout with
3808 state.maxy <- calcheight ();
3809 let y = getpagey pageno in
3814 (fun () -> conf.pagebias
)
3815 (fun v -> conf.pagebias
<- v);
3817 src#
int "scroll step"
3818 (fun () -> conf.scrollstep
)
3819 (fun n -> conf.scrollstep
<- n);
3821 src#
int "auto scroll step"
3823 match state.autoscroll
with
3825 | _ -> conf.autoscrollstep
)
3827 if state.autoscroll
<> None
3828 then state.autoscroll
<- Some
n;
3829 conf.autoscrollstep
<- n);
3832 (fun () -> truncate
(conf.zoom *. 100.))
3833 (fun v -> setzoom ((float v) /. 100.));
3836 (fun () -> conf.angle
)
3837 (fun v -> reqlayout v conf.proportional
);
3839 src#
int "scroll bar width"
3840 (fun () -> state.scrollw
)
3844 reshape conf.winw
conf.winh
;
3847 src#
int "scroll handle height"
3848 (fun () -> conf.scrollh
)
3849 (fun v -> conf.scrollh
<- v;);
3851 src#
int "thumbnail width"
3852 (fun () -> conf.thumbw
)
3854 conf.thumbw
<- min
4096 v;
3857 leavebirdseye beye
false;
3862 src#
string "columns"
3864 match conf.columns
with
3866 | Some
(multicol
, _) -> columns_to_string multicol
)
3868 let n, a, b = columns_of_string v in
3872 src#caption
"Presentation mode" 0;
3873 src#
bool "scrollbar visible"
3874 (fun () -> conf.scrollbarinpm
)
3876 if v != conf.scrollbarinpm
3878 conf.scrollbarinpm
<- v;
3879 if conf.presentation
3881 state.scrollw
<- if v then conf.scrollbw
else 0;
3882 reshape conf.winw
conf.winh
;
3888 src#caption
"Pixmap cache" 0;
3889 src#int_with_suffix
"size (advisory)"
3890 (fun () -> conf.memlimit
)
3891 (fun v -> conf.memlimit
<- v);
3894 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3895 (string_with_suffix_of_int state.memused
)
3896 (Hashtbl.length
state.tilemap
)) 1;
3899 src#caption
"Layout" 0;
3900 src#caption2
"Dimension"
3902 Printf.sprintf
"%dx%d (virtual %dx%d)"
3908 src#caption2
"Position" (fun () ->
3909 Printf.sprintf
"%dx%d" state.x state.y
3912 src#caption2
"Visible" (fun () -> describe_location ()) 1
3916 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3917 "Save these parameters as global defaults at exit"
3918 (fun () -> conf.bedefault
)
3919 (fun v -> conf.bedefault
<- v)
3923 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3924 src#
bool ~offset
:0 ~
btos "Extended parameters"
3925 (fun () -> !showextended)
3926 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3930 (fun () -> conf.checkers
)
3931 (fun v -> conf.checkers
<- v; setcheckers v);
3932 src#
bool "update cursor"
3933 (fun () -> conf.updatecurs
)
3934 (fun v -> conf.updatecurs
<- v);
3936 (fun () -> conf.verbose
)
3937 (fun v -> conf.verbose
<- v);
3938 src#
bool "invert colors"
3939 (fun () -> conf.invert
)
3940 (fun v -> conf.invert
<- v);
3942 (fun () -> conf.maxhfit
)
3943 (fun v -> conf.maxhfit
<- v);
3944 src#
bool "redirect stderr"
3945 (fun () -> conf.redirectstderr)
3946 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3947 src#
string "uri launcher"
3948 (fun () -> conf.urilauncher
)
3949 (fun v -> conf.urilauncher
<- v);
3950 src#
string "path launcher"
3951 (fun () -> conf.pathlauncher
)
3952 (fun v -> conf.pathlauncher
<- v);
3953 src#
string "tile size"
3954 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3957 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3958 conf.tileh
<- max
64 w;
3959 conf.tilew
<- max
64 h;
3962 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3963 v (Printexc.to_string exn
));
3964 src#
int "texture count"
3965 (fun () -> conf.texcount
)
3968 then conf.texcount
<- v
3969 else showtext '
!'
" Failed to set texture count please retry later"
3971 src#
int "slice height"
3972 (fun () -> conf.sliceheight
)
3974 conf.sliceheight
<- v;
3975 wcmd "sliceh" [`i
conf.sliceheight
];
3977 src#
int "anti-aliasing level"
3978 (fun () -> conf.aalevel
)
3980 conf.aalevel
<- bound v 0 8;
3981 state.anchor <- getanchor ();
3982 opendoc state.path
state.password
;
3984 src#
int "ui font size"
3985 (fun () -> fstate.fontsize
)
3986 (fun v -> setfontsize (bound v 5 100));
3987 colorp "background color"
3988 (fun () -> conf.bgcolor
)
3989 (fun v -> conf.bgcolor
<- v);
3990 src#
bool "crop hack"
3991 (fun () -> conf.crophack
)
3992 (fun v -> conf.crophack
<- v);
3993 src#
string "trim fuzz"
3994 (fun () -> irect_to_string conf.trimfuzz
)
3997 conf.trimfuzz
<- irect_of_string v;
3999 then settrim true conf.trimfuzz
;
4001 state.text <- Printf.sprintf
"bad irect `%s': %s"
4002 v (Printexc.to_string exn
)
4004 src#
string "throttle"
4006 match conf.maxwait
with
4007 | None
-> "show place holder if page is not ready"
4010 then "wait for page to fully render"
4012 "wait " ^ string_of_float
time
4013 ^
" seconds before showing placeholder"
4017 let f = float_of_string
v in
4019 then conf.maxwait
<- None
4020 else conf.maxwait
<- Some
f
4022 state.text <- Printf.sprintf
"bad time `%s': %s"
4023 v (Printexc.to_string exn
)
4025 src#
string "ghyll scroll"
4027 match conf.ghyllscroll
with
4029 | Some nab
-> ghyllscroll_to_string nab
4034 if String.length
v = 0
4036 else Some
(ghyllscroll_of_string v)
4038 conf.ghyllscroll
<- gs
4040 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4041 v (Printexc.to_string exn
)
4043 src#
string "selection command"
4044 (fun () -> conf.selcmd
)
4045 (fun v -> conf.selcmd
<- v);
4046 src#colorspace
"color space"
4047 (fun () -> colorspace_to_string conf.colorspace
)
4049 conf.colorspace
<- colorspace_of_int v;
4056 src#caption
"Document" 0;
4057 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4058 src#caption2
"Pages"
4059 (fun () -> string_of_int
state.pagecount
) 1;
4060 src#caption2
"Dimensions"
4061 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4065 src#caption
"Trimmed margins" 0;
4066 src#caption2
"Dimensions"
4067 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4070 src#reset prevmode prevuioh
;
4074 let prevmode = state.mode
4075 and prevuioh
= state.uioh in
4076 fillsrc prevmode prevuioh
;
4077 let source = (src :> lvsource
) in
4078 let modehash = findkeyhash conf "info" in
4079 state.uioh <- coe (object (self)
4080 inherit listview ~
source ~trusted
:true ~
modehash as super
4081 val mutable m_prevmemused
= 0
4082 method infochanged
= function
4084 if m_prevmemused
!= state.memused
4086 m_prevmemused
<- state.memused
;
4087 G.postRedisplay "memusedchanged";
4089 | Pdim
-> G.postRedisplay "pdimchanged"
4090 | Docinfo
-> fillsrc prevmode prevuioh
4092 method key key mask
=
4093 if not
(Wsi.withctrl mask
)
4096 | 0xff51 -> coe (self#updownlevel ~
-1)
4097 | 0xff53 -> coe (self#updownlevel
1)
4098 | _ -> super#
key key mask
4099 else super#
key key mask
4101 G.postRedisplay "info";
4107 inherit lvsourcebase
4108 method getitemcount
= Array.length
state.help
4110 let s, n, _ = state.help
.(n) in
4113 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4117 m_qsearch
<- qsearch;
4118 match state.help
.(active) with
4119 | _, _, Action
f -> Some
(f uioh)
4129 method hasaction
n =
4130 match state.help
.(n) with
4131 | _, _, Action
_ -> true
4138 let modehash = findkeyhash conf "help" in
4139 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4140 G.postRedisplay "help";
4145 let re = Str.regexp
"[\r\n]" in
4147 inherit lvsourcebase
4148 val mutable m_items
= [||]
4150 method getitemcount
= 1 + Array.length m_items
4155 else m_items
.(n-1), 0
4157 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4162 then Buffer.clear
state.errmsgs
;
4163 m_qsearch
<- qsearch;
4170 method hasaction
n =
4174 state.newerrmsgs
<- false;
4175 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4176 m_items
<- Array.of_list
l
4184 let source = (msgsource :> lvsource
) in
4185 let modehash = findkeyhash conf "listview" in
4186 state.uioh <- coe (object
4187 inherit listview ~
source ~trusted
:false ~
modehash as super
4190 then msgsource#reset
;
4193 G.postRedisplay "msgs";
4196 let quickbookmark ?title
() =
4197 match state.layout with
4203 let sec = Unix.gettimeofday
() in
4204 let tm = Unix.localtime
sec in
4205 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4209 (tm.Unix.tm_year
+ 1900)
4212 | Some
title -> title
4215 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4220 state.fullscreen
<- None
;
4224 let setautoscrollspeed step goingdown
=
4225 let incr = max
1 ((abs step
) / 2) in
4226 let incr = if goingdown
then incr else -incr in
4227 let astep = step
+ incr in
4228 state.autoscroll
<- Some
astep;
4231 let viewkeyboard key mask
=
4233 let mode = state.mode in
4234 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4237 G.postRedisplay "view:enttext"
4239 let ctrl = Wsi.withctrl mask
in
4244 | 0xff1b | 113 -> (* escape / q *)
4245 begin match state.mstate
with
4247 state.mstate
<- Mnone
;
4248 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4249 G.postRedisplay "kill zoom rect";
4251 match state.ranchors
with
4252 | [] -> raise
Wsi.Quit
4253 | (path
, password
, anchor) :: rest
->
4254 state.ranchors
<- rest
;
4255 state.anchor <- anchor;
4256 opendoc path password
4259 | 0xff08 -> (* backspace *)
4260 let y = getnav ~
-1 in
4261 gotoy_and_clear_text y
4269 G.postRedisplay "dehighlight";
4271 | 47 | 63 -> (* / ? *)
4272 let ondone isforw
s =
4273 cbput state.hists
.pat
s;
4274 state.searchpattern
<- s;
4277 let s = String.create
1 in
4278 s.[0] <- Char.chr
key;
4279 enttext (s, "", Some
(onhist state.hists
.pat
),
4280 textentry, ondone (key = 47))
4282 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4283 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4284 setzoom (conf.zoom +. incr)
4286 | 43 | 0xffab -> (* + *)
4289 try int_of_string
s with exc
->
4290 state.text <- Printf.sprintf
"bad integer `%s': %s"
4291 s (Printexc.to_string exc
);
4297 state.text <- "page bias is now " ^ string_of_int
n;
4300 enttext ("page bias: ", "", None
, intentry, ondone)
4302 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4303 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4304 setzoom (max
0.01 (conf.zoom -. decr))
4306 | 45 | 0xffad -> (* - *)
4307 let ondone msg
= state.text <- msg
in
4309 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4310 optentry state.mode, ondone
4313 | 48 when ctrl -> (* ctrl-0 *)
4316 | 49 when ctrl -> (* 1 *)
4317 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4321 | 0xffc6 -> (* f9 *)
4324 | 57 when ctrl -> (* ctrl-9 *)
4327 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4328 when not
ctrl -> (* 0..9 *)
4331 try int_of_string
s with exc
->
4332 state.text <- Printf.sprintf
"bad integer `%s': %s"
4333 s (Printexc.to_string exc
);
4339 cbput state.hists
.pag
(string_of_int
n);
4340 gotopage1 (n + conf.pagebias
- 1) 0;
4343 let pageentry text key =
4344 match Char.unsafe_chr
key with
4345 | 'g'
-> TEdone
text
4346 | _ -> intentry text key
4348 let text = "x" in text.[0] <- Char.chr
key;
4349 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4352 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4353 reshape conf.winw
conf.winh
;
4356 conf.hlinks
<- not
conf.hlinks
;
4357 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4358 G.postRedisplay "toggle highlightlinks";
4361 begin match state.autoscroll
with
4363 conf.autoscrollstep
<- step
;
4364 state.autoscroll
<- None
4366 if conf.autoscrollstep
= 0
4367 then state.autoscroll
<- Some
1
4368 else state.autoscroll
<- Some
conf.autoscrollstep
4372 conf.presentation <- not
conf.presentation;
4373 if conf.presentation
4375 if not
conf.scrollbarinpm
4376 then state.scrollw
<- 0;
4379 state.scrollw
<- conf.scrollbw
;
4381 showtext ' '
("presentation mode " ^
4382 if conf.presentation then "on" else "off");
4383 state.anchor <- getanchor ();
4387 begin match state.fullscreen
with
4389 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4392 state.fullscreen
<- None
;
4397 gotoy_and_clear_text 0
4400 gotopage1 (state.pagecount
- 1) 0
4402 | 112 | 78 -> (* p|N *)
4403 search state.searchpattern
false
4405 | 110 | 0xffc0 -> (* n|F3 *)
4406 search state.searchpattern
true
4409 begin match state.layout with
4412 gotoy_and_clear_text (getpagey l.pageno)
4416 begin match List.rev
state.layout with
4419 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4420 gotoy_and_clear_text (getpagey pageno)
4423 | 0xff9f | 0xffff -> (* delete *)
4424 begin match state.layout with
4427 let pageno = max
0 (l.pageno-1) in
4428 gotoy_and_clear_text (getpagey pageno)
4432 showtext ' '
(describe_location ());
4435 begin match state.layout with
4438 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4443 enterbookmarkmode ()
4445 | 104 | 0xffbe -> (* h|F1 *)
4451 | 101 when conf.redirectstderr -> (* e *)
4456 match state.layout with
4459 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4463 enttext ("bookmark: ", "", None
, textentry, ondone)
4467 showtext ' '
"Quick bookmark added";
4470 begin match state.layout with
4472 let rect = getpdimrect
l.pagedimno
in
4476 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4477 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4479 (truncate
(rect.(1) -. rect.(0)),
4480 truncate
(rect.(3) -. rect.(0)))
4482 let w = truncate
((float w)*.conf.zoom)
4483 and h = truncate
((float h)*.conf.zoom) in
4486 state.anchor <- getanchor ();
4487 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4489 G.postRedisplay "z";
4494 | 50 when ctrl -> (* ctrl-2 *)
4495 let maxw = getmaxw
() in
4497 then setzoom (maxw /. float conf.winw
)
4499 | 60 | 62 -> (* < > *)
4500 reqlayout (conf.angle
+ (if key = 60 then 30 else -30)) conf.proportional
4502 | 91 | 93 -> (* [ ] *)
4504 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4506 G.postRedisplay "brightness";
4508 | 107 | 0xff52 -> (* k up *)
4509 begin match state.autoscroll
with
4511 begin match state.mode with
4512 | Birdseye beye
-> upbirdseye 1 beye
4515 then gotoy (clamp ~
-(conf.winh
/2))
4516 else gotoy (clamp (-conf.scrollstep
))
4519 setautoscrollspeed n false
4522 | 106 | 0xff54 -> (* j down *)
4523 begin match state.autoscroll
with
4525 begin match state.mode with
4526 | Birdseye beye
-> downbirdseye 1 beye
4529 then gotoy_and_clear_text (clamp (conf.winh
/2))
4530 else gotoy_and_clear_text (clamp conf.scrollstep
)
4533 setautoscrollspeed n true
4536 | 0xff51 | 0xff53 when conf.zoom > 1.0 -> (* left / right *)
4544 let dx = if key = 0xff51 then dx else -dx in
4545 state.x <- state.x + dx;
4546 gotoy_and_clear_text state.y
4549 G.postRedisplay "lef/right"
4552 | 0xff55 -> (* prior *)
4556 match state.layout with
4558 | l :: _ -> state.y - l.pagey
4564 | 0xff56 -> (* next *)
4568 match List.rev
state.layout with
4570 | l :: _ -> getpagey l.pageno
4576 | 0xff50 -> gotoghyll 0
4577 | 0xff57 -> gotoghyll (clamp state.maxy)
4578 | 0xff53 when Wsi.withalt mask
->
4579 gotoghyll (getnav ~
-1)
4580 | 0xff51 when Wsi.withalt mask
->
4581 gotoghyll (getnav 1)
4584 state.anchor <- getanchor ();
4585 opendoc state.path
state.password
4590 | 118 when conf.debug
-> (* v *)
4593 match getopaque l.pageno with
4596 let x0, y0, x1, y1 = pagebbox opaque
in
4597 let a,b = float x0, float y0 in
4598 let c,d = float x1, float y0 in
4599 let e,f = float x1, float y1 in
4600 let h,j
= float x0, float y1 in
4601 let rect = (a,b,c,d,e,f,h,j
) in
4603 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4605 G.postRedisplay "v";
4611 let keyboard key mask
=
4612 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4613 then wcmd "interrupt" []
4614 else state.uioh <- state.uioh#
key key mask
4617 let birdseyekeyboard key mask
4618 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4620 match conf.columns
with
4622 | Some
((c, _, _), _) -> c
4625 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4626 let y, h = getpageyh pageno in
4627 let top = (conf.winh
- h) / 2 in
4628 gotoy (max
0 (y - top))
4629 | 0xff0d -> leavebirdseye beye
false
4630 | 0xff1b -> leavebirdseye beye
true (* escape *)
4631 | 0xff52 -> upbirdseye incr beye
(* prior *)
4632 | 0xff54 -> downbirdseye incr beye
(* next *)
4633 | 0xff51 -> upbirdseye 1 beye
(* up *)
4634 | 0xff53 -> downbirdseye 1 beye
(* down *)
4637 begin match state.layout with
4641 state.mode <- Birdseye
(
4642 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4644 gotopage1 l.pageno 0;
4647 let layout = layout (state.y-conf.winh
) conf.winh
in
4649 | [] -> gotoy (clamp (-conf.winh
))
4651 state.mode <- Birdseye
(
4652 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4654 gotopage1 l.pageno 0
4657 | [] -> gotoy (clamp (-conf.winh
))
4661 begin match List.rev
state.layout with
4663 let layout = layout (state.y + conf.winh
) conf.winh
in
4664 begin match layout with
4666 let incr = l.pageh
- l.pagevh in
4671 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4673 G.postRedisplay "birdseye pagedown";
4675 else gotoy (clamp (incr + conf.interpagespace*2));
4679 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4680 gotopage1 l.pageno 0;
4683 | [] -> gotoy (clamp conf.winh
)
4687 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4691 let pageno = state.pagecount
- 1 in
4692 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4693 if not
(pagevisible state.layout pageno)
4696 match List.rev
state.pdims
with
4698 | (_, _, h, _) :: _ -> h
4700 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4701 else G.postRedisplay "birdseye end";
4702 | _ -> viewkeyboard key mask
4707 match state.mode with
4708 | Textentry
_ -> scalecolor 0.4
4709 | View
-> scalecolor 1.0
4710 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4711 if l.pageno = hooverpageno
4714 if l.pageno = pageno
4720 begin match getopaque l.pageno with
4722 if tileready l l.pagex l.pagey
4724 let x = l.pagedispx - l.pagex
4725 and y = l.pagedispy - l.pagey in
4726 postprocess opaque
conf.hlinks
x y;
4732 let scrollindicator () =
4733 let sbw, ph
, sh = state.uioh#
scrollph in
4734 let sbh, pw
, sw = state.uioh#scrollpw
in
4736 GlDraw.color (0.64, 0.64, 0.64);
4738 (float (conf.winw
- sbw), 0.)
4739 (float conf.winw
, float conf.winh
)
4742 (0., float (conf.winh
- sbh))
4743 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4745 GlDraw.color (0.0, 0.0, 0.0);
4748 (float (conf.winw
- sbw), ph
)
4749 (float conf.winw
, ph
+. sh)
4752 (pw
, float (conf.winh
- sbh))
4753 (pw
+. sw, float conf.winh
)
4758 match state.mstate
with
4759 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4762 | Msel
((x0, y0), (x1, y1)) ->
4763 let rec loop = function
4765 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4766 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4767 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4768 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4770 match getopaque l.pageno with
4772 let dx, dy = pagetranslatepoint l 0 0 in
4777 GlMat.mode `modelview
;
4779 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4780 seltext opaque
(x0, y0, x1, y1);
4791 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4792 GlDraw.polygon_mode `both `fill
;
4793 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4795 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4797 if l.pageno = pageno
4799 let dx = float (l.pagedispx - l.pagex) in
4800 let dy = float (l.pagedispy - l.pagey) in
4801 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4802 GlDraw.begins `quads
;
4804 GlDraw.vertex2
(x0+.dx, y0+.dy);
4805 GlDraw.vertex2
(x1+.dx, y1+.dy);
4806 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4807 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4818 GlClear.color (scalecolor2 conf.bgcolor
);
4819 GlClear.clear
[`
color];
4820 List.iter
drawpage state.layout;
4825 begin match state.mstate
with
4826 | Mzoomrect
((x0, y0), (x1, y1)) ->
4828 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4829 GlDraw.polygon_mode `both `fill
;
4830 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4831 GlDraw.rect (float x0, float y0)
4832 (float x1, float y1);
4839 let mx, my
= state.mpos
in
4845 let zoomrect x y x1 y1 =
4848 and y0 = min
y y1 in
4849 gotoy (state.y + y0);
4850 state.anchor <- getanchor ();
4851 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4853 if state.w < conf.winw
- state.scrollw
4854 then (conf.winw
- state.scrollw
- state.w) / 2
4857 state.x <- (state.x + margin) - x0;
4859 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4860 state.mstate
<- Mnone
;
4864 let winw = conf.winw - state.scrollw
- 1 in
4865 let s = float x /. float winw in
4866 let destx = truncate
(float (state.w + winw) *. s) in
4867 state.x <- winw - destx;
4868 gotoy_and_clear_text state.y;
4869 state.mstate
<- Mscrollx
;
4873 let s = float y /. float conf.winh
in
4874 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4875 gotoy_and_clear_text desty;
4876 state.mstate
<- Mscrolly
;
4879 let viewmouse button down
x y mask
=
4881 | n when (n == 4 || n == 5) && not down
->
4882 if Wsi.withctrl mask
4884 match state.mstate
with
4885 | Mzoom
(oldn
, i
) ->
4893 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4895 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4897 let zoom = conf.zoom -. incr in
4899 state.mstate
<- Mzoom
(n, 0);
4901 state.mstate
<- Mzoom
(n, i
+1);
4903 else state.mstate
<- Mzoom
(n, 0)
4905 | _ -> state.mstate
<- Mzoom
(n, 0)
4908 match state.autoscroll
with
4909 | Some step
-> setautoscrollspeed step
(n=4)
4913 then -conf.scrollstep
4914 else conf.scrollstep
4916 let incr = incr * 2 in
4917 let y = clamp incr in
4918 gotoy_and_clear_text y
4921 | 1 when Wsi.withctrl mask
->
4924 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
4925 state.mstate
<- Mpan
(x, y)
4928 state.mstate
<- Mnone
4933 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4935 state.mstate
<- Mzoomrect
(p, p)
4938 match state.mstate
with
4939 | Mzoomrect
((x0, y0), _) ->
4940 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4941 then zoomrect x0 y0 x y
4943 state.mstate
<- Mnone
;
4944 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4945 G.postRedisplay "kill accidental zoom rect";
4948 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4949 state.mstate
<- Mnone
4952 | 1 when x > conf.winw - state.scrollw
->
4955 let _, position, sh = state.uioh#
scrollph in
4956 if y > truncate
position && y < truncate
(position +. sh)
4957 then state.mstate
<- Mscrolly
4960 state.mstate
<- Mnone
4962 | 1 when y > conf.winh
- state.hscrollh ->
4965 let _, position, sw = state.uioh#scrollpw
in
4966 if x > truncate
position && x < truncate
(position +. sw)
4967 then state.mstate
<- Mscrollx
4970 state.mstate
<- Mnone
4973 let dest = if down
then getunder x y else Unone
in
4974 begin match dest with
4975 | Ulinkgoto
(pageno, top) ->
4979 gotopage1 pageno top;
4985 | Uremote
(filename
, pageno) ->
4987 if Sys.file_exists filename
4990 let dir = Filename.dirname
state.path in
4991 let path = Filename.concat
dir filename
in
4992 if Sys.file_exists
path
4996 if String.length
path > 0
4998 let anchor = getanchor () in
4999 let ranchor = state.path, state.password
, anchor in
5000 state.anchor <- (pageno, 0.0);
5001 state.ranchors
<- ranchor :: state.ranchors
;
5004 else showtext '
!'
("Could not find " ^ filename
)
5006 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5008 | Unone
when down
->
5009 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5010 state.mstate
<- Mpan
(x, y);
5012 | Unone
| Utext
_ ->
5015 if conf.angle
mod 360 = 0
5017 state.mstate
<- Msel
((x, y), (x, y));
5018 G.postRedisplay "mouse select";
5022 match state.mstate
with
5025 | Mzoom
_ | Mscrollx
| Mscrolly
->
5026 state.mstate
<- Mnone
5028 | Mzoomrect
((x0, y0), _) ->
5032 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5033 state.mstate
<- Mnone
5035 | Msel
((_, y0), (_, y1)) ->
5036 let rec loop = function
5039 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5040 || ((y1 >= l.pagedispy
5041 && y1 <= (l.pagedispy + l.pagevh)))
5043 match getopaque l.pageno with
5045 copysel
conf.selcmd opaque
;
5046 G.postRedisplay "copysel"
5051 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5052 state.mstate
<- Mnone
;
5059 let birdseyemouse button down
x y mask
5060 (conf, leftx
, _, hooverpageno
, anchor) =
5063 let rec loop = function
5066 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5067 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5069 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5075 | _ -> viewmouse button down
x y mask
5078 let mouse button down
x y mask
=
5079 state.uioh <- state.uioh#button button down
x y mask
;
5083 state.uioh <- state.uioh#
motion x y
5087 state.uioh <- state.uioh#
pmotion x y;
5093 method key key mask
=
5094 begin match state.mode with
5095 | Textentry
textentry -> textentrykeyboard key mask
textentry
5096 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5097 | View
-> viewkeyboard key mask
5101 method button button bstate
x y mask
=
5102 begin match state.mode with
5103 | View
-> viewmouse button bstate
x y mask
5104 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5110 begin match state.mode with
5112 | View
| Birdseye
_ ->
5113 match state.mstate
with
5114 | Mzoom
_ | Mnone
-> ()
5119 state.mstate
<- Mpan
(x, y);
5120 if conf.zoom > 1.0 then state.x <- state.x + dx;
5122 gotoy_and_clear_text y
5125 state.mstate
<- Msel
(a, (x, y));
5126 G.postRedisplay "motion select";
5129 let y = min
conf.winh
(max
0 y) in
5133 let x = min
conf.winw (max
0 x) in
5136 | Mzoomrect
(p0
, _) ->
5137 state.mstate
<- Mzoomrect
(p0
, (x, y));
5138 G.postRedisplay "motion zoomrect";
5142 method pmotion x y =
5143 begin match state.mode with
5144 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5145 let rec loop = function
5147 if hooverpageno
!= -1
5149 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5150 G.postRedisplay "pmotion birdseye no hoover";
5153 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5154 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5156 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5157 G.postRedisplay "pmotion birdseye hoover";
5166 match state.mstate
with
5167 | Mnone
-> updateunder x y
5168 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5173 method infochanged
_ = ()
5176 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5177 let p, h = scrollph state.y maxy in
5181 let winw = conf.winw - state.scrollw
- 1 in
5182 let fwinw = float winw in
5184 let sw = fwinw /. float state.w in
5185 let sw = fwinw *. sw in
5186 max
sw (float conf.scrollh
)
5189 let f = state.w+winw in
5190 let r = float (winw-state.x) /. float f in
5191 let p = fwinw *. r in
5195 if position +. sw > fwinw
5196 then fwinw -. position
5199 state.hscrollh, position, sw
5203 match state.mode with
5204 | Textentry
_ -> "textentry"
5205 | Birdseye
_ -> "birdseye"
5208 findkeyhash conf modename
5215 let fontpath = ref "";;
5218 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5221 let l = String.length
s in
5222 let b = Buffer.create
l in
5228 try Sys.getenv
"HOME"
5231 ("Can not determine home directory location: " ^
5232 Printexc.to_string exn
);
5236 let modifier_of_string = function
5237 | "alt" -> Wsi.altmask
5238 | "shift" -> Wsi.shiftmask
5239 | "ctrl" | "control" -> Wsi.ctrlmask
5240 | "meta" -> Wsi.metamask
5245 let r = Str.regexp
"-" in
5247 let elems = Str.full_split
r s in
5250 let m1 = modifier_of_string s in
5252 then (Wsi.namekey
s, m)
5255 | Str.Delim
s when n land 1 = 0 -> g s
5257 | Str.Delim
_ -> (k
, m)
5259 let rec loop n k
m = function
5262 let k, m = f n k m x in
5268 let keys_of_string =
5269 let r = Str.regexp
"[ \t]" in
5271 let elems = Str.split
r s in
5272 List.map
key_of_string elems
5275 let copykeyhashes c =
5276 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5279 let config_of c attrs
=
5283 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5284 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5285 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5286 | "preload" -> { c with preload = bool_of_string
v }
5287 | "page-bias" -> { c with pagebias
= int_of_string
v }
5288 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5289 | "auto-scroll-step" ->
5290 { c with autoscrollstep
= max
0 (int_of_string
v) }
5291 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5292 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5295 match String.lowercase
v with
5296 | "true" -> Some infinity
5298 | f -> Some
(float_of_string
f)
5300 { c with maxwait
= mw}
5301 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5302 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5303 | "vertical-margin" ->
5304 { c with interpagespace = max
0 (int_of_string
v) }
5306 let zoom = float_of_string
v /. 100. in
5307 let zoom = max
zoom 0.0 in
5308 { c with zoom = zoom }
5309 | "presentation" -> { c with presentation = bool_of_string
v }
5310 | "rotation-angle" -> { c with angle
= int_of_string
v }
5311 | "width" -> { c with winw = max
20 (int_of_string
v) }
5312 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5313 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5314 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5315 | "pixmap-cache-size" ->
5316 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5317 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5318 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5319 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5320 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5321 | "background-color" -> { c with bgcolor
= color_of_string v }
5322 | "scrollbar-in-presentation" ->
5323 { c with scrollbarinpm
= bool_of_string
v }
5324 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5325 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5326 | "mupdf-store-size" ->
5327 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5328 | "checkers" -> { c with checkers
= bool_of_string
v }
5329 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5330 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5331 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5332 | "uri-launcher" -> { c with urilauncher
= unent v }
5333 | "path-launcher" -> { c with pathlauncher
= unent v }
5334 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5335 | "invert-colors" -> { c with invert
= bool_of_string
v }
5336 | "brightness" -> { c with colorscale
= float_of_string
v }
5337 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5339 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5341 let nab = columns_of_string v in
5342 { c with columns
= Some
(nab, [||]) }
5343 | "birds-eye-columns" ->
5344 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5345 | "selection-command" -> { c with selcmd
= unent v }
5346 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5349 prerr_endline
("Error processing attribute (`" ^
5350 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5353 let rec fold c = function
5356 let c = apply c k v in
5359 fold { c with keyhashes
= copykeyhashes c } attrs
;
5362 let fromstring f pos
n v d =
5365 dolog "Error processing attribute (%S=%S) at %d\n%s"
5366 n v pos
(Printexc.to_string exn
)
5371 let bookmark_of attrs
=
5372 let rec fold title page
rely = function
5373 | ("title", v) :: rest
-> fold v page
rely rest
5374 | ("page", v) :: rest
-> fold title v rely rest
5375 | ("rely", v) :: rest
-> fold title page
v rest
5376 | _ :: rest
-> fold title page
rely rest
5377 | [] -> title, page
, rely
5379 fold "invalid" "0" "0" attrs
5383 let rec fold path page
rely pan
= function
5384 | ("path", v) :: rest
-> fold v page
rely pan rest
5385 | ("page", v) :: rest
-> fold path v rely pan rest
5386 | ("rely", v) :: rest
-> fold path page
v pan rest
5387 | ("pan", v) :: rest
-> fold path page
rely v rest
5388 | _ :: rest
-> fold path page
rely pan rest
5389 | [] -> path, page
, rely, pan
5391 fold "" "0" "0" "0" attrs
5395 let rec fold rs ls
= function
5396 | ("out", v) :: rest
-> fold v ls rest
5397 | ("in", v) :: rest
-> fold rs
v rest
5398 | _ :: rest
-> fold ls rs rest
5404 let setconf dst
src =
5405 dst
.scrollbw
<- src.scrollbw
;
5406 dst
.scrollh
<- src.scrollh
;
5407 dst
.icase
<- src.icase
;
5408 dst
.preload <- src.preload;
5409 dst
.pagebias
<- src.pagebias
;
5410 dst
.verbose
<- src.verbose
;
5411 dst
.scrollstep
<- src.scrollstep
;
5412 dst
.maxhfit
<- src.maxhfit
;
5413 dst
.crophack
<- src.crophack
;
5414 dst
.autoscrollstep
<- src.autoscrollstep
;
5415 dst
.maxwait
<- src.maxwait
;
5416 dst
.hlinks
<- src.hlinks
;
5417 dst
.underinfo
<- src.underinfo
;
5418 dst
.interpagespace <- src.interpagespace;
5419 dst
.zoom <- src.zoom;
5420 dst
.presentation <- src.presentation;
5421 dst
.angle
<- src.angle
;
5422 dst
.winw <- src.winw;
5423 dst
.winh
<- src.winh
;
5424 dst
.savebmarks
<- src.savebmarks
;
5425 dst
.memlimit
<- src.memlimit
;
5426 dst
.proportional
<- src.proportional
;
5427 dst
.texcount
<- src.texcount
;
5428 dst
.sliceheight
<- src.sliceheight
;
5429 dst
.thumbw
<- src.thumbw
;
5430 dst
.jumpback
<- src.jumpback
;
5431 dst
.bgcolor
<- src.bgcolor
;
5432 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5433 dst
.tilew
<- src.tilew
;
5434 dst
.tileh
<- src.tileh
;
5435 dst
.mustoresize
<- src.mustoresize
;
5436 dst
.checkers
<- src.checkers
;
5437 dst
.aalevel
<- src.aalevel
;
5438 dst
.trimmargins
<- src.trimmargins
;
5439 dst
.trimfuzz
<- src.trimfuzz
;
5440 dst
.urilauncher
<- src.urilauncher
;
5441 dst
.colorspace
<- src.colorspace
;
5442 dst
.invert
<- src.invert
;
5443 dst
.colorscale
<- src.colorscale
;
5444 dst
.redirectstderr <- src.redirectstderr;
5445 dst
.ghyllscroll
<- src.ghyllscroll
;
5446 dst
.columns
<- src.columns
;
5447 dst
.beyecolumns
<- src.beyecolumns
;
5448 dst
.selcmd
<- src.selcmd
;
5449 dst
.updatecurs
<- src.updatecurs
;
5450 dst
.pathlauncher
<- src.pathlauncher
;
5451 dst
.keyhashes
<- copykeyhashes src;
5455 let h = Hashtbl.create
10 in
5456 let dc = { defconf with angle
= defconf.angle
} in
5457 let rec toplevel v t spos
_ =
5459 | Vdata
| Vcdata
| Vend
-> v
5460 | Vopen
("llppconfig", _, closed
) ->
5463 else { v with f = llppconfig
}
5465 error
"unexpected subelement at top level" s spos
5466 | Vclose
_ -> error
"unexpected close at top level" s spos
5468 and llppconfig
v t spos
_ =
5470 | Vdata
| Vcdata
-> v
5471 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5472 | Vopen
("defaults", attrs
, closed
) ->
5473 let c = config_of dc attrs
in
5477 else { v with f = defaults
}
5479 | Vopen
("ui-font", attrs
, closed
) ->
5480 let rec getsize size
= function
5482 | ("size", v) :: rest
->
5484 fromstring int_of_string spos
"size" v fstate.fontsize
in
5486 | l -> getsize size l
5488 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5491 else { v with f = uifont
(Buffer.create
10) }
5493 | Vopen
("doc", attrs
, closed
) ->
5494 let pathent, spage
, srely
, span
= doc_of attrs
in
5495 let path = unent pathent
5496 and pageno = fromstring int_of_string spos
"page" spage
0
5497 and rely = fromstring float_of_string spos
"rely" srely
0.0
5498 and pan
= fromstring int_of_string spos
"pan" span
0 in
5499 let c = config_of dc attrs
in
5500 let anchor = (pageno, rely) in
5502 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5503 else { v with f = doc
path pan
anchor c [] }
5506 error
"unexpected subelement in llppconfig" s spos
5508 | Vclose
"llppconfig" -> { v with f = toplevel }
5509 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5511 and defaults
v t spos
_ =
5513 | Vdata
| Vcdata
-> v
5514 | Vend
-> error
"unexpected end of input in defaults" s spos
5515 | Vopen
("keymap", attrs
, closed
) ->
5517 try List.assoc
"mode" attrs
5518 with Not_found
-> "global" in
5523 let h = findkeyhash dc modename in
5524 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5527 { v with f = pkeymap
ret KeyMap.empty }
5529 | Vopen
(_, _, _) ->
5530 error
"unexpected subelement in defaults" s spos
5532 | Vclose
"defaults" ->
5533 { v with f = llppconfig
}
5535 | Vclose
_ -> error
"unexpected close in defaults" s spos
5537 and uifont
b v t spos
epos =
5540 Buffer.add_substring
b s spos
(epos - spos
);
5542 | Vopen
(_, _, _) ->
5543 error
"unexpected subelement in ui-font" s spos
5544 | Vclose
"ui-font" ->
5545 if String.length
!fontpath = 0
5546 then fontpath := Buffer.contents
b;
5547 { v with f = llppconfig
}
5548 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5549 | Vend
-> error
"unexpected end of input in ui-font" s spos
5551 and doc
path pan
anchor c bookmarks
v t spos
_ =
5553 | Vdata
| Vcdata
-> v
5554 | Vend
-> error
"unexpected end of input in doc" s spos
5555 | Vopen
("bookmarks", _, closed
) ->
5558 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5560 | Vopen
("keymap", attrs
, closed
) ->
5562 try List.assoc
"mode" attrs
5563 with Not_found
-> "global"
5569 let h = findkeyhash c modename in
5570 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5571 doc
path pan
anchor c bookmarks
5573 { v with f = pkeymap
ret KeyMap.empty }
5575 | Vopen
(_, _, _) ->
5576 error
"unexpected subelement in doc" s spos
5579 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5580 { v with f = llppconfig
}
5582 | Vclose
_ -> error
"unexpected close in doc" s spos
5584 and pkeymap
ret keymap
v t spos
_ =
5586 | Vdata
| Vcdata
-> v
5587 | Vend
-> error
"unexpected end of input in keymap" s spos
5588 | Vopen
("map", attrs
, closed
) ->
5589 let r, l = map_of attrs
in
5590 let kss = fromstring keys_of_string spos
"in" r [] in
5591 let lss = fromstring keys_of_string spos
"out" l [] in
5595 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5596 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5599 then { v with f = pkeymap
ret keymap }
5602 { v with f = skip
"map" f }
5605 error
"unexpected subelement in keymap" s spos
5607 | Vclose
"keymap" ->
5608 { v with f = ret keymap }
5610 | Vclose
_ -> error
"unexpected close in keymap" s spos
5612 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5614 | Vdata
| Vcdata
-> v
5615 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5616 | Vopen
("item", attrs
, closed
) ->
5617 let titleent, spage
, srely
= bookmark_of attrs
in
5618 let page = fromstring int_of_string spos
"page" spage
0
5619 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5620 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5622 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5625 { v with f = skip
"item" f }
5628 error
"unexpected subelement in bookmarks" s spos
5630 | Vclose
"bookmarks" ->
5631 { v with f = doc
path pan
anchor c bookmarks }
5633 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5635 and skip tag
f v t spos
_ =
5637 | Vdata
| Vcdata
-> v
5639 error
("unexpected end of input in skipped " ^ tag
) s spos
5640 | Vopen
(tag'
, _, closed
) ->
5644 let f'
() = { v with f = skip tag
f } in
5645 { v with f = skip tag'
f'
}
5649 else error
("unexpected close in skipped " ^ tag
) s spos
5652 parse
{ f = toplevel; accu = () } s;
5658 let len = in_channel_length ic
in
5659 let s = String.create
len in
5660 really_input ic
s 0 len;
5663 | Parse_error
(msg
, s, pos
) ->
5664 let subs = subs s pos
in
5665 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5666 failwith
("parse error: " ^
s)
5669 failwith
("config load error: " ^
Printexc.to_string exn
)
5675 let dir = Filename.concat
home ".config" in
5676 if Sys.is_directory
dir then dir else home
5679 Filename.concat
dir "llpp.conf"
5682 let confpath = ref defconfpath;;
5685 if Sys.file_exists
!confpath
5688 (try Some
(open_in_bin
!confpath)
5691 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5692 Printexc.to_string exn
);
5701 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5702 Printexc.to_string exn
);
5708 f (Hashtbl.create
0, defconf)
5713 let pc, pb
, px, pa
=
5715 Hashtbl.find h (Filename.basename
state.path)
5716 with Not_found
-> dc, [], 0, (0, 0.0)
5720 state.bookmarks <- pb
;
5722 state.scrollw
<- conf.scrollbw
;
5724 then state.anchor <- pa
;
5725 cbput state.hists
.nav pa
;
5730 let add_attrs bb always
dc c =
5733 then Printf.bprintf bb
"\n %s='%b'" s a
5736 then Printf.bprintf bb
"\n %s='%d'" s a
5739 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5742 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5745 then Printf.bprintf bb
"\n %s='%f'" s a
5749 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5753 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5757 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5761 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5767 | Some
(_N
, _A
, _B
) ->
5768 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5778 else string_of_float
f
5780 Printf.bprintf bb
"\n %s='%s'" s v
5785 | Some
((n, a, b), _) when n > 1 ->
5786 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5792 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5797 then dc.winw, dc.winh
5799 match state.fullscreen
with
5801 | None
-> c.winw, c.winh
5803 let zoom, presentation, interpagespace, maxwait
=
5805 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5807 match state.mode with
5808 | Birdseye
(bc
, _, _, _, _) ->
5809 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5810 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5812 oi
"width" w dc.winw;
5813 oi
"height" h dc.winh
;
5814 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5815 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5816 ob "case-insensitive-search" c.icase
dc.icase
;
5817 ob "preload" c.preload dc.preload;
5818 oi
"page-bias" c.pagebias
dc.pagebias
;
5819 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5820 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5821 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5822 ob "crop-hack" c.crophack
dc.crophack
;
5823 oW
"throttle" maxwait
dc.maxwait
;
5824 ob "highlight-links" c.hlinks
dc.hlinks
;
5825 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5826 oi
"vertical-margin" interpagespace dc.interpagespace;
5827 oz
"zoom" zoom dc.zoom;
5828 ob "presentation" presentation dc.presentation;
5829 oi
"rotation-angle" c.angle
dc.angle
;
5830 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5831 ob "proportional-display" c.proportional
dc.proportional
;
5832 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5833 oi
"tex-count" c.texcount
dc.texcount
;
5834 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5835 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5836 ob "persistent-location" c.jumpback
dc.jumpback
;
5837 oc
"background-color" c.bgcolor
dc.bgcolor
;
5838 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5839 oi
"tile-width" c.tilew
dc.tilew
;
5840 oi
"tile-height" c.tileh
dc.tileh
;
5841 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5842 ob "checkers" c.checkers
dc.checkers
;
5843 oi
"aalevel" c.aalevel
dc.aalevel
;
5844 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5845 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5846 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5847 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
5848 oC
"color-space" c.colorspace
dc.colorspace
;
5849 ob "invert-colors" c.invert
dc.invert
;
5850 oF
"brightness" c.colorscale
dc.colorscale
;
5851 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5852 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5853 oco
"columns" c.columns
dc.columns
;
5854 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5855 os
"selection-command" c.selcmd
dc.selcmd
;
5856 ob "update-cursor" c.updatecurs
dc.updatecurs
;
5859 let keymapsbuf always
dc c =
5860 let bb = Buffer.create
16 in
5861 List.iter
(fun (modename, h) ->
5862 let dh = findkeyhash dc modename in
5863 if always
|| h <> dh
5865 if Hashtbl.length
h > 0
5867 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
5868 Hashtbl.iter
(fun i
o ->
5869 let isdifferent = always
||
5871 let dO = Hashtbl.find dh i
in
5873 with Not_found
-> true
5878 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
5879 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
5880 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
5881 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
5882 Buffer.add_string
bb (Wsi.keyname
k);
5885 let rec loop = function
5887 | km
:: [] -> addkm km
5888 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
5892 Buffer.add_string
bb "<map in='";
5896 Buffer.add_char
bb '
\''
;
5897 Buffer.add_string
bb " out='";
5899 Buffer.add_string
bb "'/>\n"
5902 Buffer.add_char
bb '
\''
;
5903 Buffer.add_string
bb " out='";
5905 Buffer.add_string
bb "'/>\n"
5907 | KMmulti
(ins, kms
) ->
5908 Buffer.add_char
bb ' '
;
5910 Buffer.add_char
bb '
\''
;
5911 Buffer.add_string
bb " out='";
5913 Buffer.add_string
bb "'/>\n"
5915 Buffer.add_string
bb "</keymap>";
5923 let uifontsize = fstate.fontsize
in
5924 let bb = Buffer.create
32768 in
5926 let dc = if conf.bedefault
then conf else dc in
5927 Buffer.add_string
bb "<llppconfig>\n";
5929 if String.length
!fontpath > 0
5931 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5937 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5940 Buffer.add_string
bb "<defaults ";
5941 add_attrs bb true dc dc;
5942 let kb = keymapsbuf true dc dc in
5943 if Buffer.length
kb > 0
5945 Buffer.add_string
bb ">\n";
5946 Buffer.add_buffer
bb kb;
5947 Buffer.add_string
bb "\n</defaults>\n";
5949 else Buffer.add_string
bb "/>\n";
5951 let adddoc path pan
anchor c bookmarks =
5952 if bookmarks == [] && c = dc && anchor = emptyanchor
5955 Printf.bprintf
bb "<doc path='%s'"
5956 (enent
path 0 (String.length
path));
5958 if anchor <> emptyanchor
5960 let n, y = anchor in
5961 Printf.bprintf
bb " page='%d'" n;
5964 Printf.bprintf
bb " rely='%f'" y
5969 then Printf.bprintf
bb " pan='%d'" pan
;
5971 add_attrs bb false dc c;
5972 let kb = keymapsbuf false dc c in
5974 begin match bookmarks with
5976 if Buffer.length
kb > 0
5978 Buffer.add_string
bb ">\n";
5979 Buffer.add_buffer
bb kb;
5980 Buffer.add_string
bb "</doc>\n";
5982 else Buffer.add_string
bb "/>\n"
5984 Buffer.add_string
bb ">\n<bookmarks>\n";
5985 List.iter
(fun (title, _level
, (page, rely)) ->
5987 "<item title='%s' page='%d'"
5988 (enent
title 0 (String.length
title))
5993 Printf.bprintf
bb " rely='%f'" rely
5995 Buffer.add_string
bb "/>\n";
5997 Buffer.add_string
bb "</bookmarks>";
5998 if Buffer.length
kb > 0
6000 Buffer.add_string
bb "\n";
6001 Buffer.add_buffer
bb kb;
6003 Buffer.add_string
bb "\n</doc>\n";
6009 match state.mode with
6010 | Birdseye
(c, pan, _, _, _) ->
6012 match conf.columns
with
6013 | Some
((c, _, _), _) -> Some
c
6016 match c.columns
with
6017 | Some
(c, _) -> Some
(c, [||])
6020 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6021 | _ -> state.x, conf
6023 let basename = Filename.basename state.path in
6024 adddoc basename pan (getanchor ())
6027 match state.autoscroll
with
6029 | None
-> conf.autoscrollstep
}
6030 (if conf.savebmarks
then state.bookmarks else []);
6032 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6034 then adddoc path x y c bookmarks
6036 Buffer.add_string
bb "</llppconfig>";
6039 if Buffer.length
bb > 0
6042 let tmp = !confpath ^
".tmp" in
6043 let oc = open_out_bin
tmp in
6044 Buffer.output_buffer
oc bb;
6046 Unix.rename
tmp !confpath;
6049 ("error while saving configuration: " ^
Printexc.to_string exn
)
6056 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6057 "<password> Set password");
6059 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6060 "<path> Set path to the user interface font");
6062 ("-c", Arg.String
(fun s -> Config.confpath := s),
6063 "<path> Set path to the configuration file");
6065 ("-v", Arg.Unit
(fun () ->
6067 "%s\nconfiguration path: %s\n"
6071 exit
0), " Print version and exit");
6074 (fun s -> state.path <- s)
6075 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6077 if String.length
state.path = 0
6078 then (prerr_endline
"file name missing"; exit
1);
6082 let globalkeyhash = findkeyhash conf "global" in
6083 state.wsfd
<- Wsi.init
(object
6084 method display = display ()
6085 method reshape w h = reshape w h
6086 method mouse b d x y m = mouse b d x y m
6087 method motion x y = state.mpos
<- (x, y); motion x y
6088 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6090 match state.keystate
with
6095 try Hashtbl.find globalkeyhash km
6097 let modehash = state.uioh#
modehash in
6098 try Hashtbl.find modehash km
6099 with Not_found
-> KMinsrt
(k, m)
6101 | KMinsrt
(k, m) -> keyboard k m
6102 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6103 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6105 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land m = m'
->
6106 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6107 state.keystate
<- KSnone
6108 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land m = m'
->
6109 state.keystate
<- KSinto
(keys
, insrt
)
6111 state.keystate
<- KSnone
6113 method enter
x y = state.mpos
<- (x, y); pmotion x y
6114 method leave = state.mpos
<- (-1, -1)
6115 end) conf.winw conf.winh
;
6118 List.exists
GlMisc.check_extension
6119 [ "GL_ARB_texture_rectangle"
6120 ; "GL_EXT_texture_recangle"
6121 ; "GL_NV_texture_rectangle" ]
6123 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6125 let cr, sw = Unix.pipe
()
6126 and sr
, cw
= Unix.pipe
() in
6133 setcheckers conf.checkers
;
6137 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6138 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6143 state.text <- "Opening " ^
state.path;
6144 setaalevel
conf.aalevel
;
6145 writeopen state.path state.password
;
6147 setfontsize fstate.fontsize
;
6148 doreshape conf.winw conf.winh
;
6150 let rec loop deadline
=
6152 match state.errfd
with
6153 | None
-> [state.sr
; state.wsfd
]
6154 | Some fd
-> [state.sr
; state.wsfd
; fd
]
6158 state.redisplay
<- false;
6165 if deadline
= infinity
6167 else max
0.0 (deadline
-. now)
6172 try Unix.select
r [] [] timeout
6173 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6179 if state.ghyll
== noghyll
6181 match state.autoscroll
with
6182 | Some step
when step
!= 0 ->
6183 let y = state.y + step
in
6187 else if y >= state.maxy then 0 else y
6190 if state.mode = View
6191 then state.text <- "";
6194 else deadline
+. 0.01
6199 let rec checkfds = function
6201 | fd
:: rest
when fd
= state.sr
->
6202 let cmd = readcmd state.sr
in
6206 | fd
:: rest
when fd
= state.wsfd
->
6211 let s = String.create
80 in
6212 let n = Unix.read fd
s 0 80 in
6213 if conf.redirectstderr
6215 Buffer.add_substring
state.errmsgs
s 0 n;
6216 state.newerrmsgs
<- true;
6217 state.redisplay
<- true;
6220 prerr_string
(String.sub
s 0 n);
6228 if deadline
= infinity
6232 match state.autoscroll
with
6233 | Some step
when step
!= 0 -> deadline1
6234 | _ -> if state.ghyll
== noghyll then infinity
else deadline1