1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
|
/*
* gnc-main-window.c -- GtkWindow which represents the
* GnuCash main window.
*
* Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2003 David Hampton <hampton@employees.org>
*
* 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
* 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, contact:
*
* Free Software Foundation Voice: +1-617-542-5942
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
* Boston, MA 02110-1301, USA gnu@gnu.org
*/
#include "config.h"
#include <gtk/gtk.h>
#include "gnc-embedded-window.h"
#include "gnc-engine.h"
#include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h"
#include "gnc-gui-query.h"
#include "gnc-plugin.h"
#include "gnc-plugin-manager.h"
#include "gnc-ui.h"
#include "gnc-window.h"
/* Static Globals *******************************************************/
/** The debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;
/** A pointer to the parent class of an embedded window. */
static GObjectClass *parent_class = NULL;
/* Declarations *********************************************************/
static void gnc_embedded_window_class_init (GncEmbeddedWindowClass *klass);
static void gnc_embedded_window_init (GncEmbeddedWindow *window, GncEmbeddedWindowClass *klass);
static void gnc_embedded_window_finalize (GObject *object);
static void gnc_embedded_window_dispose (GObject *object);
static void gnc_window_embedded_window_init (GncWindowIface *iface);
static void gnc_embedded_window_setup_window (GncEmbeddedWindow *window);
/** The instance private data for an embedded window object. */
typedef struct GncEmbeddedWindowPrivate
{
/** The dock (vbox) at the top of the window containing the menubar
* and toolbar. These items are generated bu the UI manager and
* stored here when the UI manager provides them to the main
* window. */
GtkWidget *menu_dock;
/* The toolbar created by the UI manager. This pointer provides
* easy access for showing/hiding the toolbar. */
GtkWidget *toolbar;
/** A pointer to the status bar at the bottom edge of the window.
* This pointer provides easy access for updating/showing/hiding
* the status bar. */
GtkWidget *statusbar;
/** The group of all actions provided by the main window itself.
* This does not include any action provided by menu or content
* plugins. */
GtkActionGroup *action_group;
/** The currently selected page. */
GncPluginPage *page;
/** The parent of this embedded "window". This points to a real
* GtkWindow widget. */
GtkWidget *parent_window;
} GncEmbeddedWindowPrivate;
#define GNC_EMBEDDED_WINDOW_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_EMBEDDED_WINDOW, GncEmbeddedWindowPrivate))
/* Get the type of a gnc embedded window. */
GType
gnc_embedded_window_get_type (void)
{
static GType gnc_embedded_window_type = 0;
if (gnc_embedded_window_type == 0) {
static const GTypeInfo our_info = {
sizeof (GncEmbeddedWindowClass),
NULL,
NULL,
(GClassInitFunc) gnc_embedded_window_class_init,
NULL,
NULL,
sizeof (GncEmbeddedWindow),
0,
(GInstanceInitFunc) gnc_embedded_window_init
};
static const GInterfaceInfo plugin_info = {
(GInterfaceInitFunc) gnc_window_embedded_window_init,
NULL,
NULL
};
gnc_embedded_window_type = g_type_register_static (GTK_TYPE_VBOX,
"GncEmbeddedWindow",
&our_info, 0);
g_type_add_interface_static (gnc_embedded_window_type,
GNC_TYPE_WINDOW,
&plugin_info);
}
return gnc_embedded_window_type;
}
/* Display a data plugin page in a window. */
void
gnc_embedded_window_open_page (GncEmbeddedWindow *window,
GncPluginPage *page)
{
GncEmbeddedWindowPrivate *priv;
g_return_if_fail (GNC_IS_EMBEDDED_WINDOW (window));
g_return_if_fail (GNC_IS_PLUGIN_PAGE (page));
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
g_return_if_fail (priv->page == NULL);
ENTER("window %p, page %p", window, page);
priv->page = page;
page->window = GTK_WIDGET(window);
page->notebook_page = gnc_plugin_page_create_widget (page);
gtk_box_pack_end(GTK_BOX(window), page->notebook_page, TRUE, TRUE, 2);
gnc_plugin_page_inserted (page);
gnc_plugin_page_merge_actions (page, window->ui_merge);
LEAVE(" ");
}
/* Remove a data plugin page from a window. */
void
gnc_embedded_window_close_page (GncEmbeddedWindow *window,
GncPluginPage *page)
{
GncEmbeddedWindowPrivate *priv;
g_return_if_fail (GNC_IS_EMBEDDED_WINDOW (window));
g_return_if_fail (GNC_IS_PLUGIN_PAGE (page));
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
g_return_if_fail (priv->page == page);
ENTER("window %p, page %p", window, page);
if (!page->notebook_page) {
LEAVE("no displayed widget");
return;
}
gtk_container_remove (GTK_CONTAINER(window), GTK_WIDGET(page->notebook_page));
priv->page = NULL;
gnc_plugin_page_removed (page);
gnc_plugin_page_unmerge_actions (page, window->ui_merge);
gtk_ui_manager_ensure_update (window->ui_merge);
gnc_plugin_page_destroy_widget (page);
g_object_unref(page);
LEAVE(" ");
}
/* Retrieve the plugin that is embedded in the specified window. */
GncPluginPage *
gnc_embedded_window_get_page (GncEmbeddedWindow *window)
{
GncEmbeddedWindowPrivate *priv;
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
return priv->page;
}
/** Initialize the class for a new gnucash embedded window. This will
* set up any function pointers that override functions in the parent
* class.
*
* @param klass The new class structure created by the object system.
*/
static void
gnc_embedded_window_class_init (GncEmbeddedWindowClass *klass)
{
GObjectClass *object_class;
ENTER("klass %p", klass);
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gnc_embedded_window_finalize;
object_class->dispose = gnc_embedded_window_dispose;
g_type_class_add_private(klass, sizeof(GncEmbeddedWindowPrivate));
LEAVE(" ");
}
/** Initialize a new instance of a gnucash embedded window. This
* function initializes the object private storage space. It also
* adds the new object to a list (for memory tracking purposes).
*
* @param view The new object instance created by the object system.
*
* @param klass A pointer to the class data structure for this
* object. */
static void
gnc_embedded_window_init (GncEmbeddedWindow *window,
GncEmbeddedWindowClass *klass)
{
ENTER("window %p", window);
gnc_embedded_window_setup_window (window);
gnc_gobject_tracking_remember(G_OBJECT(window),
G_OBJECT_CLASS(klass));
LEAVE(" ");
}
/** Finish destruction of an embedded window.
*
* @object The window being destroyed. */
static void
gnc_embedded_window_finalize (GObject *object)
{
GncEmbeddedWindow *window;
GncEmbeddedWindowPrivate *priv;
g_return_if_fail (object != NULL);
g_return_if_fail (GNC_IS_EMBEDDED_WINDOW (object));
ENTER("object %p", object);
window = GNC_EMBEDDED_WINDOW (object);
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
gnc_gobject_tracking_forget(object);
G_OBJECT_CLASS (parent_class)->finalize (object);
LEAVE(" ");
}
/** Begin destruction of an embedded window. This function should
* release all objects referenced by the window (i.e. the page).
*
* @object The window being destroyed. */
static void
gnc_embedded_window_dispose (GObject *object)
{
GncEmbeddedWindow *window;
GncEmbeddedWindowPrivate *priv;
g_return_if_fail (object != NULL);
g_return_if_fail (GNC_IS_EMBEDDED_WINDOW (object));
ENTER("object %p", object);
window = GNC_EMBEDDED_WINDOW (object);
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
if (priv->page) {
DEBUG("unreffing page %p (count currently %d)", priv->page,
G_OBJECT(priv->page)->ref_count);
g_object_unref(priv->page);
priv->page = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
LEAVE(" ");
}
static void
gnc_embedded_window_add_widget (GtkUIManager *merge,
GtkWidget *widget,
GncEmbeddedWindow *window)
{
GncEmbeddedWindowPrivate *priv;
ENTER("merge %p, new widget %p, window %p", merge, widget, window);
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
if (GTK_IS_TOOLBAR (widget)) {
priv->toolbar = widget;
}
gtk_box_pack_start (GTK_BOX (priv->menu_dock), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
LEAVE(" ");
}
/** Initialize the data structures of a gnucash embedded window.
*
* @param window The object to initialize. */
static void
gnc_embedded_window_setup_window (GncEmbeddedWindow *window)
{
GncEmbeddedWindowPrivate *priv;
ENTER("window %p", window);
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
/* Create widgets and add them to the window */
gtk_widget_show (GTK_WIDGET(window));
priv->menu_dock = gtk_vbox_new (FALSE, 0);
gtk_widget_show (priv->menu_dock);
gtk_box_pack_start (GTK_BOX (window), priv->menu_dock, TRUE, TRUE, 0);
priv->statusbar = gtk_statusbar_new ();
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR(priv->statusbar), FALSE);
gtk_widget_show (priv->statusbar);
gtk_box_pack_end (GTK_BOX (window), priv->statusbar, FALSE, TRUE, 0);
window->ui_merge = gtk_ui_manager_new ();
g_signal_connect (G_OBJECT (window->ui_merge), "add_widget",
G_CALLBACK (gnc_embedded_window_add_widget), window);
priv->action_group = NULL;
LEAVE(" ");
}
/** Create a new gnc embedded window plugin. */
GncEmbeddedWindow *
gnc_embedded_window_new (const gchar *action_group_name,
GtkActionEntry *action_entries,
gint n_action_entries,
const gchar *ui_filename,
GtkWidget *enclosing_win,
gboolean add_accelerators,
gpointer user_data)
{
GncEmbeddedWindowPrivate *priv;
GncEmbeddedWindow *window;
gchar *ui_fullname;
GError *error = NULL;
guint merge_id;
ENTER("group %s, first %p, num %d, ui file %s, parent %p, add accelerators %d, user data %p",
action_group_name, action_entries, n_action_entries, ui_filename,
enclosing_win, add_accelerators, user_data);
window = g_object_new (GNC_TYPE_EMBEDDED_WINDOW, NULL);
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
/* Determine the full pathname of the ui file */
ui_fullname = gnc_gnome_locate_ui_file(ui_filename);
priv->parent_window = enclosing_win;
/* Create menu and toolbar information */
priv->action_group = gtk_action_group_new (action_group_name);
gnc_gtk_action_group_set_translation_domain(priv->action_group, GETTEXT_PACKAGE);
gtk_action_group_add_actions (priv->action_group, action_entries,
n_action_entries, user_data);
gtk_ui_manager_insert_action_group (window->ui_merge, priv->action_group, 0);
merge_id = gtk_ui_manager_add_ui_from_file (window->ui_merge, ui_fullname,
&error);
/* Error checking */
g_assert(merge_id || error);
if (error) {
g_critical("Failed to load ui file.\n Filename %s\n Error %s",
ui_fullname, error->message);
g_error_free(error);
g_free(ui_fullname);
LEAVE("window %p", window);
return window;
}
/* Add accelerators (if wanted) */
if (add_accelerators)
gtk_window_add_accel_group (GTK_WINDOW(enclosing_win),
gtk_ui_manager_get_accel_group(window->ui_merge));
gtk_ui_manager_ensure_update (window->ui_merge);
g_free(ui_fullname);
LEAVE("window %p", window);
return window;
}
/** Retrieve the gtk window associated with an embedded window object.
* This function is called via a vector off a generic window
* interface.
*
* @param window_in A pointer to a generic window. */
static GtkWindow *
gnc_embedded_window_get_gtk_window (GncWindow *window_in)
{
GncEmbeddedWindow *window;
GncEmbeddedWindowPrivate *priv;
g_return_val_if_fail (GNC_IS_EMBEDDED_WINDOW (window_in), NULL);
window = GNC_EMBEDDED_WINDOW(window_in);
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
return GTK_WINDOW(priv->parent_window);
}
/** Retrieve the status bar associated with an embedded window object.
* This function is called via a vector off a generic window
* interface.
*
* @param window_in A pointer to a generic window. */
static GtkWidget *
gnc_embedded_window_get_statusbar (GncWindow *window_in)
{
GncEmbeddedWindowPrivate *priv;
GncEmbeddedWindow *window;
g_return_val_if_fail (GNC_IS_EMBEDDED_WINDOW (window_in), NULL);
window = GNC_EMBEDDED_WINDOW(window_in);
priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
return priv->statusbar;
}
/** Initialize the generic window interface for an embedded window.
*
* @param iface A pointer to the interface data structure to
* populate. */
static void
gnc_window_embedded_window_init (GncWindowIface *iface)
{
iface->get_gtk_window = gnc_embedded_window_get_gtk_window;
iface->get_statusbar = gnc_embedded_window_get_statusbar;
}
|