Commit f5644eb4 authored by Jose Maria Celorio's avatar Jose Maria Celorio

lots of work. Selection is starting to work now

parent 814cb1f4
......@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/glade-widget.c)
AM_INIT_AUTOMAKE(glade2, 0.1.0)
AM_INIT_AUTOMAKE(glade2, 0.0.21)
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_CATALOG_H__
#define __GLADE_CATALOG_H__
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_CHOICE_H__
#define __GLADE_CHOICE_H__
......
......@@ -95,7 +95,6 @@ glade_editor_class_init (GladeEditorClass * klass)
GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
klass->select_item = glade_editor_select_item_real;
}
static gint
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_EDITOR_H__
#define __GLADE_EDITOR_H__
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_PALETTE_H__
#define __GLADE_PALETTE_H__
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_PARAMETER_H__
#define __GLADE_PARAMETER_H__
......
......@@ -145,8 +145,11 @@ glade_placeholder_on_button_press_event (GladePlaceholder *placeholder, GdkEvent
gpw = glade_project_window_get ();
if (event->button == 1 && event->type == GDK_BUTTON_PRESS && gpw->add_class != NULL)
if (event->button == 1 && event->type == GDK_BUTTON_PRESS && gpw->add_class != NULL) {
glade_placeholder_replace_widget (placeholder, gpw->add_class);
gpw->add_class = NULL;
}
}
static void
......@@ -155,7 +158,7 @@ glade_placeholder_on_motion_notify_event (GladePlaceholder *placeholder, GdkEven
GladeProjectWindow *gpw;
gpw = glade_project_window_get ();
if (gpw->add_class == NULL)
glade_cursor_set (event->window, GLADE_CURSOR_SELECTOR);
else
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_PLACEHOLDER_H__
#define __GLADE_PLACEHOLDER_H__
......
......@@ -27,12 +27,9 @@
enum
{
ITEM_SELECTED,
LAST_SIGNAL
};
static guint glade_project_view_signals [LAST_SIGNAL] = {0};
static GtkObject *parent_class = NULL;
static void glade_project_view_class_init (GladeProjectViewClass * klass);
......@@ -234,7 +231,7 @@ glade_project_view_add_item (GladeProjectView *view,
WIDGET_COLUMN, widget,
-1);
glade_project_view_select_item (view, widget);
glade_project_selection_set (view->project, widget, TRUE);
}
......@@ -247,15 +244,8 @@ glade_project_view_class_init (GladeProjectViewClass * gpv_class)
parent_class = gtk_type_class (gtk_object_get_type ());
glade_project_view_signals [ITEM_SELECTED] =
gtk_signal_new ("item_selected",
GTK_RUN_LAST,
GTK_CLASS_TYPE(object_class),
GTK_SIGNAL_OFFSET (GladeProjectViewClass, item_selected),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
gpv_class->item_selected = NULL;
#warning FIXME, revisit
gpv_class->add_item = glade_project_view_add_item;
gpv_class->set_project = glade_project_view_set_project;
gpv_class->widget_name_changed = glade_project_view_widget_name_changed;
......@@ -283,8 +273,8 @@ glade_project_view_cell_function (GtkTreeViewColumn *tree_column,
}
static gboolean
glade_project_view_select_item_cb (GtkTreeSelection *selection,
GladeProjectView *view)
glade_project_view_selection_changed_cb (GtkTreeSelection *selection,
GladeProjectView *view)
{
GtkTreeModel *model;
GladeWidget *widget;
......@@ -308,7 +298,7 @@ glade_project_view_select_item_cb (GtkTreeSelection *selection,
if (widget == NULL)
return TRUE;
glade_project_view_select_item (view, widget);
glade_project_selection_set (view->project, widget, TRUE);
return TRUE;
}
......@@ -339,7 +329,7 @@ glade_project_view_create_widget (GladeProjectView *view)
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
g_signal_connect_data (G_OBJECT (selection),
"changed", GTK_SIGNAL_FUNC (glade_project_view_select_item_cb),
"changed", GTK_SIGNAL_FUNC (glade_project_view_selection_changed_cb),
view, NULL, FALSE, FALSE);
gtk_widget_set_usize (widget, 272, 130);
......@@ -367,8 +357,12 @@ glade_project_view_init (GladeProjectView * view)
}
void
glade_project_view_select_item (GladeProjectView *view, GladeWidget *item)
glade_project_view_selection_changed (GladeProjectView *view, GladeWidget *item)
{
glade_project_selection_clear (view->project, FALSE);
g_print ("Do something\n");
#if 0
if (view->selected_widget == item)
return;
......@@ -376,6 +370,7 @@ glade_project_view_select_item (GladeProjectView *view, GladeWidget *item)
gtk_signal_emit (GTK_OBJECT (view),
glade_project_view_signals [ITEM_SELECTED], item);
#endif
}
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2001 Ximian Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors:
* Chema Celorio <chema@ximian.com>
*/
#ifndef __GLADE_PROJECT_VIEW_H__
#define __GLADE_PROJECT_VIEW_H__
......
......@@ -224,23 +224,6 @@ glade_project_window_get ()
return glade_project_window;
}
static void
glade_project_window_selection_changed (GladeProjectView *view, GladeWidget *component, GladeProjectWindow *gpw)
{
GladeWidget *glade_widget;
g_return_if_fail (GLADE_IS_PROJECT_VIEW (view));
glade_widget = view->selected_widget;
g_return_if_fail (gpw != NULL);
g_return_if_fail (gpw->editor != NULL);
g_return_if_fail (GLADE_IS_EDITOR (gpw->editor));
glade_editor_select_widget (gpw->editor, glade_widget);
}
static void
glade_project_window_set_view (GladeProjectWindow *gpw, GladeProjectView *view)
{
......@@ -252,8 +235,6 @@ glade_project_window_set_view (GladeProjectWindow *gpw, GladeProjectView *view)
gtk_box_pack_start_defaults (GTK_BOX (gpw->main_vbox),
glade_project_view_get_widget (view));
gtk_signal_connect (GTK_OBJECT (view), "item_selected",
GTK_SIGNAL_FUNC (glade_project_window_selection_changed), gpw);
}
GladeProjectWindow *
......@@ -297,6 +278,27 @@ gpw_show_editor_cb (void)
glade_editor_show (gpw);
}
static void
glade_project_window_selection_changed_cb (GladeProject *project,
GladeProjectWindow *gpw)
{
GList *list;
gint num;
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (GLADE_IS_PROJECT_WINDOW (gpw));
if (gpw->editor) {
list = project->selection;
num = g_list_length (list);
if (num == 1)
glade_editor_select_widget (gpw->editor, list->data);
else
glade_editor_select_widget (gpw->editor, NULL);
}
}
void
glade_project_window_set_project (GladeProjectWindow *gpw, GladeProject *project)
{
......@@ -319,7 +321,10 @@ glade_project_window_set_project (GladeProjectWindow *gpw, GladeProject *project
glade_project_view_set_project (view, project);
}
gpw->project_selection_changed_signal =
gtk_signal_connect (GTK_OBJECT (project), "selection_changed",
GTK_SIGNAL_FUNC (glade_project_window_selection_changed_cb),
gpw);
}
static void
......@@ -479,3 +484,5 @@ glade_project_window_query_properties (GladeWidgetClass *class,
return FALSE;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* Gtk+ User Interface Builder
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GLADE_PROJECT_WINDOW_H__
#define __GLADE_PROJECT_WINDOW_H__
G_BEGIN_DECLS
#define GLADE_IS_PROJECT_WINDOW(o) (o != NULL)
/* A GladeProjectWindow specifies a loaded glade application.
* it contains pointers to all the components that make up
* the running app. This is (well should be) the only global
......@@ -54,6 +38,7 @@ struct _GladeProjectWindow
GList *views; /* A list of GladeProjectView item */
GList *projects; /* The list of Projects */
guint project_selection_changed_signal;
};
......
......@@ -24,6 +24,7 @@
#include "glade.h"
#include "glade-project.h"
#include "glade-project-window.h"
#include "glade-widget.h"
static void glade_project_class_init (GladeProjectClass * klass);
static void glade_project_init (GladeProject *project);
......@@ -34,6 +35,7 @@ enum
ADD_WIDGET,
REMOVE_WIDGET,
WIDGET_NAME_CHANGED,
SELECTION_CHANGED,
LAST_SIGNAL
};
......@@ -96,10 +98,18 @@ glade_project_class_init (GladeProjectClass * klass)
GTK_SIGNAL_OFFSET (GladeProjectClass, widget_name_changed),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
glade_project_signals[SELECTION_CHANGED] =
gtk_signal_new ("selection_changed",
GTK_RUN_LAST,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GladeProjectClass, selection_changed),
gtk_marshal_VOID__VOID,
GTK_TYPE_NONE, 0);
klass->add_widget = NULL;
klass->remove_widget = NULL;
klass->widget_name_changed = NULL;
klass->selection_changed = NULL;
object_class->destroy = glade_project_destroy;
}
......@@ -110,6 +120,7 @@ glade_project_init (GladeProject * project)
{
project->name = NULL;
project->widgets = NULL;
project->selection = NULL;
}
static void
......@@ -183,3 +194,116 @@ glade_project_get_active (void)
return gpw->project;
}
/**
* glade_widget_get_by_name:
* @project: The project in which to look for
* @name: The user visible name of the widget we are looking for
*
* Finds a GladeWidget inside a project given its name
*
* Return Value: a pointer to the wiget, NULL if the widget does not exist
**/
GladeWidget *
glade_project_get_widget_by_name (GladeProject *project, const gchar *name)
{
GladeWidget *widget;
GList *list;
g_return_val_if_fail (name != NULL, NULL);
list = project->widgets;
for (; list != NULL; list = list->next) {
widget = list->data;
g_return_val_if_fail (widget->name != NULL, NULL);
if (strcmp (widget->name, name) == 0)
return widget;
}
return NULL;
}
void
glade_project_selection_changed (GladeProject *project)
{
gtk_signal_emit (GTK_OBJECT (project),
glade_project_signals [SELECTION_CHANGED]);
}
void
glade_project_selection_clear (GladeProject *project, gboolean emit_signal)
{
GladeWidget *widget;
GList *list;
g_return_if_fail (GLADE_IS_PROJECT (project));
if (project->selection == NULL)
return;
list = project->selection;
for (; list != NULL; list = list->next) {
widget = list->data;
glade_widget_unselect (widget);
}
g_list_free (project->selection);
project->selection = NULL;
if (emit_signal)
glade_project_selection_changed (project);
}
void
glade_project_selection_remove (GladeProject *project, GladeWidget *widget,
gboolean emit_signal)
{
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (GLADE_IS_WIDGET (widget));
if (!widget->selected)
return;
glade_widget_unselect (widget);
project->selection = g_list_remove (project->selection, widget);
if (emit_signal)
glade_project_selection_changed (project);
}
void
glade_project_selection_add (GladeProject *project, GladeWidget *widget,
gboolean emit_signal)
{
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (GLADE_IS_WIDGET (widget));
if (widget->selected)
return;
project->selection = g_list_prepend (project->selection, widget);
glade_widget_select (widget);
if (emit_signal)
glade_project_selection_changed (project);
}
void
glade_project_selection_set (GladeProject *project, GladeWidget *widget,
gboolean emit_signal)
{
GList *list;
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (GLADE_IS_WIDGET (widget));
list = project->selection;
/* Check if the selection is different than what we have */
if ((list) && (list->next == NULL) && (list->data == widget))
return;
glade_project_selection_clear (project, FALSE);
glade_project_selection_add (project, widget, emit_signal);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2001 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors:
* Chema Celorio <chema@celorio.com>
*/
#ifndef __GLADE_PROJECT_H__
#define __GLADE_PROJECT_H__
......@@ -52,18 +31,28 @@ struct _GladeProject
GList *widgets; /* A list of GladeWidgets that make up this project.
* The widgets are stored in no particular order.
*/
#if 0
/* Not yet used */
GList *views;
#endif
GList *selection; /* We need to keep the selection in the project
* because we have multiple projects and when the
* user switchs between them, he will probably
* not want to loose the selection
*/
};
struct _GladeProjectClass
{
GtkObjectClass parent_class;
void (*add_widget) (GladeProject *project,
GladeWidget *widget);
void (*remove_widget) (GladeProject *project,
GladeWidget *widget);
void (*widget_name_changed) (GladeProject *project,
GladeWidget *widget);
void (*add_widget) (GladeProject *project,
GladeWidget *widget);
void (*remove_widget) (GladeProject *project,
GladeWidget *widget);
void (*widget_name_changed) (GladeProject *project,
GladeWidget *widget);
void (*selection_changed) (GladeProject *project);
};
......@@ -74,9 +63,18 @@ GladeProject * glade_project_new (void);
void glade_project_add_widget (GladeProject *project,
GladeWidget *glade_widget);
GladeWidget * glade_project_get_widget_by_name (GladeProject *project, const gchar *name);
void glade_project_widget_name_changed (GladeProject *project,
GladeWidget *widget);
/* Selection */
void glade_project_selection_set (GladeProject *project, GladeWidget *widget, gboolean emit_signal);
void glade_project_selection_add (GladeProject *project, GladeWidget *widget, gboolean emit_signal);
void glade_project_selection_remove (GladeProject *project, GladeWidget *widget, gboolean emit_signal);
void glade_project_selection_clear (GladeProject *project, gboolean emit_signal);
G_END_DECLS
#endif /* __GLADE_PROJECT_H__ */
......@@ -157,7 +157,7 @@ glade_property_class_find_spec (GladeWidgetClass *class, const gchar *name)
gint i;
glade_property_class_get_specs (class, &specs, &n_specs);
for (i = 0; i < n_specs; i++) {
spec = specs[i];
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_PROPERTY_CLASS_H__
#define __GLADE_PROPERTY_CLASS_H__
......@@ -22,7 +21,7 @@ typedef enum {
* make are a GladeProperty (except for the widget name)
* GladeProperties can be of any type of GladePropertyType
Example xml
Sample xml
Integer Type : (float is very similar)
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_WIDGET_CLASS_H__
#define __GLADE_WIDGET_CLASS_H__
......
......@@ -32,26 +32,18 @@
#include "glade-property-class.h"
#include "glade-placeholder.h"
GladeWidget *
glade_widget_get_by_name (GladeProject *project, const gchar *name)
{
GladeWidget *widget;
GList *list;
g_return_val_if_fail (name != NULL, NULL);
list = project->widgets;
for (; list != NULL; list = list->next) {
widget = list->data;
g_return_val_if_fail (widget->name != NULL, NULL);
if (strcmp (widget->name, name) == 0)
return widget;
}
return NULL;
}
#define GLADE_WIDGET_SELECTION_NODE_SIZE 7
/**
* glade_widget_new_name:
* @project:
* @class:
*
* Allocates a new name for a specific GladeWidgetClass.
*
* Return Value: a newly allocated name for the widget. Caller must g_free it
**/
gchar *
glade_widget_new_name (GladeProject *project, GladeWidgetClass *class)
{
......@@ -60,7 +52,7 @@ glade_widget_new_name (GladeProject *project, GladeWidgetClass *class)
while (TRUE) {
name = g_strdup_printf ("%s%i", class->generic_name, i);
if (glade_widget_get_by_name (project, name) == NULL)
if (glade_project_get_widget_by_name (project, name) == NULL)
return name;
g_free (name);
i++;
......@@ -68,6 +60,17 @@ glade_widget_new_name (GladeProject *project, GladeWidgetClass *class)
}
/**
* glade_widget_new:
* @project: The GladeProject this widget belongs to
* @class: The GladeWidgeClass of the GladeWidget
* @gtk_widget: The "view" of the GladeWidget
* @name: The unique name, this is visible name to the user
*
* Allocates a new GladeWidget structure and fills in the required memebers.
*
* Return Value:
**/
static GladeWidget *
glade_widget_new (GladeProject *project, GladeWidgetClass *class, GtkWidget *gtk_widget, const gchar *name)
{
......@@ -81,11 +84,207 @@ glade_widget_new (GladeProject *project, GladeWidgetClass *class, GtkWidget *gtk
widget->properties = glade_property_list_new_from_widget_class (class, widget);
widget->parent = NULL;
widget->children = NULL;
widget->selected = FALSE;
return widget;
}
/**
* glade_widget_get_from_gtk_widget:
* @widget:
*
* Given a GtkWidget, it returns its corresponding GladeWidget
*
* Return Value: a GladeWidget pointer for @widget, NULL if the widget does not
* have a GladeWidget counterpart.
**/
static GladeWidget *
glade_widget_get_from_gtk_widget (GtkWidget *widget)
{
return gtk_object_get_data (GTK_OBJECT (widget), GLADE_WIDGET_DATA_TAG);
}
/* 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
*/
typedef struct
{
gint x;
gint y;
GtkWidget *found_child;
}GladeFindInContainerData;
/* #define DEBUG */
static void
glade_widget_find_inside_container (GtkWidget *widget, gpointer data_in)
{
GladeFindInContainerData *data = data_in;
#ifdef DEBUG
g_print ("In find_child_at: %s X:%i Y:%i W:%i H:%i\n"
" so this means that if we are in the %d-%d , %d-%d range. We are ok\n",
gtk_widget_get_name (widget),
widget->allocation.x, widget->allocation.y,
widget->allocation.width, widget->allocation.height,
widget->allocation.x, widget->allocation.x + widget->allocation.width,
widget->allocation.y, widget->allocation.y + widget->allocation.height);
#endif
/* Notebook pages are visible but not mapped if they are not showing. */
if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)
&& (widget->allocation.x <= data->x)
&& (widget->allocation.y <= data->y)
&& (widget->allocation.x + widget->allocation.width >= data->x)
&& (widget->allocation.y + widget->allocation.height >= data->y))
{
#ifdef DEBUG
g_print ("Found it!\n");
#endif
data->found_child = widget;
}
}
/**
* glade_widget_get_from_event_widget:
* @event_widget:
* @event_glade_widget:
* @event:
*
* Returns the real widget that was "clicked over" for a given event (cooridantes) and a widget
* For example, when a label is clicked the button press event is triggered for its parent, this
* function takes the event and the widget that got the event and returns the real widget that was
* clicked
*
* Return Value:
**/
static GladeWidget *
glade_widget_get_from_event_widget (GtkWidget *event_widget, GladeWidget *event_glade_widget, GdkEventButton *event)
{
GladeFindInContainerData data;
GladeWidget *found = NULL;
GtkWidget *temp;
GdkWindow *window;
GdkWindow *parent_window;
gint x, win_x;
gint y, win_y;
#ifdef DEBUG
GladeWidget *real_event_glade_widget = glade_widget_get_from_gtk_widget (event_widget);
#endif
window = event->window;
x = event->x;
y = event->y;
gdk_window_get_position (event_widget->window, &win_x, &win_y);
#ifdef DEBUG
g_print ("Window [%d,%d]\n", win_x, win_y);
g_print ("\n\nWe want to find the real widget that was clicked at %d,%d\n", x, y);
g_print ("The widget that received the event was \"%s\" a \"%s\" [%d]\n"
"The REAL widget is %s\n",
glade_widget_get_name (event_glade_widget),
gtk_widget_get_name (event_widget),
GPOINTER_TO_INT (event_widget),
glade_widget_get_name (real_event_glade_widget));
#endif
parent_window = event_widget->parent ? event_widget->parent->window : event_widget->window;
while (window && window != parent_window) {
gdk_window_get_position (window, &win_x, &win_y);
#ifdef DEBUG
g_print (" adding X:%d Y:%d - We now have : %d %d\n",
win_x, win_y, x + win_x, y + win_y);
#endif
x += win_x;
y += win_y;
window = gdk_window_get_parent (window);
}
temp = event_widget;
data.found_child = NULL;