1
// Image.cc for FbTk - Fluxbox ToolKit
2
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
// DEALINGS IN THE SOFTWARE.
22
// $Id: Image.cc 3864 2005-01-24 18:02:34Z mathias $
25
#include "StringUtil.hh"
29
#endif // HAVE_CONFIG_H
32
#include "ImageXPM.hh"
36
#include "ImageImlib2.hh"
46
Image::ImageMap Image::s_image_map;
47
Image::StringList Image::s_search_paths;
52
// create imagehandlers for their extensions
61
void Image::shutdown() {
63
std::set<ImageBase*> handlers;
65
// one imagehandler could be registered
66
// for more than one type
67
ImageMap::iterator it = s_image_map.begin();
68
ImageMap::iterator it_end = s_image_map.end();
69
for (; it != it_end; it++) {
71
handlers.insert(it->second);
74
// free the unique handlers
75
std::set<ImageBase*>::iterator handler_it = handlers.begin();
76
std::set<ImageBase*>::iterator handler_it_end = handlers.end();
77
for(; handler_it != handler_it_end; handler_it++) {
84
PixmapWithMask *Image::load(const std::string &filename, int screen_num) {
90
// determine file ending
91
std::string extension(StringUtil::toUpper(StringUtil::findExtension(filename)));
94
if (s_image_map.find(extension) == s_image_map.end())
98
PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num);
99
// failed?, try different search paths
100
if (pm == 0 && s_search_paths.size()) {
101
// first we need to get basename of current filename
102
std::string base_filename = StringUtil::basename(filename);
103
std::string path = "";
104
// append each search path and try to load
105
StringList::iterator it = s_search_paths.begin();
106
StringList::iterator it_end = s_search_paths.end();
107
for (; it != it_end && pm == 0; ++it) {
108
// append search path and try load it
109
path = StringUtil::expandFilename(*it);
110
pm = s_image_map[extension]->load(path + "/" + base_filename, screen_num);
118
bool Image::registerType(const std::string &type, ImageBase &base) {
120
string ucase_type = StringUtil::toUpper(type);
122
// not empty and not this base?
123
if (s_image_map[ucase_type] != 0 &&
124
s_image_map[ucase_type] != &base)
126
// already registered?
127
if (s_image_map[ucase_type] == &base)
130
s_image_map[ucase_type] = &base;
135
void Image::remove(ImageBase &base) {
136
// find and remove all referenses to base
137
ImageMap::iterator it = s_image_map.begin();
138
ImageMap::iterator it_end = s_image_map.end();
139
std::list<std::string> remove_list;
140
for (; it != it_end; ++it) {
141
if (it->second == &base)
142
remove_list.push_back(it->first);
145
while (!remove_list.empty()) {
146
s_image_map.erase(remove_list.back());
147
remove_list.pop_back();
151
void Image::addSearchPath(const std::string &search_path) {
152
s_search_paths.push_back(search_path);
155
void Image::removeSearchPath(const std::string &search_path) {
156
s_search_paths.remove(search_path);
159
void Image::removeAllSearchPaths() {
160
s_search_paths.clear();
163
}; // end namespace FbTk