mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-19 15:11:23 +01:00
Starting to make ToolBarConfiguration::Position more general
This commit is contained in:
@@ -48,6 +48,9 @@
|
|||||||
#include "../widgets/AButton.h"
|
#include "../widgets/AButton.h"
|
||||||
#include "../widgets/Grabber.h"
|
#include "../widgets/Grabber.h"
|
||||||
|
|
||||||
|
const ToolBarConfiguration::Position
|
||||||
|
ToolBarConfiguration::UnspecifiedPosition { false };
|
||||||
|
|
||||||
auto ToolBarConfiguration::FindPlace(const ToolBar *bar) const
|
auto ToolBarConfiguration::FindPlace(const ToolBar *bar) const
|
||||||
-> Iterator
|
-> Iterator
|
||||||
{
|
{
|
||||||
@@ -56,12 +59,26 @@ auto ToolBarConfiguration::FindPlace(const ToolBar *bar) const
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ToolBarConfiguration::Find(const ToolBar *bar) const -> Position
|
||||||
|
{
|
||||||
|
auto iter = FindPlace(bar);
|
||||||
|
if (iter == end())
|
||||||
|
return UnspecifiedPosition;
|
||||||
|
else
|
||||||
|
return iter->position;
|
||||||
|
}
|
||||||
|
|
||||||
void ToolBarConfiguration::Insert(ToolBar *bar, Position position)
|
void ToolBarConfiguration::Insert(ToolBar *bar, Position position)
|
||||||
{
|
{
|
||||||
if (position >= size() || position == UnspecifiedPosition)
|
if (position == UnspecifiedPosition)
|
||||||
|
push_back(bar);
|
||||||
|
else {
|
||||||
|
auto index = wxArrayPtrVoid::Index(position.rightOf);
|
||||||
|
if (index == wxNOT_FOUND)
|
||||||
push_back(bar);
|
push_back(bar);
|
||||||
else
|
else
|
||||||
wxArrayPtrVoid::Insert(bar, position);
|
wxArrayPtrVoid::Insert(bar, 1 + index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolBarConfiguration::Remove(const ToolBar *bar)
|
void ToolBarConfiguration::Remove(const ToolBar *bar)
|
||||||
|
|||||||
@@ -48,12 +48,46 @@ enum
|
|||||||
class ToolBarConfiguration : public wxArrayPtrVoid
|
class ToolBarConfiguration : public wxArrayPtrVoid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Position = int;
|
struct Position {
|
||||||
static const Position UnspecifiedPosition = -1;
|
ToolBar *rightOf {};
|
||||||
|
// ToolBar *below {};
|
||||||
|
// bool adopt {true};
|
||||||
|
bool valid {true};
|
||||||
|
|
||||||
|
// Default constructor
|
||||||
|
Position() {}
|
||||||
|
|
||||||
|
Position(
|
||||||
|
ToolBar *r /*,
|
||||||
|
ToolBar *b = nullptr,
|
||||||
|
bool shouldAdopt = true */
|
||||||
|
)
|
||||||
|
: rightOf{ r } // , below{ b }, adopt{ shouldAdopt }
|
||||||
|
{}
|
||||||
|
|
||||||
|
// Constructor for the invalid value
|
||||||
|
explicit Position(bool /* dummy */) : valid{ false } {}
|
||||||
|
|
||||||
|
friend inline bool operator ==
|
||||||
|
(const Position &lhs, const Position &rhs)
|
||||||
|
{ return lhs.valid == rhs.valid &&
|
||||||
|
(!lhs.valid ||
|
||||||
|
(lhs.rightOf == rhs.rightOf
|
||||||
|
// && lhs.below == rhs.below
|
||||||
|
// && lhs.adopt == rhs.adopt
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
friend inline bool operator !=
|
||||||
|
(const Position &lhs, const Position &rhs)
|
||||||
|
{ return !(lhs == rhs); }
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Position UnspecifiedPosition;
|
||||||
|
|
||||||
struct Place {
|
struct Place {
|
||||||
ToolBar *pBar {};
|
ToolBar *pBar {};
|
||||||
Position position { UnspecifiedPosition };
|
Position position;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Iterator
|
class Iterator
|
||||||
@@ -64,9 +98,13 @@ public:
|
|||||||
const Place *operator -> () const { return &**this; }
|
const Place *operator -> () const { return &**this; }
|
||||||
Iterator &operator ++ ()
|
Iterator &operator ++ ()
|
||||||
{
|
{
|
||||||
++mIter;
|
wxASSERT(mIter != mEnd);
|
||||||
|
|
||||||
// This is a feature: advance position even at the end
|
// This is a feature: advance position even at the end
|
||||||
++mPlace.position;
|
mPlace.position.rightOf = mPlace.pBar;
|
||||||
|
// mPlace.position.below = nullptr;
|
||||||
|
|
||||||
|
++mIter;
|
||||||
if (mIter != mEnd)
|
if (mIter != mEnd)
|
||||||
mPlace.pBar = static_cast<ToolBar*>(*mIter);
|
mPlace.pBar = static_cast<ToolBar*>(*mIter);
|
||||||
else
|
else
|
||||||
@@ -93,7 +131,6 @@ public:
|
|||||||
: mIter(iter)
|
: mIter(iter)
|
||||||
, mEnd(end)
|
, mEnd(end)
|
||||||
{
|
{
|
||||||
mPlace.position = 0;
|
|
||||||
if (mIter != mEnd)
|
if (mIter != mEnd)
|
||||||
mPlace.pBar = static_cast<ToolBar*>(*mIter);
|
mPlace.pBar = static_cast<ToolBar*>(*mIter);
|
||||||
}
|
}
|
||||||
@@ -107,10 +144,7 @@ public:
|
|||||||
Iterator end() const
|
Iterator end() const
|
||||||
{ return Iterator { wxArrayPtrVoid::end(), wxArrayPtrVoid::end() }; }
|
{ return Iterator { wxArrayPtrVoid::end(), wxArrayPtrVoid::end() }; }
|
||||||
|
|
||||||
Position Find(const ToolBar *bar) const
|
Position Find(const ToolBar *bar) const;
|
||||||
{
|
|
||||||
return Index(const_cast<ToolBar*>(bar));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Contains(const ToolBar *bar) const
|
bool Contains(const ToolBar *bar) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1344,7 +1344,7 @@ void ToolManager::DoneDragging()
|
|||||||
mDragDock = NULL;
|
mDragDock = NULL;
|
||||||
mDragBar = NULL;
|
mDragBar = NULL;
|
||||||
mPrevDock = NULL;
|
mPrevDock = NULL;
|
||||||
mPrevSlot = -1;
|
mPrevSlot = { ToolBarConfiguration::UnspecifiedPosition };
|
||||||
mLastPos.x = mBarPos.x = -1;
|
mLastPos.x = mBarPos.x = -1;
|
||||||
mLastPos.y = mBarPos.y = -1;
|
mLastPos.y = mBarPos.y = -1;
|
||||||
mTimer.Stop();
|
mTimer.Stop();
|
||||||
|
|||||||
Reference in New Issue
Block a user