mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
Cleanup of notebook tab code
svn path=/trunk/; revision=17623
This commit is contained in:
parent
13cc75654c
commit
954746fa05
@ -1,3 +1,8 @@
|
||||
2007-04-23 Cody Russell <bratsche@gnome.org>
|
||||
* modules/engines/ms-windows/msw_style.c: Fixed one-pixel drawing error on
|
||||
left-most tab when notebooks are top-oriented. Also general cleanup of
|
||||
notebook tab related code. (Lieven van der Heide, Cody Russell)
|
||||
|
||||
2007-04-23 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* modules/printbackends/cups/gtkprintbackendcups.c: Reduce
|
||||
|
@ -2245,7 +2245,7 @@ draw_tab (GtkStyle * style,
|
||||
(no system API for this, but DrawEdge can draw all the parts of a tab) */
|
||||
static void DrawTab(HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
|
||||
gboolean aDrawLeft, gboolean aDrawRight)
|
||||
{
|
||||
{
|
||||
gint32 leftFlag, topFlag, rightFlag, lightFlag, shadeFlag;
|
||||
RECT topRect, sideRect, bottomRect, lightRect, shadeRect;
|
||||
gint32 selectedOffset, lOffset, rOffset;
|
||||
@ -2255,7 +2255,8 @@ static void DrawTab(HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
|
||||
rOffset = aDrawRight ? 2 : 0;
|
||||
|
||||
/* Get info for tab orientation/position (Left, Top, Right, Bottom) */
|
||||
switch (aPosition) {
|
||||
switch (aPosition)
|
||||
{
|
||||
case BF_LEFT:
|
||||
leftFlag = BF_TOP; topFlag = BF_LEFT;
|
||||
rightFlag = BF_BOTTOM;
|
||||
@ -2268,6 +2269,7 @@ static void DrawTab(HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
|
||||
SetRect(&lightRect, R.left, R.top, R.left+3, R.top+3);
|
||||
SetRect(&shadeRect, R.left+1, R.bottom-2, R.left+2, R.bottom-1);
|
||||
break;
|
||||
|
||||
case BF_TOP:
|
||||
leftFlag = BF_LEFT; topFlag = BF_TOP;
|
||||
rightFlag = BF_RIGHT;
|
||||
@ -2292,6 +2294,7 @@ static void DrawTab(HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
|
||||
SetRect(&lightRect, R.right-3, R.top, R.right-1, R.top+2);
|
||||
SetRect(&shadeRect, R.right-2, R.bottom-3, R.right, R.bottom-1);
|
||||
break;
|
||||
|
||||
case BF_BOTTOM:
|
||||
leftFlag = BF_LEFT; topFlag = BF_BOTTOM;
|
||||
rightFlag = BF_RIGHT;
|
||||
@ -2304,6 +2307,7 @@ static void DrawTab(HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
|
||||
SetRect(&lightRect, R.left, R.bottom-3, R.left+2, R.bottom-1);
|
||||
SetRect(&shadeRect, R.right-2, R.bottom-3, R.right, R.bottom-1);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_return_if_reached();
|
||||
}
|
||||
@ -2331,200 +2335,290 @@ static void DrawTab(HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
|
||||
|
||||
if (aDrawRight)
|
||||
DrawEdge(hdc, &shadeRect, EDGE_RAISED, BF_SOFT | shadeFlag);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_extension (GtkStyle * style,
|
||||
GdkWindow * window,
|
||||
static gboolean
|
||||
draw_themed_tab_button (GtkStyle *style,
|
||||
GdkWindow *window,
|
||||
GtkStateType state_type,
|
||||
GtkShadowType shadow_type,
|
||||
GdkRectangle * area,
|
||||
GtkWidget * widget,
|
||||
const gchar * detail,
|
||||
gint x,
|
||||
gint y, gint width, gint height, GtkPositionType gap_side)
|
||||
GtkNotebook *notebook,
|
||||
gint x, gint y,
|
||||
gint width, gint height,
|
||||
gint gap_side)
|
||||
{
|
||||
if (widget && GTK_IS_NOTEBOOK (widget) && detail && !strcmp (detail, "tab"))
|
||||
{
|
||||
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
|
||||
GdkPixmap *pixmap = NULL;
|
||||
GdkDrawable *target = NULL;
|
||||
gint x2 = 0, y2 = 0, w2 = width, h2 = height;
|
||||
int tab_part = XP_THEME_ELEMENT_TAB_ITEM;
|
||||
int real_gap_side = gtk_notebook_get_tab_pos (notebook);
|
||||
int border_width = gtk_container_get_border_width (GTK_CONTAINER (notebook));
|
||||
gint border_width = gtk_container_get_border_width (GTK_CONTAINER (notebook));
|
||||
GtkWidget *widget = GTK_WIDGET (notebook);
|
||||
GdkRectangle draw_rect, clip_rect;
|
||||
GdkPixbufRotation rotation = GDK_PIXBUF_ROTATE_NONE;
|
||||
|
||||
/* why this differs from the above gap_side, i have no idea... */
|
||||
if (real_gap_side == GTK_POS_LEFT)
|
||||
if (gap_side == GTK_POS_TOP)
|
||||
{
|
||||
/* Create "rotated" pixmap.. swap width and height */
|
||||
pixmap = gdk_pixmap_new (window, height, width, -1);
|
||||
target = pixmap;
|
||||
x2 = 0;
|
||||
y2 = 0;
|
||||
w2 = height;
|
||||
h2 = width - (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_hborder);
|
||||
int widget_right;
|
||||
|
||||
/* If we are currently rendering the bottom-most tab, and if that tab is the selected tab... */
|
||||
if (widget->allocation.y + widget->allocation.height - border_width == y + height &&
|
||||
state_type == GTK_STATE_NORMAL)
|
||||
{
|
||||
w2--;
|
||||
}
|
||||
}
|
||||
else if (real_gap_side == GTK_POS_RIGHT)
|
||||
{
|
||||
/* Create "rotated" pixmap.. swap width and height */
|
||||
x2 = 0;
|
||||
y2 = 0;
|
||||
w2 = height;
|
||||
h2 = width - (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_hborder);
|
||||
pixmap = gdk_pixmap_new (window, w2, h2, -1);
|
||||
target = pixmap;
|
||||
|
||||
/* If we are currently rendering the bottom-most tab, and if that tab is the selected tab... */
|
||||
if (widget->allocation.y + widget->allocation.height - border_width == y + height &&
|
||||
state_type == GTK_STATE_NORMAL)
|
||||
{
|
||||
w2--;
|
||||
}
|
||||
}
|
||||
else if (real_gap_side == GTK_POS_TOP)
|
||||
{
|
||||
target = window;
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
w2 = width;
|
||||
if (state_type == GTK_STATE_NORMAL)
|
||||
h2 = height;
|
||||
{
|
||||
draw_rect.x = x;
|
||||
draw_rect.y = y;
|
||||
draw_rect.width = width + 2;
|
||||
draw_rect.height = height;
|
||||
|
||||
clip_rect = draw_rect;
|
||||
clip_rect.height--;
|
||||
}
|
||||
else
|
||||
h2 = height - notebook->tab_vborder;
|
||||
{
|
||||
draw_rect.x = x + 2;
|
||||
draw_rect.y = y;
|
||||
draw_rect.width = width - 2;
|
||||
draw_rect.height = height - 2;
|
||||
clip_rect = draw_rect;
|
||||
}
|
||||
|
||||
/* If we are currently drawing the right-most tab, and if that tab is the selected tab... */
|
||||
if (widget->allocation.x + widget->allocation.width - border_width == x + width &&
|
||||
state_type == GTK_STATE_NORMAL)
|
||||
widget_right = widget->allocation.x + widget->allocation.width - border_width - 2;
|
||||
if (draw_rect.x + draw_rect.width >= widget_right)
|
||||
{
|
||||
x2--;
|
||||
draw_rect.width = clip_rect.width = widget_right - draw_rect.x;
|
||||
}
|
||||
}
|
||||
else if (real_gap_side == GTK_POS_BOTTOM)
|
||||
if (gap_side == GTK_POS_BOTTOM)
|
||||
{
|
||||
x2 = 0;
|
||||
y2 = 0;
|
||||
w2 = width;
|
||||
h2 = height - (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_vborder * 2);
|
||||
pixmap = gdk_pixmap_new (window, w2, h2, -1);
|
||||
target = pixmap;
|
||||
int widget_right;
|
||||
|
||||
if (state_type == GTK_STATE_NORMAL)
|
||||
{
|
||||
draw_rect.x = x;
|
||||
draw_rect.y = y;
|
||||
draw_rect.width = width + 2;
|
||||
draw_rect.height = height;
|
||||
|
||||
clip_rect = draw_rect;
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_rect.x = x + 2;
|
||||
draw_rect.y = y + 2;
|
||||
draw_rect.width = width - 2;
|
||||
draw_rect.height = height - 2;
|
||||
clip_rect = draw_rect;
|
||||
}
|
||||
|
||||
if (xp_theme_draw (target, tab_part, style, x2, y2, w2, h2, state_type, NULL /*area*/))
|
||||
/* If we are currently drawing the right-most tab, and if that tab is the selected tab... */
|
||||
widget_right = widget->allocation.x + widget->allocation.width - border_width - 2;
|
||||
if (draw_rect.x + draw_rect.width >= widget_right)
|
||||
{
|
||||
GdkPixbufRotation rotation = GDK_PIXBUF_ROTATE_NONE;
|
||||
if (real_gap_side == GTK_POS_BOTTOM)
|
||||
draw_rect.width = clip_rect.width = widget_right - draw_rect.x;
|
||||
}
|
||||
|
||||
rotation = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
|
||||
else if (real_gap_side == GTK_POS_LEFT)
|
||||
rotation = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
|
||||
else if (real_gap_side == GTK_POS_RIGHT)
|
||||
rotation = GDK_PIXBUF_ROTATE_CLOCKWISE;
|
||||
|
||||
if (rotation != GDK_PIXBUF_ROTATE_NONE)
|
||||
}
|
||||
else if (gap_side == GTK_POS_LEFT)
|
||||
{
|
||||
GdkPixbuf * pixbuf, * rotated;
|
||||
int widget_bottom;
|
||||
|
||||
pixbuf = gdk_pixbuf_get_from_drawable (NULL, target, NULL, x2, y2, 0, 0, w2, h2);
|
||||
if (state_type == GTK_STATE_NORMAL)
|
||||
{
|
||||
draw_rect.x = x;
|
||||
draw_rect.y = y;
|
||||
draw_rect.width = width;
|
||||
draw_rect.height = height + 2;
|
||||
|
||||
clip_rect = draw_rect;
|
||||
clip_rect.width--;
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_rect.x = x;
|
||||
draw_rect.y = y + 2;
|
||||
draw_rect.width = width - 2;
|
||||
draw_rect.height = height - 2;
|
||||
clip_rect = draw_rect;
|
||||
}
|
||||
|
||||
/* If we are currently drawing the bottom-most tab, and if that tab is the selected tab... */
|
||||
widget_bottom = widget->allocation.x + widget->allocation.height - border_width - 2;
|
||||
if (draw_rect.y + draw_rect.height >= widget_bottom)
|
||||
{
|
||||
draw_rect.height = clip_rect.height = widget_bottom - draw_rect.y;
|
||||
}
|
||||
|
||||
rotation = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
|
||||
}
|
||||
else if (gap_side == GTK_POS_RIGHT)
|
||||
{
|
||||
int widget_bottom;
|
||||
|
||||
if (state_type == GTK_STATE_NORMAL)
|
||||
{
|
||||
draw_rect.x = x + 1;
|
||||
draw_rect.y = y;
|
||||
draw_rect.width = width;
|
||||
draw_rect.height = height + 2;
|
||||
|
||||
clip_rect = draw_rect;
|
||||
clip_rect.width--;
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_rect.x = x + 2;
|
||||
draw_rect.y = y + 2;
|
||||
draw_rect.width = width - 2;
|
||||
draw_rect.height = height - 2;
|
||||
clip_rect = draw_rect;
|
||||
}
|
||||
|
||||
/* If we are currently drawing the bottom-most tab, and if that tab is the selected tab... */
|
||||
widget_bottom = widget->allocation.x + widget->allocation.height - border_width - 2;
|
||||
if (draw_rect.y + draw_rect.height >= widget_bottom)
|
||||
{
|
||||
draw_rect.height = clip_rect.height = widget_bottom - draw_rect.y;
|
||||
}
|
||||
|
||||
rotation = GDK_PIXBUF_ROTATE_CLOCKWISE;
|
||||
}
|
||||
|
||||
if (gap_side == GTK_POS_TOP)
|
||||
{
|
||||
if (!xp_theme_draw (window, XP_THEME_ELEMENT_TAB_ITEM, style,
|
||||
draw_rect.x, draw_rect.y,
|
||||
draw_rect.width,draw_rect.height,
|
||||
state_type, &clip_rect))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkPixbuf *rotated;
|
||||
|
||||
if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT)
|
||||
{
|
||||
pixmap = gdk_pixmap_new (window, clip_rect.height, clip_rect.width, -1);
|
||||
if (!xp_theme_draw (pixmap, XP_THEME_ELEMENT_TAB_ITEM, style,
|
||||
draw_rect.y - clip_rect.y, draw_rect.x - clip_rect.x,
|
||||
draw_rect.height, draw_rect.width, state_type, 0))
|
||||
{
|
||||
g_object_unref (pixmap);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
|
||||
clip_rect.height, clip_rect.width);
|
||||
g_object_unref (pixmap);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixmap = gdk_pixmap_new (window, clip_rect.width, clip_rect.height, -1);
|
||||
if (!xp_theme_draw (pixmap, XP_THEME_ELEMENT_TAB_ITEM, style,
|
||||
draw_rect.x - clip_rect.x, draw_rect.y - clip_rect.y,
|
||||
draw_rect.width, draw_rect.height, state_type, 0))
|
||||
{
|
||||
g_object_unref (pixmap);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
|
||||
clip_rect.width, clip_rect.height);
|
||||
g_object_unref (pixmap);
|
||||
}
|
||||
|
||||
rotated = gdk_pixbuf_rotate_simple (pixbuf, rotation);
|
||||
g_object_unref (pixbuf);
|
||||
pixbuf = rotated;
|
||||
|
||||
if (real_gap_side == GTK_POS_RIGHT)
|
||||
{
|
||||
x2 = x + (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_hborder);
|
||||
y2 = y;
|
||||
w2 = width - (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_hborder);
|
||||
h2 = height;
|
||||
|
||||
if (widget->allocation.y + widget->allocation.height - border_width == y + height &&
|
||||
state_type == GTK_STATE_NORMAL)
|
||||
{
|
||||
h2--;
|
||||
}
|
||||
}
|
||||
else if (real_gap_side == GTK_POS_LEFT)
|
||||
{
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
w2 = width - (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_hborder);
|
||||
h2 = height;
|
||||
|
||||
if (widget->allocation.y + widget->allocation.height - border_width == y + height &&
|
||||
state_type == GTK_STATE_NORMAL)
|
||||
{
|
||||
h2--;
|
||||
}
|
||||
}
|
||||
else if (real_gap_side == GTK_POS_BOTTOM)
|
||||
{
|
||||
x2 = x;
|
||||
y2 = y + (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_vborder);
|
||||
w2 = width;
|
||||
h2 = height - (state_type == GTK_STATE_NORMAL ? 0 : notebook->tab_vborder * 2);
|
||||
/* If we are currently drawing the right-most tab (any state)... */
|
||||
if (widget->allocation.x + widget->allocation.width - border_width == x + width)
|
||||
{
|
||||
x2--;
|
||||
w2--;
|
||||
}
|
||||
gdk_draw_pixbuf (window, NULL, pixbuf, 0, 0, clip_rect.x, clip_rect.y,
|
||||
clip_rect.width, clip_rect.height, GDK_RGB_DITHER_NONE, 0, 0);
|
||||
g_object_unref (pixbuf);
|
||||
}
|
||||
|
||||
gdk_draw_pixbuf (window, NULL, pixbuf, 0, 0, x2, y2, w2, h2, GDK_RGB_DITHER_NONE, 0, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_object_unref (G_OBJECT (pixbuf));
|
||||
|
||||
if (real_gap_side == GTK_POS_LEFT || real_gap_side == GTK_POS_RIGHT || real_gap_side == GTK_POS_BOTTOM)
|
||||
static gboolean
|
||||
draw_tab_button (GtkStyle *style,
|
||||
GdkWindow *window,
|
||||
GtkStateType state_type,
|
||||
GtkShadowType shadow_type,
|
||||
GdkRectangle *area,
|
||||
GtkWidget *widget,
|
||||
const gchar *detail,
|
||||
gint x, gint y,
|
||||
gint width, gint height,
|
||||
gint gap_side)
|
||||
{
|
||||
if (gap_side == GTK_POS_TOP || gap_side == GTK_POS_BOTTOM)
|
||||
{
|
||||
g_object_unref (pixmap);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (real_gap_side == GTK_POS_TOP || real_gap_side == GTK_POS_BOTTOM) {
|
||||
/* experimental tab-drawing code from mozilla */
|
||||
RECT rect;
|
||||
HDC dc;
|
||||
gint32 aPosition;
|
||||
|
||||
if (real_gap_side == GTK_POS_BOTTOM)
|
||||
g_object_unref (pixmap);
|
||||
dc = get_window_dc (style, window, state_type, x, y, width, height, &rect);
|
||||
|
||||
dc = get_window_dc(style, window, state_type, x, y, width, height, &rect);
|
||||
|
||||
if (real_gap_side == GTK_POS_TOP)
|
||||
if (gap_side == GTK_POS_TOP)
|
||||
aPosition = BF_TOP;
|
||||
else if (real_gap_side == GTK_POS_BOTTOM)
|
||||
else if (gap_side == GTK_POS_BOTTOM)
|
||||
aPosition = BF_BOTTOM;
|
||||
else if (real_gap_side == GTK_POS_LEFT)
|
||||
else if (gap_side == GTK_POS_LEFT)
|
||||
aPosition = BF_LEFT;
|
||||
else
|
||||
aPosition = BF_RIGHT;
|
||||
|
||||
if( state_type == GTK_STATE_PRELIGHT )
|
||||
if(state_type == GTK_STATE_PRELIGHT)
|
||||
state_type = GTK_STATE_NORMAL;
|
||||
if (area)
|
||||
gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
|
||||
DrawTab (dc, rect, aPosition, state_type != GTK_STATE_PRELIGHT, (real_gap_side != GTK_POS_LEFT), (real_gap_side != GTK_POS_RIGHT));
|
||||
|
||||
DrawTab (dc, rect, aPosition,
|
||||
state_type != GTK_STATE_PRELIGHT,
|
||||
(gap_side != GTK_POS_LEFT),
|
||||
(gap_side != GTK_POS_RIGHT));
|
||||
if (area)
|
||||
gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
|
||||
|
||||
release_window_dc (style, window, state_type);
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (real_gap_side == GTK_POS_LEFT || real_gap_side == GTK_POS_RIGHT)
|
||||
g_object_unref (pixmap);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
draw_extension (GtkStyle *style,
|
||||
GdkWindow *window,
|
||||
GtkStateType state_type,
|
||||
GtkShadowType shadow_type,
|
||||
GdkRectangle *area,
|
||||
GtkWidget *widget,
|
||||
const gchar *detail,
|
||||
gint x, gint y,
|
||||
gint width, gint height,
|
||||
GtkPositionType gap_side)
|
||||
{
|
||||
if (widget && GTK_IS_NOTEBOOK (widget) && detail && !strcmp (detail, "tab"))
|
||||
{
|
||||
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
|
||||
|
||||
/* Why this differs from gap_side, I have no idea.. */
|
||||
int real_gap_side = gtk_notebook_get_tab_pos (notebook);
|
||||
|
||||
if (!draw_themed_tab_button (style, window, state_type,
|
||||
GTK_NOTEBOOK (widget), x, y,
|
||||
width, height, real_gap_side))
|
||||
{
|
||||
if (!draw_tab_button (style, window, state_type,
|
||||
shadow_type, area, widget,
|
||||
detail,
|
||||
x, y, width, height, gap_side))
|
||||
{
|
||||
parent_class->draw_extension (style, window, state_type,
|
||||
shadow_type, area, widget, detail,
|
||||
x, y, width, height, real_gap_side);
|
||||
}
|
||||
}
|
||||
}
|
||||
parent_class->draw_extension
|
||||
(style, window, state_type, shadow_type, area, widget, detail,
|
||||
x, y, width, height, gap_side);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user