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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
|
/*
* Motif Tools Library, Version 3.1
* $Id$
*
* Written by David Flanagan.
* Copyright (c) 1992-2001 by David Flanagan.
* All Rights Reserved. See the file COPYRIGHT for details.
* This is open source software. See the file LICENSE for details.
* There is no warranty for this software. See NO_WARRANTY for details.
*
* $Log$
* Revision 1.2 2001/10/29 16:27:45 andre
* AA-2001-10-29-0: Fix for weired characters in helper dialogs (PE,Project Configi, Calendar, Cluster Config,
* Complex Config)
* Queue Control Reschedule functionality added (corresponds qmod -r <qname>)
* Cluster config Reschedule Unknown bug fixed
* Job Custom dialogue core dump fix
*
* Revision 1.1.1.1 2001/07/18 11:06:02 root
* Initial checkin.
*
* Revision 1.2 2001/06/12 16:25:28 andre
* *** empty log message ***
*
*
*/
#include <Xmt/Xmt.h>
#include <Xmt/LayoutGP.h>
#include <Xmt/Converters.h>
/* an empty string value unique to us. */
static char empty_string[] = "";
#define offset(field) XtOffsetOf(XmtLayoutStringRec, layout_string.field)
static XtResource resources[] = {
{XmtNlabel, XtCLabel, XtRString,
sizeof(String), offset(label),
XtRString, (XtPointer) empty_string},
{XmtNlabelString, XmCLabelString, XmRXmString,
sizeof(XmString), offset(label_string),
XmRXmString, (XtPointer)NULL},
{XmtNforeground, XtCForeground, XtRPixel,
sizeof(Pixel), offset(foreground),
XtRImmediate, (XtPointer) -1},
{XmtNbackground, XtCBackground, XtRPixel,
sizeof(Pixel), offset(background),
XtRImmediate, (XtPointer) -1}
};
#undef offset
#if NeedFunctionPrototypes
static void Initialize(Widget, Widget, ArgList, Cardinal *);
static void Destroy(Widget);
static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal *);
static void Redisplay(Widget, XEvent *, Region);
static XtGeometryResult QueryGeometry(Widget, XtWidgetGeometry *,
XtWidgetGeometry *);
static void ChangeFont(Widget);
#else
static void Initialize();
static void Destroy();
static Boolean SetValues();
static void Redisplay();
static XtGeometryResult QueryGeometry();
static void ChangeFont();
#endif
#define superclass (&xmtLayoutGadgetClassRec)
externaldef(xmtlayoutstringclasrec)
XmtLayoutStringClassRec xmtLayoutStringClassRec = {
{ /* rect_class fields */
/* superclass */ (WidgetClass)superclass,
/* class_name */ "XmtLayoutString",
/* widget_size */ sizeof(XmtLayoutStringRec),
/* class_initialize */ NULL,
/* class_part_initialize*/ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* rect1 */ NULL,
/* rect2 */ NULL,
/* rect3 */ 0,
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* rect4 */ FALSE,
/* rect5 */ FALSE,
/* rect6 */ FALSE,
/* rect7 */ FALSE,
/* destroy */ Destroy,
/* resize */ NULL,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* rect9 */ NULL,
/* version */ XtVersion,
/* callback_offsets */ NULL,
/* rect10 */ NULL,
/* query_geometry */ QueryGeometry,
/* rect11 */ NULL,
/* extension */ NULL
},
{ /* XmtLayoutGadget field */
/* change_font */ ChangeFont,
},
{ /* XmtLayoutString fields */
/* extension */ NULL
}
};
externaldef(xmtlayoutstringgadgetclass)
WidgetClass xmtLayoutStringGadgetClass = (WidgetClass)&xmtLayoutStringClassRec;
#define MARGINWIDTH 2
#define MARGINHEIGHT 2
#if NeedFunctionPrototypes
static void GetGC(XmtLayoutWidget lw, XmtLayoutStringGadget ls)
#else
static void GetGC(lw, ls)
XmtLayoutWidget lw;
XmtLayoutStringGadget ls;
#endif
{
XGCValues gcv;
if ((ls->layout_string.foreground == -1) ||
(ls->layout_string.foreground == lw->manager.foreground))
ls->layout_string.gc = None;
else {
gcv.foreground = ls->layout_string.foreground;
/* a background for XmStringDrawImage (& Motif2.0 renditions) */
if (ls->layout_string.background != -1)
gcv.background = ls->layout_string.background;
else
gcv.background = lw->core.background_pixel;
/* we need to specify some font so XmDrawString() doesn't barf */
gcv.font = lw->layout.font->fid;
ls->layout_string.gc = XtGetGC((Widget)ls,
GCForeground | GCBackground | GCFont,
&gcv);
}
}
#if NeedFunctionPrototypes
static void GetBackgroundGC(XmtLayoutWidget lw, XmtLayoutStringGadget ls)
#else
static void GetBackgroundGC(lw, ls)
XmtLayoutWidget lw;
XmtLayoutStringGadget ls;
#endif
{
XGCValues gcv;
if ((ls->layout_string.background == -1) ||
(ls->layout_string.background == lw->core.background_pixel))
ls->layout_string.background_gc = NULL;
else {
gcv.foreground = ls->layout_string.background;
ls->layout_string.background_gc =
XtGetGC((Widget)ls, GCForeground, &gcv);
}
}
#if NeedFunctionPrototypes
static void MeasureString(XmtLayoutWidget lw, XmtLayoutStringGadget ls)
#else
static void MeasureString(lw, ls)
XmtLayoutWidget lw;
XmtLayoutStringGadget ls;
#endif
{
if (ls->layout_string.label_string)
#if XmVersion < 2000
XmStringExtent(lw->layout.font_list, ls->layout_string.label_string,
&ls->layout_string.width, &ls->layout_string.height);
#else /* Motif 2.0 or later */
XmStringExtent(lw->layout.render_table, ls->layout_string.label_string,
&ls->layout_string.width, &ls->layout_string.height);
#endif
else
ls->layout_string.width = ls->layout_string.height = 0;
ls->layout_string.width += 2*MARGINWIDTH;
ls->layout_string.height += 2*MARGINHEIGHT;
}
#if NeedFunctionPrototypes
static void ChangeFont(Widget w)
#else
static void ChangeFont(w)
Widget w;
#endif
{
XmtLayoutWidget lw = (XmtLayoutWidget)XtParent(w);
XmtLayoutStringGadget ls = (XmtLayoutStringGadget)w;
MeasureString(lw, ls);
}
/* ARGSUSED */
#if NeedFunctionPrototypes
static void Initialize(Widget request, Widget init,
ArgList arglist, Cardinal *num_args)
#else
static void Initialize(request, init, arglist, num_args)
Widget request;
Widget init;
ArgList arglist;
Cardinal *num_args;
#endif
{
XmtLayoutStringGadget ls = (XmtLayoutStringGadget) init;
XmtLayoutWidget lw = (XmtLayoutWidget) XtParent(init);
Constraint(ls, type) = XmtLayoutString;
/* copy the XmString, if specified */
if (ls->layout_string.label_string)
ls->layout_string.label_string =
XmStringCopy(ls->layout_string.label_string);
else if (ls->layout_string.label) {
/* we don't copy the string; just convert it to an XmString */
/* and then set it to "" because we don't own it. */
ls->layout_string.label_string =
XmtCreateLocalizedXmString((Widget) lw, ls->layout_string.label);
ls->layout_string.label = empty_string;
}
MeasureString(lw, ls);
GetGC(lw, ls);
GetBackgroundGC(lw, ls);
}
#if NeedFunctionPrototypes
static void Destroy(Widget w)
#else
static void Destroy(w)
Widget w;
#endif
{
XmtLayoutStringGadget ls = (XmtLayoutStringGadget) w;
if (ls->layout_string.label_string)
XmStringFree(ls->layout_string.label_string);
if (ls->layout_string.gc)
XtReleaseGC(w, ls->layout_string.gc);
if (ls->layout_string.background_gc)
XtReleaseGC(w, ls->layout_string.background_gc);
}
/* ARGSUSED */
#if NeedFunctionPrototypes
static Boolean SetValues(Widget current, Widget request, Widget set,
ArgList arglist, Cardinal *num_args)
#else
static Boolean SetValues(current, request, set, arglist, num_args)
Widget current;
Widget request;
Widget set;
ArgList arglist;
Cardinal *num_args;
#endif
{
XmtLayoutStringGadget cs = (XmtLayoutStringGadget) current;
XmtLayoutStringGadget ss = (XmtLayoutStringGadget) set;
XmtLayoutWidget lw = (XmtLayoutWidget) XtParent(set);
Boolean redisplay = False;
Boolean relayout = False;
Dimension cs_width, cs_height;
if (ss->layout_string.label_string != cs->layout_string.label_string) {
if (cs->layout_string.label_string)
XmStringFree(cs->layout_string.label_string);
if (ss->layout_string.label_string)
ss->layout_string.label_string =
XmStringCopy(ss->layout_string.label_string);
cs_width = cs->layout_string.width;
cs_height = cs->layout_string.height;
MeasureString(lw, ss);
if (cs_width != ss->layout_string.width ||
cs_height != ss->layout_string.height)
relayout = True;
else
redisplay = True;
}
else if (ss->layout_string.label != empty_string) {
if (cs->layout_string.label_string)
XmStringFree(cs->layout_string.label_string);
ss->layout_string.label_string =
XmtCreateLocalizedXmString((Widget) lw, ss->layout_string.label);
ss->layout_string.label = empty_string;
cs_width = cs->layout_string.width;
cs_height = cs->layout_string.height;
MeasureString(lw, ss);
if (cs_width != ss->layout_string.width ||
cs_height != ss->layout_string.height)
relayout = True;
else
redisplay = True;
}
if (ss->layout_string.foreground != cs->layout_string.foreground) {
if (ss->layout_string.gc) XtReleaseGC(set, ss->layout_string.gc);
GetGC(lw, ss);
redisplay = True;
}
if (ss->layout_string.background != cs->layout_string.background) {
if (ss->layout_string.background_gc)
XtReleaseGC(set, ss->layout_string.gc);
GetBackgroundGC(lw, ss);
redisplay = True;
}
/*
* If the string has changed, then everything will need to be updated.
* Instead of calling _XmtLayoutChildren() directly, though, we just
* set our core.width and core.height fields to their new values,
* The new size will be noticed in Layout.c:ConstraintSetValues(),
* and _XmtLayoutChildren() will be invoked there. This way, if the
* string changes, but the size stays the same, no change will be made.
*/
if (relayout) {
/* _XmtLayoutChildren(lw, True); */
ss->rectangle.width = ss->layout_string.width;
ss->rectangle.height = ss->layout_string.height;
}
/*
* Returning True from this procedure doesn't do any good, presumably
* because the Intrinsics think that we're an Object, not a RectObj
* (This is one of the gross Motif hacks, described in Layout.c)
* So we generate an Expose event ourselves.
*/
if (redisplay && XtIsRealized((Widget)lw)) {
Redisplay((Widget)ss, (XEvent *)NULL, (Region)NULL);
}
else if ( relayout && XtIsRealized((Widget)lw)) {
XClearArea(XtDisplay((Widget)lw), XtWindow((Widget)lw),
cs->rectangle.x, cs->rectangle.y,
cs->rectangle.width, cs->rectangle.height,
True);
}
return False;
}
/* ARGSUSED */
#if NeedFunctionPrototypes
static XtGeometryResult QueryGeometry(Widget w,
XtWidgetGeometry *request,
XtWidgetGeometry *reply)
#else
static XtGeometryResult QueryGeometry(w, request, reply)
Widget w;
XtWidgetGeometry *request;
XtWidgetGeometry *reply;
#endif
{
XmtLayoutStringGadget ls = (XmtLayoutStringGadget) w;
reply->request_mode = CWWidth | CWHeight;
reply->width = ls->layout_string.width;
reply->height = ls->layout_string.height;
return XtGeometryYes;
}
/* ARGSUSED */
#if NeedFunctionPrototypes
static void Redisplay(Widget w, XEvent *event, Region region)
#else
static void Redisplay(w, event, region)
Widget w;
XEvent *event;
Region region;
#endif
{
XmtLayoutStringGadget ls = (XmtLayoutStringGadget) w;
XmtLayoutWidget lw = (XmtLayoutWidget) XtParent(w);
if (lw->core.window == None) return;
if (ls->layout_string.background_gc)
XFillRectangle(XtDisplay((Widget)lw), XtWindow((Widget)lw),
ls->layout_string.background_gc,
ls->rectangle.x, ls->rectangle.y,
ls->rectangle.width, ls->rectangle.height);
XmStringDrawImage(lw->core.screen->display, lw->core.window,
#if XmVersion < 2000
lw->layout.font_list,
#else /* Motif 2.0 or later */
lw->layout.render_table,
#endif
ls->layout_string.label_string,
(ls->layout_string.gc?ls->layout_string.gc:lw->layout.gc),
ls->rectangle.x + MARGINWIDTH,
ls->rectangle.y + MARGINHEIGHT,
ls->rectangle.width - 2*MARGINWIDTH,
XmALIGNMENT_BEGINNING, XmSTRING_DIRECTION_L_TO_R, NULL);
}
#if NeedFunctionPrototypes
Widget XmtCreateLayoutString(Widget parent, String name,
ArgList arglist, Cardinal num_args)
#else
Widget XmtCreateLayoutString(parent, name, arglist, num_args)
Widget parent;
String name;
ArgList arglist;
Cardinal num_args;
#endif
{
return XtCreateWidget(name, xmtLayoutStringGadgetClass, parent,
arglist, num_args);
}
|