153 lines
4.2 KiB
C
153 lines
4.2 KiB
C
/*
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#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;
|
|
}
|
|
|
|
void vn_window_add_form (VnWindow * window, const gchar * icon, const gchar * title, GtkWidget * form)
|
|
{
|
|
GtkBox * hbox;
|
|
GtkWidget * widget, * button;
|
|
GtkNotebook * notebook;
|
|
|
|
g_return_if_fail (VN_IS_WINDOW (window));
|
|
|
|
hbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5));
|
|
|
|
widget = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_MENU);
|
|
gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
|
|
|
|
widget = gtk_label_new (title);
|
|
gtk_box_pack_start (hbox, widget, TRUE, TRUE, 0);
|
|
|
|
button = gtk_button_new ();
|
|
g_signal_connect (button, "clicked",
|
|
G_CALLBACK (vn_gui_close_form), form);
|
|
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
|
|
gtk_box_pack_start (hbox, button, FALSE, FALSE, 0);
|
|
|
|
widget = gtk_image_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_MENU);
|
|
gtk_button_set_image (GTK_BUTTON (button), widget);
|
|
|
|
notebook = window->notebook;
|
|
gtk_notebook_set_current_page (notebook,
|
|
gtk_notebook_append_page (notebook, form, GTK_WIDGET (hbox)));
|
|
gtk_notebook_set_tab_detachable (notebook, form, TRUE);
|
|
gtk_notebook_set_tab_reorderable (notebook, form, TRUE);
|
|
gtk_container_child_set (GTK_CONTAINER (notebook), form,
|
|
"tab-expand", TRUE, NULL);
|
|
|
|
gtk_widget_show_all (GTK_WIDGET (hbox));
|
|
}
|
|
|
|
void vn_window_set_show_tabs (VnWindow * window)
|
|
{
|
|
gtk_notebook_set_show_tabs (window->notebook,
|
|
gtk_notebook_get_n_pages (window->notebook) > 1);
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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;
|
|
}
|