6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
:
87 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
115 if platform = Pcygwin
117 let sh = "/bin/sh" in
118 let args = [|sh; "-c"; cmd
|] in
119 let rec std si so se
= function
121 | (fd
, 0) :: rest
-> std fd so se rest
122 | (fd
, -1) :: rest
->
123 Unix.set_close_on_exec fd
;
126 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
128 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
129 ignore
(Unix.create_process
sh args si so se
)
138 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
141 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
143 type mpos
= int * int
145 | Msel
of (mpos
* mpos
)
147 | Mscrolly
| Mscrollx
148 | Mzoom
of (int * int)
149 | Mzoomrect
of (mpos
* mpos
)
153 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
154 and onkey
= string -> int -> te
155 and ondone
= string -> unit
156 and histcancel
= unit -> unit
157 and onhist
= ((histcmd
-> string) * histcancel
)
158 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
159 and cancelonempty
= bool
164 | TEswitch
of textentry
175 let bound v minv maxv
=
176 max minv
(min maxv v
);
180 { store
= Array.create n v
187 let drawstring size x y s
=
189 Gl.enable `texture_2d
;
190 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
191 ignore
(drawstr size x y s
);
193 Gl.disable `texture_2d
;
196 let drawstring1 size x y s
=
200 let drawstring2 size x y fmt
=
201 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
204 let cbcap b
= Array.length b
.store
;;
209 b
.wc
<- (b
.wc
+ 1) mod cap;
211 b
.len
<- min
(b
.len
+ 1) cap;
214 let cbempty b
= b
.len
= 0;;
216 let cbgetg b circular dir
=
220 let rc = b
.rc + dir
in
232 else max
0 (min
rc (b
.len
-1))
238 let cbget b
= cbgetg b
false;;
239 let cbgetc b
= cbgetg b
true;;
257 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
258 dolog " WxH %dx%d" l
.pagew l
.pageh
;
259 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
260 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
261 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
262 dolog " column %d" l
.pagecol
;
266 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
268 dolog " x0,y0=(% f, % f)" x0 y0
;
269 dolog " x1,y1=(% f, % f)" x1 y1
;
270 dolog " x2,y2=(% f, % f)" x2 y2
;
271 dolog " x3,y3=(% f, % f)" x3 y3
;
275 type multicolumns
= multicol
* pagegeom
276 and splitcolumns
= columncount
* pagegeom
277 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
278 and multicol
= columncount
* covercount
* covercount
280 and columncount
= int
281 and covercount
= int;;
284 { mutable scrollbw
: int
285 ; mutable scrollh
: int
286 ; mutable icase
: bool
287 ; mutable preload
: bool
288 ; mutable pagebias
: int
289 ; mutable verbose
: bool
290 ; mutable debug
: bool
291 ; mutable scrollstep
: int
292 ; mutable maxhfit
: bool
293 ; mutable crophack
: bool
294 ; mutable autoscrollstep
: int
295 ; mutable maxwait
: float option
296 ; mutable hlinks
: bool
297 ; mutable underinfo
: bool
298 ; mutable interpagespace
: interpagespace
299 ; mutable zoom
: float
300 ; mutable presentation
: bool
301 ; mutable angle
: angle
304 ; mutable savebmarks
: bool
305 ; mutable proportional
: proportional
306 ; mutable trimmargins
: trimmargins
307 ; mutable trimfuzz
: irect
308 ; mutable memlimit
: memsize
309 ; mutable texcount
: texcount
310 ; mutable sliceheight
: sliceheight
311 ; mutable thumbw
: width
312 ; mutable jumpback
: bool
313 ; mutable bgcolor
: float * float * float
314 ; mutable bedefault
: bool
315 ; mutable scrollbarinpm
: bool
316 ; mutable tilew
: int
317 ; mutable tileh
: int
318 ; mutable mustoresize
: memsize
319 ; mutable checkers
: bool
320 ; mutable aalevel
: int
321 ; mutable urilauncher
: string
322 ; mutable pathlauncher
: string
323 ; mutable colorspace
: colorspace
324 ; mutable invert
: bool
325 ; mutable colorscale
: float
326 ; mutable redirectstderr
: bool
327 ; mutable ghyllscroll
: (int * int * int) option
328 ; mutable columns
: columns
329 ; mutable beyecolumns
: columncount
option
330 ; mutable selcmd
: string
331 ; mutable updatecurs
: bool
332 ; mutable keyhashes
: (string * keyhash
) list
333 ; mutable hfsize
: int
337 | Cmulti
of multicolumns
338 | Csplit
of splitcolumns
341 type anchor
= pageno
* top
;;
343 type outline
= string * int * anchor
;;
345 type rect
= float * float * float * float * float * float * float * float;;
347 type tile
= opaque
* pixmapsize
* elapsed
348 and elapsed
= float;;
349 type pagemapkey
= pageno
* gen
;;
350 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
354 let emptyanchor = (0, 0.0);;
356 type infochange
= | Memused
| Docinfo
| Pdim
;;
358 class type uioh
= object
359 method display
: unit
360 method key
: int -> int -> uioh
361 method button
: int -> bool -> int -> int -> int -> uioh
362 method motion
: int -> int -> uioh
363 method pmotion
: int -> int -> uioh
364 method infochanged
: infochange
-> unit
365 method scrollpw
: (int * float * float)
366 method scrollph
: (int * float * float)
367 method modehash
: keyhash
371 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
372 | Textentry
of (textentry
* onleave
)
374 | LinkNav
of linktarget
375 and onleave
= leavetextentrystatus
-> unit
376 and leavetextentrystatus
= | Cancel
| Confirm
377 and helpitem
= string * int * action
380 | Action
of (uioh
-> uioh
)
382 | Ltexact
of (pageno
* int)
386 let isbirdseye = function Birdseye _
-> true | _
-> false;;
387 let istextentry = function Textentry _
-> true | _
-> false;;
391 | Loading
of (page
* gen
)
393 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
395 | Outlining
of outline list
398 let emptykeyhash = Hashtbl.create
0;;
399 let nouioh : uioh
= object (self
)
401 method key _ _
= self
402 method button _ _ _ _ _
= self
403 method motion _ _
= self
404 method pmotion _ _
= self
405 method infochanged _
= ()
406 method scrollpw
= (0, nan
, nan
)
407 method scrollph
= (0, nan
, nan
)
408 method modehash
= emptykeyhash
412 { mutable sr
: Unix.file_descr
413 ; mutable sw
: Unix.file_descr
414 ; mutable wsfd
: Unix.file_descr
415 ; mutable errfd
: Unix.file_descr
option
416 ; mutable stderr
: Unix.file_descr
417 ; mutable errmsgs
: Buffer.t
418 ; mutable newerrmsgs
: bool
422 ; mutable scrollw
: int
423 ; mutable hscrollh
: int
424 ; mutable anchor
: anchor
425 ; mutable ranchors
: (string * string * anchor
) list
427 ; mutable layout
: page list
428 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
429 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
430 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
431 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
432 ; mutable pagecount
: int
433 ; mutable currently
: currently
434 ; mutable mstate
: mstate
435 ; mutable searchpattern
: string
436 ; mutable rects
: (pageno
* recttype
* rect
) list
437 ; mutable rects1
: (pageno
* recttype
* rect
) list
438 ; mutable text
: string
439 ; mutable fullscreen
: (width
* height
) option
440 ; mutable mode
: mode
441 ; mutable uioh
: uioh
442 ; mutable outlines
: outline array
443 ; mutable bookmarks
: outline list
444 ; mutable path
: string
445 ; mutable password
: string
446 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
447 ; mutable memused
: memsize
449 ; mutable throttle
: (page list
* int * float) option
450 ; mutable autoscroll
: int option
451 ; mutable ghyll
: (int option -> unit)
452 ; mutable help
: helpitem array
453 ; mutable docinfo
: (int * string) list
454 ; mutable texid
: GlTex.texture_id
option
456 ; mutable prevzoom
: float
457 ; mutable progress
: float
458 ; mutable redisplay
: bool
459 ; mutable mpos
: mpos
460 ; mutable keystate
: keystate
461 ; mutable glinks
: bool
462 ; mutable prevcolumns
: (columns
* float) option
465 { pat
: string circbuf
466 ; pag
: string circbuf
467 ; nav
: anchor circbuf
468 ; sel
: string circbuf
489 ; presentation
= false
494 ; proportional
= true
495 ; trimmargins
= false
496 ; trimfuzz
= (0,0,0,0)
497 ; memlimit
= 32 lsl 20
502 ; bgcolor
= (0.5, 0.5, 0.5)
504 ; scrollbarinpm
= true
507 ; mustoresize
= 256 lsl 20
512 | Plinux
| Pfreebsd
| Pdragonflybsd
513 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
514 | Posx
-> "open \"%s\""
515 | Pcygwin
-> "cygstart \"%s\""
516 | Punknown
-> "echo %s")
517 ; pathlauncher
= "lp \"%s\""
520 | Plinux
| Pfreebsd
| Pdragonflybsd
521 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
528 ; redirectstderr
= false
535 let mk n
= (n
, Hashtbl.create
1) in
549 let findkeyhash c name
=
550 try List.assoc name c
.keyhashes
551 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
554 let conf = { defconf with angle
= defconf.angle
};;
557 { mutable fontsize
: int
558 ; mutable wwidth
: float
559 ; mutable maxrows
: int
571 fstate.fontsize
<- n
;
572 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
573 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
577 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
578 let len = String.length s
in
579 if colonpos >= 0 && colonpos + 3 < len
581 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
584 try String.rindex_from s
colonpos ' '
588 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
591 | "http" | "ftp" | "mailto" ->
593 try String.index_from s
colonpos ' '
594 with Not_found
-> len
596 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
604 if String.length
conf.urilauncher
= 0
605 then print_endline uri
607 let url = geturl uri
in
608 if String.length
url = 0
609 then print_endline uri
611 let re = Str.regexp
"%s" in
612 let command = Str.global_replace
re url conf.urilauncher
in
616 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
622 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
623 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
627 let strings = version () :: "" :: Help.keys
in
630 let url = geturl s
in
631 if String.length
url > 0
632 then (s
, 0, Action
(fun u
-> gotouri url; u
))
633 else (s
, 0, Noaction
)
638 let firstgeomcmds = "", [];;
645 ; stderr
= Unix.stderr
646 ; errmsgs
= Buffer.create
0
653 ; anchor
= emptyanchor
657 ; tilelru
= Queue.create
()
658 ; pagemap
= Hashtbl.create
10
659 ; tilemap
= Hashtbl.create
10
674 ; geomcmds
= firstgeomcmds
676 { nav
= cbnew 10 (0, 0.0)
703 Printf.kprintf prerr_endline fmt
705 Printf.kprintf ignore fmt
709 if String.length
conf.pathlauncher
= 0
710 then print_endline
state.path
712 let re = Str.regexp
"%s" in
713 let command = Str.global_replace
re state.path
conf.pathlauncher
in
717 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
723 type 'a t
= | Res
of 'a
| Exn
of exn
;;
726 try Res
(Unix.pipe ())
732 with exn
-> f
(Printexc.to_string exn
)
736 try Res
(Unix.dup fd
)
741 try Res
(Unix.dup2 fd1 fd2
)
746 let redirectstderr () =
747 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
748 if conf.redirectstderr
750 match Ne.pipe () with
752 dolog "failed to create stderr redirection pipes: %s"
753 (Printexc.to_string exn
)
756 begin match Ne.dup Unix.stderr
with
758 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
759 Ne.clo r
(clofail "pipe/r");
760 Ne.clo w
(clofail "pipe/w");
762 | Ne.Res dupstderr
->
763 begin match Ne.dup2 w
Unix.stderr
with
765 dolog "failed to dup2 to stderr: %s"
766 (Printexc.to_string exn
);
767 Ne.clo dupstderr
(clofail "stderr duplicate");
768 Ne.clo r
(clofail "redir pipe/r");
769 Ne.clo w
(clofail "redir pipe/w");
772 state.stderr
<- dupstderr
;
773 state.errfd
<- Some r
;
777 state.newerrmsgs
<- false;
778 begin match state.errfd
with
780 begin match Ne.dup2 state.stderr
Unix.stderr
with
782 dolog "failed to dup2 original stderr: %s"
783 (Printexc.to_string exn
)
785 Ne.clo fd
(clofail "dup of stderr");
786 Unix.dup2 state.stderr
Unix.stderr
;
791 prerr_string
(Buffer.contents
state.errmsgs
);
793 Buffer.clear
state.errmsgs
;
799 let postRedisplay who
=
801 then prerr_endline
("redisplay for " ^ who
);
802 state.redisplay
<- true;
806 let getopaque pageno
=
807 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
808 with Not_found
-> None
811 let putopaque pageno opaque
=
812 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
815 let pagetranslatepoint l x y
=
816 let dy = y
- l
.pagedispy
in
817 let y = dy + l
.pagey
in
818 let dx = x
- l
.pagedispx
in
819 let x = dx + l
.pagex
in
826 begin match getopaque l
.pageno
with
828 let x0 = l
.pagedispx
in
829 let x1 = x0 + l
.pagevw
in
830 let y0 = l
.pagedispy
in
831 let y1 = y0 + l
.pagevh
in
832 if y >= y0 && y <= y1 && x >= x0 && x <= x1
834 let px, py
= pagetranslatepoint l
x y in
835 match whatsunder opaque
px py
with
848 state.text
<- Printf.sprintf
"%c%s" c s
;
849 G.postRedisplay "showtext";
852 let undertext = function
855 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
856 | Utext s
-> "font: " ^ s
857 | Uunexpected s
-> "unexpected: " ^ s
858 | Ulaunch s
-> "launch: " ^ s
859 | Unamed s
-> "named: " ^ s
860 | Uremote
(filename
, pageno
) ->
861 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
864 let updateunder x y =
865 match getunder x y with
866 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
868 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
869 Wsi.setcursor
Wsi.CURSOR_INFO
870 | Ulinkgoto
(pageno
, _
) ->
872 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
873 Wsi.setcursor
Wsi.CURSOR_INFO
875 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
876 Wsi.setcursor
Wsi.CURSOR_TEXT
878 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
879 Wsi.setcursor
Wsi.CURSOR_INHERIT
881 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
882 Wsi.setcursor
Wsi.CURSOR_INHERIT
884 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
885 Wsi.setcursor
Wsi.CURSOR_INHERIT
886 | Uremote
(filename
, pageno
) ->
887 if conf.underinfo
then showtext 'r'
888 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
889 Wsi.setcursor
Wsi.CURSOR_INFO
892 let showlinktype under
=
898 let s = undertext under
in
903 let b = Buffer.create
(String.length
s + 1) in
904 Buffer.add_string
b s;
909 let colorspace_of_string s =
910 match String.lowercase
s with
914 | _
-> failwith
"invalid colorspace"
917 let int_of_colorspace = function
923 let colorspace_of_int = function
927 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
930 let colorspace_to_string = function
936 let intentry_with_suffix text key
=
938 if key
>= 32 && key
< 127
942 match Char.lowercase
c with
944 let text = addchar text c in
948 let text = addchar text c in
952 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
956 let multicolumns_to_string (n
, a
, b) =
958 then Printf.sprintf
"%d" n
959 else Printf.sprintf
"%d,%d,%d" n a
b;
962 let multicolumns_of_string s =
964 (int_of_string
s, 0, 0)
966 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
971 let n = Unix.read fd
s 0 4 in
972 if n != 4 then failwith
"incomplete read(len)";
974 lor (Char.code
s.[0] lsl 24)
975 lor (Char.code
s.[1] lsl 16)
976 lor (Char.code
s.[2] lsl 8)
977 lor (Char.code
s.[3] lsl 0)
979 let s = String.create
len in
980 let n = Unix.read fd
s 0 len in
981 if n != len then failwith
"incomplete read(data)";
985 let btod b = if b then 1 else 0;;
988 let b = Buffer.create
16 in
989 Buffer.add_string
b "llll";
992 let s = Buffer.contents
b in
993 let n = String.length
s in
995 (* dolog "wcmd %S" (String.sub s 4 len); *)
996 s.[0] <- Char.chr
((len lsr 24) land 0xff);
997 s.[1] <- Char.chr
((len lsr 16) land 0xff);
998 s.[2] <- Char.chr
((len lsr 8) land 0xff);
999 s.[3] <- Char.chr
(len land 0xff);
1000 let n'
= Unix.write
state.sw
s 0 n in
1001 if n'
!= n then failwith
"write failed";
1006 if conf.presentation
1008 let d = conf.winh
- h
in
1015 let rec f pn ph pi fh l
=
1017 | (n, _
, h
, _
) :: rest
->
1018 let ips = calcips h
in
1020 if conf.presentation
1023 if isbirdseye state.mode
&& pn
= 0
1028 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1033 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1037 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1040 let fh = f 0 0 0 0 state.pdims
in
1045 match conf.columns
with
1046 | Csingle
-> calcheight ()
1047 | Cmulti
((c, _
, _
), b) ->
1048 let rec loop y h
n =
1052 if n = Array.length
b
1055 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1061 loop max_int
0 (((Array.length
b - 1) / c) * c)
1063 if Array.length
b > 0
1065 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1070 let getpageyh pageno
=
1071 let rec f pn ph pi
y l
=
1073 | (n, _
, h
, _
) :: rest
->
1074 let ips = calcips h
in
1077 let h = if n = pageno
then h else ph
in
1078 if conf.presentation
&& n = pageno
1080 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1082 y + (pageno
- pn
) * (ph
+ pi
), h
1084 let y = y + (if conf.presentation
then pi
else 0) in
1085 let y = y + (n - pn
) * (ph
+ pi
) in
1089 y + (pageno
- pn
) * (ph
+ pi
), ph
1091 f 0 0 0 0 state.pdims
1094 let getpageyh pageno
=
1095 match conf.columns
with
1096 | Csingle
-> getpageyh pageno
1098 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1102 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1106 let getpagedim pageno
=
1109 | (n, _
, _
, _
) as pdim
:: rest
->
1111 then (if n = pageno
then pdim
else ppdim
)
1116 f (-1, -1, -1, -1) state.pdims
1119 let getpagey pageno
= fst
(getpageyh pageno
);;
1121 let nogeomcmds cmds
=
1123 | s, [] -> String.length
s = 0
1128 let sh = sh - state.hscrollh
in
1129 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1130 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1132 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1133 let ips = calcips h in
1135 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1139 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1141 prev
, pdims
, pdimno
, 0
1143 let dy = dy + yinc in
1144 let py = py + yinc in
1145 if pageno
= state.pagecount
|| dy >= sh
1150 if py + h <= vy - yinc
1152 let py = py + h + ips in
1153 let dy = max
0 (py - y) in
1154 f ~pageno
:(pageno
+1)
1162 let pagey = vy - py in
1163 let pagevh = h - pagey in
1164 let pagevh = min
(sh - dy) pagevh in
1165 let off = if yinc > 0 then py - vy else 0 in
1166 let py = py + h + ips in
1169 if state.w
< conf.winw
- state.scrollw
1170 then (conf.winw
- state.scrollw
- state.w
) / 2
1173 let dispx = xoff + state.x in
1179 let lw = w
- pagex in
1180 min
lw (conf.winw
- state.scrollw
)
1184 ; pagedimno
= pdimno
1188 ; pagey = pagey + off
1190 ; pagevh = pagevh - off
1192 ; pagedispy
= dy + off
1196 let accu = e :: accu in
1197 f ~pageno
:(pageno
+1)
1218 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1219 let sh = sh - state.hscrollh
in
1220 let rec fold accu n =
1221 if n = Array.length
b
1224 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1227 || n = state.pagecount
- coverB
1228 || (n - coverA
) mod columns
= columns
- 1)
1234 let pagey = max
0 (y - vy) in
1235 let pagedispy = if pagey > 0 then 0 else vy - y in
1236 let pagedispx, pagex =
1238 if n = coverA
- 1 || n = state.pagecount
- coverB
1239 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1240 else dx + xoff + state.x
1247 let vw = conf.winw
- state.scrollw
- pagedispx in
1248 let pw = w
- pagex in
1251 let pagevh = min
(h - pagey) (sh - pagedispy) in
1252 if pagevw > 0 && pagevh > 0
1256 ; pagedimno
= pdimno
1263 ; pagedispx = pagedispx
1264 ; pagedispy = pagedispy
1276 List.rev
(fold [] 0)
1279 let layoutS (columns
, b) y sh =
1280 let sh = sh - state.hscrollh
in
1281 let rec fold accu n =
1282 if n = Array.length
b
1285 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1292 let x = xoff + state.x in
1293 let pagey = max
0 (y - vy) in
1294 let pagedispy = if pagey > 0 then 0 else vy - y in
1295 let pagedispx, pagex =
1309 let pagecolw = pagew
/columns
in
1311 if pagecolw < conf.winw
1312 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1316 let vw = conf.winw
- pagedispx - state.scrollw
in
1317 let pw = pagew
- pagex in
1320 let pagevw = min
pagevw pagecolw in
1321 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1322 if pagevw > 0 && pagevh > 0
1325 { pageno
= n/columns
1326 ; pagedimno
= pdimno
1333 ; pagedispx = pagedispx
1334 ; pagedispy = pagedispy
1335 ; pagecol
= n mod columns
1346 List.rev
(fold [] 0)
1350 if nogeomcmds state.geomcmds
1352 match conf.columns
with
1353 | Csingle
-> layout1 y sh
1354 | Cmulti
c -> layoutN c y sh
1355 | Csplit
s -> layoutS s y sh
1360 let y = state.y + incr
in
1362 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1367 let tilex = l
.pagex mod conf.tilew
in
1368 let tiley = l
.pagey mod conf.tileh
in
1370 let col = l
.pagex / conf.tilew
in
1371 let row = l
.pagey / conf.tileh
in
1373 let rec rowloop row y0 dispy
h =
1377 let dh = conf.tileh
- y0 in
1378 let dh = min
h dh in
1379 let rec colloop col x0 dispx w
=
1383 let dw = conf.tilew
- x0 in
1384 let dw = min w
dw in
1386 f col row dispx dispy
x0 y0 dw dh;
1387 colloop (col+1) 0 (dispx+dw) (w
-dw)
1390 colloop col tilex l
.pagedispx l
.pagevw;
1391 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1394 if l
.pagevw > 0 && l
.pagevh > 0
1395 then rowloop row tiley l
.pagedispy l
.pagevh;
1398 let gettileopaque l
col row =
1400 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1402 try Some
(Hashtbl.find
state.tilemap
key)
1403 with Not_found
-> None
1406 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1407 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1408 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1411 let drawtiles l color
=
1413 let f col row x y tilex tiley w
h =
1414 match gettileopaque l
col row with
1415 | Some
(opaque
, _
, t
) ->
1416 let params = x, y, w
, h, tilex, tiley in
1420 GlFunc.blend_func `zero `one_minus_src_color
;
1422 drawtile
params opaque
;
1424 then Gl.disable `blend
;
1427 let s = Printf.sprintf
1431 let w = measurestr
fstate.fontsize
s in
1432 GlMisc.push_attrib
[`current
];
1433 GlDraw.color
(0.0, 0.0, 0.0);
1435 (float (x-2), float (y-2))
1436 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1437 GlDraw.color
(1.0, 1.0, 1.0);
1438 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1439 GlMisc.pop_attrib
();
1444 let lw = conf.winw
- state.scrollw
- x in
1447 let lh = conf.winh
- y in
1450 Gl.enable `texture_2d
;
1451 begin match state.texid
with
1453 GlTex.bind_texture `texture_2d id
;
1456 and x1 = float (x+w)
1457 and y1 = float (y+h) in
1459 let tw = float w /. 64.0
1460 and th
= float h /. 64.0 in
1461 let tx0 = float tilex /. 64.0
1462 and ty0
= float tiley /. 64.0 in
1464 and ty1
= ty0
+. th
in
1465 GlDraw.begins `quads
;
1466 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1467 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1468 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1469 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1472 Gl.disable `texture_2d
;
1474 GlDraw.color
(1.0, 1.0, 1.0);
1477 (float (x+w), float (y+h));
1479 if w > 128 && h > fstate.fontsize
+ 10
1481 GlDraw.color
(0.0, 0.0, 0.0);
1484 then (col*conf.tilew
, row*conf.tileh
)
1487 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1494 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1496 let tilevisible1 l
x y =
1498 and ax1
= l
.pagex + l
.pagevw
1500 and ay1
= l
.pagey + l
.pagevh in
1504 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1505 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1507 let rx0 = max
ax0 bx0
1508 and ry0
= max ay0 by0
1509 and rx1
= min ax1
bx1
1510 and ry1
= min ay1 by1
in
1512 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1513 nonemptyintersection
1516 let tilevisible layout n x y =
1517 let rec findpageinlayout m
= function
1518 | l
:: rest
when l
.pageno
= n ->
1519 tilevisible1 l
x y || (
1520 match conf.columns
with
1521 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1524 | _
:: rest
-> findpageinlayout 0 rest
1527 findpageinlayout 0 layout;
1530 let tileready l
x y =
1531 tilevisible1 l
x y &&
1532 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1535 let tilepage n p
layout =
1536 let rec loop = function
1540 let f col row _ _ _ _ _ _
=
1541 if state.currently
= Idle
1543 match gettileopaque l
col row with
1546 let x = col*conf.tilew
1547 and y = row*conf.tileh
in
1549 let w = l
.pagew
- x in
1553 let h = l
.pageh
- y in
1556 wcmd "tile %s %d %d %d %d" p
x y w h;
1559 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1560 conf.tilew
, conf.tileh
1569 if nogeomcmds state.geomcmds
1573 let preloadlayout visiblepages
=
1574 let presentation = conf.presentation in
1575 let interpagespace = conf.interpagespace in
1576 let maxy = state.maxy in
1577 conf.presentation <- false;
1578 conf.interpagespace <- 0;
1579 state.maxy <- calcheight ();
1581 match visiblepages
with
1582 | [] -> if state.y >= maxy then maxy else 0
1583 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1585 let y = if y < conf.winh
then 0 else y - conf.winh
in
1586 let h = state.y - y + conf.winh
*3 in
1587 let pages = layout y h in
1588 conf.presentation <- presentation;
1589 conf.interpagespace <- interpagespace;
1595 let rec loop pages =
1596 if state.currently
!= Idle
1601 begin match getopaque l
.pageno
with
1603 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1604 state.currently
<- Loading
(l
, state.gen
);
1606 tilepage l
.pageno opaque
pages;
1611 if nogeomcmds state.geomcmds
1617 if conf.preload && state.currently
= Idle
1618 then load (preloadlayout pages);
1621 let layoutready layout =
1622 let rec fold all ls
=
1623 all
&& match ls
with
1625 let seen = ref false in
1626 let allvisible = ref true in
1627 let foo col row _ _ _ _ _ _
=
1629 allvisible := !allvisible &&
1630 begin match gettileopaque l
col row with
1636 fold (!seen && !allvisible) rest
1639 let alltilesvisible = fold true layout in
1644 let y = bound y 0 state.maxy in
1645 let y, layout, proceed
=
1646 match conf.maxwait
with
1647 | Some time
when state.ghyll
== noghyll ->
1648 begin match state.throttle
with
1650 let layout = layout y conf.winh
in
1651 let ready = layoutready layout in
1655 state.throttle
<- Some
(layout, y, now ());
1657 else G.postRedisplay "gotoy showall (None)";
1659 | Some
(_
, _
, started
) ->
1660 let dt = now () -. started
in
1663 state.throttle
<- None
;
1664 let layout = layout y conf.winh
in
1666 G.postRedisplay "maxwait";
1673 let layout = layout y conf.winh
in
1674 if true || layoutready layout
1675 then G.postRedisplay "gotoy ready";
1681 state.layout <- layout;
1682 begin match state.mode
with
1683 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1684 let rec loop = function
1686 state.mode
<- LinkNav
(Ltgendir
0)
1687 | l
:: _
when l
.pageno
= pageno
->
1688 begin match getopaque pageno
with
1690 state.mode
<- LinkNav
(Ltgendir
0)
1692 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1693 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1694 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1695 then state.mode
<- LinkNav
(Ltgendir
0)
1697 | _
:: rest
-> loop rest
1702 begin match state.mode
with
1703 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1704 if not
(pagevisible layout pageno
)
1706 match state.layout with
1709 state.mode
<- Birdseye
(
1710 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1713 | LinkNav
(Ltgendir dir
as lt
) ->
1715 let rec loop = function
1718 match getopaque l
.pageno
with
1724 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1726 if dir
> 0 then LDfirst
else LDlast
1732 | Lnotfound
-> loop rest
1734 showlinktype (getlink opaque
n);
1735 Ltexact
(l
.pageno
, n)
1739 state.mode
<- LinkNav
linknav
1744 state.ghyll
<- noghyll;
1747 let mx, my
= state.mpos
in
1752 let conttiling pageno opaque
=
1753 tilepage pageno opaque
1754 (if conf.preload then preloadlayout state.layout else state.layout)
1757 let gotoy_and_clear_text y =
1758 if not
conf.verbose
then state.text <- "";
1763 match state.layout with
1766 let coloff = l
.pagecol
* l
.pageh
in
1767 (l
.pageno
, (float l
.pagey +. float coloff) /. float l
.pageh
)
1770 let getanchory (n, top
) =
1771 let y, h = getpageyh n in
1772 y + (truncate
(top
*. float h));
1775 let gotoanchor anchor
=
1776 gotoy (getanchory anchor
);
1780 cbput state.hists
.nav
(getanchor ());
1784 let anchor = cbgetc state.hists
.nav dir
in
1789 let rec scroll f n a
b =
1790 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1792 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1794 then s (float f /. float a
)
1797 then 1.0 -. s ((float (f-b) /. float (n-b)))
1804 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1805 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1807 let ins = float a
*. iv1
1808 and outs
= float (n-b) *. iv1 in
1810 ins +. outs
+. float ones
1812 let rec set (_N
, _A
, _B
) y sy
=
1813 let sum = summa
1.0 _N _A _B
in
1814 let dy = float (y - sy
) in
1818 then state.ghyll
<- noghyll
1821 let s = scroll n _N _A _B
in
1822 let y1 = y1 +. ((s *. dy) /. sum) in
1823 gotoy_and_clear_text (truncate
y1);
1824 state.ghyll
<- gf (n+1) y1;
1828 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1830 gf 0 (float state.y)
1833 match conf.ghyllscroll
with
1835 gotoy_and_clear_text y
1837 if state.ghyll
== noghyll
1838 then set nab
y state.y
1839 else state.ghyll
(Some
y)
1842 let gotopage n top
=
1843 let y, h = getpageyh n in
1844 let y = y + (truncate
(top
*. float h)) in
1848 let gotopage1 n top
=
1849 let y = getpagey n in
1854 let invalidate s f =
1859 match state.geomcmds
with
1860 | ps
, [] when String.length ps
= 0 ->
1862 state.geomcmds
<- s, [];
1865 state.geomcmds
<- ps
, [s, f];
1867 | ps
, (s'
, _
) :: rest
when s'
= s ->
1868 state.geomcmds
<- ps
, ((s, f) :: rest
);
1871 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1874 let opendoc path password
=
1876 state.password
<- password
;
1877 state.gen
<- state.gen
+ 1;
1878 state.docinfo
<- [];
1880 setaalevel
conf.aalevel
;
1881 Wsi.settitle
("llpp " ^
Filename.basename path
);
1882 wcmd "open %s\000%s\000" path password
;
1883 invalidate "reqlayout"
1885 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1889 let c = c *. conf.colorscale
in
1893 let scalecolor2 (r
, g
, b) =
1894 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1897 let docolumns = function
1900 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1901 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1902 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1903 let rec fixrow m
= if m
= pageno
then () else
1904 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1907 let y = y + (rowh
- h) / 2 in
1908 a.(m
) <- (pdimno, x, y, pdim
);
1912 if pageno
= state.pagecount
1913 then fixrow (((pageno
- 1) / columns
) * columns
)
1915 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1917 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1918 pdimno+1, pdim
, rest
1923 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1925 (conf.winw
- state.scrollw
- w) / 2,
1926 y + rowh
+ conf.interpagespace, h
1929 if (pageno
- coverA
) mod columns
= 0
1930 then 0, y + rowh
+ conf.interpagespace, h
1931 else x, y, max rowh
h
1934 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1935 then fixrow (pageno
- columns
);
1936 a.(pageno
) <- (pdimno, x, y, pdim
);
1937 let x = x + w + xoff*2 + conf.interpagespace in
1938 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1940 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1941 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1944 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1945 let rec loop pageno
pdimno pdim
y pdims
=
1946 if pageno
= state.pagecount
1949 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1951 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1952 pdimno+1, pdim
, rest
1957 let rec loop1 n x y =
1958 if n = c then y else (
1959 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1960 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1963 let y = loop1 0 0 y in
1964 loop (pageno
+1) pdimno pdim
y pdims
1966 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1967 conf.columns
<- Csplit
(c, a);
1971 docolumns conf.columns
;
1972 state.maxy <- calcheight ();
1974 if state.w <= conf.winw
- state.scrollw
1978 match state.mode
with
1979 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1980 let y, h = getpageyh pageno
in
1981 let top = (conf.winh
- h) / 2 in
1982 gotoy (max
0 (y - top))
1983 | _
-> gotoanchor state.anchor
1987 GlDraw.viewport
0 0 w h;
1988 let firsttime = state.geomcmds
== firstgeomcmds in
1989 if not
firsttime && nogeomcmds state.geomcmds
1990 then state.anchor <- getanchor ();
1993 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1996 setfontsize fstate.fontsize
;
1997 GlMat.mode `modelview
;
1998 GlMat.load_identity
();
2000 GlMat.mode `projection
;
2001 GlMat.load_identity
();
2002 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2003 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2004 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2009 else float state.x /. float state.w
2011 invalidate "geometry"
2015 then state.x <- truncate
(relx *. float w);
2017 match conf.columns
with
2019 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2020 | Csplit
(c, _
) -> w * c
2022 wcmd "geometry %d %d" w h);
2026 let len = String.length
state.text in
2029 match state.mode
with
2032 let h, _
, _
= state.uioh#scrollpw
in
2038 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2039 (x+.w, float (conf.winh
- hscrollh))
2042 let w = float (conf.winw
- state.scrollw
- 1) in
2043 if state.progress
>= 0.0 && state.progress
< 1.0
2045 GlDraw.color
(0.3, 0.3, 0.3);
2046 let w1 = w *. state.progress
in
2048 GlDraw.color
(0.0, 0.0, 0.0);
2052 GlDraw.color
(0.0, 0.0, 0.0);
2056 GlDraw.color
(1.0, 1.0, 1.0);
2057 drawstring fstate.fontsize
2058 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2061 match state.mode
with
2062 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
2066 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2068 Printf.sprintf
"%s%s_" prefix
text
2077 if not
(istextentry state.mode
)
2079 let s1 = "(press 'e' to review error messasges)" in
2080 if String.length
s > 0 then s ^
" " ^
s1 else s1
2085 if String.length
s > 0
2090 let len = Queue.length
state.tilelru
in
2092 if state.memused
<= conf.memlimit
2097 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2098 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2099 let (_
, pw, ph
, _
) = getpagedim n in
2102 && colorspace
= conf.colorspace
2103 && angle
= conf.angle
2108 match state.throttle
with
2111 then preloadlayout state.layout
2113 | Some
(layout, _
, _
) ->
2116 let x = col*conf.tilew
2117 and y = row*conf.tileh
in
2118 tilevisible layout n x y
2120 then Queue.push lruitem
state.tilelru
2122 wcmd "freetile %s" p
;
2123 state.memused
<- state.memused
- s;
2124 state.uioh#infochanged Memused
;
2125 Hashtbl.remove
state.tilemap k
;
2134 Queue.iter
(fun (k
, p
, s) ->
2135 wcmd "freetile %s" p
;
2136 state.memused
<- state.memused
- s;
2137 state.uioh#infochanged Memused
;
2138 Hashtbl.remove
state.tilemap k
;
2140 Queue.clear
state.tilelru
;
2144 let logcurrently = function
2145 | Idle
-> dolog "Idle"
2146 | Loading
(l
, gen
) ->
2147 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2148 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2150 "Tiling %d[%d,%d] page=%s cs=%s angle"
2151 l
.pageno
col row pageopaque
2152 (colorspace_to_string colorspace
)
2154 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2155 angle gen
conf.angle
state.gen
2157 conf.tilew
conf.tileh
2164 (* dolog "%S" cmds; *)
2167 try String.index cmds ' '
2168 with Not_found
-> -1
2173 let l = String.length cmds
in
2174 let op = String.sub cmds
0 spacepos in
2176 if l - spacepos < 2 then ""
2177 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2182 state.uioh#infochanged Pdim
;
2186 state.rects
<- state.rects1
;
2187 G.postRedisplay "clearrects";
2191 try Scanf.sscanf
args "%u" (fun n -> n)
2193 dolog "error processing 'continue' %S: %s"
2194 cmds
(Printexc.to_string exn
);
2197 state.pagecount
<- n;
2198 begin match state.currently
with
2200 state.currently
<- Idle
;
2201 state.outlines
<- Array.of_list
(List.rev
l)
2205 let cur, cmds
= state.geomcmds
in
2206 if String.length
cur = 0
2207 then failwith
"umpossible";
2209 begin match List.rev cmds
with
2211 state.geomcmds
<- "", [];
2215 state.geomcmds
<- s, List.rev rest
;
2217 if conf.maxwait
= None
2218 then G.postRedisplay "continue";
2228 then showtext ' '
args
2231 let progress, text =
2233 Scanf.sscanf
args "%f %n"
2235 f, String.sub
args pos
(String.length
args - pos
))
2237 dolog "error processing 'progress' %S: %s"
2238 cmds
(Printexc.to_string exn
);
2242 state.progress <- progress;
2243 G.postRedisplay "progress"
2246 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2248 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2249 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2250 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2252 dolog "error processing 'firstmatch' %S: %s"
2253 cmds
(Printexc.to_string exn
);
2256 let y = (getpagey pageno) + truncate
y0 in
2259 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2262 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2264 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2265 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2266 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2268 dolog "error processing 'match' %S: %s"
2269 cmds
(Printexc.to_string exn
);
2273 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2278 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2280 dolog "error processing 'page' %S: %s"
2281 cmds
(Printexc.to_string exn
);
2284 begin match state.currently
with
2285 | Loading
(l, gen
) ->
2286 vlog "page %d took %f sec" l.pageno t
;
2287 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2288 begin match state.throttle
with
2290 let preloadedpages =
2292 then preloadlayout state.layout
2297 Set.Make
(struct type t
= int let compare = (-) end) in
2299 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2300 IntSet.empty
preloadedpages
2303 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2304 if not
(IntSet.mem
pageno set)
2306 wcmd "freepage %s" opaque
;
2312 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2315 state.currently
<- Idle
;
2318 tilepage l.pageno pageopaque state.layout;
2320 load preloadedpages;
2321 if pagevisible state.layout l.pageno
2322 && layoutready state.layout
2323 then G.postRedisplay "page";
2326 | Some
(layout, _
, _
) ->
2327 state.currently
<- Idle
;
2328 tilepage l.pageno pageopaque layout;
2333 dolog "Inconsistent loading state";
2334 logcurrently state.currently
;
2339 let (x, y, opaque
, size
, t
) =
2341 Scanf.sscanf
args "%u %u %s %u %f"
2342 (fun x y p size t
-> (x, y, p
, size
, t
))
2344 dolog "error processing 'tile' %S: %s"
2345 cmds
(Printexc.to_string exn
);
2348 begin match state.currently
with
2349 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2350 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2352 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2354 wcmd "freetile %s" opaque
;
2355 state.currently
<- Idle
;
2359 puttileopaque l col row gen cs angle opaque size t
;
2360 state.memused
<- state.memused
+ size
;
2361 state.uioh#infochanged Memused
;
2363 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2364 opaque
, size
) state.tilelru
;
2367 match state.throttle
with
2368 | None
-> state.layout
2369 | Some
(layout, _
, _
) -> layout
2372 state.currently
<- Idle
;
2374 && conf.colorspace
= cs
2375 && conf.angle
= angle
2376 && tilevisible layout l.pageno x y
2377 then conttiling l.pageno pageopaque;
2379 begin match state.throttle
with
2381 preload state.layout;
2383 && conf.colorspace
= cs
2384 && conf.angle
= angle
2385 && tilevisible state.layout l.pageno x y
2386 then G.postRedisplay "tile nothrottle";
2388 | Some
(layout, y, _
) ->
2389 let ready = layoutready layout in
2393 state.layout <- layout;
2394 state.throttle
<- None
;
2395 G.postRedisplay "throttle";
2402 dolog "Inconsistent tiling state";
2403 logcurrently state.currently
;
2410 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2412 dolog "error processing 'pdim' %S: %s"
2413 cmds
(Printexc.to_string exn
);
2416 state.uioh#infochanged Pdim
;
2417 state.pdims
<- pdim :: state.pdims
2420 let (l, n, t
, h, pos
) =
2422 Scanf.sscanf
args "%u %u %d %u %n"
2423 (fun l n t
h pos
-> l, n, t
, h, pos
)
2425 dolog "error processing 'o' %S: %s"
2426 cmds
(Printexc.to_string exn
);
2429 let s = String.sub
args pos
(String.length
args - pos
) in
2430 let outline = (s, l, (n, float t
/. float h)) in
2431 begin match state.currently
with
2432 | Outlining outlines
->
2433 state.currently
<- Outlining
(outline :: outlines
)
2435 state.currently
<- Outlining
[outline]
2437 dolog "invalid outlining state";
2438 logcurrently currently
2442 state.docinfo
<- (1, args) :: state.docinfo
2445 state.uioh#infochanged Docinfo
;
2446 state.docinfo
<- List.rev
state.docinfo
2449 dolog "unknown cmd `%S'" cmds
2454 let action = function
2455 | HCprev
-> cbget cb ~
-1
2456 | HCnext
-> cbget cb
1
2457 | HCfirst
-> cbget cb ~
-(cb
.rc)
2458 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2459 and cancel
() = cb
.rc <- rc
2463 let search pattern forward
=
2464 if String.length pattern
> 0
2467 match state.layout with
2470 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2472 wcmd "search %d %d %d %d,%s\000"
2473 (btod conf.icase
) pn py (btod forward
) pattern
;
2476 let intentry text key =
2478 if key >= 32 && key < 127
2484 let text = addchar text c in
2488 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2492 let linknentry text key =
2494 if key >= 32 && key < 127
2500 let text = addchar text c in
2504 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2509 if String.length
s > 0
2512 let l = String.length
s in
2513 let rec loop pos
n = if pos
= l then n else
2514 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2515 loop (pos
+1) (n*26 + m)
2518 let rec loop n = function
2521 match getopaque l.pageno with
2522 | None
-> loop n rest
2524 let m = getlinkcount opaque
in
2527 let under = getlink opaque
n in
2530 else loop (n-m) rest
2532 loop n state.layout;
2536 let textentry text key =
2537 if key land 0xff00 = 0xff00
2539 else TEcont
(text ^
Wsi.toutf8
key)
2542 let reqlayout angle proportional
=
2543 match state.throttle
with
2545 if nogeomcmds state.geomcmds
2546 then state.anchor <- getanchor ();
2547 conf.angle
<- angle
mod 360;
2550 match state.mode
with
2551 | LinkNav _
-> state.mode
<- View
2554 conf.proportional
<- proportional
;
2555 invalidate "reqlayout"
2556 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2560 let settrim trimmargins trimfuzz
=
2561 if nogeomcmds state.geomcmds
2562 then state.anchor <- getanchor ();
2563 conf.trimmargins
<- trimmargins
;
2564 conf.trimfuzz
<- trimfuzz
;
2565 let x0, y0, x1, y1 = trimfuzz
in
2566 invalidate "settrim"
2568 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2569 Hashtbl.iter
(fun _ opaque
->
2570 wcmd "freepage %s" opaque
;
2572 Hashtbl.clear
state.pagemap
;
2576 match state.throttle
with
2578 let zoom = max
0.01 zoom in
2579 if zoom <> conf.zoom
2581 state.prevzoom
<- conf.zoom;
2583 reshape conf.winw
conf.winh
;
2584 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2587 | Some
(layout, y, started
) ->
2589 match conf.maxwait
with
2593 let dt = now () -. started
in
2601 let setcolumns mode columns coverA coverB
=
2602 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2606 then showtext '
!'
"split mode doesn't work in bird's eye"
2608 conf.columns
<- Csplit
(-columns
, [||]);
2616 conf.columns
<- Csingle
;
2621 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2625 reshape conf.winw
conf.winh
;
2628 let enterbirdseye () =
2629 let zoom = float conf.thumbw
/. float conf.winw
in
2630 let birdseyepageno =
2631 let cy = conf.winh
/ 2 in
2635 let rec fold best
= function
2638 let d = cy - (l.pagedispy + l.pagevh/2)
2639 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2640 if abs
d < abs dbest
2647 state.mode
<- Birdseye
(
2648 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2651 conf.presentation <- false;
2652 conf.interpagespace <- 10;
2653 conf.hlinks
<- false;
2655 state.mstate
<- Mnone
;
2656 conf.maxwait
<- None
;
2658 match conf.beyecolumns
with
2661 Cmulti
((c, 0, 0), [||])
2664 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2667 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2672 reshape conf.winw
conf.winh
;
2675 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2677 conf.zoom <- c.zoom;
2678 conf.presentation <- c.presentation;
2679 conf.interpagespace <- c.interpagespace;
2680 conf.maxwait
<- c.maxwait
;
2681 conf.hlinks
<- c.hlinks
;
2682 conf.beyecolumns
<- (
2683 match conf.columns
with
2684 | Cmulti
((c, _
, _
), _
) -> Some
c
2686 | Csplit _
-> failwith
"leaving bird's eye split mode"
2689 match c.columns
with
2690 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2691 | Csingle
-> Csingle
2692 | Csplit
(c, _
) -> Csplit
(c, [||])
2697 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2700 reshape conf.winw
conf.winh
;
2701 state.anchor <- if goback
then anchor else (pageno, 0.0);
2704 let togglebirdseye () =
2705 match state.mode
with
2706 | Birdseye vals
-> leavebirdseye vals
true
2707 | View
-> enterbirdseye ()
2711 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2712 let pageno = max
0 (pageno - incr
) in
2713 let rec loop = function
2714 | [] -> gotopage1 pageno 0
2715 | l :: _
when l.pageno = pageno ->
2716 if l.pagedispy >= 0 && l.pagey = 0
2717 then G.postRedisplay "upbirdseye"
2718 else gotopage1 pageno 0
2719 | _
:: rest
-> loop rest
2722 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2725 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2726 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2727 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2728 let rec loop = function
2730 let y, h = getpageyh pageno in
2731 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2733 | l :: _
when l.pageno = pageno ->
2734 if l.pagevh != l.pageh
2735 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2736 else G.postRedisplay "downbirdseye"
2737 | _
:: rest
-> loop rest
2742 let optentry mode _
key =
2743 let btos b = if b then "on" else "off" in
2744 if key >= 32 && key < 127
2746 let c = Char.chr
key in
2750 try conf.scrollstep
<- int_of_string
s with exc
->
2751 state.text <- Printf.sprintf
"bad integer `%s': %s"
2752 s (Printexc.to_string exc
)
2754 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2759 conf.autoscrollstep
<- int_of_string
s;
2760 if state.autoscroll
<> None
2761 then state.autoscroll
<- Some
conf.autoscrollstep
2763 state.text <- Printf.sprintf
"bad integer `%s': %s"
2764 s (Printexc.to_string exc
)
2766 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2771 let n, a, b = multicolumns_of_string s in
2772 setcolumns mode
n a b;
2774 state.text <- Printf.sprintf
"bad columns `%s': %s"
2775 s (Printexc.to_string exc
)
2777 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2782 let zoom = float (int_of_string
s) /. 100.0 in
2785 state.text <- Printf.sprintf
"bad integer `%s': %s"
2786 s (Printexc.to_string exc
)
2788 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2793 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2795 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2796 begin match mode
with
2798 leavebirdseye beye
false;
2803 state.text <- Printf.sprintf
"bad integer `%s': %s"
2804 s (Printexc.to_string exc
)
2806 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2811 Some
(int_of_string
s)
2813 state.text <- Printf.sprintf
"bad integer `%s': %s"
2814 s (Printexc.to_string exc
);
2817 | Some angle
-> reqlayout angle
conf.proportional
2820 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2823 conf.icase
<- not
conf.icase
;
2824 TEdone
("case insensitive search " ^
(btos conf.icase
))
2827 conf.preload <- not
conf.preload;
2829 TEdone
("preload " ^
(btos conf.preload))
2832 conf.verbose
<- not
conf.verbose
;
2833 TEdone
("verbose " ^
(btos conf.verbose
))
2836 conf.debug
<- not
conf.debug
;
2837 TEdone
("debug " ^
(btos conf.debug
))
2840 conf.maxhfit
<- not
conf.maxhfit
;
2841 state.maxy <- calcheight ();
2842 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2845 conf.crophack
<- not
conf.crophack
;
2846 TEdone
("crophack " ^
btos conf.crophack
)
2850 match conf.maxwait
with
2852 conf.maxwait
<- Some infinity
;
2853 "always wait for page to complete"
2855 conf.maxwait
<- None
;
2856 "show placeholder if page is not ready"
2861 conf.underinfo
<- not
conf.underinfo
;
2862 TEdone
("underinfo " ^
btos conf.underinfo
)
2865 conf.savebmarks
<- not
conf.savebmarks
;
2866 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2872 match state.layout with
2877 conf.interpagespace <- int_of_string
s;
2878 docolumns conf.columns
;
2879 state.maxy <- calcheight ();
2880 let y = getpagey pageno in
2883 state.text <- Printf.sprintf
"bad integer `%s': %s"
2884 s (Printexc.to_string exc
)
2886 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2889 reqlayout conf.angle
(not
conf.proportional
);
2890 TEdone
("proportional display " ^
btos conf.proportional
)
2893 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2894 TEdone
("trim margins " ^
btos conf.trimmargins
)
2897 conf.invert
<- not
conf.invert
;
2898 TEdone
("invert colors " ^
btos conf.invert
)
2902 cbput state.hists
.sel
s;
2905 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2906 textentry, ondone, true)
2909 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2915 class type lvsource
= object
2916 method getitemcount
: int
2917 method getitem
: int -> (string * int)
2918 method hasaction
: int -> bool
2927 method getactive
: int
2928 method getfirst
: int
2929 method getqsearch
: string
2930 method setqsearch
: string -> unit
2934 class virtual lvsourcebase
= object
2935 val mutable m_active
= 0
2936 val mutable m_first
= 0
2937 val mutable m_qsearch
= ""
2938 val mutable m_pan
= 0
2939 method getactive
= m_active
2940 method getfirst
= m_first
2941 method getqsearch
= m_qsearch
2942 method getpan
= m_pan
2943 method setqsearch
s = m_qsearch
<- s
2946 let withoutlastutf8 s =
2947 let len = String.length
s in
2955 let b = Char.code
s.[pos
] in
2956 if b land 0b110000 = 0b11000000
2961 if Char.code
s.[len-1] land 0x80 = 0
2965 String.sub
s 0 first;
2968 let textentrykeyboard
2969 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2971 state.mode
<- Textentry
(te
, onleave
);
2974 G.postRedisplay "textentrykeyboard enttext";
2976 let histaction cmd
=
2979 | Some
(action, _
) ->
2980 state.mode
<- Textentry
(
2981 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2983 G.postRedisplay "textentry histaction"
2986 | 0xff08 -> (* backspace *)
2987 let s = withoutlastutf8 text in
2988 let len = String.length
s in
2989 if cancelonempty
&& len = 0
2992 G.postRedisplay "textentrykeyboard after cancel";
2995 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3001 G.postRedisplay "textentrykeyboard after confirm"
3003 | 0xff52 -> histaction HCprev
3004 | 0xff54 -> histaction HCnext
3005 | 0xff50 -> histaction HCfirst
3006 | 0xff57 -> histaction HClast
3008 | 0xff1b -> (* escape*)
3009 if String.length
text = 0
3011 begin match opthist
with
3013 | Some
(_
, onhistcancel
) -> onhistcancel
()
3017 G.postRedisplay "textentrykeyboard after cancel2"
3020 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3023 | 0xff9f | 0xffff -> () (* delete *)
3025 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3026 begin match onkey
text key with
3030 G.postRedisplay "textentrykeyboard after confirm2";
3033 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3037 G.postRedisplay "textentrykeyboard after cancel3"
3040 state.mode
<- Textentry
(te
, onleave
);
3041 G.postRedisplay "textentrykeyboard switch";
3045 vlog "unhandled key %s" (Wsi.keyname
key)
3048 let firstof first active
=
3049 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3050 then max
0 (active
- (fstate.maxrows
/2))
3054 let calcfirst first active
=
3057 let rows = active
- first in
3058 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3062 let scrollph y maxy =
3063 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3064 let sh = float conf.winh
/. sh in
3065 let sh = max
sh (float conf.scrollh
) in
3070 else float y /. float maxy
3072 let position = (float conf.winh
-. sh) *. percent in
3075 if position +. sh > float conf.winh
3076 then float conf.winh
-. sh
3082 let coe s = (s :> uioh
);;
3084 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3086 val m_pan
= source#getpan
3087 val m_first
= source#getfirst
3088 val m_active
= source#getactive
3089 val m_qsearch
= source#getqsearch
3090 val m_prev_uioh
= state.uioh
3092 method private elemunder
y =
3093 let n = y / (fstate.fontsize
+1) in
3094 if m_first
+ n < source#getitemcount
3096 if source#hasaction
(m_first
+ n)
3097 then Some
(m_first
+ n)
3104 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3105 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3106 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3107 GlDraw.color
(1., 1., 1.);
3108 Gl.enable `texture_2d
;
3109 let fs = fstate.fontsize
in
3111 let ww = fstate.wwidth
in
3112 let tabw = 30.0*.ww in
3113 let itemcount = source#getitemcount
in
3115 if (row - m_first
) * nfs > conf.winh
3118 if row >= 0 && row < itemcount
3120 let (s, level
) = source#getitem
row in
3121 let y = (row - m_first
) * nfs in
3122 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3125 Gl.disable `texture_2d
;
3126 GlDraw.polygon_mode `both `line
;
3127 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3128 GlDraw.rect (1., float (y + 1))
3129 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3130 GlDraw.polygon_mode `both `fill
;
3131 GlDraw.color
(1., 1., 1.);
3132 Gl.enable `texture_2d
;
3135 let drawtabularstring s =
3136 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3139 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3142 let len = String.length
s - tabpos - 1 in
3143 let s1 = String.sub
s 0 tabpos
3144 and s2
= String.sub
s (tabpos + 1) len in
3145 let nx = drawstr x s1 in
3147 let x = x +. (max
tabw sw) in
3154 let _ = drawtabularstring s in
3161 Gl.disable `texture_2d
;
3163 method updownlevel incr
=
3164 let len = source#getitemcount
in
3166 if m_active
>= 0 && m_active
< len
3167 then snd
(source#getitem m_active
)
3171 if i
= len then i
-1 else if i
= -1 then 0 else
3172 let _, l = source#getitem i
in
3173 if l != curlevel then i
else flow (i
+incr
)
3175 let active = flow m_active
in
3176 let first = calcfirst m_first
active in
3177 G.postRedisplay "outline updownlevel";
3178 {< m_active
= active; m_first
= first >}
3180 method private key1
key mask
=
3181 let set1 active first qsearch
=
3182 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3184 let search active pattern incr
=
3187 if n >= 0 && n < source#getitemcount
3189 let s, _ = source#getitem
n in
3191 (try ignore
(Str.search_forward
re s 0); true
3192 with Not_found
-> false)
3194 else loop (n + incr
)
3201 let re = Str.regexp_case_fold pattern
in
3207 let itemcount = source#getitemcount
in
3208 let find start incr
=
3210 if i
= -1 || i
= itemcount
3213 if source#hasaction i
3215 else find (i
+ incr
)
3220 let set active first =
3221 let first = bound first 0 (itemcount - fstate.maxrows
) in
3223 coe {< m_active
= active; m_first
= first >}
3226 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3228 let incr1 = if incr
> 0 then 1 else -1 in
3229 if isvisible m_first m_active
3232 let next = m_active
+ incr
in
3234 if next < 0 || next >= itemcount
3236 else find next incr1
3238 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3244 let first = m_first
+ incr
in
3245 let first = bound first 0 (itemcount - 1) in
3247 let next = m_active
+ incr
in
3248 let next = bound next 0 (itemcount - 1) in
3251 let active = if next = -1 then m_active
else next in
3254 let first = min
next m_first
in
3256 if abs
(next - first) > fstate.maxrows
3262 let first = m_first
+ incr
in
3263 let first = bound first 0 (itemcount - 1) in
3265 let next = m_active
+ incr
in
3266 let next = bound next 0 (itemcount - 1) in
3267 let next = find next incr1 in
3269 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3271 let active = if m_active
= -1 then next else m_active
in
3276 if isvisible first active
3282 G.postRedisplay "listview navigate";
3286 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3287 let incr = if key = 0x72 then -1 else 1 in
3289 match search (m_active
+ incr) m_qsearch
incr with
3291 state.text <- m_qsearch ^
" [not found]";
3294 state.text <- m_qsearch
;
3295 active, firstof m_first
active
3297 G.postRedisplay "listview ctrl-r/s";
3298 set1 active first m_qsearch
;
3300 | 0xff08 -> (* backspace *)
3301 if String.length m_qsearch
= 0
3304 let qsearch = withoutlastutf8 m_qsearch
in
3305 let len = String.length
qsearch in
3309 G.postRedisplay "listview empty qsearch";
3310 set1 m_active m_first
"";
3314 match search m_active
qsearch ~
-1 with
3316 state.text <- qsearch ^
" [not found]";
3319 state.text <- qsearch;
3320 active, firstof m_first
active
3322 G.postRedisplay "listview backspace qsearch";
3323 set1 active first qsearch
3326 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3327 let pattern = m_qsearch ^
Wsi.toutf8
key in
3329 match search m_active
pattern 1 with
3331 state.text <- pattern ^
" [not found]";
3334 state.text <- pattern;
3335 active, firstof m_first
active
3337 G.postRedisplay "listview qsearch add";
3338 set1 active first pattern;
3340 | 0xff1b -> (* escape *)
3342 if String.length m_qsearch
= 0
3344 G.postRedisplay "list view escape";
3347 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3349 | None
-> m_prev_uioh
3354 G.postRedisplay "list view kill qsearch";
3355 source#setqsearch
"";
3356 coe {< m_qsearch
= "" >}
3359 | 0xff0d -> (* return *)
3361 let self = {< m_qsearch
= "" >} in
3362 source#setqsearch
"";
3364 G.postRedisplay "listview enter";
3365 if m_active
>= 0 && m_active
< source#getitemcount
3367 source#exit
(coe self) false m_active m_first m_pan
"";
3370 source#exit
(coe self) true m_active m_first m_pan
"";
3373 begin match opt with
3374 | None
-> m_prev_uioh
3378 | 0xff9f | 0xffff -> (* delete *)
3381 | 0xff52 -> navigate ~
-1 (* up *)
3382 | 0xff54 -> navigate 1 (* down *)
3383 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3384 | 0xff56 -> navigate fstate.maxrows
(* next *)
3386 | 0xff53 -> (* right *)
3388 G.postRedisplay "listview right";
3389 coe {< m_pan
= m_pan
- 1 >}
3391 | 0xff51 -> (* left *)
3393 G.postRedisplay "listview left";
3394 coe {< m_pan
= m_pan
+ 1 >}
3396 | 0xff50 -> (* home *)
3397 let active = find 0 1 in
3398 G.postRedisplay "listview home";
3401 | 0xff57 -> (* end *)
3402 let first = max
0 (itemcount - fstate.maxrows
) in
3403 let active = find (itemcount - 1) ~
-1 in
3404 G.postRedisplay "listview end";
3407 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3411 dolog "listview unknown key %#x" key; coe self
3413 method key key mask
=
3414 match state.mode
with
3415 | Textentry te
-> textentrykeyboard key mask te
; coe self
3416 | _ -> self#key1
key mask
3418 method button button down
x y _ =
3421 | 1 when x > conf.winw
- conf.scrollbw
->
3422 G.postRedisplay "listview scroll";
3425 let _, position, sh = self#
scrollph in
3426 if y > truncate
position && y < truncate
(position +. sh)
3428 state.mstate
<- Mscrolly
;
3432 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3433 let first = truncate
(s *. float source#getitemcount
) in
3434 let first = min source#getitemcount
first in
3435 Some
(coe {< m_first
= first; m_active
= first >})
3437 state.mstate
<- Mnone
;
3440 | 1 when not down
->
3441 begin match self#elemunder
y with
3443 G.postRedisplay "listview click";
3445 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3449 | n when (n == 4 || n == 5) && not down
->
3450 let len = source#getitemcount
in
3452 if n = 5 && m_first
+ fstate.maxrows
>= len
3456 let first = m_first
+ (if n == 4 then -1 else 1) in
3457 bound first 0 (len - 1)
3459 G.postRedisplay "listview wheel";
3460 Some
(coe {< m_first
= first >})
3465 | None
-> m_prev_uioh
3469 match state.mstate
with
3471 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3472 let first = truncate
(s *. float source#getitemcount
) in
3473 let first = min source#getitemcount
first in
3474 G.postRedisplay "listview motion";
3475 coe {< m_first
= first; m_active
= first >}
3478 method pmotion
x y =
3479 if x < conf.winw
- conf.scrollbw
3482 match self#elemunder
y with
3483 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3484 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3488 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3493 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3497 method infochanged
_ = ()
3499 method scrollpw
= (0, 0.0, 0.0)
3501 let nfs = fstate.fontsize
+ 1 in
3502 let y = m_first
* nfs in
3503 let itemcount = source#getitemcount
in
3504 let maxi = max
0 (itemcount - fstate.maxrows
) in
3505 let maxy = maxi * nfs in
3506 let p, h = scrollph y maxy in
3509 method modehash
= modehash
3512 class outlinelistview ~source
=
3515 ~source
:(source
:> lvsource
)
3517 ~modehash
:(findkeyhash conf "outline")
3520 method key key mask
=
3521 let calcfirst first active =
3524 let rows = active - first in
3525 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3529 let active = m_active
+ incr in
3530 let active = bound active 0 (source#getitemcount
- 1) in
3531 let first = calcfirst m_first
active in
3532 G.postRedisplay "outline navigate";
3533 coe {< m_active
= active; m_first
= first >}
3535 let ctrl = Wsi.withctrl mask
in
3537 | 110 when ctrl -> (* ctrl-n *)
3538 source#narrow m_qsearch
;
3539 G.postRedisplay "outline ctrl-n";
3540 coe {< m_first
= 0; m_active
= 0 >}
3542 | 117 when ctrl -> (* ctrl-u *)
3544 G.postRedisplay "outline ctrl-u";
3546 coe {< m_first
= 0; m_active
= 0 >}
3548 | 108 when ctrl -> (* ctrl-l *)
3549 let first = m_active
- (fstate.maxrows
/ 2) in
3550 G.postRedisplay "outline ctrl-l";
3551 coe {< m_first
= first >}
3553 | 0xff9f | 0xffff -> (* delete *)
3554 source#remove m_active
;
3555 G.postRedisplay "outline delete";
3556 let active = max
0 (m_active
-1) in
3557 coe {< m_first
= firstof m_first
active;
3558 m_active
= active >}
3560 | 0xff52 -> navigate ~
-1 (* up *)
3561 | 0xff54 -> navigate 1 (* down *)
3562 | 0xff55 -> (* prior *)
3563 navigate ~
-(fstate.maxrows
)
3564 | 0xff56 -> (* next *)
3565 navigate fstate.maxrows
3567 | 0xff53 -> (* [ctrl-]right *)
3571 G.postRedisplay "outline ctrl right";
3572 {< m_pan
= m_pan
+ 1 >}
3574 else self#updownlevel
1
3578 | 0xff51 -> (* [ctrl-]left *)
3582 G.postRedisplay "outline ctrl left";
3583 {< m_pan
= m_pan
- 1 >}
3585 else self#updownlevel ~
-1
3589 | 0xff50 -> (* home *)
3590 G.postRedisplay "outline home";
3591 coe {< m_first
= 0; m_active
= 0 >}
3593 | 0xff57 -> (* end *)
3594 let active = source#getitemcount
- 1 in
3595 let first = max
0 (active - fstate.maxrows
) in
3596 G.postRedisplay "outline end";
3597 coe {< m_active
= active; m_first
= first >}
3599 | _ -> super#
key key mask
3602 let outlinesource usebookmarks
=
3605 inherit lvsourcebase
3606 val mutable m_items
= empty
3607 val mutable m_orig_items
= empty
3608 val mutable m_prev_items
= empty
3609 val mutable m_narrow_pattern
= ""
3610 val mutable m_hadremovals
= false
3612 method getitemcount
=
3613 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3616 if n == Array.length m_items
&& m_hadremovals
3618 ("[Confirm removal]", 0)
3620 let s, n, _ = m_items
.(n) in
3623 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3624 ignore
(uioh
, first, qsearch);
3625 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3627 if String.length m_narrow_pattern
= 0
3633 if not
confrimremoval
3635 let _, _, anchor = m_items
.(active) in
3640 state.bookmarks
<- Array.to_list m_items
;
3641 m_orig_items
<- m_items
;
3644 else m_items
<- items;
3648 method hasaction
_ = true
3651 if Array.length m_items
!= Array.length m_orig_items
3652 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3655 method narrow
pattern =
3656 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3660 let rec loop accu n =
3663 m_narrow_pattern
<- pattern;
3664 m_items
<- Array.of_list
accu
3667 let (s, _, _) as o = m_items
.(n) in
3669 if (try ignore
(Str.search_forward
re s 0); true
3670 with Not_found
-> false)
3676 loop [] (Array.length m_items
- 1)
3681 then Array.of_list
state.bookmarks
3684 m_items
<- m_orig_items
3689 if m >= 0 && m < Array.length m_items
3691 m_hadremovals
<- true;
3692 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3693 let n = if n >= m then n+1 else n in
3698 method reset
anchor items =
3699 m_hadremovals
<- false;
3700 if m_orig_items
== empty || m_prev_items
!= items
3702 m_orig_items
<- items;
3703 if String.length m_narrow_pattern
= 0
3704 then m_items
<- items;
3706 m_prev_items
<- items;
3707 let rely = getanchory anchor in
3709 let rec loop n best bestd
=
3710 if n = Array.length m_items
3713 let (_, _, anchor) = m_items
.(n) in
3714 let orely = getanchory anchor in
3715 let d = abs
(orely - rely) in
3718 else loop (n+1) best bestd
3723 m_first
<- firstof m_first
active
3727 let enterselector usebookmarks
=
3728 let source = outlinesource usebookmarks
in
3732 then Array.of_list
state.bookmarks
3735 if Array.length
outlines = 0
3737 showtext ' ' errmsg
;
3740 state.text <- source#greetmsg
;
3741 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3742 let anchor = getanchor () in
3743 source#reset
anchor outlines;
3744 state.uioh
<- coe (new outlinelistview ~
source);
3745 G.postRedisplay "enter selector";
3749 let enteroutlinemode =
3750 let f = enterselector false in
3751 fun ()-> f "Document has no outline";
3754 let enterbookmarkmode =
3755 let f = enterselector true in
3756 fun () -> f "Document has no bookmarks (yet)";
3759 let color_of_string s =
3760 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3761 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3765 let color_to_string (r
, g
, b) =
3766 let r = truncate
(r *. 256.0)
3767 and g
= truncate
(g
*. 256.0)
3768 and b = truncate
(b *. 256.0) in
3769 Printf.sprintf
"%d/%d/%d" r g
b
3772 let irect_of_string s =
3773 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3776 let irect_to_string (x0,y0,x1,y1) =
3777 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3780 let makecheckers () =
3781 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3783 converted by Issac Trotts. July 25, 2002 *)
3784 let image_height = 64
3785 and image_width
= 64 in
3789 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3791 for i
= 0 to image_width
- 1 do
3792 for j
= 0 to image_height - 1 do
3793 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3794 (if (i
land 8 ) lxor (j
land 8) = 0
3795 then [|255;255;255|] else [|200;200;200|])
3800 let image = make_image () in
3801 let id = GlTex.gen_texture
() in
3802 GlTex.bind_texture `texture_2d
id;
3803 GlPix.store
(`unpack_alignment
1);
3804 GlTex.image2d
image;
3805 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3808 `mag_filter `nearest
;
3809 `min_filter `nearest
];
3813 let setcheckers enabled
=
3814 match state.texid
with
3816 if enabled
then state.texid
<- Some
(makecheckers ())
3821 GlTex.delete_texture texid
;
3822 state.texid
<- None
;
3826 let int_of_string_with_suffix s =
3827 let l = String.length
s in
3831 let suffix = Char.lowercase
s.[l-1] in
3833 | 'k'
-> String.sub
s 0 (l-1), 10
3834 | '
m'
-> String.sub
s 0 (l-1), 20
3835 | 'g'
-> String.sub
s 0 (l-1), 30
3839 let n = int_of_string
s1 in
3840 let m = n lsl shift
in
3842 then raise
(Failure
"value too large")
3846 let string_with_suffix_of_int n =
3854 if n land ((1 lsl 20) - 1) = 0
3857 if n land ((1 lsl 10) - 1) = 0
3864 let h = n mod 1000 in
3867 then string_of_int
h ^
s
3869 let s = Printf.sprintf
"_%03d%s" h s in
3876 let defghyllscroll = (40, 8, 32);;
3877 let ghyllscroll_of_string s =
3878 let (n, a, b) as nab
=
3881 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3883 if n <= a || n <= b || a >= b
3884 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3888 let ghyllscroll_to_string ((n, a, b) as nab
) =
3889 if nab
= defghyllscroll
3891 else Printf.sprintf
"%d,%d,%d" n a b;
3894 let describe_location () =
3896 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3898 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3899 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3903 else (100. *. (float state.y /. float maxy))
3907 Printf.sprintf
"page %d of %d [%.2f%%]"
3908 (fn+1) state.pagecount
percent
3911 "pages %d-%d of %d [%.2f%%]"
3912 (fn+1) (ln
+1) state.pagecount
percent
3916 let btos b = if b then "\xe2\x88\x9a" else "" in
3917 let showextended = ref false in
3918 let leave mode
= function
3919 | Confirm
-> state.mode
<- mode
3920 | Cancel
-> state.mode
<- mode
in
3923 val mutable m_first_time
= true
3924 val mutable m_l
= []
3925 val mutable m_a
= [||]
3926 val mutable m_prev_uioh
= nouioh
3927 val mutable m_prev_mode
= View
3929 inherit lvsourcebase
3931 method reset prev_mode prev_uioh
=
3932 m_a
<- Array.of_list
(List.rev m_l
);
3934 m_prev_mode
<- prev_mode
;
3935 m_prev_uioh
<- prev_uioh
;
3939 if n >= Array.length m_a
3943 | _, _, _, Action
_ -> m_active
<- n
3947 m_first_time
<- false;
3950 method int name get
set =
3952 (name
, `
int get
, 1, Action
(
3955 try set (int_of_string
s)
3957 state.text <- Printf.sprintf
"bad integer `%s': %s"
3958 s (Printexc.to_string exn
)
3961 let te = name ^
": ", "", None
, intentry, ondone, true in
3962 state.mode
<- Textentry
(te, leave m_prev_mode
);
3966 method int_with_suffix name get
set =
3968 (name
, `intws get
, 1, Action
(
3971 try set (int_of_string_with_suffix s)
3973 state.text <- Printf.sprintf
"bad integer `%s': %s"
3974 s (Printexc.to_string exn
)
3978 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3980 state.mode
<- Textentry
(te, leave m_prev_mode
);
3984 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3986 (name
, `
bool (btos, get
), offset
, Action
(
3993 method color name get
set =
3995 (name
, `color get
, 1, Action
(
3997 let invalid = (nan
, nan
, nan
) in
4000 try color_of_string s
4002 state.text <- Printf.sprintf
"bad color `%s': %s"
4003 s (Printexc.to_string exn
);
4009 let te = name ^
": ", "", None
, textentry, ondone, true in
4010 state.text <- color_to_string (get
());
4011 state.mode
<- Textentry
(te, leave m_prev_mode
);
4015 method string name get
set =
4017 (name
, `
string get
, 1, Action
(
4019 let ondone s = set s in
4020 let te = name ^
": ", "", None
, textentry, ondone, true in
4021 state.mode
<- Textentry
(te, leave m_prev_mode
);
4025 method colorspace name get
set =
4027 (name
, `
string get
, 1, Action
(
4030 let vals = [| "rgb"; "bgr"; "gray" |] in
4032 inherit lvsourcebase
4035 m_active
<- int_of_colorspace conf.colorspace
;
4038 method getitemcount
= Array.length
vals
4039 method getitem
n = (vals.(n), 0)
4040 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4041 ignore
(uioh
, first, pan
, qsearch);
4042 if not cancel
then set active;
4044 method hasaction
_ = true
4048 let modehash = findkeyhash conf "info" in
4049 coe (new listview ~
source ~trusted
:true ~
modehash)
4052 method caption
s offset
=
4053 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4055 method caption2
s f offset
=
4056 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4058 method getitemcount
= Array.length m_a
4061 let tostr = function
4062 | `
int f -> string_of_int
(f ())
4063 | `intws
f -> string_with_suffix_of_int (f ())
4065 | `color
f -> color_to_string (f ())
4066 | `
bool (btos, f) -> btos (f ())
4069 let name, t
, offset
, _ = m_a
.(n) in
4070 ((let s = tostr t
in
4071 if String.length
s > 0
4072 then Printf.sprintf
"%s\t%s" name s
4076 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4080 m_qsearch
<- qsearch;
4082 match m_a
.(active) with
4083 | _, _, _, Action
f -> f uioh
4095 method hasaction
n =
4097 | _, _, _, Action
_ -> true
4101 let rec fillsrc prevmode prevuioh
=
4102 let sep () = src#caption
"" 0 in
4103 let colorp name get
set =
4105 (fun () -> color_to_string (get
()))
4108 let c = color_of_string v in
4111 state.text <- Printf.sprintf
"bad color `%s': %s"
4112 v (Printexc.to_string exn
);
4115 let oldmode = state.mode
in
4116 let birdseye = isbirdseye state.mode
in
4118 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4120 src#
bool "presentation mode"
4121 (fun () -> conf.presentation)
4123 conf.presentation <- v;
4124 state.anchor <- getanchor ();
4127 src#
bool "ignore case in searches"
4128 (fun () -> conf.icase
)
4129 (fun v -> conf.icase
<- v);
4132 (fun () -> conf.preload)
4133 (fun v -> conf.preload <- v);
4135 src#
bool "highlight links"
4136 (fun () -> conf.hlinks
)
4137 (fun v -> conf.hlinks
<- v);
4139 src#
bool "under info"
4140 (fun () -> conf.underinfo
)
4141 (fun v -> conf.underinfo
<- v);
4143 src#
bool "persistent bookmarks"
4144 (fun () -> conf.savebmarks
)
4145 (fun v -> conf.savebmarks
<- v);
4147 src#
bool "proportional display"
4148 (fun () -> conf.proportional
)
4149 (fun v -> reqlayout conf.angle
v);
4151 src#
bool "trim margins"
4152 (fun () -> conf.trimmargins
)
4153 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4155 src#
bool "persistent location"
4156 (fun () -> conf.jumpback
)
4157 (fun v -> conf.jumpback
<- v);
4160 src#
int "inter-page space"
4161 (fun () -> conf.interpagespace)
4163 conf.interpagespace <- n;
4164 docolumns conf.columns
;
4166 match state.layout with
4171 state.maxy <- calcheight ();
4172 let y = getpagey pageno in
4177 (fun () -> conf.pagebias
)
4178 (fun v -> conf.pagebias
<- v);
4180 src#
int "scroll step"
4181 (fun () -> conf.scrollstep
)
4182 (fun n -> conf.scrollstep
<- n);
4184 src#
int "auto scroll step"
4186 match state.autoscroll
with
4188 | _ -> conf.autoscrollstep
)
4190 if state.autoscroll
<> None
4191 then state.autoscroll
<- Some
n;
4192 conf.autoscrollstep
<- n);
4195 (fun () -> truncate
(conf.zoom *. 100.))
4196 (fun v -> setzoom ((float v) /. 100.));
4199 (fun () -> conf.angle
)
4200 (fun v -> reqlayout v conf.proportional
);
4202 src#
int "scroll bar width"
4203 (fun () -> state.scrollw
)
4207 reshape conf.winw
conf.winh
;
4210 src#
int "scroll handle height"
4211 (fun () -> conf.scrollh
)
4212 (fun v -> conf.scrollh
<- v;);
4214 src#
int "thumbnail width"
4215 (fun () -> conf.thumbw
)
4217 conf.thumbw
<- min
4096 v;
4220 leavebirdseye beye
false;
4225 let mode = state.mode in
4226 src#
string "columns"
4228 match conf.columns
with
4230 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4231 | Csplit
(count
, _) -> "-" ^ string_of_int count
4234 let n, a, b = multicolumns_of_string v in
4235 setcolumns mode n a b);
4238 src#caption
"Presentation mode" 0;
4239 src#
bool "scrollbar visible"
4240 (fun () -> conf.scrollbarinpm
)
4242 if v != conf.scrollbarinpm
4244 conf.scrollbarinpm
<- v;
4245 if conf.presentation
4247 state.scrollw
<- if v then conf.scrollbw
else 0;
4248 reshape conf.winw
conf.winh
;
4254 src#caption
"Pixmap cache" 0;
4255 src#int_with_suffix
"size (advisory)"
4256 (fun () -> conf.memlimit
)
4257 (fun v -> conf.memlimit
<- v);
4260 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4261 (string_with_suffix_of_int state.memused
)
4262 (Hashtbl.length
state.tilemap
)) 1;
4265 src#caption
"Layout" 0;
4266 src#caption2
"Dimension"
4268 Printf.sprintf
"%dx%d (virtual %dx%d)"
4274 src#caption2
"Position" (fun () ->
4275 Printf.sprintf
"%dx%d" state.x state.y
4278 src#caption2
"Visible" (fun () -> describe_location ()) 1
4282 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4283 "Save these parameters as global defaults at exit"
4284 (fun () -> conf.bedefault
)
4285 (fun v -> conf.bedefault
<- v)
4289 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4290 src#
bool ~offset
:0 ~
btos "Extended parameters"
4291 (fun () -> !showextended)
4292 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4296 (fun () -> conf.checkers
)
4297 (fun v -> conf.checkers
<- v; setcheckers v);
4298 src#
bool "update cursor"
4299 (fun () -> conf.updatecurs
)
4300 (fun v -> conf.updatecurs
<- v);
4302 (fun () -> conf.verbose
)
4303 (fun v -> conf.verbose
<- v);
4304 src#
bool "invert colors"
4305 (fun () -> conf.invert
)
4306 (fun v -> conf.invert
<- v);
4308 (fun () -> conf.maxhfit
)
4309 (fun v -> conf.maxhfit
<- v);
4310 src#
bool "redirect stderr"
4311 (fun () -> conf.redirectstderr)
4312 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4313 src#
string "uri launcher"
4314 (fun () -> conf.urilauncher
)
4315 (fun v -> conf.urilauncher
<- v);
4316 src#
string "path launcher"
4317 (fun () -> conf.pathlauncher
)
4318 (fun v -> conf.pathlauncher
<- v);
4319 src#
string "tile size"
4320 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4323 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4324 conf.tilew
<- max
64 w;
4325 conf.tileh
<- max
64 h;
4328 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4329 v (Printexc.to_string exn
));
4330 src#
int "texture count"
4331 (fun () -> conf.texcount
)
4334 then conf.texcount
<- v
4335 else showtext '
!'
" Failed to set texture count please retry later"
4337 src#
int "slice height"
4338 (fun () -> conf.sliceheight
)
4340 conf.sliceheight
<- v;
4341 wcmd "sliceh %d" conf.sliceheight
;
4343 src#
int "anti-aliasing level"
4344 (fun () -> conf.aalevel
)
4346 conf.aalevel
<- bound v 0 8;
4347 state.anchor <- getanchor ();
4348 opendoc state.path
state.password
;
4350 src#
int "ui font size"
4351 (fun () -> fstate.fontsize
)
4352 (fun v -> setfontsize (bound v 5 100));
4353 src#
int "hint font size"
4354 (fun () -> conf.hfsize
)
4355 (fun v -> conf.hfsize
<- bound v 5 100);
4356 colorp "background color"
4357 (fun () -> conf.bgcolor
)
4358 (fun v -> conf.bgcolor
<- v);
4359 src#
bool "crop hack"
4360 (fun () -> conf.crophack
)
4361 (fun v -> conf.crophack
<- v);
4362 src#
string "trim fuzz"
4363 (fun () -> irect_to_string conf.trimfuzz
)
4366 conf.trimfuzz
<- irect_of_string v;
4368 then settrim true conf.trimfuzz
;
4370 state.text <- Printf.sprintf
"bad irect `%s': %s"
4371 v (Printexc.to_string exn
)
4373 src#
string "throttle"
4375 match conf.maxwait
with
4376 | None
-> "show place holder if page is not ready"
4379 then "wait for page to fully render"
4381 "wait " ^ string_of_float
time
4382 ^
" seconds before showing placeholder"
4386 let f = float_of_string
v in
4388 then conf.maxwait
<- None
4389 else conf.maxwait
<- Some
f
4391 state.text <- Printf.sprintf
"bad time `%s': %s"
4392 v (Printexc.to_string exn
)
4394 src#
string "ghyll scroll"
4396 match conf.ghyllscroll
with
4398 | Some nab
-> ghyllscroll_to_string nab
4403 if String.length
v = 0
4405 else Some
(ghyllscroll_of_string v)
4407 conf.ghyllscroll
<- gs
4409 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4410 v (Printexc.to_string exn
)
4412 src#
string "selection command"
4413 (fun () -> conf.selcmd
)
4414 (fun v -> conf.selcmd
<- v);
4415 src#colorspace
"color space"
4416 (fun () -> colorspace_to_string conf.colorspace
)
4418 conf.colorspace
<- colorspace_of_int v;
4425 src#caption
"Document" 0;
4426 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4427 src#caption2
"Pages"
4428 (fun () -> string_of_int
state.pagecount
) 1;
4429 src#caption2
"Dimensions"
4430 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4434 src#caption
"Trimmed margins" 0;
4435 src#caption2
"Dimensions"
4436 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4439 src#reset prevmode prevuioh
;
4443 let prevmode = state.mode
4444 and prevuioh
= state.uioh in
4445 fillsrc prevmode prevuioh
;
4446 let source = (src :> lvsource
) in
4447 let modehash = findkeyhash conf "info" in
4448 state.uioh <- coe (object (self)
4449 inherit listview ~
source ~trusted
:true ~
modehash as super
4450 val mutable m_prevmemused
= 0
4451 method infochanged
= function
4453 if m_prevmemused
!= state.memused
4455 m_prevmemused
<- state.memused
;
4456 G.postRedisplay "memusedchanged";
4458 | Pdim
-> G.postRedisplay "pdimchanged"
4459 | Docinfo
-> fillsrc prevmode prevuioh
4461 method key key mask
=
4462 if not
(Wsi.withctrl mask
)
4465 | 0xff51 -> coe (self#updownlevel ~
-1)
4466 | 0xff53 -> coe (self#updownlevel
1)
4467 | _ -> super#
key key mask
4468 else super#
key key mask
4470 G.postRedisplay "info";
4476 inherit lvsourcebase
4477 method getitemcount
= Array.length
state.help
4479 let s, n, _ = state.help
.(n) in
4482 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4486 m_qsearch
<- qsearch;
4487 match state.help
.(active) with
4488 | _, _, Action
f -> Some
(f uioh)
4498 method hasaction
n =
4499 match state.help
.(n) with
4500 | _, _, Action
_ -> true
4507 let modehash = findkeyhash conf "help" in
4508 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4509 G.postRedisplay "help";
4514 let re = Str.regexp
"[\r\n]" in
4516 inherit lvsourcebase
4517 val mutable m_items
= [||]
4519 method getitemcount
= 1 + Array.length m_items
4524 else m_items
.(n-1), 0
4526 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4531 then Buffer.clear
state.errmsgs
;
4532 m_qsearch
<- qsearch;
4539 method hasaction
n =
4543 state.newerrmsgs
<- false;
4544 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4545 m_items
<- Array.of_list
l
4553 let source = (msgsource :> lvsource
) in
4554 let modehash = findkeyhash conf "listview" in
4555 state.uioh <- coe (object
4556 inherit listview ~
source ~trusted
:false ~
modehash as super
4559 then msgsource#reset
;
4562 G.postRedisplay "msgs";
4565 let quickbookmark ?title
() =
4566 match state.layout with
4572 let sec = Unix.gettimeofday
() in
4573 let tm = Unix.localtime
sec in
4574 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4578 (tm.Unix.tm_year
+ 1900)
4581 | Some
title -> title
4584 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4589 state.fullscreen
<- None
;
4593 let setautoscrollspeed step goingdown
=
4594 let incr = max
1 ((abs step
) / 2) in
4595 let incr = if goingdown
then incr else -incr in
4596 let astep = step
+ incr in
4597 state.autoscroll
<- Some
astep;
4600 let gotounder = function
4601 | Ulinkgoto
(pageno, top) ->
4605 gotopage1 pageno top;
4611 | Uremote
(filename
, pageno) ->
4613 if Sys.file_exists filename
4616 let dir = Filename.dirname
state.path in
4617 let path = Filename.concat
dir filename
in
4618 if Sys.file_exists
path
4622 if String.length
path > 0
4624 let anchor = getanchor () in
4625 let ranchor = state.path, state.password
, anchor in
4626 state.anchor <- (pageno, 0.0);
4627 state.ranchors
<- ranchor :: state.ranchors
;
4630 else showtext '
!'
("Could not find " ^ filename
)
4632 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4636 match conf.columns
with
4638 | _ -> conf.zoom > 1.0
4641 let viewkeyboard key mask
=
4643 let mode = state.mode in
4644 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4647 G.postRedisplay "view:enttext"
4649 let ctrl = Wsi.withctrl mask
in
4654 | 0xff63 -> (* insert *)
4655 if conf.angle
mod 360 = 0
4657 state.mode <- LinkNav
(Ltgendir
0);
4660 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4662 | 0xff1b | 113 -> (* escape / q *)
4663 begin match state.mstate
with
4665 state.mstate
<- Mnone
;
4666 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4667 G.postRedisplay "kill zoom rect";
4669 match state.ranchors
with
4671 | (path, password
, anchor) :: rest
->
4672 state.ranchors
<- rest
;
4673 state.anchor <- anchor;
4674 opendoc path password
4677 | 0xff08 -> (* backspace *)
4678 let y = getnav ~
-1 in
4679 gotoy_and_clear_text y
4687 G.postRedisplay "dehighlight";
4689 | 47 | 63 -> (* / ? *)
4690 let ondone isforw
s =
4691 cbput state.hists
.pat
s;
4692 state.searchpattern
<- s;
4695 let s = String.create
1 in
4696 s.[0] <- Char.chr
key;
4697 enttext (s, "", Some
(onhist state.hists
.pat
),
4698 textentry, ondone (key = 47), true)
4700 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4701 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4702 setzoom (conf.zoom +. incr)
4704 | 43 | 0xffab -> (* + *)
4707 try int_of_string
s with exc
->
4708 state.text <- Printf.sprintf
"bad integer `%s': %s"
4709 s (Printexc.to_string exc
);
4715 state.text <- "page bias is now " ^ string_of_int
n;
4718 enttext ("page bias: ", "", None
, intentry, ondone, true)
4720 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4721 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4722 setzoom (max
0.01 (conf.zoom -. decr))
4724 | 45 | 0xffad -> (* - *)
4725 let ondone msg
= state.text <- msg
in
4727 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4728 optentry state.mode, ondone, true
4731 | 48 when ctrl -> (* ctrl-0 *)
4734 | 49 when ctrl -> (* 1 *)
4735 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4739 | 0xffc6 -> (* f9 *)
4742 | 57 when ctrl -> (* ctrl-9 *)
4745 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4746 when not
ctrl -> (* 0..9 *)
4749 try int_of_string
s with exc
->
4750 state.text <- Printf.sprintf
"bad integer `%s': %s"
4751 s (Printexc.to_string exc
);
4757 cbput state.hists
.pag
(string_of_int
n);
4758 gotopage1 (n + conf.pagebias
- 1) 0;
4761 let pageentry text key =
4762 match Char.unsafe_chr
key with
4763 | 'g'
-> TEdone
text
4764 | _ -> intentry text key
4766 let text = "x" in text.[0] <- Char.chr
key;
4767 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4770 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4771 reshape conf.winw
conf.winh
;
4774 conf.hlinks
<- not
conf.hlinks
;
4775 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4776 G.postRedisplay "toggle highlightlinks";
4779 state.glinks
<- true;
4780 let mode = state.mode in
4781 state.mode <- Textentry
(
4782 (":", "", None
, linknentry, linkndone (fun under ->
4787 state.glinks
<- false;
4791 G.postRedisplay "view:linkent(F)"
4794 state.glinks
<- true;
4795 let mode = state.mode in
4796 state.mode <- Textentry
(
4797 (":", "", None
, linknentry, linkndone (fun under ->
4798 match Ne.pipe () with
4800 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4801 (Printexc.to_string exn
));
4804 try popen conf.selcmd
[r, 0; w, -1]; true
4807 (Printf.sprintf
"failed to execute %s: %s"
4808 conf.selcmd
(Printexc.to_string exn
));
4812 Ne.clo fd
(fun msg
->
4813 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4816 let s = undertext under in
4820 let l = String.length
s in
4821 let n = Unix.write
w s 0 l in
4826 "failed to write %d characters to sel pipe, wrote %d"
4831 (Printf.sprintf
"failed to write to sel pipe: %s"
4832 (Printexc.to_string exn
)
4841 state.glinks
<- false;
4845 G.postRedisplay "view:linkent"
4848 begin match state.autoscroll
with
4850 conf.autoscrollstep
<- step
;
4851 state.autoscroll
<- None
4853 if conf.autoscrollstep
= 0
4854 then state.autoscroll
<- Some
1
4855 else state.autoscroll
<- Some
conf.autoscrollstep
4858 | 112 when ctrl -> (* ctrl-p *)
4862 conf.presentation <- not
conf.presentation;
4863 if conf.presentation
4865 if not
conf.scrollbarinpm
4866 then state.scrollw
<- 0;
4869 state.scrollw
<- conf.scrollbw
;
4871 showtext ' '
("presentation mode " ^
4872 if conf.presentation then "on" else "off");
4873 state.anchor <- getanchor ();
4877 begin match state.fullscreen
with
4879 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4882 state.fullscreen
<- None
;
4887 gotoy_and_clear_text 0
4890 gotopage1 (state.pagecount
- 1) 0
4892 | 112 | 78 -> (* p|N *)
4893 search state.searchpattern
false
4895 | 110 | 0xffc0 -> (* n|F3 *)
4896 search state.searchpattern
true
4899 begin match state.layout with
4902 gotoy_and_clear_text (getpagey l.pageno)
4906 begin match List.rev
state.layout with
4909 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4910 gotoy_and_clear_text (getpagey pageno)
4913 | 0xff9f | 0xffff -> (* delete *)
4914 begin match state.layout with
4917 let pageno = max
0 (l.pageno-1) in
4918 gotoy_and_clear_text (getpagey pageno)
4922 showtext ' '
(describe_location ());
4925 begin match state.layout with
4928 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4933 enterbookmarkmode ()
4935 | 104 | 0xffbe -> (* h|F1 *)
4941 | 101 when conf.redirectstderr -> (* e *)
4946 match state.layout with
4949 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4953 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4957 showtext ' '
"Quick bookmark added";
4960 begin match state.layout with
4962 let rect = getpdimrect
l.pagedimno
in
4966 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4967 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4969 (truncate
(rect.(1) -. rect.(0)),
4970 truncate
(rect.(3) -. rect.(0)))
4972 let w = truncate
((float w)*.conf.zoom)
4973 and h = truncate
((float h)*.conf.zoom) in
4976 state.anchor <- getanchor ();
4977 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4979 G.postRedisplay "z";
4984 | 50 when ctrl -> (* ctrl-2 *)
4985 let maxw = getmaxw
() in
4987 then setzoom (maxw /. float conf.winw
)
4989 | 60 | 62 -> (* < > *)
4990 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4992 | 91 | 93 -> (* [ ] *)
4994 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4996 G.postRedisplay "brightness";
4998 | 99 when state.mode = View
-> (* c *)
5000 match state.prevcolumns
with
5001 | None
-> (1, 0, 0), 1.0
5002 | Some
(columns
, z
) ->
5005 | Csplit
(c, _) -> -c, 0, 0
5006 | Cmulti
((c, a, b), _) -> c, a, b
5007 | Csingle
-> 1, 0, 0
5011 setcolumns View
c a b;
5014 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5015 setzoom state.prevzoom
5017 | 107 | 0xff52 -> (* k up *)
5018 begin match state.autoscroll
with
5020 begin match state.mode with
5021 | Birdseye beye
-> upbirdseye 1 beye
5024 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5025 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5028 setautoscrollspeed n false
5031 | 106 | 0xff54 -> (* j down *)
5032 begin match state.autoscroll
with
5034 begin match state.mode with
5035 | Birdseye beye
-> downbirdseye 1 beye
5038 then gotoy_and_clear_text (clamp (conf.winh
/2))
5039 else gotoy_and_clear_text (clamp conf.scrollstep
)
5042 setautoscrollspeed n true
5045 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5053 let dx = if key = 0xff51 then dx else -dx in
5054 state.x <- state.x + dx;
5055 gotoy_and_clear_text state.y
5058 G.postRedisplay "lef/right"
5061 | 0xff55 -> (* prior *)
5065 match state.layout with
5067 | l :: _ -> state.y - l.pagey
5073 | 0xff56 -> (* next *)
5077 match List.rev
state.layout with
5079 | l :: _ -> getpagey l.pageno
5085 | 0xff50 -> gotoghyll 0
5086 | 0xff57 -> gotoghyll (clamp state.maxy)
5087 | 0xff53 when Wsi.withalt mask
->
5088 gotoghyll (getnav ~
-1)
5089 | 0xff51 when Wsi.withalt mask
->
5090 gotoghyll (getnav 1)
5093 state.anchor <- getanchor ();
5094 opendoc state.path state.password
5096 | 118 when conf.debug
-> (* v *)
5099 match getopaque l.pageno with
5102 let x0, y0, x1, y1 = pagebbox opaque
in
5103 let a,b = float x0, float y0 in
5104 let c,d = float x1, float y0 in
5105 let e,f = float x1, float y1 in
5106 let h,j
= float x0, float y1 in
5107 let rect = (a,b,c,d,e,f,h,j
) in
5109 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5111 G.postRedisplay "v";
5114 vlog "huh? %s" (Wsi.keyname
key)
5117 let linknavkeyboard key mask
linknav =
5118 let getpage pageno =
5119 let rec loop = function
5121 | l :: _ when l.pageno = pageno -> Some
l
5122 | _ :: rest
-> loop rest
5123 in loop state.layout
5125 let doexact (pageno, n) =
5126 match getopaque pageno, getpage pageno with
5127 | Some opaque
, Some
l ->
5130 let under = getlink opaque
n in
5131 G.postRedisplay "link gotounder";
5137 | 0xff50 -> (* home *)
5138 Some
(findlink opaque LDfirst
), -1
5140 | 0xff57 -> (* end *)
5141 Some
(findlink opaque LDlast
), 1
5143 | 0xff51 -> (* left *)
5144 Some
(findlink opaque
(LDleft
n)), -1
5146 | 0xff53 -> (* right *)
5147 Some
(findlink opaque
(LDright
n)), 1
5149 | 0xff52 -> (* up *)
5150 Some
(findlink opaque
(LDup
n)), -1
5152 | 0xff54 -> (* down *)
5153 Some
(findlink opaque
(LDdown
n)), 1
5158 begin match findpwl
l.pageno dir with
5162 state.mode <- LinkNav
(Ltgendir
dir);
5163 let y, h = getpageyh pageno in
5166 then y + h - conf.winh
5171 begin match getopaque pageno, getpage pageno with
5172 | Some opaque
, Some
_ ->
5174 let ld = if dir > 0 then LDfirst
else LDlast
in
5177 begin match link with
5179 showlinktype (getlink opaque
m);
5180 state.mode <- LinkNav
(Ltexact
(pageno, m));
5181 G.postRedisplay "linknav jpage";
5188 begin match opt with
5189 | Some Lnotfound
-> pwl l dir;
5190 | Some
(Lfound
m) ->
5194 let _, y0, _, y1 = getlinkrect opaque
m in
5196 then gotopage1 l.pageno y0
5198 let d = fstate.fontsize
+ 1 in
5199 if y1 - l.pagey > l.pagevh - d
5200 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5201 else G.postRedisplay "linknav";
5203 showlinktype (getlink opaque
m);
5204 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5207 | None
-> viewkeyboard key mask
5209 | _ -> viewkeyboard key mask
5214 G.postRedisplay "leave linknav"
5218 | Ltgendir
_ -> viewkeyboard key mask
5219 | Ltexact exact
-> doexact exact
5222 let keyboard key mask
=
5223 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5224 then wcmd "interrupt"
5225 else state.uioh <- state.uioh#
key key mask
5228 let birdseyekeyboard key mask
5229 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5231 match conf.columns
with
5233 | Cmulti
((c, _, _), _) -> c
5234 | Csplit
_ -> failwith
"bird's eye split mode"
5237 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5238 let y, h = getpageyh pageno in
5239 let top = (conf.winh
- h) / 2 in
5240 gotoy (max
0 (y - top))
5241 | 0xff0d -> leavebirdseye beye
false
5242 | 0xff1b -> leavebirdseye beye
true (* escape *)
5243 | 0xff52 -> upbirdseye incr beye
(* prior *)
5244 | 0xff54 -> downbirdseye incr beye
(* next *)
5245 | 0xff51 -> upbirdseye 1 beye
(* up *)
5246 | 0xff53 -> downbirdseye 1 beye
(* down *)
5249 begin match state.layout with
5253 state.mode <- Birdseye
(
5254 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5256 gotopage1 l.pageno 0;
5259 let layout = layout (state.y-conf.winh
) conf.winh
in
5261 | [] -> gotoy (clamp (-conf.winh
))
5263 state.mode <- Birdseye
(
5264 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5266 gotopage1 l.pageno 0
5269 | [] -> gotoy (clamp (-conf.winh
))
5273 begin match List.rev
state.layout with
5275 let layout = layout (state.y + conf.winh
) conf.winh
in
5276 begin match layout with
5278 let incr = l.pageh
- l.pagevh in
5283 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5285 G.postRedisplay "birdseye pagedown";
5287 else gotoy (clamp (incr + conf.interpagespace*2));
5291 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5292 gotopage1 l.pageno 0;
5295 | [] -> gotoy (clamp conf.winh
)
5299 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5303 let pageno = state.pagecount
- 1 in
5304 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5305 if not
(pagevisible state.layout pageno)
5308 match List.rev
state.pdims
with
5310 | (_, _, h, _) :: _ -> h
5312 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5313 else G.postRedisplay "birdseye end";
5314 | _ -> viewkeyboard key mask
5317 let drawpage l linkindexbase
=
5319 match state.mode with
5320 | Textentry
_ -> scalecolor 0.4
5322 | View
-> scalecolor 1.0
5323 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5324 if l.pageno = hooverpageno
5327 if l.pageno = pageno
5333 begin match getopaque l.pageno with
5335 if tileready l l.pagex l.pagey
5337 let x = l.pagedispx - l.pagex
5338 and y = l.pagedispy - l.pagey in
5340 match conf.columns
with
5341 | Csingle
| Cmulti
_ ->
5342 (if conf.hlinks
then 1 else 0)
5344 && not
(isbirdseye state.mode) then 2 else 0)
5348 match state.mode with
5349 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5352 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5359 let scrollindicator () =
5360 let sbw, ph
, sh = state.uioh#
scrollph in
5361 let sbh, pw, sw = state.uioh#scrollpw
in
5363 GlDraw.color (0.64, 0.64, 0.64);
5365 (float (conf.winw
- sbw), 0.)
5366 (float conf.winw
, float conf.winh
)
5369 (0., float (conf.winh
- sbh))
5370 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5372 GlDraw.color (0.0, 0.0, 0.0);
5375 (float (conf.winw
- sbw), ph
)
5376 (float conf.winw
, ph
+. sh)
5379 (pw, float (conf.winh
- sbh))
5380 (pw +. sw, float conf.winh
)
5385 match state.mstate
with
5386 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5389 | Msel
((x0, y0), (x1, y1)) ->
5390 let rec loop = function
5392 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5393 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5394 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5395 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5397 match getopaque l.pageno with
5399 let x0, y0 = pagetranslatepoint l x0 y0 in
5400 let x1, y1 = pagetranslatepoint l x1 y1 in
5401 seltext opaque
(x0, y0, x1, y1);
5409 let showrects rects
=
5411 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5412 GlDraw.polygon_mode `both `fill
;
5413 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5415 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5417 if l.pageno = pageno
5419 let dx = float (l.pagedispx - l.pagex) in
5420 let dy = float (l.pagedispy - l.pagey) in
5421 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5422 GlDraw.begins `quads
;
5424 GlDraw.vertex2
(x0+.dx, y0+.dy);
5425 GlDraw.vertex2
(x1+.dx, y1+.dy);
5426 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5427 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5438 GlClear.color (scalecolor2 conf.bgcolor
);
5439 GlClear.clear
[`
color];
5440 let rec loop linkindexbase
= function
5442 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5443 loop linkindexbase rest
5446 loop 0 state.layout;
5448 match state.mode with
5449 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5450 begin match getopaque pageno with
5452 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5459 | None
-> state.rects
5466 begin match state.mstate
with
5467 | Mzoomrect
((x0, y0), (x1, y1)) ->
5469 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5470 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5471 GlDraw.rect (float x0, float y0)
5472 (float x1, float y1);
5481 let zoomrect x y x1 y1 =
5484 and y0 = min
y y1 in
5485 gotoy (state.y + y0);
5486 state.anchor <- getanchor ();
5487 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5489 if state.w < conf.winw
- state.scrollw
5490 then (conf.winw
- state.scrollw
- state.w) / 2
5493 state.x <- (state.x + margin) - x0;
5495 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5496 state.mstate
<- Mnone
;
5500 let winw = conf.winw - state.scrollw
- 1 in
5501 let s = float x /. float winw in
5502 let destx = truncate
(float (state.w + winw) *. s) in
5503 state.x <- winw - destx;
5504 gotoy_and_clear_text state.y;
5505 state.mstate
<- Mscrollx
;
5509 let s = float y /. float conf.winh
in
5510 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5511 gotoy_and_clear_text desty;
5512 state.mstate
<- Mscrolly
;
5515 let viewmouse button down
x y mask
=
5517 | n when (n == 4 || n == 5) && not down
->
5518 if Wsi.withctrl mask
5520 match state.mstate
with
5521 | Mzoom
(oldn
, i
) ->
5529 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5531 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5533 let zoom = conf.zoom -. incr in
5535 state.mstate
<- Mzoom
(n, 0);
5537 state.mstate
<- Mzoom
(n, i
+1);
5539 else state.mstate
<- Mzoom
(n, 0)
5541 | _ -> state.mstate
<- Mzoom
(n, 0)
5544 match state.autoscroll
with
5545 | Some step
-> setautoscrollspeed step
(n=4)
5549 then -conf.scrollstep
5550 else conf.scrollstep
5552 let incr = incr * 2 in
5553 let y = clamp incr in
5554 gotoy_and_clear_text y
5557 | 1 when Wsi.withctrl mask
->
5560 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5561 state.mstate
<- Mpan
(x, y)
5564 state.mstate
<- Mnone
5569 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5571 state.mstate
<- Mzoomrect
(p, p)
5574 match state.mstate
with
5575 | Mzoomrect
((x0, y0), _) ->
5576 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5577 then zoomrect x0 y0 x y
5579 state.mstate
<- Mnone
;
5580 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5581 G.postRedisplay "kill accidental zoom rect";
5584 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5585 state.mstate
<- Mnone
5588 | 1 when x > conf.winw - state.scrollw
->
5591 let _, position, sh = state.uioh#
scrollph in
5592 if y > truncate
position && y < truncate
(position +. sh)
5593 then state.mstate
<- Mscrolly
5596 state.mstate
<- Mnone
5598 | 1 when y > conf.winh
- state.hscrollh ->
5601 let _, position, sw = state.uioh#scrollpw
in
5602 if x > truncate
position && x < truncate
(position +. sw)
5603 then state.mstate
<- Mscrollx
5606 state.mstate
<- Mnone
5609 let dest = if down
then getunder x y else Unone
in
5610 begin match dest with
5614 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5617 | Unone
when down
->
5618 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5619 state.mstate
<- Mpan
(x, y);
5621 | Unone
| Utext
_ ->
5624 if conf.angle
mod 360 = 0
5626 state.mstate
<- Msel
((x, y), (x, y));
5627 G.postRedisplay "mouse select";
5631 match state.mstate
with
5634 | Mzoom
_ | Mscrollx
| Mscrolly
->
5635 state.mstate
<- Mnone
5637 | Mzoomrect
((x0, y0), _) ->
5641 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5642 state.mstate
<- Mnone
5644 | Msel
((_, y0), (_, y1)) ->
5645 let rec loop = function
5648 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5649 || ((y1 >= l.pagedispy
5650 && y1 <= (l.pagedispy + l.pagevh)))
5652 match getopaque l.pageno with
5655 match Ne.pipe () with
5659 "can not create sel pipe: %s"
5660 (Printexc.to_string exn
));
5662 let doclose what fd
=
5663 Ne.clo fd
(fun msg
->
5664 dolog "%s close failed: %s" what msg
)
5667 popen conf.selcmd
[r, 0; w, -1];
5670 G.postRedisplay "copysel";
5672 dolog "can not execute %S: %s"
5673 conf.selcmd
(Printexc.to_string exn
);
5681 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5682 state.mstate
<- Mnone
;
5689 let birdseyemouse button down
x y mask
5690 (conf, leftx
, _, hooverpageno
, anchor) =
5693 let rec loop = function
5696 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5697 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5699 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5705 | _ -> viewmouse button down
x y mask
5708 let mouse button down
x y mask
=
5709 state.uioh <- state.uioh#button button down
x y mask
;
5713 state.uioh <- state.uioh#
motion x y
5717 state.uioh <- state.uioh#
pmotion x y;
5723 method key key mask
=
5724 begin match state.mode with
5725 | Textentry
textentry -> textentrykeyboard key mask
textentry
5726 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5727 | View
-> viewkeyboard key mask
5728 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5732 method button button bstate
x y mask
=
5733 begin match state.mode with
5735 | View
-> viewmouse button bstate
x y mask
5736 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5742 begin match state.mode with
5744 | View
| Birdseye
_ | LinkNav
_ ->
5745 match state.mstate
with
5746 | Mzoom
_ | Mnone
-> ()
5751 state.mstate
<- Mpan
(x, y);
5753 then state.x <- state.x + dx;
5755 gotoy_and_clear_text y
5758 state.mstate
<- Msel
(a, (x, y));
5759 G.postRedisplay "motion select";
5762 let y = min
conf.winh
(max
0 y) in
5766 let x = min
conf.winw (max
0 x) in
5769 | Mzoomrect
(p0
, _) ->
5770 state.mstate
<- Mzoomrect
(p0
, (x, y));
5771 G.postRedisplay "motion zoomrect";
5775 method pmotion x y =
5776 begin match state.mode with
5777 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5778 let rec loop = function
5780 if hooverpageno
!= -1
5782 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5783 G.postRedisplay "pmotion birdseye no hoover";
5786 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5787 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5789 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5790 G.postRedisplay "pmotion birdseye hoover";
5800 match state.mstate
with
5801 | Mnone
-> updateunder x y
5802 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5807 method infochanged
_ = ()
5810 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5811 let p, h = scrollph state.y maxy in
5815 let winw = conf.winw - state.scrollw
- 1 in
5816 let fwinw = float winw in
5818 let sw = fwinw /. float state.w in
5819 let sw = fwinw *. sw in
5820 max
sw (float conf.scrollh
)
5823 let f = state.w+winw in
5824 let r = float (winw-state.x) /. float f in
5825 let p = fwinw *. r in
5829 if position +. sw > fwinw
5830 then fwinw -. position
5833 state.hscrollh, position, sw
5837 match state.mode with
5838 | LinkNav
_ -> "links"
5839 | Textentry
_ -> "textentry"
5840 | Birdseye
_ -> "birdseye"
5843 findkeyhash conf modename
5850 let fontpath = ref "";;
5853 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5856 let l = String.length
s in
5857 let b = Buffer.create
l in
5863 try Sys.getenv
"HOME"
5866 ("Can not determine home directory location: " ^
5867 Printexc.to_string exn
);
5871 let modifier_of_string = function
5872 | "alt" -> Wsi.altmask
5873 | "shift" -> Wsi.shiftmask
5874 | "ctrl" | "control" -> Wsi.ctrlmask
5875 | "meta" -> Wsi.metamask
5880 let r = Str.regexp
"-" in
5882 let elems = Str.full_split
r s in
5885 let m1 = modifier_of_string s in
5887 then (Wsi.namekey
s, m)
5890 | Str.Delim
s when n land 1 = 0 -> g s
5892 | Str.Delim
_ -> (k
, m)
5894 let rec loop n k
m = function
5897 let k, m = f n k m x in
5903 let keys_of_string =
5904 let r = Str.regexp
"[ \t]" in
5906 let elems = Str.split
r s in
5907 List.map
key_of_string elems
5910 let copykeyhashes c =
5911 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5914 let config_of c attrs
=
5918 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5919 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5920 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5921 | "preload" -> { c with preload = bool_of_string
v }
5922 | "page-bias" -> { c with pagebias
= int_of_string
v }
5923 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5924 | "auto-scroll-step" ->
5925 { c with autoscrollstep
= max
0 (int_of_string
v) }
5926 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5927 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5930 match String.lowercase
v with
5931 | "true" -> Some infinity
5933 | f -> Some
(float_of_string
f)
5935 { c with maxwait
= mw}
5936 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5937 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5938 | "vertical-margin" ->
5939 { c with interpagespace = max
0 (int_of_string
v) }
5941 let zoom = float_of_string
v /. 100. in
5942 let zoom = max
zoom 0.0 in
5943 { c with zoom = zoom }
5944 | "presentation" -> { c with presentation = bool_of_string
v }
5945 | "rotation-angle" -> { c with angle
= int_of_string
v }
5946 | "width" -> { c with winw = max
20 (int_of_string
v) }
5947 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5948 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5949 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5950 | "pixmap-cache-size" ->
5951 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5952 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5953 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5954 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5955 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5956 | "background-color" -> { c with bgcolor
= color_of_string v }
5957 | "scrollbar-in-presentation" ->
5958 { c with scrollbarinpm
= bool_of_string
v }
5959 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5960 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5961 | "mupdf-store-size" ->
5962 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5963 | "checkers" -> { c with checkers
= bool_of_string
v }
5964 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5965 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5966 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5967 | "uri-launcher" -> { c with urilauncher
= unent v }
5968 | "path-launcher" -> { c with pathlauncher
= unent v }
5969 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5970 | "invert-colors" -> { c with invert
= bool_of_string
v }
5971 | "brightness" -> { c with colorscale
= float_of_string
v }
5972 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5974 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5976 let (n, _, _) as nab
= multicolumns_of_string v in
5978 then { c with columns
= Csplit
(-n, [||]) }
5979 else { c with columns
= Cmulti
(nab
, [||]) }
5980 | "birds-eye-columns" ->
5981 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5982 | "selection-command" -> { c with selcmd
= unent v }
5983 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5984 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
5987 prerr_endline
("Error processing attribute (`" ^
5988 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5991 let rec fold c = function
5994 let c = apply c k v in
5997 fold { c with keyhashes
= copykeyhashes c } attrs
;
6000 let fromstring f pos
n v d =
6003 dolog "Error processing attribute (%S=%S) at %d\n%s"
6004 n v pos
(Printexc.to_string exn
)
6009 let bookmark_of attrs
=
6010 let rec fold title page
rely = function
6011 | ("title", v) :: rest
-> fold v page
rely rest
6012 | ("page", v) :: rest
-> fold title v rely rest
6013 | ("rely", v) :: rest
-> fold title page
v rest
6014 | _ :: rest
-> fold title page
rely rest
6015 | [] -> title, page
, rely
6017 fold "invalid" "0" "0" attrs
6021 let rec fold path page
rely pan
= function
6022 | ("path", v) :: rest
-> fold v page
rely pan rest
6023 | ("page", v) :: rest
-> fold path v rely pan rest
6024 | ("rely", v) :: rest
-> fold path page
v pan rest
6025 | ("pan", v) :: rest
-> fold path page
rely v rest
6026 | _ :: rest
-> fold path page
rely pan rest
6027 | [] -> path, page
, rely, pan
6029 fold "" "0" "0" "0" attrs
6033 let rec fold rs ls
= function
6034 | ("out", v) :: rest
-> fold v ls rest
6035 | ("in", v) :: rest
-> fold rs
v rest
6036 | _ :: rest
-> fold ls rs rest
6042 let setconf dst
src =
6043 dst
.scrollbw
<- src.scrollbw
;
6044 dst
.scrollh
<- src.scrollh
;
6045 dst
.icase
<- src.icase
;
6046 dst
.preload <- src.preload;
6047 dst
.pagebias
<- src.pagebias
;
6048 dst
.verbose
<- src.verbose
;
6049 dst
.scrollstep
<- src.scrollstep
;
6050 dst
.maxhfit
<- src.maxhfit
;
6051 dst
.crophack
<- src.crophack
;
6052 dst
.autoscrollstep
<- src.autoscrollstep
;
6053 dst
.maxwait
<- src.maxwait
;
6054 dst
.hlinks
<- src.hlinks
;
6055 dst
.underinfo
<- src.underinfo
;
6056 dst
.interpagespace <- src.interpagespace;
6057 dst
.zoom <- src.zoom;
6058 dst
.presentation <- src.presentation;
6059 dst
.angle
<- src.angle
;
6060 dst
.winw <- src.winw;
6061 dst
.winh
<- src.winh
;
6062 dst
.savebmarks
<- src.savebmarks
;
6063 dst
.memlimit
<- src.memlimit
;
6064 dst
.proportional
<- src.proportional
;
6065 dst
.texcount
<- src.texcount
;
6066 dst
.sliceheight
<- src.sliceheight
;
6067 dst
.thumbw
<- src.thumbw
;
6068 dst
.jumpback
<- src.jumpback
;
6069 dst
.bgcolor
<- src.bgcolor
;
6070 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6071 dst
.tilew
<- src.tilew
;
6072 dst
.tileh
<- src.tileh
;
6073 dst
.mustoresize
<- src.mustoresize
;
6074 dst
.checkers
<- src.checkers
;
6075 dst
.aalevel
<- src.aalevel
;
6076 dst
.trimmargins
<- src.trimmargins
;
6077 dst
.trimfuzz
<- src.trimfuzz
;
6078 dst
.urilauncher
<- src.urilauncher
;
6079 dst
.colorspace
<- src.colorspace
;
6080 dst
.invert
<- src.invert
;
6081 dst
.colorscale
<- src.colorscale
;
6082 dst
.redirectstderr <- src.redirectstderr;
6083 dst
.ghyllscroll
<- src.ghyllscroll
;
6084 dst
.columns
<- src.columns
;
6085 dst
.beyecolumns
<- src.beyecolumns
;
6086 dst
.selcmd
<- src.selcmd
;
6087 dst
.updatecurs
<- src.updatecurs
;
6088 dst
.pathlauncher
<- src.pathlauncher
;
6089 dst
.keyhashes
<- copykeyhashes src;
6090 dst
.hfsize
<- src.hfsize
;
6094 let h = Hashtbl.create
10 in
6095 let dc = { defconf with angle
= defconf.angle
} in
6096 let rec toplevel v t spos
_ =
6098 | Vdata
| Vcdata
| Vend
-> v
6099 | Vopen
("llppconfig", _, closed
) ->
6102 else { v with f = llppconfig
}
6104 error
"unexpected subelement at top level" s spos
6105 | Vclose
_ -> error
"unexpected close at top level" s spos
6107 and llppconfig
v t spos
_ =
6109 | Vdata
| Vcdata
-> v
6110 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6111 | Vopen
("defaults", attrs
, closed
) ->
6112 let c = config_of dc attrs
in
6116 else { v with f = defaults
}
6118 | Vopen
("ui-font", attrs
, closed
) ->
6119 let rec getsize size
= function
6121 | ("size", v) :: rest
->
6123 fromstring int_of_string spos
"size" v fstate.fontsize
in
6125 | l -> getsize size l
6127 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6130 else { v with f = uifont
(Buffer.create
10) }
6132 | Vopen
("doc", attrs
, closed
) ->
6133 let pathent, spage
, srely
, span
= doc_of attrs
in
6134 let path = unent pathent
6135 and pageno = fromstring int_of_string spos
"page" spage
0
6136 and rely = fromstring float_of_string spos
"rely" srely
0.0
6137 and pan
= fromstring int_of_string spos
"pan" span
0 in
6138 let c = config_of dc attrs
in
6139 let anchor = (pageno, rely) in
6141 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6142 else { v with f = doc
path pan
anchor c [] }
6145 error
"unexpected subelement in llppconfig" s spos
6147 | Vclose
"llppconfig" -> { v with f = toplevel }
6148 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6150 and defaults
v t spos
_ =
6152 | Vdata
| Vcdata
-> v
6153 | Vend
-> error
"unexpected end of input in defaults" s spos
6154 | Vopen
("keymap", attrs
, closed
) ->
6156 try List.assoc
"mode" attrs
6157 with Not_found
-> "global" in
6162 let h = findkeyhash dc modename in
6163 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6166 { v with f = pkeymap
ret KeyMap.empty }
6168 | Vopen
(_, _, _) ->
6169 error
"unexpected subelement in defaults" s spos
6171 | Vclose
"defaults" ->
6172 { v with f = llppconfig
}
6174 | Vclose
_ -> error
"unexpected close in defaults" s spos
6176 and uifont
b v t spos
epos =
6179 Buffer.add_substring
b s spos
(epos - spos
);
6181 | Vopen
(_, _, _) ->
6182 error
"unexpected subelement in ui-font" s spos
6183 | Vclose
"ui-font" ->
6184 if String.length
!fontpath = 0
6185 then fontpath := Buffer.contents
b;
6186 { v with f = llppconfig
}
6187 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6188 | Vend
-> error
"unexpected end of input in ui-font" s spos
6190 and doc
path pan
anchor c bookmarks
v t spos
_ =
6192 | Vdata
| Vcdata
-> v
6193 | Vend
-> error
"unexpected end of input in doc" s spos
6194 | Vopen
("bookmarks", _, closed
) ->
6197 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6199 | Vopen
("keymap", attrs
, closed
) ->
6201 try List.assoc
"mode" attrs
6202 with Not_found
-> "global"
6208 let h = findkeyhash c modename in
6209 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6210 doc
path pan
anchor c bookmarks
6212 { v with f = pkeymap
ret KeyMap.empty }
6214 | Vopen
(_, _, _) ->
6215 error
"unexpected subelement in doc" s spos
6218 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6219 { v with f = llppconfig
}
6221 | Vclose
_ -> error
"unexpected close in doc" s spos
6223 and pkeymap
ret keymap
v t spos
_ =
6225 | Vdata
| Vcdata
-> v
6226 | Vend
-> error
"unexpected end of input in keymap" s spos
6227 | Vopen
("map", attrs
, closed
) ->
6228 let r, l = map_of attrs
in
6229 let kss = fromstring keys_of_string spos
"in" r [] in
6230 let lss = fromstring keys_of_string spos
"out" l [] in
6234 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6235 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6238 then { v with f = pkeymap
ret keymap }
6241 { v with f = skip
"map" f }
6244 error
"unexpected subelement in keymap" s spos
6246 | Vclose
"keymap" ->
6247 { v with f = ret keymap }
6249 | Vclose
_ -> error
"unexpected close in keymap" s spos
6251 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6253 | Vdata
| Vcdata
-> v
6254 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6255 | Vopen
("item", attrs
, closed
) ->
6256 let titleent, spage
, srely
= bookmark_of attrs
in
6257 let page = fromstring int_of_string spos
"page" spage
0
6258 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6259 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6261 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6264 { v with f = skip
"item" f }
6267 error
"unexpected subelement in bookmarks" s spos
6269 | Vclose
"bookmarks" ->
6270 { v with f = doc
path pan
anchor c bookmarks }
6272 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6274 and skip tag
f v t spos
_ =
6276 | Vdata
| Vcdata
-> v
6278 error
("unexpected end of input in skipped " ^ tag
) s spos
6279 | Vopen
(tag'
, _, closed
) ->
6283 let f'
() = { v with f = skip tag
f } in
6284 { v with f = skip tag'
f'
}
6288 else error
("unexpected close in skipped " ^ tag
) s spos
6291 parse
{ f = toplevel; accu = () } s;
6297 let len = in_channel_length ic
in
6298 let s = String.create
len in
6299 really_input ic
s 0 len;
6302 | Parse_error
(msg
, s, pos
) ->
6303 let subs = subs s pos
in
6304 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6305 failwith
("parse error: " ^
s)
6308 failwith
("config load error: " ^
Printexc.to_string exn
)
6314 let dir = Filename.concat
home ".config" in
6315 if Sys.is_directory
dir then dir else home
6318 Filename.concat
dir "llpp.conf"
6321 let confpath = ref defconfpath;;
6324 if Sys.file_exists
!confpath
6327 (try Some
(open_in_bin
!confpath)
6330 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6331 Printexc.to_string exn
);
6340 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6341 Printexc.to_string exn
);
6347 f (Hashtbl.create
0, defconf)
6352 let pc, pb
, px, pa
=
6354 Hashtbl.find h (Filename.basename
state.path)
6355 with Not_found
-> dc, [], 0, (0, 0.0)
6359 state.bookmarks <- pb
;
6361 state.scrollw
<- conf.scrollbw
;
6363 then state.anchor <- pa
;
6364 cbput state.hists
.nav pa
;
6369 let add_attrs bb always
dc c =
6372 then Printf.bprintf bb
"\n %s='%b'" s a
6375 then Printf.bprintf bb
"\n %s='%d'" s a
6378 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6381 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6384 then Printf.bprintf bb
"\n %s='%f'" s a
6388 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6392 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6396 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6400 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6406 | Some
(_N
, _A
, _B
) ->
6407 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6417 else string_of_float
f
6419 Printf.bprintf bb
"\n %s='%s'" s v
6424 | Cmulti
((n, a, b), _) when n > 1 ->
6425 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6426 | Csplit
(n, _) when n > 1 ->
6427 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6433 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6438 then dc.winw, dc.winh
6440 match state.fullscreen
with
6442 | None
-> c.winw, c.winh
6444 let zoom, presentation, interpagespace, maxwait
=
6446 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6448 match state.mode with
6449 | Birdseye
(bc
, _, _, _, _) ->
6450 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6451 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6453 oi
"width" w dc.winw;
6454 oi
"height" h dc.winh
;
6455 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6456 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6457 ob "case-insensitive-search" c.icase
dc.icase
;
6458 ob "preload" c.preload dc.preload;
6459 oi
"page-bias" c.pagebias
dc.pagebias
;
6460 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6461 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6462 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6463 ob "crop-hack" c.crophack
dc.crophack
;
6464 oW
"throttle" maxwait
dc.maxwait
;
6465 ob "highlight-links" c.hlinks
dc.hlinks
;
6466 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6467 oi
"vertical-margin" interpagespace dc.interpagespace;
6468 oz
"zoom" zoom dc.zoom;
6469 ob "presentation" presentation dc.presentation;
6470 oi
"rotation-angle" c.angle
dc.angle
;
6471 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6472 ob "proportional-display" c.proportional
dc.proportional
;
6473 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6474 oi
"tex-count" c.texcount
dc.texcount
;
6475 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6476 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6477 ob "persistent-location" c.jumpback
dc.jumpback
;
6478 oc
"background-color" c.bgcolor
dc.bgcolor
;
6479 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6480 oi
"tile-width" c.tilew
dc.tilew
;
6481 oi
"tile-height" c.tileh
dc.tileh
;
6482 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6483 ob "checkers" c.checkers
dc.checkers
;
6484 oi
"aalevel" c.aalevel
dc.aalevel
;
6485 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6486 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6487 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6488 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6489 oC
"color-space" c.colorspace
dc.colorspace
;
6490 ob "invert-colors" c.invert
dc.invert
;
6491 oF
"brightness" c.colorscale
dc.colorscale
;
6492 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6493 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6494 oco
"columns" c.columns
dc.columns
;
6495 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6496 os
"selection-command" c.selcmd
dc.selcmd
;
6497 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6498 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6501 let keymapsbuf always
dc c =
6502 let bb = Buffer.create
16 in
6503 let rec loop = function
6505 | (modename, h) :: rest
->
6506 let dh = findkeyhash dc modename in
6507 if always
|| h <> dh
6509 if Hashtbl.length
h > 0
6511 if Buffer.length
bb > 0
6512 then Buffer.add_char
bb '
\n'
;
6513 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6514 Hashtbl.iter
(fun i
o ->
6515 let isdifferent = always
||
6517 let dO = Hashtbl.find dh i
in
6519 with Not_found
-> true
6524 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6525 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6526 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6527 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6528 Buffer.add_string
bb (Wsi.keyname
k);
6531 let rec loop = function
6533 | km
:: [] -> addkm km
6534 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6538 Buffer.add_string
bb "<map in='";
6542 Buffer.add_string
bb "' out='";
6544 Buffer.add_string
bb "'/>\n"
6547 Buffer.add_string
bb "' out='";
6549 Buffer.add_string
bb "'/>\n"
6551 | KMmulti
(ins, kms
) ->
6552 Buffer.add_char
bb ' '
;
6554 Buffer.add_string
bb "' out='";
6556 Buffer.add_string
bb "'/>\n"
6558 Buffer.add_string
bb "</keymap>";
6568 let uifontsize = fstate.fontsize
in
6569 let bb = Buffer.create
32768 in
6571 let dc = if conf.bedefault
then conf else dc in
6572 Buffer.add_string
bb "<llppconfig>\n";
6574 if String.length
!fontpath > 0
6576 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6582 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6585 Buffer.add_string
bb "<defaults ";
6586 add_attrs bb true dc dc;
6587 let kb = keymapsbuf true dc dc in
6588 if Buffer.length
kb > 0
6590 Buffer.add_string
bb ">\n";
6591 Buffer.add_buffer
bb kb;
6592 Buffer.add_string
bb "\n</defaults>\n";
6594 else Buffer.add_string
bb "/>\n";
6596 let adddoc path pan
anchor c bookmarks =
6597 if bookmarks == [] && c = dc && anchor = emptyanchor
6600 Printf.bprintf
bb "<doc path='%s'"
6601 (enent
path 0 (String.length
path));
6603 if anchor <> emptyanchor
6605 let n, y = anchor in
6606 Printf.bprintf
bb " page='%d'" n;
6609 Printf.bprintf
bb " rely='%f'" y
6614 then Printf.bprintf
bb " pan='%d'" pan
;
6616 add_attrs bb false dc c;
6617 let kb = keymapsbuf false dc c in
6619 begin match bookmarks with
6621 if Buffer.length
kb > 0
6623 Buffer.add_string
bb ">\n";
6624 Buffer.add_buffer
bb kb;
6625 Buffer.add_string
bb "\n</doc>\n";
6627 else Buffer.add_string
bb "/>\n"
6629 Buffer.add_string
bb ">\n<bookmarks>\n";
6630 List.iter
(fun (title, _level
, (page, rely)) ->
6632 "<item title='%s' page='%d'"
6633 (enent
title 0 (String.length
title))
6638 Printf.bprintf
bb " rely='%f'" rely
6640 Buffer.add_string
bb "/>\n";
6642 Buffer.add_string
bb "</bookmarks>";
6643 if Buffer.length
kb > 0
6645 Buffer.add_string
bb "\n";
6646 Buffer.add_buffer
bb kb;
6648 Buffer.add_string
bb "\n</doc>\n";
6654 match state.mode with
6655 | Birdseye
(c, pan, _, _, _) ->
6657 match conf.columns
with
6658 | Cmulti
((c, _, _), _) -> Some
c
6662 match c.columns
with
6663 | Cmulti
(c, _) -> Cmulti
(c, [||])
6664 | Csingle
-> Csingle
6665 | Csplit
_ -> failwith
"quit from bird's eye while split"
6667 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6668 | _ -> state.x, conf
6670 let basename = Filename.basename state.path in
6671 adddoc basename pan (getanchor ())
6674 match state.autoscroll
with
6676 | None
-> conf.autoscrollstep
}
6677 (if conf.savebmarks
then state.bookmarks else []);
6679 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6681 then adddoc path x y c bookmarks
6683 Buffer.add_string
bb "</llppconfig>";
6686 if Buffer.length
bb > 0
6689 let tmp = !confpath ^
".tmp" in
6690 let oc = open_out_bin
tmp in
6691 Buffer.output_buffer
oc bb;
6693 Unix.rename
tmp !confpath;
6696 ("error while saving configuration: " ^
Printexc.to_string exn
)
6703 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6704 "<password> Set password");
6706 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6707 "<path> Set path to the user interface font");
6709 ("-c", Arg.String
(fun s -> Config.confpath := s),
6710 "<path> Set path to the configuration file");
6712 ("-v", Arg.Unit
(fun () ->
6714 "%s\nconfiguration path: %s\n"
6718 exit
0), " Print version and exit");
6721 (fun s -> state.path <- s)
6722 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6724 if String.length
state.path = 0
6725 then (prerr_endline
"file name missing"; exit
1);
6729 let globalkeyhash = findkeyhash conf "global" in
6730 let wsfd, winw, winh
= Wsi.init
(object
6732 if nogeomcmds state.geomcmds
|| platform == Posx
6735 GlFunc.draw_buffer `front
;
6736 GlClear.color (scalecolor2 conf.bgcolor
);
6737 GlClear.clear
[`
color];
6738 GlFunc.draw_buffer `back
;
6740 method display = display ()
6741 method reshape w h = reshape w h
6742 method mouse b d x y m = mouse b d x y m
6743 method motion x y = state.mpos
<- (x, y); motion x y
6744 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6746 let mascm = m land (
6747 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6749 match state.keystate
with
6751 let km = k, mascm in
6754 let modehash = state.uioh#
modehash in
6755 try Hashtbl.find modehash km
6757 try Hashtbl.find globalkeyhash km
6758 with Not_found
-> KMinsrt
(k, m)
6760 | KMinsrt
(k, m) -> keyboard k m
6761 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6762 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6764 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6765 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6766 state.keystate
<- KSnone
6767 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6768 state.keystate
<- KSinto
(keys
, insrt
)
6770 state.keystate
<- KSnone
6772 method enter
x y = state.mpos
<- (x, y); pmotion x y
6773 method leave = state.mpos
<- (-1, -1)
6774 method quit
= raise Quit
6775 end) conf.winw conf.winh
(platform = Posx
) in
6780 List.exists
GlMisc.check_extension
6781 [ "GL_ARB_texture_rectangle"
6782 ; "GL_EXT_texture_recangle"
6783 ; "GL_NV_texture_rectangle" ]
6785 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6788 match Ne.pipe () with
6790 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6794 match Ne.pipe () with
6796 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6806 setcheckers conf.checkers
;
6810 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6811 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6816 state.text <- "Opening " ^
state.path;
6818 opendoc state.path state.password
;
6821 let rec loop deadline
=
6823 match state.errfd
with
6824 | None
-> [state.sr
; state.wsfd]
6825 | Some fd
-> [state.sr
; state.wsfd; fd
]
6829 state.redisplay
<- false;
6836 if deadline
= infinity
6838 else max
0.0 (deadline
-. now)
6843 try Unix.select
r [] [] timeout
6844 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6850 if state.ghyll
== noghyll
6852 match state.autoscroll
with
6853 | Some step
when step
!= 0 ->
6854 let y = state.y + step
in
6858 else if y >= state.maxy then 0 else y
6861 if state.mode = View
6862 then state.text <- "";
6865 else deadline
+. 0.01
6870 let rec checkfds = function
6872 | fd
:: rest
when fd
= state.sr
->
6873 let cmd = readcmd state.sr
in
6877 | fd
:: rest
when fd
= state.wsfd ->
6882 let s = String.create
80 in
6883 let n = Unix.read fd
s 0 80 in
6884 if conf.redirectstderr
6886 Buffer.add_substring
state.errmsgs
s 0 n;
6887 state.newerrmsgs
<- true;
6888 state.redisplay
<- true;
6891 prerr_string
(String.sub
s 0 n);
6899 if deadline
= infinity
6903 match state.autoscroll
with
6904 | Some step
when step
!= 0 -> deadline1
6905 | _ -> if state.ghyll
== noghyll then infinity
else deadline1