2008-04-20 00:16:27 +02:00
|
|
|
/*
|
2011-02-06 21:23:34 +01:00
|
|
|
WindowManager - Global UI Manager class
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
2011-02-06 21:23:34 +01:00
|
|
|
|
|
|
|
|
#include "gui/window-manager.hpp"
|
|
|
|
|
#include "gui/gtk-lumiera.hpp"
|
|
|
|
|
#include "gui/workspace/workspace-window.hpp"
|
2011-02-07 00:54:16 +01:00
|
|
|
#include "lib/searchpath.hpp"
|
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
|
|
|
|
using util::cStr;
|
2008-04-20 00:16:27 +02:00
|
|
|
|
2008-08-13 20:15:13 +02:00
|
|
|
using namespace Gtk;
|
|
|
|
|
using namespace Glib;
|
2009-01-31 19:12:04 +01:00
|
|
|
using namespace boost;
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace gui::workspace;
|
2008-08-13 20:15:13 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
namespace fsys = boost::filesystem;
|
|
|
|
|
|
|
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
namespace gui {
|
2008-10-10 11:56:07 +02:00
|
|
|
|
2008-11-18 23:06:31 +01:00
|
|
|
IconSize WindowManager::GiantIconSize = ICON_SIZE_INVALID;
|
|
|
|
|
IconSize WindowManager::MenuIconSize = ICON_SIZE_INVALID;
|
2008-04-20 00:16:27 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2009-01-31 20:30:58 +01:00
|
|
|
void
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::init (string const& iconPath, string const& resourcePath)
|
2008-08-13 20:15:13 +02:00
|
|
|
{
|
2011-02-07 00:54:16 +01:00
|
|
|
this->iconSearchPath_ = iconPath;
|
|
|
|
|
this->resourceSerachPath_ = resourcePath;
|
|
|
|
|
|
2008-11-18 23:06:31 +01:00
|
|
|
register_app_icon_sizes();
|
2008-08-13 20:15:13 +02:00
|
|
|
register_stock_items();
|
|
|
|
|
}
|
2008-06-19 00:57:47 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
WindowManager::setTheme (string const& stylesheetName)
|
|
|
|
|
{
|
|
|
|
|
gtk_rc_parse (cStr(lib::resolveModulePath (stylesheetName, resourceSerachPath_)));
|
|
|
|
|
gtk_rc_reset_styles (gtk_settings_get_default());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-31 19:12:04 +01:00
|
|
|
void
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::newWindow (gui::model::Project& source_project,
|
|
|
|
|
gui::controller::Controller &source_controller)
|
2009-01-31 19:12:04 +01:00
|
|
|
{
|
|
|
|
|
shared_ptr<WorkspaceWindow> window(
|
|
|
|
|
new WorkspaceWindow(source_project, source_controller));
|
|
|
|
|
REQUIRE(window);
|
|
|
|
|
|
|
|
|
|
window->signal_delete_event().connect(sigc::mem_fun(
|
|
|
|
|
this, &WindowManager::on_window_closed));
|
|
|
|
|
|
|
|
|
|
windowList.push_back(window);
|
|
|
|
|
|
|
|
|
|
window->show();
|
2010-12-06 13:40:32 +01:00
|
|
|
|
|
|
|
|
update_close_window_in_menus();
|
2009-01-31 19:12:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::on_window_closed (GdkEventAny* event)
|
2009-01-31 19:49:44 +01:00
|
|
|
{
|
|
|
|
|
REQUIRE(event);
|
|
|
|
|
REQUIRE(event->window);
|
|
|
|
|
|
2009-01-31 19:12:04 +01:00
|
|
|
list< shared_ptr<WorkspaceWindow> >::iterator iterator =
|
|
|
|
|
windowList.begin();
|
2009-01-31 19:49:44 +01:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
while (iterator != windowList.end())
|
2009-01-31 19:12:04 +01:00
|
|
|
{
|
2009-01-31 19:49:44 +01:00
|
|
|
shared_ptr<WorkspaceWindow> workspace_window(*iterator);
|
|
|
|
|
REQUIRE(workspace_window);
|
2009-01-31 19:12:04 +01:00
|
|
|
|
2010-12-25 21:29:53 +01:00
|
|
|
Glib::RefPtr<Gdk::Window> window = workspace_window->get_window();
|
2009-01-31 19:49:44 +01:00
|
|
|
REQUIRE(window);
|
|
|
|
|
if(window->gobj() == event->window)
|
2009-01-31 19:12:04 +01:00
|
|
|
{
|
|
|
|
|
// This window has been closed
|
|
|
|
|
iterator = windowList.erase(iterator);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
iterator++;
|
|
|
|
|
}
|
2008-06-19 00:57:47 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
if (windowList.empty())
|
2009-01-31 19:12:04 +01:00
|
|
|
{
|
|
|
|
|
// All windows have been closed - we should exit
|
|
|
|
|
Main *main = Main::instance();
|
|
|
|
|
REQUIRE(main);
|
|
|
|
|
main->quit();
|
|
|
|
|
}
|
2010-12-06 13:40:32 +01:00
|
|
|
|
|
|
|
|
update_close_window_in_menus();
|
2009-01-31 19:12:04 +01:00
|
|
|
|
|
|
|
|
// Unless this is false, the window won't close
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2010-12-06 13:40:32 +01:00
|
|
|
void
|
|
|
|
|
WindowManager::update_close_window_in_menus()
|
|
|
|
|
{
|
|
|
|
|
bool enable = windowList.size() > 1;
|
|
|
|
|
|
|
|
|
|
list< shared_ptr<WorkspaceWindow> >::iterator iterator =
|
|
|
|
|
windowList.begin();
|
|
|
|
|
|
|
|
|
|
while (iterator != windowList.end())
|
|
|
|
|
{
|
|
|
|
|
shared_ptr<WorkspaceWindow> workspace_window(*iterator);
|
|
|
|
|
REQUIRE(workspace_window);
|
|
|
|
|
|
|
|
|
|
workspace_window->set_close_window_sensitive(enable);
|
|
|
|
|
iterator++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2010-12-25 21:29:53 +01:00
|
|
|
Cairo::RefPtr<Cairo::SolidPattern>
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::read_style_colour_property (Gtk::Widget& widget,
|
|
|
|
|
const gchar *property_name,
|
|
|
|
|
guint16 red, guint16 green, guint16 blue)
|
2008-08-13 20:15:13 +02:00
|
|
|
{
|
2010-12-25 21:29:53 +01:00
|
|
|
REQUIRE (property_name);
|
2008-08-13 20:15:13 +02:00
|
|
|
|
2010-12-25 21:29:53 +01:00
|
|
|
// TODO: Can we get rid of the GdkColor completely here?
|
|
|
|
|
GdkColor *color;
|
|
|
|
|
gtk_widget_style_get(widget.gobj(), property_name, &color, NULL);
|
2008-08-13 20:15:13 +02:00
|
|
|
|
2010-12-25 21:29:53 +01:00
|
|
|
Cairo::RefPtr<Cairo::SolidPattern> pattern;
|
2008-08-13 20:15:13 +02:00
|
|
|
// Did the color load successfully?
|
2010-12-25 21:29:53 +01:00
|
|
|
if (color != NULL)
|
|
|
|
|
{
|
|
|
|
|
pattern = Cairo::SolidPattern::create_rgb ( (double)color->red / 0xFFFF,
|
|
|
|
|
(double)color->green / 0xFFFF,
|
|
|
|
|
(double)color->blue / 0xFFFF);
|
|
|
|
|
}
|
2008-08-13 20:15:13 +02:00
|
|
|
else
|
2010-12-25 21:29:53 +01:00
|
|
|
{
|
|
|
|
|
WARN(gui, "%s style value failed to load", property_name);
|
|
|
|
|
|
|
|
|
|
pattern = Cairo::SolidPattern::create_rgb ( red, green, blue );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pattern;
|
2008-08-13 20:15:13 +02:00
|
|
|
}
|
2008-06-19 00:57:47 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2008-10-10 11:56:07 +02:00
|
|
|
void
|
2008-11-18 23:06:31 +01:00
|
|
|
WindowManager::register_app_icon_sizes()
|
2008-10-10 11:56:07 +02:00
|
|
|
{
|
2008-11-18 23:06:31 +01:00
|
|
|
if(GiantIconSize == ICON_SIZE_INVALID)
|
|
|
|
|
GiantIconSize = IconSize::register_new ("giant", 48, 48);
|
|
|
|
|
if(MenuIconSize == ICON_SIZE_INVALID)
|
|
|
|
|
MenuIconSize = IconSize::register_new ("menu", 16, 16);
|
2008-10-10 11:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2008-08-13 20:15:13 +02:00
|
|
|
void
|
|
|
|
|
WindowManager::register_stock_items()
|
|
|
|
|
{
|
2010-12-25 21:29:53 +01:00
|
|
|
Glib::RefPtr<IconFactory> factory = IconFactory::create();
|
2008-08-13 20:15:13 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
add_stock_icon_set(factory, "panel-assets", "panel_assets", _("_Assets"));
|
|
|
|
|
add_stock_icon_set(factory, "panel-timeline", "panel_timeline",_("_Timeline"));
|
|
|
|
|
add_stock_icon_set(factory, "panel-viewer", "panel_viewer", _("_Viewer"));
|
2008-08-13 20:15:13 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
add_stock_icon_set(factory, "window-new", "new_window", _("New _Window"));
|
2009-01-31 17:31:15 +01:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
add_stock_icon_set(factory, "tool-arrow", "tool_arrow", _("_Arrow"));
|
|
|
|
|
add_stock_icon_set(factory, "tool-i-beam", "tool_i_beam", _("_I-Beam"));
|
2008-10-23 00:11:23 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
add_stock_icon_set(factory, "track-disabled", "track_disabled",_("Track Disabled"));
|
|
|
|
|
add_stock_icon_set(factory, "track-enabled", "track_enabled", _("Track Enabled"));
|
|
|
|
|
add_stock_icon_set(factory, "track-locked", "track_locked", _("Track Locked"));
|
|
|
|
|
add_stock_icon_set(factory, "track-unlocked", "track_unlocked",_("Track Unlocked"));
|
2008-08-13 20:15:13 +02:00
|
|
|
|
|
|
|
|
factory->add_default(); //Add factory to list of factories.
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2008-08-13 20:15:13 +02:00
|
|
|
bool
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::add_stock_icon_set (Glib::RefPtr<IconFactory> const& factory,
|
|
|
|
|
cuString& icon_name,
|
|
|
|
|
cuString& id,
|
|
|
|
|
cuString& label)
|
2008-08-13 20:15:13 +02:00
|
|
|
{
|
|
|
|
|
Gtk::IconSet icon_set;
|
|
|
|
|
|
2008-10-10 11:56:07 +02:00
|
|
|
// Load all the sizes, wildcarding the first, largest icon to be
|
|
|
|
|
// loaded
|
|
|
|
|
bool no_icons = true;
|
|
|
|
|
no_icons &= !add_stock_icon(
|
2008-11-18 23:06:31 +01:00
|
|
|
icon_set, icon_name, GiantIconSize, no_icons);
|
2008-10-10 11:56:07 +02:00
|
|
|
no_icons &= !add_stock_icon(
|
|
|
|
|
icon_set, icon_name, ICON_SIZE_BUTTON, no_icons);
|
|
|
|
|
no_icons &= !add_stock_icon(
|
|
|
|
|
icon_set, icon_name, ICON_SIZE_MENU, no_icons);
|
|
|
|
|
no_icons &= !add_stock_icon(
|
|
|
|
|
icon_set, icon_name, ICON_SIZE_LARGE_TOOLBAR, no_icons);
|
|
|
|
|
no_icons &= !add_stock_icon(
|
2008-11-18 23:06:31 +01:00
|
|
|
icon_set, icon_name, MenuIconSize, no_icons);
|
2008-10-10 11:56:07 +02:00
|
|
|
|
|
|
|
|
if(no_icons)
|
2008-04-20 00:16:27 +02:00
|
|
|
{
|
2008-10-10 11:56:07 +02:00
|
|
|
// No icons were loaded
|
2011-02-07 00:54:16 +01:00
|
|
|
ERROR (gui, "Unable to load icon '%s'", cStr(icon_name));
|
2008-10-10 11:56:07 +02:00
|
|
|
return false;
|
2008-08-13 20:15:13 +02:00
|
|
|
}
|
2008-10-10 11:56:07 +02:00
|
|
|
|
|
|
|
|
// Add the icon set to the icon factory
|
|
|
|
|
const Gtk::StockID stock_id(id);
|
|
|
|
|
factory->add(stock_id, icon_set);
|
|
|
|
|
Gtk::Stock::add(Gtk::StockItem(stock_id, label));
|
|
|
|
|
return true;
|
2008-08-13 20:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2008-08-13 20:15:13 +02:00
|
|
|
bool
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::add_stock_icon (Gtk::IconSet &icon_set,
|
|
|
|
|
cuString& icon_name,
|
|
|
|
|
Gtk::IconSize size,
|
|
|
|
|
bool wildcard)
|
2009-01-31 17:31:15 +01:00
|
|
|
{
|
|
|
|
|
// Try the icon theme
|
|
|
|
|
if(add_theme_icon_source(icon_set, icon_name, size, wildcard))
|
|
|
|
|
return true;
|
2008-08-13 20:15:13 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
// Try to resolve the icon via the configured search path
|
|
|
|
|
lib::SearchPathSplitter iconLocations (iconSearchPath_);
|
|
|
|
|
while (iconLocations)
|
|
|
|
|
if (add_non_theme_icon_source (icon_set
|
|
|
|
|
,iconLocations.next()
|
|
|
|
|
,icon_name
|
|
|
|
|
,size
|
|
|
|
|
,wildcard))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false; // icon not found
|
2008-08-13 20:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2008-08-13 20:15:13 +02:00
|
|
|
bool
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::add_theme_icon_source (Gtk::IconSet &icon_set,
|
|
|
|
|
cuString& icon_name,
|
|
|
|
|
Gtk::IconSize size,
|
|
|
|
|
bool wildcard)
|
2009-01-31 17:31:15 +01:00
|
|
|
{
|
|
|
|
|
// Get the size
|
|
|
|
|
int width = 0, height = 0;
|
|
|
|
|
if(!IconSize::lookup(size, width, height))
|
|
|
|
|
return false;
|
|
|
|
|
REQUIRE(width > 0);
|
|
|
|
|
|
|
|
|
|
// Try to load the icon
|
2010-12-25 21:29:53 +01:00
|
|
|
Glib::RefPtr<Gtk::IconTheme> theme = Gtk::IconTheme::get_default();
|
2009-01-31 17:31:15 +01:00
|
|
|
REQUIRE(theme);
|
2009-02-01 19:56:49 +01:00
|
|
|
|
|
|
|
|
TODO ("find out how IconInfo could be made const. For example, GTKmm 2.10.10 is missing the const on operator bool() in iconinfo.h");
|
2011-02-07 00:54:16 +01:00
|
|
|
IconInfo info = theme->lookup_icon(icon_name, width, (IconLookupFlags)0);
|
|
|
|
|
|
|
|
|
|
if (!info) return false; // unable to resolve Icon
|
|
|
|
|
|
|
|
|
|
cuString path(info.get_filename());
|
|
|
|
|
return add_stock_icon_from_path(path, icon_set, size, wildcard);
|
2009-01-31 17:31:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2009-01-31 17:31:15 +01:00
|
|
|
bool
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::add_non_theme_icon_source (Gtk::IconSet &icon_set,
|
|
|
|
|
cuString& base_dir, cuString& icon_name,
|
|
|
|
|
Gtk::IconSize size, bool wildcard)
|
2008-08-13 20:15:13 +02:00
|
|
|
{
|
2009-01-31 17:31:15 +01:00
|
|
|
// Get the size
|
2008-10-08 00:02:27 +02:00
|
|
|
int width = 0, height = 0;
|
|
|
|
|
if(!IconSize::lookup(size, width, height))
|
|
|
|
|
return false;
|
2009-01-31 17:31:15 +01:00
|
|
|
REQUIRE(width > 0);
|
|
|
|
|
|
|
|
|
|
// Try to load the icon
|
2011-02-07 00:54:16 +01:00
|
|
|
cuString path(ustring::compose("%1/%2x%3/%4.png",
|
2009-01-31 17:31:15 +01:00
|
|
|
base_dir, width, height, icon_name));
|
|
|
|
|
return add_stock_icon_from_path(path, icon_set, size, wildcard);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2009-01-31 17:31:15 +01:00
|
|
|
bool
|
2011-02-07 00:54:16 +01:00
|
|
|
WindowManager::add_stock_icon_from_path (string path,
|
|
|
|
|
Gtk::IconSet &icon_set,
|
|
|
|
|
Gtk::IconSize size,
|
|
|
|
|
bool wildcard)
|
2009-01-31 17:31:15 +01:00
|
|
|
{
|
2011-02-07 00:54:16 +01:00
|
|
|
if (!fsys::exists (path)) return false;
|
2008-10-08 00:02:27 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
try {
|
|
|
|
|
Gtk::IconSource source;
|
2008-08-13 20:15:13 +02:00
|
|
|
source.set_pixbuf(Gdk::Pixbuf::create_from_file(path));
|
2011-02-07 00:54:16 +01:00
|
|
|
source.set_size_wildcarded(wildcard);
|
|
|
|
|
source.set_size(size);
|
|
|
|
|
|
|
|
|
|
icon_set.add_source(source);
|
|
|
|
|
|
|
|
|
|
return true;
|
2008-04-20 00:16:27 +02:00
|
|
|
}
|
2011-02-07 00:54:16 +01:00
|
|
|
|
|
|
|
|
catch(Glib::Exception const& ex)
|
2008-08-13 20:15:13 +02:00
|
|
|
{
|
2011-02-07 00:54:16 +01:00
|
|
|
WARN (gui, "Failure when accessing icon '%s'. Problem: %s", cStr(path), cStr(ex.what()));
|
2008-08-13 20:15:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-20 00:16:27 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
} // namespace gui
|