#include "katze-utils.h"
#include <glib/gi18n.h>
+#include <math.h>
struct _KatzeThrobber
{
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))
}
}
+ 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);
}
if (G_UNLIKELY (cols == 1 && cols == rows))
{
- gdk_draw_pixbuf (event->window, NULL, throbber->pixbuf,
- 0, 0,
- widget->allocation.x,
- widget->allocation.y,
- throbber->width, throbber->height,
- GDK_RGB_DITHER_NONE, 0, 0);
+ katze_throbber_aligned_coords (widget, &ax, &ay);
+
+ if (throbber->animated)
+ gdk_draw_pixbuf (event->window, NULL, throbber->pixbuf,
+ 0, 0, ax, ay,
+ throbber->width, throbber->height,
+ GDK_RGB_DITHER_NONE, 0, 0);
return TRUE;
}
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);
}
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)
{
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
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);
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);
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);