3 let tempfailureretry = Wsi.tempfailureretry;;
8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
17 let now = Unix.gettimeofday
;;
19 type params
= (angle
* proportional
* trimparams
20 * texcount
* sliceheight
* memsize
21 * colorspace
* fontpath
* trimcachepath
31 and proportional
= bool
32 and trimmargins
= bool
33 and interpagespace
= int
40 and trimcachepath
= string
43 and irect
= (int * int * int * int)
44 and trimparams
= (trimmargins
* irect
)
45 and colorspace
= | Rgb
| Bgr
| Gray
55 | LDfirstvisible
of (int * int * int)
70 | KMmulti
of key list
* key list
72 and keyhash
= (key
, keymap
) Hashtbl.t
75 | KSinto
of (key list
* key list
)
78 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
79 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
81 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
83 external init
: pipe
-> params
-> unit = "ml_init";;
84 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
85 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
86 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
87 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
88 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
89 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
90 external measurestr
: int -> string -> float = "ml_measure_string";;
91 external getmaxw
: unit -> float = "ml_getmaxw";;
92 external postprocess
:
93 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
94 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
95 external platform
: unit -> platform
= "ml_platform";;
96 external setaalevel
: int -> unit = "ml_setaalevel";;
97 external realloctexts
: int -> bool = "ml_realloctexts";;
98 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
99 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
100 external getlink
: opaque
-> int -> under
= "ml_getlink";;
101 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
102 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
103 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
104 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
105 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
106 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
107 external freepbo
: string -> unit = "ml_freepbo";;
108 external unmappbo
: string -> unit = "ml_unmappbo";;
109 external pbousable
: unit -> bool = "ml_pbo_usable";;
111 let platform_to_string = function
112 | Punknown
-> "unknown"
116 | Pfreebsd
-> "FreeBSD"
117 | Pdragonflybsd
-> "DragonflyBSD"
118 | Popenbsd
-> "OpenBSD"
119 | Pnetbsd
-> "NetBSD"
120 | Pcygwin
-> "Cygwin"
123 let platform = platform ();;
126 if platform = Pcygwin
128 let sh = "/bin/sh" in
129 let args = [|sh; "-c"; cmd
|] in
130 let rec std si so se
= function
132 | (fd
, 0) :: rest
-> std fd so se rest
133 | (fd
, -1) :: rest
->
134 Unix.set_close_on_exec fd
;
137 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
139 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
140 ignore
(Unix.create_process
sh args si so se
)
149 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
152 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
154 type mpos
= int * int
156 | Msel
of (mpos
* mpos
)
158 | Mscrolly
| Mscrollx
159 | Mzoom
of (int * int)
160 | Mzoomrect
of (mpos
* mpos
)
164 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
165 and onkey
= string -> int -> te
166 and ondone
= string -> unit
167 and histcancel
= unit -> unit
168 and onhist
= ((histcmd
-> string) * histcancel
)
169 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
170 and cancelonempty
= bool
175 | TEswitch
of textentry
186 let bound v minv maxv
=
187 max minv
(min maxv v
);
191 { store
= Array.create n v
198 let cbcap b
= Array.length b
.store
;;
203 b
.wc
<- (b
.wc
+ 1) mod cap;
205 b
.len
<- min
(b
.len
+ 1) cap;
208 let cbempty b
= b
.len
= 0;;
210 let cbgetg b circular dir
=
214 let rc = b
.rc + dir
in
226 else bound rc 0 (b
.len
-1)
232 let cbget b
= cbgetg b
false;;
233 let cbgetc b
= cbgetg b
true;;
235 let drawstring size x y s
=
237 Gl.enable `texture_2d
;
238 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
239 ignore
(drawstr size x y s
);
241 Gl.disable `texture_2d
;
244 let drawstring1 size x y s
=
248 let drawstring2 size x y fmt
=
249 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
268 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
269 dolog " WxH %dx%d" l
.pagew l
.pageh
;
270 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
271 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
272 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
273 dolog " column %d" l
.pagecol
;
277 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
279 dolog " x0,y0=(% f, % f)" x0 y0
;
280 dolog " x1,y1=(% f, % f)" x1 y1
;
281 dolog " x2,y2=(% f, % f)" x2 y2
;
282 dolog " x3,y3=(% f, % f)" x3 y3
;
286 type multicolumns
= multicol
* pagegeom
287 and singlecolumn
= pagegeom
288 and splitcolumns
= columncount
* pagegeom
289 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
290 and multicol
= columncount
* covercount
* covercount
292 and columncount
= int
293 and covercount
= int;;
296 { mutable scrollbw
: int
297 ; mutable scrollh
: int
298 ; mutable icase
: bool
299 ; mutable preload
: bool
300 ; mutable pagebias
: int
301 ; mutable verbose
: bool
302 ; mutable debug
: bool
303 ; mutable scrollstep
: int
304 ; mutable hscrollstep
: int
305 ; mutable maxhfit
: bool
306 ; mutable crophack
: bool
307 ; mutable autoscrollstep
: int
308 ; mutable maxwait
: float option
309 ; mutable hlinks
: bool
310 ; mutable underinfo
: bool
311 ; mutable interpagespace
: interpagespace
312 ; mutable zoom
: float
313 ; mutable presentation
: bool
314 ; mutable angle
: angle
317 ; mutable savebmarks
: bool
318 ; mutable proportional
: proportional
319 ; mutable trimmargins
: trimmargins
320 ; mutable trimfuzz
: irect
321 ; mutable memlimit
: memsize
322 ; mutable texcount
: texcount
323 ; mutable sliceheight
: sliceheight
324 ; mutable thumbw
: width
325 ; mutable jumpback
: bool
326 ; mutable bgcolor
: float * float * float
327 ; mutable bedefault
: bool
328 ; mutable scrollbarinpm
: bool
329 ; mutable tilew
: int
330 ; mutable tileh
: int
331 ; mutable mustoresize
: memsize
332 ; mutable checkers
: bool
333 ; mutable aalevel
: int
334 ; mutable urilauncher
: string
335 ; mutable pathlauncher
: string
336 ; mutable colorspace
: colorspace
337 ; mutable invert
: bool
338 ; mutable colorscale
: float
339 ; mutable redirectstderr
: bool
340 ; mutable ghyllscroll
: (int * int * int) option
341 ; mutable columns
: columns
342 ; mutable beyecolumns
: columncount
option
343 ; mutable selcmd
: string
344 ; mutable updatecurs
: bool
345 ; mutable keyhashes
: (string * keyhash
) list
346 ; mutable hfsize
: int
347 ; mutable pgscale
: float
348 ; mutable usepbo
: bool
349 ; mutable wheelbypage
: bool
352 | Csingle
of singlecolumn
353 | Cmulti
of multicolumns
354 | Csplit
of splitcolumns
357 type anchor
= pageno
* top
* dtop
;;
359 type outline
= string * int * anchor
;;
361 type rect
= float * float * float * float * float * float * float * float;;
363 type tile
= opaque
* pixmapsize
* elapsed
364 and elapsed
= float;;
365 type pagemapkey
= pageno
* gen
;;
366 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
370 let emptyanchor = (0, 0.0, 0.0);;
372 type infochange
= | Memused
| Docinfo
| Pdim
;;
374 class type uioh
= object
375 method display
: unit
376 method key
: int -> int -> uioh
377 method button
: int -> bool -> int -> int -> int -> uioh
378 method motion
: int -> int -> uioh
379 method pmotion
: int -> int -> uioh
380 method infochanged
: infochange
-> unit
381 method scrollpw
: (int * float * float)
382 method scrollph
: (int * float * float)
383 method modehash
: keyhash
387 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
388 | Textentry
of (textentry
* onleave
)
390 | LinkNav
of linktarget
391 and onleave
= leavetextentrystatus
-> unit
392 and leavetextentrystatus
= | Cancel
| Confirm
393 and helpitem
= string * int * action
396 | Action
of (uioh
-> uioh
)
398 | Ltexact
of (pageno
* int)
402 let isbirdseye = function Birdseye _
-> true | _
-> false;;
403 let istextentry = function Textentry _
-> true | _
-> false;;
407 | Loading
of (page
* gen
)
409 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
411 | Outlining
of outline list
414 let emptykeyhash = Hashtbl.create
0;;
415 let nouioh : uioh
= object (self
)
417 method key _ _
= self
418 method button _ _ _ _ _
= self
419 method motion _ _
= self
420 method pmotion _ _
= self
421 method infochanged _
= ()
422 method scrollpw
= (0, nan
, nan
)
423 method scrollph
= (0, nan
, nan
)
424 method modehash
= emptykeyhash
428 { mutable sr
: Unix.file_descr
429 ; mutable sw
: Unix.file_descr
430 ; mutable wsfd
: Unix.file_descr
431 ; mutable errfd
: Unix.file_descr
option
432 ; mutable stderr
: Unix.file_descr
433 ; mutable errmsgs
: Buffer.t
434 ; mutable newerrmsgs
: bool
438 ; mutable scrollw
: int
439 ; mutable hscrollh
: int
440 ; mutable anchor
: anchor
441 ; mutable ranchors
: (string * string * anchor
) list
443 ; mutable layout
: page list
444 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
445 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
446 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
447 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
448 ; mutable pagecount
: int
449 ; mutable currently
: currently
450 ; mutable mstate
: mstate
451 ; mutable searchpattern
: string
452 ; mutable rects
: (pageno
* recttype
* rect
) list
453 ; mutable rects1
: (pageno
* recttype
* rect
) list
454 ; mutable text
: string
455 ; mutable fullscreen
: (width
* height
) option
456 ; mutable mode
: mode
457 ; mutable uioh
: uioh
458 ; mutable outlines
: outline array
459 ; mutable bookmarks
: outline list
460 ; mutable path
: string
461 ; mutable password
: string
462 ; mutable nameddest
: string
463 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
464 ; mutable memused
: memsize
466 ; mutable throttle
: (page list
* int * float) option
467 ; mutable autoscroll
: int option
468 ; mutable ghyll
: (int option -> unit)
469 ; mutable help
: helpitem array
470 ; mutable docinfo
: (int * string) list
471 ; mutable texid
: GlTex.texture_id
option
473 ; mutable prevzoom
: float
474 ; mutable progress
: float
475 ; mutable redisplay
: bool
476 ; mutable mpos
: mpos
477 ; mutable keystate
: keystate
478 ; mutable glinks
: bool
479 ; mutable prevcolumns
: (columns
* float) option
480 ; mutable wthack
: bool
483 { pat
: string circbuf
484 ; pag
: string circbuf
485 ; nav
: anchor circbuf
486 ; sel
: string circbuf
508 ; presentation
= false
513 ; proportional
= true
514 ; trimmargins
= false
515 ; trimfuzz
= (0,0,0,0)
516 ; memlimit
= 32 lsl 20
521 ; bgcolor
= (0.5, 0.5, 0.5)
523 ; scrollbarinpm
= true
526 ; mustoresize
= 256 lsl 20
531 | Plinux
| Pfreebsd
| Pdragonflybsd
532 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
533 | Posx
-> "open \"%s\""
534 | Pcygwin
-> "cygstart \"%s\""
535 | Punknown
-> "echo %s")
536 ; pathlauncher
= "lp \"%s\""
539 | Plinux
| Pfreebsd
| Pdragonflybsd
540 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
547 ; redirectstderr
= false
549 ; columns
= Csingle
[||]
555 ; wheelbypage
= false
557 let mk n
= (n
, Hashtbl.create
1) in
571 let findkeyhash c name
=
572 try List.assoc name c
.keyhashes
573 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
576 let conf = { defconf with angle
= defconf.angle
};;
578 let pgscale h
= truncate
(float h
*. conf.pgscale);;
581 { mutable fontsize
: int
582 ; mutable wwidth
: float
583 ; mutable maxrows
: int
595 fstate.fontsize
<- n
;
596 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
597 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
601 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
602 let len = String.length s
in
603 if colonpos >= 0 && colonpos + 3 < len
605 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
608 try String.rindex_from s
colonpos ' '
612 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
615 | "http" | "ftp" | "mailto" ->
617 try String.index_from s
colonpos ' '
618 with Not_found
-> len
620 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
628 if String.length
conf.urilauncher
= 0
629 then print_endline uri
631 let url = geturl uri
in
632 if String.length
url = 0
633 then print_endline uri
635 let re = Str.regexp
"%s" in
636 let command = Str.global_replace
re url conf.urilauncher
in
640 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
646 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
647 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
651 let strings = version () :: "" :: Help.keys
in
654 let url = geturl s
in
655 if String.length
url > 0
656 then (s
, 0, Action
(fun u
-> gotouri url; u
))
657 else (s
, 0, Noaction
)
662 let firstgeomcmds = "", [];;
669 ; stderr
= Unix.stderr
670 ; errmsgs
= Buffer.create
0
677 ; anchor
= emptyanchor
681 ; tilelru
= Queue.create
()
682 ; pagemap
= Hashtbl.create
10
683 ; tilemap
= Hashtbl.create
10
699 ; geomcmds
= firstgeomcmds
701 { nav
= cbnew 10 emptyanchor
729 Printf.kprintf prerr_endline fmt
731 Printf.kprintf ignore fmt
735 if String.length
conf.pathlauncher
= 0
736 then print_endline
state.path
738 let re = Str.regexp
"%s" in
739 let command = Str.global_replace
re state.path
conf.pathlauncher
in
743 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
749 type 'a t
= | Res
of 'a
| Exn
of exn
;;
752 try Res
(Unix.pipe ())
757 try tempfailureretry Unix.close fd
758 with exn
-> f
(Printexc.to_string exn
)
762 try Res
(tempfailureretry Unix.dup fd
)
767 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
772 let redirectstderr () =
773 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
774 if conf.redirectstderr
776 match Ne.pipe () with
778 dolog "failed to create stderr redirection pipes: %s"
779 (Printexc.to_string exn
)
782 begin match Ne.dup Unix.stderr
with
784 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
785 Ne.clo r
(clofail "pipe/r");
786 Ne.clo w
(clofail "pipe/w");
788 | Ne.Res dupstderr
->
789 begin match Ne.dup2 w
Unix.stderr
with
791 dolog "failed to dup2 to stderr: %s"
792 (Printexc.to_string exn
);
793 Ne.clo dupstderr
(clofail "stderr duplicate");
794 Ne.clo r
(clofail "redir pipe/r");
795 Ne.clo w
(clofail "redir pipe/w");
798 state.stderr
<- dupstderr
;
799 state.errfd
<- Some r
;
803 state.newerrmsgs
<- false;
804 begin match state.errfd
with
806 begin match Ne.dup2 state.stderr
Unix.stderr
with
808 dolog "failed to dup2 original stderr: %s"
809 (Printexc.to_string exn
)
811 Ne.clo fd
(clofail "dup of stderr");
816 prerr_string
(Buffer.contents
state.errmsgs
);
818 Buffer.clear
state.errmsgs
;
824 let postRedisplay who
=
826 then prerr_endline
("redisplay for " ^ who
);
827 state.redisplay
<- true;
831 let getopaque pageno
=
832 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
833 with Not_found
-> None
836 let putopaque pageno opaque
=
837 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
840 let pagetranslatepoint l x y
=
841 let dy = y
- l
.pagedispy
in
842 let y = dy + l
.pagey
in
843 let dx = x
- l
.pagedispx
in
844 let x = dx + l
.pagex
in
851 begin match getopaque l
.pageno
with
853 let x0 = l
.pagedispx
in
854 let x1 = x0 + l
.pagevw
in
855 let y0 = l
.pagedispy
in
856 let y1 = y0 + l
.pagevh
in
857 if y >= y0 && y <= y1 && x >= x0 && x <= x1
859 let px, py
= pagetranslatepoint l
x y in
860 match whatsunder opaque
px py
with
873 state.text
<- Printf.sprintf
"%c%s" c s
;
874 G.postRedisplay "showtext";
877 let undertext = function
880 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
881 | Utext s
-> "font: " ^ s
882 | Uunexpected s
-> "unexpected: " ^ s
883 | Ulaunch s
-> "launch: " ^ s
884 | Unamed s
-> "named: " ^ s
885 | Uremote
(filename
, pageno
) ->
886 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
889 let updateunder x y =
890 match getunder x y with
891 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
893 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
894 Wsi.setcursor
Wsi.CURSOR_INFO
895 | Ulinkgoto
(pageno
, _
) ->
897 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
898 Wsi.setcursor
Wsi.CURSOR_INFO
900 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
901 Wsi.setcursor
Wsi.CURSOR_TEXT
903 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
904 Wsi.setcursor
Wsi.CURSOR_INHERIT
906 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
907 Wsi.setcursor
Wsi.CURSOR_INHERIT
909 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
910 Wsi.setcursor
Wsi.CURSOR_INHERIT
911 | Uremote
(filename
, pageno
) ->
912 if conf.underinfo
then showtext 'r'
913 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
914 Wsi.setcursor
Wsi.CURSOR_INFO
917 let showlinktype under
=
923 let s = undertext under
in
928 let b = Buffer.create
(String.length
s + 1) in
929 Buffer.add_string
b s;
934 let colorspace_of_string s =
935 match String.lowercase
s with
939 | _
-> failwith
"invalid colorspace"
942 let int_of_colorspace = function
948 let colorspace_of_int = function
952 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
955 let colorspace_to_string = function
961 let intentry_with_suffix text key
=
963 if key
>= 32 && key
< 127
967 match Char.lowercase
c with
969 let text = addchar text c in
973 let text = addchar text c in
977 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
981 let multicolumns_to_string (n
, a
, b) =
983 then Printf.sprintf
"%d" n
984 else Printf.sprintf
"%d,%d,%d" n a
b;
987 let multicolumns_of_string s =
989 (int_of_string
s, 0, 0)
991 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
993 then failwith
"subtly broken"; (n
, a
, b)
999 let n = tempfailureretry (Unix.read fd
s 0) 4 in
1000 if n != 4 then failwith
"incomplete read(len)";
1002 lor (Char.code
s.[0] lsl 24)
1003 lor (Char.code
s.[1] lsl 16)
1004 lor (Char.code
s.[2] lsl 8)
1005 lor (Char.code
s.[3] lsl 0)
1007 let s = String.create
len in
1008 let n = tempfailureretry (Unix.read fd
s 0) len in
1009 if n != len then failwith
"incomplete read(data)";
1013 let btod b = if b then 1 else 0;;
1016 let b = Buffer.create
16 in
1017 Buffer.add_string
b "llll";
1020 let s = Buffer.contents
b in
1021 let n = String.length
s in
1023 (* dolog "wcmd %S" (String.sub s 4 len); *)
1024 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1025 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1026 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1027 s.[3] <- Char.chr
(len land 0xff);
1028 let n'
= tempfailureretry (Unix.write
state.sw
s 0) n in
1029 if n'
!= n then failwith
"write failed";
1034 let d = conf.winh
- h
in
1035 max
conf.interpagespace
((d + 1) / 2)
1038 let rowyh (c, coverA
, coverB
) b n =
1039 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1041 let _, _, vy
, (_, _, h
, _) = b.(n) in
1044 let n'
= n - coverA
in
1047 let e = min
state.pagecount
(s + c) in
1048 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1049 let _, _, y, (_, _, h
, _) = b.(m
) in
1050 let miny = min
miny y in
1051 let maxh = max
maxh h
in
1052 find (m
+1) miny maxh
1057 match conf.columns
with
1058 | Cmulti
((_, _, _) as cl
, b) ->
1059 if Array.length
b > 0
1061 let y, h
= rowyh cl
b (Array.length
b - 1) in
1062 y + h
+ (if conf.presentation
then calcips h
else 0)
1065 if Array.length
b > 0
1067 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1068 y + h
+ (if conf.presentation
then calcips h
else 0)
1071 if Array.length
b > 0
1073 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1078 let getpageyh pageno
=
1079 let pageno = bound pageno 0 (state.pagecount
-1) in
1080 match conf.columns
with
1082 if Array.length
b = 0
1085 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1087 if conf.presentation
1093 if Array.length
b = 0
1096 let y, h
= rowyh cl
b pageno in
1098 if conf.presentation
1104 if Array.length
b = 0
1108 let (_, _, y, (_, _, h
, _)) = b.(n) in
1112 let getpagedim pageno =
1115 | (n, _, _, _) as pdim
:: rest
->
1117 then (if n = pageno then pdim
else ppdim
)
1122 f (-1, -1, -1, -1) state.pdims
1125 let getpagey pageno = fst
(getpageyh pageno);;
1127 let nogeomcmds cmds
=
1129 | s, [] -> String.length
s = 0
1134 let ((c, coverA
, coverB
) as cl
), b =
1135 match conf.columns
with
1136 | Csingle
b -> (1, 0, 0), b
1137 | Cmulti
(c, b) -> c, b
1138 | Csplit
(_, b) -> (1, 0, 0), b
1140 let rec bsearch nmin nmax
=
1142 then bound nmin
0 (state.pagecount
-1)
1144 let n = (nmax
+ nmin
) / 2 in
1145 let vy, h
= rowyh cl
b n in
1147 if conf.presentation
1149 let ips = calcips h
in
1150 let y0 = vy - ips in
1151 let y1 = vy + h
+ ips in
1155 then 0, vy + h
+ conf.interpagespace
1157 let y0 = vy - conf.interpagespace
in
1158 y0, y0 + h
+ conf.interpagespace
1161 if y >= y0 && y < y1
1168 if n < state.pagecount
- coverB
1169 then ((n-coverA
)/c)*c + coverA
1176 then bsearch (n+1) nmax
1177 else bsearch nmin
(n-1)
1180 let r = bsearch 0 (state.pagecount
-1) in
1184 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1185 let sh = sh - state.hscrollh
in
1186 let rec fold accu
n =
1187 if n = Array.length
b
1190 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1193 || n = state.pagecount
- coverB
1194 || (n - coverA
) mod columns
= columns
- 1)
1200 let pagey = max
0 (y - vy) in
1201 let pagedispy = if pagey > 0 then 0 else vy - y in
1202 let pagedispx, pagex
=
1204 if n = coverA
- 1 || n = state.pagecount
- coverB
1205 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1206 else dx + xoff
+ state.x
1213 let vw = conf.winw
- state.scrollw
- pagedispx in
1214 let pw = w
- pagex
in
1217 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1218 if pagevw > 0 && pagevh > 0
1222 ; pagedimno
= pdimno
1229 ; pagedispx = pagedispx
1230 ; pagedispy = pagedispy
1242 List.rev
(fold [] (page_of_y y));
1245 let layoutS (columns
, b) y sh =
1246 let sh = sh - state.hscrollh
in
1247 let rec fold accu n =
1248 if n = Array.length
b
1251 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1258 let x = xoff
+ state.x in
1259 let pagey = max
0 (y - vy) in
1260 let pagedispy = if pagey > 0 then 0 else vy - y in
1261 let pagedispx, pagex
=
1275 let pagecolw = pagew
/columns
in
1277 if pagecolw < conf.winw
1278 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1282 let vw = conf.winw
- pagedispx - state.scrollw
in
1283 let pw = pagew
- pagex
in
1286 let pagevw = min
pagevw pagecolw in
1287 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1288 if pagevw > 0 && pagevh > 0
1291 { pageno = n/columns
1292 ; pagedimno
= pdimno
1299 ; pagedispx = pagedispx
1300 ; pagedispy = pagedispy
1301 ; pagecol
= n mod columns
1312 List.rev
(fold [] 0)
1316 if nogeomcmds state.geomcmds
1318 match conf.columns
with
1319 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1320 | Cmulti
c -> layoutN c y sh
1321 | Csplit
s -> layoutS s y sh
1326 let y = state.y + incr
in
1328 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1333 let tilex = l
.pagex
mod conf.tilew
in
1334 let tiley = l
.pagey mod conf.tileh
in
1336 let col = l
.pagex
/ conf.tilew
in
1337 let row = l
.pagey / conf.tileh
in
1339 let rec rowloop row y0 dispy h
=
1343 let dh = conf.tileh
- y0 in
1344 let dh = min h
dh in
1345 let rec colloop col x0 dispx w
=
1349 let dw = conf.tilew
- x0 in
1350 let dw = min w
dw in
1352 f col row dispx dispy
x0 y0 dw dh;
1353 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1356 colloop col tilex l
.pagedispx l
.pagevw;
1357 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1360 if l
.pagevw > 0 && l
.pagevh > 0
1361 then rowloop row tiley l
.pagedispy l
.pagevh;
1364 let gettileopaque l
col row =
1366 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1368 try Some
(Hashtbl.find state.tilemap
key)
1369 with Not_found
-> None
1372 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1373 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1374 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1377 let drawtiles l color
=
1379 let f col row x y tilex tiley w h
=
1380 match gettileopaque l
col row with
1381 | Some
(opaque
, _, t
) ->
1382 let params = x, y, w
, h
, tilex, tiley in
1386 GlFunc.blend_func `zero `one_minus_src_color
;
1388 drawtile
params opaque
;
1390 then Gl.disable `blend
;
1393 let s = Printf.sprintf
1397 let w = measurestr
fstate.fontsize
s in
1398 GlMisc.push_attrib
[`current
];
1399 GlDraw.color
(0.0, 0.0, 0.0);
1401 (float (x-2), float (y-2))
1402 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1403 GlDraw.color
(1.0, 1.0, 1.0);
1404 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1405 GlMisc.pop_attrib
();
1410 let lw = conf.winw
- state.scrollw
- x in
1413 let lh = conf.winh
- y in
1416 begin match state.texid
with
1418 Gl.enable `texture_2d
;
1419 GlTex.bind_texture `texture_2d id
;
1422 and x1 = float (x+w)
1423 and y1 = float (y+h
) in
1425 let tw = float w /. 16.0
1426 and th
= float h
/. 16.0 in
1427 let tx0 = float tilex /. 16.0
1428 and ty0
= float tiley /. 16.0 in
1430 and ty1
= ty0
+. th
in
1431 GlDraw.begins `quads
;
1432 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1433 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1434 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1435 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1438 Gl.disable `texture_2d
;
1440 GlDraw.color
(1.0, 1.0, 1.0);
1443 (float (x+w), float (y+h
));
1445 if w > 128 && h
> fstate.fontsize
+ 10
1447 GlDraw.color
(0.0, 0.0, 0.0);
1450 then (col*conf.tilew
, row*conf.tileh
)
1453 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1460 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1462 let tilevisible1 l
x y =
1464 and ax1
= l
.pagex
+ l
.pagevw
1466 and ay1
= l
.pagey + l
.pagevh in
1470 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1471 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1473 let rx0 = max
ax0 bx0
1474 and ry0
= max ay0 by0
1475 and rx1
= min ax1
bx1
1476 and ry1
= min ay1 by1
in
1478 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1479 nonemptyintersection
1482 let tilevisible layout n x y =
1483 let rec findpageinlayout m
= function
1484 | l
:: rest
when l
.pageno = n ->
1485 tilevisible1 l
x y || (
1486 match conf.columns
with
1487 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1490 | _ :: rest
-> findpageinlayout 0 rest
1493 findpageinlayout 0 layout;
1496 let tileready l
x y =
1497 tilevisible1 l
x y &&
1498 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1501 let tilepage n p
layout =
1502 let rec loop = function
1506 let f col row _ _ _ _ _ _ =
1507 if state.currently
= Idle
1509 match gettileopaque l
col row with
1512 let x = col*conf.tilew
1513 and y = row*conf.tileh
in
1515 let w = l
.pagew
- x in
1519 let h = l
.pageh
- y in
1524 then getpbo
w h conf.colorspace
1527 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1530 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1531 conf.tilew
, conf.tileh
1540 if nogeomcmds state.geomcmds
1544 let preloadlayout y =
1545 let y = if y < conf.winh
then 0 else y - conf.winh
in
1546 let h = conf.winh
*3 in
1551 let rec loop pages
=
1552 if state.currently
!= Idle
1557 begin match getopaque l
.pageno with
1559 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1560 state.currently
<- Loading
(l
, state.gen
);
1562 tilepage l
.pageno opaque pages
;
1567 if nogeomcmds state.geomcmds
1573 if conf.preload && state.currently
= Idle
1574 then load (preloadlayout state.y);
1577 let layoutready layout =
1578 let rec fold all ls
=
1579 all
&& match ls
with
1581 let seen = ref false in
1582 let allvisible = ref true in
1583 let foo col row _ _ _ _ _ _ =
1585 allvisible := !allvisible &&
1586 begin match gettileopaque l
col row with
1592 fold (!seen && !allvisible) rest
1595 let alltilesvisible = fold true layout in
1600 state.wthack
<- false;
1601 let y = bound y 0 state.maxy
in
1602 let y, layout, proceed
=
1603 match conf.maxwait
with
1604 | Some time
when state.ghyll
== noghyll ->
1605 begin match state.throttle
with
1607 let layout = layout y conf.winh
in
1608 let ready = layoutready layout in
1612 state.throttle
<- Some
(layout, y, now ());
1614 else G.postRedisplay "gotoy showall (None)";
1616 | Some
(_, _, started
) ->
1617 let dt = now () -. started
in
1620 state.throttle
<- None
;
1621 let layout = layout y conf.winh
in
1623 G.postRedisplay "maxwait";
1630 let layout = layout y conf.winh
in
1631 if true || layoutready layout
1632 then G.postRedisplay "gotoy ready";
1638 state.layout <- layout;
1639 begin match state.mode
with
1640 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1641 let rec loop = function
1643 state.mode
<- LinkNav
(Ltgendir
0)
1644 | l
:: _ when l
.pageno = pageno ->
1645 begin match getopaque pageno with
1647 state.mode
<- LinkNav
(Ltgendir
0)
1649 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1650 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1651 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1652 then state.mode
<- LinkNav
(Ltgendir
0)
1654 | _ :: rest
-> loop rest
1659 begin match state.mode
with
1660 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1661 if not
(pagevisible layout pageno)
1663 match state.layout with
1666 state.mode
<- Birdseye
(
1667 conf, leftx
, l
.pageno, hooverpageno
, anchor
1670 | LinkNav
(Ltgendir dir
as lt
) ->
1672 let rec loop = function
1675 match getopaque l
.pageno with
1681 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1683 if dir
> 0 then LDfirst
else LDlast
1689 | Lnotfound
-> loop rest
1691 showlinktype (getlink opaque
n);
1692 Ltexact
(l
.pageno, n)
1696 state.mode
<- LinkNav
linknav
1701 state.ghyll
<- noghyll;
1704 let mx, my
= state.mpos
in
1709 let conttiling pageno opaque
=
1710 tilepage pageno opaque
1711 (if conf.preload then preloadlayout state.y else state.layout)
1714 let gotoy_and_clear_text y =
1715 if not
conf.verbose
then state.text <- "";
1721 let coloff = l
.pagecol
* l
.pageh
in
1722 float (l
.pagey + coloff) /. float l
.pageh
1729 if conf.presentation
1730 then float l
.pagedispy /. float (calcips l
.pageh
)
1731 else float l
.pagedispy /. float conf.interpagespace
1733 (l
.pageno, top, dtop)
1737 match state.layout with
1738 | l
:: _ -> getanchor1 l
1740 let n = page_of_y state.y in
1741 let y, h = getpageyh n in
1742 let dy = y - state.y in
1744 if conf.presentation
1746 let ips = calcips h in
1747 float (dy + ips) /. float ips
1749 float dy /. float conf.interpagespace
1754 let getanchory (n, top, dtop) =
1755 let y, h = getpageyh n in
1756 if conf.presentation
1758 let ips = calcips h in
1759 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1761 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1764 let gotoanchor anchor
=
1765 gotoy (getanchory anchor
);
1769 cbput state.hists
.nav
(getanchor ());
1773 let anchor = cbgetc state.hists
.nav dir
in
1778 let scroll f n a
b =
1779 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1781 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1783 then s (float f /. float a
)
1786 then 1.0 -. s ((float (f-b) /. float (n-b)))
1793 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1794 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1796 let ins = float a
*. iv1
1797 and outs
= float (n-b) *. iv1 in
1799 ins +. outs
+. float ones
1801 let rec set (_N
, _A
, _B
) y sy
=
1802 let sum = summa
1.0 _N _A _B
in
1803 let dy = float (y - sy
) in
1807 then state.ghyll
<- noghyll
1810 let s = scroll n _N _A _B
in
1811 let y1 = y1 +. ((s *. dy) /. sum) in
1812 gotoy_and_clear_text (truncate
y1);
1813 state.ghyll
<- gf (n+1) y1;
1817 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1819 gf 0 (float state.y)
1822 match conf.ghyllscroll
with
1824 gotoy_and_clear_text y
1826 if state.ghyll
== noghyll
1827 then set nab
y state.y
1828 else state.ghyll
(Some
y)
1831 let gotopage n top =
1832 let y, h = getpageyh n in
1833 let y = y + (truncate
(top *. float h)) in
1837 let gotopage1 n top =
1838 let y = getpagey n in
1843 let invalidate s f =
1848 match state.geomcmds
with
1849 | ps
, [] when String.length ps
= 0 ->
1851 state.geomcmds
<- s, [];
1854 state.geomcmds
<- ps
, [s, f];
1856 | ps
, (s'
, _) :: rest
when s'
= s ->
1857 state.geomcmds
<- ps
, ((s, f) :: rest
);
1860 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1864 Hashtbl.iter
(fun _ opaque
->
1865 wcmd "freepage %s" opaque
;
1867 Hashtbl.clear
state.pagemap
;
1870 let opendoc path password
=
1872 state.password
<- password
;
1873 state.gen
<- state.gen
+ 1;
1874 state.docinfo
<- [];
1877 setaalevel
conf.aalevel
;
1878 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1879 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1880 invalidate "reqlayout"
1882 wcmd "reqlayout %d %d %s\000"
1883 conf.angle
(btod conf.proportional
) state.nameddest
;
1888 state.anchor <- getanchor ();
1889 state.wthack
<- true;
1890 opendoc state.path
state.password
;
1894 let c = c *. conf.colorscale
in
1898 let scalecolor2 (r, g
, b) =
1899 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1902 let docolumns = function
1904 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1905 let rec loop pageno pdimno pdim
y ph pdims
=
1906 if pageno = state.pagecount
1909 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1911 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1912 pdimno+1, pdim
, rest
1916 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1918 (if conf.presentation
1919 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1920 else (if pageno = 0 then 0 else conf.interpagespace
)
1923 a.(pageno) <- (pdimno, x, y, pdim
);
1924 loop (pageno+1) pdimno pdim
(y + h) h pdims
1926 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1927 conf.columns
<- Csingle
a;
1929 | Cmulti
((columns
, coverA
, coverB
), _) ->
1930 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1931 let rec loop pageno pdimno pdim
x y rowh pdims
=
1932 let rec fixrow m
= if m
= pageno then () else
1933 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1936 let y = y + (rowh
- h) / 2 in
1937 a.(m
) <- (pdimno, x, y, pdim
);
1941 if pageno = state.pagecount
1942 then fixrow (((pageno - 1) / columns
) * columns
)
1944 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1946 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1947 pdimno+1, pdim
, rest
1952 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1954 let x = (conf.winw
- state.scrollw
- w) / 2 in
1956 if conf.presentation
then calcips h else conf.interpagespace
in
1957 x, y + ips + rowh
, h
1960 if (pageno - coverA
) mod columns
= 0
1962 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1964 if conf.presentation
1966 let ips = calcips h in
1967 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1969 y + (if pageno = 0 then 0 else conf.interpagespace
)
1973 else x, y, max rowh
h
1977 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1980 if pageno = columns
&& conf.presentation
1982 let ips = calcips rowh
in
1983 for i
= 0 to pred columns
1985 let (pdimno, x, y, pdim
) = a.(i
) in
1986 a.(i
) <- (pdimno, x, y+ips, pdim
)
1992 fixrow (pageno - columns
);
1997 a.(pageno) <- (pdimno, x, y, pdim
);
1998 let x = x + w + xoff
*2 + conf.interpagespace
in
1999 loop (pageno+1) pdimno pdim
x y rowh' pdims
2001 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2002 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2005 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2006 let rec loop pageno pdimno pdim
y pdims
=
2007 if pageno = state.pagecount
2010 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2012 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2013 pdimno+1, pdim
, rest
2018 let rec loop1 n x y =
2019 if n = c then y else (
2020 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2021 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2024 let y = loop1 0 0 y in
2025 loop (pageno+1) pdimno pdim
y pdims
2027 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2028 conf.columns
<- Csplit
(c, a);
2032 docolumns conf.columns
;
2033 state.maxy
<- calcheight ();
2035 if state.w <= conf.winw
- state.scrollw
2039 let wthack = state.wthack in
2040 begin match state.mode
with
2041 | Birdseye
(_, _, pageno, _, _) ->
2042 let y, h = getpageyh pageno in
2043 let top = (conf.winh
- h) / 2 in
2044 gotoy (max
0 (y - top))
2045 | _ -> gotoanchor state.anchor
2047 state.wthack <- wthack;
2051 state.wthack <- false;
2052 GlDraw.viewport
0 0 w h;
2053 let firsttime = state.geomcmds
== firstgeomcmds in
2054 if not
firsttime && nogeomcmds state.geomcmds
2055 then state.anchor <- getanchor ();
2058 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2061 setfontsize fstate.fontsize
;
2062 GlMat.mode `modelview
;
2063 GlMat.load_identity
();
2065 GlMat.mode `projection
;
2066 GlMat.load_identity
();
2067 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2068 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2069 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2074 else float state.x /. float state.w
2076 invalidate "geometry"
2080 then state.x <- truncate
(relx *. float w);
2082 match conf.columns
with
2084 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2085 | Csplit
(c, _) -> w * c
2087 wcmd "geometry %d %d" w h);
2091 let len = String.length
state.text in
2094 match state.mode
with
2097 let h, _, _ = state.uioh#scrollpw
in
2103 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2104 (x+.w, float (conf.winh
- hscrollh))
2107 let w = float (conf.winw
- state.scrollw
- 1) in
2108 if state.progress
>= 0.0 && state.progress
< 1.0
2110 GlDraw.color
(0.3, 0.3, 0.3);
2111 let w1 = w *. state.progress
in
2113 GlDraw.color
(0.0, 0.0, 0.0);
2117 GlDraw.color
(0.0, 0.0, 0.0);
2121 GlDraw.color
(1.0, 1.0, 1.0);
2122 drawstring fstate.fontsize
2123 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2126 match state.mode
with
2127 | Textentry
((prefix
, text, _, _, _, _), _) ->
2131 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2133 Printf.sprintf
"%s%s_" prefix
text
2142 if not
(istextentry state.mode
)
2144 let s1 = "(press 'e' to review error messasges)" in
2145 if String.length
s > 0 then s ^
" " ^
s1 else s1
2150 if String.length
s > 0
2155 let len = Queue.length
state.tilelru
in
2157 match state.throttle
with
2160 then preloadlayout state.y
2162 | Some
(layout, _, _) ->
2166 if state.memused
<= conf.memlimit
2171 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2172 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2173 let (_, pw, ph
, _) = getpagedim n in
2176 && colorspace
= conf.colorspace
2177 && angle
= conf.angle
2181 let x = col*conf.tilew
2182 and y = row*conf.tileh
in
2183 tilevisible (Lazy.force_val
layout) n x y
2185 then Queue.push lruitem
state.tilelru
2188 wcmd "freetile %s" p
;
2189 state.memused
<- state.memused
- s;
2190 state.uioh#infochanged Memused
;
2191 Hashtbl.remove
state.tilemap k
;
2200 Queue.iter
(fun (k
, p
, s) ->
2201 wcmd "freetile %s" p
;
2202 state.memused
<- state.memused
- s;
2203 state.uioh#infochanged Memused
;
2204 Hashtbl.remove
state.tilemap k
;
2206 Queue.clear
state.tilelru
;
2210 let logcurrently = function
2211 | Idle
-> dolog "Idle"
2212 | Loading
(l
, gen
) ->
2213 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2214 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2216 "Tiling %d[%d,%d] page=%s cs=%s angle"
2217 l
.pageno col row pageopaque
2218 (colorspace_to_string colorspace
)
2220 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2221 angle gen
conf.angle
state.gen
2223 conf.tilew
conf.tileh
2230 (* dolog "%S" cmds; *)
2233 try String.index cmds ' '
2234 with Not_found
-> -1
2239 let l = String.length cmds
in
2240 let op = String.sub cmds
0 spacepos in
2242 if l - spacepos < 2 then ""
2243 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2248 state.uioh#infochanged Pdim
;
2252 state.rects
<- state.rects1
;
2253 G.postRedisplay "clearrects";
2257 try Scanf.sscanf
args "%u" (fun n -> n)
2259 dolog "error processing 'continue' %S: %s"
2260 cmds
(Printexc.to_string exn
);
2263 state.pagecount
<- n;
2264 begin match state.currently
with
2266 state.currently
<- Idle
;
2267 state.outlines
<- Array.of_list
(List.rev
l)
2271 let cur, cmds
= state.geomcmds
in
2272 if String.length
cur = 0
2273 then failwith
"umpossible";
2275 begin match List.rev cmds
with
2277 state.geomcmds
<- "", [];
2281 state.geomcmds
<- s, List.rev rest
;
2283 if conf.maxwait
= None
2284 then G.postRedisplay "continue";
2294 then showtext ' '
args
2297 Buffer.add_string
state.errmsgs
args;
2298 state.newerrmsgs
<- true;
2299 G.postRedisplay "error message"
2302 let progress, text =
2304 Scanf.sscanf
args "%f %n"
2306 f, String.sub
args pos
(String.length
args - pos
))
2308 dolog "error processing 'progress' %S: %s"
2309 cmds
(Printexc.to_string exn
);
2313 state.progress <- progress;
2314 G.postRedisplay "progress"
2317 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2319 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2320 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2321 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2323 dolog "error processing 'firstmatch' %S: %s"
2324 cmds
(Printexc.to_string exn
);
2327 let y = (getpagey pageno) + truncate
y0 in
2330 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2333 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2335 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2336 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2337 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2339 dolog "error processing 'match' %S: %s"
2340 cmds
(Printexc.to_string exn
);
2344 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2349 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2351 dolog "error processing 'page' %S: %s"
2352 cmds
(Printexc.to_string exn
);
2355 begin match state.currently
with
2356 | Loading
(l, gen
) ->
2357 vlog "page %d took %f sec" l.pageno t
;
2358 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2359 begin match state.throttle
with
2361 let preloadedpages =
2363 then preloadlayout state.y
2368 Set.Make
(struct type t
= int let compare = (-) end) in
2370 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2371 IntSet.empty
preloadedpages
2374 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2375 if not
(IntSet.mem
pageno set)
2377 wcmd "freepage %s" opaque
;
2383 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2386 state.currently
<- Idle
;
2389 tilepage l.pageno pageopaque state.layout;
2391 load preloadedpages;
2392 if pagevisible state.layout l.pageno
2393 && layoutready state.layout
2394 then G.postRedisplay "page";
2397 | Some
(layout, _, _) ->
2398 state.currently
<- Idle
;
2399 tilepage l.pageno pageopaque layout;
2404 dolog "Inconsistent loading state";
2405 logcurrently state.currently
;
2410 let (x, y, opaque
, size
, t
) =
2412 Scanf.sscanf
args "%u %u %s %u %f"
2413 (fun x y p size t
-> (x, y, p
, size
, t
))
2415 dolog "error processing 'tile' %S: %s"
2416 cmds
(Printexc.to_string exn
);
2419 begin match state.currently
with
2420 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2421 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2424 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2426 wcmd "freetile %s" opaque
;
2427 state.currently
<- Idle
;
2431 puttileopaque l col row gen cs angle opaque size t
;
2432 state.memused
<- state.memused
+ size
;
2433 state.uioh#infochanged Memused
;
2435 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2436 opaque
, size
) state.tilelru
;
2439 match state.throttle
with
2440 | None
-> state.layout
2441 | Some
(layout, _, _) -> layout
2444 state.currently
<- Idle
;
2446 && conf.colorspace
= cs
2447 && conf.angle
= angle
2448 && tilevisible layout l.pageno x y
2449 then conttiling l.pageno pageopaque;
2451 begin match state.throttle
with
2454 then state.wthack <- not
(layoutready state.layout);
2455 preload state.layout;
2457 && conf.colorspace
= cs
2458 && conf.angle
= angle
2459 && tilevisible state.layout l.pageno x y
2460 then G.postRedisplay "tile nothrottle";
2462 | Some
(layout, y, _) ->
2463 let ready = layoutready layout in
2466 state.wthack <- false;
2468 state.layout <- layout;
2469 state.throttle
<- None
;
2470 G.postRedisplay "throttle";
2477 dolog "Inconsistent tiling state";
2478 logcurrently state.currently
;
2485 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2487 dolog "error processing 'pdim' %S: %s"
2488 cmds
(Printexc.to_string exn
);
2491 state.uioh#infochanged Pdim
;
2492 state.pdims
<- pdim :: state.pdims
2495 let (l, n, t
, h, pos
) =
2497 Scanf.sscanf
args "%u %u %d %u %n"
2498 (fun l n t
h pos
-> l, n, t
, h, pos
)
2500 dolog "error processing 'o' %S: %s"
2501 cmds
(Printexc.to_string exn
);
2504 let s = String.sub
args pos
(String.length
args - pos
) in
2505 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2506 begin match state.currently
with
2507 | Outlining outlines
->
2508 state.currently
<- Outlining
(outline :: outlines
)
2510 state.currently
<- Outlining
[outline]
2512 dolog "invalid outlining state";
2513 logcurrently currently
2519 Scanf.sscanf
args "%u %u %d"
2520 (fun n t
h -> n, t
, h)
2522 dolog "error processing 'a' %S: %s"
2523 cmds
(Printexc.to_string exn
);
2527 if conf.presentation
2531 state.anchor <- (n, top /. float h, dtop)
2534 state.docinfo
<- (1, args) :: state.docinfo
2537 state.uioh#infochanged Docinfo
;
2538 state.docinfo
<- List.rev
state.docinfo
2541 dolog "unknown cmd `%S'" cmds
2546 let action = function
2547 | HCprev
-> cbget cb ~
-1
2548 | HCnext
-> cbget cb
1
2549 | HCfirst
-> cbget cb ~
-(cb
.rc)
2550 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2551 and cancel
() = cb
.rc <- rc
2555 let search pattern forward
=
2556 if String.length pattern
> 0
2559 match state.layout with
2562 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2564 wcmd "search %d %d %d %d,%s\000"
2565 (btod conf.icase
) pn py
(btod forward
) pattern
;
2568 let intentry text key =
2570 if key >= 32 && key < 127
2576 let text = addchar text c in
2580 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2584 let linknentry text key =
2586 if key >= 32 && key < 127
2592 let text = addchar text c in
2596 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2601 if String.length
s > 0
2604 let l = String.length
s in
2605 let rec loop pos
n = if pos
= l then n else
2606 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2607 loop (pos
+1) (n*26 + m)
2610 let rec loop n = function
2613 match getopaque l.pageno with
2614 | None
-> loop n rest
2616 let m = getlinkcount opaque
in
2619 let under = getlink opaque
n in
2622 else loop (n-m) rest
2624 loop n state.layout;
2628 let textentry text key =
2629 if key land 0xff00 = 0xff00
2631 else TEcont
(text ^
Wsi.toutf8
key)
2634 let reqlayout angle proportional
=
2635 match state.throttle
with
2637 if nogeomcmds state.geomcmds
2638 then state.anchor <- getanchor ();
2639 conf.angle
<- angle
mod 360;
2642 match state.mode
with
2643 | LinkNav
_ -> state.mode
<- View
2646 conf.proportional
<- proportional
;
2647 invalidate "reqlayout"
2648 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2652 let settrim trimmargins trimfuzz
=
2653 if nogeomcmds state.geomcmds
2654 then state.anchor <- getanchor ();
2655 conf.trimmargins
<- trimmargins
;
2656 conf.trimfuzz
<- trimfuzz
;
2657 let x0, y0, x1, y1 = trimfuzz
in
2658 invalidate "settrim"
2660 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2665 match state.throttle
with
2667 let zoom = max
0.01 zoom in
2668 if zoom <> conf.zoom
2670 state.prevzoom
<- conf.zoom;
2672 reshape conf.winw
conf.winh
;
2673 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2676 | Some
(layout, y, started
) ->
2678 match conf.maxwait
with
2682 let dt = now () -. started
in
2690 let setcolumns mode columns coverA coverB
=
2691 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2695 then showtext '
!'
"split mode doesn't work in bird's eye"
2697 conf.columns
<- Csplit
(-columns
, [||]);
2705 conf.columns
<- Csingle
[||];
2710 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2714 reshape conf.winw
conf.winh
;
2717 let enterbirdseye () =
2718 let zoom = float conf.thumbw
/. float conf.winw
in
2719 let birdseyepageno =
2720 let cy = conf.winh
/ 2 in
2724 let rec fold best
= function
2727 let d = cy - (l.pagedispy + l.pagevh/2)
2728 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2729 if abs
d < abs dbest
2736 state.mode
<- Birdseye
(
2737 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2740 conf.presentation
<- false;
2741 conf.interpagespace
<- 10;
2742 conf.hlinks
<- false;
2744 state.mstate
<- Mnone
;
2745 conf.maxwait
<- None
;
2747 match conf.beyecolumns
with
2750 Cmulti
((c, 0, 0), [||])
2751 | None
-> Csingle
[||]
2753 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2756 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2761 reshape conf.winw
conf.winh
;
2764 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2766 conf.zoom <- c.zoom;
2767 conf.presentation
<- c.presentation
;
2768 conf.interpagespace
<- c.interpagespace
;
2769 conf.maxwait
<- c.maxwait
;
2770 conf.hlinks
<- c.hlinks
;
2771 conf.beyecolumns
<- (
2772 match conf.columns
with
2773 | Cmulti
((c, _, _), _) -> Some
c
2775 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2778 match c.columns
with
2779 | Cmulti
(c, _) -> Cmulti
(c, [||])
2780 | Csingle
_ -> Csingle
[||]
2781 | Csplit
(c, _) -> Csplit
(c, [||])
2786 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2789 reshape conf.winw
conf.winh
;
2790 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2793 let togglebirdseye () =
2794 match state.mode
with
2795 | Birdseye vals
-> leavebirdseye vals
true
2796 | View
-> enterbirdseye ()
2800 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2801 let pageno = max
0 (pageno - incr
) in
2802 let rec loop = function
2803 | [] -> gotopage1 pageno 0
2804 | l :: _ when l.pageno = pageno ->
2805 if l.pagedispy >= 0 && l.pagey = 0
2806 then G.postRedisplay "upbirdseye"
2807 else gotopage1 pageno 0
2808 | _ :: rest
-> loop rest
2811 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2814 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2815 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2816 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2817 let rec loop = function
2819 let y, h = getpageyh pageno in
2820 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2822 | l :: _ when l.pageno = pageno ->
2823 if l.pagevh != l.pageh
2824 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2825 else G.postRedisplay "downbirdseye"
2826 | _ :: rest
-> loop rest
2831 let optentry mode
_ key =
2832 let btos b = if b then "on" else "off" in
2833 if key >= 32 && key < 127
2835 let c = Char.chr
key in
2839 try conf.scrollstep
<- int_of_string
s with exc
->
2840 state.text <- Printf.sprintf
"bad integer `%s': %s"
2841 s (Printexc.to_string exc
)
2843 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2848 conf.autoscrollstep
<- int_of_string
s;
2849 if state.autoscroll
<> None
2850 then state.autoscroll
<- Some
conf.autoscrollstep
2852 state.text <- Printf.sprintf
"bad integer `%s': %s"
2853 s (Printexc.to_string exc
)
2855 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2860 let n, a, b = multicolumns_of_string s in
2861 setcolumns mode
n a b;
2863 state.text <- Printf.sprintf
"bad columns `%s': %s"
2864 s (Printexc.to_string exc
)
2866 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2871 let zoom = float (int_of_string
s) /. 100.0 in
2874 state.text <- Printf.sprintf
"bad integer `%s': %s"
2875 s (Printexc.to_string exc
)
2877 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2882 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2884 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2885 begin match mode
with
2887 leavebirdseye beye
false;
2892 state.text <- Printf.sprintf
"bad integer `%s': %s"
2893 s (Printexc.to_string exc
)
2895 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2900 Some
(int_of_string
s)
2902 state.text <- Printf.sprintf
"bad integer `%s': %s"
2903 s (Printexc.to_string exc
);
2906 | Some angle
-> reqlayout angle
conf.proportional
2909 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2912 conf.icase
<- not
conf.icase
;
2913 TEdone
("case insensitive search " ^
(btos conf.icase
))
2916 conf.preload <- not
conf.preload;
2918 TEdone
("preload " ^
(btos conf.preload))
2921 conf.verbose
<- not
conf.verbose
;
2922 TEdone
("verbose " ^
(btos conf.verbose
))
2925 conf.debug
<- not
conf.debug
;
2926 TEdone
("debug " ^
(btos conf.debug
))
2929 conf.maxhfit
<- not
conf.maxhfit
;
2930 state.maxy
<- calcheight ();
2931 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2934 conf.crophack
<- not
conf.crophack
;
2935 TEdone
("crophack " ^
btos conf.crophack
)
2939 match conf.maxwait
with
2941 conf.maxwait
<- Some infinity
;
2942 "always wait for page to complete"
2944 conf.maxwait
<- None
;
2945 "show placeholder if page is not ready"
2950 conf.underinfo
<- not
conf.underinfo
;
2951 TEdone
("underinfo " ^
btos conf.underinfo
)
2954 conf.savebmarks
<- not
conf.savebmarks
;
2955 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2961 match state.layout with
2966 conf.interpagespace
<- int_of_string
s;
2967 docolumns conf.columns
;
2968 state.maxy
<- calcheight ();
2969 let y = getpagey pageno in
2972 state.text <- Printf.sprintf
"bad integer `%s': %s"
2973 s (Printexc.to_string exc
)
2975 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2978 reqlayout conf.angle
(not
conf.proportional
);
2979 TEdone
("proportional display " ^
btos conf.proportional
)
2982 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2983 TEdone
("trim margins " ^
btos conf.trimmargins
)
2986 conf.invert
<- not
conf.invert
;
2987 TEdone
("invert colors " ^
btos conf.invert
)
2991 cbput state.hists
.sel
s;
2994 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2995 textentry, ondone, true)
2998 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3004 class type lvsource
= object
3005 method getitemcount
: int
3006 method getitem
: int -> (string * int)
3007 method hasaction
: int -> bool
3016 method getactive
: int
3017 method getfirst
: int
3018 method getqsearch
: string
3019 method setqsearch
: string -> unit
3023 class virtual lvsourcebase
= object
3024 val mutable m_active
= 0
3025 val mutable m_first
= 0
3026 val mutable m_qsearch
= ""
3027 val mutable m_pan
= 0
3028 method getactive
= m_active
3029 method getfirst
= m_first
3030 method getqsearch
= m_qsearch
3031 method getpan
= m_pan
3032 method setqsearch
s = m_qsearch
<- s
3035 let withoutlastutf8 s =
3036 let len = String.length
s in
3044 let b = Char.code
s.[pos
] in
3045 if b land 0b11000000 = 0b11000000
3050 if Char.code
s.[len-1] land 0x80 = 0
3054 String.sub
s 0 first;
3057 let textentrykeyboard
3058 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3060 if key >= 0xffb0 && key <= 0xffb9
3061 then key - 0xffb0 + 48 else key
3064 state.mode
<- Textentry
(te
, onleave
);
3067 G.postRedisplay "textentrykeyboard enttext";
3069 let histaction cmd
=
3072 | Some
(action, _) ->
3073 state.mode
<- Textentry
(
3074 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3076 G.postRedisplay "textentry histaction"
3079 | 0xff08 -> (* backspace *)
3080 let s = withoutlastutf8 text in
3081 let len = String.length
s in
3082 if cancelonempty
&& len = 0
3085 G.postRedisplay "textentrykeyboard after cancel";
3088 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3091 | 0xff0d | 0xff8d -> (* (kp) enter *)
3094 G.postRedisplay "textentrykeyboard after confirm"
3096 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3097 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3098 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3099 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3101 | 0xff1b -> (* escape*)
3102 if String.length
text = 0
3104 begin match opthist
with
3106 | Some
(_, onhistcancel
) -> onhistcancel
()
3110 G.postRedisplay "textentrykeyboard after cancel2"
3113 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3116 | 0xff9f | 0xffff -> () (* delete *)
3119 && key land 0xff00 != 0xff00 (* keyboard *)
3120 && key land 0xfe00 != 0xfe00 (* xkb *)
3121 && key land 0xfd00 != 0xfd00 (* 3270 *)
3123 begin match onkey
text key with
3127 G.postRedisplay "textentrykeyboard after confirm2";
3130 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3134 G.postRedisplay "textentrykeyboard after cancel3"
3137 state.mode
<- Textentry
(te
, onleave
);
3138 G.postRedisplay "textentrykeyboard switch";
3142 vlog "unhandled key %s" (Wsi.keyname
key)
3145 let firstof first active
=
3146 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3147 then max
0 (active
- (fstate.maxrows
/2))
3151 let calcfirst first active
=
3154 let rows = active
- first in
3155 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3159 let scrollph y maxy
=
3160 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3161 let sh = float conf.winh
/. sh in
3162 let sh = max
sh (float conf.scrollh
) in
3167 else float y /. float maxy
3169 let position = (float conf.winh
-. sh) *. percent in
3172 if position +. sh > float conf.winh
3173 then float conf.winh
-. sh
3179 let coe s = (s :> uioh
);;
3181 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3183 val m_pan
= source#getpan
3184 val m_first
= source#getfirst
3185 val m_active
= source#getactive
3186 val m_qsearch
= source#getqsearch
3187 val m_prev_uioh
= state.uioh
3189 method private elemunder
y =
3190 let n = y / (fstate.fontsize
+1) in
3191 if m_first
+ n < source#getitemcount
3193 if source#hasaction
(m_first
+ n)
3194 then Some
(m_first
+ n)
3201 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3202 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3203 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3204 GlDraw.color
(1., 1., 1.);
3205 Gl.enable `texture_2d
;
3206 let fs = fstate.fontsize
in
3208 let ww = fstate.wwidth
in
3209 let tabw = 30.0*.ww in
3210 let itemcount = source#getitemcount
in
3212 if (row - m_first
) > fstate.maxrows
3215 if row >= 0 && row < itemcount
3217 let (s, level
) = source#getitem
row in
3218 let y = (row - m_first
) * nfs in
3219 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3222 Gl.disable `texture_2d
;
3223 GlDraw.polygon_mode `both `line
;
3224 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3225 GlDraw.rect (1., float (y + 1))
3226 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3227 GlDraw.polygon_mode `both `fill
;
3228 GlDraw.color
(1., 1., 1.);
3229 Gl.enable `texture_2d
;
3232 let drawtabularstring s =
3233 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3236 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3239 let len = String.length
s - tabpos - 1 in
3240 let s1 = String.sub
s 0 tabpos
3241 and s2
= String.sub
s (tabpos + 1) len in
3242 let nx = drawstr x s1 in
3244 let x = x +. (max
tabw sw) in
3251 let _ = drawtabularstring s in
3258 Gl.disable `texture_2d
;
3260 method updownlevel incr
=
3261 let len = source#getitemcount
in
3263 if m_active
>= 0 && m_active
< len
3264 then snd
(source#getitem m_active
)
3268 if i
= len then i
-1 else if i
= -1 then 0 else
3269 let _, l = source#getitem i
in
3270 if l != curlevel then i
else flow (i
+incr
)
3272 let active = flow m_active
in
3273 let first = calcfirst m_first
active in
3274 G.postRedisplay "outline updownlevel";
3275 {< m_active
= active; m_first
= first >}
3277 method private key1
key mask
=
3278 let set1 active first qsearch
=
3279 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3281 let search active pattern incr
=
3284 if n >= 0 && n < source#getitemcount
3286 let s, _ = source#getitem
n in
3288 (try ignore
(Str.search_forward
re s 0); true
3289 with Not_found
-> false)
3291 else loop (n + incr
)
3298 let re = Str.regexp_case_fold pattern
in
3304 let itemcount = source#getitemcount
in
3305 let find start incr
=
3307 if i
= -1 || i
= itemcount
3310 if source#hasaction i
3312 else find (i
+ incr
)
3317 let set active first =
3318 let first = bound first 0 (itemcount - fstate.maxrows
) in
3320 coe {< m_active
= active; m_first
= first >}
3323 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3325 let incr1 = if incr
> 0 then 1 else -1 in
3326 if isvisible m_first m_active
3329 let next = m_active
+ incr
in
3331 if next < 0 || next >= itemcount
3333 else find next incr1
3335 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3341 let first = m_first
+ incr
in
3342 let first = bound first 0 (itemcount - 1) in
3344 let next = m_active
+ incr
in
3345 let next = bound next 0 (itemcount - 1) in
3348 let active = if next = -1 then m_active
else next in
3351 let first = min
next m_first
in
3353 if abs
(next - first) > fstate.maxrows
3359 let first = m_first
+ incr
in
3360 let first = bound first 0 (itemcount - 1) in
3362 let next = m_active
+ incr
in
3363 let next = bound next 0 (itemcount - 1) in
3364 let next = find next incr1 in
3366 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3368 let active = if m_active
= -1 then next else m_active
in
3373 if isvisible first active
3379 G.postRedisplay "listview navigate";
3383 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3384 let incr = if key = 0x72 then -1 else 1 in
3386 match search (m_active
+ incr) m_qsearch
incr with
3388 state.text <- m_qsearch ^
" [not found]";
3391 state.text <- m_qsearch
;
3392 active, firstof m_first
active
3394 G.postRedisplay "listview ctrl-r/s";
3395 set1 active first m_qsearch
;
3397 | 0xff08 -> (* backspace *)
3398 if String.length m_qsearch
= 0
3401 let qsearch = withoutlastutf8 m_qsearch
in
3402 let len = String.length
qsearch in
3406 G.postRedisplay "listview empty qsearch";
3407 set1 m_active m_first
"";
3411 match search m_active
qsearch ~
-1 with
3413 state.text <- qsearch ^
" [not found]";
3416 state.text <- qsearch;
3417 active, firstof m_first
active
3419 G.postRedisplay "listview backspace qsearch";
3420 set1 active first qsearch
3423 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3424 let pattern = m_qsearch ^
Wsi.toutf8
key in
3426 match search m_active
pattern 1 with
3428 state.text <- pattern ^
" [not found]";
3431 state.text <- pattern;
3432 active, firstof m_first
active
3434 G.postRedisplay "listview qsearch add";
3435 set1 active first pattern;
3437 | 0xff1b -> (* escape *)
3439 if String.length m_qsearch
= 0
3441 G.postRedisplay "list view escape";
3444 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3446 | None
-> m_prev_uioh
3451 G.postRedisplay "list view kill qsearch";
3452 source#setqsearch
"";
3453 coe {< m_qsearch
= "" >}
3456 | 0xff0d | 0xff8d -> (* (kp) enter *)
3458 let self = {< m_qsearch
= "" >} in
3459 source#setqsearch
"";
3461 G.postRedisplay "listview enter";
3462 if m_active
>= 0 && m_active
< source#getitemcount
3464 source#exit
(coe self) false m_active m_first m_pan
"";
3467 source#exit
(coe self) true m_active m_first m_pan
"";
3470 begin match opt with
3471 | None
-> m_prev_uioh
3475 | 0xff9f | 0xffff -> (* (kp) delete *)
3478 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3479 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3480 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3481 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3483 | 0xff53 | 0xff98 -> (* (kp) right *)
3485 G.postRedisplay "listview right";
3486 coe {< m_pan
= m_pan
- 1 >}
3488 | 0xff51 | 0xff96 -> (* (kp) left *)
3490 G.postRedisplay "listview left";
3491 coe {< m_pan
= m_pan
+ 1 >}
3493 | 0xff50 | 0xff95 -> (* (kp) home *)
3494 let active = find 0 1 in
3495 G.postRedisplay "listview home";
3498 | 0xff57 | 0xff9c -> (* (kp) end *)
3499 let first = max
0 (itemcount - fstate.maxrows
) in
3500 let active = find (itemcount - 1) ~
-1 in
3501 G.postRedisplay "listview end";
3504 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3508 dolog "listview unknown key %#x" key; coe self
3510 method key key mask
=
3511 match state.mode
with
3512 | Textentry te
-> textentrykeyboard key mask te
; coe self
3513 | _ -> self#key1
key mask
3515 method button button down
x y _ =
3518 | 1 when x > conf.winw
- conf.scrollbw
->
3519 G.postRedisplay "listview scroll";
3522 let _, position, sh = self#
scrollph in
3523 if y > truncate
position && y < truncate
(position +. sh)
3525 state.mstate
<- Mscrolly
;
3529 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3530 let first = truncate
(s *. float source#getitemcount
) in
3531 let first = min source#getitemcount
first in
3532 Some
(coe {< m_first
= first; m_active
= first >})
3534 state.mstate
<- Mnone
;
3537 | 1 when not down
->
3538 begin match self#elemunder
y with
3540 G.postRedisplay "listview click";
3542 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3546 | n when (n == 4 || n == 5) && not down
->
3547 let len = source#getitemcount
in
3549 if n = 5 && m_first
+ fstate.maxrows
>= len
3553 let first = m_first
+ (if n == 4 then -1 else 1) in
3554 bound first 0 (len - 1)
3556 G.postRedisplay "listview wheel";
3557 Some
(coe {< m_first
= first >})
3558 | n when (n = 6 || n = 7) && not down
->
3559 let inc = m_first
+ (if n = 7 then -1 else 1) in
3560 G.postRedisplay "listview hwheel";
3561 Some
(coe {< m_pan
= m_pan
+ inc >})
3566 | None
-> m_prev_uioh
3570 match state.mstate
with
3572 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3573 let first = truncate
(s *. float source#getitemcount
) in
3574 let first = min source#getitemcount
first in
3575 G.postRedisplay "listview motion";
3576 coe {< m_first
= first; m_active
= first >}
3579 method pmotion
x y =
3580 if x < conf.winw
- conf.scrollbw
3583 match self#elemunder
y with
3584 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3585 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3589 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3594 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3598 method infochanged
_ = ()
3600 method scrollpw
= (0, 0.0, 0.0)
3602 let nfs = fstate.fontsize
+ 1 in
3603 let y = m_first
* nfs in
3604 let itemcount = source#getitemcount
in
3605 let maxi = max
0 (itemcount - fstate.maxrows
) in
3606 let maxy = maxi * nfs in
3607 let p, h = scrollph y maxy in
3610 method modehash
= modehash
3613 class outlinelistview ~source
=
3616 ~source
:(source
:> lvsource
)
3618 ~modehash
:(findkeyhash conf "outline")
3621 method key key mask
=
3622 let calcfirst first active =
3625 let rows = active - first in
3627 if String.length
state.text = 0
3629 else fstate.maxrows - 2
3631 if rows > maxrows then active - maxrows else first
3635 let active = m_active
+ incr in
3636 let active = bound active 0 (source#getitemcount
- 1) in
3637 let first = calcfirst m_first
active in
3638 G.postRedisplay "outline navigate";
3639 coe {< m_active
= active; m_first
= first >}
3641 let ctrl = Wsi.withctrl mask
in
3643 | 110 when ctrl -> (* ctrl-n *)
3644 source#narrow m_qsearch
;
3645 G.postRedisplay "outline ctrl-n";
3646 coe {< m_first
= 0; m_active
= 0 >}
3648 | 117 when ctrl -> (* ctrl-u *)
3650 G.postRedisplay "outline ctrl-u";
3652 coe {< m_first
= 0; m_active
= 0 >}
3654 | 108 when ctrl -> (* ctrl-l *)
3655 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3656 G.postRedisplay "outline ctrl-l";
3657 coe {< m_first
= first >}
3659 | 0xff9f | 0xffff -> (* (kp) delete *)
3660 source#remove m_active
;
3661 G.postRedisplay "outline delete";
3662 let active = max
0 (m_active
-1) in
3663 coe {< m_first
= firstof m_first
active;
3664 m_active
= active >}
3666 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3667 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3668 | 0xff55 | 0xff9a -> (* (kp) prior *)
3669 navigate ~
-(fstate.maxrows)
3670 | 0xff56 | 0xff9b -> (* (kp) next *)
3671 navigate fstate.maxrows
3673 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3677 G.postRedisplay "outline ctrl right";
3678 {< m_pan
= m_pan
+ 1 >}
3680 else self#updownlevel
1
3684 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3688 G.postRedisplay "outline ctrl left";
3689 {< m_pan
= m_pan
- 1 >}
3691 else self#updownlevel ~
-1
3695 | 0xff50 | 0xff95 -> (* (kp) home *)
3696 G.postRedisplay "outline home";
3697 coe {< m_first
= 0; m_active
= 0 >}
3699 | 0xff57 | 0xff9c -> (* (kp) end *)
3700 let active = source#getitemcount
- 1 in
3701 let first = max
0 (active - fstate.maxrows) in
3702 G.postRedisplay "outline end";
3703 coe {< m_active
= active; m_first
= first >}
3705 | _ -> super#
key key mask
3708 let outlinesource usebookmarks
=
3711 inherit lvsourcebase
3712 val mutable m_items
= empty
3713 val mutable m_orig_items
= empty
3714 val mutable m_prev_items
= empty
3715 val mutable m_narrow_pattern
= ""
3716 val mutable m_hadremovals
= false
3718 method getitemcount
=
3719 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3722 if n == Array.length m_items
&& m_hadremovals
3724 ("[Confirm removal]", 0)
3726 let s, n, _ = m_items
.(n) in
3729 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3730 ignore
(uioh
, first, qsearch);
3731 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3733 if String.length m_narrow_pattern
= 0
3739 if not
confrimremoval
3741 let _, _, anchor = m_items
.(active) in
3742 gotoghyll (getanchory anchor);
3746 state.bookmarks
<- Array.to_list m_items
;
3747 m_orig_items
<- m_items
;
3750 else m_items
<- items;
3754 method hasaction
_ = true
3757 if Array.length m_items
!= Array.length m_orig_items
3758 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3761 method narrow
pattern =
3762 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3766 let rec loop accu n =
3769 m_narrow_pattern
<- pattern;
3770 m_items
<- Array.of_list
accu
3773 let (s, _, _) as o = m_items
.(n) in
3775 if (try ignore
(Str.search_forward
re s 0); true
3776 with Not_found
-> false)
3782 loop [] (Array.length m_items
- 1)
3787 then Array.of_list
state.bookmarks
3790 m_items
<- m_orig_items
3795 if m >= 0 && m < Array.length m_items
3797 m_hadremovals
<- true;
3798 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3799 let n = if n >= m then n+1 else n in
3804 method reset
anchor items =
3805 m_hadremovals
<- false;
3806 if m_orig_items
== empty || m_prev_items
!= items
3808 m_orig_items
<- items;
3809 if String.length m_narrow_pattern
= 0
3810 then m_items
<- items;
3812 m_prev_items
<- items;
3813 let rely = getanchory anchor in
3815 let rec loop n best bestd
=
3816 if n = Array.length m_items
3819 let (_, _, anchor) = m_items
.(n) in
3820 let orely = getanchory anchor in
3821 let d = abs
(orely - rely) in
3824 else loop (n+1) best bestd
3829 m_first
<- firstof m_first
active
3833 let enterselector usebookmarks
=
3834 let source = outlinesource usebookmarks
in
3838 then Array.of_list
state.bookmarks
3841 if Array.length
outlines = 0
3843 showtext ' ' errmsg
;
3846 state.text <- source#greetmsg
;
3847 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3848 let anchor = getanchor () in
3849 source#reset
anchor outlines;
3850 state.uioh
<- coe (new outlinelistview ~
source);
3851 G.postRedisplay "enter selector";
3855 let enteroutlinemode =
3856 let f = enterselector false in
3857 fun ()-> f "Document has no outline";
3860 let enterbookmarkmode =
3861 let f = enterselector true in
3862 fun () -> f "Document has no bookmarks (yet)";
3865 let color_of_string s =
3866 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3867 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3871 let color_to_string (r, g
, b) =
3872 let r = truncate
(r *. 256.0)
3873 and g
= truncate
(g
*. 256.0)
3874 and b = truncate
(b *. 256.0) in
3875 Printf.sprintf
"%d/%d/%d" r g
b
3878 let irect_of_string s =
3879 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3882 let irect_to_string (x0,y0,x1,y1) =
3883 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3886 let makecheckers () =
3887 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3889 converted by Issac Trotts. July 25, 2002 *)
3890 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3891 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3892 let id = GlTex.gen_texture
() in
3893 GlTex.bind_texture `texture_2d
id;
3894 GlPix.store
(`unpack_alignment
1);
3895 GlTex.image2d
image;
3896 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3899 `mag_filter `nearest
;
3900 `min_filter `nearest
];
3904 let setcheckers enabled
=
3905 match state.texid
with
3907 if enabled
then state.texid
<- Some
(makecheckers ())
3912 GlTex.delete_texture texid
;
3913 state.texid
<- None
;
3917 let int_of_string_with_suffix s =
3918 let l = String.length
s in
3922 let suffix = Char.lowercase
s.[l-1] in
3924 | 'k'
-> String.sub
s 0 (l-1), 10
3925 | '
m'
-> String.sub
s 0 (l-1), 20
3926 | 'g'
-> String.sub
s 0 (l-1), 30
3930 let n = int_of_string
s1 in
3931 let m = n lsl shift
in
3933 then raise
(Failure
"value too large")
3937 let string_with_suffix_of_int n =
3942 if n land ((1 lsl 30) - 1) = 0
3945 if n land ((1 lsl 20) - 1) = 0
3948 if n land ((1 lsl 10) - 1) = 0
3955 let h = n mod 1000 in
3958 then string_of_int
h ^
s
3960 let s = Printf.sprintf
"_%03d%s" h s in
3967 let defghyllscroll = (40, 8, 32);;
3968 let ghyllscroll_of_string s =
3969 let (n, a, b) as nab
=
3972 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3974 if n <= a || n <= b || a >= b
3975 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3979 let ghyllscroll_to_string ((n, a, b) as nab
) =
3980 if nab
= defghyllscroll
3982 else Printf.sprintf
"%d,%d,%d" n a b;
3985 let describe_location () =
3987 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3989 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3990 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3994 else (100. *. (float state.y /. float maxy))
3998 Printf.sprintf
"page %d of %d [%.2f%%]"
3999 (fn+1) state.pagecount
percent
4002 "pages %d-%d of %d [%.2f%%]"
4003 (fn+1) (ln
+1) state.pagecount
percent
4006 let setpresentationmode v
=
4007 let (n, _, _) = getanchor () in
4008 let _, h = getpageyh n in
4009 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
4010 state.anchor <- (n, 0.0, float ips);
4011 conf.presentation
<- v
;
4012 if conf.presentation
4014 if not
conf.scrollbarinpm
4015 then state.scrollw
<- 0;
4017 else state.scrollw
<- conf.scrollbw
;
4022 let btos b = if b then "\xe2\x88\x9a" else "" in
4023 let showextended = ref false in
4024 let leave mode
= function
4025 | Confirm
-> state.mode
<- mode
4026 | Cancel
-> state.mode
<- mode
in
4029 val mutable m_first_time
= true
4030 val mutable m_l
= []
4031 val mutable m_a
= [||]
4032 val mutable m_prev_uioh
= nouioh
4033 val mutable m_prev_mode
= View
4035 inherit lvsourcebase
4037 method reset prev_mode prev_uioh
=
4038 m_a
<- Array.of_list
(List.rev m_l
);
4040 m_prev_mode
<- prev_mode
;
4041 m_prev_uioh
<- prev_uioh
;
4045 if n >= Array.length m_a
4049 | _, _, _, Action
_ -> m_active
<- n
4053 m_first_time
<- false;
4056 method int name get
set =
4058 (name
, `
int get
, 1, Action
(
4061 try set (int_of_string
s)
4063 state.text <- Printf.sprintf
"bad integer `%s': %s"
4064 s (Printexc.to_string exn
)
4067 let te = name ^
": ", "", None
, intentry, ondone, true in
4068 state.mode
<- Textentry
(te, leave m_prev_mode
);
4072 method int_with_suffix name get
set =
4074 (name
, `intws get
, 1, Action
(
4077 try set (int_of_string_with_suffix s)
4079 state.text <- Printf.sprintf
"bad integer `%s': %s"
4080 s (Printexc.to_string exn
)
4084 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4086 state.mode
<- Textentry
(te, leave m_prev_mode
);
4090 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4092 (name
, `
bool (btos, get
), offset
, Action
(
4099 method color name get
set =
4101 (name
, `color get
, 1, Action
(
4103 let invalid = (nan
, nan
, nan
) in
4106 try color_of_string s
4108 state.text <- Printf.sprintf
"bad color `%s': %s"
4109 s (Printexc.to_string exn
);
4115 let te = name ^
": ", "", None
, textentry, ondone, true in
4116 state.text <- color_to_string (get
());
4117 state.mode
<- Textentry
(te, leave m_prev_mode
);
4121 method string name get
set =
4123 (name
, `
string get
, 1, Action
(
4125 let ondone s = set s in
4126 let te = name ^
": ", "", None
, textentry, ondone, true in
4127 state.mode
<- Textentry
(te, leave m_prev_mode
);
4131 method colorspace name get
set =
4133 (name
, `
string get
, 1, Action
(
4136 let vals = [| "rgb"; "bgr"; "gray" |] in
4138 inherit lvsourcebase
4141 m_active
<- int_of_colorspace conf.colorspace
;
4144 method getitemcount
= Array.length
vals
4145 method getitem
n = (vals.(n), 0)
4146 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4147 ignore
(uioh
, first, pan
, qsearch);
4148 if not cancel
then set active;
4150 method hasaction
_ = true
4154 let modehash = findkeyhash conf "info" in
4155 coe (new listview ~
source ~trusted
:true ~
modehash)
4158 method caption
s offset
=
4159 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4161 method caption2
s f offset
=
4162 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4164 method getitemcount
= Array.length m_a
4167 let tostr = function
4168 | `
int f -> string_of_int
(f ())
4169 | `intws
f -> string_with_suffix_of_int (f ())
4171 | `color
f -> color_to_string (f ())
4172 | `
bool (btos, f) -> btos (f ())
4175 let name, t
, offset
, _ = m_a
.(n) in
4176 ((let s = tostr t
in
4177 if String.length
s > 0
4178 then Printf.sprintf
"%s\t%s" name s
4182 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4186 m_qsearch
<- qsearch;
4188 match m_a
.(active) with
4189 | _, _, _, Action
f -> f uioh
4201 method hasaction
n =
4203 | _, _, _, Action
_ -> true
4207 let rec fillsrc prevmode prevuioh
=
4208 let sep () = src#caption
"" 0 in
4209 let colorp name get
set =
4211 (fun () -> color_to_string (get
()))
4214 let c = color_of_string v in
4217 state.text <- Printf.sprintf
"bad color `%s': %s"
4218 v (Printexc.to_string exn
);
4221 let oldmode = state.mode
in
4222 let birdseye = isbirdseye state.mode
in
4224 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4226 src#
bool "presentation mode"
4227 (fun () -> conf.presentation
)
4228 (fun v -> setpresentationmode v);
4230 src#
bool "ignore case in searches"
4231 (fun () -> conf.icase
)
4232 (fun v -> conf.icase
<- v);
4235 (fun () -> conf.preload)
4236 (fun v -> conf.preload <- v);
4238 src#
bool "highlight links"
4239 (fun () -> conf.hlinks
)
4240 (fun v -> conf.hlinks
<- v);
4242 src#
bool "under info"
4243 (fun () -> conf.underinfo
)
4244 (fun v -> conf.underinfo
<- v);
4246 src#
bool "persistent bookmarks"
4247 (fun () -> conf.savebmarks
)
4248 (fun v -> conf.savebmarks
<- v);
4250 src#
bool "proportional display"
4251 (fun () -> conf.proportional
)
4252 (fun v -> reqlayout conf.angle
v);
4254 src#
bool "trim margins"
4255 (fun () -> conf.trimmargins
)
4256 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4258 src#
bool "persistent location"
4259 (fun () -> conf.jumpback
)
4260 (fun v -> conf.jumpback
<- v);
4263 src#
int "inter-page space"
4264 (fun () -> conf.interpagespace
)
4266 conf.interpagespace
<- n;
4267 docolumns conf.columns
;
4269 match state.layout with
4274 state.maxy <- calcheight ();
4275 let y = getpagey pageno in
4280 (fun () -> conf.pagebias
)
4281 (fun v -> conf.pagebias
<- v);
4283 src#
int "scroll step"
4284 (fun () -> conf.scrollstep
)
4285 (fun n -> conf.scrollstep
<- n);
4287 src#
int "horizontal scroll step"
4288 (fun () -> conf.hscrollstep
)
4289 (fun v -> conf.hscrollstep
<- v);
4291 src#
int "auto scroll step"
4293 match state.autoscroll
with
4295 | _ -> conf.autoscrollstep
)
4297 if state.autoscroll
<> None
4298 then state.autoscroll
<- Some
n;
4299 conf.autoscrollstep
<- n);
4302 (fun () -> truncate
(conf.zoom *. 100.))
4303 (fun v -> setzoom ((float v) /. 100.));
4306 (fun () -> conf.angle
)
4307 (fun v -> reqlayout v conf.proportional
);
4309 src#
int "scroll bar width"
4310 (fun () -> state.scrollw
)
4314 reshape conf.winw
conf.winh
;
4317 src#
int "scroll handle height"
4318 (fun () -> conf.scrollh
)
4319 (fun v -> conf.scrollh
<- v;);
4321 src#
int "thumbnail width"
4322 (fun () -> conf.thumbw
)
4324 conf.thumbw
<- min
4096 v;
4327 leavebirdseye beye
false;
4332 let mode = state.mode in
4333 src#
string "columns"
4335 match conf.columns
with
4337 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4338 | Csplit
(count
, _) -> "-" ^ string_of_int count
4341 let n, a, b = multicolumns_of_string v in
4342 setcolumns mode n a b);
4345 src#caption
"Presentation mode" 0;
4346 src#
bool "scrollbar visible"
4347 (fun () -> conf.scrollbarinpm
)
4349 if v != conf.scrollbarinpm
4351 conf.scrollbarinpm
<- v;
4352 if conf.presentation
4354 state.scrollw
<- if v then conf.scrollbw
else 0;
4355 reshape conf.winw
conf.winh
;
4361 src#caption
"Pixmap cache" 0;
4362 src#int_with_suffix
"size (advisory)"
4363 (fun () -> conf.memlimit
)
4364 (fun v -> conf.memlimit
<- v);
4367 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4368 (string_with_suffix_of_int state.memused
)
4369 (Hashtbl.length
state.tilemap
)) 1;
4372 src#caption
"Layout" 0;
4373 src#caption2
"Dimension"
4375 Printf.sprintf
"%dx%d (virtual %dx%d)"
4381 src#caption2
"Position" (fun () ->
4382 Printf.sprintf
"%dx%d" state.x state.y
4385 src#caption2
"Visible" (fun () -> describe_location ()) 1
4389 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4390 "Save these parameters as global defaults at exit"
4391 (fun () -> conf.bedefault
)
4392 (fun v -> conf.bedefault
<- v)
4396 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4397 src#
bool ~offset
:0 ~
btos "Extended parameters"
4398 (fun () -> !showextended)
4399 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4403 (fun () -> conf.checkers
)
4404 (fun v -> conf.checkers
<- v; setcheckers v);
4405 src#
bool "update cursor"
4406 (fun () -> conf.updatecurs
)
4407 (fun v -> conf.updatecurs
<- v);
4409 (fun () -> conf.verbose
)
4410 (fun v -> conf.verbose
<- v);
4411 src#
bool "invert colors"
4412 (fun () -> conf.invert
)
4413 (fun v -> conf.invert
<- v);
4415 (fun () -> conf.maxhfit
)
4416 (fun v -> conf.maxhfit
<- v);
4417 src#
bool "redirect stderr"
4418 (fun () -> conf.redirectstderr)
4419 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4420 src#
string "uri launcher"
4421 (fun () -> conf.urilauncher
)
4422 (fun v -> conf.urilauncher
<- v);
4423 src#
string "path launcher"
4424 (fun () -> conf.pathlauncher
)
4425 (fun v -> conf.pathlauncher
<- v);
4426 src#
string "tile size"
4427 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4430 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4431 conf.tilew
<- max
64 w;
4432 conf.tileh
<- max
64 h;
4435 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4436 v (Printexc.to_string exn
));
4437 src#
int "texture count"
4438 (fun () -> conf.texcount
)
4441 then conf.texcount
<- v
4442 else showtext '
!'
" Failed to set texture count please retry later"
4444 src#
int "slice height"
4445 (fun () -> conf.sliceheight
)
4447 conf.sliceheight
<- v;
4448 wcmd "sliceh %d" conf.sliceheight
;
4450 src#
int "anti-aliasing level"
4451 (fun () -> conf.aalevel
)
4453 conf.aalevel
<- bound v 0 8;
4454 state.anchor <- getanchor ();
4455 opendoc state.path
state.password
;
4457 src#
string "page scroll scaling factor"
4458 (fun () -> string_of_float
conf.pgscale)
4461 let s = float_of_string
v in
4464 state.text <- Printf.sprintf
4465 "bad page scroll scaling factor `%s': %s"
4466 v (Printexc.to_string exn
)
4469 src#
int "ui font size"
4470 (fun () -> fstate.fontsize
)
4471 (fun v -> setfontsize (bound v 5 100));
4472 src#
int "hint font size"
4473 (fun () -> conf.hfsize
)
4474 (fun v -> conf.hfsize
<- bound v 5 100);
4475 colorp "background color"
4476 (fun () -> conf.bgcolor
)
4477 (fun v -> conf.bgcolor
<- v);
4478 src#
bool "crop hack"
4479 (fun () -> conf.crophack
)
4480 (fun v -> conf.crophack
<- v);
4481 src#
string "trim fuzz"
4482 (fun () -> irect_to_string conf.trimfuzz
)
4485 conf.trimfuzz
<- irect_of_string v;
4487 then settrim true conf.trimfuzz
;
4489 state.text <- Printf.sprintf
"bad irect `%s': %s"
4490 v (Printexc.to_string exn
)
4492 src#
string "throttle"
4494 match conf.maxwait
with
4495 | None
-> "show place holder if page is not ready"
4498 then "wait for page to fully render"
4500 "wait " ^ string_of_float
time
4501 ^
" seconds before showing placeholder"
4505 let f = float_of_string
v in
4507 then conf.maxwait
<- None
4508 else conf.maxwait
<- Some
f
4510 state.text <- Printf.sprintf
"bad time `%s': %s"
4511 v (Printexc.to_string exn
)
4513 src#
string "ghyll scroll"
4515 match conf.ghyllscroll
with
4517 | Some nab
-> ghyllscroll_to_string nab
4522 if String.length
v = 0
4524 else Some
(ghyllscroll_of_string v)
4526 conf.ghyllscroll
<- gs
4528 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4529 v (Printexc.to_string exn
)
4531 src#
string "selection command"
4532 (fun () -> conf.selcmd
)
4533 (fun v -> conf.selcmd
<- v);
4534 src#colorspace
"color space"
4535 (fun () -> colorspace_to_string conf.colorspace
)
4537 conf.colorspace
<- colorspace_of_int v;
4544 (fun () -> conf.usepbo
)
4545 (fun v -> conf.usepbo
<- v);
4546 src#
bool "mouse wheel scrolls pages"
4547 (fun () -> conf.wheelbypage
)
4548 (fun v -> conf.wheelbypage
<- v);
4552 src#caption
"Document" 0;
4553 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4554 src#caption2
"Pages"
4555 (fun () -> string_of_int
state.pagecount
) 1;
4556 src#caption2
"Dimensions"
4557 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4561 src#caption
"Trimmed margins" 0;
4562 src#caption2
"Dimensions"
4563 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4567 src#caption
"OpenGL" 0;
4568 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4569 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4570 src#reset prevmode prevuioh
;
4574 let prevmode = state.mode
4575 and prevuioh
= state.uioh in
4576 fillsrc prevmode prevuioh
;
4577 let source = (src :> lvsource
) in
4578 let modehash = findkeyhash conf "info" in
4579 state.uioh <- coe (object (self)
4580 inherit listview ~
source ~trusted
:true ~
modehash as super
4581 val mutable m_prevmemused
= 0
4582 method infochanged
= function
4584 if m_prevmemused
!= state.memused
4586 m_prevmemused
<- state.memused
;
4587 G.postRedisplay "memusedchanged";
4589 | Pdim
-> G.postRedisplay "pdimchanged"
4590 | Docinfo
-> fillsrc prevmode prevuioh
4592 method key key mask
=
4593 if not
(Wsi.withctrl mask
)
4596 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4597 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4598 | _ -> super#
key key mask
4599 else super#
key key mask
4601 G.postRedisplay "info";
4607 inherit lvsourcebase
4608 method getitemcount
= Array.length
state.help
4610 let s, l, _ = state.help
.(n) in
4613 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4617 m_qsearch
<- qsearch;
4618 match state.help
.(active) with
4619 | _, _, Action
f -> Some
(f uioh)
4629 method hasaction
n =
4630 match state.help
.(n) with
4631 | _, _, Action
_ -> true
4638 let modehash = findkeyhash conf "help" in
4639 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4640 G.postRedisplay "help";
4645 let re = Str.regexp
"[\r\n]" in
4647 inherit lvsourcebase
4648 val mutable m_items
= [||]
4650 method getitemcount
= 1 + Array.length m_items
4655 else m_items
.(n-1), 0
4657 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4662 then Buffer.clear
state.errmsgs
;
4663 m_qsearch
<- qsearch;
4670 method hasaction
n =
4674 state.newerrmsgs
<- false;
4675 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4676 m_items
<- Array.of_list
l
4684 let source = (msgsource :> lvsource
) in
4685 let modehash = findkeyhash conf "listview" in
4686 state.uioh <- coe (object
4687 inherit listview ~
source ~trusted
:false ~
modehash as super
4690 then msgsource#reset
;
4693 G.postRedisplay "msgs";
4696 let quickbookmark ?title
() =
4697 match state.layout with
4703 let sec = Unix.gettimeofday
() in
4704 let tm = Unix.localtime
sec in
4705 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4709 (tm.Unix.tm_year
+ 1900)
4712 | Some
title -> title
4714 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4718 state.fullscreen
<- None
;
4722 let setautoscrollspeed step goingdown
=
4723 let incr = max
1 ((abs step
) / 2) in
4724 let incr = if goingdown
then incr else -incr in
4725 let astep = step
+ incr in
4726 state.autoscroll
<- Some
astep;
4729 let gotounder = function
4730 | Ulinkgoto
(pageno, top) ->
4734 gotopage1 pageno top;
4740 | Uremote
(filename
, pageno) ->
4742 if Sys.file_exists filename
4745 let dir = Filename.dirname
state.path in
4746 let path = Filename.concat
dir filename
in
4747 if Sys.file_exists
path
4751 if String.length
path > 0
4753 let anchor = getanchor () in
4754 let ranchor = state.path, state.password
, anchor in
4755 state.anchor <- (pageno, 0.0, 0.0);
4756 state.ranchors
<- ranchor :: state.ranchors
;
4759 else showtext '
!'
("Could not find " ^ filename
)
4761 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4765 match conf.columns
with
4767 | _ -> conf.zoom > 1.0
4770 let existsinrow pageno (columns
, coverA
, coverB
) p =
4771 let last = ((pageno - coverA
) mod columns
) + columns
in
4772 let rec any = function
4775 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4779 then (if l.pageno = last then false else any rest
)
4787 match state.layout with
4790 match conf.columns
with
4792 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4794 let y = clamp (pgscale conf.winh
) in
4797 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4798 gotoghyll (getpagey pageno)
4799 | Cmulti
((c, _, _) as cl
, _) ->
4800 if conf.presentation
4801 && (existsinrow l.pageno cl
4802 (fun l -> l.pageh
> l.pagey + l.pagevh))
4804 let y = clamp (pgscale conf.winh
) in
4807 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4808 gotoghyll (getpagey pageno)
4810 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4812 let pagey, pageh
= getpageyh l.pageno in
4813 let pagey = pagey + pageh
* l.pagecol
in
4814 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4815 gotoghyll (pagey + pageh
+ ips)
4819 match state.layout with
4822 match conf.columns
with
4824 if conf.presentation
&& l.pagey != 0
4826 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4828 let pageno = max
0 (l.pageno-1) in
4829 gotoghyll (getpagey pageno)
4830 | Cmulti
((c, _, coverB
) as cl
, _) ->
4831 if conf.presentation
&&
4832 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4834 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4837 if l.pageno = state.pagecount
- coverB
4841 let pageno = max
0 (l.pageno-decr) in
4842 gotoghyll (getpagey pageno)
4850 let pageno = max
0 (l.pageno-1) in
4851 let pagey, pageh
= getpageyh pageno in
4854 let pagey, pageh
= getpageyh l.pageno in
4855 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4860 let viewkeyboard key mask
=
4862 let mode = state.mode in
4863 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4866 G.postRedisplay "view:enttext"
4868 let ctrl = Wsi.withctrl mask
in
4870 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4876 | 0xff63 -> (* insert *)
4877 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4879 state.mode <- LinkNav
(Ltgendir
0);
4882 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4884 | 0xff1b | 113 -> (* escape / q *)
4885 begin match state.mstate
with
4887 state.mstate
<- Mnone
;
4888 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4889 G.postRedisplay "kill zoom rect";
4891 begin match state.mode with
4894 G.postRedisplay "esc leave linknav"
4896 match state.ranchors
with
4898 | (path, password
, anchor) :: rest
->
4899 state.ranchors
<- rest
;
4900 state.anchor <- anchor;
4901 opendoc path password
4905 | 0xff08 -> (* backspace *)
4906 gotoghyll (getnav ~
-1)
4914 G.postRedisplay "dehighlight";
4916 | 47 | 63 -> (* / ? *)
4917 let ondone isforw
s =
4918 cbput state.hists
.pat
s;
4919 state.searchpattern
<- s;
4922 let s = String.create
1 in
4923 s.[0] <- Char.chr
key;
4924 enttext (s, "", Some
(onhist state.hists
.pat
),
4925 textentry, ondone (key = 47), true)
4927 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4928 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4929 setzoom (conf.zoom +. incr)
4931 | 43 | 0xffab -> (* + *)
4934 try int_of_string
s with exc
->
4935 state.text <- Printf.sprintf
"bad integer `%s': %s"
4936 s (Printexc.to_string exc
);
4942 state.text <- "page bias is now " ^ string_of_int
n;
4945 enttext ("page bias: ", "", None
, intentry, ondone, true)
4947 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4948 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4949 setzoom (max
0.01 (conf.zoom -. decr))
4951 | 45 | 0xffad -> (* - *)
4952 let ondone msg
= state.text <- msg
in
4954 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4955 optentry state.mode, ondone, true
4958 | 48 when ctrl -> (* ctrl-0 *)
4961 | 49 when ctrl -> (* ctrl-1 *)
4963 match conf.columns
with
4964 | Csingle
_ | Cmulti
_ -> 1
4965 | Csplit
(n, _) -> n
4967 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4971 | 0xffc6 -> (* f9 *)
4974 | 57 when ctrl -> (* ctrl-9 *)
4977 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4978 when not
ctrl -> (* 0..9 *)
4981 try int_of_string
s with exc
->
4982 state.text <- Printf.sprintf
"bad integer `%s': %s"
4983 s (Printexc.to_string exc
);
4989 cbput state.hists
.pag
(string_of_int
n);
4990 gotopage1 (n + conf.pagebias
- 1) 0;
4993 let pageentry text key =
4994 match Char.unsafe_chr
key with
4995 | 'g'
-> TEdone
text
4996 | _ -> intentry text key
4998 let text = "x" in text.[0] <- Char.chr
key;
4999 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5002 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5003 reshape conf.winw
conf.winh
;
5006 conf.hlinks
<- not
conf.hlinks
;
5007 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5008 G.postRedisplay "toggle highlightlinks";
5011 state.glinks
<- true;
5012 let mode = state.mode in
5013 state.mode <- Textentry
(
5014 (":", "", None
, linknentry, linkndone gotounder, false),
5016 state.glinks
<- false;
5020 G.postRedisplay "view:linkent(F)"
5023 state.glinks
<- true;
5024 let mode = state.mode in
5025 state.mode <- Textentry
(
5026 (":", "", None
, linknentry, linkndone (fun under ->
5027 match Ne.pipe () with
5029 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
5030 (Printexc.to_string exn
));
5033 try popen conf.selcmd
[r, 0; w, -1]; true
5036 (Printf.sprintf
"failed to execute %s: %s"
5037 conf.selcmd
(Printexc.to_string exn
));
5041 Ne.clo fd
(fun msg
->
5042 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5045 let s = undertext under in
5049 let l = String.length
s in
5050 let n = tempfailureretry (Unix.write
w s 0) l in
5055 "failed to write %d characters to sel pipe, wrote %d"
5060 (Printf.sprintf
"failed to write to sel pipe: %s"
5061 (Printexc.to_string exn
)
5070 state.glinks
<- false;
5074 G.postRedisplay "view:linkent"
5077 begin match state.autoscroll
with
5079 conf.autoscrollstep
<- step
;
5080 state.autoscroll
<- None
5082 if conf.autoscrollstep
= 0
5083 then state.autoscroll
<- Some
1
5084 else state.autoscroll
<- Some
conf.autoscrollstep
5087 | 112 when ctrl -> (* ctrl-p *)
5091 setpresentationmode (not
conf.presentation
);
5092 showtext ' '
("presentation mode " ^
5093 if conf.presentation
then "on" else "off");
5096 begin match state.fullscreen
with
5098 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
5101 state.fullscreen
<- None
;
5105 | 112 | 78 -> (* p|N *)
5106 search state.searchpattern
false
5108 | 110 | 0xffc0 -> (* n|F3 *)
5109 search state.searchpattern
true
5112 begin match state.layout with
5115 gotoy_and_clear_text (getpagey l.pageno)
5121 | 0xff9f | 0xffff -> (* delete *)
5125 showtext ' '
(describe_location ());
5128 begin match state.layout with
5131 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5136 enterbookmarkmode ()
5138 | 104 | 0xffbe -> (* h|F1 *)
5144 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5149 match state.layout with
5151 if String.length
s > 0
5153 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5156 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5160 showtext ' '
"Quick bookmark added";
5163 begin match state.layout with
5165 let rect = getpdimrect
l.pagedimno
in
5169 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5170 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5172 (truncate
(rect.(1) -. rect.(0)),
5173 truncate
(rect.(3) -. rect.(0)))
5175 let w = truncate
((float w)*.conf.zoom)
5176 and h = truncate
((float h)*.conf.zoom) in
5179 state.anchor <- getanchor ();
5180 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5182 G.postRedisplay "z";
5187 | 50 when ctrl -> (* ctrl-2 *)
5188 let maxw = getmaxw
() in
5190 then setzoom (maxw /. float conf.winw
)
5192 | 60 | 62 -> (* < > *)
5193 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5195 | 91 | 93 -> (* [ ] *)
5197 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5199 G.postRedisplay "brightness";
5201 | 99 when state.mode = View
-> (* c *)
5203 match state.prevcolumns
with
5204 | None
-> (1, 0, 0), 1.0
5205 | Some
(columns
, z
) ->
5208 | Csplit
(c, _) -> -c, 0, 0
5209 | Cmulti
((c, a, b), _) -> c, a, b
5210 | Csingle
_ -> 1, 0, 0
5214 setcolumns View
c a b;
5217 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5218 setzoom state.prevzoom
5220 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5221 begin match state.autoscroll
with
5223 begin match state.mode with
5224 | Birdseye beye
-> upbirdseye 1 beye
5227 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5228 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5231 setautoscrollspeed n false
5234 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5235 begin match state.autoscroll
with
5237 begin match state.mode with
5238 | Birdseye beye
-> downbirdseye 1 beye
5241 then gotoy_and_clear_text (clamp (conf.winh
/2))
5242 else gotoy_and_clear_text (clamp conf.scrollstep
)
5245 setautoscrollspeed n true
5248 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5254 else conf.hscrollstep
5256 let dx = if key = 0xff51 then dx else -dx in
5257 state.x <- state.x + dx;
5258 gotoy_and_clear_text state.y
5261 G.postRedisplay "lef/right"
5264 | 0xff55 | 0xff9a -> (* (kp) prior *)
5268 match state.layout with
5270 | l :: _ -> state.y - l.pagey
5272 clamp (pgscale (-conf.winh
))
5276 | 0xff56 | 0xff9b -> (* (kp) next *)
5280 match List.rev
state.layout with
5282 | l :: _ -> getpagey l.pageno
5284 clamp (pgscale conf.winh
)
5288 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5290 | 71 | 0xff57 | 0xff9c -> (* G end *)
5291 gotoghyll (clamp state.maxy)
5293 | 0xff53 when Wsi.withalt mask
-> (* alt-right *)
5294 gotoghyll (getnav 1)
5295 | 0xff51 when Wsi.withalt mask
-> (* alt-left *)
5296 gotoghyll (getnav ~
-1)
5301 | 118 when conf.debug
-> (* v *)
5304 match getopaque l.pageno with
5307 let x0, y0, x1, y1 = pagebbox opaque
in
5308 let a,b = float x0, float y0 in
5309 let c,d = float x1, float y0 in
5310 let e,f = float x1, float y1 in
5311 let h,j
= float x0, float y1 in
5312 let rect = (a,b,c,d,e,f,h,j
) in
5314 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5316 G.postRedisplay "v";
5319 vlog "huh? %s" (Wsi.keyname
key)
5322 let linknavkeyboard key mask
linknav =
5323 let getpage pageno =
5324 let rec loop = function
5326 | l :: _ when l.pageno = pageno -> Some
l
5327 | _ :: rest
-> loop rest
5328 in loop state.layout
5330 let doexact (pageno, n) =
5331 match getopaque pageno, getpage pageno with
5332 | Some opaque
, Some
l ->
5333 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5335 let under = getlink opaque
n in
5336 G.postRedisplay "link gotounder";
5342 | 0xff50 -> (* home *)
5343 Some
(findlink opaque LDfirst
), -1
5345 | 0xff57 -> (* end *)
5346 Some
(findlink opaque LDlast
), 1
5348 | 0xff51 -> (* left *)
5349 Some
(findlink opaque
(LDleft
n)), -1
5351 | 0xff53 -> (* right *)
5352 Some
(findlink opaque
(LDright
n)), 1
5354 | 0xff52 -> (* up *)
5355 Some
(findlink opaque
(LDup
n)), -1
5357 | 0xff54 -> (* down *)
5358 Some
(findlink opaque
(LDdown
n)), 1
5363 begin match findpwl
l.pageno dir with
5367 state.mode <- LinkNav
(Ltgendir
dir);
5368 let y, h = getpageyh pageno in
5371 then y + h - conf.winh
5376 begin match getopaque pageno, getpage pageno with
5377 | Some opaque
, Some
_ ->
5379 let ld = if dir > 0 then LDfirst
else LDlast
in
5382 begin match link with
5384 showlinktype (getlink opaque
m);
5385 state.mode <- LinkNav
(Ltexact
(pageno, m));
5386 G.postRedisplay "linknav jpage";
5393 begin match opt with
5394 | Some Lnotfound
-> pwl l dir;
5395 | Some
(Lfound
m) ->
5399 let _, y0, _, y1 = getlinkrect opaque
m in
5401 then gotopage1 l.pageno y0
5403 let d = fstate.fontsize
+ 1 in
5404 if y1 - l.pagey > l.pagevh - d
5405 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5406 else G.postRedisplay "linknav";
5408 showlinktype (getlink opaque
m);
5409 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5412 | None
-> viewkeyboard key mask
5414 | _ -> viewkeyboard key mask
5419 G.postRedisplay "leave linknav"
5423 | Ltgendir
_ -> viewkeyboard key mask
5424 | Ltexact exact
-> doexact exact
5427 let keyboard key mask
=
5428 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5429 then wcmd "interrupt"
5430 else state.uioh <- state.uioh#
key key mask
5433 let birdseyekeyboard key mask
5434 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5436 match conf.columns
with
5438 | Cmulti
((c, _, _), _) -> c
5439 | Csplit
_ -> failwith
"bird's eye split mode"
5441 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5443 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5444 let y, h = getpageyh pageno in
5445 let top = (conf.winh
- h) / 2 in
5446 gotoy (max
0 (y - top))
5447 | 0xff0d (* enter *)
5448 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5449 | 0xff1b -> leavebirdseye beye
true (* escape *)
5450 | 0xff52 -> upbirdseye incr beye
(* up *)
5451 | 0xff54 -> downbirdseye incr beye
(* down *)
5452 | 0xff51 -> upbirdseye 1 beye
(* left *)
5453 | 0xff53 -> downbirdseye 1 beye
(* right *)
5455 | 0xff55 -> (* prior *)
5456 begin match state.layout with
5460 state.mode <- Birdseye
(
5461 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5463 gotopage1 l.pageno 0;
5466 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5468 | [] -> gotoy (clamp (-conf.winh
))
5470 state.mode <- Birdseye
(
5471 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5473 gotopage1 l.pageno 0
5476 | [] -> gotoy (clamp (-conf.winh
))
5479 | 0xff56 -> (* next *)
5480 begin match List.rev
state.layout with
5482 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5483 begin match layout with
5485 let incr = l.pageh
- l.pagevh in
5490 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5492 G.postRedisplay "birdseye pagedown";
5494 else gotoy (clamp (incr + conf.interpagespace
*2));
5498 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5499 gotopage1 l.pageno 0;
5502 | [] -> gotoy (clamp conf.winh
)
5505 | 0xff50 -> (* home *)
5506 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5509 | 0xff57 -> (* end *)
5510 let pageno = state.pagecount
- 1 in
5511 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5512 if not
(pagevisible state.layout pageno)
5515 match List.rev
state.pdims
with
5517 | (_, _, h, _) :: _ -> h
5519 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5520 else G.postRedisplay "birdseye end";
5521 | _ -> viewkeyboard key mask
5524 let drawpage l linkindexbase
=
5526 match state.mode with
5527 | Textentry
_ -> scalecolor 0.4
5529 | View
-> scalecolor 1.0
5530 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5531 if l.pageno = hooverpageno
5534 if l.pageno = pageno
5540 begin match getopaque l.pageno with
5542 if tileready l l.pagex
l.pagey
5544 let x = l.pagedispx - l.pagex
5545 and y = l.pagedispy - l.pagey in
5547 match conf.columns
with
5548 | Csingle
_ | Cmulti
_ ->
5549 (if conf.hlinks
then 1 else 0)
5551 && not
(isbirdseye state.mode) then 2 else 0)
5555 match state.mode with
5556 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5559 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5566 let scrollindicator () =
5567 let sbw, ph
, sh = state.uioh#
scrollph in
5568 let sbh, pw, sw = state.uioh#scrollpw
in
5570 GlDraw.color (0.64, 0.64, 0.64);
5572 (float (conf.winw
- sbw), 0.)
5573 (float conf.winw
, float conf.winh
)
5576 (0., float (conf.winh
- sbh))
5577 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5579 GlDraw.color (0.0, 0.0, 0.0);
5582 (float (conf.winw
- sbw), ph
)
5583 (float conf.winw
, ph
+. sh)
5586 (pw, float (conf.winh
- sbh))
5587 (pw +. sw, float conf.winh
)
5592 match state.mstate
with
5593 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5596 | Msel
((x0, y0), (x1, y1)) ->
5597 let rec loop = function
5599 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5600 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5601 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5602 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5604 match getopaque l.pageno with
5606 let x0, y0 = pagetranslatepoint l x0 y0 in
5607 let x1, y1 = pagetranslatepoint l x1 y1 in
5608 seltext opaque
(x0, y0, x1, y1);
5616 let showrects rects
=
5618 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5619 GlDraw.polygon_mode `both `fill
;
5620 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5622 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5624 if l.pageno = pageno
5626 let dx = float (l.pagedispx - l.pagex
) in
5627 let dy = float (l.pagedispy - l.pagey) in
5628 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5629 GlDraw.begins `quads
;
5631 GlDraw.vertex2
(x0+.dx, y0+.dy);
5632 GlDraw.vertex2
(x1+.dx, y1+.dy);
5633 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5634 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5645 GlClear.color (scalecolor2 conf.bgcolor
);
5646 GlClear.clear
[`
color];
5647 let rec loop linkindexbase
= function
5649 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5650 loop linkindexbase rest
5653 loop 0 state.layout;
5655 match state.mode with
5656 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5657 begin match getopaque pageno with
5659 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5666 | None
-> state.rects
5673 begin match state.mstate
with
5674 | Mzoomrect
((x0, y0), (x1, y1)) ->
5676 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5677 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5678 GlDraw.rect (float x0, float y0)
5679 (float x1, float y1);
5685 if not
state.wthack then Wsi.swapb
();
5688 let zoomrect x y x1 y1 =
5691 and y0 = min
y y1 in
5692 gotoy (state.y + y0);
5693 state.anchor <- getanchor ();
5694 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5696 if state.w < conf.winw
- state.scrollw
5697 then (conf.winw
- state.scrollw
- state.w) / 2
5700 state.x <- (state.x + margin) - x0;
5702 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5703 state.mstate
<- Mnone
;
5707 let winw = conf.winw - state.scrollw
- 1 in
5708 let s = float x /. float winw in
5709 let destx = truncate
(float (state.w + winw) *. s) in
5710 state.x <- winw - destx;
5711 gotoy_and_clear_text state.y;
5712 state.mstate
<- Mscrollx
;
5716 let s = float y /. float conf.winh
in
5717 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5718 gotoy_and_clear_text desty;
5719 state.mstate
<- Mscrolly
;
5722 let viewmouse button down
x y mask
=
5724 | n when (n == 4 || n == 5) && not down
->
5725 if Wsi.withctrl mask
5727 match state.mstate
with
5728 | Mzoom
(oldn
, i
) ->
5736 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5738 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5740 let zoom = conf.zoom -. incr in
5742 state.mstate
<- Mzoom
(n, 0);
5744 state.mstate
<- Mzoom
(n, i
+1);
5746 else state.mstate
<- Mzoom
(n, 0)
5748 | _ -> state.mstate
<- Mzoom
(n, 0)
5751 match state.autoscroll
with
5752 | Some step
-> setautoscrollspeed step
(n=4)
5763 then -conf.scrollstep
5764 else conf.scrollstep
5766 let incr = incr * 2 in
5767 let y = clamp incr in
5768 gotoy_and_clear_text y
5771 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5772 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5773 gotoy_and_clear_text state.y
5775 | 1 when Wsi.withctrl mask
->
5778 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5779 state.mstate
<- Mpan
(x, y)
5782 state.mstate
<- Mnone
5787 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5789 state.mstate
<- Mzoomrect
(p, p)
5792 match state.mstate
with
5793 | Mzoomrect
((x0, y0), _) ->
5794 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5795 then zoomrect x0 y0 x y
5797 state.mstate
<- Mnone
;
5798 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5799 G.postRedisplay "kill accidental zoom rect";
5802 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5803 state.mstate
<- Mnone
5806 | 1 when x > conf.winw - state.scrollw
->
5809 let _, position, sh = state.uioh#
scrollph in
5810 if y > truncate
position && y < truncate
(position +. sh)
5811 then state.mstate
<- Mscrolly
5814 state.mstate
<- Mnone
5816 | 1 when y > conf.winh
- state.hscrollh ->
5819 let _, position, sw = state.uioh#scrollpw
in
5820 if x > truncate
position && x < truncate
(position +. sw)
5821 then state.mstate
<- Mscrollx
5824 state.mstate
<- Mnone
5827 let dest = if down
then getunder x y else Unone
in
5828 begin match dest with
5832 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5835 | Unone
when down
->
5836 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5837 state.mstate
<- Mpan
(x, y);
5839 | Unone
| Utext
_ ->
5842 if conf.angle
mod 360 = 0
5844 state.mstate
<- Msel
((x, y), (x, y));
5845 G.postRedisplay "mouse select";
5849 match state.mstate
with
5852 | Mzoom
_ | Mscrollx
| Mscrolly
->
5853 state.mstate
<- Mnone
5855 | Mzoomrect
((x0, y0), _) ->
5859 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5860 state.mstate
<- Mnone
5862 | Msel
((x0, y0), (x1, y1)) ->
5863 let rec loop = function
5867 let a0 = l.pagedispy in
5868 let a1 = a0 + l.pagevh in
5869 let b0 = l.pagedispx in
5870 let b1 = b0 + l.pagevw in
5871 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5872 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5876 match getopaque l.pageno with
5879 match Ne.pipe () with
5883 "can not create sel pipe: %s"
5884 (Printexc.to_string exn
));
5886 let doclose what fd
=
5887 Ne.clo fd
(fun msg
->
5888 dolog "%s close failed: %s" what msg
)
5891 popen conf.selcmd
[r, 0; w, -1];
5894 G.postRedisplay "copysel";
5896 dolog "can not execute %S: %s"
5897 conf.selcmd
(Printexc.to_string exn
);
5905 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5906 state.mstate
<- Mnone
;
5913 let birdseyemouse button down
x y mask
5914 (conf, leftx
, _, hooverpageno
, anchor) =
5917 let rec loop = function
5920 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5921 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5923 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5929 | _ -> viewmouse button down
x y mask
5932 let mouse button down
x y mask
=
5933 state.uioh <- state.uioh#button button down
x y mask
;
5937 state.uioh <- state.uioh#
motion x y
5941 state.uioh <- state.uioh#
pmotion x y;
5947 method key key mask
=
5948 begin match state.mode with
5949 | Textentry
textentry -> textentrykeyboard key mask
textentry
5950 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5951 | View
-> viewkeyboard key mask
5952 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5956 method button button bstate
x y mask
=
5957 begin match state.mode with
5959 | View
-> viewmouse button bstate
x y mask
5960 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5966 begin match state.mode with
5968 | View
| Birdseye
_ | LinkNav
_ ->
5969 match state.mstate
with
5970 | Mzoom
_ | Mnone
-> ()
5975 state.mstate
<- Mpan
(x, y);
5977 then state.x <- state.x + dx;
5979 gotoy_and_clear_text y
5982 state.mstate
<- Msel
(a, (x, y));
5983 G.postRedisplay "motion select";
5986 let y = min
conf.winh
(max
0 y) in
5990 let x = min
conf.winw (max
0 x) in
5993 | Mzoomrect
(p0
, _) ->
5994 state.mstate
<- Mzoomrect
(p0
, (x, y));
5995 G.postRedisplay "motion zoomrect";
5999 method pmotion x y =
6000 begin match state.mode with
6001 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6002 let rec loop = function
6004 if hooverpageno
!= -1
6006 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6007 G.postRedisplay "pmotion birdseye no hoover";
6010 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6011 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6013 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6014 G.postRedisplay "pmotion birdseye hoover";
6024 match state.mstate
with
6025 | Mnone
-> updateunder x y
6026 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6031 method infochanged
_ = ()
6034 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
6035 let p, h = scrollph state.y maxy in
6039 let winw = conf.winw - state.scrollw
- 1 in
6040 let fwinw = float winw in
6042 let sw = fwinw /. float state.w in
6043 let sw = fwinw *. sw in
6044 max
sw (float conf.scrollh
)
6047 let f = state.w+winw in
6048 let r = float (winw-state.x) /. float f in
6049 let p = fwinw *. r in
6053 if position +. sw > fwinw
6054 then fwinw -. position
6057 state.hscrollh, position, sw
6061 match state.mode with
6062 | LinkNav
_ -> "links"
6063 | Textentry
_ -> "textentry"
6064 | Birdseye
_ -> "birdseye"
6067 findkeyhash conf modename
6074 let fontpath = ref "";;
6077 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6080 let l = String.length
s in
6081 let b = Buffer.create
l in
6087 try Sys.getenv
"HOME"
6090 ("Can not determine home directory location: " ^
6091 Printexc.to_string exn
);
6095 let modifier_of_string = function
6096 | "alt" -> Wsi.altmask
6097 | "shift" -> Wsi.shiftmask
6098 | "ctrl" | "control" -> Wsi.ctrlmask
6099 | "meta" -> Wsi.metamask
6104 let r = Str.regexp
"-" in
6106 let elems = Str.full_split
r s in
6109 let m1 = modifier_of_string s in
6111 then (Wsi.namekey
s, m)
6114 | Str.Delim
s when n land 1 = 0 -> g s
6116 | Str.Delim
_ -> (k
, m)
6118 let rec loop n k
m = function
6121 let k, m = f n k m x in
6127 let keys_of_string =
6128 let r = Str.regexp
"[ \t]" in
6130 let elems = Str.split
r s in
6131 List.map
key_of_string elems
6134 let copykeyhashes c =
6135 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6138 let config_of c attrs
=
6142 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6143 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6144 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6145 | "preload" -> { c with preload = bool_of_string
v }
6146 | "page-bias" -> { c with pagebias
= int_of_string
v }
6147 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6148 | "horizontal-scroll-step" ->
6149 { c with hscrollstep
= max
(int_of_string
v) 1 }
6150 | "auto-scroll-step" ->
6151 { c with autoscrollstep
= max
0 (int_of_string
v) }
6152 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6153 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6156 match String.lowercase
v with
6157 | "true" -> Some infinity
6159 | f -> Some
(float_of_string
f)
6161 { c with maxwait
= mw}
6162 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6163 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6164 | "vertical-margin" ->
6165 { c with interpagespace
= max
0 (int_of_string
v) }
6167 let zoom = float_of_string
v /. 100. in
6168 let zoom = max
zoom 0.0 in
6169 { c with zoom = zoom }
6170 | "presentation" -> { c with presentation
= bool_of_string
v }
6171 | "rotation-angle" -> { c with angle
= int_of_string
v }
6172 | "width" -> { c with winw = max
20 (int_of_string
v) }
6173 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6174 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6175 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6176 | "pixmap-cache-size" ->
6177 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6178 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6179 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6180 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6181 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6182 | "background-color" -> { c with bgcolor
= color_of_string v }
6183 | "scrollbar-in-presentation" ->
6184 { c with scrollbarinpm
= bool_of_string
v }
6185 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6186 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6187 | "mupdf-store-size" ->
6188 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6189 | "checkers" -> { c with checkers
= bool_of_string
v }
6190 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6191 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6192 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6193 | "uri-launcher" -> { c with urilauncher
= unent v }
6194 | "path-launcher" -> { c with pathlauncher
= unent v }
6195 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6196 | "invert-colors" -> { c with invert
= bool_of_string
v }
6197 | "brightness" -> { c with colorscale
= float_of_string
v }
6198 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6200 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6202 let (n, _, _) as nab
= multicolumns_of_string v in
6204 then { c with columns
= Csplit
(-n, [||]) }
6205 else { c with columns
= Cmulti
(nab
, [||]) }
6206 | "birds-eye-columns" ->
6207 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6208 | "selection-command" -> { c with selcmd
= unent v }
6209 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6210 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6211 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6212 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6213 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6216 prerr_endline
("Error processing attribute (`" ^
6217 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6220 let rec fold c = function
6223 let c = apply c k v in
6226 fold { c with keyhashes
= copykeyhashes c } attrs
;
6229 let fromstring f pos
n v d =
6232 dolog "Error processing attribute (%S=%S) at %d\n%s"
6233 n v pos
(Printexc.to_string exn
)
6238 let bookmark_of attrs
=
6239 let rec fold title page
rely visy
= function
6240 | ("title", v) :: rest
-> fold v page
rely visy rest
6241 | ("page", v) :: rest
-> fold title v rely visy rest
6242 | ("rely", v) :: rest
-> fold title page
v visy rest
6243 | ("visy", v) :: rest
-> fold title page
rely v rest
6244 | _ :: rest
-> fold title page
rely visy rest
6245 | [] -> title, page
, rely, visy
6247 fold "invalid" "0" "0" "0" attrs
6251 let rec fold path page
rely pan visy
= function
6252 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6253 | ("page", v) :: rest
-> fold path v rely pan visy rest
6254 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6255 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6256 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6257 | _ :: rest
-> fold path page
rely pan visy rest
6258 | [] -> path, page
, rely, pan
, visy
6260 fold "" "0" "0" "0" "0" attrs
6264 let rec fold rs ls
= function
6265 | ("out", v) :: rest
-> fold v ls rest
6266 | ("in", v) :: rest
-> fold rs
v rest
6267 | _ :: rest
-> fold ls rs rest
6273 let setconf dst
src =
6274 dst
.scrollbw
<- src.scrollbw
;
6275 dst
.scrollh
<- src.scrollh
;
6276 dst
.icase
<- src.icase
;
6277 dst
.preload <- src.preload;
6278 dst
.pagebias
<- src.pagebias
;
6279 dst
.verbose
<- src.verbose
;
6280 dst
.scrollstep
<- src.scrollstep
;
6281 dst
.maxhfit
<- src.maxhfit
;
6282 dst
.crophack
<- src.crophack
;
6283 dst
.autoscrollstep
<- src.autoscrollstep
;
6284 dst
.maxwait
<- src.maxwait
;
6285 dst
.hlinks
<- src.hlinks
;
6286 dst
.underinfo
<- src.underinfo
;
6287 dst
.interpagespace
<- src.interpagespace
;
6288 dst
.zoom <- src.zoom;
6289 dst
.presentation
<- src.presentation
;
6290 dst
.angle
<- src.angle
;
6291 dst
.winw <- src.winw;
6292 dst
.winh
<- src.winh
;
6293 dst
.savebmarks
<- src.savebmarks
;
6294 dst
.memlimit
<- src.memlimit
;
6295 dst
.proportional
<- src.proportional
;
6296 dst
.texcount
<- src.texcount
;
6297 dst
.sliceheight
<- src.sliceheight
;
6298 dst
.thumbw
<- src.thumbw
;
6299 dst
.jumpback
<- src.jumpback
;
6300 dst
.bgcolor
<- src.bgcolor
;
6301 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6302 dst
.tilew
<- src.tilew
;
6303 dst
.tileh
<- src.tileh
;
6304 dst
.mustoresize
<- src.mustoresize
;
6305 dst
.checkers
<- src.checkers
;
6306 dst
.aalevel
<- src.aalevel
;
6307 dst
.trimmargins
<- src.trimmargins
;
6308 dst
.trimfuzz
<- src.trimfuzz
;
6309 dst
.urilauncher
<- src.urilauncher
;
6310 dst
.colorspace
<- src.colorspace
;
6311 dst
.invert
<- src.invert
;
6312 dst
.colorscale
<- src.colorscale
;
6313 dst
.redirectstderr <- src.redirectstderr;
6314 dst
.ghyllscroll
<- src.ghyllscroll
;
6315 dst
.columns
<- src.columns
;
6316 dst
.beyecolumns
<- src.beyecolumns
;
6317 dst
.selcmd
<- src.selcmd
;
6318 dst
.updatecurs
<- src.updatecurs
;
6319 dst
.pathlauncher
<- src.pathlauncher
;
6320 dst
.keyhashes
<- copykeyhashes src;
6321 dst
.hfsize
<- src.hfsize
;
6322 dst
.hscrollstep
<- src.hscrollstep
;
6323 dst
.pgscale <- src.pgscale;
6324 dst
.usepbo
<- src.usepbo
;
6325 dst
.wheelbypage
<- src.wheelbypage
;
6329 let h = Hashtbl.create
10 in
6330 let dc = { defconf with angle
= defconf.angle
} in
6331 let rec toplevel v t spos
_ =
6333 | Vdata
| Vcdata
| Vend
-> v
6334 | Vopen
("llppconfig", _, closed
) ->
6337 else { v with f = llppconfig
}
6339 error
"unexpected subelement at top level" s spos
6340 | Vclose
_ -> error
"unexpected close at top level" s spos
6342 and llppconfig
v t spos
_ =
6344 | Vdata
| Vcdata
-> v
6345 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6346 | Vopen
("defaults", attrs
, closed
) ->
6347 let c = config_of dc attrs
in
6351 else { v with f = defaults
}
6353 | Vopen
("ui-font", attrs
, closed
) ->
6354 let rec getsize size
= function
6356 | ("size", v) :: rest
->
6358 fromstring int_of_string spos
"size" v fstate.fontsize
in
6360 | l -> getsize size l
6362 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6365 else { v with f = uifont
(Buffer.create
10) }
6367 | Vopen
("doc", attrs
, closed
) ->
6368 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6369 let path = unent pathent
6370 and pageno = fromstring int_of_string spos
"page" spage
0
6371 and rely = fromstring float_of_string spos
"rely" srely
0.0
6372 and pan
= fromstring int_of_string spos
"pan" span
0
6373 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6374 let c = config_of dc attrs
in
6375 let anchor = (pageno, rely, visy
) in
6377 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6378 else { v with f = doc
path pan
anchor c [] }
6381 error
"unexpected subelement in llppconfig" s spos
6383 | Vclose
"llppconfig" -> { v with f = toplevel }
6384 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6386 and defaults
v t spos
_ =
6388 | Vdata
| Vcdata
-> v
6389 | Vend
-> error
"unexpected end of input in defaults" s spos
6390 | Vopen
("keymap", attrs
, closed
) ->
6392 try List.assoc
"mode" attrs
6393 with Not_found
-> "global" in
6398 let h = findkeyhash dc modename in
6399 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6402 { v with f = pkeymap
ret KeyMap.empty }
6404 | Vopen
(_, _, _) ->
6405 error
"unexpected subelement in defaults" s spos
6407 | Vclose
"defaults" ->
6408 { v with f = llppconfig
}
6410 | Vclose
_ -> error
"unexpected close in defaults" s spos
6412 and uifont
b v t spos
epos =
6415 Buffer.add_substring
b s spos
(epos - spos
);
6417 | Vopen
(_, _, _) ->
6418 error
"unexpected subelement in ui-font" s spos
6419 | Vclose
"ui-font" ->
6420 if String.length
!fontpath = 0
6421 then fontpath := Buffer.contents
b;
6422 { v with f = llppconfig
}
6423 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6424 | Vend
-> error
"unexpected end of input in ui-font" s spos
6426 and doc
path pan
anchor c bookmarks
v t spos
_ =
6428 | Vdata
| Vcdata
-> v
6429 | Vend
-> error
"unexpected end of input in doc" s spos
6430 | Vopen
("bookmarks", _, closed
) ->
6433 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6435 | Vopen
("keymap", attrs
, closed
) ->
6437 try List.assoc
"mode" attrs
6438 with Not_found
-> "global"
6444 let h = findkeyhash c modename in
6445 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6446 doc
path pan
anchor c bookmarks
6448 { v with f = pkeymap
ret KeyMap.empty }
6450 | Vopen
(_, _, _) ->
6451 error
"unexpected subelement in doc" s spos
6454 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6455 { v with f = llppconfig
}
6457 | Vclose
_ -> error
"unexpected close in doc" s spos
6459 and pkeymap
ret keymap
v t spos
_ =
6461 | Vdata
| Vcdata
-> v
6462 | Vend
-> error
"unexpected end of input in keymap" s spos
6463 | Vopen
("map", attrs
, closed
) ->
6464 let r, l = map_of attrs
in
6465 let kss = fromstring keys_of_string spos
"in" r [] in
6466 let lss = fromstring keys_of_string spos
"out" l [] in
6470 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6471 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6474 then { v with f = pkeymap
ret keymap }
6477 { v with f = skip
"map" f }
6480 error
"unexpected subelement in keymap" s spos
6482 | Vclose
"keymap" ->
6483 { v with f = ret keymap }
6485 | Vclose
_ -> error
"unexpected close in keymap" s spos
6487 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6489 | Vdata
| Vcdata
-> v
6490 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6491 | Vopen
("item", attrs
, closed
) ->
6492 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6493 let page = fromstring int_of_string spos
"page" spage
0
6494 and rely = fromstring float_of_string spos
"rely" srely
0.0
6495 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6497 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6500 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6503 { v with f = skip
"item" f }
6506 error
"unexpected subelement in bookmarks" s spos
6508 | Vclose
"bookmarks" ->
6509 { v with f = doc
path pan
anchor c bookmarks }
6511 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6513 and skip tag
f v t spos
_ =
6515 | Vdata
| Vcdata
-> v
6517 error
("unexpected end of input in skipped " ^ tag
) s spos
6518 | Vopen
(tag'
, _, closed
) ->
6522 let f'
() = { v with f = skip tag
f } in
6523 { v with f = skip tag'
f'
}
6527 else error
("unexpected close in skipped " ^ tag
) s spos
6530 parse
{ f = toplevel; accu = () } s;
6536 let len = in_channel_length ic
in
6537 let s = String.create
len in
6538 really_input ic
s 0 len;
6541 | Parse_error
(msg
, s, pos
) ->
6542 let subs = subs s pos
in
6543 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6544 failwith
("parse error: " ^
s)
6547 failwith
("config load error: " ^
Printexc.to_string exn
)
6553 let dir = Filename.concat
home ".config" in
6554 if Sys.is_directory
dir then dir else home
6557 Filename.concat
dir "llpp.conf"
6560 let confpath = ref defconfpath;;
6563 if Sys.file_exists
!confpath
6566 (try Some
(open_in_bin
!confpath)
6569 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6570 Printexc.to_string exn
);
6580 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6581 Printexc.to_string exn
);
6589 f (Hashtbl.create
0, defconf)
6594 let pc, pb
, px, pa
=
6596 Hashtbl.find h (Filename.basename
state.path)
6597 with Not_found
-> dc, [], 0, emptyanchor
6601 state.bookmarks <- pb
;
6603 state.scrollw
<- conf.scrollbw
;
6605 then state.anchor <- pa
;
6606 cbput state.hists
.nav pa
;
6612 let add_attrs bb always
dc c =
6615 then Printf.bprintf bb
"\n %s='%b'" s a
6618 then Printf.bprintf bb
"\n %s='%d'" s a
6621 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6624 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6627 then Printf.bprintf bb
"\n %s='%f'" s a
6631 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6635 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6639 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6643 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6649 | Some
(_N
, _A
, _B
) ->
6650 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6660 else string_of_float
f
6662 Printf.bprintf bb
"\n %s='%s'" s v
6667 | Cmulti
((n, a, b), _) when n > 1 ->
6668 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6669 | Csplit
(n, _) when n > 1 ->
6670 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6676 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6681 then dc.winw, dc.winh
6683 match state.fullscreen
with
6685 | None
-> c.winw, c.winh
6687 oi
"width" w dc.winw;
6688 oi
"height" h dc.winh
;
6689 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6690 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6691 ob "case-insensitive-search" c.icase
dc.icase
;
6692 ob "preload" c.preload dc.preload;
6693 oi
"page-bias" c.pagebias
dc.pagebias
;
6694 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6695 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6696 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6697 ob "crop-hack" c.crophack
dc.crophack
;
6698 oW
"throttle" c.maxwait
dc.maxwait
;
6699 ob "highlight-links" c.hlinks
dc.hlinks
;
6700 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6701 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6702 oz
"zoom" c.zoom dc.zoom;
6703 ob "presentation" c.presentation
dc.presentation
;
6704 oi
"rotation-angle" c.angle
dc.angle
;
6705 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6706 ob "proportional-display" c.proportional
dc.proportional
;
6707 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6708 oi
"tex-count" c.texcount
dc.texcount
;
6709 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6710 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6711 ob "persistent-location" c.jumpback
dc.jumpback
;
6712 oc
"background-color" c.bgcolor
dc.bgcolor
;
6713 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6714 oi
"tile-width" c.tilew
dc.tilew
;
6715 oi
"tile-height" c.tileh
dc.tileh
;
6716 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6717 ob "checkers" c.checkers
dc.checkers
;
6718 oi
"aalevel" c.aalevel
dc.aalevel
;
6719 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6720 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6721 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6722 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6723 oC
"color-space" c.colorspace
dc.colorspace
;
6724 ob "invert-colors" c.invert
dc.invert
;
6725 oF
"brightness" c.colorscale
dc.colorscale
;
6726 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6727 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6728 oco
"columns" c.columns
dc.columns
;
6729 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6730 os
"selection-command" c.selcmd
dc.selcmd
;
6731 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6732 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6733 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6734 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6735 ob "use-pbo" c.usepbo
dc.usepbo
;
6736 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6739 let keymapsbuf always
dc c =
6740 let bb = Buffer.create
16 in
6741 let rec loop = function
6743 | (modename, h) :: rest
->
6744 let dh = findkeyhash dc modename in
6745 if always
|| h <> dh
6747 if Hashtbl.length
h > 0
6749 if Buffer.length
bb > 0
6750 then Buffer.add_char
bb '
\n'
;
6751 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6752 Hashtbl.iter
(fun i
o ->
6753 let isdifferent = always
||
6755 let dO = Hashtbl.find dh i
in
6757 with Not_found
-> true
6762 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6763 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6764 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6765 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6766 Buffer.add_string
bb (Wsi.keyname
k);
6769 let rec loop = function
6771 | km
:: [] -> addkm km
6772 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6776 Buffer.add_string
bb "<map in='";
6780 Buffer.add_string
bb "' out='";
6782 Buffer.add_string
bb "'/>\n"
6785 Buffer.add_string
bb "' out='";
6787 Buffer.add_string
bb "'/>\n"
6789 | KMmulti
(ins, kms
) ->
6790 Buffer.add_char
bb ' '
;
6792 Buffer.add_string
bb "' out='";
6794 Buffer.add_string
bb "'/>\n"
6796 Buffer.add_string
bb "</keymap>";
6806 let uifontsize = fstate.fontsize
in
6807 let bb = Buffer.create
32768 in
6809 let dc = if conf.bedefault
then conf else dc in
6810 Buffer.add_string
bb "<llppconfig>\n";
6812 if String.length
!fontpath > 0
6814 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6820 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6823 Buffer.add_string
bb "<defaults ";
6824 add_attrs bb true dc dc;
6825 let kb = keymapsbuf true dc dc in
6826 if Buffer.length
kb > 0
6828 Buffer.add_string
bb ">\n";
6829 Buffer.add_buffer
bb kb;
6830 Buffer.add_string
bb "\n</defaults>\n";
6832 else Buffer.add_string
bb "/>\n";
6834 let adddoc path pan
anchor c bookmarks =
6835 if bookmarks == [] && c = dc && anchor = emptyanchor
6838 Printf.bprintf
bb "<doc path='%s'"
6839 (enent
path 0 (String.length
path));
6841 if anchor <> emptyanchor
6843 let n, rely, visy
= anchor in
6844 Printf.bprintf
bb " page='%d'" n;
6847 Printf.bprintf
bb " rely='%f'" rely
6849 if abs_float visy
> 1e-6
6851 Printf.bprintf
bb " visy='%f'" visy
6856 then Printf.bprintf
bb " pan='%d'" pan
;
6858 add_attrs bb false dc c;
6859 let kb = keymapsbuf false dc c in
6861 begin match bookmarks with
6863 if Buffer.length
kb > 0
6865 Buffer.add_string
bb ">\n";
6866 Buffer.add_buffer
bb kb;
6867 Buffer.add_string
bb "\n</doc>\n";
6869 else Buffer.add_string
bb "/>\n"
6871 Buffer.add_string
bb ">\n<bookmarks>\n";
6872 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6874 "<item title='%s' page='%d'"
6875 (enent
title 0 (String.length
title))
6880 Printf.bprintf
bb " rely='%f'" rely
6882 if abs_float visy
> 1e-6
6884 Printf.bprintf
bb " visy='%f'" visy
6886 Buffer.add_string
bb "/>\n";
6888 Buffer.add_string
bb "</bookmarks>";
6889 if Buffer.length
kb > 0
6891 Buffer.add_string
bb "\n";
6892 Buffer.add_buffer
bb kb;
6894 Buffer.add_string
bb "\n</doc>\n";
6900 match state.mode with
6901 | Birdseye
(c, pan, _, _, _) ->
6903 match conf.columns
with
6904 | Cmulti
((c, _, _), _) -> Some
c
6908 match c.columns
with
6909 | Cmulti
(c, _) -> Cmulti
(c, [||])
6910 | Csingle
_ -> Csingle
[||]
6911 | Csplit
_ -> failwith
"quit from bird's eye while split"
6913 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6914 | _ -> state.x, conf
6916 let basename = Filename.basename state.path in
6917 adddoc basename pan (getanchor ())
6919 let autoscrollstep =
6920 match state.autoscroll
with
6922 | None
-> conf.autoscrollstep
6924 match state.mode with
6925 | Birdseye
(bc
, _, _, _, _) ->
6928 presentation
= bc
.presentation
;
6929 interpagespace
= bc
.interpagespace
;
6930 maxwait
= bc
.maxwait
;
6931 autoscrollstep = autoscrollstep }
6932 | _ -> { conf with autoscrollstep = autoscrollstep }
6934 (if conf.savebmarks
then state.bookmarks else []);
6936 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6938 then adddoc path x anchor c bookmarks
6940 Buffer.add_string
bb "</llppconfig>\n";
6943 if load1 f && Buffer.length
bb > 0
6946 let tmp = !confpath ^
".tmp" in
6947 let oc = open_out_bin
tmp in
6948 Buffer.output_buffer
oc bb;
6950 Unix.rename
tmp !confpath;
6953 ("error while saving configuration: " ^
Printexc.to_string exn
)
6958 let trimcachepath = ref "" in
6961 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6962 "<password> Set password");
6964 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6965 "<path> Set path to the user interface font");
6967 ("-c", Arg.String
(fun s -> Config.confpath := s),
6968 "<path> Set path to the configuration file");
6970 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6971 "<path> Set path to the trim cache file");
6973 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
6974 "<named destination> Set named destination");
6976 ("-v", Arg.Unit
(fun () ->
6978 "%s\nconfiguration path: %s\n"
6982 exit
0), " Print version and exit");
6985 (fun s -> state.path <- s)
6986 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6988 if String.length
state.path = 0
6989 then (prerr_endline
"file name missing"; exit
1);
6991 if not
(Config.load ())
6992 then prerr_endline
"failed to load configuration";
6994 let globalkeyhash = findkeyhash conf "global" in
6995 let wsfd, winw, winh
= Wsi.init
(object
6997 state.wthack <- false;
6998 if nogeomcmds state.geomcmds
|| platform == Posx
7001 GlClear.color (scalecolor2 conf.bgcolor
);
7002 GlClear.clear
[`
color];
7004 method display = display ()
7005 method reshape w h = reshape w h
7006 method mouse b d x y m = mouse b d x y m
7007 method motion x y = state.mpos
<- (x, y); motion x y
7008 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7010 let mascm = m land (
7011 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7013 match state.keystate
with
7015 let km = k, mascm in
7018 let modehash = state.uioh#
modehash in
7019 try Hashtbl.find modehash km
7021 try Hashtbl.find globalkeyhash km
7022 with Not_found
-> KMinsrt
(k, m)
7024 | KMinsrt
(k, m) -> keyboard k m
7025 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7026 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7028 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7029 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7030 state.keystate
<- KSnone
7031 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7032 state.keystate
<- KSinto
(keys
, insrt
)
7034 state.keystate
<- KSnone
7036 method enter
x y = state.mpos
<- (x, y); pmotion x y
7037 method leave = state.mpos
<- (-1, -1)
7038 method quit
= raise Quit
7039 end) conf.winw conf.winh
(platform = Posx
) in
7044 List.exists
GlMisc.check_extension
7045 [ "GL_ARB_texture_rectangle"
7046 ; "GL_EXT_texture_recangle"
7047 ; "GL_NV_texture_rectangle" ]
7049 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7052 match Ne.pipe () with
7054 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7058 match Ne.pipe () with
7060 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7070 setcheckers conf.checkers
;
7074 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7075 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7076 !Config.fontpath, !trimcachepath,
7077 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7081 state.text <- "Opening " ^
(mbtoutf8
state.path);
7083 opendoc state.path state.password
;
7086 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7088 let rec loop deadline
=
7090 match state.errfd
with
7091 | None
-> [state.sr
; state.wsfd]
7092 | Some fd
-> [state.sr
; state.wsfd; fd
]
7096 state.redisplay
<- false;
7103 if deadline
= infinity
7105 else max
0.0 (deadline
-. now)
7110 try tempfailureretry (Unix.select
r [] []) timeout
7111 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7117 if state.ghyll
== noghyll
7119 match state.autoscroll
with
7120 | Some step
when step
!= 0 ->
7121 let y = state.y + step
in
7125 else if y >= state.maxy then 0 else y
7128 if state.mode = View
7129 then state.text <- "";
7132 else deadline
+. 0.01
7137 let rec checkfds = function
7139 | fd
:: rest
when fd
= state.sr
->
7140 let cmd = readcmd state.sr
in
7144 | fd
:: rest
when fd
= state.wsfd ->
7149 let s = String.create
80 in
7150 let n = tempfailureretry (Unix.read fd
s 0) 80 in
7151 if conf.redirectstderr
7153 Buffer.add_substring
state.errmsgs
s 0 n;
7154 state.newerrmsgs
<- true;
7155 state.redisplay
<- true;
7158 prerr_string
(String.sub
s 0 n);
7166 if deadline
= infinity
7170 match state.autoscroll
with
7171 | Some step
when step
!= 0 -> deadline1
7172 | _ -> if state.ghyll
== noghyll then infinity
else deadline1