1 #ifndef lint
2 static char *RCSid = "$Header: /home/src/X/xpostit/xpostit/Plaid.c,v 2.0 1995/03/27 18:55:53 mjhammel Exp $";
3 #endif
4
5 /*
6 * Plaid.c - code for the plaid widget.
7 *
8 * Based on the Template widget from the X11R4 distribution.
9 *
10 * David A. Curry
11 * SRI International
12 * 333 Ravenswood Avenue
13 * Menlo Park, CA 94025
14 * davy@itstd.sri.com
15 *
16 * $Log: Plaid.c,v $
17 * Revision 2.0 1995/03/27 18:55:53 mjhammel
18 * Initial update to 2.0
19 *
20 * Revision 1.2 90/06/14 11:17:42 davy
21 * Ported to X11 Release 4. Added translations to invoke all actions from
22 * the plaid widget, instead of passing the event back to a single callback.
23 *
24 * Revision 1.1 90/06/13 09:48:39 davy
25 * Initial revision
26 *
27 */
28 /* #include <X11/copyright.h> */
29
30 #include <X11/IntrinsicP.h>
31 #include <X11/StringDefs.h>
32 #include "PlaidP.h"
33
34 #define plaid_width 22
35 #define plaid_height 22
36
37 /*
38 * The bits representing the plaid background.
39 */
40 static char plaid_bits[] = {
41 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
42 0x75, 0xfd, 0x3f, 0xff, 0x57, 0x15, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
43 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0x20, 0xa8, 0x2b,
44 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
45 0xff, 0xff, 0x3f, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
46 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b
47 };
48
49 /*
50 * The resources specific to the plaid widget.
51 */
52 static XtResource resources[] = {
53 #define offset(field) XtOffset(PlaidWidget,plaid.field)
54 { XtNlowerCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
55 offset(lower_callback), XtRCallback, NULL },
56 { XtNraiseCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
57 offset(raise_callback), XtRCallback, NULL },
58 { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
59 offset(foreground), XtRString, "XtDefaultForeground" }
60 #undef offset
61 };
62
63 /*****************************************************************************
64 * Plaid Widget Routines
65 *****************************************************************************/
66
67 /*
68 * RaiseAction - called when raise button is pressed.
69 */
70 static void
RaiseAction(w,event,params,num_params)71 RaiseAction(w, event, params, num_params)
72 Cardinal *num_params; /* unused */
73 String *params; /* unused */
74 XEvent *event;
75 Widget w;
76 {
77 /*
78 * Just pass it off to the user's callback function.
79 */
80 XtCallCallbacks(w, XtNraiseCallback, (caddr_t) event);
81 }
82
83 /*
84 * LowerAction - called when lower button is pressed.
85 */
86 static void
LowerAction(w,event,params,num_params)87 LowerAction(w, event, params, num_params)
88 Cardinal *num_params; /* unused */
89 String *params; /* unused */
90 XEvent *event;
91 Widget w;
92 {
93 /*
94 * Just pass it off to the user's callback function.
95 */
96 XtCallCallbacks(w, XtNlowerCallback, (caddr_t) event);
97 }
98
99 /*
100 * RealizePlaid - realize the window by creating it, and by creating the
101 * plaid background pixmap.
102 */
103 static void
RealizePlaid(w,value_mask,attributes)104 RealizePlaid(w, value_mask, attributes)
105 XSetWindowAttributes *attributes;
106 Mask *value_mask;
107 Widget w;
108 {
109 Pixmap p;
110 Window window;
111 Display *display;
112 PlaidWidget plaidw;
113
114 plaidw = (PlaidWidget) w;
115
116 /*
117 * Create the window.
118 */
119 XtCreateWindow(w, (unsigned int) InputOutput,
120 (Visual *) CopyFromParent, *value_mask, attributes);
121
122 display = XtDisplay(w);
123 window = XtWindow(w);
124
125 /*
126 * Create the plaid pixmap.
127 */
128 p = XCreatePixmapFromBitmapData(display, window, plaid_bits,
129 plaid_width, plaid_height,
130 plaidw->plaid.foreground,
131 w->core.background_pixel,
132 w->core.depth);
133
134 /*
135 * Tile the window.
136 */
137 XSetWindowBackgroundPixmap(display, window, p);
138
139 /*
140 * Now save the pixmap in the core widget.
141 */
142 w->core.background_pixmap = p;
143 }
144
145 /*
146 * DestroyPlaid - free up server resources when widget is destroyed.
147 */
148 static void
DestroyPlaid(w)149 DestroyPlaid(w)
150 Widget w;
151 {
152 /*
153 * All we need to do is get rid of the pixmap we created.
154 */
155 XFreePixmap(XtDisplay(w), w->core.background_pixmap);
156 }
157
158 /*****************************************************************************
159 * Plaid Widget definitions
160 *****************************************************************************/
161
162 /*
163 * Action table. We're only interested in button presses.
164 */
165 static XtActionsRec actions[] =
166 {
167 { "raise", RaiseAction },
168 { "lower", LowerAction }
169 };
170
171 /*
172 * Translation table. We're only interested in button presses.
173 */
174 static char translations[] =
175 "<Btn1Down>: raise() \n\
176 <Btn2Down>: lower() \n\
177 <Btn3Down>: XawPositionSimpleMenu(Menu) MenuPopup(Menu) \n\
178 ";
179
180 /*
181 * The plaid widget class record. Initialization of values.
182 */
183 PlaidClassRec plaidClassRec = {
184 { /* core fields */
185 /* superclass */ (WidgetClass) &widgetClassRec,
186 /* class_name */ "Plaid",
187 /* widget_size */ sizeof(PlaidRec),
188 /* class_initialize */ NULL,
189 /* class_part_initialize */ NULL,
190 /* class_inited */ FALSE,
191 /* initialize */ NULL,
192 /* initialize_hook */ NULL,
193 /* realize */ RealizePlaid,
194 /* actions */ actions,
195 /* num_actions */ XtNumber(actions),
196 /* resources */ resources,
197 /* num_resources */ XtNumber(resources),
198 /* xrm_class */ NULLQUARK,
199 /* compress_motion */ TRUE,
200 /* compress_exposure */ TRUE,
201 /* compress_enterleave */ TRUE,
202 /* visible_interest */ FALSE,
203 /* destroy */ DestroyPlaid,
204 /* resize */ NULL,
205 /* expose */ NULL,
206 /* set_values */ NULL,
207 /* set_values_hook */ NULL,
208 /* set_values_almost */ XtInheritSetValuesAlmost,
209 /* get_values_hook */ NULL,
210 /* accept_focus */ NULL,
211 /* version */ XtVersion,
212 /* callback_private */ NULL,
213 /* tm_table */ translations,
214 /* query_geometry */ XtInheritQueryGeometry,
215 /* display_accelerator */ XtInheritDisplayAccelerator,
216 /* extension */ NULL
217 },
218 { /* plaid fields */
219 /* empty */ 0
220 }
221 };
222
223 /*
224 * The class declaration.
225 */
226 WidgetClass plaidWidgetClass = (WidgetClass)&plaidClassRec;
227