1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* Copyright © 2020 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <Xkw/KSimpleP.h>
#define SuperClass (&simpleClassRec)
static void
KSimpleClassInitialize(void)
{
XkwInitializeWidgetSet();
}
static void
KSimpleInitialize(Widget request, Widget cnew,
ArgList args, Cardinal *num_args)
{
KSimpleWidget w = (KSimpleWidget) cnew;
(void) request;
(void) args;
(void) num_args;
w->ksimple.surface = NULL;
w->ksimple.surface_width = 0;
w->ksimple.surface_height = 0;
}
static void
KSimpleRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
{
*valueMask &= ~(CWBackPixel);
*valueMask |= (CWBackPixmap);
attributes->background_pixmap = None;
(*ksimpleWidgetClass->core_class.superclass->core_class.realize)
(w, valueMask, attributes);
}
static void
KSimpleDestroy(Widget gw)
{
KSimpleWidget w = (KSimpleWidget) gw;
if (w->ksimple.surface) {
cairo_surface_destroy(w->ksimple.surface);
w->ksimple.surface = NULL;
}
}
static void
KSimpleRedisplay(Widget gw, XEvent *event, Region region)
{
KSimpleWidget w = (KSimpleWidget) gw;
cairo_t *cr = XkwGetCairo(gw);
(void) event;
(void) region;
XkwSetSource(cr, &w->ksimple.background);
cairo_paint(cr);
cairo_destroy(cr);
}
static Boolean
KSimpleSetValues(Widget gcur, Widget greq, Widget gnew,
ArgList args, Cardinal *num_args)
{
KSimpleWidget cur = (KSimpleWidget)gcur;
KSimpleWidget req = (KSimpleWidget)greq;
KSimpleWidget new = (KSimpleWidget)gnew;
(void) req;
(void) args;
(void) num_args;
if (!XkwColorEqual(&cur->ksimple.foreground, &new->ksimple.foreground) ||
!XkwColorEqual(&cur->ksimple.background, &new->ksimple.background))
return True;
return False;
}
#define offset(field) XtOffsetOf(KSimpleRec, ksimple.field)
static XtResource resources[] = {
{ XtNbackgroundColor, XtCBackground, XtRRenderColor, sizeof (XRenderColor),
offset (background), XtRString, XtDefaultBackground },
{ XtNforegroundColor, XtCForeground, XtRRenderColor, sizeof (XRenderColor),
offset (foreground), XtRString, XtDefaultForeground },
{ XtNdpi, XtCDpi, XtRDpi, sizeof(double),
offset (dpi), XtRString, "" },
{XtNwantForward, XtCWantForward, XtRBoolean, sizeof(Boolean),
offset(want_forward), XtRImmediate, (XtPointer) True},
};
#undef offset
KSimpleClassRec ksimpleClassRec = {
/* core */
{
(WidgetClass)SuperClass, /* superclass */
"KSimple", /* class_name */
sizeof(KSimpleRec), /* widget_size */
KSimpleClassInitialize, /* class_initialize */
NULL, /* class_part_initialize */
False, /* class_inited */
KSimpleInitialize, /* initialize */
NULL, /* initialize_hook */
KSimpleRealize, /* realize */
NULL, /* actions */
0, /* num_actions */
resources, /* resources */
XtNumber(resources), /* num_resources */
NULLQUARK, /* xrm_class */
True, /* compress_motion */
True, /* compress_exposure */
True, /* compress_enterleave */
False, /* visible_interest */
KSimpleDestroy, /* destroy */
NULL, /* resize */
KSimpleRedisplay, /* expose */
KSimpleSetValues, /* 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 */
{
XtInheritChangeSensitive, /* change_sensitive */
#ifndef OLDXAW
NULL, /* extension */
#endif
},
/* ksimple */
{
0,
},
};
WidgetClass ksimpleWidgetClass = (WidgetClass)&ksimpleClassRec;
|