"Fossies" - the Fresh Open Source Software Archive

Member "procmeter3-3.6+svn387/xaw/widgets/PMGeneric.c" (24 Dec 2010, 10610 Bytes) of package /linux/misc/procmeter3-3.6+svn387.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PMGeneric.c" see the Fossies "Dox" file reference documentation.

    1 /***************************************
    2   $Header: /home/amb/CVS/procmeter3/xaw/widgets/PMGeneric.c,v 1.4 2001-01-04 19:26:46 amb Exp $
    3 
    4   ProcMeter Generic Widget Source file (for ProcMeter 3.3).
    5   ******************/ /******************
    6   Written by Andrew M. Bishop
    7 
    8   This file Copyright 1996,98,2000 Andrew M. Bishop
    9   It may be distributed under the GNU Public License, version 2, or
   10   any higher version.  See section COPYING of the GNU Public license
   11   for conditions under which this file may be redistributed.
   12   ***************************************/
   13 
   14 
   15 #include <X11/X.h>
   16 #include <X11/Xlib.h>
   17 #include <X11/Xutil.h>
   18 #include <X11/IntrinsicP.h>
   19 #include <X11/StringDefs.h>
   20 #include <X11/CoreP.h>
   21 
   22 #include "PMGenericP.h"
   23 
   24 static void Initialize(ProcMeterGenericWidget request,ProcMeterGenericWidget new);
   25 static void Destroy(ProcMeterGenericWidget pmw);
   26 static Boolean SetValues(ProcMeterGenericWidget current,ProcMeterGenericWidget request,ProcMeterGenericWidget new);
   27 static void Resize(ProcMeterGenericWidget pmw);
   28 static void Redisplay(ProcMeterGenericWidget pmw,XEvent *event,Region region);
   29 static void GenericResize(ProcMeterGenericWidget pmw);
   30 static void GenericUpdate(ProcMeterGenericWidget pmw);
   31 
   32 static XtResource resources[]=
   33 {
   34  /* The body parts. */
   35 
   36  {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
   37   XtOffset(ProcMeterGenericWidget,procmeter_generic.body_pixel),XtRString,XtDefaultForeground},
   38 
   39  /* The label parts. */
   40 
   41  {XtNlabel, XtCLabel, XtRString, sizeof(XtPointer),
   42   XtOffset(ProcMeterGenericWidget,procmeter_generic.label_string), XtRString, "" },
   43  {XtNlabelForeground, XtCForeground, XtRPixel, sizeof(Pixel),
   44   XtOffset(ProcMeterGenericWidget,procmeter_generic.label_pixel),XtRString,XtDefaultForeground},
   45  {XtNlabelPosition, XtCLabelPosition, XtRInt, sizeof(int),
   46   XtOffset(ProcMeterGenericWidget,procmeter_generic.label_pos), XtRString, "-1" },
   47  {XtNlabelFont, XtCFont, XtRFontStruct, sizeof(XFontStruct*),
   48   XtOffset(ProcMeterGenericWidget,procmeter_generic.label_font), XtRString, "-*-*-*-r-normal-sans-8-*-*-*-p-*-*-*"}
   49 };
   50 
   51 /*+ The actual ProcMeter Generic Widget Class Record. +*/
   52 ProcMeterGenericClassRec procMeterGenericClassRec=
   53 {
   54  {
   55   (WidgetClass) &widgetClassRec,
   56   "ProcMeterGeneric",
   57   sizeof(ProcMeterGenericRec),
   58   NULL,
   59   NULL,
   60   FALSE,
   61   (XtInitProc)Initialize,
   62   NULL,
   63   XtInheritRealize,
   64   NULL,
   65   0,
   66   resources,
   67   XtNumber(resources),
   68   NULLQUARK,
   69   TRUE,
   70   XtExposeCompressMaximal|XtExposeGraphicsExpose,
   71   TRUE,
   72   TRUE,
   73   (XtWidgetProc)Destroy,
   74   (XtWidgetProc)Resize,
   75   (XtExposeProc)Redisplay,
   76   (XtSetValuesFunc)SetValues,
   77   NULL,
   78   XtInheritSetValuesAlmost,
   79   NULL,
   80   NULL,
   81   XtVersion,
   82   NULL,
   83   XtInheritTranslations,
   84   NULL,
   85   NULL,
   86   NULL,
   87  },
   88  {
   89   GenericResize,
   90   GenericUpdate
   91  }
   92 };
   93 
   94 /*+ The actual ProcMeter Generic Widget Class Record masquerading as a WidgetClass type. +*/
   95 WidgetClass procMeterGenericWidgetClass=(WidgetClass)&procMeterGenericClassRec;
   96 
   97 
   98 /*++++++++++++++++++++++++++++++++++++++
   99   Initialise a new ProcMeter Generic Widget.
  100 
  101   ProcMeterGenericWidget request The requested parameters.
  102 
  103   ProcMeterGenericWidget new The new parameters that are to be filled in.
  104   ++++++++++++++++++++++++++++++++++++++*/
  105 
  106 static void Initialize(ProcMeterGenericWidget request,ProcMeterGenericWidget new)
  107 {
  108  XGCValues values;
  109 
  110  /* The core widget parts. */
  111 
  112  if(request->core.width ==0)
  113     new->core.width=100;
  114  if(request->core.height==0)
  115     new->core.height=100;
  116 
  117  /* The body parts. */
  118 
  119  values.foreground=new->procmeter_generic.body_pixel;
  120  values.background=new->core.background_pixel;
  121  new->procmeter_generic.body_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&values);
  122 
  123  /* The label parts. */
  124 
  125  if((new->procmeter_generic.label_pos!=ProcMeterLabelTop) &&
  126     (new->procmeter_generic.label_pos!=ProcMeterLabelNone) &&
  127     (new->procmeter_generic.label_pos!=ProcMeterLabelBottom))
  128     new->procmeter_generic.label_pos=ProcMeterLabelNone;
  129 
  130  new->procmeter_generic.label_string=XtNewString(request->procmeter_generic.label_string);
  131 
  132  if(!new->procmeter_generic.label_font)
  133     new->procmeter_generic.label_font=XLoadQueryFont(XtDisplay(new),"-*-*-*-r-normal-sans-8-*-*-*-p-*-*-*");
  134 
  135  values.font=new->procmeter_generic.label_font->fid;
  136  values.foreground=new->procmeter_generic.label_pixel;
  137  values.background=new->core.background_pixel;
  138  new->procmeter_generic.label_gc=XtGetGC((Widget)new,GCForeground|GCBackground|GCFont,&values);
  139 
  140  /* The rest of the sizing. */
  141 
  142  GenericResize(new);
  143 }
  144 
  145 
  146 /*++++++++++++++++++++++++++++++++++++++
  147   Destroy a ProcMeter Generic Widget.
  148 
  149   ProcMeterGenericWidget pmw The Widget to destroy.
  150   ++++++++++++++++++++++++++++++++++++++*/
  151 
  152 static void Destroy(ProcMeterGenericWidget pmw)
  153 {
  154  XtFree((XtPointer)pmw->procmeter_generic.label_string);
  155  XtReleaseGC((Widget)pmw,pmw->procmeter_generic.body_gc);
  156  XtReleaseGC((Widget)pmw,pmw->procmeter_generic.label_gc);
  157 }
  158 
  159 
  160 /*++++++++++++++++++++++++++++++++++++++
  161   The setvalues procedure that is used to set the values internal to the Widget.
  162 
  163   Boolean SetValues Returns True if the Widget is to be redrawn.
  164 
  165   ProcMeterGenericWidget current The current Widget values.
  166 
  167   ProcMeterGenericWidget request The requested Widget values.
  168 
  169   ProcMeterGenericWidget new The new Widget values to be set up.
  170   ++++++++++++++++++++++++++++++++++++++*/
  171 
  172 static Boolean SetValues(ProcMeterGenericWidget current,ProcMeterGenericWidget request,ProcMeterGenericWidget new)
  173 {
  174  Boolean redraw=False;
  175 
  176  /* The body parts. */
  177 
  178  if(request->procmeter_generic.body_pixel!=current->procmeter_generic.body_pixel)
  179    {
  180     XGCValues xgcv;
  181 
  182     XGetGCValues(XtDisplay(new),new->procmeter_generic.body_gc,GCForeground|GCBackground,&xgcv);
  183     XtReleaseGC((Widget)new,new->procmeter_generic.body_gc);
  184     xgcv.foreground=request->procmeter_generic.body_pixel;
  185     xgcv.background=request->core.background_pixel;
  186     new->procmeter_generic.body_gc=XtGetGC((Widget)new,GCForeground|GCBackground,&xgcv);
  187 
  188     redraw=True;
  189    }
  190 
  191  /* The label parts. */
  192 
  193  if(request->procmeter_generic.label_pos!=current->procmeter_generic.label_pos)
  194    {
  195     if((request->procmeter_generic.label_pos!=ProcMeterLabelTop) &&
  196        (request->procmeter_generic.label_pos!=ProcMeterLabelNone) &&
  197        (request->procmeter_generic.label_pos!=ProcMeterLabelBottom))
  198        new->procmeter_generic.label_pos=ProcMeterLabelNone;
  199 
  200     redraw=True;
  201    }
  202 
  203  if(request->procmeter_generic.label_string!=current->procmeter_generic.label_string)
  204    {
  205     XtFree((XtPointer)new->procmeter_generic.label_string);
  206     new->procmeter_generic.label_string=XtNewString(request->procmeter_generic.label_string);
  207 
  208     redraw=True;
  209    }
  210 
  211  if((request->procmeter_generic.label_font !=current->procmeter_generic.label_font)||
  212     (request->procmeter_generic.label_pixel!=current->procmeter_generic.label_pixel))
  213    {
  214     XGCValues xgcv;
  215 
  216     XGetGCValues(XtDisplay(new),new->procmeter_generic.label_gc,GCForeground|GCBackground|GCFont,&xgcv);
  217     XtReleaseGC((Widget)new,new->procmeter_generic.label_gc);
  218     xgcv.font=request->procmeter_generic.label_font->fid;
  219     xgcv.foreground=request->procmeter_generic.label_pixel;
  220     xgcv.background=request->core.background_pixel;
  221     new->procmeter_generic.label_gc=XtGetGC((Widget)new,GCForeground|GCBackground|GCFont,&xgcv);
  222 
  223     redraw=True;
  224    }
  225 
  226  /* Resize if needed */
  227 
  228  if(redraw)
  229     GenericResize(new);
  230 
  231  return(redraw);
  232 }
  233 
  234 
  235 /*++++++++++++++++++++++++++++++++++++++
  236   Resize the ProcMeter Generic Widget.
  237 
  238   ProcMeterGenericWidget pmw The Widget that is resized.
  239   ++++++++++++++++++++++++++++++++++++++*/
  240 
  241 static void Resize(ProcMeterGenericWidget pmw)
  242 {
  243  GenericResize(pmw);
  244 }
  245 
  246 
  247 /*++++++++++++++++++++++++++++++++++++++
  248   Redisplay the ProcMeter Generic Widget.
  249 
  250   ProcMeterGenericWidget pmw The Widget to redisplay.
  251 
  252   XEvent *event The event that caused the redisplay.
  253 
  254   Region region The region that was exposed.
  255   ++++++++++++++++++++++++++++++++++++++*/
  256 
  257 static void Redisplay(ProcMeterGenericWidget pmw,XEvent *event,Region region)
  258 {
  259  if(pmw->core.visible)
  260     GenericUpdate(pmw);
  261 }
  262 
  263 
  264 /*++++++++++++++++++++++++++++++++++++++
  265   Perform all of the sizing on the Widget when it is created/resized.
  266 
  267   ProcMeterGenericWidget pmw The Widget to resize.
  268   ++++++++++++++++++++++++++++++++++++++*/
  269 
  270 static void GenericResize(ProcMeterGenericWidget pmw)
  271 {
  272  /* The label parts. */
  273 
  274  if(pmw->procmeter_generic.label_pos)
  275    {
  276     pmw->procmeter_generic.label_height=pmw->procmeter_generic.label_font->ascent+pmw->procmeter_generic.label_font->descent+2;
  277     pmw->procmeter_generic.label_x=(pmw->core.width-XTextWidth(pmw->procmeter_generic.label_font,pmw->procmeter_generic.label_string,(int)strlen(pmw->procmeter_generic.label_string)))/2;
  278     if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop)
  279        pmw->procmeter_generic.label_y=pmw->procmeter_generic.label_height-1-pmw->procmeter_generic.label_font->descent;
  280     else
  281        pmw->procmeter_generic.label_y=pmw->core.height-pmw->procmeter_generic.label_font->descent;
  282    }
  283  else
  284    {
  285     pmw->procmeter_generic.label_height=0;
  286     pmw->procmeter_generic.label_x=0;
  287     pmw->procmeter_generic.label_y=0;
  288    }
  289 
  290  /* The body parts. */
  291 
  292  pmw->procmeter_generic.body_height=pmw->core.height-pmw->procmeter_generic.label_height;
  293 
  294  if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop)
  295     pmw->procmeter_generic.body_start=pmw->procmeter_generic.label_height;
  296  else
  297     pmw->procmeter_generic.body_start=0;
  298 }
  299 
  300 
  301 /*++++++++++++++++++++++++++++++++++++++
  302   Update the display of the generic part of the widget.
  303 
  304   ProcMeterGenericWidget pmw The Widget to update.
  305   ++++++++++++++++++++++++++++++++++++++*/
  306 
  307 static void GenericUpdate(ProcMeterGenericWidget pmw)
  308 {
  309  if(pmw->core.visible)
  310    {
  311     XClearWindow(XtDisplay(pmw),XtWindow(pmw));
  312 
  313     if(pmw->procmeter_generic.label_pos)
  314       {
  315        XDrawString(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc,
  316                    pmw->procmeter_generic.label_x,pmw->procmeter_generic.label_y,
  317                    pmw->procmeter_generic.label_string,(int)strlen(pmw->procmeter_generic.label_string));
  318 
  319        if(pmw->procmeter_generic.label_pos==ProcMeterLabelTop)
  320           XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc,
  321                     0              ,pmw->procmeter_generic.label_height-1,
  322                     pmw->core.width,pmw->procmeter_generic.label_height-1);
  323        else
  324           XDrawLine(XtDisplay(pmw),XtWindow(pmw),pmw->procmeter_generic.label_gc,
  325                     0              ,pmw->procmeter_generic.body_height,
  326                     pmw->core.width,pmw->procmeter_generic.body_height);
  327       }
  328    }
  329 }