summaryrefslogtreecommitdiff
path: root/src/Simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Simple.c')
-rw-r--r--src/Simple.c487
1 files changed, 343 insertions, 144 deletions
diff --git a/src/Simple.c b/src/Simple.c
index 32e6980..bee0d14 100644
--- a/src/Simple.c
+++ b/src/Simple.c
@@ -47,117 +47,237 @@ SOFTWARE.
******************************************************************/
+/* $XFree86: xc/lib/Xaw/Simple.c,v 1.17 2001/12/14 19:54:42 dawes Exp $ */
+
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
-#include <X11/Xaw/XawInit.h>
-#include <X11/Xaw/SimpleP.h>
#include <X11/Xmu/Drawing.h>
+#include <X11/Xmu/SysUtil.h>
+#include <X11/Xaw/SimpleP.h>
+#include <X11/Xaw/XawInit.h>
+#include "Private.h"
+#ifndef OLDXAW
+#include <X11/Xaw/Tip.h>
+#endif
-#define offset(field) XtOffsetOf(SimpleRec, simple.field)
+/*
+ * Class Methods
+ */
+static Bool ChangeSensitive(Widget);
+static void XawSimpleClassInitialize(void);
+static void XawSimpleClassPartInitialize(WidgetClass);
+#ifndef OLDXAW
+static void XawSimpleInitialize(Widget, Widget, ArgList, Cardinal*);
+static void XawSimpleDestroy(Widget);
+static void XawSimpleExpose(Widget, XEvent*, Region);
+#endif
+static void XawSimpleRealize(Widget, Mask*, XSetWindowAttributes*);
+static Boolean XawSimpleSetValues(Widget, Widget, Widget, ArgList, Cardinal*);
+
+/*
+ * Prototypes
+ */
+static void ConvertCursor(Widget);
+
+/*
+ * Initialization
+ */
+#ifndef OLDXAW
+static XtActionsRec actions[] = {
+ {"set-values", XawSetValuesAction},
+ {"get-values", XawGetValuesAction},
+ {"declare", XawDeclareAction},
+ {"call-proc", XawCallProcAction},
+};
+#endif
+#define offset(field) XtOffsetOf(SimpleRec, simple.field)
static XtResource resources[] = {
- {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
- offset(cursor), XtRImmediate, (XtPointer) None},
- {XtNinsensitiveBorder, XtCInsensitive, XtRPixmap, sizeof(Pixmap),
- offset(insensitive_border), XtRImmediate, (XtPointer) NULL},
- {XtNpointerColor, XtCForeground, XtRPixel, sizeof(Pixel),
- offset(pointer_fg), XtRString, XtDefaultForeground},
- {XtNpointerColorBackground, XtCBackground, XtRPixel, sizeof(Pixel),
- offset(pointer_bg), XtRString, XtDefaultBackground},
- {XtNcursorName, XtCCursor, XtRString, sizeof(String),
- offset(cursor_name), XtRString, NULL},
- {XtNinternational, XtCInternational, XtRBoolean, sizeof(Boolean),
- offset(international), XtRImmediate, (XtPointer) FALSE},
+ {
+ XtNcursor,
+ XtCCursor,
+ XtRCursor,
+ sizeof(Cursor),
+ offset(cursor),
+ XtRImmediate,
+ (XtPointer)None
+ },
+ {
+ XtNinsensitiveBorder,
+ XtCInsensitive,
+ XtRPixmap,
+ sizeof(Pixmap),
+ offset(insensitive_border),
+ XtRImmediate,
+ NULL
+ },
+ {
+ XtNpointerColor,
+ XtCForeground,
+ XtRPixel,
+ sizeof(Pixel),
+ offset(pointer_fg),
+ XtRString,
+ XtDefaultForeground
+ },
+ {
+ XtNpointerColorBackground,
+ XtCBackground,
+ XtRPixel,
+ sizeof(Pixel),
+ offset(pointer_bg),
+ XtRString,
+ XtDefaultBackground
+ },
+ {
+ XtNcursorName,
+ XtCCursor,
+ XtRString,
+ sizeof(String),
+ offset(cursor_name),
+ XtRString,
+ NULL
+ },
+ {
+ XtNinternational,
+ XtCInternational,
+ XtRBoolean,
+ sizeof(Boolean),
+ offset(international),
+ XtRImmediate,
+ (XtPointer)False
+ },
+#ifndef OLDXAW
+ {
+ XawNdisplayList,
+ XawCDisplayList,
+ XawRDisplayList,
+ sizeof(XawDisplayList*),
+ offset(display_list),
+ XtRImmediate,
+ NULL
+ },
+ {
+ XtNtip,
+ XtCTip,
+ XtRString,
+ sizeof(String),
+ offset(tip),
+ XtRImmediate,
+ NULL
+ },
+#endif
#undef offset
};
-static void ClassPartInitialize(), ClassInitialize(),Realize(),ConvertCursor();
-static Boolean SetValues(), ChangeSensitive();
-
SimpleClassRec simpleClassRec = {
- { /* core fields */
- /* superclass */ (WidgetClass) &widgetClassRec,
- /* class_name */ "Simple",
- /* widget_size */ sizeof(SimpleRec),
- /* class_initialize */ ClassInitialize,
- /* class_part_initialize */ ClassPartInitialize,
- /* class_inited */ FALSE,
- /* initialize */ NULL,
- /* initialize_hook */ NULL,
- /* realize */ Realize,
- /* actions */ NULL,
- /* num_actions */ 0,
- /* resources */ resources,
- /* num_resources */ XtNumber(resources),
- /* xrm_class */ NULLQUARK,
- /* compress_motion */ TRUE,
- /* compress_exposure */ TRUE,
- /* compress_enterleave */ TRUE,
- /* visible_interest */ FALSE,
- /* destroy */ NULL,
- /* resize */ NULL,
- /* expose */ NULL,
- /* set_values */ SetValues,
- /* set_values_hook */ NULL,
- /* set_values_almost */ XtInheritSetValuesAlmost,
- /* get_values_hook */ NULL,
- /* accept_focus */ NULL,
- /* version */ XtVersion,
- /* callback_private */ NULL,
- /* tm_table */ NULL,
- /* query_geometry */ XtInheritQueryGeometry,
- /* display_accelerator */ XtInheritDisplayAccelerator,
- /* extension */ NULL
+ /* core */
+ {
+ (WidgetClass)&widgetClassRec, /* superclass */
+ "Simple", /* class_name */
+ sizeof(SimpleRec), /* widget_size */
+ XawSimpleClassInitialize, /* class_initialize */
+ XawSimpleClassPartInitialize, /* class_part_initialize */
+ False, /* class_inited */
+#ifndef OLDXAW
+ XawSimpleInitialize, /* initialize */
+#else
+ NULL, /* initialize */
+#endif
+ NULL, /* initialize_hook */
+ XawSimpleRealize, /* realize */
+#ifndef OLDXAW
+ actions, /* actions */
+ XtNumber(actions), /* num_actions */
+#else
+ NULL, /* actions */
+ 0, /* num_actions */
+#endif
+ resources, /* resources */
+ XtNumber(resources), /* num_resources */
+ NULLQUARK, /* xrm_class */
+ True, /* compress_motion */
+ True, /* compress_exposure */
+ True, /* compress_enterleave */
+ False, /* visible_interest */
+#ifndef OLDXAW
+ XawSimpleDestroy, /* destroy */
+#else
+ NULL, /* destroy */
+#endif
+ NULL, /* resize */
+#ifndef OLDXAW
+ XawSimpleExpose, /* expose */
+#else
+ NULL, /* expose */
+#endif
+ XawSimpleSetValues, /* set_values */
+ NULL, /* set_values_hook */
+ XtInheritSetValuesAlmost, /* set_values_almost */
+ NULL, /* get_values_hook */
+ NULL, /* accept_focus */
+ XtVersion, /* version */
+ NULL, /* callback_private */
+ NULL, /* tm_table */
+ XtInheritQueryGeometry, /* query_geometry */
+ XtInheritDisplayAccelerator, /* display_accelerator */
+ NULL, /* extension */
+ },
+ /* simple */
+ {
+ ChangeSensitive, /* change_sensitive */
},
- { /* simple fields */
- /* change_sensitive */ ChangeSensitive
- }
};
WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec;
-static void ClassInitialize()
+static void
+XawSimpleClassInitialize(void)
{
static XtConvertArgRec convertArg[] = {
- {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
- sizeof(Screen *)},
- {XtResourceString, (XtPointer) XtNpointerColor, sizeof(Pixel)},
- {XtResourceString, (XtPointer) XtNpointerColorBackground,
- sizeof(Pixel)},
- {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.colormap),
- sizeof(Colormap)}
+ {
+ XtWidgetBaseOffset,
+ (XtPointer)XtOffsetOf(WidgetRec, core.screen),
+ sizeof(Screen *)
+ },
+ {
+ XtResourceString,
+ (XtPointer)XtNpointerColor,
+ sizeof(Pixel)
+ },
+ {
+ XtResourceString,
+ (XtPointer)XtNpointerColorBackground,
+ sizeof(Pixel)
+ },
+ {
+ XtWidgetBaseOffset,
+ (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
+ sizeof(Colormap)
+ },
};
XawInitializeWidgetSet();
- XtSetTypeConverter( XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
- convertArg, XtNumber(convertArg),
- XtCacheByDisplay, (XtDestructor)NULL);
+ XtSetTypeConverter(XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
+ convertArg, XtNumber(convertArg), XtCacheByDisplay, NULL);
}
-static void ClassPartInitialize(class)
- WidgetClass class;
+static void
+XawSimpleClassPartInitialize(WidgetClass cclass)
{
- SimpleWidgetClass c = (SimpleWidgetClass) class;
- SimpleWidgetClass super = (SimpleWidgetClass) c->core_class.superclass;
+ SimpleWidgetClass c = (SimpleWidgetClass)cclass;
+ SimpleWidgetClass super = (SimpleWidgetClass)c->core_class.superclass;
if (c->simple_class.change_sensitive == NULL) {
char buf[BUFSIZ];
- char* bufp;
- int len;
- char* fmt = "%s Widget: The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited.";
- if ((len = strlen (fmt) + strlen (c->core_class.class_name)) < sizeof buf)
- bufp = buf;
- else
- bufp = XtMalloc (len + 1);
- if (bufp == NULL) {
- bufp = buf;
- strcpy (bufp, "The Simple Widget class method 'change_sensitive' is undefined.\nA function must be defined or inherited.");
- } else
- (void) sprintf(bufp, fmt, c->core_class.class_name);
+ (void)XmuSnprintf(buf, sizeof(buf),
+ "%s Widget: The Simple Widget class method "
+ "'change_sensitive' is undefined.\nA function "
+ "must be defined or inherited.",
+ c->core_class.class_name);
XtWarning(buf);
- if (bufp != buf) XtFree (bufp);
c->simple_class.change_sensitive = ChangeSensitive;
}
@@ -165,13 +285,38 @@ static void ClassPartInitialize(class)
c->simple_class.change_sensitive = super->simple_class.change_sensitive;
}
-static void Realize(w, valueMask, attributes)
- Widget w;
- Mask *valueMask;
- XSetWindowAttributes *attributes;
+#ifndef OLDXAW
+/*ARGSUSED*/
+static void
+XawSimpleInitialize(Widget request, Widget cnew,
+ ArgList args, Cardinal *num_args)
+{
+ SimpleWidget simple = (SimpleWidget)cnew;
+
+ if (simple->simple.tip)
+ simple->simple.tip = XtNewString(simple->simple.tip);
+}
+
+static void
+XawSimpleDestroy(Widget w)
{
- Pixmap border_pixmap;
- if (!XtIsSensitive(w)) {
+ SimpleWidget simple = (SimpleWidget)w;
+
+ if (simple->simple.tip)
+ XtFree((XtPointer)simple->simple.tip);
+}
+#endif
+
+static void
+XawSimpleRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
+{
+#ifndef OLDXAW
+ XawPixmap *pixmap;
+#endif
+ Pixmap border_pixmap = CopyFromParent;
+
+ if (!XtIsSensitive(w))
+ {
/* change border to gray; have to remember the old one,
* so XtDestroyWidget deletes the proper one */
if (((SimpleWidget)w)->simple.insensitive_border == None)
@@ -193,99 +338,153 @@ static void Realize(w, valueMask, attributes)
if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None)
*valueMask |= CWCursor;
- XtCreateWindow( w, (unsigned int)InputOutput, (Visual *)CopyFromParent,
- *valueMask, attributes );
+ XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent,
+ *valueMask, attributes);
if (!XtIsSensitive(w))
w->core.border_pixmap = border_pixmap;
+
+#ifndef OLDXAW
+ if (w->core.background_pixmap > XtUnspecifiedPixmap) {
+ pixmap = XawPixmapFromXPixmap(w->core.background_pixmap, XtScreen(w),
+ w->core.colormap, w->core.depth);
+ if (pixmap && pixmap->mask)
+ XawReshapeWidget(w, pixmap);
+ }
+
+ if (((SimpleWidget)w)->simple.tip)
+ XawTipEnable(w);
+#endif
}
-/* Function Name: ConvertCursor
- * Description: Converts a name to a new cursor.
- * Arguments: w - the simple widget.
- * Returns: none.
+/*
+ * Function:
+ * ConvertCursor
+ *
+ * Parameters:
+ * w - simple widget
+ *
+ * Description:
+ * Converts a name to a new cursor.
*/
-
static void
-ConvertCursor(w)
-Widget w;
+ConvertCursor(Widget w)
{
SimpleWidget simple = (SimpleWidget) w;
XrmValue from, to;
- Cursor cursor;
+ Cursor cursor = None;
if (simple->simple.cursor_name == NULL)
return;
- from.addr = (XPointer) simple->simple.cursor_name;
- from.size = strlen((char *) from.addr) + 1;
+ from.addr = (XPointer)simple->simple.cursor_name;
+ from.size = strlen((char *)from.addr) + 1;
to.size = sizeof(Cursor);
- to.addr = (XPointer) &cursor;
+ to.addr = (XPointer)&cursor;
- if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to)) {
- if ( cursor != None)
- simple->simple.cursor = cursor;
- }
- else {
+ if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to))
+ simple->simple.cursor = cursor;
+ else
XtAppErrorMsg(XtWidgetToApplicationContext(w),
"convertFailed","ConvertCursor","XawError",
"Simple: ConvertCursor failed.",
- (String *)NULL, (Cardinal *)NULL);
- }
+ NULL, NULL);
}
-/* ARGSUSED */
-static Boolean SetValues(current, request, new, args, num_args)
- Widget current, request, new;
- ArgList args;
- Cardinal *num_args;
+/*ARGSUSED*/
+static Boolean
+XawSimpleSetValues(Widget current, Widget request, Widget cnew,
+ ArgList args, Cardinal *num_args)
{
- SimpleWidget s_old = (SimpleWidget) current;
- SimpleWidget s_new = (SimpleWidget) new;
- Boolean new_cursor = FALSE;
+ SimpleWidget s_old = (SimpleWidget)current;
+ SimpleWidget s_new = (SimpleWidget)cnew;
+ Bool new_cursor = False;
- /* this disables user changes after creation*/
+ /* this disables user changes after creation */
s_new->simple.international = s_old->simple.international;
- if ( XtIsSensitive(current) != XtIsSensitive(new) )
- (*((SimpleWidgetClass)XtClass(new))->
- simple_class.change_sensitive) ( new );
+ if (XtIsSensitive(current) != XtIsSensitive(cnew))
+ (*((SimpleWidgetClass)XtClass(cnew))->simple_class.change_sensitive)
+ (cnew);
- if (s_old->simple.cursor != s_new->simple.cursor) {
- new_cursor = TRUE;
- }
+ if (s_old->simple.cursor != s_new->simple.cursor)
+ new_cursor = True;
-/*
- * We are not handling the string cursor_name correctly here.
- */
+ /*
+ * We are not handling the string cursor_name correctly here
+ */
+
+ if (s_old->simple.pointer_fg != s_new->simple.pointer_fg ||
+ s_old->simple.pointer_bg != s_new->simple.pointer_bg ||
+ s_old->simple.cursor_name != s_new->simple.cursor_name) {
+ ConvertCursor(cnew);
+ new_cursor = True;
+ }
- if ( (s_old->simple.pointer_fg != s_new->simple.pointer_fg) ||
- (s_old->simple.pointer_bg != s_new->simple.pointer_bg) ||
- (s_old->simple.cursor_name != s_new->simple.cursor_name) ) {
- ConvertCursor(new);
- new_cursor = TRUE;
+ if (new_cursor && XtIsRealized(cnew)) {
+ if (s_new->simple.cursor != None)
+ XDefineCursor(XtDisplay(cnew), XtWindow(cnew), s_new->simple.cursor);
+ else
+ XUndefineCursor(XtDisplay(cnew), XtWindow(cnew));
+ }
+
+#ifndef OLDXAW
+ if (s_old->core.background_pixmap != s_new->core.background_pixmap) {
+ XawPixmap *opix, *npix;
+
+ opix = XawPixmapFromXPixmap(s_old->core.background_pixmap,
+ XtScreen(s_old), s_old->core.colormap,
+ s_old->core.depth);
+ npix = XawPixmapFromXPixmap(s_new->core.background_pixmap,
+ XtScreen(s_new), s_new->core.colormap,
+ s_new->core.depth);
+ if ((npix && npix->mask) || (opix && opix->mask))
+ XawReshapeWidget(cnew, npix);
}
- if (new_cursor && XtIsRealized(new))
- XDefineCursor(XtDisplay(new), XtWindow(new), s_new->simple.cursor);
+ if (s_old->simple.tip != s_new->simple.tip) {
+ if (s_old->simple.tip)
+ XtFree((XtPointer)s_old->simple.tip);
+ if (s_new->simple.tip)
+ s_new->simple.tip = XtNewString(s_new->simple.tip);
+ }
- return False;
+ if (s_old->simple.tip && !s_new->simple.tip)
+ XawTipDisable(cnew);
+ else if (!s_old->simple.tip && s_new->simple.tip)
+ XawTipEnable(cnew);
+
+ if (s_old->simple.display_list != s_new->simple.display_list)
+ return (True);
+#endif /* OLDXAW */
+
+ return (False);
}
+#ifndef OLDXAW
+static void
+XawSimpleExpose(Widget w, XEvent *event, Region region)
+{
+ SimpleWidget xaw = (SimpleWidget)w;
-static Boolean ChangeSensitive(w)
- Widget w;
+ if (xaw->simple.display_list)
+ XawRunDisplayList(w, xaw->simple.display_list, event, region);
+}
+#endif
+
+static Bool
+ChangeSensitive(Widget w)
{
if (XtIsRealized(w)) {
if (XtIsSensitive(w))
if (w->core.border_pixmap != XtUnspecifiedPixmap)
- XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
- w->core.border_pixmap );
+ XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
+ w->core.border_pixmap);
else
- XSetWindowBorder( XtDisplay(w), XtWindow(w),
- w->core.border_pixel );
+ XSetWindowBorder(XtDisplay(w), XtWindow(w),
+ w->core.border_pixel);
else {
if (((SimpleWidget)w)->simple.insensitive_border == None)
((SimpleWidget)w)->simple.insensitive_border =
@@ -293,10 +492,10 @@ static Boolean ChangeSensitive(w)
w->core.border_pixel,
w->core.background_pixel,
w->core.depth);
- XSetWindowBorderPixmap( XtDisplay(w), XtWindow(w),
- ((SimpleWidget)w)->
- simple.insensitive_border );
+ XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
+ ((SimpleWidget)w)->simple.insensitive_border);
}
}
- return False;
+
+ return (False);
}