aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/XLayer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/XLayer.cc')
-rw-r--r--src/FbTk/XLayer.cc116
1 files changed, 66 insertions, 50 deletions
diff --git a/src/FbTk/XLayer.cc b/src/FbTk/XLayer.cc
index d945f4b..6b1791f 100644
--- a/src/FbTk/XLayer.cc
+++ b/src/FbTk/XLayer.cc
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: XLayer.cc,v 1.3 2003/02/02 16:32:41 rathnor Exp $ 23// $Id: XLayer.cc,v 1.4 2003/02/03 13:45:23 fluxgen Exp $
24 24
25#include "XLayer.hh" 25#include "XLayer.hh"
26#include "XLayerItem.hh" 26#include "XLayerItem.hh"
@@ -35,45 +35,42 @@ XLayer::XLayer(MultLayers &manager, int layernum):
35} 35}
36 36
37XLayer::~XLayer() { 37XLayer::~XLayer() {
38
38} 39}
39 40
40void XLayer::restack() { 41void XLayer::restack() {
41 int numWindows = countWindows(); 42 int num_windows = countWindows();
42 43
43 // each LayerItem can contain several windows 44 // each LayerItem can contain several windows
44 iterator it = itemList().begin(); 45 iterator it = itemList().begin();
45 iterator it_end = itemList().end(); 46 iterator it_end = itemList().end();
46 it = itemList().begin(); 47 Window *winlist = new Window[num_windows];
47 it_end = itemList().end();
48 Window *winlist = new Window[numWindows];
49 size_t j=0; 48 size_t j=0;
50 for (size_t i=0; it != it_end; ++it, i++) { 49 for (size_t window=0; it != it_end; ++it, window++) {
51 XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin(); 50 winlist[window] = (*it)->window();
52 XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end();
53 for (; wit != wit_end; ++wit, j++) {
54 winlist[j] = (*wit);
55 }
56 } 51 }
57 52
58 XRestackWindows(FbTk::App::instance()->display(), winlist, numWindows); 53 XRestackWindows(FbTk::App::instance()->display(), winlist, num_windows);
59 54
60 delete [] winlist; 55 delete [] winlist;
61} 56}
62 57
63int XLayer::countWindows() { 58int XLayer::countWindows() {
64 int numWindows = 0; 59 int num_windows = 0;
65 iterator it = itemList().begin(); 60 iterator it = itemList().begin();
66 iterator it_end = itemList().end(); 61 iterator it_end = itemList().end();
67 for (size_t i=0; it != it_end; ++it, i++) { 62 for (size_t i=0; it != it_end; ++it, i++) {
68 numWindows += (*it)->numWindows(); 63 num_windows ++; // one window per item
69 } 64 }
70 return numWindows; 65 return num_windows;
71} 66}
72 67
73 68
74void XLayer::stackBelowItem(XLayerItem *item, XLayerItem *above) { 69void XLayer::stackBelowItem(XLayerItem *item, XLayerItem *above) {
70 //!! What????
71
75 // little optimisation 72 // little optimisation
76 Window *winlist; 73 /* Window *winlist;
77 size_t i, size, num = item->numWindows(); 74 size_t i, size, num = item->numWindows();
78 75
79 if (!above) { // must need to go right to top 76 if (!above) { // must need to go right to top
@@ -105,61 +102,70 @@ void XLayer::stackBelowItem(XLayerItem *item, XLayerItem *above) {
105 XRestackWindows(FbTk::App::instance()->display(), winlist, size); 102 XRestackWindows(FbTk::App::instance()->display(), winlist, size);
106 103
107 delete [] winlist; 104 delete [] winlist;
105 */
108} 106}
109 107
110XLayer::iterator XLayer::insert(XLayerItem &item, unsigned int pos) { 108XLayer::iterator XLayer::insert(XLayerItem &item, unsigned int pos) {
111#ifdef DEBUG 109#ifdef DEBUG
112 if (pos != 0) 110 if (pos != 0)//!! Why????
113 cerr<<__FILE__<<"("<<__LINE__<<"): Insert using non-zero position not valid in XLayer"<<endl; 111 cerr<<__FILE__<<"("<<__LINE__<<"): Insert using non-zero position not valid in XLayer"<<endl;
114#endif // DEBUG 112#endif // DEBUG
115 113
116 itemList().push_front(&item); 114 itemList().push_front(&item);
117 item.setLayer(this);
118 // restack below next window up 115 // restack below next window up
119 item.setLayerIterator(itemList().begin()); 116 // item.setLayerIterator(itemList().begin());
120 stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); 117 stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum));
121 return itemList().begin(); 118 return itemList().begin();
122} 119}
123 120
124void XLayer::remove(XLayerItem &item) { 121void XLayer::remove(XLayerItem &item) {
125 itemList().erase(item.getLayerIterator()); 122 iterator it = itemList().begin();
126 item.setLayer(0); 123 iterator it_end = itemList().end();
124 for (; it != it_end; ++it) {
125 if (*it == &item)
126 itemList().erase(it);
127 }
127} 128}
128 129
129void XLayer::cycleUp() { 130void XLayer::cycleUp() {
130 // need to find highest visible window, and move it to bottom 131 // need to find highest visible window, and move it to bottom
131 iterator it = itemList().begin(); 132 iterator it = itemList().begin();
132 iterator it_end = itemList().end(); 133 iterator it_end = itemList().end();
133 while (it != it_end && !(*it)->visible()) ++it; 134 while (it != it_end && !(*it)->visible())
135 ++it;
134 136
135 // if there is something to do 137 // if there is something to do
136 if (it != it_end) { 138 if (it != it_end)
137 lower(**it); 139 lower(**it);
138 } 140
139} 141}
140 142
141void XLayer::cycleDown() { 143void XLayer::cycleDown() {
142 // need to find highest visible window, and move it to bottom 144 // need to find highest visible window, and move it to bottom
143 reverse_iterator it = itemList().rbegin(); 145 reverse_iterator it = itemList().rbegin();
144 reverse_iterator it_end = itemList().rend(); 146 reverse_iterator it_end = itemList().rend();
145 while (it != it_end && !(*it)->visible()) ++it; 147 while (it != it_end && !(*it)->visible())
148 ++it;
146 149
147 // if there is something to do 150 // if there is something to do
148 if (it != it_end) { 151 if (it != it_end)
149 raise(**it); 152 raise(**it);
150 }
151 153
152} 154}
153 155
154void XLayer::stepUp(XLayerItem &item) { 156void XLayer::stepUp(XLayerItem &item) {
155 // need to find next visible window upwards, and put it above that 157 // need to find next visible window upwards, and put it above that
156 158
157 if (&item == itemList().front()) return; // nothing to do 159 if (&item == itemList().front())
160 return; // nothing to do
158 161
162 //!! better stable and slow than buggy!
163 /*
159 // TODO: is there a better way of doing this? 164 // TODO: is there a better way of doing this?
160 iterator it = item.getLayerIterator(); 165 iterator it = item.getLayerIterator();
161 it--; 166 it--;
162 while ((*it) != itemList().front() && !(*it)->visible()) --it; 167 while ((*it) != itemList().front() && !(*it)->visible())
168 --it;
163 169
164 if (*it == itemList().front() && !(*it)->visible()) { 170 if (*it == itemList().front() && !(*it)->visible()) {
165 // reached front item, but it wasn't visible, therefore it was already raised 171 // reached front item, but it wasn't visible, therefore it was already raised
@@ -176,33 +182,36 @@ void XLayer::stepUp(XLayerItem &item) {
176 stackBelowItem(&item, *it); 182 stackBelowItem(&item, *it);
177 } 183 }
178 } 184 }
185 */
179} 186}
180 187
181void XLayer::stepDown(XLayerItem &item) { 188void XLayer::stepDown(XLayerItem &item) {
182 // need to find next visible window down, and put it below that 189 // need to find next visible window down, and put it below that
183 if (&item == itemList().back()) return; // nothing to do 190 if (&item == itemList().back())
184 191 return; // nothing to do
185 192
186 iterator it = item.getLayerIterator(); 193 //!! better stable and slow than buggy!
194 /* iterator it = item.getLayerIterator();
187 it++; 195 it++;
188 iterator it_end = itemList().end(); 196 iterator it_end = itemList().end();
189 while (it != it_end && !(*it)->visible()) ++it; 197 while (it != it_end && !(*it)->visible())
198 ++it;
190 199
191 if (it != it_end) { 200 if (it != it_end)
192 stackBelowItem(&item, *it); 201 stackBelowItem(&item, *it);
193 } 202 */
194} 203}
195 204
205//!!
196void XLayer::raise(XLayerItem &item) { 206void XLayer::raise(XLayerItem &item) {
197 // assume it is already in this layer 207 // assume it is already in this layer
198 208
199 if (&item == itemList().front()) { 209 if (&item == itemList().front())
200 return; // nothing to do 210 return; // nothing to do
201 }
202 211
203 itemList().erase(item.getLayerIterator()); 212 // itemList().erase(item.getLayerIterator());
204 itemList().push_front(&item); 213 itemList().push_front(&item);
205 item.setLayerIterator(itemList().begin()); 214 // item.setLayerIterator(itemList().begin());
206 stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); 215 stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum));
207 216
208} 217}
@@ -212,6 +221,8 @@ void XLayer::lower(XLayerItem &item) {
212 if (&item == itemList().back()) 221 if (&item == itemList().back())
213 return; // nothing to do 222 return; // nothing to do
214 223
224 //!! better stable and slow than buggy!
225 /*
215 itemList().erase(item.getLayerIterator()); 226 itemList().erase(item.getLayerIterator());
216 itemList().push_back(&item); 227 itemList().push_back(&item);
217 iterator it = itemList().end(); 228 iterator it = itemList().end();
@@ -219,28 +230,33 @@ void XLayer::lower(XLayerItem &item) {
219 item.setLayerIterator(it); 230 item.setLayerIterator(it);
220 it--; 231 it--;
221 stackBelowItem(&item, *it); // must exist, otherwise item must == itemList().back() 232 stackBelowItem(&item, *it); // must exist, otherwise item must == itemList().back()
233 */
222} 234}
223 235
224XLayerItem *XLayer::getLowestItem() { 236XLayerItem *XLayer::getLowestItem() {
225 if (itemList().empty()) return 0; 237 if (itemList().empty())
226 else return itemList().back(); 238 return 0;
239 else
240 return itemList().back();
227} 241}
228 242
229XLayerItem *XLayer::getItemBelow(XLayerItem &item) { 243XLayerItem *XLayer::getItemBelow(XLayerItem &item) {
230 iterator it = item.getLayerIterator(); 244 //!! better stable and slow than buggy!
231 if (it == itemList().begin()) { 245 /* iterator it = item.getLayerIterator();
246 if (it == itemList().begin())
232 return 0; 247 return 0;
233 } else { 248 else
234 return *(--it); 249 return *(--it);
235 } 250 */
236} 251}
237 252
238XLayerItem *XLayer::getItemAbove(XLayerItem &item) { 253XLayerItem *XLayer::getItemAbove(XLayerItem &item) {
239 iterator it = item.getLayerIterator(); 254 //!! better stable and slow than buggy!
255 /* iterator it = item.getLayerIterator();
240 it++; 256 it++;
241 if (it == itemList().end()) { 257 if (it == itemList().end())
242 return 0; 258 return 0;
243 } else { 259 else
244 return *it; 260 return *it;
245 } 261 */
246} 262}