~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/3rdparty/qmon/Xmt310/Xmt/LayoutPixmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Motif Tools Library, Version 3.1
 
3
 * $Id$
 
4
 * 
 
5
 * Written by David Flanagan.
 
6
 * Copyright (c) 1992-2001 by David Flanagan.
 
7
 * All Rights Reserved.  See the file COPYRIGHT for details.
 
8
 * This is open source software.  See the file LICENSE for details.
 
9
 * There is no warranty for this software.  See NO_WARRANTY for details.
 
10
 *
 
11
 * $Log$
 
12
 * Revision 1.1.1.1  2001/07/18 11:06:02  root
 
13
 * Initial checkin.
 
14
 *
 
15
 * Revision 1.2  2001/06/12 16:25:28  andre
 
16
 * *** empty log message ***
 
17
 *
 
18
 *
 
19
 */
 
20
 
 
21
#include <Xmt/Xmt.h>
 
22
#include <Xmt/LayoutGP.h>
 
23
#include <Xmt/Converters.h> /* for definition of XmtRBitmask */
 
24
 
 
25
#define offset(field) XtOffsetOf(XmtLayoutPixmapRec, layout_pixmap.field)
 
26
static XtResource resources[] = {
 
27
{XmtNpixmap, XmtCPixmap, XtRPixmap,
 
28
     sizeof(Pixmap), offset(pixmap),
 
29
     XtRImmediate, (XtPointer) None},
 
30
{XmtNbitmap, XmtCBitmap, XtRBitmap,
 
31
     sizeof(Pixmap), offset(bitmap),
 
32
     XtRImmediate, (XtPointer) None},
 
33
{XmtNbitmask, XmtCBitmask, XmtRBitmask,
 
34
     sizeof(Pixmap), offset(bitmask),
 
35
     XtRImmediate, (XtPointer) None},
 
36
{XmtNforeground, XtCForeground, XtRPixel,
 
37
     sizeof(Pixel), offset(foreground),
 
38
     XtRImmediate, (XtPointer) -1},
 
39
{XmtNbackground, XtCBackground, XtRPixel,
 
40
     sizeof(Pixel), offset(background),
 
41
     XtRImmediate, (XtPointer) -1}
 
42
};
 
43
#undef offset
 
44
 
 
45
#if NeedFunctionPrototypes
 
46
static void Initialize(Widget, Widget, ArgList, Cardinal *);
 
47
static void Destroy(Widget);
 
48
static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal *);
 
49
static void Redisplay(Widget, XEvent *, Region);
 
50
static XtGeometryResult QueryGeometry(Widget, XtWidgetGeometry *,
 
51
                                      XtWidgetGeometry *);
 
52
#else
 
53
static void Initialize();
 
54
static void Destroy();
 
55
static Boolean SetValues();
 
56
static void Redisplay();
 
57
static XtGeometryResult QueryGeometry();
 
58
#endif
 
59
 
 
60
#define superclass (&xmtLayoutGadgetClassRec)
 
61
 
 
62
externaldef(xmtlayoutpixmapclassrec)
 
63
XmtLayoutPixmapClassRec xmtLayoutPixmapClassRec = {
 
64
{   /* rect_class fields  */
 
65
    /* superclass         */    (WidgetClass)superclass,
 
66
    /* class_name         */    "XmtLayoutPixmap",
 
67
    /* widget_size        */    sizeof(XmtLayoutPixmapRec),
 
68
    /* class_initialize   */    NULL,
 
69
    /* class_part_initialize*/  NULL,
 
70
    /* class_inited       */    FALSE,
 
71
    /* initialize         */    Initialize,
 
72
    /* initialize_hook    */    NULL,           
 
73
    /* rect1              */    NULL,
 
74
    /* rect2              */    NULL,
 
75
    /* rect3              */    0,
 
76
    /* resources          */    resources,
 
77
    /* num_resources      */    XtNumber(resources),
 
78
    /* xrm_class          */    NULLQUARK,
 
79
    /* rect4              */    FALSE,
 
80
    /* rect5              */    FALSE,
 
81
    /* rect6              */    FALSE,
 
82
    /* rect7              */    FALSE,
 
83
    /* destroy            */    Destroy,
 
84
    /* resize             */    NULL,
 
85
    /* expose             */    Redisplay,
 
86
    /* set_values         */    SetValues,
 
87
    /* set_values_hook    */    NULL,                   
 
88
    /* set_values_almost  */    XtInheritSetValuesAlmost,  
 
89
    /* get_values_hook    */    NULL,                   
 
90
    /* rect9              */    NULL,
 
91
    /* version            */    XtVersion,
 
92
    /* callback_offsets   */    NULL,
 
93
    /* rect10             */    NULL,
 
94
    /* query_geometry     */    QueryGeometry,
 
95
    /* rect11             */    NULL,
 
96
    /* extension            */  NULL
 
97
  },
 
98
  { /* XmtLayoutGadget field */
 
99
    /* change_font        */    NULL
 
100
  },
 
101
  { /* XmtLayoutPixmap fields */
 
102
    /* extension          */    NULL
 
103
  }
 
104
};
 
105
 
 
106
externaldef(xmtlayoutpixmapgadgetclass)
 
107
WidgetClass xmtLayoutPixmapGadgetClass = (WidgetClass)&xmtLayoutPixmapClassRec;
 
108
 
 
109
#if NeedFunctionPrototypes
 
110
static void GetGC(XmtLayoutWidget lw, XmtLayoutPixmapGadget lp)
 
111
#else
 
112
static void GetGC(lw, lp)
 
113
XmtLayoutWidget lw;
 
114
XmtLayoutPixmapGadget lp;
 
115
#endif
 
116
{
 
117
    XGCValues gcv;
 
118
    long flags = GCForeground | GCBackground | GCGraphicsExposures;
 
119
 
 
120
    if ((lp->layout_pixmap.foreground == -1)  &&
 
121
        (lp->layout_pixmap.background == -1) &&
 
122
        (lp->layout_pixmap.bitmask == None)) {
 
123
        lp->layout_pixmap.gc = NULL;
 
124
        return;
 
125
    }
 
126
    
 
127
    if (lp->layout_pixmap.foreground != -1)
 
128
        gcv.foreground = lp->layout_pixmap.foreground;
 
129
    else
 
130
        gcv.foreground = lw->manager.foreground;
 
131
    
 
132
    if (lp->layout_pixmap.background != -1)
 
133
        gcv.background = lp->layout_pixmap.background;
 
134
    else
 
135
        gcv.background = lw->core.background_pixel;
 
136
 
 
137
    gcv.graphics_exposures = False;
 
138
    
 
139
    if (lp->layout_pixmap.bitmask != None) {
 
140
        gcv.clip_mask = lp->layout_pixmap.bitmask;
 
141
        flags |= GCClipMask;
 
142
    }
 
143
    
 
144
    lp->layout_pixmap.gc = XtGetGC((Widget)lp, flags, &gcv);
 
145
}
 
146
 
 
147
#if NeedFunctionPrototypes
 
148
static void MeasurePixmap(XmtLayoutWidget lw, XmtLayoutPixmapGadget lp)
 
149
#else
 
150
static void MeasurePixmap(lw, lp)
 
151
XmtLayoutWidget lw;
 
152
XmtLayoutPixmapGadget lp;
 
153
#endif
 
154
{
 
155
    unsigned width, height, depth, border;
 
156
    int x, y;
 
157
    Window dummywin;
 
158
    
 
159
    if (lp->layout_pixmap.pixmap || lp->layout_pixmap.bitmap) {
 
160
        (void)XGetGeometry(lw->core.screen->display,
 
161
                           (lp->layout_pixmap.pixmap
 
162
                               ?lp->layout_pixmap.pixmap
 
163
                               :lp->layout_pixmap.bitmap),
 
164
                           &dummywin, &x, &y, &width, &height, &border,&depth);
 
165
        lp->layout_pixmap.width = width;
 
166
        lp->layout_pixmap.height = height;
 
167
        lp->layout_pixmap.depth = depth;
 
168
    }
 
169
    else {
 
170
        lp->layout_pixmap.width = lp->layout_pixmap.height = 0;
 
171
    }
 
172
}
 
173
 
 
174
/* ARGSUSED */
 
175
#if NeedFunctionPrototypes
 
176
static void Initialize(Widget request, Widget init,
 
177
                       ArgList arglist, Cardinal *num_args)
 
178
#else
 
179
static void Initialize(request, init, arglist, num_args)
 
180
Widget request;
 
181
Widget init;
 
182
ArgList arglist;
 
183
Cardinal *num_args;
 
184
#endif
 
185
{
 
186
    XmtLayoutPixmapGadget lp = (XmtLayoutPixmapGadget) init;
 
187
    XmtLayoutWidget lw = (XmtLayoutWidget) XtParent(init);
 
188
 
 
189
    Constraint(lp, type) = XmtLayoutPixmap;
 
190
 
 
191
    MeasurePixmap(lw, lp);
 
192
    GetGC(lw, lp);
 
193
}
 
194
 
 
195
#if NeedFunctionPrototypes
 
196
static void Destroy(Widget w)
 
197
#else
 
198
static void Destroy(w)
 
199
Widget w;
 
200
#endif
 
201
{
 
202
    XmtLayoutPixmapGadget lp = (XmtLayoutPixmapGadget) w;
 
203
 
 
204
    if (lp->layout_pixmap.gc)
 
205
        XtReleaseGC(w, lp->layout_pixmap.gc);
 
206
}
 
207
 
 
208
/* ARGSUSED */
 
209
#if NeedFunctionPrototypes
 
210
static Boolean SetValues(Widget current, Widget request, Widget set,
 
211
                         ArgList arglist, Cardinal *num_args)
 
212
#else
 
213
static Boolean SetValues(current, request, set, arglist, num_args)
 
214
Widget current;
 
215
Widget request;
 
216
Widget set;
 
217
ArgList arglist;
 
218
Cardinal *num_args;
 
219
#endif
 
220
{
 
221
    XmtLayoutPixmapGadget cp = (XmtLayoutPixmapGadget) current;
 
222
    XmtLayoutPixmapGadget sp = (XmtLayoutPixmapGadget) set;
 
223
    XmtLayoutWidget lw = (XmtLayoutWidget) XtParent(set);
 
224
    Boolean redisplay = False;
 
225
    Boolean relayout = False;
 
226
 
 
227
    if ((sp->layout_pixmap.pixmap != cp->layout_pixmap.pixmap) ||
 
228
        (sp->layout_pixmap.bitmap != cp->layout_pixmap.bitmap)) {
 
229
        MeasurePixmap(lw, sp);
 
230
        sp->rectangle.width = sp->layout_pixmap.width;
 
231
        sp->rectangle.height = sp->layout_pixmap.height;
 
232
        if (!sp->rectangle.width) sp->rectangle.width++;
 
233
        if (!sp->rectangle.height) sp->rectangle.height++;
 
234
        relayout = True;
 
235
    }
 
236
 
 
237
    if ((sp->layout_pixmap.foreground != cp->layout_pixmap.foreground) ||
 
238
        (sp->layout_pixmap.background != cp->layout_pixmap.background)||
 
239
        (sp->layout_pixmap.bitmask    != cp->layout_pixmap.bitmask)) {
 
240
        if (sp->layout_pixmap.gc) XtReleaseGC(set, sp->layout_pixmap.gc);
 
241
        GetGC(lw, sp);
 
242
        redisplay = True;
 
243
    }
 
244
 
 
245
    if ((redisplay | relayout) && XtIsRealized((Widget)lw))
 
246
        XClearArea(XtDisplay((Widget)lw), XtWindow((Widget)lw),
 
247
                   cp->rectangle.x, cp->rectangle.y,
 
248
                   cp->rectangle.width, cp->rectangle.height,
 
249
                   True);
 
250
                   
 
251
    return False;
 
252
}
 
253
 
 
254
/* ARGSUSED */
 
255
#if NeedFunctionPrototypes
 
256
static XtGeometryResult QueryGeometry(Widget w,
 
257
                                      XtWidgetGeometry *request,
 
258
                                      XtWidgetGeometry *reply)
 
259
#else
 
260
static XtGeometryResult QueryGeometry(w, request, reply)
 
261
Widget w;
 
262
XtWidgetGeometry *request;
 
263
XtWidgetGeometry *reply;
 
264
#endif
 
265
 
266
    XmtLayoutPixmapGadget lp = (XmtLayoutPixmapGadget) w;
 
267
 
 
268
    reply->request_mode = CWWidth | CWHeight;
 
269
    reply->width = lp->layout_pixmap.width;
 
270
    reply->height = lp->layout_pixmap.height;
 
271
    return XtGeometryYes;
 
272
}
 
273
 
 
274
/* ARGSUSED */
 
275
#if NeedFunctionPrototypes
 
276
static void Redisplay(Widget w, XEvent *event, Region region)
 
277
#else
 
278
static void Redisplay(w, event, region)
 
279
Widget w;
 
280
XEvent *event;
 
281
Region region;
 
282
#endif
 
283
{
 
284
    XmtLayoutPixmapGadget lp = (XmtLayoutPixmapGadget) w;
 
285
    XmtLayoutWidget lw = (XmtLayoutWidget) XtParent(w);
 
286
 
 
287
    if (lw->core.window == None) return;
 
288
    if ((lp->layout_pixmap.pixmap == None) && (lp->layout_pixmap.bitmap==None))
 
289
        return;
 
290
 
 
291
    if (lp->layout_pixmap.bitmask)
 
292
        XSetClipOrigin(XtDisplay((Widget)lw), lp->layout_pixmap.gc,
 
293
                       lp->rectangle.x, lp->rectangle.y);
 
294
 
 
295
    /*
 
296
     * pixmap should be multi-plane, and bitmap should be single-plane,
 
297
     * but we don't assume that.  We depend on the queried depth.
 
298
     */
 
299
    if ((lp->layout_pixmap.pixmap == None) ||
 
300
        (lp->layout_pixmap.depth != lw->core.depth))
 
301
        XCopyPlane(XtDisplay((Widget)lw),
 
302
                   (lp->layout_pixmap.pixmap
 
303
                      ?lp->layout_pixmap.pixmap
 
304
                      :lp->layout_pixmap.bitmap),
 
305
                   XtWindow((Widget)lw),
 
306
                   (lp->layout_pixmap.gc?lp->layout_pixmap.gc:lw->layout.gc),
 
307
                   0, 0, lp->layout_pixmap.width, lp->layout_pixmap.height,
 
308
                   lp->rectangle.x, lp->rectangle.y, (unsigned long) 1);
 
309
    else
 
310
        XCopyArea(XtDisplay((Widget)lw),
 
311
                  (lp->layout_pixmap.pixmap
 
312
                      ?lp->layout_pixmap.pixmap
 
313
                      :lp->layout_pixmap.bitmap),
 
314
                  XtWindow((Widget)lw),
 
315
                  (lp->layout_pixmap.gc?lp->layout_pixmap.gc:lw->layout.gc),
 
316
                  0, 0, lp->layout_pixmap.width, lp->layout_pixmap.height,
 
317
                  lp->rectangle.x, lp->rectangle.y);
 
318
 
 
319
    if (lp->layout_pixmap.bitmask)
 
320
        XSetClipOrigin(XtDisplay((Widget)lw), lp->layout_pixmap.gc, 0, 0);
 
321
}
 
322
 
 
323
#if NeedFunctionPrototypes
 
324
Widget XmtCreateLayoutPixmap(Widget parent, String name,
 
325
                             ArgList arglist, Cardinal num_args)
 
326
#else
 
327
Widget XmtCreateLayoutPixmap(parent, name, arglist, num_args)
 
328
Widget parent;
 
329
String name;
 
330
ArgList arglist;
 
331
Cardinal num_args;
 
332
#endif
 
333
{
 
334
    return XtCreateWidget(name, xmtLayoutPixmapGadgetClass, parent,
 
335
                          arglist, num_args);
 
336
}