📄 create_panels.c
字号:
Notify_arg arg; Notify_event_type when;{ struct reply_panel_data *ptr; Notify_value val; ptr = (struct reply_panel_data *)LINT_CAST(window_get( client, WIN_CLIENT_DATA)); val = notify_next_event_func(client, event, arg, when); if (!ptr->normalized && event_id(event) == WIN_REPAINT) {/* Textsw_index point; */ /* not used - hala */ textsw_insert_makes_visible(client); ptr->normalized = TRUE; } return (val);}/* * toggle permanent/temporary. */voidmt_replypanel_init(reply_panel) Panel reply_panel;{ struct reply_panel_data *ptr; struct panel_item_data *p; char *s1, *s2; if (reply_panel == NULL) return; ptr = (struct reply_panel_data *)LINT_CAST(panel_get( reply_panel, PANEL_CLIENT_DATA)); /* update deliver menu */ p = (struct panel_item_data *)LINT_CAST(panel_get( ptr->deliver_item, PANEL_CLIENT_DATA)); switch (ptr->behavior) { case mt_Disappear: s1 = "Deliver, Take Down Window"; s2 = "Cancel"; break; case mt_Close: s1 = "Deliver, Close Window"; s2 = "Cancel"; break; case mt_Stay_Up: s1 = "Deliver, Clear Window"; s2 = "Clear"; break; } (void) menu_set(menu_get(p->menu, MENU_NTH_ITEM, 1), MENU_STRING, s1, 0); /* update cancel button image. menu is handled via a genproc */ (void) panel_set(ptr->cancel_item, PANEL_LABEL_IMAGE, (mt_panel_style == mt_3DImages) ? outline_string(s2) : panel_button_image(reply_panel, s2, 8, (Pixfont *) 0), 0); p = (struct panel_item_data *)LINT_CAST(panel_get( ptr->cycle_item, PANEL_CLIENT_DATA));}/* * Create a button in a panel, and a menu behind it. * Strings m1 - m4 specify the menu items * that correspond to the normal, shifted, * ctrled, and ctrl-shifted versions of the * button. *//* ARGSUSED */static Panel_itempanel_create_old_button(panel, label, row, col, notify_proc, m1, m2, m3, m4) Panel panel; char *label; int row, col; Void_proc notify_proc; char *m1, *m2, *m3, *m4;{ Panel_item item; struct panel_item_data *p; item = mt_panel_create_item( panel, panel_button_image(panel, label, 8, (Pixfont *) 0), ATTR_ROW(row) + BUTTON_SPACING, ATTR_COL(col) + 5, notify_proc, m1, m2, m3, m4); p = (struct panel_item_data *)LINT_CAST(panel_get( item, PANEL_CLIENT_DATA)); p->column = col; return (item);}static Panel_itempanel_create_new_button(panel, label, row, col, notify_proc, m1, m2, m3, m4) Panel panel; char *label; int row, col; Void_proc notify_proc; char *m1, *m2, *m3, *m4;{ Panel_item item; struct panel_item_data *p; item = mt_panel_create_item( panel, panel_button_image(panel, label, 7, (Pixfont *) 0), ATTR_ROW(row) + BUTTON_SPACING, ATTR_COL(col) + 5 , notify_proc, m1, m2, m3, m4); p = (struct panel_item_data *)LINT_CAST(panel_get( item, PANEL_CLIENT_DATA)); p->column = col; return (item);}static Panel_itempanel_create_3Dbutton(panel, label, row, col, notify_proc, m1, m2, m3, m4) Panel panel; char *label; int row, col; Void_proc notify_proc; char *m1, *m2, *m3, *m4;{ Panel_item item; struct panel_item_data *p; item = mt_panel_create_item( panel, outline_string(label), ATTR_ROW(row), ATTR_COL(col), notify_proc, m1, m2, m3, m4); p = (struct panel_item_data *)LINT_CAST(panel_get( item, PANEL_CLIENT_DATA)); p->column = col; return (item);}static Panel_itempanel_create_image(panel, image, y, col, notify_proc, m1, m2, m3, m4) Panel panel; Pixrect *image; int y, col; Void_proc notify_proc; char *m1, *m2, *m3, *m4;{ Panel_item item; struct panel_item_data *p; item = mt_panel_create_item( panel, image, y, ATTR_COL(col), notify_proc, m1, m2, m3, m4); p = (struct panel_item_data *)LINT_CAST(panel_get( item, PANEL_CLIENT_DATA)); p->column = col; return (item);}static Panel_itempanel_create_3Dimage(panel, image, x, y, notify_proc, m1, m2, m3, m4) Panel panel; Pixrect *image; int x, y; Void_proc notify_proc; char *m1, *m2, *m3, *m4;{ Panel_item item; item = mt_panel_create_item( panel, outline_image(image), y, x, notify_proc, m1, m2, m3, m4); return (item);}/* * Create a button in panel, and a menu behind it. * Strings m1 - m4 specify the menu items * that correspond to the normal, shifted, * ctrled, and ctrl-shifted versions of the * button. *//* ARGSUSED */static Panel_itemmt_panel_create_item(panel, image, y, x, notify_proc, m1, m2, m3, m4) Panel panel; Pixrect *image; int x, y; Void_proc notify_proc; char *m1, *m2, *m3, *m4;{ Panel_item item; Menu menu; register char **ip; register int i; static int menuval[4] = {0, SHIFTMASK, CTRLMASK, SHIFTMASK | CTRLMASK}; struct panel_item_data *p; p = (struct panel_item_data *)LINT_CAST(calloc(1, sizeof(struct panel_item_data))); item = panel_create_item(panel, PANEL_BUTTON, PANEL_LABEL_IMAGE, image, PANEL_LABEL_X, x, PANEL_LABEL_Y, y, PANEL_NOTIFY_PROC, notify_proc, PANEL_CLIENT_DATA, p, PANEL_EVENT_PROC, mt_panel_event, 0); if (m1 != NULL) { menu = mt_create_menu_for_button(item); for (ip = &m1, i = 0; i < 4 && *ip != NULL; ip++, i++) { if (**ip == '\0') /* empty strings are skipped */ continue; (void) mt_add_menu_item( menu, *ip, notify_proc, menuval[i]); } } return (item);}Menumt_create_menu_for_button(item) Panel_item item;{ Menu menu; menu = menu_create(MENU_CLIENT_DATA, item, MENU_NOTIFY_PROC, menu_return_item, MENU_LEFT_MARGIN, 10, 0); if (item) { struct panel_item_data *p; p = (struct panel_item_data *)LINT_CAST(panel_get( item, PANEL_CLIENT_DATA)); p->menu = menu; } return (menu);}voidmt_add_menu_item(menu, string, notify_proc, mask) Menu menu; char *string; Void_proc notify_proc; int mask;{ struct Menu_value *ptr; ptr = (struct Menu_value *)LINT_CAST(malloc(sizeof(struct Menu_value))); ptr->notify_proc = notify_proc; ptr->mask = mask; (void) menu_set(menu, MENU_STRING_ITEM, string, ptr, 0); /* ptr will be the value returned when this item is selected */}/* VARARGS1 */voidmt_add_menu_items(menu, va_alist) Menu menu; va_dcl{ va_list args; char *s; Void_proc notify_proc; int mask; va_start(args); while ((s = va_arg(args, char *)) != (char *) 0) { notify_proc = va_arg(args, Void_proc); mask = va_arg(args, int); mt_add_menu_item(menu, s, notify_proc, mask); } va_end(args);}static Notify_value mt_cmdpanel_event_proc(client, event, arg, when) Notify_client client; Event *event; Notify_arg arg; Notify_event_type when;{ if (event_action(event) == WIN_RESIZE) { if (client == mt_cmdpanel) { mt_layout_cmdpanel(); (void) panel_paint(mt_cmdpanel, PANEL_CLEAR); } } return (notify_next_event_func(client, event, arg, when));}static Notify_value mt_reply_panel_event_proc(client, event, arg, when) Notify_client client; Event *event; Notify_arg arg; Notify_event_type when;{ if (event_action(event) == WIN_RESIZE) { Frame frame; struct reply_panel_data *ptr; frame = window_get(client, WIN_OWNER); if (frame == mt_frame) ptr = (struct reply_panel_data *)LINT_CAST(panel_get( mt_cmdpanel, PANEL_CLIENT_DATA)); else ptr = (struct reply_panel_data *)LINT_CAST(window_get( frame, WIN_CLIENT_DATA)); mt_layout_reply_panel(ptr->reply_panel); } return (notify_next_event_func(client, event, arg, when));}static voidmt_layout_cmdpanel(){ struct reply_panel_data *ptr; ptr = (struct reply_panel_data *)LINT_CAST(panel_get( mt_cmdpanel, PANEL_CLIENT_DATA)); mt_layout_panel(mt_cmdpanel, (mt_panel_style == mt_New) ? 5 : 0); if (ptr && (window_get(ptr->reply_panel, WIN_OWNER) == mt_frame)) /* there is also a replysw in this frame */ mt_layout_reply_panel(ptr->reply_panel);}static voidmt_layout_reply_panel(panel) Panel panel;{ mt_layout_panel(panel, 5);}static voidmt_layout_panel(panel, offset) Panel panel; int offset;{ Panel_item item; int width, delta, delta_columns; struct panel_item_data *p; width = (int)window_get(window_get(panel, WIN_OWNER), WIN_WIDTH); if (width == 0) /* window not installed yet */ return; delta = width - padding - (TOOL_COLS * charwidth); /* * original layout based on a window of width: padding + * ATTR_COL(TOOL_COLS) */ delta_columns = delta / charwidth; panel_each_item(panel, item) p = (struct panel_item_data *)LINT_CAST(panel_get( item, PANEL_CLIENT_DATA)); if (p->column > 50) (void) panel_set(item, PANEL_LABEL_X, ATTR_COL(p->column + delta_columns) + offset, 0); if (p->width > 0) (void) panel_set(item, PANEL_VALUE_DISPLAY_LENGTH, p->width + delta_columns, 0); panel_end_each}Pixrect *outline_image(old)register Pixrect *old;{#ifdef USE_IMAGES Pixrect *new; int x = old->pr_size.x + 7; int y = old->pr_size.y + 7; int w = x - 1; int h = y - 1; new = mem_create(x, y, 1); pr_rop(new, 2, 2, w, h, PIX_SRC, old, 0, 0); pr_vector(new, 3, 0, w-3, 0, PIX_SRC, 1); /* top */ pr_vector(new, 0, 3, 3, 0, PIX_SRC, 1); /* nw corner */ pr_vector(new, w, 3, w-3, 0, PIX_SRC, 1); /* ne corner */ pr_vector(new, 6, h, w-3, h, PIX_SRC, 1); /* bottom */ pr_vector(new, 0, h-6, 6, h, PIX_SRC, 1); /* sw corner */ pr_vector(new, w-3, h, w, h-3, PIX_SRC, 1); /* se corner */ pr_vector(new, 0, 3, 0, h-6, PIX_SRC, 1); /* left */ pr_vector(new, w, 3, w, h-3, PIX_SRC, 1); /* right */ pr_vector(new, w-3, 3, w-3, h-6, PIX_SRC, 1); /* inside right */ pr_vector(new, 3, h-3, w-6, h-3, PIX_SRC, 1); /* inside bottom */ pr_vector(new, w-3, 3, w-6, 0, PIX_SRC, 1); /* inside ne corner */ pr_vector(new, w-6, h-3, w-3, h-6, PIX_SRC, 1); /* inside se corner */ /* fill in bottom shadow */ for (x=6; x<w-3; x+=2) pr_put(new, x, h-2, 1); for (x=7; x<w-2; x+=2) pr_put(new, x, h-1, 1); pr_put(new, w-5, h-3, 1); pr_put(new, w-4, h-3, 1); pr_put(new, w-3, h-2, 1); pr_put(new, w-3, h-4, 1); /* fill in right shadow */ for (y=3; y<h-2; y+=2) pr_put(new, w-2, y, 1); for (y=4; y<h-2; y+=2) pr_put(new, w-1, y, 1); pr_put(new, w-3, 1, 1); pr_put(new, w-2, 2, 1);/* ifdef notdef * horizontal lines at bottom * pr_vector(new, 3, h-3, w, h-3, PIX_SRC, 1); pr_vector(new, 4, h-2, w-1, h-2, PIX_SRC, 1); pr_vector(new, 5, h-1, w-1, h-1, PIX_SRC, 1); * vertical lines at bottom * pr_vector(new, w-3, 0, w-3, h-4, PIX_SRC, 1); pr_vector(new, w-2, 1, w-2, h-4, PIX_SRC, 1); pr_vector(new, w-1, 2, w-1, h-4, PIX_SRC, 1);endif*/ return(new);#endif}Pixrect *outline_string(s) char *s;{#ifdef USE_IMAGES struct pr_prpos where; struct pr_size size; int x, y, w, h; size = pf_textwidth(strlen(s), mt_3Dfont, s); x = size.x + 24; y = size.y + 18; w = x - 1; h = y - 1; where.pr = mem_create(x, y, 1); where.pos.x = (w - size.x) / 2; where.pos.y = fonthome(mt_3Dfont) + 7; pf_text(where, PIX_SRC, mt_3Dfont, s); pr_vector(where.pr, 3, 0, w - 3, 0, PIX_SRC, 1); /* top */ pr_vector(where.pr, 0, 3, 3, 0, PIX_SRC, 1); /* nw corner */ pr_vector(where.pr, w, 3, w - 3, 0, PIX_SRC, 1); /* ne corner */ pr_vector(where.pr, 6, h, w - 3, h, PIX_SRC, 1); /* bottom */ pr_vector(where.pr, 0, h - 6, 6, h, PIX_SRC, 1); /* sw corner */ pr_vector(where.pr, w - 3, h, w, h - 3, PIX_SRC, 1); /* se corner */ pr_vector(where.pr, 0, 3, 0, h - 6, PIX_SRC, 1); /* left */ pr_vector(where.pr, w, 3, w, h - 3, PIX_SRC, 1); /* right */ pr_vector(where.pr, w - 3, 3, w - 3, h - 6, PIX_SRC, 1); /* inside right */ pr_vector(where.pr, 3, h - 3, w - 6, h - 3, PIX_SRC, 1); /* inside bottom */ pr_vector(where.pr, w - 3, 3, w - 6, 0, PIX_SRC, 1); /* inside ne corner */ pr_vector(where.pr, w - 6, h - 3, w - 3, h - 6, PIX_SRC, 1); /* inside se corner */ /* fill in bottom shadow */ for (x = 6; x < w - 3; x += 2) pr_put(where.pr, x, h - 2, 1); for (x = 7; x < w - 2; x += 2) pr_put(where.pr, x, h - 1, 1); pr_put(where.pr, w - 5, h - 3, 1); pr_put(where.pr, w - 4, h - 3, 1); pr_put(where.pr, w - 3, h - 2, 1); pr_put(where.pr, w - 3, h - 4, 1); /* fill in right shadow */ for (y = 3; y < h - 2; y += 2) pr_put(where.pr, w - 2, y, 1); for (y = 4; y < h - 2; y += 2) pr_put(where.pr, w - 1, y, 1); pr_put(where.pr, w - 3, 1, 1); pr_put(where.pr, w - 2, 2, 1); return (where.pr);#endif}#ifdef USE_IMAGESstaticfonthome(font)Pixfont *font;{ return -(font->pf_char['n'].pc_home.y);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -