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 ^^^ ***/
10 * File: fileChooser_stubs.c
11 * Contains: Module callbacks and connection functions
13 * This file was generated by dtcodegen, from module fileChooser
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.
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! **
26 #include "dtb_utils.h"
27 #include "fileChooser_ui.h"
30 /**************************************************************************
31 *** DTB_USER_CODE_START
33 *** All necessary header files have been included.
35 *** Add include files, types, macros, externs, and user functions here.
42 #if defined(linux) || defined(CSRG_BASED)
47 #include <strstream.h>
51 #include "ttsnoop_ui.h"
54 * There is no public header file for this function (only an
55 * internal header XmStringI.h).
58 extern XtPointer _XmStringUngenerate (XmString string,
61 XmTextType output_type);
64 extern std::ofstream snoopStream;
65 extern int globalTimeout;
67 typedef struct _FileChooserInfo {
68 _DtFileChooserAction choice;
74 _DtFileChooserAction choice,
82 case _DtFileChoosePatternAdd:
84 title = "tt_pattern_file_add";
86 case _DtFileChooseMessageSet:
88 title = "tt_message_file_set";
90 case _DtFileChooseJoin:
92 title = "tt_file_join";
94 case _DtFileChooseDtJoin:
96 title = "ttdt_file_join";
98 case _DtFileChooseQuit:
100 title = "tt_file_quit";
102 case _DtFileChooseDefault:
104 title = "tt_default_file_set";
106 case _DtFileChooseGetModified:
108 title = "ttdt_Get_Modified";
110 case _DtFileChooseSave:
114 case _DtFileChooseRevert:
116 title = "ttdt_Revert";
118 case _DtFileChooseNetfile:
119 okString = "Netfile";
120 title = "tt_file_netfile";
122 case _DtFileChooseChdir:
126 case _DtFileChooseTypesLoad:
128 title = "tt_session_types_load";
133 DtbFileChooserFchooserInfo instance =
134 &dtb_file_chooser_fchooser;
135 if (! instance->initialized) {
136 dtb_file_chooser_fchooser_initialize(
137 instance, dtb_ttsnoop_ttsnoop_win.ttsnoopWin );
139 XmString okXmString = XmStringCreateLocalized( okString );
140 XtVaSetValues( instance->fchooser, XmNokLabelString, okXmString, 0 );
141 XmStringFree( okXmString );
142 XtVaSetValues( instance->fchooser_shell, XmNtitle, title, 0 );
144 // Remember dialog mode, entity
145 FileChooserInfo *info = new FileChooserInfo;
146 info->choice = choice;
147 info->entity = entity;
148 XtVaSetValues( instance->fchooser, XmNuserData, info, 0 );
150 XtManageChild( instance->fchooser );
164 DtTtCreated( DTTT_MESSAGE, msg );
165 snoopIt( "Ttdt_file_cb", (void *) snoopFileMsg, msg );
166 if ( (tt_message_class( msg ) == TT_REQUEST)
167 && (tt_message_state( msg ) == TT_SENT))
169 // Let user fill in the answer
170 Widget newWidget = DtTtMessageWidgetCreate(
171 dtb_ttsnoop_ttsnoop_win.ttsnoopWin,
172 msg, DtTtMessageWidgetUpdate );
173 if (! tt_is_err( tt_ptr_error( newWidget ) )) {
174 XRaiseWindow( XtDisplay( newWidget ),
175 XtWindow( newWidget ));
181 /*** DTB_USER_CODE_END
183 *** End of user code section
185 **************************************************************************/
192 XtPointer clientData,
196 /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
197 /*** DTB_USER_CODE_END ^^^ Add C variables and code above ^^^ ***/
199 /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
200 DtbFileChooserFchooserInfo instance =
201 (DtbFileChooserFchooserInfo)clientData;
202 XmFileSelectionBoxCallbackStruct *cbRec =
203 (XmFileSelectionBoxCallbackStruct *)callData;
206 path = (char *) _XmStringUngenerate((XmString) cbRec->value, NULL,
207 XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
213 if ((path != 0) && (path[0] == '\0')) {
217 XtVaGetValues( instance->fchooser, XmNuserData, &xtPtr, 0 );
218 FileChooserInfo *info = (FileChooserInfo *)xtPtr;
219 Widget label = dtb_ttsnoop_ttsnoop_win.ttsnoopWin_label;
220 std::ostrstream script;
221 switch (info->choice) {
227 case _DtFileChoosePatternAdd:
228 _DtTtPatternUpdate( (Tt_pattern)info->entity, info->choice, path );
230 case _DtFileChooseMessageSet:
231 _DtTtMessageUpdate( (Tt_message)info->entity, info->choice, path );
233 case _DtFileChooseJoin:
234 status = tt_file_join( path );
235 DtTtSetLabel( label, "tt_file_join()", status );
237 case _DtFileChooseDtJoin:
238 pats = ttdt_file_join( path, TT_SCOPE_NONE, 1, snoopFileMsg, 0 );
239 status = DtTtSetLabel( label, "ttdt_file_join()", pats );
240 if ((status == TT_OK) && (pats != 0)) {
241 DtTtCreated( DTTT_DTFILE, pats, path );
244 case _DtFileChooseQuit:
245 status = tt_file_quit( path );
246 DtTtSetLabel( label, "tt_file_quit()", status );
248 case _DtFileChooseDefault:
249 status = tt_default_file_set( path );
250 DtTtSetLabel( label, "tt_default_file_set()", status );
252 case _DtFileChooseGetModified:
253 DtTtSetLabel( label, "ttdt_Get_Modified() = ..." );
254 XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
255 ival = ttdt_Get_Modified( 0, path, TT_BOTH,
256 XtWidgetToApplicationContext( label ),
258 XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
259 DtTtSetLabel( label, "ttdt_Get_Modified()", ival );
261 case _DtFileChooseSave:
262 DtTtSetLabel( label, "ttdt_Save() = ..." );
263 XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
264 status = ttdt_Save( 0, path, TT_BOTH,
265 XtWidgetToApplicationContext( label ),
267 // XXX Put up watch cursor; disable dialogs?
268 XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
269 DtTtSetLabel( label, "ttdt_Save()", status );
271 case _DtFileChooseRevert:
272 DtTtSetLabel( label, "ttdt_Revert() = ..." );
273 XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
274 ival = ttdt_Revert( 0, path, TT_BOTH,
275 XtWidgetToApplicationContext( label ),
277 XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
278 DtTtSetLabel( label, "ttdt_Revert()", ival );
280 case _DtFileChooseNetfile:
281 val = tt_file_netfile( path );
282 DtTtSetLabel( label, "tt_file_netfile()", val );
283 if (! tt_is_err( tt_ptr_error( val ))) {
284 snoopStream << "tt_file_netfile( \"" << val
285 << "\" ) = \"" << val << "\"" << endl;
288 case _DtFileChooseChdir:
289 ival = chdir( path );
290 DtTtSetLabel( label, "chdir()", ival );
292 case _DtFileChooseTypesLoad:
294 // Validate types file, with tt_type_comp -p
295 // (A corrupt file could crash ttsession.)
297 script << "numChars=`tt_type_comp -p \"" << path;
298 script << "\" | wc -c`; if [ $numChars = 0 ]; "
299 "then exit 1; else exit 0; fi" << endl;
300 ival = system( script.str() );
302 if (! WIFEXITED( ival )) {
304 "system( \"tt_type_comp -p\" )", ival );
307 if (WEXITSTATUS( ival ) != 0) {
308 std::ostrstream diagnosis;
309 diagnosis << "tt_type_comp -p: syntax error in "
311 DtTtSetLabel( label, diagnosis.str() );
312 delete diagnosis.str();
315 sess = tt_default_session();
316 status = tt_session_types_load( sess, path );
318 DtTtSetLabel( label, "tt_session_types_load()", status );
323 XtUnmanageChild( instance->fchooser_shell );
324 /*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/
329 /**************************************************************************
330 *** DTB_USER_CODE_START
332 *** All automatically-generated data and functions have been defined.
334 *** Add new functions here, or at the top of the file.
337 /*** DTB_USER_CODE_END
339 *** End of user code section
341 **************************************************************************/