1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/ribbon/page.cpp
3 // Purpose: Container for ribbon-bar-style interface panels
4 // Author: Peter Cawley
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
19 #include "wx/ribbon/page.h"
20 #include "wx/ribbon/art.h"
21 #include "wx/ribbon/bar.h"
22 #include "wx/dcbuffer.h"
28 #include "wx/msw/private.h"
31 static int GetSizeInOrientation(wxSize size
, wxOrientation orientation
);
33 // As scroll buttons need to be rendered on top of a page's child windows, the
34 // buttons themselves have to be proper child windows (rather than just painted
35 // onto the page). In order to get proper clipping of a page's children (with
36 // regard to the scroll button), the scroll buttons are created as children of
37 // the ribbon bar rather than children of the page. This could not have been
38 // achieved by creating buttons as children of the page and then doing some Z-order
39 // manipulation, as this causes problems on win32 due to ribbon panels having the
40 // transparent flag set.
41 class wxRibbonPageScrollButton
: public wxRibbonControl
44 wxRibbonPageScrollButton(wxRibbonPage
* sibling
,
45 wxWindowID id
= wxID_ANY
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
,
50 virtual ~wxRibbonPageScrollButton();
53 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
55 void OnEraseBackground(wxEraseEvent
& evt
);
56 void OnPaint(wxPaintEvent
& evt
);
57 void OnMouseEnter(wxMouseEvent
& evt
);
58 void OnMouseLeave(wxMouseEvent
& evt
);
59 void OnMouseDown(wxMouseEvent
& evt
);
60 void OnMouseUp(wxMouseEvent
& evt
);
62 wxRibbonPage
* m_sibling
;
65 DECLARE_CLASS(wxRibbonPageScrollButton
)
69 IMPLEMENT_CLASS(wxRibbonPageScrollButton
, wxRibbonControl
)
71 BEGIN_EVENT_TABLE(wxRibbonPageScrollButton
, wxRibbonControl
)
72 EVT_ENTER_WINDOW(wxRibbonPageScrollButton::OnMouseEnter
)
73 EVT_ERASE_BACKGROUND(wxRibbonPageScrollButton::OnEraseBackground
)
74 EVT_LEAVE_WINDOW(wxRibbonPageScrollButton::OnMouseLeave
)
75 EVT_LEFT_DOWN(wxRibbonPageScrollButton::OnMouseDown
)
76 EVT_LEFT_UP(wxRibbonPageScrollButton::OnMouseUp
)
77 EVT_PAINT(wxRibbonPageScrollButton::OnPaint
)
80 wxRibbonPageScrollButton::wxRibbonPageScrollButton(wxRibbonPage
* sibling
,
84 long style
) : wxRibbonControl(sibling
->GetParent(), id
, pos
, size
, wxBORDER_NONE
)
86 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
88 m_flags
= (style
& wxRIBBON_SCROLL_BTN_DIRECTION_MASK
) | wxRIBBON_SCROLL_BTN_FOR_PAGE
;
91 wxRibbonPageScrollButton::~wxRibbonPageScrollButton()
95 void wxRibbonPageScrollButton::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
97 // Do nothing - all painting done in main paint handler
100 void wxRibbonPageScrollButton::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
102 wxAutoBufferedPaintDC
dc(this);
105 m_art
->DrawScrollButton(dc
, this, GetSize(), m_flags
);
109 void wxRibbonPageScrollButton::OnMouseEnter(wxMouseEvent
& WXUNUSED(evt
))
111 m_flags
|= wxRIBBON_SCROLL_BTN_HOVERED
;
115 void wxRibbonPageScrollButton::OnMouseLeave(wxMouseEvent
& WXUNUSED(evt
))
117 m_flags
&= ~wxRIBBON_SCROLL_BTN_HOVERED
;
118 m_flags
&= ~wxRIBBON_SCROLL_BTN_ACTIVE
;
122 void wxRibbonPageScrollButton::OnMouseDown(wxMouseEvent
& WXUNUSED(evt
))
124 m_flags
|= wxRIBBON_SCROLL_BTN_ACTIVE
;
128 void wxRibbonPageScrollButton::OnMouseUp(wxMouseEvent
& WXUNUSED(evt
))
130 if(m_flags
& wxRIBBON_SCROLL_BTN_ACTIVE
)
132 m_flags
&= ~wxRIBBON_SCROLL_BTN_ACTIVE
;
134 switch(m_flags
& wxRIBBON_SCROLL_BTN_DIRECTION_MASK
)
136 case wxRIBBON_SCROLL_BTN_DOWN
:
137 case wxRIBBON_SCROLL_BTN_RIGHT
:
138 m_sibling
->ScrollLines(1);
140 case wxRIBBON_SCROLL_BTN_UP
:
141 case wxRIBBON_SCROLL_BTN_LEFT
:
142 m_sibling
->ScrollLines(-1);
150 IMPLEMENT_CLASS(wxRibbonPage
, wxRibbonControl
)
152 BEGIN_EVENT_TABLE(wxRibbonPage
, wxRibbonControl
)
153 EVT_ERASE_BACKGROUND(wxRibbonPage::OnEraseBackground
)
154 EVT_PAINT(wxRibbonPage::OnPaint
)
155 EVT_SIZE(wxRibbonPage::OnSize
)
158 wxRibbonPage::wxRibbonPage()
160 m_scroll_left_btn
= NULL
;
161 m_scroll_right_btn
= NULL
;
163 m_scroll_buttons_visible
= false;
166 wxRibbonPage::wxRibbonPage(wxRibbonBar
* parent
,
168 const wxString
& label
,
169 const wxBitmap
& icon
,
170 long WXUNUSED(style
))
171 : wxRibbonControl(parent
, id
, wxDefaultPosition
, wxDefaultSize
, wxBORDER_NONE
)
173 CommonInit(label
, icon
);
176 wxRibbonPage::~wxRibbonPage()
178 delete[] m_size_calc_array
;
181 bool wxRibbonPage::Create(wxRibbonBar
* parent
,
183 const wxString
& label
,
184 const wxBitmap
& icon
,
185 long WXUNUSED(style
))
187 if(!wxRibbonControl::Create(parent
, id
, wxDefaultPosition
, wxDefaultSize
, wxBORDER_NONE
))
190 CommonInit(label
, icon
);
195 void wxRibbonPage::CommonInit(const wxString
& label
, const wxBitmap
& icon
)
200 m_old_size
= wxSize(0, 0);
202 m_scroll_left_btn
= NULL
;
203 m_scroll_right_btn
= NULL
;
204 m_size_calc_array
= NULL
;
205 m_size_calc_array_size
= 0;
207 m_scroll_buttons_visible
= false;
209 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
211 wxDynamicCast(GetParent(), wxRibbonBar
)->AddPage(this);
214 void wxRibbonPage::SetArtProvider(wxRibbonArtProvider
* art
)
217 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
219 node
= node
->GetNext() )
221 wxWindow
* child
= node
->GetData();
222 wxRibbonControl
* ribbon_child
= wxDynamicCast(child
, wxRibbonControl
);
225 ribbon_child
->SetArtProvider(art
);
230 void wxRibbonPage::AdjustRectToIncludeScrollButtons(wxRect
* rect
) const
232 if(m_scroll_buttons_visible
)
234 if(GetMajorAxis() == wxVERTICAL
)
236 if(m_scroll_left_btn
)
238 rect
->SetY(rect
->GetY() -
239 m_scroll_left_btn
->GetSize().GetHeight());
240 rect
->SetHeight(rect
->GetHeight() +
241 m_scroll_left_btn
->GetSize().GetHeight());
243 if(m_scroll_right_btn
)
245 rect
->SetHeight(rect
->GetHeight() +
246 m_scroll_right_btn
->GetSize().GetHeight());
251 if(m_scroll_left_btn
)
253 rect
->SetX(rect
->GetX() -
254 m_scroll_left_btn
->GetSize().GetWidth());
255 rect
->SetWidth(rect
->GetWidth() +
256 m_scroll_left_btn
->GetSize().GetWidth());
258 if(m_scroll_right_btn
)
260 rect
->SetWidth(rect
->GetWidth() +
261 m_scroll_right_btn
->GetSize().GetWidth());
267 void wxRibbonPage::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
269 // All painting done in main paint handler to minimise flicker
272 void wxRibbonPage::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
274 // No foreground painting done by the page itself, but a paint DC
275 // must be created anyway.
276 wxAutoBufferedPaintDC
dc(this);
277 wxRect
rect(GetSize());
278 AdjustRectToIncludeScrollButtons(&rect
);
279 m_art
->DrawPageBackground(dc
, this, rect
);
282 wxOrientation
wxRibbonPage::GetMajorAxis() const
284 if(m_art
&& (m_art
->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL
))
294 bool wxRibbonPage::ScrollLines(int lines
)
296 return ScrollPixels(lines
* 8);
299 bool wxRibbonPage::ScrollPixels(int pixels
)
303 if(m_scroll_amount
== 0)
305 if(m_scroll_amount
< -pixels
)
306 pixels
= -m_scroll_amount
;
310 if(m_scroll_amount
== m_scroll_amount_limit
)
312 if(m_scroll_amount
+ pixels
> m_scroll_amount_limit
)
313 pixels
= m_scroll_amount_limit
- m_scroll_amount
;
318 m_scroll_amount
+= pixels
;
320 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
322 node
= node
->GetNext() )
324 wxWindow
* child
= node
->GetData();
326 child
->GetPosition(&x
, &y
);
327 if(GetMajorAxis() == wxHORIZONTAL
)
331 child
->SetPosition(wxPoint(x
, y
));
339 void wxRibbonPage::SetSizeWithScrollButtonAdjustment(int x
, int y
, int width
, int height
)
341 if(m_scroll_buttons_visible
)
343 if(GetMajorAxis() == wxHORIZONTAL
)
345 if(m_scroll_left_btn
)
347 int w
= m_scroll_left_btn
->GetSize().GetWidth();
348 m_scroll_left_btn
->SetPosition(wxPoint(x
, y
));
352 if(m_scroll_right_btn
)
354 int w
= m_scroll_right_btn
->GetSize().GetWidth();
356 m_scroll_right_btn
->SetPosition(wxPoint(x
+ width
, y
));
361 if(m_scroll_left_btn
)
363 int h
= m_scroll_left_btn
->GetSize().GetHeight();
364 m_scroll_left_btn
->SetPosition(wxPoint(x
, y
));
368 if(m_scroll_right_btn
)
370 int h
= m_scroll_right_btn
->GetSize().GetHeight();
372 m_scroll_right_btn
->SetPosition(wxPoint(x
, y
+ height
));
376 if (width
< 0) width
= 0;
377 if (height
< 0) height
= 0;
378 SetSize(x
, y
, width
, height
);
381 void wxRibbonPage::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
383 // When a resize triggers the scroll buttons to become visible, the page is resized.
384 // This resize from within a resize event can cause (MSW) wxWidgets some confusion,
385 // and report the 1st size to the 2nd size event. Hence the most recent size is
386 // remembered internally and used in Layout() where appropiate.
388 if(GetMajorAxis() == wxHORIZONTAL
)
390 m_size_in_major_axis_for_children
= width
;
391 if(m_scroll_buttons_visible
)
393 if(m_scroll_left_btn
)
394 m_size_in_major_axis_for_children
+= m_scroll_left_btn
->GetSize().GetWidth();
395 if(m_scroll_right_btn
)
396 m_size_in_major_axis_for_children
+= m_scroll_right_btn
->GetSize().GetWidth();
401 m_size_in_major_axis_for_children
= height
;
402 if(m_scroll_buttons_visible
)
404 if(m_scroll_left_btn
)
405 m_size_in_major_axis_for_children
+= m_scroll_left_btn
->GetSize().GetHeight();
406 if(m_scroll_right_btn
)
407 m_size_in_major_axis_for_children
+= m_scroll_right_btn
->GetSize().GetHeight();
411 wxRibbonControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
414 void wxRibbonPage::OnSize(wxSizeEvent
& evt
)
416 wxSize new_size
= evt
.GetSize();
421 wxRect invalid_rect
= m_art
->GetPageBackgroundRedrawArea(temp_dc
, this, m_old_size
, new_size
);
422 Refresh(true, &invalid_rect
);
425 m_old_size
= new_size
;
427 if(new_size
.GetX() > 0 && new_size
.GetY() > 0)
433 // Simplify other calculations by pretending new size is zero in both
436 // When size == 0, no point in doing any layout
442 void wxRibbonPage::RemoveChild(wxWindowBase
*child
)
444 // Remove all references to the child from the collapse stack
445 size_t count
= m_collapse_stack
.GetCount();
447 for(src
= 0, dst
= 0; src
< count
; ++src
, ++dst
)
449 wxRibbonControl
*item
= m_collapse_stack
.Item(src
);
460 m_collapse_stack
.Item(dst
) = item
;
465 m_collapse_stack
.RemoveAt(dst
, src
- dst
);
468 // ... and then proceed as normal
469 wxRibbonControl::RemoveChild(child
);
472 bool wxRibbonPage::Realize()
476 m_collapse_stack
.Clear();
477 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
479 node
= node
->GetNext())
481 wxRibbonControl
* child
= wxDynamicCast(node
->GetData(), wxRibbonControl
);
486 if(!child
->Realize())
491 PopulateSizeCalcArray(&wxWindow::GetMinSize
);
493 return DoActualLayout() && status
;
496 void wxRibbonPage::PopulateSizeCalcArray(wxSize (wxWindow::*get_size
)(void) const)
498 if(m_size_calc_array_size
!= GetChildren().GetCount())
500 delete[] m_size_calc_array
;
501 m_size_calc_array_size
= GetChildren().GetCount();
502 m_size_calc_array
= new wxSize
[m_size_calc_array_size
];
504 wxSize
* node_size
= m_size_calc_array
;
505 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
507 node
= node
->GetNext(), ++node_size
)
509 wxWindow
* child
= node
->GetData();
510 *node_size
= (child
->*get_size
)();
514 bool wxRibbonPage::Layout()
516 if(GetChildren().GetCount() == 0)
522 PopulateSizeCalcArray(&wxWindow::GetSize
);
523 return DoActualLayout();
527 bool wxRibbonPage::DoActualLayout()
529 wxPoint
origin(m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_LEFT_SIZE
), m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_TOP_SIZE
));
530 wxOrientation major_axis
= GetMajorAxis();
534 if(major_axis
== wxHORIZONTAL
)
536 gap
= m_art
->GetMetric(wxRIBBON_ART_PANEL_X_SEPARATION_SIZE
);
537 minor_axis_size
= GetSize().GetHeight() - origin
.y
- m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_BOTTOM_SIZE
);
538 available_space
= m_size_in_major_axis_for_children
- m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_RIGHT_SIZE
) - origin
.x
;
542 gap
= m_art
->GetMetric(wxRIBBON_ART_PANEL_Y_SEPARATION_SIZE
);
543 minor_axis_size
= GetSize().GetWidth() - origin
.x
- m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_RIGHT_SIZE
);
544 available_space
= m_size_in_major_axis_for_children
- m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_BOTTOM_SIZE
) - origin
.y
;
546 if (minor_axis_size
< 0) minor_axis_size
= 0;
548 for(size_index
= 0; size_index
< m_size_calc_array_size
; ++size_index
)
550 if(major_axis
== wxHORIZONTAL
)
552 available_space
-= m_size_calc_array
[size_index
].GetWidth();
553 m_size_calc_array
[size_index
].SetHeight(minor_axis_size
);
557 available_space
-= m_size_calc_array
[size_index
].GetHeight();
558 m_size_calc_array
[size_index
].SetWidth(minor_axis_size
);
561 available_space
-= gap
;
563 bool todo_hide_scroll_buttons
= false;
564 bool todo_show_scroll_buttons
= false;
565 if(available_space
>= 0)
567 if(m_scroll_buttons_visible
)
568 todo_hide_scroll_buttons
= true;
569 if(available_space
> 0)
570 ExpandPanels(major_axis
, available_space
);
574 if(m_scroll_buttons_visible
)
576 // Scroll buttons already visible - not going to be able to downsize any more
577 m_scroll_amount_limit
= -available_space
;
578 if(m_scroll_amount
> m_scroll_amount_limit
)
580 m_scroll_amount
= m_scroll_amount_limit
;
581 todo_show_scroll_buttons
= true;
586 if(!CollapsePanels(major_axis
, -available_space
))
589 m_scroll_amount_limit
= -available_space
;
590 todo_show_scroll_buttons
= true;
594 if(m_scroll_buttons_visible
)
596 if(major_axis
== wxHORIZONTAL
)
598 origin
.x
-= m_scroll_amount
;
599 if(m_scroll_left_btn
)
600 origin
.x
-= m_scroll_left_btn
->GetSize().GetWidth();
604 origin
.y
-= m_scroll_amount
;
605 if(m_scroll_left_btn
)
606 origin
.y
-= m_scroll_left_btn
->GetSize().GetHeight();
610 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
612 node
= node
->GetNext(), ++size_index
)
614 wxWindow
* child
= node
->GetData();
615 int w
= m_size_calc_array
[size_index
].GetWidth();
616 int h
= m_size_calc_array
[size_index
].GetHeight();
617 child
->SetSize(origin
.x
, origin
.y
, w
, h
);
618 if(major_axis
== wxHORIZONTAL
)
628 if(todo_show_scroll_buttons
)
630 else if(todo_hide_scroll_buttons
)
637 bool wxRibbonPage::Show(bool show
)
639 if(m_scroll_left_btn
)
640 m_scroll_left_btn
->Show(show
);
641 if(m_scroll_right_btn
)
642 m_scroll_right_btn
->Show(show
);
643 return wxRibbonControl::Show(show
);
646 void wxRibbonPage::HideScrollButtons()
649 m_scroll_amount_limit
= 0;
653 void wxRibbonPage::ShowScrollButtons()
655 bool show_left
= true;
656 bool show_right
= true;
657 bool reposition
= false;
658 if(m_scroll_amount
== 0)
662 if(m_scroll_amount
>= m_scroll_amount_limit
)
665 m_scroll_amount
= m_scroll_amount_limit
;
667 m_scroll_buttons_visible
= show_left
|| show_right
;
671 if(m_scroll_left_btn
== NULL
)
676 if(GetMajorAxis() == wxHORIZONTAL
)
678 direction
= wxRIBBON_SCROLL_BTN_LEFT
;
679 size
= m_art
->GetScrollButtonMinimumSize(temp_dc
, GetParent(), direction
);
680 size
.SetHeight(GetSize().GetHeight());
684 direction
= wxRIBBON_SCROLL_BTN_UP
;
685 size
= m_art
->GetScrollButtonMinimumSize(temp_dc
, GetParent(), direction
);
686 size
.SetWidth(GetSize().GetWidth());
688 m_scroll_left_btn
= new wxRibbonPageScrollButton(this, wxID_ANY
, GetPosition(), size
, direction
);
691 m_scroll_left_btn
->Hide();
698 if(m_scroll_left_btn
!= NULL
)
700 m_scroll_left_btn
->Destroy();
701 m_scroll_left_btn
= NULL
;
708 if(m_scroll_right_btn
== NULL
)
713 if(GetMajorAxis() == wxHORIZONTAL
)
715 direction
= wxRIBBON_SCROLL_BTN_RIGHT
;
716 size
= m_art
->GetScrollButtonMinimumSize(temp_dc
, GetParent(), direction
);
717 size
.SetHeight(GetSize().GetHeight());
721 direction
= wxRIBBON_SCROLL_BTN_DOWN
;
722 size
= m_art
->GetScrollButtonMinimumSize(temp_dc
, GetParent(), direction
);
723 size
.SetWidth(GetSize().GetWidth());
725 wxPoint initial_pos
= GetPosition() + GetSize() - size
;
726 m_scroll_right_btn
= new wxRibbonPageScrollButton(this, wxID_ANY
, initial_pos
, size
, direction
);
729 m_scroll_right_btn
->Hide();
736 if(m_scroll_right_btn
!= NULL
)
738 m_scroll_right_btn
->Destroy();
739 m_scroll_right_btn
= NULL
;
746 wxDynamicCast(GetParent(), wxRibbonBar
)->RepositionPage(this);
750 static int GetSizeInOrientation(wxSize size
, wxOrientation orientation
)
754 case wxHORIZONTAL
: return size
.GetWidth();
755 case wxVERTICAL
: return size
.GetHeight();
756 case wxBOTH
: return size
.GetWidth() * size
.GetHeight();
761 bool wxRibbonPage::ExpandPanels(wxOrientation direction
, int maximum_amount
)
763 bool expanded_something
= false;
764 while(maximum_amount
> 0)
766 int smallest_size
= INT_MAX
;
767 wxRibbonPanel
* smallest_panel
= NULL
;
768 wxSize
* smallest_panel_size
= NULL
;
769 wxSize
* panel_size
= m_size_calc_array
;
770 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
772 node
= node
->GetNext(), ++panel_size
)
774 wxRibbonPanel
* panel
= wxDynamicCast(node
->GetData(), wxRibbonPanel
);
779 if(panel
->IsSizingContinuous())
781 int size
= GetSizeInOrientation(*panel_size
, direction
);
782 if(size
< smallest_size
)
784 smallest_size
= size
;
785 smallest_panel
= panel
;
786 smallest_panel_size
= panel_size
;
791 int size
= GetSizeInOrientation(*panel_size
, direction
);
792 if(size
< smallest_size
)
794 wxSize larger
= panel
->GetNextLargerSize(direction
, *panel_size
);
795 if(larger
!= (*panel_size
) && GetSizeInOrientation(larger
, direction
) > size
)
797 smallest_size
= size
;
798 smallest_panel
= panel
;
799 smallest_panel_size
= panel_size
;
804 if(smallest_panel
!= NULL
)
806 if(smallest_panel
->IsSizingContinuous())
808 int amount
= maximum_amount
;
811 // For "large" growth, grow this panel a bit, and then re-allocate
812 // the remainder (which may come to this panel again anyway)
815 if(direction
& wxHORIZONTAL
)
817 smallest_panel_size
->x
+= amount
;
819 if(direction
& wxVERTICAL
)
821 smallest_panel_size
->y
+= amount
;
823 maximum_amount
-= amount
;
824 m_collapse_stack
.Add(smallest_panel
);
825 expanded_something
= true;
829 wxSize larger
= smallest_panel
->GetNextLargerSize(direction
, *smallest_panel_size
);
830 wxSize delta
= larger
- (*smallest_panel_size
);
831 if(GetSizeInOrientation(delta
, direction
) <= maximum_amount
)
833 *smallest_panel_size
= larger
;
834 maximum_amount
-= GetSizeInOrientation(delta
, direction
);
835 m_collapse_stack
.Add(smallest_panel
);
836 expanded_something
= true;
849 return expanded_something
;
852 bool wxRibbonPage::CollapsePanels(wxOrientation direction
, int minimum_amount
)
854 bool collapsed_something
= false;
855 while(minimum_amount
> 0)
857 int largest_size
= 0;
858 wxRibbonPanel
* largest_panel
= NULL
;
859 wxSize
* largest_panel_size
= NULL
;
860 wxSize
* panel_size
= m_size_calc_array
;
861 if(!m_collapse_stack
.IsEmpty())
863 // For a more consistent panel layout, try to collapse panels which
864 // were recently expanded.
865 largest_panel
= wxDynamicCast(m_collapse_stack
.Last(), wxRibbonPanel
);
866 m_collapse_stack
.RemoveAt(m_collapse_stack
.GetCount() - 1);
867 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
869 node
= node
->GetNext(), ++panel_size
)
871 wxRibbonPanel
* panel
= wxDynamicCast(node
->GetData(), wxRibbonPanel
);
872 if(panel
== largest_panel
)
874 largest_panel_size
= panel_size
;
881 for(wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
883 node
= node
->GetNext(), ++panel_size
)
885 wxRibbonPanel
* panel
= wxDynamicCast(node
->GetData(), wxRibbonPanel
);
890 if(panel
->IsSizingContinuous())
892 int size
= GetSizeInOrientation(*panel_size
, direction
);
893 if(size
> largest_size
)
896 largest_panel
= panel
;
897 largest_panel_size
= panel_size
;
902 int size
= GetSizeInOrientation(*panel_size
, direction
);
903 if(size
> largest_size
)
905 wxSize smaller
= panel
->GetNextSmallerSize(direction
, *panel_size
);
906 if(smaller
!= (*panel_size
) &&
907 GetSizeInOrientation(smaller
, direction
) < size
)
910 largest_panel
= panel
;
911 largest_panel_size
= panel_size
;
917 if(largest_panel
!= NULL
)
919 if(largest_panel
->IsSizingContinuous())
921 int amount
= minimum_amount
;
924 // For "large" contraction, reduce this panel a bit, and
925 // then re-allocate the remainder of the quota (which may
926 // come to this panel again anyway)
929 if(direction
& wxHORIZONTAL
)
931 largest_panel_size
->x
-= amount
;
933 if(direction
& wxVERTICAL
)
935 largest_panel_size
->y
-= amount
;
937 minimum_amount
-= amount
;
938 collapsed_something
= true;
942 wxSize smaller
= largest_panel
->GetNextSmallerSize(direction
, *largest_panel_size
);
943 wxSize delta
= (*largest_panel_size
) - smaller
;
944 *largest_panel_size
= smaller
;
945 minimum_amount
-= GetSizeInOrientation(delta
, direction
);
946 collapsed_something
= true;
954 return collapsed_something
;
957 bool wxRibbonPage::DismissExpandedPanel()
959 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
961 node
= node
->GetNext() )
963 wxRibbonPanel
* panel
= wxDynamicCast(node
->GetData(), wxRibbonPanel
);
968 if(panel
->GetExpandedPanel() != NULL
)
970 return panel
->HideExpanded();
976 wxSize
wxRibbonPage::GetMinSize() const
978 wxSize
min(wxDefaultCoord
, wxDefaultCoord
);
980 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
982 node
= node
->GetNext() )
984 wxWindow
* child
= node
->GetData();
985 wxSize
child_min(child
->GetMinSize());
987 min
.x
= wxMax(min
.x
, child_min
.x
);
988 min
.y
= wxMax(min
.y
, child_min
.y
);
991 if(GetMajorAxis() == wxHORIZONTAL
)
993 min
.x
= wxDefaultCoord
;
994 if(min
.y
!= wxDefaultCoord
)
996 min
.y
+= m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_TOP_SIZE
) + m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_BOTTOM_SIZE
);
1001 if(min
.x
!= wxDefaultCoord
)
1003 min
.x
+= m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_LEFT_SIZE
) + m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_RIGHT_SIZE
);
1005 min
.y
= wxDefaultCoord
;
1011 wxSize
wxRibbonPage::DoGetBestSize() const
1016 if(GetMajorAxis() == wxHORIZONTAL
)
1018 best
.y
= wxDefaultCoord
;
1020 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1022 node
= node
->GetNext() )
1024 wxWindow
* child
= node
->GetData();
1025 wxSize
child_best(child
->GetBestSize());
1027 if(child_best
.x
!= wxDefaultCoord
)
1029 best
.IncBy(child_best
.x
, 0);
1031 best
.y
= wxMax(best
.y
, child_best
.y
);
1038 best
.IncBy((count
- 1) * m_art
->GetMetric(wxRIBBON_ART_PANEL_X_SEPARATION_SIZE
), 0);
1043 best
.x
= wxDefaultCoord
;
1045 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1047 node
= node
->GetNext() )
1049 wxWindow
* child
= node
->GetData();
1050 wxSize
child_best(child
->GetBestSize());
1052 best
.x
= wxMax(best
.x
, child_best
.x
);
1053 if(child_best
.y
!= wxDefaultCoord
)
1055 best
.IncBy(0, child_best
.y
);
1063 best
.IncBy(0, (count
- 1) * m_art
->GetMetric(wxRIBBON_ART_PANEL_Y_SEPARATION_SIZE
));
1067 if(best
.x
!= wxDefaultCoord
)
1069 best
.x
+= m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_LEFT_SIZE
) + m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_RIGHT_SIZE
);
1071 if(best
.y
!= wxDefaultCoord
)
1073 best
.y
+= m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_TOP_SIZE
) + m_art
->GetMetric(wxRIBBON_ART_PAGE_BORDER_BOTTOM_SIZE
);
1078 #endif // wxUSE_RIBBON