news download themes documentation links










ButtonTool.cc

00001 // ButtonTool.cc for Fluxbox
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: ButtonTool.cc,v 1.3 2004/01/13 14:41:32 rathnor Exp $
00023 
00024 #include "ButtonTool.hh"
00025 
00026 #include "FbTk/Button.hh"
00027 #include "FbTk/ImageControl.hh"
00028 #include "ButtonTheme.hh"
00029 
00030 ButtonTool::ButtonTool(FbTk::Button *button, 
00031                        ToolbarItem::Type type, 
00032                        ButtonTheme &theme,
00033                        FbTk::ImageControl &img_ctrl):
00034     GenericTool(button, type, theme),
00035     m_cache_pm(0),
00036     m_cache_pressed_pm(0),
00037     m_image_ctrl(img_ctrl) {
00038 
00039     renderTheme();
00040 }
00041 
00042 ButtonTool::~ButtonTool() {
00043     if (m_cache_pm)
00044         m_image_ctrl.removeImage(m_cache_pm);
00045 
00046     if (m_cache_pressed_pm)
00047         m_image_ctrl.removeImage(m_cache_pressed_pm);
00048 
00049 }
00050 
00051 void ButtonTool::renderTheme() {
00052     FbTk::Button &btn = static_cast<FbTk::Button &>(window());
00053 
00054     btn.setGC(static_cast<const ButtonTheme &>(theme()).gc());
00055     btn.setBorderColor(theme().border().color());
00056     btn.setBorderWidth(theme().border().width());
00057     btn.setAlpha(theme().alpha());
00058 
00059     Pixmap old_pm = m_cache_pm;
00060     if (!theme().texture().usePixmap()) {
00061         m_cache_pm = 0;
00062         btn.setBackgroundColor(theme().texture().color());
00063     } else {
00064         m_cache_pm = m_image_ctrl.renderImage(width(), height(),
00065                                               theme().texture());
00066         btn.setBackgroundPixmap(m_cache_pm);
00067     }
00068     if (old_pm)
00069         m_image_ctrl.removeImage(old_pm);
00070 
00071     old_pm = m_cache_pressed_pm;
00072     if (! static_cast<const ButtonTheme &>(theme()).pressed().usePixmap()) {
00073         m_cache_pressed_pm = 0;
00074         btn.setPressedColor(static_cast<const ButtonTheme &>(theme()).pressed().color());
00075     } else {
00076         m_cache_pressed_pm = m_image_ctrl.renderImage(width(), height(),
00077                                                       static_cast<const ButtonTheme &>(theme()).pressed());
00078         btn.setPressedPixmap(m_cache_pressed_pm);
00079     }
00080 
00081     if (old_pm)
00082         m_image_ctrl.removeImage(old_pm);
00083 
00084     btn.clear();
00085     btn.updateTransparent();
00086 }
00087 

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