1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Move code from LabelTrack into LabelTextHandle

This commit is contained in:
Paul Licameli 2019-06-20 09:45:26 -04:00
parent e0c4a94cfd
commit 6622f494fe
2 changed files with 128 additions and 126 deletions

View File

@ -1525,132 +1525,6 @@ auto LabelStruct::RegionRelation(
}
}
void LabelTextHandle::HandleTextDragRelease(const wxMouseEvent & evt)
{
auto pTrack = mpLT.lock();
if (!pTrack)
return;
auto &view = LabelTrackView::Get( *pTrack );
if(evt.LeftUp())
{
#if 0
// AWD: Due to wxWidgets bug #7491 (fix not ported to 2.8 branch) we
// should never write the primary selection. We can enable this block
// when we move to the 3.0 branch (or if a fixed 2.8 version is released
// and we can do a runtime version check)
#if defined (__WXGTK__) && defined (HAVE_GTK)
// On GTK, if we just dragged out a text selection, set the primary
// selection
if (mInitialCursorPos != mCurrentCursorPos) {
wxTheClipboard->UsePrimarySelection(true);
CopySelectedText();
wxTheClipboard->UsePrimarySelection(false);
}
#endif
#endif
return;
}
if(evt.Dragging())
{
if (!mRightDragging)
// Update drag end
view.SetCurrentCursorPosition(
view.FindCursorPosition( evt.m_x ) );
return;
}
if (evt.RightUp()) {
const auto selIndex = view.GetSelectedIndex();
if ( selIndex != -1 &&
LabelTrackView::OverTextBox(
pTrack->GetLabel( selIndex ), evt.m_x, evt.m_y ) ) {
// popup menu for editing
// TODO: handle context menus via CellularPanel?
view.ShowContextMenu();
}
}
return;
}
void LabelTextHandle::HandleTextClick(const wxMouseEvent & evt,
const wxRect & r, const ZoomInfo &zoomInfo,
SelectedRegion *newSel)
{
auto pTrack = mpLT.lock();
if (!pTrack)
return;
auto &view = LabelTrackView::Get( *pTrack );
static_cast<void>(r);//compiler food.
static_cast<void>(zoomInfo);//compiler food.
if (evt.ButtonDown())
{
const auto selIndex = LabelTrackView::OverATextBox( *pTrack, evt.m_x, evt.m_y );
view.SetSelectedIndex( selIndex );
if ( selIndex != -1 ) {
const auto &mLabels = pTrack->GetLabels();
const auto &labelStruct = mLabels[ selIndex ];
*newSel = labelStruct.selectedRegion;
if (evt.LeftDown()) {
// Find the NEW drag end
auto position = view.FindCursorPosition( evt.m_x );
// Anchor shift-drag at the farther end of the previous highlight
// that is farther from the click, on Mac, for consistency with
// its text editors, but on the others, re-use the previous
// anchor.
auto initial = view.GetInitialCursorPosition();
if (evt.ShiftDown()) {
#ifdef __WXMAC__
// Set the drag anchor at the end of the previous selection
// that is farther from the NEW drag end
const auto current = view.GetCurrentCursorPosition();
if ( abs( position - current ) > abs( position - initial ) )
initial = current;
#else
// initial position remains as before
#endif
}
else
initial = position;
view.SetTextHighlight( initial, position );
mRightDragging = false;
}
else
// Actually this might be right or middle down
mRightDragging = true;
// Middle click on GTK: paste from primary selection
#if defined(__WXGTK__) && (HAVE_GTK)
if (evt.MiddleDown()) {
// Check for a click outside of the selected label's text box; in this
// case PasteSelectedText() will start a NEW label at the click
// location
if (!LabelTrackView::OverTextBox(&labelStruct, evt.m_x, evt.m_y))
view.SetSelectedIndex( -1 );
double t = zoomInfo.PositionToTime(evt.m_x, r.x);
*newSel = SelectedRegion(t, t);
}
#endif
}
#if defined(__WXGTK__) && (HAVE_GTK)
if (evt.MiddleDown()) {
// Paste text, making a NEW label if none is selected.
wxTheClipboard->UsePrimarySelection(true);
view.PasteSelectedText(newSel->t0(), newSel->t1());
wxTheClipboard->UsePrimarySelection(false);
}
#endif
}
}
static bool IsGoodLabelFirstKey(const wxKeyEvent & evt);
static bool IsGoodLabelEditKey(const wxKeyEvent & evt);

View File

@ -24,6 +24,8 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../ViewInfo.h"
#include "../../../images/Cursors.h"
#include <wx/clipbrd.h>
LabelTextHandle::LabelTextHandle
( const std::shared_ptr<LabelTrack> &pLT, int labelNum )
: mpLT{ pLT }
@ -69,6 +71,80 @@ LabelTextHandle::~LabelTextHandle()
{
}
void LabelTextHandle::HandleTextClick(const wxMouseEvent & evt,
const wxRect & r, const ZoomInfo &zoomInfo,
SelectedRegion *newSel)
{
auto pTrack = mpLT.lock();
if (!pTrack)
return;
auto &view = LabelTrackView::Get( *pTrack );
static_cast<void>(r);//compiler food.
static_cast<void>(zoomInfo);//compiler food.
if (evt.ButtonDown())
{
const auto selIndex = LabelTrackView::OverATextBox( *pTrack, evt.m_x, evt.m_y );
view.SetSelectedIndex( selIndex );
if ( selIndex != -1 ) {
const auto &mLabels = pTrack->GetLabels();
const auto &labelStruct = mLabels[ selIndex ];
*newSel = labelStruct.selectedRegion;
if (evt.LeftDown()) {
// Find the NEW drag end
auto position = view.FindCursorPosition( evt.m_x );
// Anchor shift-drag at the farther end of the previous highlight
// that is farther from the click, on Mac, for consistency with
// its text editors, but on the others, re-use the previous
// anchor.
auto initial = view.GetInitialCursorPosition();
if (evt.ShiftDown()) {
#ifdef __WXMAC__
// Set the drag anchor at the end of the previous selection
// that is farther from the NEW drag end
const auto current = view.GetCurrentCursorPosition();
if ( abs( position - current ) > abs( position - initial ) )
initial = current;
#else
// initial position remains as before
#endif
}
else
initial = position;
view.SetTextHighlight( initial, position );
mRightDragging = false;
}
else
// Actually this might be right or middle down
mRightDragging = true;
// Middle click on GTK: paste from primary selection
#if defined(__WXGTK__) && (HAVE_GTK)
if (evt.MiddleDown()) {
// Check for a click outside of the selected label's text box; in this
// case PasteSelectedText() will start a NEW label at the click
// location
if (!LabelTrackView::OverTextBox(&labelStruct, evt.m_x, evt.m_y))
view.SetSelectedIndex( -1 );
double t = zoomInfo.PositionToTime(evt.m_x, r.x);
*newSel = SelectedRegion(t, t);
}
#endif
}
#if defined(__WXGTK__) && (HAVE_GTK)
if (evt.MiddleDown()) {
// Paste text, making a NEW label if none is selected.
wxTheClipboard->UsePrimarySelection(true);
view.PasteSelectedText(newSel->t0(), newSel->t1());
wxTheClipboard->UsePrimarySelection(false);
}
#endif
}
}
UIHandle::Result LabelTextHandle::Click
(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
{
@ -116,6 +192,58 @@ UIHandle::Result LabelTextHandle::Click
return result | RefreshCode::RefreshCell | RefreshCode::UpdateSelection;
}
void LabelTextHandle::HandleTextDragRelease(const wxMouseEvent & evt)
{
auto pTrack = mpLT.lock();
if (!pTrack)
return;
auto &view = LabelTrackView::Get( *pTrack );
if(evt.LeftUp())
{
#if 0
// AWD: Due to wxWidgets bug #7491 (fix not ported to 2.8 branch) we
// should never write the primary selection. We can enable this block
// when we move to the 3.0 branch (or if a fixed 2.8 version is released
// and we can do a runtime version check)
#if defined (__WXGTK__) && defined (HAVE_GTK)
// On GTK, if we just dragged out a text selection, set the primary
// selection
if (mInitialCursorPos != mCurrentCursorPos) {
wxTheClipboard->UsePrimarySelection(true);
CopySelectedText();
wxTheClipboard->UsePrimarySelection(false);
}
#endif
#endif
return;
}
if(evt.Dragging())
{
if (!mRightDragging)
// Update drag end
view.SetCurrentCursorPosition(
view.FindCursorPosition( evt.m_x ) );
return;
}
if (evt.RightUp()) {
const auto selIndex = view.GetSelectedIndex();
if ( selIndex != -1 &&
LabelTrackView::OverTextBox(
pTrack->GetLabel( selIndex ), evt.m_x, evt.m_y ) ) {
// popup menu for editing
// TODO: handle context menus via CellularPanel?
view.ShowContextMenu();
}
}
return;
}
UIHandle::Result LabelTextHandle::Drag
(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
{