aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Layer.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Layer.hh')
-rw-r--r--src/FbTk/Layer.hh116
1 files changed, 45 insertions, 71 deletions
diff --git a/src/FbTk/Layer.hh b/src/FbTk/Layer.hh
index 5836c9c..6f8f184 100644
--- a/src/FbTk/Layer.hh
+++ b/src/FbTk/Layer.hh
@@ -1,7 +1,7 @@
1// Layer.hh for FbTk - fluxbox toolkit 1// Layer.hh for FbTk - fluxbox toolkit
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) 2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org)
3// and Simon Bowden (rathnor at users.sourceforge.net) 3// and Simon Bowden (rathnor at users.sourceforge.net)
4// 4//
5// Permission is hereby granted, free of charge, to any person obtaining a 5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"), 6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation 7// to deal in the Software without restriction, including without limitation
@@ -20,92 +20,66 @@
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#ifndef FBTK_LAYERTEMPLATE_HH 23#ifndef FBTK_XLAYER_HH
24#define FBTK_LAYERTEMPLATE_HH 24#define FBTK_XLAYER_HH
25 25
26#include <vector> 26#include <vector>
27#include <algorithm> 27#include <list>
28 28
29namespace FbTk { 29namespace FbTk {
30 30
31template <typename ItemType, typename Container = std::vector<ItemType *> > 31class MultLayers;
32class LayerBase { 32class LayerItem;
33public:
34 typedef Container ListType;
35 typedef typename Container::iterator iterator;
36 typedef typename Container::reverse_iterator reverse_iterator;
37 virtual ~LayerBase() { }
38 /// insert in top by default
39 virtual iterator insert(ItemType &item, unsigned int pos=0);
40 /// remove item from list
41 virtual void remove(ItemType &item);
42 /// move item to top
43 virtual void raise(ItemType &item);
44 /// move item to bottom
45 virtual void lower(ItemType &item);
46 /// @return number of elements in layer
47 size_t size() const { return m_list.size(); }
48 /// @return layer list
49 const ListType &itemList() const { return m_list; }
50 /// @return layer list
51 ListType &itemList() { return m_list; }
52protected:
53 virtual void restack();
54private:
55 ListType m_list;
56};
57 33
58template <typename ItemType, typename Container> 34class Layer {
59typename Container::iterator LayerBase<ItemType, Container>::insert(ItemType &item, unsigned int position) { 35public:
60 // make sure we don't alreay have it in the list
61 if (std::find(itemList().begin(), itemList().end(), &item) != itemList().end())
62 return m_list.end();
63 36
64 if (position > size()) 37 Layer(MultLayers &manager, int layernum);
65 position = size(); 38 ~Layer();
66 39
67 iterator it = m_list.begin(); 40 typedef std::list<LayerItem *> ItemList;
41 typedef std::list<LayerItem *>::iterator iterator;
68 42
69 for (unsigned int i=0; i<position; ++it, ++i) 43 //typedef std::list<LayerItem *>::reverse_iterator reverse_iterator;
70 continue;
71 44
72 m_list.insert(it, &item); 45 void setLayerNum(int layernum) { m_layernum = layernum; };
73 restack(); 46 int getLayerNum() { return m_layernum; };
74 return it++; 47 // Put all items on the same layer (called when layer item added to)
75} 48 void alignItem(LayerItem &item);
49 int countWindows();
50 void stackBelowItem(LayerItem &item, LayerItem *above);
51 LayerItem *getLowestItem();
52 const ItemList &itemList() const { return m_items; }
53 ItemList &itemList() { return m_items; }
76 54
55 // we redefine these as Layer has special optimisations, and X restacking needs
56 iterator insert(LayerItem &item, unsigned int pos=0);
57 void remove(LayerItem &item);
77 58
78template <typename ItemType, typename Container> 59 // bring to top of layer
79void LayerBase<ItemType, Container>::remove(ItemType &item) { 60 void raise(LayerItem &item);
80 iterator it = std::find(itemList().begin(), itemList().end(), &item); 61 void lower(LayerItem &item);
81 if (it != itemList().end())
82 m_list.erase(it);
83}
84 62
85template <typename ItemType, typename Container> 63 // raise it, but don't make it permanent (i.e. restack will revert)
86void LayerBase<ItemType, Container>::raise(ItemType &item) { 64 void tempRaise(LayerItem &item);
87 if (&item == itemList().front()) // already at the bottom
88 return;
89 remove(item);
90 insert(item, 0);
91 restack();
92}
93 65
94template <typename ItemType, typename Container> 66 // send to next layer up
95void LayerBase<ItemType, Container>::lower(ItemType &item) { 67 void raiseLayer(LayerItem &item);
96 if (&item == itemList().back()) // already at the bottom 68 void lowerLayer(LayerItem &item);
97 return; 69 void moveToLayer(LayerItem &item, int layernum);
98 remove(item);
99 insert(item, size());
100 restack();
101}
102 70
103template <typename ItemType, typename Container> 71 static void restack(const std::vector<Layer*>& layers);
104void LayerBase<ItemType, Container>::restack() {
105}
106 72
73private:
74 void restack();
75 void restackAndTempRaise(LayerItem &item);
107 76
108} // end namespace FbTk 77 MultLayers &m_manager;
78 int m_layernum;
79 bool m_needs_restack;
80 ItemList m_items;
81};
109 82
83} // namespace FbTk
110 84
111#endif // FBTK_LAYERTEMPLATE_HH 85#endif // FBTK_XLAYER_HH