diff options
Diffstat (limited to 'src/FbTk/MultLayers.cc')
-rw-r--r-- | src/FbTk/MultLayers.cc | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/src/FbTk/MultLayers.cc b/src/FbTk/MultLayers.cc new file mode 100644 index 0000000..9875ef7 --- /dev/null +++ b/src/FbTk/MultLayers.cc | |||
@@ -0,0 +1,201 @@ | |||
1 | // MultLayers.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: MultLayers.cc,v 1.8 2004/01/08 22:04:04 fluxgen Exp $ | ||
24 | |||
25 | #include "MultLayers.hh" | ||
26 | #include "XLayer.hh" | ||
27 | #include "XLayerItem.hh" | ||
28 | #include "App.hh" | ||
29 | |||
30 | #include <iostream> | ||
31 | using namespace std; | ||
32 | |||
33 | using namespace FbTk; | ||
34 | |||
35 | MultLayers::MultLayers(int numlayers) : | ||
36 | m_lock(0) | ||
37 | { | ||
38 | for (int i=0; i < numlayers; ++i) | ||
39 | m_layers.push_back(new XLayer(*this, i)); | ||
40 | } | ||
41 | |||
42 | MultLayers::~MultLayers() { | ||
43 | while (!m_layers.empty()) { | ||
44 | delete m_layers.back(); | ||
45 | m_layers.pop_back(); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | |||
50 | XLayerItem *MultLayers::getLowestItemAboveLayer(int layernum) { | ||
51 | if (layernum >= static_cast<signed>(m_layers.size()) || layernum <= 0) | ||
52 | return 0; | ||
53 | |||
54 | layernum--; // next one up | ||
55 | XLayerItem *item = 0; | ||
56 | while (layernum >= 0 && (item = m_layers[layernum]->getLowestItem()) == 0) | ||
57 | layernum--; | ||
58 | return item; | ||
59 | |||
60 | } | ||
61 | |||
62 | XLayerItem *MultLayers::getItemBelow(XLayerItem &item) { | ||
63 | XLayer &curr_layer = item.getLayer(); | ||
64 | |||
65 | // assume that the LayerItem does exist in a layer. | ||
66 | XLayerItem *ret = curr_layer.getItemBelow(item); | ||
67 | |||
68 | if (ret == 0) { | ||
69 | int num = curr_layer.getLayerNum()-1; | ||
70 | while (num >= 0 && !ret) { | ||
71 | ret = m_layers[num]->getItemBelow(item); | ||
72 | num--; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | return ret; | ||
77 | } | ||
78 | |||
79 | XLayerItem *MultLayers::getItemAbove(XLayerItem &item) { | ||
80 | XLayer &curr_layer = item.getLayer(); | ||
81 | |||
82 | // assume that the LayerItem does exist in a layer. | ||
83 | XLayerItem *ret = curr_layer.getItemAbove(item); | ||
84 | |||
85 | if (!ret) { | ||
86 | ret = getLowestItemAboveLayer(curr_layer.getLayerNum()); | ||
87 | } | ||
88 | |||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | void MultLayers::addToTop(XLayerItem &item, int layernum) { | ||
93 | if (layernum < 0) | ||
94 | layernum = 0; | ||
95 | else if (layernum >= static_cast<signed>(m_layers.size())) | ||
96 | layernum = m_layers.size()-1; | ||
97 | |||
98 | m_layers[layernum]->insert(item); | ||
99 | restack(); | ||
100 | } | ||
101 | |||
102 | |||
103 | // raise the whole layer | ||
104 | void MultLayers::raise(XLayer &layer) { | ||
105 | int layernum = layer.getLayerNum(); | ||
106 | if (layernum >= static_cast<signed>(m_layers.size() - 1)) | ||
107 | // already on top | ||
108 | return; | ||
109 | |||
110 | // not yet implemented | ||
111 | } | ||
112 | |||
113 | // lower the whole layer | ||
114 | void MultLayers::lower(XLayer &layer) { | ||
115 | int layernum = layer.getLayerNum(); | ||
116 | if (layernum == 0) | ||
117 | // already on bottom | ||
118 | return; | ||
119 | |||
120 | // not yet implemented | ||
121 | } | ||
122 | |||
123 | /* raise the item one level */ | ||
124 | void MultLayers::raiseLayer(XLayerItem &item) { | ||
125 | // get the layer it is in | ||
126 | XLayer &curr_layer = item.getLayer(); | ||
127 | moveToLayer(item, curr_layer.getLayerNum()-1); | ||
128 | } | ||
129 | |||
130 | /* raise the item one level */ | ||
131 | void MultLayers::lowerLayer(XLayerItem &item) { | ||
132 | // get the layer it is in | ||
133 | XLayer &curr_layer = item.getLayer(); | ||
134 | moveToLayer(item, curr_layer.getLayerNum()+1); | ||
135 | } | ||
136 | |||
137 | void MultLayers::moveToLayer(XLayerItem &item, int layernum) { | ||
138 | // get the layer it is in | ||
139 | XLayer &curr_layer = item.getLayer(); | ||
140 | |||
141 | // do nothing if the item already is in the requested layer | ||
142 | if (curr_layer.getLayerNum() == layernum) | ||
143 | return; | ||
144 | |||
145 | // clamp layer number | ||
146 | if (layernum < 0) | ||
147 | layernum = 0; | ||
148 | else if (layernum >= static_cast<signed>(m_layers.size())) | ||
149 | layernum = m_layers.size()-1; | ||
150 | // remove item from old layer and insert it into the | ||
151 | item.setLayer(*m_layers[layernum]); | ||
152 | } | ||
153 | |||
154 | void MultLayers::restack() { | ||
155 | if (!isUpdatable()) | ||
156 | return; | ||
157 | |||
158 | int layernum=0, winnum=0, size = this->size(); | ||
159 | |||
160 | Window *winlist = new Window[size]; | ||
161 | for (layernum=0; layernum < static_cast<signed>(m_layers.size()); layernum++) { | ||
162 | |||
163 | XLayer::ItemList::iterator it = m_layers[layernum]->getItemList().begin(); | ||
164 | XLayer::ItemList::iterator it_end = m_layers[layernum]->getItemList().end(); | ||
165 | |||
166 | // add all windows from each layeritem in each layer | ||
167 | for (; it != it_end; ++it) { | ||
168 | XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin(); | ||
169 | XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end(); | ||
170 | for (; wit != wit_end; ++wit) { | ||
171 | if ((*wit)->window()) | ||
172 | winlist[winnum++] = (*wit)->window(); | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | |||
177 | XRestackWindows(FbTk::App::instance()->display(), winlist, winnum); | ||
178 | |||
179 | delete [] winlist; | ||
180 | } | ||
181 | |||
182 | int MultLayers::size() { | ||
183 | int i = 0, num = 0; | ||
184 | for (; i < static_cast<signed>(m_layers.size()); i++) { | ||
185 | num += m_layers[i]->countWindows(); | ||
186 | } | ||
187 | return num; | ||
188 | } | ||
189 | |||
190 | XLayer *MultLayers::getLayer(size_t num) { | ||
191 | if (num >= m_layers.size()) | ||
192 | return 0; | ||
193 | return m_layers[num]; | ||
194 | } | ||
195 | |||
196 | const XLayer *MultLayers::getLayer(size_t num) const { | ||
197 | if (num >= m_layers.size()) | ||
198 | return 0; | ||
199 | return m_layers[num]; | ||
200 | } | ||
201 | |||