Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
ToolBarConfiguration Class Reference

#include <ToolDock.h>

Collaboration diagram for ToolBarConfiguration:
[legend]

Classes

class  Iterator
 
struct  Legacy
 
struct  Place
 
struct  Position
 
struct  Tree
 

Public Member Functions

void Swap (ToolBarConfiguration &that)
 
void Clear ()
 
Iterator begin ()
 
Iterator end () const
 
Position Find (const ToolBar *bar) const
 
ToolBarFindToolBar (Identifier id) const
 
bool Contains (const ToolBar *bar) const
 
void Insert (ToolBar *bar, Position position=UnspecifiedPosition)
 
void InsertAtPath (ToolBar *bar, const std::vector< int > &path)
 
void Remove (const ToolBar *bar)
 
bool Shows (const ToolBar *bar) const
 
void Show (ToolBar *bar)
 
void Hide (ToolBar *bar)
 
bool IsRightmost (const ToolBar *bar) const
 
void PostRead (Legacy &legacy)
 

Static Public Member Functions

static bool Read (ToolBarConfiguration *pConfiguration, Legacy *pLegacy, ToolBar *bar, bool &visible, bool defaultVisible)
 
static void Write (const ToolBarConfiguration *pConfiguration, const ToolBar *bar)
 

Static Public Attributes

static const Position UnspecifiedPosition { false }
 

Private Types

using Forest = std::vector< Tree >
 

Private Member Functions

void Remove (Forest &forest, Forest::iterator iter)
 
void RemoveNulls (Forest &forest)
 
Iterator FindPlace (const ToolBar *bar) const
 
std::pair< Forest *, Forest::iterator > FindPeers (const ToolBar *bar)
 

Private Attributes

Forest mForest
 

Detailed Description

Definition at line 50 of file ToolDock.h.

Member Typedef Documentation

◆ Forest

using ToolBarConfiguration::Forest = std::vector<Tree>
private

Definition at line 53 of file ToolDock.h.

Member Function Documentation

◆ begin()

Iterator ToolBarConfiguration::begin ( )
inline

Definition at line 229 of file ToolDock.h.

229{ return Iterator { *this }; }

Referenced by Insert().

Here is the caller graph for this function:

◆ Clear()

void ToolBarConfiguration::Clear ( )
inline

Definition at line 62 of file ToolDock.h.

63 {
64 mForest.clear();
65 }

References mForest.

Referenced by ToolManager::Destroy(), ToolManager::DoneDragging(), ToolDock::RestoreConfiguration(), ToolDock::VisitLayout(), and ToolDock::WrapConfiguration().

Here is the caller graph for this function:

◆ Contains()

bool ToolBarConfiguration::Contains ( const ToolBar bar) const
inline

Definition at line 235 of file ToolDock.h.

236 {
237 return Find(bar) != UnspecifiedPosition;
238 }
static const Position UnspecifiedPosition
Definition: ToolDock.h:106
Position Find(const ToolBar *bar) const
Definition: ToolDock.cpp:87

References Find(), and UnspecifiedPosition.

Referenced by ToolDock::Dock(), Show(), Shows(), ToolDock::Undock(), and ToolManager::WriteConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

Iterator ToolBarConfiguration::end ( ) const
inline

Definition at line 230 of file ToolDock.h.

230{ return Iterator {}; }

Referenced by FindToolBar(), Insert(), IsRightmost(), and Write().

Here is the caller graph for this function:

◆ Find()

auto ToolBarConfiguration::Find ( const ToolBar bar) const

Definition at line 87 of file ToolDock.cpp.

88{
89 auto iter = FindPlace(bar);
90 if (iter == end())
92 else
93 return iter->position;
94}
Iterator end() const
Definition: ToolDock.h:230
Iterator FindPlace(const ToolBar *bar) const
Definition: ToolDock.cpp:52

References details::end().

Referenced by Contains(), and ToolManager::OnGrabber().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindPeers()

auto ToolBarConfiguration::FindPeers ( const ToolBar bar)
private

Definition at line 62 of file ToolDock.cpp.

64{
65 auto findTree = [=](Forest &forest){
66 return std::find_if(forest.begin(), forest.end(),
67 [=](const Tree &tree){ return tree.pBar == bar; });
68 };
69
70 auto iter1 = findTree(mForest);
71 if (iter1 != mForest.end())
72 return { &mForest, iter1 };
73
74 Forest::iterator result;
75 auto iter = std::find_if(begin(), end(),
76 [&](const Place &place){
77 auto &children = place.pTree->children;
78 return (result = findTree(children)) != children.end();
79 }
80 );
81 if (iter != end())
82 return { &iter->pTree->children, result };
83
84 return { nullptr, Forest::iterator{} };
85}
Iterator begin()
Definition: ToolDock.h:229
std::vector< Tree > Forest
Definition: ToolDock.h:53

References details::begin(), ToolBarConfiguration::Tree::children, details::end(), and ToolBarConfiguration::Place::pTree.

Referenced by Remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindPlace()

auto ToolBarConfiguration::FindPlace ( const ToolBar bar) const
private

Definition at line 52 of file ToolDock.cpp.

54{
55 auto This = const_cast<ToolBarConfiguration*>(this);
56 return std::find_if(This->begin(), This->end(),
57 [=](const Place &place){
58 return place.pTree->pBar == bar;
59 });
60}

Referenced by Insert(), IsRightmost(), and Write().

Here is the caller graph for this function:

◆ FindToolBar()

ToolBar * ToolBarConfiguration::FindToolBar ( Identifier  id) const

Definition at line 96 of file ToolDock.cpp.

97{
98 if (toolBarID.empty())
99 return nullptr;
100
101 auto This = const_cast<ToolBarConfiguration*>(this);
102 auto it = std::find_if(
103 This->begin(), This->end(),
104 [=](const Place& place)
105 { return place.pTree->pBar->GetSection() == toolBarID; });
106
107 return it != end() ? it->pTree->pBar : nullptr;
108}

References Identifier::empty(), end(), ToolBarConfiguration::Tree::pBar, and ToolBarConfiguration::Place::pTree.

Referenced by Show().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Hide()

void ToolBarConfiguration::Hide ( ToolBar bar)

Definition at line 257 of file ToolDock.cpp.

258{
259 // Future: might hide a bar without eliminating it from the configuration
260 Remove(bar);
261}
void Remove(const ToolBar *bar)
Definition: ToolDock.cpp:224

References Remove().

Referenced by ToolDock::Expose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Insert()

void ToolBarConfiguration::Insert ( ToolBar bar,
Position  position = UnspecifiedPosition 
)

Definition at line 110 of file ToolDock.cpp.

111{
112 if (position == UnspecifiedPosition) {
113 // Add at the "end" of the layout
114 // bottommost and rightmost
115 Forest *pForest = &mForest;
116 while (!pForest->empty())
117 pForest = &pForest->back().children;
118 pForest->push_back( Tree {} );
119 pForest->back().pBar = bar;
120 }
121 else {
122 // Insert at what depth?
123 auto pForest = &mForest;
124 if (position.rightOf) {
125 const auto parent = FindPlace(position.rightOf);
126 if (parent != end())
127 // Insert among children of some node
128 pForest = &parent->pTree->children;
129 }
130 else {
131 // Insert a new root in the top forest
132 }
133
134 // Insert at what breadth?
135 const auto begin = pForest->begin();
136 auto iter = begin;
137 const auto end = pForest->end();
138 bool adopt = false;
139
140 if (position.below) {
141 iter = std::find_if(begin, end,
142 [=](const Tree &tree){ return tree.pBar == position.below; }
143 );
144 if (iter != end) {
145 ++iter;
146 if (iter != end)
147 adopt = true;
148 }
149 else
150 // Not found, default to topmost
151 iter = begin;
152 }
153 else
154 // No previous sibling specified, so insert as first
155 adopt = (iter != end);
156
157 // Insert as a leaf, or as an internal node?
158 if (adopt && position.adopt) {
159 // Existing children of parent become grandchildren
160
161 // Make NEW node
162 Tree tree;
163 tree.pBar = bar;
164
165 // Do adoption
166 const auto barHeight = bar->GetSize().GetY() + toolbarGap;
167 auto totalHeight = 0;
168 while (iter != pForest->end() &&
169 barHeight >=
170 (totalHeight += (iter->pBar->GetSize().GetY() + toolbarGap))) {
171 tree.children.push_back(Tree{});
172 auto &child = tree.children.back();
173 child.pBar = iter->pBar;
174 child.children.swap(iter->children);
175 iter = pForest->erase(iter);
176 }
177
178 // Put the node in the tree
179 iter = pForest->insert(iter, Tree{});
180 (*iter).swap(tree);
181 }
182 else
183 // Insert as a leaf
184 pForest->insert(iter, Tree {})->pBar = bar;
185 }
186}
#define toolbarGap
Definition: ToolBar.h:64

References ToolBarConfiguration::Position::adopt, begin(), ToolBarConfiguration::Position::below, ToolBarConfiguration::Tree::children, end(), FindPlace(), mForest, ToolBarConfiguration::Tree::pBar, ToolBarConfiguration::Position::rightOf, toolbarGap, and UnspecifiedPosition.

Referenced by ToolDock::Dock(), PostRead(), Show(), and ToolDock::VisitLayout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InsertAtPath()

void ToolBarConfiguration::InsertAtPath ( ToolBar bar,
const std::vector< int > &  path 
)

Definition at line 188 of file ToolDock.cpp.

190{
191 auto pForest = &mForest;
192 Tree *pTree {};
193
194 // Guarantee the existence of nodes
195 for (auto ii : path) {
196 Forest::size_type uu = std::max(0, ii);
197 // This may make more than one default-constructed tree, which we
198 // will fill in with some other call to InsertAtPath, or else cleanup
199 // with RemoveNulls
200 pForest->resize(std::max(uu + 1, pForest->size()));
201 pTree = &(*pForest)[uu];
202 pForest = &pTree->children;
203 }
204
205 if (pTree)
206 pTree->pBar = bar;
207}

References mForest.

Referenced by Read().

Here is the caller graph for this function:

◆ IsRightmost()

bool ToolBarConfiguration::IsRightmost ( const ToolBar bar) const

Definition at line 263 of file ToolDock.cpp.

264{
265 auto iter = FindPlace(bar);
266 auto endit = end();
267 if (iter == endit)
268 // not present
269 return true;
270 if (++iter == endit)
271 // Last of all
272 return true;
273 if (bar->GetRect().y != iter->pTree->pBar->GetRect().y)
274 // Next step in preorder traversal is not rightward to a child drawn at
275 // the same height
276 return true;
277 return false;
278}

References end(), and FindPlace().

Referenced by ToolDock::OnPaint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PostRead()

void ToolBarConfiguration::PostRead ( Legacy legacy)

Definition at line 334 of file ToolDock.cpp.

335{
336 // Be sure no nodes contain NULL,
337 // against the case of obsolete preferences, perhaps
339
340 // Interpret what was saved in old .cfg files under "order"
341 // which specified toolbar configuration simply as a sequence, not a tree
342 ToolBar *prev {};
343 for (auto pBar : legacy.bars) {
344 if (!pBar)
345 continue;
346
347 Position position{ prev };
348 Insert(pBar, position);
349
350 prev = pBar;
351 }
352}
void Insert(ToolBar *bar, Position position=UnspecifiedPosition)
Definition: ToolDock.cpp:110
void RemoveNulls(Forest &forest)
Definition: ToolDock.cpp:322
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:74

References ToolBarConfiguration::Legacy::bars, Insert(), mForest, and RemoveNulls().

Referenced by ToolManager::ReadConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Read()

bool ToolBarConfiguration::Read ( ToolBarConfiguration pConfiguration,
Legacy pLegacy,
ToolBar bar,
bool &  visible,
bool  defaultVisible 
)
static

Definition at line 280 of file ToolDock.cpp.

284{
285 bool result = true;
286
287 // Future: might remember visibility in the configuration, not forgetting
288 // positions of hidden bars.
289 gPrefs->Read( wxT("Show"), &visible, defaultVisible);
290
291 if (pConfiguration && visible) {
292 int ord;
293 gPrefs->Read( wxT("Order"), &ord, -1 );
294 // Index was written 1-based
295 --ord;
296 if (ord >= 0)
297 {
298 // Legacy preferences
299 while (pLegacy->bars.size() <= size_t(ord))
300 pLegacy->bars.push_back(nullptr);
301 pLegacy->bars[ord] = bar;
302 }
303 else {
304 wxString strPath;
305 gPrefs->Read( wxT("Path"), &strPath );
306 if (!strPath.empty()) {
307 wxStringTokenizer toker { strPath, wxT(",") };
308 std::vector<int> path;
309 while(toker.HasMoreTokens()) {
310 auto token = toker.GetNextToken();
311 auto ii = wxAtoi(token);
312 path.push_back(ii);
313 }
314 pConfiguration->InsertAtPath(bar, path);
315 }
316 }
317 }
318
319 return result;
320}
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
void InsertAtPath(ToolBar *bar, const std::vector< int > &path)
Definition: ToolDock.cpp:189
virtual bool Read(const wxString &key, bool *value) const =0

References ToolBarConfiguration::Legacy::bars, gPrefs, InsertAtPath(), audacity::BasicSettings::Read(), and wxT().

Referenced by ToolManager::ReadConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Remove() [1/2]

void ToolBarConfiguration::Remove ( const ToolBar bar)

Definition at line 224 of file ToolDock.cpp.

225{
226 auto results = FindPeers(bar);
227 auto pForest = results.first;
228 if (pForest) {
229 // Reparent all of the children of the deleted node
230 auto iter = results.second;
231 wxASSERT(iter->pBar == bar);
232 Remove(*pForest, iter);
233 }
234}
std::pair< Forest *, Forest::iterator > FindPeers(const ToolBar *bar)
Definition: ToolDock.cpp:62

References FindPeers(), and Remove().

Referenced by Hide(), ToolManager::OnMouse(), Remove(), RemoveNulls(), and ToolDock::Undock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Remove() [2/2]

void ToolBarConfiguration::Remove ( Forest forest,
Forest::iterator  iter 
)
private

Definition at line 209 of file ToolDock.cpp.

210{
211 // Reparent all of the children of the deleted node
212 Tree tree;
213 tree.swap(*iter);
214 iter = forest.erase(iter);
215 auto &children = tree.children;
216 auto cIter = children.rbegin(), cEnd = children.rend();
217 while (cIter != cEnd) {
218 iter = forest.insert(iter, Tree{});
219 (*iter).swap(*cIter);
220 ++cIter;
221 }
222}

References ToolBarConfiguration::Tree::children, and ToolBarConfiguration::Tree::swap().

Here is the call graph for this function:

◆ RemoveNulls()

void ToolBarConfiguration::RemoveNulls ( Forest forest)
private

Definition at line 322 of file ToolDock.cpp.

323{
324 for (size_t ii = 0; ii < forest.size(); ++ii) {
325 if(forest[ii].pBar == nullptr)
326 Remove(forest, forest.begin() + ii--);
327 }
328
329 // Now do the same recursively
330 for (auto &tree : forest)
331 RemoveNulls(tree.children);
332}

References Remove(), and RemoveNulls().

Referenced by PostRead(), and RemoveNulls().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Show()

void ToolBarConfiguration::Show ( ToolBar bar)

Definition at line 236 of file ToolDock.cpp.

237{
238 // Do not assume the bar is absent, though in practice that is always so
239 if (!Contains(bar)) {
240 auto position = UnspecifiedPosition;
241 const auto preferredNeighbors = bar->PreferredNeighbors();
242 if (!preferredNeighbors.first.empty() ||
243 !preferredNeighbors.second.empty())
244 {
245 auto leftNeighbor = FindToolBar(preferredNeighbors.first);
246 auto topNeighbor = FindToolBar(preferredNeighbors.second);
247
248 // Perform a sanity check to verify that neighbors are
249 // really inside this configuration
250 if (leftNeighbor != nullptr || topNeighbor != nullptr)
251 position = Position { leftNeighbor, topNeighbor };
252 }
253 Insert(bar, position);
254 }
255}
bool Contains(const ToolBar *bar) const
Definition: ToolDock.h:235
ToolBar * FindToolBar(Identifier id) const
Definition: ToolDock.cpp:96
std::pair< Identifier, Identifier > PreferredNeighbors() const noexcept
Defaults to (NoBarID, NoBarId)
Definition: ToolBar.cpp:451

References Contains(), FindToolBar(), Insert(), ToolBar::PreferredNeighbors(), and UnspecifiedPosition.

Referenced by ToolDock::Expose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shows()

bool ToolBarConfiguration::Shows ( const ToolBar bar) const
inline

Definition at line 248 of file ToolDock.h.

248{ return Contains(bar); }

References Contains().

Referenced by ToolDock::Expose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Swap()

void ToolBarConfiguration::Swap ( ToolBarConfiguration that)
inline

Definition at line 57 of file ToolDock.h.

58 {
59 mForest.swap(that.mForest);
60 }

References mForest.

Referenced by ToolDock::RestoreConfiguration(), and ToolDock::WrapConfiguration().

Here is the caller graph for this function:

◆ Write()

void ToolBarConfiguration::Write ( const ToolBarConfiguration pConfiguration,
const ToolBar bar 
)
static

Definition at line 354 of file ToolDock.cpp.

356{
357 // Assume a path has been set in gPrefs suitable for bar
358 if (pConfiguration) {
359 // Write comma-separated list of numbers specifying position in the tree
360 wxString strPath;
361 const auto cIter = pConfiguration->FindPlace(bar);
362 const auto path = cIter.GetPath();
363 if (!path.empty()) {
364 auto iter = path.begin(), end = path.end();
365 strPath += wxString::Format(wxT("%d"), *iter++);
366 while (iter != end)
367 strPath += wxString::Format(wxT(",%d"), *iter++);
368 }
369 gPrefs->Write(wxT("Path"), strPath);
370
371 // Remove any legacy configuration info.
372 // Note: this causes Audacity 2.1.2 and earlier to create toolbars
373 // always in default position when reading a .cfg saved by Audacity
374 // 2.1.3 or later
375 gPrefs->DeleteEntry(wxT("Order"));
376 }
377 gPrefs->Write( wxT("Show"), bar->IsVisible() );
378}
std::vector< int > GetPath() const
Definition: ToolDock.h:169
bool IsVisible() const
Definition: ToolBar.cpp:441
virtual bool Write(const wxString &key, bool value)=0
bool DeleteEntry(const wxString &key)
Deletes specified entry if exists.

References audacity::BasicSettings::DeleteEntry(), end(), FindPlace(), ToolBarConfiguration::Iterator::GetPath(), gPrefs, ToolBar::IsVisible(), audacity::BasicSettings::Write(), and wxT().

Referenced by ToolManager::WriteConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mForest

Forest ToolBarConfiguration::mForest
private

◆ UnspecifiedPosition

const ToolBarConfiguration::Position ToolBarConfiguration::UnspecifiedPosition { false }
static

Definition at line 106 of file ToolDock.h.

Referenced by Contains(), ToolManager::DoneDragging(), Insert(), ToolDock::PositionBar(), and Show().


The documentation for this class was generated from the following files: