diff options
author | rathnor <rathnor> | 2003-01-16 12:41:27 (GMT) |
---|---|---|
committer | rathnor <rathnor> | 2003-01-16 12:41:27 (GMT) |
commit | 000fe76aae9c19c0c799da7bfdfc377f4bd59793 (patch) | |
tree | 17896b42de7f1cbbbc636dc8af2e3264a22dd5a9 /src/FbTk/XLayer.cc | |
parent | 00e10146668a4a04f13838d6df651870589b19e2 (diff) | |
download | fluxbox_pavel-000fe76aae9c19c0c799da7bfdfc377f4bd59793.zip fluxbox_pavel-000fe76aae9c19c0c799da7bfdfc377f4bd59793.tar.bz2 |
New Layer System
Diffstat (limited to 'src/FbTk/XLayer.cc')
-rw-r--r-- | src/FbTk/XLayer.cc | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/src/FbTk/XLayer.cc b/src/FbTk/XLayer.cc new file mode 100644 index 0000000..786cefe --- /dev/null +++ b/src/FbTk/XLayer.cc | |||
@@ -0,0 +1,186 @@ | |||
1 | // XLayer.cc for FbTk - fluxbox toolkit | ||
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: XLayer.cc,v 1.1 2003/01/16 12:41:27 rathnor Exp $ | ||
24 | |||
25 | #include "XLayer.hh" | ||
26 | #include "XLayerItem.hh" | ||
27 | #include "App.hh" | ||
28 | |||
29 | #include <iostream> | ||
30 | using namespace std; | ||
31 | using namespace FbTk; | ||
32 | |||
33 | XLayer::XLayer(MultLayers &manager, int layernum): | ||
34 | m_manager(manager), m_layernum(layernum) { | ||
35 | } | ||
36 | |||
37 | XLayer::~XLayer() { | ||
38 | } | ||
39 | |||
40 | void XLayer::restack() { | ||
41 | int numWindows = size(); | ||
42 | Window *winlist = new Window[numWindows]; | ||
43 | typedef FbTk::Layer<XLayerItem> BaseClass; | ||
44 | iterator it = itemList().begin(); | ||
45 | iterator it_end = itemList().end(); | ||
46 | for (size_t i=0; it != it_end; ++it, i++) { | ||
47 | winlist[i] = (*it)->window(); | ||
48 | } | ||
49 | |||
50 | XRestackWindows(FbTk::App::instance()->display(), winlist, numWindows); | ||
51 | |||
52 | delete [] winlist; | ||
53 | } | ||
54 | |||
55 | void XLayer::stackBelowItem(XLayerItem *item, XLayerItem *above) { | ||
56 | // little optimisation | ||
57 | if (!above) { // must need to go right to top | ||
58 | XRaiseWindow(FbTk::App::instance()->display(), item->window()); | ||
59 | return; | ||
60 | } | ||
61 | |||
62 | Window * winlist = new Window[2]; | ||
63 | winlist[0] = above->window(); | ||
64 | winlist[1] = item->window(); | ||
65 | |||
66 | XRestackWindows(FbTk::App::instance()->display(), winlist, 2); | ||
67 | |||
68 | delete [] winlist; | ||
69 | } | ||
70 | |||
71 | XLayer::iterator XLayer::insert(XLayerItem &item, unsigned int pos) { | ||
72 | #ifdef DEBUG | ||
73 | if (pos != 0) | ||
74 | cerr<<__FILE__<<"("<<__LINE__<<"): Insert using non-zero position not valid in XLayer"<<endl; | ||
75 | #endif // DEBUG | ||
76 | |||
77 | itemList().push_front(&item); | ||
78 | item.setLayer(*this); | ||
79 | // restack below next window up | ||
80 | item.setLayerIterator(itemList().begin()); | ||
81 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); | ||
82 | return itemList().begin(); | ||
83 | } | ||
84 | |||
85 | void XLayer::remove(XLayerItem &item) { | ||
86 | itemList().erase(item.getLayerIterator()); | ||
87 | } | ||
88 | |||
89 | void XLayer::cycleUp() { | ||
90 | // need to find highest visible window, and move it to bottom | ||
91 | iterator it = itemList().begin(); | ||
92 | iterator it_end = itemList().end(); | ||
93 | while (it != it_end && !(*it)->visible()) ++it; | ||
94 | |||
95 | // if there is something to do | ||
96 | if (it != it_end) { | ||
97 | lower(**it); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | void XLayer::cycleDown() { | ||
102 | // need to find highest visible window, and move it to bottom | ||
103 | reverse_iterator it = itemList().rbegin(); | ||
104 | reverse_iterator it_end = itemList().rend(); | ||
105 | while (it != it_end && !(*it)->visible()) ++it; | ||
106 | |||
107 | // if there is something to do | ||
108 | if (it != it_end) { | ||
109 | raise(**it); | ||
110 | } | ||
111 | |||
112 | } | ||
113 | |||
114 | void XLayer::stepUp(XLayerItem &item) { | ||
115 | // need to find next visible window upwards, and put it above that | ||
116 | |||
117 | if (&item == itemList().front()) return; // nothing to do | ||
118 | |||
119 | // TODO: is there a better way of doing this? | ||
120 | iterator it = item.getLayerIterator(); | ||
121 | it--; | ||
122 | while ((*it) != itemList().front() && !(*it)->visible()) --it; | ||
123 | |||
124 | if (*it == itemList().front() && !(*it)->visible()) { | ||
125 | // reached front item, but it wasn't visible, therefore it was already raised | ||
126 | //moveToBottom(item); | ||
127 | } else { | ||
128 | // it is the next visible item down, we need to be above it. | ||
129 | itemList().erase(item.getLayerIterator()); | ||
130 | //itemList().insert(it, item); | ||
131 | item.setLayerIterator(it = itemList().insert(it, &item)); | ||
132 | if (*it == itemList().front()) { | ||
133 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); | ||
134 | } else { | ||
135 | it--; | ||
136 | stackBelowItem(&item, *it); | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | |||
141 | void XLayer::stepDown(XLayerItem &item) { | ||
142 | // need to find next visible window down, and put it below that | ||
143 | if (&item == itemList().back()) return; // nothing to do | ||
144 | |||
145 | |||
146 | iterator it = item.getLayerIterator(); | ||
147 | it++; | ||
148 | iterator it_end = itemList().end(); | ||
149 | while (it != it_end && !(*it)->visible()) ++it; | ||
150 | |||
151 | if (it != it_end) { | ||
152 | stackBelowItem(&item, *it); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | void XLayer::raise(XLayerItem &item) { | ||
157 | // assume it is already in this layer | ||
158 | |||
159 | if (&item == itemList().front()) | ||
160 | return; // nothing to do | ||
161 | |||
162 | itemList().erase(item.getLayerIterator()); | ||
163 | itemList().push_front(&item); | ||
164 | item.setLayerIterator(itemList().begin()); | ||
165 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); | ||
166 | |||
167 | } | ||
168 | |||
169 | void XLayer::lower(XLayerItem &item) { | ||
170 | // assume already in this layer | ||
171 | if (&item == itemList().back()) | ||
172 | return; // nothing to do | ||
173 | |||
174 | itemList().erase(item.getLayerIterator()); | ||
175 | itemList().push_back(&item); | ||
176 | iterator it = itemList().end(); | ||
177 | it--; | ||
178 | item.setLayerIterator(it); | ||
179 | it--; | ||
180 | stackBelowItem(&item, *it); // must exist, otherwise item must == itemList().back() | ||
181 | } | ||
182 | |||
183 | XLayerItem *XLayer::getLowestItem() { | ||
184 | if (itemList().empty()) return 0; | ||
185 | else return itemList().back(); | ||
186 | } | ||