1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
/* Part of XPCE --- The SWI-Prolog GUI toolkit
Author: Jan Wielemaker and Anjo Anjewierden
E-mail: jan@swi.psy.uva.nl
WWW: http://www.swi.psy.uva.nl/projects/xpce/
Copyright (c) 2000-2015, University of Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
:- module(browser_classes, []).
:- use_module(library(pce)).
:- use_module(doc(util)).
:- use_module(doc(emit)).
:- use_module(doc(vfont)).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Support classes for the html rendering package. Defines the classes:
# pbox
Refinement of class parbox with event-handling, etc.
# button_box
hbox for labeling buttons
# anchor_box
hbox for labeling anchors
# bullet_list
lbox for dealing with bulletted lists (<UL>)
# enum_list
lbox for dealing with ordered lists (<OL>)
# definition_list
lbox for dealing with definition lists <DL>
# doc_mode
Style and font handling
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*******************************
* PBOX *
*******************************/
:- pce_begin_class(pbox, parbox, "Refined parbox for viewer").
class_variable(auto_crop, bool, @on).
:- pce_global(@pbox_recogniser,
new(click_gesture(left, '', single,
message(@receiver, clicked, @event)))).
event(PB, Ev:event) :->
( send_super(PB, event, Ev)
; send(@pbox_recogniser, event, Ev)
; send(Ev, is_a, loc_move),
send(PB, show_location, Ev)
).
clicked(PB, Ev:event) :->
get(PB, locate_event, Ev, Index),
( get(PB, box, Index, Box),
get(Box, attribute, footnote, Footnote)
-> send(PB, show_note, Footnote)
; find_button(PB, Index, Button),
get(Button, message, Message),
send(Message, forward, Button)
-> true
; debugging(parbox),
get(PB, box_area, Index, area(X,Y,W,H)),
send(PB, display, box(W, H), point(X, Y))
).
find_button(PB, Index, Button) :-
find_button(PB, Index, Index, 100, Button).
find_button(PB, Index0, Index, _, CB) :-
get(PB, box, Index, CB),
send(CB, instance_of, button_box),
get(CB, hypered, open, OB),
get(PB?content, index, OB, OpenIndex),
OpenIndex =< Index0,
!.
find_button(PB, Index0, Index, MaxDist, CB) :-
Index1 is Index+1,
Index0+MaxDist > Index,
find_button(PB, Index0, Index1, MaxDist, CB).
show_note(_, Note:graphical) :->
get(Note, size, Size),
send(Note, lock_object, @on),
new(W, window('Footnote', size := Size)),
send(W, kind, popup),
send(W, display, Note),
send(W, recogniser,
new(C, click_gesture(left, '', single,
message(W, free)))),
send(W, focus, W, C, @nil, @nil),
get(@event, position, @display, Pos),
send(W, open, Pos, @on).
:- dynamic
showing/1. % actually we should use the frame for this
show_location(PB, Ev:event) :->
get(PB, locate_event, Ev, Index),
( find_button(PB, Index, Button),
get(Button, balloon, Text),
Text \== @nil
-> true
; Text = ''
),
( showing(Text)
-> true
; retractall(showing(_)),
assert(showing(Text)),
send(PB, report, status, Text)
).
anchor(PB, Anchor:name, Reply:tuple) :<-
"Find tuple(Box, Index) defining this anchor"::
get(PB, find,
and(message(@arg1, instance_of, anchor_box),
@arg1?identifier == Anchor),
Reply).
url(PB, URL:name) :<-
"Represented URL"::
get(PB, window, Window),
catch(get(Window, url, URL), _, fail).
show(PB, Content:prolog, Mode:mode=[doc_mode]) :->
"Render list of commands in this box"::
( Mode == @default
-> new(M, doc_mode)
; M = Mode
),
( Content = element(_,_,_)
-> emit([Content], PB, M)
; emit(Content, PB, M)
).
% send(PB, compute).
:- pce_end_class.
/*******************************
* BUTTON *
*******************************/
:- pce_begin_class(button_box, hbox,
"Open/close buttons").
variable(message, code*, both, "Message executed on click").
variable(balloon, string*, both, "Message displayed when hooveing").
initialise(B, Message:code*, Balloon:[string]*) :->
default(Balloon, @nil, Text),
send_super(B, initialise),
send(B, message, Message),
send(B, balloon, Text).
:- pce_end_class.
:- pce_begin_class(anchor_box, hbox,
"End-point of a link").
variable(identifier, name*, get, "Identifier (label)").
initialise(B, Id:any) :->
send_super(B, initialise),
send(B, slot, identifier, Id).
:- pce_end_class.
/*******************************
* BULLET LIST *
*******************************/
:- pce_begin_class(bullet_list, lbox, "TeX bulletlist environment").
class_variable(item_sep, '0..', 0).
new_label(_, Label:graphical) :<-
new(Label, circle(8)),
send(Label, fill_pattern, @black_image).
make_item(BL, Item:prolog, Mode:mode, PB:parbox) :<-
"Create a new item"::
( Item == []
-> Label = @default
; get(BL, label_width, LW),
new(Label, pbox(LW, right)),
get(Mode, clone, Clone),
emit(Item, Label, Clone)
),
get(Mode, alignment, Align),
send(BL, append, Label, new(PB, pbox(0, Align))).
:- pce_end_class.
/*******************************
* ENUMERATE *
*******************************/
:- pce_begin_class(enum_list, lbox, "TeX enumerate environment").
variable(index, int := 0, both, "Current index").
new_label(EN, Label:graphical) :<-
get(EN, index, I0),
I is I0 + 1,
send(EN, index, I),
new(Label, text(I, right, normal)).
make_item(BL, Item:prolog, Mode:mode, PB:parbox) :<-
"Create a new item"::
( Item == []
-> Label = @default
; get(BL, label_width, LW),
new(Label, pbox(LW, right)),
get(Mode, clone, Clone),
emit(Item, Label, Clone)
),
get(Mode, alignment, Align),
send(BL, append, Label, new(PB, pbox(0, Align))).
:- pce_end_class.
/*******************************
* DESCRIPTION *
*******************************/
:- pce_begin_class(definition_list, lbox, "HTML <DL> element").
make_item(DL, Item:prolog, Mode:mode, PB:parbox) :<-
"Create a new item"::
get(Mode, alignment, Align),
get(DL, item_width, IW),
send(DL, append, @default, new(PB, pbox(IW, Align))),
get(DL, left_margin, LM),
send(PB, append, hbox(-LM)),
get(Mode, clone, Clone),
append(Item, [@br], Label),
emit([\setfont(weight, bold) | Label], PB, Clone).
:- pce_end_class.
/*******************************
* CLASS DOC-MODE *
*******************************/
:- pce_begin_class(doc_mode, object, "Parameters of rendering engine").
variable(style, style, get, "Basic text style").
variable(parsep, hbox, get, "Amount to skip for paragraph").
variable(parindent, hbox, get, "Indentation for paragraph").
variable(alignment, name, both, "Default paragraph alignment").
variable(vfont, vfont, get, "Virtual font").
variable(space, hbox, get, "Space in current font").
variable(base_url, name:='', both, "Reference URL").
variable(ignore_blanks, [name], both, "How to handle blanks").
variable(space_mode, {preserve,canonical}, both, "How to handle blanks").
variable(link_colour, colour, both, "Colour for hyperlinks").
class_variable(alignment, name, justify).
initialise(M) :->
send_super(M, initialise),
send(M, slot, vfont, new(VFont, vfont)),
send(M, slot, link_colour, colour(dark_green)),
send(M, slot, style, style(font := VFont?font)),
send(M, slot, ignore_blanks, @default),
send(M, set_font, family, helvetica),
send(M, slot, parsep, hbox(0,8)), % vertical skip
send(M, slot, parindent, hbox(0,0)), % horizontal skip
send(M, space_mode, canonical).
set_font(M, Att:name, Val:any) :->
"Set a font attribute"::
get(M, vfont, VFont),
send(VFont, Att, Val),
get(VFont, font, Font),
send(M?style, font, Font),
get(Font, advance, ' ', SW),
get(Font, ascent, Ascent),
get(Font, descent, Descent),
send(M, slot, space, hbox(SW, Ascent, Descent, @space_rubber)).
colour(M, Colour:colour) :->
"Set text-foreground colour"::
send(M?style, colour, Colour).
underline(M, OnOff:bool) :->
"Set text underline"::
send(M?style, underline, OnOff).
:- pce_end_class.
|