marlin r1300 - in trunk/src: ephy libegg other
- From: iain svn gnome org
- To: svn-commits-list gnome org
- Subject: marlin r1300 - in trunk/src: ephy libegg other
- Date: Thu, 9 Oct 2008 00:05:55 +0000 (UTC)
Author: iain
Date: Thu Oct 9 00:05:55 2008
New Revision: 1300
URL: http://svn.gnome.org/viewvc/marlin?rev=1300&view=rev
Log:
Finish the GObject restructuring
Modified:
trunk/src/ephy/ephy-toolbars-model.c
trunk/src/libegg/egg-editable-toolbar.c
trunk/src/libegg/egg-toolbar-editor.c
trunk/src/libegg/egg-toolbars-model.c
trunk/src/other/gtkvumeter.c
Modified: trunk/src/ephy/ephy-toolbars-model.c
==============================================================================
--- trunk/src/ephy/ephy-toolbars-model.c (original)
+++ trunk/src/ephy/ephy-toolbars-model.c Thu Oct 9 00:05:55 2008
@@ -32,7 +32,7 @@
#define EPHY_TOOLBARS_XML_FILE "marlin-toolbars-2.xml"
#define EPHY_TOOLBARS_XML_VERSION "1.0"
-#define EPHY_TOOLBARS_MODEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TOOLBARS_MODEL, EphyToolbarsModelPrivate))
+#define GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TOOLBARS_MODEL, EphyToolbarsModelPrivate))
struct EphyToolbarsModelPrivate
{
@@ -40,36 +40,21 @@
guint timeout;
};
-static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass);
-static void ephy_toolbars_model_init (EphyToolbarsModel *model);
+G_DEFINE_TYPE (EphyToolbarsModel, ephy_toolbars_model, EGG_TYPE_TOOLBARS_MODEL);
-static GObjectClass *parent_class = NULL;
-
-GType
-ephy_toolbars_model_get_type (void)
+static void
+finalize (GObject *object)
{
- static GType type = 0;
-
- if (type == 0)
- {
- static const GTypeInfo our_info = {
- sizeof (EphyToolbarsModelClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) ephy_toolbars_model_class_init,
- NULL,
- NULL, /* class_data */
- sizeof (EphyToolbarsModel),
- 0, /* n_preallocs */
- (GInstanceInitFunc) ephy_toolbars_model_init
- };
-
- type = g_type_register_static (EGG_TYPE_TOOLBARS_MODEL,
- "EphyToolbarsModel",
- &our_info, 0);
+ EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (object);
+
+ if (model->priv->timeout != 0) {
+ g_source_remove (model->priv->timeout);
+ model->priv->timeout = 0;
}
- return type;
+ g_free (model->priv->xml_file);
+
+ G_OBJECT_CLASS (ephy_toolbars_model_parent_class)->finalize (object);
}
static gboolean
@@ -87,10 +72,30 @@
}
static void
+dispose (GObject *object)
+{
+ EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (object);
+
+ save_changes_idle (model);
+
+ G_OBJECT_CLASS (ephy_toolbars_model_parent_class)->dispose (object);
+}
+
+static void
+ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *) klass;
+
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+
+ g_type_class_add_private (object_class, sizeof (EphyToolbarsModelPrivate));
+}
+
+static void
save_changes (EphyToolbarsModel *model)
{
- if (model->priv->timeout == 0)
- {
+ if (model->priv->timeout == 0) {
model->priv->timeout =
g_idle_add ((GSourceFunc) save_changes_idle, model);
}
@@ -105,13 +110,11 @@
n_toolbars = egg_toolbars_model_n_toolbars (eggmodel);
- if (n_toolbars <= 1)
- {
+ if (n_toolbars <= 1) {
flag |= EGG_TB_MODEL_NOT_REMOVABLE;
}
- for (i = 0; i < n_toolbars; i++)
- {
+ for (i = 0; i < n_toolbars; i++) {
const char *t_name;
EggTbModelFlags flags;
@@ -135,14 +138,12 @@
n_toolbars = egg_toolbars_model_n_toolbars (model);
- for (i = 0; i < n_toolbars; i++)
- {
+ for (i = 0; i < n_toolbars; i++) {
const char *t_name;
t_name = egg_toolbars_model_toolbar_nth (model, i);
g_return_val_if_fail (t_name != NULL, -1);
- if (strcmp (name, t_name) == 0)
- {
+ if (strcmp (name, t_name) == 0) {
return i;
}
}
@@ -158,8 +159,7 @@
success = egg_toolbars_model_load (eggmodel, model->priv->xml_file);
#if 0
- if (success == FALSE)
- {
+ if (success == FALSE) {
char *old_xml;
old_xml = g_build_filename (marlin_dot_dir (),
"marlin-toolbars.xml",
@@ -170,15 +170,13 @@
#endif
/* Still no success, load the default toolbars */
- if (success == FALSE)
- {
+ if (success == FALSE) {
success = egg_toolbars_model_load
(eggmodel, marlin_file ("toolbars.xml"));
}
/* Ensure we have at least 1 toolbar */
- if (egg_toolbars_model_n_toolbars (eggmodel) < 1)
- {
+ if (egg_toolbars_model_n_toolbars (eggmodel) < 1) {
egg_toolbars_model_add_toolbar (eggmodel, 0, "DefaultToolbar");
}
}
@@ -186,7 +184,7 @@
static void
ephy_toolbars_model_init (EphyToolbarsModel *model)
{
- model->priv = EPHY_TOOLBARS_MODEL_GET_PRIVATE (model);
+ model->priv = GET_PRIVATE (model);
model->priv->xml_file = g_build_filename (marlin_dot_dir (),
EPHY_TOOLBARS_XML_FILE,
@@ -202,44 +200,6 @@
G_CALLBACK (update_flags_and_save_changes), NULL);
}
-static void
-ephy_toolbars_model_dispose (GObject *object)
-{
- EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (object);
-
- save_changes_idle (model);
-
- G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-static void
-ephy_toolbars_model_finalize (GObject *object)
-{
- EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (object);
-
- if (model->priv->timeout != 0)
- {
- g_source_remove (model->priv->timeout);
- model->priv->timeout = 0;
- }
-
- g_free (model->priv->xml_file);
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static void
-ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->dispose = ephy_toolbars_model_dispose;
- object_class->finalize = ephy_toolbars_model_finalize;
-
- g_type_class_add_private (object_class, sizeof (EphyToolbarsModelPrivate));
-}
EggToolbarsModel *
ephy_toolbars_model_new (void)
Modified: trunk/src/libegg/egg-editable-toolbar.c
==============================================================================
--- trunk/src/libegg/egg-editable-toolbar.c (original)
+++ trunk/src/libegg/egg-editable-toolbar.c Thu Oct 9 00:05:55 2008
@@ -42,163 +42,132 @@
#include <string.h>
#include <marlin/marlin-cursors.h>
-static void egg_editable_toolbar_class_init (EggEditableToolbarClass *klass);
-static void egg_editable_toolbar_init (EggEditableToolbar *t);
-static void egg_editable_toolbar_finalize (GObject *object);
#define MIN_TOOLBAR_HEIGHT 20
static GtkTargetEntry source_drag_types[] = {
- {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
+ {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
};
static int n_source_drag_types = G_N_ELEMENTS (source_drag_types);
static GtkTargetEntry dest_drag_types[] = {
- {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
+ {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
};
static int n_dest_drag_types = G_N_ELEMENTS (dest_drag_types);
enum
{
- PROP_0,
- PROP_TOOLBARS_MODEL,
- PROP_MENU_MERGE
+ PROP_0,
+ PROP_TOOLBARS_MODEL,
+ PROP_MENU_MERGE
};
enum
{
- ACTION_REQUEST,
- LAST_SIGNAL
+ ACTION_REQUEST,
+ LAST_SIGNAL
};
static guint egg_editable_toolbar_signals[LAST_SIGNAL] = { 0 };
-static GObjectClass *parent_class = NULL;
+G_DEFINE_TYPE (EggEditableToolbar, egg_editable_toolbar, GTK_TYPE_VBOX);
-#define EGG_EDITABLE_TOOLBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarPrivate))
+#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarPrivate))
struct EggEditableToolbarPrivate
{
- GtkUIManager *merge;
- EggToolbarsModel *model;
- gboolean edit_mode;
- GtkWidget *selected_toolbar;
- GtkWidget *fixed_toolbar;
-
- gboolean pending;
- GtkToolbar *target_toolbar;
- GtkWidget *dragged_item;
+ GtkUIManager *merge;
+ EggToolbarsModel *model;
+ gboolean edit_mode;
+ GtkWidget *selected_toolbar;
+ GtkWidget *fixed_toolbar;
+
+ gboolean pending;
+ GtkToolbar *target_toolbar;
+ GtkWidget *dragged_item;
};
-GType
-egg_editable_toolbar_get_type (void)
-{
- static GType egg_editable_toolbar_type = 0;
-
- if (egg_editable_toolbar_type == 0)
- {
- static 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
- };
-
- egg_editable_toolbar_type = g_type_register_static (GTK_TYPE_VBOX,
- "EggEditableToolbar",
- &our_info, 0);
- }
-
- return egg_editable_toolbar_type;
-}
-
static int
get_toolbar_position (EggEditableToolbar *etoolbar, GtkWidget *toolbar)
{
- GList *l;
- int result;
+ GList *l;
+ int result;
- l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
- result = g_list_index (l, toolbar->parent);
- g_list_free (l);
+ l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
+ result = g_list_index (l, toolbar->parent);
+ g_list_free (l);
- return result;
+ return result;
}
static int
get_n_toolbars (EggEditableToolbar *etoolbar)
{
- GList *l;
- int result;
+ GList *l;
+ int result;
- l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
- result = g_list_length (l);
- g_list_free (l);
+ l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
+ result = g_list_length (l);
+ g_list_free (l);
- return result;
+ return result;
}
static GtkWidget *
get_dock_nth (EggEditableToolbar *etoolbar,
int position)
{
- GList *l;
- GtkWidget *result;
+ GList *l;
+ GtkWidget *result;
- l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
- result = g_list_nth_data (l, position);
- g_list_free (l);
+ l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
+ result = g_list_nth_data (l, position);
+ g_list_free (l);
- return result;
+ return result;
}
static GtkWidget *
get_toolbar_nth (EggEditableToolbar *etoolbar,
int position)
{
- GList *l;
- GtkWidget *dock;
- GtkWidget *result;
-
- dock = get_dock_nth (etoolbar, position);
- if (dock == NULL) {
- return NULL;
- }
-
- l = gtk_container_get_children (GTK_CONTAINER (dock));
- result = GTK_WIDGET (l->data);
- g_list_free (l);
+ GList *l;
+ GtkWidget *dock;
+ GtkWidget *result;
+
+ dock = get_dock_nth (etoolbar, position);
+ if (dock == NULL) {
+ return NULL;
+ }
+
+ l = gtk_container_get_children (GTK_CONTAINER (dock));
+ result = GTK_WIDGET (l->data);
+ g_list_free (l);
- return result;
+ return result;
}
static GtkAction *
find_action (EggEditableToolbar *t,
const char *name)
{
- GList *l;
- GtkAction *action = NULL;
+ GList *l;
+ GtkAction *action = NULL;
- l = gtk_ui_manager_get_action_groups (t->priv->merge);
+ l = gtk_ui_manager_get_action_groups (t->priv->merge);
- g_return_val_if_fail (EGG_IS_EDITABLE_TOOLBAR (t), NULL);
- g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (EGG_IS_EDITABLE_TOOLBAR (t), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
- for (; l != NULL; l = l->next)
- {
- GtkAction *tmp;
+ for (; l != NULL; l = l->next) {
+ GtkAction *tmp;
- tmp = gtk_action_group_get_action (GTK_ACTION_GROUP (l->data), name);
- if (tmp)
- action = tmp;
- }
+ tmp = gtk_action_group_get_action (GTK_ACTION_GROUP (l->data), name);
+ if (tmp)
+ action = tmp;
+ }
- return action;
+ return action;
}
static void
@@ -206,16 +175,16 @@
GdkDragContext *context,
EggEditableToolbar *etoolbar)
{
- int pos, toolbar_pos;
+ int pos, toolbar_pos;
- g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
+ g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
- pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget->parent),
- GTK_TOOL_ITEM (widget));
- toolbar_pos = get_toolbar_position (etoolbar, widget->parent);
+ pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget->parent),
+ GTK_TOOL_ITEM (widget));
+ toolbar_pos = get_toolbar_position (etoolbar, widget->parent);
- egg_toolbars_model_remove_item (etoolbar->priv->model,
- toolbar_pos, pos);
+ egg_toolbars_model_remove_item (etoolbar->priv->model,
+ toolbar_pos, pos);
}
static void
@@ -242,47 +211,42 @@
guint32 time,
EggEditableToolbar *etoolbar)
{
- GtkAction *action;
- const char *target;
+ GtkAction *action;
+ const char *target;
+
+ g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
- g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
+ action = GTK_ACTION (g_object_get_data (G_OBJECT (widget), "gtk-action"));
- action = GTK_ACTION (g_object_get_data (G_OBJECT (widget), "gtk-action"));
+ if (action){
+ target = gtk_action_get_name (action);
+ } else {
+ target = "separator";
+ }
- if (action)
- {
- target = gtk_action_get_name (action);
- }
- else
- {
- target = "separator";
- }
-
- gtk_selection_data_set (selection_data,
- selection_data->target, 8,
- (const guchar *) target, strlen (target));
+ gtk_selection_data_set (selection_data,
+ selection_data->target, 8,
+ (const guchar *) target, strlen (target));
}
static void
set_drag_cursor (GtkWidget *widget)
{
- if (widget->window)
- {
- GdkCursor *cursor;
-
- cursor = marlin_cursor_get (widget, HAND_OPEN);
- gdk_window_set_cursor (widget->window, cursor);
- gdk_cursor_unref (cursor);
- }
+ if (widget->window) {
+ GdkCursor *cursor;
+
+ cursor = marlin_cursor_get (widget, HAND_OPEN);
+ gdk_window_set_cursor (widget->window, cursor);
+ gdk_cursor_unref (cursor);
+ }
}
static void
unset_drag_cursor (GtkWidget *widget)
{
- if (widget->window)
- {
- gdk_window_set_cursor (widget->window, NULL);
- }
+ if (widget->window) {
+ gdk_window_set_cursor (widget->window, NULL);
+ }
}
static void
@@ -290,45 +254,39 @@
GtkAction *action,
gboolean is_separator)
{
- gtk_drag_source_set (item, GDK_BUTTON1_MASK,
- source_drag_types, n_source_drag_types,
- GDK_ACTION_MOVE);
-
- if (is_separator)
- {
- GtkWidget *icon;
- GdkPixbuf *pixbuf;
-
- icon = _egg_editable_toolbar_new_separator_image ();
- pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (icon));
- gtk_drag_source_set_icon_pixbuf (item, pixbuf);
- }
- else
- {
- const char *stock_id;
- GValue value = { 0, };
- GdkPixbuf *pixbuf;
-
- g_value_init (&value, G_TYPE_STRING);
- g_object_get_property (G_OBJECT (action), "stock_id", &value);
- stock_id = g_value_get_string (&value);
-
- if (stock_id != NULL)
- {
- pixbuf = gtk_widget_render_icon (item, stock_id,
- GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
- }
- else
- {
- pixbuf = gtk_widget_render_icon (item, GTK_STOCK_DND,
- GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
- }
+ gtk_drag_source_set (item, GDK_BUTTON1_MASK,
+ source_drag_types, n_source_drag_types,
+ GDK_ACTION_MOVE);
+
+ if (is_separator) {
+ GtkWidget *icon;
+ GdkPixbuf *pixbuf;
+
+ icon = _egg_editable_toolbar_new_separator_image ();
+ pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (icon));
+ gtk_drag_source_set_icon_pixbuf (item, pixbuf);
+ } else {
+ const char *stock_id;
+ GValue value = { 0, };
+ GdkPixbuf *pixbuf;
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_object_get_property (G_OBJECT (action), "stock_id", &value);
+ stock_id = g_value_get_string (&value);
+
+ if (stock_id != NULL) {
+ pixbuf = gtk_widget_render_icon (item, stock_id,
+ GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
+ } else {
+ pixbuf = gtk_widget_render_icon (item, GTK_STOCK_DND,
+ GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
+ }
- gtk_drag_source_set_icon_pixbuf (item, pixbuf);
- g_object_unref (pixbuf);
+ gtk_drag_source_set_icon_pixbuf (item, pixbuf);
+ g_object_unref (pixbuf);
- g_value_unset (&value);
- }
+ g_value_unset (&value);
+ }
}
static GtkWidget *
@@ -337,55 +295,47 @@
gboolean is_separator,
GtkAction **ret_action)
{
- GtkWidget *item;
- GtkAction *action;
+ GtkWidget *item;
+ GtkAction *action;
+
+ if (is_separator) {
+ item = GTK_WIDGET (gtk_separator_tool_item_new ());
+ action = NULL;
+ } else {
+ g_signal_emit (G_OBJECT (t), egg_editable_toolbar_signals[ACTION_REQUEST],
+ 0, action_name);
+
+ action = find_action (t, action_name);
+ if (action) {
+ item = gtk_action_create_tool_item (action);
+ } else {
+ return NULL;
+ }
+ }
+
+ gtk_widget_show (item);
+
+ g_signal_connect (item, "drag_begin",
+ G_CALLBACK (drag_begin_cb), t);
+ g_signal_connect (item, "drag_end",
+ G_CALLBACK (drag_end_cb), t);
+ g_signal_connect (item, "drag_data_get",
+ G_CALLBACK (drag_data_get_cb), t);
+ g_signal_connect (item, "drag_data_delete",
+ G_CALLBACK (drag_data_delete_cb), t);
+
+ if (t->priv->edit_mode) {
+ set_drag_cursor (item);
+ gtk_widget_set_sensitive (item, TRUE);
+ set_item_drag_source (item, action, is_separator);
+ gtk_tool_item_set_use_drag_window (GTK_TOOL_ITEM (item), TRUE);
+ }
- if (is_separator)
- {
- item = GTK_WIDGET (gtk_separator_tool_item_new ());
- action = NULL;
- }
- else
- {
- g_signal_emit (G_OBJECT (t), egg_editable_toolbar_signals[ACTION_REQUEST],
- 0, action_name);
-
- action = find_action (t, action_name);
- if (action)
- {
- item = gtk_action_create_tool_item (action);
- }
- else
- {
- return NULL;
- }
- }
-
- gtk_widget_show (item);
-
- g_signal_connect (item, "drag_begin",
- G_CALLBACK (drag_begin_cb), t);
- g_signal_connect (item, "drag_end",
- G_CALLBACK (drag_end_cb), t);
- g_signal_connect (item, "drag_data_get",
- G_CALLBACK (drag_data_get_cb), t);
- g_signal_connect (item, "drag_data_delete",
- G_CALLBACK (drag_data_delete_cb), t);
-
- if (t->priv->edit_mode)
- {
- set_drag_cursor (item);
- gtk_widget_set_sensitive (item, TRUE);
- set_item_drag_source (item, action, is_separator);
- gtk_tool_item_set_use_drag_window (GTK_TOOL_ITEM (item), TRUE);
- }
-
- if (ret_action)
- {
- *ret_action = action;
- }
+ if (ret_action) {
+ *ret_action = action;
+ }
- return item;
+ return item;
}
static GtkWidget *
@@ -395,18 +345,18 @@
int position,
GtkAction **ret_action)
{
- const char *action_name;
- gboolean is_separator;
+ const char *action_name;
+ gboolean is_separator;
- action_name = egg_toolbars_model_item_nth
+ action_name = egg_toolbars_model_item_nth
(model, toolbar_position, position, &is_separator);
- return create_item_from_action (t, action_name, is_separator, ret_action);
+ return create_item_from_action (t, action_name, is_separator, ret_action);
}
static gboolean
data_is_separator (const char *data)
{
- return strcmp (data, "separator") == 0;
+ return strcmp (data, "separator") == 0;
}
static void
@@ -419,76 +369,69 @@
guint time,
EggEditableToolbar *etoolbar)
{
- char *type;
- char *id;
+ char *type;
+ char *id;
+
+ GdkAtom 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,
+ (const char *) selection_data->data);
+
+ /* This function can be called for two reasons
+ *
+ * (1) drag_motion() needs an item to pass to
+ * gtk_toolbar_set_drop_highlight_item(). We can
+ * recognize this case by etoolbar->priv->pending being TRUE
+ * We should just create an item and return.
+ *
+ * (2) The drag has finished, and drag_drop() wants us to
+ * actually add a new item to the toolbar.
+ */
+
+ if (id == NULL) {
+ etoolbar->priv->pending = FALSE;
+ g_free (type);
+ return;
+ }
+
+ if (etoolbar->priv->pending) {
+ etoolbar->priv->pending = FALSE;
+ etoolbar->priv->dragged_item =
+ create_item_from_action (etoolbar, id, data_is_separator (id), NULL);
+ g_object_ref (etoolbar->priv->dragged_item);
+ gtk_object_sink (GTK_OBJECT (etoolbar->priv->dragged_item));
+ } else {
+ int pos, toolbar_pos;
+
+ pos = gtk_toolbar_get_drop_index (GTK_TOOLBAR (widget), x, y);
+ toolbar_pos = get_toolbar_position (etoolbar, widget);
+
+ if (data_is_separator ((const char *) selection_data->data)) {
+ egg_toolbars_model_add_separator (etoolbar->priv->model,
+ toolbar_pos, pos);
+ } else {
+ egg_toolbars_model_add_item (etoolbar->priv->model,
+ toolbar_pos, pos, id, type);
+ }
- GdkAtom 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,
- (const char *) selection_data->data);
-
- /* This function can be called for two reasons
- *
- * (1) drag_motion() needs an item to pass to
- * gtk_toolbar_set_drop_highlight_item(). We can
- * recognize this case by etoolbar->priv->pending being TRUE
- * We should just create an item and return.
- *
- * (2) The drag has finished, and drag_drop() wants us to
- * actually add a new item to the toolbar.
- */
-
- if (id == NULL)
- {
- etoolbar->priv->pending = FALSE;
- g_free (type);
- return;
- }
-
- if (etoolbar->priv->pending)
- {
- etoolbar->priv->pending = FALSE;
- etoolbar->priv->dragged_item =
- create_item_from_action (etoolbar, id, data_is_separator (id), NULL);
- g_object_ref (etoolbar->priv->dragged_item);
- gtk_object_sink (GTK_OBJECT (etoolbar->priv->dragged_item));
- }
- else
- {
- int pos, toolbar_pos;
-
- pos = gtk_toolbar_get_drop_index (GTK_TOOLBAR (widget), x, y);
- toolbar_pos = get_toolbar_position (etoolbar, widget);
-
- if (data_is_separator ((const char *) selection_data->data))
- {
- egg_toolbars_model_add_separator (etoolbar->priv->model,
- toolbar_pos, pos);
- }
- else
- {
- egg_toolbars_model_add_item (etoolbar->priv->model,
- toolbar_pos, pos, id, type);
- }
-
- gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE,
- time);
- }
+ gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE,
+ time);
+ }
- g_free (type);
- g_free (id);
+ g_free (type);
+ g_free (id);
}
static void
remove_toolbar_cb (GtkWidget *menuitem,
EggEditableToolbar *etoolbar)
{
- int pos;
+ int pos;
- pos = get_toolbar_position (etoolbar, etoolbar->priv->selected_toolbar);
- egg_toolbars_model_remove_toolbar (etoolbar->priv->model, pos);
+ pos = get_toolbar_position (etoolbar, etoolbar->priv->selected_toolbar);
+ egg_toolbars_model_remove_toolbar (etoolbar->priv->model, pos);
}
static void
@@ -498,50 +441,47 @@
gint button_number,
EggEditableToolbar *t)
{
- GtkWidget *menu;
- GtkWidget *item;
- GtkWidget *image;
-
- if (t->priv->edit_mode)
- {
- EggTbModelFlags flags;
- int position;
-
- t->priv->selected_toolbar = toolbar;
-
- menu = gtk_menu_new ();
-
- item = gtk_image_menu_item_new_with_mnemonic (_("_Remove Toolbar"));
- gtk_widget_show (item);
- image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU);
- gtk_widget_show (image);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- g_signal_connect (item, "activate",
- G_CALLBACK (remove_toolbar_cb),
- t);
-
- position = get_toolbar_position (t, toolbar);
- flags = egg_toolbars_model_get_flags (t->priv->model, position);
- if (flags & EGG_TB_MODEL_NOT_REMOVABLE)
- {
- gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
- }
-
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 2,
- gtk_get_current_event_time ());
- }
+ GtkWidget *menu;
+ GtkWidget *item;
+ GtkWidget *image;
+
+ if (t->priv->edit_mode) {
+ EggTbModelFlags flags;
+ int position;
+
+ t->priv->selected_toolbar = toolbar;
+
+ menu = gtk_menu_new ();
+
+ item = gtk_image_menu_item_new_with_mnemonic (_("_Remove Toolbar"));
+ gtk_widget_show (item);
+ image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU);
+ gtk_widget_show (image);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ g_signal_connect (item, "activate",
+ G_CALLBACK (remove_toolbar_cb),
+ t);
+
+ position = get_toolbar_position (t, toolbar);
+ flags = egg_toolbars_model_get_flags (t->priv->model, position);
+ if (flags & EGG_TB_MODEL_NOT_REMOVABLE) {
+ gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
+ }
+
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 2,
+ gtk_get_current_event_time ());
+ }
}
static void
free_dragged_item (EggEditableToolbar *etoolbar)
{
- if (etoolbar->priv->dragged_item)
- {
- gtk_widget_destroy (etoolbar->priv->dragged_item);
- g_object_unref (etoolbar->priv->dragged_item);
- etoolbar->priv->dragged_item = NULL;
- }
+ if (etoolbar->priv->dragged_item) {
+ gtk_widget_destroy (etoolbar->priv->dragged_item);
+ g_object_unref (etoolbar->priv->dragged_item);
+ etoolbar->priv->dragged_item = NULL;
+ }
}
static gboolean
@@ -552,20 +492,19 @@
guint time,
EggEditableToolbar *etoolbar)
{
- GdkAtom target;
+ GdkAtom target;
- target = gtk_drag_dest_find_target (widget, context, NULL);
- if (target != GDK_NONE)
- {
- gtk_drag_get_data (widget, context,
- target,
- time);
- return TRUE;
- }
-
- free_dragged_item (etoolbar);
-
- return FALSE;
+ target = gtk_drag_dest_find_target (widget, context, NULL);
+ if (target != GDK_NONE) {
+ gtk_drag_get_data (widget, context,
+ target,
+ time);
+ return TRUE;
+ }
+
+ free_dragged_item (etoolbar);
+
+ return FALSE;
}
static gboolean
@@ -576,43 +515,40 @@
guint time,
EggEditableToolbar *etoolbar)
{
- GdkAtom target;
- int index;
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolItem *item;
-
- target = gtk_drag_dest_find_target (widget, context, NULL);
- if (target == GDK_NONE)
- {
- gdk_drag_status (context, 0, time);
- return FALSE;
- }
-
- if (etoolbar->priv->target_toolbar != toolbar)
- {
- if (etoolbar->priv->target_toolbar)
- gtk_toolbar_set_drop_highlight_item
- (etoolbar->priv->target_toolbar, NULL, 0);
-
- free_dragged_item (etoolbar);
- etoolbar->priv->pending = TRUE;
-
- etoolbar->priv->target_toolbar = toolbar;
-
- gtk_drag_get_data (widget, context, target, time);
- }
-
- if (etoolbar->priv->dragged_item != NULL)
- {
- item = GTK_TOOL_ITEM (etoolbar->priv->dragged_item);
-
- index = gtk_toolbar_get_drop_index (toolbar, x, y);
- gtk_toolbar_set_drop_highlight_item (toolbar, item, index);
- }
+ GdkAtom target;
+ int index;
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolItem *item;
+
+ target = gtk_drag_dest_find_target (widget, context, NULL);
+ if (target == GDK_NONE) {
+ gdk_drag_status (context, 0, time);
+ return FALSE;
+ }
+
+ if (etoolbar->priv->target_toolbar != toolbar) {
+ if (etoolbar->priv->target_toolbar)
+ gtk_toolbar_set_drop_highlight_item
+ (etoolbar->priv->target_toolbar, NULL, 0);
+
+ free_dragged_item (etoolbar);
+ etoolbar->priv->pending = TRUE;
+
+ etoolbar->priv->target_toolbar = toolbar;
- gdk_drag_status (context, context->suggested_action, time);
+ gtk_drag_get_data (widget, context, target, time);
+ }
+
+ if (etoolbar->priv->dragged_item != NULL) {
+ item = GTK_TOOL_ITEM (etoolbar->priv->dragged_item);
+
+ index = gtk_toolbar_get_drop_index (toolbar, x, y);
+ gtk_toolbar_set_drop_highlight_item (toolbar, item, index);
+ }
- return TRUE;
+ gdk_drag_status (context, context->suggested_action, time);
+
+ return TRUE;
}
static void
@@ -621,68 +557,67 @@
guint time,
EggEditableToolbar *etoolbar)
{
- /* This is a workaround for bug 125557. Sometimes
- * we seemingly enter another toolbar *before* leaving
- * the current one.
- *
- * In that case etoolbar->priv->target_toolbar will
- * have been set to something else and the highlighting
- * will already have been turned off
- */
+ /* This is a workaround for bug 125557. Sometimes
+ * we seemingly enter another toolbar *before* leaving
+ * the current one.
+ *
+ * In that case etoolbar->priv->target_toolbar will
+ * have been set to something else and the highlighting
+ * will already have been turned off
+ */
- if (etoolbar->priv->target_toolbar == toolbar)
- {
- gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
-
- etoolbar->priv->target_toolbar = NULL;
- free_dragged_item (etoolbar);
- }
+ if (etoolbar->priv->target_toolbar == toolbar) {
+ gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
+
+ etoolbar->priv->target_toolbar = NULL;
+ free_dragged_item (etoolbar);
+ }
}
static GtkWidget *
create_dock (EggEditableToolbar *t)
{
- GtkWidget *toolbar, *hbox;
+ GtkWidget *toolbar, *hbox;
- hbox = gtk_hbox_new (0, FALSE);
- gtk_widget_show (hbox);
+ hbox = gtk_hbox_new (0, FALSE);
+ gtk_widget_show (hbox);
- toolbar = gtk_toolbar_new ();
- gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
- gtk_widget_show (toolbar);
- gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
-
- gtk_drag_dest_set (toolbar, 0,
- dest_drag_types, n_dest_drag_types,
- GDK_ACTION_MOVE | GDK_ACTION_COPY);
+ toolbar = gtk_toolbar_new ();
+ gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
+ gtk_widget_show (toolbar);
+ gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
+
+ gtk_drag_dest_set (toolbar, 0,
+ dest_drag_types, n_dest_drag_types,
+ GDK_ACTION_MOVE | GDK_ACTION_COPY);
- g_signal_connect (toolbar, "drag_drop",
- G_CALLBACK (toolbar_drag_drop_cb), t);
- g_signal_connect (toolbar, "drag_motion",
- G_CALLBACK (toolbar_drag_motion_cb), t);
- g_signal_connect (toolbar, "drag_leave",
- G_CALLBACK (toolbar_drag_leave_cb), t);
-
- g_signal_connect (toolbar, "drag_data_received",
- G_CALLBACK (drag_data_received_cb), t);
- g_signal_connect (toolbar, "popup_context_menu",
- G_CALLBACK (popup_toolbar_context_menu_cb), t);
+ g_signal_connect (toolbar, "drag_drop",
+ G_CALLBACK (toolbar_drag_drop_cb), t);
+ g_signal_connect (toolbar, "drag_motion",
+ G_CALLBACK (toolbar_drag_motion_cb), t);
+ g_signal_connect (toolbar, "drag_leave",
+ G_CALLBACK (toolbar_drag_leave_cb), t);
+
+ g_signal_connect (toolbar, "drag_data_received",
+ G_CALLBACK (drag_data_received_cb), t);
+ g_signal_connect (toolbar, "popup_context_menu",
+ G_CALLBACK (popup_toolbar_context_menu_cb), t);
- return hbox;
+ return hbox;
}
static void
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);
+ g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
+ gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar), style);
}
static void
unset_fixed_style (EggEditableToolbar *t)
{
- g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
- gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
+ g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
+ gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
}
static void
@@ -690,76 +625,63 @@
int position,
EggEditableToolbar *t)
{
- GtkWidget *toolbar;
- EggTbModelFlags flags;
- GtkToolbarStyle style;
-
- flags = egg_toolbars_model_get_flags (model, position);
- toolbar = get_toolbar_nth (t, position);
-
- if (flags & EGG_TB_MODEL_ICONS_ONLY)
- {
- style = GTK_TOOLBAR_ICONS;
- }
- else if (flags & EGG_TB_MODEL_TEXT_ONLY)
- {
- style = GTK_TOOLBAR_TEXT;
- }
- else if (flags & EGG_TB_MODEL_ICONS_TEXT)
- {
- style = GTK_TOOLBAR_BOTH;
- }
- else if (flags & EGG_TB_MODEL_ICONS_TEXT_HORIZ)
- {
- style = GTK_TOOLBAR_BOTH_HORIZ;
- }
- else
- {
- gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
- if (position == 0 && t->priv->fixed_toolbar)
- {
- unset_fixed_style (t);
- }
- return;
- }
-
- gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
- if (position == 0 && t->priv->fixed_toolbar)
- {
- set_fixed_style (t, style);
- }
+ GtkWidget *toolbar;
+ EggTbModelFlags flags;
+ GtkToolbarStyle style;
+
+ flags = egg_toolbars_model_get_flags (model, position);
+ toolbar = get_toolbar_nth (t, position);
+
+ if (flags & EGG_TB_MODEL_ICONS_ONLY) {
+ style = GTK_TOOLBAR_ICONS;
+ } else if (flags & EGG_TB_MODEL_TEXT_ONLY) {
+ style = GTK_TOOLBAR_TEXT;
+ } else if (flags & EGG_TB_MODEL_ICONS_TEXT) {
+ style = GTK_TOOLBAR_BOTH;
+ } else if (flags & EGG_TB_MODEL_ICONS_TEXT_HORIZ) {
+ style = GTK_TOOLBAR_BOTH_HORIZ;
+ } else {
+ gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
+ if (position == 0 && t->priv->fixed_toolbar) {
+ unset_fixed_style (t);
+ }
+ return;
+ }
+
+ gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
+ if (position == 0 && t->priv->fixed_toolbar) {
+ set_fixed_style (t, style);
+ }
}
static void
unparent_fixed (EggEditableToolbar *t)
{
- GtkWidget *toolbar, *dock;
- g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
+ GtkWidget *toolbar, *dock;
+ g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
- toolbar = t->priv->fixed_toolbar;
- dock = get_dock_nth (t, 0);
+ toolbar = t->priv->fixed_toolbar;
+ dock = get_dock_nth (t, 0);
- if (dock && toolbar->parent != NULL)
- {
- gtk_container_remove (GTK_CONTAINER (dock), toolbar);
- }
+ if (dock && toolbar->parent != NULL) {
+ gtk_container_remove (GTK_CONTAINER (dock), toolbar);
+ }
}
static void
update_fixed (EggEditableToolbar *t)
{
- GtkWidget *toolbar, *dock;
- if (!t->priv->fixed_toolbar) return;
+ GtkWidget *toolbar, *dock;
+ if (!t->priv->fixed_toolbar) return;
- toolbar = t->priv->fixed_toolbar;
- dock = get_dock_nth (t, 0);
+ toolbar = t->priv->fixed_toolbar;
+ dock = get_dock_nth (t, 0);
- if (dock && toolbar && toolbar->parent == NULL)
- {
- gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
+ if (dock && toolbar && toolbar->parent == NULL) {
+ gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
- gtk_widget_show_all (toolbar);
- }
+ gtk_widget_show_all (toolbar);
+ }
}
static void
@@ -767,19 +689,19 @@
int position,
EggEditableToolbar *t)
{
- GtkWidget *dock;
+ GtkWidget *dock;
- dock = create_dock (t);
+ dock = create_dock (t);
- gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
+ gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
- gtk_box_pack_start (GTK_BOX (t), dock, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (t), dock, TRUE, TRUE, 0);
- gtk_box_reorder_child (GTK_BOX (t), dock, position);
+ gtk_box_reorder_child (GTK_BOX (t), dock, position);
- gtk_widget_show_all (dock);
+ gtk_widget_show_all (dock);
- update_fixed (t);
+ update_fixed (t);
}
static void
@@ -787,12 +709,12 @@
int position,
EggEditableToolbar *t)
{
- GtkWidget *toolbar;
+ GtkWidget *toolbar;
- toolbar = get_dock_nth (t, position);
- gtk_widget_destroy (toolbar);
+ toolbar = get_dock_nth (t, position);
+ gtk_widget_destroy (toolbar);
- update_fixed (t);
+ update_fixed (t);
}
static void
@@ -801,25 +723,24 @@
int position,
EggEditableToolbar *t)
{
- GtkWidget *dock;
- GtkWidget *toolbar;
- GtkWidget *item;
- GtkAction *action;
-
- toolbar = get_toolbar_nth (t, toolbar_position);
- item = create_item (t, model, toolbar_position, position, &action);
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
- GTK_TOOL_ITEM (item), position);
-
- dock = get_dock_nth (t, toolbar_position);
- gtk_widget_set_size_request (dock, -1, -1);
- gtk_widget_queue_resize_no_redraw (dock);
-
- /* FIXME Hack to make tooltip work from gtk */
- if (action)
- {
- g_object_notify (G_OBJECT (action), "tooltip");
- }
+ GtkWidget *dock;
+ GtkWidget *toolbar;
+ GtkWidget *item;
+ GtkAction *action;
+
+ toolbar = get_toolbar_nth (t, toolbar_position);
+ item = create_item (t, model, toolbar_position, position, &action);
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
+ GTK_TOOL_ITEM (item), position);
+
+ dock = get_dock_nth (t, toolbar_position);
+ gtk_widget_set_size_request (dock, -1, -1);
+ gtk_widget_queue_resize_no_redraw (dock);
+
+ /* FIXME Hack to make tooltip work from gtk */
+ if (action) {
+ g_object_notify (G_OBJECT (action), "tooltip");
+ }
}
static void
@@ -828,170 +749,177 @@
int position,
EggEditableToolbar *t)
{
- GtkWidget *toolbar;
- GtkWidget *item;
+ GtkWidget *toolbar;
+ GtkWidget *item;
- toolbar = get_toolbar_nth (t, toolbar_position);
- item = GTK_WIDGET (gtk_toolbar_get_nth_item
- (GTK_TOOLBAR (toolbar), position));
- g_return_if_fail (item != NULL);
- gtk_container_remove (GTK_CONTAINER (toolbar), item);
-
- if (egg_toolbars_model_n_items (model, toolbar_position) == 0)
- {
- egg_toolbars_model_remove_toolbar (model, toolbar_position);
- }
+ toolbar = get_toolbar_nth (t, toolbar_position);
+ item = GTK_WIDGET (gtk_toolbar_get_nth_item
+ (GTK_TOOLBAR (toolbar), position));
+ g_return_if_fail (item != NULL);
+ gtk_container_remove (GTK_CONTAINER (toolbar), item);
+
+ if (egg_toolbars_model_n_items (model, toolbar_position) == 0) {
+ egg_toolbars_model_remove_toolbar (model, toolbar_position);
+ }
}
static void
toolbars_clean (EggEditableToolbar *t)
{
- GList *children, *l;
+ GList *children, *l;
+
+ if (t->priv->fixed_toolbar) {
+ unset_fixed_style (t);
+ unparent_fixed (t);
+ }
+
+ children = gtk_container_get_children (GTK_CONTAINER (t));
- if (t->priv->fixed_toolbar)
- {
- unset_fixed_style (t);
- unparent_fixed (t);
- }
-
- children = gtk_container_get_children (GTK_CONTAINER (t));
-
- for (l = children; l != NULL; l = l->next)
- {
- gtk_widget_destroy (GTK_WIDGET (l->data));
- }
+ for (l = children; l != NULL; l = l->next) {
+ gtk_widget_destroy (GTK_WIDGET (l->data));
+ }
- g_list_free (children);
+ g_list_free (children);
}
static void
egg_editable_toolbar_construct (EggEditableToolbar *t)
{
- int i, l, n_items, n_toolbars;
- EggToolbarsModel *model = t->priv->model;
+ int i, l, n_items, n_toolbars;
+ EggToolbarsModel *model = t->priv->model;
+
+ g_return_if_fail (model != NULL);
- g_return_if_fail (model != NULL);
+ n_toolbars = egg_toolbars_model_n_toolbars (model);
- n_toolbars = egg_toolbars_model_n_toolbars (model);
+ 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);
+ }
+ }
- 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++)
- {
- GtkWidget *item;
- GtkAction *action;
-
- item = create_item (t, model, i, l, &action);
- if (item)
- {
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
- GTK_TOOL_ITEM (item), l);
- /* FIXME Hack to make tooltip work from gtk */
- if (action)
- {
- g_object_notify (G_OBJECT (action), "tooltip");
+ n_items = egg_toolbars_model_n_items (model, i);
+ for (l = 0; l < n_items; l++) {
+ GtkWidget *item;
+ GtkAction *action;
+
+ item = create_item (t, model, i, l, &action);
+ if (item) {
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
+ GTK_TOOL_ITEM (item), l);
+ /* FIXME Hack to make tooltip work from gtk */
+ if (action) {
+ g_object_notify (G_OBJECT (action),
+ "tooltip");
+ }
+ } else {
+ egg_toolbars_model_remove_item (model, i, l);
+ l--;
+ n_items--;
+ }
+ }
+
+ if (n_items == 0) {
+ gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
}
- }
- else
- {
- egg_toolbars_model_remove_item (model, i, l);
- l--;
- n_items--;
- }
- }
-
- if (n_items == 0)
- {
- gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
}
- }
- update_fixed (t);
+ update_fixed (t);
}
static void
egg_editable_toolbar_set_model (EggEditableToolbar *t,
EggToolbarsModel *model)
{
- g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model));
- g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (t));
+ g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model));
+ g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (t));
+
+ if (t->priv->model == model) {
+ return;
+ }
- if (t->priv->model == model) return;
+ if (t->priv->model) {
+ g_signal_handlers_disconnect_by_func
+ (t->priv->model, G_CALLBACK (item_added_cb), t);
+ g_signal_handlers_disconnect_by_func
+ (t->priv->model, G_CALLBACK (item_removed_cb), t);
+ g_signal_handlers_disconnect_by_func
+ (t->priv->model, G_CALLBACK (toolbar_added_cb), t);
+ g_signal_handlers_disconnect_by_func
+ (t->priv->model, G_CALLBACK (toolbar_removed_cb), t);
+ g_signal_handlers_disconnect_by_func
+ (t->priv->model, G_CALLBACK (toolbar_changed_cb), t);
- if (t->priv->model)
- {
- g_signal_handlers_disconnect_by_func
- (t->priv->model, G_CALLBACK (item_added_cb), t);
- g_signal_handlers_disconnect_by_func
- (t->priv->model, G_CALLBACK (item_removed_cb), t);
- g_signal_handlers_disconnect_by_func
- (t->priv->model, G_CALLBACK (toolbar_added_cb), t);
- g_signal_handlers_disconnect_by_func
- (t->priv->model, G_CALLBACK (toolbar_removed_cb), t);
- g_signal_handlers_disconnect_by_func
- (t->priv->model, G_CALLBACK (toolbar_changed_cb), t);
-
- g_object_unref (t->priv->model);
- }
-
- t->priv->model = g_object_ref (model);
-
- toolbars_clean (t);
- if (t->priv->merge != NULL)
- {
- egg_editable_toolbar_construct (t);
- }
-
- g_signal_connect_object (model, "item_added",
- G_CALLBACK (item_added_cb), t, 0);
- g_signal_connect_object (model, "item_removed",
- G_CALLBACK (item_removed_cb), t, 0);
- g_signal_connect_object (model, "toolbar_added",
- G_CALLBACK (toolbar_added_cb), t, 0);
- g_signal_connect_object (model, "toolbar_removed",
- G_CALLBACK (toolbar_removed_cb), t, 0);
- g_signal_connect_object (model, "toolbar_changed",
- G_CALLBACK (toolbar_changed_cb), t, 0);
+ g_object_unref (t->priv->model);
+ }
+
+ t->priv->model = g_object_ref (model);
+
+ toolbars_clean (t);
+ if (t->priv->merge != NULL) {
+ egg_editable_toolbar_construct (t);
+ }
+
+ g_signal_connect_object (model, "item_added",
+ G_CALLBACK (item_added_cb), t, 0);
+ g_signal_connect_object (model, "item_removed",
+ G_CALLBACK (item_removed_cb), t, 0);
+ g_signal_connect_object (model, "toolbar_added",
+ G_CALLBACK (toolbar_added_cb), t, 0);
+ g_signal_connect_object (model, "toolbar_removed",
+ G_CALLBACK (toolbar_removed_cb), t, 0);
+ g_signal_connect_object (model, "toolbar_changed",
+ G_CALLBACK (toolbar_changed_cb), t, 0);
}
static void
egg_editable_toolbar_set_merge (EggEditableToolbar *t,
GtkUIManager *merge)
{
- g_return_if_fail (GTK_IS_UI_MANAGER (merge));
- g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (t));
+ g_return_if_fail (GTK_IS_UI_MANAGER (merge));
+ g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (t));
+
+ if (t->priv->merge == merge) return;
+
+ if (t->priv->merge) {
+ g_object_unref (t->priv->merge);
+ }
+
+ t->priv->merge = g_object_ref (merge);
+
+ if (t->priv->model != NULL) {
+ egg_editable_toolbar_construct (t);
+ }
+}
+
+static void
+egg_editable_toolbar_finalize (GObject *object)
+{
+ EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object);
+
+ if (t->priv->fixed_toolbar) {
+ g_object_unref (t->priv->fixed_toolbar);
+ }
- if (t->priv->merge == merge) return;
+ if (t->priv->merge) {
+ g_object_unref (t->priv->merge);
+ }
+
+ if (t->priv->model) {
+ g_object_unref (t->priv->model);
+ }
- if (t->priv->merge)
- {
- g_object_unref (t->priv->merge);
- }
-
- t->priv->merge = g_object_ref (merge);
-
- if (t->priv->model != NULL)
- {
- egg_editable_toolbar_construct (t);
- }
+ G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->finalize (object);
}
static void
@@ -1000,17 +928,17 @@
const GValue *value,
GParamSpec *pspec)
{
- EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object);
+ EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object);
- switch (prop_id)
- {
- case PROP_MENU_MERGE:
- egg_editable_toolbar_set_merge (t, g_value_get_object (value));
- break;
- case PROP_TOOLBARS_MODEL:
- egg_editable_toolbar_set_model (t, g_value_get_object (value));
- break;
- }
+ switch (prop_id) {
+ case PROP_MENU_MERGE:
+ egg_editable_toolbar_set_merge (t, g_value_get_object (value));
+ break;
+
+ case PROP_TOOLBARS_MODEL:
+ egg_editable_toolbar_set_model (t, g_value_get_object (value));
+ break;
+ }
}
static void
@@ -1019,97 +947,72 @@
GValue *value,
GParamSpec *pspec)
{
- EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object);
+ EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object);
- switch (prop_id)
- {
- case PROP_MENU_MERGE:
- g_value_set_object (value, t->priv->merge);
- break;
- case PROP_TOOLBARS_MODEL:
- g_value_set_object (value, t->priv->model);
- break;
- }
+ switch (prop_id) {
+ case PROP_MENU_MERGE:
+ g_value_set_object (value, t->priv->merge);
+ break;
+
+ case PROP_TOOLBARS_MODEL:
+ g_value_set_object (value, t->priv->model);
+ break;
+ }
}
static void
egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
+ object_class->finalize = egg_editable_toolbar_finalize;
+ object_class->set_property = egg_editable_toolbar_set_property;
+ object_class->get_property = egg_editable_toolbar_get_property;
+
+ egg_editable_toolbar_signals[ACTION_REQUEST] =
+ g_signal_new ("action_request",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
+ NULL, NULL, g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ g_object_class_install_property (object_class,
+ PROP_MENU_MERGE,
+ g_param_spec_object ("MenuMerge",
+ "MenuMerge",
+ "Menu merge",
+ GTK_TYPE_UI_MANAGER,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_TOOLBARS_MODEL,
+ g_param_spec_object ("ToolbarsModel",
+ "ToolbarsModel",
+ "Toolbars Model",
+ EGG_TYPE_TOOLBARS_MODEL,
+ G_PARAM_READWRITE));
- object_class->finalize = egg_editable_toolbar_finalize;
- object_class->set_property = egg_editable_toolbar_set_property;
- object_class->get_property = egg_editable_toolbar_get_property;
-
- egg_editable_toolbar_signals[ACTION_REQUEST] =
- g_signal_new ("action_request",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
- NULL, NULL, g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- g_object_class_install_property (object_class,
- PROP_MENU_MERGE,
- g_param_spec_object ("MenuMerge",
- "MenuMerge",
- "Menu merge",
- GTK_TYPE_UI_MANAGER,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_TOOLBARS_MODEL,
- g_param_spec_object ("ToolbarsModel",
- "ToolbarsModel",
- "Toolbars Model",
- EGG_TYPE_TOOLBARS_MODEL,
- G_PARAM_READWRITE));
-
- g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
+ g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
}
static void
egg_editable_toolbar_init (EggEditableToolbar *t)
{
- t->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (t);
-
- t->priv->merge = NULL;
- t->priv->edit_mode = FALSE;
- t->priv->dragged_item = NULL;
-}
-
-static void
-egg_editable_toolbar_finalize (GObject *object)
-{
- EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object);
+ t->priv = GET_PRIVATE (t);
- if (t->priv->fixed_toolbar)
- {
- g_object_unref (t->priv->fixed_toolbar);
- }
-
- if (t->priv->merge)
- {
- g_object_unref (t->priv->merge);
- }
-
- if (t->priv->model)
- {
- g_object_unref (t->priv->model);
- }
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ t->priv->merge = NULL;
+ t->priv->edit_mode = FALSE;
+ t->priv->dragged_item = NULL;
}
GtkWidget *
egg_editable_toolbar_new (GtkUIManager *merge,
EggToolbarsModel *model)
{
- return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
- "ToolbarsModel", model,
- "MenuMerge", merge,
- NULL));
+ return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
+ "ToolbarsModel", model,
+ "MenuMerge", merge,
+ NULL));
}
gboolean
@@ -1122,116 +1025,108 @@
egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
gboolean mode)
{
- int i, l, n_toolbars, n_items;
+ int i, l, n_toolbars, n_items;
- etoolbar->priv->edit_mode = mode;
+ etoolbar->priv->edit_mode = mode;
- n_toolbars = get_n_toolbars (etoolbar);
- for (i = 0; i < n_toolbars; i++)
- {
- GtkWidget *toolbar;
-
- toolbar = get_toolbar_nth (etoolbar, i);
- n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
- for (l = 0; l < n_items; l++)
- {
- GtkToolItem *item;
- const char *action_name;
- gboolean is_separator;
- GtkAction *action;
-
- action_name = egg_toolbars_model_item_nth
- (etoolbar->priv->model, i, l,
- &is_separator);
- action = find_action (etoolbar, action_name);
-
- item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
- gtk_tool_item_set_use_drag_window (item, mode);
-
- if (mode)
- {
- set_drag_cursor (GTK_WIDGET (item));
- gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
- set_item_drag_source (GTK_WIDGET (item), action, is_separator);
- }
- else
- {
- unset_drag_cursor (GTK_WIDGET (item));
- gtk_drag_source_unset (GTK_WIDGET (item));
-
- if (!is_separator)
- {
- g_object_notify (G_OBJECT (action), "sensitive");
+ n_toolbars = get_n_toolbars (etoolbar);
+ for (i = 0; i < n_toolbars; i++) {
+ GtkWidget *toolbar;
+
+ toolbar = get_toolbar_nth (etoolbar, i);
+ n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
+ for (l = 0; l < n_items; l++) {
+ GtkToolItem *item;
+ const char *action_name;
+ gboolean is_separator;
+ GtkAction *action;
+
+ action_name = egg_toolbars_model_item_nth
+ (etoolbar->priv->model, i, l,
+ &is_separator);
+ action = find_action (etoolbar, action_name);
+
+ item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
+ gtk_tool_item_set_use_drag_window (item, mode);
+
+ if (mode) {
+ set_drag_cursor (GTK_WIDGET (item));
+ gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
+ set_item_drag_source (GTK_WIDGET (item),
+ action, is_separator);
+ } else {
+ unset_drag_cursor (GTK_WIDGET (item));
+ gtk_drag_source_unset (GTK_WIDGET (item));
+
+ if (!is_separator) {
+ g_object_notify (G_OBJECT (action),
+ "sensitive");
+ }
+ }
}
- }
}
- }
}
void
egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
const char *name)
{
- int i, n_toolbars;
- EggToolbarsModel *model = etoolbar->priv->model;
+ int i, n_toolbars;
+ EggToolbarsModel *model = etoolbar->priv->model;
- g_return_if_fail (model != NULL);
+ g_return_if_fail (model != NULL);
- n_toolbars = egg_toolbars_model_n_toolbars (model);
- for (i = 0; i < n_toolbars; i++)
- {
- const char *toolbar_name;
-
- toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
- if (strcmp (toolbar_name, name) == 0)
- {
- gtk_widget_show (get_dock_nth (etoolbar, i));
- }
- }
+ n_toolbars = egg_toolbars_model_n_toolbars (model);
+ for (i = 0; i < n_toolbars; i++) {
+ const char *toolbar_name;
+
+ toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
+ if (strcmp (toolbar_name, name) == 0) {
+ gtk_widget_show (get_dock_nth (etoolbar, i));
+ }
+ }
}
void
egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
const char *name)
{
- int i, n_toolbars;
- EggToolbarsModel *model = etoolbar->priv->model;
+ int i, n_toolbars;
+ EggToolbarsModel *model = etoolbar->priv->model;
- g_return_if_fail (model != NULL);
+ g_return_if_fail (model != NULL);
- n_toolbars = egg_toolbars_model_n_toolbars (model);
- for (i = 0; i < n_toolbars; i++)
- {
- const char *toolbar_name;
-
- toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
- if (strcmp (toolbar_name, name) == 0)
- {
- gtk_widget_hide (get_dock_nth (etoolbar, i));
- }
- }
+ n_toolbars = egg_toolbars_model_n_toolbars (model);
+ for (i = 0; i < n_toolbars; i++) {
+ const char *toolbar_name;
+
+ toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
+ if (strcmp (toolbar_name, name) == 0) {
+ gtk_widget_hide (get_dock_nth (etoolbar, i));
+ }
+ }
}
GtkToolbar *
egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
GtkWidget *fixed)
{
- GtkWidget *fixed_item;
+ GtkWidget *fixed_item;
- etoolbar->priv->fixed_toolbar = gtk_toolbar_new ();
- gtk_toolbar_set_show_arrow (GTK_TOOLBAR (etoolbar->priv->fixed_toolbar), FALSE);
- g_object_ref (etoolbar->priv->fixed_toolbar);
- gtk_object_sink (GTK_OBJECT (etoolbar->priv->fixed_toolbar));
+ etoolbar->priv->fixed_toolbar = gtk_toolbar_new ();
+ gtk_toolbar_set_show_arrow (GTK_TOOLBAR (etoolbar->priv->fixed_toolbar), FALSE);
+ g_object_ref (etoolbar->priv->fixed_toolbar);
+ gtk_object_sink (GTK_OBJECT (etoolbar->priv->fixed_toolbar));
- fixed_item = GTK_WIDGET (gtk_tool_item_new ());
- gtk_toolbar_insert (GTK_TOOLBAR (etoolbar->priv->fixed_toolbar),
- GTK_TOOL_ITEM (fixed_item), 0);
+ fixed_item = GTK_WIDGET (gtk_tool_item_new ());
+ gtk_toolbar_insert (GTK_TOOLBAR (etoolbar->priv->fixed_toolbar),
+ GTK_TOOL_ITEM (fixed_item), 0);
- gtk_container_add (GTK_CONTAINER (fixed_item), fixed);
+ gtk_container_add (GTK_CONTAINER (fixed_item), fixed);
- update_fixed (etoolbar);
+ update_fixed (etoolbar);
- return GTK_TOOLBAR (etoolbar->priv->fixed_toolbar);
+ return GTK_TOOLBAR (etoolbar->priv->fixed_toolbar);
}
void
@@ -1240,27 +1135,25 @@
gint n_targets,
const char *toolbar_name)
{
- int i, n_toolbars;
- EggToolbarsModel *model = etoolbar->priv->model;
+ int i, n_toolbars;
+ EggToolbarsModel *model = etoolbar->priv->model;
- g_return_if_fail (model != NULL);
+ g_return_if_fail (model != NULL);
- n_toolbars = egg_toolbars_model_n_toolbars (model);
- for (i = 0; i < n_toolbars; i++)
- {
- const char *name;
-
- name = egg_toolbars_model_toolbar_nth (model, i);
- if (strcmp (toolbar_name, name) == 0)
- {
- GtkWidget *widget = get_toolbar_nth (etoolbar, i);
-
- gtk_drag_dest_unset (widget);
- gtk_drag_dest_set (widget, 0,
- targets, n_targets,
- GDK_ACTION_MOVE | GDK_ACTION_COPY);
- }
- }
+ n_toolbars = egg_toolbars_model_n_toolbars (model);
+ for (i = 0; i < n_toolbars; i++) {
+ const char *name;
+
+ name = egg_toolbars_model_toolbar_nth (model, i);
+ if (strcmp (toolbar_name, name) == 0) {
+ GtkWidget *widget = get_toolbar_nth (etoolbar, i);
+
+ gtk_drag_dest_unset (widget);
+ gtk_drag_dest_set (widget, 0,
+ targets, n_targets,
+ GDK_ACTION_MOVE | GDK_ACTION_COPY);
+ }
+ }
}
#define DEFAULT_ICON_HEIGHT 20
@@ -1270,20 +1163,20 @@
fake_expose_widget (GtkWidget *widget,
GdkPixmap *pixmap)
{
- GdkWindow *tmp_window;
- GdkEventExpose event;
+ 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;
+ 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.
@@ -1294,86 +1187,85 @@
static GdkPixbuf *
new_pixbuf_from_widget (GtkWidget *widget)
{
- GtkWidget *window;
- GdkPixbuf *pixbuf;
- GtkRequisition requisition;
- GtkAllocation allocation;
- GdkPixmap *pixmap;
- GdkVisual *visual;
- gint icon_width;
- gint icon_height;
-
- icon_width = DEFAULT_ICON_WIDTH;
-
- if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_default (),
- GTK_ICON_SIZE_LARGE_TOOLBAR,
- NULL,
- &icon_height))
- {
- icon_height = DEFAULT_ICON_HEIGHT;
- }
+ GtkWidget *window;
+ GdkPixbuf *pixbuf;
+ GtkRequisition requisition;
+ GtkAllocation allocation;
+ GdkPixmap *pixmap;
+ GdkVisual *visual;
+ gint icon_width;
+ gint icon_height;
+
+ icon_width = DEFAULT_ICON_WIDTH;
+
+ if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_default (),
+ GTK_ICON_SIZE_LARGE_TOOLBAR,
+ NULL,
+ &icon_height)) {
+ icon_height = DEFAULT_ICON_HEIGHT;
+ }
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
- 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);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ 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, gdk_visual_get_best_depth());
- gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
+ /* Create a pixmap */
+ visual = gtk_widget_get_visual (window);
+ pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, gdk_visual_get_best_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);
+ /* 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);
+ 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);
+ 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);
- return pixbuf;
+ return pixbuf;
}
static GdkPixbuf *
new_separator_pixbuf (void)
{
- GtkWidget *separator;
- GdkPixbuf *pixbuf;
+ GtkWidget *separator;
+ GdkPixbuf *pixbuf;
- separator = gtk_vseparator_new ();
- pixbuf = new_pixbuf_from_widget (separator);
- gtk_widget_destroy (separator);
- return pixbuf;
+ separator = gtk_vseparator_new ();
+ pixbuf = new_pixbuf_from_widget (separator);
+ gtk_widget_destroy (separator);
+ return pixbuf;
}
static void
update_separator_image (GtkImage *image)
{
- GdkPixbuf *pixbuf = new_separator_pixbuf ();
- gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
- g_object_unref (pixbuf);
+ GdkPixbuf *pixbuf = new_separator_pixbuf ();
+ gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
+ g_object_unref (pixbuf);
}
static gboolean
@@ -1382,17 +1274,18 @@
GtkImage *image)
{
- update_separator_image (image);
- return FALSE;
+ update_separator_image (image);
+ return FALSE;
}
GtkWidget *
_egg_editable_toolbar_new_separator_image (void)
{
- GtkWidget *image = gtk_image_new ();
- update_separator_image (GTK_IMAGE (image));
- g_signal_connect (G_OBJECT (image), "style_set",
- G_CALLBACK (style_set_cb), GTK_IMAGE (image));
+ GtkWidget *image = gtk_image_new ();
+ update_separator_image (GTK_IMAGE (image));
+ g_signal_connect (G_OBJECT (image), "style_set",
+ G_CALLBACK (style_set_cb), GTK_IMAGE (image));
- return image;
+ return image;
}
+
Modified: trunk/src/libegg/egg-toolbar-editor.c
==============================================================================
--- trunk/src/libegg/egg-toolbar-editor.c (original)
+++ trunk/src/libegg/egg-toolbar-editor.c Thu Oct 9 00:05:55 2008
@@ -59,71 +59,45 @@
PROP_TOOLBARS_MODEL
};
-static GObjectClass *parent_class = NULL;
+G_DEFINE_TYPE (EggToolbarEditor, egg_toolbar_editor, GTK_TYPE_VBOX);
-#define EGG_TOOLBAR_EDITOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_TOOLBAR_EDITOR, EggToolbarEditorPrivate))
+#define GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_TOOLBAR_EDITOR, EggToolbarEditorPrivate))
struct EggToolbarEditorPrivate
{
GtkUIManager *merge;
EggToolbarsModel *model;
-
+
GtkWidget *table;
GtkWidget *scrolled_window;
-
+
GList *default_actions_list;
GList *actions_list;
};
-GType
-egg_toolbar_editor_get_type (void)
-{
- static GType type = 0;
-
- if (type == 0) {
- static const GTypeInfo our_info = {
- sizeof (EggToolbarEditorClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) egg_toolbar_editor_class_init,
- NULL,
- NULL, /* class_data */
- sizeof (EggToolbarEditor),
- 0, /* n_preallocs */
- (GInstanceInitFunc) egg_toolbar_editor_init
- };
-
- type = g_type_register_static (GTK_TYPE_VBOX,
- "EggToolbarEditor",
- &our_info, 0);
- }
-
- return type;
-}
-
static gint
compare_actions (gconstpointer a, gconstpointer b)
{
g_return_val_if_fail (GTK_IS_ACTION (a), 0);
g_return_val_if_fail (GTK_IS_ACTION (b), 0);
-
+
GValue value_a = { 0, }, value_b = { 0, };
const char *short_label_a, *short_label_b;
int ret;
-
+
g_value_init (&value_a, G_TYPE_STRING);
g_object_get_property (G_OBJECT (a), "short_label", &value_a);
short_label_a = g_value_get_string (&value_a);
-
+
g_value_init (&value_b, G_TYPE_STRING);
g_object_get_property (G_OBJECT (b), "short_label", &value_b);
short_label_b = g_value_get_string (&value_b);
-
+
ret = g_utf8_collate (short_label_a, short_label_b);
-
+
g_value_unset (&value_a);
g_value_unset (&value_b);
-
+
return ret;
}
@@ -133,22 +107,22 @@
{
GList *l;
GtkAction *action = NULL;
-
+
l = gtk_ui_manager_get_action_groups (t->priv->merge);
-
+
g_return_val_if_fail (EGG_IS_TOOLBAR_EDITOR (t), NULL);
g_return_val_if_fail (name != NULL, NULL);
-
+
for (; l != NULL; l = l->next) {
GtkAction *tmp;
-
+
tmp = gtk_action_group_get_action (GTK_ACTION_GROUP (l->data),
name);
if (tmp) {
action = tmp;
}
}
-
+
return action;
}
@@ -158,7 +132,7 @@
{
g_return_if_fail (GTK_IS_UI_MANAGER (merge));
g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (t));
-
+
t->priv->merge = g_object_ref (merge);
}
@@ -176,64 +150,98 @@
EggToolbarsModel *model)
{
g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (t));
-
+
t->priv->model = g_object_ref (model);
-
+
g_signal_connect_object (model, "toolbar_removed",
G_CALLBACK (toolbar_removed_cb), t, 0);
}
static void
-egg_toolbar_editor_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
EggToolbarEditor *t = EGG_TOOLBAR_EDITOR (object);
-
+
switch (prop_id) {
case PROP_MENU_MERGE:
egg_toolbar_editor_set_merge (t, g_value_get_object (value));
break;
+
case PROP_TOOLBARS_MODEL:
egg_toolbar_editor_set_model (t, g_value_get_object (value));
break;
+
default:
break;
}
}
static void
-egg_toolbar_editor_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
EggToolbarEditor *t = EGG_TOOLBAR_EDITOR (object);
-
+
switch (prop_id) {
case PROP_MENU_MERGE:
g_value_set_object (value, t->priv->merge);
break;
+
case PROP_TOOLBARS_MODEL:
g_value_set_object (value, t->priv->model);
break;
+
default:
break;
}
}
static void
+finalize (GObject *object)
+{
+ EggToolbarEditor *editor = EGG_TOOLBAR_EDITOR (object);
+ EggToolbarEditorPrivate *priv = editor->priv;
+
+ g_list_free (priv->default_actions_list);
+ g_list_free (priv->actions_list);
+
+ G_OBJECT_CLASS (egg_toolbar_editor_parent_class)->finalize (object);
+}
+
+static void
+dispose (GObject *object)
+{
+ EggToolbarEditor *editor = EGG_TOOLBAR_EDITOR (object);
+ EggToolbarEditorPrivate *priv = editor->priv;
+
+ if (priv->merge) {
+ g_object_unref (priv->merge);
+ priv->merge = NULL;
+ }
+
+ if (priv->model) {
+ g_object_unref (priv->model);
+ priv->model = NULL;
+ }
+
+ G_OBJECT_CLASS (egg_toolbar_editor_parent_class)->dispose (object);
+}
+
+static void
egg_toolbar_editor_class_init (EggToolbarEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->finalize = egg_toolbar_editor_finalize;
- object_class->set_property = egg_toolbar_editor_set_property;
- object_class->get_property = egg_toolbar_editor_get_property;
-
+
+ object_class->finalize = finalize;
+ object_class->dispose = dispose;
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+
g_object_class_install_property (object_class,
PROP_MENU_MERGE,
g_param_spec_object ("MenuMerge",
@@ -250,27 +258,8 @@
EGG_TYPE_TOOLBARS_MODEL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
-
- g_type_class_add_private (object_class, sizeof (EggToolbarEditorPrivate));
-}
-static void
-egg_toolbar_editor_finalize (GObject *object)
-{
- EggToolbarEditor *editor = EGG_TOOLBAR_EDITOR (object);
-
- if (editor->priv->merge) {
- g_object_unref (editor->priv->merge);
- }
-
- if (editor->priv->model) {
- g_object_unref (editor->priv->model);
- }
-
- g_list_free (editor->priv->default_actions_list);
- g_list_free (editor->priv->actions_list);
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ g_type_class_add_private (object_class, sizeof (EggToolbarEditorPrivate));
}
GtkWidget *
@@ -309,26 +298,28 @@
{
GtkAction *action;
const char *data;
-
+
g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor));
g_return_if_fail (selection_data != NULL);
-
+
if (selection_data->length <= 0 || selection_data->data == NULL) {
return;
}
data = (const char *) selection_data->data;
-
- if (strcmp (data, "separator") == 0) return;
-
+
+ if (strcmp (data, "separator") == 0) {
+ return;
+ }
+
action = find_action (editor, data);
g_return_if_fail (action != NULL);
-
+
if (g_list_find (editor->priv->default_actions_list, action)) {
editor->priv->actions_list = g_list_insert_sorted
(editor->priv->actions_list, action, compare_actions);
}
-
+
update_editor_sheet (editor);
}
@@ -339,14 +330,14 @@
{
GtkAction *action;
g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor));
-
- action = GTK_ACTION (g_object_get_data (G_OBJECT (widget),
+
+ action = GTK_ACTION (g_object_get_data (G_OBJECT (widget),
"egg-action"));
if (action) {
editor->priv->actions_list = g_list_remove
(editor->priv->actions_list, action);
}
-
+
update_editor_sheet (editor);
}
@@ -360,18 +351,18 @@
{
GtkAction *action;
const char *target;
-
- action = GTK_ACTION (g_object_get_data (G_OBJECT (widget),
+
+ action = GTK_ACTION (g_object_get_data (G_OBJECT (widget),
"egg-action"));
-
+
if (action) {
target = gtk_action_get_name (action);
} else {
target = "separator";
}
-
+
gtk_selection_data_set (selection_data,
- selection_data->target, 8,
+ selection_data->target, 8,
(guchar *) target, strlen (target));
}
@@ -381,10 +372,10 @@
gchar *q, *result;
const gchar *p;
gboolean last_underscore;
-
+
q = result = g_malloc (strlen (original) + 1);
last_underscore = FALSE;
-
+
for (p = original; *p; p++) {
if (!last_underscore && *p == '_') {
last_underscore = TRUE;
@@ -393,9 +384,9 @@
*q++ = *p;
}
}
-
+
*q = '\0';
-
+
return result;
}
@@ -403,7 +394,7 @@
set_drag_cursor (GtkWidget *widget)
{
GdkCursor *cursor;
-
+
cursor = marlin_cursor_get (widget, HAND_OPEN);
gdk_window_set_cursor (widget->window, cursor);
gdk_cursor_unref (cursor);
@@ -413,9 +404,9 @@
event_box_realize_cb (GtkWidget *widget, GtkImage *icon)
{
GtkImageType type;
-
+
set_drag_cursor (widget);
-
+
type = gtk_image_get_storage_type (icon);
if (type == GTK_IMAGE_STOCK) {
gchar *stock_id;
@@ -442,12 +433,12 @@
GtkWidget *vbox;
GtkWidget *label;
gchar *label_no_mnemonic = NULL;
-
+
event_box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
gtk_widget_show (event_box);
- gtk_drag_source_set (event_box, GDK_BUTTON1_MASK, source_drag_types,
+ gtk_drag_source_set (event_box, GDK_BUTTON1_MASK, source_drag_types,
n_source_drag_types, action);
g_signal_connect (event_box, "drag_data_get",
G_CALLBACK (drag_data_get_cb), editor);
@@ -455,18 +446,18 @@
G_CALLBACK (editor_drag_data_delete_cb), editor);
g_signal_connect_after (event_box, "realize",
G_CALLBACK (event_box_realize_cb), icon);
-
+
if (action == GDK_ACTION_MOVE) {
g_signal_connect (event_box, "drag_begin",
G_CALLBACK (drag_begin_cb), NULL);
g_signal_connect (event_box, "drag_end",
G_CALLBACK (drag_end_cb), NULL);
}
-
+
vbox = gtk_vbox_new (0, FALSE);
gtk_widget_show (vbox);
gtk_container_add (GTK_CONTAINER (event_box), vbox);
-
+
gtk_widget_show (GTK_WIDGET (icon));
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (icon), FALSE, TRUE, 0);
@@ -475,7 +466,7 @@
g_free (label_no_mnemonic);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
-
+
return event_box;
}
@@ -489,9 +480,9 @@
GtkWidget *viewport;
GtkWidget *item;
GtkWidget *icon;
-
+
g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor));
-
+
viewport = GTK_BIN (editor->priv->scrolled_window)->child;
if (viewport) {
table = GTK_BIN (viewport)->child;
@@ -506,23 +497,23 @@
(GTK_SCROLLED_WINDOW (editor->priv->scrolled_window), table);
gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL,
- dest_drag_types, n_dest_drag_types,
+ dest_drag_types, n_dest_drag_types,
GDK_ACTION_MOVE);
g_signal_connect (table, "drag_data_received",
G_CALLBACK (editor_drag_data_received_cb), editor);
-
+
to_drag = editor->priv->actions_list;
-
+
x = y = 0;
width = 4;
height = (g_list_length (to_drag)) / width + 1;
gtk_table_resize (GTK_TABLE (editor->priv->table), height, width);
-
+
for (l = to_drag; l != NULL; l = l->next) {
GtkAction *action = (l->data);
const char *stock_id, *short_label;
GValue value = { 0, };
-
+
g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (action), "stock_id", &value);
stock_id = g_value_get_string (&value);
@@ -530,9 +521,9 @@
(stock_id ? stock_id : GTK_STOCK_DND,
GTK_ICON_SIZE_LARGE_TOOLBAR);
g_value_unset (&value);
-
+
g_value_init (&value, G_TYPE_STRING);
- g_object_get_property (G_OBJECT (action),
+ g_object_get_property (G_OBJECT (action),
"short_label", &value);
short_label = g_value_get_string (&value);
item = editor_create_item (editor, GTK_IMAGE (icon),
@@ -542,14 +533,14 @@
g_object_set_data (G_OBJECT (item), "egg-action", action);
gtk_table_attach_defaults (GTK_TABLE (editor->priv->table),
item, x, x + 1, y, y + 1);
-
+
x++;
if (x >= width) {
x = 0;
y++;
}
}
-
+
icon = _egg_editable_toolbar_new_separator_image ();
item = editor_create_item (editor, GTK_IMAGE (icon), _("Separator"),
GDK_ACTION_COPY);
@@ -564,21 +555,21 @@
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);
editor->priv->scrolled_window = scrolled_window;
gtk_widget_show (scrolled_window);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_AUTOMATIC,
+ 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,
+ 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);
@@ -592,12 +583,12 @@
static void
egg_toolbar_editor_init (EggToolbarEditor *t)
{
- t->priv = EGG_TOOLBAR_EDITOR_GET_PRIVATE (t);
-
+ t->priv = GET_PRIVATE (t);
+
t->priv->merge = NULL;
t->priv->default_actions_list = NULL;
t->priv->actions_list = NULL;
-
+
setup_editor (t);
}
@@ -702,7 +693,7 @@
if (pc->in_avail == FALSE) {
*error = g_error_new (G_MARKUP_ERROR,
G_MARKUP_ERROR_INVALID_CONTENT,
- "Toolitem '%s' not inside available",
+ "Toolitem '%s' not inside available",
name);
return;
}
Modified: trunk/src/libegg/egg-toolbars-model.c
==============================================================================
--- trunk/src/libegg/egg-toolbars-model.c (original)
+++ trunk/src/libegg/egg-toolbars-model.c Thu Oct 9 00:05:55 2008
@@ -28,10 +28,6 @@
#include <gdk/gdkproperty.h>
-static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass);
-static void egg_toolbars_model_init (EggToolbarsModel *t);
-static void egg_toolbars_model_finalize (GObject *object);
-
enum
{
ITEM_ADDED,
@@ -57,42 +53,15 @@
static guint egg_toolbars_model_signals[LAST_SIGNAL] = { 0 };
-static GObjectClass *parent_class = NULL;
+G_DEFINE_TYPE (EggToolbarsModel, egg_toolbars_model, G_TYPE_OBJECT);
-#define EGG_TOOLBARS_MODEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModelPrivate))
+#define GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModelPrivate))
struct EggToolbarsModelPrivate
{
GNode *toolbars;
};
-GType
-egg_toolbars_model_get_type (void)
-{
- static GType type = 0;
-
- if (type == 0) {
- static const GTypeInfo our_info = {
- sizeof (EggToolbarsModelClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) egg_toolbars_model_class_init,
- NULL,
- NULL, /* class_data */
- sizeof (EggToolbarsModel),
- 0, /* n_preallocs */
- (GInstanceInitFunc) egg_toolbars_model_init
- };
-
- type = g_type_register_static (G_TYPE_OBJECT,
- "EggToolbarsModel",
- &our_info, 0);
- }
-
- return type;
-
-}
-
static char *
egg_toolbars_model_to_string (EggToolbarsModel *t,
const char *version)
@@ -102,15 +71,15 @@
char *str;
g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), NULL);
-
+
tl = t->priv->toolbars;
-
+
doc = g_string_new ("");
g_string_append_printf (doc, "<toolbars version=\"%s\">\n", version);
-
+
for (l1 = tl->children; l1 != NULL; l1 = l1->next) {
EggToolbarsToolbar *toolbar = l1->data;
-
+
if ((toolbar->flags & EGG_TB_MODEL_ICONS_ONLY) == EGG_TB_MODEL_ICONS_ONLY) {
g_string_append_printf (doc, "<toolbar name=\"%s\" style=\"icons-only\">\n",
toolbar->name);
@@ -118,16 +87,16 @@
g_string_append_printf (doc, "<toolbar name=\"%s\">",
toolbar->name);
}
-
+
for (l2 = l1->children; l2 != NULL; l2 = l2->next) {
EggToolbarsItem *item = l2->data;
-
+
if (item->separator) {
g_string_append (doc, "<separator/>\n");
} else {
char *name;
- name = egg_toolbars_model_get_item_name (t, item->type, item->id);
+ name = egg_toolbars_model_get_item_name (t, item->type, item->id);
g_string_append_printf (doc, "<toolitem type=\"%s\" name=\"%s\"/>\n",
item->type, name);
g_free (name);
@@ -136,7 +105,7 @@
g_string_append (doc, "</toolbar>\n");
}
-
+
g_string_append (doc, "</toolbars>");
str = doc->str;
g_string_free (doc, FALSE);
@@ -145,7 +114,7 @@
}
static gboolean
-safe_save_xml (const char *xml_file,
+safe_save_xml (const char *xml_file,
const char *doc)
{
char *tmp_file;
@@ -153,14 +122,14 @@
gboolean old_exist;
gboolean retval = TRUE;
GError *error = NULL;
-
+
tmp_file = g_strconcat (xml_file, ".tmp", NULL);
old_file = g_strconcat (xml_file, ".old", NULL);
-
+
retval = g_file_set_contents (tmp_file, doc, -1, &error);
if (retval == FALSE) {
if (error) {
- g_warning ("Failed to write XML data to %s: %s",
+ g_warning ("Failed to write XML data to %s: %s",
tmp_file, error->message);
g_error_free (error);
}
@@ -169,7 +138,7 @@
}
old_exist = g_file_test (xml_file, G_FILE_TEST_EXISTS);
-
+
if (old_exist) {
if (rename (xml_file, old_file) < 0) {
g_warning ("Failed to rename %s to %s", xml_file, old_file);
@@ -177,7 +146,7 @@
goto failed;
}
}
-
+
if (rename (tmp_file, xml_file) < 0) {
g_warning ("Failed to rename %s to %s", tmp_file, xml_file);
@@ -187,7 +156,7 @@
retval = FALSE;
goto failed;
}
-
+
if (old_exist) {
if (unlink (old_file) < 0) {
g_warning ("Failed to delete old file %s", old_file);
@@ -207,9 +176,9 @@
const char *version)
{
char *doc;
-
+
g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t));
-
+
doc = egg_toolbars_model_to_string (t, version);
safe_save_xml (xml_file, doc);
@@ -220,11 +189,11 @@
toolbars_toolbar_new (const char *name)
{
EggToolbarsToolbar *toolbar;
-
+
toolbar = g_new0 (EggToolbarsToolbar, 1);
toolbar->name = g_strdup (name);
toolbar->flags = 0;
-
+
return toolbar;
}
@@ -234,15 +203,15 @@
gboolean separator)
{
EggToolbarsItem *item;
-
+
g_return_val_if_fail (id != NULL, NULL);
g_return_val_if_fail (type != NULL, NULL);
-
+
item = g_new0 (EggToolbarsItem, 1);
item->id = g_strdup (id);
item->type = g_strdup (type);
item->separator = separator;
-
+
return item;
}
@@ -250,7 +219,7 @@
free_toolbar_node (EggToolbarsToolbar *toolbar)
{
g_return_if_fail (toolbar != NULL);
-
+
g_free (toolbar->name);
g_free (toolbar);
}
@@ -259,7 +228,7 @@
free_item_node (EggToolbarsItem *item)
{
g_return_if_fail (item != NULL);
-
+
g_free (item->id);
g_free (item->type);
g_free (item);
@@ -271,12 +240,12 @@
{
GNode *toolbar_node;
EggToolbarsToolbar *toolbar;
-
+
toolbar_node = g_node_nth_child (t->priv->toolbars, toolbar_position);
g_return_val_if_fail (toolbar_node != NULL, -1);
-
+
toolbar = toolbar_node->data;
-
+
return toolbar->flags;
}
@@ -287,15 +256,15 @@
{
GNode *toolbar_node;
EggToolbarsToolbar *toolbar;
-
+
toolbar_node = g_node_nth_child (t->priv->toolbars, toolbar_position);
g_return_if_fail (toolbar_node != NULL);
-
+
toolbar = toolbar_node->data;
-
+
toolbar->flags = flags;
-
- g_signal_emit (G_OBJECT (t),
+
+ g_signal_emit (G_OBJECT (t),
egg_toolbars_model_signals[TOOLBAR_CHANGED],
0, toolbar_position);
}
@@ -309,16 +278,16 @@
GNode *node;
EggToolbarsItem *item;
int real_position;
-
+
g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t));
-
+
parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position);
item = toolbars_item_new ("separator", "separator", TRUE);
node = g_node_new (item);
g_node_insert (parent_node, position, node);
-
+
real_position = g_node_child_position (parent_node, node);
-
+
g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_ADDED], 0,
toolbar_position, real_position);
}
@@ -334,21 +303,21 @@
GNode *node;
EggToolbarsItem *item;
int real_position;
-
+
g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), FALSE);
g_return_val_if_fail (id != NULL, FALSE);
g_return_val_if_fail (type != NULL, FALSE);
-
+
parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position);
item = toolbars_item_new (id, type, FALSE);
node = g_node_new (item);
g_node_insert (parent_node, position, node);
-
+
real_position = g_node_child_position (parent_node, node);
-
+
g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_ADDED], 0,
toolbar_position, real_position);
-
+
return TRUE;
}
@@ -359,17 +328,17 @@
{
GNode *node;
int real_position;
-
+
g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), -1);
-
+
node = g_node_new (toolbars_toolbar_new (name));
g_node_insert (t->priv->toolbars, position, node);
-
+
real_position = g_node_child_position (t->priv->toolbars, node);
-
+
g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[TOOLBAR_ADDED],
0, real_position);
-
+
return g_node_child_position (t->priv->toolbars, node);
}
@@ -415,7 +384,7 @@
if (strcmp (element_name, "toolbar") == 0) {
int position;
const char *name, *style;
-
+
name = get_prop (attribute_names, attribute_values, "name");
position = egg_toolbars_model_add_toolbar (t, -1, name);
@@ -529,7 +498,7 @@
gsize length;
GError *error = NULL;
gboolean ret;
-
+
g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), FALSE);
ret = g_file_get_contents (xml_file, &contents, &length, &error);
@@ -580,7 +549,7 @@
if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) {
return g_strdup (name);
}
-
+
return NULL;
}
@@ -592,7 +561,7 @@
if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) {
return g_strdup (id);
}
-
+
return NULL;
}
@@ -603,24 +572,33 @@
if (gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE) == type) {
return g_strdup (EGG_TOOLBAR_ITEM_TYPE);
}
-
+
return NULL;
}
static void
+egg_toolbars_model_finalize (GObject *object)
+{
+ EggToolbarsModel *t = EGG_TOOLBARS_MODEL (object);
+
+ /* FIXME free nodes */
+ g_node_destroy (t->priv->toolbars);
+
+ G_OBJECT_CLASS (egg_toolbars_model_parent_class)->finalize (object);
+}
+
+static void
egg_toolbars_model_class_init (EggToolbarsModelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
+
object_class->finalize = egg_toolbars_model_finalize;
-
+
klass->add_item = impl_add_item;
klass->get_item_id = impl_get_item_id;
klass->get_item_name = impl_get_item_name;
klass->get_item_type = impl_get_item_type;
-
+
egg_toolbars_model_signals[ITEM_ADDED] =
g_signal_new ("item_added",
G_OBJECT_CLASS_TYPE (object_class),
@@ -656,27 +634,16 @@
G_STRUCT_OFFSET (EggToolbarsModelClass, toolbar_changed),
NULL, NULL, g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1, G_TYPE_INT);
-
+
g_type_class_add_private (object_class, sizeof (EggToolbarsModelPrivate));
}
static void
egg_toolbars_model_init (EggToolbarsModel *t)
{
- t->priv =EGG_TOOLBARS_MODEL_GET_PRIVATE (t);
-
- t->priv->toolbars = NULL;
-}
+ t->priv = GET_PRIVATE (t);
-static void
-egg_toolbars_model_finalize (GObject *object)
-{
- EggToolbarsModel *t = EGG_TOOLBARS_MODEL (object);
-
- /* FIXME free nodes */
- g_node_destroy (t->priv->toolbars);
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ t->priv->toolbars = NULL;
}
EggToolbarsModel *
@@ -691,19 +658,19 @@
{
GNode *node;
EggTbModelFlags flags;
-
+
g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t));
-
+
flags = egg_toolbars_model_get_flags (t, position);
-
+
if (!(flags & EGG_TB_MODEL_NOT_REMOVABLE)) {
node = g_node_nth_child (t->priv->toolbars, position);
g_return_if_fail (node != NULL);
-
+
free_toolbar_node (node->data);
g_node_destroy (node);
-
- g_signal_emit (G_OBJECT (t),
+
+ g_signal_emit (G_OBJECT (t),
egg_toolbars_model_signals[TOOLBAR_REMOVED],
0, position);
}
@@ -715,19 +682,19 @@
int position)
{
GNode *node, *toolbar;
-
+
g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t));
-
+
toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position);
g_return_if_fail (toolbar != NULL);
-
+
node = g_node_nth_child (toolbar, position);
g_return_if_fail (node != NULL);
-
+
free_item_node (node->data);
g_node_destroy (node);
-
- g_signal_emit (G_OBJECT (t),
+
+ g_signal_emit (G_OBJECT (t),
egg_toolbars_model_signals[ITEM_REMOVED], 0,
toolbar_position, position);
}
@@ -737,10 +704,10 @@
int toolbar_position)
{
GNode *toolbar;
-
+
toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position);
g_return_val_if_fail (toolbar != NULL, -1);
-
+
return g_node_n_children (toolbar);
}
@@ -753,17 +720,17 @@
GNode *toolbar;
GNode *item;
EggToolbarsItem *idata;
-
+
toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position);
g_return_val_if_fail (toolbar != NULL, NULL);
-
+
item = g_node_nth_child (toolbar, position);
g_return_val_if_fail (item != NULL, NULL);
-
+
idata = item->data;
-
+
*is_separator = idata->separator;
-
+
return idata->id;
}
@@ -779,12 +746,12 @@
{
GNode *toolbar;
EggToolbarsToolbar *tdata;
-
+
toolbar = g_node_nth_child (t->priv->toolbars, position);
g_return_val_if_fail (toolbar != NULL, NULL);
-
+
tdata = toolbar->data;
-
+
return tdata->name;
}
Modified: trunk/src/other/gtkvumeter.c
==============================================================================
--- trunk/src/other/gtkvumeter.c (original)
+++ trunk/src/other/gtkvumeter.c Thu Oct 9 00:05:55 2008
@@ -21,70 +21,17 @@
#define VERTICAL_VUMETER_WIDTH 20
#define MIN_VERTICAL_VUMETER_HEIGHT 200
-static void gtk_vumeter_init (GtkVUMeter *vumeter);
-static void gtk_vumeter_class_init (GtkVUMeterClass *class);
-static void gtk_vumeter_finalize (GObject *object);
-static void gtk_vumeter_realize (GtkWidget *widget);
-static void gtk_vumeter_unrealize (GtkWidget *widget);
-static void gtk_vumeter_size_request (GtkWidget *widget, GtkRequisition *requisition);
-static void gtk_vumeter_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
-static gint gtk_vumeter_expose (GtkWidget *widget, GdkEventExpose *event);
-static void gtk_vumeter_free_colors (GtkVUMeter *vumeter);
-static void gtk_vumeter_setup_colors (GtkVUMeter *vumeter);
-static gint gtk_vumeter_sound_level_to_draw_level (GtkVUMeter *vumeter, double level);
-
-static GtkWidgetClass *parent_class = NULL;
+G_DEFINE_TYPE (GtkVUMeter, gtk_vumeter, GTK_TYPE_WIDGET);
enum {
PROP_0,
PROP_SCALE
};
-GType
-gtk_vumeter_get_type (void)
-{
- static GType vumeter_type = 0;
-
- if (!vumeter_type) {
- static const GTypeInfo vumeter_info = {
- sizeof (GtkVUMeterClass),
- NULL, NULL,
- (GClassInitFunc) gtk_vumeter_class_init,
- NULL, NULL, sizeof (GtkVUMeter), 0,
- (GInstanceInitFunc) gtk_vumeter_init,
- };
-
- vumeter_type = g_type_register_static (GTK_TYPE_WIDGET,
- "GtkVUMeter",
- &vumeter_info, 0);
- }
-
- return vumeter_type;
-}
-
-/* Orientation should be a property */
-GtkWidget*
-gtk_vumeter_new (GtkVUMeterOrientation orientation)
-{
- GtkVUMeter *vumeter;
-
- vumeter = gtk_type_new (GTK_TYPE_VUMETER);
- vumeter->orientation = orientation;
- return GTK_WIDGET (vumeter);
-}
-
static void
-gtk_vumeter_init (GtkVUMeter *vumeter)
+finalize (GObject *object)
{
- GTK_WIDGET_SET_FLAGS (vumeter, GTK_NO_WINDOW);
-
- vumeter->peaks_falloff = GTK_VUMETER_PEAKS_FALLOFF_MEDIUM;
-
- vumeter->gc = NULL;
-
- vumeter->rms_level = 0.0;
- vumeter->peak_level = 0.0;
- vumeter->scale = MARLIN_SCALE_LOG;
+ G_OBJECT_CLASS (gtk_vumeter_parent_class)->finalize (object);
}
static void
@@ -131,50 +78,153 @@
}
static void
-gtk_vumeter_class_init (GtkVUMeterClass *class)
+free_colors (GtkVUMeter *vumeter)
{
- GObjectClass *object_class;
- GtkWidgetClass *widget_class;
+ if (vumeter->f_colors) {
+ gdk_colormap_free_colors (vumeter->colormap, vumeter->f_colors,
+ vumeter->colors);
+ g_free (vumeter->f_colors);
+ vumeter->f_colors = NULL;
+ }
- object_class = (GObjectClass*) class;
- widget_class = (GtkWidgetClass*) class;
- parent_class = gtk_type_class(gtk_widget_get_type());
+ if (vumeter->b_colors) {
+ gdk_colormap_free_colors (vumeter->colormap, vumeter->b_colors,
+ vumeter->colors);
+ g_free (vumeter->b_colors);
+ vumeter->b_colors = NULL;
+ }
+}
- object_class->finalize = gtk_vumeter_finalize;
- object_class->set_property = set_property;
- object_class->get_property = get_property;
+static void
+setup_colors (GtkVUMeter *vumeter)
+{
+ int index, colours;
+ int f_step, b_step;
+ int first, second;
+ int log_max = 0;
- widget_class->realize = gtk_vumeter_realize;
- widget_class->unrealize = gtk_vumeter_unrealize;
- widget_class->expose_event = gtk_vumeter_expose;
- widget_class->size_request = gtk_vumeter_size_request;
- widget_class->size_allocate = gtk_vumeter_size_allocate;
+ g_return_if_fail (vumeter->colormap != NULL);
- g_object_class_install_property (object_class,
- PROP_SCALE,
- g_param_spec_enum ("scale",
- "", "",
- MARLIN_TYPE_SCALE,
- MARLIN_SCALE_LOG,
- G_PARAM_READWRITE));
+ if (vumeter->orientation == GTK_VUMETER_VERTICAL) {
+ colours = MAX (GTK_WIDGET (vumeter)->allocation.height - 2, 0);
+ } else {
+ colours = MAX (GTK_WIDGET (vumeter)->allocation.width - 2, 0);
+ }
+
+ if (colours == vumeter->colors) {
+ return;
+ }
+
+ free_colors (vumeter);
+
+ vumeter->colors = colours;
+ if (vumeter->colors == 0)
+ return;
+
+ vumeter->f_colors = g_malloc (vumeter->colors * sizeof (GdkColor));
+ vumeter->b_colors = g_malloc (vumeter->colors * sizeof (GdkColor));
+
+ if (vumeter->scale == MARLIN_SCALE_LINEAR) {
+ first = vumeter->colors / 2;
+ second = vumeter->colors;
+ } else {
+ log_max = -20 * log10 (1.0 / 20.0);
+
+ first = (int) ((double) vumeter->colors * (6.0 / log_max));
+ second = (int) ((double) vumeter->colors * (18.0 / log_max));
+ }
+
+ vumeter->f_colors[0].red = 65535;
+ vumeter->f_colors[0].green = 0;
+ vumeter->f_colors[0].blue = 0;
+
+ vumeter->b_colors[0].red = 49151;
+ vumeter->b_colors[0].green = 0;
+ vumeter->b_colors[0].blue = 0;
+
+ /* Allocate from Red to Yellow */
+ f_step = 65535 / (first - 1);
+ b_step = 49151 / (first - 1);
+
+ for (index = 1; index < first; index++) {
+ vumeter->f_colors[index].red = 65535;
+ vumeter->f_colors[index].green = vumeter->f_colors[index - 1].green + f_step;
+ vumeter->f_colors[index].blue = 0;
+
+ vumeter->b_colors[index].red = 49151;
+ vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green + b_step;
+ vumeter->b_colors[index].blue = 0;
+ }
+
+ /* Allocate from Yellow to Green */
+ f_step = 65535 / (second - first);
+ b_step = 49151 / (second - first);
+
+ for (index = first; index < second; index++) {
+ vumeter->f_colors[index].red = vumeter->f_colors[index - 1].red - f_step;
+ vumeter->f_colors[index].green = vumeter->f_colors[index - 1].green;
+ vumeter->f_colors[index].blue = 0;
+
+ vumeter->b_colors[index].red = vumeter->b_colors[index - 1].red - b_step;
+ vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green;
+ vumeter->b_colors[index].blue = 0;
+ }
+
+ if (vumeter->scale == MARLIN_SCALE_LOG) {
+ /* Allocate from Green to Dark Green */
+ f_step = 32767 / (vumeter->colors - second);
+ b_step = 32767 / (vumeter->colors - second);
+
+ for (index = second; index < vumeter->colors; index++) {
+ vumeter->f_colors[index].red = 0;
+ vumeter->f_colors[index].green = vumeter->f_colors[index - 1].green - f_step;
+ vumeter->f_colors[index].blue = 0;
+
+ vumeter->b_colors[index].red = 0;
+ vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green - b_step;
+ vumeter->b_colors[index].blue = 0;
+ }
+ }
+
+ for (index = 0; index < vumeter->colors; index++) {
+ gdk_colormap_alloc_color (vumeter->colormap,
+ &vumeter->f_colors[index],
+ FALSE, TRUE);
+
+ gdk_colormap_alloc_color (vumeter->colormap,
+ &vumeter->b_colors[index],
+ FALSE, TRUE);
+ }
}
-static void
-gtk_vumeter_finalize (GObject *object)
+static int
+sound_level_to_draw_level (GtkVUMeter *vumeter,
+ double level)
{
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ double draw_level;
+ double height;
+
+ height = GTK_WIDGET (vumeter)->allocation.height - 2;
+
+ if (vumeter->scale == MARLIN_SCALE_LINEAR) {
+ draw_level = 0;
+ } else {
+ draw_level = level * height;
+ }
+
+ return (int) draw_level;
}
static void
-gtk_vumeter_realize (GtkWidget *widget)
+realize (GtkWidget *widget)
{
GtkVUMeter *vumeter = (GtkVUMeter *) widget;
- GTK_WIDGET_CLASS (parent_class)->realize (widget);
+ GTK_WIDGET_CLASS (gtk_vumeter_parent_class)->realize (widget);
/* colors */
vumeter->colormap = gdk_colormap_get_system ();
- gtk_vumeter_setup_colors (vumeter);
+ setup_colors (vumeter);
/* Set up GC */
vumeter->gc = gdk_gc_new (widget->window);
@@ -182,25 +232,22 @@
}
static void
-gtk_vumeter_unrealize (GtkWidget *widget)
+unrealize (GtkWidget *widget)
{
GtkVUMeter *vumeter = (GtkVUMeter *) widget;
- gtk_vumeter_free_colors (vumeter);
+ free_colors (vumeter);
g_object_unref (G_OBJECT (vumeter->gc));
- GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+ GTK_WIDGET_CLASS (gtk_vumeter_parent_class)->unrealize (widget);
}
static void
-gtk_vumeter_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
{
GtkVUMeter *vumeter;
- g_return_if_fail (GTK_IS_VUMETER (widget));
- g_return_if_fail (requisition != NULL);
-
vumeter = GTK_VUMETER (widget);
switch (vumeter->orientation) {
@@ -217,8 +264,8 @@
}
static void
-gtk_vumeter_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
{
GtkVUMeter *vumeter;
@@ -229,12 +276,12 @@
return;
}
- gtk_vumeter_setup_colors (vumeter);
+ setup_colors (vumeter);
}
static gint
-gtk_vumeter_expose (GtkWidget *widget,
- GdkEventExpose *event)
+expose (GtkWidget *widget,
+ GdkEventExpose *event)
{
GtkVUMeter *vumeter;
int index, rms_level, peak_level;
@@ -246,10 +293,9 @@
}
vumeter = GTK_VUMETER (widget);
- rms_level = gtk_vumeter_sound_level_to_draw_level (vumeter,
- vumeter->rms_level);
- peak_level = gtk_vumeter_sound_level_to_draw_level (vumeter,
- vumeter->peak_level);
+ rms_level = sound_level_to_draw_level (vumeter, vumeter->rms_level);
+ peak_level = sound_level_to_draw_level (vumeter, vumeter->peak_level);
+
x = widget->allocation.x;
y = widget->allocation.y;
width = widget->allocation.width;
@@ -257,7 +303,6 @@
switch (vumeter->orientation) {
case GTK_VUMETER_VERTICAL:
-
height -= 3;
for (index = rms_level; index < peak_level; index++) {
@@ -320,143 +365,56 @@
}
static void
-gtk_vumeter_free_colors (GtkVUMeter *vumeter)
-{
- if (vumeter->f_colors) {
- gdk_colormap_free_colors (vumeter->colormap, vumeter->f_colors,
- vumeter->colors);
- g_free (vumeter->f_colors);
- vumeter->f_colors = NULL;
- }
-
- if (vumeter->b_colors) {
- gdk_colormap_free_colors (vumeter->colormap, vumeter->b_colors,
- vumeter->colors);
- g_free (vumeter->b_colors);
- vumeter->b_colors = NULL;
- }
-}
-
-static void
-gtk_vumeter_setup_colors (GtkVUMeter *vumeter)
+gtk_vumeter_class_init (GtkVUMeterClass *class)
{
- int index, colours;
- int f_step, b_step;
- int first, second;
- int log_max = 0;
-
- g_return_if_fail (vumeter->colormap != NULL);
-
- if (vumeter->orientation == GTK_VUMETER_VERTICAL) {
- colours = MAX (GTK_WIDGET (vumeter)->allocation.height - 2, 0);
- } else {
- colours = MAX (GTK_WIDGET (vumeter)->allocation.width - 2, 0);
- }
-
- if (colours == vumeter->colors) {
- return;
- }
-
- gtk_vumeter_free_colors (vumeter);
-
- vumeter->colors = colours;
- if (vumeter->colors == 0)
- return;
-
- vumeter->f_colors = g_malloc (vumeter->colors * sizeof (GdkColor));
- vumeter->b_colors = g_malloc (vumeter->colors * sizeof (GdkColor));
-
- if (vumeter->scale == MARLIN_SCALE_LINEAR) {
- first = vumeter->colors / 2;
- second = vumeter->colors;
- } else {
- log_max = -20 * log10 (1.0 / 20.0);
-
- first = (int) ((double) vumeter->colors * (6.0 / log_max));
- second = (int) ((double) vumeter->colors * (18.0 / log_max));
- }
-
- vumeter->f_colors[0].red = 65535;
- vumeter->f_colors[0].green = 0;
- vumeter->f_colors[0].blue = 0;
-
- vumeter->b_colors[0].red = 49151;
- vumeter->b_colors[0].green = 0;
- vumeter->b_colors[0].blue = 0;
-
- /* Allocate from Red to Yellow */
- f_step = 65535 / (first - 1);
- b_step = 49151 / (first - 1);
-
- for (index = 1; index < first; index++) {
- vumeter->f_colors[index].red = 65535;
- vumeter->f_colors[index].green = vumeter->f_colors[index - 1].green + f_step;
- vumeter->f_colors[index].blue = 0;
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
- vumeter->b_colors[index].red = 49151;
- vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green + b_step;
- vumeter->b_colors[index].blue = 0;
- }
+ object_class = (GObjectClass*) class;
+ widget_class = (GtkWidgetClass*) class;
- /* Allocate from Yellow to Green */
- f_step = 65535 / (second - first);
- b_step = 49151 / (second - first);
+ object_class->finalize = finalize;
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
- for (index = first; index < second; index++) {
- vumeter->f_colors[index].red = vumeter->f_colors[index - 1].red - f_step;
- vumeter->f_colors[index].green = vumeter->f_colors[index - 1].green;
- vumeter->f_colors[index].blue = 0;
+ widget_class->realize = realize;
+ widget_class->unrealize = unrealize;
+ widget_class->expose_event = expose;
+ widget_class->size_request = size_request;
+ widget_class->size_allocate = size_allocate;
- vumeter->b_colors[index].red = vumeter->b_colors[index - 1].red - b_step;
- vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green;
- vumeter->b_colors[index].blue = 0;
- }
-
- if (vumeter->scale == MARLIN_SCALE_LOG) {
- /* Allocate from Green to Dark Green */
- f_step = 32767 / (vumeter->colors - second);
- b_step = 32767 / (vumeter->colors - second);
+ g_object_class_install_property (object_class,
+ PROP_SCALE,
+ g_param_spec_enum ("scale", "", "",
+ MARLIN_TYPE_SCALE,
+ MARLIN_SCALE_LOG,
+ G_PARAM_READWRITE));
+}
- for (index = second; index < vumeter->colors; index++) {
- vumeter->f_colors[index].red = 0;
- vumeter->f_colors[index].green = vumeter->f_colors[index - 1].green - f_step;
- vumeter->f_colors[index].blue = 0;
+static void
+gtk_vumeter_init (GtkVUMeter *vumeter)
+{
+ GTK_WIDGET_SET_FLAGS (vumeter, GTK_NO_WINDOW);
- vumeter->b_colors[index].red = 0;
- vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green - b_step;
- vumeter->b_colors[index].blue = 0;
- }
- }
+ vumeter->peaks_falloff = GTK_VUMETER_PEAKS_FALLOFF_MEDIUM;
- for (index = 0; index < vumeter->colors; index++) {
- gdk_colormap_alloc_color (vumeter->colormap,
- &vumeter->f_colors[index],
- FALSE, TRUE);
+ vumeter->gc = NULL;
- gdk_colormap_alloc_color (vumeter->colormap,
- &vumeter->b_colors[index],
- FALSE, TRUE);
- }
+ vumeter->rms_level = 0.0;
+ vumeter->peak_level = 0.0;
+ vumeter->scale = MARLIN_SCALE_LOG;
}
-static int
-gtk_vumeter_sound_level_to_draw_level (GtkVUMeter *vumeter,
- double level)
-{
- double draw_level;
- double height;
- /* double log_level; */
-
- height = GTK_WIDGET (vumeter)->allocation.height - 2;
- if (vumeter->scale == MARLIN_SCALE_LINEAR) {
- draw_level = 0;
- } else {
- /* log_level = level / MARLIN_MIN_DB; */
- draw_level = level * height;
- }
+/* Orientation should be a property */
+GtkWidget*
+gtk_vumeter_new (GtkVUMeterOrientation orientation)
+{
+ GtkVUMeter *vumeter;
- return (int) draw_level;
+ vumeter = gtk_type_new (GTK_TYPE_VUMETER);
+ vumeter->orientation = orientation;
+ return GTK_WIDGET (vumeter);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]