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

📄 dialog.c

📁 BCView - Bayes Classifier Visualization Download xbcview Linux executable (218 kb) wbcview.exe W
💻 C
📖 第 1 页 / 共 3 页
字号:
           "!Alt<Key>c : db_close(cancel)\n"           "<Btn1Down> : db_focus()\n");    XtOverrideTranslations(item, tl);  }                             /* augment/override translations */  tmp = psh->items +psh->itemcnt++;  tmp->widget = psh->previtem = item;  tmp->type   = type;           /* note item and its type */  if (!psh->currline) psh->currline = item;  return 0;                     /* return `ok' */}  /* psh_additem() *//*--------------------------------------------------------------------*/int psh_addcb (PSHEET *psh, const char *name,              XtCallbackProc callback, XtPointer data){                               /* --- set callback procedure */  XtAddCallback(XtNameToWidget(psh->form, name),    XtNcallback, callback, data);  return 0;                     /* return `ok' */}  /* psh_addcb() *//*--------------------------------------------------------------------*/int psh_menuadd (PSHEET *psh, const char *name, const char *text){                               /* --- add an item to a menu */  Widget pane;                  /* widget for menu pane */  Widget item;                  /* widget for menu item */  pane = XtNameToWidget(psh->form, name);  pane = XtNameToWidget(pane, name);  if (!text) {                  /* if no text is given */    item = XtCreateManagedWidget("_line_",             smeLineObjectClass, pane, NULL, 0);    if (!item) return -1; }     /* create a separating line */  else {                        /* if an item name is given */    item = XtCreateManagedWidget(text,             smeBSBObjectClass, pane, NULL, 0);    if (!item) return -1;       /* create a menu item */    XtAddCallback(item, XtNcallback, cb_menu, NULL);  }                             /* add callback function */  return 0;                     /* return `ok' */}  /* psh_menuadd() *//*--------------------------------------------------------------------*/int psh_setval (PSHEET *psh, const char *name, const char *text){                               /* --- set a prop. sheet item value */  int     i, k;                 /* loop variable, buffer */  Widget  item;                 /* widget of property sheet item */  Widget  *mnitem;              /* to traverse menu items */  PSHITEM *pshi;                /* to traverse item vector */  String  menu;                 /* name of menu */  String  label;                /* label */  item = XtNameToWidget(psh->form, name);  pshi = psh->items;            /* traverse property sheet items */  for (i = psh->itemcnt; --i >= 0; pshi++)    if (item == pshi->widget) break;  if (i < 0) return -1;         /* find item in item vector */  switch (pshi->type) {         /* according to item type */    case PSH_TOGGLE:            /* toggle button (checkbox) */      XtVaSetValues(item, XtNstate, (text) ? True : False, NULL);      break;                    /* set new state of toggle */    case PSH_TEXT:              /* non-editable text field */    case PSH_EDIT:              /* editable text field */      XtVaSetValues(item, XtNstring, text, NULL);      XawTextSetInsertionPoint(item, strlen(text));      break;                    /* set new string */    case PSH_MENU:              /* menu */      XtVaGetValues(item, XtNmenuName, &menu, NULL);      XtVaGetValues(XtNameToWidget(pshi->widget, menu),        XtNnumChildren, &k, XtNchildren, &mnitem, NULL);      i = (int)text;            /* get index of selection */      if (i >= k) return -1;    /* and check it */      XtVaGetValues(mnitem[i], XtNlabel, &label, NULL);      XtVaSetValues(item,      XtNlabel, label,  NULL);      break;                    /* set new selection */    default:                    /* otherwise */      XtVaSetValues(item, XtNlabel, text, NULL);      break;                    /* set new label */  }  return 0;                     /* return `ok' */}  /* psh_setval() *//*--------------------------------------------------------------------*/const char* psh_getval (PSHEET *psh, const char *name){                               /* --- get a prop. sheet item value */  int     i, k;                 /* loop variables */  Widget  item;                 /* widget of property sheet item */  Widget  *mnitem;              /* to traverse menu items */  PSHITEM *pshi;                 /* to traverse item vector */  String  menu;                 /* name of menu */  String  label;                /* label */  String  text;                 /* text input */  Boolean state;                /* state of toggle */  item = XtNameToWidget(psh->form, name);  pshi = psh->items;            /* traverse property sheet items */  for (i = psh->itemcnt; --i >= 0; pshi++)    if (item == pshi->widget) break;  if (i < 0) return NULL;       /* find item in item vector */  switch (pshi->type) {         /* according to item type */    case PSH_TOGGLE:            /* toggle button (checkbox) */      XtVaGetValues(item, XtNstate, &state, NULL);      return (const char*)((state) ? 1 : 0);                                /* get and return state of toggle */    case PSH_TEXT:              /* non-editable text field */    case PSH_EDIT:              /* editable text field */      XtVaGetValues(item, XtNstring, &text, NULL);      return text;              /* get and return input text */    case PSH_MENU:              /* menu */      XtVaGetValues(item, XtNmenuName, &menu, NULL);      XtVaGetValues(XtNameToWidget(pshi->widget, menu),        XtNnumChildren, &k, XtNchildren, &mnitem, NULL);      XtVaGetValues(item, XtNlabel, &label, NULL);      for (i = 0; i < k; i++) { /* traverse menu items */        XtVaGetValues(mnitem[i], XtNlabel, &text, NULL);        if (strcmp(label, text) == 0) return (const char*)i;      } return (const char*)-1; /* get and return index of selection */    default:                    /* otherwise */      XtVaGetValues(item, XtNlabel, &label, NULL);      return label;             /* get and return label of item */  }}  /* psh_getval() *//*--------------------------------------------------------------------*/int psh_handle (PSHEET *psh, XtCallbackProc callback){                               /* --- handle property sheet dialog */  Atom      wm_delete;          /* delete window atom */  Dimension wd, ht;             /* width and height of created dialog */  Dimension dd;                 /* default distance of controls */  Dimension max;                /* maximal width of labels/controls */  Dimension total;              /* total width of dialog box */  Dimension tmp;                /* temporary buffer */  Position  x, y;               /* position of dialog box */  Arg       args[2];            /* widget argument list */  int       n, i;               /* argument counter, loop variable */  PSHITEM   *pshi;              /* to traverse items */  Widget    *item;              /* to traverse menu items */  String    name;               /* name of menu */  /* --- determine and set label width --- */  pshi = psh->items; max = 0;   /* traverse property sheet items */  for (n = psh->itemcnt; --n >= 0; pshi++) {    if ((pshi->type != PSH_LINE)/* skip non-labels */    ||  !pshi->widget) continue;/* and empty labels */    XtVaGetValues(pshi->widget, XtNwidth, &wd, NULL);    if (wd > max) max = wd;     /* determine the maximum */  }                             /* of the label widths */  pshi = psh->items;            /* traverse property sheet items */  for (n = psh->itemcnt; --n >= 0; pshi++) {    if ((pshi->type != PSH_LINE)/* skip non-labels */    ||  !pshi->widget) continue;/* and empty labels */    XtVaSetValues(pshi->widget, XtNwidth, max, NULL);  }                             /* set maximal label width */  total = max;                  /* and note it */  /* --- determine menu widths --- */  pshi = psh->items;            /* traverse property sheet items */  for (n = psh->itemcnt; --n >= 0; pshi++) {    if (pshi->type != PSH_MENU) continue;   /* skip non-menus */    XtVaGetValues(pshi->widget, XtNwidth, &max,      XtNmenuName, &name, NULL);    XtVaGetValues(XtNameToWidget(pshi->widget, name),      XtNnumChildren, &i, XtNchildren, &item, NULL);    for ( ; --i >= 0; item++) {      XtVaGetValues(*item, XtNwidth, &wd, NULL);      if (wd > max) max = wd;   /* determine maximal width */    }                           /* of menu entries */    XtVaSetValues(pshi->widget, XtNwidth, max, NULL);  }                             /* set maximal menu item width */  /* --- determine controls width --- */  #ifdef LINUX                  /* if Linux Athena Widgets */  XtVaGetValues(psh->form, XtNdefaultDistance, &dd, NULL);  #else                         /* get the default distance, */  dd = 4;                       /* if Sun or HP Athena Widgets */  #endif                        /* set the default distance */  pshi = psh->items; max = wd = 0; /* traverse property sheet items */  for (n = psh->itemcnt; --n >= 0; pshi++) {    if (pshi->type == PSH_LINE){/* if item is a label, */      if (wd > max) max = wd;   /* update the maximal line width */      if (!pshi->widget) {      /* if the label is empty, */        pshi++; n--;             /* go to the line control */        XtVaGetValues(pshi->widget, XtNwidth, &wd, NULL);        if (wd > total +max) max = wd -total;      }                         /* update the maximal line width */      wd = 0; continue;         /* reset the line width and */    }                           /* continue with the next item */    XtVaGetValues(pshi->widget, XtNwidth, &tmp, NULL);    wd += (wd > 0) ? tmp +dd +2 : tmp;  }                             /* determine the control width sum */  total += (wd > max) ? wd:max; /* determine total width of box and */  wd = (psh->ca) ? (total -2) /2 : total +dd;       /* button width */  n = 0;                        /* build argument list */  XtSetArg(args[n], XtNwidth,    wd);            n++;  XtSetArg(args[n], XtNfromVert, psh->currline); n++;  XtSetValues(psh->ok, args, n);/* set width of ok button */  if (psh->ca) {                /* if there is a cancel button */    XtSetArg(args[0], XtNwidth, total -2 -wd);    XtSetValues(psh->ca, args, n);  }                             /* set width of cancel button */  /* --- set width of line controls --- */  pshi = psh->items;            /* traverse property sheet items */  for (n = psh->itemcnt; --n >= 0; pshi++) {    if ((pshi->type != PSH_LINE)/* skip non-labels */    ||   pshi->widget) continue;/* and non-empty labels */    XtVaSetValues(pshi[1].widget, XtNwidth, total +dd, NULL);  }                             /* set maximal label width */  /* --- set callback functions --- */  XtRemoveAllCallbacks(psh->ok, XtNcallback);  XtAddCallback(psh->ok, XtNcallback, cb_ok, (XtPointer)callback);  if (psh->ca) {                /* if there is a cancel button */    XtRemoveAllCallbacks(psh->ca, XtNcallback);    XtAddCallback(psh->ca, XtNcallback, cb_cancel, (XtPointer)callback);  }                             /* set callback function for it, too */  /* --- install actions and accelerators --- */  XtAppAddActions(XtWidgetToApplicationContext(psh->parent),    actions, XtNumber(actions));  XtInstallAllAccelerators(psh->form, psh->form);  /* --- show dialog box --- */  XtVaGetValues(psh->parent, XtNx, &x, XtNy, &y, NULL);  XtVaSetValues(psh->shell,  XtNx,  x, XtNy,  y, NULL);  XtPopup(psh->shell, XtGrabExclusive);  for (pshi = psh->items, n = 0; n < psh->itemcnt; n++, pshi++) {    if (!pshi->widget) continue;/* traverse property sheet items */     if (XtClass(pshi->widget) == asciiTextWidgetClass) {      XtSetKeyboardFocus(psh->shell, pshi->widget); break; }  }                             /* set keyboard focus */  XtVaGetValues(psh->form, XtNdefaultDistance, &dd, NULL);  /* --- set position and inhibit resize --- */  XtVaGetValues(psh->shell, XtNwidth,   &wd, XtNheight,   &ht, NULL);  XtVaSetValues(psh->shell, XtNminWidth, wd, XtNminHeight, ht,                            XtNmaxWidth, wd, XtNmaxHeight, ht, NULL);  /* --- override window manager delete --- */  XtOverrideTranslations(psh->shell,    XtParseTranslationTable("<Message>WM_PROTOCOLS: db_close()"));  wm_delete = XInternAtom(XtDisplay(psh->shell),    "WM_DELETE_WINDOW", False);  XSetWMProtocols(XtDisplay(psh->shell), XtWindow(psh->shell),    &wm_delete, 1);             /* override window manager delete */  return 0;                     /* return `ok' */}  /* psh_handle() */

⌨️ 快捷键说明

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