*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id$
*/
#include "egg-toolbars-model.h"
#include "egg-toolbar-editor.h"
-#include <gtk/gtkvseparator.h>
-#include <gtk/gtkiconfactory.h>
-#include <gtk/gtkwindow.h>
-#include <gtk/gtkmain.h>
-#include <gtk/gtkdnd.h>
-#include <gtk/gtkhbox.h>
-#include <gtk/gtkimage.h>
-#include <gtk/gtktoggleaction.h>
-#include <gtk/gtkcheckmenuitem.h>
-#include <gtk/gtkimagemenuitem.h>
-#include <gtk/gtkseparatormenuitem.h>
-#include <gtk/gtkmenu.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkbutton.h>
-#include <gtk/gtktoolbar.h>
-#include <gtk/gtktoolitem.h>
-#include <gtk/gtktoolbutton.h>
-#include <gtk/gtkseparatortoolitem.h>
+#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <string.h>
-static void egg_editable_toolbar_class_init (EggEditableToolbarClass *klass);
-static void egg_editable_toolbar_init (EggEditableToolbar *etoolbar);
+static GdkPixbuf * new_separator_pixbuf (void);
#define MIN_TOOLBAR_HEIGHT 20
#define EGG_ITEM_NAME "egg-item-name"
static guint egg_editable_toolbar_signals[LAST_SIGNAL] = { 0 };
-static GObjectClass *parent_class = NULL;
-
#define EGG_EDITABLE_TOOLBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarPrivate))
struct _EggEditableToolbarPrivate
guint edit_mode;
gboolean save_hidden;
GtkWidget *fixed_toolbar;
-
+
GtkWidget *selected;
GtkActionGroup *actions;
-
+
guint visibility_id;
GList *visibility_paths;
GPtrArray *visibility_actions;
GtkToolItem *dnd_toolitem;
};
-GType
-egg_editable_toolbar_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0))
- {
- const GTypeInfo our_info = {
- sizeof (EggEditableToolbarClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) egg_editable_toolbar_class_init,
- NULL,
- NULL, /* class_data */
- sizeof (EggEditableToolbar),
- 0, /* n_preallocs */
- (GInstanceInitFunc) egg_editable_toolbar_init
- };
-
- type = g_type_register_static (GTK_TYPE_VBOX,
- "EggEditableToolbar",
- &our_info, 0);
- }
-
- return type;
-}
+G_DEFINE_TYPE (EggEditableToolbar, egg_editable_toolbar, GTK_TYPE_VBOX);
static int
get_dock_position (EggEditableToolbar *etoolbar,
static int
get_toolbar_position (EggEditableToolbar *etoolbar, GtkWidget *toolbar)
{
- return get_dock_position (etoolbar, toolbar->parent);
+ return get_dock_position (etoolbar, gtk_widget_get_parent (toolbar));
}
static int
EggEditableToolbar *etoolbar)
{
int pos, toolbar_pos;
+ GtkWidget *parent;
widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
g_return_if_fail (widget != NULL);
g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
- pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget->parent),
+ parent = gtk_widget_get_parent (widget);
+ pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (parent),
GTK_TOOL_ITEM (widget));
- toolbar_pos = get_toolbar_position (etoolbar, widget->parent);
+ toolbar_pos = get_toolbar_position (etoolbar, parent);
egg_toolbars_model_remove_item (etoolbar->priv->model,
toolbar_pos, pos);
{
GtkAction *action;
gint flags;
-
+
gtk_widget_hide (widget);
- action = g_object_get_data (G_OBJECT (widget), "gtk-action");
+#if GTK_CHECK_VERSION (2, 16, 0)
+ action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
+#else
+ action = gtk_widget_get_action (widget);
+#endif
+
if (action == NULL) return;
-
+
flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
gtk_action_get_name (action));
if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
{
GtkAction *action;
gint flags;
-
+
if (gtk_widget_get_parent (widget) != NULL)
{
gtk_widget_show (widget);
- action = g_object_get_data (G_OBJECT (widget), "gtk-action");
+#if GTK_CHECK_VERSION (2, 16, 0)
+ action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
+#else
+ action = gtk_widget_get_action (widget);
+#endif
+
if (action == NULL) return;
-
+
flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
gtk_action_get_name (action));
if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
EggToolbarsModel *model;
const char *name;
char *data;
+ GdkAtom target;
g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
model = egg_editable_toolbar_get_model (etoolbar);
-
+
name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
if (name == NULL)
{
name = g_object_get_data (G_OBJECT (gtk_widget_get_parent (widget)), EGG_ITEM_NAME);
g_return_if_fail (name != NULL);
}
-
- data = egg_toolbars_model_get_data (model, selection_data->target, name);
+
+ target = gtk_selection_data_get_target (selection_data);
+ data = egg_toolbars_model_get_data (model, target, name);
if (data != NULL)
{
- gtk_selection_data_set (selection_data, selection_data->target, 8, (unsigned char *)data, strlen (data));
+ gtk_selection_data_set (selection_data, target, 8, (unsigned char *)data, strlen (data));
g_free (data);
}
}
gdk_event_get_state (realevent, &event.state);
gdk_event_get_coords (realevent, &event.x, &event.y);
gdk_event_get_root_coords (realevent, &event.x_root, &event.y_root);
-
+
gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event);
gtk_target_list_unref (list);
}
EggEditableToolbar *etoolbar)
{
GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
+ GtkWidget *parent = gtk_widget_get_parent (toolitem);
int pos, toolbar_pos;
-
- toolbar_pos = get_toolbar_position (etoolbar, toolitem->parent);
- pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolitem->parent),
+
+ toolbar_pos = get_toolbar_position (etoolbar, parent);
+ pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (parent),
GTK_TOOL_ITEM (toolitem));
egg_toolbars_model_remove_item (etoolbar->priv->model,
if (etoolbar->priv->popup_path != NULL)
{
GtkMenu *menu;
-
+
egg_editable_toolbar_set_selected (etoolbar, toolbar);
g_object_notify (G_OBJECT (etoolbar), "selected");
-
- menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
+
+ menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
etoolbar->priv->popup_path));
g_return_if_fail (menu != NULL);
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
if (event->button == 3 && etoolbar->priv->popup_path != NULL)
{
GtkMenu *menu;
-
+
egg_editable_toolbar_set_selected (etoolbar, widget);
g_object_notify (G_OBJECT (etoolbar), "selected");
-
- menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
+
+ menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
etoolbar->priv->popup_path));
g_return_val_if_fail (menu != NULL, FALSE);
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
g_signal_connect_object (menu, "selection-done",
G_CALLBACK (popup_context_deactivate),
etoolbar, 0);
-
+
return TRUE;
}
-
+
return FALSE;
}
{
GtkAction *action;
char *name;
-
+
name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
action = name ? find_action (etoolbar, name) : NULL;
-
+
if (action)
{
g_object_notify (G_OBJECT (action), "sensitive");
}
gtk_tool_item_set_use_drag_window (item,
- (etoolbar->priv->edit_mode > 0) ||
+ (etoolbar->priv->edit_mode > 0) ||
GTK_IS_SEPARATOR_TOOL_ITEM (item));
-
+
}
static void
{
EggEditableToolbarPrivate *priv = etoolbar->priv;
GtkWidget *widget = GTK_WIDGET (item);
+ GdkWindow *window = gtk_widget_get_window (widget);
- if (widget->window != NULL)
+ if (window != NULL)
{
if (priv->edit_mode > 0)
{
GdkCursor *cursor;
-
- cursor = gdk_cursor_new (GDK_HAND2);
- gdk_window_set_cursor (widget->window, cursor);
- gdk_cursor_unref (cursor);
+ GdkScreen *screen;
+ GdkPixbuf *pixbuf = NULL;
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));
+
+ cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
+ GDK_HAND2);
+ gdk_window_set_cursor (window, cursor);
+ g_object_unref (cursor);
gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
+ if (GTK_IS_SEPARATOR_TOOL_ITEM (item))
+ {
+ pixbuf = new_separator_pixbuf ();
+ }
+ else
+ {
+ char *icon_name=NULL;
+ char *stock_id=NULL;
+ GtkAction *action;
+ char *name;
+
+ name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
+ action = name ? find_action (etoolbar, name) : NULL;
+
+ if (action)
+ {
+ g_object_get (action,
+ "icon-name", &icon_name,
+ "stock-id", &stock_id,
+ NULL);
+ }
+ if (icon_name)
+ {
+ GdkScreen *screen;
+ GtkIconTheme *icon_theme;
+ GtkSettings *settings;
+ gint width, height;
+
+ screen = gtk_widget_get_screen (widget);
+ icon_theme = gtk_icon_theme_get_for_screen (screen);
+ settings = gtk_settings_get_for_screen (screen);
+
+ if (!gtk_icon_size_lookup_for_settings (settings,
+ GTK_ICON_SIZE_LARGE_TOOLBAR,
+ &width, &height))
+ {
+ width = height = 24;
+ }
+
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
+ MIN (width, height), 0, NULL);
+ }
+ else if (stock_id)
+ {
+ pixbuf = gtk_widget_render_icon_pixbuf (widget, stock_id,
+ GTK_ICON_SIZE_LARGE_TOOLBAR);
+ }
+ g_free (icon_name);
+ g_free (stock_id);
+ }
+
+ if (G_UNLIKELY (!pixbuf))
+ {
+ return;
+ }
+ gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
+ g_object_unref (pixbuf);
+
}
else
{
- gdk_window_set_cursor (GTK_WIDGET(item)->window, NULL);
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET(item)), NULL);
}
}
}
static void
configure_item_tooltip (GtkToolItem *item)
{
- GtkAction *action = g_object_get_data (G_OBJECT (item),
- "gtk-action");
-
+ GtkAction *action;
+
+#if GTK_CHECK_VERSION (2, 16, 0)
+ action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
+#else
+ action = gtk_widget_get_action (GTK_WIDGET (item));
+#endif
+
if (action != NULL)
{
g_object_notify (G_OBJECT (action), "tooltip");
if (GTK_IS_TOOL_ITEM (proxy))
{
g_signal_connect_object (proxy, "drag_begin",
- G_CALLBACK (drag_begin_cb),
+ G_CALLBACK (drag_begin_cb),
etoolbar, 0);
g_signal_connect_object (proxy, "drag_end",
G_CALLBACK (drag_end_cb),
etoolbar, 0);
g_signal_connect_object (proxy, "drag_data_get",
- G_CALLBACK (drag_data_get_cb),
+ G_CALLBACK (drag_data_get_cb),
etoolbar, 0);
g_signal_connect_object (proxy, "drag_data_delete",
G_CALLBACK (drag_data_delete_cb),
etoolbar, 0);
}
-
+
if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
{
g_signal_connect_object (proxy, "button-press-event",
}
static void
-action_sensitive_cb (GtkAction *action,
+action_sensitive_cb (GtkAction *action,
GParamSpec *pspec,
GtkToolItem *item)
{
GtkToolItem *item;
g_return_val_if_fail (name != NULL, NULL);
-
+
if (strcmp (name, "_separator") == 0)
{
item = gtk_separator_tool_item_new ();
{
GtkAction *action = find_action (etoolbar, name);
if (action == NULL) return NULL;
-
+
item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));
/* Normally done on-demand by the GtkUIManager, but no
*/
gtk_action_set_accel_group
(action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));
-
+
g_signal_connect_object (action, "notify::sensitive",
G_CALLBACK (action_sensitive_cb), item, 0);
}
gtk_widget_show (GTK_WIDGET (item));
g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
- g_strdup (name), g_free);
-
+ g_strdup (name), g_free);
+
return item;
}
* actually add a new item to the toolbar.
*/
- GdkAtom type = selection_data->type;
- const char *data = (char *)selection_data->data;
-
+ GdkAtom type = gtk_selection_data_get_data_type (selection_data);
+ const char *data = (char *)gtk_selection_data_get_data (selection_data);
+
int ipos = -1;
char *name = NULL;
gboolean used = FALSE;
-
+
/* Find out where the drop is occuring, and the name of what is being dropped. */
- if (selection_data->length >= 0)
+ if (gtk_selection_data_get_length (selection_data) >= 0)
{
ipos = gtk_toolbar_get_drop_index (toolbar, x, y);
name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE);
if (etoolbar->priv->dnd_pending > 0)
{
etoolbar->priv->dnd_pending--;
-
+
if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used)
{
etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name);
gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
etoolbar->priv->dnd_toolbar = NULL;
etoolbar->priv->dnd_toolitem = NULL;
-
+
/* If we don't have a name to use yet, try to create one. */
- if (name == NULL && selection_data->length >= 0)
+ if (name == NULL && gtk_selection_data_get_length (selection_data) >= 0)
{
name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
}
-
+
if (name != NULL && !used)
{
gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar));
egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name);
- gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
+ gtk_drag_finish (context, TRUE,
+ gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
}
else
- {
- gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
+ {
+ gtk_drag_finish (context, FALSE,
+ gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
}
}
-
+
g_free (name);
}
gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
return TRUE;
}
-
+
return FALSE;
}
etoolbar->priv->dnd_pending++;
gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
}
-
+
/* If a highlight item is available, use it. */
else if (etoolbar->priv->dnd_toolitem)
{
etoolbar->priv->dnd_toolitem, ipos);
}
- gdk_drag_status (context, context->suggested_action, time);
+ gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);
return TRUE;
}
gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
dest_drag_types, G_N_ELEMENTS (dest_drag_types),
GDK_ACTION_MOVE | GDK_ACTION_COPY);
-
+
/* Add any specialist drag-drop abilities. */
targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
list = egg_toolbars_model_get_types (etoolbar->priv->model);
EggTbModelFlags flags;
gboolean visible;
gint i;
-
+
visible = gtk_toggle_action_get_active (action);
for (i = 0; i < priv->visibility_actions->len; i++)
if (g_ptr_array_index (priv->visibility_actions, i) == action)
break;
-
+
g_return_if_fail (i < priv->visibility_actions->len);
-
- dock = get_dock_nth (etoolbar, i);
+
+ dock = get_dock_nth (etoolbar, i);
if (visible)
{
gtk_widget_show (dock);
{
gtk_widget_hide (dock);
}
-
+
if (priv->save_hidden)
- {
+ {
flags = egg_toolbars_model_get_flags (priv->model, i);
-
+
if (visible)
{
flags &= ~(EGG_TB_MODEL_HIDDEN);
{
flags |= (EGG_TB_MODEL_HIDDEN);
}
-
+
egg_toolbars_model_set_flags (priv->model, i, flags);
}
}
gboolean showing;
char action_name[40];
char *action_label;
- char *tmp;
-
+ char *tmp;
+
if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
priv->visibility_paths == NULL || priv->actions == NULL)
{
{
priv->visibility_actions = g_ptr_array_new ();
}
-
+
if (priv->visibility_id != 0)
{
gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
- }
-
+ }
+
priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
-
+
+#if GTK_CHECK_VERSION(2,20,0)
+ showing = gtk_widget_get_visible (GTK_WIDGET (etoolbar));
+#else
showing = GTK_WIDGET_VISIBLE (etoolbar);
-
+#endif
+
n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
for (i = 0; i < n_toolbars; i++)
{
{
g_string_append (string, " ...");
}
-
+
tmp = g_string_free (string, FALSE);
for (j = 0, k = 0; tmp[j]; j++)
{
* please remove. */
action_label = g_strdup_printf (_("Show ā_%sā"), tmp);
g_free (tmp);
-
+
sprintf(action_name, "ToolbarToggle%d", i);
-
+
if (i >= priv->visibility_actions->len)
{
action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
g_object_set (action, "label", action_label, NULL);
}
- gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
+ gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
& EGG_TB_MODEL_NOT_REMOVABLE) == 0);
gtk_action_set_sensitive (GTK_ACTION (action), showing);
+#if GTK_CHECK_VERSION(2,20,0)
+ gtk_toggle_action_set_active (action, gtk_widget_get_visible
+ (get_dock_nth (etoolbar, i)));
+#else
gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
(get_dock_nth (etoolbar, i)));
-
+#endif
+
for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
{
gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
(const char *)list->data, action_name, action_name,
GTK_UI_MANAGER_MENUITEM, FALSE);
}
-
+
g_free (action_label);
}
-
+
gtk_ui_manager_ensure_update (priv->manager);
-
+
while (i < priv->visibility_actions->len)
{
action = g_ptr_array_index (priv->visibility_actions, i);
gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
g_signal_connect (toolbar, "drag_drop",
- G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
+ G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
g_signal_connect (toolbar, "drag_motion",
G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
g_signal_connect (toolbar, "drag_leave",
G_CALLBACK (popup_context_menu_cb), etoolbar);
configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
-
+
return hbox;
}
toolbar = etoolbar->priv->fixed_toolbar;
dock = get_dock_nth (etoolbar, 0);
- if (dock && toolbar->parent != NULL)
+ if (dock && gtk_widget_get_parent (toolbar) != NULL)
{
gtk_container_remove (GTK_CONTAINER (dock), toolbar);
}
toolbar = etoolbar->priv->fixed_toolbar;
dock = get_dock_nth (etoolbar, 0);
- if (dock && toolbar && toolbar->parent == NULL)
+ if (dock && toolbar && gtk_widget_get_parent (toolbar) == NULL)
{
gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
gtk_widget_show (toolbar);
-
+
gtk_widget_set_size_request (dock, -1, -1);
gtk_widget_queue_resize_no_redraw (dock);
}
gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
gtk_widget_show_all (dock);
-
+
update_fixed (etoolbar);
toolbar_visibility_refresh (etoolbar);
gtk_widget_destroy (dock);
update_fixed (etoolbar);
-
+
toolbar_visibility_refresh (etoolbar);
}
toolbar = get_toolbar_nth (etoolbar, tpos);
item = create_item_from_position (etoolbar, tpos, ipos);
if (item == NULL) return;
-
+
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
-
+
connect_widget_signals (GTK_WIDGET (item), etoolbar);
configure_item_tooltip (item);
configure_item_cursor (item, etoolbar);
configure_item_sensitivity (item, etoolbar);
-
+
dock = get_dock_nth (etoolbar, tpos);
gtk_widget_set_size_request (dock, -1, -1);
gtk_widget_queue_resize_no_redraw (dock);
EggEditableToolbar *etoolbar)
{
EggEditableToolbarPrivate *priv = etoolbar->priv;
-
+
GtkWidget *toolbar;
GtkWidget *item;
if (item)
{
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
-
+
connect_widget_signals (GTK_WIDGET (item), etoolbar);
configure_item_tooltip (item);
configure_item_sensitivity (item, etoolbar);
priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
priv->save_hidden = TRUE;
-
+
g_signal_connect (etoolbar, "notify::visible",
G_CALLBACK (toolbar_visibility_refresh), NULL);
}
priv->visibility_paths = NULL;
}
+ g_free (priv->popup_path);
+ priv->popup_path = NULL;
+
if (priv->manager != NULL)
{
if (priv->visibility_id)
priv->model = NULL;
}
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->dispose (object);
}
static void
{ "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
};
-
+
etoolbar->priv->manager = g_object_ref (manager);
etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
gboolean editable;
etoolbar->priv->selected = widget;
-
+
toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
-
+
if(toolbar != NULL)
{
gint tpos = get_toolbar_position (etoolbar, toolbar);
{
editable = FALSE;
}
-
+
gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
priv->edit_mode--;
}
i *= priv->edit_mode;
-
+
if (i == 0)
{
for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
{
GtkWidget *toolbar;
-
+
toolbar = get_toolbar_nth (etoolbar, i);
n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
egg_toolbars_model_remove_toolbar (priv->model, i);
}
else
- {
+ {
for (l = 0; l < n_items; l++)
{
GtkToolItem *item;
-
+
item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
-
+
configure_item_cursor (item, etoolbar);
configure_item_sensitivity (item, etoolbar);
}
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
object_class->dispose = egg_editable_toolbar_dispose;
object_class->set_property = egg_editable_toolbar_set_property;
object_class->get_property = egg_editable_toolbar_get_property;
}
#define DEFAULT_ICON_HEIGHT 20
-#define DEFAULT_ICON_WIDTH 0
-
-static void
-fake_expose_widget (GtkWidget *widget,
- GdkPixmap *pixmap)
-{
- GdkWindow *tmp_window;
- GdkEventExpose event;
-
- event.type = GDK_EXPOSE;
- event.window = pixmap;
- event.send_event = FALSE;
- event.area = widget->allocation;
- event.region = NULL;
- event.count = 0;
-
- tmp_window = widget->window;
- widget->window = pixmap;
- gtk_widget_send_expose (widget, (GdkEvent *) &event);
- widget->window = tmp_window;
-}
/* We should probably experiment some more with this.
* Right now the rendered icon is pretty good for most
{
GtkWidget *window;
GdkPixbuf *pixbuf;
- GtkRequisition requisition;
- GtkAllocation allocation;
- GdkPixmap *pixmap;
- GdkVisual *visual;
- gint icon_width;
gint icon_height;
+ GdkScreen *screen;
- icon_width = DEFAULT_ICON_WIDTH;
+ screen = gtk_widget_get_screen (widget);
- if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_default (),
+ if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
GTK_ICON_SIZE_LARGE_TOOLBAR,
- NULL,
+ NULL,
&icon_height))
{
icon_height = DEFAULT_ICON_HEIGHT;
}
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
+ window = gtk_offscreen_window_new ();
+ /* Set the width to -1 as we want the separator to be as thin as possible. */
+ gtk_widget_set_size_request (widget, -1, icon_height);
+
gtk_container_add (GTK_CONTAINER (window), widget);
- gtk_widget_realize (window);
- gtk_widget_show (widget);
- gtk_widget_realize (widget);
- gtk_widget_map (widget);
-
- /* Gtk will never set the width or height of a window to 0. So setting the width to
- * 0 and than getting it will provide us with the minimum width needed to render
- * the icon correctly, without any additional window background noise.
- * This is needed mostly for pixmap based themes.
- */
- gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
- gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
-
- gtk_widget_size_request (window, &requisition);
- allocation.x = 0;
- allocation.y = 0;
- allocation.width = icon_width;
- allocation.height = icon_height;
- gtk_widget_size_allocate (window, &allocation);
- gtk_widget_size_request (window, &requisition);
-
- /* Create a pixmap */
- visual = gtk_widget_get_visual (window);
- pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, visual->depth);
- gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
-
- /* Draw the window */
- gtk_widget_ensure_style (window);
- g_assert (window->style);
- g_assert (window->style->font_desc);
-
- fake_expose_widget (window, pixmap);
- fake_expose_widget (widget, pixmap);
-
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
- gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
+ gtk_widget_show_all (window);
+ /* Process the waiting events to have the widget actually drawn */
+ gdk_window_process_updates (gtk_widget_get_window (window), TRUE);
+ pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
gtk_widget_destroy (window);
return pixbuf;
}
static GdkPixbuf *
-new_separator_pixbuf ()
+new_separator_pixbuf (void)
{
GtkWidget *separator;
GdkPixbuf *pixbuf;