Audacity 3.2.0
MovableControl.h
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file MovableControl.h
6
7 @author Vitaly Sverchinsky
8
9**********************************************************************/
10
11#pragma once
12
13#include <wx/event.h>
14#include <wx/window.h>
15
16//Event generated by MovableControl when item is picked,
17//dragged or dropped, extends wxCommandEvent interface
18//with "source" and "target" indices which denote the
19//initial and final element positions inside wxSizer (if present)
20class MovableControlEvent final : public wxCommandEvent
21{
22 int mSourceIndex{-1};
23 int mTargetIndex{-1};
24public:
25 MovableControlEvent(wxEventType eventType, int winid = 0);
26
27 void SetSourceIndex(int index) noexcept;
28 int GetSourceIndex() const noexcept;
29
30 void SetTargetIndex(int index) noexcept;
31 int GetTargetIndex() const noexcept;
32
33 wxEvent* Clone() const override;
34};
35
36wxDECLARE_EVENT(EVT_MOVABLE_CONTROL_DRAG_STARTED, MovableControlEvent);
37wxDECLARE_EVENT(EVT_MOVABLE_CONTROL_DRAG_POSITION, MovableControlEvent);
38wxDECLARE_EVENT(EVT_MOVABLE_CONTROL_DRAG_FINISHED, MovableControlEvent);
39
40//Base class for the controls that can be moved with drag-and-drop
41//action. Currently implementation is far from being generic and
42//can work only in pair with wxBoxSizer with wxVERTICAL layout.
43class MovableControl : public wxWindow
44{
45 bool mDragging { false };
47
48 int mTargetIndex { -1 };
49 int mSourceIndex { -1 };
50public:
51
52 MovableControl() = default;
53
54 MovableControl(wxWindow* parent,
55 wxWindowID id,
56 const wxPoint& pos = wxDefaultPosition,
57 const wxSize& size = wxDefaultSize,
58 long style = 0,
59 const wxString& name = wxPanelNameStr);
60
61 void Create(wxWindow* parent,
62 wxWindowID id,
63 const wxPoint& pos = wxDefaultPosition,
64 const wxSize& size = wxDefaultSize,
65 long style = 0,
66 const wxString& name = wxPanelNameStr);
67
68 void ProcessDragEvent(wxWindow* target, wxEventType eventType);
69
70 int FindIndexInParent() const;
71
72private:
73
74 void OnKeyDown(wxKeyEvent& evt);
75
76 void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
77
78 void DragFinished();
79
80 void OnMouseDown(wxMouseEvent& evt);
81
82 void OnMouseUp(wxMouseEvent& evt);
83
84 void OnMove(wxMouseEvent& evt);
85};
wxDECLARE_EVENT(EVT_MOVABLE_CONTROL_DRAG_STARTED, MovableControlEvent)
wxString name
Definition: TagsEditor.cpp:166
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)
wxPoint mInitialPosition
MovableControl()=default