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