set the property

2001-07-15  Chema Celorio  <chema@celorio.com>

	* src/glade-property.c (glade_property_changed_choice): set the property

	* src/glade-widget.c (glade_widget_new_from_class_name): implement
	(glade_widget_new_from_class): no need to pass the project. We know
	it from parent->project. Update all the calls to this function
	(glade_widget_new_toplevel): impl.

	* src/glade-widget-class.c (glade_widget_class_get_by_name): implement

	* src/glade-placeholder.c (glade_placeholder_replace_notebook): implement

	* widgets/gtknotebook.xml: add properties

	* src/glade-placeholder.c (glade_placeholder_add): handle notebook

	* src/glade-widget-class.c (glade_widget_class_add_virtual_methods): handle
	gtk_notebook.
This commit is contained in:
Chema Celorio 2001-07-15 10:22:28 +00:00 committed by Jose Maria Celorio
parent 711ceca471
commit 8fd0cdfa14
13 changed files with 224 additions and 20 deletions

View File

@ -1,3 +1,23 @@
2001-07-15 Chema Celorio <chema@celorio.com>
* src/glade-property.c (glade_property_changed_choice): set the property
* src/glade-widget.c (glade_widget_new_from_class_name): implement
(glade_widget_new_from_class): no need to pass the project. We know
it from parent->project. Update all the calls to this function
(glade_widget_new_toplevel): impl.
* src/glade-widget-class.c (glade_widget_class_get_by_name): implement
* src/glade-placeholder.c (glade_placeholder_replace_notebook): implement
* widgets/gtknotebook.xml: add properties
* src/glade-placeholder.c (glade_placeholder_add): handle notebook
* src/glade-widget-class.c (glade_widget_class_add_virtual_methods): handle
gtk_notebook.
2001-07-10 Chema Celorio <chema@celorio.com>
* src/glade-gtk.c (glade_gtk_entry_set_text): implement.

View File

@ -4,6 +4,10 @@
G_BEGIN_DECLS
#define GLADE_CHOICE(c) ((GladeChoice *)c)
#define GLADE_IS_CHOICE(c) (c != NULL)
/* GladeChoice is used for GladeProperties of type "choice"
* each property of type choice has a list of GladeChoice objects.
* [see glade-property ]

View File

@ -151,7 +151,7 @@ glade_palette_button_clicked (GtkWidget *button, GladePalette *palette)
if (GLADE_WIDGET_CLASS_TOPLEVEL (class)) {
project = glade_project_get_active ();
g_return_if_fail (project != NULL);
glade_widget_new_from_class (project, class, NULL);
glade_widget_new_toplevel (project, class);
dont_recurse = TRUE;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (palette->dummy_button), TRUE);
dont_recurse = FALSE;

View File

@ -116,13 +116,49 @@ glade_placeholder_replace_table (GladePlaceholder *placeholder,
void
glade_placeholder_replace_container (GladePlaceholder *placeholder,
GladeWidget *widget,
GladeWidget *parent)
GladeWidget *widget,
GladeWidget *parent)
{
gtk_container_remove (GTK_CONTAINER (parent->widget), placeholder);
gtk_container_add (GTK_CONTAINER (parent->widget), widget->widget);
}
void
glade_placeholder_replace_notebook (GladePlaceholder *placeholder,
GladeWidget *widget,
GladeWidget *parent)
{
GtkNotebook *notebook;
GtkWidget *page;
GtkWidget *label;
gint page_num;
notebook = GTK_NOTEBOOK (parent->widget);
page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (placeholder));
if (page_num == -1) {
g_warning ("GtkNotebookPage not found\n");
return;
}
page = gtk_notebook_get_nth_page (notebook, page_num);
label = gtk_notebook_get_tab_label (notebook, GTK_WIDGET (placeholder));
gtk_widget_ref (page);
gtk_widget_ref (label);
gtk_notebook_remove_page (notebook, page_num);
gtk_notebook_insert_page (notebook, widget->widget,
label, page_num);
gtk_notebook_set_tab_label (notebook,
widget->widget,
label);
gtk_widget_unref (label);
gtk_widget_unref (page);
gtk_notebook_set_current_page (notebook, page_num);
}
static void
glade_placeholder_replace_widget (GladePlaceholder *placeholder, GladeWidgetClass *class, GladeProject *project)
{
@ -132,7 +168,7 @@ glade_placeholder_replace_widget (GladePlaceholder *placeholder, GladeWidgetClas
parent = glade_placeholder_get_parent (placeholder);
g_return_if_fail (parent != NULL);
widget = glade_widget_new_from_class (parent->project, class, parent);
widget = glade_widget_new_from_class (class, parent);
if (widget == NULL)
return;
@ -325,6 +361,31 @@ glade_placeholder_add (GladeWidgetClass *class,
return;
}
if ((strcmp (class->name, "GtkNotebook") == 0)) {
GladeWidgetClass *label_class;
GladeWidget *label;
gint page;
gint pages = 3;
glade_property_query_result_get_int (result, "pages", &pages);
label_class = glade_widget_class_get_by_name ("GtkLabel");
g_return_if_fail (label_class != NULL);
for (page = 0; page < pages; page++) {
label = glade_widget_new_from_class_name ("GtkLabel",
widget);
g_return_if_fail (GTK_IS_WIDGET (label->widget));
placeholder = glade_placeholder_new (widget);
gtk_notebook_append_page (GTK_NOTEBOOK (widget->widget),
placeholder,
label->widget);
}
return;
}
g_warning ("A new container was cretated but there isn't any code to add a placeholder "
"for this class (%s)", class->name);
}

View File

@ -21,6 +21,10 @@ void glade_placeholder_replace_table (GladePlaceholder *placeholder
void glade_placeholder_replace_container (GladePlaceholder *placeholder,
GladeWidget *widget,
GladeWidget *parent);
void glade_placeholder_replace_notebook (GladePlaceholder *placeholder,
GladeWidget *widget,
GladeWidget *parent);
G_END_DECLS

View File

@ -170,7 +170,7 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
}
static GladeChoice *
glade_property_class_get_choice_from_value (GEnumValue value)
glade_property_class_choice_new_from_value (GEnumValue value)
{
GladeChoice *choice;
@ -196,7 +196,7 @@ glade_property_class_get_choices_from_spec (GParamSpec *spec)
num = class->n_values;
for (i = 0; i < num; i++) {
value = class->values[i];
choice = glade_property_class_get_choice_from_value (value);
choice = glade_property_class_choice_new_from_value (value);
if (choice)
list = g_list_prepend (list, choice);
}

View File

@ -348,6 +348,9 @@ glade_property_changed_choice (GladeProperty *property, GladeChoice *choice)
g_free (property->value);
property->value = g_strdup_printf ("%s", choice->symbol);
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id, choice->value, NULL);
}

View File

@ -41,6 +41,8 @@
#include "glade-placeholder.h"
#include "glade-property.h"
#include "glade-property-class.h"
#include "glade-project-window.h"
#include "glade-catalog.h"
#include "glade-choice.h"
#include "glade-parameter.h"
#include "glade-widget-class.h"
@ -98,9 +100,11 @@ glade_widget_class_add_virtual_methods (GladeWidgetClass *class)
class->placeholder_replace = glade_placeholder_replace_box;
if (strcmp (class->name, "GtkTable") == 0)
class->placeholder_replace = glade_placeholder_replace_table;
if ((strcmp (class->name, "GtkWindow") == 0) ||
(strcmp (class->name, "GtkFrame") == 0) ||
(strcmp (class->name, "GtkHandleBox") == 0))
if (strcmp (class->name, "GtkNotebook") == 0)
class->placeholder_replace = glade_placeholder_replace_notebook;
if ((strcmp (class->name, "GtkWindow") == 0) ||
(strcmp (class->name, "GtkFrame") == 0) ||
(strcmp (class->name, "GtkHandleBox") == 0 ))
class->placeholder_replace = glade_placeholder_replace_container;
if (class->placeholder_replace == NULL)
@ -407,3 +411,30 @@ glade_widget_class_dump_param_specs (GladeWidgetClass *class)
g_print ("%02d - %s\n", i, spec->name);
}
}
GladeWidgetClass *
glade_widget_class_get_by_name (const gchar *name)
{
GladeProjectWindow *gpw;
GladeWidgetClass *class;
GList *list;
g_return_val_if_fail (name != NULL, NULL);
gpw = glade_project_window_get ();
list = gpw->catalog->widgets;
for (; list != NULL; list = list->next) {
class = list->data;
g_return_val_if_fail (class->name != NULL, NULL);
if (class->name == NULL)
return NULL;
if (strcmp (class->name, name) == 0)
return class;
}
g_warning ("Class not found by name %s\n", name);
return NULL;
}

View File

@ -70,6 +70,7 @@ struct _GladeWidgetClassSignal {
};
GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name);
GladeWidgetClass * glade_widget_class_get_by_name (const gchar *name);
const gchar * glade_widget_class_get_name (GladeWidgetClass *class);
GType glade_widget_class_get_type (GladeWidgetClass *class);

View File

@ -562,14 +562,15 @@ glade_widget_create_gtk_widget (GladeProject *project,
*
* Return Value: A newly creatred GladeWidget, NULL on user cancel or error
**/
GladeWidget *
glade_widget_new_from_class (GladeProject *project, GladeWidgetClass *class, GladeWidget *parent)
static GladeWidget *
glade_widget_new_from_class_full (GladeWidgetClass *class, GladeProject *project, GladeWidget *parent)
{
GladePropertyQueryResult *result = NULL;
GladeWidget *glade_widget;
g_return_val_if_fail (project != NULL, NULL);
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), NULL);
g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL);
if (glade_widget_class_has_queries (class)) {
result = glade_property_query_result_new ();
if (glade_project_window_query_properties (class, result))
@ -588,7 +589,30 @@ glade_widget_new_from_class (GladeProject *project, GladeWidgetClass *class, Gla
return glade_widget;
}
GladeWidget *
glade_widget_new_from_class (GladeWidgetClass *class, GladeWidget *parent)
{
GladeProject *project;
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), NULL);
g_return_val_if_fail (GLADE_IS_WIDGET (parent), NULL);
g_return_val_if_fail (GLADE_IS_PROJECT (parent->project), NULL);
project = parent->project;
return glade_widget_new_from_class_full (class, project, parent);
}
GladeWidget *
glade_widget_new_toplevel (GladeProject *project, GladeWidgetClass *class)
{
g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL);
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), NULL);
return glade_widget_new_from_class_full (class, project, NULL);
}
const gchar *
glade_widget_get_name (GladeWidget *widget)
@ -677,3 +701,33 @@ glade_widget_delete (GladeWidget *widget)
g_print ("Implement delete. Widget : %s\n",
glade_widget_get_name (widget));
}
/**
* glade_widget_new_from_class_name:
* @class_name:
* @parent:
*
* Given a class name, it creates a GladeWidget
*
* Return Value: the newly created GladeWidget, NULL on error
**/
GladeWidget *
glade_widget_new_from_class_name (const gchar *name,
GladeWidget *parent)
{
GladeWidgetClass *class;
GladeWidget *widget;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (GLADE_IS_WIDGET (parent), NULL);
class = glade_widget_class_get_by_name (name);
if (class == NULL)
return NULL;
widget = glade_widget_new_from_class (class, parent);
return widget;
}

View File

@ -64,9 +64,13 @@ struct _GladeWidgetSignal {
};
GladeWidget * glade_widget_new_from_class (GladeProject *project,
GladeWidgetClass *class,
GladeWidget * glade_widget_new_toplevel (GladeProject *project,
GladeWidgetClass *class);
GladeWidget * glade_widget_new_from_class (GladeWidgetClass *class,
GladeWidget *widget);
GladeWidget * glade_widget_new_from_class_name (const gchar *class_name,
GladeWidget *parent);
const gchar * glade_widget_get_name (GladeWidget *widget);
GladeWidgetClass * glade_widget_get_class (GladeWidget *widget);

View File

@ -4,10 +4,35 @@
<GetTypeFunction>gtk_notebook_get_type</GetTypeFunction>
<GenericName>notebook</GenericName>
<Toplevel>False</Toplevel>
<Placeholder>True</Placeholder>
<Properties>
<Property ParamSpec="TRUE" Id="name"/>
<Property ParamSpec="TRUE" Id="border-width"/>
<Property ParamSpec="TRUE" Id="show-tabs"/>
<Property ParamSpec="TRUE" Id="show-border"/>
<Property ParamSpec="TRUE" Id="tab-pos"/>
<Property ParamSpec="TRUE" Id="scrollable"/>
<Property ParamSpec="TRUE" Id="tab-hborder"/>
<Property ParamSpec="TRUE" Id="tab-vborder"/>
<Property ParamSpec="TRUE" Id="enable-popup"/>
<Property ParamSpec="FALSE" Id="pages" Name="Number of pages">
<Type>Integer</Type>
<Tooltip>The number of pages in the notebook</Tooltip>
<Parameters>
<Parameter Key="Min" Value="1"/>
<Parameter Key="Max" Value="100"/>
<Parameter Key="Default" Value="3"/>
<Parameter Key="StepIncrement" Value="1"/>
<Parameter Key="PageIncrement" Value="1"/>
<Parameter Key="ClibmRate" Value="1"/>
</Parameters>
<Query>
<WindowTitle>New Notebook</WindowTitle>
<Question>Number of pages</Question>
</Query>
</Property>
</Properties>

View File

@ -18,7 +18,6 @@
<Type>Integer</Type>
<Name>Rows</Name>
<Tooltip>The number of rows in the table</Tooltip>
<GtkArg>rows</GtkArg>
<Parameters>
<Parameter Key="Min" Value="0"/>
<Parameter Key="Max" Value="10000"/>
@ -33,11 +32,9 @@
</Query>
</Property>
<Property Id="columns">
<Property Id="columns" Name="Columns">
<Type>Integer</Type>
<Name>Columns</Name>
<Tooltip>The number of columnd in the table</Tooltip>
<GtkArg>columns</GtkArg>
<Parameters>
<Parameter Key="Min" Value="0"/>
<Parameter Key="Max" Value="10000"/>