1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/ribbon/panel.cpp
3 // Purpose: Ribbon-style container for a group of related tools / controls
4 // Author: Peter Cawley
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/ribbon/panel.h"
21 #include "wx/ribbon/art.h"
22 #include "wx/ribbon/bar.h"
23 #include "wx/dcbuffer.h"
24 #include "wx/display.h"
32 #include "wx/msw/private.h"
35 IMPLEMENT_CLASS(wxRibbonPanel
, wxRibbonControl
)
37 BEGIN_EVENT_TABLE(wxRibbonPanel
, wxRibbonControl
)
38 EVT_ENTER_WINDOW(wxRibbonPanel::OnMouseEnter
)
39 EVT_ERASE_BACKGROUND(wxRibbonPanel::OnEraseBackground
)
40 EVT_KILL_FOCUS(wxRibbonPanel::OnKillFocus
)
41 EVT_LEAVE_WINDOW(wxRibbonPanel::OnMouseLeave
)
42 EVT_LEFT_DOWN(wxRibbonPanel::OnMouseClick
)
43 EVT_PAINT(wxRibbonPanel::OnPaint
)
44 EVT_SIZE(wxRibbonPanel::OnSize
)
47 wxRibbonPanel::wxRibbonPanel() : m_expanded_dummy(NULL
), m_expanded_panel(NULL
)
51 wxRibbonPanel::wxRibbonPanel(wxWindow
* parent
,
53 const wxString
& label
,
54 const wxBitmap
& minimised_icon
,
58 : wxRibbonControl(parent
, id
, pos
, size
, wxBORDER_NONE
)
60 CommonInit(label
, minimised_icon
, style
);
63 wxRibbonPanel::~wxRibbonPanel()
67 m_expanded_panel
->m_expanded_dummy
= NULL
;
68 m_expanded_panel
->GetParent()->Destroy();
72 bool wxRibbonPanel::Create(wxWindow
* parent
,
74 const wxString
& label
,
80 if(!wxRibbonControl::Create(parent
, id
, pos
, size
, wxBORDER_NONE
))
85 CommonInit(label
, icon
, style
);
90 void wxRibbonPanel::SetArtProvider(wxRibbonArtProvider
* art
)
93 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
95 node
= node
->GetNext() )
97 wxWindow
* child
= node
->GetData();
98 wxRibbonControl
* ribbon_child
= wxDynamicCast(child
, wxRibbonControl
);
101 ribbon_child
->SetArtProvider(art
);
105 m_expanded_panel
->SetArtProvider(art
);
108 void wxRibbonPanel::CommonInit(const wxString
& label
, const wxBitmap
& icon
, long style
)
113 m_minimised_size
= wxDefaultSize
; // Unknown / none
114 m_smallest_unminimised_size
= wxDefaultSize
;// Unknown / none for IsFullySpecified()
115 m_preferred_expand_direction
= wxSOUTH
;
116 m_expanded_dummy
= NULL
;
117 m_expanded_panel
= NULL
;
119 m_minimised_icon
= icon
;
125 wxRibbonControl
* parent
= wxDynamicCast(GetParent(), wxRibbonControl
);
128 m_art
= parent
->GetArtProvider();
133 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
134 SetMinSize(wxSize(20, 20));
137 bool wxRibbonPanel::IsMinimised() const
142 bool wxRibbonPanel::IsHovered() const
147 void wxRibbonPanel::OnMouseEnter(wxMouseEvent
& evt
)
149 TestPositionForHover(evt
.GetPosition());
152 void wxRibbonPanel::OnMouseEnterChild(wxMouseEvent
& evt
)
154 wxPoint pos
= evt
.GetPosition();
155 wxWindow
*child
= wxDynamicCast(evt
.GetEventObject(), wxWindow
);
158 pos
+= child
->GetPosition();
159 TestPositionForHover(pos
);
164 void wxRibbonPanel::OnMouseLeave(wxMouseEvent
& evt
)
166 TestPositionForHover(evt
.GetPosition());
169 void wxRibbonPanel::OnMouseLeaveChild(wxMouseEvent
& evt
)
171 wxPoint pos
= evt
.GetPosition();
172 wxWindow
*child
= wxDynamicCast(evt
.GetEventObject(), wxWindow
);
175 pos
+= child
->GetPosition();
176 TestPositionForHover(pos
);
181 void wxRibbonPanel::TestPositionForHover(const wxPoint
& pos
)
183 bool hovered
= false;
184 if(pos
.x
>= 0 && pos
.y
>= 0)
186 wxSize size
= GetSize();
187 if(pos
.x
< size
.GetWidth() && pos
.y
< size
.GetHeight())
192 if(hovered
!= m_hovered
)
199 void wxRibbonPanel::AddChild(wxWindowBase
*child
)
201 wxRibbonControl::AddChild(child
);
203 // Window enter / leave events count for only the window in question, not
204 // for children of the window. The panel wants to be in the hovered state
205 // whenever the mouse cursor is within its boundary, so the events need to
206 // be attached to children too.
207 child
->Connect(wxEVT_ENTER_WINDOW
, (wxObjectEventFunction
)&wxRibbonPanel::OnMouseEnterChild
, NULL
, this);
208 child
->Connect(wxEVT_LEAVE_WINDOW
, (wxObjectEventFunction
)&wxRibbonPanel::OnMouseLeaveChild
, NULL
, this);
211 void wxRibbonPanel::RemoveChild(wxWindowBase
*child
)
213 child
->Disconnect(wxEVT_ENTER_WINDOW
, (wxObjectEventFunction
)&wxRibbonPanel::OnMouseEnterChild
, NULL
, this);
214 child
->Disconnect(wxEVT_LEAVE_WINDOW
, (wxObjectEventFunction
)&wxRibbonPanel::OnMouseLeaveChild
, NULL
, this);
216 wxRibbonControl::RemoveChild(child
);
219 void wxRibbonPanel::OnSize(wxSizeEvent
& evt
)
227 void wxRibbonPanel::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
229 // At least on MSW, changing the size of a window will cause GetSize() to
230 // report the new size, but a size event may not be handled immediately.
231 // If this minimised check was performed in the OnSize handler, then
232 // GetSize() could return a size much larger than the minimised size while
233 // IsMinimised() returns true. This would then affect layout, as the panel
234 // will refuse to grow any larger while in limbo between minimised and non.
236 bool minimised
= (m_flags
& wxRIBBON_PANEL_NO_AUTO_MINIMISE
) == 0 &&
237 IsMinimised(wxSize(width
, height
)); // check if would be at this size
238 if(minimised
!= m_minimised
)
240 m_minimised
= minimised
;
241 // Note that for sizers, this routine disallows the use of mixed shown
242 // and hidden controls
243 // TODO ? use some list of user set invisible children to restore status.
244 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
246 node
= node
->GetNext())
248 node
->GetData()->Show(!minimised
);
254 wxRibbonControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
257 // Checks if panel would be minimised at (client size) at_size
258 bool wxRibbonPanel::IsMinimised(wxSize at_size
) const
262 // we have no information on size change direction
264 wxSize size
= GetMinNotMinimisedSize();
265 if(size
.x
> at_size
.x
|| size
.y
> at_size
.y
)
271 if(!m_minimised_size
.IsFullySpecified())
274 return (at_size
.GetX() <= m_minimised_size
.GetX() &&
275 at_size
.GetY() <= m_minimised_size
.GetY()) ||
276 at_size
.GetX() < m_smallest_unminimised_size
.GetX() ||
277 at_size
.GetY() < m_smallest_unminimised_size
.GetY();
280 void wxRibbonPanel::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
282 // All painting done in main paint handler to minimise flicker
285 void wxRibbonPanel::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
287 wxAutoBufferedPaintDC
dc(this);
293 m_art
->DrawMinimisedPanel(dc
, this, GetSize(), m_minimised_icon_resized
);
297 m_art
->DrawPanelBackground(dc
, this, GetSize());
302 bool wxRibbonPanel::IsSizingContinuous() const
304 // A panel never sizes continuously, even if all of its children can,
305 // as it would appear out of place along side non-continuous panels.
307 // JS 2012-03-09: introducing wxRIBBON_PANEL_STRETCH to allow
308 // the panel to fill its parent page. For example we might have
309 // a list of styles in one of the pages, which should stretch to
310 // fill available space.
311 return (m_flags
& wxRIBBON_PANEL_STRETCH
) != 0;
314 wxSize
wxRibbonPanel::DoGetNextSmallerSize(wxOrientation direction
,
315 wxSize relative_to
) const
317 if(m_expanded_panel
!= NULL
)
319 // Next size depends upon children, who are currently in the
321 return m_expanded_panel
->DoGetNextSmallerSize(direction
, relative_to
);
326 wxClientDC
dc((wxRibbonPanel
*) this);
327 wxSize child_relative
= m_art
->GetPanelClientSize(dc
, this, relative_to
, NULL
);
328 wxSize
smaller(-1, -1);
329 bool minimise
= false;
333 // Get smallest non minimised size
334 smaller
= GetMinSize();
335 // and adjust to child_relative for parent page
336 if(m_art
->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL
)
338 minimise
= (child_relative
.y
<= smaller
.y
);
339 if(smaller
.x
< child_relative
.x
)
340 smaller
.x
= child_relative
.x
;
344 minimise
= (child_relative
.x
<= smaller
.x
);
345 if(smaller
.y
< child_relative
.y
)
346 smaller
.y
= child_relative
.y
;
349 else if(GetChildren().GetCount() == 1)
351 // Simple (and common) case of single ribbon child or Sizer
352 wxWindow
* child
= GetChildren().Item(0)->GetData();
353 wxRibbonControl
* ribbon_child
= wxDynamicCast(child
, wxRibbonControl
);
354 if(ribbon_child
!= NULL
)
356 smaller
= ribbon_child
->GetNextSmallerSize(direction
, child_relative
);
357 minimise
= (smaller
== child_relative
);
363 if(CanAutoMinimise())
365 wxSize minimised
= m_minimised_size
;
369 minimised
.SetHeight(relative_to
.GetHeight());
372 minimised
.SetWidth(relative_to
.GetWidth());
384 else if(smaller
.IsFullySpecified()) // Use fallback if !(sizer/child = 1)
386 return m_art
->GetPanelSize(dc
, this, smaller
, NULL
);
390 // Fallback: Decrease by 20% (or minimum size, whichever larger)
391 wxSize
current(relative_to
);
392 wxSize
minimum(GetMinSize());
393 if(direction
& wxHORIZONTAL
)
395 current
.x
= (current
.x
* 4) / 5;
396 if(current
.x
< minimum
.x
)
398 current
.x
= minimum
.x
;
401 if(direction
& wxVERTICAL
)
403 current
.y
= (current
.y
* 4) / 5;
404 if(current
.y
< minimum
.y
)
406 current
.y
= minimum
.y
;
412 wxSize
wxRibbonPanel::DoGetNextLargerSize(wxOrientation direction
,
413 wxSize relative_to
) const
415 if(m_expanded_panel
!= NULL
)
417 // Next size depends upon children, who are currently in the
419 return m_expanded_panel
->DoGetNextLargerSize(direction
, relative_to
);
422 if(IsMinimised(relative_to
))
424 wxSize current
= relative_to
;
425 wxSize min_size
= GetMinNotMinimisedSize();
429 if(min_size
.x
> current
.x
&& min_size
.y
== current
.y
)
433 if(min_size
.x
== current
.x
&& min_size
.y
> current
.y
)
437 if(min_size
.x
> current
.x
&& min_size
.y
> current
.y
)
447 wxClientDC
dc((wxRibbonPanel
*) this);
448 wxSize child_relative
= m_art
->GetPanelClientSize(dc
, this, relative_to
, NULL
);
449 wxSize
larger(-1, -1);
453 // We could just let the sizer expand in flow direction but see comment
454 // in IsSizingContinuous()
455 larger
= GetPanelSizerBestSize();
456 // and adjust for page in non flow direction
457 if(m_art
->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL
)
459 if(larger
.x
!= child_relative
.x
)
460 larger
.x
= child_relative
.x
;
462 else if(larger
.y
!= child_relative
.y
)
464 larger
.y
= child_relative
.y
;
467 else if(GetChildren().GetCount() == 1)
469 // Simple (and common) case of single ribbon child
470 wxWindow
* child
= GetChildren().Item(0)->GetData();
471 wxRibbonControl
* ribbon_child
= wxDynamicCast(child
, wxRibbonControl
);
472 if(ribbon_child
!= NULL
)
474 larger
= ribbon_child
->GetNextLargerSize(direction
, child_relative
);
478 if(larger
.IsFullySpecified()) // Use fallback if !(sizer/child = 1)
480 if(larger
== child_relative
)
486 return m_art
->GetPanelSize(dc
, this, larger
, NULL
);
491 // Fallback: Increase by 25% (equal to a prior or subsequent 20% decrease)
492 // Note that due to rounding errors, this increase may not exactly equal a
493 // matching decrease - an ideal solution would not have these errors, but
494 // avoiding them is non-trivial unless an increase is by 100% rather than
495 // a fractional amount. This would then be non-ideal as the resizes happen
496 // at very large intervals.
497 wxSize
current(relative_to
);
498 if(direction
& wxHORIZONTAL
)
500 current
.x
= (current
.x
* 5 + 3) / 4;
502 if(direction
& wxVERTICAL
)
504 current
.y
= (current
.y
* 5 + 3) / 4;
509 bool wxRibbonPanel::CanAutoMinimise() const
511 return (m_flags
& wxRIBBON_PANEL_NO_AUTO_MINIMISE
) == 0
512 && m_minimised_size
.IsFullySpecified();
515 wxSize
wxRibbonPanel::GetMinSize() const
517 if(m_expanded_panel
!= NULL
)
519 // Minimum size depends upon children, who are currently in the
521 return m_expanded_panel
->GetMinSize();
524 if(CanAutoMinimise())
526 return m_minimised_size
;
530 return GetMinNotMinimisedSize();
534 wxSize
wxRibbonPanel::GetMinNotMinimisedSize() const
536 // Ask sizer if present
539 wxClientDC
dc((wxRibbonPanel
*) this);
540 return m_art
->GetPanelSize(dc
, this, GetPanelSizerMinSize(), NULL
);
542 else if(GetChildren().GetCount() == 1)
544 // Common case of single child taking up the entire panel
545 wxWindow
* child
= GetChildren().Item(0)->GetData();
546 wxClientDC
dc((wxRibbonPanel
*) this);
547 return m_art
->GetPanelSize(dc
, this, child
->GetMinSize(), NULL
);
550 return wxRibbonControl::GetMinSize();
553 wxSize
wxRibbonPanel::GetPanelSizerMinSize() const
555 // Called from Realize() to set m_smallest_unminimised_size and from other
556 // functions to get the minimum size.
557 // The panel will be invisible when minimised and sizer calcs will be 0
558 // Uses m_smallest_unminimised_size in preference to GetSizer()->CalcMin()
559 // to eliminate flicker.
561 // Check if is visible and not previously calculated
562 if(IsShown() && !m_smallest_unminimised_size
.IsFullySpecified())
564 return GetSizer()->CalcMin();
566 // else use previously calculated m_smallest_unminimised_size
567 wxClientDC
dc((wxRibbonPanel
*) this);
568 return m_art
->GetPanelClientSize(dc
,
570 m_smallest_unminimised_size
,
574 wxSize
wxRibbonPanel::GetPanelSizerBestSize() const
576 wxSize size
= GetPanelSizerMinSize();
577 // TODO allow panel to increase its size beyond minimum size
578 // by steps similarly to ribbon control panels (preferred for aesthetics)
583 wxSize
wxRibbonPanel::DoGetBestSize() const
585 // Ask sizer if present
588 wxClientDC
dc((wxRibbonPanel
*) this);
589 return m_art
->GetPanelSize(dc
, this, GetPanelSizerBestSize(), NULL
);
591 else if(GetChildren().GetCount() == 1)
593 // Common case of no sizer and single child taking up the entire panel
594 wxWindow
* child
= GetChildren().Item(0)->GetData();
595 wxClientDC
dc((wxRibbonPanel
*) this);
596 return m_art
->GetPanelSize(dc
, this, child
->GetBestSize(), NULL
);
599 return wxRibbonControl::DoGetBestSize();
602 bool wxRibbonPanel::Realize()
606 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
608 node
= node
->GetNext())
610 wxRibbonControl
* child
= wxDynamicCast(node
->GetData(), wxRibbonControl
);
615 if(!child
->Realize())
621 wxSize
minimum_children_size(0, 0);
623 // Ask sizer if there is one present
626 minimum_children_size
= GetPanelSizerMinSize();
628 else if(GetChildren().GetCount() == 1)
630 minimum_children_size
= GetChildren().GetFirst()->GetData()->GetMinSize();
635 wxClientDC
temp_dc(this);
637 m_smallest_unminimised_size
=
638 m_art
->GetPanelSize(temp_dc
, this, minimum_children_size
, NULL
);
641 wxSize panel_min_size
= GetMinNotMinimisedSize();
642 m_minimised_size
= m_art
->GetMinimisedPanelMinimumSize(temp_dc
, this,
643 &bitmap_size
, &m_preferred_expand_direction
);
644 if(m_minimised_icon
.IsOk() && m_minimised_icon
.GetSize() != bitmap_size
)
646 wxImage
img(m_minimised_icon
.ConvertToImage());
647 img
.Rescale(bitmap_size
.GetWidth(), bitmap_size
.GetHeight(), wxIMAGE_QUALITY_HIGH
);
648 m_minimised_icon_resized
= wxBitmap(img
);
652 m_minimised_icon_resized
= m_minimised_icon
;
654 if(m_minimised_size
.x
> panel_min_size
.x
&&
655 m_minimised_size
.y
> panel_min_size
.y
)
657 // No point in having a minimised size which is larger than the
658 // minimum size which the children can go to.
659 m_minimised_size
= wxSize(-1, -1);
663 if(m_art
->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL
)
665 m_minimised_size
.x
= panel_min_size
.x
;
669 m_minimised_size
.y
= panel_min_size
.y
;
675 m_minimised_size
= wxSize(-1, -1);
678 return Layout() && status
;
681 bool wxRibbonPanel::Layout()
685 // Children are all invisible when minimised
689 // Get wxRibbonPanel client size
692 wxSize size
= m_art
->GetPanelClientSize(dc
, this, GetSize(), &position
);
694 // If there is a sizer, use it
697 GetSizer()->SetDimension(position
, size
); // SetSize and Layout()
699 else if(GetChildren().GetCount() == 1)
701 // Common case of no sizer and single child taking up the entire panel
702 wxWindow
* child
= GetChildren().Item(0)->GetData();
703 child
->SetSize(position
.x
, position
.y
, size
.GetWidth(), size
.GetHeight());
708 void wxRibbonPanel::OnMouseClick(wxMouseEvent
& WXUNUSED(evt
))
712 if(m_expanded_panel
!= NULL
)
723 wxRibbonPanel
* wxRibbonPanel::GetExpandedDummy()
725 return m_expanded_dummy
;
728 wxRibbonPanel
* wxRibbonPanel::GetExpandedPanel()
730 return m_expanded_panel
;
733 bool wxRibbonPanel::ShowExpanded()
739 if(m_expanded_dummy
!= NULL
|| m_expanded_panel
!= NULL
)
744 wxSize size
= GetBestSize();
745 wxPoint pos
= GetExpandedPosition(wxRect(GetScreenPosition(), GetSize()),
746 size
, m_preferred_expand_direction
).GetTopLeft();
748 // Need a top-level frame to contain the expanded panel
749 wxFrame
*container
= new wxFrame(NULL
, wxID_ANY
, GetLabel(),
750 pos
, size
, wxFRAME_NO_TASKBAR
| wxBORDER_NONE
);
752 m_expanded_panel
= new wxRibbonPanel(container
, wxID_ANY
,
753 GetLabel(), m_minimised_icon
, wxPoint(0, 0), size
, m_flags
);
755 m_expanded_panel
->SetArtProvider(m_art
);
756 m_expanded_panel
->m_expanded_dummy
= this;
758 // Move all children to the new panel.
759 // Conceptually it might be simpler to reparent this entire panel to the
760 // container and create a new panel to sit in its place while expanded.
761 // This approach has a problem though - when the panel is reinserted into
762 // its original parent, it'll be at a different position in the child list
763 // and thus assume a new position.
764 // NB: Children iterators not used as behaviour is not well defined
765 // when iterating over a container which is being emptied
766 while(!GetChildren().IsEmpty())
768 wxWindow
*child
= GetChildren().GetFirst()->GetData();
769 child
->Reparent(m_expanded_panel
);
773 // Move sizer to new panel
776 wxSizer
* sizer
= GetSizer();
777 SetSizer(NULL
, false);
778 m_expanded_panel
->SetSizer(sizer
);
781 m_expanded_panel
->Realize();
783 container
->SetMinClientSize(size
);
785 m_expanded_panel
->SetFocus();
790 bool wxRibbonPanel::ShouldSendEventToDummy(wxEvent
& evt
)
792 // For an expanded panel, filter events between being sent up to the
793 // floating top level window or to the dummy panel sitting in the ribbon
796 // Child focus events should not be redirected, as the child would not be a
797 // child of the window the event is redirected to. All other command events
798 // seem to be suitable for redirecting.
799 return evt
.IsCommandEvent() && evt
.GetEventType() != wxEVT_CHILD_FOCUS
;
802 bool wxRibbonPanel::TryAfter(wxEvent
& evt
)
804 if(m_expanded_dummy
&& ShouldSendEventToDummy(evt
))
806 wxPropagateOnce
propagateOnce(evt
);
807 return m_expanded_dummy
->GetEventHandler()->ProcessEvent(evt
);
811 return wxRibbonControl::TryAfter(evt
);
815 static bool IsAncestorOf(wxWindow
*ancestor
, wxWindow
*window
)
817 while(window
!= NULL
)
819 wxWindow
*parent
= window
->GetParent();
820 if(parent
== ancestor
)
828 void wxRibbonPanel::OnKillFocus(wxFocusEvent
& evt
)
832 wxWindow
*receiver
= evt
.GetWindow();
833 if(IsAncestorOf(this, receiver
))
835 m_child_with_focus
= receiver
;
836 receiver
->Connect(wxEVT_KILL_FOCUS
,
837 wxFocusEventHandler(wxRibbonPanel::OnChildKillFocus
),
840 else if(receiver
== NULL
|| receiver
!= m_expanded_dummy
)
847 void wxRibbonPanel::OnChildKillFocus(wxFocusEvent
& evt
)
849 if(m_child_with_focus
== NULL
)
850 return; // Should never happen, but a check can't hurt
852 m_child_with_focus
->Disconnect(wxEVT_KILL_FOCUS
,
853 wxFocusEventHandler(wxRibbonPanel::OnChildKillFocus
), NULL
, this);
854 m_child_with_focus
= NULL
;
856 wxWindow
*receiver
= evt
.GetWindow();
857 if(receiver
== this || IsAncestorOf(this, receiver
))
859 m_child_with_focus
= receiver
;
860 receiver
->Connect(wxEVT_KILL_FOCUS
,
861 wxFocusEventHandler(wxRibbonPanel::OnChildKillFocus
), NULL
, this);
864 else if(receiver
== NULL
|| receiver
!= m_expanded_dummy
)
867 // Do not skip event, as the panel has been de-expanded, causing the
868 // child with focus to be reparented (and hidden). If the event
869 // continues propogation then bad things happen.
877 bool wxRibbonPanel::HideExpanded()
879 if(m_expanded_dummy
== NULL
)
883 return m_expanded_panel
->HideExpanded();
891 // Move children back to original panel
892 // NB: Children iterators not used as behaviour is not well defined
893 // when iterating over a container which is being emptied
894 while(!GetChildren().IsEmpty())
896 wxWindow
*child
= GetChildren().GetFirst()->GetData();
897 child
->Reparent(m_expanded_dummy
);
904 wxSizer
* sizer
= GetSizer();
905 SetSizer(NULL
, false);
906 m_expanded_dummy
->SetSizer(sizer
);
909 m_expanded_dummy
->m_expanded_panel
= NULL
;
910 m_expanded_dummy
->Realize();
911 m_expanded_dummy
->Refresh();
912 wxWindow
*parent
= GetParent();
919 wxRect
wxRibbonPanel::GetExpandedPosition(wxRect panel
,
920 wxSize expanded_size
,
921 wxDirection direction
)
924 // 1) Determine primary position based on requested direction
925 // 2) Move the position so that it sits entirely within a display
926 // (for single monitor systems, this moves it into the display region,
927 // but for multiple monitors, it does so without splitting it over
928 // more than one display)
929 // 2.1) Move in the primary axis
930 // 2.2) Move in the secondary axis
933 bool primary_x
= false;
939 pos
.x
= panel
.GetX() + (panel
.GetWidth() - expanded_size
.GetWidth()) / 2;
940 pos
.y
= panel
.GetY() - expanded_size
.GetHeight();
945 pos
.x
= panel
.GetRight();
946 pos
.y
= panel
.GetY() + (panel
.GetHeight() - expanded_size
.GetHeight()) / 2;
950 pos
.x
= panel
.GetX() + (panel
.GetWidth() - expanded_size
.GetWidth()) / 2;
951 pos
.y
= panel
.GetBottom();
957 pos
.x
= panel
.GetX() - expanded_size
.GetWidth();
958 pos
.y
= panel
.GetY() + (panel
.GetHeight() - expanded_size
.GetHeight()) / 2;
962 wxRect
expanded(pos
, expanded_size
);
964 wxRect
best(expanded
);
965 int best_distance
= INT_MAX
;
967 const unsigned display_n
= wxDisplay::GetCount();
969 for(display_i
= 0; display_i
< display_n
; ++display_i
)
971 wxRect display
= wxDisplay(display_i
).GetGeometry();
973 if(display
.Contains(expanded
))
977 else if(display
.Intersects(expanded
))
979 wxRect
new_rect(expanded
);
984 if(expanded
.GetRight() > display
.GetRight())
986 distance
= expanded
.GetRight() - display
.GetRight();
987 new_rect
.x
-= distance
;
989 else if(expanded
.GetLeft() < display
.GetLeft())
991 distance
= display
.GetLeft() - expanded
.GetLeft();
992 new_rect
.x
+= distance
;
997 if(expanded
.GetBottom() > display
.GetBottom())
999 distance
= expanded
.GetBottom() - display
.GetBottom();
1000 new_rect
.y
-= distance
;
1002 else if(expanded
.GetTop() < display
.GetTop())
1004 distance
= display
.GetTop() - expanded
.GetTop();
1005 new_rect
.y
+= distance
;
1008 if(!display
.Contains(new_rect
))
1010 // Tried moving in primary axis, but failed.
1011 // Hence try moving in the secondary axis.
1012 int dx
= secondary_x
* (panel
.GetWidth() + expanded_size
.GetWidth());
1013 int dy
= secondary_y
* (panel
.GetHeight() + expanded_size
.GetHeight());
1017 // Squaring makes secondary moves more expensive (and also
1018 // prevents a negative cost)
1019 distance
+= dx
* dx
+ dy
* dy
;
1021 if(display
.Contains(new_rect
) && distance
< best_distance
)
1024 best_distance
= distance
;
1032 #endif // wxUSE_RIBBON