Commit 97b88b88 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Added glade-palette-item.[ch], glade-palette-box.[ch] and


	* src/Makefile.am: Added glade-palette-item.[ch],
	  glade-palette-box.[ch] and glade-palette-expander.[ch]
	  to build sources.

	* src/glade.h, src/glade-builtins.[ch]: Declare an enum
	  GladeItemAppearance and define a GType for it.

	* src/glade-palette.[ch]: Entirely reworked. new API.

	* src/glade-app.c, src/glade-fixed.c,
	  src/glade-placeholder.c: Recognize new palette API.

	* src/glade-project-window.c: Added UI functionality
	  to support features in the new palette.
parent a76e96fb
2006-06-20 Vincent Geddes <vgeddes@metroweb.co.za>
* src/Makefile.am: Added glade-palette-item.[ch],
glade-palette-box.[ch] and glade-palette-expander.[ch]
to build sources.
* src/glade.h, src/glade-builtins.[ch]: Declare an enum
GladeItemAppearance and define a GType for it.
* src/glade-palette.[ch]: Entirely reworked. new API.
* src/glade-app.c, src/glade-fixed.c,
src/glade-placeholder.c: Recognize new palette API.
* src/glade-project-window.c: Added UI functionality
to support features in the new palette.
2006-06-20 Tristan Van Berkom <tvb@gnome.org>
* TODO: Added bugs 345438, 303679 and 345470 to the blockers.
......
......@@ -64,13 +64,6 @@ struct _GladeAppPriv {
GladeEditor *editor; /* See glade-editor */
GladeClipboard *clipboard; /* See glade-clipboard */
GList *catalogs; /* See glade-catalog */
GladeWidgetClass *add_class; /* The GladeWidgetClass that we are about
* to add to a container. NULL if no
* class is to be added. This also has to
* be in sync with the depressed button
* in the GladePalette
*/
GladeWidgetClass *alt_class;
GList *views; /* A list of GladeProjectView item */
GList *projects; /* The list of Projects */
......@@ -274,7 +267,7 @@ on_palette_button_clicked (GladePalette *palette, GladeApp *app)
GladeWidget *widget;
g_return_if_fail (GLADE_IS_PALETTE (palette));
class = palette->current;
class = glade_palette_get_current_item_class (palette);
/* class may be NULL if the selector was pressed */
if (class && g_type_is_a (class->type, GTK_TYPE_WINDOW))
......@@ -288,20 +281,8 @@ on_palette_button_clicked (GladePalette *palette, GladeApp *app)
app->priv->accel_group);
}
glade_palette_unselect_widget (palette);
app->priv->add_class = NULL;
glade_palette_deselect_current_item (palette);
}
else if ((app->priv->add_class = class) != NULL)
app->priv->alt_class = class;
}
static void
on_palette_catalog_changed (GladePalette *palette, GladeApp *app)
{
g_return_if_fail (GLADE_IS_PALETTE (palette));
glade_palette_unselect_widget (palette);
app->priv->alt_class = app->priv->add_class = NULL;
}
static gboolean
......@@ -349,23 +330,19 @@ glade_app_init (GladeApp *app)
initialized = TRUE;
}
app->priv = g_new0 (GladeAppPriv, 1);
app->priv->add_class = NULL;
app->priv->alt_class = NULL;
app->priv->accel_group = NULL;
/* Initialize app objects */
app->priv->catalogs = glade_catalog_load_all ();
/* Create palette */
app->priv->palette = glade_palette_new (app->priv->catalogs);
app->priv->palette = glade_palette_new (app->priv->catalogs, GLADE_ITEM_ICON_ONLY);
g_object_ref (app->priv->palette);
gtk_object_sink (GTK_OBJECT (app->priv->palette));
gtk_widget_show_all (GTK_WIDGET (app->priv->palette));
g_signal_connect (G_OBJECT (app->priv->palette), "toggled",
G_CALLBACK (on_palette_button_clicked), app);
g_signal_connect (G_OBJECT (app->priv->palette), "catalog-changed",
G_CALLBACK (on_palette_catalog_changed), app);
/* Create Editor */
app->priv->editor = GLADE_EDITOR (glade_editor_new ());
......@@ -685,20 +662,6 @@ glade_app_get_editor (void)
return app->priv->editor;
}
GladeWidgetClass *
glade_app_get_add_class (void)
{
GladeApp *app = glade_app_get ();
return app->priv->add_class;
}
GladeWidgetClass *
glade_app_get_alt_class (void)
{
GladeApp *app = glade_app_get ();
return app->priv->alt_class;
}
GladePalette *
glade_app_get_palette (void)
{
......
......@@ -77,10 +77,6 @@ GtkWidget* glade_app_get_window (void);
LIBGLADEUI_API
GladeEditor* glade_app_get_editor (void);
LIBGLADEUI_API
GladeWidgetClass* glade_app_get_add_class (void);
LIBGLADEUI_API
GladeWidgetClass* glade_app_get_alt_class (void);
LIBGLADEUI_API
GladePalette* glade_app_get_palette (void);
LIBGLADEUI_API
GladeClipboard* glade_app_get_clipboard (void);
......
......@@ -544,3 +544,24 @@ glade_builtin_string_from_key (guint key)
return GladeKeys[i].name;
return NULL;
}
GType
glade_item_appearance_get_type (void)
{
static GType etype = 0;
if (etype == 0)
{
static const GEnumValue values[] = {
{ GLADE_ITEM_ICON_AND_LABEL, "GLADE_ITEM_ICON_AND_LABEL", "icon-and-label" },
{ GLADE_ITEM_ICON_ONLY, "GLADE_ITEM_ICON_ONLY", "icon-only" },
{ GLADE_ITEM_LABEL_ONLY, "GLADE_ITEM_LABEL_ONLY", "label-only" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static ("GladeItemAppearance", values);
}
return etype;
}
......@@ -28,6 +28,7 @@ LIBGLADEUI_API const GladeKey GladeKeys[];
#define GLADE_TYPE_ACCEL_GLIST (glade_accel_glist_get_type())
#define GLADE_TYPE_PARAM_OBJECTS (glade_param_objects_get_type())
#define GLADE_TYPE_PARAM_ACCEL (glade_param_accel_get_type())
#define GLADE_ITEM_APPEARANCE_TYPE (glade_item_appearance_get_type())
#define GLADE_IS_STOCK(pspec) \
(G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GLADE_TYPE_STOCK))
......@@ -51,6 +52,8 @@ LIBGLADEUI_API GType glade_glist_get_type (void) G_GNUC_CONST;
LIBGLADEUI_API GType glade_accel_glist_get_type (void) G_GNUC_CONST;
LIBGLADEUI_API GType glade_param_objects_get_type (void) G_GNUC_CONST;
LIBGLADEUI_API GType glade_param_accel_get_type (void) G_GNUC_CONST;
LIBGLADEUI_API GType glade_item_appearance_get_type (void) G_GNUC_CONST;
LIBGLADEUI_API guint glade_builtin_key_from_string (const gchar *string);
LIBGLADEUI_API const gchar *glade_builtin_string_from_key (guint key);
......@@ -60,6 +63,7 @@ LIBGLADEUI_API GList *glade_accel_list_copy (GList *accels
LIBGLADEUI_API void glade_accel_list_free (GList *accels);
LIBGLADEUI_API GParamSpec *glade_param_spec_objects (const gchar *name,
const gchar *nick,
const gchar *blurb,
......
......@@ -572,7 +572,7 @@ glade_fixed_child_event (GtkWidget *widget,
/* Early return for placeholders with selection in
* the palette.
*/
if (glade_app_get_add_class ())
if (glade_palette_get_current_item_class (glade_app_get_palette ()) != NULL)
{
glade_cursor_set (((GdkEventAny *)event)->window,
GLADE_CURSOR_ADD_WIDGET);
......@@ -715,16 +715,16 @@ glade_fixed_event (GtkWidget *widget,
GladeWidget *gwidget_fixed)
{
GladeFixed *fixed = GLADE_FIXED (gwidget_fixed);
GladeWidgetClass *add_class, *alt_class;
GladeWidgetClass *item_class;
GtkWidget *event_widget;
gboolean handled = FALSE;
GladeWidget *event_gwidget, *search;
add_class = glade_app_get_add_class ();
alt_class = glade_app_get_alt_class ();
gdk_window_get_pointer (widget->window, NULL, NULL, NULL);
item_class = glade_palette_get_current_item_class (glade_app_get_palette ());
/* Get the event widget and the deep widget */
gdk_window_get_user_data (((GdkEventAny *)event)->window, (gpointer)&event_widget);
event_gwidget = glade_widget_event_widget ();
......@@ -763,7 +763,7 @@ glade_fixed_event (GtkWidget *widget,
/* Early return for placeholders with selection in
* the palette.
*/
if (glade_app_get_add_class ())
if (item_class)
{
glade_cursor_set (((GdkEventAny *)event)->window,
GLADE_CURSOR_ADD_WIDGET);
......@@ -810,33 +810,29 @@ glade_fixed_event (GtkWidget *widget,
switch (event->type)
{
case GDK_BUTTON_PRESS: // add widget
if (((GdkEventButton *)event)->button == 1)
if (((GdkEventButton *) event)->button == 1)
{
if ((add_class != NULL) ||
((((GdkEventButton *)event)->state & GDK_SHIFT_MASK) &&
alt_class != NULL))
if (item_class != NULL)
{
/* A widget type is selected in the palette.
* Add a new widget of that type.
*/
fixed->creating = TRUE;
glade_command_create
(add_class ? add_class : alt_class,
GLADE_WIDGET (fixed), NULL,
GLADE_WIDGET (fixed)->project);
glade_command_create (item_class,
GLADE_WIDGET (fixed), NULL,
GLADE_WIDGET (fixed)->project);
fixed->creating = FALSE;
/* reset the palette */
glade_palette_unselect_widget
(glade_app_get_palette ());
glade_palette_deselect_current_item (glade_app_get_palette ());
handled = TRUE;
}
}
break;
case GDK_ENTER_NOTIFY:
case GDK_MOTION_NOTIFY:
if (glade_app_get_add_class ())
if (item_class != NULL)
{
glade_cursor_set (((GdkEventAny *)event)->window,
GLADE_CURSOR_ADD_WIDGET);
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* glade-palette-box.c
*
* Copyright (C) 2006 The Gnome Foundation.
*
* Authors:
* Vincent Geddes <vgeddes@metroweb.co.za>
*
* 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.
*
*/
#include "glade-palette-box.h"
static void glade_palette_box_class_init (GladePaletteBoxClass *klass);
static void glade_palette_box_init (GladePaletteBox *box);
static void glade_palette_box_add (GtkContainer *container, GtkWidget *widget);
static void glade_palette_box_remove (GtkContainer *container, GtkWidget *widget);
static GType glade_palette_box_child_type (GtkContainer *container);
static void glade_palette_box_size_request (GtkWidget *widget, GtkRequisition *requisition);
static void glade_palette_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
static void glade_palette_box_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
static void glade_palette_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void glade_palette_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void glade_palette_box_set_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void glade_palette_box_get_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GtkContainerClass *parent_class = NULL;
enum {
PROP_0
};
enum {
CHILD_PROP_0,
CHILD_PROP_POSITION
};
GType
glade_palette_box_get_type (void)
{
static GType type = 0;
if (type == 0)
{
static const GTypeInfo info =
{
sizeof (GladePaletteBoxClass),
NULL,
NULL,
(GClassInitFunc) glade_palette_box_class_init,
NULL,
NULL,
sizeof (GladePaletteBox),
0,
(GInstanceInitFunc) glade_palette_box_init,
};
type = g_type_register_static (GTK_TYPE_CONTAINER,
"GladePaletteBox",
&info, 0);
}
return type;
}
static void
glade_palette_box_class_init (GladePaletteBoxClass *class)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
parent_class = g_type_class_peek_parent (class);
gobject_class = G_OBJECT_CLASS (class);
gobject_class->set_property = glade_palette_box_set_property;
gobject_class->get_property = glade_palette_box_get_property;
container_class = GTK_CONTAINER_CLASS (class);
container_class->add = glade_palette_box_add;
container_class->remove = glade_palette_box_remove;
container_class->forall = glade_palette_box_forall;
container_class->child_type = glade_palette_box_child_type;
container_class->set_child_property = glade_palette_box_set_child_property;
container_class->get_child_property = glade_palette_box_get_child_property;
widget_class = GTK_WIDGET_CLASS (class);
widget_class->size_request = glade_palette_box_size_request;
widget_class->size_allocate = glade_palette_box_size_allocate;
gtk_container_class_install_child_property (container_class,
CHILD_PROP_POSITION,
g_param_spec_int ("position",
"Position",
"The index of the child in the parent",
-1, G_MAXINT, 0,
G_PARAM_READWRITE));
}
static void
glade_palette_box_init (GladePaletteBox *box)
{
GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW);
gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE);
box->children = NULL;
}
static void
glade_palette_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GladePaletteBox *box;
box = GLADE_PALETTE_BOX (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_palette_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GladePaletteBox *box;
box = GLADE_PALETTE_BOX (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_palette_box_set_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
case CHILD_PROP_POSITION:
glade_palette_box_reorder_child (GLADE_PALETTE_BOX (container),
child,
g_value_get_int (value));
break;
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
break;
}
}
static void
glade_palette_box_get_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GList *list;
guint i;
switch (property_id)
{
case CHILD_PROP_POSITION:
i = 0;
for (list = GLADE_PALETTE_BOX (container)->children; list; list = list->next)
{
GladePaletteBoxChild *child_entry;
child_entry = list->data;
if (child_entry->widget == child)
break;
i++;
}
g_value_set_int (value, list ? i : -1);
break;
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
break;
}
}
GtkWidget*
glade_palette_box_new (void)
{
GladePaletteBox *box;
box = g_object_new (GLADE_TYPE_PALETTE_BOX, NULL);
return GTK_WIDGET (box);
}
/* do some badass mathematics */
static gint
calculate_children_width_allocation (GtkWidget *widget,
GtkAllocation *allocation,
GtkRequisition *child_requisition,
gint nvis_children)
{
gint w; /* container width */
gint cw; /* children width request */
gint tmp = 0;
g_assert (child_requisition->width >= 0);
w = allocation->width - GTK_CONTAINER (widget)->border_width;
cw = child_requisition->width;
if ((nvis_children * cw) < w )
return cw;
if ((tmp = w - w % cw) == 0)
return child_requisition->width;
else
return w / (tmp / cw);
}
static void
glade_palette_box_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
GladePaletteBox *box;
GladePaletteBoxChild *child;
GtkRequisition child_requisition;
GList *l;
gint nvis_children = 0;
box = GLADE_PALETTE_BOX (widget);
requisition->width = 0;
requisition->height = 0;
child_requisition.width = 0;
child_requisition.height = 0;
for (l = box->children; l; l = l->next)
{
child = (GladePaletteBoxChild *) (l->data);
if (GTK_WIDGET_VISIBLE (child->widget))
{
GtkRequisition requisition;
gtk_widget_size_request (child->widget, &requisition);
child_requisition.width = MAX (child_requisition.width, requisition.width);
nvis_children += 1;
}
}
if (nvis_children > 0)
{
requisition->width += child_requisition.width;
requisition->height += child_requisition.height;
}
requisition->width += GTK_CONTAINER (box)->border_width * 2;
requisition->height += GTK_CONTAINER (box)->border_width * 2;
}
static void
glade_palette_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
GladePaletteBox *box;
GladePaletteBoxChild *child;
GList *l;
GtkRequisition child_requisition;
GtkAllocation child_allocation;
gint nvis_children = 0;
gint x, y;
gint rows = 1;
gint children_width;
box = GLADE_PALETTE_BOX (widget);
widget->allocation = *allocation;
child_requisition.width = 0;
child_requisition.height = 0;
/* Retrieve maximum requisition from children */
for (l = box->children; l; l = l->next)
{
child = (GladePaletteBoxChild *) (l->data);
if (GTK_WIDGET_VISIBLE (child->widget))
{
GtkRequisition requisition;
gtk_widget_get_child_requisition (child->widget, &requisition);
child_requisition.width = MAX (child_requisition.width, requisition.width);
child_requisition.height = MAX (child_requisition.height, requisition.height);
nvis_children += 1;
}
}
if (nvis_children <= 0)
return;
x = allocation->x + GTK_CONTAINER (box)->border_width;
y = allocation->y + GTK_CONTAINER (box)->border_width;
children_width = calculate_children_width_allocation (widget, allocation,
&child_requisition,
nvis_children);
/* Allocate real estate to children */
for (l = box->children; l; l = l->next)
{
child = (GladePaletteBoxChild *) (l->data);
gint horizontal_space_remaining;
if (GTK_WIDGET_VISIBLE (child->widget))
{
child_allocation.x = x;
child_allocation.y = y;
child_allocation.width = children_width;
child_allocation.height = child_requisition.height;
gtk_widget_size_allocate (child->widget, &child_allocation);
x += child_allocation.width;
/* calculate horizontal space remaining */
horizontal_space_remaining = x
- allocation->x
+ GTK_CONTAINER (box)->border_width
+ children_width;
/* jump to next row */
if ((horizontal_space_remaining > allocation->width) && l->next )
{
x = allocation->x + GTK_CONTAINER (box)->border_width;
y += child_allocation.height;
rows++;
}
}
}
/* force minimum height */
gtk_widget_set_size_request (widget, -1, rows * child_allocation.height);
}
static void
glade_palette_box_add (GtkContainer *container, GtkWidget *widget)
{
GladePaletteBox *box;
GladePaletteBoxChild *child;
g_return_if_fail (GLADE_IS_PALETTE_BOX (container));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (widget->parent == NULL);
box = GLADE_PALETTE_BOX (container);
child = g_new (GladePaletteBoxChild, 1);
child->widget = widget;
box->children = g_list_append (box->children, child);
gtk_widget_set_parent (widget, GTK_WIDGET (box));
}
static void
glade_palette_box_remove (GtkContainer *container, GtkWidget *widget)
{
GladePaletteBox *box;
GladePaletteBoxChild *child;
GList *children;
g_return_if_fail (GLADE_IS_PALETTE_BOX (container));
g_return_if_fail (GTK_IS_WIDGET (widget));
box = GLADE_PALETTE_BOX (container);
children = box->children;
while (children != NULL)
{
child = children->data;
children = g_list_next (children);
if (child->widget == widget)
{
gboolean was_visible;
was_visible = GTK_WIDGET_VISIBLE (widget);
gtk_widget_unparent (widget);
box->children = g_list_remove (box->children, child);
g_free (child);
if (was_visible)
gtk_widget_queue_resize (GTK_WIDGET (container));
break;
}
}
}
static void
glade_palette_box_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data)
{
GladePaletteBox *box;
GladePaletteBoxChild *child;
GList *children;
g_return_if_fail (callback != NULL);
box = GLADE_PALETTE_BOX (container);
children = box->children;
while (children != NULL)
{
child = children->data;
children = g_list_next (children);
(* callback) (child->widget, callback_data);
}
}
void
glade_palette_box_reorder_child (GladePaletteBox *box,
GtkWidget *child,
gint position)
{
GList *old_link;