diff options
author | fluxgen <fluxgen> | 2003-02-03 13:46:13 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-02-03 13:46:13 (GMT) |
commit | 76d490dcbb6156d44fce9986e9c557cb67f36e69 (patch) | |
tree | d74d19ddfc9bcb4757f61c1cfbdb65c6ab7fbfef /src | |
parent | 7e2187d8c5cb6c37d27be6794072d61abd7f1b24 (diff) | |
download | fluxbox-76d490dcbb6156d44fce9986e9c557cb67f36e69.zip fluxbox-76d490dcbb6156d44fce9986e9c557cb67f36e69.tar.bz2 |
needs cleaning
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/MultLayers.cc | 131 |
1 files changed, 64 insertions, 67 deletions
diff --git a/src/FbTk/MultLayers.cc b/src/FbTk/MultLayers.cc index 7f8f584..b552b5c 100644 --- a/src/FbTk/MultLayers.cc +++ b/src/FbTk/MultLayers.cc | |||
@@ -20,46 +20,51 @@ | |||
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: MultLayers.cc,v 1.3 2003/02/02 16:32:41 rathnor Exp $ | 23 | // $Id: MultLayers.cc,v 1.4 2003/02/03 13:46:13 fluxgen Exp $ |
24 | 24 | ||
25 | #include "MultLayers.hh" | 25 | #include "MultLayers.hh" |
26 | #include "XLayer.hh" | 26 | #include "XLayer.hh" |
27 | #include "XLayerItem.hh" | 27 | #include "XLayerItem.hh" |
28 | #include "App.hh" | 28 | #include "App.hh" |
29 | 29 | ||
30 | #include <iostream> | ||
31 | using namespace std; | ||
32 | |||
30 | using namespace FbTk; | 33 | using namespace FbTk; |
31 | 34 | ||
32 | MultLayers::MultLayers(int numlayers) : | 35 | MultLayers::MultLayers(int numlayers) { |
33 | m_numlayers(numlayers), m_layers(numlayers) { | 36 | for (int i=0; i < numlayers; ++i) |
34 | for (int i=0; i < numlayers; i++) { | 37 | m_layers.push_back(new XLayer(*this, i)); |
35 | m_layers[i] = new XLayer(*this, i); | ||
36 | } | ||
37 | } | 38 | } |
38 | 39 | ||
39 | MultLayers::~MultLayers() { | 40 | MultLayers::~MultLayers() { |
40 | // TODO delete all the layers | 41 | while (!m_layers.empty()) { |
42 | delete m_layers.back(); | ||
43 | m_layers.pop_back(); | ||
44 | } | ||
41 | } | 45 | } |
42 | 46 | ||
43 | 47 | ||
44 | XLayerItem *MultLayers::getLowestItemAboveLayer(int layernum) { | 48 | XLayerItem *MultLayers::getLowestItemAboveLayer(int layernum) { |
45 | if (layernum >= (m_numlayers) || layernum <= 0) | 49 | if (layernum >= m_layers.size() || layernum <= 0) |
46 | return 0; | 50 | return 0; |
47 | 51 | ||
48 | layernum--; // next one up | 52 | layernum--; // next one up |
49 | XLayerItem *item = 0; | 53 | XLayerItem *item = 0; |
50 | while (layernum >= 0 && (item = m_layers[layernum]->getLowestItem()) == 0) layernum--; | 54 | while (layernum >= 0 && (item = m_layers[layernum]->getLowestItem()) == 0) |
55 | layernum--; | ||
51 | return item; | 56 | return item; |
52 | 57 | ||
53 | } | 58 | } |
54 | 59 | ||
55 | XLayerItem *MultLayers::getItemBelow(XLayerItem &item) { | 60 | XLayerItem *MultLayers::getItemBelow(XLayerItem &item) { |
56 | XLayer *curr_layer = item.getLayer(); | 61 | XLayer &curr_layer = item.getLayer(); |
57 | cerr<<"getItemBelow xlayer = "<<hex<<curr_layer<<endl; | 62 | |
58 | // assume that the LayerItem does exist in a layer. | 63 | // assume that the LayerItem does exist in a layer. |
59 | XLayerItem *ret = curr_layer->getItemBelow(item); | 64 | XLayerItem *ret = curr_layer.getItemBelow(item); |
60 | 65 | ||
61 | if (!ret) { | 66 | if (ret == 0) { |
62 | int num = curr_layer->getLayerNum()-1; | 67 | int num = curr_layer.getLayerNum()-1; |
63 | while (num >= 0 && !ret) { | 68 | while (num >= 0 && !ret) { |
64 | ret = m_layers[num]->getItemBelow(item); | 69 | ret = m_layers[num]->getItemBelow(item); |
65 | num--; | 70 | num--; |
@@ -70,14 +75,14 @@ XLayerItem *MultLayers::getItemBelow(XLayerItem &item) { | |||
70 | } | 75 | } |
71 | 76 | ||
72 | XLayerItem *MultLayers::getItemAbove(XLayerItem &item) { | 77 | XLayerItem *MultLayers::getItemAbove(XLayerItem &item) { |
73 | XLayer *curr_layer = item.getLayer(); | 78 | XLayer &curr_layer = item.getLayer(); |
74 | 79 | ||
75 | // assume that the LayerItem does exist in a layer. | 80 | // assume that the LayerItem does exist in a layer. |
76 | XLayerItem *ret = curr_layer->getItemAbove(item); | 81 | XLayerItem *ret = curr_layer.getItemAbove(item); |
77 | 82 | ||
78 | if (!ret) { | 83 | if (!ret) { |
79 | ret = getLowestItemAboveLayer(curr_layer->getLayerNum()); | 84 | ret = getLowestItemAboveLayer(curr_layer.getLayerNum()); |
80 | } | 85 | } |
81 | 86 | ||
82 | return ret; | 87 | return ret; |
83 | } | 88 | } |
@@ -85,84 +90,76 @@ XLayerItem *MultLayers::getItemAbove(XLayerItem &item) { | |||
85 | void MultLayers::addToTop(XLayerItem &item, int layernum) { | 90 | void MultLayers::addToTop(XLayerItem &item, int layernum) { |
86 | if (layernum < 0) | 91 | if (layernum < 0) |
87 | layernum = 0; | 92 | layernum = 0; |
88 | else if (layernum >= m_numlayers) | 93 | else if (layernum >= m_layers.size()) |
89 | layernum = m_numlayers-1; | 94 | layernum = m_layers.size()-1; |
90 | 95 | ||
91 | m_layers[layernum]->insert(item); | 96 | m_layers[layernum]->insert(item); |
92 | restack(); | 97 | restack(); |
93 | } | 98 | } |
94 | 99 | ||
95 | void MultLayers::remove(XLayerItem &item) { | ||
96 | XLayer *curr_layer = item.getLayer(); | ||
97 | if (!curr_layer || curr_layer->getLayerNum() < 0 || curr_layer->getLayerNum() >= m_numlayers) { | ||
98 | // do nothing | ||
99 | return; | ||
100 | } | ||
101 | curr_layer->remove(item); | ||
102 | } | ||
103 | |||
104 | /* raise the item one level */ | 100 | /* raise the item one level */ |
105 | void MultLayers::raise(XLayerItem &item) { | 101 | void MultLayers::raise(XLayerItem &item) { |
106 | // get the layer it is in | 102 | // get the layer it is in |
107 | XLayer *curr_layer = item.getLayer(); | 103 | XLayer &curr_layer = item.getLayer(); |
108 | moveToLayer(item, curr_layer->getLayerNum()-1); | 104 | moveToLayer(item, curr_layer.getLayerNum()-1); |
109 | } | ||
110 | |||
111 | /* lower the item one level */ | ||
112 | void MultLayers::lower(XLayerItem &item) { | ||
113 | // get the layer it is in | ||
114 | XLayer *curr_layer = item.getLayer(); | ||
115 | moveToLayer(item, curr_layer->getLayerNum()+1); | ||
116 | } | 105 | } |
117 | 106 | ||
118 | void MultLayers::moveToLayer(XLayerItem &item, int layernum) { | 107 | void MultLayers::moveToLayer(XLayerItem &item, int layernum) { |
119 | // get the layer it is in | 108 | // get the layer it is in |
120 | XLayer *curr_layer = item.getLayer(); | 109 | XLayer &curr_layer = item.getLayer(); |
121 | if (!curr_layer) { | 110 | |
122 | addToTop(item, layernum); | 111 | // do nothing if the item already is in the requested layer |
123 | return; | 112 | if (curr_layer.getLayerNum() == layernum) |
124 | } | ||
125 | if (curr_layer->getLayerNum() == layernum ) | ||
126 | // do nothing | ||
127 | return; | 113 | return; |
128 | 114 | ||
115 | // clamp layer number | ||
129 | if (layernum < 0) | 116 | if (layernum < 0) |
130 | layernum = 0; | 117 | layernum = 0; |
131 | else if (layernum >= m_numlayers) | 118 | else if (layernum >= m_layers.size()) |
132 | layernum = m_numlayers-1; | 119 | layernum = m_layers.size()-1; |
133 | 120 | // remove item from old layer and insert it into the | |
134 | curr_layer->remove(item); | 121 | item.setLayer(*m_layers[layernum]); |
122 | curr_layer.remove(item); | ||
135 | m_layers[layernum]->insert(item); | 123 | m_layers[layernum]->insert(item); |
136 | } | 124 | } |
137 | 125 | ||
138 | void MultLayers::restack() { | 126 | void MultLayers::restack() { |
139 | int i=0, j=0, size=0; | 127 | size_t winlist_size=0; |
140 | for (; i < m_numlayers; i++) { | 128 | for (size_t layer=0; layer < m_layers.size(); layer++) { |
141 | size += m_layers[i]->countWindows(); | 129 | winlist_size += m_layers[layer]->countWindows(); |
142 | } | 130 | } |
143 | 131 | ||
144 | Window *winlist = new Window[size]; | 132 | Window *winlist = new Window[winlist_size]; |
145 | for (i=0; i < m_numlayers; i++) { | 133 | for (size_t layer=0, window=0; layer < m_layers.size(); layer++) { |
146 | 134 | ||
147 | XLayer::ItemList::iterator it = m_layers[i]->getItemList().begin(); | 135 | XLayer::ItemList::iterator item_it = m_layers[layer]->getItemList().begin(); |
148 | XLayer::ItemList::iterator it_end = m_layers[i]->getItemList().end(); | 136 | XLayer::ItemList::iterator item_it_end = m_layers[layer]->getItemList().end(); |
149 | 137 | for (; item_it != item_it_end; ++item_it, window++) | |
150 | for (; it != it_end; ++it) { | 138 | winlist[window] = (*item_it)->window(); |
151 | XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin(); | ||
152 | XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end(); | ||
153 | for (; wit != wit_end; ++wit, j++) { | ||
154 | winlist[j] = (*wit); | ||
155 | } | ||
156 | } | ||
157 | } | 139 | } |
158 | 140 | ||
159 | XRestackWindows(FbTk::App::instance()->display(), winlist, size); | 141 | XRestackWindows(FbTk::App::instance()->display(), winlist, winlist_size); |
142 | |||
143 | delete[] winlist; | ||
160 | } | 144 | } |
161 | 145 | ||
162 | int MultLayers::size() { | 146 | int MultLayers::size() { |
163 | int i = 0, num = 0; | 147 | int i = 0, num = 0; |
164 | for (; i < m_numlayers; i++) { | 148 | for (; i < m_layers.size(); i++) { |
165 | num += m_layers[i]->countWindows(); | 149 | num += m_layers[i]->countWindows(); |
166 | } | 150 | } |
167 | return num; | 151 | return num; |
168 | } | 152 | } |
153 | |||
154 | XLayer *MultLayers::getLayer(size_t num) { | ||
155 | if (num >= m_layers.size()) | ||
156 | return 0; | ||
157 | return m_layers[num]; | ||
158 | } | ||
159 | |||
160 | const XLayer *MultLayers::getLayer(size_t num) const { | ||
161 | if (num >= m_layers.size()) | ||
162 | return 0; | ||
163 | return m_layers[num]; | ||
164 | } | ||
165 | |||