1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : AW_window.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "aw_at.hxx" |
---|
12 | #include "aw_nawar.hxx" |
---|
13 | #include "aw_xfig.hxx" |
---|
14 | #include "aw_Xm.hxx" |
---|
15 | #include "aw_window.hxx" |
---|
16 | #include "aw_window_Xm.hxx" |
---|
17 | #include "aw_xkey.hxx" |
---|
18 | #include "aw_select.hxx" |
---|
19 | #include "aw_awar.hxx" |
---|
20 | #include "aw_msg.hxx" |
---|
21 | #include "aw_root.hxx" |
---|
22 | #include "aw_xargs.hxx" |
---|
23 | #include "aw_device_click.hxx" |
---|
24 | |
---|
25 | #include <arbdbt.h> |
---|
26 | #include <arb_file.h> |
---|
27 | #include <arb_str.h> |
---|
28 | #include <arb_strarray.h> |
---|
29 | |
---|
30 | #include <X11/Shell.h> |
---|
31 | #include <Xm/AtomMgr.h> |
---|
32 | #include <Xm/Frame.h> |
---|
33 | #include <Xm/PushB.h> |
---|
34 | #include <Xm/Protocols.h> |
---|
35 | #include <Xm/RowColumn.h> |
---|
36 | #include <Xm/DrawingA.h> |
---|
37 | #include <Xm/Form.h> |
---|
38 | #include <Xm/Separator.h> |
---|
39 | #include <Xm/MainW.h> |
---|
40 | #include <Xm/CascadeB.h> |
---|
41 | #include <Xm/MenuShell.h> |
---|
42 | #include <Xm/ScrollBar.h> |
---|
43 | #include <Xm/MwmUtil.h> |
---|
44 | |
---|
45 | #include "aw_question.hxx" |
---|
46 | |
---|
47 | #include <cctype> |
---|
48 | #include <map> |
---|
49 | #include <string> |
---|
50 | |
---|
51 | void AW_POPDOWN(AW_window *window){ |
---|
52 | window->hide(); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * CB wrapper for create_*_window calls to ensure that a window |
---|
57 | * is only created once. |
---|
58 | */ |
---|
59 | |
---|
60 | #if defined(DEBUG) |
---|
61 | #define NOWINWARN() fputs("window factory did not create a window\n", stderr) |
---|
62 | #else |
---|
63 | #define NOWINWARN() |
---|
64 | #endif |
---|
65 | |
---|
66 | static AW_window *find_or_createAndRegisterWindow(CreateWindowCallback *windowMaker) { |
---|
67 | typedef std::map<CreateWindowCallback, AW_window*> window_map; |
---|
68 | |
---|
69 | static window_map window; // previously popped up windows |
---|
70 | CreateWindowCallback& maker = *windowMaker; |
---|
71 | |
---|
72 | if (window.find(maker) == window.end()) { |
---|
73 | AW_window *made = maker(AW_root::SINGLETON); |
---|
74 | if (!made) { NOWINWARN(); return NULL; } |
---|
75 | |
---|
76 | window[maker] = made; |
---|
77 | } |
---|
78 | return window[maker]; |
---|
79 | } |
---|
80 | |
---|
81 | void AW_window::popper(AW_window *, CreateWindowCallback *windowMaker) { |
---|
82 | AW_window *toPopup = find_or_createAndRegisterWindow(windowMaker); |
---|
83 | if (toPopup) toPopup->activate(); |
---|
84 | } |
---|
85 | void AW_window::replacer(AW_window *caller, CreateWindowCallback *windowMaker) { |
---|
86 | AW_window *toPopup = find_or_createAndRegisterWindow(windowMaker); |
---|
87 | if (toPopup) { |
---|
88 | toPopup->activate(); |
---|
89 | caller->hide(); |
---|
90 | } |
---|
91 | } |
---|
92 | void AW_window::destroyCreateWindowCallback(CreateWindowCallback *windowMaker) { |
---|
93 | delete windowMaker; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | void AW_window::label(const char *_label) { |
---|
98 | freedup(_at->label_for_inputfield, _label); |
---|
99 | } |
---|
100 | |
---|
101 | // ---------------------------------------------------------------------- |
---|
102 | // force-diff-sync 1927391236 (remove after merging back to trunk) |
---|
103 | // ---------------------------------------------------------------------- |
---|
104 | |
---|
105 | void AW_window::get_window_size(int &width, int &height){ |
---|
106 | unsigned short hoffset = 0; |
---|
107 | if (p_w->menu_bar[0]) XtVaGetValues(p_w->menu_bar[0], XmNheight, &hoffset, NULL); |
---|
108 | width = _at->max_x_size; |
---|
109 | height = hoffset + _at->max_y_size; |
---|
110 | } |
---|
111 | |
---|
112 | void AW_window::help_text(const char *id) { |
---|
113 | //! set help text for next created button |
---|
114 | delete _at->helptext_for_next_button; // @@@ delete/free mismatch |
---|
115 | _at->helptext_for_next_button = strdup(id); |
---|
116 | } |
---|
117 | |
---|
118 | void AW_window::highlight() { |
---|
119 | //! make next created button default button |
---|
120 | _at->highlight = true; |
---|
121 | } |
---|
122 | |
---|
123 | void AW_window::sens_mask(AW_active mask) { |
---|
124 | //! Set up sensitivity mask for next widget (action) |
---|
125 | aw_assert(legal_mask(mask)); |
---|
126 | _at->widget_mask = mask; |
---|
127 | } |
---|
128 | |
---|
129 | void AW_window::callback(const WindowCallback& wcb) { |
---|
130 | /*! |
---|
131 | * Register callback for the next action implicitly created |
---|
132 | * when making a widget. |
---|
133 | */ |
---|
134 | _callback = new AW_cb(this, wcb); |
---|
135 | } |
---|
136 | |
---|
137 | void AW_window::d_callback(const WindowCallback& wcb) { |
---|
138 | /*! |
---|
139 | * Register double click callback for the next action implicitly created |
---|
140 | * when making a widget. |
---|
141 | */ |
---|
142 | _d_callback = new AW_cb(this, wcb); |
---|
143 | } |
---|
144 | |
---|
145 | // ------------------------------------------------------------- |
---|
146 | // code used by scalers (common between motif and gtk) |
---|
147 | |
---|
148 | static float apply_ScalerType(float val, AW_ScalerType scalerType, bool inverse) { |
---|
149 | float res = 0.0; |
---|
150 | |
---|
151 | aw_assert(val>=0.0 && val<=1.0); |
---|
152 | |
---|
153 | switch (scalerType) { |
---|
154 | case AW_SCALER_LINEAR: |
---|
155 | res = val; |
---|
156 | break; |
---|
157 | |
---|
158 | case AW_SCALER_EXP_LOWER: |
---|
159 | if (inverse) res = pow(val, 1/3.0); |
---|
160 | else res = pow(val, 3.0); |
---|
161 | break; |
---|
162 | |
---|
163 | case AW_SCALER_EXP_UPPER: |
---|
164 | res = 1.0-apply_ScalerType(1.0-val, AW_SCALER_EXP_LOWER, inverse); |
---|
165 | break; |
---|
166 | |
---|
167 | case AW_SCALER_EXP_BORDER: |
---|
168 | inverse = !inverse; |
---|
169 | // fall-through |
---|
170 | case AW_SCALER_EXP_CENTER: { |
---|
171 | AW_ScalerType subType = inverse ? AW_SCALER_EXP_UPPER : AW_SCALER_EXP_LOWER; |
---|
172 | if (val>0.5) res = (1+apply_ScalerType(2*val-1, subType, false))/2; |
---|
173 | else if (val<0.5) res = (1-apply_ScalerType(1-2*val, subType, false))/2; |
---|
174 | else res = val; |
---|
175 | break; |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | aw_assert(res>=0.0 && res<=1.0); |
---|
180 | |
---|
181 | return res; |
---|
182 | } |
---|
183 | |
---|
184 | float AW_ScalerTransformer::scaler2awar(float scaler, AW_awar *awar) { |
---|
185 | float amin = awar->get_min(); |
---|
186 | float amax = awar->get_max(); |
---|
187 | float modScaleRel = apply_ScalerType(scaler, type, false); |
---|
188 | float aval = amin + modScaleRel*(amax-amin); |
---|
189 | |
---|
190 | return aval; |
---|
191 | } |
---|
192 | |
---|
193 | float AW_ScalerTransformer::awar2scaler(AW_awar *awar) { |
---|
194 | float amin = awar->get_min(); |
---|
195 | float amax = awar->get_max(); |
---|
196 | |
---|
197 | float awarRel = 0.0; |
---|
198 | switch (awar->variable_type) { |
---|
199 | case AW_FLOAT: |
---|
200 | awarRel = (awar->read_float()-amin) / (amax-amin); |
---|
201 | break; |
---|
202 | |
---|
203 | case AW_INT: |
---|
204 | awarRel = (awar->read_int()-amin) / (amax-amin); |
---|
205 | break; |
---|
206 | |
---|
207 | default: |
---|
208 | GBK_terminatef("Unsupported awar type %i in calculate_scaler_value", int(awar->variable_type)); |
---|
209 | break; |
---|
210 | } |
---|
211 | |
---|
212 | aw_assert(awarRel>=0.0 && awarRel<=1.0); |
---|
213 | |
---|
214 | return apply_ScalerType(awarRel, type, true); |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | // ---------------------------------------------------------------------- |
---|
219 | // force-diff-sync 7284637824 (remove after merging back to trunk) |
---|
220 | // ---------------------------------------------------------------------- |
---|
221 | |
---|
222 | static unsigned timed_window_title_cb(AW_root*, char *title, AW_window *aw) { |
---|
223 | aw->number_of_timed_title_changes--; |
---|
224 | if (!aw->number_of_timed_title_changes) { |
---|
225 | aw->set_window_title_intern(title); |
---|
226 | } |
---|
227 | |
---|
228 | delete title; |
---|
229 | return 0; // do not recall |
---|
230 | } |
---|
231 | |
---|
232 | void AW_window::message(char *title, int ms) { |
---|
233 | char *old_title = NULL; |
---|
234 | |
---|
235 | number_of_timed_title_changes++; |
---|
236 | |
---|
237 | old_title = strdup(window_name); |
---|
238 | |
---|
239 | XtVaSetValues(p_w->shell, XmNtitle, title, NULL); |
---|
240 | |
---|
241 | get_root()->add_timed_callback(ms, makeTimedCallback(timed_window_title_cb, old_title, this)); |
---|
242 | } |
---|
243 | |
---|
244 | // ---------------------------------------------------------------------- |
---|
245 | // force-diff-sync 1284672342939 (remove after merging back to trunk) |
---|
246 | // ---------------------------------------------------------------------- |
---|
247 | |
---|
248 | // ------------------------- |
---|
249 | // Hotkey Checking |
---|
250 | |
---|
251 | #if defined(DEBUG) |
---|
252 | #define CHECK_DUPLICATED_MNEMONICS |
---|
253 | #endif |
---|
254 | |
---|
255 | #ifdef CHECK_DUPLICATED_MNEMONICS |
---|
256 | |
---|
257 | inline char oppositeCase(char c) { |
---|
258 | return isupper(c) ? tolower(c) : toupper(c); |
---|
259 | } |
---|
260 | static void strcpy_overlapping(char *dest, char *src) { |
---|
261 | int src_len = strlen(src); |
---|
262 | memmove(dest, src, src_len+1); |
---|
263 | } |
---|
264 | static const char *possible_mnemonics(const char *used_mnemonics, bool top_level, const char *topic_name) { |
---|
265 | static char *unused; |
---|
266 | for (int fromTopic = 1; fromTopic>=0; --fromTopic) { |
---|
267 | freedup(unused, fromTopic ? topic_name : "abcdefghijklmnopqrstuvwxyz"); |
---|
268 | |
---|
269 | for (int t = 0; unused[t]; ++t) { |
---|
270 | bool remove = false; |
---|
271 | if ((top_level && !isalpha(unused[t])) || !isalnum(unused[t])) { // remove useless chars |
---|
272 | remove = true; |
---|
273 | } |
---|
274 | else { |
---|
275 | char *dup = strchr(unused, unused[t]); |
---|
276 | if (dup && (dup-unused)<t) { // remove duplicated chars |
---|
277 | remove = true; |
---|
278 | } |
---|
279 | else { |
---|
280 | dup = strchr(unused, oppositeCase(unused[t])); |
---|
281 | if (dup && (dup-unused)<t) { // char is duplicated with opposite case |
---|
282 | dup[0] = toupper(dup[0]); // prefer upper case |
---|
283 | remove = true; |
---|
284 | } |
---|
285 | } |
---|
286 | } |
---|
287 | if (remove) { |
---|
288 | strcpy_overlapping(unused+t, unused+t+1); |
---|
289 | --t; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | for (int t = 0; used_mnemonics[t]; ++t) { |
---|
294 | char c = used_mnemonics[t]; // upper case! |
---|
295 | char *u = strchr(unused, c); |
---|
296 | if (u) strcpy_overlapping(u, u+1); // remove char |
---|
297 | u = strchr(unused, tolower(c)); |
---|
298 | if (u) strcpy_overlapping(u, u+1); // remove char |
---|
299 | } |
---|
300 | |
---|
301 | if (unused[0]) { |
---|
302 | if (!fromTopic) { |
---|
303 | freeset(unused, GBS_global_string_copy("unused but not in topic: \"%s\"", unused)); |
---|
304 | } |
---|
305 | break; |
---|
306 | } |
---|
307 | } |
---|
308 | return unused; |
---|
309 | } |
---|
310 | |
---|
311 | class MnemonicScope : virtual Noncopyable { |
---|
312 | typedef std::map<char,std::string> Char2Topic; |
---|
313 | |
---|
314 | std::string name; // of menu or window |
---|
315 | MnemonicScope *parent; |
---|
316 | StrArray requested; // topics lacking sufficient mnemonic |
---|
317 | Char2Topic accepted; // accepted mnemonics (key = uppercase hotkey, value=topic) |
---|
318 | |
---|
319 | void print_at_menu(FILE *out) { |
---|
320 | if (parent) { |
---|
321 | parent->print_at_menu(out); |
---|
322 | fputc('|', out); |
---|
323 | } |
---|
324 | fputs(name.c_str(), out); |
---|
325 | } |
---|
326 | void print_at_location(FILE *out, const char *topic) { |
---|
327 | fputs(" (", out); |
---|
328 | print_at_menu(out); |
---|
329 | fprintf(out, "|%s)\n", topic); |
---|
330 | } |
---|
331 | |
---|
332 | void requestPossibilities(const char *topic_name) { |
---|
333 | // will be shown delayed (when menu closes) |
---|
334 | if (requested.index_of(topic_name) == -1) { // avoid duplicates |
---|
335 | requested.put(strdup(topic_name)); |
---|
336 | } |
---|
337 | } |
---|
338 | |
---|
339 | void showRequestedPossibilities() { |
---|
340 | unsigned size = accepted.size(); |
---|
341 | char *used = new char[size+1]; |
---|
342 | |
---|
343 | int i = 0; |
---|
344 | for (Char2Topic::iterator a = accepted.begin(); a != accepted.end(); ++a) { |
---|
345 | used[i++] = a->first; |
---|
346 | } |
---|
347 | used[size] = 0; |
---|
348 | |
---|
349 | for (i = 0; requested[i]; ++i) { |
---|
350 | const char *possible = possible_mnemonics(used, !parent, requested[i]); |
---|
351 | fprintf(stderr, "Warning: Possible mnemonics for '%s': '%s'\n", requested[i], possible); |
---|
352 | } |
---|
353 | |
---|
354 | delete [] used; |
---|
355 | } |
---|
356 | |
---|
357 | void warn_mnemonic(const char *topic_name, const char *mnemonic, const char *warning) { |
---|
358 | fprintf(stderr, "Warning: mnemonic '%s' %s", mnemonic, warning); |
---|
359 | print_at_location(stderr, topic_name); |
---|
360 | } |
---|
361 | |
---|
362 | public: |
---|
363 | |
---|
364 | MnemonicScope(const char *name_, MnemonicScope *parent_) |
---|
365 | : name(name_), |
---|
366 | parent(parent_) |
---|
367 | {} |
---|
368 | |
---|
369 | ~MnemonicScope() { |
---|
370 | showRequestedPossibilities(); |
---|
371 | } |
---|
372 | |
---|
373 | void add(const char *topic_name, const char *mnemonic); |
---|
374 | |
---|
375 | MnemonicScope *get_parent() { return parent; } |
---|
376 | }; |
---|
377 | |
---|
378 | static MnemonicScope *current_mscope = NULL; |
---|
379 | static MnemonicScope *help_mscope = NULL; |
---|
380 | |
---|
381 | void MnemonicScope::add(const char *topic_name, const char *mnemonic) { |
---|
382 | if (mnemonic && mnemonic[0] != 0) { |
---|
383 | if (mnemonic[1]) { // longer than 1 char -> wrong |
---|
384 | warn_mnemonic(topic_name, mnemonic, "is too long; only 1 character allowed"); |
---|
385 | } |
---|
386 | |
---|
387 | if (AW_IS_IMAGEREF(topic_name)) { |
---|
388 | if (mnemonic[0]) { |
---|
389 | warn_mnemonic(topic_name, mnemonic, "is useless for graphical menu entry"); |
---|
390 | } |
---|
391 | } |
---|
392 | else if (!isalpha(mnemonic[0]) && !get_parent()) { // do not allow top-level numeric mnemonics |
---|
393 | warn_mnemonic(topic_name, mnemonic, "is invalid (allowed: a-z)"); |
---|
394 | requestPossibilities(topic_name); |
---|
395 | } |
---|
396 | else if (!isalnum(mnemonic[0])) { |
---|
397 | warn_mnemonic(topic_name, mnemonic, "is invalid (allowed: a-z and 0-9)"); |
---|
398 | requestPossibilities(topic_name); |
---|
399 | } |
---|
400 | else { |
---|
401 | char *TOPIC_NAME = ARB_strupper(strdup(topic_name)); |
---|
402 | char HOTKEY = toupper(mnemonic[0]); // store hotkeys case-less (case does not matter when pressing the hotkey) |
---|
403 | |
---|
404 | if (strchr(TOPIC_NAME, HOTKEY)) { // occurs in menu text |
---|
405 | Char2Topic::iterator found = accepted.find(HOTKEY); |
---|
406 | |
---|
407 | if (found != accepted.end()) { |
---|
408 | warn_mnemonic(topic_name, mnemonic, "is used multiple times"); |
---|
409 | requestPossibilities(topic_name); |
---|
410 | requestPossibilities(found->second.c_str()); // show possibilities for accepted duplicate |
---|
411 | } |
---|
412 | else { |
---|
413 | accepted[HOTKEY] = topic_name; |
---|
414 | |
---|
415 | if (!strchr(topic_name, mnemonic[0])) { |
---|
416 | char *warning = GBS_global_string_copy("has wrong case, use '%c'", HOTKEY == mnemonic[0] ? tolower(HOTKEY) : HOTKEY); |
---|
417 | warn_mnemonic(topic_name, mnemonic, warning); |
---|
418 | free(warning); |
---|
419 | } |
---|
420 | } |
---|
421 | } |
---|
422 | else { |
---|
423 | warn_mnemonic(topic_name, mnemonic, "is useless; does not occur in text"); |
---|
424 | requestPossibilities(topic_name); |
---|
425 | } |
---|
426 | free(TOPIC_NAME); |
---|
427 | } |
---|
428 | } |
---|
429 | else { |
---|
430 | if (!AW_IS_IMAGEREF(topic_name)) { |
---|
431 | fputs("Warning: mnemonic is missing", stderr); |
---|
432 | print_at_location(stderr, topic_name); |
---|
433 | requestPossibilities(topic_name); |
---|
434 | } |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | static void open_test_duplicate_mnemonics(const char *sub_menu_name, const char *mnemonic) { |
---|
439 | aw_assert(current_mscope); |
---|
440 | current_mscope->add(sub_menu_name, mnemonic); |
---|
441 | |
---|
442 | MnemonicScope *prev = current_mscope; |
---|
443 | current_mscope = new MnemonicScope(sub_menu_name, prev); |
---|
444 | } |
---|
445 | |
---|
446 | static void close_test_duplicate_mnemonics() { |
---|
447 | MnemonicScope *prev = current_mscope->get_parent(); |
---|
448 | delete current_mscope; |
---|
449 | current_mscope = prev; |
---|
450 | } |
---|
451 | |
---|
452 | static void init_duplicate_mnemonic(const char *window_name) { |
---|
453 | if (!current_mscope) { |
---|
454 | current_mscope = new MnemonicScope(window_name, NULL); |
---|
455 | help_mscope = new MnemonicScope("<HELP>", current_mscope); |
---|
456 | } |
---|
457 | else { |
---|
458 | while (current_mscope->get_parent()) { |
---|
459 | close_test_duplicate_mnemonics(); |
---|
460 | } |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | static void test_duplicate_mnemonics(const char *topic_name, const char *mnemonic) { |
---|
465 | aw_assert(current_mscope); |
---|
466 | current_mscope->add(topic_name, mnemonic); |
---|
467 | } |
---|
468 | |
---|
469 | static void exit_duplicate_mnemonic() { |
---|
470 | delete help_mscope; help_mscope = NULL; |
---|
471 | while (current_mscope) close_test_duplicate_mnemonics(); |
---|
472 | } |
---|
473 | |
---|
474 | |
---|
475 | #endif |
---|
476 | |
---|
477 | // ---------------------------------------------------------------------- |
---|
478 | // force-diff-sync 9273192739 (remove after merging back to trunk) |
---|
479 | // ---------------------------------------------------------------------- |
---|
480 | |
---|
481 | void AW_window::create_menu(AW_label name, const char *mnemonic, AW_active mask) { |
---|
482 | aw_assert(legal_mask(mask)); |
---|
483 | p_w->menu_deep = 0; |
---|
484 | |
---|
485 | #ifdef CHECK_DUPLICATED_MNEMONICS |
---|
486 | init_duplicate_mnemonic(window_name); |
---|
487 | #endif |
---|
488 | |
---|
489 | #if defined(DUMP_MENU_LIST) |
---|
490 | dumpCloseAllSubMenus(); |
---|
491 | #endif // DUMP_MENU_LIST |
---|
492 | insert_sub_menu(name, mnemonic, mask); |
---|
493 | } |
---|
494 | |
---|
495 | void AW_window::close_sub_menu() { |
---|
496 | /** |
---|
497 | * Closes the currently open sub menu. |
---|
498 | * If no menu is open this method will crash. |
---|
499 | */ |
---|
500 | #ifdef CHECK_DUPLICATED_MNEMONICS |
---|
501 | close_test_duplicate_mnemonics(); |
---|
502 | #endif |
---|
503 | #if defined(DUMP_MENU_LIST) |
---|
504 | dumpCloseSubMenu(); |
---|
505 | #endif // DUMP_MENU_LIST |
---|
506 | if (p_w->menu_deep>0) |
---|
507 | p_w->menu_deep--; |
---|
508 | } |
---|
509 | |
---|
510 | void AW_window::all_menus_created() const { // this is called by AW_window::show() (i.e. after all menus have been created) |
---|
511 | #if defined(DEBUG) |
---|
512 | if (p_w->menu_deep>0) { // window had menu |
---|
513 | aw_assert(p_w->menu_deep == 1); |
---|
514 | #ifdef CHECK_DUPLICATED_MNEMONICS |
---|
515 | exit_duplicate_mnemonic(); // cleanup mnemonic check |
---|
516 | #endif |
---|
517 | } |
---|
518 | #endif // DEBUG |
---|
519 | } |
---|
520 | |
---|
521 | // ---------------------------------------------------------------------- |
---|
522 | // force-diff-sync 2939128467234 (remove after merging back to trunk) |
---|
523 | // ---------------------------------------------------------------------- |
---|
524 | |
---|
525 | void AW_window::draw_line(int x1, int y1, int x2, int y2, int width, bool resize) { |
---|
526 | aw_assert(xfig_data); // forgot to call load_xfig ? |
---|
527 | |
---|
528 | xfig_data->add_line(x1, y1, x2, y2, width); |
---|
529 | |
---|
530 | _at->max_x_size = std::max(_at->max_x_size, xfig_data->maxx - xfig_data->minx); |
---|
531 | _at->max_y_size = std::max(_at->max_y_size, xfig_data->maxy - xfig_data->miny); |
---|
532 | |
---|
533 | if (resize) { |
---|
534 | recalc_size_atShow(AW_RESIZE_ANY); |
---|
535 | #if defined(ARB_MOTIF) |
---|
536 | set_window_size(WIDER_THAN_SCREEN, HIGHER_THAN_SCREEN); |
---|
537 | #endif |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | AW_device_click *AW_window::get_click_device(AW_area area, int mousex, int mousey, int max_distance) { |
---|
542 | AW_area_management *aram = MAP_ARAM(area); |
---|
543 | AW_device_click *click_device = NULL; |
---|
544 | |
---|
545 | if (aram) { |
---|
546 | click_device = aram->get_click_device(); |
---|
547 | click_device->init_click(AW::Position(mousex, mousey), max_distance, AW_ALL_DEVICES); |
---|
548 | } |
---|
549 | return click_device; |
---|
550 | } |
---|
551 | |
---|
552 | AW_device *AW_window::get_device(AW_area area) { // @@@ rename to get_screen_device |
---|
553 | AW_area_management *aram = MAP_ARAM(area); |
---|
554 | arb_assert(aram); |
---|
555 | return aram->get_screen_device(); |
---|
556 | } |
---|
557 | |
---|
558 | void AW_window::get_event(AW_event *eventi) const { |
---|
559 | *eventi = event; |
---|
560 | } |
---|
561 | |
---|
562 | AW_device_print *AW_window::get_print_device(AW_area area) { |
---|
563 | AW_area_management *aram = MAP_ARAM(area); |
---|
564 | return aram ? aram->get_print_device() : NULL; |
---|
565 | } |
---|
566 | |
---|
567 | AW_device_size *AW_window::get_size_device(AW_area area) { |
---|
568 | AW_area_management *aram = MAP_ARAM(area); |
---|
569 | if (!aram) return NULL; |
---|
570 | |
---|
571 | AW_device_size *size_device = aram->get_size_device(); |
---|
572 | if (size_device) { |
---|
573 | size_device->restart_tracking(); |
---|
574 | size_device->reset(); // @@@ hm |
---|
575 | } |
---|
576 | return size_device; |
---|
577 | } |
---|
578 | |
---|
579 | AW_common *AW_window::get_common(AW_area area) { |
---|
580 | AW_area_management *aram = MAP_ARAM(area); |
---|
581 | return aram ? aram->get_common() : NULL; |
---|
582 | } |
---|
583 | |
---|
584 | void AW_window::insert_help_topic(const char *labeli, |
---|
585 | const char *mnemonic, const char *helpText, |
---|
586 | AW_active mask, const WindowCallback& cb) { |
---|
587 | aw_assert(legal_mask(mask)); |
---|
588 | Widget button; |
---|
589 | |
---|
590 | #ifdef CHECK_DUPLICATED_MNEMONICS |
---|
591 | if (!current_mscope) init_duplicate_mnemonic(window_name); |
---|
592 | MnemonicScope *tmp = current_mscope; |
---|
593 | current_mscope = help_mscope; |
---|
594 | test_duplicate_mnemonics(labeli, mnemonic); |
---|
595 | current_mscope = tmp; |
---|
596 | #endif |
---|
597 | |
---|
598 | // insert one help-sub-menu-entry |
---|
599 | button = XtVaCreateManagedWidget("", xmPushButtonWidgetClass, |
---|
600 | p_w->help_pull_down, |
---|
601 | RES_CONVERT(XmNlabelString, labeli), |
---|
602 | RES_CONVERT(XmNmnemonic, mnemonic), NULL); |
---|
603 | XtAddCallback(button, XmNactivateCallback, |
---|
604 | (XtCallbackProc) AW_server_callback, |
---|
605 | (XtPointer) new AW_cb(this, cb, helpText)); |
---|
606 | |
---|
607 | root->make_sensitive(button, mask); |
---|
608 | } |
---|
609 | |
---|
610 | void AW_window::insert_menu_topic(const char *topic_id, const char *labeltext, |
---|
611 | const char *mnemonic, const char *helpText, |
---|
612 | AW_active mask, const WindowCallback& wcb) { |
---|
613 | aw_assert(legal_mask(mask)); |
---|
614 | Widget button; |
---|
615 | |
---|
616 | TuneBackground(p_w->menu_bar[p_w->menu_deep], TUNE_MENUTOPIC); // set background color for normal menu topics |
---|
617 | |
---|
618 | #if defined(DUMP_MENU_LIST) |
---|
619 | dumpMenuEntry(name); |
---|
620 | #endif // DUMP_MENU_LIST |
---|
621 | |
---|
622 | #ifdef CHECK_DUPLICATED_MNEMONICS |
---|
623 | test_duplicate_mnemonics(labeltext, mnemonic); |
---|
624 | #endif |
---|
625 | |
---|
626 | Label topiclabel(labeltext, this); |
---|
627 | if (mnemonic && *mnemonic && strchr(labeltext, mnemonic[0])) { |
---|
628 | // create one sub-menu-point |
---|
629 | button = XtVaCreateManagedWidget("", xmPushButtonWidgetClass, |
---|
630 | p_w->menu_bar[p_w->menu_deep], |
---|
631 | RES_LABEL_CONVERT(topiclabel), |
---|
632 | RES_CONVERT(XmNmnemonic, mnemonic), |
---|
633 | XmNbackground, _at->background_color, NULL); |
---|
634 | } |
---|
635 | else { |
---|
636 | button = XtVaCreateManagedWidget("", |
---|
637 | xmPushButtonWidgetClass, |
---|
638 | p_w->menu_bar[p_w->menu_deep], |
---|
639 | RES_LABEL_CONVERT(topiclabel), |
---|
640 | XmNbackground, _at->background_color, |
---|
641 | NULL); |
---|
642 | } |
---|
643 | |
---|
644 | AW_label_in_awar_list(this, button, labeltext); |
---|
645 | AW_cb *cbs = new AW_cb(this, wcb, helpText); |
---|
646 | XtAddCallback(button, XmNactivateCallback, |
---|
647 | (XtCallbackProc) AW_server_callback, |
---|
648 | (XtPointer) cbs); |
---|
649 | |
---|
650 | #if defined(DEVEL_RALF) // wanted version |
---|
651 | aw_assert(topic_id); |
---|
652 | #else // !defined(DEVEL_RALF) |
---|
653 | if (!topic_id) topic_id = labeltext; |
---|
654 | #endif |
---|
655 | cbs->id = strdup(topic_id); |
---|
656 | root->define_remote_command(cbs); |
---|
657 | root->make_sensitive(button, mask); |
---|
658 | } |
---|
659 | |
---|
660 | // ---------------------------------------------------------------------- |
---|
661 | // force-diff-sync 824638723647 (remove after merging back to trunk) |
---|
662 | // ---------------------------------------------------------------------- |
---|
663 | |
---|
664 | void AW_window::insert_sub_menu(const char *labeli, const char *mnemonic, AW_active mask){ |
---|
665 | aw_assert(legal_mask(mask)); |
---|
666 | Widget shell, Label; |
---|
667 | |
---|
668 | TuneBackground(p_w->menu_bar[p_w->menu_deep], TUNE_SUBMENU); // set background color for submenus |
---|
669 | // (Note: This must even be called if TUNE_SUBMENU is 0! |
---|
670 | // Otherwise several submenus get the TUNE_MENUTOPIC color) |
---|
671 | |
---|
672 | #if defined(DUMP_MENU_LIST) |
---|
673 | dumpOpenSubMenu(name); |
---|
674 | #endif // DUMP_MENU_LIST |
---|
675 | |
---|
676 | #ifdef CHECK_DUPLICATED_MNEMONICS |
---|
677 | open_test_duplicate_mnemonics(labeli, mnemonic); |
---|
678 | #endif |
---|
679 | |
---|
680 | // create shell for Pull-Down |
---|
681 | shell = XtVaCreatePopupShell("menu_shell", xmMenuShellWidgetClass, |
---|
682 | p_w->menu_bar[p_w->menu_deep], |
---|
683 | XmNwidth, 1, |
---|
684 | XmNheight, 1, |
---|
685 | XmNallowShellResize, true, |
---|
686 | XmNoverrideRedirect, true, |
---|
687 | NULL); |
---|
688 | |
---|
689 | // create row column in Pull-Down shell |
---|
690 | |
---|
691 | p_w->menu_bar[p_w->menu_deep+1] = XtVaCreateWidget("menu_row_column", |
---|
692 | xmRowColumnWidgetClass, shell, |
---|
693 | XmNrowColumnType, XmMENU_PULLDOWN, |
---|
694 | XmNtearOffModel, XmTEAR_OFF_ENABLED, |
---|
695 | NULL); |
---|
696 | |
---|
697 | // create label in menu bar |
---|
698 | if (mnemonic && *mnemonic && strchr(labeli, mnemonic[0])) { |
---|
699 | // if mnemonic is "" -> Cannot convert string "" to type KeySym |
---|
700 | Label = XtVaCreateManagedWidget("menu1_top_b1", |
---|
701 | xmCascadeButtonWidgetClass, p_w->menu_bar[p_w->menu_deep], |
---|
702 | RES_CONVERT(XmNlabelString, labeli), |
---|
703 | RES_CONVERT(XmNmnemonic, mnemonic), |
---|
704 | XmNsubMenuId, p_w->menu_bar[p_w->menu_deep+1], |
---|
705 | XmNbackground, _at->background_color, NULL); |
---|
706 | } |
---|
707 | else { |
---|
708 | Label = XtVaCreateManagedWidget("menu1_top_b1", |
---|
709 | xmCascadeButtonWidgetClass, |
---|
710 | p_w->menu_bar[p_w->menu_deep], |
---|
711 | RES_CONVERT(XmNlabelString, labeli), |
---|
712 | XmNsubMenuId, p_w->menu_bar[p_w->menu_deep+1], |
---|
713 | XmNbackground, _at->background_color, |
---|
714 | NULL); |
---|
715 | } |
---|
716 | |
---|
717 | if (p_w->menu_deep < AW_MAX_MENU_DEEP-1) p_w->menu_deep++; |
---|
718 | |
---|
719 | root->make_sensitive(Label, mask); |
---|
720 | } |
---|
721 | |
---|
722 | static void AW_xfigCB_info_area(AW_window *aww, AW_xfig *xfig) { |
---|
723 | AW_device *device = aww->get_device(AW_INFO_AREA); |
---|
724 | device->reset(); |
---|
725 | |
---|
726 | if (aww->get_root()->color_mode == 0) { // mono colr |
---|
727 | device->clear(-1); |
---|
728 | } |
---|
729 | device->set_offset(AW::Vector(-xfig->minx, -xfig->miny)); |
---|
730 | |
---|
731 | xfig->print(device); |
---|
732 | } |
---|
733 | |
---|
734 | void AW_window::get_font_size(int& width, int& height) { |
---|
735 | width = get_root()->font_width; |
---|
736 | height = get_root()->font_height; |
---|
737 | } |
---|
738 | |
---|
739 | // ---------------------------------------------------------------------- |
---|
740 | // force-diff-sync 264782364273 (remove after merging back to trunk) |
---|
741 | // ---------------------------------------------------------------------- |
---|
742 | |
---|
743 | void AW_window::load_xfig(const char *file, bool resize /*= true*/) { |
---|
744 | int width, height; |
---|
745 | get_font_size(width, height); |
---|
746 | |
---|
747 | if (file) xfig_data = new AW_xfig(file, width, height); |
---|
748 | else xfig_data = new AW_xfig(width, height); // create an empty xfig |
---|
749 | |
---|
750 | xfig_data->create_gcs(get_device(AW_INFO_AREA), get_root()->color_mode ? 8 : 1); |
---|
751 | |
---|
752 | // @@@ move into AW_at::set_xfig |
---|
753 | int xsize = xfig_data->maxx - xfig_data->minx; |
---|
754 | int ysize = xfig_data->maxy - xfig_data->miny; |
---|
755 | if (xsize>_at->max_x_size) _at->max_x_size = xsize; |
---|
756 | if (ysize>_at->max_y_size) _at->max_y_size = ysize; |
---|
757 | |
---|
758 | if (resize) { |
---|
759 | recalc_size_atShow(AW_RESIZE_ANY); |
---|
760 | #if defined(ARB_MOTIF) |
---|
761 | set_window_size(WIDER_THAN_SCREEN, HIGHER_THAN_SCREEN); |
---|
762 | #else |
---|
763 | // @@@ should not be needed in gtk, as soon as recalc_size_atShow has proper effect (see #377) |
---|
764 | // @@@ This is the last remaining use in gtk! Remove if removed here. |
---|
765 | set_window_size(_at->max_x_size, _at->max_y_size); |
---|
766 | #endif |
---|
767 | } |
---|
768 | |
---|
769 | set_expose_callback(AW_INFO_AREA, makeWindowCallback(AW_xfigCB_info_area, xfig_data)); |
---|
770 | } |
---|
771 | |
---|
772 | /** |
---|
773 | * Construct window-local id. |
---|
774 | * Prefixes @param id with AW_window::window_defaults_name + "/" |
---|
775 | */ |
---|
776 | const char *AW_window::local_id(const char *id) const { |
---|
777 | static char *last_local_id = 0; |
---|
778 | freeset(last_local_id, GBS_global_string_copy("%s/%s", get_window_id(), id)); |
---|
779 | return last_local_id; |
---|
780 | } |
---|
781 | |
---|
782 | void AW_window::sep______________() { |
---|
783 | //! insert a separator into the currently open menu |
---|
784 | XtVaCreateManagedWidget("", xmSeparatorWidgetClass, |
---|
785 | p_w->menu_bar[p_w->menu_deep], |
---|
786 | NULL); |
---|
787 | } |
---|
788 | |
---|
789 | /** |
---|
790 | * Registers @param wcb as expose callback. |
---|
791 | * Called whenever the @param area receives an expose event. |
---|
792 | * This is where any drawing should be handled. |
---|
793 | */ |
---|
794 | void AW_window::set_expose_callback(AW_area area, const WindowCallback& wcb) { |
---|
795 | AW_area_management *aram = MAP_ARAM(area); |
---|
796 | if (aram) aram->set_expose_callback(this, wcb); |
---|
797 | } |
---|
798 | |
---|
799 | static void AW_focusCB(Widget /*wgt*/, XtPointer cl_aww, XEvent*, Boolean*) { |
---|
800 | AW_window *aww = (AW_window*)cl_aww; |
---|
801 | aww->run_focus_callback(); |
---|
802 | } |
---|
803 | |
---|
804 | /** |
---|
805 | * Registers a focus callback. |
---|
806 | */ |
---|
807 | void AW_window::set_focus_callback(const WindowCallback& wcb) { |
---|
808 | if (!focus_cb) { |
---|
809 | XtAddEventHandler(MIDDLE_WIDGET, EnterWindowMask, FALSE, AW_focusCB, (XtPointer) this); |
---|
810 | } |
---|
811 | if (!focus_cb || !focus_cb->contains((AnyWinCB)wcb.callee())) { |
---|
812 | focus_cb = new AW_cb(this, wcb, 0, focus_cb); |
---|
813 | } |
---|
814 | } |
---|
815 | |
---|
816 | /** |
---|
817 | * Registers callback to be executed after the window is shown. |
---|
818 | * Called multiple times if a show() follows a hide(). |
---|
819 | */ |
---|
820 | void AW_window::set_popup_callback(const WindowCallback& wcb) { |
---|
821 | p_w->popup_cb = new AW_cb(this, wcb, 0, p_w->popup_cb); |
---|
822 | } |
---|
823 | |
---|
824 | void AW_window::set_info_area_height(int h) { |
---|
825 | XtVaSetValues(INFO_WIDGET, XmNheight, h, NULL); |
---|
826 | XtVaSetValues(p_w->frame, XmNtopOffset, h, NULL); |
---|
827 | } |
---|
828 | |
---|
829 | void AW_window::set_bottom_area_height(int h) { |
---|
830 | XtVaSetValues(BOTTOM_WIDGET, XmNheight, h, NULL); |
---|
831 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNbottomOffset, (int)h, NULL); |
---|
832 | } |
---|
833 | |
---|
834 | void AW_window::set_input_callback(AW_area area, const WindowCallback& wcb) { |
---|
835 | AW_area_management *aram = MAP_ARAM(area); |
---|
836 | if (aram) aram->set_input_callback(this, wcb); |
---|
837 | } |
---|
838 | |
---|
839 | void AW_window::set_motion_callback(AW_area area, const WindowCallback& wcb) { |
---|
840 | AW_area_management *aram = MAP_ARAM(area); |
---|
841 | if (aram) aram->set_motion_callback(this, wcb); |
---|
842 | } |
---|
843 | |
---|
844 | void AW_window::set_resize_callback(AW_area area, const WindowCallback& wcb) { |
---|
845 | AW_area_management *aram = MAP_ARAM(area); |
---|
846 | if (aram) aram->set_resize_callback(this, wcb); |
---|
847 | } |
---|
848 | |
---|
849 | // SCROLL BAR STUFF |
---|
850 | |
---|
851 | void AW_window::tell_scrolled_picture_size(AW_screen_area rectangle) { |
---|
852 | picture->l = rectangle.l; |
---|
853 | picture->r = rectangle.r; |
---|
854 | picture->t = rectangle.t; |
---|
855 | picture->b = rectangle.b; |
---|
856 | } |
---|
857 | |
---|
858 | void AW_window::tell_scrolled_picture_size(AW_world rectangle) { |
---|
859 | picture->l = (int)rectangle.l; |
---|
860 | picture->r = (int)rectangle.r; |
---|
861 | picture->t = (int)rectangle.t; |
---|
862 | picture->b = (int)rectangle.b; |
---|
863 | } |
---|
864 | |
---|
865 | AW_pos AW_window::get_scrolled_picture_width() const { |
---|
866 | return (picture->r - picture->l); |
---|
867 | } |
---|
868 | |
---|
869 | AW_pos AW_window::get_scrolled_picture_height() const { |
---|
870 | return (picture->b - picture->t); |
---|
871 | } |
---|
872 | |
---|
873 | void AW_window::reset_scrolled_picture_size() { |
---|
874 | picture->l = 0; |
---|
875 | picture->r = 0; |
---|
876 | picture->t = 0; |
---|
877 | picture->b = 0; |
---|
878 | } |
---|
879 | |
---|
880 | void AW_window::set_vertical_scrollbar_top_indent(int indent) { |
---|
881 | XtVaSetValues(p_w->scroll_bar_vertical, XmNtopOffset, (int)indent, NULL); |
---|
882 | top_indent_of_vertical_scrollbar = indent; |
---|
883 | } |
---|
884 | |
---|
885 | void AW_window::set_horizontal_scrollbar_left_indent(int indent) { |
---|
886 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNleftOffset, (int)indent, NULL); |
---|
887 | left_indent_of_horizontal_scrollbar = indent; |
---|
888 | } |
---|
889 | |
---|
890 | void AW_window::_get_area_size(AW_area area, AW_screen_area *square) { |
---|
891 | AW_area_management *aram = MAP_ARAM(area); |
---|
892 | *square = aram->get_common()->get_screen(); |
---|
893 | } |
---|
894 | |
---|
895 | void AW_window::get_scrollarea_size(AW_screen_area *square) { |
---|
896 | _get_area_size(AW_MIDDLE_AREA, square); |
---|
897 | square->r -= left_indent_of_horizontal_scrollbar; |
---|
898 | square->b -= top_indent_of_vertical_scrollbar; |
---|
899 | } |
---|
900 | |
---|
901 | void AW_window::calculate_scrollbars() { |
---|
902 | AW_screen_area scrollArea; |
---|
903 | get_scrollarea_size(&scrollArea); |
---|
904 | |
---|
905 | // HORIZONTAL |
---|
906 | { |
---|
907 | int slider_max = (int)get_scrolled_picture_width(); |
---|
908 | if (slider_max <1) { |
---|
909 | slider_max = 1; |
---|
910 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNsliderSize, 1, NULL); |
---|
911 | } |
---|
912 | |
---|
913 | bool use_horizontal_bar = true; |
---|
914 | int slider_size_horizontal = scrollArea.r; |
---|
915 | |
---|
916 | if (slider_size_horizontal < 1) slider_size_horizontal = 1; // ist der slider zu klein (<1) ? |
---|
917 | if (slider_size_horizontal > slider_max) { // Schirm groesser als Bild |
---|
918 | slider_size_horizontal = slider_max; // slider nimmt ganze laenge ein |
---|
919 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNvalue, 0, NULL); // slider ganz links setzen |
---|
920 | use_horizontal_bar = false; // kein horizontaler slider mehr |
---|
921 | } |
---|
922 | |
---|
923 | // check wether XmNValue is to big |
---|
924 | int position_of_slider; |
---|
925 | XtVaGetValues(p_w->scroll_bar_horizontal, XmNvalue, &position_of_slider, NULL); |
---|
926 | if (position_of_slider > (slider_max-slider_size_horizontal)) { // steht der slider fuer slidergroesse zu rechts ? |
---|
927 | position_of_slider = slider_max-slider_size_horizontal; // -1 ? vielleicht ! |
---|
928 | if (position_of_slider < 0) position_of_slider = 0; |
---|
929 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNvalue, position_of_slider, NULL); |
---|
930 | } |
---|
931 | // Anpassung fuer resize, wenn unbeschriebener Bereich vergroessert wird |
---|
932 | int max_slider_pos = (int)(get_scrolled_picture_width() - scrollArea.r); |
---|
933 | if (slider_pos_horizontal>max_slider_pos) { |
---|
934 | slider_pos_horizontal = use_horizontal_bar ? max_slider_pos : 0; |
---|
935 | } |
---|
936 | |
---|
937 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNsliderSize, 1, NULL); |
---|
938 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNmaximum, slider_max, NULL); |
---|
939 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNsliderSize, slider_size_horizontal, NULL); |
---|
940 | |
---|
941 | update_scrollbar_settings_from_awars(AW_HORIZONTAL); |
---|
942 | } |
---|
943 | |
---|
944 | // VERTICAL |
---|
945 | { |
---|
946 | int slider_max = (int)get_scrolled_picture_height(); |
---|
947 | if (slider_max <1) { |
---|
948 | slider_max = 1; |
---|
949 | XtVaSetValues(p_w->scroll_bar_vertical, XmNsliderSize, 1, NULL); |
---|
950 | } |
---|
951 | |
---|
952 | bool use_vertical_bar = true; |
---|
953 | int slider_size_vertical = scrollArea.b; |
---|
954 | |
---|
955 | if (slider_size_vertical < 1) slider_size_vertical = 1; |
---|
956 | if (slider_size_vertical > slider_max) { |
---|
957 | slider_size_vertical = slider_max; |
---|
958 | XtVaSetValues(p_w->scroll_bar_vertical, XmNvalue, 0, NULL); |
---|
959 | use_vertical_bar = false; |
---|
960 | } |
---|
961 | |
---|
962 | // check wether XmNValue is to big |
---|
963 | int position_of_slider; |
---|
964 | XtVaGetValues(p_w->scroll_bar_vertical, XmNvalue, &position_of_slider, NULL); |
---|
965 | if (position_of_slider > (slider_max-slider_size_vertical)) { |
---|
966 | position_of_slider = slider_max-slider_size_vertical; // -1 ? vielleicht ! |
---|
967 | if (position_of_slider < 0) position_of_slider = 0; |
---|
968 | XtVaSetValues(p_w->scroll_bar_vertical, XmNvalue, position_of_slider, NULL); |
---|
969 | } |
---|
970 | // Anpassung fuer resize, wenn unbeschriebener Bereich vergroessert wird |
---|
971 | int max_slider_pos = (int)(get_scrolled_picture_height() - scrollArea.b); |
---|
972 | if (slider_pos_vertical>max_slider_pos) { |
---|
973 | slider_pos_vertical = use_vertical_bar ? max_slider_pos : 0; |
---|
974 | } |
---|
975 | |
---|
976 | XtVaSetValues(p_w->scroll_bar_vertical, XmNsliderSize, 1, NULL); |
---|
977 | XtVaSetValues(p_w->scroll_bar_vertical, XmNmaximum, slider_max, NULL); |
---|
978 | XtVaSetValues(p_w->scroll_bar_vertical, XmNsliderSize, slider_size_vertical, NULL); |
---|
979 | |
---|
980 | update_scrollbar_settings_from_awars(AW_VERTICAL); |
---|
981 | } |
---|
982 | } |
---|
983 | |
---|
984 | // ---------------------------------------------------------------------- |
---|
985 | // force-diff-sync 82346723846 (remove after merging back to trunk) |
---|
986 | // ---------------------------------------------------------------------- |
---|
987 | |
---|
988 | static void horizontal_scrollbar_redefinition_cb(AW_root*, AW_window *aw) { |
---|
989 | aw->update_scrollbar_settings_from_awars(AW_HORIZONTAL); |
---|
990 | } |
---|
991 | |
---|
992 | static void vertical_scrollbar_redefinition_cb(AW_root*, AW_window *aw) { |
---|
993 | aw->update_scrollbar_settings_from_awars(AW_VERTICAL); |
---|
994 | } |
---|
995 | |
---|
996 | const char *AW_window::window_local_awarname(const char *localname, bool tmp) { |
---|
997 | CONSTEXPR int MAXNAMELEN = 200; |
---|
998 | static char buffer[MAXNAMELEN]; |
---|
999 | return GBS_global_string_to_buffer(buffer, MAXNAMELEN, |
---|
1000 | tmp ? "tmp/window/%s/%s" : "window/%s/%s", |
---|
1001 | window_defaults_name, localname); |
---|
1002 | // (see also aw_size_awar_name) |
---|
1003 | } |
---|
1004 | |
---|
1005 | AW_awar *AW_window::window_local_awar(const char *localname, bool tmp) { |
---|
1006 | return get_root()->awar(window_local_awarname(localname, tmp)); |
---|
1007 | } |
---|
1008 | |
---|
1009 | void AW_window::create_window_variables() { |
---|
1010 | RootCallback hor_src = makeRootCallback(horizontal_scrollbar_redefinition_cb, this); |
---|
1011 | RootCallback ver_src = makeRootCallback(vertical_scrollbar_redefinition_cb, this); |
---|
1012 | |
---|
1013 | get_root()->awar_int(window_local_awarname("horizontal_page_increment"), 50)->add_callback(hor_src); |
---|
1014 | get_root()->awar_int(window_local_awarname("vertical_page_increment"), 50)->add_callback(ver_src); |
---|
1015 | get_root()->awar_int(window_local_awarname("scroll_width_horizontal"), 9)->add_callback(hor_src); |
---|
1016 | get_root()->awar_int(window_local_awarname("scroll_width_vertical"), 20)->add_callback(ver_src); |
---|
1017 | get_root()->awar_int(window_local_awarname("scroll_delay_horizontal"), 20)->add_callback(hor_src); |
---|
1018 | get_root()->awar_int(window_local_awarname("scroll_delay_vertical"), 20)->add_callback(ver_src); |
---|
1019 | } |
---|
1020 | |
---|
1021 | void AW_window::set_vertical_scrollbar_position(int position){ |
---|
1022 | #if defined(DEBUG) && 0 |
---|
1023 | fprintf(stderr, "set_vertical_scrollbar_position to %i\n", position); |
---|
1024 | #endif |
---|
1025 | // @@@ test and constrain against limits |
---|
1026 | slider_pos_vertical = position; |
---|
1027 | XtVaSetValues(p_w->scroll_bar_vertical, XmNvalue, position, NULL); |
---|
1028 | } |
---|
1029 | |
---|
1030 | void AW_window::set_horizontal_scrollbar_position(int position) { |
---|
1031 | #if defined(DEBUG) && 0 |
---|
1032 | fprintf(stderr, "set_horizontal_scrollbar_position to %i\n", position); |
---|
1033 | #endif |
---|
1034 | // @@@ test and constrain against limits |
---|
1035 | slider_pos_horizontal = position; |
---|
1036 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNvalue, position, NULL); |
---|
1037 | } |
---|
1038 | |
---|
1039 | static void value_changed_scroll_bar_vertical(Widget /*wgt*/, XtPointer aw_cb_struct, XtPointer call_data) { |
---|
1040 | XmScrollBarCallbackStruct *sbcbs = (XmScrollBarCallbackStruct *)call_data; |
---|
1041 | AW_cb *cbs = (AW_cb *) aw_cb_struct; |
---|
1042 | cbs->aw->slider_pos_vertical = sbcbs->value; // setzt Scrollwerte im AW_window |
---|
1043 | cbs->run_callbacks(); |
---|
1044 | } |
---|
1045 | static void value_changed_scroll_bar_horizontal(Widget /*wgt*/, XtPointer aw_cb_struct, XtPointer call_data) { |
---|
1046 | XmScrollBarCallbackStruct *sbcbs = (XmScrollBarCallbackStruct *)call_data; |
---|
1047 | AW_cb *cbs = (AW_cb *) aw_cb_struct; |
---|
1048 | (cbs->aw)->slider_pos_horizontal = sbcbs->value; // setzt Scrollwerte im AW_window |
---|
1049 | cbs->run_callbacks(); |
---|
1050 | } |
---|
1051 | |
---|
1052 | static void drag_scroll_bar_vertical(Widget /*wgt*/, XtPointer aw_cb_struct, XtPointer call_data) { |
---|
1053 | XmScrollBarCallbackStruct *sbcbs = (XmScrollBarCallbackStruct *)call_data; |
---|
1054 | AW_cb *cbs = (AW_cb *) aw_cb_struct; |
---|
1055 | cbs->aw->slider_pos_vertical = sbcbs->value; // setzt Scrollwerte im AW_window |
---|
1056 | cbs->run_callbacks(); |
---|
1057 | } |
---|
1058 | static void drag_scroll_bar_horizontal(Widget /*wgt*/, XtPointer aw_cb_struct, XtPointer call_data) { |
---|
1059 | XmScrollBarCallbackStruct *sbcbs = (XmScrollBarCallbackStruct *)call_data; |
---|
1060 | AW_cb *cbs = (AW_cb *) aw_cb_struct; |
---|
1061 | (cbs->aw)->slider_pos_horizontal = sbcbs->value; // setzt Scrollwerte im AW_window |
---|
1062 | cbs->run_callbacks(); |
---|
1063 | } |
---|
1064 | |
---|
1065 | void AW_window::set_vertical_change_callback(const WindowCallback& wcb) { |
---|
1066 | XtAddCallback(p_w->scroll_bar_vertical, XmNvalueChangedCallback, |
---|
1067 | (XtCallbackProc) value_changed_scroll_bar_vertical, |
---|
1068 | (XtPointer) new AW_cb(this, wcb, "")); |
---|
1069 | XtAddCallback(p_w->scroll_bar_vertical, XmNdragCallback, |
---|
1070 | (XtCallbackProc) drag_scroll_bar_vertical, |
---|
1071 | (XtPointer) new AW_cb(this, wcb, "")); |
---|
1072 | |
---|
1073 | XtAddCallback(p_w->scroll_bar_vertical, XmNpageIncrementCallback, |
---|
1074 | (XtCallbackProc) drag_scroll_bar_vertical, |
---|
1075 | (XtPointer) new AW_cb(this, wcb, "")); |
---|
1076 | XtAddCallback(p_w->scroll_bar_vertical, XmNpageDecrementCallback, |
---|
1077 | (XtCallbackProc) drag_scroll_bar_vertical, |
---|
1078 | (XtPointer) new AW_cb(this, wcb, "")); |
---|
1079 | } |
---|
1080 | |
---|
1081 | void AW_window::set_horizontal_change_callback(const WindowCallback& wcb) { |
---|
1082 | XtAddCallback(p_w->scroll_bar_horizontal, XmNvalueChangedCallback, |
---|
1083 | (XtCallbackProc) value_changed_scroll_bar_horizontal, |
---|
1084 | (XtPointer) new AW_cb(this, wcb, "")); |
---|
1085 | XtAddCallback(p_w->scroll_bar_horizontal, XmNdragCallback, |
---|
1086 | (XtCallbackProc) drag_scroll_bar_horizontal, |
---|
1087 | (XtPointer) new AW_cb(this, wcb, "")); |
---|
1088 | } |
---|
1089 | |
---|
1090 | // END SCROLLBAR STUFF |
---|
1091 | |
---|
1092 | |
---|
1093 | void AW_window::set_window_size(int width, int height) { |
---|
1094 | XtVaSetValues(p_w->shell, XmNwidth, (int)width, XmNheight, (int)height, NULL); |
---|
1095 | } |
---|
1096 | |
---|
1097 | void AW_window::set_window_title_intern(char *title) { |
---|
1098 | XtVaSetValues(p_w->shell, XmNtitle, title, NULL); |
---|
1099 | } |
---|
1100 | |
---|
1101 | void AW_window::set_window_title(const char *title){ |
---|
1102 | XtVaSetValues(p_w->shell, XmNtitle, title, NULL); |
---|
1103 | freedup(window_name, title); |
---|
1104 | } |
---|
1105 | |
---|
1106 | const char* AW_window::get_window_title() const { |
---|
1107 | return window_name; |
---|
1108 | } |
---|
1109 | |
---|
1110 | void AW_window::shadow_width(int shadow_thickness) { |
---|
1111 | _at->shadow_thickness = shadow_thickness; |
---|
1112 | } |
---|
1113 | |
---|
1114 | #if defined(ARB_MOTIF) |
---|
1115 | void AW_window::button_height(int height) { |
---|
1116 | _at->height_of_buttons = height>1 ? height : 0; |
---|
1117 | } |
---|
1118 | #endif |
---|
1119 | |
---|
1120 | // ---------------------------------------------------------------------- |
---|
1121 | // force-diff-sync 874687234237 (remove after merging back to trunk) |
---|
1122 | // ---------------------------------------------------------------------- |
---|
1123 | |
---|
1124 | void AW_window::window_fit() { |
---|
1125 | int width, height; |
---|
1126 | get_window_size(width, height); |
---|
1127 | set_window_size(width, height); |
---|
1128 | } |
---|
1129 | |
---|
1130 | AW_window::AW_window() |
---|
1131 | : recalc_size_at_show(AW_KEEP_SIZE), |
---|
1132 | recalc_pos_at_show(AW_KEEP_POS), |
---|
1133 | hide_cb(NULL), |
---|
1134 | expose_callback_added(false), |
---|
1135 | focus_cb(NULL), |
---|
1136 | xfig_data(NULL), |
---|
1137 | _at(new AW_at), |
---|
1138 | left_indent_of_horizontal_scrollbar(0), |
---|
1139 | top_indent_of_vertical_scrollbar(0), |
---|
1140 | root(NULL), |
---|
1141 | click_time(0), |
---|
1142 | color_table_size(0), |
---|
1143 | color_table(NULL), |
---|
1144 | number_of_timed_title_changes(0), |
---|
1145 | p_w(new AW_window_Motif), |
---|
1146 | _callback(NULL), |
---|
1147 | _d_callback(NULL), |
---|
1148 | window_name(NULL), |
---|
1149 | window_defaults_name(NULL), |
---|
1150 | slider_pos_vertical(0), |
---|
1151 | slider_pos_horizontal(0), |
---|
1152 | window_is_shown(false), |
---|
1153 | picture(new AW_screen_area) |
---|
1154 | { |
---|
1155 | reset_scrolled_picture_size(); |
---|
1156 | } |
---|
1157 | |
---|
1158 | AW_window::~AW_window() { |
---|
1159 | delete picture; |
---|
1160 | delete p_w; |
---|
1161 | } |
---|
1162 | |
---|
1163 | #if defined(DEBUG) |
---|
1164 | // #define DUMP_MENU_LIST // this should NOT be defined normally (if defined, every window writes all menu-entries to stdout) |
---|
1165 | #endif // DEBUG |
---|
1166 | #if defined(DUMP_MENU_LIST) |
---|
1167 | |
---|
1168 | static char *window_name = 0; |
---|
1169 | static char *sub_menu = 0; |
---|
1170 | |
---|
1171 | static void initMenuListing(const char *win_name) { |
---|
1172 | aw_assert(win_name); |
---|
1173 | |
---|
1174 | freedup(window_name, win_name); |
---|
1175 | freenull(sub_menu); |
---|
1176 | |
---|
1177 | printf("---------------------------------------- list of menus for '%s'\n", window_name); |
---|
1178 | } |
---|
1179 | |
---|
1180 | static void dumpMenuEntry(const char *entry) { |
---|
1181 | aw_assert(window_name); |
---|
1182 | if (sub_menu) { |
---|
1183 | printf("'%s/%s/%s'\n", window_name, sub_menu, entry); |
---|
1184 | } |
---|
1185 | else { |
---|
1186 | printf("'%s/%s'\n", window_name, entry); |
---|
1187 | } |
---|
1188 | } |
---|
1189 | |
---|
1190 | static void dumpOpenSubMenu(const char *sub_name) { |
---|
1191 | aw_assert(sub_name); |
---|
1192 | |
---|
1193 | dumpMenuEntry(sub_name); // dump the menu itself |
---|
1194 | |
---|
1195 | if (sub_menu) freeset(sub_menu, GBS_global_string_copy("%s/%s", sub_menu, sub_name)); |
---|
1196 | else sub_menu = strdup(sub_name); |
---|
1197 | } |
---|
1198 | |
---|
1199 | static void dumpCloseSubMenu() { |
---|
1200 | aw_assert(sub_menu); |
---|
1201 | char *lslash = strrchr(sub_menu, '/'); |
---|
1202 | if (lslash) { |
---|
1203 | lslash[0] = 0; |
---|
1204 | } |
---|
1205 | else freenull(sub_menu); |
---|
1206 | } |
---|
1207 | |
---|
1208 | static void dumpCloseAllSubMenus() { |
---|
1209 | freenull(sub_menu); |
---|
1210 | } |
---|
1211 | |
---|
1212 | #endif // DUMP_MENU_LIST |
---|
1213 | |
---|
1214 | AW_window_menu_modes::AW_window_menu_modes() : AW_window_menu_modes_private(NULL) {} |
---|
1215 | AW_window_menu_modes::~AW_window_menu_modes() {} |
---|
1216 | |
---|
1217 | AW_window_menu::AW_window_menu() {} |
---|
1218 | AW_window_menu::~AW_window_menu() {} |
---|
1219 | |
---|
1220 | AW_window_simple::AW_window_simple() {} |
---|
1221 | AW_window_simple::~AW_window_simple() {} |
---|
1222 | |
---|
1223 | AW_window_simple_menu::AW_window_simple_menu() {} |
---|
1224 | AW_window_simple_menu::~AW_window_simple_menu() {} |
---|
1225 | |
---|
1226 | AW_window_message::AW_window_message() {} |
---|
1227 | AW_window_message::~AW_window_message() {} |
---|
1228 | |
---|
1229 | #define LAYOUT_AWAR_ROOT "window/windows" |
---|
1230 | #define BUFSIZE 256 |
---|
1231 | static char aw_size_awar_name_buffer[BUFSIZE]; |
---|
1232 | static const char *aw_size_awar_name(AW_window *aww, const char *sub_entry) { |
---|
1233 | #if defined(DEBUG) |
---|
1234 | int size = |
---|
1235 | #endif // DEBUG |
---|
1236 | sprintf(aw_size_awar_name_buffer, LAYOUT_AWAR_ROOT "/%s/%s", |
---|
1237 | aww->window_defaults_name, sub_entry); |
---|
1238 | #if defined(DEBUG) |
---|
1239 | aw_assert(size < BUFSIZE); |
---|
1240 | #endif // DEBUG |
---|
1241 | return aw_size_awar_name_buffer; |
---|
1242 | // (see also AW_window::window_local_awarname) |
---|
1243 | } |
---|
1244 | #undef BUFSIZE |
---|
1245 | |
---|
1246 | #define aw_awar_name_posx(aww) aw_size_awar_name((aww), "posx") |
---|
1247 | #define aw_awar_name_posy(aww) aw_size_awar_name((aww), "posy") |
---|
1248 | #define aw_awar_name_width(aww) aw_size_awar_name((aww), "width") |
---|
1249 | #define aw_awar_name_height(aww) aw_size_awar_name((aww), "height") |
---|
1250 | |
---|
1251 | void AW_window::create_user_geometry_awars(int posx, int posy, int width, int height) { |
---|
1252 | get_root()->awar_int(aw_awar_name_posx(this), posx); |
---|
1253 | get_root()->awar_int(aw_awar_name_posy(this), posy); |
---|
1254 | get_root()->awar_int(aw_awar_name_width(this), width); |
---|
1255 | get_root()->awar_int(aw_awar_name_height(this), height); |
---|
1256 | } |
---|
1257 | |
---|
1258 | |
---|
1259 | void AW_window::store_size_in_awars(int width, int height) { |
---|
1260 | get_root()->awar(aw_awar_name_width(this))->write_int(width); |
---|
1261 | get_root()->awar(aw_awar_name_height(this))->write_int(height); |
---|
1262 | } |
---|
1263 | |
---|
1264 | void AW_window::get_size_from_awars(int& width, int& height) { |
---|
1265 | width = get_root()->awar(aw_awar_name_width(this))->read_int(); |
---|
1266 | height = get_root()->awar(aw_awar_name_height(this))->read_int(); |
---|
1267 | } |
---|
1268 | |
---|
1269 | void AW_window::store_pos_in_awars(int posx, int posy) { |
---|
1270 | get_root()->awar(aw_awar_name_posx(this))->write_int(posx); |
---|
1271 | get_root()->awar(aw_awar_name_posy(this))->write_int(posy); |
---|
1272 | } |
---|
1273 | |
---|
1274 | void AW_window::get_pos_from_awars(int& posx, int& posy) { |
---|
1275 | posx = get_root()->awar(aw_awar_name_posx(this))->read_int(); |
---|
1276 | posy = get_root()->awar(aw_awar_name_posy(this))->read_int(); |
---|
1277 | } |
---|
1278 | |
---|
1279 | void AW_window::reset_geometry_awars() { |
---|
1280 | AW_root *awr = get_root(); |
---|
1281 | |
---|
1282 | ASSERT_NO_ERROR(awr->awar(aw_awar_name_posx(this)) ->reset_to_default()); |
---|
1283 | ASSERT_NO_ERROR(awr->awar(aw_awar_name_posy(this)) ->reset_to_default()); |
---|
1284 | ASSERT_NO_ERROR(awr->awar(aw_awar_name_width(this)) ->reset_to_default()); |
---|
1285 | ASSERT_NO_ERROR(awr->awar(aw_awar_name_height(this))->reset_to_default()); |
---|
1286 | |
---|
1287 | recalc_pos_atShow(AW_REPOS_TO_MOUSE_ONCE); |
---|
1288 | recalc_size_atShow(AW_RESIZE_ANY); |
---|
1289 | } |
---|
1290 | |
---|
1291 | #undef aw_awar_name_posx |
---|
1292 | #undef aw_awar_name_posy |
---|
1293 | #undef aw_awar_name_width |
---|
1294 | #undef aw_awar_name_height |
---|
1295 | |
---|
1296 | static void aw_onExpose_calc_WM_offsets(AW_window *aww); |
---|
1297 | static unsigned aw_calc_WM_offsets_delayed(AW_root *, AW_window*aww) { aw_onExpose_calc_WM_offsets(aww); return 0; } |
---|
1298 | |
---|
1299 | static void aw_onExpose_calc_WM_offsets(AW_window *aww) { |
---|
1300 | AW_window_Motif *motif = p_aww(aww); |
---|
1301 | |
---|
1302 | int posx, posy; aww->get_window_content_pos(posx, posy); |
---|
1303 | |
---|
1304 | bool knows_window_position = posx != 0 || posy != 0; |
---|
1305 | |
---|
1306 | if (!knows_window_position) { // oops - motif has no idea where the window has been placed |
---|
1307 | // assume positions stored in awars are correct and use them. |
---|
1308 | // This works around problems with unclickable GUI-elements when running on 'Unity' |
---|
1309 | |
---|
1310 | int oposx, oposy; aww->get_pos_from_awars(oposx, oposy); |
---|
1311 | aww->set_window_frame_pos(oposx, oposy); |
---|
1312 | |
---|
1313 | if (!motif->knows_WM_offset()) { |
---|
1314 | aww->get_root()->add_timed_callback(100, makeTimedCallback(aw_calc_WM_offsets_delayed, aww)); |
---|
1315 | } |
---|
1316 | } |
---|
1317 | else if (!motif->knows_WM_offset()) { |
---|
1318 | int oposx, oposy; aww->get_pos_from_awars(oposx, oposy); |
---|
1319 | |
---|
1320 | // calculate offset |
---|
1321 | int left = posx-oposx; |
---|
1322 | int top = posy-oposy; |
---|
1323 | |
---|
1324 | if (top == 0 || left == 0) { // invalid frame size |
---|
1325 | if (motif->WM_left_offset == 0) { |
---|
1326 | motif->WM_left_offset = 1; // hack: unused yet, use as flag to avoid endless repeats |
---|
1327 | #if defined(DEBUG) |
---|
1328 | fprintf(stderr, "aw_onExpose_calc_WM_offsets: failed to detect framesize (shift window 1 pixel and retry)\n"); |
---|
1329 | #endif |
---|
1330 | oposx = oposx>10 ? oposx-1 : oposx+1; |
---|
1331 | oposy = oposy>10 ? oposy-1 : oposy+1; |
---|
1332 | |
---|
1333 | aww->set_window_frame_pos(oposx, oposy); |
---|
1334 | aww->store_pos_in_awars(oposx, oposy); |
---|
1335 | |
---|
1336 | aww->get_root()->add_timed_callback(500, makeTimedCallback(aw_calc_WM_offsets_delayed, aww)); |
---|
1337 | return; |
---|
1338 | } |
---|
1339 | else { |
---|
1340 | // use maximum seen frame size |
---|
1341 | top = AW_window_Motif::WM_max_top_offset; |
---|
1342 | left = AW_window_Motif::WM_max_left_offset; |
---|
1343 | |
---|
1344 | if (top == 0 || left == 0) { // still invalid -> retry later |
---|
1345 | aww->get_root()->add_timed_callback(10000, makeTimedCallback(aw_calc_WM_offsets_delayed, aww)); |
---|
1346 | return; |
---|
1347 | } |
---|
1348 | } |
---|
1349 | } |
---|
1350 | motif->WM_top_offset = top; |
---|
1351 | motif->WM_left_offset = left; |
---|
1352 | |
---|
1353 | // remember maximum seen offsets |
---|
1354 | AW_window_Motif::WM_max_top_offset = std::max(AW_window_Motif::WM_max_top_offset, motif->WM_top_offset); |
---|
1355 | AW_window_Motif::WM_max_left_offset = std::max(AW_window_Motif::WM_max_left_offset, motif->WM_left_offset); |
---|
1356 | |
---|
1357 | #if defined(DEBUG) |
---|
1358 | fprintf(stderr, "WM_top_offset=%i WM_left_offset=%i (pos from awar: %i/%i, content-pos: %i/%i)\n", |
---|
1359 | motif->WM_top_offset, motif->WM_left_offset, |
---|
1360 | oposx, oposy, posx, posy); |
---|
1361 | #endif |
---|
1362 | } |
---|
1363 | } |
---|
1364 | |
---|
1365 | AW_root_Motif::AW_root_Motif() |
---|
1366 | : last_widget(0), |
---|
1367 | display(NULL), |
---|
1368 | context(0), |
---|
1369 | toplevel_widget(0), |
---|
1370 | main_widget(0), |
---|
1371 | main_aww(NULL), |
---|
1372 | message_shell(0), |
---|
1373 | foreground(0), |
---|
1374 | background(0), |
---|
1375 | fontlist(0), |
---|
1376 | option_menu_list(NULL), |
---|
1377 | last_option_menu(NULL), |
---|
1378 | current_option_menu(NULL), |
---|
1379 | toggle_field_list(NULL), |
---|
1380 | last_toggle_field(NULL), |
---|
1381 | selection_list(NULL), |
---|
1382 | last_selection_list(NULL), |
---|
1383 | screen_depth(0), |
---|
1384 | color_table(NULL), |
---|
1385 | colormap(0), |
---|
1386 | help_active(0), |
---|
1387 | clock_cursor(0), |
---|
1388 | question_cursor(0), |
---|
1389 | old_cursor_display(NULL), |
---|
1390 | old_cursor_window(0), |
---|
1391 | no_exit(false), |
---|
1392 | action_hash(NULL) |
---|
1393 | {} |
---|
1394 | |
---|
1395 | AW_root_Motif::~AW_root_Motif() { |
---|
1396 | GBS_free_hash(action_hash); |
---|
1397 | XmFontListFree(fontlist); |
---|
1398 | free(color_table); |
---|
1399 | } |
---|
1400 | |
---|
1401 | void AW_root_Motif::set_cursor(Display *d, Window w, Cursor c) { |
---|
1402 | XSetWindowAttributes attrs; |
---|
1403 | old_cursor_display = d; |
---|
1404 | old_cursor_window = w; |
---|
1405 | |
---|
1406 | if (c) |
---|
1407 | attrs.cursor = c; |
---|
1408 | else |
---|
1409 | attrs.cursor = None; |
---|
1410 | |
---|
1411 | if (d && w) { |
---|
1412 | XChangeWindowAttributes(d, w, CWCursor, &attrs); |
---|
1413 | } |
---|
1414 | XChangeWindowAttributes(XtDisplay(main_widget), XtWindow(main_widget), |
---|
1415 | CWCursor, &attrs); |
---|
1416 | XFlush(XtDisplay(main_widget)); |
---|
1417 | } |
---|
1418 | |
---|
1419 | void AW_root_Motif::normal_cursor() { |
---|
1420 | set_cursor(old_cursor_display, old_cursor_window, 0); |
---|
1421 | } |
---|
1422 | |
---|
1423 | void AW_server_callback(Widget /*wgt*/, XtPointer aw_cb_struct, XtPointer /*call_data*/) { |
---|
1424 | AW_cb *cbs = (AW_cb *) aw_cb_struct; |
---|
1425 | |
---|
1426 | AW_root *root = cbs->aw->get_root(); |
---|
1427 | if (p_global->help_active) { |
---|
1428 | p_global->help_active = 0; |
---|
1429 | p_global->normal_cursor(); |
---|
1430 | |
---|
1431 | if (cbs->help_text && ((GBS_string_matches(cbs->help_text, "*.ps", GB_IGNORE_CASE)) || |
---|
1432 | (GBS_string_matches(cbs->help_text, "*.hlp", GB_IGNORE_CASE)) || |
---|
1433 | (GBS_string_matches(cbs->help_text, "*.help", GB_IGNORE_CASE)))) |
---|
1434 | { |
---|
1435 | AW_help_popup(NULL, cbs->help_text); |
---|
1436 | } |
---|
1437 | else { |
---|
1438 | aw_message("Sorry no help available"); |
---|
1439 | } |
---|
1440 | return; |
---|
1441 | } |
---|
1442 | |
---|
1443 | if (root->is_tracking()) root->track_action(cbs->id); |
---|
1444 | |
---|
1445 | p_global->set_cursor(XtDisplay(p_global->toplevel_widget), |
---|
1446 | XtWindow(p_aww(cbs->aw)->shell), |
---|
1447 | p_global->clock_cursor); |
---|
1448 | cbs->run_callbacks(); |
---|
1449 | |
---|
1450 | XEvent event; // destroy all old events !!! |
---|
1451 | while (XCheckMaskEvent(XtDisplay(p_global->toplevel_widget), |
---|
1452 | ButtonPressMask|ButtonReleaseMask|ButtonMotionMask| |
---|
1453 | KeyPressMask|KeyReleaseMask|PointerMotionMask, &event)) { |
---|
1454 | } |
---|
1455 | |
---|
1456 | if (p_global->help_active) { |
---|
1457 | p_global->set_cursor(XtDisplay(p_global->toplevel_widget), |
---|
1458 | XtWindow(p_aww(cbs->aw)->shell), |
---|
1459 | p_global->question_cursor); |
---|
1460 | } |
---|
1461 | else { |
---|
1462 | p_global->set_cursor(XtDisplay(p_global->toplevel_widget), |
---|
1463 | XtWindow(p_aww(cbs->aw)->shell), |
---|
1464 | 0); |
---|
1465 | } |
---|
1466 | } |
---|
1467 | |
---|
1468 | // ---------------------------------------------------------------------- |
---|
1469 | // force-diff-sync 2964732647236 (remove after merging back to trunk) |
---|
1470 | // ---------------------------------------------------------------------- |
---|
1471 | |
---|
1472 | void AW_window::recalc_pos_atShow(AW_PosRecalc pr) { |
---|
1473 | recalc_pos_at_show = pr; |
---|
1474 | } |
---|
1475 | |
---|
1476 | AW_PosRecalc AW_window::get_recalc_pos_atShow() const { |
---|
1477 | return recalc_pos_at_show; |
---|
1478 | } |
---|
1479 | |
---|
1480 | void AW_window::recalc_size_atShow(enum AW_SizeRecalc sr) { |
---|
1481 | if (sr == AW_RESIZE_ANY) { |
---|
1482 | sr = (recalc_size_at_show == AW_RESIZE_USER) ? AW_RESIZE_USER : AW_RESIZE_DEFAULT; |
---|
1483 | } |
---|
1484 | recalc_size_at_show = sr; |
---|
1485 | } |
---|
1486 | |
---|
1487 | |
---|
1488 | |
---|
1489 | // -------------- |
---|
1490 | // focus |
---|
1491 | |
---|
1492 | |
---|
1493 | void AW_window::run_focus_callback() { |
---|
1494 | if (focus_cb) focus_cb->run_callbacks(); |
---|
1495 | } |
---|
1496 | |
---|
1497 | bool AW_window::is_focus_callback(AnyWinCB f) { |
---|
1498 | return focus_cb && focus_cb->contains(f); |
---|
1499 | } |
---|
1500 | |
---|
1501 | // --------------- |
---|
1502 | // expose |
---|
1503 | |
---|
1504 | inline void AW_area_management::run_expose_callback() { |
---|
1505 | if (expose_cb) expose_cb->run_callbacks(); |
---|
1506 | } |
---|
1507 | |
---|
1508 | static void AW_exposeCB(Widget /*wgt*/, XtPointer aw_cb_struct, XmDrawingAreaCallbackStruct *call_data) { |
---|
1509 | XEvent *ev = call_data->event; |
---|
1510 | AW_area_management *aram = (AW_area_management *) aw_cb_struct; |
---|
1511 | if (ev->xexpose.count == 0) { // last expose cb |
---|
1512 | aram->run_expose_callback(); |
---|
1513 | } |
---|
1514 | } |
---|
1515 | |
---|
1516 | void AW_area_management::set_expose_callback(AW_window *aww, const WindowCallback& cb) { |
---|
1517 | // insert expose callback for draw_area |
---|
1518 | if (!expose_cb) { |
---|
1519 | XtAddCallback(area, XmNexposeCallback, (XtCallbackProc) AW_exposeCB, |
---|
1520 | (XtPointer) this); |
---|
1521 | } |
---|
1522 | expose_cb = new AW_cb(aww, cb, 0, expose_cb); |
---|
1523 | } |
---|
1524 | |
---|
1525 | bool AW_area_management::is_expose_callback(AnyWinCB f) { |
---|
1526 | return expose_cb && expose_cb->contains(f); |
---|
1527 | } |
---|
1528 | |
---|
1529 | bool AW_window::is_expose_callback(AW_area area, AnyWinCB f) { |
---|
1530 | AW_area_management *aram = MAP_ARAM(area); |
---|
1531 | return aram && aram->is_expose_callback(f); |
---|
1532 | } |
---|
1533 | |
---|
1534 | void AW_window::force_expose() { |
---|
1535 | XmDrawingAreaCallbackStruct da_struct; |
---|
1536 | |
---|
1537 | da_struct.reason = XmCR_EXPOSE; |
---|
1538 | da_struct.event = (XEvent *) NULL; |
---|
1539 | da_struct.window = XtWindow(p_w->shell); |
---|
1540 | |
---|
1541 | XtCallCallbacks(p_w->shell, XmNexposeCallback, (XtPointer) &da_struct); |
---|
1542 | } |
---|
1543 | |
---|
1544 | // --------------- |
---|
1545 | // resize |
---|
1546 | |
---|
1547 | |
---|
1548 | bool AW_area_management::is_resize_callback(AnyWinCB f) { |
---|
1549 | return resize_cb && resize_cb->contains(f); |
---|
1550 | } |
---|
1551 | |
---|
1552 | bool AW_window::is_resize_callback(AW_area area, AnyWinCB f) { |
---|
1553 | AW_area_management *aram = MAP_ARAM(area); |
---|
1554 | return aram && aram->is_resize_callback(f); |
---|
1555 | } |
---|
1556 | |
---|
1557 | void AW_window::set_window_frame_pos(int x, int y) { |
---|
1558 | // this will set the position of the frame around the client-area (see also WM_top_offset ..) |
---|
1559 | XtVaSetValues(p_w->shell, XmNx, (int)x, XmNy, (int)y, NULL); |
---|
1560 | } |
---|
1561 | void AW_window::get_window_content_pos(int& xpos, int& ypos) { |
---|
1562 | // this will report the position of the client-area (see also WM_top_offset ..) |
---|
1563 | unsigned short x, y; |
---|
1564 | XtVaGetValues(p_w->shell, XmNx, &x, XmNy, &y, NULL); |
---|
1565 | xpos = x; |
---|
1566 | ypos = y; |
---|
1567 | } |
---|
1568 | |
---|
1569 | void AW_window::get_screen_size(int &width, int &height) { |
---|
1570 | Screen *screen = XtScreen(p_w->shell); |
---|
1571 | |
---|
1572 | width = WidthOfScreen(screen); |
---|
1573 | height = HeightOfScreen(screen); |
---|
1574 | } |
---|
1575 | |
---|
1576 | bool AW_window::get_mouse_pos(int& x, int& y) { |
---|
1577 | Display *d = XtDisplay(p_w->shell); |
---|
1578 | Window w1 = XtWindow(p_w->shell); |
---|
1579 | Window w2; |
---|
1580 | Window w3; |
---|
1581 | int rx, ry; |
---|
1582 | int wx, wy; |
---|
1583 | unsigned int mask; |
---|
1584 | |
---|
1585 | Bool ok = XQueryPointer(d, w1, &w2, &w3, &rx, &ry, &wx, &wy, &mask); |
---|
1586 | |
---|
1587 | if (ok) { |
---|
1588 | #if defined(DEBUG) && 0 |
---|
1589 | printf("get_mouse_pos: rx/ry=%i/%i wx/wy=%i/%i\n", rx, ry, wx, wy); |
---|
1590 | #endif // DEBUG |
---|
1591 | x = rx; |
---|
1592 | y = ry; |
---|
1593 | } |
---|
1594 | return ok; |
---|
1595 | } |
---|
1596 | |
---|
1597 | static int is_resize_event(Display *display, XEvent *event, XPointer) { |
---|
1598 | // Predicate function: checks, if the given event is a ResizeEvent |
---|
1599 | if (event && (event->type == ResizeRequest || event->type |
---|
1600 | == ConfigureNotify) && event->xany.display == display) { |
---|
1601 | return 1; |
---|
1602 | } |
---|
1603 | return 0; |
---|
1604 | } |
---|
1605 | |
---|
1606 | static void cleanupResizeEvents(Display *display) { |
---|
1607 | // Removes redundant resize events from the x-event queue |
---|
1608 | if (display) { |
---|
1609 | XLockDisplay(display); |
---|
1610 | XEvent event; |
---|
1611 | if (XCheckIfEvent(display, &event, is_resize_event, 0)) { |
---|
1612 | // Some magic happens here... ;-) (removing redundant events from queue) |
---|
1613 | while (XCheckIfEvent(display, &event, is_resize_event, 0)) |
---|
1614 | ; |
---|
1615 | // Keep last Event in queue |
---|
1616 | XPutBackEvent(display, &event); |
---|
1617 | } |
---|
1618 | XUnlockDisplay(display); |
---|
1619 | } |
---|
1620 | } |
---|
1621 | |
---|
1622 | static void aw_window_avoid_destroy_cb(Widget, AW_window *, XmAnyCallbackStruct *) { |
---|
1623 | aw_message("If YOU do not know what to answer, how should ARB know?\nPlease think again and answer the prompt!"); |
---|
1624 | } |
---|
1625 | static void aw_window_noexit_destroy_cb(Widget, AW_window *aww, XmAnyCallbackStruct *) { |
---|
1626 | aww->hide(); |
---|
1627 | // don't exit, when using destroy callback |
---|
1628 | } |
---|
1629 | static void aw_window_destroy_cb(Widget, AW_window *aww, XmAnyCallbackStruct *) { |
---|
1630 | AW_root *root = aww->get_root(); |
---|
1631 | if ((p_global->main_aww == aww) || !p_global->main_aww->is_shown()) { |
---|
1632 | #ifdef NDEBUG |
---|
1633 | if (!aw_ask_sure("quit_by_X", "Are you sure to quit?")) return; |
---|
1634 | #endif |
---|
1635 | exit(EXIT_SUCCESS); |
---|
1636 | } |
---|
1637 | aww->hide(); |
---|
1638 | } |
---|
1639 | |
---|
1640 | static void aw_set_delete_window_cb(AW_window *aww, Widget shell, bool allow_close) { |
---|
1641 | Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay(shell), (char*)"WM_DELETE_WINDOW", False); |
---|
1642 | |
---|
1643 | // remove any previous callbacks |
---|
1644 | XmRemoveWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc)aw_window_avoid_destroy_cb, (caddr_t)aww); |
---|
1645 | XmRemoveWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc)aw_window_noexit_destroy_cb, (caddr_t)aww); |
---|
1646 | XmRemoveWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc)aw_window_destroy_cb, (caddr_t)aww); |
---|
1647 | |
---|
1648 | if (!allow_close) { |
---|
1649 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc)aw_window_avoid_destroy_cb, (caddr_t)aww); |
---|
1650 | } |
---|
1651 | else { |
---|
1652 | AW_root *root = aww->get_root(); |
---|
1653 | if (p_global->no_exit) { |
---|
1654 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc)aw_window_noexit_destroy_cb, (caddr_t)aww); |
---|
1655 | } |
---|
1656 | else { |
---|
1657 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc)aw_window_destroy_cb, (caddr_t)aww); |
---|
1658 | } |
---|
1659 | } |
---|
1660 | } |
---|
1661 | |
---|
1662 | // ---------------------------------------------------------------------- |
---|
1663 | // force-diff-sync 8294723642364 (remove after merging back to trunk) |
---|
1664 | // ---------------------------------------------------------------------- |
---|
1665 | |
---|
1666 | void AW_window::allow_delete_window(bool allow_close) { |
---|
1667 | aw_set_delete_window_cb(this, p_w->shell, allow_close); |
---|
1668 | } |
---|
1669 | |
---|
1670 | // ---------------------------------------------------------------------- |
---|
1671 | // force-diff-sync 9268347253894 (remove after merging back to trunk) |
---|
1672 | // ---------------------------------------------------------------------- |
---|
1673 | |
---|
1674 | bool AW_window::is_shown() const { |
---|
1675 | // return true if window is shown ( = not invisible and already created) |
---|
1676 | // Note: does return TRUE!, if window is only minimized by WM |
---|
1677 | return window_is_shown; |
---|
1678 | } |
---|
1679 | |
---|
1680 | static void aw_update_window_geometry_awars(AW_window *aww) { |
---|
1681 | AW_window_Motif *motif = p_aww(aww); |
---|
1682 | |
---|
1683 | short posx, posy; |
---|
1684 | unsigned short width, height, borderwidth; |
---|
1685 | XtVaGetValues(motif->shell, // bad hack |
---|
1686 | XmNborderWidth, &borderwidth, |
---|
1687 | XmNwidth, &width, |
---|
1688 | XmNheight, &height, |
---|
1689 | XmNx, &posx, |
---|
1690 | XmNy, &posy, |
---|
1691 | NULL); |
---|
1692 | |
---|
1693 | if (motif->knows_WM_offset()) { |
---|
1694 | posx -= motif->WM_left_offset; |
---|
1695 | posy -= motif->WM_top_offset; |
---|
1696 | |
---|
1697 | if (posx<0) posx = 0; |
---|
1698 | if (posy<0) posy = 0; |
---|
1699 | |
---|
1700 | aww->store_pos_in_awars(posx, posy); |
---|
1701 | } |
---|
1702 | #if defined(DEBUG) |
---|
1703 | else { |
---|
1704 | fprintf(stderr, "Warning: WM_offsets unknown => did not update awars for window '%s'\n", aww->get_window_title()); |
---|
1705 | } |
---|
1706 | #endif |
---|
1707 | aww->store_size_in_awars(width, height); |
---|
1708 | } |
---|
1709 | |
---|
1710 | void AW_window::show() { |
---|
1711 | bool was_shown = true; |
---|
1712 | if (!window_is_shown) { |
---|
1713 | all_menus_created(); |
---|
1714 | get_root()->window_show(); |
---|
1715 | window_is_shown = true; |
---|
1716 | was_shown = false; |
---|
1717 | } |
---|
1718 | |
---|
1719 | int width, height; // w/o window frame |
---|
1720 | if (recalc_size_at_show != AW_KEEP_SIZE) { |
---|
1721 | if (recalc_size_at_show == AW_RESIZE_DEFAULT) { |
---|
1722 | // window ignores user-size (even if changed inside current session). |
---|
1723 | // used for question boxes, user masks, ... |
---|
1724 | window_fit(); |
---|
1725 | get_window_size(width, height); |
---|
1726 | } |
---|
1727 | else { |
---|
1728 | aw_assert(recalc_size_at_show == AW_RESIZE_USER); |
---|
1729 | // check whether user size is too small and increase to minimum window size |
---|
1730 | |
---|
1731 | int min_width, min_height; get_window_size(min_width, min_height); |
---|
1732 | int user_width, user_height; get_size_from_awars(user_width, user_height); |
---|
1733 | |
---|
1734 | if (user_width <min_width) user_width = min_width; |
---|
1735 | if (user_height<min_height) user_height = min_height; |
---|
1736 | |
---|
1737 | set_window_size(user_width, user_height); // restores user size |
---|
1738 | |
---|
1739 | width = user_width; |
---|
1740 | height = user_height; |
---|
1741 | |
---|
1742 | #if defined(DEBUG) |
---|
1743 | if (!was_shown) { // first popup |
---|
1744 | // warn about too big default size |
---|
1745 | #define LOWEST_SUPPORTED_SCREEN_X 1280 |
---|
1746 | #define LOWEST_SUPPORTED_SCREEN_Y 800 |
---|
1747 | |
---|
1748 | if (min_width>LOWEST_SUPPORTED_SCREEN_X || min_height>LOWEST_SUPPORTED_SCREEN_Y) { |
---|
1749 | fprintf(stderr, |
---|
1750 | "Warning: Window '%s' won't fit on %ix%i (win=%ix%i)\n", |
---|
1751 | get_window_title(), |
---|
1752 | LOWEST_SUPPORTED_SCREEN_X, LOWEST_SUPPORTED_SCREEN_Y, |
---|
1753 | min_width, min_height); |
---|
1754 | #if defined(DEVEL_RALF) |
---|
1755 | aw_assert(0); |
---|
1756 | #endif |
---|
1757 | } |
---|
1758 | } |
---|
1759 | #endif |
---|
1760 | } |
---|
1761 | store_size_in_awars(width, height); |
---|
1762 | recalc_size_at_show = AW_KEEP_SIZE; |
---|
1763 | } |
---|
1764 | else { |
---|
1765 | get_window_size(width, height); |
---|
1766 | } |
---|
1767 | |
---|
1768 | { |
---|
1769 | int posx, posy; |
---|
1770 | int swidth, sheight; get_screen_size(swidth, sheight); |
---|
1771 | bool posIsFrame = false; |
---|
1772 | |
---|
1773 | switch (recalc_pos_at_show) { |
---|
1774 | case AW_REPOS_TO_MOUSE_ONCE: |
---|
1775 | recalc_pos_at_show = AW_KEEP_POS; |
---|
1776 | // fallthrough |
---|
1777 | case AW_REPOS_TO_MOUSE: { |
---|
1778 | int mx, my; |
---|
1779 | if (!get_mouse_pos(mx, my)) goto FALLBACK_CENTER; |
---|
1780 | |
---|
1781 | posx = mx-width/2; |
---|
1782 | posy = my-height/2; |
---|
1783 | break; |
---|
1784 | } |
---|
1785 | case AW_REPOS_TO_CENTER: |
---|
1786 | FALLBACK_CENTER: |
---|
1787 | posx = (swidth-width)/2; |
---|
1788 | posy = (sheight-height)/4; |
---|
1789 | break; |
---|
1790 | |
---|
1791 | case AW_KEEP_POS: |
---|
1792 | if (was_shown) { |
---|
1793 | // user might have moved the window -> store (new) positions |
---|
1794 | aw_update_window_geometry_awars(this); |
---|
1795 | } |
---|
1796 | get_pos_from_awars(posx, posy); |
---|
1797 | get_size_from_awars(width, height); |
---|
1798 | posIsFrame = true; |
---|
1799 | break; |
---|
1800 | } |
---|
1801 | |
---|
1802 | int frameWidth, frameHeight; |
---|
1803 | if (p_w->knows_WM_offset()) { |
---|
1804 | frameWidth = p_w->WM_left_offset; |
---|
1805 | frameHeight = p_w->WM_top_offset; |
---|
1806 | } |
---|
1807 | else { |
---|
1808 | // estimate |
---|
1809 | frameWidth = AW_window_Motif::WM_max_left_offset + 1; |
---|
1810 | frameHeight = AW_window_Motif::WM_max_top_offset + 1; |
---|
1811 | } |
---|
1812 | |
---|
1813 | if (!posIsFrame) { |
---|
1814 | posx -= frameWidth; |
---|
1815 | posy -= frameHeight; |
---|
1816 | posIsFrame = true; |
---|
1817 | } |
---|
1818 | |
---|
1819 | // avoid windows outside of screen (or too near to screen-edges) |
---|
1820 | { |
---|
1821 | int maxx = swidth - 2*frameWidth - width; |
---|
1822 | int maxy = sheight - frameWidth-frameHeight - height; // assumes lower border-width == frameWidth |
---|
1823 | |
---|
1824 | if (posx>maxx) posx = maxx; |
---|
1825 | if (posy>maxy) posy = maxy; |
---|
1826 | |
---|
1827 | if (p_w->knows_WM_offset()) { |
---|
1828 | if (posx<0) posx = 0; |
---|
1829 | if (posy<0) posy = 0; |
---|
1830 | } |
---|
1831 | else { |
---|
1832 | // workaround a bug leading to wrong WM-offsets (occurs when window-content is placed at screen-border) |
---|
1833 | // shift window away from border |
---|
1834 | if (posx<frameWidth) posx = frameWidth; |
---|
1835 | if (posy<frameHeight) posy = frameHeight; |
---|
1836 | } |
---|
1837 | } |
---|
1838 | |
---|
1839 | aw_assert(implicated(p_w->knows_WM_offset(), posIsFrame)); |
---|
1840 | |
---|
1841 | // store position and position window |
---|
1842 | store_pos_in_awars(posx, posy); |
---|
1843 | set_window_frame_pos(posx, posy); |
---|
1844 | } |
---|
1845 | |
---|
1846 | XtPopup(p_w->shell, XtGrabNone); |
---|
1847 | if (!expose_callback_added) { |
---|
1848 | set_expose_callback(AW_INFO_AREA, aw_onExpose_calc_WM_offsets); // @@@ should be removed after it was called once |
---|
1849 | expose_callback_added = true; |
---|
1850 | } |
---|
1851 | } |
---|
1852 | |
---|
1853 | void AW_window::show_modal() { |
---|
1854 | recalc_pos_atShow(AW_REPOS_TO_MOUSE); |
---|
1855 | get_root()->current_modal_window = this; |
---|
1856 | activate(); |
---|
1857 | } |
---|
1858 | |
---|
1859 | void AW_window::hide() { |
---|
1860 | if (window_is_shown) { |
---|
1861 | aw_update_window_geometry_awars(this); |
---|
1862 | if (hide_cb) hide_cb(this); |
---|
1863 | get_root()->window_hide(this); |
---|
1864 | window_is_shown = false; |
---|
1865 | } |
---|
1866 | XtPopdown(p_w->shell); |
---|
1867 | } |
---|
1868 | |
---|
1869 | void AW_window::hide_or_notify(const char *error) { |
---|
1870 | if (error) aw_message(error); |
---|
1871 | else hide(); |
---|
1872 | } |
---|
1873 | |
---|
1874 | // ---------------------------------------------------------------------- |
---|
1875 | // force-diff-sync 9287423467632 (remove after merging back to trunk) |
---|
1876 | // ---------------------------------------------------------------------- |
---|
1877 | |
---|
1878 | void AW_window::on_hide(WindowCallbackSimple call_on_hide) { |
---|
1879 | hide_cb = call_on_hide; |
---|
1880 | } |
---|
1881 | |
---|
1882 | inline void AW_area_management::run_resize_callback() { |
---|
1883 | if (resize_cb) resize_cb->run_callbacks(); |
---|
1884 | } |
---|
1885 | |
---|
1886 | static void AW_resizeCB_draw_area(Widget /*wgt*/, XtPointer aw_cb_struct, XtPointer /*call_data*/) { |
---|
1887 | AW_area_management *aram = (AW_area_management *) aw_cb_struct; |
---|
1888 | cleanupResizeEvents(aram->get_common()->get_display()); |
---|
1889 | aram->run_resize_callback(); |
---|
1890 | } |
---|
1891 | |
---|
1892 | void AW_area_management::set_resize_callback(AW_window *aww, const WindowCallback& cb) { |
---|
1893 | // insert resize callback for draw_area |
---|
1894 | if (!resize_cb) { |
---|
1895 | XtAddCallback(area, XmNresizeCallback, |
---|
1896 | (XtCallbackProc) AW_resizeCB_draw_area, (XtPointer) this); |
---|
1897 | } |
---|
1898 | resize_cb = new AW_cb(aww, cb, 0, resize_cb); |
---|
1899 | } |
---|
1900 | |
---|
1901 | // ------------------- |
---|
1902 | // user input |
---|
1903 | |
---|
1904 | |
---|
1905 | static void AW_inputCB_draw_area(Widget wgt, XtPointer aw_cb_struct, XmDrawingAreaCallbackStruct *call_data) { |
---|
1906 | XEvent *ev = call_data->event; |
---|
1907 | AW_cb *cbs = (AW_cb *) aw_cb_struct; |
---|
1908 | AW_window *aww = cbs->aw; |
---|
1909 | bool run_callback = false; |
---|
1910 | bool run_double_click_callback = false; |
---|
1911 | AW_area_management *area = 0; |
---|
1912 | { |
---|
1913 | int i; |
---|
1914 | for (i=0; i<AW_MAX_AREA; i++) { |
---|
1915 | if (p_aww(aww)->areas[i]->get_area() == wgt) { |
---|
1916 | area = p_aww(aww)->areas[i]; |
---|
1917 | break; |
---|
1918 | } |
---|
1919 | } |
---|
1920 | } |
---|
1921 | |
---|
1922 | if (ev->xbutton.type == ButtonPress || ev->xbutton.type == ButtonRelease) { |
---|
1923 | aww->event.button = AW_MouseButton(ev->xbutton.button); |
---|
1924 | aww->event.x = ev->xbutton.x; |
---|
1925 | aww->event.y = ev->xbutton.y; |
---|
1926 | aww->event.keymodifier = (AW_key_mod)(ev->xbutton.state & (AW_KEYMODE_SHIFT|AW_KEYMODE_CONTROL|AW_KEYMODE_ALT)); |
---|
1927 | aww->event.keycode = AW_KEY_NONE; |
---|
1928 | aww->event.character = '\0'; |
---|
1929 | |
---|
1930 | if (ev->xbutton.type == ButtonPress) { |
---|
1931 | aww->event.type = AW_Mouse_Press; |
---|
1932 | if (area && area->get_double_click_cb()) { |
---|
1933 | if ((ev->xbutton.time - area->get_click_time()) < 200) { |
---|
1934 | run_double_click_callback = true; |
---|
1935 | } |
---|
1936 | else { |
---|
1937 | run_callback = true; |
---|
1938 | } |
---|
1939 | area->set_click_time(ev->xbutton.time); |
---|
1940 | } |
---|
1941 | else { |
---|
1942 | run_callback = true; |
---|
1943 | } |
---|
1944 | aww->event.time = ev->xbutton.time; |
---|
1945 | } |
---|
1946 | else if (ev->xbutton.type == ButtonRelease) { |
---|
1947 | aww->event.type = AW_Mouse_Release; |
---|
1948 | run_callback = true; |
---|
1949 | // keep event.time set in ButtonPress-branch |
---|
1950 | } |
---|
1951 | } |
---|
1952 | else if (ev->xkey.type == KeyPress || ev->xkey.type == KeyRelease) { |
---|
1953 | aww->event.time = ev->xbutton.time; |
---|
1954 | |
---|
1955 | const awXKeymap *mykey = aw_xkey_2_awkey(&(ev->xkey)); |
---|
1956 | |
---|
1957 | aww->event.keycode = mykey->awkey; |
---|
1958 | aww->event.keymodifier = mykey->awmod; |
---|
1959 | |
---|
1960 | if (mykey->awstr) { |
---|
1961 | aww->event.character = mykey->awstr[0]; |
---|
1962 | } |
---|
1963 | else { |
---|
1964 | aww->event.character = 0; |
---|
1965 | } |
---|
1966 | |
---|
1967 | if (ev->xkey.type == KeyPress) { |
---|
1968 | aww->event.type = AW_Keyboard_Press; |
---|
1969 | } |
---|
1970 | else { |
---|
1971 | aww->event.type = AW_Keyboard_Release; |
---|
1972 | } |
---|
1973 | aww->event.button = AW_BUTTON_NONE; |
---|
1974 | aww->event.x = ev->xbutton.x; |
---|
1975 | aww->event.y = ev->xbutton.y; |
---|
1976 | |
---|
1977 | if (!mykey->awmod && mykey->awkey >= AW_KEY_F1 && mykey->awkey |
---|
1978 | <= AW_KEY_F12 && p_aww(aww)->modes_f_callbacks && p_aww(aww)->modes_f_callbacks[mykey->awkey-AW_KEY_F1] |
---|
1979 | && aww->event.type == AW_Keyboard_Press) { |
---|
1980 | p_aww(aww)->modes_f_callbacks[mykey->awkey-AW_KEY_F1]->run_callbacks(); |
---|
1981 | } |
---|
1982 | else { |
---|
1983 | run_callback = true; |
---|
1984 | } |
---|
1985 | } |
---|
1986 | |
---|
1987 | if (run_double_click_callback) { |
---|
1988 | if (cbs->help_text == (char*)1) { |
---|
1989 | cbs->run_callbacks(); |
---|
1990 | } |
---|
1991 | else { |
---|
1992 | if (area) |
---|
1993 | area->get_double_click_cb()->run_callbacks(); |
---|
1994 | } |
---|
1995 | } |
---|
1996 | |
---|
1997 | if (run_callback && (cbs->help_text == (char*)0)) { |
---|
1998 | cbs->run_callbacks(); |
---|
1999 | } |
---|
2000 | } |
---|
2001 | |
---|
2002 | void AW_area_management::set_input_callback(AW_window *aww, const WindowCallback& wcb) { |
---|
2003 | XtAddCallback(area, XmNinputCallback, |
---|
2004 | (XtCallbackProc)AW_inputCB_draw_area, |
---|
2005 | (XtPointer)new AW_cb(aww, wcb)); |
---|
2006 | } |
---|
2007 | |
---|
2008 | void AW_area_management::set_double_click_callback(AW_window *aww, const WindowCallback& wcb) { |
---|
2009 | double_click_cb = new AW_cb(aww, wcb, (char*)0, double_click_cb); |
---|
2010 | } |
---|
2011 | |
---|
2012 | void AW_window::set_double_click_callback(AW_area area, const WindowCallback& wcb) { |
---|
2013 | AW_area_management *aram = MAP_ARAM(area); |
---|
2014 | if (!aram) |
---|
2015 | return; |
---|
2016 | aram->set_double_click_callback(this, wcb); |
---|
2017 | } |
---|
2018 | |
---|
2019 | // --------------- |
---|
2020 | // motion |
---|
2021 | |
---|
2022 | static void AW_motionCB(Widget /*w*/, XtPointer aw_cb_struct, XEvent *ev, Boolean*) { |
---|
2023 | AW_cb *cbs = (AW_cb *) aw_cb_struct; |
---|
2024 | |
---|
2025 | cbs->aw->event.type = AW_Mouse_Drag; |
---|
2026 | cbs->aw->event.x = ev->xmotion.x; |
---|
2027 | cbs->aw->event.y = ev->xmotion.y; |
---|
2028 | cbs->aw->event.keycode = AW_KEY_NONE; |
---|
2029 | |
---|
2030 | cbs->run_callbacks(); |
---|
2031 | } |
---|
2032 | void AW_area_management::set_motion_callback(AW_window *aww, const WindowCallback& wcb) { |
---|
2033 | XtAddEventHandler(area, ButtonMotionMask, False, |
---|
2034 | AW_motionCB, (XtPointer) new AW_cb(aww, wcb, "")); |
---|
2035 | } |
---|
2036 | static long destroy_awar(const char *, long val, void *) { |
---|
2037 | AW_awar *awar = (AW_awar*)val; |
---|
2038 | delete awar; |
---|
2039 | return 0; // remove from hash |
---|
2040 | } |
---|
2041 | |
---|
2042 | void AW_root::exit_variables() { |
---|
2043 | if (hash_table_for_variables) { |
---|
2044 | GBS_hash_do_loop(hash_table_for_variables, destroy_awar, NULL); |
---|
2045 | GBS_free_hash(hash_table_for_variables); |
---|
2046 | hash_table_for_variables = NULL; |
---|
2047 | } |
---|
2048 | |
---|
2049 | if (hash_for_windows) { |
---|
2050 | GBS_free_hash(hash_for_windows); |
---|
2051 | hash_for_windows = NULL; |
---|
2052 | } |
---|
2053 | |
---|
2054 | if (application_database) { |
---|
2055 | GBDATA *prop_main = application_database; |
---|
2056 | application_database = NULL; |
---|
2057 | GB_close(prop_main); |
---|
2058 | } |
---|
2059 | } |
---|
2060 | |
---|
2061 | void AW_root::exit_root() { |
---|
2062 | aw_uninstall_xkeys(); |
---|
2063 | } |
---|
2064 | |
---|
2065 | void AW_window::update_scrollbar_settings_from_awars(AW_orientation orientation) { |
---|
2066 | AW_screen_area scrolled; |
---|
2067 | get_scrollarea_size(&scrolled); |
---|
2068 | |
---|
2069 | if (orientation == AW_HORIZONTAL) { |
---|
2070 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNpageIncrement, (int)(scrolled.r*(window_local_awar("horizontal_page_increment")->read_int()*0.01)), NULL); |
---|
2071 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNincrement, (int)(window_local_awar("scroll_width_horizontal")->read_int()), NULL); |
---|
2072 | XtVaSetValues(p_w->scroll_bar_horizontal, XmNrepeatDelay, (int)(window_local_awar("scroll_delay_horizontal")->read_int()), NULL); |
---|
2073 | } |
---|
2074 | else { |
---|
2075 | XtVaSetValues(p_w->scroll_bar_vertical, XmNpageIncrement, (int)(scrolled.b*(window_local_awar("vertical_page_increment")->read_int()*0.01)), NULL); |
---|
2076 | XtVaSetValues(p_w->scroll_bar_vertical, XmNincrement, (int)(window_local_awar("scroll_width_vertical")->read_int()), NULL); |
---|
2077 | XtVaSetValues(p_w->scroll_bar_vertical, XmNrepeatDelay, (int)(window_local_awar("scroll_delay_vertical")->read_int()), NULL); |
---|
2078 | } |
---|
2079 | } |
---|
2080 | |
---|
2081 | void AW_area_management::create_devices(AW_window *aww, AW_area ar) { |
---|
2082 | AW_root *root = aww->get_root(); |
---|
2083 | common = new AW_common_Xm(XtDisplay(area), XtWindow(area), p_global->color_table, aww->color_table, aww->color_table_size, aww, ar); |
---|
2084 | } |
---|
2085 | |
---|
2086 | AW_color_idx AW_window::alloc_named_data_color(int colnum, const char *colorname) { |
---|
2087 | if (!color_table_size) { |
---|
2088 | color_table_size = AW_STD_COLOR_IDX_MAX + colnum; |
---|
2089 | ARB_alloc(color_table, color_table_size); |
---|
2090 | for (int i = 0; i<color_table_size; ++i) color_table[i] = AW_NO_COLOR; |
---|
2091 | } |
---|
2092 | else { |
---|
2093 | if (colnum>=color_table_size) { |
---|
2094 | long new_size = colnum+8; |
---|
2095 | ARB_realloc(color_table, new_size); |
---|
2096 | for (int i = color_table_size; i<new_size; ++i) { |
---|
2097 | color_table[i] = AW_NO_COLOR; |
---|
2098 | } |
---|
2099 | color_table_size = new_size; |
---|
2100 | } |
---|
2101 | } |
---|
2102 | XColor xcolor_returned, xcolor_exakt; |
---|
2103 | |
---|
2104 | if (p_global->screen_depth == 1) { // Black and White Monitor |
---|
2105 | static int col = 1; |
---|
2106 | if (colnum == AW_DATA_BG) { |
---|
2107 | col = 1; |
---|
2108 | if (strcmp(colorname, "white")) |
---|
2109 | col *= -1; |
---|
2110 | } |
---|
2111 | if (col==1) { |
---|
2112 | color_table[colnum] = WhitePixelOfScreen(XtScreen(p_global->toplevel_widget)); |
---|
2113 | } |
---|
2114 | else { |
---|
2115 | color_table[colnum] = BlackPixelOfScreen(XtScreen(p_global->toplevel_widget)); |
---|
2116 | } |
---|
2117 | if (colnum == AW_DATA_BG) |
---|
2118 | col *= -1; |
---|
2119 | } |
---|
2120 | else { // Color monitor |
---|
2121 | if (color_table[colnum] != AW_NO_COLOR) { |
---|
2122 | unsigned long color = color_table[colnum]; |
---|
2123 | XFreeColors(p_global->display, p_global->colormap, &color, 1, 0); |
---|
2124 | } |
---|
2125 | if (XAllocNamedColor(p_global->display, p_global->colormap, colorname, &xcolor_returned, &xcolor_exakt) == 0) { |
---|
2126 | aw_message(GBS_global_string("XAllocColor failed: %s\n", colorname)); |
---|
2127 | color_table[colnum] = AW_NO_COLOR; |
---|
2128 | } |
---|
2129 | else { |
---|
2130 | color_table[colnum] = xcolor_returned.pixel; |
---|
2131 | } |
---|
2132 | } |
---|
2133 | if (colnum == AW_DATA_BG) { |
---|
2134 | XtVaSetValues(p_w->areas[AW_MIDDLE_AREA]->get_area(), XmNbackground, color_table[colnum], NULL); |
---|
2135 | } |
---|
2136 | return (AW_color_idx)colnum; |
---|
2137 | } |
---|
2138 | |
---|
2139 | void AW_window::create_devices() { |
---|
2140 | unsigned long background_color; |
---|
2141 | if (p_w->areas[AW_INFO_AREA]) { |
---|
2142 | p_w->areas[AW_INFO_AREA]->create_devices(this, AW_INFO_AREA); |
---|
2143 | XtVaGetValues(p_w->areas[AW_INFO_AREA]->get_area(), XmNbackground, &background_color, NULL); |
---|
2144 | p_global->color_table[AW_WINDOW_DRAG] = background_color ^ p_global->color_table[AW_WINDOW_FG]; |
---|
2145 | } |
---|
2146 | if (p_w->areas[AW_MIDDLE_AREA]) { |
---|
2147 | p_w->areas[AW_MIDDLE_AREA]->create_devices(this, AW_MIDDLE_AREA); |
---|
2148 | } |
---|
2149 | if (p_w->areas[AW_BOTTOM_AREA]) { |
---|
2150 | p_w->areas[AW_BOTTOM_AREA]->create_devices(this, AW_BOTTOM_AREA); |
---|
2151 | } |
---|
2152 | } |
---|
2153 | |
---|
2154 | void aw_insert_default_help_entries(AW_window *aww) { |
---|
2155 | aww->insert_help_topic("Click here and then on the questionable button/menu/...", "q", 0, AWM_ALL, AW_help_entry_pressed); |
---|
2156 | |
---|
2157 | aww->insert_help_topic("How to use help", "H", "help.hlp", AWM_ALL, makeHelpCallback("help.hlp")); |
---|
2158 | aww->insert_help_topic("ARB help", "A", "arb.hlp", AWM_ALL, makeHelpCallback("arb.hlp")); |
---|
2159 | } |
---|
2160 | |
---|
2161 | inline char *strdup_getlen(const char *str, int& len) { |
---|
2162 | len = strlen(str); |
---|
2163 | return ARB_strduplen(str, len); |
---|
2164 | } |
---|
2165 | Label::Label(const char *labeltext, AW_window *aww) { |
---|
2166 | imageref = AW_IS_IMAGEREF(labeltext); |
---|
2167 | if (imageref) { |
---|
2168 | label = strdup_getlen(AW_get_pixmapPath(labeltext+1), len); |
---|
2169 | } |
---|
2170 | else { |
---|
2171 | AW_awar *is_awar = aww->get_root()->label_is_awar(labeltext); |
---|
2172 | |
---|
2173 | if (is_awar) { // for labels displaying awar values, insert dummy text here |
---|
2174 | len = aww->get_at().length_of_buttons - 2; |
---|
2175 | if (len < 1) len = 1; |
---|
2176 | |
---|
2177 | ARB_alloc(label, len+1); |
---|
2178 | memset(label, 'y', len); |
---|
2179 | label[len] = 0; |
---|
2180 | } |
---|
2181 | else { |
---|
2182 | label = strdup_getlen(labeltext, len); |
---|
2183 | } |
---|
2184 | } |
---|
2185 | } |
---|
2186 | |
---|
2187 | void AW_label_in_awar_list(AW_window *aww, Widget widget, const char *str) { |
---|
2188 | AW_awar *is_awar = aww->get_root()->label_is_awar(str); |
---|
2189 | if (is_awar) { |
---|
2190 | char *display = is_awar->read_as_string(); |
---|
2191 | |
---|
2192 | if (!display) { |
---|
2193 | aw_assert(0); // awar not found |
---|
2194 | freeset(display, GBS_global_string_copy("<undef AWAR: %s>", str)); |
---|
2195 | } |
---|
2196 | if (!display[0]) freeset(display, strdup(" ")); // empty string causes wrong-sized buttons |
---|
2197 | |
---|
2198 | aww->update_label(widget, display); |
---|
2199 | free(display); |
---|
2200 | |
---|
2201 | is_awar->tie_widget(0, widget, AW_WIDGET_LABEL_FIELD, aww); |
---|
2202 | } |
---|
2203 | } |
---|
2204 | |
---|
2205 | static long aw_loop_get_window_geometry(const char *, long val, void *) { |
---|
2206 | aw_update_window_geometry_awars((AW_window *)val); |
---|
2207 | return val; |
---|
2208 | } |
---|
2209 | void aw_update_all_window_geometry_awars(AW_root *awr) { |
---|
2210 | GBS_hash_do_loop(awr->hash_for_windows, aw_loop_get_window_geometry, NULL); |
---|
2211 | } |
---|
2212 | |
---|
2213 | static long aw_loop_forget_window_geometry(const char *, long val, void *) { |
---|
2214 | ((AW_window*)val)->reset_geometry_awars(); |
---|
2215 | return val; |
---|
2216 | } |
---|
2217 | void AW_forget_all_window_geometry(AW_window *aww) { |
---|
2218 | AW_root *awr = aww->get_root(); |
---|
2219 | GBS_hash_do_loop(awr->hash_for_windows, aw_loop_forget_window_geometry, NULL); // reset geometry for used windows |
---|
2220 | |
---|
2221 | // reset geometry in stored, unused windows |
---|
2222 | GBDATA *gb_props = awr->check_properties(NULL); |
---|
2223 | GB_transaction ta(gb_props); |
---|
2224 | GBDATA *gb_win = GB_search(gb_props, LAYOUT_AWAR_ROOT, GB_FIND); |
---|
2225 | if (gb_win) { |
---|
2226 | for (GBDATA *gbw = GB_child(gb_win); gbw; ) { |
---|
2227 | const char *key = GB_read_key_pntr(gbw); |
---|
2228 | long usedWin = GBS_read_hash(awr->hash_for_windows, key); |
---|
2229 | GBDATA *gbnext = GB_nextChild(gbw); |
---|
2230 | |
---|
2231 | if (!usedWin) { |
---|
2232 | GB_ERROR error = GB_delete(gbw); |
---|
2233 | aw_message_if(error); |
---|
2234 | } |
---|
2235 | gbw = gbnext; |
---|
2236 | } |
---|
2237 | } |
---|
2238 | } |
---|
2239 | |
---|
2240 | static const char *existingPixmap(const char *icon_relpath, const char *name) { |
---|
2241 | const char *icon_relname = GBS_global_string("%s/%s.xpm", icon_relpath, name); |
---|
2242 | const char *icon_fullname = AW_get_pixmapPath(icon_relname); |
---|
2243 | |
---|
2244 | if (!GB_is_regularfile(icon_fullname)) icon_fullname = NULL; |
---|
2245 | |
---|
2246 | return icon_fullname; |
---|
2247 | } |
---|
2248 | |
---|
2249 | |
---|
2250 | static Pixmap getIcon(Screen *screen, const char *iconName, Pixel foreground, Pixel background) { |
---|
2251 | static SmartCustomPtr(GB_HASH, GBS_free_hash) icon_hash; |
---|
2252 | if (icon_hash.isNull()) { |
---|
2253 | icon_hash = GBS_create_hash(100, GB_MIND_CASE); |
---|
2254 | } |
---|
2255 | |
---|
2256 | Pixmap pixmap = GBS_read_hash(&*icon_hash, iconName); |
---|
2257 | |
---|
2258 | if (!pixmap && iconName) { |
---|
2259 | const char *iconFile = existingPixmap("icons", iconName); |
---|
2260 | |
---|
2261 | if (iconFile) { |
---|
2262 | char *ico = strdup(iconFile); |
---|
2263 | pixmap = XmGetPixmap(screen, ico, foreground, background); |
---|
2264 | GBS_write_hash(&*icon_hash, iconName, pixmap); |
---|
2265 | free(ico); |
---|
2266 | } |
---|
2267 | } |
---|
2268 | |
---|
2269 | return pixmap; |
---|
2270 | } |
---|
2271 | |
---|
2272 | Widget aw_create_shell(AW_window *aww, bool allow_resize, bool allow_close, int width, int height, int posx, int posy) { // @@@ move into AW_window |
---|
2273 | AW_root *root = aww->get_root(); |
---|
2274 | Widget shell; |
---|
2275 | |
---|
2276 | // set minimum window size to size provided by init |
---|
2277 | if (width >aww->get_at().max_x_size) aww->get_at().max_x_size = width; |
---|
2278 | if (height>aww->get_at().max_y_size) aww->get_at().max_y_size = height; |
---|
2279 | |
---|
2280 | bool has_user_geometry = false; |
---|
2281 | if (!GBS_read_hash(root->hash_for_windows, aww->get_window_id())) { |
---|
2282 | GBS_write_hash(root->hash_for_windows, aww->get_window_id(), (long)aww); |
---|
2283 | |
---|
2284 | aww->create_user_geometry_awars(posx, posy, width, height); |
---|
2285 | } |
---|
2286 | { |
---|
2287 | int user_width, user_height; aww->get_size_from_awars(user_width, user_height); |
---|
2288 | int user_posx, user_posy; aww->get_pos_from_awars(user_posx, user_posy); |
---|
2289 | |
---|
2290 | if (allow_resize) { |
---|
2291 | if (width != user_width) { width = user_width; has_user_geometry = true; } |
---|
2292 | if (height != user_height) { height = user_height; has_user_geometry = true; } |
---|
2293 | } |
---|
2294 | |
---|
2295 | // @@@ FIXME: maximum should be set to current screen size minus some offset |
---|
2296 | // to ensure that windows do not appear outside screen |
---|
2297 | if (posx != user_posx) { posx = user_posx; has_user_geometry = true; } |
---|
2298 | if (posy != user_posy) { posy = user_posy; has_user_geometry = true; } |
---|
2299 | |
---|
2300 | if (has_user_geometry) { |
---|
2301 | aww->recalc_size_atShow(AW_RESIZE_USER); // keep user geometry (only if user size is smaller than default size, the latter is used) |
---|
2302 | } |
---|
2303 | else { // no geometry yet |
---|
2304 | aww->recalc_pos_atShow(AW_REPOS_TO_MOUSE_ONCE); // popup the window at current mouse position |
---|
2305 | } |
---|
2306 | } |
---|
2307 | |
---|
2308 | if (allow_resize) { |
---|
2309 | // create the window big enough to ensure that all widgets |
---|
2310 | // are created in visible area (otherwise widget are crippled). |
---|
2311 | // window will be resized later (on show) |
---|
2312 | |
---|
2313 | width = WIDER_THAN_SCREEN; |
---|
2314 | height = HIGHER_THAN_SCREEN; |
---|
2315 | |
---|
2316 | aww->recalc_size_atShow(AW_RESIZE_ANY); |
---|
2317 | } |
---|
2318 | |
---|
2319 | Widget father = p_global->toplevel_widget; |
---|
2320 | Screen *screen = XtScreen(father); |
---|
2321 | Pixmap icon_pixmap = getIcon(screen, aww->window_defaults_name, p_global->foreground, p_global->background); |
---|
2322 | |
---|
2323 | if (!icon_pixmap) { |
---|
2324 | icon_pixmap = getIcon(screen, root->program_name, p_global->foreground, p_global->background); |
---|
2325 | } |
---|
2326 | |
---|
2327 | if (!icon_pixmap) { |
---|
2328 | GBK_terminatef("Missing icon pixmap for window '%s'\n", aww->window_defaults_name); |
---|
2329 | } |
---|
2330 | else if (icon_pixmap == XmUNSPECIFIED_PIXMAP) { |
---|
2331 | GBK_terminatef("Failed to load icon pixmap for window '%s'\n", aww->window_defaults_name); |
---|
2332 | } |
---|
2333 | |
---|
2334 | int focusPolicy = root->focus_follows_mouse ? XmPOINTER : XmEXPLICIT; |
---|
2335 | |
---|
2336 | { |
---|
2337 | aw_xargs args(9); |
---|
2338 | |
---|
2339 | args.add(XmNwidth, width); |
---|
2340 | args.add(XmNheight, height); |
---|
2341 | args.add(XmNx, posx); |
---|
2342 | args.add(XmNy, posy); |
---|
2343 | args.add(XmNtitle, (XtArgVal)aww->window_name); |
---|
2344 | args.add(XmNiconName, (XtArgVal)aww->window_name); |
---|
2345 | args.add(XmNkeyboardFocusPolicy, focusPolicy); |
---|
2346 | args.add(XmNdeleteResponse, XmDO_NOTHING); |
---|
2347 | args.add(XtNiconPixmap, icon_pixmap); |
---|
2348 | |
---|
2349 | if (!p_global->main_widget || !p_global->main_aww->is_shown()) { |
---|
2350 | shell = XtCreatePopupShell("editor", applicationShellWidgetClass, father, args.list(), args.size()); |
---|
2351 | } |
---|
2352 | else { |
---|
2353 | shell = XtCreatePopupShell("transient", transientShellWidgetClass, father, args.list(), args.size()); |
---|
2354 | } |
---|
2355 | } |
---|
2356 | |
---|
2357 | if (!p_global->main_widget) { |
---|
2358 | p_global->main_widget = shell; |
---|
2359 | p_global->main_aww = aww; |
---|
2360 | } |
---|
2361 | else { |
---|
2362 | if (!p_global->main_aww->is_shown()) { // now i am the root window |
---|
2363 | p_global->main_widget = shell; |
---|
2364 | p_global->main_aww = aww; |
---|
2365 | } |
---|
2366 | } |
---|
2367 | |
---|
2368 | aw_set_delete_window_cb(aww, shell, allow_close); |
---|
2369 | |
---|
2370 | // set icon window (for window managers where iconified applications are dropped onto desktop or similar) |
---|
2371 | { |
---|
2372 | Window icon_window; |
---|
2373 | XtVaGetValues(shell, XmNiconWindow, &icon_window, NULL); |
---|
2374 | |
---|
2375 | Display *dpy = XtDisplay(shell); |
---|
2376 | if (!icon_window) { |
---|
2377 | XSetWindowAttributes attr; |
---|
2378 | attr.background_pixmap = icon_pixmap; |
---|
2379 | |
---|
2380 | int xpos, ypos; |
---|
2381 | unsigned int xsize, ysize, borderwidth, depth; |
---|
2382 | Window wroot; |
---|
2383 | |
---|
2384 | if (XGetGeometry(dpy, icon_pixmap, &wroot, &xpos, &ypos, &xsize, &ysize, &borderwidth, &depth)) { |
---|
2385 | icon_window = XCreateWindow(dpy, wroot, 0, 0, xsize, ysize, 0, depth, CopyFromParent, CopyFromParent, CWBackPixmap, &attr); |
---|
2386 | } |
---|
2387 | } |
---|
2388 | if (!icon_window) { |
---|
2389 | XtVaSetValues(shell, XmNiconPixmap, icon_pixmap, NULL); |
---|
2390 | } |
---|
2391 | else { |
---|
2392 | XtVaSetValues(shell, XmNiconWindow, icon_window, NULL); |
---|
2393 | XSetWindowBackgroundPixmap(dpy, icon_window, icon_pixmap); |
---|
2394 | XClearWindow(dpy, icon_window); |
---|
2395 | } |
---|
2396 | } |
---|
2397 | |
---|
2398 | return shell; |
---|
2399 | } |
---|
2400 | |
---|
2401 | |
---|
2402 | void aw_realize_widget(AW_window *aww) { |
---|
2403 | if (p_aww(aww)->areas[AW_INFO_AREA] && p_aww(aww)->areas[AW_INFO_AREA]->get_form()) { |
---|
2404 | XtManageChild(p_aww(aww)->areas[AW_INFO_AREA]->get_form()); |
---|
2405 | } |
---|
2406 | if (p_aww(aww)->areas[AW_MIDDLE_AREA] && p_aww(aww)->areas[AW_MIDDLE_AREA]->get_form()) { |
---|
2407 | XtManageChild(p_aww(aww)->areas[AW_MIDDLE_AREA]->get_form()); |
---|
2408 | } |
---|
2409 | if (p_aww(aww)->areas[AW_BOTTOM_AREA] && p_aww(aww)->areas[AW_BOTTOM_AREA]->get_form()) { |
---|
2410 | XtManageChild(p_aww(aww)->areas[AW_BOTTOM_AREA]->get_form()); |
---|
2411 | } |
---|
2412 | XtRealizeWidget(p_aww(aww)->shell); |
---|
2413 | p_aww(aww)->WM_top_offset = AW_CALC_OFFSET_ON_EXPOSE; |
---|
2414 | } |
---|
2415 | |
---|
2416 | void AW_window_menu_modes::init(AW_root *root_in, const char *wid, const char *windowname, int width, int height) { |
---|
2417 | Widget main_window; |
---|
2418 | Widget help_popup; |
---|
2419 | Widget help_label; |
---|
2420 | Widget separator; |
---|
2421 | Widget form1; |
---|
2422 | Widget form2; |
---|
2423 | const char *help_button = "HELP"; |
---|
2424 | const char *help_mnemonic = "H"; |
---|
2425 | |
---|
2426 | #if defined(DUMP_MENU_LIST) |
---|
2427 | initMenuListing(windowname); |
---|
2428 | #endif // DUMP_MENU_LIST |
---|
2429 | root = root_in; // for macro |
---|
2430 | window_name = strdup(windowname); |
---|
2431 | window_defaults_name = GBS_string_2_key(wid); |
---|
2432 | |
---|
2433 | int posx = 50; |
---|
2434 | int posy = 50; |
---|
2435 | |
---|
2436 | p_w->shell = aw_create_shell(this, true, true, width, height, posx, posy); |
---|
2437 | |
---|
2438 | main_window = XtVaCreateManagedWidget("mainWindow1", |
---|
2439 | xmMainWindowWidgetClass, p_w->shell, |
---|
2440 | NULL); |
---|
2441 | |
---|
2442 | p_w->menu_bar[0] = XtVaCreateManagedWidget("menu1", xmRowColumnWidgetClass, |
---|
2443 | main_window, |
---|
2444 | XmNrowColumnType, XmMENU_BAR, |
---|
2445 | NULL); |
---|
2446 | |
---|
2447 | // create shell for help-cascade |
---|
2448 | help_popup = XtVaCreatePopupShell("menu_shell", xmMenuShellWidgetClass, |
---|
2449 | p_w->menu_bar[0], |
---|
2450 | XmNwidth, 1, |
---|
2451 | XmNheight, 1, |
---|
2452 | XmNallowShellResize, true, |
---|
2453 | XmNoverrideRedirect, true, |
---|
2454 | NULL); |
---|
2455 | |
---|
2456 | // create row column in Pull-Down shell |
---|
2457 | p_w->help_pull_down = XtVaCreateWidget("menu_row_column", |
---|
2458 | xmRowColumnWidgetClass, help_popup, |
---|
2459 | XmNrowColumnType, XmMENU_PULLDOWN, |
---|
2460 | NULL); |
---|
2461 | |
---|
2462 | // create HELP-label in menu bar |
---|
2463 | help_label = XtVaCreateManagedWidget("menu1_top_b1", |
---|
2464 | xmCascadeButtonWidgetClass, p_w->menu_bar[0], |
---|
2465 | RES_CONVERT(XmNlabelString, help_button), |
---|
2466 | RES_CONVERT(XmNmnemonic, help_mnemonic), |
---|
2467 | XmNsubMenuId, p_w->help_pull_down, NULL); |
---|
2468 | XtVaSetValues(p_w->menu_bar[0], XmNmenuHelpWidget, help_label, NULL); |
---|
2469 | root->make_sensitive(help_label, AWM_ALL); |
---|
2470 | |
---|
2471 | form1 = XtVaCreateManagedWidget("form1", |
---|
2472 | xmFormWidgetClass, |
---|
2473 | main_window, |
---|
2474 | // XmNwidth, width, |
---|
2475 | // XmNheight, height, |
---|
2476 | XmNresizePolicy, XmRESIZE_NONE, |
---|
2477 | // XmNx, 0, |
---|
2478 | // XmNy, 0, |
---|
2479 | NULL); |
---|
2480 | |
---|
2481 | p_w->mode_area = XtVaCreateManagedWidget("mode area", |
---|
2482 | xmDrawingAreaWidgetClass, |
---|
2483 | form1, |
---|
2484 | XmNresizePolicy, XmRESIZE_NONE, |
---|
2485 | XmNwidth, 38, |
---|
2486 | XmNheight, height, |
---|
2487 | XmNx, 0, |
---|
2488 | XmNy, 0, |
---|
2489 | XmNleftOffset, 0, |
---|
2490 | XmNtopOffset, 0, |
---|
2491 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2492 | XmNleftAttachment, XmATTACH_POSITION, |
---|
2493 | XmNtopAttachment, XmATTACH_POSITION, |
---|
2494 | XmNmarginHeight, 2, |
---|
2495 | XmNmarginWidth, 1, |
---|
2496 | NULL); |
---|
2497 | |
---|
2498 | separator = XtVaCreateManagedWidget("separator", |
---|
2499 | xmSeparatorWidgetClass, |
---|
2500 | form1, |
---|
2501 | XmNx, 37, |
---|
2502 | XmNshadowThickness, 4, |
---|
2503 | XmNorientation, XmVERTICAL, |
---|
2504 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2505 | XmNtopAttachment, XmATTACH_FORM, |
---|
2506 | XmNleftAttachment, XmATTACH_NONE, |
---|
2507 | XmNleftWidget, NULL, |
---|
2508 | XmNrightAttachment, XmATTACH_NONE, |
---|
2509 | XmNleftOffset, 70, |
---|
2510 | XmNleftPosition, 0, |
---|
2511 | NULL); |
---|
2512 | |
---|
2513 | form2 = XtVaCreateManagedWidget("form2", |
---|
2514 | xmFormWidgetClass, |
---|
2515 | form1, |
---|
2516 | XmNwidth, width, |
---|
2517 | XmNheight, height, |
---|
2518 | XmNtopOffset, 0, |
---|
2519 | XmNbottomOffset, 0, |
---|
2520 | XmNleftOffset, 0, |
---|
2521 | XmNrightOffset, 0, |
---|
2522 | XmNrightAttachment, XmATTACH_FORM, |
---|
2523 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2524 | XmNleftAttachment, XmATTACH_WIDGET, |
---|
2525 | XmNleftWidget, separator, |
---|
2526 | XmNtopAttachment, XmATTACH_POSITION, |
---|
2527 | XmNresizePolicy, XmRESIZE_NONE, |
---|
2528 | XmNx, 0, |
---|
2529 | XmNy, 0, |
---|
2530 | NULL); |
---|
2531 | p_w->areas[AW_INFO_AREA] = |
---|
2532 | new AW_area_management(form2, XtVaCreateManagedWidget("info_area", |
---|
2533 | xmDrawingAreaWidgetClass, |
---|
2534 | form2, |
---|
2535 | XmNheight, 0, |
---|
2536 | XmNbottomAttachment, XmATTACH_NONE, |
---|
2537 | XmNtopAttachment, XmATTACH_FORM, |
---|
2538 | XmNleftAttachment, XmATTACH_FORM, |
---|
2539 | XmNrightAttachment, XmATTACH_FORM, |
---|
2540 | XmNmarginHeight, 2, |
---|
2541 | XmNmarginWidth, 2, |
---|
2542 | NULL)); |
---|
2543 | |
---|
2544 | p_w->areas[AW_BOTTOM_AREA] = |
---|
2545 | new AW_area_management(form2, XtVaCreateManagedWidget("bottom_area", |
---|
2546 | xmDrawingAreaWidgetClass, |
---|
2547 | form2, |
---|
2548 | XmNheight, 0, |
---|
2549 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2550 | XmNtopAttachment, XmATTACH_NONE, |
---|
2551 | XmNleftAttachment, XmATTACH_FORM, |
---|
2552 | XmNrightAttachment, XmATTACH_FORM, |
---|
2553 | NULL)); |
---|
2554 | |
---|
2555 | p_w->scroll_bar_horizontal = XtVaCreateManagedWidget("scroll_bar_horizontal", |
---|
2556 | xmScrollBarWidgetClass, |
---|
2557 | form2, |
---|
2558 | XmNheight, 15, |
---|
2559 | XmNminimum, 0, |
---|
2560 | XmNmaximum, AW_SCROLL_MAX, |
---|
2561 | XmNincrement, 10, |
---|
2562 | XmNsliderSize, AW_SCROLL_MAX, |
---|
2563 | XmNrightAttachment, XmATTACH_FORM, |
---|
2564 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2565 | XmNbottomOffset, 0, |
---|
2566 | XmNleftAttachment, XmATTACH_FORM, |
---|
2567 | XmNtopAttachment, XmATTACH_NONE, |
---|
2568 | XmNorientation, XmHORIZONTAL, |
---|
2569 | XmNrightOffset, 18, |
---|
2570 | NULL); |
---|
2571 | |
---|
2572 | p_w->scroll_bar_vertical = XtVaCreateManagedWidget("scroll_bar_vertical", |
---|
2573 | xmScrollBarWidgetClass, |
---|
2574 | form2, |
---|
2575 | XmNwidth, 15, |
---|
2576 | XmNminimum, 0, |
---|
2577 | XmNmaximum, AW_SCROLL_MAX, |
---|
2578 | XmNincrement, 10, |
---|
2579 | XmNsliderSize, AW_SCROLL_MAX, |
---|
2580 | XmNrightAttachment, XmATTACH_FORM, |
---|
2581 | XmNbottomAttachment, XmATTACH_WIDGET, |
---|
2582 | XmNbottomWidget, p_w->scroll_bar_horizontal, |
---|
2583 | XmNbottomOffset, 3, |
---|
2584 | XmNleftOffset, 3, |
---|
2585 | XmNrightOffset, 3, |
---|
2586 | XmNleftAttachment, XmATTACH_NONE, |
---|
2587 | XmNtopAttachment, XmATTACH_WIDGET, |
---|
2588 | XmNtopWidget, INFO_WIDGET, |
---|
2589 | NULL); |
---|
2590 | |
---|
2591 | p_w->frame = XtVaCreateManagedWidget("draw_area", |
---|
2592 | xmFrameWidgetClass, |
---|
2593 | form2, |
---|
2594 | XmNshadowType, XmSHADOW_IN, |
---|
2595 | XmNshadowThickness, 2, |
---|
2596 | XmNleftOffset, 3, |
---|
2597 | XmNtopOffset, 3, |
---|
2598 | XmNbottomOffset, 3, |
---|
2599 | XmNrightOffset, 3, |
---|
2600 | XmNbottomAttachment, XmATTACH_WIDGET, |
---|
2601 | XmNbottomWidget, p_w->scroll_bar_horizontal, |
---|
2602 | XmNtopAttachment, XmATTACH_FORM, |
---|
2603 | XmNtopOffset, 0, |
---|
2604 | XmNleftAttachment, XmATTACH_FORM, |
---|
2605 | XmNrightAttachment, XmATTACH_WIDGET, |
---|
2606 | XmNrightWidget, p_w->scroll_bar_vertical, |
---|
2607 | NULL); |
---|
2608 | |
---|
2609 | p_w->areas[AW_MIDDLE_AREA] = |
---|
2610 | new AW_area_management(p_w->frame, XtVaCreateManagedWidget("draw area", |
---|
2611 | xmDrawingAreaWidgetClass, |
---|
2612 | p_w->frame, |
---|
2613 | XmNmarginHeight, 0, |
---|
2614 | XmNmarginWidth, 0, |
---|
2615 | NULL)); |
---|
2616 | |
---|
2617 | XmMainWindowSetAreas(main_window, p_w->menu_bar[0], (Widget) NULL, (Widget) NULL, (Widget) NULL, form1); |
---|
2618 | |
---|
2619 | aw_realize_widget(this); |
---|
2620 | |
---|
2621 | create_devices(); |
---|
2622 | aw_insert_default_help_entries(this); |
---|
2623 | create_window_variables(); |
---|
2624 | } |
---|
2625 | |
---|
2626 | void AW_window_menu::init(AW_root *root_in, const char *wid, const char *windowname, int width, int height) { |
---|
2627 | Widget main_window; |
---|
2628 | Widget help_popup; |
---|
2629 | Widget help_label; |
---|
2630 | Widget separator; |
---|
2631 | Widget form1; |
---|
2632 | Widget form2; |
---|
2633 | const char *help_button = "HELP"; |
---|
2634 | const char *help_mnemonic = "H"; |
---|
2635 | |
---|
2636 | #if defined(DUMP_MENU_LIST) |
---|
2637 | initMenuListing(windowname); |
---|
2638 | #endif // DUMP_MENU_LIST |
---|
2639 | root = root_in; // for macro |
---|
2640 | window_name = strdup(windowname); |
---|
2641 | window_defaults_name = GBS_string_2_key(wid); |
---|
2642 | |
---|
2643 | int posx = 50; |
---|
2644 | int posy = 50; |
---|
2645 | |
---|
2646 | p_w->shell = aw_create_shell(this, true, true, width, height, posx, posy); |
---|
2647 | |
---|
2648 | main_window = XtVaCreateManagedWidget("mainWindow1", |
---|
2649 | xmMainWindowWidgetClass, p_w->shell, |
---|
2650 | NULL); |
---|
2651 | |
---|
2652 | p_w->menu_bar[0] = XtVaCreateManagedWidget("menu1", xmRowColumnWidgetClass, |
---|
2653 | main_window, |
---|
2654 | XmNrowColumnType, XmMENU_BAR, |
---|
2655 | NULL); |
---|
2656 | |
---|
2657 | // create shell for help-cascade |
---|
2658 | help_popup = XtVaCreatePopupShell("menu_shell", xmMenuShellWidgetClass, |
---|
2659 | p_w->menu_bar[0], |
---|
2660 | XmNwidth, 1, |
---|
2661 | XmNheight, 1, |
---|
2662 | XmNallowShellResize, true, |
---|
2663 | XmNoverrideRedirect, true, |
---|
2664 | NULL); |
---|
2665 | |
---|
2666 | // create row column in Pull-Down shell |
---|
2667 | p_w->help_pull_down = XtVaCreateWidget("menu_row_column", |
---|
2668 | xmRowColumnWidgetClass, help_popup, |
---|
2669 | XmNrowColumnType, XmMENU_PULLDOWN, |
---|
2670 | NULL); |
---|
2671 | |
---|
2672 | // create HELP-label in menu bar |
---|
2673 | help_label = XtVaCreateManagedWidget("menu1_top_b1", |
---|
2674 | xmCascadeButtonWidgetClass, p_w->menu_bar[0], |
---|
2675 | RES_CONVERT(XmNlabelString, help_button), |
---|
2676 | RES_CONVERT(XmNmnemonic, help_mnemonic), |
---|
2677 | XmNsubMenuId, p_w->help_pull_down, NULL); |
---|
2678 | XtVaSetValues(p_w->menu_bar[0], XmNmenuHelpWidget, help_label, NULL); |
---|
2679 | root->make_sensitive(help_label, AWM_ALL); |
---|
2680 | |
---|
2681 | form1 = XtVaCreateManagedWidget("form1", |
---|
2682 | xmFormWidgetClass, |
---|
2683 | main_window, |
---|
2684 | // XmNwidth, width, |
---|
2685 | // XmNheight, height, |
---|
2686 | XmNresizePolicy, XmRESIZE_NONE, |
---|
2687 | // XmNx, 0, |
---|
2688 | // XmNy, 0, |
---|
2689 | NULL); |
---|
2690 | |
---|
2691 | p_w->mode_area = XtVaCreateManagedWidget("mode area", |
---|
2692 | xmDrawingAreaWidgetClass, |
---|
2693 | form1, |
---|
2694 | XmNresizePolicy, XmRESIZE_NONE, |
---|
2695 | XmNwidth, 17, |
---|
2696 | XmNheight, height, |
---|
2697 | XmNx, 0, |
---|
2698 | XmNy, 0, |
---|
2699 | XmNleftOffset, 0, |
---|
2700 | XmNtopOffset, 0, |
---|
2701 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2702 | XmNleftAttachment, XmATTACH_POSITION, |
---|
2703 | XmNtopAttachment, XmATTACH_POSITION, |
---|
2704 | XmNmarginHeight, 2, |
---|
2705 | XmNmarginWidth, 1, |
---|
2706 | NULL); |
---|
2707 | |
---|
2708 | separator = p_w->mode_area; |
---|
2709 | |
---|
2710 | form2 = XtVaCreateManagedWidget("form2", |
---|
2711 | xmFormWidgetClass, |
---|
2712 | form1, |
---|
2713 | XmNwidth, width, |
---|
2714 | XmNheight, height, |
---|
2715 | XmNtopOffset, 0, |
---|
2716 | XmNbottomOffset, 0, |
---|
2717 | XmNleftOffset, 0, |
---|
2718 | XmNrightOffset, 0, |
---|
2719 | XmNrightAttachment, XmATTACH_FORM, |
---|
2720 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2721 | XmNleftAttachment, XmATTACH_WIDGET, |
---|
2722 | XmNleftWidget, separator, |
---|
2723 | XmNtopAttachment, XmATTACH_POSITION, |
---|
2724 | XmNresizePolicy, XmRESIZE_NONE, |
---|
2725 | XmNx, 0, |
---|
2726 | XmNy, 0, |
---|
2727 | NULL); |
---|
2728 | p_w->areas[AW_INFO_AREA] = |
---|
2729 | new AW_area_management(form2, XtVaCreateManagedWidget("info_area", |
---|
2730 | xmDrawingAreaWidgetClass, |
---|
2731 | form2, |
---|
2732 | XmNheight, 0, |
---|
2733 | XmNbottomAttachment, XmATTACH_NONE, |
---|
2734 | XmNtopAttachment, XmATTACH_FORM, |
---|
2735 | XmNleftAttachment, XmATTACH_FORM, |
---|
2736 | XmNrightAttachment, XmATTACH_FORM, |
---|
2737 | XmNmarginHeight, 2, |
---|
2738 | XmNmarginWidth, 2, |
---|
2739 | NULL)); |
---|
2740 | |
---|
2741 | p_w->areas[AW_BOTTOM_AREA] = |
---|
2742 | new AW_area_management(form2, XtVaCreateManagedWidget("bottom_area", |
---|
2743 | xmDrawingAreaWidgetClass, |
---|
2744 | form2, |
---|
2745 | XmNheight, 0, |
---|
2746 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2747 | XmNtopAttachment, XmATTACH_NONE, |
---|
2748 | XmNleftAttachment, XmATTACH_FORM, |
---|
2749 | XmNrightAttachment, XmATTACH_FORM, |
---|
2750 | NULL)); |
---|
2751 | |
---|
2752 | p_w->scroll_bar_horizontal = XtVaCreateManagedWidget("scroll_bar_horizontal", |
---|
2753 | xmScrollBarWidgetClass, |
---|
2754 | form2, |
---|
2755 | XmNheight, 15, |
---|
2756 | XmNminimum, 0, |
---|
2757 | XmNmaximum, AW_SCROLL_MAX, |
---|
2758 | XmNincrement, 10, |
---|
2759 | XmNsliderSize, AW_SCROLL_MAX, |
---|
2760 | XmNrightAttachment, XmATTACH_FORM, |
---|
2761 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2762 | XmNbottomOffset, 0, |
---|
2763 | XmNleftAttachment, XmATTACH_FORM, |
---|
2764 | XmNtopAttachment, XmATTACH_NONE, |
---|
2765 | XmNorientation, XmHORIZONTAL, |
---|
2766 | XmNrightOffset, 18, |
---|
2767 | NULL); |
---|
2768 | |
---|
2769 | p_w->scroll_bar_vertical = XtVaCreateManagedWidget("scroll_bar_vertical", |
---|
2770 | xmScrollBarWidgetClass, |
---|
2771 | form2, |
---|
2772 | XmNwidth, 15, |
---|
2773 | XmNminimum, 0, |
---|
2774 | XmNmaximum, AW_SCROLL_MAX, |
---|
2775 | XmNincrement, 10, |
---|
2776 | XmNsliderSize, AW_SCROLL_MAX, |
---|
2777 | XmNrightAttachment, XmATTACH_FORM, |
---|
2778 | XmNbottomAttachment, XmATTACH_WIDGET, |
---|
2779 | XmNbottomWidget, p_w->scroll_bar_horizontal, |
---|
2780 | XmNbottomOffset, 3, |
---|
2781 | XmNleftOffset, 3, |
---|
2782 | XmNrightOffset, 3, |
---|
2783 | XmNleftAttachment, XmATTACH_NONE, |
---|
2784 | XmNtopAttachment, XmATTACH_WIDGET, |
---|
2785 | XmNtopWidget, INFO_WIDGET, |
---|
2786 | NULL); |
---|
2787 | |
---|
2788 | p_w->frame = XtVaCreateManagedWidget("draw_area", |
---|
2789 | xmFrameWidgetClass, |
---|
2790 | form2, |
---|
2791 | XmNshadowType, XmSHADOW_IN, |
---|
2792 | XmNshadowThickness, 2, |
---|
2793 | XmNleftOffset, 3, |
---|
2794 | XmNtopOffset, 3, |
---|
2795 | XmNbottomOffset, 3, |
---|
2796 | XmNrightOffset, 3, |
---|
2797 | XmNbottomAttachment, XmATTACH_WIDGET, |
---|
2798 | XmNbottomWidget, p_w->scroll_bar_horizontal, |
---|
2799 | XmNtopAttachment, XmATTACH_FORM, |
---|
2800 | XmNtopOffset, 0, |
---|
2801 | XmNleftAttachment, XmATTACH_FORM, |
---|
2802 | XmNrightAttachment, XmATTACH_WIDGET, |
---|
2803 | XmNrightWidget, p_w->scroll_bar_vertical, |
---|
2804 | NULL); |
---|
2805 | |
---|
2806 | p_w->areas[AW_MIDDLE_AREA] = |
---|
2807 | new AW_area_management(p_w->frame, XtVaCreateManagedWidget("draw area", |
---|
2808 | xmDrawingAreaWidgetClass, |
---|
2809 | p_w->frame, |
---|
2810 | XmNmarginHeight, 0, |
---|
2811 | XmNmarginWidth, 0, |
---|
2812 | NULL)); |
---|
2813 | |
---|
2814 | XmMainWindowSetAreas(main_window, p_w->menu_bar[0], (Widget) NULL, |
---|
2815 | (Widget) NULL, (Widget) NULL, form1); |
---|
2816 | |
---|
2817 | aw_realize_widget(this); |
---|
2818 | |
---|
2819 | create_devices(); |
---|
2820 | aw_insert_default_help_entries(this); |
---|
2821 | create_window_variables(); |
---|
2822 | } |
---|
2823 | |
---|
2824 | void AW_window_simple::init(AW_root *root_in, const char *wid, const char *windowname) { |
---|
2825 | root = root_in; // for macro |
---|
2826 | |
---|
2827 | int width = 100; // this is only the minimum size! |
---|
2828 | int height = 100; |
---|
2829 | int posx = 50; |
---|
2830 | int posy = 50; |
---|
2831 | |
---|
2832 | window_name = strdup(windowname); |
---|
2833 | window_defaults_name = GBS_string_2_key(wid); |
---|
2834 | |
---|
2835 | p_w->shell = aw_create_shell(this, true, true, width, height, posx, posy); |
---|
2836 | |
---|
2837 | // add this to disable resize or maximize in simple dialogs (avoids broken layouts) |
---|
2838 | // XtVaSetValues(p_w->shell, XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE, NULL); |
---|
2839 | |
---|
2840 | Widget form1 = XtVaCreateManagedWidget("forms", xmFormWidgetClass, |
---|
2841 | p_w->shell, |
---|
2842 | NULL); |
---|
2843 | |
---|
2844 | p_w->areas[AW_INFO_AREA] = |
---|
2845 | new AW_area_management(form1, XtVaCreateManagedWidget("info_area", |
---|
2846 | xmDrawingAreaWidgetClass, |
---|
2847 | form1, |
---|
2848 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2849 | XmNtopAttachment, XmATTACH_FORM, |
---|
2850 | XmNleftAttachment, XmATTACH_FORM, |
---|
2851 | XmNrightAttachment, XmATTACH_FORM, |
---|
2852 | XmNmarginHeight, 2, |
---|
2853 | XmNmarginWidth, 2, |
---|
2854 | NULL)); |
---|
2855 | |
---|
2856 | aw_realize_widget(this); |
---|
2857 | create_devices(); |
---|
2858 | } |
---|
2859 | |
---|
2860 | void AW_window_simple_menu::init(AW_root *root_in, const char *wid, const char *windowname) { |
---|
2861 | root = root_in; // for macro |
---|
2862 | |
---|
2863 | const char *help_button = "HELP"; |
---|
2864 | const char *help_mnemonic = "H"; |
---|
2865 | window_name = strdup(windowname); |
---|
2866 | window_defaults_name = GBS_string_2_key(wid); |
---|
2867 | |
---|
2868 | int width = 100; |
---|
2869 | int height = 100; |
---|
2870 | int posx = 50; |
---|
2871 | int posy = 50; |
---|
2872 | |
---|
2873 | p_w->shell = aw_create_shell(this, true, true, width, height, posx, posy); |
---|
2874 | |
---|
2875 | Widget main_window; |
---|
2876 | Widget help_popup; |
---|
2877 | Widget help_label; |
---|
2878 | Widget form1; |
---|
2879 | |
---|
2880 | main_window = XtVaCreateManagedWidget("mainWindow1", |
---|
2881 | xmMainWindowWidgetClass, p_w->shell, |
---|
2882 | NULL); |
---|
2883 | |
---|
2884 | p_w->menu_bar[0] = XtVaCreateManagedWidget("menu1", xmRowColumnWidgetClass, |
---|
2885 | main_window, |
---|
2886 | XmNrowColumnType, XmMENU_BAR, |
---|
2887 | NULL); |
---|
2888 | |
---|
2889 | // create shell for help-cascade |
---|
2890 | help_popup = XtVaCreatePopupShell("menu_shell", xmMenuShellWidgetClass, |
---|
2891 | p_w->menu_bar[0], |
---|
2892 | XmNwidth, 1, |
---|
2893 | XmNheight, 1, |
---|
2894 | XmNallowShellResize, true, |
---|
2895 | XmNoverrideRedirect, true, |
---|
2896 | NULL); |
---|
2897 | |
---|
2898 | // create row column in Pull-Down shell |
---|
2899 | p_w->help_pull_down = XtVaCreateWidget("menu_row_column", |
---|
2900 | xmRowColumnWidgetClass, help_popup, |
---|
2901 | XmNrowColumnType, XmMENU_PULLDOWN, |
---|
2902 | NULL); |
---|
2903 | |
---|
2904 | // create HELP-label in menu bar |
---|
2905 | help_label = XtVaCreateManagedWidget("menu1_top_b1", |
---|
2906 | xmCascadeButtonWidgetClass, p_w->menu_bar[0], |
---|
2907 | RES_CONVERT(XmNlabelString, help_button), |
---|
2908 | RES_CONVERT(XmNmnemonic, help_mnemonic), |
---|
2909 | XmNsubMenuId, p_w->help_pull_down, NULL); |
---|
2910 | XtVaSetValues(p_w->menu_bar[0], XmNmenuHelpWidget, help_label, NULL); |
---|
2911 | root->make_sensitive(help_label, AWM_ALL); |
---|
2912 | |
---|
2913 | form1 = XtVaCreateManagedWidget("form1", |
---|
2914 | xmFormWidgetClass, |
---|
2915 | main_window, |
---|
2916 | XmNtopOffset, 10, |
---|
2917 | XmNresizePolicy, XmRESIZE_NONE, |
---|
2918 | NULL); |
---|
2919 | |
---|
2920 | p_w->areas[AW_INFO_AREA] = |
---|
2921 | new AW_area_management(form1, XtVaCreateManagedWidget("info_area", |
---|
2922 | xmDrawingAreaWidgetClass, |
---|
2923 | form1, |
---|
2924 | XmNbottomAttachment, XmATTACH_FORM, |
---|
2925 | XmNtopAttachment, XmATTACH_FORM, |
---|
2926 | XmNleftAttachment, XmATTACH_FORM, |
---|
2927 | XmNrightAttachment, XmATTACH_FORM, |
---|
2928 | XmNmarginHeight, 2, |
---|
2929 | XmNmarginWidth, 2, |
---|
2930 | NULL)); |
---|
2931 | |
---|
2932 | aw_realize_widget(this); |
---|
2933 | |
---|
2934 | aw_insert_default_help_entries(this); |
---|
2935 | create_devices(); |
---|
2936 | } |
---|
2937 | |
---|
2938 | void AW_window_message::init(AW_root *root_in, const char *wid, const char *windowname, bool allow_close) { |
---|
2939 | root = root_in; // for macro |
---|
2940 | |
---|
2941 | int width = 100; |
---|
2942 | int height = 100; |
---|
2943 | int posx = 50; |
---|
2944 | int posy = 50; |
---|
2945 | |
---|
2946 | window_name = strdup(windowname); |
---|
2947 | window_defaults_name = strdup(wid); |
---|
2948 | |
---|
2949 | // create shell for message box |
---|
2950 | p_w->shell = aw_create_shell(this, true, allow_close, width, height, posx, posy); |
---|
2951 | |
---|
2952 | // disable resize or maximize in simple dialogs (avoids broken layouts) |
---|
2953 | XtVaSetValues(p_w->shell, XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE, |
---|
2954 | NULL); |
---|
2955 | |
---|
2956 | p_w->areas[AW_INFO_AREA] = |
---|
2957 | new AW_area_management(p_w->shell, XtVaCreateManagedWidget("info_area", |
---|
2958 | xmDrawingAreaWidgetClass, |
---|
2959 | p_w->shell, |
---|
2960 | XmNheight, 0, |
---|
2961 | XmNbottomAttachment, XmATTACH_NONE, |
---|
2962 | XmNtopAttachment, XmATTACH_FORM, |
---|
2963 | XmNleftAttachment, XmATTACH_FORM, |
---|
2964 | XmNrightAttachment, XmATTACH_FORM, |
---|
2965 | NULL)); |
---|
2966 | |
---|
2967 | aw_realize_widget(this); |
---|
2968 | } |
---|
2969 | void AW_window_message::init(AW_root *root_in, const char *windowname, bool allow_close) { |
---|
2970 | char *wid = GBS_string_2_key(windowname); |
---|
2971 | init(root_in, wid, windowname, allow_close); |
---|
2972 | free(wid); |
---|
2973 | } |
---|
2974 | |
---|
2975 | void AW_window::set_focus_policy(bool follow_mouse) { |
---|
2976 | int focusPolicy = follow_mouse ? XmPOINTER : XmEXPLICIT; |
---|
2977 | XtVaSetValues(p_w->shell, XmNkeyboardFocusPolicy, focusPolicy, NULL); |
---|
2978 | } |
---|
2979 | |
---|
2980 | void AW_window::select_mode(int mode) { |
---|
2981 | if (mode >= p_w->number_of_modes) |
---|
2982 | return; |
---|
2983 | |
---|
2984 | Widget oldwidget = p_w->modes_widgets[p_w->selected_mode]; |
---|
2985 | p_w->selected_mode = mode; |
---|
2986 | Widget widget = p_w->modes_widgets[p_w->selected_mode]; |
---|
2987 | XtVaSetValues(oldwidget, XmNbackground, p_global->background, NULL); |
---|
2988 | XtVaSetValues(widget, XmNbackground, p_global->foreground, NULL); |
---|
2989 | } |
---|
2990 | |
---|
2991 | static void aw_mode_callback(AW_window *aww, short mode, AW_cb *cbs) { |
---|
2992 | aww->select_mode(mode); |
---|
2993 | cbs->run_callbacks(); |
---|
2994 | } |
---|
2995 | |
---|
2996 | #define MODE_BUTTON_OFFSET 34 |
---|
2997 | inline int yoffset_for_mode_button(int button_number) { |
---|
2998 | return button_number*MODE_BUTTON_OFFSET + (button_number/4)*8 + 2; |
---|
2999 | } |
---|
3000 | |
---|
3001 | int AW_window::create_mode(const char *pixmap, const char *helpText, AW_active mask, const WindowCallback& cb) { |
---|
3002 | aw_assert(legal_mask(mask)); |
---|
3003 | Widget button; |
---|
3004 | |
---|
3005 | TuneBackground(p_w->mode_area, TUNE_BUTTON); // set background color for mode-buttons |
---|
3006 | |
---|
3007 | const char *path = AW_get_pixmapPath(pixmap); |
---|
3008 | |
---|
3009 | int y = yoffset_for_mode_button(p_w->number_of_modes); |
---|
3010 | button = XtVaCreateManagedWidget("", xmPushButtonWidgetClass, p_w->mode_area, |
---|
3011 | XmNx, 0, |
---|
3012 | XmNy, y, |
---|
3013 | XmNlabelType, XmPIXMAP, |
---|
3014 | XmNshadowThickness, 1, |
---|
3015 | XmNbackground, _at->background_color, |
---|
3016 | NULL); |
---|
3017 | XtVaSetValues(button, RES_CONVERT(XmNlabelPixmap, path), NULL); |
---|
3018 | XtVaGetValues(button, XmNforeground, &p_global->foreground, NULL); |
---|
3019 | |
---|
3020 | AW_cb *cbs = new AW_cb(this, cb, 0); |
---|
3021 | AW_cb *cb2 = new AW_cb(this, makeWindowCallback(aw_mode_callback, p_w->number_of_modes, cbs), helpText, cbs); |
---|
3022 | XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)AW_server_callback, (XtPointer)cb2); |
---|
3023 | |
---|
3024 | if (!p_w->modes_f_callbacks) ARB_calloc(p_w->modes_f_callbacks, AW_NUMBER_OF_F_KEYS); // valgrinders : never freed because AW_window never is freed |
---|
3025 | if (!p_w->modes_widgets) ARB_calloc(p_w->modes_widgets, AW_NUMBER_OF_F_KEYS); |
---|
3026 | |
---|
3027 | if (p_w->number_of_modes<AW_NUMBER_OF_F_KEYS) { |
---|
3028 | p_w->modes_f_callbacks[p_w->number_of_modes] = cb2; |
---|
3029 | p_w->modes_widgets[p_w->number_of_modes] = button; |
---|
3030 | } |
---|
3031 | |
---|
3032 | root->make_sensitive(button, mask); |
---|
3033 | p_w->number_of_modes++; |
---|
3034 | |
---|
3035 | int ynext = yoffset_for_mode_button(p_w->number_of_modes); |
---|
3036 | if (ynext> _at->max_y_size) _at->max_y_size = ynext; |
---|
3037 | |
---|
3038 | return p_w->number_of_modes; |
---|
3039 | } |
---|
3040 | |
---|
3041 | AW_area_management::AW_area_management(Widget formi, Widget widget) { |
---|
3042 | memset((char *)this, 0, sizeof(AW_area_management)); |
---|
3043 | form = formi; |
---|
3044 | area = widget; |
---|
3045 | } |
---|
3046 | |
---|
3047 | AW_device_Xm *AW_area_management::get_screen_device() { |
---|
3048 | if (!device) device = new AW_device_Xm(common); |
---|
3049 | return device; |
---|
3050 | } |
---|
3051 | |
---|
3052 | AW_device_size *AW_area_management::get_size_device() { |
---|
3053 | if (!size_device) size_device = new AW_device_size(common); |
---|
3054 | return size_device; |
---|
3055 | } |
---|
3056 | |
---|
3057 | AW_device_print *AW_area_management::get_print_device() { |
---|
3058 | if (!print_device) print_device = new AW_device_print(common); |
---|
3059 | return print_device; |
---|
3060 | } |
---|
3061 | |
---|
3062 | AW_device_click *AW_area_management::get_click_device() { |
---|
3063 | if (!click_device) click_device = new AW_device_click(common); |
---|
3064 | return click_device; |
---|
3065 | } |
---|
3066 | |
---|
3067 | void AW_window::wm_activate() { |
---|
3068 | { |
---|
3069 | Boolean iconic = False; |
---|
3070 | XtVaGetValues(p_w->shell, XmNiconic, &iconic, NULL); |
---|
3071 | |
---|
3072 | if (iconic == True) { |
---|
3073 | XtVaSetValues(p_w->shell, XmNiconic, False, NULL); |
---|
3074 | |
---|
3075 | XtMapWidget(p_w->shell); |
---|
3076 | XRaiseWindow(XtDisplay(p_w->shell), XtWindow(p_w->shell)); |
---|
3077 | } |
---|
3078 | } |
---|
3079 | |
---|
3080 | { |
---|
3081 | Display *xdpy = XtDisplay(p_w->shell); |
---|
3082 | Window window = XtWindow(p_w->shell); |
---|
3083 | Atom netactivewindow = XInternAtom(xdpy, "_NET_ACTIVE_WINDOW", False); |
---|
3084 | |
---|
3085 | if (netactivewindow) { |
---|
3086 | |
---|
3087 | XClientMessageEvent ce; |
---|
3088 | ce.type = ClientMessage; |
---|
3089 | ce.display = xdpy; |
---|
3090 | ce.window = window; |
---|
3091 | ce.message_type = netactivewindow; |
---|
3092 | ce.format = 32; |
---|
3093 | ce.data.l[0] = 2; |
---|
3094 | ce.data.l[1] = None; |
---|
3095 | ce.data.l[2] = Above; |
---|
3096 | ce.data.l[3] = 0; |
---|
3097 | ce.data.l[4] = 0; |
---|
3098 | |
---|
3099 | #if defined(DEBUG) |
---|
3100 | Status ret = |
---|
3101 | #endif // DEBUG |
---|
3102 | XSendEvent(xdpy, XDefaultRootWindow(xdpy), |
---|
3103 | False, |
---|
3104 | SubstructureRedirectMask | SubstructureNotifyMask, |
---|
3105 | (XEvent *) &ce); |
---|
3106 | |
---|
3107 | #if defined(DEBUG) |
---|
3108 | if (!ret) { fprintf(stderr, "Failed to send _NET_ACTIVE_WINDOW to WM (XSendEvent returns %i)\n", ret); } |
---|
3109 | #endif // DEBUG |
---|
3110 | XSync(xdpy, False); |
---|
3111 | } |
---|
3112 | #if defined(DEBUG) |
---|
3113 | else { |
---|
3114 | fputs("No such atom '_NET_ACTIVE_WINDOW'\n", stderr); |
---|
3115 | } |
---|
3116 | #endif // DEBUG |
---|
3117 | } |
---|
3118 | } |
---|
3119 | |
---|
3120 | void AW_window::_set_activate_callback(void *widget) { |
---|
3121 | if (_callback && (long)_callback != 1) { |
---|
3122 | if (!_callback->help_text && _at->helptext_for_next_button) { |
---|
3123 | _callback->help_text = _at->helptext_for_next_button; |
---|
3124 | _at->helptext_for_next_button = 0; |
---|
3125 | } |
---|
3126 | |
---|
3127 | XtAddCallback((Widget) widget, XmNactivateCallback, |
---|
3128 | (XtCallbackProc) AW_server_callback, (XtPointer) _callback); |
---|
3129 | } |
---|
3130 | _callback = NULL; |
---|
3131 | } |
---|
3132 | |
---|
3133 | |
---|
3134 | void AW_window::set_background(const char *colorname, Widget parentWidget) { |
---|
3135 | bool colorSet = false; |
---|
3136 | |
---|
3137 | if (colorname) { |
---|
3138 | XColor unused, color; |
---|
3139 | |
---|
3140 | if (XAllocNamedColor(p_global->display, p_global->colormap, colorname, &color, &unused) |
---|
3141 | == 0) { |
---|
3142 | fprintf(stderr, "XAllocColor failed: %s\n", colorname); |
---|
3143 | } |
---|
3144 | else { |
---|
3145 | _at->background_color = color.pixel; |
---|
3146 | colorSet = true; |
---|
3147 | } |
---|
3148 | } |
---|
3149 | |
---|
3150 | if (!colorSet) { |
---|
3151 | XtVaGetValues(parentWidget, XmNbackground, &(_at->background_color), |
---|
3152 | NULL); // fallback to background color |
---|
3153 | } |
---|
3154 | } |
---|
3155 | |
---|
3156 | void AW_window::TuneOrSetBackground(Widget w, const char *color, int modStrength) { |
---|
3157 | // Sets the background for the next created widget. |
---|
3158 | // |
---|
3159 | // If 'color' is specified, it may contain one of the following values: |
---|
3160 | // "+" means: slightly increase color of parent widget 'w' |
---|
3161 | // "-" means: slightly decrease color of parent widget 'w' |
---|
3162 | // otherwise it contains a specific color ('name' or '#RGB') |
---|
3163 | // |
---|
3164 | // If color is not specified, the color of the parent widget 'w' is modified |
---|
3165 | // by 'modStrength' (increased if positive, decreased if negative) |
---|
3166 | // |
---|
3167 | // If it's not possible to modify the color (e.g. we cannot increase 'white'), |
---|
3168 | // the color will be modified in the opposite direction. For details see TuneBackground() |
---|
3169 | |
---|
3170 | if (color) { |
---|
3171 | switch (color[0]) { |
---|
3172 | case '+': |
---|
3173 | TuneBackground(w, TUNE_BRIGHT); |
---|
3174 | break; |
---|
3175 | case '-': |
---|
3176 | TuneBackground(w, TUNE_DARK); |
---|
3177 | break; |
---|
3178 | default: |
---|
3179 | set_background(color, w); // use explicit color |
---|
3180 | } |
---|
3181 | } |
---|
3182 | else { |
---|
3183 | TuneBackground(w, modStrength); |
---|
3184 | } |
---|
3185 | } |
---|
3186 | |
---|
3187 | void AW_window::TuneBackground(Widget w, int modStrength) { |
---|
3188 | // Gets the Background Color, modifies the rgb values slightly and sets new background color |
---|
3189 | // Intended to give buttons a nicer 3D-look. |
---|
3190 | // |
---|
3191 | // possible values for modStrength: |
---|
3192 | // |
---|
3193 | // 0 = do not modify (i.e. set to background color of parent widget) |
---|
3194 | // 1 .. 127 = increase if background is bright, decrease if background is dark |
---|
3195 | // -1 ..-127 = opposite behavior than above |
---|
3196 | // 256 .. 383 = always increase |
---|
3197 | // -256 ..-383 = always decrease |
---|
3198 | // |
---|
3199 | // if it's impossible to decrease or increase -> opposite direction is used. |
---|
3200 | |
---|
3201 | int col[3]; |
---|
3202 | { |
---|
3203 | Pixel bg; |
---|
3204 | XtVaGetValues(w, XmNbackground, &bg, NULL); |
---|
3205 | |
---|
3206 | XColor xc; |
---|
3207 | xc.pixel = bg; |
---|
3208 | XQueryColor(XtDisplay(w), p_global->colormap, &xc); |
---|
3209 | |
---|
3210 | col[0] = xc.red >> 8; // take MSB |
---|
3211 | col[1] = xc.green >> 8; |
---|
3212 | col[2] = xc.blue >> 8; |
---|
3213 | } |
---|
3214 | |
---|
3215 | int mod = modStrength; |
---|
3216 | int preferredDir = 0; |
---|
3217 | bool invertedMod = false; |
---|
3218 | |
---|
3219 | if (modStrength>0) { |
---|
3220 | if (modStrength>255) { |
---|
3221 | mod -= 256; |
---|
3222 | preferredDir = 1; // increase preferred |
---|
3223 | } |
---|
3224 | } |
---|
3225 | else { |
---|
3226 | if (modStrength<-255) { |
---|
3227 | mod = -modStrength-256; |
---|
3228 | preferredDir = -1; // decrease preferred |
---|
3229 | } |
---|
3230 | else { |
---|
3231 | invertedMod = true; |
---|
3232 | mod = -mod; |
---|
3233 | } |
---|
3234 | } |
---|
3235 | |
---|
3236 | aw_assert(mod >= 0 && mod < 128); |
---|
3237 | // illegal modification |
---|
3238 | |
---|
3239 | bool incPossible[3]; // increment possible for color |
---|
3240 | bool decPossible[3]; // decrement possible for color |
---|
3241 | int incs = 0; // count possible increments |
---|
3242 | int decs = 0; // count possible decrements |
---|
3243 | |
---|
3244 | for (int i = 0; i<3; ++i) { |
---|
3245 | if ((incPossible[i] = ((col[i]+mod) <= 255))) |
---|
3246 | incs++; |
---|
3247 | if ((decPossible[i] = ((col[i]-mod) >= 0))) |
---|
3248 | decs++; |
---|
3249 | } |
---|
3250 | |
---|
3251 | aw_assert(incs||decs); |
---|
3252 | |
---|
3253 | switch (preferredDir) { |
---|
3254 | case 0: // no direction preferred yet, need to decide |
---|
3255 | if (invertedMod) |
---|
3256 | preferredDir = decs ? -1 : 1; |
---|
3257 | else |
---|
3258 | preferredDir = incs ? 1 : -1; |
---|
3259 | break; |
---|
3260 | case 1: |
---|
3261 | if (!incs) |
---|
3262 | preferredDir = -1; |
---|
3263 | break; |
---|
3264 | case -1: |
---|
3265 | if (!decs) |
---|
3266 | preferredDir = 1; |
---|
3267 | break; |
---|
3268 | } |
---|
3269 | |
---|
3270 | aw_assert(preferredDir == 1 || preferredDir == -1); // no direction chosen above |
---|
3271 | |
---|
3272 | if (preferredDir == 1) { |
---|
3273 | for (int i=0; i<3; ++i) col[i] += (incPossible[i] ? mod : 0); |
---|
3274 | } |
---|
3275 | else if (preferredDir == -1) { |
---|
3276 | for (int i=0; i<3; ++i) col[i] -= (decPossible[i] ? mod : 0); |
---|
3277 | } |
---|
3278 | |
---|
3279 | |
---|
3280 | char hex_color[50]; |
---|
3281 | sprintf(hex_color, "#%2.2X%2.2X%2.2X", col[0], col[1], col[2]); |
---|
3282 | aw_assert(strlen(hex_color) == 7); |
---|
3283 | // otherwise some value overflowed |
---|
3284 | set_background(hex_color, w); |
---|
3285 | } |
---|
3286 | |
---|
3287 | void AW_root::make_sensitive(Widget w, AW_active mask) { |
---|
3288 | // Don't call make_sensitive directly! |
---|
3289 | // |
---|
3290 | // Simply set sens_mask(AWM_EXP) and after creating the expert-mode-only widgets, |
---|
3291 | // set it back using sens_mask(AWM_ALL) |
---|
3292 | |
---|
3293 | aw_assert(w); |
---|
3294 | aw_assert(legal_mask(mask)); |
---|
3295 | |
---|
3296 | prvt->set_last_widget(w); |
---|
3297 | |
---|
3298 | if (mask != AWM_ALL) { // no need to make widget sensitive, if its shown unconditionally |
---|
3299 | button_sens_list = new AW_buttons_struct(mask, w, button_sens_list); |
---|
3300 | if (!(mask & global_mask)) XtSetSensitive(w, False); // disable widget if mask doesn't match |
---|
3301 | } |
---|
3302 | } |
---|
3303 | |
---|
3304 | AW_buttons_struct::AW_buttons_struct(AW_active maski, Widget w, AW_buttons_struct *prev_button) { |
---|
3305 | aw_assert(w); |
---|
3306 | aw_assert(legal_mask(maski)); |
---|
3307 | |
---|
3308 | mask = maski; |
---|
3309 | button = w; |
---|
3310 | next = prev_button; |
---|
3311 | } |
---|
3312 | |
---|
3313 | AW_buttons_struct::~AW_buttons_struct() { |
---|
3314 | delete next; |
---|
3315 | } |
---|
3316 | |
---|
3317 | bool AW_root::remove_button_from_sens_list(Widget button) { |
---|
3318 | bool removed = false; |
---|
3319 | if (button_sens_list) { |
---|
3320 | AW_buttons_struct *prev = 0; |
---|
3321 | AW_buttons_struct *bl = button_sens_list; |
---|
3322 | |
---|
3323 | while (bl) { |
---|
3324 | if (bl->button == button) break; // found wanted widget |
---|
3325 | prev = bl; |
---|
3326 | bl = bl->next; |
---|
3327 | } |
---|
3328 | |
---|
3329 | if (bl) { |
---|
3330 | // remove from list |
---|
3331 | if (prev) prev->next = bl->next; |
---|
3332 | else button_sens_list = bl->next; |
---|
3333 | |
---|
3334 | bl->next = 0; |
---|
3335 | removed = true; |
---|
3336 | |
---|
3337 | delete bl; |
---|
3338 | } |
---|
3339 | } |
---|
3340 | return removed; |
---|
3341 | } |
---|
3342 | |
---|
3343 | AW_option_menu_struct::AW_option_menu_struct(int numberi, const char *variable_namei, |
---|
3344 | AW_VARIABLE_TYPE variable_typei, Widget label_widgeti, |
---|
3345 | Widget menu_widgeti, AW_pos xi, AW_pos yi, int correct) { |
---|
3346 | option_menu_number = numberi; |
---|
3347 | variable_name = strdup(variable_namei); |
---|
3348 | variable_type = variable_typei; |
---|
3349 | label_widget = label_widgeti; |
---|
3350 | menu_widget = menu_widgeti; |
---|
3351 | first_choice = NULL; |
---|
3352 | last_choice = NULL; |
---|
3353 | default_choice = NULL; |
---|
3354 | next = NULL; |
---|
3355 | x = xi; |
---|
3356 | y = yi; |
---|
3357 | |
---|
3358 | correct_for_at_center_intern = correct; |
---|
3359 | } |
---|
3360 | |
---|
3361 | AW_toggle_field_struct::AW_toggle_field_struct(int toggle_field_numberi, |
---|
3362 | const char *variable_namei, AW_VARIABLE_TYPE variable_typei, |
---|
3363 | Widget label_widgeti, int correct) { |
---|
3364 | |
---|
3365 | toggle_field_number = toggle_field_numberi; |
---|
3366 | variable_name = strdup(variable_namei); |
---|
3367 | variable_type = variable_typei; |
---|
3368 | label_widget = label_widgeti; |
---|
3369 | first_toggle = NULL; |
---|
3370 | last_toggle = NULL; |
---|
3371 | default_toggle = NULL; |
---|
3372 | next = NULL; |
---|
3373 | correct_for_at_center_intern = correct; |
---|
3374 | } |
---|
3375 | |
---|
3376 | AW_window_Motif::AW_window_Motif() |
---|
3377 | : shell(0), |
---|
3378 | scroll_bar_vertical(0), |
---|
3379 | scroll_bar_horizontal(0), |
---|
3380 | menu_deep(0), |
---|
3381 | help_pull_down(0), |
---|
3382 | mode_area(0), |
---|
3383 | number_of_modes(0), |
---|
3384 | modes_f_callbacks(NULL), |
---|
3385 | modes_widgets(NULL), |
---|
3386 | selected_mode(0), |
---|
3387 | popup_cb(NULL), |
---|
3388 | frame(0), |
---|
3389 | toggle_field(0), |
---|
3390 | toggle_label(0), |
---|
3391 | toggle_field_var_name(NULL), |
---|
3392 | toggle_field_var_type(AW_NONE), |
---|
3393 | keymodifier(AW_KEYMODE_NONE), |
---|
3394 | WM_top_offset(0), |
---|
3395 | WM_left_offset(0) |
---|
3396 | { |
---|
3397 | for (int i = 0; i<AW_MAX_MENU_DEEP; ++i) { |
---|
3398 | menu_bar[i] = 0; |
---|
3399 | } |
---|
3400 | for (int i = 0; i<AW_MAX_AREA; ++i) { |
---|
3401 | areas[i] = NULL; |
---|
3402 | } |
---|
3403 | } |
---|
3404 | |
---|
3405 | int AW_window_Motif::WM_max_top_offset = 0; |
---|
3406 | int AW_window_Motif::WM_max_left_offset = 0; |
---|