4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
9 | Uremote
of (string * int)
10 and facename
= string;;
12 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
13 let now = Unix.gettimeofday
;;
15 type params
= (angle
* proportional
* trimparams
16 * texcount
* sliceheight
* memsize
17 * colorspace
* fontpath
)
26 and proportional
= bool
27 and trimmargins
= bool
28 and interpagespace
= int
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
41 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
42 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
44 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
46 external init
: pipe
-> params
-> unit = "ml_init";;
47 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
48 external copysel
: string -> opaque
-> unit = "ml_copysel";;
49 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
50 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
51 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
52 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
53 external measurestr
: int -> string -> float = "ml_measure_string";;
54 external getmaxw
: unit -> float = "ml_getmaxw";;
55 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
56 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
57 external platform
: unit -> platform
= "ml_platform";;
58 external setaalevel
: int -> unit = "ml_setaalevel";;
59 external realloctexts
: int -> bool = "ml_realloctexts";;
60 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
62 let platform_to_string = function
63 | Punknown
-> "unknown"
67 | Pfreebsd
-> "FreeBSD"
68 | Pdragonflybsd
-> "DragonflyBSD"
69 | Popenbsd
-> "OpenBSD"
74 let platform = platform ();;
80 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
83 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
87 | Msel
of (mpos
* mpos
)
90 | Mzoom
of (int * int)
91 | Mzoomrect
of (mpos
* mpos
)
95 type textentry
= string * string * onhist
option * onkey
* ondone
96 and onkey
= string -> int -> te
97 and ondone
= string -> unit
98 and histcancel
= unit -> unit
99 and onhist
= ((histcmd
-> string) * histcancel
)
100 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
105 | TEswitch
of textentry
116 let bound v minv maxv
=
117 max minv
(min maxv v
);
121 { store
= Array.create n v
128 let drawstring size x y s
=
130 Gl.enable `texture_2d
;
131 ignore
(drawstr size x y s
);
133 Gl.disable `texture_2d
;
136 let drawstring1 size x y s
=
140 let drawstring2 size x y fmt
=
141 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
144 let cbcap b
= Array.length b
.store
;;
149 b
.wc
<- (b
.wc
+ 1) mod cap;
151 b
.len
<- min
(b
.len
+ 1) cap;
154 let cbempty b
= b
.len
= 0;;
156 let cbgetg b circular dir
=
160 let rc = b
.rc + dir
in
172 else max
0 (min
rc (b
.len
-1))
178 let cbget b
= cbgetg b
false;;
179 let cbgetc b
= cbgetg b
true;;
196 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
197 dolog " WxH %dx%d" l
.pagew l
.pageh
;
198 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
199 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
200 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
204 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
206 dolog " x0,y0=(% f, % f)" x0 y0
;
207 dolog " x1,y1=(% f, % f)" x1 y1
;
208 dolog " x2,y2=(% f, % f)" x2 y2
;
209 dolog " x3,y3=(% f, % f)" x3 y3
;
214 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
215 and multicol
= columncount
* covercount
* covercount
217 and columncount
= int
218 and covercount
= int;;
221 { mutable scrollbw
: int
222 ; mutable scrollh
: int
223 ; mutable icase
: bool
224 ; mutable preload
: bool
225 ; mutable pagebias
: int
226 ; mutable verbose
: bool
227 ; mutable debug
: bool
228 ; mutable scrollstep
: int
229 ; mutable maxhfit
: bool
230 ; mutable crophack
: bool
231 ; mutable autoscrollstep
: int
232 ; mutable maxwait
: float option
233 ; mutable hlinks
: bool
234 ; mutable underinfo
: bool
235 ; mutable interpagespace
: interpagespace
236 ; mutable zoom
: float
237 ; mutable presentation
: bool
238 ; mutable angle
: angle
241 ; mutable savebmarks
: bool
242 ; mutable proportional
: proportional
243 ; mutable trimmargins
: trimmargins
244 ; mutable trimfuzz
: irect
245 ; mutable memlimit
: memsize
246 ; mutable texcount
: texcount
247 ; mutable sliceheight
: sliceheight
248 ; mutable thumbw
: width
249 ; mutable jumpback
: bool
250 ; mutable bgcolor
: float * float * float
251 ; mutable bedefault
: bool
252 ; mutable scrollbarinpm
: bool
253 ; mutable tilew
: int
254 ; mutable tileh
: int
255 ; mutable mustoresize
: memsize
256 ; mutable checkers
: bool
257 ; mutable aalevel
: int
258 ; mutable urilauncher
: string
259 ; mutable pathlauncher
: string
260 ; mutable colorspace
: colorspace
261 ; mutable invert
: bool
262 ; mutable colorscale
: float
263 ; mutable redirectstderr
: bool
264 ; mutable ghyllscroll
: (int * int * int) option
265 ; mutable columns
: columns
option
266 ; mutable beyecolumns
: columncount
option
267 ; mutable selcmd
: string
268 ; mutable updatecurs
: bool
272 type anchor
= pageno
* top
;;
274 type outline
= string * int * anchor
;;
276 type rect
= float * float * float * float * float * float * float * float;;
278 type tile
= opaque
* pixmapsize
* elapsed
279 and elapsed
= float;;
280 type pagemapkey
= pageno
* gen
;;
281 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
285 let emptyanchor = (0, 0.0);;
287 type infochange
= | Memused
| Docinfo
| Pdim
;;
289 class type uioh
= object
290 method display
: unit
291 method key
: int -> int -> uioh
292 method button
: int -> bool -> int -> int -> int -> uioh
293 method motion
: int -> int -> uioh
294 method pmotion
: int -> int -> uioh
295 method infochanged
: infochange
-> unit
296 method scrollpw
: (int * float * float)
297 method scrollph
: (int * float * float)
301 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
302 | Textentry
of (textentry
* onleave
)
304 and onleave
= leavetextentrystatus
-> unit
305 and leavetextentrystatus
= | Cancel
| Confirm
306 and helpitem
= string * int * action
309 | Action
of (uioh
-> uioh
)
312 let isbirdseye = function Birdseye _
-> true | _
-> false;;
313 let istextentry = function Textentry _
-> true | _
-> false;;
317 | Loading
of (page
* gen
)
319 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
321 | Outlining
of outline list
324 let nouioh : uioh
= object (self
)
326 method key _ _
= self
327 method button _ _ _ _ _
= self
328 method motion _ _
= self
329 method pmotion _ _
= self
330 method infochanged _
= ()
331 method scrollpw
= (0, nan
, nan
)
332 method scrollph
= (0, nan
, nan
)
336 { mutable sr
: Unix.file_descr
337 ; mutable sw
: Unix.file_descr
338 ; mutable wsfd
: Unix.file_descr
339 ; mutable errfd
: Unix.file_descr
option
340 ; mutable stderr
: Unix.file_descr
341 ; mutable errmsgs
: Buffer.t
342 ; mutable newerrmsgs
: bool
346 ; mutable scrollw
: int
347 ; mutable hscrollh
: int
348 ; mutable anchor
: anchor
349 ; mutable ranchors
: (string * string * anchor
) list
351 ; mutable layout
: page list
352 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
353 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
354 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
355 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
356 ; mutable pagecount
: int
357 ; mutable currently
: currently
358 ; mutable mstate
: mstate
359 ; mutable searchpattern
: string
360 ; mutable rects
: (pageno
* recttype
* rect
) list
361 ; mutable rects1
: (pageno
* recttype
* rect
) list
362 ; mutable text
: string
363 ; mutable fullscreen
: (width
* height
) option
364 ; mutable mode
: mode
365 ; mutable uioh
: uioh
366 ; mutable outlines
: outline array
367 ; mutable bookmarks
: outline list
368 ; mutable path
: string
369 ; mutable password
: string
370 ; mutable invalidated
: int
371 ; mutable memused
: memsize
373 ; mutable throttle
: (page list
* int * float) option
374 ; mutable autoscroll
: int option
375 ; mutable ghyll
: (int option -> unit)
376 ; mutable help
: helpitem array
377 ; mutable docinfo
: (int * string) list
378 ; mutable texid
: GlTex.texture_id
option
380 ; mutable prevzoom
: float
381 ; mutable progress
: float
382 ; mutable redisplay
: bool
383 ; mutable mpos
: mpos
386 { pat
: string circbuf
387 ; pag
: string circbuf
388 ; nav
: anchor circbuf
389 ; sel
: string circbuf
410 ; presentation
= false
415 ; proportional
= true
416 ; trimmargins
= false
417 ; trimfuzz
= (0,0,0,0)
418 ; memlimit
= 32 lsl 20
423 ; bgcolor
= (0.5, 0.5, 0.5)
425 ; scrollbarinpm
= true
428 ; mustoresize
= 128 lsl 20
433 | Plinux
| Pfreebsd
| Pdragonflybsd
434 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
435 | Posx
-> "open \"%s\""
436 | Pcygwin
-> "cygstart %s"
437 | Punknown
-> "echo %s")
438 ; pathlauncher
= "lp \"%s\""
441 | Plinux
| Pfreebsd
| Pdragonflybsd
442 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
449 ; redirectstderr
= false
457 let conf = { defconf with angle
= defconf.angle
};;
460 { mutable fontsize
: int
461 ; mutable wwidth
: float
462 ; mutable maxrows
: int
474 fstate.fontsize
<- n
;
475 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
476 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
480 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
481 let len = String.length s
in
482 if colonpos >= 0 && colonpos + 3 < len
484 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
487 try String.rindex_from s
colonpos ' '
491 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
494 | "http" | "ftp" | "mailto" ->
496 try String.index_from s
colonpos ' '
497 with Not_found
-> len
499 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
507 let shell, farg
= "/bin/sh", "-c" in
509 let args = [|shell; farg
; s
|] in
510 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
514 if String.length
conf.urilauncher
= 0
515 then print_endline uri
517 let url = geturl uri
in
518 if String.length
url = 0
519 then print_endline uri
521 let re = Str.regexp
"%s" in
522 let command = Str.global_replace
re url conf.urilauncher
in
526 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
532 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
533 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
537 let strings = version () :: "" :: Help.keys
in
540 let url = geturl s
in
541 if String.length
url > 0
542 then (s
, 0, Action
(fun u
-> gotouri url; u
))
543 else (s
, 0, Noaction
)
554 ; stderr
= Unix.stderr
555 ; errmsgs
= Buffer.create
0
562 ; anchor
= emptyanchor
566 ; tilelru
= Queue.create
()
567 ; pagemap
= Hashtbl.create
10
568 ; tilemap
= Hashtbl.create
10
585 { nav
= cbnew 10 (0, 0.0)
609 Printf.kprintf prerr_endline fmt
611 Printf.kprintf ignore fmt
615 if String.length
conf.pathlauncher
= 0
616 then print_endline
state.path
618 let re = Str.regexp
"%s" in
619 let command = Str.global_replace
re state.path
conf.pathlauncher
in
623 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
628 let redirectstderr () =
629 if conf.redirectstderr
631 let rfd, wfd
= Unix.pipe
() in
632 state.stderr
<- Unix.dup
Unix.stderr
;
633 state.errfd
<- Some
rfd;
634 Unix.dup2 wfd
Unix.stderr
;
636 state.newerrmsgs
<- false;
637 begin match state.errfd
with
640 Unix.dup2
state.stderr
Unix.stderr
;
644 prerr_string
(Buffer.contents
state.errmsgs
);
646 Buffer.clear
state.errmsgs
;
652 let postRedisplay who
=
654 then prerr_endline
("redisplay for " ^ who
);
655 state.redisplay
<- true;
659 let getopaque pageno
=
660 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
661 with Not_found
-> None
664 let putopaque pageno opaque
=
665 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
668 let pagetranslatepoint l x y
=
669 let dy = y
- l
.pagedispy
in
670 let y = dy + l
.pagey
in
671 let dx = x
- l
.pagedispx
in
672 let x = dx + l
.pagex
in
679 begin match getopaque l
.pageno
with
681 let x0 = l
.pagedispx
in
682 let x1 = x0 + l
.pagevw
in
683 let y0 = l
.pagedispy
in
684 let y1 = y0 + l
.pagevh
in
685 if y >= y0 && y <= y1 && x >= x0 && x <= x1
687 let px, py
= pagetranslatepoint l
x y in
688 match whatsunder opaque
px py
with
701 state.text
<- Printf.sprintf
"%c%s" c s
;
702 G.postRedisplay "showtext";
705 let updateunder x y =
706 match getunder x y with
707 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
709 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
710 Wsi.setcursor
Wsi.CURSOR_INFO
711 | Ulinkgoto
(page
, _
) ->
713 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
714 Wsi.setcursor
Wsi.CURSOR_INFO
716 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
717 Wsi.setcursor
Wsi.CURSOR_TEXT
719 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
720 Wsi.setcursor
Wsi.CURSOR_INHERIT
722 if conf.underinfo
then showtext 'l'
("launch: " ^ s
);
723 Wsi.setcursor
Wsi.CURSOR_INHERIT
725 if conf.underinfo
then showtext 'n'
("named: " ^ s
);
726 Wsi.setcursor
Wsi.CURSOR_INHERIT
727 | Uremote
(filename
, pageno
) ->
728 if conf.underinfo
then showtext 'r'
729 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
730 Wsi.setcursor
Wsi.CURSOR_INFO
734 let b = Buffer.create
(String.length s
+ 1) in
735 Buffer.add_string
b s
;
740 let colorspace_of_string s
=
741 match String.lowercase s
with
745 | _
-> failwith
"invalid colorspace"
748 let int_of_colorspace = function
754 let colorspace_of_int = function
758 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
761 let colorspace_to_string = function
767 let intentry_with_suffix text key
=
769 if key
>= 32 && key
< 127
773 match Char.lowercase
c with
775 let text = addchar text c in
779 let text = addchar text c in
783 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
787 let columns_to_string (n
, a
, b) =
789 then Printf.sprintf
"%d" n
790 else Printf.sprintf
"%d,%d,%d" n a
b;
793 let columns_of_string s
=
795 (int_of_string s
, 0, 0)
797 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
801 let len = String.length s
in
803 let b = Buffer.create
n in
804 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
805 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
806 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
807 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
808 Buffer.add_string
b s
;
809 let s'
= Buffer.contents
b in
810 let n'
= Unix.write fd
s'
0 n in
811 if n'
!= n then failwith
"write failed";
816 let n = Unix.read fd
s 0 4 in
817 if n != 4 then failwith
"incomplete read(len)";
819 lor (Char.code
s.[0] lsl 24)
820 lor (Char.code
s.[1] lsl 16)
821 lor (Char.code
s.[2] lsl 8)
822 lor (Char.code
s.[3] lsl 0)
824 let s = String.create
len in
825 let n = Unix.read fd
s 0 len in
826 if n != len then failwith
"incomplete read(data)";
831 let b = Buffer.create
10 in
832 Buffer.add_string
b s;
833 let rec combine = function
836 Buffer.add_char
b ' '
;
839 | `
b b -> if b then "1" else "0"
841 | `i i
-> string_of_int i
842 | `
f f -> string_of_float
f
843 | `I
f -> string_of_int
(truncate
f)
845 Buffer.add_string
b s;
852 let cmd = Buffer.contents
(makecmd s l
) in
853 writecmd state.sw
cmd;
859 let d = conf.winh
- h
in
866 let rec f pn ph pi fh l
=
868 | (n, _
, h
, _
) :: rest
->
869 let ips = calcips h
in
874 if isbirdseye state.mode
&& pn
= 0
879 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
884 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
888 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
891 let fh = f 0 0 0 0 state.pdims
in
896 match conf.columns
with
897 | None
-> calcheight ()
899 if Array.length
b > 0
901 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
906 let getpageyh pageno
=
907 let rec f pn ph pi
y l
=
909 | (n, _
, h
, _
) :: rest
->
910 let ips = calcips h
in
913 let h = if n = pageno
then h else ph
in
914 if conf.presentation
&& n = pageno
916 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
918 y + (pageno
- pn
) * (ph
+ pi
), h
920 let y = y + (if conf.presentation
then pi
else 0) in
921 let y = y + (n - pn
) * (ph
+ pi
) in
925 y + (pageno
- pn
) * (ph
+ pi
), ph
927 f 0 0 0 0 state.pdims
930 let getpageyh pageno
=
931 match conf.columns
with
932 | None
-> getpageyh pageno
934 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
938 let getpagedim pageno
=
941 | (n, _
, _
, _
) as pdim
:: rest
->
943 then (if n = pageno
then pdim
else ppdim
)
948 f (-1, -1, -1, -1) state.pdims
951 let getpagey pageno
= fst
(getpageyh pageno
);;
954 let sh = sh - state.hscrollh
in
955 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
956 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
958 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
959 let ips = calcips h in
961 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
965 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
967 prev
, pdims
, pdimno
, 0
969 let dy = dy + yinc in
970 let py = py + yinc in
971 if pageno
= state.pagecount
|| dy >= sh
976 if py + h <= vy - yinc
978 let py = py + h + ips in
979 let dy = max
0 (py - y) in
988 let pagey = vy - py in
989 let pagevh = h - pagey in
990 let pagevh = min
(sh - dy) pagevh in
991 let off = if yinc > 0 then py - vy else 0 in
992 let py = py + h + ips in
995 if state.w
< conf.winw
- state.scrollw
996 then (conf.winw
- state.scrollw
- state.w
) / 2
999 let dispx = xoff + state.x in
1005 let lw = w
- pagex in
1006 min
lw (conf.winw
- state.scrollw
)
1010 ; pagedimno
= pdimno
1014 ; pagey = pagey + off
1016 ; pagevh = pagevh - off
1018 ; pagedispy
= dy + off
1021 let accu = e :: accu in
1022 f ~pageno
:(pageno
+1)
1030 if state.invalidated
= 0
1048 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1049 let sh = sh - state.hscrollh
in
1050 let rec fold accu n =
1051 if n = Array.length
b
1054 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1057 || n = state.pagecount
- coverB
1058 || (n - coverA
) mod columns
= columns
- 1)
1064 let pagey = max
0 (y - vy) in
1065 let pagedispy = if pagey > 0 then 0 else vy - y in
1066 let pagedispx, pagex, pagevw =
1068 if n = coverA
- 1 || n = state.pagecount
- coverB
1069 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1070 else dx + xoff + state.x
1073 then 0, -pdx, w
+ pdx
1074 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1076 let pagevh = min
(h - pagey) (sh - pagedispy) in
1077 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1081 ; pagedimno
= pdimno
1088 ; pagedispx = pagedispx
1089 ; pagedispy = pagedispy
1100 if state.invalidated
= 0
1101 then List.rev
(fold [] 0)
1106 match conf.columns
with
1107 | None
-> layout1 y sh
1108 | Some
c -> layoutN c y sh
1112 let y = state.y + incr
in
1114 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1119 let tilex = l
.pagex mod conf.tilew
in
1120 let tiley = l
.pagey mod conf.tileh
in
1122 let col = l
.pagex / conf.tilew
in
1123 let row = l
.pagey / conf.tileh
in
1126 let a = l
.pagew
- l
.pagex in
1127 let b = conf.winw
- state.scrollw
in
1129 and vh
= l
.pagevh in
1131 let rec rowloop row y0 dispy
h =
1135 let dh = conf.tileh
- y0 in
1136 let dh = min
h dh in
1137 let rec colloop col x0 dispx w
=
1141 let dw = conf.tilew
- x0 in
1142 let dw = min w
dw in
1144 f col row dispx dispy
x0 y0 dw dh;
1145 colloop (col+1) 0 (dispx+dw) (w
-dw)
1148 colloop col tilex l
.pagedispx vw;
1149 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1153 then rowloop row tiley l
.pagedispy vh
;
1156 let gettileopaque l
col row =
1158 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1160 try Some
(Hashtbl.find
state.tilemap
key)
1161 with Not_found
-> None
1164 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1165 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1166 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1169 let drawtiles l color
=
1171 let f col row x y tilex tiley w
h =
1172 match gettileopaque l
col row with
1173 | Some
(opaque
, _
, t
) ->
1174 let params = x, y, w
, h, tilex, tiley in
1178 GlFunc.blend_func `zero `one_minus_src_color
;
1180 drawtile
params opaque
;
1182 then Gl.disable `blend
;
1185 let s = Printf.sprintf
1189 let w = measurestr
fstate.fontsize
s in
1190 GlMisc.push_attrib
[`current
];
1191 GlDraw.color
(0.0, 0.0, 0.0);
1193 (float (x-2), float (y-2))
1194 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1195 GlDraw.color
(1.0, 1.0, 1.0);
1196 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1197 GlMisc.pop_attrib
();
1202 let lw = conf.winw
- state.scrollw
- x in
1205 let lh = conf.winh
- y in
1208 Gl.enable `texture_2d
;
1209 begin match state.texid
with
1211 GlTex.bind_texture `texture_2d id
;
1214 and x1 = float (x+w)
1215 and y1 = float (y+h) in
1217 let tw = float w /. 64.0
1218 and th
= float h /. 64.0 in
1219 let tx0 = float tilex /. 64.0
1220 and ty0
= float tiley /. 64.0 in
1222 and ty1
= ty0
+. th
in
1223 GlDraw.begins `quads
;
1224 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1225 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1226 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1227 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1230 Gl.disable `texture_2d
;
1232 GlDraw.color
(1.0, 1.0, 1.0);
1235 (float (x+w), float (y+h));
1237 if w > 128 && h > fstate.fontsize
+ 10
1239 GlDraw.color
(0.0, 0.0, 0.0);
1242 then (col*conf.tilew
, row*conf.tileh
)
1245 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1252 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1254 let tilevisible1 l
x y =
1256 and ax1
= l
.pagex + l
.pagevw
1258 and ay1
= l
.pagey + l
.pagevh in
1262 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1263 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1265 let rx0 = max
ax0 bx0
1266 and ry0
= max ay0 by0
1267 and rx1
= min ax1
bx1
1268 and ry1
= min ay1 by1
in
1270 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1271 nonemptyintersection
1274 let tilevisible layout n x y =
1275 let rec findpageinlayout = function
1276 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1277 | _
:: rest
-> findpageinlayout rest
1280 findpageinlayout layout
1283 let tileready l
x y =
1284 tilevisible1 l
x y &&
1285 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1288 let tilepage n p
layout =
1289 let rec loop = function
1293 let f col row _ _ _ _ _ _
=
1294 if state.currently
= Idle
1296 match gettileopaque l
col row with
1299 let x = col*conf.tilew
1300 and y = row*conf.tileh
in
1302 let w = l
.pagew
- x in
1306 let h = l
.pageh
- y in
1318 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1319 conf.tilew
, conf.tileh
1328 if state.invalidated
= 0 then loop layout;
1331 let preloadlayout visiblepages
=
1332 let presentation = conf.presentation in
1333 let interpagespace = conf.interpagespace in
1334 let maxy = state.maxy in
1335 conf.presentation <- false;
1336 conf.interpagespace <- 0;
1337 state.maxy <- calcheight ();
1339 match visiblepages
with
1341 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1343 let y = if y < conf.winh
then 0 else y - conf.winh
in
1344 let h = state.y - y + conf.winh
*3 in
1345 let pages = layout y h in
1346 conf.presentation <- presentation;
1347 conf.interpagespace <- interpagespace;
1353 let rec loop pages =
1354 if state.currently
!= Idle
1359 begin match getopaque l
.pageno
with
1361 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1362 state.currently
<- Loading
(l
, state.gen
);
1364 tilepage l
.pageno opaque
pages;
1369 if state.invalidated
= 0 then loop pages
1374 if conf.preload && state.currently
= Idle
1375 then load (preloadlayout pages);
1378 let layoutready layout =
1379 let rec fold all ls
=
1380 all
&& match ls
with
1382 let seen = ref false in
1383 let allvisible = ref true in
1384 let foo col row _ _ _ _ _ _
=
1386 allvisible := !allvisible &&
1387 begin match gettileopaque l
col row with
1393 fold (!seen && !allvisible) rest
1396 let alltilesvisible = fold true layout in
1401 let y = bound y 0 state.maxy in
1402 let y, layout, proceed
=
1403 match conf.maxwait
with
1404 | Some time
when state.ghyll
== noghyll ->
1405 begin match state.throttle
with
1407 let layout = layout y conf.winh
in
1408 let ready = layoutready layout in
1412 state.throttle
<- Some
(layout, y, now ());
1414 else G.postRedisplay "gotoy showall (None)";
1416 | Some
(_
, _
, started
) ->
1417 let dt = now () -. started
in
1420 state.throttle
<- None
;
1421 let layout = layout y conf.winh
in
1423 G.postRedisplay "maxwait";
1430 let layout = layout y conf.winh
in
1431 if true || layoutready layout
1432 then G.postRedisplay "gotoy ready";
1438 state.layout <- layout;
1439 begin match state.mode
with
1440 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1441 if not
(pagevisible layout pageno
)
1443 match state.layout with
1446 state.mode
<- Birdseye
(
1447 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1454 state.ghyll
<- noghyll;
1457 let conttiling pageno opaque
=
1458 tilepage pageno opaque
1459 (if conf.preload then preloadlayout state.layout else state.layout)
1462 let gotoy_and_clear_text y =
1464 if not
conf.verbose
then state.text <- "";
1468 match state.layout with
1470 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1473 let getanchory (n, top
) =
1474 let y, h = getpageyh n in
1475 y + (truncate
(top
*. float h));
1478 let gotoanchor anchor
=
1479 gotoy (getanchory anchor
);
1483 cbput state.hists
.nav
(getanchor ());
1487 let anchor = cbgetc state.hists
.nav dir
in
1492 let rec scroll f n a b =
1493 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1495 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1497 then s (float f /. float a)
1500 then 1.0 -. s ((float (f-b) /. float (n-b)))
1507 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1508 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1510 let ins = float a *. iv1
1511 and outs
= float (n-b) *. iv1 in
1513 ins +. outs
+. float ones
1515 let rec set (_N
, _A
, _B
) y sy
=
1516 let sum = summa
1.0 _N _A _B
in
1517 let dy = float (y - sy
) in
1521 then state.ghyll
<- noghyll
1524 let s = scroll n _N _A _B
in
1525 let y1 = y1 +. ((s *. dy) /. sum) in
1526 gotoy_and_clear_text (truncate
y1);
1527 state.ghyll
<- gf (n+1) y1;
1531 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1533 gf 0 (float state.y)
1536 match conf.ghyllscroll
with
1538 gotoy_and_clear_text y
1540 if state.ghyll
== noghyll
1541 then set nab
y state.y
1542 else state.ghyll
(Some
y)
1545 let gotopage n top
=
1546 let y, h = getpageyh n in
1547 let y = y + (truncate
(top
*. float h)) in
1551 let gotopage1 n top
=
1552 let y = getpagey n in
1562 state.invalidated
<- state.invalidated
+ 1;
1565 let writeopen path password
=
1566 writecmd state.sw
("open " ^ path ^
"\000" ^ password ^
"\000");
1569 let opendoc path password
=
1572 state.password
<- password
;
1573 state.gen
<- state.gen
+ 1;
1574 state.docinfo
<- [];
1576 setaalevel
conf.aalevel
;
1577 writeopen path password
;
1578 Wsi.settitle
("llpp " ^
Filename.basename path
);
1579 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1583 let c = c *. conf.colorscale
in
1587 let scalecolor2 (r
, g
, b) =
1588 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1592 let docolumns = function
1594 | Some
((columns
, coverA
, coverB
), _
) ->
1595 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1596 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1597 if pageno
= state.pagecount
1600 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1602 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1603 pdimno+1, pdim
, rest
1608 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1610 (conf.winw
- state.scrollw
- w) / 2,
1611 y + rowh
+ conf.interpagespace, h
1614 if (pageno
- coverA
) mod columns
= 0
1615 then 0, y + rowh
+ conf.interpagespace, h
1616 else x, y, max rowh
h
1619 let rec fixrow m
= if m
= pageno
then () else
1620 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1623 let y = y + (rowh
- h) / 2 in
1624 a.(m
) <- (pdimno, x, y, pdim
);
1628 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1629 then fixrow (pageno
- columns
);
1630 a.(pageno
) <- (pdimno, x, y, pdim
);
1631 let x = x + w + xoff*2 + conf.interpagespace in
1632 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1634 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1635 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1637 docolumns conf.columns
;
1638 state.maxy <- calcheight ();
1640 if state.w <= conf.winw
- state.scrollw
1644 match state.mode
with
1645 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1646 let y, h = getpageyh pageno
in
1647 let top = (conf.winh
- h) / 2 in
1648 gotoy (max
0 (y - top))
1649 | _
-> gotoanchor state.anchor
1653 let firsttime = ref true in
1655 GlDraw.viewport
0 0 w h;
1656 if state.invalidated
= 0 && not
!firsttime
1657 then state.anchor <- getanchor ();
1661 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1665 setfontsize fstate.fontsize
;
1666 GlMat.mode `modelview
;
1667 GlMat.load_identity
();
1669 GlMat.mode `projection
;
1670 GlMat.load_identity
();
1671 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1672 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1673 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1676 match conf.columns
with
1678 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1681 wcmd "geometry" [`i
w; `i
h];
1685 let len = String.length
state.text in
1688 match state.mode
with
1689 | View
-> state.hscrollh
1694 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1695 (x+.w, float (conf.winh
- hscrollh))
1698 let w = float (conf.winw
- state.scrollw
- 1) in
1699 if state.progress
>= 0.0 && state.progress
< 1.0
1701 GlDraw.color
(0.3, 0.3, 0.3);
1702 let w1 = w *. state.progress
in
1704 GlDraw.color
(0.0, 0.0, 0.0);
1708 GlDraw.color
(0.0, 0.0, 0.0);
1712 GlDraw.color
(1.0, 1.0, 1.0);
1713 drawstring fstate.fontsize
1714 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1717 match state.mode
with
1718 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1722 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1724 Printf.sprintf
"%s%s_" prefix
text
1733 if not
(istextentry state.mode
)
1735 let s1 = "(press 'e' to review error messasges)" in
1736 if String.length
s > 0 then s ^
" " ^
s1 else s1
1741 if String.length
s > 0
1746 let len = Queue.length
state.tilelru
in
1748 if state.memused
<= conf.memlimit
1753 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1754 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1755 let (_
, pw
, ph
, _
) = getpagedim n in
1758 && colorspace
= conf.colorspace
1759 && angle
= conf.angle
1764 match state.throttle
with
1767 then preloadlayout state.layout
1769 | Some
(layout, _
, _
) ->
1772 let x = col*conf.tilew
1773 and y = row*conf.tileh
in
1774 tilevisible layout n x y
1776 then Queue.push lruitem
state.tilelru
1778 wcmd "freetile" [`
s p
];
1779 state.memused
<- state.memused
- s;
1780 state.uioh#infochanged Memused
;
1781 Hashtbl.remove
state.tilemap k
;
1790 Queue.iter
(fun (k
, p
, s) ->
1791 wcmd "freetile" [`
s p
];
1792 state.memused
<- state.memused
- s;
1793 state.uioh#infochanged Memused
;
1794 Hashtbl.remove
state.tilemap k
;
1796 Queue.clear
state.tilelru
;
1800 let logcurrently = function
1801 | Idle
-> dolog "Idle"
1802 | Loading
(l
, gen
) ->
1803 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1804 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1806 "Tiling %d[%d,%d] page=%s cs=%s angle"
1807 l
.pageno
col row pageopaque
1808 (colorspace_to_string colorspace
)
1810 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1811 angle gen
conf.angle
state.gen
1813 conf.tilew
conf.tileh
1820 (* dolog "%S" cmds; *)
1823 try String.index cmds ' '
1824 with Not_found
-> -1
1829 let l = String.length cmds
in
1830 let op = String.sub cmds
0 spacepos in
1832 if l - spacepos < 2 then ""
1833 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1838 state.uioh#infochanged Pdim
;
1842 state.rects
<- state.rects1
;
1843 G.postRedisplay "clearrects";
1847 try Scanf.sscanf
args "%u" (fun n -> n)
1849 dolog "error processing 'continue' %S: %s"
1850 cmds
(Printexc.to_string exn
);
1853 state.pagecount
<- n;
1854 state.invalidated
<- state.invalidated
- 1;
1855 begin match state.currently
with
1857 state.currently
<- Idle
;
1858 state.outlines
<- Array.of_list
(List.rev
l)
1861 if state.invalidated
= 0
1863 if conf.maxwait
= None
1864 then G.postRedisplay "continue";
1874 then showtext ' '
args
1877 let progress, text =
1879 Scanf.sscanf
args "%f %n"
1881 f, String.sub
args pos
(String.length
args - pos
))
1883 dolog "error processing 'progress' %S: %s"
1884 cmds
(Printexc.to_string exn
);
1888 state.progress <- progress;
1889 G.postRedisplay "progress"
1892 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1894 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1895 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1896 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1898 dolog "error processing 'firstmatch' %S: %s"
1899 cmds
(Printexc.to_string exn
);
1902 let y = (getpagey pageno) + truncate
y0 in
1905 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1908 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1910 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1911 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1912 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1914 dolog "error processing 'match' %S: %s"
1915 cmds
(Printexc.to_string exn
);
1919 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1924 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1926 dolog "error processing 'page' %S: %s"
1927 cmds
(Printexc.to_string exn
);
1930 begin match state.currently
with
1931 | Loading
(l, gen
) ->
1932 vlog "page %d took %f sec" l.pageno t
;
1933 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1934 begin match state.throttle
with
1936 let preloadedpages =
1938 then preloadlayout state.layout
1943 Set.Make
(struct type t
= int let compare = (-) end) in
1945 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1946 IntSet.empty
preloadedpages
1949 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1950 if not
(IntSet.mem
pageno set)
1952 wcmd "freepage" [`
s opaque
];
1958 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1961 state.currently
<- Idle
;
1964 tilepage l.pageno pageopaque state.layout;
1966 load preloadedpages;
1967 if pagevisible state.layout l.pageno
1968 && layoutready state.layout
1969 then G.postRedisplay "page";
1972 | Some
(layout, _
, _
) ->
1973 state.currently
<- Idle
;
1974 tilepage l.pageno pageopaque layout;
1979 dolog "Inconsistent loading state";
1980 logcurrently state.currently
;
1985 let (x, y, opaque
, size
, t
) =
1987 Scanf.sscanf
args "%u %u %s %u %f"
1988 (fun x y p size t
-> (x, y, p
, size
, t
))
1990 dolog "error processing 'tile' %S: %s"
1991 cmds
(Printexc.to_string exn
);
1994 begin match state.currently
with
1995 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1996 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1998 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2000 wcmd "freetile" [`
s opaque
];
2001 state.currently
<- Idle
;
2005 puttileopaque l col row gen cs angle opaque size t
;
2006 state.memused
<- state.memused
+ size
;
2007 state.uioh#infochanged Memused
;
2009 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2010 opaque
, size
) state.tilelru
;
2013 match state.throttle
with
2014 | None
-> state.layout
2015 | Some
(layout, _
, _
) -> layout
2018 state.currently
<- Idle
;
2020 && conf.colorspace
= cs
2021 && conf.angle
= angle
2022 && tilevisible layout l.pageno x y
2023 then conttiling l.pageno pageopaque;
2025 begin match state.throttle
with
2027 preload state.layout;
2029 && conf.colorspace
= cs
2030 && conf.angle
= angle
2031 && tilevisible state.layout l.pageno x y
2032 then G.postRedisplay "tile nothrottle";
2034 | Some
(layout, y, _
) ->
2035 let ready = layoutready layout in
2039 state.layout <- layout;
2040 state.throttle
<- None
;
2041 G.postRedisplay "throttle";
2048 dolog "Inconsistent tiling state";
2049 logcurrently state.currently
;
2056 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2058 dolog "error processing 'pdim' %S: %s"
2059 cmds
(Printexc.to_string exn
);
2062 state.uioh#infochanged Pdim
;
2063 state.pdims
<- pdim :: state.pdims
2066 let (l, n, t
, h, pos
) =
2068 Scanf.sscanf
args "%u %u %d %u %n"
2069 (fun l n t
h pos
-> l, n, t
, h, pos
)
2071 dolog "error processing 'o' %S: %s"
2072 cmds
(Printexc.to_string exn
);
2075 let s = String.sub
args pos
(String.length
args - pos
) in
2076 let outline = (s, l, (n, float t
/. float h)) in
2077 begin match state.currently
with
2078 | Outlining outlines
->
2079 state.currently
<- Outlining
(outline :: outlines
)
2081 state.currently
<- Outlining
[outline]
2083 dolog "invalid outlining state";
2084 logcurrently currently
2088 state.docinfo
<- (1, args) :: state.docinfo
2091 state.uioh#infochanged Docinfo
;
2092 state.docinfo
<- List.rev
state.docinfo
2095 dolog "unknown cmd `%S'" cmds
2100 let action = function
2101 | HCprev
-> cbget cb ~
-1
2102 | HCnext
-> cbget cb
1
2103 | HCfirst
-> cbget cb ~
-(cb
.rc)
2104 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2105 and cancel
() = cb
.rc <- rc
2109 let search pattern forward
=
2110 if String.length pattern
> 0
2113 match state.layout with
2116 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2119 let b = makecmd "search"
2120 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2122 Buffer.add_char
b '
,'
;
2123 Buffer.add_string
b pattern
;
2124 Buffer.add_char
b '
\000'
;
2127 writecmd state.sw
cmd;
2130 let intentry text key =
2132 if key >= 32 && key < 127
2138 let text = addchar text c in
2142 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2146 let textentry text key =
2147 if key land 0xff00 = 0xff00
2149 else TEcont
(text ^
Wsi.toutf8
key)
2152 let reqlayout angle proportional
=
2153 match state.throttle
with
2155 if state.invalidated
= 0 then state.anchor <- getanchor ();
2156 conf.angle
<- angle
mod 360;
2157 conf.proportional
<- proportional
;
2159 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2163 let settrim trimmargins trimfuzz
=
2164 if state.invalidated
= 0 then state.anchor <- getanchor ();
2165 conf.trimmargins
<- trimmargins
;
2166 conf.trimfuzz
<- trimfuzz
;
2167 let x0, y0, x1, y1 = trimfuzz
in
2170 `
b conf.trimmargins
;
2176 Hashtbl.iter
(fun _ opaque
->
2177 wcmd "freepage" [`
s opaque
];
2179 Hashtbl.clear
state.pagemap
;
2183 match state.throttle
with
2185 let zoom = max
0.01 zoom in
2186 if zoom <> conf.zoom
2188 state.prevzoom
<- conf.zoom;
2191 then (state.x <- 0; 0.0)
2192 else float state.x /. float state.w
2195 reshape conf.winw
conf.winh
;
2198 let x = relx *. float state.w in
2199 state.x <- truncate
x;
2201 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2204 | Some
(layout, y, started
) ->
2206 match conf.maxwait
with
2210 let dt = now () -. started
in
2218 let setcolumns columns coverA coverB
=
2221 conf.columns
<- None
;
2226 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2229 reshape conf.winw
conf.winh
;
2232 let enterbirdseye () =
2233 let zoom = float conf.thumbw
/. float conf.winw
in
2234 let birdseyepageno =
2235 let cy = conf.winh
/ 2 in
2239 let rec fold best
= function
2242 let d = cy - (l.pagedispy + l.pagevh/2)
2243 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2244 if abs
d < abs dbest
2251 state.mode
<- Birdseye
(
2252 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2255 conf.presentation <- false;
2256 conf.interpagespace <- 10;
2257 conf.hlinks
<- false;
2259 state.mstate
<- Mnone
;
2260 conf.maxwait
<- None
;
2262 match conf.beyecolumns
with
2265 Some
((c, 0, 0), [||])
2268 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2271 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2276 reshape conf.winw
conf.winh
;
2279 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2281 conf.zoom <- c.zoom;
2282 conf.presentation <- c.presentation;
2283 conf.interpagespace <- c.interpagespace;
2284 conf.maxwait
<- c.maxwait
;
2285 conf.hlinks
<- c.hlinks
;
2286 conf.beyecolumns
<- (
2287 match conf.columns
with
2288 | Some
((c, _
, _
), _
) -> Some
c
2292 match c.columns
with
2293 | Some
(c, _
) -> Some
(c, [||])
2299 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2302 reshape conf.winw
conf.winh
;
2303 state.anchor <- if goback
then anchor else (pageno, 0.0);
2306 let togglebirdseye () =
2307 match state.mode
with
2308 | Birdseye vals
-> leavebirdseye vals
true
2309 | View
-> enterbirdseye ()
2313 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2314 let pageno = max
0 (pageno - incr
) in
2315 let rec loop = function
2316 | [] -> gotopage1 pageno 0
2317 | l :: _
when l.pageno = pageno ->
2318 if l.pagedispy >= 0 && l.pagey = 0
2319 then G.postRedisplay "upbirdseye"
2320 else gotopage1 pageno 0
2321 | _
:: rest
-> loop rest
2324 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2327 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2328 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2329 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2330 let rec loop = function
2332 let y, h = getpageyh pageno in
2333 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2335 | l :: _
when l.pageno = pageno ->
2336 if l.pagevh != l.pageh
2337 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2338 else G.postRedisplay "downbirdseye"
2339 | _
:: rest
-> loop rest
2344 let optentry mode _
key =
2345 let btos b = if b then "on" else "off" in
2346 if key >= 32 && key < 127
2348 let c = Char.chr
key in
2352 try conf.scrollstep
<- int_of_string
s with exc
->
2353 state.text <- Printf.sprintf
"bad integer `%s': %s"
2354 s (Printexc.to_string exc
)
2356 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2361 conf.autoscrollstep
<- int_of_string
s;
2362 if state.autoscroll
<> None
2363 then state.autoscroll
<- Some
conf.autoscrollstep
2365 state.text <- Printf.sprintf
"bad integer `%s': %s"
2366 s (Printexc.to_string exc
)
2368 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2373 let n, a, b = columns_of_string s in
2376 state.text <- Printf.sprintf
"bad columns `%s': %s"
2377 s (Printexc.to_string exc
)
2379 TEswitch
("columns: ", "", None
, textentry, ondone)
2384 let zoom = float (int_of_string
s) /. 100.0 in
2387 state.text <- Printf.sprintf
"bad integer `%s': %s"
2388 s (Printexc.to_string exc
)
2390 TEswitch
("zoom: ", "", None
, intentry, ondone)
2395 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2397 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2398 begin match mode
with
2400 leavebirdseye beye
false;
2405 state.text <- Printf.sprintf
"bad integer `%s': %s"
2406 s (Printexc.to_string exc
)
2408 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2413 Some
(int_of_string
s)
2415 state.text <- Printf.sprintf
"bad integer `%s': %s"
2416 s (Printexc.to_string exc
);
2419 | Some angle
-> reqlayout angle
conf.proportional
2422 TEswitch
("rotation: ", "", None
, intentry, ondone)
2425 conf.icase
<- not
conf.icase
;
2426 TEdone
("case insensitive search " ^
(btos conf.icase
))
2429 conf.preload <- not
conf.preload;
2431 TEdone
("preload " ^
(btos conf.preload))
2434 conf.verbose
<- not
conf.verbose
;
2435 TEdone
("verbose " ^
(btos conf.verbose
))
2438 conf.debug
<- not
conf.debug
;
2439 TEdone
("debug " ^
(btos conf.debug
))
2442 conf.maxhfit
<- not
conf.maxhfit
;
2444 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2445 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2448 conf.crophack
<- not
conf.crophack
;
2449 TEdone
("crophack " ^
btos conf.crophack
)
2453 match conf.maxwait
with
2455 conf.maxwait
<- Some infinity
;
2456 "always wait for page to complete"
2458 conf.maxwait
<- None
;
2459 "show placeholder if page is not ready"
2464 conf.underinfo
<- not
conf.underinfo
;
2465 TEdone
("underinfo " ^
btos conf.underinfo
)
2468 conf.savebmarks
<- not
conf.savebmarks
;
2469 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2475 match state.layout with
2480 conf.interpagespace <- int_of_string
s;
2481 state.maxy <- calcheight ();
2482 let y = getpagey pageno in
2485 state.text <- Printf.sprintf
"bad integer `%s': %s"
2486 s (Printexc.to_string exc
)
2488 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2491 reqlayout conf.angle
(not
conf.proportional
);
2492 TEdone
("proportional display " ^
btos conf.proportional
)
2495 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2496 TEdone
("trim margins " ^
btos conf.trimmargins
)
2499 conf.invert
<- not
conf.invert
;
2500 TEdone
("invert colors " ^
btos conf.invert
)
2504 cbput state.hists
.sel
s;
2507 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2511 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2517 class type lvsource
= object
2518 method getitemcount
: int
2519 method getitem
: int -> (string * int)
2520 method hasaction
: int -> bool
2529 method getactive
: int
2530 method getfirst
: int
2531 method getqsearch
: string
2532 method setqsearch
: string -> unit
2536 class virtual lvsourcebase
= object
2537 val mutable m_active
= 0
2538 val mutable m_first
= 0
2539 val mutable m_qsearch
= ""
2540 val mutable m_pan
= 0
2541 method getactive
= m_active
2542 method getfirst
= m_first
2543 method getqsearch
= m_qsearch
2544 method getpan
= m_pan
2545 method setqsearch
s = m_qsearch
<- s
2548 let withoutlastutf8 s =
2549 let len = String.length
s in
2557 let b = Char.code
s.[pos
] in
2558 if b land 0b110000 = 0b11000000
2563 if Char.code
s.[len-1] land 0x80 = 0
2567 String.sub
s 0 first;
2570 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2572 state.mode
<- Textentry
(te
, onleave
);
2575 G.postRedisplay "textentrykeyboard enttext";
2577 let histaction cmd =
2580 | Some
(action, _
) ->
2581 state.mode
<- Textentry
(
2582 (c, action cmd, opthist
, onkey
, ondone), onleave
2584 G.postRedisplay "textentry histaction"
2587 | 0xff08 -> (* backspace *)
2588 let s = withoutlastutf8 text in
2589 let len = String.length
s in
2593 G.postRedisplay "textentrykeyboard after cancel";
2596 enttext (c, s, opthist
, onkey
, ondone)
2602 G.postRedisplay "textentrykeyboard after confirm"
2604 | 0xff52 -> histaction HCprev
2605 | 0xff54 -> histaction HCnext
2606 | 0xff50 -> histaction HCfirst
2607 | 0xff57 -> histaction HClast
2609 | 0xff1b -> (* escape*)
2610 if String.length
text = 0
2612 begin match opthist
with
2614 | Some
(_
, onhistcancel
) -> onhistcancel
()
2618 G.postRedisplay "textentrykeyboard after cancel2"
2621 enttext (c, "", opthist
, onkey
, ondone)
2624 | 0xff9f | 0xffff -> () (* delete *)
2626 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2627 begin match onkey
text key with
2631 G.postRedisplay "textentrykeyboard after confirm2";
2634 enttext (c, text, opthist
, onkey
, ondone);
2638 G.postRedisplay "textentrykeyboard after cancel3"
2641 state.mode
<- Textentry
(te
, onleave
);
2642 G.postRedisplay "textentrykeyboard switch";
2646 vlog "unhandled key %#x" key
2649 let firstof first active
=
2650 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2651 then max
0 (active
- (fstate.maxrows
/2))
2655 let calcfirst first active
=
2658 let rows = active
- first in
2659 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2663 let scrollph y maxy =
2664 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2665 let sh = float conf.winh
/. sh in
2666 let sh = max
sh (float conf.scrollh
) in
2671 else float y /. float maxy
2673 let position = (float conf.winh
-. sh) *. percent in
2676 if position +. sh > float conf.winh
2677 then float conf.winh
-. sh
2683 let coe s = (s :> uioh
);;
2685 class listview ~
(source
:lvsource
) ~trusted
=
2687 val m_pan
= source#getpan
2688 val m_first
= source#getfirst
2689 val m_active
= source#getactive
2690 val m_qsearch
= source#getqsearch
2691 val m_prev_uioh
= state.uioh
2693 method private elemunder
y =
2694 let n = y / (fstate.fontsize
+1) in
2695 if m_first
+ n < source#getitemcount
2697 if source#hasaction
(m_first
+ n)
2698 then Some
(m_first
+ n)
2705 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2706 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2707 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2708 GlDraw.color
(1., 1., 1.);
2709 Gl.enable `texture_2d
;
2710 let fs = fstate.fontsize
in
2712 let ww = fstate.wwidth
in
2713 let tabw = 30.0*.ww in
2714 let itemcount = source#getitemcount
in
2716 if (row - m_first
) * nfs > conf.winh
2719 if row >= 0 && row < itemcount
2721 let (s, level
) = source#getitem
row in
2722 let y = (row - m_first
) * nfs in
2723 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2726 Gl.disable `texture_2d
;
2727 GlDraw.polygon_mode `both `line
;
2728 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2729 GlDraw.rect (1., float (y + 1))
2730 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2731 GlDraw.polygon_mode `both `fill
;
2732 GlDraw.color
(1., 1., 1.);
2733 Gl.enable `texture_2d
;
2736 let drawtabularstring s =
2737 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2740 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2743 let len = String.length
s - tabpos - 1 in
2744 let s1 = String.sub
s 0 tabpos
2745 and s2
= String.sub
s (tabpos + 1) len in
2746 let nx = drawstr x s1 in
2748 let x = x +. (max
tabw sw) in
2755 let _ = drawtabularstring s in
2762 Gl.disable `texture_2d
;
2764 method updownlevel incr
=
2765 let len = source#getitemcount
in
2767 if m_active
>= 0 && m_active
< len
2768 then snd
(source#getitem m_active
)
2772 if i
= len then i
-1 else if i
= -1 then 0 else
2773 let _, l = source#getitem i
in
2774 if l != curlevel then i
else flow (i
+incr
)
2776 let active = flow m_active
in
2777 let first = calcfirst m_first
active in
2778 G.postRedisplay "outline updownlevel";
2779 {< m_active
= active; m_first
= first >}
2781 method private key1
key mask
=
2782 let set1 active first qsearch
=
2783 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2785 let search active pattern incr
=
2788 if n >= 0 && n < source#getitemcount
2790 let s, _ = source#getitem
n in
2792 (try ignore
(Str.search_forward
re s 0); true
2793 with Not_found
-> false)
2795 else loop (n + incr
)
2802 let re = Str.regexp_case_fold pattern
in
2808 let itemcount = source#getitemcount
in
2809 let find start incr
=
2811 if i
= -1 || i
= itemcount
2814 if source#hasaction i
2816 else find (i
+ incr
)
2821 let set active first =
2822 let first = bound first 0 (itemcount - fstate.maxrows
) in
2824 coe {< m_active
= active; m_first
= first >}
2827 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2829 let incr1 = if incr
> 0 then 1 else -1 in
2830 if isvisible m_first m_active
2833 let next = m_active
+ incr
in
2835 if next < 0 || next >= itemcount
2837 else find next incr1
2839 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2845 let first = m_first
+ incr
in
2846 let first = bound first 0 (itemcount - 1) in
2848 let next = m_active
+ incr
in
2849 let next = bound next 0 (itemcount - 1) in
2852 let active = if next = -1 then m_active
else next in
2855 let first = min
next m_first
in
2857 if abs
(next - first) > fstate.maxrows
2863 let first = m_first
+ incr
in
2864 let first = bound first 0 (itemcount - 1) in
2866 let next = m_active
+ incr
in
2867 let next = bound next 0 (itemcount - 1) in
2868 let next = find next incr1 in
2870 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2872 let active = if m_active
= -1 then next else m_active
in
2877 if isvisible first active
2883 G.postRedisplay "listview navigate";
2887 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2888 let incr = if key = 0x72 then -1 else 1 in
2890 match search (m_active
+ incr) m_qsearch
incr with
2892 state.text <- m_qsearch ^
" [not found]";
2895 state.text <- m_qsearch
;
2896 active, firstof m_first
active
2898 G.postRedisplay "listview ctrl-r/s";
2899 set1 active first m_qsearch
;
2901 | 0xff08 -> (* backspace *)
2902 if String.length m_qsearch
= 0
2905 let qsearch = withoutlastutf8 m_qsearch
in
2906 let len = String.length
qsearch in
2910 G.postRedisplay "listview empty qsearch";
2911 set1 m_active m_first
"";
2915 match search m_active
qsearch ~
-1 with
2917 state.text <- qsearch ^
" [not found]";
2920 state.text <- qsearch;
2921 active, firstof m_first
active
2923 G.postRedisplay "listview backspace qsearch";
2924 set1 active first qsearch
2927 | key when ((key >= 32 && key < 127)
2928 || (key != 0 && key land 0xff00 != 0xff00)) ->
2930 if key >= 32 && key < 127
2931 then addchar m_qsearch
(Char.chr
key)
2932 else m_qsearch ^
Wsi.toutf8
key
2935 match search m_active
pattern 1 with
2937 state.text <- pattern ^
" [not found]";
2940 state.text <- pattern;
2941 active, firstof m_first
active
2943 G.postRedisplay "listview qsearch add";
2944 set1 active first pattern;
2946 | 0xff1b -> (* escape *)
2948 if String.length m_qsearch
= 0
2950 G.postRedisplay "list view escape";
2953 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2955 | None
-> m_prev_uioh
2960 G.postRedisplay "list view kill qsearch";
2961 source#setqsearch
"";
2962 coe {< m_qsearch
= "" >}
2965 | 0xff0d -> (* return *)
2967 let self = {< m_qsearch
= "" >} in
2968 source#setqsearch
"";
2970 G.postRedisplay "listview enter";
2971 if m_active
>= 0 && m_active
< source#getitemcount
2973 source#exit
(coe self) false m_active m_first m_pan
"";
2976 source#exit
(coe self) true m_active m_first m_pan
"";
2979 begin match opt with
2980 | None
-> m_prev_uioh
2984 | 0xff9f | 0xffff -> (* delete *)
2987 | 0xff52 -> navigate ~
-1 (* up *)
2988 | 0xff54 -> navigate 1 (* down *)
2989 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
2990 | 0xff56 -> navigate fstate.maxrows
(* next *)
2992 | 0xff53 -> (* right *)
2994 G.postRedisplay "listview right";
2995 coe {< m_pan
= m_pan
- 1 >}
2997 | 0xff51 -> (* left *)
2999 G.postRedisplay "listview left";
3000 coe {< m_pan
= m_pan
+ 1 >}
3002 | 0xff50 -> (* home *)
3003 let active = find 0 1 in
3004 G.postRedisplay "listview home";
3007 | 0xff57 -> (* end *)
3008 let first = max
0 (itemcount - fstate.maxrows
) in
3009 let active = find (itemcount - 1) ~
-1 in
3010 G.postRedisplay "listview end";
3013 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3017 dolog "listview unknown key %#x" key; coe self
3019 method key key mask
=
3020 match state.mode
with
3021 | Textentry te
-> textentrykeyboard key mask te
; coe self
3022 | _ -> self#key1
key mask
3024 method button button down
x y _ =
3027 | 1 when x > conf.winw
- conf.scrollbw
->
3028 G.postRedisplay "listview scroll";
3031 let _, position, sh = self#
scrollph in
3032 if y > truncate
position && y < truncate
(position +. sh)
3034 state.mstate
<- Mscrolly
;
3038 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3039 let first = truncate
(s *. float source#getitemcount
) in
3040 let first = min source#getitemcount
first in
3041 Some
(coe {< m_first
= first; m_active
= first >})
3043 state.mstate
<- Mnone
;
3046 | 1 when not down
->
3047 begin match self#elemunder
y with
3049 G.postRedisplay "listview click";
3051 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3055 | n when (n == 4 || n == 5) && not down
->
3056 let len = source#getitemcount
in
3058 if n = 5 && m_first
+ fstate.maxrows
>= len
3062 let first = m_first
+ (if n == 4 then -1 else 1) in
3063 bound first 0 (len - 1)
3065 G.postRedisplay "listview wheel";
3066 Some
(coe {< m_first
= first >})
3071 | None
-> m_prev_uioh
3075 match state.mstate
with
3077 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3078 let first = truncate
(s *. float source#getitemcount
) in
3079 let first = min source#getitemcount
first in
3080 G.postRedisplay "listview motion";
3081 coe {< m_first
= first; m_active
= first >}
3084 method pmotion
x y =
3085 if x < conf.winw
- conf.scrollbw
3088 match self#elemunder
y with
3089 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3090 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3094 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3099 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3103 method infochanged
_ = ()
3105 method scrollpw
= (0, 0.0, 0.0)
3107 let nfs = fstate.fontsize
+ 1 in
3108 let y = m_first
* nfs in
3109 let itemcount = source#getitemcount
in
3110 let maxi = max
0 (itemcount - fstate.maxrows
) in
3111 let maxy = maxi * nfs in
3112 let p, h = scrollph y maxy in
3116 class outlinelistview ~source
=
3118 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3120 method key key mask
=
3121 let calcfirst first active =
3124 let rows = active - first in
3125 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3129 let active = m_active
+ incr in
3130 let active = bound active 0 (source#getitemcount
- 1) in
3131 let first = calcfirst m_first
active in
3132 G.postRedisplay "outline navigate";
3133 coe {< m_active
= active; m_first
= first >}
3135 let ctrl = Wsi.withctrl mask
in
3137 | 110 when ctrl -> (* ctrl-n *)
3138 source#narrow m_qsearch
;
3139 G.postRedisplay "outline ctrl-n";
3140 coe {< m_first
= 0; m_active
= 0 >}
3142 | 117 when ctrl -> (* ctrl-u *)
3144 G.postRedisplay "outline ctrl-u";
3146 coe {< m_first
= 0; m_active
= 0 >}
3148 | 108 when ctrl -> (* ctrl-l *)
3149 let first = m_active
- (fstate.maxrows
/ 2) in
3150 G.postRedisplay "outline ctrl-l";
3151 coe {< m_first
= first >}
3153 | 0xff9f | 0xffff -> (* delete *)
3154 source#remove m_active
;
3155 G.postRedisplay "outline delete";
3156 let active = max
0 (m_active
-1) in
3157 coe {< m_first
= firstof m_first
active;
3158 m_active
= active >}
3160 | 0xff52 -> navigate ~
-1 (* up *)
3161 | 0xff54 -> navigate 1 (* down *)
3162 | 0xff55 -> (* prior *)
3163 navigate ~
-(fstate.maxrows
)
3164 | 0xff56 -> (* next *)
3165 navigate fstate.maxrows
3167 | 0xff53 -> (* [ctrl-]right *)
3171 G.postRedisplay "outline ctrl right";
3172 {< m_pan
= m_pan
+ 1 >}
3174 else self#updownlevel
1
3178 | 0xff51 -> (* [ctrl-]left *)
3182 G.postRedisplay "outline ctrl left";
3183 {< m_pan
= m_pan
- 1 >}
3185 else self#updownlevel ~
-1
3189 | 0xff50 -> (* home *)
3190 G.postRedisplay "outline home";
3191 coe {< m_first
= 0; m_active
= 0 >}
3193 | 0xff57 -> (* end *)
3194 let active = source#getitemcount
- 1 in
3195 let first = max
0 (active - fstate.maxrows
) in
3196 G.postRedisplay "outline end";
3197 coe {< m_active
= active; m_first
= first >}
3199 | _ -> super#
key key mask
3202 let outlinesource usebookmarks
=
3205 inherit lvsourcebase
3206 val mutable m_items
= empty
3207 val mutable m_orig_items
= empty
3208 val mutable m_prev_items
= empty
3209 val mutable m_narrow_pattern
= ""
3210 val mutable m_hadremovals
= false
3212 method getitemcount
=
3213 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3216 if n == Array.length m_items
&& m_hadremovals
3218 ("[Confirm removal]", 0)
3220 let s, n, _ = m_items
.(n) in
3223 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3224 ignore
(uioh
, first, qsearch);
3225 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3227 if String.length m_narrow_pattern
= 0
3233 if not
confrimremoval
3235 let _, _, anchor = m_items
.(active) in
3240 state.bookmarks
<- Array.to_list m_items
;
3241 m_orig_items
<- m_items
;
3244 else m_items
<- items;
3248 method hasaction
_ = true
3251 if Array.length m_items
!= Array.length m_orig_items
3252 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3255 method narrow
pattern =
3256 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3260 let rec loop accu n =
3263 m_narrow_pattern
<- pattern;
3264 m_items
<- Array.of_list
accu
3267 let (s, _, _) as o = m_items
.(n) in
3269 if (try ignore
(Str.search_forward
re s 0); true
3270 with Not_found
-> false)
3276 loop [] (Array.length m_items
- 1)
3281 then Array.of_list
state.bookmarks
3284 m_items
<- m_orig_items
3289 if m
>= 0 && m
< Array.length m_items
3291 m_hadremovals
<- true;
3292 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3293 let n = if n >= m
then n+1 else n in
3298 method reset
anchor items =
3299 m_hadremovals
<- false;
3300 if m_orig_items
== empty || m_prev_items
!= items
3302 m_orig_items
<- items;
3303 if String.length m_narrow_pattern
= 0
3304 then m_items
<- items;
3306 m_prev_items
<- items;
3307 let rely = getanchory anchor in
3309 let rec loop n best bestd
=
3310 if n = Array.length m_items
3313 let (_, _, anchor) = m_items
.(n) in
3314 let orely = getanchory anchor in
3315 let d = abs
(orely - rely) in
3318 else loop (n+1) best bestd
3323 m_first
<- firstof m_first
active
3327 let enterselector usebookmarks
=
3328 let source = outlinesource usebookmarks
in
3332 then Array.of_list
state.bookmarks
3335 if Array.length
outlines = 0
3337 showtext ' ' errmsg
;
3340 state.text <- source#greetmsg
;
3341 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3342 let anchor = getanchor () in
3343 source#reset
anchor outlines;
3344 state.uioh
<- coe (new outlinelistview ~
source);
3345 G.postRedisplay "enter selector";
3349 let enteroutlinemode =
3350 let f = enterselector false in
3351 fun ()-> f "Document has no outline";
3354 let enterbookmarkmode =
3355 let f = enterselector true in
3356 fun () -> f "Document has no bookmarks (yet)";
3359 let color_of_string s =
3360 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3361 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3365 let color_to_string (r
, g
, b) =
3366 let r = truncate
(r *. 256.0)
3367 and g
= truncate
(g
*. 256.0)
3368 and b = truncate
(b *. 256.0) in
3369 Printf.sprintf
"%d/%d/%d" r g
b
3372 let irect_of_string s =
3373 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3376 let irect_to_string (x0,y0,x1,y1) =
3377 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3380 let makecheckers () =
3381 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3383 converted by Issac Trotts. July 25, 2002 *)
3384 let image_height = 64
3385 and image_width
= 64 in
3389 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3391 for i
= 0 to image_width
- 1 do
3392 for j
= 0 to image_height - 1 do
3393 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3394 (if (i
land 8 ) lxor (j
land 8) = 0
3395 then [|255;255;255|] else [|200;200;200|])
3400 let image = make_image () in
3401 let id = GlTex.gen_texture
() in
3402 GlTex.bind_texture `texture_2d
id;
3403 GlPix.store
(`unpack_alignment
1);
3404 GlTex.image2d
image;
3405 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3408 `mag_filter `nearest
;
3409 `min_filter `nearest
];
3413 let setcheckers enabled
=
3414 match state.texid
with
3416 if enabled
then state.texid
<- Some
(makecheckers ())
3421 GlTex.delete_texture texid
;
3422 state.texid
<- None
;
3426 let int_of_string_with_suffix s =
3427 let l = String.length
s in
3431 let suffix = Char.lowercase
s.[l-1] in
3433 | 'k'
-> String.sub
s 0 (l-1), 10
3434 | 'm'
-> String.sub
s 0 (l-1), 20
3435 | 'g'
-> String.sub
s 0 (l-1), 30
3439 let n = int_of_string
s1 in
3440 let m = n lsl shift
in
3442 then raise
(Failure
"value too large")
3446 let string_with_suffix_of_int n =
3454 if n land ((1 lsl 20) - 1) = 0
3457 if n land ((1 lsl 10) - 1) = 0
3464 let h = n mod 1000 in
3467 then string_of_int
h ^
s
3469 let s = Printf.sprintf
"_%03d%s" h s in
3476 let defghyllscroll = (40, 8, 32);;
3477 let ghyllscroll_of_string s =
3478 let (n, a, b) as nab
=
3481 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3483 if n <= a || n <= b || a >= b
3484 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3488 let ghyllscroll_to_string ((n, a, b) as nab
) =
3489 if nab
= defghyllscroll
3491 else Printf.sprintf
"%d,%d,%d" n a b;
3494 let describe_location () =
3496 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3498 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3499 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3503 else (100. *. (float state.y /. float maxy))
3507 Printf.sprintf
"page %d of %d [%.2f%%]"
3508 (fn+1) state.pagecount
percent
3511 "pages %d-%d of %d [%.2f%%]"
3512 (fn+1) (ln
+1) state.pagecount
percent
3516 let btos b = if b then "\xe2\x88\x9a" else "" in
3517 let showextended = ref false in
3518 let leave mode
= function
3519 | Confirm
-> state.mode
<- mode
3520 | Cancel
-> state.mode
<- mode
in
3523 val mutable m_first_time
= true
3524 val mutable m_l
= []
3525 val mutable m_a
= [||]
3526 val mutable m_prev_uioh
= nouioh
3527 val mutable m_prev_mode
= View
3529 inherit lvsourcebase
3531 method reset prev_mode prev_uioh
=
3532 m_a
<- Array.of_list
(List.rev m_l
);
3534 m_prev_mode
<- prev_mode
;
3535 m_prev_uioh
<- prev_uioh
;
3539 if n >= Array.length m_a
3543 | _, _, _, Action
_ -> m_active
<- n
3547 m_first_time
<- false;
3550 method int name get
set =
3552 (name
, `
int get
, 1, Action
(
3555 try set (int_of_string
s)
3557 state.text <- Printf.sprintf
"bad integer `%s': %s"
3558 s (Printexc.to_string exn
)
3561 let te = name ^
": ", "", None
, intentry, ondone in
3562 state.mode
<- Textentry
(te, leave m_prev_mode
);
3566 method int_with_suffix name get
set =
3568 (name
, `intws get
, 1, Action
(
3571 try set (int_of_string_with_suffix s)
3573 state.text <- Printf.sprintf
"bad integer `%s': %s"
3574 s (Printexc.to_string exn
)
3578 name ^
": ", "", None
, intentry_with_suffix, ondone
3580 state.mode
<- Textentry
(te, leave m_prev_mode
);
3584 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3586 (name
, `
bool (btos, get
), offset
, Action
(
3593 method color name get
set =
3595 (name
, `color get
, 1, Action
(
3597 let invalid = (nan
, nan
, nan
) in
3600 try color_of_string s
3602 state.text <- Printf.sprintf
"bad color `%s': %s"
3603 s (Printexc.to_string exn
);
3609 let te = name ^
": ", "", None
, textentry, ondone in
3610 state.text <- color_to_string (get
());
3611 state.mode
<- Textentry
(te, leave m_prev_mode
);
3615 method string name get
set =
3617 (name
, `
string get
, 1, Action
(
3619 let ondone s = set s in
3620 let te = name ^
": ", "", None
, textentry, ondone in
3621 state.mode
<- Textentry
(te, leave m_prev_mode
);
3625 method colorspace name get
set =
3627 (name
, `
string get
, 1, Action
(
3630 let vals = [| "rgb"; "bgr"; "gray" |] in
3632 inherit lvsourcebase
3635 m_active
<- int_of_colorspace conf.colorspace
;
3638 method getitemcount
= Array.length
vals
3639 method getitem
n = (vals.(n), 0)
3640 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3641 ignore
(uioh
, first, pan
, qsearch);
3642 if not cancel
then set active;
3644 method hasaction
_ = true
3648 coe (new listview ~
source ~trusted
:true)
3651 method caption
s offset
=
3652 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3654 method caption2
s f offset
=
3655 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3657 method getitemcount
= Array.length m_a
3660 let tostr = function
3661 | `
int f -> string_of_int
(f ())
3662 | `intws
f -> string_with_suffix_of_int (f ())
3664 | `color
f -> color_to_string (f ())
3665 | `
bool (btos, f) -> btos (f ())
3668 let name, t
, offset
, _ = m_a
.(n) in
3669 ((let s = tostr t
in
3670 if String.length
s > 0
3671 then Printf.sprintf
"%s\t%s" name s
3675 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3679 m_qsearch
<- qsearch;
3681 match m_a
.(active) with
3682 | _, _, _, Action
f -> f uioh
3694 method hasaction
n =
3696 | _, _, _, Action
_ -> true
3700 let rec fillsrc prevmode prevuioh
=
3701 let sep () = src#caption
"" 0 in
3702 let colorp name get
set =
3704 (fun () -> color_to_string (get
()))
3707 let c = color_of_string v in
3710 state.text <- Printf.sprintf
"bad color `%s': %s"
3711 v (Printexc.to_string exn
);
3714 let oldmode = state.mode
in
3715 let birdseye = isbirdseye state.mode
in
3717 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3719 src#
bool "presentation mode"
3720 (fun () -> conf.presentation)
3722 conf.presentation <- v;
3723 state.anchor <- getanchor ();
3726 src#
bool "ignore case in searches"
3727 (fun () -> conf.icase
)
3728 (fun v -> conf.icase
<- v);
3731 (fun () -> conf.preload)
3732 (fun v -> conf.preload <- v);
3734 src#
bool "highlight links"
3735 (fun () -> conf.hlinks
)
3736 (fun v -> conf.hlinks
<- v);
3738 src#
bool "under info"
3739 (fun () -> conf.underinfo
)
3740 (fun v -> conf.underinfo
<- v);
3742 src#
bool "persistent bookmarks"
3743 (fun () -> conf.savebmarks
)
3744 (fun v -> conf.savebmarks
<- v);
3746 src#
bool "proportional display"
3747 (fun () -> conf.proportional
)
3748 (fun v -> reqlayout conf.angle
v);
3750 src#
bool "trim margins"
3751 (fun () -> conf.trimmargins
)
3752 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3754 src#
bool "persistent location"
3755 (fun () -> conf.jumpback
)
3756 (fun v -> conf.jumpback
<- v);
3759 src#
int "inter-page space"
3760 (fun () -> conf.interpagespace)
3762 conf.interpagespace <- n;
3764 match state.layout with
3769 state.maxy <- calcheight ();
3770 let y = getpagey pageno in
3775 (fun () -> conf.pagebias
)
3776 (fun v -> conf.pagebias
<- v);
3778 src#
int "scroll step"
3779 (fun () -> conf.scrollstep
)
3780 (fun n -> conf.scrollstep
<- n);
3782 src#
int "auto scroll step"
3784 match state.autoscroll
with
3786 | _ -> conf.autoscrollstep
)
3788 if state.autoscroll
<> None
3789 then state.autoscroll
<- Some
n;
3790 conf.autoscrollstep
<- n);
3793 (fun () -> truncate
(conf.zoom *. 100.))
3794 (fun v -> setzoom ((float v) /. 100.));
3797 (fun () -> conf.angle
)
3798 (fun v -> reqlayout v conf.proportional
);
3800 src#
int "scroll bar width"
3801 (fun () -> state.scrollw
)
3805 reshape conf.winw
conf.winh
;
3808 src#
int "scroll handle height"
3809 (fun () -> conf.scrollh
)
3810 (fun v -> conf.scrollh
<- v;);
3812 src#
int "thumbnail width"
3813 (fun () -> conf.thumbw
)
3815 conf.thumbw
<- min
4096 v;
3818 leavebirdseye beye
false;
3823 src#
string "columns"
3825 match conf.columns
with
3827 | Some
(multicol
, _) -> columns_to_string multicol
)
3829 let n, a, b = columns_of_string v in
3833 src#caption
"Presentation mode" 0;
3834 src#
bool "scrollbar visible"
3835 (fun () -> conf.scrollbarinpm
)
3837 if v != conf.scrollbarinpm
3839 conf.scrollbarinpm
<- v;
3840 if conf.presentation
3842 state.scrollw
<- if v then conf.scrollbw
else 0;
3843 reshape conf.winw
conf.winh
;
3849 src#caption
"Pixmap cache" 0;
3850 src#int_with_suffix
"size (advisory)"
3851 (fun () -> conf.memlimit
)
3852 (fun v -> conf.memlimit
<- v);
3855 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3856 (string_with_suffix_of_int state.memused
)
3857 (Hashtbl.length
state.tilemap
)) 1;
3860 src#caption
"Layout" 0;
3861 src#caption2
"Dimension"
3863 Printf.sprintf
"%dx%d (virtual %dx%d)"
3869 src#caption2
"Position" (fun () ->
3870 Printf.sprintf
"%dx%d" state.x state.y
3873 src#caption2
"Visible" (fun () -> describe_location ()) 1
3877 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3878 "Save these parameters as global defaults at exit"
3879 (fun () -> conf.bedefault
)
3880 (fun v -> conf.bedefault
<- v)
3884 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3885 src#
bool ~offset
:0 ~
btos "Extended parameters"
3886 (fun () -> !showextended)
3887 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3891 (fun () -> conf.checkers
)
3892 (fun v -> conf.checkers
<- v; setcheckers v);
3893 src#
bool "update cursor"
3894 (fun () -> conf.updatecurs
)
3895 (fun v -> conf.updatecurs
<- v);
3897 (fun () -> conf.verbose
)
3898 (fun v -> conf.verbose
<- v);
3899 src#
bool "invert colors"
3900 (fun () -> conf.invert
)
3901 (fun v -> conf.invert
<- v);
3903 (fun () -> conf.maxhfit
)
3904 (fun v -> conf.maxhfit
<- v);
3905 src#
bool "redirect stderr"
3906 (fun () -> conf.redirectstderr)
3907 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3908 src#
string "uri launcher"
3909 (fun () -> conf.urilauncher
)
3910 (fun v -> conf.urilauncher
<- v);
3911 src#
string "path launcher"
3912 (fun () -> conf.pathlauncher
)
3913 (fun v -> conf.pathlauncher
<- v);
3914 src#
string "tile size"
3915 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3918 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3919 conf.tileh
<- max
64 w;
3920 conf.tilew
<- max
64 h;
3923 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3924 v (Printexc.to_string exn
));
3925 src#
int "texture count"
3926 (fun () -> conf.texcount
)
3929 then conf.texcount
<- v
3930 else showtext '
!'
" Failed to set texture count please retry later"
3932 src#
int "slice height"
3933 (fun () -> conf.sliceheight
)
3935 conf.sliceheight
<- v;
3936 wcmd "sliceh" [`i
conf.sliceheight
];
3938 src#
int "anti-aliasing level"
3939 (fun () -> conf.aalevel
)
3941 conf.aalevel
<- bound v 0 8;
3942 state.anchor <- getanchor ();
3943 opendoc state.path
state.password
;
3945 src#
int "ui font size"
3946 (fun () -> fstate.fontsize
)
3947 (fun v -> setfontsize (bound v 5 100));
3948 colorp "background color"
3949 (fun () -> conf.bgcolor
)
3950 (fun v -> conf.bgcolor
<- v);
3951 src#
bool "crop hack"
3952 (fun () -> conf.crophack
)
3953 (fun v -> conf.crophack
<- v);
3954 src#
string "trim fuzz"
3955 (fun () -> irect_to_string conf.trimfuzz
)
3958 conf.trimfuzz
<- irect_of_string v;
3960 then settrim true conf.trimfuzz
;
3962 state.text <- Printf.sprintf
"bad irect `%s': %s"
3963 v (Printexc.to_string exn
)
3965 src#
string "throttle"
3967 match conf.maxwait
with
3968 | None
-> "show place holder if page is not ready"
3971 then "wait for page to fully render"
3973 "wait " ^ string_of_float
time
3974 ^
" seconds before showing placeholder"
3978 let f = float_of_string
v in
3980 then conf.maxwait
<- None
3981 else conf.maxwait
<- Some
f
3983 state.text <- Printf.sprintf
"bad time `%s': %s"
3984 v (Printexc.to_string exn
)
3986 src#
string "ghyll scroll"
3988 match conf.ghyllscroll
with
3990 | Some nab
-> ghyllscroll_to_string nab
3995 if String.length
v = 0
3997 else Some
(ghyllscroll_of_string v)
3999 conf.ghyllscroll
<- gs
4001 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4002 v (Printexc.to_string exn
)
4004 src#
string "selection command"
4005 (fun () -> conf.selcmd
)
4006 (fun v -> conf.selcmd
<- v);
4007 src#colorspace
"color space"
4008 (fun () -> colorspace_to_string conf.colorspace
)
4010 conf.colorspace
<- colorspace_of_int v;
4017 src#caption
"Document" 0;
4018 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4019 src#caption2
"Pages"
4020 (fun () -> string_of_int
state.pagecount
) 1;
4021 src#caption2
"Dimensions"
4022 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4026 src#caption
"Trimmed margins" 0;
4027 src#caption2
"Dimensions"
4028 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4031 src#reset prevmode prevuioh
;
4035 let prevmode = state.mode
4036 and prevuioh
= state.uioh in
4037 fillsrc prevmode prevuioh
;
4038 let source = (src :> lvsource
) in
4039 state.uioh <- coe (object (self)
4040 inherit listview ~
source ~trusted
:true as super
4041 val mutable m_prevmemused
= 0
4042 method infochanged
= function
4044 if m_prevmemused
!= state.memused
4046 m_prevmemused
<- state.memused
;
4047 G.postRedisplay "memusedchanged";
4049 | Pdim
-> G.postRedisplay "pdimchanged"
4050 | Docinfo
-> fillsrc prevmode prevuioh
4052 method key key mask
=
4053 if not
(Wsi.withctrl mask
)
4056 | 0xff51 -> coe (self#updownlevel ~
-1)
4057 | 0xff53 -> coe (self#updownlevel
1)
4058 | _ -> super#
key key mask
4059 else super#
key key mask
4061 G.postRedisplay "info";
4067 inherit lvsourcebase
4068 method getitemcount
= Array.length
state.help
4070 let s, n, _ = state.help
.(n) in
4073 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4077 m_qsearch
<- qsearch;
4078 match state.help
.(active) with
4079 | _, _, Action
f -> Some
(f uioh)
4089 method hasaction
n =
4090 match state.help
.(n) with
4091 | _, _, Action
_ -> true
4098 state.uioh <- coe (new listview ~
source ~trusted
:true);
4099 G.postRedisplay "help";
4104 let re = Str.regexp
"[\r\n]" in
4106 inherit lvsourcebase
4107 val mutable m_items
= [||]
4109 method getitemcount
= 1 + Array.length m_items
4114 else m_items
.(n-1), 0
4116 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4121 then Buffer.clear
state.errmsgs
;
4122 m_qsearch
<- qsearch;
4129 method hasaction
n =
4133 state.newerrmsgs
<- false;
4134 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4135 m_items
<- Array.of_list
l
4143 let source = (msgsource :> lvsource
) in
4144 state.uioh <- coe (object
4145 inherit listview ~
source ~trusted
:false as super
4148 then msgsource#reset
;
4151 G.postRedisplay "msgs";
4154 let quickbookmark ?title
() =
4155 match state.layout with
4161 let sec = Unix.gettimeofday
() in
4162 let tm = Unix.localtime
sec in
4163 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4167 (tm.Unix.tm_year
+ 1900)
4170 | Some
title -> title
4173 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4178 state.fullscreen
<- None
;
4182 let setautoscrollspeed step goingdown
=
4183 let incr = max
1 ((abs step
) / 2) in
4184 let incr = if goingdown
then incr else -incr in
4185 let astep = step
+ incr in
4186 state.autoscroll
<- Some
astep;
4189 let viewkeyboard key mask
=
4191 let mode = state.mode in
4192 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4195 G.postRedisplay "view:enttext"
4197 let ctrl = Wsi.withctrl mask
in
4202 | 0xff1b | 113 -> (* escape / q *)
4203 begin match state.mstate
with
4205 state.mstate
<- Mnone
;
4206 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4207 G.postRedisplay "kill zoom rect";
4209 match state.ranchors
with
4210 | [] -> raise
Wsi.Quit
4211 | (path
, password
, anchor) :: rest
->
4212 state.ranchors
<- rest
;
4213 state.anchor <- anchor;
4214 opendoc path password
4217 | 0xff08 -> (* backspace *)
4218 let y = getnav ~
-1 in
4219 gotoy_and_clear_text y
4227 G.postRedisplay "dehighlight";
4229 | 47 | 63 -> (* / ? *)
4230 let ondone isforw
s =
4231 cbput state.hists
.pat
s;
4232 state.searchpattern
<- s;
4235 let s = String.create
1 in
4236 s.[0] <- Char.chr
key;
4237 enttext (s, "", Some
(onhist state.hists
.pat
),
4238 textentry, ondone (key = 47))
4240 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4241 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4242 setzoom (conf.zoom +. incr)
4244 | 43 | 0xffab -> (* + *)
4247 try int_of_string
s with exc
->
4248 state.text <- Printf.sprintf
"bad integer `%s': %s"
4249 s (Printexc.to_string exc
);
4255 state.text <- "page bias is now " ^ string_of_int
n;
4258 enttext ("page bias: ", "", None
, intentry, ondone)
4260 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4261 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4262 setzoom (max
0.01 (conf.zoom -. decr))
4264 | 45 | 0xffad -> (* - *)
4265 let ondone msg
= state.text <- msg
in
4267 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4268 optentry state.mode, ondone
4271 | 48 when ctrl -> (* ctrl-0 *)
4274 | 49 when ctrl -> (* 1 *)
4275 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4279 | 0xffc6 -> (* f9 *)
4282 | 57 when ctrl -> (* ctrl-9 *)
4285 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4286 when not
ctrl -> (* 0..9 *)
4289 try int_of_string
s with exc
->
4290 state.text <- Printf.sprintf
"bad integer `%s': %s"
4291 s (Printexc.to_string exc
);
4297 cbput state.hists
.pag
(string_of_int
n);
4298 gotopage1 (n + conf.pagebias
- 1) 0;
4301 let pageentry text key =
4302 match Char.unsafe_chr
key with
4303 | 'g'
-> TEdone
text
4304 | _ -> intentry text key
4306 let text = "x" in text.[0] <- Char.chr
key;
4307 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4310 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4311 reshape conf.winw
conf.winh
;
4314 conf.hlinks
<- not
conf.hlinks
;
4315 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4316 G.postRedisplay "toggle highlightlinks";
4319 begin match state.autoscroll
with
4321 conf.autoscrollstep
<- step
;
4322 state.autoscroll
<- None
4324 if conf.autoscrollstep
= 0
4325 then state.autoscroll
<- Some
1
4326 else state.autoscroll
<- Some
conf.autoscrollstep
4330 conf.presentation <- not
conf.presentation;
4331 if conf.presentation
4333 if not
conf.scrollbarinpm
4334 then state.scrollw
<- 0;
4337 state.scrollw
<- conf.scrollbw
;
4339 showtext ' '
("presentation mode " ^
4340 if conf.presentation then "on" else "off");
4341 state.anchor <- getanchor ();
4345 begin match state.fullscreen
with
4347 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4350 state.fullscreen
<- None
;
4355 gotoy_and_clear_text 0
4358 gotopage1 (state.pagecount
- 1) 0
4360 | 112 | 78 -> (* p|N *)
4361 search state.searchpattern
false
4363 | 110 | 0xffc0 -> (* n|F3 *)
4364 search state.searchpattern
true
4367 begin match state.layout with
4370 gotoy_and_clear_text (getpagey l.pageno)
4374 begin match List.rev
state.layout with
4377 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4378 gotoy_and_clear_text (getpagey pageno)
4381 | 0xff9f | 0xffff -> (* delete *)
4382 begin match state.layout with
4385 let pageno = max
0 (l.pageno-1) in
4386 gotoy_and_clear_text (getpagey pageno)
4390 showtext ' '
(describe_location ());
4393 begin match state.layout with
4396 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4401 enterbookmarkmode ()
4403 | 104 | 0xffbe -> (* h|F1 *)
4409 | 101 when conf.redirectstderr -> (* e *)
4414 match state.layout with
4417 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4421 enttext ("bookmark: ", "", None
, textentry, ondone)
4425 showtext ' '
"Quick bookmark added";
4428 begin match state.layout with
4430 let rect = getpdimrect
l.pagedimno
in
4434 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4435 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4437 (truncate
(rect.(1) -. rect.(0)),
4438 truncate
(rect.(3) -. rect.(0)))
4440 let w = truncate
((float w)*.conf.zoom)
4441 and h = truncate
((float h)*.conf.zoom) in
4444 state.anchor <- getanchor ();
4445 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4447 G.postRedisplay "z";
4452 | 50 when ctrl -> (* ctrl-2 *)
4453 let maxw = getmaxw
() in
4455 then setzoom (maxw /. float conf.winw
)
4457 | 60 | 62 -> (* < > *)
4458 reqlayout (conf.angle
+ (if key = 60 then 30 else -30)) conf.proportional
4460 | 91 | 93 -> (* [ ] *)
4462 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4464 G.postRedisplay "brightness";
4466 | 107 | 0xff52 -> (* k up *)
4467 begin match state.autoscroll
with
4469 begin match state.mode with
4470 | Birdseye beye
-> upbirdseye 1 beye
4473 then gotoy (clamp ~
-(conf.winh
/2))
4474 else gotoy (clamp (-conf.scrollstep
))
4477 setautoscrollspeed n false
4480 | 106 | 0xff54 -> (* j down *)
4481 begin match state.autoscroll
with
4483 begin match state.mode with
4484 | Birdseye beye
-> downbirdseye 1 beye
4487 then gotoy_and_clear_text (clamp (conf.winh
/2))
4488 else gotoy_and_clear_text (clamp conf.scrollstep
)
4491 setautoscrollspeed n true
4494 | 0xff51 | 0xff53 when conf.zoom > 1.0 -> (* left / right *)
4502 let dx = if key = 0xff51 then dx else -dx in
4503 state.x <- state.x + dx;
4504 gotoy_and_clear_text state.y
4507 G.postRedisplay "lef/right"
4510 | 0xff55 -> (* prior *)
4514 match state.layout with
4516 | l :: _ -> state.y - l.pagey
4522 | 0xff56 -> (* next *)
4526 match List.rev
state.layout with
4528 | l :: _ -> getpagey l.pageno
4534 | 0xff50 -> gotoghyll 0
4535 | 0xff57 -> gotoghyll (clamp state.maxy)
4536 | 0xff53 when Wsi.withalt mask
->
4537 gotoghyll (getnav ~
-1)
4538 | 0xff51 when Wsi.withalt mask
->
4539 gotoghyll (getnav 1)
4542 state.anchor <- getanchor ();
4543 opendoc state.path
state.password
4548 | 118 when conf.debug
-> (* v *)
4551 match getopaque l.pageno with
4554 let x0, y0, x1, y1 = pagebbox opaque
in
4555 let a,b = float x0, float y0 in
4556 let c,d = float x1, float y0 in
4557 let e,f = float x1, float y1 in
4558 let h,j
= float x0, float y1 in
4559 let rect = (a,b,c,d,e,f,h,j
) in
4561 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4563 G.postRedisplay "v";
4569 let keyboard key mask
=
4570 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4571 then wcmd "interrupt" []
4572 else state.uioh <- state.uioh#
key key mask
4575 let birdseyekeyboard key mask
4576 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4578 match conf.columns
with
4580 | Some
((c, _, _), _) -> c
4583 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4584 let y, h = getpageyh pageno in
4585 let top = (conf.winh
- h) / 2 in
4586 gotoy (max
0 (y - top))
4587 | 0xff0d -> leavebirdseye beye
false
4588 | 0xff1b -> leavebirdseye beye
true (* escape *)
4589 | 0xff52 -> upbirdseye incr beye
(* prior *)
4590 | 0xff54 -> downbirdseye incr beye
(* next *)
4591 | 0xff51 -> upbirdseye 1 beye
(* up *)
4592 | 0xff53 -> downbirdseye 1 beye
(* down *)
4595 begin match state.layout with
4599 state.mode <- Birdseye
(
4600 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4602 gotopage1 l.pageno 0;
4605 let layout = layout (state.y-conf.winh
) conf.winh
in
4607 | [] -> gotoy (clamp (-conf.winh
))
4609 state.mode <- Birdseye
(
4610 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4612 gotopage1 l.pageno 0
4615 | [] -> gotoy (clamp (-conf.winh
))
4619 begin match List.rev
state.layout with
4621 let layout = layout (state.y + conf.winh
) conf.winh
in
4622 begin match layout with
4624 let incr = l.pageh
- l.pagevh in
4629 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4631 G.postRedisplay "birdseye pagedown";
4633 else gotoy (clamp (incr + conf.interpagespace*2));
4637 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4638 gotopage1 l.pageno 0;
4641 | [] -> gotoy (clamp conf.winh
)
4645 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4649 let pageno = state.pagecount
- 1 in
4650 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4651 if not
(pagevisible state.layout pageno)
4654 match List.rev
state.pdims
with
4656 | (_, _, h, _) :: _ -> h
4658 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4659 else G.postRedisplay "birdseye end";
4660 | _ -> viewkeyboard key mask
4665 match state.mode with
4666 | Textentry
_ -> scalecolor 0.4
4667 | View
-> scalecolor 1.0
4668 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4669 if l.pageno = hooverpageno
4672 if l.pageno = pageno
4678 begin match getopaque l.pageno with
4680 if tileready l l.pagex l.pagey
4682 let x = l.pagedispx - l.pagex
4683 and y = l.pagedispy - l.pagey in
4684 postprocess opaque
conf.hlinks
x y;
4690 let scrollindicator () =
4691 let sbw, ph
, sh = state.uioh#
scrollph in
4692 let sbh, pw
, sw = state.uioh#scrollpw
in
4694 GlDraw.color (0.64, 0.64, 0.64);
4696 (float (conf.winw
- sbw), 0.)
4697 (float conf.winw
, float conf.winh
)
4700 (0., float (conf.winh
- sbh))
4701 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4703 GlDraw.color (0.0, 0.0, 0.0);
4706 (float (conf.winw
- sbw), ph
)
4707 (float conf.winw
, ph
+. sh)
4710 (pw
, float (conf.winh
- sbh))
4711 (pw
+. sw, float conf.winh
)
4716 match state.mstate
with
4717 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4720 | Msel
((x0, y0), (x1, y1)) ->
4721 let rec loop = function
4723 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4724 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4725 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4726 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4728 match getopaque l.pageno with
4730 let dx, dy = pagetranslatepoint l 0 0 in
4735 GlMat.mode `modelview
;
4737 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4738 seltext opaque
(x0, y0, x1, y1);
4749 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4750 GlDraw.polygon_mode `both `fill
;
4751 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4753 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4755 if l.pageno = pageno
4757 let dx = float (l.pagedispx - l.pagex) in
4758 let dy = float (l.pagedispy - l.pagey) in
4759 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4760 GlDraw.begins `quads
;
4762 GlDraw.vertex2
(x0+.dx, y0+.dy);
4763 GlDraw.vertex2
(x1+.dx, y1+.dy);
4764 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4765 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4776 GlClear.color (scalecolor2 conf.bgcolor
);
4777 GlClear.clear
[`
color];
4778 List.iter
drawpage state.layout;
4783 begin match state.mstate
with
4784 | Mzoomrect
((x0, y0), (x1, y1)) ->
4786 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4787 GlDraw.polygon_mode `both `fill
;
4788 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4789 GlDraw.rect (float x0, float y0)
4790 (float x1, float y1);
4797 let mx, my
= state.mpos
in
4803 let zoomrect x y x1 y1 =
4806 and y0 = min
y y1 in
4807 gotoy (state.y + y0);
4808 state.anchor <- getanchor ();
4809 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4811 if state.w < conf.winw
- state.scrollw
4812 then (conf.winw
- state.scrollw
- state.w) / 2
4815 state.x <- (state.x + margin) - x0;
4817 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4818 state.mstate
<- Mnone
;
4822 let winw = conf.winw - state.scrollw
- 1 in
4823 let s = float x /. float winw in
4824 let destx = truncate
(float (state.w + winw) *. s) in
4825 state.x <- winw - destx;
4826 gotoy_and_clear_text state.y;
4827 state.mstate
<- Mscrollx
;
4831 let s = float y /. float conf.winh
in
4832 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4833 gotoy_and_clear_text desty;
4834 state.mstate
<- Mscrolly
;
4837 let viewmouse button down
x y mask
=
4839 | n when (n == 4 || n == 5) && not down
->
4840 if Wsi.withctrl mask
4842 match state.mstate
with
4843 | Mzoom
(oldn
, i
) ->
4851 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4853 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4855 let zoom = conf.zoom -. incr in
4857 state.mstate
<- Mzoom
(n, 0);
4859 state.mstate
<- Mzoom
(n, i
+1);
4861 else state.mstate
<- Mzoom
(n, 0)
4863 | _ -> state.mstate
<- Mzoom
(n, 0)
4866 match state.autoscroll
with
4867 | Some step
-> setautoscrollspeed step
(n=4)
4871 then -conf.scrollstep
4872 else conf.scrollstep
4874 let incr = incr * 2 in
4875 let y = clamp incr in
4876 gotoy_and_clear_text y
4879 | 1 when Wsi.withctrl mask
->
4882 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
4883 state.mstate
<- Mpan
(x, y)
4886 state.mstate
<- Mnone
4891 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4893 state.mstate
<- Mzoomrect
(p, p)
4896 match state.mstate
with
4897 | Mzoomrect
((x0, y0), _) ->
4898 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4899 then zoomrect x0 y0 x y
4901 state.mstate
<- Mnone
;
4902 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4903 G.postRedisplay "kill accidental zoom rect";
4906 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4907 state.mstate
<- Mnone
4910 | 1 when x > conf.winw - state.scrollw
->
4913 let _, position, sh = state.uioh#
scrollph in
4914 if y > truncate
position && y < truncate
(position +. sh)
4915 then state.mstate
<- Mscrolly
4918 state.mstate
<- Mnone
4920 | 1 when y > conf.winh
- state.hscrollh ->
4923 let _, position, sw = state.uioh#scrollpw
in
4924 if x > truncate
position && x < truncate
(position +. sw)
4925 then state.mstate
<- Mscrollx
4928 state.mstate
<- Mnone
4931 let dest = if down
then getunder x y else Unone
in
4932 begin match dest with
4933 | Ulinkgoto
(pageno, top) ->
4937 gotopage1 pageno top;
4943 | Uremote
(filename
, pageno) ->
4945 if Sys.file_exists filename
4948 let dir = Filename.dirname
state.path in
4949 let path = Filename.concat
dir filename
in
4950 if Sys.file_exists
path
4954 if String.length
path > 0
4956 let anchor = getanchor () in
4957 let ranchor = state.path, state.password
, anchor in
4958 state.anchor <- (pageno, 0.0);
4959 state.ranchors
<- ranchor :: state.ranchors
;
4962 else showtext '
!'
("Could not find " ^ filename
)
4964 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
4966 | Unone
when down
->
4967 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
4968 state.mstate
<- Mpan
(x, y);
4970 | Unone
| Utext
_ ->
4973 if conf.angle
mod 360 = 0
4975 state.mstate
<- Msel
((x, y), (x, y));
4976 G.postRedisplay "mouse select";
4980 match state.mstate
with
4983 | Mzoom
_ | Mscrollx
| Mscrolly
->
4984 state.mstate
<- Mnone
4986 | Mzoomrect
((x0, y0), _) ->
4990 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4991 state.mstate
<- Mnone
4993 | Msel
((_, y0), (_, y1)) ->
4994 let rec loop = function
4997 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4998 || ((y1 >= l.pagedispy
4999 && y1 <= (l.pagedispy + l.pagevh)))
5001 match getopaque l.pageno with
5003 copysel
conf.selcmd opaque
;
5004 G.postRedisplay "copysel"
5009 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5010 state.mstate
<- Mnone
;
5017 let birdseyemouse button down
x y mask
5018 (conf, leftx
, _, hooverpageno
, anchor) =
5021 let rec loop = function
5024 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5025 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5027 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5033 | _ -> viewmouse button down
x y mask
5036 let mouse button down
x y mask
=
5037 state.uioh <- state.uioh#button button down
x y mask
;
5041 state.uioh <- state.uioh#
motion x y
5045 state.uioh <- state.uioh#
pmotion x y;
5051 method key key mask
=
5052 begin match state.mode with
5053 | Textentry
textentry -> textentrykeyboard key mask
textentry
5054 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5055 | View
-> viewkeyboard key mask
5059 method button button bstate
x y mask
=
5060 begin match state.mode with
5061 | View
-> viewmouse button bstate
x y mask
5062 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5068 begin match state.mode with
5070 | View
| Birdseye
_ ->
5071 match state.mstate
with
5072 | Mzoom
_ | Mnone
-> ()
5077 state.mstate
<- Mpan
(x, y);
5078 if conf.zoom > 1.0 then state.x <- state.x + dx;
5080 gotoy_and_clear_text y
5083 state.mstate
<- Msel
(a, (x, y));
5084 G.postRedisplay "motion select";
5087 let y = min
conf.winh
(max
0 y) in
5091 let x = min
conf.winw (max
0 x) in
5094 | Mzoomrect
(p0
, _) ->
5095 state.mstate
<- Mzoomrect
(p0
, (x, y));
5096 G.postRedisplay "motion zoomrect";
5100 method pmotion x y =
5101 begin match state.mode with
5102 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5103 let rec loop = function
5105 if hooverpageno
!= -1
5107 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5108 G.postRedisplay "pmotion birdseye no hoover";
5111 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5112 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5114 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5115 G.postRedisplay "pmotion birdseye hoover";
5124 match state.mstate
with
5125 | Mnone
-> updateunder x y
5126 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5131 method infochanged
_ = ()
5134 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5135 let p, h = scrollph state.y maxy in
5139 let winw = conf.winw - state.scrollw
- 1 in
5140 let fwinw = float winw in
5142 let sw = fwinw /. float state.w in
5143 let sw = fwinw *. sw in
5144 max
sw (float conf.scrollh
)
5147 let f = state.w+winw in
5148 let r = float (winw-state.x) /. float f in
5149 let p = fwinw *. r in
5153 if position +. sw > fwinw
5154 then fwinw -. position
5157 state.hscrollh, position, sw
5164 let fontpath = ref "";;
5167 let l = String.length
s in
5168 let b = Buffer.create
l in
5174 try Sys.getenv
"HOME"
5177 ("Can not determine home directory location: " ^
5178 Printexc.to_string exn
);
5182 let config_of c attrs
=
5186 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5187 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5188 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5189 | "preload" -> { c with preload = bool_of_string
v }
5190 | "page-bias" -> { c with pagebias
= int_of_string
v }
5191 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5192 | "auto-scroll-step" ->
5193 { c with autoscrollstep
= max
0 (int_of_string
v) }
5194 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5195 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5198 match String.lowercase
v with
5199 | "true" -> Some infinity
5201 | f -> Some
(float_of_string
f)
5203 { c with maxwait
= mw}
5204 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5205 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5206 | "vertical-margin" ->
5207 { c with interpagespace = max
0 (int_of_string
v) }
5209 let zoom = float_of_string
v /. 100. in
5210 let zoom = max
zoom 0.0 in
5211 { c with zoom = zoom }
5212 | "presentation" -> { c with presentation = bool_of_string
v }
5213 | "rotation-angle" -> { c with angle
= int_of_string
v }
5214 | "width" -> { c with winw = max
20 (int_of_string
v) }
5215 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5216 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5217 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5218 | "pixmap-cache-size" ->
5219 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5220 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5221 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5222 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5223 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5224 | "background-color" -> { c with bgcolor
= color_of_string v }
5225 | "scrollbar-in-presentation" ->
5226 { c with scrollbarinpm
= bool_of_string
v }
5227 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5228 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5229 | "mupdf-store-size" ->
5230 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5231 | "checkers" -> { c with checkers
= bool_of_string
v }
5232 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5233 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5234 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5235 | "uri-launcher" -> { c with urilauncher
= unent v }
5236 | "path-launcher" -> { c with pathlauncher
= unent v }
5237 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5238 | "invert-colors" -> { c with invert
= bool_of_string
v }
5239 | "brightness" -> { c with colorscale
= float_of_string
v }
5240 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5242 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5244 let nab = columns_of_string v in
5245 { c with columns
= Some
(nab, [||]) }
5246 | "birds-eye-columns" ->
5247 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5248 | "selection-command" -> { c with selcmd
= unent v }
5249 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5252 prerr_endline
("Error processing attribute (`" ^
5253 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5256 let rec fold c = function
5259 let c = apply c k
v in
5265 let fromstring f pos
n v d =
5268 dolog "Error processing attribute (%S=%S) at %d\n%s"
5269 n v pos
(Printexc.to_string exn
)
5274 let bookmark_of attrs
=
5275 let rec fold title page
rely = function
5276 | ("title", v) :: rest
-> fold v page
rely rest
5277 | ("page", v) :: rest
-> fold title v rely rest
5278 | ("rely", v) :: rest
-> fold title page
v rest
5279 | _ :: rest
-> fold title page
rely rest
5280 | [] -> title, page
, rely
5282 fold "invalid" "0" "0" attrs
5286 let rec fold path page
rely pan
= function
5287 | ("path", v) :: rest
-> fold v page
rely pan rest
5288 | ("page", v) :: rest
-> fold path v rely pan rest
5289 | ("rely", v) :: rest
-> fold path page
v pan rest
5290 | ("pan", v) :: rest
-> fold path page
rely v rest
5291 | _ :: rest
-> fold path page
rely pan rest
5292 | [] -> path, page
, rely, pan
5294 fold "" "0" "0" "0" attrs
5297 let setconf dst
src =
5298 dst
.scrollbw
<- src.scrollbw
;
5299 dst
.scrollh
<- src.scrollh
;
5300 dst
.icase
<- src.icase
;
5301 dst
.preload <- src.preload;
5302 dst
.pagebias
<- src.pagebias
;
5303 dst
.verbose
<- src.verbose
;
5304 dst
.scrollstep
<- src.scrollstep
;
5305 dst
.maxhfit
<- src.maxhfit
;
5306 dst
.crophack
<- src.crophack
;
5307 dst
.autoscrollstep
<- src.autoscrollstep
;
5308 dst
.maxwait
<- src.maxwait
;
5309 dst
.hlinks
<- src.hlinks
;
5310 dst
.underinfo
<- src.underinfo
;
5311 dst
.interpagespace <- src.interpagespace;
5312 dst
.zoom <- src.zoom;
5313 dst
.presentation <- src.presentation;
5314 dst
.angle
<- src.angle
;
5315 dst
.winw <- src.winw;
5316 dst
.winh
<- src.winh
;
5317 dst
.savebmarks
<- src.savebmarks
;
5318 dst
.memlimit
<- src.memlimit
;
5319 dst
.proportional
<- src.proportional
;
5320 dst
.texcount
<- src.texcount
;
5321 dst
.sliceheight
<- src.sliceheight
;
5322 dst
.thumbw
<- src.thumbw
;
5323 dst
.jumpback
<- src.jumpback
;
5324 dst
.bgcolor
<- src.bgcolor
;
5325 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5326 dst
.tilew
<- src.tilew
;
5327 dst
.tileh
<- src.tileh
;
5328 dst
.mustoresize
<- src.mustoresize
;
5329 dst
.checkers
<- src.checkers
;
5330 dst
.aalevel
<- src.aalevel
;
5331 dst
.trimmargins
<- src.trimmargins
;
5332 dst
.trimfuzz
<- src.trimfuzz
;
5333 dst
.urilauncher
<- src.urilauncher
;
5334 dst
.colorspace
<- src.colorspace
;
5335 dst
.invert
<- src.invert
;
5336 dst
.colorscale
<- src.colorscale
;
5337 dst
.redirectstderr <- src.redirectstderr;
5338 dst
.ghyllscroll
<- src.ghyllscroll
;
5339 dst
.columns
<- src.columns
;
5340 dst
.beyecolumns
<- src.beyecolumns
;
5341 dst
.selcmd
<- src.selcmd
;
5342 dst
.updatecurs
<- src.updatecurs
;
5343 dst
.pathlauncher
<- src.pathlauncher
;
5347 let h = Hashtbl.create
10 in
5348 let dc = { defconf with angle
= defconf.angle
} in
5349 let rec toplevel v t spos
_ =
5351 | Vdata
| Vcdata
| Vend
-> v
5352 | Vopen
("llppconfig", _, closed
) ->
5355 else { v with f = llppconfig
}
5357 error
"unexpected subelement at top level" s spos
5358 | Vclose
_ -> error
"unexpected close at top level" s spos
5360 and llppconfig
v t spos
_ =
5362 | Vdata
| Vcdata
-> v
5363 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5364 | Vopen
("defaults", attrs
, closed
) ->
5365 let c = config_of dc attrs
in
5369 else { v with f = skip
"defaults" (fun () -> v) }
5371 | Vopen
("ui-font", attrs
, closed
) ->
5372 let rec getsize size
= function
5374 | ("size", v) :: rest
->
5376 fromstring int_of_string spos
"size" v fstate.fontsize
in
5378 | l -> getsize size l
5380 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5383 else { v with f = uifont
(Buffer.create
10) }
5385 | Vopen
("doc", attrs
, closed
) ->
5386 let pathent, spage
, srely
, span
= doc_of attrs
in
5387 let path = unent pathent
5388 and pageno = fromstring int_of_string spos
"page" spage
0
5389 and rely = fromstring float_of_string spos
"rely" srely
0.0
5390 and pan
= fromstring int_of_string spos
"pan" span
0 in
5391 let c = config_of dc attrs
in
5392 let anchor = (pageno, rely) in
5394 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5395 else { v with f = doc
path pan
anchor c [] }
5398 error
"unexpected subelement in llppconfig" s spos
5400 | Vclose
"llppconfig" -> { v with f = toplevel }
5401 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5403 and uifont
b v t spos
epos =
5406 Buffer.add_substring
b s spos
(epos - spos
);
5408 | Vopen
(_, _, _) ->
5409 error
"unexpected subelement in ui-font" s spos
5410 | Vclose
"ui-font" ->
5411 if String.length
!fontpath = 0
5412 then fontpath := Buffer.contents
b;
5413 { v with f = llppconfig
}
5414 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5415 | Vend
-> error
"unexpected end of input in ui-font" s spos
5417 and doc
path pan
anchor c bookmarks
v t spos
_ =
5419 | Vdata
| Vcdata
-> v
5420 | Vend
-> error
"unexpected end of input in doc" s spos
5421 | Vopen
("bookmarks", _, closed
) ->
5424 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5426 | Vopen
(_, _, _) ->
5427 error
"unexpected subelement in doc" s spos
5430 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5431 { v with f = llppconfig
}
5433 | Vclose
_ -> error
"unexpected close in doc" s spos
5435 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5437 | Vdata
| Vcdata
-> v
5438 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5439 | Vopen
("item", attrs
, closed
) ->
5440 let titleent, spage
, srely
= bookmark_of attrs
in
5441 let page = fromstring int_of_string spos
"page" spage
0
5442 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5443 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5445 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5448 { v with f = skip
"item" f }
5451 error
"unexpected subelement in bookmarks" s spos
5453 | Vclose
"bookmarks" ->
5454 { v with f = doc
path pan
anchor c bookmarks }
5456 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5458 and skip tag
f v t spos
_ =
5460 | Vdata
| Vcdata
-> v
5462 error
("unexpected end of input in skipped " ^ tag
) s spos
5463 | Vopen
(tag'
, _, closed
) ->
5467 let f'
() = { v with f = skip tag
f } in
5468 { v with f = skip tag'
f'
}
5472 else error
("unexpected close in skipped " ^ tag
) s spos
5475 parse
{ f = toplevel; accu = () } s;
5481 let len = in_channel_length ic
in
5482 let s = String.create
len in
5483 really_input ic
s 0 len;
5486 | Parse_error
(msg
, s, pos
) ->
5487 let subs = subs s pos
in
5488 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5489 failwith
("parse error: " ^
s)
5492 failwith
("config load error: " ^
Printexc.to_string exn
)
5498 let dir = Filename.concat
home ".config" in
5499 if Sys.is_directory
dir then dir else home
5502 Filename.concat
dir "llpp.conf"
5505 let confpath = ref defconfpath;;
5508 if Sys.file_exists
!confpath
5511 (try Some
(open_in_bin
!confpath)
5514 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5515 Printexc.to_string exn
);
5524 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5525 Printexc.to_string exn
);
5531 f (Hashtbl.create
0, defconf)
5536 let pc, pb
, px, pa
=
5538 Hashtbl.find h (Filename.basename
state.path)
5539 with Not_found
-> dc, [], 0, (0, 0.0)
5543 state.bookmarks <- pb
;
5545 state.scrollw
<- conf.scrollbw
;
5547 then state.anchor <- pa
;
5548 cbput state.hists
.nav pa
;
5553 let add_attrs bb always
dc c =
5556 then Printf.bprintf bb
"\n %s='%b'" s a
5559 then Printf.bprintf bb
"\n %s='%d'" s a
5562 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5565 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5568 then Printf.bprintf bb
"\n %s='%f'" s a
5572 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5576 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5580 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5584 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5590 | Some
(_N
, _A
, _B
) ->
5591 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5601 else string_of_float
f
5603 Printf.bprintf bb
"\n %s='%s'" s v
5608 | Some
((n, a, b), _) when n > 1 ->
5609 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5615 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5620 then dc.winw, dc.winh
5622 match state.fullscreen
with
5624 | None
-> c.winw, c.winh
5626 let zoom, presentation, interpagespace, maxwait
=
5628 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5630 match state.mode with
5631 | Birdseye
(bc
, _, _, _, _) ->
5632 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5633 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5635 oi
"width" w dc.winw;
5636 oi
"height" h dc.winh
;
5637 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5638 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5639 ob "case-insensitive-search" c.icase
dc.icase
;
5640 ob "preload" c.preload dc.preload;
5641 oi
"page-bias" c.pagebias
dc.pagebias
;
5642 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5643 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5644 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5645 ob "crop-hack" c.crophack
dc.crophack
;
5646 oW
"throttle" maxwait
dc.maxwait
;
5647 ob "highlight-links" c.hlinks
dc.hlinks
;
5648 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5649 oi
"vertical-margin" interpagespace dc.interpagespace;
5650 oz
"zoom" zoom dc.zoom;
5651 ob "presentation" presentation dc.presentation;
5652 oi
"rotation-angle" c.angle
dc.angle
;
5653 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5654 ob "proportional-display" c.proportional
dc.proportional
;
5655 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5656 oi
"tex-count" c.texcount
dc.texcount
;
5657 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5658 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5659 ob "persistent-location" c.jumpback
dc.jumpback
;
5660 oc
"background-color" c.bgcolor
dc.bgcolor
;
5661 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5662 oi
"tile-width" c.tilew
dc.tilew
;
5663 oi
"tile-height" c.tileh
dc.tileh
;
5664 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5665 ob "checkers" c.checkers
dc.checkers
;
5666 oi
"aalevel" c.aalevel
dc.aalevel
;
5667 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5668 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5669 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5670 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
5671 oC
"color-space" c.colorspace
dc.colorspace
;
5672 ob "invert-colors" c.invert
dc.invert
;
5673 oF
"brightness" c.colorscale
dc.colorscale
;
5674 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5675 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5676 oco
"columns" c.columns
dc.columns
;
5677 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5678 os
"selection-command" c.selcmd
dc.selcmd
;
5679 ob "update-cursor" c.updatecurs
dc.updatecurs
;
5683 let uifontsize = fstate.fontsize
in
5684 let bb = Buffer.create
32768 in
5686 let dc = if conf.bedefault
then conf else dc in
5687 Buffer.add_string
bb "<llppconfig>\n";
5689 if String.length
!fontpath > 0
5691 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5697 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5700 Buffer.add_string
bb "<defaults ";
5701 add_attrs bb true dc dc;
5702 Buffer.add_string
bb "/>\n";
5704 let adddoc path pan
anchor c bookmarks =
5705 if bookmarks == [] && c = dc && anchor = emptyanchor
5708 Printf.bprintf
bb "<doc path='%s'"
5709 (enent
path 0 (String.length
path));
5711 if anchor <> emptyanchor
5713 let n, y = anchor in
5714 Printf.bprintf
bb " page='%d'" n;
5717 Printf.bprintf
bb " rely='%f'" y
5722 then Printf.bprintf
bb " pan='%d'" pan
;
5724 add_attrs bb false dc c;
5726 begin match bookmarks with
5727 | [] -> Buffer.add_string
bb "/>\n"
5729 Buffer.add_string
bb ">\n<bookmarks>\n";
5730 List.iter
(fun (title, _level
, (page, rely)) ->
5732 "<item title='%s' page='%d'"
5733 (enent
title 0 (String.length
title))
5738 Printf.bprintf
bb " rely='%f'" rely
5740 Buffer.add_string
bb "/>\n";
5742 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5748 match state.mode with
5749 | Birdseye
(c, pan, _, _, _) ->
5751 match conf.columns
with
5752 | Some
((c, _, _), _) -> Some
c
5755 match c.columns
with
5756 | Some
(c, _) -> Some
(c, [||])
5759 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
5760 | _ -> state.x, conf
5762 let basename = Filename.basename state.path in
5763 adddoc basename pan (getanchor ())
5766 match state.autoscroll
with
5768 | None
-> conf.autoscrollstep
}
5769 (if conf.savebmarks
then state.bookmarks else []);
5771 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5773 then adddoc path x y c bookmarks
5775 Buffer.add_string
bb "</llppconfig>";
5778 if Buffer.length
bb > 0
5781 let tmp = !confpath ^
".tmp" in
5782 let oc = open_out_bin
tmp in
5783 Buffer.output_buffer
oc bb;
5785 Unix.rename
tmp !confpath;
5788 ("error while saving configuration: " ^
Printexc.to_string exn
)
5795 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5796 "<password> Set password");
5798 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5799 "<path> Set path to the user interface font");
5801 ("-c", Arg.String
(fun s -> Config.confpath := s),
5802 "<path> Set path to the configuration file");
5804 ("-v", Arg.Unit
(fun () ->
5806 "%s\nconfiguration path: %s\n"
5810 exit
0), " Print version and exit");
5813 (fun s -> state.path <- s)
5814 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5816 if String.length
state.path = 0
5817 then (prerr_endline
"file name missing"; exit
1);
5821 state.wsfd
<- Wsi.init
(object
5822 method display = display ()
5823 method reshape w h = reshape w h
5824 method mouse b d x y m = mouse b d x y m
5825 method motion x y = state.mpos
<- (x, y); motion x y
5826 method pmotion x y = state.mpos
<- (x, y); pmotion x y
5827 method key c m = keyboard c m
5828 method enter
x y = state.mpos
<- (x, y); pmotion x y
5829 method leave = state.mpos
<- (-1, -1)
5830 end) conf.winw conf.winh
;
5833 List.exists
GlMisc.check_extension
5834 [ "GL_ARB_texture_rectangle"
5835 ; "GL_EXT_texture_recangle"
5836 ; "GL_NV_texture_rectangle" ]
5838 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5840 let cr, sw = Unix.pipe
()
5841 and sr
, cw
= Unix.pipe
() in
5848 setcheckers conf.checkers
;
5852 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5853 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5858 state.text <- "Opening " ^
state.path;
5859 setaalevel
conf.aalevel
;
5860 writeopen state.path state.password
;
5862 setfontsize fstate.fontsize
;
5863 doreshape conf.winw conf.winh
;
5865 let rec loop deadline
=
5867 match state.errfd
with
5868 | None
-> [state.sr
; state.wsfd
]
5869 | Some fd
-> [state.sr
; state.wsfd
; fd
]
5873 state.redisplay
<- false;
5880 if deadline
= infinity
5882 else max
0.0 (deadline
-. now)
5887 try Unix.select
r [] [] timeout
5888 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5894 match state.autoscroll
with
5895 | Some step
when step
!= 0 ->
5896 let y = state.y + step
in
5900 else if y >= state.maxy then 0 else y
5903 if state.mode = View
5904 then state.text <- "";
5907 if state.ghyll
== noghyll then infinity
else deadline
+. 0.01
5912 let rec checkfds = function
5914 | fd
:: rest
when fd
= state.sr
->
5915 let cmd = readcmd state.sr
in
5919 | fd
:: rest
when fd
= state.wsfd
->
5924 let s = String.create
80 in
5925 let n = Unix.read fd
s 0 80 in
5926 if conf.redirectstderr
5928 Buffer.add_substring
state.errmsgs
s 0 n;
5929 state.newerrmsgs
<- true;
5930 state.redisplay
<- true;
5933 prerr_string
(String.sub
s 0 n);
5941 if deadline
= infinity
5945 match state.autoscroll
with
5946 | Some step
when step
!= 0 -> deadline1
5947 | _ -> if state.ghyll
== noghyll then infinity
else deadline1