aboutsummaryrefslogtreecommitdiff
path: root/src/Container.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Container.cc')
-rw-r--r--src/Container.cc32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/Container.cc b/src/Container.cc
index 3a53a4b..0c2ddd5 100644
--- a/src/Container.cc
+++ b/src/Container.cc
@@ -28,6 +28,8 @@
28#include "FbTk/EventManager.hh" 28#include "FbTk/EventManager.hh"
29#include "CompareWindow.hh" 29#include "CompareWindow.hh"
30 30
31#include <algorithm>
32
31Container::Container(const FbTk::FbWindow &parent): 33Container::Container(const FbTk::FbWindow &parent):
32 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), 34 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask),
33 m_align(RELATIVE), 35 m_align(RELATIVE),
@@ -113,35 +115,31 @@ void Container::insertItem(Item item, int pos) {
113} 115}
114 116
115void Container::moveItem(Item item, int movement) { 117void Container::moveItem(Item item, int movement) {
118
116 int index = find(item); 119 int index = find(item);
117 if (index < 0) 120 const int size = m_item_list.size();
121
122 if (index < 0 || (movement % size) == 0) {
118 return; 123 return;
124 }
119 125
120 int size = m_item_list.size();
121 int newindex = (index + movement) % size; 126 int newindex = (index + movement) % size;
122 if (newindex < 0) // neg wrap 127 if (newindex < 0) // neg wrap
123 newindex += size; 128 newindex += size;
124 129
125 if (newindex > index) // one smaller now 130 ItemList::iterator it = std::find(m_item_list.begin(),
126 --newindex; 131 m_item_list.end(),
127 132 item);
128 ItemList::iterator it = m_item_list.begin(); 133 m_item_list.erase(it);
129 for (; newindex > 0 && index > 0; ++it, --newindex, --index) { 134
135 for (it = m_item_list.begin(); newindex >= 0; ++it, --newindex) {
130 if (newindex == 0) { 136 if (newindex == 0) {
131 m_item_list.insert(it, item); 137 break;
132 ++newindex;
133 }
134
135 if (index == 0) {
136 m_item_list.erase(it);
137 --index;
138 } 138 }
139 } 139 }
140 140
141 m_item_list.insert(it, item); 141 m_item_list.insert(it, item);
142 insertItem(item, newindex);
143 repositionItems(); 142 repositionItems();
144
145} 143}
146 144
147// returns true if something was done 145// returns true if something was done