DtUtil.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /* $TOG: DtUtil.c /main/10 1998/07/30 12:13:08 mgreess $ */
  24. /*
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  26. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  27. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  28. * (c) Copyright 1993, 1994 Novell, Inc. *
  29. */
  30. /******************************************************************************
  31. *
  32. * File Name: DtUtil.c
  33. *
  34. * Contains the DT functions used by an application to connect to the
  35. * underlying communications mechanism.
  36. *
  37. *****************************************************************************/
  38. #include <sys/param.h>
  39. #include <sys/types.h>
  40. #include <sys/stat.h>
  41. #include <netdb.h>
  42. #include <X11/Xlib.h>
  43. #include <X11/Intrinsic.h>
  44. #include <X11/StringDefs.h>
  45. #include <Xm/Xm.h>
  46. #include <Dt/DtP.h>
  47. #include <Dt/UserMsg.h>
  48. #include <Dt/DtNlUtils.h>
  49. #include <Dt/EnvControlP.h>
  50. #include "DtSvcLock.h"
  51. /*****************************************
  52. *
  53. * External functions not defined in header files.
  54. *
  55. *****************************************/
  56. /******** End Public Function Declarations ********/
  57. /******** Static Function Declarations ********/
  58. static Boolean DtBigInitialize(
  59. Display *display,
  60. Widget widget,
  61. char *name,
  62. char *toolClass,
  63. XtAppContext app_context) ;
  64. static void InitButtonLabels( void ) ;
  65. static void DtGlobalsInitialize(
  66. Display *display,
  67. char *name,
  68. char *toolClass) ;
  69. /******** End Static Function Declarations ********/
  70. /*****************************************
  71. *
  72. * Global variables
  73. *
  74. *****************************************/
  75. XrmDatabase _DtResourceDatabase = NULL; /* This Dt global indicates which
  76. Xrm database should be read for
  77. resources. */
  78. XtAppContext _DtAppContext = NULL; /* This Dt global keeps track of the
  79. app-context, if one has been
  80. specified. Note that libXv does
  81. not yet support multiple app-
  82. contexts. */
  83. XtAppContext *_DtInitAppContextp = NULL;
  84. Widget _DtInitTtContextWidget = NULL;
  85. Display *_DtDisplay = NULL; /* This global variable is saved
  86. when a client invokes "DtInitialize"
  87. It is used later to get resources
  88. when the DT databases are loaded.*/
  89. char *_DtApplicationName = NULL; /* This global variable is the
  90. client's "ApplicationName". */
  91. char *_DtApplicationClass = NULL; /* This global variable is the
  92. client's "ApplicationClass". */
  93. char *_DtToolClass = NULL; /* Tool class passed to _DtInit...() */
  94. /* Localizable button labels */
  95. const char * _DtOkString = NULL;
  96. const char * _DtCancelString = NULL;
  97. const char * _DtHelpString = NULL;
  98. const char * _DtApplyString = NULL;
  99. const char * _DtCloseString = NULL;
  100. /*********************************************
  101. *
  102. * Initialization Functions
  103. *
  104. *********************************************/
  105. Boolean
  106. DtAppInitialize(
  107. XtAppContext app_context,
  108. Display *display,
  109. Widget widget,
  110. char *name,
  111. char *toolClass )
  112. {
  113. Boolean result;
  114. _DtSvcAppLock(app_context);
  115. result = DtBigInitialize (display, widget, name, toolClass, app_context);
  116. _DtSvcAppUnlock(app_context);
  117. return (result);
  118. }
  119. Boolean
  120. DtInitialize(
  121. Display *display,
  122. Widget widget,
  123. char *name,
  124. char *toolClass )
  125. {
  126. Boolean result;
  127. _DtSvcDisplayToAppContext(display);
  128. _DtSvcAppLock(app);
  129. result = DtBigInitialize (display, widget, name, toolClass, NULL);
  130. _DtSvcAppUnlock(app);
  131. return (result);
  132. }
  133. static Boolean
  134. DtBigInitialize(
  135. Display *display,
  136. Widget widget,
  137. char *name,
  138. char *toolClass,
  139. XtAppContext app_context )
  140. {
  141. static Boolean initialized = False;
  142. /* Initialization can only be performed once. */
  143. _DtSvcProcessLock();
  144. if (initialized) {
  145. _DtSvcProcessUnlock();
  146. return (False);
  147. }
  148. /* Preserve the pre-Dt environ and add Dt-specifics to environ */
  149. (void) _DtEnvControl (DT_ENV_SET);
  150. /* Initialize a bunch of miscellaneous things. */
  151. DtNlInitialize();
  152. InitButtonLabels();
  153. DtGlobalsInitialize (display, name, toolClass);
  154. if ( XmIsGadget(widget) )
  155. _DtInitTtContextWidget = XtParent(widget);
  156. else
  157. _DtInitTtContextWidget = widget;
  158. if (app_context)
  159. _DtAppContext = app_context;
  160. else
  161. _DtAppContext = XtWidgetToApplicationContext(_DtInitTtContextWidget);
  162. _DtInitAppContextp = &_DtAppContext;
  163. initialized = TRUE;
  164. _DtSvcProcessUnlock();
  165. return (initialized);
  166. }
  167. /* Initialize the global button labels */
  168. static void
  169. InitButtonLabels( void )
  170. {
  171. _DtOkString = XtNewString(Dt11GETMESSAGE(28, 1, "OK"));
  172. _DtCancelString = XtNewString(Dt11GETMESSAGE(28, 2, "Cancel"));
  173. _DtHelpString = XtNewString(Dt11GETMESSAGE(28, 3, "Help"));
  174. _DtApplyString = XtNewString(Dt11GETMESSAGE(28, 4, "Apply"));
  175. _DtCloseString = XtNewString(Dt11GETMESSAGE(28, 5, "Close"));
  176. }
  177. static void
  178. DtGlobalsInitialize(
  179. Display *display,
  180. char *name,
  181. char *toolClass )
  182. {
  183. _DtResourceDatabase = XtDatabase (display);
  184. DtProgName = name;
  185. _DtToolClass = XtNewString(toolClass);
  186. XeToolClass = XtNewString (toolClass);
  187. /*
  188. * Save the application name and application class.
  189. */
  190. _DtDisplay = display;
  191. XtGetApplicationNameAndClass (display,
  192. &_DtApplicationName,
  193. &_DtApplicationClass);
  194. }