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