Fix tab icon alignment and hiding throbber fallback when needed

This commit is contained in:
Christian Dywan 2008-10-30 22:17:19 +01:00
parent 28ccfd8743
commit d1b64e6d48
2 changed files with 69 additions and 32 deletions

View file

@ -14,6 +14,7 @@
#include "katze-utils.h"
#include <glib/gi18n.h>
#include <math.h>
struct _KatzeThrobber
{
@ -782,10 +783,30 @@ katze_throbber_size_request (GtkWidget* widget,
requisition);
}
static void
katze_throbber_aligned_coords (GtkWidget* widget,
gint* ax,
gint* ay)
{
gfloat xalign, yalign;
gint xpad, ypad;
gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
xalign = 1.0 - xalign;
gtk_misc_get_padding (GTK_MISC (widget), &xpad, &ypad);
*ax = floor (widget->allocation.x + xpad
+ ((widget->allocation.width - widget->requisition.width) * xalign));
*ay = floor (widget->allocation.y + ypad
+ ((widget->allocation.height - widget->requisition.height) * yalign));
}
static gboolean
katze_throbber_expose_event (GtkWidget* widget,
GdkEventExpose* event)
{
gint ax, ay;
KatzeThrobber* throbber = KATZE_THROBBER (widget);
if (G_UNLIKELY (!throbber->width || !throbber->height))
@ -825,10 +846,10 @@ katze_throbber_expose_event (GtkWidget* widget,
}
}
katze_throbber_aligned_coords (widget, &ax, &ay);
gdk_draw_pixbuf (event->window, NULL, throbber->static_pixbuf,
0, 0,
widget->allocation.x,
widget->allocation.y,
0, 0, ax, ay,
throbber->width, throbber->height,
GDK_RGB_DITHER_NONE, 0, 0);
}
@ -852,10 +873,11 @@ katze_throbber_expose_event (GtkWidget* widget,
if (G_UNLIKELY (cols == 1 && cols == rows))
{
katze_throbber_aligned_coords (widget, &ax, &ay);
if (throbber->animated)
gdk_draw_pixbuf (event->window, NULL, throbber->pixbuf,
0, 0,
widget->allocation.x,
widget->allocation.y,
0, 0, ax, ay,
throbber->width, throbber->height,
GDK_RGB_DITHER_NONE, 0, 0);
return TRUE;
@ -863,18 +885,20 @@ katze_throbber_expose_event (GtkWidget* widget,
if (G_LIKELY (cols > 0 && rows > 0))
{
gint index = throbber->index % (cols * rows);
gint index;
guint x, y;
katze_throbber_aligned_coords (widget, &ax, &ay);
index = throbber->index % (cols * rows);
if (G_LIKELY (throbber->timer_id >= 0))
index = MAX (index, 1);
guint x = (index % cols) * throbber->width;
guint y = (index / cols) * throbber->height;
x = (index % cols) * throbber->width;
y = (index / cols) * throbber->height;
gdk_draw_pixbuf (event->window, NULL, throbber->pixbuf,
x, y,
widget->allocation.x,
widget->allocation.y,
x, y, ax, ay,
throbber->width, throbber->height,
GDK_RGB_DITHER_NONE, 0, 0);
}

View file

@ -1114,20 +1114,6 @@ midori_view_new (KatzeNet* net)
return g_object_new (MIDORI_TYPE_VIEW, "net", net, NULL);
}
static void
_update_label_size (GtkWidget* label,
gint size)
{
gint width, height;
if (size < 1)
size = 10;
sokoke_widget_get_text_size (label, "M", &width, &height);
gtk_widget_set_size_request (label, width * size, -1);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
}
static void
_midori_view_update_settings (MidoriView* view)
{
@ -1617,6 +1603,30 @@ midori_view_tab_close_clicked (GtkWidget* tab_close,
gtk_widget_destroy (widget);
}
static void
midori_view_tab_icon_style_set_cb (GtkWidget* tab_icon,
GtkStyle* previous_style)
{
GtkSettings* gtk_settings;
gint width, height;
gtk_settings = gtk_widget_get_settings (tab_icon);
gtk_icon_size_lookup_for_settings (gtk_settings, GTK_ICON_SIZE_MENU,
&width, &height);
gtk_widget_set_size_request (tab_icon, width + 4, height + 4);
}
static void
midori_view_update_label_size (GtkWidget* label,
gint size)
{
gint width;
sokoke_widget_get_text_size (label, "M", &width, NULL);
gtk_widget_set_size_request (label, width * size, -1);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
}
/**
* midori_view_get_proxy_tab_label:
* @view: a #MidoriView
@ -1646,15 +1656,16 @@ midori_view_get_proxy_tab_label (MidoriView* view)
view->tab_icon = katze_throbber_new ();
katze_throbber_set_static_pixbuf (KATZE_THROBBER (view->tab_icon),
midori_view_get_icon (view));
gtk_misc_set_alignment (GTK_MISC (view->tab_icon), 0.0, 0.5);
view->tab_title = gtk_label_new (midori_view_get_display_title (view));
gtk_misc_set_alignment (GTK_MISC (view->tab_title), 0.0, 0.5);
event_box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
hbox = gtk_hbox_new (FALSE, 1);
gtk_container_add (GTK_CONTAINER (event_box), GTK_WIDGET (hbox));
/* TODO: make the tab initially look "unvisited" until it's focused */
_update_label_size (view->tab_title, 10);
midori_view_update_label_size (view->tab_title, 10);
view->tab_close = gtk_button_new ();
gtk_button_set_relief (GTK_BUTTON (view->tab_close), GTK_RELIEF_NONE);
@ -1665,7 +1676,7 @@ midori_view_get_proxy_tab_label (MidoriView* view)
g_object_unref (rcstyle);
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON (view->tab_close), image);
gtk_misc_set_alignment (GTK_MISC (image), 0.0, 0.0);
gtk_misc_set_alignment (GTK_MISC (image), 0.0, 0.5);
#if HAVE_OSX
gtk_box_pack_end (GTK_BOX (hbox), view->tab_icon, FALSE, FALSE, 0);
@ -1683,6 +1694,8 @@ midori_view_get_proxy_tab_label (MidoriView* view)
g_signal_connect (event_box, "button-release-event",
G_CALLBACK (midori_view_tab_label_button_release_event), view);
g_signal_connect (view->tab_close, "style-set",
G_CALLBACK (midori_view_tab_icon_style_set_cb), NULL);
g_signal_connect (view->tab_close, "clicked",
G_CALLBACK (midori_view_tab_close_clicked), view);