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 librararies 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>
48 #include <Dt/Service.h>
51 /*************************************<->*************************************
53 * Tt_callback_action _WsSelectionCB (Tt_message m, Tt_pattern p)
58 * Internal function called for a marquee selection
63 * m - ToolTalk message
64 * p - ToolTalk pattern
68 * Return - ToolTalk callback status
73 *************************************<->***********************************/
75 static Tt_callback_action
76 _WsSelectionCB (Tt_message m, Tt_pattern p)
78 struct _DtWsmCBContext *pCbCtx;
81 Dimension width, height;
84 DtWsmMarqueeSelectionProc marquee_selection;
85 XtPointer client_data;
88 * user data 0: Widget widget;
89 * user data 1: DtWsmWsModifiedProc ws_modify;
90 * user data 2: XtPointer client_data;
92 widget = (Widget)tt_pattern_user(p, 0);
93 marquee_selection = (DtWsmMarqueeSelectionProc)tt_pattern_user(p, 1);
94 client_data = (XtPointer)tt_pattern_user(p, 2);
97 * 0th arg: screen number, string, not used
100 tt_message_arg_ival(m, 1, &type); /* type */
101 tt_message_arg_ival(m, 2, &val); /* x */
103 tt_message_arg_ival(m, 3, &val); /* y */
105 tt_message_arg_ival(m, 4, &val); /* width */
107 tt_message_arg_ival(m, 5, &val); /* height */
111 * Call registered callback function.
113 (*marquee_selection)(widget, type, x, y, width, height, client_data);
114 return TT_CALLBACK_PROCESSED;
115 } /* END OF FUNCTION _DtWsmWsModifyHandler */
117 /*************************************<->*************************************
119 * DtWsmCBContext * DtWsmAddMarqueeSelectionCallback (widget,
126 * Register a function to be called when a marquee selection is made
131 * widget - widget for this client
132 * marquee_select - function to call for marquee select
133 * client_data - additional data to pass back to client when called.
137 * Return - ptr to callback context data (opaque)
141 * The callback context data ptr should be saved if you intend to
142 * removed this callback at some point in the future.
144 *************************************<->***********************************/
146 _DtWsmAddMarqueeSelectionCallback (
148 DtWsmMarqueeSelectionProc marquee_selection,
149 XtPointer client_data)
151 struct _DtWsmCBContext *pCbCtx;
161 * This function register a ToolTalk pattern for every
164 _DtSvcInitToolTalk(widget);
166 pattern = tt_pattern_create();
167 status = tt_ptr_error(pattern);
168 if (status != TT_OK) {
172 if (tt_pattern_category_set(pattern, TT_OBSERVE) != TT_OK) {
175 if (tt_pattern_scope_add(pattern, TT_SESSION) != TT_OK) {
178 sessId = tt_default_session();
179 if (tt_pattern_session_add(pattern, sessId) != TT_OK) {
184 screen = XScreenNumberOfScreen(XtScreen(widget));
185 sprintf(sNum, "%d", screen);
186 sName = _DtWsmSelectionNameForScreen (screen);
189 * Only receive DtMarquee_Selection notice from the screen
190 * we registered with.
192 status = tt_pattern_arg_add(pattern, TT_IN, Tttk_string, sNum);
193 if (status != TT_OK) {
197 if (tt_pattern_op_add(pattern, "DtMarquee_Selection") != TT_OK) {
201 if (tt_pattern_state_add(pattern, TT_SENT) != TT_OK) {
206 * Store information needed by the callback in the user data
207 * fields of the pattern.
209 status = tt_pattern_user_set(pattern, 0, (void *)widget);
210 if (status != TT_OK) {
213 status = tt_pattern_user_set(pattern, 1, (void *)marquee_selection);
214 if (status != TT_OK) {
217 status = tt_pattern_user_set(pattern, 2, (void *)client_data);
218 if (status != TT_OK) {
223 * _WsSelectionCB is the ToolTalk callback which will call
226 if (tt_pattern_callback_add(pattern, _WsSelectionCB) != TT_OK) {
230 if (tt_pattern_register(pattern) != TT_OK) {
235 * Allocate data to remember stuff about this callback
237 pCbCtx = (struct _DtWsmCBContext * )
238 XtMalloc (sizeof(struct _DtWsmCBContext));
241 * Save what we want to remember
243 pCbCtx->pattern = pattern;
244 pCbCtx->widget = widget;
245 pCbCtx->ws_cb = marquee_selection;
246 pCbCtx->client_data = client_data;
252 } /* END OF FUNCTION DtWsmAddMarqueeSelectionCallback */