Audacity  2.3.1
DragCommand.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity - A Digital Audio Editor
4  Copyright 1999-2018 Audacity Team
5  License: wxwidgets
6 
7  James Crook
8 
9 ******************************************************************//*******************************************************************/
18 
19 #include "../Audacity.h"
20 #include "DragCommand.h"
21 #include "../Project.h"
22 #include "../Track.h"
23 #include "../TrackPanel.h"
24 #include "../WaveTrack.h"
25 #include "../ShuttleGui.h"
26 #include "CommandContext.h"
27 
29 {
30 }
31 
33 {
39 };
40 
42 {
43  { XO("Panel") },
44  { wxT("App"), XO("Application") },
45  { wxT("Track0"), XO("Track 0") },
46  { wxT("Track1"), XO("Track 1") },
47 };
48 
49 
51  S.OptionalN( bHasId ).Define( mId, wxT("Id"), 11000.0, -100000.0, 1000000.0);
52  S.OptionalY( bHasWinName ).Define( mWinName, wxT("Window"), "Timeline");
53  S.OptionalY( bHasFromX ).Define( mFromX, wxT("FromX"), 200.0, 0.0, 1000000.0);
54  S.OptionalY( bHasFromY ).Define( mFromY, wxT("FromY"), 10.0, 0.0, 1000000.0);
55  S.OptionalN( bHasToX ).Define( mToX, wxT("ToX"), 400.0, 0.0, 1000000.0);
56  S.OptionalN( bHasToY ).Define( mToY, wxT("ToY"), 10.0, 0.0, 1000000.0);
57  S.OptionalN( bHasRelativeTo ).DefineEnum( mRelativeTo, wxT("RelativeTo"), kPanel, kCoordTypeStrings, nCoordTypes );
58  return true;
59 };
60 
62 {
63  auto coords = LocalizedStrings( kCoordTypeStrings, nCoordTypes );
64 
65  S.AddSpace(0, 5);
66 
67  S.StartMultiColumn(3, wxALIGN_CENTER);
68  {
69  /* i18n-hint abbreviates "Identity" or "Identifier" */
70  S.Optional( bHasId ).TieNumericTextBox( _("Id:"), mId );
71  S.Optional( bHasWinName ).TieTextBox( _("Window Name:"), mWinName );
72  S.Optional( bHasFromX ).TieNumericTextBox( _("From X:"), mFromX );
73  S.Optional( bHasFromY ).TieNumericTextBox( _("From Y:"), mFromY );
74  S.Optional( bHasToX ).TieNumericTextBox( _("To X:"), mToX );
75  S.Optional( bHasToY ).TieNumericTextBox( _("To Y:"), mToY );
76  S.Optional( bHasRelativeTo ).TieChoice( _("Relative To:"), mRelativeTo, &coords );
77  }
78  S.EndMultiColumn();
79 }
80 
81 bool DragCommand::Apply(const CommandContext & context)
82 {
83  // Defaults if no value...
84  if( !bHasFromX )
85  mFromX = 200.0;
86  if( !bHasFromY )
87  mFromY = 10;
88  if( !bHasToX )
89  mToX = 400;
90  if( !bHasToY )
91  mToY = 10;
92 
93  wxWindow * pWin = context.GetProject();
94  wxWindow * pWin1 = nullptr;
95  wxMouseEvent Evt( wxEVT_MOTION );
96  Evt.m_x = mFromX;
97  Evt.m_y = mFromY;
98  if( bHasId )
99  pWin1 = pWin->FindWindowById( mId );
100  if( bHasWinName )
101  pWin1 = pWin->FindWindowByName( mWinName );
102  if( pWin1 )
103  pWin = pWin1;
104  // Process twice - possible bug in Audacity being worked around
105  // where we need an event to enter AND an event to move.
106  // AdornedRuler Quick-Play bug.
107  pWin->GetEventHandler()->ProcessEvent( Evt );
108  pWin->GetEventHandler()->ProcessEvent( Evt );
109  if( bHasToX ){
110  wxMouseEvent Evt2( wxEVT_LEFT_DOWN );
111  Evt2.m_leftDown = true;
112  Evt2.m_x = mFromX;
113  Evt2.m_y = mFromY;
114  Evt2.m_aux2Down = true;
115  pWin->GetEventHandler()->ProcessEvent( Evt2 );
116  wxMouseEvent Evt3( wxEVT_MOTION );
117  Evt3.m_leftDown = true;
118  Evt2.m_aux2Down = true;
119  Evt3.m_x = mToX;
120  Evt3.m_y = mToY;
121  // AdornedRuler Quick-Play bug again.
122  pWin->GetEventHandler()->ProcessEvent( Evt3 );
123  pWin->GetEventHandler()->ProcessEvent( Evt3 );
124  wxMouseEvent Evt4( wxEVT_LEFT_UP );
125  Evt2.m_aux2Down = true;
126  Evt4.m_x = mToX;
127  Evt4.m_y = mToY;
128  pWin->GetEventHandler()->ProcessEvent( Evt4 );
129  }
130  return true;
131 }
double mFromX
Definition: DragCommand.h:40
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
ShuttleGui & Optional(bool &bVar)
AudacityProject * GetProject() const
bool bHasFromX
Definition: DragCommand.h:48
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
double mToY
Definition: DragCommand.h:43
kCoordTypes
Definition: DragCommand.cpp:32
wxArrayString LocalizedStrings(const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Internat.cpp:303
void EndMultiColumn()
#define XO(s)
Definition: Internat.h:33
bool bHasFromY
Definition: DragCommand.h:49
bool bHasToX
Definition: DragCommand.h:50
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
Declarations of DragCommand and DragCommandType classes.
static const IdentInterfaceSymbol kCoordTypeStrings[nCoordTypes]
Definition: DragCommand.cpp:41
bool DefineParams(ShuttleParams &S) override
Definition: DragCommand.cpp:50
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
int mRelativeTo
Definition: DragCommand.h:44
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:345
double mToX
Definition: DragCommand.h:42
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:338
wxTextCtrl * TieNumericTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
bool bHasWinName
Definition: DragCommand.h:54
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
wxString mWinName
Definition: DragCommand.h:46
double mFromY
Definition: DragCommand.h:41
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
bool bHasToY
Definition: DragCommand.h:51
bool bHasRelativeTo
Definition: DragCommand.h:52
wxSizerItem * AddSpace(int width, int height)
void PopulateOrExchange(ShuttleGui &S) override
Definition: DragCommand.cpp:61
wxTextCtrl * TieTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
virtual bool Apply()