⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialog.c

📁 BCView - Bayes Classifier Visualization Download xbcview Linux executable (218 kb) wbcview.exe W
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------  File    : dialog.c  Contents: simplified dialog definition for Athena widgets            (action functions, alert/about dialog, property sheets)  History : 15.05.1998 file created as psheet.c            03.06.1998 minor improvements            06.08.1998 functions psh_focus and psh_next added            09.01.2000 callback function stored as client data            12.01.2000 action functions and alert/about dialog added            15.01.2000 minimal width for toggles (checkboxes) added            20.01.2000 text display dialog box added            17.09.2002 cursor positioned at end of text            26.04.2004 "apply" functionality added to function db_close            27.04.2004 backward direction added to function db_next----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include "dialog.h"#include <X11/StringDefs.h>#include <X11/cursorfont.h>#include <X11/Xaw/Form.h>#include <X11/Xaw/Viewport.h>#include <X11/Xaw/Label.h>#include <X11/Xaw/Command.h>#include <X11/Xaw/Toggle.h>#include <X11/Xaw/AsciiText.h>#include <X11/Xaw/MenuButton.h>#include <X11/Xaw/SimpleMenu.h>#include <X11/Xaw/SmeBSB.h>#include <X11/Xaw/SmeLine.h>/*----------------------------------------------------------------------  Preprocessor Definitions----------------------------------------------------------------------*/#define PSH_LINE    -1          /* line label */#define BLKSIZE     32          /* block size for item vector */#define TXT_WD     320          /* width  of text display box */#define TXT_HT     120          /* height of text display box */#define TXT_MINWD  240          /* minimum width  of text display box */#define TXT_MINHT   96          /* minimum height of text display box *//*----------------------------------------------------------------------  Constants----------------------------------------------------------------------*/#include "excl.xbm"             /* exclamation mark for alert boxes */#include "logo.xbm"             /* logo bitmap (Otto von Guericke) *//*----------------------------------------------------------------------  Global Variables----------------------------------------------------------------------*/static XtActionsRec actions[] = {  { "db_focus",  db_focus },    /* set focus on input field */  { "db_next",   db_next  },    /* switch to next input field */  { "db_close",  db_close } };  /* close dialog box *//*----------------------------------------------------------------------  Dialog Box Action Functions----------------------------------------------------------------------*/void db_focus (Widget w, XEvent *e, String *s, Cardinal *c){                               /* --- set focus on input field */  XtSetKeyboardFocus(XtParent(XtParent(w)), w);}  /* db_focus() *//*--------------------------------------------------------------------*/void db_next (Widget w, XEvent *e, String *s, Cardinal *c){                               /* --- switch to next input field */  Widget     form;              /* form widget of property sheet */  WidgetList list;              /* list of child widgets */  Cardinal   n, i;              /* number of child widgets, index */  Boolean    dc;                /* whether to display caret */  form = XtParent(w);           /* get form widget */  XtVaGetValues(form, XtNnumChildren, &n, XtNchildren, &list, NULL);  for (i = 0; i < n; i++)       /* get children of shell widget */    if (list[i] == w) break;    /* and look for current widget */  if (i >= n) return;           /* if not found, abort function */  while (1) {                   /* widget search loop */    if ((*c == 0) || (atoi(*s) >= 0)) {         if (++i >= n) i = 0; } /* go to next child of shell widget */    else if (i-- <= 0) i = n-1; /* or to the preceding child */    if (list[i] == w) break;    /* if round completed, abort */    if (XtClass(list[i]) != asciiTextWidgetClass)      continue;                 /* skip non-text gadgets */    XtVaGetValues(list[i], XtNdisplayCaret, &dc, NULL);    if (dc) break;              /* if to display a caret (editable), */  }                             /* abort the loop */  XtSetKeyboardFocus(XtParent(form), list[i]);}  /* db_next() */              /* set new input focus *//*--------------------------------------------------------------------*/void db_close (Widget w, XEvent *e, String *s, Cardinal *c){                               /* --- close dialog box */  Widget b;                     /* buffer for button widget */  void   *p;                    /* user data for button callback */  while (!XtIsTransientShell(w))    w = XtParent(w);            /* find the shell widget */  if ((*c == 0) || (strcmp(*s, "cancel") == 0)) {    b = XtNameToWidget(w, "*cancel");    if (b) { XtCallCallbacks(b, XtNcallback, (void*)0); return; }  }                             /* call button callback function */  b = XtNameToWidget(w, "*ok"); /* of a cancel or an ok button */  p = (void*)((strcmp(*s, "ok") == 0) ? 1 : 2);  if (b) { XtCallCallbacks(b, XtNcallback, p); return; }  XtPopdown(w);                 /* close the dialog box */}  /* db_close() *//*----------------------------------------------------------------------  Alert Box Function----------------------------------------------------------------------*/int db_alert (Widget parent, XtCallbackProc callback, const char *msg){                               /* --- show an alert dialog box */  static Widget alert = NULL;   /* shell widget */  static int    init  = 0;      /* initialization flag */  Widget    shell, form;        /* shell and form for alert box */  Widget    text, ok;           /* widgets of message and button */  Pixmap    excl;               /* bitmap for exclamation mark */  Arg       args[4];            /* widget arguments */  int       n;                  /* argument counter */  Position  x,  y;              /* position of dialog box */  Dimension wd, ht;             /* width and height of created dialog */  Atom      wm_delwin;          /* delete window atom of window mgr. */  if (!alert) {                 /* if widget is not created */    shell = XtCreatePopupShell("alertDlg", transientShellWidgetClass,              parent, NULL, 0); /* create a dialog box shell */    if (!shell) { XtDestroyWidget(shell); return -1; }    XtVaSetValues(shell, XtNallowShellResize, True, NULL);    XtSetArg(args[0], XtNborderWidth, 0);    form = XtCreateManagedWidget("form", formWidgetClass,             shell, args, 1);   /* create form for box layout */    if (!form)  { XtDestroyWidget(shell); return -1; }    excl  = XCreateBitmapFromData(XtDisplay(parent), XtWindow(parent),              (char*)excl_bits, excl_width, excl_height);    if (!excl) { XtDestroyWidget(shell); return -1; }    n = 0;                      /* build argument list */    XtSetArg(args[n], XtNborderWidth, 0);    n++;    XtSetArg(args[n], XtNresizable,   True); n++;    XtSetArg(args[n], XtNleftBitmap,  excl); n++;    text = XtCreateManagedWidget("msg", labelWidgetClass,              form, args, n);   /* create text label */    if (!text) { XtDestroyWidget(shell); return -1; }    n = 0;                      /* build argument list */    XtSetArg(args[n], XtNfromVert,  text);   n++;    XtSetArg(args[n], XtNresizable, True);   n++;    ok   = XtCreateManagedWidget("ok", commandWidgetClass,             form, args, n);    /* create 'ok' button */    if (!ok) { XtDestroyWidget(shell); return -1; }    XtInstallAllAccelerators(form, form);    alert = shell;              /* install accelerators and */  }                             /* note created dialog box widget */  if (!msg) return 0;           /* if no message, abort function */  text = XtNameToWidget(alert, "*msg");  ok   = XtNameToWidget(alert, "*ok");  XtRemoveAllCallbacks(ok, XtNcallback);  XtAddCallback(ok,     XtNcallback, callback, NULL);  XtVaSetValues(text,   XtNlabel, msg, NULL);  XtVaGetValues(text,   XtNwidth, &wd, XtNheight, &ht, NULL);  if (ht < excl_height)         /* adapt width and height of widgets */    XtVaSetValues(text, XtNheight, excl_height, NULL);  XtVaSetValues(ok,     XtNwidth, 1,  NULL);  /* force resize (seems */  XtVaSetValues(ok,     XtNwidth, wd, NULL);  /* to be necessary) */  XtVaGetValues(parent, XtNx, &x, XtNy, &y, NULL);  XtVaSetValues(alert,  XtNx,  x, XtNy,  y, NULL);  XtPopup(alert, XtGrabExclusive);  /* place and show alert box */  XtVaGetValues(alert,  XtNwidth, &wd, XtNheight, &ht, NULL);  XtVaSetValues(alert,  XtNminWidth, wd, XtNminHeight, ht,                        XtNmaxWidth, wd, XtNmaxHeight, ht, NULL);  if (!init) {                  /* if shell was created */    XtOverrideTranslations(alert,      XtParseTranslationTable("<Message>WM_PROTOCOLS: db_close()"));    wm_delwin = XInternAtom(XtDisplay(alert),      "WM_DELETE_WINDOW", False);    XSetWMProtocols(XtDisplay(alert), XtWindow(alert), &wm_delwin, 1);    init = 1;                   /* override WM delete and */  }                             /* set the initialization flag */  return 0;                     /* return `ok' */ }  /* db_alert() *//*----------------------------------------------------------------------  About Box Function----------------------------------------------------------------------*/int db_about (Widget parent, XtCallbackProc callback){                               /* --- show an about dialog box */  static Widget about = NULL;   /* shell widget of about box */  Widget    shell = NULL, form; /* widgets for shell and form */  Widget    label, logo, ok;    /* widgets for labels and button */  Pixmap    bmap;               /* logo bitmap */  Arg       args[4];            /* widget argument list */  int       n;                  /* argument counter */  Position  x,  y;              /* position of dialog box */  Dimension wd, ht;             /* width and height of created dialog */  Atom      wm_delwin;          /* delete window atom of window mgr. */  if (!about) {                 /* if widget is not created */    shell = XtCreatePopupShell("aboutDlg", transientShellWidgetClass,              parent, NULL, 0); /* create a dialog box shell */    if (!shell) { XtDestroyWidget(shell); return -1; }    XtSetArg(args[0], XtNborderWidth, 0);    form  = XtCreateManagedWidget("form", formWidgetClass,              shell, args, 1);   /* create form for box layout */    if (!form)  { XtDestroyWidget(shell); return -1; }    XtSetArg(args[0], XtNborderWidth, 0);    label = XtCreateManagedWidget("info", labelWidgetClass,              form, args, 1);   /* create text label */    if (!label) { XtDestroyWidget(shell); return -1; }    bmap  = XCreateBitmapFromData(XtDisplay(parent), XtWindow(parent),              (char*)logo_bits, logo_width, logo_height);    if (bmap == None) {         /* create logo bitmap */      XtDestroyWidget(shell); return -1; }    n = 0;                      /* build argument list */    XtSetArg(args[n], XtNborderWidth,   0);     n++;    XtSetArg(args[n], XtNinternalWidth, 0);     n++;    XtSetArg(args[n], XtNfromHoriz,     label); n++;    XtSetArg(args[n], XtNbitmap,        bmap);  n++;    logo = XtCreateManagedWidget("logo", labelWidgetClass,             form, args, n);    /* create logo label */    if (!logo) { XtDestroyWidget(shell);      XFreePixmap(XtDisplay(parent), bmap); return -1; }    n = 0;                      /* build argument list */    XtSetArg(args[n], XtNfromHoriz, label);      n++;    XtSetArg(args[n], XtNfromVert,  logo);       n++;    XtSetArg(args[n], XtNwidth,     logo_width); n++;    ok = XtCreateManagedWidget("ok", commandWidgetClass,           form, args, n);      /* create 'ok' button */    if (!ok) { XtDestroyWidget(shell);      XFreePixmap(XtDisplay(parent), bmap); return -1; }    XtInstallAllAccelerators(form, form);    about = shell;              /* install accelerators and */  }                             /* note created dialog box widget */  ok = XtNameToWidget(about, "*ok");  XtRemoveAllCallbacks(ok, XtNcallback);  XtAddCallback(ok, XtNcallback, callback, NULL);  XtVaGetValues(parent, XtNx, &x, XtNy, &y, NULL);  XtVaSetValues(about,  XtNx,  x, XtNy,  y, NULL);  XtPopup(about, XtGrabExclusive);  if (shell) {                  /* show and prepare dialog box */    XtVaGetValues(shell, XtNwidth,   &wd, XtNheight,   &ht, NULL);    XtVaSetValues(shell, XtNminWidth, wd, XtNminHeight, ht,                         XtNmaxWidth, wd, XtNmaxHeight, ht, NULL);    XtOverrideTranslations(shell,      XtParseTranslationTable("<Message>WM_PROTOCOLS: db_close()"));    wm_delwin = XInternAtom(XtDisplay(shell),      "WM_DELETE_WINDOW", False);    XSetWMProtocols(XtDisplay(shell), XtWindow(shell), &wm_delwin, 1);  }                             /* inhibit resize, override WM delete */  return 0;                     /* return 'ok' */}  /* db_about() *//*----------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -