[Monodevelop-patches-list] r1165 - in trunk/MonoDevelop: . gdldock/sources/gdl
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Fri Mar 12 16:04:23 EST 2004
Author: ggiraldez
Date: 2004-03-12 16:04:23 -0500 (Fri, 12 Mar 2004)
New Revision: 1165
Modified:
trunk/MonoDevelop/ChangeLog
trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-bar.c
trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.c
trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.h
trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item.c
trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-object.c
Log:
2004-03-12 Gustavo Gir?\195?\161ldez <gustavo.giraldez at gmx.net>
* gdldock/sources/gdl/gdl-dock-item-grip.c:
* gdldock/sources/gdl/gdl-dock-item-grip.h:
* gdldock/sources/gdl/gdl-dock-item.c:
* gdldock/sources/gdl/gdl-dock-object.c:
* gdldock/sources/gdl/gdl-dock-bar.c:
Update GdlDock from Gnome's gdl module: ellipsizing labels for the
dock item grip and a couple of memory and object leaks.
Modified: trunk/MonoDevelop/ChangeLog
===================================================================
--- trunk/MonoDevelop/ChangeLog 2004-03-12 19:01:15 UTC (rev 1164)
+++ trunk/MonoDevelop/ChangeLog 2004-03-12 21:04:23 UTC (rev 1165)
@@ -1,5 +1,16 @@
2004-03-12 Gustavo Giráldez <gustavo.giraldez at gmx.net>
+ * gdldock/sources/gdl/gdl-dock-item-grip.c:
+ * gdldock/sources/gdl/gdl-dock-item-grip.h:
+ * gdldock/sources/gdl/gdl-dock-item.c:
+ * gdldock/sources/gdl/gdl-dock-object.c:
+ * gdldock/sources/gdl/gdl-dock-bar.c:
+
+ Update GdlDock from Gnome's gdl module: ellipsizing labels for the
+ dock item grip and a couple of memory and object leaks.
+
+2004-03-12 Gustavo Giráldez <gustavo.giraldez at gmx.net>
+
* gdldock/sources/gdl/Makefile.am: Build libgdldock.so using
automake builtin rules for shared libraries instead of a hackish,
home made solution.
Modified: trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-bar.c
===================================================================
--- trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-bar.c 2004-03-12 19:01:15 UTC (rev 1164)
+++ trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-bar.c 2004-03-12 21:04:23 UTC (rev 1165)
@@ -99,6 +99,8 @@
dockbar->_priv->master = NULL;
dockbar->_priv->items = NULL;
dockbar->_priv->tooltips = gtk_tooltips_new ();
+ g_object_ref (dockbar->_priv->tooltips);
+ gtk_object_sink (GTK_OBJECT (dockbar->_priv->tooltips));
}
static void
@@ -152,7 +154,7 @@
}
if (priv->tooltips) {
- gtk_object_destroy (GTK_OBJECT (priv->tooltips));
+ g_object_unref (priv->tooltips);
priv->tooltips = NULL;
}
@@ -249,6 +251,7 @@
gtk_box_pack_start (GTK_BOX (dockbar), button, FALSE, FALSE, 0);
gtk_tooltips_set_tip (priv->tooltips, button, name, name);
+ g_free (name);
g_object_set_data (G_OBJECT (item), "GdlDockBar", dockbar);
g_object_set_data (G_OBJECT (item), "GdlDockBarButton", button);
Modified: trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.c
===================================================================
--- trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.c 2004-03-12 19:01:15 UTC (rev 1164)
+++ trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.c 2004-03-12 21:04:23 UTC (rev 1165)
@@ -17,25 +17,16 @@
#include "gdl-i18n.h"
#include <string.h>
#include <glib-object.h>
-#include <atk/atkstateset.h>
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtkaccessible.h>
-#include <gtk/gtkbindings.h>
+#include <gtk/gtkbutton.h>
+#include <gtk/gtktooltips.h>
+#include <gtk/gtkimage.h>
#include "gdl-dock-item.h"
#include "gdl-dock-item-grip.h"
-#include "gdl-dock.h"
#include "gdl-stock.h"
#include "gdl-tools.h"
-#define A11Y_UNFINISHED
enum {
- ACTIVATE,
- LAST_SIGNAL
-};
-static guint signals [LAST_SIGNAL];
-
-enum {
PROP_0,
PROP_ITEM
};
@@ -45,13 +36,17 @@
GtkWidget *iconify_button;
GtkTooltips *tooltips;
+ gboolean icon_pixbuf_valid;
GdkPixbuf *icon_pixbuf;
+
+ gchar *title;
PangoLayout *title_layout;
};
GDL_CLASS_BOILERPLATE (GdlDockItemGrip, gdl_dock_item_grip,
GtkContainer, GTK_TYPE_CONTAINER);
+/* must be called after size_allocate */
static void
gdl_dock_item_grip_get_title_area (GdlDockItemGrip *grip,
GdkRectangle *area)
@@ -65,15 +60,11 @@
pango_layout_get_pixel_size (grip->_priv->title_layout, NULL, &alloc_height);
if (GTK_WIDGET_VISIBLE (grip->_priv->close_button)) {
- if (grip->_priv->close_button->allocation.height > alloc_height) {
- alloc_height = grip->_priv->close_button->allocation.height;
- }
+ alloc_height = MAX (grip->_priv->close_button->allocation.height, alloc_height);
area->width -= grip->_priv->close_button->allocation.width;
}
if (GTK_WIDGET_VISIBLE (grip->_priv->iconify_button)) {
- if (grip->_priv->iconify_button->allocation.height > alloc_height) {
- alloc_height = grip->_priv->iconify_button->allocation.height;
- }
+ alloc_height = MAX (grip->_priv->iconify_button->allocation.height, alloc_height);
area->width -= grip->_priv->iconify_button->allocation.width;
}
@@ -84,85 +75,95 @@
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
area->x += (widget->allocation.width - 2 * border) - area->width;
}
-
+
+static void
+ensure_title_and_icon_pixbuf (GdlDockItemGrip *grip)
+{
+ gchar *stock_id;
+
+ g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (grip));
+
+ /* get long name property from the dock object */
+ if (!grip->_priv->title) {
+ g_object_get (G_OBJECT (grip->item), "long_name", &grip->_priv->title, NULL);
+ if (!grip->_priv->title)
+ grip->_priv->title = g_strdup ("");
+ }
+
+ /* retrieve stock pixbuf, if any */
+ if (!grip->_priv->icon_pixbuf_valid) {
+ g_object_get (G_OBJECT (grip->item), "stock_id", &stock_id, NULL);
+
+ if (stock_id) {
+ grip->_priv->icon_pixbuf = gtk_widget_render_icon (GTK_WIDGET (grip),
+ stock_id,
+ GTK_ICON_SIZE_MENU, "");
+ g_free (stock_id);
+ }
+ grip->_priv->icon_pixbuf_valid = TRUE;
+ }
+
+ /* create layout: the actual text is reset at size_allocate */
+ if (!grip->_priv->title_layout) {
+ grip->_priv->title_layout = gtk_widget_create_pango_layout (GTK_WIDGET (grip),
+ grip->_priv->title);
+ pango_layout_set_single_paragraph_mode (grip->_priv->title_layout, TRUE);
+ }
+}
+
static gint
gdl_dock_item_grip_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GdlDockItemGrip *grip;
- gint border;
- gchar *stock_id;
- GdkRectangle pixbuf_rect;
- gint pixbuf_width;
GdkRectangle title_area;
GdkRectangle expose_area;
- gchar *name;
gint layout_width;
gint layout_height;
gint text_x;
gint text_y;
grip = GDL_DOCK_ITEM_GRIP (widget);
- border = GTK_CONTAINER (grip)->border_width;
- g_object_get (G_OBJECT (grip->item), "stock_id", &stock_id, NULL);
- if (stock_id) {
- GdkPixbuf *pixbuf;
+ gdl_dock_item_grip_get_title_area (grip, &title_area);
+
+ if (grip->_priv->icon_pixbuf) {
+ GdkRectangle pixbuf_rect;
- if (!grip->_priv->icon_pixbuf) {
- pixbuf = gtk_widget_render_icon (widget, stock_id,
- GTK_ICON_SIZE_MENU, "");
- grip->_priv->icon_pixbuf = pixbuf;
+ pixbuf_rect.width = gdk_pixbuf_get_width (grip->_priv->icon_pixbuf);
+ pixbuf_rect.height = gdk_pixbuf_get_height (grip->_priv->icon_pixbuf);
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) {
+ pixbuf_rect.x = title_area.x + title_area.width - pixbuf_rect.width;
} else {
- pixbuf = grip->_priv->icon_pixbuf;
+ pixbuf_rect.x = title_area.x;
+ title_area.x += pixbuf_rect.width + 1;
}
-
- g_free (stock_id);
+ /* shrink title area by the pixbuf width plus a 1px spacing */
+ title_area.width -= pixbuf_rect.width + 1;
+ pixbuf_rect.y = title_area.y + (title_area.height - pixbuf_rect.height) / 2;
- pixbuf_rect.width = gdk_pixbuf_get_width (pixbuf);
- pixbuf_rect.height = gdk_pixbuf_get_height (pixbuf);
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- pixbuf_rect.x = widget->allocation.x + widget->allocation.width -
- border - pixbuf_rect.width;
- else
- pixbuf_rect.x = widget->allocation.x + border;
- pixbuf_rect.y = widget->allocation.y + border +
- (widget->allocation.height - pixbuf_rect.height) / 2;
-
if (gdk_rectangle_intersect (&event->area, &pixbuf_rect, &expose_area)) {
GdkGC *gc;
GtkStyle *style;
style = gtk_widget_get_style (widget);
gc = style->bg_gc[widget->state];
- gdk_draw_pixbuf (GDK_DRAWABLE (widget->window), gc, pixbuf,
+ gdk_draw_pixbuf (GDK_DRAWABLE (widget->window), gc,
+ grip->_priv->icon_pixbuf,
0, 0, pixbuf_rect.x, pixbuf_rect.y,
pixbuf_rect.width, pixbuf_rect.height,
GDK_RGB_DITHER_NONE, 0, 0);
}
-
- pixbuf_width = pixbuf_rect.width + 1;
- } else {
- pixbuf_width = 0;
}
- gdl_dock_item_grip_get_title_area (grip, &title_area);
-
if (gdk_rectangle_intersect (&title_area, &event->area, &expose_area)) {
- if (!grip->_priv->title_layout) {
- g_object_get (G_OBJECT (grip->item), "long_name", &name, NULL);
- grip->_priv->title_layout = gtk_widget_create_pango_layout (widget,
- name);
- g_free (name);
- }
-
pango_layout_get_pixel_size (grip->_priv->title_layout, &layout_width,
&layout_height);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- text_x = title_area.x + title_area.width - layout_width - pixbuf_width;
+ text_x = title_area.x + title_area.width - layout_width;
else
- text_x = title_area.x + pixbuf_width;
+ text_x = title_area.x;
text_y = title_area.y + (title_area.height - layout_height) / 2;
@@ -174,232 +175,44 @@
return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
}
-#ifndef A11Y_UNFINISHED
-
-static AtkObjectClass *a11y_parent_class = NULL;
-
static void
-grip_item_a11y_initialize (AtkObject *accessible, gpointer widget)
-{
- accessible->role = ATK_ROLE_SEPARATOR;
- atk_object_set_name (accessible, "grip");
-
- a11y_parent_class->initialize (accessible, widget);
-}
-
-static AtkStateSet*
-grip_item_a11y_ref_state_set (AtkObject *accessible)
-{
- AtkStateSet *state_set;
- GdlDockItemGrip *grip;
-
- state_set = a11y_parent_class->ref_state_set (accessible);
- grip = GDL_DOCK_ITEM_GRIP (
- GTK_ACCESSIBLE (accessible)->widget);
-
- if (grip == NULL)
- return state_set;
-
- if (grip->item->orientation == GTK_ORIENTATION_VERTICAL) {
- atk_state_set_add_state (state_set, ATK_STATE_VERTICAL);
- atk_state_set_remove_state (state_set, ATK_STATE_HORIZONTAL);
- } else {
- atk_state_set_add_state (state_set, ATK_STATE_HORIZONTAL);
- atk_state_set_remove_state (state_set, ATK_STATE_VERTICAL);
- }
-
- return state_set;
-}
-
-static GdlDock *
-get_dock (GtkWidget *widget)
-{
- while (widget && !GDL_IS_DOCK (widget))
- widget = widget->parent;
-
- return (GdlDock *) widget;
-}
-
-static void
-gdl_dock_item_grip_dock (GdlDockItemGrip *grip)
-{
- GdlDock *dock;
-
- g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (grip));
-
- dock = get_dock (GTK_WIDGET (grip->item));
- g_return_if_fail (dock != NULL);
-
- gdl_dock_item_unfloat (grip->item);
-
- g_object_ref (G_OBJECT (grip->item));
- gtk_container_remove (
- GTK_CONTAINER (
- GTK_WIDGET (grip->item)->parent),
- GTK_WIDGET (grip->item));
- gdl_dock_add_item (
- dock, grip->item,
- BONOBO_DOCK_TOP, 2, 0, 0, TRUE);
- g_object_unref (G_OBJECT (grip->item));
-}
-
-static void
-gdl_dock_item_grip_undock (GdlDockItemGrip *grip)
-{
- guint x, y;
-
- g_return_if_fail (BONOBO_IS_DOCK_ITEM_GRIP (grip));
-
- if (grip->item->is_floating)
- return;
-
- gdk_window_get_position (
- GTK_WIDGET (grip)->window, &x, &y);
-
- gdl_dock_item_detach (grip->item, x, y);
-}
-
-enum {
- ACTION_DOCK,
- ACTION_UNDOCK,
- ACTION_LAST
-};
-
-static gboolean
-gdl_dock_item_grip_do_action (AtkAction *action,
- gint i)
-{
- GdlDockItemGrip *grip;
-
- grip = GDL_DOCK_ITEM_GRIP (
- GTK_ACCESSIBLE (action)->widget);
-
- if (grip->item->behavior & GDL_DOCK_ITEM_BEH_LOCKED)
- return FALSE;
-
- switch (i) {
- case ACTION_DOCK:
- gdl_dock_item_grip_dock (grip);
- break;
- case ACTION_UNDOCK:
- gdl_dock_item_grip_undock (grip);
- break;
- default:
- break;
- }
- return FALSE;
-}
-
-static gint
-gdl_dock_item_grip_get_n_actions (AtkAction *action)
-{
- GdlDockItemGrip *grip;
-
- grip = GDL_DOCK_ITEM_GRIP (
- GTK_ACCESSIBLE (action)->widget);
-
- if (grip->item->behavior & GDL_DOCK_ITEM_BEH_LOCKED)
- return 0;
- else
- return ACTION_LAST;
-}
-
-static void
-grip_item_a11y_class_init (AtkObjectClass *klass)
-{
- a11y_parent_class = g_type_class_peek_parent (klass);
-
- klass->initialize = grip_item_a11y_initialize;
- klass->ref_state_set = grip_item_a11y_ref_state_set;
-}
-
-#endif /* A11Y_UNFINISHED */
-
-
-static AtkObject *
-gdl_dock_item_grip_get_accessible (GtkWidget *widget)
-{
-#ifndef A11Y_UNFINISHED
- AtkObject *accessible;
- static GType a11y_type = 0;
-
- if (!a11y_type) {
- AtkActionIface action_if;
-
- a11y_type = bonobo_a11y_get_derived_type_for (
- GDL_TYPE_DOCK_ITEM_GRIP,
- NULL, grip_item_a11y_class_init);
-
- memset (&action_if, 0, sizeof (AtkActionIface));
- action_if.do_action = gdl_dock_item_grip_do_action;
- action_if.get_n_actions = gdl_dock_item_grip_get_n_actions;
-
- bonobo_a11y_add_actions_interface (
- a11y_type, &action_if,
- ACTION_DOCK, "dock", _("Dock the toolbar"), "<Enter>",
- ACTION_UNDOCK, "undock", _("Un dock the toolbar"), "<Enter>",
- -1);
- }
-
- if ((accessible = bonobo_a11y_get_atk_object (widget)))
- return accessible;
-
- return bonobo_a11y_set_atk_object_ret (
- widget, g_object_new (a11y_type, NULL));
-#else /* !A11Y_UNFINISHED */
- return NULL;
-#endif /* A11Y_UNFINISHED */
-}
-
-static void
-gdl_dock_item_grip_activate (GdlDockItemGrip *grip)
-{
-#ifndef A11Y_UNFINISHED
- if (grip->item->is_floating)
- gdl_dock_item_grip_dock (grip);
- else
- gdl_dock_item_grip_undock (grip);
-#endif /* A11Y_UNFINISHED */
-}
-
-static void
gdl_dock_item_grip_item_notify (GObject *master,
GParamSpec *pspec,
gpointer data)
{
GdlDockItemGrip *grip;
- gchar *name;
- gchar *stock_id;
grip = GDL_DOCK_ITEM_GRIP (data);
- g_object_get (master, "long_name", &name, "stock_id", &stock_id, NULL);
- if (name && grip->_priv->title_layout) {
- g_object_unref (grip->_priv->title_layout);
- grip->_priv->title_layout = NULL;
- g_free (name);
- }
- if (stock_id && grip->_priv->icon_pixbuf) {
- g_object_unref (grip->_priv->icon_pixbuf);
- grip->_priv->icon_pixbuf = NULL;
- g_free (stock_id);
- }
- if (grip->_priv->close_button) {
- if (GDL_DOCK_ITEM_CANT_CLOSE (grip->item)) {
- gtk_widget_hide (GTK_WIDGET (grip->_priv->close_button));
- } else {
- gtk_widget_show (GTK_WIDGET (grip->_priv->close_button));
- }
- }
- if (grip->_priv->iconify_button) {
- if (GDL_DOCK_ITEM_CANT_ICONIFY (grip->item)) {
- gtk_widget_hide (GTK_WIDGET (grip->_priv->iconify_button));
- } else {
- gtk_widget_show (GTK_WIDGET (grip->_priv->iconify_button));
- }
- }
+ if (strcmp (pspec->name, "stock_id") == 0) {
+ if (grip->_priv->icon_pixbuf) {
+ g_object_unref (grip->_priv->icon_pixbuf);
+ grip->_priv->icon_pixbuf = NULL;
+ }
+ grip->_priv->icon_pixbuf_valid = FALSE;
+ ensure_title_and_icon_pixbuf (grip);
- gtk_widget_queue_resize (GTK_WIDGET (grip));
+ } else if (strcmp (pspec->name, "long_name") == 0) {
+ g_free (grip->_priv->title);
+ grip->_priv->title = NULL;
+ ensure_title_and_icon_pixbuf (grip);
+
+ } else if (strcmp (pspec->name, "behavior") == 0) {
+ if (grip->_priv->close_button) {
+ if (GDL_DOCK_ITEM_CANT_CLOSE (grip->item)) {
+ gtk_widget_hide (GTK_WIDGET (grip->_priv->close_button));
+ } else {
+ gtk_widget_show (GTK_WIDGET (grip->_priv->close_button));
+ }
+ }
+ if (grip->_priv->iconify_button) {
+ if (GDL_DOCK_ITEM_CANT_ICONIFY (grip->item)) {
+ gtk_widget_hide (GTK_WIDGET (grip->_priv->iconify_button));
+ } else {
+ gtk_widget_show (GTK_WIDGET (grip->_priv->iconify_button));
+ }
+ }
+ }
}
static void
@@ -414,20 +227,23 @@
g_object_unref (priv->title_layout);
priv->title_layout = NULL;
}
-
+ g_free (priv->title);
+ priv->title = NULL;
+
if (priv->icon_pixbuf) {
g_object_unref (priv->icon_pixbuf);
priv->icon_pixbuf = NULL;
}
if (priv->tooltips) {
- gtk_object_destroy (GTK_OBJECT (priv->tooltips));
+ g_object_unref (priv->tooltips);
priv->tooltips = NULL;
}
- g_signal_handlers_disconnect_by_func (grip->item,
- gdl_dock_item_grip_item_notify,
- grip);
+ if (grip->item)
+ g_signal_handlers_disconnect_by_func (grip->item,
+ gdl_dock_item_grip_item_notify,
+ grip);
grip->item = NULL;
grip->_priv = NULL;
@@ -462,6 +278,11 @@
g_signal_connect (grip->item, "notify::behavior",
G_CALLBACK (gdl_dock_item_grip_item_notify),
grip);
+
+ if (!GDL_DOCK_ITEM_CANT_CLOSE (grip->item) && grip->_priv->close_button)
+ gtk_widget_show (grip->_priv->close_button);
+ if (!GDL_DOCK_ITEM_CANT_ICONIFY (grip->item) && grip->_priv->iconify_button)
+ gtk_widget_show (grip->_priv->iconify_button);
}
break;
default:
@@ -500,11 +321,10 @@
GTK_WIDGET_SET_FLAGS (grip, GTK_NO_WINDOW);
grip->_priv = g_new0 (GdlDockItemGripPrivate, 1);
+ grip->_priv->icon_pixbuf_valid = FALSE;
grip->_priv->icon_pixbuf = NULL;
grip->_priv->title_layout = NULL;
- gdl_stock_init ();
-
gtk_widget_push_composite_child ();
grip->_priv->close_button = gtk_button_new ();
gtk_widget_pop_composite_child ();
@@ -538,44 +358,14 @@
G_CALLBACK (gdl_dock_item_grip_iconify_clicked), grip);
grip->_priv->tooltips = gtk_tooltips_new ();
+ g_object_ref (grip->_priv->tooltips);
+ gtk_object_sink (GTK_OBJECT (grip->_priv->tooltips));
gtk_tooltips_set_tip (grip->_priv->tooltips, grip->_priv->iconify_button,
_("Iconify"), _("Iconify this dock"));
gtk_tooltips_set_tip (grip->_priv->tooltips, grip->_priv->close_button,
_("Close"), _("Close this dock"));
}
-#ifndef A11Y_UNFINISHED
-static BonoboDockBand *
-get_dock_band (GtkWidget *widget)
-{
- while (widget && !BONOBO_IS_DOCK_BAND (widget))
- widget = widget->parent;
-
- return (BonoboDockBand *) widget;
-}
-#endif /* A11Y_UNFINISHED */
-
-static gint
-gdl_dock_item_grip_key_press_event (GtkWidget *widget,
- GdkEventKey *event)
-{
-#ifndef A11Y_UNFINISHED
- gboolean had_focus = GTK_WIDGET_HAS_FOCUS (widget);
- BonoboDockBand *band = get_dock_band (widget);
- BonoboDockItemGrip *grip = (BonoboDockItemGrip *) widget;
-
- if (!grip->item->is_floating && band &&
- bonobo_dock_band_handle_key_nav (band, grip->item, event))
- {
- if (had_focus && !GTK_WIDGET_HAS_FOCUS (widget))
- gtk_widget_grab_focus (widget);
- return TRUE;
- }
-#endif /* A11Y_UNFINISHED */
-
- return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
-}
-
static void
gdl_dock_item_grip_realize (GtkWidget *widget)
{
@@ -588,6 +378,7 @@
GdkRectangle area;
GdkCursor *cursor;
+ ensure_title_and_icon_pixbuf (grip);
gdl_dock_item_grip_get_title_area (grip, &area);
attributes.x = area.x;
@@ -660,9 +451,6 @@
GtkRequisition child_requisition;
GtkContainer *container;
GdlDockItemGrip *grip;
- GdkRectangle title_rect;
- gchar *stock_id;
- gchar *name;
gint layout_height;
g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
@@ -674,53 +462,70 @@
requisition->width = container->border_width * 2;
requisition->height = container->border_width * 2;
- if (!grip->_priv->title_layout) {
- g_object_get (G_OBJECT (grip->item), "long_name", &name, NULL);
- grip->_priv->title_layout = gtk_widget_create_pango_layout (widget,
- name);
- g_free (name);
- }
-
+ ensure_title_and_icon_pixbuf (grip);
pango_layout_get_pixel_size (grip->_priv->title_layout, NULL, &layout_height);
if (GTK_WIDGET_VISIBLE (grip->_priv->close_button)) {
gtk_widget_size_request (grip->_priv->close_button, &child_requisition);
requisition->width += child_requisition.width;
- if (child_requisition.height > layout_height) {
- layout_height = child_requisition.height;
- }
+ layout_height = MAX (layout_height, child_requisition.height);
}
if (GTK_WIDGET_VISIBLE (grip->_priv->iconify_button)) {
gtk_widget_size_request (grip->_priv->iconify_button, &child_requisition);
requisition->width += child_requisition.width;
- if (child_requisition.height > layout_height) {
- layout_height = child_requisition.height;
- }
+ layout_height = MAX (layout_height, child_requisition.height);
}
requisition->height += layout_height;
- gdl_dock_item_grip_get_title_area (grip, &title_rect);
- requisition->width += title_rect.width;
+ if (grip->_priv->icon_pixbuf) {
+ requisition->width += gdk_pixbuf_get_width (grip->_priv->icon_pixbuf) + 1;
+ }
+}
- g_object_get (G_OBJECT (grip->item), "stock_id", &stock_id, NULL);
- if (stock_id) {
- GdkPixbuf *pixbuf;
-
- if (!grip->_priv->icon_pixbuf) {
- pixbuf = gtk_widget_render_icon (widget, stock_id,
- GTK_ICON_SIZE_MENU, "");
- grip->_priv->icon_pixbuf = pixbuf;
- } else {
- pixbuf = grip->_priv->icon_pixbuf;
- }
+#define ELLIPSIS "..."
- requisition->width += gdk_pixbuf_get_width (pixbuf) + 1;
- g_free (stock_id);
+static void
+ellipsize_layout (PangoLayout *layout, gint width)
+{
+ PangoLayoutLine *line;
+ PangoLayout *ell;
+ gint h, w, ell_w, x;
+ GString *text;
+
+ if (width <= 0) {
+ pango_layout_set_text (layout, "", -1);
+ return;
}
+
+ pango_layout_get_pixel_size (layout, &w, &h);
+ if (w <= width) return;
+
+ /* calculate ellipsis width */
+ ell = pango_layout_copy (layout);
+ pango_layout_set_text (ell, ELLIPSIS, -1);
+ pango_layout_get_pixel_size (ell, &ell_w, NULL);
+ g_object_unref (ell);
+
+ if (width < ell_w) {
+ /* not even ellipsis fits, so hide the text */
+ pango_layout_set_text (layout, "", -1);
+ return;
+ }
+
+ /* shrink total available width by the width of the ellipsis */
+ width -= ell_w;
+ line = pango_layout_get_line (layout, 0);
+ text = g_string_new (pango_layout_get_text (layout));
+ if (pango_layout_line_x_to_index (line, width * PANGO_SCALE, &x, NULL)) {
+ g_string_set_size (text, x);
+ g_string_append (text, ELLIPSIS);
+ pango_layout_set_text (layout, text->str, -1);
+ }
+ g_string_free (text, TRUE);
}
static void
@@ -779,10 +584,20 @@
if (grip->title_window) {
GdkRectangle area;
+ /* set layout text */
+ ensure_title_and_icon_pixbuf (grip);
+ pango_layout_set_text (grip->_priv->title_layout, grip->_priv->title, -1);
+
gdl_dock_item_grip_get_title_area (grip, &area);
-
+
gdk_window_move_resize (grip->title_window,
area.x, area.y, area.width, area.height);
+
+ if (grip->_priv->icon_pixbuf)
+ area.width -= gdk_pixbuf_get_width (grip->_priv->icon_pixbuf) + 1;
+
+ /* ellipsize title if it doesn't fit the title area */
+ ellipsize_layout (grip->_priv->title_layout, area.width);
}
}
@@ -821,13 +636,12 @@
static GtkType
gdl_dock_item_grip_child_type (GtkContainer *container)
{
- return GTK_TYPE_WIDGET;
+ return G_TYPE_NONE;
}
static void
gdl_dock_item_grip_class_init (GdlDockItemGripClass *klass)
{
- GtkBindingSet *binding_set;
GObjectClass *gobject_class;
GtkObjectClass *gtk_object_class;
GtkWidgetClass *widget_class;
@@ -844,8 +658,6 @@
gtk_object_class->destroy = gdl_dock_item_grip_destroy;
widget_class->expose_event = gdl_dock_item_grip_expose;
- widget_class->get_accessible = gdl_dock_item_grip_get_accessible;
- widget_class->key_press_event = gdl_dock_item_grip_key_press_event;
widget_class->realize = gdl_dock_item_grip_realize;
widget_class->unrealize = gdl_dock_item_grip_unrealize;
widget_class->map = gdl_dock_item_grip_map;
@@ -858,31 +670,15 @@
container_class->forall = gdl_dock_item_grip_forall;
container_class->child_type = gdl_dock_item_grip_child_type;
- klass->activate = gdl_dock_item_grip_activate;
-
- binding_set = gtk_binding_set_by_class (klass);
-
g_object_class_install_property (
gobject_class, PROP_ITEM,
g_param_spec_object ("item", _("Controlling dock item"),
_("Dockitem which 'owns' this grip"),
GDL_TYPE_DOCK_ITEM,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
- signals [ACTIVATE] =
- g_signal_new ("activate",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (
- GdlDockItemGripClass, activate),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- widget_class->activate_signal = signals [ACTIVATE];
- gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
- "activate", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
- "activate", 0);
+ /* initialize stock images */
+ gdl_stock_init ();
}
GtkWidget *
Modified: trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.h
===================================================================
--- trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.h 2004-03-12 19:01:15 UTC (rev 1164)
+++ trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item-grip.h 2004-03-12 21:04:23 UTC (rev 1165)
@@ -46,8 +46,6 @@
struct _GdlDockItemGripClass {
GtkContainerClass parent_class;
-
- void (*activate) (GdlDockItemGrip *grip);
};
GType gdl_dock_item_grip_get_type (void);
Modified: trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item.c
===================================================================
--- trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item.c 2004-03-12 19:01:15 UTC (rev 1164)
+++ trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-item.c 2004-03-12 21:04:23 UTC (rev 1165)
@@ -939,12 +939,17 @@
GDL_DOCK_ITEM_UNSET_FLAGS (item, GDL_DOCK_IN_PREDRAG);
event_handled = TRUE;
}
-
- cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
- GDK_HAND2);
- gdk_window_set_cursor (GDL_DOCK_ITEM_GRIP (item->_priv->grip)->title_window,
- cursor);
- gdk_cursor_unref (cursor);
+
+ /* we check the window since if the item was redocked it's
+ been unrealized and maybe it's not realized again yet */
+ if (GDL_DOCK_ITEM_GRIP (item->_priv->grip)->title_window) {
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
+ GDK_HAND2);
+ gdk_window_set_cursor (GDL_DOCK_ITEM_GRIP (item->_priv->grip)->title_window,
+ cursor);
+ gdk_cursor_unref (cursor);
+ }
+
} else if (event->button == 3 && event->type == GDK_BUTTON_PRESS && in_handle) {
gdl_dock_item_popup_menu (item, event->button, event->time);
event_handled = TRUE;
Modified: trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-object.c
===================================================================
--- trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-object.c 2004-03-12 19:01:15 UTC (rev 1164)
+++ trunk/MonoDevelop/gdldock/sources/gdl/gdl-dock-object.c 2004-03-12 21:04:23 UTC (rev 1165)
@@ -266,6 +266,8 @@
object->name = NULL;
g_free (object->long_name);
object->long_name = NULL;
+ g_free (object->stock_id);
+ object->stock_id = NULL;
GDL_CALL_PARENT (G_OBJECT_CLASS, finalize, (g_object));
}
More information about the Monodevelop-patches-list
mailing list