summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Container.cc63
-rw-r--r--src/Container.hh9
2 files changed, 54 insertions, 18 deletions
diff --git a/src/Container.cc b/src/Container.cc
index d3072a6..b6bc5b8 100644
--- a/src/Container.cc
+++ b/src/Container.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: Container.cc,v 1.8 2003/12/07 15:45:28 fluxgen Exp $ 23// $Id: Container.cc,v 1.9 2003/12/12 14:35:34 fluxgen Exp $
24 24
25#include "Container.hh" 25#include "Container.hh"
26 26
@@ -28,7 +28,10 @@
28#include "FbTk/EventManager.hh" 28#include "FbTk/EventManager.hh"
29 29
30Container::Container(const FbTk::FbWindow &parent): 30Container::Container(const FbTk::FbWindow &parent):
31 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), m_selected(0), 31 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask),
32 m_align(RELATIVE),
33 m_max_size_per_client(60),
34 m_selected(0),
32 m_update_lock(false) { 35 m_update_lock(false) {
33 FbTk::EventManager::instance()->add(*this, *this); 36 FbTk::EventManager::instance()->add(*this, *this);
34} 37}
@@ -161,6 +164,14 @@ void Container::setSelected(int pos) {
161 164
162} 165}
163 166
167void Container::setMaxSizePerClient(unsigned int size) {
168 m_max_size_per_client = size;
169}
170
171void Container::setAlignment(Container::Alignment a) {
172 m_align = a;
173}
174
164void Container::exposeEvent(XExposeEvent &event) { 175void Container::exposeEvent(XExposeEvent &event) {
165 if (!m_update_lock) 176 if (!m_update_lock)
166 clearArea(event.x, event.y, event.width, event.height); 177 clearArea(event.x, event.y, event.width, event.height);
@@ -182,15 +193,21 @@ void Container::repositionItems() {
182 193
183 int next_x = -borderW; // zero so the border of the first shows 194 int next_x = -borderW; // zero so the border of the first shows
184 int extra = 0; 195 int extra = 0;
185 for (; it != it_end; ++it, next_x += max_width_per_client + borderW + extra) { 196 int direction = 1;
197 if (alignment() == RIGHT) {
198 direction = -1;
199 next_x = width() - max_width_per_client + borderW;
200 }
201
202 for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) {
186 //!! TODO: check this more carefully, seems like error doesn't work with even numbers 203 //!! TODO: check this more carefully, seems like error doesn't work with even numbers
187 /* 204 /*
188 if (rounding_error != 0) { 205 if (rounding_error != 0) {
189 --rounding_error; 206 --rounding_error;
190 extra = 0; 207 extra = 0;
191 } else { 208 } else {
192 extra = 0; 209 extra = 0;
193 } 210 }
194 */ 211 */
195 // resize each clients including border in size 212 // resize each clients including border in size
196 (*it)->moveResize(next_x, 213 (*it)->moveResize(next_x,
@@ -199,17 +216,29 @@ void Container::repositionItems() {
199 height()); 216 height());
200 (*it)->clear(); 217 (*it)->clear();
201 } 218 }
219
202} 220}
203 221
204 222
205unsigned int Container::maxWidthPerClient() const { 223unsigned int Container::maxWidthPerClient() const {
206 int count = size(); 224 switch (alignment()) {
207 if (count == 0) 225 case RIGHT:
208 return width(); 226 case LEFT:
209 else { 227 return m_max_size_per_client;
210 int borderW = m_item_list.front()->borderWidth(); 228 break;
211 // there're count-1 borders to fit in with the windows 229 case RELATIVE:
212 // -> 1 per window plus end 230 int count = size();
213 return (width() - (count - 1) * borderW) / count; 231 if (count == 0)
232 return width();
233 else {
234 int borderW = m_item_list.front()->borderWidth();
235 // there're count-1 borders to fit in with the windows
236 // -> 1 per window plus end
237 return (width() - (count - 1) * borderW) / count;
238 }
239 break;
214 } 240 }
241
242 // this will never happen anyway
243 return 1;
215} 244}
diff --git a/src/Container.hh b/src/Container.hh
index 5f2ca4b..f620d3a 100644
--- a/src/Container.hh
+++ b/src/Container.hh
@@ -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: Container.hh,v 1.3 2003/09/08 16:28:32 fluxgen Exp $ 23// $Id: Container.hh,v 1.4 2003/12/12 14:35:34 fluxgen Exp $
24 24
25#ifndef CONTAINER_HH 25#ifndef CONTAINER_HH
26#define CONTAINER_HH 26#define CONTAINER_HH
@@ -33,6 +33,7 @@
33 33
34class Container:public FbTk::FbWindow, public FbTk::EventHandler, private FbTk::NotCopyable { 34class Container:public FbTk::FbWindow, public FbTk::EventHandler, private FbTk::NotCopyable {
35public: 35public:
36 enum Alignment { LEFT, RELATIVE, RIGHT };
36 typedef FbTk::FbWindow * Item; 37 typedef FbTk::FbWindow * Item;
37 typedef std::list<Item> ItemList; 38 typedef std::list<Item> ItemList;
38 39
@@ -51,6 +52,9 @@ public:
51 void removeAll(); 52 void removeAll();
52 int find(Item item); 53 int find(Item item);
53 void setSelected(int index); 54 void setSelected(int index);
55 void setMaxSizePerClient(unsigned int size);
56 void setAlignment(Alignment a);
57
54 /// force update 58 /// force update
55 inline void update() { repositionItems(); } 59 inline void update() { repositionItems(); }
56 /// so we can add items without having an graphic update for each item 60 /// so we can add items without having an graphic update for each item
@@ -60,6 +64,7 @@ public:
60 void exposeEvent(XExposeEvent &event); 64 void exposeEvent(XExposeEvent &event);
61 65
62 /// accessors 66 /// accessors
67 inline Alignment alignment() const { return m_align; }
63 inline int size() const { return m_item_list.size(); } 68 inline int size() const { return m_item_list.size(); }
64 inline const Item selected() const { return m_selected; } 69 inline const Item selected() const { return m_selected; }
65 inline Item selected() { return m_selected; } 70 inline Item selected() { return m_selected; }
@@ -70,6 +75,8 @@ public:
70private: 75private:
71 void repositionItems(); 76 void repositionItems();
72 77
78 Alignment m_align;
79 unsigned int m_max_size_per_client;
73 ItemList m_item_list; 80 ItemList m_item_list;
74 Item m_selected; 81 Item m_selected;
75 bool m_update_lock; 82 bool m_update_lock;