aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Image.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Image.cc')
-rw-r--r--src/FbTk/Image.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/FbTk/Image.cc b/src/FbTk/Image.cc
new file mode 100644
index 0000000..e4ab6ac
--- /dev/null
+++ b/src/FbTk/Image.cc
@@ -0,0 +1,120 @@
1// Image.cc for FbTk - Fluxbox ToolKit
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
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:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
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.
21
22// $Id: Image.cc,v 1.1 2003/08/22 21:25:14 fluxgen Exp $
23
24#include "Image.hh"
25#include "StringUtil.hh"
26
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif // HAVE_CONFIG_H
30
31#ifdef HAVE_XPM
32#include "ImageXPM.hh"
33#endif /// HAVE_XPM
34
35#include <list>
36#include <iostream>
37using namespace std;
38
39namespace FbTk {
40
41Image::ImageMap Image::s_image_map;
42Image::StringList Image::s_search_paths;
43
44PixmapWithMask *Image::load(const std::string &filename, int screen_num) {
45
46#ifdef HAVE_XPM
47 // we must do this because static linkage with libFbTk will not init
48 // a static autoreg variable for it
49 static ImageXPM xpm;
50#endif // HAVE_XPM
51
52 if (filename == "")
53 return false;
54
55 // determine file ending
56 std::string extension(StringUtil::toUpper(StringUtil::findExtension(filename)));
57
58 // valid handle?
59 if (s_image_map[extension] == 0)
60 return false;
61
62 // load file
63 PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num);
64 // failed?, try different search paths
65 if (pm == 0 && s_search_paths.size()) {
66 // first we need to get basename of current filename
67 std::string base_filename = StringUtil::basename(filename);
68 // append each search path and try to load
69 StringList::iterator it = s_search_paths.begin();
70 StringList::iterator it_end = s_search_paths.end();
71 for (; it != it_end && pm == 0; ++it) {
72 // append search path and try load it
73 std::string path = StringUtil::expandFilename(*it);
74 pm = s_image_map[extension]->load(path + "/" + base_filename, screen_num);
75 }
76 }
77
78 return pm;
79}
80
81bool Image::registerType(const std::string &type, ImageBase &base) {
82
83 string ucase_type = StringUtil::toUpper(type);
84
85 // not empty and not this base?
86 if (s_image_map[ucase_type] != 0 &&
87 s_image_map[ucase_type] != &base)
88 return false;
89 // already registered?
90 if (s_image_map[ucase_type] = &base)
91 return true;
92
93 s_image_map[ucase_type] = &base;
94}
95
96void Image::remove(ImageBase &base) {
97 // find and remove all referenses to base
98 ImageMap::iterator it = s_image_map.begin();
99 ImageMap::iterator it_end = s_image_map.end();
100 std::list<std::string> remove_list;
101 for (; it != it_end; ++it) {
102 if (it->second == &base)
103 remove_list.push_back(it->first);
104 }
105
106 while (!remove_list.empty()) {
107 s_image_map.erase(remove_list.back());
108 remove_list.pop_back();
109 }
110}
111
112void Image::addSearchPath(const std::string &search_path) {
113 s_search_paths.push_back(search_path);
114}
115
116void Image::removeAllSearchPaths() {
117 s_search_paths.clear();
118}
119
120}; // end namespace FbTk