remove OSF1 support
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Managers / PrefMgr.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*      Copyright (c) 1994 FUJITSU LIMITED      */
24 /*      All Rights Reserved                     */
25
26 /*
27  * $XConsortium: PrefMgr.cc /main/5 1996/06/11 16:27:12 cde-hal $
28  *
29  * Copyright (c) 1992 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
33  * OR DISCLOSURE.
34  * 
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
39  * INTERNATIONAL, LTD.
40  * 
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.
46  *
47  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
48  *                  1315 Dell Avenue
49  *                  Campbell, CA  95008
50  * 
51  */
52
53 #define C_UserPreference
54 #define C_IntegerPref
55 #define C_BooleanPref
56 #define C_WindowGeometryPref
57 #define C_StringPref
58 #define L_Preferences
59
60 #define C_PrefAgent
61 #define L_Agents
62
63 #define C_PrefMgr
64 #define C_MessageMgr
65 #define L_Managers
66
67 #include <Prelude.h>
68
69 #ifndef ORIGINAL
70 LONG_LIVED_CC(PrefMgr,pref_mgr);
71 #else
72 PrefMgr *PrefMgr::g_pref_mgr;
73 PrefMgr &
74 pref_mgr()
75 {
76   message_mgr().warning_dialog ("PrefMgr access detected.");
77   if (PrefMgr::g_pref_mgr == NULL)
78     PrefMgr::g_pref_mgr = new PrefMgr();
79   return (*PrefMgr::g_pref_mgr);
80 }
81 #endif
82
83 #if defined(__STDC__) || defined(hpux)
84 # define DEFSYM(S) PrefSymbol PrefMgr::S = (PrefSymbol) #S
85 #else
86 # define DEFSYM(S) PrefSymbol PrefMgr::S = (PrefSymbol) "S"
87 #endif
88
89 DEFSYM (BrowseGeometry);
90 DEFSYM (FontScale);
91 DEFSYM (BrowseLock);
92 DEFSYM (MapGeometry);
93 DEFSYM (MapAutoUpdate);
94 DEFSYM (NodeHistSize);
95 DEFSYM (SearchHistSize);
96 DEFSYM (MaxSearchHits);
97 DEFSYM (DefaultMarkBase);
98 DEFSYM (DisplayFirstHit);
99 DEFSYM (AutomaticHelp);
100 #ifdef UseWideChars
101 // preferences for Japanese hyphenation - 4/6/94 kamiya
102 DEFSYM (HyphenMethod);
103 DEFSYM (HyphenLevel);
104 #endif
105
106
107 PrefMgr::~PrefMgr()
108 {
109   delete f_last_preference;
110 }
111
112 void
113 PrefMgr::display()
114 {
115   if (f_pref_agent == NULL)
116     f_pref_agent = new PrefAgent();
117
118   f_pref_agent->display();
119 }
120
121
122 void
123 PrefMgr::sync()
124 {
125   mtry
126     {
127       UserPreference::flush_preferences();
128     }
129   mcatch_any()
130     {
131       message_mgr().error_dialog ((char*)"Unable to save preferences.");
132     }
133   end_try;
134 }
135
136
137 int
138 PrefMgr::get_int (const PrefSymbol sym)
139 {
140   if (f_last_symbol != sym)
141     {
142       f_last_symbol = sym;
143       delete f_last_preference;
144       f_last_preference = new IntegerPref (sym);
145     }
146
147   return (((IntegerPref *) f_last_preference)->value());
148 }
149
150 void
151 PrefMgr::set_int (const PrefSymbol sym, int value)
152 {
153   if (f_last_symbol != sym)
154     {
155       f_last_symbol = sym;
156       delete f_last_preference;
157       f_last_preference = new IntegerPref (sym);
158     }
159
160   ((IntegerPref *) f_last_preference)->value (value);
161   notify (INT_CHANGED);
162 }
163
164
165 bool
166 PrefMgr::get_boolean (const PrefSymbol sym)
167 {
168   if (f_last_symbol != sym)
169     {
170       f_last_symbol = sym;
171       delete f_last_preference;
172       f_last_preference = new BooleanPref (sym);
173     }
174
175   return (((BooleanPref *) f_last_preference)->value());
176 }
177
178 void
179 PrefMgr::set_boolean (const PrefSymbol sym, bool value)
180 {
181   if (f_last_symbol != sym)
182     {
183       f_last_symbol = sym;
184       delete f_last_preference;
185       f_last_preference = new BooleanPref (sym);
186     }
187
188   ((BooleanPref *) f_last_preference)->value (value);
189   notify (BOOLEAN_CHANGED);
190 }
191
192
193 const char *
194 PrefMgr::get_string (const PrefSymbol sym)
195 {
196   if (f_last_symbol != sym)
197     {
198       f_last_symbol = sym;
199       delete f_last_preference;
200       f_last_preference = new StringPref (sym);
201     }
202
203   return (((StringPref *) f_last_preference)->value());
204 }
205
206 void
207 PrefMgr::set_string (const PrefSymbol sym, const char *value)
208 {
209   if (f_last_symbol != sym)
210     {
211       f_last_symbol = sym;
212       delete f_last_preference;
213       f_last_preference = new StringPref (sym);
214     }
215
216   ((StringPref *) f_last_preference)->value (value);
217   notify (STRING_CHANGED);
218 }
219
220
221 const WindowGeometry &
222 PrefMgr::get_geometry (const PrefSymbol sym)
223 {
224   if (f_last_symbol != sym)
225     {
226       f_last_symbol = sym;
227       delete f_last_preference;
228       f_last_preference = new WindowGeometryPref (sym);
229     }
230
231   return (((WindowGeometryPref *) f_last_preference)->value());
232 }
233
234 void
235 PrefMgr::set_geometry (const PrefSymbol sym, const WindowGeometry &value)
236 {
237   if (f_last_symbol != sym)
238     {
239       f_last_symbol = sym;
240       delete f_last_preference;
241       f_last_preference = new WindowGeometryPref (sym);
242     }
243
244   ((WindowGeometryPref *) f_last_preference)->value (value);
245   notify (GEOMETRY_CHANGED);
246 }