Fix Linux rpc problems with new glibc
[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 libraries 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/types.h>
33 #include <sys/signal.h>
34 #include <X11/cursorfont.h>
35
36 #include <Dt/Icon.h>
37 #include <Dt/Help.h>
38 #include <Dt/HelpDialog.h>
39
40 #include "dtcreate.h"
41 #include "OpenFile.h"
42 #include "cmncbs.h"
43 #include "cmnrtns.h"
44 #include "CreateActionAppShell.h"
45 #include "af_aux.h"
46 #include "ca_aux.h"
47 #include "icon_selection_dialog.h"
48
49 /* from main.c */
50 extern void UxDoEditPixmap(Widget wid, char *fname);
51
52 /******************************************************************************/
53 /* Initialize global values.                                                  */
54 /******************************************************************************/
55 Boolean bRegisteredSignal = FALSE;
56 int     (*sigchildRoutine)();
57
58 /******************************************************************************/
59 /* activateCB_open_FindSet - Callback for the "Find Set" button on            */
60 /*                           CreateActionAppShell and AddFiletype windows.    */
61 /*                           This callback will pop up the Icon Selection     */
62 /*                           dialog box.                                      */
63 /*                                                                            */
64 /* INPUT:  Widget filesel - file selection box widget id                      */
65 /*         XtPointer cdata - client data                                      */
66 /*         XmFileSelectionBoxCallbackStruct *cbstruct - callback data         */
67 /*                                                                            */
68 /* OUTPUT: none                                                               */
69 /*                                                                            */
70 /******************************************************************************/
71 void activateCB_open_FindSet (Widget find_set_button, XtPointer cdata,
72                               XmFileSelectionBoxCallbackStruct *cbstruct)
73 {
74   Widget filter;
75   XtArgVal /* Boolean */ use_bm = False;
76   static char *use_bm_filter = "*.m.bm";
77   static char *use_pm_filter = "*.m.pm";
78   char *search_path;
79   char *filter_field_title = NULL;
80   int use_filter_field = False;
81   char *file_filter;
82
83   char **directories_list = GetIconSearchPathList();
84   int numberOfTopButtons = 0;
85   void *top_button_one_cb = NULL;
86   void *top_button_two_cb = NULL;
87   void *top_button_three_cb = NULL;
88   char *top_button_one_label = NULL;
89   char *top_button_two_label = NULL;
90   char *top_button_three_label = NULL;
91   int use_icon_name_field = True;
92   int numberOfBottomButtons = 3;
93   void *bottom_button_one_cb = (void *)load_icons;
94   void *bottom_button_two_cb = NULL;
95   void *bottom_button_three_cb = NULL;
96   void *bottom_button_four_cb = NULL;
97   char *bottom_button_one_label = NULL;   /* use default */
98   char *bottom_button_two_label = NULL;   /* use default */
99   char *bottom_button_three_label = NULL; /* use default */
100   char *bottom_button_four_label = NULL;  /* use default */
101
102   char *name_field_title;
103   char *container_title;
104   char *directory_title;
105   char *dialog_title, *pre, *suf;
106
107   name_field_title = XtNewString(GETMESSAGE(11, 12, "Enter Icon Filename"));
108   container_title = XtNewString(GETMESSAGE(11, 11, "Icon Files"));
109   directory_title = XtNewString(GETMESSAGE(11, 30, "Icon Folders"));
110
111   pre = GETMESSAGE(3, 10, "Create Action");
112   suf = GETMESSAGE(6, 18, "Find Set");
113   dialog_title = XtMalloc(strlen(pre) + strlen(suf) + 4);
114   sprintf(dialog_title, "%s - %s", pre, suf);
115
116 #ifdef DEBUG
117   printf("activate Find Set button; client_data = %p\n", cdata); /* debug */
118 #endif
119
120   XtVaGetValues (COLOR_MONO_OPTION, XmNset, &use_bm, NULL);
121
122   if (use_bm) file_filter = use_bm_filter;
123   else file_filter = use_pm_filter;
124
125 #ifndef _ICONSELECTOR_DESTROY_ENABLED
126   if (!IconSelector) {
127 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
128      IconSelector = create_icon_selection_dialog ((swidget) CreateActionAppShell,
129                                                (unsigned char *)dialog_title,
130                                                (unsigned char *)filter_field_title,
131                                                use_filter_field,
132                                                (unsigned char *)file_filter,
133                                                (unsigned char *)directory_title,
134                                                (unsigned char **)directories_list,
135                                                (unsigned char *)container_title,
136                                                numberOfTopButtons,
137                                                (unsigned char *)top_button_one_label,
138                                                (void (*)())top_button_one_cb,
139                                                (unsigned char *)top_button_two_label,
140                                                (void (*)())top_button_two_cb,
141                                                (unsigned char *)top_button_three_label,
142                                                (void (*)())top_button_three_cb,
143                                                use_icon_name_field,
144                                                (unsigned char *)name_field_title,
145                                                numberOfBottomButtons,
146                                                (unsigned char *)bottom_button_one_label,
147                                                (void (*)())bottom_button_one_cb,
148                                                (unsigned char *)bottom_button_two_label,
149                                                (void (*)())bottom_button_two_cb,
150                                                (unsigned char *)bottom_button_three_label,
151                                                (void (*)())bottom_button_three_cb,
152                                                (unsigned char *)bottom_button_four_label,
153                                                (void (*)())bottom_button_four_cb);
154 #ifndef _ICONSELECTOR_DESTROY_ENABLED
155   }
156 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
157   XtFree(name_field_title);
158   XtFree(container_title);
159   XtFree(directory_title);
160   XtFree(dialog_title);
161   FreeIconSearchPathList(directories_list);
162   XtVaSetValues (IconSelector, XmNuserData, cdata, NULL);
163   UxPopupInterface (IconSelector, no_grab);
164   XmProcessTraversal(ISD_SelectedIconTextField, XmTRAVERSE_CURRENT);
165   return;
166 }
167
168 /******************************************************************************/
169 /*                                                                            */
170 /* createCB_IconGadget                                                        */
171 /*                                                                            */
172 /* INPUT:  Widget wid  - icon gadget windet id                                */
173 /*         Boolean bActionIcons - is this an action widget                    */
174 /*         enum icon_size_range - size of icon this widget represents         */
175 /*                                                                            */
176 /* OUTPUT: none                                                               */
177 /*                                                                            */
178 /******************************************************************************/
179         void    createCB_IconGadget(Widget wid,
180                                     Boolean bActionIcons,
181                                     enum icon_size_range IconSize)
182
183 {
184   SetIconData(wid,
185               (char *)((bActionIcons) ?
186                        ca_full_icon_default : af_full_icon_default),
187               IconSize);
188
189 }
190
191 /******************************************************************************/
192 /* activateCB_edit_icon - brings up icon editor with selected icon            */
193 /*                                                                            */
194 /* INPUT:  Widget wid - widget id                                             */
195 /*         XtPointer cd - client data                                         */
196 /*         XmPushButtonCallbackStruct *cbs - callback data                    */
197 /* OUTPUT: none                                                               */
198 /*                                                                            */
199 /******************************************************************************/
200 void activateCB_edit_icon (Widget wid, XtPointer client_data,
201                            XmPushButtonCallbackStruct *cbs)
202 {
203   char    *pszIconToEdit;
204   Boolean IsActionIcons;
205
206   if (bIconEditorDisplayed) return;
207
208   if ((int)(XtArgVal)client_data == CA_ACTION_ICONS) {
209      IsActionIcons = True;
210      widSelectedIcon = get_selected_action_icon();
211      widEditSource = CreateActionAppShell;
212   } else {
213      IsActionIcons = False;
214      widSelectedIcon = (Widget)get_selected_filetype_icon();
215      widEditSource = AddFiletype;
216   }
217   XtVaGetValues (widSelectedIcon, XmNimageName, &pszIconToEdit, NULL);
218
219   /***************************************************************/
220   /* Call routine to send tooltalk message to start icon editor. */
221   /***************************************************************/
222   UxDoEditPixmap(widSelectedIcon, pszIconToEdit);
223
224   return;
225 }
226
227 /* We use this so we can reuse an open help dialog window. */
228 static Widget  mainHelpDialog = NULL;
229
230 /******************************************************************************/
231 /*                                                                            */
232 /* closeCB_mainHelpDialog                                                     */
233 /*                                                                            */
234 /* INPUT:  Widget wid - widget id                                             */
235 /*         XtPointer cd - client data                                         */
236 /*         XtPointer cbs - callback data                                      */
237 /* OUTPUT: none                                                               */
238 /*                                                                            */
239 /******************************************************************************/
240 void closeCB_mainHelpDialog(Widget wid, XtPointer client_data,
241                            XtPointer *cbs)
242 {
243   XtDestroyWidget(wid);
244   mainHelpDialog = NULL;
245 }
246
247 /******************************************************************************/
248 /*                                                                            */
249 /* DisplayHelpDialog                                                          */
250 /*                                                                            */
251 /* INPUT:  Widget wid - widget id                                             */
252 /*         XtPointer cd - client data                                         */
253 /*         XtPointer cbs - callback data                                      */
254 /* OUTPUT: none                                                               */
255 /*                                                                            */
256 /******************************************************************************/
257 void DisplayHelpDialog(Widget wid, XtPointer client_data, XtPointer cbs)
258 {
259   Widget  parent;
260   int     i;
261   Arg     args[10];
262   char    pszTitle[MAXBUFSIZE];
263   char    pszTopic[MAXBUFSIZE];
264
265   i = 0;
266
267   /***********************************************************************/
268   /* Get help dialog window title.                                       */
269   /***********************************************************************/
270   /*
271   sprintf(pszTitle, "%s  -  %s", GETMESSAGE(3, 10, "Create Action"),
272           GETMESSAGE(2, 53, "Help"));
273   */
274   snprintf(pszTitle, sizeof(pszTitle), "%s  -  %s", GETMESSAGE(3, 10, "Create Action"), 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 }