diff --git a/vn/Makefile.am b/vn/Makefile.am
index 8d6e982..26d3f44 100644
--- a/vn/Makefile.am
+++ b/vn/Makefile.am
@@ -11,6 +11,7 @@ vn_include_HEADERS = \
vn-column.h \
vn-login.h \
vn-gui.h \
+ vn-window.h \
vn-mod.h \
vn-form.h \
vn-grid-model.h \
@@ -20,6 +21,9 @@ vn_include_HEADERS = \
field/field.h \
column/column.h
+noinst_HEADERS = \
+ vn-gui-private.h
+
AM_CPPFLAGS = \
-I$(top_srcdir) \
$(DEFINES) \
@@ -37,6 +41,7 @@ libvn_files = \
vn-column.c \
vn-login.c \
vn-gui.c \
+ vn-window.c \
vn-mod.c \
vn-form.c \
vn-grid-model.c \
@@ -52,6 +57,7 @@ glade_files = \
$(top_srcdir)/vn/glade/vn-batch.c
libvn_la_SOURCES = \
$(libvn_files) \
+ $(noinst_HEADERS) \
$(glade_files)
pkgconfig_DATA = vn.pc
diff --git a/vn/vn-gui-private.h b/vn/vn-gui-private.h
new file mode 100644
index 0000000..9cf0169
--- /dev/null
+++ b/vn/vn-gui-private.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 - Juan Ferrer Toribio
+ *
+ * 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 3 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, see .
+ */
+
+#ifndef VN_GUI_PRIVATE_H
+#define VN_GUI_PRIVATE_H
+
+#include "vn-gui.h"
+
+VnWindow * vn_gui_add_window (VnGui * obj, VnWindow * window);
+
+gboolean vn_gui_on_last_window_deleted (GtkWidget * widget, GdkEvent * event, VnWindow * window);
+void vn_gui_on_window_destroyed (GtkWindow * widget, VnWindow * window);
+gboolean vn_gui_on_window_focused (GtkWidget * widget, GdkEvent * event, VnWindow * window);
+
+GtkNotebook * vn_gui_on_page_detached (GtkNotebook * old_notebook, GtkWidget * page, gint x, gint y, VnWindow * window);
+void vn_gui_on_switch_page (GtkNotebook * notebook, VnForm * form, guint num, VnWindow * window);
+void vn_gui_on_page_removed (GtkNotebook * notebook, GtkWidget * page, guint num, VnWindow * window);
+void vn_gui_on_page_added (GtkNotebook * notebook, GtkWidget * page, guint num, VnWindow * window);
+
+#endif
\ No newline at end of file
diff --git a/vn/vn-gui.c b/vn/vn-gui.c
index 18d332f..61addd3 100644
--- a/vn/vn-gui.c
+++ b/vn/vn-gui.c
@@ -142,17 +142,6 @@ static void gui_data_free (GuiData * gui_data)
g_free (gui_data);
}
-static void vn_gui_free_window (VnGui * obj, VnWindow * window)
-{
- g_signal_handlers_disconnect_by_func (window->widget,
- vn_gui_on_window_destroyed, window);
- g_signal_handlers_disconnect_by_func (window->notebook,
- vn_gui_on_page_removed, window);
-
- gtk_widget_destroy (GTK_WIDGET (window->widget));
- g_free (window);
-}
-
/*
* Validates a module definition file at @path against the DTD
*/
@@ -464,22 +453,19 @@ static void vn_gui_set_menu_accels (VnGui * obj, GMenuModel * menu, gboolean ena
}
}
-static VnWindow * vn_gui_add_window (VnGui * obj, GtkWindow * widget, GtkNotebook * notebook)
+VnWindow * vn_gui_add_window (VnGui * obj, VnWindow * window)
{
GSList * n;
GtkWidget * button;
- VnWindow * window = g_new (VnWindow, 1);
+ GtkWindow * widget = window->widget;
- window->obj = obj;
- window->widget = widget;
- window->notebook = notebook;
window->active_form = NULL;
window->merge_id = 0;
obj->windows = g_slist_prepend (obj->windows, window);
gtk_application_add_window (obj->app, widget);
- gtk_notebook_set_group_name (notebook,
+ gtk_notebook_set_group_name (window->notebook,
g_application_get_application_id (G_APPLICATION (obj->app)));
// Setting header and window menu
@@ -492,7 +478,7 @@ static VnWindow * vn_gui_add_window (VnGui * obj, GtkWindow * widget, GtkNoteboo
gtk_window_set_titlebar (widget, GTK_WIDGET (window->header));
button = gtk_menu_button_new ();
- g_action_map_add_action_entries (G_ACTION_MAP (window->widget),
+ g_action_map_add_action_entries (G_ACTION_MAP (widget),
win_entries, G_N_ELEMENTS (win_entries), window);
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), obj->main_menu);
gtk_button_set_image (GTK_BUTTON (button),
@@ -511,7 +497,7 @@ static VnWindow * vn_gui_add_window (VnGui * obj, GtkWindow * widget, GtkNoteboo
// Loading the modules actions
- g_action_map_add_action_entries (G_ACTION_MAP (window->widget),
+ g_action_map_add_action_entries (G_ACTION_MAP (widget),
open_action, G_N_ELEMENTS (open_action), window);
for (n = obj->modules; n; n = n->next)
@@ -519,7 +505,7 @@ static VnWindow * vn_gui_add_window (VnGui * obj, GtkWindow * widget, GtkNoteboo
gint size;
VnMod * mod = VN_MOD (n->data);
const GActionEntry * actions = vn_mod_get_actions (mod, &size);
- g_action_map_add_action_entries (G_ACTION_MAP (window->widget),
+ g_action_map_add_action_entries (G_ACTION_MAP (widget),
actions, size, mod);
}
@@ -586,7 +572,7 @@ static void vn_gui_close (VnGui * obj)
);
for (n = obj->windows; n; n = n->next)
- vn_gui_free_window (obj, n->data);
+ g_object_unref (n->data);
g_slist_free (obj->windows);
obj->windows = NULL;
@@ -715,8 +701,8 @@ gboolean vn_gui_on_last_window_deleted (GtkWidget * widget, GdkEvent * event, Vn
*/
void vn_gui_on_window_destroyed (GtkWindow * widget, VnWindow * window)
{
- VnGui * obj = window->obj;
- vn_gui_free_window (obj, window);
+ VnGui * obj = window->gui;
+ g_object_unref (window);
obj->windows = g_slist_remove (obj->windows, window);
}
@@ -739,7 +725,7 @@ gboolean vn_gui_on_window_focused (GtkWidget * widget, GdkEvent * event, VnWindo
GtkNotebook * vn_gui_on_page_detached (GtkNotebook * old_notebook,
GtkWidget * page, gint x, gint y, VnWindow * window)
{
- VnWindow * new_window = vn_gui_create_window (window->obj, x, y);
+ VnWindow * new_window = vn_window_new (window->gui, x, y);
return (window) ? new_window->notebook : NULL;
}
@@ -832,12 +818,8 @@ void vn_gui_on_open_form_activated (GSimpleAction * a, GVariant * p, gpointer ob
void vn_gui_on_new_window_activated (GSimpleAction * a, GVariant * v, gpointer obj)
{
gint x , y;
- VnWindow * w;
- VnGui * o = obj;
-
- gtk_window_get_position (o->active_window->widget, &x, &y);
- w = vn_gui_create_window (obj, x + 100, y + 100);
- gtk_window_resize (w->widget, 500, 500);
+ gtk_window_get_position (VN_GUI (obj)->active_window->widget, &x, &y);
+ vn_window_new (obj, x + 100, y + 100);
}
/*
@@ -1013,7 +995,7 @@ void vn_gui_open (VnGui * obj)
height = g_key_file_get_integer (config, windows[m], "height", NULL);
maximized = g_key_file_get_boolean (config, windows[m], "maximized", NULL);
- window = vn_gui_create_window (obj, x, y);
+ window = vn_window_new (obj, x, y);
gtk_window_resize (window->widget, width, height);
if (maximized)
@@ -1031,10 +1013,7 @@ void vn_gui_open (VnGui * obj)
g_strfreev (windows);
}
else
- {
- VnWindow * window = vn_gui_create_window (obj, 100, 100);
- gtk_window_resize (window->widget, 500, 400);
- }
+ vn_window_new (obj, 100, 100);
g_key_file_free (config);
@@ -1075,7 +1054,7 @@ void vn_gui_save (VnGui * obj)
for (m = obj->windows; m; m = m->next)
{
- window = (VnWindow *) m->data;
+ window = m->data;
group = g_strdup_printf ("window%d", i++);
// Saving the window position and size
@@ -1113,46 +1092,6 @@ void vn_gui_save (VnGui * obj)
g_key_file_free (config);
}
-/**
- * vn_gui_create_window:
- * @obj: the #VnGui
- * @x: the x coordinate
- * @y: the y coordinate
- *
- * Creates a new window.
- *
- * Return value: VnWindow.
- **/
-VnWindow * vn_gui_create_window (VnGui * obj, gint x, gint y)
-{
- GtkBuilder * builder;
- VnWindow * window = NULL;
- GError * err = NULL;
-
- g_return_val_if_fail (VN_IS_GUI (obj), NULL);
-
- builder = gtk_builder_new ();
-
- if (gtk_builder_add_from_file (builder, MAIN_UI, &err))
- {
- GtkWindow * widget = gtk_builder_get (builder, "window");
- GtkNotebook * notebook = gtk_builder_get (builder, "notebook");
- gtk_window_move (widget, x, y);
-
- window = vn_gui_add_window (obj, widget, notebook);
- window->about = gtk_builder_get (builder, "about");
- gtk_builder_connect_signals (builder, window);
- }
- else
- {
- g_warning ("VnGui: %s", err->message);
- g_error_free (err);
- }
-
- g_object_unref (builder);
- return window;
-}
-
/**
* vn_gui_open_form_at_window:
* @obj: the #VnGui
diff --git a/vn/vn-gui.h b/vn/vn-gui.h
index 9f47b6a..e3e9e98 100644
--- a/vn/vn-gui.h
+++ b/vn/vn-gui.h
@@ -35,6 +35,7 @@ typedef struct _VnWindow VnWindow;
#include "vn-mod.h"
#include "vn-form.h"
+#include "vn-window.h"
/*
* @windows: (element-type VnWindow):
@@ -69,7 +70,6 @@ GType vn_gui_get_type ();
VnGui * vn_gui_new (GtkApplication * app, DbConn * conn);
void vn_gui_open (VnGui * obj);
void vn_gui_save (VnGui * obj);
-VnWindow * vn_gui_create_window (VnGui * obj, gint x, gint y);
VnForm * vn_gui_open_form_at_window (VnGui * obj, const gchar * form_name, VnWindow * window);
VnForm * vn_gui_open_form (VnGui * obj, const gchar * form_name);
void vn_gui_close_form (VnGui * obj, VnForm * form);
diff --git a/vn/vn-window.c b/vn/vn-window.c
new file mode 100644
index 0000000..f1034f5
--- /dev/null
+++ b/vn/vn-window.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2012 - Juan Ferrer Toribio
+ *
+ * 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 3 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, see .
+ */
+
+#include "vn-window.h"
+#include "vn-gui-private.h"
+
+#define MAIN_UI _GUI_DIR"/main.glade"
+
+#define gtk_builder_get(builder, id) ((gpointer) gtk_builder_get_object (builder, id))
+
+/**
+ * SECTION: vn-window
+ * @Short_description: The windows used by hedera
+ * @Title: VnWindow
+ *
+ * The windows used by hedera.
+ */
+G_DEFINE_TYPE (VnWindow, vn_window, G_TYPE_OBJECT);
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
+
+/**
+ * vn_window_new:
+ * @gui: the #VnGui
+ * @x: the global x coordinate position
+ * @y: the global y coordinate position
+ *
+ * Creates a new window at (@x, @y).
+ *
+ * Return value: #VnWindow.
+ **/
+VnWindow * vn_window_new (VnGui * gui, gint x, gint y)
+{
+ VnWindow * self;
+ GtkBuilder * builder;
+ GError * err = NULL;
+
+ g_return_val_if_fail (VN_IS_GUI (gui), NULL);
+
+ self = g_object_new (VN_TYPE_WINDOW, NULL);
+ self->gui = g_object_ref (gui);
+ builder = gtk_builder_new ();
+
+ if (gtk_builder_add_from_file (builder, MAIN_UI, &err))
+ {
+ self->widget = gtk_builder_get (builder, "window");
+ self->notebook = gtk_builder_get (builder, "notebook");
+ gtk_window_move (self->widget, x, y);
+
+ self = vn_gui_add_window (gui, self);
+ self->about = gtk_builder_get (builder, "about");
+ gtk_builder_connect_signals (builder, self);
+ }
+ else
+ {
+ g_warning ("VnGui: %s", err->message);
+ g_error_free (err);
+ }
+
+ g_object_unref (builder);
+ return self;
+}
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
+
+static void vn_window_init (VnWindow * self)
+{
+ self->gui = NULL;
+ self->widget = NULL;
+ self->about = NULL;
+ self->header = NULL;
+ self->menu_button = NULL;
+ self->spinner = NULL;
+ self->notebook = NULL;
+ self->active_form = NULL;
+ self->maximized = FALSE;
+}
+
+static void vn_window_finalize (VnWindow * self)
+{
+ g_signal_handlers_disconnect_by_func (self->widget,
+ vn_gui_on_window_destroyed, self);
+ g_signal_handlers_disconnect_by_func (self->notebook,
+ vn_gui_on_page_removed, self);
+
+ gtk_widget_destroy (GTK_WIDGET (self->widget));
+ g_object_unref (self->gui);
+
+ G_OBJECT_CLASS (vn_window_parent_class)->finalize (G_OBJECT (self));
+}
+
+static void vn_window_class_init (VnWindowClass * klass)
+{
+ GObjectClass * k = G_OBJECT_CLASS (klass);
+ k->finalize = (GObjectFinalizeFunc) vn_window_finalize;
+}
diff --git a/vn/vn-window.h b/vn/vn-window.h
new file mode 100644
index 0000000..297ac5f
--- /dev/null
+++ b/vn/vn-window.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2012 - Juan Ferrer Toribio
+ *
+ * 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 3 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, see .
+ */
+
+#ifndef VN_WINDOW_H
+#define VN_WINDOW_H
+
+#include
+
+#define VN_TYPE_WINDOW (vn_window_get_type ())
+#define VN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, VN_TYPE_WINDOW, VnWindow))
+#define VN_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, VN_TYPE_WINDOW))
+#define VN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, VN_TYPE_WINDOW, VnWindowClass))
+#define VN_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (klass, VN_TYPE_WINDOW))
+#define VN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS (obj, VN_TYPE_WINDOW, VnWindowClass))
+
+typedef struct _VnWindow VnWindow;
+typedef struct _VnWindowClass VnWindowClass;
+
+#include "vn-gui.h"
+
+struct _VnWindow
+{
+ GObject parent;
+
+ VnGui * gui;
+ GtkWindow * widget;
+ GtkDialog * about;
+ GtkHeaderBar * header;
+ GtkWidget * menu_button;
+ GtkWidget * spinner;
+ GtkNotebook * notebook;
+ VnForm * active_form;
+ gboolean maximized;
+};
+
+struct _VnWindowClass
+{
+ GObjectClass parent;
+};
+
+GType vn_window_get_type ();
+
+VnWindow * vn_window_new (VnGui * gui, gint x, gint y);
+
+#endif