📄 dialog.c
字号:
XEvent xevent; CState s; int width, height; char *p = 0; CWidget *w; CPushFont ("editor", 0); width = columns * FONT_MEAN_WIDTH + 1 + 6; height = lines * FONT_PIX_PER_LINE + 1 + 6; CPopFont (); CBackupState (&s); CDisable ("*"); win = CDrawDialog ("_select", in, x, y); CGetHintPos (&x, &y); w = CDrawTextbox ("_textmessbox", win, x, y, width, height, line, 0, text, 0); w->cursor = cursor_line; CGetHintPos (0, &y); CIdent ("_select")->position = WINDOW_UNMOVEABLE | WINDOW_ALWAYS_RAISED; CSetSizeHintPos ("_select"); CMapDialog ("_select"); CFocus (CIdent ("_textmessbox")); do { CNextEvent (&xevent, &cwevent); if (xevent.xany.window == w->winid) { if (!strcmp (cwevent.ident, "_textmessbox") && (cwevent.command == CK_Enter || cwevent.double_click)) { p = CGetTextBoxLine (w, w->cursor); break; } } else if (xevent.xany.type == ButtonPress && cwevent.kind != C_VERTSCROLL_WIDGET && cwevent.kind != C_HORISCROLL_WIDGET && cwevent.kind != C_WINDOW_WIDGET) { CSendEvent (&xevent); /* resend this to get processed, here the widget is disabled */ break; } if (!CIdent ("_select")) break; } while (cwevent.command != CK_Cancel && cwevent.key != XK_KP_Tab && cwevent.key != XK_Tab); CDestroyWidget ("_select"); CRestoreState (&s); return p;}void CFatalErrorDialog (int x, int y, const char *fmt,...){ va_list pa; char *str; Window win; CEvent cwevent; CState s; Window in; va_start (pa, fmt); str = vsprintf_alloc (fmt, pa); va_end (pa); fprintf (stderr, "%s: %s\n", CAppName, str); in = find_mapped_window (0); if (CDisplay) { CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("fatalerror", in, x, y," Fatal Error "); CGetHintPos (&x, &y); CDrawText ("fatalerror.text", win, x, y, "%s", str); CCentre ("fatalerror.text"); CGetHintPos (0, &y); ((*look->draw_cross_cancel_button) ("clickhere", win, -50, y))->position = POSITION_CENTRE; CCentre ("clickhere"); CIdent ("fatalerror")->position = WINDOW_UNMOVEABLE | WINDOW_ALWAYS_RAISED; CSetSizeHintPos ("fatalerror"); CMapDialog ("fatalerror"); CFocus (CIdent ("clickhere")); do { CNextEvent (NULL, &cwevent); if (!CIdent ("fatalerror")) abort (); } while (strcmp (cwevent.ident, "clickhere")); } abort ();}/* returns a raw XK_key sym, or 0 on cancel */XEvent *CRawkeyQuery (Window in, int x, int y, const char *heading, const char *fmt,...){ va_list pa; char *str; XEvent *p = 0; Window win; CEvent cwevent; static XEvent xevent; CState s; va_start (pa, fmt); str = vsprintf_alloc (fmt, pa); va_end (pa); if (!in) { x = MID_X; y = MID_Y; } in = find_mapped_window (in); CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("_rawkeydlg", in, x, y, heading); CGetHintPos (&x, &y); CDrawText ("_rawkeydlg.text", win, x, y, "%s", str); CGetHintPos (&x, 0); free (str); CDrawTextInput ("_rawkeydlg.input", win, x, y, (FONT_MEAN_WIDTH) * 6, AUTO_HEIGHT, 256, ""); CGetHintPos (0, &y); ((*look->draw_cross_cancel_button) ("_rawkeydlg.crosshere", win, -50, y))->position = POSITION_CENTRE; CCentre ("_rawkeydlg.crosshere"); CSetSizeHintPos ("_rawkeydlg"); CMapDialog ("_rawkeydlg"); CFocus (CIdent ("_rawkeydlg.input")); CIdent ("_rawkeydlg")->position = WINDOW_ALWAYS_RAISED;/* handler : */ do { CNextEvent (&xevent, &cwevent); if (!CIdent ("_rawkeydlg")) break; if (cwevent.command == CK_Cancel || !strcmp (cwevent.ident, "_rawkeydlg.crosshere")) break; if (xevent.type == KeyPress) { KeySym k; k = CKeySym (&xevent); if (k && !mod_type_key (k)) p = &xevent; } } while (!p); CDestroyWidget ("_rawkeydlg"); CRestoreState (&s); return p;}/* def is the default string in the textinput widget. Result must be free'd. Returns 0 on cancel. */char *CInputDialog (const char *ident, Window in, int x, int y, int min_width, const char *def, const char *heading, const char *fmt,...){ va_list pa; char *str, *p = 0; int w, h; Window win; CEvent cwevent; CState s; char inp_name[256]; int browse = 0, xf, yf; min_width &= ~INPUT_DIALOG_BROWSE_MASK; browse = min_width & INPUT_DIALOG_BROWSE_MASK; va_start (pa, fmt); str = vsprintf_alloc (fmt, pa); va_end (pa); if (!in) { x = MID_X; y = MID_Y; } xf = x + 20; yf = y + 20; in = find_mapped_window (in); CTextSize (&w, &h, str); w = max (max (w, min_width), 130); CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("_inputdialog", in, x, y, heading); CGetHintPos (&x, &y); CDrawText ("", win, x, y, "%s", str); CGetHintPos (0, &y); free (str); strcpy (inp_name, ident); inp_name[20] = '\0'; strcat (inp_name, ".inpt_dlg"); CDrawTextInput (inp_name, win, x, y, w, AUTO_HEIGHT, 256, def); if (browse) { CGetHintPos (&x, 0); w += (CDrawButton ("_inputdialog.browse", win, x, y, AUTO_SIZE, _ (" Browse... ")))->width + WIDGET_SPACING; } CGetHintPos (0, &y); (*look->draw_tick_ok_button) ("_inputdialog.clickhere", win, (w + 16) / 4 - 22, y); (*look->draw_cross_cancel_button) ("_inputdialog.crosshere", win, 3 * (w + 16) / 4 - 22, y); CSetSizeHintPos ("_inputdialog"); CMapDialog ("_inputdialog"); CFocus (CIdent (inp_name)); CIdent ("_inputdialog")->position = WINDOW_ALWAYS_RAISED;/* handler : */ do { CNextEvent (NULL, &cwevent); if (cwevent.command == CK_Cancel || !strcmp (cwevent.ident, "_inputdialog.crosshere")) goto fin; if (cwevent.command == CK_Enter) break; if (!strcmp (cwevent.ident, "_inputdialog.browse")) { char *f = 0;/* dialog title */ switch (browse) { case INPUT_DIALOG_BROWSE_DIR: f = CGetDirectory (in, xf, yf, current_dir, "", _ (" Browse ")); break; case INPUT_DIALOG_BROWSE_SAVE: f = CGetSaveFile (in, xf, yf, current_dir, "", _ (" Browse ")); break; case INPUT_DIALOG_BROWSE_LOAD: f = CGetLoadFile (in, xf, yf, current_dir, "", _ (" Browse ")); break; } if (f) if (*f) { if (CIdent (inp_name)->text) free (CIdent (inp_name)->text); CIdent (inp_name)->text = f; CIdent (inp_name)->cursor = strlen (f); CExpose (inp_name); } CFocus (CIdent (inp_name)); } if (!CIdent ("_inputdialog")) goto fin; } while (strcmp (cwevent.ident, "_inputdialog.clickhere")); p = (char *) strdup (CIdent (inp_name)->text); fin: CDestroyWidget ("_inputdialog"); CRestoreState (&s); return p;}static char *id[32] ={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};void free_last_query_buttons (void){ int i; for (i = 0; i < 32; i++) if (id[i]) { free (id[i]); id[i] = 0; }}/* returns -1 on widget-destroyed-without-a-button-pressed or cancel (i.e. Esc) */int CQueryDialog (Window in, int x, int y, const char *heading, const char *first,...){ va_list pa; int i, buttons = 0, r = -1; Window win; CEvent cwevent; CState s; char *b[32]; free_last_query_buttons (); va_start (pa, first); while ((b[buttons] = space_string (va_arg (pa, char *)))) buttons++; va_end (pa); if (!buttons) return -1; if (!in) { x = MID_X; y = MID_Y; } in = find_mapped_window (in); CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("_querydialog", in, x, y, heading); CGetHintPos (&x, &y); CDrawText ("_querydialog.text", win, x, y, "%s", first); CGetHintPos (0, &y); for (i = 0; i < buttons; i++) { CDrawButton (id[i] = sprintf_alloc ("_query.%.20s", b[i]), win, x, y, AUTO_WIDTH, AUTO_HEIGHT, b[i]); CGetHintPos (&x, 0); } CSetSizeHintPos ("_querydialog"); CMapDialog ("_querydialog"); CFocus (CIdent (catstrs ("_query.", b[0], 0))); CIdent ("_querydialog")->position = WINDOW_ALWAYS_RAISED; for (; r < 0;) { CNextEvent (NULL, &cwevent); if (!CIdent ("_querydialog")) break; if (!cwevent.handled && cwevent.command == CK_Cancel) break; for (i = 0; i < buttons; i++) { if (!strcmp (cwevent.ident, id[i])) { r = i; break; } } } for (i = 0; i < buttons; i++) free (b[i]); CDestroyWidget ("_querydialog"); CRestoreState (&s); return r;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -