From 0a01f73b51766fc5619c5e38424e4aa344b47583 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 15 Feb 2003 02:00:29 +0000 Subject: fixed indentation and added theme listener object --- src/Toolbar.cc | 142 ++++++++++++++++++++++++++++++--------------------------- src/Toolbar.hh | 18 ++++++-- 2 files changed, 90 insertions(+), 70 deletions(-) diff --git a/src/Toolbar.cc b/src/Toolbar.cc index b88abf2..856c8e6 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Toolbar.cc,v 1.55 2003/01/12 18:53:16 fluxgen Exp $ +// $Id: Toolbar.cc,v 1.56 2003/02/15 02:00:29 fluxgen Exp $ #include "Toolbar.hh" @@ -181,7 +181,11 @@ Toolbar::Toolbar(BScreen *scrn, size_t width): hide_timer(&hide_handler), m_toolbarmenu(*scrn->menuTheme(), scrn->getScreenNumber(), *scrn->getImageControl()), m_theme(scrn->getScreenNumber()), - m_place(BOTTOMCENTER) { + m_place(BOTTOMCENTER), + m_themelistener(*this) { + + // we need to get notified when the theme is reloaded + m_theme.addListener(m_themelistener); setupMenus(*this); @@ -412,7 +416,8 @@ void Toolbar::reconfigure() { frame.base = None; frame.window.setBackgroundColor(texture->color()); } else { - frame.base = image_ctrl.renderImage(frame.window.width(), frame.window.height(), *texture); + frame.base = image_ctrl.renderImage(frame.window.width(), + frame.window.height(), *texture); frame.window.setBackgroundPixmap(frame.base); } if (tmp) image_ctrl.removeImage(tmp); @@ -424,7 +429,8 @@ void Toolbar::reconfigure() { frame.window_label.setBackgroundColor(texture->color()); } else { frame.label = - image_ctrl.renderImage(frame.window_label.width(), frame.window_label.height(), *texture); + image_ctrl.renderImage(frame.window_label.width(), + frame.window_label.height(), *texture); frame.window_label.setBackgroundPixmap(frame.label); } if (tmp) image_ctrl.removeImage(tmp); @@ -562,75 +568,77 @@ void Toolbar::checkClock(bool redraw, bool date) { cerr<<__FILE__<<"("<<__LINE__<<"): time(null)<0"<getStrftimeFormat(), tt)) - return; + char t[1024]; + if (! strftime(t, 1024, screen()->getStrftimeFormat(), tt)) + return; #else // !HAVE_STRFTIME - char t[9]; - if (date) { - // format the date... with special consideration for y2k ;) - if (screen()->getDateFormat() == Blackbox::B_EuropeanDate) { - sprintf(t, - i18n->getMessage( - ToolbarSet, ToolbarNoStrftimeDateFormatEu, - "%02d.%02d.%02d"), - tt->tm_mday, tt->tm_mon + 1, - (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year); - } else { - sprintf(t, - i18n->getMessage( - ToolbarSet, ToolbarNoStrftimeDateFormat, - "%02d/%02d/%02d"), - tt->tm_mon + 1, tt->tm_mday, - (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year); - } + char t[9]; + if (date) { + // format the date... with special consideration for y2k ;) + if (screen()->getDateFormat() == Blackbox::B_EuropeanDate) { + sprintf(t, + i18n->getMessage( + ToolbarSet, ToolbarNoStrftimeDateFormatEu, + "%02d.%02d.%02d"), + tt->tm_mday, tt->tm_mon + 1, + (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year); } else { - if (screen()->isClock24Hour()) { - sprintf(t, - i18n->getMessage( - ToolbarSet, ToolbarNoStrftimeTimeFormat24, - " %02d:%02d "), - frame.hour, frame.minute); - } else { - sprintf(t, - i18n->getMessage( - ToolbarSet, ToolbarNoStrftimeTimeFormat12, - "%02d:%02d %sm"), - ((frame.hour > 12) ? frame.hour - 12 : - ((frame.hour == 0) ? 12 : frame.hour)), frame.minute, - ((frame.hour >= 12) ? - i18n->getMessage( - ToolbarSet, ToolbarNoStrftimeTimeFormatP, - "p") : - i18n->getMessage( - ToolbarSet, ToolbarNoStrftimeTimeFormatA, - "a"))); - } + sprintf(t, + i18n->getMessage( + ToolbarSet, ToolbarNoStrftimeDateFormat, + "%02d/%02d/%02d"), + tt->tm_mon + 1, tt->tm_mday, + (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year); + } + } else { + if (screen()->isClock24Hour()) { + sprintf(t, + i18n->getMessage( + ToolbarSet, ToolbarNoStrftimeTimeFormat24, + " %02d:%02d "), + frame.hour, frame.minute); + } else { + sprintf(t, + i18n->getMessage( + ToolbarSet, ToolbarNoStrftimeTimeFormat12, + "%02d:%02d %sm"), + ((frame.hour > 12) ? frame.hour - 12 : + ((frame.hour == 0) ? 12 : frame.hour)), frame.minute, + ((frame.hour >= 12) ? + i18n->getMessage( + ToolbarSet, ToolbarNoStrftimeTimeFormatP, + "p") : + i18n->getMessage( + ToolbarSet, ToolbarNoStrftimeTimeFormatA, + "a"))); } + } #endif // HAVE_STRFTIME - size_t newlen = strlen(t); - int dx = FbTk::doAlignment(frame.clock_w, - frame.bevel_w*2, - m_theme.justify(), - m_theme.font(), - t, strlen(t), newlen); - int dy = 1 + m_theme.font().ascent(); - if (m_theme.font().isRotated()) { - int tmp = dy; - dy = frame.clock.height() - dx; - dx = tmp; - } - m_theme.font().drawText( - frame.clock.window(), - screen()->getScreenNumber(), - m_theme.clockTextGC(), - t, newlen, - dx, dy); - } + size_t newlen = strlen(t); + int dx = FbTk::doAlignment(frame.clock_w, + frame.bevel_w*2, + m_theme.justify(), + m_theme.font(), + t, strlen(t), newlen); + int dy = 1 + m_theme.font().ascent(); + if (m_theme.font().isRotated()) { + int tmp = dy; + dy = frame.clock.height() - dx; + dx = tmp; + } + m_theme.font().drawText( + frame.clock.window(), + screen()->getScreenNumber(), + m_theme.clockTextGC(), + t, newlen, + dx, dy); + } diff --git a/src/Toolbar.hh b/src/Toolbar.hh index 9accc20..eb7af70 100644 --- a/src/Toolbar.hh +++ b/src/Toolbar.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Toolbar.hh,v 1.21 2003/01/12 18:52:35 fluxgen Exp $ +// $Id: Toolbar.hh,v 1.22 2003/02/15 02:00:29 fluxgen Exp $ #ifndef TOOLBAR_HH #define TOOLBAR_HH @@ -33,6 +33,7 @@ #include "EventHandler.hh" #include "FbWindow.hh" #include "ArrowButton.hh" +#include "Observer.hh" #include @@ -144,6 +145,7 @@ private: virtual void timeout(); } hide_handler; + friend class HideHandler; BScreen *m_screen; FbTk::ImageControl &image_ctrl; @@ -156,8 +158,18 @@ private: ToolbarTheme m_theme; Placement m_place; - - friend class HideHandler; + //!! TODO this is just temporary + class ThemeListener: public FbTk::Observer { + public: + ThemeListener(Toolbar &tb):m_tb(tb) { } + void update(FbTk::Subject *subj) { + m_tb.reconfigure(); + } + private: + Toolbar &m_tb; + }; + + ThemeListener m_themelistener; }; -- cgit v0.11.2