remove the packing memebers, we where not using them.

2001-08-13  Chema Celorio  <chema@celorio.com>

	* src/glade-widget.h: remove the packing memebers, we where not using them.

	* src/glade-widget.c (glade_widget_button_press): if the widget is not
	selected, stop the emision of the button clicked event.
	(glade_widget_set_default_options_real): remove the code for handling
	->apply_first_time.
	(glade_widget_ugly_hack): add an ugly hack till i figure out the real
	problem of the placeholders not beeing drawn inside containers.
	(glade_widget_clear_draw_selection): function used when we unselect an
	item so that it gets redrawn and the selection nodes cleared.
	(glade_widget_properties_hash_from_node): impl.
	(glade_widget_apply_property_from_hash_item): impl.
	(glade_widget_new_child_from_node): impl.

	* src/glade-widget-class.c (glade_widget_class_new_from_node): load
	postcreatefunction
	(glade_widget_class_is): implement.

	* src/glade-property.c (glade_property_set): implement.

	* src/glade-property-class.h: remove ->apply_first_time

	* src/glade-project-window.c (glade_project_window_add_project): add
	two g_return_val_if_fail

	* src/glade-project-view.c (glade_project_view_widget_name_changed): if
	view->is_list and the widget is not a toplevel, return.

	* src/glade-placeholder.c (glade_placeholder_add_methods_to_class):
	make all methods static. implement.
	(glade_placeholder_add): take a rows & cols argument and not a
	GladePropertyQueryResult.
	:use glade_widget_class_is and not a strcmp
	(glade_placeholder_add_with_result): impl.
	(glade_placeholder_replace): impl.
	(glade_placeholder_get_from_properties): impl.

	* src/glade-packing.c (glade_packing_box_position_set): remove a
	warning

	* src/glade-gtk.c (glade_gtk_window_post_create): impl.
	(glade_gtk_check_button_post_create): impl.
This commit is contained in:
Chema Celorio 2001-08-13 16:42:50 +00:00 committed by Jose Maria Celorio
parent 8b9ec7363e
commit 1c2347c484
20 changed files with 551 additions and 159 deletions

View File

@ -1,3 +1,48 @@
2001-08-13 Chema Celorio <chema@celorio.com>
* src/glade-widget.h: remove the packing memebers, we where not using them.
* src/glade-widget.c (glade_widget_button_press): if the widget is not
selected, stop the emision of the button clicked event.
(glade_widget_set_default_options_real): remove the code for handling
->apply_first_time.
(glade_widget_ugly_hack): add an ugly hack till i figure out the real
problem of the placeholders not beeing drawn inside containers.
(glade_widget_clear_draw_selection): function used when we unselect an
item so that it gets redrawn and the selection nodes cleared.
(glade_widget_properties_hash_from_node): impl.
(glade_widget_apply_property_from_hash_item): impl.
(glade_widget_new_child_from_node): impl.
* src/glade-widget-class.c (glade_widget_class_new_from_node): load
postcreatefunction
(glade_widget_class_is): implement.
* src/glade-property.c (glade_property_set): implement.
* src/glade-property-class.h: remove ->apply_first_time
* src/glade-project-window.c (glade_project_window_add_project): add
two g_return_val_if_fail
* src/glade-project-view.c (glade_project_view_widget_name_changed): if
view->is_list and the widget is not a toplevel, return.
* src/glade-placeholder.c (glade_placeholder_add_methods_to_class):
make all methods static. implement.
(glade_placeholder_add): take a rows & cols argument and not a
GladePropertyQueryResult.
:use glade_widget_class_is and not a strcmp
(glade_placeholder_add_with_result): impl.
(glade_placeholder_replace): impl.
(glade_placeholder_get_from_properties): impl.
* src/glade-packing.c (glade_packing_box_position_set): remove a
warning
* src/glade-gtk.c (glade_gtk_window_post_create): impl.
(glade_gtk_check_button_post_create): impl.
2001-08-11 Chema Celorio <chema@celorio.com>
* src/glade.h: try to fix gettext support. Duno why translations are not

View File

@ -29,7 +29,7 @@ msgstr ""
#: src/main.c:112
msgid "Translate me\n"
msgstr "Traduceme"
msgstr "Traduceme\n"
#: src/glade-editor.c:140
msgid "Properties"

View File

@ -222,6 +222,35 @@ empty (GObject *object, GValue *value)
{
}
/* ------------------------------------ Post Create functions ------------------------------ */
static void
glade_gtk_window_post_create (GObject *object, GValue *not_used)
{
GtkWindow *window = GTK_WINDOW (object);
g_return_if_fail (GTK_IS_WINDOW (window));
gtk_window_set_default_size (window, 440, 250);
}
static void
glade_gtk_check_button_post_create (GObject *object, GValue *not_used)
{
GtkCheckButton *button = GTK_CHECK_BUTTON (object);
GtkWidget *label;
g_return_if_fail (GTK_IS_CHECK_BUTTON (button));
label = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (button), label);
gtk_widget_show (label);
}
/* ================ Temp hack =================== */
/* We have this table, but what we should do is use gmodule for this,
* however this requires that we link with libtool cause right now
@ -252,11 +281,13 @@ GladeGtkFunction functions [] = {
{"glade_gtk_adjustment_set_page_increment", glade_gtk_adjustment_set_page_increment},
{"glade_gtk_adjustment_set_page_size", glade_gtk_adjustment_set_page_size},
{"glade_gtk_check_button_post_create", glade_gtk_check_button_post_create},
{"glade_gtk_window_post_create", glade_gtk_window_post_create},
};
static gpointer
gpointer
glade_gtk_get_function (const gchar *name)
{
gint num;

View File

@ -378,22 +378,19 @@ glade_packing_box_position_set (GObject *object, const GValue *value)
child = box_child->widget;
glade_widget_child = glade_widget_get_from_gtk_widget (child);
if (!glade_widget_child) {
g_warning ("Could not get the GladeWidget to set packing position");
/* This is a placeholder */
if (!glade_widget_child)
continue;
}
property = glade_property_get_from_id (glade_widget_child->properties,
"position");
/* If we have a placeholder in the Box the property will not be found */
if (property)
glade_packing_box_position_get (G_OBJECT (child), property->value);
glade_packing_box_position_get (G_OBJECT (child), property->value);
/* We should pass a FALSE argument so that this property is not added to the
* undo stack
* Also we should have a generic way to update a property, here we know is interger
* but it shuold be done with a generic fuction
* but it should be done with a generic fuction
*/
}

View File

@ -21,6 +21,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include "glade.h"
#include "glade-placeholder.h"
@ -34,7 +35,7 @@
#define GLADE_PLACEHOLDER_ROW_STRING "GladePlaceholderRow"
#define GLADE_PLACEHOLDER_COL_STRING "GladePlaceholderColumn"
void
static void
glade_placeholder_replace_box (GtkWidget *current,
GtkWidget *new,
GtkWidget *container)
@ -54,7 +55,7 @@ glade_placeholder_replace_box (GtkWidget *current,
break;
}
if (list == NULL) {
g_warning ("Error while adding a widget to a GtkBox\n");
g_warning ("Error while replacing a widget in a GtkBox. The old widget could not be found\n");
return;
}
gtk_widget_unparent (child_info->widget);
@ -73,7 +74,7 @@ glade_placeholder_replace_box (GtkWidget *current,
/* */
}
void
static void
glade_placeholder_replace_table (GtkWidget *current,
GtkWidget *new,
GtkWidget *container)
@ -113,7 +114,7 @@ glade_placeholder_replace_table (GtkWidget *current,
/* */
}
void
static void
glade_placeholder_replace_container (GtkWidget *current,
GtkWidget *new,
GtkWidget *container)
@ -130,7 +131,7 @@ glade_placeholder_replace_container (GtkWidget *current,
*
* Replaces a widget inside a notebook with a new widget.
**/
void
static void
glade_placeholder_replace_notebook (GtkWidget *current,
GtkWidget *new,
GtkWidget *container)
@ -179,18 +180,34 @@ glade_placeholder_replace_widget (GladePlaceholder *placeholder, GladeWidgetClas
if (widget == NULL)
return;
if (parent->class->placeholder_replace != NULL)
parent->class->placeholder_replace (GTK_WIDGET (placeholder), widget->widget, parent->widget);
else
g_warning ("A widget was added to a placeholder, but the placeholder_replace "
"function has not been implemented for this class (%s)\n",
class->name);
glade_placeholder_replace (placeholder, parent, widget);
glade_widget_set_default_packing_options (widget);
glade_project_selection_set (widget, TRUE);
}
void
glade_placeholder_add_methods_to_class (GladeWidgetClass *class)
{
/* This is ugly, make it better. Chema */
if ((strcmp (class->name, "GtkVBox") == 0) ||
(strcmp (class->name, "GtkHBox") == 0))
class->placeholder_replace = glade_placeholder_replace_box;
if (strcmp (class->name, "GtkTable") == 0)
class->placeholder_replace = glade_placeholder_replace_table;
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)
g_warning ("placeholder_replace has not been implemented for %s\n",
class->name);
}
static void
glade_placeholder_on_button_press_event (GladePlaceholder *placeholder, GdkEventButton *event, GladeProject *project)
{
@ -314,12 +331,13 @@ glade_placeholder_new (GladeWidget *parent)
return placeholder;
}
#undef GLADE_PLACEHOLDER_SIZE
void
glade_placeholder_add (GladeWidgetClass *class,
GladeWidget *widget,
GladePropertyQueryResult *result)
gint rows, gint columns)
{
GladePlaceholder *placeholder;
@ -332,40 +350,29 @@ glade_placeholder_add (GladeWidgetClass *class,
return;
}
if ((strcmp (class->name, "GtkFrame") == 0) ||
(strcmp (class->name, "GtkHandleBox") == 0)) {
if (glade_widget_class_is (class, "GtkFrame") ||
glade_widget_class_is (class, "GtkHandleBox")) {
placeholder = glade_placeholder_new (widget);
gtk_container_add (GTK_CONTAINER (widget->widget),
placeholder);
return;
}
if ((strcmp (class->name, "GtkVBox") == 0) ||
(strcmp (class->name, "GtkHBox") == 0)) {
gint i;
gint size;
glade_property_query_result_get_int (result, "size", &size);
g_print ("Size is %d\n", size);
for (i = 0; i < size; i++) {
g_print ("Add placeholder %d\n", size);
placeholder = glade_placeholder_new (widget);
gtk_box_pack_start_defaults (GTK_BOX (widget->widget),
GTK_WIDGET (placeholder));
}
if (glade_widget_class_is (class, "GtkVBox") ||
glade_widget_class_is (class, "GtkHBox")) {
#if 0
g_print ("Deprecated !!\n");
#endif
return;
/* This function shuold not exist */
}
if ((strcmp (class->name, "GtkTable") == 0)) {
if (glade_widget_class_is (class, "GtkTable")) {
gint row, col;
gint rows = 6, cols = 6;
gint n_rows = rows, n_cols = columns;
glade_property_query_result_get_int (result, "n-rows", &rows);
glade_property_query_result_get_int (result, "n-columns", &cols);
for (row = 0; row < rows; row++) {
for (col = 0; col < cols; col++) {
for (row = 0; row < n_rows; row++) {
for (col = 0; col < n_cols; col++) {
placeholder = glade_placeholder_new (widget);
gtk_table_attach (GTK_TABLE (widget->widget),
GTK_WIDGET (placeholder),
@ -380,13 +387,11 @@ glade_placeholder_add (GladeWidgetClass *class,
}
if ((strcmp (class->name, "GtkNotebook") == 0)) {
if (glade_widget_class_is (class, "GtkNotebook")) {
GladeWidgetClass *label_class;
GladeWidget *label;
gint page;
gint pages = 3;
glade_property_query_result_get_int (result, "pages", &pages);
gint pages = rows;
label_class = glade_widget_class_get_by_name ("GtkLabel");
g_return_if_fail (label_class != NULL);
@ -408,6 +413,35 @@ glade_placeholder_add (GladeWidgetClass *class,
"for this class (%s)", class->name);
}
void
glade_placeholder_add_with_result (GladeWidgetClass *class,
GladeWidget *widget,
GladePropertyQueryResult *result)
{
gint rows = 0, columns = 0;
if (glade_widget_class_is (class, "GtkVBox") ||
glade_widget_class_is (class, "GtkHBox")) {
GladeProperty *property;
gint size;
glade_property_query_result_get_int (result, "size", &size);
property = glade_property_get_from_id (widget->properties,
"size");
glade_property_set_integer (property, size);
}
if (glade_widget_class_is (class, "GtkTable")) {
glade_property_query_result_get_int (result, "n-rows", &rows);
glade_property_query_result_get_int (result, "n-columns", &columns);
}
if (glade_widget_class_is (class, "GtkNotebook"))
glade_property_query_result_get_int (result, "pages", &rows);
glade_placeholder_add (class, widget, rows, columns);
}
GladeWidget *
glade_placeholder_get_parent (GladePlaceholder *placeholder)
{
@ -417,3 +451,43 @@ glade_placeholder_get_parent (GladePlaceholder *placeholder)
return parent;
}
void
glade_placeholder_replace (GladePlaceholder *placeholder, GladeWidget *parent, GladeWidget *child)
{
g_return_if_fail (GTK_IS_WIDGET (placeholder));
if (parent->class->placeholder_replace != NULL)
parent->class->placeholder_replace (GTK_WIDGET (placeholder), child->widget, parent->widget);
else
g_warning ("Could not replace a placeholder because we don't have a replace "
" function has not been implemented for \"%s\"\n",
parent->class->name);
}
GladePlaceholder *
glade_placeholder_get_from_properties (GladeWidget *parent,
GHashTable *properties)
{
GladePlaceholder *placeholder = NULL;
GList *list;
list = gtk_container_children (GTK_CONTAINER (parent->widget));
if (glade_widget_class_is (parent->class, "GtkVBox") ||
glade_widget_class_is (parent->class, "GtkHBox")) {
GtkBoxChild *box_child;
const gchar *val;
val = g_hash_table_lookup (properties, "position");
box_child = (GtkBoxChild *) g_list_nth (list, atoi (val));
placeholder = box_child->widget;
}
/* Get the first free placeholder */
if (!placeholder && list)
placeholder = list->data;
return placeholder;
}

View File

@ -6,27 +6,24 @@ G_BEGIN_DECLS
void glade_placeholder_add (GladeWidgetClass *class,
GladeWidget *widget,
GladePropertyQueryResult *result);
gint rows, gint columns);
void glade_placeholder_add_with_result (GladeWidgetClass *class,
GladeWidget *widget,
GladePropertyQueryResult *result);
GladePlaceholder * glade_placeholder_new (GladeWidget *parent);
GladeWidget * glade_placeholder_get_parent (GladePlaceholder *placeholder);
void glade_placeholder_add_methods_to_class (GladeWidgetClass *class);
/* Hacks */
void glade_placeholder_replace_box (GtkWidget *current,
GtkWidget *new,
GtkWidget *container);
void glade_placeholder_replace_table (GtkWidget *current,
GtkWidget *new,
GtkWidget *container);
void glade_placeholder_replace_container (GtkWidget *current,
GtkWidget *new,
GtkWidget *container);
void glade_placeholder_replace_notebook (GtkWidget *current,
GtkWidget *new,
GtkWidget *container);
void glade_placeholder_replace (GladePlaceholder *placeholder,
GladeWidget *parent,
GladeWidget *child);
GladePlaceholder * glade_placeholder_get_from_properties (GladeWidget *parent,
GHashTable *properties);
G_END_DECLS

View File

@ -134,7 +134,11 @@ glade_project_view_widget_name_changed (GladeProjectView *view,
{
GtkTreeModel *model;
GtkTreeIter *iter;
if (view->is_list && !GLADE_WIDGET_IS_TOPLEVEL (findme))
return;
model = GTK_TREE_MODEL (view->model);
iter = glade_project_view_find_iter_by_widget (model,

View File

@ -471,6 +471,9 @@ glade_project_window_add_project (GladeProjectWindow *gpw, GladeProject *project
{
GtkItemFactoryEntry entry;
g_return_if_fail (GLADE_IS_PROJECT_WINDOW (gpw));
g_return_if_fail (GLADE_IS_PROJECT (project));
gpw->projects = g_list_prepend (gpw->projects, project);
entry.path = g_strdup_printf ("/Project/%s", project->name);

View File

@ -131,10 +131,10 @@ glade_property_class_new (void)
property_class->parameters = NULL;
property_class->choices = NULL;
property_class->optional = FALSE;
property_class->optional_default = TRUE;
property_class->common = FALSE;
property_class->packing = FALSE;
property_class->get_default = FALSE;
property_class->apply_first_time = FALSE;
property_class->query = NULL;
property_class->set_function = NULL;
@ -277,6 +277,11 @@ glade_property_class_make_string_from_gvalue (GladePropertyType type,
case GLADE_PROPERTY_TYPE_STRING:
string = g_strdup (g_value_get_string (value));
break;
case GLADE_PROPERTY_TYPE_ENUM:
#if 0
glade_implement_me ();
#endif
break;
default:
g_warning ("Could not make string from gvalue for type %s\n",
glade_property_type_enum_to_string (type));
@ -315,6 +320,10 @@ glade_property_class_make_gvalue_from_string (GladePropertyType type,
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, string);
break;
case GLADE_PROPERTY_TYPE_ENUM:
g_free (value);
value = NULL;
break;
default:
g_warning ("Could not make gvalue from string %s and type %s\n",
string,
@ -653,7 +662,6 @@ glade_property_class_new_from_node (GladeXmlNode *node, GladeWidgetClass *widget
property_class->optional = glade_xml_property_get_boolean (node, GLADE_TAG_OPTIONAL, FALSE);
if (property_class->optional) {
property_class->optional_default = glade_xml_property_get_boolean (node, GLADE_TAG_OPTIONAL_DEFAULT, FALSE);
property_class->apply_first_time = glade_xml_property_get_boolean (node, GLADE_TAG_APPLY_FIRST_TIME, FALSE);
}
/* Now get the list of signals that we should listen to */

View File

@ -158,10 +158,9 @@ struct _GladePropertyClass {
* the "toggled" signal to get the state of the property
* from the real widget
*/
gboolean common; /* Common properties go in the common tab */
gboolean packing; /* Packing properties go in the packing tab */
gboolean apply_first_time; /* Temp hack */
gboolean get_default; /* If true, when the default property is applied it is queried
* from the GtkWidget rather than setting it to some value. We need
* this for example for the packing position in a gtkbox, we container
@ -195,7 +194,8 @@ GParamSpec * glade_property_class_find_spec (GladeWidgetClass *class, const gcha
gchar * glade_property_type_enum_to_string (GladePropertyType type);
GValue * glade_property_class_make_gvalue_from_string (GladePropertyType type, const gchar *string);
GValue * glade_property_class_make_gvalue_from_string (GladePropertyType type,
const gchar *string);
gchar * glade_property_class_make_string_from_gvalue (GladePropertyType type,
const GValue *value);

View File

@ -269,8 +269,10 @@ glade_property_set_string (GladeProperty *property,
g_return_if_fail (property->value != NULL);
g_return_if_fail (property->widget != NULL);
g_return_if_fail (property->widget->widget != NULL);
g_return_if_fail (text != NULL);
if (strcmp (text, g_value_get_string) != 0)
if (!g_value_get_string (property->value) ||
(strcmp (text, g_value_get_string (property->value)) != 0))
g_value_set_string (property->value, text);
if (property->enabled) {
@ -423,7 +425,55 @@ glade_property_set_choice (GladeProperty *property, GladeChoice *choice)
#endif
}
void
glade_property_set (GladeProperty *property, GValue *value)
{
switch (property->class->type) {
case GLADE_PROPERTY_TYPE_BOOLEAN:
glade_property_set_boolean (property,
g_value_get_boolean (value));
break;
case GLADE_PROPERTY_TYPE_FLOAT:
glade_property_set_float (property,
g_value_get_float (value));
break;
case GLADE_PROPERTY_TYPE_INTEGER:
glade_property_set_integer (property,
g_value_get_int (value));
break;
case GLADE_PROPERTY_TYPE_DOUBLE:
glade_property_set_double (property,
g_value_get_double (value));
break;
case GLADE_PROPERTY_TYPE_STRING:
glade_property_set_string (property,
g_value_get_string (value));
break;
case GLADE_PROPERTY_TYPE_ENUM:
break;
case GLADE_PROPERTY_TYPE_OBJECT:
glade_implement_me ();
g_print ("Set adjustment\n");
#if 1
g_print ("Set directly \n");
#if 0
glade_widget_set_default_options_real (property->child, packing);
#endif
gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (property->widget->widget),
GTK_ADJUSTMENT (property->child));
#else
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id,
property->child, NULL);
#endif
g_print ("Adjustment has been set\n");
break;
default:
g_warning ("Implement set default for this type [%s]\n", property->class->name);
break;
}
}
const gchar *
glade_property_get_string (GladeProperty *property)

View File

@ -73,6 +73,7 @@ GList * glade_property_list_new_from_widget_class (GladeWidgetClass *class,
GladeProperty * glade_property_new_from_class (GladePropertyClass *class, GladeWidget *widget);
void glade_property_free (GladeProperty *property);
void glade_property_set (GladeProperty *property, GValue *value);
void glade_property_set_string (GladeProperty *property, const gchar *text);
void glade_property_set_integer (GladeProperty *property, gint val);
void glade_property_set_float (GladeProperty *property, gfloat val);

View File

@ -99,24 +99,8 @@ glade_widget_class_add_virtual_methods (GladeWidgetClass *class)
{
g_return_if_fail (class->name != NULL);
if (GLADE_WIDGET_CLASS_ADD_PLACEHOLDER(class)) {
/* I don't love this. Make it better. Chema */
if ((strcmp (class->name, "GtkVBox") == 0) ||
(strcmp (class->name, "GtkHBox") == 0))
class->placeholder_replace = glade_placeholder_replace_box;
if (strcmp (class->name, "GtkTable") == 0)
class->placeholder_replace = glade_placeholder_replace_table;
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)
g_warning ("placeholder_replace has not been implemented for %s\n",
class->name);
}
if (GLADE_WIDGET_CLASS_ADD_PLACEHOLDER(class))
glade_placeholder_add_methods_to_class (class);
}
GList *
@ -250,6 +234,9 @@ glade_widget_class_new_from_node (GladeXmlNode *node)
else
GLADE_WIDGET_CLASS_UNSET_FLAGS (class, GLADE_ADD_PLACEHOLDER);
/* <PostCreateFunction> */
class->post_create_function = glade_xml_get_value_string (node, GLADE_TAG_POST_CREATE_FUNCTION);
glade_widget_class_add_virtual_methods (class);
return class;
@ -474,3 +461,15 @@ glade_widget_class_get_by_name (const gchar *name)
return NULL;
}
gboolean
glade_widget_class_is (GladeWidgetClass *class, const gchar *name)
{
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
if (strcmp (class->name, name) == 0)
return TRUE;
return FALSE;
}

View File

@ -57,6 +57,8 @@ struct _GladeWidgetClass {
void (*placeholder_replace) (GtkWidget *current,
GtkWidget *new,
GtkWidget *container);
gchar *post_create_function;
};
/* GladeWidgetClassSignal contains all the info we need for a given signal, such as
@ -77,7 +79,7 @@ const gchar * glade_widget_class_get_name (GladeWidgetClass *class);
GType glade_widget_class_get_type (GladeWidgetClass *class);
gboolean glade_widget_class_has_queries (GladeWidgetClass *class);
gboolean glade_widget_class_is (GladeWidgetClass *class, const gchar *name);
/* ParamSpec stuff */
GParamSpec * glade_widget_class_find_spec (GladeWidgetClass *class, const gchar *name);
void glade_widget_class_dump_param_specs (GladeWidgetClass *class);

View File

@ -33,6 +33,7 @@
#include "glade-popup.h"
#include "glade-placeholder.h"
#include "glade-signal.h"
#include "glade-gtk.h"
#include "glade-packing.h"
#define GLADE_WIDGET_SELECTION_NODE_SIZE 7
@ -282,10 +283,17 @@ glade_widget_button_press (GtkWidget *event_widget, GdkEventButton *event, gpoin
#ifdef DEBUG
g_debug ("Event button %d\n", event->button);
#endif
if (event->button == 1)
#endif
if (event->button == 1) {
/* If this is a selection set, don't change the state of the widget
* for exmaple for toggle buttons
*/
if (!glade_widget->selected)
gtk_signal_emit_stop_by_name (GTK_OBJECT (event_widget),
"button_press_event");
glade_project_selection_set (glade_widget, TRUE);
else if (event->button == 3)
} else if (event->button == 3)
glade_popup_pop (glade_widget, event);
#ifdef DEBUG
else
@ -386,14 +394,6 @@ glade_widget_set_default_options_real (GladeWidget *widget, gboolean packing)
continue;
}
if (property->class->apply_first_time && !property->enabled) {
property->enabled = TRUE;
property->loading = TRUE;
glade_property_refresh (property);
property->loading = FALSE;
property->enabled = FALSE;
}
property->loading = TRUE;
glade_property_refresh (property);
property->loading = FALSE;
@ -459,7 +459,7 @@ glade_widget_draw_selection_nodes (GladeWidget *glade_widget)
y = 0;
gdk_window_get_size (window, &w, &h);
}
gc = paint_widget->style->black_gc;
gdk_gc_set_subwindow (gc, GDK_INCLUDE_INFERIORS);
@ -484,18 +484,22 @@ glade_widget_draw_selection_nodes (GladeWidget *glade_widget)
x, y, width - 1, height - 1);
gdk_gc_set_subwindow (gc, GDK_CLIP_BY_CHILDREN);
}
static void
static gint
glade_widget_expose_event_cb (GtkWidget *widget, GdkEventExpose *event,
GladeWidget *glade_widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GLADE_IS_WIDGET (widget));
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
g_assert (widget == glade_widget->widget);
if (glade_widget->selected)
glade_widget_draw_selection_nodes (glade_widget);
return FALSE;
}
static void
@ -506,11 +510,6 @@ glade_widget_connect_draw_signals (GladeWidget *glade_widget)
gtk_signal_connect_after (GTK_OBJECT (widget), "expose_event",
GTK_SIGNAL_FUNC (glade_widget_expose_event_cb),
glade_widget);
/* We need to turn doble buffering off since we are going
* to draw the selection nodes over the widget
*/
gtk_widget_set_double_buffered (widget, FALSE);
}
static void
@ -641,6 +640,22 @@ glade_widget_connect_other_signals (GladeWidget *widget)
}
}
/* Sigh.
* Fix, Fix, fix. Turn this off to see why this is here.
* Add a gtkwindow and a gtkvbox to reproduce
* Some werid redraw problems that i can't figure out.
* Chema
*/
static gint
glade_widget_ugly_hack (gpointer data)
{
GladeWidget *widget = data;
gtk_widget_queue_resize (widget->widget);
return FALSE;
}
static gboolean
glade_widget_create_gtk_widget (GladeWidget *glade_widget)
{
@ -668,6 +683,31 @@ glade_widget_create_gtk_widget (GladeWidget *glade_widget)
glade_widget->widget = widget;
gtk_object_set_data (GTK_OBJECT (glade_widget->widget), GLADE_WIDGET_DATA_TAG, glade_widget);
/* Ugly ugly hack. Don't even remind me about it. SEND ME PATCH !! and you'll
* gain 100 love points.
* 100ms works for me, but since i don't know what the problem is i'll add a couple
* of more times the call for slower systems or systems under heavy workload, no harm
* done with an extra queue_resize.
* This was not needed for gtk 1.3.5 but needed for 1.3.7.
* To reproduce the problem, remove this timeouts and create a gtkwindow
* and then a gtkvbox inside it. It will not draw correctly.
* Chema
*/
if (class->post_create_function) {
void (*pcf) (GObject *object);
pcf = glade_gtk_get_function (class->post_create_function);
if (!pcf)
g_warning ("Could not find %s\n", class->post_create_function);
else
pcf (G_OBJECT (glade_widget->widget));
}
gtk_timeout_add ( 100, glade_widget_ugly_hack, glade_widget);
gtk_timeout_add ( 400, glade_widget_ugly_hack, glade_widget);
gtk_timeout_add (1000, glade_widget_ugly_hack, glade_widget);
return TRUE;
}
@ -743,10 +783,8 @@ glade_widget_new_from_class_full (GladeWidgetClass *class, GladeProject *project
widget = glade_widget_new_full (project, class, parent);
/* If we are a container, add the placeholders */
if (GLADE_WIDGET_CLASS_ADD_PLACEHOLDER (class)) {
g_print ("Add placeholder \n");
glade_placeholder_add (class, widget, result);
}
if (GLADE_WIDGET_CLASS_ADD_PLACEHOLDER (class))
glade_placeholder_add_with_result (class, widget, result);
if (result)
glade_property_query_result_destroy (result);
@ -897,9 +935,27 @@ glade_widget_select (GladeWidget *widget)
}
/* I don't think this flag is beeing used at all, but for now it is queueing
* redraws. Chema.
*/
static void
glade_widget_clear_draw_selection (GladeWidget *widget)
{
GdkWindow *window;
g_return_if_fail (GLADE_IS_WIDGET (widget));
if (widget->parent)
window = widget->parent->widget->window;
else
window = widget->widget->window;
gdk_window_clear_area (window,
widget->widget->allocation.x,
widget->widget->allocation.y,
widget->widget->allocation.width,
widget->widget->allocation.height);
gtk_widget_queue_draw (widget->widget);
}
/**
* glade_widget_flag_unselected:
* @widget:
@ -912,7 +968,8 @@ glade_widget_flag_unselected (GladeWidget *widget)
g_return_if_fail (widget->selected);
widget->selected = FALSE;
gtk_widget_queue_draw (widget->widget);
glade_widget_clear_draw_selection (widget);
}
/**
@ -1118,6 +1175,7 @@ static gboolean
glade_widget_apply_property_from_node (GladeXmlNode *node, GladeWidget *widget)
{
GladeProperty *property;
GValue *gvalue;
gchar *value;
gchar *id;
@ -1129,23 +1187,29 @@ glade_widget_apply_property_from_node (GladeXmlNode *node, GladeWidget *widget)
property = glade_property_get_from_id (widget->properties,
id);
g_print ("Apply %s with %s\n", id, value);
if (property == NULL) {
g_warning ("Could not apply property from node. Id :%s\n",
id);
return FALSE;
}
gvalue = glade_property_class_make_gvalue_from_string (property->class->type,
value);
glade_property_set (property, gvalue);
g_free (id);
g_free (value);
g_free (gvalue);
return TRUE;
}
static void
glade_widget_load_child_from_node (GladeXmlNode *node)
{
g_print ("Foo\n");
}
static gboolean
glade_widget_new_child_from_node (GladeXmlNode *node, GladeProject *project, GladeWidget *parent);
GladeWidget *
glade_widget_new_from_node (GladeXmlNode *node, GladeProject *project)
static GladeWidget *
glade_widget_new_from_node_real (GladeXmlNode *node, GladeProject *project, GladeWidget *parent)
{
GladeWidgetClass *class;
GladeXmlNode *child;
@ -1162,23 +1226,135 @@ glade_widget_new_from_node (GladeXmlNode *node, GladeProject *project)
if (!class)
return NULL;
widget = glade_widget_new_full (project,
class,
NULL);
widget = glade_widget_new_full (project, class, parent);
g_print ("The %s widget has %d properties\n", widget->name,
g_list_length (widget->properties));
child = glade_xml_node_get_children (node);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!(glade_xml_node_verify_silent (child, GLADE_XML_TAG_CHILD) ||
glade_xml_node_verify (child, GLADE_XML_TAG_PROPERTY)))
if (!glade_xml_node_verify_silent (child, GLADE_XML_TAG_PROPERTY))
continue;
if (!glade_widget_apply_property_from_node (child, widget)) {
return NULL;
if (glade_xml_node_verify_silent (child, GLADE_XML_TAG_CHILD))
glade_widget_load_child_from_node (child);
else
glade_widget_apply_property_from_node (child, widget);
}
}
child = glade_xml_node_get_children (node);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify_silent (child, GLADE_XML_TAG_CHILD))
continue;
if (!glade_widget_new_child_from_node (child, project, widget)) {
return NULL;
}
}
gtk_widget_show_all (widget->widget);
return widget;
}
static GHashTable *
glade_widget_properties_hash_from_node (GladeXmlNode *node)
{
GladeXmlNode *child;
GHashTable *hash;
gchar *id;
gchar *value;
if (!glade_xml_node_verify (node, GLADE_XML_TAG_PACKING))
return NULL;
hash = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_free);
child = glade_xml_node_get_children (node);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, GLADE_XML_TAG_PROPERTY)) {
return NULL;
}
id = glade_xml_get_property_string_required (child, GLADE_XML_TAG_NAME, NULL);
value = glade_xml_get_content (child);
if (!value || !id) {
g_warning ("Invalid property %s:%s\n", value, id);
return NULL;
}
g_hash_table_insert (hash, id, value);
}
return hash;
}
static void
glade_widget_apply_property_from_hash_item (gpointer key, gpointer val, gpointer data)
{
GladeProperty *property;
GladeWidget *widget = data;
GValue *gvalue;
const gchar *id = key;
const gchar *value = val;
property = glade_property_get_from_id (widget->properties, id);
g_assert (property);
gvalue = glade_property_class_make_gvalue_from_string (property->class->type,
value);
glade_property_set (property, gvalue);
}
static void
glade_widget_apply_properties_from_hash (GladeWidget *widget, GHashTable *properties)
{
g_hash_table_foreach (properties, glade_widget_apply_property_from_hash_item, widget);
}
static gboolean
glade_widget_new_child_from_node (GladeXmlNode *node, GladeProject *project, GladeWidget *parent)
{
GladeXmlNode *child_node;
GladeWidget *child;
GtkWidget *placeholder;
GHashTable *packing_properties;
if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD))
return FALSE;
/* Get the packing properties */
child_node = glade_xml_search_child_required (node, GLADE_XML_TAG_PACKING);
if (!child_node)
return FALSE;
packing_properties = glade_widget_properties_hash_from_node (child_node);
if (packing_properties == NULL)
return FALSE;
/* Get and create the widget */
child_node = glade_xml_search_child_required (node, GLADE_XML_TAG_WIDGET);
if (!child_node)
return FALSE;
child = glade_widget_new_from_node_real (child_node, project, parent);
g_assert (child);
/* Get the placeholder and replace it with the widget */
placeholder = glade_placeholder_get_from_properties (parent, packing_properties);
if (placeholder)
glade_placeholder_replace (placeholder, parent, child);
else
gtk_container_add (GTK_CONTAINER (parent->widget), child->widget);
/* Apply the properties and free the hash that contains them */
glade_widget_apply_properties_from_hash (child, packing_properties);
g_hash_table_destroy (packing_properties);
return TRUE;
}
GladeWidget *
glade_widget_new_from_node (GladeXmlNode *node, GladeProject *project)
{
return glade_widget_new_from_node_real (node, project, NULL);
}

View File

@ -50,22 +50,6 @@ struct _GladeWidget {
*/
gboolean selected;
/* Packing */
gint attach_left;
gint attach_right;
gint attach_top;
gint attach_bottom;
gint padding_horizontal;
gint padding_vertical;
gboolean expand_x : 1;
gboolean expand_y : 1;
gboolean shrink_x : 1;
gboolean shrink_y : 1;
gboolean fill_x : 1;
gboolean fill_y : 1;
};
/* GladeWidgetSignal is a structure that holds information about a signal a

View File

@ -57,7 +57,6 @@
#define GLADE_TAG_COMMON "Common"
#define GLADE_TAG_OPTIONAL "Optional"
#define GLADE_TAG_OPTIONAL_DEFAULT "OptionalDefault"
#define GLADE_TAG_APPLY_FIRST_TIME "ApplyFirstTime"
#define GLADE_TAG_TYPE "Type"
#define GLADE_TAG_TOOLTIP "Tooltip"
#define GLADE_TAG_GTKARG "GtkArg"
@ -89,6 +88,7 @@
#define GLADE_TAG_UPDATE_SIGNALS "UpdateSignals"
#define GLADE_TAG_SIGNAL_NAME "SignalName"
#define GLADE_TAG_DEFAULT "Default"
#define GLADE_TAG_POST_CREATE_FUNCTION "PostCreateFunction"
#define GLADE_TAG_CATALOG "GladeCatalog"
#define GLADE_TAG_GLADE_WIDGET "GladeWidget"

View File

@ -2,6 +2,7 @@
<Name>GtkCheckButton</Name>
<GenericName>checkbutton</GenericName>
<Toplevel>False</Toplevel>
<PostCreateFunction>glade_gtk_check_button_post_create</PostCreateFunction>
<Properties>
@ -16,7 +17,7 @@
<Property Id="draw-indicator" Default="True"/>
</Properties>
</GladeWidgetClass>

View File

@ -28,6 +28,25 @@
<Property Id="spacing"/>
<Property Common="True" Optional="True" OptioanlDefault="False" Default="0" Id="width-request"/>
<Property Common="True" Optional="True" OptioanlDefault="False" Default="0" Id="height-request"/>
<Property Common="True" Id="visible" Default="True">
<SetFunction>ignore</SetFunction>
</Property>
<Property Common="True" Id="sensitive"/>
<Property Common="True" Id="tooltip" ParamSpec="False" Name="Tooltip">
<Type>String</Type>
<SetFunction>glade_gtk_widget_set_tooltip</SetFunction>
<GetFunction>glade_gtk_widget_get_tooltip</GetFunction>
</Property>
<Property Common="True" Id="can-default"/>
<Property Common="True" Id="has-default"/>
<Property Common="True" Id="can-focus"/>
<!-- Not yet implemented
<Property Common="True" Id="events"/>
-->
<Property Common="True" Id="extension-events"/>
</Properties>
</GladeWidgetClass>

View File

@ -3,6 +3,7 @@
<GenericName>window</GenericName>
<Toplevel>True</Toplevel>
<Placeholder>True</Placeholder>
<PostCreateFunction>glade_gtk_window_post_create</PostCreateFunction>
<Properties>
@ -13,8 +14,8 @@
<Property Id="modal">
<SetFunction>ignore</SetFunction>
</Property>
<Property Id="default-width" Default="440" Optional="True" OptionalDefault="False" ApplyFirstTime="True"/>
<Property Id="default-height" Default="250" Optional="True" OptionalDefault="False" ApplyFirstTime="True"/>
<Property Id="default-width" Default="0" Optional="True" OptionalDefault="False"/>
<Property Id="default-height" Default="0" Optional="True" OptionalDefault="False"/>
<Property Id="allow-grow"/>
<Property Id="allow-shrink"/>