diff options
author | fluxgen <fluxgen> | 2003-08-11 14:32:39 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-08-11 14:32:39 (GMT) |
commit | d45b3ad764f2854f323254a6616c93466df5445d (patch) | |
tree | 002939ca9daafa14eda54507b87bf37f6536c0c9 /src | |
parent | 4f51fab7afc2b7fa48e28d182336df84ffe284d2 (diff) | |
download | fluxbox_paul-d45b3ad764f2854f323254a6616c93466df5445d.zip fluxbox_paul-d45b3ad764f2854f323254a6616c93466df5445d.tar.bz2 |
basic tools for toolbar
Diffstat (limited to 'src')
-rw-r--r-- | src/ClockTool.cc | 148 | ||||
-rw-r--r-- | src/ClockTool.hh | 77 | ||||
-rw-r--r-- | src/WorkspaceNameTool.cc | 115 | ||||
-rw-r--r-- | src/WorkspaceNameTool.hh | 62 |
4 files changed, 402 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> | ||
40 | using namespace std; | ||
41 | |||
42 | ClockTool::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 | |||
69 | ClockTool::~ClockTool() { | ||
70 | // remove cached pixmap | ||
71 | if (m_pixmap) | ||
72 | m_screen.imageControl().removeImage(m_pixmap); | ||
73 | } | ||
74 | |||
75 | void ClockTool::move(int x, int y) { | ||
76 | m_button.move(x, y); | ||
77 | } | ||
78 | |||
79 | void ClockTool::resize(unsigned int width, unsigned int height) { | ||
80 | m_button.resize(width, height); | ||
81 | renderTheme(); | ||
82 | } | ||
83 | |||
84 | void ClockTool::moveResize(int x, int y, | ||
85 | unsigned int width, unsigned int height) { | ||
86 | m_button.moveResize(x, y, width, height); | ||
87 | } | ||
88 | |||
89 | void ClockTool::show() { | ||
90 | m_button.show(); | ||
91 | } | ||
92 | |||
93 | void ClockTool::hide() { | ||
94 | m_button.hide(); | ||
95 | } | ||
96 | |||
97 | void ClockTool::update(FbTk::Subject *subj) { | ||
98 | updateTime(); | ||
99 | resize(m_button.textWidth(), m_button.height()); | ||
100 | } | ||
101 | |||
102 | unsigned int ClockTool::width() const { | ||
103 | return m_theme.font().textWidth(m_button.text().c_str(), m_button.text().size()); | ||
104 | } | ||
105 | |||
106 | unsigned int ClockTool::height() const { | ||
107 | return m_button.height(); | ||
108 | } | ||
109 | |||
110 | void 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 | |||
134 | void 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 | } | ||
diff --git a/src/ClockTool.hh b/src/ClockTool.hh new file mode 100644 index 0000000..ceaebae --- /dev/null +++ b/src/ClockTool.hh | |||
@@ -0,0 +1,77 @@ | |||
1 | // ClockTool.hh | ||
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.hh,v 1.1 2003/08/11 14:32:39 fluxgen Exp $ | ||
24 | |||
25 | #ifndef CLOCKTOOL_HH | ||
26 | #define CLOCKTOOL_HH | ||
27 | |||
28 | |||
29 | #include "ToolbarItem.hh" | ||
30 | #include "TextButton.hh" | ||
31 | |||
32 | #include "FbTk/Observer.hh" | ||
33 | #include "FbTk/Resource.hh" | ||
34 | #include "FbTk/Timer.hh" | ||
35 | |||
36 | #include <string> | ||
37 | |||
38 | class ToolTheme; | ||
39 | class BScreen; | ||
40 | |||
41 | namespace FbTk { | ||
42 | class ImageControl; | ||
43 | class Subject; | ||
44 | } | ||
45 | |||
46 | class ClockTool:public ToolbarItem, public FbTk::Observer { | ||
47 | public: | ||
48 | ClockTool(const FbTk::FbWindow &parent, ToolTheme &theme, BScreen &screen); | ||
49 | virtual ~ClockTool(); | ||
50 | |||
51 | void move(int x, int y); | ||
52 | void resize(unsigned int width, unsigned int height); | ||
53 | void moveResize(int x, int y, | ||
54 | unsigned int width, unsigned int height); | ||
55 | |||
56 | void show(); | ||
57 | void hide(); | ||
58 | unsigned int width() const; | ||
59 | unsigned int height() const; | ||
60 | |||
61 | private: | ||
62 | void updateTime(); | ||
63 | void update(FbTk::Subject *subj); | ||
64 | void renderTheme(); | ||
65 | |||
66 | TextButton m_button; | ||
67 | |||
68 | const ToolTheme &m_theme; | ||
69 | BScreen &m_screen; | ||
70 | Pixmap m_pixmap; | ||
71 | FbTk::Timer m_timer; | ||
72 | |||
73 | FbTk::Resource<std::string> m_timeformat; | ||
74 | |||
75 | }; | ||
76 | |||
77 | #endif // CLOCKTOOL_HH | ||
diff --git a/src/WorkspaceNameTool.cc b/src/WorkspaceNameTool.cc new file mode 100644 index 0000000..bc493fa --- /dev/null +++ b/src/WorkspaceNameTool.cc | |||
@@ -0,0 +1,115 @@ | |||
1 | // WorkspaceNameTool.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: WorkspaceNameTool.cc,v 1.1 2003/08/11 14:32:39 fluxgen Exp $ | ||
24 | |||
25 | #include "WorkspaceNameTool.hh" | ||
26 | |||
27 | #include "ToolTheme.hh" | ||
28 | #include "Screen.hh" | ||
29 | #include "Workspace.hh" | ||
30 | |||
31 | #include "FbTk/ImageControl.hh" | ||
32 | |||
33 | WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent, | ||
34 | ToolTheme &theme, BScreen &screen): | ||
35 | ToolbarItem(ToolbarItem::FIXED), | ||
36 | m_button(parent, theme.font(), "a workspace name"), | ||
37 | m_theme(theme), | ||
38 | m_screen(screen), | ||
39 | m_pixmap(0) { | ||
40 | // set text | ||
41 | m_button.setText(m_screen.currentWorkspace()->name()); | ||
42 | // setup signals | ||
43 | screen.currentWorkspaceSig().attach(this); | ||
44 | theme.reconfigSig().attach(this); | ||
45 | } | ||
46 | |||
47 | WorkspaceNameTool::~WorkspaceNameTool() { | ||
48 | if (m_pixmap) | ||
49 | m_screen.imageControl().removeImage(m_pixmap); | ||
50 | } | ||
51 | |||
52 | void WorkspaceNameTool::move(int x, int y) { | ||
53 | m_button.move(x, y); | ||
54 | } | ||
55 | |||
56 | void WorkspaceNameTool::resize(unsigned int width, unsigned int height) { | ||
57 | m_button.resize(width, height); | ||
58 | } | ||
59 | |||
60 | |||
61 | void WorkspaceNameTool::moveResize(int x, int y, | ||
62 | unsigned int width, unsigned int height) { | ||
63 | m_button.moveResize(x, y, width, height); | ||
64 | } | ||
65 | |||
66 | void WorkspaceNameTool::update(FbTk::Subject *subj) { | ||
67 | m_button.setText(m_screen.currentWorkspace()->name()); | ||
68 | renderTheme(); | ||
69 | } | ||
70 | |||
71 | unsigned int WorkspaceNameTool::width() const { | ||
72 | // calculate largest size | ||
73 | int max_size = 0; | ||
74 | const int num_workspaces = m_screen.getNumberOfWorkspaces(); | ||
75 | for (int workspace = 0; workspace < num_workspaces; ++workspace) { | ||
76 | const std::string &name = m_screen.getWorkspace(workspace)->name().c_str(); | ||
77 | int size = m_theme.font().textWidth(name.c_str(), name.size()); | ||
78 | if (size > max_size) | ||
79 | max_size = size; | ||
80 | } | ||
81 | // so align text dont cut the last character | ||
82 | max_size += 2; | ||
83 | |||
84 | return max_size; | ||
85 | } | ||
86 | |||
87 | unsigned int WorkspaceNameTool::height() const { | ||
88 | return m_button.height(); | ||
89 | } | ||
90 | |||
91 | |||
92 | void WorkspaceNameTool::show() { | ||
93 | m_button.show(); | ||
94 | } | ||
95 | |||
96 | void WorkspaceNameTool::hide() { | ||
97 | m_button.hide(); | ||
98 | } | ||
99 | |||
100 | void WorkspaceNameTool::renderTheme() { | ||
101 | Pixmap tmp = m_pixmap; | ||
102 | if (m_theme.texture().type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { | ||
103 | m_pixmap = 0; | ||
104 | m_button.setBackgroundColor(m_theme.texture().color()); | ||
105 | } else { | ||
106 | m_pixmap = m_screen.imageControl().renderImage(width(), height(), | ||
107 | m_theme.texture()); | ||
108 | } | ||
109 | if (tmp) | ||
110 | m_screen.imageControl().removeImage(tmp); | ||
111 | |||
112 | m_button.setFont(m_theme.font()); | ||
113 | m_button.setJustify(m_theme.justify()); | ||
114 | m_button.clear(); | ||
115 | } | ||
diff --git a/src/WorkspaceNameTool.hh b/src/WorkspaceNameTool.hh new file mode 100644 index 0000000..a5d0188 --- /dev/null +++ b/src/WorkspaceNameTool.hh | |||
@@ -0,0 +1,62 @@ | |||
1 | // WorkspaceNameTool.hh | ||
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: WorkspaceNameTool.hh,v 1.1 2003/08/11 14:32:39 fluxgen Exp $ | ||
24 | |||
25 | #ifndef WORKSPACENAMETOOL_HH | ||
26 | #define WORKSPACENAMETOOL_HH | ||
27 | |||
28 | #include "ToolbarItem.hh" | ||
29 | #include "TextButton.hh" | ||
30 | |||
31 | #include "FbTk/Observer.hh" | ||
32 | |||
33 | class BScreen; | ||
34 | class ToolTheme; | ||
35 | |||
36 | class WorkspaceNameTool: public ToolbarItem, FbTk::Observer { | ||
37 | public: | ||
38 | WorkspaceNameTool(const FbTk::FbWindow &parent, ToolTheme &theme, BScreen &screen); | ||
39 | virtual ~WorkspaceNameTool(); | ||
40 | |||
41 | void move(int x, int y); | ||
42 | void resize(unsigned int width, unsigned int height); | ||
43 | void moveResize(int x, int y, | ||
44 | unsigned int width, unsigned int height); | ||
45 | |||
46 | void show(); | ||
47 | void hide(); | ||
48 | unsigned int width() const; | ||
49 | unsigned int height() const; | ||
50 | |||
51 | void update(FbTk::Subject *subj); | ||
52 | |||
53 | private: | ||
54 | void renderTheme(); | ||
55 | TextButton m_button; | ||
56 | const ToolTheme &m_theme; | ||
57 | BScreen &m_screen; | ||
58 | Pixmap m_pixmap; | ||
59 | }; | ||
60 | |||
61 | #endif // WORKSPACENAMETOOL_HH | ||
62 | |||