"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "xmsql-0.4.2/choice.c" of archive xmsql-0.4.2.tgz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2  * AUTHOR: Jay Schmidgall <jay.schmidgall@spdbump.sungardss.com>
    3  *
    4  * $Id: choice.c,v 1.6 1997/02/08 06:04:52 lister Exp $
    5  */
    6 
    7 #include <Xm/Xm.h>
    8 #include <Xm/BulletinB.h>
    9 #include <Xm/DialogS.h>
   10 #include <Xm/Form.h>
   11 #include <Xm/Frame.h>
   12 #include <Xm/Label.h>
   13 #include <Xm/PushB.h>
   14 #include <Xm/RowColumn.h>
   15 #include <Xm/Scale.h>
   16 #include <Xm/ToggleB.h>
   17 #include <Xm/TextF.h>
   18 #include <Xm/Text.h>
   19 
   20 #include <stdio.h>
   21 #include <string.h>
   22 
   23 #include "common.h"
   24 #include "ComboBox.h"
   25 #include "Xbae/Matrix.h"
   26 typedef struct {
   27     Widget  mw;
   28     int	    value;
   29 } SetValueStruct;
   30 
   31 SetColValueStruct  *tableCol;
   32 
   33 void cbRadio(w, client, call)
   34 Widget w;
   35 XtPointer client;
   36 XtPointer call;
   37 {
   38     XmComboBoxSelectionCallbackStruct *svs =
   39                            (XmComboBoxSelectionCallbackStruct *) call;
   40 
   41     switch(svs->index) {
   42     case 1:  tableCol->type = CHAR_TYPE;
   43              break;
   44     case 2:  tableCol->type = INT_TYPE;
   45              break;
   46     case 3:  tableCol->type = REAL_TYPE;
   47              break;
   48     default: break;
   49     }
   50 }
   51 
   52 void cbRadioLen(w, client, call)
   53 Widget w;
   54 XtPointer client;
   55 XtPointer call;
   56 {
   57     XmComboBoxSelectionCallbackStruct *svs =
   58                            (XmComboBoxSelectionCallbackStruct *) call;
   59 
   60     switch(svs->index) {
   61     case 1:  tableCol->ColLen = (short) 3;
   62              break;
   63     case 2:  tableCol->ColLen = (short) 5;
   64              break;
   65     case 3:  tableCol->ColLen = (short) 6;
   66              break;
   67     case 4:  tableCol->ColLen = (short) 8;
   68              break;
   69     case 5:  tableCol->ColLen = (short) 12;
   70              break;
   71     case 6:  tableCol->ColLen = (short) 20;
   72              break;
   73     default: tableCol->ColLen = (short) 2;
   74              break;
   75     }
   76 }
   77 
   78 void cbScale(w, client, call)
   79 Widget w;
   80 XtPointer client;
   81 XtPointer call;
   82 {
   83     XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct *) call;
   84     tableCol->ColLen = (short) cbs->value;
   85 
   86 if (debug)
   87     fprintf(debugfp,"ColLen Set Value is : %d\n", tableCol->ColLen);
   88 }
   89 
   90 void ColData(w, client, call)
   91 Widget w;
   92 XtPointer client;
   93 XtPointer call;
   94 {
   95     tableCol->ColData = XmTextFieldGetString(w);
   96 
   97 if (debug)
   98     fprintf(debugfp,"ColData is : %s\n", tableCol->ColData);
   99 
  100 }
  101 
  102 void ColLabel(w, client, call)
  103 Widget w;
  104 XtPointer client;
  105 XtPointer call;
  106 {
  107 
  108     tableCol->ColLabel = XmTextFieldGetString(w);
  109 
  110 if (debug)
  111     fprintf(debugfp,"ColLabel is : %s\n", tableCol->ColLabel);
  112 
  113 }
  114 
  115 
  116 Widget createButtonBox(parent, name)
  117 Widget parent;
  118 char *name;
  119 {
  120     Widget frame, frame2, label, rc;
  121 
  122     frame = XtVaCreateManagedWidget(
  123 	"frame", xmFrameWidgetClass, parent,
  124 	NULL);
  125 
  126     frame2 = XtVaCreateManagedWidget(
  127 	"frame", xmFrameWidgetClass, frame,
  128 	XmNchildType,		    XmFRAME_TITLE_CHILD,
  129 	XmNchildHorizontalAlignment,   XmALIGNMENT_CENTER,
  130 	XmNchildVerticalAlignment,	    XmALIGNMENT_CENTER,
  131 	XmNmarginWidth,		    4,
  132 	NULL);
  133 
  134     label = XtVaCreateManagedWidget(
  135 	name, xmLabelWidgetClass, frame2,
  136 	NULL);
  137 
  138     rc = XtVaCreateManagedWidget(
  139 	"rc", xmRowColumnWidgetClass, frame,
  140 	XmNchildType,	    XmFRAME_WORKAREA_CHILD,
  141 	XmNadjustLast,	    False,
  142 	XmNradioBehavior,   True,
  143 	XmNradioAlwaysOne,  True,
  144 	XmNorientation,     XmHORIZONTAL,
  145 	XmNpacking,	    XmPACK_COLUMN,
  146 	NULL);
  147     return rc;
  148 }
  149 
  150 
  151 Widget createScaleBox(parent, name, min, max)
  152 Widget parent;
  153 char *name;
  154 int min, max;
  155 {
  156     Widget frame, frame2, label, scale;
  157 
  158     frame = XtVaCreateManagedWidget(
  159 	"frame", xmFrameWidgetClass, parent,
  160 				    NULL);
  161 
  162     frame2 = XtVaCreateManagedWidget(
  163 	"frame", xmFrameWidgetClass, frame,
  164 	XmNchildType,		    XmFRAME_TITLE_CHILD,
  165 	XmNchildHorizontalAlignment,   XmALIGNMENT_CENTER,
  166 	XmNchildVerticalAlignment,	    XmALIGNMENT_CENTER,
  167 	XmNmarginWidth,		    4,
  168 	NULL);
  169 
  170     label = XtVaCreateManagedWidget(
  171 	name, xmLabelWidgetClass, frame2,
  172 	NULL);
  173 
  174     scale = XtVaCreateManagedWidget(
  175 	"scale", xmScaleWidgetClass, frame,
  176 	XmNchildType,     XmFRAME_WORKAREA_CHILD,
  177 	XmNorientation,   XmHORIZONTAL,
  178 	XmNminimum,	  min,
  179 	XmNmaximum,	  max,
  180 	XmNscaleMultiple, 1,
  181 	XmNshowValue,     True,
  182 	NULL);
  183     return scale;
  184 }
  185 
  186 
  187 void createColType(parent, mw, type)
  188 Widget parent;
  189 Widget mw;
  190 int    type;
  191 {
  192     XmString   item;
  193     Widget rc, combo;
  194     SetValueStruct *svs;
  195 
  196     rc = createButtonBox(parent, "Column Type");
  197 
  198     combo = XtVaCreateManagedWidget(
  199 	"TYPE", xmComboBoxWidgetClass, rc,
  200 	NULL);
  201 /*
  202     svs = XtNew(SetValueStruct);
  203     svs->mw = mw;
  204     svs->value = CHAR_TYPE;
  205 
  206     XtAddCallback(button, XmNvalueChangedCallback, cbRadio, (XtPointer) svs);
  207  */
  208     XtAddCallback(combo, XmNselectionCallback, cbRadio, NULL);
  209     item = XmStringCreateSimple("Char");
  210     XmComboBoxAddItem(combo, item, 0);
  211     XmComboBoxSelectItem(combo, item, False);
  212     XmStringFree(item);
  213 
  214     tableCol->type = CHAR_TYPE;
  215 
  216     item = XmStringCreateSimple("Integer");
  217     XmComboBoxAddItem(combo, item, 0);
  218     XmStringFree(item);
  219     item = XmStringCreateSimple("Real");
  220     XmComboBoxAddItem(combo, item, 0);
  221     XmStringFree(item);
  222 
  223 }
  224 
  225 void createColLen(parent, mw, type)
  226 Widget parent;
  227 Widget mw;
  228 int    type;
  229 {
  230     int       len;
  231     XmString  item;
  232     Widget    rc, combo;
  233 /*
  234     SetValueStruct *svs;
  235 */
  236     rc = createButtonBox(parent, "Column Length");
  237 
  238     combo = XtVaCreateManagedWidget(
  239 	"COLLEN", xmComboBoxWidgetClass, rc,
  240 	NULL);
  241 /*
  242     svs = XtNew(SetValueStruct);
  243     svs->mw = mw;
  244     svs->value = 3;
  245     XtAddCallback(button, XmNvalueChangedCallback, cbRadioLen, (XtPointer) svs);
  246 */
  247     XtAddCallback(combo, XmNselectionCallback, cbRadioLen, NULL);
  248 
  249     item = XmStringCreateSimple("3");
  250     XmComboBoxAddItem(combo, item, 0);
  251     XmComboBoxSelectItem(combo, item, False);
  252     XmStringFree(item);
  253 
  254     tableCol->ColLen = (short) 3;
  255     item = XmStringCreateSimple("5");
  256     XmComboBoxAddItem(combo, item, 0);
  257     XmStringFree(item);
  258     item = XmStringCreateSimple("6");
  259     XmComboBoxAddItem(combo, item, 0);
  260     XmStringFree(item);
  261     item = XmStringCreateSimple("8");
  262     XmComboBoxAddItem(combo, item, 0);
  263     XmStringFree(item);
  264     item = XmStringCreateSimple("12");
  265     XmComboBoxAddItem(combo, item, 0);
  266     XmStringFree(item);
  267     item = XmStringCreateSimple("20");
  268     XmComboBoxAddItem(combo, item, 0);
  269     XmStringFree(item);
  270 
  271 }
  272 
  273 void createColData(top, mw, type)
  274 Widget top;
  275 Widget mw;
  276 int    type;
  277 {
  278     Widget cap, label, tf;
  279     cap = XtVaCreateManagedWidget("rc",
  280           xmRowColumnWidgetClass, formdlg,
  281           XmNtopAttachment,	XmATTACH_WIDGET,
  282 	  XmNtopWidget,	top,
  283 	  XmNtopOffset,	4,
  284 	  XmNleftAttachment,	XmATTACH_FORM,
  285 	  XmNleftOffset,	4,
  286 	  XmNrightAttachment,	XmATTACH_FORM,
  287 	  XmNrightOffset,	4,
  288 	  XmNadjustLast,		True,
  289 	  XmNorientation,	        XmHORIZONTAL,
  290 	  /*XmNnumColumns,		2,*/
  291 	  XmNpacking,		XmPACK_TIGHT,
  292 	  NULL);
  293 
  294     if ((type == SetColumnName) || (type == AddColumn)
  295          || (type == AddTailColumn)) {
  296           label = XtVaCreateManagedWidget(
  297         	  "Label Name:" , xmLabelWidgetClass, cap,
  298                   NULL);
  299 
  300           tf = XtVaCreateManagedWidget("tf",
  301 		  xmTextFieldWidgetClass, cap,
  302                   XmNcolumns, 20,
  303                   XmNeditable, True,
  304         	  NULL);
  305 
  306           tableCol->labelW = tf;
  307 
  308           XtAddCallback(tf,XmNactivateCallback,ColLabel,NULL);
  309     }
  310 
  311     if ((type == SetColumnData) || (type == AddColumn)
  312          || (type == AddTailColumn)) {
  313           label = XtVaCreateManagedWidget(
  314 	          "Data:" , xmLabelWidgetClass, cap,
  315                   NULL);
  316 
  317           tf = XtVaCreateManagedWidget("tf",
  318 		  xmTextFieldWidgetClass, cap,
  319                   XmNcolumns, 20,
  320                   XmNeditable, True,
  321         	  NULL);
  322 
  323           tableCol->dataW = tf;
  324 
  325           XtAddCallback(tf,XmNactivateCallback,ColData,NULL);
  326 
  327     }
  328 }
  329 
  330 void SetColumnLen()
  331 {
  332    char      tmp[80];
  333    short     *widths;
  334    int       i;
  335 
  336 if (debug)
  337    fprintf(debugfp,"Desired Len: %d\n",tableCol->ColLen);
  338 
  339    widths = (short *)malloc((cMsql.rowsCount+2)*sizeof(short));
  340 
  341    XtVaGetValues(tableMW,
  342                  XmNcolumnWidths, &widths,
  343                  NULL);
  344 
  345    /* Check if shrinking */
  346    if (widths[hs.lastcolumn] < tableCol->ColLen)
  347            widths[hs.lastcolumn] = tableCol->ColLen;
  348 
  349    seekFld(hs.lastcolumn);
  350 
  351    cMsql.flist->length = tableCol->ColLen;
  352    cMsql.flist->type = 'C';
  353 
  354 if (debug) {
  355 
  356    sprintf(tmp,"%s:C%d",cMsql.flist->fld,tableCol->ColLen);
  357    fprintf(debugfp,"Producing Fieldlist %s\n",tmp);
  358 
  359    }
  360 
  361    XtVaSetValues(tableMW,
  362                  XmNcolumnWidths, widths,
  363                  NULL);
  364 
  365    XbaeMatrixRefresh(tableMW);
  366 
  367    free((short *)widths);
  368 }
  369 
  370 void updateColumnData()
  371 {
  372    char      tmp[80];
  373    int       i, j;
  374 
  375 
  376    tableCol->ColData = XmTextFieldGetString(tableCol->dataW);
  377 
  378    cMsql.cells = (String **)malloc((cMsql.rowsCount+2) *
  379                    (cMsql.fldsCount+2) * sizeof(String *));
  380 
  381    XtVaGetValues(tableMW,
  382                  XmNcells, &cMsql.cells,
  383                  NULL);
  384    for (i = 0; i < cMsql.rowsCount; i++)
  385             cMsql.cells[i][hs.lastcolumn] = &tableCol->ColData[0];
  386 
  387    XtVaSetValues(tableMW,
  388                  XmNcells, cMsql.cells,
  389                  NULL);
  390    XbaeMatrixRefresh(tableMW);
  391 
  392 }
  393 
  394 void okChoiceCB(w, client, call)
  395 Widget w;
  396 XtPointer client;
  397 XtPointer call;
  398 {
  399    int       type = (int)client;
  400 
  401    char      tmp[80];
  402    char      tmpswap[80];
  403    int       i, j;
  404    short     *widths;
  405    String    *coldatas;
  406    Flist     *flist;
  407 
  408    XtDestroyWidget(formdlg);
  409 
  410    if (type == SetColumnWidth) {
  411             SetColumnLen();
  412             return;
  413    }
  414 
  415 if (debug)
  416    fprintf(debugfp,"Not SetColumnLen!\n");
  417 
  418    if (type == SetColumnData) {
  419             updateColumnData();
  420             return;
  421    }
  422 
  423 if (debug)
  424    fprintf(debugfp,"Not updateColumData\n");
  425 
  426    if (hs.lastcolumn == -1) hs.lastcolumn = 0;
  427    if (type == AddTailColumn) hs.lastcolumn += 1;
  428 
  429    tableCol->ColData  = XmTextFieldGetString(tableCol->dataW);
  430    tableCol->ColLabel = XmTextFieldGetString(tableCol->labelW);
  431 
  432 if (debug)
  433    fprintf(debugfp,"Start do AddColumn pos: %d\n",hs.lastcolumn);
  434 
  435    widths = (short *)malloc((cMsql.rowsCount+1)*sizeof(short));
  436    coldatas = (String *)malloc((cMsql.rowsCount+1)*sizeof(String));
  437 
  438    for (i = 0; i < cMsql.rowsCount; i++) {
  439 	    widths[i] = tableCol->ColLen;
  440 	    coldatas[i]=(char *)malloc(sizeof(tableCol->ColData)+1);
  441             strcpy(coldatas[i] ,tableCol->ColData);
  442    }
  443 
  444 if (debug)
  445    fprintf(debugfp,"Before do XbaeAddColumns\n");
  446 
  447    XbaeMatrixAddColumns(tableMW, hs.lastcolumn, coldatas,
  448           (String *)&tableCol->ColLabel, widths, NULL, NULL, NULL, NULL, 1);
  449 
  450    free ((short *)widths);
  451    free ((String *)coldatas);
  452    XbaeMatrixRefresh(tableMW);
  453 
  454 if (debug)
  455    fprintf(debugfp,"After Add Column\n");
  456 
  457    cMsql.fldsCount = XbaeMatrixNumColumns(tableMW);
  458    cMsql.rowsCount = XbaeMatrixNumRows(tableMW);
  459 
  460 if (debug)
  461    fprintf(debugfp,"Enter okChoiceCB2 %d\n",cMsql.fldsCount);
  462 
  463    if (hs.lastcolumn < (cMsql.fldsCount - 1)) seekFld(hs.lastcolumn);
  464 
  465    flist = (Flist *)malloc(sizeof(Flist));
  466 
  467    switch (tableCol->type) {
  468    case CHAR_TYPE : flist->type = 'C';
  469                     break;
  470    case INT_TYPE  : flist->type = 'N';
  471                     break;
  472    case REAL_TYPE : flist->type = 'R';
  473                     break;
  474    default        : break;
  475    }
  476 
  477    flist->fld = (char *)malloc(strlen(tableCol->ColLabel)+1);
  478    strcpy(flist->fld,tableCol->ColLabel);
  479    flist->length = tableCol->ColLen;
  480    flist->fldno  = 999;
  481    insertFld(cMsql.flist,flist);
  482 
  483 if (debug)
  484    fprintf(debugfp,"After Add Flds: %s(%d)\n",cMsql.flist->fld,cMsql.fldsCount);
  485    rewindFlds();
  486    reorderFlds();
  487    hs.lastcolumn ++ ;
  488 }
  489 
  490 void cancelChoiceCB(w, client, call)
  491 Widget w;
  492 XtPointer client;
  493 XtPointer call;
  494 {
  495     XtDestroyWidget(formdlg);
  496 }
  497 
  498 void AddChoiceDlgCB(w, name, type)
  499 Widget  w;
  500 char    *name;
  501 int     type;
  502 {
  503     Widget rc, button;
  504 
  505     rc = createButtonBox(w, "Reply:");
  506 
  507     button = XtVaCreateManagedWidget(
  508 	"OK", xmPushButtonWidgetClass, rc,
  509 	NULL);
  510     XtAddCallback(button, XmNactivateCallback, okChoiceCB, (XtPointer)type);
  511 
  512     button = XtVaCreateManagedWidget(
  513 	"Cancel", xmPushButtonWidgetClass, rc,
  514 	NULL);
  515     XtAddCallback(button, XmNactivateCallback, cancelChoiceCB, NULL);
  516 
  517 }
  518 
  519 
  520 void ColChoice(type)
  521 int type;
  522 {
  523     Widget    rc, cap, tf, label;
  524     Arg       args[20];
  525     Cardinal  n;
  526     char      *name="ColChoice";
  527     XmString  item;
  528 
  529     tableCol = XtNew(SetColValueStruct);
  530 
  531     n = 0;
  532     XtSetArg(args[n], XmNallowResize, True); n++;
  533 
  534     formdlg = XmCreateFormDialog(toplevel,"Column Choice",args,n);
  535 
  536     rc = XtVaCreateManagedWidget(
  537 	"rc", xmRowColumnWidgetClass, formdlg,
  538 	XmNtopAttachment,	XmATTACH_FORM,
  539 	XmNleftAttachment,	XmATTACH_FORM,
  540 	XmNadjustLast,		True,
  541 	XmNorientation,	        XmHORIZONTAL,
  542 	XmNnumColumns,		3,
  543 	XmNpacking,		XmPACK_TIGHT,
  544 	NULL);
  545 
  546     if ((type != SetColumnWidth) && (type != SetColumnData))
  547             createColType(rc, tableMW, type);
  548 
  549     if (type != SetColumnData)
  550             createColLen(rc, tableMW, type);
  551 
  552     if (type != SetColumnWidth) {
  553             createColData(rc, tableMW, type);
  554     }
  555 
  556     AddChoiceDlgCB(rc,name,type);
  557 
  558 
  559     XtManageChild(formdlg);
  560 }
  561 
  562 
  563 
  564 
  565 
  566 
  567 
  568 
  569 
  570 
  571 
  572