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

📄 dialog.c

📁 数据挖掘中的bridgit算法的例子。 非常经典
💻 C
📖 第 1 页 / 共 3 页
字号:
  Text Display Function----------------------------------------------------------------------*/int db_text (Widget parent, XtCallbackProc callback,             const char *title, int src, const char *text){                               /* --- display a text */  static Widget txtbox = NULL;  /* shell widget of text display box */  Widget   shell = NULL, form;  /* widgets for shell and form */  Widget   info, button;        /* widgets for text and button */  Arg      args[16];            /* widget argument list */  int      n;                   /* argument counter */  Position x, y;                /* position of dialog box */  Atom     wm_delwin;           /* delete window atom of window mgr. */  if (!txtbox) {                /* if widget is not created */    shell = XtCreatePopupShell("textDlg", 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; }    n = 0;                      /* build argument list */    XtSetArg(args[n], XtNborderWidth,  1);             n++;    XtSetArg(args[n], XtNdisplayCaret, False);         n++;    XtSetArg(args[n], XtNwidth,        TXT_WD);        n++;    XtSetArg(args[n], XtNheight,       TXT_HT);        n++;    XtSetArg(args[n], XtNleft,         XtChainLeft);   n++;    XtSetArg(args[n], XtNtop,          XtChainTop);    n++;    XtSetArg(args[n], XtNright,        XtChainRight);  n++;    XtSetArg(args[n], XtNbottom,       XtChainBottom); n++;    XtSetArg(args[n], XtNscrollHorizontal,                      XawtextScrollWhenNeeded);        n++;    XtSetArg(args[n], XtNscrollVertical,                      XawtextScrollAlways);            n++;    info = XtCreateManagedWidget("info", asciiTextWidgetClass,             form, args, n);    /* create text widget */    if (!info) { XtDestroyWidget(shell); return -1; }    n = 0;                      /* build argument list */    XtSetArg(args[n], XtNfromVert,     info);          n++;    XtSetArg(args[n], XtNwidth,        TXT_WD);        n++;    XtSetArg(args[n], XtNleft,         XtChainLeft);   n++;    XtSetArg(args[n], XtNtop,          XtChainBottom); n++;    XtSetArg(args[n], XtNright,        XtChainRight);  n++;    XtSetArg(args[n], XtNbottom,       XtChainBottom); n++;    button = XtCreateManagedWidget("dismiss", commandWidgetClass,               form, args, n);  /* create a `dismiss' button */    if (!button) { XtDestroyWidget(shell); return -1; }    XtInstallAllAccelerators(form, form);    txtbox = shell;             /* install accelerators and */  }                             /* note created dialog box widget */  if (src == TXT_FILE) XtSetArg(args[0], XtNtype, XawAsciiFile);  else                 XtSetArg(args[0], XtNtype, XawAsciiString);  XtSetArg(args[1], XtNstring, text);  info = XtNameToWidget(txtbox, "*info");  XtSetValues(info, args, 2);   /* set the text source */  button = XtNameToWidget(txtbox, "*dismiss");  XtRemoveAllCallbacks(button, XtNcallback);  XtAddCallback(button, XtNcallback, callback, NULL);  XtVaGetValues(parent, XtNx, &x, XtNy, &y, NULL);  XtVaSetValues(txtbox, XtNx,  x, XtNy,  y, NULL);  if (title) XtVaSetValues(txtbox, XtNtitle, title, NULL);  XtPopup(txtbox, XtGrabExclusive);  if (shell) {                  /* show and prepare dialog box */    XtVaSetValues(shell, XtNminWidth,  TXT_MINWD,                         XtNminHeight, TXT_MINHT, 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_text() *//*----------------------------------------------------------------------  Callback Functions----------------------------------------------------------------------*/static void cb_ok (Widget w, XtPointer client, XtPointer call){                               /* --- callback for ok button */  XtPopdown(XtParent(XtParent(w)));  /* close dialog box */  ((XtCallbackProc)client)(w, (void*)1, NULL);}  /* cb_ok() *//*--------------------------------------------------------------------*/static void cb_cancel (Widget w, XtPointer client, XtPointer call){                               /* --- callback for cancel button */  XtPopdown(XtParent(XtParent(w)));  /* close dialog box */  ((XtCallbackProc)client)(w, (void*)0, NULL);}  /* cb_cancel() *//*--------------------------------------------------------------------*/static void cb_menu (Widget w, XtPointer client, XtPointer call){                               /* --- callback for menu selection */  String text;                  /* text of menu entry */  XtVaGetValues(w, XtNlabel, &text, NULL);  XtVaSetValues(XtParent(XtParent(w)), XtNlabel, text, NULL);}  /* cb_menu() */              /* set text of selected menu item *//*----------------------------------------------------------------------  Property Sheet Functions----------------------------------------------------------------------*/PSHEET* psh_create (const char *name, Widget parent, int cabutton){                               /* --- create a property sheet */  PSHEET *psh;                  /* created property sheet */  Arg    args[1];               /* widget argument list */  psh = (PSHEET*)malloc(sizeof(PSHEET));  if (!psh) return NULL;        /* allocate memory and */  psh->parent   = parent;       /* initialize fields */  psh->itemvsz  = psh->itemcnt  = 0;  psh->items    = NULL;  psh->currline = psh->prevline = psh->previtem = NULL;  psh->shell    = XtCreatePopupShell(name, transientShellWidgetClass,    parent, NULL, 0);           /* create a dialog box shell */  if (!psh->shell) { psh_delete(psh); return NULL; }  XtSetArg(args[0], XtNborderWidth, 0);  psh->form = XtCreateManagedWidget("form", formWidgetClass,    psh->shell, args, 1);       /* create a dialog box form */  if (!psh->form) { psh_delete(psh); return NULL; }  psh->ok = XtCreateManagedWidget("ok", commandWidgetClass,    psh->form, args, 0);        /* create 'ok' button */  if (!psh->ok) { psh_delete(psh); return NULL; }  if (!cabutton) {              /* if no cancel button requested, */    psh->ca = NULL; return psh; }           /* abort the function */  XtSetArg(args[0], XtNfromHoriz, psh->ok);  psh->ca = XtCreateManagedWidget("cancel", commandWidgetClass,    psh->form, args, 1);        /* create 'cancel' button */  if (!psh->ca) { psh_delete(psh); return NULL; }  return psh;                   /* return created property sheet */}  /* psh_create() *//*--------------------------------------------------------------------*/void psh_delete (PSHEET *psh){                               /* --- delete a property sheet */  if (psh->shell) XtDestroyWidget(psh->shell);  if (psh->items) free(psh->items);  /* destroy widgets and */  free(psh);                         /* delete property sheet */}  /* psh_delete() *//*--------------------------------------------------------------------*/int psh_addline (PSHEET *psh, const char *name){                               /* --- add a line to a prop. sheet */  int     vsz;                  /* size of item vector */  PSHITEM *tmp;                 /* temporary buffer */  Arg     args[4];              /* widget argument list */  int     n;                    /* argument counter */  Widget  label = NULL;         /* widget for line label */  vsz = psh->itemvsz;           /* get the label vector size */  if (psh->itemcnt >= vsz) {    /* if the label vector is full, */    vsz += BLKSIZE;             /* enlarge the item vector */    tmp = (PSHITEM*)realloc(psh->items, vsz *sizeof(PSHITEM));    if (!tmp) return -1;        /* allocate (new) item vector */    psh->items = tmp; psh->itemvsz = vsz;  }                             /* set (new) item vector and its size */  if (name) {                   /* if label name is given */    n = 0;                      /* build argument list */    XtSetArg(args[n], XtNborderWidth, 0);             n++;    XtSetArg(args[n], XtNjustify,     XtJustifyLeft); n++;    XtSetArg(args[n], XtNfromVert,    psh->currline); n++;    label = XtCreateManagedWidget(name, labelWidgetClass,      psh->form, args, n);      /* create a label widget */    if (!label) return -1;  }                             /* note label widget */  tmp = psh->items +psh->itemcnt++;  tmp->widget = label; tmp->type = PSH_LINE;  psh->prevline = psh->currline;  psh->currline = psh->previtem = label;  return 0;                     /* return 'ok' */}  /* psh_addline() *//*--------------------------------------------------------------------*/int psh_additem (PSHEET *psh, const char *name, int type, int width){                               /* --- add an item to a prop. sheet */  XtTranslations tl;            /* translations for text widgets */  int         vsz;              /* size of item vector */  PSHITEM     *tmp;             /* temporary buffer */  Arg         args[6];          /* widget argument list */  int         n;                /* argument counter */  WidgetClass class;            /* class of created item */  Widget      item;             /* widget for created item */  Widget      pane;             /* widget for menu pane */  String      s;                /* label of toggle gadget */  vsz = psh->itemvsz;           /* get the label vector size */  if (psh->itemcnt >= vsz) {    /* if the label vector is full, */    vsz += BLKSIZE;             /* enlarge the item vector */    tmp = (PSHITEM*)realloc(psh->items, vsz *sizeof(PSHITEM));    if (!tmp) return -1;        /* allocate (new) item vector */    psh->items = tmp; psh->itemvsz = vsz;  }                             /* set (new) item vector and its size */  n = 0;                        /* build argument list */  XtSetArg(args[n], XtNfromHoriz, psh->previtem); n++;  XtSetArg(args[n], XtNfromVert,  psh->prevline); n++;  switch (type) {               /* evaluate item type */    case PSH_LABEL  :           /* label */      XtSetArg(args[n], XtNborderWidth,  0);             n++;      XtSetArg(args[n], XtNjustify,      XtJustifyLeft); n++;      class = labelWidgetClass;      break;    case PSH_COMMAND:           /* command button */      XtSetArg(args[n], XtNborderWidth,  1);             n++;      class = commandWidgetClass;    break;    case PSH_TEXT   :           /* non-editable text field */      XtSetArg(args[n], XtNborderWidth,  1);             n++;      XtSetArg(args[n], XtNeditType,     XawtextRead);   n++;      XtSetArg(args[n], XtNdisplayCaret, False);         n++;      XtSetArg(args[n], XtNcursor,       XC_X_cursor);   n++;      class = asciiTextWidgetClass;  break;    case PSH_EDIT   :           /* editable text field */      XtSetArg(args[n], XtNborderWidth,  1);             n++;      XtSetArg(args[n], XtNeditType,     XawtextEdit);   n++;      class = asciiTextWidgetClass;  break;    case PSH_TOGGLE :           /* toggle button (checkbox) */      XtSetArg(args[n], XtNborderWidth,  1);             n++;      class = toggleWidgetClass;     break;    case PSH_RADIO  :           /* radio button */      XtSetArg(args[n], XtNborderWidth,  1);             n++;      class = toggleWidgetClass;     break;    case PSH_MENU   :           /* menu button */      XtSetArg(args[n], XtNborderWidth,  1);             n++;      XtSetArg(args[n], XtNmenuName,     name);          n++;      class = menuButtonWidgetClass; break;    default        :            /* an unknown item type */      return -1;                /* abort function */  }  item = XtCreateManagedWidget(name, class, psh->form, args, n);  if (!item) return -1;         /* create a widget */  if (width > 0)                /* if width given, set it */    XtVaSetValues(item, XtNwidth, width, NULL);  if      (type == PSH_MENU) {  /* if the object is a menu */    pane = XtCreatePopupShell(name, simpleMenuWidgetClass,             item, NULL, 0);    /* create a menu pane */    if (!pane) { XtDestroyWidget(item); return -1; } }  else if (type == PSH_TOGGLE){ /* if the object is a checkbox */    if (width <= 0) {           /* if no width given */      XtVaGetValues(item, XtNlabel, &s, NULL);      if (*s == '\0') XtVaSetValues(item, XtNwidth, 10, NULL);    } }                         /* set minimal width of toggle */  else if (type == PSH_EDIT) {  /* if the object is a text gadget */    tl = XtParseTranslationTable(           "<Key>Home  : beginning-of-line()\n"           "<Key>End   : end-of-line()\n");    XtAugmentTranslations(item, tl);    tl = XtParseTranslationTable(           "<Key>Tab   : db_next()\n"           "<Key>Return: db_close(ok)\n"           "!Alt<Key>o : db_close(ok)\n"

⌨️ 快捷键说明

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