Back to index

tetex-bin  3.0
Defines | Functions | Variables
xlwradio.c File Reference
#include "xdvi-config.h"
#include "xdvi.h"
#include "xdvi-debug.h"
#include "util.h"
#include "xaw_bitmaps.h"
#include "xlwradioP.h"
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Xos.h>
#include <X11/Xaw/Text.h>
#include <X11/Xaw/AsciiText.h>

Go to the source code of this file.

Defines

#define BOX_SIZE   16
#define PIXMAP_OFFSET   2 /* additional space between pixmap and label */
#define UNUSED(x)   ((void)(x))
#define MAX(i, j)   ( (i) > (j) ? (i) : (j) )
#define rclass(w)   ((RadioWidgetClass)((w)->core.widget_class))
#define swid(rw)   ((rw)->core.border_width)
#define bsize(rw)   (rclass(rw)->radio_class.dsize)
#define bs(rw)   (bsize(rw) + PIXMAP_OFFSET + 2*swid(rw))
#define offset(field)   XtOffset(RadioWidget, radio.field)
#define SuperClass   ((ToggleWidgetClass)&toggleClassRec)

Functions

static void RadioInit (Widget, Widget, ArgList, Cardinal *)
static void RadioExpose (Widget, XEvent *, Region)
static void RadioResize (Widget)
static void RadioDestroy (Widget)
static void RadioClassInit (void)
static void RadioClassPartInit (WidgetClass)
static Boolean RadioSetValues (Widget, Widget, Widget, ArgList, Cardinal *)
static void DrawDiamond (Widget)
static XtGeometryResult RadioQueryGeometry (Widget, XtWidgetGeometry *, XtWidgetGeometry *)
static void RadioHighlight (Widget, XEvent *, String *, Cardinal *)
static void RadioUnhighlight (Widget, XEvent *, String *, Cardinal *)
static void RadioSize (RadioWidget, Dimension *, Dimension *)
static void DrawHighlight (Widget w, GC gc)
void RadioSet (Widget w, XEvent *event, String *params, Cardinal *num_params)
void RadioUnset (Widget w, XEvent *event, String *params, Cardinal *num_params)

Variables

static XtActionsRec actionsList []
static XtResource resources []
RadioClassRec radioClassRec
WidgetClass radioWidgetClass = (WidgetClass) &radioClassRec

Define Documentation

#define BOX_SIZE   16

Definition at line 95 of file xlwradio.c.

#define bs (   rw)    (bsize(rw) + PIXMAP_OFFSET + 2*swid(rw))

Definition at line 117 of file xlwradio.c.

#define bsize (   rw)    (rclass(rw)->radio_class.dsize)

Definition at line 116 of file xlwradio.c.

#define MAX (   i,
 
)    ( (i) > (j) ? (i) : (j) )

Definition at line 103 of file xlwradio.c.

#define offset (   field)    XtOffset(RadioWidget, radio.field)

Definition at line 162 of file xlwradio.c.

#define PIXMAP_OFFSET   2 /* additional space between pixmap and label */

Definition at line 96 of file xlwradio.c.

#define rclass (   w)    ((RadioWidgetClass)((w)->core.widget_class))

Definition at line 107 of file xlwradio.c.

#define SuperClass   ((ToggleWidgetClass)&toggleClassRec)

Definition at line 170 of file xlwradio.c.

#define swid (   rw)    ((rw)->core.border_width)

Definition at line 113 of file xlwradio.c.

#define UNUSED (   x)    ((void)(x))

Definition at line 99 of file xlwradio.c.


Function Documentation

static void DrawDiamond ( Widget  w) [static]

Definition at line 638 of file xlwradio.c.

{
    RadioWidget rw = (RadioWidget) w;
    Display *dpy = XtDisplay(w);
    Window win = XtWindow(w);
    
    Position x = rw->label.internal_width;
    Position y = rw->core.height/2;
    GC gc = XtIsSensitive(w) ? rw->command.normal_GC : rw->label.gray_GC;
    Pixmap selected, unselected;

    if (rw->radio.isRadio) { /* it's a radio button */
       selected = rclass(rw)->radio_class.sel_radio;
       unselected = rclass(rw)->radio_class.unsel_radio;
    }
    else {
       selected = rclass(rw)->radio_class.sel_menu;
       unselected = rclass(rw)->radio_class.unsel_menu;
    }
    
    ASSERT(selected != None, "");
    ASSERT(unselected != None, "");
    
    if(rw->command.set) {
       XCopyPlane(dpy, selected, win, gc,
                 0, 0, BUTTON_BITMAP_H, BUTTON_BITMAP_W,
                 x, y - BUTTON_BITMAP_H / 2, 1L);
    }
    else {
       XCopyPlane(dpy, unselected, win, gc,
                 0, 0, BUTTON_BITMAP_H, BUTTON_BITMAP_W,
                 x, y - BUTTON_BITMAP_H / 2, 1L);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void DrawHighlight ( Widget  w,
GC  gc 
) [static]

Definition at line 511 of file xlwradio.c.

{
       RadioWidget   rw = (RadioWidget)w;
       XRectangle    rects[4];
       Dimension     ht = rw->command.highlight_thickness;

       if( ht <= 0 ||
           ht > rw->core.width/2  ||
           ht > rw->core.height/2 )
         return;

       if( ! XtIsRealized(w) )
         return;

       rects[0].x = 0; rects[0].y = 0;
       rects[0].width = rw->core.width; rects[0].height = ht;
       rects[1].x = 0; rects[1].y = rw->core.height - ht;
       rects[1].width = rw->core.width; rects[1].height = ht;
       rects[2].x = 0; rects[2].y = ht;
       rects[2].width = ht; rects[2].height = rw->core.height - ht*2;
       rects[3].x = rw->core.width - ht; rects[3].y = ht;
       rects[3].width = ht; rects[3].height = rw->core.height - ht*2;
       XFillRectangles( XtDisplay(w), XtWindow(w), gc, rects, 4);
}

Here is the caller graph for this function:

static void RadioClassInit ( void  ) [static]

Definition at line 255 of file xlwradio.c.

{
  XawInitializeWidgetSet();
}
static void RadioClassPartInit ( WidgetClass  class) [static]
static void RadioDestroy ( Widget  w) [static]

Definition at line 327 of file xlwradio.c.

{
    RadioWidget rw = (RadioWidget)w;
    /* de-allocate bitmaps */
    XFreePixmap(XtDisplay(w), rclass(rw)->radio_class.sel_radio);
    XFreePixmap(XtDisplay(w), rclass(rw)->radio_class.unsel_radio);
    XFreePixmap(XtDisplay(w), rclass(rw)->radio_class.sel_menu);
    XFreePixmap(XtDisplay(w), rclass(rw)->radio_class.unsel_menu);
}
static void RadioExpose ( Widget  w,
XEvent *  event,
Region  region 
) [static]

Definition at line 372 of file xlwradio.c.

{
       RadioWidget   rw = (RadioWidget) w;
       Display              *dpy = XtDisplay(w);
       Window        win = XtWindow(w);
       GC            gc;
       Pixmap        left_bitmap;
       extern WidgetClass labelWidgetClass;

       /* Note: the Label widget examines the region to decide if anything
        * needs to be drawn.  I'm not sure that this is worth the effort,
        * but it bears thinking on.
        */

       /* Command widget may sometimes override the label GC in order
        * to draw inverse video.  We don't use inverse video, so we need
        * to restore the label's normal GC.
        */
       rw->label.normal_GC = rw->command.normal_GC;


       /* Let label widget draw the label.  If there was an lbm_x
        * field, we could let Label draw the bitmap too.  But there
        * isn't, so we need to temporarily remove the bitmap and
        * draw it ourself later.
        */
       left_bitmap = rw->label.left_bitmap;
       rw->label.left_bitmap = None;
       labelWidgetClass->core_class.expose(w,event,region);
       rw->label.left_bitmap = left_bitmap;

       /* now manually draw the left bitmap.  TODO: 3-d look, xaw-xpm */
       gc = XtIsSensitive(w) ? rw->label.normal_GC : rw->label.gray_GC;
       if( left_bitmap != None && rw->label.lbm_width > 0 )
       {
         /* TODO: handle pixmaps */
         XCopyPlane(dpy, left_bitmap, win, gc,
                   0,0, rw->label.lbm_width, rw->label.lbm_height,
                   (int) rw->label.internal_width*2 + bs(rw),
                   (int) rw->label.internal_height + rw->label.lbm_y,
                   1UL);
       }
       DrawDiamond(w);
       /* Finally, the button itself */
       ((RadioWidgetClass)(w->core.widget_class))->radio_class.drawDiamond(w);
}

Here is the call graph for this function:

static void RadioHighlight ( Widget  w,
XEvent *  event,
String params,
Cardinal *  num_params 
) [static]

Definition at line 538 of file xlwradio.c.

{
    RadioWidget      rw = (RadioWidget)w;
    UNUSED(event);
    UNUSED(params);
    UNUSED(num_params);
    
    DrawHighlight(w, rw->command.normal_GC);
}

Here is the call graph for this function:

static void RadioInit ( Widget  request,
Widget  new,
ArgList  args,
Cardinal *  num_args 
) [static]

Definition at line 278 of file xlwradio.c.

{
    RadioWidget rw = (RadioWidget) new;
    RadioWidget rw_req = (RadioWidget) request;
    Dimension w,h;

    UNUSED(args);
    UNUSED(num_args);

    /* FIXME: should pixmap initialization be here?? */

    /* Select initial size for the widget */
    if( rw_req->core.width == 0  ||  rw_req->core.height == 0 ) {
       RadioSize(rw, &w,&h);
       if( rw_req->core.width == 0 )
           rw->core.width = w;
       if( rw_req->core.height == 0 )
           rw->core.height = h;
       rw->core.widget_class->core_class.resize(new);
    }
    /*
      FIXME: access to XtWindow(rw) fails in the init method, so
      I moved the bitmap creation here -- is there a better way??
    */
    /* create pixmaps */
    rclass(rw)->radio_class.sel_radio
       = XCreateBitmapFromData(XtDisplay(rw), RootWindowOfScreen(XtScreen(rw)),
                            (char *)button_radio_on_bits, BUTTON_BITMAP_W, BUTTON_BITMAP_H);
    rclass(rw)->radio_class.unsel_radio
       = XCreateBitmapFromData(XtDisplay(rw), RootWindowOfScreen(XtScreen(rw)),
                            (char *)button_radio_off_bits, BUTTON_BITMAP_W, BUTTON_BITMAP_H);
    rclass(rw)->radio_class.sel_menu
       = XCreateBitmapFromData(XtDisplay(rw), RootWindowOfScreen(XtScreen(rw)),
                            (char *)button_check_on_bits, BUTTON_BITMAP_W, BUTTON_BITMAP_H);
    rclass(rw)->radio_class.unsel_menu
       = XCreateBitmapFromData(XtDisplay(rw), RootWindowOfScreen(XtScreen(rw)),
                            (char *)button_check_off_bits, BUTTON_BITMAP_W, BUTTON_BITMAP_H);
}

Here is the call graph for this function:

static XtGeometryResult RadioQueryGeometry ( Widget  w,
XtWidgetGeometry *  intended,
XtWidgetGeometry *  preferred 
) [static]

Definition at line 473 of file xlwradio.c.

{
    RadioWidget rw = (RadioWidget) w;

    preferred->request_mode = CWWidth | CWHeight;
    RadioSize(rw, &preferred->width, &preferred->height);

    if (  ((intended->request_mode & (CWWidth | CWHeight))
              == (CWWidth | CWHeight)) &&
         intended->width == preferred->width &&
         intended->height == preferred->height)
       return XtGeometryYes;
    else if (preferred->width == w->core.width &&
            preferred->height == w->core.height)
       return XtGeometryNo;
    else
       return XtGeometryAlmost;
}

Here is the call graph for this function:

static void RadioResize ( Widget  w) [static]

Definition at line 344 of file xlwradio.c.

{
    RadioWidget rw = (RadioWidget)w;

    /* call parent resize proc */
    SuperClass->core_class.resize(w);

    /* override label offset */

    switch( rw->label.justify ) {
      case XtJustifyLeft:
       rw->label.label_x += (bs(rw) + rw->label.internal_width);
       break;
      case XtJustifyRight:
       break;
      case XtJustifyCenter:
      default:
       rw->label.label_x += (bs(rw) + rw->label.internal_width)/2;
       break;
    }
}

Here is the caller graph for this function:

void RadioSet ( Widget  w,
XEvent *  event,
String params,
Cardinal *  num_params 
)

Definition at line 568 of file xlwradio.c.

{
    RadioWidget      rw = (RadioWidget)w;
    RadioWidgetClass class = (RadioWidgetClass) w->core.widget_class;

    UNUSED(event);
    UNUSED(params);
    UNUSED(num_params);
    
    if( rw->command.set )
      return;

    rw->command.set = TRUE;
    if( XtIsRealized(w) )
      class->radio_class.drawDiamond(w);
}
static Boolean RadioSetValues ( Widget  current,
Widget  request,
Widget  new,
ArgList  args,
Cardinal *  num_args 
) [static]

Definition at line 433 of file xlwradio.c.

{
    RadioWidget oldrw = (RadioWidget) current;
    RadioWidget newrw = (RadioWidget) new;

    UNUSED(request);
    UNUSED(args);
    UNUSED(num_args);
    
    /* Need to find out if the size of the widget changed.  Set new size
     * if it did and resize is permitted.  One way to determine of the
     * widget changed size would be to scan the args list.  Another way
     * is to compare the old and new widgets and see if any of several
     * size-related fields have been changed.  The Label widget chose the
     * former method, but I choose the latter.
     */

    if( newrw->label.resize &&
       ( newrw->core.width != oldrw->core.width ||
         newrw->core.height != oldrw->core.height ||
         newrw->core.border_width != oldrw->core.border_width ) )
    {
      RadioSize(newrw, &newrw->core.width, &newrw->core.height);
    }

    /* The label set values routine can resize the widget. We need to
     * recalculate if this is true.
     */
    if (newrw->label.label_x != oldrw->label.label_x)
    {
      RadioResize (new);
    }
    return FALSE;
}

Here is the call graph for this function:

static void RadioSize ( RadioWidget  rw,
Dimension w,
Dimension h 
) [static]

Definition at line 626 of file xlwradio.c.

{
       *w = rw->label.label_width + bs(rw) + LEFT_OFFSET(rw) + 
              3 * rw->label.internal_width;
       *h = MAX( rw->label.label_height, bs(rw) ) +
              2 * rw->label.internal_width;
}

Here is the caller graph for this function:

static void RadioUnhighlight ( Widget  w,
XEvent *  event,
String params,
Cardinal *  num_params 
) [static]

Definition at line 553 of file xlwradio.c.

{
    RadioWidget      rw = (RadioWidget)w;
    UNUSED(event);
    UNUSED(params);
    UNUSED(num_params);
    
    DrawHighlight(w, rw->command.inverse_GC);
}

Here is the call graph for this function:

void RadioUnset ( Widget  w,
XEvent *  event,
String params,
Cardinal *  num_params 
)

Definition at line 590 of file xlwradio.c.

{
    RadioWidget      rw = (RadioWidget)w;
    RadioWidgetClass class = (RadioWidgetClass) w->core.widget_class;

    UNUSED(event);
    UNUSED(params);
    UNUSED(num_params);
    
    if( ! rw->command.set )
      return;

    rw->command.set = FALSE;
    if( XtIsRealized(w) )
      class->radio_class.drawDiamond(w);
}

Variable Documentation

XtActionsRec actionsList[] [static]
Initial value:
{
  {"highlight",             RadioHighlight},
  {"unhighlight",    RadioUnhighlight},
}

Definition at line 156 of file xlwradio.c.

Definition at line 172 of file xlwradio.c.

WidgetClass radioWidgetClass = (WidgetClass) &radioClassRec

Definition at line 241 of file xlwradio.c.

XtResource resources[] [static]
Initial value:
 {
  {XtNisRadio,  XtCIsRadio, XtRBoolean, sizeof(Boolean),
   offset(isRadio), XtRImmediate, (XtPointer)True },
}

Definition at line 164 of file xlwradio.c.