[gnome-panel/wip/packed-objects: 8/17] panel: Fix addition of objects with the new packed model
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/packed-objects: 8/17] panel: Fix addition of objects with the new packed model
- Date: Thu, 31 Mar 2011 07:00:04 +0000 (UTC)
commit af036d62e837af5ca34334130165c085fd603e65
Author: Vincent Untz <vuntz gnome org>
Date: Wed Mar 30 23:42:50 2011 +0530
panel: Fix addition of objects with the new packed model
gnome-panel/launcher.c | 70 +++++++------
gnome-panel/launcher.h | 34 +++---
gnome-panel/panel-action-button.c | 16 ++--
gnome-panel/panel-action-button.h | 6 +-
gnome-panel/panel-addto.c | 29 ++++--
gnome-panel/panel-applet-frame.c | 9 +-
gnome-panel/panel-applet-frame.h | 3 +-
gnome-panel/panel-menu-bar.c | 7 +-
gnome-panel/panel-menu-bar.h | 5 +-
gnome-panel/panel-menu-button.c | 13 ++-
gnome-panel/panel-menu-button.h | 11 +-
gnome-panel/panel-separator.c | 7 +-
gnome-panel/panel-separator.h | 5 +-
gnome-panel/panel-widget.c | 109 ++++++++++++++++++--
gnome-panel/panel-widget.h | 19 +++-
gnome-panel/panel.c | 201 +++++++++++++++++++++----------------
gnome-panel/panel.h | 19 +----
17 files changed, 349 insertions(+), 214 deletions(-)
---
diff --git a/gnome-panel/launcher.c b/gnome-panel/launcher.c
index 9e00a27..31e9ac7 100644
--- a/gnome-panel/launcher.c
+++ b/gnome-panel/launcher.c
@@ -854,23 +854,27 @@ static void
launcher_new_saved (GtkWidget *dialog,
gpointer data)
{
- PanelWidget *panel;
- int pos;
- const char *uri;
+ PanelWidget *panel;
+ PanelObjectPackType pack_type;
+ int pack_index;
+ const char *uri;
- pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "pos"));
+ pack_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog),
+ "pack-type"));
panel = g_object_get_data (G_OBJECT (dialog), "panel");
+ pack_index = panel_widget_get_new_pack_index (panel, pack_type);
+
uri = panel_ditem_editor_get_uri (PANEL_DITEM_EDITOR (dialog));
if (panel_launcher_get_filename (uri) != NULL)
uri = panel_launcher_get_filename (uri);
- panel_launcher_create (panel->toplevel, pos, uri);
+ panel_launcher_create (panel->toplevel, pack_type, pack_index, uri);
}
void
-ask_about_launcher (const char *file,
- PanelWidget *panel,
- int pos)
+ask_about_launcher (const char *file,
+ PanelWidget *panel,
+ PanelObjectPackType pack_type)
{
GtkWidget *dialog;
GKeyFile *key_file;
@@ -901,20 +905,22 @@ ask_about_launcher (const char *file,
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_widget_get_screen (GTK_WIDGET (panel)));
- g_object_set_data (G_OBJECT (dialog), "pos", GINT_TO_POINTER (pos));
+ g_object_set_data (G_OBJECT (dialog), "pack-type",
+ GINT_TO_POINTER (pack_type));
g_object_set_data (G_OBJECT (dialog), "panel", panel);
gtk_widget_show (dialog);
}
void
-panel_launcher_create_from_info (PanelToplevel *toplevel,
- int position,
- gboolean exec_info,
- const char *exec_or_uri,
- const char *name,
- const char *comment,
- const char *icon)
+panel_launcher_create_from_info (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ gboolean exec_info,
+ const char *exec_or_uri,
+ const char *name,
+ const char *comment,
+ const char *icon)
{
GKeyFile *key_file;
char *location;
@@ -943,7 +949,7 @@ panel_launcher_create_from_info (PanelToplevel *toplevel,
error = NULL;
if (panel_key_file_to_file (key_file, location, &error)) {
- panel_launcher_create (toplevel, position, location);
+ panel_launcher_create (toplevel, pack_type, pack_index, location);
} else {
panel_error_dialog (GTK_WINDOW (toplevel),
gtk_window_get_screen (GTK_WINDOW (toplevel)),
@@ -956,10 +962,11 @@ panel_launcher_create_from_info (PanelToplevel *toplevel,
g_key_file_free (key_file);
}
-void
-panel_launcher_create_with_id (const char *toplevel_id,
- int position,
- const char *location)
+static void
+panel_launcher_create_with_id (const char *toplevel_id,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *location)
{
char *id;
GSettings *settings;
@@ -971,8 +978,7 @@ panel_launcher_create_with_id (const char *toplevel_id,
id = panel_layout_object_create_start (PANEL_OBJECT_LAUNCHER,
NULL,
- toplevel_id,
- position, PANEL_OBJECT_PACK_START,
+ toplevel_id, pack_type, pack_index,
&settings);
no_uri = NULL;
@@ -1002,19 +1008,21 @@ panel_launcher_create_with_id (const char *toplevel_id,
}
void
-panel_launcher_create (PanelToplevel *toplevel,
- int position,
- const char *location)
+panel_launcher_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *location)
{
panel_launcher_create_with_id (panel_toplevel_get_id (toplevel),
- position,
+ pack_type, pack_index,
location);
}
gboolean
-panel_launcher_create_copy (PanelToplevel *toplevel,
- int position,
- const char *location)
+panel_launcher_create_copy (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *location)
{
char *new_location;
GFile *source;
@@ -1036,7 +1044,7 @@ panel_launcher_create_copy (PanelToplevel *toplevel,
}
filename = panel_launcher_get_filename (new_location);
- panel_launcher_create (toplevel, position, filename);
+ panel_launcher_create (toplevel, pack_type, pack_index, filename);
g_free (new_location);
return TRUE;
diff --git a/gnome-panel/launcher.h b/gnome-panel/launcher.h
index e788639..350b7bd 100644
--- a/gnome-panel/launcher.h
+++ b/gnome-panel/launcher.h
@@ -29,22 +29,22 @@ typedef struct {
gulong destroy_handler;
} Launcher;
-void panel_launcher_create (PanelToplevel *toplevel,
- int position,
- const char *location);
-void panel_launcher_create_with_id (const char *toplevel_id,
- int position,
- const char *location);
-gboolean panel_launcher_create_copy (PanelToplevel *toplevel,
- int position,
- const char *location);
-void panel_launcher_create_from_info (PanelToplevel *toplevel,
- int position,
- gboolean exec_info,
- const char *exec_or_uri,
- const char *name,
- const char *comment,
- const char *icon);
+void panel_launcher_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *location);
+gboolean panel_launcher_create_copy (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *location);
+void panel_launcher_create_from_info (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ gboolean exec_info,
+ const char *exec_or_uri,
+ const char *name,
+ const char *comment,
+ const char *icon);
void launcher_launch (Launcher *launcher,
GtkWidget *widget);
@@ -59,7 +59,7 @@ void panel_launcher_delete (Launcher *launcher);
void ask_about_launcher (const char *file,
PanelWidget *panel,
- int pos);
+ PanelObjectPackType pack_type);
Launcher * find_launcher (const char *path);
diff --git a/gnome-panel/panel-action-button.c b/gnome-panel/panel-action-button.c
index 68a532d..abc5843 100644
--- a/gnome-panel/panel-action-button.c
+++ b/gnome-panel/panel-action-button.c
@@ -652,7 +652,8 @@ panel_action_button_load_helper (PanelWidget *panel,
void
panel_action_button_create (PanelToplevel *toplevel,
- int position,
+ PanelObjectPackType pack_type,
+ int pack_index,
PanelActionButtonType type)
{
const char *detail;
@@ -662,7 +663,7 @@ panel_action_button_create (PanelToplevel *toplevel,
panel_layout_object_create (PANEL_OBJECT_ACTION,
detail,
panel_toplevel_get_id (toplevel),
- position, PANEL_OBJECT_PACK_START);
+ pack_type, pack_index);
}
void
@@ -704,10 +705,11 @@ panel_action_button_invoke_menu (PanelActionButton *button,
}
gboolean
-panel_action_button_load_from_drag (PanelToplevel *toplevel,
- int position,
- const char *drag_string,
- int *old_applet_idx)
+panel_action_button_load_from_drag (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *drag_string,
+ int *old_applet_idx)
{
PanelActionButtonType type = PANEL_ACTION_NONE;
gboolean retval = FALSE;
@@ -742,7 +744,7 @@ panel_action_button_load_from_drag (PanelToplevel *toplevel,
g_strfreev (elements);
- panel_action_button_create (toplevel, position, type);
+ panel_action_button_create (toplevel, pack_type, pack_index, type);
return retval;
}
diff --git a/gnome-panel/panel-action-button.h b/gnome-panel/panel-action-button.h
index 982999c..31f4087 100644
--- a/gnome-panel/panel-action-button.h
+++ b/gnome-panel/panel-action-button.h
@@ -57,7 +57,8 @@ struct _PanelActionButtonClass {
GType panel_action_button_get_type (void) G_GNUC_CONST;
void panel_action_button_create (PanelToplevel *toplevel,
- int position,
+ PanelObjectPackType pack_type,
+ int pack_index,
PanelActionButtonType type);
void panel_action_button_set_type (PanelActionButton *button,
@@ -75,7 +76,8 @@ void panel_action_button_set_dnd_enabled (PanelActionButton *button,
gboolean dnd_enabled);
gboolean panel_action_button_load_from_drag (PanelToplevel *toplevel,
- int position,
+ PanelObjectPackType pack_type,
+ int pack_index,
const char *drag_string,
int *old_applet_idx);
diff --git a/gnome-panel/panel-addto.c b/gnome-panel/panel-addto.c
index 9c96cbc..09f832c 100644
--- a/gnome-panel/panel-addto.c
+++ b/gnome-panel/panel-addto.c
@@ -73,7 +73,7 @@ typedef struct {
guint name_notify;
- int insertion_position;
+ PanelObjectPackType insert_pack_type;
} PanelAddtoDialog;
static GQuark panel_addto_dialog_quark = 0;
@@ -753,17 +753,24 @@ static void
panel_addto_add_item (PanelAddtoDialog *dialog,
PanelAddtoItemInfo *item_info)
{
+ int pack_index;
+
g_assert (item_info != NULL);
+ pack_index = panel_widget_get_new_pack_index (dialog->panel_widget,
+ dialog->insert_pack_type);
+
switch (item_info->type) {
case PANEL_ADDTO_APPLET:
panel_applet_frame_create (dialog->panel_widget->toplevel,
- dialog->insertion_position,
+ dialog->insert_pack_type,
+ pack_index,
item_info->iid);
break;
case PANEL_ADDTO_ACTION:
panel_action_button_create (dialog->panel_widget->toplevel,
- dialog->insertion_position,
+ dialog->insert_pack_type,
+ pack_index,
item_info->action_type);
break;
case PANEL_ADDTO_LAUNCHER_MENU:
@@ -771,27 +778,31 @@ panel_addto_add_item (PanelAddtoDialog *dialog,
break;
case PANEL_ADDTO_LAUNCHER:
panel_launcher_create (dialog->panel_widget->toplevel,
- dialog->insertion_position,
+ dialog->insert_pack_type,
+ pack_index,
item_info->launcher_path);
break;
case PANEL_ADDTO_LAUNCHER_NEW:
ask_about_launcher (NULL, dialog->panel_widget,
- dialog->insertion_position);
+ dialog->insert_pack_type);
break;
case PANEL_ADDTO_MENU:
panel_menu_button_create (dialog->panel_widget->toplevel,
- dialog->insertion_position,
+ dialog->insert_pack_type,
+ pack_index,
item_info->menu_filename,
item_info->menu_path,
item_info->name);
break;
case PANEL_ADDTO_MENUBAR:
panel_menu_bar_create (dialog->panel_widget->toplevel,
- dialog->insertion_position);
+ dialog->insert_pack_type,
+ pack_index);
break;
case PANEL_ADDTO_SEPARATOR:
panel_separator_create (dialog->panel_widget->toplevel,
- dialog->insertion_position);
+ dialog->insert_pack_type,
+ pack_index);
break;
}
}
@@ -1401,7 +1412,7 @@ panel_addto_present (GtkMenuItem *item,
panel_addto_present_applets (dialog);
}
- dialog->insertion_position = pd ? pd->insertion_pos : -1;
+ dialog->insert_pack_type = pd ? pd->insert_pack_type : PANEL_OBJECT_PACK_START;
gtk_window_set_screen (GTK_WINDOW (dialog->addto_dialog), screen);
gtk_window_set_default_size (GTK_WINDOW (dialog->addto_dialog),
height * 8 / 7, height);
diff --git a/gnome-panel/panel-applet-frame.c b/gnome-panel/panel-applet-frame.c
index 5bf26d4..a19735e 100644
--- a/gnome-panel/panel-applet-frame.c
+++ b/gnome-panel/panel-applet-frame.c
@@ -1004,14 +1004,15 @@ panel_applet_frame_load (PanelWidget *panel_widget,
}
void
-panel_applet_frame_create (PanelToplevel *toplevel,
- int position,
- const char *iid)
+panel_applet_frame_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *iid)
{
g_return_if_fail (iid != NULL);
panel_layout_object_create (PANEL_OBJECT_APPLET,
iid,
panel_toplevel_get_id (toplevel),
- position, PANEL_OBJECT_PACK_START);
+ pack_type, pack_index);
}
diff --git a/gnome-panel/panel-applet-frame.h b/gnome-panel/panel-applet-frame.h
index 2ef72c3..3b9de81 100644
--- a/gnome-panel/panel-applet-frame.h
+++ b/gnome-panel/panel-applet-frame.h
@@ -80,7 +80,8 @@ struct _PanelAppletFrame {
GType panel_applet_frame_get_type (void) G_GNUC_CONST;
void panel_applet_frame_create (PanelToplevel *toplevel,
- int position,
+ PanelObjectPackType pack_type,
+ int pack_index,
const char *iid);
void panel_applet_frame_load (PanelWidget *panel_widget,
diff --git a/gnome-panel/panel-menu-bar.c b/gnome-panel/panel-menu-bar.c
index c1f2139..b18d447 100644
--- a/gnome-panel/panel-menu-bar.c
+++ b/gnome-panel/panel-menu-bar.c
@@ -431,12 +431,13 @@ panel_menu_bar_load (PanelWidget *panel,
}
void
-panel_menu_bar_create (PanelToplevel *toplevel,
- int position)
+panel_menu_bar_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index)
{
panel_layout_object_create (PANEL_OBJECT_MENU_BAR, NULL,
panel_toplevel_get_id (toplevel),
- position, PANEL_OBJECT_PACK_START);
+ pack_type, pack_index);
}
void
diff --git a/gnome-panel/panel-menu-bar.h b/gnome-panel/panel-menu-bar.h
index 874b3fb..25f6d6f 100644
--- a/gnome-panel/panel-menu-bar.h
+++ b/gnome-panel/panel-menu-bar.h
@@ -53,8 +53,9 @@ struct _PanelMenuBarClass {
GType panel_menu_bar_get_type (void) G_GNUC_CONST;
-void panel_menu_bar_create (PanelToplevel *toplevel,
- int position);
+void panel_menu_bar_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index);
void panel_menu_bar_load (PanelWidget *panel,
const char *id,
diff --git a/gnome-panel/panel-menu-button.c b/gnome-panel/panel-menu-button.c
index f0b9b3f..ef95dfb 100644
--- a/gnome-panel/panel-menu-button.c
+++ b/gnome-panel/panel-menu-button.c
@@ -764,11 +764,12 @@ panel_menu_button_load (PanelWidget *panel,
}
gboolean
-panel_menu_button_create (PanelToplevel *toplevel,
- int position,
- const char *filename,
- const char *menu_path,
- const char *tooltip)
+panel_menu_button_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *filename,
+ const char *menu_path,
+ const char *tooltip)
{
char *id;
GSettings *settings;
@@ -784,7 +785,7 @@ panel_menu_button_create (PanelToplevel *toplevel,
id = panel_layout_object_create_start (PANEL_OBJECT_MENU, NULL,
panel_toplevel_get_id (toplevel),
- position, PANEL_OBJECT_PACK_START,
+ pack_type, pack_index,
&settings);
settings_instance = panel_layout_get_instance_settings (settings,
diff --git a/gnome-panel/panel-menu-button.h b/gnome-panel/panel-menu-button.h
index 08b561d..dfbfecc 100644
--- a/gnome-panel/panel-menu-button.h
+++ b/gnome-panel/panel-menu-button.h
@@ -54,11 +54,12 @@ struct _PanelMenuButtonClass {
GType panel_menu_button_get_type (void) G_GNUC_CONST;
-gboolean panel_menu_button_create (PanelToplevel *toplevel,
- int position,
- const char *filename,
- const char *menu_path,
- const char *tooltip);
+gboolean panel_menu_button_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *filename,
+ const char *menu_path,
+ const char *tooltip);
gboolean panel_menu_button_is_main_menu (PanelMenuButton *button);
void panel_menu_button_set_menu_path (PanelMenuButton *button,
diff --git a/gnome-panel/panel-separator.c b/gnome-panel/panel-separator.c
index 2b579aa..869ab67 100644
--- a/gnome-panel/panel-separator.c
+++ b/gnome-panel/panel-separator.c
@@ -256,12 +256,13 @@ panel_separator_load (PanelWidget *panel,
}
void
-panel_separator_create (PanelToplevel *toplevel,
- int position)
+panel_separator_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index)
{
panel_layout_object_create (PANEL_OBJECT_SEPARATOR, NULL,
panel_toplevel_get_id (toplevel),
- position, PANEL_OBJECT_PACK_START);
+ pack_type, pack_index);
}
void
diff --git a/gnome-panel/panel-separator.h b/gnome-panel/panel-separator.h
index 982916f..40dc922 100644
--- a/gnome-panel/panel-separator.h
+++ b/gnome-panel/panel-separator.h
@@ -52,8 +52,9 @@ struct _PanelSeparatorClass {
};
GType panel_separator_get_type (void) G_GNUC_CONST;
-void panel_separator_create (PanelToplevel *toplevel,
- int position);
+void panel_separator_create (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index);
void panel_separator_load (PanelWidget *panel_widget,
const char *id,
GSettings *settings);
diff --git a/gnome-panel/panel-widget.c b/gnome-panel/panel-widget.c
index af752d3..94aa482 100644
--- a/gnome-panel/panel-widget.c
+++ b/gnome-panel/panel-widget.c
@@ -1743,6 +1743,73 @@ panel_widget_get_cursorloc (PanelWidget *panel)
return y;
}
+/* get pack type & index for insertion at the cursor location in panel */
+void
+panel_widget_get_insert_at_cursor (PanelWidget *widget,
+ int offset,
+ PanelObjectPackType *pack_type,
+ int *pack_index)
+{
+ int pos;
+ GList *l;
+ AppletData *ad;
+
+ g_return_if_fail (PANEL_IS_WIDGET (widget));
+
+ pos = panel_widget_get_cursorloc (widget) - offset;
+
+ /* check if cursor is in an object; in this case, return the pack type
+ * of the object */
+ for (l = widget->applet_list; l; l = l->next) {
+ ad = l->data;
+
+ if (ad->constrained <= pos) {
+ if (ad->constrained + ad->cells > pos) {
+ *pack_type = ad->pack_type;
+ *pack_index = ad->pack_index;
+ }
+ } else
+ break;
+ }
+
+ if (pos <= widget->size / 2)
+ *pack_type = PANEL_OBJECT_PACK_START;
+ else
+ *pack_type = PANEL_OBJECT_PACK_END;
+
+ *pack_index = panel_widget_get_new_pack_index (widget, *pack_type);
+}
+
+/* get pack type for insertion at the cursor location in panel */
+PanelObjectPackType
+panel_widget_get_insert_pack_type_at_cursor (PanelWidget *panel)
+{
+ PanelObjectPackType ret = PANEL_OBJECT_PACK_START;
+ int pack_index = 0;
+
+ panel_widget_get_insert_at_cursor (panel, 0, &ret, &pack_index);
+
+ return ret;
+}
+
+/* get index for insertion with pack type */
+int
+panel_widget_get_new_pack_index (PanelWidget *panel,
+ PanelObjectPackType pack_type)
+{
+ GList *l;
+ AppletData *ad;
+ int max_pack_index = -1;
+
+ for (l = panel->applet_list; l; l = l->next) {
+ ad = l->data;
+ if (ad->pack_type == pack_type)
+ max_pack_index = MAX (max_pack_index, ad->pack_index);
+ }
+
+ return max_pack_index + 1;
+}
+
/*calculates the value to move the applet by*/
static int
panel_widget_get_moveby (PanelWidget *panel, int pos, int offset)
@@ -1929,14 +1996,19 @@ panel_widget_applet_move_to_cursor (PanelWidget *panel)
panel_widget_is_cursor (new_panel,10) &&
panel_screen_from_panel_widget (panel) ==
panel_screen_from_panel_widget (new_panel)) {
- pos = panel_widget_get_moveby (new_panel, 0, ad->drag_off);
+ PanelObjectPackType pack_type = PANEL_OBJECT_PACK_START;
+ int pack_index = 0;
- if (pos < 0) pos = 0;
+ panel_widget_get_insert_at_cursor (new_panel,
+ ad->drag_off,
+ &pack_type,
+ &pack_index);
panel_widget_applet_drag_end (panel);
/*disable reentrancy into this function*/
- if (!panel_widget_reparent (panel, new_panel, applet, pos)) {
+ if (!panel_widget_reparent (panel, new_panel, applet,
+ pack_type, pack_index)) {
panel_widget_applet_drag_start (
panel, applet, ad->drag_off, GDK_CURRENT_TIME);
continue;
@@ -2383,19 +2455,21 @@ panel_widget_add (PanelWidget *panel,
}
gboolean
-panel_widget_reparent (PanelWidget *old_panel,
- PanelWidget *new_panel,
- GtkWidget *applet,
- int pos)
+panel_widget_reparent (PanelWidget *old_panel,
+ PanelWidget *new_panel,
+ GtkWidget *applet,
+ PanelObjectPackType pack_type,
+ int pack_index)
{
AppletData *ad;
GtkWidget *focus_widget = NULL;
AppletInfo* info;
+ GList *l;
g_return_val_if_fail(PANEL_IS_WIDGET(old_panel), FALSE);
g_return_val_if_fail(PANEL_IS_WIDGET(new_panel), FALSE);
g_return_val_if_fail(GTK_IS_WIDGET(applet), FALSE);
- g_return_val_if_fail(pos>=0, FALSE);
+ g_return_val_if_fail(pack_index>=0, FALSE);
ad = g_object_get_data (G_OBJECT (applet), PANEL_APPLET_DATA);
g_return_val_if_fail(ad!=NULL, FALSE);
@@ -2408,9 +2482,19 @@ panel_widget_reparent (PanelWidget *old_panel,
info = g_object_get_data (G_OBJECT (ad->applet), "applet_info");
- ad->pos = ad->constrained = panel_widget_get_free_spot (new_panel, ad, pos);
- if (ad->pos == -1)
- ad->pos = ad->constrained = 0;
+ for (l = new_panel->applet_list; l; l = l->next) {
+ AppletData *ad_to_move = l->data;
+ if (ad_to_move->pack_type == pack_type &&
+ ad_to_move->pack_index >= pack_index) {
+ ad_to_move->pack_index++;
+ emit_applet_moved (new_panel, ad_to_move);
+ }
+ }
+
+ ad->pack_type = pack_type;
+ ad->pack_index = pack_index;
+ /* with reparent, we'll call cremove/cadd, which will reinsert ad at
+ * the right place in the list */
gtk_widget_queue_resize (GTK_WIDGET (new_panel));
gtk_widget_queue_resize (GTK_WIDGET (old_panel));
@@ -2620,7 +2704,8 @@ panel_widget_tab_move (PanelWidget *panel,
if (new_panel &&
(new_panel != panel))
- panel_widget_reparent (panel, new_panel, ad->applet, 0);
+ panel_widget_reparent (panel, new_panel, ad->applet,
+ PANEL_OBJECT_PACK_START, 0);
}
static void
diff --git a/gnome-panel/panel-widget.h b/gnome-panel/panel-widget.h
index b338d4c..5bb9105 100644
--- a/gnome-panel/panel-widget.h
+++ b/gnome-panel/panel-widget.h
@@ -161,10 +161,11 @@ void panel_widget_add (PanelWidget *panel,
gboolean use_pack_index);
/*move applet to a different panel*/
-int panel_widget_reparent (PanelWidget *old_panel,
- PanelWidget *new_panel,
- GtkWidget *applet,
- int pos);
+int panel_widget_reparent (PanelWidget *old_panel,
+ PanelWidget *new_panel,
+ GtkWidget *applet,
+ PanelObjectPackType pack_type,
+ int pack_index);
/* use these for drag_off for special cases */
#define PW_DRAG_OFF_CURSOR -1
@@ -195,6 +196,16 @@ void panel_widget_draw_icon (PanelWidget *panel,
/*get pos of the cursor location in panel coordinates*/
int panel_widget_get_cursorloc (PanelWidget *panel);
+/* get pack type & index for insertion at the cursor location in panel */
+void panel_widget_get_insert_at_cursor (PanelWidget *widget,
+ int offset,
+ PanelObjectPackType *pack_type,
+ int *pack_index);
+/* get pack type for insertion at the cursor location in panel */
+PanelObjectPackType panel_widget_get_insert_pack_type_at_cursor (PanelWidget *panel);
+/* get index for insertion with pack type */
+int panel_widget_get_new_pack_index (PanelWidget *panel,
+ PanelObjectPackType pack_type);
/*needed for other panel types*/
gboolean panel_widget_is_cursor (PanelWidget *panel,
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index 3c8db8a..75b1245 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -197,7 +197,7 @@ deactivate_idle (gpointer data)
PanelData *pd = data;
pd->deactivate_idle = 0;
- pd->insertion_pos = -1;
+ pd->insert_pack_type = PANEL_OBJECT_PACK_START;
return FALSE;
}
@@ -335,9 +335,9 @@ panel_popup_menu (PanelToplevel *toplevel,
current_event = gtk_get_current_event ();
if (current_event->type == GDK_BUTTON_PRESS)
- panel_data->insertion_pos = panel_widget_get_cursorloc (panel_widget);
+ panel_data->insert_pack_type = panel_widget_get_insert_pack_type_at_cursor (panel_widget);
else
- panel_data->insertion_pos = -1;
+ panel_data->insert_pack_type = PANEL_OBJECT_PACK_START;
menu = make_popup_panel_menu (panel_widget);
if (!menu)
@@ -496,9 +496,10 @@ reset_background (PanelToplevel *toplevel)
}
static gboolean
-drop_url (PanelWidget *panel,
- int position,
- const char *url)
+drop_url (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *url)
{
enum {
NETSCAPE_URL_URL,
@@ -528,7 +529,8 @@ drop_url (PanelWidget *panel,
else
name = netscape_url[NETSCAPE_URL_NAME];
- panel_launcher_create_from_info (panel->toplevel, position, FALSE,
+ panel_launcher_create_from_info (panel->toplevel, pack_type, pack_index,
+ FALSE,
netscape_url[NETSCAPE_URL_URL],
name, comment, PANEL_ICON_REMOTE);
@@ -539,16 +541,17 @@ drop_url (PanelWidget *panel,
}
static gboolean
-drop_menu (PanelWidget *panel,
- int position,
- const char *menu_filename,
- const char *menu_path)
+drop_menu (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *menu_filename,
+ const char *menu_path)
{
if (!panel_layout_is_writable ())
return FALSE;
return panel_menu_button_create (panel->toplevel,
- position,
+ pack_type, pack_index,
menu_filename,
menu_path,
NULL);
@@ -556,10 +559,11 @@ drop_menu (PanelWidget *panel,
}
static gboolean
-drop_uri (PanelWidget *panel,
- int position,
- const char *uri,
- const char *fallback_icon)
+drop_uri (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *uri,
+ const char *fallback_icon)
{
char *name;
char *comment;
@@ -589,8 +593,8 @@ drop_uri (PanelWidget *panel,
comment = g_strdup_printf (_("Open '%s'"), buf);
g_free (buf);
- panel_launcher_create_from_info (panel->toplevel, position, FALSE,
- uri, name, comment, icon);
+ panel_launcher_create_from_info (panel->toplevel, pack_type, pack_index,
+ FALSE, uri, name, comment, icon);
g_free (name);
g_free (comment);
@@ -600,9 +604,10 @@ drop_uri (PanelWidget *panel,
}
static gboolean
-drop_nautilus_desktop_uri (PanelWidget *panel,
- int pos,
- const char *uri)
+drop_nautilus_desktop_uri (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *uri)
{
gboolean success;
const char *id;
@@ -617,7 +622,7 @@ drop_nautilus_desktop_uri (PanelWidget *panel,
basename = uri + strlen ("x-nautilus-desktop:///");
if (strncmp (basename, "trash", strlen ("trash")) == 0)
- panel_applet_frame_create (panel->toplevel, pos,
+ panel_applet_frame_create (panel->toplevel, pack_type, pack_index,
"OAFIID:GNOME_Panel_TrashApplet");
else if (strncmp (basename, "home", strlen ("home")) == 0) {
char *name;
@@ -631,7 +636,7 @@ drop_nautilus_desktop_uri (PanelWidget *panel,
g_object_unref (file);
panel_launcher_create_from_info (panel->toplevel,
- pos,
+ pack_type, pack_index,
TRUE, /* is_exec? */
"nautilus --no-desktop", /* exec */
name, /* name */
@@ -641,7 +646,7 @@ drop_nautilus_desktop_uri (PanelWidget *panel,
g_free (name);
} else if (strncmp (basename, "computer", strlen ("computer")) == 0)
panel_launcher_create_from_info (panel->toplevel,
- pos,
+ pack_type, pack_index,
TRUE, /* is_exec? */
"nautilus --no-desktop computer://", /* exec */
_("Computer"), /* name */
@@ -649,7 +654,7 @@ drop_nautilus_desktop_uri (PanelWidget *panel,
PANEL_ICON_COMPUTER); /* icon name */
else if (strncmp (basename, "network", strlen ("network")) == 0)
panel_launcher_create_from_info (panel->toplevel,
- pos,
+ pack_type, pack_index,
TRUE, /* is_exec? */
"nautilus --no-desktop network://", /* exec */
_("Network"), /* name */
@@ -662,9 +667,10 @@ drop_nautilus_desktop_uri (PanelWidget *panel,
}
static gboolean
-drop_urilist (PanelWidget *panel,
- int pos,
- char *urilist)
+drop_urilist (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ char *urilist)
{
char **uris;
GFile *home;
@@ -698,33 +704,43 @@ drop_urilist (PanelWidget *panel,
/* FIXME: probably do this only on link,
* in fact, on link always set up a link,
* on copy do all the other stuff. Or something. */
- if ( ! drop_url (panel, pos, uri))
+ if ( ! drop_url (panel, pack_type, pack_index, uri))
success = FALSE;
continue;
}
if (g_ascii_strncasecmp (uri, "x-nautilus-desktop:",
strlen ("x-nautilus-desktop:")) == 0) {
- success = drop_nautilus_desktop_uri (panel, pos, uri);
+ success = drop_nautilus_desktop_uri (panel,
+ pack_type, pack_index,
+ uri);
continue;
}
file = g_file_new_for_uri (uri);
if (g_file_equal (home, file)) {
- success = drop_nautilus_desktop_uri (panel, pos, "x-nautilus-desktop:///home");
+ success = drop_nautilus_desktop_uri (panel,
+ pack_type, pack_index,
+ "x-nautilus-desktop:///home");
g_object_unref (file);
continue;
} else if (g_file_equal (trash, file)) {
- success = drop_nautilus_desktop_uri (panel, pos, "x-nautilus-desktop:///trash");
+ success = drop_nautilus_desktop_uri (panel,
+ pack_type, pack_index,
+ "x-nautilus-desktop:///trash");
g_object_unref (file);
continue;
} else if (g_file_equal (computer, file)) {
- success = drop_nautilus_desktop_uri (panel, pos, "x-nautilus-desktop:///computer");
+ success = drop_nautilus_desktop_uri (panel,
+ pack_type, pack_index,
+ "x-nautilus-desktop:///computer");
g_object_unref (file);
continue;
} else if (g_file_equal (network, file)) {
- success = drop_nautilus_desktop_uri (panel, pos, "x-nautilus-desktop:///network");
+ success = drop_nautilus_desktop_uri (panel,
+ pack_type, pack_index,
+ "x-nautilus-desktop:///network");
g_object_unref (file);
continue;
}
@@ -755,7 +771,9 @@ drop_urilist (PanelWidget *panel,
!strcmp (mime, "application/x-desktop") ||
!strcmp (mime, "application/x-kde-app-info"))) {
if (panel_layout_is_writable ())
- panel_launcher_create (panel->toplevel, pos, uri);
+ panel_launcher_create (panel->toplevel,
+ pack_type, pack_index,
+ uri);
else
success = FALSE;
} else if (type != G_FILE_TYPE_DIRECTORY && can_exec) {
@@ -767,17 +785,18 @@ drop_urilist (PanelWidget *panel,
/* executable and local, so add a
* launcher with it */
ask_about_launcher (filename, panel,
- pos);
+ pack_type);
else
success = FALSE;
g_free (filename);
} else {
- if (!drop_uri (panel, pos, uri,
+ if (!drop_uri (panel, pack_type, pack_index, uri,
PANEL_ICON_UNKNOWN))
success = FALSE;
}
} else {
- if (!drop_uri (panel, pos, uri, PANEL_ICON_UNKNOWN))
+ if (!drop_uri (panel, pack_type, pack_index,
+ uri, PANEL_ICON_UNKNOWN))
success = FALSE;
}
@@ -795,10 +814,11 @@ drop_urilist (PanelWidget *panel,
}
static gboolean
-drop_internal_icon (PanelWidget *panel,
- int pos,
- const char *icon_name,
- int action)
+drop_internal_icon (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *icon_name,
+ int action)
{
Launcher *old_launcher = NULL;
@@ -811,7 +831,8 @@ drop_internal_icon (PanelWidget *panel,
if (action == GDK_ACTION_MOVE)
old_launcher = find_launcher (icon_name);
- if (!panel_launcher_create_copy (panel->toplevel, pos, icon_name))
+ if (!panel_launcher_create_copy (panel->toplevel, pack_type, pack_index,
+ icon_name))
return FALSE;
if (old_launcher && old_launcher->button) {
@@ -831,7 +852,10 @@ drop_internal_icon (PanelWidget *panel,
}
static gboolean
-move_applet (PanelWidget *panel, int pos, int applet_index)
+move_applet (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ int applet_index)
{
GSList *applet_list;
AppletInfo *info;
@@ -844,9 +868,6 @@ move_applet (PanelWidget *panel, int pos, int applet_index)
if ( ! panel_applet_can_freely_move (info))
return FALSE;
- if (pos < 0)
- pos = 0;
-
parent = gtk_widget_get_parent (info->widget);
if (info != NULL &&
@@ -856,15 +877,18 @@ move_applet (PanelWidget *panel, int pos, int applet_index)
panel_widget_reparent (PANEL_WIDGET (parent),
panel,
info->widget,
- pos);
+ pack_type, pack_index);
}
return TRUE;
}
static gboolean
-drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
- int action)
+drop_internal_applet (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *applet_type,
+ int action)
{
int applet_index = -1;
gboolean remove_applet = FALSE;
@@ -876,7 +900,7 @@ drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
if (sscanf (applet_type, "MENU:%d", &applet_index) == 1) {
if (action != GDK_ACTION_MOVE)
g_warning ("Only MOVE supported for menus");
- success = move_applet (panel, pos, applet_index);
+ success = move_applet (panel, pack_type, pack_index, applet_index);
} else if (strncmp (applet_type, "MENU:", strlen ("MENU:")) == 0) {
const char *menu;
@@ -887,15 +911,17 @@ drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
if (!menu_path) {
if (strncmp (menu, "MAIN", strlen ("MAIN")) == 0)
- success = drop_menu (panel, pos, NULL, NULL);
+ success = drop_menu (panel, pack_type, pack_index,
+ NULL, NULL);
else
- success = drop_menu (panel, pos, menu, NULL);
+ success = drop_menu (panel, pack_type, pack_index,
+ menu, NULL);
} else {
char *menu_filename;
menu_filename = g_strndup (menu, menu_path - menu);
menu_path++;
- success = drop_menu (panel, pos,
+ success = drop_menu (panel, pack_type, pack_index,
menu_filename, menu_path);
g_free (menu_filename);
}
@@ -904,7 +930,7 @@ drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
if (panel_layout_is_writable ()) {
remove_applet = panel_action_button_load_from_drag (
panel->toplevel,
- pos,
+ pack_type, pack_index,
applet_type,
&applet_index);
success = TRUE;
@@ -914,7 +940,8 @@ drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
} else if (!strcmp (applet_type, "MENUBAR:NEW")) {
if (panel_layout_is_writable ()) {
- panel_menu_bar_create (panel->toplevel, pos);
+ panel_menu_bar_create (panel->toplevel,
+ pack_type, pack_index);
success = TRUE;
} else {
success = FALSE;
@@ -922,7 +949,8 @@ drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
} else if (!strcmp(applet_type,"SEPARATOR:NEW")) {
if (panel_layout_is_writable ()) {
- panel_separator_create (panel->toplevel, pos);
+ panel_separator_create (panel->toplevel,
+ pack_type, pack_index);
success = TRUE;
} else {
success = FALSE;
@@ -930,7 +958,7 @@ drop_internal_applet (PanelWidget *panel, int pos, const char *applet_type,
} else if (!strcmp(applet_type,"LAUNCHER:ASK")) {
if (panel_layout_is_writable ()) {
- ask_about_launcher (NULL, panel, pos);
+ ask_about_launcher (NULL, panel, pack_type);
success = TRUE;
} else {
success = FALSE;
@@ -980,7 +1008,7 @@ get_target_list (void)
return target_list;
}
-gboolean
+static gboolean
panel_check_dnd_target_data (GtkWidget *widget,
GdkDragContext *context,
guint *ret_info,
@@ -1042,7 +1070,7 @@ do_highlight (GtkWidget *widget, gboolean highlight)
}
}
-gboolean
+static gboolean
panel_check_drop_forbidden (PanelWidget *panel,
GdkDragContext *context,
guint info,
@@ -1135,13 +1163,14 @@ drag_leave_cb (GtkWidget *widget,
panel_toplevel_queue_auto_hide (toplevel);
}
-void
-panel_receive_dnd_data (PanelWidget *panel,
- guint info,
- int pos,
- GtkSelectionData *selection_data,
- GdkDragContext *context,
- guint time_)
+static void
+panel_receive_dnd_data (PanelWidget *panel,
+ guint info,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ GtkSelectionData *selection_data,
+ GdkDragContext *context,
+ guint time_)
{
const guchar *data;
gboolean success = FALSE;
@@ -1155,10 +1184,10 @@ panel_receive_dnd_data (PanelWidget *panel,
switch (info) {
case TARGET_URL:
- success = drop_urilist (panel, pos, (char *)data);
+ success = drop_urilist (panel, pack_type, pack_index, (char *)data);
break;
case TARGET_NETSCAPE_URL:
- success = drop_url (panel, pos, (char *)data);
+ success = drop_url (panel, pack_type, pack_index, (char *)data);
break;
case TARGET_COLOR:
success = set_background_color (panel->toplevel, (guint16 *) data);
@@ -1170,7 +1199,7 @@ panel_receive_dnd_data (PanelWidget *panel,
success = reset_background (panel->toplevel);
break;
case TARGET_DIRECTORY:
- success = drop_uri (panel, pos, (char *)data,
+ success = drop_uri (panel, pack_type, pack_index, (char *)data,
PANEL_ICON_FOLDER);
break;
case TARGET_APPLET:
@@ -1179,18 +1208,22 @@ panel_receive_dnd_data (PanelWidget *panel,
return;
}
if (panel_layout_is_writable ()) {
- panel_applet_frame_create (panel->toplevel, pos, (char *) data);
+ panel_applet_frame_create (panel->toplevel,
+ pack_type, pack_index,
+ (char *) data);
success = TRUE;
} else {
success = FALSE;
}
break;
case TARGET_APPLET_INTERNAL:
- success = drop_internal_applet (panel, pos, (char *)data,
+ success = drop_internal_applet (panel, pack_type, pack_index,
+ (char *)data,
gdk_drag_context_get_selected_action (context));
break;
case TARGET_ICON_INTERNAL:
- success = drop_internal_icon (panel, pos, (char *)data,
+ success = drop_internal_icon (panel, pack_type, pack_index,
+ (char *)data,
gdk_drag_context_get_selected_action (context));
break;
default:
@@ -1210,8 +1243,9 @@ drag_data_recieved_cb (GtkWidget *widget,
guint info,
guint time)
{
- PanelWidget *panel_widget;
- int pos;
+ PanelWidget *panel_widget;
+ PanelObjectPackType pack_type = PANEL_OBJECT_PACK_START;
+ int pack_index = 0;
g_return_if_fail (PANEL_IS_TOPLEVEL (widget));
@@ -1225,20 +1259,11 @@ drag_data_recieved_cb (GtkWidget *widget,
panel_widget = panel_toplevel_get_panel_widget (PANEL_TOPLEVEL (widget));
- pos = panel_widget_get_cursorloc (panel_widget);
+ panel_widget_get_insert_at_cursor (panel_widget, 0, &pack_type, &pack_index);
- /*
- * -1 passed to panel_applet_register will turn on
- * the insert_at_pos flag for panel_widget_add_full,
- * which will not place it after the first applet.
- */
- if(pos < 0)
- pos = -1;
- else if(pos > panel_widget->size)
- pos = panel_widget->size;
-
panel_receive_dnd_data (
- panel_widget, info, pos, selection_data, context, time);
+ panel_widget, info, pack_type, pack_index,
+ selection_data, context, time);
}
static void
@@ -1275,7 +1300,7 @@ panel_setup (PanelToplevel *toplevel)
pd = g_new0 (PanelData,1);
pd->menu = NULL;
pd->panel = GTK_WIDGET (toplevel);
- pd->insertion_pos = -1;
+ pd->insert_pack_type = PANEL_OBJECT_PACK_START;
pd->deactivate_idle = 0;
panel_list = g_slist_append (panel_list, pd);
diff --git a/gnome-panel/panel.h b/gnome-panel/panel.h
index 3630b8d..799f54e 100644
--- a/gnome-panel/panel.h
+++ b/gnome-panel/panel.h
@@ -12,7 +12,7 @@ typedef struct _PanelData PanelData;
struct _PanelData {
GtkWidget *panel;
GtkWidget *menu;
- int insertion_pos;
+ PanelObjectPackType insert_pack_type;
guint deactivate_idle;
};
@@ -24,23 +24,6 @@ PanelData *panel_setup (PanelToplevel *toplevel);
GdkScreen *panel_screen_from_panel_widget (PanelWidget *panel);
-gboolean panel_check_dnd_target_data (GtkWidget *widget,
- GdkDragContext *context,
- guint *ret_info,
- GdkAtom *ret_atom);
-
-void panel_receive_dnd_data (PanelWidget *panel,
- guint info,
- int pos,
- GtkSelectionData *selection_data,
- GdkDragContext *context,
- guint time_);
-
-gboolean panel_check_drop_forbidden (PanelWidget *panel,
- GdkDragContext *context,
- guint info,
- guint time_);
-
void panel_delete (PanelToplevel *toplevel);
GtkWidget *panel_deletion_dialog (PanelToplevel *toplevel);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]