aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-11 15:28:33 (GMT)
committerfluxgen <fluxgen>2003-08-11 15:28:33 (GMT)
commit242798ae46270e31135faa8e06dab34652480686 (patch)
tree2ed24bbe39ef968a71e8090f4bfb324908ee5d83
parentb490cca0981e363609dc7fdf605716b509af6fa9 (diff)
downloadfluxbox_paul-242798ae46270e31135faa8e06dab34652480686.zip
fluxbox_paul-242798ae46270e31135faa8e06dab34652480686.tar.bz2
gui container
-rw-r--r--src/Container.cc186
-rw-r--r--src/Container.hh78
2 files changed, 264 insertions, 0 deletions
diff --git a/src/Container.cc b/src/Container.cc
new file mode 100644
index 0000000..0fff44a
--- /dev/null
+++ b/src/Container.cc
@@ -0,0 +1,186 @@
1// Container.cc
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: Container.cc,v 1.1 2003/08/11 15:28:33 fluxgen Exp $
24
25#include "FbTk/Button.hh"
26#include "Container.hh"
27
28#include "FbTk/EventManager.hh"
29
30Container::Container(const FbTk::FbWindow &parent):
31 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), m_selected(0) {
32
33 FbTk::EventManager::instance()->add(*this, *this);
34}
35
36Container::~Container() {
37
38}
39
40void Container::resize(unsigned int width, unsigned int height) {
41 // do we need to resize?
42 if (FbTk::FbWindow::width() == width &&
43 FbTk::FbWindow::height() == height)
44 return;
45
46 FbTk::FbWindow::resize(width, height);
47 repositionItems();
48}
49
50void Container::moveResize(int x, int y,
51 unsigned int width, unsigned int height) {
52 FbTk::FbWindow::moveResize(x, y, width, height);
53 repositionItems();
54}
55
56void Container::insertItems(ItemList &item_list, int pos) {
57
58 // make sure all items have parent == this
59 ItemList::iterator it = m_item_list.begin();
60 ItemList::iterator it_end = m_item_list.end();
61 for (; it != it_end; ++it) {
62 if ((*it)->window().parent() != this)
63 return;
64 }
65
66 if (pos > size() || pos < 0) {
67 // insert last
68 m_item_list.splice(m_item_list.end(), item_list);
69 } else if (pos == 0) {
70 // insert first
71 m_item_list.splice(m_item_list.begin(), item_list);
72 } else {
73 // find insert point
74 for (it = m_item_list.begin(); pos != 0; ++it, --pos)
75 continue;
76 m_item_list.splice(it, item_list);
77 }
78
79 m_item_list.unique();
80
81 // update position
82 repositionItems();
83}
84
85void Container::insertItem(Item item, int pos) {
86 if (find(item) != -1)
87 return;
88
89 // it must be a child of this window
90 if (item->window().parent() != this)
91 return;
92
93 if (pos >= size() || pos < 0) {
94 m_item_list.push_back(item);
95 } else if (pos == 0) {
96 m_item_list.push_front(item);
97 } else {
98 ItemList::iterator it = m_item_list.begin();
99 for (; pos != 0; ++it, --pos)
100 continue;
101
102 m_item_list.insert(it, item);
103 }
104
105 // make sure we dont have duplicate items
106 m_item_list.unique();
107
108 repositionItems();
109}
110
111void Container::removeItem(int index) {
112 if (index < 0 || index > size())
113 return;
114
115 ItemList::iterator it = m_item_list.begin();
116 for (; index != 0; ++it, --index)
117 continue;
118
119 if (*it == selected())
120 m_selected = 0;
121
122 m_item_list.erase(it);
123
124 repositionItems();
125}
126
127void Container::removeAll() {
128 m_selected = 0;
129 m_item_list.clear();
130 clear();
131
132}
133
134int Container::find(Item item) {
135 ItemList::iterator it = m_item_list.begin();
136 ItemList::iterator it_end = m_item_list.end();
137 int index = 0;
138 for (; it != it_end; ++it, ++index) {
139 if ((*it) == item)
140 break;
141 }
142
143 if (it == it_end)
144 return -1;
145
146 return index;
147}
148
149void Container::setSelected(int pos) {
150 if (pos < 0 || pos >= size())
151 m_selected = 0;
152 else {
153 ItemList::iterator it = m_item_list.begin();
154 for (; pos != 0; --pos, ++it)
155 continue;
156 m_selected = *it;
157 if (m_selected)
158 m_selected->clear();
159 }
160
161}
162
163void Container::exposeEvent(XExposeEvent &event) {
164 clear();
165}
166
167void Container::repositionItems() {
168 if (size() == 0)
169 return;
170
171 //!! TODO vertical position
172
173 const int max_width_per_client = maxWidthPerClient();
174
175 ItemList::iterator it = m_item_list.begin();
176 const ItemList::iterator it_end = m_item_list.end();
177 int next_x = 0;
178 for (; it != it_end; ++it, next_x += max_width_per_client) {
179 // resize each clients including border in size
180 (*it)->moveResize(next_x - (*it)->window().borderWidth(),
181 (*it)->window().borderWidth(),
182 max_width_per_client - (*it)->window().borderWidth(),
183 height() + (*it)->window().borderWidth());
184 (*it)->clear();
185 }
186}
diff --git a/src/Container.hh b/src/Container.hh
new file mode 100644
index 0000000..474e55b
--- /dev/null
+++ b/src/Container.hh
@@ -0,0 +1,78 @@
1// Container.hh
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: Container.hh,v 1.1 2003/08/11 15:28:33 fluxgen Exp $
24
25#ifndef CONTAINER_HH
26#define CONTAINER_HH
27
28#include "FbTk/FbWindow.hh"
29#include "FbTk/EventHandler.hh"
30#include "FbTk/NotCopyable.hh"
31
32#include <list>
33
34class ContainerTheme;
35
36namespace FbTk {
37class Button;
38};
39
40class Container:public FbTk::FbWindow, public FbTk::EventHandler, private FbTk::NotCopyable {
41public:
42 typedef FbTk::Button * Item;
43 typedef std::list<Item> ItemList;
44
45 explicit Container(const FbTk::FbWindow &parent);
46 virtual ~Container();
47
48 // manipulators
49
50 void resize(unsigned int width, unsigned int height);
51 void moveResize(int x, int y,
52 unsigned int width, unsigned int height);
53
54 void insertItems(ItemList &list, int position=-1);
55 void insertItem(Item item, int pos = -1);
56 void removeItem(int item);
57 void removeAll();
58 int find(Item item);
59 void setSelected(int index);
60
61 // event handler
62 void exposeEvent(XExposeEvent &event);
63
64 // accessors
65 int size() const { return m_item_list.size(); }
66 const Item selected() const { return m_selected; }
67 Item selected() { return m_selected; }
68 unsigned int maxWidthPerClient() const { return (size() == 0 ? width() : width()/size()); }
69 unsigned int maxHeightPerClient() const { return (size() == 0 ? height() : height()/size()); }
70private:
71 void repositionItems();
72
73 ItemList m_item_list;
74 Item m_selected;
75};
76
77#endif // CONTAINER_HH
78