00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <sys/stat.h>
00005 #include <signal.h>
00006 #include <errno.h>
00007 #ifndef WIN32
00008 #include <unistd.h>
00009 #include <string.h>
00010 #include <sys/file.h>
00011 #include <sys/types.h>
00012
00013 #include <X11/Xatom.h>
00014 #include <X11/cursorfont.h>
00015 #include <Xm/MainW.h>
00016 #include <Xm/CascadeB.h>
00017 #include <Xm/Frame.h>
00018 #include <Xm/ScrolledW.h>
00019 #include <Xm/ScrollBar.h>
00020 #include <Xm/RowColumn.h>
00021 #include <Xm/Form.h>
00022 #include <Xm/PushB.h>
00023 #include <Xm/Separator.h>
00024 #include <Xm/Label.h>
00025 #include <Xm/Text.h>
00026 #include <Xm/TextF.h>
00027 #include <Xm/ToggleB.h>
00028 #include <Xm/FileSB.h>
00029 #include <Xm/Scale.h>
00030 #include <Xm/List.h>
00031 #else
00032 #include "win32.h"
00033 #include "win-dialogs.h"
00034 #endif
00035 #include "sic_comm.h"
00036
00037 #include "xinput.h"
00038
00039 static int debugMode = 0;
00040
00041 char window_title[10][TITLELENGTH], helpfilename[10][HLPFILELNGTH];
00042 char main_command[COMMANDLENGTH];
00043
00044 static int update[NSTRUCT];
00045
00046 static int WIN0 = 0;
00047 static int OK = -1;
00048
00049 static int ABORT = -3;
00050
00051 #define MINI(a,b) (((a)<(b))? (a):(b))
00052 #define MAXI(a,b) (((a)>(b))? (a):(b))
00053
00054
00055 #define LABELPROPS \
00056 XmNtraversalOn, TRUE,\
00057 XmNshadowThickness, 0,\
00058 XmNhighlightOnEnter, FALSE,\
00059 XmNalignment,XmALIGNMENT_END, \
00060 NULL
00061
00062 #define REMOVE_CALLBACK(widget,id) \
00063 XtRemoveCallback( widget, \
00064 XmNmotionVerifyCallback,(XtCallbackProc) text_verify, &id);\
00065 XtRemoveCallback( widget, \
00066 XmNmodifyVerifyCallback,(XtCallbackProc) text_verify, &id)
00067
00068 #define UPDATE_STRING(widget) \
00069 if( debugMode)printf( "string=\"%s\"\n",dum);\
00070 XmTextFieldSetString( widget, dum);\
00071 XmTextFieldSetInsertionPosition( widget, strlen( dum))
00072
00073 #define UPDATE_SLIDERPOS \
00074 { char *dum;\
00075 int val;\
00076 dum = (char *) XmTextFieldGetString( sliderchain_w[i]);\
00077 widgets[i].slider.uservalue = \
00078 MINI(MAXI(widgets[i].slider.min, atof( dum)), \
00079 widgets[i].slider.min + widgets[i].slider.width); \
00080 val = (int)( 100*((float) atof( dum) - widgets[i].slider.min)/\
00081 widgets[i].slider.width);\
00082 val = MINI(MAXI(0, val), 100);\
00083 XtVaSetValues( slider_w[i],XmNvalue,val,NULL);\
00084 XtFree( dum);\
00085 }
00086
00087 #define RESTORE_CALLBACK(widget,id) \
00088 XtAddCallback( widget, \
00089 XmNmotionVerifyCallback,(XtCallbackProc) text_verify, &id);\
00090 XtAddCallback( widget, \
00091 XmNmodifyVerifyCallback,(XtCallbackProc) text_verify, &id)
00092
00093 #define ISSAMEWIDGET(i,j) \
00094 ((strcmp( widgets[i].generic.variable,widgets[j].generic.variable) == 0) \
00095 && (widgets[i].generic.type==widgets[j].generic.type))
00096
00097 #define ISSAMEVARIABLE(i,j) \
00098 ((strcmp( widgets[i].generic.variable,widgets[j].generic.variable) == 0))
00099
00100 #define NWINDOWS 10
00101 #define NMAXCHOICE 128
00102
00103 static int nwin;
00104
00105 global_struct widgets[NSTRUCT];
00106 int nb_widgets;
00107
00108 #ifndef WIN32
00109
00110 static Widget toplevel, main_shell, main_w, command_bar, frame;
00111 static Widget fselshell[NSTRUCT], file_w[NSTRUCT], choice_shell[NSTRUCT];
00112 static Widget moreoptionshell[NWINDOWS], rowcol[NWINDOWS];
00113 static Widget buttonform;
00114 static Widget helpshell[NWINDOWS], text_w[NWINDOWS];
00115 static Widget form_w[NSTRUCT], label_w[NSTRUCT];
00116 static Widget separator_w[NSTRUCT], menu_bar, main_go, menu_pane;
00117 static Widget cascade, go_w[NSTRUCT], button, button_w[NSTRUCT];
00118 static Widget helpbutton[NWINDOWS], morehelpbutton[NWINDOWS], morebutton[NWINDOWS];
00119
00120 static Widget chain_w[NSTRUCT];
00121 static Widget showtext_w[NSTRUCT];
00122 static Widget logic_w[NSTRUCT];
00123 static Widget filebutton_w[NSTRUCT], filechain_w[NSTRUCT];
00124 static Widget choice_bar[NSTRUCT], choice_w[NSTRUCT];
00125 static Widget list_w;
00126
00127 static Cursor context_cursor = 0;
00128
00129 static int num_actions[NSTRUCT];
00130
00131 static int hcotep, bcotep;
00132 static Dimension termheight, termwidth;
00133
00134 static Widget sliderchain_w[NSTRUCT], slider_w[NSTRUCT];
00135 static int cb_id[NSTRUCT];
00136 static int moreid[NSTRUCT];
00137 static int revid[NWINDOWS];
00138
00139 static Dimension buttonwidth = 150, helpwidth = 125, morewidth = 200,
00140 width, testwidth, main_titlewidth = 0, titlewidth = 0, scrollheight, scrollwidth;
00141
00142 static Arg args[25];
00143 static XtAppContext app;
00144
00145 static Display *display;
00146 static Window from_window;
00147 static int revert_to;
00148
00149 extern void close_dialog( );
00150 extern void popup_helpshell( );
00151 extern void popup_moreoptionshell( );
00152 extern void create_moreoptionshell( );
00153 extern void create_item( );
00154 extern void set_dim( );
00155 extern void toggled( );
00156 extern void text_verify( );
00157 extern void update_slider( );
00158
00159
00160
00161 extern void send_command( );
00162 extern void popup_help( );
00163 extern void popdown_help( );
00164 extern void popup_moreoption( );
00165 extern void popdown_moreoption( );
00166
00167
00168 static XtActionsRec actions_list[] = {
00169 {"send_command", send_command},
00170 {"popup_help", popup_help},
00171 {"popdown_help", popdown_help},
00172 {"popup_moreoption", popup_moreoption},
00173 {"popdown_moreoption", popdown_moreoption},
00174 };
00175
00176 static char edit_traversal[] = "<Key>Delete: delete-previous-character( )\n\
00177 <Key>BackSpace: delete-previous-character( )\n\
00178 <Key>Left: backward-character( )\n\
00179 <Key>Right: forward-character( )\n\
00180 <Key>Up: traverse-prev( )\n\
00181 <Key>Down: traverse-next( )\n";
00182
00183 static char button_traversal[] = "<Key>Up: PrimitiveTraverseUp( )\n\
00184 <Key>Down: PrimitiveTraverseDown( )\n\
00185 <Key>Left: PrimitiveTraverseLeft( )\n\
00186 <Key>Right: PrimitiveTraverseRight( )\n";
00187
00188 static char command_traversal[] = "<Key>Return: send_command( )\n";
00189 static char help_traversal[] = " <Key>Return: popup_help( )\n";
00190 static char popdownhelp_traversal[] = "<Key>Return: popdown_help( )\n";
00191 static char more_traversal[] = "<Key>Return: popup_moreoption( )\n";
00192 static char popdownmore_traversal[] = "<Key>Return: popdown_moreoption( )\n";
00193
00194 static XWindowAttributes attrib;
00195
00196 void EnterHandler( Widget w, XtPointer data, XKeyEvent * event)
00197 {
00198 XmAnyCallbackStruct cbs;
00199 Boolean bool;
00200 int i;
00201
00202 KeySym symb;
00203 KeyCode enter_code;
00204 char etiq[80];
00205
00206 sprintf( etiq, "%s", "KP_Enter");
00207 symb = XStringToKeysym( etiq);
00208 enter_code = XKeysymToKeycode( display, symb);
00209
00210 if (event->keycode == enter_code) {
00211 XtVaGetValues( w, XmNset, &bool, NULL);
00212 XtVaSetValues( w, XmNset, !bool, NULL);
00213
00214 for (i = 0; i < nb_widgets; i++) {
00215 if (widgets[i].generic.type != LOGIC)
00216 continue;
00217 if (w == logic_w[i])
00218 break;
00219 }
00220 toggled( w, &update[i], &cbs);
00221 }
00222 }
00223
00224 void send_command( w, event)
00225 Widget w;
00226 XKeyEvent *event;
00227 {
00228 int i;
00229
00230 XmAnyCallbackStruct cbs;
00231
00232 for (i = 0; i < nb_widgets; i++) {
00233 if ((w == button_w[i]) || (w == go_w[i]))
00234 break;
00235 }
00236
00237 if (i < nb_widgets)
00238 close_dialog( w, &cb_id[i], &cbs);
00239 else
00240 close_dialog( w, &OK, &cbs);
00241 }
00242
00243 void popup_help( w, event)
00244 Widget w;
00245 XKeyEvent *event;
00246 {
00247 int i = 1;
00248 XmAnyCallbackStruct cbs;
00249
00250 while ((i > 0) && (i <= nwin)) {
00251 if ((w == helpbutton[i]) || (w == morehelpbutton[i])) {
00252 popup_helpshell( w, &cb_id[i], &cbs);
00253 break;
00254 }
00255 i++;
00256 }
00257 }
00258
00259 void popup_moreoption( w, event)
00260 Widget w;
00261 XKeyEvent *event;
00262 {
00263 int i = 1;
00264 XmAnyCallbackStruct cbs;
00265
00266 while ((i > 0) && (i <= nwin)) {
00267 if (w == morebutton[i]) {
00268 popup_moreoptionshell( w, &cb_id[i], &cbs);
00269 break;
00270 }
00271 i++;
00272 }
00273 }
00274
00275
00276 void save_context( int win)
00277 {
00278 int i, j, length;
00279 Boolean bool;
00280 char *dum;
00281
00282 for (i = 0; i < nb_widgets; i++) {
00283 if (win)
00284 if (widgets[i].generic.window_id != win)
00285 continue;
00286
00287 switch (widgets[i].generic.type) {
00288 case LOGIC:
00289 XtVaGetValues( logic_w[i], XmNset, &bool, NULL);
00290 widgets[i].logic.userlogic = bool;
00291 break;
00292 case CHAIN:
00293 dum = (char *)XmTextFieldGetString( chain_w[i]);
00294 strncpy( widgets[i].chain.userchain, dum, CHAINLENGTH);
00295
00296 XtFree( dum);
00297 break;
00298 case CHOICE:
00299 dum = (char *)XmTextFieldGetString( choice_w[i]);
00300 length = strlen( dum);
00301
00302 if (widgets[i].choice.mode == 1) {
00303 for (j = 0; j < widgets[i].choice.nchoices; j++) {
00304
00305 if (length == strlen( widgets[i].choice.choices[j])) {
00306 if (strncmp( dum, widgets[i].choice.choices[j], strlen( widgets[i].choice.choices[j])) == 0)
00307 break;
00308 }
00309 }
00310 sprintf( dum, "%d", (j + 1));
00311 }
00312 strncpy( widgets[i].choice.userchoice, dum, CHAINLENGTH);
00313
00314 XtFree( dum);
00315 break;
00316 case BROWSER:
00317 dum = (char *)XmTextFieldGetString( filechain_w[i]);
00318 strncpy( widgets[i].file.userchain, dum, CHAINLENGTH);
00319
00320
00321 XtFree( dum);
00322 break;
00323 }
00324 }
00325 }
00326
00327 void close_dialog( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00328 {
00329
00330
00331
00332
00333
00334 char return_command[COMMANDLENGTH];
00335
00336
00337
00338
00339
00340
00341
00342
00343 if (*tag == OK)
00344 strcpy( return_command, main_command);
00345 else if (*tag >= 0)
00346 strcpy( return_command, widgets[*tag].button.command);
00347 else
00348 return_command[0] = '\0';
00349
00350
00351 save_context( WIN0);
00352
00353 if (on_close_dialog( return_command, *tag) == -1)
00354 XBell( display, 0);
00355 }
00356
00357
00358
00359 void create_actionarea( int ind)
00360 {
00361
00362 buttonform = XtVaCreateManagedWidget( "form", xmFormWidgetClass, rowcol[ind], XmNfractionBase, 59, NULL);
00363
00364
00365 go_w[revid[ind]] =
00366 XtVaCreateManagedWidget( "Go",
00367 xmPushButtonWidgetClass,
00368 buttonform,
00369 XmNtraversalOn, TRUE,
00370 XmNleftAttachment, XmATTACH_FORM,
00371 XmNtopAttachment, XmATTACH_FORM,
00372 XmNbottomAttachment, XmATTACH_FORM,
00373 XmNrightAttachment, XmATTACH_POSITION,
00374 XmNrightPosition, 19, XmNshowAsDefault, 0, XmNdefaultButtonShadowThickness, 1, NULL);
00375 XtAddCallback( go_w[revid[ind]], XmNactivateCallback, (XtCallbackProc) close_dialog, &revid[ind]);
00376 XtAugmentTranslations( go_w[revid[ind]], XtParseTranslationTable( button_traversal));
00377 XtOverrideTranslations( go_w[revid[ind]], XtParseTranslationTable( command_traversal));
00378
00379
00380 button =
00381 XtVaCreateManagedWidget( "Dismiss",
00382 xmPushButtonWidgetClass,
00383 buttonform,
00384 XmNtraversalOn, TRUE,
00385 XmNleftAttachment, XmATTACH_POSITION,
00386 XmNleftPosition, 20,
00387 XmNtopAttachment, XmATTACH_FORM,
00388 XmNbottomAttachment, XmATTACH_FORM,
00389 XmNrightAttachment, XmATTACH_POSITION,
00390 XmNrightPosition, 39, XmNshowAsDefault, 1, XmNdefaultButtonShadowThickness, 1, NULL);
00391 XtAddCallback( button, XmNactivateCallback, (XtCallbackProc) popdown_moreoption, &cb_id[ind]);
00392 XtAugmentTranslations( button, XtParseTranslationTable( button_traversal));
00393 XtOverrideTranslations( button, XtParseTranslationTable( popdownmore_traversal));
00394
00395
00396
00397 morehelpbutton[ind] =
00398 XtVaCreateManagedWidget( "Help",
00399 xmPushButtonWidgetClass,
00400 buttonform,
00401 XmNtraversalOn, TRUE,
00402 XmNleftAttachment, XmATTACH_POSITION,
00403 XmNleftPosition, 40,
00404 XmNrightAttachment, XmATTACH_FORM,
00405 XmNtopAttachment, XmATTACH_FORM,
00406 XmNbottomAttachment, XmATTACH_FORM, XmNshowAsDefault, 0, XmNdefaultButtonShadowThickness, 1, NULL);
00407 XtAddCallback( morehelpbutton[ind], XmNactivateCallback, (XtCallbackProc) popup_helpshell, &cb_id[ind]);
00408 XtAugmentTranslations( morehelpbutton[ind], XtParseTranslationTable( button_traversal));
00409 XtOverrideTranslations( morehelpbutton[ind], XtParseTranslationTable( help_traversal));
00410 }
00411
00412
00413
00414 void popup_moreoptionshell( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00415 {
00416 int i;
00417 Dimension shellwidth, shellheight;
00418
00419 if (moreoptionshell[*tag] == NULL) {
00420 create_moreoptionshell( *tag);
00421 for (i = 0; i < nb_widgets; i++) {
00422 if (widgets[i].generic.window_id == *tag) {
00423 create_item( i);
00424 set_dim( i);
00425 }
00426 }
00427 create_actionarea( *tag);
00428 XtRealizeWidget( moreoptionshell[*tag]);
00429
00430
00431
00432
00433 XtVaGetValues( moreoptionshell[*tag], XmNwidth, &shellwidth, XmNheight, &shellheight, NULL);
00434 if (debugMode)
00435 printf( "popup_moreoptionshell:width=%d\n", shellwidth);
00436 if (debugMode)
00437 printf( "popup_moreoptionshell:height=%d\n", shellheight);
00438
00439 XtVaSetValues( moreoptionshell[*tag], XmNwidth, 500, XmNheight, 300, NULL);
00440 XtVaSetValues( moreoptionshell[*tag], XmNmaxWidth, shellwidth, XmNmaxHeight, shellheight, NULL);
00441 XtVaSetValues( moreoptionshell[*tag], XmNminWidth, shellwidth, XmNminHeight, shellheight, NULL);
00442 } else {
00443 Display *disp;
00444 Window win;
00445
00446 XtMapWidget( moreoptionshell[*tag]);
00447 win = XtWindow( moreoptionshell[*tag]);
00448 disp = XtDisplay( moreoptionshell[*tag]);
00449 XRaiseWindow( disp, win);
00450 }
00451 }
00452 void popdown_moreoption( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00453 {
00454
00455 XtUnmapWidget( XtParent( XtParent( XtParent( w))));
00456 }
00457
00458 void destroy_moreoption( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00459 {
00460 moreoptionshell[*tag] = NULL;
00461 save_context( *tag);
00462 popup_moreoptionshell( w, tag, cbs);
00463 }
00464
00465 void toggled( w, update_elsewhere, cbs)
00466 Widget w;
00467 int *update_elsewhere;
00468 XmAnyCallbackStruct *cbs;
00469 {
00470 XmString label;
00471 Boolean bool;
00472 int i, j;
00473
00474 XtVaGetValues( w, XmNset, &bool, NULL);
00475
00476 label = (bool) ? XmStringCreateLocalized( "Yes ") : XmStringCreateLocalized( "No ");
00477
00478 XtVaSetValues( w, XmNlabelString, label, NULL);
00479 if (*update_elsewhere) {
00480 if (debugMode)
00481 printf( "update\n");
00482 for (i = 0; i < nb_widgets; i++) {
00483 if (widgets[i].generic.type != LOGIC)
00484 continue;
00485 if (w == logic_w[i])
00486 break;
00487 }
00488 for (j = 0; j < nb_widgets; j++) {
00489 if ((j != i) && ISSAMEWIDGET(i, j)) {
00490 if (debugMode)
00491 printf( "update %d\n", j);
00492 XtVaSetValues( logic_w[j], XmNset, bool, XmNlabelString, label, NULL);
00493 }
00494 }
00495 }
00496 }
00497
00498 static void fsel_ok( Widget w, int *tag, XmFileSelectionBoxCallbackStruct * cbs)
00499 {
00500 int i;
00501 char *dum;
00502
00503 dum = (char *)XmTextFieldGetString( file_w[*tag]);
00504
00505 if (update[*tag]) {
00506 REMOVE_CALLBACK(filechain_w[*tag], cb_id[*tag]);
00507 }
00508 UPDATE_STRING(filechain_w[*tag]);
00509 if (update[*tag]) {
00510 RESTORE_CALLBACK(filechain_w[*tag], cb_id[*tag]);
00511 }
00512
00513 for (i = 0; i < nb_widgets; i++) {
00514 if ((i != *tag) && ISSAMEVARIABLE(i, *tag)) {
00515 switch (widgets[i].generic.type) {
00516 case CHAIN:
00517 REMOVE_CALLBACK(chain_w[i], cb_id[i]);
00518 UPDATE_STRING(chain_w[i]);
00519
00520 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
00521 break;
00522
00523
00524
00525
00526
00527
00528
00529
00530 case CHOICE:
00531 REMOVE_CALLBACK(choice_w[i], cb_id[i]);
00532 UPDATE_STRING(choice_w[i]);
00533 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
00534 break;
00535 case BROWSER:
00536 REMOVE_CALLBACK(filechain_w[i], cb_id[i]);
00537 UPDATE_STRING(filechain_w[i]);
00538 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
00539 break;
00540 }
00541 }
00542 }
00543 XtUnmapWidget( fselshell[*tag]);
00544 XtFree( dum);
00545 }
00546
00547 static void fsel_cancel( Widget w, int *tag, XmFileSelectionBoxCallbackStruct * cbs)
00548 {
00549 XtUnmapWidget( fselshell[*tag]);
00550 }
00551
00552 void destroy_fselshell( w, tag, cbs)
00553 Widget w;
00554 int *tag;
00555 XmAnyCallbackStruct *cbs;
00556 {
00557 fselshell[*tag] = NULL;
00558 }
00559
00560 void create_fileselbox( w, tag, cbs)
00561 Widget w;
00562 int *tag;
00563 XmAnyCallbackStruct *cbs;
00564 {
00565 Widget fselbox, okbutton, cancelbutton, filter_w, dialog_list;
00566 XmString filestring, filterstring;
00567
00568 if (fselshell[*tag] != NULL) {
00569 XtMapWidget( fselshell[*tag]);
00570 return;
00571 }
00572
00573 fselshell[*tag] = XtVaAppCreateShell( widgets[*tag].file.label, "fselshell", topLevelShellWidgetClass, display, NULL);
00574 XtAddCallback( fselshell[*tag], XtNdestroyCallback, (XtCallbackProc) destroy_fselshell, &cb_id[*tag]);
00575
00576 fselbox = (Widget) XmCreateFileSelectionBox( fselshell[*tag], "fselbox", NULL, 0);
00577 XtManageChild( fselbox);
00578
00579 okbutton = XmFileSelectionBoxGetChild( fselbox, XmDIALOG_OK_BUTTON);
00580
00581 XtAddCallback( okbutton, XmNactivateCallback, (XtCallbackProc) fsel_ok, tag);
00582
00583 cancelbutton = XmFileSelectionBoxGetChild( fselbox, XmDIALOG_CANCEL_BUTTON);
00584
00585 XtAddCallback( cancelbutton, XmNactivateCallback, (XtCallbackProc) fsel_cancel, tag);
00586
00587
00588 filter_w = XmFileSelectionBoxGetChild( fselbox, XmDIALOG_FILTER_TEXT);
00589
00590 filterstring = XmStringCreateLocalized( widgets[*tag].file.filter);
00591
00592
00593 XmFileSelectionDoSearch( fselbox, filterstring);
00594
00595 file_w[*tag] = XmFileSelectionBoxGetChild( fselbox, XmDIALOG_TEXT);
00596
00597 dialog_list = XmFileSelectionBoxGetChild( fselbox, XmDIALOG_LIST);
00598
00599 filestring = XmStringCreateLocalized( widgets[*tag].file.userchain);
00600
00601
00602
00603 XmListSelectItem( dialog_list, filestring, True);
00604
00605 XmTextFieldSetString( filter_w, widgets[*tag].file.filter);
00606 XmTextFieldSetString( file_w[*tag], widgets[*tag].file.userchain);
00607
00608 XtRealizeWidget( fselshell[*tag]);
00609
00610
00611
00612
00613
00614 }
00615
00616 void select_chain( Widget w, int *tag, XmRowColumnCallbackStruct * cbs)
00617 {
00618 int i;
00619
00620 if (update[*tag]) {
00621 REMOVE_CALLBACK(choice_w[*tag], cb_id[*tag]);
00622 }
00623 XmTextFieldSetString( choice_w[*tag], XtName( w));
00624 if (update[*tag]) {
00625 RESTORE_CALLBACK(choice_w[*tag], cb_id[*tag]);
00626 }
00627
00628 for (i = 0; i < nb_widgets; i++) {
00629 if ((i != *tag) && ISSAMEVARIABLE(i, *tag)) {
00630 switch (widgets[i].generic.type) {
00631 case CHAIN:
00632 REMOVE_CALLBACK(chain_w[i], cb_id[i]);
00633 XmTextFieldSetString( chain_w[i], XtName( w));
00634 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
00635 break;
00636
00637
00638
00639
00640
00641
00642
00643
00644 case CHOICE:
00645 REMOVE_CALLBACK(choice_w[i], cb_id[i]);
00646 XmTextFieldSetString( choice_w[i], XtName( w));
00647 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
00648 break;
00649 case BROWSER:
00650 REMOVE_CALLBACK(filechain_w[i], cb_id[i]);
00651 XmTextFieldSetString( filechain_w[i], XtName( w));
00652 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
00653 break;
00654 case SLIDER:
00655 REMOVE_CALLBACK(sliderchain_w[i], cb_id[i]);
00656 XmTextFieldSetString( sliderchain_w[i], XtName( w));
00657 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
00658 UPDATE_SLIDERPOS;
00659 break;
00660 }
00661 }
00662 }
00663 }
00664
00665 void destroy_choiceshell( w, tag, cbs)
00666 Widget w;
00667 int *tag;
00668 XmAnyCallbackStruct *cbs;
00669 {
00670 choice_shell[*tag] = NULL;
00671 }
00672
00673 XmStringCharSet charset = XmSTRING_DEFAULT_CHARSET;
00674
00675 void item_selection( list_w, tag, cbs)
00676 Widget list_w;
00677 int *tag;
00678 XmListCallbackStruct *cbs;
00679 {
00680 char *choice;
00681 int i;
00682
00683 if (!XmStringGetLtoR(cbs->item, charset, &choice))
00684 return;
00685 if (update[*tag]) {
00686 REMOVE_CALLBACK(choice_w[*tag], cb_id[*tag]);
00687 }
00688 XmTextFieldSetString( choice_w[*tag], choice);
00689 if (update[*tag]) {
00690 RESTORE_CALLBACK(choice_w[*tag], cb_id[*tag]);
00691 }
00692
00693 for (i = 0; i < nb_widgets; i++) {
00694 if ((i != *tag) && ISSAMEVARIABLE(i, *tag)) {
00695 switch (widgets[i].generic.type) {
00696 case CHAIN:
00697 REMOVE_CALLBACK(chain_w[i], cb_id[i]);
00698 XmTextFieldSetString( chain_w[i], choice);
00699 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
00700 break;
00701
00702
00703
00704
00705
00706
00707
00708
00709 case CHOICE:
00710 REMOVE_CALLBACK(choice_w[i], cb_id[i]);
00711 XmTextFieldSetString( choice_w[i], choice);
00712 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
00713 break;
00714 case BROWSER:
00715 REMOVE_CALLBACK(filechain_w[i], cb_id[i]);
00716 XmTextFieldSetString( filechain_w[i], choice);
00717 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
00718 break;
00719 case SLIDER:
00720 REMOVE_CALLBACK(sliderchain_w[i], cb_id[i]);
00721 XmTextFieldSetString( sliderchain_w[i], choice);
00722 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
00723 UPDATE_SLIDERPOS;
00724 break;
00725 }
00726 }
00727 }
00728 }
00729
00730 void popup_listofchoice( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00731 {
00732 int k;
00733 XmString elem;
00734
00735 if (choice_shell[*tag] == NULL) {
00736 choice_shell[*tag] =
00737 XtVaAppCreateShell( widgets[*tag].choice.label, "choiceshell", topLevelShellWidgetClass, display, XmNwidth, 200, NULL);
00738
00739 XtAddCallback( choice_shell[*tag], XtNdestroyCallback, (XtCallbackProc) destroy_choiceshell, &cb_id[*tag]);
00740
00741 list_w = XmCreateScrolledList( choice_shell[*tag], "list_w", NULL, 0);
00742 for (k = 1; k <= widgets[*tag].choice.nchoices; k++) {
00743 elem = XmStringCreateSimple( widgets[*tag].choice.choices[k - 1]);
00744 XmListAddItem( list_w, elem, k);
00745 XmStringFree( elem);
00746 }
00747
00748 XtVaSetValues( list_w, XmNvisibleItemCount, 5, XmNselectionPolicy, XmEXTENDED_SELECT, NULL);
00749 XtManageChild( list_w);
00750
00751 XtAddCallback( list_w, XmNextendedSelectionCallback, (XtCallbackProc) item_selection, &cb_id[*tag]);
00752
00753 XtAddCallback( list_w, XmNdefaultActionCallback, (XtCallbackProc) item_selection, &cb_id[*tag]);
00754
00755 XtRealizeWidget( choice_shell[*tag]);
00756
00757
00758
00759
00760
00761 } else {
00762 XtUnmapWidget( choice_shell[*tag]);
00763 choice_shell[*tag] = NULL;
00764 }
00765 }
00766
00767 void change_value( w, tag, cbs)
00768 Widget w;
00769 int *tag;
00770 XmScaleCallbackStruct *cbs;
00771 {
00772 int i;
00773 char dum[80];
00774
00775 widgets[*tag].slider.uservalue = widgets[*tag].slider.min + (widgets[*tag].slider.width / 100) * cbs->value;
00776
00777 sprintf( dum, "%g", widgets[*tag].slider.uservalue);
00778
00779 if (update[*tag]) {
00780 REMOVE_CALLBACK(sliderchain_w[*tag], cb_id[*tag]);
00781 }
00782 UPDATE_STRING(sliderchain_w[*tag]);
00783 if (update[*tag]) {
00784 RESTORE_CALLBACK(sliderchain_w[*tag], cb_id[*tag]);
00785 }
00786
00787 for (i = 0; i < nb_widgets; i++) {
00788 if ((i != *tag) && ISSAMEVARIABLE(i, *tag)) {
00789 switch (widgets[i].generic.type) {
00790 case CHAIN:
00791
00792
00793 REMOVE_CALLBACK(chain_w[i], cb_id[i]);
00794 UPDATE_STRING(chain_w[i]);
00795
00796 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
00797 break;
00798
00799
00800
00801
00802
00803
00804
00805
00806 case CHOICE:
00807 REMOVE_CALLBACK(choice_w[i], cb_id[i]);
00808 UPDATE_STRING(choice_w[i]);
00809 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
00810 break;
00811 case BROWSER:
00812 REMOVE_CALLBACK(filechain_w[i], cb_id[i]);
00813 UPDATE_STRING(filechain_w[i]);
00814 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
00815 break;
00816 case SLIDER:
00817 widgets[i].slider.uservalue = widgets[*tag].slider.uservalue;
00818 XtVaSetValues( slider_w[i], XmNvalue, cbs->value, NULL);
00819 REMOVE_CALLBACK(sliderchain_w[i], cb_id[i]);
00820 UPDATE_STRING(sliderchain_w[i]);
00821 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
00822 break;
00823 }
00824 }
00825 }
00826 }
00827
00828 void update_slider( Widget w, int *tag, XmTextVerifyCallbackStruct * cbs)
00829 {
00830 char *dum;
00831 char newchain[80];
00832 int i, val;
00833
00834 dum = (char *)XmTextFieldGetString( sliderchain_w[*tag]);
00835
00836 widgets[*tag].slider.uservalue =
00837 MINI(MAXI(widgets[*tag].slider.min, atof( dum)), widgets[*tag].slider.min + widgets[*tag].slider.width);
00838
00839 sprintf( newchain, "%g", widgets[*tag].slider.uservalue);
00840
00841 if (update[*tag]) {
00842 REMOVE_CALLBACK(sliderchain_w[*tag], cb_id[*tag]);
00843 }
00844 XmTextFieldSetString( sliderchain_w[*tag], newchain);
00845 XmTextFieldSetInsertionPosition( sliderchain_w[*tag], strlen( newchain));
00846 if (update[*tag]) {
00847 RESTORE_CALLBACK(sliderchain_w[*tag], cb_id[*tag]);
00848 }
00849
00850 val = (int)(100 * ((float)atof( dum) - widgets[*tag].slider.min) / widgets[*tag].slider.width);
00851 val = MINI(MAXI(0, val), 100);
00852 XtVaSetValues( slider_w[*tag], XmNvalue, val, NULL);
00853
00854 for (i = 0; i < nb_widgets; i++) {
00855 if ((i != *tag) && ISSAMEWIDGET(i, *tag)) {
00856 widgets[i].slider.uservalue = widgets[*tag].slider.uservalue;
00857 REMOVE_CALLBACK(sliderchain_w[i], cb_id[i]);
00858 XmTextFieldSetString( sliderchain_w[i], newchain);
00859 XmTextFieldSetInsertionPosition( sliderchain_w[i], strlen( newchain));
00860 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
00861 XtVaSetValues( slider_w[i], XmNvalue, val, NULL);
00862 }
00863 }
00864 XtFree( dum);
00865 }
00866
00867 void popdown_help( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00868 {
00869 XtUnmapWidget( XtParent( XtParent( w)));
00870
00871
00872
00873
00874
00875 }
00876
00877 void destroy_help( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00878 {
00879 helpshell[*tag] = NULL;
00880 text_w[*tag] = NULL;
00881 }
00882
00883
00884 void popup_helpshell( Widget w, int *tag, XmAnyCallbackStruct * cbs)
00885 {
00886 Arg args[12];
00887 char dum[HLPFILELNGTH];
00888 char *text;
00889 struct stat statb;
00890 FILE *hfile;
00891 Widget form = NULL, button;
00892 int i, j, ind, nrows = 0, ncols, n = 0, nc, ncmax;
00893 char variablename[SICVLN - 1], taskname[16];
00894 char tampon[256];
00895 char underline[] = " --------------------------------------------";
00896
00897 sprintf( dum, "%s", helpfilename[*tag]);
00898
00899 for (i = 0; i < nb_widgets; i++) {
00900 if ((widgets[i].generic.type == SEPARATOR) || (widgets[i].generic.type == SHOW))
00901 continue;
00902 if (label_w[i] == w)
00903 break;
00904 }
00905
00906 nc = ncmax = 0;
00907 if (stat( dum, &statb) == -1) {
00908 text = (char *)XtMalloc( (unsigned)256 * sizeof( char));
00909 if (i == nb_widgets) {
00910 strcpy( text, "Reference not found ...");
00911 nc = 24;
00912 nc = sprintf( tampon, "File %s: Not found...", helpfilename[*tag]);
00913 strcpy( text, tampon);
00914 } else {
00915 nc = sprintf( tampon, "Variable %s: No help...", widgets[i].generic.variable);
00916 strcpy( text, tampon);
00917 }
00918 nrows = 1;
00919 ncmax = nc;
00920 } else {
00921 hfile = fopen( dum, "r");
00922
00923
00924 text = (char *)XtMalloc( (unsigned)(2 * statb.st_size));
00925
00926 if (i == nb_widgets) {
00927 if (*tag == 0)
00928 strcpy( text, " ");
00929 while (fgets( tampon, 255, hfile) != NULL) {
00930 if (strncmp( tampon, "1 END", 5) == 0)
00931 break;
00932 if (tampon[0] == '1') {
00933 sscanf( tampon, "%d%s", &ind, taskname);
00934
00935 nc = sprintf( tampon, "\n %s:\n", taskname);
00936 strcat( text, tampon);
00937 strncat( text, underline, nc - 2);
00938 strcat( text, "\n");
00939 ncmax = MAXI(ncmax, nc);
00940 nrows += 2;
00941 } else if (tampon[0] == '2') {
00942 sscanf( tampon, "%d%s", &ind, variablename);
00943 nc = sprintf( tampon, "\n Variable %s :\n", variablename);
00944 strcat( text, tampon);
00945 strncat( text, underline, nc - 2);
00946 strcat( text, "\n");
00947 ncmax = MAXI(ncmax, nc);
00948 nrows += 2;
00949 } else
00950 strcat( text, tampon);
00951 nc = strlen( tampon);
00952 ncmax = MAXI(ncmax, nc);
00953 nrows++;
00954 }
00955 } else {
00956
00957
00958 j = 0;
00959 while (widgets[i].generic.variable[j] != ' ')
00960 j++;
00961 while (fgets( tampon, 255, hfile) != NULL) {
00962 sscanf( tampon, "%d%s", &ind, variablename);
00963 if (strncmp( variablename, widgets[i].generic.variable, j) == 0)
00964 break;
00965 }
00966 if (strncmp( variablename, widgets[i].generic.variable, j) != 0) {
00967 nc = sprintf( tampon, " Variable %s\n", widgets[i].generic.variable);
00968 strcpy( text, tampon);
00969 strncat( text, underline, nc - 1);
00970 strcat( text, "\n");
00971 ncmax = MAXI(ncmax, nc);
00972 nrows += 2;
00973 } else {
00974 sscanf( tampon, "%d%s", &ind, variablename);
00975 nc = sprintf( tampon, " Variable %s:\n", variablename);
00976 strcpy( text, tampon);
00977 strncat( text, underline, nc - 1);
00978 strcat( text, "\n");
00979 ncmax = MAXI(ncmax, nc);
00980 nrows += 2;
00981 while (fgets( tampon, 255, hfile) != NULL) {
00982 if ((tampon[0] == '1') || (tampon[0] == '2'))
00983 break;
00984 else {
00985 strcat( text, tampon);
00986 nc = strlen( tampon);
00987 ncmax = MAXI(ncmax, nc);
00988 nrows++;
00989 }
00990 }
00991 }
00992 }
00993 fclose( hfile);
00994 }
00995
00996 if (!helpshell[*tag]) {
00997
00998 helpshell[*tag] = (Widget) XtVaAppCreateShell( dum, "helpshell", topLevelShellWidgetClass, display, NULL);
00999
01000 XtAddCallback( helpshell[*tag], XtNdestroyCallback, (XtCallbackProc) destroy_help, &cb_id[*tag]);
01001
01002 form = XtVaCreateManagedWidget( "form", xmFormWidgetClass, helpshell[*tag], NULL);
01003 button =
01004 XtVaCreateManagedWidget( "Dismiss",
01005 xmPushButtonWidgetClass,
01006 form,
01007 XmNleftAttachment, XmATTACH_FORM,
01008 XmNbottomAttachment, XmATTACH_FORM,
01009 XmNrightAttachment, XmATTACH_FORM,
01010 XmNshowAsDefault, 1, XmNdefaultButtonShadowThickness, 1, NULL);
01011
01012 XtAddCallback( button, XmNactivateCallback, (XtCallbackProc) popdown_help, &cb_id[*tag]);
01013 XtAugmentTranslations( button, XtParseTranslationTable( button_traversal));
01014 XtOverrideTranslations( button, XtParseTranslationTable( popdownhelp_traversal));
01015
01016
01017 n = 0;
01018 XtSetArg( args[n], XmNrows, 24);
01019 n++;
01020 XtSetArg( args[n], XmNcolumns, 80);
01021 n++;
01022 XtSetArg( args[n], XmNeditable, False);
01023 n++;
01024 XtSetArg( args[n], XmNcursorPositionVisible, False);
01025 n++;
01026 #ifdef LESSTIF_VERSION
01027 #else
01028 XtSetArg( args[n], XmNeditMode, XmMULTI_LINE_EDIT);
01029 n++;
01030 #endif
01031 XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM);
01032 n++;
01033 XtSetArg( args[n], XmNbottomAttachment, XmATTACH_WIDGET);
01034 n++;
01035 XtSetArg( args[n], XmNshadowThickness, 1);
01036 n++;
01037 XtSetArg( args[n], XmNbottomWidget, button);
01038 n++;
01039 XtSetArg( args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED);
01040 n++;
01041 XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM);
01042 n++;
01043 XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM);
01044 n++;
01045 }
01046
01047 ncols = ncmax;
01048 if (debugMode)
01049 printf( "nrows=%d,ncols=%d\n", nrows, ncols);
01050 if (!text_w[*tag]) {
01051 text_w[*tag] = XmCreateScrolledText( form, "text_w", args, n);
01052 XtManageChild( text_w[*tag]);
01053 XtRealizeWidget( helpshell[*tag]);
01054
01055
01056
01057
01058 }
01059
01060
01061
01062
01063
01064 XmTextSetString( text_w[*tag], text);
01065 XtFree( text);
01066 XMapRaised( display, XtWindow( helpshell[*tag]));
01067 }
01068
01069 void create_moreoptionshell( int ind)
01070 {
01071 moreoptionshell[ind] =
01072 (Widget) XtVaAppCreateShell( window_title[ind],
01073 "moreoption_shell",
01074 topLevelShellWidgetClass,
01075 display, XmNmappedWhenManaged, 0, XmNkeyboardFocusPolicy, XmPOINTER, NULL);
01076 XtAddCallback( moreoptionshell[ind], XtNdestroyCallback, (XtCallbackProc) destroy_moreoption, &cb_id[ind]);
01077 rowcol[ind] = XtVaCreateManagedWidget( "rowcol", xmRowColumnWidgetClass, moreoptionshell[ind], NULL);
01078 XmAddTabGroup( rowcol[ind]);
01079 }
01080
01081 void text_verify( Widget w, int *tag, XmTextVerifyCallbackStruct * cbs)
01082 {
01083 char *dum;
01084 int i;
01085
01086 dum = (char *)XmTextFieldGetString( w);
01087
01088 for (i = 0; i < nb_widgets; i++) {
01089 if ((i != *tag) && ISSAMEVARIABLE(i, *tag)) {
01090 switch (widgets[i].generic.type) {
01091 case CHAIN:
01092
01093
01094 REMOVE_CALLBACK(chain_w[i], cb_id[i]);
01095 UPDATE_STRING(chain_w[i]);
01096
01097 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
01098 break;
01099
01100
01101
01102
01103
01104
01105
01106
01107 case CHOICE:
01108 REMOVE_CALLBACK(choice_w[i], cb_id[i]);
01109 UPDATE_STRING(choice_w[i]);
01110 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
01111 break;
01112 case BROWSER:
01113 REMOVE_CALLBACK(filechain_w[i], cb_id[i]);
01114 UPDATE_STRING(filechain_w[i]);
01115 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
01116 break;
01117 case SLIDER:
01118 REMOVE_CALLBACK(sliderchain_w[i], cb_id[i]);
01119 UPDATE_STRING(sliderchain_w[i]);
01120 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
01121 UPDATE_SLIDERPOS;
01122 break;
01123 }
01124 }
01125 }
01126 XtFree( dum);
01127 }
01128
01129 void create_item( int i)
01130 {
01131 int n, k;
01132 char dum[80];
01133 XmString label_string;
01134
01135 form_w[i] = XtVaCreateManagedWidget( "form_w", xmFormWidgetClass, rowcol[widgets[i].generic.window_id], NULL);
01136
01137 n = 0;
01138 switch (widgets[i].generic.type) {
01139
01140 case SEPARATOR:
01141
01142 XtSetArg( args[n], XmNorientation, XmHORIZONTAL);
01143 n++;
01144 XtSetArg( args[n], XmNseparatorType, XmSHADOW_ETCHED_IN);
01145 n++;
01146 separator_w[i] = XmCreateSeparator( form_w[i], "separator", args, n);
01147 XtManageChild( separator_w[i]);
01148 n = 0;
01149 break;
01150 case CHAIN:
01151 label_w[i] = XtVaCreateManagedWidget( widgets[i].chain.label, xmPushButtonWidgetClass, form_w[i], LABELPROPS);
01152 XtAddCallback( label_w[i], XmNactivateCallback, (XtCallbackProc) popup_helpshell, &widgets[i].chain.window_id);
01153 XtAugmentTranslations( label_w[i], XtParseTranslationTable( button_traversal));
01154 XtOverrideTranslations( label_w[i], XtParseTranslationTable( help_traversal));
01155
01156 if (!widgets[i].chain.editable) {
01157 XtSetArg( args[n], XmNtraversalOn, FALSE);
01158 n++;
01159 XtSetArg( args[n], XmNcursorPositionVisible, FALSE);
01160 n++;
01161 XtSetArg( args[n], XmNeditable, FALSE);
01162 n++;
01163 XtSetArg( args[n], XmNshadowThickness, 1);
01164 n++;
01165 } else {
01166 XtSetArg( args[n], XmNtraversalOn, TRUE);
01167 n++;
01168 XtSetArg( args[n], XmNcursorPositionVisible, TRUE);
01169 n++;
01170 XtSetArg( args[n], XmNhighlightOnEnter, TRUE);
01171 n++;
01172 XtSetArg( args[n], XmNeditable, TRUE);
01173 n++;
01174 }
01175 chain_w[i] = XmCreateTextField( form_w[i], "input_w", args, n);
01176 XtManageChild( chain_w[i]);
01177 if (widgets[i].chain.editable) {
01178 XtAugmentTranslations( chain_w[i], XtParseTranslationTable( button_traversal));
01179 XtOverrideTranslations( chain_w[i], XtParseTranslationTable( edit_traversal));
01180 }
01181 XmTextFieldSetString( chain_w[i], widgets[i].chain.userchain);
01182 XmTextFieldSetInsertionPosition( chain_w[i], strlen( widgets[i].chain.userchain));
01183 if (update[i]) {
01184 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
01185 }
01186 n = 0;
01187 break;
01188
01189 case SLIDER:
01190 label_w[i] = XtVaCreateManagedWidget( widgets[i].slider.label, xmPushButtonWidgetClass, form_w[i], LABELPROPS);
01191 XtAddCallback( label_w[i], XmNactivateCallback, (XtCallbackProc) popup_helpshell, &widgets[i].slider.window_id);
01192 XtAugmentTranslations( label_w[i], XtParseTranslationTable( button_traversal));
01193 XtOverrideTranslations( label_w[i], XtParseTranslationTable( help_traversal));
01194
01195 XtSetArg( args[n], XmNtraversalOn, TRUE);
01196 n++;
01197 XtSetArg( args[n], XmNhighlightOnEnter, TRUE);
01198 n++;
01199 sliderchain_w[i] = XmCreateTextField( form_w[i], "input_w", args, n);
01200 XtManageChild( sliderchain_w[i]);
01201 sprintf( dum, "%g", widgets[i].slider.uservalue);
01202 XmTextFieldSetString( sliderchain_w[i], dum);
01203 XmTextFieldSetInsertionPosition( sliderchain_w[i], strlen( dum));
01204 if (update[i]) {
01205 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
01206 }
01207 XtAddCallback( sliderchain_w[i], XmNlosingFocusCallback, (XtCallbackProc) update_slider, &cb_id[i]);
01208 XtAugmentTranslations( sliderchain_w[i], XtParseTranslationTable( button_traversal));
01209 XtOverrideTranslations( sliderchain_w[i], XtParseTranslationTable( edit_traversal));
01210
01211 sprintf( dum, "[%9.3g,%9.3g]", widgets[i].slider.min, widgets[i].slider.min + widgets[i].slider.width);
01212 label_string = XmStringCreateLocalized( dum);
01213
01214 n = 0;
01215 XtSetArg( args[n], XmNvalue, (int)(100 * (widgets[i].slider.uservalue - widgets[i].slider.min) / widgets[i].slider.width));
01216 n++;
01217 XtSetArg( args[n], XmNheight, 30);
01218 n++;
01219 XtSetArg( args[n], XmNscaleHeight, 15);
01220 n++;
01221 XtSetArg( args[n], XmNorientation, XmHORIZONTAL);
01222 n++;
01223 XtSetArg( args[n], XmNprocessingDirection, XmMAX_ON_RIGHT);
01224 n++;
01225 XtSetArg( args[n], XmNtitleString, label_string);
01226 n++;
01227 XtSetArg( args[n], XmNtraversalOn, TRUE);
01228 n++;
01229 slider_w[i] = XmCreateScale( form_w[i], "slider_w", args, n);
01230 XtManageChild( slider_w[i]);
01231 XmStringFree( label_string);
01232 XtAddCallback( slider_w[i], XmNdragCallback, (XtCallbackProc) change_value, &cb_id[i]);
01233 XtAddCallback( slider_w[i], XmNvalueChangedCallback, (XtCallbackProc) change_value, &cb_id[i]);
01234 n = 0;
01235 break;
01236
01237 case SHOW:
01238 label_string = XmStringCreateLocalized( widgets[i].show.text);
01239 showtext_w[i] =
01240 XtVaCreateManagedWidget( "label",
01241 xmLabelWidgetClass, form_w[i], XmNtraversalOn, FALSE, XmNlabelString, label_string, NULL);
01242 XmStringFree( label_string);
01243 break;
01244
01245 case LOGIC:
01246 label_w[i] = XtVaCreateManagedWidget( widgets[i].logic.label, xmPushButtonWidgetClass, form_w[i], LABELPROPS);
01247 XtAddCallback( label_w[i], XmNactivateCallback, (XtCallbackProc) popup_helpshell, &widgets[i].logic.window_id);
01248 XtAugmentTranslations( label_w[i], XtParseTranslationTable( button_traversal));
01249 XtOverrideTranslations( label_w[i], XtParseTranslationTable( help_traversal));
01250
01251 label_string = (widgets[i].logic.userlogic == 1) ? XmStringCreateLocalized( "Yes ") : XmStringCreateLocalized( "No ");
01252 logic_w[i] =
01253 XtVaCreateManagedWidget( "logic_w",
01254 xmToggleButtonWidgetClass,
01255 form_w[i],
01256 XmNtraversalOn, TRUE,
01257 XmNset, widgets[i].logic.userlogic,
01258 XmNlabelString, label_string, XmNhighlightOnEnter, TRUE, NULL);
01259 XtAddEventHandler( logic_w[i], KeyPressMask, False, (XtEventHandler) EnterHandler, NULL);
01260 XmStringFree( label_string);
01261 XtAddCallback( logic_w[i], XmNvalueChangedCallback, (XtCallbackProc) toggled, &update[i]);
01262 XtAugmentTranslations( logic_w[i], XtParseTranslationTable( button_traversal));
01263 break;
01264
01265 case BROWSER:
01266 label_w[i] = XtVaCreateManagedWidget( widgets[i].file.label, xmPushButtonWidgetClass, form_w[i], LABELPROPS);
01267 XtAddCallback( label_w[i], XmNactivateCallback, (XtCallbackProc) popup_helpshell, &widgets[i].file.window_id);
01268 XtAugmentTranslations( label_w[i], XtParseTranslationTable( button_traversal));
01269 XtOverrideTranslations( label_w[i], XtParseTranslationTable( help_traversal));
01270
01271 filechain_w[i] =
01272 XtVaCreateManagedWidget( "input_w",
01273 xmTextFieldWidgetClass,
01274 form_w[i], XmNeditable, TRUE, XmNtraversalOn, TRUE, XmNhighlightOnEnter, TRUE, NULL);
01275 XtAugmentTranslations( filechain_w[i], XtParseTranslationTable( edit_traversal));
01276 XmTextFieldSetString( filechain_w[i], widgets[i].file.userchain);
01277 XmTextFieldSetInsertionPosition( filechain_w[i], strlen( widgets[i].file.userchain));
01278 if (update[i]) {
01279 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
01280 }
01281 filebutton_w[i] =
01282 XtVaCreateManagedWidget( "File",
01283 xmPushButtonWidgetClass, form_w[i], XmNtraversalOn, TRUE, XmNhighlightOnEnter, TRUE, NULL);
01284 XtAugmentTranslations( filebutton_w[i], XtParseTranslationTable( button_traversal));
01285
01286 XtAddCallback( filebutton_w[i], XmNactivateCallback, (XtCallbackProc) create_fileselbox, &cb_id[i]);
01287 break;
01288
01289 case CHOICE:
01290 label_w[i] = XtVaCreateManagedWidget( widgets[i].choice.label, xmPushButtonWidgetClass, form_w[i], LABELPROPS);
01291 XtAddCallback( label_w[i], XmNactivateCallback, (XtCallbackProc) popup_helpshell, &widgets[i].choice.window_id);
01292 XtAugmentTranslations( label_w[i], XtParseTranslationTable( button_traversal));
01293 XtOverrideTranslations( label_w[i], XtParseTranslationTable( help_traversal));
01294
01295 n = 0;
01296 if (abs( widgets[i].choice.mode) == 1) {
01297 XtSetArg( args[n], XmNtraversalOn, FALSE);
01298 n++;
01299 XtSetArg( args[n], XmNeditable, FALSE);
01300 n++;
01301 XtSetArg( args[n], XmNcursorPositionVisible, FALSE);
01302 n++;
01303 XtSetArg( args[n], XmNshadowThickness, 1);
01304 n++;
01305 } else {
01306 XtSetArg( args[n], XmNtraversalOn, TRUE);
01307 n++;
01308 XtSetArg( args[n], XmNeditable, TRUE);
01309 n++;
01310 XtSetArg( args[n], XmNhighlightOnEnter, TRUE);
01311 n++;
01312 XtSetArg( args[n], XmNcursorPositionVisible, TRUE);
01313 n++;
01314 }
01315 choice_w[i] = XmCreateTextField( form_w[i], "input_w", args, n);
01316 XtManageChild( choice_w[i]);
01317 if (widgets[i].choice.mode == 0) {
01318 XtAugmentTranslations( choice_w[i], XtParseTranslationTable( button_traversal));
01319 XtOverrideTranslations( choice_w[i], XtParseTranslationTable( edit_traversal));
01320 }
01321 XmTextFieldSetString( choice_w[i], widgets[i].choice.userchoice);
01322 if (widgets[i].choice.mode == 0) {
01323 XmTextFieldSetInsertionPosition( choice_w[i], strlen( widgets[i].choice.userchoice));
01324 }
01325
01326 if (update[i]) {
01327 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
01328 }
01329 n = 0;
01330 XtSetArg( args[n], XmNtraversalOn, TRUE);
01331 n++;
01332 XtSetArg( args[n], XmNhighlightOnEnter, TRUE);
01333 n++;
01334 choice_bar[i] = XmCreateMenuBar( form_w[i], "menu_bar", args, n);
01335 XtManageChild( choice_bar[i]);
01336 if (widgets[i].choice.nchoices <= NMAXCHOICE) {
01337 menu_pane = XmCreatePulldownMenu( choice_bar[i], "menu_pane", args, n);
01338
01339 for (k = 0; k < widgets[i].choice.nchoices; k++) {
01340 button = XmCreatePushButton( menu_pane, widgets[i].choice.choices[k], args, n);
01341 XtManageChild( button);
01342 XtAddCallback( button, XmNactivateCallback, (XtCallbackProc) select_chain, &cb_id[i]);
01343 }
01344 XtSetArg( args[n], XmNsubMenuId, menu_pane);
01345 n++;
01346 }
01347
01348
01349 cascade = XmCreateCascadeButton( choice_bar[i], "Choices", args, n);
01350 XtManageChild( cascade);
01351 XtAugmentTranslations( cascade, XtParseTranslationTable( button_traversal));
01352 if (widgets[i].choice.nchoices > NMAXCHOICE) {
01353
01354 XtAddCallback( cascade, XmNactivateCallback, (XtCallbackProc) popup_listofchoice, &cb_id[i]);
01355 }
01356 n = 0;
01357 break;
01358
01359 case BUTTON:
01360 label_string = XmStringCreateLocalized( widgets[i].button.label);
01361
01362 label_w[i] =
01363 XtVaCreateManagedWidget( "label",
01364 xmLabelWidgetClass, form_w[i], XmNtraversalOn, FALSE, XmNlabelString, label_string, NULL);
01365 XmStringFree( label_string);
01366
01367 label_string = XmStringCreateLocalized( widgets[i].button.title);
01368 n = 0;
01369 XtSetArg( args[n], XmNtraversalOn, TRUE);
01370 n++;
01371 XtSetArg( args[n], XmNlabelString, label_string);
01372 n++;
01373 XtSetArg( args[n], XmNrecomputeSize, 0);
01374 n++;
01375 XtSetArg( args[n], XmNhighlightOnEnter, TRUE);
01376 n++;
01377 button_w[i] = XmCreatePushButton( form_w[i], "button", args, n);
01378 XtManageChild( button_w[i]);
01379 XtVaGetValues( button_w[i], XmNwidth, &width, NULL);
01380 if (width > buttonwidth)
01381 buttonwidth = width;
01382 XmStringFree( label_string);
01383 XtAddCallback( button_w[i], XmNactivateCallback, (XtCallbackProc) close_dialog, &cb_id[i]);
01384 XtAugmentTranslations( button_w[i], XtParseTranslationTable( button_traversal));
01385
01386 if (strlen( widgets[i].button.moretxt) > 1) {
01387 label_string = XmStringCreateLocalized( widgets[i].button.moretxt);
01388
01389 n = 0;
01390 XtSetArg( args[n], XmNtraversalOn, TRUE);
01391 n++;
01392 XtSetArg( args[n], XmNlabelString, label_string);
01393 n++;
01394 XtSetArg( args[n], XmNrecomputeSize, 0);
01395 n++;
01396 XtSetArg( args[n], XmNhighlightOnEnter, TRUE);
01397 n++;
01398 morebutton[moreid[i]] = XmCreatePushButton( form_w[i], "morebutton", args, n);
01399 XtManageChild( morebutton[moreid[i]]);
01400 XtVaGetValues( morebutton[moreid[i]], XmNwidth, &width, NULL);
01401 if (width > morewidth)
01402 morewidth = width;
01403 XmStringFree( label_string);
01404 XtAddCallback( morebutton[moreid[i]], XmNactivateCallback, (XtCallbackProc) popup_moreoptionshell, &moreid[i]);
01405 XtAugmentTranslations( morebutton[moreid[i]], XtParseTranslationTable( button_traversal));
01406 XtOverrideTranslations( morebutton[moreid[i]], XtParseTranslationTable( more_traversal));
01407 }
01408
01409 if (strlen( widgets[i].button.helptxt) > 1) {
01410 sprintf( helpfilename[moreid[i]], "%s", widgets[i].button.helptxt);
01411 label_string = XmStringCreateLocalized( "Help");
01412 n = 0;
01413 XtSetArg( args[n], XmNlabelString, label_string);
01414 n++;
01415
01416 helpbutton[moreid[i]] = XmCreatePushButton( form_w[i], "Help", args, n);
01417 XtManageChild( helpbutton[moreid[i]]);
01418
01419 XmStringFree( label_string);
01420
01421 XtAddCallback( helpbutton[moreid[i]], XmNactivateCallback, (XtCallbackProc) popup_helpshell, &moreid[i]);
01422 XtAugmentTranslations( helpbutton[moreid[i]], XtParseTranslationTable( button_traversal));
01423 XtOverrideTranslations( helpbutton[moreid[i]], XtParseTranslationTable( help_traversal));
01424
01425 }
01426
01427 break;
01428
01429 }
01430 }
01431
01432
01433 void set_dim( int i)
01434 {
01435 XtWidgetGeometry preferred_return;
01436
01437 if ((widgets[i].generic.type != SEPARATOR) && ((widgets[i].generic.type != SHOW)))
01438 XtVaSetValues( label_w[i],
01439 XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL);
01440
01441 if (widgets[i].generic.type == SEPARATOR)
01442 XtVaSetValues( separator_w[i],
01443 XmNheight, 5,
01444 XmNleftAttachment, XmATTACH_FORM,
01445 XmNrightAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL);
01446
01447
01448 if (widgets[i].generic.type == SHOW) {
01449 if (widgets[i].generic.window_id == 0)
01450 XtVaSetValues( showtext_w[i], XmNwidth, main_titlewidth + buttonwidth + morewidth + helpwidth, NULL);
01451 else
01452 XtVaSetValues( showtext_w[i], XmNwidth, titlewidth + 390, NULL);
01453 }
01454
01455
01456 if (widgets[i].generic.type == BUTTON) {
01457 XtVaSetValues( label_w[i], XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, button_w[i], NULL);
01458
01459 XtVaSetValues( button_w[i], XmNx, main_titlewidth, XmNwidth, buttonwidth, NULL);
01460
01461 if (strlen( widgets[i].button.moretxt) > 1)
01462 XtVaSetValues( morebutton[moreid[i]], XmNx, main_titlewidth + buttonwidth, XmNwidth, morewidth, NULL);
01463 if (strlen( widgets[i].button.helptxt) > 1)
01464 XtVaSetValues( helpbutton[moreid[i]], XmNwidth, helpwidth, XmNx, main_titlewidth + buttonwidth + morewidth, NULL);
01465
01466 }
01467 if (widgets[i].generic.type == CHAIN) {
01468
01469 XtVaSetValues( label_w[i], XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, chain_w[i], NULL);
01470
01471 if (widgets[i].generic.window_id == 0)
01472
01473 XtVaSetValues( chain_w[i], XmNwidth, buttonwidth + helpwidth + morewidth, XmNx, main_titlewidth, NULL);
01474 else
01475 XtVaSetValues( chain_w[i], XmNwidth, 390, XmNx, titlewidth, NULL);
01476 }
01477 if (widgets[i].generic.type == LOGIC) {
01478 XtVaSetValues( label_w[i], XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, logic_w[i], NULL);
01479
01480 if (widgets[i].generic.window_id == 0)
01481 XtVaSetValues( logic_w[i], XmNx, main_titlewidth, NULL);
01482 else
01483 XtVaSetValues( logic_w[i], XmNx, titlewidth, NULL);
01484 }
01485 if (widgets[i].generic.type == BROWSER) {
01486 XtVaSetValues( label_w[i], XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, filechain_w[i], NULL);
01487 XtQueryGeometry( filebutton_w[i], NULL, &preferred_return);
01488 if (widgets[i].generic.window_id == 0) {
01489 XtVaSetValues( filechain_w[i],
01490 XmNwidth, buttonwidth + morewidth + helpwidth - preferred_return.width, XmNx, main_titlewidth, NULL);
01491 XtVaSetValues( filebutton_w[i], XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNwidth, preferred_return.width,
01492 XmNx, main_titlewidth + buttonwidth + morewidth + helpwidth - preferred_return.width, NULL);
01493 } else {
01494 XtVaSetValues( filechain_w[i], XmNwidth, 390 - preferred_return.width, XmNx, titlewidth, NULL);
01495 XtVaSetValues( filebutton_w[i],
01496 XmNtopAttachment, XmATTACH_FORM,
01497 XmNbottomAttachment, XmATTACH_FORM,
01498 XmNwidth, preferred_return.width, XmNx, titlewidth + 390 - preferred_return.width, NULL);
01499 }
01500 }
01501
01502 if (widgets[i].generic.type == SLIDER) {
01503 XtVaSetValues( label_w[i], XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, sliderchain_w[i], NULL);
01504 if (widgets[i].generic.window_id == 0) {
01505 XtVaSetValues( sliderchain_w[i], XmNwidth, buttonwidth + morewidth + helpwidth - 300, XmNx, main_titlewidth, NULL);
01506 XtVaSetValues( slider_w[i], XmNwidth, 300, XmNx, main_titlewidth + buttonwidth + morewidth + helpwidth - 300, NULL);
01507 }
01508
01509 else {
01510 XtVaSetValues( sliderchain_w[i], XmNwidth, 90, XmNx, titlewidth, NULL);
01511 XtVaSetValues( slider_w[i], XmNwidth, 300, XmNx, titlewidth + 90, NULL);
01512 }
01513 }
01514
01515 if (widgets[i].generic.type == CHOICE) {
01516 XtVaSetValues( label_w[i], XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, choice_w[i], NULL);
01517 XtQueryGeometry( choice_bar[i], NULL, &preferred_return);
01518
01519 if (widgets[i].generic.window_id == 0) {
01520 XtVaSetValues( choice_w[i],
01521 XmNwidth, buttonwidth + morewidth + helpwidth - preferred_return.width, XmNx, main_titlewidth, NULL);
01522
01523 XtVaSetValues( choice_bar[i],
01524 XmNwidth, preferred_return.width,
01525 XmNx, main_titlewidth + buttonwidth + morewidth + helpwidth - preferred_return.width, NULL);
01526 } else {
01527
01528 XtVaSetValues( choice_w[i], XmNwidth, 390 - preferred_return.width, XmNx, titlewidth, NULL);
01529 XtVaSetValues( choice_bar[i], XmNwidth, preferred_return.width, XmNx, titlewidth + 390 - preferred_return.width, NULL);
01530 }
01531 }
01532 }
01533
01534 typedef struct {
01535 XFontStruct *myfont;
01536
01537
01538
01539
01540
01541 } application_variable_rec;
01542
01543 static XtResource resources[] = {
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558 {"myfont", XtCFont, XtRFontStruct, sizeof( XFontStruct *),
01559 XtOffsetOf( application_variable_rec, myfont),
01560 XtRString, XtDefaultFont}
01561 };
01562
01563 int myhandler( Display * display, XErrorEvent * ev)
01564 {
01565 if (debugMode) {
01566 char *tmptxt;
01567
01568 tmptxt = malloc( 512);
01569 XGetErrorText( display, ev->error_code, tmptxt, 511);
01570 printf( "X11 Error number %d (%s).\n", ev->error_code, tmptxt);
01571 free( tmptxt);
01572 }
01573 return 1;
01574 }
01575
01576 void create_widgets( int argc, char **argv)
01577 {
01578 XWMHints gestw;
01579 application_variable_rec app_vars;
01580 int dir;
01581 XCharStruct dimglob;
01582 XtWidgetGeometry preferred_return;
01583 Dimension shellwidth, shellheight, menuheight, commandheight, menuwidth, commandwidth = 0;
01584 int n_action = 0;
01585 Screen *ecran;
01586 int screen;
01587 Window fenrac;
01588 int i, j = 1, n = 0;
01589
01590 if (!(toplevel = XtVaAppInitialize( &app,
01591 "Xxgag",
01592 NULL, 0, &argc, argv, NULL, XmNmappedWhenManaged, False, XmNtitle, window_title[0], NULL))) {
01593 printf( "Failed to start X Window\n");
01594 sic_do_exit( 0);
01595 }
01596
01597 XtAppAddActions( app, actions_list, XtNumber( actions_list));
01598 display = XtDisplay( toplevel);
01599 XSetErrorHandler( myhandler);
01600 ecran = XtScreen( toplevel);
01601 fenrac = RootWindowOfScreen( ecran);
01602 screen = DefaultScreen( display);
01603 XGetInputFocus( display, &from_window, &revert_to);
01604 XGetWindowAttributes( display, from_window, &attrib);
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614 if (context_cursor == 0)
01615 context_cursor = XCreateFontCursor( display, XC_question_arrow);
01616
01617 termheight = DisplayHeight( display, screen);
01618 termwidth = DisplayWidth( display, screen);
01619 if (debugMode)
01620 printf( "termheight=%d\n", termheight);
01621 if (debugMode)
01622 printf( "termwidth=%d\n", termwidth);
01623
01624 XtGetApplicationResources( toplevel, &app_vars,
01625 resources,
01626 XtNumber( resources),
01627 NULL, 0);
01628
01629 XTextExtents( app_vars.myfont, "Chain", 0, &dir, &hcotep, &bcotep, &dimglob);
01630
01631 main_shell =
01632 XtVaAppCreateShell( window_title[0],
01633 "mainshell", topLevelShellWidgetClass, display, XmNkeyboardFocusPolicy, XmPOINTER, NULL);
01634
01635 XtAddCallback( main_shell, XtNdestroyCallback, (XtCallbackProc) close_dialog, &ABORT);
01636 n = 0;
01637
01638
01639 XtSetArg( args[n], XmNtraversalOn, TRUE);
01640 n++;
01641 XtSetArg( args[n], XmNshowSeparator, TRUE);
01642 n++;
01643 XtSetArg( args[n], XmNkeyboardFocusPolicy, XmPOINTER);
01644 n++;
01645 main_w = XmCreateMainWindow( main_shell, "main_w", args, n);
01646
01647 XtManageChild( main_w);
01648
01649
01650 n = 0;
01651 XtSetArg( args[n], XmNorientation, XmHORIZONTAL);
01652 n++;
01653 menu_bar = XmCreateRowColumn( main_w, "menu", args, n);
01654 XtManageChild( menu_bar);
01655
01656
01657 n = 0;
01658 XtSetArg( args[n], XmNtraversalOn, TRUE);
01659 n++;
01660 main_go = XmCreatePushButton( menu_bar, " GO ", args, n);
01661 XtManageChild( main_go);
01662 XtVaGetValues( main_go, XmNwidth, &testwidth, NULL);
01663 XtAddCallback( main_go, XmNactivateCallback, (XtCallbackProc) close_dialog, &OK);
01664 XtAugmentTranslations( main_go, XtParseTranslationTable( button_traversal));
01665
01666 cascade = XmCreatePushButton( menu_bar, " ABORT ", args, n);
01667 XtManageChild( cascade);
01668 XtVaGetValues( cascade, XmNwidth, &testwidth, NULL);
01669 XtAddCallback( cascade, XmNactivateCallback, (XtCallbackProc) close_dialog, &ABORT);
01670 XtAugmentTranslations( cascade, XtParseTranslationTable( button_traversal));
01671
01672 cascade = XmCreatePushButton( menu_bar, " HELP ", args, n);
01673 XtManageChild( cascade);
01674 XtVaGetValues( cascade, XmNwidth, &testwidth, NULL);
01675 XtAddCallback( cascade, XmNactivateCallback, (XtCallbackProc) popup_helpshell, &WIN0);
01676 XtAugmentTranslations( cascade, XtParseTranslationTable( button_traversal));
01677
01678
01679 n = 0;
01680 XtSetArg( args[n], XmNmenuHelpWidget, cascade);
01681 n++;
01682 XtSetValues( menu_bar, args, n);
01683
01684
01685 n = 0;
01686 for (i = 0; i < NSTRUCT; i++) {
01687 cb_id[i] = i;
01688 fselshell[i] = NULL;
01689 choice_shell[i] = NULL;
01690 }
01691 for (i = 0; i < NSTRUCT; i++) {
01692 moreoptionshell[i] = NULL;
01693 helpshell[i] = NULL;
01694 }
01695
01696 n_action = 0;
01697 for (i = 0; i < nb_widgets; i++) {
01698 if (widgets[i].generic.type != BUTTON)
01699 continue;
01700 if (widgets[i].button.showlength == 0) {
01701 num_actions[n_action] = i;
01702 n_action++;
01703 }
01704 }
01705
01706 if (n_action) {
01707 command_bar =
01708 XtVaCreateManagedWidget( "command", xmFormWidgetClass, main_w,
01709 XmNfractionBase, 20 * n_action - 1, XmNtraversalOn, TRUE, XmNskipAdjust, TRUE, NULL);
01710
01711 for (i = 0; i < n_action; i++) {
01712 button =
01713 XtVaCreateManagedWidget( widgets[num_actions[i]].button.title,
01714 xmPushButtonWidgetClass, command_bar,
01715 XmNleftAttachment,
01716 i ? XmATTACH_POSITION : XmATTACH_FORM,
01717 XmNleftPosition, 20 * i,
01718 XmNtopAttachment, XmATTACH_FORM,
01719 XmNbottomAttachment, XmATTACH_FORM,
01720 XmNrightAttachment,
01721 i != n_action - 1 ?
01722 XmATTACH_POSITION : XmATTACH_FORM,
01723 XmNrightPosition, 20 * i + 19,
01724 XmNdefaultButtonShadowThickness, 1, XmNtraversalOn, TRUE, NULL);
01725 XtAddCallback( button, XmNactivateCallback, (XtCallbackProc) close_dialog, &cb_id[num_actions[i]]);
01726 XtAugmentTranslations( button, XtParseTranslationTable( button_traversal));
01727 }
01728 }
01729
01730 for (i = 0; i < nb_widgets; i++) {
01731 if (widgets[i].generic.type != BUTTON)
01732 continue;
01733 if (widgets[i].button.showlength == 0)
01734 continue;
01735 moreid[i] = j;
01736 revid[j] = i;
01737 j++;
01738 if (strlen( widgets[i].button.moretxt) == 1)
01739 continue;
01740 sprintf( window_title[moreid[i]], "%s", widgets[i].button.moretxt);
01741 create_moreoptionshell( moreid[i]);
01742 }
01743 nwin = j - 1;
01744 #ifndef linux
01745
01746 frame = XtVaCreateManagedWidget( "scrolled_w", xmScrolledWindowWidgetClass, main_w, XmNscrollingPolicy, XmAUTOMATIC, NULL);
01747
01748 #else
01749
01750 n = 0;
01751 XtSetArg( args[n], XmNmarginWidth, 2);
01752 n++;
01753 XtSetArg( args[n], XmNmarginHeight, 2);
01754 n++;
01755 XtSetArg( args[n], XmNshadowThickness, 1);
01756 n++;
01757 XtSetArg( args[n], XmNshadowType, XmSHADOW_OUT);
01758 n++;
01759 frame = XmCreateFrame( main_w, "frame", args, n);
01760 XtManageChild( frame);
01761 #endif
01762
01763 rowcol[0] = XtVaCreateManagedWidget( "rowcol", xmRowColumnWidgetClass, frame, NULL);
01764
01765 for (i = 0; i < nb_widgets; i++) {
01766 if ((widgets[i].generic.type == BUTTON) && (widgets[i].button.showlength == 0))
01767 continue;
01768 create_item( i);
01769 }
01770 XmAddTabGroup( rowcol[0]);
01771
01772
01773 for (i = 0; i < nb_widgets; i++) {
01774 if (widgets[i].generic.type == SEPARATOR)
01775 continue;
01776 if ((widgets[i].generic.type == BUTTON) && (widgets[i].button.showlength == 0))
01777 continue;
01778 if (widgets[i].generic.type == SHOW)
01779 continue;
01780 XtVaGetValues( label_w[i], XmNwidth, &testwidth, NULL);
01781 if (widgets[i].generic.window_id == 0) {
01782 if (testwidth > main_titlewidth)
01783 main_titlewidth = testwidth;
01784 } else {
01785 if (testwidth > titlewidth)
01786 titlewidth = testwidth;
01787 }
01788 }
01789
01790 for (i = 0; i < nb_widgets; i++) {
01791 if ((widgets[i].generic.type == BUTTON) && (widgets[i].button.showlength == 0))
01792 continue;
01793 set_dim( i);
01794 }
01795
01796 if (0) {
01797 n = 0;
01798 XtSetArg( args[n], XmNwidth, main_titlewidth + buttonwidth + helpwidth + morewidth + 10);
01799 n++;
01800 XtSetValues( command_bar, args, n);
01801 }
01802
01803 for (i = 1; i < j; i++) {
01804
01805 create_actionarea( i);
01806 XtRealizeWidget( moreoptionshell[i]);
01807
01808
01809
01810
01811 XtVaGetValues( moreoptionshell[i], XmNwidth, &shellwidth, XmNheight, &shellheight, NULL);
01812
01813 XtVaSetValues( moreoptionshell[i], XmNminWidth, shellwidth, XmNminHeight, shellheight, NULL);
01814 XtVaSetValues( moreoptionshell[i], XmNmaxWidth, shellwidth, XmNmaxHeight, shellheight, NULL);
01815 }
01816
01817 XtQueryGeometry( rowcol[0], NULL, &preferred_return);
01818 scrollheight = preferred_return.height + 10;
01819 scrollwidth = preferred_return.width + 10;
01820 if (debugMode)
01821 printf( "rowcol.preferredheight=%d\n", scrollheight);
01822 if (debugMode)
01823 printf( "rowcol.preferred.width=%d\n", scrollwidth);
01824
01825
01826 XtQueryGeometry( menu_bar, NULL, &preferred_return);
01827 menuheight = preferred_return.height;
01828 menuwidth = preferred_return.width;
01829 if (debugMode)
01830 printf( "menuheight=%d\n", menuheight);
01831 if (debugMode)
01832 printf( "menuwidth=%d\n", menuwidth);
01833
01834 if (n_action) {
01835 XtQueryGeometry( command_bar, NULL, &preferred_return);
01836 commandheight = preferred_return.height;
01837 commandwidth = preferred_return.width;
01838 if (debugMode)
01839 printf( "commandheight=%d\n", commandheight);
01840 if (debugMode)
01841 printf( "commandwidth=%d\n", commandwidth);
01842 }
01843
01844 if (scrollwidth < menuwidth)
01845 scrollwidth = menuwidth;
01846 if (n_action && (scrollwidth < commandwidth))
01847 scrollwidth = commandwidth;
01848
01849 if (scrollheight > termheight)
01850 scrollheight = termheight;
01851 if (scrollwidth > termwidth)
01852 scrollwidth = termwidth;
01853
01854 XtVaSetValues( frame, XmNwidth, scrollwidth, XmNheight, scrollheight, NULL);
01855 #ifdef linux
01856 if (debugMode)
01857 printf( "frame set to: height=%d", scrollheight);
01858 #else
01859 if (debugMode)
01860 printf( "scrolled_w set to: height=%d", scrollheight);
01861 #endif
01862 if (debugMode)
01863 printf( ", width=%d\n", scrollwidth);
01864
01865
01866 XmMainWindowSetAreas( main_w, menu_bar, command_bar, NULL, NULL, frame);
01867
01868 XtRealizeWidget( main_shell);
01869
01870
01871
01872
01873 XtVaGetValues( main_shell, XmNwidth, &shellwidth, XmNheight, &shellheight, NULL);
01874 if (debugMode)
01875 printf( "main_shell:height=%d\n", preferred_return.height);
01876 if (debugMode)
01877 printf( "main_shell:width=%d\n", preferred_return.width);
01878
01879 for (i = 0; i < nb_widgets; i++) {
01880 if ((widgets[i].generic.type != SHOW) && (widgets[i].generic.type != BUTTON) && (widgets[i].generic.type != SEPARATOR))
01881 XDefineCursor( display, XtWindow( label_w[i]), context_cursor);
01882 }
01883
01884 gestw.input = FALSE;
01885 for (i = 0; i < nb_widgets; i++) {
01886 if (((widgets[i].generic.type == CHAIN) && (widgets[i].chain.editable))
01887 || (widgets[i].generic.type == BROWSER)
01888 || (widgets[i].generic.type == SLIDER)
01889 || ((widgets[i].generic.type == CHOICE) && (widgets[i].choice.mode == 0))
01890 ) {
01891 gestw.input = TRUE;
01892 if (debugMode)
01893 printf( "main_shell has focus\n");
01894 break;
01895 }
01896 }
01897 gestw.flags = InputHint;
01898 XSetWMHints( display, XtWindow( main_shell), &gestw);
01899
01900 sic_post_widget_created( );
01901
01902 XtAppMainLoop( app);
01903 }
01904
01905 static void update_variable( sic_widget_def_t *widget)
01906 {
01907 int i, j, do_it = 0;
01908 XmString label;
01909 char dum[256];
01910 int was;
01911
01912
01913
01914 was = -1;
01915 for (i = 0; i < nb_widgets; i++) {
01916
01917 if ((strcmp( widget->generic.variable,
01918 widgets[i].generic.variable) == 0) && (widget->generic.type == widgets[i].generic.type)) {
01919
01920 switch (widgets[i].generic.type) {
01921 case SLIDER:
01922 widgets[i].slider.uservalue =
01923 MINI(MAXI(widgets[i].slider.min, widget->slider.uservalue),
01924 widgets[i].slider.min + widgets[i].slider.width);
01925 sprintf( dum, "%g", widgets[i].slider.uservalue);
01926 REMOVE_CALLBACK(sliderchain_w[i], cb_id[i]);
01927 UPDATE_STRING(sliderchain_w[i]);
01928 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
01929 XtVaSetValues( slider_w[i],
01930 XmNvalue,
01931 (int)(100 * (widgets[i].slider.uservalue
01932 - widgets[i].slider.min) / widgets[i].slider.width), NULL);
01933 was = i;
01934 break;
01935 case LOGIC:
01936 widgets[i].logic.userlogic = widget->logic.userlogic;
01937
01938 label = (widgets[i].logic.userlogic) ? XmStringCreateLocalized( "Yes ") : XmStringCreateLocalized( "No ");
01939
01940 XtVaSetValues( logic_w[i], XmNset, widgets[i].logic.userlogic, XmNlabelString, label, NULL);
01941 was = i;
01942 break;
01943 case CHAIN:
01944 if (debugMode)
01945 printf( "read %s %d\n", widget->chain.userchain, (int)strlen( widget->chain.userchain));
01946 strcpy( widgets[i].chain.userchain, widget->chain.userchain);
01947
01948
01949 REMOVE_CALLBACK(chain_w[i], cb_id[i]);
01950 XmTextFieldSetString( chain_w[i], widgets[i].chain.userchain);
01951 XmTextFieldSetInsertionPosition( chain_w[i], strlen( widgets[i].chain.userchain));
01952 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
01953 was = i;
01954 sprintf( dum, "%s", widgets[i].chain.userchain);
01955 break;
01956 case CHOICE:
01957
01958
01959 if (widgets[i].choice.mode == -1) {
01960 for (j = 0; j < widgets[i].choice.nchoices; j++) {
01961 if (strncmp( widget->choice.userchoice,
01962 widgets[i].choice.choices[j], strlen( widgets[i].choice.choices[j])) == 0) {
01963
01964 do_it = 1;
01965 break;
01966 }
01967 }
01968 }
01969
01970 if (widgets[i].choice.mode == 1) {
01971 if ((atoi( widget->choice.userchoice) >= 1) &&
01972 (atoi( widget->choice.userchoice) <= widgets[i].choice.nchoices)) {
01973 strcpy( widget->choice.userchoice,
01974 widgets[i].choice.choices[atoi( widget->choice.userchoice) - 1]);
01975 do_it = 1;
01976 }
01977 }
01978
01979 if (widgets[i].choice.mode == 0)
01980 do_it = 1;
01981
01982 if (!do_it) {
01983 printf( "Impossible Choice for Variable \",%s\"\n", widget->generic.variable);
01984 return;
01985 }
01986
01987 strcpy( widgets[i].choice.userchoice, widget->choice.userchoice);
01988
01989 REMOVE_CALLBACK(choice_w[i], cb_id[i]);
01990 XmTextFieldSetString( choice_w[i], widgets[i].choice.userchoice);
01991 XmTextFieldSetInsertionPosition( choice_w[i], strlen( widgets[i].choice.userchoice));
01992 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
01993 was = i;
01994 sprintf( dum, "%s", widgets[i].choice.userchoice);
01995 break;
01996 case BROWSER:
01997 strcpy( widgets[i].file.userchain, widget->file.userchain);
01998 REMOVE_CALLBACK(filechain_w[i], cb_id[i]);
01999 XmTextFieldSetString( filechain_w[i], widgets[i].file.userchain);
02000 XmTextFieldSetInsertionPosition( filechain_w[i], strlen( widgets[i].file.userchain));
02001 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
02002 was = i;
02003 sprintf( dum, "%s", widgets[i].file.userchain);
02004 break;
02005 default:
02006 was = i;
02007 break;
02008 }
02009 }
02010 }
02011
02012 if (was == -1) {
02013
02014 return;
02015 }
02016
02017 for (i = 0; i < nb_widgets; i++) {
02018 if ((i != was) && ISSAMEVARIABLE(i, was)) {
02019 switch (widgets[i].generic.type) {
02020 case CHAIN:
02021
02022
02023 REMOVE_CALLBACK(chain_w[i], cb_id[i]);
02024 UPDATE_STRING(chain_w[i]);
02025
02026 RESTORE_CALLBACK(chain_w[i], cb_id[i]);
02027 break;
02028
02029
02030
02031
02032
02033
02034
02035 case CHOICE:
02036 REMOVE_CALLBACK(choice_w[i], cb_id[i]);
02037 UPDATE_STRING(choice_w[i]);
02038 RESTORE_CALLBACK(choice_w[i], cb_id[i]);
02039 break;
02040 case BROWSER:
02041 REMOVE_CALLBACK(filechain_w[i], cb_id[i]);
02042 UPDATE_STRING(filechain_w[i]);
02043 RESTORE_CALLBACK(filechain_w[i], cb_id[i]);
02044 break;
02045 case SLIDER:
02046 REMOVE_CALLBACK(sliderchain_w[i], cb_id[i]);
02047 UPDATE_STRING(sliderchain_w[i]);
02048 RESTORE_CALLBACK(sliderchain_w[i], cb_id[i]);
02049 UPDATE_SLIDERPOS;
02050 break;
02051 }
02052 }
02053 }
02054 XFlush( display);
02055
02056 }
02057
02058 #else
02059 #endif
02060
02061 int on_close_dialog( char *return_command, int returned_code)
02062 {
02063 int i;
02064
02065 sic_open_widget_board( );
02066
02067 for (i = 0; i < nb_widgets; i++) {
02068 sic_set_widget_def( i, &widgets[i]);
02069 }
02070
02071 sic_set_widget_returned_command( return_command);
02072 sic_set_widget_returned_code( returned_code);
02073
02074 sic_close_widget_board( );
02075
02076 return sic_post_command_text( "GUI\\END");
02077 }
02078
02079 int run_xinput( int argc, char **argv)
02080 {
02081 int i, j;
02082 char *Name = "DEBUG_SIC_XINPUT";
02083
02084
02085 #include <locale.h>
02086 if (setlocale( LC_NUMERIC, "en_US") == NULL) {
02087 if (setlocale( LC_NUMERIC, "UTF-8") == NULL) {
02088
02089
02090
02091
02092
02093 }
02094 }
02095
02096 sic_add_modified_variable_listener( update_variable);
02097
02098 if (getenv( Name) != 0)
02099 debugMode = 1;
02100
02101 nb_widgets = sic_open_widget_board( );
02102
02103 sic_get_widget_global_infos( window_title[0], helpfilename[0], main_command);
02104
02105
02106 for (i = 0; i < nb_widgets; i++) {
02107 sic_get_widget_def( i, &widgets[i]);
02108 }
02109
02110 sic_close_widget_board( );
02111
02112
02113
02114 for (i = 0; i < nb_widgets; i++)
02115 update[i] = 0;
02116 for (i = 0; i < nb_widgets; i++) {
02117 for (j = i + 1; j < nb_widgets; j++) {
02118 if (ISSAMEVARIABLE( i, j)) {
02119 update[i] = 1;
02120 update[j] = 1;
02121 }
02122 }
02123 }
02124
02125 #ifndef WIN32
02126 create_widgets( argc, argv);
02127 #else
02128 DialogFunc( NULL);
02129 #endif
02130
02131 return 0;
02132 }
02133