fileChooser_stubs.C.src 9.5 KB

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