2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /************************************<+>*************************************
24 ****************************************************************************
28 ** RCS: $XConsortium: WmMarquee.c /main/4 1995/10/26 15:12:59 rswiston $
30 ** Project: DT Workspace Manager
32 ** Description: Get Marquee Selection Data
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.
39 ****************************************************************************
40 ************************************<+>*************************************/
43 #include <X11/Xutil.h>
49 #include <Dt/Service.h>
52 /*************************************<->*************************************
54 * Tt_callback_action _WsSelectionCB (Tt_message m, Tt_pattern p)
59 * Internal function called for a marquee selection
64 * m - ToolTalk message
65 * p - ToolTalk pattern
69 * Return - ToolTalk callback status
74 *************************************<->***********************************/
76 static Tt_callback_action
77 _WsSelectionCB (Tt_message m, Tt_pattern p)
79 struct _DtWsmCBContext *pCbCtx;
82 Dimension width, height;
85 DtWsmMarqueeSelectionProc marquee_selection;
86 XtPointer client_data;
89 * user data 0: Widget widget;
90 * user data 1: DtWsmWsModifiedProc ws_modify;
91 * user data 2: XtPointer client_data;
93 widget = (Widget)tt_pattern_user(p, 0);
94 marquee_selection = (DtWsmMarqueeSelectionProc)tt_pattern_user(p, 1);
95 client_data = (XtPointer)tt_pattern_user(p, 2);
98 * 0th arg: screen number, string, not used
101 tt_message_arg_ival(m, 1, &type); /* type */
102 tt_message_arg_ival(m, 2, &val); /* x */
104 tt_message_arg_ival(m, 3, &val); /* y */
106 tt_message_arg_ival(m, 4, &val); /* width */
108 tt_message_arg_ival(m, 5, &val); /* height */
112 * Call registered callback function.
114 (*marquee_selection)(widget, type, x, y, width, height, client_data);
115 return TT_CALLBACK_PROCESSED;
116 } /* END OF FUNCTION _DtWsmWsModifyHandler */
118 /*************************************<->*************************************
120 * DtWsmCBContext * DtWsmAddMarqueeSelectionCallback (widget,
127 * Register a function to be called when a marquee selection is made
132 * widget - widget for this client
133 * marquee_select - function to call for marquee select
134 * client_data - additional data to pass back to client when called.
138 * Return - ptr to callback context data (opaque)
142 * The callback context data ptr should be saved if you intend to
143 * removed this callback at some point in the future.
145 *************************************<->***********************************/
147 _DtWsmAddMarqueeSelectionCallback (
149 DtWsmMarqueeSelectionProc marquee_selection,
150 XtPointer client_data)
152 struct _DtWsmCBContext *pCbCtx;
162 * This function register a ToolTalk pattern for every
165 _DtSvcInitToolTalk(widget);
167 pattern = tt_pattern_create();
168 status = tt_ptr_error(pattern);
169 if (status != TT_OK) {
173 if (tt_pattern_category_set(pattern, TT_OBSERVE) != TT_OK) {
176 if (tt_pattern_scope_add(pattern, TT_SESSION) != TT_OK) {
179 sessId = tt_default_session();
180 if (tt_pattern_session_add(pattern, sessId) != TT_OK) {
185 screen = XScreenNumberOfScreen(XtScreen(widget));
186 sprintf(sNum, "%d", screen);
187 sName = _DtWsmSelectionNameForScreen (screen);
190 * Only receive DtMarquee_Selection notice from the screen
191 * we registered with.
193 status = tt_pattern_arg_add(pattern, TT_IN, Tttk_string, sNum);
194 if (status != TT_OK) {
198 if (tt_pattern_op_add(pattern, "DtMarquee_Selection") != TT_OK) {
202 if (tt_pattern_state_add(pattern, TT_SENT) != TT_OK) {
207 * Store information needed by the callback in the user data
208 * fields of the pattern.
210 status = tt_pattern_user_set(pattern, 0, (void *)widget);
211 if (status != TT_OK) {
214 status = tt_pattern_user_set(pattern, 1, (void *)marquee_selection);
215 if (status != TT_OK) {
218 status = tt_pattern_user_set(pattern, 2, (void *)client_data);
219 if (status != TT_OK) {
224 * _WsSelectionCB is the ToolTalk callback which will call
227 if (tt_pattern_callback_add(pattern, _WsSelectionCB) != TT_OK) {
231 if (tt_pattern_register(pattern) != TT_OK) {
236 * Allocate data to remember stuff about this callback
238 pCbCtx = (struct _DtWsmCBContext * )
239 XtMalloc (sizeof(struct _DtWsmCBContext));
242 * Save what we want to remember
244 pCbCtx->pattern = pattern;
245 pCbCtx->widget = widget;
246 pCbCtx->ws_cb = marquee_selection;
247 pCbCtx->client_data = client_data;
253 } /* END OF FUNCTION DtWsmAddMarqueeSelectionCallback */