DtSvc/DtUtil1: fix implicit function declarations
[oweals/cde.git] / cde / lib / DtSvc / DtUtil1 / WmMarquee.c
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  *
54  *  Tt_callback_action _WsSelectionCB (Tt_message m, Tt_pattern p)
55  *
56  *
57  *  Description:
58  *  -----------
59  *  Internal function called for a marquee selection
60  *
61  *
62  *  Inputs:
63  *  ------
64  *  m           - ToolTalk message
65  *  p           - ToolTalk pattern
66  *
67  *  Outputs:
68  *  --------
69  *  Return      - ToolTalk callback status
70  *
71  *  Comments:
72  *  ---------
73  * 
74  *************************************<->***********************************/
75
76 static Tt_callback_action
77 _WsSelectionCB (Tt_message m, Tt_pattern p)
78 {
79     struct _DtWsmCBContext      *pCbCtx;
80     int                         type, val;
81     Position                    x, y;
82     Dimension                   width, height;
83
84     Widget                      widget;
85     DtWsmMarqueeSelectionProc   marquee_selection;
86     XtPointer                   client_data;
87
88     /*
89      * user data 0: Widget              widget;
90      * user data 1: DtWsmWsModifiedProc ws_modify;
91      * user data 2: XtPointer           client_data;
92      */
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);
96
97     /*
98      * 0th arg: screen number, string, not used
99      */
100
101     tt_message_arg_ival(m, 1, &type);   /* type */
102     tt_message_arg_ival(m, 2, &val);    /* x */
103     x = val;
104     tt_message_arg_ival(m, 3, &val);    /* y */
105     y = val;
106     tt_message_arg_ival(m, 4, &val);    /* width */
107     width = val;
108     tt_message_arg_ival(m, 5, &val);    /* height */
109     height = val;
110
111     /*
112      * Call registered callback function.
113      */
114     (*marquee_selection)(widget, type, x, y, width, height, client_data);
115     return TT_CALLBACK_PROCESSED;
116 } /* END OF FUNCTION _DtWsmWsModifyHandler */
117
118 /*************************************<->*************************************
119  *
120  *  DtWsmCBContext * DtWsmAddMarqueeSelectionCallback (widget, 
121  *                                                      marquee_select, 
122  *                                                      client_data)
123  *
124  *
125  *  Description:
126  *  -----------
127  *  Register a function to be called when a marquee selection is made
128  *
129  *
130  *  Inputs:
131  *  ------
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.
135  *
136  *  Outputs:
137  *  --------
138  *  Return      - ptr to callback context data (opaque) 
139  *
140  *  Comments:
141  *  ---------
142  *  The callback context data ptr should be saved if you intend to
143  *  removed this callback at some point in the future. 
144  * 
145  *************************************<->***********************************/
146 DtWsmCBContext 
147 _DtWsmAddMarqueeSelectionCallback (
148         Widget                          widget,
149         DtWsmMarqueeSelectionProc       marquee_selection,
150         XtPointer                       client_data)
151 {
152     struct _DtWsmCBContext *pCbCtx;
153     int         screen;
154     String      sName;
155     char        sNum[32];
156
157     Tt_status   status;
158     Tt_pattern  pattern;
159     char *      sessId;
160
161     /*
162      * This function register a ToolTalk pattern for every
163      * callback added.
164      */
165     _DtSvcInitToolTalk(widget);
166
167     pattern = tt_pattern_create();
168     status = tt_ptr_error(pattern);
169     if (status != TT_OK) {
170         return NULL;
171     }
172
173     if (tt_pattern_category_set(pattern, TT_OBSERVE) != TT_OK) {
174         return NULL;
175     }
176     if (tt_pattern_scope_add(pattern, TT_SESSION) != TT_OK) {
177         return NULL;
178     }
179     sessId = tt_default_session();
180     if (tt_pattern_session_add(pattern, sessId) != TT_OK) {
181         return NULL;
182     }
183     tt_free(sessId);
184
185     screen = XScreenNumberOfScreen(XtScreen(widget));
186     sprintf(sNum, "%d", screen);
187     sName = _DtWsmSelectionNameForScreen (screen);
188
189     /*
190      * Only receive DtMarquee_Selection notice from the screen
191      * we registered with.
192      */
193     status = tt_pattern_arg_add(pattern, TT_IN, Tttk_string, sNum);
194     if (status != TT_OK) {
195         return NULL;
196     }
197
198     if (tt_pattern_op_add(pattern, "DtMarquee_Selection") != TT_OK) {
199         return NULL;
200     }
201
202     if (tt_pattern_state_add(pattern, TT_SENT) != TT_OK) {
203         return NULL;
204     }
205
206     /*
207      * Store information needed by the callback in the user data
208      * fields of the pattern.
209      */
210     status = tt_pattern_user_set(pattern, 0, (void *)widget);
211     if (status != TT_OK) {
212         return NULL;
213     }
214     status = tt_pattern_user_set(pattern, 1, (void *)marquee_selection);
215     if (status != TT_OK) {
216         return NULL;
217     }
218     status = tt_pattern_user_set(pattern, 2, (void *)client_data);
219     if (status != TT_OK) {
220         return NULL;
221     }
222
223     /*
224      * _WsSelectionCB is the ToolTalk callback which will call
225      * the user callback.
226      */
227     if (tt_pattern_callback_add(pattern, _WsSelectionCB) != TT_OK) {
228         return NULL;
229     }
230
231     if (tt_pattern_register(pattern) != TT_OK) {
232         return NULL;
233     }
234
235     /*
236      * Allocate data to remember stuff about this callback
237      */
238     pCbCtx = (struct _DtWsmCBContext * ) 
239                 XtMalloc (sizeof(struct _DtWsmCBContext));
240
241     /* 
242      * Save what we want to remember
243      */
244     pCbCtx->pattern = pattern;
245     pCbCtx->widget = widget;
246     pCbCtx->ws_cb = marquee_selection;
247     pCbCtx->client_data = client_data;
248
249     XtFree (sName);
250
251     return (pCbCtx);
252
253 } /* END OF FUNCTION DtWsmAddMarqueeSelectionCallback */