WmMarquee.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. /************************************<+>*************************************
  24. ****************************************************************************
  25. **
  26. ** File: WmMarquee.c
  27. **
  28. ** RCS: $XConsortium: WmMarquee.c /main/4 1995/10/26 15:12:59 rswiston $
  29. **
  30. ** Project: DT Workspace Manager
  31. **
  32. ** Description: Get Marquee Selection Data
  33. **
  34. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  35. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  36. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  37. ** (c) Copyright 1993, 1994 Novell, Inc.
  38. **
  39. ****************************************************************************
  40. ************************************<+>*************************************/
  41. #include <stdio.h>
  42. #include <X11/Xlib.h>
  43. #include <X11/Xutil.h>
  44. #include <Tt/tttk.h>
  45. #include <Dt/Wsm.h>
  46. #include <Dt/WsmM.h>
  47. #include <Dt/SvcTT.h>
  48. #include "WsmP.h"
  49. #include <Dt/Service.h>
  50. #include <Xm/Xm.h>
  51. /*************************************<->*************************************
  52. *
  53. * Tt_callback_action _WsSelectionCB (Tt_message m, Tt_pattern p)
  54. *
  55. *
  56. * Description:
  57. * -----------
  58. * Internal function called for a marquee selection
  59. *
  60. *
  61. * Inputs:
  62. * ------
  63. * m - ToolTalk message
  64. * p - ToolTalk pattern
  65. *
  66. * Outputs:
  67. * --------
  68. * Return - ToolTalk callback status
  69. *
  70. * Comments:
  71. * ---------
  72. *
  73. *************************************<->***********************************/
  74. static Tt_callback_action
  75. _WsSelectionCB (Tt_message m, Tt_pattern p)
  76. {
  77. struct _DtWsmCBContext *pCbCtx;
  78. int type, val;
  79. Position x, y;
  80. Dimension width, height;
  81. Widget widget;
  82. DtWsmMarqueeSelectionProc marquee_selection;
  83. XtPointer client_data;
  84. /*
  85. * user data 0: Widget widget;
  86. * user data 1: DtWsmWsModifiedProc ws_modify;
  87. * user data 2: XtPointer client_data;
  88. */
  89. widget = (Widget)tt_pattern_user(p, 0);
  90. marquee_selection = (DtWsmMarqueeSelectionProc)tt_pattern_user(p, 1);
  91. client_data = (XtPointer)tt_pattern_user(p, 2);
  92. /*
  93. * 0th arg: screen number, string, not used
  94. */
  95. tt_message_arg_ival(m, 1, &type); /* type */
  96. tt_message_arg_ival(m, 2, &val); /* x */
  97. x = val;
  98. tt_message_arg_ival(m, 3, &val); /* y */
  99. y = val;
  100. tt_message_arg_ival(m, 4, &val); /* width */
  101. width = val;
  102. tt_message_arg_ival(m, 5, &val); /* height */
  103. height = val;
  104. /*
  105. * Call registered callback function.
  106. */
  107. (*marquee_selection)(widget, type, x, y, width, height, client_data);
  108. return TT_CALLBACK_PROCESSED;
  109. } /* END OF FUNCTION _DtWsmWsModifyHandler */
  110. /*************************************<->*************************************
  111. *
  112. * DtWsmCBContext * DtWsmAddMarqueeSelectionCallback (widget,
  113. * marquee_select,
  114. * client_data)
  115. *
  116. *
  117. * Description:
  118. * -----------
  119. * Register a function to be called when a marquee selection is made
  120. *
  121. *
  122. * Inputs:
  123. * ------
  124. * widget - widget for this client
  125. * marquee_select - function to call for marquee select
  126. * client_data - additional data to pass back to client when called.
  127. *
  128. * Outputs:
  129. * --------
  130. * Return - ptr to callback context data (opaque)
  131. *
  132. * Comments:
  133. * ---------
  134. * The callback context data ptr should be saved if you intend to
  135. * removed this callback at some point in the future.
  136. *
  137. *************************************<->***********************************/
  138. DtWsmCBContext
  139. _DtWsmAddMarqueeSelectionCallback (
  140. Widget widget,
  141. DtWsmMarqueeSelectionProc marquee_selection,
  142. XtPointer client_data)
  143. {
  144. struct _DtWsmCBContext *pCbCtx;
  145. int screen;
  146. String sName;
  147. char sNum[32];
  148. Tt_status status;
  149. Tt_pattern pattern;
  150. char * sessId;
  151. /*
  152. * This function register a ToolTalk pattern for every
  153. * callback added.
  154. */
  155. _DtSvcInitToolTalk(widget);
  156. pattern = tt_pattern_create();
  157. status = tt_ptr_error(pattern);
  158. if (status != TT_OK) {
  159. return NULL;
  160. }
  161. if (tt_pattern_category_set(pattern, TT_OBSERVE) != TT_OK) {
  162. return NULL;
  163. }
  164. if (tt_pattern_scope_add(pattern, TT_SESSION) != TT_OK) {
  165. return NULL;
  166. }
  167. sessId = tt_default_session();
  168. if (tt_pattern_session_add(pattern, sessId) != TT_OK) {
  169. return NULL;
  170. }
  171. tt_free(sessId);
  172. screen = XScreenNumberOfScreen(XtScreen(widget));
  173. sprintf(sNum, "%d", screen);
  174. sName = _DtWsmSelectionNameForScreen (screen);
  175. /*
  176. * Only receive DtMarquee_Selection notice from the screen
  177. * we registered with.
  178. */
  179. status = tt_pattern_arg_add(pattern, TT_IN, Tttk_string, sNum);
  180. if (status != TT_OK) {
  181. return NULL;
  182. }
  183. if (tt_pattern_op_add(pattern, "DtMarquee_Selection") != TT_OK) {
  184. return NULL;
  185. }
  186. if (tt_pattern_state_add(pattern, TT_SENT) != TT_OK) {
  187. return NULL;
  188. }
  189. /*
  190. * Store information needed by the callback in the user data
  191. * fields of the pattern.
  192. */
  193. status = tt_pattern_user_set(pattern, 0, (void *)widget);
  194. if (status != TT_OK) {
  195. return NULL;
  196. }
  197. status = tt_pattern_user_set(pattern, 1, (void *)marquee_selection);
  198. if (status != TT_OK) {
  199. return NULL;
  200. }
  201. status = tt_pattern_user_set(pattern, 2, (void *)client_data);
  202. if (status != TT_OK) {
  203. return NULL;
  204. }
  205. /*
  206. * _WsSelectionCB is the ToolTalk callback which will call
  207. * the user callback.
  208. */
  209. if (tt_pattern_callback_add(pattern, _WsSelectionCB) != TT_OK) {
  210. return NULL;
  211. }
  212. if (tt_pattern_register(pattern) != TT_OK) {
  213. return NULL;
  214. }
  215. /*
  216. * Allocate data to remember stuff about this callback
  217. */
  218. pCbCtx = (struct _DtWsmCBContext * )
  219. XtMalloc (sizeof(struct _DtWsmCBContext));
  220. /*
  221. * Save what we want to remember
  222. */
  223. pCbCtx->pattern = pattern;
  224. pCbCtx->widget = widget;
  225. pCbCtx->ws_cb = marquee_selection;
  226. pCbCtx->client_data = client_data;
  227. XtFree (sName);
  228. return (pCbCtx);
  229. } /* END OF FUNCTION DtWsmAddMarqueeSelectionCallback */