MyGUI  3.0.1
MyGUI_DDContainer.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_DDContainer.h"
25 #include "MyGUI_InputManager.h"
26 #include "MyGUI_LayerManager.h"
27 
28 namespace MyGUI
29 {
30 
32  mDropResult(false),
33  mNeedDrop(false),
34  mStartDrop(false),
35  mOldDrop(nullptr),
36  mCurrentSender(nullptr),
37  mDropSenderIndex(ITEM_NONE),
38  mDropItem(nullptr),
39  mNeedDragDrop(false),
40  mReseiverContainer(nullptr)
41  {
42  }
43 
44  void DDContainer::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name)
45  {
46  Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name);
47 
48  initialiseWidgetSkin(_info);
49  }
50 
52  {
53  shutdownWidgetSkin();
54  }
55 
57  {
58  shutdownWidgetSkin();
60  initialiseWidgetSkin(_info);
61  }
62 
63  void DDContainer::initialiseWidgetSkin(ResourceSkin* _info)
64  {
65  }
66 
67  void DDContainer::shutdownWidgetSkin()
68  {
69  }
70 
71  void DDContainer::onMouseButtonPressed(int _left, int _top, MouseButton _id)
72  {
73  // смещение внутри виджета, куда кликнули мышкой
75 
76  mouseButtonPressed(_id);
77 
78  Base::onMouseButtonPressed(_left, _top, _id);
79  }
80 
81  void DDContainer::onMouseButtonReleased(int _left, int _top, MouseButton _id)
82  {
84 
85  Base::onMouseButtonReleased(_left, _top, _id);
86  }
87 
88  void DDContainer::onMouseDrag(int _left, int _top)
89  {
90  mouseDrag();
91 
92  Base::onMouseDrag(_left, _top);
93  }
94 
96  {
97  if (MouseButton::Left == _id)
98  {
99  // сбрасываем инфу для дропа
100  mDropResult = false;
101  mOldDrop = nullptr;
102  mDropInfo.reset();
103  mReseiverContainer = nullptr;
104 
105  // сбрасываем, чтобы обновился дропный виджет
106  mCurrentSender = nullptr;
107  mStartDrop = false;
108 
109  }
110  // если нажата другая клавиша и был дроп то сбрасываем
111  else
112  {
113  endDrop(true);
114  }
115  }
116 
118  {
119  if (MouseButton::Left == _id)
120  {
121  endDrop(false);
122  }
123  }
124 
126  {
127  // нужно ли обновить данные
128  bool update = false;
129 
130  // первый раз дропаем елемент
132  {
133  mStartDrop = true;
134  mNeedDrop = false;
135  update = true;
136  // запрос на нужность дропа по индексу
137  mDropInfo.set(this, mDropSenderIndex, nullptr, ITEM_NONE);
138  mReseiverContainer = nullptr;
139 
141 
142  if (mNeedDrop)
143  {
145  setEnableToolTip(false);
146  }
147  else
148  {
149  // сбрасываем фокус мыши (не обязательно)
151  }
152  }
153 
154  // дроп не нужен
155  if (!mNeedDrop)
156  {
157  return;
158  }
159 
160  // делаем запрос, над кем наша мыша
163 
164  updateDropItems();
165 
166  // если равно, значит уже спрашивали
167  if (mOldDrop == item) return;
168  mOldDrop = item;
169 
170  // сбрасываем старую подсветку
172 
173  mDropResult = false;
174  mReseiverContainer = nullptr;
175  Widget* receiver = nullptr;
176  size_t receiver_index = ITEM_NONE;
177  // есть виджет под нами
178  if (item)
179  {
180  // делаем запрос на индекс по произвольному виджету
181  item->_getContainer(receiver, receiver_index);
182  // работаем только с контейнерами
183  if (receiver && receiver->isType<DDContainer>())
184  {
185  // подписываемся на информацию о валидности дропа
186  mReseiverContainer = static_cast<DDContainer*>(receiver);
188 
189  // делаем запрос на возможность дропа
190  mDropInfo.set(this, mDropSenderIndex, mReseiverContainer, receiver_index);
191 
193 
194  // устанавливаем новую подсветку
196  }
197  else
198  {
199  mDropInfo.set(this, mDropSenderIndex, nullptr, ITEM_NONE);
200  }
201  }
202  // нет виджета под нами
203  else
204  {
205  mDropInfo.set(this, mDropSenderIndex, nullptr, ITEM_NONE);
206  }
207 
208  DDItemState state;
209 
211  data.update = update;
212 
213  if (receiver == nullptr)
214  {
215  data.accept = false;
216  data.refuse = false;
217  state = DDItemState::Miss;
218  }
219  else if (mDropResult)
220  {
221  data.accept = true;
222  data.refuse = false;
223  state = DDItemState::Accept;
224  }
225  else
226  {
227  data.accept = false;
228  data.refuse = true;
229  state = DDItemState::Refuse;
230  }
231 
232  updateDropItemsState(data);
233 
234  eventChangeDDState(this, state);
235  }
236 
237  void DDContainer::endDrop(bool _reset)
238  {
239  if (mStartDrop)
240  {
241  removeDropItems();
242 
243  // сбрасываем старую подсветку
245 
246  if (_reset) mDropResult = false;
249  setEnableToolTip(true);
250 
251  // сбрасываем инфу для дропа
252  mStartDrop = false;
253  mDropResult = false;
254  mNeedDrop = false;
255  mOldDrop = nullptr;
256  mDropInfo.reset();
257  mReseiverContainer = nullptr;
259  }
260  }
261 
263  {
264  mDropItem = nullptr;
265  }
266 
268  {
269 
270  if (mDropItem == nullptr)
271  {
273  }
274 
276 
277  if (mDropItem)
278  {
280  mDropItem->setVisible(true);
281  }
282  }
283 
285  {
286  eventUpdateDropState(this, mDropItem, _state);
287  }
288 
290  {
291  mouseDrag();
292  }
293 
294  void DDContainer::_getContainer(Widget*& _container, size_t& _index)
295  {
296  _container = this;
297  _index = ITEM_NONE;
298  }
299 
300  void DDContainer::setProperty(const std::string& _key, const std::string& _value)
301  {
302  if (_key == "DDContainer_NeedDragDrop") setNeedDragDrop(utility::parseValue<bool>(_value));
303  else
304  {
305  Base::setProperty(_key, _value);
306  return;
307  }
308  eventChangeProperty(this, _key, _value);
309  }
310 
311 } // namespace MyGUI