Add -fpermissive to linux standard c++ option define in linux.cf
[oweals/cde.git] / cde / programs / dtprintinfo / UI / DtMainW.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 librararies 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 /* $TOG: DtMainW.C /main/5 1998/07/24 16:12:56 mgreess $ */
24 /*                                                                      *
25  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
26  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
27  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
28  * (c) Copyright 1993, 1994 Novell, Inc.                                *
29  */
30
31 #include "DtMainW.h"
32 #include "Application.h"
33 #include "Menu.h"
34 #include "MenuBar.h"
35 #include "LabelObj.h"
36 #include "Sep.h"
37 #include "Button.h"
38 #include "IconObj.h"
39 #include "DtWorkArea.h"
40 #include "DtActions.h"
41 #include "DtSetModList.h"
42 #include "DtFindD.h"
43 #include "HelpSystem.h"
44
45 #include "BaseObj.h"
46
47 #include "dtprintinfomsg.h"
48
49 #include <stdlib.h>
50 #include <stdio.h>
51
52 static char *GetIcon(AnyUI *obj, PrinterApplicationMode app_mode)
53 {
54    if (app_mode == SINGLE_PRINTER)
55     {
56       if (obj->depth == 1)
57          return "Fpprnt.l.bm";
58       else
59          return "Fpprnt.l.pm";
60     }
61    else
62     {
63       if (obj->depth == 1)
64          return "FpPrtmg.l.bm";
65       else
66          return "FpPrtmg.l.pm";
67     }
68 }
69
70 DtMainW::DtMainW(char *category,
71                  AnyUI *p, 
72                  char *name, 
73                  ContainerType container_type,
74                  SelectionType select_type,
75                  OpenCallback openCB, 
76                  void *openCallbackData,
77                  PreferenceCallback prefCB, 
78                  void *prefCallbackData,
79                  char *fileMenuName,
80                  char *fileMenuMnemonic,
81                  PrinterApplicationMode _app_mode)
82         : MainWindow(category, p, name, name, GetIcon(p, _app_mode))
83 {
84    Visible(true);
85    in_find = false;
86    working_curs = 0;
87    app_mode = _app_mode;
88    _openClose = openCB;
89    _prefCB = prefCB;
90    if (openCallbackData)
91       _openCallbackData = openCallbackData;
92    else
93       _openCallbackData = this;
94    if (prefCallbackData)
95       _prefCallbackData = prefCallbackData;
96    else
97       _prefCallbackData = this;
98    _fileMenuName = fileMenuName;
99    _fileMenuMnemonic = fileMenuMnemonic;
100    _container_type = container_type;
101    _select_type = select_type;
102    setModList = NULL;
103    setPrefD = NULL;
104    findD = NULL;
105    helpSystem = NULL;
106    findSetD = NULL;
107    action_data = (ActionData **) malloc(sizeof(ActionData *));
108    n_action_data = 0;
109 }
110
111 DtMainW::~DtMainW()
112 {
113    int i;
114    for (i = 0; i < n_action_data; i++)
115     {
116       delete action_data[i]->actionReferenceName;
117       delete action_data[i];
118     }
119    delete action_data;
120 }
121
122 void DtMainW::DisplayHelp(char *location_id, char *volume)
123 {
124    char old_msg[200];
125
126    strcpy(old_msg, status_line->Name());
127    status_line->Name(MESSAGE(GettingHelpL));
128    WorkingCursor(true);
129    if (!helpSystem)
130     {
131       char *title = new char[120];
132       sprintf(title, "%s - %s", Name(), MESSAGE(HelpL));
133
134       helpSystem = new HelpSystem(this, title, volume, location_id);
135       helpSystem->Visible(true);
136       delete [] title;
137     }
138    else
139     {
140       helpSystem->Visible(true);
141       helpSystem->Refresh();
142       helpSystem->HelpVolume(volume, location_id);
143     }
144    status_line->Name(old_msg);
145    WorkingCursor(false);
146    helpSystem->ToFront();
147 }
148
149 void DtMainW::Initialize()
150 {
151    mbar = new MenuBar(this);
152    Container *form = new DtWorkArea((char *) Category(), this, (char *)Name(), 
153                                     FORM);
154    container = new DtWorkArea((char *) Category(), form, (char *)Name(), 
155                               _container_type, _select_type);
156
157    status_line = new LabelObj(form, " ", LEFT_JUSTIFIED, true);
158    status_line->AttachBottom();
159    status_line->AttachLeft();
160    status_line->AttachRight();
161    container->AttachTop();
162    container->AttachLeft();
163    container->AttachRight();
164    container->AttachBottom(status_line);
165    if (app_mode == SINGLE_PRINTER)
166       container->WidthHeight(600, 150);
167    else
168       container->WidthHeight(600, 400);
169    SetWorkWindow(form);
170
171    char *title = new char[100];
172    sprintf(title, MESSAGE(SetOptionsTitleL), Name());
173    setPrefD = new DtSetPref(this, title, container, _prefCB,
174                             _prefCallbackData);
175    delete [] title;
176
177    fileMenu = new DtMenu(mbar, _fileMenuName, _fileMenuMnemonic,
178                          "PrinterMenuDE");
179    exitB = new Button(fileMenu, MESSAGE(ExitChoiceL), PUSH_BUTTON, ExitCB, this,
180                       MESSAGE(ExitMnemonicL), MESSAGE(ExitAcceleratorL));
181
182    actionsMenu = new DtActions(mbar, MESSAGE(SelectedMenuL),
183                                MESSAGE(SelectedAcceleratorL));
184    actionsMenu->Active(false);
185
186    if (app_mode != CONFIG_PRINTERS)
187     {
188       viewMenu = new DtMenu(mbar, MESSAGE(ViewMenuL),
189                             MESSAGE(ViewAcceleratorL), "ViewMenuDE");
190
191       setPref = new Button(viewMenu, MESSAGE(SetOptionsChoiceL), PUSH_BUTTON,
192                            SetPrefCB, setPrefD, MESSAGE(SetOptionsMnemonicL));
193     }
194    else
195       viewMenu = NULL;
196    helpMenu = new DtMenu(mbar, MESSAGE(HelpChoiceL), MESSAGE(HelpMnemonicL),
197                          "HelpMenuDE");
198    introduction = new Button(helpMenu, MESSAGE(OverviewChoiceL), PUSH_BUTTON,
199                              HelpCB, this, MESSAGE(OverviewMnemonicL));
200    new Sep(helpMenu);
201    tasks = new Button(helpMenu, MESSAGE(TaskChoiceL), PUSH_BUTTON, TasksCB,
202                       this, MESSAGE(TaskMnemonicL));
203    reference = new Button(helpMenu, MESSAGE(ReferenceChoiceL), PUSH_BUTTON,
204                           ReferenceCB, this, MESSAGE(ReferenceMnemonicL));
205    onWindow = new Button(helpMenu, MESSAGE(OnItemChoiceL), PUSH_BUTTON,
206                          OnItemCB, this, MESSAGE(OnItemMnemonicL));
207    new Sep(helpMenu);
208    usingHelp = new Button(helpMenu, MESSAGE(UsingHelpChoiceL), PUSH_BUTTON,
209                           UsingHelpCB, this, MESSAGE(UsingHelpMnemonicL));
210    new Sep(helpMenu);
211    char *tmp;
212    if (app_mode == PRINT_MANAGER)
213       tmp = MESSAGE(AboutChoice1L);
214    else if (app_mode == SINGLE_PRINTER)
215       tmp = MESSAGE(AboutChoice2L);
216    else
217       tmp = MESSAGE(AboutChoice3L);
218    version = new Button(helpMenu, tmp, PUSH_BUTTON, AboutCB,
219                         this, MESSAGE(AboutMnemonicL));
220
221    mbar->SetHelpMenu(helpMenu);
222 }
223
224 void DtMainW::SetPrefCB(void *data)
225 {
226    DtSetPref *obj = (DtSetPref *) data;
227
228    obj->Visible(true);
229 }
230
231 void DtMainW::ExitCB(void *data)
232 {
233    Application *app = (Application *)((BaseUI *)data)->Parent();
234    app->SaveMe();
235    delete (BaseObj *)((BaseUI *)data)->ApplicationData;
236    delete ((BaseUI *)data)->Parent();
237    exit (0);
238 }
239
240 void DtMainW::OpenClose(BaseUI *obj)
241 {
242    if (_openClose)
243       (*_openClose)(_openCallbackData, obj);
244 }
245
246 void DtMainW::DtAddAction(char *name, char *category, char *actionName,
247                           ActionCallback callback, void *callback_data,
248                           char *mnemonic, char *acceleratorText,
249                           char *accelerator)
250 {
251    BaseUI *action1;
252    if (action1 = actionsMenu->FindByName(name))
253       action1->Category(NULL);
254    else
255       actionsMenu->AddAction(name, category, actionName, callback, 
256                              callback_data, mnemonic, acceleratorText,
257                              accelerator);
258
259    int size = sizeof(ActionData *) * (n_action_data + 1);
260    action_data = (ActionData **) realloc(action_data, size);
261    action_data[n_action_data] = (ActionData *)malloc(sizeof(ActionData));
262    action_data[n_action_data]->actionReferenceName = strdup(actionName);
263    action_data[n_action_data]->callback_data = callback_data;
264    action_data[n_action_data]->actionCallback = callback;
265    Button *action = AddAction(name, category, &DtMainW::ActionCB, NULL,
266                               mnemonic, acceleratorText, accelerator); 
267    action->ApplicationData = action_data[n_action_data];
268    n_action_data++;
269 }
270
271 void DtMainW::DtAddSep(char *category)
272 {
273    actionsMenu->AddSep(category);
274    AddSep(category);
275 }
276
277 void DtMainW::ActionCB(void *callback_data)
278 {
279    Button *action = (Button *) callback_data;
280    DtMainW *window = (DtMainW *)action->Parent()->Parent()->Parent();
281    ActionData *cb = (ActionData *) action->ApplicationData;
282    if (cb->actionCallback)
283     {
284       if (window->container->ObjectExists(window->PopupObjectUniqueID))
285        {
286          (*cb->actionCallback)(cb->callback_data, window->PopupObject,
287                                cb->actionReferenceName);
288        }
289       else
290        {
291          Dialog *dialog = new Dialog(window, (char *)window->Name(), 
292                                      MESSAGE(NotFoundMessageL), INFORMATION,
293                                      MESSAGE(OKL));
294          dialog->Visible(true);
295        }
296     }
297 }
298
299 void DtMainW::HelpCB(void *data)
300 {
301    DtMainW * obj = (DtMainW *) data;
302    obj->DisplayHelp("_hometopic");
303 }
304
305 void DtMainW::ReferenceCB(void *data)
306 {
307    DtMainW * obj = (DtMainW *) data;
308    obj->DisplayHelp("Reference");
309 }
310
311 void DtMainW::TasksCB(void *data)
312 {
313    DtMainW * obj = (DtMainW *) data;
314    obj->DisplayHelp("Tasks");
315 }
316
317 void DtMainW::UsingHelpCB(void *data)
318 {
319    DtMainW * obj = (DtMainW *) data;
320    obj->DisplayHelp("_hometopic", "Help4Help");
321 }
322
323 void DtMainW::AboutCB(void *data)
324 {
325    DtMainW * obj = (DtMainW *) data;
326    obj->DisplayHelp("_copyright");
327 }
328
329 void DtMainW::OnItemCB(void *data)
330 {
331    DtMainW * obj = (DtMainW *) data;
332
333    obj->ContextualHelp();
334 }
335
336 boolean DtMainW::HandleHelpRequest()
337 {
338    if (app_mode == PRINT_MANAGER)
339       DisplayHelp("MainWindowDE");
340    else
341       DisplayHelp("PJMainWindowDE");
342    return true;
343 }
344
345 void DtMainW::WorkingCursor(boolean flag)
346 {
347    int i;
348    BaseUI **children = Children();
349    if (flag)
350     {
351       if (working_curs == 0)
352          for (i = 0; i < NumChildren(); i++, children++)
353             (*children)->PointerShape(HOUR_GLASS_CURSOR);
354       working_curs++;
355     }
356    else
357     {
358       working_curs--;
359       if (working_curs == 0)
360          for (i = 0; i < NumChildren(); i++, children++)
361             (*children)->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
362     }
363
364 }
365
366 boolean DtMenu::HandleHelpRequest()
367 {
368    ((DtMainW *)Parent()->Parent())->DisplayHelp(location_id);
369    return true;
370 }