Command.c File Reference

#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xmu/Misc.h>
#include <X11/Xaw3d/XawInit.h>
#include <X11/Xaw3d/CommandP.h>
#include <X11/Xmu/Converters.h>
#include <X11/extensions/shape.h>

Include dependency graph for Command.c:

Go to the source code of this file.

Defines

#define DEFAULT_HIGHLIGHT_THICKNESS   2
#define DEFAULT_SHAPE_HIGHLIGHT   32767
#define offset(field)   XtOffsetOf(CommandRec, field)
#define SuperClass   ((LabelWidgetClass)&labelClassRec)

Functions

static Boolean SetValues ()
static void Initialize ()
static void Redisplay ()
static void Set ()
static void Reset ()
static void Notify ()
static void Unset ()
static void Highlight ()
static void Unhighlight ()
static void Destroy ()
static void PaintCommandWidget ()
static void ClassInitialize ()
static Boolean ShapeButton ()
static void Realize ()
static void Resize ()
static GC Get_GC (CommandWidget cbw, Pixel fg, Pixel bg)
static void Initialize (Widget request, Widget new, ArgList args, Cardinal *num_args)
static Region HighlightRegion (CommandWidget cbw)
static void Set (Widget w, XEvent *event, String *params, Cardinal *num_params)
static void Unset (Widget w, XEvent *event, String *params, Cardinal *num_params)
static void Reset (Widget w, XEvent *event, String *params, Cardinal *num_params)
static void Highlight (Widget w, XEvent *event, String *params, Cardinal *num_params)
static void Unhighlight (Widget w, XEvent *event, String *params, Cardinal *num_params)
static void Notify (Widget w, XEvent *event, String *params, Cardinal *num_params)
static void Redisplay (Widget w, XEvent *event, Region region)
static void PaintCommandWidget (Widget w, XEvent *event, Region region, Boolean change)
static void Destroy (Widget w)
static Boolean SetValues (Widget current, Widget request, Widget new, ArgList args, Cardinal *num_args)
static Boolean ShapeButton (CommandWidget cbw, Boolean checkRectangular)
static void Realize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
static void Resize (Widget w)

Variables

static char defaultTranslations []
static XtResource resources []
static XtActionsRec actionsList []
CommandClassRec commandClassRec
WidgetClass commandWidgetClass = (WidgetClass) &commandClassRec


Define Documentation

#define DEFAULT_HIGHLIGHT_THICKNESS   2

Definition at line 64 of file Command.c.

Referenced by Initialize().

#define DEFAULT_SHAPE_HIGHLIGHT   32767

Definition at line 65 of file Command.c.

Referenced by Initialize().

#define offset ( field   )     XtOffsetOf(CommandRec, field)

Definition at line 81 of file Command.c.

#define SuperClass   ((LabelWidgetClass)&labelClassRec)

Definition at line 117 of file Command.c.


Function Documentation

static void ClassInitialize (  )  [static]

Definition at line 559 of file Command.c.

References NULL, XawInitializeWidgetSet(), XmuCvtStringToShapeStyle(), and XtRShapeStyle.

00560 {
00561     XawInitializeWidgetSet();
00562     XtSetTypeConverter( XtRString, XtRShapeStyle, XmuCvtStringToShapeStyle,
00563                         (XtConvertArgList)NULL, 0, XtCacheNone, (XtDestructor)NULL );
00564 }

Here is the call graph for this function:

static void Destroy ( Widget  w  )  [static]

Definition at line 491 of file Command.c.

References _CommandRec::command, CommandPart::inverse_GC, _CommandRec::label, CommandPart::normal_GC, and LabelPart::normal_GC.

00493 {
00494   CommandWidget cbw = (CommandWidget) w;
00495 
00496   /* so Label can release it */
00497   if (cbw->label.normal_GC == cbw->command.normal_GC)
00498     XtReleaseGC( w, cbw->command.inverse_GC );
00499   else
00500     XtReleaseGC( w, cbw->command.normal_GC );
00501 }

static void Destroy (  ) 

static GC Get_GC ( CommandWidget  cbw,
Pixel  fg,
Pixel  bg 
) [static]

Definition at line 178 of file Command.c.

Referenced by Initialize(), and SetValues().

00181 {
00182   XGCValues     values;
00183   
00184   values.foreground   = fg;
00185   values.background     = bg;
00186   values.font           = cbw->label.font->fid;
00187   values.cap_style = CapProjecting;
00188   
00189   if (cbw->command.highlight_thickness > 1 )
00190     values.line_width   = cbw->command.highlight_thickness;
00191   else 
00192     values.line_width   = 0;
00193   
00194   if ( cbw->simple.international == True )
00195       return XtAllocateGC((Widget)cbw, 0, 
00196                  (GCForeground|GCBackground|GCLineWidth|GCCapStyle),
00197                  &values, GCFont, 0 );
00198   else
00199       return XtGetGC((Widget)cbw,
00200                  (GCForeground|GCBackground|GCFont|GCLineWidth|GCCapStyle),
00201                  &values);
00202 }

Here is the caller graph for this function:

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

Definition at line 336 of file Command.c.

References _CommandRec::command, HighlightAlways, CommandPart::highlighted, HighlightRegion(), HighlightWhenUnset, PaintCommandWidget(), and TRUE.

00341 {
00342   CommandWidget cbw = (CommandWidget)w;
00343 
00344   if ( *num_params == (Cardinal) 0) 
00345     cbw->command.highlighted = HighlightWhenUnset;
00346   else {
00347     if ( *num_params != (Cardinal) 1) 
00348       XtWarning("Too many parameters passed to highlight action table.");
00349     switch (params[0][0]) {
00350     case 'A':
00351     case 'a':
00352       cbw->command.highlighted = HighlightAlways;
00353       break;
00354     default:
00355       cbw->command.highlighted = HighlightWhenUnset;
00356       break;
00357     }
00358   }
00359 
00360   if (XtIsRealized(w))
00361     PaintCommandWidget(w, event, HighlightRegion(cbw), TRUE);
00362 }

Here is the call graph for this function:

static void Highlight (  )  [static]

static Region HighlightRegion ( CommandWidget  cbw  )  [static]

Definition at line 242 of file Command.c.

References Min, NULL, and s.

Referenced by Highlight(), and Unhighlight().

00244 {
00245   static Region outerRegion = NULL, innerRegion, emptyRegion;
00246   Dimension s = cbw->threeD.shadow_width;
00247   XRectangle rect;
00248 
00249   if (cbw->command.highlight_thickness == 0 ||
00250       cbw->command.highlight_thickness >
00251       (Dimension) ((Dimension) Min(cbw->core.width, cbw->core.height)/2))
00252     return(NULL);
00253 
00254   if (outerRegion == NULL) {
00255     /* save time by allocating scratch regions only once. */
00256     outerRegion = XCreateRegion();
00257     innerRegion = XCreateRegion();
00258     emptyRegion = XCreateRegion();
00259   }
00260 
00261   rect.x = rect.y = s;
00262   rect.width = cbw->core.width - 2 * s;
00263   rect.height = cbw->core.height - 2 * s;
00264   XUnionRectWithRegion( &rect, emptyRegion, outerRegion );
00265   rect.x = rect.y += cbw->command.highlight_thickness;
00266   rect.width -= cbw->command.highlight_thickness * 2;
00267   rect.height -= cbw->command.highlight_thickness * 2;
00268   XUnionRectWithRegion( &rect, emptyRegion, innerRegion );
00269   XSubtractRegion( outerRegion, innerRegion, outerRegion );
00270   return outerRegion;
00271 }

Here is the caller graph for this function:

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

Definition at line 207 of file Command.c.

References _CommandRec::command, _CommandRec::core, DEFAULT_HIGHLIGHT_THICKNESS, DEFAULT_SHAPE_HIGHLIGHT, FALSE, LabelPart::foreground, Get_GC(), CommandPart::highlight_thickness, CommandPart::highlighted, HighlightNone, CommandPart::inverse_GC, _CommandRec::label, LabelPart::normal_GC, CommandPart::normal_GC, CommandPart::set, ThreeDPart::shadow_width, CommandPart::shape_style, _CommandRec::threeD, and XawShapeRectangle.

00211 {
00212   CommandWidget cbw = (CommandWidget) new;
00213   int shape_event_base, shape_error_base;
00214 
00215   if (cbw->command.shape_style != XawShapeRectangle
00216       && !XShapeQueryExtension(XtDisplay(new), &shape_event_base, 
00217                                &shape_error_base))
00218       cbw->command.shape_style = XawShapeRectangle;
00219   if (cbw->command.highlight_thickness == DEFAULT_SHAPE_HIGHLIGHT) {
00220       if (cbw->command.shape_style != XawShapeRectangle)
00221           cbw->command.highlight_thickness = 0;
00222       else
00223           cbw->command.highlight_thickness = DEFAULT_HIGHLIGHT_THICKNESS;
00224   }
00225   if (cbw->command.shape_style != XawShapeRectangle) {
00226     cbw->threeD.shadow_width = 0;
00227     cbw->core.border_width = 1;
00228   }
00229 
00230   cbw->command.normal_GC = Get_GC(cbw, cbw->label.foreground, 
00231                                   cbw->core.background_pixel);
00232   cbw->command.inverse_GC = Get_GC(cbw, cbw->core.background_pixel, 
00233                                    cbw->label.foreground);
00234   XtReleaseGC(new, cbw->label.normal_GC);
00235   cbw->label.normal_GC = cbw->command.normal_GC;
00236 
00237   cbw->command.set = FALSE;
00238   cbw->command.highlighted = HighlightNone;
00239 }

Here is the call graph for this function:

static void Initialize ( void   )  [static]

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

Definition at line 381 of file Command.c.

References CommandPart::callbacks, _CommandRec::command, NULL, and CommandPart::set.

00386 {
00387   CommandWidget cbw = (CommandWidget)w; 
00388 
00389   /* check to be sure state is still Set so that user can cancel
00390      the action (e.g. by moving outside the window, in the default
00391      bindings.
00392   */
00393   if (cbw->command.set)
00394     XtCallCallbackList(w, cbw->command.callbacks, (XtPointer) NULL);
00395 }

static void Notify (  ) 

Referenced by TurnOffRadioSiblings(), XawToggleSetCurrent(), and XawToggleUnsetCurrent().

Here is the caller graph for this function:

static void PaintCommandWidget ( Widget  w,
XEvent *  event,
Region  region,
Boolean  change 
) [static]

Definition at line 426 of file Command.c.

References _CommandRec::command, _CommandRec::core, CommandPart::highlight_thickness, CommandPart::highlighted, HighlightNone, HighlightWhenUnset, CommandPart::inverse_GC, _CommandRec::label, Min, CommandPart::normal_GC, LabelPart::normal_GC, NULL, offset, s, CommandPart::set, ThreeDPart::shadow_width, ThreeDClassPart::shadowdraw, SuperClass, _CommandRec::threeD, and _CommandClassRec::threeD_class.

00431 {
00432   CommandWidget cbw = (CommandWidget) w;
00433   CommandWidgetClass cwclass = (CommandWidgetClass) XtClass (w);
00434   Boolean very_thick;
00435   GC norm_gc, rev_gc;
00436   Dimension     s = cbw->threeD.shadow_width;
00437    
00438   very_thick = cbw->command.highlight_thickness >
00439                (Dimension)((Dimension) Min(cbw->core.width, cbw->core.height)/2);
00440 
00441   if (cbw->command.set) {
00442     cbw->label.normal_GC = cbw->command.inverse_GC;
00443     XFillRectangle(XtDisplay(w), XtWindow(w), cbw->command.normal_GC,
00444                    s, s, cbw->core.width - 2 * s, cbw->core.height - 2 * s);
00445     region = NULL;              /* Force label to repaint text. */
00446   }
00447   else
00448     cbw->label.normal_GC = cbw->command.normal_GC;
00449 
00450   if (cbw->command.highlight_thickness <= 0)
00451   {
00452     (*SuperClass->core_class.expose) (w, event, region);
00453     (*cwclass->threeD_class.shadowdraw) (w, event, region, !cbw->command.set);
00454     return;
00455   }
00456 
00457 /*
00458  * If we are set then use the same colors as if we are not highlighted. 
00459  */
00460 
00461   if (cbw->command.set == (cbw->command.highlighted == HighlightNone)) {
00462     norm_gc = cbw->command.inverse_GC;
00463     rev_gc = cbw->command.normal_GC;
00464   }
00465   else {
00466     norm_gc = cbw->command.normal_GC;
00467     rev_gc = cbw->command.inverse_GC;
00468   }
00469 
00470   if ( !( (!change && (cbw->command.highlighted == HighlightNone)) ||
00471           ((cbw->command.highlighted == HighlightWhenUnset) &&
00472            (cbw->command.set))) ) {
00473     if (very_thick) {
00474       cbw->label.normal_GC = norm_gc; /* Give the label the right GC. */
00475       XFillRectangle(XtDisplay(w),XtWindow(w), rev_gc,
00476                      s, s, cbw->core.width - 2 * s, cbw->core.height - 2 * s);
00477     }
00478     else {
00479       /* wide lines are centered on the path, so indent it */
00480       int offset = cbw->command.highlight_thickness/2;
00481       XDrawRectangle(XtDisplay(w),XtWindow(w), rev_gc, s + offset, s + offset, 
00482                      cbw->core.width - cbw->command.highlight_thickness - 2 * s,
00483                      cbw->core.height - cbw->command.highlight_thickness - 2 * s);
00484     }
00485   }
00486   (*SuperClass->core_class.expose) (w, event, region);
00487   (*cwclass->threeD_class.shadowdraw) (w, event, region, !cbw->command.set);
00488 }

static void PaintCommandWidget (  ) 

Referenced by Highlight(), Redisplay(), Set(), Unhighlight(), and Unset().

Here is the caller graph for this function:

static void Realize ( Widget  w,
Mask *  valueMask,
XSetWindowAttributes *  attributes 
) [static]

Definition at line 590 of file Command.c.

References FALSE, and ShapeButton().

00594 {
00595     (*commandWidgetClass->core_class.superclass->core_class.realize)
00596         (w, valueMask, attributes);
00597 
00598     ShapeButton( (CommandWidget) w, FALSE);
00599 }

Here is the call graph for this function:

static void Realize (  )  [static]

static void Redisplay ( Widget  w,
XEvent *  event,
Region  region 
) [static]

Definition at line 409 of file Command.c.

References FALSE, and PaintCommandWidget().

00413 {
00414   PaintCommandWidget(w, event, region, FALSE);
00415 }

Here is the call graph for this function:

static void Redisplay (  ) 

Referenced by ActionNotify(), MakeSetValuesRequest(), Resize(), and XawListChange().

Here is the caller graph for this function:

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

Definition at line 319 of file Command.c.

References _CommandRec::command, CommandPart::highlighted, HighlightNone, CommandPart::set, Unhighlight(), and Unset().

00324 {
00325   CommandWidget cbw = (CommandWidget)w;
00326 
00327   if (cbw->command.set) {
00328     cbw->command.highlighted = HighlightNone;
00329     Unset(w, event, params, num_params);
00330   } else
00331     Unhighlight(w, event, params, num_params);
00332 }

Here is the call graph for this function:

static void Reset (  ) 

static void Resize ( Widget  w  )  [static]

Definition at line 601 of file Command.c.

References FALSE, and ShapeButton().

00603 {
00604     if (XtIsRealized(w)) 
00605         ShapeButton( (CommandWidget) w, FALSE);
00606 
00607     (*commandWidgetClass->core_class.superclass->core_class.resize)(w);
00608 }

Here is the call graph for this function:

static void Resize (  ) 

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

Definition at line 281 of file Command.c.

References _CommandRec::command, NULL, PaintCommandWidget(), CommandPart::set, and TRUE.

00286 {
00287   CommandWidget cbw = (CommandWidget)w;
00288 
00289   if (cbw->command.set)
00290     return;
00291 
00292   cbw->command.set= TRUE;
00293   if (XtIsRealized(w))
00294     PaintCommandWidget(w, event, (Region) NULL, TRUE);
00295 }

Here is the call graph for this function:

static void Set (  ) 

static Boolean SetValues ( Widget  current,
Widget  request,
Widget  new,
ArgList  args,
Cardinal *  num_args 
) [static]

Definition at line 509 of file Command.c.

References _CommandRec::command, _CommandRec::core, FALSE, LabelPart::font, LabelPart::foreground, Get_GC(), CommandPart::highlight_thickness, CommandPart::highlighted, HighlightNone, CommandPart::inverse_GC, _CommandRec::label, CommandPart::normal_GC, LabelPart::normal_GC, CommandPart::set, CommandPart::shape_style, ShapeButton(), and TRUE.

00513 {
00514   CommandWidget oldcbw = (CommandWidget) current;
00515   CommandWidget cbw = (CommandWidget) new;
00516   Boolean redisplay = False;
00517 
00518   if ( oldcbw->core.sensitive != cbw->core.sensitive && !cbw->core.sensitive) {
00519     /* about to become insensitive */
00520     cbw->command.set = FALSE;
00521     cbw->command.highlighted = HighlightNone;
00522     redisplay = TRUE;
00523   }
00524   
00525   if ( (oldcbw->label.foreground != cbw->label.foreground)           ||
00526        (oldcbw->core.background_pixel != cbw->core.background_pixel) ||
00527        (oldcbw->command.highlight_thickness != 
00528                                    cbw->command.highlight_thickness) ||
00529        (oldcbw->label.font != cbw->label.font) ) 
00530   {
00531     if (oldcbw->label.normal_GC == oldcbw->command.normal_GC)
00532         /* Label has release one of these */
00533       XtReleaseGC(new, cbw->command.inverse_GC);
00534     else
00535       XtReleaseGC(new, cbw->command.normal_GC);
00536 
00537     cbw->command.normal_GC = Get_GC(cbw, cbw->label.foreground, 
00538                                     cbw->core.background_pixel);
00539     cbw->command.inverse_GC = Get_GC(cbw, cbw->core.background_pixel, 
00540                                      cbw->label.foreground);
00541     XtReleaseGC(new, cbw->label.normal_GC);
00542     cbw->label.normal_GC = (cbw->command.set
00543                             ? cbw->command.inverse_GC
00544                             : cbw->command.normal_GC);
00545     
00546     redisplay = True;
00547   }
00548 
00549   if ( XtIsRealized(new)
00550        && oldcbw->command.shape_style != cbw->command.shape_style
00551        && !ShapeButton(cbw, TRUE))
00552   {
00553       cbw->command.shape_style = oldcbw->command.shape_style;
00554   }
00555 
00556   return (redisplay);
00557 }

Here is the call graph for this function:

static Boolean SetValues (  )  [static]

static Boolean ShapeButton ( CommandWidget  cbw,
Boolean  checkRectangular 
) [static]

Definition at line 568 of file Command.c.

References TRUE, XawShapeRectangle, XawShapeRoundedRectangle, and XmuReshapeWidget().

00571 {
00572     Dimension corner_size = 0;
00573 
00574     if ( (cbw->command.shape_style == XawShapeRoundedRectangle) ) {
00575         corner_size = (cbw->core.width < cbw->core.height) ? cbw->core.width 
00576                                                            : cbw->core.height;
00577         corner_size = (int) (corner_size * cbw->command.corner_round) / 100;
00578     }
00579 
00580     if (checkRectangular || cbw->command.shape_style != XawShapeRectangle) {
00581         if (!XmuReshapeWidget((Widget) cbw, cbw->command.shape_style,
00582                               corner_size, corner_size)) {
00583             cbw->command.shape_style = XawShapeRectangle;
00584             return(False);
00585         }
00586     }
00587     return(TRUE);
00588 }

Here is the call graph for this function:

static Boolean ShapeButton (  )  [static]

Referenced by Realize(), Resize(), and SetValues().

Here is the caller graph for this function:

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

Definition at line 366 of file Command.c.

References _CommandRec::command, CommandPart::highlighted, HighlightNone, HighlightRegion(), PaintCommandWidget(), and TRUE.

00371 {
00372   CommandWidget cbw = (CommandWidget)w;
00373 
00374   cbw->command.highlighted = HighlightNone;
00375   if (XtIsRealized(w))
00376     PaintCommandWidget(w, event, HighlightRegion(cbw), TRUE);
00377 }

Here is the call graph for this function:

static void Unhighlight (  ) 

Referenced by Highlight(), and Reset().

Here is the caller graph for this function:

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

Definition at line 299 of file Command.c.

References _CommandRec::command, FALSE, NULL, PaintCommandWidget(), CommandPart::set, and TRUE.

00304 {
00305   CommandWidget cbw = (CommandWidget)w;
00306 
00307   if (!cbw->command.set)
00308     return;
00309 
00310   cbw->command.set = FALSE;
00311   if (XtIsRealized(w)) {
00312     XClearWindow(XtDisplay(w), XtWindow(w));
00313     PaintCommandWidget(w, event, (Region) NULL, TRUE);
00314   }
00315 }

Here is the call graph for this function:

static void Unset (  ) 

Referenced by Reset().

Here is the caller graph for this function:


Variable Documentation

XtActionsRec actionsList[] [static]

Initial value:

 {
  {"set",               Set},
  {"notify",            Notify},
  {"highlight",         Highlight},
  {"reset",             Reset},
  {"unset",             Unset},
  {"unhighlight",       Unhighlight}
}

Definition at line 108 of file Command.c.

CommandClassRec commandClassRec

Definition at line 119 of file Command.c.

WidgetClass commandWidgetClass = (WidgetClass) &commandClassRec

Definition at line 169 of file Command.c.

char defaultTranslations[] [static]

Initial value:

    "<EnterWindow>:     highlight()             \n\
     <LeaveWindow>:     reset()                 \n\
     <Btn1Down>:        set()                   \n\
     <Btn1Up>:          notify() unset()        "

Definition at line 75 of file Command.c.

XtResource resources[] [static]

Initial value:

 { 
   {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), 
      offset(command.callbacks), XtRCallback, (XtPointer)NULL},
   {XtNhighlightThickness, XtCThickness, XtRDimension, sizeof(Dimension),
      offset(command.highlight_thickness), XtRImmediate,
      (XtPointer) DEFAULT_SHAPE_HIGHLIGHT},
   {XtNshapeStyle, XtCShapeStyle, XtRShapeStyle, sizeof(int),
      offset(command.shape_style), XtRImmediate, (XtPointer)XawShapeRectangle},
   {XtNcornerRoundPercent, XtCCornerRoundPercent, 
        XtRDimension, sizeof(Dimension),
        offset(command.corner_round), XtRImmediate, (XtPointer) 25},
   {XtNshadowWidth, XtCShadowWidth, XtRDimension, sizeof(Dimension),
      offset(threeD.shadow_width), XtRImmediate, (XtPointer) 2},
   {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
      XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate,
      (XtPointer)0}
}

Definition at line 82 of file Command.c.


Generated on Sun Mar 4 16:01:04 2007 for Scilab [trunk] by  doxygen 1.5.1