Gui: WindowManager and GtkLumiera refactoring

- split off the tricky basic GTKmm includes
- reduce the clutter in the gtk-lumiera.header
- make GtkLumiera a singleton, placed into static memory
- remove all static functions from WindowManager
This commit is contained in:
Fischlurch 2011-02-06 21:23:34 +01:00
parent 29e67e828d
commit 421a81b25b
12 changed files with 252 additions and 194 deletions

104
src/gui/gtk-base.hpp Normal file
View file

@ -0,0 +1,104 @@
/*
GTK-BASE.hpp - GTK includes and basic definitions
Copyright (C) Lumiera.org
2011, Hermann Vosseler <Ichthyostega@web.de>
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file gtk-base.hpp
** A set of basic GTK includes.
** There are some tricky point to consider when including the
** basic GTKmm headers. Especially, GTK tries to shadow the ERROR macro
** from Microsoft Windows. Unfortunately this breaks the ERROR macro from NoBug;
** thus we need to include NoBug \em after GTK
**
** Besides, this header defines the basic NLS. Most parts of the GUI rely either
** directly on this header, or through the inclusion of gtk-lumiera.hpp
**
** @see GtkLumiera
*/
#ifndef GUI_GTK_BASE_H
#define GUI_GTK_BASE_H
//--------------------tricky special Include sequence
#include <locale>
#include <gtkmm.h>
#include <nobug.h>
//--------------------tricky special Include sequence
#include "lib/error.hpp"
#include "lib/util.hpp"
#include "lib/lumitime.hpp"
#ifdef ENABLE_NLS
# include <libintl.h>
# define _(String) gettext (String)
# define gettext_noop(String) String
# define N_(String) gettext_noop (String)
#else
# define _(String) (String)
# define N_(String) String
# define textdomain(Domain)
# define bindtextdomain(Package, Directory)
#endif
/* ======= Namespace Definitions ======= */
/** Lumiera GTK GUI implementation root. */
namespace gui {
/** Dialog box classes. */
namespace dialogs {}
/** The Lumiera GTK-GUI uses a thin proxy layer data model
* on top of the actual "high-level-model", which lives in the
* Proc-Layer below. GUI operations interact with these proxy model
* entities, which in turn forward the calls to the actual objects
* in the Proc-Layer, through the Command system (which enables UNDO).
*
* @todo: as of 1/2011 this connection between the GUI proxy model and
* the Proc-Layer model needs to be set up. Currently, the GUI model
* entities are just created standalone and thus dysfunctional.
*/
namespace model {}
/** The namespace of all video output implementations. */
namespace output {}
/** Docking panel classes. */
namespace panels {}
/** Lumiera custom widgets. */
namespace widgets {}
/** The workspace window and it's helper classes. */
namespace workspace {}
/** GUI helpers, utility functions and classes. */
namespace util {}
}// namespace gui
#endif

View file

@ -1,5 +1,5 @@
/*
gtk-lumiera.cpp - The entry point for the GTK GUI application
GtkLumiera - The Lumiera GUI Application Object
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
@ -20,24 +20,14 @@
* *****************************************************/
#include <gtkmm.h>
#include <nobug.h>
#ifdef ENABLE_NLS
# include <libintl.h>
#endif
#include "gui/gtk-lumiera.hpp"
#include "gui/window-manager.hpp"
#include "gui/workspace/workspace-window.hpp"
#include "gui/controller/controller.hpp"
#include "gui/model/project.hpp"
#include "lib/singleton.hpp"
#include "gtk-lumiera.hpp"
#include "window-manager.hpp"
#include "workspace/workspace-window.hpp"
#include "model/project.hpp"
#include "controller/controller.hpp"
extern "C" {
#include "common/interface.h"
}
NOBUG_CPP_DEFINE_FLAG(gui);
using namespace Gtk;
using namespace Glib;
@ -47,36 +37,47 @@ using namespace gui::model;
using namespace gui::controller;
using namespace std;
GtkLumiera the_application;
namespace gui {
namespace {
/** storage for the Main Application object */
lib::Singleton<GtkLumiera> theApplicationInstance;
}
GtkLumiera&
GtkLumiera::application()
{
return theApplicationInstance();
}
void
GtkLumiera::main(int argc, char *argv[])
GtkLumiera::main (int argc, char *argv[])
{
Glib::thread_init();
Main kit(argc, argv);
Glib::set_application_name(get_app_title());
Glib::set_application_name (get_app_title());
Project project;
Controller controller(project);
windowManager.init();
windowManager.set_theme("lumiera_ui.rc");
windowManager.new_window(project, controller);
windowManagerInstance_.init();
windowManagerInstance_.set_theme ("lumiera_ui.rc");
windowManagerInstance_.new_window (project, controller);
kit.run();
}
WindowManager&
GtkLumiera::get_window_manager()
GtkLumiera::windowManager()
{
return windowManager;
return windowManagerInstance_;
}
Glib::ustring
@ -125,10 +126,5 @@ GtkLumiera::get_app_authors()
return list;
}
GtkLumiera&
application()
{
return the_application;
}
} // namespace gui

View file

@ -1,5 +1,5 @@
/*
gtk-lumiera.hpp - Application wide global definitions
GTK-LUMIERA.hpp - The Lumiera GUI Application Object
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
@ -25,137 +25,58 @@
** @see gtk-lumiera.cpp
*/
#ifndef GTK_LUMIERA_HPP
#define GTK_LUMIERA_HPP
#ifndef GUI_GTK_LUMIERA_H
#define GUI_GTK_LUMIERA_H
#include <locale>
#include <gtkmm.h>
#include <nobug.h> // need to include this after gtkmm.h, because types.h from GTK tries to shaddow the ERROR macro from windows, which kills NoBug's ERROR macro
#include "gui/gtk-base.hpp"
#include "gui/window-manager.hpp"
#include <boost/noncopyable.hpp>
#include <vector>
#include <boost/utility.hpp>
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "lib/util.hpp"
#include "lib/lumitime.hpp"
#include "window-manager.hpp"
extern "C" {
#include <gavl/gavltime.h>
}
//NOBUG_DECLARE_FLAG(gui);
#ifdef ENABLE_NLS
# include <libintl.h>
# define _(String) gettext (String)
# define gettext_noop(String) String
# define N_(String) gettext_noop (String)
#else
# define _(String) (String)
# define N_(String) String
# define textdomain(Domain)
# define bindtextdomain(Package, Directory)
#endif
/**
* Lumiera GTK GUI implementation root.
*/
namespace gui {
/* ===== The Application Class ===== */
/* ====== The Application Class ====== */
/**
* The main application class.
*/
class GtkLumiera : private boost::noncopyable
{
public:
void main(int argc, char *argv[]);
WindowManager& get_window_manager();
static Glib::ustring get_home_data_path();
/**
* Returns the name of the application
*/
static const Glib::ustring get_app_title();
/**
* Returns the version number of the application
*/
static const Glib::ustring get_app_version();
/**
* Returns the copyright of the application
*/
static const Glib::ustring get_app_copyright();
/**
* Returns the website of the application
*/
static const Glib::ustring get_app_website();
/**
* Returns tn alphabetical list of the application's authors
*/
static const std::vector<Glib::ustring> get_app_authors();
protected:
/**
* The application window manager object
*/
WindowManager windowManager;
};
/**
* Returns a reference to the global application object
*/
GtkLumiera& application();
/* ===== Namespace Definitions ===== */
/**
* The namespace of all dialog box classes.
*/
namespace dialogs {}
/**
* The namespace of data model classes.
*/
namespace model {}
/**
* The namespace of all video output implementations.
*/
namespace output {}
/**
* The namespace of all docking panel classes.
*/
namespace panels {}
/**
* The namespace of all Lumiera custom widgets.
*/
namespace widgets {}
/**
* The namespace of the workspace window, and it's helper classes.
*/
namespace workspace {}
/**
* The namespace of utility functions and classes.
*/
namespace util {}
} // namespace gui
#endif // GTK_LUMIERA_HPP
class GtkLumiera
: boost::noncopyable
{
/** Central application window manager instance */
WindowManager windowManagerInstance_;
public:
/** access the the global application object */
static GtkLumiera& application();
void main(int argc, char *argv[]);
WindowManager& windowManager();
static Glib::ustring get_home_data_path();
/** the name of the application */
static const Glib::ustring get_app_title();
static const Glib::ustring get_app_version();
static const Glib::ustring get_app_copyright();
static const Glib::ustring get_app_website();
/** alphabetical list of the application's authors */
static const std::vector<Glib::ustring> get_app_authors();
};
}// namespace gui
#endif

View file

@ -110,7 +110,8 @@ namespace gui {
int argc =0;
char *argv[] = {}; // dummy command line for GTK
gui::application().main(argc, argv); // execute the GTK Event Loop
// execute the GTK Event Loop____________
GtkLumiera::application().main(argc, argv);
if (!lumiera_error_peek())
return; // all went well, normal shutdown

View file

@ -25,11 +25,15 @@
** are also track parents. This class wraps proc layer data
*/
#ifndef PARENT_TRACK_HPP
#define PARENT_TRACK_HPP
#include "track.hpp"
#include "lib/observable-list.hpp"
#ifndef PARENT_TRACK_HPP
#define PARENT_TRACK_HPP
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
namespace gui {
namespace model {

View file

@ -19,10 +19,13 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file timeline-panel.hpp
** This file contains the definition of the timeline panel
*/
#ifndef TIMELINE_PANEL_HPP
#define TIMELINE_PANEL_HPP
@ -30,8 +33,12 @@
#include "gui/widgets/timecode-widget.hpp"
#include "gui/widgets/timeline-widget.hpp"
#include <boost/scoped_ptr.hpp>
#include <boost/weak_ptr.hpp>
using namespace gui::widgets;
namespace gui {
namespace model {

View file

@ -29,6 +29,8 @@
#include "gui/gtk-lumiera.hpp"
#include "timeline-tool.hpp"
#include <boost/scoped_ptr.hpp>
namespace gui {
namespace model {

View file

@ -30,6 +30,8 @@
#include "gui/gtk-lumiera.hpp"
#include "lib/tree.hpp"
#include <boost/optional.hpp>
namespace gui {
namespace model {

View file

@ -19,21 +19,28 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file widgets/timeline/timeline-track.hpp
** This file contains the definition of timeline track object
*/
#ifndef TIMELINE_TRACK_HPP
#define TIMELINE_TRACK_HPP
#include "gui/gtk-lumiera.hpp"
#include "gui/model/track.hpp"
#include "gui/widgets/menu-button.hpp"
#include "gui/widgets/mini-button.hpp"
#include "gui/widgets/button-bar.hpp"
#include "timeline-clip.hpp"
#include "timeline-header-container.hpp"
#include "timeline-header-widget.hpp"
#include "gui/widgets/timeline/timeline-clip.hpp"
#include "gui/widgets/timeline/timeline-header-container.hpp"
#include "gui/widgets/timeline/timeline-header-widget.hpp"
#include <boost/scoped_ptr.hpp>
#ifndef TIMELINE_TRACK_HPP
#define TIMELINE_TRACK_HPP
namespace gui {
namespace widgets {

View file

@ -1,5 +1,5 @@
/*
window-manager.cpp - Defines the global UI Manager class
WindowManager - Global UI Manager class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
@ -20,9 +20,10 @@
* *****************************************************/
#include "window-manager.hpp"
#include "include/logging.h"
#include "workspace/workspace-window.hpp"
#include "gui/window-manager.hpp"
#include "gui/gtk-lumiera.hpp"
#include "gui/workspace/workspace-window.hpp"
using namespace Gtk;
using namespace Glib;

View file

@ -1,5 +1,5 @@
/*
window-manager.hpp - Defines the global UI Manager class
WINDOW-MANAGER.hpp - Global UI Manager class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
@ -19,20 +19,31 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file window-manager.hpp
** This file contains the defintion of global UI Manager class.
** @see window-manager.cpp
** Manager for all application windows and resources.
** This file defines the global UI Manager class. The central WindowManager
** instance is owned by the GtkLumiera object and initialised in GTK-main.
** The WindowManager has the ability to create new windows integrated with
** the application framework, to provide Icons and other resources and
** to set and access a general UI theme.
**
** @see gtk-lumiera.hpp
*/
#include <cairomm/cairomm.h>
#include "gtk-lumiera.hpp"
//#include "workspace/workspace-window.hpp"
#ifndef WINDOW_MANAGER_HPP
#define WINDOW_MANAGER_HPP
#include "gui/gtk-base.hpp"
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <cairomm/cairomm.h>
namespace gui {
namespace model {
@ -50,11 +61,13 @@ namespace workspace {
/**
* The centralised manager of all lumiera-gui's windows.
*/
class WindowManager : private boost::noncopyable
class WindowManager
: boost::noncopyable
{
public:
/**
* Initializes the window manager object
* Initialise the window manager on application start.
* Register the icon configuration and sizes.
*/
void init();
@ -104,17 +117,16 @@ private:
* otherwise.
*/
void update_close_window_in_menus();
/**
* Registers the custom icon sizes.
*/
static void register_app_icon_sizes();
/** Registers the custom icon sizes. */
void register_app_icon_sizes();
/**
* Registers application stock items: icons and
* labels associated with IDs
*/
static void register_stock_items();
void register_stock_items();
/**
* Adds an icon (in different sizes) to the icon factory.
@ -125,7 +137,7 @@ private:
* @return Returns true if the icon was successfully loaded, returns
* false otherwise.
*/
static bool add_stock_icon_set(
bool add_stock_icon_set(
const Glib::RefPtr<Gtk::IconFactory>& factory,
const Glib::ustring& icon_name,
const Glib::ustring& id,
@ -141,7 +153,7 @@ private:
* wildcarded.
* @return Returns true if the icon was loaded successfully.
*/
static bool add_stock_icon(Gtk::IconSet &icon_set,
bool add_stock_icon(Gtk::IconSet &icon_set,
const Glib::ustring& icon_name, Gtk::IconSize size, bool wildcard);
/**
@ -153,7 +165,7 @@ private:
* wildcarded.
* @return Returns true if the icon was loaded successfully.
*/
static bool add_theme_icon_source(Gtk::IconSet &icon_set,
bool add_theme_icon_source(Gtk::IconSet &icon_set,
const Glib::ustring& icon_name, Gtk::IconSize size, bool wildcard);
/**
@ -166,7 +178,7 @@ private:
* wildcarded.
* @return Returns true if the icon was loaded successfully.
*/
static bool add_non_theme_icon_source(Gtk::IconSet &icon_set,
bool add_non_theme_icon_source(Gtk::IconSet &icon_set,
const Glib::ustring& base_dir, const Glib::ustring& icon_name,
Gtk::IconSize size, bool wildcard);
@ -179,7 +191,7 @@ private:
* wildcarded.
* @return Returns true if the icon was loaded successfully.
*/
static bool add_stock_icon_from_path(Glib::ustring path,
bool add_stock_icon_from_path(Glib::ustring path,
Gtk::IconSet &icon_set, Gtk::IconSize size, bool wildcard);
private:
@ -203,6 +215,7 @@ public:
static Gtk::IconSize MenuIconSize;
};
} // namespace gui
#endif // WINDOW_MANAGER_HPP
}// namespace gui
#endif

View file

@ -334,7 +334,7 @@ Actions::on_menu_track_add()
void
Actions::on_menu_window_new_window()
{
application().get_window_manager().new_window(
GtkLumiera::application().windowManager().new_window(
workspaceWindow.get_project(),
workspaceWindow.get_controller());
}