Audacity 3.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ToolBarArea Class Referencefinal

An alternative to ToolBarFrame which can contain an ExpandingToolBar. ToolBarArea is used for a 'docked' ToolBar, ToolBarFrame for a floating one. More...

#include <ExpandingToolBar.h>

Inheritance diagram for ToolBarArea:
[legend]
Collaboration diagram for ToolBarArea:
[legend]

Public Member Functions

 ToolBarArea (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
 ~ToolBarArea ()
 
bool Layout () override
 
void Fit () override
 
void OnSize (wxSizeEvent &evt)
 
void OnMouse (wxMouseEvent &evt)
 
void CollapseAll (bool now=false)
 
void AddChild (ExpandingToolBar *child)
 
void RemoveChild (ExpandingToolBar *child)
 
std::unique_ptr< ToolBarArrangementSaveArrangement ()
 
void RestoreArrangement (std::unique_ptr< ToolBarArrangement > &&arrangement)
 
std::vector< wxRect > GetDropTargets ()
 
void MoveChild (ExpandingToolBar *child, wxRect dropTarget)
 
void SetCapturedChild (ExpandingToolBar *child)
 
- 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 TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- 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 ContractRow (int rowIndex)
 
bool ExpandRow (int rowIndex)
 
void LayoutOne (int childIndex)
 
void AdjustLayout ()
 
void Fit (bool horizontal, bool vertical)
 

Protected Attributes

std::vector< ExpandingToolBar * > mChildArray
 
std::vector< int > mRowArray
 
wxSize mLastLayoutSize
 
bool mInOnSize
 
ExpandingToolBarmCapturedChild
 
wxSize mMinSize
 
wxSize mMaxSize
 
wxSize mActualSize
 
std::vector< wxRect > mDropTargets
 
std::vector< int > mDropTargetIndices
 
std::vector< int > mDropTargetRows
 

Detailed Description

An alternative to ToolBarFrame which can contain an ExpandingToolBar. ToolBarArea is used for a 'docked' ToolBar, ToolBarFrame for a floating one.

Definition at line 196 of file ExpandingToolBar.h.

Constructor & Destructor Documentation

◆ ToolBarArea()

ToolBarArea::ToolBarArea ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize 
)

Definition at line 843 of file ExpandingToolBar.cpp.

846 :
847 wxPanelWrapper(parent, id, pos, size),
848 mInOnSize(false),
849 mCapturedChild(NULL)
850{
851
852}
ExpandingToolBar * mCapturedChild

◆ ~ToolBarArea()

ToolBarArea::~ToolBarArea ( )

Definition at line 854 of file ExpandingToolBar.cpp.

855{
856}

Member Function Documentation

◆ AddChild()

void ToolBarArea::AddChild ( ExpandingToolBar child)

Definition at line 1154 of file ExpandingToolBar.cpp.

1155{
1156 mChildArray.push_back(child);
1157 mRowArray.push_back(-1); // unknown row
1158 LayoutOne(mChildArray.size() - 1);
1159 Fit(false, true);
1160}
std::vector< int > mRowArray
std::vector< ExpandingToolBar * > mChildArray
void Fit() override
void LayoutOne(int childIndex)

References Fit(), LayoutOne(), mChildArray, and mRowArray.

Referenced by ExpandingToolBar::OnSize().

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

◆ AdjustLayout()

void ToolBarArea::AdjustLayout ( )
protected

Definition at line 1030 of file ExpandingToolBar.cpp.

1031{
1032 // Try to modify the layout as little as possible - but if that's
1033 // impossible, redo the layout as necessary.
1034
1035 int row = -1;
1036 int i, j;
1037
1038 for(i = 0; i < (int)mChildArray.size(); i++) {
1039 if (mRowArray[i] > row) {
1040 row = mRowArray[i];
1041 bool success = ExpandRow(row);
1042 if (!success) {
1043 // Re-layout all toolbars from this row on
1044 for(j = i; j < (int)mChildArray.size(); j++)
1045 LayoutOne(j);
1046 return;
1047 }
1048 }
1049 }
1050}
bool ExpandRow(int rowIndex)

References ExpandRow(), LayoutOne(), mChildArray, and mRowArray.

Referenced by OnSize().

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

◆ CollapseAll()

void ToolBarArea::CollapseAll ( bool  now = false)

Definition at line 1146 of file ExpandingToolBar.cpp.

1147{
1148 int i;
1149
1150 for(i = 0; i < (int)mChildArray.size(); i++)
1151 mChildArray[i]->Collapse(now);
1152}

References mChildArray.

Referenced by ExpandingToolBar::FinishMoving(), and ExpandingToolBar::StartMoving().

Here is the caller graph for this function:

◆ ContractRow()

void ToolBarArea::ContractRow ( int  rowIndex)
protected

Definition at line 858 of file ExpandingToolBar.cpp.

859{
860 // Contract all of the toolbars in a given row to their
861 // minimum size. This is an intermediate step in layout.
862
863 int i;
864 int x = 0;
865
866 for(i = 0; i < (int)mChildArray.size(); i++)
867 if (mRowArray[i] == rowIndex) {
868 wxPoint childPos = mChildArray[i]->GetPosition();
869 wxSize childMin = mChildArray[i]->GetMinSize();
870
871 mChildArray[i]->SetSize(x, childPos.y,
872 childMin.x, childMin.y);
873 x += childMin.x;
874 }
875}

References mChildArray, and mRowArray.

Referenced by LayoutOne(), and MoveChild().

Here is the caller graph for this function:

◆ ExpandRow()

bool ToolBarArea::ExpandRow ( int  rowIndex)
protected

Definition at line 877 of file ExpandingToolBar.cpp.

878{
879 // Expand all of the toolbars in a given row so that the
880 // whole width is filled, if possible. This is the last
881 // step after laying out as many toolbars as possible in
882 // that row. Returns false if it's not possible to fit
883 // all of these toolbars in one row anymore.
884
885 wxSize area = GetClientSize();
886 int i, j, x;
887 int minWidth = 0;
888 int leftoverSpace = 0;
889 int expandableCount = 0;
890 int toolbarCount = 0;
891
892 for(i = 0; i < (int)mChildArray.size(); i++)
893 if (mRowArray[i] == rowIndex) {
894 ExpandingToolBar *child = mChildArray[i];
895 wxSize childMin = child->GetMinSize();
896 wxSize childMax = child->GetMaxSize();
897
898 minWidth += childMin.x;
899
900 toolbarCount++;
901 if (childMax.x > childMin.x)
902 expandableCount++;
903 }
904
905 leftoverSpace = area.x - minWidth;
906
907 if (leftoverSpace <= 0) {
908 if (toolbarCount > 1)
909 return false; // not possible to fit all in one row
910 else
911 return true; // there's only one, so it doesn't matter
912 }
913
914 j = 0;
915 x = 0;
916 for(i = 0; i < (int)mChildArray.size(); i++)
917 if (mRowArray[i] == rowIndex) {
918 ExpandingToolBar *child = mChildArray[i];
919 wxPoint childPos = child->GetPosition();
920 wxSize childMin = child->GetMinSize();
921 wxSize childMax = child->GetMaxSize();
922
923 int width = childMin.x;
924
925 if (childMax.x > childMin.x)
926 width +=
927 (leftoverSpace * (j+1) / expandableCount) -
928 (leftoverSpace * (j) / expandableCount);
929
930 mChildArray[i]->SetSize(x, childPos.y,
931 width, childMin.y);
932 x += width;
933 j++;
934 }
935
936 return true; // success
937}
A smart ToolBar class that has a "MainPanel" which is always displayed, and an "ExtraPanel" that can ...

References mChildArray, and mRowArray.

Referenced by AdjustLayout(), and LayoutOne().

Here is the caller graph for this function:

◆ Fit() [1/2]

void ToolBarArea::Fit ( )
override

Definition at line 1052 of file ExpandingToolBar.cpp.

1053{
1054 Fit(true, true);
1055}

References Fit().

Referenced by AddChild(), Fit(), MoveChild(), OnSize(), RemoveChild(), and RestoreArrangement().

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

◆ Fit() [2/2]

void ToolBarArea::Fit ( bool  horizontal,
bool  vertical 
)
protected

Definition at line 1057 of file ExpandingToolBar.cpp.

1058{
1059 wxSize clientSize = GetClientSize();
1060 wxSize minSize;
1061 wxSize maxSize;
1062 wxSize actualSize;
1063 int i;
1064
1065 minSize.x = 0;
1066 minSize.y = 0;
1067 maxSize.x = 9999;
1068 maxSize.y = 0;
1069 for(i = 0; i < (int)mChildArray.size(); i++) {
1070 wxPoint childPos = mChildArray[i]->GetPosition();
1071 wxSize childSize = mChildArray[i]->GetSize();
1072
1073 if (childPos.x + childSize.x > actualSize.x) {
1074 actualSize.x = childPos.x + childSize.x;
1075 }
1076
1077 if (childSize.x > minSize.x) {
1078 minSize.x = childSize.x;
1079 }
1080
1081 if (childPos.y + childSize.y > maxSize.y) {
1082 maxSize.y = childPos.y + childSize.y;
1083 minSize.y = maxSize.y;
1084 actualSize.y = maxSize.y;
1085 }
1086 }
1087
1088 if (!horizontal && actualSize.x < clientSize.x)
1089 actualSize.x = clientSize.x;
1090 if (!vertical && actualSize.y < clientSize.y)
1091 actualSize.y = clientSize.y;
1092
1093 if (minSize != mMinSize ||
1094 maxSize != mMaxSize) {
1095 mMinSize = minSize;
1096 mMaxSize = maxSize;
1097 SetMinSize(mMinSize);
1098 SetMaxSize(mMaxSize);
1099 }
1100 if (actualSize != mActualSize) {
1101 mActualSize = actualSize;
1102 SetSize(mActualSize);
1103 }
1104}

References mActualSize, mChildArray, mMaxSize, and mMinSize.

◆ GetDropTargets()

std::vector< wxRect > ToolBarArea::GetDropTargets ( )

Definition at line 1215 of file ExpandingToolBar.cpp.

1216{
1217 mDropTargets.clear();
1218 mDropTargetIndices.clear();
1219 mDropTargetRows.clear();
1220
1221 int numChildren = (int)mChildArray.size();
1222 int i;
1223 int row = -1;
1224
1225 if (numChildren == 0)
1226 return mDropTargets;
1227
1228 for(i=0; i<numChildren; i++) {
1229 int childRow = mRowArray[i];
1230 wxRect childRect = mChildArray[i]->GetRect();
1231
1232 if (childRow != row) {
1233 // Add a target before this child (at beginning of row only)
1234 row = childRow;
1235 mDropTargetIndices.push_back(i);
1236 mDropTargetRows.push_back(row);
1237 mDropTargets.push_back(wxRect(childRect.x, childRect.y,
1238 0, childRect.height));
1239 }
1240
1241 // Add a target after this child (always)
1242 mDropTargetIndices.push_back(i+1);
1243 mDropTargetRows.push_back(row);
1244 mDropTargets.push_back(wxRect(childRect.x+childRect.width, childRect.y,
1245 0, childRect.height));
1246 }
1247
1248 return mDropTargets;
1249}
std::vector< int > mDropTargetIndices
std::vector< wxRect > mDropTargets
std::vector< int > mDropTargetRows

References mChildArray, mDropTargetIndices, mDropTargetRows, mDropTargets, and mRowArray.

Referenced by ExpandingToolBar::StartMoving().

Here is the caller graph for this function:

◆ Layout()

bool ToolBarArea::Layout ( )
override

Definition at line 1012 of file ExpandingToolBar.cpp.

1013{
1014 // Redo the layout from scratch, preserving only the order of
1015 // the children
1016
1017 int i;
1018
1019 for(i = 0; i < (int)mChildArray.size(); i++)
1020 mRowArray[i] = -1;
1021
1022 for(i = 0; i < (int)mChildArray.size(); i++)
1023 LayoutOne(i);
1024
1025 Refresh(true);
1026
1027 return true;
1028}

References LayoutOne(), mChildArray, and mRowArray.

Referenced by OnSize().

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

◆ LayoutOne()

void ToolBarArea::LayoutOne ( int  childIndex)
protected

Definition at line 939 of file ExpandingToolBar.cpp.

940{
941 wxSize area = GetClientSize();
942 ExpandingToolBar *child = mChildArray[childIndex];
943 wxSize childMin = child->GetMinSize();
944
945 if (childIndex == 0) {
946 mRowArray[childIndex] = 0;
947 mChildArray[childIndex]->SetSize(0, 0, childMin.x, childMin.y);
948 ExpandRow(0);
949
950 #if 0
951 wxPoint p = mChildArray[childIndex]->GetPosition();
952 wxSize s = mChildArray[childIndex]->GetSize();
953
954 wxPrintf("ToolBar %d moved to row %d at (%d, %d), size (%d x %d)\n",
955 childIndex, mRowArray[childIndex],
956 p.x, p.y, s.x, s.y);
957 #endif
958
959 mLastLayoutSize = area;
960
961 return;
962 }
963
964 int prevRow = mRowArray[childIndex-1];
965 ContractRow(prevRow);
966 wxPoint prevPos = mChildArray[childIndex-1]->GetPosition();
967 wxSize prevSize = mChildArray[childIndex-1]->GetSize();
968
969 int prevX = prevPos.x + prevSize.x;
970 int availableWidth = area.x - prevX;
971
972 if (childMin.x <= availableWidth) {
973 // It fits into the same row
974 mRowArray[childIndex] = prevRow;
975 mChildArray[childIndex]->SetSize(prevX, prevPos.y,
976 childMin.x, childMin.y);
977 ExpandRow(prevRow);
978 }
979 else {
980 // Go to the next row
981 ExpandRow(prevRow);
982 mRowArray[childIndex] = prevRow + 1;
983
984 int i;
985 int maxRowHeight = 0;
986 for(i=0; i<childIndex; i++)
987 if (mRowArray[i] == prevRow &&
988 mChildArray[i]->GetSize().y > maxRowHeight)
989 maxRowHeight = mChildArray[i]->GetSize().y;
990
991 mChildArray[childIndex]->SetSize(0, prevPos.y + maxRowHeight,
992 childMin.x, childMin.y);
993 ExpandRow(prevRow+1);
994 }
995
996 // Save the size of the window the last time we moved one of the
997 // toolbars around. If the user does a minor resize, we try to
998 // preserve the layout. If the user does a major resize, we're
999 // allowed to redo the layout.
1000 mLastLayoutSize = area;
1001
1002 #if 0
1003 wxPoint p = mChildArray[childIndex]->GetPosition();
1004 wxSize s = mChildArray[childIndex]->GetSize();
1005
1006 wxPrintf("ToolBar %d moved to row %d at (%d, %d), size (%d x %d)\n",
1007 childIndex, mRowArray[childIndex],
1008 p.x, p.y, s.x, s.y);
1009 #endif
1010}
wxSize mLastLayoutSize
void ContractRow(int rowIndex)

References ContractRow(), ExpandRow(), mChildArray, mLastLayoutSize, and mRowArray.

Referenced by AddChild(), AdjustLayout(), Layout(), MoveChild(), and RemoveChild().

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

◆ MoveChild()

void ToolBarArea::MoveChild ( ExpandingToolBar child,
wxRect  dropTarget 
)

Definition at line 1251 of file ExpandingToolBar.cpp.

1252{
1253 int i, j;
1254
1255 for(i = 0; i < (int)mDropTargets.size(); i++) {
1256 if (dropTarget == mDropTargets[i]) {
1257 int newIndex = mDropTargetIndices[i];
1258 int newRow = mDropTargetRows[i];
1259
1260 mChildArray.insert(mChildArray.begin() + newIndex, toolBar);
1261 mRowArray.insert(mRowArray.begin() + newIndex, newRow);
1262
1263 for(j = newIndex+1; j < (int)mChildArray.size(); j++)
1264 mRowArray[j] = -1;
1265
1266 ContractRow(newRow);
1267
1268 mChildArray[newIndex]->Show();
1269
1270 for(j = newIndex; j < (int)mChildArray.size(); j++)
1271 LayoutOne(j);
1272
1273 Fit(false, true);
1274
1275 return;
1276 }
1277 }
1278}

References ContractRow(), Fit(), LayoutOne(), mChildArray, mDropTargetIndices, mDropTargetRows, mDropTargets, and mRowArray.

Referenced by ExpandingToolBar::FinishMoving().

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

◆ OnMouse()

void ToolBarArea::OnMouse ( wxMouseEvent &  evt)

Definition at line 1133 of file ExpandingToolBar.cpp.

1134{
1135 if (mCapturedChild) {
1136 if (evt.ButtonUp())
1138 else if (evt.Moving() || evt.Dragging())
1140 }
1141 else {
1142 evt.Skip();
1143 }
1144}

References ExpandingToolBar::FinishMoving(), mCapturedChild, and ExpandingToolBar::UpdateMoving().

Here is the call graph for this function:

◆ OnSize()

void ToolBarArea::OnSize ( wxSizeEvent &  evt)

Definition at line 1106 of file ExpandingToolBar.cpp.

1107{
1108 if (mInOnSize)
1109 return;
1110
1111 mInOnSize = true;
1112
1113 wxSize currentSize = GetClientSize();
1114
1115 if (abs(currentSize.x - mLastLayoutSize.x) >= 100) {
1116 // If they resize by more than 100 pixels (horizontally),
1117 // we totally redo the layout, preserving the order of the
1118 // toolbars but not the exact position.
1119 Layout();
1120 }
1121 else {
1122 // If it was a minor resize, we try to preserve the positions of
1123 // the toolbars. If this is impossible, we still redo the layout,
1124 // of course.
1125 AdjustLayout();
1126 }
1127
1128 Fit(false, true);
1129
1130 mInOnSize = false;
1131}
bool Layout() override

References AdjustLayout(), Fit(), Layout(), mInOnSize, and mLastLayoutSize.

Here is the call graph for this function:

◆ RemoveChild()

void ToolBarArea::RemoveChild ( ExpandingToolBar child)

Definition at line 1162 of file ExpandingToolBar.cpp.

1163{
1164 int i, j;
1165
1166 for(i = 0; i < (int)mChildArray.size(); i++) {
1167 if (mChildArray[i] == child) {
1168 child->Hide();
1169
1170 mChildArray.erase(mChildArray.begin() + i);
1171 mRowArray.erase(mRowArray.begin() + i);
1172
1173 for(j = i; j < (int)mChildArray.size(); j++)
1174 mRowArray[j] = -1;
1175
1176 for(j = i; j < (int)mChildArray.size(); j++)
1177 LayoutOne(j);
1178
1179 Fit(false, true);
1180 }
1181 }
1182}

References Fit(), LayoutOne(), mChildArray, and mRowArray.

Referenced by ExpandingToolBar::StartMoving().

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

◆ RestoreArrangement()

void ToolBarArea::RestoreArrangement ( std::unique_ptr< ToolBarArrangement > &&  arrangement)

Definition at line 1198 of file ExpandingToolBar.cpp.

1199{
1200 int i;
1201
1202 mChildArray = arrangement->childArray;
1203 mRowArray = arrangement->rowArray;
1204
1205 for(i = 0; i < (int)mChildArray.size(); i++) {
1206 mChildArray[i]->SetSize(arrangement->rectArray[i]);
1207 mChildArray[i]->Show();
1208 }
1209
1210 Fit(false, true);
1211
1212 arrangement.reset();
1213}

References Fit(), mChildArray, and mRowArray.

Referenced by ExpandingToolBar::FinishMoving().

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

◆ SaveArrangement()

std::unique_ptr< ToolBarArrangement > ToolBarArea::SaveArrangement ( )

Definition at line 1184 of file ExpandingToolBar.cpp.

1185{
1186 auto arrangement = std::make_unique<ToolBarArrangement>();
1187 int i;
1188
1189 arrangement->childArray = mChildArray;
1190 arrangement->rowArray = mRowArray;
1191
1192 for(i = 0; i < (int)mChildArray.size(); i++)
1193 arrangement->rectArray.push_back(mChildArray[i]->GetRect());
1194
1195 return arrangement;
1196}

References mChildArray, and mRowArray.

Referenced by ExpandingToolBar::StartMoving().

Here is the caller graph for this function:

◆ SetCapturedChild()

void ToolBarArea::SetCapturedChild ( ExpandingToolBar child)

Definition at line 1280 of file ExpandingToolBar.cpp.

1281{
1282 mCapturedChild = child;
1283}

References mCapturedChild.

Referenced by ExpandingToolBar::FinishMoving(), and ExpandingToolBar::StartMoving().

Here is the caller graph for this function:

Member Data Documentation

◆ mActualSize

wxSize ToolBarArea::mActualSize
protected

Definition at line 243 of file ExpandingToolBar.h.

Referenced by Fit().

◆ mCapturedChild

ExpandingToolBar* ToolBarArea::mCapturedChild
protected

Definition at line 239 of file ExpandingToolBar.h.

Referenced by OnMouse(), and SetCapturedChild().

◆ mChildArray

std::vector<ExpandingToolBar*> ToolBarArea::mChildArray
protected

◆ mDropTargetIndices

std::vector<int> ToolBarArea::mDropTargetIndices
protected

Definition at line 246 of file ExpandingToolBar.h.

Referenced by GetDropTargets(), and MoveChild().

◆ mDropTargetRows

std::vector<int> ToolBarArea::mDropTargetRows
protected

Definition at line 247 of file ExpandingToolBar.h.

Referenced by GetDropTargets(), and MoveChild().

◆ mDropTargets

std::vector<wxRect> ToolBarArea::mDropTargets
protected

Definition at line 245 of file ExpandingToolBar.h.

Referenced by GetDropTargets(), and MoveChild().

◆ mInOnSize

bool ToolBarArea::mInOnSize
protected

Definition at line 237 of file ExpandingToolBar.h.

Referenced by OnSize().

◆ mLastLayoutSize

wxSize ToolBarArea::mLastLayoutSize
protected

Definition at line 236 of file ExpandingToolBar.h.

Referenced by LayoutOne(), and OnSize().

◆ mMaxSize

wxSize ToolBarArea::mMaxSize
protected

Definition at line 242 of file ExpandingToolBar.h.

Referenced by Fit().

◆ mMinSize

wxSize ToolBarArea::mMinSize
protected

Definition at line 241 of file ExpandingToolBar.h.

Referenced by Fit().

◆ mRowArray

std::vector<int> ToolBarArea::mRowArray
protected

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