[evolution/webkit-composer: 23/30] Introduce EEditorWindow



commit 38c7c42198bc4694db42a2c587b30cfbcf7981ed
Author: Dan VrÃtil <dvratil redhat com>
Date:   Mon Aug 27 17:22:37 2012 +0200

    Introduce EEditorWindow
    
    EEditorWindow is a GtkWindow which already contains EEditor
    and toolbars.

 widgets/editor/Makefile.am       |    3 +-
 widgets/editor/e-editor-test.c   |   11 +--
 widgets/editor/e-editor-window.c |  168 ++++++++++++++++++++++++++++++++++++++
 widgets/editor/e-editor-window.h |   74 +++++++++++++++++
 widgets/editor/e-editor.c        |   15 ----
 5 files changed, 249 insertions(+), 22 deletions(-)
---
diff --git a/widgets/editor/Makefile.am b/widgets/editor/Makefile.am
index f25d1dd..cbac87e 100644
--- a/widgets/editor/Makefile.am
+++ b/widgets/editor/Makefile.am
@@ -53,7 +53,8 @@ libeeditor_la_SOURCES =						\
 	e-editor-utils.h					\
 	e-editor-widget.c					\
 	e-editor-widget.h					\
-	e-editor-widgets.h					\
+	e-editor-window.c					\
+	e-editor-window.h					\
 	e-editor.c						\
 	e-editor.h						\
 	e-emoticon-action.c					\
diff --git a/widgets/editor/e-editor-test.c b/widgets/editor/e-editor-test.c
index e972a60..10c335a 100644
--- a/widgets/editor/e-editor-test.c
+++ b/widgets/editor/e-editor-test.c
@@ -22,6 +22,7 @@
 
 #include <gtk/gtk.h>
 #include "e-editor.h"
+#include "e-editor-window.h"
 
 #include <glib/gi18n-lib.h>
 
@@ -386,7 +387,8 @@ gint main (gint argc,
 {
 	GtkActionGroup *action_group;
 	GtkUIManager *manager;
-	GtkWidget *window, *editor;
+	GtkWidget *window;
+	EEditor *editor;
 	WebKitWebInspector *inspector;
 
 	GError *error = NULL;
@@ -397,15 +399,12 @@ gint main (gint argc,
 
 	gtk_init (&argc, &argv);
 
-        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+        window = g_object_new (E_TYPE_EDITOR_WINDOW, GTK_WINDOW_TOPLEVEL, NULL);
         gtk_widget_set_size_request (window, 600, 400);
         g_signal_connect_swapped (window, "destroy",
                 G_CALLBACK (gtk_main_quit), NULL);
 
-	editor = e_editor_new ();
-	gtk_container_add (GTK_CONTAINER (window), editor);
-	gtk_widget_show (editor);
-
+	editor = e_editor_window_get_editor (E_EDITOR_WINDOW (window));
 	inspector = webkit_web_view_get_inspector (
 			WEBKIT_WEB_VIEW (e_editor_get_editor_widget (
 				E_EDITOR (editor))));
diff --git a/widgets/editor/e-editor-window.c b/widgets/editor/e-editor-window.c
new file mode 100644
index 0000000..fd55563
--- /dev/null
+++ b/widgets/editor/e-editor-window.c
@@ -0,0 +1,168 @@
+/*
+ * e-editor-window.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-editor-window.h"
+
+G_DEFINE_TYPE (
+	EEditorWindow,
+	e_editor_window,
+	GTK_TYPE_WINDOW)
+
+struct _EEditorWindowPrivate {
+	EEditor *editor;
+	GtkGrid *main_layout;
+
+	GtkWidget *main_menu;
+	GtkWidget *main_toolbar;
+
+	gint editor_row;
+};
+
+enum {
+	PROP_0,
+	PROP_EDITOR
+};
+
+static void
+editor_window_get_property (GObject *object,
+			    guint property_id,
+			    GValue *value,
+			    GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_EDITOR:
+			g_value_set_object (
+				value, E_EDITOR_WINDOW (object)->priv->editor);
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+e_editor_window_class_init (EEditorWindowClass *klass)
+{
+	GObjectClass *object_class;
+
+	e_editor_window_parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (EEditorWindowPrivate));
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->get_property = editor_window_get_property;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_EDITOR,
+		g_param_spec_object (
+			"editor",
+		        NULL,
+		       	NULL,
+		        E_TYPE_EDITOR,
+		        G_PARAM_READABLE));
+}
+
+static void
+e_editor_window_init (EEditorWindow *window)
+{
+	EEditorWindowPrivate *priv;
+	GtkWidget *widget;
+
+	window->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+		window, E_TYPE_EDITOR_WINDOW, EEditorWindowPrivate);
+
+	priv = window->priv;
+	priv->editor = E_EDITOR (e_editor_new ());
+
+	priv->main_layout = GTK_GRID (gtk_grid_new ());
+	gtk_orientable_set_orientation (
+		GTK_ORIENTABLE (priv->main_layout), GTK_ORIENTATION_VERTICAL);
+	gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (priv->main_layout));
+	gtk_widget_show (GTK_WIDGET (priv->main_layout));
+
+	widget = e_editor_get_managed_widget (priv->editor, "/main-menu");
+	gtk_grid_attach (priv->main_layout, widget, 0, 0, 1, 1);
+	gtk_widget_set_hexpand (widget, TRUE);
+	priv->main_menu = g_object_ref (widget);
+	gtk_widget_show (widget);
+
+	widget = e_editor_get_managed_widget (priv->editor, "/main-toolbar");
+	gtk_widget_set_hexpand (widget, TRUE);
+	gtk_grid_attach (
+		priv->main_layout, widget, 0, 1, 1, 1);
+	priv->main_toolbar = g_object_ref (widget);
+	gtk_widget_show (widget);
+
+	gtk_style_context_add_class (
+		gtk_widget_get_style_context (widget),
+		GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
+
+	gtk_widget_set_hexpand (GTK_WIDGET (priv->editor), TRUE);
+	gtk_grid_attach (
+		priv->main_layout, GTK_WIDGET (priv->editor),
+		0, 2, 1, 1);
+	gtk_widget_show (GTK_WIDGET (priv->editor));
+	priv->editor_row = 2;
+}
+
+GtkWidget *
+e_editor_window_new (GtkWindowType type)
+{
+	return g_object_new (
+		E_TYPE_EDITOR_WINDOW,
+		"type", type,
+		NULL);
+}
+
+EEditor *
+e_editor_window_get_editor (EEditorWindow *window)
+{
+	g_return_val_if_fail (E_IS_EDITOR_WINDOW (window), NULL);
+
+	return window->priv->editor;
+}
+
+void
+e_editor_window_pack_above (EEditorWindow *window,
+			    GtkWidget *child)
+{
+	g_return_if_fail (E_IS_EDITOR_WINDOW (window));
+	g_return_if_fail (GTK_IS_WIDGET (child));
+
+	gtk_grid_insert_row (window->priv->main_layout, window->priv->editor_row);
+	window->priv->editor_row++;
+	gtk_grid_attach_next_to (
+		window->priv->main_layout, child,
+		GTK_WIDGET (window->priv->editor),
+		GTK_POS_TOP, 1, 1);
+}
+
+void
+e_editor_window_pack_below (EEditorWindow *window,
+			  GtkWidget *child)
+{
+	g_return_if_fail (E_IS_EDITOR_WINDOW (window));
+	g_return_if_fail (GTK_IS_WIDGET (child));
+
+	gtk_grid_attach_next_to (
+		window->priv->main_layout, child,
+		NULL, GTK_POS_BOTTOM, 1, 1);
+}
diff --git a/widgets/editor/e-editor-window.h b/widgets/editor/e-editor-window.h
new file mode 100644
index 0000000..727ba4d
--- /dev/null
+++ b/widgets/editor/e-editor-window.h
@@ -0,0 +1,74 @@
+/*
+ * e-editor-window.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_EDITOR_WINDOW_H
+#define E_EDITOR_WINDOW_H
+
+#include <gtk/gtk.h>
+#include <widgets/editor/e-editor.h>
+
+/* Standard GObject macros */
+#define E_TYPE_EDITOR_WINDOW \
+	(e_editor_window_get_type ())
+#define E_EDITOR_WINDOW(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_EDITOR_WINDOW, EEditorWindow))
+#define E_EDITOR_WINDOW_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_EDITOR_WINDOW, EEditorWindowClass))
+#define E_IS_EDITOR_WINDOW(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_EDITOR_WINDOW))
+#define E_IS_EDITOR_WINDOW_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_EDITOR_WINDOW))
+#define E_EDITOR_WINDOW_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_EDITOR_WINDOW, EEditorWindowClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EEditorWindow EEditorWindow;
+typedef struct _EEditorWindowClass EEditorWindowClass;
+typedef struct _EEditorWindowPrivate EEditorWindowPrivate;
+
+struct _EEditorWindow {
+	GtkWindow parent;
+
+	EEditorWindowPrivate *priv;
+};
+
+struct _EEditorWindowClass {
+	GtkWindowClass parent_class;
+};
+
+GType		e_editor_window_get_type 	(void);
+
+GtkWidget *	e_editor_window_new		(GtkWindowType type);
+
+EEditor *	e_editor_window_get_editor	(EEditorWindow *window);
+
+void		e_editor_window_pack_above	(EEditorWindow *window,
+						 GtkWidget *child);
+
+void		e_editor_window_pack_below	(EEditorWindow *window,
+						 GtkWidget *child);
+
+G_END_DECLS
+
+#endif /* E_EDITOR_WINDOW_H */
diff --git a/widgets/editor/e-editor.c b/widgets/editor/e-editor.c
index fcf6d8e..0c4d667 100644
--- a/widgets/editor/e-editor.c
+++ b/widgets/editor/e-editor.c
@@ -575,21 +575,6 @@ editor_constructed (GObject *object)
 	GtkToolItem *tool_item;
 
 	/* Construct main window widgets. */
-
-	widget = e_editor_get_managed_widget (editor, "/main-menu");
-	gtk_box_pack_start (GTK_BOX (editor), widget, FALSE, FALSE, 0);
-	priv->main_menu = g_object_ref (widget);
-	gtk_widget_show (widget);
-
-	widget = e_editor_get_managed_widget (editor, "/main-toolbar");
-	gtk_box_pack_start (GTK_BOX (editor), widget, FALSE, FALSE, 0);
-	priv->main_toolbar = g_object_ref (widget);
-	gtk_widget_show (widget);
-
-	gtk_style_context_add_class (
-		gtk_widget_get_style_context (widget),
-		GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
-
 	widget = e_editor_get_managed_widget (editor, "/edit-toolbar");
 	gtk_toolbar_set_style (GTK_TOOLBAR (widget), GTK_TOOLBAR_BOTH_HORIZ);
 	gtk_box_pack_start (GTK_BOX (editor), widget, FALSE, FALSE, 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]