diff options
author | David Robillard <d@drobilla.net> | 2007-10-26 03:13:49 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-10-26 03:13:49 +0000 |
commit | 9e8425f0d5f9e2d8a7db45a29a3bb93b824a11c4 (patch) | |
tree | e1b356a54fb54d7258eae8662825aa9098bc95ea /src/libs/gui/App.cpp | |
parent | 203d851e116d4590897eceab582f735fb30c4e26 (diff) | |
download | ingen-9e8425f0d5f9e2d8a7db45a29a3bb93b824a11c4.tar.gz ingen-9e8425f0d5f9e2d8a7db45a29a3bb93b824a11c4.tar.bz2 ingen-9e8425f0d5f9e2d8a7db45a29a3bb93b824a11c4.zip |
Apply module icons patch from larsl (with formatting/visual tweaks).
git-svn-id: http://svn.drobilla.net/lad/ingen@901 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/gui/App.cpp')
-rw-r--r-- | src/libs/gui/App.cpp | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/libs/gui/App.cpp b/src/libs/gui/App.cpp index 997ae791..78f9e6e8 100644 --- a/src/libs/gui/App.cpp +++ b/src/libs/gui/App.cpp @@ -356,24 +356,49 @@ App::quit() Glib::RefPtr<Gdk::Pixbuf> -App::icon_from_path(const string& path) +App::icon_from_path(const string& path, int size) { - map<string, Glib::RefPtr<Gdk::Pixbuf> >::iterator iter = _icons.find(path); + /* If weak references to Glib::Objects are needed somewhere else it will + probably be a good idea to create a proper WeakPtr class instead of + using raw pointers, but for a single use this will do. */ - if (iter != _icons.end()) - return iter->second; + IconMap::iterator iter = _icons.find(make_pair(path, size)); + + if (iter != _icons.end()) { + // we need to reference manually since the RefPtr constructor doesn't do it + iter->second->reference(); + return Glib::RefPtr<Gdk::Pixbuf>(iter->second); + } Glib::RefPtr<Gdk::Pixbuf> buf; try { - buf = Gdk::Pixbuf::create_from_file(path, 20, 20); - _icons.insert(make_pair(path, buf)); + buf = Gdk::Pixbuf::create_from_file(path, size, size); + _icons.insert(make_pair(make_pair(path, size), buf.operator->())); + buf->add_destroy_notify_callback(new pair<string, int>(path, size), + &App::icon_destroyed); + cerr << "Loaded icon " << path << " with size " << size << endl; } catch (...) { - buf = Glib::RefPtr<Gdk::Pixbuf>(0); + cerr << "Caught exception, failed to load icon " << path << endl; } return buf; } +void* +App::icon_destroyed(void* data) +{ + pair<string, int>* p = static_cast<pair<string, int>*>(data); + cerr << "Destroyed icon " << p->first << " with size " << p->second << endl; + IconMap::iterator iter = instance()._icons.find(*p); + if (iter != instance()._icons.end()) + instance()._icons.erase(iter); + + delete p; // allocated in App::icon_from_path + + return NULL; +} + + } // namespace GUI } // namespace Ingen |