mirror of
https://gitlab.gnome.org/GNOME/glade.git
synced 2025-10-09 00:07:00 -04:00
Bye bye GladeWidget->children, GladeWidget->parent.
This commit is contained in:
parent
4043756d49
commit
db87c89b9f
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
||||
2003-08-21 Paolo Borelli <pborelli@katamail.com>
|
||||
|
||||
* src/glade-widget.[ch]: remove the tree structure (GladeWidget->parent
|
||||
and GladeWidget->children) from struct GladeWidget: gtk holds that info
|
||||
for us.
|
||||
* src/glade-project.[ch]: adapt for the above, it allows to simplify
|
||||
add_widget and remove_widget.
|
||||
* src/glade-command.c: adapt for the above changes.
|
||||
* src/glade-project-view.c: ditto.
|
||||
* src/glade-popuc.c: ditto.
|
||||
* src/glade-editor.c: ditto.
|
||||
* src/glade-gtk.c: ditto.
|
||||
|
||||
2003-08-20 Paolo Borelli <pborelli@katamail.com>
|
||||
|
||||
* src/glade-project-view.c (glade_project_view_add_columns): new
|
||||
|
@ -573,13 +573,13 @@ glade_command_create_execute (GladeCommandCreateDelete *me)
|
||||
GladeWidget *widget = me->widget;
|
||||
GladePlaceholder *placeholder = me->placeholder;
|
||||
|
||||
glade_project_add_widget (widget->project, widget, widget->parent);
|
||||
glade_project_selection_set (widget->project, widget->widget, TRUE);
|
||||
|
||||
if (!GLADE_WIDGET_IS_TOPLEVEL (widget)) {
|
||||
glade_placeholder_replace_with_widget (placeholder, widget);
|
||||
}
|
||||
|
||||
glade_project_add_widget (widget->project, widget->widget);
|
||||
glade_project_selection_set (widget->project, widget->widget, TRUE);
|
||||
|
||||
if (GTK_IS_WIDGET (widget->widget))
|
||||
gtk_widget_show_all (widget->widget);
|
||||
|
||||
@ -590,12 +590,14 @@ static gboolean
|
||||
glade_command_delete_execute (GladeCommandCreateDelete *me)
|
||||
{
|
||||
GladeWidget *widget = me->widget;
|
||||
GladeWidget *parent;
|
||||
|
||||
g_return_val_if_fail (widget != NULL, TRUE);
|
||||
|
||||
if (widget->parent) {
|
||||
parent = glade_widget_get_parent (widget);
|
||||
if (parent) {
|
||||
if (me->placeholder == NULL) {
|
||||
me->placeholder = glade_placeholder_new (widget->parent);
|
||||
me->placeholder = glade_placeholder_new ();
|
||||
g_object_ref (G_OBJECT (me->placeholder));
|
||||
}
|
||||
|
||||
@ -604,7 +606,7 @@ glade_command_delete_execute (GladeCommandCreateDelete *me)
|
||||
|
||||
gtk_widget_hide (widget->widget);
|
||||
|
||||
glade_project_remove_widget (widget);
|
||||
glade_project_remove_widget (widget->project, widget->widget);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -779,7 +781,7 @@ glade_command_paste_execute (GladeCommandCutPaste *me)
|
||||
glade_placeholder_replace_with_widget (placeholder, widget);
|
||||
}
|
||||
|
||||
glade_project_add_widget (project, widget, parent);
|
||||
glade_project_add_widget (project, widget->widget);
|
||||
glade_project_selection_set (widget->project, widget->widget, TRUE);
|
||||
|
||||
if (GTK_IS_WIDGET (widget->widget))
|
||||
@ -794,14 +796,16 @@ static gboolean
|
||||
glade_command_cut_execute (GladeCommandCutPaste *me)
|
||||
{
|
||||
GladeWidget *widget = me->widget;
|
||||
GladeWidget *parent;
|
||||
|
||||
g_return_val_if_fail (widget != NULL, TRUE);
|
||||
|
||||
glade_clipboard_add (me->clipboard, widget);
|
||||
|
||||
if (widget->parent) {
|
||||
parent = glade_widget_get_parent (widget);
|
||||
if (parent) {
|
||||
if (me->placeholder == NULL) {
|
||||
me->placeholder = glade_placeholder_new (widget->parent);
|
||||
me->placeholder = glade_placeholder_new ();
|
||||
g_object_ref (G_OBJECT (me->placeholder));
|
||||
}
|
||||
|
||||
@ -810,7 +814,7 @@ glade_command_cut_execute (GladeCommandCutPaste *me)
|
||||
|
||||
gtk_widget_hide (widget->widget);
|
||||
|
||||
glade_project_remove_widget (widget);
|
||||
glade_project_remove_widget (widget->project, widget->widget);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1365,6 +1365,7 @@ glade_editor_load_packing_page (GladeEditor *editor, GladeWidget *widget)
|
||||
GladeEditorProperty *editor_property;
|
||||
GladeEditorTable *table;
|
||||
GladePropertyClass *property_class;
|
||||
GladeWidget *parent;
|
||||
GtkContainer *container;
|
||||
GList *list;
|
||||
|
||||
@ -1389,7 +1390,8 @@ glade_editor_load_packing_page (GladeEditor *editor, GladeWidget *widget)
|
||||
return;
|
||||
|
||||
/* if the widget is a toplevel there are no packing properties */
|
||||
if (!widget->parent)
|
||||
parent = glade_widget_get_parent (widget);
|
||||
if (!parent)
|
||||
return;
|
||||
|
||||
/* Now add the new properties */
|
||||
@ -1398,8 +1400,7 @@ glade_editor_load_packing_page (GladeEditor *editor, GladeWidget *widget)
|
||||
table->common = FALSE;
|
||||
table->packing = TRUE;
|
||||
|
||||
list = widget->parent->class->child_properties;
|
||||
for (; list; list = list->next) {
|
||||
for (list = parent->class->child_properties; list; list = list->next) {
|
||||
property_class = list->data;
|
||||
g_assert (property_class->packing == TRUE);
|
||||
editor_property = glade_editor_table_append_item (table, property_class);
|
||||
|
@ -226,7 +226,7 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
|
||||
|
||||
glade_widget = glade_widget_get_from_gtk_widget (child_widget);
|
||||
if (glade_widget) /* it may be NULL, e.g a placeholder */
|
||||
glade_project_remove_widget (glade_widget);
|
||||
glade_project_remove_widget (glade_widget->project, child_widget);
|
||||
|
||||
gtk_container_remove (GTK_CONTAINER (box), child_widget);
|
||||
|
||||
@ -299,9 +299,8 @@ glade_gtk_notebook_set_n_pages (GObject *object, GValue *value)
|
||||
* If we got it, and its not a placeholder, remove it
|
||||
* from project.
|
||||
*/
|
||||
if (child_gwidget) {
|
||||
glade_project_remove_widget (child_gwidget);
|
||||
}
|
||||
if (child_gwidget)
|
||||
glade_project_remove_widget (child_gwidget->project, child_widget);
|
||||
|
||||
gtk_notebook_remove_page (notebook, old_size-1);
|
||||
old_size--;
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "glade.h"
|
||||
#include "glade-widget.h"
|
||||
#include "glade-widget-class.h"
|
||||
#include "glade-popup.h"
|
||||
#include "glade-placeholder.h"
|
||||
#include "glade-clipboard.h"
|
||||
@ -130,7 +131,7 @@ glade_popup_populate_childs(GtkWidget* popup_menu, GladeWidget* parent)
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu),
|
||||
child);
|
||||
|
||||
parent = parent->parent;
|
||||
parent = glade_widget_get_parent (parent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,8 +153,11 @@ glade_popup_create_menu (GladeWidget *widget, gboolean add_childs)
|
||||
glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, TRUE,
|
||||
glade_popup_delete_cb, widget);
|
||||
|
||||
if (add_childs && widget->parent)
|
||||
glade_popup_populate_childs(popup_menu, widget->parent);
|
||||
if (add_childs && !GLADE_WIDGET_IS_TOPLEVEL (widget)) {
|
||||
GladeWidget *parent = glade_widget_get_parent (widget);
|
||||
g_return_val_if_fail (GLADE_IS_WIDGET (parent), popup_menu);
|
||||
glade_popup_populate_childs(popup_menu, parent);
|
||||
}
|
||||
|
||||
return popup_menu;
|
||||
}
|
||||
|
@ -218,6 +218,7 @@ glade_project_view_add_item (GladeProjectView *view,
|
||||
GladeWidget *widget)
|
||||
{
|
||||
GladeWidgetClass *class;
|
||||
GladeWidget *parent;
|
||||
GtkTreeStore *model;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeIter *parent_iter = NULL;
|
||||
@ -231,10 +232,11 @@ glade_project_view_add_item (GladeProjectView *view,
|
||||
|
||||
model = view->model;
|
||||
|
||||
if (widget->parent != NULL)
|
||||
parent = glade_widget_get_parent (widget);
|
||||
if (parent)
|
||||
parent_iter = glade_project_view_find_iter_by_widget (GTK_TREE_MODEL (model),
|
||||
widget->parent);
|
||||
|
||||
parent);
|
||||
|
||||
gtk_tree_store_append (model, &iter, parent_iter);
|
||||
gtk_tree_store_set (model, &iter,
|
||||
WIDGET_COLUMN, widget,
|
||||
|
@ -164,12 +164,21 @@ glade_project_selection_changed (GladeProject *project)
|
||||
0);
|
||||
}
|
||||
|
||||
static void
|
||||
glade_project_add_widget_real (GladeProject *project,
|
||||
GtkWidget *widget)
|
||||
/**
|
||||
* glade_project_add_widget:
|
||||
* @project: the project the widget is added to
|
||||
* @widget: the GtkWidget to add
|
||||
*
|
||||
* Adds a widget to the project.
|
||||
*/
|
||||
void
|
||||
glade_project_add_widget (GladeProject *project, GtkWidget *widget)
|
||||
{
|
||||
GladeWidget *gwidget;
|
||||
|
||||
g_return_if_fail (GLADE_IS_PROJECT (project));
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
/* We don't list placeholders */
|
||||
if (GLADE_IS_PLACEHOLDER (widget))
|
||||
return;
|
||||
@ -182,7 +191,7 @@ glade_project_add_widget_real (GladeProject *project,
|
||||
list = gtk_container_get_children (GTK_CONTAINER (widget));
|
||||
for (; list; list = list->next) {
|
||||
child = list->data;
|
||||
glade_project_add_widget_real (project, child);
|
||||
glade_project_add_widget (project, child);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,6 +211,7 @@ glade_project_add_widget_real (GladeProject *project,
|
||||
gwidget->project = project;
|
||||
|
||||
project->widgets = g_list_prepend (project->widgets, widget);
|
||||
project->changed = TRUE;
|
||||
g_signal_emit (G_OBJECT (project),
|
||||
glade_project_signals [ADD_WIDGET],
|
||||
0,
|
||||
@ -209,46 +219,23 @@ glade_project_add_widget_real (GladeProject *project,
|
||||
}
|
||||
|
||||
/**
|
||||
* glade_project_add_widget:
|
||||
* @project: the project the widget is added to
|
||||
* @widget: the GladeWidget to add
|
||||
* @parent: the GladeWidget @widget is reparented to
|
||||
* glade_project_remove_widget:
|
||||
* @project: the project the widget is removed from
|
||||
* @widget: the GtkWidget to remove
|
||||
*
|
||||
* Adds a widget to the project. Parent should be NULL for toplevels.
|
||||
*/
|
||||
void
|
||||
glade_project_add_widget (GladeProject *project,
|
||||
GladeWidget *widget,
|
||||
GladeWidget *parent)
|
||||
{
|
||||
g_return_if_fail (GLADE_IS_PROJECT (project));
|
||||
g_return_if_fail (GLADE_IS_WIDGET (widget));
|
||||
|
||||
glade_project_add_widget_real (project, widget->widget);
|
||||
|
||||
/* reparent */
|
||||
widget->parent = parent;
|
||||
if (parent) {
|
||||
g_return_if_fail (GLADE_IS_WIDGET (parent));
|
||||
|
||||
widget->parent = parent;
|
||||
parent->children = g_list_append (parent->children, widget);
|
||||
}
|
||||
|
||||
project->changed = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a widget from the project.
|
||||
* Note that when removing the GtkWidget from the project we
|
||||
* don't change ->project in the associated GladeWidget, this
|
||||
* way UNDO works.
|
||||
*/
|
||||
static void
|
||||
glade_project_remove_widget_real (GladeProject *project,
|
||||
GtkWidget *widget)
|
||||
void
|
||||
glade_project_remove_widget (GladeProject *project, GtkWidget *widget)
|
||||
{
|
||||
GladeWidget *gwidget;
|
||||
|
||||
g_return_if_fail (GLADE_IS_PROJECT (project));
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
if (GLADE_IS_PLACEHOLDER (widget))
|
||||
return;
|
||||
|
||||
@ -260,7 +247,7 @@ glade_project_remove_widget_real (GladeProject *project,
|
||||
list = gtk_container_get_children (GTK_CONTAINER (widget));
|
||||
for (; list; list = list->next) {
|
||||
child = list->data;
|
||||
glade_project_remove_widget_real (project, child);
|
||||
glade_project_remove_widget (project, child);
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,38 +259,13 @@ glade_project_remove_widget_real (GladeProject *project,
|
||||
glade_project_selection_changed (project);
|
||||
|
||||
project->widgets = g_list_remove (project->widgets, widget);
|
||||
project->changed = TRUE;
|
||||
g_signal_emit (G_OBJECT (project),
|
||||
glade_project_signals [REMOVE_WIDGET],
|
||||
0,
|
||||
gwidget);
|
||||
}
|
||||
|
||||
/**
|
||||
* glade_project_remove_widget:
|
||||
* @widget: the GladeWidget to remove
|
||||
*
|
||||
* Remove a widget from the project.
|
||||
*/
|
||||
void
|
||||
glade_project_remove_widget (GladeWidget *widget)
|
||||
{
|
||||
GladeWidget *parent;
|
||||
|
||||
g_return_if_fail (GLADE_IS_WIDGET (widget));
|
||||
|
||||
glade_project_remove_widget_real (widget->project, widget->widget);
|
||||
|
||||
/* remove from the parent's children list */
|
||||
parent = widget->parent;
|
||||
if (parent) {
|
||||
g_return_if_fail (GLADE_IS_WIDGET (parent));
|
||||
|
||||
parent->children = g_list_remove (parent->children, widget);
|
||||
}
|
||||
|
||||
widget->project->changed = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glade_project_widget_name_changed (GladeProject *project,
|
||||
GladeWidget *widget)
|
||||
|
@ -70,11 +70,8 @@ GladeProject *glade_project_new (gboolean untitled);
|
||||
GladeProject *glade_project_open (const gchar *path);
|
||||
gboolean glade_project_save (GladeProject *project, const gchar *path);
|
||||
|
||||
/* Widget related stuff */
|
||||
void glade_project_remove_widget (GladeWidget *widget);
|
||||
void glade_project_add_widget (GladeProject *project,
|
||||
GladeWidget *widget,
|
||||
GladeWidget *parent);
|
||||
void glade_project_add_widget (GladeProject *project, GtkWidget *widget);
|
||||
void glade_project_remove_widget (GladeProject *project, GtkWidget *widget);
|
||||
|
||||
GladeWidget *glade_project_get_widget_by_name (GladeProject *project, const char *name);
|
||||
char *glade_project_new_widget_name (GladeProject *project, const char *base_name);
|
||||
|
@ -192,7 +192,8 @@ static void
|
||||
glade_property_set_property (GladeProperty *property, const GValue *value)
|
||||
{
|
||||
if (property->class->packing) {
|
||||
GtkContainer *container = GTK_CONTAINER (property->widget->parent->widget);
|
||||
GladeWidget *parent = glade_widget_get_parent (property->widget);
|
||||
GtkContainer *container = GTK_CONTAINER (parent->widget);
|
||||
GtkWidget *child = property->widget->widget;
|
||||
gtk_container_child_set_property (container, child, property->class->id, value);
|
||||
} else {
|
||||
|
@ -104,8 +104,6 @@ glade_widget_new (GladeWidgetClass *class)
|
||||
/* we don't have packing properties until we container add the widget */
|
||||
widget->packing_properties = NULL;
|
||||
widget->signals = NULL;
|
||||
widget->parent = NULL;
|
||||
widget->children = NULL;
|
||||
|
||||
return widget;
|
||||
}
|
||||
@ -129,6 +127,34 @@ glade_widget_get_from_gtk_widget (GtkWidget *widget)
|
||||
return glade_widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* glade_widget_get_parent:
|
||||
* @widget
|
||||
*
|
||||
* Convenience function to retrieve the GladeWidget associated
|
||||
* to the parent of @widget.
|
||||
* Returns NULL if it is a toplevel.
|
||||
**/
|
||||
GladeWidget *
|
||||
glade_widget_get_parent (GladeWidget *widget)
|
||||
{
|
||||
GladeWidget *parent = NULL;
|
||||
GtkWidget *parent_widget;
|
||||
|
||||
g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL);
|
||||
|
||||
if (GLADE_WIDGET_IS_TOPLEVEL (widget))
|
||||
return NULL;
|
||||
|
||||
parent_widget = gtk_widget_get_parent (widget->widget);
|
||||
g_return_val_if_fail (parent_widget != NULL, NULL);
|
||||
|
||||
parent = glade_widget_get_from_gtk_widget (parent_widget);
|
||||
g_return_val_if_fail (GLADE_IS_WIDGET (parent), NULL);
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/* A temp data struct that we use when looking for a widget inside a container
|
||||
* we need a struct, because the forall can only pass one pointer
|
||||
*/
|
||||
@ -529,7 +555,6 @@ glade_widget_free (GladeWidget *widget)
|
||||
widget->class = NULL;
|
||||
widget->project = NULL;
|
||||
widget->widget = NULL;
|
||||
widget->parent = NULL;
|
||||
|
||||
if (widget->name)
|
||||
g_free (widget->name);
|
||||
@ -636,7 +661,6 @@ glade_widget_new_full (GladeWidgetClass *class,
|
||||
|
||||
widget = glade_widget_new (class);
|
||||
widget->name = glade_widget_new_name (project, class);
|
||||
widget->parent = parent;
|
||||
widget->project = project;
|
||||
|
||||
widget->widget = glade_widget_create_gtk_widget (class);
|
||||
@ -1037,15 +1061,12 @@ glade_widget_replace_with_placeholder (GladeWidget *widget,
|
||||
g_return_if_fail (GLADE_IS_WIDGET (widget));
|
||||
g_return_if_fail (GLADE_IS_PLACEHOLDER (placeholder));
|
||||
|
||||
parent = widget->parent;
|
||||
parent = glade_widget_get_parent (widget);
|
||||
|
||||
if (parent->class->placeholder_replace) {
|
||||
parent->class->placeholder_replace (widget->widget,
|
||||
GTK_WIDGET (placeholder),
|
||||
parent->widget);
|
||||
|
||||
/* Remove it from the parent's child list */
|
||||
widget->parent->children = g_list_remove (widget->parent->children, widget);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1403,7 +1424,7 @@ glade_widget_new_child_from_node (GladeXmlNode *node,
|
||||
/* is it a placeholder? */
|
||||
child_node = glade_xml_search_child (node, GLADE_XML_TAG_PLACEHOLDER);
|
||||
if (child_node) {
|
||||
child_widget = glade_placeholder_new (parent);
|
||||
child_widget = glade_placeholder_new ();
|
||||
gtk_container_add (GTK_CONTAINER (parent->widget), child_widget);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -8,10 +8,9 @@ G_BEGIN_DECLS
|
||||
#define GLADE_WIDGET(w) ((GladeWidget *)w)
|
||||
#define GLADE_IS_WIDGET(w) (w != NULL)
|
||||
|
||||
/* A GladeWidget is an instance of a GladeWidgetClass. For every widget
|
||||
* in the project there is a GladeWidget
|
||||
/* A GladeWidget is an instance of a GladeWidgetClass.
|
||||
* Each GtkWidget in the project has an associated GladeWidget.
|
||||
*/
|
||||
|
||||
struct _GladeWidget
|
||||
{
|
||||
GladeWidgetClass *class; /* The class of the widget.
|
||||
@ -52,33 +51,28 @@ struct _GladeWidget
|
||||
*/
|
||||
|
||||
GList *signals; /* A list of GladeSignals */
|
||||
|
||||
/* Tree Structure */
|
||||
GladeWidget *parent; /* The parent of this widget, NULL if this is a
|
||||
* toplevel widget.
|
||||
*/
|
||||
GList *children; /* A list of GladeWidget childrens of this widget.
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
gchar * glade_widget_new_name (GladeProject *project, GladeWidgetClass *class);
|
||||
gchar *glade_widget_new_name (GladeProject *project, GladeWidgetClass *class);
|
||||
void glade_widget_set_contents (GladeWidget *widget);
|
||||
void glade_widget_connect_signals (GladeWidget *widget);
|
||||
|
||||
void glade_widget_set_packing_properties (GladeWidget *widget,
|
||||
GladeWidgetClass *container_class);
|
||||
|
||||
GladeWidget * glade_widget_new_from_class (GladeWidgetClass *class,
|
||||
GladeProject *project,
|
||||
GladeWidget *parent);
|
||||
GladeWidget *glade_widget_new_from_class (GladeWidgetClass *class,
|
||||
GladeProject *project,
|
||||
GladeWidget *parent);
|
||||
|
||||
void glade_widget_set_default_packing_options (GladeWidget *widget);
|
||||
|
||||
const gchar * glade_widget_get_name (GladeWidget *widget);
|
||||
GladeWidgetClass * glade_widget_get_class (GladeWidget *widget);
|
||||
GladeProperty * glade_widget_get_property_from_class (GladeWidget *widget,
|
||||
GladePropertyClass *property_class);
|
||||
const gchar *glade_widget_get_name (GladeWidget *widget);
|
||||
|
||||
GladeWidgetClass *glade_widget_get_class (GladeWidget *widget);
|
||||
|
||||
GladeProperty *glade_widget_get_property_from_class (GladeWidget *widget,
|
||||
GladePropertyClass *property_class);
|
||||
|
||||
void glade_widget_set_name (GladeWidget *widget, const gchar *name);
|
||||
|
||||
@ -89,6 +83,8 @@ void glade_widget_replace_with_placeholder (GladeWidget *widget,
|
||||
|
||||
GladeWidget *glade_widget_get_from_gtk_widget (GtkWidget *widget);
|
||||
|
||||
GladeWidget *glade_widget_get_parent (GladeWidget *widget);
|
||||
|
||||
/* Widget signal*/
|
||||
GList *glade_widget_find_signal (GladeWidget *widget, GladeSignal *signal);
|
||||
void glade_widget_add_signal (GladeWidget *widget, GladeSignal *signal);
|
||||
|
Loading…
x
Reference in New Issue
Block a user