Audacity 3.2.0
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 "CommandDispatch.h"
23#include "MenuRegistry.h"
24#include "../CommonCommandFlags.h"
25#include "LoadCommands.h"
26#include "Project.h"
27#include "../ProjectWindows.h"
28#include "WaveTrack.h"
29#include "SettingsVisitor.h"
30#include "ShuttleGui.h"
31#include "CommandContext.h"
32
33#include <wx/frame.h>
34
36{ XO("Drag") };
37
39
41{
42}
43
45{
51};
52
54{
55 { XO("Panel") },
56 { wxT("App"), XO("Application") },
57 { wxT("Track0"), XO("Track 0") },
58 { wxT("Track1"), XO("Track 1") },
59};
60
61
62template<bool Const>
64 S.OptionalN( bHasId ).Define( mId, wxT("Id"), 11000, -100000, 1000000);
65 S.OptionalY( bHasWinName ).Define( mWinName, wxT("Window"), wxString{"Timeline"});
66 S.OptionalY( bHasFromX ).Define( mFromX, wxT("FromX"), 200.0, 0.0, 1000000.0);
67 S.OptionalY( bHasFromY ).Define( mFromY, wxT("FromY"), 10.0, 0.0, 1000000.0);
68 S.OptionalN( bHasToX ).Define( mToX, wxT("ToX"), 400.0, 0.0, 1000000.0);
69 S.OptionalN( bHasToY ).Define( mToY, wxT("ToY"), 10.0, 0.0, 1000000.0);
70 S.OptionalN( bHasRelativeTo ).DefineEnum( mRelativeTo, wxT("RelativeTo"), kPanel, kCoordTypeStrings, nCoordTypes );
71 return true;
72};
73
75 { return VisitSettings<false>(S); }
76
78 { return VisitSettings<true>(S); }
79
81{
82 S.AddSpace(0, 5);
83
84 S.StartMultiColumn(3, wxALIGN_CENTER);
85 {
86 /* i18n-hint abbreviates "Identity" or "Identifier" */
87 S.Optional( bHasId ).TieNumericTextBox( XXO("Id:"), mId );
88 S.Optional( bHasWinName ).TieTextBox( XXO("Window Name:"), mWinName );
89 S.Optional( bHasFromX ).TieNumericTextBox( XXO("From X:"), mFromX );
90 S.Optional( bHasFromY ).TieNumericTextBox( XXO("From Y:"), mFromY );
91 S.Optional( bHasToX ).TieNumericTextBox( XXO("To X:"), mToX );
92 S.Optional( bHasToY ).TieNumericTextBox( XXO("To Y:"), mToY );
93 S.Optional( bHasRelativeTo ).TieChoice( XXO("Relative To:"), mRelativeTo,
95 }
96 S.EndMultiColumn();
97}
98
100{
101 // Defaults if no value...
102 if( !bHasFromX )
103 mFromX = 200.0;
104 if( !bHasFromY )
105 mFromY = 10;
106 if( !bHasToX )
107 mToX = 400;
108 if( !bHasToY )
109 mToY = 10;
110
111 wxWindow * pWin = &GetProjectFrame( context.project );
112 wxWindow * pWin1 = nullptr;
113 wxMouseEvent Evt( wxEVT_MOTION );
114 Evt.m_x = mFromX;
115 Evt.m_y = mFromY;
116 if( bHasId )
117 pWin1 = pWin->FindWindowById( mId );
118 if( bHasWinName )
119 pWin1 = pWin->FindWindowByName( mWinName );
120 if( pWin1 )
121 pWin = pWin1;
122 // Process twice - possible bug in Audacity being worked around
123 // where we need an event to enter AND an event to move.
124 // AdornedRuler Quick-Play bug.
125 pWin->GetEventHandler()->ProcessEvent( Evt );
126 pWin->GetEventHandler()->ProcessEvent( Evt );
127 if( bHasToX ){
128 wxMouseEvent Evt2( wxEVT_LEFT_DOWN );
129 Evt2.m_leftDown = true;
130 Evt2.m_x = mFromX;
131 Evt2.m_y = mFromY;
132 Evt2.m_aux2Down = true;
133 pWin->GetEventHandler()->ProcessEvent( Evt2 );
134 wxMouseEvent Evt3( wxEVT_MOTION );
135 Evt3.m_leftDown = true;
136 Evt2.m_aux2Down = true;
137 Evt3.m_x = mToX;
138 Evt3.m_y = mToY;
139 // AdornedRuler Quick-Play bug again.
140 pWin->GetEventHandler()->ProcessEvent( Evt3 );
141 pWin->GetEventHandler()->ProcessEvent( Evt3 );
142 wxMouseEvent Evt4( wxEVT_LEFT_UP );
143 Evt2.m_aux2Down = true;
144 Evt4.m_x = mToX;
145 Evt4.m_y = mToY;
146 pWin->GetEventHandler()->ProcessEvent( Evt4 );
147 }
148 return true;
149}
150
151namespace {
152using namespace MenuRegistry;
153
154// Register menu items
155
157 // Note that the PLUGIN_SYMBOL must have a space between words,
158 // whereas the short-form used here must not.
159 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
160 // you would have to use "CompareAudio" here.)
161 Command( wxT("Drag"), XXO("Move Mouse..."),
163 wxT("Optional/Extra/Part2/Scriptables2")
164};
165
166}
wxT("CloseDown"))
const ReservedCommandFlag & AudioIONotBusyFlag()
kCoordTypes
Definition: DragCommand.cpp:45
@ nCoordTypes
Definition: DragCommand.cpp:50
@ kTrack0
Definition: DragCommand.cpp:48
@ kTrack1
Definition: DragCommand.cpp:49
@ kApp
Definition: DragCommand.cpp:47
@ kPanel
Definition: DragCommand.cpp:46
static const EnumValueSymbol kCoordTypeStrings[nCoordTypes]
Definition: DragCommand.cpp:53
Declarations of DragCommand and DragCommandType classes.
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
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 ...
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
bool Apply(const CommandContext &context) override
Definition: DragCommand.cpp:99
bool bHasWinName
Definition: DragCommand.h:56
double mToY
Definition: DragCommand.h:45
double mToX
Definition: DragCommand.h:44
static const ComponentInterfaceSymbol Symbol
Definition: DragCommand.h:25
bool bHasToX
Definition: DragCommand.h:52
wxString mWinName
Definition: DragCommand.h:48
double mFromY
Definition: DragCommand.h:43
double mFromX
Definition: DragCommand.h:42
bool bHasFromX
Definition: DragCommand.h:50
void PopulateOrExchange(ShuttleGui &S) override
Definition: DragCommand.cpp:80
bool bHasToY
Definition: DragCommand.h:53
bool bHasFromY
Definition: DragCommand.h:51
bool VisitSettings(SettingsVisitorBase< Const > &S)
Definition: DragCommand.cpp:63
bool bHasRelativeTo
Definition: DragCommand.h:54
int mRelativeTo
Definition: DragCommand.h:46
Generates classes whose instances register items at construction.
Definition: Registry.h:388
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< DragCommand > reg
Definition: DragCommand.cpp:38