OpenFile.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. /* $XConsortium: OpenFile.c /main/6 1996/10/17 14:06:40 rswiston $ */
  24. /*******************************************************************************
  25. OpenFile.c
  26. Associated Header file: OpenFile.h
  27. *******************************************************************************/
  28. #include <stdio.h>
  29. #include <Xm/Xm.h>
  30. #include <Xm/MwmUtil.h>
  31. #include <Xm/DialogS.h>
  32. #include <Xm/MenuShell.h>
  33. #include <Xm/FileSB.h>
  34. #include <Dt/Icon.h>
  35. #include "UxXt.h"
  36. #include "dtcreate.h"
  37. #include "cmnrtns.h"
  38. #include "cmncbs.h"
  39. #include "ca_aux.h"
  40. #include "fileio.h"
  41. #define CONTEXT_MACRO_ACCESS 1
  42. #include "OpenFile.h"
  43. #undef CONTEXT_MACRO_ACCESS
  44. extern XtPointer
  45. _XmStringUngenerate(XmString, XmStringTag, XmTextType, XmTextType);
  46. /*******************************************************************************
  47. The following are callback functions.
  48. *******************************************************************************/
  49. static void cancelCB_OpenFile( Widget UxWidget,
  50. XtPointer UxClientData,
  51. XtPointer UxCallbackArg )
  52. {
  53. _UxCOpenFile *UxSaveCtx, *UxContext;
  54. UxSaveCtx = UxOpenFileContext;
  55. UxOpenFileContext = UxContext =
  56. (_UxCOpenFile *) UxGetContext( UxWidget );
  57. {
  58. UxPopdownInterface(UxWidget);
  59. }
  60. UxOpenFileContext = UxSaveCtx;
  61. }
  62. static void okCallback_OpenFile( Widget UxWidget,
  63. XtPointer UxClientData,
  64. XtPointer UxCallbackArg )
  65. {
  66. _UxCOpenFile *UxSaveCtx, *UxContext;
  67. XmFileSelectionBoxCallbackStruct *cbs;
  68. /*char *text;*/
  69. int rc = 1; /* 1 = OpenDefinitionFile() failure */
  70. ActionData ADTmp;
  71. UxSaveCtx = UxOpenFileContext;
  72. UxOpenFileContext = UxContext =
  73. (_UxCOpenFile *) UxGetContext( UxWidget );
  74. {
  75. /********************************************************************/
  76. /* Call file parsing code here! */
  77. /********************************************************************/
  78. cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
  79. if (pszFileToEdit) {
  80. XtFree(pszFileToEdit);
  81. }
  82. pszFileToEdit =
  83. _XmStringUngenerate(cbs->value, NULL,
  84. XmCHARSET_TEXT, XmCHARSET_TEXT);
  85. if (pszFileToEdit != (char *)NULL) {
  86. memset(&ADTmp, 0, sizeof(ActionData));
  87. rc = OpenDefinitionFile(pszFileToEdit, &ADTmp);
  88. /*XtFree(text);*/
  89. /*****************************************************************/
  90. /* If everything ok, then clear out data from action structure */
  91. /* and store new data. */
  92. /*****************************************************************/
  93. if (!rc) {
  94. FreeAndClearAD(&AD);
  95. memcpy(&AD, &ADTmp, sizeof(ActionData));
  96. }
  97. }
  98. UxPopdownInterface (UxWidget);
  99. /********************************************************************/
  100. /* If successfully opened and parsed file, then init the fields of */
  101. /* the main window. */
  102. /********************************************************************/
  103. if (!rc) {
  104. clear_CreateActionAppShell_fields();
  105. writeCAToGUI(&AD);
  106. }
  107. }
  108. UxOpenFileContext = UxSaveCtx;
  109. }
  110. static void helpCallback_OpenFile( Widget UxWidget,
  111. XtPointer UxClientData,
  112. XtPointer UxCallbackArg )
  113. {
  114. _UxCOpenFile *UxSaveCtx, *UxContext;
  115. UxSaveCtx = UxOpenFileContext;
  116. UxOpenFileContext = UxContext =
  117. (_UxCOpenFile *) UxGetContext( UxWidget );
  118. {
  119. DisplayHelpDialog(UxWidget, (XtPointer)HELP_OPENFILE, UxCallbackArg);
  120. }
  121. UxOpenFileContext = UxSaveCtx;
  122. }
  123. /*******************************************************************************
  124. The 'build_' function creates all the widgets
  125. using the resource values specified in the Property Editor.
  126. *******************************************************************************/
  127. static Widget _Uxbuild_OpenFile(void)
  128. {
  129. Widget _UxParent;
  130. /* Creation of OpenFile */
  131. _UxParent = XtVaCreatePopupShell( "OpenFile_shell",
  132. xmDialogShellWidgetClass, UxTopLevel,
  133. XmNx, 200,
  134. XmNy, 290,
  135. XmNwidth, 398,
  136. XmNheight, 500,
  137. XmNallowShellResize, TRUE,
  138. XmNshellUnitType, XmPIXELS,
  139. XmNtitle, GETMESSAGE(12, 25, "Create Action - Open"),
  140. NULL );
  141. OpenFile = XtVaCreateWidget( "OpenFile",
  142. xmFileSelectionBoxWidgetClass,
  143. _UxParent,
  144. XmNresizePolicy, XmRESIZE_GROW,
  145. XmNunitType, XmPIXELS,
  146. XmNwidth, 398,
  147. XmNheight, 500,
  148. RES_CONVERT( XmNdialogTitle, GETMESSAGE(12, 25, "Create Action - Open")),
  149. RES_CONVERT( XmNdirectory, "" ),
  150. RES_CONVERT( XmNtextString, "" ),
  151. RES_CONVERT( XmNdirSpec, "" ),
  152. XmNdialogType, XmDIALOG_FILE_SELECTION,
  153. XmNtextColumns, 20,
  154. XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  155. XmNallowOverlap, FALSE,
  156. RES_CONVERT( XmNchildPlacement, "place_below_selection" ),
  157. XmNdefaultPosition, FALSE,
  158. RES_CONVERT( XmNdirMask, "" ),
  159. RES_CONVERT( XmNpattern, "" ),
  160. NULL );
  161. XtAddCallback( OpenFile, XmNcancelCallback,
  162. (XtCallbackProc) cancelCB_OpenFile,
  163. (XtPointer) UxOpenFileContext );
  164. XtAddCallback( OpenFile, XmNokCallback,
  165. (XtCallbackProc) okCallback_OpenFile,
  166. (XtPointer) UxOpenFileContext );
  167. XtAddCallback( OpenFile, XmNhelpCallback,
  168. (XtCallbackProc) helpCallback_OpenFile,
  169. (XtPointer) UxOpenFileContext );
  170. XtVaSetValues(OpenFile, XmNuserData, OpenFile, NULL);
  171. UxPutContext( OpenFile, (char *) UxOpenFileContext );
  172. XtAddCallback( OpenFile, XmNdestroyCallback,
  173. (XtCallbackProc) UxDestroyContextCB,
  174. (XtPointer) UxOpenFileContext);
  175. return ( OpenFile );
  176. }
  177. /*******************************************************************************
  178. The following is the 'Interface function' which is the
  179. external entry point for creating this interface.
  180. This function should be called from your application or from
  181. a callback function.
  182. *******************************************************************************/
  183. Widget create_OpenFile(void)
  184. {
  185. Widget rtrn;
  186. _UxCOpenFile *UxContext;
  187. UxOpenFileContext = UxContext =
  188. (_UxCOpenFile *) UxNewContext( sizeof(_UxCOpenFile), False );
  189. rtrn = _Uxbuild_OpenFile();
  190. return(rtrn);
  191. }
  192. /*******************************************************************************
  193. END OF FILE
  194. *******************************************************************************/