]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/themes/gtk.cpp
added wxTreeEvent::GetKeyEvent() to allow to retrieve the key event flags from EVT_TR...
[wxWidgets.git] / src / univ / themes / gtk.cpp
index 9ef37e16d189e9827fe885bcc48fc8f670298b2b..4a0bcfdcc8e7fa919efb8441e6b99bcc673af0d8 100644 (file)
@@ -30,6 +30,7 @@
     #include "wx/dcmemory.h"
     #include "wx/window.h"
 
+    #include "wx/bmpbuttn.h"
     #include "wx/button.h"
     #include "wx/checkbox.h"
     #include "wx/listbox.h"
@@ -204,7 +205,39 @@ public:
                                    wxCoord y,
                                    const wxMenuGeometryInfo& geomInfo);
 #endif
+
+    virtual void DrawFrameTitleBar(wxDC& dc,
+                                   const wxRect& rect,
+                                   const wxString& title,
+                                   const wxIcon& icon,
+                                   int flags,
+                                   int pressedButtons = 0);
+    virtual void DrawFrameBorder(wxDC& dc,
+                                 const wxRect& rect,
+                                 int flags);
+    virtual void DrawFrameBackground(wxDC& dc,
+                                     const wxRect& rect,
+                                     int flags);
+    virtual void DrawFrameTitle(wxDC& dc,
+                                const wxRect& rect,
+                                const wxString& title,
+                                int flags);
+    virtual void DrawFrameIcon(wxDC& dc,
+                               const wxRect& rect,
+                               const wxIcon& icon,
+                               int flags);
+    virtual void DrawFrameButton(wxDC& dc,
+                                 wxCoord x, wxCoord y,
+                                 int button,
+                                 int flags = 0);
+
+    // titlebars
+    virtual wxRect GetFrameClientArea(const wxRect& rect, int flags) const;
+    virtual wxSize GetFrameTotalSize(const wxSize& clientSize, int flags) const;
+    virtual wxSize GetFrameIconSize() const;
+
     virtual void GetComboBitmaps(wxBitmap *bmpNormal,
+                                 wxBitmap *bmpFocus,
                                  wxBitmap *bmpPressed,
                                  wxBitmap *bmpDisabled);
 
@@ -370,6 +403,9 @@ protected:
                                   wxAlignment align,
                                   int indexAccel);
 
+    // initialize the combo bitmaps
+    void InitComboBitmaps();
+
 private:
     const wxColourScheme *m_scheme;
 
@@ -390,6 +426,18 @@ private:
 
     // the line wrap bitmap (drawn at the end of wrapped lines)
     wxBitmap m_bmpLineWrap;
+
+    // the combobox bitmaps
+    enum
+    {
+        ComboState_Normal,
+        ComboState_Focus,
+        ComboState_Pressed,
+        ComboState_Disabled,
+        ComboState_Max
+    };
+
+    wxBitmap m_bitmapsCombo[ComboState_Max];
 };
 
 // ----------------------------------------------------------------------------
@@ -402,12 +450,12 @@ class wxGTKInputHandler : public wxInputHandler
 public:
     wxGTKInputHandler(wxGTKRenderer *renderer);
 
-    virtual bool HandleKey(wxControl *control,
+    virtual bool HandleKey(wxInputConsumer *control,
                            const wxKeyEvent& event,
                            bool pressed);
-    virtual bool HandleMouse(wxControl *control,
+    virtual bool HandleMouse(wxInputConsumer *control,
                              const wxMouseEvent& event);
-    virtual bool HandleMouseMove(wxControl *control, const wxMouseEvent& event);
+    virtual bool HandleMouseMove(wxInputConsumer *control, const wxMouseEvent& event);
 
 protected:
     wxGTKRenderer *m_renderer;
@@ -453,7 +501,7 @@ public:
     wxGTKCheckboxInputHandler(wxInputHandler *handler)
         : wxStdCheckboxInputHandler(handler) { }
 
-    virtual bool HandleKey(wxControl *control,
+    virtual bool HandleKey(wxInputConsumer *control,
                            const wxKeyEvent& event,
                            bool pressed);
 };
@@ -464,7 +512,7 @@ public:
     wxGTKTextCtrlInputHandler(wxInputHandler *handler)
         : wxStdTextCtrlInputHandler(handler) { }
 
-    virtual bool HandleKey(wxControl *control,
+    virtual bool HandleKey(wxInputConsumer *control,
                            const wxKeyEvent& event,
                            bool pressed);
 };
@@ -849,7 +897,10 @@ void wxGTKRenderer::DrawBorder(wxDC& dc,
             break;
 
         case wxBORDER_STATIC:
-            DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
+            for ( width = 0; width < BORDER_THICKNESS; width++ )
+            {
+                DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
+            }
             break;
 
         case wxBORDER_RAISED:
@@ -860,13 +911,19 @@ void wxGTKRenderer::DrawBorder(wxDC& dc,
             break;
 
         case wxBORDER_DOUBLE:
-            DrawShadedRect(dc, &rect, m_penLightGrey, m_penBlack);
-            DrawShadedRect(dc, &rect, m_penHighlight, m_penDarkGrey);
-            DrawRect(dc, &rect, m_penLightGrey);
+            for ( width = 0; width < BORDER_THICKNESS; width++ )
+            {
+                DrawShadedRect(dc, &rect, m_penLightGrey, m_penBlack);
+                DrawShadedRect(dc, &rect, m_penHighlight, m_penDarkGrey);
+                DrawRect(dc, &rect, m_penLightGrey);
+            }
             break;
 
         case wxBORDER_SIMPLE:
-            DrawRect(dc, &rect, m_penBlack);
+            for ( width = 0; width < BORDER_THICKNESS; width++ )
+            {
+                DrawRect(dc, &rect, m_penBlack);
+            }
             break;
 
         default:
@@ -894,11 +951,11 @@ wxRect wxGTKRenderer::GetBorderDimensions(wxBorder border) const
 
         case wxBORDER_SIMPLE:
         case wxBORDER_STATIC:
-            width = 1;
+            width = BORDER_THICKNESS;
             break;
 
         case wxBORDER_DOUBLE:
-            width = 3;
+            width = 3*BORDER_THICKNESS;
             break;
 
         default:
@@ -938,15 +995,18 @@ void wxGTKRenderer::DrawTextBorder(wxDC& dc,
 {
     wxRect rect = rectOrig;
 
-    if ( flags & wxCONTROL_FOCUSED )
+    if ( border != wxBORDER_NONE )
     {
-        DrawRect(dc, &rect, m_penBlack);
-        DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
-    }
-    else // !focused
-    {
-        DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
-        DrawAntiShadedRect(dc, &rect, m_penBlack, m_penHighlight);
+        if ( flags & wxCONTROL_FOCUSED )
+        {
+            DrawRect(dc, &rect, m_penBlack);
+            DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
+        }
+        else // !focused
+        {
+            DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
+            DrawAntiShadedRect(dc, &rect, m_penBlack, m_penHighlight);
+        }
     }
 
     if ( rectIn )
@@ -964,8 +1024,12 @@ void wxGTKRenderer::DrawButtonBorder(wxDC& dc,
     {
         // button pressed: draw a black border around it and an inward shade
         DrawRect(dc, &rect, m_penBlack);
-        DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
-        DrawAntiShadedRect(dc, &rect, m_penBlack, m_penDarkGrey);
+
+        for ( size_t width = 0; width < BORDER_THICKNESS; width++ )
+        {
+            DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
+            DrawAntiShadedRect(dc, &rect, m_penBlack, m_penDarkGrey);
+        }
     }
     else
     {
@@ -983,10 +1047,13 @@ void wxGTKRenderer::DrawButtonBorder(wxDC& dc,
         }
 
         // now draw a normal button
-        DrawShadedRect(dc, &rect, m_penHighlight, m_penBlack);
-        DrawAntiShadedRect(dc, &rect,
-                           wxPen(GetBackgroundColour(flags), 0, wxSOLID),
-                           m_penDarkGrey);
+        for ( size_t width = 0; width < BORDER_THICKNESS; width++ )
+        {
+            DrawShadedRect(dc, &rect, m_penHighlight, m_penBlack);
+            DrawAntiShadedRect(dc, &rect,
+                               wxPen(GetBackgroundColour(flags), 0, wxSOLID),
+                               m_penDarkGrey);
+        }
     }
 
     if ( rectIn )
@@ -1456,13 +1523,11 @@ void wxGTKRenderer::DrawRadioButton(wxDC& dc,
 // text control
 // ----------------------------------------------------------------------------
 
-static const int TEXT_BORDER = 2;
-
 wxRect wxGTKRenderer::GetTextTotalArea(const wxTextCtrl *text,
                                        const wxRect& rect)
 {
     wxRect rectTotal = rect;
-    rectTotal.Inflate(TEXT_BORDER);
+    rectTotal.Inflate(2*BORDER_THICKNESS);
     return rectTotal;
 }
 
@@ -1471,7 +1536,7 @@ wxRect wxGTKRenderer::GetTextClientArea(const wxTextCtrl *text,
                                         wxCoord *extraSpaceBeyond)
 {
     wxRect rectText = rect;
-    rectText.Inflate(-TEXT_BORDER);
+    rectText.Inflate(-2*BORDER_THICKNESS);
 
     if ( text->WrapLines() )
     {
@@ -1792,16 +1857,64 @@ wxMenuGeometryInfo *wxGTKRenderer::GetMenuGeometry(wxWindow *win,
 
     return NULL;
 }
-#endif
+#endif // wxUSE_MENUS
+
 // ----------------------------------------------------------------------------
 // combobox
 // ----------------------------------------------------------------------------
 
+void wxGTKRenderer::InitComboBitmaps()
+{
+    wxSize sizeArrow = m_sizeScrollbarArrow;
+    sizeArrow.x -= 2;
+    sizeArrow.y -= 2;
+
+    size_t n;
+
+    for ( n = ComboState_Normal; n < ComboState_Max; n++ )
+    {
+        m_bitmapsCombo[n].Create(sizeArrow.x, sizeArrow.y);
+    }
+
+    static const int comboButtonFlags[ComboState_Max] =
+    {
+        0,
+        wxCONTROL_CURRENT,
+        wxCONTROL_PRESSED,
+        wxCONTROL_DISABLED,
+    };
+
+    wxRect rect(wxPoint(0, 0), sizeArrow);
+
+    wxMemoryDC dc;
+    for ( n = ComboState_Normal; n < ComboState_Max; n++ )
+    {
+        int flags = comboButtonFlags[n];
+
+        dc.SelectObject(m_bitmapsCombo[n]);
+        DoDrawBackground(dc, GetBackgroundColour(flags), rect);
+        DrawArrow(dc, wxDOWN, rect, flags);
+    }
+}
+
 void wxGTKRenderer::GetComboBitmaps(wxBitmap *bmpNormal,
+                                    wxBitmap *bmpFocus,
                                     wxBitmap *bmpPressed,
                                     wxBitmap *bmpDisabled)
 {
-    // TODO
+    if ( !m_bitmapsCombo[ComboState_Normal].Ok() )
+    {
+        InitComboBitmaps();
+    }
+
+    if ( bmpNormal )
+        *bmpNormal = m_bitmapsCombo[ComboState_Normal];
+    if ( bmpFocus )
+        *bmpFocus = m_bitmapsCombo[ComboState_Focus];
+    if ( bmpPressed )
+        *bmpPressed = m_bitmapsCombo[ComboState_Pressed];
+    if ( bmpDisabled )
+        *bmpDisabled = m_bitmapsCombo[ComboState_Disabled];
 }
 
 // ----------------------------------------------------------------------------
@@ -2216,20 +2329,30 @@ int wxGTKRenderer::PixelToScrollbar(const wxScrollBar *scrollbar,
 
 void wxGTKRenderer::AdjustSize(wxSize *size, const wxWindow *window)
 {
-    if ( wxDynamicCast(window, wxButton) )
+#if wxUSE_BMPBUTTON
+    if ( wxDynamicCast(window, wxBitmapButton) )
     {
-        // TODO: this is ad hoc...
-        size->x += 3*window->GetCharWidth();
-        if ( size->x < 80 )
-            size->x = 80;
-        wxCoord minBtnHeight = 22;
-        if ( size->y < minBtnHeight )
-            size->y = minBtnHeight;
-
-        // button border width
+        size->x += 4;
         size->y += 4;
-    }
-    else if ( wxDynamicCast(window, wxScrollBar) )
+    } else
+#endif // wxUSE_BMPBUTTON
+#if wxUSE_BUTTON
+    if ( wxDynamicCast(window, wxButton) )
+    {
+        if ( !(window->GetWindowStyle() & wxBU_EXACTFIT) )
+        {
+            // TODO: this is ad hoc...
+            size->x += 3*window->GetCharWidth();
+            wxCoord minBtnHeight = 18;
+            if ( size->y < minBtnHeight )
+                size->y = minBtnHeight;
+
+            // button border width
+            size->y += 4;
+        }
+    } else
+#endif wxUSE_BUTTON
+    if ( wxDynamicCast(window, wxScrollBar) )
     {
         // we only set the width of vert scrollbars and height of the
         // horizontal ones
@@ -2247,6 +2370,69 @@ void wxGTKRenderer::AdjustSize(wxSize *size, const wxWindow *window)
     }
 }
 
+// ----------------------------------------------------------------------------
+// top level windows
+// ----------------------------------------------------------------------------
+
+void wxGTKRenderer::DrawFrameTitleBar(wxDC& dc,
+                                      const wxRect& rect,
+                                      const wxString& title,
+                                      const wxIcon& icon,
+                                      int flags,
+                                      int pressedButtons = 0)
+{
+}
+
+void wxGTKRenderer::DrawFrameBorder(wxDC& dc,
+                                    const wxRect& rect,
+                                    int flags)
+{
+}
+
+void wxGTKRenderer::DrawFrameBackground(wxDC& dc,
+                                        const wxRect& rect,
+                                        int flags)
+{
+}
+
+void wxGTKRenderer::DrawFrameTitle(wxDC& dc,
+                                   const wxRect& rect,
+                                   const wxString& title,
+                                   int flags)
+{
+}
+
+void wxGTKRenderer::DrawFrameIcon(wxDC& dc,
+                                  const wxRect& rect,
+                                  const wxIcon& icon,
+                                  int flags)
+{
+}
+
+void wxGTKRenderer::DrawFrameButton(wxDC& dc,
+                                    wxCoord x, wxCoord y,
+                                    int button,
+                                    int flags = 0)
+{
+}
+
+wxRect wxGTKRenderer::GetFrameClientArea(const wxRect& rect, int flags) const
+{
+    return rect;
+}
+
+wxSize wxGTKRenderer::GetFrameTotalSize(const wxSize& clientSize, int flags) const
+{
+    return clientSize;
+}
+
+wxSize wxGTKRenderer::GetFrameIconSize() const
+{
+    return wxSize(-1, -1);
+}
+
+
+
 // ============================================================================
 // wxInputHandler
 // ============================================================================
@@ -2260,20 +2446,20 @@ wxGTKInputHandler::wxGTKInputHandler(wxGTKRenderer *renderer)
     m_renderer = renderer;
 }
 
-bool wxGTKInputHandler::HandleKey(wxControl *control,
+bool wxGTKInputHandler::HandleKey(wxInputConsumer *control,
                                   const wxKeyEvent& event,
                                   bool pressed)
 {
     return FALSE;
 }
 
-bool wxGTKInputHandler::HandleMouse(wxControl *control,
+bool wxGTKInputHandler::HandleMouse(wxInputConsumer *control,
                                     const wxMouseEvent& event)
 {
     // clicking on the control gives it focus
-    if ( event.ButtonDown() )
+    if ( event.ButtonDown() && wxWindow::FindFocus() != control->GetInputWindow() )
     {
-        control->SetFocus();
+        control->GetInputWindow()->SetFocus();
 
         return TRUE;
     }
@@ -2281,16 +2467,16 @@ bool wxGTKInputHandler::HandleMouse(wxControl *control,
     return FALSE;
 }
 
-bool wxGTKInputHandler::HandleMouseMove(wxControl *control,
+bool wxGTKInputHandler::HandleMouseMove(wxInputConsumer *control,
                                         const wxMouseEvent& event)
 {
     if ( event.Entering() )
     {
-        control->SetCurrent(TRUE);
+        control->GetInputWindow()->SetCurrent(TRUE);
     }
     else if ( event.Leaving() )
     {
-        control->SetCurrent(FALSE);
+        control->GetInputWindow()->SetCurrent(FALSE);
     }
     else
     {
@@ -2304,7 +2490,7 @@ bool wxGTKInputHandler::HandleMouseMove(wxControl *control,
 // wxGTKCheckboxInputHandler
 // ----------------------------------------------------------------------------
 
-bool wxGTKCheckboxInputHandler::HandleKey(wxControl *control,
+bool wxGTKCheckboxInputHandler::HandleKey(wxInputConsumer *control,
                                           const wxKeyEvent& event,
                                           bool pressed)
 {
@@ -2326,7 +2512,7 @@ bool wxGTKCheckboxInputHandler::HandleKey(wxControl *control,
 // wxGTKTextCtrlInputHandler
 // ----------------------------------------------------------------------------
 
-bool wxGTKTextCtrlInputHandler::HandleKey(wxControl *control,
+bool wxGTKTextCtrlInputHandler::HandleKey(wxInputConsumer *control,
                                           const wxKeyEvent& event,
                                           bool pressed)
 {