00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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