svpopup.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. *
  3. Copyright 1989, 1998 The Open Group
  4. Permission to use, copy, modify, distribute, and sell this software and its
  5. documentation for any purpose is hereby granted without fee, provided that
  6. the above copyright notice appear in all copies and that both that
  7. copyright notice and this permission notice appear in supporting
  8. documentation.
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  15. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall not be
  18. used in advertising or otherwise to promote the sale, use or other dealings
  19. in this Software without prior written authorization from The Open Group.
  20. *
  21. * Author: Chris D. Peterson, MIT X Consortium
  22. */
  23. #include <X11/Intrinsic.h>
  24. #include <X11/StringDefs.h> /* Get standard string definations. */
  25. #include <X11/Xatom.h>
  26. #include <X11/cursorfont.h>
  27. #include <X11/Shell.h>
  28. #include <X11/Xaw/AsciiText.h>
  29. #include <X11/Xaw/Cardinals.h>
  30. #include <X11/Xaw/Command.h>
  31. #include <X11/Xaw/Form.h>
  32. #include <X11/Xaw/Label.h>
  33. #include <stdio.h>
  34. #ifdef XKB
  35. #include <X11/extensions/XKBbells.h>
  36. #endif
  37. #include "editresP.h"
  38. static void _SetField ( Widget new, Widget old );
  39. static void CreateSetValuesPopup ( Widget parent, ScreenData * scr_data );
  40. static void DoSetValues ( Widget w, XtPointer junk, XtPointer garbage );
  41. static void CancelSetValues ( Widget w, XtPointer junk, XtPointer garbage );
  42. /* Function Name: PopupSetValues
  43. * Description: This function pops up the setvalues dialog
  44. * Arguments: parent - the parent of the setvalues popup.
  45. * event - the event that caused this popup, or NULL.
  46. * Returns: none
  47. */
  48. /* ARGSUSED */
  49. void
  50. PopupSetValues(Widget parent, XEvent *event)
  51. {
  52. Arg args[1];
  53. if (global_tree_info == NULL) {
  54. SetMessage(global_screen_data.info_label,
  55. res_labels[17]);
  56. return;
  57. }
  58. /*
  59. * Check and possibly create the popup.
  60. */
  61. if (global_screen_data.set_values_popup == NULL)
  62. CreateSetValuesPopup(parent, &global_screen_data);
  63. /*
  64. * Clear out the old strings, and set the active widget to the name widget.
  65. */
  66. XtSetArg(args[0], XtNstring, "");
  67. XtSetValues(global_screen_data.res_text, args, ONE);
  68. XtSetValues(global_screen_data.val_text, args, ONE);
  69. _SetField(global_screen_data.res_text, global_screen_data.val_text);
  70. /*
  71. * Pop it up.
  72. */
  73. PopupCentered(event, global_screen_data.set_values_popup, XtGrabNone);
  74. }
  75. /* Function Name: ModifySVEntry
  76. * Description: Action routine that can be bound to the set values
  77. * dialog box's Text Widget that will send input to the
  78. * field specified.
  79. * Arguments: (Standard Action Routine args)
  80. * Returns: none.
  81. */
  82. /* ARGSUSED */
  83. void
  84. ModifySVEntry(Widget w, XEvent *event, String *params, Cardinal *num_params)
  85. {
  86. Widget new, old;
  87. char msg[BUFSIZ];
  88. if (*num_params != 1) {
  89. strcpy(msg,
  90. res_labels[21]);
  91. SetMessage(global_screen_data.info_label, msg);
  92. return;
  93. }
  94. switch (params[0][0]) {
  95. case 'r':
  96. case 'R':
  97. new = global_screen_data.res_text;
  98. old = global_screen_data.val_text;
  99. break;
  100. case 'v':
  101. case 'V':
  102. new = global_screen_data.val_text;
  103. old = global_screen_data.res_text;
  104. break;
  105. default:
  106. sprintf(msg, res_labels[22]);
  107. SetMessage(global_screen_data.info_label, msg);
  108. return;
  109. }
  110. _SetField(new, old);
  111. }
  112. /************************************************************
  113. *
  114. * Private Functions
  115. *
  116. ************************************************************/
  117. /* Function Name: _SetField
  118. * Description: Sets the current text entry field.
  119. * Arguments: new, old - new and old text fields.
  120. * Returns: none
  121. */
  122. static void
  123. _SetField(Widget new, Widget old)
  124. {
  125. Arg args[2];
  126. Pixel new_border, old_border, old_bg;
  127. if (!XtIsSensitive(new)) {
  128. #ifdef XKB
  129. /* Don't set field to an inactive Widget. */
  130. XkbStdBell(XtDisplay(old), XtWindow(new), 0, XkbBI_InvalidLocation);
  131. #else
  132. XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */
  133. #endif
  134. return;
  135. }
  136. XtSetKeyboardFocus(XtParent(new), new);
  137. XtSetArg(args[0], XtNborderColor, &old_border);
  138. XtSetArg(args[1], XtNbackground, &old_bg);
  139. XtGetValues(new, args, TWO);
  140. XtSetArg(args[0], XtNborderColor, &new_border);
  141. XtGetValues(old, args, ONE);
  142. if (old_border != old_bg) /* Colors are already correct, return. */
  143. return;
  144. XtSetArg(args[0], XtNborderColor, old_border);
  145. XtSetValues(old, args, ONE);
  146. XtSetArg(args[0], XtNborderColor, new_border);
  147. XtSetValues(new, args, ONE);
  148. }
  149. /* Function Name: CreateSetValuesPopup
  150. * Description: Creates the setvalues popup.
  151. * Arguments: parent - the parent of the popup.
  152. * scr_data - the data about this screen.
  153. * Returns: the set values popup.
  154. */
  155. static void
  156. CreateSetValuesPopup(Widget parent, ScreenData *scr_data)
  157. {
  158. Widget form, cancel, do_it, label;
  159. Widget res_label;
  160. Arg args[10];
  161. Cardinal num_args;
  162. scr_data->set_values_popup = XtCreatePopupShell("setValuesPopup",
  163. transientShellWidgetClass,
  164. parent, NULL, ZERO);
  165. form = XtCreateManagedWidget("form", formWidgetClass,
  166. scr_data->set_values_popup, NULL, ZERO);
  167. num_args = 0;
  168. label = XtCreateManagedWidget("label", labelWidgetClass,
  169. form, args, num_args);
  170. num_args = 0;
  171. XtSetArg(args[num_args], XtNfromVert, label); num_args++;
  172. res_label = XtCreateManagedWidget("resourceLabel", labelWidgetClass,
  173. form, args, num_args);
  174. num_args = 0;
  175. XtSetArg(args[num_args], XtNfromVert, label); num_args++;
  176. XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
  177. scr_data->res_text = XtCreateManagedWidget("resourceText",
  178. asciiTextWidgetClass,
  179. form, args, num_args);
  180. num_args = 0;
  181. XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
  182. (void) XtCreateManagedWidget("valueLabel", labelWidgetClass,
  183. form, args, num_args);
  184. num_args = 0;
  185. XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
  186. XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
  187. scr_data->val_text = XtCreateManagedWidget("valueText",
  188. asciiTextWidgetClass,
  189. form, args, num_args);
  190. num_args = 0;
  191. XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
  192. do_it = XtCreateManagedWidget("setValues", commandWidgetClass,
  193. form, args, num_args);
  194. num_args = 0;
  195. XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
  196. XtSetArg(args[num_args], XtNfromHoriz, do_it); num_args++;
  197. cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
  198. form, args, num_args);
  199. XtAddCallback(do_it, XtNcallback, DoSetValues, NULL);
  200. XtAddCallback(cancel, XtNcallback, CancelSetValues, NULL);
  201. /*
  202. * Initialize the text entry fields.
  203. */
  204. {
  205. Pixel color;
  206. num_args = 0;
  207. XtSetArg(args[num_args], XtNbackground, &color); num_args++;
  208. XtGetValues(scr_data->val_text, args, num_args);
  209. num_args = 0;
  210. XtSetArg(args[num_args], XtNborderColor, color); num_args++;
  211. XtSetValues(scr_data->val_text, args, num_args);
  212. XtSetKeyboardFocus(form, scr_data->res_text);
  213. }
  214. }
  215. /* Function Name: DoSetValues
  216. * Description: Performs a SetValues.
  217. * Arguments: w - the widget that called this.
  218. * junk, garbage - ** UNUSED **.
  219. * Returns: none.
  220. */
  221. /* ARGSUSED */
  222. static void
  223. DoSetValues(Widget w, XtPointer junk, XtPointer garbage)
  224. {
  225. ProtocolStream * stream = &(global_client.stream);
  226. char *res_name, *res_value;
  227. Arg args[1];
  228. Cardinal i;
  229. if (global_tree_info->num_nodes == 0) {
  230. SetMessage(global_screen_data.info_label,
  231. res_labels[23]);
  232. return;
  233. }
  234. XtSetArg(args[0], XtNstring, &res_name);
  235. XtGetValues(global_screen_data.res_text, args, ONE);
  236. XtSetArg(args[0], XtNstring, &res_value);
  237. XtGetValues(global_screen_data.val_text, args, ONE);
  238. _XEditResResetStream(stream);
  239. _XEditResPutString8(stream, res_name);
  240. _XEditResPutString8(stream, XtRString);
  241. _XEditResPutString8(stream, res_value);
  242. _XEditResPut16(stream, global_tree_info->num_nodes);
  243. for (i = 0; i < global_tree_info->num_nodes; i++)
  244. InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
  245. SetCommand(w, LocalSetValues, NULL);
  246. }
  247. /* Function Name: CancelSetValues
  248. * Description: Pops down the setvalues popup.
  249. * Arguments: w - any grandchild of the popup.
  250. * junk, garbage - ** UNUSED **.
  251. * Returns: none.
  252. */
  253. /* ARGSUSED */
  254. static void
  255. CancelSetValues(Widget w, XtPointer junk, XtPointer garbage)
  256. {
  257. XtPopdown(XtParent(XtParent(w)));
  258. }