diff options
author | fluxgen <fluxgen> | 2003-10-13 23:37:41 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-10-13 23:37:41 (GMT) |
commit | 53be8d6f67a70527990ed32efc22e8e7763af3fb (patch) | |
tree | f558f7bcdb5844826ad91459c6622e0889414f3c /src/ToolFactory.cc | |
parent | 82ac933efe4ce3b88ec32ee8f64b1c3dcc0528b1 (diff) | |
download | fluxbox-53be8d6f67a70527990ed32efc22e8e7763af3fb.zip fluxbox-53be8d6f67a70527990ed32efc22e8e7763af3fb.tar.bz2 |
creates tools
Diffstat (limited to 'src/ToolFactory.cc')
-rw-r--r-- | src/ToolFactory.cc | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc new file mode 100644 index 0000000..24ab499 --- /dev/null +++ b/src/ToolFactory.cc | |||
@@ -0,0 +1,171 @@ | |||
1 | // ToolFactory.cc for Fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: ToolFactory.cc,v 1.1 2003/10/13 23:37:41 fluxgen Exp $ | ||
23 | |||
24 | #include "ToolFactory.hh" | ||
25 | |||
26 | // Tools | ||
27 | #include "ButtonTool.hh" | ||
28 | #include "ClockTool.hh" | ||
29 | #include "SystemTray.hh" | ||
30 | #include "IconbarTool.hh" | ||
31 | #include "WorkspaceNameTool.hh" | ||
32 | #include "ArrowButton.hh" | ||
33 | |||
34 | // Themes | ||
35 | #include "IconbarTheme.hh" | ||
36 | #include "WorkspaceNameTheme.hh" | ||
37 | #include "ButtonTheme.hh" | ||
38 | |||
39 | #include "CommandParser.hh" | ||
40 | #include "Screen.hh" | ||
41 | #include "Toolbar.hh" | ||
42 | #include "fluxbox.hh" | ||
43 | |||
44 | #include "FbTk/FbWindow.hh" | ||
45 | |||
46 | namespace { | ||
47 | class ShowMenuAboveToolbar: public FbTk::Command { | ||
48 | public: | ||
49 | explicit ShowMenuAboveToolbar(Toolbar &tbar):m_tbar(tbar) { } | ||
50 | void execute() { | ||
51 | |||
52 | // get last button pos | ||
53 | const XEvent &event = Fluxbox::instance()->lastEvent(); | ||
54 | int x = event.xbutton.x_root - (m_tbar.menu().width() / 2); | ||
55 | int y = event.xbutton.y_root - (m_tbar.menu().height() / 2); | ||
56 | |||
57 | if (x < 0) | ||
58 | x = 0; | ||
59 | else if (x + m_tbar.menu().width() > m_tbar.screen().width()) | ||
60 | x = m_tbar.screen().width() - m_tbar.menu().width(); | ||
61 | |||
62 | if (y < 0) | ||
63 | y = 0; | ||
64 | else if (y + m_tbar.menu().height() > m_tbar.screen().height()) | ||
65 | y = m_tbar.screen().height() - m_tbar.menu().height(); | ||
66 | |||
67 | m_tbar.menu().move(x, y); | ||
68 | m_tbar.menu().show(); | ||
69 | } | ||
70 | private: | ||
71 | Toolbar &m_tbar; | ||
72 | }; | ||
73 | |||
74 | }; | ||
75 | |||
76 | ToolFactory::ToolFactory(BScreen &screen):m_screen(screen), | ||
77 | m_clock_theme(screen.screenNumber(), "toolbar.clock", "Toolbar.Clock"), | ||
78 | m_button_theme(new ButtonTheme(screen.screenNumber(), "toolbar.button", "Toolbar.Button")), | ||
79 | m_workspace_theme(new WorkspaceNameTheme(screen.screenNumber(), "toolbar.workspace", "Toolbar.Workspace")), | ||
80 | m_iconbar_theme(screen.screenNumber(), "toolbar.iconbar", "Toolbar.Iconbar") { | ||
81 | |||
82 | } | ||
83 | |||
84 | ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &parent, Toolbar &tbar) { | ||
85 | |||
86 | unsigned int button_size = 24; | ||
87 | if (tbar.theme().buttonSize() > 0) | ||
88 | button_size = tbar.theme().buttonSize(); | ||
89 | |||
90 | if (name == "workspacename") { | ||
91 | WorkspaceNameTool *item = new WorkspaceNameTool(parent, | ||
92 | *m_workspace_theme, screen()); | ||
93 | using namespace FbTk; | ||
94 | RefCount<Command> showmenu(new ShowMenuAboveToolbar(tbar)); | ||
95 | item->button().setOnClick(showmenu); | ||
96 | return item; | ||
97 | } else if (name == "iconbar") { | ||
98 | return new IconbarTool(parent, m_iconbar_theme, | ||
99 | screen(), tbar.menu()); | ||
100 | } else if (name == "systemtray") { | ||
101 | return new SystemTray(parent); | ||
102 | } else if (name == "clock") { | ||
103 | return new ClockTool(parent, m_clock_theme, screen()); | ||
104 | } else if (name == "nextworkspace" || | ||
105 | name == "prevworkspace") { | ||
106 | |||
107 | FbTk::RefCount<FbTk::Command> cmd(CommandParser::instance().parseLine(name)); | ||
108 | if (*cmd == 0) // we need a command | ||
109 | return 0; | ||
110 | |||
111 | ArrowButton::Type arrow_type = ArrowButton::LEFT; | ||
112 | if (name == "nextworkspace") | ||
113 | arrow_type = ArrowButton::RIGHT; | ||
114 | |||
115 | ArrowButton *win = new ArrowButton(arrow_type, parent, | ||
116 | 0, 0, | ||
117 | button_size, button_size); | ||
118 | win->setOnClick(cmd); | ||
119 | return new ButtonTool(win, ToolbarItem::FIXED, | ||
120 | dynamic_cast<ButtonTheme &>(*m_button_theme), | ||
121 | screen().imageControl()); | ||
122 | |||
123 | } else if (name == "nextwindow" || | ||
124 | name == "prevwindow") { | ||
125 | |||
126 | FbTk::RefCount<FbTk::Command> cmd(CommandParser::instance().parseLine(name)); | ||
127 | if (*cmd == 0) // we need a command | ||
128 | return 0; | ||
129 | |||
130 | ArrowButton::Type arrow_type = ArrowButton::LEFT; | ||
131 | if (name == "nextwindow") | ||
132 | arrow_type = ArrowButton::RIGHT; | ||
133 | |||
134 | ArrowButton *win = new ArrowButton(arrow_type, parent, | ||
135 | 0, 0, | ||
136 | button_size, button_size); | ||
137 | win->setOnClick(cmd); | ||
138 | return new ButtonTool(win, ToolbarItem::FIXED, | ||
139 | dynamic_cast<ButtonTheme &>(*m_button_theme), | ||
140 | screen().imageControl()); | ||
141 | |||
142 | } | ||
143 | |||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | void ToolFactory::updateThemes() { | ||
148 | m_clock_theme.setAntialias(screen().antialias()); | ||
149 | m_iconbar_theme.setAntialias(screen().antialias()); | ||
150 | m_button_theme->setAntialias(screen().antialias()); | ||
151 | m_workspace_theme->setAntialias(screen().antialias()); | ||
152 | } | ||
153 | |||
154 | |||
155 | int ToolFactory::maxFontHeight() const { | ||
156 | unsigned int max_height = 0; | ||
157 | if (max_height < m_clock_theme.font().height()) | ||
158 | max_height = m_clock_theme.font().height(); | ||
159 | |||
160 | if (max_height < m_iconbar_theme.focusedText().font().height()) | ||
161 | max_height = m_iconbar_theme.focusedText().font().height(); | ||
162 | |||
163 | if (max_height < m_iconbar_theme.unfocusedText().font().height()) | ||
164 | max_height = m_iconbar_theme.unfocusedText().font().height(); | ||
165 | |||
166 | if (max_height < m_workspace_theme->font().height()) | ||
167 | max_height = m_workspace_theme->font().height(); | ||
168 | |||
169 | return max_height; | ||
170 | } | ||
171 | |||