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

« back to all changes in this revision

Viewing changes to lib/Xm/Sash.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
/* 
 
2
 *  @OPENGROUP_COPYRIGHT@
 
3
 *  COPYRIGHT NOTICE
 
4
 *  Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
 
5
 *  Copyright (c) 1996, 1997, 1998, 1999, 2000 The Open Group
 
6
 *  ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
 
7
 *  the full copyright text.
 
8
 *  
 
9
 *  This software is subject to an open license. It may only be
 
10
 *  used on, with or for operating systems which are themselves open
 
11
 *  source systems. You must contact The Open Group for a license
 
12
 *  allowing distribution and sublicensing of this software on, with,
 
13
 *  or for operating systems which are not Open Source programs.
 
14
 *  
 
15
 *  See http://www.opengroup.org/openmotif/license for full
 
16
 *  details of the license agreement. Any use, reproduction, or
 
17
 *  distribution of the program constitutes recipient's acceptance of
 
18
 *  this agreement.
 
19
 *  
 
20
 *  EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
 
21
 *  PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
22
 *  KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
 
23
 *  WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
 
24
 *  OR FITNESS FOR A PARTICULAR PURPOSE
 
25
 *  
 
26
 *  EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
 
27
 *  NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT,
 
28
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
29
 *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED
 
30
 *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
31
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
32
 *  ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
 
33
 *  EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
 
34
 *  POSSIBILITY OF SUCH DAMAGES.
 
35
*/ 
 
36
/* 
 
37
 * HISTORY
 
38
*/ 
 
39
#ifdef REV_INFO
 
40
#ifndef lint
 
41
static char rcsid[] = "$XConsortium: Sash.c /main/12 1995/07/13 17:51:55 drk $"
 
42
#endif
 
43
#endif
 
44
/* (c) Copyright 1989, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
 
45
/* (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 HEWLETT-PACKARD COMPANY */
 
46
/* (c) Copyright 1988 MASSACHUSETTS INSTITUTE OF TECHNOLOGY  */
 
47
 
 
48
#ifdef HAVE_CONFIG_H
 
49
#include <config.h>
 
50
#endif
 
51
 
 
52
 
 
53
#include <X11/cursorfont.h>
 
54
#include "XmI.h"
 
55
#include <Xm/SashP.h>
 
56
#include <Xm/TransltnsP.h>
 
57
#include <Xm/DrawP.h>
 
58
#include <Xm/DisplayP.h>
 
59
#include "MenuStateI.h"
 
60
#include "TraversalI.h"
 
61
 
 
62
#define defTranslations         _XmSash_defTranslations
 
63
#define SASHSIZE 10
 
64
 
 
65
/********    Static Function Declarations    ********/
 
66
 
 
67
static void ClassPartInitialize( 
 
68
                        WidgetClass wc) ;
 
69
static void ClassInitialize( void ) ;
 
70
static void Initialize( 
 
71
                        Widget rw,
 
72
                        Widget nw,
 
73
                        ArgList args,
 
74
                        Cardinal *num_args) ;
 
75
static void HighlightSash( 
 
76
                        Widget sash) ;
 
77
static void UnhighlightSash( 
 
78
                        Widget sash) ;
 
79
static XmNavigability WidgetNavigable( 
 
80
                        Widget wid) ;
 
81
static void SashFocusIn( 
 
82
                        Widget w,
 
83
                        XEvent *event,
 
84
                        char **params,
 
85
                        Cardinal *num_params) ;
 
86
static void SashFocusOut( 
 
87
                        Widget w,
 
88
                        XEvent *event,
 
89
                        char **params,
 
90
                        Cardinal *num_params) ;
 
91
static void SashAction( 
 
92
                        Widget widget,
 
93
                        XEvent *event,
 
94
                        String *params,
 
95
                        Cardinal *num_params) ;
 
96
static void Realize( 
 
97
                        register Widget w,
 
98
                        XtValueMask *p_valueMask,
 
99
                        XSetWindowAttributes *attributes) ;
 
100
static void Redisplay( 
 
101
                        Widget w,
 
102
                        XEvent *event,
 
103
                        Region region) ;
 
104
 
 
105
static void SashDisplayDestroyCallback ( 
 
106
                        Widget w, 
 
107
                        XtPointer client_data, 
 
108
                        XtPointer call_data );
 
109
/********    End Static Function Declarations    ********/
 
110
 
 
111
 
 
112
static XtResource resources[] = {
 
113
   {XmNborderWidth, XmCBorderWidth, XmRHorizontalDimension, sizeof(Dimension),
 
114
      XtOffsetOf( struct _XmSashRec, core.border_width), XmRImmediate, (XtPointer) 0},
 
115
 
 
116
   {XmNcallback, XmCCallback, XmRCallback, sizeof(XtCallbackList), 
 
117
      XtOffsetOf( struct _XmSashRec, sash.sash_action), XmRPointer, NULL},
 
118
 
 
119
   { XmNnavigationType, XmCNavigationType, XmRNavigationType,
 
120
     sizeof (unsigned char),
 
121
     XtOffsetOf( struct _XmPrimitiveRec, primitive.navigation_type),
 
122
     XmRImmediate, (XtPointer) XmSTICKY_TAB_GROUP},
 
123
};
 
124
 
 
125
 
 
126
static XtActionsRec actionsList[] =
 
127
{
 
128
  {"SashAction",        SashAction},
 
129
  {"SashFocusIn",       SashFocusIn},
 
130
  {"SashFocusOut",      SashFocusOut},
 
131
};
 
132
 
 
133
 
 
134
static XmBaseClassExtRec SashBaseClassExtRec = {
 
135
    NULL,
 
136
    NULLQUARK,
 
137
    XmBaseClassExtVersion,
 
138
    sizeof(XmBaseClassExtRec),
 
139
    NULL,                               /* InitializePrehook    */
 
140
    NULL,                               /* SetValuesPrehook     */
 
141
    NULL,                               /* InitializePosthook   */
 
142
    NULL,                               /* SetValuesPosthook    */
 
143
    NULL,                               /* secondaryObjectClass */
 
144
    NULL,                               /* secondaryCreate      */
 
145
    NULL,                               /* getSecRes data       */
 
146
    { 0 },                              /* fastSubclass flags   */
 
147
    NULL,                               /* get_values_prehook   */
 
148
    NULL,                               /* get_values_posthook  */
 
149
    NULL,                               /* classPartInitPrehook */
 
150
    NULL,                               /* classPartInitPosthook*/
 
151
    NULL,                               /* ext_resources        */
 
152
    NULL,                               /* compiled_ext_resources*/
 
153
    0,                                  /* num_ext_resources    */
 
154
    FALSE,                              /* use_sub_resources    */
 
155
    WidgetNavigable,                    /* widgetNavigable      */
 
156
    XmInheritFocusChange,               /* focusChange          */
 
157
};
 
158
 
 
159
externaldef(xmsashclassrec) XmSashClassRec xmSashClassRec = {
 
160
   {
 
161
/* core class fields */
 
162
    /* superclass         */   (WidgetClass) &xmPrimitiveClassRec,
 
163
    /* class name         */   "XmSash",
 
164
    /* size               */   sizeof(XmSashRec),
 
165
    /* class initialize   */   ClassInitialize,
 
166
    /* class_part_init    */   ClassPartInitialize,
 
167
    /* class_inited       */   FALSE,
 
168
    /* initialize         */   Initialize,
 
169
    /* initialize_hook    */   NULL,
 
170
    /* realize            */   Realize,
 
171
    /* actions            */   actionsList,
 
172
    /* num_actions        */   XtNumber(actionsList),
 
173
    /* resourses          */   resources,
 
174
    /* resource_count     */   XtNumber(resources),
 
175
    /* xrm_class          */   NULLQUARK,
 
176
    /* compress_motion    */   TRUE,
 
177
    /* compress_exposure  */   XtExposeCompressMaximal,
 
178
    /* compress_enter/lv  */   TRUE,
 
179
    /* visible_interest   */   FALSE,
 
180
    /* destroy            */   NULL,
 
181
    /* resize             */   NULL,
 
182
    /* expose             */   Redisplay,
 
183
    /* set_values         */   NULL,
 
184
    /* set_values_hook    */   NULL,
 
185
    /* set_values_almost  */   XtInheritSetValuesAlmost,
 
186
    /* get_values_hook    */   NULL,
 
187
    /* accept_focus       */   NULL,
 
188
    /* version            */   XtVersion,
 
189
    /* callback_private   */   NULL,
 
190
    /* tm_table           */   defTranslations,
 
191
    /* query_geometry     */   NULL,
 
192
    NULL,                             /* display_accelerator   */
 
193
    (XtPointer)&SashBaseClassExtRec, /* extension             */
 
194
   },
 
195
 
 
196
   {
 
197
      XmInheritWidgetProc,   /* Primitive border_highlight   */
 
198
      XmInheritWidgetProc,   /* Primitive border_unhighlight */
 
199
      NULL,         /* translations                 */
 
200
      NULL,         /* arm_and_activate             */
 
201
      NULL,         /* get resources                */
 
202
      0,            /* num get_resources            */
 
203
      NULL,         /* extension                    */
 
204
   },
 
205
 
 
206
   {
 
207
      (XtPointer) NULL,         /* extension        */
 
208
   }
 
209
 
 
210
};
 
211
 
 
212
externaldef(xmsashwidgetclass) WidgetClass xmSashWidgetClass =
 
213
                                                 (WidgetClass) &xmSashClassRec;
 
214
 
 
215
/************************************************************************
 
216
 *
 
217
 *  ClassPartInitialize
 
218
 *    Set up the fast subclassing for the widget.
 
219
 *
 
220
 ************************************************************************/
 
221
static void 
 
222
ClassPartInitialize(
 
223
        WidgetClass wc )
 
224
{
 
225
   _XmFastSubclassInit(wc, XmSASH_BIT);
 
226
}
 
227
 
 
228
/************************************************************************
 
229
 *
 
230
 *  ClassInitialize
 
231
 *    Initialize the primitive part of class structure with 
 
232
 *    routines to do special highlight & unhighlight for Sash.
 
233
 *
 
234
 ************************************************************************/
 
235
static void 
 
236
ClassInitialize( void )
 
237
{
 
238
   xmSashClassRec.primitive_class.border_highlight =
 
239
                  HighlightSash;
 
240
   xmSashClassRec.primitive_class.border_unhighlight = 
 
241
                  UnhighlightSash;
 
242
   SashBaseClassExtRec.record_type = XmQmotif;
 
243
}
 
244
 
 
245
/*ARGSUSED*/
 
246
static void 
 
247
Initialize(
 
248
        Widget rw,
 
249
        Widget nw,
 
250
        ArgList args,           /* unused */
 
251
        Cardinal *num_args )    /* unused */
 
252
{
 
253
        XmSashWidget request = (XmSashWidget) rw ;
 
254
        XmSashWidget new_w = (XmSashWidget) nw ;
 
255
  if (request->core.width == 0)
 
256
     new_w->core.width += SASHSIZE;
 
257
  if (request->core.height == 0)
 
258
     new_w->core.height += SASHSIZE;
 
259
  new_w->sash.has_focus = False;
 
260
}
 
261
 
 
262
static void 
 
263
HighlightSash(
 
264
        Widget sash )
 
265
{
 
266
  int x, y;
 
267
  
 
268
  x = y = ((XmSashWidget) sash)->primitive.shadow_thickness;
 
269
  
 
270
  XFillRectangle( XtDisplay( sash), XtWindow( sash),
 
271
                   ((XmSashWidget) sash)->primitive.highlight_GC,
 
272
                   x,y, sash->core.width-(2*x), sash->core.height-(2*y));
 
273
}
 
274
 
 
275
static void 
 
276
UnhighlightSash(
 
277
        Widget sash )
 
278
{
 
279
  int x, y;
 
280
  
 
281
  x = y = ((XmSashWidget) sash)->primitive.shadow_thickness;
 
282
 
 
283
  XClearArea( XtDisplay( sash), XtWindow( sash),
 
284
                   x,y, sash->core.width-(2*x), sash->core.height-(2*y),
 
285
                   FALSE);
 
286
}
 
287
 
 
288
static XmNavigability
 
289
WidgetNavigable(
 
290
        Widget wid)
 
291
{   
 
292
  if(    _XmShellIsExclusive( wid)    )
 
293
    {
 
294
      /* Preserve 1.0 behavior.  (Why?  Don't ask me!)
 
295
       */
 
296
      return XmNOT_NAVIGABLE ;
 
297
    }
 
298
  if(    XtIsSensitive(wid)
 
299
     &&  ((XmPrimitiveWidget) wid)->primitive.traversal_on    )
 
300
    {   
 
301
      XmNavigationType nav_type = ((XmPrimitiveWidget) wid)
 
302
                                                  ->primitive.navigation_type ;
 
303
      if(    (nav_type == XmSTICKY_TAB_GROUP)
 
304
         ||  (nav_type == XmEXCLUSIVE_TAB_GROUP)
 
305
         ||  (    (nav_type == XmTAB_GROUP)
 
306
              &&  !_XmShellIsExclusive( wid))    )
 
307
        {
 
308
          return XmTAB_NAVIGABLE ;
 
309
        }
 
310
    }
 
311
  return XmNOT_NAVIGABLE ;
 
312
}
 
313
 
 
314
/* ARGSUSED */
 
315
static void 
 
316
SashFocusIn(
 
317
        Widget w,
 
318
        XEvent *event,
 
319
        char **params,
 
320
        Cardinal *num_params )
 
321
{
 
322
    register XmSashWidget sash = (XmSashWidget) w;
 
323
 
 
324
    if (event->xany.type != FocusIn || !event->xfocus.send_event)
 
325
          return;
 
326
 
 
327
    if (_XmGetFocusPolicy( (Widget) sash) == XmEXPLICIT)
 
328
       HighlightSash(w);
 
329
 
 
330
 
 
331
    XmeDrawShadows (XtDisplay (w), XtWindow (w),
 
332
                     sash->primitive.top_shadow_GC,
 
333
                     sash->primitive.bottom_shadow_GC,
 
334
                     0,0,w->core.width, w->core.height,
 
335
                     sash->primitive.shadow_thickness,
 
336
                     XmSHADOW_OUT);
 
337
 
 
338
    sash->sash.has_focus = True;
 
339
}
 
340
 
 
341
/* ARGSUSED */
 
342
static void 
 
343
SashFocusOut(
 
344
        Widget w,
 
345
        XEvent *event,
 
346
        char **params,
 
347
        Cardinal *num_params )
 
348
{
 
349
    register XmSashWidget sash = (XmSashWidget) w;
 
350
 
 
351
    if (event->xany.type != FocusOut || !event->xfocus.send_event)
 
352
          return;
 
353
 
 
354
    if (_XmGetFocusPolicy( (Widget) sash) == XmEXPLICIT)
 
355
       UnhighlightSash(w);
 
356
 
 
357
    XmeDrawShadows (XtDisplay (w), XtWindow (w),
 
358
                     sash->primitive.top_shadow_GC,
 
359
                     sash->primitive.bottom_shadow_GC,
 
360
                     0,0,w->core.width, w->core.height,
 
361
                     sash->primitive.shadow_thickness,
 
362
                     XmSHADOW_OUT);
 
363
 
 
364
    sash->sash.has_focus = False;
 
365
}
 
366
 
 
367
static void 
 
368
SashAction(
 
369
        Widget widget,
 
370
        XEvent *event,
 
371
        String *params,
 
372
        Cardinal *num_params )
 
373
{
 
374
    register XmSashWidget sash = (XmSashWidget) widget;
 
375
    SashCallDataRec call_data;
 
376
 
 
377
    call_data.event = event;
 
378
    call_data.params = params;
 
379
    call_data.num_params = *num_params;
 
380
 
 
381
    XtCallCallbackList(widget, sash->sash.sash_action, (XtPointer)&call_data);
 
382
}
 
383
 
 
384
static void 
 
385
Realize(
 
386
        register Widget w,
 
387
        XtValueMask *p_valueMask,
 
388
        XSetWindowAttributes *attributes )
 
389
{
 
390
        XmDisplay   dd = (XmDisplay) XmGetXmDisplay(XtDisplay(w));
 
391
        Cursor SashCursor = 
 
392
                ((XmDisplayInfo *)(dd->display.displayInfo))->SashCursor;
 
393
        
 
394
        if (0L == SashCursor)
 
395
                {
 
396
                /* create some data shared among all instances on this 
 
397
                ** display; the first one along can create it, and 
 
398
                ** any one can remove it; note no reference count
 
399
                */
 
400
                SashCursor = 
 
401
                ((XmDisplayInfo *)(dd->display.displayInfo))->SashCursor = 
 
402
                        XCreateFontCursor(XtDisplay(w), XC_crosshair);
 
403
                XtAddCallback((Widget)dd, XtNdestroyCallback, 
 
404
                        SashDisplayDestroyCallback, (XtPointer) NULL);
 
405
                }
 
406
 
 
407
        attributes->cursor = SashCursor;
 
408
        XtCreateWindow (w, InputOutput, CopyFromParent, 
 
409
                *p_valueMask | CWCursor, attributes);
 
410
}
 
411
 
 
412
/*ARGSUSED*/
 
413
static void 
 
414
SashDisplayDestroyCallback 
 
415
        ( Widget w,
 
416
        XtPointer client_data,  /* unused */
 
417
        XtPointer call_data )   /* unused */
 
418
{
 
419
        XmDisplay   dd = (XmDisplay) XmGetXmDisplay(XtDisplay(w));
 
420
        Cursor SashCursor;
 
421
        if ((XmDisplay)NULL != dd)
 
422
        {
 
423
          SashCursor  = 
 
424
                ((XmDisplayInfo *)(dd->display.displayInfo))->SashCursor;
 
425
            if (0L != SashCursor)
 
426
                {
 
427
                        XFreeCursor(XtDisplay(w), SashCursor);
 
428
                        /*
 
429
                        ((XmDisplayInfo *)(dd->display.displayInfo))->SashCursor= 0L;
 
430
                        */
 
431
                }
 
432
        }
 
433
}
 
434
 
 
435
 
 
436
 
 
437
 
 
438
/*************************************<->*************************************
 
439
 *
 
440
 *  Redisplay (w, event)
 
441
 *
 
442
 *   Description:
 
443
 *   -----------
 
444
 *     Cause the widget, identified by w, to be redisplayed.
 
445
 *
 
446
 *
 
447
 *   Inputs:
 
448
 *   ------
 
449
 *     w = widget to be redisplayed;
 
450
 *     event = event structure identifying need for redisplay on this
 
451
 *             widget.
 
452
 * 
 
453
 *   Outputs:
 
454
 *   -------
 
455
 *
 
456
 *   Procedures Called
 
457
 *   -----------------
 
458
 *   DrawToggle()
 
459
 *   XDrawString()
 
460
 *************************************<->***********************************/
 
461
/* ARGSUSED */
 
462
static void 
 
463
Redisplay(
 
464
        Widget w,
 
465
        XEvent *event,
 
466
        Region region )
 
467
{
 
468
   register XmSashWidget sash = (XmSashWidget) w;
 
469
 
 
470
     XmeDrawShadows (XtDisplay (w), XtWindow (w), 
 
471
                      sash->primitive.top_shadow_GC,
 
472
                      sash->primitive.bottom_shadow_GC, 
 
473
                      0,0,w->core.width, w->core.height,
 
474
                      sash->primitive.shadow_thickness,
 
475
                      XmSHADOW_OUT);
 
476
 
 
477
     if (sash->sash.has_focus) HighlightSash(w);
 
478
}