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 "../WaveTrack.h"
25 #include "../Shuttle.h"
26 #include "../ShuttleGui.h"
27 #include "CommandContext.h"
28 
29 #include <wx/frame.h>
30 
32 { XO("Drag") };
33 
35 
37 {
38 }
39 
41 {
47 };
48 
50 {
51  { XO("Panel") },
52  { wxT("App"), XO("Application") },
53  { wxT("Track0"), XO("Track 0") },
54  { wxT("Track1"), XO("Track 1") },
55 };
56 
57 
59  S.OptionalN( bHasId ).Define( mId, wxT("Id"), 11000.0, -100000.0, 1000000.0);
60  S.OptionalY( bHasWinName ).Define( mWinName, wxT("Window"), "Timeline");
61  S.OptionalY( bHasFromX ).Define( mFromX, wxT("FromX"), 200.0, 0.0, 1000000.0);
62  S.OptionalY( bHasFromY ).Define( mFromY, wxT("FromY"), 10.0, 0.0, 1000000.0);
63  S.OptionalN( bHasToX ).Define( mToX, wxT("ToX"), 400.0, 0.0, 1000000.0);
64  S.OptionalN( bHasToY ).Define( mToY, wxT("ToY"), 10.0, 0.0, 1000000.0);
66  return true;
67 };
68 
70 {
71  S.AddSpace(0, 5);
72 
73  S.StartMultiColumn(3, wxALIGN_CENTER);
74  {
75  /* i18n-hint abbreviates "Identity" or "Identifier" */
76  S.Optional( bHasId ).TieNumericTextBox( XXO("Id:"), mId );
77  S.Optional( bHasWinName ).TieTextBox( XXO("Window Name:"), mWinName );
78  S.Optional( bHasFromX ).TieNumericTextBox( XXO("From X:"), mFromX );
79  S.Optional( bHasFromY ).TieNumericTextBox( XXO("From Y:"), mFromY );
80  S.Optional( bHasToX ).TieNumericTextBox( XXO("To X:"), mToX );
81  S.Optional( bHasToY ).TieNumericTextBox( XXO("To Y:"), mToY );
82  S.Optional( bHasRelativeTo ).TieChoice( XXO("Relative To:"), mRelativeTo,
84  }
85  S.EndMultiColumn();
86 }
87 
88 bool DragCommand::Apply(const CommandContext & context)
89 {
90  // Defaults if no value...
91  if( !bHasFromX )
92  mFromX = 200.0;
93  if( !bHasFromY )
94  mFromY = 10;
95  if( !bHasToX )
96  mToX = 400;
97  if( !bHasToY )
98  mToY = 10;
99 
100  wxWindow * pWin = &GetProjectFrame( context.project );
101  wxWindow * pWin1 = nullptr;
102  wxMouseEvent Evt( wxEVT_MOTION );
103  Evt.m_x = mFromX;
104  Evt.m_y = mFromY;
105  if( bHasId )
106  pWin1 = pWin->FindWindowById( mId );
107  if( bHasWinName )
108  pWin1 = pWin->FindWindowByName( mWinName );
109  if( pWin1 )
110  pWin = pWin1;
111  // Process twice - possible bug in Audacity being worked around
112  // where we need an event to enter AND an event to move.
113  // AdornedRuler Quick-Play bug.
114  pWin->GetEventHandler()->ProcessEvent( Evt );
115  pWin->GetEventHandler()->ProcessEvent( Evt );
116  if( bHasToX ){
117  wxMouseEvent Evt2( wxEVT_LEFT_DOWN );
118  Evt2.m_leftDown = true;
119  Evt2.m_x = mFromX;
120  Evt2.m_y = mFromY;
121  Evt2.m_aux2Down = true;
122  pWin->GetEventHandler()->ProcessEvent( Evt2 );
123  wxMouseEvent Evt3( wxEVT_MOTION );
124  Evt3.m_leftDown = true;
125  Evt2.m_aux2Down = true;
126  Evt3.m_x = mToX;
127  Evt3.m_y = mToY;
128  // AdornedRuler Quick-Play bug again.
129  pWin->GetEventHandler()->ProcessEvent( Evt3 );
130  pWin->GetEventHandler()->ProcessEvent( Evt3 );
131  wxMouseEvent Evt4( wxEVT_LEFT_UP );
132  Evt2.m_aux2Down = true;
133  Evt4.m_x = mToX;
134  Evt4.m_y = mToY;
135  pWin->GetEventHandler()->ProcessEvent( Evt4 );
136  }
137  return true;
138 }
DragCommand::DragCommand
DragCommand()
Definition: DragCommand.cpp:36
DragCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: DragCommand.h:25
kTrack1
@ kTrack1
Definition: DragCommand.cpp:45
LoadCommands.h
DragCommand::bHasToY
bool bHasToY
Definition: DragCommand.h:51
kPanel
@ kPanel
Definition: DragCommand.cpp:42
kCoordTypeStrings
static const EnumValueSymbol kCoordTypeStrings[nCoordTypes]
Definition: DragCommand.cpp:49
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2447
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:69
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:22
DragCommand.h
Declarations of DragCommand and DragCommandType classes.
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
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: Project.cpp:188
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:88
DragCommand::bHasToX
bool bHasToX
Definition: DragCommand.h:50
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
nCoordTypes
@ nCoordTypes
Definition: DragCommand.cpp:46
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:2510
DragCommand::bHasRelativeTo
bool bHasRelativeTo
Definition: DragCommand.h:52
DragCommand::bHasFromX
bool bHasFromX
Definition: DragCommand.h:48
DragCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: DragCommand.cpp:58
DragCommand::bHasId
bool bHasId
Definition: DragCommand.h:53
DragCommand::bHasWinName
bool bHasWinName
Definition: DragCommand.h:54
kCoordTypes
kCoordTypes
Definition: DragCommand.cpp:41
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:43
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:52
DragCommand::mId
int mId
Definition: DragCommand.h:45
kTrack0
@ kTrack0
Definition: DragCommand.cpp:44
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:34