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 // Finds the best width and height given the parent's width and height
315 wxSize
wxRibbonPanel::GetBestSizeForParentSize(const wxSize
& parentSize
) const
317 if (GetChildren().GetCount() == 1)
319 wxWindow
* win
= GetChildren().GetFirst()->GetData();
320 wxRibbonControl
* control
= wxDynamicCast(win
, wxRibbonControl
);
323 wxClientDC
temp_dc((wxRibbonPanel
*) this);
324 wxSize clientParentSize
= m_art
->GetPanelClientSize(temp_dc
, this, parentSize
, NULL
);
325 wxSize childSize
= control
->GetBestSizeForParentSize(clientParentSize
);
326 wxSize overallSize
= m_art
->GetPanelSize(temp_dc
, this, childSize
, NULL
);
333 wxSize
wxRibbonPanel::DoGetNextSmallerSize(wxOrientation direction
,
334 wxSize relative_to
) const
336 if(m_expanded_panel
!= NULL
)
338 // Next size depends upon children, who are currently in the
340 return m_expanded_panel
->DoGetNextSmallerSize(direction
, relative_to
);
345 wxClientDC
dc((wxRibbonPanel
*) this);
346 wxSize child_relative
= m_art
->GetPanelClientSize(dc
, this, relative_to
, NULL
);
347 wxSize
smaller(-1, -1);
348 bool minimise
= false;
352 // Get smallest non minimised size
353 smaller
= GetMinSize();
354 // and adjust to child_relative for parent page
355 if(m_art
->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL
)
357 minimise
= (child_relative
.y
<= smaller
.y
);
358 if(smaller
.x
< child_relative
.x
)
359 smaller
.x
= child_relative
.x
;
363 minimise
= (child_relative
.x
<= smaller
.x
);
364 if(smaller
.y
< child_relative
.y
)
365 smaller
.y
= child_relative
.y
;
368 else if(GetChildren().GetCount() == 1)
370 // Simple (and common) case of single ribbon child or Sizer
371 wxWindow
* child
= GetChildren().Item(0)->GetData();
372 wxRibbonControl
* ribbon_child
= wxDynamicCast(child
, wxRibbonControl
);
373 if(ribbon_child
!= NULL
)
375 smaller
= ribbon_child
->GetNextSmallerSize(direction
, child_relative
);
376 minimise
= (smaller
== child_relative
);
382 if(CanAutoMinimise())
384 wxSize minimised
= m_minimised_size
;
388 minimised
.SetHeight(relative_to
.GetHeight());
391 minimised
.SetWidth(relative_to
.GetWidth());
403 else if(smaller
.IsFullySpecified()) // Use fallback if !(sizer/child = 1)
405 return m_art
->GetPanelSize(dc
, this, smaller
, NULL
);
409 // Fallback: Decrease by 20% (or minimum size, whichever larger)
410 wxSize
current(relative_to
);
411 wxSize
minimum(GetMinSize());
412 if(direction
& wxHORIZONTAL
)
414 current
.x
= (current
.x
* 4) / 5;
415 if(current
.x
< minimum
.x
)
417 current
.x
= minimum
.x
;
420 if(direction
& wxVERTICAL
)
422 current
.y
= (current
.y
* 4) / 5;
423 if(current
.y
< minimum
.y
)
425 current
.y
= minimum
.y
;
431 wxSize
wxRibbonPanel::DoGetNextLargerSize(wxOrientation direction
,
432 wxSize relative_to
) const
434 if(m_expanded_panel
!= NULL
)
436 // Next size depends upon children, who are currently in the
438 return m_expanded_panel
->DoGetNextLargerSize(direction
, relative_to
);
441 if(IsMinimised(relative_to
))
443 wxSize current
= relative_to
;
444 wxSize min_size
= GetMinNotMinimisedSize();
448 if(min_size
.x
> current
.x
&& min_size
.y
== current
.y
)
452 if(min_size
.x
== current
.x
&& min_size
.y
> current
.y
)
456 if(min_size
.x
> current
.x
&& min_size
.y
> current
.y
)
466 wxClientDC
dc((wxRibbonPanel
*) this);
467 wxSize child_relative
= m_art
->GetPanelClientSize(dc
, this, relative_to
, NULL
);
468 wxSize
larger(-1, -1);
472 // We could just let the sizer expand in flow direction but see comment
473 // in IsSizingContinuous()
474 larger
= GetPanelSizerBestSize();
475 // and adjust for page in non flow direction
476 if(m_art
->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL
)
478 if(larger
.x
!= child_relative
.x
)
479 larger
.x
= child_relative
.x
;
481 else if(larger
.y
!= child_relative
.y
)
483 larger
.y
= child_relative
.y
;
486 else if(GetChildren().GetCount() == 1)
488 // Simple (and common) case of single ribbon child
489 wxWindow
* child
= GetChildren().Item(0)->GetData();
490 wxRibbonControl
* ribbon_child
= wxDynamicCast(child
, wxRibbonControl
);
491 if(ribbon_child
!= NULL
)
493 larger
= ribbon_child
->GetNextLargerSize(direction
, child_relative
);
497 if(larger
.IsFullySpecified()) // Use fallback if !(sizer/child = 1)
499 if(larger
== child_relative
)
505 return m_art
->GetPanelSize(dc
, this, larger
, NULL
);
510 // Fallback: Increase by 25% (equal to a prior or subsequent 20% decrease)
511 // Note that due to rounding errors, this increase may not exactly equal a
512 // matching decrease - an ideal solution would not have these errors, but
513 // avoiding them is non-trivial unless an increase is by 100% rather than
514 // a fractional amount. This would then be non-ideal as the resizes happen
515 // at very large intervals.
516 wxSize
current(relative_to
);
517 if(direction
& wxHORIZONTAL
)
519 current
.x
= (current
.x
* 5 + 3) / 4;
521 if(direction
& wxVERTICAL
)
523 current
.y
= (current
.y
* 5 + 3) / 4;
528 bool wxRibbonPanel::CanAutoMinimise() const
530 return (m_flags
& wxRIBBON_PANEL_NO_AUTO_MINIMISE
) == 0
531 && m_minimised_size
.IsFullySpecified();
534 wxSize
wxRibbonPanel::GetMinSize() const
536 if(m_expanded_panel
!= NULL
)
538 // Minimum size depends upon children, who are currently in the
540 return m_expanded_panel
->GetMinSize();
543 if(CanAutoMinimise())
545 return m_minimised_size
;
549 return GetMinNotMinimisedSize();
553 wxSize
wxRibbonPanel::GetMinNotMinimisedSize() const
555 // Ask sizer if present
558 wxClientDC
dc((wxRibbonPanel
*) this);
559 return m_art
->GetPanelSize(dc
, this, GetPanelSizerMinSize(), NULL
);
561 else if(GetChildren().GetCount() == 1)
563 // Common case of single child taking up the entire panel
564 wxWindow
* child
= GetChildren().Item(0)->GetData();
565 wxClientDC
dc((wxRibbonPanel
*) this);
566 return m_art
->GetPanelSize(dc
, this, child
->GetMinSize(), NULL
);
569 return wxRibbonControl::GetMinSize();
572 wxSize
wxRibbonPanel::GetPanelSizerMinSize() const
574 // Called from Realize() to set m_smallest_unminimised_size and from other
575 // functions to get the minimum size.
576 // The panel will be invisible when minimised and sizer calcs will be 0
577 // Uses m_smallest_unminimised_size in preference to GetSizer()->CalcMin()
578 // to eliminate flicker.
580 // Check if is visible and not previously calculated
581 if(IsShown() && !m_smallest_unminimised_size
.IsFullySpecified())
583 return GetSizer()->CalcMin();
585 // else use previously calculated m_smallest_unminimised_size
586 wxClientDC
dc((wxRibbonPanel
*) this);
587 return m_art
->GetPanelClientSize(dc
,
589 m_smallest_unminimised_size
,
593 wxSize
wxRibbonPanel::GetPanelSizerBestSize() const
595 wxSize size
= GetPanelSizerMinSize();
596 // TODO allow panel to increase its size beyond minimum size
597 // by steps similarly to ribbon control panels (preferred for aesthetics)
602 wxSize
wxRibbonPanel::DoGetBestSize() const
604 // Ask sizer if present
607 wxClientDC
dc((wxRibbonPanel
*) this);
608 return m_art
->GetPanelSize(dc
, this, GetPanelSizerBestSize(), NULL
);
610 else if(GetChildren().GetCount() == 1)
612 // Common case of no sizer and single child taking up the entire panel
613 wxWindow
* child
= GetChildren().Item(0)->GetData();
614 wxClientDC
dc((wxRibbonPanel
*) this);
615 return m_art
->GetPanelSize(dc
, this, child
->GetBestSize(), NULL
);
618 return wxRibbonControl::DoGetBestSize();
621 bool wxRibbonPanel::Realize()
625 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
627 node
= node
->GetNext())
629 wxRibbonControl
* child
= wxDynamicCast(node
->GetData(), wxRibbonControl
);
634 if(!child
->Realize())
640 wxSize
minimum_children_size(0, 0);
642 // Ask sizer if there is one present
645 minimum_children_size
= GetPanelSizerMinSize();
647 else if(GetChildren().GetCount() == 1)
649 minimum_children_size
= GetChildren().GetFirst()->GetData()->GetMinSize();
654 wxClientDC
temp_dc(this);
656 m_smallest_unminimised_size
=
657 m_art
->GetPanelSize(temp_dc
, this, minimum_children_size
, NULL
);
660 wxSize panel_min_size
= GetMinNotMinimisedSize();
661 m_minimised_size
= m_art
->GetMinimisedPanelMinimumSize(temp_dc
, this,
662 &bitmap_size
, &m_preferred_expand_direction
);
663 if(m_minimised_icon
.IsOk() && m_minimised_icon
.GetSize() != bitmap_size
)
665 wxImage
img(m_minimised_icon
.ConvertToImage());
666 img
.Rescale(bitmap_size
.GetWidth(), bitmap_size
.GetHeight(), wxIMAGE_QUALITY_HIGH
);
667 m_minimised_icon_resized
= wxBitmap(img
);
671 m_minimised_icon_resized
= m_minimised_icon
;
673 if(m_minimised_size
.x
> panel_min_size
.x
&&
674 m_minimised_size
.y
> panel_min_size
.y
)
676 // No point in having a minimised size which is larger than the
677 // minimum size which the children can go to.
678 m_minimised_size
= wxSize(-1, -1);
682 if(m_art
->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL
)
684 m_minimised_size
.x
= panel_min_size
.x
;
688 m_minimised_size
.y
= panel_min_size
.y
;
694 m_minimised_size
= wxSize(-1, -1);
697 return Layout() && status
;
700 bool wxRibbonPanel::Layout()
704 // Children are all invisible when minimised
708 // Get wxRibbonPanel client size
711 wxSize size
= m_art
->GetPanelClientSize(dc
, this, GetSize(), &position
);
713 // If there is a sizer, use it
716 GetSizer()->SetDimension(position
, size
); // SetSize and Layout()
718 else if(GetChildren().GetCount() == 1)
720 // Common case of no sizer and single child taking up the entire panel
721 wxWindow
* child
= GetChildren().Item(0)->GetData();
722 child
->SetSize(position
.x
, position
.y
, size
.GetWidth(), size
.GetHeight());
727 void wxRibbonPanel::OnMouseClick(wxMouseEvent
& WXUNUSED(evt
))
731 if(m_expanded_panel
!= NULL
)
742 wxRibbonPanel
* wxRibbonPanel::GetExpandedDummy()
744 return m_expanded_dummy
;
747 wxRibbonPanel
* wxRibbonPanel::GetExpandedPanel()
749 return m_expanded_panel
;
752 bool wxRibbonPanel::ShowExpanded()
758 if(m_expanded_dummy
!= NULL
|| m_expanded_panel
!= NULL
)
763 wxSize size
= GetBestSize();
765 // Special case for flexible panel layout, where GetBestSize doesn't work
766 if (GetFlags() & wxRIBBON_PANEL_FLEXIBLE
)
768 size
= GetBestSizeForParentSize(wxSize(400, 1000));
771 wxPoint pos
= GetExpandedPosition(wxRect(GetScreenPosition(), GetSize()),
772 size
, m_preferred_expand_direction
).GetTopLeft();
774 // Need a top-level frame to contain the expanded panel
775 wxFrame
*container
= new wxFrame(NULL
, wxID_ANY
, GetLabel(),
776 pos
, size
, wxFRAME_NO_TASKBAR
| wxBORDER_NONE
);
778 m_expanded_panel
= new wxRibbonPanel(container
, wxID_ANY
,
779 GetLabel(), m_minimised_icon
, wxPoint(0, 0), size
, (m_flags
/* & ~wxRIBBON_PANEL_FLEXIBLE */));
781 m_expanded_panel
->SetArtProvider(m_art
);
782 m_expanded_panel
->m_expanded_dummy
= this;
784 // Move all children to the new panel.
785 // Conceptually it might be simpler to reparent this entire panel to the
786 // container and create a new panel to sit in its place while expanded.
787 // This approach has a problem though - when the panel is reinserted into
788 // its original parent, it'll be at a different position in the child list
789 // and thus assume a new position.
790 // NB: Children iterators not used as behaviour is not well defined
791 // when iterating over a container which is being emptied
792 while(!GetChildren().IsEmpty())
794 wxWindow
*child
= GetChildren().GetFirst()->GetData();
795 child
->Reparent(m_expanded_panel
);
799 // Move sizer to new panel
802 wxSizer
* sizer
= GetSizer();
803 SetSizer(NULL
, false);
804 m_expanded_panel
->SetSizer(sizer
);
807 m_expanded_panel
->Realize();
809 container
->SetMinClientSize(size
);
811 m_expanded_panel
->SetFocus();
816 bool wxRibbonPanel::ShouldSendEventToDummy(wxEvent
& evt
)
818 // For an expanded panel, filter events between being sent up to the
819 // floating top level window or to the dummy panel sitting in the ribbon
822 // Child focus events should not be redirected, as the child would not be a
823 // child of the window the event is redirected to. All other command events
824 // seem to be suitable for redirecting.
825 return evt
.IsCommandEvent() && evt
.GetEventType() != wxEVT_CHILD_FOCUS
;
828 bool wxRibbonPanel::TryAfter(wxEvent
& evt
)
830 if(m_expanded_dummy
&& ShouldSendEventToDummy(evt
))
832 wxPropagateOnce
propagateOnce(evt
);
833 return m_expanded_dummy
->GetEventHandler()->ProcessEvent(evt
);
837 return wxRibbonControl::TryAfter(evt
);
841 static bool IsAncestorOf(wxWindow
*ancestor
, wxWindow
*window
)
843 while(window
!= NULL
)
845 wxWindow
*parent
= window
->GetParent();
846 if(parent
== ancestor
)
854 void wxRibbonPanel::OnKillFocus(wxFocusEvent
& evt
)
858 wxWindow
*receiver
= evt
.GetWindow();
859 if(IsAncestorOf(this, receiver
))
861 m_child_with_focus
= receiver
;
862 receiver
->Connect(wxEVT_KILL_FOCUS
,
863 wxFocusEventHandler(wxRibbonPanel::OnChildKillFocus
),
866 else if(receiver
== NULL
|| receiver
!= m_expanded_dummy
)
873 void wxRibbonPanel::OnChildKillFocus(wxFocusEvent
& evt
)
875 if(m_child_with_focus
== NULL
)
876 return; // Should never happen, but a check can't hurt
878 m_child_with_focus
->Disconnect(wxEVT_KILL_FOCUS
,
879 wxFocusEventHandler(wxRibbonPanel::OnChildKillFocus
), NULL
, this);
880 m_child_with_focus
= NULL
;
882 wxWindow
*receiver
= evt
.GetWindow();
883 if(receiver
== this || IsAncestorOf(this, receiver
))
885 m_child_with_focus
= receiver
;
886 receiver
->Connect(wxEVT_KILL_FOCUS
,
887 wxFocusEventHandler(wxRibbonPanel::OnChildKillFocus
), NULL
, this);
890 else if(receiver
== NULL
|| receiver
!= m_expanded_dummy
)
893 // Do not skip event, as the panel has been de-expanded, causing the
894 // child with focus to be reparented (and hidden). If the event
895 // continues propogation then bad things happen.
903 bool wxRibbonPanel::HideExpanded()
905 if(m_expanded_dummy
== NULL
)
909 return m_expanded_panel
->HideExpanded();
917 // Move children back to original panel
918 // NB: Children iterators not used as behaviour is not well defined
919 // when iterating over a container which is being emptied
920 while(!GetChildren().IsEmpty())
922 wxWindow
*child
= GetChildren().GetFirst()->GetData();
923 child
->Reparent(m_expanded_dummy
);
930 wxSizer
* sizer
= GetSizer();
931 SetSizer(NULL
, false);
932 m_expanded_dummy
->SetSizer(sizer
);
935 m_expanded_dummy
->m_expanded_panel
= NULL
;
936 m_expanded_dummy
->Realize();
937 m_expanded_dummy
->Refresh();
938 wxWindow
*parent
= GetParent();
945 wxRect
wxRibbonPanel::GetExpandedPosition(wxRect panel
,
946 wxSize expanded_size
,
947 wxDirection direction
)
950 // 1) Determine primary position based on requested direction
951 // 2) Move the position so that it sits entirely within a display
952 // (for single monitor systems, this moves it into the display region,
953 // but for multiple monitors, it does so without splitting it over
954 // more than one display)
955 // 2.1) Move in the primary axis
956 // 2.2) Move in the secondary axis
959 bool primary_x
= false;
965 pos
.x
= panel
.GetX() + (panel
.GetWidth() - expanded_size
.GetWidth()) / 2;
966 pos
.y
= panel
.GetY() - expanded_size
.GetHeight();
971 pos
.x
= panel
.GetRight();
972 pos
.y
= panel
.GetY() + (panel
.GetHeight() - expanded_size
.GetHeight()) / 2;
976 pos
.x
= panel
.GetX() + (panel
.GetWidth() - expanded_size
.GetWidth()) / 2;
977 pos
.y
= panel
.GetBottom();
983 pos
.x
= panel
.GetX() - expanded_size
.GetWidth();
984 pos
.y
= panel
.GetY() + (panel
.GetHeight() - expanded_size
.GetHeight()) / 2;
988 wxRect
expanded(pos
, expanded_size
);
990 wxRect
best(expanded
);
991 int best_distance
= INT_MAX
;
993 const unsigned display_n
= wxDisplay::GetCount();
995 for(display_i
= 0; display_i
< display_n
; ++display_i
)
997 wxRect display
= wxDisplay(display_i
).GetGeometry();
999 if(display
.Contains(expanded
))
1003 else if(display
.Intersects(expanded
))
1005 wxRect
new_rect(expanded
);
1010 if(expanded
.GetRight() > display
.GetRight())
1012 distance
= expanded
.GetRight() - display
.GetRight();
1013 new_rect
.x
-= distance
;
1015 else if(expanded
.GetLeft() < display
.GetLeft())
1017 distance
= display
.GetLeft() - expanded
.GetLeft();
1018 new_rect
.x
+= distance
;
1023 if(expanded
.GetBottom() > display
.GetBottom())
1025 distance
= expanded
.GetBottom() - display
.GetBottom();
1026 new_rect
.y
-= distance
;
1028 else if(expanded
.GetTop() < display
.GetTop())
1030 distance
= display
.GetTop() - expanded
.GetTop();
1031 new_rect
.y
+= distance
;
1034 if(!display
.Contains(new_rect
))
1036 // Tried moving in primary axis, but failed.
1037 // Hence try moving in the secondary axis.
1038 int dx
= secondary_x
* (panel
.GetWidth() + expanded_size
.GetWidth());
1039 int dy
= secondary_y
* (panel
.GetHeight() + expanded_size
.GetHeight());
1043 // Squaring makes secondary moves more expensive (and also
1044 // prevents a negative cost)
1045 distance
+= dx
* dx
+ dy
* dy
;
1047 if(display
.Contains(new_rect
) && distance
< best_distance
)
1050 best_distance
= distance
;
1058 #endif // wxUSE_RIBBON