8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
23 type params
= (angle
* fitmodel
* trimparams
24 * texcount
* sliceheight
* memsize
25 * colorspace
* fontpath
* trimcachepath
35 and trimmargins
= bool
36 and interpagespace
= int
43 and trimcachepath
= string
46 and irect
= (int * int * int * int)
47 and trimparams
= (trimmargins
* irect
)
48 and colorspace
= | Rgb
| Bgr
| Gray
49 and fitmodel
= | FitWidth
| FitProportional
| FitPage
57 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
66 | LDfirstvisible
of (int * int * int)
81 | KMmulti
of key list
* key list
83 and keyhash
= (key
, keymap
) Hashtbl.t
86 | KSinto
of (key list
* key list
)
89 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
90 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
92 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
94 external init
: pipe
-> params
-> unit = "ml_init";;
95 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
96 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
97 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
98 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
99 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
100 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
101 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
102 external measurestr
: int -> string -> float = "ml_measure_string";;
103 external postprocess
:
104 opaque
-> int -> int -> int -> (int * string * int) -> int
106 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
107 external platform
: unit -> platform
= "ml_platform";;
108 external setaalevel
: int -> unit = "ml_setaalevel";;
109 external realloctexts
: int -> bool = "ml_realloctexts";;
110 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
111 external getlink
: opaque
-> int -> under
= "ml_getlink";;
112 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
113 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
114 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
115 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
116 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
117 external freepbo
: string -> unit = "ml_freepbo";;
118 external unmappbo
: string -> unit = "ml_unmappbo";;
119 external pbousable
: unit -> bool = "ml_pbo_usable";;
120 external unproject
: opaque
-> int -> int -> (int * int) option
122 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
124 let platform_to_string = function
125 | Punknown
-> "unknown"
129 | Pfreebsd
-> "FreeBSD"
130 | Pdragonflybsd
-> "DragonflyBSD"
131 | Popenbsd
-> "OpenBSD"
132 | Pnetbsd
-> "NetBSD"
133 | Pcygwin
-> "Cygwin"
136 let platform = platform ();;
138 let now = Unix.gettimeofday
;;
140 let selfexec = ref "";;
143 if platform = Pcygwin
145 let sh = "/bin/sh" in
146 let args = [|sh; "-c"; cmd
|] in
147 let rec std si so se
= function
149 | (fd
, 0) :: rest
-> std fd so se rest
150 | (fd
, -1) :: rest
->
151 Unix.set_close_on_exec fd
;
154 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
156 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
157 ignore
(Unix.create_process
sh args si so se
)
162 type mpos
= int * int
164 | Msel
of (mpos
* mpos
)
166 | Mscrolly
| Mscrollx
167 | Mzoom
of (int * int)
168 | Mzoomrect
of (mpos
* mpos
)
172 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
173 and onkey
= string -> int -> te
174 and ondone
= string -> unit
175 and histcancel
= unit -> unit
176 and onhist
= ((histcmd
-> string) * histcancel
)
177 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
178 and cancelonempty
= bool
183 | TEswitch
of textentry
194 let bound v minv maxv
=
195 max minv
(min maxv v
);
199 { store
= Array.create n v
206 let cbcap b
= Array.length b
.store
;;
211 b
.wc
<- (b
.wc
+ 1) mod cap;
213 b
.len
<- min
(b
.len
+ 1) cap;
216 let cbempty b
= b
.len
= 0;;
218 let cbgetg b circular dir
=
222 let rc = b
.rc + dir
in
234 else bound rc 0 (b
.len
-1)
240 let cbget b
= cbgetg b
false;;
241 let cbgetc b
= cbgetg b
true;;
243 let drawstring size x y s
=
245 Gl.enable `texture_2d
;
246 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
247 ignore
(drawstr size x y s
);
249 Gl.disable `texture_2d
;
252 let drawstring1 size x y s
=
256 let drawstring2 size x y fmt
=
257 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
276 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
277 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
278 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
279 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
280 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
281 dolog
" column %d" l
.pagecol
;
285 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
287 dolog
" x0,y0=(% f, % f)" x0 y0
;
288 dolog
" x1,y1=(% f, % f)" x1 y1
;
289 dolog
" x2,y2=(% f, % f)" x2 y2
;
290 dolog
" x3,y3=(% f, % f)" x3 y3
;
294 type multicolumns
= multicol
* pagegeom
295 and singlecolumn
= pagegeom
296 and splitcolumns
= columncount
* pagegeom
297 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
298 and multicol
= columncount
* covercount
* covercount
300 and columncount
= int
301 and covercount
= int;;
308 { mutable scrollbw
: int
309 ; mutable scrollh
: int
310 ; mutable scrollb
: scrollb
311 ; mutable icase
: bool
312 ; mutable preload
: bool
313 ; mutable pagebias
: int
314 ; mutable verbose
: bool
315 ; mutable debug
: bool
316 ; mutable scrollstep
: int
317 ; mutable hscrollstep
: int
318 ; mutable maxhfit
: bool
319 ; mutable crophack
: bool
320 ; mutable autoscrollstep
: int
321 ; mutable maxwait
: float option
322 ; mutable hlinks
: bool
323 ; mutable underinfo
: bool
324 ; mutable interpagespace
: interpagespace
325 ; mutable zoom
: float
326 ; mutable presentation
: bool
327 ; mutable angle
: angle
328 ; mutable cwinw
: int
329 ; mutable cwinh
: int
330 ; mutable savebmarks
: bool
331 ; mutable fitmodel
: fitmodel
332 ; mutable trimmargins
: trimmargins
333 ; mutable trimfuzz
: irect
334 ; mutable memlimit
: memsize
335 ; mutable texcount
: texcount
336 ; mutable sliceheight
: sliceheight
337 ; mutable thumbw
: width
338 ; mutable jumpback
: bool
339 ; mutable bgcolor
: (float * float * float)
340 ; mutable bedefault
: bool
341 ; mutable tilew
: int
342 ; mutable tileh
: int
343 ; mutable mustoresize
: memsize
344 ; mutable checkers
: bool
345 ; mutable aalevel
: int
346 ; mutable urilauncher
: string
347 ; mutable pathlauncher
: string
348 ; mutable colorspace
: colorspace
349 ; mutable invert
: bool
350 ; mutable colorscale
: float
351 ; mutable redirectstderr
: bool
352 ; mutable ghyllscroll
: (int * int * int) option
353 ; mutable columns
: columns
354 ; mutable beyecolumns
: columncount
option
355 ; mutable selcmd
: string
356 ; mutable paxcmd
: string
357 ; mutable updatecurs
: bool
358 ; mutable keyhashes
: (string * keyhash
) list
359 ; mutable hfsize
: int
360 ; mutable pgscale
: float
361 ; mutable usepbo
: bool
362 ; mutable wheelbypage
: bool
363 ; mutable stcmd
: string
364 ; mutable riani
: bool
365 ; mutable pax
: (float * int * int) ref option
366 ; mutable paxmark
: mark
369 | Csingle
of singlecolumn
370 | Cmulti
of multicolumns
371 | Csplit
of splitcolumns
374 type anchor
= pageno
* top
* dtop
;;
376 type outline
= string * int * anchor
;;
378 type rect
= float * float * float * float * float * float * float * float;;
380 type tile
= opaque
* pixmapsize
* elapsed
381 and elapsed
= float;;
382 type pagemapkey
= pageno
* gen
;;
383 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
387 let emptyanchor = (0, 0.0, 0.0);;
389 type infochange
= | Memused
| Docinfo
| Pdim
;;
391 class type uioh
= object
392 method display
: unit
393 method key
: int -> int -> uioh
394 method button
: int -> bool -> int -> int -> int -> uioh
395 method motion
: int -> int -> uioh
396 method pmotion
: int -> int -> uioh
397 method infochanged
: infochange
-> unit
398 method scrollpw
: (int * float * float)
399 method scrollph
: (int * float * float)
400 method modehash
: keyhash
401 method eformsgs
: bool
405 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
406 | Textentry
of (textentry
* onleave
)
408 | LinkNav
of linktarget
409 and onleave
= leavetextentrystatus
-> unit
410 and leavetextentrystatus
= | Cancel
| Confirm
411 and helpitem
= string * int * action
414 | Action
of (uioh
-> uioh
)
416 | Ltexact
of (pageno
* int)
420 let isbirdseye = function Birdseye _
-> true | _
-> false;;
421 let istextentry = function Textentry _
-> true | _
-> false;;
425 | Loading
of (page
* gen
)
427 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
429 | Outlining
of outline list
432 let emptykeyhash = Hashtbl.create
0;;
433 let nouioh : uioh
= object (self
)
435 method key _ _
= self
436 method button _ _ _ _ _
= self
437 method motion _ _
= self
438 method pmotion _ _
= self
439 method infochanged _
= ()
440 method scrollpw
= (0, nan
, nan
)
441 method scrollph
= (0, nan
, nan
)
442 method modehash
= emptykeyhash
443 method eformsgs
= false
447 { mutable sr
: Unix.file_descr
448 ; mutable sw
: Unix.file_descr
449 ; mutable wsfd
: Unix.file_descr
450 ; mutable errfd
: Unix.file_descr
option
451 ; mutable stderr
: Unix.file_descr
452 ; mutable errmsgs
: Buffer.t
453 ; mutable newerrmsgs
: bool
457 ; mutable anchor
: anchor
458 ; mutable ranchors
: (string * string * anchor
* string) list
460 ; mutable layout
: page list
461 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
462 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
463 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
464 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
465 ; mutable pagecount
: int
466 ; mutable currently
: currently
467 ; mutable mstate
: mstate
468 ; mutable searchpattern
: string
469 ; mutable rects
: (pageno
* recttype
* rect
) list
470 ; mutable rects1
: (pageno
* recttype
* rect
) list
471 ; mutable text
: string
472 ; mutable winstate
: Wsi.winstate list
473 ; mutable mode
: mode
474 ; mutable uioh
: uioh
475 ; mutable outlines
: outline array
476 ; mutable bookmarks
: outline list
477 ; mutable path
: string
478 ; mutable password
: string
479 ; mutable nameddest
: string
480 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
481 ; mutable memused
: memsize
483 ; mutable throttle
: (page list
* int * float) option
484 ; mutable autoscroll
: int option
485 ; mutable ghyll
: (int option -> unit)
486 ; mutable help
: helpitem array
487 ; mutable docinfo
: (int * string) list
488 ; mutable texid
: GlTex.texture_id
option
490 ; mutable prevzoom
: float
491 ; mutable progress
: float
492 ; mutable redisplay
: bool
493 ; mutable mpos
: mpos
494 ; mutable keystate
: keystate
495 ; mutable glinks
: bool
496 ; mutable prevcolumns
: (columns
* float) option
499 ; mutable reprf
: (unit -> unit)
500 ; mutable origin
: string
501 ; mutable roam
: (unit -> unit)
504 { pat
: string circbuf
505 ; pag
: string circbuf
506 ; nav
: anchor circbuf
507 ; sel
: string circbuf
514 ; scrollb
= scrollbhv lor scrollbvv
530 ; presentation
= false
535 ; fitmodel
= FitProportional
536 ; trimmargins
= false
537 ; trimfuzz
= (0,0,0,0)
538 ; memlimit
= 32 lsl 20
543 ; bgcolor
= (0.5, 0.5, 0.5)
547 ; mustoresize
= 256 lsl 20
552 | Plinux
| Pfreebsd
| Pdragonflybsd
553 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
554 | Posx
-> "open \"%s\""
555 | Pcygwin
-> "cygstart \"%s\""
556 | Punknown
-> "echo %s")
557 ; pathlauncher
= "lp \"%s\""
560 | Plinux
| Pfreebsd
| Pdragonflybsd
561 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
569 ; redirectstderr
= false
571 ; columns
= Csingle
[||]
577 ; wheelbypage
= false
578 ; stcmd
= "echo SyncTex"
581 ; paxmark
= Mark_word
583 let mk n
= (n
, Hashtbl.create
1) in
597 let wtmode = ref false;;
598 let cxack = ref false;;
600 let findkeyhash c name
=
601 try List.assoc name c
.keyhashes
602 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
605 let conf = { defconf with angle
= defconf.angle
};;
607 let pgscale h
= truncate
(float h
*. conf.pgscale);;
610 { mutable fontsize
: int
611 ; mutable wwidth
: float
612 ; mutable maxrows
: int
624 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
625 let len = String.length s
in
626 if colonpos >= 0 && colonpos + 3 < len
628 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
631 try String.rindex_from s
colonpos ' '
635 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
638 | "http" | "ftp" | "mailto" ->
640 try String.index_from s
colonpos ' '
641 with Not_found
-> len
643 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
651 if String.length
conf.urilauncher
= 0
652 then print_endline uri
654 let url = geturl uri
in
655 if String.length
url = 0
656 then Printf.eprintf
"obtained empty url from uri %S" uri
658 let re = Str.regexp
"%s" in
659 let command = Str.global_replace
re url conf.urilauncher
in
663 "failed to execute `%s': %s\n" command (exntos exn
);
669 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
670 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
674 let strings = version () :: "" :: Help.keys
in
677 let url = geturl s
in
678 if String.length
url > 0
679 then (s
, 0, Action
(fun u
-> gotouri url; u
))
680 else (s
, 0, Noaction
)
685 let firstgeomcmds = "", [];;
686 let noreprf () = ();;
693 ; stderr
= Unix.stderr
694 ; errmsgs
= Buffer.create
0
699 ; anchor
= emptyanchor
703 ; tilelru
= Queue.create
()
704 ; pagemap
= Hashtbl.create
10
705 ; tilemap
= Hashtbl.create
10
721 ; geomcmds
= firstgeomcmds
723 { nav
= cbnew 10 emptyanchor
748 ; roam
= (fun () -> ())
753 if (conf.scrollb
land scrollbhv = 0)
754 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
760 if (conf.scrollb
land scrollbvv = 0)
765 let wadjsb w
= w
- vscrollw ();;
768 fstate.fontsize
<- n
;
769 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
770 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
776 Printf.kprintf prerr_endline fmt
778 Printf.kprintf ignore fmt
782 if String.length
conf.pathlauncher
= 0
783 then print_endline
state.path
785 let re = Str.regexp
"%s" in
786 let command = Str.global_replace
re state.path
conf.pathlauncher
in
789 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
795 type 'a t
= | Res
of 'a
| Exn
of exn
;;
798 try Res
(Unix.pipe ())
803 try tempfailureretry
Unix.close fd
804 with exn
-> f
(exntos exn
)
808 try Res
(tempfailureretry
Unix.dup fd
)
813 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
818 let redirectstderr () =
819 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
820 if conf.redirectstderr
822 match Ne.pipe () with
824 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
827 begin match Ne.dup Unix.stderr
with
829 dolog
"failed to dup stderr: %s" (exntos exn
);
830 Ne.clo r
(clofail "pipe/r");
831 Ne.clo w
(clofail "pipe/w");
833 | Ne.Res dupstderr
->
834 begin match Ne.dup2 w
Unix.stderr
with
836 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
837 Ne.clo dupstderr
(clofail "stderr duplicate");
838 Ne.clo r
(clofail "redir pipe/r");
839 Ne.clo w
(clofail "redir pipe/w");
842 state.stderr
<- dupstderr
;
843 state.errfd
<- Some r
;
847 state.newerrmsgs
<- false;
848 begin match state.errfd
with
850 begin match Ne.dup2 state.stderr
Unix.stderr
with
852 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
854 Ne.clo fd
(clofail "dup of stderr");
859 prerr_string
(Buffer.contents
state.errmsgs
);
861 Buffer.clear
state.errmsgs
;
867 let postRedisplay who
=
869 then prerr_endline
("redisplay for " ^ who
);
870 state.redisplay
<- true;
874 let getopaque pageno
=
875 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
876 with Not_found
-> None
879 let putopaque pageno opaque
=
880 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
883 let pagetranslatepoint l x y
=
884 let dy = y
- l
.pagedispy
in
885 let y = dy + l
.pagey
in
886 let dx = x
- l
.pagedispx
in
887 let x = dx + l
.pagex
in
891 let onppundermouse g
x y d
=
894 begin match getopaque l
.pageno
with
896 let x0 = l
.pagedispx
in
897 let x1 = x0 + l
.pagevw
in
898 let y0 = l
.pagedispy
in
899 let y1 = y0 + l
.pagevh
in
900 if y >= y0 && y <= y1 && x >= x0 && x <= x1
902 let px, py
= pagetranslatepoint l
x y in
903 match g opaque l
px py
with
916 let g opaque _
px py
=
917 match whatsunder opaque
px py
with
919 | under
-> Some under
921 onppundermouse g x y Unone
926 match unproject opaque
x y with
927 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
930 onppundermouse g x y None
;
934 state.text
<- Printf.sprintf
"%c%s" c s
;
935 G.postRedisplay "showtext";
939 let g opaque l
px py
=
940 if markunder opaque
px py
conf.paxmark
943 match getopaque l
.pageno
with
946 match Ne.pipe () with
950 "can not create mark pipe: %s"
953 let doclose what fd
=
954 Ne.clo fd
(fun msg
->
955 dolog
"%s close failed: %s" what msg
)
958 popen conf.paxcmd
[r
, 0; w
, -1];
959 copysel w opaque
false;
961 G.postRedisplay "paxunder";
963 dolog
"can not execute %S: %s"
964 conf.paxcmd
(exntos exn
);
971 G.postRedisplay "paxunder";
973 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
977 match Ne.pipe () with
979 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
982 try popen conf.selcmd
[r
, 0; w
, -1]; true
985 (Printf.sprintf
"failed to execute %s: %s"
986 conf.selcmd
(exntos exn
));
990 Ne.clo fd
(fun msg
->
991 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
997 let l = String.length s
in
998 let n = tempfailureretry
(Unix.write w s
0) l in
1003 "failed to write %d characters to sel pipe, wrote %d"
1008 (Printf.sprintf
"failed to write to sel pipe: %s"
1017 let undertext = function
1020 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1021 | Utext s
-> "font: " ^ s
1022 | Uunexpected s
-> "unexpected: " ^ s
1023 | Ulaunch s
-> "launch: " ^ s
1024 | Unamed s
-> "named: " ^ s
1025 | Uremote
(filename
, pageno
) ->
1026 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1029 let updateunder x y =
1030 match getunder x y with
1031 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1033 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1034 Wsi.setcursor
Wsi.CURSOR_INFO
1035 | Ulinkgoto
(pageno
, _
) ->
1037 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1038 Wsi.setcursor
Wsi.CURSOR_INFO
1040 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1041 Wsi.setcursor
Wsi.CURSOR_TEXT
1043 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1044 Wsi.setcursor
Wsi.CURSOR_INHERIT
1046 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1047 Wsi.setcursor
Wsi.CURSOR_INHERIT
1049 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1050 Wsi.setcursor
Wsi.CURSOR_INHERIT
1051 | Uremote
(filename
, pageno
) ->
1052 if conf.underinfo
then showtext 'r'
1053 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1054 Wsi.setcursor
Wsi.CURSOR_INFO
1057 let showlinktype under
=
1063 let s = undertext under
in
1068 let b = Buffer.create
(String.length
s + 1) in
1069 Buffer.add_string
b s;
1070 Buffer.add_char
b c
;
1074 module type TextEnumType
=
1078 val names
: string array
1081 module TextEnumMake
(Ten
: TextEnumType
) =
1083 let names = Ten.names;;
1084 let to_int (t
: Ten.t
) = Obj.magic t
;;
1085 let to_string t
= names.(to_int t
);;
1086 let of_int n : Ten.t
= Obj.magic
n;;
1089 if i
= Array.length
names
1090 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1092 if Ten.names.(i
) = s
1099 module CSTE
= TextEnumMake
(struct
1100 type t
= colorspace
;;
1101 let name = "colorspace";;
1102 let names = [|"rgb"; "bgr"; "gray"|];;
1105 module MTE
= TextEnumMake
(struct
1108 let names = [|"page"; "block"; "line"; "word"|];;
1111 module FMTE
= TextEnumMake
(struct
1113 let name = "fitmodel";;
1114 let names = [|"width"; "proportional"; "page"|];;
1117 let intentry_with_suffix text key
=
1119 if key
>= 32 && key
< 127
1123 match Char.lowercase
c with
1125 let text = addchar text c in
1128 | 'k'
| 'm'
| '
g'
->
1129 let text = addchar text c in
1133 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1137 let multicolumns_to_string (n, a
, b) =
1139 then Printf.sprintf
"%d" n
1140 else Printf.sprintf
"%d,%d,%d" n a
b;
1143 let multicolumns_of_string s =
1145 (int_of_string
s, 0, 0)
1147 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1149 then failwith
"subtly broken"; (n, a
, b)
1155 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1156 if n != 4 then failwith
"incomplete read(len)";
1158 lor (Char.code
s.[0] lsl 24)
1159 lor (Char.code
s.[1] lsl 16)
1160 lor (Char.code
s.[2] lsl 8)
1161 lor (Char.code
s.[3] lsl 0)
1163 let s = String.create
len in
1164 let n = tempfailureretry
(Unix.read fd
s 0) len in
1165 if n != len then failwith
"incomplete read(data)";
1169 let btod b = if b then 1 else 0;;
1172 let b = Buffer.create
16 in
1173 Buffer.add_string
b "llll";
1176 let s = Buffer.contents
b in
1177 let n = String.length
s in
1179 (* dolog "wcmd %S" (String.sub s 4 len); *)
1180 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1181 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1182 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1183 s.[3] <- Char.chr
(len land 0xff);
1184 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1185 if n'
!= n then failwith
"write failed";
1190 let d = state.winh
- h
in
1191 max
conf.interpagespace
((d + 1) / 2)
1194 let rowyh (c, coverA
, coverB
) b n =
1195 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1197 let _, _, vy
, (_, _, h
, _) = b.(n) in
1200 let n'
= n - coverA
in
1203 let e = min
state.pagecount
(s + c) in
1204 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1205 let _, _, y, (_, _, h
, _) = b.(m
) in
1206 let miny = min
miny y in
1207 let maxh = max
maxh h
in
1208 find (m
+1) miny maxh
1213 match conf.columns
with
1214 | Cmulti
((_, _, _) as cl
, b) ->
1215 if Array.length
b > 0
1217 let y, h
= rowyh cl
b (Array.length
b - 1) in
1218 y + h
+ (if conf.presentation
then calcips h
else 0)
1221 if Array.length
b > 0
1223 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1224 y + h
+ (if conf.presentation
then calcips h
else 0)
1227 if Array.length
b > 0
1229 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1234 let getpageyh pageno
=
1235 let pageno = bound pageno 0 (state.pagecount
-1) in
1236 match conf.columns
with
1238 if Array.length
b = 0
1241 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1243 if conf.presentation
1249 if Array.length
b = 0
1252 let y, h
= rowyh cl
b pageno in
1254 if conf.presentation
1260 if Array.length
b = 0
1264 let (_, _, y, (_, _, h
, _)) = b.(n) in
1268 let getpagedim pageno =
1271 | (n, _, _, _) as pdim
:: rest
->
1273 then (if n = pageno then pdim
else ppdim
)
1278 f (-1, -1, -1, -1) state.pdims
1281 let getpagey pageno = fst
(getpageyh pageno);;
1283 let nogeomcmds cmds
=
1285 | s, [] -> String.length
s = 0
1290 let ((c, coverA
, coverB
) as cl
), b =
1291 match conf.columns
with
1292 | Csingle
b -> (1, 0, 0), b
1293 | Cmulti
(c, b) -> c, b
1294 | Csplit
(_, b) -> (1, 0, 0), b
1296 if Array.length
b = 0
1299 let rec bsearch nmin nmax
=
1301 then bound nmin
0 (state.pagecount
-1)
1303 let n = (nmax
+ nmin
) / 2 in
1304 let vy, h
= rowyh cl
b n in
1306 if conf.presentation
1308 let ips = calcips h
in
1309 let y0 = vy - ips in
1310 let y1 = vy + h
+ ips in
1314 then 0, vy + h
+ conf.interpagespace
1316 let y0 = vy - conf.interpagespace
in
1317 y0, y0 + h
+ conf.interpagespace
1320 if y >= y0 && y < y1
1327 if n < state.pagecount
- coverB
1328 then ((n-coverA
)/c)*c + coverA
1335 then bsearch (n+1) nmax
1336 else bsearch nmin
(n-1)
1339 let r = bsearch 0 (state.pagecount
-1) in
1343 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1344 let sh = sh - (hscrollh ()) in
1345 let rec fold accu
n =
1346 if n = Array.length
b
1349 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1352 || n = state.pagecount
- coverB
1353 || (n - coverA
) mod columns
= columns
- 1)
1359 let pagey = max
0 (y - vy) in
1360 let pagedispy = if pagey > 0 then 0 else vy - y in
1361 let pagedispx, pagex
=
1363 if n = coverA
- 1 || n = state.pagecount
- coverB
1364 then state.x + (wadjsb state.winw
- w
) / 2
1365 else dx + xoff
+ state.x
1372 let vw = wadjsb state.winw
- pagedispx in
1373 let pw = w
- pagex
in
1376 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1377 if pagevw > 0 && pagevh > 0
1381 ; pagedimno
= pdimno
1388 ; pagedispx = pagedispx
1389 ; pagedispy = pagedispy
1401 List.rev
(fold [] (page_of_y y));
1404 let layoutS (columns
, b) y sh =
1405 let sh = sh - hscrollh () in
1406 let rec fold accu n =
1407 if n = Array.length
b
1410 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1417 let x = xoff
+ state.x in
1418 let pagey = max
0 (y - vy) in
1419 let pagedispy = if pagey > 0 then 0 else vy - y in
1420 let pagedispx, pagex
=
1434 let pagecolw = pagew
/columns
in
1436 if pagecolw < state.winw
1437 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1441 let vw = wadjsb state.winw
- pagedispx in
1442 let pw = pagew
- pagex
in
1445 let pagevw = min
pagevw pagecolw in
1446 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1447 if pagevw > 0 && pagevh > 0
1450 { pageno = n/columns
1451 ; pagedimno
= pdimno
1458 ; pagedispx = pagedispx
1459 ; pagedispy = pagedispy
1460 ; pagecol
= n mod columns
1471 List.rev
(fold [] 0)
1475 if nogeomcmds state.geomcmds
1477 match conf.columns
with
1478 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1479 | Cmulti
c -> layoutN c y sh
1480 | Csplit
s -> layoutS s y sh
1485 let y = state.y + incr
in
1487 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1492 let tilex = l.pagex
mod conf.tilew
in
1493 let tiley = l.pagey mod conf.tileh
in
1495 let col = l.pagex
/ conf.tilew
in
1496 let row = l.pagey / conf.tileh
in
1498 let rec rowloop row y0 dispy h
=
1502 let dh = conf.tileh
- y0 in
1503 let dh = min h
dh in
1504 let rec colloop col x0 dispx w
=
1508 let dw = conf.tilew
- x0 in
1509 let dw = min w
dw in
1511 f col row dispx dispy
x0 y0 dw dh;
1512 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1515 colloop col tilex l.pagedispx l.pagevw;
1516 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1519 if l.pagevw > 0 && l.pagevh > 0
1520 then rowloop row tiley l.pagedispy l.pagevh;
1523 let gettileopaque l col row =
1525 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1527 try Some
(Hashtbl.find state.tilemap
key)
1528 with Not_found
-> None
1531 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1532 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1533 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1536 let drawtiles l color
=
1538 let f col row x y tilex tiley w h
=
1539 match gettileopaque l col row with
1540 | Some
(opaque
, _, t
) ->
1541 let params = x, y, w
, h
, tilex, tiley in
1545 GlFunc.blend_func `zero `one_minus_src_color
;
1547 drawtile
params opaque
;
1549 then Gl.disable `blend
;
1552 let s = Printf.sprintf
1556 let w = measurestr
fstate.fontsize
s in
1557 GlMisc.push_attrib
[`current
];
1558 GlDraw.color
(0.0, 0.0, 0.0);
1560 (float (x-2), float (y-2))
1561 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1562 GlDraw.color
(1.0, 1.0, 1.0);
1563 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1564 GlMisc.pop_attrib
();
1569 let lw = wadjsb state.winw
- x in
1572 let lh = state.winh
- y in
1575 begin match state.texid
with
1577 Gl.enable `texture_2d
;
1578 GlTex.bind_texture `texture_2d id
;
1581 and x1 = float (x+w)
1582 and y1 = float (y+h
) in
1584 let tw = float w /. 16.0
1585 and th
= float h
/. 16.0 in
1586 let tx0 = float tilex /. 16.0
1587 and ty0
= float tiley /. 16.0 in
1589 and ty1
= ty0
+. th
in
1590 GlDraw.begins `quads
;
1591 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1592 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1593 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1594 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1597 Gl.disable `texture_2d
;
1599 GlDraw.color
(1.0, 1.0, 1.0);
1602 (float (x+w), float (y+h
));
1604 if w > 128 && h
> fstate.fontsize
+ 10
1606 GlDraw.color
(0.0, 0.0, 0.0);
1609 then (col*conf.tilew
, row*conf.tileh
)
1612 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1619 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1621 let tilevisible1 l x y =
1623 and ax1
= l.pagex
+ l.pagevw
1625 and ay1
= l.pagey + l.pagevh in
1629 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1630 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1632 let rx0 = max
ax0 bx0
1633 and ry0
= max ay0 by0
1634 and rx1
= min ax1
bx1
1635 and ry1
= min ay1 by1
in
1637 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1638 nonemptyintersection
1641 let tilevisible layout n x y =
1642 let rec findpageinlayout m
= function
1643 | l :: rest
when l.pageno = n ->
1644 tilevisible1 l x y || (
1645 match conf.columns
with
1646 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1649 | _ :: rest
-> findpageinlayout 0 rest
1652 findpageinlayout 0 layout;
1655 let tileready l x y =
1656 tilevisible1 l x y &&
1657 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1660 let tilepage n p
layout =
1661 let rec loop = function
1665 let f col row _ _ _ _ _ _ =
1666 if state.currently
= Idle
1668 match gettileopaque l col row with
1671 let x = col*conf.tilew
1672 and y = row*conf.tileh
in
1674 let w = l.pagew
- x in
1678 let h = l.pageh
- y in
1683 then getpbo
w h conf.colorspace
1686 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1689 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1690 conf.tilew
, conf.tileh
1699 if nogeomcmds state.geomcmds
1703 let preloadlayout y =
1704 let y = if y < state.winh
then 0 else y - state.winh
in
1705 let h = state.winh
*3 in
1710 let rec loop pages
=
1711 if state.currently
!= Idle
1716 begin match getopaque l.pageno with
1718 wcmd "page %d %d" l.pageno l.pagedimno
;
1719 state.currently
<- Loading
(l, state.gen
);
1721 tilepage l.pageno opaque pages
;
1726 if nogeomcmds state.geomcmds
1732 if conf.preload && state.currently
= Idle
1733 then load (preloadlayout state.y);
1736 let layoutready layout =
1737 let rec fold all ls
=
1738 all
&& match ls
with
1740 let seen = ref false in
1741 let allvisible = ref true in
1742 let foo col row _ _ _ _ _ _ =
1744 allvisible := !allvisible &&
1745 begin match gettileopaque l col row with
1751 fold (!seen && !allvisible) rest
1754 let alltilesvisible = fold true layout in
1759 let y = bound y 0 state.maxy
in
1760 let y, layout, proceed
=
1761 match conf.maxwait
with
1762 | Some time
when state.ghyll
== noghyll ->
1763 begin match state.throttle
with
1765 let layout = layout y state.winh
in
1766 let ready = layoutready layout in
1770 state.throttle
<- Some
(layout, y, now ());
1772 else G.postRedisplay "gotoy showall (None)";
1774 | Some
(_, _, started
) ->
1775 let dt = now () -. started
in
1778 state.throttle
<- None
;
1779 let layout = layout y state.winh
in
1781 G.postRedisplay "maxwait";
1788 let layout = layout y state.winh
in
1789 if not
!wtmode || layoutready layout
1790 then G.postRedisplay "gotoy ready";
1796 state.layout <- layout;
1797 begin match state.mode
with
1798 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1799 let rec loop = function
1801 state.mode
<- LinkNav
(Ltgendir
0)
1802 | l :: _ when l.pageno = pageno ->
1803 begin match getopaque pageno with
1805 state.mode
<- LinkNav
(Ltgendir
0)
1807 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1808 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1809 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1810 then state.mode
<- LinkNav
(Ltgendir
0)
1812 | _ :: rest
-> loop rest
1817 begin match state.mode
with
1818 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1819 if not
(pagevisible layout pageno)
1821 match state.layout with
1824 state.mode
<- Birdseye
(
1825 conf, leftx
, l.pageno, hooverpageno
, anchor
1828 | LinkNav
(Ltgendir dir
as lt
) ->
1830 let rec loop = function
1833 match getopaque l.pageno with
1839 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1841 if dir
> 0 then LDfirst
else LDlast
1847 | Lnotfound
-> loop rest
1849 showlinktype (getlink opaque
n);
1850 Ltexact
(l.pageno, n)
1854 state.mode
<- LinkNav
linknav
1859 state.ghyll
<- noghyll;
1862 let mx, my
= state.mpos
in
1867 let conttiling pageno opaque
=
1868 tilepage pageno opaque
1869 (if conf.preload then preloadlayout state.y else state.layout)
1872 let gotoy_and_clear_text y =
1873 if not
conf.verbose
then state.text <- "";
1879 let coloff = l.pagecol
* l.pageh
in
1880 float (l.pagey + coloff) /. float l.pageh
1887 if conf.presentation
1888 then float l.pagedispy /. float (calcips l.pageh
)
1889 else float l.pagedispy /. float conf.interpagespace
1892 (l.pageno, top, dtop)
1896 match state.layout with
1897 | l :: _ -> getanchor1 l
1899 let n = page_of_y state.y in
1903 let y, h = getpageyh n in
1904 let dy = y - state.y in
1906 if conf.presentation
1908 let ips = calcips h in
1909 float (dy + ips) /. float ips
1911 float dy /. float conf.interpagespace
1916 let getanchory (n, top, dtop) =
1917 let y, h = getpageyh n in
1918 if conf.presentation
1920 let ips = calcips h in
1921 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1923 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1926 let gotoanchor anchor
=
1927 gotoy (getanchory anchor
);
1931 cbput state.hists
.nav
(getanchor ());
1935 let anchor = cbgetc state.hists
.nav dir
in
1940 let scroll f n a
b =
1941 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1943 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1945 then s (float f /. float a
)
1948 then 1.0 -. s ((float (f-b) /. float (n-b)))
1954 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1955 let iv x = x**3.-.0.5*.x**4. in
1957 let ins = float a
*. iv1
1958 and outs
= float (n-b) *. iv1 in
1960 ins +. outs
+. float ones
1962 let rec set (_N
, _A
, _B
) y sy
=
1963 let sum = summa
1.0 _N _A _B
in
1964 let dy = float (y - sy
) in
1968 then state.ghyll
<- noghyll
1971 let s = scroll n _N _A _B
in
1972 let y1 = y1 +. ((s *. dy) /. sum) in
1973 gotoy_and_clear_text (truncate
y1);
1974 state.ghyll
<- gf (n+1) y1;
1978 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1980 gf 0 (float state.y)
1983 match conf.ghyllscroll
with
1985 gotoy_and_clear_text y
1987 if state.ghyll
== noghyll
1988 then set nab
y state.y
1989 else state.ghyll
(Some
y)
1992 let gotopage n top =
1993 let y, h = getpageyh n in
1994 let y = y + (truncate
(top *. float h)) in
1998 let gotopage1 n top =
1999 let y = getpagey n in
2004 let invalidate s f =
2009 match state.geomcmds
with
2010 | ps
, [] when String.length ps
= 0 ->
2012 state.geomcmds
<- s, [];
2015 state.geomcmds
<- ps
, [s, f];
2017 | ps
, (s'
, _) :: rest
when s'
= s ->
2018 state.geomcmds
<- ps
, ((s, f) :: rest
);
2021 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2025 Hashtbl.iter
(fun _ opaque
->
2026 wcmd "freepage %s" opaque
;
2028 Hashtbl.clear
state.pagemap
;
2032 if not
(Queue.is_empty
state.tilelru
)
2034 Queue.iter
(fun (k
, p
, s) ->
2035 wcmd "freetile %s" p
;
2036 state.memused
<- state.memused
- s;
2037 Hashtbl.remove
state.tilemap k
;
2039 state.uioh#infochanged Memused
;
2040 Queue.clear
state.tilelru
;
2046 let h = truncate
(float h*.conf.zoom
) in
2047 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2051 let opendoc path password
=
2053 state.password
<- password
;
2054 state.gen
<- state.gen
+ 1;
2055 state.docinfo
<- [];
2058 setaalevel
conf.aalevel
;
2060 if String.length
state.origin
= 0
2064 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2065 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2066 invalidate "reqlayout"
2068 wcmd "reqlayout %d %d %d %s\000"
2069 conf.angle
(FMTE.to_int conf.fitmodel
)
2070 (stateh state.winh
) state.nameddest
2075 state.anchor <- getanchor ();
2076 opendoc state.path
state.password
;
2080 let c = c *. conf.colorscale
in
2084 let scalecolor2 (r, g, b) =
2085 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2088 let docolumns = function
2090 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2091 let rec loop pageno pdimno pdim
y ph pdims
=
2092 if pageno = state.pagecount
2095 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2097 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2098 pdimno+1, pdim
, rest
2102 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2104 (if conf.presentation
2105 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2106 else (if pageno = 0 then 0 else conf.interpagespace
)
2109 a.(pageno) <- (pdimno, x, y, pdim
);
2110 loop (pageno+1) pdimno pdim
(y + h) h pdims
2112 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2113 conf.columns
<- Csingle
a;
2115 | Cmulti
((columns
, coverA
, coverB
), _) ->
2116 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2117 let rec loop pageno pdimno pdim
x y rowh pdims
=
2118 let rec fixrow m
= if m
= pageno then () else
2119 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2122 let y = y + (rowh
- h) / 2 in
2123 a.(m
) <- (pdimno, x, y, pdim
);
2127 if pageno = state.pagecount
2128 then fixrow (((pageno - 1) / columns
) * columns
)
2130 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2132 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2133 pdimno+1, pdim
, rest
2138 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2140 let x = (wadjsb state.winw
- w) / 2 in
2142 if conf.presentation
then calcips h else conf.interpagespace
in
2143 x, y + ips + rowh
, h
2146 if (pageno - coverA
) mod columns
= 0
2148 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2150 if conf.presentation
2152 let ips = calcips h in
2153 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2155 y + (if pageno = 0 then 0 else conf.interpagespace
)
2159 else x, y, max rowh
h
2163 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2166 if pageno = columns
&& conf.presentation
2168 let ips = calcips rowh
in
2169 for i
= 0 to pred columns
2171 let (pdimno, x, y, pdim
) = a.(i
) in
2172 a.(i
) <- (pdimno, x, y+ips, pdim
)
2178 fixrow (pageno - columns
);
2183 a.(pageno) <- (pdimno, x, y, pdim
);
2184 let x = x + w + xoff
*2 + conf.interpagespace
in
2185 loop (pageno+1) pdimno pdim
x y rowh' pdims
2187 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2188 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2191 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2192 let rec loop pageno pdimno pdim
y pdims
=
2193 if pageno = state.pagecount
2196 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2198 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2199 pdimno+1, pdim
, rest
2204 let rec loop1 n x y =
2205 if n = c then y else (
2206 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2207 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2210 let y = loop1 0 0 y in
2211 loop (pageno+1) pdimno pdim
y pdims
2213 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2214 conf.columns
<- Csplit
(c, a);
2218 docolumns conf.columns
;
2219 state.maxy
<- calcheight ();
2220 if state.reprf
== noreprf
2222 match state.mode
with
2223 | Birdseye
(_, _, pageno, _, _) ->
2224 let y, h = getpageyh pageno in
2225 let top = (state.winh
- h) / 2 in
2226 gotoy (max
0 (y - top))
2227 | _ -> gotoanchor state.anchor
2231 state.reprf
<- noreprf;
2236 GlDraw.viewport
0 0 w h;
2237 let firsttime = state.geomcmds
== firstgeomcmds in
2238 if not
firsttime && nogeomcmds state.geomcmds
2239 then state.anchor <- getanchor ();
2242 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2245 setfontsize fstate.fontsize
;
2246 GlMat.mode `modelview
;
2247 GlMat.load_identity
();
2249 GlMat.mode `projection
;
2250 GlMat.load_identity
();
2251 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2252 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2253 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2258 else float state.x /. float state.w
2260 invalidate "geometry"
2264 then state.x <- truncate
(relx *. float w);
2266 match conf.columns
with
2268 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2269 | Csplit
(c, _) -> w * c
2271 wcmd "geometry %d %d %d"
2272 w (stateh h) (FMTE.to_int conf.fitmodel
)
2277 let len = String.length
state.text in
2280 match state.mode
with
2281 | Textentry
_ | View
| LinkNav
_ ->
2282 let h, _, _ = state.uioh#scrollpw
in
2288 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2289 (x+.w, float (state.winh
- hscrollh))
2292 let w = float (wadjsb state.winw
- 1) in
2293 if state.progress
>= 0.0 && state.progress
< 1.0
2295 GlDraw.color
(0.3, 0.3, 0.3);
2296 let w1 = w *. state.progress
in
2298 GlDraw.color
(0.0, 0.0, 0.0);
2302 GlDraw.color
(0.0, 0.0, 0.0);
2306 GlDraw.color
(1.0, 1.0, 1.0);
2307 drawstring fstate.fontsize
2308 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2311 match state.mode
with
2312 | Textentry
((prefix
, text, _, _, _, _), _) ->
2316 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2318 Printf.sprintf
"%s%s_" prefix
text
2327 if not
(istextentry state.mode
) && state.uioh#eformsgs
2329 let s1 = "(press 'e' to review error messasges)" in
2330 if String.length
s > 0 then s ^
" " ^
s1 else s1
2335 if String.length
s > 0
2340 let len = Queue.length
state.tilelru
in
2342 match state.throttle
with
2345 then preloadlayout state.y
2347 | Some
(layout, _, _) ->
2351 if state.memused
<= conf.memlimit
2356 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2357 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2358 let (_, pw, ph
, _) = getpagedim n in
2361 && colorspace
= conf.colorspace
2362 && angle
= conf.angle
2366 let x = col*conf.tilew
2367 and y = row*conf.tileh
in
2368 tilevisible (Lazy.force_val
layout) n x y
2370 then Queue.push lruitem
state.tilelru
2373 wcmd "freetile %s" p
;
2374 state.memused
<- state.memused
- s;
2375 state.uioh#infochanged Memused
;
2376 Hashtbl.remove
state.tilemap k
;
2384 let logcurrently = function
2385 | Idle
-> dolog
"Idle"
2386 | Loading
(l, gen
) ->
2387 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2388 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2390 "Tiling %d[%d,%d] page=%s cs=%s angle"
2391 l.pageno col row pageopaque
2392 (CSTE.to_string colorspace
)
2394 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2395 angle gen
conf.angle
state.gen
2397 conf.tilew
conf.tileh
2404 let r = Str.regexp
" " in
2405 fun s -> Str.bounded_split
r s 2;
2408 let onpagerect pageno f =
2410 match conf.columns
with
2411 | Cmulti
(_, b) -> b
2413 | Csplit
(_, b) -> b
2415 if pageno >= 0 && pageno < Array.length
b
2417 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2418 let r = getpdimrect
pdimno in
2419 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2422 let gotopagexy1 pageno x y =
2423 onpagerect pageno (fun w h ->
2425 let _,w1,_,leftx
= getpagedim pageno in
2426 let wh = state.winh
- hscrollh () in
2427 let sw = float w1 /. w in
2429 let x = leftx
+ state.x + truncate
x in
2431 if x < 0 || x >= wadjsb state.winw
2435 let py, h = getpageyh pageno in
2436 let pdy = truncate
(top *. float h) in
2437 let y'
= py + pdy in
2438 let dy = y'
- state.y in
2440 if x != state.x || not
(dy > 0 && dy < wh)
2442 if conf.presentation
2444 if abs
(py - y'
) > wh
2451 if state.x != sx || state.y != sy
2456 let ww = wadjsb state.winw
in
2458 and qy
= pdy / wh in
2460 and y = py + qy
* wh in
2461 let x = if -x + ww > w1 then -(w1-ww) else x
2462 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2464 if conf.presentation
2466 if abs
(py - y'
) > wh
2476 gotoy_and_clear_text y;
2478 else gotoy_and_clear_text state.y;
2482 let gotopagexy pageno x y =
2483 match state.mode
with
2484 | Birdseye
_ -> gotopage pageno 0.0
2485 | _ -> gotopagexy1 pageno x y
2489 (* dolog "%S" cmds; *)
2490 let cl = splitatspace cmds
in
2492 try Scanf.sscanf
s fmt
f
2494 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2499 state.uioh#infochanged Pdim
;
2502 | "clearrects" :: [] ->
2503 state.rects
<- state.rects1
;
2504 G.postRedisplay "clearrects";
2506 | "continue" :: args :: [] ->
2507 let n = scan args "%u" (fun n -> n) in
2508 state.pagecount
<- n;
2509 begin match state.currently
with
2511 state.currently
<- Idle
;
2512 state.outlines
<- Array.of_list
(List.rev
l)
2516 let cur, cmds
= state.geomcmds
in
2517 if String.length
cur = 0
2518 then failwith
"umpossible";
2520 begin match List.rev cmds
with
2522 state.geomcmds
<- "", [];
2526 state.geomcmds
<- s, List.rev rest
;
2528 if conf.maxwait
= None
&& not
!wtmode
2529 then G.postRedisplay "continue";
2531 | "title" :: args :: [] ->
2534 | "msg" :: args :: [] ->
2537 | "vmsg" :: args :: [] ->
2539 then showtext ' '
args
2541 | "emsg" :: args :: [] ->
2542 Buffer.add_string
state.errmsgs
args;
2543 state.newerrmsgs
<- true;
2544 G.postRedisplay "error message"
2546 | "progress" :: args :: [] ->
2547 let progress, text =
2550 f, String.sub
args pos
(String.length
args - pos
))
2553 state.progress <- progress;
2554 G.postRedisplay "progress"
2556 | "firstmatch" :: args :: [] ->
2557 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2558 scan args "%u %d %f %f %f %f %f %f %f %f"
2559 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2560 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2562 let y = (getpagey pageno) + truncate
y0 in
2565 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2567 | "match" :: args :: [] ->
2568 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2569 scan args "%u %d %f %f %f %f %f %f %f %f"
2570 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2571 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2574 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2576 | "page" :: args :: [] ->
2577 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2578 begin match state.currently
with
2579 | Loading
(l, gen
) ->
2580 vlog "page %d took %f sec" l.pageno t
;
2581 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2582 begin match state.throttle
with
2584 let preloadedpages =
2586 then preloadlayout state.y
2591 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2592 IntSet.empty
preloadedpages
2595 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2596 if not
(IntSet.mem
pageno set)
2598 wcmd "freepage %s" opaque
;
2604 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2607 state.currently
<- Idle
;
2610 tilepage l.pageno pageopaque state.layout;
2612 load preloadedpages;
2613 if pagevisible state.layout l.pageno
2614 && layoutready state.layout
2615 then G.postRedisplay "page";
2618 | Some
(layout, _, _) ->
2619 state.currently
<- Idle
;
2620 tilepage l.pageno pageopaque layout;
2625 dolog
"Inconsistent loading state";
2626 logcurrently state.currently
;
2630 | "tile" :: args :: [] ->
2631 let (x, y, opaque
, size
, t
) =
2632 scan args "%u %u %s %u %f"
2633 (fun x y p size t
-> (x, y, p
, size
, t
))
2635 begin match state.currently
with
2636 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2637 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2640 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2642 wcmd "freetile %s" opaque
;
2643 state.currently
<- Idle
;
2647 puttileopaque l col row gen cs angle opaque size t
;
2648 state.memused
<- state.memused
+ size
;
2649 state.uioh#infochanged Memused
;
2651 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2652 opaque
, size
) state.tilelru
;
2655 match state.throttle
with
2656 | None
-> state.layout
2657 | Some
(layout, _, _) -> layout
2660 state.currently
<- Idle
;
2662 && conf.colorspace
= cs
2663 && conf.angle
= angle
2664 && tilevisible layout l.pageno x y
2665 then conttiling l.pageno pageopaque;
2667 begin match state.throttle
with
2669 preload state.layout;
2671 && conf.colorspace
= cs
2672 && conf.angle
= angle
2673 && tilevisible state.layout l.pageno x y
2674 && (not
!wtmode || layoutready state.layout)
2675 then G.postRedisplay "tile nothrottle";
2677 | Some
(layout, y, _) ->
2678 let ready = layoutready layout in
2682 state.layout <- layout;
2683 state.throttle
<- None
;
2684 G.postRedisplay "throttle";
2691 dolog
"Inconsistent tiling state";
2692 logcurrently state.currently
;
2696 | "pdim" :: args :: [] ->
2697 let (n, w, h, _) as pdim
=
2698 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2701 match conf.fitmodel
, conf.columns
with
2702 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2705 state.uioh#infochanged Pdim
;
2706 state.pdims
<- pdim :: state.pdims
2708 | "o" :: args :: [] ->
2709 let (l, n, t
, h, pos
) =
2710 scan args "%u %u %d %u %n"
2711 (fun l n t
h pos
-> l, n, t
, h, pos
)
2713 let s = String.sub
args pos
(String.length
args - pos
) in
2714 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2715 begin match state.currently
with
2716 | Outlining outlines
->
2717 state.currently
<- Outlining
(outline :: outlines
)
2719 state.currently
<- Outlining
[outline]
2721 dolog
"invalid outlining state";
2722 logcurrently currently
2725 | "a" :: args :: [] ->
2727 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2729 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2731 | "info" :: args :: [] ->
2732 state.docinfo
<- (1, args) :: state.docinfo
2734 | "infoend" :: [] ->
2735 state.uioh#infochanged Docinfo
;
2736 state.docinfo
<- List.rev
state.docinfo
2739 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2744 let action = function
2745 | HCprev
-> cbget cb ~
-1
2746 | HCnext
-> cbget cb
1
2747 | HCfirst
-> cbget cb ~
-(cb
.rc)
2748 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2749 and cancel
() = cb
.rc <- rc
2753 let search pattern forward
=
2754 match conf.columns
with
2756 showtext '
!'
"searching does not work properly in split columns mode"
2758 if String.length pattern
> 0
2761 match state.layout with
2764 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2766 wcmd "search %d %d %d %d,%s\000"
2767 (btod conf.icase
) pn py (btod forward
) pattern
;
2770 let intentry text key =
2772 if key >= 32 && key < 127
2778 let text = addchar text c in
2782 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2786 let linknentry text key =
2788 if key >= 32 && key < 127
2794 let text = addchar text c in
2798 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2803 if String.length
s > 0
2806 let l = String.length
s in
2807 let rec loop pos
n = if pos
= l then n else
2808 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2809 loop (pos
+1) (n*26 + m)
2812 let rec loop n = function
2815 match getopaque l.pageno with
2816 | None
-> loop n rest
2818 let m = getlinkcount opaque
in
2821 let under = getlink opaque
n in
2824 else loop (n-m) rest
2826 loop n state.layout;
2830 let textentry text key =
2831 if key land 0xff00 = 0xff00
2833 else TEcont
(text ^ toutf8
key)
2836 let reqlayout angle fitmodel
=
2837 match state.throttle
with
2839 if nogeomcmds state.geomcmds
2840 then state.anchor <- getanchor ();
2841 conf.angle
<- angle
mod 360;
2844 match state.mode
with
2845 | LinkNav
_ -> state.mode
<- View
2848 conf.fitmodel
<- fitmodel
;
2849 invalidate "reqlayout"
2851 wcmd "reqlayout %d %d %d"
2852 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2857 let settrim trimmargins trimfuzz
=
2858 if nogeomcmds state.geomcmds
2859 then state.anchor <- getanchor ();
2860 conf.trimmargins
<- trimmargins
;
2861 conf.trimfuzz
<- trimfuzz
;
2862 let x0, y0, x1, y1 = trimfuzz
in
2863 invalidate "settrim"
2865 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2870 match state.throttle
with
2872 let zoom = max
0.0001 zoom in
2873 if zoom <> conf.zoom
2875 state.prevzoom
<- conf.zoom;
2877 reshape state.winw
state.winh
;
2878 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2881 | Some
(layout, y, started
) ->
2883 match conf.maxwait
with
2887 let dt = now () -. started
in
2895 let setcolumns mode columns coverA coverB
=
2896 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2900 then showtext '
!'
"split mode doesn't work in bird's eye"
2902 conf.columns
<- Csplit
(-columns
, [||]);
2910 conf.columns
<- Csingle
[||];
2915 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2919 reshape state.winw
state.winh
;
2922 let enterbirdseye () =
2923 let zoom = float conf.thumbw
/. float state.winw
in
2924 let birdseyepageno =
2925 let cy = state.winh
/ 2 in
2929 let rec fold best
= function
2932 let d = cy - (l.pagedispy + l.pagevh/2)
2933 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2934 if abs
d < abs dbest
2941 state.mode
<- Birdseye
(
2942 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2945 conf.presentation
<- false;
2946 conf.interpagespace
<- 10;
2947 conf.hlinks
<- false;
2948 conf.fitmodel
<- FitProportional
;
2950 state.mstate
<- Mnone
;
2951 conf.maxwait
<- None
;
2953 match conf.beyecolumns
with
2956 Cmulti
((c, 0, 0), [||])
2957 | None
-> Csingle
[||]
2959 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2962 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2967 reshape state.winw
state.winh
;
2970 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2972 conf.zoom <- c.zoom;
2973 conf.presentation
<- c.presentation
;
2974 conf.interpagespace
<- c.interpagespace
;
2975 conf.maxwait
<- c.maxwait
;
2976 conf.hlinks
<- c.hlinks
;
2977 conf.fitmodel
<- c.fitmodel
;
2978 conf.beyecolumns
<- (
2979 match conf.columns
with
2980 | Cmulti
((c, _, _), _) -> Some
c
2982 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2985 match c.columns
with
2986 | Cmulti
(c, _) -> Cmulti
(c, [||])
2987 | Csingle
_ -> Csingle
[||]
2988 | Csplit
(c, _) -> Csplit
(c, [||])
2993 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2996 reshape state.winw
state.winh
;
2997 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3000 let togglebirdseye () =
3001 match state.mode
with
3002 | Birdseye vals
-> leavebirdseye vals
true
3003 | View
-> enterbirdseye ()
3007 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3008 let pageno = max
0 (pageno - incr
) in
3009 let rec loop = function
3010 | [] -> gotopage1 pageno 0
3011 | l :: _ when l.pageno = pageno ->
3012 if l.pagedispy >= 0 && l.pagey = 0
3013 then G.postRedisplay "upbirdseye"
3014 else gotopage1 pageno 0
3015 | _ :: rest
-> loop rest
3018 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3021 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3022 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3023 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3024 let rec loop = function
3026 let y, h = getpageyh pageno in
3027 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3029 | l :: _ when l.pageno = pageno ->
3030 if l.pagevh != l.pageh
3031 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3032 else G.postRedisplay "downbirdseye"
3033 | _ :: rest
-> loop rest
3038 let optentry mode
_ key =
3039 let btos b = if b then "on" else "off" in
3040 if key >= 32 && key < 127
3042 let c = Char.chr
key in
3046 try conf.scrollstep
<- int_of_string
s with exc
->
3047 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3049 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3054 conf.autoscrollstep
<- int_of_string
s;
3055 if state.autoscroll
<> None
3056 then state.autoscroll
<- Some
conf.autoscrollstep
3058 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3060 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3065 let n, a, b = multicolumns_of_string s in
3066 setcolumns mode
n a b;
3068 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3070 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3075 let zoom = float (int_of_string
s) /. 100.0 in
3078 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3080 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3085 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3087 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3088 begin match mode
with
3090 leavebirdseye beye
false;
3095 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3097 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3102 Some
(int_of_string
s)
3104 state.text <- Printf.sprintf
"bad integer `%s': %s"
3108 | Some angle
-> reqlayout angle
conf.fitmodel
3111 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3114 conf.icase
<- not
conf.icase
;
3115 TEdone
("case insensitive search " ^
(btos conf.icase
))
3118 conf.preload <- not
conf.preload;
3120 TEdone
("preload " ^
(btos conf.preload))
3123 conf.verbose
<- not
conf.verbose
;
3124 TEdone
("verbose " ^
(btos conf.verbose
))
3127 conf.debug
<- not
conf.debug
;
3128 TEdone
("debug " ^
(btos conf.debug
))
3131 conf.maxhfit
<- not
conf.maxhfit
;
3132 state.maxy
<- calcheight ();
3133 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3136 conf.crophack
<- not
conf.crophack
;
3137 TEdone
("crophack " ^
btos conf.crophack
)
3141 match conf.maxwait
with
3143 conf.maxwait
<- Some infinity
;
3144 "always wait for page to complete"
3146 conf.maxwait
<- None
;
3147 "show placeholder if page is not ready"
3152 conf.underinfo
<- not
conf.underinfo
;
3153 TEdone
("underinfo " ^
btos conf.underinfo
)
3156 conf.savebmarks
<- not
conf.savebmarks
;
3157 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3163 match state.layout with
3168 conf.interpagespace
<- int_of_string
s;
3169 docolumns conf.columns
;
3170 state.maxy
<- calcheight ();
3171 let y = getpagey pageno in
3174 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3176 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3180 match conf.fitmodel
with
3181 | FitProportional
-> FitWidth
3182 | _ -> FitProportional
3184 reqlayout conf.angle
fm;
3185 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3188 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3189 TEdone
("trim margins " ^
btos conf.trimmargins
)
3192 conf.invert
<- not
conf.invert
;
3193 TEdone
("invert colors " ^
btos conf.invert
)
3197 cbput state.hists
.sel
s;
3200 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3201 textentry, ondone, true)
3205 then conf.pax
<- Some
(ref (0.0, 0, 0))
3206 else conf.pax
<- None
;
3207 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3210 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3216 class type lvsource
= object
3217 method getitemcount
: int
3218 method getitem
: int -> (string * int)
3219 method hasaction
: int -> bool
3228 method getactive
: int
3229 method getfirst
: int
3230 method getqsearch
: string
3231 method setqsearch
: string -> unit
3235 class virtual lvsourcebase
= object
3236 val mutable m_active
= 0
3237 val mutable m_first
= 0
3238 val mutable m_qsearch
= ""
3239 val mutable m_pan
= 0
3240 method getactive
= m_active
3241 method getfirst
= m_first
3242 method getqsearch
= m_qsearch
3243 method getpan
= m_pan
3244 method setqsearch
s = m_qsearch
<- s
3247 let withoutlastutf8 s =
3248 let len = String.length
s in
3256 let b = Char.code
s.[pos
] in
3257 if b land 0b11000000 = 0b11000000
3262 if Char.code
s.[len-1] land 0x80 = 0
3266 String.sub
s 0 first;
3269 let textentrykeyboard
3270 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3272 if key >= 0xffb0 && key <= 0xffb9
3273 then key - 0xffb0 + 48 else key
3276 state.mode
<- Textentry
(te
, onleave
);
3279 G.postRedisplay "textentrykeyboard enttext";
3281 let histaction cmd
=
3284 | Some
(action, _) ->
3285 state.mode
<- Textentry
(
3286 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3288 G.postRedisplay "textentry histaction"
3291 | 0xff08 -> (* backspace *)
3292 let s = withoutlastutf8 text in
3293 let len = String.length
s in
3294 if cancelonempty
&& len = 0
3297 G.postRedisplay "textentrykeyboard after cancel";
3300 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3303 | 0xff0d | 0xff8d -> (* (kp) enter *)
3306 G.postRedisplay "textentrykeyboard after confirm"
3308 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3309 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3310 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3311 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3313 | 0xff1b -> (* escape*)
3314 if String.length
text = 0
3316 begin match opthist
with
3318 | Some
(_, onhistcancel
) -> onhistcancel
()
3322 G.postRedisplay "textentrykeyboard after cancel2"
3325 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3328 | 0xff9f | 0xffff -> () (* delete *)
3331 && key land 0xff00 != 0xff00 (* keyboard *)
3332 && key land 0xfe00 != 0xfe00 (* xkb *)
3333 && key land 0xfd00 != 0xfd00 (* 3270 *)
3335 begin match onkey
text key with
3339 G.postRedisplay "textentrykeyboard after confirm2";
3342 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3346 G.postRedisplay "textentrykeyboard after cancel3"
3349 state.mode
<- Textentry
(te
, onleave
);
3350 G.postRedisplay "textentrykeyboard switch";
3354 vlog "unhandled key %s" (Wsi.keyname
key)
3357 let firstof first active
=
3358 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3359 then max
0 (active
- (fstate.maxrows
/2))
3363 let calcfirst first active
=
3366 let rows = active
- first in
3367 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3371 let scrollph y maxy
=
3372 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3373 let sh = float state.winh
/. sh in
3374 let sh = max
sh (float conf.scrollh
) in
3376 let percent = float y /. float maxy
in
3377 let position = (float state.winh
-. sh) *. percent in
3380 if position +. sh > float state.winh
3381 then float state.winh
-. sh
3387 let coe s = (s :> uioh
);;
3389 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3391 val m_pan
= source#getpan
3392 val m_first
= source#getfirst
3393 val m_active
= source#getactive
3394 val m_qsearch
= source#getqsearch
3395 val m_prev_uioh
= state.uioh
3397 method private elemunder
y =
3398 let n = y / (fstate.fontsize
+1) in
3399 if m_first
+ n < source#getitemcount
3401 if source#hasaction
(m_first
+ n)
3402 then Some
(m_first
+ n)
3409 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3410 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3411 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3412 GlDraw.color
(1., 1., 1.);
3413 Gl.enable `texture_2d
;
3414 let fs = fstate.fontsize
in
3416 let ww = fstate.wwidth
in
3417 let tabw = 30.0*.ww in
3418 let itemcount = source#getitemcount
in
3420 if (row - m_first
) > fstate.maxrows
3423 if row >= 0 && row < itemcount
3425 let (s, level
) = source#getitem
row in
3426 let y = (row - m_first
) * nfs in
3427 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3430 Gl.disable `texture_2d
;
3431 GlDraw.polygon_mode `both `line
;
3432 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3433 GlDraw.color
(1., 1., 1.) ~
alpha;
3434 GlDraw.rect (1., float (y + 1))
3435 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3436 GlDraw.polygon_mode `both `fill
;
3437 GlDraw.color
(1., 1., 1.);
3438 Gl.enable `texture_2d
;
3441 let drawtabularstring s =
3442 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3445 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3448 let len = String.length
s - tabpos - 1 in
3449 let s1 = String.sub
s 0 tabpos
3450 and s2
= String.sub
s (tabpos + 1) len in
3451 let nx = drawstr x s1 in
3453 let x = x +. (max
tabw sw) in
3460 let _ = drawtabularstring s in
3467 Gl.disable `texture_2d
;
3469 method updownlevel incr
=
3470 let len = source#getitemcount
in
3472 if m_active
>= 0 && m_active
< len
3473 then snd
(source#getitem m_active
)
3477 if i
= len then i
-1 else if i
= -1 then 0 else
3478 let _, l = source#getitem i
in
3479 if l != curlevel then i
else flow (i
+incr
)
3481 let active = flow m_active
in
3482 let first = calcfirst m_first
active in
3483 G.postRedisplay "outline updownlevel";
3484 {< m_active
= active; m_first
= first >}
3486 method private key1
key mask
=
3487 let set1 active first qsearch
=
3488 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3490 let search active pattern incr
=
3491 let active = if active = -1 then m_first
else active in
3494 if n >= 0 && n < source#getitemcount
3496 let s, _ = source#getitem
n in
3498 (try ignore
(Str.search_forward
re s 0); true
3499 with Not_found
-> false)
3501 else loop (n + incr
)
3508 let re = Str.regexp_case_fold pattern
in
3514 let itemcount = source#getitemcount
in
3515 let find start incr
=
3517 if i
= -1 || i
= itemcount
3520 if source#hasaction i
3522 else find (i
+ incr
)
3527 let set active first =
3528 let first = bound first 0 (itemcount - fstate.maxrows
) in
3530 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3533 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3535 let incr1 = if incr
> 0 then 1 else -1 in
3536 if isvisible m_first m_active
3539 let next = m_active
+ incr
in
3541 if next < 0 || next >= itemcount
3543 else find next incr1
3545 if abs
(m_active
- next) > fstate.maxrows
3551 let first = m_first
+ incr
in
3552 let first = bound first 0 (itemcount - fstate.maxrows
) in
3554 let next = m_active
+ incr
in
3555 let next = bound next 0 (itemcount - 1) in
3562 if isvisible first next
3569 let first = min
next m_first
in
3571 if abs
(next - first) > fstate.maxrows
3577 let first = m_first
+ incr
in
3578 let first = bound first 0 (itemcount - 1) in
3580 let next = m_active
+ incr
in
3581 let next = bound next 0 (itemcount - 1) in
3582 let next = find next incr1 in
3584 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3586 let active = if m_active
= -1 then next else m_active
in
3591 if isvisible first active
3597 G.postRedisplay "listview navigate";
3601 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3602 let incr = if key = 0x72 then -1 else 1 in
3604 match search (m_active
+ incr) m_qsearch
incr with
3606 state.text <- m_qsearch ^
" [not found]";
3609 state.text <- m_qsearch
;
3610 active, firstof m_first
active
3612 G.postRedisplay "listview ctrl-r/s";
3613 set1 active first m_qsearch
;
3615 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3616 if m_active
>= 0 && m_active
< source#getitemcount
3618 let s, _ = source#getitem m_active
in
3623 | 0xff08 -> (* backspace *)
3624 if String.length m_qsearch
= 0
3627 let qsearch = withoutlastutf8 m_qsearch
in
3628 let len = String.length
qsearch in
3632 G.postRedisplay "listview empty qsearch";
3633 set1 m_active m_first
"";
3637 match search m_active
qsearch ~
-1 with
3639 state.text <- qsearch ^
" [not found]";
3642 state.text <- qsearch;
3643 active, firstof m_first
active
3645 G.postRedisplay "listview backspace qsearch";
3646 set1 active first qsearch
3649 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3650 let pattern = m_qsearch ^ toutf8
key in
3652 match search m_active
pattern 1 with
3654 state.text <- pattern ^
" [not found]";
3657 state.text <- pattern;
3658 active, firstof m_first
active
3660 G.postRedisplay "listview qsearch add";
3661 set1 active first pattern;
3663 | 0xff1b -> (* escape *)
3665 if String.length m_qsearch
= 0
3667 G.postRedisplay "list view escape";
3670 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3672 | None
-> m_prev_uioh
3677 G.postRedisplay "list view kill qsearch";
3678 source#setqsearch
"";
3679 coe {< m_qsearch
= "" >}
3682 | 0xff0d | 0xff8d -> (* (kp) enter *)
3684 let self = {< m_qsearch
= "" >} in
3685 source#setqsearch
"";
3687 G.postRedisplay "listview enter";
3688 if m_active
>= 0 && m_active
< source#getitemcount
3690 source#exit
(coe self) false m_active m_first m_pan
"";
3693 source#exit
(coe self) true m_active m_first m_pan
"";
3696 begin match opt with
3697 | None
-> m_prev_uioh
3701 | 0xff9f | 0xffff -> (* (kp) delete *)
3704 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3705 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3706 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3707 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3709 | 0xff53 | 0xff98 -> (* (kp) right *)
3711 G.postRedisplay "listview right";
3712 coe {< m_pan
= m_pan
- 1 >}
3714 | 0xff51 | 0xff96 -> (* (kp) left *)
3716 G.postRedisplay "listview left";
3717 coe {< m_pan
= m_pan
+ 1 >}
3719 | 0xff50 | 0xff95 -> (* (kp) home *)
3720 let active = find 0 1 in
3721 G.postRedisplay "listview home";
3724 | 0xff57 | 0xff9c -> (* (kp) end *)
3725 let first = max
0 (itemcount - fstate.maxrows
) in
3726 let active = find (itemcount - 1) ~
-1 in
3727 G.postRedisplay "listview end";
3730 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3734 dolog
"listview unknown key %#x" key; coe self
3736 method key key mask
=
3737 match state.mode
with
3738 | Textentry te
-> textentrykeyboard key mask te
; coe self
3739 | _ -> self#key1
key mask
3741 method button button down
x y _ =
3744 | 1 when x > state.winw
- conf.scrollbw
->
3745 G.postRedisplay "listview scroll";
3748 let _, position, sh = self#
scrollph in
3749 if y > truncate
position && y < truncate
(position +. sh)
3751 state.mstate
<- Mscrolly
;
3755 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3756 let first = truncate
(s *. float source#getitemcount
) in
3757 let first = min source#getitemcount
first in
3758 Some
(coe {< m_first
= first; m_active
= first >})
3760 state.mstate
<- Mnone
;
3763 | 1 when not down
->
3764 begin match self#elemunder
y with
3766 G.postRedisplay "listview click";
3768 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3772 | n when (n == 4 || n == 5) && not down
->
3773 let len = source#getitemcount
in
3775 if n = 5 && m_first
+ fstate.maxrows
>= len
3779 let first = m_first
+ (if n == 4 then -1 else 1) in
3780 bound first 0 (len - 1)
3782 G.postRedisplay "listview wheel";
3783 Some
(coe {< m_first
= first >})
3784 | n when (n = 6 || n = 7) && not down
->
3785 let inc = m_first
+ (if n = 7 then -1 else 1) in
3786 G.postRedisplay "listview hwheel";
3787 Some
(coe {< m_pan
= m_pan
+ inc >})
3792 | None
-> m_prev_uioh
3796 match state.mstate
with
3798 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3799 let first = truncate
(s *. float source#getitemcount
) in
3800 let first = min source#getitemcount
first in
3801 G.postRedisplay "listview motion";
3802 coe {< m_first
= first; m_active
= first >}
3805 method pmotion
x y =
3806 if x < state.winw
- conf.scrollbw
3809 match self#elemunder
y with
3810 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3811 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3815 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3820 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3824 method infochanged
_ = ()
3826 method scrollpw
= (0, 0.0, 0.0)
3828 let nfs = fstate.fontsize
+ 1 in
3829 let y = m_first
* nfs in
3830 let itemcount = source#getitemcount
in
3831 let maxi = max
0 (itemcount - fstate.maxrows
) in
3832 let maxy = maxi * nfs in
3833 let p, h = scrollph y maxy in
3836 method modehash
= modehash
3837 method eformsgs
= false
3840 class outlinelistview ~source
=
3843 ~source
:(source
:> lvsource
)
3845 ~modehash
:(findkeyhash conf "outline")
3848 method key key mask
=
3849 let calcfirst first active =
3852 let rows = active - first in
3854 if String.length
state.text = 0
3856 else fstate.maxrows - 2
3858 if rows > maxrows then active - maxrows else first
3862 let active = m_active
+ incr in
3863 let active = bound active 0 (source#getitemcount
- 1) in
3864 let first = calcfirst m_first
active in
3865 G.postRedisplay "outline navigate";
3866 coe {< m_active
= active; m_first
= first >}
3868 let ctrl = Wsi.withctrl mask
in
3870 | 110 when ctrl -> (* ctrl-n *)
3871 source#narrow m_qsearch
;
3872 G.postRedisplay "outline ctrl-n";
3873 coe {< m_first
= 0; m_active
= 0 >}
3875 | 117 when ctrl -> (* ctrl-u *)
3877 G.postRedisplay "outline ctrl-u";
3879 coe {< m_first
= 0; m_active
= 0 >}
3881 | 108 when ctrl -> (* ctrl-l *)
3882 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3883 G.postRedisplay "outline ctrl-l";
3884 coe {< m_first
= first >}
3886 | 0xff9f | 0xffff -> (* (kp) delete *)
3887 source#remove m_active
;
3888 G.postRedisplay "outline delete";
3889 let active = max
0 (m_active
-1) in
3890 coe {< m_first
= firstof m_first
active;
3891 m_active
= active >}
3893 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3894 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3895 | 0xff55 | 0xff9a -> (* (kp) prior *)
3896 navigate ~
-(fstate.maxrows)
3897 | 0xff56 | 0xff9b -> (* (kp) next *)
3898 navigate fstate.maxrows
3900 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3904 G.postRedisplay "outline ctrl right";
3905 {< m_pan
= m_pan
+ 1 >}
3907 else self#updownlevel
1
3911 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3915 G.postRedisplay "outline ctrl left";
3916 {< m_pan
= m_pan
- 1 >}
3918 else self#updownlevel ~
-1
3922 | 0xff50 | 0xff95 -> (* (kp) home *)
3923 G.postRedisplay "outline home";
3924 coe {< m_first
= 0; m_active
= 0 >}
3926 | 0xff57 | 0xff9c -> (* (kp) end *)
3927 let active = source#getitemcount
- 1 in
3928 let first = max
0 (active - fstate.maxrows) in
3929 G.postRedisplay "outline end";
3930 coe {< m_active
= active; m_first
= first >}
3932 | _ -> super#
key key mask
3935 let outlinesource usebookmarks
=
3938 inherit lvsourcebase
3939 val mutable m_items
= empty
3940 val mutable m_orig_items
= empty
3941 val mutable m_prev_items
= empty
3942 val mutable m_narrow_pattern
= ""
3943 val mutable m_hadremovals
= false
3945 method getitemcount
=
3946 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3949 if n == Array.length m_items
&& m_hadremovals
3951 ("[Confirm removal]", 0)
3953 let s, n, _ = m_items
.(n) in
3956 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3957 ignore
(uioh
, first, qsearch);
3958 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3960 if String.length m_narrow_pattern
= 0
3966 if not
confrimremoval
3968 let _, _, anchor = m_items
.(active) in
3969 gotoghyll (getanchory anchor);
3973 state.bookmarks
<- Array.to_list m_items
;
3974 m_orig_items
<- m_items
;
3977 else m_items
<- items;
3981 method hasaction
_ = true
3984 if Array.length m_items
!= Array.length m_orig_items
3985 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3988 method narrow
pattern =
3989 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3993 let rec loop accu n =
3996 m_narrow_pattern
<- pattern;
3997 m_items
<- Array.of_list
accu
4000 let (s, _, _) as o = m_items
.(n) in
4002 if (try ignore
(Str.search_forward
re s 0); true
4003 with Not_found
-> false)
4009 loop [] (Array.length m_items
- 1)
4014 then Array.of_list
state.bookmarks
4017 m_items
<- m_orig_items
4022 if m >= 0 && m < Array.length m_items
4024 m_hadremovals
<- true;
4025 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4026 let n = if n >= m then n+1 else n in
4031 method reset
anchor items =
4032 m_hadremovals
<- false;
4033 if m_orig_items
== empty || m_prev_items
!= items
4035 m_orig_items
<- items;
4036 if String.length m_narrow_pattern
= 0
4037 then m_items
<- items;
4039 m_prev_items
<- items;
4040 let rely = getanchory anchor in
4042 let rec loop n best bestd
=
4043 if n = Array.length m_items
4046 let (_, _, anchor) = m_items
.(n) in
4047 let orely = getanchory anchor in
4048 let d = abs
(orely - rely) in
4051 else loop (n+1) best bestd
4056 m_first
<- firstof m_first
active
4060 let enterselector usebookmarks
=
4061 let source = outlinesource usebookmarks
in
4065 then Array.of_list
state.bookmarks
4068 if Array.length
outlines = 0
4070 showtext ' ' errmsg
;
4073 state.text <- source#greetmsg
;
4074 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4075 let anchor = getanchor () in
4076 source#reset
anchor outlines;
4077 state.uioh
<- coe (new outlinelistview ~
source);
4078 G.postRedisplay "enter selector";
4082 let enteroutlinemode =
4083 let f = enterselector false in
4084 fun ()-> f "Document has no outline";
4087 let enterbookmarkmode =
4088 let f = enterselector true in
4089 fun () -> f "Document has no bookmarks (yet)";
4092 let color_of_string s =
4093 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4094 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4098 let color_to_string (r, g, b) =
4099 let r = truncate
(r *. 256.0)
4100 and g = truncate
(g *. 256.0)
4101 and b = truncate
(b *. 256.0) in
4102 Printf.sprintf
"%d/%d/%d" r g b
4105 let irect_of_string s =
4106 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4109 let irect_to_string (x0,y0,x1,y1) =
4110 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4113 let makecheckers () =
4114 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4116 converted by Issac Trotts. July 25, 2002 *)
4117 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4118 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4119 let id = GlTex.gen_texture
() in
4120 GlTex.bind_texture `texture_2d
id;
4121 GlPix.store
(`unpack_alignment
1);
4122 GlTex.image2d
image;
4123 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4124 [ `mag_filter `nearest
; `min_filter `nearest
];
4128 let setcheckers enabled
=
4129 match state.texid
with
4131 if enabled
then state.texid
<- Some
(makecheckers ())
4136 GlTex.delete_texture texid
;
4137 state.texid
<- None
;
4141 let int_of_string_with_suffix s =
4142 let l = String.length
s in
4146 let suffix = Char.lowercase
s.[l-1] in
4148 | 'k'
-> String.sub
s 0 (l-1), 10
4149 | '
m'
-> String.sub
s 0 (l-1), 20
4150 | '
g'
-> String.sub
s 0 (l-1), 30
4154 let n = int_of_string
s1 in
4155 let m = n lsl shift
in
4157 then raise
(Failure
"value too large")
4161 let string_with_suffix_of_int n =
4166 if n land ((1 lsl 30) - 1) = 0
4169 if n land ((1 lsl 20) - 1) = 0
4172 if n land ((1 lsl 10) - 1) = 0
4179 let h = n mod 1000 in
4182 then string_of_int
h ^
s
4184 let s = Printf.sprintf
"_%03d%s" h s in
4191 let defghyllscroll = (40, 8, 32);;
4192 let ghyllscroll_of_string s =
4193 let (n, a, b) as nab
=
4196 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4198 if n <= a || n <= b || a >= b
4199 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4203 let ghyllscroll_to_string ((n, a, b) as nab
) =
4204 if nab
= defghyllscroll
4206 else Printf.sprintf
"%d,%d,%d" n a b;
4209 let describe_location () =
4210 let fn = page_of_y state.y in
4211 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4212 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4216 else (100. *. (float state.y /. float maxy))
4220 Printf.sprintf
"page %d of %d [%.2f%%]"
4221 (fn+1) state.pagecount
percent
4224 "pages %d-%d of %d [%.2f%%]"
4225 (fn+1) (ln+1) state.pagecount
percent
4228 let setpresentationmode v
=
4229 let n = page_of_y state.y in
4230 state.anchor <- (n, 0.0, 1.0);
4231 conf.presentation
<- v
;
4232 if conf.fitmodel
= FitPage
4233 then reqlayout conf.angle
conf.fitmodel
;
4238 let btos b = if b then "\xe2\x88\x9a" else "" in
4239 let showextended = ref false in
4240 let leave mode
= function
4241 | Confirm
-> state.mode
<- mode
4242 | Cancel
-> state.mode
<- mode
in
4245 val mutable m_first_time
= true
4246 val mutable m_l
= []
4247 val mutable m_a
= [||]
4248 val mutable m_prev_uioh
= nouioh
4249 val mutable m_prev_mode
= View
4251 inherit lvsourcebase
4253 method reset prev_mode prev_uioh
=
4254 m_a
<- Array.of_list
(List.rev m_l
);
4256 m_prev_mode
<- prev_mode
;
4257 m_prev_uioh
<- prev_uioh
;
4261 if n >= Array.length m_a
4265 | _, _, _, Action
_ -> m_active
<- n
4269 m_first_time
<- false;
4272 method int name get
set =
4274 (name, `
int get
, 1, Action
(
4277 try set (int_of_string
s)
4279 state.text <- Printf.sprintf
"bad integer `%s': %s"
4283 let te = name ^
": ", "", None
, intentry, ondone, true in
4284 state.mode
<- Textentry
(te, leave m_prev_mode
);
4288 method int_with_suffix
name get
set =
4290 (name, `intws get
, 1, Action
(
4293 try set (int_of_string_with_suffix s)
4295 state.text <- Printf.sprintf
"bad integer `%s': %s"
4300 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4302 state.mode
<- Textentry
(te, leave m_prev_mode
);
4306 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4308 (name, `
bool (btos, get
), offset
, Action
(
4315 method color
name get
set =
4317 (name, `color get
, 1, Action
(
4319 let invalid = (nan
, nan
, nan
) in
4322 try color_of_string s
4324 state.text <- Printf.sprintf
"bad color `%s': %s"
4331 let te = name ^
": ", "", None
, textentry, ondone, true in
4332 state.text <- color_to_string (get
());
4333 state.mode
<- Textentry
(te, leave m_prev_mode
);
4337 method string name get
set =
4339 (name, `
string get
, 1, Action
(
4341 let ondone s = set s in
4342 let te = name ^
": ", "", None
, textentry, ondone, true in
4343 state.mode
<- Textentry
(te, leave m_prev_mode
);
4347 method colorspace
name get
set =
4349 (name, `
string get
, 1, Action
(
4353 inherit lvsourcebase
4356 m_active
<- CSTE.to_int conf.colorspace
;
4359 method getitemcount
=
4360 Array.length
CSTE.names
4363 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4364 ignore
(uioh
, first, pan
, qsearch);
4365 if not cancel
then set active;
4367 method hasaction
_ = true
4371 let modehash = findkeyhash conf "info" in
4372 coe (new listview ~
source ~trusted
:true ~
modehash)
4375 method paxmark
name get
set =
4377 (name, `
string get
, 1, Action
(
4381 inherit lvsourcebase
4384 m_active
<- MTE.to_int conf.paxmark
;
4387 method getitemcount
= Array.length
MTE.names
4388 method getitem
n = (MTE.names.(n), 0)
4389 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4390 ignore
(uioh
, first, pan
, qsearch);
4391 if not cancel
then set active;
4393 method hasaction
_ = true
4397 let modehash = findkeyhash conf "info" in
4398 coe (new listview ~
source ~trusted
:true ~
modehash)
4401 method fitmodel
name get
set =
4403 (name, `
string get
, 1, Action
(
4407 inherit lvsourcebase
4410 m_active
<- FMTE.to_int conf.fitmodel
;
4413 method getitemcount
= Array.length
FMTE.names
4414 method getitem
n = (FMTE.names.(n), 0)
4415 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4416 ignore
(uioh
, first, pan
, qsearch);
4417 if not cancel
then set active;
4419 method hasaction
_ = true
4423 let modehash = findkeyhash conf "info" in
4424 coe (new listview ~
source ~trusted
:true ~
modehash)
4427 method caption
s offset
=
4428 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4430 method caption2
s f offset
=
4431 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4433 method getitemcount
= Array.length m_a
4436 let tostr = function
4437 | `
int f -> string_of_int
(f ())
4438 | `intws
f -> string_with_suffix_of_int (f ())
4440 | `color
f -> color_to_string (f ())
4441 | `
bool (btos, f) -> btos (f ())
4444 let name, t
, offset
, _ = m_a
.(n) in
4445 ((let s = tostr t
in
4446 if String.length
s > 0
4447 then Printf.sprintf
"%s\t%s" name s
4451 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4455 m_qsearch
<- qsearch;
4457 match m_a
.(active) with
4458 | _, _, _, Action
f -> f uioh
4470 method hasaction
n =
4472 | _, _, _, Action
_ -> true
4476 let rec fillsrc prevmode prevuioh
=
4477 let sep () = src#caption
"" 0 in
4478 let colorp name get
set =
4480 (fun () -> color_to_string (get
()))
4483 let c = color_of_string v in
4486 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4489 let oldmode = state.mode
in
4490 let birdseye = isbirdseye state.mode
in
4492 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4494 src#
bool "presentation mode"
4495 (fun () -> conf.presentation
)
4496 (fun v -> setpresentationmode v);
4498 src#
bool "ignore case in searches"
4499 (fun () -> conf.icase
)
4500 (fun v -> conf.icase
<- v);
4503 (fun () -> conf.preload)
4504 (fun v -> conf.preload <- v);
4506 src#
bool "highlight links"
4507 (fun () -> conf.hlinks
)
4508 (fun v -> conf.hlinks
<- v);
4510 src#
bool "under info"
4511 (fun () -> conf.underinfo
)
4512 (fun v -> conf.underinfo
<- v);
4514 src#
bool "persistent bookmarks"
4515 (fun () -> conf.savebmarks
)
4516 (fun v -> conf.savebmarks
<- v);
4518 src#fitmodel
"fit model"
4519 (fun () -> FMTE.to_string conf.fitmodel
)
4520 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4522 src#
bool "trim margins"
4523 (fun () -> conf.trimmargins
)
4524 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4526 src#
bool "persistent location"
4527 (fun () -> conf.jumpback
)
4528 (fun v -> conf.jumpback
<- v);
4531 src#
int "inter-page space"
4532 (fun () -> conf.interpagespace
)
4534 conf.interpagespace
<- n;
4535 docolumns conf.columns
;
4537 match state.layout with
4542 state.maxy <- calcheight ();
4543 let y = getpagey pageno in
4548 (fun () -> conf.pagebias
)
4549 (fun v -> conf.pagebias
<- v);
4551 src#
int "scroll step"
4552 (fun () -> conf.scrollstep
)
4553 (fun n -> conf.scrollstep
<- n);
4555 src#
int "horizontal scroll step"
4556 (fun () -> conf.hscrollstep
)
4557 (fun v -> conf.hscrollstep
<- v);
4559 src#
int "auto scroll step"
4561 match state.autoscroll
with
4563 | _ -> conf.autoscrollstep
)
4565 if state.autoscroll
<> None
4566 then state.autoscroll
<- Some
n;
4567 conf.autoscrollstep
<- n);
4570 (fun () -> truncate
(conf.zoom *. 100.))
4571 (fun v -> setzoom ((float v) /. 100.));
4574 (fun () -> conf.angle
)
4575 (fun v -> reqlayout v conf.fitmodel
);
4577 src#
int "scroll bar width"
4578 (fun () -> conf.scrollbw
)
4581 reshape state.winw
state.winh
;
4584 src#
int "scroll handle height"
4585 (fun () -> conf.scrollh
)
4586 (fun v -> conf.scrollh
<- v;);
4588 src#
int "thumbnail width"
4589 (fun () -> conf.thumbw
)
4591 conf.thumbw
<- min
4096 v;
4594 leavebirdseye beye
false;
4599 let mode = state.mode in
4600 src#
string "columns"
4602 match conf.columns
with
4604 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4605 | Csplit
(count
, _) -> "-" ^ string_of_int count
4608 let n, a, b = multicolumns_of_string v in
4609 setcolumns mode n a b);
4612 src#caption
"Pixmap cache" 0;
4613 src#int_with_suffix
"size (advisory)"
4614 (fun () -> conf.memlimit
)
4615 (fun v -> conf.memlimit
<- v);
4618 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4619 (string_with_suffix_of_int state.memused
)
4620 (Hashtbl.length
state.tilemap
)) 1;
4623 src#caption
"Layout" 0;
4624 src#caption2
"Dimension"
4626 Printf.sprintf
"%dx%d (virtual %dx%d)"
4627 state.winw
state.winh
4632 src#caption2
"Position" (fun () ->
4633 Printf.sprintf
"%dx%d" state.x state.y
4636 src#caption2
"Position" (fun () -> describe_location ()) 1
4640 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4641 "Save these parameters as global defaults at exit"
4642 (fun () -> conf.bedefault
)
4643 (fun v -> conf.bedefault
<- v)
4647 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4648 src#
bool ~offset
:0 ~
btos "Extended parameters"
4649 (fun () -> !showextended)
4650 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4654 (fun () -> conf.checkers
)
4655 (fun v -> conf.checkers
<- v; setcheckers v);
4656 src#
bool "update cursor"
4657 (fun () -> conf.updatecurs
)
4658 (fun v -> conf.updatecurs
<- v);
4660 (fun () -> conf.verbose
)
4661 (fun v -> conf.verbose
<- v);
4662 src#
bool "invert colors"
4663 (fun () -> conf.invert
)
4664 (fun v -> conf.invert
<- v);
4666 (fun () -> conf.maxhfit
)
4667 (fun v -> conf.maxhfit
<- v);
4668 src#
bool "redirect stderr"
4669 (fun () -> conf.redirectstderr)
4670 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4672 (fun () -> conf.pax
!= None
)
4675 then conf.pax
<- Some
(ref (now (), 0, 0))
4676 else conf.pax
<- None
);
4677 src#
string "uri launcher"
4678 (fun () -> conf.urilauncher
)
4679 (fun v -> conf.urilauncher
<- v);
4680 src#
string "path launcher"
4681 (fun () -> conf.pathlauncher
)
4682 (fun v -> conf.pathlauncher
<- v);
4683 src#
string "tile size"
4684 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4687 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4688 conf.tilew
<- max
64 w;
4689 conf.tileh
<- max
64 h;
4692 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4695 src#
int "texture count"
4696 (fun () -> conf.texcount
)
4699 then conf.texcount
<- v
4700 else showtext '
!'
" Failed to set texture count please retry later"
4702 src#
int "slice height"
4703 (fun () -> conf.sliceheight
)
4705 conf.sliceheight
<- v;
4706 wcmd "sliceh %d" conf.sliceheight
;
4708 src#
int "anti-aliasing level"
4709 (fun () -> conf.aalevel
)
4711 conf.aalevel
<- bound v 0 8;
4712 state.anchor <- getanchor ();
4713 opendoc state.path
state.password
;
4715 src#
string "page scroll scaling factor"
4716 (fun () -> string_of_float
conf.pgscale)
4719 let s = float_of_string
v in
4722 state.text <- Printf.sprintf
4723 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4726 src#
int "ui font size"
4727 (fun () -> fstate.fontsize
)
4728 (fun v -> setfontsize (bound v 5 100));
4729 src#
int "hint font size"
4730 (fun () -> conf.hfsize
)
4731 (fun v -> conf.hfsize
<- bound v 5 100);
4732 colorp "background color"
4733 (fun () -> conf.bgcolor
)
4734 (fun v -> conf.bgcolor
<- v);
4735 src#
bool "crop hack"
4736 (fun () -> conf.crophack
)
4737 (fun v -> conf.crophack
<- v);
4738 src#
string "trim fuzz"
4739 (fun () -> irect_to_string conf.trimfuzz
)
4742 conf.trimfuzz
<- irect_of_string v;
4744 then settrim true conf.trimfuzz
;
4746 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4748 src#
string "throttle"
4750 match conf.maxwait
with
4751 | None
-> "show place holder if page is not ready"
4754 then "wait for page to fully render"
4756 "wait " ^ string_of_float
time
4757 ^
" seconds before showing placeholder"
4761 let f = float_of_string
v in
4763 then conf.maxwait
<- None
4764 else conf.maxwait
<- Some
f
4766 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4768 src#
string "ghyll scroll"
4770 match conf.ghyllscroll
with
4772 | Some nab
-> ghyllscroll_to_string nab
4777 if String.length
v = 0
4779 else Some
(ghyllscroll_of_string v)
4781 conf.ghyllscroll
<- gs
4783 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4785 src#
string "selection command"
4786 (fun () -> conf.selcmd
)
4787 (fun v -> conf.selcmd
<- v);
4788 src#
string "synctex command"
4789 (fun () -> conf.stcmd
)
4790 (fun v -> conf.stcmd
<- v);
4791 src#
string "pax command"
4792 (fun () -> conf.paxcmd
)
4793 (fun v -> conf.paxcmd
<- v);
4794 src#colorspace
"color space"
4795 (fun () -> CSTE.to_string conf.colorspace
)
4797 conf.colorspace
<- CSTE.of_int v;
4801 src#paxmark
"pax mark method"
4802 (fun () -> MTE.to_string conf.paxmark
)
4803 (fun v -> conf.paxmark
<- MTE.of_int v);
4807 (fun () -> conf.usepbo
)
4808 (fun v -> conf.usepbo
<- v);
4809 src#
bool "mouse wheel scrolls pages"
4810 (fun () -> conf.wheelbypage
)
4811 (fun v -> conf.wheelbypage
<- v);
4812 src#
bool "open remote links in a new instance"
4813 (fun () -> conf.riani
)
4814 (fun v -> conf.riani
<- v);
4818 src#caption
"Document" 0;
4819 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4820 src#caption2
"Pages"
4821 (fun () -> string_of_int
state.pagecount
) 1;
4822 src#caption2
"Dimensions"
4823 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4827 src#caption
"Trimmed margins" 0;
4828 src#caption2
"Dimensions"
4829 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4833 src#caption
"OpenGL" 0;
4834 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4835 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4838 src#caption
"Location" 0;
4839 if String.length
state.origin
> 0
4840 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4841 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4843 src#reset prevmode prevuioh
;
4847 let prevmode = state.mode
4848 and prevuioh
= state.uioh in
4849 fillsrc prevmode prevuioh
;
4850 let source = (src :> lvsource
) in
4851 let modehash = findkeyhash conf "info" in
4852 state.uioh <- coe (object (self)
4853 inherit listview ~
source ~trusted
:true ~
modehash as super
4854 val mutable m_prevmemused
= 0
4855 method infochanged
= function
4857 if m_prevmemused
!= state.memused
4859 m_prevmemused
<- state.memused
;
4860 G.postRedisplay "memusedchanged";
4862 | Pdim
-> G.postRedisplay "pdimchanged"
4863 | Docinfo
-> fillsrc prevmode prevuioh
4865 method key key mask
=
4866 if not
(Wsi.withctrl mask
)
4869 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4870 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4871 | _ -> super#
key key mask
4872 else super#
key key mask
4874 G.postRedisplay "info";
4880 inherit lvsourcebase
4881 method getitemcount
= Array.length
state.help
4883 let s, l, _ = state.help
.(n) in
4886 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4890 m_qsearch
<- qsearch;
4891 match state.help
.(active) with
4892 | _, _, Action
f -> Some
(f uioh)
4902 method hasaction
n =
4903 match state.help
.(n) with
4904 | _, _, Action
_ -> true
4911 let modehash = findkeyhash conf "help" in
4912 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4913 G.postRedisplay "help";
4918 let re = Str.regexp
"[\r\n]" in
4920 inherit lvsourcebase
4921 val mutable m_items
= [||]
4923 method getitemcount
= 1 + Array.length m_items
4928 else m_items
.(n-1), 0
4930 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4935 then Buffer.clear
state.errmsgs
;
4936 m_qsearch
<- qsearch;
4943 method hasaction
n =
4947 state.newerrmsgs
<- false;
4948 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4949 m_items
<- Array.of_list
l
4957 let source = (msgsource :> lvsource
) in
4958 let modehash = findkeyhash conf "listview" in
4959 state.uioh <- coe (object
4960 inherit listview ~
source ~trusted
:false ~
modehash as super
4963 then msgsource#reset
;
4966 G.postRedisplay "msgs";
4969 let quickbookmark ?title
() =
4970 match state.layout with
4976 let sec = Unix.gettimeofday
() in
4977 let tm = Unix.localtime
sec in
4978 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4982 (tm.Unix.tm_year
+ 1900)
4985 | Some
title -> title
4987 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4990 let setautoscrollspeed step goingdown
=
4991 let incr = max
1 ((abs step
) / 2) in
4992 let incr = if goingdown
then incr else -incr in
4993 let astep = step
+ incr in
4994 state.autoscroll
<- Some
astep;
4997 let gotounder = function
4998 | Ulinkgoto
(pageno, top) ->
5002 gotopage1 pageno top;
5008 | Uremote
(filename
, pageno) ->
5010 if String.length filename
> 0
5012 if Filename.is_relative filename
5014 let dir = Filename.dirname
state.path in
5016 if Filename.is_implicit
dir
5017 then Filename.concat
(Sys.getcwd
()) dir
5020 Filename.concat
dir filename
5025 if Sys.file_exists
path
5029 if String.length
path > 0
5033 let command = !selfexec ^
" " ^
path in
5034 try popen command []
5037 "failed to execute `%s': %s\n" command (exntos exn
);
5040 let anchor = getanchor () in
5041 let ranchor = state.path, state.password
, anchor, state.origin
in
5043 state.anchor <- (pageno, 0.0, 0.0);
5044 state.ranchors
<- ranchor :: state.ranchors
;
5047 else showtext '
!'
("Could not find " ^ filename
)
5049 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5053 match conf.columns
with
5055 | _ -> state.x != 0 || conf.zoom > 1.0
5058 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5060 let existsinrow pageno (columns
, coverA
, coverB
) p =
5061 let last = ((pageno - coverA
) mod columns
) + columns
in
5062 let rec any = function
5065 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5069 then (if l.pageno = last then false else any rest
)
5077 match state.layout with
5079 let pageno = page_of_y state.y in
5080 gotoghyll (getpagey (pageno+1))
5082 match conf.columns
with
5084 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5086 let y = clamp (pgscale state.winh
) in
5089 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5090 gotoghyll (getpagey pageno)
5091 | Cmulti
((c, _, _) as cl, _) ->
5092 if conf.presentation
5093 && (existsinrow l.pageno cl
5094 (fun l -> l.pageh
> l.pagey + l.pagevh))
5096 let y = clamp (pgscale state.winh
) in
5099 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5100 gotoghyll (getpagey pageno)
5102 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5104 let pagey, pageh
= getpageyh l.pageno in
5105 let pagey = pagey + pageh
* l.pagecol
in
5106 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5107 gotoghyll (pagey + pageh
+ ips)
5111 match state.layout with
5113 let pageno = page_of_y state.y in
5114 gotoghyll (getpagey (pageno-1))
5116 match conf.columns
with
5118 if conf.presentation
&& l.pagey != 0
5120 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5122 let pageno = max
0 (l.pageno-1) in
5123 gotoghyll (getpagey pageno)
5124 | Cmulti
((c, _, coverB
) as cl, _) ->
5125 if conf.presentation
&&
5126 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5128 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5131 if l.pageno = state.pagecount
- coverB
5135 let pageno = max
0 (l.pageno-decr) in
5136 gotoghyll (getpagey pageno)
5144 let pageno = max
0 (l.pageno-1) in
5145 let pagey, pageh
= getpageyh pageno in
5148 let pagey, pageh
= getpageyh l.pageno in
5149 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5154 let viewkeyboard key mask
=
5156 let mode = state.mode in
5157 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5160 G.postRedisplay "view:enttext"
5162 let ctrl = Wsi.withctrl mask
in
5164 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5170 | 0xff63 -> (* insert *)
5171 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5173 state.mode <- LinkNav
(Ltgendir
0);
5176 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5178 | 0xff1b | 113 -> (* escape / q *)
5179 begin match state.mstate
with
5181 state.mstate
<- Mnone
;
5182 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5183 G.postRedisplay "kill zoom rect";
5185 begin match state.mode with
5188 G.postRedisplay "esc leave linknav"
5190 match state.ranchors
with
5192 | (path, password
, anchor, origin
) :: rest
->
5193 state.ranchors
<- rest
;
5194 state.anchor <- anchor;
5195 state.origin
<- origin
;
5196 opendoc path password
5200 | 0xff08 -> (* backspace *)
5201 gotoghyll (getnav ~
-1)
5209 G.postRedisplay "dehighlight";
5211 | 47 | 63 -> (* / ? *)
5212 let ondone isforw
s =
5213 cbput state.hists
.pat
s;
5214 state.searchpattern
<- s;
5217 let s = String.create
1 in
5218 s.[0] <- Char.chr
key;
5219 enttext (s, "", Some
(onhist state.hists
.pat
),
5220 textentry, ondone (key = 47), true)
5222 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5223 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5224 setzoom (conf.zoom +. incr)
5226 | 43 | 0xffab -> (* + *)
5229 try int_of_string
s with exc
->
5230 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5236 state.text <- "page bias is now " ^ string_of_int
n;
5239 enttext ("page bias: ", "", None
, intentry, ondone, true)
5241 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5242 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5243 setzoom (max
0.01 (conf.zoom -. decr))
5245 | 45 | 0xffad -> (* - *)
5246 let ondone msg
= state.text <- msg
in
5248 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5249 optentry state.mode, ondone, true
5252 | 48 when ctrl -> (* ctrl-0 *)
5260 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5262 match conf.columns
with
5263 | Csingle
_ | Cmulti
_ -> 1
5264 | Csplit
(n, _) -> n
5266 let h = state.winh
-
5267 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5269 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5270 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5273 | 51 when ctrl -> (* ctrl-3 *)
5275 match conf.fitmodel
with
5276 | FitWidth
-> FitProportional
5277 | FitProportional
-> FitPage
5278 | FitPage
-> FitWidth
5280 state.text <- "fit model: " ^
FMTE.to_string fm;
5281 reqlayout conf.angle
fm
5283 | 0xffc6 -> (* f9 *)
5286 | 57 when ctrl -> (* ctrl-9 *)
5289 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5290 when not
ctrl -> (* 0..9 *)
5293 try int_of_string
s with exc
->
5294 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5300 cbput state.hists
.pag
(string_of_int
n);
5301 gotopage1 (n + conf.pagebias
- 1) 0;
5304 let pageentry text key =
5305 match Char.unsafe_chr
key with
5306 | '
g'
-> TEdone
text
5307 | _ -> intentry text key
5309 let text = "x" in text.[0] <- Char.chr
key;
5310 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5313 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5314 reshape state.winw
state.winh
;
5317 conf.hlinks
<- not
conf.hlinks
;
5318 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5319 G.postRedisplay "toggle highlightlinks";
5322 state.glinks
<- true;
5323 let mode = state.mode in
5324 state.mode <- Textentry
(
5325 (":", "", None
, linknentry, linkndone gotounder, false),
5327 state.glinks
<- false;
5331 G.postRedisplay "view:linkent(F)"
5334 state.glinks
<- true;
5335 let mode = state.mode in
5336 state.mode <- Textentry
(
5338 ":", "", None
, linknentry, linkndone (fun under ->
5339 selstring (undertext under);
5343 state.glinks
<- false;
5347 G.postRedisplay "view:linkent"
5350 begin match state.autoscroll
with
5352 conf.autoscrollstep
<- step
;
5353 state.autoscroll
<- None
5355 if conf.autoscrollstep
= 0
5356 then state.autoscroll
<- Some
1
5357 else state.autoscroll
<- Some
conf.autoscrollstep
5360 | 112 when ctrl -> (* ctrl-p *)
5364 setpresentationmode (not
conf.presentation
);
5365 showtext ' '
("presentation mode " ^
5366 if conf.presentation
then "on" else "off");
5369 if List.mem
Wsi.Fullscreen
state.winstate
5370 then Wsi.reshape conf.cwinw
conf.cwinh
5371 else Wsi.fullscreen
()
5373 | 112 | 78 -> (* p|N *)
5374 search state.searchpattern
false
5376 | 110 | 0xffc0 -> (* n|F3 *)
5377 search state.searchpattern
true
5380 begin match state.layout with
5383 gotoghyll (getpagey l.pageno)
5389 | 0xff9f | 0xffff -> (* delete *)
5393 showtext ' '
(describe_location ());
5396 begin match state.layout with
5399 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5404 enterbookmarkmode ()
5406 | 104 | 0xffbe -> (* h|F1 *)
5412 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5417 match state.layout with
5419 if String.length
s > 0
5421 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5424 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5428 showtext ' '
"Quick bookmark added";
5431 begin match state.layout with
5433 let rect = getpdimrect
l.pagedimno
in
5437 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5438 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5440 (truncate
(rect.(1) -. rect.(0)),
5441 truncate
(rect.(3) -. rect.(0)))
5443 let w = truncate
((float w)*.conf.zoom)
5444 and h = truncate
((float h)*.conf.zoom) in
5447 state.anchor <- getanchor ();
5448 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5450 G.postRedisplay "z";
5455 | 120 -> state.roam
()
5456 | 60 | 62 -> (* < > *)
5457 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5459 | 91 | 93 -> (* [ ] *)
5461 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5463 G.postRedisplay "brightness";
5465 | 99 when state.mode = View
-> (* [alt-]c *)
5470 let m = (wadjsb state.winw
- state.w) / 2 in
5472 gotoy_and_clear_text state.y
5476 match state.prevcolumns
with
5477 | None
-> (1, 0, 0), 1.0
5478 | Some
(columns
, z
) ->
5481 | Csplit
(c, _) -> -c, 0, 0
5482 | Cmulti
((c, a, b), _) -> c, a, b
5483 | Csingle
_ -> 1, 0, 0
5487 setcolumns View
c a b;
5490 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5491 setzoom state.prevzoom
5493 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5494 begin match state.autoscroll
with
5496 begin match state.mode with
5497 | Birdseye beye
-> upbirdseye 1 beye
5500 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5502 if not
(Wsi.withshift mask
) && conf.presentation
5504 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5508 setautoscrollspeed n false
5511 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5512 begin match state.autoscroll
with
5514 begin match state.mode with
5515 | Birdseye beye
-> downbirdseye 1 beye
5518 then gotoy_and_clear_text (clamp (state.winh
/2))
5520 if not
(Wsi.withshift mask
) && conf.presentation
5522 else gotoy_and_clear_text (clamp conf.scrollstep
)
5526 setautoscrollspeed n true
5529 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5530 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5536 else conf.hscrollstep
5538 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5539 state.x <- panbound (state.x + dx);
5540 gotoy_and_clear_text state.y
5543 G.postRedisplay "left/right"
5546 | 0xff55 | 0xff9a -> (* (kp) prior *)
5550 match state.layout with
5552 | l :: _ -> state.y - l.pagey
5554 clamp (pgscale (-state.winh
))
5558 | 0xff56 | 0xff9b -> (* (kp) next *)
5562 match List.rev
state.layout with
5564 | l :: _ -> getpagey l.pageno
5566 clamp (pgscale state.winh
)
5570 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5572 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5573 gotoghyll (clamp state.maxy)
5576 when Wsi.withalt mask
-> (* alt-(kp) right *)
5577 gotoghyll (getnav 1)
5579 when Wsi.withalt mask
-> (* alt-(kp) left *)
5580 gotoghyll (getnav ~
-1)
5585 | 118 when conf.debug
-> (* v *)
5588 match getopaque l.pageno with
5591 let x0, y0, x1, y1 = pagebbox opaque
in
5592 let a,b = float x0, float y0 in
5593 let c,d = float x1, float y0 in
5594 let e,f = float x1, float y1 in
5595 let h,j
= float x0, float y1 in
5596 let rect = (a,b,c,d,e,f,h,j
) in
5598 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5600 G.postRedisplay "v";
5603 vlog "huh? %s" (Wsi.keyname
key)
5606 let linknavkeyboard key mask
linknav =
5607 let getpage pageno =
5608 let rec loop = function
5610 | l :: _ when l.pageno = pageno -> Some
l
5611 | _ :: rest
-> loop rest
5612 in loop state.layout
5614 let doexact (pageno, n) =
5615 match getopaque pageno, getpage pageno with
5616 | Some opaque
, Some
l ->
5617 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5619 let under = getlink opaque
n in
5620 G.postRedisplay "link gotounder";
5626 | 0xff50 -> (* home *)
5627 Some
(findlink opaque LDfirst
), -1
5629 | 0xff57 -> (* end *)
5630 Some
(findlink opaque LDlast
), 1
5632 | 0xff51 -> (* left *)
5633 Some
(findlink opaque
(LDleft
n)), -1
5635 | 0xff53 -> (* right *)
5636 Some
(findlink opaque
(LDright
n)), 1
5638 | 0xff52 -> (* up *)
5639 Some
(findlink opaque
(LDup
n)), -1
5641 | 0xff54 -> (* down *)
5642 Some
(findlink opaque
(LDdown
n)), 1
5647 begin match findpwl
l.pageno dir with
5651 state.mode <- LinkNav
(Ltgendir
dir);
5652 let y, h = getpageyh pageno in
5655 then y + h - state.winh
5660 begin match getopaque pageno, getpage pageno with
5661 | Some opaque
, Some
_ ->
5663 let ld = if dir > 0 then LDfirst
else LDlast
in
5666 begin match link with
5668 showlinktype (getlink opaque
m);
5669 state.mode <- LinkNav
(Ltexact
(pageno, m));
5670 G.postRedisplay "linknav jpage";
5677 begin match opt with
5678 | Some Lnotfound
-> pwl l dir;
5679 | Some
(Lfound
m) ->
5683 let _, y0, _, y1 = getlinkrect opaque
m in
5685 then gotopage1 l.pageno y0
5687 let d = fstate.fontsize
+ 1 in
5688 if y1 - l.pagey > l.pagevh - d
5689 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5690 else G.postRedisplay "linknav";
5692 showlinktype (getlink opaque
m);
5693 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5696 | None
-> viewkeyboard key mask
5698 | _ -> viewkeyboard key mask
5703 G.postRedisplay "leave linknav"
5707 | Ltgendir
_ -> viewkeyboard key mask
5708 | Ltexact exact
-> doexact exact
5711 let keyboard key mask
=
5712 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5713 then wcmd "interrupt"
5714 else state.uioh <- state.uioh#
key key mask
5717 let birdseyekeyboard key mask
5718 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5720 match conf.columns
with
5722 | Cmulti
((c, _, _), _) -> c
5723 | Csplit
_ -> failwith
"bird's eye split mode"
5725 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5727 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5728 let y, h = getpageyh pageno in
5729 let top = (state.winh
- h) / 2 in
5730 gotoy (max
0 (y - top))
5731 | 0xff0d (* enter *)
5732 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5733 | 0xff1b -> leavebirdseye beye
true (* escape *)
5734 | 0xff52 -> upbirdseye incr beye
(* up *)
5735 | 0xff54 -> downbirdseye incr beye
(* down *)
5736 | 0xff51 -> upbirdseye 1 beye
(* left *)
5737 | 0xff53 -> downbirdseye 1 beye
(* right *)
5739 | 0xff55 -> (* prior *)
5740 begin match state.layout with
5744 state.mode <- Birdseye
(
5745 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5747 gotopage1 l.pageno 0;
5750 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5752 | [] -> gotoy (clamp (-state.winh
))
5754 state.mode <- Birdseye
(
5755 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5757 gotopage1 l.pageno 0
5760 | [] -> gotoy (clamp (-state.winh
))
5763 | 0xff56 -> (* next *)
5764 begin match List.rev
state.layout with
5766 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5767 begin match layout with
5769 let incr = l.pageh
- l.pagevh in
5774 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5776 G.postRedisplay "birdseye pagedown";
5778 else gotoy (clamp (incr + conf.interpagespace
*2));
5782 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5783 gotopage1 l.pageno 0;
5786 | [] -> gotoy (clamp state.winh
)
5789 | 0xff50 -> (* home *)
5790 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5793 | 0xff57 -> (* end *)
5794 let pageno = state.pagecount
- 1 in
5795 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5796 if not
(pagevisible state.layout pageno)
5799 match List.rev
state.pdims
with
5801 | (_, _, h, _) :: _ -> h
5803 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5804 else G.postRedisplay "birdseye end";
5805 | _ -> viewkeyboard key mask
5810 match state.mode with
5811 | Textentry
_ -> scalecolor 0.4
5813 | View
-> scalecolor 1.0
5814 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5815 if l.pageno = hooverpageno
5818 if l.pageno = pageno
5826 let postdrawpage l linkindexbase
=
5827 match getopaque l.pageno with
5829 if tileready l l.pagex
l.pagey
5831 let x = l.pagedispx - l.pagex
5832 and y = l.pagedispy - l.pagey in
5834 match conf.columns
with
5835 | Csingle
_ | Cmulti
_ ->
5836 (if conf.hlinks
then 1 else 0)
5838 && not
(isbirdseye state.mode) then 2 else 0)
5842 match state.mode with
5843 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5846 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5851 let scrollindicator () =
5852 let sbw, ph
, sh = state.uioh#
scrollph in
5853 let sbh, pw, sw = state.uioh#scrollpw
in
5855 GlDraw.color (0.64, 0.64, 0.64);
5857 (float (state.winw
- sbw), 0.)
5858 (float state.winw
, float state.winh
)
5861 (0., float (state.winh
- sbh))
5862 (float (wadjsb state.winw
- 1), float state.winh
)
5864 GlDraw.color (0.0, 0.0, 0.0);
5867 (float (state.winw
- sbw), ph
)
5868 (float state.winw
, ph
+. sh)
5871 (pw, float (state.winh
- sbh))
5872 (pw +. sw, float state.winh
)
5877 match state.mstate
with
5878 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5881 | Msel
((x0, y0), (x1, y1)) ->
5882 let rec loop = function
5884 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5885 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5886 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5887 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5889 match getopaque l.pageno with
5891 let x0, y0 = pagetranslatepoint l x0 y0 in
5892 let x1, y1 = pagetranslatepoint l x1 y1 in
5893 seltext opaque
(x0, y0, x1, y1);
5901 let showrects rects
=
5903 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5904 GlDraw.polygon_mode `both `fill
;
5905 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5907 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5909 if l.pageno = pageno
5911 let dx = float (l.pagedispx - l.pagex
) in
5912 let dy = float (l.pagedispy - l.pagey) in
5913 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5914 GlDraw.begins `quads
;
5916 GlDraw.vertex2
(x0+.dx, y0+.dy);
5917 GlDraw.vertex2
(x1+.dx, y1+.dy);
5918 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5919 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5930 GlClear.color (scalecolor2 conf.bgcolor
);
5931 GlClear.clear
[`
color];
5932 List.iter
drawpage state.layout;
5934 match state.mode with
5935 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5936 begin match getopaque pageno with
5938 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5945 | None
-> state.rects
5950 let rec postloop linkindexbase
= function
5952 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5953 postloop linkindexbase rest
5957 postloop 0 state.layout;
5959 begin match state.mstate
with
5960 | Mzoomrect
((x0, y0), (x1, y1)) ->
5962 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5963 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5964 GlDraw.rect (float x0, float y0)
5965 (float x1, float y1);
5974 let zoomrect x y x1 y1 =
5977 and y0 = min
y y1 in
5978 gotoy (state.y + y0);
5979 state.anchor <- getanchor ();
5980 let zoom = (float state.w) /. float (x1 - x0) in
5982 match conf.fitmodel
, conf.columns
with
5983 | FitPage
, Csplit
_ ->
5984 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5987 let adjw = wadjsb state.winw
in
5989 then (adjw - state.w) / 2
5992 state.x <- (state.x + margin) - x0;
5994 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5995 state.mstate
<- Mnone
;
5999 let winw = wadjsb state.winw - 1 in
6000 let s = float x /. float winw in
6001 let destx = truncate
(float (state.w + winw) *. s) in
6002 state.x <- winw - destx;
6003 gotoy_and_clear_text state.y;
6004 state.mstate
<- Mscrollx
;
6008 let s = float y /. float state.winh
in
6009 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6010 gotoy_and_clear_text desty;
6011 state.mstate
<- Mscrolly
;
6014 let viewmouse button down
x y mask
=
6016 | n when (n == 4 || n == 5) && not down
->
6017 if Wsi.withctrl mask
6019 match state.mstate
with
6020 | Mzoom
(oldn
, i
) ->
6028 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6030 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6032 let zoom = conf.zoom -. incr in
6034 state.mstate
<- Mzoom
(n, 0);
6036 state.mstate
<- Mzoom
(n, i
+1);
6038 else state.mstate
<- Mzoom
(n, 0)
6040 | _ -> state.mstate
<- Mzoom
(n, 0)
6043 match state.autoscroll
with
6044 | Some step
-> setautoscrollspeed step
(n=4)
6046 if conf.wheelbypage
|| conf.presentation
6055 then -conf.scrollstep
6056 else conf.scrollstep
6058 let incr = incr * 2 in
6059 let y = clamp incr in
6060 gotoy_and_clear_text y
6063 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6065 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6066 gotoy_and_clear_text state.y
6068 | 1 when Wsi.withshift mask
->
6069 state.mstate
<- Mnone
;
6072 match unproject x y with
6073 | Some
(pageno, ux
, uy
) ->
6074 let cmd = Printf.sprintf
6076 conf.stcmd
state.path pageno ux uy
6082 | 1 when Wsi.withctrl mask
->
6085 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6086 state.mstate
<- Mpan
(x, y)
6089 state.mstate
<- Mnone
6094 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6096 state.mstate
<- Mzoomrect
(p, p)
6099 match state.mstate
with
6100 | Mzoomrect
((x0, y0), _) ->
6101 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6102 then zoomrect x0 y0 x y
6104 state.mstate
<- Mnone
;
6105 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6106 G.postRedisplay "kill accidental zoom rect";
6109 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6110 state.mstate
<- Mnone
6113 | 1 when x > state.winw - vscrollw () ->
6116 let _, position, sh = state.uioh#
scrollph in
6117 if y > truncate
position && y < truncate
(position +. sh)
6118 then state.mstate
<- Mscrolly
6121 state.mstate
<- Mnone
6123 | 1 when y > state.winh
- hscrollh () ->
6126 let _, position, sw = state.uioh#scrollpw
in
6127 if x > truncate
position && x < truncate
(position +. sw)
6128 then state.mstate
<- Mscrollx
6131 state.mstate
<- Mnone
6134 let dest = if down
then getunder x y else Unone
in
6135 begin match dest with
6139 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6142 | Unone
when down
->
6143 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6144 state.mstate
<- Mpan
(x, y);
6146 | Unone
| Utext
_ ->
6149 if conf.angle
mod 360 = 0
6151 state.mstate
<- Msel
((x, y), (x, y));
6152 G.postRedisplay "mouse select";
6156 match state.mstate
with
6159 | Mzoom
_ | Mscrollx
| Mscrolly
->
6160 state.mstate
<- Mnone
6162 | Mzoomrect
((x0, y0), _) ->
6166 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6167 state.mstate
<- Mnone
6169 | Msel
((x0, y0), (x1, y1)) ->
6170 let rec loop = function
6174 let a0 = l.pagedispy in
6175 let a1 = a0 + l.pagevh in
6176 let b0 = l.pagedispx in
6177 let b1 = b0 + l.pagevw in
6178 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6179 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6183 match getopaque l.pageno with
6186 match Ne.pipe () with
6190 "can not create sel pipe: %s"
6193 let doclose what fd
=
6194 Ne.clo fd
(fun msg
->
6195 dolog
"%s close failed: %s" what msg
)
6198 popen conf.selcmd
[r, 0; w, -1];
6199 copysel
w opaque
true;
6201 G.postRedisplay "copysel";
6203 dolog
"can not execute %S: %s"
6204 conf.selcmd
(exntos exn
);
6212 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6213 state.mstate
<- Mnone
;
6220 let birdseyemouse button down
x y mask
6221 (conf, leftx
, _, hooverpageno
, anchor) =
6224 let rec loop = function
6227 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6228 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6230 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6236 | _ -> viewmouse button down
x y mask
6239 let mouse button down
x y mask
=
6240 state.uioh <- state.uioh#button button down
x y mask
;
6244 state.uioh <- state.uioh#
motion x y
6248 state.uioh <- state.uioh#
pmotion x y;
6254 method key key mask
=
6255 begin match state.mode with
6256 | Textentry
textentry -> textentrykeyboard key mask
textentry
6257 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6258 | View
-> viewkeyboard key mask
6259 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6263 method button button bstate
x y mask
=
6264 begin match state.mode with
6266 | View
-> viewmouse button bstate
x y mask
6267 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6273 begin match state.mode with
6275 | View
| Birdseye
_ | LinkNav
_ ->
6276 match state.mstate
with
6277 | Mzoom
_ | Mnone
-> ()
6282 state.mstate
<- Mpan
(x, y);
6284 then state.x <- panbound (state.x + dx);
6286 gotoy_and_clear_text y
6289 state.mstate
<- Msel
(a, (x, y));
6290 G.postRedisplay "motion select";
6293 let y = min
state.winh
(max
0 y) in
6297 let x = min
state.winw (max
0 x) in
6300 | Mzoomrect
(p0
, _) ->
6301 state.mstate
<- Mzoomrect
(p0
, (x, y));
6302 G.postRedisplay "motion zoomrect";
6306 method pmotion x y =
6307 begin match state.mode with
6308 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6309 let rec loop = function
6311 if hooverpageno
!= -1
6313 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6314 G.postRedisplay "pmotion birdseye no hoover";
6317 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6318 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6320 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6321 G.postRedisplay "pmotion birdseye hoover";
6331 match state.mstate
with
6332 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6339 let past, _, _ = !r in
6341 let delta = now -. past in
6344 else r := (now, x, y)
6348 method infochanged
_ = ()
6351 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6354 then 0.0, float state.winh
6355 else scrollph state.y maxy
6360 let winw = wadjsb state.winw in
6361 let fwinw = float winw in
6363 let sw = fwinw /. float state.w in
6364 let sw = fwinw *. sw in
6365 max
sw (float conf.scrollh
)
6368 let maxx = state.w + winw in
6369 let x = winw - state.x in
6370 let percent = float x /. float maxx in
6371 (fwinw -. sw) *. percent
6373 hscrollh (), position, sw
6377 match state.mode with
6378 | LinkNav
_ -> "links"
6379 | Textentry
_ -> "textentry"
6380 | Birdseye
_ -> "birdseye"
6383 findkeyhash conf modename
6385 method eformsgs
= true
6392 let fontpath = ref "";;
6395 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6398 let l = String.length
s in
6399 let b = Buffer.create
l in
6405 try Sys.getenv
"HOME"
6408 ("Can not determine home directory location: " ^ exntos exn
);
6412 let modifier_of_string = function
6413 | "alt" -> Wsi.altmask
6414 | "shift" -> Wsi.shiftmask
6415 | "ctrl" | "control" -> Wsi.ctrlmask
6416 | "meta" -> Wsi.metamask
6421 let r = Str.regexp
"-" in
6423 let elems = Str.full_split
r s in
6426 let m1 = modifier_of_string s in
6428 then (Wsi.namekey
s, m)
6431 | Str.Delim
s when n land 1 = 0 -> g s
6433 | Str.Delim
_ -> (k
, m)
6435 let rec loop n k
m = function
6438 let k, m = f n k m x in
6444 let keys_of_string =
6445 let r = Str.regexp
"[ \t]" in
6447 let elems = Str.split
r s in
6448 List.map
key_of_string elems
6451 let copykeyhashes c =
6452 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6455 let config_of c attrs
=
6459 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6460 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6461 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6462 | "preload" -> { c with preload = bool_of_string
v }
6463 | "page-bias" -> { c with pagebias
= int_of_string
v }
6464 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6465 | "horizontal-scroll-step" ->
6466 { c with hscrollstep
= max
(int_of_string
v) 1 }
6467 | "auto-scroll-step" ->
6468 { c with autoscrollstep
= max
0 (int_of_string
v) }
6469 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6470 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6473 match String.lowercase
v with
6474 | "true" -> Some infinity
6476 | f -> Some
(float_of_string
f)
6478 { c with maxwait
= mw}
6479 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6480 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6481 | "vertical-margin" ->
6482 { c with interpagespace
= max
0 (int_of_string
v) }
6484 let zoom = float_of_string
v /. 100. in
6485 let zoom = max
zoom 0.0 in
6486 { c with zoom = zoom }
6487 | "presentation" -> { c with presentation
= bool_of_string
v }
6488 | "rotation-angle" -> { c with angle
= int_of_string
v }
6489 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6490 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6491 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6492 | "proportional-display" ->
6495 then FitProportional
6498 { c with fitmodel
= fm }
6499 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6500 | "pixmap-cache-size" ->
6501 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6502 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6503 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6504 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6505 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6506 | "background-color" -> { c with bgcolor
= color_of_string v }
6507 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6508 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6509 | "mupdf-store-size" ->
6510 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6511 | "checkers" -> { c with checkers
= bool_of_string
v }
6512 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6513 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6514 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6515 | "uri-launcher" -> { c with urilauncher
= unent v }
6516 | "path-launcher" -> { c with pathlauncher
= unent v }
6517 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6518 | "invert-colors" -> { c with invert
= bool_of_string
v }
6519 | "brightness" -> { c with colorscale
= float_of_string
v }
6520 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6522 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6524 let (n, _, _) as nab
= multicolumns_of_string v in
6526 then { c with columns
= Csplit
(-n, [||]) }
6527 else { c with columns
= Cmulti
(nab
, [||]) }
6528 | "birds-eye-columns" ->
6529 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6530 | "selection-command" -> { c with selcmd
= unent v }
6531 | "synctex-command" -> { c with stcmd
= unent v }
6532 | "pax-command" -> { c with paxcmd
= unent v }
6533 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6534 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6535 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6536 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6537 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6538 | "horizontal-scrollbar-visible" ->
6541 then c.scrollb
lor scrollbhv
6542 else c.scrollb
land (lnot
scrollbhv)
6544 { c with scrollb
= b }
6545 | "vertical-scrollbar-visible" ->
6548 then c.scrollb
lor scrollbvv
6549 else c.scrollb
land (lnot
scrollbvv)
6551 { c with scrollb
= b }
6552 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6556 then Some
(ref (0.0, 0, 0))
6558 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6561 prerr_endline
("Error processing attribute (`" ^
6562 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6565 let rec fold c = function
6568 let c = apply c k v in
6571 fold { c with keyhashes
= copykeyhashes c } attrs
;
6574 let fromstring f pos
n v d =
6577 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6578 n v pos
(exntos exn
)
6583 let bookmark_of attrs
=
6584 let rec fold title page
rely visy
= function
6585 | ("title", v) :: rest
-> fold v page
rely visy rest
6586 | ("page", v) :: rest
-> fold title v rely visy rest
6587 | ("rely", v) :: rest
-> fold title page
v visy rest
6588 | ("visy", v) :: rest
-> fold title page
rely v rest
6589 | _ :: rest
-> fold title page
rely visy rest
6590 | [] -> title, page
, rely, visy
6592 fold "invalid" "0" "0" "0" attrs
6596 let rec fold path page
rely pan visy
= function
6597 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6598 | ("page", v) :: rest
-> fold path v rely pan visy rest
6599 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6600 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6601 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6602 | _ :: rest
-> fold path page
rely pan visy rest
6603 | [] -> path, page
, rely, pan
, visy
6605 fold "" "0" "0" "0" "0" attrs
6609 let rec fold rs ls
= function
6610 | ("out", v) :: rest
-> fold v ls rest
6611 | ("in", v) :: rest
-> fold rs
v rest
6612 | _ :: rest
-> fold ls rs rest
6618 let setconf dst
src =
6619 dst
.scrollbw
<- src.scrollbw
;
6620 dst
.scrollh
<- src.scrollh
;
6621 dst
.icase
<- src.icase
;
6622 dst
.preload <- src.preload;
6623 dst
.pagebias
<- src.pagebias
;
6624 dst
.verbose
<- src.verbose
;
6625 dst
.scrollstep
<- src.scrollstep
;
6626 dst
.maxhfit
<- src.maxhfit
;
6627 dst
.crophack
<- src.crophack
;
6628 dst
.autoscrollstep
<- src.autoscrollstep
;
6629 dst
.maxwait
<- src.maxwait
;
6630 dst
.hlinks
<- src.hlinks
;
6631 dst
.underinfo
<- src.underinfo
;
6632 dst
.interpagespace
<- src.interpagespace
;
6633 dst
.zoom <- src.zoom;
6634 dst
.presentation
<- src.presentation
;
6635 dst
.angle
<- src.angle
;
6636 dst
.cwinw
<- src.cwinw
;
6637 dst
.cwinh
<- src.cwinh
;
6638 dst
.savebmarks
<- src.savebmarks
;
6639 dst
.memlimit
<- src.memlimit
;
6640 dst
.fitmodel
<- src.fitmodel
;
6641 dst
.texcount
<- src.texcount
;
6642 dst
.sliceheight
<- src.sliceheight
;
6643 dst
.thumbw
<- src.thumbw
;
6644 dst
.jumpback
<- src.jumpback
;
6645 dst
.bgcolor
<- src.bgcolor
;
6646 dst
.tilew
<- src.tilew
;
6647 dst
.tileh
<- src.tileh
;
6648 dst
.mustoresize
<- src.mustoresize
;
6649 dst
.checkers
<- src.checkers
;
6650 dst
.aalevel
<- src.aalevel
;
6651 dst
.trimmargins
<- src.trimmargins
;
6652 dst
.trimfuzz
<- src.trimfuzz
;
6653 dst
.urilauncher
<- src.urilauncher
;
6654 dst
.colorspace
<- src.colorspace
;
6655 dst
.invert
<- src.invert
;
6656 dst
.colorscale
<- src.colorscale
;
6657 dst
.redirectstderr <- src.redirectstderr;
6658 dst
.ghyllscroll
<- src.ghyllscroll
;
6659 dst
.columns
<- src.columns
;
6660 dst
.beyecolumns
<- src.beyecolumns
;
6661 dst
.selcmd
<- src.selcmd
;
6662 dst
.updatecurs
<- src.updatecurs
;
6663 dst
.pathlauncher
<- src.pathlauncher
;
6664 dst
.keyhashes
<- copykeyhashes src;
6665 dst
.hfsize
<- src.hfsize
;
6666 dst
.hscrollstep
<- src.hscrollstep
;
6667 dst
.pgscale <- src.pgscale;
6668 dst
.usepbo
<- src.usepbo
;
6669 dst
.wheelbypage
<- src.wheelbypage
;
6670 dst
.stcmd
<- src.stcmd
;
6671 dst
.paxcmd
<- src.paxcmd
;
6672 dst
.scrollb
<- src.scrollb
;
6673 dst
.riani
<- src.riani
;
6674 dst
.paxmark
<- src.paxmark
;
6678 else Some
((ref (0.0, 0, 0)));
6682 let h = Hashtbl.create
10 in
6683 let dc = { defconf with angle
= defconf.angle
} in
6684 let rec toplevel v t spos
_ =
6686 | Vdata
| Vcdata
| Vend
-> v
6687 | Vopen
("llppconfig", _, closed
) ->
6690 else { v with f = llppconfig
}
6692 error
"unexpected subelement at top level" s spos
6693 | Vclose
_ -> error
"unexpected close at top level" s spos
6695 and llppconfig
v t spos
_ =
6697 | Vdata
| Vcdata
-> v
6698 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6699 | Vopen
("defaults", attrs
, closed
) ->
6700 let c = config_of dc attrs
in
6704 else { v with f = defaults
}
6706 | Vopen
("ui-font", attrs
, closed
) ->
6707 let rec getsize size
= function
6709 | ("size", v) :: rest
->
6711 fromstring int_of_string spos
"size" v fstate.fontsize
in
6713 | l -> getsize size l
6715 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6718 else { v with f = uifont
(Buffer.create
10) }
6720 | Vopen
("doc", attrs
, closed
) ->
6721 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6722 let path = unent pathent
6723 and pageno = fromstring int_of_string spos
"page" spage
0
6724 and rely = fromstring float_of_string spos
"rely" srely
0.0
6725 and pan
= fromstring int_of_string spos
"pan" span
0
6726 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6727 let c = config_of dc attrs
in
6728 let anchor = (pageno, rely, visy
) in
6730 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6731 else { v with f = doc
path pan
anchor c [] }
6734 error
"unexpected subelement in llppconfig" s spos
6736 | Vclose
"llppconfig" -> { v with f = toplevel }
6737 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6739 and defaults
v t spos
_ =
6741 | Vdata
| Vcdata
-> v
6742 | Vend
-> error
"unexpected end of input in defaults" s spos
6743 | Vopen
("keymap", attrs
, closed
) ->
6745 try List.assoc
"mode" attrs
6746 with Not_found
-> "global" in
6751 let h = findkeyhash dc modename in
6752 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6755 { v with f = pkeymap
ret KeyMap.empty }
6757 | Vopen
(_, _, _) ->
6758 error
"unexpected subelement in defaults" s spos
6760 | Vclose
"defaults" ->
6761 { v with f = llppconfig
}
6763 | Vclose
_ -> error
"unexpected close in defaults" s spos
6765 and uifont
b v t spos
epos =
6768 Buffer.add_substring
b s spos
(epos - spos
);
6770 | Vopen
(_, _, _) ->
6771 error
"unexpected subelement in ui-font" s spos
6772 | Vclose
"ui-font" ->
6773 if String.length
!fontpath = 0
6774 then fontpath := Buffer.contents
b;
6775 { v with f = llppconfig
}
6776 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6777 | Vend
-> error
"unexpected end of input in ui-font" s spos
6779 and doc
path pan
anchor c bookmarks
v t spos
_ =
6781 | Vdata
| Vcdata
-> v
6782 | Vend
-> error
"unexpected end of input in doc" s spos
6783 | Vopen
("bookmarks", _, closed
) ->
6786 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6788 | Vopen
("keymap", attrs
, closed
) ->
6790 try List.assoc
"mode" attrs
6791 with Not_found
-> "global"
6797 let h = findkeyhash c modename in
6798 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6799 doc
path pan
anchor c bookmarks
6801 { v with f = pkeymap
ret KeyMap.empty }
6803 | Vopen
(_, _, _) ->
6804 error
"unexpected subelement in doc" s spos
6807 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6808 { v with f = llppconfig
}
6810 | Vclose
_ -> error
"unexpected close in doc" s spos
6812 and pkeymap
ret keymap
v t spos
_ =
6814 | Vdata
| Vcdata
-> v
6815 | Vend
-> error
"unexpected end of input in keymap" s spos
6816 | Vopen
("map", attrs
, closed
) ->
6817 let r, l = map_of attrs
in
6818 let kss = fromstring keys_of_string spos
"in" r [] in
6819 let lss = fromstring keys_of_string spos
"out" l [] in
6823 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6824 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6827 then { v with f = pkeymap
ret keymap }
6830 { v with f = skip
"map" f }
6833 error
"unexpected subelement in keymap" s spos
6835 | Vclose
"keymap" ->
6836 { v with f = ret keymap }
6838 | Vclose
_ -> error
"unexpected close in keymap" s spos
6840 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6842 | Vdata
| Vcdata
-> v
6843 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6844 | Vopen
("item", attrs
, closed
) ->
6845 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6846 let page = fromstring int_of_string spos
"page" spage
0
6847 and rely = fromstring float_of_string spos
"rely" srely
0.0
6848 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6850 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6853 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6856 { v with f = skip
"item" f }
6859 error
"unexpected subelement in bookmarks" s spos
6861 | Vclose
"bookmarks" ->
6862 { v with f = doc
path pan
anchor c bookmarks }
6864 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6866 and skip tag
f v t spos
_ =
6868 | Vdata
| Vcdata
-> v
6870 error
("unexpected end of input in skipped " ^ tag
) s spos
6871 | Vopen
(tag'
, _, closed
) ->
6875 let f'
() = { v with f = skip tag
f } in
6876 { v with f = skip tag'
f'
}
6880 else error
("unexpected close in skipped " ^ tag
) s spos
6883 parse
{ f = toplevel; accu = () } s;
6889 let len = in_channel_length ic
in
6890 let s = String.create
len in
6891 really_input ic
s 0 len;
6894 | Parse_error
(msg
, s, pos
) ->
6895 let subs = subs s pos
in
6896 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6897 failwith
("parse error: " ^
s)
6900 failwith
("config load error: " ^ exntos exn
)
6906 let dir = Filename.concat
home ".config" in
6907 if Sys.is_directory
dir then dir else home
6910 Filename.concat
dir "llpp.conf"
6913 let confpath = ref defconfpath;;
6916 if Sys.file_exists
!confpath
6919 (try Some
(open_in_bin
!confpath)
6922 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6933 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6942 f (Hashtbl.create
0, defconf)
6947 let pc, pb
, px, pa
=
6950 if String.length
state.origin
= 0
6954 Hashtbl.find h (Filename.basename
key)
6955 with Not_found
-> dc, [], 0, emptyanchor
6959 state.bookmarks <- pb
;
6962 then state.anchor <- pa
;
6963 cbput state.hists
.nav pa
;
6969 let add_attrs bb always
dc c =
6972 then Printf.bprintf bb
"\n %s='%b'" s a
6975 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
6978 then Printf.bprintf bb
"\n %s='%d'" s a
6981 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6984 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6987 then Printf.bprintf bb
"\n %s='%f'" s a
6991 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6995 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
6999 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7003 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7009 | Some
(_N
, _A
, _B
) ->
7010 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7020 else string_of_float
f
7022 Printf.bprintf bb
"\n %s='%s'" s v
7027 | Cmulti
((n, a, b), _) when n > 1 ->
7028 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7029 | Csplit
(n, _) when n > 1 ->
7030 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7036 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7041 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7045 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7049 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7051 oi
"width" c.cwinw
dc.cwinw
;
7052 oi
"height" c.cwinh
dc.cwinh
;
7053 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7054 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7055 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7056 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7057 ob "case-insensitive-search" c.icase
dc.icase
;
7058 ob "preload" c.preload dc.preload;
7059 oi
"page-bias" c.pagebias
dc.pagebias
;
7060 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7061 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7062 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7063 ob "crop-hack" c.crophack
dc.crophack
;
7064 oW
"throttle" c.maxwait
dc.maxwait
;
7065 ob "highlight-links" c.hlinks
dc.hlinks
;
7066 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7067 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7068 oz
"zoom" c.zoom dc.zoom;
7069 ob "presentation" c.presentation
dc.presentation
;
7070 oi
"rotation-angle" c.angle
dc.angle
;
7071 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7072 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7073 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7074 oi
"tex-count" c.texcount
dc.texcount
;
7075 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7076 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7077 ob "persistent-location" c.jumpback
dc.jumpback
;
7078 oc
"background-color" c.bgcolor
dc.bgcolor
;
7079 oi
"tile-width" c.tilew
dc.tilew
;
7080 oi
"tile-height" c.tileh
dc.tileh
;
7081 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7082 ob "checkers" c.checkers
dc.checkers
;
7083 oi
"aalevel" c.aalevel
dc.aalevel
;
7084 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7085 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7086 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7087 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7088 oC
"color-space" c.colorspace
dc.colorspace
;
7089 ob "invert-colors" c.invert
dc.invert
;
7090 oF
"brightness" c.colorscale
dc.colorscale
;
7091 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7092 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7093 oco
"columns" c.columns
dc.columns
;
7094 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7095 os
"selection-command" c.selcmd
dc.selcmd
;
7096 os
"synctex-command" c.stcmd
dc.stcmd
;
7097 os
"pax-command" c.paxcmd
dc.paxcmd
;
7098 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7099 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7100 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7101 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7102 ob "use-pbo" c.usepbo
dc.usepbo
;
7103 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7104 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7105 op
"point-and-x" c.pax
dc.pax
;
7106 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7109 let keymapsbuf always
dc c =
7110 let bb = Buffer.create
16 in
7111 let rec loop = function
7113 | (modename, h) :: rest
->
7114 let dh = findkeyhash dc modename in
7115 if always
|| h <> dh
7117 if Hashtbl.length
h > 0
7119 if Buffer.length
bb > 0
7120 then Buffer.add_char
bb '
\n'
;
7121 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7122 Hashtbl.iter
(fun i
o ->
7123 let isdifferent = always
||
7125 let dO = Hashtbl.find dh i
in
7127 with Not_found
-> true
7132 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7133 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7134 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7135 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7136 Buffer.add_string
bb (Wsi.keyname
k);
7139 let rec loop = function
7141 | km
:: [] -> addkm km
7142 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7146 Buffer.add_string
bb "<map in='";
7150 Buffer.add_string
bb "' out='";
7152 Buffer.add_string
bb "'/>\n"
7155 Buffer.add_string
bb "' out='";
7157 Buffer.add_string
bb "'/>\n"
7159 | KMmulti
(ins, kms
) ->
7160 Buffer.add_char
bb ' '
;
7162 Buffer.add_string
bb "' out='";
7164 Buffer.add_string
bb "'/>\n"
7166 Buffer.add_string
bb "</keymap>";
7176 let uifontsize = fstate.fontsize
in
7177 let bb = Buffer.create
32768 in
7178 let relx = float state.x /. float state.winw in
7180 let cx w = truncate
(relx *. float w) in
7182 (fun (w, h, x) ws
->
7184 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7185 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7186 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7188 (state.winw, state.winh
, state.x) state.winstate
7193 let dc = if conf.bedefault
then conf else dc in
7194 Buffer.add_string
bb "<llppconfig>\n";
7196 if String.length
!fontpath > 0
7198 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7204 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7207 Buffer.add_string
bb "<defaults ";
7208 add_attrs bb true dc dc;
7209 let kb = keymapsbuf true dc dc in
7210 if Buffer.length
kb > 0
7212 Buffer.add_string
bb ">\n";
7213 Buffer.add_buffer
bb kb;
7214 Buffer.add_string
bb "\n</defaults>\n";
7216 else Buffer.add_string
bb "/>\n";
7218 let adddoc path pan
anchor c bookmarks =
7219 if bookmarks == [] && c = dc && anchor = emptyanchor
7222 Printf.bprintf
bb "<doc path='%s'"
7223 (enent
path 0 (String.length
path));
7225 if anchor <> emptyanchor
7227 let n, rely, visy
= anchor in
7228 Printf.bprintf
bb " page='%d'" n;
7231 Printf.bprintf
bb " rely='%f'" rely
7233 if abs_float visy
> 1e-6
7235 Printf.bprintf
bb " visy='%f'" visy
7240 then Printf.bprintf
bb " pan='%d'" pan
;
7242 add_attrs bb false dc c;
7243 let kb = keymapsbuf false dc c in
7245 begin match bookmarks with
7247 if Buffer.length
kb > 0
7249 Buffer.add_string
bb ">\n";
7250 Buffer.add_buffer
bb kb;
7251 Buffer.add_string
bb "\n</doc>\n";
7253 else Buffer.add_string
bb "/>\n"
7255 Buffer.add_string
bb ">\n<bookmarks>\n";
7256 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7258 "<item title='%s' page='%d'"
7259 (enent
title 0 (String.length
title))
7264 Printf.bprintf
bb " rely='%f'" rely
7266 if abs_float visy
> 1e-6
7268 Printf.bprintf
bb " visy='%f'" visy
7270 Buffer.add_string
bb "/>\n";
7272 Buffer.add_string
bb "</bookmarks>";
7273 if Buffer.length
kb > 0
7275 Buffer.add_string
bb "\n";
7276 Buffer.add_buffer
bb kb;
7278 Buffer.add_string
bb "\n</doc>\n";
7284 match state.mode with
7285 | Birdseye
(c, pan, _, _, _) ->
7287 match conf.columns
with
7288 | Cmulti
((c, _, _), _) -> Some
c
7292 match c.columns
with
7293 | Cmulti
(c, _) -> Cmulti
(c, [||])
7294 | Csingle
_ -> Csingle
[||]
7295 | Csplit
_ -> failwith
"quit from bird's eye while split"
7297 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7300 let basename = Filename.basename
7301 (if String.length
state.origin
= 0 then state.path else state.origin
)
7303 adddoc basename pan (getanchor ())
7305 let autoscrollstep =
7306 match state.autoscroll
with
7308 | None
-> conf.autoscrollstep
7310 match state.mode with
7311 | Birdseye
(bc
, _, _, _, _) ->
7314 presentation
= bc
.presentation
;
7315 interpagespace
= bc
.interpagespace
;
7316 maxwait
= bc
.maxwait
;
7317 autoscrollstep = autoscrollstep }
7318 | _ -> { conf with autoscrollstep = autoscrollstep }
7320 (if conf.savebmarks
then state.bookmarks else []);
7322 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7324 then adddoc path x anchor c bookmarks
7326 Buffer.add_string
bb "</llppconfig>\n";
7329 if load1 f && Buffer.length
bb > 0
7332 let tmp = !confpath ^
".tmp" in
7333 let oc = open_out_bin
tmp in
7334 Buffer.output_buffer
oc bb;
7336 Unix.rename
tmp !confpath;
7339 ("error while saving configuration: " ^ exntos exn
)
7343 let adderrmsg src msg
=
7344 Buffer.add_string
state.errmsgs msg
;
7345 state.newerrmsgs
<- true;
7349 let adderrfmt src fmt
=
7350 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7354 let cl = splitatspace cmds
in
7356 try Scanf.sscanf
s fmt
f
7358 adderrfmt "remote exec"
7359 "error processing '%S': %s\n" cmds
(exntos exn
)
7362 | "reload" :: [] -> reload ()
7363 | "goto" :: args :: [] ->
7364 scan args "%u %f %f"
7366 let cmd, _ = state.geomcmds
in
7367 if String.length
cmd = 0
7368 then gotopagexy pageno x y
7371 gotopagexy pageno x y;
7374 state.reprf
<- f state.reprf
7376 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7377 | "rect" :: args :: [] ->
7378 scan args "%u %u %f %f %f %f"
7379 (fun pageno color x0 y0 x1 y1 ->
7380 onpagerect pageno (fun w h ->
7381 let _,w1,h1
,_ = getpagedim pageno in
7382 let sw = float w1 /. w
7383 and sh = float h1
/. h in
7387 and y1s
= y1 *. sh in
7388 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7390 state.rects <- (pageno, color, rect) :: state.rects;
7391 G.postRedisplay "rect";
7394 | "activatewin" :: [] -> Wsi.activatewin
()
7395 | "quit" :: [] -> raise Quit
7397 adderrfmt "remote command"
7398 "error processing remote command: %S\n" cmds
;
7402 let scratch = String.create
80 in
7403 let buf = Buffer.create
80 in
7406 try Some
(Unix.read fd
scratch 0 80)
7408 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7409 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7412 match tempfr () with
7418 if Buffer.length
buf > 0
7420 let s = Buffer.contents
buf in
7430 let pos = String.index_from
scratch ppos '
\n'
in
7431 if pos >= n then -1 else pos
7432 with Not_found
-> -1
7436 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7437 let s = Buffer.contents
buf in
7443 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7449 let remoteopen path =
7450 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7452 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7457 let trimcachepath = ref "" in
7458 let rcmdpath = ref "" in
7459 selfexec := Sys.executable_name
;
7462 [("-p", Arg.String
(fun s -> state.password
<- s),
7463 "<password> Set password");
7467 Config.fontpath := s;
7468 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7470 "<path> Set path to the user interface font");
7474 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7475 Config.confpath := s),
7476 "<path> Set path to the configuration file");
7478 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7479 "<path> Set path to the trim cache file");
7481 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7482 "<named-destination> Set named destination");
7484 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7485 ("-cxack", Arg.Set
cxack, " Cut corners");
7487 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7488 "<path> Set path to the remote commands source");
7490 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7491 "<original-path> Set original path");
7493 ("-v", Arg.Unit
(fun () ->
7495 "%s\nconfiguration path: %s\n"
7499 exit
0), " Print version and exit");
7502 (fun s -> state.path <- s)
7503 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7506 then selfexec := !selfexec ^
" -wtmode";
7508 if String.length
state.path = 0
7509 then (prerr_endline
"file name missing"; exit
1);
7511 if not
(Config.load ())
7512 then prerr_endline
"failed to load configuration";
7514 let wsfd, winw, winh
= Wsi.init
(object
7515 val mutable m_hack
= false
7516 method expose
= if not m_hack
then G.postRedisplay "expose"
7517 method visible
= G.postRedisplay "visible"
7518 method display = m_hack
<- false; display ()
7519 method reshape w h =
7520 m_hack
<- w < state.winw && h < state.winh
;
7522 method mouse b d x y m = mouse b d x y m
7523 method motion x y = state.mpos
<- (x, y); motion x y
7524 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7526 let mascm = m land (
7527 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7529 match state.keystate
with
7531 let km = k, mascm in
7534 let modehash = state.uioh#
modehash in
7535 try Hashtbl.find modehash km
7537 try Hashtbl.find (findkeyhash conf "global") km
7538 with Not_found
-> KMinsrt
(k, m)
7540 | KMinsrt
(k, m) -> keyboard k m
7541 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7542 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7544 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7545 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7546 state.keystate
<- KSnone
7547 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7548 state.keystate
<- KSinto
(keys
, insrt
)
7550 state.keystate
<- KSnone
7552 method enter
x y = state.mpos
<- (x, y); pmotion x y
7553 method leave = state.mpos
<- (-1, -1)
7554 method winstate wsl
= state.winstate
<- wsl
7555 method quit
= raise Quit
7556 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7561 List.exists
GlMisc.check_extension
7562 [ "GL_ARB_texture_rectangle"
7563 ; "GL_EXT_texture_recangle"
7564 ; "GL_NV_texture_rectangle" ]
7566 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7569 let r = GlMisc.get_string `renderer
in
7570 let p = "Mesa DRI Intel(" in
7571 let l = String.length
p in
7572 String.length
r > l && String.sub
r 0 l = p
7574 then defconf.sliceheight
<- 1024;
7577 match Ne.pipe () with
7579 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7583 match Ne.pipe () with
7585 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7595 setcheckers conf.checkers
;
7597 if conf.redirectstderr
7600 let s = Buffer.contents
state.errmsgs ^
7601 (match state.errfd
with
7603 let s = String.create
(80*24) in
7606 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7608 then Unix.read fd
s 0 (String.length
s)
7614 else String.sub
s 0 n
7618 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7619 with exn
-> print_endline
(exntos exn
)
7624 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7625 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7626 !Config.fontpath, !trimcachepath,
7627 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7631 state.text <- "Opening " ^
(mbtoutf8
state.path);
7633 opendoc state.path state.password
;
7637 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7640 if String.length
!rcmdpath > 0
7641 then remoteopen !rcmdpath
7646 let rec loop deadline
=
7648 match state.errfd
with
7649 | None
-> [state.sr
; state.wsfd]
7650 | Some fd
-> [state.sr
; state.wsfd; fd
]
7655 | Some fd
-> fd
:: r
7659 state.redisplay
<- false;
7666 if deadline
= infinity
7668 else max
0.0 (deadline
-. now)
7673 try Unix.select
r [] [] timeout
7674 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7680 if state.ghyll
== noghyll
7682 match state.autoscroll
with
7683 | Some step
when step
!= 0 ->
7684 let y = state.y + step
in
7688 else if y >= state.maxy then 0 else y
7691 if state.mode = View
7692 then state.text <- "";
7695 else deadline
+. 0.01
7700 let rec checkfds = function
7702 | fd
:: rest
when fd
= state.sr
->
7703 let cmd = readcmd state.sr
in
7707 | fd
:: rest
when fd
= state.wsfd ->
7711 | fd
:: rest
when Some fd
= !optrfd ->
7712 begin match remote fd
with
7713 | None
-> optrfd := remoteopen !rcmdpath;
7714 | opt -> optrfd := opt
7719 let s = String.create
80 in
7720 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7721 if conf.redirectstderr
7723 Buffer.add_substring
state.errmsgs
s 0 n;
7724 state.newerrmsgs
<- true;
7725 state.redisplay
<- true;
7728 prerr_string
(String.sub
s 0 n);
7736 if deadline
= infinity
7740 match state.autoscroll
with
7741 | Some step
when step
!= 0 -> deadline1
7742 | _ -> if state.ghyll
== noghyll then infinity
else deadline1