]> git.saurik.com Git - wxWidgets.git/blobdiff - src/ribbon/bar.cpp
Add MUI_LANGUAGE_NAME to wx/msw/missing.h.
[wxWidgets.git] / src / ribbon / bar.cpp
index 1e2acc9e2de3d14c44abfa3c5b204f40b15e9075..e64b381778e028d1ce94e29e5e44fe3860594bf1 100644 (file)
@@ -40,6 +40,7 @@ wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP, wxRibbonBarEvent);
 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN, wxRibbonBarEvent);
 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, wxRibbonBarEvent);
 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TOGGLED, wxRibbonBarEvent);
 
 IMPLEMENT_CLASS(wxRibbonBar, wxRibbonControl)
 IMPLEMENT_DYNAMIC_CLASS(wxRibbonBarEvent, wxNotifyEvent)
@@ -66,6 +67,7 @@ void wxRibbonBar::AddPage(wxRibbonPage *page)
     info.page = page;
     info.active = false;
     info.hovered = false;
+    info.highlight = false;
     info.shown = true;
     // info.rect not set (intentional)
 
@@ -243,6 +245,7 @@ void wxRibbonBar::OnMouseMove(wxMouseEvent& evt)
     {
         RefreshTabBar();
     }
+    HitTestToggleButton(evt.GetPosition());
 }
 
 void wxRibbonBar::OnMouseLeave(wxMouseEvent& WXUNUSED(evt))
@@ -270,6 +273,12 @@ void wxRibbonBar::OnMouseLeave(wxMouseEvent& WXUNUSED(evt))
     {
         RefreshTabBar();
     }
+    if(m_toggle_button_hovered)
+    {
+        m_bar_hovered = false;
+        m_toggle_button_hovered = false;
+        Refresh(false);
+    }
 }
 
 wxRibbonPage* wxRibbonBar::GetPage(int n)
@@ -298,6 +307,20 @@ void wxRibbonBar::ShowPage(size_t page, bool show)
     m_pages.Item(page).shown = show;
 }
 
+bool wxRibbonBar::IsPageHighlighted(size_t page) const
+{
+    if (page >= m_pages.GetCount())
+        return false;
+    return m_pages.Item(page).highlight;
+}
+
+void wxRibbonBar::AddPageHighlight(size_t page, bool highlight)
+{
+    if(page >= m_pages.GetCount())
+        return;
+    m_pages.Item(page).highlight = highlight;
+}
+
 void wxRibbonBar::DeletePage(size_t n)
 {
     if(n < m_pages.GetCount())
@@ -720,6 +743,9 @@ void wxRibbonBar::CommonInit(long style)
         SetArtProvider(new wxRibbonDefaultArtProvider);
     }
     SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+
+    m_toggle_button_hovered = false;
+    m_bar_hovered = false;
 }
 
 void wxRibbonBar::SetArtProvider(wxRibbonArtProvider* art)
@@ -757,6 +783,8 @@ void wxRibbonBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
 
     DoEraseBackground(dc);
 
+    m_toggle_button_rect = m_art->GetBarToggleButtonArea(dc, this, GetSize());
+
     size_t numtabs = m_pages.GetCount();
     double sep_visibility = 0.0;
     bool draw_sep = false;
@@ -830,6 +858,9 @@ void wxRibbonBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
             m_art->DrawScrollButton(dc, this, m_tab_scroll_right_button_rect, wxRIBBON_SCROLL_BTN_RIGHT | m_tab_scroll_right_button_state | wxRIBBON_SCROLL_BTN_FOR_TABS);
         }
     }
+    wxRect rect(GetClientSize().GetWidth() - 30, 6, 12, 12);
+    if ( m_flags & wxRIBBON_BAR_SHOW_TOGGLE_BUTTON  )
+        m_art->DrawToggleButton(dc, this, rect, ArePanelsShown());
 }
 
 void wxRibbonBar::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
@@ -927,6 +958,23 @@ void wxRibbonBar::OnMouseLeftDown(wxMouseEvent& evt)
             RefreshTabBar();
         }
     }
+
+    wxPoint position = evt.GetPosition();
+
+    if(position.x >= 0 && position.y >= 0)
+    {
+        wxSize size = GetSize();
+        if(position.x < size.GetWidth() && position.y < size.GetHeight())
+        {
+            if(m_toggle_button_rect.Contains(position))
+            {
+                ShowPanels(!ArePanelsShown());
+                wxRibbonBarEvent event(wxEVT_COMMAND_RIBBONBAR_TOGGLED, GetId());
+                event.SetEventObject(this);
+                ProcessWindowEvent(event);
+            }
+        }
+    }
 }
 
 void wxRibbonBar::OnMouseLeftUp(wxMouseEvent& WXUNUSED(evt))
@@ -1110,4 +1158,29 @@ wxSize wxRibbonBar::DoGetBestSize() const
     return best;
 }
 
+void wxRibbonBar::HitTestToggleButton(wxPoint position)
+{
+    bool hovered = false, toggle_button_hovered = false;
+    if(position.x >= 0 && position.y >= 0)
+    {
+        wxSize size = GetSize();
+        if(position.x < size.GetWidth() && position.y < size.GetHeight())
+        {
+            hovered = true;
+        }
+    }
+    if(hovered)
+    {
+        toggle_button_hovered = (m_flags & wxRIBBON_BAR_SHOW_TOGGLE_BUTTON) &&
+                                    m_toggle_button_rect.Contains(position);
+
+        if(hovered != m_bar_hovered || toggle_button_hovered != m_toggle_button_hovered)
+        {
+            m_bar_hovered = hovered;
+            m_toggle_button_hovered = toggle_button_hovered;
+            Refresh(false);
+        }
+    }
+}
+
 #endif // wxUSE_RIBBON