00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include <X11/IntrinsicP.h>
00057 #include <X11/Xos.h>
00058 #include <X11/StringDefs.h>
00059 #include <X11/Xmu/Misc.h>
00060
00061 #include <X11/Xaw3d/XawInit.h>
00062 #include <X11/Xaw3d/AsciiText.h>
00063 #include <X11/Xaw3d/Command.h>
00064 #include <X11/Xaw3d/Label.h>
00065 #include <X11/Xaw3d/DialogP.h>
00066 #include <X11/Xaw3d/Cardinals.h>
00067
00068
00069
00070
00071
00072
00073
00074 #define MAGIC_VALUE ((char *) 3)
00075
00076 #define streq(a,b) (strcmp( (a), (b) ) == 0)
00077
00078 static XtResource resources[] = {
00079 {XtNlabel, XtCLabel, XtRString, sizeof(String),
00080 XtOffsetOf(DialogRec, dialog.label), XtRString, NULL},
00081 {XtNvalue, XtCValue, XtRString, sizeof(String),
00082 XtOffsetOf(DialogRec, dialog.value), XtRString, NULL},
00083 {XtNicon, XtCIcon, XtRBitmap, sizeof(Pixmap),
00084 XtOffsetOf(DialogRec, dialog.icon), XtRImmediate, 0},
00085 };
00086
00087 static void Initialize(), ConstraintInitialize(), CreateDialogValueWidget(),
00088 GetValuesHook();
00089
00090 static Boolean SetValues();
00091
00092 DialogClassRec dialogClassRec = {
00093 {
00094 (WidgetClass) &formClassRec,
00095 "Dialog",
00096 sizeof(DialogRec),
00097 XawInitializeWidgetSet,
00098 NULL,
00099 FALSE,
00100 Initialize,
00101 NULL,
00102 XtInheritRealize,
00103 NULL,
00104 0,
00105 resources,
00106 XtNumber(resources),
00107 NULLQUARK,
00108 TRUE,
00109 TRUE,
00110 TRUE,
00111 FALSE,
00112 NULL,
00113 XtInheritResize,
00114 XtInheritExpose,
00115 SetValues,
00116 NULL,
00117 XtInheritSetValuesAlmost,
00118 GetValuesHook,
00119 NULL,
00120 XtVersion,
00121 NULL,
00122 NULL,
00123 XtInheritQueryGeometry,
00124 XtInheritDisplayAccelerator,
00125 NULL
00126 },
00127 {
00128 XtInheritGeometryManager,
00129 XtInheritChangeManaged,
00130 XtInheritInsertChild,
00131 XtInheritDeleteChild,
00132 NULL
00133 },
00134 {
00135 NULL,
00136 0,
00137 sizeof(DialogConstraintsRec),
00138 ConstraintInitialize,
00139 NULL,
00140 NULL,
00141 NULL
00142 },
00143 {
00144 XtInheritLayout
00145 },
00146 {
00147 0
00148 }
00149 };
00150
00151 WidgetClass dialogWidgetClass = (WidgetClass)&dialogClassRec;
00152
00153
00154 static void Initialize(request, new, args, num_args)
00155 Widget request, new;
00156 ArgList args;
00157 Cardinal *num_args;
00158 {
00159 DialogWidget dw = (DialogWidget)new;
00160 Arg arglist[9];
00161 Cardinal arg_cnt = 0;
00162
00163 XtSetArg(arglist[arg_cnt], XtNborderWidth, 0); arg_cnt++;
00164 XtSetArg(arglist[arg_cnt], XtNleft, XtChainLeft); arg_cnt++;
00165
00166 if (dw->dialog.icon != (Pixmap)0) {
00167 XtSetArg(arglist[arg_cnt], XtNbitmap, dw->dialog.icon); arg_cnt++;
00168 XtSetArg(arglist[arg_cnt], XtNright, XtChainLeft); arg_cnt++;
00169 dw->dialog.iconW =
00170 XtCreateManagedWidget( "icon", labelWidgetClass,
00171 new, arglist, arg_cnt );
00172 arg_cnt = 2;
00173 XtSetArg(arglist[arg_cnt], XtNfromHoriz, dw->dialog.iconW);arg_cnt++;
00174 } else dw->dialog.iconW = (Widget)NULL;
00175
00176 XtSetArg(arglist[arg_cnt], XtNlabel, dw->dialog.label); arg_cnt++;
00177 XtSetArg(arglist[arg_cnt], XtNright, XtChainRight); arg_cnt++;
00178
00179 dw->dialog.labelW = XtCreateManagedWidget( "label", labelWidgetClass,
00180 new, arglist, arg_cnt);
00181
00182 if (dw->dialog.iconW != (Widget)NULL &&
00183 (dw->dialog.labelW->core.height < dw->dialog.iconW->core.height)) {
00184 XtSetArg( arglist[0], XtNheight, dw->dialog.iconW->core.height );
00185 XtSetValues( dw->dialog.labelW, arglist, ONE );
00186 }
00187 if (dw->dialog.value != NULL)
00188 CreateDialogValueWidget( (Widget) dw);
00189 else
00190 dw->dialog.valueW = NULL;
00191 }
00192
00193
00194 static void ConstraintInitialize(request, new, args, num_args)
00195 Widget request, new;
00196 ArgList args;
00197 Cardinal *num_args;
00198 {
00199 DialogWidget dw = (DialogWidget)new->core.parent;
00200 DialogConstraints constraint = (DialogConstraints)new->core.constraints;
00201
00202 if (!XtIsSubclass(new, commandWidgetClass))
00203 return;
00204
00205 constraint->form.left = constraint->form.right = XtChainLeft;
00206 if (dw->dialog.valueW == NULL)
00207 constraint->form.vert_base = dw->dialog.labelW;
00208 else
00209 constraint->form.vert_base = dw->dialog.valueW;
00210
00211 if (dw->composite.num_children > 1) {
00212 WidgetList children = dw->composite.children;
00213 Widget *childP;
00214 for (childP = children + dw->composite.num_children - 1;
00215 childP >= children; childP-- ) {
00216 if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW)
00217 break;
00218 if (XtIsManaged(*childP) &&
00219 XtIsSubclass(*childP, commandWidgetClass)) {
00220 constraint->form.horiz_base = *childP;
00221 break;
00222 }
00223 }
00224 }
00225 }
00226
00227 #define ICON 0
00228 #define LABEL 1
00229 #define NUM_CHECKS 2
00230
00231
00232 static Boolean SetValues(current, request, new, in_args, in_num_args)
00233 Widget current, request, new;
00234 ArgList in_args;
00235 Cardinal *in_num_args;
00236 {
00237 DialogWidget w = (DialogWidget)new;
00238 DialogWidget old = (DialogWidget)current;
00239 Arg args[5];
00240 Cardinal num_args;
00241 int i;
00242 Boolean checks[NUM_CHECKS];
00243
00244 for (i = 0; i < NUM_CHECKS; i++)
00245 checks[i] = FALSE;
00246
00247 for (i = 0; i < *in_num_args; i++) {
00248 if (streq(XtNicon, in_args[i].name))
00249 checks[ICON] = TRUE;
00250 if (streq(XtNlabel, in_args[i].name))
00251 checks[LABEL] = TRUE;
00252 }
00253
00254 if (checks[ICON]) {
00255 if (w->dialog.icon != (Pixmap)0) {
00256 XtSetArg( args[0], XtNbitmap, w->dialog.icon );
00257 if (old->dialog.iconW != (Widget)NULL) {
00258 XtSetValues( old->dialog.iconW, args, ONE );
00259 } else {
00260 XtSetArg( args[1], XtNborderWidth, 0);
00261 XtSetArg( args[2], XtNleft, XtChainLeft);
00262 XtSetArg( args[3], XtNright, XtChainLeft);
00263 w->dialog.iconW =
00264 XtCreateWidget( "icon", labelWidgetClass,
00265 new, args, FOUR );
00266 ((DialogConstraints)w->dialog.labelW->core.constraints)->
00267 form.horiz_base = w->dialog.iconW;
00268 XtManageChild(w->dialog.iconW);
00269 }
00270 } else if (old->dialog.icon != (Pixmap)0) {
00271 ((DialogConstraints)w->dialog.labelW->core.constraints)->
00272 form.horiz_base = (Widget)NULL;
00273 XtDestroyWidget(old->dialog.iconW);
00274 w->dialog.iconW = (Widget)NULL;
00275 }
00276 }
00277
00278 if ( checks[LABEL] ) {
00279 num_args = 0;
00280 XtSetArg( args[num_args], XtNlabel, w->dialog.label ); num_args++;
00281 if (w->dialog.iconW != (Widget)NULL &&
00282 (w->dialog.labelW->core.height <= w->dialog.iconW->core.height)) {
00283 XtSetArg(args[num_args], XtNheight, w->dialog.iconW->core.height);
00284 num_args++;
00285 }
00286 XtSetValues( w->dialog.labelW, args, num_args );
00287 }
00288
00289 if ( w->dialog.value != old->dialog.value ) {
00290 if (w->dialog.value == NULL)
00291
00292 XtDestroyWidget(old->dialog.valueW);
00293 else if (old->dialog.value == NULL) {
00294 w->core.width = old->core.width;
00295 w->core.height = old->core.height;
00296 #ifdef notdef
00297
00298
00299
00300
00301
00302 w->form.resize_in_layout = False;
00303 CreateDialogValueWidget( (Widget) w);
00304 w->core.width = w->form.preferred_width;
00305 w->core.height = w->form.preferred_height;
00306 w->form.resize_in_layout = True;
00307 #else
00308 CreateDialogValueWidget( (Widget) w);
00309 #endif
00310 }
00311 else {
00312 Arg args[1];
00313 XtSetArg(args[0], XtNstring, w->dialog.value);
00314 XtSetValues(w->dialog.valueW, args, ONE);
00315 w->dialog.value = MAGIC_VALUE;
00316 }
00317 }
00318 return False;
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 static void
00331 GetValuesHook(w, args, num_args)
00332 Widget w;
00333 ArgList args;
00334 Cardinal * num_args;
00335 {
00336 Arg a[1];
00337 String s;
00338 DialogWidget src = (DialogWidget) w;
00339 int i;
00340
00341 for (i=0; i < *num_args; i++)
00342 if (streq(args[i].name, XtNvalue)) {
00343 XtSetArg(a[0], XtNstring, &s);
00344 XtGetValues(src->dialog.valueW, a, 1);
00345 *((char **) args[i].value) = s;
00346 }
00347 }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 static void
00359 CreateDialogValueWidget(w)
00360 Widget w;
00361 {
00362 DialogWidget dw = (DialogWidget) w;
00363 Arg arglist[10];
00364 Cardinal num_args = 0;
00365
00366 #ifdef notdef
00367 XtSetArg(arglist[num_args], XtNwidth,
00368 dw->dialog.labelW->core.width); num_args++;
00369 #endif
00370 XtSetArg(arglist[num_args], XtNstring, dw->dialog.value); num_args++;
00371 XtSetArg(arglist[num_args], XtNresizable, True); num_args++;
00372 XtSetArg(arglist[num_args], XtNresize, XawtextResizeBoth); num_args++;
00373 XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); num_args++;
00374 XtSetArg(arglist[num_args], XtNfromVert, dw->dialog.labelW); num_args++;
00375 XtSetArg(arglist[num_args], XtNleft, XtChainLeft); num_args++;
00376 XtSetArg(arglist[num_args], XtNright, XtChainRight); num_args++;
00377
00378 dw->dialog.valueW = XtCreateWidget("value", asciiTextWidgetClass,
00379 w, arglist, num_args);
00380
00381
00382
00383
00384 if (dw->composite.num_children > 1) {
00385 WidgetList children = dw->composite.children;
00386 Widget *childP;
00387 for (childP = children + dw->composite.num_children - 1;
00388 childP >= children; childP-- ) {
00389 if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW)
00390 continue;
00391 if (XtIsManaged(*childP) &&
00392 XtIsSubclass(*childP, commandWidgetClass)) {
00393 ((DialogConstraints)(*childP)->core.constraints)->
00394 form.vert_base = dw->dialog.valueW;
00395 }
00396 }
00397 }
00398 XtManageChild(dw->dialog.valueW);
00399
00400
00401
00402
00403
00404 XtSetKeyboardFocus(w, dw->dialog.valueW);
00405 dw->dialog.value = MAGIC_VALUE;
00406 }
00407
00408
00409 void
00410 #if NeedFunctionPrototypes
00411 XawDialogAddButton(Widget dialog, _Xconst char* name, XtCallbackProc function,
00412 XtPointer param)
00413 #else
00414 XawDialogAddButton(dialog, name, function, param)
00415 Widget dialog;
00416 String name;
00417 XtCallbackProc function;
00418 XtPointer param;
00419 #endif
00420 {
00421
00422
00423
00424 Widget button;
00425
00426 button = XtCreateManagedWidget( name, commandWidgetClass, dialog,
00427 (ArgList)NULL, (Cardinal)0 );
00428
00429 if (function != NULL)
00430 XtAddCallback(button, XtNcallback, function, param);
00431 }
00432
00433
00434 char *
00435 #if NeedFunctionPrototypes
00436 XawDialogGetValueString(Widget w)
00437 #else
00438 XawDialogGetValueString(w)
00439 Widget w;
00440 #endif
00441 {
00442 Arg args[1];
00443 char * value;
00444
00445 XtSetArg(args[0], XtNstring, &value);
00446 XtGetValues( ((DialogWidget)w)->dialog.valueW, args, ONE);
00447 return(value);
00448 }