mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-06 23:29:24 +02:00
Abstract ToolBarConfiguration further, with an iterator class
This commit is contained in:
parent
dd327cd304
commit
b46e263afb
@ -48,6 +48,14 @@
|
||||
#include "../widgets/AButton.h"
|
||||
#include "../widgets/Grabber.h"
|
||||
|
||||
auto ToolBarConfiguration::FindPlace(const ToolBar *bar) const
|
||||
-> Iterator
|
||||
{
|
||||
return std::find_if(begin(), end(),
|
||||
[=](const Place &place){ return place.pBar == bar; }
|
||||
);
|
||||
}
|
||||
|
||||
void ToolBarConfiguration::Insert(ToolBar *bar, Position position)
|
||||
{
|
||||
if (position >= size() || position == UnspecifiedPosition)
|
||||
@ -182,11 +190,10 @@ void ToolDock::Dock( ToolBar *bar, bool deflate, ToolBarConfiguration::Position
|
||||
//
|
||||
void ToolDock::LayoutToolBars()
|
||||
{
|
||||
ToolBar *lt = NULL;
|
||||
ToolBar *lt = nullptr;
|
||||
|
||||
wxRect stack[ ToolBarCount + 1 ];
|
||||
int stkcnt = 0;
|
||||
int cnt = mConfiguration.GetCount();
|
||||
int width, height;
|
||||
|
||||
// Get size of our parent since we haven't been sized yet
|
||||
@ -202,10 +209,10 @@ void ToolDock::LayoutToolBars()
|
||||
stack[ 0 ].SetHeight( height );
|
||||
|
||||
// Process all docked and visible toolbars
|
||||
for( int ndx = 0; ndx < cnt; ndx++ )
|
||||
for (const auto &place : GetConfiguration())
|
||||
{
|
||||
// Cache toolbar pointer
|
||||
ToolBar *ct = (ToolBar *)mConfiguration[ ndx ];
|
||||
ToolBar *ct = place.pBar;
|
||||
|
||||
// Get and cache the toolbar sizes
|
||||
wxSize sz = ct->GetSize();
|
||||
@ -235,7 +242,7 @@ void ToolDock::LayoutToolBars()
|
||||
const auto cpos = stack[ stkcnt ].GetPosition();
|
||||
|
||||
// Position the previous toolbar
|
||||
if( ndx > 0 )
|
||||
if( lt )
|
||||
{
|
||||
// Keep the tab order in order
|
||||
ct->MoveAfterInTabOrder( lt );
|
||||
@ -284,7 +291,6 @@ ToolBarConfiguration::Position
|
||||
|
||||
wxRect stack[ ToolBarCount + 1 ];
|
||||
int stkcnt = 0;
|
||||
int cnt = mConfiguration.GetCount();
|
||||
int width, height;
|
||||
|
||||
// Get size of our parent since we haven't been sized yet
|
||||
@ -302,23 +308,27 @@ ToolBarConfiguration::Position
|
||||
// Process all docked and visible toolbars
|
||||
//
|
||||
// Careful...slightly different from above in that we expect to
|
||||
// process one more bar than is currently docked (<= in for)
|
||||
for ( int ndx = 0; ndx <= cnt; ndx++)
|
||||
// process one more bar than is currently docked
|
||||
for ( auto iter = GetConfiguration().begin(),
|
||||
end = GetConfiguration().end();
|
||||
; // iterate once more at end
|
||||
++iter )
|
||||
{
|
||||
wxRect sz;
|
||||
|
||||
// If last entry, then it is the
|
||||
if (ndx == cnt)
|
||||
if (iter == end)
|
||||
{
|
||||
// Add the NEW bars' dimensions to the mix
|
||||
rect = t->GetRect();
|
||||
sz = t->GetDockedSize();
|
||||
tindx = ndx;
|
||||
// This will break the loop
|
||||
tindx = iter->position;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cache toolbar pointer
|
||||
ToolBar *ct = (ToolBar *)mConfiguration[ndx];
|
||||
ToolBar *ct = iter->pBar;
|
||||
|
||||
// Remember current bars ' dimensions
|
||||
sz = ct->GetSize();
|
||||
@ -341,7 +351,7 @@ ToolBarConfiguration::Position
|
||||
// Add the NEW bars' dimensions to the mix
|
||||
rect = t->GetRect();
|
||||
sz = t->GetDockedSize();
|
||||
tindx = ndx;
|
||||
tindx = iter->position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,62 @@ public:
|
||||
using Position = int;
|
||||
static const Position UnspecifiedPosition = -1;
|
||||
|
||||
struct Place {
|
||||
ToolBar *pBar {};
|
||||
Position position { UnspecifiedPosition };
|
||||
};
|
||||
|
||||
class Iterator
|
||||
: public std::iterator<std::forward_iterator_tag, Place>
|
||||
{
|
||||
public:
|
||||
const Place &operator * () const { return mPlace; }
|
||||
const Place *operator -> () const { return &**this; }
|
||||
Iterator &operator ++ ()
|
||||
{
|
||||
++mIter;
|
||||
// This is a feature: advance position even at the end
|
||||
++mPlace.position;
|
||||
if (mIter != mEnd)
|
||||
mPlace.pBar = static_cast<ToolBar*>(*mIter);
|
||||
else
|
||||
mPlace.pBar = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend inline bool operator ==
|
||||
(const Iterator &lhs, const Iterator &rhs)
|
||||
{
|
||||
return lhs.mIter == rhs.mIter;
|
||||
}
|
||||
|
||||
friend inline bool operator !=
|
||||
(const Iterator &lhs, const Iterator &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
friend ToolBarConfiguration;
|
||||
using iterator = wxArrayPtrVoid::const_iterator;
|
||||
explicit Iterator(iterator iter, iterator end)
|
||||
: mIter(iter)
|
||||
, mEnd(end)
|
||||
{
|
||||
mPlace.position = 0;
|
||||
if (mIter != mEnd)
|
||||
mPlace.pBar = static_cast<ToolBar*>(*mIter);
|
||||
}
|
||||
|
||||
iterator mIter, mEnd;
|
||||
Place mPlace;
|
||||
};
|
||||
|
||||
Iterator begin() const
|
||||
{ return Iterator { wxArrayPtrVoid::begin(), wxArrayPtrVoid::end() }; }
|
||||
Iterator end() const
|
||||
{ return Iterator { wxArrayPtrVoid::end(), wxArrayPtrVoid::end() }; }
|
||||
|
||||
Position Find(const ToolBar *bar) const
|
||||
{
|
||||
return Index(const_cast<ToolBar*>(bar));
|
||||
@ -74,6 +130,7 @@ public:
|
||||
void Hide(ToolBar *bar);
|
||||
|
||||
private:
|
||||
Iterator FindPlace(const ToolBar *bar) const;
|
||||
};
|
||||
|
||||
class ToolDock final : public wxPanel
|
||||
|
Loading…
x
Reference in New Issue
Block a user