📄 look-gtk.c
字号:
/* look-gtk.c - look 'n feel type: GTK Copyright (C) 1996-2000 Paul Sheer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include <stdio.h>#include <my_string.h>#include <stdlib.h>#include <stdarg.h>#include <X11/Intrinsic.h>#include "lkeysym.h"#include "stringtools.h"#include "app_glob.c"#include "coolwidget.h"#include "coollocal.h"#include "mad.h"extern struct look *look;extern void look_cool_search_replace_dialog (Window parent, int x, int y, char **search_text, char **replace_text, char **arg_order, char *heading, int option);extern CWidget *look_cool_draw_file_list (const char *identifier, Window parent, int x, int y, int width, int height, int line, int column, struct file_entry *directentry, long options);extern CWidget *look_cool_redraw_file_list (const char *identifier, struct file_entry *directentry, int preserve);extern struct file_entry *look_cool_get_file_list_line (CWidget * w, int line);Window find_mapped_window (Window w);extern char *look_cool_get_file_or_dir (Window parent, int x, int y, const char *dir, const char *file, const char *label, int options);extern void look_cool_draw_browser (const char *ident, Window parent, int x, int y, const char *dir, const char *file, const char *label);/* }}} file browser stuff */int find_menu_hotkey (struct menu_item m[], int this, int num);/* outermost bevel */#define BEVEL_MAIN 2/* next-outermost bevel */#define BEVEL_IN 2#define BEVEL_OUT 2/* between items, and between items and next-outermost bevel */#define SPACING 2/* between items rectangle and text */#define RELIEF 3#define S SPACING/* between window border and items */#define O (BEVEL_OUT + SPACING)/* total height of an item *//* size of bar item */#define BAR_HEIGHT 4#define H (FONT_PIX_PER_LINE + RELIEF * 2)#define B BAR_HEIGHTstatic char *look_gtk_get_default_widget_font (void){ return "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*";}static void look_gtk_get_menu_item_extents (int n, int j, struct menu_item m[], int *border, int *relief, int *y1, int *y2){ int i, n_items = 0, n_bars = 0; *border = O; *relief = RELIEF; if (!n || j < 0) { *y1 = O; *y2 = *y1 + H; } else { int not_bar; not_bar = (m[j].text[2] != '\0'); for (i = 0; i < j; i++) if (m[i].text[2]) n_items++; else n_bars++; *y1 = O + n_items * (H + S) + n_bars * (B + S) + (not_bar ? 0 : 2); *y2 = *y1 + (not_bar ? H : (B - 4)); }}unsigned long bevel_background_color = 1;static void look_gtk_menu_draw (Window win, int w, int h, struct menu_item m[], int n, int light){ int i, y1, y2, offset = 0; static int last_light = 0, last_n = 0; static Window last_win = 0; render_bevel (win, 0, 0, w - 1, h - 1, BEVEL_MAIN, 0);#if 0 render_bevel (win, BEVEL_IN, BEVEL_IN, w - 1 - BEVEL_IN, h - 1 - BEVEL_IN, BEVEL_OUT - BEVEL_IN, 1);#endif if (last_win == win && last_n != n) { XClearWindow (CDisplay, win); } else if (last_light >= 0 && last_light < n) { int border, relief; look_gtk_get_menu_item_extents (n, last_light, m, &border, &relief, &y1, &y2); CSetColor (COLOR_FLAT); CRectangle (win, O - 1, y1 - 1, w - O * 2 + 2, y2 - y1 + 2); } last_win = win; last_n = n; CPushFont ("widget", 0); for (i = 0; i < n; i++) { int border, relief; look_gtk_get_menu_item_extents (n, i, m, &border, &relief, &y1, &y2); if (i == light && m[i].text[2]) { offset = 1; bevel_background_color = color_widget (14); render_bevel (win, O - 1, y1 - 1, w - O, y2, 2, 2); bevel_background_color = COLOR_FLAT; } else { if (!(m[i].text[2])) { CSetColor (color_widget (9)); CLine (win, O, y1 - 1, w - O, y1 - 1); CSetColor (color_widget (14)); CLine (win, O, y1, w - O, y1); } offset = 0; } if (m[i].text[2]) { char *u; u = strrchr (m[i].text, '\t'); if (u) *u = 0; CSetColor (COLOR_BLACK); if (m[i].hot_key == '~') m[i].hot_key = find_menu_hotkey (m, i, n); if (i == light) CSetBackgroundColor (color_widget (14)); else CSetBackgroundColor (COLOR_FLAT); drawstring_xy_hotkey (win, RELIEF + O - offset, RELIEF + y1 - offset, m[i].text, m[i].hot_key); if (u) { drawstring_xy (win, RELIEF + O + (w - (O + RELIEF) * 2 - CImageStringWidth (u + 1)) - offset, RELIEF + y1 - offset, u + 1); *u = '\t'; } } } last_light = light; CPopFont ();}static void look_gtk_render_menu_button (CWidget * wdt){ int w = wdt->width, h = wdt->height; int x = 0, y = 0; Window win = wdt->winid; if (wdt->disabled) goto disabled; if (wdt->options & BUTTON_PRESSED || wdt->droppedmenu) { render_bevel (win, x, y, x + w - 1, y + h - 1, 2, 0); } else { disabled: CSetColor (COLOR_FLAT); XDrawRectangle (CDisplay, win, CGC, x, y, w - 1, h - 1); XDrawRectangle (CDisplay, win, CGC, x + 1, y + 1, w - 3, h - 3); } if (!wdt->label) return; if (!(*(wdt->label))) return; CSetColor (COLOR_BLACK); CPushFont ("widget", 0); CSetBackgroundColor (COLOR_FLAT); drawstring_xy_hotkey (win, x + 2 + BUTTON_RELIEF, y + 2 + BUTTON_RELIEF, wdt->label, wdt->hotkey); CPopFont ();}static void look_gtk_render_button (CWidget * wdt){ int w = wdt->width, h = wdt->height; int x = 0, y = 0; XGCValues gcv; Window win = wdt->winid;#define BUTTON_BEVEL 2 if (wdt->pixmap_mask) { gcv.clip_mask = wdt->pixmap_mask; XChangeGC (CDisplay, CGC, GCClipMask, &gcv); } if (wdt->disabled) goto disabled; if (wdt->options & BUTTON_PRESSED) { bevel_background_color = color_widget (10); render_bevel (win, x, y, x + w - 1, y + h - 1, BUTTON_BEVEL, 3); bevel_background_color = COLOR_FLAT; CSetBackgroundColor (color_widget (10)); } else if (wdt->options & BUTTON_HIGHLIGHT) { bevel_background_color = color_widget (14); render_bevel (win, x, y, x + w - 1, y + h - 1, 2, 2); bevel_background_color = COLOR_FLAT; CSetBackgroundColor (color_widget (14)); } else { disabled: render_bevel (win, x, y, x + w - 1, y + h - 1, BUTTON_BEVEL, 2); CSetBackgroundColor (COLOR_FLAT); } if (wdt->label) { if ((*(wdt->label))) { CSetColor (COLOR_BLACK); CPushFont ("widget", 0); drawstring_xy_hotkey (win, x + 2 + BUTTON_RELIEF, y + 2 + BUTTON_RELIEF, wdt->label, wdt->hotkey); CPopFont (); } } if (wdt->pixmap_mask) { gcv.clip_mask = 0; XChangeGC (CDisplay, CGC, GCClipMask, &gcv); }}static void look_gtk_render_bar (CWidget * wdt){ int w = wdt->width, h = wdt->height; Window win = wdt->winid; CSetColor (color_widget (9)); CLine (win, 0, 0, w - 1, 0); CSetColor (color_widget (15)); CLine (win, 0, h - 1, w - 1, h - 1);}void look_gtk_render_sunken_bevel (Window win, int x1, int y1, int x2, int y2, int thick, int sunken){ int i; CSetColor (color_widget (9)); CLine (win, x1, y1, x2, y1); CLine (win, x1, y1 + 1, x1, y2); if (thick > 1) { CSetColor (color_widget (0)); CLine (win, x1 + 1, y1 + 1, x2 - 1, y1 + 1); CLine (win, x1 + 1, y1 + 2, x1 + 1, y2 - 1); } CSetColor (color_widget (15)); CLine (win, x2, y1 + 1, x2, y2); CLine (win, x1 + 1, y2, x2 - 1, y2); if (thick > 1) { CSetColor (bevel_background_color == COLOR_WHITE ? COLOR_FLAT : bevel_background_color); CLine (win, x2 - 1, y1 + 2, x2 - 1, y2 - 1); CLine (win, x1 + 2, y2 - 1, x2 - 2, y2 - 1); } if (thick > 2) { CSetColor (bevel_background_color); for (i = 2; i < thick; i++) { CLine (win, x1 + i, y1 + i, x2 - 1 - i, y1 + i); CLine (win, x1 + i, y1 + i + 1, x1 + i, y2 - 1 - i); CLine (win, x2 - i, y1 + i, x2 - i, y2 - i); CLine (win, x1 + i, y2 - i, x2 - i - 1, y2 - i); } } if ((sunken & 2)) { CSetColor (bevel_background_color); CRectangle (win, x1 + thick, y1 + thick, x2 - x1 - 2 * thick + 1, y2 - y1 - 2 * thick + 1); }}static void look_gtk_render_raised_bevel (Window win, int x1, int y1, int x2, int y2, int thick, int sunken){ int i; if (bevel_background_color == 1) bevel_background_color = COLOR_FLAT; x2--; y2--; CSetColor (color_widget (15)); CLine (win, x1, y1, x1, y2); CLine (win, x1 + 1, y1, x2, y1); if (thick > 1) { CLine (win, x1 + 1, y2, x1 + 1, y2); CLine (win, x2, y1 + 1, x2, y1 + 1); CSetColor (color_widget (9)); CLine (win, x1 + 2, y2, x2 - 1, y2); CLine (win, x2, y1 + 2, x2, y2); } CSetColor (color_widget (0)); CLine (win, x1, y2 + 1, x2, y2 + 1); CLine (win, x2 + 1, y1, x2 + 1, y2 + 1); if (thick > 1) { CSetColor (bevel_background_color); CLine (win, x1 + 1, y1 + 1, x1 + 1, y2 - 1); CLine (win, x1 + 1, y1 + 1, x2 - 1, y1 + 1); } x2++; y2++; if (thick > 2) { for (i = 2; i < thick; i++) { CLine (win, x1 + i, y1 + i, x2 - 1 - i, y1 + i); CLine (win, x1 + i, y1 + i + 1, x1 + i, y2 - 1 - i); CLine (win, x2 - i, y1 + i, x2 - i, y2 - i); CLine (win, x1 + i, y2 - i, x2 - i - 1, y2 - i); } } if ((sunken & 2)) { CSetColor (bevel_background_color); CRectangle (win, x1 + thick, y1 + thick, x2 - x1 - 2 * thick + 1, y2 - y1 - 2 * thick + 1); }}static void look_gtk_draw_hotkey_understroke (Window win, int x, int y, int hotkey){ CLine (win, x, y + 1, x + FONT_PER_CHAR (hotkey) - 1, y + 1);}static void look_gtk_render_text (CWidget * wdt){ Window win = wdt->winid; char text[1024], *p, *q; int hot, y, w = wdt->width, center = 0; CPushFont ("widget", 0); CSetColor (COLOR_FLAT); CRectangle (win, 0, 0, w - 1, wdt->height - 1); CSetColor (COLOR_BLACK); hot = wdt->hotkey; /* a letter that needs underlining */ y = 1; /* bevel */ q = wdt->text; CSetBackgroundColor (COLOR_FLAT); for (;;) { p = strchr (q, '\n'); if (!p) { /* last line */ if (wdt->options & TEXT_CENTRED) center = (wdt->width - (TEXT_RELIEF + 1) * 2 - CImageTextWidth (q, strlen (q))) / 2; drawstring_xy_hotkey (win, TEXT_RELIEF + 1 + center, TEXT_RELIEF + y, q, hot); break; } else { int l; l = min (1023, (unsigned long) p - (unsigned long) q); memcpy (text, q, l); text[l] = 0; if (wdt->options & TEXT_CENTRED) center = (wdt->width - (TEXT_RELIEF + 1) * 2 - CImageTextWidth (q, l)) / 2; drawstring_xy_hotkey (win, TEXT_RELIEF + 1 + center, TEXT_RELIEF + y, text, hot); } y += FONT_PIX_PER_LINE; hot = 0; /* only for first line */ q = p + 1; /* next line */ } CPopFont (); return;}static void look_gtk_render_window (CWidget * wdt){ int w = wdt->width, h = wdt->height;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -