Audacity  3.0.3
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 
20 #include "DragCommand.h"
21 
22 #include "LoadCommands.h"
23 #include "Project.h"
24 #include "../ProjectWindows.h"
25 #include "../WaveTrack.h"
26 #include "../Shuttle.h"
27 #include "../ShuttleGui.h"
28 #include "CommandContext.h"
29 
30 #include <wx/frame.h>
31 
33 { XO("Drag") };
34 
36 
38 {
39 }
40 
42 {
48 };
49 
51 {
52  { XO("Panel") },
53  { wxT("App"), XO("Application") },
54  { wxT("Track0"), XO("Track 0") },
55  { wxT("Track1"), XO("Track 1") },
56 };
57 
58 
60  S.OptionalN( bHasId ).Define( mId, wxT("Id"), 11000.0, -100000.0, 1000000.0);
61  S.OptionalY( bHasWinName ).Define( mWinName, wxT("Window"), "Timeline");
62  S.OptionalY( bHasFromX ).Define( mFromX, wxT("FromX"), 200.0, 0.0, 1000000.0);
63  S.OptionalY( bHasFromY ).Define( mFromY, wxT("FromY"), 10.0, 0.0, 1000000.0);
64  S.OptionalN( bHasToX ).Define( mToX, wxT("ToX"), 400.0, 0.0, 1000000.0);
65  S.OptionalN( bHasToY ).Define( mToY, wxT("ToY"), 10.0, 0.0, 1000000.0);
67  return true;
68 };
69 
71 {
72  S.AddSpace(0, 5);
73 
74  S.StartMultiColumn(3, wxALIGN_CENTER);
75  {
76  /* i18n-hint abbreviates "Identity" or "Identifier" */
77  S.Optional( bHasId ).TieNumericTextBox( XXO("Id:"), mId );
78  S.Optional( bHasWinName ).TieTextBox( XXO("Window Name:"), mWinName );
79  S.Optional( bHasFromX ).TieNumericTextBox( XXO("From X:"), mFromX );
80  S.Optional( bHasFromY ).TieNumericTextBox( XXO("From Y:"), mFromY );
81  S.Optional( bHasToX ).TieNumericTextBox( XXO("To X:"), mToX );
82  S.Optional( bHasToY ).TieNumericTextBox( XXO("To Y:"), mToY );
83  S.Optional( bHasRelativeTo ).TieChoice( XXO("Relative To:"), mRelativeTo,
85  }
86  S.EndMultiColumn();
87 }
88 
89 bool DragCommand::Apply(const CommandContext & context)
90 {
91  // Defaults if no value...
92  if( !bHasFromX )
93  mFromX = 200.0;
94  if( !bHasFromY )
95  mFromY = 10;
96  if( !bHasToX )
97  mToX = 400;
98  if( !bHasToY )
99  mToY = 10;
100 
101  wxWindow * pWin = &GetProjectFrame( context.project );
102  wxWindow * pWin1 = nullptr;
103  wxMouseEvent Evt( wxEVT_MOTION );
104  Evt.m_x = mFromX;
105  Evt.m_y = mFromY;
106  if( bHasId )
107  pWin1 = pWin->FindWindowById( mId );
108  if( bHasWinName )
109  pWin1 = pWin->FindWindowByName( mWinName );
110  if( pWin1 )
111  pWin = pWin1;
112  // Process twice - possible bug in Audacity being worked around
113  // where we need an event to enter AND an event to move.
114  // AdornedRuler Quick-Play bug.
115  pWin->GetEventHandler()->ProcessEvent( Evt );
116  pWin->GetEventHandler()->ProcessEvent( Evt );
117  if( bHasToX ){
118  wxMouseEvent Evt2( wxEVT_LEFT_DOWN );
119  Evt2.m_leftDown = true;
120  Evt2.m_x = mFromX;
121  Evt2.m_y = mFromY;
122  Evt2.m_aux2Down = true;
123  pWin->GetEventHandler()->ProcessEvent( Evt2 );
124  wxMouseEvent Evt3( wxEVT_MOTION );
125  Evt3.m_leftDown = true;
126  Evt2.m_aux2Down = true;
127  Evt3.m_x = mToX;
128  Evt3.m_y = mToY;
129  // AdornedRuler Quick-Play bug again.
130  pWin->GetEventHandler()->ProcessEvent( Evt3 );
131  pWin->GetEventHandler()->ProcessEvent( Evt3 );
132  wxMouseEvent Evt4( wxEVT_LEFT_UP );
133  Evt2.m_aux2Down = true;
134  Evt4.m_x = mToX;
135  Evt4.m_y = mToY;
136  pWin->GetEventHandler()->ProcessEvent( Evt4 );
137  }
138  return true;
139 }
DragCommand::DragCommand
DragCommand()
Definition: DragCommand.cpp:37
DragCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: DragCommand.h:25
kTrack1
@ kTrack1
Definition: DragCommand.cpp:46
LoadCommands.h
DragCommand::bHasToY
bool bHasToY
Definition: DragCommand.h:51
Project.h
kPanel
@ kPanel
Definition: DragCommand.cpp:43
kCoordTypeStrings
static const EnumValueSymbol kCoordTypeStrings[nCoordTypes]
Definition: DragCommand.cpp:50
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2459
XO
#define XO(s)
Definition: Internat.h:31
DragCommand::mRelativeTo
int mRelativeTo
Definition: DragCommand.h:44
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
DragCommand::mToX
double mToX
Definition: DragCommand.h:42
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
ShuttleGuiBase::TieTextBox
wxTextCtrl * TieTextBox(const TranslatableString &Caption, wxString &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1652
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
CommandContext.h
DragCommand::mFromX
double mFromX
Definition: DragCommand.h:40
XXO
#define XXO(s)
Definition: Internat.h:44
DragCommand::mFromY
double mFromY
Definition: DragCommand.h:41
DragCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: DragCommand.cpp:70
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
DragCommand.h
Declarations of DragCommand and DragCommandType classes.
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
DragCommand::bHasFromY
bool bHasFromY
Definition: DragCommand.h:49
ShuttleParams::DefineEnum
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const EnumValueSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:339
DragCommand::Apply
bool Apply(const CommandContext &context) override
Definition: DragCommand.cpp:89
DragCommand::bHasToX
bool bHasToX
Definition: DragCommand.h:50
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
nCoordTypes
@ nCoordTypes
Definition: DragCommand.cpp:47
ShuttleGuiBase::TieNumericTextBox
wxTextCtrl * TieNumericTextBox(const TranslatableString &Prompt, int &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1673
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
Definition: ShuttleGui.cpp:2522
DragCommand::bHasRelativeTo
bool bHasRelativeTo
Definition: DragCommand.h:52
DragCommand::bHasFromX
bool bHasFromX
Definition: DragCommand.h:48
GetProjectFrame
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
Definition: ProjectWindows.cpp:72
DragCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: DragCommand.cpp:59
DragCommand::bHasId
bool bHasId
Definition: DragCommand.h:53
DragCommand::bHasWinName
bool bHasWinName
Definition: DragCommand.h:54
kCoordTypes
kCoordTypes
Definition: DragCommand.cpp:42
ShuttleParams::Define
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:332
kApp
@ kApp
Definition: DragCommand.cpp:44
ShuttleGui::Optional
ShuttleGui & Optional(bool &bVar)
Definition: ShuttleGui.cpp:2280
DragCommand::mToY
double mToY
Definition: DragCommand.h:43
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:64
DragCommand::mId
int mId
Definition: DragCommand.h:45
kTrack0
@ kTrack0
Definition: DragCommand.cpp:45
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1727
DragCommand::mWinName
wxString mWinName
Definition: DragCommand.h:46
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
anonymous_namespace{DragCommand.cpp}::reg
BuiltinCommandsModule::Registration< DragCommand > reg
Definition: DragCommand.cpp:35