📄 dna.cc
字号:
label = XmCreateLabel(parent, string, args, n); XtManageChild(label); return label;} //--------------------------------------------------------------------//// event_loop //// Wait here until user clicks OK or Cancel, so that the variables //// being filled don't go out of scope. The only other way to avoid //// this is to make all the variables global, which would make the //// program incompatible with the DOS version. //// Compare the widget ID of the form clicked in case 2 dialogs //// are active. ////--------------------------------------------------------------------//void event_loop(Widget w){ g.dialogdone = 0; g.getout=0; while(g.dialogdone != w && g.getout==0) XtAppProcessEvent (XtWidgetToApplicationContext(g.main_widget), XtIMAll); g.dialogdone=0;} //--------------------------------------------------------------------//// list - display a single list (Motif) ////--------------------------------------------------------------------//void list(listinfo *l) { int wc = 0; Widget form, list, *widgetlist; widgetlist = new Widget[100]; form = openwindow(l, &list, widgetlist, &wc); event_loop(form); closewindow(form, widgetlist, wc); XtUnmanageChild(form); delete[] widgetlist;}//--------------------------------------------------------------------//// additemtolist //// 'w' is the list widget to add the item to. //// 'l' is a ptr to the listinfo struct //// 'form' is the form widget the list is displayed on. //// 'showpos' can be TOP or BOTTOM. If TOP it displays first item. ////--------------------------------------------------------------------//void additemtolist(Widget w, Widget form, char *s, int showpos){ XmString xms; // Last param = position; 0 means append to list XmListAddItemUnselected(w, xms = XmStringCreateSimple(s), 0); if(showpos==BOTTOM) XmListSetBottomPos(w, 0); // Last item is last visible item. XmStringFree(xms); if(XtIsManaged(form)) XRaiseWindow(g.display, XtWindow(XtParent(form)));}//--------------------------------------------------------------------//// closewindow //// Unmanages & destroys all Widgets on an opened window. The calling //// routine must maintain a dynamic array w[] of Widgets and the //// Widget count wc, which are filled when openwindow() is called. ////--------------------------------------------------------------------//void closewindow(Widget form, Widget *widgetlist, int wc){ int k; XtUnmanageChild(form); for(k=0;k<wc;k++) XtDestroyWidget(widgetlist[k]);}//--------------------------------------------------------------------//// openwindow (Motif version) //// same as list except remains on screen permanently. Calling routine //// calls closewindow() to get rid of it. //// Pass the address of 'helptopic', not the helptopic no. itself, //// since the cb would go out of scope. //// Returns the list Widget in 'listwidget' so caller can add to list. //// 'listwidget' is needed for XmListAddItemUnselected. //// The return widget is needed as a parameter to closewindow(). //// The calling routine must create and maintain a dynamic array w //// of Widgets which is filled when openwindow() is called. This is //// used to destroy the Widgets in closewindow(). ////--------------------------------------------------------------------//Widget openwindow(listinfo *l, Widget *listwidget, Widget *w, int *count){ int k, width=0, xsize, ysize, showtop=TOP, wc=0; Widget list, form, label, savebutton; Arg args[100]; XmString xms; Cardinal n; const int LISTTOP = 8; xsize = 440; // Minimum size ysize = l->itemstoshow*16 +200; if(l->firstitem>1) showtop=BOTTOM; wc = *count; //------- Calculate width -----------------------------------------// for(k=0;k<l->size;k++) width=max(width,(int)strlen(l->info[k])); xsize = max(xsize,min(640,width*8)); xsize = max(l->width, xsize); //------- Create a form dialog shell widget -----------------------// n=0; XtSetArg(args[n], XmNwidth, xsize); n++; XtSetArg(args[n], XmNheight, ysize); n++; if(l->transient) { XtSetArg(args[n], XmNtransient, True); n++;} else { XtSetArg(args[n], XmNtransient, False); n++;} XtSetArg(args[n], XmNresizable, False); n++; XtSetArg(args[n], XmNautoUnmanage, False); n++; XtSetArg(args[n], XmNkeyboardFocusPolicy, XmEXPLICIT); n++; XtSetArg(args[n], XmNnavigationType, XmNONE); n++; XtSetArg(args[n], XmNdialogTitle, xms=XmStringCreateSimple(l->title)); n++; form = w[wc++] = XmCreateFormDialog(g.main_widget, "List", args, n); XmStringFree(xms); label = w[wc++] = addlabel(form, l->title, CENTER, 20, 1, 80, LISTTOP); //--------Title and 'save' button----------------------------------// addstandardbuttons(form, &w[wc], &l->helptopic); wc += 3; // addstandardbuttons adds 3 widgets savebutton = w[wc++] = XtVaCreateManagedWidget("Save", xmPushButtonWidgetClass, form, XmNtopAttachment, XmATTACH_NONE, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_NONE, XmNwidth, 100, XmNleftOffset, 335, XmNbottomOffset, 2, XmNdefaultButton, False, NULL); //------- Put scrolled list on the form ---------------------------// XtSetArg(args[n], XmNbottomOffset, 34); n++; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; XtSetArg(args[n], XmNtopWidget, label); n++; XtSetArg(args[n], XmNfractionBase, 100); n++; // Use percentages XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNresizable, False); n++; XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); n++; XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT); n++; XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++; XtSetArg(args[n], XmNorientation, XmVERTICAL); n++; XtSetArg(args[n], XmNvisibleItemCount, l->itemstoshow); n++; list = w[wc++] = XmCreateScrolledList(form, "list", args, n); *listwidget = list; XtAddCallback(list, XmNsingleSelectionCallback, listcb, (XtPointer*)l); l->widget = list; XtAddCallback(savebutton, XmNactivateCallback, (XtCallbackProc)savecb, (XtPointer)l); for(k=0;k<l->size;k++) additemtolist(list, form, l->info[k], showtop); XtManageChild(list); XtManageChild(form); *count = wc; return form;} //--------------------------------------------------------------------//// message (Motif version) //// valid modes //// ----------- //// NONE //// INFO //// PROMPT //// QUESTION //// YESNOQUESTION //// WARNING //// ERROR //// Space for the returnstring must be already allocated. //// 'maxstringsize' must be set to the buffer size of `returnstring' if//// mode is PROMPT. The string will be truncated to this size. //// Returns one of: //// OK //// INFO = a string was entered //// YES = user clicked Yes to yes/no question or Ok //// NO = user clicked No button //// CANCEL = user clicked Cancel button // //--------------------------------------------------------------------//int message(char *heading){ return message(heading, NULL, INFO, 0); }int message(char *heading, int mode){ if(mode==PROMPT) fprintf(stderr,"Error in message, line %d\n",__LINE__); return message(heading, NULL, mode, 50); }int message(char *heading, char *returnstring, int mode, int maxstringsize){ int alloc1=0, alloc3=0, n; XmString xms, xms2, xms3=NULL; Arg args[100]; Widget w2=0; Widget www; if(mode==NONE) return 0; if(!g.want_messages) return 0; int ostate = g.state; g.state = MESSAGE; clickboxinfo c; c.title = new char[1024]; c.helptopic = 34; c.answer = 0; c.form = NULL; c.maxstringsize = maxstringsize; if(mode==PROMPT && returnstring!=NULL) strcpy(c.title, returnstring); n = 0; xms = XmStringCreateLtoR(heading, XmFONTLIST_DEFAULT_TAG); XtSetArg(args[n], XmNmessageString, xms); n++; XtSetArg(args[n], XmNnoResize, False); n++; XtSetArg(args[n], XmNselectionLabelString, xms) ;n++; switch(mode) { case INFO: XtSetArg(args[n], XmNtitle, "Information"); n++; www = XmCreateInformationDialog(g.main_widget, "Information", args, n); break; case PROMPT: XtSetArg(args[n], XmNtitle, "Information needed"); n++; if(returnstring[0] && returnstring!=NULL) { alloc3=1; XtSetArg(args[n], XmNtextString,xms3=XmStringCreateSimple(returnstring));n++; } www = XmCreatePromptDialog(g.main_widget, "Prompt", args, n); if(alloc3) XmStringFree(xms3); break; case ERROR: XtSetArg(args[n], XmNtitle, "Error"); n++; www = XmCreateErrorDialog(g.main_widget, "Error", args, n); break; case QUESTION: // Ok, cancel, help XtSetArg(args[n], XmNtitle, "Question"); n++; www = XmCreateQuestionDialog(g.main_widget, "Question", args, n); break; case YESNOQUESTION: // Yes, no, cancel, help XtSetArg(args[n], XmNtitle, "Question"); n++; XtSetArg(args[n], XmNokLabelString, xms2=XmStringCreateSimple("Yes")); n++; www = XmCreateQuestionDialog(g.main_widget, "YesNoQuestion", args, n); n = 0; w2 = XmCreatePushButton(www, "No", args, n); XtManageChild(w2); alloc1 = 1; XtAddCallback(w2, XmNactivateCallback, nomsgcb, (XtPointer)&c); XmStringFree(xms2); break; case WARNING: default: XtSetArg(args[n], XmNtitle, "Warning"); n++; www = XmCreateWarningDialog(g.main_widget, "Warning", args, n); break; } if(mode==PROMPT) XtAddCallback(www, XmNokCallback, promptmsgcb, (XtPointer)&c); else XtAddCallback(www, XmNokCallback, okmsgcb, (XtPointer)&c); XtAddCallback(www, XmNcancelCallback, cancelmsgcb, (XtPointer)&c); XtManageChild(www); XmStringFree(xms); while(!c.answer) XtAppProcessEvent(XtWidgetToApplicationContext(www),XtIMAll); if(mode==PROMPT && c.title[0] && c.title!=NULL && returnstring!=NULL) { c.title[FILENAMELENGTH-2] = 0; strcpy(returnstring, c.title); } if(alloc1) XtDestroyWidget(w2); XtDestroyWidget(www); delete[] c.title; g.state = ostate; return c.answer;}//--------------------------------------------------------------------// // clickbox ////--------------------------------------------------------------------// int clickbox(char* title, int startval, int minval, int maxval, void f(int answer), int helptopic){ return clickbox(title,startval,minval,maxval,f,null,0,INTEGER,helptopic);}double clickbox(char* title, double fstartval, double fminval, double fmaxval, void f(double answer), int helptopic){ int startval, minval, maxval, answer; double fanswer; double factor = pow(10,g.signif); startval = (int)(fstartval * factor); minval = (int)(fminval * factor); maxval = (int)(fmaxval * factor); answer = clickbox(title, startval, minval, maxval, null, f, g.signif, DOUBLE, helptopic); fanswer = (double)answer / factor; return fanswer;}int clickbox(char* title, int startval, int minval, int maxval, void f1(int answer), void f2(double answer), int decimalpoints, int type, int helptopic){ Widget form, slider, text, *w; clickboxinfo clickboxdata[2]; int k, n, wc=0, xsize=340, ysize=200; Arg args[100]; w = new Widget[100]; char textlabel[FILENAMELENGTH]; int answer; if(minval==maxval || startval<minval || startval>maxval) { message("Value cannot currently be changed"); g.getout=0; return startval; } int ostate = g.state; g.state = MESSAGE; //------- Create a form dialog shell widget -----------------------// n=0; XtSetArg(args[n], XmNwidth, xsize); n++; XtSetArg(args[n], XmNheight, ysize); n++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -