Link with C++ linker
[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) + 2);
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 /******************************************************************************/
224 /*                                                                            */
225 /* closeCB_mainHelpDialog                                                     */
226 /*                                                                            */
227 /* INPUT:  Widget wid - widget id                                             */
228 /*         XtPointer cd - client data                                         */
229 /*         XtPointer cbs - callback data                                      */
230 /* OUTPUT: none                                                               */
231 /*                                                                            */
232 /******************************************************************************/
233 void closeCB_mainHelpDialog(Widget wid, XtPointer client_data,
234                            XtPointer *cbs)
235 {
236   XtDestroyWidget(wid);
237 }
238
239 /******************************************************************************/
240 /*                                                                            */
241 /* DisplayHelpDialog                                                          */
242 /*                                                                            */
243 /* INPUT:  Widget wid - widget id                                             */
244 /*         XtPointer cd - client data                                         */
245 /*         XtPointer cbs - callback data                                      */
246 /* OUTPUT: none                                                               */
247 /*                                                                            */
248 /******************************************************************************/
249 void DisplayHelpDialog(Widget wid, XtPointer client_data, XtPointer cbs)
250 {
251   static Widget  mainHelpDialog = NULL;
252   Widget  parent;
253   int     i;
254   Arg     args[10];
255   char    pszTitle[MAXBUFSIZE];
256   char    pszTopic[MAXBUFSIZE];
257
258   i = 0;
259
260   /***********************************************************************/
261   /* Get help dialog window title.                                       */
262   /***********************************************************************/
263   /*
264   sprintf(pszTitle, "%s  -  %s", GETMESSAGE(3, 10, "Create Action"),
265           GETMESSAGE(2, 53, "Help"));
266   */
267   sprintf(pszTitle, "%s  -  ", GETMESSAGE(3, 10, "Create Action"));
268   strcat(pszTitle, GETMESSAGE(2, 53, "Help"));
269   XtSetArg(args[i], XmNtitle, pszTitle); i++;
270
271   /***********************************************************************/
272   /* Now set the particular helpvolume and topic to view                 */
273   /***********************************************************************/
274   XtSetArg(args[i], DtNhelpType, DtHELP_TYPE_TOPIC); i++;
275   XtSetArg(args[i], DtNhelpVolume, "CreatAct"); i++;
276   XtSetArg(args[i], DtNlocationId, pszTopic); i++;
277
278   switch ((int)client_data) {
279      case HELP_OVERVIEW:
280                          strcpy(pszTopic, "_hometopic");
281                          break;
282      case HELP_TASKS:
283                          strcpy(pszTopic, "Tasks");
284                          break;
285      case HELP_REFERENCE:
286                          strcpy(pszTopic, "Reference");
287                          break;
288      case HELP_USING:
289                          strcpy(pszTopic, "_HOMETOPIC");
290                          XtSetArg(args[i], DtNhelpVolume, "Help4Help"); i++;
291                          break;
292      case HELP_ABOUT:
293                          strcpy(pszTopic, "_copyright");
294                          break;
295      case HELP_ONITEM:
296                          strcpy(pszTopic, "CreateActionMainWindow");
297                          break;
298      case HELP_ADDFILETYPE:
299                          strcpy(pszTopic, "AddDatatypeWindow");
300                          break;
301      case HELP_FILECHAR:
302                          strcpy(pszTopic, "DatatypeCriteriaWindow");
303                          break;
304      case HELP_ICONSELECTOR:
305                          strcpy(pszTopic, "FindIconSetDialog");
306                          break;
307      case HELP_OPENFILE:
308                          strcpy(pszTopic, "openDialog");
309                          break;
310   }
311
312   /***********************************************************************/
313   /* Create the Help dialog.                                             */
314   /***********************************************************************/
315   /*  **** old method of getting parent ****
316   XtVaGetValues(wid, XmNuserData, &parent, NULL);
317   if (!parent) {
318      parent = wid;
319   }
320   */
321   parent = GetTrueToplevel(wid);
322   TurnOnHourGlassAllWindows();
323   if ( mainHelpDialog == NULL ) {
324       mainHelpDialog = DtCreateHelpDialog(parent, "mainHelpDialog", args, i);
325       XtAddCallback(mainHelpDialog, DtNcloseCallback,
326                 (void (*)())closeCB_mainHelpDialog,
327                 (XtPointer)NULL);
328       XtManageChild(mainHelpDialog);
329   } else {
330      XtSetValues( mainHelpDialog, args, i );
331   }
332   TurnOffHourGlassAllWindows();
333 }
334 /******************************************************************************/
335 /*                                                                            */
336 /* helpCB_general                                                             */
337 /*                                                                            */
338 /* INPUT:  Widget wid - widget id                                             */
339 /*         XtPointer cd - client data                                         */
340 /*         XtPointer cbs - callback data                                      */
341 /* OUTPUT: none                                                               */
342 /*                                                                            */
343 /******************************************************************************/
344 void    helpCB_general(Widget UxWidget,
345                        XtPointer UxClientData,
346                        XtPointer UxCallbackArg)
347
348 {
349   DisplayHelpDialog(UxWidget, UxClientData, UxCallbackArg);
350 }