13#include <wx/wupdlock.h>
20 : wxCommandEvent(eventType, winid)
78 event.SetEventObject(
this);
79 target->GetEventHandler()->ProcessEvent(event);
84 auto parent = GetParent();
88 if(
auto sizer = parent->GetSizer())
90 for(
size_t i = 0, count = sizer->GetItemCount(); i < count; ++i)
92 if(sizer->GetItem(i)->GetWindow() ==
this)
93 return static_cast<int>(i);
101 const auto keyCode = evt.GetKeyCode();
102 if(evt.AltDown() && (keyCode == WXK_DOWN || keyCode == WXK_UP))
106 static long lastEventTimestamp = 0;
107 if(lastEventTimestamp == evt.GetTimestamp())
109 lastEventTimestamp = evt.GetTimestamp();
113 if(sourceIndex == -1)
119 const auto targetIndex = std::clamp(
120 keyCode == WXK_DOWN ? sourceIndex + 1 : sourceIndex - 1,
122 static_cast<int>(GetParent()->GetSizer()->GetItemCount()) - 1
124 if(sourceIndex != targetIndex)
143 if(
auto parent = GetParent())
145 wxWindowUpdateLocker freeze(
this);
185 auto parent = GetParent();
190 Move(GetParent()->ScreenToClient(newPosition));
192 if(
auto boxSizer =
dynamic_cast<wxBoxSizer*
>(parent->GetSizer()))
194 if(boxSizer->GetOrientation() == wxVERTICAL)
200 if(GetPosition().y < boxSizer->GetItem(
mSourceIndex)->GetPosition().y)
205 const auto item = boxSizer->GetItem(i);
207 if(GetRect().GetTop() <= item->GetPosition().y + item->GetSize().y / 2)
217 for(
int i =
static_cast<int>(boxSizer->GetItemCount()) - 1; i >
mSourceIndex; --i)
219 const auto item = boxSizer->GetItem(i);
220 if(GetRect().GetBottom() >= item->GetPosition().y + item->GetSize().y / 2)
wxDEFINE_EVENT(EVT_MOVABLE_CONTROL_DRAG_STARTED, MovableControlEvent)
void SetTargetIndex(int index) noexcept
int GetSourceIndex() const noexcept
wxEvent * Clone() const override
int GetTargetIndex() const noexcept
void SetSourceIndex(int index) noexcept
MovableControlEvent(wxEventType eventType, int winid=0)
void OnMouseCaptureLost(wxMouseCaptureLostEvent &event)
void OnMove(wxMouseEvent &evt)
void Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)
void OnKeyDown(wxKeyEvent &evt)
void OnMouseUp(wxMouseEvent &evt)
int FindIndexInParent() const
void ProcessDragEvent(wxWindow *target, wxEventType eventType)
void OnMouseDown(wxMouseEvent &evt)