diff options
author | simonb <simonb> | 2005-06-19 12:12:54 (GMT) |
---|---|---|
committer | simonb <simonb> | 2005-06-19 12:12:54 (GMT) |
commit | c2ec3065f96c327b52082cf5f254a85b32eb938a (patch) | |
tree | 63587d43b211c63cd4a63af4cbcc6e6a898c2c61 /src/Container.cc | |
parent | e0e11dd32bd9f7eb717ec7ee9a3b1f08a677d7e4 (diff) | |
download | fluxbox_pavel-c2ec3065f96c327b52082cf5f254a85b32eb938a.zip fluxbox_pavel-c2ec3065f96c327b52082cf5f254a85b32eb938a.tar.bz2 |
change fbwinframe to use container
move a few frame ops to have most code in Container
Diffstat (limited to 'src/Container.cc')
-rw-r--r-- | src/Container.cc | 170 |
1 files changed, 167 insertions, 3 deletions
diff --git a/src/Container.cc b/src/Container.cc index 8e1d41c..3a53a4b 100644 --- a/src/Container.cc +++ b/src/Container.cc | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include "FbTk/Button.hh" | 27 | #include "FbTk/Button.hh" |
28 | #include "FbTk/EventManager.hh" | 28 | #include "FbTk/EventManager.hh" |
29 | #include "CompareWindow.hh" | ||
29 | 30 | ||
30 | Container::Container(const FbTk::FbWindow &parent): | 31 | Container::Container(const FbTk::FbWindow &parent): |
31 | FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), | 32 | FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), |
@@ -111,10 +112,97 @@ void Container::insertItem(Item item, int pos) { | |||
111 | repositionItems(); | 112 | repositionItems(); |
112 | } | 113 | } |
113 | 114 | ||
114 | void Container::removeItem(int index) { | 115 | void Container::moveItem(Item item, int movement) { |
115 | if (index < 0 || index > size()) | 116 | int index = find(item); |
117 | if (index < 0) | ||
116 | return; | 118 | return; |
117 | 119 | ||
120 | int size = m_item_list.size(); | ||
121 | int newindex = (index + movement) % size; | ||
122 | if (newindex < 0) // neg wrap | ||
123 | newindex += size; | ||
124 | |||
125 | if (newindex > index) // one smaller now | ||
126 | --newindex; | ||
127 | |||
128 | ItemList::iterator it = m_item_list.begin(); | ||
129 | for (; newindex > 0 && index > 0; ++it, --newindex, --index) { | ||
130 | if (newindex == 0) { | ||
131 | m_item_list.insert(it, item); | ||
132 | ++newindex; | ||
133 | } | ||
134 | |||
135 | if (index == 0) { | ||
136 | m_item_list.erase(it); | ||
137 | --index; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | m_item_list.insert(it, item); | ||
142 | insertItem(item, newindex); | ||
143 | repositionItems(); | ||
144 | |||
145 | } | ||
146 | |||
147 | // returns true if something was done | ||
148 | bool Container::moveItemTo(Item item, int x, int y) { | ||
149 | Window parent_return=0, | ||
150 | root_return=0, | ||
151 | *children_return = NULL; | ||
152 | |||
153 | unsigned int nchildren_return; | ||
154 | |||
155 | // get the root window | ||
156 | if (!XQueryTree(display(), window(), | ||
157 | &root_return, &parent_return, &children_return, &nchildren_return)) | ||
158 | parent_return = parent_return; | ||
159 | |||
160 | if (children_return != NULL) | ||
161 | XFree(children_return); | ||
162 | |||
163 | int dest_x = 0, dest_y = 0; | ||
164 | Window itemwin = 0; | ||
165 | if (!XTranslateCoordinates(display(), | ||
166 | root_return, window(), | ||
167 | x, y, &dest_x, &dest_y, | ||
168 | &itemwin)) | ||
169 | return false; | ||
170 | |||
171 | ItemList::iterator it = find_if(m_item_list.begin(), | ||
172 | m_item_list.end(), | ||
173 | CompareWindow(&FbTk::FbWindow::window, | ||
174 | itemwin)); | ||
175 | // not found :( | ||
176 | if (it == m_item_list.end()) | ||
177 | return false; | ||
178 | |||
179 | Window child_return = 0; | ||
180 | //make x and y relative to our item | ||
181 | if (!XTranslateCoordinates(display(), | ||
182 | window(), itemwin, | ||
183 | dest_x, dest_y, &x, &y, | ||
184 | &child_return)) | ||
185 | return false; | ||
186 | return true; | ||
187 | } | ||
188 | |||
189 | bool Container::removeItem(Item item) { | ||
190 | ItemList::iterator it = m_item_list.begin(); | ||
191 | ItemList::iterator it_end = m_item_list.end(); | ||
192 | for (; it != it_end && (*it) != item; ++it); | ||
193 | |||
194 | if (it == it_end) | ||
195 | return false; | ||
196 | |||
197 | m_item_list.erase(it); | ||
198 | repositionItems(); | ||
199 | return true; | ||
200 | } | ||
201 | |||
202 | bool Container::removeItem(int index) { | ||
203 | if (index < 0 || index > size()) | ||
204 | return false; | ||
205 | |||
118 | ItemList::iterator it = m_item_list.begin(); | 206 | ItemList::iterator it = m_item_list.begin(); |
119 | for (; index != 0; ++it, --index) | 207 | for (; index != 0; ++it, --index) |
120 | continue; | 208 | continue; |
@@ -125,6 +213,7 @@ void Container::removeItem(int index) { | |||
125 | m_item_list.erase(it); | 213 | m_item_list.erase(it); |
126 | 214 | ||
127 | repositionItems(); | 215 | repositionItems(); |
216 | return true; | ||
128 | } | 217 | } |
129 | 218 | ||
130 | void Container::removeAll() { | 219 | void Container::removeAll() { |
@@ -136,7 +225,7 @@ void Container::removeAll() { | |||
136 | 225 | ||
137 | } | 226 | } |
138 | 227 | ||
139 | int Container::find(Item item) { | 228 | int Container::find(ConstItem item) { |
140 | ItemList::iterator it = m_item_list.begin(); | 229 | ItemList::iterator it = m_item_list.begin(); |
141 | ItemList::iterator it_end = m_item_list.end(); | 230 | ItemList::iterator it_end = m_item_list.end(); |
142 | int index = 0; | 231 | int index = 0; |
@@ -178,6 +267,60 @@ void Container::exposeEvent(XExposeEvent &event) { | |||
178 | } | 267 | } |
179 | } | 268 | } |
180 | 269 | ||
270 | bool Container::tryExposeEvent(XExposeEvent &event) { | ||
271 | if (event.window == window()) { | ||
272 | exposeEvent(event); | ||
273 | return true; | ||
274 | } | ||
275 | |||
276 | ItemList::iterator it = find_if(m_item_list.begin(), | ||
277 | m_item_list.end(), | ||
278 | CompareWindow(&FbTk::FbWindow::window, | ||
279 | event.window)); | ||
280 | // not found :( | ||
281 | if (it == m_item_list.end()) | ||
282 | return false; | ||
283 | |||
284 | (*it)->exposeEvent(event); | ||
285 | return true; | ||
286 | } | ||
287 | |||
288 | bool Container::tryButtonPressEvent(XButtonEvent &event) { | ||
289 | if (event.window == window()) { | ||
290 | // we don't have a buttonrelease event atm | ||
291 | return true; | ||
292 | } | ||
293 | |||
294 | ItemList::iterator it = find_if(m_item_list.begin(), | ||
295 | m_item_list.end(), | ||
296 | CompareWindow(&FbTk::FbWindow::window, | ||
297 | event.window)); | ||
298 | // not found :( | ||
299 | if (it == m_item_list.end()) | ||
300 | return false; | ||
301 | |||
302 | (*it)->buttonPressEvent(event); | ||
303 | return true; | ||
304 | } | ||
305 | |||
306 | bool Container::tryButtonReleaseEvent(XButtonEvent &event) { | ||
307 | if (event.window == window()) { | ||
308 | // we don't have a buttonrelease event atm | ||
309 | return true; | ||
310 | } | ||
311 | |||
312 | ItemList::iterator it = find_if(m_item_list.begin(), | ||
313 | m_item_list.end(), | ||
314 | CompareWindow(&FbTk::FbWindow::window, | ||
315 | event.window)); | ||
316 | // not found :( | ||
317 | if (it == m_item_list.end()) | ||
318 | return false; | ||
319 | |||
320 | (*it)->buttonReleaseEvent(event); | ||
321 | return true; | ||
322 | } | ||
323 | |||
181 | void Container::repositionItems() { | 324 | void Container::repositionItems() { |
182 | if (empty() || m_update_lock) | 325 | if (empty() || m_update_lock) |
183 | return; | 326 | return; |
@@ -241,3 +384,24 @@ unsigned int Container::maxWidthPerClient() const { | |||
241 | // this will never happen anyway | 384 | // this will never happen anyway |
242 | return 1; | 385 | return 1; |
243 | } | 386 | } |
387 | |||
388 | void Container::for_each(std::mem_fun_t<void, FbTk::FbWindow> function) { | ||
389 | std::for_each(m_item_list.begin(), | ||
390 | m_item_list.end(), | ||
391 | function); | ||
392 | } | ||
393 | |||
394 | void Container::setAlpha(unsigned char alpha) { | ||
395 | ItemList::iterator it = m_item_list.begin(); | ||
396 | ItemList::iterator it_end = m_item_list.end(); | ||
397 | for (; it != it_end; ++it) | ||
398 | (*it)->setAlpha(alpha); | ||
399 | } | ||
400 | |||
401 | void Container::clear() { | ||
402 | ItemList::iterator it = m_item_list.begin(); | ||
403 | ItemList::iterator it_end = m_item_list.end(); | ||
404 | for (; it != it_end; ++it) | ||
405 | (*it)->clear(); | ||
406 | |||
407 | } | ||