6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
* trimcachepath
29 and proportional
= bool
30 and trimmargins
= bool
31 and interpagespace
= int
38 and trimcachepath
= string
41 and irect
= (int * int * int * int)
42 and trimparams
= (trimmargins
* irect
)
43 and colorspace
= | Rgb
| Bgr
| Gray
53 | LDfirstvisible
of (int * int * int)
68 | KMmulti
of key list
* key list
70 and keyhash
= (key
, keymap
) Hashtbl.t
73 | KSinto
of (key list
* key list
)
76 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
77 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
79 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
81 external init
: pipe
-> params
-> unit = "ml_init";;
82 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
83 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
84 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
85 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
86 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
87 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
88 external measurestr
: int -> string -> float = "ml_measure_string";;
89 external getmaxw
: unit -> float = "ml_getmaxw";;
90 external postprocess
:
91 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
92 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
93 external platform
: unit -> platform
= "ml_platform";;
94 external setaalevel
: int -> unit = "ml_setaalevel";;
95 external realloctexts
: int -> bool = "ml_realloctexts";;
96 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
97 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
98 external getlink
: opaque
-> int -> under
= "ml_getlink";;
99 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
100 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
101 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
102 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
103 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
104 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
105 external freepbo
: string -> unit = "ml_freepbo";;
106 external unmappbo
: string -> unit = "ml_unmappbo";;
107 external pbousable
: unit -> bool = "ml_pbo_usable";;
109 let platform_to_string = function
110 | Punknown
-> "unknown"
114 | Pfreebsd
-> "FreeBSD"
115 | Pdragonflybsd
-> "DragonflyBSD"
116 | Popenbsd
-> "OpenBSD"
117 | Pnetbsd
-> "NetBSD"
118 | Pcygwin
-> "Cygwin"
121 let platform = platform ();;
124 if platform = Pcygwin
126 let sh = "/bin/sh" in
127 let args = [|sh; "-c"; cmd
|] in
128 let rec std si so se
= function
130 | (fd
, 0) :: rest
-> std fd so se rest
131 | (fd
, -1) :: rest
->
132 Unix.set_close_on_exec fd
;
135 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
137 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
138 ignore
(Unix.create_process
sh args si so se
)
147 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
150 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
152 type mpos
= int * int
154 | Msel
of (mpos
* mpos
)
156 | Mscrolly
| Mscrollx
157 | Mzoom
of (int * int)
158 | Mzoomrect
of (mpos
* mpos
)
162 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
163 and onkey
= string -> int -> te
164 and ondone
= string -> unit
165 and histcancel
= unit -> unit
166 and onhist
= ((histcmd
-> string) * histcancel
)
167 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
168 and cancelonempty
= bool
173 | TEswitch
of textentry
184 let bound v minv maxv
=
185 max minv
(min maxv v
);
189 { store
= Array.create n v
196 let cbcap b
= Array.length b
.store
;;
201 b
.wc
<- (b
.wc
+ 1) mod cap;
203 b
.len
<- min
(b
.len
+ 1) cap;
206 let cbempty b
= b
.len
= 0;;
208 let cbgetg b circular dir
=
212 let rc = b
.rc + dir
in
224 else bound rc 0 (b
.len
-1)
230 let cbget b
= cbgetg b
false;;
231 let cbgetc b
= cbgetg b
true;;
233 let drawstring size x y s
=
235 Gl.enable `texture_2d
;
236 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
237 ignore
(drawstr size x y s
);
239 Gl.disable `texture_2d
;
242 let drawstring1 size x y s
=
246 let drawstring2 size x y fmt
=
247 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
266 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
267 dolog " WxH %dx%d" l
.pagew l
.pageh
;
268 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
269 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
270 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
271 dolog " column %d" l
.pagecol
;
275 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
277 dolog " x0,y0=(% f, % f)" x0 y0
;
278 dolog " x1,y1=(% f, % f)" x1 y1
;
279 dolog " x2,y2=(% f, % f)" x2 y2
;
280 dolog " x3,y3=(% f, % f)" x3 y3
;
284 type multicolumns
= multicol
* pagegeom
285 and singlecolumn
= pagegeom
286 and splitcolumns
= columncount
* pagegeom
287 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
288 and multicol
= columncount
* covercount
* covercount
290 and columncount
= int
291 and covercount
= int;;
294 { mutable scrollbw
: int
295 ; mutable scrollh
: int
296 ; mutable icase
: bool
297 ; mutable preload
: bool
298 ; mutable pagebias
: int
299 ; mutable verbose
: bool
300 ; mutable debug
: bool
301 ; mutable scrollstep
: int
302 ; mutable hscrollstep
: int
303 ; mutable maxhfit
: bool
304 ; mutable crophack
: bool
305 ; mutable autoscrollstep
: int
306 ; mutable maxwait
: float option
307 ; mutable hlinks
: bool
308 ; mutable underinfo
: bool
309 ; mutable interpagespace
: interpagespace
310 ; mutable zoom
: float
311 ; mutable presentation
: bool
312 ; mutable angle
: angle
315 ; mutable savebmarks
: bool
316 ; mutable proportional
: proportional
317 ; mutable trimmargins
: trimmargins
318 ; mutable trimfuzz
: irect
319 ; mutable memlimit
: memsize
320 ; mutable texcount
: texcount
321 ; mutable sliceheight
: sliceheight
322 ; mutable thumbw
: width
323 ; mutable jumpback
: bool
324 ; mutable bgcolor
: float * float * float
325 ; mutable bedefault
: bool
326 ; mutable scrollbarinpm
: bool
327 ; mutable tilew
: int
328 ; mutable tileh
: int
329 ; mutable mustoresize
: memsize
330 ; mutable checkers
: bool
331 ; mutable aalevel
: int
332 ; mutable urilauncher
: string
333 ; mutable pathlauncher
: string
334 ; mutable colorspace
: colorspace
335 ; mutable invert
: bool
336 ; mutable colorscale
: float
337 ; mutable redirectstderr
: bool
338 ; mutable ghyllscroll
: (int * int * int) option
339 ; mutable columns
: columns
340 ; mutable beyecolumns
: columncount
option
341 ; mutable selcmd
: string
342 ; mutable updatecurs
: bool
343 ; mutable keyhashes
: (string * keyhash
) list
344 ; mutable hfsize
: int
345 ; mutable pgscale
: float
346 ; mutable usepbo
: bool
347 ; mutable wheelbypage
: bool
350 | Csingle
of singlecolumn
351 | Cmulti
of multicolumns
352 | Csplit
of splitcolumns
355 type anchor
= pageno
* top
* dtop
;;
357 type outline
= string * int * anchor
;;
359 type rect
= float * float * float * float * float * float * float * float;;
361 type tile
= opaque
* pixmapsize
* elapsed
362 and elapsed
= float;;
363 type pagemapkey
= pageno
* gen
;;
364 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
368 let emptyanchor = (0, 0.0, 0.0);;
370 type infochange
= | Memused
| Docinfo
| Pdim
;;
372 class type uioh
= object
373 method display
: unit
374 method key
: int -> int -> uioh
375 method button
: int -> bool -> int -> int -> int -> uioh
376 method motion
: int -> int -> uioh
377 method pmotion
: int -> int -> uioh
378 method infochanged
: infochange
-> unit
379 method scrollpw
: (int * float * float)
380 method scrollph
: (int * float * float)
381 method modehash
: keyhash
385 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
386 | Textentry
of (textentry
* onleave
)
388 | LinkNav
of linktarget
389 and onleave
= leavetextentrystatus
-> unit
390 and leavetextentrystatus
= | Cancel
| Confirm
391 and helpitem
= string * int * action
394 | Action
of (uioh
-> uioh
)
396 | Ltexact
of (pageno
* int)
400 let isbirdseye = function Birdseye _
-> true | _
-> false;;
401 let istextentry = function Textentry _
-> true | _
-> false;;
405 | Loading
of (page
* gen
)
407 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
409 | Outlining
of outline list
412 let emptykeyhash = Hashtbl.create
0;;
413 let nouioh : uioh
= object (self
)
415 method key _ _
= self
416 method button _ _ _ _ _
= self
417 method motion _ _
= self
418 method pmotion _ _
= self
419 method infochanged _
= ()
420 method scrollpw
= (0, nan
, nan
)
421 method scrollph
= (0, nan
, nan
)
422 method modehash
= emptykeyhash
426 { mutable sr
: Unix.file_descr
427 ; mutable sw
: Unix.file_descr
428 ; mutable wsfd
: Unix.file_descr
429 ; mutable errfd
: Unix.file_descr
option
430 ; mutable stderr
: Unix.file_descr
431 ; mutable errmsgs
: Buffer.t
432 ; mutable newerrmsgs
: bool
436 ; mutable scrollw
: int
437 ; mutable hscrollh
: int
438 ; mutable anchor
: anchor
439 ; mutable ranchors
: (string * string * anchor
) list
441 ; mutable layout
: page list
442 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
443 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
444 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
445 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
446 ; mutable pagecount
: int
447 ; mutable currently
: currently
448 ; mutable mstate
: mstate
449 ; mutable searchpattern
: string
450 ; mutable rects
: (pageno
* recttype
* rect
) list
451 ; mutable rects1
: (pageno
* recttype
* rect
) list
452 ; mutable text
: string
453 ; mutable fullscreen
: (width
* height
) option
454 ; mutable mode
: mode
455 ; mutable uioh
: uioh
456 ; mutable outlines
: outline array
457 ; mutable bookmarks
: outline list
458 ; mutable path
: string
459 ; mutable password
: string
460 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
461 ; mutable memused
: memsize
463 ; mutable throttle
: (page list
* int * float) option
464 ; mutable autoscroll
: int option
465 ; mutable ghyll
: (int option -> unit)
466 ; mutable help
: helpitem array
467 ; mutable docinfo
: (int * string) list
468 ; mutable texid
: GlTex.texture_id
option
470 ; mutable prevzoom
: float
471 ; mutable progress
: float
472 ; mutable redisplay
: bool
473 ; mutable mpos
: mpos
474 ; mutable keystate
: keystate
475 ; mutable glinks
: bool
476 ; mutable prevcolumns
: (columns
* float) option
477 ; mutable wthack
: bool
480 { pat
: string circbuf
481 ; pag
: string circbuf
482 ; nav
: anchor circbuf
483 ; sel
: string circbuf
505 ; presentation
= false
510 ; proportional
= true
511 ; trimmargins
= false
512 ; trimfuzz
= (0,0,0,0)
513 ; memlimit
= 32 lsl 20
518 ; bgcolor
= (0.5, 0.5, 0.5)
520 ; scrollbarinpm
= true
523 ; mustoresize
= 256 lsl 20
528 | Plinux
| Pfreebsd
| Pdragonflybsd
529 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
530 | Posx
-> "open \"%s\""
531 | Pcygwin
-> "cygstart \"%s\""
532 | Punknown
-> "echo %s")
533 ; pathlauncher
= "lp \"%s\""
536 | Plinux
| Pfreebsd
| Pdragonflybsd
537 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
544 ; redirectstderr
= false
546 ; columns
= Csingle
[||]
552 ; wheelbypage
= false
554 let mk n
= (n
, Hashtbl.create
1) in
568 let findkeyhash c name
=
569 try List.assoc name c
.keyhashes
570 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
573 let conf = { defconf with angle
= defconf.angle
};;
575 let pgscale h
= truncate
(float h
*. conf.pgscale);;
578 { mutable fontsize
: int
579 ; mutable wwidth
: float
580 ; mutable maxrows
: int
592 fstate.fontsize
<- n
;
593 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
594 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
598 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
599 let len = String.length s
in
600 if colonpos >= 0 && colonpos + 3 < len
602 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
605 try String.rindex_from s
colonpos ' '
609 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
612 | "http" | "ftp" | "mailto" ->
614 try String.index_from s
colonpos ' '
615 with Not_found
-> len
617 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
625 if String.length
conf.urilauncher
= 0
626 then print_endline uri
628 let url = geturl uri
in
629 if String.length
url = 0
630 then print_endline uri
632 let re = Str.regexp
"%s" in
633 let command = Str.global_replace
re url conf.urilauncher
in
637 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
643 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
644 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
648 let strings = version () :: "" :: Help.keys
in
651 let url = geturl s
in
652 if String.length
url > 0
653 then (s
, 0, Action
(fun u
-> gotouri url; u
))
654 else (s
, 0, Noaction
)
659 let firstgeomcmds = "", [];;
666 ; stderr
= Unix.stderr
667 ; errmsgs
= Buffer.create
0
674 ; anchor
= emptyanchor
678 ; tilelru
= Queue.create
()
679 ; pagemap
= Hashtbl.create
10
680 ; tilemap
= Hashtbl.create
10
695 ; geomcmds
= firstgeomcmds
697 { nav
= cbnew 10 emptyanchor
725 Printf.kprintf prerr_endline fmt
727 Printf.kprintf ignore fmt
731 if String.length
conf.pathlauncher
= 0
732 then print_endline
state.path
734 let re = Str.regexp
"%s" in
735 let command = Str.global_replace
re state.path
conf.pathlauncher
in
739 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
745 type 'a t
= | Res
of 'a
| Exn
of exn
;;
748 try Res
(Unix.pipe ())
754 with exn
-> f
(Printexc.to_string exn
)
758 try Res
(Unix.dup fd
)
763 try Res
(Unix.dup2 fd1 fd2
)
768 let redirectstderr () =
769 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
770 if conf.redirectstderr
772 match Ne.pipe () with
774 dolog "failed to create stderr redirection pipes: %s"
775 (Printexc.to_string exn
)
778 begin match Ne.dup Unix.stderr
with
780 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
781 Ne.clo r
(clofail "pipe/r");
782 Ne.clo w
(clofail "pipe/w");
784 | Ne.Res dupstderr
->
785 begin match Ne.dup2 w
Unix.stderr
with
787 dolog "failed to dup2 to stderr: %s"
788 (Printexc.to_string exn
);
789 Ne.clo dupstderr
(clofail "stderr duplicate");
790 Ne.clo r
(clofail "redir pipe/r");
791 Ne.clo w
(clofail "redir pipe/w");
794 state.stderr
<- dupstderr
;
795 state.errfd
<- Some r
;
799 state.newerrmsgs
<- false;
800 begin match state.errfd
with
802 begin match Ne.dup2 state.stderr
Unix.stderr
with
804 dolog "failed to dup2 original stderr: %s"
805 (Printexc.to_string exn
)
807 Ne.clo fd
(clofail "dup of stderr");
808 Unix.dup2 state.stderr
Unix.stderr
;
813 prerr_string
(Buffer.contents
state.errmsgs
);
815 Buffer.clear
state.errmsgs
;
821 let postRedisplay who
=
823 then prerr_endline
("redisplay for " ^ who
);
824 state.redisplay
<- true;
828 let getopaque pageno
=
829 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
830 with Not_found
-> None
833 let putopaque pageno opaque
=
834 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
837 let pagetranslatepoint l x y
=
838 let dy = y
- l
.pagedispy
in
839 let y = dy + l
.pagey
in
840 let dx = x
- l
.pagedispx
in
841 let x = dx + l
.pagex
in
848 begin match getopaque l
.pageno
with
850 let x0 = l
.pagedispx
in
851 let x1 = x0 + l
.pagevw
in
852 let y0 = l
.pagedispy
in
853 let y1 = y0 + l
.pagevh
in
854 if y >= y0 && y <= y1 && x >= x0 && x <= x1
856 let px, py
= pagetranslatepoint l
x y in
857 match whatsunder opaque
px py
with
870 state.text
<- Printf.sprintf
"%c%s" c s
;
871 G.postRedisplay "showtext";
874 let undertext = function
877 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
878 | Utext s
-> "font: " ^ s
879 | Uunexpected s
-> "unexpected: " ^ s
880 | Ulaunch s
-> "launch: " ^ s
881 | Unamed s
-> "named: " ^ s
882 | Uremote
(filename
, pageno
) ->
883 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
886 let updateunder x y =
887 match getunder x y with
888 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
890 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
891 Wsi.setcursor
Wsi.CURSOR_INFO
892 | Ulinkgoto
(pageno
, _
) ->
894 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
895 Wsi.setcursor
Wsi.CURSOR_INFO
897 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
898 Wsi.setcursor
Wsi.CURSOR_TEXT
900 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
901 Wsi.setcursor
Wsi.CURSOR_INHERIT
903 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
904 Wsi.setcursor
Wsi.CURSOR_INHERIT
906 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
907 Wsi.setcursor
Wsi.CURSOR_INHERIT
908 | Uremote
(filename
, pageno
) ->
909 if conf.underinfo
then showtext 'r'
910 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
911 Wsi.setcursor
Wsi.CURSOR_INFO
914 let showlinktype under
=
920 let s = undertext under
in
925 let b = Buffer.create
(String.length
s + 1) in
926 Buffer.add_string
b s;
931 let colorspace_of_string s =
932 match String.lowercase
s with
936 | _
-> failwith
"invalid colorspace"
939 let int_of_colorspace = function
945 let colorspace_of_int = function
949 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
952 let colorspace_to_string = function
958 let intentry_with_suffix text key
=
960 if key
>= 32 && key
< 127
964 match Char.lowercase
c with
966 let text = addchar text c in
970 let text = addchar text c in
974 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
978 let multicolumns_to_string (n
, a
, b) =
980 then Printf.sprintf
"%d" n
981 else Printf.sprintf
"%d,%d,%d" n a
b;
984 let multicolumns_of_string s =
986 (int_of_string
s, 0, 0)
988 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
990 then failwith
"subtly broken"; (n
, a
, b)
996 let n = Unix.read fd
s 0 4 in
997 if n != 4 then failwith
"incomplete read(len)";
999 lor (Char.code
s.[0] lsl 24)
1000 lor (Char.code
s.[1] lsl 16)
1001 lor (Char.code
s.[2] lsl 8)
1002 lor (Char.code
s.[3] lsl 0)
1004 let s = String.create
len in
1005 let n = Unix.read fd
s 0 len in
1006 if n != len then failwith
"incomplete read(data)";
1010 let btod b = if b then 1 else 0;;
1013 let b = Buffer.create
16 in
1014 Buffer.add_string
b "llll";
1017 let s = Buffer.contents
b in
1018 let n = String.length
s in
1020 (* dolog "wcmd %S" (String.sub s 4 len); *)
1021 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1022 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1023 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1024 s.[3] <- Char.chr
(len land 0xff);
1025 let n'
= Unix.write
state.sw
s 0 n in
1026 if n'
!= n then failwith
"write failed";
1031 let d = conf.winh
- h
in
1032 max
conf.interpagespace
((d + 1) / 2)
1035 let rowyh (c, coverA
, coverB
) b n =
1036 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1038 let _, _, vy
, (_, _, h
, _) = b.(n) in
1041 let n'
= n - coverA
in
1044 let e = min
state.pagecount
(s + c) in
1045 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1046 let _, _, y, (_, _, h
, _) = b.(m
) in
1047 let miny = min
miny y in
1048 let maxh = max
maxh h
in
1049 find (m
+1) miny maxh
1054 match conf.columns
with
1055 | Cmulti
((_, _, _) as cl
, b) ->
1056 if Array.length
b > 0
1058 let y, h
= rowyh cl
b (Array.length
b - 1) in
1059 y + h
+ (if conf.presentation
then calcips h
else 0)
1062 if Array.length
b > 0
1064 let (_, _, y, (_, _, h
, _)) = 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
1075 let getpageyh pageno
=
1076 let pageno = bound pageno 0 (state.pagecount
-1) in
1077 match conf.columns
with
1079 if Array.length
b = 0
1082 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1084 if conf.presentation
1090 if Array.length
b = 0
1093 let y, h
= rowyh cl
b pageno in
1095 if conf.presentation
1101 if Array.length
b = 0
1105 let (_, _, y, (_, _, h
, _)) = b.(n) in
1109 let getpagedim pageno =
1112 | (n, _, _, _) as pdim
:: rest
->
1114 then (if n = pageno then pdim
else ppdim
)
1119 f (-1, -1, -1, -1) state.pdims
1122 let getpagey pageno = fst
(getpageyh pageno);;
1124 let nogeomcmds cmds
=
1126 | s, [] -> String.length
s = 0
1131 let ((c, coverA
, coverB
) as cl
), b =
1132 match conf.columns
with
1133 | Csingle
b -> (1, 0, 0), b
1134 | Cmulti
(c, b) -> c, b
1135 | Csplit
(_, b) -> (1, 0, 0), b
1137 let rec bsearch nmin nmax
=
1139 then bound nmin
0 (state.pagecount
-1)
1141 let n = (nmax
+ nmin
) / 2 in
1142 let vy, h
= rowyh cl
b n in
1144 if conf.presentation
1146 let ips = calcips h
in
1147 let y0 = vy - ips in
1148 let y1 = vy + h
+ ips in
1152 then 0, vy + h
+ conf.interpagespace
1154 let y0 = vy - conf.interpagespace
in
1155 y0, y0 + h
+ conf.interpagespace
1158 if y >= y0 && y < y1
1165 if n < state.pagecount
- coverB
1166 then ((n-coverA
)/c)*c + coverA
1173 then bsearch (n+1) nmax
1174 else bsearch nmin
(n-1)
1177 let r = bsearch 0 (state.pagecount
-1) in
1181 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1182 let sh = sh - state.hscrollh
in
1183 let rec fold accu
n =
1184 if n = Array.length
b
1187 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1190 || n = state.pagecount
- coverB
1191 || (n - coverA
) mod columns
= columns
- 1)
1197 let pagey = max
0 (y - vy) in
1198 let pagedispy = if pagey > 0 then 0 else vy - y in
1199 let pagedispx, pagex
=
1201 if n = coverA
- 1 || n = state.pagecount
- coverB
1202 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1203 else dx + xoff
+ state.x
1210 let vw = conf.winw
- state.scrollw
- pagedispx in
1211 let pw = w
- pagex
in
1214 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1215 if pagevw > 0 && pagevh > 0
1219 ; pagedimno
= pdimno
1226 ; pagedispx = pagedispx
1227 ; pagedispy = pagedispy
1239 List.rev
(fold [] (page_of_y y));
1242 let layoutS (columns
, b) y sh =
1243 let sh = sh - state.hscrollh
in
1244 let rec fold accu n =
1245 if n = Array.length
b
1248 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1255 let x = xoff
+ state.x in
1256 let pagey = max
0 (y - vy) in
1257 let pagedispy = if pagey > 0 then 0 else vy - y in
1258 let pagedispx, pagex
=
1272 let pagecolw = pagew
/columns
in
1274 if pagecolw < conf.winw
1275 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1279 let vw = conf.winw
- pagedispx - state.scrollw
in
1280 let pw = pagew
- pagex
in
1283 let pagevw = min
pagevw pagecolw in
1284 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1285 if pagevw > 0 && pagevh > 0
1288 { pageno = n/columns
1289 ; pagedimno
= pdimno
1296 ; pagedispx = pagedispx
1297 ; pagedispy = pagedispy
1298 ; pagecol
= n mod columns
1309 List.rev
(fold [] 0)
1313 if nogeomcmds state.geomcmds
1315 match conf.columns
with
1316 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1317 | Cmulti
c -> layoutN c y sh
1318 | Csplit
s -> layoutS s y sh
1323 let y = state.y + incr
in
1325 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1330 let tilex = l
.pagex
mod conf.tilew
in
1331 let tiley = l
.pagey mod conf.tileh
in
1333 let col = l
.pagex
/ conf.tilew
in
1334 let row = l
.pagey / conf.tileh
in
1336 let rec rowloop row y0 dispy h
=
1340 let dh = conf.tileh
- y0 in
1341 let dh = min h
dh in
1342 let rec colloop col x0 dispx w
=
1346 let dw = conf.tilew
- x0 in
1347 let dw = min w
dw in
1349 f col row dispx dispy
x0 y0 dw dh;
1350 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1353 colloop col tilex l
.pagedispx l
.pagevw;
1354 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1357 if l
.pagevw > 0 && l
.pagevh > 0
1358 then rowloop row tiley l
.pagedispy l
.pagevh;
1361 let gettileopaque l
col row =
1363 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1365 try Some
(Hashtbl.find state.tilemap
key)
1366 with Not_found
-> None
1369 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1370 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1371 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1374 let drawtiles l color
=
1376 let f col row x y tilex tiley w h
=
1377 match gettileopaque l
col row with
1378 | Some
(opaque
, _, t
) ->
1379 let params = x, y, w
, h
, tilex, tiley in
1383 GlFunc.blend_func `zero `one_minus_src_color
;
1385 drawtile
params opaque
;
1387 then Gl.disable `blend
;
1390 let s = Printf.sprintf
1394 let w = measurestr
fstate.fontsize
s in
1395 GlMisc.push_attrib
[`current
];
1396 GlDraw.color
(0.0, 0.0, 0.0);
1398 (float (x-2), float (y-2))
1399 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1400 GlDraw.color
(1.0, 1.0, 1.0);
1401 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1402 GlMisc.pop_attrib
();
1407 let lw = conf.winw
- state.scrollw
- x in
1410 let lh = conf.winh
- y in
1413 begin match state.texid
with
1415 Gl.enable `texture_2d
;
1416 GlTex.bind_texture `texture_2d id
;
1419 and x1 = float (x+w)
1420 and y1 = float (y+h
) in
1422 let tw = float w /. 16.0
1423 and th
= float h
/. 16.0 in
1424 let tx0 = float tilex /. 16.0
1425 and ty0
= float tiley /. 16.0 in
1427 and ty1
= ty0
+. th
in
1428 GlDraw.begins `quads
;
1429 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1430 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1431 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1432 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1435 Gl.disable `texture_2d
;
1437 GlDraw.color
(1.0, 1.0, 1.0);
1440 (float (x+w), float (y+h
));
1442 if w > 128 && h
> fstate.fontsize
+ 10
1444 GlDraw.color
(0.0, 0.0, 0.0);
1447 then (col*conf.tilew
, row*conf.tileh
)
1450 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1457 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1459 let tilevisible1 l
x y =
1461 and ax1
= l
.pagex
+ l
.pagevw
1463 and ay1
= l
.pagey + l
.pagevh in
1467 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1468 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1470 let rx0 = max
ax0 bx0
1471 and ry0
= max ay0 by0
1472 and rx1
= min ax1
bx1
1473 and ry1
= min ay1 by1
in
1475 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1476 nonemptyintersection
1479 let tilevisible layout n x y =
1480 let rec findpageinlayout m
= function
1481 | l
:: rest
when l
.pageno = n ->
1482 tilevisible1 l
x y || (
1483 match conf.columns
with
1484 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1487 | _ :: rest
-> findpageinlayout 0 rest
1490 findpageinlayout 0 layout;
1493 let tileready l
x y =
1494 tilevisible1 l
x y &&
1495 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1498 let tilepage n p
layout =
1499 let rec loop = function
1503 let f col row _ _ _ _ _ _ =
1504 if state.currently
= Idle
1506 match gettileopaque l
col row with
1509 let x = col*conf.tilew
1510 and y = row*conf.tileh
in
1512 let w = l
.pagew
- x in
1516 let h = l
.pageh
- y in
1521 then getpbo
w h conf.colorspace
1524 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1527 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1528 conf.tilew
, conf.tileh
1537 if nogeomcmds state.geomcmds
1541 let preloadlayout y =
1542 let y = if y < conf.winh
then 0 else y - conf.winh
in
1543 let h = conf.winh
*3 in
1548 let rec loop pages
=
1549 if state.currently
!= Idle
1554 begin match getopaque l
.pageno with
1556 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1557 state.currently
<- Loading
(l
, state.gen
);
1559 tilepage l
.pageno opaque pages
;
1564 if nogeomcmds state.geomcmds
1570 if conf.preload && state.currently
= Idle
1571 then load (preloadlayout state.y);
1574 let layoutready layout =
1575 let rec fold all ls
=
1576 all
&& match ls
with
1578 let seen = ref false in
1579 let allvisible = ref true in
1580 let foo col row _ _ _ _ _ _ =
1582 allvisible := !allvisible &&
1583 begin match gettileopaque l
col row with
1589 fold (!seen && !allvisible) rest
1592 let alltilesvisible = fold true layout in
1597 let y = bound y 0 state.maxy
in
1598 let y, layout, proceed
=
1599 match conf.maxwait
with
1600 | Some time
when state.ghyll
== noghyll ->
1601 begin match state.throttle
with
1603 let layout = layout y conf.winh
in
1604 let ready = layoutready layout in
1608 state.throttle
<- Some
(layout, y, now ());
1610 else G.postRedisplay "gotoy showall (None)";
1612 | Some
(_, _, started
) ->
1613 let dt = now () -. started
in
1616 state.throttle
<- None
;
1617 let layout = layout y conf.winh
in
1619 G.postRedisplay "maxwait";
1626 let layout = layout y conf.winh
in
1627 if true || layoutready layout
1628 then G.postRedisplay "gotoy ready";
1634 state.layout <- layout;
1635 begin match state.mode
with
1636 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1637 let rec loop = function
1639 state.mode
<- LinkNav
(Ltgendir
0)
1640 | l
:: _ when l
.pageno = pageno ->
1641 begin match getopaque pageno with
1643 state.mode
<- LinkNav
(Ltgendir
0)
1645 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1646 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1647 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1648 then state.mode
<- LinkNav
(Ltgendir
0)
1650 | _ :: rest
-> loop rest
1655 begin match state.mode
with
1656 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1657 if not
(pagevisible layout pageno)
1659 match state.layout with
1662 state.mode
<- Birdseye
(
1663 conf, leftx
, l
.pageno, hooverpageno
, anchor
1666 | LinkNav
(Ltgendir dir
as lt
) ->
1668 let rec loop = function
1671 match getopaque l
.pageno with
1677 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1679 if dir
> 0 then LDfirst
else LDlast
1685 | Lnotfound
-> loop rest
1687 showlinktype (getlink opaque
n);
1688 Ltexact
(l
.pageno, n)
1692 state.mode
<- LinkNav
linknav
1697 state.ghyll
<- noghyll;
1700 let mx, my
= state.mpos
in
1705 let conttiling pageno opaque
=
1706 tilepage pageno opaque
1707 (if conf.preload then preloadlayout state.y else state.layout)
1710 let gotoy_and_clear_text y =
1711 if not
conf.verbose
then state.text <- "";
1717 let coloff = l
.pagecol
* l
.pageh
in
1718 float (l
.pagey + coloff) /. float l
.pageh
1725 if conf.presentation
1726 then float l
.pagedispy /. float (calcips l
.pageh
)
1727 else float l
.pagedispy /. float conf.interpagespace
1729 (l
.pageno, top, dtop)
1733 match state.layout with
1734 | l
:: _ -> getanchor1 l
1736 let n = page_of_y state.y in
1737 let y, h = getpageyh n in
1738 let dy = y - state.y in
1740 if conf.presentation
1742 let ips = calcips h in
1743 float (dy + ips) /. float ips
1745 float dy /. float conf.interpagespace
1750 let getanchory (n, top, dtop) =
1751 let y, h = getpageyh n in
1752 if conf.presentation
1754 let ips = calcips h in
1755 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1757 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1760 let gotoanchor anchor
=
1761 gotoy (getanchory anchor
);
1765 cbput state.hists
.nav
(getanchor ());
1769 let anchor = cbgetc state.hists
.nav dir
in
1774 let scroll f n a
b =
1775 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1777 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1779 then s (float f /. float a
)
1782 then 1.0 -. s ((float (f-b) /. float (n-b)))
1789 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1790 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1792 let ins = float a
*. iv1
1793 and outs
= float (n-b) *. iv1 in
1795 ins +. outs
+. float ones
1797 let rec set (_N
, _A
, _B
) y sy
=
1798 let sum = summa
1.0 _N _A _B
in
1799 let dy = float (y - sy
) in
1803 then state.ghyll
<- noghyll
1806 let s = scroll n _N _A _B
in
1807 let y1 = y1 +. ((s *. dy) /. sum) in
1808 gotoy_and_clear_text (truncate
y1);
1809 state.ghyll
<- gf (n+1) y1;
1813 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1815 gf 0 (float state.y)
1818 match conf.ghyllscroll
with
1820 gotoy_and_clear_text y
1822 if state.ghyll
== noghyll
1823 then set nab
y state.y
1824 else state.ghyll
(Some
y)
1827 let gotopage n top =
1828 let y, h = getpageyh n in
1829 let y = y + (truncate
(top *. float h)) in
1833 let gotopage1 n top =
1834 let y = getpagey n in
1839 let invalidate s f =
1844 match state.geomcmds
with
1845 | ps
, [] when String.length ps
= 0 ->
1847 state.geomcmds
<- s, [];
1850 state.geomcmds
<- ps
, [s, f];
1852 | ps
, (s'
, _) :: rest
when s'
= s ->
1853 state.geomcmds
<- ps
, ((s, f) :: rest
);
1856 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1860 Hashtbl.iter
(fun _ opaque
->
1861 wcmd "freepage %s" opaque
;
1863 Hashtbl.clear
state.pagemap
;
1866 let opendoc path password
=
1868 state.password
<- password
;
1869 state.gen
<- state.gen
+ 1;
1870 state.docinfo
<- [];
1873 setaalevel
conf.aalevel
;
1874 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1875 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1876 invalidate "reqlayout"
1878 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1882 state.anchor <- getanchor ();
1883 state.wthack
<- true;
1884 opendoc state.path
state.password
;
1888 let c = c *. conf.colorscale
in
1892 let scalecolor2 (r, g
, b) =
1893 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1896 let docolumns = function
1898 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1899 let rec loop pageno pdimno pdim
y ph pdims
=
1900 if pageno = state.pagecount
1903 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1905 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1906 pdimno+1, pdim
, rest
1910 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1912 (if conf.presentation
1913 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1914 else (if pageno = 0 then 0 else conf.interpagespace
)
1917 a.(pageno) <- (pdimno, x, y, pdim
);
1918 loop (pageno+1) pdimno pdim
(y + h) h pdims
1920 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1921 conf.columns
<- Csingle
a;
1923 | Cmulti
((columns
, coverA
, coverB
), _) ->
1924 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1925 let rec loop pageno pdimno pdim
x y rowh pdims
=
1926 let rec fixrow m
= if m
= pageno then () else
1927 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1930 let y = y + (rowh
- h) / 2 in
1931 a.(m
) <- (pdimno, x, y, pdim
);
1935 if pageno = state.pagecount
1936 then fixrow (((pageno - 1) / columns
) * columns
)
1938 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1940 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1941 pdimno+1, pdim
, rest
1946 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1948 let x = (conf.winw
- state.scrollw
- w) / 2 in
1950 if conf.presentation
then calcips h else conf.interpagespace
in
1951 x, y + ips + rowh
, h
1954 if (pageno - coverA
) mod columns
= 0
1956 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1958 if conf.presentation
1960 let ips = calcips h in
1961 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1963 y + (if pageno = 0 then 0 else conf.interpagespace
)
1967 else x, y, max rowh
h
1971 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1974 if pageno = columns
&& conf.presentation
1976 let ips = calcips rowh
in
1977 for i
= 0 to pred columns
1979 let (pdimno, x, y, pdim
) = a.(i
) in
1980 a.(i
) <- (pdimno, x, y+ips, pdim
)
1986 fixrow (pageno - columns
);
1991 a.(pageno) <- (pdimno, x, y, pdim
);
1992 let x = x + w + xoff
*2 + conf.interpagespace
in
1993 loop (pageno+1) pdimno pdim
x y rowh' pdims
1995 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1996 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1999 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2000 let rec loop pageno pdimno pdim
y pdims
=
2001 if pageno = state.pagecount
2004 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2006 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2007 pdimno+1, pdim
, rest
2012 let rec loop1 n x y =
2013 if n = c then y else (
2014 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2015 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2018 let y = loop1 0 0 y in
2019 loop (pageno+1) pdimno pdim
y pdims
2021 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2022 conf.columns
<- Csplit
(c, a);
2026 docolumns conf.columns
;
2027 state.maxy
<- calcheight ();
2029 if state.w <= conf.winw
- state.scrollw
2033 match state.mode
with
2034 | Birdseye
(_, _, pageno, _, _) ->
2035 let y, h = getpageyh pageno in
2036 let top = (conf.winh
- h) / 2 in
2037 gotoy (max
0 (y - top))
2038 | _ -> gotoanchor state.anchor
2042 state.wthack
<- false;
2043 GlDraw.viewport
0 0 w h;
2044 let firsttime = state.geomcmds
== firstgeomcmds in
2045 if not
firsttime && nogeomcmds state.geomcmds
2046 then state.anchor <- getanchor ();
2049 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2052 setfontsize fstate.fontsize
;
2053 GlMat.mode `modelview
;
2054 GlMat.load_identity
();
2056 GlMat.mode `projection
;
2057 GlMat.load_identity
();
2058 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2059 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2060 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2065 else float state.x /. float state.w
2067 invalidate "geometry"
2071 then state.x <- truncate
(relx *. float w);
2073 match conf.columns
with
2075 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2076 | Csplit
(c, _) -> w * c
2078 wcmd "geometry %d %d" w h);
2082 let len = String.length
state.text in
2085 match state.mode
with
2088 let h, _, _ = state.uioh#scrollpw
in
2094 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2095 (x+.w, float (conf.winh
- hscrollh))
2098 let w = float (conf.winw
- state.scrollw
- 1) in
2099 if state.progress
>= 0.0 && state.progress
< 1.0
2101 GlDraw.color
(0.3, 0.3, 0.3);
2102 let w1 = w *. state.progress
in
2104 GlDraw.color
(0.0, 0.0, 0.0);
2108 GlDraw.color
(0.0, 0.0, 0.0);
2112 GlDraw.color
(1.0, 1.0, 1.0);
2113 drawstring fstate.fontsize
2114 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2117 match state.mode
with
2118 | Textentry
((prefix
, text, _, _, _, _), _) ->
2122 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2124 Printf.sprintf
"%s%s_" prefix
text
2133 if not
(istextentry state.mode
)
2135 let s1 = "(press 'e' to review error messasges)" in
2136 if String.length
s > 0 then s ^
" " ^
s1 else s1
2141 if String.length
s > 0
2146 let len = Queue.length
state.tilelru
in
2148 match state.throttle
with
2151 then preloadlayout state.y
2153 | Some
(layout, _, _) ->
2157 if state.memused
<= conf.memlimit
2162 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2163 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2164 let (_, pw, ph
, _) = getpagedim n in
2167 && colorspace
= conf.colorspace
2168 && angle
= conf.angle
2172 let x = col*conf.tilew
2173 and y = row*conf.tileh
in
2174 tilevisible (Lazy.force_val
layout) n x y
2176 then Queue.push lruitem
state.tilelru
2179 wcmd "freetile %s" p
;
2180 state.memused
<- state.memused
- s;
2181 state.uioh#infochanged Memused
;
2182 Hashtbl.remove
state.tilemap k
;
2191 Queue.iter
(fun (k
, p
, s) ->
2192 wcmd "freetile %s" p
;
2193 state.memused
<- state.memused
- s;
2194 state.uioh#infochanged Memused
;
2195 Hashtbl.remove
state.tilemap k
;
2197 Queue.clear
state.tilelru
;
2201 let logcurrently = function
2202 | Idle
-> dolog "Idle"
2203 | Loading
(l
, gen
) ->
2204 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2205 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2207 "Tiling %d[%d,%d] page=%s cs=%s angle"
2208 l
.pageno col row pageopaque
2209 (colorspace_to_string colorspace
)
2211 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2212 angle gen
conf.angle
state.gen
2214 conf.tilew
conf.tileh
2221 (* dolog "%S" cmds; *)
2224 try String.index cmds ' '
2225 with Not_found
-> -1
2230 let l = String.length cmds
in
2231 let op = String.sub cmds
0 spacepos in
2233 if l - spacepos < 2 then ""
2234 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2239 state.uioh#infochanged Pdim
;
2243 state.rects
<- state.rects1
;
2244 G.postRedisplay "clearrects";
2248 try Scanf.sscanf
args "%u" (fun n -> n)
2250 dolog "error processing 'continue' %S: %s"
2251 cmds
(Printexc.to_string exn
);
2254 state.pagecount
<- n;
2255 begin match state.currently
with
2257 state.currently
<- Idle
;
2258 state.outlines
<- Array.of_list
(List.rev
l)
2262 let cur, cmds
= state.geomcmds
in
2263 if String.length
cur = 0
2264 then failwith
"umpossible";
2266 begin match List.rev cmds
with
2268 state.geomcmds
<- "", [];
2272 state.geomcmds
<- s, List.rev rest
;
2274 if conf.maxwait
= None
2275 then G.postRedisplay "continue";
2285 then showtext ' '
args
2288 let progress, text =
2290 Scanf.sscanf
args "%f %n"
2292 f, String.sub
args pos
(String.length
args - pos
))
2294 dolog "error processing 'progress' %S: %s"
2295 cmds
(Printexc.to_string exn
);
2299 state.progress <- progress;
2300 G.postRedisplay "progress"
2303 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2305 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2306 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2307 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2309 dolog "error processing 'firstmatch' %S: %s"
2310 cmds
(Printexc.to_string exn
);
2313 let y = (getpagey pageno) + truncate
y0 in
2316 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
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 'match' %S: %s"
2326 cmds
(Printexc.to_string exn
);
2330 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2335 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2337 dolog "error processing 'page' %S: %s"
2338 cmds
(Printexc.to_string exn
);
2341 begin match state.currently
with
2342 | Loading
(l, gen
) ->
2343 vlog "page %d took %f sec" l.pageno t
;
2344 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2345 begin match state.throttle
with
2347 let preloadedpages =
2349 then preloadlayout state.y
2354 Set.Make
(struct type t
= int let compare = (-) end) in
2356 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2357 IntSet.empty
preloadedpages
2360 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2361 if not
(IntSet.mem
pageno set)
2363 wcmd "freepage %s" opaque
;
2369 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2372 state.currently
<- Idle
;
2375 tilepage l.pageno pageopaque state.layout;
2377 load preloadedpages;
2378 if pagevisible state.layout l.pageno
2379 && layoutready state.layout
2380 then G.postRedisplay "page";
2383 | Some
(layout, _, _) ->
2384 state.currently
<- Idle
;
2385 tilepage l.pageno pageopaque layout;
2390 dolog "Inconsistent loading state";
2391 logcurrently state.currently
;
2396 let (x, y, opaque
, size
, t
) =
2398 Scanf.sscanf
args "%u %u %s %u %f"
2399 (fun x y p size t
-> (x, y, p
, size
, t
))
2401 dolog "error processing 'tile' %S: %s"
2402 cmds
(Printexc.to_string exn
);
2405 begin match state.currently
with
2406 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2407 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2410 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2412 wcmd "freetile %s" opaque
;
2413 state.currently
<- Idle
;
2417 puttileopaque l col row gen cs angle opaque size t
;
2418 state.memused
<- state.memused
+ size
;
2419 state.uioh#infochanged Memused
;
2421 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2422 opaque
, size
) state.tilelru
;
2425 match state.throttle
with
2426 | None
-> state.layout
2427 | Some
(layout, _, _) -> layout
2430 state.currently
<- Idle
;
2432 && conf.colorspace
= cs
2433 && conf.angle
= angle
2434 && tilevisible layout l.pageno x y
2435 then conttiling l.pageno pageopaque;
2437 begin match state.throttle
with
2439 state.wthack
<- false;
2440 preload state.layout;
2442 && conf.colorspace
= cs
2443 && conf.angle
= angle
2444 && tilevisible state.layout l.pageno x y
2445 then G.postRedisplay "tile nothrottle";
2447 | Some
(layout, y, _) ->
2448 let ready = layoutready layout in
2451 state.wthack
<- false;
2453 state.layout <- layout;
2454 state.throttle
<- None
;
2455 G.postRedisplay "throttle";
2462 dolog "Inconsistent tiling state";
2463 logcurrently state.currently
;
2470 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2472 dolog "error processing 'pdim' %S: %s"
2473 cmds
(Printexc.to_string exn
);
2476 state.uioh#infochanged Pdim
;
2477 state.pdims
<- pdim :: state.pdims
2480 let (l, n, t
, h, pos
) =
2482 Scanf.sscanf
args "%u %u %d %u %n"
2483 (fun l n t
h pos
-> l, n, t
, h, pos
)
2485 dolog "error processing 'o' %S: %s"
2486 cmds
(Printexc.to_string exn
);
2489 let s = String.sub
args pos
(String.length
args - pos
) in
2490 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2491 begin match state.currently
with
2492 | Outlining outlines
->
2493 state.currently
<- Outlining
(outline :: outlines
)
2495 state.currently
<- Outlining
[outline]
2497 dolog "invalid outlining state";
2498 logcurrently currently
2502 state.docinfo
<- (1, args) :: state.docinfo
2505 state.uioh#infochanged Docinfo
;
2506 state.docinfo
<- List.rev
state.docinfo
2509 dolog "unknown cmd `%S'" cmds
2514 let action = function
2515 | HCprev
-> cbget cb ~
-1
2516 | HCnext
-> cbget cb
1
2517 | HCfirst
-> cbget cb ~
-(cb
.rc)
2518 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2519 and cancel
() = cb
.rc <- rc
2523 let search pattern forward
=
2524 if String.length pattern
> 0
2527 match state.layout with
2530 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2532 wcmd "search %d %d %d %d,%s\000"
2533 (btod conf.icase
) pn py
(btod forward
) pattern
;
2536 let intentry text key =
2538 if key >= 32 && key < 127
2544 let text = addchar text c in
2548 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2552 let linknentry text key =
2554 if key >= 32 && key < 127
2560 let text = addchar text c in
2564 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2569 if String.length
s > 0
2572 let l = String.length
s in
2573 let rec loop pos
n = if pos
= l then n else
2574 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2575 loop (pos
+1) (n*26 + m)
2578 let rec loop n = function
2581 match getopaque l.pageno with
2582 | None
-> loop n rest
2584 let m = getlinkcount opaque
in
2587 let under = getlink opaque
n in
2590 else loop (n-m) rest
2592 loop n state.layout;
2596 let textentry text key =
2597 if key land 0xff00 = 0xff00
2599 else TEcont
(text ^
Wsi.toutf8
key)
2602 let reqlayout angle proportional
=
2603 match state.throttle
with
2605 if nogeomcmds state.geomcmds
2606 then state.anchor <- getanchor ();
2607 conf.angle
<- angle
mod 360;
2610 match state.mode
with
2611 | LinkNav
_ -> state.mode
<- View
2614 conf.proportional
<- proportional
;
2615 invalidate "reqlayout"
2616 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2620 let settrim trimmargins trimfuzz
=
2621 if nogeomcmds state.geomcmds
2622 then state.anchor <- getanchor ();
2623 conf.trimmargins
<- trimmargins
;
2624 conf.trimfuzz
<- trimfuzz
;
2625 let x0, y0, x1, y1 = trimfuzz
in
2626 invalidate "settrim"
2628 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2633 match state.throttle
with
2635 let zoom = max
0.01 zoom in
2636 if zoom <> conf.zoom
2638 state.prevzoom
<- conf.zoom;
2640 reshape conf.winw
conf.winh
;
2641 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2644 | Some
(layout, y, started
) ->
2646 match conf.maxwait
with
2650 let dt = now () -. started
in
2658 let setcolumns mode columns coverA coverB
=
2659 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2663 then showtext '
!'
"split mode doesn't work in bird's eye"
2665 conf.columns
<- Csplit
(-columns
, [||]);
2673 conf.columns
<- Csingle
[||];
2678 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2682 reshape conf.winw
conf.winh
;
2685 let enterbirdseye () =
2686 let zoom = float conf.thumbw
/. float conf.winw
in
2687 let birdseyepageno =
2688 let cy = conf.winh
/ 2 in
2692 let rec fold best
= function
2695 let d = cy - (l.pagedispy + l.pagevh/2)
2696 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2697 if abs
d < abs dbest
2704 state.mode
<- Birdseye
(
2705 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2708 conf.presentation
<- false;
2709 conf.interpagespace
<- 10;
2710 conf.hlinks
<- false;
2712 state.mstate
<- Mnone
;
2713 conf.maxwait
<- None
;
2715 match conf.beyecolumns
with
2718 Cmulti
((c, 0, 0), [||])
2719 | None
-> Csingle
[||]
2721 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2724 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2729 reshape conf.winw
conf.winh
;
2732 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2734 conf.zoom <- c.zoom;
2735 conf.presentation
<- c.presentation
;
2736 conf.interpagespace
<- c.interpagespace
;
2737 conf.maxwait
<- c.maxwait
;
2738 conf.hlinks
<- c.hlinks
;
2739 conf.beyecolumns
<- (
2740 match conf.columns
with
2741 | Cmulti
((c, _, _), _) -> Some
c
2743 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2746 match c.columns
with
2747 | Cmulti
(c, _) -> Cmulti
(c, [||])
2748 | Csingle
_ -> Csingle
[||]
2749 | Csplit
(c, _) -> Csplit
(c, [||])
2754 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2757 reshape conf.winw
conf.winh
;
2758 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2761 let togglebirdseye () =
2762 match state.mode
with
2763 | Birdseye vals
-> leavebirdseye vals
true
2764 | View
-> enterbirdseye ()
2768 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2769 let pageno = max
0 (pageno - incr
) in
2770 let rec loop = function
2771 | [] -> gotopage1 pageno 0
2772 | l :: _ when l.pageno = pageno ->
2773 if l.pagedispy >= 0 && l.pagey = 0
2774 then G.postRedisplay "upbirdseye"
2775 else gotopage1 pageno 0
2776 | _ :: rest
-> loop rest
2779 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2782 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2783 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2784 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2785 let rec loop = function
2787 let y, h = getpageyh pageno in
2788 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2790 | l :: _ when l.pageno = pageno ->
2791 if l.pagevh != l.pageh
2792 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2793 else G.postRedisplay "downbirdseye"
2794 | _ :: rest
-> loop rest
2799 let optentry mode
_ key =
2800 let btos b = if b then "on" else "off" in
2801 if key >= 32 && key < 127
2803 let c = Char.chr
key in
2807 try conf.scrollstep
<- int_of_string
s with exc
->
2808 state.text <- Printf.sprintf
"bad integer `%s': %s"
2809 s (Printexc.to_string exc
)
2811 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2816 conf.autoscrollstep
<- int_of_string
s;
2817 if state.autoscroll
<> None
2818 then state.autoscroll
<- Some
conf.autoscrollstep
2820 state.text <- Printf.sprintf
"bad integer `%s': %s"
2821 s (Printexc.to_string exc
)
2823 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2828 let n, a, b = multicolumns_of_string s in
2829 setcolumns mode
n a b;
2831 state.text <- Printf.sprintf
"bad columns `%s': %s"
2832 s (Printexc.to_string exc
)
2834 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2839 let zoom = float (int_of_string
s) /. 100.0 in
2842 state.text <- Printf.sprintf
"bad integer `%s': %s"
2843 s (Printexc.to_string exc
)
2845 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2850 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2852 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2853 begin match mode
with
2855 leavebirdseye beye
false;
2860 state.text <- Printf.sprintf
"bad integer `%s': %s"
2861 s (Printexc.to_string exc
)
2863 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2868 Some
(int_of_string
s)
2870 state.text <- Printf.sprintf
"bad integer `%s': %s"
2871 s (Printexc.to_string exc
);
2874 | Some angle
-> reqlayout angle
conf.proportional
2877 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2880 conf.icase
<- not
conf.icase
;
2881 TEdone
("case insensitive search " ^
(btos conf.icase
))
2884 conf.preload <- not
conf.preload;
2886 TEdone
("preload " ^
(btos conf.preload))
2889 conf.verbose
<- not
conf.verbose
;
2890 TEdone
("verbose " ^
(btos conf.verbose
))
2893 conf.debug
<- not
conf.debug
;
2894 TEdone
("debug " ^
(btos conf.debug
))
2897 conf.maxhfit
<- not
conf.maxhfit
;
2898 state.maxy
<- calcheight ();
2899 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2902 conf.crophack
<- not
conf.crophack
;
2903 TEdone
("crophack " ^
btos conf.crophack
)
2907 match conf.maxwait
with
2909 conf.maxwait
<- Some infinity
;
2910 "always wait for page to complete"
2912 conf.maxwait
<- None
;
2913 "show placeholder if page is not ready"
2918 conf.underinfo
<- not
conf.underinfo
;
2919 TEdone
("underinfo " ^
btos conf.underinfo
)
2922 conf.savebmarks
<- not
conf.savebmarks
;
2923 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2929 match state.layout with
2934 conf.interpagespace
<- int_of_string
s;
2935 docolumns conf.columns
;
2936 state.maxy
<- calcheight ();
2937 let y = getpagey pageno in
2940 state.text <- Printf.sprintf
"bad integer `%s': %s"
2941 s (Printexc.to_string exc
)
2943 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2946 reqlayout conf.angle
(not
conf.proportional
);
2947 TEdone
("proportional display " ^
btos conf.proportional
)
2950 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2951 TEdone
("trim margins " ^
btos conf.trimmargins
)
2954 conf.invert
<- not
conf.invert
;
2955 TEdone
("invert colors " ^
btos conf.invert
)
2959 cbput state.hists
.sel
s;
2962 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2963 textentry, ondone, true)
2966 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2972 class type lvsource
= object
2973 method getitemcount
: int
2974 method getitem
: int -> (string * int)
2975 method hasaction
: int -> bool
2984 method getactive
: int
2985 method getfirst
: int
2986 method getqsearch
: string
2987 method setqsearch
: string -> unit
2991 class virtual lvsourcebase
= object
2992 val mutable m_active
= 0
2993 val mutable m_first
= 0
2994 val mutable m_qsearch
= ""
2995 val mutable m_pan
= 0
2996 method getactive
= m_active
2997 method getfirst
= m_first
2998 method getqsearch
= m_qsearch
2999 method getpan
= m_pan
3000 method setqsearch
s = m_qsearch
<- s
3003 let withoutlastutf8 s =
3004 let len = String.length
s in
3012 let b = Char.code
s.[pos
] in
3013 if b land 0b11000000 = 0b11000000
3018 if Char.code
s.[len-1] land 0x80 = 0
3022 String.sub
s 0 first;
3025 let textentrykeyboard
3026 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3028 if key >= 0xffb0 && key <= 0xffb9
3029 then key - 0xffb0 + 48 else key
3032 state.mode
<- Textentry
(te
, onleave
);
3035 G.postRedisplay "textentrykeyboard enttext";
3037 let histaction cmd
=
3040 | Some
(action, _) ->
3041 state.mode
<- Textentry
(
3042 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3044 G.postRedisplay "textentry histaction"
3047 | 0xff08 -> (* backspace *)
3048 let s = withoutlastutf8 text in
3049 let len = String.length
s in
3050 if cancelonempty
&& len = 0
3053 G.postRedisplay "textentrykeyboard after cancel";
3056 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3059 | 0xff0d | 0xff8d -> (* (kp) enter *)
3062 G.postRedisplay "textentrykeyboard after confirm"
3064 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3065 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3066 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3067 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3069 | 0xff1b -> (* escape*)
3070 if String.length
text = 0
3072 begin match opthist
with
3074 | Some
(_, onhistcancel
) -> onhistcancel
()
3078 G.postRedisplay "textentrykeyboard after cancel2"
3081 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3084 | 0xff9f | 0xffff -> () (* delete *)
3087 && key land 0xff00 != 0xff00 (* keyboard *)
3088 && key land 0xfe00 != 0xfe00 (* xkb *)
3089 && key land 0xfd00 != 0xfd00 (* 3270 *)
3091 begin match onkey
text key with
3095 G.postRedisplay "textentrykeyboard after confirm2";
3098 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3102 G.postRedisplay "textentrykeyboard after cancel3"
3105 state.mode
<- Textentry
(te
, onleave
);
3106 G.postRedisplay "textentrykeyboard switch";
3110 vlog "unhandled key %s" (Wsi.keyname
key)
3113 let firstof first active
=
3114 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3115 then max
0 (active
- (fstate.maxrows
/2))
3119 let calcfirst first active
=
3122 let rows = active
- first in
3123 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3127 let scrollph y maxy
=
3128 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3129 let sh = float conf.winh
/. sh in
3130 let sh = max
sh (float conf.scrollh
) in
3135 else float y /. float maxy
3137 let position = (float conf.winh
-. sh) *. percent in
3140 if position +. sh > float conf.winh
3141 then float conf.winh
-. sh
3147 let coe s = (s :> uioh
);;
3149 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3151 val m_pan
= source#getpan
3152 val m_first
= source#getfirst
3153 val m_active
= source#getactive
3154 val m_qsearch
= source#getqsearch
3155 val m_prev_uioh
= state.uioh
3157 method private elemunder
y =
3158 let n = y / (fstate.fontsize
+1) in
3159 if m_first
+ n < source#getitemcount
3161 if source#hasaction
(m_first
+ n)
3162 then Some
(m_first
+ n)
3169 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3170 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3171 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3172 GlDraw.color
(1., 1., 1.);
3173 Gl.enable `texture_2d
;
3174 let fs = fstate.fontsize
in
3176 let ww = fstate.wwidth
in
3177 let tabw = 30.0*.ww in
3178 let itemcount = source#getitemcount
in
3180 if (row - m_first
) > fstate.maxrows
3183 if row >= 0 && row < itemcount
3185 let (s, level
) = source#getitem
row in
3186 let y = (row - m_first
) * nfs in
3187 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3190 Gl.disable `texture_2d
;
3191 GlDraw.polygon_mode `both `line
;
3192 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3193 GlDraw.rect (1., float (y + 1))
3194 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3195 GlDraw.polygon_mode `both `fill
;
3196 GlDraw.color
(1., 1., 1.);
3197 Gl.enable `texture_2d
;
3200 let drawtabularstring s =
3201 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3204 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3207 let len = String.length
s - tabpos - 1 in
3208 let s1 = String.sub
s 0 tabpos
3209 and s2
= String.sub
s (tabpos + 1) len in
3210 let nx = drawstr x s1 in
3212 let x = x +. (max
tabw sw) in
3219 let _ = drawtabularstring s in
3226 Gl.disable `texture_2d
;
3228 method updownlevel incr
=
3229 let len = source#getitemcount
in
3231 if m_active
>= 0 && m_active
< len
3232 then snd
(source#getitem m_active
)
3236 if i
= len then i
-1 else if i
= -1 then 0 else
3237 let _, l = source#getitem i
in
3238 if l != curlevel then i
else flow (i
+incr
)
3240 let active = flow m_active
in
3241 let first = calcfirst m_first
active in
3242 G.postRedisplay "outline updownlevel";
3243 {< m_active
= active; m_first
= first >}
3245 method private key1
key mask
=
3246 let set1 active first qsearch
=
3247 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3249 let search active pattern incr
=
3252 if n >= 0 && n < source#getitemcount
3254 let s, _ = source#getitem
n in
3256 (try ignore
(Str.search_forward
re s 0); true
3257 with Not_found
-> false)
3259 else loop (n + incr
)
3266 let re = Str.regexp_case_fold pattern
in
3272 let itemcount = source#getitemcount
in
3273 let find start incr
=
3275 if i
= -1 || i
= itemcount
3278 if source#hasaction i
3280 else find (i
+ incr
)
3285 let set active first =
3286 let first = bound first 0 (itemcount - fstate.maxrows
) in
3288 coe {< m_active
= active; m_first
= first >}
3291 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3293 let incr1 = if incr
> 0 then 1 else -1 in
3294 if isvisible m_first m_active
3297 let next = m_active
+ incr
in
3299 if next < 0 || next >= itemcount
3301 else find next incr1
3303 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3309 let first = m_first
+ incr
in
3310 let first = bound first 0 (itemcount - 1) in
3312 let next = m_active
+ incr
in
3313 let next = bound next 0 (itemcount - 1) in
3316 let active = if next = -1 then m_active
else next in
3319 let first = min
next m_first
in
3321 if abs
(next - first) > fstate.maxrows
3327 let first = m_first
+ incr
in
3328 let first = bound first 0 (itemcount - 1) in
3330 let next = m_active
+ incr
in
3331 let next = bound next 0 (itemcount - 1) in
3332 let next = find next incr1 in
3334 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3336 let active = if m_active
= -1 then next else m_active
in
3341 if isvisible first active
3347 G.postRedisplay "listview navigate";
3351 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3352 let incr = if key = 0x72 then -1 else 1 in
3354 match search (m_active
+ incr) m_qsearch
incr with
3356 state.text <- m_qsearch ^
" [not found]";
3359 state.text <- m_qsearch
;
3360 active, firstof m_first
active
3362 G.postRedisplay "listview ctrl-r/s";
3363 set1 active first m_qsearch
;
3365 | 0xff08 -> (* backspace *)
3366 if String.length m_qsearch
= 0
3369 let qsearch = withoutlastutf8 m_qsearch
in
3370 let len = String.length
qsearch in
3374 G.postRedisplay "listview empty qsearch";
3375 set1 m_active m_first
"";
3379 match search m_active
qsearch ~
-1 with
3381 state.text <- qsearch ^
" [not found]";
3384 state.text <- qsearch;
3385 active, firstof m_first
active
3387 G.postRedisplay "listview backspace qsearch";
3388 set1 active first qsearch
3391 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3392 let pattern = m_qsearch ^
Wsi.toutf8
key in
3394 match search m_active
pattern 1 with
3396 state.text <- pattern ^
" [not found]";
3399 state.text <- pattern;
3400 active, firstof m_first
active
3402 G.postRedisplay "listview qsearch add";
3403 set1 active first pattern;
3405 | 0xff1b -> (* escape *)
3407 if String.length m_qsearch
= 0
3409 G.postRedisplay "list view escape";
3412 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3414 | None
-> m_prev_uioh
3419 G.postRedisplay "list view kill qsearch";
3420 source#setqsearch
"";
3421 coe {< m_qsearch
= "" >}
3424 | 0xff0d | 0xff8d -> (* (kp) enter *)
3426 let self = {< m_qsearch
= "" >} in
3427 source#setqsearch
"";
3429 G.postRedisplay "listview enter";
3430 if m_active
>= 0 && m_active
< source#getitemcount
3432 source#exit
(coe self) false m_active m_first m_pan
"";
3435 source#exit
(coe self) true m_active m_first m_pan
"";
3438 begin match opt with
3439 | None
-> m_prev_uioh
3443 | 0xff9f | 0xffff -> (* (kp) delete *)
3446 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3447 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3448 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3449 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3451 | 0xff53 | 0xff98 -> (* (kp) right *)
3453 G.postRedisplay "listview right";
3454 coe {< m_pan
= m_pan
- 1 >}
3456 | 0xff51 | 0xff96 -> (* (kp) left *)
3458 G.postRedisplay "listview left";
3459 coe {< m_pan
= m_pan
+ 1 >}
3461 | 0xff50 | 0xff95 -> (* (kp) home *)
3462 let active = find 0 1 in
3463 G.postRedisplay "listview home";
3466 | 0xff57 | 0xff9c -> (* (kp) end *)
3467 let first = max
0 (itemcount - fstate.maxrows
) in
3468 let active = find (itemcount - 1) ~
-1 in
3469 G.postRedisplay "listview end";
3472 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3476 dolog "listview unknown key %#x" key; coe self
3478 method key key mask
=
3479 match state.mode
with
3480 | Textentry te
-> textentrykeyboard key mask te
; coe self
3481 | _ -> self#key1
key mask
3483 method button button down
x y _ =
3486 | 1 when x > conf.winw
- conf.scrollbw
->
3487 G.postRedisplay "listview scroll";
3490 let _, position, sh = self#
scrollph in
3491 if y > truncate
position && y < truncate
(position +. sh)
3493 state.mstate
<- Mscrolly
;
3497 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3498 let first = truncate
(s *. float source#getitemcount
) in
3499 let first = min source#getitemcount
first in
3500 Some
(coe {< m_first
= first; m_active
= first >})
3502 state.mstate
<- Mnone
;
3505 | 1 when not down
->
3506 begin match self#elemunder
y with
3508 G.postRedisplay "listview click";
3510 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3514 | n when (n == 4 || n == 5) && not down
->
3515 let len = source#getitemcount
in
3517 if n = 5 && m_first
+ fstate.maxrows
>= len
3521 let first = m_first
+ (if n == 4 then -1 else 1) in
3522 bound first 0 (len - 1)
3524 G.postRedisplay "listview wheel";
3525 Some
(coe {< m_first
= first >})
3526 | n when (n = 6 || n = 7) && not down
->
3527 let inc = m_first
+ (if n = 7 then -1 else 1) in
3528 G.postRedisplay "listview hwheel";
3529 Some
(coe {< m_pan
= m_pan
+ inc >})
3534 | None
-> m_prev_uioh
3538 match state.mstate
with
3540 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3541 let first = truncate
(s *. float source#getitemcount
) in
3542 let first = min source#getitemcount
first in
3543 G.postRedisplay "listview motion";
3544 coe {< m_first
= first; m_active
= first >}
3547 method pmotion
x y =
3548 if x < conf.winw
- conf.scrollbw
3551 match self#elemunder
y with
3552 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3553 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3557 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3562 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3566 method infochanged
_ = ()
3568 method scrollpw
= (0, 0.0, 0.0)
3570 let nfs = fstate.fontsize
+ 1 in
3571 let y = m_first
* nfs in
3572 let itemcount = source#getitemcount
in
3573 let maxi = max
0 (itemcount - fstate.maxrows
) in
3574 let maxy = maxi * nfs in
3575 let p, h = scrollph y maxy in
3578 method modehash
= modehash
3581 class outlinelistview ~source
=
3584 ~source
:(source
:> lvsource
)
3586 ~modehash
:(findkeyhash conf "outline")
3589 method key key mask
=
3590 let calcfirst first active =
3593 let rows = active - first in
3595 if String.length
state.text = 0
3597 else fstate.maxrows - 2
3599 if rows > maxrows then active - maxrows else first
3603 let active = m_active
+ incr in
3604 let active = bound active 0 (source#getitemcount
- 1) in
3605 let first = calcfirst m_first
active in
3606 G.postRedisplay "outline navigate";
3607 coe {< m_active
= active; m_first
= first >}
3609 let ctrl = Wsi.withctrl mask
in
3611 | 110 when ctrl -> (* ctrl-n *)
3612 source#narrow m_qsearch
;
3613 G.postRedisplay "outline ctrl-n";
3614 coe {< m_first
= 0; m_active
= 0 >}
3616 | 117 when ctrl -> (* ctrl-u *)
3618 G.postRedisplay "outline ctrl-u";
3620 coe {< m_first
= 0; m_active
= 0 >}
3622 | 108 when ctrl -> (* ctrl-l *)
3623 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3624 G.postRedisplay "outline ctrl-l";
3625 coe {< m_first
= first >}
3627 | 0xff9f | 0xffff -> (* (kp) delete *)
3628 source#remove m_active
;
3629 G.postRedisplay "outline delete";
3630 let active = max
0 (m_active
-1) in
3631 coe {< m_first
= firstof m_first
active;
3632 m_active
= active >}
3634 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3635 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3636 | 0xff55 | 0xff9a -> (* (kp) prior *)
3637 navigate ~
-(fstate.maxrows)
3638 | 0xff56 | 0xff9b -> (* (kp) next *)
3639 navigate fstate.maxrows
3641 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3645 G.postRedisplay "outline ctrl right";
3646 {< m_pan
= m_pan
+ 1 >}
3648 else self#updownlevel
1
3652 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3656 G.postRedisplay "outline ctrl left";
3657 {< m_pan
= m_pan
- 1 >}
3659 else self#updownlevel ~
-1
3663 | 0xff50 | 0xff95 -> (* (kp) home *)
3664 G.postRedisplay "outline home";
3665 coe {< m_first
= 0; m_active
= 0 >}
3667 | 0xff57 | 0xff9c -> (* (kp) end *)
3668 let active = source#getitemcount
- 1 in
3669 let first = max
0 (active - fstate.maxrows) in
3670 G.postRedisplay "outline end";
3671 coe {< m_active
= active; m_first
= first >}
3673 | _ -> super#
key key mask
3676 let outlinesource usebookmarks
=
3679 inherit lvsourcebase
3680 val mutable m_items
= empty
3681 val mutable m_orig_items
= empty
3682 val mutable m_prev_items
= empty
3683 val mutable m_narrow_pattern
= ""
3684 val mutable m_hadremovals
= false
3686 method getitemcount
=
3687 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3690 if n == Array.length m_items
&& m_hadremovals
3692 ("[Confirm removal]", 0)
3694 let s, n, _ = m_items
.(n) in
3697 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3698 ignore
(uioh
, first, qsearch);
3699 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3701 if String.length m_narrow_pattern
= 0
3707 if not
confrimremoval
3709 let _, _, anchor = m_items
.(active) in
3710 gotoghyll (getanchory anchor);
3714 state.bookmarks
<- Array.to_list m_items
;
3715 m_orig_items
<- m_items
;
3718 else m_items
<- items;
3722 method hasaction
_ = true
3725 if Array.length m_items
!= Array.length m_orig_items
3726 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3729 method narrow
pattern =
3730 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3734 let rec loop accu n =
3737 m_narrow_pattern
<- pattern;
3738 m_items
<- Array.of_list
accu
3741 let (s, _, _) as o = m_items
.(n) in
3743 if (try ignore
(Str.search_forward
re s 0); true
3744 with Not_found
-> false)
3750 loop [] (Array.length m_items
- 1)
3755 then Array.of_list
state.bookmarks
3758 m_items
<- m_orig_items
3763 if m >= 0 && m < Array.length m_items
3765 m_hadremovals
<- true;
3766 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3767 let n = if n >= m then n+1 else n in
3772 method reset
anchor items =
3773 m_hadremovals
<- false;
3774 if m_orig_items
== empty || m_prev_items
!= items
3776 m_orig_items
<- items;
3777 if String.length m_narrow_pattern
= 0
3778 then m_items
<- items;
3780 m_prev_items
<- items;
3781 let rely = getanchory anchor in
3783 let rec loop n best bestd
=
3784 if n = Array.length m_items
3787 let (_, _, anchor) = m_items
.(n) in
3788 let orely = getanchory anchor in
3789 let d = abs
(orely - rely) in
3792 else loop (n+1) best bestd
3797 m_first
<- firstof m_first
active
3801 let enterselector usebookmarks
=
3802 let source = outlinesource usebookmarks
in
3806 then Array.of_list
state.bookmarks
3809 if Array.length
outlines = 0
3811 showtext ' ' errmsg
;
3814 state.text <- source#greetmsg
;
3815 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3816 let anchor = getanchor () in
3817 source#reset
anchor outlines;
3818 state.uioh
<- coe (new outlinelistview ~
source);
3819 G.postRedisplay "enter selector";
3823 let enteroutlinemode =
3824 let f = enterselector false in
3825 fun ()-> f "Document has no outline";
3828 let enterbookmarkmode =
3829 let f = enterselector true in
3830 fun () -> f "Document has no bookmarks (yet)";
3833 let color_of_string s =
3834 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3835 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3839 let color_to_string (r, g
, b) =
3840 let r = truncate
(r *. 256.0)
3841 and g
= truncate
(g
*. 256.0)
3842 and b = truncate
(b *. 256.0) in
3843 Printf.sprintf
"%d/%d/%d" r g
b
3846 let irect_of_string s =
3847 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3850 let irect_to_string (x0,y0,x1,y1) =
3851 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3854 let makecheckers () =
3855 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3857 converted by Issac Trotts. July 25, 2002 *)
3858 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3859 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3860 let id = GlTex.gen_texture
() in
3861 GlTex.bind_texture `texture_2d
id;
3862 GlPix.store
(`unpack_alignment
1);
3863 GlTex.image2d
image;
3864 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3867 `mag_filter `nearest
;
3868 `min_filter `nearest
];
3872 let setcheckers enabled
=
3873 match state.texid
with
3875 if enabled
then state.texid
<- Some
(makecheckers ())
3880 GlTex.delete_texture texid
;
3881 state.texid
<- None
;
3885 let int_of_string_with_suffix s =
3886 let l = String.length
s in
3890 let suffix = Char.lowercase
s.[l-1] in
3892 | 'k'
-> String.sub
s 0 (l-1), 10
3893 | '
m'
-> String.sub
s 0 (l-1), 20
3894 | 'g'
-> String.sub
s 0 (l-1), 30
3898 let n = int_of_string
s1 in
3899 let m = n lsl shift
in
3901 then raise
(Failure
"value too large")
3905 let string_with_suffix_of_int n =
3910 if n land ((1 lsl 30) - 1) = 0
3913 if n land ((1 lsl 20) - 1) = 0
3916 if n land ((1 lsl 10) - 1) = 0
3923 let h = n mod 1000 in
3926 then string_of_int
h ^
s
3928 let s = Printf.sprintf
"_%03d%s" h s in
3935 let defghyllscroll = (40, 8, 32);;
3936 let ghyllscroll_of_string s =
3937 let (n, a, b) as nab
=
3940 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3942 if n <= a || n <= b || a >= b
3943 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3947 let ghyllscroll_to_string ((n, a, b) as nab
) =
3948 if nab
= defghyllscroll
3950 else Printf.sprintf
"%d,%d,%d" n a b;
3953 let describe_location () =
3955 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3957 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3958 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3962 else (100. *. (float state.y /. float maxy))
3966 Printf.sprintf
"page %d of %d [%.2f%%]"
3967 (fn+1) state.pagecount
percent
3970 "pages %d-%d of %d [%.2f%%]"
3971 (fn+1) (ln
+1) state.pagecount
percent
3974 let setpresentationmode v
=
3975 let (n, _, _) = getanchor () in
3976 let _, h = getpageyh n in
3977 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
3978 state.anchor <- (n, 0.0, float ips);
3979 conf.presentation
<- v
;
3980 if conf.presentation
3982 if not
conf.scrollbarinpm
3983 then state.scrollw
<- 0;
3985 else state.scrollw
<- conf.scrollbw
;
3990 let btos b = if b then "\xe2\x88\x9a" else "" in
3991 let showextended = ref false in
3992 let leave mode
= function
3993 | Confirm
-> state.mode
<- mode
3994 | Cancel
-> state.mode
<- mode
in
3997 val mutable m_first_time
= true
3998 val mutable m_l
= []
3999 val mutable m_a
= [||]
4000 val mutable m_prev_uioh
= nouioh
4001 val mutable m_prev_mode
= View
4003 inherit lvsourcebase
4005 method reset prev_mode prev_uioh
=
4006 m_a
<- Array.of_list
(List.rev m_l
);
4008 m_prev_mode
<- prev_mode
;
4009 m_prev_uioh
<- prev_uioh
;
4013 if n >= Array.length m_a
4017 | _, _, _, Action
_ -> m_active
<- n
4021 m_first_time
<- false;
4024 method int name get
set =
4026 (name
, `
int get
, 1, Action
(
4029 try set (int_of_string
s)
4031 state.text <- Printf.sprintf
"bad integer `%s': %s"
4032 s (Printexc.to_string exn
)
4035 let te = name ^
": ", "", None
, intentry, ondone, true in
4036 state.mode
<- Textentry
(te, leave m_prev_mode
);
4040 method int_with_suffix name get
set =
4042 (name
, `intws get
, 1, Action
(
4045 try set (int_of_string_with_suffix s)
4047 state.text <- Printf.sprintf
"bad integer `%s': %s"
4048 s (Printexc.to_string exn
)
4052 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4054 state.mode
<- Textentry
(te, leave m_prev_mode
);
4058 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4060 (name
, `
bool (btos, get
), offset
, Action
(
4067 method color name get
set =
4069 (name
, `color get
, 1, Action
(
4071 let invalid = (nan
, nan
, nan
) in
4074 try color_of_string s
4076 state.text <- Printf.sprintf
"bad color `%s': %s"
4077 s (Printexc.to_string exn
);
4083 let te = name ^
": ", "", None
, textentry, ondone, true in
4084 state.text <- color_to_string (get
());
4085 state.mode
<- Textentry
(te, leave m_prev_mode
);
4089 method string name get
set =
4091 (name
, `
string get
, 1, Action
(
4093 let ondone s = set s in
4094 let te = name ^
": ", "", None
, textentry, ondone, true in
4095 state.mode
<- Textentry
(te, leave m_prev_mode
);
4099 method colorspace name get
set =
4101 (name
, `
string get
, 1, Action
(
4104 let vals = [| "rgb"; "bgr"; "gray" |] in
4106 inherit lvsourcebase
4109 m_active
<- int_of_colorspace conf.colorspace
;
4112 method getitemcount
= Array.length
vals
4113 method getitem
n = (vals.(n), 0)
4114 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4115 ignore
(uioh
, first, pan
, qsearch);
4116 if not cancel
then set active;
4118 method hasaction
_ = true
4122 let modehash = findkeyhash conf "info" in
4123 coe (new listview ~
source ~trusted
:true ~
modehash)
4126 method caption
s offset
=
4127 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4129 method caption2
s f offset
=
4130 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4132 method getitemcount
= Array.length m_a
4135 let tostr = function
4136 | `
int f -> string_of_int
(f ())
4137 | `intws
f -> string_with_suffix_of_int (f ())
4139 | `color
f -> color_to_string (f ())
4140 | `
bool (btos, f) -> btos (f ())
4143 let name, t
, offset
, _ = m_a
.(n) in
4144 ((let s = tostr t
in
4145 if String.length
s > 0
4146 then Printf.sprintf
"%s\t%s" name s
4150 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4154 m_qsearch
<- qsearch;
4156 match m_a
.(active) with
4157 | _, _, _, Action
f -> f uioh
4169 method hasaction
n =
4171 | _, _, _, Action
_ -> true
4175 let rec fillsrc prevmode prevuioh
=
4176 let sep () = src#caption
"" 0 in
4177 let colorp name get
set =
4179 (fun () -> color_to_string (get
()))
4182 let c = color_of_string v in
4185 state.text <- Printf.sprintf
"bad color `%s': %s"
4186 v (Printexc.to_string exn
);
4189 let oldmode = state.mode
in
4190 let birdseye = isbirdseye state.mode
in
4192 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4194 src#
bool "presentation mode"
4195 (fun () -> conf.presentation
)
4196 (fun v -> setpresentationmode v);
4198 src#
bool "ignore case in searches"
4199 (fun () -> conf.icase
)
4200 (fun v -> conf.icase
<- v);
4203 (fun () -> conf.preload)
4204 (fun v -> conf.preload <- v);
4206 src#
bool "highlight links"
4207 (fun () -> conf.hlinks
)
4208 (fun v -> conf.hlinks
<- v);
4210 src#
bool "under info"
4211 (fun () -> conf.underinfo
)
4212 (fun v -> conf.underinfo
<- v);
4214 src#
bool "persistent bookmarks"
4215 (fun () -> conf.savebmarks
)
4216 (fun v -> conf.savebmarks
<- v);
4218 src#
bool "proportional display"
4219 (fun () -> conf.proportional
)
4220 (fun v -> reqlayout conf.angle
v);
4222 src#
bool "trim margins"
4223 (fun () -> conf.trimmargins
)
4224 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4226 src#
bool "persistent location"
4227 (fun () -> conf.jumpback
)
4228 (fun v -> conf.jumpback
<- v);
4231 src#
int "inter-page space"
4232 (fun () -> conf.interpagespace
)
4234 conf.interpagespace
<- n;
4235 docolumns conf.columns
;
4237 match state.layout with
4242 state.maxy <- calcheight ();
4243 let y = getpagey pageno in
4248 (fun () -> conf.pagebias
)
4249 (fun v -> conf.pagebias
<- v);
4251 src#
int "scroll step"
4252 (fun () -> conf.scrollstep
)
4253 (fun n -> conf.scrollstep
<- n);
4255 src#
int "horizontal scroll step"
4256 (fun () -> conf.hscrollstep
)
4257 (fun v -> conf.hscrollstep
<- v);
4259 src#
int "auto scroll step"
4261 match state.autoscroll
with
4263 | _ -> conf.autoscrollstep
)
4265 if state.autoscroll
<> None
4266 then state.autoscroll
<- Some
n;
4267 conf.autoscrollstep
<- n);
4270 (fun () -> truncate
(conf.zoom *. 100.))
4271 (fun v -> setzoom ((float v) /. 100.));
4274 (fun () -> conf.angle
)
4275 (fun v -> reqlayout v conf.proportional
);
4277 src#
int "scroll bar width"
4278 (fun () -> state.scrollw
)
4282 reshape conf.winw
conf.winh
;
4285 src#
int "scroll handle height"
4286 (fun () -> conf.scrollh
)
4287 (fun v -> conf.scrollh
<- v;);
4289 src#
int "thumbnail width"
4290 (fun () -> conf.thumbw
)
4292 conf.thumbw
<- min
4096 v;
4295 leavebirdseye beye
false;
4300 let mode = state.mode in
4301 src#
string "columns"
4303 match conf.columns
with
4305 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4306 | Csplit
(count
, _) -> "-" ^ string_of_int count
4309 let n, a, b = multicolumns_of_string v in
4310 setcolumns mode n a b);
4313 src#caption
"Presentation mode" 0;
4314 src#
bool "scrollbar visible"
4315 (fun () -> conf.scrollbarinpm
)
4317 if v != conf.scrollbarinpm
4319 conf.scrollbarinpm
<- v;
4320 if conf.presentation
4322 state.scrollw
<- if v then conf.scrollbw
else 0;
4323 reshape conf.winw
conf.winh
;
4329 src#caption
"Pixmap cache" 0;
4330 src#int_with_suffix
"size (advisory)"
4331 (fun () -> conf.memlimit
)
4332 (fun v -> conf.memlimit
<- v);
4335 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4336 (string_with_suffix_of_int state.memused
)
4337 (Hashtbl.length
state.tilemap
)) 1;
4340 src#caption
"Layout" 0;
4341 src#caption2
"Dimension"
4343 Printf.sprintf
"%dx%d (virtual %dx%d)"
4349 src#caption2
"Position" (fun () ->
4350 Printf.sprintf
"%dx%d" state.x state.y
4353 src#caption2
"Visible" (fun () -> describe_location ()) 1
4357 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4358 "Save these parameters as global defaults at exit"
4359 (fun () -> conf.bedefault
)
4360 (fun v -> conf.bedefault
<- v)
4364 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4365 src#
bool ~offset
:0 ~
btos "Extended parameters"
4366 (fun () -> !showextended)
4367 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4371 (fun () -> conf.checkers
)
4372 (fun v -> conf.checkers
<- v; setcheckers v);
4373 src#
bool "update cursor"
4374 (fun () -> conf.updatecurs
)
4375 (fun v -> conf.updatecurs
<- v);
4377 (fun () -> conf.verbose
)
4378 (fun v -> conf.verbose
<- v);
4379 src#
bool "invert colors"
4380 (fun () -> conf.invert
)
4381 (fun v -> conf.invert
<- v);
4383 (fun () -> conf.maxhfit
)
4384 (fun v -> conf.maxhfit
<- v);
4385 src#
bool "redirect stderr"
4386 (fun () -> conf.redirectstderr)
4387 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4388 src#
string "uri launcher"
4389 (fun () -> conf.urilauncher
)
4390 (fun v -> conf.urilauncher
<- v);
4391 src#
string "path launcher"
4392 (fun () -> conf.pathlauncher
)
4393 (fun v -> conf.pathlauncher
<- v);
4394 src#
string "tile size"
4395 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4398 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4399 conf.tilew
<- max
64 w;
4400 conf.tileh
<- max
64 h;
4403 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4404 v (Printexc.to_string exn
));
4405 src#
int "texture count"
4406 (fun () -> conf.texcount
)
4409 then conf.texcount
<- v
4410 else showtext '
!'
" Failed to set texture count please retry later"
4412 src#
int "slice height"
4413 (fun () -> conf.sliceheight
)
4415 conf.sliceheight
<- v;
4416 wcmd "sliceh %d" conf.sliceheight
;
4418 src#
int "anti-aliasing level"
4419 (fun () -> conf.aalevel
)
4421 conf.aalevel
<- bound v 0 8;
4422 state.anchor <- getanchor ();
4423 opendoc state.path
state.password
;
4425 src#
string "page scroll scaling factor"
4426 (fun () -> string_of_float
conf.pgscale)
4429 let s = float_of_string
v in
4432 state.text <- Printf.sprintf
4433 "bad page scroll scaling factor `%s': %s"
4434 v (Printexc.to_string exn
)
4437 src#
int "ui font size"
4438 (fun () -> fstate.fontsize
)
4439 (fun v -> setfontsize (bound v 5 100));
4440 src#
int "hint font size"
4441 (fun () -> conf.hfsize
)
4442 (fun v -> conf.hfsize
<- bound v 5 100);
4443 colorp "background color"
4444 (fun () -> conf.bgcolor
)
4445 (fun v -> conf.bgcolor
<- v);
4446 src#
bool "crop hack"
4447 (fun () -> conf.crophack
)
4448 (fun v -> conf.crophack
<- v);
4449 src#
string "trim fuzz"
4450 (fun () -> irect_to_string conf.trimfuzz
)
4453 conf.trimfuzz
<- irect_of_string v;
4455 then settrim true conf.trimfuzz
;
4457 state.text <- Printf.sprintf
"bad irect `%s': %s"
4458 v (Printexc.to_string exn
)
4460 src#
string "throttle"
4462 match conf.maxwait
with
4463 | None
-> "show place holder if page is not ready"
4466 then "wait for page to fully render"
4468 "wait " ^ string_of_float
time
4469 ^
" seconds before showing placeholder"
4473 let f = float_of_string
v in
4475 then conf.maxwait
<- None
4476 else conf.maxwait
<- Some
f
4478 state.text <- Printf.sprintf
"bad time `%s': %s"
4479 v (Printexc.to_string exn
)
4481 src#
string "ghyll scroll"
4483 match conf.ghyllscroll
with
4485 | Some nab
-> ghyllscroll_to_string nab
4490 if String.length
v = 0
4492 else Some
(ghyllscroll_of_string v)
4494 conf.ghyllscroll
<- gs
4496 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4497 v (Printexc.to_string exn
)
4499 src#
string "selection command"
4500 (fun () -> conf.selcmd
)
4501 (fun v -> conf.selcmd
<- v);
4502 src#colorspace
"color space"
4503 (fun () -> colorspace_to_string conf.colorspace
)
4505 conf.colorspace
<- colorspace_of_int v;
4512 (fun () -> conf.usepbo
)
4513 (fun v -> conf.usepbo
<- v);
4514 src#
bool "mouse wheel scrolls pages"
4515 (fun () -> conf.wheelbypage
)
4516 (fun v -> conf.wheelbypage
<- v);
4520 src#caption
"Document" 0;
4521 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4522 src#caption2
"Pages"
4523 (fun () -> string_of_int
state.pagecount
) 1;
4524 src#caption2
"Dimensions"
4525 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4529 src#caption
"Trimmed margins" 0;
4530 src#caption2
"Dimensions"
4531 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4535 src#caption
"OpenGL" 0;
4536 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4537 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4538 src#reset prevmode prevuioh
;
4542 let prevmode = state.mode
4543 and prevuioh
= state.uioh in
4544 fillsrc prevmode prevuioh
;
4545 let source = (src :> lvsource
) in
4546 let modehash = findkeyhash conf "info" in
4547 state.uioh <- coe (object (self)
4548 inherit listview ~
source ~trusted
:true ~
modehash as super
4549 val mutable m_prevmemused
= 0
4550 method infochanged
= function
4552 if m_prevmemused
!= state.memused
4554 m_prevmemused
<- state.memused
;
4555 G.postRedisplay "memusedchanged";
4557 | Pdim
-> G.postRedisplay "pdimchanged"
4558 | Docinfo
-> fillsrc prevmode prevuioh
4560 method key key mask
=
4561 if not
(Wsi.withctrl mask
)
4564 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4565 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4566 | _ -> super#
key key mask
4567 else super#
key key mask
4569 G.postRedisplay "info";
4575 inherit lvsourcebase
4576 method getitemcount
= Array.length
state.help
4578 let s, l, _ = state.help
.(n) in
4581 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4585 m_qsearch
<- qsearch;
4586 match state.help
.(active) with
4587 | _, _, Action
f -> Some
(f uioh)
4597 method hasaction
n =
4598 match state.help
.(n) with
4599 | _, _, Action
_ -> true
4606 let modehash = findkeyhash conf "help" in
4607 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4608 G.postRedisplay "help";
4613 let re = Str.regexp
"[\r\n]" in
4615 inherit lvsourcebase
4616 val mutable m_items
= [||]
4618 method getitemcount
= 1 + Array.length m_items
4623 else m_items
.(n-1), 0
4625 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4630 then Buffer.clear
state.errmsgs
;
4631 m_qsearch
<- qsearch;
4638 method hasaction
n =
4642 state.newerrmsgs
<- false;
4643 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4644 m_items
<- Array.of_list
l
4652 let source = (msgsource :> lvsource
) in
4653 let modehash = findkeyhash conf "listview" in
4654 state.uioh <- coe (object
4655 inherit listview ~
source ~trusted
:false ~
modehash as super
4658 then msgsource#reset
;
4661 G.postRedisplay "msgs";
4664 let quickbookmark ?title
() =
4665 match state.layout with
4671 let sec = Unix.gettimeofday
() in
4672 let tm = Unix.localtime
sec in
4673 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4677 (tm.Unix.tm_year
+ 1900)
4680 | Some
title -> title
4682 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4686 state.fullscreen
<- None
;
4690 let setautoscrollspeed step goingdown
=
4691 let incr = max
1 ((abs step
) / 2) in
4692 let incr = if goingdown
then incr else -incr in
4693 let astep = step
+ incr in
4694 state.autoscroll
<- Some
astep;
4697 let gotounder = function
4698 | Ulinkgoto
(pageno, top) ->
4702 gotopage1 pageno top;
4708 | Uremote
(filename
, pageno) ->
4710 if Sys.file_exists filename
4713 let dir = Filename.dirname
state.path in
4714 let path = Filename.concat
dir filename
in
4715 if Sys.file_exists
path
4719 if String.length
path > 0
4721 let anchor = getanchor () in
4722 let ranchor = state.path, state.password
, anchor in
4723 state.anchor <- (pageno, 0.0, 0.0);
4724 state.ranchors
<- ranchor :: state.ranchors
;
4727 else showtext '
!'
("Could not find " ^ filename
)
4729 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4733 match conf.columns
with
4735 | _ -> conf.zoom > 1.0
4738 let existsinrow pageno (columns
, coverA
, coverB
) p =
4739 let last = ((pageno - coverA
) mod columns
) + columns
in
4740 let rec any = function
4743 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4747 then (if l.pageno = last then false else any rest
)
4755 match state.layout with
4758 match conf.columns
with
4760 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4762 let y = clamp (pgscale conf.winh
) in
4765 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4766 gotoghyll (getpagey pageno)
4767 | Cmulti
((c, _, _) as cl
, _) ->
4768 if conf.presentation
4769 && (existsinrow l.pageno cl
4770 (fun l -> l.pageh
> l.pagey + l.pagevh))
4772 let y = clamp (pgscale conf.winh
) in
4775 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4776 gotoghyll (getpagey pageno)
4778 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4780 let pagey, pageh
= getpageyh l.pageno in
4781 let pagey = pagey + pageh
* l.pagecol
in
4782 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4783 gotoghyll (pagey + pageh
+ ips)
4787 match state.layout with
4790 match conf.columns
with
4792 if conf.presentation
&& l.pagey != 0
4794 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4796 let pageno = max
0 (l.pageno-1) in
4797 gotoghyll (getpagey pageno)
4798 | Cmulti
((c, _, coverB
) as cl
, _) ->
4799 if conf.presentation
&&
4800 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4802 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4805 if l.pageno = state.pagecount
- coverB
4809 let pageno = max
0 (l.pageno-decr) in
4810 gotoghyll (getpagey pageno)
4818 let pageno = max
0 (l.pageno-1) in
4819 let pagey, pageh
= getpageyh pageno in
4822 let pagey, pageh
= getpageyh l.pageno in
4823 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4828 let viewkeyboard key mask
=
4830 let mode = state.mode in
4831 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4834 G.postRedisplay "view:enttext"
4836 let ctrl = Wsi.withctrl mask
in
4838 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4844 | 0xff63 -> (* insert *)
4845 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4847 state.mode <- LinkNav
(Ltgendir
0);
4850 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4852 | 0xff1b | 113 -> (* escape / q *)
4853 begin match state.mstate
with
4855 state.mstate
<- Mnone
;
4856 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4857 G.postRedisplay "kill zoom rect";
4859 begin match state.mode with
4862 G.postRedisplay "esc leave linknav"
4864 match state.ranchors
with
4866 | (path, password
, anchor) :: rest
->
4867 state.ranchors
<- rest
;
4868 state.anchor <- anchor;
4869 opendoc path password
4873 | 0xff08 -> (* backspace *)
4874 gotoghyll (getnav ~
-1)
4882 G.postRedisplay "dehighlight";
4884 | 47 | 63 -> (* / ? *)
4885 let ondone isforw
s =
4886 cbput state.hists
.pat
s;
4887 state.searchpattern
<- s;
4890 let s = String.create
1 in
4891 s.[0] <- Char.chr
key;
4892 enttext (s, "", Some
(onhist state.hists
.pat
),
4893 textentry, ondone (key = 47), true)
4895 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4896 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4897 setzoom (conf.zoom +. incr)
4899 | 43 | 0xffab -> (* + *)
4902 try int_of_string
s with exc
->
4903 state.text <- Printf.sprintf
"bad integer `%s': %s"
4904 s (Printexc.to_string exc
);
4910 state.text <- "page bias is now " ^ string_of_int
n;
4913 enttext ("page bias: ", "", None
, intentry, ondone, true)
4915 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4916 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4917 setzoom (max
0.01 (conf.zoom -. decr))
4919 | 45 | 0xffad -> (* - *)
4920 let ondone msg
= state.text <- msg
in
4922 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4923 optentry state.mode, ondone, true
4926 | 48 when ctrl -> (* ctrl-0 *)
4929 | 49 when ctrl -> (* ctrl-1 *)
4931 match conf.columns
with
4932 | Csingle
_ | Cmulti
_ -> 1
4933 | Csplit
(n, _) -> n
4935 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4939 | 0xffc6 -> (* f9 *)
4942 | 57 when ctrl -> (* ctrl-9 *)
4945 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4946 when not
ctrl -> (* 0..9 *)
4949 try int_of_string
s with exc
->
4950 state.text <- Printf.sprintf
"bad integer `%s': %s"
4951 s (Printexc.to_string exc
);
4957 cbput state.hists
.pag
(string_of_int
n);
4958 gotopage1 (n + conf.pagebias
- 1) 0;
4961 let pageentry text key =
4962 match Char.unsafe_chr
key with
4963 | 'g'
-> TEdone
text
4964 | _ -> intentry text key
4966 let text = "x" in text.[0] <- Char.chr
key;
4967 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4970 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4971 reshape conf.winw
conf.winh
;
4974 conf.hlinks
<- not
conf.hlinks
;
4975 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4976 G.postRedisplay "toggle highlightlinks";
4979 state.glinks
<- true;
4980 let mode = state.mode in
4981 state.mode <- Textentry
(
4982 (":", "", None
, linknentry, linkndone gotounder, false),
4984 state.glinks
<- false;
4988 G.postRedisplay "view:linkent(F)"
4991 state.glinks
<- true;
4992 let mode = state.mode in
4993 state.mode <- Textentry
(
4994 (":", "", None
, linknentry, linkndone (fun under ->
4995 match Ne.pipe () with
4997 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4998 (Printexc.to_string exn
));
5001 try popen conf.selcmd
[r, 0; w, -1]; true
5004 (Printf.sprintf
"failed to execute %s: %s"
5005 conf.selcmd
(Printexc.to_string exn
));
5009 Ne.clo fd
(fun msg
->
5010 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5013 let s = undertext under in
5017 let l = String.length
s in
5018 let n = Unix.write
w s 0 l in
5023 "failed to write %d characters to sel pipe, wrote %d"
5028 (Printf.sprintf
"failed to write to sel pipe: %s"
5029 (Printexc.to_string exn
)
5038 state.glinks
<- false;
5042 G.postRedisplay "view:linkent"
5045 begin match state.autoscroll
with
5047 conf.autoscrollstep
<- step
;
5048 state.autoscroll
<- None
5050 if conf.autoscrollstep
= 0
5051 then state.autoscroll
<- Some
1
5052 else state.autoscroll
<- Some
conf.autoscrollstep
5055 | 112 when ctrl -> (* ctrl-p *)
5059 setpresentationmode (not
conf.presentation
);
5060 showtext ' '
("presentation mode " ^
5061 if conf.presentation
then "on" else "off");
5064 begin match state.fullscreen
with
5066 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
5069 state.fullscreen
<- None
;
5073 | 112 | 78 -> (* p|N *)
5074 search state.searchpattern
false
5076 | 110 | 0xffc0 -> (* n|F3 *)
5077 search state.searchpattern
true
5080 begin match state.layout with
5083 gotoy_and_clear_text (getpagey l.pageno)
5089 | 0xff9f | 0xffff -> (* delete *)
5093 showtext ' '
(describe_location ());
5096 begin match state.layout with
5099 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5104 enterbookmarkmode ()
5106 | 104 | 0xffbe -> (* h|F1 *)
5112 | 101 when conf.redirectstderr -> (* e *)
5117 match state.layout with
5119 if String.length
s > 0
5121 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5124 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5128 showtext ' '
"Quick bookmark added";
5131 begin match state.layout with
5133 let rect = getpdimrect
l.pagedimno
in
5137 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5138 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5140 (truncate
(rect.(1) -. rect.(0)),
5141 truncate
(rect.(3) -. rect.(0)))
5143 let w = truncate
((float w)*.conf.zoom)
5144 and h = truncate
((float h)*.conf.zoom) in
5147 state.anchor <- getanchor ();
5148 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5150 G.postRedisplay "z";
5155 | 50 when ctrl -> (* ctrl-2 *)
5156 let maxw = getmaxw
() in
5158 then setzoom (maxw /. float conf.winw
)
5160 | 60 | 62 -> (* < > *)
5161 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5163 | 91 | 93 -> (* [ ] *)
5165 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5167 G.postRedisplay "brightness";
5169 | 99 when state.mode = View
-> (* c *)
5171 match state.prevcolumns
with
5172 | None
-> (1, 0, 0), 1.0
5173 | Some
(columns
, z
) ->
5176 | Csplit
(c, _) -> -c, 0, 0
5177 | Cmulti
((c, a, b), _) -> c, a, b
5178 | Csingle
_ -> 1, 0, 0
5182 setcolumns View
c a b;
5185 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5186 setzoom state.prevzoom
5188 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5189 begin match state.autoscroll
with
5191 begin match state.mode with
5192 | Birdseye beye
-> upbirdseye 1 beye
5195 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5196 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5199 setautoscrollspeed n false
5202 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5203 begin match state.autoscroll
with
5205 begin match state.mode with
5206 | Birdseye beye
-> downbirdseye 1 beye
5209 then gotoy_and_clear_text (clamp (conf.winh
/2))
5210 else gotoy_and_clear_text (clamp conf.scrollstep
)
5213 setautoscrollspeed n true
5216 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5222 else conf.hscrollstep
5224 let dx = if key = 0xff51 then dx else -dx in
5225 state.x <- state.x + dx;
5226 gotoy_and_clear_text state.y
5229 G.postRedisplay "lef/right"
5232 | 0xff55 | 0xff9a -> (* (kp) prior *)
5236 match state.layout with
5238 | l :: _ -> state.y - l.pagey
5240 clamp (pgscale (-conf.winh
))
5244 | 0xff56 | 0xff9b -> (* (kp) next *)
5248 match List.rev
state.layout with
5250 | l :: _ -> getpagey l.pageno
5252 clamp (pgscale conf.winh
)
5256 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5258 | 71 | 0xff57 | 0xff9c -> (* G end *)
5259 gotoghyll (clamp state.maxy)
5261 | 0xff53 when Wsi.withalt mask
-> (* alt-right *)
5262 gotoghyll (getnav 1)
5263 | 0xff51 when Wsi.withalt mask
-> (* alt-left *)
5264 gotoghyll (getnav ~
-1)
5269 | 118 when conf.debug
-> (* v *)
5272 match getopaque l.pageno with
5275 let x0, y0, x1, y1 = pagebbox opaque
in
5276 let a,b = float x0, float y0 in
5277 let c,d = float x1, float y0 in
5278 let e,f = float x1, float y1 in
5279 let h,j
= float x0, float y1 in
5280 let rect = (a,b,c,d,e,f,h,j
) in
5282 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5284 G.postRedisplay "v";
5287 vlog "huh? %s" (Wsi.keyname
key)
5290 let linknavkeyboard key mask
linknav =
5291 let getpage pageno =
5292 let rec loop = function
5294 | l :: _ when l.pageno = pageno -> Some
l
5295 | _ :: rest
-> loop rest
5296 in loop state.layout
5298 let doexact (pageno, n) =
5299 match getopaque pageno, getpage pageno with
5300 | Some opaque
, Some
l ->
5301 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5303 let under = getlink opaque
n in
5304 G.postRedisplay "link gotounder";
5310 | 0xff50 -> (* home *)
5311 Some
(findlink opaque LDfirst
), -1
5313 | 0xff57 -> (* end *)
5314 Some
(findlink opaque LDlast
), 1
5316 | 0xff51 -> (* left *)
5317 Some
(findlink opaque
(LDleft
n)), -1
5319 | 0xff53 -> (* right *)
5320 Some
(findlink opaque
(LDright
n)), 1
5322 | 0xff52 -> (* up *)
5323 Some
(findlink opaque
(LDup
n)), -1
5325 | 0xff54 -> (* down *)
5326 Some
(findlink opaque
(LDdown
n)), 1
5331 begin match findpwl
l.pageno dir with
5335 state.mode <- LinkNav
(Ltgendir
dir);
5336 let y, h = getpageyh pageno in
5339 then y + h - conf.winh
5344 begin match getopaque pageno, getpage pageno with
5345 | Some opaque
, Some
_ ->
5347 let ld = if dir > 0 then LDfirst
else LDlast
in
5350 begin match link with
5352 showlinktype (getlink opaque
m);
5353 state.mode <- LinkNav
(Ltexact
(pageno, m));
5354 G.postRedisplay "linknav jpage";
5361 begin match opt with
5362 | Some Lnotfound
-> pwl l dir;
5363 | Some
(Lfound
m) ->
5367 let _, y0, _, y1 = getlinkrect opaque
m in
5369 then gotopage1 l.pageno y0
5371 let d = fstate.fontsize
+ 1 in
5372 if y1 - l.pagey > l.pagevh - d
5373 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5374 else G.postRedisplay "linknav";
5376 showlinktype (getlink opaque
m);
5377 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5380 | None
-> viewkeyboard key mask
5382 | _ -> viewkeyboard key mask
5387 G.postRedisplay "leave linknav"
5391 | Ltgendir
_ -> viewkeyboard key mask
5392 | Ltexact exact
-> doexact exact
5395 let keyboard key mask
=
5396 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5397 then wcmd "interrupt"
5398 else state.uioh <- state.uioh#
key key mask
5401 let birdseyekeyboard key mask
5402 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5404 match conf.columns
with
5406 | Cmulti
((c, _, _), _) -> c
5407 | Csplit
_ -> failwith
"bird's eye split mode"
5409 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5411 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5412 let y, h = getpageyh pageno in
5413 let top = (conf.winh
- h) / 2 in
5414 gotoy (max
0 (y - top))
5415 | 0xff0d (* enter *)
5416 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5417 | 0xff1b -> leavebirdseye beye
true (* escape *)
5418 | 0xff52 -> upbirdseye incr beye
(* up *)
5419 | 0xff54 -> downbirdseye incr beye
(* down *)
5420 | 0xff51 -> upbirdseye 1 beye
(* left *)
5421 | 0xff53 -> downbirdseye 1 beye
(* right *)
5423 | 0xff55 -> (* prior *)
5424 begin match state.layout with
5428 state.mode <- Birdseye
(
5429 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5431 gotopage1 l.pageno 0;
5434 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5436 | [] -> gotoy (clamp (-conf.winh
))
5438 state.mode <- Birdseye
(
5439 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5441 gotopage1 l.pageno 0
5444 | [] -> gotoy (clamp (-conf.winh
))
5447 | 0xff56 -> (* next *)
5448 begin match List.rev
state.layout with
5450 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5451 begin match layout with
5453 let incr = l.pageh
- l.pagevh in
5458 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5460 G.postRedisplay "birdseye pagedown";
5462 else gotoy (clamp (incr + conf.interpagespace
*2));
5466 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5467 gotopage1 l.pageno 0;
5470 | [] -> gotoy (clamp conf.winh
)
5473 | 0xff50 -> (* home *)
5474 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5477 | 0xff57 -> (* end *)
5478 let pageno = state.pagecount
- 1 in
5479 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5480 if not
(pagevisible state.layout pageno)
5483 match List.rev
state.pdims
with
5485 | (_, _, h, _) :: _ -> h
5487 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5488 else G.postRedisplay "birdseye end";
5489 | _ -> viewkeyboard key mask
5492 let drawpage l linkindexbase
=
5494 match state.mode with
5495 | Textentry
_ -> scalecolor 0.4
5497 | View
-> scalecolor 1.0
5498 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5499 if l.pageno = hooverpageno
5502 if l.pageno = pageno
5508 begin match getopaque l.pageno with
5510 if tileready l l.pagex
l.pagey
5512 let x = l.pagedispx - l.pagex
5513 and y = l.pagedispy - l.pagey in
5515 match conf.columns
with
5516 | Csingle
_ | Cmulti
_ ->
5517 (if conf.hlinks
then 1 else 0)
5519 && not
(isbirdseye state.mode) then 2 else 0)
5523 match state.mode with
5524 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5527 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5534 let scrollindicator () =
5535 let sbw, ph
, sh = state.uioh#
scrollph in
5536 let sbh, pw, sw = state.uioh#scrollpw
in
5538 GlDraw.color (0.64, 0.64, 0.64);
5540 (float (conf.winw
- sbw), 0.)
5541 (float conf.winw
, float conf.winh
)
5544 (0., float (conf.winh
- sbh))
5545 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5547 GlDraw.color (0.0, 0.0, 0.0);
5550 (float (conf.winw
- sbw), ph
)
5551 (float conf.winw
, ph
+. sh)
5554 (pw, float (conf.winh
- sbh))
5555 (pw +. sw, float conf.winh
)
5560 match state.mstate
with
5561 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5564 | Msel
((x0, y0), (x1, y1)) ->
5565 let rec loop = function
5567 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5568 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5569 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5570 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5572 match getopaque l.pageno with
5574 let x0, y0 = pagetranslatepoint l x0 y0 in
5575 let x1, y1 = pagetranslatepoint l x1 y1 in
5576 seltext opaque
(x0, y0, x1, y1);
5584 let showrects rects
=
5586 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5587 GlDraw.polygon_mode `both `fill
;
5588 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5590 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5592 if l.pageno = pageno
5594 let dx = float (l.pagedispx - l.pagex
) in
5595 let dy = float (l.pagedispy - l.pagey) in
5596 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5597 GlDraw.begins `quads
;
5599 GlDraw.vertex2
(x0+.dx, y0+.dy);
5600 GlDraw.vertex2
(x1+.dx, y1+.dy);
5601 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5602 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5613 GlClear.color (scalecolor2 conf.bgcolor
);
5614 GlClear.clear
[`
color];
5615 let rec loop linkindexbase
= function
5617 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5618 loop linkindexbase rest
5621 loop 0 state.layout;
5623 match state.mode with
5624 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5625 begin match getopaque pageno with
5627 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5634 | None
-> state.rects
5641 begin match state.mstate
with
5642 | Mzoomrect
((x0, y0), (x1, y1)) ->
5644 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5645 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5646 GlDraw.rect (float x0, float y0)
5647 (float x1, float y1);
5653 if not
state.wthack
then Wsi.swapb
();
5656 let zoomrect x y x1 y1 =
5659 and y0 = min
y y1 in
5660 gotoy (state.y + y0);
5661 state.anchor <- getanchor ();
5662 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5664 if state.w < conf.winw
- state.scrollw
5665 then (conf.winw
- state.scrollw
- state.w) / 2
5668 state.x <- (state.x + margin) - x0;
5670 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5671 state.mstate
<- Mnone
;
5675 let winw = conf.winw - state.scrollw
- 1 in
5676 let s = float x /. float winw in
5677 let destx = truncate
(float (state.w + winw) *. s) in
5678 state.x <- winw - destx;
5679 gotoy_and_clear_text state.y;
5680 state.mstate
<- Mscrollx
;
5684 let s = float y /. float conf.winh
in
5685 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5686 gotoy_and_clear_text desty;
5687 state.mstate
<- Mscrolly
;
5690 let viewmouse button down
x y mask
=
5692 | n when (n == 4 || n == 5) && not down
->
5693 if Wsi.withctrl mask
5695 match state.mstate
with
5696 | Mzoom
(oldn
, i
) ->
5704 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5706 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5708 let zoom = conf.zoom -. incr in
5710 state.mstate
<- Mzoom
(n, 0);
5712 state.mstate
<- Mzoom
(n, i
+1);
5714 else state.mstate
<- Mzoom
(n, 0)
5716 | _ -> state.mstate
<- Mzoom
(n, 0)
5719 match state.autoscroll
with
5720 | Some step
-> setautoscrollspeed step
(n=4)
5731 then -conf.scrollstep
5732 else conf.scrollstep
5734 let incr = incr * 2 in
5735 let y = clamp incr in
5736 gotoy_and_clear_text y
5739 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5740 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5741 gotoy_and_clear_text state.y
5743 | 1 when Wsi.withctrl mask
->
5746 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5747 state.mstate
<- Mpan
(x, y)
5750 state.mstate
<- Mnone
5755 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5757 state.mstate
<- Mzoomrect
(p, p)
5760 match state.mstate
with
5761 | Mzoomrect
((x0, y0), _) ->
5762 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5763 then zoomrect x0 y0 x y
5765 state.mstate
<- Mnone
;
5766 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5767 G.postRedisplay "kill accidental zoom rect";
5770 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5771 state.mstate
<- Mnone
5774 | 1 when x > conf.winw - state.scrollw
->
5777 let _, position, sh = state.uioh#
scrollph in
5778 if y > truncate
position && y < truncate
(position +. sh)
5779 then state.mstate
<- Mscrolly
5782 state.mstate
<- Mnone
5784 | 1 when y > conf.winh
- state.hscrollh ->
5787 let _, position, sw = state.uioh#scrollpw
in
5788 if x > truncate
position && x < truncate
(position +. sw)
5789 then state.mstate
<- Mscrollx
5792 state.mstate
<- Mnone
5795 let dest = if down
then getunder x y else Unone
in
5796 begin match dest with
5800 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5803 | Unone
when down
->
5804 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5805 state.mstate
<- Mpan
(x, y);
5807 | Unone
| Utext
_ ->
5810 if conf.angle
mod 360 = 0
5812 state.mstate
<- Msel
((x, y), (x, y));
5813 G.postRedisplay "mouse select";
5817 match state.mstate
with
5820 | Mzoom
_ | Mscrollx
| Mscrolly
->
5821 state.mstate
<- Mnone
5823 | Mzoomrect
((x0, y0), _) ->
5827 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5828 state.mstate
<- Mnone
5830 | Msel
((x0, y0), (x1, y1)) ->
5831 let rec loop = function
5835 let a0 = l.pagedispy in
5836 let a1 = a0 + l.pagevh in
5837 let b0 = l.pagedispx in
5838 let b1 = b0 + l.pagevw in
5839 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5840 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5844 match getopaque l.pageno with
5847 match Ne.pipe () with
5851 "can not create sel pipe: %s"
5852 (Printexc.to_string exn
));
5854 let doclose what fd
=
5855 Ne.clo fd
(fun msg
->
5856 dolog "%s close failed: %s" what msg
)
5859 popen conf.selcmd
[r, 0; w, -1];
5862 G.postRedisplay "copysel";
5864 dolog "can not execute %S: %s"
5865 conf.selcmd
(Printexc.to_string exn
);
5873 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5874 state.mstate
<- Mnone
;
5881 let birdseyemouse button down
x y mask
5882 (conf, leftx
, _, hooverpageno
, anchor) =
5885 let rec loop = function
5888 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5889 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5891 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5897 | _ -> viewmouse button down
x y mask
5900 let mouse button down
x y mask
=
5901 state.uioh <- state.uioh#button button down
x y mask
;
5905 state.uioh <- state.uioh#
motion x y
5909 state.uioh <- state.uioh#
pmotion x y;
5915 method key key mask
=
5916 begin match state.mode with
5917 | Textentry
textentry -> textentrykeyboard key mask
textentry
5918 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5919 | View
-> viewkeyboard key mask
5920 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5924 method button button bstate
x y mask
=
5925 begin match state.mode with
5927 | View
-> viewmouse button bstate
x y mask
5928 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5934 begin match state.mode with
5936 | View
| Birdseye
_ | LinkNav
_ ->
5937 match state.mstate
with
5938 | Mzoom
_ | Mnone
-> ()
5943 state.mstate
<- Mpan
(x, y);
5945 then state.x <- state.x + dx;
5947 gotoy_and_clear_text y
5950 state.mstate
<- Msel
(a, (x, y));
5951 G.postRedisplay "motion select";
5954 let y = min
conf.winh
(max
0 y) in
5958 let x = min
conf.winw (max
0 x) in
5961 | Mzoomrect
(p0
, _) ->
5962 state.mstate
<- Mzoomrect
(p0
, (x, y));
5963 G.postRedisplay "motion zoomrect";
5967 method pmotion x y =
5968 begin match state.mode with
5969 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5970 let rec loop = function
5972 if hooverpageno
!= -1
5974 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5975 G.postRedisplay "pmotion birdseye no hoover";
5978 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5979 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5981 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5982 G.postRedisplay "pmotion birdseye hoover";
5992 match state.mstate
with
5993 | Mnone
-> updateunder x y
5994 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5999 method infochanged
_ = ()
6002 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
6003 let p, h = scrollph state.y maxy in
6007 let winw = conf.winw - state.scrollw
- 1 in
6008 let fwinw = float winw in
6010 let sw = fwinw /. float state.w in
6011 let sw = fwinw *. sw in
6012 max
sw (float conf.scrollh
)
6015 let f = state.w+winw in
6016 let r = float (winw-state.x) /. float f in
6017 let p = fwinw *. r in
6021 if position +. sw > fwinw
6022 then fwinw -. position
6025 state.hscrollh, position, sw
6029 match state.mode with
6030 | LinkNav
_ -> "links"
6031 | Textentry
_ -> "textentry"
6032 | Birdseye
_ -> "birdseye"
6035 findkeyhash conf modename
6042 let fontpath = ref "";;
6045 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6048 let l = String.length
s in
6049 let b = Buffer.create
l in
6055 try Sys.getenv
"HOME"
6058 ("Can not determine home directory location: " ^
6059 Printexc.to_string exn
);
6063 let modifier_of_string = function
6064 | "alt" -> Wsi.altmask
6065 | "shift" -> Wsi.shiftmask
6066 | "ctrl" | "control" -> Wsi.ctrlmask
6067 | "meta" -> Wsi.metamask
6072 let r = Str.regexp
"-" in
6074 let elems = Str.full_split
r s in
6077 let m1 = modifier_of_string s in
6079 then (Wsi.namekey
s, m)
6082 | Str.Delim
s when n land 1 = 0 -> g s
6084 | Str.Delim
_ -> (k
, m)
6086 let rec loop n k
m = function
6089 let k, m = f n k m x in
6095 let keys_of_string =
6096 let r = Str.regexp
"[ \t]" in
6098 let elems = Str.split
r s in
6099 List.map
key_of_string elems
6102 let copykeyhashes c =
6103 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6106 let config_of c attrs
=
6110 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6111 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6112 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6113 | "preload" -> { c with preload = bool_of_string
v }
6114 | "page-bias" -> { c with pagebias
= int_of_string
v }
6115 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6116 | "horizontal-scroll-step" ->
6117 { c with hscrollstep
= max
(int_of_string
v) 1 }
6118 | "auto-scroll-step" ->
6119 { c with autoscrollstep
= max
0 (int_of_string
v) }
6120 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6121 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6124 match String.lowercase
v with
6125 | "true" -> Some infinity
6127 | f -> Some
(float_of_string
f)
6129 { c with maxwait
= mw}
6130 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6131 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6132 | "vertical-margin" ->
6133 { c with interpagespace
= max
0 (int_of_string
v) }
6135 let zoom = float_of_string
v /. 100. in
6136 let zoom = max
zoom 0.0 in
6137 { c with zoom = zoom }
6138 | "presentation" -> { c with presentation
= bool_of_string
v }
6139 | "rotation-angle" -> { c with angle
= int_of_string
v }
6140 | "width" -> { c with winw = max
20 (int_of_string
v) }
6141 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6142 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6143 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6144 | "pixmap-cache-size" ->
6145 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6146 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6147 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6148 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6149 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6150 | "background-color" -> { c with bgcolor
= color_of_string v }
6151 | "scrollbar-in-presentation" ->
6152 { c with scrollbarinpm
= bool_of_string
v }
6153 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6154 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6155 | "mupdf-store-size" ->
6156 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6157 | "checkers" -> { c with checkers
= bool_of_string
v }
6158 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6159 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6160 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6161 | "uri-launcher" -> { c with urilauncher
= unent v }
6162 | "path-launcher" -> { c with pathlauncher
= unent v }
6163 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6164 | "invert-colors" -> { c with invert
= bool_of_string
v }
6165 | "brightness" -> { c with colorscale
= float_of_string
v }
6166 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6168 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6170 let (n, _, _) as nab
= multicolumns_of_string v in
6172 then { c with columns
= Csplit
(-n, [||]) }
6173 else { c with columns
= Cmulti
(nab
, [||]) }
6174 | "birds-eye-columns" ->
6175 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6176 | "selection-command" -> { c with selcmd
= unent v }
6177 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6178 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6179 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6180 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6181 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6184 prerr_endline
("Error processing attribute (`" ^
6185 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6188 let rec fold c = function
6191 let c = apply c k v in
6194 fold { c with keyhashes
= copykeyhashes c } attrs
;
6197 let fromstring f pos
n v d =
6200 dolog "Error processing attribute (%S=%S) at %d\n%s"
6201 n v pos
(Printexc.to_string exn
)
6206 let bookmark_of attrs
=
6207 let rec fold title page
rely visy
= function
6208 | ("title", v) :: rest
-> fold v page
rely visy rest
6209 | ("page", v) :: rest
-> fold title v rely visy rest
6210 | ("rely", v) :: rest
-> fold title page
v visy rest
6211 | ("visy", v) :: rest
-> fold title page
rely v rest
6212 | _ :: rest
-> fold title page
rely visy rest
6213 | [] -> title, page
, rely, visy
6215 fold "invalid" "0" "0" "0" attrs
6219 let rec fold path page
rely pan visy
= function
6220 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6221 | ("page", v) :: rest
-> fold path v rely pan visy rest
6222 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6223 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6224 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6225 | _ :: rest
-> fold path page
rely pan visy rest
6226 | [] -> path, page
, rely, pan
, visy
6228 fold "" "0" "0" "0" "0" attrs
6232 let rec fold rs ls
= function
6233 | ("out", v) :: rest
-> fold v ls rest
6234 | ("in", v) :: rest
-> fold rs
v rest
6235 | _ :: rest
-> fold ls rs rest
6241 let setconf dst
src =
6242 dst
.scrollbw
<- src.scrollbw
;
6243 dst
.scrollh
<- src.scrollh
;
6244 dst
.icase
<- src.icase
;
6245 dst
.preload <- src.preload;
6246 dst
.pagebias
<- src.pagebias
;
6247 dst
.verbose
<- src.verbose
;
6248 dst
.scrollstep
<- src.scrollstep
;
6249 dst
.maxhfit
<- src.maxhfit
;
6250 dst
.crophack
<- src.crophack
;
6251 dst
.autoscrollstep
<- src.autoscrollstep
;
6252 dst
.maxwait
<- src.maxwait
;
6253 dst
.hlinks
<- src.hlinks
;
6254 dst
.underinfo
<- src.underinfo
;
6255 dst
.interpagespace
<- src.interpagespace
;
6256 dst
.zoom <- src.zoom;
6257 dst
.presentation
<- src.presentation
;
6258 dst
.angle
<- src.angle
;
6259 dst
.winw <- src.winw;
6260 dst
.winh
<- src.winh
;
6261 dst
.savebmarks
<- src.savebmarks
;
6262 dst
.memlimit
<- src.memlimit
;
6263 dst
.proportional
<- src.proportional
;
6264 dst
.texcount
<- src.texcount
;
6265 dst
.sliceheight
<- src.sliceheight
;
6266 dst
.thumbw
<- src.thumbw
;
6267 dst
.jumpback
<- src.jumpback
;
6268 dst
.bgcolor
<- src.bgcolor
;
6269 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6270 dst
.tilew
<- src.tilew
;
6271 dst
.tileh
<- src.tileh
;
6272 dst
.mustoresize
<- src.mustoresize
;
6273 dst
.checkers
<- src.checkers
;
6274 dst
.aalevel
<- src.aalevel
;
6275 dst
.trimmargins
<- src.trimmargins
;
6276 dst
.trimfuzz
<- src.trimfuzz
;
6277 dst
.urilauncher
<- src.urilauncher
;
6278 dst
.colorspace
<- src.colorspace
;
6279 dst
.invert
<- src.invert
;
6280 dst
.colorscale
<- src.colorscale
;
6281 dst
.redirectstderr <- src.redirectstderr;
6282 dst
.ghyllscroll
<- src.ghyllscroll
;
6283 dst
.columns
<- src.columns
;
6284 dst
.beyecolumns
<- src.beyecolumns
;
6285 dst
.selcmd
<- src.selcmd
;
6286 dst
.updatecurs
<- src.updatecurs
;
6287 dst
.pathlauncher
<- src.pathlauncher
;
6288 dst
.keyhashes
<- copykeyhashes src;
6289 dst
.hfsize
<- src.hfsize
;
6290 dst
.hscrollstep
<- src.hscrollstep
;
6291 dst
.pgscale <- src.pgscale;
6292 dst
.usepbo
<- src.usepbo
;
6293 dst
.wheelbypage
<- src.wheelbypage
;
6297 let h = Hashtbl.create
10 in
6298 let dc = { defconf with angle
= defconf.angle
} in
6299 let rec toplevel v t spos
_ =
6301 | Vdata
| Vcdata
| Vend
-> v
6302 | Vopen
("llppconfig", _, closed
) ->
6305 else { v with f = llppconfig
}
6307 error
"unexpected subelement at top level" s spos
6308 | Vclose
_ -> error
"unexpected close at top level" s spos
6310 and llppconfig
v t spos
_ =
6312 | Vdata
| Vcdata
-> v
6313 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6314 | Vopen
("defaults", attrs
, closed
) ->
6315 let c = config_of dc attrs
in
6319 else { v with f = defaults
}
6321 | Vopen
("ui-font", attrs
, closed
) ->
6322 let rec getsize size
= function
6324 | ("size", v) :: rest
->
6326 fromstring int_of_string spos
"size" v fstate.fontsize
in
6328 | l -> getsize size l
6330 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6333 else { v with f = uifont
(Buffer.create
10) }
6335 | Vopen
("doc", attrs
, closed
) ->
6336 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6337 let path = unent pathent
6338 and pageno = fromstring int_of_string spos
"page" spage
0
6339 and rely = fromstring float_of_string spos
"rely" srely
0.0
6340 and pan
= fromstring int_of_string spos
"pan" span
0
6341 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6342 let c = config_of dc attrs
in
6343 let anchor = (pageno, rely, visy
) in
6345 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6346 else { v with f = doc
path pan
anchor c [] }
6349 error
"unexpected subelement in llppconfig" s spos
6351 | Vclose
"llppconfig" -> { v with f = toplevel }
6352 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6354 and defaults
v t spos
_ =
6356 | Vdata
| Vcdata
-> v
6357 | Vend
-> error
"unexpected end of input in defaults" s spos
6358 | Vopen
("keymap", attrs
, closed
) ->
6360 try List.assoc
"mode" attrs
6361 with Not_found
-> "global" in
6366 let h = findkeyhash dc modename in
6367 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6370 { v with f = pkeymap
ret KeyMap.empty }
6372 | Vopen
(_, _, _) ->
6373 error
"unexpected subelement in defaults" s spos
6375 | Vclose
"defaults" ->
6376 { v with f = llppconfig
}
6378 | Vclose
_ -> error
"unexpected close in defaults" s spos
6380 and uifont
b v t spos
epos =
6383 Buffer.add_substring
b s spos
(epos - spos
);
6385 | Vopen
(_, _, _) ->
6386 error
"unexpected subelement in ui-font" s spos
6387 | Vclose
"ui-font" ->
6388 if String.length
!fontpath = 0
6389 then fontpath := Buffer.contents
b;
6390 { v with f = llppconfig
}
6391 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6392 | Vend
-> error
"unexpected end of input in ui-font" s spos
6394 and doc
path pan
anchor c bookmarks
v t spos
_ =
6396 | Vdata
| Vcdata
-> v
6397 | Vend
-> error
"unexpected end of input in doc" s spos
6398 | Vopen
("bookmarks", _, closed
) ->
6401 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6403 | Vopen
("keymap", attrs
, closed
) ->
6405 try List.assoc
"mode" attrs
6406 with Not_found
-> "global"
6412 let h = findkeyhash c modename in
6413 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6414 doc
path pan
anchor c bookmarks
6416 { v with f = pkeymap
ret KeyMap.empty }
6418 | Vopen
(_, _, _) ->
6419 error
"unexpected subelement in doc" s spos
6422 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6423 { v with f = llppconfig
}
6425 | Vclose
_ -> error
"unexpected close in doc" s spos
6427 and pkeymap
ret keymap
v t spos
_ =
6429 | Vdata
| Vcdata
-> v
6430 | Vend
-> error
"unexpected end of input in keymap" s spos
6431 | Vopen
("map", attrs
, closed
) ->
6432 let r, l = map_of attrs
in
6433 let kss = fromstring keys_of_string spos
"in" r [] in
6434 let lss = fromstring keys_of_string spos
"out" l [] in
6438 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6439 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6442 then { v with f = pkeymap
ret keymap }
6445 { v with f = skip
"map" f }
6448 error
"unexpected subelement in keymap" s spos
6450 | Vclose
"keymap" ->
6451 { v with f = ret keymap }
6453 | Vclose
_ -> error
"unexpected close in keymap" s spos
6455 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6457 | Vdata
| Vcdata
-> v
6458 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6459 | Vopen
("item", attrs
, closed
) ->
6460 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6461 let page = fromstring int_of_string spos
"page" spage
0
6462 and rely = fromstring float_of_string spos
"rely" srely
0.0
6463 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6465 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6468 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6471 { v with f = skip
"item" f }
6474 error
"unexpected subelement in bookmarks" s spos
6476 | Vclose
"bookmarks" ->
6477 { v with f = doc
path pan
anchor c bookmarks }
6479 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6481 and skip tag
f v t spos
_ =
6483 | Vdata
| Vcdata
-> v
6485 error
("unexpected end of input in skipped " ^ tag
) s spos
6486 | Vopen
(tag'
, _, closed
) ->
6490 let f'
() = { v with f = skip tag
f } in
6491 { v with f = skip tag'
f'
}
6495 else error
("unexpected close in skipped " ^ tag
) s spos
6498 parse
{ f = toplevel; accu = () } s;
6504 let len = in_channel_length ic
in
6505 let s = String.create
len in
6506 really_input ic
s 0 len;
6509 | Parse_error
(msg
, s, pos
) ->
6510 let subs = subs s pos
in
6511 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6512 failwith
("parse error: " ^
s)
6515 failwith
("config load error: " ^
Printexc.to_string exn
)
6521 let dir = Filename.concat
home ".config" in
6522 if Sys.is_directory
dir then dir else home
6525 Filename.concat
dir "llpp.conf"
6528 let confpath = ref defconfpath;;
6531 if Sys.file_exists
!confpath
6534 (try Some
(open_in_bin
!confpath)
6537 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6538 Printexc.to_string exn
);
6548 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6549 Printexc.to_string exn
);
6557 f (Hashtbl.create
0, defconf)
6562 let pc, pb
, px, pa
=
6564 Hashtbl.find h (Filename.basename
state.path)
6565 with Not_found
-> dc, [], 0, emptyanchor
6569 state.bookmarks <- pb
;
6571 state.scrollw
<- conf.scrollbw
;
6573 then state.anchor <- pa
;
6574 cbput state.hists
.nav pa
;
6580 let add_attrs bb always
dc c =
6583 then Printf.bprintf bb
"\n %s='%b'" s a
6586 then Printf.bprintf bb
"\n %s='%d'" s a
6589 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6592 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6595 then Printf.bprintf bb
"\n %s='%f'" s a
6599 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6603 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6607 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6611 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6617 | Some
(_N
, _A
, _B
) ->
6618 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6628 else string_of_float
f
6630 Printf.bprintf bb
"\n %s='%s'" s v
6635 | Cmulti
((n, a, b), _) when n > 1 ->
6636 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6637 | Csplit
(n, _) when n > 1 ->
6638 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6644 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6649 then dc.winw, dc.winh
6651 match state.fullscreen
with
6653 | None
-> c.winw, c.winh
6655 oi
"width" w dc.winw;
6656 oi
"height" h dc.winh
;
6657 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6658 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6659 ob "case-insensitive-search" c.icase
dc.icase
;
6660 ob "preload" c.preload dc.preload;
6661 oi
"page-bias" c.pagebias
dc.pagebias
;
6662 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6663 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6664 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6665 ob "crop-hack" c.crophack
dc.crophack
;
6666 oW
"throttle" c.maxwait
dc.maxwait
;
6667 ob "highlight-links" c.hlinks
dc.hlinks
;
6668 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6669 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6670 oz
"zoom" c.zoom dc.zoom;
6671 ob "presentation" c.presentation
dc.presentation
;
6672 oi
"rotation-angle" c.angle
dc.angle
;
6673 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6674 ob "proportional-display" c.proportional
dc.proportional
;
6675 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6676 oi
"tex-count" c.texcount
dc.texcount
;
6677 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6678 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6679 ob "persistent-location" c.jumpback
dc.jumpback
;
6680 oc
"background-color" c.bgcolor
dc.bgcolor
;
6681 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6682 oi
"tile-width" c.tilew
dc.tilew
;
6683 oi
"tile-height" c.tileh
dc.tileh
;
6684 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6685 ob "checkers" c.checkers
dc.checkers
;
6686 oi
"aalevel" c.aalevel
dc.aalevel
;
6687 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6688 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6689 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6690 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6691 oC
"color-space" c.colorspace
dc.colorspace
;
6692 ob "invert-colors" c.invert
dc.invert
;
6693 oF
"brightness" c.colorscale
dc.colorscale
;
6694 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6695 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6696 oco
"columns" c.columns
dc.columns
;
6697 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6698 os
"selection-command" c.selcmd
dc.selcmd
;
6699 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6700 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6701 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6702 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6703 ob "use-pbo" c.usepbo
dc.usepbo
;
6704 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6707 let keymapsbuf always
dc c =
6708 let bb = Buffer.create
16 in
6709 let rec loop = function
6711 | (modename, h) :: rest
->
6712 let dh = findkeyhash dc modename in
6713 if always
|| h <> dh
6715 if Hashtbl.length
h > 0
6717 if Buffer.length
bb > 0
6718 then Buffer.add_char
bb '
\n'
;
6719 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6720 Hashtbl.iter
(fun i
o ->
6721 let isdifferent = always
||
6723 let dO = Hashtbl.find dh i
in
6725 with Not_found
-> true
6730 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6731 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6732 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6733 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6734 Buffer.add_string
bb (Wsi.keyname
k);
6737 let rec loop = function
6739 | km
:: [] -> addkm km
6740 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6744 Buffer.add_string
bb "<map in='";
6748 Buffer.add_string
bb "' out='";
6750 Buffer.add_string
bb "'/>\n"
6753 Buffer.add_string
bb "' out='";
6755 Buffer.add_string
bb "'/>\n"
6757 | KMmulti
(ins, kms
) ->
6758 Buffer.add_char
bb ' '
;
6760 Buffer.add_string
bb "' out='";
6762 Buffer.add_string
bb "'/>\n"
6764 Buffer.add_string
bb "</keymap>";
6774 let uifontsize = fstate.fontsize
in
6775 let bb = Buffer.create
32768 in
6777 let dc = if conf.bedefault
then conf else dc in
6778 Buffer.add_string
bb "<llppconfig>\n";
6780 if String.length
!fontpath > 0
6782 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6788 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6791 Buffer.add_string
bb "<defaults ";
6792 add_attrs bb true dc dc;
6793 let kb = keymapsbuf true dc dc in
6794 if Buffer.length
kb > 0
6796 Buffer.add_string
bb ">\n";
6797 Buffer.add_buffer
bb kb;
6798 Buffer.add_string
bb "\n</defaults>\n";
6800 else Buffer.add_string
bb "/>\n";
6802 let adddoc path pan
anchor c bookmarks =
6803 if bookmarks == [] && c = dc && anchor = emptyanchor
6806 Printf.bprintf
bb "<doc path='%s'"
6807 (enent
path 0 (String.length
path));
6809 if anchor <> emptyanchor
6811 let n, rely, visy
= anchor in
6812 Printf.bprintf
bb " page='%d'" n;
6815 Printf.bprintf
bb " rely='%f'" rely
6817 if abs_float visy
> 1e-6
6819 Printf.bprintf
bb " visy='%f'" visy
6824 then Printf.bprintf
bb " pan='%d'" pan
;
6826 add_attrs bb false dc c;
6827 let kb = keymapsbuf false dc c in
6829 begin match bookmarks with
6831 if Buffer.length
kb > 0
6833 Buffer.add_string
bb ">\n";
6834 Buffer.add_buffer
bb kb;
6835 Buffer.add_string
bb "\n</doc>\n";
6837 else Buffer.add_string
bb "/>\n"
6839 Buffer.add_string
bb ">\n<bookmarks>\n";
6840 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6842 "<item title='%s' page='%d'"
6843 (enent
title 0 (String.length
title))
6848 Printf.bprintf
bb " rely='%f'" rely
6850 if abs_float visy
> 1e-6
6852 Printf.bprintf
bb " visy='%f'" visy
6854 Buffer.add_string
bb "/>\n";
6856 Buffer.add_string
bb "</bookmarks>";
6857 if Buffer.length
kb > 0
6859 Buffer.add_string
bb "\n";
6860 Buffer.add_buffer
bb kb;
6862 Buffer.add_string
bb "\n</doc>\n";
6868 match state.mode with
6869 | Birdseye
(c, pan, _, _, _) ->
6871 match conf.columns
with
6872 | Cmulti
((c, _, _), _) -> Some
c
6876 match c.columns
with
6877 | Cmulti
(c, _) -> Cmulti
(c, [||])
6878 | Csingle
_ -> Csingle
[||]
6879 | Csplit
_ -> failwith
"quit from bird's eye while split"
6881 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6882 | _ -> state.x, conf
6884 let basename = Filename.basename state.path in
6885 adddoc basename pan (getanchor ())
6887 let autoscrollstep =
6888 match state.autoscroll
with
6890 | None
-> conf.autoscrollstep
6892 match state.mode with
6893 | Birdseye
(bc
, _, _, _, _) ->
6896 presentation
= bc
.presentation
;
6897 interpagespace
= bc
.interpagespace
;
6898 maxwait
= bc
.maxwait
;
6899 autoscrollstep = autoscrollstep }
6900 | _ -> { conf with autoscrollstep = autoscrollstep }
6902 (if conf.savebmarks
then state.bookmarks else []);
6904 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6906 then adddoc path x anchor c bookmarks
6908 Buffer.add_string
bb "</llppconfig>\n";
6911 if load1 f && Buffer.length
bb > 0
6914 let tmp = !confpath ^
".tmp" in
6915 let oc = open_out_bin
tmp in
6916 Buffer.output_buffer
oc bb;
6918 Unix.rename
tmp !confpath;
6921 ("error while saving configuration: " ^
Printexc.to_string exn
)
6926 let trimcachepath = ref "" in
6929 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6930 "<password> Set password");
6932 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6933 "<path> Set path to the user interface font");
6935 ("-c", Arg.String
(fun s -> Config.confpath := s),
6936 "<path> Set path to the configuration file");
6938 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6939 "<path> Set path to the trim cache file");
6941 ("-v", Arg.Unit
(fun () ->
6943 "%s\nconfiguration path: %s\n"
6947 exit
0), " Print version and exit");
6950 (fun s -> state.path <- s)
6951 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6953 if String.length
state.path = 0
6954 then (prerr_endline
"file name missing"; exit
1);
6956 if not
(Config.load ())
6957 then prerr_endline
"failed to load configuration";
6959 let globalkeyhash = findkeyhash conf "global" in
6960 let wsfd, winw, winh
= Wsi.init
(object
6962 state.wthack
<- false;
6963 if nogeomcmds state.geomcmds
|| platform == Posx
6966 GlClear.color (scalecolor2 conf.bgcolor
);
6967 GlClear.clear
[`
color];
6969 method display = display ()
6970 method reshape w h = reshape w h
6971 method mouse b d x y m = mouse b d x y m
6972 method motion x y = state.mpos
<- (x, y); motion x y
6973 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6975 let mascm = m land (
6976 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6978 match state.keystate
with
6980 let km = k, mascm in
6983 let modehash = state.uioh#
modehash in
6984 try Hashtbl.find modehash km
6986 try Hashtbl.find globalkeyhash km
6987 with Not_found
-> KMinsrt
(k, m)
6989 | KMinsrt
(k, m) -> keyboard k m
6990 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6991 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6993 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6994 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6995 state.keystate
<- KSnone
6996 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6997 state.keystate
<- KSinto
(keys
, insrt
)
6999 state.keystate
<- KSnone
7001 method enter
x y = state.mpos
<- (x, y); pmotion x y
7002 method leave = state.mpos
<- (-1, -1)
7003 method quit
= raise Quit
7004 end) conf.winw conf.winh
(platform = Posx
) in
7009 List.exists
GlMisc.check_extension
7010 [ "GL_ARB_texture_rectangle"
7011 ; "GL_EXT_texture_recangle"
7012 ; "GL_NV_texture_rectangle" ]
7014 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7017 match Ne.pipe () with
7019 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7023 match Ne.pipe () with
7025 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7035 setcheckers conf.checkers
;
7039 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7040 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7041 !Config.fontpath, !trimcachepath,
7042 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7046 state.text <- "Opening " ^
(mbtoutf8
state.path);
7048 opendoc state.path state.password
;
7051 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7053 let rec loop deadline
=
7055 match state.errfd
with
7056 | None
-> [state.sr
; state.wsfd]
7057 | Some fd
-> [state.sr
; state.wsfd; fd
]
7061 state.redisplay
<- false;
7068 if deadline
= infinity
7070 else max
0.0 (deadline
-. now)
7075 try Unix.select
r [] [] timeout
7076 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7082 if state.ghyll
== noghyll
7084 match state.autoscroll
with
7085 | Some step
when step
!= 0 ->
7086 let y = state.y + step
in
7090 else if y >= state.maxy then 0 else y
7093 if state.mode = View
7094 then state.text <- "";
7097 else deadline
+. 0.01
7102 let rec checkfds = function
7104 | fd
:: rest
when fd
= state.sr
->
7105 let cmd = readcmd state.sr
in
7109 | fd
:: rest
when fd
= state.wsfd ->
7114 let s = String.create
80 in
7115 let n = Unix.read fd
s 0 80 in
7116 if conf.redirectstderr
7118 Buffer.add_substring
state.errmsgs
s 0 n;
7119 state.newerrmsgs
<- true;
7120 state.redisplay
<- true;
7123 prerr_string
(String.sub
s 0 n);
7131 if deadline
= infinity
7135 match state.autoscroll
with
7136 | Some step
when step
!= 0 -> deadline1
7137 | _ -> if state.ghyll
== noghyll then infinity
else deadline1