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