Audacity  2.3.1
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 381 of file ToolDock.cpp.

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

381  :
382  wxPanelWrapper( parent, dockid, wxDefaultPosition, parent->GetSize() )
383 {
384  SetLabel( _( "ToolDock" ) );
385  SetName( _( "ToolDock" ) );
386 
387  // Init
388  mManager = manager;
389  memset(mBars, 0, sizeof(mBars)); // otherwise uninitialized
390  SetBackgroundColour(theTheme.Colour( clrMedium ));
391  SetLayoutDirection(wxLayout_LeftToRight);
392  // Use for testing gaps
393  // SetOwnBackgroundColour( wxColour( 255, 0, 0 ) );
394 }
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 399 of file ToolDock.cpp.

400 {
401 }

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 418 of file ToolDock.cpp.

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

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

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

Definition at line 833 of file ToolDock.cpp.

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

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

834 {
835  ToolBar *t = mBars[ type ];
836 
837  // Maintain the docked array
838  const auto shown = mConfiguration.Shows( t );
839  if( show && !shown )
840  mConfiguration.Show( t );
841  else if( !show && shown )
842  mConfiguration.Hide( t );
843 
844  // Make it (dis)appear
845  t->Expose( show );
846 }
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:418
void Hide(ToolBar *bar)
Definition: ToolDock.cpp:234
void Show(ToolBar *bar)
Definition: ToolDock.cpp:227
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339
ToolBar * mBars[ToolBarCount]
Definition: ToolDock.h:344
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
ToolBarConfiguration& ToolDock::GetConfiguration ( )
inline
int ToolDock::GetOrder ( ToolBar bar)
void ToolDock::LayoutToolBars ( )

Definition at line 666 of file ToolDock.cpp.

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

Referenced by ToolManager::LayoutToolBars().

667 {
668  struct SizeSetter final : public LayoutVisitor
669  {
670  SizeSetter (ToolDock *d) : dock{ d } {}
671 
672  void Visit
673  (ToolBar *bar, wxPoint point)
674  override
675  {
676  // Place the toolbar
677  if(bar)
678  bar->SetPosition( point );
679  }
680 
681  bool ShouldVisitSpaces() override
682  {
683  return false;
684  }
685 
686  virtual void FinalRect
687  (const wxRect &rect, ToolBarConfiguration::Position)
688  override
689  {
690  // Set the final size of the dock window
691  dock->SetMinSize( rect.GetSize() );
692  }
693 
694  ToolDock *dock;
695  } sizeSetter {
696  this
697  };
698  VisitLayout(sizeSetter, &mWrappedConfiguration);
699 
700  // Set tab order
701  {
702  ToolBar *lt{};
703  for ( const auto &place : GetConfiguration() ) {
704  auto ct = place.pTree->pBar;
705  if( lt )
706  ct->MoveAfterInTabOrder( lt );
707  lt = ct;
708  }
709  }
710 
711  // Clean things up
712  Refresh( false );
713 }
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:485
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 446 of file ToolDock.cpp.

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

Referenced by ToolManager::ReadConfig().

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

Definition at line 882 of file ToolDock.cpp.

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

Definition at line 862 of file ToolDock.cpp.

References GrabberEvent::IsEscaping(), and mManager.

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

Definition at line 943 of file ToolDock.cpp.

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

Definition at line 890 of file ToolDock.cpp.

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

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

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

Definition at line 719 of file ToolDock.cpp.

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

Referenced by ToolManager::OnMouse().

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

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

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

824 {
827  mConfiguration.Swap(backup);
828 }
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 406 of file ToolDock.cpp.

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

Referenced by ToolManager::Reset().

407 {
408  if( mConfiguration.Contains( bar ) )
409  {
410  mConfiguration.Remove( bar );
411  }
412  mBars[ bar->GetId() ] = nullptr;
413 }
bool Contains(const ToolBar *bar) const
Definition: ToolDock.h:234
void Remove(const ToolBar *bar)
Definition: ToolDock.cpp:215
ToolBarConfiguration mConfiguration
Definition: ToolDock.h:339
ToolBar * mBars[ToolBarCount]
Definition: ToolDock.h:344
void ToolDock::Updated ( )

Definition at line 852 of file ToolDock.cpp.

Referenced by LoadConfig(), and ToolBar::Updated().

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

Definition at line 485 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().

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

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

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

817 {
818  backup.Clear();
819  backup.Swap(mConfiguration);
821 }
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: