3 let tempfailureretry = Wsi.tempfailureretry;;
8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
17 let now = Unix.gettimeofday
;;
19 type params
= (angle
* proportional
* trimparams
20 * texcount
* sliceheight
* memsize
21 * colorspace
* fontpath
* trimcachepath
31 and proportional
= bool
32 and trimmargins
= bool
33 and interpagespace
= int
40 and trimcachepath
= string
43 and irect
= (int * int * int * int)
44 and trimparams
= (trimmargins
* irect
)
45 and colorspace
= | Rgb
| Bgr
| Gray
55 | LDfirstvisible
of (int * int * int)
70 | KMmulti
of key list
* key list
72 and keyhash
= (key
, keymap
) Hashtbl.t
75 | KSinto
of (key list
* key list
)
78 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
79 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
81 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
83 external init
: pipe
-> params
-> unit = "ml_init";;
84 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
85 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
86 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
87 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
88 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
89 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
90 external measurestr
: int -> string -> float = "ml_measure_string";;
91 external getmaxw
: unit -> float = "ml_getmaxw";;
92 external postprocess
:
93 opaque
-> int -> int -> int -> (int * string * int) -> int
95 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
96 external platform
: unit -> platform
= "ml_platform";;
97 external setaalevel
: int -> unit = "ml_setaalevel";;
98 external realloctexts
: int -> bool = "ml_realloctexts";;
99 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
100 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
101 external getlink
: opaque
-> int -> under
= "ml_getlink";;
102 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
103 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
104 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
105 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
106 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
107 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
108 external freepbo
: string -> unit = "ml_freepbo";;
109 external unmappbo
: string -> unit = "ml_unmappbo";;
110 external pbousable
: unit -> bool = "ml_pbo_usable";;
112 let platform_to_string = function
113 | Punknown
-> "unknown"
117 | Pfreebsd
-> "FreeBSD"
118 | Pdragonflybsd
-> "DragonflyBSD"
119 | Popenbsd
-> "OpenBSD"
120 | Pnetbsd
-> "NetBSD"
121 | Pcygwin
-> "Cygwin"
124 let platform = platform ();;
127 if platform = Pcygwin
129 let sh = "/bin/sh" in
130 let args = [|sh; "-c"; cmd
|] in
131 let rec std si so se
= function
133 | (fd
, 0) :: rest
-> std fd so se rest
134 | (fd
, -1) :: rest
->
135 Unix.set_close_on_exec fd
;
138 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
140 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
141 ignore
(Unix.create_process
sh args si so se
)
150 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
153 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
155 type mpos
= int * int
157 | Msel
of (mpos
* mpos
)
159 | Mscrolly
| Mscrollx
160 | Mzoom
of (int * int)
161 | Mzoomrect
of (mpos
* mpos
)
165 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
166 and onkey
= string -> int -> te
167 and ondone
= string -> unit
168 and histcancel
= unit -> unit
169 and onhist
= ((histcmd
-> string) * histcancel
)
170 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
171 and cancelonempty
= bool
176 | TEswitch
of textentry
187 let bound v minv maxv
=
188 max minv
(min maxv v
);
192 { store
= Array.create n v
199 let cbcap b
= Array.length b
.store
;;
204 b
.wc
<- (b
.wc
+ 1) mod cap;
206 b
.len
<- min
(b
.len
+ 1) cap;
209 let cbempty b
= b
.len
= 0;;
211 let cbgetg b circular dir
=
215 let rc = b
.rc + dir
in
227 else bound rc 0 (b
.len
-1)
233 let cbget b
= cbgetg b
false;;
234 let cbgetc b
= cbgetg b
true;;
236 let drawstring size x y s
=
238 Gl.enable `texture_2d
;
239 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
240 ignore
(drawstr size x y s
);
242 Gl.disable `texture_2d
;
245 let drawstring1 size x y s
=
249 let drawstring2 size x y fmt
=
250 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
269 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
270 dolog " WxH %dx%d" l
.pagew l
.pageh
;
271 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
272 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
273 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
274 dolog " column %d" l
.pagecol
;
278 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
280 dolog " x0,y0=(% f, % f)" x0 y0
;
281 dolog " x1,y1=(% f, % f)" x1 y1
;
282 dolog " x2,y2=(% f, % f)" x2 y2
;
283 dolog " x3,y3=(% f, % f)" x3 y3
;
287 type multicolumns
= multicol
* pagegeom
288 and singlecolumn
= pagegeom
289 and splitcolumns
= columncount
* pagegeom
290 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
291 and multicol
= columncount
* covercount
* covercount
293 and columncount
= int
294 and covercount
= int;;
297 { mutable scrollbw
: int
298 ; mutable scrollh
: int
299 ; mutable icase
: bool
300 ; mutable preload
: bool
301 ; mutable pagebias
: int
302 ; mutable verbose
: bool
303 ; mutable debug
: bool
304 ; mutable scrollstep
: int
305 ; mutable hscrollstep
: int
306 ; mutable maxhfit
: bool
307 ; mutable crophack
: bool
308 ; mutable autoscrollstep
: int
309 ; mutable maxwait
: float option
310 ; mutable hlinks
: bool
311 ; mutable underinfo
: bool
312 ; mutable interpagespace
: interpagespace
313 ; mutable zoom
: float
314 ; mutable presentation
: bool
315 ; mutable angle
: angle
318 ; mutable savebmarks
: bool
319 ; mutable proportional
: proportional
320 ; mutable trimmargins
: trimmargins
321 ; mutable trimfuzz
: irect
322 ; mutable memlimit
: memsize
323 ; mutable texcount
: texcount
324 ; mutable sliceheight
: sliceheight
325 ; mutable thumbw
: width
326 ; mutable jumpback
: bool
327 ; mutable bgcolor
: float * float * float
328 ; mutable bedefault
: bool
329 ; mutable scrollbarinpm
: bool
330 ; mutable tilew
: int
331 ; mutable tileh
: int
332 ; mutable mustoresize
: memsize
333 ; mutable checkers
: bool
334 ; mutable aalevel
: int
335 ; mutable urilauncher
: string
336 ; mutable pathlauncher
: string
337 ; mutable colorspace
: colorspace
338 ; mutable invert
: bool
339 ; mutable colorscale
: float
340 ; mutable redirectstderr
: bool
341 ; mutable ghyllscroll
: (int * int * int) option
342 ; mutable columns
: columns
343 ; mutable beyecolumns
: columncount
option
344 ; mutable selcmd
: string
345 ; mutable updatecurs
: bool
346 ; mutable keyhashes
: (string * keyhash
) list
347 ; mutable hfsize
: int
348 ; mutable pgscale
: float
349 ; mutable usepbo
: bool
350 ; mutable wheelbypage
: bool
353 | Csingle
of singlecolumn
354 | Cmulti
of multicolumns
355 | Csplit
of splitcolumns
358 type anchor
= pageno
* top
* dtop
;;
360 type outline
= string * int * anchor
;;
362 type rect
= float * float * float * float * float * float * float * float;;
364 type tile
= opaque
* pixmapsize
* elapsed
365 and elapsed
= float;;
366 type pagemapkey
= pageno
* gen
;;
367 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
371 let emptyanchor = (0, 0.0, 0.0);;
373 type infochange
= | Memused
| Docinfo
| Pdim
;;
375 class type uioh
= object
376 method display
: unit
377 method key
: int -> int -> uioh
378 method button
: int -> bool -> int -> int -> int -> uioh
379 method motion
: int -> int -> uioh
380 method pmotion
: int -> int -> uioh
381 method infochanged
: infochange
-> unit
382 method scrollpw
: (int * float * float)
383 method scrollph
: (int * float * float)
384 method modehash
: keyhash
388 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
389 | Textentry
of (textentry
* onleave
)
391 | LinkNav
of linktarget
392 and onleave
= leavetextentrystatus
-> unit
393 and leavetextentrystatus
= | Cancel
| Confirm
394 and helpitem
= string * int * action
397 | Action
of (uioh
-> uioh
)
399 | Ltexact
of (pageno
* int)
403 let isbirdseye = function Birdseye _
-> true | _
-> false;;
404 let istextentry = function Textentry _
-> true | _
-> false;;
408 | Loading
of (page
* gen
)
410 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
412 | Outlining
of outline list
415 let emptykeyhash = Hashtbl.create
0;;
416 let nouioh : uioh
= object (self
)
418 method key _ _
= self
419 method button _ _ _ _ _
= self
420 method motion _ _
= self
421 method pmotion _ _
= self
422 method infochanged _
= ()
423 method scrollpw
= (0, nan
, nan
)
424 method scrollph
= (0, nan
, nan
)
425 method modehash
= emptykeyhash
429 { mutable sr
: Unix.file_descr
430 ; mutable sw
: Unix.file_descr
431 ; mutable wsfd
: Unix.file_descr
432 ; mutable errfd
: Unix.file_descr
option
433 ; mutable stderr
: Unix.file_descr
434 ; mutable errmsgs
: Buffer.t
435 ; mutable newerrmsgs
: bool
439 ; mutable scrollw
: int
440 ; mutable hscrollh
: int
441 ; mutable anchor
: anchor
442 ; mutable ranchors
: (string * string * anchor
) list
444 ; mutable layout
: page list
445 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
446 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
447 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
448 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
449 ; mutable pagecount
: int
450 ; mutable currently
: currently
451 ; mutable mstate
: mstate
452 ; mutable searchpattern
: string
453 ; mutable rects
: (pageno
* recttype
* rect
) list
454 ; mutable rects1
: (pageno
* recttype
* rect
) list
455 ; mutable text
: string
456 ; mutable fullscreen
: (width
* height
) option
457 ; mutable mode
: mode
458 ; mutable uioh
: uioh
459 ; mutable outlines
: outline array
460 ; mutable bookmarks
: outline list
461 ; mutable path
: string
462 ; mutable password
: string
463 ; mutable nameddest
: string
464 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
465 ; mutable memused
: memsize
467 ; mutable throttle
: (page list
* int * float) option
468 ; mutable autoscroll
: int option
469 ; mutable ghyll
: (int option -> unit)
470 ; mutable help
: helpitem array
471 ; mutable docinfo
: (int * string) list
472 ; mutable texid
: GlTex.texture_id
option
474 ; mutable prevzoom
: float
475 ; mutable progress
: float
476 ; mutable redisplay
: bool
477 ; mutable mpos
: mpos
478 ; mutable keystate
: keystate
479 ; mutable glinks
: bool
480 ; mutable prevcolumns
: (columns
* float) option
481 ; mutable wthack
: bool
484 { pat
: string circbuf
485 ; pag
: string circbuf
486 ; nav
: anchor circbuf
487 ; sel
: string circbuf
509 ; presentation
= false
514 ; proportional
= true
515 ; trimmargins
= false
516 ; trimfuzz
= (0,0,0,0)
517 ; memlimit
= 32 lsl 20
522 ; bgcolor
= (0.5, 0.5, 0.5)
524 ; scrollbarinpm
= true
527 ; mustoresize
= 256 lsl 20
532 | Plinux
| Pfreebsd
| Pdragonflybsd
533 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
534 | Posx
-> "open \"%s\""
535 | Pcygwin
-> "cygstart \"%s\""
536 | Punknown
-> "echo %s")
537 ; pathlauncher
= "lp \"%s\""
540 | Plinux
| Pfreebsd
| Pdragonflybsd
541 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
548 ; redirectstderr
= false
550 ; columns
= Csingle
[||]
556 ; wheelbypage
= false
558 let mk n
= (n
, Hashtbl.create
1) in
572 let wtmode = ref false;;
574 let findkeyhash c name
=
575 try List.assoc name c
.keyhashes
576 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
579 let conf = { defconf with angle
= defconf.angle
};;
581 let pgscale h
= truncate
(float h
*. conf.pgscale);;
584 { mutable fontsize
: int
585 ; mutable wwidth
: float
586 ; mutable maxrows
: int
598 fstate.fontsize
<- n
;
599 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
600 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
604 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
605 let len = String.length s
in
606 if colonpos >= 0 && colonpos + 3 < len
608 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
611 try String.rindex_from s
colonpos ' '
615 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
618 | "http" | "ftp" | "mailto" ->
620 try String.index_from s
colonpos ' '
621 with Not_found
-> len
623 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
631 if String.length
conf.urilauncher
= 0
632 then print_endline uri
634 let url = geturl uri
in
635 if String.length
url = 0
636 then print_endline uri
638 let re = Str.regexp
"%s" in
639 let command = Str.global_replace
re url conf.urilauncher
in
643 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
649 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
650 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
654 let strings = version () :: "" :: Help.keys
in
657 let url = geturl s
in
658 if String.length
url > 0
659 then (s
, 0, Action
(fun u
-> gotouri url; u
))
660 else (s
, 0, Noaction
)
665 let firstgeomcmds = "", [];;
672 ; stderr
= Unix.stderr
673 ; errmsgs
= Buffer.create
0
680 ; anchor
= emptyanchor
684 ; tilelru
= Queue.create
()
685 ; pagemap
= Hashtbl.create
10
686 ; tilemap
= Hashtbl.create
10
702 ; geomcmds
= firstgeomcmds
704 { nav
= cbnew 10 emptyanchor
732 Printf.kprintf prerr_endline fmt
734 Printf.kprintf ignore fmt
738 if String.length
conf.pathlauncher
= 0
739 then print_endline
state.path
741 let re = Str.regexp
"%s" in
742 let command = Str.global_replace
re state.path
conf.pathlauncher
in
746 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
752 type 'a t
= | Res
of 'a
| Exn
of exn
;;
755 try Res
(Unix.pipe ())
760 try tempfailureretry Unix.close fd
761 with exn
-> f
(Printexc.to_string exn
)
765 try Res
(tempfailureretry Unix.dup fd
)
770 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
775 let redirectstderr () =
776 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
777 if conf.redirectstderr
779 match Ne.pipe () with
781 dolog "failed to create stderr redirection pipes: %s"
782 (Printexc.to_string exn
)
785 begin match Ne.dup Unix.stderr
with
787 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
788 Ne.clo r
(clofail "pipe/r");
789 Ne.clo w
(clofail "pipe/w");
791 | Ne.Res dupstderr
->
792 begin match Ne.dup2 w
Unix.stderr
with
794 dolog "failed to dup2 to stderr: %s"
795 (Printexc.to_string exn
);
796 Ne.clo dupstderr
(clofail "stderr duplicate");
797 Ne.clo r
(clofail "redir pipe/r");
798 Ne.clo w
(clofail "redir pipe/w");
801 state.stderr
<- dupstderr
;
802 state.errfd
<- Some r
;
806 state.newerrmsgs
<- false;
807 begin match state.errfd
with
809 begin match Ne.dup2 state.stderr
Unix.stderr
with
811 dolog "failed to dup2 original stderr: %s"
812 (Printexc.to_string exn
)
814 Ne.clo fd
(clofail "dup of stderr");
819 prerr_string
(Buffer.contents
state.errmsgs
);
821 Buffer.clear
state.errmsgs
;
827 let postRedisplay who
=
829 then prerr_endline
("redisplay for " ^ who
);
830 state.redisplay
<- true;
834 let getopaque pageno
=
835 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
836 with Not_found
-> None
839 let putopaque pageno opaque
=
840 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
843 let pagetranslatepoint l x y
=
844 let dy = y
- l
.pagedispy
in
845 let y = dy + l
.pagey
in
846 let dx = x
- l
.pagedispx
in
847 let x = dx + l
.pagex
in
854 begin match getopaque l
.pageno
with
856 let x0 = l
.pagedispx
in
857 let x1 = x0 + l
.pagevw
in
858 let y0 = l
.pagedispy
in
859 let y1 = y0 + l
.pagevh
in
860 if y >= y0 && y <= y1 && x >= x0 && x <= x1
862 let px, py
= pagetranslatepoint l
x y in
863 match whatsunder opaque
px py
with
876 state.text
<- Printf.sprintf
"%c%s" c s
;
877 G.postRedisplay "showtext";
880 let undertext = function
883 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
884 | Utext s
-> "font: " ^ s
885 | Uunexpected s
-> "unexpected: " ^ s
886 | Ulaunch s
-> "launch: " ^ s
887 | Unamed s
-> "named: " ^ s
888 | Uremote
(filename
, pageno
) ->
889 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
892 let updateunder x y =
893 match getunder x y with
894 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
896 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
897 Wsi.setcursor
Wsi.CURSOR_INFO
898 | Ulinkgoto
(pageno
, _
) ->
900 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
901 Wsi.setcursor
Wsi.CURSOR_INFO
903 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
904 Wsi.setcursor
Wsi.CURSOR_TEXT
906 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
907 Wsi.setcursor
Wsi.CURSOR_INHERIT
909 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
910 Wsi.setcursor
Wsi.CURSOR_INHERIT
912 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
913 Wsi.setcursor
Wsi.CURSOR_INHERIT
914 | Uremote
(filename
, pageno
) ->
915 if conf.underinfo
then showtext 'r'
916 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
917 Wsi.setcursor
Wsi.CURSOR_INFO
920 let showlinktype under
=
926 let s = undertext under
in
931 let b = Buffer.create
(String.length
s + 1) in
932 Buffer.add_string
b s;
937 let colorspace_of_string s =
938 match String.lowercase
s with
942 | _
-> failwith
"invalid colorspace"
945 let int_of_colorspace = function
951 let colorspace_of_int = function
955 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
958 let colorspace_to_string = function
964 let intentry_with_suffix text key
=
966 if key
>= 32 && key
< 127
970 match Char.lowercase
c with
972 let text = addchar text c in
976 let text = addchar text c in
980 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
984 let multicolumns_to_string (n
, a
, b) =
986 then Printf.sprintf
"%d" n
987 else Printf.sprintf
"%d,%d,%d" n a
b;
990 let multicolumns_of_string s =
992 (int_of_string
s, 0, 0)
994 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
996 then failwith
"subtly broken"; (n
, a
, b)
1002 let n = tempfailureretry (Unix.read fd
s 0) 4 in
1003 if n != 4 then failwith
"incomplete read(len)";
1005 lor (Char.code
s.[0] lsl 24)
1006 lor (Char.code
s.[1] lsl 16)
1007 lor (Char.code
s.[2] lsl 8)
1008 lor (Char.code
s.[3] lsl 0)
1010 let s = String.create
len in
1011 let n = tempfailureretry (Unix.read fd
s 0) len in
1012 if n != len then failwith
"incomplete read(data)";
1016 let btod b = if b then 1 else 0;;
1019 let b = Buffer.create
16 in
1020 Buffer.add_string
b "llll";
1023 let s = Buffer.contents
b in
1024 let n = String.length
s in
1026 (* dolog "wcmd %S" (String.sub s 4 len); *)
1027 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1028 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1029 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1030 s.[3] <- Char.chr
(len land 0xff);
1031 let n'
= tempfailureretry (Unix.write
state.sw
s 0) n in
1032 if n'
!= n then failwith
"write failed";
1037 let d = conf.winh
- h
in
1038 max
conf.interpagespace
((d + 1) / 2)
1041 let rowyh (c, coverA
, coverB
) b n =
1042 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1044 let _, _, vy
, (_, _, h
, _) = b.(n) in
1047 let n'
= n - coverA
in
1050 let e = min
state.pagecount
(s + c) in
1051 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1052 let _, _, y, (_, _, h
, _) = b.(m
) in
1053 let miny = min
miny y in
1054 let maxh = max
maxh h
in
1055 find (m
+1) miny maxh
1060 match conf.columns
with
1061 | Cmulti
((_, _, _) as cl
, b) ->
1062 if Array.length
b > 0
1064 let y, h
= rowyh cl
b (Array.length
b - 1) in
1065 y + h
+ (if conf.presentation
then calcips h
else 0)
1068 if Array.length
b > 0
1070 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1071 y + h
+ (if conf.presentation
then calcips h
else 0)
1074 if Array.length
b > 0
1076 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1081 let getpageyh pageno
=
1082 let pageno = bound pageno 0 (state.pagecount
-1) in
1083 match conf.columns
with
1085 if Array.length
b = 0
1088 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1090 if conf.presentation
1096 if Array.length
b = 0
1099 let y, h
= rowyh cl
b pageno in
1101 if conf.presentation
1107 if Array.length
b = 0
1111 let (_, _, y, (_, _, h
, _)) = b.(n) in
1115 let getpagedim pageno =
1118 | (n, _, _, _) as pdim
:: rest
->
1120 then (if n = pageno then pdim
else ppdim
)
1125 f (-1, -1, -1, -1) state.pdims
1128 let getpagey pageno = fst
(getpageyh pageno);;
1130 let nogeomcmds cmds
=
1132 | s, [] -> String.length
s = 0
1137 let ((c, coverA
, coverB
) as cl
), b =
1138 match conf.columns
with
1139 | Csingle
b -> (1, 0, 0), b
1140 | Cmulti
(c, b) -> c, b
1141 | Csplit
(_, b) -> (1, 0, 0), b
1143 let rec bsearch nmin nmax
=
1145 then bound nmin
0 (state.pagecount
-1)
1147 let n = (nmax
+ nmin
) / 2 in
1148 let vy, h
= rowyh cl
b n in
1150 if conf.presentation
1152 let ips = calcips h
in
1153 let y0 = vy - ips in
1154 let y1 = vy + h
+ ips in
1158 then 0, vy + h
+ conf.interpagespace
1160 let y0 = vy - conf.interpagespace
in
1161 y0, y0 + h
+ conf.interpagespace
1164 if y >= y0 && y < y1
1171 if n < state.pagecount
- coverB
1172 then ((n-coverA
)/c)*c + coverA
1179 then bsearch (n+1) nmax
1180 else bsearch nmin
(n-1)
1183 let r = bsearch 0 (state.pagecount
-1) in
1187 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1188 let sh = sh - state.hscrollh
in
1189 let rec fold accu
n =
1190 if n = Array.length
b
1193 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1196 || n = state.pagecount
- coverB
1197 || (n - coverA
) mod columns
= columns
- 1)
1203 let pagey = max
0 (y - vy) in
1204 let pagedispy = if pagey > 0 then 0 else vy - y in
1205 let pagedispx, pagex
=
1207 if n = coverA
- 1 || n = state.pagecount
- coverB
1208 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1209 else dx + xoff
+ state.x
1216 let vw = conf.winw
- state.scrollw
- pagedispx in
1217 let pw = w
- pagex
in
1220 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1221 if pagevw > 0 && pagevh > 0
1225 ; pagedimno
= pdimno
1232 ; pagedispx = pagedispx
1233 ; pagedispy = pagedispy
1245 List.rev
(fold [] (page_of_y y));
1248 let layoutS (columns
, b) y sh =
1249 let sh = sh - state.hscrollh
in
1250 let rec fold accu n =
1251 if n = Array.length
b
1254 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1261 let x = xoff
+ state.x in
1262 let pagey = max
0 (y - vy) in
1263 let pagedispy = if pagey > 0 then 0 else vy - y in
1264 let pagedispx, pagex
=
1278 let pagecolw = pagew
/columns
in
1280 if pagecolw < conf.winw
1281 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1285 let vw = conf.winw
- pagedispx - state.scrollw
in
1286 let pw = pagew
- pagex
in
1289 let pagevw = min
pagevw pagecolw in
1290 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1291 if pagevw > 0 && pagevh > 0
1294 { pageno = n/columns
1295 ; pagedimno
= pdimno
1302 ; pagedispx = pagedispx
1303 ; pagedispy = pagedispy
1304 ; pagecol
= n mod columns
1315 List.rev
(fold [] 0)
1319 if nogeomcmds state.geomcmds
1321 match conf.columns
with
1322 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1323 | Cmulti
c -> layoutN c y sh
1324 | Csplit
s -> layoutS s y sh
1329 let y = state.y + incr
in
1331 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1336 let tilex = l
.pagex
mod conf.tilew
in
1337 let tiley = l
.pagey mod conf.tileh
in
1339 let col = l
.pagex
/ conf.tilew
in
1340 let row = l
.pagey / conf.tileh
in
1342 let rec rowloop row y0 dispy h
=
1346 let dh = conf.tileh
- y0 in
1347 let dh = min h
dh in
1348 let rec colloop col x0 dispx w
=
1352 let dw = conf.tilew
- x0 in
1353 let dw = min w
dw in
1355 f col row dispx dispy
x0 y0 dw dh;
1356 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1359 colloop col tilex l
.pagedispx l
.pagevw;
1360 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1363 if l
.pagevw > 0 && l
.pagevh > 0
1364 then rowloop row tiley l
.pagedispy l
.pagevh;
1367 let gettileopaque l
col row =
1369 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1371 try Some
(Hashtbl.find state.tilemap
key)
1372 with Not_found
-> None
1375 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1376 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1377 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1380 let drawtiles l color
=
1382 let f col row x y tilex tiley w h
=
1383 match gettileopaque l
col row with
1384 | Some
(opaque
, _, t
) ->
1385 let params = x, y, w
, h
, tilex, tiley in
1389 GlFunc.blend_func `zero `one_minus_src_color
;
1391 drawtile
params opaque
;
1393 then Gl.disable `blend
;
1396 let s = Printf.sprintf
1400 let w = measurestr
fstate.fontsize
s in
1401 GlMisc.push_attrib
[`current
];
1402 GlDraw.color
(0.0, 0.0, 0.0);
1404 (float (x-2), float (y-2))
1405 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1406 GlDraw.color
(1.0, 1.0, 1.0);
1407 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1408 GlMisc.pop_attrib
();
1413 let lw = conf.winw
- state.scrollw
- x in
1416 let lh = conf.winh
- y in
1419 begin match state.texid
with
1421 Gl.enable `texture_2d
;
1422 GlTex.bind_texture `texture_2d id
;
1425 and x1 = float (x+w)
1426 and y1 = float (y+h
) in
1428 let tw = float w /. 16.0
1429 and th
= float h
/. 16.0 in
1430 let tx0 = float tilex /. 16.0
1431 and ty0
= float tiley /. 16.0 in
1433 and ty1
= ty0
+. th
in
1434 GlDraw.begins `quads
;
1435 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1436 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1437 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1438 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1441 Gl.disable `texture_2d
;
1443 GlDraw.color
(1.0, 1.0, 1.0);
1446 (float (x+w), float (y+h
));
1448 if w > 128 && h
> fstate.fontsize
+ 10
1450 GlDraw.color
(0.0, 0.0, 0.0);
1453 then (col*conf.tilew
, row*conf.tileh
)
1456 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1463 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1465 let tilevisible1 l
x y =
1467 and ax1
= l
.pagex
+ l
.pagevw
1469 and ay1
= l
.pagey + l
.pagevh in
1473 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1474 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1476 let rx0 = max
ax0 bx0
1477 and ry0
= max ay0 by0
1478 and rx1
= min ax1
bx1
1479 and ry1
= min ay1 by1
in
1481 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1482 nonemptyintersection
1485 let tilevisible layout n x y =
1486 let rec findpageinlayout m
= function
1487 | l
:: rest
when l
.pageno = n ->
1488 tilevisible1 l
x y || (
1489 match conf.columns
with
1490 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1493 | _ :: rest
-> findpageinlayout 0 rest
1496 findpageinlayout 0 layout;
1499 let tileready l
x y =
1500 tilevisible1 l
x y &&
1501 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1504 let tilepage n p
layout =
1505 let rec loop = function
1509 let f col row _ _ _ _ _ _ =
1510 if state.currently
= Idle
1512 match gettileopaque l
col row with
1515 let x = col*conf.tilew
1516 and y = row*conf.tileh
in
1518 let w = l
.pagew
- x in
1522 let h = l
.pageh
- y in
1527 then getpbo
w h conf.colorspace
1530 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1533 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1534 conf.tilew
, conf.tileh
1543 if nogeomcmds state.geomcmds
1547 let preloadlayout y =
1548 let y = if y < conf.winh
then 0 else y - conf.winh
in
1549 let h = conf.winh
*3 in
1554 let rec loop pages
=
1555 if state.currently
!= Idle
1560 begin match getopaque l
.pageno with
1562 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1563 state.currently
<- Loading
(l
, state.gen
);
1565 tilepage l
.pageno opaque pages
;
1570 if nogeomcmds state.geomcmds
1576 if conf.preload && state.currently
= Idle
1577 then load (preloadlayout state.y);
1580 let layoutready layout =
1581 let rec fold all ls
=
1582 all
&& match ls
with
1584 let seen = ref false in
1585 let allvisible = ref true in
1586 let foo col row _ _ _ _ _ _ =
1588 allvisible := !allvisible &&
1589 begin match gettileopaque l
col row with
1595 fold (!seen && !allvisible) rest
1598 let alltilesvisible = fold true layout in
1603 state.wthack
<- false;
1604 let y = bound y 0 state.maxy
in
1605 let y, layout, proceed
=
1606 match conf.maxwait
with
1607 | Some time
when state.ghyll
== noghyll ->
1608 begin match state.throttle
with
1610 let layout = layout y conf.winh
in
1611 let ready = layoutready layout in
1615 state.throttle
<- Some
(layout, y, now ());
1617 else G.postRedisplay "gotoy showall (None)";
1619 | Some
(_, _, started
) ->
1620 let dt = now () -. started
in
1623 state.throttle
<- None
;
1624 let layout = layout y conf.winh
in
1626 G.postRedisplay "maxwait";
1633 let layout = layout y conf.winh
in
1634 G.postRedisplay "gotoy ready";
1640 state.layout <- layout;
1641 begin match state.mode
with
1642 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1643 let rec loop = function
1645 state.mode
<- LinkNav
(Ltgendir
0)
1646 | l
:: _ when l
.pageno = pageno ->
1647 begin match getopaque pageno with
1649 state.mode
<- LinkNav
(Ltgendir
0)
1651 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1652 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1653 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1654 then state.mode
<- LinkNav
(Ltgendir
0)
1656 | _ :: rest
-> loop rest
1661 begin match state.mode
with
1662 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1663 if not
(pagevisible layout pageno)
1665 match state.layout with
1668 state.mode
<- Birdseye
(
1669 conf, leftx
, l
.pageno, hooverpageno
, anchor
1672 | LinkNav
(Ltgendir dir
as lt
) ->
1674 let rec loop = function
1677 match getopaque l
.pageno with
1683 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1685 if dir
> 0 then LDfirst
else LDlast
1691 | Lnotfound
-> loop rest
1693 showlinktype (getlink opaque
n);
1694 Ltexact
(l
.pageno, n)
1698 state.mode
<- LinkNav
linknav
1703 state.ghyll
<- noghyll;
1706 let mx, my
= state.mpos
in
1711 let conttiling pageno opaque
=
1712 tilepage pageno opaque
1713 (if conf.preload then preloadlayout state.y else state.layout)
1716 let gotoy_and_clear_text y =
1717 if not
conf.verbose
then state.text <- "";
1723 let coloff = l
.pagecol
* l
.pageh
in
1724 float (l
.pagey + coloff) /. float l
.pageh
1731 if conf.presentation
1732 then float l
.pagedispy /. float (calcips l
.pageh
)
1733 else float l
.pagedispy /. float conf.interpagespace
1735 (l
.pageno, top, dtop)
1739 match state.layout with
1740 | l
:: _ -> getanchor1 l
1742 let n = page_of_y state.y in
1743 let y, h = getpageyh n in
1744 let dy = y - state.y in
1746 if conf.presentation
1748 let ips = calcips h in
1749 float (dy + ips) /. float ips
1751 float dy /. float conf.interpagespace
1756 let getanchory (n, top, dtop) =
1757 let y, h = getpageyh n in
1758 if conf.presentation
1760 let ips = calcips h in
1761 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1763 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1766 let gotoanchor anchor
=
1767 gotoy (getanchory anchor
);
1771 cbput state.hists
.nav
(getanchor ());
1775 let anchor = cbgetc state.hists
.nav dir
in
1780 let scroll f n a
b =
1781 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1783 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1785 then s (float f /. float a
)
1788 then 1.0 -. s ((float (f-b) /. float (n-b)))
1795 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1796 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1798 let ins = float a
*. iv1
1799 and outs
= float (n-b) *. iv1 in
1801 ins +. outs
+. float ones
1803 let rec set (_N
, _A
, _B
) y sy
=
1804 let sum = summa
1.0 _N _A _B
in
1805 let dy = float (y - sy
) in
1809 then state.ghyll
<- noghyll
1812 let s = scroll n _N _A _B
in
1813 let y1 = y1 +. ((s *. dy) /. sum) in
1814 gotoy_and_clear_text (truncate
y1);
1815 state.ghyll
<- gf (n+1) y1;
1819 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1821 gf 0 (float state.y)
1824 match conf.ghyllscroll
with
1826 gotoy_and_clear_text y
1828 if state.ghyll
== noghyll
1829 then set nab
y state.y
1830 else state.ghyll
(Some
y)
1833 let gotopage n top =
1834 let y, h = getpageyh n in
1835 let y = y + (truncate
(top *. float h)) in
1839 let gotopage1 n top =
1840 let y = getpagey n in
1845 let invalidate s f =
1850 match state.geomcmds
with
1851 | ps
, [] when String.length ps
= 0 ->
1853 state.geomcmds
<- s, [];
1856 state.geomcmds
<- ps
, [s, f];
1858 | ps
, (s'
, _) :: rest
when s'
= s ->
1859 state.geomcmds
<- ps
, ((s, f) :: rest
);
1862 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1866 Hashtbl.iter
(fun _ opaque
->
1867 wcmd "freepage %s" opaque
;
1869 Hashtbl.clear
state.pagemap
;
1872 let opendoc path password
=
1874 state.password
<- password
;
1875 state.gen
<- state.gen
+ 1;
1876 state.docinfo
<- [];
1879 setaalevel
conf.aalevel
;
1880 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1881 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1882 invalidate "reqlayout"
1884 wcmd "reqlayout %d %d %s\000"
1885 conf.angle
(btod conf.proportional
) state.nameddest
;
1890 state.anchor <- getanchor ();
1891 state.wthack
<- !wtmode;
1892 opendoc state.path
state.password
;
1896 let c = c *. conf.colorscale
in
1900 let scalecolor2 (r, g
, b) =
1901 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1904 let docolumns = function
1906 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1907 let rec loop pageno pdimno pdim
y ph pdims
=
1908 if pageno = state.pagecount
1911 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1913 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1914 pdimno+1, pdim
, rest
1918 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1920 (if conf.presentation
1921 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1922 else (if pageno = 0 then 0 else conf.interpagespace
)
1925 a.(pageno) <- (pdimno, x, y, pdim
);
1926 loop (pageno+1) pdimno pdim
(y + h) h pdims
1928 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1929 conf.columns
<- Csingle
a;
1931 | Cmulti
((columns
, coverA
, coverB
), _) ->
1932 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1933 let rec loop pageno pdimno pdim
x y rowh pdims
=
1934 let rec fixrow m
= if m
= pageno then () else
1935 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1938 let y = y + (rowh
- h) / 2 in
1939 a.(m
) <- (pdimno, x, y, pdim
);
1943 if pageno = state.pagecount
1944 then fixrow (((pageno - 1) / columns
) * columns
)
1946 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1948 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1949 pdimno+1, pdim
, rest
1954 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1956 let x = (conf.winw
- state.scrollw
- w) / 2 in
1958 if conf.presentation
then calcips h else conf.interpagespace
in
1959 x, y + ips + rowh
, h
1962 if (pageno - coverA
) mod columns
= 0
1964 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1966 if conf.presentation
1968 let ips = calcips h in
1969 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1971 y + (if pageno = 0 then 0 else conf.interpagespace
)
1975 else x, y, max rowh
h
1979 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1982 if pageno = columns
&& conf.presentation
1984 let ips = calcips rowh
in
1985 for i
= 0 to pred columns
1987 let (pdimno, x, y, pdim
) = a.(i
) in
1988 a.(i
) <- (pdimno, x, y+ips, pdim
)
1994 fixrow (pageno - columns
);
1999 a.(pageno) <- (pdimno, x, y, pdim
);
2000 let x = x + w + xoff
*2 + conf.interpagespace
in
2001 loop (pageno+1) pdimno pdim
x y rowh' pdims
2003 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2004 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2007 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2008 let rec loop pageno pdimno pdim
y pdims
=
2009 if pageno = state.pagecount
2012 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2014 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2015 pdimno+1, pdim
, rest
2020 let rec loop1 n x y =
2021 if n = c then y else (
2022 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2023 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2026 let y = loop1 0 0 y in
2027 loop (pageno+1) pdimno pdim
y pdims
2029 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2030 conf.columns
<- Csplit
(c, a);
2034 docolumns conf.columns
;
2035 state.maxy
<- calcheight ();
2037 if state.w <= conf.winw
- state.scrollw
2041 let wthack = state.wthack in
2042 begin match state.mode
with
2043 | Birdseye
(_, _, pageno, _, _) ->
2044 let y, h = getpageyh pageno in
2045 let top = (conf.winh
- h) / 2 in
2046 gotoy (max
0 (y - top))
2047 | _ -> gotoanchor state.anchor
2049 state.wthack <- wthack;
2053 state.wthack <- false;
2054 GlDraw.viewport
0 0 w h;
2055 let firsttime = state.geomcmds
== firstgeomcmds in
2056 if not
firsttime && nogeomcmds state.geomcmds
2057 then state.anchor <- getanchor ();
2060 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2063 setfontsize fstate.fontsize
;
2064 GlMat.mode `modelview
;
2065 GlMat.load_identity
();
2067 GlMat.mode `projection
;
2068 GlMat.load_identity
();
2069 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2070 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2071 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2076 else float state.x /. float state.w
2078 invalidate "geometry"
2082 then state.x <- truncate
(relx *. float w);
2084 match conf.columns
with
2086 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2087 | Csplit
(c, _) -> w * c
2089 wcmd "geometry %d %d" w h);
2093 let len = String.length
state.text in
2096 match state.mode
with
2099 let h, _, _ = state.uioh#scrollpw
in
2105 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2106 (x+.w, float (conf.winh
- hscrollh))
2109 let w = float (conf.winw
- state.scrollw
- 1) in
2110 if state.progress
>= 0.0 && state.progress
< 1.0
2112 GlDraw.color
(0.3, 0.3, 0.3);
2113 let w1 = w *. state.progress
in
2115 GlDraw.color
(0.0, 0.0, 0.0);
2119 GlDraw.color
(0.0, 0.0, 0.0);
2123 GlDraw.color
(1.0, 1.0, 1.0);
2124 drawstring fstate.fontsize
2125 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2128 match state.mode
with
2129 | Textentry
((prefix
, text, _, _, _, _), _) ->
2133 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2135 Printf.sprintf
"%s%s_" prefix
text
2144 if not
(istextentry state.mode
)
2146 let s1 = "(press 'e' to review error messasges)" in
2147 if String.length
s > 0 then s ^
" " ^
s1 else s1
2152 if String.length
s > 0
2157 let len = Queue.length
state.tilelru
in
2159 match state.throttle
with
2162 then preloadlayout state.y
2164 | Some
(layout, _, _) ->
2168 if state.memused
<= conf.memlimit
2173 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2174 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2175 let (_, pw, ph
, _) = getpagedim n in
2178 && colorspace
= conf.colorspace
2179 && angle
= conf.angle
2183 let x = col*conf.tilew
2184 and y = row*conf.tileh
in
2185 tilevisible (Lazy.force_val
layout) n x y
2187 then Queue.push lruitem
state.tilelru
2190 wcmd "freetile %s" p
;
2191 state.memused
<- state.memused
- s;
2192 state.uioh#infochanged Memused
;
2193 Hashtbl.remove
state.tilemap k
;
2202 Queue.iter
(fun (k
, p
, s) ->
2203 wcmd "freetile %s" p
;
2204 state.memused
<- state.memused
- s;
2205 state.uioh#infochanged Memused
;
2206 Hashtbl.remove
state.tilemap k
;
2208 Queue.clear
state.tilelru
;
2212 let logcurrently = function
2213 | Idle
-> dolog "Idle"
2214 | Loading
(l
, gen
) ->
2215 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2216 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2218 "Tiling %d[%d,%d] page=%s cs=%s angle"
2219 l
.pageno col row pageopaque
2220 (colorspace_to_string colorspace
)
2222 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2223 angle gen
conf.angle
state.gen
2225 conf.tilew
conf.tileh
2232 (* dolog "%S" cmds; *)
2235 try String.index cmds ' '
2236 with Not_found
-> -1
2241 let l = String.length cmds
in
2242 let op = String.sub cmds
0 spacepos in
2244 if l - spacepos < 2 then ""
2245 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2250 state.uioh#infochanged Pdim
;
2254 state.rects
<- state.rects1
;
2255 G.postRedisplay "clearrects";
2259 try Scanf.sscanf
args "%u" (fun n -> n)
2261 dolog "error processing 'continue' %S: %s"
2262 cmds
(Printexc.to_string exn
);
2265 state.pagecount
<- n;
2266 begin match state.currently
with
2268 state.currently
<- Idle
;
2269 state.outlines
<- Array.of_list
(List.rev
l)
2273 let cur, cmds
= state.geomcmds
in
2274 if String.length
cur = 0
2275 then failwith
"umpossible";
2277 begin match List.rev cmds
with
2279 state.geomcmds
<- "", [];
2283 state.geomcmds
<- s, List.rev rest
;
2285 if conf.maxwait
= None
2286 then G.postRedisplay "continue";
2296 then showtext ' '
args
2299 Buffer.add_string
state.errmsgs
args;
2300 state.newerrmsgs
<- true;
2301 G.postRedisplay "error message"
2304 let progress, text =
2306 Scanf.sscanf
args "%f %n"
2308 f, String.sub
args pos
(String.length
args - pos
))
2310 dolog "error processing 'progress' %S: %s"
2311 cmds
(Printexc.to_string exn
);
2315 state.progress <- progress;
2316 G.postRedisplay "progress"
2319 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2321 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2322 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2323 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2325 dolog "error processing 'firstmatch' %S: %s"
2326 cmds
(Printexc.to_string exn
);
2329 let y = (getpagey pageno) + truncate
y0 in
2332 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2335 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2337 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2338 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2339 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2341 dolog "error processing 'match' %S: %s"
2342 cmds
(Printexc.to_string exn
);
2346 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2351 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2353 dolog "error processing 'page' %S: %s"
2354 cmds
(Printexc.to_string exn
);
2357 begin match state.currently
with
2358 | Loading
(l, gen
) ->
2359 vlog "page %d took %f sec" l.pageno t
;
2360 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2361 begin match state.throttle
with
2363 let preloadedpages =
2365 then preloadlayout state.y
2370 Set.Make
(struct type t
= int let compare = (-) end) in
2372 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2373 IntSet.empty
preloadedpages
2376 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2377 if not
(IntSet.mem
pageno set)
2379 wcmd "freepage %s" opaque
;
2385 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2388 state.currently
<- Idle
;
2391 tilepage l.pageno pageopaque state.layout;
2393 load preloadedpages;
2394 if pagevisible state.layout l.pageno
2395 && layoutready state.layout
2396 then G.postRedisplay "page";
2399 | Some
(layout, _, _) ->
2400 state.currently
<- Idle
;
2401 tilepage l.pageno pageopaque layout;
2406 dolog "Inconsistent loading state";
2407 logcurrently state.currently
;
2412 let (x, y, opaque
, size
, t
) =
2414 Scanf.sscanf
args "%u %u %s %u %f"
2415 (fun x y p size t
-> (x, y, p
, size
, t
))
2417 dolog "error processing 'tile' %S: %s"
2418 cmds
(Printexc.to_string exn
);
2421 begin match state.currently
with
2422 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2423 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2426 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2428 wcmd "freetile %s" opaque
;
2429 state.currently
<- Idle
;
2433 puttileopaque l col row gen cs angle opaque size t
;
2434 state.memused
<- state.memused
+ size
;
2435 state.uioh#infochanged Memused
;
2437 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2438 opaque
, size
) state.tilelru
;
2441 match state.throttle
with
2442 | None
-> state.layout
2443 | Some
(layout, _, _) -> layout
2446 state.currently
<- Idle
;
2448 && conf.colorspace
= cs
2449 && conf.angle
= angle
2450 && tilevisible layout l.pageno x y
2451 then conttiling l.pageno pageopaque;
2453 begin match state.throttle
with
2456 then state.wthack <- not
(layoutready state.layout);
2457 preload state.layout;
2459 && conf.colorspace
= cs
2460 && conf.angle
= angle
2461 && tilevisible state.layout l.pageno x y
2462 then G.postRedisplay "tile nothrottle";
2464 | Some
(layout, y, _) ->
2465 let ready = layoutready layout in
2468 state.wthack <- false;
2470 state.layout <- layout;
2471 state.throttle
<- None
;
2472 G.postRedisplay "throttle";
2479 dolog "Inconsistent tiling state";
2480 logcurrently state.currently
;
2487 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2489 dolog "error processing 'pdim' %S: %s"
2490 cmds
(Printexc.to_string exn
);
2493 state.uioh#infochanged Pdim
;
2494 state.pdims
<- pdim :: state.pdims
2497 let (l, n, t
, h, pos
) =
2499 Scanf.sscanf
args "%u %u %d %u %n"
2500 (fun l n t
h pos
-> l, n, t
, h, pos
)
2502 dolog "error processing 'o' %S: %s"
2503 cmds
(Printexc.to_string exn
);
2506 let s = String.sub
args pos
(String.length
args - pos
) in
2507 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2508 begin match state.currently
with
2509 | Outlining outlines
->
2510 state.currently
<- Outlining
(outline :: outlines
)
2512 state.currently
<- Outlining
[outline]
2514 dolog "invalid outlining state";
2515 logcurrently currently
2521 Scanf.sscanf
args "%u %u %d"
2522 (fun n t
h -> n, t
, h)
2524 dolog "error processing 'a' %S: %s"
2525 cmds
(Printexc.to_string exn
);
2529 if conf.presentation
2531 else float t
/. float h, 0.0
2533 state.anchor <- (n, top, dtop)
2536 state.docinfo
<- (1, args) :: state.docinfo
2539 state.uioh#infochanged Docinfo
;
2540 state.docinfo
<- List.rev
state.docinfo
2543 dolog "unknown cmd `%S'" cmds
2548 let action = function
2549 | HCprev
-> cbget cb ~
-1
2550 | HCnext
-> cbget cb
1
2551 | HCfirst
-> cbget cb ~
-(cb
.rc)
2552 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2553 and cancel
() = cb
.rc <- rc
2557 let search pattern forward
=
2558 if String.length pattern
> 0
2561 match state.layout with
2564 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2566 wcmd "search %d %d %d %d,%s\000"
2567 (btod conf.icase
) pn py
(btod forward
) pattern
;
2570 let intentry text key =
2572 if key >= 32 && key < 127
2578 let text = addchar text c in
2582 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2586 let linknentry text key =
2588 if key >= 32 && key < 127
2594 let text = addchar text c in
2598 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2603 if String.length
s > 0
2606 let l = String.length
s in
2607 let rec loop pos
n = if pos
= l then n else
2608 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2609 loop (pos
+1) (n*26 + m)
2612 let rec loop n = function
2615 match getopaque l.pageno with
2616 | None
-> loop n rest
2618 let m = getlinkcount opaque
in
2621 let under = getlink opaque
n in
2624 else loop (n-m) rest
2626 loop n state.layout;
2630 let textentry text key =
2631 if key land 0xff00 = 0xff00
2633 else TEcont
(text ^
Wsi.toutf8
key)
2636 let reqlayout angle proportional
=
2637 match state.throttle
with
2639 if nogeomcmds state.geomcmds
2640 then state.anchor <- getanchor ();
2641 conf.angle
<- angle
mod 360;
2644 match state.mode
with
2645 | LinkNav
_ -> state.mode
<- View
2648 conf.proportional
<- proportional
;
2649 invalidate "reqlayout"
2650 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2654 let settrim trimmargins trimfuzz
=
2655 if nogeomcmds state.geomcmds
2656 then state.anchor <- getanchor ();
2657 conf.trimmargins
<- trimmargins
;
2658 conf.trimfuzz
<- trimfuzz
;
2659 let x0, y0, x1, y1 = trimfuzz
in
2660 invalidate "settrim"
2662 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2667 match state.throttle
with
2669 let zoom = max
0.01 zoom in
2670 if zoom <> conf.zoom
2672 state.prevzoom
<- conf.zoom;
2674 reshape conf.winw
conf.winh
;
2675 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2678 | Some
(layout, y, started
) ->
2680 match conf.maxwait
with
2684 let dt = now () -. started
in
2692 let setcolumns mode columns coverA coverB
=
2693 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2697 then showtext '
!'
"split mode doesn't work in bird's eye"
2699 conf.columns
<- Csplit
(-columns
, [||]);
2707 conf.columns
<- Csingle
[||];
2712 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2716 reshape conf.winw
conf.winh
;
2719 let enterbirdseye () =
2720 let zoom = float conf.thumbw
/. float conf.winw
in
2721 let birdseyepageno =
2722 let cy = conf.winh
/ 2 in
2726 let rec fold best
= function
2729 let d = cy - (l.pagedispy + l.pagevh/2)
2730 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2731 if abs
d < abs dbest
2738 state.mode
<- Birdseye
(
2739 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2742 conf.presentation
<- false;
2743 conf.interpagespace
<- 10;
2744 conf.hlinks
<- false;
2746 state.mstate
<- Mnone
;
2747 conf.maxwait
<- None
;
2749 match conf.beyecolumns
with
2752 Cmulti
((c, 0, 0), [||])
2753 | None
-> Csingle
[||]
2755 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2758 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2763 reshape conf.winw
conf.winh
;
2766 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2768 conf.zoom <- c.zoom;
2769 conf.presentation
<- c.presentation
;
2770 conf.interpagespace
<- c.interpagespace
;
2771 conf.maxwait
<- c.maxwait
;
2772 conf.hlinks
<- c.hlinks
;
2773 conf.beyecolumns
<- (
2774 match conf.columns
with
2775 | Cmulti
((c, _, _), _) -> Some
c
2777 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2780 match c.columns
with
2781 | Cmulti
(c, _) -> Cmulti
(c, [||])
2782 | Csingle
_ -> Csingle
[||]
2783 | Csplit
(c, _) -> Csplit
(c, [||])
2788 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2791 reshape conf.winw
conf.winh
;
2792 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2795 let togglebirdseye () =
2796 match state.mode
with
2797 | Birdseye vals
-> leavebirdseye vals
true
2798 | View
-> enterbirdseye ()
2802 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2803 let pageno = max
0 (pageno - incr
) in
2804 let rec loop = function
2805 | [] -> gotopage1 pageno 0
2806 | l :: _ when l.pageno = pageno ->
2807 if l.pagedispy >= 0 && l.pagey = 0
2808 then G.postRedisplay "upbirdseye"
2809 else gotopage1 pageno 0
2810 | _ :: rest
-> loop rest
2813 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2816 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2817 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2818 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2819 let rec loop = function
2821 let y, h = getpageyh pageno in
2822 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2824 | l :: _ when l.pageno = pageno ->
2825 if l.pagevh != l.pageh
2826 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2827 else G.postRedisplay "downbirdseye"
2828 | _ :: rest
-> loop rest
2833 let optentry mode
_ key =
2834 let btos b = if b then "on" else "off" in
2835 if key >= 32 && key < 127
2837 let c = Char.chr
key in
2841 try conf.scrollstep
<- int_of_string
s with exc
->
2842 state.text <- Printf.sprintf
"bad integer `%s': %s"
2843 s (Printexc.to_string exc
)
2845 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2850 conf.autoscrollstep
<- int_of_string
s;
2851 if state.autoscroll
<> None
2852 then state.autoscroll
<- Some
conf.autoscrollstep
2854 state.text <- Printf.sprintf
"bad integer `%s': %s"
2855 s (Printexc.to_string exc
)
2857 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2862 let n, a, b = multicolumns_of_string s in
2863 setcolumns mode
n a b;
2865 state.text <- Printf.sprintf
"bad columns `%s': %s"
2866 s (Printexc.to_string exc
)
2868 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2873 let zoom = float (int_of_string
s) /. 100.0 in
2876 state.text <- Printf.sprintf
"bad integer `%s': %s"
2877 s (Printexc.to_string exc
)
2879 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2884 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2886 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2887 begin match mode
with
2889 leavebirdseye beye
false;
2894 state.text <- Printf.sprintf
"bad integer `%s': %s"
2895 s (Printexc.to_string exc
)
2897 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2902 Some
(int_of_string
s)
2904 state.text <- Printf.sprintf
"bad integer `%s': %s"
2905 s (Printexc.to_string exc
);
2908 | Some angle
-> reqlayout angle
conf.proportional
2911 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2914 conf.icase
<- not
conf.icase
;
2915 TEdone
("case insensitive search " ^
(btos conf.icase
))
2918 conf.preload <- not
conf.preload;
2920 TEdone
("preload " ^
(btos conf.preload))
2923 conf.verbose
<- not
conf.verbose
;
2924 TEdone
("verbose " ^
(btos conf.verbose
))
2927 conf.debug
<- not
conf.debug
;
2928 TEdone
("debug " ^
(btos conf.debug
))
2931 conf.maxhfit
<- not
conf.maxhfit
;
2932 state.maxy
<- calcheight ();
2933 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2936 conf.crophack
<- not
conf.crophack
;
2937 TEdone
("crophack " ^
btos conf.crophack
)
2941 match conf.maxwait
with
2943 conf.maxwait
<- Some infinity
;
2944 "always wait for page to complete"
2946 conf.maxwait
<- None
;
2947 "show placeholder if page is not ready"
2952 conf.underinfo
<- not
conf.underinfo
;
2953 TEdone
("underinfo " ^
btos conf.underinfo
)
2956 conf.savebmarks
<- not
conf.savebmarks
;
2957 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2963 match state.layout with
2968 conf.interpagespace
<- int_of_string
s;
2969 docolumns conf.columns
;
2970 state.maxy
<- calcheight ();
2971 let y = getpagey pageno in
2974 state.text <- Printf.sprintf
"bad integer `%s': %s"
2975 s (Printexc.to_string exc
)
2977 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2980 reqlayout conf.angle
(not
conf.proportional
);
2981 TEdone
("proportional display " ^
btos conf.proportional
)
2984 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2985 TEdone
("trim margins " ^
btos conf.trimmargins
)
2988 conf.invert
<- not
conf.invert
;
2989 TEdone
("invert colors " ^
btos conf.invert
)
2993 cbput state.hists
.sel
s;
2996 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2997 textentry, ondone, true)
3000 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3006 class type lvsource
= object
3007 method getitemcount
: int
3008 method getitem
: int -> (string * int)
3009 method hasaction
: int -> bool
3018 method getactive
: int
3019 method getfirst
: int
3020 method getqsearch
: string
3021 method setqsearch
: string -> unit
3025 class virtual lvsourcebase
= object
3026 val mutable m_active
= 0
3027 val mutable m_first
= 0
3028 val mutable m_qsearch
= ""
3029 val mutable m_pan
= 0
3030 method getactive
= m_active
3031 method getfirst
= m_first
3032 method getqsearch
= m_qsearch
3033 method getpan
= m_pan
3034 method setqsearch
s = m_qsearch
<- s
3037 let withoutlastutf8 s =
3038 let len = String.length
s in
3046 let b = Char.code
s.[pos
] in
3047 if b land 0b11000000 = 0b11000000
3052 if Char.code
s.[len-1] land 0x80 = 0
3056 String.sub
s 0 first;
3059 let textentrykeyboard
3060 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3062 if key >= 0xffb0 && key <= 0xffb9
3063 then key - 0xffb0 + 48 else key
3066 state.mode
<- Textentry
(te
, onleave
);
3069 G.postRedisplay "textentrykeyboard enttext";
3071 let histaction cmd
=
3074 | Some
(action, _) ->
3075 state.mode
<- Textentry
(
3076 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3078 G.postRedisplay "textentry histaction"
3081 | 0xff08 -> (* backspace *)
3082 let s = withoutlastutf8 text in
3083 let len = String.length
s in
3084 if cancelonempty
&& len = 0
3087 G.postRedisplay "textentrykeyboard after cancel";
3090 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3093 | 0xff0d | 0xff8d -> (* (kp) enter *)
3096 G.postRedisplay "textentrykeyboard after confirm"
3098 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3099 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3100 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3101 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3103 | 0xff1b -> (* escape*)
3104 if String.length
text = 0
3106 begin match opthist
with
3108 | Some
(_, onhistcancel
) -> onhistcancel
()
3112 G.postRedisplay "textentrykeyboard after cancel2"
3115 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3118 | 0xff9f | 0xffff -> () (* delete *)
3121 && key land 0xff00 != 0xff00 (* keyboard *)
3122 && key land 0xfe00 != 0xfe00 (* xkb *)
3123 && key land 0xfd00 != 0xfd00 (* 3270 *)
3125 begin match onkey
text key with
3129 G.postRedisplay "textentrykeyboard after confirm2";
3132 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3136 G.postRedisplay "textentrykeyboard after cancel3"
3139 state.mode
<- Textentry
(te
, onleave
);
3140 G.postRedisplay "textentrykeyboard switch";
3144 vlog "unhandled key %s" (Wsi.keyname
key)
3147 let firstof first active
=
3148 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3149 then max
0 (active
- (fstate.maxrows
/2))
3153 let calcfirst first active
=
3156 let rows = active
- first in
3157 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3161 let scrollph y maxy
=
3162 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3163 let sh = float conf.winh
/. sh in
3164 let sh = max
sh (float conf.scrollh
) in
3169 else float y /. float maxy
3171 let position = (float conf.winh
-. sh) *. percent in
3174 if position +. sh > float conf.winh
3175 then float conf.winh
-. sh
3181 let coe s = (s :> uioh
);;
3183 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3185 val m_pan
= source#getpan
3186 val m_first
= source#getfirst
3187 val m_active
= source#getactive
3188 val m_qsearch
= source#getqsearch
3189 val m_prev_uioh
= state.uioh
3191 method private elemunder
y =
3192 let n = y / (fstate.fontsize
+1) in
3193 if m_first
+ n < source#getitemcount
3195 if source#hasaction
(m_first
+ n)
3196 then Some
(m_first
+ n)
3203 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3204 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3205 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3206 GlDraw.color
(1., 1., 1.);
3207 Gl.enable `texture_2d
;
3208 let fs = fstate.fontsize
in
3210 let ww = fstate.wwidth
in
3211 let tabw = 30.0*.ww in
3212 let itemcount = source#getitemcount
in
3214 if (row - m_first
) > fstate.maxrows
3217 if row >= 0 && row < itemcount
3219 let (s, level
) = source#getitem
row in
3220 let y = (row - m_first
) * nfs in
3221 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3224 Gl.disable `texture_2d
;
3225 GlDraw.polygon_mode `both `line
;
3226 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3227 GlDraw.rect (1., float (y + 1))
3228 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3229 GlDraw.polygon_mode `both `fill
;
3230 GlDraw.color
(1., 1., 1.);
3231 Gl.enable `texture_2d
;
3234 let drawtabularstring s =
3235 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3238 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3241 let len = String.length
s - tabpos - 1 in
3242 let s1 = String.sub
s 0 tabpos
3243 and s2
= String.sub
s (tabpos + 1) len in
3244 let nx = drawstr x s1 in
3246 let x = x +. (max
tabw sw) in
3253 let _ = drawtabularstring s in
3260 Gl.disable `texture_2d
;
3262 method updownlevel incr
=
3263 let len = source#getitemcount
in
3265 if m_active
>= 0 && m_active
< len
3266 then snd
(source#getitem m_active
)
3270 if i
= len then i
-1 else if i
= -1 then 0 else
3271 let _, l = source#getitem i
in
3272 if l != curlevel then i
else flow (i
+incr
)
3274 let active = flow m_active
in
3275 let first = calcfirst m_first
active in
3276 G.postRedisplay "outline updownlevel";
3277 {< m_active
= active; m_first
= first >}
3279 method private key1
key mask
=
3280 let set1 active first qsearch
=
3281 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3283 let search active pattern incr
=
3286 if n >= 0 && n < source#getitemcount
3288 let s, _ = source#getitem
n in
3290 (try ignore
(Str.search_forward
re s 0); true
3291 with Not_found
-> false)
3293 else loop (n + incr
)
3300 let re = Str.regexp_case_fold pattern
in
3306 let itemcount = source#getitemcount
in
3307 let find start incr
=
3309 if i
= -1 || i
= itemcount
3312 if source#hasaction i
3314 else find (i
+ incr
)
3319 let set active first =
3320 let first = bound first 0 (itemcount - fstate.maxrows
) in
3322 coe {< m_active
= active; m_first
= first >}
3325 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3327 let incr1 = if incr
> 0 then 1 else -1 in
3328 if isvisible m_first m_active
3331 let next = m_active
+ incr
in
3333 if next < 0 || next >= itemcount
3335 else find next incr1
3337 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3343 let first = m_first
+ incr
in
3344 let first = bound first 0 (itemcount - 1) in
3346 let next = m_active
+ incr
in
3347 let next = bound next 0 (itemcount - 1) in
3350 let active = if next = -1 then m_active
else next in
3353 let first = min
next m_first
in
3355 if abs
(next - first) > fstate.maxrows
3361 let first = m_first
+ incr
in
3362 let first = bound first 0 (itemcount - 1) in
3364 let next = m_active
+ incr
in
3365 let next = bound next 0 (itemcount - 1) in
3366 let next = find next incr1 in
3368 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3370 let active = if m_active
= -1 then next else m_active
in
3375 if isvisible first active
3381 G.postRedisplay "listview navigate";
3385 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3386 let incr = if key = 0x72 then -1 else 1 in
3388 match search (m_active
+ incr) m_qsearch
incr with
3390 state.text <- m_qsearch ^
" [not found]";
3393 state.text <- m_qsearch
;
3394 active, firstof m_first
active
3396 G.postRedisplay "listview ctrl-r/s";
3397 set1 active first m_qsearch
;
3399 | 0xff08 -> (* backspace *)
3400 if String.length m_qsearch
= 0
3403 let qsearch = withoutlastutf8 m_qsearch
in
3404 let len = String.length
qsearch in
3408 G.postRedisplay "listview empty qsearch";
3409 set1 m_active m_first
"";
3413 match search m_active
qsearch ~
-1 with
3415 state.text <- qsearch ^
" [not found]";
3418 state.text <- qsearch;
3419 active, firstof m_first
active
3421 G.postRedisplay "listview backspace qsearch";
3422 set1 active first qsearch
3425 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3426 let pattern = m_qsearch ^
Wsi.toutf8
key in
3428 match search m_active
pattern 1 with
3430 state.text <- pattern ^
" [not found]";
3433 state.text <- pattern;
3434 active, firstof m_first
active
3436 G.postRedisplay "listview qsearch add";
3437 set1 active first pattern;
3439 | 0xff1b -> (* escape *)
3441 if String.length m_qsearch
= 0
3443 G.postRedisplay "list view escape";
3446 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3448 | None
-> m_prev_uioh
3453 G.postRedisplay "list view kill qsearch";
3454 source#setqsearch
"";
3455 coe {< m_qsearch
= "" >}
3458 | 0xff0d | 0xff8d -> (* (kp) enter *)
3460 let self = {< m_qsearch
= "" >} in
3461 source#setqsearch
"";
3463 G.postRedisplay "listview enter";
3464 if m_active
>= 0 && m_active
< source#getitemcount
3466 source#exit
(coe self) false m_active m_first m_pan
"";
3469 source#exit
(coe self) true m_active m_first m_pan
"";
3472 begin match opt with
3473 | None
-> m_prev_uioh
3477 | 0xff9f | 0xffff -> (* (kp) delete *)
3480 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3481 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3482 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3483 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3485 | 0xff53 | 0xff98 -> (* (kp) right *)
3487 G.postRedisplay "listview right";
3488 coe {< m_pan
= m_pan
- 1 >}
3490 | 0xff51 | 0xff96 -> (* (kp) left *)
3492 G.postRedisplay "listview left";
3493 coe {< m_pan
= m_pan
+ 1 >}
3495 | 0xff50 | 0xff95 -> (* (kp) home *)
3496 let active = find 0 1 in
3497 G.postRedisplay "listview home";
3500 | 0xff57 | 0xff9c -> (* (kp) end *)
3501 let first = max
0 (itemcount - fstate.maxrows
) in
3502 let active = find (itemcount - 1) ~
-1 in
3503 G.postRedisplay "listview end";
3506 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3510 dolog "listview unknown key %#x" key; coe self
3512 method key key mask
=
3513 match state.mode
with
3514 | Textentry te
-> textentrykeyboard key mask te
; coe self
3515 | _ -> self#key1
key mask
3517 method button button down
x y _ =
3520 | 1 when x > conf.winw
- conf.scrollbw
->
3521 G.postRedisplay "listview scroll";
3524 let _, position, sh = self#
scrollph in
3525 if y > truncate
position && y < truncate
(position +. sh)
3527 state.mstate
<- Mscrolly
;
3531 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3532 let first = truncate
(s *. float source#getitemcount
) in
3533 let first = min source#getitemcount
first in
3534 Some
(coe {< m_first
= first; m_active
= first >})
3536 state.mstate
<- Mnone
;
3539 | 1 when not down
->
3540 begin match self#elemunder
y with
3542 G.postRedisplay "listview click";
3544 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3548 | n when (n == 4 || n == 5) && not down
->
3549 let len = source#getitemcount
in
3551 if n = 5 && m_first
+ fstate.maxrows
>= len
3555 let first = m_first
+ (if n == 4 then -1 else 1) in
3556 bound first 0 (len - 1)
3558 G.postRedisplay "listview wheel";
3559 Some
(coe {< m_first
= first >})
3560 | n when (n = 6 || n = 7) && not down
->
3561 let inc = m_first
+ (if n = 7 then -1 else 1) in
3562 G.postRedisplay "listview hwheel";
3563 Some
(coe {< m_pan
= m_pan
+ inc >})
3568 | None
-> m_prev_uioh
3572 match state.mstate
with
3574 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3575 let first = truncate
(s *. float source#getitemcount
) in
3576 let first = min source#getitemcount
first in
3577 G.postRedisplay "listview motion";
3578 coe {< m_first
= first; m_active
= first >}
3581 method pmotion
x y =
3582 if x < conf.winw
- conf.scrollbw
3585 match self#elemunder
y with
3586 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3587 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3591 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3596 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3600 method infochanged
_ = ()
3602 method scrollpw
= (0, 0.0, 0.0)
3604 let nfs = fstate.fontsize
+ 1 in
3605 let y = m_first
* nfs in
3606 let itemcount = source#getitemcount
in
3607 let maxi = max
0 (itemcount - fstate.maxrows
) in
3608 let maxy = maxi * nfs in
3609 let p, h = scrollph y maxy in
3612 method modehash
= modehash
3615 class outlinelistview ~source
=
3618 ~source
:(source
:> lvsource
)
3620 ~modehash
:(findkeyhash conf "outline")
3623 method key key mask
=
3624 let calcfirst first active =
3627 let rows = active - first in
3629 if String.length
state.text = 0
3631 else fstate.maxrows - 2
3633 if rows > maxrows then active - maxrows else first
3637 let active = m_active
+ incr in
3638 let active = bound active 0 (source#getitemcount
- 1) in
3639 let first = calcfirst m_first
active in
3640 G.postRedisplay "outline navigate";
3641 coe {< m_active
= active; m_first
= first >}
3643 let ctrl = Wsi.withctrl mask
in
3645 | 110 when ctrl -> (* ctrl-n *)
3646 source#narrow m_qsearch
;
3647 G.postRedisplay "outline ctrl-n";
3648 coe {< m_first
= 0; m_active
= 0 >}
3650 | 117 when ctrl -> (* ctrl-u *)
3652 G.postRedisplay "outline ctrl-u";
3654 coe {< m_first
= 0; m_active
= 0 >}
3656 | 108 when ctrl -> (* ctrl-l *)
3657 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3658 G.postRedisplay "outline ctrl-l";
3659 coe {< m_first
= first >}
3661 | 0xff9f | 0xffff -> (* (kp) delete *)
3662 source#remove m_active
;
3663 G.postRedisplay "outline delete";
3664 let active = max
0 (m_active
-1) in
3665 coe {< m_first
= firstof m_first
active;
3666 m_active
= active >}
3668 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3669 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3670 | 0xff55 | 0xff9a -> (* (kp) prior *)
3671 navigate ~
-(fstate.maxrows)
3672 | 0xff56 | 0xff9b -> (* (kp) next *)
3673 navigate fstate.maxrows
3675 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3679 G.postRedisplay "outline ctrl right";
3680 {< m_pan
= m_pan
+ 1 >}
3682 else self#updownlevel
1
3686 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3690 G.postRedisplay "outline ctrl left";
3691 {< m_pan
= m_pan
- 1 >}
3693 else self#updownlevel ~
-1
3697 | 0xff50 | 0xff95 -> (* (kp) home *)
3698 G.postRedisplay "outline home";
3699 coe {< m_first
= 0; m_active
= 0 >}
3701 | 0xff57 | 0xff9c -> (* (kp) end *)
3702 let active = source#getitemcount
- 1 in
3703 let first = max
0 (active - fstate.maxrows) in
3704 G.postRedisplay "outline end";
3705 coe {< m_active
= active; m_first
= first >}
3707 | _ -> super#
key key mask
3710 let outlinesource usebookmarks
=
3713 inherit lvsourcebase
3714 val mutable m_items
= empty
3715 val mutable m_orig_items
= empty
3716 val mutable m_prev_items
= empty
3717 val mutable m_narrow_pattern
= ""
3718 val mutable m_hadremovals
= false
3720 method getitemcount
=
3721 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3724 if n == Array.length m_items
&& m_hadremovals
3726 ("[Confirm removal]", 0)
3728 let s, n, _ = m_items
.(n) in
3731 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3732 ignore
(uioh
, first, qsearch);
3733 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3735 if String.length m_narrow_pattern
= 0
3741 if not
confrimremoval
3743 let _, _, anchor = m_items
.(active) in
3744 gotoghyll (getanchory anchor);
3748 state.bookmarks
<- Array.to_list m_items
;
3749 m_orig_items
<- m_items
;
3752 else m_items
<- items;
3756 method hasaction
_ = true
3759 if Array.length m_items
!= Array.length m_orig_items
3760 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3763 method narrow
pattern =
3764 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3768 let rec loop accu n =
3771 m_narrow_pattern
<- pattern;
3772 m_items
<- Array.of_list
accu
3775 let (s, _, _) as o = m_items
.(n) in
3777 if (try ignore
(Str.search_forward
re s 0); true
3778 with Not_found
-> false)
3784 loop [] (Array.length m_items
- 1)
3789 then Array.of_list
state.bookmarks
3792 m_items
<- m_orig_items
3797 if m >= 0 && m < Array.length m_items
3799 m_hadremovals
<- true;
3800 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3801 let n = if n >= m then n+1 else n in
3806 method reset
anchor items =
3807 m_hadremovals
<- false;
3808 if m_orig_items
== empty || m_prev_items
!= items
3810 m_orig_items
<- items;
3811 if String.length m_narrow_pattern
= 0
3812 then m_items
<- items;
3814 m_prev_items
<- items;
3815 let rely = getanchory anchor in
3817 let rec loop n best bestd
=
3818 if n = Array.length m_items
3821 let (_, _, anchor) = m_items
.(n) in
3822 let orely = getanchory anchor in
3823 let d = abs
(orely - rely) in
3826 else loop (n+1) best bestd
3831 m_first
<- firstof m_first
active
3835 let enterselector usebookmarks
=
3836 let source = outlinesource usebookmarks
in
3840 then Array.of_list
state.bookmarks
3843 if Array.length
outlines = 0
3845 showtext ' ' errmsg
;
3848 state.text <- source#greetmsg
;
3849 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3850 let anchor = getanchor () in
3851 source#reset
anchor outlines;
3852 state.uioh
<- coe (new outlinelistview ~
source);
3853 G.postRedisplay "enter selector";
3857 let enteroutlinemode =
3858 let f = enterselector false in
3859 fun ()-> f "Document has no outline";
3862 let enterbookmarkmode =
3863 let f = enterselector true in
3864 fun () -> f "Document has no bookmarks (yet)";
3867 let color_of_string s =
3868 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3869 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3873 let color_to_string (r, g
, b) =
3874 let r = truncate
(r *. 256.0)
3875 and g
= truncate
(g
*. 256.0)
3876 and b = truncate
(b *. 256.0) in
3877 Printf.sprintf
"%d/%d/%d" r g
b
3880 let irect_of_string s =
3881 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3884 let irect_to_string (x0,y0,x1,y1) =
3885 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3888 let makecheckers () =
3889 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3891 converted by Issac Trotts. July 25, 2002 *)
3892 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3893 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3894 let id = GlTex.gen_texture
() in
3895 GlTex.bind_texture `texture_2d
id;
3896 GlPix.store
(`unpack_alignment
1);
3897 GlTex.image2d
image;
3898 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3899 [ `mag_filter `nearest
; `min_filter `nearest
];
3903 let setcheckers enabled
=
3904 match state.texid
with
3906 if enabled
then state.texid
<- Some
(makecheckers ())
3911 GlTex.delete_texture texid
;
3912 state.texid
<- None
;
3916 let int_of_string_with_suffix s =
3917 let l = String.length
s in
3921 let suffix = Char.lowercase
s.[l-1] in
3923 | 'k'
-> String.sub
s 0 (l-1), 10
3924 | '
m'
-> String.sub
s 0 (l-1), 20
3925 | 'g'
-> String.sub
s 0 (l-1), 30
3929 let n = int_of_string
s1 in
3930 let m = n lsl shift
in
3932 then raise
(Failure
"value too large")
3936 let string_with_suffix_of_int n =
3941 if n land ((1 lsl 30) - 1) = 0
3944 if n land ((1 lsl 20) - 1) = 0
3947 if n land ((1 lsl 10) - 1) = 0
3954 let h = n mod 1000 in
3957 then string_of_int
h ^
s
3959 let s = Printf.sprintf
"_%03d%s" h s in
3966 let defghyllscroll = (40, 8, 32);;
3967 let ghyllscroll_of_string s =
3968 let (n, a, b) as nab
=
3971 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3973 if n <= a || n <= b || a >= b
3974 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3978 let ghyllscroll_to_string ((n, a, b) as nab
) =
3979 if nab
= defghyllscroll
3981 else Printf.sprintf
"%d,%d,%d" n a b;
3984 let describe_location () =
3986 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3988 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3989 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3993 else (100. *. (float state.y /. float maxy))
3997 Printf.sprintf
"page %d of %d [%.2f%%]"
3998 (fn+1) state.pagecount
percent
4001 "pages %d-%d of %d [%.2f%%]"
4002 (fn+1) (ln
+1) state.pagecount
percent
4005 let setpresentationmode v
=
4006 let (n, _, _) = getanchor () in
4007 let _, h = getpageyh n in
4008 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
4009 state.anchor <- (n, 0.0, float ips);
4010 conf.presentation
<- v
;
4011 if conf.presentation
4013 if not
conf.scrollbarinpm
4014 then state.scrollw
<- 0;
4016 else state.scrollw
<- conf.scrollbw
;
4021 let btos b = if b then "\xe2\x88\x9a" else "" in
4022 let showextended = ref false in
4023 let leave mode
= function
4024 | Confirm
-> state.mode
<- mode
4025 | Cancel
-> state.mode
<- mode
in
4028 val mutable m_first_time
= true
4029 val mutable m_l
= []
4030 val mutable m_a
= [||]
4031 val mutable m_prev_uioh
= nouioh
4032 val mutable m_prev_mode
= View
4034 inherit lvsourcebase
4036 method reset prev_mode prev_uioh
=
4037 m_a
<- Array.of_list
(List.rev m_l
);
4039 m_prev_mode
<- prev_mode
;
4040 m_prev_uioh
<- prev_uioh
;
4044 if n >= Array.length m_a
4048 | _, _, _, Action
_ -> m_active
<- n
4052 m_first_time
<- false;
4055 method int name get
set =
4057 (name
, `
int get
, 1, Action
(
4060 try set (int_of_string
s)
4062 state.text <- Printf.sprintf
"bad integer `%s': %s"
4063 s (Printexc.to_string exn
)
4066 let te = name ^
": ", "", None
, intentry, ondone, true in
4067 state.mode
<- Textentry
(te, leave m_prev_mode
);
4071 method int_with_suffix name get
set =
4073 (name
, `intws get
, 1, Action
(
4076 try set (int_of_string_with_suffix s)
4078 state.text <- Printf.sprintf
"bad integer `%s': %s"
4079 s (Printexc.to_string exn
)
4083 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4085 state.mode
<- Textentry
(te, leave m_prev_mode
);
4089 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4091 (name
, `
bool (btos, get
), offset
, Action
(
4098 method color name get
set =
4100 (name
, `color get
, 1, Action
(
4102 let invalid = (nan
, nan
, nan
) in
4105 try color_of_string s
4107 state.text <- Printf.sprintf
"bad color `%s': %s"
4108 s (Printexc.to_string exn
);
4114 let te = name ^
": ", "", None
, textentry, ondone, true in
4115 state.text <- color_to_string (get
());
4116 state.mode
<- Textentry
(te, leave m_prev_mode
);
4120 method string name get
set =
4122 (name
, `
string get
, 1, Action
(
4124 let ondone s = set s in
4125 let te = name ^
": ", "", None
, textentry, ondone, true in
4126 state.mode
<- Textentry
(te, leave m_prev_mode
);
4130 method colorspace name get
set =
4132 (name
, `
string get
, 1, Action
(
4135 let vals = [| "rgb"; "bgr"; "gray" |] in
4137 inherit lvsourcebase
4140 m_active
<- int_of_colorspace conf.colorspace
;
4143 method getitemcount
= Array.length
vals
4144 method getitem
n = (vals.(n), 0)
4145 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4146 ignore
(uioh
, first, pan
, qsearch);
4147 if not cancel
then set active;
4149 method hasaction
_ = true
4153 let modehash = findkeyhash conf "info" in
4154 coe (new listview ~
source ~trusted
:true ~
modehash)
4157 method caption
s offset
=
4158 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4160 method caption2
s f offset
=
4161 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4163 method getitemcount
= Array.length m_a
4166 let tostr = function
4167 | `
int f -> string_of_int
(f ())
4168 | `intws
f -> string_with_suffix_of_int (f ())
4170 | `color
f -> color_to_string (f ())
4171 | `
bool (btos, f) -> btos (f ())
4174 let name, t
, offset
, _ = m_a
.(n) in
4175 ((let s = tostr t
in
4176 if String.length
s > 0
4177 then Printf.sprintf
"%s\t%s" name s
4181 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4185 m_qsearch
<- qsearch;
4187 match m_a
.(active) with
4188 | _, _, _, Action
f -> f uioh
4200 method hasaction
n =
4202 | _, _, _, Action
_ -> true
4206 let rec fillsrc prevmode prevuioh
=
4207 let sep () = src#caption
"" 0 in
4208 let colorp name get
set =
4210 (fun () -> color_to_string (get
()))
4213 let c = color_of_string v in
4216 state.text <- Printf.sprintf
"bad color `%s': %s"
4217 v (Printexc.to_string exn
);
4220 let oldmode = state.mode
in
4221 let birdseye = isbirdseye state.mode
in
4223 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4225 src#
bool "presentation mode"
4226 (fun () -> conf.presentation
)
4227 (fun v -> setpresentationmode v);
4229 src#
bool "ignore case in searches"
4230 (fun () -> conf.icase
)
4231 (fun v -> conf.icase
<- v);
4234 (fun () -> conf.preload)
4235 (fun v -> conf.preload <- v);
4237 src#
bool "highlight links"
4238 (fun () -> conf.hlinks
)
4239 (fun v -> conf.hlinks
<- v);
4241 src#
bool "under info"
4242 (fun () -> conf.underinfo
)
4243 (fun v -> conf.underinfo
<- v);
4245 src#
bool "persistent bookmarks"
4246 (fun () -> conf.savebmarks
)
4247 (fun v -> conf.savebmarks
<- v);
4249 src#
bool "proportional display"
4250 (fun () -> conf.proportional
)
4251 (fun v -> reqlayout conf.angle
v);
4253 src#
bool "trim margins"
4254 (fun () -> conf.trimmargins
)
4255 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4257 src#
bool "persistent location"
4258 (fun () -> conf.jumpback
)
4259 (fun v -> conf.jumpback
<- v);
4262 src#
int "inter-page space"
4263 (fun () -> conf.interpagespace
)
4265 conf.interpagespace
<- n;
4266 docolumns conf.columns
;
4268 match state.layout with
4273 state.maxy <- calcheight ();
4274 let y = getpagey pageno in
4279 (fun () -> conf.pagebias
)
4280 (fun v -> conf.pagebias
<- v);
4282 src#
int "scroll step"
4283 (fun () -> conf.scrollstep
)
4284 (fun n -> conf.scrollstep
<- n);
4286 src#
int "horizontal scroll step"
4287 (fun () -> conf.hscrollstep
)
4288 (fun v -> conf.hscrollstep
<- v);
4290 src#
int "auto scroll step"
4292 match state.autoscroll
with
4294 | _ -> conf.autoscrollstep
)
4296 if state.autoscroll
<> None
4297 then state.autoscroll
<- Some
n;
4298 conf.autoscrollstep
<- n);
4301 (fun () -> truncate
(conf.zoom *. 100.))
4302 (fun v -> setzoom ((float v) /. 100.));
4305 (fun () -> conf.angle
)
4306 (fun v -> reqlayout v conf.proportional
);
4308 src#
int "scroll bar width"
4309 (fun () -> state.scrollw
)
4313 reshape conf.winw
conf.winh
;
4316 src#
int "scroll handle height"
4317 (fun () -> conf.scrollh
)
4318 (fun v -> conf.scrollh
<- v;);
4320 src#
int "thumbnail width"
4321 (fun () -> conf.thumbw
)
4323 conf.thumbw
<- min
4096 v;
4326 leavebirdseye beye
false;
4331 let mode = state.mode in
4332 src#
string "columns"
4334 match conf.columns
with
4336 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4337 | Csplit
(count
, _) -> "-" ^ string_of_int count
4340 let n, a, b = multicolumns_of_string v in
4341 setcolumns mode n a b);
4344 src#caption
"Presentation mode" 0;
4345 src#
bool "scrollbar visible"
4346 (fun () -> conf.scrollbarinpm
)
4348 if v != conf.scrollbarinpm
4350 conf.scrollbarinpm
<- v;
4351 if conf.presentation
4353 state.scrollw
<- if v then conf.scrollbw
else 0;
4354 reshape conf.winw
conf.winh
;
4360 src#caption
"Pixmap cache" 0;
4361 src#int_with_suffix
"size (advisory)"
4362 (fun () -> conf.memlimit
)
4363 (fun v -> conf.memlimit
<- v);
4366 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4367 (string_with_suffix_of_int state.memused
)
4368 (Hashtbl.length
state.tilemap
)) 1;
4371 src#caption
"Layout" 0;
4372 src#caption2
"Dimension"
4374 Printf.sprintf
"%dx%d (virtual %dx%d)"
4380 src#caption2
"Position" (fun () ->
4381 Printf.sprintf
"%dx%d" state.x state.y
4384 src#caption2
"Visible" (fun () -> describe_location ()) 1
4388 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4389 "Save these parameters as global defaults at exit"
4390 (fun () -> conf.bedefault
)
4391 (fun v -> conf.bedefault
<- v)
4395 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4396 src#
bool ~offset
:0 ~
btos "Extended parameters"
4397 (fun () -> !showextended)
4398 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4402 (fun () -> conf.checkers
)
4403 (fun v -> conf.checkers
<- v; setcheckers v);
4404 src#
bool "update cursor"
4405 (fun () -> conf.updatecurs
)
4406 (fun v -> conf.updatecurs
<- v);
4408 (fun () -> conf.verbose
)
4409 (fun v -> conf.verbose
<- v);
4410 src#
bool "invert colors"
4411 (fun () -> conf.invert
)
4412 (fun v -> conf.invert
<- v);
4414 (fun () -> conf.maxhfit
)
4415 (fun v -> conf.maxhfit
<- v);
4416 src#
bool "redirect stderr"
4417 (fun () -> conf.redirectstderr)
4418 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4419 src#
string "uri launcher"
4420 (fun () -> conf.urilauncher
)
4421 (fun v -> conf.urilauncher
<- v);
4422 src#
string "path launcher"
4423 (fun () -> conf.pathlauncher
)
4424 (fun v -> conf.pathlauncher
<- v);
4425 src#
string "tile size"
4426 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4429 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4430 conf.tilew
<- max
64 w;
4431 conf.tileh
<- max
64 h;
4434 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4435 v (Printexc.to_string exn
));
4436 src#
int "texture count"
4437 (fun () -> conf.texcount
)
4440 then conf.texcount
<- v
4441 else showtext '
!'
" Failed to set texture count please retry later"
4443 src#
int "slice height"
4444 (fun () -> conf.sliceheight
)
4446 conf.sliceheight
<- v;
4447 wcmd "sliceh %d" conf.sliceheight
;
4449 src#
int "anti-aliasing level"
4450 (fun () -> conf.aalevel
)
4452 conf.aalevel
<- bound v 0 8;
4453 state.anchor <- getanchor ();
4454 opendoc state.path
state.password
;
4456 src#
string "page scroll scaling factor"
4457 (fun () -> string_of_float
conf.pgscale)
4460 let s = float_of_string
v in
4463 state.text <- Printf.sprintf
4464 "bad page scroll scaling factor `%s': %s"
4465 v (Printexc.to_string exn
)
4468 src#
int "ui font size"
4469 (fun () -> fstate.fontsize
)
4470 (fun v -> setfontsize (bound v 5 100));
4471 src#
int "hint font size"
4472 (fun () -> conf.hfsize
)
4473 (fun v -> conf.hfsize
<- bound v 5 100);
4474 colorp "background color"
4475 (fun () -> conf.bgcolor
)
4476 (fun v -> conf.bgcolor
<- v);
4477 src#
bool "crop hack"
4478 (fun () -> conf.crophack
)
4479 (fun v -> conf.crophack
<- v);
4480 src#
string "trim fuzz"
4481 (fun () -> irect_to_string conf.trimfuzz
)
4484 conf.trimfuzz
<- irect_of_string v;
4486 then settrim true conf.trimfuzz
;
4488 state.text <- Printf.sprintf
"bad irect `%s': %s"
4489 v (Printexc.to_string exn
)
4491 src#
string "throttle"
4493 match conf.maxwait
with
4494 | None
-> "show place holder if page is not ready"
4497 then "wait for page to fully render"
4499 "wait " ^ string_of_float
time
4500 ^
" seconds before showing placeholder"
4504 let f = float_of_string
v in
4506 then conf.maxwait
<- None
4507 else conf.maxwait
<- Some
f
4509 state.text <- Printf.sprintf
"bad time `%s': %s"
4510 v (Printexc.to_string exn
)
4512 src#
string "ghyll scroll"
4514 match conf.ghyllscroll
with
4516 | Some nab
-> ghyllscroll_to_string nab
4521 if String.length
v = 0
4523 else Some
(ghyllscroll_of_string v)
4525 conf.ghyllscroll
<- gs
4527 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4528 v (Printexc.to_string exn
)
4530 src#
string "selection command"
4531 (fun () -> conf.selcmd
)
4532 (fun v -> conf.selcmd
<- v);
4533 src#colorspace
"color space"
4534 (fun () -> colorspace_to_string conf.colorspace
)
4536 conf.colorspace
<- colorspace_of_int v;
4543 (fun () -> conf.usepbo
)
4544 (fun v -> conf.usepbo
<- v);
4545 src#
bool "mouse wheel scrolls pages"
4546 (fun () -> conf.wheelbypage
)
4547 (fun v -> conf.wheelbypage
<- v);
4551 src#caption
"Document" 0;
4552 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4553 src#caption2
"Pages"
4554 (fun () -> string_of_int
state.pagecount
) 1;
4555 src#caption2
"Dimensions"
4556 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4560 src#caption
"Trimmed margins" 0;
4561 src#caption2
"Dimensions"
4562 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4566 src#caption
"OpenGL" 0;
4567 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4568 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4569 src#reset prevmode prevuioh
;
4573 let prevmode = state.mode
4574 and prevuioh
= state.uioh in
4575 fillsrc prevmode prevuioh
;
4576 let source = (src :> lvsource
) in
4577 let modehash = findkeyhash conf "info" in
4578 state.uioh <- coe (object (self)
4579 inherit listview ~
source ~trusted
:true ~
modehash as super
4580 val mutable m_prevmemused
= 0
4581 method infochanged
= function
4583 if m_prevmemused
!= state.memused
4585 m_prevmemused
<- state.memused
;
4586 G.postRedisplay "memusedchanged";
4588 | Pdim
-> G.postRedisplay "pdimchanged"
4589 | Docinfo
-> fillsrc prevmode prevuioh
4591 method key key mask
=
4592 if not
(Wsi.withctrl mask
)
4595 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4596 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4597 | _ -> super#
key key mask
4598 else super#
key key mask
4600 G.postRedisplay "info";
4606 inherit lvsourcebase
4607 method getitemcount
= Array.length
state.help
4609 let s, l, _ = state.help
.(n) in
4612 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4616 m_qsearch
<- qsearch;
4617 match state.help
.(active) with
4618 | _, _, Action
f -> Some
(f uioh)
4628 method hasaction
n =
4629 match state.help
.(n) with
4630 | _, _, Action
_ -> true
4637 let modehash = findkeyhash conf "help" in
4638 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4639 G.postRedisplay "help";
4644 let re = Str.regexp
"[\r\n]" in
4646 inherit lvsourcebase
4647 val mutable m_items
= [||]
4649 method getitemcount
= 1 + Array.length m_items
4654 else m_items
.(n-1), 0
4656 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4661 then Buffer.clear
state.errmsgs
;
4662 m_qsearch
<- qsearch;
4669 method hasaction
n =
4673 state.newerrmsgs
<- false;
4674 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4675 m_items
<- Array.of_list
l
4683 let source = (msgsource :> lvsource
) in
4684 let modehash = findkeyhash conf "listview" in
4685 state.uioh <- coe (object
4686 inherit listview ~
source ~trusted
:false ~
modehash as super
4689 then msgsource#reset
;
4692 G.postRedisplay "msgs";
4695 let quickbookmark ?title
() =
4696 match state.layout with
4702 let sec = Unix.gettimeofday
() in
4703 let tm = Unix.localtime
sec in
4704 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4708 (tm.Unix.tm_year
+ 1900)
4711 | Some
title -> title
4713 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4717 state.fullscreen
<- None
;
4721 let setautoscrollspeed step goingdown
=
4722 let incr = max
1 ((abs step
) / 2) in
4723 let incr = if goingdown
then incr else -incr in
4724 let astep = step
+ incr in
4725 state.autoscroll
<- Some
astep;
4728 let gotounder = function
4729 | Ulinkgoto
(pageno, top) ->
4733 gotopage1 pageno top;
4739 | Uremote
(filename
, pageno) ->
4741 if Sys.file_exists filename
4744 let dir = Filename.dirname
state.path in
4745 let path = Filename.concat
dir filename
in
4746 if Sys.file_exists
path
4750 if String.length
path > 0
4752 let anchor = getanchor () in
4753 let ranchor = state.path, state.password
, anchor in
4754 state.anchor <- (pageno, 0.0, 0.0);
4755 state.ranchors
<- ranchor :: state.ranchors
;
4758 else showtext '
!'
("Could not find " ^ filename
)
4760 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4764 match conf.columns
with
4766 | _ -> conf.zoom > 1.0
4769 let existsinrow pageno (columns
, coverA
, coverB
) p =
4770 let last = ((pageno - coverA
) mod columns
) + columns
in
4771 let rec any = function
4774 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4778 then (if l.pageno = last then false else any rest
)
4786 match state.layout with
4789 match conf.columns
with
4791 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4793 let y = clamp (pgscale conf.winh
) in
4796 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4797 gotoghyll (getpagey pageno)
4798 | Cmulti
((c, _, _) as cl
, _) ->
4799 if conf.presentation
4800 && (existsinrow l.pageno cl
4801 (fun l -> l.pageh
> l.pagey + l.pagevh))
4803 let y = clamp (pgscale conf.winh
) in
4806 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4807 gotoghyll (getpagey pageno)
4809 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4811 let pagey, pageh
= getpageyh l.pageno in
4812 let pagey = pagey + pageh
* l.pagecol
in
4813 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4814 gotoghyll (pagey + pageh
+ ips)
4818 match state.layout with
4821 match conf.columns
with
4823 if conf.presentation
&& l.pagey != 0
4825 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4827 let pageno = max
0 (l.pageno-1) in
4828 gotoghyll (getpagey pageno)
4829 | Cmulti
((c, _, coverB
) as cl
, _) ->
4830 if conf.presentation
&&
4831 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4833 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4836 if l.pageno = state.pagecount
- coverB
4840 let pageno = max
0 (l.pageno-decr) in
4841 gotoghyll (getpagey pageno)
4849 let pageno = max
0 (l.pageno-1) in
4850 let pagey, pageh
= getpageyh pageno in
4853 let pagey, pageh
= getpageyh l.pageno in
4854 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4859 let viewkeyboard key mask
=
4861 let mode = state.mode in
4862 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4865 G.postRedisplay "view:enttext"
4867 let ctrl = Wsi.withctrl mask
in
4869 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4875 | 0xff63 -> (* insert *)
4876 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4878 state.mode <- LinkNav
(Ltgendir
0);
4881 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4883 | 0xff1b | 113 -> (* escape / q *)
4884 begin match state.mstate
with
4886 state.mstate
<- Mnone
;
4887 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4888 G.postRedisplay "kill zoom rect";
4890 begin match state.mode with
4893 G.postRedisplay "esc leave linknav"
4895 match state.ranchors
with
4897 | (path, password
, anchor) :: rest
->
4898 state.ranchors
<- rest
;
4899 state.anchor <- anchor;
4900 opendoc path password
4904 | 0xff08 -> (* backspace *)
4905 gotoghyll (getnav ~
-1)
4913 G.postRedisplay "dehighlight";
4915 | 47 | 63 -> (* / ? *)
4916 let ondone isforw
s =
4917 cbput state.hists
.pat
s;
4918 state.searchpattern
<- s;
4921 let s = String.create
1 in
4922 s.[0] <- Char.chr
key;
4923 enttext (s, "", Some
(onhist state.hists
.pat
),
4924 textentry, ondone (key = 47), true)
4926 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4927 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4928 setzoom (conf.zoom +. incr)
4930 | 43 | 0xffab -> (* + *)
4933 try int_of_string
s with exc
->
4934 state.text <- Printf.sprintf
"bad integer `%s': %s"
4935 s (Printexc.to_string exc
);
4941 state.text <- "page bias is now " ^ string_of_int
n;
4944 enttext ("page bias: ", "", None
, intentry, ondone, true)
4946 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4947 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4948 setzoom (max
0.01 (conf.zoom -. decr))
4950 | 45 | 0xffad -> (* - *)
4951 let ondone msg
= state.text <- msg
in
4953 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4954 optentry state.mode, ondone, true
4957 | 48 when ctrl -> (* ctrl-0 *)
4960 | 49 when ctrl -> (* ctrl-1 *)
4962 match conf.columns
with
4963 | Csingle
_ | Cmulti
_ -> 1
4964 | Csplit
(n, _) -> n
4966 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4970 | 0xffc6 -> (* f9 *)
4973 | 57 when ctrl -> (* ctrl-9 *)
4976 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4977 when not
ctrl -> (* 0..9 *)
4980 try int_of_string
s with exc
->
4981 state.text <- Printf.sprintf
"bad integer `%s': %s"
4982 s (Printexc.to_string exc
);
4988 cbput state.hists
.pag
(string_of_int
n);
4989 gotopage1 (n + conf.pagebias
- 1) 0;
4992 let pageentry text key =
4993 match Char.unsafe_chr
key with
4994 | 'g'
-> TEdone
text
4995 | _ -> intentry text key
4997 let text = "x" in text.[0] <- Char.chr
key;
4998 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5001 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5002 reshape conf.winw
conf.winh
;
5005 conf.hlinks
<- not
conf.hlinks
;
5006 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5007 G.postRedisplay "toggle highlightlinks";
5010 state.glinks
<- true;
5011 let mode = state.mode in
5012 state.mode <- Textentry
(
5013 (":", "", None
, linknentry, linkndone gotounder, false),
5015 state.glinks
<- false;
5019 G.postRedisplay "view:linkent(F)"
5022 state.glinks
<- true;
5023 let mode = state.mode in
5024 state.mode <- Textentry
(
5025 (":", "", None
, linknentry, linkndone (fun under ->
5026 match Ne.pipe () with
5028 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
5029 (Printexc.to_string exn
));
5032 try popen conf.selcmd
[r, 0; w, -1]; true
5035 (Printf.sprintf
"failed to execute %s: %s"
5036 conf.selcmd
(Printexc.to_string exn
));
5040 Ne.clo fd
(fun msg
->
5041 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5044 let s = undertext under in
5048 let l = String.length
s in
5049 let n = tempfailureretry (Unix.write
w s 0) l in
5054 "failed to write %d characters to sel pipe, wrote %d"
5059 (Printf.sprintf
"failed to write to sel pipe: %s"
5060 (Printexc.to_string exn
)
5069 state.glinks
<- false;
5073 G.postRedisplay "view:linkent"
5076 begin match state.autoscroll
with
5078 conf.autoscrollstep
<- step
;
5079 state.autoscroll
<- None
5081 if conf.autoscrollstep
= 0
5082 then state.autoscroll
<- Some
1
5083 else state.autoscroll
<- Some
conf.autoscrollstep
5086 | 112 when ctrl -> (* ctrl-p *)
5090 setpresentationmode (not
conf.presentation
);
5091 showtext ' '
("presentation mode " ^
5092 if conf.presentation
then "on" else "off");
5095 begin match state.fullscreen
with
5097 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
5100 state.fullscreen
<- None
;
5104 | 112 | 78 -> (* p|N *)
5105 search state.searchpattern
false
5107 | 110 | 0xffc0 -> (* n|F3 *)
5108 search state.searchpattern
true
5111 begin match state.layout with
5114 gotoy_and_clear_text (getpagey l.pageno)
5120 | 0xff9f | 0xffff -> (* delete *)
5124 showtext ' '
(describe_location ());
5127 begin match state.layout with
5130 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5135 enterbookmarkmode ()
5137 | 104 | 0xffbe -> (* h|F1 *)
5143 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5148 match state.layout with
5150 if String.length
s > 0
5152 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5155 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5159 showtext ' '
"Quick bookmark added";
5162 begin match state.layout with
5164 let rect = getpdimrect
l.pagedimno
in
5168 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5169 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5171 (truncate
(rect.(1) -. rect.(0)),
5172 truncate
(rect.(3) -. rect.(0)))
5174 let w = truncate
((float w)*.conf.zoom)
5175 and h = truncate
((float h)*.conf.zoom) in
5178 state.anchor <- getanchor ();
5179 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5181 G.postRedisplay "z";
5186 | 50 when ctrl -> (* ctrl-2 *)
5187 let maxw = getmaxw
() in
5189 then setzoom (maxw /. float conf.winw
)
5191 | 60 | 62 -> (* < > *)
5192 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5194 | 91 | 93 -> (* [ ] *)
5196 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5198 G.postRedisplay "brightness";
5200 | 99 when state.mode = View
-> (* c *)
5202 match state.prevcolumns
with
5203 | None
-> (1, 0, 0), 1.0
5204 | Some
(columns
, z
) ->
5207 | Csplit
(c, _) -> -c, 0, 0
5208 | Cmulti
((c, a, b), _) -> c, a, b
5209 | Csingle
_ -> 1, 0, 0
5213 setcolumns View
c a b;
5216 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5217 setzoom state.prevzoom
5219 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5220 begin match state.autoscroll
with
5222 begin match state.mode with
5223 | Birdseye beye
-> upbirdseye 1 beye
5226 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5227 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5230 setautoscrollspeed n false
5233 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5234 begin match state.autoscroll
with
5236 begin match state.mode with
5237 | Birdseye beye
-> downbirdseye 1 beye
5240 then gotoy_and_clear_text (clamp (conf.winh
/2))
5241 else gotoy_and_clear_text (clamp conf.scrollstep
)
5244 setautoscrollspeed n true
5247 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5248 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5254 else conf.hscrollstep
5256 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5257 state.x <- state.x + dx;
5258 gotoy_and_clear_text state.y
5261 G.postRedisplay "lef/right"
5264 | 0xff55 | 0xff9a -> (* (kp) prior *)
5268 match state.layout with
5270 | l :: _ -> state.y - l.pagey
5272 clamp (pgscale (-conf.winh
))
5276 | 0xff56 | 0xff9b -> (* (kp) next *)
5280 match List.rev
state.layout with
5282 | l :: _ -> getpagey l.pageno
5284 clamp (pgscale conf.winh
)
5288 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5290 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5291 gotoghyll (clamp state.maxy)
5294 when Wsi.withalt mask
-> (* alt-(kp) right *)
5295 gotoghyll (getnav 1)
5297 when Wsi.withalt mask
-> (* alt-(kp) left *)
5298 gotoghyll (getnav ~
-1)
5303 | 118 when conf.debug
-> (* v *)
5306 match getopaque l.pageno with
5309 let x0, y0, x1, y1 = pagebbox opaque
in
5310 let a,b = float x0, float y0 in
5311 let c,d = float x1, float y0 in
5312 let e,f = float x1, float y1 in
5313 let h,j
= float x0, float y1 in
5314 let rect = (a,b,c,d,e,f,h,j
) in
5316 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5318 G.postRedisplay "v";
5321 vlog "huh? %s" (Wsi.keyname
key)
5324 let linknavkeyboard key mask
linknav =
5325 let getpage pageno =
5326 let rec loop = function
5328 | l :: _ when l.pageno = pageno -> Some
l
5329 | _ :: rest
-> loop rest
5330 in loop state.layout
5332 let doexact (pageno, n) =
5333 match getopaque pageno, getpage pageno with
5334 | Some opaque
, Some
l ->
5335 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5337 let under = getlink opaque
n in
5338 G.postRedisplay "link gotounder";
5344 | 0xff50 -> (* home *)
5345 Some
(findlink opaque LDfirst
), -1
5347 | 0xff57 -> (* end *)
5348 Some
(findlink opaque LDlast
), 1
5350 | 0xff51 -> (* left *)
5351 Some
(findlink opaque
(LDleft
n)), -1
5353 | 0xff53 -> (* right *)
5354 Some
(findlink opaque
(LDright
n)), 1
5356 | 0xff52 -> (* up *)
5357 Some
(findlink opaque
(LDup
n)), -1
5359 | 0xff54 -> (* down *)
5360 Some
(findlink opaque
(LDdown
n)), 1
5365 begin match findpwl
l.pageno dir with
5369 state.mode <- LinkNav
(Ltgendir
dir);
5370 let y, h = getpageyh pageno in
5373 then y + h - conf.winh
5378 begin match getopaque pageno, getpage pageno with
5379 | Some opaque
, Some
_ ->
5381 let ld = if dir > 0 then LDfirst
else LDlast
in
5384 begin match link with
5386 showlinktype (getlink opaque
m);
5387 state.mode <- LinkNav
(Ltexact
(pageno, m));
5388 G.postRedisplay "linknav jpage";
5395 begin match opt with
5396 | Some Lnotfound
-> pwl l dir;
5397 | Some
(Lfound
m) ->
5401 let _, y0, _, y1 = getlinkrect opaque
m in
5403 then gotopage1 l.pageno y0
5405 let d = fstate.fontsize
+ 1 in
5406 if y1 - l.pagey > l.pagevh - d
5407 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5408 else G.postRedisplay "linknav";
5410 showlinktype (getlink opaque
m);
5411 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5414 | None
-> viewkeyboard key mask
5416 | _ -> viewkeyboard key mask
5421 G.postRedisplay "leave linknav"
5425 | Ltgendir
_ -> viewkeyboard key mask
5426 | Ltexact exact
-> doexact exact
5429 let keyboard key mask
=
5430 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5431 then wcmd "interrupt"
5432 else state.uioh <- state.uioh#
key key mask
5435 let birdseyekeyboard key mask
5436 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5438 match conf.columns
with
5440 | Cmulti
((c, _, _), _) -> c
5441 | Csplit
_ -> failwith
"bird's eye split mode"
5443 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5445 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5446 let y, h = getpageyh pageno in
5447 let top = (conf.winh
- h) / 2 in
5448 gotoy (max
0 (y - top))
5449 | 0xff0d (* enter *)
5450 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5451 | 0xff1b -> leavebirdseye beye
true (* escape *)
5452 | 0xff52 -> upbirdseye incr beye
(* up *)
5453 | 0xff54 -> downbirdseye incr beye
(* down *)
5454 | 0xff51 -> upbirdseye 1 beye
(* left *)
5455 | 0xff53 -> downbirdseye 1 beye
(* right *)
5457 | 0xff55 -> (* prior *)
5458 begin match state.layout with
5462 state.mode <- Birdseye
(
5463 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5465 gotopage1 l.pageno 0;
5468 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5470 | [] -> gotoy (clamp (-conf.winh
))
5472 state.mode <- Birdseye
(
5473 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5475 gotopage1 l.pageno 0
5478 | [] -> gotoy (clamp (-conf.winh
))
5481 | 0xff56 -> (* next *)
5482 begin match List.rev
state.layout with
5484 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5485 begin match layout with
5487 let incr = l.pageh
- l.pagevh in
5492 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5494 G.postRedisplay "birdseye pagedown";
5496 else gotoy (clamp (incr + conf.interpagespace
*2));
5500 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5501 gotopage1 l.pageno 0;
5504 | [] -> gotoy (clamp conf.winh
)
5507 | 0xff50 -> (* home *)
5508 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5511 | 0xff57 -> (* end *)
5512 let pageno = state.pagecount
- 1 in
5513 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5514 if not
(pagevisible state.layout pageno)
5517 match List.rev
state.pdims
with
5519 | (_, _, h, _) :: _ -> h
5521 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5522 else G.postRedisplay "birdseye end";
5523 | _ -> viewkeyboard key mask
5526 let drawpage l linkindexbase
=
5528 match state.mode with
5529 | Textentry
_ -> scalecolor 0.4
5531 | View
-> scalecolor 1.0
5532 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5533 if l.pageno = hooverpageno
5536 if l.pageno = pageno
5542 begin match getopaque l.pageno with
5544 if tileready l l.pagex
l.pagey
5546 let x = l.pagedispx - l.pagex
5547 and y = l.pagedispy - l.pagey in
5549 match conf.columns
with
5550 | Csingle
_ | Cmulti
_ ->
5551 (if conf.hlinks
then 1 else 0)
5553 && not
(isbirdseye state.mode) then 2 else 0)
5557 match state.mode with
5558 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5561 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5568 let scrollindicator () =
5569 let sbw, ph
, sh = state.uioh#
scrollph in
5570 let sbh, pw, sw = state.uioh#scrollpw
in
5572 GlDraw.color (0.64, 0.64, 0.64);
5574 (float (conf.winw
- sbw), 0.)
5575 (float conf.winw
, float conf.winh
)
5578 (0., float (conf.winh
- sbh))
5579 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5581 GlDraw.color (0.0, 0.0, 0.0);
5584 (float (conf.winw
- sbw), ph
)
5585 (float conf.winw
, ph
+. sh)
5588 (pw, float (conf.winh
- sbh))
5589 (pw +. sw, float conf.winh
)
5594 match state.mstate
with
5595 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5598 | Msel
((x0, y0), (x1, y1)) ->
5599 let rec loop = function
5601 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5602 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5603 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5604 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5606 match getopaque l.pageno with
5608 let x0, y0 = pagetranslatepoint l x0 y0 in
5609 let x1, y1 = pagetranslatepoint l x1 y1 in
5610 seltext opaque
(x0, y0, x1, y1);
5618 let showrects rects
=
5620 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5621 GlDraw.polygon_mode `both `fill
;
5622 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5624 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5626 if l.pageno = pageno
5628 let dx = float (l.pagedispx - l.pagex
) in
5629 let dy = float (l.pagedispy - l.pagey) in
5630 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5631 GlDraw.begins `quads
;
5633 GlDraw.vertex2
(x0+.dx, y0+.dy);
5634 GlDraw.vertex2
(x1+.dx, y1+.dy);
5635 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5636 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5647 GlClear.color (scalecolor2 conf.bgcolor
);
5648 GlClear.clear
[`
color];
5649 let rec loop linkindexbase
= function
5651 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5652 loop linkindexbase rest
5655 loop 0 state.layout;
5657 match state.mode with
5658 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5659 begin match getopaque pageno with
5661 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5668 | None
-> state.rects
5675 begin match state.mstate
with
5676 | Mzoomrect
((x0, y0), (x1, y1)) ->
5678 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5679 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5680 GlDraw.rect (float x0, float y0)
5681 (float x1, float y1);
5690 let zoomrect x y x1 y1 =
5693 and y0 = min
y y1 in
5694 gotoy (state.y + y0);
5695 state.anchor <- getanchor ();
5696 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5698 if state.w < conf.winw
- state.scrollw
5699 then (conf.winw
- state.scrollw
- state.w) / 2
5702 state.x <- (state.x + margin) - x0;
5704 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5705 state.mstate
<- Mnone
;
5709 let winw = conf.winw - state.scrollw
- 1 in
5710 let s = float x /. float winw in
5711 let destx = truncate
(float (state.w + winw) *. s) in
5712 state.x <- winw - destx;
5713 gotoy_and_clear_text state.y;
5714 state.mstate
<- Mscrollx
;
5718 let s = float y /. float conf.winh
in
5719 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5720 gotoy_and_clear_text desty;
5721 state.mstate
<- Mscrolly
;
5724 let viewmouse button down
x y mask
=
5726 | n when (n == 4 || n == 5) && not down
->
5727 if Wsi.withctrl mask
5729 match state.mstate
with
5730 | Mzoom
(oldn
, i
) ->
5738 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5740 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5742 let zoom = conf.zoom -. incr in
5744 state.mstate
<- Mzoom
(n, 0);
5746 state.mstate
<- Mzoom
(n, i
+1);
5748 else state.mstate
<- Mzoom
(n, 0)
5750 | _ -> state.mstate
<- Mzoom
(n, 0)
5753 match state.autoscroll
with
5754 | Some step
-> setautoscrollspeed step
(n=4)
5765 then -conf.scrollstep
5766 else conf.scrollstep
5768 let incr = incr * 2 in
5769 let y = clamp incr in
5770 gotoy_and_clear_text y
5773 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5774 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5775 gotoy_and_clear_text state.y
5777 | 1 when Wsi.withctrl mask
->
5780 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5781 state.mstate
<- Mpan
(x, y)
5784 state.mstate
<- Mnone
5789 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5791 state.mstate
<- Mzoomrect
(p, p)
5794 match state.mstate
with
5795 | Mzoomrect
((x0, y0), _) ->
5796 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5797 then zoomrect x0 y0 x y
5799 state.mstate
<- Mnone
;
5800 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5801 G.postRedisplay "kill accidental zoom rect";
5804 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5805 state.mstate
<- Mnone
5808 | 1 when x > conf.winw - state.scrollw
->
5811 let _, position, sh = state.uioh#
scrollph in
5812 if y > truncate
position && y < truncate
(position +. sh)
5813 then state.mstate
<- Mscrolly
5816 state.mstate
<- Mnone
5818 | 1 when y > conf.winh
- state.hscrollh ->
5821 let _, position, sw = state.uioh#scrollpw
in
5822 if x > truncate
position && x < truncate
(position +. sw)
5823 then state.mstate
<- Mscrollx
5826 state.mstate
<- Mnone
5829 let dest = if down
then getunder x y else Unone
in
5830 begin match dest with
5834 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5837 | Unone
when down
->
5838 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5839 state.mstate
<- Mpan
(x, y);
5841 | Unone
| Utext
_ ->
5844 if conf.angle
mod 360 = 0
5846 state.mstate
<- Msel
((x, y), (x, y));
5847 G.postRedisplay "mouse select";
5851 match state.mstate
with
5854 | Mzoom
_ | Mscrollx
| Mscrolly
->
5855 state.mstate
<- Mnone
5857 | Mzoomrect
((x0, y0), _) ->
5861 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5862 state.mstate
<- Mnone
5864 | Msel
((x0, y0), (x1, y1)) ->
5865 let rec loop = function
5869 let a0 = l.pagedispy in
5870 let a1 = a0 + l.pagevh in
5871 let b0 = l.pagedispx in
5872 let b1 = b0 + l.pagevw in
5873 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5874 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5878 match getopaque l.pageno with
5881 match Ne.pipe () with
5885 "can not create sel pipe: %s"
5886 (Printexc.to_string exn
));
5888 let doclose what fd
=
5889 Ne.clo fd
(fun msg
->
5890 dolog "%s close failed: %s" what msg
)
5893 popen conf.selcmd
[r, 0; w, -1];
5896 G.postRedisplay "copysel";
5898 dolog "can not execute %S: %s"
5899 conf.selcmd
(Printexc.to_string exn
);
5907 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5908 state.mstate
<- Mnone
;
5915 let birdseyemouse button down
x y mask
5916 (conf, leftx
, _, hooverpageno
, anchor) =
5919 let rec loop = function
5922 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5923 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5925 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5931 | _ -> viewmouse button down
x y mask
5934 let mouse button down
x y mask
=
5935 state.uioh <- state.uioh#button button down
x y mask
;
5939 state.uioh <- state.uioh#
motion x y
5943 state.uioh <- state.uioh#
pmotion x y;
5949 method key key mask
=
5950 begin match state.mode with
5951 | Textentry
textentry -> textentrykeyboard key mask
textentry
5952 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5953 | View
-> viewkeyboard key mask
5954 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5958 method button button bstate
x y mask
=
5959 begin match state.mode with
5961 | View
-> viewmouse button bstate
x y mask
5962 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5968 begin match state.mode with
5970 | View
| Birdseye
_ | LinkNav
_ ->
5971 match state.mstate
with
5972 | Mzoom
_ | Mnone
-> ()
5977 state.mstate
<- Mpan
(x, y);
5979 then state.x <- state.x + dx;
5981 gotoy_and_clear_text y
5984 state.mstate
<- Msel
(a, (x, y));
5985 G.postRedisplay "motion select";
5988 let y = min
conf.winh
(max
0 y) in
5992 let x = min
conf.winw (max
0 x) in
5995 | Mzoomrect
(p0
, _) ->
5996 state.mstate
<- Mzoomrect
(p0
, (x, y));
5997 G.postRedisplay "motion zoomrect";
6001 method pmotion x y =
6002 begin match state.mode with
6003 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6004 let rec loop = function
6006 if hooverpageno
!= -1
6008 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6009 G.postRedisplay "pmotion birdseye no hoover";
6012 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6013 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6015 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6016 G.postRedisplay "pmotion birdseye hoover";
6026 match state.mstate
with
6027 | Mnone
-> updateunder x y
6028 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6033 method infochanged
_ = ()
6036 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
6037 let p, h = scrollph state.y maxy in
6041 let winw = conf.winw - state.scrollw
- 1 in
6042 let fwinw = float winw in
6044 let sw = fwinw /. float state.w in
6045 let sw = fwinw *. sw in
6046 max
sw (float conf.scrollh
)
6049 let f = state.w+winw in
6050 let r = float (winw-state.x) /. float f in
6051 let p = fwinw *. r in
6055 if position +. sw > fwinw
6056 then fwinw -. position
6059 state.hscrollh, position, sw
6063 match state.mode with
6064 | LinkNav
_ -> "links"
6065 | Textentry
_ -> "textentry"
6066 | Birdseye
_ -> "birdseye"
6069 findkeyhash conf modename
6076 let fontpath = ref "";;
6079 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6082 let l = String.length
s in
6083 let b = Buffer.create
l in
6089 try Sys.getenv
"HOME"
6092 ("Can not determine home directory location: " ^
6093 Printexc.to_string exn
);
6097 let modifier_of_string = function
6098 | "alt" -> Wsi.altmask
6099 | "shift" -> Wsi.shiftmask
6100 | "ctrl" | "control" -> Wsi.ctrlmask
6101 | "meta" -> Wsi.metamask
6106 let r = Str.regexp
"-" in
6108 let elems = Str.full_split
r s in
6111 let m1 = modifier_of_string s in
6113 then (Wsi.namekey
s, m)
6116 | Str.Delim
s when n land 1 = 0 -> g s
6118 | Str.Delim
_ -> (k
, m)
6120 let rec loop n k
m = function
6123 let k, m = f n k m x in
6129 let keys_of_string =
6130 let r = Str.regexp
"[ \t]" in
6132 let elems = Str.split
r s in
6133 List.map
key_of_string elems
6136 let copykeyhashes c =
6137 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6140 let config_of c attrs
=
6144 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6145 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6146 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6147 | "preload" -> { c with preload = bool_of_string
v }
6148 | "page-bias" -> { c with pagebias
= int_of_string
v }
6149 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6150 | "horizontal-scroll-step" ->
6151 { c with hscrollstep
= max
(int_of_string
v) 1 }
6152 | "auto-scroll-step" ->
6153 { c with autoscrollstep
= max
0 (int_of_string
v) }
6154 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6155 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6158 match String.lowercase
v with
6159 | "true" -> Some infinity
6161 | f -> Some
(float_of_string
f)
6163 { c with maxwait
= mw}
6164 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6165 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6166 | "vertical-margin" ->
6167 { c with interpagespace
= max
0 (int_of_string
v) }
6169 let zoom = float_of_string
v /. 100. in
6170 let zoom = max
zoom 0.0 in
6171 { c with zoom = zoom }
6172 | "presentation" -> { c with presentation
= bool_of_string
v }
6173 | "rotation-angle" -> { c with angle
= int_of_string
v }
6174 | "width" -> { c with winw = max
20 (int_of_string
v) }
6175 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6176 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6177 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6178 | "pixmap-cache-size" ->
6179 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6180 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6181 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6182 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6183 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6184 | "background-color" -> { c with bgcolor
= color_of_string v }
6185 | "scrollbar-in-presentation" ->
6186 { c with scrollbarinpm
= bool_of_string
v }
6187 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6188 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6189 | "mupdf-store-size" ->
6190 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6191 | "checkers" -> { c with checkers
= bool_of_string
v }
6192 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6193 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6194 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6195 | "uri-launcher" -> { c with urilauncher
= unent v }
6196 | "path-launcher" -> { c with pathlauncher
= unent v }
6197 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6198 | "invert-colors" -> { c with invert
= bool_of_string
v }
6199 | "brightness" -> { c with colorscale
= float_of_string
v }
6200 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6202 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6204 let (n, _, _) as nab
= multicolumns_of_string v in
6206 then { c with columns
= Csplit
(-n, [||]) }
6207 else { c with columns
= Cmulti
(nab
, [||]) }
6208 | "birds-eye-columns" ->
6209 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6210 | "selection-command" -> { c with selcmd
= unent v }
6211 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6212 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6213 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6214 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6215 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6218 prerr_endline
("Error processing attribute (`" ^
6219 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6222 let rec fold c = function
6225 let c = apply c k v in
6228 fold { c with keyhashes
= copykeyhashes c } attrs
;
6231 let fromstring f pos
n v d =
6234 dolog "Error processing attribute (%S=%S) at %d\n%s"
6235 n v pos
(Printexc.to_string exn
)
6240 let bookmark_of attrs
=
6241 let rec fold title page
rely visy
= function
6242 | ("title", v) :: rest
-> fold v page
rely visy rest
6243 | ("page", v) :: rest
-> fold title v rely visy rest
6244 | ("rely", v) :: rest
-> fold title page
v visy rest
6245 | ("visy", v) :: rest
-> fold title page
rely v rest
6246 | _ :: rest
-> fold title page
rely visy rest
6247 | [] -> title, page
, rely, visy
6249 fold "invalid" "0" "0" "0" attrs
6253 let rec fold path page
rely pan visy
= function
6254 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6255 | ("page", v) :: rest
-> fold path v rely pan visy rest
6256 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6257 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6258 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6259 | _ :: rest
-> fold path page
rely pan visy rest
6260 | [] -> path, page
, rely, pan
, visy
6262 fold "" "0" "0" "0" "0" attrs
6266 let rec fold rs ls
= function
6267 | ("out", v) :: rest
-> fold v ls rest
6268 | ("in", v) :: rest
-> fold rs
v rest
6269 | _ :: rest
-> fold ls rs rest
6275 let setconf dst
src =
6276 dst
.scrollbw
<- src.scrollbw
;
6277 dst
.scrollh
<- src.scrollh
;
6278 dst
.icase
<- src.icase
;
6279 dst
.preload <- src.preload;
6280 dst
.pagebias
<- src.pagebias
;
6281 dst
.verbose
<- src.verbose
;
6282 dst
.scrollstep
<- src.scrollstep
;
6283 dst
.maxhfit
<- src.maxhfit
;
6284 dst
.crophack
<- src.crophack
;
6285 dst
.autoscrollstep
<- src.autoscrollstep
;
6286 dst
.maxwait
<- src.maxwait
;
6287 dst
.hlinks
<- src.hlinks
;
6288 dst
.underinfo
<- src.underinfo
;
6289 dst
.interpagespace
<- src.interpagespace
;
6290 dst
.zoom <- src.zoom;
6291 dst
.presentation
<- src.presentation
;
6292 dst
.angle
<- src.angle
;
6293 dst
.winw <- src.winw;
6294 dst
.winh
<- src.winh
;
6295 dst
.savebmarks
<- src.savebmarks
;
6296 dst
.memlimit
<- src.memlimit
;
6297 dst
.proportional
<- src.proportional
;
6298 dst
.texcount
<- src.texcount
;
6299 dst
.sliceheight
<- src.sliceheight
;
6300 dst
.thumbw
<- src.thumbw
;
6301 dst
.jumpback
<- src.jumpback
;
6302 dst
.bgcolor
<- src.bgcolor
;
6303 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6304 dst
.tilew
<- src.tilew
;
6305 dst
.tileh
<- src.tileh
;
6306 dst
.mustoresize
<- src.mustoresize
;
6307 dst
.checkers
<- src.checkers
;
6308 dst
.aalevel
<- src.aalevel
;
6309 dst
.trimmargins
<- src.trimmargins
;
6310 dst
.trimfuzz
<- src.trimfuzz
;
6311 dst
.urilauncher
<- src.urilauncher
;
6312 dst
.colorspace
<- src.colorspace
;
6313 dst
.invert
<- src.invert
;
6314 dst
.colorscale
<- src.colorscale
;
6315 dst
.redirectstderr <- src.redirectstderr;
6316 dst
.ghyllscroll
<- src.ghyllscroll
;
6317 dst
.columns
<- src.columns
;
6318 dst
.beyecolumns
<- src.beyecolumns
;
6319 dst
.selcmd
<- src.selcmd
;
6320 dst
.updatecurs
<- src.updatecurs
;
6321 dst
.pathlauncher
<- src.pathlauncher
;
6322 dst
.keyhashes
<- copykeyhashes src;
6323 dst
.hfsize
<- src.hfsize
;
6324 dst
.hscrollstep
<- src.hscrollstep
;
6325 dst
.pgscale <- src.pgscale;
6326 dst
.usepbo
<- src.usepbo
;
6327 dst
.wheelbypage
<- src.wheelbypage
;
6331 let h = Hashtbl.create
10 in
6332 let dc = { defconf with angle
= defconf.angle
} in
6333 let rec toplevel v t spos
_ =
6335 | Vdata
| Vcdata
| Vend
-> v
6336 | Vopen
("llppconfig", _, closed
) ->
6339 else { v with f = llppconfig
}
6341 error
"unexpected subelement at top level" s spos
6342 | Vclose
_ -> error
"unexpected close at top level" s spos
6344 and llppconfig
v t spos
_ =
6346 | Vdata
| Vcdata
-> v
6347 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6348 | Vopen
("defaults", attrs
, closed
) ->
6349 let c = config_of dc attrs
in
6353 else { v with f = defaults
}
6355 | Vopen
("ui-font", attrs
, closed
) ->
6356 let rec getsize size
= function
6358 | ("size", v) :: rest
->
6360 fromstring int_of_string spos
"size" v fstate.fontsize
in
6362 | l -> getsize size l
6364 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6367 else { v with f = uifont
(Buffer.create
10) }
6369 | Vopen
("doc", attrs
, closed
) ->
6370 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6371 let path = unent pathent
6372 and pageno = fromstring int_of_string spos
"page" spage
0
6373 and rely = fromstring float_of_string spos
"rely" srely
0.0
6374 and pan
= fromstring int_of_string spos
"pan" span
0
6375 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6376 let c = config_of dc attrs
in
6377 let anchor = (pageno, rely, visy
) in
6379 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6380 else { v with f = doc
path pan
anchor c [] }
6383 error
"unexpected subelement in llppconfig" s spos
6385 | Vclose
"llppconfig" -> { v with f = toplevel }
6386 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6388 and defaults
v t spos
_ =
6390 | Vdata
| Vcdata
-> v
6391 | Vend
-> error
"unexpected end of input in defaults" s spos
6392 | Vopen
("keymap", attrs
, closed
) ->
6394 try List.assoc
"mode" attrs
6395 with Not_found
-> "global" in
6400 let h = findkeyhash dc modename in
6401 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6404 { v with f = pkeymap
ret KeyMap.empty }
6406 | Vopen
(_, _, _) ->
6407 error
"unexpected subelement in defaults" s spos
6409 | Vclose
"defaults" ->
6410 { v with f = llppconfig
}
6412 | Vclose
_ -> error
"unexpected close in defaults" s spos
6414 and uifont
b v t spos
epos =
6417 Buffer.add_substring
b s spos
(epos - spos
);
6419 | Vopen
(_, _, _) ->
6420 error
"unexpected subelement in ui-font" s spos
6421 | Vclose
"ui-font" ->
6422 if String.length
!fontpath = 0
6423 then fontpath := Buffer.contents
b;
6424 { v with f = llppconfig
}
6425 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6426 | Vend
-> error
"unexpected end of input in ui-font" s spos
6428 and doc
path pan
anchor c bookmarks
v t spos
_ =
6430 | Vdata
| Vcdata
-> v
6431 | Vend
-> error
"unexpected end of input in doc" s spos
6432 | Vopen
("bookmarks", _, closed
) ->
6435 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6437 | Vopen
("keymap", attrs
, closed
) ->
6439 try List.assoc
"mode" attrs
6440 with Not_found
-> "global"
6446 let h = findkeyhash c modename in
6447 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6448 doc
path pan
anchor c bookmarks
6450 { v with f = pkeymap
ret KeyMap.empty }
6452 | Vopen
(_, _, _) ->
6453 error
"unexpected subelement in doc" s spos
6456 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6457 { v with f = llppconfig
}
6459 | Vclose
_ -> error
"unexpected close in doc" s spos
6461 and pkeymap
ret keymap
v t spos
_ =
6463 | Vdata
| Vcdata
-> v
6464 | Vend
-> error
"unexpected end of input in keymap" s spos
6465 | Vopen
("map", attrs
, closed
) ->
6466 let r, l = map_of attrs
in
6467 let kss = fromstring keys_of_string spos
"in" r [] in
6468 let lss = fromstring keys_of_string spos
"out" l [] in
6472 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6473 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6476 then { v with f = pkeymap
ret keymap }
6479 { v with f = skip
"map" f }
6482 error
"unexpected subelement in keymap" s spos
6484 | Vclose
"keymap" ->
6485 { v with f = ret keymap }
6487 | Vclose
_ -> error
"unexpected close in keymap" s spos
6489 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6491 | Vdata
| Vcdata
-> v
6492 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6493 | Vopen
("item", attrs
, closed
) ->
6494 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6495 let page = fromstring int_of_string spos
"page" spage
0
6496 and rely = fromstring float_of_string spos
"rely" srely
0.0
6497 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6499 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6502 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6505 { v with f = skip
"item" f }
6508 error
"unexpected subelement in bookmarks" s spos
6510 | Vclose
"bookmarks" ->
6511 { v with f = doc
path pan
anchor c bookmarks }
6513 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6515 and skip tag
f v t spos
_ =
6517 | Vdata
| Vcdata
-> v
6519 error
("unexpected end of input in skipped " ^ tag
) s spos
6520 | Vopen
(tag'
, _, closed
) ->
6524 let f'
() = { v with f = skip tag
f } in
6525 { v with f = skip tag'
f'
}
6529 else error
("unexpected close in skipped " ^ tag
) s spos
6532 parse
{ f = toplevel; accu = () } s;
6538 let len = in_channel_length ic
in
6539 let s = String.create
len in
6540 really_input ic
s 0 len;
6543 | Parse_error
(msg
, s, pos
) ->
6544 let subs = subs s pos
in
6545 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6546 failwith
("parse error: " ^
s)
6549 failwith
("config load error: " ^
Printexc.to_string exn
)
6555 let dir = Filename.concat
home ".config" in
6556 if Sys.is_directory
dir then dir else home
6559 Filename.concat
dir "llpp.conf"
6562 let confpath = ref defconfpath;;
6565 if Sys.file_exists
!confpath
6568 (try Some
(open_in_bin
!confpath)
6571 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6572 Printexc.to_string exn
);
6582 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6583 Printexc.to_string exn
);
6591 f (Hashtbl.create
0, defconf)
6596 let pc, pb
, px, pa
=
6598 Hashtbl.find h (Filename.basename
state.path)
6599 with Not_found
-> dc, [], 0, emptyanchor
6603 state.bookmarks <- pb
;
6605 state.scrollw
<- conf.scrollbw
;
6607 then state.anchor <- pa
;
6608 cbput state.hists
.nav pa
;
6614 let add_attrs bb always
dc c =
6617 then Printf.bprintf bb
"\n %s='%b'" s a
6620 then Printf.bprintf bb
"\n %s='%d'" s a
6623 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6626 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6629 then Printf.bprintf bb
"\n %s='%f'" s a
6633 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6637 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6641 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6645 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6651 | Some
(_N
, _A
, _B
) ->
6652 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6662 else string_of_float
f
6664 Printf.bprintf bb
"\n %s='%s'" s v
6669 | Cmulti
((n, a, b), _) when n > 1 ->
6670 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6671 | Csplit
(n, _) when n > 1 ->
6672 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6678 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6683 then dc.winw, dc.winh
6685 match state.fullscreen
with
6687 | None
-> c.winw, c.winh
6689 oi
"width" w dc.winw;
6690 oi
"height" h dc.winh
;
6691 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6692 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6693 ob "case-insensitive-search" c.icase
dc.icase
;
6694 ob "preload" c.preload dc.preload;
6695 oi
"page-bias" c.pagebias
dc.pagebias
;
6696 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6697 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6698 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6699 ob "crop-hack" c.crophack
dc.crophack
;
6700 oW
"throttle" c.maxwait
dc.maxwait
;
6701 ob "highlight-links" c.hlinks
dc.hlinks
;
6702 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6703 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6704 oz
"zoom" c.zoom dc.zoom;
6705 ob "presentation" c.presentation
dc.presentation
;
6706 oi
"rotation-angle" c.angle
dc.angle
;
6707 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6708 ob "proportional-display" c.proportional
dc.proportional
;
6709 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6710 oi
"tex-count" c.texcount
dc.texcount
;
6711 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6712 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6713 ob "persistent-location" c.jumpback
dc.jumpback
;
6714 oc
"background-color" c.bgcolor
dc.bgcolor
;
6715 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6716 oi
"tile-width" c.tilew
dc.tilew
;
6717 oi
"tile-height" c.tileh
dc.tileh
;
6718 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6719 ob "checkers" c.checkers
dc.checkers
;
6720 oi
"aalevel" c.aalevel
dc.aalevel
;
6721 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6722 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6723 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6724 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6725 oC
"color-space" c.colorspace
dc.colorspace
;
6726 ob "invert-colors" c.invert
dc.invert
;
6727 oF
"brightness" c.colorscale
dc.colorscale
;
6728 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6729 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6730 oco
"columns" c.columns
dc.columns
;
6731 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6732 os
"selection-command" c.selcmd
dc.selcmd
;
6733 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6734 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6735 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6736 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6737 ob "use-pbo" c.usepbo
dc.usepbo
;
6738 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6741 let keymapsbuf always
dc c =
6742 let bb = Buffer.create
16 in
6743 let rec loop = function
6745 | (modename, h) :: rest
->
6746 let dh = findkeyhash dc modename in
6747 if always
|| h <> dh
6749 if Hashtbl.length
h > 0
6751 if Buffer.length
bb > 0
6752 then Buffer.add_char
bb '
\n'
;
6753 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6754 Hashtbl.iter
(fun i
o ->
6755 let isdifferent = always
||
6757 let dO = Hashtbl.find dh i
in
6759 with Not_found
-> true
6764 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6765 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6766 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6767 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6768 Buffer.add_string
bb (Wsi.keyname
k);
6771 let rec loop = function
6773 | km
:: [] -> addkm km
6774 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6778 Buffer.add_string
bb "<map in='";
6782 Buffer.add_string
bb "' out='";
6784 Buffer.add_string
bb "'/>\n"
6787 Buffer.add_string
bb "' out='";
6789 Buffer.add_string
bb "'/>\n"
6791 | KMmulti
(ins, kms
) ->
6792 Buffer.add_char
bb ' '
;
6794 Buffer.add_string
bb "' out='";
6796 Buffer.add_string
bb "'/>\n"
6798 Buffer.add_string
bb "</keymap>";
6808 let uifontsize = fstate.fontsize
in
6809 let bb = Buffer.create
32768 in
6811 let dc = if conf.bedefault
then conf else dc in
6812 Buffer.add_string
bb "<llppconfig>\n";
6814 if String.length
!fontpath > 0
6816 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6822 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6825 Buffer.add_string
bb "<defaults ";
6826 add_attrs bb true dc dc;
6827 let kb = keymapsbuf true dc dc in
6828 if Buffer.length
kb > 0
6830 Buffer.add_string
bb ">\n";
6831 Buffer.add_buffer
bb kb;
6832 Buffer.add_string
bb "\n</defaults>\n";
6834 else Buffer.add_string
bb "/>\n";
6836 let adddoc path pan
anchor c bookmarks =
6837 if bookmarks == [] && c = dc && anchor = emptyanchor
6840 Printf.bprintf
bb "<doc path='%s'"
6841 (enent
path 0 (String.length
path));
6843 if anchor <> emptyanchor
6845 let n, rely, visy
= anchor in
6846 Printf.bprintf
bb " page='%d'" n;
6849 Printf.bprintf
bb " rely='%f'" rely
6851 if abs_float visy
> 1e-6
6853 Printf.bprintf
bb " visy='%f'" visy
6858 then Printf.bprintf
bb " pan='%d'" pan
;
6860 add_attrs bb false dc c;
6861 let kb = keymapsbuf false dc c in
6863 begin match bookmarks with
6865 if Buffer.length
kb > 0
6867 Buffer.add_string
bb ">\n";
6868 Buffer.add_buffer
bb kb;
6869 Buffer.add_string
bb "\n</doc>\n";
6871 else Buffer.add_string
bb "/>\n"
6873 Buffer.add_string
bb ">\n<bookmarks>\n";
6874 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6876 "<item title='%s' page='%d'"
6877 (enent
title 0 (String.length
title))
6882 Printf.bprintf
bb " rely='%f'" rely
6884 if abs_float visy
> 1e-6
6886 Printf.bprintf
bb " visy='%f'" visy
6888 Buffer.add_string
bb "/>\n";
6890 Buffer.add_string
bb "</bookmarks>";
6891 if Buffer.length
kb > 0
6893 Buffer.add_string
bb "\n";
6894 Buffer.add_buffer
bb kb;
6896 Buffer.add_string
bb "\n</doc>\n";
6902 match state.mode with
6903 | Birdseye
(c, pan, _, _, _) ->
6905 match conf.columns
with
6906 | Cmulti
((c, _, _), _) -> Some
c
6910 match c.columns
with
6911 | Cmulti
(c, _) -> Cmulti
(c, [||])
6912 | Csingle
_ -> Csingle
[||]
6913 | Csplit
_ -> failwith
"quit from bird's eye while split"
6915 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6916 | _ -> state.x, conf
6918 let basename = Filename.basename state.path in
6919 adddoc basename pan (getanchor ())
6921 let autoscrollstep =
6922 match state.autoscroll
with
6924 | None
-> conf.autoscrollstep
6926 match state.mode with
6927 | Birdseye
(bc
, _, _, _, _) ->
6930 presentation
= bc
.presentation
;
6931 interpagespace
= bc
.interpagespace
;
6932 maxwait
= bc
.maxwait
;
6933 autoscrollstep = autoscrollstep }
6934 | _ -> { conf with autoscrollstep = autoscrollstep }
6936 (if conf.savebmarks
then state.bookmarks else []);
6938 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6940 then adddoc path x anchor c bookmarks
6942 Buffer.add_string
bb "</llppconfig>\n";
6945 if load1 f && Buffer.length
bb > 0
6948 let tmp = !confpath ^
".tmp" in
6949 let oc = open_out_bin
tmp in
6950 Buffer.output_buffer
oc bb;
6952 Unix.rename
tmp !confpath;
6955 ("error while saving configuration: " ^
Printexc.to_string exn
)
6960 let trimcachepath = ref "" in
6963 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6964 "<password> Set password");
6966 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6967 "<path> Set path to the user interface font");
6969 ("-c", Arg.String
(fun s -> Config.confpath := s),
6970 "<path> Set path to the configuration file");
6972 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6973 "<path> Set path to the trim cache file");
6975 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
6976 "<named destination> Set named destination");
6978 ("-wtmode", Arg.Set
wtmode, "wt mode");
6980 ("-v", Arg.Unit
(fun () ->
6982 "%s\nconfiguration path: %s\n"
6986 exit
0), " Print version and exit");
6989 (fun s -> state.path <- s)
6990 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6992 if String.length
state.path = 0
6993 then (prerr_endline
"file name missing"; exit
1);
6995 if not
(Config.load ())
6996 then prerr_endline
"failed to load configuration";
6998 let globalkeyhash = findkeyhash conf "global" in
6999 let wsfd, winw, winh
= Wsi.init
(object
7001 state.wthack <- false;
7002 if nogeomcmds state.geomcmds
|| platform == Posx
7005 GlClear.color (scalecolor2 conf.bgcolor
);
7006 GlClear.clear
[`
color];
7008 method display = display ()
7009 method reshape w h = reshape w h
7010 method mouse b d x y m = mouse b d x y m
7011 method motion x y = state.mpos
<- (x, y); motion x y
7012 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7014 let mascm = m land (
7015 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7017 match state.keystate
with
7019 let km = k, mascm in
7022 let modehash = state.uioh#
modehash in
7023 try Hashtbl.find modehash km
7025 try Hashtbl.find globalkeyhash km
7026 with Not_found
-> KMinsrt
(k, m)
7028 | KMinsrt
(k, m) -> keyboard k m
7029 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7030 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7032 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7033 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7034 state.keystate
<- KSnone
7035 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7036 state.keystate
<- KSinto
(keys
, insrt
)
7038 state.keystate
<- KSnone
7040 method enter
x y = state.mpos
<- (x, y); pmotion x y
7041 method leave = state.mpos
<- (-1, -1)
7042 method quit
= raise Quit
7043 end) conf.winw conf.winh
(platform = Posx
) in
7048 List.exists
GlMisc.check_extension
7049 [ "GL_ARB_texture_rectangle"
7050 ; "GL_EXT_texture_recangle"
7051 ; "GL_NV_texture_rectangle" ]
7053 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7056 match Ne.pipe () with
7058 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7062 match Ne.pipe () with
7064 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7074 setcheckers conf.checkers
;
7078 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7079 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7080 !Config.fontpath, !trimcachepath,
7081 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7085 state.text <- "Opening " ^
(mbtoutf8
state.path);
7087 opendoc state.path state.password
;
7090 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7092 let rec loop deadline
=
7094 match state.errfd
with
7095 | None
-> [state.sr
; state.wsfd]
7096 | Some fd
-> [state.sr
; state.wsfd; fd
]
7098 if state.redisplay
&& not
state.wthack
7100 state.redisplay
<- false;
7107 if deadline
= infinity
7109 else max
0.0 (deadline
-. now)
7114 try tempfailureretry (Unix.select
r [] []) timeout
7115 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7121 if state.ghyll
== noghyll
7123 match state.autoscroll
with
7124 | Some step
when step
!= 0 ->
7125 let y = state.y + step
in
7129 else if y >= state.maxy then 0 else y
7132 if state.mode = View
7133 then state.text <- "";
7136 else deadline
+. 0.01
7141 let rec checkfds = function
7143 | fd
:: rest
when fd
= state.sr
->
7144 let cmd = readcmd state.sr
in
7148 | fd
:: rest
when fd
= state.wsfd ->
7153 let s = String.create
80 in
7154 let n = tempfailureretry (Unix.read fd
s 0) 80 in
7155 if conf.redirectstderr
7157 Buffer.add_substring
state.errmsgs
s 0 n;
7158 state.newerrmsgs
<- true;
7159 state.redisplay
<- true;
7162 prerr_string
(String.sub
s 0 n);
7170 if deadline
= infinity
7174 match state.autoscroll
with
7175 | Some step
when step
!= 0 -> deadline1
7176 | _ -> if state.ghyll
== noghyll then infinity
else deadline1