aboutsummaryrefslogtreecommitdiff
path: root/src/ClockTool.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-11 14:32:39 (GMT)
committerfluxgen <fluxgen>2003-08-11 14:32:39 (GMT)
commitd45b3ad764f2854f323254a6616c93466df5445d (patch)
tree002939ca9daafa14eda54507b87bf37f6536c0c9 /src/ClockTool.cc
parent4f51fab7afc2b7fa48e28d182336df84ffe284d2 (diff)
downloadfluxbox-d45b3ad764f2854f323254a6616c93466df5445d.zip
fluxbox-d45b3ad764f2854f323254a6616c93466df5445d.tar.bz2
basic tools for toolbar
Diffstat (limited to 'src/ClockTool.cc')
-rw-r--r--src/ClockTool.cc148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/ClockTool.cc b/src/ClockTool.cc
new file mode 100644
index 0000000..3b56be1
--- /dev/null
+++ b/src/ClockTool.cc
@@ -0,0 +1,148 @@
1// ClockTool.cc
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: ClockTool.cc,v 1.1 2003/08/11 14:32:39 fluxgen Exp $
24
25#include "ClockTool.hh"
26
27#include "ToolTheme.hh"
28#include "Screen.hh"
29
30#include "FbTk/SimpleCommand.hh"
31#include "FbTk/ImageControl.hh"
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif // HAVE_CONFIG_H
36
37#include <ctime>
38
39#include <iostream>
40using namespace std;
41
42ClockTool::ClockTool(const FbTk::FbWindow &parent,
43 ToolTheme &theme, BScreen &screen):
44 ToolbarItem(ToolbarItem::FIXED),
45 m_button(parent, theme.font(), ""),
46 m_theme(theme),
47 m_screen(screen),
48 m_pixmap(0),
49 m_timeformat(screen.resourceManager(), std::string("%k:%M"),
50 screen.name() + ".strftimeFormat", screen.altName() + ".StrftimeFormat") {
51
52 theme.reconfigSig().attach(this);
53 m_button.setGC(theme.textGC());
54 m_button.clear();
55
56 // setup timer to update the graphics each second
57 timeval delay;
58 delay.tv_sec = 1;
59 delay.tv_usec = 0;
60 m_timer.setTimeout(delay);
61 FbTk::RefCount<FbTk::Command> update_graphic(new FbTk::SimpleCommand<ClockTool>(*this,
62 &ClockTool::updateTime));
63 m_timer.setCommand(update_graphic);
64 m_timer.start();
65
66 update(0);
67}
68
69ClockTool::~ClockTool() {
70 // remove cached pixmap
71 if (m_pixmap)
72 m_screen.imageControl().removeImage(m_pixmap);
73}
74
75void ClockTool::move(int x, int y) {
76 m_button.move(x, y);
77}
78
79void ClockTool::resize(unsigned int width, unsigned int height) {
80 m_button.resize(width, height);
81 renderTheme();
82}
83
84void ClockTool::moveResize(int x, int y,
85 unsigned int width, unsigned int height) {
86 m_button.moveResize(x, y, width, height);
87}
88
89void ClockTool::show() {
90 m_button.show();
91}
92
93void ClockTool::hide() {
94 m_button.hide();
95}
96
97void ClockTool::update(FbTk::Subject *subj) {
98 updateTime();
99 resize(m_button.textWidth(), m_button.height());
100}
101
102unsigned int ClockTool::width() const {
103 return m_theme.font().textWidth(m_button.text().c_str(), m_button.text().size());
104}
105
106unsigned int ClockTool::height() const {
107 return m_button.height();
108}
109
110void ClockTool::updateTime() {
111
112 // update clock
113 time_t the_time = time(0);
114
115 if (the_time != -1) {
116 char time_string[255];
117 struct tm *time_type = localtime(&the_time);
118 if (time_type == 0)
119 return;
120
121#ifdef HAVE_STRFTIME
122 if (!strftime(time_string, 255, m_timeformat->c_str(), time_type))
123 return;
124 m_button.setText(time_string);
125#else // dont have strftime so we have to set it to hour:minut
126 // sprintf(time_string, "%d:%d", );
127#endif // HAVE_STRFTIME
128 }
129
130
131 m_button.clear();
132}
133
134void ClockTool::renderTheme() {
135 Pixmap old_pm = m_pixmap;
136 if (m_theme.texture().type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
137 m_pixmap = 0;
138 m_button.setBackgroundColor(m_theme.texture().color());
139 } else {
140 m_pixmap = m_screen.imageControl().renderImage(m_button.width(), m_button.height(), m_theme.texture());
141 m_button.setBackgroundPixmap(m_pixmap);
142 }
143
144 if (old_pm)
145 m_screen.imageControl().removeImage(old_pm);
146
147 m_button.clear();
148}