/* * This file is part of RawTherapee. * * Copyright (c) 2004-2010 Gabor Horvath * Copyright (c) 2011 Jean-Christophe FRISCH * * RawTherapee 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 3 of the License, or * (at your option) any later version. * * RawTherapee 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 RawTherapee. If not, see . */ #include "rtimage.h" #include "../rtengine/safegtk.h" extern Glib::ustring argv0; extern Options options; std::vector imagesPaths; std::map > pixBufMap; // List of image buffers in order to live update them on theme switch and to avoid a lot of file accesses /* * RTImage is a derived class of Gtk::Image, in order to handle theme related iconsets */ RTImage::RTImage(Glib::ustring fileName, Glib::ustring rtlFileName) : Gtk::Image() { Glib::ustring mapKey; if (rtlFileName.length()) { if (get_direction() == Gtk::TEXT_DIR_RTL) { mapKey = rtlFileName; } else { mapKey = fileName; } } else { mapKey = fileName; } std::map >::iterator it; it = pixBufMap.find(mapKey); if (it != pixBufMap.end()) { set(it->second); } else { Glib::RefPtr tempPixPuf = Gdk::Pixbuf::create_from_file(findIconAbsolutePath(mapKey)); pixBufMap.insert(std::pair >(mapKey, tempPixPuf)); set(tempPixPuf); } } void RTImage::updateImages() { std::map >::iterator it; for (it=pixBufMap.begin(); it!=pixBufMap.end(); ++it) { Glib::ustring fullPath = findIconAbsolutePath(it->first); it->second = Gdk::Pixbuf::create_from_file(fullPath); } } // DONE (was TODO: Maybe this could be optimized: in order to avoid looking up for an icon file in the filesystem on each popupmenu selection, maybe we could find a way to copy the image data from another RTImage) void RTImage::changeImage(Glib::ustring &newImage) { clear(); std::map >::iterator it; it = pixBufMap.find(newImage); if (it != pixBufMap.end()) { set(it->second); } else { Glib::ustring fullPath = findIconAbsolutePath(newImage); Glib::RefPtr tempPixPuf = Gdk::Pixbuf::create_from_file(fullPath); pixBufMap.insert(std::pair >(newImage, tempPixPuf)); set(tempPixPuf); } } Glib::ustring RTImage::findIconAbsolutePath(const Glib::ustring &iconFName) { Glib::ustring path; for (unsigned int i=0; i