PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/xts5/Xt9/XtGrabKey.m

#
Objective C | 353 lines | 329 code | 14 blank | 10 comment | 23 complexity | 6aa652c1daafb148809ff043996f6dd1 MD5 | raw file
  1. Copyright (c) 2005 X.Org Foundation LLC
  2. Permission is hereby granted, free of charge, to any person obtaining a copy of
  3. this software and associated documentation files (the "Software"), to deal in
  4. the Software without restriction, including without limitation the rights to
  5. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  6. of the Software, and to permit persons to whom the Software is furnished to do
  7. so, subject to the following conditions:
  8. The above copyright notice and this permission notice shall be included in all
  9. copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. SOFTWARE.
  17. Copyright (c) Applied Testing and Technology, Inc. 1993, 1994, 1995
  18. Copyright (c) 88open Consortium, Ltd. 1990, 1991, 1992, 1993
  19. All Rights Reserved.
  20. >>#
  21. >># Project: VSW5
  22. >>#
  23. >># File: xts/Xt9/XtGrabKey.m
  24. >>#
  25. >># Description:
  26. >># Tests for XtGrabKey()
  27. >>#
  28. >># Modifications:
  29. >># $Log: tgrabkey.m,v $
  30. >># Revision 1.1 2005-02-12 14:38:24 anderson
  31. >># Initial revision
  32. >>#
  33. >># Revision 8.0 1998/12/23 23:37:00 mar
  34. >># Branch point for Release 5.0.2
  35. >>#
  36. >># Revision 7.1 1998/11/20 23:36:32 mar
  37. >># req.4.W.00130: use a valid keysym instead of zero (min is 8)
  38. >>#
  39. >># Revision 7.0 1998/10/30 22:59:54 mar
  40. >># Branch point for Release 5.0.2b1
  41. >>#
  42. >># Revision 6.0 1998/03/02 05:28:07 tbr
  43. >># Branch point for Release 5.0.1
  44. >>#
  45. >># Revision 5.0 1998/01/26 03:24:41 tbr
  46. >># Branch point for Release 5.0.1b1
  47. >>#
  48. >># Revision 4.0 1995/12/15 09:18:10 tbr
  49. >># Branch point for Release 5.0.0
  50. >>#
  51. >># Revision 3.1 1995/12/15 02:11:22 andy
  52. >># Prepare for GA Release
  53. >>#
  54. >>EXTERN
  55. #include <X11/IntrinsicP.h>
  56. #include <X11/ConstrainP.h>
  57. #include <X11/CoreP.h>
  58. #ifdef XTESTEXTENSION
  59. #include <X11/extensions/XTest.h>
  60. #endif
  61. XtAppContext app_ctext;
  62. Widget topLevel, panedw, boxw1, boxw2;
  63. Widget labelw, rowcolw, click_quit;
  64. XKeyboardControl kbvalues;
  65. Widget topLevel;
  66. Widget panedw, boxw1, boxw2;
  67. Widget labelw, click_pass, click_fail;
  68. char label[80];
  69. Widget labelw_msg;
  70. #ifdef XTESTEXTENSION
  71. /*
  72. ** procedure XtTMO_Proc
  73. */
  74. void XtTMO_Proc2(client_data, id)
  75. XtPointer client_data;
  76. XtIntervalId *id;
  77. {
  78. XEvent event;
  79. /*fake user input to get autorepeat back*/
  80. event.xkey.type = KeyRelease;
  81. event.xkey.display = XtDisplay(labelw_msg);
  82. event.xkey.window = XtWindow(labelw_msg);
  83. event.xkey.x = -1;
  84. XSelectInput( XtDisplay(topLevel), XtWindow(labelw_msg), KeyReleaseMask);
  85. XSendEvent(XtDisplay(labelw_msg), XtWindow(labelw_msg), False, KeyReleaseMask, &event);
  86. tet_infoline("ERROR: Timed out waiting for input");
  87. tet_result(TET_UNRESOLVED);
  88. }
  89. /*
  90. ** procedure XtTMO_Proc
  91. */
  92. void XtTMO_Proc(client_data, id)
  93. XtPointer client_data;
  94. XtIntervalId *id;
  95. {
  96. Position rootx, rooty;
  97. XtAppAddTimeOut(app_ctext, (unsigned long)2000, XtTMO_Proc2, topLevel);
  98. tet_infoline("PREP: Send KeyRelease outside grab widget");
  99. XtTranslateCoords(labelw_msg, 0,0,&rootx, &rooty);
  100. XTestFakeMotionEvent(XtDisplay(labelw_msg), -1, rootx+10, rooty+10, CurrentTime);
  101. XTestFakeKeyEvent(XtDisplay(labelw_msg), XKeysymToKeycode(XtDisplay(labelw_msg), 32), True, CurrentTime);
  102. XTestFakeMotionEvent(XtDisplay(labelw_msg), -1, rootx-100, rooty, CurrentTime);
  103. XTestFakeKeyEvent(XtDisplay(labelw_msg), XKeysymToKeycode(XtDisplay(labelw_msg), 32), False, CurrentTime);
  104. }
  105. static void analyse_events(TestWidget)
  106. Widget TestWidget;
  107. {
  108. XtPointer client_data, call_data;
  109. XtAppContext app_context;
  110. Display *display;
  111. XEvent event;
  112. Window window;
  113. int eflag = 3;
  114. app_context = XtWidgetToApplicationContext(TestWidget);
  115. display = XtDisplay(TestWidget);
  116. window = XtWindow(TestWidget);
  117. for (;;) {
  118. XtAppNextEvent(app_context, &event);
  119. if (eflag < 3)
  120. eflag--;
  121. if (event.type == KeyRelease) {
  122. tet_infoline("TEST: KeyRelease sent to proper place");
  123. if (event.xkey.window != window) {
  124. sprintf(ebuf, "ERROR: Key did not go to correct widget");
  125. tet_infoline(ebuf);
  126. tet_result(TET_FAIL);
  127. eflag = 2;
  128. kbvalues.auto_repeat_mode = AutoRepeatModeOn;
  129. XChangeKeyboardControl(XtDisplay(topLevel), KBAutoRepeatMode, &kbvalues);
  130. /*this hack seems to be necessary to get the kbd control to take*/
  131. send_event(topLevel, FocusIn, FocusChangeMask, TRUE);
  132. send_event(topLevel, FocusOut, FocusChangeMask, TRUE);
  133. }
  134. if (event.xkey.x >= 0) {
  135. sprintf(ebuf, "ERROR: KeyRelease was not left of window");
  136. tet_infoline(ebuf);
  137. tet_result(TET_FAIL);
  138. eflag = 2;
  139. kbvalues.auto_repeat_mode = AutoRepeatModeOn;
  140. XChangeKeyboardControl(XtDisplay(topLevel), KBAutoRepeatMode, &kbvalues);
  141. /*this hack seems to be necessary to get the kbd control to take*/
  142. send_event(topLevel, FocusIn, FocusChangeMask, TRUE);
  143. send_event(topLevel, FocusOut, FocusChangeMask, TRUE);
  144. }
  145. else {
  146. tet_result(TET_PASS);
  147. kbvalues.auto_repeat_mode = AutoRepeatModeOn;
  148. XChangeKeyboardControl(XtDisplay(topLevel), KBAutoRepeatMode, &kbvalues);
  149. /*this hack seems to be necessary to get the kbd control to take*/
  150. send_event(topLevel, FocusIn, FocusChangeMask, TRUE);
  151. send_event(topLevel, FocusOut, FocusChangeMask, TRUE);
  152. eflag = 2;
  153. }
  154. } /*end if release*/
  155. XtDispatchEvent(&event);
  156. if (eflag == 0)
  157. exit(0);
  158. } /* end for*/
  159. }
  160. #endif
  161. >>TITLE XtGrabKey Xt9
  162. void
  163. XtGrabKey(widget, keycode, modifiers, owner_events pointer_mode, keyboard_mode)
  164. >>ASSERTION Good A
  165. When the widget
  166. .A widget
  167. is realized a successful call to
  168. void XtGrabKey(widget, keycode, modifiers, owner_events,
  169. pointer_mode, keyboard_mode)
  170. shall call XGrabKey to establish a passive key grab
  171. for the widget
  172. .A widget.
  173. >>CODE
  174. int status;
  175. char *msg = "This is the grab widget\n";
  176. pid_t pid2;
  177. #ifdef XTESTEXTENSION
  178. FORK(pid2);
  179. xt_tomultiple = 3;
  180. tet_infoline("PREP: Initialize toolkit, Open display and Create topLevel root widget");
  181. topLevel = (Widget) avs_xt_init("Tgrabkey1", NULL, 0);
  182. tet_infoline("PREP: Disable autorepeat (which would break this test)");
  183. kbvalues.auto_repeat_mode = AutoRepeatModeOff;
  184. XChangeKeyboardControl(XtDisplay(topLevel), KBAutoRepeatMode, &kbvalues);
  185. tet_infoline("PREP: Set up the XtToolkitError handler");
  186. app_ctext = XtWidgetToApplicationContext(topLevel);
  187. XtAppSetErrorMsgHandler(app_ctext, xt_handler);
  188. tet_infoline("PREP: Set up widget tree of depth eight (8) return panedw widget");
  189. panedw = (Widget) avs_xt_tree(topLevel);
  190. tet_infoline("PREP: Create boxw1 widget in panedw widget");
  191. boxw1 = (Widget) CreateBoxWidget(panedw);
  192. tet_infoline("PREP: Get the label widget name");
  193. strcpy(label, (char *)title("XtGrabKey") );
  194. sprintf(ebuf, "PREP: Create label: %s in boxw1 widget", label);
  195. tet_infoline(ebuf);
  196. labelw = (Widget) CreateLabelWidget(label, boxw1);
  197. tet_infoline("PREP: Create boxw2 widget in panedw widget");
  198. boxw2 = (Widget) CreateBoxWidget(panedw);
  199. tet_infoline("PREP: Set height and width of boxw2 widget");
  200. ConfigureDimension(topLevel, boxw2);
  201. labelw_msg = (Widget) CreateLabelWidget(msg, boxw1);
  202. tet_infoline("PREP: Create windows for widgets and map them");
  203. XtRealizeWidget(topLevel);
  204. tet_infoline("PREP: Establish passive grab with XtGrabKey");
  205. XtGrabKey(labelw_msg, AnyKey, AnyModifier, FALSE, GrabModeAsync, GrabModeAsync);
  206. XtAppAddTimeOut(app_ctext, (unsigned long)500, XtTMO_Proc, topLevel);
  207. analyse_events(labelw_msg);
  208. LKROF(pid2, (AVSXTTIMEOUT-2)*xt_tomultiple);
  209. #else
  210. tet_infoline("INFO: XTEST extension not configured");
  211. tet_result(TET_UNSUPPORTED);
  212. #endif
  213. >>ASSERTION Good A
  214. When the widget
  215. .A widget
  216. is not realized a successful call to
  217. void XtGrabKey(widget, keycode, modifiers, owner_events pointer_mode,
  218. keyboard_mode)
  219. shall cause XGrabKey to be called to establish a passive key grab
  220. for the specified widget when it is realized.
  221. >>CODE
  222. int status;
  223. char *msg = "This is the grab widget\n";
  224. pid_t pid2;
  225. #ifdef XTESTEXTENSION
  226. FORK(pid2);
  227. xt_tomultiple = 3;
  228. tet_infoline("PREP: Initialize toolkit, Open display and Create topLevel root widget");
  229. topLevel = (Widget) avs_xt_init("Tgrabkey2", NULL, 0);
  230. tet_infoline("PREP: Disable autorepeat (which would break this test)");
  231. kbvalues.auto_repeat_mode = AutoRepeatModeOff;
  232. XChangeKeyboardControl(XtDisplay(topLevel), KBAutoRepeatMode, &kbvalues);
  233. tet_infoline("PREP: Set up the XtToolkitError handler");
  234. app_ctext = XtWidgetToApplicationContext(topLevel);
  235. XtAppSetErrorMsgHandler(app_ctext, xt_handler);
  236. tet_infoline("PREP: Set up widget tree of depth eight (8) return panedw widget");
  237. panedw = (Widget) avs_xt_tree(topLevel);
  238. tet_infoline("PREP: Create boxw1 widget in panedw widget");
  239. boxw1 = (Widget) CreateBoxWidget(panedw);
  240. tet_infoline("PREP: Get the label widget name");
  241. strcpy(label, (char *)title("XtGrabKey") );
  242. sprintf(ebuf, "PREP: Create label: %s in boxw1 widget", label);
  243. tet_infoline(ebuf);
  244. labelw = (Widget) CreateLabelWidget(label, boxw1);
  245. tet_infoline("PREP: Create boxw2 widget in panedw widget");
  246. boxw2 = (Widget) CreateBoxWidget(panedw);
  247. tet_infoline("PREP: Set height and width of boxw2 widget");
  248. ConfigureDimension(topLevel, boxw2);
  249. labelw_msg = (Widget) CreateLabelWidget(msg, boxw1);
  250. tet_infoline("PREP: Establish passive grab with XtGrabKey");
  251. XtGrabKey(labelw_msg, AnyKey, AnyModifier, FALSE, GrabModeAsync, GrabModeAsync);
  252. XtAppAddTimeOut(app_ctext, (unsigned long)500, XtTMO_Proc, topLevel);
  253. tet_infoline("PREP: Create windows for widgets and map them");
  254. XtRealizeWidget(topLevel);
  255. analyse_events(labelw_msg);
  256. LKROF(pid2, (AVSXTTIMEOUT-2)*xt_tomultiple);
  257. #else
  258. tet_infoline("INFO: XTEST extension not configured");
  259. tet_result(TET_UNSUPPORTED);
  260. #endif
  261. >>ASSERTION Good A
  262. When the widget
  263. .A widget
  264. is realized a successful call to
  265. void XtGrabKey(widget, keycode, modifiers, owner_events pointer_mode,
  266. keyboard_mode)
  267. shall cause XGrabKey to be called to establish a passive key grab
  268. for the specified widget when the widget is next realized
  269. following an unrealize action on the widget.
  270. >>CODE
  271. int status;
  272. char *msg = "This is the grab widget\n";
  273. pid_t pid2;
  274. #ifdef XTESTEXTENSION
  275. FORK(pid2);
  276. xt_tomultiple = 3;
  277. tet_infoline("PREP: Initialize toolkit, Open display and Create topLevel root widget");
  278. topLevel = (Widget) avs_xt_init("Tgrabkey3", NULL, 0);
  279. tet_infoline("PREP: Disable autorepeat (which would break this test)");
  280. kbvalues.auto_repeat_mode = AutoRepeatModeOff;
  281. XChangeKeyboardControl(XtDisplay(topLevel), KBAutoRepeatMode, &kbvalues);
  282. tet_infoline("PREP: Set up the XtToolkitError handler");
  283. app_ctext = XtWidgetToApplicationContext(topLevel);
  284. XtAppSetErrorMsgHandler(app_ctext, xt_handler);
  285. tet_infoline("PREP: Set up widget tree of depth eight (8) return panedw widget");
  286. panedw = (Widget) avs_xt_tree(topLevel);
  287. tet_infoline("PREP: Create boxw1 widget in panedw widget");
  288. boxw1 = (Widget) CreateBoxWidget(panedw);
  289. tet_infoline("PREP: Get the label widget name");
  290. strcpy(label, (char *)title("XtGrabKey") );
  291. sprintf(ebuf, "PREP: Create label: %s in boxw1 widget", label);
  292. tet_infoline(ebuf);
  293. labelw = (Widget) CreateLabelWidget(label, boxw1);
  294. tet_infoline("PREP: Create boxw2 widget in panedw widget");
  295. boxw2 = (Widget) CreateBoxWidget(panedw);
  296. tet_infoline("PREP: Set height and width of boxw2 widget");
  297. ConfigureDimension(topLevel, boxw2);
  298. labelw_msg = (Widget) CreateLabelWidget(msg, boxw1);
  299. tet_infoline("PREP: Create windows for widgets and map them");
  300. XtRealizeWidget(topLevel);
  301. tet_infoline("PREP: Establish passive grab with XtGrabKey");
  302. XtGrabKey(labelw_msg, AnyKey, AnyModifier, FALSE, GrabModeAsync, GrabModeAsync);
  303. tet_infoline("PREP: Unrealize grab widget");
  304. XtRealizeWidget(labelw_msg);
  305. tet_infoline("PREP: Realize grab widget");
  306. XtRealizeWidget(labelw_msg);
  307. XtAppAddTimeOut(app_ctext, (unsigned long)500, XtTMO_Proc, topLevel);
  308. analyse_events(labelw_msg);
  309. LKROF(pid2, (AVSXTTIMEOUT-2)*xt_tomultiple);
  310. #else
  311. tet_infoline("INFO: XTEST extension not configured");
  312. tet_result(TET_UNSUPPORTED);
  313. #endif
  314. >>ASSERTION Good B 0
  315. After a passive key grab is established for the widget
  316. .A widget
  317. by a call to
  318. void XtGrabKey(widget, keycode, modifiers, owner_events pointer_mode,
  319. keyboard_mode)
  320. when an event matching
  321. .A keycode
  322. and
  323. .A modifiers
  324. occurs in the specified widget, a modal cascade exists,
  325. and the widget is not in the active subset of the modal
  326. cascade the grab shall not be performed.
  327. >>ASSERTION Good D 0
  328. If the implementation is X11R5 or later:
  329. After a passive key grab is established for the widget
  330. .A widget
  331. by a call to
  332. void XtGrabKey(widget, keycode, modifiers, owner_events pointer_mode,
  333. keyboard_mode)
  334. when an event matching
  335. .A keycode
  336. and
  337. .A modifiers
  338. occurs in the specified widget and an input method exists
  339. for the widget the grab shall not be performed.