news download themes documentation links










Image.cc

00001 // Image.cc for FbTk - Fluxbox ToolKit
00002 // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
00003 //
00004 // Permission is hereby granted, free of charge, to any person obtaining a
00005 // copy of this software and associated documentation files (the "Software"),
00006 // to deal in the Software without restriction, including without limitation
00007 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 // and/or sell copies of the Software, and to permit persons to whom the
00009 // Software is furnished to do so, subject to the following conditions:
00010 //
00011 // The above copyright notice and this permission notice shall be included in
00012 // all copies or substantial portions of the Software.
00013 //
00014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00017 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020 // DEALINGS IN THE SOFTWARE.
00021 
00022 // $Id: Image.cc,v 1.4 2004/01/02 22:01:08 fluxgen Exp $
00023 
00024 #include "Image.hh"
00025 #include "StringUtil.hh"
00026 
00027 #ifdef HAVE_CONFIG_H
00028 #include "config.h"
00029 #endif // HAVE_CONFIG_H
00030 
00031 #ifdef HAVE_XPM
00032 #include "ImageXPM.hh"
00033 #endif 
00034 
00035 #include <list>
00036 #include <iostream>
00037 using namespace std;
00038 
00039 namespace FbTk {
00040 
00041 Image::ImageMap Image::s_image_map;
00042 Image::StringList Image::s_search_paths;
00043 
00044 PixmapWithMask *Image::load(const std::string &filename, int screen_num) {
00045 
00046 #ifdef HAVE_XPM
00047     // we must do this because static linkage with libFbTk will not init 
00048     // a static autoreg variable for it
00049     static ImageXPM xpm;
00050 #endif // HAVE_XPM
00051 
00052     if (filename == "")
00053         return false;
00054 
00055     // determine file ending
00056     std::string extension(StringUtil::toUpper(StringUtil::findExtension(filename)));
00057 
00058     // valid handle?
00059     if (s_image_map[extension] == 0)
00060         return false;
00061     
00062     // load file
00063     PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num);
00064     // failed?, try different search paths
00065     if (pm == 0 && s_search_paths.size()) {
00066         // first we need to get basename of current filename
00067         std::string base_filename = StringUtil::basename(filename);
00068         std::string path = "";
00069         // append each search path and try to load
00070         StringList::iterator it = s_search_paths.begin();
00071         StringList::iterator it_end = s_search_paths.end();
00072         for (; it != it_end && pm == 0; ++it) {
00073             // append search path and try load it
00074             path = StringUtil::expandFilename(*it);
00075             pm = s_image_map[extension]->load(path + "/" + base_filename, screen_num);
00076         }
00077 
00078     }
00079 
00080     return pm;
00081 }
00082 
00083 bool Image::registerType(const std::string &type, ImageBase &base) {
00084 
00085     string ucase_type = StringUtil::toUpper(type);
00086 
00087     // not empty and not this base?
00088     if (s_image_map[ucase_type] != 0 &&
00089         s_image_map[ucase_type] != &base) 
00090         return false;
00091     // already registered?
00092     if (s_image_map[ucase_type] == &base)
00093         return true;
00094 
00095     s_image_map[ucase_type] = &base;
00096 
00097     return true;
00098 }
00099 
00100 void Image::remove(ImageBase &base) {
00101     // find and remove all referenses to base
00102     ImageMap::iterator it = s_image_map.begin();
00103     ImageMap::iterator it_end = s_image_map.end();
00104     std::list<std::string> remove_list;
00105     for (; it != it_end; ++it) {
00106         if (it->second == &base)
00107             remove_list.push_back(it->first);
00108     }
00109 
00110     while (!remove_list.empty()) {
00111         s_image_map.erase(remove_list.back());
00112         remove_list.pop_back();
00113     }
00114 }
00115 
00116 void Image::addSearchPath(const std::string &search_path) {
00117     s_search_paths.push_back(search_path);
00118 }
00119 
00120 void Image::removeSearchPath(const std::string &search_path) {
00121     s_search_paths.remove(search_path);
00122 }
00123 
00124 void Image::removeAllSearchPaths() {
00125     s_search_paths.clear();
00126 }
00127 
00128 }; // end namespace FbTk

Fluxbox CVS-Jan-2003




      



Got comments about the page? Send them to webmaster.
If you have general Fluxbox related questions ask them on our irc channel or mailing lists.

Show Source








Designed by aLEczapKA