Audacity  2.2.2
Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ToolDock Class Referencefinal

A dynamic panel where a ToolBar can be docked. More...

#include <ToolDock.h>

Inheritance diagram for ToolDock:
wxPanelWrapper wxTabTraversalWrapper< wxPanel >

Classes

class  LayoutVisitor
 

Public Member Functions

 ToolDock (ToolManager *manager, wxWindow *parent, int dockid)
 Methods for ToolDock. More...
 
 ~ToolDock ()
 
bool AcceptsFocus () const override
 
void LoadConfig ()
 
void LayoutToolBars ()
 
void Expose (int type, bool show)
 
int GetOrder (ToolBar *bar)
 
void Dock (ToolBar *bar, bool deflate, ToolBarConfiguration::Position ndx=ToolBarConfiguration::UnspecifiedPosition)
 
void Undock (ToolBar *bar)
 
ToolBarConfiguration::Position PositionBar (ToolBar *t, const wxPoint &pos, wxRect &rect)
 
ToolBarConfigurationGetConfiguration ()
 
void WrapConfiguration (ToolBarConfiguration &backup)
 
void RestoreConfiguration (ToolBarConfiguration &backup)
 
void Updated ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&...args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Protected Member Functions

void OnErase (wxEraseEvent &event)
 
void OnSize (wxSizeEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnGrabber (GrabberEvent &event)
 
void OnMouseEvents (wxMouseEvent &event)
 

Private Member Functions

void VisitLayout (LayoutVisitor &visitor, ToolBarConfiguration *pWrappedConfiguration=nullptr)
 

Private Attributes

ToolManagermManager
 
ToolBarConfiguration mConfiguration
 
ToolBarConfiguration mWrappedConfiguration
 
ToolBarmBars [ToolBarCount]
 

Detailed Description

A dynamic panel where a ToolBar can be docked.

Definition at line 290 of file ToolDock.h.

Constructor & Destructor Documentation

ToolDock::ToolDock ( ToolManager manager,
wxWindow *  parent,
int  dockid 
)

Methods for ToolDock.

Definition at line 376 of file ToolDock.cpp.

References _(), ThemeBase::Colour(), and theTheme.

376  :
377  wxPanelWrapper( parent, dockid, wxDefaultPosition, parent->GetSize() )
378 {
379  SetLabel( _( "ToolDock" ) );
380  SetName( _( "ToolDock" ) );
381 
382  // Init
383  mManager = manager;
384  memset(mBars, 0, sizeof(mBars)); // otherwise uninitialized
385  SetBackgroundColour(theTheme.Colour( clrMedium ));
386  // Use for testing gaps
387  // SetOwnBackgroundColour( wxColour( 255, 0, 0 ) );
388 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
ToolManager * mManager
Definition: ToolDock.h:336
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
ToolBar * mBars[ToolBarCount]
Definition: ToolDock.h:344
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
ToolDock::~ToolDock ( )

Definition at line 393 of file ToolDock.cpp.

394 {
395 }

Member Function Documentation

bool ToolDock::AcceptsFocus ( ) const
inlineoverride

Definition at line 297 of file ToolDock.h.

297 { return false; };
void ToolDock::Dock ( ToolBar bar,
bool  deflate,
ToolBarConfiguration::Position  ndx = ToolBarConfiguration::UnspecifiedPosition 
)

Definition at line 412 of file ToolDock.cpp.

References ToolBarConfiguration::Contains(), ToolBar::GetDockedSize(), ToolBarConfiguration::Insert(), ToolBar::IsVisible(), LayoutToolBars(), mBars, mConfiguration, ToolBar::SetDocked(), ToolBarFloatMargin, and Updated().

Referenced by ToolManager::HandleEscapeKey(), LoadConfig(), ToolManager::OnMouse(), ToolManager::ReadConfig(), and ToolManager::Reset().

413 {
414 #ifndef __WXMAC__
415  // Apply the deflate fix only on Mac, else you introduce the opposite bug on others
416  deflate = false;
417 #endif
418 
419  // Adopt the toolbar into our family
420  bar->Reparent( this );
421  mBars[ bar->GetId() ] = bar;
422 
423  // Reset size
424  bar->SetSize(
425  // Undo the expansion that was applied when un-docking
426  bar->GetSize().x - (deflate ? 2 * ToolBarFloatMargin : 0),
427  // Don't need to adjust y the same way.
428  bar->GetDockedSize().y
429  );
430 
431  // Park the NEW bar in the correct berth
432  if (!mConfiguration.Contains(bar) && bar->IsVisible())
433  mConfiguration.Insert( bar, position );
434 
435  // Inform toolbar of change
436  bar->SetDocked( this, false );
437 
438  // Rearrange our world
439  if (bar->IsVisible())
440  LayoutToolBars();
441  Updated();
442 }
bool Contains(const ToolBar *bar) const
Definition: ToolDock.h:234
bool IsVisible() const
Definition: ToolBar.cpp:402
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339
ToolBar * mBars[ToolBarCount]
Definition: ToolDock.h:344
void Insert(ToolBar *bar, Position position=UnspecifiedPosition)
Definition: ToolDock.cpp:101
void Updated()
Definition: ToolDock.cpp:854
virtual wxSize GetDockedSize()
Definition: ToolBar.h:129
void SetDocked(ToolDock *dock, bool pushed)
Definition: ToolBar.cpp:572
void LayoutToolBars()
Definition: ToolDock.cpp:664
void ToolDock::Expose ( int  type,
bool  show 
)

Definition at line 831 of file ToolDock.cpp.

References ToolBar::Expose(), ToolBarConfiguration::Hide(), LayoutToolBars(), mBars, mConfiguration, ToolBarConfiguration::Show(), ToolBarConfiguration::Shows(), and Updated().

Referenced by ToolManager::Expose(), and LoadConfig().

832 {
833  ToolBar *t = mBars[ type ];
834 
835  // Maintain the docked array
836  const auto shown = mConfiguration.Shows( t );
837  if( show && !shown )
838  mConfiguration.Show( t );
839  else if( !show && shown )
840  mConfiguration.Hide( t );
841 
842  // Make it (dis)appear
843  t->Expose( show );
844 
845  // Update the layout
846  LayoutToolBars();
847  Updated();
848 }
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:415
void Hide(ToolBar *bar)
Definition: ToolDock.cpp:229
void Show(ToolBar *bar)
Definition: ToolDock.cpp:222
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339
ToolBar * mBars[ToolBarCount]
Definition: ToolDock.h:344
void Updated()
Definition: ToolDock.cpp:854
bool Shows(const ToolBar *bar) const
Definition: ToolDock.h:247
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
void LayoutToolBars()
Definition: ToolDock.cpp:664
ToolBarConfiguration& ToolDock::GetConfiguration ( )
inline
int ToolDock::GetOrder ( ToolBar bar)
void ToolDock::LayoutToolBars ( )

Definition at line 664 of file ToolDock.cpp.

References GetConfiguration(), mWrappedConfiguration, and VisitLayout().

Referenced by Dock(), Expose(), and ToolManager::LayoutToolBars().

665 {
666  struct SizeSetter final : public LayoutVisitor
667  {
668  SizeSetter (ToolDock *d) : dock{ d } {}
669 
670  void Visit
671  (ToolBar *bar, wxPoint point)
672  override
673  {
674  // Place the toolbar
675  if(bar)
676  bar->SetPosition( point );
677  }
678 
679  bool ShouldVisitSpaces() override
680  {
681  return false;
682  }
683 
684  virtual void FinalRect
685  (const wxRect &rect, ToolBarConfiguration::Position)
686  override
687  {
688  // Set the final size of the dock window
689  dock->SetMinSize( rect.GetSize() );
690  }
691 
692  ToolDock *dock;
693  } sizeSetter {
694  this
695  };
696  VisitLayout(sizeSetter, &mWrappedConfiguration);
697 
698  // Set tab order
699  {
700  ToolBar *lt{};
701  for ( const auto &place : GetConfiguration() ) {
702  auto ct = place.pTree->pBar;
703  if( lt )
704  ct->MoveAfterInTabOrder( lt );
705  lt = ct;
706  }
707  }
708 
709  // Clean things up
710  Refresh( false );
711 }
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
ToolBarConfiguration mWrappedConfiguration
Definition: ToolDock.h:342
void VisitLayout(LayoutVisitor &visitor, ToolBarConfiguration *pWrappedConfiguration=nullptr)
Definition: ToolDock.cpp:483
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
ToolBarConfiguration & GetConfiguration()
Definition: ToolDock.h:310
void ToolDock::LoadConfig ( )

Definition at line 445 of file ToolDock.cpp.

References Dock(), Expose(), and GetConfiguration().

Referenced by ToolManager::ReadConfig().

446 {
447  // Add all ordered toolbars
448  for(const auto &place : GetConfiguration()) {
449  auto bar = place.pTree->pBar;
450  this->Dock(bar, false);
451  // Show it -- hidden bars are not (yet) ever saved as part of a
452  // configuration
453  Expose( bar->GetId(), true );
454  }
455 }
void Dock(ToolBar *bar, bool deflate, ToolBarConfiguration::Position ndx=ToolBarConfiguration::UnspecifiedPosition)
Definition: ToolDock.cpp:412
void Expose(int type, bool show)
Definition: ToolDock.cpp:831
ToolBarConfiguration & GetConfiguration()
Definition: ToolDock.h:310
void ToolDock::OnErase ( wxEraseEvent &  event)
protected

Definition at line 884 of file ToolDock.cpp.

885 {
886  // Ignore it to prevent flashing
887 }
void ToolDock::OnGrabber ( GrabberEvent event)
protected

Definition at line 864 of file ToolDock.cpp.

References GrabberEvent::IsEscaping(), and mManager.

865 {
866  // auto pos = event.GetPosition();
867  if (!event.IsEscaping()) {
868  // Pass it on to the manager since it isn't in the handling hierarchy
869  mManager->ProcessEvent( event );
870  }
871 }
bool IsEscaping() const
Definition: Grabber.h:70
ToolManager * mManager
Definition: ToolDock.h:336
void ToolDock::OnMouseEvents ( wxMouseEvent &  event)
protected

Definition at line 945 of file ToolDock.cpp.

946 {
947  // Do this hack so scrubber can detect mouse drags anywhere
948  event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
949  event.Skip();
950 }
void ToolDock::OnPaint ( wxPaintEvent &  event)
protected

Definition at line 892 of file ToolDock.cpp.

References ThemeBase::Colour(), AColor::Dark(), GetConfiguration(), ToolBarConfiguration::IsRightmost(), AColor::Line(), mConfiguration, and theTheme.

893 {
894  // Don't use a wxBufferedPaintDC() here. It produces a bogus
895  // background on Windows and GTK.
896  wxPaintDC dc( this );
897 
898  // Start with a clean background
899  //
900  // Under GTK, we don't set the toolbar background to the background
901  // colour in the system theme. Instead we use our own colour.
902 
903  dc.SetBackground( wxBrush( theTheme.Colour( clrMedium )));
904  dc.Clear();
905 
906  // Set the gap color
907  AColor::Dark( &dc, false );
908 
909  // Draw the initial horizontal and vertical gaps
910  wxSize sz = GetClientSize();
911 
912  AColor::Line(dc, 0, 0, sz.GetWidth(), 0 );
913  AColor::Line(dc, 0, 0, 0, sz.GetHeight() );
914 
915  // Draw the gap between each bar
916  for (const auto &place : GetConfiguration())
917  {
918  auto toolbar = place.pTree->pBar;
919  if (!toolbar)
920  continue;
921 
922  wxRect r = toolbar->GetRect();
923 
924  // Draw a horizontal line under the bar extending to the right edge of
925  // the dock
926  AColor::Line( dc,
927  r.GetLeft(),
928  r.GetBottom() + 1,
929  sz.GetWidth(),
930  r.GetBottom() + 1 );
931 
932  // For all bars but the last...
933  // ...and for bars that aren't the last in a row, draw a
934  // vertical gap line
935  if (!mConfiguration.IsRightmost(toolbar)) {
936  AColor::Line(dc,
937  r.GetRight() + 1,
938  r.GetTop(),
939  r.GetRight() + 1,
940  r.GetBottom() + 1 );
941  }
942  }
943 }
bool IsRightmost(const ToolBar *bar) const
Definition: ToolDock.cpp:235
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:338
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
ToolBarConfiguration & GetConfiguration()
Definition: ToolDock.h:310
void ToolDock::OnSize ( wxSizeEvent &  event)
protected

Definition at line 876 of file ToolDock.cpp.

877 {
878 // event.Skip();
879 }
ToolBarConfiguration::Position ToolDock::PositionBar ( ToolBar t,
const wxPoint &  pos,
wxRect &  rect 
)

Definition at line 717 of file ToolDock.cpp.

References ToolBarConfiguration::Position::adopt, ToolBarConfiguration::UnspecifiedPosition, and VisitLayout().

Referenced by ToolManager::OnMouse().

718 {
719  // Set width and size, but we must still find x and y.
720  rect = t->GetRect();
721 
722  using Position = ToolBarConfiguration::Position;
723  Position result { ToolBarConfiguration::UnspecifiedPosition };
724  struct Inserter : public LayoutVisitor
725  {
726  struct Stop {};
727 
728  Inserter(Position &p, wxRect &r, const wxPoint &pt, ToolBar *t)
729  : result(p), rect(r), point(pt), tb(t)
730  {}
731 
732  void ModifySize
733  (ToolBar *ct,
734  const wxRect &rect,
735  ToolBarConfiguration::Position prevPosition,
737  wxSize &sz)
738  override
739  {
740  // Maybe insert the NEW bar if it hasn't already been done
741  // and is in the right place.
742 
743  // Does the location fall within this bar?
744  if (rect.Contains(point))
745  {
746  sz = tb->GetDockedSize();
747  // Choose a position always, if there is a bar to displace.
748  // Else, only if the fit is possible.
749  if (ct || (sz.x <= rect.width && sz.y <= rect.height)) {
750  // May choose current or previous.
751  if (ct &&
752  (sz.y < rect.height ||
753  point.y < (rect.GetTop() + rect.GetBottom()) / 2))
754  // "Wedge" the bar into a crack alone, not adopting others,
755  // if either a short bar displaces a tall one, or else
756  // the displacing bar is at least at tall, but the pointer is
757  // in the upper half of the box.
758  usedPrev = true, result = prevPosition, result.adopt = false;
759  else
760  result = position;
761  }
762  // Now wait until the other callback below to discover x and y
763  }
764  }
765 
766  void Visit
767  (ToolBar *, wxPoint point)
768  override
769  {
771  // If we've placed it, we're done.
772  rect.x = point.x;
773  rect.y = point.y;
774  if (usedPrev)
775  rect.y -= tb->GetDockedSize().GetHeight() / 2;
776 
777  throw Stop {};
778  }
779  }
780 
781  bool ShouldVisitSpaces() override
782  {
783  return true;
784  }
785 
786  void FinalRect
787  (const wxRect &finalRect, ToolBarConfiguration::Position finalPosition)
788  override
789  {
791  // Default of all other placements.
792  result = finalPosition;
793  wxPoint point { finalRect.GetLeft(), finalRect.GetBottom() };
794  rect.SetPosition(point);
795  }
796  }
797 
798 
799  Position &result;
800  wxRect &rect;
801  const wxPoint point;
802  ToolBar *const tb;
803  bool usedPrev { false };
804  } inserter {
805  result, rect, pos, t
806  };
807 
808  try { this->VisitLayout(inserter); } catch (const Inserter::Stop&) {}
809 
810  // rect is decided
811  return result;
812 }
static const Position UnspecifiedPosition
Definition: ToolDock.h:106
void VisitLayout(LayoutVisitor &visitor, ToolBarConfiguration *pWrappedConfiguration=nullptr)
Definition: ToolDock.cpp:483
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
void ToolDock::RestoreConfiguration ( ToolBarConfiguration backup)

Definition at line 821 of file ToolDock.cpp.

References ToolBarConfiguration::Clear(), mConfiguration, mWrappedConfiguration, and ToolBarConfiguration::Swap().

Referenced by ToolManager::HandleEscapeKey(), and ToolManager::OnMouse().

822 {
825  mConfiguration.Swap(backup);
826 }
void Swap(ToolBarConfiguration &that)
Definition: ToolDock.h:57
ToolBarConfiguration mWrappedConfiguration
Definition: ToolDock.h:342
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339
void ToolDock::Undock ( ToolBar bar)

Definition at line 400 of file ToolDock.cpp.

References ToolBarConfiguration::Contains(), mBars, mConfiguration, and ToolBarConfiguration::Remove().

Referenced by ToolManager::Reset().

401 {
402  if( mConfiguration.Contains( bar ) )
403  {
404  mConfiguration.Remove( bar );
405  }
406  mBars[ bar->GetId() ] = nullptr;
407 }
bool Contains(const ToolBar *bar) const
Definition: ToolDock.h:234
void Remove(const ToolBar *bar)
Definition: ToolDock.cpp:210
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339
ToolBar * mBars[ToolBarCount]
Definition: ToolDock.h:344
void ToolDock::Updated ( )

Definition at line 854 of file ToolDock.cpp.

Referenced by Dock(), Expose(), and ToolBar::Updated().

855 {
856  // Queue an update event
857  wxCommandEvent e( EVT_TOOLBAR_UPDATED, GetId() );
858  GetParent()->GetEventHandler()->AddPendingEvent( e );
859 }
void ToolDock::VisitLayout ( LayoutVisitor visitor,
ToolBarConfiguration pWrappedConfiguration = nullptr 
)
private

Definition at line 483 of file ToolDock.cpp.

References ToolBarConfiguration::Clear(), ToolDock::LayoutVisitor::FinalRect(), GetConfiguration(), ToolBar::GetType(), ToolBarConfiguration::Insert(), mBars, ToolDock::LayoutVisitor::ModifySize(), NoBarID, ToolDock::LayoutVisitor::ShouldVisitSpaces(), ToolBarCount, toolbarGap, and ToolDock::LayoutVisitor::Visit().

Referenced by LayoutToolBars(), and PositionBar().

485 {
486  if (pWrappedConfiguration)
487  pWrappedConfiguration->Clear();
488 
489  // Get size of our parent since we haven't been sized yet
490  int width, height;
491  GetParent()->GetClientSize( &width, &height );
492  width -= toolbarGap;
493  height -= toolbarGap;
494 
495  // Rectangle of space to allocate
496  wxRect main{ toolbarGap, toolbarGap,
497  // Allow limited width, but arbitrary height, for the root rectangle
498  width, std::numeric_limits<int>::max() };
499 
500  // For recording the nested subdivisions of the rectangle
501  struct Item {
502  int myBarID { NoBarID };
503  int parentBarID { NoBarID };
504  ToolBar *lastSib {};
505  ToolBar *lastWrappedChild {};
506  wxRect rect;
507  } layout[ ToolBarCount ];
508 
509  ToolBar *lastRoot {};
510  ToolBar *lastWrappedRoot {};
511 
512  // Process all docked and visible toolbars
513  for ( const auto &place : this->GetConfiguration() )
514  {
515  // Cache toolbar pointer
516  const auto ct = place.pTree->pBar;
517 
518  // set up the chain of ancestors.
519  const auto parent = place.position.rightOf;
520  const auto type = ct->GetType();
521  auto &newItem = layout[ type ];
522  newItem.parentBarID = parent ? parent->GetType() : NoBarID;
523  // Mark the slots that really were visited, for final pass through
524  // the spaces.
525  newItem.myBarID = type;
526 
527  const auto parentItem = parent ? &layout[ parent->GetType() ] : nullptr;
528  ToolBar *prevSib;
529  if (!parent) {
530  prevSib = lastRoot;
531  lastRoot = ct;
532  }
533  else {
534  auto &sib = parentItem->lastSib;
535  prevSib = sib;
536  sib = ct;
537  }
538  auto prevPosition = ToolBarConfiguration::Position{ parent, prevSib };
539 
540  // Determine the size of the toolbar to fit, with advice from
541  // the visitor object
542  wxSize sz = ct->GetSize();
543  {
544  wxRect temp;
545  temp.SetPosition(ct->GetParent()->ClientToScreen(ct->GetPosition()));
546  temp.SetSize(sz);
547  visitor.ModifySize(ct, temp, prevPosition, place.position, sz);
548  }
549 
550  // Inflate the size to leave margins
551  int tw = sz.GetWidth() + toolbarGap;
552  int th = sz.GetHeight() + toolbarGap;
553 
554  // Choose the rectangle to subdivide
555  // Find a box that we fit in by going up the tree as needed --
556  // thus when parent space is exhausted, fall back on ancestors --
557  // so if the tree has too much depth for the width of the
558  // window, the toolbars may "wrap."
559  // Can always fall back to the main rectangle even if the bar is too
560  // wide.
561  auto pItem = parentItem;
562  auto pRect = pItem ? &pItem->rect : &main;
563  while (pRect != &main)
564  {
565  // Get out if it will fit
566  bool bTooWide = tw > pRect->GetWidth();
567  // We'd like to be able to add a tall toolbar in at the start of a row,
568  // even if there isn't enough height for it.
569  // If so, we'd have to at least change how we calculate 'bTooHigh'.
570  bool bTooHigh = th > pRect->GetHeight();
571  //bTooHigh &= stack[stkcnt].GetWidth() < (width - toolbarGap);
572  //bTooHigh = false;
573 
574  if (!bTooWide && !bTooHigh)
575  break;
576 
577  if (pItem->parentBarID == NoBarID) {
578  pItem = nullptr;
579  pRect = &main;
580  }
581  else {
582  pItem = &layout[ pItem->parentBarID ];
583  pRect = &pItem->rect;
584  }
585  }
586 
587  // Record where the toolbar wrapped
588  ToolBar *& sib = pItem ? pItem->lastWrappedChild : lastWrappedRoot;
589  ToolBarConfiguration::Position newPosition {
590  pItem ? this->mBars[ pItem->myBarID ] : nullptr,
591  sib
592  };
593  sib = ct;
594  if (pWrappedConfiguration)
595  pWrappedConfiguration->Insert(ct, newPosition);
596 
597  // Place the toolbar at the upper left part of the rectangle.
598  const auto cpos = pRect->GetPosition();
599  visitor.Visit(ct, cpos);
600 
601  // Allocate an upper portion of the rectangle to this bar.
602  pRect->y += th;
603  pRect->height -= th;
604 
605  // A right portion of that upper portion remains available for
606  // descendant bars and is remembered in the layout array.
607  int x = cpos.x + tw;
608  newItem.rect = wxRect{ x, cpos.y, width - x, th };
609  }
610 
611  if (visitor.ShouldVisitSpaces()) {
612  // Visit the fringe where NEW leaves of the tree could go
613 
614  // Find the items with leftover spaces
615  const auto end = std::remove_if(layout, layout + ToolBarCount,
616  [](const Item &item){
617  return item.myBarID == NoBarID || item.rect.IsEmpty();
618  }
619  );
620  // Sort top to bottom for definiteness, though perhaps not really needed
621  std::sort(layout, end,
622  [](const Item &lhs, const Item &rhs){
623  return lhs.rect.y < rhs.rect.y;
624  }
625  );
626  for (auto iter = layout; iter != end; ++iter) {
627  const auto &item = *iter;
628  const auto &rect = item.rect;
629 
630  auto globalRect = rect;
631  globalRect.SetPosition( this->ClientToScreen(rect.GetPosition()) );
632 
633  // Let the visitor determine size
634  wxSize sz {};
636  position { this->mBars[ item.myBarID ], item.lastWrappedChild },
637  prevPosition {};
638  visitor.ModifySize(nullptr, globalRect, prevPosition, position, sz);
639  int tw = sz.GetWidth() + toolbarGap;
640  int th = sz.GetHeight() + toolbarGap;
641 
642  // Test fit
643  bool bTooWide = tw > rect.GetWidth();
644  bool bTooHigh = th > rect.GetHeight();
645  if (!bTooWide && !bTooHigh) {
646  // Call visitor again to confirm the placement
647  const auto cpos = rect.GetPosition();
648  visitor.Visit(nullptr, cpos);
649  }
650  }
651  }
652 
653  // Report the final bounding box of all the bars, and a position where
654  // you can insert a NEW bar at bottom left.
655  ToolBarConfiguration::Position finalPosition { nullptr, lastRoot };
656  visitor.FinalRect(
657  wxRect { toolbarGap, toolbarGap, main.width, main.y }, finalPosition
658  );
659 }
#define toolbarGap
Definition: ToolBar.h:59
ToolBar * mBars[ToolBarCount]
Definition: ToolDock.h:344
void Insert(ToolBar *bar, Position position=UnspecifiedPosition)
Definition: ToolDock.cpp:101
int GetType()
Definition: ToolBar.cpp:370
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
ToolBarConfiguration & GetConfiguration()
Definition: ToolDock.h:310
void ToolDock::WrapConfiguration ( ToolBarConfiguration backup)

Definition at line 814 of file ToolDock.cpp.

References ToolBarConfiguration::Clear(), mConfiguration, mWrappedConfiguration, and ToolBarConfiguration::Swap().

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

815 {
816  backup.Clear();
817  backup.Swap(mConfiguration);
819 }
void Swap(ToolBarConfiguration &that)
Definition: ToolDock.h:57
ToolBarConfiguration mWrappedConfiguration
Definition: ToolDock.h:342
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339

Member Data Documentation

ToolBar* ToolDock::mBars[ToolBarCount]
private

Definition at line 344 of file ToolDock.h.

Referenced by Dock(), Expose(), Undock(), and VisitLayout().

ToolBarConfiguration ToolDock::mConfiguration
private
ToolManager* ToolDock::mManager
private

Definition at line 336 of file ToolDock.h.

Referenced by OnGrabber().

ToolBarConfiguration ToolDock::mWrappedConfiguration
private

Definition at line 342 of file ToolDock.h.

Referenced by LayoutToolBars(), RestoreConfiguration(), and WrapConfiguration().


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