Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MovableControl Class Reference

#include <MovableControl.h>

Inheritance diagram for MovableControl:
[legend]
Collaboration diagram for MovableControl:
[legend]

Public Member Functions

 MovableControl ()=default
 
 MovableControl (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)
 
void Create (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)
 
void ProcessDragEvent (wxWindow *target, wxEventType eventType)
 
int FindIndexInParent () const
 

Private Member Functions

void OnKeyDown (wxKeyEvent &evt)
 
void OnMouseCaptureLost (wxMouseCaptureLostEvent &event)
 
void DragFinished ()
 
void OnMouseDown (wxMouseEvent &evt)
 
void OnMouseUp (wxMouseEvent &evt)
 
void OnMove (wxMouseEvent &evt)
 

Private Attributes

bool mDragging { false }
 
wxPoint mInitialPosition
 
int mTargetIndex { -1 }
 
int mSourceIndex { -1 }
 

Detailed Description

Definition at line 43 of file MovableControl.h.

Constructor & Destructor Documentation

◆ MovableControl() [1/2]

MovableControl::MovableControl ( )
default

◆ MovableControl() [2/2]

MovableControl::MovableControl ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxString &  name = wxPanelNameStr 
)

Definition at line 48 of file MovableControl.cpp.

54{
55 Create(parent, id, pos, size, style, name);
56}
wxString name
Definition: TagsEditor.cpp:166
void Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)

References Create(), name, size, and anonymous_namespace{AudacityDontAskAgainMessageDialog.cpp}::style.

Here is the call graph for this function:

Member Function Documentation

◆ Create()

void MovableControl::Create ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxString &  name = wxPanelNameStr 
)

Definition at line 58 of file MovableControl.cpp.

64{
65 wxWindow::Create(parent, id, pos, size, style, name);
66 Bind(wxEVT_LEFT_DOWN, &MovableControl::OnMouseDown, this);
67 Bind(wxEVT_LEFT_UP, &MovableControl::OnMouseUp, this);
68 Bind(wxEVT_MOTION, &MovableControl::OnMove, this);
69 Bind(wxEVT_KEY_DOWN, &MovableControl::OnKeyDown, this);
70 Bind(wxEVT_MOUSE_CAPTURE_LOST, &MovableControl::OnMouseCaptureLost, this);
71}
void OnMouseCaptureLost(wxMouseCaptureLostEvent &event)
void OnMove(wxMouseEvent &evt)
void OnKeyDown(wxKeyEvent &evt)
void OnMouseUp(wxMouseEvent &evt)
void OnMouseDown(wxMouseEvent &evt)

References name, OnKeyDown(), OnMouseCaptureLost(), OnMouseDown(), OnMouseUp(), OnMove(), size, and anonymous_namespace{AudacityDontAskAgainMessageDialog.cpp}::style.

Referenced by anonymous_namespace{RealtimeEffectPanel.cpp}::RealtimeEffectControl::Create(), and MovableControl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DragFinished()

void MovableControl::DragFinished ( )
private

Definition at line 141 of file MovableControl.cpp.

142{
143 if(auto parent = GetParent())
144 {
145 wxWindowUpdateLocker freeze(this);
146 ProcessDragEvent(parent, EVT_MOVABLE_CONTROL_DRAG_FINISHED);
147 }
148 mDragging = false;
149}
void ProcessDragEvent(wxWindow *target, wxEventType eventType)

References mDragging, and ProcessDragEvent().

Referenced by OnMouseCaptureLost(), OnMouseDown(), and OnMouseUp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindIndexInParent()

int MovableControl::FindIndexInParent ( ) const

Definition at line 82 of file MovableControl.cpp.

83{
84 auto parent = GetParent();
85 if(!parent)
86 return -1;
87
88 if(auto sizer = parent->GetSizer())
89 {
90 for(size_t i = 0, count = sizer->GetItemCount(); i < count; ++i)
91 {
92 if(sizer->GetItem(i)->GetWindow() == this)
93 return static_cast<int>(i);
94 }
95 }
96 return -1;
97}

Referenced by OnKeyDown(), and OnMouseDown().

Here is the caller graph for this function:

◆ OnKeyDown()

void MovableControl::OnKeyDown ( wxKeyEvent &  evt)
private

Definition at line 99 of file MovableControl.cpp.

100{
101 const auto keyCode = evt.GetKeyCode();
102 if(evt.AltDown() && (keyCode == WXK_DOWN || keyCode == WXK_UP))
103 {
104#ifdef __WXOSX__
105 {//don't allow auto-repeats
106 static long lastEventTimestamp = 0;
107 if(lastEventTimestamp == evt.GetTimestamp())
108 return;//don't skip
109 lastEventTimestamp = evt.GetTimestamp();
110 }
111#endif
112 const auto sourceIndex = FindIndexInParent();
113 if(sourceIndex == -1)
114 {
115 evt.Skip();
116 return;
117 }
118
119 const auto targetIndex = std::clamp(
120 keyCode == WXK_DOWN ? sourceIndex + 1 : sourceIndex - 1,
121 0,
122 static_cast<int>(GetParent()->GetSizer()->GetItemCount()) - 1
123 );
124 if(sourceIndex != targetIndex)
125 {
126 mSourceIndex = sourceIndex;
127 mTargetIndex = targetIndex;
128 ProcessDragEvent(GetParent(), EVT_MOVABLE_CONTROL_DRAG_FINISHED);
129 }
130 }
131 else
132 evt.Skip();
133}
int FindIndexInParent() const

References FindIndexInParent(), mSourceIndex, mTargetIndex, and ProcessDragEvent().

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnMouseCaptureLost()

void MovableControl::OnMouseCaptureLost ( wxMouseCaptureLostEvent &  event)
private

Definition at line 135 of file MovableControl.cpp.

136{
137 if(mDragging)
138 DragFinished();
139}

References DragFinished(), and mDragging.

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnMouseDown()

void MovableControl::OnMouseDown ( wxMouseEvent &  evt)
private

Definition at line 151 of file MovableControl.cpp.

152{
153 if(mDragging)
154 {
155 DragFinished();
156 return;
157 }
158
160 if(mSourceIndex != -1)
161 {
162 CaptureMouse();
163 ProcessDragEvent(GetParent(), EVT_MOVABLE_CONTROL_DRAG_STARTED);
164
165 mInitialPosition = evt.GetPosition();
166 mDragging=true;
167 }
168}
wxPoint mInitialPosition

References DragFinished(), FindIndexInParent(), mDragging, mInitialPosition, mSourceIndex, mTargetIndex, and ProcessDragEvent().

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnMouseUp()

void MovableControl::OnMouseUp ( wxMouseEvent &  evt)
private

Definition at line 170 of file MovableControl.cpp.

171{
172 if(!mDragging)
173 return;
174
175 ReleaseMouse();
176
177 DragFinished();
178}

References DragFinished(), and mDragging.

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnMove()

void MovableControl::OnMove ( wxMouseEvent &  evt)
private

Definition at line 180 of file MovableControl.cpp.

181{
182 if(!mDragging)
183 return;
184
185 auto parent = GetParent();
186 if(!parent)
187 return;
188
189 wxPoint newPosition = wxGetMousePosition() - mInitialPosition;
190 Move(GetParent()->ScreenToClient(newPosition));
191
192 if(auto boxSizer = dynamic_cast<wxBoxSizer*>(parent->GetSizer()))
193 {
194 if(boxSizer->GetOrientation() == wxVERTICAL)
195 {
196 auto targetIndex = mSourceIndex;
197
198 //assuming that items are ordered from top to bottom (i > j <=> y(i) > y(j))
199 //compare wxSizerItem position with the current MovableControl position!
200 if(GetPosition().y < boxSizer->GetItem(mSourceIndex)->GetPosition().y)
201 {
202 //moving up
203 for(int i = 0; i < mSourceIndex; ++i)
204 {
205 const auto item = boxSizer->GetItem(i);
206
207 if(GetRect().GetTop() <= item->GetPosition().y + item->GetSize().y / 2)
208 {
209 targetIndex = i;
210 break;
211 }
212 }
213 }
214 else
215 {
216 //moving down
217 for(int i = static_cast<int>(boxSizer->GetItemCount()) - 1; i > mSourceIndex; --i)
218 {
219 const auto item = boxSizer->GetItem(i);
220 if(GetRect().GetBottom() >= item->GetPosition().y + item->GetSize().y / 2)
221 {
222 targetIndex = i;
223 break;
224 }
225 }
226 }
227
228 if(targetIndex != mTargetIndex)
229 {
230 mTargetIndex = targetIndex;
231 ProcessDragEvent(parent, EVT_MOVABLE_CONTROL_DRAG_POSITION);
232 }
233 }
234 }
235}

References mDragging, mInitialPosition, mSourceIndex, mTargetIndex, and ProcessDragEvent().

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessDragEvent()

void MovableControl::ProcessDragEvent ( wxWindow *  target,
wxEventType  eventType 
)

Definition at line 73 of file MovableControl.cpp.

74{
75 MovableControlEvent event(eventType);
76 event.SetSourceIndex(mSourceIndex);
77 event.SetTargetIndex(mTargetIndex);
78 event.SetEventObject(this);
79 target->GetEventHandler()->ProcessEvent(event);
80}

References mSourceIndex, and mTargetIndex.

Referenced by DragFinished(), OnKeyDown(), OnMouseDown(), and OnMove().

Here is the caller graph for this function:

Member Data Documentation

◆ mDragging

bool MovableControl::mDragging { false }
private

Definition at line 45 of file MovableControl.h.

Referenced by DragFinished(), OnMouseCaptureLost(), OnMouseDown(), OnMouseUp(), and OnMove().

◆ mInitialPosition

wxPoint MovableControl::mInitialPosition
private

Definition at line 46 of file MovableControl.h.

Referenced by OnMouseDown(), and OnMove().

◆ mSourceIndex

int MovableControl::mSourceIndex { -1 }
private

Definition at line 49 of file MovableControl.h.

Referenced by OnKeyDown(), OnMouseDown(), OnMove(), and ProcessDragEvent().

◆ mTargetIndex

int MovableControl::mTargetIndex { -1 }
private

Definition at line 48 of file MovableControl.h.

Referenced by OnKeyDown(), OnMouseDown(), OnMove(), and ProcessDragEvent().


The documentation for this class was generated from the following files: