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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
|
/*
* Motif
*
* Copyright (c) 1987-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
/*
* HISTORY
*/
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$TOG: DrawArea2.c /main/11 1999/12/01 17:53:00 jff $"
#endif
#endif
/*
* (c) Copyright 1987, 1988, 1989 HEWLETT-PACKARD COMPANY */
/****************************************
* Automatic test program generation *
* Version 1.2 *
* Wed Apr 5 09:33:51 1989 *
****************************************/
#include <X11/Xlib.h>
#include <testlib.h>
#include "DrawArea2.h"
void ForceResize (w, client_data, call_data)
Widget w;
XtPointer client_data, call_data;
{
Arg args[2];
int n;
Dimension height, width;
n = 0;
XtSetArg (args[n], XmNheight, &height); n++;
XtSetArg (args[n], XmNwidth, &width); n++;
XtGetValues ((Widget) client_data, args, n);
n = 0;
XtSetArg (args[n], XmNheight, height + 50); n++;
XtSetArg (args[n], XmNwidth, width + 50); n++;
XtSetValues ((Widget) client_data, args, n);
}
void DrawStuff(widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
{
XEvent *callingEvent;
XmDrawingAreaCallbackStruct *inputCallback;
static drawKeepStruct fromStruct = {0, 0, 1};
drawKeepStruct toStruct;
GC myGC;
Drawable myWindow;
XtGCMask valueMask;
XGCValues values;
Widget drawingWidget;
int throwaway, i;
char buffer[256];
#ifdef DEBUG
printf (" INPUT CALLBACK\n");
#endif
for (i = 0; i <= 255; i++)
buffer[i] = '\0';
drawingWidget = (Widget) DrawingArea1;
myWindow = XtWindow(drawingWidget);
if (myWindow == NULL)
{ printf ("Null window, dummy.\n");
exit (1);
};
values.foreground = XBlackPixel(display, 0);
values.background = XWhitePixel(display, 0);
values.line_width = 1;
valueMask = GCForeground | GCBackground | GCLineWidth;
myGC = XCreateGC(display, myWindow, valueMask, &values);
inputCallback = (XmDrawingAreaCallbackStruct *) call_data;
callingEvent = (XEvent *) inputCallback->event;
if (callingEvent != NULL)
{
/* do the work on a release only */
if (callingEvent->xbutton.type == ButtonRelease)
{
/* ok, we're gonna fill out the toStruct with info from event*/
toStruct.xpos = callingEvent->xkey.x;
toStruct.ypos = callingEvent->xkey.y;
toStruct.whichButton = callingEvent->xbutton.button;
/* if it's a button1 event, draw the line */
if (toStruct.whichButton == 1)
{
XDrawLine (display, myWindow, myGC, fromStruct.xpos,
fromStruct.ypos,
toStruct.xpos,
toStruct.ypos);
}
fromStruct.xpos = toStruct.xpos;
fromStruct.ypos = toStruct.ypos;
fromStruct.whichButton = toStruct.whichButton;
}
if (callingEvent->xkey.type == KeyPress) {
XLookupString ((XKeyEvent *) callingEvent,
buffer,
sizeof (buffer),
NULL,
NULL);
printf ("Received keypress event for %s (0x%x)\n",
buffer, buffer[0]);
}
}
else
{ printf ("Hmm, the event seems to be NULL.");
}
/* Deallocate the Graphics Context. */
XFreeGC( display, myGC );
}
void DrawAction (w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
static XmDrawingAreaCallbackStruct cb;
cb.reason = XmCR_INPUT;
cb.event = event;
cb.window = XtWindow(w);
DrawStuff (w, NULL, &cb);
}
void ExposeRoutine(w,d1,d2)
Widget w;
XtPointer d1;
XtPointer d2;
{
printf ("An expose event has been generated\n");
}
void HelpRoutine(w,d1,d2)
Widget w;
XtPointer d1;
XtPointer d2;
{
printf ("An help event has been generated\n");
}
void
ResizeRoutine(widget, client_data, call_data)
Widget widget;
XtPointer call_data, client_data;
{
printf ("The resizeCallback was called.\n");
if ((((XmDrawingAreaCallbackStruct *) call_data)->event) == NULL)
printf ("The event is NULL. This is expected.\n");
else printf ("The event is not NULL! This is an ERROR.\n");
/* begin test for PIR 4107 */
if (widget == NULL)
printf ("The widget is NULL! This is an ERROR.\n");
else
printf ("The widget value is not NULL. This is expected.\n");
/* end test for PIR 4107 */
fflush (stdout);
}
void FocusRoutine(w,d1,d2)
Widget w;
XtPointer d1;
XtPointer d2;
{
printf ("An focus event has been generated\n");
}
void main (argc, argv)
int argc;
char **argv;
{
Boolean trace = False;
register int n;
Arg args[MAX_ARGS];
XmString tcs;
Widget BulletinBoard, PushButton, Frame;
Widget popupshell, msg_widget, DrawingArea2;
static XtActionsRec actions[] = {{ "DrawAction", DrawAction}};
static char translation_table[] = "<ButtonPress>: DrawAction()\n\
<KeyPress>: DrawAction()";
/* test for PIR 3062 (will be fixed in 1.2) */
XFontStruct *newfont;
XmFontList newfontlist;
CommonTestInit(argc, argv);
n = 0;
BulletinBoard = XmCreateBulletinBoard(Shell1, "BulletinBoard", args, n);
n = 0;
PushButton = XmCreatePushButton (BulletinBoard, "PushButton", args, n);
n = 0;
XtSetArg(args[n], XmNshadowType, XmSHADOW_ETCHED_IN); n++;
XtSetArg(args[n], XmNshadowThickness, 1); n++;
XtSetArg(args[n], XmNy, 40); n++;
Frame = XmCreateFrame (BulletinBoard, "Frame", args, n);
n = 0;
/* the following resource currently has no effect */
/* the drawing area does not have a drawing routine to support it */
XtSetArg (args[n], XmNshadowThickness, 10); n++;
XtSetArg (args[n], XmNx, 0); n++;
XtSetArg (args[n], XmNy, 200); n++;
XtSetArg (args[n], XmNheight, 300); n++;
XtSetArg (args[n], XmNwidth, 300); n++;
DrawingArea1 = XmCreateDrawingArea(Frame, "DrawingArea1", args, n);
XtAddCallback (DrawingArea1, XmNexposeCallback, ExposeRoutine, NULL);
XtAddCallback (DrawingArea1, XmNinputCallback, DrawStuff, NULL);
XtAddCallback (DrawingArea1, XmNhelpCallback, HelpRoutine, NULL);
/* focus callback is not supported for Drawing Area */
/* XtAddCallback (DrawingArea1, XmNfocusCallback, FocusRoutine, NULL); */
XtAddCallback (DrawingArea1, XmNresizeCallback, ResizeRoutine, NULL);
XtAddCallback (PushButton, XmNactivateCallback, ForceResize, (XtPointer)
DrawingArea1);
XtManageChild(DrawingArea1);
XtManageChild(Frame);
XtManageChild(PushButton);
XtManageChild(BulletinBoard);
XtRealizeWidget(Shell1);
CommonPause(); /* list instructions */
XtRemoveCallback(DrawingArea1, XmNinputCallback, DrawStuff, NULL);
XtAppAddActions(app_context, actions, 1);
XtOverrideTranslations(DrawingArea1,
XtParseTranslationTable(translation_table));
CommonPause();
/* start test for PIR 2772 */
/* test for P3062 */
newfont = XLoadQueryFont(XtDisplay(Shell1), "variable");
newfontlist = XmFontListCreate(newfont, XmSTRING_DEFAULT_CHARSET);
n = 0;
XtSetArg(args[n], XmNwidth, 200); n++;
XtSetArg(args[n], XmNheight, 100); n++;
popupshell = XtCreatePopupShell("Shell2", topLevelShellWidgetClass,
Shell1, args, n);
n = 0;
DrawingArea2 = XmCreateDrawingArea (popupshell, "DrawingArea2",
args, n);
n = 0;
XtSetArg(args[n], XmNlabelString,
XmStringCreate("Put the focus in this window.",
XmSTRING_DEFAULT_CHARSET)); n++;
/* test for P3062 */
XtSetArg(args[n], XmNfontList, newfontlist); n++;
msg_widget = XmCreateLabelGadget (DrawingArea2, "msg_widget", args, n);
XtManageChild(msg_widget);
XtManageChild(DrawingArea2);
XtRealizeWidget(popupshell);
XtPopup(popupshell, XtGrabNone);
CommonPause();
/* end test for PIR 2772 */
XtAppMainLoop(app_context);
}
|