From b15864870d34a1188eda93ad215734275037278e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 11 Sep 2006 11:10:35 +0000 Subject: Switched homebrew CountedPtr to boost::shared_ptr. Factories for patch windows, controller. Robustness updated in many places. Tons of cleanups, rewrites, bugfixes, etc. git-svn-id: http://svn.drobilla.net/lad/ingen@128 a436a847-0d15-0410-975c-d299462d15a1 --- src/progs/ingenuity/WindowFactory.cpp | 108 ++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/progs/ingenuity/WindowFactory.cpp (limited to 'src/progs/ingenuity/WindowFactory.cpp') diff --git a/src/progs/ingenuity/WindowFactory.cpp b/src/progs/ingenuity/WindowFactory.cpp new file mode 100644 index 00000000..6a913663 --- /dev/null +++ b/src/progs/ingenuity/WindowFactory.cpp @@ -0,0 +1,108 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen 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. + * + * Ingen 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 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., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "WindowFactory.h" +#include "PatchWindow.h" +#include "GladeFactory.h" +#include "App.h" + +namespace Ingenuity { + + +/** Present a PatchWindow for a Patch. + * + * If @a preferred is not NULL, it will be set to display @a patch if the patch + * does not already have a visible window, otherwise that window will be presented and + * @a preferred left unmodified. + */ +void +WindowFactory::present(CountedPtr patch, PatchWindow* preferred) +{ + std::map::iterator w = _windows.find(patch->model()->path()); + + if (w != _windows.end()) { + (*w).second->present(); + } else if (preferred) { + w = _windows.find(preferred->patch_controller()->model()->path()); + assert((*w).second == preferred); + + preferred->set_patch(patch); + _windows.erase(w); + _windows[patch->model()->path()] = preferred; + preferred->present(); + + } else { + PatchWindow* win = create_new(patch); + win->present(); + } +} + + +PatchWindow* +WindowFactory::create_new(CountedPtr patch) +{ + // FIXME: can't just load "patch_win" and children because PatchWindow + // loads things it really shouldn't. + //Glib::RefPtr xml = GladeFactory::new_glade_reference("patch_win"); + Glib::RefPtr xml = GladeFactory::new_glade_reference(); + + PatchWindow* win = NULL; + xml->get_widget_derived("patch_win", win); + assert(win); + + win->set_patch(patch); + _windows[patch->model()->path()] = win; + + win->signal_delete_event().connect(sigc::bind<0>( + sigc::mem_fun(this, &WindowFactory::remove), win)); + + cerr << "Created window - count: " << _windows.size() << endl; + + return win; +} + + +bool +WindowFactory::remove(PatchWindow* win, GdkEventAny* ignored) +{ + if (_windows.size() <= 1) { + Gtk::MessageDialog d(*win, "This is the last remaining open patch " + "window. Closing this window will exit Ingenuity (the engine will " + "remain running).\n\nAre you sure you want to quit?", + true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE, true); + d.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + d.add_button(Gtk::Stock::QUIT, Gtk::RESPONSE_CLOSE); + int ret = d.run(); + if (ret == Gtk::RESPONSE_CLOSE) + App::instance().quit(); + else + return false; + } + + std::map::iterator w + = _windows.find(win->patch_controller()->model()->path()); + + assert((*w).second == win); + _windows.erase(w); + + delete win; + + cerr << "Removed window " << win << "- count: " << _windows.size() << endl; + + return true; +} + +} // namespace Ingenuity -- cgit v1.2.1