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