Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / programs / ttsnoop / fileChooser_stubs.C.src
1 /*** DTB_USER_CODE_START vvv Add file header below vvv ***/
2 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company
3 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.
4 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
5 //%%  (c) Copyright 1993, 1994 Novell, Inc.
6 //%%  $XConsortium: fileChooser_stubs.C.src /main/4 1996/10/14 09:35:42 barstow $
7 /*** DTB_USER_CODE_END   ^^^ Add file header above ^^^ ***/
8
9 /*
10  * File: fileChooser_stubs.c
11  * Contains: Module callbacks and connection functions
12  *
13  * This file was generated by dtcodegen, from module fileChooser
14  *
15  * Any text may be added between the DTB_USER_CODE_START and
16  * DTB_USER_CODE_END comments (even non-C code). Descriptive comments
17  * are provided only as an aid.
18  *
19  *  ** EDIT ONLY WITHIN SECTIONS MARKED WITH DTB_USER_CODE COMMENTS.  **
20  *  ** ALL OTHER MODIFICATIONS WILL BE OVERWRITTEN. DO NOT MODIFY OR  **
21  *  ** DELETE THE GENERATED COMMENTS!                                 **
22  */
23
24 #include <stdio.h>
25 #include <Xm/Xm.h>
26 #include "dtb_utils.h"
27 #include "fileChooser_ui.h"
28
29
30 /**************************************************************************
31  *** DTB_USER_CODE_START
32  ***
33  *** All necessary header files have been included.
34  ***
35  *** Add include files, types, macros, externs, and user functions here.
36  ***/
37
38 #include <unistd.h>
39 #include <sys/wait.h>
40 #include <Xm/TextF.h>
41
42 #include <fstream>
43 #include <sstream>
44
45 #include "DtTt.h"
46 #include "ttsnoop_ui.h"
47
48 /*
49  * There is no public header file for this function (only an
50  * internal header XmStringI.h).
51  */
52 extern "C" {
53 extern XtPointer _XmStringUngenerate (XmString string,
54                         XmStringTag tag,
55                         XmTextType tag_type,
56                         XmTextType output_type);
57 }
58
59 extern std::ofstream snoopStream;
60 extern int      globalTimeout;
61
62 typedef struct _FileChooserInfo {
63         _DtFileChooserAction    choice;
64         void *                  entity;
65 } FileChooserInfo;
66
67 void
68 _DtFileChooserSet(
69         _DtFileChooserAction    choice,
70         void *                  entity
71 )
72 {
73         char *okString;
74         char *title;
75         char *valueLabel;
76         switch (choice) {
77             case _DtFileChoosePatternAdd:
78                 okString = "Add";
79                 title = "tt_pattern_file_add";
80                 break;
81             case _DtFileChooseMessageSet:
82                 okString = "Set";
83                 title = "tt_message_file_set";
84                 break;
85             case _DtFileChooseJoin:
86                 okString = "Join";
87                 title = "tt_file_join";
88                 break;
89             case _DtFileChooseDtJoin:
90                 okString = "Join";
91                 title = "ttdt_file_join";
92                 break;
93             case _DtFileChooseQuit:
94                 okString = "Quit";
95                 title = "tt_file_quit";
96                 break;
97             case _DtFileChooseDefault:
98                 okString = "Set";
99                 title = "tt_default_file_set";
100                 break;
101             case _DtFileChooseGetModified:
102                 okString = "Get";
103                 title = "ttdt_Get_Modified";
104                 break;
105             case _DtFileChooseSave:
106                 okString = "Save";
107                 title = "ttdt_Save";
108                 break;
109             case _DtFileChooseRevert:
110                 okString = "Revert";
111                 title = "ttdt_Revert";
112                 break;
113             case _DtFileChooseNetfile:
114                 okString = "Netfile";
115                 title = "tt_file_netfile";
116                 break;
117             case _DtFileChooseChdir:
118                 okString = "chdir";
119                 title = "chdir(2)";
120                 break;
121             case _DtFileChooseTypesLoad:
122                 okString = "Load";
123                 title = "tt_session_types_load";
124                 break;
125             default:
126                 return;
127         }
128         DtbFileChooserFchooserInfo instance =
129                 &dtb_file_chooser_fchooser;
130         if (! instance->initialized) {
131                 dtb_file_chooser_fchooser_initialize(
132                         instance, dtb_ttsnoop_ttsnoop_win.ttsnoopWin );
133         }
134         XmString okXmString = XmStringCreateLocalized( okString );
135         XtVaSetValues( instance->fchooser, XmNokLabelString, okXmString, NULL );
136         XmStringFree( okXmString );
137         XtVaSetValues( instance->fchooser_shell, XmNtitle, title, NULL );
138
139         // Remember dialog mode, entity
140         FileChooserInfo *info = new FileChooserInfo;
141         info->choice = choice;
142         info->entity = entity;
143         XtVaSetValues( instance->fchooser, XmNuserData, info, NULL );
144
145         XtManageChild( instance->fchooser );
146 }
147
148 static Tt_message
149 snoopFileMsg(
150         Tt_message      msg,
151         Tttk_op         op,
152         char *          pathname,
153         void *          clientData,
154         int             trust,
155         int             isMe
156 )
157 {
158         tt_free( pathname );
159         DtTtCreated( DTTT_MESSAGE, msg );
160         snoopIt( "Ttdt_file_cb", (void *) snoopFileMsg, msg );
161         if (   (tt_message_class( msg ) == TT_REQUEST)
162             && (tt_message_state( msg ) == TT_SENT))
163         {
164                 // Let user fill in the answer
165                 Widget newWidget = DtTtMessageWidgetCreate(
166                                     dtb_ttsnoop_ttsnoop_win.ttsnoopWin,
167                                     msg, DtTtMessageWidgetUpdate );
168                 if (! tt_is_err( tt_ptr_error( newWidget ) )) {
169                         XRaiseWindow( XtDisplay( newWidget ),
170                                       XtWindow( newWidget ));
171                 }
172         }
173         return 0;
174 }
175
176 /*** DTB_USER_CODE_END
177  ***
178  *** End of user code section
179  ***
180  **************************************************************************/
181
182
183
184 void 
185 fileOkayed(
186     Widget widget,
187     XtPointer clientData,
188     XtPointer callData
189 )
190 {
191     /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
192     /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
193     
194     /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
195     DtbFileChooserFchooserInfo instance =
196             (DtbFileChooserFchooserInfo)clientData;
197     XmFileSelectionBoxCallbackStruct *cbRec =
198             (XmFileSelectionBoxCallbackStruct *)callData;
199     char *path;
200     
201     path = (char *) _XmStringUngenerate((XmString) cbRec->value, NULL,
202                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
203
204     if (!path) {
205             abort();
206             return;
207     }
208     if ((path != 0) && (path[0] == '\0')) {
209             path = 0;
210     }
211     XtPointer xtPtr;
212     XtVaGetValues( instance->fchooser, XmNuserData, &xtPtr, NULL );
213     FileChooserInfo *info = (FileChooserInfo *)xtPtr;
214     Widget label = dtb_ttsnoop_ttsnoop_win.ttsnoopWin_label;
215     std::ostringstream script;
216     switch (info->choice) {
217             Tt_pattern *pats;
218             Tt_message msg;
219             Tt_status status;
220             int ival;
221             char *sess, *val;
222         case _DtFileChoosePatternAdd:
223             _DtTtPatternUpdate( (Tt_pattern)info->entity, info->choice, path );
224             break;
225         case _DtFileChooseMessageSet:
226             _DtTtMessageUpdate( (Tt_message)info->entity, info->choice, path );
227             break;
228         case _DtFileChooseJoin:
229             status = tt_file_join( path );
230             DtTtSetLabel( label, "tt_file_join()", status );
231             break;
232         case _DtFileChooseDtJoin:
233             pats = ttdt_file_join( path, TT_SCOPE_NONE, 1, snoopFileMsg, 0 );
234             status = DtTtSetLabel( label, "ttdt_file_join()", pats );
235             if ((status == TT_OK) && (pats != 0)) {
236                     DtTtCreated( DTTT_DTFILE, pats, path );
237             }
238             break;
239         case _DtFileChooseQuit:
240             status = tt_file_quit( path );
241             DtTtSetLabel( label, "tt_file_quit()", status );
242             break;
243         case _DtFileChooseDefault:
244             status = tt_default_file_set( path );
245             DtTtSetLabel( label, "tt_default_file_set()", status );
246             break;
247         case _DtFileChooseGetModified:
248             DtTtSetLabel( label, "ttdt_Get_Modified() = ..." );
249             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
250             ival = ttdt_Get_Modified( 0, path, TT_BOTH,
251                                       XtWidgetToApplicationContext( label ),
252                                       globalTimeout );
253             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
254             DtTtSetLabel( label, "ttdt_Get_Modified()", ival );
255             break;
256         case _DtFileChooseSave:
257             DtTtSetLabel( label, "ttdt_Save() = ..." );
258             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
259             status = ttdt_Save( 0, path, TT_BOTH,
260                                 XtWidgetToApplicationContext( label ),
261                                 globalTimeout );
262             // XXX Put up watch cursor; disable dialogs?
263             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
264             DtTtSetLabel( label, "ttdt_Save()", status );
265             break;
266         case _DtFileChooseRevert:
267             DtTtSetLabel( label, "ttdt_Revert() = ..." );
268             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
269             ival = ttdt_Revert( 0, path, TT_BOTH,
270                                 XtWidgetToApplicationContext( label ),
271                                 globalTimeout );
272             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
273             DtTtSetLabel( label, "ttdt_Revert()", ival );
274             break;
275         case _DtFileChooseNetfile:
276             val = tt_file_netfile( path );
277             DtTtSetLabel( label, "tt_file_netfile()", val );
278             if (! tt_is_err( tt_ptr_error( val ))) {
279                     snoopStream << "tt_file_netfile( \"" << val
280                             << "\" ) = \"" << val << "\"" << endl;
281             }
282             break;
283         case _DtFileChooseChdir:
284             ival = chdir( path );
285             DtTtSetLabel( label, "chdir()", ival );
286             break;
287         case _DtFileChooseTypesLoad:
288             //
289             // Validate types file, with tt_type_comp -p
290             // (A corrupt file could crash ttsession.)
291             //
292             script << "numChars=`tt_type_comp -p \"" << path;
293             script << "\" | wc -c`; if [ $numChars = 0 ]; "
294                       "then exit 1; else exit 0; fi" << endl;
295             ival = system( script.str().c_str() );
296             if (! WIFEXITED( ival )) {
297                     DtTtSetLabel( label,
298                         "system( \"tt_type_comp -p\" )", ival );
299                     break;
300             }
301             if (WEXITSTATUS( ival ) != 0) {
302                     std::ostringstream diagnosis;
303                     diagnosis << "tt_type_comp -p: syntax error in "
304                             << path << ends;
305                     DtTtSetLabel( label, diagnosis.str().c_str() );
306                     break;
307             }
308             sess = tt_default_session();
309             status = tt_session_types_load( sess, path );
310             tt_free( sess );
311             DtTtSetLabel( label, "tt_session_types_load()", status );
312             break;
313         default:
314             break;
315     }
316     XtUnmanageChild( instance->fchooser_shell );
317     /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
318 }
319
320
321
322 /**************************************************************************
323  *** DTB_USER_CODE_START
324  ***
325  *** All automatically-generated data and functions have been defined.
326  ***
327  *** Add new functions here, or at the top of the file.
328  ***/
329
330 /*** DTB_USER_CODE_END
331  ***
332  *** End of user code section
333  ***
334  **************************************************************************/
335
336