[evolution/webkit-composer: 66/111] Introduce EEditorWindow



commit 19e85051e0bc17e3f552fa0236070a81181c588f
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.

 e-util/Makefile.am       |    2 +
 e-util/e-editor-window.c |  168 ++++++++++++++++++++++++++++++++++++++++++++++
 e-util/e-editor-window.h |   78 +++++++++++++++++++++
 e-util/e-editor.c        |   15 ----
 e-util/e-util.h          |    1 +
 e-util/test-editor.c     |   10 +--
 6 files changed, 253 insertions(+), 21 deletions(-)
---
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index 3a403e2..52e19b0 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -186,6 +186,7 @@ eutilinclude_HEADERS =  \
 	e-editor-text-dialog.h \
 	e-editor-utils.h \
 	e-editor-widget.h \
+	e-editor-window.h \
 	e-editor.h \
 	e-emoticon-action.h \
 	e-emoticon-chooser-menu.h \
@@ -459,6 +460,7 @@ libeutil_la_SOURCES = \
 	e-editor-text-dialog.c \
 	e-editor-utils.c \
 	e-editor-widget.c \
+	e-editor-window.c \
 	e-editor.c \
 	e-emoticon-action.c \
 	e-emoticon-chooser-menu.c \
diff --git a/e-util/e-editor-window.c b/e-util/e-editor-window.c
new file mode 100644
index 0000000..fd55563
--- /dev/null
+++ b/e-util/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/e-util/e-editor-window.h b/e-util/e-editor-window.h
new file mode 100644
index 0000000..adb9bbc
--- /dev/null
+++ b/e-util/e-editor-window.h
@@ -0,0 +1,78 @@
+/*
+ * 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/>
+ *
+ */
+
+#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
+#error "Only <e-util/e-util.h> should be included directly."
+#endif
+
+#ifndef E_EDITOR_WINDOW_H
+#define E_EDITOR_WINDOW_H
+
+#include <gtk/gtk.h>
+#include <e-util/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/e-util/e-editor.c b/e-util/e-editor.c
index fcf6d8e..0c4d667 100644
--- a/e-util/e-editor.c
+++ b/e-util/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);
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 65593cb..05a3a6a 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -106,6 +106,7 @@
 #include <e-util/e-editor-text-dialog.h>
 #include <e-util/e-editor-utils.h>
 #include <e-util/e-editor-widget.h>
+#include <e-util/e-editor-window.h>
 #include <e-util/e-editor.h>
 #include <e-util/e-emoticon-action.h>
 #include <e-util/e-emoticon-chooser-menu.h>
diff --git a/e-util/test-editor.c b/e-util/test-editor.c
index d103268..febfee4 100644
--- a/e-util/test-editor.c
+++ b/e-util/test-editor.c
@@ -386,7 +386,8 @@ gint main (gint argc,
 {
 	GtkActionGroup *action_group;
 	GtkUIManager *manager;
-	GtkWidget *window, *editor;
+	GtkWidget *window;
+	EEditor *editor;
 	WebKitWebInspector *inspector;
 
 	GError *error = NULL;
@@ -397,15 +398,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))));



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