/*
- * Copyright (C) 2003-2004 Marco Pesenti Gritti
- * Copyright (C) 2004 Christian Persch
+ * Copyright (C) 2003, 2004 Marco Pesenti Gritti
+ * Copyright (C) 2003, 2004, 2005 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* $Id$
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include "egg-editable-toolbar.h"
#include "egg-toolbars-model.h"
#define MIN_TOOLBAR_HEIGHT 20
-static GtkTargetEntry dest_drag_types[] = {
+static const GtkTargetEntry dest_drag_types[] = {
{EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
};
-static int n_dest_drag_types = G_N_ELEMENTS (dest_drag_types);
enum
{
#define EGG_EDITABLE_TOOLBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarPrivate))
-struct EggEditableToolbarPrivate
+struct _EggEditableToolbarPrivate
{
GtkUIManager *manager;
EggToolbarsModel *model;
gboolean edit_mode;
GtkWidget *selected_toolbar;
- GtkToolItem *fixed;
GtkWidget *fixed_toolbar;
gboolean pending;
GType
egg_editable_toolbar_get_type (void)
{
- static GType egg_editable_toolbar_type = 0;
+ static GType type = 0;
- if (egg_editable_toolbar_type == 0)
+ if (G_UNLIKELY (type == 0))
{
static const GTypeInfo our_info = {
sizeof (EggEditableToolbarClass),
(GInstanceInitFunc) egg_editable_toolbar_init
};
- egg_editable_toolbar_type = g_type_register_static (GTK_TYPE_VBOX,
- "EggEditableToolbar",
- &our_info, 0);
+ type = g_type_register_static (GTK_TYPE_VBOX,
+ "EggEditableToolbar",
+ &our_info, 0);
}
- return egg_editable_toolbar_type;
+ return type;
}
static int
}
gtk_selection_data_set (selection_data,
- selection_data->target, 8, (unsigned char *)target, strlen (target));
+ selection_data->target, 8,
+ (const guchar *)target, strlen (target));
g_free (target);
}
target = gtk_drag_dest_find_target (widget, context, NULL);
type = egg_toolbars_model_get_item_type (etoolbar->priv->model, target);
- id = egg_toolbars_model_get_item_id (etoolbar->priv->model, type, (char *)selection_data->data);
+ id = egg_toolbars_model_get_item_id (etoolbar->priv->model, type,
+ (const char*)selection_data->data);
/* This function can be called for two reasons
*
pos = gtk_toolbar_get_drop_index (GTK_TOOLBAR (widget), x, y);
toolbar_pos = get_toolbar_position (etoolbar, widget);
- if (data_is_separator ((char *)selection_data->data))
+ if (data_is_separator ((const char*)selection_data->data))
{
egg_toolbars_model_add_separator (etoolbar->priv->model,
toolbar_pos, pos);
gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
gtk_drag_dest_set (toolbar, 0,
- dest_drag_types, n_dest_drag_types,
+ dest_drag_types, G_N_ELEMENTS (dest_drag_types),
GDK_ACTION_MOVE | GDK_ACTION_COPY);
g_signal_connect (toolbar, "drag_drop",
set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
{
g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
- gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar), style);
+ gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
+ style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
}
static void
flags = egg_toolbars_model_get_flags (model, position);
toolbar = get_toolbar_nth (t, position);
- if (flags & EGG_TB_MODEL_ICONS_ONLY)
+ if (flags & EGG_TB_MODEL_ICONS)
{
style = GTK_TOOLBAR_ICONS;
}
- else if (flags & EGG_TB_MODEL_TEXT_ONLY)
+ else if (flags & EGG_TB_MODEL_TEXT)
{
style = GTK_TOOLBAR_TEXT;
}
- else if (flags & EGG_TB_MODEL_ICONS_TEXT)
+ else if (flags & EGG_TB_MODEL_BOTH)
{
style = GTK_TOOLBAR_BOTH;
}
- else if (flags & EGG_TB_MODEL_ICONS_TEXT_HORIZ)
+ else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
{
style = GTK_TOOLBAR_BOTH_HORIZ;
}
{
gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
- gtk_widget_show_all (toolbar);
+ gtk_widget_show (toolbar);
+
+ gtk_widget_set_size_request (dock, -1, -1);
+ gtk_widget_queue_resize_no_redraw (dock);
}
}
{
GtkWidget *toolbar;
+ if (position == 0 && t->priv->fixed_toolbar != NULL)
+ {
+ unparent_fixed (t);
+ }
+
toolbar = get_dock_nth (t, position);
gtk_widget_destroy (toolbar);
for (i = 0; i < n_toolbars; i++)
{
GtkWidget *toolbar, *dock;
- EggTbModelFlags flags;
dock = create_dock (t);
gtk_box_pack_start (GTK_BOX (t), dock, TRUE, TRUE, 0);
toolbar = get_toolbar_nth (t, i);
- flags = egg_toolbars_model_get_flags (model, i);
- if (flags & EGG_TB_MODEL_ICONS_ONLY)
- {
- gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
- if (i == 0 && t->priv->fixed_toolbar)
- {
- set_fixed_style (t, GTK_TOOLBAR_ICONS);
- }
- }
-
n_items = egg_toolbars_model_n_items (model, i);
for (l = 0; l < n_items; l++)
{
}
update_fixed (t);
+
+ /* apply styles */
+ for (i = 0; i < n_toolbars; i ++)
+ {
+ toolbar_changed_cb (model, i, t);
+ }
}
static void
void
egg_editable_toolbar_set_fixed (EggEditableToolbar *toolbar,
- GtkToolItem *fixed)
+ GtkToolbar *fixed_toolbar)
{
g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (toolbar));
- g_return_if_fail (!fixed || GTK_IS_TOOL_ITEM (fixed));
+ g_return_if_fail (!fixed_toolbar || GTK_IS_TOOLBAR (fixed_toolbar));
- if (!toolbar->priv->fixed_toolbar)
+ if (toolbar->priv->fixed_toolbar)
{
- toolbar->priv->fixed_toolbar = gtk_toolbar_new ();
- gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar->priv->fixed_toolbar), FALSE);
- g_object_ref (toolbar->priv->fixed_toolbar);
- gtk_object_sink (GTK_OBJECT (toolbar->priv->fixed_toolbar));
+ unparent_fixed (toolbar);
+ g_object_unref (toolbar->priv->fixed_toolbar);
+ toolbar->priv->fixed_toolbar = NULL;
}
- if (toolbar->priv->fixed)
+ if (fixed_toolbar)
{
- gtk_container_remove (GTK_CONTAINER (toolbar->priv->fixed_toolbar),
- GTK_WIDGET (toolbar->priv->fixed));
- g_object_unref (toolbar->priv->fixed);
+ toolbar->priv->fixed_toolbar = GTK_WIDGET (fixed_toolbar);
+ gtk_toolbar_set_show_arrow (fixed_toolbar, FALSE);
+ g_object_ref (fixed_toolbar);
+ gtk_object_sink (GTK_OBJECT (fixed_toolbar));
}
- toolbar->priv->fixed = fixed;
-
- if (fixed)
- {
- g_object_ref (fixed);
- gtk_object_sink (GTK_OBJECT (fixed));
-
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar->priv->fixed_toolbar), fixed, 0);
- }
+ update_fixed (toolbar);
}
void
/*
- * Copyright (C) 2003-2004 Marco Pesenti Gritti
- * Copyright (C) 2004 Christian Persch
+ * Copyright (C) 2003, 2004 Marco Pesenti Gritti
+ * Copyright (C) 2003, 2004, 2005 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
G_BEGIN_DECLS
-typedef struct EggEditableToolbarClass EggEditableToolbarClass;
-
#define EGG_TYPE_EDITABLE_TOOLBAR (egg_editable_toolbar_get_type ())
#define EGG_EDITABLE_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbar))
#define EGG_EDITABLE_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarClass))
#define EGG_IS_EDITABLE_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_EDITABLE_TOOLBAR))
#define EGG_EDITABLE_TOOLBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarClass))
+typedef struct _EggEditableToolbar EggEditableToolbar;
+typedef struct _EggEditableToolbarPrivate EggEditableToolbarPrivate;
+typedef struct _EggEditableToolbarClass EggEditableToolbarClass;
-typedef struct EggEditableToolbar EggEditableToolbar;
-typedef struct EggEditableToolbarPrivate EggEditableToolbarPrivate;
-
-struct EggEditableToolbar
+struct _EggEditableToolbar
{
GtkVBox parent_object;
EggEditableToolbarPrivate *priv;
};
-struct EggEditableToolbarClass
+struct _EggEditableToolbarClass
{
GtkVBoxClass parent_class;
gint n_targets,
const char *toolbar_name);
void egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
- GtkToolItem *fixed);
+ GtkToolbar *fixed_toolbar);
/* Private Functions */
* $Id$
*/
+#include "config.h"
+
#include "egg-toolbar-editor.h"
#include "egg-editable-toolbar.h"
#include "eggintl.h"
#include <gtk/gtkstock.h>
#include <gtk/gtkhbox.h>
-static GtkTargetEntry dest_drag_types[] = {
+static const GtkTargetEntry dest_drag_types[] = {
{EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
};
-static int n_dest_drag_types = G_N_ELEMENTS (dest_drag_types);
-static GtkTargetEntry source_drag_types[] = {
+static const GtkTargetEntry source_drag_types[] = {
{EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
};
-static int n_source_drag_types = G_N_ELEMENTS (source_drag_types);
static void egg_toolbar_editor_class_init (EggToolbarEditorClass *klass);
static void egg_toolbar_editor_init (EggToolbarEditor *t);
GType
egg_toolbar_editor_get_type (void)
{
- static GType egg_toolbar_editor_type = 0;
+ static GType type = 0;
- if (egg_toolbar_editor_type == 0)
+ if (G_UNLIKELY (type == 0))
{
static const GTypeInfo our_info = {
sizeof (EggToolbarEditorClass),
(GInstanceInitFunc) egg_toolbar_editor_init
};
- egg_toolbar_editor_type = g_type_register_static (GTK_TYPE_VBOX,
- "EggToolbarEditor",
- &our_info, 0);
+ type = g_type_register_static (GTK_TYPE_VBOX,
+ "EggToolbarEditor",
+ &our_info, 0);
}
- return egg_toolbar_editor_type;
+ return type;
}
static gint
}
gtk_selection_data_set (selection_data,
- selection_data->target, 8, (unsigned char *)target, strlen (target));
+ selection_data->target, 8,
+ (const guchar *)target, strlen (target));
}
static gchar *
gtk_widget_show (event_box);
gtk_drag_source_set (event_box,
GDK_BUTTON1_MASK,
- source_drag_types, n_source_drag_types, action);
+ source_drag_types, G_N_ELEMENTS (source_drag_types), action);
g_signal_connect (event_box, "drag_data_get",
G_CALLBACK (drag_data_get_cb), editor);
g_signal_connect (event_box, "drag_data_delete",
gtk_scrolled_window_add_with_viewport
(GTK_SCROLLED_WINDOW (editor->priv->scrolled_window), table);
gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL,
- dest_drag_types, n_dest_drag_types, GDK_ACTION_MOVE);
+ dest_drag_types, G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
g_signal_connect (table, "drag_data_received",
G_CALLBACK (editor_drag_data_received_cb), editor);
setup_editor (EggToolbarEditor *editor)
{
GtkWidget *scrolled_window;
- GtkWidget *label_hbox;
- GtkWidget *image;
- GtkWidget *label;
-
- g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor));
gtk_container_set_border_width (GTK_CONTAINER (editor), 12);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (editor), scrolled_window, TRUE, TRUE, 0);
- label_hbox = gtk_hbox_new (FALSE, 6);
- gtk_widget_show (label_hbox);
- gtk_box_pack_start (GTK_BOX (editor), label_hbox, FALSE, FALSE, 0);
- image =
- gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
- gtk_widget_show (image);
- gtk_box_pack_start (GTK_BOX (label_hbox), image, FALSE, FALSE, 0);
- label = gtk_label_new (_("Drag an item onto the toolbars above to add it, "
- "from the toolbars in the items table to remove it."));
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_widget_show (label);
- gtk_box_pack_start (GTK_BOX (label_hbox), label, FALSE, TRUE, 0);
}
static void
{
while (child)
{
- if (xmlStrEqual (child->name, (xmlChar *)"toolitem"))
+ if (xmlStrEqual (child->name, (const xmlChar*) "toolitem"))
{
xmlChar *name;
- name = xmlGetProp (child, (xmlChar *)"name");
- egg_toolbar_editor_add_action (t, (char *)name);
+ name = xmlGetProp (child, (const xmlChar*) "name");
+ egg_toolbar_editor_add_action (t, (const char*)name);
xmlFree (name);
}
child = child->next;
while (child)
{
- if (xmlStrEqual (child->name, (xmlChar *)"available"))
+ if (xmlStrEqual (child->name, (const xmlChar*) "available"))
{
parse_item_list (editor, child->children);
}
* $Id$
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include "egg-toolbars-model.h"
#include "eggmarshalers.h"
{
static GType type = 0;
- if (type == 0)
+ if (G_UNLIKELY (type == 0))
{
static const GTypeInfo our_info = {
sizeof (EggToolbarsModelClass),
tl = t->priv->toolbars;
xmlIndentTreeOutput = TRUE;
- doc = xmlNewDoc ((xmlChar *)"1.0");
- doc->children = xmlNewDocNode (doc, NULL, (xmlChar *)"toolbars", NULL);
+ doc = xmlNewDoc ((const xmlChar*) "1.0");
+ doc->children = xmlNewDocNode (doc, NULL, (const xmlChar*) "toolbars", NULL);
for (l1 = tl->children; l1 != NULL; l1 = l1->next)
{
xmlNodePtr tnode;
EggToolbarsToolbar *toolbar = l1->data;
- tnode = xmlNewChild (doc->children, NULL, (xmlChar *)"toolbar", NULL);
- xmlSetProp (tnode, (xmlChar *)"name", (xmlChar *)toolbar->name);
+ tnode = xmlNewChild (doc->children, NULL, (const xmlChar*) "toolbar", NULL);
+ xmlSetProp (tnode, (const xmlChar*) "name", (const xmlChar*) toolbar->name);
for (l2 = l1->children; l2 != NULL; l2 = l2->next)
{
if (item->separator)
{
- node = xmlNewChild (tnode, NULL, (xmlChar *)"separator", NULL);
+ node = xmlNewChild (tnode, NULL, (const xmlChar*) "separator", NULL);
}
else
{
char *data;
- node = xmlNewChild (tnode, NULL, (xmlChar *)"toolitem", NULL);
+ node = xmlNewChild (tnode, NULL, (const xmlChar*) "toolitem", NULL);
data = egg_toolbars_model_get_item_data (t, item->type, item->id);
- xmlSetProp (node, (xmlChar *)"type", (xmlChar *)item->type);
- xmlSetProp (node, (xmlChar *)"name", (xmlChar *)data);
+ xmlSetProp (node, (const xmlChar*) "type", (const xmlChar*) item->type);
+ xmlSetProp (node, (const xmlChar*) "name", (const xmlChar*) data);
g_free (data);
}
}
doc = egg_toolbars_model_to_xml (t);
root = xmlDocGetRootElement (doc);
- xmlSetProp (root, (xmlChar *)"version", (xmlChar *)version);
+ xmlSetProp (root, (const xmlChar*) "version", (const xmlChar*) version);
safe_save_xml (xml_file, doc);
xmlFreeDoc (doc);
}
{
while (child)
{
- if (xmlStrEqual (child->name, (xmlChar *)"toolitem"))
+ if (xmlStrEqual (child->name, (const xmlChar*) "toolitem"))
{
xmlChar *name, *type;
char *id;
- name = xmlGetProp (child, (xmlChar *)"name");
- type = xmlGetProp (child, (xmlChar *)"type");
+ name = xmlGetProp (child, (const xmlChar*) "name");
+ type = xmlGetProp (child, (const xmlChar*) "type");
if (type == NULL)
{
- type = xmlStrdup ((xmlChar *)EGG_TOOLBAR_ITEM_TYPE);
+ type = xmlCharStrdup (EGG_TOOLBAR_ITEM_TYPE);
}
if (name != NULL && name[0] != '\0' && type != NULL)
{
- id = egg_toolbars_model_get_item_id (t, (char *)type, (char *)name);
+ id = egg_toolbars_model_get_item_id (t, (const char*)type, (const char*)name);
if (id != NULL)
{
- egg_toolbars_model_add_item (t, position, -1, id, (char *)type);
+ egg_toolbars_model_add_item (t, position, -1, id, (const char*)type);
}
g_free (id);
}
xmlFree (name);
xmlFree (type);
}
- else if (xmlStrEqual (child->name, (xmlChar *)"separator"))
+ else if (xmlStrEqual (child->name, (const xmlChar*) "separator"))
{
egg_toolbars_model_add_separator (t, position, -1);
}
{
while (child)
{
- if (xmlStrEqual (child->name, (xmlChar *)"toolbar"))
+ if (xmlStrEqual (child->name, (const xmlChar*) "toolbar"))
{
xmlChar *name;
xmlChar *style;
int position;
- name = xmlGetProp (child, (xmlChar *)"name");
- position = egg_toolbars_model_add_toolbar (t, -1, (char *)name);
+ name = xmlGetProp (child, (const xmlChar*) "name");
+ position = egg_toolbars_model_add_toolbar (t, -1, (const char*) name);
xmlFree (name);
- style = xmlGetProp (child, (xmlChar *)"style");
- if (style && xmlStrEqual (style, (xmlChar *)"icons-only"))
+ style = xmlGetProp (child, (const xmlChar*) "style");
+ if (style && xmlStrEqual (style, (const xmlChar*) "icons-only"))
{
/* FIXME: use toolbar position instead of 0 */
- egg_toolbars_model_set_flags (t, 0, EGG_TB_MODEL_ICONS_ONLY);
+ egg_toolbars_model_set_flags (t, 0, EGG_TB_MODEL_ICONS);
}
xmlFree (style);
* 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.
+ *
+ * $Id$
*/
#ifndef EGG_TOOLBARS_MODEL_H
G_BEGIN_DECLS
-
#define EGG_TYPE_TOOLBARS_MODEL (egg_toolbars_model_get_type ())
#define EGG_TOOLBARS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModel))
#define EGG_TOOLBARS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModelClass))
typedef enum
{
EGG_TB_MODEL_NOT_REMOVABLE = 1 << 0,
- EGG_TB_MODEL_ICONS_ONLY = 1 << 1,
- EGG_TB_MODEL_TEXT_ONLY = 1 << 2,
- EGG_TB_MODEL_ICONS_TEXT = 1 << 3,
- EGG_TB_MODEL_ICONS_TEXT_HORIZ = 1 << 4,
+ EGG_TB_MODEL_BOTH = 1 << 1,
+ EGG_TB_MODEL_BOTH_HORIZ = 1 << 2,
+ EGG_TB_MODEL_ICONS = 1 << 3,
+ EGG_TB_MODEL_TEXT = 1 << 4,
+ EGG_TB_MODEL_STYLES_MASK = 0x1F,
EGG_TB_MODEL_ACCEPT_ITEMS_ONLY = 1 << 5
} EggTbModelFlags;
const char *type);
};
+GType egg_toolbars_model_flags_get_type (void);
GType egg_toolbars_model_get_type (void);
EggToolbarsModel *egg_toolbars_model_new (void);
gboolean egg_toolbars_model_load (EggToolbarsModel *model,