// Author: Peter Cawley
// Modified by:
// Created: 2009-05-25
-// RCS-ID: $Id$
// Copyright: (C) Peter Cawley
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#include "wx/msw/private.h"
#endif
+wxDEFINE_EVENT(wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, wxRibbonPanelEvent);
+
+IMPLEMENT_DYNAMIC_CLASS(wxRibbonPanelEvent, wxCommandEvent)
+
IMPLEMENT_CLASS(wxRibbonPanel, wxRibbonControl)
BEGIN_EVENT_TABLE(wxRibbonPanel, wxRibbonControl)
EVT_ERASE_BACKGROUND(wxRibbonPanel::OnEraseBackground)
EVT_KILL_FOCUS(wxRibbonPanel::OnKillFocus)
EVT_LEAVE_WINDOW(wxRibbonPanel::OnMouseLeave)
+ EVT_MOTION(wxRibbonPanel::OnMotion)
EVT_LEFT_DOWN(wxRibbonPanel::OnMouseClick)
EVT_PAINT(wxRibbonPanel::OnPaint)
EVT_SIZE(wxRibbonPanel::OnSize)
m_minimised_icon = icon;
m_minimised = false;
m_hovered = false;
+ m_ext_button_hovered = false;
if(m_art == NULL)
{
return m_hovered;
}
+bool wxRibbonPanel::IsExtButtonHovered() const
+{
+ return m_ext_button_hovered;
+}
+
void wxRibbonPanel::OnMouseEnter(wxMouseEvent& evt)
{
TestPositionForHover(evt.GetPosition());
evt.Skip();
}
+void wxRibbonPanel::OnMotion(wxMouseEvent& evt)
+{
+ TestPositionForHover(evt.GetPosition());
+}
+
void wxRibbonPanel::TestPositionForHover(const wxPoint& pos)
{
- bool hovered = false;
+ bool hovered = false, ext_button_hovered = false;
if(pos.x >= 0 && pos.y >= 0)
{
wxSize size = GetSize();
hovered = true;
}
}
- if(hovered != m_hovered)
+ if(hovered)
+ {
+ if(HasExtButton())
+ ext_button_hovered = m_ext_button_rect.Contains(pos);
+ else
+ ext_button_hovered = false;
+ }
+ if(hovered != m_hovered || ext_button_hovered != m_ext_button_hovered)
{
m_hovered = hovered;
+ m_ext_button_hovered = ext_button_hovered;
Refresh(false);
}
}
// for children of the window. The panel wants to be in the hovered state
// whenever the mouse cursor is within its boundary, so the events need to
// be attached to children too.
- child->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)&wxRibbonPanel::OnMouseEnterChild, NULL, this);
- child->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)&wxRibbonPanel::OnMouseLeaveChild, NULL, this);
+ child->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(wxRibbonPanel::OnMouseEnterChild), NULL, this);
+ child->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(wxRibbonPanel::OnMouseLeaveChild), NULL, this);
}
void wxRibbonPanel::RemoveChild(wxWindowBase *child)
{
- child->Disconnect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)&wxRibbonPanel::OnMouseEnterChild, NULL, this);
- child->Disconnect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)&wxRibbonPanel::OnMouseLeaveChild, NULL, this);
+ child->Disconnect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(wxRibbonPanel::OnMouseEnterChild), NULL, this);
+ child->Disconnect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(wxRibbonPanel::OnMouseLeaveChild), NULL, this);
wxRibbonControl::RemoveChild(child);
}
+bool wxRibbonPanel::HasExtButton()const
+{
+ wxRibbonBar* bar = GetAncestorRibbonBar();
+ if(bar==NULL)
+ return false;
+ return (m_flags & wxRIBBON_PANEL_EXT_BUTTON) &&
+ (bar->GetWindowStyleFlag() & wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS);
+}
+
void wxRibbonPanel::OnSize(wxSizeEvent& evt)
{
if(GetAutoLayout())
return (m_flags & wxRIBBON_PANEL_STRETCH) != 0;
}
+// Finds the best width and height given the parent's width and height
+wxSize wxRibbonPanel::GetBestSizeForParentSize(const wxSize& parentSize) const
+{
+ if (GetChildren().GetCount() == 1)
+ {
+ wxWindow* win = GetChildren().GetFirst()->GetData();
+ wxRibbonControl* control = wxDynamicCast(win, wxRibbonControl);
+ if (control)
+ {
+ wxClientDC temp_dc((wxRibbonPanel*) this);
+ wxSize clientParentSize = m_art->GetPanelClientSize(temp_dc, this, parentSize, NULL);
+ wxSize childSize = control->GetBestSizeForParentSize(clientParentSize);
+ wxSize overallSize = m_art->GetPanelSize(temp_dc, this, childSize, NULL);
+ return overallSize;
+ }
+ }
+ return GetSize();
+}
+
wxSize wxRibbonPanel::DoGetNextSmallerSize(wxOrientation direction,
wxSize relative_to) const
{
wxWindow* child = GetChildren().Item(0)->GetData();
child->SetSize(position.x, position.y, size.GetWidth(), size.GetHeight());
}
+
+ if(HasExtButton())
+ m_ext_button_rect = m_art->GetPanelExtButtonArea(dc, this, GetSize());
+
return true;
}
ShowExpanded();
}
}
+ else if(IsExtButtonHovered())
+ {
+ wxRibbonPanelEvent notification(wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, GetId());
+ notification.SetEventObject(this);
+ notification.SetPanel(this);
+ ProcessEvent(notification);
+ }
}
wxRibbonPanel* wxRibbonPanel::GetExpandedDummy()
}
wxSize size = GetBestSize();
+
+ // Special case for flexible panel layout, where GetBestSize doesn't work
+ if (GetFlags() & wxRIBBON_PANEL_FLEXIBLE)
+ {
+ size = GetBestSizeForParentSize(wxSize(400, 1000));
+ }
+
wxPoint pos = GetExpandedPosition(wxRect(GetScreenPosition(), GetSize()),
size, m_preferred_expand_direction).GetTopLeft();
pos, size, wxFRAME_NO_TASKBAR | wxBORDER_NONE);
m_expanded_panel = new wxRibbonPanel(container, wxID_ANY,
- GetLabel(), m_minimised_icon, wxPoint(0, 0), size, m_flags);
+ GetLabel(), m_minimised_icon, wxPoint(0, 0), size, (m_flags /* & ~wxRIBBON_PANEL_FLEXIBLE */));
m_expanded_panel->SetArtProvider(m_art);
m_expanded_panel->m_expanded_dummy = this;
HideExpanded();
// Do not skip event, as the panel has been de-expanded, causing the
// child with focus to be reparented (and hidden). If the event
- // continues propogation then bad things happen.
+ // continues propagation then bad things happen.
}
else
{
return best;
}
+void wxRibbonPanel::HideIfExpanded()
+{
+ wxStaticCast(m_parent, wxRibbonPage)->HideIfExpanded();
+}
+
#endif // wxUSE_RIBBON