8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
11 | Ulaunch
of launchcommand
13 | Uremote
of (filename
* pageno
)
14 | Uremotedest
of (filename
* destname
)
16 and launchcommand
= string
19 and destname
= string;;
30 type t
= private string
31 val of_string
: string -> t
32 val to_string
: t
-> string
42 let (~
<) = Opaque.of_string;;
43 let (~
>) = Opaque.to_string;;
45 type params
= (angle
* fitmodel
* trimparams
46 * texcount
* sliceheight
* memsize
47 * colorspace
* fontpath
* trimcachepath
56 and trimmargins
= bool
57 and interpagespace
= int
64 and trimcachepath
= string
67 and irect
= (int * int * int * int)
68 and trimparams
= (trimmargins
* irect
)
69 and colorspace
= | Rgb
| Bgr
| Gray
70 and fitmodel
= | FitWidth
| FitProportional
| FitPage
80 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
89 | LDfirstvisible
of (int * int * int)
103 | KMinsrl
of key list
104 | KMmulti
of key list
* key list
106 and keyhash
= (key
, keymap
) Hashtbl.t
109 | KSinto
of (key list
* key list
)
112 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
113 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
115 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
117 external init
: pipe
-> params
-> unit = "ml_init";;
118 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
119 external hassel
: opaque
-> bool = "ml_hassel";;
120 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
121 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
122 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
123 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
124 external clearmark
: opaque
-> unit = "ml_clearmark";;
125 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
126 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
127 external measurestr
: int -> string -> float = "ml_measure_string";;
128 external postprocess
:
129 opaque
-> int -> int -> int -> (int * string * int) -> int
131 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
132 external platform
: unit -> platform
= "ml_platform";;
133 external setaalevel
: int -> unit = "ml_setaalevel";;
134 external realloctexts
: int -> bool = "ml_realloctexts";;
135 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
136 external getlink
: opaque
-> int -> under
= "ml_getlink";;
137 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
138 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
139 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
140 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
141 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
142 external freepbo
: opaque
-> unit = "ml_freepbo";;
143 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
144 external pbousable
: unit -> bool = "ml_pbo_usable";;
145 external unproject
: opaque
-> int -> int -> (int * int) option
147 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
148 external rectofblock
: opaque
-> int -> int -> float array
option
150 external fz_version
: unit -> string = "ml_fz_version";;
151 external begintiles
: unit -> unit = "ml_begintiles";;
152 external endtiles
: unit -> unit = "ml_endtiles";;
154 let platform_to_string = function
155 | Punknown
-> "unknown"
159 | Pfreebsd
-> "FreeBSD"
160 | Pdragonflybsd
-> "DragonflyBSD"
161 | Popenbsd
-> "OpenBSD"
162 | Pnetbsd
-> "NetBSD"
163 | Pcygwin
-> "Cygwin"
166 let platform = platform ();;
168 let now = Unix.gettimeofday
;;
170 let selfexec = ref "";;
173 if platform = Pcygwin
175 let sh = "/bin/sh" in
176 let args = [|sh; "-c"; cmd
|] in
177 let rec std si so se
= function
179 | (fd
, 0) :: rest
-> std fd so se rest
180 | (fd
, -1) :: rest
->
181 Unix.set_close_on_exec fd
;
184 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
186 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
187 ignore
(Unix.create_process
sh args si so se
)
192 type mpos
= int * int
194 | Msel
of (mpos
* mpos
)
196 | Mscrolly
| Mscrollx
197 | Mzoom
of (int * int)
198 | Mzoomrect
of (mpos
* mpos
)
202 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
203 and onkey
= string -> int -> te
204 and ondone
= string -> unit
205 and histcancel
= unit -> unit
206 and onhist
= ((histcmd
-> string) * histcancel
)
207 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
208 and cancelonempty
= bool
213 | TEswitch
of textentry
224 let bound v minv maxv
=
225 max minv
(min maxv v
);
229 { store
= Array.create n v
236 let cbcap b
= Array.length b
.store
;;
241 b
.wc
<- (b
.wc
+ 1) mod cap;
243 b
.len
<- min
(b
.len
+ 1) cap;
246 let cbempty b
= b
.len
= 0;;
248 let cbgetg b circular dir
=
252 let rc = b
.rc + dir
in
264 else bound rc 0 (b
.len
-1)
270 let cbget b
= cbgetg b
false;;
271 let cbgetc b
= cbgetg b
true;;
273 let drawstring size x y s
=
275 Gl.enable `texture_2d
;
276 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
277 ignore
(drawstr size x y s
);
279 Gl.disable `texture_2d
;
282 let drawstring1 size x y s
=
286 let drawstring2 size x y fmt
=
287 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
306 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
307 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
308 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
309 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
310 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
311 dolog
" column %d" l
.pagecol
;
315 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
317 dolog
" x0,y0=(% f, % f)" x0 y0
;
318 dolog
" x1,y1=(% f, % f)" x1 y1
;
319 dolog
" x2,y2=(% f, % f)" x2 y2
;
320 dolog
" x3,y3=(% f, % f)" x3 y3
;
324 type multicolumns
= multicol
* pagegeom
325 and singlecolumn
= pagegeom
326 and splitcolumns
= columncount
* pagegeom
327 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
328 and multicol
= columncount
* covercount
* covercount
330 and columncount
= int
331 and covercount
= int;;
338 { mutable scrollbw
: int
339 ; mutable scrollh
: int
340 ; mutable scrollb
: scrollb
341 ; mutable icase
: bool
342 ; mutable preload
: bool
343 ; mutable pagebias
: int
344 ; mutable verbose
: bool
345 ; mutable debug
: bool
346 ; mutable scrollstep
: int
347 ; mutable hscrollstep
: int
348 ; mutable maxhfit
: bool
349 ; mutable crophack
: bool
350 ; mutable autoscrollstep
: int
351 ; mutable maxwait
: float option
352 ; mutable hlinks
: bool
353 ; mutable underinfo
: bool
354 ; mutable interpagespace
: interpagespace
355 ; mutable zoom
: float
356 ; mutable presentation
: bool
357 ; mutable angle
: angle
358 ; mutable cwinw
: int
359 ; mutable cwinh
: int
360 ; mutable savebmarks
: bool
361 ; mutable fitmodel
: fitmodel
362 ; mutable trimmargins
: trimmargins
363 ; mutable trimfuzz
: irect
364 ; mutable memlimit
: memsize
365 ; mutable texcount
: texcount
366 ; mutable sliceheight
: sliceheight
367 ; mutable thumbw
: width
368 ; mutable jumpback
: bool
369 ; mutable bgcolor
: (float * float * float)
370 ; mutable bedefault
: bool
371 ; mutable tilew
: int
372 ; mutable tileh
: int
373 ; mutable mustoresize
: memsize
374 ; mutable checkers
: bool
375 ; mutable aalevel
: int
376 ; mutable urilauncher
: string
377 ; mutable pathlauncher
: string
378 ; mutable colorspace
: colorspace
379 ; mutable invert
: bool
380 ; mutable colorscale
: float
381 ; mutable redirectstderr
: bool
382 ; mutable ghyllscroll
: (int * int * int) option
383 ; mutable columns
: columns
384 ; mutable beyecolumns
: columncount
option
385 ; mutable selcmd
: string
386 ; mutable paxcmd
: string
387 ; mutable updatecurs
: bool
388 ; mutable keyhashes
: (string * keyhash
) list
389 ; mutable hfsize
: int
390 ; mutable pgscale
: float
391 ; mutable usepbo
: bool
392 ; mutable wheelbypage
: bool
393 ; mutable stcmd
: string
394 ; mutable riani
: bool
395 ; mutable pax
: (float * int * int) ref option
396 ; mutable paxmark
: mark
399 | Csingle
of singlecolumn
400 | Cmulti
of multicolumns
401 | Csplit
of splitcolumns
404 type anchor
= pageno
* top
* dtop
;;
410 | Olaunch
of launchcommand
411 | Oremote
of (filename
* pageno
)
412 | Oremotedest
of (filename
* destname
)
413 and outline
= (caption
* outlinelevel
* outlinekind
)
414 and outlinelevel
= int
417 type rect
= float * float * float * float * float * float * float * float;;
419 type tile
= opaque
* pixmapsize
* elapsed
420 and elapsed
= float;;
421 type pagemapkey
= pageno
* gen
;;
422 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
426 let emptyanchor = (0, 0.0, 0.0);;
428 type infochange
= | Memused
| Docinfo
| Pdim
;;
430 class type uioh
= object
431 method display
: unit
432 method key
: int -> int -> uioh
433 method button
: int -> bool -> int -> int -> int -> uioh
434 method multiclick
: int -> int -> int -> int -> uioh
435 method motion
: int -> int -> uioh
436 method pmotion
: int -> int -> uioh
437 method infochanged
: infochange
-> unit
438 method scrollpw
: (int * float * float)
439 method scrollph
: (int * float * float)
440 method modehash
: keyhash
441 method eformsgs
: bool
445 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
446 | Textentry
of (textentry
* onleave
)
448 | LinkNav
of linktarget
449 and onleave
= leavetextentrystatus
-> unit
450 and leavetextentrystatus
= | Cancel
| Confirm
451 and helpitem
= string * int * action
454 | Action
of (uioh
-> uioh
)
456 | Ltexact
of (pageno
* int)
460 let isbirdseye = function Birdseye _
-> true | _
-> false;;
461 let istextentry = function Textentry _
-> true | _
-> false;;
465 | Loading
of (page
* gen
)
467 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
469 | Outlining
of outline list
472 let emptykeyhash = Hashtbl.create
0;;
473 let nouioh : uioh
= object (self
)
475 method key _ _
= self
476 method multiclick _ _ _ _
= self
477 method button _ _ _ _ _
= self
478 method motion _ _
= self
479 method pmotion _ _
= self
480 method infochanged _
= ()
481 method scrollpw
= (0, nan
, nan
)
482 method scrollph
= (0, nan
, nan
)
483 method modehash
= emptykeyhash
484 method eformsgs
= false
488 { mutable sr
: Unix.file_descr
489 ; mutable sw
: Unix.file_descr
490 ; mutable wsfd
: Unix.file_descr
491 ; mutable errfd
: Unix.file_descr
option
492 ; mutable stderr
: Unix.file_descr
493 ; mutable errmsgs
: Buffer.t
494 ; mutable newerrmsgs
: bool
498 ; mutable anchor
: anchor
499 ; mutable ranchors
: (string * string * anchor
* string) list
501 ; mutable layout
: page list
502 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
503 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
504 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
505 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
506 ; mutable pagecount
: int
507 ; mutable currently
: currently
508 ; mutable mstate
: mstate
509 ; mutable searchpattern
: string
510 ; mutable rects
: (pageno
* recttype
* rect
) list
511 ; mutable rects1
: (pageno
* recttype
* rect
) list
512 ; mutable text
: string
513 ; mutable winstate
: Wsi.winstate list
514 ; mutable mode
: mode
515 ; mutable uioh
: uioh
516 ; mutable outlines
: outline array
517 ; mutable bookmarks
: outline list
518 ; mutable path
: string
519 ; mutable password
: string
520 ; mutable nameddest
: string
521 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
522 ; mutable memused
: memsize
524 ; mutable throttle
: (page list
* int * float) option
525 ; mutable autoscroll
: int option
526 ; mutable ghyll
: (int option -> unit)
527 ; mutable help
: helpitem array
528 ; mutable docinfo
: (int * string) list
529 ; mutable texid
: GlTex.texture_id
option
531 ; mutable prevzoom
: (float * int)
532 ; mutable progress
: float
533 ; mutable redisplay
: bool
534 ; mutable mpos
: mpos
535 ; mutable keystate
: keystate
536 ; mutable glinks
: bool
537 ; mutable prevcolumns
: (columns
* float) option
540 ; mutable reprf
: (unit -> unit)
541 ; mutable origin
: string
542 ; mutable roam
: (unit -> unit)
543 ; mutable bzoom
: bool
544 ; mutable traw
: [`
float] Raw.t
545 ; mutable vraw
: [`
float] Raw.t
548 { pat
: string circbuf
549 ; pag
: string circbuf
550 ; nav
: anchor circbuf
551 ; sel
: string circbuf
558 ; scrollb
= scrollbhv lor scrollbvv
574 ; presentation
= false
579 ; fitmodel
= FitProportional
580 ; trimmargins
= false
581 ; trimfuzz
= (0,0,0,0)
582 ; memlimit
= 32 lsl 20
587 ; bgcolor
= (0.5, 0.5, 0.5)
591 ; mustoresize
= 256 lsl 20
596 | Plinux
| Pfreebsd
| Pdragonflybsd
597 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
598 | Posx
-> "open \"%s\""
599 | Pcygwin
-> "cygstart \"%s\""
600 | Punknown
-> "echo %s")
601 ; pathlauncher
= "lp \"%s\""
604 | Plinux
| Pfreebsd
| Pdragonflybsd
605 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
613 ; redirectstderr
= false
615 ; columns
= Csingle
[||]
621 ; wheelbypage
= false
622 ; stcmd
= "echo SyncTex"
625 ; paxmark
= Mark_word
627 let mk n
= (n
, Hashtbl.create
1) in
641 let wtmode = ref false;;
642 let cxack = ref false;;
644 let findkeyhash c name
=
645 try List.assoc name c
.keyhashes
646 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
649 let conf = { defconf with angle
= defconf.angle
};;
651 let pgscale h
= truncate
(float h
*. conf.pgscale);;
654 { mutable fontsize
: int
655 ; mutable wwidth
: float
656 ; mutable maxrows
: int
668 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
669 let len = String.length s
in
670 if colonpos >= 0 && colonpos + 3 < len
672 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
675 try String.rindex_from s
colonpos ' '
679 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
682 | "http" | "ftp" | "mailto" ->
684 try String.index_from s
colonpos ' '
685 with Not_found
-> len
687 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
695 if emptystr
conf.urilauncher
696 then print_endline uri
698 let url = geturl uri
in
700 then Printf.eprintf
"obtained empty url from uri %S\n" uri
702 let re = Str.regexp
"%s" in
703 let command = Str.global_replace
re url conf.urilauncher
in
707 "failed to execute `%s': %s\n" command (exntos exn
);
713 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
714 Help.version (fz_version
()) Sys.ocaml_version
715 (platform_to_string platform) Sys.word_size
719 let strings = version () :: "" :: Help.keys
in
722 let url = geturl s
in
724 then (s
, 0, Action
(fun u
-> gotouri url; u
))
725 else (s
, 0, Noaction
)
730 let firstgeomcmds = "", [];;
731 let noreprf () = ();;
739 ; stderr
= Unix.stderr
740 ; errmsgs
= Buffer.create
0
745 ; anchor
= emptyanchor
749 ; tilelru
= Queue.create
()
750 ; pagemap
= Hashtbl.create
10
751 ; tilemap
= Hashtbl.create
10
767 ; geomcmds
= firstgeomcmds
769 { nav
= cbnew 10 emptyanchor
782 ; prevzoom
= (1.0, 0)
796 ; traw
= Raw.create_static `
float 8
797 ; vraw
= Raw.create_static `
float 8
802 if (conf.scrollb
land scrollbhv = 0)
803 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
809 if (conf.scrollb
land scrollbvv = 0)
814 let wadjsb w
= w
- vscrollw ();;
817 fstate.fontsize
<- n
;
818 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
819 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
825 Printf.kprintf prerr_endline fmt
827 Printf.kprintf ignore fmt
831 if emptystr
conf.pathlauncher
832 then print_endline
state.path
834 let re = Str.regexp
"%s" in
835 let command = Str.global_replace
re state.path
conf.pathlauncher
in
838 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
844 type 'a t
= | Res
of 'a
| Exn
of exn
;;
852 try tempfailureretry
Unix.close fd
853 with exn
-> f
(exntos exn
)
857 try Res
(tempfailureretry
Unix.dup fd
)
862 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
867 let redirectstderr () =
868 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
869 if conf.redirectstderr
871 match Ne.res Unix.pipe
with
873 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
876 begin match Ne.dup Unix.stderr
with
878 dolog
"failed to dup stderr: %s" (exntos exn
);
879 Ne.clo r
(clofail "pipe/r");
880 Ne.clo w
(clofail "pipe/w");
882 | Ne.Res dupstderr
->
883 begin match Ne.dup2 w
Unix.stderr
with
885 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
886 Ne.clo dupstderr
(clofail "stderr duplicate");
887 Ne.clo r
(clofail "redir pipe/r");
888 Ne.clo w
(clofail "redir pipe/w");
891 state.stderr
<- dupstderr
;
892 state.errfd
<- Some r
;
896 state.newerrmsgs
<- false;
897 begin match state.errfd
with
899 begin match Ne.dup2 state.stderr
Unix.stderr
with
901 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
903 Ne.clo fd
(clofail "dup of stderr");
908 prerr_string
(Buffer.contents
state.errmsgs
);
910 Buffer.clear
state.errmsgs
;
916 let postRedisplay who
=
918 then prerr_endline
("redisplay for " ^ who
);
919 state.redisplay
<- true;
923 let getopaque pageno
=
924 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
925 with Not_found
-> None
928 let putopaque pageno opaque
=
929 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
932 let pagetranslatepoint l x y
=
933 let dy = y
- l
.pagedispy
in
934 let y = dy + l
.pagey
in
935 let dx = x
- l
.pagedispx
in
936 let x = dx + l
.pagex
in
940 let onppundermouse g
x y d
=
943 begin match getopaque l
.pageno
with
945 let x0 = l
.pagedispx
in
946 let x1 = x0 + l
.pagevw
in
947 let y0 = l
.pagedispy
in
948 let y1 = y0 + l
.pagevh
in
949 if y >= y0 && y <= y1 && x >= x0 && x <= x1
951 let px, py
= pagetranslatepoint l
x y in
952 match g opaque l
px py
with
965 let g opaque l
px py
=
968 match rectofblock opaque
px py
with
970 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
971 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
972 G.postRedisplay "getunder";
975 match whatsunder opaque
px py
with
977 | under
-> Some under
979 onppundermouse g x y Unone
984 match unproject opaque
x y with
985 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
988 onppundermouse g x y None
;
992 state.text
<- Printf.sprintf
"%c%s" c s
;
993 G.postRedisplay "showtext";
996 let pipesel opaque cmd
=
999 match Ne.res Unix.pipe
with
1002 (Printf.sprintf
"pipesel can not create pipe: %s" (exntos exn
));
1004 let doclose what fd
=
1005 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
1008 try popen cmd
[r
, 0; w
, -1]; true
1010 dolog
"can not execute %S: %s" cmd
(exntos exn
);
1016 G.postRedisplay "pipesel";
1018 else doclose "pipesel pipe/w" w
;
1019 doclose "pipesel pipe/r" r
;
1023 let g opaque l
px py
=
1024 if markunder opaque
px py
conf.paxmark
1027 match getopaque l
.pageno
with
1029 | Some opaque
-> pipesel opaque
conf.paxcmd
1034 G.postRedisplay "paxunder";
1035 if conf.paxmark
= Mark_page
1038 match getopaque l
.pageno
with
1040 | Some opaque
-> clearmark opaque
) state.layout
;
1042 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1046 match Ne.res Unix.pipe
with
1048 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1051 Ne.clo fd
(fun msg
->
1052 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1056 try popen conf.selcmd
[r
, 0; w
, -1]; true
1059 (Printf.sprintf
"failed to execute %s: %s"
1060 conf.selcmd
(exntos exn
));
1066 let l = String.length s
in
1067 let n = tempfailureretry
(Unix.write w s
0) l in
1072 "failed to write %d characters to sel pipe, wrote %d"
1077 (Printf.sprintf
"failed to write to sel pipe: %s"
1082 clo "selstring pipe/r" r
;
1083 clo "selstring pipe/w" w
;
1086 let undertext = function
1089 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1090 | Utext s
-> "font: " ^ s
1091 | Uunexpected s
-> "unexpected: " ^ s
1092 | Ulaunch s
-> "launch: " ^ s
1093 | Unamed s
-> "named: " ^ s
1094 | Uremote
(filename
, pageno
) ->
1095 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1096 | Uremotedest
(filename
, destname
) ->
1097 Printf.sprintf
"%s: destination %S" filename destname
1100 let updateunder x y =
1101 match getunder x y with
1102 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1104 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1105 Wsi.setcursor
Wsi.CURSOR_INFO
1106 | Ulinkgoto
(pageno
, _
) ->
1108 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1109 Wsi.setcursor
Wsi.CURSOR_INFO
1111 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1112 Wsi.setcursor
Wsi.CURSOR_TEXT
1114 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1115 Wsi.setcursor
Wsi.CURSOR_INHERIT
1117 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1118 Wsi.setcursor
Wsi.CURSOR_INHERIT
1120 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1121 Wsi.setcursor
Wsi.CURSOR_INHERIT
1122 | Uremote
(filename
, pageno
) ->
1123 if conf.underinfo
then showtext 'r'
1124 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1125 Wsi.setcursor
Wsi.CURSOR_INFO
1126 | Uremotedest
(filename
, destname
) ->
1127 if conf.underinfo
then showtext 'r'
1128 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1129 Wsi.setcursor
Wsi.CURSOR_INFO
1132 let showlinktype under
=
1138 let s = undertext under
in
1143 let b = Buffer.create
(String.length
s + 1) in
1144 Buffer.add_string
b s;
1145 Buffer.add_char
b c
;
1149 module type TextEnumType
=
1153 val names
: string array
1156 module TextEnumMake
(Ten
: TextEnumType
) =
1158 let names = Ten.names;;
1159 let to_int (t
: Ten.t
) = Obj.magic t
;;
1160 let to_string t
= names.(to_int t
);;
1161 let of_int n : Ten.t
= Obj.magic
n;;
1164 if i
= Array.length
names
1165 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1167 if Ten.names.(i
) = s
1174 module CSTE
= TextEnumMake
(struct
1175 type t
= colorspace
;;
1176 let name = "colorspace";;
1177 let names = [|"rgb"; "bgr"; "gray"|];;
1180 module MTE
= TextEnumMake
(struct
1183 let names = [|"page"; "block"; "line"; "word"|];;
1186 module FMTE
= TextEnumMake
(struct
1188 let name = "fitmodel";;
1189 let names = [|"width"; "proportional"; "page"|];;
1192 let intentry_with_suffix text key
=
1194 if key
>= 32 && key
< 127
1198 match Char.lowercase
c with
1200 let text = addchar text c in
1203 | 'k'
| 'm'
| '
g'
->
1204 let text = addchar text c in
1208 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1212 let multicolumns_to_string (n, a
, b) =
1214 then Printf.sprintf
"%d" n
1215 else Printf.sprintf
"%d,%d,%d" n a
b;
1218 let multicolumns_of_string s =
1220 (int_of_string
s, 0, 0)
1222 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1224 then failwith
"subtly broken"; (n, a
, b)
1230 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1231 if n != 4 then error
"incomplete read(len) = %d" n;
1233 lor (Char.code
s.[0] lsl 24)
1234 lor (Char.code
s.[1] lsl 16)
1235 lor (Char.code
s.[2] lsl 8)
1236 lor (Char.code
s.[3] lsl 0)
1238 let s = String.create
len in
1239 let n = tempfailureretry
(Unix.read fd
s 0) len in
1240 if n != len then error
"incomplete read(data) %d vs %d" n len;
1244 let btod b = if b then 1 else 0;;
1247 let b = Buffer.create
16 in
1248 Buffer.add_string
b "llll";
1251 let s = Buffer.contents
b in
1252 let n = String.length
s in
1254 (* dolog "wcmd %S" (String.sub s 4 len); *)
1255 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1256 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1257 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1258 s.[3] <- Char.chr
(len land 0xff);
1259 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1260 if n'
!= n then error
"write failed %d vs %d" n'
n;
1265 let d = state.winh
- h
in
1266 max
conf.interpagespace
((d + 1) / 2)
1269 let rowyh (c, coverA
, coverB
) b n =
1270 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1272 let _, _, vy
, (_, _, h
, _) = b.(n) in
1275 let n'
= n - coverA
in
1278 let e = min
state.pagecount
(s + c) in
1279 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1280 let _, _, y, (_, _, h
, _) = b.(m
) in
1281 let miny = min
miny y in
1282 let maxh = max
maxh h
in
1283 find (m
+1) miny maxh
1288 match conf.columns
with
1289 | Cmulti
((_, _, _) as cl
, b) ->
1290 if Array.length
b > 0
1292 let y, h
= rowyh cl
b (Array.length
b - 1) in
1293 y + h
+ (if conf.presentation
then calcips h
else 0)
1296 if Array.length
b > 0
1298 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1299 y + h
+ (if conf.presentation
then calcips h
else 0)
1302 if Array.length
b > 0
1304 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1309 let getpageywh pageno
=
1310 let pageno = bound pageno 0 (state.pagecount
-1) in
1311 match conf.columns
with
1313 if Array.length
b = 0
1316 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1318 if conf.presentation
1324 if Array.length
b = 0
1327 let y, h
= rowyh cl
b pageno in
1328 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1330 if conf.presentation
1336 if Array.length
b = 0
1340 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1344 let getpageyh pageno =
1345 let y,_,h
= getpageywh pageno in
1349 let getpagedim pageno =
1352 | (n, _, _, _) as pdim
:: rest
->
1354 then (if n = pageno then pdim
else ppdim
)
1359 f (-1, -1, -1, -1) state.pdims
1362 let getpagey pageno = fst
(getpageyh pageno);;
1364 let nogeomcmds cmds
=
1366 | s, [] -> emptystr
s
1371 let ((c, coverA
, coverB
) as cl
), b =
1372 match conf.columns
with
1373 | Csingle
b -> (1, 0, 0), b
1374 | Cmulti
(c, b) -> c, b
1375 | Csplit
(_, b) -> (1, 0, 0), b
1377 if Array.length
b = 0
1380 let rec bsearch nmin nmax
=
1382 then bound nmin
0 (state.pagecount
-1)
1384 let n = (nmax
+ nmin
) / 2 in
1385 let vy, h
= rowyh cl
b n in
1387 if conf.presentation
1389 let ips = calcips h
in
1390 let y0 = vy - ips in
1391 let y1 = vy + h
+ ips in
1395 then 0, vy + h
+ conf.interpagespace
1397 let y0 = vy - conf.interpagespace
in
1398 y0, y0 + h
+ conf.interpagespace
1401 if y >= y0 && y < y1
1408 if n < state.pagecount
- coverB
1409 then ((n-coverA
)/c)*c + coverA
1416 then bsearch (n+1) nmax
1417 else bsearch nmin
(n-1)
1420 bsearch 0 (state.pagecount
-1);
1423 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1424 let sh = sh - (hscrollh ()) in
1425 let rec fold accu
n =
1426 if n = Array.length
b
1429 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1432 || n = state.pagecount
- coverB
1433 || (n - coverA
) mod columns
= columns
- 1)
1439 let pagey = max
0 (y - vy) in
1440 let pagedispy = if pagey > 0 then 0 else vy - y in
1441 let pagedispx, pagex
=
1443 if n = coverA
- 1 || n = state.pagecount
- coverB
1444 then state.x + (wadjsb state.winw
- w
) / 2
1445 else dx + xoff
+ state.x
1452 let vw = wadjsb state.winw
- pagedispx in
1453 let pw = w
- pagex
in
1456 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1457 if pagevw > 0 && pagevh > 0
1461 ; pagedimno
= pdimno
1468 ; pagedispx = pagedispx
1469 ; pagedispy = pagedispy
1481 if Array.length
b = 0
1483 else List.rev
(fold [] (page_of_y y))
1486 let layoutS (columns
, b) y sh =
1487 let sh = sh - hscrollh () in
1488 let rec fold accu n =
1489 if n = Array.length
b
1492 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1499 let x = xoff
+ state.x in
1500 let pagey = max
0 (y - vy) in
1501 let pagedispy = if pagey > 0 then 0 else vy - y in
1502 let pagedispx, pagex
=
1516 let pagecolw = pagew
/columns
in
1518 if pagecolw < state.winw
1519 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1523 let vw = wadjsb state.winw
- pagedispx in
1524 let pw = pagew
- pagex
in
1527 let pagevw = min
pagevw pagecolw in
1528 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1529 if pagevw > 0 && pagevh > 0
1532 { pageno = n/columns
1533 ; pagedimno
= pdimno
1540 ; pagedispx = pagedispx
1541 ; pagedispy = pagedispy
1542 ; pagecol
= n mod columns
1553 List.rev
(fold [] 0)
1557 if nogeomcmds state.geomcmds
1559 match conf.columns
with
1560 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1561 | Cmulti
c -> layoutN c y sh
1562 | Csplit
s -> layoutS s y sh
1567 let y = state.y + incr
in
1569 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1574 let tilex = l.pagex
mod conf.tilew
in
1575 let tiley = l.pagey mod conf.tileh
in
1577 let col = l.pagex
/ conf.tilew
in
1578 let row = l.pagey / conf.tileh
in
1580 let rec rowloop row y0 dispy h
=
1584 let dh = conf.tileh
- y0 in
1585 let dh = min h
dh in
1586 let rec colloop col x0 dispx w
=
1590 let dw = conf.tilew
- x0 in
1591 let dw = min w
dw in
1593 f col row dispx dispy
x0 y0 dw dh;
1594 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1597 colloop col tilex l.pagedispx l.pagevw;
1598 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1601 if l.pagevw > 0 && l.pagevh > 0
1602 then rowloop row tiley l.pagedispy l.pagevh;
1605 let gettileopaque l col row =
1607 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1609 try Some
(Hashtbl.find state.tilemap
key)
1610 with Not_found
-> None
1613 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1614 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1615 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1618 let filledrect x0 y0 x1 y1 =
1619 GlArray.disable `texture_coord
;
1620 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1621 GlArray.vertex `two
state.vraw
;
1622 GlArray.draw_arrays `triangle_strip
0 4;
1623 GlArray.enable `texture_coord
;
1626 let linerect x0 y0 x1 y1 =
1627 GlArray.disable `texture_coord
;
1628 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1629 GlArray.vertex `two
state.vraw
;
1630 GlArray.draw_arrays `line_loop
0 4;
1631 GlArray.enable `texture_coord
;
1634 let drawtiles l color
=
1637 let f col row x y tilex tiley w h
=
1638 match gettileopaque l col row with
1639 | Some
(opaque
, _, t
) ->
1640 let params = x, y, w
, h
, tilex, tiley in
1642 then GlTex.env
(`mode `blend
);
1643 drawtile
params opaque
;
1645 then GlTex.env
(`mode `modulate
);
1649 let s = Printf.sprintf
1653 let w = measurestr
fstate.fontsize
s in
1654 GlDraw.color
(0.0, 0.0, 0.0);
1655 filledrect (float (x-2))
1658 (float (y + fstate.fontsize
+ 2));
1659 GlDraw.color
(1.0, 1.0, 1.0);
1660 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1667 let lw = wadjsb state.winw
- x in
1670 let lh = state.winh
- y in
1674 then GlTex.env
(`mode `blend
);
1675 begin match state.texid
with
1677 Gl.enable `texture_2d
;
1678 GlTex.bind_texture `texture_2d id
;
1681 and x1 = float (x+w)
1682 and y1 = float (y+h
) in
1684 let tw = float w /. 16.0
1685 and th
= float h
/. 16.0 in
1686 let tx0 = float tilex /. 16.0
1687 and ty0
= float tiley /. 16.0 in
1689 and ty1
= ty0
+. th
in
1690 Raw.sets_float
state.vraw ~pos
:0
1691 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1692 Raw.sets_float
state.traw ~pos
:0
1693 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1694 GlArray.vertex `two
state.vraw
;
1695 GlArray.tex_coord `two
state.traw
;
1696 GlArray.draw_arrays `triangle_strip
0 4;
1697 Gl.disable `texture_2d
;
1700 GlDraw.color
(1.0, 1.0, 1.0);
1701 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1704 then GlTex.env
(`mode `modulate
);
1705 if w > 128 && h
> fstate.fontsize
+ 10
1707 let c = if conf.invert
then 1.0 else 0.0 in
1708 GlDraw.color
(c, c, c);
1711 then (col*conf.tilew
, row*conf.tileh
)
1714 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1723 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1725 let tilevisible1 l x y =
1727 and ax1
= l.pagex
+ l.pagevw
1729 and ay1
= l.pagey + l.pagevh in
1733 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1734 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1736 let rx0 = max
ax0 bx0
1737 and ry0
= max ay0 by0
1738 and rx1
= min ax1
bx1
1739 and ry1
= min ay1 by1
in
1741 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1742 nonemptyintersection
1745 let tilevisible layout n x y =
1746 let rec findpageinlayout m
= function
1747 | l :: rest
when l.pageno = n ->
1748 tilevisible1 l x y || (
1749 match conf.columns
with
1750 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1753 | _ :: rest
-> findpageinlayout 0 rest
1756 findpageinlayout 0 layout;
1759 let tileready l x y =
1760 tilevisible1 l x y &&
1761 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1764 let tilepage n p
layout =
1765 let rec loop = function
1769 let f col row _ _ _ _ _ _ =
1770 if state.currently
= Idle
1772 match gettileopaque l col row with
1775 let x = col*conf.tilew
1776 and y = row*conf.tileh
in
1778 let w = l.pagew
- x in
1782 let h = l.pageh
- y in
1787 then getpbo
w h conf.colorspace
1790 wcmd "tile %s %d %d %d %d %s"
1791 (~
> p
) x y w h (~
> pbo);
1794 l, p
, conf.colorspace
, conf.angle
,
1795 state.gen
, col, row, conf.tilew
, conf.tileh
1804 if nogeomcmds state.geomcmds
1808 let preloadlayout y =
1809 let y = if y < state.winh
then 0 else y - state.winh
in
1810 let h = state.winh
*3 in
1815 let rec loop pages
=
1816 if state.currently
!= Idle
1821 begin match getopaque l.pageno with
1823 wcmd "page %d %d" l.pageno l.pagedimno
;
1824 state.currently
<- Loading
(l, state.gen
);
1826 tilepage l.pageno opaque pages
;
1831 if nogeomcmds state.geomcmds
1837 if conf.preload && state.currently
= Idle
1838 then load (preloadlayout state.y);
1841 let layoutready layout =
1842 let rec fold all ls
=
1843 all
&& match ls
with
1845 let seen = ref false in
1846 let allvisible = ref true in
1847 let foo col row _ _ _ _ _ _ =
1849 allvisible := !allvisible &&
1850 begin match gettileopaque l col row with
1856 fold (!seen && !allvisible) rest
1859 let alltilesvisible = fold true layout in
1864 let y = bound y 0 state.maxy
in
1865 let y, layout, proceed
=
1866 match conf.maxwait
with
1867 | Some time
when state.ghyll
== noghyll ->
1868 begin match state.throttle
with
1870 let layout = layout y state.winh
in
1871 let ready = layoutready layout in
1875 state.throttle
<- Some
(layout, y, now ());
1877 else G.postRedisplay "gotoy showall (None)";
1879 | Some
(_, _, started
) ->
1880 let dt = now () -. started
in
1883 state.throttle
<- None
;
1884 let layout = layout y state.winh
in
1886 G.postRedisplay "maxwait";
1893 let layout = layout y state.winh
in
1894 if not
!wtmode || layoutready layout
1895 then G.postRedisplay "gotoy ready";
1901 state.layout <- layout;
1902 begin match state.mode
with
1903 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1904 let rec loop = function
1906 state.mode
<- LinkNav
(Ltgendir
0)
1907 | l :: _ when l.pageno = pageno ->
1908 begin match getopaque pageno with
1910 state.mode
<- LinkNav
(Ltgendir
0)
1912 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1913 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1914 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1915 then state.mode
<- LinkNav
(Ltgendir
0)
1917 | _ :: rest
-> loop rest
1922 begin match state.mode
with
1923 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1924 if not
(pagevisible layout pageno)
1926 match state.layout with
1929 state.mode
<- Birdseye
(
1930 conf, leftx
, l.pageno, hooverpageno
, anchor
1933 | LinkNav
(Ltgendir dir
as lt
) ->
1935 let rec loop = function
1938 match getopaque l.pageno with
1944 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1946 if dir
> 0 then LDfirst
else LDlast
1952 | Lnotfound
-> loop rest
1954 showlinktype (getlink opaque
n);
1955 Ltexact
(l.pageno, n)
1959 state.mode
<- LinkNav
linknav
1964 state.ghyll
<- noghyll;
1967 let mx, my
= state.mpos
in
1972 let conttiling pageno opaque
=
1973 tilepage pageno opaque
1974 (if conf.preload then preloadlayout state.y else state.layout)
1977 let gotoy_and_clear_text y =
1978 if not
conf.verbose
then state.text <- "";
1984 let coloff = l.pagecol
* l.pageh
in
1985 float (l.pagey + coloff) /. float l.pageh
1992 if conf.presentation
1993 then float l.pagedispy /. float (calcips l.pageh
)
1994 else float l.pagedispy /. float conf.interpagespace
1997 (l.pageno, top, dtop)
2001 match state.layout with
2002 | l :: _ -> getanchor1 l
2004 let n = page_of_y state.y in
2008 let y, h = getpageyh n in
2009 let dy = y - state.y in
2011 if conf.presentation
2013 let ips = calcips h in
2014 float (dy + ips) /. float ips
2016 float dy /. float conf.interpagespace
2021 let getanchory (n, top, dtop) =
2022 let y, h = getpageyh n in
2023 if conf.presentation
2025 let ips = calcips h in
2026 y + truncate
(top*.float h -. dtop*.float ips) + ips;
2028 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
2031 let gotoanchor anchor
=
2032 gotoy (getanchory anchor
);
2036 cbput state.hists
.nav
(getanchor ());
2040 let anchor = cbgetc state.hists
.nav dir
in
2044 let gotoghyll1 single
y =
2045 let scroll f n a
b =
2046 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2048 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2050 then s (float f /. float a
)
2053 then 1.0 -. s ((float (f-b) /. float (n-b)))
2059 let ins = float a
*. 0.5
2060 and outs
= float (n-b) *. 0.5 in
2062 ins +. outs
+. float ones
2064 let rec set nab
y sy
=
2065 let (_N
, _A
, _B
), y =
2068 let scl = if y > sy
then 2 else -2 in
2069 let _N, _, _ = nab
in
2070 (_N,0,_N), y+conf.scrollstep
*scl
2072 let sum = summa
_N _A _B
in
2073 let dy = float (y - sy
) in
2077 then state.ghyll
<- noghyll
2080 let s = scroll n _N _A _B
in
2081 let y1 = y1 +. ((s *. dy) /. sum) in
2082 gotoy_and_clear_text (truncate
y1);
2083 state.ghyll
<- gf (n+1) y1;
2087 | Some
y'
when single
-> set nab
y'
state.y
2088 | Some
y'
-> set (_N/2, 1, 1) y'
state.y
2090 gf 0 (float state.y)
2093 match conf.ghyllscroll
with
2094 | Some nab
when not
conf.presentation
->
2095 if state.ghyll
== noghyll
2096 then set nab
y state.y
2097 else state.ghyll
(Some
y)
2099 gotoy_and_clear_text y
2102 let gotoghyll = gotoghyll1 false;;
2104 let gotopage n top =
2105 let y, h = getpageyh n in
2106 let y = y + (truncate
(top *. float h)) in
2110 let gotopage1 n top =
2111 let y = getpagey n in
2116 let invalidate s f =
2121 match state.geomcmds
with
2122 | ps
, [] when emptystr ps
->
2124 state.geomcmds
<- s, [];
2127 state.geomcmds
<- ps
, [s, f];
2129 | ps
, (s'
, _) :: rest
when s'
= s ->
2130 state.geomcmds
<- ps
, ((s, f) :: rest
);
2133 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2137 Hashtbl.iter
(fun _ opaque
->
2138 wcmd "freepage %s" (~
> opaque
);
2140 Hashtbl.clear
state.pagemap
;
2144 if not
(Queue.is_empty
state.tilelru
)
2146 Queue.iter
(fun (k
, p
, s) ->
2147 wcmd "freetile %s" (~
> p
);
2148 state.memused
<- state.memused
- s;
2149 Hashtbl.remove
state.tilemap k
;
2151 state.uioh#infochanged Memused
;
2152 Queue.clear
state.tilelru
;
2158 let h = truncate
(float h*.conf.zoom
) in
2159 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2163 let opendoc path password
=
2165 state.password
<- password
;
2166 state.gen
<- state.gen
+ 1;
2167 state.docinfo
<- [];
2170 setaalevel
conf.aalevel
;
2172 if emptystr
state.origin
2176 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2177 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2178 invalidate "reqlayout"
2180 wcmd "reqlayout %d %d %d %s\000"
2181 conf.angle
(FMTE.to_int conf.fitmodel
)
2182 (stateh state.winh
) state.nameddest
2187 state.anchor <- getanchor ();
2188 opendoc state.path
state.password
;
2192 let c = c *. conf.colorscale
in
2196 let scalecolor2 (r
, g, b) =
2197 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2200 let docolumns = function
2202 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2203 let rec loop pageno pdimno pdim
y ph pdims
=
2204 if pageno = state.pagecount
2207 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2209 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2210 pdimno+1, pdim
, rest
2214 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2216 (if conf.presentation
2217 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2218 else (if pageno = 0 then 0 else conf.interpagespace
)
2221 a.(pageno) <- (pdimno, x, y, pdim
);
2222 loop (pageno+1) pdimno pdim
(y + h) h pdims
2224 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2225 conf.columns
<- Csingle
a;
2227 | Cmulti
((columns
, coverA
, coverB
), _) ->
2228 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2229 let rec loop pageno pdimno pdim
x y rowh pdims
=
2230 let rec fixrow m
= if m
= pageno then () else
2231 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2234 let y = y + (rowh
- h) / 2 in
2235 a.(m
) <- (pdimno, x, y, pdim
);
2239 if pageno = state.pagecount
2240 then fixrow (((pageno - 1) / columns
) * columns
)
2242 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2244 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2245 pdimno+1, pdim
, rest
2250 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2252 let x = (wadjsb state.winw
- w) / 2 in
2254 if conf.presentation
then calcips h else conf.interpagespace
in
2255 x, y + ips + rowh
, h
2258 if (pageno - coverA
) mod columns
= 0
2260 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2262 if conf.presentation
2264 let ips = calcips h in
2265 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2267 y + (if pageno = 0 then 0 else conf.interpagespace
)
2271 else x, y, max rowh
h
2275 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2278 if pageno = columns
&& conf.presentation
2280 let ips = calcips rowh
in
2281 for i
= 0 to pred columns
2283 let (pdimno, x, y, pdim
) = a.(i
) in
2284 a.(i
) <- (pdimno, x, y+ips, pdim
)
2290 fixrow (pageno - columns
);
2295 a.(pageno) <- (pdimno, x, y, pdim
);
2296 let x = x + w + xoff
*2 + conf.interpagespace
in
2297 loop (pageno+1) pdimno pdim
x y rowh' pdims
2299 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2300 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2303 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2304 let rec loop pageno pdimno pdim
y pdims
=
2305 if pageno = state.pagecount
2308 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2310 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2311 pdimno+1, pdim
, rest
2316 let rec loop1 n x y =
2317 if n = c then y else (
2318 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2319 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2322 let y = loop1 0 0 y in
2323 loop (pageno+1) pdimno pdim
y pdims
2325 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2326 conf.columns
<- Csplit
(c, a);
2330 docolumns conf.columns
;
2331 state.maxy
<- calcheight ();
2332 if state.reprf
== noreprf
2334 match state.mode
with
2335 | Birdseye
(_, _, pageno, _, _) ->
2336 let y, h = getpageyh pageno in
2337 let top = (state.winh
- h) / 2 in
2338 gotoy (max
0 (y - top))
2339 | _ -> gotoanchor state.anchor
2343 state.reprf
<- noreprf;
2348 GlDraw.viewport
0 0 w h;
2349 let firsttime = state.geomcmds
== firstgeomcmds in
2350 if not
firsttime && nogeomcmds state.geomcmds
2351 then state.anchor <- getanchor ();
2354 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2357 setfontsize fstate.fontsize
;
2358 GlMat.mode `modelview
;
2359 GlMat.load_identity
();
2361 GlMat.mode `projection
;
2362 GlMat.load_identity
();
2363 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2364 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2365 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2370 else float state.x /. float state.w
2372 invalidate "geometry"
2376 then state.x <- truncate
(relx *. float w);
2378 match conf.columns
with
2380 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2381 | Csplit
(c, _) -> w * c
2383 wcmd "geometry %d %d %d"
2384 w (stateh h) (FMTE.to_int conf.fitmodel
)
2389 let len = String.length
state.text in
2392 match state.mode
with
2393 | Textentry
_ | View
| LinkNav
_ ->
2394 let h, _, _ = state.uioh#scrollpw
in
2399 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2400 (x+.w) (float (state.winh
- hscrollh))
2403 let w = float (wadjsb state.winw
- 1) in
2404 if state.progress
>= 0.0 && state.progress
< 1.0
2406 GlDraw.color
(0.3, 0.3, 0.3);
2407 let w1 = w *. state.progress
in
2409 GlDraw.color
(0.0, 0.0, 0.0);
2413 GlDraw.color
(0.0, 0.0, 0.0);
2417 GlDraw.color
(1.0, 1.0, 1.0);
2418 drawstring fstate.fontsize
2419 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2422 match state.mode
with
2423 | Textentry
((prefix
, text, _, _, _, _), _) ->
2427 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2429 Printf.sprintf
"%s%s_" prefix
text
2438 if not
(istextentry state.mode
) && state.uioh#eformsgs
2440 let s1 = "(press 'e' to review error messasges)" in
2441 if nonemptystr
s then s ^
" " ^
s1 else s1
2451 let len = Queue.length
state.tilelru
in
2453 match state.throttle
with
2456 then preloadlayout state.y
2458 | Some
(layout, _, _) ->
2462 if state.memused
<= conf.memlimit
2467 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2468 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2469 let (_, pw, ph
, _) = getpagedim n in
2472 && colorspace
= conf.colorspace
2473 && angle
= conf.angle
2477 let x = col*conf.tilew
2478 and y = row*conf.tileh
in
2479 tilevisible (Lazy.force_val
layout) n x y
2481 then Queue.push lruitem
state.tilelru
2484 wcmd "freetile %s" (~
> p
);
2485 state.memused
<- state.memused
- s;
2486 state.uioh#infochanged Memused
;
2487 Hashtbl.remove
state.tilemap k
;
2495 let logcurrently = function
2496 | Idle
-> dolog
"Idle"
2497 | Loading
(l, gen
) ->
2498 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2499 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2501 "Tiling %d[%d,%d] page=%s cs=%s angle"
2502 l.pageno col row (~
> pageopaque
)
2503 (CSTE.to_string colorspace
)
2505 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2506 angle gen
conf.angle
state.gen
2508 conf.tilew
conf.tileh
2515 let r = Str.regexp
" " in
2516 fun s -> Str.bounded_split
r s 2;
2519 let onpagerect pageno f =
2521 match conf.columns
with
2522 | Cmulti
(_, b) -> b
2524 | Csplit
(_, b) -> b
2526 if pageno >= 0 && pageno < Array.length
b
2528 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2532 let gotopagexy1 pageno x y =
2533 let _,w1,h1
,leftx
= getpagedim pageno in
2534 let top = y /. (float h1
) in
2535 let left = x /. (float w1) in
2536 let py, w, h = getpageywh pageno in
2537 let wh = state.winh
- hscrollh () in
2538 let x = left *. (float w) in
2539 let x = leftx
+ state.x + truncate
x in
2541 if x < 0 || x >= wadjsb state.winw
2545 let pdy = truncate
(top *. float h) in
2546 let y'
= py + pdy in
2547 let dy = y'
- state.y in
2549 if x != state.x || not
(dy > 0 && dy < wh)
2551 if conf.presentation
2553 if abs
(py - y'
) > wh
2560 if state.x != sx || state.y != sy
2565 let ww = wadjsb state.winw
in
2567 and qy
= pdy / wh in
2569 and y = py + qy
* wh in
2570 let x = if -x + ww > w1 then -(w1-ww) else x
2571 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2573 if conf.presentation
2575 if abs
(py - y'
) > wh
2585 gotoy_and_clear_text y;
2587 else gotoy_and_clear_text state.y;
2590 let gotopagexy pageno x y =
2591 match state.mode
with
2592 | Birdseye
_ -> gotopage pageno 0.0
2593 | _ -> gotopagexy1 pageno x y
2597 (* dolog "%S" cmds; *)
2598 let cl = splitatspace cmds
in
2600 try Scanf.sscanf
s fmt
f
2602 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2605 let addoutline outline
=
2606 match state.currently
with
2607 | Outlining outlines
->
2608 state.currently
<- Outlining
(outline
:: outlines
)
2609 | Idle
-> state.currently
<- Outlining
[outline
]
2611 dolog
"invalid outlining state";
2612 logcurrently currently
2616 state.uioh#infochanged Pdim
;
2619 | "clearrects" :: [] ->
2620 state.rects
<- state.rects1
;
2621 G.postRedisplay "clearrects";
2623 | "continue" :: args :: [] ->
2624 let n = scan args "%u" (fun n -> n) in
2625 state.pagecount
<- n;
2626 begin match state.currently
with
2628 state.currently
<- Idle
;
2629 state.outlines
<- Array.of_list
(List.rev
l)
2633 let cur, cmds
= state.geomcmds
in
2635 then failwith
"umpossible";
2637 begin match List.rev cmds
with
2639 state.geomcmds
<- "", [];
2640 state.throttle
<- None
;
2644 state.geomcmds
<- s, List.rev rest
;
2646 if conf.maxwait
= None
&& not
!wtmode
2647 then G.postRedisplay "continue";
2649 | "title" :: args :: [] ->
2652 | "msg" :: args :: [] ->
2655 | "vmsg" :: args :: [] ->
2657 then showtext ' '
args
2659 | "emsg" :: args :: [] ->
2660 Buffer.add_string
state.errmsgs
args;
2661 state.newerrmsgs
<- true;
2662 G.postRedisplay "error message"
2664 | "progress" :: args :: [] ->
2665 let progress, text =
2668 f, String.sub
args pos
(String.length
args - pos
))
2671 state.progress <- progress;
2672 G.postRedisplay "progress"
2674 | "firstmatch" :: args :: [] ->
2675 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2676 scan args "%u %d %f %f %f %f %f %f %f %f"
2677 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2678 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2680 let y = (getpagey pageno) + truncate
y0 in
2683 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2685 | "match" :: args :: [] ->
2686 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2687 scan args "%u %d %f %f %f %f %f %f %f %f"
2688 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2689 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2692 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2694 | "page" :: args :: [] ->
2695 let pageopaques, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2696 let pageopaque = ~
< pageopaques in
2697 begin match state.currently
with
2698 | Loading
(l, gen
) ->
2699 vlog "page %d took %f sec" l.pageno t
;
2700 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2701 begin match state.throttle
with
2703 let preloadedpages =
2705 then preloadlayout state.y
2710 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2711 IntSet.empty
preloadedpages
2714 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2715 if not
(IntSet.mem
pageno set)
2717 wcmd "freepage %s" (~
> opaque
);
2723 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2726 state.currently
<- Idle
;
2729 tilepage l.pageno pageopaque state.layout;
2731 load preloadedpages;
2732 if pagevisible state.layout l.pageno
2733 && layoutready state.layout
2734 then G.postRedisplay "page";
2737 | Some
(layout, _, _) ->
2738 state.currently
<- Idle
;
2739 tilepage l.pageno pageopaque layout;
2744 dolog
"Inconsistent loading state";
2745 logcurrently state.currently
;
2749 | "tile" :: args :: [] ->
2750 let (x, y, opaques
, size
, t
) =
2751 scan args "%u %u %s %u %f"
2752 (fun x y p size t
-> (x, y, p
, size
, t
))
2754 let opaque = ~
< opaques
in
2755 begin match state.currently
with
2756 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2757 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2760 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2762 wcmd "freetile %s" (~
> opaque);
2763 state.currently
<- Idle
;
2767 puttileopaque l col row gen cs angle
opaque size t
;
2768 state.memused
<- state.memused
+ size
;
2769 state.uioh#infochanged Memused
;
2771 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2772 opaque, size
) state.tilelru
;
2775 match state.throttle
with
2776 | None
-> state.layout
2777 | Some
(layout, _, _) -> layout
2780 state.currently
<- Idle
;
2782 && conf.colorspace
= cs
2783 && conf.angle
= angle
2784 && tilevisible layout l.pageno x y
2785 then conttiling l.pageno pageopaque;
2787 begin match state.throttle
with
2789 preload state.layout;
2791 && conf.colorspace
= cs
2792 && conf.angle
= angle
2793 && tilevisible state.layout l.pageno x y
2794 && (not
!wtmode || layoutready state.layout)
2795 then G.postRedisplay "tile nothrottle";
2797 | Some
(layout, y, _) ->
2798 let ready = layoutready layout in
2802 state.layout <- layout;
2803 state.throttle
<- None
;
2804 G.postRedisplay "throttle";
2811 dolog
"Inconsistent tiling state";
2812 logcurrently state.currently
;
2816 | "pdim" :: args :: [] ->
2817 let (n, w, h, _) as pdim
=
2818 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2821 match conf.fitmodel
, conf.columns
with
2822 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2825 state.uioh#infochanged Pdim
;
2826 state.pdims
<- pdim :: state.pdims
2828 | "o" :: args :: [] ->
2829 let (l, n, t
, h, pos
) =
2830 scan args "%u %u %d %u %n"
2831 (fun l n t
h pos
-> l, n, t
, h, pos
)
2833 let s = String.sub
args pos
(String.length
args - pos
) in
2834 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
2836 | "ou" :: args :: [] ->
2837 let (l, len, pos
) = scan args "%u %u %n" (fun l len pos
-> l, len, pos
) in
2838 let s = String.sub
args pos
len in
2839 let pos2 = pos
+ len + 1 in
2840 let uri = String.sub
args pos2 (String.length
args - pos2) in
2841 addoutline (s, l, Ouri
uri)
2843 | "on" :: args :: [] ->
2844 let (l, pos
) = scan args "%u %n" (fun l pos
-> l, pos
) in
2845 let s = String.sub
args pos
(String.length
args - pos
) in
2846 addoutline (s, l, Onone
)
2848 | "a" :: args :: [] ->
2850 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2852 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2854 | "info" :: args :: [] ->
2855 state.docinfo
<- (1, args) :: state.docinfo
2857 | "infoend" :: [] ->
2858 state.uioh#infochanged Docinfo
;
2859 state.docinfo
<- List.rev
state.docinfo
2862 error
"unknown cmd `%S'" cmds
2867 let action = function
2868 | HCprev
-> cbget cb ~
-1
2869 | HCnext
-> cbget cb
1
2870 | HCfirst
-> cbget cb ~
-(cb
.rc)
2871 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2872 and cancel
() = cb
.rc <- rc
2876 let search pattern forward
=
2877 match conf.columns
with
2879 showtext '
!'
"searching does not work properly in split columns mode"
2881 if nonemptystr pattern
2884 match state.layout with
2887 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2889 wcmd "search %d %d %d %d,%s\000"
2890 (btod conf.icase
) pn py (btod forward
) pattern
;
2893 let intentry text key =
2895 if key >= 32 && key < 127
2901 let text = addchar text c in
2905 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2909 let linknentry text key =
2911 if key >= 32 && key < 127
2917 let text = addchar text c in
2921 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2929 let l = String.length
s in
2930 let rec loop pos
n = if pos
= l then n else
2931 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2932 loop (pos
+1) (n*26 + m)
2935 let rec loop n = function
2938 match getopaque l.pageno with
2939 | None
-> loop n rest
2941 let m = getlinkcount
opaque in
2944 let under = getlink
opaque n in
2947 else loop (n-m) rest
2949 loop n state.layout;
2953 let textentry text key =
2954 if key land 0xff00 = 0xff00
2956 else TEcont
(text ^ toutf8
key)
2959 let reqlayout angle fitmodel
=
2960 match state.throttle
with
2962 if nogeomcmds state.geomcmds
2963 then state.anchor <- getanchor ();
2964 conf.angle
<- angle
mod 360;
2967 match state.mode
with
2968 | LinkNav
_ -> state.mode
<- View
2971 conf.fitmodel
<- fitmodel
;
2972 invalidate "reqlayout"
2974 wcmd "reqlayout %d %d %d"
2975 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2980 let settrim trimmargins trimfuzz
=
2981 if nogeomcmds state.geomcmds
2982 then state.anchor <- getanchor ();
2983 conf.trimmargins
<- trimmargins
;
2984 conf.trimfuzz
<- trimfuzz
;
2985 let x0, y0, x1, y1 = trimfuzz
in
2986 invalidate "settrim"
2988 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2993 match state.throttle
with
2995 let zoom = max
0.0001 zoom in
2996 if zoom <> conf.zoom
2998 state.prevzoom
<- (conf.zoom, state.x);
3000 reshape state.winw
state.winh
;
3001 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
3004 | Some
(layout, y, started
) ->
3006 match conf.maxwait
with
3010 let dt = now () -. started
in
3018 let setcolumns mode columns coverA coverB
=
3019 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
3023 then showtext '
!'
"split mode doesn't work in bird's eye"
3025 conf.columns
<- Csplit
(-columns
, [||]);
3033 conf.columns
<- Csingle
[||];
3038 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
3042 reshape state.winw
state.winh
;
3045 let resetmstate () =
3046 state.mstate
<- Mnone
;
3047 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3050 let enterbirdseye () =
3051 let zoom = float conf.thumbw
/. float state.winw
in
3052 let birdseyepageno =
3053 let cy = state.winh
/ 2 in
3057 let rec fold best
= function
3060 let d = cy - (l.pagedispy + l.pagevh/2)
3061 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
3062 if abs
d < abs dbest
3069 state.mode
<- Birdseye
(
3070 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
3074 conf.presentation
<- false;
3075 conf.interpagespace
<- 10;
3076 conf.hlinks
<- false;
3077 conf.fitmodel
<- FitProportional
;
3079 conf.maxwait
<- None
;
3081 match conf.beyecolumns
with
3084 Cmulti
((c, 0, 0), [||])
3085 | None
-> Csingle
[||]
3089 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3094 reshape state.winw
state.winh
;
3097 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3099 conf.zoom <- c.zoom;
3100 conf.presentation
<- c.presentation
;
3101 conf.interpagespace
<- c.interpagespace
;
3102 conf.maxwait
<- c.maxwait
;
3103 conf.hlinks
<- c.hlinks
;
3104 conf.fitmodel
<- c.fitmodel
;
3105 conf.beyecolumns
<- (
3106 match conf.columns
with
3107 | Cmulti
((c, _, _), _) -> Some
c
3109 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3112 match c.columns
with
3113 | Cmulti
(c, _) -> Cmulti
(c, [||])
3114 | Csingle
_ -> Csingle
[||]
3115 | Csplit
(c, _) -> Csplit
(c, [||])
3119 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3122 reshape state.winw
state.winh
;
3123 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3127 let togglebirdseye () =
3128 match state.mode
with
3129 | Birdseye vals
-> leavebirdseye vals
true
3130 | View
-> enterbirdseye ()
3134 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3135 let pageno = max
0 (pageno - incr
) in
3136 let rec loop = function
3137 | [] -> gotopage1 pageno 0
3138 | l :: _ when l.pageno = pageno ->
3139 if l.pagedispy >= 0 && l.pagey = 0
3140 then G.postRedisplay "upbirdseye"
3141 else gotopage1 pageno 0
3142 | _ :: rest
-> loop rest
3145 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3148 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3149 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3150 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3151 let rec loop = function
3153 let y, h = getpageyh pageno in
3154 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3156 | l :: _ when l.pageno = pageno ->
3157 if l.pagevh != l.pageh
3158 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3159 else G.postRedisplay "downbirdseye"
3160 | _ :: rest
-> loop rest
3165 let boundastep h step
=
3167 then bound step ~
-h 0
3171 let optentry mode
_ key =
3172 let btos b = if b then "on" else "off" in
3173 if key >= 32 && key < 127
3175 let c = Char.chr
key in
3179 try conf.scrollstep
<- int_of_string
s with exc
->
3180 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3182 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3187 conf.autoscrollstep
<- boundastep state.winh
(int_of_string
s);
3188 if state.autoscroll
<> None
3189 then state.autoscroll
<- Some
conf.autoscrollstep
3191 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3193 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3198 let n, a, b = multicolumns_of_string s in
3199 setcolumns mode
n a b;
3201 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3203 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3208 let zoom = float (int_of_string
s) /. 100.0 in
3211 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3213 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3218 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3220 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3221 begin match mode
with
3223 leavebirdseye beye
false;
3228 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3230 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3235 Some
(int_of_string
s)
3237 state.text <- Printf.sprintf
"bad integer `%s': %s"
3241 | Some angle
-> reqlayout angle
conf.fitmodel
3244 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3247 conf.icase
<- not
conf.icase
;
3248 TEdone
("case insensitive search " ^
(btos conf.icase
))
3251 conf.preload <- not
conf.preload;
3253 TEdone
("preload " ^
(btos conf.preload))
3256 conf.verbose
<- not
conf.verbose
;
3257 TEdone
("verbose " ^
(btos conf.verbose
))
3260 conf.debug
<- not
conf.debug
;
3261 TEdone
("debug " ^
(btos conf.debug
))
3264 conf.maxhfit
<- not
conf.maxhfit
;
3265 state.maxy
<- calcheight ();
3266 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3269 conf.crophack
<- not
conf.crophack
;
3270 TEdone
("crophack " ^
btos conf.crophack
)
3274 match conf.maxwait
with
3276 conf.maxwait
<- Some infinity
;
3277 "always wait for page to complete"
3279 conf.maxwait
<- None
;
3280 "show placeholder if page is not ready"
3285 conf.underinfo
<- not
conf.underinfo
;
3286 TEdone
("underinfo " ^
btos conf.underinfo
)
3289 conf.savebmarks
<- not
conf.savebmarks
;
3290 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3296 match state.layout with
3301 conf.interpagespace
<- int_of_string
s;
3302 docolumns conf.columns
;
3303 state.maxy
<- calcheight ();
3304 let y = getpagey pageno in
3307 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3309 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3313 match conf.fitmodel
with
3314 | FitProportional
-> FitWidth
3315 | _ -> FitProportional
3317 reqlayout conf.angle
fm;
3318 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3321 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3322 TEdone
("trim margins " ^
btos conf.trimmargins
)
3325 conf.invert
<- not
conf.invert
;
3326 TEdone
("invert colors " ^
btos conf.invert
)
3330 cbput state.hists
.sel
s;
3333 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3334 textentry, ondone, true)
3338 then conf.pax
<- Some
(ref (0.0, 0, 0))
3339 else conf.pax
<- None
;
3340 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3343 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3349 class type lvsource
= object
3350 method getitemcount
: int
3351 method getitem
: int -> (string * int)
3352 method hasaction
: int -> bool
3360 method getactive
: int
3361 method getfirst
: int
3363 method getminfo
: (int * int) array
3366 class virtual lvsourcebase
= object
3367 val mutable m_active
= 0
3368 val mutable m_first
= 0
3369 val mutable m_pan
= 0
3370 method getactive
= m_active
3371 method getfirst
= m_first
3372 method getpan
= m_pan
3373 method getminfo
: (int * int) array
= [||]
3376 let withoutlastutf8 s =
3377 let len = String.length
s in
3385 let b = Char.code
s.[pos
] in
3386 if b land 0b11000000 = 0b11000000
3391 if Char.code
s.[len-1] land 0x80 = 0
3395 String.sub
s 0 first;
3398 let textentrykeyboard
3399 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3401 if key >= 0xffb0 && key <= 0xffb9
3402 then key - 0xffb0 + 48 else key
3405 state.mode
<- Textentry
(te
, onleave
);
3408 G.postRedisplay "textentrykeyboard enttext";
3410 let histaction cmd
=
3413 | Some
(action, _) ->
3414 state.mode
<- Textentry
(
3415 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3417 G.postRedisplay "textentry histaction"
3420 | 0xff08 -> (* backspace *)
3421 if emptystr
text && cancelonempty
3424 G.postRedisplay "textentrykeyboard after cancel";
3427 let s = withoutlastutf8 text in
3428 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3430 | 0xff0d | 0xff8d -> (* (kp) enter *)
3433 G.postRedisplay "textentrykeyboard after confirm"
3435 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3436 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3437 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3438 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3440 | 0xff1b -> (* escape*)
3443 begin match opthist
with
3445 | Some
(_, onhistcancel
) -> onhistcancel
()
3449 G.postRedisplay "textentrykeyboard after cancel2"
3452 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3455 | 0xff9f | 0xffff -> () (* delete *)
3458 && key land 0xff00 != 0xff00 (* keyboard *)
3459 && key land 0xfe00 != 0xfe00 (* xkb *)
3460 && key land 0xfd00 != 0xfd00 (* 3270 *)
3462 begin match onkey
text key with
3466 G.postRedisplay "textentrykeyboard after confirm2";
3469 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3473 G.postRedisplay "textentrykeyboard after cancel3"
3476 state.mode
<- Textentry
(te
, onleave
);
3477 G.postRedisplay "textentrykeyboard switch";
3481 vlog "unhandled key %s" (Wsi.keyname
key)
3484 let firstof first active
=
3485 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3486 then max
0 (active
- (fstate.maxrows
/2))
3490 let calcfirst first active
=
3493 let rows = active
- first in
3494 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3498 let scrollph y maxy
=
3499 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3500 let sh = float state.winh
/. sh in
3501 let sh = max
sh (float conf.scrollh
) in
3503 let percent = float y /. float maxy
in
3504 let position = (float state.winh
-. sh) *. percent in
3507 if position +. sh > float state.winh
3508 then float state.winh
-. sh
3514 let coe s = (s :> uioh
);;
3516 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3518 val m_pan
= source#getpan
3519 val m_first
= source#getfirst
3520 val m_active
= source#getactive
3522 val m_prev_uioh
= state.uioh
3524 method private elemunder
y =
3528 let n = y / (fstate.fontsize
+1) in
3529 if m_first
+ n < source#getitemcount
3531 if source#hasaction
(m_first
+ n)
3532 then Some
(m_first
+ n)
3539 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3540 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3541 filledrect 0. 0. (float state.winw
) (float state.winh
);
3542 GlDraw.color
(1., 1., 1.);
3543 Gl.enable `texture_2d
;
3544 let fs = fstate.fontsize
in
3546 let ww = fstate.wwidth
in
3547 let tabw = 30.0*.ww in
3548 let itemcount = source#getitemcount
in
3549 let minfo = source#getminfo
in
3551 if (row - m_first
) > fstate.maxrows
3554 if row >= 0 && row < itemcount
3556 let (s, level
) = source#getitem
row in
3557 let y = (row - m_first
) * nfs in
3558 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3561 Gl.disable `texture_2d
;
3562 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3563 GlDraw.color
(1., 1., 1.) ~
alpha;
3564 linerect 1. (float (y + 1))
3565 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3566 Gl.enable `texture_2d
;
3567 GlDraw.color
(1., 1., 1.);
3569 let drawtabularstring s =
3570 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3573 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3576 let len = String.length
s - tabpos - 1 in
3577 let s1 = String.sub
s 0 tabpos
3578 and s2
= String.sub
s (tabpos + 1) len in
3579 let nx = drawstr x s1 in
3581 let x = x +. (max
tabw sw) in
3588 let _ = drawtabularstring s in
3594 GlDraw.color
(1.0, 1.0, 1.0) ~
alpha:0.5;
3596 if (row - m_first
) > fstate.maxrows
3599 if row >= 0 && row < itemcount
3601 let (s, level
) = source#getitem
row in
3602 let y = (row - m_first
) * nfs in
3603 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3604 let (first, last
) = minfo.(row) in
3605 let prefix = String.sub
s 0 first in
3606 let suffix = String.sub
s first (last
- first) in
3607 let w1 = measurestr
fstate.fontsize
prefix in
3608 let w2 = measurestr
fstate.fontsize
suffix in
3610 and y0 = (float (y+2)) in
3612 and y1 = (float (y+fs+3)) in
3613 filledrect x0 y0 x1 y1;
3618 Gl.disable `texture_2d
;
3619 if Array.length
minfo > 0 then loop m_first
;
3622 method updownlevel incr
=
3623 let len = source#getitemcount
in
3625 if m_active
>= 0 && m_active
< len
3626 then snd
(source#getitem m_active
)
3630 if i
= len then i
-1 else if i
= -1 then 0 else
3631 let _, l = source#getitem i
in
3632 if l != curlevel then i
else flow (i
+incr
)
3634 let active = flow m_active
in
3635 let first = calcfirst m_first
active in
3636 G.postRedisplay "outline updownlevel";
3637 {< m_active
= active; m_first
= first >}
3639 method private key1
key mask
=
3640 let set1 active first qsearch
=
3641 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3643 let search active pattern incr
=
3644 let active = if active = -1 then m_first
else active in
3647 if n >= 0 && n < source#getitemcount
3649 let s, _ = source#getitem
n in
3651 (try ignore
(Str.search_forward
re s 0); true
3652 with Not_found
-> false)
3654 else loop (n + incr
)
3661 let re = Str.regexp_case_fold pattern
in
3667 let itemcount = source#getitemcount
in
3668 let find start incr
=
3670 if i
= -1 || i
= itemcount
3673 if source#hasaction i
3675 else find (i
+ incr
)
3680 let set active first =
3681 let first = bound first 0 (itemcount - fstate.maxrows
) in
3683 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3686 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3688 let incr1 = if incr
> 0 then 1 else -1 in
3689 if isvisible m_first m_active
3692 let next = m_active
+ incr
in
3694 if next < 0 || next >= itemcount
3696 else find next incr1
3698 if abs
(m_active
- next) > fstate.maxrows
3704 let first = m_first
+ incr
in
3705 let first = bound first 0 (itemcount - fstate.maxrows
) in
3707 let next = m_active
+ incr
in
3708 let next = bound next 0 (itemcount - 1) in
3715 if isvisible first next
3722 let first = min
next m_first
in
3724 if abs
(next - first) > fstate.maxrows
3730 let first = m_first
+ incr
in
3731 let first = bound first 0 (itemcount - 1) in
3733 let next = m_active
+ incr
in
3734 let next = bound next 0 (itemcount - 1) in
3735 let next = find next incr1 in
3737 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3739 let active = if m_active
= -1 then next else m_active
in
3744 if isvisible first active
3750 G.postRedisplay "listview navigate";
3754 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3755 let incr = if key = 0x72 then -1 else 1 in
3757 match search (m_active
+ incr) m_qsearch
incr with
3759 state.text <- m_qsearch ^
" [not found]";
3762 state.text <- m_qsearch
;
3763 active, firstof m_first
active
3765 G.postRedisplay "listview ctrl-r/s";
3766 set1 active first m_qsearch
;
3768 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3769 if m_active
>= 0 && m_active
< source#getitemcount
3771 let s, _ = source#getitem m_active
in
3776 | 0xff08 -> (* backspace *)
3777 if emptystr m_qsearch
3780 let qsearch = withoutlastutf8 m_qsearch
in
3784 G.postRedisplay "listview empty qsearch";
3785 set1 m_active m_first
"";
3789 match search m_active
qsearch ~
-1 with
3791 state.text <- qsearch ^
" [not found]";
3794 state.text <- qsearch;
3795 active, firstof m_first
active
3797 G.postRedisplay "listview backspace qsearch";
3798 set1 active first qsearch
3801 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3802 let pattern = m_qsearch ^ toutf8
key in
3804 match search m_active
pattern 1 with
3806 state.text <- pattern ^
" [not found]";
3809 state.text <- pattern;
3810 active, firstof m_first
active
3812 G.postRedisplay "listview qsearch add";
3813 set1 active first pattern;
3815 | 0xff1b -> (* escape *)
3817 if emptystr m_qsearch
3819 G.postRedisplay "list view escape";
3822 source#exit
(coe self
) true m_active m_first m_pan
3824 | None
-> m_prev_uioh
3829 G.postRedisplay "list view kill qsearch";
3830 coe {< m_qsearch
= "" >}
3833 | 0xff0d | 0xff8d -> (* (kp) enter *)
3835 let self = {< m_qsearch
= "" >} in
3837 G.postRedisplay "listview enter";
3838 if m_active
>= 0 && m_active
< source#getitemcount
3840 source#exit
(coe self) false m_active m_first m_pan
;
3843 source#exit
(coe self) true m_active m_first m_pan
;
3846 begin match opt with
3847 | None
-> m_prev_uioh
3851 | 0xff9f | 0xffff -> (* (kp) delete *)
3854 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3855 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3856 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3857 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3859 | 0xff53 | 0xff98 -> (* (kp) right *)
3861 G.postRedisplay "listview right";
3862 coe {< m_pan
= m_pan
- 1 >}
3864 | 0xff51 | 0xff96 -> (* (kp) left *)
3866 G.postRedisplay "listview left";
3867 coe {< m_pan
= m_pan
+ 1 >}
3869 | 0xff50 | 0xff95 -> (* (kp) home *)
3870 let active = find 0 1 in
3871 G.postRedisplay "listview home";
3874 | 0xff57 | 0xff9c -> (* (kp) end *)
3875 let first = max
0 (itemcount - fstate.maxrows
) in
3876 let active = find (itemcount - 1) ~
-1 in
3877 G.postRedisplay "listview end";
3880 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3884 dolog
"listview unknown key %#x" key; coe self
3886 method key key mask
=
3887 match state.mode
with
3888 | Textentry te
-> textentrykeyboard key mask te
; coe self
3889 | _ -> self#key1
key mask
3891 method button button down
x y _ =
3894 | 1 when x > state.winw
- conf.scrollbw
->
3895 G.postRedisplay "listview scroll";
3898 let _, position, sh = self#
scrollph in
3899 if y > truncate
position && y < truncate
(position +. sh)
3901 state.mstate
<- Mscrolly
;
3905 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3906 let first = truncate
(s *. float source#getitemcount
) in
3907 let first = min source#getitemcount
first in
3908 Some
(coe {< m_first
= first; m_active
= first >})
3910 state.mstate
<- Mnone
;
3913 | 1 when not down
->
3914 begin match self#elemunder
y with
3916 G.postRedisplay "listview click";
3917 source#exit
(coe {< m_active
= n >}) false n m_first m_pan
3921 | n when (n == 4 || n == 5) && not down
->
3922 let len = source#getitemcount
in
3924 if n = 5 && m_first
+ fstate.maxrows
>= len
3928 let first = m_first
+ (if n == 4 then -1 else 1) in
3929 bound first 0 (len - 1)
3931 G.postRedisplay "listview wheel";
3932 Some
(coe {< m_first
= first >})
3933 | n when (n = 6 || n = 7) && not down
->
3934 let inc = if n = 7 then -1 else 1 in
3935 G.postRedisplay "listview hwheel";
3936 Some
(coe {< m_pan
= m_pan
+ inc >})
3941 | None
-> m_prev_uioh
3944 method multiclick
_ x y = self#button
1 true x y
3947 match state.mstate
with
3949 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3950 let first = truncate
(s *. float source#getitemcount
) in
3951 let first = min source#getitemcount
first in
3952 G.postRedisplay "listview motion";
3953 coe {< m_first
= first; m_active
= first >}
3956 method pmotion
x y =
3957 if x < state.winw
- conf.scrollbw
3960 match self#elemunder
y with
3961 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3962 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3966 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3971 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3975 method infochanged
_ = ()
3977 method scrollpw
= (0, 0.0, 0.0)
3979 let nfs = fstate.fontsize
+ 1 in
3980 let y = m_first
* nfs in
3981 let itemcount = source#getitemcount
in
3982 let maxi = max
0 (itemcount - fstate.maxrows
) in
3983 let maxy = maxi * nfs in
3984 let p, h = scrollph y maxy in
3987 method modehash
= modehash
3988 method eformsgs
= false
3991 class outlinelistview ~source
=
3992 let settext autonarrow
s =
3995 let ss = source#statestr
in
3999 else "{" ^
ss ^
"} [" ^
s ^
"]"
4000 else state.text <- s
4004 ~source
:(source
:> lvsource
)
4006 ~modehash
:(findkeyhash conf "outline")
4009 val m_autonarrow
= false
4011 method display
= super#display
4013 method key key mask
=
4015 if emptystr
state.text
4017 else fstate.maxrows - 2
4019 let calcfirst first active =
4022 let rows = active - first in
4023 if rows > maxrows then active - maxrows else first
4027 let active = m_active
+ incr in
4028 let active = bound active 0 (source#getitemcount
- 1) in
4029 let first = calcfirst m_first
active in
4030 G.postRedisplay "outline navigate";
4031 coe {< m_active
= active; m_first
= first >}
4033 let navscroll first =
4035 let dist = m_active
- first in
4041 else first + maxrows
4044 G.postRedisplay "outline navscroll";
4045 coe {< m_first
= first; m_active
= active >}
4047 let ctrl = Wsi.withctrl mask
in
4049 | 97 when ctrl -> (* ctrl-a *)
4052 then (source#denarrow
; "")
4054 let pattern = source#renarrow
in
4055 if nonemptystr m_qsearch
4056 then (source#narrow m_qsearch
; m_qsearch
)
4060 settext (not m_autonarrow
) text;
4061 G.postRedisplay "toggle auto narrowing";
4062 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
4064 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
4066 G.postRedisplay "toggle auto narrowing";
4067 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
4069 | 110 when ctrl -> (* ctrl-n *)
4070 source#narrow m_qsearch
;
4072 then source#add_narrow_pattern m_qsearch
;
4073 G.postRedisplay "outline ctrl-n";
4074 coe {< m_first
= 0; m_active
= 0 >}
4076 | 83 when ctrl -> (* ctrl-S *)
4077 let active = source#calcactive
(getanchor ()) in
4078 let first = firstof m_first
active in
4079 G.postRedisplay "outline ctrl-s";
4080 coe {< m_first
= first; m_active
= active >}
4082 | 117 when ctrl -> (* ctrl-u *)
4083 G.postRedisplay "outline ctrl-u";
4084 if m_autonarrow
&& nonemptystr m_qsearch
4086 ignore
(source#renarrow
);
4087 settext m_autonarrow
"";
4088 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4091 source#del_narrow_pattern
;
4092 let pattern = source#renarrow
in
4094 if emptystr
pattern then "" else "Narrowed to " ^
pattern
4096 settext m_autonarrow
text;
4097 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4100 | 108 when ctrl -> (* ctrl-l *)
4101 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
4102 G.postRedisplay "outline ctrl-l";
4103 coe {< m_first
= first >}
4105 | 0xff09 when m_autonarrow
-> (* tab *)
4106 if nonemptystr m_qsearch
4108 G.postRedisplay "outline list view tab";
4109 source#add_narrow_pattern m_qsearch
;
4111 coe {< m_qsearch
= "" >}
4115 | 0xff1b when m_autonarrow
-> (* escape *)
4116 if nonemptystr m_qsearch
4117 then source#add_narrow_pattern m_qsearch
;
4120 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
4121 if nonemptystr m_qsearch
4122 then source#add_narrow_pattern m_qsearch
;
4125 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
4126 let pattern = m_qsearch ^ toutf8
key in
4127 G.postRedisplay "outlinelistview autonarrow add";
4128 source#narrow
pattern;
4129 settext true pattern;
4130 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4132 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4133 if emptystr m_qsearch
4136 let pattern = withoutlastutf8 m_qsearch
in
4137 G.postRedisplay "outlinelistview autonarrow backspace";
4138 ignore
(source#renarrow
);
4139 source#narrow
pattern;
4140 settext true pattern;
4141 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4143 | 0xff9f | 0xffff -> (* (kp) delete *)
4144 source#remove m_active
;
4145 G.postRedisplay "outline delete";
4146 let active = max
0 (m_active
-1) in
4147 coe {< m_first
= firstof m_first
active;
4148 m_active
= active >}
4150 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4151 navscroll (max
0 (m_first
- 1))
4153 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4154 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4156 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4157 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4158 | 0xff55 | 0xff9a -> (* (kp) prior *)
4159 navigate ~
-(fstate.maxrows)
4160 | 0xff56 | 0xff9b -> (* (kp) next *)
4161 navigate fstate.maxrows
4163 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4167 G.postRedisplay "outline ctrl right";
4168 {< m_pan
= m_pan
+ 1 >}
4170 else self#updownlevel
1
4174 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4178 G.postRedisplay "outline ctrl left";
4179 {< m_pan
= m_pan
- 1 >}
4181 else self#updownlevel ~
-1
4185 | 0xff50 | 0xff95 -> (* (kp) home *)
4186 G.postRedisplay "outline home";
4187 coe {< m_first
= 0; m_active
= 0 >}
4189 | 0xff57 | 0xff9c -> (* (kp) end *)
4190 let active = source#getitemcount
- 1 in
4191 let first = max
0 (active - fstate.maxrows) in
4192 G.postRedisplay "outline end";
4193 coe {< m_active
= active; m_first
= first >}
4195 | _ -> super#
key key mask
4198 let gotounder under =
4199 let getpath filename
=
4201 if nonemptystr filename
4203 if Filename.is_relative filename
4205 let dir = Filename.dirname
state.path in
4207 if Filename.is_implicit
dir
4208 then Filename.concat
(Sys.getcwd
()) dir
4211 Filename.concat
dir filename
4215 if Sys.file_exists
path
4220 | Ulinkgoto
(pageno, top) ->
4224 gotopage1 pageno top;
4230 | Uremote
(filename
, pageno) ->
4231 let path = getpath filename
in
4236 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
4237 try popen command []
4239 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
4242 let anchor = getanchor () in
4243 let ranchor = state.path, state.password
, anchor, state.origin
in
4245 state.anchor <- (pageno, 0.0, 0.0);
4246 state.ranchors
<- ranchor :: state.ranchors
;
4249 else showtext '
!'
("Could not find " ^ filename
)
4251 | Uremotedest
(filename
, destname
) ->
4252 let path = getpath filename
in
4257 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
4258 try popen command []
4261 "failed to execute `%s': %s\n" command (exntos exn
);
4264 let anchor = getanchor () in
4265 let ranchor = state.path, state.password
, anchor, state.origin
in
4267 state.nameddest
<- destname
;
4268 state.ranchors
<- ranchor :: state.ranchors
;
4271 else showtext '
!'
("Could not find " ^ filename
)
4273 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4276 let gotooutline (_, _, kind
) =
4280 let (pageno, y, _) = anchor in
4282 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4286 | Ouri
uri -> gotounder (Ulinkuri
uri)
4287 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
4288 | Oremote remote
-> gotounder (Uremote remote
)
4289 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
4292 let outlinesource usebookmarks
=
4295 inherit lvsourcebase
4296 val mutable m_items
= empty
4297 val mutable m_minfo
= empty
4298 val mutable m_orig_items
= empty
4299 val mutable m_orig_minfo
= empty
4300 val mutable m_narrow_patterns
= []
4301 val mutable m_hadremovals
= false
4302 val mutable m_gen
= -1
4304 method getitemcount
=
4305 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4308 if n == Array.length m_items
&& m_hadremovals
4310 ("[Confirm removal]", 0)
4312 let s, n, _ = m_items
.(n) in
4315 method exit ~uioh ~cancel ~
active ~
first ~pan
=
4316 ignore
(uioh
, first);
4317 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4319 if m_narrow_patterns
= []
4320 then m_orig_items
, m_orig_minfo
4321 else m_items
, m_minfo
4325 if not
confrimremoval
4327 gotooutline m_items
.(active);
4332 state.bookmarks
<- Array.to_list m_items
;
4333 m_orig_items
<- m_items
;
4334 m_orig_minfo
<- m_minfo
;
4344 method hasaction
_ = true
4347 if Array.length m_items
!= Array.length m_orig_items
4350 match m_narrow_patterns
with
4352 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
4354 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4358 match m_narrow_patterns
with
4361 | head
:: _ -> "\xe2\x80\xa6" ^ head
4363 method narrow
pattern =
4364 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4368 let rec loop accu minfo n =
4371 m_items
<- Array.of_list
accu;
4372 m_minfo
<- Array.of_list
minfo;
4375 let (s, _, _) as o = m_items
.(n) in
4378 try Str.search_forward
re s 0
4379 with Not_found
-> -1
4382 then o :: accu, (first, Str.match_end
()) :: minfo
4385 loop accu minfo (n-1)
4387 loop [] [] (Array.length m_items
- 1)
4389 method getminfo
= m_minfo
4394 then Array.of_list
state.bookmarks
4397 m_minfo
<- m_orig_minfo
;
4398 m_items
<- m_orig_items
4403 if m >= 0 && m < Array.length m_items
4405 m_hadremovals
<- true;
4406 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4407 let n = if n >= m then n+1 else n in
4412 method add_narrow_pattern
pattern =
4413 m_narrow_patterns
<- pattern :: m_narrow_patterns
4415 method del_narrow_pattern
=
4416 match m_narrow_patterns
with
4417 | _ :: rest
-> m_narrow_patterns
<- rest
4422 match m_narrow_patterns
with
4423 | pattern :: [] -> self#narrow
pattern; pattern
4425 List.fold_left
(fun accu pattern ->
4426 self#narrow
pattern;
4427 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
4429 method calcactive
anchor =
4430 let rely = getanchory anchor in
4431 let rec loop n best bestd
=
4432 if n = Array.length m_items
4435 let _, _, kind
= m_items
.(n) in
4438 let orely = getanchory anchor in
4439 let d = abs
(orely - rely) in
4442 else loop (n+1) best bestd
4443 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
4444 loop (n+1) best bestd
4448 method reset
anchor items =
4449 m_hadremovals
<- false;
4450 if state.gen
!= m_gen
4452 m_orig_items
<- items;
4454 m_narrow_patterns
<- [];
4456 m_orig_minfo
<- empty;
4460 if items != m_orig_items
4462 m_orig_items
<- items;
4463 if m_narrow_patterns
== []
4464 then m_items
<- items;
4467 let active = self#calcactive
anchor in
4469 m_first
<- firstof m_first
active
4473 let enterselector usebookmarks
=
4475 let source = outlinesource usebookmarks
in
4479 then Array.of_list
state.bookmarks
4482 if Array.length
outlines = 0
4484 showtext ' ' errmsg
;
4487 state.text <- source#greetmsg
;
4488 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4489 let anchor = getanchor () in
4490 source#reset
anchor outlines;
4491 state.uioh
<- coe (new outlinelistview ~
source);
4492 G.postRedisplay "enter selector";
4496 let enteroutlinemode =
4497 let f = enterselector false in
4498 fun ()-> f "Document has no outline";
4501 let enterbookmarkmode =
4502 let f = enterselector true in
4503 fun () -> f "Document has no bookmarks (yet)";
4506 let color_of_string s =
4507 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4508 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4512 let color_to_string (r, g, b) =
4513 let r = truncate
(r *. 256.0)
4514 and g = truncate
(g *. 256.0)
4515 and b = truncate
(b *. 256.0) in
4516 Printf.sprintf
"%d/%d/%d" r g b
4519 let irect_of_string s =
4520 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4523 let irect_to_string (x0,y0,x1,y1) =
4524 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4527 let makecheckers () =
4528 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4530 converted by Issac Trotts. July 25, 2002 *)
4531 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4532 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4533 let id = GlTex.gen_texture
() in
4534 GlTex.bind_texture `texture_2d
id;
4535 GlPix.store
(`unpack_alignment
1);
4536 GlTex.image2d
image;
4537 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4538 [ `mag_filter `nearest
; `min_filter `nearest
];
4542 let setcheckers enabled
=
4543 match state.texid
with
4545 if enabled
then state.texid
<- Some
(makecheckers ())
4550 GlTex.delete_texture texid
;
4551 state.texid
<- None
;
4555 let int_of_string_with_suffix s =
4556 let l = String.length
s in
4560 let suffix = Char.lowercase
s.[l-1] in
4562 | 'k'
-> String.sub
s 0 (l-1), 10
4563 | '
m'
-> String.sub
s 0 (l-1), 20
4564 | '
g'
-> String.sub
s 0 (l-1), 30
4568 let n = int_of_string
s1 in
4569 let m = n lsl shift
in
4571 then raise
(Failure
"value too large")
4575 let string_with_suffix_of_int n =
4579 let units = [(30, "G"); (20, "M"); (10, "K")] in
4582 let h = n mod 1000 in
4585 then string_of_int
h ^
s
4587 let s = Printf.sprintf
"_%03d%s" h s in
4593 let rec find = function
4595 | (shift
, suffix) :: rest
->
4596 if (n land ((1 lsl shift
) - 1)) = 0
4597 then prettyint (n lsr shift
) ^
suffix
4603 let fastghyllscroll = (5,1,2);;
4604 let neatghyllscroll = (10,1,9);;
4605 let ghyllscroll_of_string s =
4607 | "fast" -> Some
fastghyllscroll
4608 | "neat" -> Some
(10,1,9)
4609 | "" | "none" -> None
4611 let (n,a,b) as nab
=
4612 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4613 if n <= a || n <= b || a >= b
4614 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4619 let ghyllscroll_to_string ((n, a, b) as nab
) =
4620 (**) if nab
= fastghyllscroll then "fast"
4621 else if nab
= neatghyllscroll then "neat"
4622 else Printf.sprintf
"%d,%d,%d" n a b;
4625 let describe_location () =
4626 let fn = page_of_y state.y in
4627 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4628 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4632 else (100. *. (float state.y /. float maxy))
4636 Printf.sprintf
"page %d of %d [%.2f%%]"
4637 (fn+1) state.pagecount
percent
4640 "pages %d-%d of %d [%.2f%%]"
4641 (fn+1) (ln+1) state.pagecount
percent
4644 let setpresentationmode v
=
4645 let n = page_of_y state.y in
4646 state.anchor <- (n, 0.0, 1.0);
4647 conf.presentation
<- v
;
4648 if conf.fitmodel
= FitPage
4649 then reqlayout conf.angle
conf.fitmodel
;
4654 let btos b = if b then "\xe2\x88\x9a" else "" in
4655 let showextended = ref false in
4656 let leave mode
= function
4657 | Confirm
-> state.mode
<- mode
4658 | Cancel
-> state.mode
<- mode
in
4661 val mutable m_first_time
= true
4662 val mutable m_l
= []
4663 val mutable m_a
= [||]
4664 val mutable m_prev_uioh
= nouioh
4665 val mutable m_prev_mode
= View
4667 inherit lvsourcebase
4669 method reset prev_mode prev_uioh
=
4670 m_a
<- Array.of_list
(List.rev m_l
);
4672 m_prev_mode
<- prev_mode
;
4673 m_prev_uioh
<- prev_uioh
;
4677 if n >= Array.length m_a
4681 | _, _, _, Action
_ -> m_active
<- n
4685 m_first_time
<- false;
4688 method int name get
set =
4690 (name, `
int get
, 1, Action
(
4693 try set (int_of_string
s)
4695 state.text <- Printf.sprintf
"bad integer `%s': %s"
4699 let te = name ^
": ", "", None
, intentry, ondone, true in
4700 state.mode
<- Textentry
(te, leave m_prev_mode
);
4704 method int_with_suffix
name get
set =
4706 (name, `intws get
, 1, Action
(
4709 try set (int_of_string_with_suffix s)
4711 state.text <- Printf.sprintf
"bad integer `%s': %s"
4716 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4718 state.mode
<- Textentry
(te, leave m_prev_mode
);
4722 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4724 (name, `
bool (btos, get
), offset
, Action
(
4731 method color
name get
set =
4733 (name, `color get
, 1, Action
(
4735 let invalid = (nan
, nan
, nan
) in
4738 try color_of_string s
4740 state.text <- Printf.sprintf
"bad color `%s': %s"
4747 let te = name ^
": ", "", None
, textentry, ondone, true in
4748 state.text <- color_to_string (get
());
4749 state.mode
<- Textentry
(te, leave m_prev_mode
);
4753 method string name get
set =
4755 (name, `
string get
, 1, Action
(
4757 let ondone s = set s in
4758 let te = name ^
": ", "", None
, textentry, ondone, true in
4759 state.mode
<- Textentry
(te, leave m_prev_mode
);
4763 method colorspace
name get
set =
4765 (name, `
string get
, 1, Action
(
4769 inherit lvsourcebase
4772 m_active
<- CSTE.to_int conf.colorspace
;
4775 method getitemcount
=
4776 Array.length
CSTE.names
4779 method exit ~uioh ~cancel ~
active ~
first ~pan
=
4780 ignore
(uioh
, first, pan
);
4781 if not cancel
then set active;
4783 method hasaction
_ = true
4787 let modehash = findkeyhash conf "info" in
4788 coe (new listview ~
source ~trusted
:true ~
modehash)
4791 method paxmark
name get
set =
4793 (name, `
string get
, 1, Action
(
4797 inherit lvsourcebase
4800 m_active
<- MTE.to_int conf.paxmark
;
4803 method getitemcount
= Array.length
MTE.names
4804 method getitem
n = (MTE.names.(n), 0)
4805 method exit ~uioh ~cancel ~
active ~
first ~pan
=
4806 ignore
(uioh
, first, pan
);
4807 if not cancel
then set active;
4809 method hasaction
_ = true
4813 let modehash = findkeyhash conf "info" in
4814 coe (new listview ~
source ~trusted
:true ~
modehash)
4817 method fitmodel
name get
set =
4819 (name, `
string get
, 1, Action
(
4823 inherit lvsourcebase
4826 m_active
<- FMTE.to_int conf.fitmodel
;
4829 method getitemcount
= Array.length
FMTE.names
4830 method getitem
n = (FMTE.names.(n), 0)
4831 method exit ~uioh ~cancel ~
active ~
first ~pan
=
4832 ignore
(uioh
, first, pan
);
4833 if not cancel
then set active;
4835 method hasaction
_ = true
4839 let modehash = findkeyhash conf "info" in
4840 coe (new listview ~
source ~trusted
:true ~
modehash)
4843 method caption
s offset
=
4844 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4846 method caption2
s f offset
=
4847 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4849 method getitemcount
= Array.length m_a
4852 let tostr = function
4853 | `
int f -> string_of_int
(f ())
4854 | `intws
f -> string_with_suffix_of_int (f ())
4856 | `color
f -> color_to_string (f ())
4857 | `
bool (btos, f) -> btos (f ())
4860 let name, t
, offset
, _ = m_a
.(n) in
4861 ((let s = tostr t
in
4863 then Printf.sprintf
"%s\t%s" name s
4867 method exit ~uioh ~cancel ~
active ~
first ~pan
=
4872 match m_a
.(active) with
4873 | _, _, _, Action
f -> f uioh
4885 method hasaction
n =
4887 | _, _, _, Action
_ -> true
4891 let rec fillsrc prevmode prevuioh
=
4892 let sep () = src#caption
"" 0 in
4893 let colorp name get
set =
4895 (fun () -> color_to_string (get
()))
4898 let c = color_of_string v in
4901 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4904 let oldmode = state.mode
in
4905 let birdseye = isbirdseye state.mode
in
4907 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4909 src#
bool "presentation mode"
4910 (fun () -> conf.presentation
)
4911 (fun v -> setpresentationmode v);
4913 src#
bool "ignore case in searches"
4914 (fun () -> conf.icase
)
4915 (fun v -> conf.icase
<- v);
4918 (fun () -> conf.preload)
4919 (fun v -> conf.preload <- v);
4921 src#
bool "highlight links"
4922 (fun () -> conf.hlinks
)
4923 (fun v -> conf.hlinks
<- v);
4925 src#
bool "under info"
4926 (fun () -> conf.underinfo
)
4927 (fun v -> conf.underinfo
<- v);
4929 src#
bool "persistent bookmarks"
4930 (fun () -> conf.savebmarks
)
4931 (fun v -> conf.savebmarks
<- v);
4933 src#fitmodel
"fit model"
4934 (fun () -> FMTE.to_string conf.fitmodel
)
4935 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4937 src#
bool "trim margins"
4938 (fun () -> conf.trimmargins
)
4939 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4941 src#
bool "persistent location"
4942 (fun () -> conf.jumpback
)
4943 (fun v -> conf.jumpback
<- v);
4946 src#
int "inter-page space"
4947 (fun () -> conf.interpagespace
)
4949 conf.interpagespace
<- n;
4950 docolumns conf.columns
;
4952 match state.layout with
4957 state.maxy <- calcheight ();
4958 let y = getpagey pageno in
4963 (fun () -> conf.pagebias
)
4964 (fun v -> conf.pagebias
<- v);
4966 src#
int "scroll step"
4967 (fun () -> conf.scrollstep
)
4968 (fun n -> conf.scrollstep
<- n);
4970 src#
int "horizontal scroll step"
4971 (fun () -> conf.hscrollstep
)
4972 (fun v -> conf.hscrollstep
<- v);
4974 src#
int "auto scroll step"
4976 match state.autoscroll
with
4978 | _ -> conf.autoscrollstep
)
4980 let n = boundastep state.winh
n in
4981 if state.autoscroll
<> None
4982 then state.autoscroll
<- Some
n;
4983 conf.autoscrollstep
<- n);
4986 (fun () -> truncate
(conf.zoom *. 100.))
4987 (fun v -> setzoom ((float v) /. 100.));
4990 (fun () -> conf.angle
)
4991 (fun v -> reqlayout v conf.fitmodel
);
4993 src#
int "scroll bar width"
4994 (fun () -> conf.scrollbw
)
4997 reshape state.winw
state.winh
;
5000 src#
int "scroll handle height"
5001 (fun () -> conf.scrollh
)
5002 (fun v -> conf.scrollh
<- v;);
5004 src#
int "thumbnail width"
5005 (fun () -> conf.thumbw
)
5007 conf.thumbw
<- min
4096 v;
5010 leavebirdseye beye
false;
5015 let mode = state.mode in
5016 src#
string "columns"
5018 match conf.columns
with
5020 | Cmulti
(multi
, _) -> multicolumns_to_string multi
5021 | Csplit
(count
, _) -> "-" ^ string_of_int count
5024 let n, a, b = multicolumns_of_string v in
5025 setcolumns mode n a b);
5028 src#caption
"Pixmap cache" 0;
5029 src#int_with_suffix
"size (advisory)"
5030 (fun () -> conf.memlimit
)
5031 (fun v -> conf.memlimit
<- v);
5034 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
5035 (string_with_suffix_of_int state.memused
)
5036 (Hashtbl.length
state.tilemap
)) 1;
5039 src#caption
"Layout" 0;
5040 src#caption2
"Dimension"
5042 Printf.sprintf
"%dx%d (virtual %dx%d)"
5043 state.winw
state.winh
5048 src#caption2
"Position" (fun () ->
5049 Printf.sprintf
"%dx%d" state.x state.y
5052 src#caption2
"Position" (fun () -> describe_location ()) 1
5056 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
5057 "Save these parameters as global defaults at exit"
5058 (fun () -> conf.bedefault
)
5059 (fun v -> conf.bedefault
<- v)
5063 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
5064 src#
bool ~offset
:0 ~
btos "Extended parameters"
5065 (fun () -> !showextended)
5066 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
5070 (fun () -> conf.checkers
)
5071 (fun v -> conf.checkers
<- v; setcheckers v);
5072 src#
bool "update cursor"
5073 (fun () -> conf.updatecurs
)
5074 (fun v -> conf.updatecurs
<- v);
5076 (fun () -> conf.verbose
)
5077 (fun v -> conf.verbose
<- v);
5078 src#
bool "invert colors"
5079 (fun () -> conf.invert
)
5080 (fun v -> conf.invert
<- v);
5082 (fun () -> conf.maxhfit
)
5083 (fun v -> conf.maxhfit
<- v);
5084 src#
bool "redirect stderr"
5085 (fun () -> conf.redirectstderr)
5086 (fun v -> conf.redirectstderr <- v; redirectstderr ());
5088 (fun () -> conf.pax
!= None
)
5091 then conf.pax
<- Some
(ref (now (), 0, 0))
5092 else conf.pax
<- None
);
5093 src#
string "uri launcher"
5094 (fun () -> conf.urilauncher
)
5095 (fun v -> conf.urilauncher
<- v);
5096 src#
string "path launcher"
5097 (fun () -> conf.pathlauncher
)
5098 (fun v -> conf.pathlauncher
<- v);
5099 src#
string "tile size"
5100 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
5103 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
5104 conf.tilew
<- max
64 w;
5105 conf.tileh
<- max
64 h;
5108 state.text <- Printf.sprintf
"bad tile size `%s': %s"
5111 src#
int "texture count"
5112 (fun () -> conf.texcount
)
5115 then conf.texcount
<- v
5116 else showtext '
!'
" Failed to set texture count please retry later"
5118 src#
int "slice height"
5119 (fun () -> conf.sliceheight
)
5121 conf.sliceheight
<- v;
5122 wcmd "sliceh %d" conf.sliceheight
;
5124 src#
int "anti-aliasing level"
5125 (fun () -> conf.aalevel
)
5127 conf.aalevel
<- bound v 0 8;
5128 state.anchor <- getanchor ();
5129 opendoc state.path state.password
;
5131 src#
string "page scroll scaling factor"
5132 (fun () -> string_of_float
conf.pgscale)
5135 let s = float_of_string
v in
5138 state.text <- Printf.sprintf
5139 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
5142 src#
int "ui font size"
5143 (fun () -> fstate.fontsize
)
5144 (fun v -> setfontsize (bound v 5 100));
5145 src#
int "hint font size"
5146 (fun () -> conf.hfsize
)
5147 (fun v -> conf.hfsize
<- bound v 5 100);
5148 colorp "background color"
5149 (fun () -> conf.bgcolor
)
5150 (fun v -> conf.bgcolor
<- v);
5151 src#
bool "crop hack"
5152 (fun () -> conf.crophack
)
5153 (fun v -> conf.crophack
<- v);
5154 src#
string "trim fuzz"
5155 (fun () -> irect_to_string conf.trimfuzz
)
5158 conf.trimfuzz
<- irect_of_string v;
5160 then settrim true conf.trimfuzz
;
5162 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
5164 src#
string "throttle"
5166 match conf.maxwait
with
5167 | None
-> "show place holder if page is not ready"
5170 then "wait for page to fully render"
5172 "wait " ^ string_of_float
time
5173 ^
" seconds before showing placeholder"
5177 let f = float_of_string
v in
5179 then conf.maxwait
<- None
5180 else conf.maxwait
<- Some
f
5182 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
5184 src#
string "ghyll scroll"
5186 match conf.ghyllscroll
with
5188 | Some nab
-> ghyllscroll_to_string nab
5191 try conf.ghyllscroll
<- ghyllscroll_of_string v
5193 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
5195 src#
string "selection command"
5196 (fun () -> conf.selcmd
)
5197 (fun v -> conf.selcmd
<- v);
5198 src#
string "synctex command"
5199 (fun () -> conf.stcmd
)
5200 (fun v -> conf.stcmd
<- v);
5201 src#
string "pax command"
5202 (fun () -> conf.paxcmd
)
5203 (fun v -> conf.paxcmd
<- v);
5204 src#colorspace
"color space"
5205 (fun () -> CSTE.to_string conf.colorspace
)
5207 conf.colorspace
<- CSTE.of_int v;
5211 src#paxmark
"pax mark method"
5212 (fun () -> MTE.to_string conf.paxmark
)
5213 (fun v -> conf.paxmark
<- MTE.of_int v);
5217 (fun () -> conf.usepbo
)
5218 (fun v -> conf.usepbo
<- v);
5219 src#
bool "mouse wheel scrolls pages"
5220 (fun () -> conf.wheelbypage
)
5221 (fun v -> conf.wheelbypage
<- v);
5222 src#
bool "open remote links in a new instance"
5223 (fun () -> conf.riani
)
5224 (fun v -> conf.riani
<- v);
5228 src#caption
"Document" 0;
5229 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
5230 src#caption2
"Pages"
5231 (fun () -> string_of_int
state.pagecount
) 1;
5232 src#caption2
"Dimensions"
5233 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5237 src#caption
"Trimmed margins" 0;
5238 src#caption2
"Dimensions"
5239 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5243 src#caption
"OpenGL" 0;
5244 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
5245 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
5248 src#caption
"Location" 0;
5249 if nonemptystr
state.origin
5250 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
5251 src#caption
("Path\t" ^ mbtoutf8
state.path) 1;
5253 src#reset prevmode prevuioh
;
5258 let prevmode = state.mode
5259 and prevuioh
= state.uioh in
5260 fillsrc prevmode prevuioh
;
5261 let source = (src :> lvsource
) in
5262 let modehash = findkeyhash conf "info" in
5263 state.uioh <- coe (object (self)
5264 inherit listview ~
source ~trusted
:true ~
modehash as super
5265 val mutable m_prevmemused
= 0
5266 method infochanged
= function
5268 if m_prevmemused
!= state.memused
5270 m_prevmemused
<- state.memused
;
5271 G.postRedisplay "memusedchanged";
5273 | Pdim
-> G.postRedisplay "pdimchanged"
5274 | Docinfo
-> fillsrc prevmode prevuioh
5276 method key key mask
=
5277 if not
(Wsi.withctrl mask
)
5280 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5281 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5282 | _ -> super#
key key mask
5283 else super#
key key mask
5285 G.postRedisplay "info";
5291 inherit lvsourcebase
5292 method getitemcount
= Array.length
state.help
5294 let s, l, _ = state.help
.(n) in
5297 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
5301 match state.help
.(active) with
5302 | _, _, Action
f -> Some
(f uioh)
5312 method hasaction
n =
5313 match state.help
.(n) with
5314 | _, _, Action
_ -> true
5321 let modehash = findkeyhash conf "help" in
5323 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5324 G.postRedisplay "help";
5329 let re = Str.regexp
"[\r\n]" in
5331 inherit lvsourcebase
5332 val mutable m_items
= [||]
5334 method getitemcount
= 1 + Array.length m_items
5339 else m_items
.(n-1), 0
5341 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
5346 then Buffer.clear
state.errmsgs
;
5353 method hasaction
n =
5357 state.newerrmsgs
<- false;
5358 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5359 m_items
<- Array.of_list
l
5368 let source = (msgsource :> lvsource
) in
5369 let modehash = findkeyhash conf "listview" in
5370 state.uioh <- coe (object
5371 inherit listview ~
source ~trusted
:false ~
modehash as super
5374 then msgsource#reset
;
5377 G.postRedisplay "msgs";
5380 let quickbookmark ?title
() =
5381 match state.layout with
5387 let sec = Unix.gettimeofday
() in
5388 let tm = Unix.localtime
sec in
5389 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5393 (tm.Unix.tm_year
+ 1900)
5396 | Some
title -> title
5398 state.bookmarks
<- (title, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5401 let setautoscrollspeed step goingdown
=
5402 let incr = max
1 ((abs step
) / 2) in
5403 let incr = if goingdown
then incr else -incr in
5404 let astep = boundastep state.winh
(step
+ incr) in
5405 state.autoscroll
<- Some
astep;
5409 match conf.columns
with
5411 | _ -> state.x != 0 || conf.zoom > 1.0
5414 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5416 let existsinrow pageno (columns
, coverA
, coverB
) p =
5417 let last = ((pageno - coverA
) mod columns
) + columns
in
5418 let rec any = function
5421 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5425 then (if l.pageno = last then false else any rest
)
5433 match state.layout with
5435 let pageno = page_of_y state.y in
5436 gotoghyll (getpagey (pageno+1))
5438 match conf.columns
with
5440 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5442 let y = clamp (pgscale state.winh
) in
5445 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5446 gotoghyll (getpagey pageno)
5447 | Cmulti
((c, _, _) as cl, _) ->
5448 if conf.presentation
5449 && (existsinrow l.pageno cl
5450 (fun l -> l.pageh
> l.pagey + l.pagevh))
5452 let y = clamp (pgscale state.winh
) in
5455 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5456 gotoghyll (getpagey pageno)
5458 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5460 let pagey, pageh
= getpageyh l.pageno in
5461 let pagey = pagey + pageh
* l.pagecol
in
5462 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5463 gotoghyll (pagey + pageh
+ ips)
5467 match state.layout with
5469 let pageno = page_of_y state.y in
5470 gotoghyll (getpagey (pageno-1))
5472 match conf.columns
with
5474 if conf.presentation
&& l.pagey != 0
5476 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5478 let pageno = max
0 (l.pageno-1) in
5479 gotoghyll (getpagey pageno)
5480 | Cmulti
((c, _, coverB
) as cl, _) ->
5481 if conf.presentation
&&
5482 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5484 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5487 if l.pageno = state.pagecount
- coverB
5491 let pageno = max
0 (l.pageno-decr) in
5492 gotoghyll (getpagey pageno)
5500 let pageno = max
0 (l.pageno-1) in
5501 let pagey, pageh
= getpageyh pageno in
5504 let pagey, pageh
= getpageyh l.pageno in
5505 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5510 let viewkeyboard key mask
=
5512 let mode = state.mode in
5513 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5516 G.postRedisplay "view:enttext"
5518 let ctrl = Wsi.withctrl mask
in
5520 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5526 | 0xff63 -> (* insert *)
5527 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5529 state.mode <- LinkNav
(Ltgendir
0);
5532 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5534 | 0xff1b | 113 -> (* escape / q *)
5535 begin match state.mstate
with
5538 G.postRedisplay "kill zoom rect";
5540 begin match state.mode with
5543 G.postRedisplay "esc leave linknav"
5545 match state.ranchors
with
5547 | (path, password
, anchor, origin
) :: rest
->
5548 state.ranchors
<- rest
;
5549 state.anchor <- anchor;
5550 state.origin
<- origin
;
5551 state.nameddest
<- "";
5552 opendoc path password
5556 | 0xff08 -> (* backspace *)
5557 gotoghyll (getnav ~
-1)
5565 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state.pagemap
;
5566 G.postRedisplay "dehighlight";
5568 | 47 | 63 -> (* / ? *)
5569 let ondone isforw
s =
5570 cbput state.hists
.pat
s;
5571 state.searchpattern
<- s;
5574 let s = String.create
1 in
5575 s.[0] <- Char.chr
key;
5576 enttext (s, "", Some
(onhist state.hists
.pat
),
5577 textentry, ondone (key = 47), true)
5579 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5580 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5581 setzoom (conf.zoom +. incr)
5583 | 43 | 0xffab -> (* + *)
5586 try int_of_string
s with exc
->
5587 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5593 state.text <- "page bias is now " ^ string_of_int
n;
5596 enttext ("page bias: ", "", None
, intentry, ondone, true)
5598 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5599 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5600 setzoom (max
0.01 (conf.zoom -. decr))
5602 | 45 | 0xffad -> (* - *)
5603 let ondone msg
= state.text <- msg
in
5605 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5606 optentry state.mode, ondone, true
5609 | 48 when ctrl -> (* ctrl-0 *)
5617 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5619 match conf.columns
with
5620 | Csingle
_ | Cmulti
_ -> 1
5621 | Csplit
(n, _) -> n
5623 let h = state.winh
-
5624 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5626 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5627 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5630 | 51 when ctrl -> (* ctrl-3 *)
5632 match conf.fitmodel
with
5633 | FitWidth
-> FitProportional
5634 | FitProportional
-> FitPage
5635 | FitPage
-> FitWidth
5637 state.text <- "fit model: " ^
FMTE.to_string fm;
5638 reqlayout conf.angle
fm
5640 | 0xffc6 -> (* f9 *)
5643 | 57 when ctrl -> (* ctrl-9 *)
5646 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5647 when not
ctrl -> (* 0..9 *)
5650 try int_of_string
s with exc
->
5651 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5657 cbput state.hists
.pag
(string_of_int
n);
5658 gotopage1 (n + conf.pagebias
- 1) 0;
5661 let pageentry text key =
5662 match Char.unsafe_chr
key with
5663 | '
g'
-> TEdone
text
5664 | _ -> intentry text key
5666 let text = "x" in text.[0] <- Char.chr
key;
5667 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5670 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5671 reshape state.winw
state.winh
;
5674 state.bzoom
<- not
state.bzoom
;
5676 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5679 conf.hlinks
<- not
conf.hlinks
;
5680 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5681 G.postRedisplay "toggle highlightlinks";
5684 state.glinks
<- true;
5685 let mode = state.mode in
5686 state.mode <- Textentry
(
5687 (":", "", None
, linknentry, linkndone gotounder, false),
5689 state.glinks
<- false;
5693 G.postRedisplay "view:linkent(F)"
5696 state.glinks
<- true;
5697 let mode = state.mode in
5698 state.mode <- Textentry
(
5700 ":", "", None
, linknentry, linkndone (fun under ->
5701 selstring (undertext under);
5705 state.glinks
<- false;
5709 G.postRedisplay "view:linkent"
5712 begin match state.autoscroll
with
5714 conf.autoscrollstep
<- step
;
5715 state.autoscroll
<- None
5717 if conf.autoscrollstep
= 0
5718 then state.autoscroll
<- Some
1
5719 else state.autoscroll
<- Some
conf.autoscrollstep
5722 | 112 when ctrl -> (* ctrl-p *)
5726 setpresentationmode (not
conf.presentation
);
5727 showtext ' '
("presentation mode " ^
5728 if conf.presentation
then "on" else "off");
5731 if List.mem
Wsi.Fullscreen
state.winstate
5732 then Wsi.reshape conf.cwinw
conf.cwinh
5733 else Wsi.fullscreen
()
5735 | 112 | 78 -> (* p|N *)
5736 search state.searchpattern
false
5738 | 110 | 0xffc0 -> (* n|F3 *)
5739 search state.searchpattern
true
5742 begin match state.layout with
5745 gotoghyll (getpagey l.pageno)
5751 | 0xff9f | 0xffff -> (* delete *)
5755 showtext ' '
(describe_location ());
5758 begin match state.layout with
5761 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5766 enterbookmarkmode ()
5768 | 104 | 0xffbe -> (* h|F1 *)
5774 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5779 match state.layout with
5784 (s, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5787 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5791 showtext ' '
"Quick bookmark added";
5794 begin match state.layout with
5796 let rect = getpdimrect
l.pagedimno
in
5800 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5801 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5803 (truncate
(rect.(1) -. rect.(0)),
5804 truncate
(rect.(3) -. rect.(0)))
5806 let w = truncate
((float w)*.conf.zoom)
5807 and h = truncate
((float h)*.conf.zoom) in
5810 state.anchor <- getanchor ();
5811 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5813 G.postRedisplay "z";
5820 | 60 | 62 -> (* < > *)
5821 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5823 | 91 | 93 -> (* [ ] *)
5825 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5827 G.postRedisplay "brightness";
5829 | 99 when state.mode = View
-> (* [alt-]c *)
5834 let m = (wadjsb state.winw
- state.w) / 2 in
5836 gotoy_and_clear_text state.y
5840 match state.prevcolumns
with
5841 | None
-> (1, 0, 0), 1.0
5842 | Some
(columns
, z
) ->
5845 | Csplit
(c, _) -> -c, 0, 0
5846 | Cmulti
((c, a, b), _) -> c, a, b
5847 | Csingle
_ -> 1, 0, 0
5851 setcolumns View
c a b;
5854 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5855 -> (* ctrl-shift- (kp) [up|down] *)
5856 let zoom, x = state.prevzoom
in
5860 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5861 begin match state.autoscroll
with
5863 begin match state.mode with
5864 | Birdseye beye
-> upbirdseye 1 beye
5867 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5869 if not
(Wsi.withshift mask
) && conf.presentation
5871 else gotoghyll1 true (clamp (-conf.scrollstep
))
5875 setautoscrollspeed n false
5878 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5879 begin match state.autoscroll
with
5881 begin match state.mode with
5882 | Birdseye beye
-> downbirdseye 1 beye
5885 then gotoy_and_clear_text (clamp (state.winh
/2))
5887 if not
(Wsi.withshift mask
) && conf.presentation
5889 else gotoghyll1 true (clamp (conf.scrollstep
))
5893 setautoscrollspeed n true
5896 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5897 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5903 else conf.hscrollstep
5905 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5906 state.x <- panbound (state.x + dx);
5907 gotoy_and_clear_text state.y
5910 G.postRedisplay "left/right"
5913 | 0xff55 | 0xff9a -> (* (kp) prior *)
5917 match state.layout with
5919 | l :: _ -> state.y - l.pagey
5921 clamp (pgscale (-state.winh
))
5925 | 0xff56 | 0xff9b -> (* (kp) next *)
5929 match List.rev
state.layout with
5931 | l :: _ -> getpagey l.pageno
5933 clamp (pgscale state.winh
)
5937 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5939 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5940 gotoghyll (clamp state.maxy)
5943 when Wsi.withalt mask
-> (* alt-(kp) right *)
5944 gotoghyll (getnav 1)
5946 when Wsi.withalt mask
-> (* alt-(kp) left *)
5947 gotoghyll (getnav ~
-1)
5952 | 118 when conf.debug
-> (* v *)
5955 match getopaque l.pageno with
5958 let x0, y0, x1, y1 = pagebbox
opaque in
5959 let a,b = float x0, float y0 in
5960 let c,d = float x1, float y0 in
5961 let e,f = float x1, float y1 in
5962 let h,j
= float x0, float y1 in
5963 let rect = (a,b,c,d,e,f,h,j
) in
5965 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5967 G.postRedisplay "v";
5970 let mode = state.mode in
5972 let onleave = function
5973 | Cancel
-> state.mode <- mode
5976 match getopaque l.pageno with
5977 | Some
opaque -> pipesel opaque !cmd
5978 | None
-> ()) state.layout;
5982 cbput state.hists
.sel
s;
5986 "| ", !cmd, Some
(onhist state.hists
.sel
), textentry, ondone, true
5988 G.postRedisplay "|";
5989 state.mode <- Textentry
(te, onleave);
5992 vlog "huh? %s" (Wsi.keyname
key)
5995 let linknavkeyboard key mask
linknav =
5996 let getpage pageno =
5997 let rec loop = function
5999 | l :: _ when l.pageno = pageno -> Some
l
6000 | _ :: rest
-> loop rest
6001 in loop state.layout
6003 let doexact (pageno, n) =
6004 match getopaque pageno, getpage pageno with
6005 | Some
opaque, Some
l ->
6006 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
6008 let under = getlink
opaque n in
6009 G.postRedisplay "link gotounder";
6015 | 0xff50 -> (* home *)
6016 Some
(findlink
opaque LDfirst
), -1
6018 | 0xff57 -> (* end *)
6019 Some
(findlink
opaque LDlast
), 1
6021 | 0xff51 -> (* left *)
6022 Some
(findlink
opaque (LDleft
n)), -1
6024 | 0xff53 -> (* right *)
6025 Some
(findlink
opaque (LDright
n)), 1
6027 | 0xff52 -> (* up *)
6028 Some
(findlink
opaque (LDup
n)), -1
6030 | 0xff54 -> (* down *)
6031 Some
(findlink
opaque (LDdown
n)), 1
6036 begin match findpwl
l.pageno dir with
6040 state.mode <- LinkNav
(Ltgendir
dir);
6041 let y, h = getpageyh pageno in
6044 then y + h - state.winh
6049 begin match getopaque pageno, getpage pageno with
6050 | Some
opaque, Some
_ ->
6052 let ld = if dir > 0 then LDfirst
else LDlast
in
6055 begin match link with
6057 showlinktype (getlink
opaque m);
6058 state.mode <- LinkNav
(Ltexact
(pageno, m));
6059 G.postRedisplay "linknav jpage";
6066 begin match opt with
6067 | Some Lnotfound
-> pwl l dir;
6068 | Some
(Lfound
m) ->
6072 let _, y0, _, y1 = getlinkrect
opaque m in
6074 then gotopage1 l.pageno y0
6076 let d = fstate.fontsize
+ 1 in
6077 if y1 - l.pagey > l.pagevh - d
6078 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
6079 else G.postRedisplay "linknav";
6081 showlinktype (getlink
opaque m);
6082 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
6085 | None
-> viewkeyboard key mask
6087 | _ -> viewkeyboard key mask
6092 G.postRedisplay "leave linknav"
6096 | Ltgendir
_ -> viewkeyboard key mask
6097 | Ltexact exact
-> doexact exact
6100 let keyboard key mask
=
6101 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
6102 then wcmd "interrupt"
6103 else state.uioh <- state.uioh#
key key mask
6106 let birdseyekeyboard key mask
6107 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
6109 match conf.columns
with
6111 | Cmulti
((c, _, _), _) -> c
6112 | Csplit
_ -> failwith
"bird's eye split mode"
6114 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
6116 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
6117 let y, h = getpageyh pageno in
6118 let top = (state.winh
- h) / 2 in
6119 gotoy (max
0 (y - top))
6120 | 0xff0d (* enter *)
6121 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
6122 | 0xff1b -> leavebirdseye beye
true (* escape *)
6123 | 0xff52 -> upbirdseye incr beye
(* up *)
6124 | 0xff54 -> downbirdseye incr beye
(* down *)
6125 | 0xff51 -> upbirdseye 1 beye
(* left *)
6126 | 0xff53 -> downbirdseye 1 beye
(* right *)
6128 | 0xff55 -> (* prior *)
6129 begin match state.layout with
6133 state.mode <- Birdseye
(
6134 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6136 gotopage1 l.pageno 0;
6139 let layout = layout (state.y-state.winh
) (pgh state.layout) in
6141 | [] -> gotoy (clamp (-state.winh
))
6143 state.mode <- Birdseye
(
6144 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6146 gotopage1 l.pageno 0
6149 | [] -> gotoy (clamp (-state.winh
))
6152 | 0xff56 -> (* next *)
6153 begin match List.rev
state.layout with
6155 let layout = layout (state.y + (pgh state.layout)) state.winh
in
6156 begin match layout with
6158 let incr = l.pageh
- l.pagevh in
6163 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
6165 G.postRedisplay "birdseye pagedown";
6167 else gotoy (clamp (incr + conf.interpagespace
*2));
6171 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
6172 gotopage1 l.pageno 0;
6175 | [] -> gotoy (clamp state.winh
)
6178 | 0xff50 -> (* home *)
6179 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
6182 | 0xff57 -> (* end *)
6183 let pageno = state.pagecount
- 1 in
6184 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
6185 if not
(pagevisible state.layout pageno)
6188 match List.rev
state.pdims
with
6190 | (_, _, h, _) :: _ -> h
6192 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
6193 else G.postRedisplay "birdseye end";
6194 | _ -> viewkeyboard key mask
6199 match state.mode with
6200 | Textentry
_ -> scalecolor 0.4
6202 | View
-> scalecolor 1.0
6203 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6204 if l.pageno = hooverpageno
6207 if l.pageno = pageno
6215 let postdrawpage l linkindexbase
=
6216 match getopaque l.pageno with
6218 if tileready l l.pagex
l.pagey
6220 let x = l.pagedispx - l.pagex
6221 and y = l.pagedispy - l.pagey in
6223 match conf.columns
with
6224 | Csingle
_ | Cmulti
_ ->
6225 (if conf.hlinks
then 1 else 0)
6227 && not
(isbirdseye state.mode) then 2 else 0)
6231 match state.mode with
6232 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6235 postprocess
opaque hlmask x y (linkindexbase
, s, conf.hfsize
);
6240 let scrollindicator () =
6241 let sbw, ph
, sh = state.uioh#
scrollph in
6242 let sbh, pw, sw = state.uioh#scrollpw
in
6244 GlDraw.color (0.64, 0.64, 0.64);
6246 (float (state.winw
- sbw)) 0.
6247 (float state.winw
) (float state.winh
)
6250 0. (float (state.winh
- sbh))
6251 (float (wadjsb state.winw
- 1)) (float state.winh
)
6253 GlDraw.color (0.0, 0.0, 0.0);
6256 (float (state.winw
- sbw)) ph
6257 (float state.winw
) (ph
+. sh)
6260 pw (float (state.winh
- sbh))
6261 (pw +. sw) (float state.winh
)
6266 match state.mstate
with
6267 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6270 | Msel
((x0, y0), (x1, y1)) ->
6271 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
6272 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< "", -1, 0, 0) in
6273 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< "", -1, 0, 0) in
6274 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
6277 let showrects = function [] -> () | rects
->
6279 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6280 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6282 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6284 if l.pageno = pageno
6286 let dx = float (l.pagedispx - l.pagex
) in
6287 let dy = float (l.pagedispy - l.pagey) in
6288 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6289 Raw.sets_float
state.vraw ~pos
:0
6294 GlArray.vertex `two
state.vraw
;
6295 GlArray.draw_arrays `triangle_strip
0 4;
6304 GlClear.color (scalecolor2 conf.bgcolor
);
6305 GlClear.clear
[`
color];
6306 List.iter
drawpage state.layout;
6308 match state.mode with
6309 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6310 begin match getopaque pageno with
6312 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
6319 | None
-> state.rects
6324 let rec postloop linkindexbase
= function
6326 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6327 postloop linkindexbase rest
6331 postloop 0 state.layout;
6333 begin match state.mstate
with
6334 | Mzoomrect
((x0, y0), (x1, y1)) ->
6336 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6337 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6338 filledrect (float x0) (float y0) (float x1) (float y1);
6347 let zoomrect x y x1 y1 =
6350 and y0 = min
y y1 in
6351 gotoy (state.y + y0);
6352 state.anchor <- getanchor ();
6353 let zoom = (float state.w) /. float (x1 - x0) in
6355 match conf.fitmodel
, conf.columns
with
6356 | FitPage
, Csplit
_ ->
6357 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6360 let adjw = wadjsb state.winw
in
6362 then (adjw - state.w) / 2
6365 state.x <- (state.x + margin) - x0;
6371 let g opaque l px py =
6372 match rectofblock
opaque px py with
6374 let x0 = a.(0) -. 20. in
6375 let x1 = a.(1) +. 20. in
6376 let y0 = a.(2) -. 20. in
6377 let zoom = (float state.w) /. (x1 -. x0) in
6378 let pagey = getpagey l.pageno in
6379 gotoy_and_clear_text (pagey + truncate
y0);
6380 state.anchor <- getanchor ();
6381 let margin = (state.w - l.pagew
)/2 in
6382 state.x <- -truncate
x0 - margin;
6387 match conf.columns
with
6389 showtext '
!'
"block zooming does not work properly in split columns mode"
6390 | _ -> onppundermouse g x y ()
6394 let winw = wadjsb state.winw - 1 in
6395 let s = float x /. float winw in
6396 let destx = truncate
(float (state.w + winw) *. s) in
6397 state.x <- winw - destx;
6398 gotoy_and_clear_text state.y;
6399 state.mstate
<- Mscrollx
;
6403 let s = float y /. float state.winh
in
6404 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6405 gotoy_and_clear_text desty;
6406 state.mstate
<- Mscrolly
;
6409 let viewmulticlick clicks
x y mask
=
6410 let g opaque l px py =
6418 if markunder
opaque px py mark
6422 match getopaque l.pageno with
6424 | Some
opaque -> pipesel opaque cmd
6426 state.roam
<- (fun () -> dopipe conf.paxcmd
);
6427 if not
(Wsi.withctrl mask
) then dopipe conf.selcmd
;
6432 G.postRedisplay "viewmulticlick";
6433 onppundermouse g x y (fun () -> showtext '
!'
"Nothing to select") ();
6437 match conf.columns
with
6439 | Csingle
_ | Cmulti
_ -> conf.angle
mod 360 = 0
6442 let viewmouse button down
x y mask
=
6444 | n when (n == 4 || n == 5) && not down
->
6445 if Wsi.withctrl mask
6447 match state.mstate
with
6448 | Mzoom
(oldn
, i
) ->
6456 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6458 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6460 let zoom = conf.zoom -. incr in
6462 state.mstate
<- Mzoom
(n, 0);
6464 state.mstate
<- Mzoom
(n, i
+1);
6466 else state.mstate
<- Mzoom
(n, 0)
6468 | _ -> state.mstate
<- Mzoom
(n, 0)
6471 match state.autoscroll
with
6472 | Some step
-> setautoscrollspeed step
(n=4)
6474 if conf.wheelbypage
|| conf.presentation
6483 then -conf.scrollstep
6484 else conf.scrollstep
6486 let incr = incr * 2 in
6487 let y = clamp incr in
6488 gotoy_and_clear_text y
6491 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6493 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6494 gotoy_and_clear_text state.y
6496 | 1 when Wsi.withshift mask
->
6497 state.mstate
<- Mnone
;
6500 match unproject x y with
6501 | Some
(pageno, ux
, uy
) ->
6502 let cmd = Printf.sprintf
6504 conf.stcmd
state.path pageno ux uy
6510 | 1 when Wsi.withctrl mask
->
6513 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6514 state.mstate
<- Mpan
(x, y)
6517 state.mstate
<- Mnone
6522 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6524 state.mstate
<- Mzoomrect
(p, p)
6527 match state.mstate
with
6528 | Mzoomrect
((x0, y0), _) ->
6529 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6530 then zoomrect x0 y0 x y
6533 G.postRedisplay "kill accidental zoom rect";
6539 | 1 when x > state.winw - vscrollw () ->
6542 let _, position, sh = state.uioh#
scrollph in
6543 if y > truncate
position && y < truncate
(position +. sh)
6544 then state.mstate
<- Mscrolly
6547 state.mstate
<- Mnone
6549 | 1 when y > state.winh
- hscrollh () ->
6552 let _, position, sw = state.uioh#scrollpw
in
6553 if x > truncate
position && x < truncate
(position +. sw)
6554 then state.mstate
<- Mscrollx
6557 state.mstate
<- Mnone
6559 | 1 when state.bzoom
-> if not down
then zoomblock x y
6562 let dest = if down
then getunder x y else Unone
in
6563 begin match dest with
6566 | Uremote
_ | Uremotedest
_
6567 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6570 | Unone
when down
->
6571 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6572 state.mstate
<- Mpan
(x, y);
6574 | Unone
| Utext
_ ->
6579 state.mstate
<- Msel
((x, y), (x, y));
6580 G.postRedisplay "mouse select";
6584 match state.mstate
with
6587 | Mzoom
_ | Mscrollx
| Mscrolly
->
6588 state.mstate
<- Mnone
6590 | Mzoomrect
((x0, y0), _) ->
6594 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6595 state.mstate
<- Mnone
6597 | Msel
((x0, y0), (x1, y1)) ->
6598 let rec loop = function
6602 let a0 = l.pagedispy in
6603 let a1 = a0 + l.pagevh in
6604 let b0 = l.pagedispx in
6605 let b1 = b0 + l.pagevw in
6606 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6607 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6611 match getopaque l.pageno with
6614 match Ne.res Unix.pipe
with
6618 "can not create sel pipe: %s"
6622 Ne.clo fd
(fun msg
->
6623 dolog
"%s close failed: %s" what msg
)
6626 try popen cmd [r, 0; w, -1]; true
6628 dolog
"can not execute %S: %s"
6635 G.postRedisplay "copysel";
6637 else clo "Msel pipe/w" w;
6638 clo "Msel pipe/r" r;
6640 dosel conf.selcmd
();
6641 state.roam
<- dosel conf.paxcmd
;
6653 let birdseyemouse button down
x y mask
6654 (conf, leftx
, _, hooverpageno
, anchor) =
6657 let rec loop = function
6660 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6661 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6663 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6669 | _ -> viewmouse button down
x y mask
6675 method key key mask
=
6676 begin match state.mode with
6677 | Textentry
textentry -> textentrykeyboard key mask
textentry
6678 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6679 | View
-> viewkeyboard key mask
6680 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6684 method button button bstate
x y mask
=
6685 begin match state.mode with
6687 | View
-> viewmouse button bstate
x y mask
6688 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6693 method multiclick clicks
x y mask
=
6694 begin match state.mode with
6696 | View
-> viewmulticlick clicks
x y mask
6703 begin match state.mode with
6705 | View
| Birdseye
_ | LinkNav
_ ->
6706 match state.mstate
with
6707 | Mzoom
_ | Mnone
-> ()
6712 state.mstate
<- Mpan
(x, y);
6714 then state.x <- panbound (state.x + dx);
6716 gotoy_and_clear_text y
6719 state.mstate
<- Msel
(a, (x, y));
6720 G.postRedisplay "motion select";
6723 let y = min
state.winh
(max
0 y) in
6727 let x = min
state.winw (max
0 x) in
6730 | Mzoomrect
(p0
, _) ->
6731 state.mstate
<- Mzoomrect
(p0
, (x, y));
6732 G.postRedisplay "motion zoomrect";
6736 method pmotion
x y =
6737 begin match state.mode with
6738 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6739 let rec loop = function
6741 if hooverpageno
!= -1
6743 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6744 G.postRedisplay "pmotion birdseye no hoover";
6747 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6748 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6750 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6751 G.postRedisplay "pmotion birdseye hoover";
6761 match state.mstate
with
6762 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6771 let past, _, _ = !r in
6773 let delta = now -. past in
6776 else r := (now, x, y)
6780 method infochanged
_ = ()
6783 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6786 then 0.0, float state.winh
6787 else scrollph state.y maxy
6792 let winw = wadjsb state.winw in
6793 let fwinw = float winw in
6795 let sw = fwinw /. float state.w in
6796 let sw = fwinw *. sw in
6797 max
sw (float conf.scrollh
)
6800 let maxx = state.w + winw in
6801 let x = winw - state.x in
6802 let percent = float x /. float maxx in
6803 (fwinw -. sw) *. percent
6805 hscrollh (), position, sw
6809 match state.mode with
6810 | LinkNav
_ -> "links"
6811 | Textentry
_ -> "textentry"
6812 | Birdseye
_ -> "birdseye"
6815 findkeyhash conf modename
6817 method eformsgs
= true
6824 let fontpath = ref "";;
6827 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6830 let l = String.length
s in
6831 let b = Buffer.create
l in
6837 try Sys.getenv
"HOME"
6840 ("Can not determine home directory location: " ^ exntos exn
);
6844 let modifier_of_string = function
6845 | "alt" -> Wsi.altmask
6846 | "shift" -> Wsi.shiftmask
6847 | "ctrl" | "control" -> Wsi.ctrlmask
6848 | "meta" -> Wsi.metamask
6853 let r = Str.regexp
"-" in
6855 let elems = Str.full_split
r s in
6858 let m1 = modifier_of_string s in
6860 then (Wsi.namekey
s, m)
6863 | Str.Delim
s when n land 1 = 0 -> g s
6865 | Str.Delim
_ -> (k
, m)
6867 let rec loop n k
m = function
6870 let k, m = f n k m x in
6876 let keys_of_string =
6877 let r = Str.regexp
"[ \t]" in
6879 let elems = Str.split
r s in
6880 List.map
key_of_string elems
6883 let copykeyhashes c =
6884 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6887 let config_of c attrs
=
6891 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6892 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6893 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6894 | "preload" -> { c with preload = bool_of_string
v }
6895 | "page-bias" -> { c with pagebias
= int_of_string
v }
6896 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6897 | "horizontal-scroll-step" ->
6898 { c with hscrollstep
= max
(int_of_string
v) 1 }
6899 | "auto-scroll-step" ->
6900 { c with autoscrollstep
= max
0 (int_of_string
v) }
6901 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6902 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6905 match String.lowercase
v with
6906 | "true" -> Some infinity
6908 | f -> Some
(float_of_string
f)
6910 { c with maxwait
= mw}
6911 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6912 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6913 | "vertical-margin" ->
6914 { c with interpagespace
= max
0 (int_of_string
v) }
6916 let zoom = float_of_string
v /. 100. in
6917 let zoom = max
zoom 0.0 in
6918 { c with zoom = zoom }
6919 | "presentation" -> { c with presentation
= bool_of_string
v }
6920 | "rotation-angle" -> { c with angle
= int_of_string
v }
6921 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6922 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6923 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6924 | "proportional-display" ->
6927 then FitProportional
6930 { c with fitmodel
= fm }
6931 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6932 | "pixmap-cache-size" ->
6933 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6934 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6935 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6936 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6937 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6938 | "background-color" -> { c with bgcolor
= color_of_string v }
6939 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6940 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6941 | "mupdf-store-size" ->
6942 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6943 | "checkers" -> { c with checkers
= bool_of_string
v }
6944 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6945 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6946 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6947 | "uri-launcher" -> { c with urilauncher
= unent v }
6948 | "path-launcher" -> { c with pathlauncher
= unent v }
6949 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6950 | "invert-colors" -> { c with invert
= bool_of_string
v }
6951 | "brightness" -> { c with colorscale
= float_of_string
v }
6952 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6953 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6955 let (n, _, _) as nab
= multicolumns_of_string v in
6957 then { c with columns
= Csplit
(-n, [||]) }
6958 else { c with columns
= Cmulti
(nab
, [||]) }
6959 | "birds-eye-columns" ->
6960 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6961 | "selection-command" -> { c with selcmd
= unent v }
6962 | "synctex-command" -> { c with stcmd
= unent v }
6963 | "pax-command" -> { c with paxcmd
= unent v }
6964 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6965 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6966 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6967 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6968 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6969 | "horizontal-scrollbar-visible" ->
6972 then c.scrollb
lor scrollbhv
6973 else c.scrollb
land (lnot
scrollbhv)
6975 { c with scrollb
= b }
6976 | "vertical-scrollbar-visible" ->
6979 then c.scrollb
lor scrollbvv
6980 else c.scrollb
land (lnot
scrollbvv)
6982 { c with scrollb
= b }
6983 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6987 then Some
(ref (0.0, 0, 0))
6989 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6992 prerr_endline
("Error processing attribute (`" ^
6993 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6996 let rec fold c = function
6999 let c = apply c k v in
7002 fold { c with keyhashes
= copykeyhashes c } attrs
;
7005 let fromstring f pos
n v d =
7008 dolog
"Error processing attribute (%S=%S) at %d\n%s"
7009 n v pos
(exntos exn
)
7014 let bookmark_of attrs
=
7015 let rec fold title page
rely visy
= function
7016 | ("title", v) :: rest
-> fold v page
rely visy rest
7017 | ("page", v) :: rest
-> fold title v rely visy rest
7018 | ("rely", v) :: rest
-> fold title page
v visy rest
7019 | ("visy", v) :: rest
-> fold title page
rely v rest
7020 | _ :: rest
-> fold title page
rely visy rest
7021 | [] -> title, page
, rely, visy
7023 fold "invalid" "0" "0" "0" attrs
7027 let rec fold path page
rely pan visy
= function
7028 | ("path", v) :: rest
-> fold v page
rely pan visy rest
7029 | ("page", v) :: rest
-> fold path v rely pan visy rest
7030 | ("rely", v) :: rest
-> fold path page
v pan visy rest
7031 | ("pan", v) :: rest
-> fold path page
rely v visy rest
7032 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
7033 | _ :: rest
-> fold path page
rely pan visy rest
7034 | [] -> path, page
, rely, pan
, visy
7036 fold "" "0" "0" "0" "0" attrs
7040 let rec fold rs ls
= function
7041 | ("out", v) :: rest
-> fold v ls rest
7042 | ("in", v) :: rest
-> fold rs
v rest
7043 | _ :: rest
-> fold ls rs rest
7049 let setconf dst
src =
7050 dst
.scrollbw
<- src.scrollbw
;
7051 dst
.scrollh
<- src.scrollh
;
7052 dst
.icase
<- src.icase
;
7053 dst
.preload <- src.preload;
7054 dst
.pagebias
<- src.pagebias
;
7055 dst
.verbose
<- src.verbose
;
7056 dst
.scrollstep
<- src.scrollstep
;
7057 dst
.maxhfit
<- src.maxhfit
;
7058 dst
.crophack
<- src.crophack
;
7059 dst
.autoscrollstep
<- src.autoscrollstep
;
7060 dst
.maxwait
<- src.maxwait
;
7061 dst
.hlinks
<- src.hlinks
;
7062 dst
.underinfo
<- src.underinfo
;
7063 dst
.interpagespace
<- src.interpagespace
;
7064 dst
.zoom <- src.zoom;
7065 dst
.presentation
<- src.presentation
;
7066 dst
.angle
<- src.angle
;
7067 dst
.cwinw
<- src.cwinw
;
7068 dst
.cwinh
<- src.cwinh
;
7069 dst
.savebmarks
<- src.savebmarks
;
7070 dst
.memlimit
<- src.memlimit
;
7071 dst
.fitmodel
<- src.fitmodel
;
7072 dst
.texcount
<- src.texcount
;
7073 dst
.sliceheight
<- src.sliceheight
;
7074 dst
.thumbw
<- src.thumbw
;
7075 dst
.jumpback
<- src.jumpback
;
7076 dst
.bgcolor
<- src.bgcolor
;
7077 dst
.tilew
<- src.tilew
;
7078 dst
.tileh
<- src.tileh
;
7079 dst
.mustoresize
<- src.mustoresize
;
7080 dst
.checkers
<- src.checkers
;
7081 dst
.aalevel
<- src.aalevel
;
7082 dst
.trimmargins
<- src.trimmargins
;
7083 dst
.trimfuzz
<- src.trimfuzz
;
7084 dst
.urilauncher
<- src.urilauncher
;
7085 dst
.colorspace
<- src.colorspace
;
7086 dst
.invert
<- src.invert
;
7087 dst
.colorscale
<- src.colorscale
;
7088 dst
.redirectstderr <- src.redirectstderr;
7089 dst
.ghyllscroll
<- src.ghyllscroll
;
7090 dst
.columns
<- src.columns
;
7091 dst
.beyecolumns
<- src.beyecolumns
;
7092 dst
.selcmd
<- src.selcmd
;
7093 dst
.updatecurs
<- src.updatecurs
;
7094 dst
.pathlauncher
<- src.pathlauncher
;
7095 dst
.keyhashes
<- copykeyhashes src;
7096 dst
.hfsize
<- src.hfsize
;
7097 dst
.hscrollstep
<- src.hscrollstep
;
7098 dst
.pgscale <- src.pgscale;
7099 dst
.usepbo
<- src.usepbo
;
7100 dst
.wheelbypage
<- src.wheelbypage
;
7101 dst
.stcmd
<- src.stcmd
;
7102 dst
.paxcmd
<- src.paxcmd
;
7103 dst
.scrollb
<- src.scrollb
;
7104 dst
.riani
<- src.riani
;
7105 dst
.paxmark
<- src.paxmark
;
7109 else Some
((ref (0.0, 0, 0)));
7113 let h = Hashtbl.create
10 in
7114 let dc = { defconf with angle
= defconf.angle
} in
7115 let rec toplevel v t spos
_ =
7117 | Vdata
| Vcdata
| Vend
-> v
7118 | Vopen
("llppconfig", _, closed
) ->
7121 else { v with f = llppconfig
}
7123 error
"unexpected subelement at top level" s spos
7124 | Vclose
_ -> error
"unexpected close at top level" s spos
7126 and llppconfig
v t spos
_ =
7128 | Vdata
| Vcdata
-> v
7129 | Vend
-> error
"unexpected end of input in llppconfig" s spos
7130 | Vopen
("defaults", attrs
, closed
) ->
7131 let c = config_of dc attrs
in
7135 else { v with f = defaults
}
7137 | Vopen
("ui-font", attrs
, closed
) ->
7138 let rec getsize size
= function
7140 | ("size", v) :: rest
->
7142 fromstring int_of_string spos
"size" v fstate.fontsize
in
7144 | l -> getsize size l
7146 fstate.fontsize
<- getsize fstate.fontsize attrs
;
7149 else { v with f = uifont
(Buffer.create
10) }
7151 | Vopen
("doc", attrs
, closed
) ->
7152 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
7153 let path = unent pathent
7154 and pageno = fromstring int_of_string spos
"page" spage
0
7155 and rely = fromstring float_of_string spos
"rely" srely
0.0
7156 and pan
= fromstring int_of_string spos
"pan" span
0
7157 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7158 let c = config_of dc attrs
in
7159 let anchor = (pageno, rely, visy
) in
7161 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
7162 else { v with f = doc
path pan
anchor c [] }
7165 error
"unexpected subelement in llppconfig" s spos
7167 | Vclose
"llppconfig" -> { v with f = toplevel }
7168 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
7170 and defaults
v t spos
_ =
7172 | Vdata
| Vcdata
-> v
7173 | Vend
-> error
"unexpected end of input in defaults" s spos
7174 | Vopen
("keymap", attrs
, closed
) ->
7176 try List.assoc
"mode" attrs
7177 with Not_found
-> "global" in
7182 let h = findkeyhash dc modename in
7183 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7186 { v with f = pkeymap
ret KeyMap.empty }
7188 | Vopen
(_, _, _) ->
7189 error
"unexpected subelement in defaults" s spos
7191 | Vclose
"defaults" ->
7192 { v with f = llppconfig
}
7194 | Vclose
_ -> error
"unexpected close in defaults" s spos
7196 and uifont
b v t spos
epos =
7199 Buffer.add_substring
b s spos
(epos - spos
);
7201 | Vopen
(_, _, _) ->
7202 error
"unexpected subelement in ui-font" s spos
7203 | Vclose
"ui-font" ->
7204 if emptystr
!fontpath
7205 then fontpath := Buffer.contents
b;
7206 { v with f = llppconfig
}
7207 | Vclose
_ -> error
"unexpected close in ui-font" s spos
7208 | Vend
-> error
"unexpected end of input in ui-font" s spos
7210 and doc
path pan
anchor c bookmarks
v t spos
_ =
7212 | Vdata
| Vcdata
-> v
7213 | Vend
-> error
"unexpected end of input in doc" s spos
7214 | Vopen
("bookmarks", _, closed
) ->
7217 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
7219 | Vopen
("keymap", attrs
, closed
) ->
7221 try List.assoc
"mode" attrs
7222 with Not_found
-> "global"
7228 let h = findkeyhash c modename in
7229 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7230 doc
path pan
anchor c bookmarks
7232 { v with f = pkeymap
ret KeyMap.empty }
7234 | Vopen
(_, _, _) ->
7235 error
"unexpected subelement in doc" s spos
7238 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7239 { v with f = llppconfig
}
7241 | Vclose
_ -> error
"unexpected close in doc" s spos
7243 and pkeymap
ret keymap
v t spos
_ =
7245 | Vdata
| Vcdata
-> v
7246 | Vend
-> error
"unexpected end of input in keymap" s spos
7247 | Vopen
("map", attrs
, closed
) ->
7248 let r, l = map_of attrs
in
7249 let kss = fromstring keys_of_string spos
"in" r [] in
7250 let lss = fromstring keys_of_string spos
"out" l [] in
7254 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7255 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7258 then { v with f = pkeymap
ret keymap }
7261 { v with f = skip
"map" f }
7264 error
"unexpected subelement in keymap" s spos
7266 | Vclose
"keymap" ->
7267 { v with f = ret keymap }
7269 | Vclose
_ -> error
"unexpected close in keymap" s spos
7271 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7273 | Vdata
| Vcdata
-> v
7274 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7275 | Vopen
("item", attrs
, closed
) ->
7276 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7277 let page = fromstring int_of_string spos
"page" spage
0
7278 and rely = fromstring float_of_string spos
"rely" srely
0.0
7279 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7281 (unent titleent, 0, Oanchor
(page, rely, visy
)) :: bookmarks
7284 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7287 { v with f = skip
"item" f }
7290 error
"unexpected subelement in bookmarks" s spos
7292 | Vclose
"bookmarks" ->
7293 { v with f = doc
path pan
anchor c bookmarks }
7295 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7297 and skip tag
f v t spos
_ =
7299 | Vdata
| Vcdata
-> v
7301 error
("unexpected end of input in skipped " ^ tag
) s spos
7302 | Vopen
(tag'
, _, closed
) ->
7306 let f'
() = { v with f = skip tag
f } in
7307 { v with f = skip tag'
f'
}
7311 else error
("unexpected close in skipped " ^ tag
) s spos
7314 parse
{ f = toplevel; accu = () } s;
7320 let len = in_channel_length ic
in
7321 let s = String.create
len in
7322 really_input ic
s 0 len;
7325 | Parse_error
(msg
, s, pos
) ->
7326 let subs = subs s pos
in
7327 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7330 failwith
("config load error: " ^ exntos exn
)
7336 let dir = Filename.concat
home ".config" in
7337 if Sys.is_directory
dir then dir else home
7340 Filename.concat
dir "llpp.conf"
7343 let confpath = ref defconfpath;;
7346 if Sys.file_exists
!confpath
7349 (try Some
(open_in_bin
!confpath)
7352 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7363 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7372 f (Hashtbl.create
0, defconf)
7377 let pc, pb
, px, pa
=
7380 if emptystr
state.origin
7384 Hashtbl.find h (Filename.basename
key)
7385 with Not_found
-> dc, [], 0, emptyanchor
7389 state.bookmarks <- pb
;
7392 then state.anchor <- pa
;
7393 cbput state.hists
.nav pa
;
7399 let add_attrs bb always
dc c =
7402 then Printf.bprintf bb
"\n %s='%b'" s a
7405 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7408 then Printf.bprintf bb
"\n %s='%d'" s a
7411 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7414 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7417 then Printf.bprintf bb
"\n %s='%f'" s a
7421 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7425 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7429 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7433 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7438 | Some
(_N, _A
, _B
) ->
7439 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7444 Printf.bprintf bb
"\n %s='none'" s
7454 else string_of_float
f
7456 Printf.bprintf bb
"\n %s='%s'" s v
7461 | Cmulti
((n, a, b), _) when n > 1 ->
7462 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7463 | Csplit
(n, _) when n > 1 ->
7464 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7470 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7475 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7479 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7483 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7485 oi
"width" c.cwinw
dc.cwinw
;
7486 oi
"height" c.cwinh
dc.cwinh
;
7487 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7488 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7489 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7490 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7491 ob "case-insensitive-search" c.icase
dc.icase
;
7492 ob "preload" c.preload dc.preload;
7493 oi
"page-bias" c.pagebias
dc.pagebias
;
7494 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7495 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7496 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7497 ob "crop-hack" c.crophack
dc.crophack
;
7498 oW
"throttle" c.maxwait
dc.maxwait
;
7499 ob "highlight-links" c.hlinks
dc.hlinks
;
7500 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7501 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7502 oz
"zoom" c.zoom dc.zoom;
7503 ob "presentation" c.presentation
dc.presentation
;
7504 oi
"rotation-angle" c.angle
dc.angle
;
7505 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7506 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7507 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7508 oi
"tex-count" c.texcount
dc.texcount
;
7509 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7510 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7511 ob "persistent-location" c.jumpback
dc.jumpback
;
7512 oc
"background-color" c.bgcolor
dc.bgcolor
;
7513 oi
"tile-width" c.tilew
dc.tilew
;
7514 oi
"tile-height" c.tileh
dc.tileh
;
7515 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7516 ob "checkers" c.checkers
dc.checkers
;
7517 oi
"aalevel" c.aalevel
dc.aalevel
;
7518 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7519 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7520 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7521 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7522 oC
"color-space" c.colorspace
dc.colorspace
;
7523 ob "invert-colors" c.invert
dc.invert
;
7524 oF
"brightness" c.colorscale
dc.colorscale
;
7525 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7526 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7527 oco
"columns" c.columns
dc.columns
;
7528 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7529 os
"selection-command" c.selcmd
dc.selcmd
;
7530 os
"synctex-command" c.stcmd
dc.stcmd
;
7531 os
"pax-command" c.paxcmd
dc.paxcmd
;
7532 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7533 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7534 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7535 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7536 ob "use-pbo" c.usepbo
dc.usepbo
;
7537 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7538 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7539 op
"point-and-x" c.pax
dc.pax
;
7540 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7543 let keymapsbuf always
dc c =
7544 let bb = Buffer.create
16 in
7545 let rec loop = function
7547 | (modename, h) :: rest
->
7548 let dh = findkeyhash dc modename in
7549 if always
|| h <> dh
7551 if Hashtbl.length
h > 0
7553 if Buffer.length
bb > 0
7554 then Buffer.add_char
bb '
\n'
;
7555 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7556 Hashtbl.iter
(fun i
o ->
7557 let isdifferent = always
||
7559 let dO = Hashtbl.find dh i
in
7561 with Not_found
-> true
7566 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7567 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7568 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7569 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7570 Buffer.add_string
bb (Wsi.keyname
k);
7573 let rec loop = function
7575 | km
:: [] -> addkm km
7576 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7580 Buffer.add_string
bb "<map in='";
7584 Buffer.add_string
bb "' out='";
7586 Buffer.add_string
bb "'/>\n"
7589 Buffer.add_string
bb "' out='";
7591 Buffer.add_string
bb "'/>\n"
7593 | KMmulti
(ins, kms
) ->
7594 Buffer.add_char
bb ' '
;
7596 Buffer.add_string
bb "' out='";
7598 Buffer.add_string
bb "'/>\n"
7600 Buffer.add_string
bb "</keymap>";
7610 let uifontsize = fstate.fontsize
in
7611 let bb = Buffer.create
32768 in
7612 let relx = float state.x /. float state.winw in
7614 let cx w = truncate
(relx *. float w) in
7616 (fun (w, h, x) ws
->
7618 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7619 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7620 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7622 (state.winw, state.winh
, state.x) state.winstate
7627 let dc = if conf.bedefault
then conf else dc in
7628 Buffer.add_string
bb "<llppconfig>\n";
7630 if nonemptystr
!fontpath
7632 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7638 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7641 Buffer.add_string
bb "<defaults";
7642 add_attrs bb true dc dc;
7643 let kb = keymapsbuf true dc dc in
7644 if Buffer.length
kb > 0
7646 Buffer.add_string
bb ">\n";
7647 Buffer.add_buffer
bb kb;
7648 Buffer.add_string
bb "\n</defaults>\n";
7650 else Buffer.add_string
bb "/>\n";
7652 let adddoc path pan
anchor c bookmarks =
7653 if bookmarks == [] && c = dc && anchor = emptyanchor
7656 Printf.bprintf
bb "<doc path='%s'"
7657 (enent
path 0 (String.length
path));
7659 if anchor <> emptyanchor
7661 let n, rely, visy
= anchor in
7662 Printf.bprintf
bb " page='%d'" n;
7665 Printf.bprintf
bb " rely='%f'" rely
7667 if abs_float visy
> 1e-6
7669 Printf.bprintf
bb " visy='%f'" visy
7674 then Printf.bprintf
bb " pan='%d'" pan
;
7676 add_attrs bb false dc c;
7677 let kb = keymapsbuf false dc c in
7679 begin match bookmarks with
7681 if Buffer.length
kb > 0
7683 Buffer.add_string
bb ">\n";
7684 Buffer.add_buffer
bb kb;
7685 Buffer.add_string
bb "\n</doc>\n";
7687 else Buffer.add_string
bb "/>\n"
7689 Buffer.add_string
bb ">\n<bookmarks>\n";
7690 List.iter
(fun (title, _, kind
) ->
7691 begin match kind
with
7692 | Oanchor
(page, rely, visy
) ->
7694 "<item title='%s' page='%d'"
7695 (enent
title 0 (String.length
title))
7700 Printf.bprintf
bb " rely='%f'" rely
7702 if abs_float visy
> 1e-6
7704 Printf.bprintf
bb " visy='%f'" visy
7706 | Onone
| Ouri
_ | Oremote
_ | Oremotedest
_ | Olaunch
_ ->
7707 failwith
"unexpected link in bookmarks"
7709 Buffer.add_string
bb "/>\n";
7711 Buffer.add_string
bb "</bookmarks>";
7712 if Buffer.length
kb > 0
7714 Buffer.add_string
bb "\n";
7715 Buffer.add_buffer
bb kb;
7717 Buffer.add_string
bb "\n</doc>\n";
7723 match state.mode with
7724 | Birdseye
(c, pan, _, _, _) ->
7726 match conf.columns
with
7727 | Cmulti
((c, _, _), _) -> Some
c
7731 match c.columns
with
7732 | Cmulti
(c, _) -> Cmulti
(c, [||])
7733 | Csingle
_ -> Csingle
[||]
7734 | Csplit
_ -> failwith
"quit from bird's eye while split"
7736 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7739 let basename = Filename.basename
7740 (if emptystr
state.origin
then state.path else state.origin
)
7742 adddoc basename pan (getanchor ())
7743 (let autoscrollstep =
7744 match state.autoscroll
with
7746 | None
-> conf.autoscrollstep
7747 in begin match state.mode with
7748 | Birdseye beye
-> leavebirdseye beye
true;
7751 { conf with autoscrollstep = autoscrollstep })
7752 (if conf.savebmarks
then state.bookmarks else []);
7754 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7756 then adddoc path x anchor c bookmarks
7758 Buffer.add_string
bb "</llppconfig>\n";
7761 if load1 f && Buffer.length
bb > 0
7764 let tmp = !confpath ^
".tmp" in
7765 let oc = open_out_bin
tmp in
7766 Buffer.output_buffer
oc bb;
7768 Unix.rename
tmp !confpath;
7771 ("error while saving configuration: " ^ exntos exn
)
7775 let adderrmsg src msg
=
7776 Buffer.add_string
state.errmsgs msg
;
7777 state.newerrmsgs
<- true;
7781 let adderrfmt src fmt
=
7782 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7786 let cl = splitatspace cmds
in
7788 try Scanf.sscanf
s fmt
f
7790 adderrfmt "remote exec"
7791 "error processing '%S': %s\n" cmds
(exntos exn
)
7794 | "reload" :: [] -> reload ()
7795 | "goto" :: args :: [] ->
7796 scan args "%u %f %f"
7798 let cmd, _ = state.geomcmds
in
7800 then gotopagexy pageno x y
7803 gotopagexy pageno x y;
7806 state.reprf
<- f state.reprf
7808 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7809 | "gotor" :: args :: [] ->
7811 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
7812 | "gotord" :: args :: [] ->
7814 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
7815 | "rect" :: args :: [] ->
7816 scan args "%u %u %f %f %f %f"
7817 (fun pageno color x0 y0 x1 y1 ->
7818 onpagerect pageno (fun w h ->
7819 let _,w1,h1
,_ = getpagedim pageno in
7820 let sw = float w1 /. float w
7821 and sh = float h1
/. float h in
7825 and y1s
= y1 *. sh in
7826 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7828 state.rects <- (pageno, color, rect) :: state.rects;
7829 G.postRedisplay "rect";
7832 | "activatewin" :: [] -> Wsi.activatewin
()
7833 | "quit" :: [] -> raise Quit
7835 adderrfmt "remote command"
7836 "error processing remote command: %S\n" cmds
;
7840 let scratch = String.create
80 in
7841 let buf = Buffer.create
80 in
7844 try Some
(Unix.read fd
scratch 0 80)
7846 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7847 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7850 match tempfr () with
7856 if Buffer.length
buf > 0
7858 let s = Buffer.contents
buf in
7868 let pos = String.index_from
scratch ppos '
\n'
in
7869 if pos >= n then -1 else pos
7870 with Not_found
-> -1
7874 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7875 let s = Buffer.contents
buf in
7881 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7887 let remoteopen path =
7888 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
7890 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7895 let trimcachepath = ref "" in
7896 let rcmdpath = ref "" in
7897 let pageno = ref None
in
7898 selfexec := Sys.executable_name
;
7901 [("-p", Arg.String
(fun s -> state.password
<- s),
7902 "<password> Set password");
7906 Config.fontpath := s;
7907 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7909 "<path> Set path to the user interface font");
7913 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7914 Config.confpath := s),
7915 "<path> Set path to the configuration file");
7917 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
7918 "<page-number> Jump to page");
7920 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7921 "<path> Set path to the trim cache file");
7923 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7924 "<named-destination> Set named destination");
7926 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7927 ("-cxack", Arg.Set
cxack, " Cut corners");
7929 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7930 "<path> Set path to the remote commands source");
7932 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7933 "<original-path> Set original path");
7935 ("-v", Arg.Unit
(fun () ->
7937 "%s\nconfiguration path: %s\n"
7941 exit
0), " Print version and exit");
7944 (fun s -> state.path <- s)
7945 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7948 then selfexec := !selfexec ^
" -wtmode";
7950 if emptystr
state.path
7951 then (prerr_endline
"file name missing"; exit
1);
7953 if not
(Config.load ())
7954 then prerr_endline
"failed to load configuration";
7955 begin match !pageno with
7956 | Some
pageno -> state.anchor <- (pageno, 0.0, 0.0)
7960 let wsfd, winw, winh
= Wsi.init
(object (self)
7961 val mutable m_hack
= false
7962 val mutable m_clicks
= 0
7963 val mutable m_click_x
= 0
7964 val mutable m_click_y
= 0
7965 val mutable m_lastclicktime
= infinity
7967 method private cleanup
=
7968 state.roam
<- noroam;
7969 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state.pagemap
;
7970 method expose
= if not m_hack
then G.postRedisplay "expose"
7971 method visible
= G.postRedisplay "visible"
7972 method display = m_hack
<- false; display ()
7973 method reshape w h =
7975 m_hack
<- w < state.winw && h < state.winh
;
7977 method mouse
b d x y m =
7978 if d && canselect ()
7980 (* http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx *)
7986 if abs
x - m_click_x
> 10
7987 || abs
y - m_click_y
> 10
7988 || abs_float
(t -. m_lastclicktime
) > 0.3
7990 m_clicks
<- m_clicks
+ 1;
7991 m_lastclicktime
<- t;
7995 G.postRedisplay "cleanup";
7996 state.uioh <- state.uioh#button
b d x y m;
7998 else state.uioh <- state.uioh#multiclick m_clicks
x y m
8003 m_lastclicktime
<- infinity
;
8004 state.uioh <- state.uioh#button
b d x y m
8008 state.uioh <- state.uioh#button
b d x y m
8011 state.mpos
<- (x, y);
8012 state.uioh <- state.uioh#motion
x y
8013 method pmotion
x y =
8014 state.mpos
<- (x, y);
8015 state.uioh <- state.uioh#pmotion
x y
8017 let mascm = m land (
8018 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
8021 let x = state.x and y = state.y in
8023 if x != state.x || y != state.y then self#cleanup
8025 match state.keystate
with
8027 let km = k, mascm in
8030 let modehash = state.uioh#
modehash in
8031 try Hashtbl.find modehash km
8033 try Hashtbl.find (findkeyhash conf "global") km
8034 with Not_found
-> KMinsrt
(k, m)
8036 | KMinsrt
(k, m) -> keyboard k m
8037 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
8038 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
8040 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
8041 List.iter
(fun (k, m) -> keyboard k m) insrt
;
8042 state.keystate
<- KSnone
8043 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
8044 state.keystate
<- KSinto
(keys
, insrt
)
8046 state.keystate
<- KSnone
8049 state.mpos
<- (x, y);
8050 state.uioh <- state.uioh#pmotion
x y
8051 method leave = state.mpos
<- (-1, -1)
8052 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
8053 method quit
= raise Quit
8054 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
8059 List.exists
GlMisc.check_extension
8060 [ "GL_ARB_texture_rectangle"
8061 ; "GL_EXT_texture_recangle"
8062 ; "GL_NV_texture_rectangle" ]
8064 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
8067 let r = GlMisc.get_string `renderer
in
8068 let p = "Mesa DRI Intel(" in
8069 let l = String.length
p in
8070 String.length
r > l && String.sub
r 0 l = p
8073 defconf.sliceheight
<- 1024;
8074 defconf.texcount
<- 32;
8075 defconf.usepbo
<- true;
8079 match Ne.res Unix.pipe
with
8081 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
8085 match Ne.res Unix.pipe
with
8087 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
8097 setcheckers conf.checkers
;
8099 if conf.redirectstderr
8102 let s = Buffer.contents
state.errmsgs ^
8103 (match state.errfd
with
8105 let s = String.create
(80*24) in
8108 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
8110 then Unix.read fd
s 0 (String.length
s)
8116 else String.sub
s 0 n
8120 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
8121 with exn
-> print_endline
(exntos exn
)
8126 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
8127 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
8128 !Config.fontpath, !trimcachepath,
8129 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
8131 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
8134 state.text <- "Opening " ^
(mbtoutf8
state.path);
8136 opendoc state.path state.password
;
8140 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
8143 if nonemptystr
!rcmdpath
8144 then remoteopen !rcmdpath
8149 let rec loop deadline
=
8151 match state.errfd
with
8152 | None
-> [state.sr
; state.wsfd]
8153 | Some fd
-> [state.sr
; state.wsfd; fd
]
8158 | Some fd
-> fd
:: r
8162 state.redisplay
<- false;
8169 if deadline
= infinity
8171 else max
0.0 (deadline
-. now)
8176 try Unix.select
r [] [] timeout
8177 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
8183 if state.ghyll
== noghyll
8185 match state.autoscroll
with
8186 | Some step
when step
!= 0 ->
8187 let y = state.y + step
in
8191 else if y >= state.maxy then 0 else y
8194 if state.mode = View
8195 then state.text <- "";
8198 else deadline
+. 0.01
8203 let rec checkfds = function
8205 | fd
:: rest
when fd
= state.sr
->
8206 let cmd = readcmd state.sr
in
8210 | fd
:: rest
when fd
= state.wsfd ->
8214 | fd
:: rest
when Some fd
= !optrfd ->
8215 begin match remote fd
with
8216 | None
-> optrfd := remoteopen !rcmdpath;
8217 | opt -> optrfd := opt
8222 let s = String.create
80 in
8223 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
8224 if conf.redirectstderr
8226 Buffer.add_substring
state.errmsgs
s 0 n;
8227 state.newerrmsgs
<- true;
8228 state.redisplay
<- true;
8231 prerr_string
(String.sub
s 0 n);
8239 if deadline
= infinity
8243 match state.autoscroll
with
8244 | Some step
when step
!= 0 -> deadline1
8245 | _ -> if state.ghyll
== noghyll then infinity
else deadline1