dtcreate: Avoid trying to reuse closed help window
[oweals/cde.git] / cde / programs / dtcreate / cmncbs.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: cmncbs.c /main/8 1999/09/17 15:44:29 mgreess $ */
24 /*****************************************************************************/
25 /*                                                                           */
26 /*  cmncbs.c                                                                 */
27 /*                                                                           */
28 /*   Common callbacks                                                        */
29 /*                                                                           */
30 /*****************************************************************************/
31 #include <stdio.h>
32 #include <sys/signal.h>
33 #include <X11/cursorfont.h>
34
35 #include <Dt/Icon.h>
36 #include <Dt/Help.h>
37 #include <Dt/HelpDialog.h>
38
39 #include "dtcreate.h"
40 #include "OpenFile.h"
41 #include "cmncbs.h"
42 #include "cmnrtns.h"
43 #include "CreateActionAppShell.h"
44 #include "ca_aux.h"
45 #include "icon_selection_dialog.h"
46
47
48 /******************************************************************************/
49 /* Initialize global values.                                                  */
50 /******************************************************************************/
51 Boolean bRegisteredSignal = FALSE;
52 int     (*sigchildRoutine)();
53
54 /******************************************************************************/
55 /* activateCB_open_FindSet - Callback for the "Find Set" button on            */
56 /*                           CreateActionAppShell and AddFiletype windows.    */
57 /*                           This callback will pop up the Icon Selection     */
58 /*                           dialog box.                                      */
59 /*                                                                            */
60 /* INPUT:  Widget filesel - file selection box widget id                      */
61 /*         XtPointer cdata - client data                                      */
62 /*         XmFileSelectionBoxCallbackStruct *cbstruct - callback data         */
63 /*                                                                            */
64 /* OUTPUT: none                                                               */
65 /*                                                                            */
66 /******************************************************************************/
67 void activateCB_open_FindSet (Widget find_set_button, XtPointer cdata,
68                               XmFileSelectionBoxCallbackStruct *cbstruct)
69 {
70   Widget filter;
71   Boolean use_bm = False;
72   static char *use_bm_filter = "*.m.bm";
73   static char *use_pm_filter = "*.m.pm";
74   char *search_path;
75   char *filter_field_title = NULL;
76   int use_filter_field = False;
77   char *file_filter;
78
79   char **directories_list = GetIconSearchPathList();
80   int numberOfTopButtons = 0;
81   void *top_button_one_cb = NULL;
82   void *top_button_two_cb = NULL;
83   void *top_button_three_cb = NULL;
84   char *top_button_one_label = NULL;
85   char *top_button_two_label = NULL;
86   char *top_button_three_label = NULL;
87   int use_icon_name_field = True;
88   int numberOfBottomButtons = 3;
89   void *bottom_button_one_cb = (void *)load_icons;
90   void *bottom_button_two_cb = NULL;
91   void *bottom_button_three_cb = NULL;
92   void *bottom_button_four_cb = NULL;
93   char *bottom_button_one_label = NULL;   /* use default */
94   char *bottom_button_two_label = NULL;   /* use default */
95   char *bottom_button_three_label = NULL; /* use default */
96   char *bottom_button_four_label = NULL;  /* use default */
97
98   char *name_field_title;
99   char *container_title;
100   char *directory_title;
101   char *dialog_title, *pre, *suf;
102
103   name_field_title = XtNewString(GETMESSAGE(11, 12, "Enter Icon Filename"));
104   container_title = XtNewString(GETMESSAGE(11, 11, "Icon Files"));
105   directory_title = XtNewString(GETMESSAGE(11, 30, "Icon Folders"));
106
107   pre = GETMESSAGE(3, 10, "Create Action");
108   suf = GETMESSAGE(6, 18, "Find Set");
109   dialog_title = XtMalloc(strlen(pre) + strlen(suf) + 4);
110   sprintf(dialog_title, "%s - %s", pre, suf);
111
112 #ifdef DEBUG
113   printf("activate Find Set button; client_data = %p\n", cdata); /* debug */
114 #endif
115
116   XtVaGetValues (COLOR_MONO_OPTION, XmNset, &use_bm, NULL);
117
118   if (use_bm) file_filter = use_bm_filter;
119   else file_filter = use_pm_filter;
120
121 #ifndef _ICONSELECTOR_DESTROY_ENABLED
122   if (!IconSelector) {
123 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
124      IconSelector = create_icon_selection_dialog ((swidget) CreateActionAppShell,
125                                                (unsigned char *)dialog_title,
126                                                (unsigned char *)filter_field_title,
127                                                use_filter_field,
128                                                (unsigned char *)file_filter,
129                                                (unsigned char *)directory_title,
130                                                (unsigned char **)directories_list,
131                                                (unsigned char *)container_title,
132                                                numberOfTopButtons,
133                                                (unsigned char *)top_button_one_label,
134                                                (void (*)())top_button_one_cb,
135                                                (unsigned char *)top_button_two_label,
136                                                (void (*)())top_button_two_cb,
137                                                (unsigned char *)top_button_three_label,
138                                                (void (*)())top_button_three_cb,
139                                                use_icon_name_field,
140                                                (unsigned char *)name_field_title,
141                                                numberOfBottomButtons,
142                                                (unsigned char *)bottom_button_one_label,
143                                                (void (*)())bottom_button_one_cb,
144                                                (unsigned char *)bottom_button_two_label,
145                                                (void (*)())bottom_button_two_cb,
146                                                (unsigned char *)bottom_button_three_label,
147                                                (void (*)())bottom_button_three_cb,
148                                                (unsigned char *)bottom_button_four_label,
149                                                (void (*)())bottom_button_four_cb);
150 #ifndef _ICONSELECTOR_DESTROY_ENABLED
151   }
152 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
153   XtFree(name_field_title);
154   XtFree(container_title);
155   XtFree(directory_title);
156   XtFree(dialog_title);
157   FreeIconSearchPathList(directories_list);
158   XtVaSetValues (IconSelector, XmNuserData, cdata, NULL);
159   UxPopupInterface (IconSelector, no_grab);
160   XmProcessTraversal(ISD_SelectedIconTextField, XmTRAVERSE_CURRENT);
161   return;
162 }
163
164 /******************************************************************************/
165 /*                                                                            */
166 /* createCB_IconGadget                                                        */
167 /*                                                                            */
168 /* INPUT:  Widget wid  - icon gadget windet id                                */
169 /*         Boolean bActionIcons - is this an action widget                    */
170 /*         enum icon_size_range - size of icon this widget represents         */
171 /*                                                                            */
172 /* OUTPUT: none                                                               */
173 /*                                                                            */
174 /******************************************************************************/
175         void    createCB_IconGadget(Widget wid,
176                                     Boolean bActionIcons,
177                                     enum icon_size_range IconSize)
178
179 {
180   SetIconData(wid,
181               (char *)((bActionIcons) ?
182                        ca_full_icon_default : af_full_icon_default),
183               IconSize);
184
185 }
186
187 /******************************************************************************/
188 /* activateCB_edit_icon - brings up icon editor with selected icon            */
189 /*                                                                            */
190 /* INPUT:  Widget wid - widget id                                             */
191 /*         XtPointer cd - client data                                         */
192 /*         XmPushButtonCallbackStruct *cbs - callback data                    */
193 /* OUTPUT: none                                                               */
194 /*                                                                            */
195 /******************************************************************************/
196 void activateCB_edit_icon (Widget wid, XtPointer client_data,
197                            XmPushButtonCallbackStruct *cbs)
198 {
199   char    *pszIconToEdit;
200   Boolean IsActionIcons;
201
202   if (bIconEditorDisplayed) return;
203
204   if ((int)client_data == CA_ACTION_ICONS) {
205      IsActionIcons = True;
206      widSelectedIcon = get_selected_action_icon();
207      widEditSource = CreateActionAppShell;
208   } else {
209      IsActionIcons = False;
210      widSelectedIcon = (Widget)get_selected_filetype_icon();
211      widEditSource = AddFiletype;
212   }
213   XtVaGetValues (widSelectedIcon, XmNimageName, &pszIconToEdit, NULL);
214
215   /***************************************************************/
216   /* Call routine to send tooltalk message to start icon editor. */
217   /***************************************************************/
218   UxDoEditPixmap(widSelectedIcon, pszIconToEdit);
219
220   return;
221 }
222
223 /* We use this so we can reuse an open help dialog window. */
224 static Widget  mainHelpDialog = NULL;
225
226 /******************************************************************************/
227 /*                                                                            */
228 /* closeCB_mainHelpDialog                                                     */
229 /*                                                                            */
230 /* INPUT:  Widget wid - widget id                                             */
231 /*         XtPointer cd - client data                                         */
232 /*         XtPointer cbs - callback data                                      */
233 /* OUTPUT: none                                                               */
234 /*                                                                            */
235 /******************************************************************************/
236 void closeCB_mainHelpDialog(Widget wid, XtPointer client_data,
237                            XtPointer *cbs)
238 {
239   XtDestroyWidget(wid);
240   mainHelpDialog = NULL;
241 }
242
243 /******************************************************************************/
244 /*                                                                            */
245 /* DisplayHelpDialog                                                          */
246 /*                                                                            */
247 /* INPUT:  Widget wid - widget id                                             */
248 /*         XtPointer cd - client data                                         */
249 /*         XtPointer cbs - callback data                                      */
250 /* OUTPUT: none                                                               */
251 /*                                                                            */
252 /******************************************************************************/
253 void DisplayHelpDialog(Widget wid, XtPointer client_data, XtPointer cbs)
254 {
255   Widget  parent;
256   int     i;
257   Arg     args[10];
258   char    pszTitle[MAXBUFSIZE];
259   char    pszTopic[MAXBUFSIZE];
260
261   i = 0;
262
263   /***********************************************************************/
264   /* Get help dialog window title.                                       */
265   /***********************************************************************/
266   /*
267   sprintf(pszTitle, "%s  -  %s", GETMESSAGE(3, 10, "Create Action"),
268           GETMESSAGE(2, 53, "Help"));
269   */
270   sprintf(pszTitle, "%s  -  ", GETMESSAGE(3, 10, "Create Action"));
271   strcat(pszTitle, GETMESSAGE(2, 53, "Help"));
272   XtSetArg(args[i], XmNtitle, pszTitle); i++;
273
274   /***********************************************************************/
275   /* Now set the particular helpvolume and topic to view                 */
276   /***********************************************************************/
277   XtSetArg(args[i], DtNhelpType, DtHELP_TYPE_TOPIC); i++;
278   XtSetArg(args[i], DtNhelpVolume, "CreatAct"); i++;
279   XtSetArg(args[i], DtNlocationId, pszTopic); i++;
280
281   switch ((int)client_data) {
282      case HELP_OVERVIEW:
283                          strcpy(pszTopic, "_hometopic");
284                          break;
285      case HELP_TASKS:
286                          strcpy(pszTopic, "Tasks");
287                          break;
288      case HELP_REFERENCE:
289                          strcpy(pszTopic, "Reference");
290                          break;
291      case HELP_USING:
292                          strcpy(pszTopic, "_HOMETOPIC");
293                          XtSetArg(args[i], DtNhelpVolume, "Help4Help"); i++;
294                          break;
295      case HELP_ABOUT:
296                          strcpy(pszTopic, "_copyright");
297                          break;
298      case HELP_ONITEM:
299                          strcpy(pszTopic, "CreateActionMainWindow");
300                          break;
301      case HELP_ADDFILETYPE:
302                          strcpy(pszTopic, "AddDatatypeWindow");
303                          break;
304      case HELP_FILECHAR:
305                          strcpy(pszTopic, "DatatypeCriteriaWindow");
306                          break;
307      case HELP_ICONSELECTOR:
308                          strcpy(pszTopic, "FindIconSetDialog");
309                          break;
310      case HELP_OPENFILE:
311                          strcpy(pszTopic, "openDialog");
312                          break;
313   }
314
315   /***********************************************************************/
316   /* Create the Help dialog.                                             */
317   /***********************************************************************/
318   /*  **** old method of getting parent ****
319   XtVaGetValues(wid, XmNuserData, &parent, NULL);
320   if (!parent) {
321      parent = wid;
322   }
323   */
324   parent = GetTrueToplevel(wid);
325   TurnOnHourGlassAllWindows();
326   if ( mainHelpDialog == NULL ) {
327       mainHelpDialog = DtCreateHelpDialog(parent, "mainHelpDialog", args, i);
328       XtAddCallback(mainHelpDialog, DtNcloseCallback,
329                 (void (*)())closeCB_mainHelpDialog,
330                 (XtPointer)NULL);
331       XtManageChild(mainHelpDialog);
332   } else {
333      XtSetValues( mainHelpDialog, args, i );
334   }
335   TurnOffHourGlassAllWindows();
336 }
337 /******************************************************************************/
338 /*                                                                            */
339 /* helpCB_general                                                             */
340 /*                                                                            */
341 /* INPUT:  Widget wid - widget id                                             */
342 /*         XtPointer cd - client data                                         */
343 /*         XtPointer cbs - callback data                                      */
344 /* OUTPUT: none                                                               */
345 /*                                                                            */
346 /******************************************************************************/
347 void    helpCB_general(Widget UxWidget,
348                        XtPointer UxClientData,
349                        XtPointer UxCallbackArg)
350
351 {
352   DisplayHelpDialog(UxWidget, UxClientData, UxCallbackArg);
353 }