Simple.c

Go to the documentation of this file.
00001 /* $XConsortium: Simple.c,v 1.36 94/04/17 20:12:43 kaleb Exp $ */
00002 
00003 /***********************************************************
00004 
00005 Copyright (c) 1987, 1988, 1994  X Consortium
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 
00024 Except as contained in this notice, the name of the X Consortium shall not be
00025 used in advertising or otherwise to promote the sale, use or other dealings
00026 in this Software without prior written authorization from the X Consortium.
00027 
00028 
00029 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
00030 
00031                         All Rights Reserved
00032 
00033 Permission to use, copy, modify, and distribute this software and its 
00034 documentation for any purpose and without fee is hereby granted, 
00035 provided that the above copyright notice appear in all copies and that
00036 both that copyright notice and this permission notice appear in 
00037 supporting documentation, and that the name of Digital not be
00038 used in advertising or publicity pertaining to distribution of the
00039 software without specific, written prior permission.  
00040 
00041 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00042 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00043 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00044 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00045 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00046 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00047 SOFTWARE.
00048 
00049 ******************************************************************/
00050 
00051 #include <stdio.h>
00052 #include <X11/IntrinsicP.h>
00053 #include <X11/StringDefs.h>
00054 #include <X11/Xaw3d/XawInit.h>
00055 #include <X11/Xaw3d/SimpleP.h>
00056 #include <X11/Xmu/Drawing.h>
00057 
00058 #define offset(field) XtOffsetOf(SimpleRec, simple.field)
00059 
00060 static XtResource resources[] = {
00061   {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
00062      offset(cursor), XtRImmediate, (XtPointer) None},
00063   {XtNinsensitiveBorder, XtCInsensitive, XtRPixmap, sizeof(Pixmap),
00064      offset(insensitive_border), XtRImmediate, (XtPointer) NULL},
00065   {XtNpointerColor, XtCForeground, XtRPixel, sizeof(Pixel),
00066      offset(pointer_fg), XtRString, XtDefaultForeground},
00067   {XtNpointerColorBackground, XtCBackground, XtRPixel, sizeof(Pixel),
00068      offset(pointer_bg), XtRString, XtDefaultBackground},
00069   {XtNcursorName, XtCCursor, XtRString, sizeof(String),
00070      offset(cursor_name), XtRString, NULL},
00071   {XtNinternational, XtCInternational, XtRBoolean, sizeof(Boolean),
00072      offset(international), XtRImmediate, (XtPointer) FALSE},
00073 #undef offset
00074 };
00075 
00076 static void ClassPartInitialize(), ClassInitialize(),Realize(),ConvertCursor();
00077 static Boolean SetValues(), ChangeSensitive();
00078 
00079 SimpleClassRec simpleClassRec = {
00080   { /* core fields */
00081     /* superclass               */      (WidgetClass) &widgetClassRec,
00082     /* class_name               */      "Simple",
00083     /* widget_size              */      sizeof(SimpleRec),
00084     /* class_initialize         */      ClassInitialize,
00085     /* class_part_initialize    */      ClassPartInitialize,
00086     /* class_inited             */      FALSE,
00087     /* initialize               */      NULL,
00088     /* initialize_hook          */      NULL,
00089     /* realize                  */      Realize,
00090     /* actions                  */      NULL,
00091     /* num_actions              */      0,
00092     /* resources                */      resources,
00093     /* num_resources            */      XtNumber(resources),
00094     /* xrm_class                */      NULLQUARK,
00095     /* compress_motion          */      TRUE,
00096     /* compress_exposure        */      TRUE,
00097     /* compress_enterleave      */      TRUE,
00098     /* visible_interest         */      FALSE,
00099     /* destroy                  */      NULL,
00100     /* resize                   */      NULL,
00101     /* expose                   */      NULL,
00102     /* set_values               */      SetValues,
00103     /* set_values_hook          */      NULL,
00104     /* set_values_almost        */      XtInheritSetValuesAlmost,
00105     /* get_values_hook          */      NULL,
00106     /* accept_focus             */      NULL,
00107     /* version                  */      XtVersion,
00108     /* callback_private         */      NULL,
00109     /* tm_table                 */      NULL,
00110     /* query_geometry           */      XtInheritQueryGeometry,
00111     /* display_accelerator      */      XtInheritDisplayAccelerator,
00112     /* extension                */      NULL
00113   },
00114   { /* simple fields */
00115     /* change_sensitive         */      ChangeSensitive
00116   }
00117 };
00118 
00119 WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec;
00120 
00121 static void ClassInitialize()
00122 {
00123     static XtConvertArgRec convertArg[] = {
00124         {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
00125              sizeof(Screen *)},
00126         {XtResourceString, (XtPointer) XtNpointerColor, sizeof(Pixel)},
00127         {XtResourceString, (XtPointer) XtNpointerColorBackground, 
00128              sizeof(Pixel)},
00129         {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.colormap),
00130              sizeof(Colormap)}
00131     };
00132 
00133     XawInitializeWidgetSet();
00134     XtSetTypeConverter( XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
00135                        convertArg, XtNumber(convertArg), 
00136                        XtCacheByDisplay, (XtDestructor)NULL);
00137 }
00138 
00139 static void ClassPartInitialize(class)
00140     WidgetClass class;
00141 {
00142     SimpleWidgetClass c     = (SimpleWidgetClass) class;
00143     SimpleWidgetClass super = (SimpleWidgetClass)
00144       c->core_class.superclass;
00145 
00146     if (c->simple_class.change_sensitive == NULL) {
00147         char buf[BUFSIZ];
00148 
00149         (void) sprintf(buf,
00150                 "%s Widget: The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited.",
00151                 c->core_class.class_name);
00152         XtWarning(buf);
00153         c->simple_class.change_sensitive = ChangeSensitive;
00154     }
00155 
00156     if (c->simple_class.change_sensitive == XtInheritChangeSensitive)
00157         c->simple_class.change_sensitive = super->simple_class.change_sensitive;
00158 }
00159 
00160 static void Realize(w, valueMask, attributes)
00161     Widget w;
00162     Mask *valueMask;
00163     XSetWindowAttributes *attributes;
00164 {
00165     Pixmap border_pixmap = 0;
00166     if (!XtIsSensitive(w)) {
00167         /* change border to gray; have to remember the old one,
00168          * so XtDestroyWidget deletes the proper one */
00169         if (((SimpleWidget)w)->simple.insensitive_border == None)
00170             ((SimpleWidget)w)->simple.insensitive_border =
00171                 XmuCreateStippledPixmap(XtScreen(w),
00172                                         w->core.border_pixel, 
00173                                         w->core.background_pixel,
00174                                         w->core.depth);
00175         border_pixmap = w->core.border_pixmap;
00176         attributes->border_pixmap =
00177           w->core.border_pixmap = ((SimpleWidget)w)->simple.insensitive_border;
00178 
00179         *valueMask |= CWBorderPixmap;
00180         *valueMask &= ~CWBorderPixel;
00181     }
00182 
00183     ConvertCursor(w);
00184 
00185     if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None)
00186         *valueMask |= CWCursor;
00187 
00188     XtCreateWindow( w, (unsigned int)InputOutput, (Visual *)CopyFromParent,
00189                     *valueMask, attributes );
00190 
00191     if (!XtIsSensitive(w))
00192         w->core.border_pixmap = border_pixmap;
00193 }
00194 
00195 /*      Function Name: ConvertCursor
00196  *      Description: Converts a name to a new cursor.
00197  *      Arguments: w - the simple widget.
00198  *      Returns: none.
00199  */
00200 
00201 static void
00202 ConvertCursor(w)
00203 Widget w;
00204 {
00205     SimpleWidget simple = (SimpleWidget) w;
00206     XrmValue from, to;
00207     Cursor cursor;
00208    
00209     if (simple->simple.cursor_name == NULL)
00210         return;
00211 
00212     from.addr = (XPointer) simple->simple.cursor_name;
00213     from.size = strlen((char *) from.addr) + 1;
00214 
00215     to.size = sizeof(Cursor);
00216     to.addr = (XPointer) &cursor;
00217 
00218     if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to)) {
00219         if ( cursor !=  None) 
00220             simple->simple.cursor = cursor;
00221     } 
00222     else {
00223         XtAppErrorMsg(XtWidgetToApplicationContext(w),
00224                       "convertFailed","ConvertCursor","XawError",
00225                       "Simple: ConvertCursor failed.",
00226                       (String *)NULL, (Cardinal *)NULL);
00227     }
00228 }
00229 
00230 
00231 /* ARGSUSED */
00232 static Boolean SetValues(current, request, new, args, num_args)
00233     Widget current, request, new;
00234     ArgList args;
00235     Cardinal *num_args;
00236 {
00237     SimpleWidget s_old = (SimpleWidget) current;
00238     SimpleWidget s_new = (SimpleWidget) new;
00239     Boolean new_cursor = FALSE;
00240 
00241     /* this disables user changes after creation*/
00242     s_new->simple.international = s_old->simple.international;
00243 
00244     if ( XtIsSensitive(current) != XtIsSensitive(new) )
00245         (*((SimpleWidgetClass)XtClass(new))->
00246              simple_class.change_sensitive) ( new );
00247 
00248     if (s_old->simple.cursor != s_new->simple.cursor) {
00249         new_cursor = TRUE;
00250     }
00251         
00252 /*
00253  * We are not handling the string cursor_name correctly here.
00254  */
00255 
00256     if ( (s_old->simple.pointer_fg != s_new->simple.pointer_fg) ||
00257         (s_old->simple.pointer_bg != s_new->simple.pointer_bg) ||
00258         (s_old->simple.cursor_name != s_new->simple.cursor_name) ) {
00259         ConvertCursor(new);
00260         new_cursor = TRUE;
00261     }
00262 
00263     if (new_cursor && XtIsRealized(new))
00264         XDefineCursor(XtDisplay(new), XtWindow(new), s_new->simple.cursor);
00265 
00266     return False;   
00267 }
00268 
00269 
00270 static Boolean ChangeSensitive(w)
00271     Widget w;
00272 {
00273     if (XtIsRealized(w)) {
00274         if (XtIsSensitive(w))
00275             if (w->core.border_pixmap != XtUnspecifiedPixmap)
00276                 XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
00277                                         w->core.border_pixmap );
00278             else
00279                 XSetWindowBorder( XtDisplay(w), XtWindow(w), 
00280                                   w->core.border_pixel );
00281         else {
00282             if (((SimpleWidget)w)->simple.insensitive_border == None)
00283                 ((SimpleWidget)w)->simple.insensitive_border =
00284                     XmuCreateStippledPixmap(XtScreen(w),
00285                                             w->core.border_pixel, 
00286                                             w->core.background_pixel,
00287                                             w->core.depth);
00288             XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
00289                                     ((SimpleWidget)w)->
00290                                         simple.insensitive_border );
00291         }
00292     }
00293     return False;
00294 }

Generated on Sun Mar 4 15:03:55 2007 for Scilab [trunk] by  doxygen 1.5.1