8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 | Uremotedest
of (string * string)
15 and facename
= string;;
24 type params
= (angle
* fitmodel
* trimparams
25 * texcount
* sliceheight
* memsize
26 * colorspace
* fontpath
* trimcachepath
36 and trimmargins
= bool
37 and interpagespace
= int
44 and trimcachepath
= string
47 and irect
= (int * int * int * int)
48 and trimparams
= (trimmargins
* irect
)
49 and colorspace
= | Rgb
| Bgr
| Gray
50 and fitmodel
= | FitWidth
| FitProportional
| FitPage
58 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
67 | LDfirstvisible
of (int * int * int)
82 | KMmulti
of key list
* key list
84 and keyhash
= (key
, keymap
) Hashtbl.t
87 | KSinto
of (key list
* key list
)
90 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
91 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
93 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
95 external init
: pipe
-> params
-> unit = "ml_init";;
96 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
97 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
98 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
99 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
100 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
101 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
102 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
103 external measurestr
: int -> string -> float = "ml_measure_string";;
104 external postprocess
:
105 opaque
-> int -> int -> int -> (int * string * int) -> int
107 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
108 external platform
: unit -> platform
= "ml_platform";;
109 external setaalevel
: int -> unit = "ml_setaalevel";;
110 external realloctexts
: int -> bool = "ml_realloctexts";;
111 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
112 external getlink
: opaque
-> int -> under
= "ml_getlink";;
113 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
114 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
115 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
116 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
117 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
118 external freepbo
: string -> unit = "ml_freepbo";;
119 external unmappbo
: string -> unit = "ml_unmappbo";;
120 external pbousable
: unit -> bool = "ml_pbo_usable";;
121 external unproject
: opaque
-> int -> int -> (int * int) option
123 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
124 external rectofblock
: opaque
-> int -> int -> float array
option
127 let platform_to_string = function
128 | Punknown
-> "unknown"
132 | Pfreebsd
-> "FreeBSD"
133 | Pdragonflybsd
-> "DragonflyBSD"
134 | Popenbsd
-> "OpenBSD"
135 | Pnetbsd
-> "NetBSD"
136 | Pcygwin
-> "Cygwin"
139 let platform = platform ();;
141 let now = Unix.gettimeofday
;;
143 let selfexec = ref "";;
146 if platform = Pcygwin
148 let sh = "/bin/sh" in
149 let args = [|sh; "-c"; cmd
|] in
150 let rec std si so se
= function
152 | (fd
, 0) :: rest
-> std fd so se rest
153 | (fd
, -1) :: rest
->
154 Unix.set_close_on_exec fd
;
157 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
159 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
160 ignore
(Unix.create_process
sh args si so se
)
165 type mpos
= int * int
167 | Msel
of (mpos
* mpos
)
169 | Mscrolly
| Mscrollx
170 | Mzoom
of (int * int)
171 | Mzoomrect
of (mpos
* mpos
)
175 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
176 and onkey
= string -> int -> te
177 and ondone
= string -> unit
178 and histcancel
= unit -> unit
179 and onhist
= ((histcmd
-> string) * histcancel
)
180 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
181 and cancelonempty
= bool
186 | TEswitch
of textentry
197 let bound v minv maxv
=
198 max minv
(min maxv v
);
202 { store
= Array.create n v
209 let cbcap b
= Array.length b
.store
;;
214 b
.wc
<- (b
.wc
+ 1) mod cap;
216 b
.len
<- min
(b
.len
+ 1) cap;
219 let cbempty b
= b
.len
= 0;;
221 let cbgetg b circular dir
=
225 let rc = b
.rc + dir
in
237 else bound rc 0 (b
.len
-1)
243 let cbget b
= cbgetg b
false;;
244 let cbgetc b
= cbgetg b
true;;
246 let drawstring size x y s
=
248 Gl.enable `texture_2d
;
249 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
250 ignore
(drawstr size x y s
);
252 Gl.disable `texture_2d
;
255 let drawstring1 size x y s
=
259 let drawstring2 size x y fmt
=
260 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
279 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
280 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
281 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
282 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
283 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
284 dolog
" column %d" l
.pagecol
;
288 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
290 dolog
" x0,y0=(% f, % f)" x0 y0
;
291 dolog
" x1,y1=(% f, % f)" x1 y1
;
292 dolog
" x2,y2=(% f, % f)" x2 y2
;
293 dolog
" x3,y3=(% f, % f)" x3 y3
;
297 type multicolumns
= multicol
* pagegeom
298 and singlecolumn
= pagegeom
299 and splitcolumns
= columncount
* pagegeom
300 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
301 and multicol
= columncount
* covercount
* covercount
303 and columncount
= int
304 and covercount
= int;;
311 { mutable scrollbw
: int
312 ; mutable scrollh
: int
313 ; mutable scrollb
: scrollb
314 ; mutable icase
: bool
315 ; mutable preload
: bool
316 ; mutable pagebias
: int
317 ; mutable verbose
: bool
318 ; mutable debug
: bool
319 ; mutable scrollstep
: int
320 ; mutable hscrollstep
: int
321 ; mutable maxhfit
: bool
322 ; mutable crophack
: bool
323 ; mutable autoscrollstep
: int
324 ; mutable maxwait
: float option
325 ; mutable hlinks
: bool
326 ; mutable underinfo
: bool
327 ; mutable interpagespace
: interpagespace
328 ; mutable zoom
: float
329 ; mutable presentation
: bool
330 ; mutable angle
: angle
331 ; mutable cwinw
: int
332 ; mutable cwinh
: int
333 ; mutable savebmarks
: bool
334 ; mutable fitmodel
: fitmodel
335 ; mutable trimmargins
: trimmargins
336 ; mutable trimfuzz
: irect
337 ; mutable memlimit
: memsize
338 ; mutable texcount
: texcount
339 ; mutable sliceheight
: sliceheight
340 ; mutable thumbw
: width
341 ; mutable jumpback
: bool
342 ; mutable bgcolor
: (float * float * float)
343 ; mutable bedefault
: bool
344 ; mutable tilew
: int
345 ; mutable tileh
: int
346 ; mutable mustoresize
: memsize
347 ; mutable checkers
: bool
348 ; mutable aalevel
: int
349 ; mutable urilauncher
: string
350 ; mutable pathlauncher
: string
351 ; mutable colorspace
: colorspace
352 ; mutable invert
: bool
353 ; mutable colorscale
: float
354 ; mutable redirectstderr
: bool
355 ; mutable ghyllscroll
: (int * int * int) option
356 ; mutable columns
: columns
357 ; mutable beyecolumns
: columncount
option
358 ; mutable selcmd
: string
359 ; mutable paxcmd
: string
360 ; mutable updatecurs
: bool
361 ; mutable keyhashes
: (string * keyhash
) list
362 ; mutable hfsize
: int
363 ; mutable pgscale
: float
364 ; mutable usepbo
: bool
365 ; mutable wheelbypage
: bool
366 ; mutable stcmd
: string
367 ; mutable riani
: bool
368 ; mutable pax
: (float * int * int) ref option
369 ; mutable paxmark
: mark
372 | Csingle
of singlecolumn
373 | Cmulti
of multicolumns
374 | Csplit
of splitcolumns
377 type anchor
= pageno
* top
* dtop
;;
379 type outline
= string * int * anchor
;;
381 type rect
= float * float * float * float * float * float * float * float;;
383 type tile
= opaque
* pixmapsize
* elapsed
384 and elapsed
= float;;
385 type pagemapkey
= pageno
* gen
;;
386 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
390 let emptyanchor = (0, 0.0, 0.0);;
392 type infochange
= | Memused
| Docinfo
| Pdim
;;
394 class type uioh
= object
395 method display
: unit
396 method key
: int -> int -> uioh
397 method button
: int -> bool -> int -> int -> int -> uioh
398 method motion
: int -> int -> uioh
399 method pmotion
: int -> int -> uioh
400 method infochanged
: infochange
-> unit
401 method scrollpw
: (int * float * float)
402 method scrollph
: (int * float * float)
403 method modehash
: keyhash
404 method eformsgs
: bool
408 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
409 | Textentry
of (textentry
* onleave
)
411 | LinkNav
of linktarget
412 and onleave
= leavetextentrystatus
-> unit
413 and leavetextentrystatus
= | Cancel
| Confirm
414 and helpitem
= string * int * action
417 | Action
of (uioh
-> uioh
)
419 | Ltexact
of (pageno
* int)
423 let isbirdseye = function Birdseye _
-> true | _
-> false;;
424 let istextentry = function Textentry _
-> true | _
-> false;;
428 | Loading
of (page
* gen
)
430 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
432 | Outlining
of outline list
435 let emptykeyhash = Hashtbl.create
0;;
436 let nouioh : uioh
= object (self
)
438 method key _ _
= self
439 method button _ _ _ _ _
= self
440 method motion _ _
= self
441 method pmotion _ _
= self
442 method infochanged _
= ()
443 method scrollpw
= (0, nan
, nan
)
444 method scrollph
= (0, nan
, nan
)
445 method modehash
= emptykeyhash
446 method eformsgs
= false
450 { mutable sr
: Unix.file_descr
451 ; mutable sw
: Unix.file_descr
452 ; mutable wsfd
: Unix.file_descr
453 ; mutable errfd
: Unix.file_descr
option
454 ; mutable stderr
: Unix.file_descr
455 ; mutable errmsgs
: Buffer.t
456 ; mutable newerrmsgs
: bool
460 ; mutable anchor
: anchor
461 ; mutable ranchors
: (string * string * anchor
* string) list
463 ; mutable layout
: page list
464 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
465 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
466 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
467 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
468 ; mutable pagecount
: int
469 ; mutable currently
: currently
470 ; mutable mstate
: mstate
471 ; mutable searchpattern
: string
472 ; mutable rects
: (pageno
* recttype
* rect
) list
473 ; mutable rects1
: (pageno
* recttype
* rect
) list
474 ; mutable text
: string
475 ; mutable winstate
: Wsi.winstate list
476 ; mutable mode
: mode
477 ; mutable uioh
: uioh
478 ; mutable outlines
: outline array
479 ; mutable bookmarks
: outline list
480 ; mutable path
: string
481 ; mutable password
: string
482 ; mutable nameddest
: string
483 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
484 ; mutable memused
: memsize
486 ; mutable throttle
: (page list
* int * float) option
487 ; mutable autoscroll
: int option
488 ; mutable ghyll
: (int option -> unit)
489 ; mutable help
: helpitem array
490 ; mutable docinfo
: (int * string) list
491 ; mutable texid
: GlTex.texture_id
option
493 ; mutable prevzoom
: (float * int)
494 ; mutable progress
: float
495 ; mutable redisplay
: bool
496 ; mutable mpos
: mpos
497 ; mutable keystate
: keystate
498 ; mutable glinks
: bool
499 ; mutable prevcolumns
: (columns
* float) option
502 ; mutable reprf
: (unit -> unit)
503 ; mutable origin
: string
504 ; mutable roam
: (unit -> unit)
505 ; mutable bzoom
: bool
508 { pat
: string circbuf
509 ; pag
: string circbuf
510 ; nav
: anchor circbuf
511 ; sel
: string circbuf
518 ; scrollb
= scrollbhv lor scrollbvv
534 ; presentation
= false
539 ; fitmodel
= FitProportional
540 ; trimmargins
= false
541 ; trimfuzz
= (0,0,0,0)
542 ; memlimit
= 32 lsl 20
547 ; bgcolor
= (0.5, 0.5, 0.5)
551 ; mustoresize
= 256 lsl 20
556 | Plinux
| Pfreebsd
| Pdragonflybsd
557 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
558 | Posx
-> "open \"%s\""
559 | Pcygwin
-> "cygstart \"%s\""
560 | Punknown
-> "echo %s")
561 ; pathlauncher
= "lp \"%s\""
564 | Plinux
| Pfreebsd
| Pdragonflybsd
565 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
573 ; redirectstderr
= false
575 ; columns
= Csingle
[||]
581 ; wheelbypage
= false
582 ; stcmd
= "echo SyncTex"
585 ; paxmark
= Mark_word
587 let mk n
= (n
, Hashtbl.create
1) in
601 let wtmode = ref false;;
602 let cxack = ref false;;
604 let findkeyhash c name
=
605 try List.assoc name c
.keyhashes
606 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
609 let conf = { defconf with angle
= defconf.angle
};;
611 let pgscale h
= truncate
(float h
*. conf.pgscale);;
614 { mutable fontsize
: int
615 ; mutable wwidth
: float
616 ; mutable maxrows
: int
628 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
629 let len = String.length s
in
630 if colonpos >= 0 && colonpos + 3 < len
632 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
635 try String.rindex_from s
colonpos ' '
639 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
642 | "http" | "ftp" | "mailto" ->
644 try String.index_from s
colonpos ' '
645 with Not_found
-> len
647 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
655 if emptystr
conf.urilauncher
656 then print_endline uri
658 let url = geturl uri
in
660 then Printf.eprintf
"obtained empty url from uri %S" uri
662 let re = Str.regexp
"%s" in
663 let command = Str.global_replace
re url conf.urilauncher
in
667 "failed to execute `%s': %s\n" command (exntos exn
);
673 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
674 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
678 let strings = version () :: "" :: Help.keys
in
681 let url = geturl s
in
683 then (s
, 0, Action
(fun u
-> gotouri url; u
))
684 else (s
, 0, Noaction
)
689 let firstgeomcmds = "", [];;
690 let noreprf () = ();;
697 ; stderr
= Unix.stderr
698 ; errmsgs
= Buffer.create
0
703 ; anchor
= emptyanchor
707 ; tilelru
= Queue.create
()
708 ; pagemap
= Hashtbl.create
10
709 ; tilemap
= Hashtbl.create
10
725 ; geomcmds
= firstgeomcmds
727 { nav
= cbnew 10 emptyanchor
740 ; prevzoom
= (1.0, 0)
752 ; roam
= (fun () -> ())
758 if (conf.scrollb
land scrollbhv = 0)
759 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
765 if (conf.scrollb
land scrollbvv = 0)
770 let wadjsb w
= w
- vscrollw ();;
773 fstate.fontsize
<- n
;
774 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
775 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
781 Printf.kprintf prerr_endline fmt
783 Printf.kprintf ignore fmt
787 if emptystr
conf.pathlauncher
788 then print_endline
state.path
790 let re = Str.regexp
"%s" in
791 let command = Str.global_replace
re state.path
conf.pathlauncher
in
794 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
800 type 'a t
= | Res
of 'a
| Exn
of exn
;;
803 try Res
(Unix.pipe ())
808 try tempfailureretry
Unix.close fd
809 with exn
-> f
(exntos exn
)
813 try Res
(tempfailureretry
Unix.dup fd
)
818 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
823 let redirectstderr () =
824 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
825 if conf.redirectstderr
827 match Ne.pipe () with
829 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
832 begin match Ne.dup Unix.stderr
with
834 dolog
"failed to dup stderr: %s" (exntos exn
);
835 Ne.clo r
(clofail "pipe/r");
836 Ne.clo w
(clofail "pipe/w");
838 | Ne.Res dupstderr
->
839 begin match Ne.dup2 w
Unix.stderr
with
841 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
842 Ne.clo dupstderr
(clofail "stderr duplicate");
843 Ne.clo r
(clofail "redir pipe/r");
844 Ne.clo w
(clofail "redir pipe/w");
847 state.stderr
<- dupstderr
;
848 state.errfd
<- Some r
;
852 state.newerrmsgs
<- false;
853 begin match state.errfd
with
855 begin match Ne.dup2 state.stderr
Unix.stderr
with
857 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
859 Ne.clo fd
(clofail "dup of stderr");
864 prerr_string
(Buffer.contents
state.errmsgs
);
866 Buffer.clear
state.errmsgs
;
872 let postRedisplay who
=
874 then prerr_endline
("redisplay for " ^ who
);
875 state.redisplay
<- true;
879 let getopaque pageno
=
880 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
881 with Not_found
-> None
884 let putopaque pageno opaque
=
885 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
888 let pagetranslatepoint l x y
=
889 let dy = y
- l
.pagedispy
in
890 let y = dy + l
.pagey
in
891 let dx = x
- l
.pagedispx
in
892 let x = dx + l
.pagex
in
896 let onppundermouse g
x y d
=
899 begin match getopaque l
.pageno
with
901 let x0 = l
.pagedispx
in
902 let x1 = x0 + l
.pagevw
in
903 let y0 = l
.pagedispy
in
904 let y1 = y0 + l
.pagevh
in
905 if y >= y0 && y <= y1 && x >= x0 && x <= x1
907 let px, py
= pagetranslatepoint l
x y in
908 match g opaque l
px py
with
921 let g opaque l
px py
=
924 match rectofblock opaque
px py
with
926 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
927 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
928 G.postRedisplay "getunder";
931 match whatsunder opaque
px py
with
933 | under
-> Some under
935 onppundermouse g x y Unone
940 match unproject opaque
x y with
941 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
944 onppundermouse g x y None
;
948 state.text
<- Printf.sprintf
"%c%s" c s
;
949 G.postRedisplay "showtext";
953 let g opaque l
px py
=
954 if markunder opaque
px py
conf.paxmark
957 match getopaque l
.pageno
with
960 match Ne.pipe () with
964 "can not create mark pipe: %s"
967 let doclose what fd
=
968 Ne.clo fd
(fun msg
->
969 dolog
"%s close failed: %s" what msg
)
972 popen conf.paxcmd
[r
, 0; w
, -1];
973 copysel w opaque
false;
975 G.postRedisplay "paxunder";
977 dolog
"can not execute %S: %s"
978 conf.paxcmd
(exntos exn
);
985 G.postRedisplay "paxunder";
987 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
991 match Ne.pipe () with
993 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
996 try popen conf.selcmd
[r
, 0; w
, -1]; true
999 (Printf.sprintf
"failed to execute %s: %s"
1000 conf.selcmd
(exntos exn
));
1004 Ne.clo fd
(fun msg
->
1005 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1011 let l = String.length s
in
1012 let n = tempfailureretry
(Unix.write w s
0) l in
1017 "failed to write %d characters to sel pipe, wrote %d"
1022 (Printf.sprintf
"failed to write to sel pipe: %s"
1031 let undertext = function
1034 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1035 | Utext s
-> "font: " ^ s
1036 | Uunexpected s
-> "unexpected: " ^ s
1037 | Ulaunch s
-> "launch: " ^ s
1038 | Unamed s
-> "named: " ^ s
1039 | Uremote
(filename
, pageno
) ->
1040 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1041 | Uremotedest
(filename
, destname
) ->
1042 Printf.sprintf
"%s: destination %S" filename destname
1045 let updateunder x y =
1046 match getunder x y with
1047 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1049 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1050 Wsi.setcursor
Wsi.CURSOR_INFO
1051 | Ulinkgoto
(pageno
, _
) ->
1053 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1054 Wsi.setcursor
Wsi.CURSOR_INFO
1056 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1057 Wsi.setcursor
Wsi.CURSOR_TEXT
1059 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1060 Wsi.setcursor
Wsi.CURSOR_INHERIT
1062 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1063 Wsi.setcursor
Wsi.CURSOR_INHERIT
1065 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1066 Wsi.setcursor
Wsi.CURSOR_INHERIT
1067 | Uremote
(filename
, pageno
) ->
1068 if conf.underinfo
then showtext 'r'
1069 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1070 Wsi.setcursor
Wsi.CURSOR_INFO
1071 | Uremotedest
(filename
, destname
) ->
1072 if conf.underinfo
then showtext 'r'
1073 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1074 Wsi.setcursor
Wsi.CURSOR_INFO
1077 let showlinktype under
=
1083 let s = undertext under
in
1088 let b = Buffer.create
(String.length
s + 1) in
1089 Buffer.add_string
b s;
1090 Buffer.add_char
b c
;
1094 module type TextEnumType
=
1098 val names
: string array
1101 module TextEnumMake
(Ten
: TextEnumType
) =
1103 let names = Ten.names;;
1104 let to_int (t
: Ten.t
) = Obj.magic t
;;
1105 let to_string t
= names.(to_int t
);;
1106 let of_int n : Ten.t
= Obj.magic
n;;
1109 if i
= Array.length
names
1110 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1112 if Ten.names.(i
) = s
1119 module CSTE
= TextEnumMake
(struct
1120 type t
= colorspace
;;
1121 let name = "colorspace";;
1122 let names = [|"rgb"; "bgr"; "gray"|];;
1125 module MTE
= TextEnumMake
(struct
1128 let names = [|"page"; "block"; "line"; "word"|];;
1131 module FMTE
= TextEnumMake
(struct
1133 let name = "fitmodel";;
1134 let names = [|"width"; "proportional"; "page"|];;
1137 let intentry_with_suffix text key
=
1139 if key
>= 32 && key
< 127
1143 match Char.lowercase
c with
1145 let text = addchar text c in
1148 | 'k'
| 'm'
| '
g'
->
1149 let text = addchar text c in
1153 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1157 let multicolumns_to_string (n, a
, b) =
1159 then Printf.sprintf
"%d" n
1160 else Printf.sprintf
"%d,%d,%d" n a
b;
1163 let multicolumns_of_string s =
1165 (int_of_string
s, 0, 0)
1167 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1169 then failwith
"subtly broken"; (n, a
, b)
1175 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1176 if n != 4 then failwith
"incomplete read(len)";
1178 lor (Char.code
s.[0] lsl 24)
1179 lor (Char.code
s.[1] lsl 16)
1180 lor (Char.code
s.[2] lsl 8)
1181 lor (Char.code
s.[3] lsl 0)
1183 let s = String.create
len in
1184 let n = tempfailureretry
(Unix.read fd
s 0) len in
1185 if n != len then failwith
"incomplete read(data)";
1189 let btod b = if b then 1 else 0;;
1192 let b = Buffer.create
16 in
1193 Buffer.add_string
b "llll";
1196 let s = Buffer.contents
b in
1197 let n = String.length
s in
1199 (* dolog "wcmd %S" (String.sub s 4 len); *)
1200 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1201 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1202 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1203 s.[3] <- Char.chr
(len land 0xff);
1204 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1205 if n'
!= n then failwith
"write failed";
1210 let d = state.winh
- h
in
1211 max
conf.interpagespace
((d + 1) / 2)
1214 let rowyh (c, coverA
, coverB
) b n =
1215 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1217 let _, _, vy
, (_, _, h
, _) = b.(n) in
1220 let n'
= n - coverA
in
1223 let e = min
state.pagecount
(s + c) in
1224 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1225 let _, _, y, (_, _, h
, _) = b.(m
) in
1226 let miny = min
miny y in
1227 let maxh = max
maxh h
in
1228 find (m
+1) miny maxh
1233 match conf.columns
with
1234 | Cmulti
((_, _, _) as cl
, b) ->
1235 if Array.length
b > 0
1237 let y, h
= rowyh cl
b (Array.length
b - 1) in
1238 y + h
+ (if conf.presentation
then calcips h
else 0)
1241 if Array.length
b > 0
1243 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1244 y + h
+ (if conf.presentation
then calcips h
else 0)
1247 if Array.length
b > 0
1249 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1254 let getpageywh pageno
=
1255 let pageno = bound pageno 0 (state.pagecount
-1) in
1256 match conf.columns
with
1258 if Array.length
b = 0
1261 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1263 if conf.presentation
1269 if Array.length
b = 0
1272 let y, h
= rowyh cl
b pageno in
1273 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1275 if conf.presentation
1281 if Array.length
b = 0
1285 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1289 let getpageyh pageno =
1290 let y,_,h
= getpageywh pageno in
1294 let getpagedim pageno =
1297 | (n, _, _, _) as pdim
:: rest
->
1299 then (if n = pageno then pdim
else ppdim
)
1304 f (-1, -1, -1, -1) state.pdims
1307 let getpagey pageno = fst
(getpageyh pageno);;
1309 let nogeomcmds cmds
=
1311 | s, [] -> emptystr
s
1316 let ((c, coverA
, coverB
) as cl
), b =
1317 match conf.columns
with
1318 | Csingle
b -> (1, 0, 0), b
1319 | Cmulti
(c, b) -> c, b
1320 | Csplit
(_, b) -> (1, 0, 0), b
1322 if Array.length
b = 0
1325 let rec bsearch nmin nmax
=
1327 then bound nmin
0 (state.pagecount
-1)
1329 let n = (nmax
+ nmin
) / 2 in
1330 let vy, h
= rowyh cl
b n in
1332 if conf.presentation
1334 let ips = calcips h
in
1335 let y0 = vy - ips in
1336 let y1 = vy + h
+ ips in
1340 then 0, vy + h
+ conf.interpagespace
1342 let y0 = vy - conf.interpagespace
in
1343 y0, y0 + h
+ conf.interpagespace
1346 if y >= y0 && y < y1
1353 if n < state.pagecount
- coverB
1354 then ((n-coverA
)/c)*c + coverA
1361 then bsearch (n+1) nmax
1362 else bsearch nmin
(n-1)
1365 let r = bsearch 0 (state.pagecount
-1) in
1369 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1370 let sh = sh - (hscrollh ()) in
1371 let rec fold accu
n =
1372 if n = Array.length
b
1375 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1378 || n = state.pagecount
- coverB
1379 || (n - coverA
) mod columns
= columns
- 1)
1385 let pagey = max
0 (y - vy) in
1386 let pagedispy = if pagey > 0 then 0 else vy - y in
1387 let pagedispx, pagex
=
1389 if n = coverA
- 1 || n = state.pagecount
- coverB
1390 then state.x + (wadjsb state.winw
- w
) / 2
1391 else dx + xoff
+ state.x
1398 let vw = wadjsb state.winw
- pagedispx in
1399 let pw = w
- pagex
in
1402 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1403 if pagevw > 0 && pagevh > 0
1407 ; pagedimno
= pdimno
1414 ; pagedispx = pagedispx
1415 ; pagedispy = pagedispy
1427 if Array.length
b = 0
1429 else List.rev
(fold [] (page_of_y y))
1432 let layoutS (columns
, b) y sh =
1433 let sh = sh - hscrollh () in
1434 let rec fold accu n =
1435 if n = Array.length
b
1438 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1445 let x = xoff
+ state.x in
1446 let pagey = max
0 (y - vy) in
1447 let pagedispy = if pagey > 0 then 0 else vy - y in
1448 let pagedispx, pagex
=
1462 let pagecolw = pagew
/columns
in
1464 if pagecolw < state.winw
1465 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1469 let vw = wadjsb state.winw
- pagedispx in
1470 let pw = pagew
- pagex
in
1473 let pagevw = min
pagevw pagecolw in
1474 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1475 if pagevw > 0 && pagevh > 0
1478 { pageno = n/columns
1479 ; pagedimno
= pdimno
1486 ; pagedispx = pagedispx
1487 ; pagedispy = pagedispy
1488 ; pagecol
= n mod columns
1499 List.rev
(fold [] 0)
1503 if nogeomcmds state.geomcmds
1505 match conf.columns
with
1506 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1507 | Cmulti
c -> layoutN c y sh
1508 | Csplit
s -> layoutS s y sh
1513 let y = state.y + incr
in
1515 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1520 let tilex = l.pagex
mod conf.tilew
in
1521 let tiley = l.pagey mod conf.tileh
in
1523 let col = l.pagex
/ conf.tilew
in
1524 let row = l.pagey / conf.tileh
in
1526 let rec rowloop row y0 dispy h
=
1530 let dh = conf.tileh
- y0 in
1531 let dh = min h
dh in
1532 let rec colloop col x0 dispx w
=
1536 let dw = conf.tilew
- x0 in
1537 let dw = min w
dw in
1539 f col row dispx dispy
x0 y0 dw dh;
1540 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1543 colloop col tilex l.pagedispx l.pagevw;
1544 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1547 if l.pagevw > 0 && l.pagevh > 0
1548 then rowloop row tiley l.pagedispy l.pagevh;
1551 let gettileopaque l col row =
1553 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1555 try Some
(Hashtbl.find state.tilemap
key)
1556 with Not_found
-> None
1559 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1560 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1561 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1564 let drawtiles l color
=
1566 let f col row x y tilex tiley w h
=
1567 match gettileopaque l col row with
1568 | Some
(opaque
, _, t
) ->
1569 let params = x, y, w
, h
, tilex, tiley in
1573 GlFunc.blend_func `zero `one_minus_src_color
;
1575 drawtile
params opaque
;
1577 then Gl.disable `blend
;
1580 let s = Printf.sprintf
1584 let w = measurestr
fstate.fontsize
s in
1585 GlMisc.push_attrib
[`current
];
1586 GlDraw.color
(0.0, 0.0, 0.0);
1588 (float (x-2), float (y-2))
1589 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1590 GlDraw.color
(1.0, 1.0, 1.0);
1591 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1592 GlMisc.pop_attrib
();
1597 let lw = wadjsb state.winw
- x in
1600 let lh = state.winh
- y in
1603 begin match state.texid
with
1605 Gl.enable `texture_2d
;
1606 GlTex.bind_texture `texture_2d id
;
1609 and x1 = float (x+w)
1610 and y1 = float (y+h
) in
1612 let tw = float w /. 16.0
1613 and th
= float h
/. 16.0 in
1614 let tx0 = float tilex /. 16.0
1615 and ty0
= float tiley /. 16.0 in
1617 and ty1
= ty0
+. th
in
1618 GlDraw.begins `quads
;
1619 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1620 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1621 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1622 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1625 Gl.disable `texture_2d
;
1627 GlDraw.color
(1.0, 1.0, 1.0);
1630 (float (x+w), float (y+h
));
1632 if w > 128 && h
> fstate.fontsize
+ 10
1634 GlDraw.color
(0.0, 0.0, 0.0);
1637 then (col*conf.tilew
, row*conf.tileh
)
1640 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1647 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1649 let tilevisible1 l x y =
1651 and ax1
= l.pagex
+ l.pagevw
1653 and ay1
= l.pagey + l.pagevh in
1657 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1658 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1660 let rx0 = max
ax0 bx0
1661 and ry0
= max ay0 by0
1662 and rx1
= min ax1
bx1
1663 and ry1
= min ay1 by1
in
1665 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1666 nonemptyintersection
1669 let tilevisible layout n x y =
1670 let rec findpageinlayout m
= function
1671 | l :: rest
when l.pageno = n ->
1672 tilevisible1 l x y || (
1673 match conf.columns
with
1674 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1677 | _ :: rest
-> findpageinlayout 0 rest
1680 findpageinlayout 0 layout;
1683 let tileready l x y =
1684 tilevisible1 l x y &&
1685 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1688 let tilepage n p
layout =
1689 let rec loop = function
1693 let f col row _ _ _ _ _ _ =
1694 if state.currently
= Idle
1696 match gettileopaque l col row with
1699 let x = col*conf.tilew
1700 and y = row*conf.tileh
in
1702 let w = l.pagew
- x in
1706 let h = l.pageh
- y in
1711 then getpbo
w h conf.colorspace
1714 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1717 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1718 conf.tilew
, conf.tileh
1727 if nogeomcmds state.geomcmds
1731 let preloadlayout y =
1732 let y = if y < state.winh
then 0 else y - state.winh
in
1733 let h = state.winh
*3 in
1738 let rec loop pages
=
1739 if state.currently
!= Idle
1744 begin match getopaque l.pageno with
1746 wcmd "page %d %d" l.pageno l.pagedimno
;
1747 state.currently
<- Loading
(l, state.gen
);
1749 tilepage l.pageno opaque pages
;
1754 if nogeomcmds state.geomcmds
1760 if conf.preload && state.currently
= Idle
1761 then load (preloadlayout state.y);
1764 let layoutready layout =
1765 let rec fold all ls
=
1766 all
&& match ls
with
1768 let seen = ref false in
1769 let allvisible = ref true in
1770 let foo col row _ _ _ _ _ _ =
1772 allvisible := !allvisible &&
1773 begin match gettileopaque l col row with
1779 fold (!seen && !allvisible) rest
1782 let alltilesvisible = fold true layout in
1787 let y = bound y 0 state.maxy
in
1788 let y, layout, proceed
=
1789 match conf.maxwait
with
1790 | Some time
when state.ghyll
== noghyll ->
1791 begin match state.throttle
with
1793 let layout = layout y state.winh
in
1794 let ready = layoutready layout in
1798 state.throttle
<- Some
(layout, y, now ());
1800 else G.postRedisplay "gotoy showall (None)";
1802 | Some
(_, _, started
) ->
1803 let dt = now () -. started
in
1806 state.throttle
<- None
;
1807 let layout = layout y state.winh
in
1809 G.postRedisplay "maxwait";
1816 let layout = layout y state.winh
in
1817 if not
!wtmode || layoutready layout
1818 then G.postRedisplay "gotoy ready";
1824 state.layout <- layout;
1825 begin match state.mode
with
1826 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1827 let rec loop = function
1829 state.mode
<- LinkNav
(Ltgendir
0)
1830 | l :: _ when l.pageno = pageno ->
1831 begin match getopaque pageno with
1833 state.mode
<- LinkNav
(Ltgendir
0)
1835 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1836 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1837 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1838 then state.mode
<- LinkNav
(Ltgendir
0)
1840 | _ :: rest
-> loop rest
1845 begin match state.mode
with
1846 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1847 if not
(pagevisible layout pageno)
1849 match state.layout with
1852 state.mode
<- Birdseye
(
1853 conf, leftx
, l.pageno, hooverpageno
, anchor
1856 | LinkNav
(Ltgendir dir
as lt
) ->
1858 let rec loop = function
1861 match getopaque l.pageno with
1867 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1869 if dir
> 0 then LDfirst
else LDlast
1875 | Lnotfound
-> loop rest
1877 showlinktype (getlink opaque
n);
1878 Ltexact
(l.pageno, n)
1882 state.mode
<- LinkNav
linknav
1887 state.ghyll
<- noghyll;
1890 let mx, my
= state.mpos
in
1895 let conttiling pageno opaque
=
1896 tilepage pageno opaque
1897 (if conf.preload then preloadlayout state.y else state.layout)
1900 let gotoy_and_clear_text y =
1901 if not
conf.verbose
then state.text <- "";
1907 let coloff = l.pagecol
* l.pageh
in
1908 float (l.pagey + coloff) /. float l.pageh
1915 if conf.presentation
1916 then float l.pagedispy /. float (calcips l.pageh
)
1917 else float l.pagedispy /. float conf.interpagespace
1920 (l.pageno, top, dtop)
1924 match state.layout with
1925 | l :: _ -> getanchor1 l
1927 let n = page_of_y state.y in
1931 let y, h = getpageyh n in
1932 let dy = y - state.y in
1934 if conf.presentation
1936 let ips = calcips h in
1937 float (dy + ips) /. float ips
1939 float dy /. float conf.interpagespace
1944 let getanchory (n, top, dtop) =
1945 let y, h = getpageyh n in
1946 if conf.presentation
1948 let ips = calcips h in
1949 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1951 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1954 let gotoanchor anchor
=
1955 gotoy (getanchory anchor
);
1959 cbput state.hists
.nav
(getanchor ());
1963 let anchor = cbgetc state.hists
.nav dir
in
1968 let scroll f n a
b =
1969 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1971 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1973 then s (float f /. float a
)
1976 then 1.0 -. s ((float (f-b) /. float (n-b)))
1982 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1983 let iv x = x**3.-.0.5*.x**4. in
1985 let ins = float a
*. iv1
1986 and outs
= float (n-b) *. iv1 in
1988 ins +. outs
+. float ones
1990 let rec set (_N
, _A
, _B
) y sy
=
1991 let sum = summa
1.0 _N _A _B
in
1992 let dy = float (y - sy
) in
1996 then state.ghyll
<- noghyll
1999 let s = scroll n _N _A _B
in
2000 let y1 = y1 +. ((s *. dy) /. sum) in
2001 gotoy_and_clear_text (truncate
y1);
2002 state.ghyll
<- gf (n+1) y1;
2006 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2008 gf 0 (float state.y)
2011 match conf.ghyllscroll
with
2013 gotoy_and_clear_text y
2015 if state.ghyll
== noghyll
2016 then set nab
y state.y
2017 else state.ghyll
(Some
y)
2020 let gotopage n top =
2021 let y, h = getpageyh n in
2022 let y = y + (truncate
(top *. float h)) in
2026 let gotopage1 n top =
2027 let y = getpagey n in
2032 let invalidate s f =
2037 match state.geomcmds
with
2038 | ps
, [] when emptystr ps
->
2040 state.geomcmds
<- s, [];
2043 state.geomcmds
<- ps
, [s, f];
2045 | ps
, (s'
, _) :: rest
when s'
= s ->
2046 state.geomcmds
<- ps
, ((s, f) :: rest
);
2049 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2053 Hashtbl.iter
(fun _ opaque
->
2054 wcmd "freepage %s" opaque
;
2056 Hashtbl.clear
state.pagemap
;
2060 if not
(Queue.is_empty
state.tilelru
)
2062 Queue.iter
(fun (k
, p
, s) ->
2063 wcmd "freetile %s" p
;
2064 state.memused
<- state.memused
- s;
2065 Hashtbl.remove
state.tilemap k
;
2067 state.uioh#infochanged Memused
;
2068 Queue.clear
state.tilelru
;
2074 let h = truncate
(float h*.conf.zoom
) in
2075 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2079 let opendoc path password
=
2081 state.password
<- password
;
2082 state.gen
<- state.gen
+ 1;
2083 state.docinfo
<- [];
2086 setaalevel
conf.aalevel
;
2088 if emptystr
state.origin
2092 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2093 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2094 invalidate "reqlayout"
2096 wcmd "reqlayout %d %d %d %s\000"
2097 conf.angle
(FMTE.to_int conf.fitmodel
)
2098 (stateh state.winh
) state.nameddest
2103 state.anchor <- getanchor ();
2104 opendoc state.path
state.password
;
2108 let c = c *. conf.colorscale
in
2112 let scalecolor2 (r, g, b) =
2113 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2116 let docolumns = function
2118 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2119 let rec loop pageno pdimno pdim
y ph pdims
=
2120 if pageno = state.pagecount
2123 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2125 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2126 pdimno+1, pdim
, rest
2130 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2132 (if conf.presentation
2133 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2134 else (if pageno = 0 then 0 else conf.interpagespace
)
2137 a.(pageno) <- (pdimno, x, y, pdim
);
2138 loop (pageno+1) pdimno pdim
(y + h) h pdims
2140 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2141 conf.columns
<- Csingle
a;
2143 | Cmulti
((columns
, coverA
, coverB
), _) ->
2144 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2145 let rec loop pageno pdimno pdim
x y rowh pdims
=
2146 let rec fixrow m
= if m
= pageno then () else
2147 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2150 let y = y + (rowh
- h) / 2 in
2151 a.(m
) <- (pdimno, x, y, pdim
);
2155 if pageno = state.pagecount
2156 then fixrow (((pageno - 1) / columns
) * columns
)
2158 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2160 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2161 pdimno+1, pdim
, rest
2166 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2168 let x = (wadjsb state.winw
- w) / 2 in
2170 if conf.presentation
then calcips h else conf.interpagespace
in
2171 x, y + ips + rowh
, h
2174 if (pageno - coverA
) mod columns
= 0
2176 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2178 if conf.presentation
2180 let ips = calcips h in
2181 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2183 y + (if pageno = 0 then 0 else conf.interpagespace
)
2187 else x, y, max rowh
h
2191 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2194 if pageno = columns
&& conf.presentation
2196 let ips = calcips rowh
in
2197 for i
= 0 to pred columns
2199 let (pdimno, x, y, pdim
) = a.(i
) in
2200 a.(i
) <- (pdimno, x, y+ips, pdim
)
2206 fixrow (pageno - columns
);
2211 a.(pageno) <- (pdimno, x, y, pdim
);
2212 let x = x + w + xoff
*2 + conf.interpagespace
in
2213 loop (pageno+1) pdimno pdim
x y rowh' pdims
2215 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2216 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2219 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2220 let rec loop pageno pdimno pdim
y pdims
=
2221 if pageno = state.pagecount
2224 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2226 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2227 pdimno+1, pdim
, rest
2232 let rec loop1 n x y =
2233 if n = c then y else (
2234 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2235 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2238 let y = loop1 0 0 y in
2239 loop (pageno+1) pdimno pdim
y pdims
2241 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2242 conf.columns
<- Csplit
(c, a);
2246 docolumns conf.columns
;
2247 state.maxy
<- calcheight ();
2248 if state.reprf
== noreprf
2250 match state.mode
with
2251 | Birdseye
(_, _, pageno, _, _) ->
2252 let y, h = getpageyh pageno in
2253 let top = (state.winh
- h) / 2 in
2254 gotoy (max
0 (y - top))
2255 | _ -> gotoanchor state.anchor
2259 state.reprf
<- noreprf;
2264 GlDraw.viewport
0 0 w h;
2265 let firsttime = state.geomcmds
== firstgeomcmds in
2266 if not
firsttime && nogeomcmds state.geomcmds
2267 then state.anchor <- getanchor ();
2270 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2273 setfontsize fstate.fontsize
;
2274 GlMat.mode `modelview
;
2275 GlMat.load_identity
();
2277 GlMat.mode `projection
;
2278 GlMat.load_identity
();
2279 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2280 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2281 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2286 else float state.x /. float state.w
2288 invalidate "geometry"
2292 then state.x <- truncate
(relx *. float w);
2294 match conf.columns
with
2296 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2297 | Csplit
(c, _) -> w * c
2299 wcmd "geometry %d %d %d"
2300 w (stateh h) (FMTE.to_int conf.fitmodel
)
2305 let len = String.length
state.text in
2308 match state.mode
with
2309 | Textentry
_ | View
| LinkNav
_ ->
2310 let h, _, _ = state.uioh#scrollpw
in
2316 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2317 (x+.w, float (state.winh
- hscrollh))
2320 let w = float (wadjsb state.winw
- 1) in
2321 if state.progress
>= 0.0 && state.progress
< 1.0
2323 GlDraw.color
(0.3, 0.3, 0.3);
2324 let w1 = w *. state.progress
in
2326 GlDraw.color
(0.0, 0.0, 0.0);
2330 GlDraw.color
(0.0, 0.0, 0.0);
2334 GlDraw.color
(1.0, 1.0, 1.0);
2335 drawstring fstate.fontsize
2336 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2339 match state.mode
with
2340 | Textentry
((prefix
, text, _, _, _, _), _) ->
2344 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2346 Printf.sprintf
"%s%s_" prefix
text
2355 if not
(istextentry state.mode
) && state.uioh#eformsgs
2357 let s1 = "(press 'e' to review error messasges)" in
2358 if nonemptystr
s then s ^
" " ^
s1 else s1
2368 let len = Queue.length
state.tilelru
in
2370 match state.throttle
with
2373 then preloadlayout state.y
2375 | Some
(layout, _, _) ->
2379 if state.memused
<= conf.memlimit
2384 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2385 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2386 let (_, pw, ph
, _) = getpagedim n in
2389 && colorspace
= conf.colorspace
2390 && angle
= conf.angle
2394 let x = col*conf.tilew
2395 and y = row*conf.tileh
in
2396 tilevisible (Lazy.force_val
layout) n x y
2398 then Queue.push lruitem
state.tilelru
2401 wcmd "freetile %s" p
;
2402 state.memused
<- state.memused
- s;
2403 state.uioh#infochanged Memused
;
2404 Hashtbl.remove
state.tilemap k
;
2412 let logcurrently = function
2413 | Idle
-> dolog
"Idle"
2414 | Loading
(l, gen
) ->
2415 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2416 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2418 "Tiling %d[%d,%d] page=%s cs=%s angle"
2419 l.pageno col row pageopaque
2420 (CSTE.to_string colorspace
)
2422 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2423 angle gen
conf.angle
state.gen
2425 conf.tilew
conf.tileh
2432 let r = Str.regexp
" " in
2433 fun s -> Str.bounded_split
r s 2;
2436 let onpagerect pageno f =
2438 match conf.columns
with
2439 | Cmulti
(_, b) -> b
2441 | Csplit
(_, b) -> b
2443 if pageno >= 0 && pageno < Array.length
b
2445 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2449 let gotopagexy1 pageno x y =
2450 let _,w1,h1
,leftx
= getpagedim pageno in
2451 let top = y /. (float h1
) in
2452 let left = x /. (float w1) in
2453 let py, w, h = getpageywh pageno in
2454 let wh = state.winh
- hscrollh () in
2455 let x = left *. (float w) in
2456 let x = leftx
+ state.x + truncate
x in
2458 if x < 0 || x >= wadjsb state.winw
2462 let pdy = truncate
(top *. float h) in
2463 let y'
= py + pdy in
2464 let dy = y'
- state.y in
2466 if x != state.x || not
(dy > 0 && dy < wh)
2468 if conf.presentation
2470 if abs
(py - y'
) > wh
2477 if state.x != sx || state.y != sy
2482 let ww = wadjsb state.winw
in
2484 and qy
= pdy / wh in
2486 and y = py + qy
* wh in
2487 let x = if -x + ww > w1 then -(w1-ww) else x
2488 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2490 if conf.presentation
2492 if abs
(py - y'
) > wh
2502 gotoy_and_clear_text y;
2504 else gotoy_and_clear_text state.y;
2507 let gotopagexy pageno x y =
2508 match state.mode
with
2509 | Birdseye
_ -> gotopage pageno 0.0
2510 | _ -> gotopagexy1 pageno x y
2514 (* dolog "%S" cmds; *)
2515 let cl = splitatspace cmds
in
2517 try Scanf.sscanf
s fmt
f
2519 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2524 state.uioh#infochanged Pdim
;
2527 | "clearrects" :: [] ->
2528 state.rects
<- state.rects1
;
2529 G.postRedisplay "clearrects";
2531 | "continue" :: args :: [] ->
2532 let n = scan args "%u" (fun n -> n) in
2533 state.pagecount
<- n;
2534 begin match state.currently
with
2536 state.currently
<- Idle
;
2537 state.outlines
<- Array.of_list
(List.rev
l)
2541 let cur, cmds
= state.geomcmds
in
2543 then failwith
"umpossible";
2545 begin match List.rev cmds
with
2547 state.geomcmds
<- "", [];
2551 state.geomcmds
<- s, List.rev rest
;
2553 if conf.maxwait
= None
&& not
!wtmode
2554 then G.postRedisplay "continue";
2556 | "title" :: args :: [] ->
2559 | "msg" :: args :: [] ->
2562 | "vmsg" :: args :: [] ->
2564 then showtext ' '
args
2566 | "emsg" :: args :: [] ->
2567 Buffer.add_string
state.errmsgs
args;
2568 state.newerrmsgs
<- true;
2569 G.postRedisplay "error message"
2571 | "progress" :: args :: [] ->
2572 let progress, text =
2575 f, String.sub
args pos
(String.length
args - pos
))
2578 state.progress <- progress;
2579 G.postRedisplay "progress"
2581 | "firstmatch" :: args :: [] ->
2582 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2583 scan args "%u %d %f %f %f %f %f %f %f %f"
2584 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2585 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2587 let y = (getpagey pageno) + truncate
y0 in
2590 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2592 | "match" :: args :: [] ->
2593 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2594 scan args "%u %d %f %f %f %f %f %f %f %f"
2595 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2596 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2599 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2601 | "page" :: args :: [] ->
2602 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2603 begin match state.currently
with
2604 | Loading
(l, gen
) ->
2605 vlog "page %d took %f sec" l.pageno t
;
2606 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2607 begin match state.throttle
with
2609 let preloadedpages =
2611 then preloadlayout state.y
2616 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2617 IntSet.empty
preloadedpages
2620 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2621 if not
(IntSet.mem
pageno set)
2623 wcmd "freepage %s" opaque
;
2629 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2632 state.currently
<- Idle
;
2635 tilepage l.pageno pageopaque state.layout;
2637 load preloadedpages;
2638 if pagevisible state.layout l.pageno
2639 && layoutready state.layout
2640 then G.postRedisplay "page";
2643 | Some
(layout, _, _) ->
2644 state.currently
<- Idle
;
2645 tilepage l.pageno pageopaque layout;
2650 dolog
"Inconsistent loading state";
2651 logcurrently state.currently
;
2655 | "tile" :: args :: [] ->
2656 let (x, y, opaque
, size
, t
) =
2657 scan args "%u %u %s %u %f"
2658 (fun x y p size t
-> (x, y, p
, size
, t
))
2660 begin match state.currently
with
2661 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2662 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2665 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2667 wcmd "freetile %s" opaque
;
2668 state.currently
<- Idle
;
2672 puttileopaque l col row gen cs angle opaque size t
;
2673 state.memused
<- state.memused
+ size
;
2674 state.uioh#infochanged Memused
;
2676 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2677 opaque
, size
) state.tilelru
;
2680 match state.throttle
with
2681 | None
-> state.layout
2682 | Some
(layout, _, _) -> layout
2685 state.currently
<- Idle
;
2687 && conf.colorspace
= cs
2688 && conf.angle
= angle
2689 && tilevisible layout l.pageno x y
2690 then conttiling l.pageno pageopaque;
2692 begin match state.throttle
with
2694 preload state.layout;
2696 && conf.colorspace
= cs
2697 && conf.angle
= angle
2698 && tilevisible state.layout l.pageno x y
2699 && (not
!wtmode || layoutready state.layout)
2700 then G.postRedisplay "tile nothrottle";
2702 | Some
(layout, y, _) ->
2703 let ready = layoutready layout in
2707 state.layout <- layout;
2708 state.throttle
<- None
;
2709 G.postRedisplay "throttle";
2716 dolog
"Inconsistent tiling state";
2717 logcurrently state.currently
;
2721 | "pdim" :: args :: [] ->
2722 let (n, w, h, _) as pdim
=
2723 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2726 match conf.fitmodel
, conf.columns
with
2727 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2730 state.uioh#infochanged Pdim
;
2731 state.pdims
<- pdim :: state.pdims
2733 | "o" :: args :: [] ->
2734 let (l, n, t
, h, pos
) =
2735 scan args "%u %u %d %u %n"
2736 (fun l n t
h pos
-> l, n, t
, h, pos
)
2738 let s = String.sub
args pos
(String.length
args - pos
) in
2739 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2740 begin match state.currently
with
2741 | Outlining outlines
->
2742 state.currently
<- Outlining
(outline :: outlines
)
2744 state.currently
<- Outlining
[outline]
2746 dolog
"invalid outlining state";
2747 logcurrently currently
2750 | "a" :: args :: [] ->
2752 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2754 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2756 | "info" :: args :: [] ->
2757 state.docinfo
<- (1, args) :: state.docinfo
2759 | "infoend" :: [] ->
2760 state.uioh#infochanged Docinfo
;
2761 state.docinfo
<- List.rev
state.docinfo
2764 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2769 let action = function
2770 | HCprev
-> cbget cb ~
-1
2771 | HCnext
-> cbget cb
1
2772 | HCfirst
-> cbget cb ~
-(cb
.rc)
2773 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2774 and cancel
() = cb
.rc <- rc
2778 let search pattern forward
=
2779 match conf.columns
with
2781 showtext '
!'
"searching does not work properly in split columns mode"
2783 if nonemptystr pattern
2786 match state.layout with
2789 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2791 wcmd "search %d %d %d %d,%s\000"
2792 (btod conf.icase
) pn py (btod forward
) pattern
;
2795 let intentry text key =
2797 if key >= 32 && key < 127
2803 let text = addchar text c in
2807 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2811 let linknentry text key =
2813 if key >= 32 && key < 127
2819 let text = addchar text c in
2823 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2831 let l = String.length
s in
2832 let rec loop pos
n = if pos
= l then n else
2833 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2834 loop (pos
+1) (n*26 + m)
2837 let rec loop n = function
2840 match getopaque l.pageno with
2841 | None
-> loop n rest
2843 let m = getlinkcount opaque
in
2846 let under = getlink opaque
n in
2849 else loop (n-m) rest
2851 loop n state.layout;
2855 let textentry text key =
2856 if key land 0xff00 = 0xff00
2858 else TEcont
(text ^ toutf8
key)
2861 let reqlayout angle fitmodel
=
2862 match state.throttle
with
2864 if nogeomcmds state.geomcmds
2865 then state.anchor <- getanchor ();
2866 conf.angle
<- angle
mod 360;
2869 match state.mode
with
2870 | LinkNav
_ -> state.mode
<- View
2873 conf.fitmodel
<- fitmodel
;
2874 invalidate "reqlayout"
2876 wcmd "reqlayout %d %d %d"
2877 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2882 let settrim trimmargins trimfuzz
=
2883 if nogeomcmds state.geomcmds
2884 then state.anchor <- getanchor ();
2885 conf.trimmargins
<- trimmargins
;
2886 conf.trimfuzz
<- trimfuzz
;
2887 let x0, y0, x1, y1 = trimfuzz
in
2888 invalidate "settrim"
2890 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2895 match state.throttle
with
2897 let zoom = max
0.0001 zoom in
2898 if zoom <> conf.zoom
2900 state.prevzoom
<- (conf.zoom, state.x);
2902 reshape state.winw
state.winh
;
2903 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2906 | Some
(layout, y, started
) ->
2908 match conf.maxwait
with
2912 let dt = now () -. started
in
2920 let setcolumns mode columns coverA coverB
=
2921 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2925 then showtext '
!'
"split mode doesn't work in bird's eye"
2927 conf.columns
<- Csplit
(-columns
, [||]);
2935 conf.columns
<- Csingle
[||];
2940 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2944 reshape state.winw
state.winh
;
2947 let enterbirdseye () =
2948 let zoom = float conf.thumbw
/. float state.winw
in
2949 let birdseyepageno =
2950 let cy = state.winh
/ 2 in
2954 let rec fold best
= function
2957 let d = cy - (l.pagedispy + l.pagevh/2)
2958 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2959 if abs
d < abs dbest
2966 state.mode
<- Birdseye
(
2967 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2970 conf.presentation
<- false;
2971 conf.interpagespace
<- 10;
2972 conf.hlinks
<- false;
2973 conf.fitmodel
<- FitProportional
;
2975 state.mstate
<- Mnone
;
2976 conf.maxwait
<- None
;
2978 match conf.beyecolumns
with
2981 Cmulti
((c, 0, 0), [||])
2982 | None
-> Csingle
[||]
2984 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2987 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2992 reshape state.winw
state.winh
;
2995 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2997 conf.zoom <- c.zoom;
2998 conf.presentation
<- c.presentation
;
2999 conf.interpagespace
<- c.interpagespace
;
3000 conf.maxwait
<- c.maxwait
;
3001 conf.hlinks
<- c.hlinks
;
3002 conf.fitmodel
<- c.fitmodel
;
3003 conf.beyecolumns
<- (
3004 match conf.columns
with
3005 | Cmulti
((c, _, _), _) -> Some
c
3007 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3010 match c.columns
with
3011 | Cmulti
(c, _) -> Cmulti
(c, [||])
3012 | Csingle
_ -> Csingle
[||]
3013 | Csplit
(c, _) -> Csplit
(c, [||])
3018 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3021 reshape state.winw
state.winh
;
3022 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3025 let togglebirdseye () =
3026 match state.mode
with
3027 | Birdseye vals
-> leavebirdseye vals
true
3028 | View
-> enterbirdseye ()
3032 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3033 let pageno = max
0 (pageno - incr
) in
3034 let rec loop = function
3035 | [] -> gotopage1 pageno 0
3036 | l :: _ when l.pageno = pageno ->
3037 if l.pagedispy >= 0 && l.pagey = 0
3038 then G.postRedisplay "upbirdseye"
3039 else gotopage1 pageno 0
3040 | _ :: rest
-> loop rest
3043 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3046 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3047 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3048 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3049 let rec loop = function
3051 let y, h = getpageyh pageno in
3052 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3054 | l :: _ when l.pageno = pageno ->
3055 if l.pagevh != l.pageh
3056 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3057 else G.postRedisplay "downbirdseye"
3058 | _ :: rest
-> loop rest
3063 let optentry mode
_ key =
3064 let btos b = if b then "on" else "off" in
3065 if key >= 32 && key < 127
3067 let c = Char.chr
key in
3071 try conf.scrollstep
<- int_of_string
s with exc
->
3072 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3074 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3079 conf.autoscrollstep
<- int_of_string
s;
3080 if state.autoscroll
<> None
3081 then state.autoscroll
<- Some
conf.autoscrollstep
3083 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3085 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3090 let n, a, b = multicolumns_of_string s in
3091 setcolumns mode
n a b;
3093 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3095 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3100 let zoom = float (int_of_string
s) /. 100.0 in
3103 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3105 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3110 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3112 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3113 begin match mode
with
3115 leavebirdseye beye
false;
3120 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3122 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3127 Some
(int_of_string
s)
3129 state.text <- Printf.sprintf
"bad integer `%s': %s"
3133 | Some angle
-> reqlayout angle
conf.fitmodel
3136 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3139 conf.icase
<- not
conf.icase
;
3140 TEdone
("case insensitive search " ^
(btos conf.icase
))
3143 conf.preload <- not
conf.preload;
3145 TEdone
("preload " ^
(btos conf.preload))
3148 conf.verbose
<- not
conf.verbose
;
3149 TEdone
("verbose " ^
(btos conf.verbose
))
3152 conf.debug
<- not
conf.debug
;
3153 TEdone
("debug " ^
(btos conf.debug
))
3156 conf.maxhfit
<- not
conf.maxhfit
;
3157 state.maxy
<- calcheight ();
3158 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3161 conf.crophack
<- not
conf.crophack
;
3162 TEdone
("crophack " ^
btos conf.crophack
)
3166 match conf.maxwait
with
3168 conf.maxwait
<- Some infinity
;
3169 "always wait for page to complete"
3171 conf.maxwait
<- None
;
3172 "show placeholder if page is not ready"
3177 conf.underinfo
<- not
conf.underinfo
;
3178 TEdone
("underinfo " ^
btos conf.underinfo
)
3181 conf.savebmarks
<- not
conf.savebmarks
;
3182 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3188 match state.layout with
3193 conf.interpagespace
<- int_of_string
s;
3194 docolumns conf.columns
;
3195 state.maxy
<- calcheight ();
3196 let y = getpagey pageno in
3199 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3201 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3205 match conf.fitmodel
with
3206 | FitProportional
-> FitWidth
3207 | _ -> FitProportional
3209 reqlayout conf.angle
fm;
3210 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3213 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3214 TEdone
("trim margins " ^
btos conf.trimmargins
)
3217 conf.invert
<- not
conf.invert
;
3218 TEdone
("invert colors " ^
btos conf.invert
)
3222 cbput state.hists
.sel
s;
3225 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3226 textentry, ondone, true)
3230 then conf.pax
<- Some
(ref (0.0, 0, 0))
3231 else conf.pax
<- None
;
3232 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3235 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3241 class type lvsource
= object
3242 method getitemcount
: int
3243 method getitem
: int -> (string * int)
3244 method hasaction
: int -> bool
3253 method getactive
: int
3254 method getfirst
: int
3255 method getqsearch
: string
3256 method setqsearch
: string -> unit
3260 class virtual lvsourcebase
= object
3261 val mutable m_active
= 0
3262 val mutable m_first
= 0
3263 val mutable m_qsearch
= ""
3264 val mutable m_pan
= 0
3265 method getactive
= m_active
3266 method getfirst
= m_first
3267 method getqsearch
= m_qsearch
3268 method getpan
= m_pan
3269 method setqsearch
s = m_qsearch
<- s
3272 let withoutlastutf8 s =
3273 let len = String.length
s in
3281 let b = Char.code
s.[pos
] in
3282 if b land 0b11000000 = 0b11000000
3287 if Char.code
s.[len-1] land 0x80 = 0
3291 String.sub
s 0 first;
3294 let textentrykeyboard
3295 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3297 if key >= 0xffb0 && key <= 0xffb9
3298 then key - 0xffb0 + 48 else key
3301 state.mode
<- Textentry
(te
, onleave
);
3304 G.postRedisplay "textentrykeyboard enttext";
3306 let histaction cmd
=
3309 | Some
(action, _) ->
3310 state.mode
<- Textentry
(
3311 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3313 G.postRedisplay "textentry histaction"
3316 | 0xff08 -> (* backspace *)
3317 let s = withoutlastutf8 text in
3318 let len = String.length
s in
3319 if cancelonempty
&& len = 0
3322 G.postRedisplay "textentrykeyboard after cancel";
3325 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3328 | 0xff0d | 0xff8d -> (* (kp) enter *)
3331 G.postRedisplay "textentrykeyboard after confirm"
3333 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3334 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3335 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3336 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3338 | 0xff1b -> (* escape*)
3341 begin match opthist
with
3343 | Some
(_, onhistcancel
) -> onhistcancel
()
3347 G.postRedisplay "textentrykeyboard after cancel2"
3350 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3353 | 0xff9f | 0xffff -> () (* delete *)
3356 && key land 0xff00 != 0xff00 (* keyboard *)
3357 && key land 0xfe00 != 0xfe00 (* xkb *)
3358 && key land 0xfd00 != 0xfd00 (* 3270 *)
3360 begin match onkey
text key with
3364 G.postRedisplay "textentrykeyboard after confirm2";
3367 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3371 G.postRedisplay "textentrykeyboard after cancel3"
3374 state.mode
<- Textentry
(te
, onleave
);
3375 G.postRedisplay "textentrykeyboard switch";
3379 vlog "unhandled key %s" (Wsi.keyname
key)
3382 let firstof first active
=
3383 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3384 then max
0 (active
- (fstate.maxrows
/2))
3388 let calcfirst first active
=
3391 let rows = active
- first in
3392 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3396 let scrollph y maxy
=
3397 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3398 let sh = float state.winh
/. sh in
3399 let sh = max
sh (float conf.scrollh
) in
3401 let percent = float y /. float maxy
in
3402 let position = (float state.winh
-. sh) *. percent in
3405 if position +. sh > float state.winh
3406 then float state.winh
-. sh
3412 let coe s = (s :> uioh
);;
3414 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3416 val m_pan
= source#getpan
3417 val m_first
= source#getfirst
3418 val m_active
= source#getactive
3419 val m_qsearch
= source#getqsearch
3420 val m_prev_uioh
= state.uioh
3422 method private elemunder
y =
3423 let n = y / (fstate.fontsize
+1) in
3424 if m_first
+ n < source#getitemcount
3426 if source#hasaction
(m_first
+ n)
3427 then Some
(m_first
+ n)
3434 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3435 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3436 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3437 GlDraw.color
(1., 1., 1.);
3438 Gl.enable `texture_2d
;
3439 let fs = fstate.fontsize
in
3441 let ww = fstate.wwidth
in
3442 let tabw = 30.0*.ww in
3443 let itemcount = source#getitemcount
in
3445 if (row - m_first
) > fstate.maxrows
3448 if row >= 0 && row < itemcount
3450 let (s, level
) = source#getitem
row in
3451 let y = (row - m_first
) * nfs in
3452 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3455 Gl.disable `texture_2d
;
3456 GlDraw.polygon_mode `both `line
;
3457 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3458 GlDraw.color
(1., 1., 1.) ~
alpha;
3459 GlDraw.rect (1., float (y + 1))
3460 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3461 GlDraw.polygon_mode `both `fill
;
3462 GlDraw.color
(1., 1., 1.);
3463 Gl.enable `texture_2d
;
3466 let drawtabularstring s =
3467 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3470 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3473 let len = String.length
s - tabpos - 1 in
3474 let s1 = String.sub
s 0 tabpos
3475 and s2
= String.sub
s (tabpos + 1) len in
3476 let nx = drawstr x s1 in
3478 let x = x +. (max
tabw sw) in
3485 let _ = drawtabularstring s in
3492 Gl.disable `texture_2d
;
3494 method updownlevel incr
=
3495 let len = source#getitemcount
in
3497 if m_active
>= 0 && m_active
< len
3498 then snd
(source#getitem m_active
)
3502 if i
= len then i
-1 else if i
= -1 then 0 else
3503 let _, l = source#getitem i
in
3504 if l != curlevel then i
else flow (i
+incr
)
3506 let active = flow m_active
in
3507 let first = calcfirst m_first
active in
3508 G.postRedisplay "outline updownlevel";
3509 {< m_active
= active; m_first
= first >}
3511 method private key1
key mask
=
3512 let set1 active first qsearch
=
3513 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3515 let search active pattern incr
=
3516 let active = if active = -1 then m_first
else active in
3519 if n >= 0 && n < source#getitemcount
3521 let s, _ = source#getitem
n in
3523 (try ignore
(Str.search_forward
re s 0); true
3524 with Not_found
-> false)
3526 else loop (n + incr
)
3533 let re = Str.regexp_case_fold pattern
in
3539 let itemcount = source#getitemcount
in
3540 let find start incr
=
3542 if i
= -1 || i
= itemcount
3545 if source#hasaction i
3547 else find (i
+ incr
)
3552 let set active first =
3553 let first = bound first 0 (itemcount - fstate.maxrows
) in
3555 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3558 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3560 let incr1 = if incr
> 0 then 1 else -1 in
3561 if isvisible m_first m_active
3564 let next = m_active
+ incr
in
3566 if next < 0 || next >= itemcount
3568 else find next incr1
3570 if abs
(m_active
- next) > fstate.maxrows
3576 let first = m_first
+ incr
in
3577 let first = bound first 0 (itemcount - fstate.maxrows
) in
3579 let next = m_active
+ incr
in
3580 let next = bound next 0 (itemcount - 1) in
3587 if isvisible first next
3594 let first = min
next m_first
in
3596 if abs
(next - first) > fstate.maxrows
3602 let first = m_first
+ incr
in
3603 let first = bound first 0 (itemcount - 1) in
3605 let next = m_active
+ incr
in
3606 let next = bound next 0 (itemcount - 1) in
3607 let next = find next incr1 in
3609 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3611 let active = if m_active
= -1 then next else m_active
in
3616 if isvisible first active
3622 G.postRedisplay "listview navigate";
3626 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3627 let incr = if key = 0x72 then -1 else 1 in
3629 match search (m_active
+ incr) m_qsearch
incr with
3631 state.text <- m_qsearch ^
" [not found]";
3634 state.text <- m_qsearch
;
3635 active, firstof m_first
active
3637 G.postRedisplay "listview ctrl-r/s";
3638 set1 active first m_qsearch
;
3640 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3641 if m_active
>= 0 && m_active
< source#getitemcount
3643 let s, _ = source#getitem m_active
in
3648 | 0xff08 -> (* backspace *)
3649 if emptystr m_qsearch
3652 let qsearch = withoutlastutf8 m_qsearch
in
3656 G.postRedisplay "listview empty qsearch";
3657 set1 m_active m_first
"";
3661 match search m_active
qsearch ~
-1 with
3663 state.text <- qsearch ^
" [not found]";
3666 state.text <- qsearch;
3667 active, firstof m_first
active
3669 G.postRedisplay "listview backspace qsearch";
3670 set1 active first qsearch
3673 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3674 let pattern = m_qsearch ^ toutf8
key in
3676 match search m_active
pattern 1 with
3678 state.text <- pattern ^
" [not found]";
3681 state.text <- pattern;
3682 active, firstof m_first
active
3684 G.postRedisplay "listview qsearch add";
3685 set1 active first pattern;
3687 | 0xff1b -> (* escape *)
3689 if emptystr m_qsearch
3691 G.postRedisplay "list view escape";
3694 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3696 | None
-> m_prev_uioh
3701 G.postRedisplay "list view kill qsearch";
3702 source#setqsearch
"";
3703 coe {< m_qsearch
= "" >}
3706 | 0xff0d | 0xff8d -> (* (kp) enter *)
3708 let self = {< m_qsearch
= "" >} in
3709 source#setqsearch
"";
3711 G.postRedisplay "listview enter";
3712 if m_active
>= 0 && m_active
< source#getitemcount
3714 source#exit
(coe self) false m_active m_first m_pan
"";
3717 source#exit
(coe self) true m_active m_first m_pan
"";
3720 begin match opt with
3721 | None
-> m_prev_uioh
3725 | 0xff9f | 0xffff -> (* (kp) delete *)
3728 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3729 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3730 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3731 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3733 | 0xff53 | 0xff98 -> (* (kp) right *)
3735 G.postRedisplay "listview right";
3736 coe {< m_pan
= m_pan
- 1 >}
3738 | 0xff51 | 0xff96 -> (* (kp) left *)
3740 G.postRedisplay "listview left";
3741 coe {< m_pan
= m_pan
+ 1 >}
3743 | 0xff50 | 0xff95 -> (* (kp) home *)
3744 let active = find 0 1 in
3745 G.postRedisplay "listview home";
3748 | 0xff57 | 0xff9c -> (* (kp) end *)
3749 let first = max
0 (itemcount - fstate.maxrows
) in
3750 let active = find (itemcount - 1) ~
-1 in
3751 G.postRedisplay "listview end";
3754 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3758 dolog
"listview unknown key %#x" key; coe self
3760 method key key mask
=
3761 match state.mode
with
3762 | Textentry te
-> textentrykeyboard key mask te
; coe self
3763 | _ -> self#key1
key mask
3765 method button button down
x y _ =
3768 | 1 when x > state.winw
- conf.scrollbw
->
3769 G.postRedisplay "listview scroll";
3772 let _, position, sh = self#
scrollph in
3773 if y > truncate
position && y < truncate
(position +. sh)
3775 state.mstate
<- Mscrolly
;
3779 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3780 let first = truncate
(s *. float source#getitemcount
) in
3781 let first = min source#getitemcount
first in
3782 Some
(coe {< m_first
= first; m_active
= first >})
3784 state.mstate
<- Mnone
;
3787 | 1 when not down
->
3788 begin match self#elemunder
y with
3790 G.postRedisplay "listview click";
3792 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3796 | n when (n == 4 || n == 5) && not down
->
3797 let len = source#getitemcount
in
3799 if n = 5 && m_first
+ fstate.maxrows
>= len
3803 let first = m_first
+ (if n == 4 then -1 else 1) in
3804 bound first 0 (len - 1)
3806 G.postRedisplay "listview wheel";
3807 Some
(coe {< m_first
= first >})
3808 | n when (n = 6 || n = 7) && not down
->
3809 let inc = if n = 7 then -1 else 1 in
3810 G.postRedisplay "listview hwheel";
3811 Some
(coe {< m_pan
= m_pan
+ inc >})
3816 | None
-> m_prev_uioh
3820 match state.mstate
with
3822 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3823 let first = truncate
(s *. float source#getitemcount
) in
3824 let first = min source#getitemcount
first in
3825 G.postRedisplay "listview motion";
3826 coe {< m_first
= first; m_active
= first >}
3829 method pmotion
x y =
3830 if x < state.winw
- conf.scrollbw
3833 match self#elemunder
y with
3834 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3835 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3839 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3844 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3848 method infochanged
_ = ()
3850 method scrollpw
= (0, 0.0, 0.0)
3852 let nfs = fstate.fontsize
+ 1 in
3853 let y = m_first
* nfs in
3854 let itemcount = source#getitemcount
in
3855 let maxi = max
0 (itemcount - fstate.maxrows
) in
3856 let maxy = maxi * nfs in
3857 let p, h = scrollph y maxy in
3860 method modehash
= modehash
3861 method eformsgs
= false
3864 class outlinelistview ~source
=
3865 let settext autonarrow
s =
3867 then state.text <- "[" ^
s ^
"]"
3868 else state.text <- s
3872 ~source
:(source
:> lvsource
)
3874 ~modehash
:(findkeyhash conf "outline")
3877 val m_autonarrow
= false
3879 method key key mask
=
3881 if emptystr
state.text
3883 else fstate.maxrows - 2
3885 let calcfirst first active =
3888 let rows = active - first in
3889 if rows > maxrows then active - maxrows else first
3893 let active = m_active
+ incr in
3894 let active = bound active 0 (source#getitemcount
- 1) in
3895 let first = calcfirst m_first
active in
3896 G.postRedisplay "outline navigate";
3897 coe {< m_active
= active; m_first
= first >}
3899 let navscroll first =
3901 let dist = m_active
- first in
3907 else first + maxrows
3910 G.postRedisplay "outline navscroll";
3911 coe {< m_first
= first; m_active
= active >}
3913 let ctrl = Wsi.withctrl mask
in
3915 | 97 when ctrl -> (* ctrl-a *)
3917 then source#denarrow
3918 else source#narrow m_qsearch
;
3919 settext (not m_autonarrow
) m_qsearch
;
3920 G.postRedisplay "toggle auto narrowing";
3921 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3923 | 110 when ctrl -> (* ctrl-n *)
3924 source#narrow m_qsearch
;
3925 G.postRedisplay "outline ctrl-n";
3926 coe {< m_first
= 0; m_active
= 0 >}
3928 | 117 when ctrl -> (* ctrl-u *)
3930 G.postRedisplay "outline ctrl-u";
3931 settext m_autonarrow
"";
3932 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3934 | 108 when ctrl -> (* ctrl-l *)
3935 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3936 G.postRedisplay "outline ctrl-l";
3937 coe {< m_first
= first >}
3939 | 0xff1b when m_autonarrow
-> (* escape *)
3940 let o = super#
key key mask
in
3941 if nonemptystr m_qsearch
3942 then settext true "";
3945 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3946 let pattern = m_qsearch ^ toutf8
key in
3947 G.postRedisplay "outlinelistview autonarrow add";
3948 source#narrow
pattern;
3949 settext true pattern;
3950 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3952 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3953 if emptystr m_qsearch
3956 let pattern = withoutlastutf8 m_qsearch
in
3957 G.postRedisplay "outlinelistview backspace autonarrow";
3959 source#narrow
pattern;
3960 settext true pattern;
3961 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3963 | 0xff9f | 0xffff -> (* (kp) delete *)
3964 source#remove m_active
;
3965 G.postRedisplay "outline delete";
3966 let active = max
0 (m_active
-1) in
3967 coe {< m_first
= firstof m_first
active;
3968 m_active
= active >}
3970 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3971 navscroll (max
0 (m_first
- 1))
3973 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3974 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3976 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3977 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3978 | 0xff55 | 0xff9a -> (* (kp) prior *)
3979 navigate ~
-(fstate.maxrows)
3980 | 0xff56 | 0xff9b -> (* (kp) next *)
3981 navigate fstate.maxrows
3983 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3987 G.postRedisplay "outline ctrl right";
3988 {< m_pan
= m_pan
+ 1 >}
3990 else self#updownlevel
1
3994 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3998 G.postRedisplay "outline ctrl left";
3999 {< m_pan
= m_pan
- 1 >}
4001 else self#updownlevel ~
-1
4005 | 0xff50 | 0xff95 -> (* (kp) home *)
4006 G.postRedisplay "outline home";
4007 coe {< m_first
= 0; m_active
= 0 >}
4009 | 0xff57 | 0xff9c -> (* (kp) end *)
4010 let active = source#getitemcount
- 1 in
4011 let first = max
0 (active - fstate.maxrows) in
4012 G.postRedisplay "outline end";
4013 coe {< m_active
= active; m_first
= first >}
4015 | _ -> super#
key key mask
4018 let outlinesource usebookmarks
=
4021 inherit lvsourcebase
4022 val mutable m_items
= empty
4023 val mutable m_orig_items
= empty
4024 val mutable m_narrow_pattern
= ""
4025 val mutable m_hadremovals
= false
4027 method getitemcount
=
4028 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4031 if n == Array.length m_items
&& m_hadremovals
4033 ("[Confirm removal]", 0)
4035 let s, n, _ = m_items
.(n) in
4038 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4039 ignore
(uioh
, first, qsearch);
4040 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4042 if emptystr m_narrow_pattern
4048 if not
confrimremoval
4050 let _, _, ((pageno, y, _) as anchor) = m_items
.(active) in
4052 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4058 state.bookmarks
<- Array.to_list m_items
;
4059 m_orig_items
<- m_items
;
4062 else m_items
<- items;
4066 method hasaction
_ = true
4069 if Array.length m_items
!= Array.length m_orig_items
4070 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
4073 method narrow
pattern =
4074 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4078 let rec loop accu n =
4081 m_narrow_pattern
<- pattern;
4082 m_items
<- Array.of_list
accu
4085 let (s, _, _) as o = m_items
.(n) in
4087 if (try ignore
(Str.search_forward
re s 0); true
4088 with Not_found
-> false)
4094 loop [] (Array.length m_items
- 1)
4099 then Array.of_list
state.bookmarks
4102 m_items
<- m_orig_items
4107 if m >= 0 && m < Array.length m_items
4109 m_hadremovals
<- true;
4110 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4111 let n = if n >= m then n+1 else n in
4116 method reset
anchor items =
4117 m_hadremovals
<- false;
4118 if m_orig_items
== empty
4120 m_orig_items
<- items;
4121 if emptystr m_narrow_pattern
4122 then m_items
<- items;
4124 let rely = getanchory anchor in
4126 let rec loop n best bestd
=
4127 if n = Array.length m_items
4130 let (_, _, anchor) = m_items
.(n) in
4131 let orely = getanchory anchor in
4132 let d = abs
(orely - rely) in
4135 else loop (n+1) best bestd
4140 m_first
<- firstof m_first
active
4144 let enterselector usebookmarks
=
4145 let source = outlinesource usebookmarks
in
4149 then Array.of_list
state.bookmarks
4152 if Array.length
outlines = 0
4154 showtext ' ' errmsg
;
4157 state.text <- source#greetmsg
;
4158 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4159 let anchor = getanchor () in
4160 source#reset
anchor outlines;
4161 state.uioh
<- coe (new outlinelistview ~
source);
4162 G.postRedisplay "enter selector";
4166 let enteroutlinemode =
4167 let f = enterselector false in
4168 fun ()-> f "Document has no outline";
4171 let enterbookmarkmode =
4172 let f = enterselector true in
4173 fun () -> f "Document has no bookmarks (yet)";
4176 let color_of_string s =
4177 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4178 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4182 let color_to_string (r, g, b) =
4183 let r = truncate
(r *. 256.0)
4184 and g = truncate
(g *. 256.0)
4185 and b = truncate
(b *. 256.0) in
4186 Printf.sprintf
"%d/%d/%d" r g b
4189 let irect_of_string s =
4190 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4193 let irect_to_string (x0,y0,x1,y1) =
4194 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4197 let makecheckers () =
4198 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4200 converted by Issac Trotts. July 25, 2002 *)
4201 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4202 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4203 let id = GlTex.gen_texture
() in
4204 GlTex.bind_texture `texture_2d
id;
4205 GlPix.store
(`unpack_alignment
1);
4206 GlTex.image2d
image;
4207 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4208 [ `mag_filter `nearest
; `min_filter `nearest
];
4212 let setcheckers enabled
=
4213 match state.texid
with
4215 if enabled
then state.texid
<- Some
(makecheckers ())
4220 GlTex.delete_texture texid
;
4221 state.texid
<- None
;
4225 let int_of_string_with_suffix s =
4226 let l = String.length
s in
4230 let suffix = Char.lowercase
s.[l-1] in
4232 | 'k'
-> String.sub
s 0 (l-1), 10
4233 | '
m'
-> String.sub
s 0 (l-1), 20
4234 | '
g'
-> String.sub
s 0 (l-1), 30
4238 let n = int_of_string
s1 in
4239 let m = n lsl shift
in
4241 then raise
(Failure
"value too large")
4245 let string_with_suffix_of_int n =
4250 if n land ((1 lsl 30) - 1) = 0
4253 if n land ((1 lsl 20) - 1) = 0
4256 if n land ((1 lsl 10) - 1) = 0
4263 let h = n mod 1000 in
4266 then string_of_int
h ^
s
4268 let s = Printf.sprintf
"_%03d%s" h s in
4275 let defghyllscroll = (40, 8, 32);;
4276 let ghyllscroll_of_string s =
4277 let (n, a, b) as nab
=
4280 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4282 if n <= a || n <= b || a >= b
4283 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4287 let ghyllscroll_to_string ((n, a, b) as nab
) =
4288 if nab
= defghyllscroll
4290 else Printf.sprintf
"%d,%d,%d" n a b;
4293 let describe_location () =
4294 let fn = page_of_y state.y in
4295 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4296 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4300 else (100. *. (float state.y /. float maxy))
4304 Printf.sprintf
"page %d of %d [%.2f%%]"
4305 (fn+1) state.pagecount
percent
4308 "pages %d-%d of %d [%.2f%%]"
4309 (fn+1) (ln+1) state.pagecount
percent
4312 let setpresentationmode v
=
4313 let n = page_of_y state.y in
4314 state.anchor <- (n, 0.0, 1.0);
4315 conf.presentation
<- v
;
4316 if conf.fitmodel
= FitPage
4317 then reqlayout conf.angle
conf.fitmodel
;
4322 let btos b = if b then "\xe2\x88\x9a" else "" in
4323 let showextended = ref false in
4324 let leave mode
= function
4325 | Confirm
-> state.mode
<- mode
4326 | Cancel
-> state.mode
<- mode
in
4329 val mutable m_first_time
= true
4330 val mutable m_l
= []
4331 val mutable m_a
= [||]
4332 val mutable m_prev_uioh
= nouioh
4333 val mutable m_prev_mode
= View
4335 inherit lvsourcebase
4337 method reset prev_mode prev_uioh
=
4338 m_a
<- Array.of_list
(List.rev m_l
);
4340 m_prev_mode
<- prev_mode
;
4341 m_prev_uioh
<- prev_uioh
;
4345 if n >= Array.length m_a
4349 | _, _, _, Action
_ -> m_active
<- n
4353 m_first_time
<- false;
4356 method int name get
set =
4358 (name, `
int get
, 1, Action
(
4361 try set (int_of_string
s)
4363 state.text <- Printf.sprintf
"bad integer `%s': %s"
4367 let te = name ^
": ", "", None
, intentry, ondone, true in
4368 state.mode
<- Textentry
(te, leave m_prev_mode
);
4372 method int_with_suffix
name get
set =
4374 (name, `intws get
, 1, Action
(
4377 try set (int_of_string_with_suffix s)
4379 state.text <- Printf.sprintf
"bad integer `%s': %s"
4384 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4386 state.mode
<- Textentry
(te, leave m_prev_mode
);
4390 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4392 (name, `
bool (btos, get
), offset
, Action
(
4399 method color
name get
set =
4401 (name, `color get
, 1, Action
(
4403 let invalid = (nan
, nan
, nan
) in
4406 try color_of_string s
4408 state.text <- Printf.sprintf
"bad color `%s': %s"
4415 let te = name ^
": ", "", None
, textentry, ondone, true in
4416 state.text <- color_to_string (get
());
4417 state.mode
<- Textentry
(te, leave m_prev_mode
);
4421 method string name get
set =
4423 (name, `
string get
, 1, Action
(
4425 let ondone s = set s in
4426 let te = name ^
": ", "", None
, textentry, ondone, true in
4427 state.mode
<- Textentry
(te, leave m_prev_mode
);
4431 method colorspace
name get
set =
4433 (name, `
string get
, 1, Action
(
4437 inherit lvsourcebase
4440 m_active
<- CSTE.to_int conf.colorspace
;
4443 method getitemcount
=
4444 Array.length
CSTE.names
4447 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4448 ignore
(uioh
, first, pan
, qsearch);
4449 if not cancel
then set active;
4451 method hasaction
_ = true
4455 let modehash = findkeyhash conf "info" in
4456 coe (new listview ~
source ~trusted
:true ~
modehash)
4459 method paxmark
name get
set =
4461 (name, `
string get
, 1, Action
(
4465 inherit lvsourcebase
4468 m_active
<- MTE.to_int conf.paxmark
;
4471 method getitemcount
= Array.length
MTE.names
4472 method getitem
n = (MTE.names.(n), 0)
4473 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4474 ignore
(uioh
, first, pan
, qsearch);
4475 if not cancel
then set active;
4477 method hasaction
_ = true
4481 let modehash = findkeyhash conf "info" in
4482 coe (new listview ~
source ~trusted
:true ~
modehash)
4485 method fitmodel
name get
set =
4487 (name, `
string get
, 1, Action
(
4491 inherit lvsourcebase
4494 m_active
<- FMTE.to_int conf.fitmodel
;
4497 method getitemcount
= Array.length
FMTE.names
4498 method getitem
n = (FMTE.names.(n), 0)
4499 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4500 ignore
(uioh
, first, pan
, qsearch);
4501 if not cancel
then set active;
4503 method hasaction
_ = true
4507 let modehash = findkeyhash conf "info" in
4508 coe (new listview ~
source ~trusted
:true ~
modehash)
4511 method caption
s offset
=
4512 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4514 method caption2
s f offset
=
4515 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4517 method getitemcount
= Array.length m_a
4520 let tostr = function
4521 | `
int f -> string_of_int
(f ())
4522 | `intws
f -> string_with_suffix_of_int (f ())
4524 | `color
f -> color_to_string (f ())
4525 | `
bool (btos, f) -> btos (f ())
4528 let name, t
, offset
, _ = m_a
.(n) in
4529 ((let s = tostr t
in
4531 then Printf.sprintf
"%s\t%s" name s
4535 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4539 m_qsearch
<- qsearch;
4541 match m_a
.(active) with
4542 | _, _, _, Action
f -> f uioh
4554 method hasaction
n =
4556 | _, _, _, Action
_ -> true
4560 let rec fillsrc prevmode prevuioh
=
4561 let sep () = src#caption
"" 0 in
4562 let colorp name get
set =
4564 (fun () -> color_to_string (get
()))
4567 let c = color_of_string v in
4570 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4573 let oldmode = state.mode
in
4574 let birdseye = isbirdseye state.mode
in
4576 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4578 src#
bool "presentation mode"
4579 (fun () -> conf.presentation
)
4580 (fun v -> setpresentationmode v);
4582 src#
bool "ignore case in searches"
4583 (fun () -> conf.icase
)
4584 (fun v -> conf.icase
<- v);
4587 (fun () -> conf.preload)
4588 (fun v -> conf.preload <- v);
4590 src#
bool "highlight links"
4591 (fun () -> conf.hlinks
)
4592 (fun v -> conf.hlinks
<- v);
4594 src#
bool "under info"
4595 (fun () -> conf.underinfo
)
4596 (fun v -> conf.underinfo
<- v);
4598 src#
bool "persistent bookmarks"
4599 (fun () -> conf.savebmarks
)
4600 (fun v -> conf.savebmarks
<- v);
4602 src#fitmodel
"fit model"
4603 (fun () -> FMTE.to_string conf.fitmodel
)
4604 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4606 src#
bool "trim margins"
4607 (fun () -> conf.trimmargins
)
4608 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4610 src#
bool "persistent location"
4611 (fun () -> conf.jumpback
)
4612 (fun v -> conf.jumpback
<- v);
4615 src#
int "inter-page space"
4616 (fun () -> conf.interpagespace
)
4618 conf.interpagespace
<- n;
4619 docolumns conf.columns
;
4621 match state.layout with
4626 state.maxy <- calcheight ();
4627 let y = getpagey pageno in
4632 (fun () -> conf.pagebias
)
4633 (fun v -> conf.pagebias
<- v);
4635 src#
int "scroll step"
4636 (fun () -> conf.scrollstep
)
4637 (fun n -> conf.scrollstep
<- n);
4639 src#
int "horizontal scroll step"
4640 (fun () -> conf.hscrollstep
)
4641 (fun v -> conf.hscrollstep
<- v);
4643 src#
int "auto scroll step"
4645 match state.autoscroll
with
4647 | _ -> conf.autoscrollstep
)
4649 if state.autoscroll
<> None
4650 then state.autoscroll
<- Some
n;
4651 conf.autoscrollstep
<- n);
4654 (fun () -> truncate
(conf.zoom *. 100.))
4655 (fun v -> setzoom ((float v) /. 100.));
4658 (fun () -> conf.angle
)
4659 (fun v -> reqlayout v conf.fitmodel
);
4661 src#
int "scroll bar width"
4662 (fun () -> conf.scrollbw
)
4665 reshape state.winw
state.winh
;
4668 src#
int "scroll handle height"
4669 (fun () -> conf.scrollh
)
4670 (fun v -> conf.scrollh
<- v;);
4672 src#
int "thumbnail width"
4673 (fun () -> conf.thumbw
)
4675 conf.thumbw
<- min
4096 v;
4678 leavebirdseye beye
false;
4683 let mode = state.mode in
4684 src#
string "columns"
4686 match conf.columns
with
4688 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4689 | Csplit
(count
, _) -> "-" ^ string_of_int count
4692 let n, a, b = multicolumns_of_string v in
4693 setcolumns mode n a b);
4696 src#caption
"Pixmap cache" 0;
4697 src#int_with_suffix
"size (advisory)"
4698 (fun () -> conf.memlimit
)
4699 (fun v -> conf.memlimit
<- v);
4702 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4703 (string_with_suffix_of_int state.memused
)
4704 (Hashtbl.length
state.tilemap
)) 1;
4707 src#caption
"Layout" 0;
4708 src#caption2
"Dimension"
4710 Printf.sprintf
"%dx%d (virtual %dx%d)"
4711 state.winw
state.winh
4716 src#caption2
"Position" (fun () ->
4717 Printf.sprintf
"%dx%d" state.x state.y
4720 src#caption2
"Position" (fun () -> describe_location ()) 1
4724 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4725 "Save these parameters as global defaults at exit"
4726 (fun () -> conf.bedefault
)
4727 (fun v -> conf.bedefault
<- v)
4731 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4732 src#
bool ~offset
:0 ~
btos "Extended parameters"
4733 (fun () -> !showextended)
4734 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4738 (fun () -> conf.checkers
)
4739 (fun v -> conf.checkers
<- v; setcheckers v);
4740 src#
bool "update cursor"
4741 (fun () -> conf.updatecurs
)
4742 (fun v -> conf.updatecurs
<- v);
4744 (fun () -> conf.verbose
)
4745 (fun v -> conf.verbose
<- v);
4746 src#
bool "invert colors"
4747 (fun () -> conf.invert
)
4748 (fun v -> conf.invert
<- v);
4750 (fun () -> conf.maxhfit
)
4751 (fun v -> conf.maxhfit
<- v);
4752 src#
bool "redirect stderr"
4753 (fun () -> conf.redirectstderr)
4754 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4756 (fun () -> conf.pax
!= None
)
4759 then conf.pax
<- Some
(ref (now (), 0, 0))
4760 else conf.pax
<- None
);
4761 src#
string "uri launcher"
4762 (fun () -> conf.urilauncher
)
4763 (fun v -> conf.urilauncher
<- v);
4764 src#
string "path launcher"
4765 (fun () -> conf.pathlauncher
)
4766 (fun v -> conf.pathlauncher
<- v);
4767 src#
string "tile size"
4768 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4771 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4772 conf.tilew
<- max
64 w;
4773 conf.tileh
<- max
64 h;
4776 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4779 src#
int "texture count"
4780 (fun () -> conf.texcount
)
4783 then conf.texcount
<- v
4784 else showtext '
!'
" Failed to set texture count please retry later"
4786 src#
int "slice height"
4787 (fun () -> conf.sliceheight
)
4789 conf.sliceheight
<- v;
4790 wcmd "sliceh %d" conf.sliceheight
;
4792 src#
int "anti-aliasing level"
4793 (fun () -> conf.aalevel
)
4795 conf.aalevel
<- bound v 0 8;
4796 state.anchor <- getanchor ();
4797 opendoc state.path
state.password
;
4799 src#
string "page scroll scaling factor"
4800 (fun () -> string_of_float
conf.pgscale)
4803 let s = float_of_string
v in
4806 state.text <- Printf.sprintf
4807 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4810 src#
int "ui font size"
4811 (fun () -> fstate.fontsize
)
4812 (fun v -> setfontsize (bound v 5 100));
4813 src#
int "hint font size"
4814 (fun () -> conf.hfsize
)
4815 (fun v -> conf.hfsize
<- bound v 5 100);
4816 colorp "background color"
4817 (fun () -> conf.bgcolor
)
4818 (fun v -> conf.bgcolor
<- v);
4819 src#
bool "crop hack"
4820 (fun () -> conf.crophack
)
4821 (fun v -> conf.crophack
<- v);
4822 src#
string "trim fuzz"
4823 (fun () -> irect_to_string conf.trimfuzz
)
4826 conf.trimfuzz
<- irect_of_string v;
4828 then settrim true conf.trimfuzz
;
4830 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4832 src#
string "throttle"
4834 match conf.maxwait
with
4835 | None
-> "show place holder if page is not ready"
4838 then "wait for page to fully render"
4840 "wait " ^ string_of_float
time
4841 ^
" seconds before showing placeholder"
4845 let f = float_of_string
v in
4847 then conf.maxwait
<- None
4848 else conf.maxwait
<- Some
f
4850 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4852 src#
string "ghyll scroll"
4854 match conf.ghyllscroll
with
4856 | Some nab
-> ghyllscroll_to_string nab
4863 else Some
(ghyllscroll_of_string v)
4865 conf.ghyllscroll
<- gs
4867 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4869 src#
string "selection command"
4870 (fun () -> conf.selcmd
)
4871 (fun v -> conf.selcmd
<- v);
4872 src#
string "synctex command"
4873 (fun () -> conf.stcmd
)
4874 (fun v -> conf.stcmd
<- v);
4875 src#
string "pax command"
4876 (fun () -> conf.paxcmd
)
4877 (fun v -> conf.paxcmd
<- v);
4878 src#colorspace
"color space"
4879 (fun () -> CSTE.to_string conf.colorspace
)
4881 conf.colorspace
<- CSTE.of_int v;
4885 src#paxmark
"pax mark method"
4886 (fun () -> MTE.to_string conf.paxmark
)
4887 (fun v -> conf.paxmark
<- MTE.of_int v);
4891 (fun () -> conf.usepbo
)
4892 (fun v -> conf.usepbo
<- v);
4893 src#
bool "mouse wheel scrolls pages"
4894 (fun () -> conf.wheelbypage
)
4895 (fun v -> conf.wheelbypage
<- v);
4896 src#
bool "open remote links in a new instance"
4897 (fun () -> conf.riani
)
4898 (fun v -> conf.riani
<- v);
4902 src#caption
"Document" 0;
4903 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4904 src#caption2
"Pages"
4905 (fun () -> string_of_int
state.pagecount
) 1;
4906 src#caption2
"Dimensions"
4907 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4911 src#caption
"Trimmed margins" 0;
4912 src#caption2
"Dimensions"
4913 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4917 src#caption
"OpenGL" 0;
4918 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4919 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4922 src#caption
"Location" 0;
4923 if nonemptystr
state.origin
4924 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4925 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4927 src#reset prevmode prevuioh
;
4931 let prevmode = state.mode
4932 and prevuioh
= state.uioh in
4933 fillsrc prevmode prevuioh
;
4934 let source = (src :> lvsource
) in
4935 let modehash = findkeyhash conf "info" in
4936 state.uioh <- coe (object (self)
4937 inherit listview ~
source ~trusted
:true ~
modehash as super
4938 val mutable m_prevmemused
= 0
4939 method infochanged
= function
4941 if m_prevmemused
!= state.memused
4943 m_prevmemused
<- state.memused
;
4944 G.postRedisplay "memusedchanged";
4946 | Pdim
-> G.postRedisplay "pdimchanged"
4947 | Docinfo
-> fillsrc prevmode prevuioh
4949 method key key mask
=
4950 if not
(Wsi.withctrl mask
)
4953 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4954 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4955 | _ -> super#
key key mask
4956 else super#
key key mask
4958 G.postRedisplay "info";
4964 inherit lvsourcebase
4965 method getitemcount
= Array.length
state.help
4967 let s, l, _ = state.help
.(n) in
4970 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4974 m_qsearch
<- qsearch;
4975 match state.help
.(active) with
4976 | _, _, Action
f -> Some
(f uioh)
4986 method hasaction
n =
4987 match state.help
.(n) with
4988 | _, _, Action
_ -> true
4995 let modehash = findkeyhash conf "help" in
4996 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4997 G.postRedisplay "help";
5002 let re = Str.regexp
"[\r\n]" in
5004 inherit lvsourcebase
5005 val mutable m_items
= [||]
5007 method getitemcount
= 1 + Array.length m_items
5012 else m_items
.(n-1), 0
5014 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5019 then Buffer.clear
state.errmsgs
;
5020 m_qsearch
<- qsearch;
5027 method hasaction
n =
5031 state.newerrmsgs
<- false;
5032 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5033 m_items
<- Array.of_list
l
5041 let source = (msgsource :> lvsource
) in
5042 let modehash = findkeyhash conf "listview" in
5043 state.uioh <- coe (object
5044 inherit listview ~
source ~trusted
:false ~
modehash as super
5047 then msgsource#reset
;
5050 G.postRedisplay "msgs";
5053 let quickbookmark ?title
() =
5054 match state.layout with
5060 let sec = Unix.gettimeofday
() in
5061 let tm = Unix.localtime
sec in
5062 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5066 (tm.Unix.tm_year
+ 1900)
5069 | Some
title -> title
5071 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5074 let setautoscrollspeed step goingdown
=
5075 let incr = max
1 ((abs step
) / 2) in
5076 let incr = if goingdown
then incr else -incr in
5077 let astep = step
+ incr in
5078 state.autoscroll
<- Some
astep;
5081 let gotounder under =
5082 let getpath filename
=
5084 if nonemptystr filename
5086 if Filename.is_relative filename
5088 let dir = Filename.dirname
state.path in
5090 if Filename.is_implicit
dir
5091 then Filename.concat
(Sys.getcwd
()) dir
5094 Filename.concat
dir filename
5098 if Sys.file_exists
path
5103 | Ulinkgoto
(pageno, top) ->
5107 gotopage1 pageno top;
5113 | Uremote
(filename
, pageno) ->
5114 let path = getpath filename
in
5119 let command = !selfexec ^
" " ^
path in
5120 try popen command []
5123 "failed to execute `%s': %s\n" command (exntos exn
);
5126 let anchor = getanchor () in
5127 let ranchor = state.path, state.password
, anchor, state.origin
in
5129 state.anchor <- (pageno, 0.0, 0.0);
5130 state.ranchors
<- ranchor :: state.ranchors
;
5133 else showtext '
!'
("Could not find " ^ filename
)
5135 | Uremotedest
(filename
, destname
) ->
5136 let path = getpath filename
in
5141 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
5142 try popen command []
5145 "failed to execute `%s': %s\n" command (exntos exn
);
5148 let anchor = getanchor () in
5149 let ranchor = state.path, state.password
, anchor, state.origin
in
5151 state.nameddest
<- destname
;
5152 state.ranchors
<- ranchor :: state.ranchors
;
5155 else showtext '
!'
("Could not find " ^ filename
)
5157 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5161 match conf.columns
with
5163 | _ -> state.x != 0 || conf.zoom > 1.0
5166 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5168 let existsinrow pageno (columns
, coverA
, coverB
) p =
5169 let last = ((pageno - coverA
) mod columns
) + columns
in
5170 let rec any = function
5173 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5177 then (if l.pageno = last then false else any rest
)
5185 match state.layout with
5187 let pageno = page_of_y state.y in
5188 gotoghyll (getpagey (pageno+1))
5190 match conf.columns
with
5192 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5194 let y = clamp (pgscale state.winh
) in
5197 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5198 gotoghyll (getpagey pageno)
5199 | Cmulti
((c, _, _) as cl, _) ->
5200 if conf.presentation
5201 && (existsinrow l.pageno cl
5202 (fun l -> l.pageh
> l.pagey + l.pagevh))
5204 let y = clamp (pgscale state.winh
) in
5207 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5208 gotoghyll (getpagey pageno)
5210 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5212 let pagey, pageh
= getpageyh l.pageno in
5213 let pagey = pagey + pageh
* l.pagecol
in
5214 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5215 gotoghyll (pagey + pageh
+ ips)
5219 match state.layout with
5221 let pageno = page_of_y state.y in
5222 gotoghyll (getpagey (pageno-1))
5224 match conf.columns
with
5226 if conf.presentation
&& l.pagey != 0
5228 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5230 let pageno = max
0 (l.pageno-1) in
5231 gotoghyll (getpagey pageno)
5232 | Cmulti
((c, _, coverB
) as cl, _) ->
5233 if conf.presentation
&&
5234 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5236 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5239 if l.pageno = state.pagecount
- coverB
5243 let pageno = max
0 (l.pageno-decr) in
5244 gotoghyll (getpagey pageno)
5252 let pageno = max
0 (l.pageno-1) in
5253 let pagey, pageh
= getpageyh pageno in
5256 let pagey, pageh
= getpageyh l.pageno in
5257 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5262 let viewkeyboard key mask
=
5264 let mode = state.mode in
5265 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5268 G.postRedisplay "view:enttext"
5270 let ctrl = Wsi.withctrl mask
in
5272 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5278 | 0xff63 -> (* insert *)
5279 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5281 state.mode <- LinkNav
(Ltgendir
0);
5284 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5286 | 0xff1b | 113 -> (* escape / q *)
5287 begin match state.mstate
with
5289 state.mstate
<- Mnone
;
5290 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5291 G.postRedisplay "kill zoom rect";
5293 begin match state.mode with
5296 G.postRedisplay "esc leave linknav"
5298 match state.ranchors
with
5300 | (path, password
, anchor, origin
) :: rest
->
5301 state.ranchors
<- rest
;
5302 state.anchor <- anchor;
5303 state.origin
<- origin
;
5304 state.nameddest
<- "";
5305 opendoc path password
5309 | 0xff08 -> (* backspace *)
5310 gotoghyll (getnav ~
-1)
5318 G.postRedisplay "dehighlight";
5320 | 47 | 63 -> (* / ? *)
5321 let ondone isforw
s =
5322 cbput state.hists
.pat
s;
5323 state.searchpattern
<- s;
5326 let s = String.create
1 in
5327 s.[0] <- Char.chr
key;
5328 enttext (s, "", Some
(onhist state.hists
.pat
),
5329 textentry, ondone (key = 47), true)
5331 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5332 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5333 setzoom (conf.zoom +. incr)
5335 | 43 | 0xffab -> (* + *)
5338 try int_of_string
s with exc
->
5339 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5345 state.text <- "page bias is now " ^ string_of_int
n;
5348 enttext ("page bias: ", "", None
, intentry, ondone, true)
5350 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5351 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5352 setzoom (max
0.01 (conf.zoom -. decr))
5354 | 45 | 0xffad -> (* - *)
5355 let ondone msg
= state.text <- msg
in
5357 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5358 optentry state.mode, ondone, true
5361 | 48 when ctrl -> (* ctrl-0 *)
5369 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5371 match conf.columns
with
5372 | Csingle
_ | Cmulti
_ -> 1
5373 | Csplit
(n, _) -> n
5375 let h = state.winh
-
5376 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5378 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5379 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5382 | 51 when ctrl -> (* ctrl-3 *)
5384 match conf.fitmodel
with
5385 | FitWidth
-> FitProportional
5386 | FitProportional
-> FitPage
5387 | FitPage
-> FitWidth
5389 state.text <- "fit model: " ^
FMTE.to_string fm;
5390 reqlayout conf.angle
fm
5392 | 0xffc6 -> (* f9 *)
5395 | 57 when ctrl -> (* ctrl-9 *)
5398 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5399 when not
ctrl -> (* 0..9 *)
5402 try int_of_string
s with exc
->
5403 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5409 cbput state.hists
.pag
(string_of_int
n);
5410 gotopage1 (n + conf.pagebias
- 1) 0;
5413 let pageentry text key =
5414 match Char.unsafe_chr
key with
5415 | '
g'
-> TEdone
text
5416 | _ -> intentry text key
5418 let text = "x" in text.[0] <- Char.chr
key;
5419 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5422 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5423 reshape state.winw
state.winh
;
5426 state.bzoom
<- not
state.bzoom
;
5428 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5431 conf.hlinks
<- not
conf.hlinks
;
5432 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5433 G.postRedisplay "toggle highlightlinks";
5436 state.glinks
<- true;
5437 let mode = state.mode in
5438 state.mode <- Textentry
(
5439 (":", "", None
, linknentry, linkndone gotounder, false),
5441 state.glinks
<- false;
5445 G.postRedisplay "view:linkent(F)"
5448 state.glinks
<- true;
5449 let mode = state.mode in
5450 state.mode <- Textentry
(
5452 ":", "", None
, linknentry, linkndone (fun under ->
5453 selstring (undertext under);
5457 state.glinks
<- false;
5461 G.postRedisplay "view:linkent"
5464 begin match state.autoscroll
with
5466 conf.autoscrollstep
<- step
;
5467 state.autoscroll
<- None
5469 if conf.autoscrollstep
= 0
5470 then state.autoscroll
<- Some
1
5471 else state.autoscroll
<- Some
conf.autoscrollstep
5474 | 112 when ctrl -> (* ctrl-p *)
5478 setpresentationmode (not
conf.presentation
);
5479 showtext ' '
("presentation mode " ^
5480 if conf.presentation
then "on" else "off");
5483 if List.mem
Wsi.Fullscreen
state.winstate
5484 then Wsi.reshape conf.cwinw
conf.cwinh
5485 else Wsi.fullscreen
()
5487 | 112 | 78 -> (* p|N *)
5488 search state.searchpattern
false
5490 | 110 | 0xffc0 -> (* n|F3 *)
5491 search state.searchpattern
true
5494 begin match state.layout with
5497 gotoghyll (getpagey l.pageno)
5503 | 0xff9f | 0xffff -> (* delete *)
5507 showtext ' '
(describe_location ());
5510 begin match state.layout with
5513 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5518 enterbookmarkmode ()
5520 | 104 | 0xffbe -> (* h|F1 *)
5526 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5531 match state.layout with
5535 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5538 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5542 showtext ' '
"Quick bookmark added";
5545 begin match state.layout with
5547 let rect = getpdimrect
l.pagedimno
in
5551 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5552 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5554 (truncate
(rect.(1) -. rect.(0)),
5555 truncate
(rect.(3) -. rect.(0)))
5557 let w = truncate
((float w)*.conf.zoom)
5558 and h = truncate
((float h)*.conf.zoom) in
5561 state.anchor <- getanchor ();
5562 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5564 G.postRedisplay "z";
5569 | 120 -> state.roam
()
5570 | 60 | 62 -> (* < > *)
5571 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5573 | 91 | 93 -> (* [ ] *)
5575 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5577 G.postRedisplay "brightness";
5579 | 99 when state.mode = View
-> (* [alt-]c *)
5584 let m = (wadjsb state.winw
- state.w) / 2 in
5586 gotoy_and_clear_text state.y
5590 match state.prevcolumns
with
5591 | None
-> (1, 0, 0), 1.0
5592 | Some
(columns
, z
) ->
5595 | Csplit
(c, _) -> -c, 0, 0
5596 | Cmulti
((c, a, b), _) -> c, a, b
5597 | Csingle
_ -> 1, 0, 0
5601 setcolumns View
c a b;
5604 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5605 -> (* ctrl-shift- (kp) [up|down] *)
5606 let zoom, x = state.prevzoom
in
5610 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5611 begin match state.autoscroll
with
5613 begin match state.mode with
5614 | Birdseye beye
-> upbirdseye 1 beye
5617 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5619 if not
(Wsi.withshift mask
) && conf.presentation
5621 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5625 setautoscrollspeed n false
5628 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5629 begin match state.autoscroll
with
5631 begin match state.mode with
5632 | Birdseye beye
-> downbirdseye 1 beye
5635 then gotoy_and_clear_text (clamp (state.winh
/2))
5637 if not
(Wsi.withshift mask
) && conf.presentation
5639 else gotoy_and_clear_text (clamp conf.scrollstep
)
5643 setautoscrollspeed n true
5646 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5647 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5653 else conf.hscrollstep
5655 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5656 state.x <- panbound (state.x + dx);
5657 gotoy_and_clear_text state.y
5660 G.postRedisplay "left/right"
5663 | 0xff55 | 0xff9a -> (* (kp) prior *)
5667 match state.layout with
5669 | l :: _ -> state.y - l.pagey
5671 clamp (pgscale (-state.winh
))
5675 | 0xff56 | 0xff9b -> (* (kp) next *)
5679 match List.rev
state.layout with
5681 | l :: _ -> getpagey l.pageno
5683 clamp (pgscale state.winh
)
5687 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5689 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5690 gotoghyll (clamp state.maxy)
5693 when Wsi.withalt mask
-> (* alt-(kp) right *)
5694 gotoghyll (getnav 1)
5696 when Wsi.withalt mask
-> (* alt-(kp) left *)
5697 gotoghyll (getnav ~
-1)
5702 | 118 when conf.debug
-> (* v *)
5705 match getopaque l.pageno with
5708 let x0, y0, x1, y1 = pagebbox opaque
in
5709 let a,b = float x0, float y0 in
5710 let c,d = float x1, float y0 in
5711 let e,f = float x1, float y1 in
5712 let h,j
= float x0, float y1 in
5713 let rect = (a,b,c,d,e,f,h,j
) in
5715 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5717 G.postRedisplay "v";
5720 vlog "huh? %s" (Wsi.keyname
key)
5723 let linknavkeyboard key mask
linknav =
5724 let getpage pageno =
5725 let rec loop = function
5727 | l :: _ when l.pageno = pageno -> Some
l
5728 | _ :: rest
-> loop rest
5729 in loop state.layout
5731 let doexact (pageno, n) =
5732 match getopaque pageno, getpage pageno with
5733 | Some opaque
, Some
l ->
5734 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5736 let under = getlink opaque
n in
5737 G.postRedisplay "link gotounder";
5743 | 0xff50 -> (* home *)
5744 Some
(findlink opaque LDfirst
), -1
5746 | 0xff57 -> (* end *)
5747 Some
(findlink opaque LDlast
), 1
5749 | 0xff51 -> (* left *)
5750 Some
(findlink opaque
(LDleft
n)), -1
5752 | 0xff53 -> (* right *)
5753 Some
(findlink opaque
(LDright
n)), 1
5755 | 0xff52 -> (* up *)
5756 Some
(findlink opaque
(LDup
n)), -1
5758 | 0xff54 -> (* down *)
5759 Some
(findlink opaque
(LDdown
n)), 1
5764 begin match findpwl
l.pageno dir with
5768 state.mode <- LinkNav
(Ltgendir
dir);
5769 let y, h = getpageyh pageno in
5772 then y + h - state.winh
5777 begin match getopaque pageno, getpage pageno with
5778 | Some opaque
, Some
_ ->
5780 let ld = if dir > 0 then LDfirst
else LDlast
in
5783 begin match link with
5785 showlinktype (getlink opaque
m);
5786 state.mode <- LinkNav
(Ltexact
(pageno, m));
5787 G.postRedisplay "linknav jpage";
5794 begin match opt with
5795 | Some Lnotfound
-> pwl l dir;
5796 | Some
(Lfound
m) ->
5800 let _, y0, _, y1 = getlinkrect opaque
m in
5802 then gotopage1 l.pageno y0
5804 let d = fstate.fontsize
+ 1 in
5805 if y1 - l.pagey > l.pagevh - d
5806 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5807 else G.postRedisplay "linknav";
5809 showlinktype (getlink opaque
m);
5810 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5813 | None
-> viewkeyboard key mask
5815 | _ -> viewkeyboard key mask
5820 G.postRedisplay "leave linknav"
5824 | Ltgendir
_ -> viewkeyboard key mask
5825 | Ltexact exact
-> doexact exact
5828 let keyboard key mask
=
5829 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5830 then wcmd "interrupt"
5831 else state.uioh <- state.uioh#
key key mask
5834 let birdseyekeyboard key mask
5835 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5837 match conf.columns
with
5839 | Cmulti
((c, _, _), _) -> c
5840 | Csplit
_ -> failwith
"bird's eye split mode"
5842 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5844 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5845 let y, h = getpageyh pageno in
5846 let top = (state.winh
- h) / 2 in
5847 gotoy (max
0 (y - top))
5848 | 0xff0d (* enter *)
5849 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5850 | 0xff1b -> leavebirdseye beye
true (* escape *)
5851 | 0xff52 -> upbirdseye incr beye
(* up *)
5852 | 0xff54 -> downbirdseye incr beye
(* down *)
5853 | 0xff51 -> upbirdseye 1 beye
(* left *)
5854 | 0xff53 -> downbirdseye 1 beye
(* right *)
5856 | 0xff55 -> (* prior *)
5857 begin match state.layout with
5861 state.mode <- Birdseye
(
5862 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5864 gotopage1 l.pageno 0;
5867 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5869 | [] -> gotoy (clamp (-state.winh
))
5871 state.mode <- Birdseye
(
5872 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5874 gotopage1 l.pageno 0
5877 | [] -> gotoy (clamp (-state.winh
))
5880 | 0xff56 -> (* next *)
5881 begin match List.rev
state.layout with
5883 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5884 begin match layout with
5886 let incr = l.pageh
- l.pagevh in
5891 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5893 G.postRedisplay "birdseye pagedown";
5895 else gotoy (clamp (incr + conf.interpagespace
*2));
5899 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5900 gotopage1 l.pageno 0;
5903 | [] -> gotoy (clamp state.winh
)
5906 | 0xff50 -> (* home *)
5907 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5910 | 0xff57 -> (* end *)
5911 let pageno = state.pagecount
- 1 in
5912 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5913 if not
(pagevisible state.layout pageno)
5916 match List.rev
state.pdims
with
5918 | (_, _, h, _) :: _ -> h
5920 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5921 else G.postRedisplay "birdseye end";
5922 | _ -> viewkeyboard key mask
5927 match state.mode with
5928 | Textentry
_ -> scalecolor 0.4
5930 | View
-> scalecolor 1.0
5931 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5932 if l.pageno = hooverpageno
5935 if l.pageno = pageno
5943 let postdrawpage l linkindexbase
=
5944 match getopaque l.pageno with
5946 if tileready l l.pagex
l.pagey
5948 let x = l.pagedispx - l.pagex
5949 and y = l.pagedispy - l.pagey in
5951 match conf.columns
with
5952 | Csingle
_ | Cmulti
_ ->
5953 (if conf.hlinks
then 1 else 0)
5955 && not
(isbirdseye state.mode) then 2 else 0)
5959 match state.mode with
5960 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5963 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5968 let scrollindicator () =
5969 let sbw, ph
, sh = state.uioh#
scrollph in
5970 let sbh, pw, sw = state.uioh#scrollpw
in
5972 GlDraw.color (0.64, 0.64, 0.64);
5974 (float (state.winw
- sbw), 0.)
5975 (float state.winw
, float state.winh
)
5978 (0., float (state.winh
- sbh))
5979 (float (wadjsb state.winw
- 1), float state.winh
)
5981 GlDraw.color (0.0, 0.0, 0.0);
5984 (float (state.winw
- sbw), ph
)
5985 (float state.winw
, ph
+. sh)
5988 (pw, float (state.winh
- sbh))
5989 (pw +. sw, float state.winh
)
5994 match state.mstate
with
5995 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5998 | Msel
((x0, y0), (x1, y1)) ->
5999 let rec loop = function
6001 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6002 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6003 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6004 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6006 match getopaque l.pageno with
6008 let x0, y0 = pagetranslatepoint l x0 y0 in
6009 let x1, y1 = pagetranslatepoint l x1 y1 in
6010 seltext opaque
(x0, y0, x1, y1);
6018 let showrects rects
=
6020 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6021 GlDraw.polygon_mode `both `fill
;
6022 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6024 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6026 if l.pageno = pageno
6028 let dx = float (l.pagedispx - l.pagex
) in
6029 let dy = float (l.pagedispy - l.pagey) in
6030 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6031 GlDraw.begins `quads
;
6033 GlDraw.vertex2
(x0+.dx, y0+.dy);
6034 GlDraw.vertex2
(x1+.dx, y1+.dy);
6035 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
6036 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
6047 GlClear.color (scalecolor2 conf.bgcolor
);
6048 GlClear.clear
[`
color];
6049 List.iter
drawpage state.layout;
6051 match state.mode with
6052 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6053 begin match getopaque pageno with
6055 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6062 | None
-> state.rects
6067 let rec postloop linkindexbase
= function
6069 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6070 postloop linkindexbase rest
6074 postloop 0 state.layout;
6076 begin match state.mstate
with
6077 | Mzoomrect
((x0, y0), (x1, y1)) ->
6079 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6080 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6081 GlDraw.rect (float x0, float y0)
6082 (float x1, float y1);
6091 let zoomrect x y x1 y1 =
6094 and y0 = min
y y1 in
6095 gotoy (state.y + y0);
6096 state.anchor <- getanchor ();
6097 let zoom = (float state.w) /. float (x1 - x0) in
6099 match conf.fitmodel
, conf.columns
with
6100 | FitPage
, Csplit
_ ->
6101 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6104 let adjw = wadjsb state.winw
in
6106 then (adjw - state.w) / 2
6109 state.x <- (state.x + margin) - x0;
6111 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6112 state.mstate
<- Mnone
;
6116 let g opaque
l px py =
6117 match rectofblock opaque
px py with
6119 let x0 = a.(0) -. 20. in
6120 let x1 = a.(1) +. 20. in
6121 let y0 = a.(2) -. 20. in
6122 let zoom = (float state.w) /. (x1 -. x0) in
6123 let pagey = getpagey l.pageno in
6124 gotoy_and_clear_text (pagey + truncate
y0);
6125 state.anchor <- getanchor ();
6126 let margin = (state.w - l.pagew
)/2 in
6127 state.x <- -truncate
x0 - margin;
6132 match conf.columns
with
6134 showtext '
!'
"block zooming does not work properly in split columns mode"
6135 | _ -> onppundermouse g x y ()
6139 let winw = wadjsb state.winw - 1 in
6140 let s = float x /. float winw in
6141 let destx = truncate
(float (state.w + winw) *. s) in
6142 state.x <- winw - destx;
6143 gotoy_and_clear_text state.y;
6144 state.mstate
<- Mscrollx
;
6148 let s = float y /. float state.winh
in
6149 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6150 gotoy_and_clear_text desty;
6151 state.mstate
<- Mscrolly
;
6154 let viewmouse button down
x y mask
=
6156 | n when (n == 4 || n == 5) && not down
->
6157 if Wsi.withctrl mask
6159 match state.mstate
with
6160 | Mzoom
(oldn
, i
) ->
6168 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6170 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6172 let zoom = conf.zoom -. incr in
6174 state.mstate
<- Mzoom
(n, 0);
6176 state.mstate
<- Mzoom
(n, i
+1);
6178 else state.mstate
<- Mzoom
(n, 0)
6180 | _ -> state.mstate
<- Mzoom
(n, 0)
6183 match state.autoscroll
with
6184 | Some step
-> setautoscrollspeed step
(n=4)
6186 if conf.wheelbypage
|| conf.presentation
6195 then -conf.scrollstep
6196 else conf.scrollstep
6198 let incr = incr * 2 in
6199 let y = clamp incr in
6200 gotoy_and_clear_text y
6203 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6205 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6206 gotoy_and_clear_text state.y
6208 | 1 when Wsi.withshift mask
->
6209 state.mstate
<- Mnone
;
6212 match unproject x y with
6213 | Some
(pageno, ux
, uy
) ->
6214 let cmd = Printf.sprintf
6216 conf.stcmd
state.path pageno ux uy
6222 | 1 when Wsi.withctrl mask
->
6225 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6226 state.mstate
<- Mpan
(x, y)
6229 state.mstate
<- Mnone
6234 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6236 state.mstate
<- Mzoomrect
(p, p)
6239 match state.mstate
with
6240 | Mzoomrect
((x0, y0), _) ->
6241 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6242 then zoomrect x0 y0 x y
6244 state.mstate
<- Mnone
;
6245 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6246 G.postRedisplay "kill accidental zoom rect";
6249 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6250 state.mstate
<- Mnone
6253 | 1 when x > state.winw - vscrollw () ->
6256 let _, position, sh = state.uioh#
scrollph in
6257 if y > truncate
position && y < truncate
(position +. sh)
6258 then state.mstate
<- Mscrolly
6261 state.mstate
<- Mnone
6263 | 1 when y > state.winh
- hscrollh () ->
6266 let _, position, sw = state.uioh#scrollpw
in
6267 if x > truncate
position && x < truncate
(position +. sw)
6268 then state.mstate
<- Mscrollx
6271 state.mstate
<- Mnone
6273 | 1 when state.bzoom
-> if not down
then zoomblock x y
6276 let dest = if down
then getunder x y else Unone
in
6277 begin match dest with
6280 | Uremote
_ | Uremotedest
_
6281 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6284 | Unone
when down
->
6285 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6286 state.mstate
<- Mpan
(x, y);
6288 | Unone
| Utext
_ ->
6291 if conf.angle
mod 360 = 0
6293 state.mstate
<- Msel
((x, y), (x, y));
6294 G.postRedisplay "mouse select";
6298 match state.mstate
with
6301 | Mzoom
_ | Mscrollx
| Mscrolly
->
6302 state.mstate
<- Mnone
6304 | Mzoomrect
((x0, y0), _) ->
6308 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6309 state.mstate
<- Mnone
6311 | Msel
((x0, y0), (x1, y1)) ->
6312 let rec loop = function
6316 let a0 = l.pagedispy in
6317 let a1 = a0 + l.pagevh in
6318 let b0 = l.pagedispx in
6319 let b1 = b0 + l.pagevw in
6320 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6321 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6325 match getopaque l.pageno with
6328 match Ne.pipe () with
6332 "can not create sel pipe: %s"
6335 let doclose what fd
=
6336 Ne.clo fd
(fun msg
->
6337 dolog
"%s close failed: %s" what msg
)
6340 popen conf.selcmd
[r, 0; w, -1];
6341 copysel
w opaque
true;
6343 G.postRedisplay "copysel";
6345 dolog
"can not execute %S: %s"
6346 conf.selcmd
(exntos exn
);
6354 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6355 state.mstate
<- Mnone
;
6362 let birdseyemouse button down
x y mask
6363 (conf, leftx
, _, hooverpageno
, anchor) =
6366 let rec loop = function
6369 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6370 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6372 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6378 | _ -> viewmouse button down
x y mask
6381 let mouse button down
x y mask
=
6382 state.uioh <- state.uioh#button button down
x y mask
;
6386 state.uioh <- state.uioh#
motion x y
6390 state.uioh <- state.uioh#
pmotion x y;
6396 method key key mask
=
6397 begin match state.mode with
6398 | Textentry
textentry -> textentrykeyboard key mask
textentry
6399 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6400 | View
-> viewkeyboard key mask
6401 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6405 method button button bstate
x y mask
=
6406 begin match state.mode with
6408 | View
-> viewmouse button bstate
x y mask
6409 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6415 begin match state.mode with
6417 | View
| Birdseye
_ | LinkNav
_ ->
6418 match state.mstate
with
6419 | Mzoom
_ | Mnone
-> ()
6424 state.mstate
<- Mpan
(x, y);
6426 then state.x <- panbound (state.x + dx);
6428 gotoy_and_clear_text y
6431 state.mstate
<- Msel
(a, (x, y));
6432 G.postRedisplay "motion select";
6435 let y = min
state.winh
(max
0 y) in
6439 let x = min
state.winw (max
0 x) in
6442 | Mzoomrect
(p0
, _) ->
6443 state.mstate
<- Mzoomrect
(p0
, (x, y));
6444 G.postRedisplay "motion zoomrect";
6448 method pmotion x y =
6449 begin match state.mode with
6450 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6451 let rec loop = function
6453 if hooverpageno
!= -1
6455 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6456 G.postRedisplay "pmotion birdseye no hoover";
6459 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6460 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6462 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6463 G.postRedisplay "pmotion birdseye hoover";
6473 match state.mstate
with
6474 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6481 let past, _, _ = !r in
6483 let delta = now -. past in
6486 else r := (now, x, y)
6490 method infochanged
_ = ()
6493 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6496 then 0.0, float state.winh
6497 else scrollph state.y maxy
6502 let winw = wadjsb state.winw in
6503 let fwinw = float winw in
6505 let sw = fwinw /. float state.w in
6506 let sw = fwinw *. sw in
6507 max
sw (float conf.scrollh
)
6510 let maxx = state.w + winw in
6511 let x = winw - state.x in
6512 let percent = float x /. float maxx in
6513 (fwinw -. sw) *. percent
6515 hscrollh (), position, sw
6519 match state.mode with
6520 | LinkNav
_ -> "links"
6521 | Textentry
_ -> "textentry"
6522 | Birdseye
_ -> "birdseye"
6525 findkeyhash conf modename
6527 method eformsgs
= true
6534 let fontpath = ref "";;
6537 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6540 let l = String.length
s in
6541 let b = Buffer.create
l in
6547 try Sys.getenv
"HOME"
6550 ("Can not determine home directory location: " ^ exntos exn
);
6554 let modifier_of_string = function
6555 | "alt" -> Wsi.altmask
6556 | "shift" -> Wsi.shiftmask
6557 | "ctrl" | "control" -> Wsi.ctrlmask
6558 | "meta" -> Wsi.metamask
6563 let r = Str.regexp
"-" in
6565 let elems = Str.full_split
r s in
6568 let m1 = modifier_of_string s in
6570 then (Wsi.namekey
s, m)
6573 | Str.Delim
s when n land 1 = 0 -> g s
6575 | Str.Delim
_ -> (k
, m)
6577 let rec loop n k
m = function
6580 let k, m = f n k m x in
6586 let keys_of_string =
6587 let r = Str.regexp
"[ \t]" in
6589 let elems = Str.split
r s in
6590 List.map
key_of_string elems
6593 let copykeyhashes c =
6594 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6597 let config_of c attrs
=
6601 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6602 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6603 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6604 | "preload" -> { c with preload = bool_of_string
v }
6605 | "page-bias" -> { c with pagebias
= int_of_string
v }
6606 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6607 | "horizontal-scroll-step" ->
6608 { c with hscrollstep
= max
(int_of_string
v) 1 }
6609 | "auto-scroll-step" ->
6610 { c with autoscrollstep
= max
0 (int_of_string
v) }
6611 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6612 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6615 match String.lowercase
v with
6616 | "true" -> Some infinity
6618 | f -> Some
(float_of_string
f)
6620 { c with maxwait
= mw}
6621 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6622 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6623 | "vertical-margin" ->
6624 { c with interpagespace
= max
0 (int_of_string
v) }
6626 let zoom = float_of_string
v /. 100. in
6627 let zoom = max
zoom 0.0 in
6628 { c with zoom = zoom }
6629 | "presentation" -> { c with presentation
= bool_of_string
v }
6630 | "rotation-angle" -> { c with angle
= int_of_string
v }
6631 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6632 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6633 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6634 | "proportional-display" ->
6637 then FitProportional
6640 { c with fitmodel
= fm }
6641 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6642 | "pixmap-cache-size" ->
6643 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6644 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6645 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6646 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6647 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6648 | "background-color" -> { c with bgcolor
= color_of_string v }
6649 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6650 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6651 | "mupdf-store-size" ->
6652 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6653 | "checkers" -> { c with checkers
= bool_of_string
v }
6654 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6655 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6656 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6657 | "uri-launcher" -> { c with urilauncher
= unent v }
6658 | "path-launcher" -> { c with pathlauncher
= unent v }
6659 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6660 | "invert-colors" -> { c with invert
= bool_of_string
v }
6661 | "brightness" -> { c with colorscale
= float_of_string
v }
6662 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6664 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6666 let (n, _, _) as nab
= multicolumns_of_string v in
6668 then { c with columns
= Csplit
(-n, [||]) }
6669 else { c with columns
= Cmulti
(nab
, [||]) }
6670 | "birds-eye-columns" ->
6671 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6672 | "selection-command" -> { c with selcmd
= unent v }
6673 | "synctex-command" -> { c with stcmd
= unent v }
6674 | "pax-command" -> { c with paxcmd
= unent v }
6675 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6676 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6677 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6678 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6679 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6680 | "horizontal-scrollbar-visible" ->
6683 then c.scrollb
lor scrollbhv
6684 else c.scrollb
land (lnot
scrollbhv)
6686 { c with scrollb
= b }
6687 | "vertical-scrollbar-visible" ->
6690 then c.scrollb
lor scrollbvv
6691 else c.scrollb
land (lnot
scrollbvv)
6693 { c with scrollb
= b }
6694 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6698 then Some
(ref (0.0, 0, 0))
6700 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6703 prerr_endline
("Error processing attribute (`" ^
6704 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6707 let rec fold c = function
6710 let c = apply c k v in
6713 fold { c with keyhashes
= copykeyhashes c } attrs
;
6716 let fromstring f pos
n v d =
6719 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6720 n v pos
(exntos exn
)
6725 let bookmark_of attrs
=
6726 let rec fold title page
rely visy
= function
6727 | ("title", v) :: rest
-> fold v page
rely visy rest
6728 | ("page", v) :: rest
-> fold title v rely visy rest
6729 | ("rely", v) :: rest
-> fold title page
v visy rest
6730 | ("visy", v) :: rest
-> fold title page
rely v rest
6731 | _ :: rest
-> fold title page
rely visy rest
6732 | [] -> title, page
, rely, visy
6734 fold "invalid" "0" "0" "0" attrs
6738 let rec fold path page
rely pan visy
= function
6739 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6740 | ("page", v) :: rest
-> fold path v rely pan visy rest
6741 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6742 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6743 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6744 | _ :: rest
-> fold path page
rely pan visy rest
6745 | [] -> path, page
, rely, pan
, visy
6747 fold "" "0" "0" "0" "0" attrs
6751 let rec fold rs ls
= function
6752 | ("out", v) :: rest
-> fold v ls rest
6753 | ("in", v) :: rest
-> fold rs
v rest
6754 | _ :: rest
-> fold ls rs rest
6760 let setconf dst
src =
6761 dst
.scrollbw
<- src.scrollbw
;
6762 dst
.scrollh
<- src.scrollh
;
6763 dst
.icase
<- src.icase
;
6764 dst
.preload <- src.preload;
6765 dst
.pagebias
<- src.pagebias
;
6766 dst
.verbose
<- src.verbose
;
6767 dst
.scrollstep
<- src.scrollstep
;
6768 dst
.maxhfit
<- src.maxhfit
;
6769 dst
.crophack
<- src.crophack
;
6770 dst
.autoscrollstep
<- src.autoscrollstep
;
6771 dst
.maxwait
<- src.maxwait
;
6772 dst
.hlinks
<- src.hlinks
;
6773 dst
.underinfo
<- src.underinfo
;
6774 dst
.interpagespace
<- src.interpagespace
;
6775 dst
.zoom <- src.zoom;
6776 dst
.presentation
<- src.presentation
;
6777 dst
.angle
<- src.angle
;
6778 dst
.cwinw
<- src.cwinw
;
6779 dst
.cwinh
<- src.cwinh
;
6780 dst
.savebmarks
<- src.savebmarks
;
6781 dst
.memlimit
<- src.memlimit
;
6782 dst
.fitmodel
<- src.fitmodel
;
6783 dst
.texcount
<- src.texcount
;
6784 dst
.sliceheight
<- src.sliceheight
;
6785 dst
.thumbw
<- src.thumbw
;
6786 dst
.jumpback
<- src.jumpback
;
6787 dst
.bgcolor
<- src.bgcolor
;
6788 dst
.tilew
<- src.tilew
;
6789 dst
.tileh
<- src.tileh
;
6790 dst
.mustoresize
<- src.mustoresize
;
6791 dst
.checkers
<- src.checkers
;
6792 dst
.aalevel
<- src.aalevel
;
6793 dst
.trimmargins
<- src.trimmargins
;
6794 dst
.trimfuzz
<- src.trimfuzz
;
6795 dst
.urilauncher
<- src.urilauncher
;
6796 dst
.colorspace
<- src.colorspace
;
6797 dst
.invert
<- src.invert
;
6798 dst
.colorscale
<- src.colorscale
;
6799 dst
.redirectstderr <- src.redirectstderr;
6800 dst
.ghyllscroll
<- src.ghyllscroll
;
6801 dst
.columns
<- src.columns
;
6802 dst
.beyecolumns
<- src.beyecolumns
;
6803 dst
.selcmd
<- src.selcmd
;
6804 dst
.updatecurs
<- src.updatecurs
;
6805 dst
.pathlauncher
<- src.pathlauncher
;
6806 dst
.keyhashes
<- copykeyhashes src;
6807 dst
.hfsize
<- src.hfsize
;
6808 dst
.hscrollstep
<- src.hscrollstep
;
6809 dst
.pgscale <- src.pgscale;
6810 dst
.usepbo
<- src.usepbo
;
6811 dst
.wheelbypage
<- src.wheelbypage
;
6812 dst
.stcmd
<- src.stcmd
;
6813 dst
.paxcmd
<- src.paxcmd
;
6814 dst
.scrollb
<- src.scrollb
;
6815 dst
.riani
<- src.riani
;
6816 dst
.paxmark
<- src.paxmark
;
6820 else Some
((ref (0.0, 0, 0)));
6824 let h = Hashtbl.create
10 in
6825 let dc = { defconf with angle
= defconf.angle
} in
6826 let rec toplevel v t spos
_ =
6828 | Vdata
| Vcdata
| Vend
-> v
6829 | Vopen
("llppconfig", _, closed
) ->
6832 else { v with f = llppconfig
}
6834 error
"unexpected subelement at top level" s spos
6835 | Vclose
_ -> error
"unexpected close at top level" s spos
6837 and llppconfig
v t spos
_ =
6839 | Vdata
| Vcdata
-> v
6840 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6841 | Vopen
("defaults", attrs
, closed
) ->
6842 let c = config_of dc attrs
in
6846 else { v with f = defaults
}
6848 | Vopen
("ui-font", attrs
, closed
) ->
6849 let rec getsize size
= function
6851 | ("size", v) :: rest
->
6853 fromstring int_of_string spos
"size" v fstate.fontsize
in
6855 | l -> getsize size l
6857 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6860 else { v with f = uifont
(Buffer.create
10) }
6862 | Vopen
("doc", attrs
, closed
) ->
6863 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6864 let path = unent pathent
6865 and pageno = fromstring int_of_string spos
"page" spage
0
6866 and rely = fromstring float_of_string spos
"rely" srely
0.0
6867 and pan
= fromstring int_of_string spos
"pan" span
0
6868 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6869 let c = config_of dc attrs
in
6870 let anchor = (pageno, rely, visy
) in
6872 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6873 else { v with f = doc
path pan
anchor c [] }
6876 error
"unexpected subelement in llppconfig" s spos
6878 | Vclose
"llppconfig" -> { v with f = toplevel }
6879 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6881 and defaults
v t spos
_ =
6883 | Vdata
| Vcdata
-> v
6884 | Vend
-> error
"unexpected end of input in defaults" s spos
6885 | Vopen
("keymap", attrs
, closed
) ->
6887 try List.assoc
"mode" attrs
6888 with Not_found
-> "global" in
6893 let h = findkeyhash dc modename in
6894 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6897 { v with f = pkeymap
ret KeyMap.empty }
6899 | Vopen
(_, _, _) ->
6900 error
"unexpected subelement in defaults" s spos
6902 | Vclose
"defaults" ->
6903 { v with f = llppconfig
}
6905 | Vclose
_ -> error
"unexpected close in defaults" s spos
6907 and uifont
b v t spos
epos =
6910 Buffer.add_substring
b s spos
(epos - spos
);
6912 | Vopen
(_, _, _) ->
6913 error
"unexpected subelement in ui-font" s spos
6914 | Vclose
"ui-font" ->
6915 if emptystr
!fontpath
6916 then fontpath := Buffer.contents
b;
6917 { v with f = llppconfig
}
6918 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6919 | Vend
-> error
"unexpected end of input in ui-font" s spos
6921 and doc
path pan
anchor c bookmarks
v t spos
_ =
6923 | Vdata
| Vcdata
-> v
6924 | Vend
-> error
"unexpected end of input in doc" s spos
6925 | Vopen
("bookmarks", _, closed
) ->
6928 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6930 | Vopen
("keymap", attrs
, closed
) ->
6932 try List.assoc
"mode" attrs
6933 with Not_found
-> "global"
6939 let h = findkeyhash c modename in
6940 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6941 doc
path pan
anchor c bookmarks
6943 { v with f = pkeymap
ret KeyMap.empty }
6945 | Vopen
(_, _, _) ->
6946 error
"unexpected subelement in doc" s spos
6949 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6950 { v with f = llppconfig
}
6952 | Vclose
_ -> error
"unexpected close in doc" s spos
6954 and pkeymap
ret keymap
v t spos
_ =
6956 | Vdata
| Vcdata
-> v
6957 | Vend
-> error
"unexpected end of input in keymap" s spos
6958 | Vopen
("map", attrs
, closed
) ->
6959 let r, l = map_of attrs
in
6960 let kss = fromstring keys_of_string spos
"in" r [] in
6961 let lss = fromstring keys_of_string spos
"out" l [] in
6965 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6966 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6969 then { v with f = pkeymap
ret keymap }
6972 { v with f = skip
"map" f }
6975 error
"unexpected subelement in keymap" s spos
6977 | Vclose
"keymap" ->
6978 { v with f = ret keymap }
6980 | Vclose
_ -> error
"unexpected close in keymap" s spos
6982 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6984 | Vdata
| Vcdata
-> v
6985 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6986 | Vopen
("item", attrs
, closed
) ->
6987 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6988 let page = fromstring int_of_string spos
"page" spage
0
6989 and rely = fromstring float_of_string spos
"rely" srely
0.0
6990 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6992 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6995 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6998 { v with f = skip
"item" f }
7001 error
"unexpected subelement in bookmarks" s spos
7003 | Vclose
"bookmarks" ->
7004 { v with f = doc
path pan
anchor c bookmarks }
7006 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7008 and skip tag
f v t spos
_ =
7010 | Vdata
| Vcdata
-> v
7012 error
("unexpected end of input in skipped " ^ tag
) s spos
7013 | Vopen
(tag'
, _, closed
) ->
7017 let f'
() = { v with f = skip tag
f } in
7018 { v with f = skip tag'
f'
}
7022 else error
("unexpected close in skipped " ^ tag
) s spos
7025 parse
{ f = toplevel; accu = () } s;
7031 let len = in_channel_length ic
in
7032 let s = String.create
len in
7033 really_input ic
s 0 len;
7036 | Parse_error
(msg
, s, pos
) ->
7037 let subs = subs s pos
in
7038 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
7039 failwith
("parse error: " ^
s)
7042 failwith
("config load error: " ^ exntos exn
)
7048 let dir = Filename.concat
home ".config" in
7049 if Sys.is_directory
dir then dir else home
7052 Filename.concat
dir "llpp.conf"
7055 let confpath = ref defconfpath;;
7058 if Sys.file_exists
!confpath
7061 (try Some
(open_in_bin
!confpath)
7064 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7075 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7084 f (Hashtbl.create
0, defconf)
7089 let pc, pb
, px, pa
=
7092 if emptystr
state.origin
7096 Hashtbl.find h (Filename.basename
key)
7097 with Not_found
-> dc, [], 0, emptyanchor
7101 state.bookmarks <- pb
;
7104 then state.anchor <- pa
;
7105 cbput state.hists
.nav pa
;
7111 let add_attrs bb always
dc c =
7114 then Printf.bprintf bb
"\n %s='%b'" s a
7117 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7120 then Printf.bprintf bb
"\n %s='%d'" s a
7123 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7126 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7129 then Printf.bprintf bb
"\n %s='%f'" s a
7133 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7137 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7141 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7145 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7151 | Some
(_N
, _A
, _B
) ->
7152 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7162 else string_of_float
f
7164 Printf.bprintf bb
"\n %s='%s'" s v
7169 | Cmulti
((n, a, b), _) when n > 1 ->
7170 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7171 | Csplit
(n, _) when n > 1 ->
7172 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7178 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7183 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7187 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7191 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7193 oi
"width" c.cwinw
dc.cwinw
;
7194 oi
"height" c.cwinh
dc.cwinh
;
7195 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7196 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7197 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7198 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7199 ob "case-insensitive-search" c.icase
dc.icase
;
7200 ob "preload" c.preload dc.preload;
7201 oi
"page-bias" c.pagebias
dc.pagebias
;
7202 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7203 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7204 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7205 ob "crop-hack" c.crophack
dc.crophack
;
7206 oW
"throttle" c.maxwait
dc.maxwait
;
7207 ob "highlight-links" c.hlinks
dc.hlinks
;
7208 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7209 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7210 oz
"zoom" c.zoom dc.zoom;
7211 ob "presentation" c.presentation
dc.presentation
;
7212 oi
"rotation-angle" c.angle
dc.angle
;
7213 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7214 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7215 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7216 oi
"tex-count" c.texcount
dc.texcount
;
7217 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7218 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7219 ob "persistent-location" c.jumpback
dc.jumpback
;
7220 oc
"background-color" c.bgcolor
dc.bgcolor
;
7221 oi
"tile-width" c.tilew
dc.tilew
;
7222 oi
"tile-height" c.tileh
dc.tileh
;
7223 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7224 ob "checkers" c.checkers
dc.checkers
;
7225 oi
"aalevel" c.aalevel
dc.aalevel
;
7226 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7227 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7228 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7229 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7230 oC
"color-space" c.colorspace
dc.colorspace
;
7231 ob "invert-colors" c.invert
dc.invert
;
7232 oF
"brightness" c.colorscale
dc.colorscale
;
7233 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7234 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7235 oco
"columns" c.columns
dc.columns
;
7236 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7237 os
"selection-command" c.selcmd
dc.selcmd
;
7238 os
"synctex-command" c.stcmd
dc.stcmd
;
7239 os
"pax-command" c.paxcmd
dc.paxcmd
;
7240 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7241 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7242 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7243 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7244 ob "use-pbo" c.usepbo
dc.usepbo
;
7245 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7246 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7247 op
"point-and-x" c.pax
dc.pax
;
7248 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7251 let keymapsbuf always
dc c =
7252 let bb = Buffer.create
16 in
7253 let rec loop = function
7255 | (modename, h) :: rest
->
7256 let dh = findkeyhash dc modename in
7257 if always
|| h <> dh
7259 if Hashtbl.length
h > 0
7261 if Buffer.length
bb > 0
7262 then Buffer.add_char
bb '
\n'
;
7263 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7264 Hashtbl.iter
(fun i
o ->
7265 let isdifferent = always
||
7267 let dO = Hashtbl.find dh i
in
7269 with Not_found
-> true
7274 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7275 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7276 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7277 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7278 Buffer.add_string
bb (Wsi.keyname
k);
7281 let rec loop = function
7283 | km
:: [] -> addkm km
7284 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7288 Buffer.add_string
bb "<map in='";
7292 Buffer.add_string
bb "' out='";
7294 Buffer.add_string
bb "'/>\n"
7297 Buffer.add_string
bb "' out='";
7299 Buffer.add_string
bb "'/>\n"
7301 | KMmulti
(ins, kms
) ->
7302 Buffer.add_char
bb ' '
;
7304 Buffer.add_string
bb "' out='";
7306 Buffer.add_string
bb "'/>\n"
7308 Buffer.add_string
bb "</keymap>";
7318 let uifontsize = fstate.fontsize
in
7319 let bb = Buffer.create
32768 in
7320 let relx = float state.x /. float state.winw in
7322 let cx w = truncate
(relx *. float w) in
7324 (fun (w, h, x) ws
->
7326 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7327 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7328 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7330 (state.winw, state.winh
, state.x) state.winstate
7335 let dc = if conf.bedefault
then conf else dc in
7336 Buffer.add_string
bb "<llppconfig>\n";
7338 if nonemptystr
!fontpath
7340 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7346 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7349 Buffer.add_string
bb "<defaults ";
7350 add_attrs bb true dc dc;
7351 let kb = keymapsbuf true dc dc in
7352 if Buffer.length
kb > 0
7354 Buffer.add_string
bb ">\n";
7355 Buffer.add_buffer
bb kb;
7356 Buffer.add_string
bb "\n</defaults>\n";
7358 else Buffer.add_string
bb "/>\n";
7360 let adddoc path pan
anchor c bookmarks =
7361 if bookmarks == [] && c = dc && anchor = emptyanchor
7364 Printf.bprintf
bb "<doc path='%s'"
7365 (enent
path 0 (String.length
path));
7367 if anchor <> emptyanchor
7369 let n, rely, visy
= anchor in
7370 Printf.bprintf
bb " page='%d'" n;
7373 Printf.bprintf
bb " rely='%f'" rely
7375 if abs_float visy
> 1e-6
7377 Printf.bprintf
bb " visy='%f'" visy
7382 then Printf.bprintf
bb " pan='%d'" pan
;
7384 add_attrs bb false dc c;
7385 let kb = keymapsbuf false dc c in
7387 begin match bookmarks with
7389 if Buffer.length
kb > 0
7391 Buffer.add_string
bb ">\n";
7392 Buffer.add_buffer
bb kb;
7393 Buffer.add_string
bb "\n</doc>\n";
7395 else Buffer.add_string
bb "/>\n"
7397 Buffer.add_string
bb ">\n<bookmarks>\n";
7398 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7400 "<item title='%s' page='%d'"
7401 (enent
title 0 (String.length
title))
7406 Printf.bprintf
bb " rely='%f'" rely
7408 if abs_float visy
> 1e-6
7410 Printf.bprintf
bb " visy='%f'" visy
7412 Buffer.add_string
bb "/>\n";
7414 Buffer.add_string
bb "</bookmarks>";
7415 if Buffer.length
kb > 0
7417 Buffer.add_string
bb "\n";
7418 Buffer.add_buffer
bb kb;
7420 Buffer.add_string
bb "\n</doc>\n";
7426 match state.mode with
7427 | Birdseye
(c, pan, _, _, _) ->
7429 match conf.columns
with
7430 | Cmulti
((c, _, _), _) -> Some
c
7434 match c.columns
with
7435 | Cmulti
(c, _) -> Cmulti
(c, [||])
7436 | Csingle
_ -> Csingle
[||]
7437 | Csplit
_ -> failwith
"quit from bird's eye while split"
7439 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7442 let basename = Filename.basename
7443 (if emptystr
state.origin
then state.path else state.origin
)
7445 adddoc basename pan (getanchor ())
7447 let autoscrollstep =
7448 match state.autoscroll
with
7450 | None
-> conf.autoscrollstep
7452 match state.mode with
7453 | Birdseye
(bc
, _, _, _, _) ->
7456 presentation
= bc
.presentation
;
7457 interpagespace
= bc
.interpagespace
;
7458 maxwait
= bc
.maxwait
;
7459 autoscrollstep = autoscrollstep }
7460 | _ -> { conf with autoscrollstep = autoscrollstep }
7462 (if conf.savebmarks
then state.bookmarks else []);
7464 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7466 then adddoc path x anchor c bookmarks
7468 Buffer.add_string
bb "</llppconfig>\n";
7471 if load1 f && Buffer.length
bb > 0
7474 let tmp = !confpath ^
".tmp" in
7475 let oc = open_out_bin
tmp in
7476 Buffer.output_buffer
oc bb;
7478 Unix.rename
tmp !confpath;
7481 ("error while saving configuration: " ^ exntos exn
)
7485 let adderrmsg src msg
=
7486 Buffer.add_string
state.errmsgs msg
;
7487 state.newerrmsgs
<- true;
7491 let adderrfmt src fmt
=
7492 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7496 let cl = splitatspace cmds
in
7498 try Scanf.sscanf
s fmt
f
7500 adderrfmt "remote exec"
7501 "error processing '%S': %s\n" cmds
(exntos exn
)
7504 | "reload" :: [] -> reload ()
7505 | "goto" :: args :: [] ->
7506 scan args "%u %f %f"
7508 let cmd, _ = state.geomcmds
in
7510 then gotopagexy pageno x y
7513 gotopagexy pageno x y;
7516 state.reprf
<- f state.reprf
7518 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7519 | "rect" :: args :: [] ->
7520 scan args "%u %u %f %f %f %f"
7521 (fun pageno color x0 y0 x1 y1 ->
7522 onpagerect pageno (fun w h ->
7523 let _,w1,h1
,_ = getpagedim pageno in
7524 let sw = float w1 /. float w
7525 and sh = float h1
/. float h in
7529 and y1s
= y1 *. sh in
7530 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7532 state.rects <- (pageno, color, rect) :: state.rects;
7533 G.postRedisplay "rect";
7536 | "activatewin" :: [] -> Wsi.activatewin
()
7537 | "quit" :: [] -> raise Quit
7539 adderrfmt "remote command"
7540 "error processing remote command: %S\n" cmds
;
7544 let scratch = String.create
80 in
7545 let buf = Buffer.create
80 in
7548 try Some
(Unix.read fd
scratch 0 80)
7550 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7551 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7554 match tempfr () with
7560 if Buffer.length
buf > 0
7562 let s = Buffer.contents
buf in
7572 let pos = String.index_from
scratch ppos '
\n'
in
7573 if pos >= n then -1 else pos
7574 with Not_found
-> -1
7578 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7579 let s = Buffer.contents
buf in
7585 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7591 let remoteopen path =
7592 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7594 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7599 let trimcachepath = ref "" in
7600 let rcmdpath = ref "" in
7601 selfexec := Sys.executable_name
;
7604 [("-p", Arg.String
(fun s -> state.password
<- s),
7605 "<password> Set password");
7609 Config.fontpath := s;
7610 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7612 "<path> Set path to the user interface font");
7616 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7617 Config.confpath := s),
7618 "<path> Set path to the configuration file");
7620 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7621 "<path> Set path to the trim cache file");
7623 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7624 "<named-destination> Set named destination");
7626 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7627 ("-cxack", Arg.Set
cxack, " Cut corners");
7629 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7630 "<path> Set path to the remote commands source");
7632 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7633 "<original-path> Set original path");
7635 ("-v", Arg.Unit
(fun () ->
7637 "%s\nconfiguration path: %s\n"
7641 exit
0), " Print version and exit");
7644 (fun s -> state.path <- s)
7645 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7648 then selfexec := !selfexec ^
" -wtmode";
7650 if emptystr
state.path
7651 then (prerr_endline
"file name missing"; exit
1);
7653 if not
(Config.load ())
7654 then prerr_endline
"failed to load configuration";
7656 let wsfd, winw, winh
= Wsi.init
(object
7657 val mutable m_hack
= false
7658 method expose
= if not m_hack
then G.postRedisplay "expose"
7659 method visible
= G.postRedisplay "visible"
7660 method display = m_hack
<- false; display ()
7661 method reshape w h =
7662 m_hack
<- w < state.winw && h < state.winh
;
7664 method mouse b d x y m = mouse b d x y m
7665 method motion x y = state.mpos
<- (x, y); motion x y
7666 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7668 let mascm = m land (
7669 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7671 match state.keystate
with
7673 let km = k, mascm in
7676 let modehash = state.uioh#
modehash in
7677 try Hashtbl.find modehash km
7679 try Hashtbl.find (findkeyhash conf "global") km
7680 with Not_found
-> KMinsrt
(k, m)
7682 | KMinsrt
(k, m) -> keyboard k m
7683 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7684 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7686 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7687 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7688 state.keystate
<- KSnone
7689 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7690 state.keystate
<- KSinto
(keys
, insrt
)
7692 state.keystate
<- KSnone
7694 method enter
x y = state.mpos
<- (x, y); pmotion x y
7695 method leave = state.mpos
<- (-1, -1)
7696 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7697 method quit
= raise Quit
7698 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7703 List.exists
GlMisc.check_extension
7704 [ "GL_ARB_texture_rectangle"
7705 ; "GL_EXT_texture_recangle"
7706 ; "GL_NV_texture_rectangle" ]
7708 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7711 let r = GlMisc.get_string `renderer
in
7712 let p = "Mesa DRI Intel(" in
7713 let l = String.length
p in
7714 String.length
r > l && String.sub
r 0 l = p
7717 defconf.sliceheight
<- 1024;
7718 defconf.texcount
<- 32;
7719 defconf.usepbo
<- true;
7723 match Ne.pipe () with
7725 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7729 match Ne.pipe () with
7731 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7741 setcheckers conf.checkers
;
7743 if conf.redirectstderr
7746 let s = Buffer.contents
state.errmsgs ^
7747 (match state.errfd
with
7749 let s = String.create
(80*24) in
7752 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7754 then Unix.read fd
s 0 (String.length
s)
7760 else String.sub
s 0 n
7764 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7765 with exn
-> print_endline
(exntos exn
)
7770 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7771 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7772 !Config.fontpath, !trimcachepath,
7773 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7777 state.text <- "Opening " ^
(mbtoutf8
state.path);
7779 opendoc state.path state.password
;
7783 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7786 if nonemptystr
!rcmdpath
7787 then remoteopen !rcmdpath
7792 let rec loop deadline
=
7794 match state.errfd
with
7795 | None
-> [state.sr
; state.wsfd]
7796 | Some fd
-> [state.sr
; state.wsfd; fd
]
7801 | Some fd
-> fd
:: r
7805 state.redisplay
<- false;
7812 if deadline
= infinity
7814 else max
0.0 (deadline
-. now)
7819 try Unix.select
r [] [] timeout
7820 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7826 if state.ghyll
== noghyll
7828 match state.autoscroll
with
7829 | Some step
when step
!= 0 ->
7830 let y = state.y + step
in
7834 else if y >= state.maxy then 0 else y
7837 if state.mode = View
7838 then state.text <- "";
7841 else deadline
+. 0.01
7846 let rec checkfds = function
7848 | fd
:: rest
when fd
= state.sr
->
7849 let cmd = readcmd state.sr
in
7853 | fd
:: rest
when fd
= state.wsfd ->
7857 | fd
:: rest
when Some fd
= !optrfd ->
7858 begin match remote fd
with
7859 | None
-> optrfd := remoteopen !rcmdpath;
7860 | opt -> optrfd := opt
7865 let s = String.create
80 in
7866 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7867 if conf.redirectstderr
7869 Buffer.add_substring
state.errmsgs
s 0 n;
7870 state.newerrmsgs
<- true;
7871 state.redisplay
<- true;
7874 prerr_string
(String.sub
s 0 n);
7882 if deadline
= infinity
7886 match state.autoscroll
with
7887 | Some step
when step
!= 0 -> deadline1
7888 | _ -> if state.ghyll
== noghyll then infinity
else deadline1