Skeleton routine common to insertion of a toolbar, and figuring out width-constrained layout of toolbars
| 503 | // Skeleton routine common to insertion of a toolbar, and figuring out |
| 504 | // width-constrained layout of toolbars |
| 505 | void ToolDock::VisitLayout(LayoutVisitor &visitor, |
| 506 | ToolBarConfiguration *pWrappedConfiguration) |
| 507 | { |
| 508 | if (pWrappedConfiguration) |
| 509 | pWrappedConfiguration->Clear(); |
| 510 | |
| 511 | // Get size of our parent since we haven't been sized yet |
| 512 | int width, height; |
| 513 | GetParent()->GetClientSize( &width, &height ); |
| 514 | width -= toolbarGap; |
| 515 | height -= toolbarGap; |
| 516 | |
| 517 | // Rectangle of space to allocate |
| 518 | wxRect main{ toolbarGap, toolbarGap, |
| 519 | // Allow limited width, but arbitrary height, for the root rectangle |
| 520 | width, std::numeric_limits<int>::max() }; |
| 521 | |
| 522 | // For recording the nested subdivisions of the rectangle |
| 523 | struct Item { |
| 524 | Identifier section; |
| 525 | Item *parent{}; |
| 526 | ToolBar *lastSib {}; |
| 527 | ToolBar *lastWrappedChild {}; |
| 528 | wxRect rect; |
| 529 | }; |
| 530 | std::vector<Item> items(mBars.size()); |
| 531 | Item *layout = items.data(); |
| 532 | Item *next = layout; |
| 533 | |
| 534 | ToolBar *lastRoot {}; |
| 535 | ToolBar *lastWrappedRoot {}; |
| 536 | |
| 537 | // Process all docked and visible toolbars |
| 538 | for ( const auto &place : this->GetConfiguration() ) |
| 539 | { |
| 540 | // Cache toolbar pointer |
| 541 | const auto ct = place.pTree->pBar; |
| 542 | |
| 543 | // set up the chain of ancestors. |
| 544 | const auto parent = place.position.rightOf; |
| 545 | const auto section = ct->GetSection(); |
| 546 | auto &newItem = *next++; |
| 547 | if (parent) |
| 548 | newItem.parent = std::find_if(layout, next - 1, [&](Item &item){ |
| 549 | return parent->GetSection() == item.section; |
| 550 | }); |
| 551 | // Mark the slots that really were visited, for final pass through |
| 552 | // the spaces. |
| 553 | newItem.section = section; |
| 554 | |
| 555 | ToolBar *prevSib; |
| 556 | if (!parent) { |
| 557 | prevSib = lastRoot; |
| 558 | lastRoot = ct; |
| 559 | } |
| 560 | else { |
| 561 | auto &sib = newItem.parent->lastSib; |
| 562 | prevSib = sib; |
no test coverage detected