implement caret blink

This commit is contained in:
cinamod 2003-09-15 14:02:23 +00:00
parent 9ee8236440
commit 2344c84ea5
4 changed files with 215 additions and 72 deletions

View File

@ -1,3 +1,9 @@
2003-09-15 Dom Lachowicz <cinamod@hotmail.com>
* src/wimp_style.c: Fix a few more console messages, implement caret blinking
* src/xp_theme.*: Stub out line drawing. Apparently, documented bits arae missing
from MS's implementation. Go figure...
2003-09-14 Raymond Penners <raymond@dotsphinx.com>
* src/wimp_style.c: Fixed console message complaining about

View File

@ -34,8 +34,8 @@
/* Default values, not normally used
*/
static GtkRequisition default_option_indicator_size = { 9, 8 };
static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
static const GtkRequisition default_option_indicator_size = { 9, 8 };
static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
static GtkStyleClass *parent_class;
@ -127,25 +127,25 @@ typedef enum
static gboolean
get_system_font(SystemFontType type, LOGFONT *out_lf)
{
gboolean ok;
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
ok = SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0);
if (ok)
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0))
{
if (type == CAPTION_FONT)
*out_lf = ncm.lfCaptionFont;
else if (type == MENU_FONT)
*out_lf = ncm.lfMenuFont;
else if (type == STATUS_FONT)
*out_lf = ncm.lfStatusFont;
else
*out_lf = ncm.lfMessageFont;
if (type == CAPTION_FONT)
*out_lf = ncm.lfCaptionFont;
else if (type == MENU_FONT)
*out_lf = ncm.lfMenuFont;
else if (type == STATUS_FONT)
*out_lf = ncm.lfStatusFont;
else
*out_lf = ncm.lfMessageFont;
return TRUE;
}
return ok;
return FALSE;
}
static char *
@ -205,6 +205,73 @@ sys_font_to_pango_font (SystemFontType type, char * buf)
return NULL;
}
static void
setup_system_settings (GtkStyle * style)
{
GtkSettings * settings;
int menu_delay, cursor_blink_time;
gboolean win95 = FALSE;
settings = gtk_settings_get_default ();
if (!settings)
return;
cursor_blink_time = GetCaretBlinkTime ();
g_object_set (G_OBJECT (settings), "gtk-cursor-blink",
cursor_blink_time > 0, NULL);
if (cursor_blink_time > 0)
{
g_object_set (G_OBJECT (settings), "gtk-cursor-blink-time",
cursor_blink_time, NULL);
}
g_object_set (G_OBJECT (settings), "gtk-double-clink-time",
GetDoubleClickTime(), NULL);
g_object_set (G_OBJECT (settings), "gtk-dnd-drag-threshold",
GetSystemMetrics (SM_CXDRAG), NULL);
#if 0
/* TODO: there's an ICONMETRICS struct that we should probably use instead */
g_object_set (G_OBJECT (settings), "gtk-toolbar-icon-size",
GTK_ICON_SIZE_SMALL_TOOLBAR, NULL);
g_object_set (G_OBJECT (settings), "gtk-icon-sizes",
"gtk-menu=10,10", NULL);
{
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if (!GetVersionEx ( (OSVERSIONINFO *) &osvi))
win95 = TRUE; /* assume the worst */
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
win95 = TRUE;
}
if (!win95) {
if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0)) {
g_object_set (G_OBJECT (settings), "gtk-menu-bar-popup-delay",
menu_delay, NULL);
g_object_set (G_OBJECT (settings), "gtk-menu-popdown-delay",
menu_delay, NULL);
g_object_set (G_OBJECT (settings), "gtk-menu-popup-delay",
menu_delay, NULL);
}
}
#endif
/*
http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp
*/
}
static void
setup_system_font(GtkStyle *style)
{
@ -372,10 +439,10 @@ setup_system_styles(GtkStyle *style)
TODO: use GetThemeMetric for the border and outside border */
sprintf(buf, "style \"wimp-button\" = \"wimp-default\"\n"
"{fg[NORMAL] = { %d, %d, %d }\n"
"GtkButton::default_border = { 1, 1, 1, 1 }\n"
"GtkButton::default_outside_border = { 0, 0, 0, 0 }\n"
"GtkButton::child_displacement_x = 1\n"
"GtkButton::child_displacement_y = 1\n"
"GtkButton::default-border = { 1, 1, 1, 1 }\n"
"GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
"GtkButton::child-displacement-x = 1\n"
"GtkButton::child-displacement-y = 1\n"
"}widget_class \"*GtkButton*\" style \"wimp-button\"\n",
btn_fore.red,
btn_fore.green,
@ -526,7 +593,7 @@ draw_check(GtkStyle *style,
if (xp_theme_draw(window, shadow == GTK_SHADOW_IN
? XP_THEME_ELEMENT_PRESSED_CHECKBOX
: XP_THEME_ELEMENT_CHECKBOX,
style, x, y, width, height, state))
style, x, y, width, height, state, area))
{
}
else
@ -579,7 +646,7 @@ draw_expander(GtkStyle *style,
if (xp_theme_draw(window, xp_expander, style,
x, y - expander_size / 2,
expander_size, expander_size, state))
expander_size, expander_size, state, area))
{
return;
}
@ -654,7 +721,7 @@ draw_option(GtkStyle *style,
{
if (xp_theme_draw(window,
XP_THEME_ELEMENT_RADIO_BUTTON, style,
x, y, width, height, state))
x, y, width, height, state, area))
{
}
else
@ -825,7 +892,6 @@ reverse_engineer_stepper_box (GtkWidget *range,
*height = box_height;
}
static void
draw_arrow (GtkStyle *style,
GdkWindow *window,
@ -891,7 +957,7 @@ draw_arrow (GtkStyle *style,
xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
break;
}
if (xp_theme_draw(window, xp_arrow, style, box_x, box_y, box_width, box_height, state))
if (xp_theme_draw(window, xp_arrow, style, box_x, box_y, box_width, box_height, state, area))
{
}
else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
@ -916,7 +982,7 @@ draw_arrow (GtkStyle *style,
/* draw the toolbar chevrons - waiting for GTK 2.4 */
if (name && !strcmp (name, "gtk-toolbar-arrow"))
{
if (xp_theme_draw(window, XP_THEME_ELEMENT_CHEVRON, style, x, y, width, height, state))
if (xp_theme_draw(window, XP_THEME_ELEMENT_CHEVRON, style, x, y, width, height, state, area))
return;
}
@ -994,7 +1060,7 @@ draw_box (GtkStyle *style,
if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
{
if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
width, height, state_type))
width, height, state_type, area))
return;
}
else
@ -1002,7 +1068,7 @@ draw_box (GtkStyle *style,
gboolean is_default = !strcmp (detail, "buttondefault");
if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
: XP_THEME_ELEMENT_BUTTON, style, x, y,
width, height, state_type))
width, height, state_type, area))
return;
}
}
@ -1020,7 +1086,7 @@ draw_box (GtkStyle *style,
(! strcmp (detail, "spinbutton_up"))
? XP_THEME_ELEMENT_SPIN_BUTTON_UP
: XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
style, x, y, width, height, state_type))
style, x, y, width, height, state_type, area))
{
return;
}
@ -1035,7 +1101,7 @@ draw_box (GtkStyle *style,
(! GTK_IS_VSCROLLBAR(widget))
? XP_THEME_ELEMENT_SCROLLBAR_V
: XP_THEME_ELEMENT_SCROLLBAR_H,
style, x, y, width, height, state_type))
style, x, y, width, height, state_type, area))
{
return;
}
@ -1048,20 +1114,20 @@ draw_box (GtkStyle *style,
GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
if (xp_theme_draw (window, xp_progress_bar,
style, x, y, width, height, state_type))
style, x, y, width, height, state_type, area))
{
return;
}
}
}
else if (detail && !strcmp (detail, "handlebox_bin")) {
if (xp_theme_draw (window, XP_THEME_ELEMENT_REBAR, style, x, y, width, height, state_type))
if (xp_theme_draw (window, XP_THEME_ELEMENT_REBAR, style, x, y, width, height, state_type, area))
{
return;
}
}
else if (name && !strcmp (name, "gtk-tooltips")) {
if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type))
if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
{
return;
}
@ -1077,7 +1143,7 @@ draw_box (GtkStyle *style,
GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
if (xp_theme_draw (window, xp_progress_bar,
style, x, y, width, height, state_type))
style, x, y, width, height, state_type, area))
{
return;
}
@ -1096,7 +1162,7 @@ draw_box (GtkStyle *style,
? XP_THEME_ELEMENT_TROUGH_V
: XP_THEME_ELEMENT_TROUGH_H,
style,
x, y, width, height, state_type))
x, y, width, height, state_type, area))
{
return;
}
@ -1137,7 +1203,7 @@ draw_box (GtkStyle *style,
else if (detail && strcmp (detail, "optionmenu") == 0)
{
if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
style, x, y, width, height, state_type))
style, x, y, width, height, state_type, area))
{
return;
}
@ -1194,7 +1260,7 @@ draw_tab (GtkStyle *style,
{
if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
style, x-5, widget->allocation.y+1,
width+10, widget->allocation.height-2, state))
width+10, widget->allocation.height-2, state, area))
{
return;
}
@ -1254,7 +1320,7 @@ draw_extension(GtkStyle *style,
gtk_notebook_get_current_page(notebook)==0
? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
: XP_THEME_ELEMENT_TAB_ITEM,
style, x, y, width, height, state_type))
style, x, y, width, height, state_type, area))
{
return;
}
@ -1275,9 +1341,9 @@ draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
{
GtkNotebook *notebook = GTK_NOTEBOOK(widget);
/* FIXME: pos != TOP to be implemented */
/* FIXME: pos != TOP to be implemented */
if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
state_type))
state_type, area))
{
return;
}
@ -1322,7 +1388,7 @@ draw_shadow (GtkStyle *style,
if(detail && ! strcmp(detail, "entry"))
{
if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
x, y, width, height, state_type))
x, y, width, height, state_type, area))
{
return;
}
@ -1342,9 +1408,17 @@ draw_hline (GtkStyle *style,
gint x2,
gint y)
{
/* TODO: GP_LINEHORIZ : LHS_FLAT, LHS_RAISED, LHS_SUNKEN*/
parent_class->draw_hline (style, window, state_type, area, widget,
detail, x1, x2, y);
#if UXTHEME_HAS_LINES
if (xp_theme_draw(window, XP_THEME_ELEMENT_HLINE, style, x1, y, x2,
style->ythickness, state_type, area))
{
}
else
#endif
{
parent_class->draw_hline (style, window, state_type, area, widget,
detail, x1, x2, y);
}
}
static void
@ -1358,9 +1432,17 @@ draw_vline (GtkStyle *style,
gint y2,
gint x)
{
/* TODO: GP_LINEVERT : LVS_FLAT, LVS_RAISED, LVS_SUNKEN */
parent_class->draw_vline (style, window, state_type, area, widget,
detail, y1, y2, x);
#if UXTHEME_HAS_LINES
if (xp_theme_draw(window, XP_THEME_ELEMENT_VLINE, style, x, y1,
style->xthickness, y2, state_type, area))
{
}
else
#endif
{
parent_class->draw_vline (style, window, state_type, area, widget,
detail, y1, y2, x);
}
}
static void
@ -1385,7 +1467,7 @@ draw_handle (GtkStyle *style,
else
hndl = XP_THEME_ELEMENT_GRIPPER_H;
if (xp_theme_draw(window, hndl, style, x, y, width, height, state_type))
if (xp_theme_draw(window, hndl, style, x, y, width, height, state_type, area))
{
return;
}
@ -1407,6 +1489,7 @@ wimp_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
{
setup_system_font (style);
setup_system_styles (style);
setup_system_settings (style);
parent_class->init_from_rc(style, rc_style);
}
@ -1462,4 +1545,3 @@ wimp_style_register_type (GTypeModule *module)
"WimpStyle",
&object_info, 0);
}

View File

@ -42,7 +42,8 @@ static LPCWSTR class_descriptors[] =
L"Progress",
L"Tooltip",
L"Rebar",
L"Toolbar"
L"Toolbar",
L"Globals"
};
static const short element_part_map[]=
@ -83,6 +84,12 @@ static const short element_part_map[]=
RP_GRIPPERVERT,
RP_CHEVRON,
TP_BUTTON
#if UXTHEME_HAS_LINES
,
GP_LINEHORZ,
GP_LINEVERT
#endif
};
static HINSTANCE uxtheme_dll = NULL;
@ -107,8 +114,6 @@ static EnableThemeDialogTextureFunc enable_theme_dialog_texture_func = NULL;
void
xp_theme_init()
{
int i;
if (uxtheme_dll)
return;
@ -127,7 +132,7 @@ xp_theme_exit()
{
int i;
if(! uxtheme_dll)
if(!uxtheme_dll)
return;
for (i=0; i<XP_THEME_CLASS__SIZEOF; i++)
@ -182,6 +187,11 @@ xp_theme_get_handle_by_element(XpThemeElement element)
klazz = XP_THEME_CLASS_TOOLBAR;
break;
case XP_THEME_ELEMENT_HLINE:
case XP_THEME_ELEMENT_VLINE:
klazz = XP_THEME_CLASS_GLOBALS;
break;
case XP_THEME_ELEMENT_PRESSED_CHECKBOX:
case XP_THEME_ELEMENT_CHECKBOX:
case XP_THEME_ELEMENT_BUTTON:
@ -247,7 +257,6 @@ xp_theme_get_handle_by_element(XpThemeElement element)
return ret;
}
static int
xp_theme_map_gtk_state(XpThemeElement element, GtkStateType state)
{
@ -265,9 +274,9 @@ xp_theme_map_gtk_state(XpThemeElement element, GtkStateType state)
ret = 0;
break;
case XP_THEME_ELEMENT_CHEVRON:
switch (state)
{
case XP_THEME_ELEMENT_CHEVRON:
switch (state)
{
case GTK_STATE_PRELIGHT:
ret = CHEVS_HOT;
break;
@ -277,7 +286,8 @@ xp_theme_map_gtk_state(XpThemeElement element, GtkStateType state)
break;
default:
ret = CHEVS_NORMAL;
}
}
break;
case XP_THEME_ELEMENT_TOOLBAR:
ret = 1;
@ -512,6 +522,36 @@ xp_theme_map_gtk_state(XpThemeElement element, GtkStateType state)
ret = 1;
break;
#if UXTHEME_HAS_LINES
case XP_THEME_ELEMENT_HLINE:
switch(state) {
case GTK_STATE_ACTIVE:
ret = LHS_RAISED;
break;
case GTK_STATE_INSENSITIVE:
ret = LHS_SUNKEN;
break;
default:
ret = LHS_FLAT;
}
break;
case XP_THEME_ELEMENT_VLINE:
switch(state) {
case GTK_STATE_ACTIVE:
ret = LVS_RAISED;
break;
case GTK_STATE_INSENSITIVE:
ret = LVS_SUNKEN;
break;
default:
ret = LHS_FLAT;
}
break;
#endif
default:
switch(state)
{
@ -533,10 +573,11 @@ xp_theme_map_gtk_state(XpThemeElement element, GtkStateType state)
gboolean
xp_theme_draw(GdkWindow *win, XpThemeElement element, GtkStyle *style,
int x, int y, int width, int height, GtkStateType state_type)
int x, int y, int width, int height, GtkStateType state_type,
GdkRectangle *area)
{
HTHEME theme;
RECT rect;
RECT rect, clip, *pClip;
int xoff, yoff, state;
HDC dc;
GdkDrawable *drawable;
@ -567,13 +608,27 @@ xp_theme_draw(GdkWindow *win, XpThemeElement element, GtkStyle *style,
rect.right = rect.left + width;
rect.bottom = rect.top + height;
if (area)
{
clip.left = area->x - xoff;
clip.top = area->y - yoff;
clip.right = rect.left + area->width;
clip.bottom = rect.top + area->height;
pClip = &clip;
}
else
{
pClip = NULL;
}
gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
dc = gdk_win32_hdc_get(drawable, style->dark_gc[state_type], 0);
if (!dc)
return FALSE;
part_state = xp_theme_map_gtk_state(element, state_type);
draw_theme_background_func(theme, dc, element_part_map[element], part_state, &rect, 0);
draw_theme_background_func(theme, dc, element_part_map[element], part_state, &rect, pClip);
gdk_win32_hdc_release(drawable, style->dark_gc[state_type], 0);
return TRUE;
@ -582,23 +637,19 @@ xp_theme_draw(GdkWindow *win, XpThemeElement element, GtkStyle *style,
gboolean
xp_theme_is_drawable(XpThemeElement element)
{
gboolean ret = FALSE;
if (uxtheme_dll)
{
ret = xp_theme_get_handle_by_element(element) != NULL;
return (xp_theme_get_handle_by_element(element) != NULL);
}
return ret;
return FALSE;
}
gboolean
xp_theme_get_system_font(LOGFONT *lf)
xp_theme_get_system_font(int fontId, LOGFONT *lf)
{
gboolean ret = FALSE;
if (get_theme_sys_font_func != NULL)
{
HRESULT hr = (*get_theme_sys_font_func)(NULL, TMT_MSGBOXFONT, lf);
ret = (hr == S_OK);
return ((*get_theme_sys_font_func)(NULL, fontId, lf) == S_OK);
}
return ret;
return FALSE;
}

View File

@ -38,6 +38,7 @@ typedef enum
XP_THEME_CLASS_TOOLTIP,
XP_THEME_CLASS_REBAR,
XP_THEME_CLASS_TOOLBAR,
XP_THEME_CLASS_GLOBALS,
XP_THEME_CLASS__SIZEOF
} XpThemeClass;
@ -79,14 +80,17 @@ typedef enum
XP_THEME_ELEMENT_GRIPPER_V,
XP_THEME_ELEMENT_CHEVRON,
XP_THEME_ELEMENT_TOOLBAR,
XP_THEME_ELEMENT_HLINE,
XP_THEME_ELEMENT_VLINE,
XP_THEME_ELEMENT__SIZEOF
} XpThemeElement;
void xp_theme_init();
void xp_theme_exit();
gboolean xp_theme_draw(GdkWindow *win, XpThemeElement element, GtkStyle *style,
int x, int y, int width, int height, GtkStateType state_type);
int x, int y, int width, int height, GtkStateType state_type,
GdkRectangle *area);
gboolean xp_theme_is_drawable(XpThemeElement element);
gboolean xp_theme_get_system_font(LOGFONT *lf);
gboolean xp_theme_get_system_font(int fontId, LOGFONT *lf);
#endif /* XP_THEME_H */