~ubuntu-branches/ubuntu/quantal/openmotif/quantal

« back to all changes in this revision

Viewing changes to demos/lib/Wsm/send.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bauer
  • Date: 2010-06-23 12:12:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100623121231-u89gxdp51sg9wjj2
Tags: 2.3.0-1
* New Maintainer (Closes: #379258) 
* Acknowledge NMU changes
* New upstream release (Closes: #494375)
* Get rid of security patches as they are already part of new upstream
  release (00-xpmvuln.openmotif.patch, 342092-CVE-2005-3964.patch)
* Bump Standards to 3.8.4
* Added {misc:Depends} to make the package lintian cleaner
* Fix weak-library-dev-dependency by adding ${binary:Version}) for the
  -dev Package of openmotif
* Let package depend on autotools-dev to use newer autotools-helper-files
* Work around an autoconf-bug (Gentoo-Bug #1475)
* Added Client-side anti-aliased fonts support via XFT
* Added UTF-8 and UTF8_STRING atom support
* Ability to show text and pixmaps in Label, LabelGadget and all
  derived widgets
* Support of PNG/JPEG image formats in the same way as XPM is supported
* Increase FILE_OFFSET_BITS to 64 to show files >2GB in file-selector
  Idea taken from Magne Oestlyngen (Closes: #288537)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XConsortium: send.c /main/5 1995/07/15 20:42:54 drk $ */
 
2
/*
 
3
 * @OPENGROUP_COPYRIGHT@
 
4
 * COPYRIGHT NOTICE
 
5
 * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
 
6
 * Copyright (c) 1996, 1997, 1998, 1999, 2000 The Open Group
 
7
 * ALL RIGHTS RESERVED (MOTIF).  See the file named COPYRIGHT.MOTIF for
 
8
 * the full copyright text.
 
9
 * 
 
10
 * This software is subject to an open license. It may only be
 
11
 * used on, with or for operating systems which are themselves open
 
12
 * source systems. You must contact The Open Group for a license
 
13
 * allowing distribution and sublicensing of this software on, with,
 
14
 * or for operating systems which are not Open Source programs.
 
15
 * 
 
16
 * See http://www.opengroup.org/openmotif/license for full
 
17
 * details of the license agreement. Any use, reproduction, or
 
18
 * distribution of the program constitutes recipient's acceptance of
 
19
 * this agreement.
 
20
 * 
 
21
 * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
 
22
 * PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
23
 * KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
 
24
 * WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
 
25
 * OR FITNESS FOR A PARTICULAR PURPOSE
 
26
 * 
 
27
 * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
 
28
 * NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT,
 
29
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
30
 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED
 
31
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
33
 * ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
 
34
 * EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
 
35
 * POSSIBILITY OF SUCH DAMAGES.
 
36
 * 
 
37
 */
 
38
/*
 
39
 * HISTORY
 
40
 */
 
41
 
 
42
#include <Xm/Transfer.h>
 
43
#include "wsm_proto.h"
 
44
#include "utm_send.h"
 
45
 
 
46
typedef struct _RequestInfo {
 
47
    WSMReplyCallbackFunc reply_callback; /* The reply callback func */
 
48
    XtPointer reply_data;       /* The user data for the callback func */
 
49
    WSMRequestType request_type; /* The kind of request for cross check. */
 
50
    Atom send_atom;             /* The atom that we sent this message to. */
 
51
} RequestInfo;
 
52
 
 
53
static void UTMReplyReceived(
 
54
Widget, XtPointer, XtPointer
 
55
);
 
56
 
 
57
static void ReplyReceived(
 
58
Widget, XtPointer, Atom *, Atom *, XtPointer, unsigned long *, int *
 
59
);
 
60
 
 
61
static UTMPackageRec *_WSMBuildUtmPackage(
 
62
Atom, int, unsigned long, XtPointer, XtPointer
 
63
);
 
64
 
 
65
/*      Function Name: WSMSendMessage
 
66
 *      Description: Sends a message to WSM or WM on the screen
 
67
 *                   and display specified.
 
68
 *      Arguments: w - any widget on this display and screen that
 
69
 *                     also has destination callback.
 
70
 *                     Note - This widget MUST have the destination
 
71
 *                            callback set to UTMDestinationProc that
 
72
 *                            is defined in utm_send.c.
 
73
 *                 send_to - either WSMWorkspaceManager or WSMWindowManager
 
74
 *                 request - the request to send.
 
75
 *                 reply_callback - The routine to call when the
 
76
 *                                  reply comes in.
 
77
 *                 reply_data - Client data passed to the reply_callback.
 
78
 *      Returns: True if an attempt is made to retrieve the selection,
 
79
 *               False if an obvious error occured.
 
80
 * 
 
81
 * NOTE: Reply callback will be called with reply == NULL if unable
 
82
 *       to convert request.
 
83
 */
 
84
 
 
85
Boolean
 
86
WSMSendMessage(Widget w, WSMClientType send_to, WSMRequest *request, 
 
87
               WSMReplyCallbackFunc reply_callback, XtPointer reply_data)
 
88
{
 
89
    int screen_num = XScreenNumberOfScreen(XtScreen(w));
 
90
    Display *dpy = XtDisplay(w);
 
91
    Atom send_atom = _WSMGetSelectionAtom(dpy, screen_num, send_to);
 
92
    MessageData msg_data;
 
93
    unsigned long msg_len;
 
94
    RequestInfo *req_info;
 
95
    WSMErrorCode error;
 
96
    UTMPackageRec *pUtmData;
 
97
    Time time = GetTimestamp(dpy); /* 0 or CurrentTime not allowed. */
 
98
 
 
99
    if (send_atom == None) {
 
100
        fprintf(stderr, "%s: Could not get selection atom to send message\n",
 
101
                "Internal Error");
 
102
        return(False);
 
103
    }
 
104
 
 
105
    /*
 
106
     * Package human-readable request data into protocol package.
 
107
     */
 
108
    msg_data = _WSMPackRequest(dpy, screen_num, request, &msg_len, &error);
 
109
    if (msg_data == NULL) {
 
110
        (*reply_callback)(w, reply_data, NULL, error);
 
111
        return(False);
 
112
    }
 
113
 
 
114
    req_info = (RequestInfo *) XtMalloc(sizeof(RequestInfo));
 
115
    req_info->reply_callback = reply_callback;  /* The reply callback func */
 
116
    req_info->reply_data = reply_data;  /* user data for the callback func */
 
117
    req_info->request_type = request->any.type;/*request kind for cross check*/
 
118
    req_info->send_atom = send_atom;    /* Atom we sent this message to. */
 
119
 
 
120
    if (!XtIsRealized(w)) {
 
121
        fprintf(stderr, "%s WSMSendMessage must be realized, and is not.\n",
 
122
                "Programmer Error: Widget passed to");
 
123
        return(False);
 
124
    }
 
125
 
 
126
    UTMSendMessage(w,
 
127
                   send_atom,
 
128
                   _WSMReqTypeToTarget(dpy, request->any.type),
 
129
                   (XtPointer) msg_data, msg_len, WSM_PROTO_FMT,
 
130
                   UTMReplyReceived, req_info,
 
131
                   time);
 
132
    return(True);
 
133
}
 
134
 
 
135
 
 
136
/************************************************************
 
137
 *
 
138
 *  Internal Routines.
 
139
 *
 
140
 ************************************************************/
 
141
 
 
142
 
 
143
/*      Function Name: UTMReplyReceived
 
144
 *      Description: Called after the selection owner's convert proc
 
145
 *                   has finished.
 
146
 *      Arguments: w - The widget who initiated the request.
 
147
 *                 clientData - 
 
148
 *                 callData - 
 
149
 *      Returns: none
 
150
 */
 
151
static void
 
152
UTMReplyReceived(Widget w, XtPointer clientData, XtPointer callData)
 
153
{
 
154
  XmSelectionCallbackStruct *scs = (XmSelectionCallbackStruct *) callData;
 
155
  RequestInfo *req_info = (RequestInfo *) clientData;
 
156
  Boolean errorFound = False;
 
157
  Atom type = _WSMReqTypeToTarget(XtDisplay(w), req_info->request_type);
 
158
 
 
159
  /* Let's check some other values just to make sure things are ok. */
 
160
  if (scs->reason != XmCR_OK) {
 
161
    fprintf(stderr, "ERROR: Bad reason value received in UTMReplyReceived.\n");
 
162
    errorFound = True;
 
163
  }
 
164
  if (scs->type == XT_CONVERT_FAIL) {
 
165
    fprintf(stderr, "ERROR: Convert failure detected in UTMReplyReceived.\n");
 
166
    errorFound = True;
 
167
  }
 
168
  if (scs->flags != XmSELECTION_DEFAULT) {
 
169
    fprintf(stderr, "ERROR: Bad flags value received in UTMReplyReceived.\n");
 
170
    errorFound = True;
 
171
  }
 
172
  if (errorFound)
 
173
    return;
 
174
 
 
175
  ReplyReceived(w,
 
176
                req_info, /* the request info pointer to fill in. */
 
177
                &scs->selection,
 
178
                &type,  /* type of request that was made. */
 
179
                scs->value, /* data returned from conversion. */
 
180
                &scs->length,
 
181
                &scs->format);
 
182
}
 
183
 
 
184
 
 
185
/*      Function Name: ReplyReceived
 
186
 *      Description: Called when a reply is received from a request
 
187
 *                   initiated by a WSMSendMessage.
 
188
 *      Arguments: w - The widget who initiated the request.
 
189
 *                 req_info_ptr - pointer to the request info.
 
190
 *                 selection - The selection that has been converted.
 
191
 *                 req_type_atom - The type of request that was made.
 
192
 *                 length - the amount of message data.
 
193
 *                 format - the format of the reply.
 
194
 *      Returns: none
 
195
 */
 
196
static void
 
197
ReplyReceived(Widget w, XtPointer req_info_ptr,
 
198
              Atom *selection, Atom *req_type_atom,
 
199
              XtPointer value, unsigned long *length, int *format)
 
200
{
 
201
    RequestInfo *req_info = (RequestInfo *) req_info_ptr;
 
202
    WSMReply reply;
 
203
    Display *dpy = XtDisplay(w);
 
204
    int screen_num;
 
205
    WSMErrorCode fail_code = WSM_SUCCESS;
 
206
 
 
207
    /*
 
208
     * First a few checks to make sure everything is as we expect.
 
209
     */
 
210
 
 
211
    if (*selection != req_info->send_atom) {
 
212
        fprintf(stderr, "%s, request %d - reply %d\n",
 
213
               "Selection of the reply is not the same as the request",
 
214
               (int) req_info->send_atom, (int) *selection);
 
215
 
 
216
            fail_code = WSM_ERROR_INTERNAL;
 
217
    }
 
218
    if (*req_type_atom != _WSMReqTypeToTarget(dpy, req_info->request_type)) {
 
219
        if (*req_type_atom == None) {
 
220
            if (XGetSelectionOwner(dpy, *selection) == None)
 
221
              {
 
222
                fail_code = WSM_ERROR_NO_SEL_OWNER;
 
223
                printf("No owner for selection #%d\n", (int)*selection);
 
224
              }
 
225
            else
 
226
                fail_code = WSM_ERROR_CONVERSION_FAILED;
 
227
        }
 
228
        else if (*req_type_atom == XT_CONVERT_FAIL)
 
229
            fail_code = WSM_ERROR_TIMEOUT;
 
230
        else {
 
231
            fprintf(stderr, "%s, request %s - reply %d:%s\n",
 
232
                "Target of the reply is not the same as the request",
 
233
                _WSMReqTypeToName(req_info->request_type),
 
234
                (int) *req_type_atom,
 
235
                _WSMReqTypeToName(_WSMTargetToReqType(dpy, *req_type_atom)));
 
236
 
 
237
            fail_code = WSM_ERROR_INTERNAL;
 
238
        }
 
239
    }
 
240
    if (*format != WSM_PROTO_FMT) {
 
241
        fprintf(stderr, "%s, request %d - reply %d\n",
 
242
               "Format of the reply is not the same as the request",
 
243
               (int) WSM_PROTO_FMT, (int) *format);
 
244
 
 
245
        fail_code = WSM_ERROR_INTERNAL;
 
246
    }
 
247
 
 
248
    if (fail_code != WSM_SUCCESS) {
 
249
        /*
 
250
         * Failure, call callback with NULL reply.
 
251
         */
 
252
 
 
253
        (*req_info->reply_callback)(w, req_info->reply_data, NULL, fail_code);
 
254
    }
 
255
    else {
 
256
        screen_num = XScreenNumberOfScreen(XtScreen(w));
 
257
        
 
258
        _WSMUnpackReply(dpy, screen_num, value, *length,
 
259
                          req_info->request_type, &reply);
 
260
        
 
261
        (*req_info->reply_callback)(w, req_info->reply_data, &reply,fail_code);
 
262
        
 
263
        FreeReply(&reply);
 
264
    }
 
265
 
 
266
    XtFree((XtPointer) req_info_ptr);
 
267
}
 
268
 
 
269
 
 
270
 
 
271
/*      Function Name: 
 
272
 *      Description: 
 
273
 *      Arguments: target - target to make request against. this is the
 
274
 *                          same as the request type.
 
275
 *                 fmt - format of param data (should be WSM_PROTO_FMT).
 
276
 *                 len - length of param in fmt units.
 
277
 *                 param - parameter data to send to selection owner.
 
278
 *      Returns: The UTM data package.
 
279
 */
 
280
static UTMPackageRec *
 
281
_WSMBuildUtmPackage(
 
282
     Atom           target,
 
283
     int            fmt,
 
284
     unsigned long  len,
 
285
     XtPointer      param,
 
286
     XtPointer      closure)
 
287
{
 
288
  UTMPackageRec *pUtmData;
 
289
 
 
290
  pUtmData = (UTMPackageRec *) XtMalloc(sizeof(UTMPackageRec));
 
291
  pUtmData->fmt = fmt;
 
292
  pUtmData->len = len;
 
293
  pUtmData->target = target;
 
294
  pUtmData->param = param;
 
295
  pUtmData->closure = closure;
 
296
 
 
297
  return(pUtmData);
 
298
}