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 wtmode = ref false;;
573 let findkeyhash c name
=
574 try List.assoc name c
.keyhashes
575 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
578 let conf = { defconf with angle
= defconf.angle
};;
580 let pgscale h
= truncate
(float h
*. conf.pgscale);;
583 { mutable fontsize
: int
584 ; mutable wwidth
: float
585 ; mutable maxrows
: int
597 fstate.fontsize
<- n
;
598 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
599 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
603 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
604 let len = String.length s
in
605 if colonpos >= 0 && colonpos + 3 < len
607 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
610 try String.rindex_from s
colonpos ' '
614 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
617 | "http" | "ftp" | "mailto" ->
619 try String.index_from s
colonpos ' '
620 with Not_found
-> len
622 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
630 if String.length
conf.urilauncher
= 0
631 then print_endline uri
633 let url = geturl uri
in
634 if String.length
url = 0
635 then print_endline uri
637 let re = Str.regexp
"%s" in
638 let command = Str.global_replace
re url conf.urilauncher
in
642 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
648 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
649 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
653 let strings = version () :: "" :: Help.keys
in
656 let url = geturl s
in
657 if String.length
url > 0
658 then (s
, 0, Action
(fun u
-> gotouri url; u
))
659 else (s
, 0, Noaction
)
664 let firstgeomcmds = "", [];;
671 ; stderr
= Unix.stderr
672 ; errmsgs
= Buffer.create
0
679 ; anchor
= emptyanchor
683 ; tilelru
= Queue.create
()
684 ; pagemap
= Hashtbl.create
10
685 ; tilemap
= Hashtbl.create
10
701 ; geomcmds
= firstgeomcmds
703 { nav
= cbnew 10 emptyanchor
731 Printf.kprintf prerr_endline fmt
733 Printf.kprintf ignore fmt
737 if String.length
conf.pathlauncher
= 0
738 then print_endline
state.path
740 let re = Str.regexp
"%s" in
741 let command = Str.global_replace
re state.path
conf.pathlauncher
in
745 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
751 type 'a t
= | Res
of 'a
| Exn
of exn
;;
754 try Res
(Unix.pipe ())
759 try tempfailureretry Unix.close fd
760 with exn
-> f
(Printexc.to_string exn
)
764 try Res
(tempfailureretry Unix.dup fd
)
769 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
774 let redirectstderr () =
775 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
776 if conf.redirectstderr
778 match Ne.pipe () with
780 dolog "failed to create stderr redirection pipes: %s"
781 (Printexc.to_string exn
)
784 begin match Ne.dup Unix.stderr
with
786 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
787 Ne.clo r
(clofail "pipe/r");
788 Ne.clo w
(clofail "pipe/w");
790 | Ne.Res dupstderr
->
791 begin match Ne.dup2 w
Unix.stderr
with
793 dolog "failed to dup2 to stderr: %s"
794 (Printexc.to_string exn
);
795 Ne.clo dupstderr
(clofail "stderr duplicate");
796 Ne.clo r
(clofail "redir pipe/r");
797 Ne.clo w
(clofail "redir pipe/w");
800 state.stderr
<- dupstderr
;
801 state.errfd
<- Some r
;
805 state.newerrmsgs
<- false;
806 begin match state.errfd
with
808 begin match Ne.dup2 state.stderr
Unix.stderr
with
810 dolog "failed to dup2 original stderr: %s"
811 (Printexc.to_string exn
)
813 Ne.clo fd
(clofail "dup of stderr");
818 prerr_string
(Buffer.contents
state.errmsgs
);
820 Buffer.clear
state.errmsgs
;
826 let postRedisplay who
=
828 then prerr_endline
("redisplay for " ^ who
);
829 state.redisplay
<- true;
833 let getopaque pageno
=
834 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
835 with Not_found
-> None
838 let putopaque pageno opaque
=
839 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
842 let pagetranslatepoint l x y
=
843 let dy = y
- l
.pagedispy
in
844 let y = dy + l
.pagey
in
845 let dx = x
- l
.pagedispx
in
846 let x = dx + l
.pagex
in
853 begin match getopaque l
.pageno
with
855 let x0 = l
.pagedispx
in
856 let x1 = x0 + l
.pagevw
in
857 let y0 = l
.pagedispy
in
858 let y1 = y0 + l
.pagevh
in
859 if y >= y0 && y <= y1 && x >= x0 && x <= x1
861 let px, py
= pagetranslatepoint l
x y in
862 match whatsunder opaque
px py
with
875 state.text
<- Printf.sprintf
"%c%s" c s
;
876 G.postRedisplay "showtext";
879 let undertext = function
882 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
883 | Utext s
-> "font: " ^ s
884 | Uunexpected s
-> "unexpected: " ^ s
885 | Ulaunch s
-> "launch: " ^ s
886 | Unamed s
-> "named: " ^ s
887 | Uremote
(filename
, pageno
) ->
888 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
891 let updateunder x y =
892 match getunder x y with
893 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
895 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
896 Wsi.setcursor
Wsi.CURSOR_INFO
897 | Ulinkgoto
(pageno
, _
) ->
899 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
900 Wsi.setcursor
Wsi.CURSOR_INFO
902 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
903 Wsi.setcursor
Wsi.CURSOR_TEXT
905 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
906 Wsi.setcursor
Wsi.CURSOR_INHERIT
908 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
909 Wsi.setcursor
Wsi.CURSOR_INHERIT
911 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
912 Wsi.setcursor
Wsi.CURSOR_INHERIT
913 | Uremote
(filename
, pageno
) ->
914 if conf.underinfo
then showtext 'r'
915 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
916 Wsi.setcursor
Wsi.CURSOR_INFO
919 let showlinktype under
=
925 let s = undertext under
in
930 let b = Buffer.create
(String.length
s + 1) in
931 Buffer.add_string
b s;
936 let colorspace_of_string s =
937 match String.lowercase
s with
941 | _
-> failwith
"invalid colorspace"
944 let int_of_colorspace = function
950 let colorspace_of_int = function
954 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
957 let colorspace_to_string = function
963 let intentry_with_suffix text key
=
965 if key
>= 32 && key
< 127
969 match Char.lowercase
c with
971 let text = addchar text c in
975 let text = addchar text c in
979 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
983 let multicolumns_to_string (n
, a
, b) =
985 then Printf.sprintf
"%d" n
986 else Printf.sprintf
"%d,%d,%d" n a
b;
989 let multicolumns_of_string s =
991 (int_of_string
s, 0, 0)
993 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
995 then failwith
"subtly broken"; (n
, a
, b)
1001 let n = tempfailureretry (Unix.read fd
s 0) 4 in
1002 if n != 4 then failwith
"incomplete read(len)";
1004 lor (Char.code
s.[0] lsl 24)
1005 lor (Char.code
s.[1] lsl 16)
1006 lor (Char.code
s.[2] lsl 8)
1007 lor (Char.code
s.[3] lsl 0)
1009 let s = String.create
len in
1010 let n = tempfailureretry (Unix.read fd
s 0) len in
1011 if n != len then failwith
"incomplete read(data)";
1015 let btod b = if b then 1 else 0;;
1018 let b = Buffer.create
16 in
1019 Buffer.add_string
b "llll";
1022 let s = Buffer.contents
b in
1023 let n = String.length
s in
1025 (* dolog "wcmd %S" (String.sub s 4 len); *)
1026 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1027 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1028 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1029 s.[3] <- Char.chr
(len land 0xff);
1030 let n'
= tempfailureretry (Unix.write
state.sw
s 0) n in
1031 if n'
!= n then failwith
"write failed";
1036 let d = conf.winh
- h
in
1037 max
conf.interpagespace
((d + 1) / 2)
1040 let rowyh (c, coverA
, coverB
) b n =
1041 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1043 let _, _, vy
, (_, _, h
, _) = b.(n) in
1046 let n'
= n - coverA
in
1049 let e = min
state.pagecount
(s + c) in
1050 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1051 let _, _, y, (_, _, h
, _) = b.(m
) in
1052 let miny = min
miny y in
1053 let maxh = max
maxh h
in
1054 find (m
+1) miny maxh
1059 match conf.columns
with
1060 | Cmulti
((_, _, _) as cl
, b) ->
1061 if Array.length
b > 0
1063 let y, h
= rowyh cl
b (Array.length
b - 1) in
1064 y + h
+ (if conf.presentation
then calcips h
else 0)
1067 if Array.length
b > 0
1069 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1070 y + h
+ (if conf.presentation
then calcips h
else 0)
1073 if Array.length
b > 0
1075 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1080 let getpageyh pageno
=
1081 let pageno = bound pageno 0 (state.pagecount
-1) in
1082 match conf.columns
with
1084 if Array.length
b = 0
1087 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1089 if conf.presentation
1095 if Array.length
b = 0
1098 let y, h
= rowyh cl
b pageno in
1100 if conf.presentation
1106 if Array.length
b = 0
1110 let (_, _, y, (_, _, h
, _)) = b.(n) in
1114 let getpagedim pageno =
1117 | (n, _, _, _) as pdim
:: rest
->
1119 then (if n = pageno then pdim
else ppdim
)
1124 f (-1, -1, -1, -1) state.pdims
1127 let getpagey pageno = fst
(getpageyh pageno);;
1129 let nogeomcmds cmds
=
1131 | s, [] -> String.length
s = 0
1136 let ((c, coverA
, coverB
) as cl
), b =
1137 match conf.columns
with
1138 | Csingle
b -> (1, 0, 0), b
1139 | Cmulti
(c, b) -> c, b
1140 | Csplit
(_, b) -> (1, 0, 0), b
1142 let rec bsearch nmin nmax
=
1144 then bound nmin
0 (state.pagecount
-1)
1146 let n = (nmax
+ nmin
) / 2 in
1147 let vy, h
= rowyh cl
b n in
1149 if conf.presentation
1151 let ips = calcips h
in
1152 let y0 = vy - ips in
1153 let y1 = vy + h
+ ips in
1157 then 0, vy + h
+ conf.interpagespace
1159 let y0 = vy - conf.interpagespace
in
1160 y0, y0 + h
+ conf.interpagespace
1163 if y >= y0 && y < y1
1170 if n < state.pagecount
- coverB
1171 then ((n-coverA
)/c)*c + coverA
1178 then bsearch (n+1) nmax
1179 else bsearch nmin
(n-1)
1182 let r = bsearch 0 (state.pagecount
-1) in
1186 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1187 let sh = sh - state.hscrollh
in
1188 let rec fold accu
n =
1189 if n = Array.length
b
1192 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1195 || n = state.pagecount
- coverB
1196 || (n - coverA
) mod columns
= columns
- 1)
1202 let pagey = max
0 (y - vy) in
1203 let pagedispy = if pagey > 0 then 0 else vy - y in
1204 let pagedispx, pagex
=
1206 if n = coverA
- 1 || n = state.pagecount
- coverB
1207 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1208 else dx + xoff
+ state.x
1215 let vw = conf.winw
- state.scrollw
- pagedispx in
1216 let pw = w
- pagex
in
1219 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1220 if pagevw > 0 && pagevh > 0
1224 ; pagedimno
= pdimno
1231 ; pagedispx = pagedispx
1232 ; pagedispy = pagedispy
1244 List.rev
(fold [] (page_of_y y));
1247 let layoutS (columns
, b) y sh =
1248 let sh = sh - state.hscrollh
in
1249 let rec fold accu n =
1250 if n = Array.length
b
1253 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1260 let x = xoff
+ state.x in
1261 let pagey = max
0 (y - vy) in
1262 let pagedispy = if pagey > 0 then 0 else vy - y in
1263 let pagedispx, pagex
=
1277 let pagecolw = pagew
/columns
in
1279 if pagecolw < conf.winw
1280 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1284 let vw = conf.winw
- pagedispx - state.scrollw
in
1285 let pw = pagew
- pagex
in
1288 let pagevw = min
pagevw pagecolw in
1289 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1290 if pagevw > 0 && pagevh > 0
1293 { pageno = n/columns
1294 ; pagedimno
= pdimno
1301 ; pagedispx = pagedispx
1302 ; pagedispy = pagedispy
1303 ; pagecol
= n mod columns
1314 List.rev
(fold [] 0)
1318 if nogeomcmds state.geomcmds
1320 match conf.columns
with
1321 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1322 | Cmulti
c -> layoutN c y sh
1323 | Csplit
s -> layoutS s y sh
1328 let y = state.y + incr
in
1330 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1335 let tilex = l
.pagex
mod conf.tilew
in
1336 let tiley = l
.pagey mod conf.tileh
in
1338 let col = l
.pagex
/ conf.tilew
in
1339 let row = l
.pagey / conf.tileh
in
1341 let rec rowloop row y0 dispy h
=
1345 let dh = conf.tileh
- y0 in
1346 let dh = min h
dh in
1347 let rec colloop col x0 dispx w
=
1351 let dw = conf.tilew
- x0 in
1352 let dw = min w
dw in
1354 f col row dispx dispy
x0 y0 dw dh;
1355 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1358 colloop col tilex l
.pagedispx l
.pagevw;
1359 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1362 if l
.pagevw > 0 && l
.pagevh > 0
1363 then rowloop row tiley l
.pagedispy l
.pagevh;
1366 let gettileopaque l
col row =
1368 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1370 try Some
(Hashtbl.find state.tilemap
key)
1371 with Not_found
-> None
1374 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1375 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1376 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1379 let drawtiles l color
=
1381 let f col row x y tilex tiley w h
=
1382 match gettileopaque l
col row with
1383 | Some
(opaque
, _, t
) ->
1384 let params = x, y, w
, h
, tilex, tiley in
1388 GlFunc.blend_func `zero `one_minus_src_color
;
1390 drawtile
params opaque
;
1392 then Gl.disable `blend
;
1395 let s = Printf.sprintf
1399 let w = measurestr
fstate.fontsize
s in
1400 GlMisc.push_attrib
[`current
];
1401 GlDraw.color
(0.0, 0.0, 0.0);
1403 (float (x-2), float (y-2))
1404 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1405 GlDraw.color
(1.0, 1.0, 1.0);
1406 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1407 GlMisc.pop_attrib
();
1412 let lw = conf.winw
- state.scrollw
- x in
1415 let lh = conf.winh
- y in
1418 begin match state.texid
with
1420 Gl.enable `texture_2d
;
1421 GlTex.bind_texture `texture_2d id
;
1424 and x1 = float (x+w)
1425 and y1 = float (y+h
) in
1427 let tw = float w /. 16.0
1428 and th
= float h
/. 16.0 in
1429 let tx0 = float tilex /. 16.0
1430 and ty0
= float tiley /. 16.0 in
1432 and ty1
= ty0
+. th
in
1433 GlDraw.begins `quads
;
1434 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1435 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1436 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1437 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1440 Gl.disable `texture_2d
;
1442 GlDraw.color
(1.0, 1.0, 1.0);
1445 (float (x+w), float (y+h
));
1447 if w > 128 && h
> fstate.fontsize
+ 10
1449 GlDraw.color
(0.0, 0.0, 0.0);
1452 then (col*conf.tilew
, row*conf.tileh
)
1455 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1462 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1464 let tilevisible1 l
x y =
1466 and ax1
= l
.pagex
+ l
.pagevw
1468 and ay1
= l
.pagey + l
.pagevh in
1472 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1473 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1475 let rx0 = max
ax0 bx0
1476 and ry0
= max ay0 by0
1477 and rx1
= min ax1
bx1
1478 and ry1
= min ay1 by1
in
1480 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1481 nonemptyintersection
1484 let tilevisible layout n x y =
1485 let rec findpageinlayout m
= function
1486 | l
:: rest
when l
.pageno = n ->
1487 tilevisible1 l
x y || (
1488 match conf.columns
with
1489 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1492 | _ :: rest
-> findpageinlayout 0 rest
1495 findpageinlayout 0 layout;
1498 let tileready l
x y =
1499 tilevisible1 l
x y &&
1500 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1503 let tilepage n p
layout =
1504 let rec loop = function
1508 let f col row _ _ _ _ _ _ =
1509 if state.currently
= Idle
1511 match gettileopaque l
col row with
1514 let x = col*conf.tilew
1515 and y = row*conf.tileh
in
1517 let w = l
.pagew
- x in
1521 let h = l
.pageh
- y in
1526 then getpbo
w h conf.colorspace
1529 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1532 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1533 conf.tilew
, conf.tileh
1542 if nogeomcmds state.geomcmds
1546 let preloadlayout y =
1547 let y = if y < conf.winh
then 0 else y - conf.winh
in
1548 let h = conf.winh
*3 in
1553 let rec loop pages
=
1554 if state.currently
!= Idle
1559 begin match getopaque l
.pageno with
1561 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1562 state.currently
<- Loading
(l
, state.gen
);
1564 tilepage l
.pageno opaque pages
;
1569 if nogeomcmds state.geomcmds
1575 if conf.preload && state.currently
= Idle
1576 then load (preloadlayout state.y);
1579 let layoutready layout =
1580 let rec fold all ls
=
1581 all
&& match ls
with
1583 let seen = ref false in
1584 let allvisible = ref true in
1585 let foo col row _ _ _ _ _ _ =
1587 allvisible := !allvisible &&
1588 begin match gettileopaque l
col row with
1594 fold (!seen && !allvisible) rest
1597 let alltilesvisible = fold true layout in
1602 state.wthack
<- false;
1603 let y = bound y 0 state.maxy
in
1604 let y, layout, proceed
=
1605 match conf.maxwait
with
1606 | Some time
when state.ghyll
== noghyll ->
1607 begin match state.throttle
with
1609 let layout = layout y conf.winh
in
1610 let ready = layoutready layout in
1614 state.throttle
<- Some
(layout, y, now ());
1616 else G.postRedisplay "gotoy showall (None)";
1618 | Some
(_, _, started
) ->
1619 let dt = now () -. started
in
1622 state.throttle
<- None
;
1623 let layout = layout y conf.winh
in
1625 G.postRedisplay "maxwait";
1632 let layout = layout y conf.winh
in
1633 G.postRedisplay "gotoy ready";
1639 state.layout <- layout;
1640 begin match state.mode
with
1641 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1642 let rec loop = function
1644 state.mode
<- LinkNav
(Ltgendir
0)
1645 | l
:: _ when l
.pageno = pageno ->
1646 begin match getopaque pageno with
1648 state.mode
<- LinkNav
(Ltgendir
0)
1650 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1651 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1652 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1653 then state.mode
<- LinkNav
(Ltgendir
0)
1655 | _ :: rest
-> loop rest
1660 begin match state.mode
with
1661 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1662 if not
(pagevisible layout pageno)
1664 match state.layout with
1667 state.mode
<- Birdseye
(
1668 conf, leftx
, l
.pageno, hooverpageno
, anchor
1671 | LinkNav
(Ltgendir dir
as lt
) ->
1673 let rec loop = function
1676 match getopaque l
.pageno with
1682 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1684 if dir
> 0 then LDfirst
else LDlast
1690 | Lnotfound
-> loop rest
1692 showlinktype (getlink opaque
n);
1693 Ltexact
(l
.pageno, n)
1697 state.mode
<- LinkNav
linknav
1702 state.ghyll
<- noghyll;
1705 let mx, my
= state.mpos
in
1710 let conttiling pageno opaque
=
1711 tilepage pageno opaque
1712 (if conf.preload then preloadlayout state.y else state.layout)
1715 let gotoy_and_clear_text y =
1716 if not
conf.verbose
then state.text <- "";
1722 let coloff = l
.pagecol
* l
.pageh
in
1723 float (l
.pagey + coloff) /. float l
.pageh
1730 if conf.presentation
1731 then float l
.pagedispy /. float (calcips l
.pageh
)
1732 else float l
.pagedispy /. float conf.interpagespace
1734 (l
.pageno, top, dtop)
1738 match state.layout with
1739 | l
:: _ -> getanchor1 l
1741 let n = page_of_y state.y in
1742 let y, h = getpageyh n in
1743 let dy = y - state.y in
1745 if conf.presentation
1747 let ips = calcips h in
1748 float (dy + ips) /. float ips
1750 float dy /. float conf.interpagespace
1755 let getanchory (n, top, dtop) =
1756 let y, h = getpageyh n in
1757 if conf.presentation
1759 let ips = calcips h in
1760 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1762 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1765 let gotoanchor anchor
=
1766 gotoy (getanchory anchor
);
1770 cbput state.hists
.nav
(getanchor ());
1774 let anchor = cbgetc state.hists
.nav dir
in
1779 let scroll f n a
b =
1780 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1782 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1784 then s (float f /. float a
)
1787 then 1.0 -. s ((float (f-b) /. float (n-b)))
1794 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1795 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1797 let ins = float a
*. iv1
1798 and outs
= float (n-b) *. iv1 in
1800 ins +. outs
+. float ones
1802 let rec set (_N
, _A
, _B
) y sy
=
1803 let sum = summa
1.0 _N _A _B
in
1804 let dy = float (y - sy
) in
1808 then state.ghyll
<- noghyll
1811 let s = scroll n _N _A _B
in
1812 let y1 = y1 +. ((s *. dy) /. sum) in
1813 gotoy_and_clear_text (truncate
y1);
1814 state.ghyll
<- gf (n+1) y1;
1818 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1820 gf 0 (float state.y)
1823 match conf.ghyllscroll
with
1825 gotoy_and_clear_text y
1827 if state.ghyll
== noghyll
1828 then set nab
y state.y
1829 else state.ghyll
(Some
y)
1832 let gotopage n top =
1833 let y, h = getpageyh n in
1834 let y = y + (truncate
(top *. float h)) in
1838 let gotopage1 n top =
1839 let y = getpagey n in
1844 let invalidate s f =
1849 match state.geomcmds
with
1850 | ps
, [] when String.length ps
= 0 ->
1852 state.geomcmds
<- s, [];
1855 state.geomcmds
<- ps
, [s, f];
1857 | ps
, (s'
, _) :: rest
when s'
= s ->
1858 state.geomcmds
<- ps
, ((s, f) :: rest
);
1861 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1865 Hashtbl.iter
(fun _ opaque
->
1866 wcmd "freepage %s" opaque
;
1868 Hashtbl.clear
state.pagemap
;
1871 let opendoc path password
=
1873 state.password
<- password
;
1874 state.gen
<- state.gen
+ 1;
1875 state.docinfo
<- [];
1878 setaalevel
conf.aalevel
;
1879 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1880 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1881 invalidate "reqlayout"
1883 wcmd "reqlayout %d %d %s\000"
1884 conf.angle
(btod conf.proportional
) state.nameddest
;
1889 state.anchor <- getanchor ();
1890 state.wthack
<- !wtmode;
1891 opendoc state.path
state.password
;
1895 let c = c *. conf.colorscale
in
1899 let scalecolor2 (r, g
, b) =
1900 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1903 let docolumns = function
1905 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1906 let rec loop pageno pdimno pdim
y ph pdims
=
1907 if pageno = state.pagecount
1910 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1912 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1913 pdimno+1, pdim
, rest
1917 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1919 (if conf.presentation
1920 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1921 else (if pageno = 0 then 0 else conf.interpagespace
)
1924 a.(pageno) <- (pdimno, x, y, pdim
);
1925 loop (pageno+1) pdimno pdim
(y + h) h pdims
1927 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1928 conf.columns
<- Csingle
a;
1930 | Cmulti
((columns
, coverA
, coverB
), _) ->
1931 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1932 let rec loop pageno pdimno pdim
x y rowh pdims
=
1933 let rec fixrow m
= if m
= pageno then () else
1934 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1937 let y = y + (rowh
- h) / 2 in
1938 a.(m
) <- (pdimno, x, y, pdim
);
1942 if pageno = state.pagecount
1943 then fixrow (((pageno - 1) / columns
) * columns
)
1945 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1947 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1948 pdimno+1, pdim
, rest
1953 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1955 let x = (conf.winw
- state.scrollw
- w) / 2 in
1957 if conf.presentation
then calcips h else conf.interpagespace
in
1958 x, y + ips + rowh
, h
1961 if (pageno - coverA
) mod columns
= 0
1963 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1965 if conf.presentation
1967 let ips = calcips h in
1968 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1970 y + (if pageno = 0 then 0 else conf.interpagespace
)
1974 else x, y, max rowh
h
1978 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1981 if pageno = columns
&& conf.presentation
1983 let ips = calcips rowh
in
1984 for i
= 0 to pred columns
1986 let (pdimno, x, y, pdim
) = a.(i
) in
1987 a.(i
) <- (pdimno, x, y+ips, pdim
)
1993 fixrow (pageno - columns
);
1998 a.(pageno) <- (pdimno, x, y, pdim
);
1999 let x = x + w + xoff
*2 + conf.interpagespace
in
2000 loop (pageno+1) pdimno pdim
x y rowh' pdims
2002 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2003 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2006 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2007 let rec loop pageno pdimno pdim
y pdims
=
2008 if pageno = state.pagecount
2011 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2013 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2014 pdimno+1, pdim
, rest
2019 let rec loop1 n x y =
2020 if n = c then y else (
2021 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2022 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2025 let y = loop1 0 0 y in
2026 loop (pageno+1) pdimno pdim
y pdims
2028 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2029 conf.columns
<- Csplit
(c, a);
2033 docolumns conf.columns
;
2034 state.maxy
<- calcheight ();
2036 if state.w <= conf.winw
- state.scrollw
2040 let wthack = state.wthack in
2041 begin match state.mode
with
2042 | Birdseye
(_, _, pageno, _, _) ->
2043 let y, h = getpageyh pageno in
2044 let top = (conf.winh
- h) / 2 in
2045 gotoy (max
0 (y - top))
2046 | _ -> gotoanchor state.anchor
2048 state.wthack <- wthack;
2052 state.wthack <- false;
2053 GlDraw.viewport
0 0 w h;
2054 let firsttime = state.geomcmds
== firstgeomcmds in
2055 if not
firsttime && nogeomcmds state.geomcmds
2056 then state.anchor <- getanchor ();
2059 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2062 setfontsize fstate.fontsize
;
2063 GlMat.mode `modelview
;
2064 GlMat.load_identity
();
2066 GlMat.mode `projection
;
2067 GlMat.load_identity
();
2068 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2069 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2070 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2075 else float state.x /. float state.w
2077 invalidate "geometry"
2081 then state.x <- truncate
(relx *. float w);
2083 match conf.columns
with
2085 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2086 | Csplit
(c, _) -> w * c
2088 wcmd "geometry %d %d" w h);
2092 let len = String.length
state.text in
2095 match state.mode
with
2098 let h, _, _ = state.uioh#scrollpw
in
2104 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2105 (x+.w, float (conf.winh
- hscrollh))
2108 let w = float (conf.winw
- state.scrollw
- 1) in
2109 if state.progress
>= 0.0 && state.progress
< 1.0
2111 GlDraw.color
(0.3, 0.3, 0.3);
2112 let w1 = w *. state.progress
in
2114 GlDraw.color
(0.0, 0.0, 0.0);
2118 GlDraw.color
(0.0, 0.0, 0.0);
2122 GlDraw.color
(1.0, 1.0, 1.0);
2123 drawstring fstate.fontsize
2124 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2127 match state.mode
with
2128 | Textentry
((prefix
, text, _, _, _, _), _) ->
2132 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2134 Printf.sprintf
"%s%s_" prefix
text
2143 if not
(istextentry state.mode
)
2145 let s1 = "(press 'e' to review error messasges)" in
2146 if String.length
s > 0 then s ^
" " ^
s1 else s1
2151 if String.length
s > 0
2156 let len = Queue.length
state.tilelru
in
2158 match state.throttle
with
2161 then preloadlayout state.y
2163 | Some
(layout, _, _) ->
2167 if state.memused
<= conf.memlimit
2172 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2173 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2174 let (_, pw, ph
, _) = getpagedim n in
2177 && colorspace
= conf.colorspace
2178 && angle
= conf.angle
2182 let x = col*conf.tilew
2183 and y = row*conf.tileh
in
2184 tilevisible (Lazy.force_val
layout) n x y
2186 then Queue.push lruitem
state.tilelru
2189 wcmd "freetile %s" p
;
2190 state.memused
<- state.memused
- s;
2191 state.uioh#infochanged Memused
;
2192 Hashtbl.remove
state.tilemap k
;
2201 Queue.iter
(fun (k
, p
, s) ->
2202 wcmd "freetile %s" p
;
2203 state.memused
<- state.memused
- s;
2204 state.uioh#infochanged Memused
;
2205 Hashtbl.remove
state.tilemap k
;
2207 Queue.clear
state.tilelru
;
2211 let logcurrently = function
2212 | Idle
-> dolog "Idle"
2213 | Loading
(l
, gen
) ->
2214 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2215 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2217 "Tiling %d[%d,%d] page=%s cs=%s angle"
2218 l
.pageno col row pageopaque
2219 (colorspace_to_string colorspace
)
2221 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2222 angle gen
conf.angle
state.gen
2224 conf.tilew
conf.tileh
2231 (* dolog "%S" cmds; *)
2234 try String.index cmds ' '
2235 with Not_found
-> -1
2240 let l = String.length cmds
in
2241 let op = String.sub cmds
0 spacepos in
2243 if l - spacepos < 2 then ""
2244 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2249 state.uioh#infochanged Pdim
;
2253 state.rects
<- state.rects1
;
2254 G.postRedisplay "clearrects";
2258 try Scanf.sscanf
args "%u" (fun n -> n)
2260 dolog "error processing 'continue' %S: %s"
2261 cmds
(Printexc.to_string exn
);
2264 state.pagecount
<- n;
2265 begin match state.currently
with
2267 state.currently
<- Idle
;
2268 state.outlines
<- Array.of_list
(List.rev
l)
2272 let cur, cmds
= state.geomcmds
in
2273 if String.length
cur = 0
2274 then failwith
"umpossible";
2276 begin match List.rev cmds
with
2278 state.geomcmds
<- "", [];
2282 state.geomcmds
<- s, List.rev rest
;
2284 if conf.maxwait
= None
2285 then G.postRedisplay "continue";
2295 then showtext ' '
args
2298 Buffer.add_string
state.errmsgs
args;
2299 state.newerrmsgs
<- true;
2300 G.postRedisplay "error message"
2303 let progress, text =
2305 Scanf.sscanf
args "%f %n"
2307 f, String.sub
args pos
(String.length
args - pos
))
2309 dolog "error processing 'progress' %S: %s"
2310 cmds
(Printexc.to_string exn
);
2314 state.progress <- progress;
2315 G.postRedisplay "progress"
2318 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2320 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2321 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2322 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2324 dolog "error processing 'firstmatch' %S: %s"
2325 cmds
(Printexc.to_string exn
);
2328 let y = (getpagey pageno) + truncate
y0 in
2331 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2334 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2336 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2337 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2338 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2340 dolog "error processing 'match' %S: %s"
2341 cmds
(Printexc.to_string exn
);
2345 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2350 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2352 dolog "error processing 'page' %S: %s"
2353 cmds
(Printexc.to_string exn
);
2356 begin match state.currently
with
2357 | Loading
(l, gen
) ->
2358 vlog "page %d took %f sec" l.pageno t
;
2359 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2360 begin match state.throttle
with
2362 let preloadedpages =
2364 then preloadlayout state.y
2369 Set.Make
(struct type t
= int let compare = (-) end) in
2371 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2372 IntSet.empty
preloadedpages
2375 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2376 if not
(IntSet.mem
pageno set)
2378 wcmd "freepage %s" opaque
;
2384 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2387 state.currently
<- Idle
;
2390 tilepage l.pageno pageopaque state.layout;
2392 load preloadedpages;
2393 if pagevisible state.layout l.pageno
2394 && layoutready state.layout
2395 then G.postRedisplay "page";
2398 | Some
(layout, _, _) ->
2399 state.currently
<- Idle
;
2400 tilepage l.pageno pageopaque layout;
2405 dolog "Inconsistent loading state";
2406 logcurrently state.currently
;
2411 let (x, y, opaque
, size
, t
) =
2413 Scanf.sscanf
args "%u %u %s %u %f"
2414 (fun x y p size t
-> (x, y, p
, size
, t
))
2416 dolog "error processing 'tile' %S: %s"
2417 cmds
(Printexc.to_string exn
);
2420 begin match state.currently
with
2421 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2422 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2425 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2427 wcmd "freetile %s" opaque
;
2428 state.currently
<- Idle
;
2432 puttileopaque l col row gen cs angle opaque size t
;
2433 state.memused
<- state.memused
+ size
;
2434 state.uioh#infochanged Memused
;
2436 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2437 opaque
, size
) state.tilelru
;
2440 match state.throttle
with
2441 | None
-> state.layout
2442 | Some
(layout, _, _) -> layout
2445 state.currently
<- Idle
;
2447 && conf.colorspace
= cs
2448 && conf.angle
= angle
2449 && tilevisible layout l.pageno x y
2450 then conttiling l.pageno pageopaque;
2452 begin match state.throttle
with
2455 then state.wthack <- not
(layoutready state.layout);
2456 preload state.layout;
2458 && conf.colorspace
= cs
2459 && conf.angle
= angle
2460 && tilevisible state.layout l.pageno x y
2461 then G.postRedisplay "tile nothrottle";
2463 | Some
(layout, y, _) ->
2464 let ready = layoutready layout in
2467 state.wthack <- false;
2469 state.layout <- layout;
2470 state.throttle
<- None
;
2471 G.postRedisplay "throttle";
2478 dolog "Inconsistent tiling state";
2479 logcurrently state.currently
;
2486 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2488 dolog "error processing 'pdim' %S: %s"
2489 cmds
(Printexc.to_string exn
);
2492 state.uioh#infochanged Pdim
;
2493 state.pdims
<- pdim :: state.pdims
2496 let (l, n, t
, h, pos
) =
2498 Scanf.sscanf
args "%u %u %d %u %n"
2499 (fun l n t
h pos
-> l, n, t
, h, pos
)
2501 dolog "error processing 'o' %S: %s"
2502 cmds
(Printexc.to_string exn
);
2505 let s = String.sub
args pos
(String.length
args - pos
) in
2506 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2507 begin match state.currently
with
2508 | Outlining outlines
->
2509 state.currently
<- Outlining
(outline :: outlines
)
2511 state.currently
<- Outlining
[outline]
2513 dolog "invalid outlining state";
2514 logcurrently currently
2520 Scanf.sscanf
args "%u %u %d"
2521 (fun n t
h -> n, t
, h)
2523 dolog "error processing 'a' %S: %s"
2524 cmds
(Printexc.to_string exn
);
2528 if conf.presentation
2530 else float t
/. float h, 0.0
2532 state.anchor <- (n, top, dtop)
2535 state.docinfo
<- (1, args) :: state.docinfo
2538 state.uioh#infochanged Docinfo
;
2539 state.docinfo
<- List.rev
state.docinfo
2542 dolog "unknown cmd `%S'" cmds
2547 let action = function
2548 | HCprev
-> cbget cb ~
-1
2549 | HCnext
-> cbget cb
1
2550 | HCfirst
-> cbget cb ~
-(cb
.rc)
2551 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2552 and cancel
() = cb
.rc <- rc
2556 let search pattern forward
=
2557 if String.length pattern
> 0
2560 match state.layout with
2563 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2565 wcmd "search %d %d %d %d,%s\000"
2566 (btod conf.icase
) pn py
(btod forward
) pattern
;
2569 let intentry text key =
2571 if key >= 32 && key < 127
2577 let text = addchar text c in
2581 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2585 let linknentry text key =
2587 if key >= 32 && key < 127
2593 let text = addchar text c in
2597 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2602 if String.length
s > 0
2605 let l = String.length
s in
2606 let rec loop pos
n = if pos
= l then n else
2607 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2608 loop (pos
+1) (n*26 + m)
2611 let rec loop n = function
2614 match getopaque l.pageno with
2615 | None
-> loop n rest
2617 let m = getlinkcount opaque
in
2620 let under = getlink opaque
n in
2623 else loop (n-m) rest
2625 loop n state.layout;
2629 let textentry text key =
2630 if key land 0xff00 = 0xff00
2632 else TEcont
(text ^
Wsi.toutf8
key)
2635 let reqlayout angle proportional
=
2636 match state.throttle
with
2638 if nogeomcmds state.geomcmds
2639 then state.anchor <- getanchor ();
2640 conf.angle
<- angle
mod 360;
2643 match state.mode
with
2644 | LinkNav
_ -> state.mode
<- View
2647 conf.proportional
<- proportional
;
2648 invalidate "reqlayout"
2649 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2653 let settrim trimmargins trimfuzz
=
2654 if nogeomcmds state.geomcmds
2655 then state.anchor <- getanchor ();
2656 conf.trimmargins
<- trimmargins
;
2657 conf.trimfuzz
<- trimfuzz
;
2658 let x0, y0, x1, y1 = trimfuzz
in
2659 invalidate "settrim"
2661 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2666 match state.throttle
with
2668 let zoom = max
0.01 zoom in
2669 if zoom <> conf.zoom
2671 state.prevzoom
<- conf.zoom;
2673 reshape conf.winw
conf.winh
;
2674 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2677 | Some
(layout, y, started
) ->
2679 match conf.maxwait
with
2683 let dt = now () -. started
in
2691 let setcolumns mode columns coverA coverB
=
2692 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2696 then showtext '
!'
"split mode doesn't work in bird's eye"
2698 conf.columns
<- Csplit
(-columns
, [||]);
2706 conf.columns
<- Csingle
[||];
2711 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2715 reshape conf.winw
conf.winh
;
2718 let enterbirdseye () =
2719 let zoom = float conf.thumbw
/. float conf.winw
in
2720 let birdseyepageno =
2721 let cy = conf.winh
/ 2 in
2725 let rec fold best
= function
2728 let d = cy - (l.pagedispy + l.pagevh/2)
2729 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2730 if abs
d < abs dbest
2737 state.mode
<- Birdseye
(
2738 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2741 conf.presentation
<- false;
2742 conf.interpagespace
<- 10;
2743 conf.hlinks
<- false;
2745 state.mstate
<- Mnone
;
2746 conf.maxwait
<- None
;
2748 match conf.beyecolumns
with
2751 Cmulti
((c, 0, 0), [||])
2752 | None
-> Csingle
[||]
2754 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2757 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2762 reshape conf.winw
conf.winh
;
2765 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2767 conf.zoom <- c.zoom;
2768 conf.presentation
<- c.presentation
;
2769 conf.interpagespace
<- c.interpagespace
;
2770 conf.maxwait
<- c.maxwait
;
2771 conf.hlinks
<- c.hlinks
;
2772 conf.beyecolumns
<- (
2773 match conf.columns
with
2774 | Cmulti
((c, _, _), _) -> Some
c
2776 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2779 match c.columns
with
2780 | Cmulti
(c, _) -> Cmulti
(c, [||])
2781 | Csingle
_ -> Csingle
[||]
2782 | Csplit
(c, _) -> Csplit
(c, [||])
2787 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2790 reshape conf.winw
conf.winh
;
2791 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2794 let togglebirdseye () =
2795 match state.mode
with
2796 | Birdseye vals
-> leavebirdseye vals
true
2797 | View
-> enterbirdseye ()
2801 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2802 let pageno = max
0 (pageno - incr
) in
2803 let rec loop = function
2804 | [] -> gotopage1 pageno 0
2805 | l :: _ when l.pageno = pageno ->
2806 if l.pagedispy >= 0 && l.pagey = 0
2807 then G.postRedisplay "upbirdseye"
2808 else gotopage1 pageno 0
2809 | _ :: rest
-> loop rest
2812 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2815 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2816 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2817 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2818 let rec loop = function
2820 let y, h = getpageyh pageno in
2821 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2823 | l :: _ when l.pageno = pageno ->
2824 if l.pagevh != l.pageh
2825 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2826 else G.postRedisplay "downbirdseye"
2827 | _ :: rest
-> loop rest
2832 let optentry mode
_ key =
2833 let btos b = if b then "on" else "off" in
2834 if key >= 32 && key < 127
2836 let c = Char.chr
key in
2840 try conf.scrollstep
<- int_of_string
s with exc
->
2841 state.text <- Printf.sprintf
"bad integer `%s': %s"
2842 s (Printexc.to_string exc
)
2844 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2849 conf.autoscrollstep
<- int_of_string
s;
2850 if state.autoscroll
<> None
2851 then state.autoscroll
<- Some
conf.autoscrollstep
2853 state.text <- Printf.sprintf
"bad integer `%s': %s"
2854 s (Printexc.to_string exc
)
2856 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2861 let n, a, b = multicolumns_of_string s in
2862 setcolumns mode
n a b;
2864 state.text <- Printf.sprintf
"bad columns `%s': %s"
2865 s (Printexc.to_string exc
)
2867 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2872 let zoom = float (int_of_string
s) /. 100.0 in
2875 state.text <- Printf.sprintf
"bad integer `%s': %s"
2876 s (Printexc.to_string exc
)
2878 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2883 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2885 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2886 begin match mode
with
2888 leavebirdseye beye
false;
2893 state.text <- Printf.sprintf
"bad integer `%s': %s"
2894 s (Printexc.to_string exc
)
2896 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2901 Some
(int_of_string
s)
2903 state.text <- Printf.sprintf
"bad integer `%s': %s"
2904 s (Printexc.to_string exc
);
2907 | Some angle
-> reqlayout angle
conf.proportional
2910 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2913 conf.icase
<- not
conf.icase
;
2914 TEdone
("case insensitive search " ^
(btos conf.icase
))
2917 conf.preload <- not
conf.preload;
2919 TEdone
("preload " ^
(btos conf.preload))
2922 conf.verbose
<- not
conf.verbose
;
2923 TEdone
("verbose " ^
(btos conf.verbose
))
2926 conf.debug
<- not
conf.debug
;
2927 TEdone
("debug " ^
(btos conf.debug
))
2930 conf.maxhfit
<- not
conf.maxhfit
;
2931 state.maxy
<- calcheight ();
2932 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2935 conf.crophack
<- not
conf.crophack
;
2936 TEdone
("crophack " ^
btos conf.crophack
)
2940 match conf.maxwait
with
2942 conf.maxwait
<- Some infinity
;
2943 "always wait for page to complete"
2945 conf.maxwait
<- None
;
2946 "show placeholder if page is not ready"
2951 conf.underinfo
<- not
conf.underinfo
;
2952 TEdone
("underinfo " ^
btos conf.underinfo
)
2955 conf.savebmarks
<- not
conf.savebmarks
;
2956 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2962 match state.layout with
2967 conf.interpagespace
<- int_of_string
s;
2968 docolumns conf.columns
;
2969 state.maxy
<- calcheight ();
2970 let y = getpagey pageno in
2973 state.text <- Printf.sprintf
"bad integer `%s': %s"
2974 s (Printexc.to_string exc
)
2976 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2979 reqlayout conf.angle
(not
conf.proportional
);
2980 TEdone
("proportional display " ^
btos conf.proportional
)
2983 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2984 TEdone
("trim margins " ^
btos conf.trimmargins
)
2987 conf.invert
<- not
conf.invert
;
2988 TEdone
("invert colors " ^
btos conf.invert
)
2992 cbput state.hists
.sel
s;
2995 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2996 textentry, ondone, true)
2999 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3005 class type lvsource
= object
3006 method getitemcount
: int
3007 method getitem
: int -> (string * int)
3008 method hasaction
: int -> bool
3017 method getactive
: int
3018 method getfirst
: int
3019 method getqsearch
: string
3020 method setqsearch
: string -> unit
3024 class virtual lvsourcebase
= object
3025 val mutable m_active
= 0
3026 val mutable m_first
= 0
3027 val mutable m_qsearch
= ""
3028 val mutable m_pan
= 0
3029 method getactive
= m_active
3030 method getfirst
= m_first
3031 method getqsearch
= m_qsearch
3032 method getpan
= m_pan
3033 method setqsearch
s = m_qsearch
<- s
3036 let withoutlastutf8 s =
3037 let len = String.length
s in
3045 let b = Char.code
s.[pos
] in
3046 if b land 0b11000000 = 0b11000000
3051 if Char.code
s.[len-1] land 0x80 = 0
3055 String.sub
s 0 first;
3058 let textentrykeyboard
3059 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3061 if key >= 0xffb0 && key <= 0xffb9
3062 then key - 0xffb0 + 48 else key
3065 state.mode
<- Textentry
(te
, onleave
);
3068 G.postRedisplay "textentrykeyboard enttext";
3070 let histaction cmd
=
3073 | Some
(action, _) ->
3074 state.mode
<- Textentry
(
3075 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3077 G.postRedisplay "textentry histaction"
3080 | 0xff08 -> (* backspace *)
3081 let s = withoutlastutf8 text in
3082 let len = String.length
s in
3083 if cancelonempty
&& len = 0
3086 G.postRedisplay "textentrykeyboard after cancel";
3089 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3092 | 0xff0d | 0xff8d -> (* (kp) enter *)
3095 G.postRedisplay "textentrykeyboard after confirm"
3097 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3098 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3099 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3100 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3102 | 0xff1b -> (* escape*)
3103 if String.length
text = 0
3105 begin match opthist
with
3107 | Some
(_, onhistcancel
) -> onhistcancel
()
3111 G.postRedisplay "textentrykeyboard after cancel2"
3114 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3117 | 0xff9f | 0xffff -> () (* delete *)
3120 && key land 0xff00 != 0xff00 (* keyboard *)
3121 && key land 0xfe00 != 0xfe00 (* xkb *)
3122 && key land 0xfd00 != 0xfd00 (* 3270 *)
3124 begin match onkey
text key with
3128 G.postRedisplay "textentrykeyboard after confirm2";
3131 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3135 G.postRedisplay "textentrykeyboard after cancel3"
3138 state.mode
<- Textentry
(te
, onleave
);
3139 G.postRedisplay "textentrykeyboard switch";
3143 vlog "unhandled key %s" (Wsi.keyname
key)
3146 let firstof first active
=
3147 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3148 then max
0 (active
- (fstate.maxrows
/2))
3152 let calcfirst first active
=
3155 let rows = active
- first in
3156 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3160 let scrollph y maxy
=
3161 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3162 let sh = float conf.winh
/. sh in
3163 let sh = max
sh (float conf.scrollh
) in
3168 else float y /. float maxy
3170 let position = (float conf.winh
-. sh) *. percent in
3173 if position +. sh > float conf.winh
3174 then float conf.winh
-. sh
3180 let coe s = (s :> uioh
);;
3182 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3184 val m_pan
= source#getpan
3185 val m_first
= source#getfirst
3186 val m_active
= source#getactive
3187 val m_qsearch
= source#getqsearch
3188 val m_prev_uioh
= state.uioh
3190 method private elemunder
y =
3191 let n = y / (fstate.fontsize
+1) in
3192 if m_first
+ n < source#getitemcount
3194 if source#hasaction
(m_first
+ n)
3195 then Some
(m_first
+ n)
3202 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3203 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3204 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3205 GlDraw.color
(1., 1., 1.);
3206 Gl.enable `texture_2d
;
3207 let fs = fstate.fontsize
in
3209 let ww = fstate.wwidth
in
3210 let tabw = 30.0*.ww in
3211 let itemcount = source#getitemcount
in
3213 if (row - m_first
) > fstate.maxrows
3216 if row >= 0 && row < itemcount
3218 let (s, level
) = source#getitem
row in
3219 let y = (row - m_first
) * nfs in
3220 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3223 Gl.disable `texture_2d
;
3224 GlDraw.polygon_mode `both `line
;
3225 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3226 GlDraw.rect (1., float (y + 1))
3227 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3228 GlDraw.polygon_mode `both `fill
;
3229 GlDraw.color
(1., 1., 1.);
3230 Gl.enable `texture_2d
;
3233 let drawtabularstring s =
3234 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3237 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3240 let len = String.length
s - tabpos - 1 in
3241 let s1 = String.sub
s 0 tabpos
3242 and s2
= String.sub
s (tabpos + 1) len in
3243 let nx = drawstr x s1 in
3245 let x = x +. (max
tabw sw) in
3252 let _ = drawtabularstring s in
3259 Gl.disable `texture_2d
;
3261 method updownlevel incr
=
3262 let len = source#getitemcount
in
3264 if m_active
>= 0 && m_active
< len
3265 then snd
(source#getitem m_active
)
3269 if i
= len then i
-1 else if i
= -1 then 0 else
3270 let _, l = source#getitem i
in
3271 if l != curlevel then i
else flow (i
+incr
)
3273 let active = flow m_active
in
3274 let first = calcfirst m_first
active in
3275 G.postRedisplay "outline updownlevel";
3276 {< m_active
= active; m_first
= first >}
3278 method private key1
key mask
=
3279 let set1 active first qsearch
=
3280 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3282 let search active pattern incr
=
3285 if n >= 0 && n < source#getitemcount
3287 let s, _ = source#getitem
n in
3289 (try ignore
(Str.search_forward
re s 0); true
3290 with Not_found
-> false)
3292 else loop (n + incr
)
3299 let re = Str.regexp_case_fold pattern
in
3305 let itemcount = source#getitemcount
in
3306 let find start incr
=
3308 if i
= -1 || i
= itemcount
3311 if source#hasaction i
3313 else find (i
+ incr
)
3318 let set active first =
3319 let first = bound first 0 (itemcount - fstate.maxrows
) in
3321 coe {< m_active
= active; m_first
= first >}
3324 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3326 let incr1 = if incr
> 0 then 1 else -1 in
3327 if isvisible m_first m_active
3330 let next = m_active
+ incr
in
3332 if next < 0 || next >= itemcount
3334 else find next incr1
3336 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3342 let first = m_first
+ incr
in
3343 let first = bound first 0 (itemcount - 1) in
3345 let next = m_active
+ incr
in
3346 let next = bound next 0 (itemcount - 1) in
3349 let active = if next = -1 then m_active
else next in
3352 let first = min
next m_first
in
3354 if abs
(next - first) > fstate.maxrows
3360 let first = m_first
+ incr
in
3361 let first = bound first 0 (itemcount - 1) in
3363 let next = m_active
+ incr
in
3364 let next = bound next 0 (itemcount - 1) in
3365 let next = find next incr1 in
3367 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3369 let active = if m_active
= -1 then next else m_active
in
3374 if isvisible first active
3380 G.postRedisplay "listview navigate";
3384 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3385 let incr = if key = 0x72 then -1 else 1 in
3387 match search (m_active
+ incr) m_qsearch
incr with
3389 state.text <- m_qsearch ^
" [not found]";
3392 state.text <- m_qsearch
;
3393 active, firstof m_first
active
3395 G.postRedisplay "listview ctrl-r/s";
3396 set1 active first m_qsearch
;
3398 | 0xff08 -> (* backspace *)
3399 if String.length m_qsearch
= 0
3402 let qsearch = withoutlastutf8 m_qsearch
in
3403 let len = String.length
qsearch in
3407 G.postRedisplay "listview empty qsearch";
3408 set1 m_active m_first
"";
3412 match search m_active
qsearch ~
-1 with
3414 state.text <- qsearch ^
" [not found]";
3417 state.text <- qsearch;
3418 active, firstof m_first
active
3420 G.postRedisplay "listview backspace qsearch";
3421 set1 active first qsearch
3424 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3425 let pattern = m_qsearch ^
Wsi.toutf8
key in
3427 match search m_active
pattern 1 with
3429 state.text <- pattern ^
" [not found]";
3432 state.text <- pattern;
3433 active, firstof m_first
active
3435 G.postRedisplay "listview qsearch add";
3436 set1 active first pattern;
3438 | 0xff1b -> (* escape *)
3440 if String.length m_qsearch
= 0
3442 G.postRedisplay "list view escape";
3445 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3447 | None
-> m_prev_uioh
3452 G.postRedisplay "list view kill qsearch";
3453 source#setqsearch
"";
3454 coe {< m_qsearch
= "" >}
3457 | 0xff0d | 0xff8d -> (* (kp) enter *)
3459 let self = {< m_qsearch
= "" >} in
3460 source#setqsearch
"";
3462 G.postRedisplay "listview enter";
3463 if m_active
>= 0 && m_active
< source#getitemcount
3465 source#exit
(coe self) false m_active m_first m_pan
"";
3468 source#exit
(coe self) true m_active m_first m_pan
"";
3471 begin match opt with
3472 | None
-> m_prev_uioh
3476 | 0xff9f | 0xffff -> (* (kp) delete *)
3479 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3480 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3481 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3482 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3484 | 0xff53 | 0xff98 -> (* (kp) right *)
3486 G.postRedisplay "listview right";
3487 coe {< m_pan
= m_pan
- 1 >}
3489 | 0xff51 | 0xff96 -> (* (kp) left *)
3491 G.postRedisplay "listview left";
3492 coe {< m_pan
= m_pan
+ 1 >}
3494 | 0xff50 | 0xff95 -> (* (kp) home *)
3495 let active = find 0 1 in
3496 G.postRedisplay "listview home";
3499 | 0xff57 | 0xff9c -> (* (kp) end *)
3500 let first = max
0 (itemcount - fstate.maxrows
) in
3501 let active = find (itemcount - 1) ~
-1 in
3502 G.postRedisplay "listview end";
3505 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3509 dolog "listview unknown key %#x" key; coe self
3511 method key key mask
=
3512 match state.mode
with
3513 | Textentry te
-> textentrykeyboard key mask te
; coe self
3514 | _ -> self#key1
key mask
3516 method button button down
x y _ =
3519 | 1 when x > conf.winw
- conf.scrollbw
->
3520 G.postRedisplay "listview scroll";
3523 let _, position, sh = self#
scrollph in
3524 if y > truncate
position && y < truncate
(position +. sh)
3526 state.mstate
<- Mscrolly
;
3530 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3531 let first = truncate
(s *. float source#getitemcount
) in
3532 let first = min source#getitemcount
first in
3533 Some
(coe {< m_first
= first; m_active
= first >})
3535 state.mstate
<- Mnone
;
3538 | 1 when not down
->
3539 begin match self#elemunder
y with
3541 G.postRedisplay "listview click";
3543 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3547 | n when (n == 4 || n == 5) && not down
->
3548 let len = source#getitemcount
in
3550 if n = 5 && m_first
+ fstate.maxrows
>= len
3554 let first = m_first
+ (if n == 4 then -1 else 1) in
3555 bound first 0 (len - 1)
3557 G.postRedisplay "listview wheel";
3558 Some
(coe {< m_first
= first >})
3559 | n when (n = 6 || n = 7) && not down
->
3560 let inc = m_first
+ (if n = 7 then -1 else 1) in
3561 G.postRedisplay "listview hwheel";
3562 Some
(coe {< m_pan
= m_pan
+ inc >})
3567 | None
-> m_prev_uioh
3571 match state.mstate
with
3573 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3574 let first = truncate
(s *. float source#getitemcount
) in
3575 let first = min source#getitemcount
first in
3576 G.postRedisplay "listview motion";
3577 coe {< m_first
= first; m_active
= first >}
3580 method pmotion
x y =
3581 if x < conf.winw
- conf.scrollbw
3584 match self#elemunder
y with
3585 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3586 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3590 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3595 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3599 method infochanged
_ = ()
3601 method scrollpw
= (0, 0.0, 0.0)
3603 let nfs = fstate.fontsize
+ 1 in
3604 let y = m_first
* nfs in
3605 let itemcount = source#getitemcount
in
3606 let maxi = max
0 (itemcount - fstate.maxrows
) in
3607 let maxy = maxi * nfs in
3608 let p, h = scrollph y maxy in
3611 method modehash
= modehash
3614 class outlinelistview ~source
=
3617 ~source
:(source
:> lvsource
)
3619 ~modehash
:(findkeyhash conf "outline")
3622 method key key mask
=
3623 let calcfirst first active =
3626 let rows = active - first in
3628 if String.length
state.text = 0
3630 else fstate.maxrows - 2
3632 if rows > maxrows then active - maxrows else first
3636 let active = m_active
+ incr in
3637 let active = bound active 0 (source#getitemcount
- 1) in
3638 let first = calcfirst m_first
active in
3639 G.postRedisplay "outline navigate";
3640 coe {< m_active
= active; m_first
= first >}
3642 let ctrl = Wsi.withctrl mask
in
3644 | 110 when ctrl -> (* ctrl-n *)
3645 source#narrow m_qsearch
;
3646 G.postRedisplay "outline ctrl-n";
3647 coe {< m_first
= 0; m_active
= 0 >}
3649 | 117 when ctrl -> (* ctrl-u *)
3651 G.postRedisplay "outline ctrl-u";
3653 coe {< m_first
= 0; m_active
= 0 >}
3655 | 108 when ctrl -> (* ctrl-l *)
3656 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3657 G.postRedisplay "outline ctrl-l";
3658 coe {< m_first
= first >}
3660 | 0xff9f | 0xffff -> (* (kp) delete *)
3661 source#remove m_active
;
3662 G.postRedisplay "outline delete";
3663 let active = max
0 (m_active
-1) in
3664 coe {< m_first
= firstof m_first
active;
3665 m_active
= active >}
3667 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3668 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3669 | 0xff55 | 0xff9a -> (* (kp) prior *)
3670 navigate ~
-(fstate.maxrows)
3671 | 0xff56 | 0xff9b -> (* (kp) next *)
3672 navigate fstate.maxrows
3674 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3678 G.postRedisplay "outline ctrl right";
3679 {< m_pan
= m_pan
+ 1 >}
3681 else self#updownlevel
1
3685 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3689 G.postRedisplay "outline ctrl left";
3690 {< m_pan
= m_pan
- 1 >}
3692 else self#updownlevel ~
-1
3696 | 0xff50 | 0xff95 -> (* (kp) home *)
3697 G.postRedisplay "outline home";
3698 coe {< m_first
= 0; m_active
= 0 >}
3700 | 0xff57 | 0xff9c -> (* (kp) end *)
3701 let active = source#getitemcount
- 1 in
3702 let first = max
0 (active - fstate.maxrows) in
3703 G.postRedisplay "outline end";
3704 coe {< m_active
= active; m_first
= first >}
3706 | _ -> super#
key key mask
3709 let outlinesource usebookmarks
=
3712 inherit lvsourcebase
3713 val mutable m_items
= empty
3714 val mutable m_orig_items
= empty
3715 val mutable m_prev_items
= empty
3716 val mutable m_narrow_pattern
= ""
3717 val mutable m_hadremovals
= false
3719 method getitemcount
=
3720 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3723 if n == Array.length m_items
&& m_hadremovals
3725 ("[Confirm removal]", 0)
3727 let s, n, _ = m_items
.(n) in
3730 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3731 ignore
(uioh
, first, qsearch);
3732 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3734 if String.length m_narrow_pattern
= 0
3740 if not
confrimremoval
3742 let _, _, anchor = m_items
.(active) in
3743 gotoghyll (getanchory anchor);
3747 state.bookmarks
<- Array.to_list m_items
;
3748 m_orig_items
<- m_items
;
3751 else m_items
<- items;
3755 method hasaction
_ = true
3758 if Array.length m_items
!= Array.length m_orig_items
3759 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3762 method narrow
pattern =
3763 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3767 let rec loop accu n =
3770 m_narrow_pattern
<- pattern;
3771 m_items
<- Array.of_list
accu
3774 let (s, _, _) as o = m_items
.(n) in
3776 if (try ignore
(Str.search_forward
re s 0); true
3777 with Not_found
-> false)
3783 loop [] (Array.length m_items
- 1)
3788 then Array.of_list
state.bookmarks
3791 m_items
<- m_orig_items
3796 if m >= 0 && m < Array.length m_items
3798 m_hadremovals
<- true;
3799 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3800 let n = if n >= m then n+1 else n in
3805 method reset
anchor items =
3806 m_hadremovals
<- false;
3807 if m_orig_items
== empty || m_prev_items
!= items
3809 m_orig_items
<- items;
3810 if String.length m_narrow_pattern
= 0
3811 then m_items
<- items;
3813 m_prev_items
<- items;
3814 let rely = getanchory anchor in
3816 let rec loop n best bestd
=
3817 if n = Array.length m_items
3820 let (_, _, anchor) = m_items
.(n) in
3821 let orely = getanchory anchor in
3822 let d = abs
(orely - rely) in
3825 else loop (n+1) best bestd
3830 m_first
<- firstof m_first
active
3834 let enterselector usebookmarks
=
3835 let source = outlinesource usebookmarks
in
3839 then Array.of_list
state.bookmarks
3842 if Array.length
outlines = 0
3844 showtext ' ' errmsg
;
3847 state.text <- source#greetmsg
;
3848 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3849 let anchor = getanchor () in
3850 source#reset
anchor outlines;
3851 state.uioh
<- coe (new outlinelistview ~
source);
3852 G.postRedisplay "enter selector";
3856 let enteroutlinemode =
3857 let f = enterselector false in
3858 fun ()-> f "Document has no outline";
3861 let enterbookmarkmode =
3862 let f = enterselector true in
3863 fun () -> f "Document has no bookmarks (yet)";
3866 let color_of_string s =
3867 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3868 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3872 let color_to_string (r, g
, b) =
3873 let r = truncate
(r *. 256.0)
3874 and g
= truncate
(g
*. 256.0)
3875 and b = truncate
(b *. 256.0) in
3876 Printf.sprintf
"%d/%d/%d" r g
b
3879 let irect_of_string s =
3880 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3883 let irect_to_string (x0,y0,x1,y1) =
3884 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3887 let makecheckers () =
3888 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3890 converted by Issac Trotts. July 25, 2002 *)
3891 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3892 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3893 let id = GlTex.gen_texture
() in
3894 GlTex.bind_texture `texture_2d
id;
3895 GlPix.store
(`unpack_alignment
1);
3896 GlTex.image2d
image;
3897 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3900 `mag_filter `nearest
;
3901 `min_filter `nearest
];
3905 let setcheckers enabled
=
3906 match state.texid
with
3908 if enabled
then state.texid
<- Some
(makecheckers ())
3913 GlTex.delete_texture texid
;
3914 state.texid
<- None
;
3918 let int_of_string_with_suffix s =
3919 let l = String.length
s in
3923 let suffix = Char.lowercase
s.[l-1] in
3925 | 'k'
-> String.sub
s 0 (l-1), 10
3926 | '
m'
-> String.sub
s 0 (l-1), 20
3927 | 'g'
-> String.sub
s 0 (l-1), 30
3931 let n = int_of_string
s1 in
3932 let m = n lsl shift
in
3934 then raise
(Failure
"value too large")
3938 let string_with_suffix_of_int n =
3943 if n land ((1 lsl 30) - 1) = 0
3946 if n land ((1 lsl 20) - 1) = 0
3949 if n land ((1 lsl 10) - 1) = 0
3956 let h = n mod 1000 in
3959 then string_of_int
h ^
s
3961 let s = Printf.sprintf
"_%03d%s" h s in
3968 let defghyllscroll = (40, 8, 32);;
3969 let ghyllscroll_of_string s =
3970 let (n, a, b) as nab
=
3973 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3975 if n <= a || n <= b || a >= b
3976 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3980 let ghyllscroll_to_string ((n, a, b) as nab
) =
3981 if nab
= defghyllscroll
3983 else Printf.sprintf
"%d,%d,%d" n a b;
3986 let describe_location () =
3988 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3990 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3991 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3995 else (100. *. (float state.y /. float maxy))
3999 Printf.sprintf
"page %d of %d [%.2f%%]"
4000 (fn+1) state.pagecount
percent
4003 "pages %d-%d of %d [%.2f%%]"
4004 (fn+1) (ln
+1) state.pagecount
percent
4007 let setpresentationmode v
=
4008 let (n, _, _) = getanchor () in
4009 let _, h = getpageyh n in
4010 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
4011 state.anchor <- (n, 0.0, float ips);
4012 conf.presentation
<- v
;
4013 if conf.presentation
4015 if not
conf.scrollbarinpm
4016 then state.scrollw
<- 0;
4018 else state.scrollw
<- conf.scrollbw
;
4023 let btos b = if b then "\xe2\x88\x9a" else "" in
4024 let showextended = ref false in
4025 let leave mode
= function
4026 | Confirm
-> state.mode
<- mode
4027 | Cancel
-> state.mode
<- mode
in
4030 val mutable m_first_time
= true
4031 val mutable m_l
= []
4032 val mutable m_a
= [||]
4033 val mutable m_prev_uioh
= nouioh
4034 val mutable m_prev_mode
= View
4036 inherit lvsourcebase
4038 method reset prev_mode prev_uioh
=
4039 m_a
<- Array.of_list
(List.rev m_l
);
4041 m_prev_mode
<- prev_mode
;
4042 m_prev_uioh
<- prev_uioh
;
4046 if n >= Array.length m_a
4050 | _, _, _, Action
_ -> m_active
<- n
4054 m_first_time
<- false;
4057 method int name get
set =
4059 (name
, `
int get
, 1, Action
(
4062 try set (int_of_string
s)
4064 state.text <- Printf.sprintf
"bad integer `%s': %s"
4065 s (Printexc.to_string exn
)
4068 let te = name ^
": ", "", None
, intentry, ondone, true in
4069 state.mode
<- Textentry
(te, leave m_prev_mode
);
4073 method int_with_suffix name get
set =
4075 (name
, `intws get
, 1, Action
(
4078 try set (int_of_string_with_suffix s)
4080 state.text <- Printf.sprintf
"bad integer `%s': %s"
4081 s (Printexc.to_string exn
)
4085 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4087 state.mode
<- Textentry
(te, leave m_prev_mode
);
4091 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4093 (name
, `
bool (btos, get
), offset
, Action
(
4100 method color name get
set =
4102 (name
, `color get
, 1, Action
(
4104 let invalid = (nan
, nan
, nan
) in
4107 try color_of_string s
4109 state.text <- Printf.sprintf
"bad color `%s': %s"
4110 s (Printexc.to_string exn
);
4116 let te = name ^
": ", "", None
, textentry, ondone, true in
4117 state.text <- color_to_string (get
());
4118 state.mode
<- Textentry
(te, leave m_prev_mode
);
4122 method string name get
set =
4124 (name
, `
string get
, 1, Action
(
4126 let ondone s = set s in
4127 let te = name ^
": ", "", None
, textentry, ondone, true in
4128 state.mode
<- Textentry
(te, leave m_prev_mode
);
4132 method colorspace name get
set =
4134 (name
, `
string get
, 1, Action
(
4137 let vals = [| "rgb"; "bgr"; "gray" |] in
4139 inherit lvsourcebase
4142 m_active
<- int_of_colorspace conf.colorspace
;
4145 method getitemcount
= Array.length
vals
4146 method getitem
n = (vals.(n), 0)
4147 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4148 ignore
(uioh
, first, pan
, qsearch);
4149 if not cancel
then set active;
4151 method hasaction
_ = true
4155 let modehash = findkeyhash conf "info" in
4156 coe (new listview ~
source ~trusted
:true ~
modehash)
4159 method caption
s offset
=
4160 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4162 method caption2
s f offset
=
4163 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4165 method getitemcount
= Array.length m_a
4168 let tostr = function
4169 | `
int f -> string_of_int
(f ())
4170 | `intws
f -> string_with_suffix_of_int (f ())
4172 | `color
f -> color_to_string (f ())
4173 | `
bool (btos, f) -> btos (f ())
4176 let name, t
, offset
, _ = m_a
.(n) in
4177 ((let s = tostr t
in
4178 if String.length
s > 0
4179 then Printf.sprintf
"%s\t%s" name s
4183 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4187 m_qsearch
<- qsearch;
4189 match m_a
.(active) with
4190 | _, _, _, Action
f -> f uioh
4202 method hasaction
n =
4204 | _, _, _, Action
_ -> true
4208 let rec fillsrc prevmode prevuioh
=
4209 let sep () = src#caption
"" 0 in
4210 let colorp name get
set =
4212 (fun () -> color_to_string (get
()))
4215 let c = color_of_string v in
4218 state.text <- Printf.sprintf
"bad color `%s': %s"
4219 v (Printexc.to_string exn
);
4222 let oldmode = state.mode
in
4223 let birdseye = isbirdseye state.mode
in
4225 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4227 src#
bool "presentation mode"
4228 (fun () -> conf.presentation
)
4229 (fun v -> setpresentationmode v);
4231 src#
bool "ignore case in searches"
4232 (fun () -> conf.icase
)
4233 (fun v -> conf.icase
<- v);
4236 (fun () -> conf.preload)
4237 (fun v -> conf.preload <- v);
4239 src#
bool "highlight links"
4240 (fun () -> conf.hlinks
)
4241 (fun v -> conf.hlinks
<- v);
4243 src#
bool "under info"
4244 (fun () -> conf.underinfo
)
4245 (fun v -> conf.underinfo
<- v);
4247 src#
bool "persistent bookmarks"
4248 (fun () -> conf.savebmarks
)
4249 (fun v -> conf.savebmarks
<- v);
4251 src#
bool "proportional display"
4252 (fun () -> conf.proportional
)
4253 (fun v -> reqlayout conf.angle
v);
4255 src#
bool "trim margins"
4256 (fun () -> conf.trimmargins
)
4257 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4259 src#
bool "persistent location"
4260 (fun () -> conf.jumpback
)
4261 (fun v -> conf.jumpback
<- v);
4264 src#
int "inter-page space"
4265 (fun () -> conf.interpagespace
)
4267 conf.interpagespace
<- n;
4268 docolumns conf.columns
;
4270 match state.layout with
4275 state.maxy <- calcheight ();
4276 let y = getpagey pageno in
4281 (fun () -> conf.pagebias
)
4282 (fun v -> conf.pagebias
<- v);
4284 src#
int "scroll step"
4285 (fun () -> conf.scrollstep
)
4286 (fun n -> conf.scrollstep
<- n);
4288 src#
int "horizontal scroll step"
4289 (fun () -> conf.hscrollstep
)
4290 (fun v -> conf.hscrollstep
<- v);
4292 src#
int "auto scroll step"
4294 match state.autoscroll
with
4296 | _ -> conf.autoscrollstep
)
4298 if state.autoscroll
<> None
4299 then state.autoscroll
<- Some
n;
4300 conf.autoscrollstep
<- n);
4303 (fun () -> truncate
(conf.zoom *. 100.))
4304 (fun v -> setzoom ((float v) /. 100.));
4307 (fun () -> conf.angle
)
4308 (fun v -> reqlayout v conf.proportional
);
4310 src#
int "scroll bar width"
4311 (fun () -> state.scrollw
)
4315 reshape conf.winw
conf.winh
;
4318 src#
int "scroll handle height"
4319 (fun () -> conf.scrollh
)
4320 (fun v -> conf.scrollh
<- v;);
4322 src#
int "thumbnail width"
4323 (fun () -> conf.thumbw
)
4325 conf.thumbw
<- min
4096 v;
4328 leavebirdseye beye
false;
4333 let mode = state.mode in
4334 src#
string "columns"
4336 match conf.columns
with
4338 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4339 | Csplit
(count
, _) -> "-" ^ string_of_int count
4342 let n, a, b = multicolumns_of_string v in
4343 setcolumns mode n a b);
4346 src#caption
"Presentation mode" 0;
4347 src#
bool "scrollbar visible"
4348 (fun () -> conf.scrollbarinpm
)
4350 if v != conf.scrollbarinpm
4352 conf.scrollbarinpm
<- v;
4353 if conf.presentation
4355 state.scrollw
<- if v then conf.scrollbw
else 0;
4356 reshape conf.winw
conf.winh
;
4362 src#caption
"Pixmap cache" 0;
4363 src#int_with_suffix
"size (advisory)"
4364 (fun () -> conf.memlimit
)
4365 (fun v -> conf.memlimit
<- v);
4368 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4369 (string_with_suffix_of_int state.memused
)
4370 (Hashtbl.length
state.tilemap
)) 1;
4373 src#caption
"Layout" 0;
4374 src#caption2
"Dimension"
4376 Printf.sprintf
"%dx%d (virtual %dx%d)"
4382 src#caption2
"Position" (fun () ->
4383 Printf.sprintf
"%dx%d" state.x state.y
4386 src#caption2
"Visible" (fun () -> describe_location ()) 1
4390 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4391 "Save these parameters as global defaults at exit"
4392 (fun () -> conf.bedefault
)
4393 (fun v -> conf.bedefault
<- v)
4397 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4398 src#
bool ~offset
:0 ~
btos "Extended parameters"
4399 (fun () -> !showextended)
4400 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4404 (fun () -> conf.checkers
)
4405 (fun v -> conf.checkers
<- v; setcheckers v);
4406 src#
bool "update cursor"
4407 (fun () -> conf.updatecurs
)
4408 (fun v -> conf.updatecurs
<- v);
4410 (fun () -> conf.verbose
)
4411 (fun v -> conf.verbose
<- v);
4412 src#
bool "invert colors"
4413 (fun () -> conf.invert
)
4414 (fun v -> conf.invert
<- v);
4416 (fun () -> conf.maxhfit
)
4417 (fun v -> conf.maxhfit
<- v);
4418 src#
bool "redirect stderr"
4419 (fun () -> conf.redirectstderr)
4420 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4421 src#
string "uri launcher"
4422 (fun () -> conf.urilauncher
)
4423 (fun v -> conf.urilauncher
<- v);
4424 src#
string "path launcher"
4425 (fun () -> conf.pathlauncher
)
4426 (fun v -> conf.pathlauncher
<- v);
4427 src#
string "tile size"
4428 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4431 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4432 conf.tilew
<- max
64 w;
4433 conf.tileh
<- max
64 h;
4436 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4437 v (Printexc.to_string exn
));
4438 src#
int "texture count"
4439 (fun () -> conf.texcount
)
4442 then conf.texcount
<- v
4443 else showtext '
!'
" Failed to set texture count please retry later"
4445 src#
int "slice height"
4446 (fun () -> conf.sliceheight
)
4448 conf.sliceheight
<- v;
4449 wcmd "sliceh %d" conf.sliceheight
;
4451 src#
int "anti-aliasing level"
4452 (fun () -> conf.aalevel
)
4454 conf.aalevel
<- bound v 0 8;
4455 state.anchor <- getanchor ();
4456 opendoc state.path
state.password
;
4458 src#
string "page scroll scaling factor"
4459 (fun () -> string_of_float
conf.pgscale)
4462 let s = float_of_string
v in
4465 state.text <- Printf.sprintf
4466 "bad page scroll scaling factor `%s': %s"
4467 v (Printexc.to_string exn
)
4470 src#
int "ui font size"
4471 (fun () -> fstate.fontsize
)
4472 (fun v -> setfontsize (bound v 5 100));
4473 src#
int "hint font size"
4474 (fun () -> conf.hfsize
)
4475 (fun v -> conf.hfsize
<- bound v 5 100);
4476 colorp "background color"
4477 (fun () -> conf.bgcolor
)
4478 (fun v -> conf.bgcolor
<- v);
4479 src#
bool "crop hack"
4480 (fun () -> conf.crophack
)
4481 (fun v -> conf.crophack
<- v);
4482 src#
string "trim fuzz"
4483 (fun () -> irect_to_string conf.trimfuzz
)
4486 conf.trimfuzz
<- irect_of_string v;
4488 then settrim true conf.trimfuzz
;
4490 state.text <- Printf.sprintf
"bad irect `%s': %s"
4491 v (Printexc.to_string exn
)
4493 src#
string "throttle"
4495 match conf.maxwait
with
4496 | None
-> "show place holder if page is not ready"
4499 then "wait for page to fully render"
4501 "wait " ^ string_of_float
time
4502 ^
" seconds before showing placeholder"
4506 let f = float_of_string
v in
4508 then conf.maxwait
<- None
4509 else conf.maxwait
<- Some
f
4511 state.text <- Printf.sprintf
"bad time `%s': %s"
4512 v (Printexc.to_string exn
)
4514 src#
string "ghyll scroll"
4516 match conf.ghyllscroll
with
4518 | Some nab
-> ghyllscroll_to_string nab
4523 if String.length
v = 0
4525 else Some
(ghyllscroll_of_string v)
4527 conf.ghyllscroll
<- gs
4529 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4530 v (Printexc.to_string exn
)
4532 src#
string "selection command"
4533 (fun () -> conf.selcmd
)
4534 (fun v -> conf.selcmd
<- v);
4535 src#colorspace
"color space"
4536 (fun () -> colorspace_to_string conf.colorspace
)
4538 conf.colorspace
<- colorspace_of_int v;
4545 (fun () -> conf.usepbo
)
4546 (fun v -> conf.usepbo
<- v);
4547 src#
bool "mouse wheel scrolls pages"
4548 (fun () -> conf.wheelbypage
)
4549 (fun v -> conf.wheelbypage
<- v);
4553 src#caption
"Document" 0;
4554 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4555 src#caption2
"Pages"
4556 (fun () -> string_of_int
state.pagecount
) 1;
4557 src#caption2
"Dimensions"
4558 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4562 src#caption
"Trimmed margins" 0;
4563 src#caption2
"Dimensions"
4564 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4568 src#caption
"OpenGL" 0;
4569 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4570 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4571 src#reset prevmode prevuioh
;
4575 let prevmode = state.mode
4576 and prevuioh
= state.uioh in
4577 fillsrc prevmode prevuioh
;
4578 let source = (src :> lvsource
) in
4579 let modehash = findkeyhash conf "info" in
4580 state.uioh <- coe (object (self)
4581 inherit listview ~
source ~trusted
:true ~
modehash as super
4582 val mutable m_prevmemused
= 0
4583 method infochanged
= function
4585 if m_prevmemused
!= state.memused
4587 m_prevmemused
<- state.memused
;
4588 G.postRedisplay "memusedchanged";
4590 | Pdim
-> G.postRedisplay "pdimchanged"
4591 | Docinfo
-> fillsrc prevmode prevuioh
4593 method key key mask
=
4594 if not
(Wsi.withctrl mask
)
4597 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4598 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4599 | _ -> super#
key key mask
4600 else super#
key key mask
4602 G.postRedisplay "info";
4608 inherit lvsourcebase
4609 method getitemcount
= Array.length
state.help
4611 let s, l, _ = state.help
.(n) in
4614 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4618 m_qsearch
<- qsearch;
4619 match state.help
.(active) with
4620 | _, _, Action
f -> Some
(f uioh)
4630 method hasaction
n =
4631 match state.help
.(n) with
4632 | _, _, Action
_ -> true
4639 let modehash = findkeyhash conf "help" in
4640 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4641 G.postRedisplay "help";
4646 let re = Str.regexp
"[\r\n]" in
4648 inherit lvsourcebase
4649 val mutable m_items
= [||]
4651 method getitemcount
= 1 + Array.length m_items
4656 else m_items
.(n-1), 0
4658 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4663 then Buffer.clear
state.errmsgs
;
4664 m_qsearch
<- qsearch;
4671 method hasaction
n =
4675 state.newerrmsgs
<- false;
4676 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4677 m_items
<- Array.of_list
l
4685 let source = (msgsource :> lvsource
) in
4686 let modehash = findkeyhash conf "listview" in
4687 state.uioh <- coe (object
4688 inherit listview ~
source ~trusted
:false ~
modehash as super
4691 then msgsource#reset
;
4694 G.postRedisplay "msgs";
4697 let quickbookmark ?title
() =
4698 match state.layout with
4704 let sec = Unix.gettimeofday
() in
4705 let tm = Unix.localtime
sec in
4706 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4710 (tm.Unix.tm_year
+ 1900)
4713 | Some
title -> title
4715 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4719 state.fullscreen
<- None
;
4723 let setautoscrollspeed step goingdown
=
4724 let incr = max
1 ((abs step
) / 2) in
4725 let incr = if goingdown
then incr else -incr in
4726 let astep = step
+ incr in
4727 state.autoscroll
<- Some
astep;
4730 let gotounder = function
4731 | Ulinkgoto
(pageno, top) ->
4735 gotopage1 pageno top;
4741 | Uremote
(filename
, pageno) ->
4743 if Sys.file_exists filename
4746 let dir = Filename.dirname
state.path in
4747 let path = Filename.concat
dir filename
in
4748 if Sys.file_exists
path
4752 if String.length
path > 0
4754 let anchor = getanchor () in
4755 let ranchor = state.path, state.password
, anchor in
4756 state.anchor <- (pageno, 0.0, 0.0);
4757 state.ranchors
<- ranchor :: state.ranchors
;
4760 else showtext '
!'
("Could not find " ^ filename
)
4762 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4766 match conf.columns
with
4768 | _ -> conf.zoom > 1.0
4771 let existsinrow pageno (columns
, coverA
, coverB
) p =
4772 let last = ((pageno - coverA
) mod columns
) + columns
in
4773 let rec any = function
4776 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4780 then (if l.pageno = last then false else any rest
)
4788 match state.layout with
4791 match conf.columns
with
4793 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4795 let y = clamp (pgscale conf.winh
) in
4798 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4799 gotoghyll (getpagey pageno)
4800 | Cmulti
((c, _, _) as cl
, _) ->
4801 if conf.presentation
4802 && (existsinrow l.pageno cl
4803 (fun l -> l.pageh
> l.pagey + l.pagevh))
4805 let y = clamp (pgscale conf.winh
) in
4808 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4809 gotoghyll (getpagey pageno)
4811 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4813 let pagey, pageh
= getpageyh l.pageno in
4814 let pagey = pagey + pageh
* l.pagecol
in
4815 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4816 gotoghyll (pagey + pageh
+ ips)
4820 match state.layout with
4823 match conf.columns
with
4825 if conf.presentation
&& l.pagey != 0
4827 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4829 let pageno = max
0 (l.pageno-1) in
4830 gotoghyll (getpagey pageno)
4831 | Cmulti
((c, _, coverB
) as cl
, _) ->
4832 if conf.presentation
&&
4833 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4835 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4838 if l.pageno = state.pagecount
- coverB
4842 let pageno = max
0 (l.pageno-decr) in
4843 gotoghyll (getpagey pageno)
4851 let pageno = max
0 (l.pageno-1) in
4852 let pagey, pageh
= getpageyh pageno in
4855 let pagey, pageh
= getpageyh l.pageno in
4856 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4861 let viewkeyboard key mask
=
4863 let mode = state.mode in
4864 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4867 G.postRedisplay "view:enttext"
4869 let ctrl = Wsi.withctrl mask
in
4871 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4877 | 0xff63 -> (* insert *)
4878 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4880 state.mode <- LinkNav
(Ltgendir
0);
4883 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4885 | 0xff1b | 113 -> (* escape / q *)
4886 begin match state.mstate
with
4888 state.mstate
<- Mnone
;
4889 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4890 G.postRedisplay "kill zoom rect";
4892 begin match state.mode with
4895 G.postRedisplay "esc leave linknav"
4897 match state.ranchors
with
4899 | (path, password
, anchor) :: rest
->
4900 state.ranchors
<- rest
;
4901 state.anchor <- anchor;
4902 opendoc path password
4906 | 0xff08 -> (* backspace *)
4907 gotoghyll (getnav ~
-1)
4915 G.postRedisplay "dehighlight";
4917 | 47 | 63 -> (* / ? *)
4918 let ondone isforw
s =
4919 cbput state.hists
.pat
s;
4920 state.searchpattern
<- s;
4923 let s = String.create
1 in
4924 s.[0] <- Char.chr
key;
4925 enttext (s, "", Some
(onhist state.hists
.pat
),
4926 textentry, ondone (key = 47), true)
4928 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4929 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4930 setzoom (conf.zoom +. incr)
4932 | 43 | 0xffab -> (* + *)
4935 try int_of_string
s with exc
->
4936 state.text <- Printf.sprintf
"bad integer `%s': %s"
4937 s (Printexc.to_string exc
);
4943 state.text <- "page bias is now " ^ string_of_int
n;
4946 enttext ("page bias: ", "", None
, intentry, ondone, true)
4948 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4949 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4950 setzoom (max
0.01 (conf.zoom -. decr))
4952 | 45 | 0xffad -> (* - *)
4953 let ondone msg
= state.text <- msg
in
4955 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4956 optentry state.mode, ondone, true
4959 | 48 when ctrl -> (* ctrl-0 *)
4962 | 49 when ctrl -> (* ctrl-1 *)
4964 match conf.columns
with
4965 | Csingle
_ | Cmulti
_ -> 1
4966 | Csplit
(n, _) -> n
4968 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4972 | 0xffc6 -> (* f9 *)
4975 | 57 when ctrl -> (* ctrl-9 *)
4978 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4979 when not
ctrl -> (* 0..9 *)
4982 try int_of_string
s with exc
->
4983 state.text <- Printf.sprintf
"bad integer `%s': %s"
4984 s (Printexc.to_string exc
);
4990 cbput state.hists
.pag
(string_of_int
n);
4991 gotopage1 (n + conf.pagebias
- 1) 0;
4994 let pageentry text key =
4995 match Char.unsafe_chr
key with
4996 | 'g'
-> TEdone
text
4997 | _ -> intentry text key
4999 let text = "x" in text.[0] <- Char.chr
key;
5000 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5003 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5004 reshape conf.winw
conf.winh
;
5007 conf.hlinks
<- not
conf.hlinks
;
5008 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5009 G.postRedisplay "toggle highlightlinks";
5012 state.glinks
<- true;
5013 let mode = state.mode in
5014 state.mode <- Textentry
(
5015 (":", "", None
, linknentry, linkndone gotounder, false),
5017 state.glinks
<- false;
5021 G.postRedisplay "view:linkent(F)"
5024 state.glinks
<- true;
5025 let mode = state.mode in
5026 state.mode <- Textentry
(
5027 (":", "", None
, linknentry, linkndone (fun under ->
5028 match Ne.pipe () with
5030 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
5031 (Printexc.to_string exn
));
5034 try popen conf.selcmd
[r, 0; w, -1]; true
5037 (Printf.sprintf
"failed to execute %s: %s"
5038 conf.selcmd
(Printexc.to_string exn
));
5042 Ne.clo fd
(fun msg
->
5043 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5046 let s = undertext under in
5050 let l = String.length
s in
5051 let n = tempfailureretry (Unix.write
w s 0) l in
5056 "failed to write %d characters to sel pipe, wrote %d"
5061 (Printf.sprintf
"failed to write to sel pipe: %s"
5062 (Printexc.to_string exn
)
5071 state.glinks
<- false;
5075 G.postRedisplay "view:linkent"
5078 begin match state.autoscroll
with
5080 conf.autoscrollstep
<- step
;
5081 state.autoscroll
<- None
5083 if conf.autoscrollstep
= 0
5084 then state.autoscroll
<- Some
1
5085 else state.autoscroll
<- Some
conf.autoscrollstep
5088 | 112 when ctrl -> (* ctrl-p *)
5092 setpresentationmode (not
conf.presentation
);
5093 showtext ' '
("presentation mode " ^
5094 if conf.presentation
then "on" else "off");
5097 begin match state.fullscreen
with
5099 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
5102 state.fullscreen
<- None
;
5106 | 112 | 78 -> (* p|N *)
5107 search state.searchpattern
false
5109 | 110 | 0xffc0 -> (* n|F3 *)
5110 search state.searchpattern
true
5113 begin match state.layout with
5116 gotoy_and_clear_text (getpagey l.pageno)
5122 | 0xff9f | 0xffff -> (* delete *)
5126 showtext ' '
(describe_location ());
5129 begin match state.layout with
5132 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5137 enterbookmarkmode ()
5139 | 104 | 0xffbe -> (* h|F1 *)
5145 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5150 match state.layout with
5152 if String.length
s > 0
5154 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5157 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5161 showtext ' '
"Quick bookmark added";
5164 begin match state.layout with
5166 let rect = getpdimrect
l.pagedimno
in
5170 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5171 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5173 (truncate
(rect.(1) -. rect.(0)),
5174 truncate
(rect.(3) -. rect.(0)))
5176 let w = truncate
((float w)*.conf.zoom)
5177 and h = truncate
((float h)*.conf.zoom) in
5180 state.anchor <- getanchor ();
5181 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5183 G.postRedisplay "z";
5188 | 50 when ctrl -> (* ctrl-2 *)
5189 let maxw = getmaxw
() in
5191 then setzoom (maxw /. float conf.winw
)
5193 | 60 | 62 -> (* < > *)
5194 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5196 | 91 | 93 -> (* [ ] *)
5198 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5200 G.postRedisplay "brightness";
5202 | 99 when state.mode = View
-> (* c *)
5204 match state.prevcolumns
with
5205 | None
-> (1, 0, 0), 1.0
5206 | Some
(columns
, z
) ->
5209 | Csplit
(c, _) -> -c, 0, 0
5210 | Cmulti
((c, a, b), _) -> c, a, b
5211 | Csingle
_ -> 1, 0, 0
5215 setcolumns View
c a b;
5218 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5219 setzoom state.prevzoom
5221 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5222 begin match state.autoscroll
with
5224 begin match state.mode with
5225 | Birdseye beye
-> upbirdseye 1 beye
5228 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5229 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5232 setautoscrollspeed n false
5235 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5236 begin match state.autoscroll
with
5238 begin match state.mode with
5239 | Birdseye beye
-> downbirdseye 1 beye
5242 then gotoy_and_clear_text (clamp (conf.winh
/2))
5243 else gotoy_and_clear_text (clamp conf.scrollstep
)
5246 setautoscrollspeed n true
5249 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5255 else conf.hscrollstep
5257 let dx = if key = 0xff51 then dx else -dx in
5258 state.x <- state.x + dx;
5259 gotoy_and_clear_text state.y
5262 G.postRedisplay "lef/right"
5265 | 0xff55 | 0xff9a -> (* (kp) prior *)
5269 match state.layout with
5271 | l :: _ -> state.y - l.pagey
5273 clamp (pgscale (-conf.winh
))
5277 | 0xff56 | 0xff9b -> (* (kp) next *)
5281 match List.rev
state.layout with
5283 | l :: _ -> getpagey l.pageno
5285 clamp (pgscale conf.winh
)
5289 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5291 | 71 | 0xff57 | 0xff9c -> (* G end *)
5292 gotoghyll (clamp state.maxy)
5294 | 0xff53 when Wsi.withalt mask
-> (* alt-right *)
5295 gotoghyll (getnav 1)
5296 | 0xff51 when Wsi.withalt mask
-> (* alt-left *)
5297 gotoghyll (getnav ~
-1)
5302 | 118 when conf.debug
-> (* v *)
5305 match getopaque l.pageno with
5308 let x0, y0, x1, y1 = pagebbox opaque
in
5309 let a,b = float x0, float y0 in
5310 let c,d = float x1, float y0 in
5311 let e,f = float x1, float y1 in
5312 let h,j
= float x0, float y1 in
5313 let rect = (a,b,c,d,e,f,h,j
) in
5315 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5317 G.postRedisplay "v";
5320 vlog "huh? %s" (Wsi.keyname
key)
5323 let linknavkeyboard key mask
linknav =
5324 let getpage pageno =
5325 let rec loop = function
5327 | l :: _ when l.pageno = pageno -> Some
l
5328 | _ :: rest
-> loop rest
5329 in loop state.layout
5331 let doexact (pageno, n) =
5332 match getopaque pageno, getpage pageno with
5333 | Some opaque
, Some
l ->
5334 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5336 let under = getlink opaque
n in
5337 G.postRedisplay "link gotounder";
5343 | 0xff50 -> (* home *)
5344 Some
(findlink opaque LDfirst
), -1
5346 | 0xff57 -> (* end *)
5347 Some
(findlink opaque LDlast
), 1
5349 | 0xff51 -> (* left *)
5350 Some
(findlink opaque
(LDleft
n)), -1
5352 | 0xff53 -> (* right *)
5353 Some
(findlink opaque
(LDright
n)), 1
5355 | 0xff52 -> (* up *)
5356 Some
(findlink opaque
(LDup
n)), -1
5358 | 0xff54 -> (* down *)
5359 Some
(findlink opaque
(LDdown
n)), 1
5364 begin match findpwl
l.pageno dir with
5368 state.mode <- LinkNav
(Ltgendir
dir);
5369 let y, h = getpageyh pageno in
5372 then y + h - conf.winh
5377 begin match getopaque pageno, getpage pageno with
5378 | Some opaque
, Some
_ ->
5380 let ld = if dir > 0 then LDfirst
else LDlast
in
5383 begin match link with
5385 showlinktype (getlink opaque
m);
5386 state.mode <- LinkNav
(Ltexact
(pageno, m));
5387 G.postRedisplay "linknav jpage";
5394 begin match opt with
5395 | Some Lnotfound
-> pwl l dir;
5396 | Some
(Lfound
m) ->
5400 let _, y0, _, y1 = getlinkrect opaque
m in
5402 then gotopage1 l.pageno y0
5404 let d = fstate.fontsize
+ 1 in
5405 if y1 - l.pagey > l.pagevh - d
5406 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5407 else G.postRedisplay "linknav";
5409 showlinktype (getlink opaque
m);
5410 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5413 | None
-> viewkeyboard key mask
5415 | _ -> viewkeyboard key mask
5420 G.postRedisplay "leave linknav"
5424 | Ltgendir
_ -> viewkeyboard key mask
5425 | Ltexact exact
-> doexact exact
5428 let keyboard key mask
=
5429 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5430 then wcmd "interrupt"
5431 else state.uioh <- state.uioh#
key key mask
5434 let birdseyekeyboard key mask
5435 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5437 match conf.columns
with
5439 | Cmulti
((c, _, _), _) -> c
5440 | Csplit
_ -> failwith
"bird's eye split mode"
5442 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5444 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5445 let y, h = getpageyh pageno in
5446 let top = (conf.winh
- h) / 2 in
5447 gotoy (max
0 (y - top))
5448 | 0xff0d (* enter *)
5449 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5450 | 0xff1b -> leavebirdseye beye
true (* escape *)
5451 | 0xff52 -> upbirdseye incr beye
(* up *)
5452 | 0xff54 -> downbirdseye incr beye
(* down *)
5453 | 0xff51 -> upbirdseye 1 beye
(* left *)
5454 | 0xff53 -> downbirdseye 1 beye
(* right *)
5456 | 0xff55 -> (* prior *)
5457 begin match state.layout with
5461 state.mode <- Birdseye
(
5462 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5464 gotopage1 l.pageno 0;
5467 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5469 | [] -> gotoy (clamp (-conf.winh
))
5471 state.mode <- Birdseye
(
5472 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5474 gotopage1 l.pageno 0
5477 | [] -> gotoy (clamp (-conf.winh
))
5480 | 0xff56 -> (* next *)
5481 begin match List.rev
state.layout with
5483 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5484 begin match layout with
5486 let incr = l.pageh
- l.pagevh in
5491 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5493 G.postRedisplay "birdseye pagedown";
5495 else gotoy (clamp (incr + conf.interpagespace
*2));
5499 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5500 gotopage1 l.pageno 0;
5503 | [] -> gotoy (clamp conf.winh
)
5506 | 0xff50 -> (* home *)
5507 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5510 | 0xff57 -> (* end *)
5511 let pageno = state.pagecount
- 1 in
5512 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5513 if not
(pagevisible state.layout pageno)
5516 match List.rev
state.pdims
with
5518 | (_, _, h, _) :: _ -> h
5520 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5521 else G.postRedisplay "birdseye end";
5522 | _ -> viewkeyboard key mask
5525 let drawpage l linkindexbase
=
5527 match state.mode with
5528 | Textentry
_ -> scalecolor 0.4
5530 | View
-> scalecolor 1.0
5531 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5532 if l.pageno = hooverpageno
5535 if l.pageno = pageno
5541 begin match getopaque l.pageno with
5543 if tileready l l.pagex
l.pagey
5545 let x = l.pagedispx - l.pagex
5546 and y = l.pagedispy - l.pagey in
5548 match conf.columns
with
5549 | Csingle
_ | Cmulti
_ ->
5550 (if conf.hlinks
then 1 else 0)
5552 && not
(isbirdseye state.mode) then 2 else 0)
5556 match state.mode with
5557 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5560 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5567 let scrollindicator () =
5568 let sbw, ph
, sh = state.uioh#
scrollph in
5569 let sbh, pw, sw = state.uioh#scrollpw
in
5571 GlDraw.color (0.64, 0.64, 0.64);
5573 (float (conf.winw
- sbw), 0.)
5574 (float conf.winw
, float conf.winh
)
5577 (0., float (conf.winh
- sbh))
5578 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5580 GlDraw.color (0.0, 0.0, 0.0);
5583 (float (conf.winw
- sbw), ph
)
5584 (float conf.winw
, ph
+. sh)
5587 (pw, float (conf.winh
- sbh))
5588 (pw +. sw, float conf.winh
)
5593 match state.mstate
with
5594 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5597 | Msel
((x0, y0), (x1, y1)) ->
5598 let rec loop = function
5600 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5601 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5602 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5603 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5605 match getopaque l.pageno with
5607 let x0, y0 = pagetranslatepoint l x0 y0 in
5608 let x1, y1 = pagetranslatepoint l x1 y1 in
5609 seltext opaque
(x0, y0, x1, y1);
5617 let showrects rects
=
5619 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5620 GlDraw.polygon_mode `both `fill
;
5621 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5623 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5625 if l.pageno = pageno
5627 let dx = float (l.pagedispx - l.pagex
) in
5628 let dy = float (l.pagedispy - l.pagey) in
5629 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5630 GlDraw.begins `quads
;
5632 GlDraw.vertex2
(x0+.dx, y0+.dy);
5633 GlDraw.vertex2
(x1+.dx, y1+.dy);
5634 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5635 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5646 GlClear.color (scalecolor2 conf.bgcolor
);
5647 GlClear.clear
[`
color];
5648 let rec loop linkindexbase
= function
5650 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5651 loop linkindexbase rest
5654 loop 0 state.layout;
5656 match state.mode with
5657 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5658 begin match getopaque pageno with
5660 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5667 | None
-> state.rects
5674 begin match state.mstate
with
5675 | Mzoomrect
((x0, y0), (x1, y1)) ->
5677 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5678 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5679 GlDraw.rect (float x0, float y0)
5680 (float x1, float y1);
5686 if not
state.wthack then Wsi.swapb
();
5689 let zoomrect x y x1 y1 =
5692 and y0 = min
y y1 in
5693 gotoy (state.y + y0);
5694 state.anchor <- getanchor ();
5695 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5697 if state.w < conf.winw
- state.scrollw
5698 then (conf.winw
- state.scrollw
- state.w) / 2
5701 state.x <- (state.x + margin) - x0;
5703 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5704 state.mstate
<- Mnone
;
5708 let winw = conf.winw - state.scrollw
- 1 in
5709 let s = float x /. float winw in
5710 let destx = truncate
(float (state.w + winw) *. s) in
5711 state.x <- winw - destx;
5712 gotoy_and_clear_text state.y;
5713 state.mstate
<- Mscrollx
;
5717 let s = float y /. float conf.winh
in
5718 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5719 gotoy_and_clear_text desty;
5720 state.mstate
<- Mscrolly
;
5723 let viewmouse button down
x y mask
=
5725 | n when (n == 4 || n == 5) && not down
->
5726 if Wsi.withctrl mask
5728 match state.mstate
with
5729 | Mzoom
(oldn
, i
) ->
5737 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5739 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5741 let zoom = conf.zoom -. incr in
5743 state.mstate
<- Mzoom
(n, 0);
5745 state.mstate
<- Mzoom
(n, i
+1);
5747 else state.mstate
<- Mzoom
(n, 0)
5749 | _ -> state.mstate
<- Mzoom
(n, 0)
5752 match state.autoscroll
with
5753 | Some step
-> setautoscrollspeed step
(n=4)
5764 then -conf.scrollstep
5765 else conf.scrollstep
5767 let incr = incr * 2 in
5768 let y = clamp incr in
5769 gotoy_and_clear_text y
5772 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5773 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5774 gotoy_and_clear_text state.y
5776 | 1 when Wsi.withctrl mask
->
5779 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5780 state.mstate
<- Mpan
(x, y)
5783 state.mstate
<- Mnone
5788 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5790 state.mstate
<- Mzoomrect
(p, p)
5793 match state.mstate
with
5794 | Mzoomrect
((x0, y0), _) ->
5795 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5796 then zoomrect x0 y0 x y
5798 state.mstate
<- Mnone
;
5799 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5800 G.postRedisplay "kill accidental zoom rect";
5803 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5804 state.mstate
<- Mnone
5807 | 1 when x > conf.winw - state.scrollw
->
5810 let _, position, sh = state.uioh#
scrollph in
5811 if y > truncate
position && y < truncate
(position +. sh)
5812 then state.mstate
<- Mscrolly
5815 state.mstate
<- Mnone
5817 | 1 when y > conf.winh
- state.hscrollh ->
5820 let _, position, sw = state.uioh#scrollpw
in
5821 if x > truncate
position && x < truncate
(position +. sw)
5822 then state.mstate
<- Mscrollx
5825 state.mstate
<- Mnone
5828 let dest = if down
then getunder x y else Unone
in
5829 begin match dest with
5833 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5836 | Unone
when down
->
5837 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5838 state.mstate
<- Mpan
(x, y);
5840 | Unone
| Utext
_ ->
5843 if conf.angle
mod 360 = 0
5845 state.mstate
<- Msel
((x, y), (x, y));
5846 G.postRedisplay "mouse select";
5850 match state.mstate
with
5853 | Mzoom
_ | Mscrollx
| Mscrolly
->
5854 state.mstate
<- Mnone
5856 | Mzoomrect
((x0, y0), _) ->
5860 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5861 state.mstate
<- Mnone
5863 | Msel
((x0, y0), (x1, y1)) ->
5864 let rec loop = function
5868 let a0 = l.pagedispy in
5869 let a1 = a0 + l.pagevh in
5870 let b0 = l.pagedispx in
5871 let b1 = b0 + l.pagevw in
5872 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5873 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5877 match getopaque l.pageno with
5880 match Ne.pipe () with
5884 "can not create sel pipe: %s"
5885 (Printexc.to_string exn
));
5887 let doclose what fd
=
5888 Ne.clo fd
(fun msg
->
5889 dolog "%s close failed: %s" what msg
)
5892 popen conf.selcmd
[r, 0; w, -1];
5895 G.postRedisplay "copysel";
5897 dolog "can not execute %S: %s"
5898 conf.selcmd
(Printexc.to_string exn
);
5906 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5907 state.mstate
<- Mnone
;
5914 let birdseyemouse button down
x y mask
5915 (conf, leftx
, _, hooverpageno
, anchor) =
5918 let rec loop = function
5921 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5922 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5924 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5930 | _ -> viewmouse button down
x y mask
5933 let mouse button down
x y mask
=
5934 state.uioh <- state.uioh#button button down
x y mask
;
5938 state.uioh <- state.uioh#
motion x y
5942 state.uioh <- state.uioh#
pmotion x y;
5948 method key key mask
=
5949 begin match state.mode with
5950 | Textentry
textentry -> textentrykeyboard key mask
textentry
5951 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5952 | View
-> viewkeyboard key mask
5953 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5957 method button button bstate
x y mask
=
5958 begin match state.mode with
5960 | View
-> viewmouse button bstate
x y mask
5961 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5967 begin match state.mode with
5969 | View
| Birdseye
_ | LinkNav
_ ->
5970 match state.mstate
with
5971 | Mzoom
_ | Mnone
-> ()
5976 state.mstate
<- Mpan
(x, y);
5978 then state.x <- state.x + dx;
5980 gotoy_and_clear_text y
5983 state.mstate
<- Msel
(a, (x, y));
5984 G.postRedisplay "motion select";
5987 let y = min
conf.winh
(max
0 y) in
5991 let x = min
conf.winw (max
0 x) in
5994 | Mzoomrect
(p0
, _) ->
5995 state.mstate
<- Mzoomrect
(p0
, (x, y));
5996 G.postRedisplay "motion zoomrect";
6000 method pmotion x y =
6001 begin match state.mode with
6002 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6003 let rec loop = function
6005 if hooverpageno
!= -1
6007 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6008 G.postRedisplay "pmotion birdseye no hoover";
6011 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6012 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6014 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6015 G.postRedisplay "pmotion birdseye hoover";
6025 match state.mstate
with
6026 | Mnone
-> updateunder x y
6027 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6032 method infochanged
_ = ()
6035 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
6036 let p, h = scrollph state.y maxy in
6040 let winw = conf.winw - state.scrollw
- 1 in
6041 let fwinw = float winw in
6043 let sw = fwinw /. float state.w in
6044 let sw = fwinw *. sw in
6045 max
sw (float conf.scrollh
)
6048 let f = state.w+winw in
6049 let r = float (winw-state.x) /. float f in
6050 let p = fwinw *. r in
6054 if position +. sw > fwinw
6055 then fwinw -. position
6058 state.hscrollh, position, sw
6062 match state.mode with
6063 | LinkNav
_ -> "links"
6064 | Textentry
_ -> "textentry"
6065 | Birdseye
_ -> "birdseye"
6068 findkeyhash conf modename
6075 let fontpath = ref "";;
6078 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6081 let l = String.length
s in
6082 let b = Buffer.create
l in
6088 try Sys.getenv
"HOME"
6091 ("Can not determine home directory location: " ^
6092 Printexc.to_string exn
);
6096 let modifier_of_string = function
6097 | "alt" -> Wsi.altmask
6098 | "shift" -> Wsi.shiftmask
6099 | "ctrl" | "control" -> Wsi.ctrlmask
6100 | "meta" -> Wsi.metamask
6105 let r = Str.regexp
"-" in
6107 let elems = Str.full_split
r s in
6110 let m1 = modifier_of_string s in
6112 then (Wsi.namekey
s, m)
6115 | Str.Delim
s when n land 1 = 0 -> g s
6117 | Str.Delim
_ -> (k
, m)
6119 let rec loop n k
m = function
6122 let k, m = f n k m x in
6128 let keys_of_string =
6129 let r = Str.regexp
"[ \t]" in
6131 let elems = Str.split
r s in
6132 List.map
key_of_string elems
6135 let copykeyhashes c =
6136 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6139 let config_of c attrs
=
6143 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6144 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6145 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6146 | "preload" -> { c with preload = bool_of_string
v }
6147 | "page-bias" -> { c with pagebias
= int_of_string
v }
6148 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6149 | "horizontal-scroll-step" ->
6150 { c with hscrollstep
= max
(int_of_string
v) 1 }
6151 | "auto-scroll-step" ->
6152 { c with autoscrollstep
= max
0 (int_of_string
v) }
6153 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6154 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6157 match String.lowercase
v with
6158 | "true" -> Some infinity
6160 | f -> Some
(float_of_string
f)
6162 { c with maxwait
= mw}
6163 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6164 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6165 | "vertical-margin" ->
6166 { c with interpagespace
= max
0 (int_of_string
v) }
6168 let zoom = float_of_string
v /. 100. in
6169 let zoom = max
zoom 0.0 in
6170 { c with zoom = zoom }
6171 | "presentation" -> { c with presentation
= bool_of_string
v }
6172 | "rotation-angle" -> { c with angle
= int_of_string
v }
6173 | "width" -> { c with winw = max
20 (int_of_string
v) }
6174 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6175 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6176 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6177 | "pixmap-cache-size" ->
6178 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6179 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6180 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6181 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6182 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6183 | "background-color" -> { c with bgcolor
= color_of_string v }
6184 | "scrollbar-in-presentation" ->
6185 { c with scrollbarinpm
= bool_of_string
v }
6186 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6187 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6188 | "mupdf-store-size" ->
6189 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6190 | "checkers" -> { c with checkers
= bool_of_string
v }
6191 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6192 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6193 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6194 | "uri-launcher" -> { c with urilauncher
= unent v }
6195 | "path-launcher" -> { c with pathlauncher
= unent v }
6196 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6197 | "invert-colors" -> { c with invert
= bool_of_string
v }
6198 | "brightness" -> { c with colorscale
= float_of_string
v }
6199 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6201 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6203 let (n, _, _) as nab
= multicolumns_of_string v in
6205 then { c with columns
= Csplit
(-n, [||]) }
6206 else { c with columns
= Cmulti
(nab
, [||]) }
6207 | "birds-eye-columns" ->
6208 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6209 | "selection-command" -> { c with selcmd
= unent v }
6210 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6211 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6212 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6213 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6214 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6217 prerr_endline
("Error processing attribute (`" ^
6218 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6221 let rec fold c = function
6224 let c = apply c k v in
6227 fold { c with keyhashes
= copykeyhashes c } attrs
;
6230 let fromstring f pos
n v d =
6233 dolog "Error processing attribute (%S=%S) at %d\n%s"
6234 n v pos
(Printexc.to_string exn
)
6239 let bookmark_of attrs
=
6240 let rec fold title page
rely visy
= function
6241 | ("title", v) :: rest
-> fold v page
rely visy rest
6242 | ("page", v) :: rest
-> fold title v rely visy rest
6243 | ("rely", v) :: rest
-> fold title page
v visy rest
6244 | ("visy", v) :: rest
-> fold title page
rely v rest
6245 | _ :: rest
-> fold title page
rely visy rest
6246 | [] -> title, page
, rely, visy
6248 fold "invalid" "0" "0" "0" attrs
6252 let rec fold path page
rely pan visy
= function
6253 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6254 | ("page", v) :: rest
-> fold path v rely pan visy rest
6255 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6256 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6257 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6258 | _ :: rest
-> fold path page
rely pan visy rest
6259 | [] -> path, page
, rely, pan
, visy
6261 fold "" "0" "0" "0" "0" attrs
6265 let rec fold rs ls
= function
6266 | ("out", v) :: rest
-> fold v ls rest
6267 | ("in", v) :: rest
-> fold rs
v rest
6268 | _ :: rest
-> fold ls rs rest
6274 let setconf dst
src =
6275 dst
.scrollbw
<- src.scrollbw
;
6276 dst
.scrollh
<- src.scrollh
;
6277 dst
.icase
<- src.icase
;
6278 dst
.preload <- src.preload;
6279 dst
.pagebias
<- src.pagebias
;
6280 dst
.verbose
<- src.verbose
;
6281 dst
.scrollstep
<- src.scrollstep
;
6282 dst
.maxhfit
<- src.maxhfit
;
6283 dst
.crophack
<- src.crophack
;
6284 dst
.autoscrollstep
<- src.autoscrollstep
;
6285 dst
.maxwait
<- src.maxwait
;
6286 dst
.hlinks
<- src.hlinks
;
6287 dst
.underinfo
<- src.underinfo
;
6288 dst
.interpagespace
<- src.interpagespace
;
6289 dst
.zoom <- src.zoom;
6290 dst
.presentation
<- src.presentation
;
6291 dst
.angle
<- src.angle
;
6292 dst
.winw <- src.winw;
6293 dst
.winh
<- src.winh
;
6294 dst
.savebmarks
<- src.savebmarks
;
6295 dst
.memlimit
<- src.memlimit
;
6296 dst
.proportional
<- src.proportional
;
6297 dst
.texcount
<- src.texcount
;
6298 dst
.sliceheight
<- src.sliceheight
;
6299 dst
.thumbw
<- src.thumbw
;
6300 dst
.jumpback
<- src.jumpback
;
6301 dst
.bgcolor
<- src.bgcolor
;
6302 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6303 dst
.tilew
<- src.tilew
;
6304 dst
.tileh
<- src.tileh
;
6305 dst
.mustoresize
<- src.mustoresize
;
6306 dst
.checkers
<- src.checkers
;
6307 dst
.aalevel
<- src.aalevel
;
6308 dst
.trimmargins
<- src.trimmargins
;
6309 dst
.trimfuzz
<- src.trimfuzz
;
6310 dst
.urilauncher
<- src.urilauncher
;
6311 dst
.colorspace
<- src.colorspace
;
6312 dst
.invert
<- src.invert
;
6313 dst
.colorscale
<- src.colorscale
;
6314 dst
.redirectstderr <- src.redirectstderr;
6315 dst
.ghyllscroll
<- src.ghyllscroll
;
6316 dst
.columns
<- src.columns
;
6317 dst
.beyecolumns
<- src.beyecolumns
;
6318 dst
.selcmd
<- src.selcmd
;
6319 dst
.updatecurs
<- src.updatecurs
;
6320 dst
.pathlauncher
<- src.pathlauncher
;
6321 dst
.keyhashes
<- copykeyhashes src;
6322 dst
.hfsize
<- src.hfsize
;
6323 dst
.hscrollstep
<- src.hscrollstep
;
6324 dst
.pgscale <- src.pgscale;
6325 dst
.usepbo
<- src.usepbo
;
6326 dst
.wheelbypage
<- src.wheelbypage
;
6330 let h = Hashtbl.create
10 in
6331 let dc = { defconf with angle
= defconf.angle
} in
6332 let rec toplevel v t spos
_ =
6334 | Vdata
| Vcdata
| Vend
-> v
6335 | Vopen
("llppconfig", _, closed
) ->
6338 else { v with f = llppconfig
}
6340 error
"unexpected subelement at top level" s spos
6341 | Vclose
_ -> error
"unexpected close at top level" s spos
6343 and llppconfig
v t spos
_ =
6345 | Vdata
| Vcdata
-> v
6346 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6347 | Vopen
("defaults", attrs
, closed
) ->
6348 let c = config_of dc attrs
in
6352 else { v with f = defaults
}
6354 | Vopen
("ui-font", attrs
, closed
) ->
6355 let rec getsize size
= function
6357 | ("size", v) :: rest
->
6359 fromstring int_of_string spos
"size" v fstate.fontsize
in
6361 | l -> getsize size l
6363 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6366 else { v with f = uifont
(Buffer.create
10) }
6368 | Vopen
("doc", attrs
, closed
) ->
6369 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6370 let path = unent pathent
6371 and pageno = fromstring int_of_string spos
"page" spage
0
6372 and rely = fromstring float_of_string spos
"rely" srely
0.0
6373 and pan
= fromstring int_of_string spos
"pan" span
0
6374 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6375 let c = config_of dc attrs
in
6376 let anchor = (pageno, rely, visy
) in
6378 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6379 else { v with f = doc
path pan
anchor c [] }
6382 error
"unexpected subelement in llppconfig" s spos
6384 | Vclose
"llppconfig" -> { v with f = toplevel }
6385 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6387 and defaults
v t spos
_ =
6389 | Vdata
| Vcdata
-> v
6390 | Vend
-> error
"unexpected end of input in defaults" s spos
6391 | Vopen
("keymap", attrs
, closed
) ->
6393 try List.assoc
"mode" attrs
6394 with Not_found
-> "global" in
6399 let h = findkeyhash dc modename in
6400 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6403 { v with f = pkeymap
ret KeyMap.empty }
6405 | Vopen
(_, _, _) ->
6406 error
"unexpected subelement in defaults" s spos
6408 | Vclose
"defaults" ->
6409 { v with f = llppconfig
}
6411 | Vclose
_ -> error
"unexpected close in defaults" s spos
6413 and uifont
b v t spos
epos =
6416 Buffer.add_substring
b s spos
(epos - spos
);
6418 | Vopen
(_, _, _) ->
6419 error
"unexpected subelement in ui-font" s spos
6420 | Vclose
"ui-font" ->
6421 if String.length
!fontpath = 0
6422 then fontpath := Buffer.contents
b;
6423 { v with f = llppconfig
}
6424 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6425 | Vend
-> error
"unexpected end of input in ui-font" s spos
6427 and doc
path pan
anchor c bookmarks
v t spos
_ =
6429 | Vdata
| Vcdata
-> v
6430 | Vend
-> error
"unexpected end of input in doc" s spos
6431 | Vopen
("bookmarks", _, closed
) ->
6434 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6436 | Vopen
("keymap", attrs
, closed
) ->
6438 try List.assoc
"mode" attrs
6439 with Not_found
-> "global"
6445 let h = findkeyhash c modename in
6446 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6447 doc
path pan
anchor c bookmarks
6449 { v with f = pkeymap
ret KeyMap.empty }
6451 | Vopen
(_, _, _) ->
6452 error
"unexpected subelement in doc" s spos
6455 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6456 { v with f = llppconfig
}
6458 | Vclose
_ -> error
"unexpected close in doc" s spos
6460 and pkeymap
ret keymap
v t spos
_ =
6462 | Vdata
| Vcdata
-> v
6463 | Vend
-> error
"unexpected end of input in keymap" s spos
6464 | Vopen
("map", attrs
, closed
) ->
6465 let r, l = map_of attrs
in
6466 let kss = fromstring keys_of_string spos
"in" r [] in
6467 let lss = fromstring keys_of_string spos
"out" l [] in
6471 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6472 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6475 then { v with f = pkeymap
ret keymap }
6478 { v with f = skip
"map" f }
6481 error
"unexpected subelement in keymap" s spos
6483 | Vclose
"keymap" ->
6484 { v with f = ret keymap }
6486 | Vclose
_ -> error
"unexpected close in keymap" s spos
6488 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6490 | Vdata
| Vcdata
-> v
6491 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6492 | Vopen
("item", attrs
, closed
) ->
6493 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6494 let page = fromstring int_of_string spos
"page" spage
0
6495 and rely = fromstring float_of_string spos
"rely" srely
0.0
6496 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6498 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6501 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6504 { v with f = skip
"item" f }
6507 error
"unexpected subelement in bookmarks" s spos
6509 | Vclose
"bookmarks" ->
6510 { v with f = doc
path pan
anchor c bookmarks }
6512 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6514 and skip tag
f v t spos
_ =
6516 | Vdata
| Vcdata
-> v
6518 error
("unexpected end of input in skipped " ^ tag
) s spos
6519 | Vopen
(tag'
, _, closed
) ->
6523 let f'
() = { v with f = skip tag
f } in
6524 { v with f = skip tag'
f'
}
6528 else error
("unexpected close in skipped " ^ tag
) s spos
6531 parse
{ f = toplevel; accu = () } s;
6537 let len = in_channel_length ic
in
6538 let s = String.create
len in
6539 really_input ic
s 0 len;
6542 | Parse_error
(msg
, s, pos
) ->
6543 let subs = subs s pos
in
6544 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6545 failwith
("parse error: " ^
s)
6548 failwith
("config load error: " ^
Printexc.to_string exn
)
6554 let dir = Filename.concat
home ".config" in
6555 if Sys.is_directory
dir then dir else home
6558 Filename.concat
dir "llpp.conf"
6561 let confpath = ref defconfpath;;
6564 if Sys.file_exists
!confpath
6567 (try Some
(open_in_bin
!confpath)
6570 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6571 Printexc.to_string exn
);
6581 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6582 Printexc.to_string exn
);
6590 f (Hashtbl.create
0, defconf)
6595 let pc, pb
, px, pa
=
6597 Hashtbl.find h (Filename.basename
state.path)
6598 with Not_found
-> dc, [], 0, emptyanchor
6602 state.bookmarks <- pb
;
6604 state.scrollw
<- conf.scrollbw
;
6606 then state.anchor <- pa
;
6607 cbput state.hists
.nav pa
;
6613 let add_attrs bb always
dc c =
6616 then Printf.bprintf bb
"\n %s='%b'" s a
6619 then Printf.bprintf bb
"\n %s='%d'" s a
6622 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6625 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6628 then Printf.bprintf bb
"\n %s='%f'" s a
6632 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6636 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6640 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6644 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6650 | Some
(_N
, _A
, _B
) ->
6651 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6661 else string_of_float
f
6663 Printf.bprintf bb
"\n %s='%s'" s v
6668 | Cmulti
((n, a, b), _) when n > 1 ->
6669 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6670 | Csplit
(n, _) when n > 1 ->
6671 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6677 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6682 then dc.winw, dc.winh
6684 match state.fullscreen
with
6686 | None
-> c.winw, c.winh
6688 oi
"width" w dc.winw;
6689 oi
"height" h dc.winh
;
6690 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6691 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6692 ob "case-insensitive-search" c.icase
dc.icase
;
6693 ob "preload" c.preload dc.preload;
6694 oi
"page-bias" c.pagebias
dc.pagebias
;
6695 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6696 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6697 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6698 ob "crop-hack" c.crophack
dc.crophack
;
6699 oW
"throttle" c.maxwait
dc.maxwait
;
6700 ob "highlight-links" c.hlinks
dc.hlinks
;
6701 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6702 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6703 oz
"zoom" c.zoom dc.zoom;
6704 ob "presentation" c.presentation
dc.presentation
;
6705 oi
"rotation-angle" c.angle
dc.angle
;
6706 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6707 ob "proportional-display" c.proportional
dc.proportional
;
6708 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6709 oi
"tex-count" c.texcount
dc.texcount
;
6710 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6711 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6712 ob "persistent-location" c.jumpback
dc.jumpback
;
6713 oc
"background-color" c.bgcolor
dc.bgcolor
;
6714 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6715 oi
"tile-width" c.tilew
dc.tilew
;
6716 oi
"tile-height" c.tileh
dc.tileh
;
6717 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6718 ob "checkers" c.checkers
dc.checkers
;
6719 oi
"aalevel" c.aalevel
dc.aalevel
;
6720 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6721 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6722 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6723 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6724 oC
"color-space" c.colorspace
dc.colorspace
;
6725 ob "invert-colors" c.invert
dc.invert
;
6726 oF
"brightness" c.colorscale
dc.colorscale
;
6727 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6728 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6729 oco
"columns" c.columns
dc.columns
;
6730 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6731 os
"selection-command" c.selcmd
dc.selcmd
;
6732 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6733 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6734 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6735 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6736 ob "use-pbo" c.usepbo
dc.usepbo
;
6737 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6740 let keymapsbuf always
dc c =
6741 let bb = Buffer.create
16 in
6742 let rec loop = function
6744 | (modename, h) :: rest
->
6745 let dh = findkeyhash dc modename in
6746 if always
|| h <> dh
6748 if Hashtbl.length
h > 0
6750 if Buffer.length
bb > 0
6751 then Buffer.add_char
bb '
\n'
;
6752 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6753 Hashtbl.iter
(fun i
o ->
6754 let isdifferent = always
||
6756 let dO = Hashtbl.find dh i
in
6758 with Not_found
-> true
6763 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6764 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6765 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6766 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6767 Buffer.add_string
bb (Wsi.keyname
k);
6770 let rec loop = function
6772 | km
:: [] -> addkm km
6773 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6777 Buffer.add_string
bb "<map in='";
6781 Buffer.add_string
bb "' out='";
6783 Buffer.add_string
bb "'/>\n"
6786 Buffer.add_string
bb "' out='";
6788 Buffer.add_string
bb "'/>\n"
6790 | KMmulti
(ins, kms
) ->
6791 Buffer.add_char
bb ' '
;
6793 Buffer.add_string
bb "' out='";
6795 Buffer.add_string
bb "'/>\n"
6797 Buffer.add_string
bb "</keymap>";
6807 let uifontsize = fstate.fontsize
in
6808 let bb = Buffer.create
32768 in
6810 let dc = if conf.bedefault
then conf else dc in
6811 Buffer.add_string
bb "<llppconfig>\n";
6813 if String.length
!fontpath > 0
6815 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6821 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6824 Buffer.add_string
bb "<defaults ";
6825 add_attrs bb true dc dc;
6826 let kb = keymapsbuf true dc dc in
6827 if Buffer.length
kb > 0
6829 Buffer.add_string
bb ">\n";
6830 Buffer.add_buffer
bb kb;
6831 Buffer.add_string
bb "\n</defaults>\n";
6833 else Buffer.add_string
bb "/>\n";
6835 let adddoc path pan
anchor c bookmarks =
6836 if bookmarks == [] && c = dc && anchor = emptyanchor
6839 Printf.bprintf
bb "<doc path='%s'"
6840 (enent
path 0 (String.length
path));
6842 if anchor <> emptyanchor
6844 let n, rely, visy
= anchor in
6845 Printf.bprintf
bb " page='%d'" n;
6848 Printf.bprintf
bb " rely='%f'" rely
6850 if abs_float visy
> 1e-6
6852 Printf.bprintf
bb " visy='%f'" visy
6857 then Printf.bprintf
bb " pan='%d'" pan
;
6859 add_attrs bb false dc c;
6860 let kb = keymapsbuf false dc c in
6862 begin match bookmarks with
6864 if Buffer.length
kb > 0
6866 Buffer.add_string
bb ">\n";
6867 Buffer.add_buffer
bb kb;
6868 Buffer.add_string
bb "\n</doc>\n";
6870 else Buffer.add_string
bb "/>\n"
6872 Buffer.add_string
bb ">\n<bookmarks>\n";
6873 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6875 "<item title='%s' page='%d'"
6876 (enent
title 0 (String.length
title))
6881 Printf.bprintf
bb " rely='%f'" rely
6883 if abs_float visy
> 1e-6
6885 Printf.bprintf
bb " visy='%f'" visy
6887 Buffer.add_string
bb "/>\n";
6889 Buffer.add_string
bb "</bookmarks>";
6890 if Buffer.length
kb > 0
6892 Buffer.add_string
bb "\n";
6893 Buffer.add_buffer
bb kb;
6895 Buffer.add_string
bb "\n</doc>\n";
6901 match state.mode with
6902 | Birdseye
(c, pan, _, _, _) ->
6904 match conf.columns
with
6905 | Cmulti
((c, _, _), _) -> Some
c
6909 match c.columns
with
6910 | Cmulti
(c, _) -> Cmulti
(c, [||])
6911 | Csingle
_ -> Csingle
[||]
6912 | Csplit
_ -> failwith
"quit from bird's eye while split"
6914 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6915 | _ -> state.x, conf
6917 let basename = Filename.basename state.path in
6918 adddoc basename pan (getanchor ())
6920 let autoscrollstep =
6921 match state.autoscroll
with
6923 | None
-> conf.autoscrollstep
6925 match state.mode with
6926 | Birdseye
(bc
, _, _, _, _) ->
6929 presentation
= bc
.presentation
;
6930 interpagespace
= bc
.interpagespace
;
6931 maxwait
= bc
.maxwait
;
6932 autoscrollstep = autoscrollstep }
6933 | _ -> { conf with autoscrollstep = autoscrollstep }
6935 (if conf.savebmarks
then state.bookmarks else []);
6937 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6939 then adddoc path x anchor c bookmarks
6941 Buffer.add_string
bb "</llppconfig>\n";
6944 if load1 f && Buffer.length
bb > 0
6947 let tmp = !confpath ^
".tmp" in
6948 let oc = open_out_bin
tmp in
6949 Buffer.output_buffer
oc bb;
6951 Unix.rename
tmp !confpath;
6954 ("error while saving configuration: " ^
Printexc.to_string exn
)
6959 let trimcachepath = ref "" in
6962 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6963 "<password> Set password");
6965 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6966 "<path> Set path to the user interface font");
6968 ("-c", Arg.String
(fun s -> Config.confpath := s),
6969 "<path> Set path to the configuration file");
6971 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6972 "<path> Set path to the trim cache file");
6974 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
6975 "<named destination> Set named destination");
6977 ("-wtmode", Arg.Set
wtmode, "wt mode");
6979 ("-v", Arg.Unit
(fun () ->
6981 "%s\nconfiguration path: %s\n"
6985 exit
0), " Print version and exit");
6988 (fun s -> state.path <- s)
6989 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6991 if String.length
state.path = 0
6992 then (prerr_endline
"file name missing"; exit
1);
6994 if not
(Config.load ())
6995 then prerr_endline
"failed to load configuration";
6997 let globalkeyhash = findkeyhash conf "global" in
6998 let wsfd, winw, winh
= Wsi.init
(object
7000 state.wthack <- false;
7001 if nogeomcmds state.geomcmds
|| platform == Posx
7004 GlClear.color (scalecolor2 conf.bgcolor
);
7005 GlClear.clear
[`
color];
7007 method display = display ()
7008 method reshape w h = reshape w h
7009 method mouse b d x y m = mouse b d x y m
7010 method motion x y = state.mpos
<- (x, y); motion x y
7011 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7013 let mascm = m land (
7014 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7016 match state.keystate
with
7018 let km = k, mascm in
7021 let modehash = state.uioh#
modehash in
7022 try Hashtbl.find modehash km
7024 try Hashtbl.find globalkeyhash km
7025 with Not_found
-> KMinsrt
(k, m)
7027 | KMinsrt
(k, m) -> keyboard k m
7028 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7029 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7031 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7032 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7033 state.keystate
<- KSnone
7034 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7035 state.keystate
<- KSinto
(keys
, insrt
)
7037 state.keystate
<- KSnone
7039 method enter
x y = state.mpos
<- (x, y); pmotion x y
7040 method leave = state.mpos
<- (-1, -1)
7041 method quit
= raise Quit
7042 end) conf.winw conf.winh
(platform = Posx
) in
7047 List.exists
GlMisc.check_extension
7048 [ "GL_ARB_texture_rectangle"
7049 ; "GL_EXT_texture_recangle"
7050 ; "GL_NV_texture_rectangle" ]
7052 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7055 match Ne.pipe () with
7057 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7061 match Ne.pipe () with
7063 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7073 setcheckers conf.checkers
;
7077 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7078 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7079 !Config.fontpath, !trimcachepath,
7080 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7084 state.text <- "Opening " ^
(mbtoutf8
state.path);
7086 opendoc state.path state.password
;
7089 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7091 let rec loop deadline
=
7093 match state.errfd
with
7094 | None
-> [state.sr
; state.wsfd]
7095 | Some fd
-> [state.sr
; state.wsfd; fd
]
7099 state.redisplay
<- false;
7106 if deadline
= infinity
7108 else max
0.0 (deadline
-. now)
7113 try tempfailureretry (Unix.select
r [] []) timeout
7114 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7120 if state.ghyll
== noghyll
7122 match state.autoscroll
with
7123 | Some step
when step
!= 0 ->
7124 let y = state.y + step
in
7128 else if y >= state.maxy then 0 else y
7131 if state.mode = View
7132 then state.text <- "";
7135 else deadline
+. 0.01
7140 let rec checkfds = function
7142 | fd
:: rest
when fd
= state.sr
->
7143 let cmd = readcmd state.sr
in
7147 | fd
:: rest
when fd
= state.wsfd ->
7152 let s = String.create
80 in
7153 let n = tempfailureretry (Unix.read fd
s 0) 80 in
7154 if conf.redirectstderr
7156 Buffer.add_substring
state.errmsgs
s 0 n;
7157 state.newerrmsgs
<- true;
7158 state.redisplay
<- true;
7161 prerr_string
(String.sub
s 0 n);
7169 if deadline
= infinity
7173 match state.autoscroll
with
7174 | Some step
when step
!= 0 -> deadline1
7175 | _ -> if state.ghyll
== noghyll then infinity
else deadline1