Commit 0f48965b authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

* gladeui/glade-design-view.[ch]:

    o removed glade_design_view_get_layout() declaration
    o removed gladeui/glade-design-layout.h include
    o implemented _glade_design_view_freeze/thaw()
    o handle widget adding and removal on project's add-widget and remove-widget signals
    o use widget-visibility-changed to remove toplevel from project when its hidden

  * gladeui/glade-design-layout.[ch]:
    o added design-view construct only property
    o use _glade_design_view_freeze/thaw() to avoid scrolling to selection from
      the layout.
    o removed unused _glade_design_layout_should_scroll()

  * gladeui/glade-design-private.h: added new file to declare private API.
parent 59b67558
......@@ -144,7 +144,8 @@ libgladeuiinclude_HEADERS = \
glade-signal-model.h
noinst_HEADERS = \
glade-design-layout.h
glade-design-layout.h \
glade-design-private.h
if PLATFORM_WIN32
libgladeui_2_la_LDFLAGS += -no-undefined
......
......@@ -28,9 +28,11 @@
#include "glade.h"
#include "glade-design-layout.h"
#include "glade-design-private.h"
#include "glade-accumulators.h"
#include "glade-marshallers.h"
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#define GLADE_DESIGN_LAYOUT_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
......@@ -56,8 +58,6 @@ struct _GladeDesignLayoutPrivate
GdkRectangle east, south, south_east;
GdkCursor *cursors[sizeof (Activity)];
gboolean should_scroll;
PangoLayout *widget_name;
/* state machine */
......@@ -68,6 +68,15 @@ struct _GladeDesignLayoutPrivate
gint dy; /* child.height - event.pointer.y */
gint new_width; /* user's new requested width */
gint new_height; /* user's new requested height */
/* Properties */
GladeDesignView *view;
};
enum
{
PROP_0,
PROP_DESIGN_VIEW
};
G_DEFINE_TYPE (GladeDesignLayout, glade_design_layout, GTK_TYPE_BIN)
......@@ -263,10 +272,13 @@ glade_design_layout_button_press_event (GtkWidget *widget, GdkEventButton *ev)
(gchild = glade_widget_get_from_gobject (G_OBJECT (child))))
{
GladeProject *project = glade_widget_get_project (gchild);
priv->should_scroll = FALSE;
if (project)
{
_glade_design_view_freeze (priv->view);
glade_project_selection_set (project, G_OBJECT (gtk_bin_get_child (GTK_BIN (widget))), TRUE);
priv->should_scroll = TRUE;
_glade_design_view_thaw (priv->view);
}
}
}
else if (ev->type == GDK_2BUTTON_PRESS)
......@@ -945,8 +957,6 @@ glade_design_layout_init (GladeDesignLayout * layout)
priv->new_width = -1;
priv->new_height = -1;
priv->should_scroll = TRUE;
/* setup static member of rectangles */
priv->east.width = PADDING + OUTLINE_WIDTH;
priv->south.height = PADDING + OUTLINE_WIDTH;
......@@ -954,6 +964,42 @@ glade_design_layout_init (GladeDesignLayout * layout)
gtk_widget_set_has_window (GTK_WIDGET (layout), TRUE);
}
static void
glade_design_layout_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
switch (prop_id)
{
case PROP_DESIGN_VIEW:
GLADE_DESIGN_LAYOUT_GET_PRIVATE (object)->view = GLADE_DESIGN_VIEW (g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_design_layout_get_property (GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec)
{
switch (prop_id)
{
case PROP_DESIGN_VIEW:
g_value_set_object (value, GLADE_DESIGN_LAYOUT_GET_PRIVATE (object)->view);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_design_layout_class_init (GladeDesignLayoutClass * klass)
{
......@@ -966,6 +1012,8 @@ glade_design_layout_class_init (GladeDesignLayoutClass * klass)
container_class = GTK_CONTAINER_CLASS (klass);
object_class->finalize = glade_design_layout_finalize;
object_class->set_property = glade_design_layout_set_property;
object_class->get_property = glade_design_layout_get_property;
container_class->add = glade_design_layout_add;
container_class->remove = glade_design_layout_remove;
......@@ -981,6 +1029,12 @@ glade_design_layout_class_init (GladeDesignLayoutClass * klass)
widget_class->get_preferred_width = glade_design_layout_get_preferred_width;
widget_class->size_allocate = glade_design_layout_size_allocate;
g_object_class_install_property (object_class, PROP_DESIGN_VIEW,
g_param_spec_object ("design-view", _("Design View"),
_("The GladeDesignView that contains this layout"),
GLADE_TYPE_DESIGN_VIEW,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
GLADE_TYPE_DESIGN_LAYOUT,
g_cclosure_new (G_CALLBACK (glade_design_layout_damage),
......@@ -992,9 +1046,9 @@ glade_design_layout_class_init (GladeDesignLayoutClass * klass)
/* Internal API */
GtkWidget *
_glade_design_layout_new (void)
_glade_design_layout_new (GladeDesignView *view)
{
return g_object_new (GLADE_TYPE_DESIGN_LAYOUT, NULL);
return g_object_new (GLADE_TYPE_DESIGN_LAYOUT, "design-view", view, NULL);
}
/*
......@@ -1025,7 +1079,7 @@ _glade_design_layout_do_event (GladeDesignLayout * layout, GdkEvent * event)
glade_design_layout_find_inside_container (child, &data);
priv->should_scroll = FALSE;
_glade_design_view_freeze (priv->view);
/* Try the placeholder first */
if (data.placeholder && gtk_widget_event (data.placeholder, event))
......@@ -1035,22 +1089,7 @@ _glade_design_layout_do_event (GladeDesignLayout * layout, GdkEvent * event)
else
retval = FALSE;
priv->should_scroll = TRUE;
_glade_design_view_thaw (priv->view);
return retval;
}
/*
* _glade_design_layout_should_scroll:
* @layout: A #GladeDesignLayout
*
*
*
* Returns: true if it is ok to scroll or not.
*/
gboolean
_glade_design_layout_should_scroll (GladeDesignLayout *layout)
{
GladeDesignLayoutPrivate *priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (layout);
return priv->should_scroll;
}
......@@ -26,6 +26,7 @@
#define __GLADE_DESIGN_LAYOUT_H__
#include <gtk/gtk.h>
#include "glade-design-view.h"
G_BEGIN_DECLS
......@@ -61,13 +62,11 @@ struct _GladeDesignLayoutClass
GType glade_design_layout_get_type (void) G_GNUC_CONST;
GtkWidget *_glade_design_layout_new (void);
GtkWidget *_glade_design_layout_new (GladeDesignView *view);
gboolean _glade_design_layout_do_event (GladeDesignLayout *layout,
GdkEvent *event);
gboolean _glade_design_layout_should_scroll (GladeDesignLayout *layout);
G_END_DECLS
#endif /* __GLADE_DESIGN_LAYOUT_H__ */
/*
* glade-design-private.h
*
* Copyright (C) 2011 Juan Pablo Ugarte
*
* Authors:
* Juan Pablo Ugarte <juanpablougarte@gmail.com>
*
* 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
* MERCHANDESIGN_VIEWILITY 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef __GLADE_DESIGN_PRIVATE_H__
#define __GLADE_DESIGN_PRIVATE_H__
G_BEGIN_DECLS
void _glade_design_view_freeze (GladeDesignView *view);
void _glade_design_view_thaw (GladeDesignView *view);
G_END_DECLS
#endif /* __GLADE_DESIGN_PRIVATE_H__ */
......@@ -38,6 +38,7 @@
#include "glade-utils.h"
#include "glade-design-view.h"
#include "glade-design-layout.h"
#include "glade-design-private.h"
#include <glib.h>
#include <glib/gi18n.h>
......@@ -126,8 +127,7 @@ glade_design_view_selection_changed (GladeProject * project, GladeDesignView * v
if (GTK_IS_WIDGET (toplevel) &&
(layout = gtk_widget_get_parent (GTK_WIDGET (toplevel))) &&
GLADE_IS_DESIGN_LAYOUT (layout) &&
_glade_design_layout_should_scroll (GLADE_DESIGN_LAYOUT (layout)))
GLADE_IS_DESIGN_LAYOUT (layout))
{
gdouble vadj_val, hadj_val, vpage_end, hpage_end;
GtkAdjustment *vadj, *hadj;
......@@ -155,40 +155,58 @@ glade_design_view_selection_changed (GladeProject * project, GladeDesignView * v
}
}
static void
glade_design_view_remove_toplevel (GladeDesignView *view, GladeWidget *widget)
{
GtkWidget *layout;
GObject *object;
if (glade_widget_get_parent (widget) ||
(object = glade_widget_get_object (widget)) == NULL ||
!GTK_IS_WIDGET (object)) return;
/* Remove toplevel widget from the view */
layout = gtk_widget_get_parent (GTK_WIDGET (object));
if (layout)
{
gtk_container_remove (GTK_CONTAINER (layout), GTK_WIDGET (object));
gtk_container_remove (GTK_CONTAINER (view->priv->layout_box), layout);
}
}
static void
glade_design_view_widget_visibility_changed (GladeProject *project,
GladeWidget *widget,
gboolean visible,
GladeDesignView *view)
{
if (visible) return;
glade_design_view_remove_toplevel (view, widget);
}
static void
on_project_add_widget (GladeProject *project, GladeWidget *widget, GladeDesignView *view)
{
GtkWidget *layout;
GObject *object;
/* Ignore non toplevel widgets */
if (glade_widget_get_parent (widget) ||
(object = glade_widget_get_object (widget)) == NULL ||
!GTK_IS_WIDGET (object)) return;
if (visible)
{
/* Create a GladeDesignLayout and add the toplevel widget to the view */
layout = _glade_design_layout_new ();
layout = _glade_design_layout_new (view);
gtk_box_pack_start (GTK_BOX (view->priv->layout_box), layout, FALSE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (layout), GTK_WIDGET (object));
gtk_widget_show (GTK_WIDGET (object));
gtk_widget_show (layout);
}
else
{
/* Remove toplevel widget from the view */
layout = gtk_widget_get_parent (GTK_WIDGET (object));
if (layout)
{
gtk_container_remove (GTK_CONTAINER (layout), GTK_WIDGET (object));
gtk_container_remove (GTK_CONTAINER (view->priv->layout_box), layout);
}
}
}
static void
on_project_remove_widget (GladeProject *project, GladeWidget *widget, GladeDesignView *view)
{
glade_design_view_remove_toplevel (view, widget);
}
static void
......@@ -198,6 +216,10 @@ glade_design_view_set_project (GladeDesignView * view, GladeProject * project)
view->priv->project = project;
g_signal_connect (project, "add-widget",
G_CALLBACK (on_project_add_widget), view);
g_signal_connect (project, "remove-widget",
G_CALLBACK (on_project_remove_widget), view);
g_signal_connect (project, "parse-began",
G_CALLBACK (glade_design_view_parse_began), view);
g_signal_connect (project, "parse-finished",
......@@ -347,6 +369,30 @@ glade_design_view_class_init (GladeDesignViewClass * klass)
g_type_class_add_private (object_class, sizeof (GladeDesignViewPrivate));
}
/* Private API */
void
_glade_design_view_freeze (GladeDesignView *view)
{
g_return_if_fail (GLADE_IS_DESIGN_VIEW (view));
g_signal_handlers_block_by_func (view->priv->project,
glade_design_view_selection_changed,
view);
}
void
_glade_design_view_thaw (GladeDesignView *view)
{
g_return_if_fail (GLADE_IS_DESIGN_VIEW (view));
g_signal_handlers_unblock_by_func (view->priv->project,
glade_design_view_selection_changed,
view);
}
/* Public API */
GladeProject *
glade_design_view_get_project (GladeDesignView * view)
{
......
......@@ -27,7 +27,6 @@
#include <gladeui/glade.h>
#include <gladeui/glade-project.h>
#include <gladeui/glade-design-layout.h>
#include <gtk/gtk.h>
......@@ -70,9 +69,6 @@ GladeProject *glade_design_view_get_project (GladeDesignView *view);
GladeDesignView *glade_design_view_get_from_project (GladeProject *project);
GladeDesignLayout *glade_design_view_get_layout (GladeDesignView *view);
G_END_DECLS
#endif /* __GLADE_DESIGN_VIEW_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment