2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // Copyright (c) 1994,1995,1996 FUJITSU LIMITED
24 // All Rights Reserved
27 * $XConsortium: PrefAgentMotif.C /main/14 1996/11/23 14:13:16 cde-hal $
29 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
30 * All rights reserved. Unpublished -- rights reserved under
31 * the Copyright Laws of the United States. USE OF A COPYRIGHT
32 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
35 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
36 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
37 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
38 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
41 * RESTRICTED RIGHTS LEGEND
42 * Use, duplication, or disclosure by the Government is subject
43 * to the restrictions as set forth in subparagraph (c)(l)(ii)
44 * of the Rights in Technical Data and Computer Software clause
45 * at DFARS 252.227-7013.
47 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
56 #define C_WindowSystem
61 #define C_StyleSheetMgr
62 #define C_NodeWindowMgr
63 #define C_GlobalHistoryMgr
72 #include "Other/XmStringLocalized.hh"
73 #include "Managers/CatMgr.hh"
77 #include "Registration.hh"
79 #include <WWL/WXmForm.h>
80 #include <WWL/WXmMenu.h>
81 #include <WWL/WXmLabel.h>
82 #include <WWL/WXmFrame.h>
83 #include <WWL/WXmSeparator.h>
84 #include <WWL/WXmArrowButton.h>
85 #include <WWL/WXmDialogShell.h>
86 #include <WWL/WXmMessageBox.h>
88 #include <X11/cursorfont.h>
92 #include <libintl.h> // 1/21/94 yuji
96 /* Update time in milliseconds when arrow button held down. */
97 #define CHANGE_SPEED 300
99 #define CLASS PrefAgent
100 #include "create_macros.hh"
102 // All the stuff below is semi-bogus. There really needs to be classes
103 // for displaying values of certain types, and there needs to be preference
104 // classes which take care of the modified/unmodified BS.
105 // 14:03 11-Apr-93 DJB
107 // Modes of operation:
108 // 1) Set field from preference (initialize only!).
109 // 2) Reset field from preference.
110 // 3) Set preference from field (when field is modified).
111 // 4) Update other UI parts when preference changes.
116 ChangeData (WXmTextField &f, Widget up, Widget dn, int c, int l)
117 : field (f), up_arrow(up), dn_arrow(dn), change(c), limit(l)
120 WXmTextField field; // Field to change
123 int change; // Amount of change
124 int limit; // Limit of change
133 { changed = TRUE; num_changed++; }
135 { changed = FALSE; num_changed--; }
137 static int num_changed;
140 int Value::num_changed = 0;
142 class IntegerValue : public Value {
144 IntegerValue (int value)
145 : original (value), current (value) { }
146 void set_value (int value)
148 if (value == original) // ie: reset
150 else if (!changed) // ie: first change
154 void apply (PrefSymbol sym)
157 unmodified(); original = current;
158 pref_mgr().set_int (sym, current);
166 class BooleanValue : public Value {
168 BooleanValue (bool value)
169 : original (value), current (value) { }
170 void set_value (int value)
172 if (value == original) // ie: reset
174 else if (!changed) // ie: first change
178 void apply (PrefSymbol sym)
181 unmodified(); original = current;
182 pref_mgr().set_boolean (sym, current);
190 // NOTE: String currently unused, will probably have to strdup() values.
191 class StringValue : public Value {
193 StringValue (String value)
194 : original (value), current (value) { }
195 void set_value (String value)
197 if (value == original) // ie: reset
199 else if (!changed) // ie: first change
203 void apply (PrefSymbol sym)
206 unmodified(); original = current;
207 pref_mgr().set_string (sym, current);
215 class WindowGeometryValue : public Value {
217 WindowGeometryValue (const WindowGeometry &value)
218 : original (value), current (value) { }
219 void set_value (WindowGeometry &value)
221 if (value == original) // ie: reset
223 else if (!changed) // ie: first change
227 void apply (PrefSymbol sym)
230 unmodified(); original = current;
231 pref_mgr().set_geometry (sym, current);
235 WindowGeometry original;
236 WindowGeometry current;
239 #define IS_CHANGED(X) (((Value *) (X).UserData())->changed)
240 #define SET_CHANGED(X,V) ((Value *) (X).UserData())->changed = V
242 #if defined(__STDC__) || defined(hpux) || defined(__osf__)
243 #define ATTACH_VALUE(X,T,V) (X).UserData ((void *) new T##Value(V))
244 #define SET_VALUE(X,T,V) ((T##Value *) (X).UserData())->set_value(V)
245 #define ORIGINAL_VALUE(X,T) ((T##Value *) (X).UserData())->original
246 #define CURRENT_VALUE(X,T) ((T##Value *) (X).UserData())->current
247 #define APPLY_VALUE(X,T,S) ((T##Value *) (X).UserData())->apply(S)
249 #define ATTACH_VALUE(X,T,V) (X).UserData ((void *) new T/**/Value(V))
250 #define SET_VALUE(X,T,V) ((T/**/Value *) (X).UserData())->set_value(V)
251 #define ORIGINAL_VALUE(X,T) ((T/**/Value *) (X).UserData())->original
252 #define CURRENT_VALUE(X,T) ((T/**/Value *) (X).UserData())->current
253 #define APPLY_VALUE(X,T,S) ((T/**/Value *) (X).UserData())->apply(S)
256 // /////////////////////////////////////////////////////////////////
258 // /////////////////////////////////////////////////////////////////
261 PrefAgent::PrefAgent()
267 // /////////////////////////////////////////////////////////////////
269 // /////////////////////////////////////////////////////////////////
271 PrefAgent::~PrefAgent()
279 // /////////////////////////////////////////////////////////////////
281 // /////////////////////////////////////////////////////////////////
290 // Always reset on new popup.
298 // /////////////////////////////////////////////////////////////////
300 // /////////////////////////////////////////////////////////////////
303 PrefAgent::create_ui()
305 // Create main preferences window.
307 XmStringLocalized mtfstring;
309 int decorations=MWM_DECOR_BORDER |
314 f_shell = WTopLevelShell (window_system().toplevel(), WPopup, "preferences");
315 window_system().register_shell(&f_shell);
317 string = CATGETS(Set_PrefAgent, 1, "Dtinfo: Preferences");
318 XtVaSetValues((Widget)f_shell,
320 XmNmwmDecorations, decorations,
323 DECL (WXmForm, form, f_shell, "form");
324 DECLM (WXmOptionMenu, options, form, "options");
325 DECL (WXmPulldownMenu, options_menu, form, "options_menu");
327 mtfstring = CATGETS(Set_AgentLabel, 186, "Preferences for");
328 XtVaSetValues(options, XmNlabelString, (XmString)mtfstring, NULL);
330 ASSNM (WXmPushButton, f_ok, form, "ok");
331 ASSNM (WXmPushButton, f_apply, form, "apply");
332 ASSNM (WXmPushButton, f_reset, form, "reset");
333 DECLM (WXmPushButton, cancel, form, "cancel");
334 DECLM (WXmPushButton, help, form, "help");
336 mtfstring = CATGETS(Set_AgentLabel, 161, "OK");
337 XtVaSetValues(f_ok, XmNlabelString, (XmString)mtfstring, NULL);
338 mtfstring = CATGETS(Set_AgentLabel, 201, "Apply");
339 XtVaSetValues(f_apply, XmNlabelString, (XmString)mtfstring, NULL);
340 mtfstring = CATGETS(Set_AgentLabel, 202, "Reset");
341 XtVaSetValues(f_reset, XmNlabelString, (XmString)mtfstring, NULL);
342 mtfstring = CATGETS(Set_AgentLabel, 162, "Cancel");
343 XtVaSetValues(cancel, XmNlabelString, (XmString)mtfstring, NULL);
344 mtfstring = CATGETS(Set_AgentLabel, 48, "Help");
345 XtVaSetValues(help, XmNlabelString, (XmString)mtfstring, NULL);
347 SET_CALLBACK (f_ok,Activate,ok);
348 SET_CALLBACK (f_apply,Activate,apply);
349 SET_CALLBACK (f_reset,Activate,reset);
350 SET_CALLBACK (cancel,Activate,cancel);
351 help_agent().add_activate_help (help, "preferences_help");
353 DECLM (WXmFrame, frame, form, "frame");
354 DECL (WXmForm, container, frame, "container");
356 // Create browsing preferences.
357 DECLM (WXmPushButton, browse, options_menu, "browse");
359 DECL (WXmForm, browse_form, container, "browse_prefs");
360 DECLM (WXmLabel, browse_label, browse_form, "browse_label");
361 DECLM (WXmPushButton, get_browse_geo, browse_form, "get_browse_geo");
362 ASSNM (WXmTextField, f_browse_geo, browse_form, "browse_geo");
363 DECLM (WXmLabel, fs_label, browse_form, "fs_label");
364 DECL (WXmForm, fs_form, browse_form, "fs_form");
365 ASSNM (WXmTextField, f_fs_field, fs_form, "scale_field");
366 DECLM (WXmArrowButton, scale_up, fs_form, "scale_up");
367 DECLM (WXmArrowButton, scale_down, fs_form, "scale_down");
368 DECLM (WXmLabel, lock_label, browse_form, "lock_label");
369 ASSNM (WXmToggleButton, f_lock_toggle, browse_form, "lock_toggle");
371 mtfstring = CATGETS(Set_AgentLabel, 187, "Browsing");
372 XtVaSetValues(browse, XmNlabelString, (XmString)mtfstring, NULL);
373 mtfstring = CATGETS(Set_AgentLabel, 190, "Browser Geometry");
374 XtVaSetValues(browse_label, XmNlabelString, (XmString)mtfstring, NULL);
375 mtfstring = CATGETS(Set_AgentLabel, 270, "...");
376 XtVaSetValues(get_browse_geo, XmNlabelString, (XmString)mtfstring, NULL);
377 mtfstring = CATGETS(Set_AgentLabel, 192, "Font Scale");
378 XtVaSetValues(fs_label, XmNlabelString, (XmString)mtfstring, NULL);
379 mtfstring = CATGETS(Set_AgentLabel, 193, "Pin Window");
380 XtVaSetValues(lock_label, XmNlabelString, (XmString)mtfstring, NULL);
381 mtfstring = CATGETS(Set_AgentLabel, 194, "File a Bug");
382 XtVaSetValues(f_lock_toggle, XmNlabelString, (XmString)mtfstring, NULL);
385 ChangeData *inc, *dec;
387 // Assume that the fields are taller than the labels. If the user
388 // changes the font resources and violates this assumtion he's screwed
389 // and that's the way we like it.
391 height = f_fs_field.Height();
393 browse_label.Height (height);
394 fs_label.Height (height);
395 scale_up.Height (height/2);
396 scale_down.Height (height/2);
398 f_lock_toggle.LabelType (XmPIXMAP);
399 lock_label.Height (height);
402 browse_form.Manage();
403 f_top_panel = browse_form;
405 SET_CALLBACK_D (browse,Activate,switch_to_window,(Widget)browse_form);
406 SET_CALLBACK_D (get_browse_geo,Activate,get_geometry,(Widget)f_browse_geo);
407 SET_CALLBACK (f_browse_geo,ValueChanged,something_changed);
408 SET_CALLBACK (f_fs_field,ValueChanged,something_changed);
409 SET_CALLBACK (f_lock_toggle,ValueChanged,something_changed);
410 SET_CALLBACK (f_lock_toggle,ValueChanged,lock_toggle);
412 inc = new ChangeData(f_fs_field, scale_up, scale_down, 1, 5);
413 dec = new ChangeData(f_fs_field, scale_up, scale_down, -1, -2);
414 SET_CALLBACK_D (scale_up,Activate,change_cb,inc);
415 SET_CALLBACK_D (scale_up,Arm,arm_arrow,inc);
416 SET_CALLBACK (scale_up,Disarm,disarm_arrow);
417 SET_CALLBACK_D (scale_down,Activate,change_cb,dec);
418 SET_CALLBACK_D (scale_down,Arm,arm_arrow,dec);
419 SET_CALLBACK (scale_down,Disarm,disarm_arrow);
421 // Create map window preferences
422 DECLM (WXmPushButton, map, options_menu, "map");
423 DECLM (WXmForm, map_form, container, "map_prefs");
424 DECLM (WXmLabel, map_label, map_form, "map_label");
425 DECLM (WXmPushButton, get_map_geo, map_form, "get_map_geo");
426 ASSNM (WXmTextField, f_map_geo, map_form, "map_geo");
427 DECLM (WXmLabel, update_label, map_form, "update_label");
428 ASSNM (WXmToggleButton, f_update_toggle, map_form, "update_toggle");
430 mtfstring = CATGETS(Set_AgentLabel, 188, "Map");
431 XtVaSetValues(map, XmNlabelString, (XmString)mtfstring, NULL);
432 mtfstring = CATGETS(Set_AgentLabel, 195, "Map Geometry");
433 XtVaSetValues(map_label, XmNlabelString, (XmString)mtfstring, NULL);
434 mtfstring = CATGETS(Set_AgentLabel, 270, "...");
435 XtVaSetValues(get_map_geo, XmNlabelString, (XmString)mtfstring, NULL);
436 mtfstring = CATGETS(Set_AgentLabel, 196, "Auto Update");
437 XtVaSetValues(update_label, XmNlabelString, (XmString)mtfstring, NULL);
438 mtfstring = CATGETS(Set_AgentLabel, 194, "File a Bug");
439 XtVaSetValues(f_update_toggle, XmNlabelString, (XmString)mtfstring, NULL);
441 height = f_map_geo.Height();
442 map_label.Height (height);
443 update_label.Height (height);
445 SET_CALLBACK_D (get_map_geo,Activate,get_geometry,(Widget)f_map_geo);
446 SET_CALLBACK_D (map,Activate,switch_to_window,(Widget)map_form);
447 SET_CALLBACK (f_map_geo,ValueChanged,something_changed);
448 SET_CALLBACK (f_update_toggle,ValueChanged,something_changed);
449 SET_CALLBACK (f_update_toggle,ValueChanged,update_toggle);
453 // Create history preferences
454 DECLM (WXmPushButton, history, options_menu, "history");
456 mtfstring = CATGETS(Set_AgentLabel, 260, "History");
457 XtVaSetValues(history, XmNlabelString, (XmString)mtfstring, NULL);
459 DECL (WXmForm, hist_form, container, "history_prefs");
460 DECLM (WXmLabel, nh_label, hist_form, "nh_label");
461 DECL (WXmForm, nh_form, hist_form, "nh_form");
462 ASSNM (WXmTextField, f_nh_field, nh_form, "nh_field");
463 DECLM (WXmArrowButton, nh_up, nh_form, "nh_up");
464 DECLM (WXmArrowButton, nh_down, nh_form, "nh_down");
465 DECLM (WXmLabel, sh_label, hist_form, "sh_label");
466 DECL (WXmForm, sh_form, hist_form, "sh_form");
467 ASSNM (WXmTextField, f_sh_field, sh_form, "sh_field");
468 DECLM (WXmArrowButton, sh_up, sh_form, "sh_up");
469 DECLM (WXmArrowButton, sh_down, sh_form, "sh_down");
471 mtfstring = CATGETS(Set_AgentLabel, 197, "Section History Size");
472 XtVaSetValues(nh_label, XmNlabelString, (XmString)mtfstring, NULL);
473 mtfstring = CATGETS(Set_AgentLabel, 198, "Search History Size");
474 XtVaSetValues(sh_label, XmNlabelString, (XmString)mtfstring, NULL);
476 height = f_nh_field.Height();
477 nh_label.Height (height);
478 nh_up.Height (height/2);
479 nh_down.Height (height/2);
481 height = f_sh_field.Height();
482 sh_label.Height (height);
483 sh_up.Height (height/2);
484 sh_down.Height (height/2);
490 SET_CALLBACK_D (history,Activate,switch_to_window,(Widget)hist_form);
491 SET_CALLBACK (f_nh_field,ValueChanged,something_changed);
492 SET_CALLBACK (f_sh_field,ValueChanged,something_changed);
494 inc = new ChangeData (f_nh_field, nh_up, nh_down, 10, 1000);
495 dec = new ChangeData (f_nh_field, nh_up, nh_down, -10, 10);
496 SET_CALLBACK_D (nh_up,Activate,change_cb,inc);
497 SET_CALLBACK_D (nh_up,Arm,arm_arrow,inc);
498 SET_CALLBACK (nh_up,Disarm,disarm_arrow);
499 SET_CALLBACK_D (nh_down,Activate,change_cb,dec);
500 SET_CALLBACK_D (nh_down,Arm,arm_arrow,dec);
501 SET_CALLBACK (nh_down,Disarm,disarm_arrow);
503 inc = new ChangeData (f_sh_field, sh_up, sh_down, 10, 1000);
504 dec = new ChangeData (f_sh_field, sh_up, sh_down, -10, 10);
505 SET_CALLBACK_D (sh_up,Activate,change_cb,inc);
506 SET_CALLBACK_D (sh_up,Arm,arm_arrow,inc);
507 SET_CALLBACK (sh_up,Disarm,disarm_arrow);
508 SET_CALLBACK_D (sh_down,Activate,change_cb,dec);
509 SET_CALLBACK_D (sh_down,Arm,arm_arrow,dec);
510 SET_CALLBACK (sh_down,Disarm,disarm_arrow);
512 // Create Search preferences.
514 DECLM (WXmPushButton, search, options_menu, "search");
516 mtfstring = CATGETS(Set_AgentLabel, 189, "Searching");
517 XtVaSetValues(search, XmNlabelString, (XmString)mtfstring, NULL);
519 DECL (WXmForm, search_form, container, "search_prefs");
520 DECLM (WXmLabel, max_hits_label, search_form, "max_hits");
521 DECL (WXmForm, hits_form, search_form, "hits_form");
522 ASSNM (WXmTextField, f_max_hits_field, hits_form, "hits_field");
523 DECLM (WXmArrowButton, hits_up, hits_form, "hits_up");
524 DECLM (WXmArrowButton, hits_down, hits_form, "hits_down");
525 DECLM (WXmLabel, adisplay_label, search_form, "adisplay_label");
526 ASSNM (WXmToggleButton, f_adisplay_toggle, search_form, "adisplay_toggle");
528 mtfstring = CATGETS(Set_AgentLabel, 199, "Maximum Search Hits");
529 XtVaSetValues(max_hits_label, XmNlabelString, (XmString)mtfstring, NULL);
530 mtfstring = CATGETS(Set_AgentLabel, 200, "Auto Display First Hit");
531 XtVaSetValues(adisplay_label, XmNlabelString, (XmString)mtfstring, NULL);
532 mtfstring = CATGETS(Set_AgentLabel, 194, "File a Bug");
533 XtVaSetValues(f_adisplay_toggle, XmNlabelString, (XmString)mtfstring, NULL);
535 height = f_max_hits_field.Height();
536 max_hits_label.Height (height);
537 hits_up.Height (height/2);
538 hits_down.Height (height/2);
539 adisplay_label.Height (height);
542 search_form.Manage();
544 SET_CALLBACK_D (search,Activate,switch_to_window,(Widget)search_form);
545 SET_CALLBACK (f_max_hits_field,ValueChanged,something_changed);
547 inc = new ChangeData (f_max_hits_field, hits_up, hits_down, 10, 500);
548 dec = new ChangeData (f_max_hits_field, hits_up, hits_down, -10, 10);
549 SET_CALLBACK_D (hits_up,Activate,change_cb,inc);
550 SET_CALLBACK_D (hits_up,Arm,arm_arrow,inc);
551 SET_CALLBACK (hits_up,Disarm,disarm_arrow);
552 SET_CALLBACK_D (hits_down,Activate,change_cb,dec);
553 SET_CALLBACK_D (hits_down,Arm,arm_arrow,dec);
554 SET_CALLBACK (hits_down,Disarm,disarm_arrow);
555 SET_CALLBACK (f_adisplay_toggle,ValueChanged,something_changed);
556 SET_CALLBACK (f_adisplay_toggle,ValueChanged,adisplay_toggle);
558 /* -------- node history size, search history size -------- */
560 options.SubMenuId (options_menu);
563 form.DefaultButton (f_ok);
564 form.ShadowThickness (0);
569 f_shell.Get (WArgList (XmNheight, (XtArgVal) &height,
572 f_shell.Set (WArgList (XmNminHeight, height,
573 XmNmaxHeight, height,
579 hist_form.Unmanage();
580 search_form.Unmanage();
582 // Values get displayed when reset() is called on dialog display.
587 // /////////////////////////////////////////////////////////////////
589 // /////////////////////////////////////////////////////////////////
600 // All the functionaly in the `if' statements below in appy and reset
601 // really should be part of the class. No time right now, though.
604 // /////////////////////////////////////////////////////////////////
606 // /////////////////////////////////////////////////////////////////
611 // Save browse preferences.
612 bool update_fs = False;
613 if (IS_CHANGED (f_fs_field))
615 APPLY_VALUE (f_browse_geo, WindowGeometry, PrefMgr::BrowseGeometry);
616 APPLY_VALUE (f_fs_field, Integer, PrefMgr::FontScale);
617 APPLY_VALUE (f_lock_toggle, Boolean, PrefMgr::BrowseLock);
619 // Save map preferences.
620 APPLY_VALUE (f_map_geo, WindowGeometry, PrefMgr::MapGeometry);
621 APPLY_VALUE (f_update_toggle, Boolean, PrefMgr::MapAutoUpdate);
622 map_mgr().set_auto_update(f_update_toggle.Set());
624 // Save history preferences.
625 ON_DEBUG (printf ("Section hist changed = %d\n", IS_CHANGED (f_nh_field)));
626 if (IS_CHANGED (f_nh_field))
627 global_history_mgr().set_max_length (CURRENT_VALUE (f_nh_field, Integer));
628 APPLY_VALUE (f_nh_field, Integer, PrefMgr::NodeHistSize);
629 ON_DEBUG (printf ("Search hist changed = %d\n", IS_CHANGED (f_nh_field)));
630 if (IS_CHANGED (f_sh_field))
631 search_mgr().set_history_length (CURRENT_VALUE (f_sh_field, Integer));
632 APPLY_VALUE (f_sh_field, Integer, PrefMgr::SearchHistSize);
634 // Save search preferences.
635 APPLY_VALUE (f_max_hits_field, Integer, PrefMgr::MaxSearchHits);
636 APPLY_VALUE (f_adisplay_toggle, Boolean, PrefMgr::DisplayFirstHit);
638 // Desensitize appropriate controls.
639 f_ok.SetSensitive (False);
640 f_apply.SetSensitive (False);
641 f_reset.SetSensitive (False);
648 style_sheet_mgr().font_preference_modified();
653 // /////////////////////////////////////////////////////////////////
655 // /////////////////////////////////////////////////////////////////
660 // Reset browse preferences.
661 if (IS_CHANGED (f_browse_geo))
662 set_geometry (f_browse_geo, ORIGINAL_VALUE (f_browse_geo, WindowGeometry));
663 if (IS_CHANGED (f_fs_field))
664 set_integer (f_fs_field, ORIGINAL_VALUE (f_fs_field, Integer));
665 if (IS_CHANGED (f_lock_toggle)) {
666 set_lock (ORIGINAL_VALUE (f_lock_toggle, Boolean));
667 f_lock_toggle.Unmap();
671 // Reset map preferences.
672 if (IS_CHANGED (f_map_geo))
673 set_geometry (f_map_geo, ORIGINAL_VALUE (f_map_geo, WindowGeometry));
674 if (IS_CHANGED (f_update_toggle))
675 set_update (ORIGINAL_VALUE (f_update_toggle, Boolean));
677 // Reset history preferences.
678 if (IS_CHANGED (f_nh_field))
679 set_integer (f_nh_field, ORIGINAL_VALUE (f_nh_field, Integer));
680 if (IS_CHANGED (f_sh_field))
681 set_integer (f_sh_field, ORIGINAL_VALUE (f_sh_field, Integer));
683 // Reset Search preferences.
684 if (IS_CHANGED (f_max_hits_field))
685 set_integer (f_max_hits_field, ORIGINAL_VALUE (f_max_hits_field, Integer));
686 if (IS_CHANGED (f_adisplay_toggle))
687 set_auto_display (ORIGINAL_VALUE (f_adisplay_toggle, Boolean));
689 // Desensitize appropriate controls.
690 f_ok.SetSensitive (False);
691 f_apply.SetSensitive (False);
692 f_reset.SetSensitive (False);
695 // /////////////////////////////////////////////////////////////////
697 // /////////////////////////////////////////////////////////////////
706 // /////////////////////////////////////////////////////////////////
708 // /////////////////////////////////////////////////////////////////
711 PrefAgent::init_values()
713 PrefMgr &m = pref_mgr();
715 ATTACH_VALUE (f_browse_geo, WindowGeometry,
716 m.get_geometry (PrefMgr::BrowseGeometry));
717 ATTACH_VALUE (f_fs_field, Integer, m.get_int (PrefMgr::FontScale));
718 ATTACH_VALUE (f_lock_toggle, Boolean, m.get_boolean (PrefMgr::BrowseLock));
720 ATTACH_VALUE (f_map_geo, WindowGeometry,
721 m.get_geometry (PrefMgr::MapGeometry));
722 ATTACH_VALUE (f_update_toggle, Boolean,
723 m.get_boolean (PrefMgr::MapAutoUpdate));
725 ATTACH_VALUE (f_nh_field, Integer, m.get_int (PrefMgr::NodeHistSize));
726 ATTACH_VALUE (f_sh_field, Integer, m.get_int (PrefMgr::SearchHistSize));
728 ATTACH_VALUE (f_max_hits_field, Integer, m.get_int (PrefMgr::MaxSearchHits));
729 ATTACH_VALUE (f_adisplay_toggle, Boolean,
730 m.get_boolean (PrefMgr::DisplayFirstHit));
734 // /////////////////////////////////////////////////////////////////
736 // /////////////////////////////////////////////////////////////////
739 PrefAgent::something_changed()
741 f_ok.SetSensitive (True);
742 f_apply.SetSensitive (True);
743 f_reset.SetSensitive (True);
747 // /////////////////////////////////////////////////////////////////
749 // /////////////////////////////////////////////////////////////////
752 PrefAgent::switch_to_window (WCallback *wcb)
754 Widget w = (Widget) wcb->ClientData();
755 if (w == f_top_panel)
759 XRaiseWindow (XtDisplay (w), XtWindow (w));
760 XtUnmanageChild (f_top_panel);
765 // Keep track if timeout called. If so, don't change on active callback.
766 static int timeout_called;
768 // /////////////////////////////////////////////////////////////////
769 // change_cb - update callback for field arrow buttons
770 // /////////////////////////////////////////////////////////////////
773 PrefAgent::change_cb (WCallback *wcb)
775 if (timeout_called == 0)
776 change_field ((ChangeData *) wcb->ClientData());
777 // Get rid of the timeout if it is active.
786 // /////////////////////////////////////////////////////////////////
787 // arm_arrow - arm callback for field arrow buttons
788 // /////////////////////////////////////////////////////////////////
791 PrefAgent::arm_arrow (WCallback *wcb)
793 // Add a timeout to keep changing the value.
796 new WTimeOut (window_system().app_context(), CHANGE_SPEED, this,
797 (WTimeOutFunc) &PrefAgent::change_timeout,
802 // /////////////////////////////////////////////////////////////////
803 // disarm_arrow - arm callback for field arrow buttons
804 // /////////////////////////////////////////////////////////////////
807 PrefAgent::disarm_arrow()
814 // /////////////////////////////////////////////////////////////////
816 // /////////////////////////////////////////////////////////////////
819 PrefAgent::change_timeout (WTimeOut *wto)
823 bool changed = change_field ((ChangeData *) wto->ClientData());
824 // Add the callback again if the limit hasn't been reached.
827 int speed = CHANGE_SPEED;
828 // After three times double the speed.
829 if (timeout_called > 3)
832 new WTimeOut (window_system().app_context(), speed, this,
833 (WTimeOutFunc) &PrefAgent::change_timeout,
841 // /////////////////////////////////////////////////////////////////
843 // /////////////////////////////////////////////////////////////////
846 PrefAgent::change_field (ChangeData *cd)
848 // Get the current field value and add the change to it.
849 char *value = cd->field.Value();
850 int amount = atoi (value);
852 amount += cd->change;
854 // reached the limit, need to make the arrow go insensitive
855 if (amount == cd->limit)
857 // see if incrementing or decrementing
860 // user is decrementing--make down arrow insensitive
861 XtSetSensitive(cd->dn_arrow, False);
865 // user is incrementing--make down arrow insensitive
866 XtSetSensitive(cd->up_arrow, False);
871 // see if incrementing or decrementing
874 // user is decrementing--make up arrow sensitive if it is
876 if(!XtIsSensitive(cd->up_arrow))
877 XtSetSensitive(cd->up_arrow, True);
881 // user is incrementing--make down arrow sensitive if it is
883 if(!XtIsSensitive(cd->dn_arrow))
884 XtSetSensitive(cd->dn_arrow, True);
888 // Make sure the change won't exceed any limits.
889 // If change is negative, then limit is a lower limit (and vice-versa).
890 if ((cd->change < 0 && amount < cd->limit) ||
891 (cd->change > 0 && amount > cd->limit))
894 window_system().beep();
898 // Update the field to display the new value.
899 set_integer (cd->field, amount);
905 // /////////////////////////////////////////////////////////////////
907 // /////////////////////////////////////////////////////////////////
910 PrefAgent::lock_toggle (WCallback *wcb)
912 XmToggleButtonCallbackStruct &cbs =
913 *(XmToggleButtonCallbackStruct*) wcb->CallData();
919 // /////////////////////////////////////////////////////////////////
921 // /////////////////////////////////////////////////////////////////
924 PrefAgent::update_toggle (WCallback *wcb)
926 XmToggleButtonCallbackStruct &cbs =
927 *(XmToggleButtonCallbackStruct*) wcb->CallData();
929 set_update (cbs.set);
933 // /////////////////////////////////////////////////////////////////
935 // /////////////////////////////////////////////////////////////////
938 PrefAgent::set_lock (bool set)
941 f_lock_toggle.WObject::Set(WArgList(XmNselectPixmap,
942 window_system().locked_pixmap(f_lock_toggle.Parent()),
944 window_system().semilocked_pixmap(f_lock_toggle.Parent()),
948 f_lock_toggle.WObject::Set(WArgList(XmNselectPixmap,
949 window_system().semilocked_pixmap(f_lock_toggle.Parent()),
951 window_system().unlocked_pixmap(f_lock_toggle.Parent()),
955 f_lock_toggle.Set (set);
956 SET_VALUE (f_lock_toggle, Boolean, set);
960 // /////////////////////////////////////////////////////////////////
962 // /////////////////////////////////////////////////////////////////
965 PrefAgent::set_update (bool set)
967 XmStringLocalized mtfstring =
968 CATGETS(Set_AgentLabel, set? 203 : 204, set ? "On" : "Off");
970 XtVaSetValues(f_update_toggle, XmNlabelString, (XmString)mtfstring, NULL);
972 f_update_toggle.Set (set);
973 SET_VALUE (f_update_toggle, Boolean, set);
977 // /////////////////////////////////////////////////////////////////
979 // /////////////////////////////////////////////////////////////////
982 PrefAgent::set_geometry (WXmTextField &field, WindowGeometry &wg)
985 sprintf (buf, "%dx%d", wg.width, wg.height);
987 SET_VALUE (field, WindowGeometry, wg);
991 // /////////////////////////////////////////////////////////////////
993 // /////////////////////////////////////////////////////////////////
996 PrefAgent::set_integer (WXmTextField &field, int i)
999 sprintf (buf, "%d", i);
1001 SET_VALUE (field, Integer, i);
1005 // /////////////////////////////////////////////////////////////////
1007 // /////////////////////////////////////////////////////////////////
1010 PrefAgent::adisplay_toggle (WCallback *wcb)
1012 XmToggleButtonCallbackStruct &cbs =
1013 *(XmToggleButtonCallbackStruct*) wcb->CallData();
1015 set_auto_display (cbs.set);
1019 // /////////////////////////////////////////////////////////////////
1021 // /////////////////////////////////////////////////////////////////
1024 PrefAgent::set_auto_display (bool set)
1026 XmStringLocalized mtfstring =
1027 CATGETS(Set_AgentLabel, set? 203 : 204, set ? "On" : "Off");
1029 XtVaSetValues(f_adisplay_toggle, XmNlabelString, (XmString)mtfstring, NULL);
1031 f_adisplay_toggle.Set (set);
1032 SET_VALUE (f_adisplay_toggle, Boolean, set);
1036 // /////////////////////////////////////////////////////////////////
1037 // hyphen_toggle - 4/11/94 kamiya
1038 // This will be obsolete because toggle is not adequate for selecting
1039 // hyphenation processing method - 4/11/94 kamiya
1040 // /////////////////////////////////////////////////////////////////
1042 PrefAgent::hyphen_toggle (WCallback *)
1044 // obsolete, remove this method right away.
1047 // /////////////////////////////////////////////////////////////////
1048 // set_hyphen - 4/11/94 kamiya
1049 // /////////////////////////////////////////////////////////////////
1051 PrefAgent::set_hyphen (XtPointer)
1053 // obsolete, remove this method right away.
1057 // /////////////////////////////////////////////////////////////////
1058 // get_geometry - interactivly get a window geometry
1059 // /////////////////////////////////////////////////////////////////
1062 PrefAgent::get_geometry (WCallback *wcb)
1064 WXmTextField text_field ((Widget)wcb->ClientData());
1066 if (text_field == f_map_geo)
1068 else if (text_field == f_browse_geo)
1069 shell_name = "nodeview";
1071 // Display an instructional dialog.
1073 info_dialog ((Widget)f_shell, "geometry_msg",
1074 WArgList (XmNdialogType, XmDIALOG_INFORMATION, NULL));
1075 WXmDialogShell shell (info_dialog.Parent());
1077 String string = CATGETS(Set_PrefAgent, 2, "Dtinfo: Get Geometry");
1078 XtVaSetValues((Widget)shell, XmNtitle, string, NULL);
1079 // window_system().register_full_modal_shell (&shell);
1080 info_dialog.MessageString (
1081 (char*)UAS_String(CATGETS(Set_Messages, 16, "File a Bug")));
1082 XtUnmanageChild (info_dialog.OkPB());
1083 XtUnmanageChild (info_dialog.HelpPB());
1085 XtVaSetValues((Widget)info_dialog, XmNdefaultPosition, False, NULL);
1087 // Wait for the dialog to appear.
1089 info_dialog.Manage();
1090 XtAddEventHandler (info_dialog, ExposureMask, False,
1091 dialog_mapped, (XtPointer) &mapped);
1092 XtAppContext app_context = window_system().app_context();
1096 XtAppNextEvent (app_context, &event);
1097 XtDispatchEvent (&event);
1100 // Let the user pick an OLIAS window.
1101 static Cursor pick_cursor =
1102 XCreateFontCursor (window_system().display(), XC_crosshair);
1104 target = XmTrackingEvent (f_shell, pick_cursor, False, &event);
1106 // Get the geometry of the selected window.
1107 while (target != NULL && !XtIsShell (target))
1108 target = XtParent (target);
1110 if (target != (Widget) info_dialog.Parent())
1112 // Make sure the user clicked on the right kind of window.
1113 if (target != NULL && strcmp (XtName(target), shell_name) != 0)
1118 XBell (window_system().display(), 100);
1122 WShell shell (target);
1124 wg.width = shell.Width();
1125 wg.height = shell.Height();
1126 set_geometry (text_field, wg);
1131 info_dialog.Unmanage();
1132 XtDestroyWidget (info_dialog.Parent());
1136 // /////////////////////////////////////////////////////////////////
1137 // dialog_mapped - wait for dialog to appear on-screen
1138 // /////////////////////////////////////////////////////////////////
1141 PrefAgent::dialog_mapped (Widget w, XtPointer client_data,
1142 XEvent *, Boolean *)
1144 XmUpdateDisplay (w);
1146 *((int *) client_data) = TRUE;