34
35:- module(pce_help_messages, []). 36:- use_module(library(pce)). 37
38:- pce_global(@help_message_window, new(help_message_window)).
39
40:- pce_begin_class(help_message_window, dialog,
41 ).
42
43class_variable(background, colour,
44 when(@pce?window_system == windows,
45 win_infobk,
46 burlywood1),
47 ).
48class_variable(foreground, colour,
49 when(@pce?window_system == windows,
50 win_infotext,
51 black)).
52
53variable(handler, handler, get, ).
54variable(message, string*, get, ).
55
56initialise(W) :->
57 send(W, slot, handler,
58 handler(mouse, message(W, try_hide, @event))),
59 send_super(W, initialise),
60 get(W, frame, Frame),
61 send(Frame, kind, popup),
62 send(Frame, sensitive, @off),
63 send(Frame, border, 0),
64 send(Frame?tile, border, 0),
65 send(W, gap, size(5, 2)),
66 ( get(@pce, window_system, windows) 67 -> send(W, pen, 1)
68 ; send(W, pen, 0)
69 ),
70 send(W, append, new(L, label(feedback, '', normal))),
71 send(L, length, 0),
72 send(Frame, create).
73
74owner(W, Owner:[any]*) :->
75 ::
76 ( Owner == @nil
77 -> send(W, delete_hypers, owner)
78 ; Owner == @default
79 -> true 80 ; new(_, help_hyper(Owner, W, help_baloon, owner))
81 ).
82owner(W, Owner:any) :<-
83 get(W, hypered, owner, Owner).
84
85
86try_hide(W, Ev:event) :->
87 get(W, owner, Owner),
88 ( send(Ev, inside, Owner),
89 ( send(Ev, is_a, loc_move)
90 ; send(Ev, is_a, loc_still)
91 )
92 -> 93 get(W, message, OldMsg),
94 ( get(Owner, help_message, tag, Ev, Msg)
95 -> 96 ( OldMsg \== @nil,
97 send(Msg, equal, OldMsg)
98 -> ( send(Ev, is_a, loc_still)
99 -> send(W, adjust_position, Ev)
100 ; true
101 )
102 ; send(W, feedback, Msg, Ev)
103 )
104 ; ( get(W, message, @nil)
105 -> true
106 ; send(W, feedback, @nil, Ev)
107 )
108 )
109 ; send(W, owner, @nil),
110 send(W, hide),
111 fail 112 ).
113
114
115hide(W) :->
116 ::
117 send(W, show, @off),
118 get(W, handler, H),
119 send(W?display?inspect_handlers, delete, H).
120
121
122feedback(W, S:string*, Ev:event, For:[any]*) :->
123 ::
124 send(W, owner, For),
125 send(W, slot, message, S),
126 ( S == @nil
127 -> send(W, show, @off)
128 ; get(W, member, feedback, L),
129 send(L, selection, S),
130 send(W, layout),
131 send(W?frame, fit),
132 send(W, adjust_position, Ev),
133 send(W?display, inspect_handler, W?handler)
134 ).
135
136
137adjust_position(W, Ev:event) :->
138 ::
139 get(Ev, position, W?display, P),
140 get(P, plus, point(5,5), point(FX, FY)),
141 send(W?frame, set, FX, FY),
142 send(W?frame, expose).
143
144:- pce_end_class.
145
146
147attribute_name(tag, help_tag).
148attribute_name(summary, help_summary).
149
150:- pce_extend_class(visual).
151
152help_message(Gr, What:{tag,summary}, Msg:string*) :->
153 ::
154 attribute_name(What, AttName),
155 ( Msg == @nil
156 -> send(Gr, delete_attribute, AttName)
157 ; send(Gr, attribute, AttName, Msg)
158 ).
159help_message(V, What:{tag,summary}, _Ev:[event], Msg:string) :<-
160 attribute_name(What, AttName),
161 get(V, attribute, AttName, Msg).
162
163:- pce_end_class.
164
165
166:- pce_extend_class(graphical).
167
168show_help_message(Gr, What:name, Ev:event) :->
169 find_help_message(Gr, What, Ev, Owner, Msg),
170 send(@help_message_window, feedback, Msg, Ev, Owner).
171
172
173find_help_message(Gr, What, Ev, Gr, Msg) :-
174 get(Gr, help_message, What, Ev, Msg),
175 !.
176find_help_message(Gr, What, Ev, Owner, Msg) :-
177 get(Gr, contained_in, Container),
178 find_help_message(Container, What, Ev, Owner, Msg).
179
180:- pce_end_class.
181
182
183:- pce_extend_class(menu).
184
185help_message(Gr, What:{tag,summary}, Ev:[event], Msg:string) :<-
186 ::
187 ( get(Gr, item_from_event, Ev, Item),
188 get(Item, help_message, What, Msg)
189 -> true
190 ; get(Gr, get_super, help_message, What, Ev, Msg)
191 ).
192
193:- pce_end_class.
194
195
196:- pce_begin_class(help_hyper, hyper,
197 ).
198
199unlink_from(H) :->
200 ::
201 get(H, to, Part),
202 ( object(Part)
203 -> send(Part, hide)
204 ; free(Part)
205 ),
206 free(H).
207
208:- pce_end_class.
209
210 213
214register_help_message_window :-
215 send(@display, inspect_handler,
216 handler(loc_still,
217 message(@receiver, show_help_message, tag, @event))),
218 send(@display, inspect_handler,
219 handler(help,
220 message(@receiver, show_help_message, summary, @event))).
221
222:- initialization
223 register_help_message_window.