Determine the position where a NEW bar would be placed 'rect' will be the rectangle for the dock marker (black triangle)
| 741 | // |
| 742 | // 'rect' will be the rectangle for the dock marker (black triangle) |
| 743 | ToolBarConfiguration::Position |
| 744 | ToolDock::PositionBar( ToolBar *t, const wxPoint & pos, wxRect & rect ) |
| 745 | { |
| 746 | // Set width and size, but we must still find x and y. |
| 747 | rect = t->GetRect(); |
| 748 | |
| 749 | using Position = ToolBarConfiguration::Position; |
| 750 | Position result { ToolBarConfiguration::UnspecifiedPosition }; |
| 751 | struct Inserter : public LayoutVisitor |
| 752 | { |
| 753 | struct Stop {}; |
| 754 | |
| 755 | Inserter(Position &p, wxRect &r, const wxPoint &pt, ToolBar *t) |
| 756 | : result(p), rect(r), point(pt), tb(t) |
| 757 | {} |
| 758 | |
| 759 | void ModifySize |
| 760 | (ToolBar *ct, |
| 761 | const wxRect &rectIn, |
| 762 | ToolBarConfiguration::Position prevPosition, |
| 763 | ToolBarConfiguration::Position position, |
| 764 | wxSize &sz) |
| 765 | override |
| 766 | { |
| 767 | // Maybe insert the NEW bar if it hasn't already been done |
| 768 | // and is in the right place. |
| 769 | |
| 770 | // Does the location fall within this bar? |
| 771 | if (rectIn.Contains(point)) |
| 772 | { |
| 773 | sz = tb->GetDockedSize(); |
| 774 | // Choose a position always, if there is a bar to displace. |
| 775 | // Else, only if the fit is possible. |
| 776 | if (ct || (sz.x <= rectIn.width && sz.y <= rectIn.height)) { |
| 777 | // May choose current or previous. |
| 778 | if (ct && |
| 779 | (sz.y < rectIn.height || |
| 780 | point.y < (rectIn.GetTop() + rectIn.GetBottom()) / 2)) |
| 781 | // "Wedge" the bar into a crack alone, not adopting others, |
| 782 | // if either a short bar displaces a tall one, or else |
| 783 | // the displacing bar is at least at tall, but the pointer is |
| 784 | // in the upper half of the box. |
| 785 | usedPrev = true, result = prevPosition, result.adopt = false; |
| 786 | else |
| 787 | result = position; |
| 788 | } |
| 789 | // Now wait until the other callback below to discover x and y |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | void Visit |
| 794 | (ToolBar *, wxPoint pointIn) |
| 795 | override |
| 796 | { |
| 797 | if (result != ToolBarConfiguration::UnspecifiedPosition) { |
| 798 | // If we've placed it, we're done. |
| 799 | rect.x = pointIn.x; |
| 800 | rect.y = pointIn.y; |