diff --git a/include/wx/scrolbar.h b/include/wx/scrolbar.h index 4630c70054..066dd0659f 100644 --- a/include/wx/scrolbar.h +++ b/include/wx/scrolbar.h @@ -36,7 +36,7 @@ public: bool refresh = TRUE) = 0; }; -#if defined(__WXMSW__) +#if defined(__WXUNIVERSAL__) #include "wx/univ/scrolbar.h" #elif defined(__WXMSW__) #include "wx/msw/scrolbar.h" diff --git a/include/wx/univ/colschem.h b/include/wx/univ/colschem.h index 793c4dc30d..b172a5a5bc 100644 --- a/include/wx/univ/colschem.h +++ b/include/wx/univ/colschem.h @@ -31,6 +31,7 @@ public: // the background and text colour for the control CONTROL, CONTROL_TEXT, + SCROLLBAR, // the background and text colour for the highlighted item HIGHLIGHT, diff --git a/include/wx/univ/control.h b/include/wx/univ/control.h index e4f8760106..bd1641fc4b 100644 --- a/include/wx/univ/control.h +++ b/include/wx/univ/control.h @@ -16,6 +16,8 @@ #pragma interface "control.h" #endif +#include "wx/bitmap.h" // for m_bitmapBg + class WXDLLEXPORT wxControlRenderer; class WXDLLEXPORT wxInputHandler; diff --git a/include/wx/univ/renderer.h b/include/wx/univ/renderer.h index cb0f1e0659..08e97f546d 100644 --- a/include/wx/univ/renderer.h +++ b/include/wx/univ/renderer.h @@ -38,7 +38,6 @@ class WXDLLEXPORT wxRenderer public: // draw the controls background virtual void DrawBackground(wxDC& dc, - const wxColour& col, const wxRect& rect, int flags) = 0; @@ -86,7 +85,8 @@ public: int thumbPosStart, int thumbPosEnd, const wxRect& rect, - int flags = 0) = 0; + int flags = 0, + int extraFlags = 0) = 0; // TODO: having this is ugly but I don't see how to solve GetBestSize() // problem without something like this @@ -114,10 +114,9 @@ public: wxDelegateRenderer(wxRenderer *renderer) : m_renderer(renderer) { } virtual void DrawBackground(wxDC& dc, - const wxColour& col, const wxRect& rect, int flags) - { m_renderer->DrawBackground(dc, col, rect, flags); } + { m_renderer->DrawBackground(dc, rect, flags); } virtual void DrawLabel(wxDC& dc, const wxString& label, const wxRect& rect, @@ -153,9 +152,10 @@ public: int thumbPosStart, int thumbPosEnd, const wxRect& rect, - int flags = 0) + int flags = 0, + int extraFlags = 0) { m_renderer->DrawScrollbar(dc, orient, thumbPosStart, - thumbPosEnd, rect, flags); } + thumbPosEnd, rect, flags, extraFlags); } virtual void AdjustSize(wxSize *size, const wxWindow *window) { m_renderer->AdjustSize(size, window); } @@ -181,7 +181,7 @@ public: void DrawButtonBorder(); void DrawFrame(); void DrawBackgroundBitmap(); - void DrawScrollbar(int thumbStart, int thumbEnd); + void DrawScrollbar(int thumbStart, int thumbEnd, int extraFlags = 0); // accessors wxRenderer *GetRenderer() const { return m_renderer; } diff --git a/include/wx/univ/scrolbar.h b/include/wx/univ/scrolbar.h index e8a3f6f404..4fd7516b41 100644 --- a/include/wx/univ/scrolbar.h +++ b/include/wx/univ/scrolbar.h @@ -22,6 +22,12 @@ class WXDLLEXPORT wxInputHandler; // the actions supported by this control // ---------------------------------------------------------------------------- +// various parts of scrollbar may be highlighted +#define wxACTION_SCROLL_HIGHLIGHT_ARROW_UP _T("focusarrowup") +#define wxACTION_SCROLL_HIGHLIGHT_ARROW_DOWN _T("focusarrowdown") +#define wxACTION_SCROLL_HIGHLIGHT_THUMB _T("focusthumb") +#define wxACTION_SCROLL_HIGHLIGHT_BAR _T("focusbar") + // scroll the bar #define wxACTION_SCROLL_START _T("start") // to the beginning #define wxACTION_SCROLL_END _T("end") // to the end @@ -45,6 +51,15 @@ class WXDLLEXPORT wxInputHandler; class WXDLLEXPORT wxScrollBar : public wxScrollBarBase { public: + enum + { + // which part of scrollbar is currently highlighted? + Highlight_Arrow1 = 0x0001, + Highlight_Arrow2 = 0x0002, + Highlight_Thumb = 0x0004, + Highlight_Bar = 0x0008 + }; + wxScrollBar() { Init(); } wxScrollBar(wxWindow *parent, wxWindowID id, @@ -52,7 +67,7 @@ public: const wxSize& size = wxDefaultSize, long style = wxSB_HORIZONTAL, const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr) + const wxString& name = wxScrollBarNameStr) { Init(); @@ -65,7 +80,7 @@ public: const wxSize& size = wxDefaultSize, long style = wxSB_HORIZONTAL, const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); + const wxString& name = wxScrollBarNameStr); virtual ~wxScrollBar(); diff --git a/samples/univ/univ.cpp b/samples/univ/univ.cpp index 3c56761a7b..23cb613fe5 100644 --- a/samples/univ/univ.cpp +++ b/samples/univ/univ.cpp @@ -120,7 +120,11 @@ bool MyUnivApp::OnInit() MyUnivFrame::MyUnivFrame(const wxString& title) : wxFrame(NULL, -1, title, wxDefaultPosition, wxSize(600, 450)) { +#ifdef __WXMSW__ SetBackgroundColour(*wxLIGHT_GREY); +#else + SetBackgroundColour(0xd6d6d6); +#endif wxStaticText *text; diff --git a/src/univ/control.cpp b/src/univ/control.cpp index 737b609ac9..ca15a296b1 100644 --- a/src/univ/control.cpp +++ b/src/univ/control.cpp @@ -30,6 +30,7 @@ #if wxUSE_CONTROLS #ifndef WX_PRECOMP + #include "wx/app.h" #include "wx/control.h" #include "wx/dcclient.h" #endif @@ -48,14 +49,7 @@ BEGIN_EVENT_TABLE(wxControl, wxControlBase) EVT_KEY_DOWN(wxControl::OnKeyDown) EVT_KEY_UP(wxControl::OnKeyUp) - EVT_LEFT_DOWN(wxControl::OnMouse) - EVT_LEFT_UP(wxControl::OnMouse) - EVT_RIGHT_DOWN(wxControl::OnMouse) - EVT_RIGHT_UP(wxControl::OnMouse) - EVT_MIDDLE_DOWN(wxControl::OnMouse) - EVT_MIDDLE_UP(wxControl::OnMouse) - EVT_LEAVE_WINDOW(wxControl::OnMouse) - EVT_ENTER_WINDOW(wxControl::OnMouse) + EVT_MOUSE_EVENTS(wxControl::OnMouse) EVT_SET_FOCUS(wxControl::OnFocus) EVT_KILL_FOCUS(wxControl::OnFocus) diff --git a/src/univ/files.lst b/src/univ/files.lst index d6c1210718..47912b43f9 100644 --- a/src/univ/files.lst +++ b/src/univ/files.lst @@ -4,6 +4,7 @@ UNIVOBJS = \ control.o \ inphand.o \ renderer.o \ + scrolbar.o \ statbox.o \ stattext.o \ theme.o \ diff --git a/src/univ/renderer.cpp b/src/univ/renderer.cpp index d2ad1536ee..6951f731ce 100644 --- a/src/univ/renderer.cpp +++ b/src/univ/renderer.cpp @@ -74,8 +74,7 @@ void wxControlRenderer::DrawBorder() m_rect, flags, &m_rect); // fill the inside (TODO: query the theme for bg bitmap) - m_renderer->DrawBackground(m_dc, - m_ctrl->GetBackgroundColour(), m_rect, flags); + m_renderer->DrawBackground(m_dc, m_rect, flags); } void wxControlRenderer::DrawLabel() @@ -111,8 +110,7 @@ void wxControlRenderer::DrawButtonBorder() m_renderer->DrawButtonBorder(m_dc, m_rect, flags, &m_rect); - m_renderer->DrawBackground(m_dc, m_ctrl->GetBackgroundColour(), - m_rect, flags); + m_renderer->DrawBackground(m_dc, m_rect, flags); } void wxControlRenderer::DrawBackgroundBitmap() diff --git a/src/univ/scrolbar.cpp b/src/univ/scrolbar.cpp index 0105be2836..5041110167 100644 --- a/src/univ/scrolbar.cpp +++ b/src/univ/scrolbar.cpp @@ -65,6 +65,10 @@ bool wxScrollBar::Create(wxWindow *parent, const wxValidator& validator, const wxString &name) { + // the scrollbars always have the standard border so far + style &= ~wxBORDER_MASK; + style |= wxBORDER_SUNKEN; + if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return FALSE; diff --git a/src/univ/themes/gtk.cpp b/src/univ/themes/gtk.cpp index 2b4d9502b1..95a243e2c3 100644 --- a/src/univ/themes/gtk.cpp +++ b/src/univ/themes/gtk.cpp @@ -26,13 +26,16 @@ #ifndef WX_PRECOMP #include "wx/intl.h" - #include "wx/button.h" #include "wx/dc.h" #include "wx/window.h" + + #include "wx/button.h" + #include "wx/scrolbar.h" #endif // WX_PRECOMP #include "wx/univ/renderer.h" #include "wx/univ/inphand.h" +#include "wx/univ/colschem.h" #include "wx/univ/theme.h" // ---------------------------------------------------------------------------- @@ -42,13 +45,12 @@ class wxGTKRenderer : public wxRenderer { public: - wxGTKRenderer(); + wxGTKRenderer(const wxColourScheme *scheme); // implement the base class pure virtuals virtual void DrawBackground(wxDC& dc, - const wxColour& col, const wxRect& rect, - int flags); + int flags = 0); virtual void DrawLabel(wxDC& dc, const wxString& label, const wxRect& rect, @@ -70,10 +72,26 @@ public: const wxRect& rect, int flags = 0, wxRect *rectIn = (wxRect *)NULL); + virtual void DrawArrow(wxDC& dc, + wxDirection dir, + const wxRect& rect, + int flags = 0); + virtual void DrawScrollbar(wxDC& dc, + wxOrientation orient, + int thumbPosStart, + int thumbPosEnd, + const wxRect& rect, + int flags = 0, + int extraFlags = 0); virtual void AdjustSize(wxSize *size, const wxWindow *window); protected: + // DrawBackground() helper + void DoDrawBackground(wxDC& dc, + const wxColour& col, + const wxRect& rect); + // DrawBorder() helpers: all of them shift and clip the DC after drawing // the border @@ -97,10 +115,16 @@ protected: void DrawRaisedBorder(wxDC& dc, wxRect *rect); private: + const wxColourScheme *m_scheme; + + // data + wxSize m_sizeScrollbarArrow; + + // GDI objects wxPen m_penBlack, m_penDarkGrey, + m_penGrey, m_penLightGrey, - m_penWhite, m_penHighlight; }; @@ -129,6 +153,19 @@ private: bool m_winHasMouse; }; +class wxGTKScrollBarInputHandler : public wxGTKInputHandler +{ +public: + wxGTKScrollBarInputHandler(); + + virtual wxControlActions Map(const wxKeyEvent& event, bool pressed); + virtual wxControlActions Map(const wxMouseEvent& event); + +private: + wxWindow *m_winCapture; + bool m_winHasMouse; +}; + // ---------------------------------------------------------------------------- // wxGTKColourScheme: uses the standard GTK colours // ---------------------------------------------------------------------------- @@ -136,7 +173,7 @@ private: class wxGTKColourScheme : public wxColourScheme { public: - virtual wxColour Get(StdColour col); + virtual wxColour Get(StdColour col, int flags = 0) const; }; // ---------------------------------------------------------------------------- @@ -153,7 +190,7 @@ public: virtual wxRenderer *GetRenderer() { return m_renderer; } virtual wxInputHandler *GetInputHandler(const wxString& control); - virtual wxColourScheme *GetColourScheme() { return m_scheme; } + virtual wxColourScheme *GetColourScheme(const wxString& control) { return m_scheme; } private: wxGTKRenderer *m_renderer; @@ -180,8 +217,8 @@ WX_IMPLEMENT_THEME(wxGTKTheme, gtk, wxTRANSLATE("GTK+ theme")); wxGTKTheme::wxGTKTheme() { - m_renderer = new wxGTKRenderer; m_scheme = new wxGTKColourScheme; + m_renderer = new wxGTKRenderer(m_scheme); } wxGTKTheme::~wxGTKTheme() @@ -200,6 +237,8 @@ wxInputHandler *wxGTKTheme::GetInputHandler(const wxString& control) if ( control == wxCONTROL_BUTTON ) handler = new wxGTKButtonInputHandler; + else if ( control == wxCONTROL_SCROLLBAR ) + handler = new wxGTKScrollBarInputHandler; else { wxASSERT_MSG( control == wxCONTROL_DEFAULT, @@ -222,23 +261,40 @@ wxInputHandler *wxGTKTheme::GetInputHandler(const wxString& control) // wxGTKColourScheme // ============================================================================ -wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col) +wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col, + int flags) const { switch ( col ) { - case DARK_SHADOW: return wxColour(0x7f7f7f); - case FACE: return wxColour(0xc0c0c0); - case HIGHLIGHT: return wxColour(0xe0e0e0); - case LIGHT: return wxColour(0xffffff); - case SHADOW: return wxColour(0xc0c0c0); - case CONTROL_TEXT: return wxColour(0x000000); - case HIGHLIGHT: return wxColour(0x0000ff); - case HIGHLIGHT_TEXT:return wxColour(0x00ffff); + case SHADOW_DARK: return *wxBLACK; + case SHADOW_HIGHLIGHT: return *wxWHITE; + case SHADOW_IN: return wxColour(0xd6d6d6); + case SHADOW_OUT: return wxColour(0x969696); + + case CONTROL: + if ( flags & wxCONTROL_PRESSED ) + { + return wxColour(0x7f7f7f); + } + else if ( flags & wxCONTROL_CURRENT ) + { + return wxColour(0xeaeaea); + } + else + { + return wxColour(0xd6d6d6); + } + + case CONTROL_TEXT: return *wxBLACK; + case SCROLLBAR: return wxColour(0xc3c3c3); + + case HIGHLIGHT: return wxColour(0x0000ff); + case HIGHLIGHT_TEXT: return wxColour(0x00ffff); case MAX: default: wxFAIL_MSG(_T("invalid standard colour")); - return wxColour(0x000000); + return *wxBLACK; } } @@ -250,86 +306,24 @@ wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col) // construction // ---------------------------------------------------------------------------- -wxGTKRenderer::wxGTKRenderer() - : m_penBlack(*wxBLACK_PEN), - m_penDarkGrey(wxColour(0x7f7f7f), 0, wxSOLID), - m_penLightGrey(wxColour(0xc0c0c0), 0, wxSOLID), - m_penWhite(*wxWHITE_PEN), - m_penHighlight(wxColour(0xe0e0e0), 0, wxSOLID) +wxGTKRenderer::wxGTKRenderer(const wxColourScheme *scheme) { + // init data + m_scheme = scheme; + m_sizeScrollbarArrow = wxSize(12, 12); + + // init pens + m_penBlack = wxPen(scheme->Get(wxColourScheme::SHADOW_DARK), 0, wxSOLID); + m_penDarkGrey = wxPen(scheme->Get(wxColourScheme::SHADOW_OUT), 0, wxSOLID); + m_penGrey = wxPen(scheme->Get(wxColourScheme::SCROLLBAR), 0, wxSOLID); + m_penLightGrey = wxPen(scheme->Get(wxColourScheme::SHADOW_IN), 0, wxSOLID); + m_penHighlight = wxPen(scheme->Get(wxColourScheme::SHADOW_HIGHLIGHT), 0, wxSOLID); } // ---------------------------------------------------------------------------- // border stuff // ---------------------------------------------------------------------------- -/* - The raised border in GTK looks like this: - - IIIIIIIIIIIIIIIIIIIIIIB - I GB - I GB I = white (HILIGHT) - I GB H = light grey (LIGHT) - I GB G = dark grey (SHADOI) - I GB B = black (DKSHADOI) - I GB I = hIghlight (COLOR_3DHILIGHT) - I GB - IGGGGGGGGGGGGGGGGGGGGGB - BBBBBBBBBBBBBBBBBBBBBBB - - The sunken border looks like this: - - GGGGGGGGGGGGGGGGGGGGGGI - GBBBBBBBBBBBBBBBBBBBBHI - GB HI - GB HI - GB HI - GB HI - GB HI - GB HI - GHHHHHHHHHHHHHHHHHHHHHI - IIIIIIIIIIIIIIIIIIIIIII - - The static border (used for the controls which don't get focus) is like - this: - - GGGGGGGGGGGGGGGGGGGGGGW - G W - G W - G W - G W - G W - G W - G W - WWWWWWWWWWWWWWWWWWWWWWW - - The most complicated is the double border: - - HHHHHHHHHHHHHHHHHHHHHHB - HWWWWWWWWWWWWWWWWWWWWGB - HWHHHHHHHHHHHHHHHHHHHGB - HWH HGB - HWH HGB - HWH HGB - HWH HGB - HWHHHHHHHHHHHHHHHHHHHGB - HGGGGGGGGGGGGGGGGGGGGGB - BBBBBBBBBBBBBBBBBBBBBBB - - And the simple border is, well, simple: - - BBBBBBBBBBBBBBBBBBBBBBB - B B - B B - B B - B B - B B - B B - B B - B B - BBBBBBBBBBBBBBBBBBBBBBB -*/ - void wxGTKRenderer::DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen) { // draw @@ -572,32 +566,250 @@ void wxGTKRenderer::DrawLabel(wxDC& dc, // background // ---------------------------------------------------------------------------- -void wxGTKRenderer::DrawBackground(wxDC& dc, - const wxColour& col, - const wxRect& rect, - int flags) +void wxGTKRenderer::DoDrawBackground(wxDC& dc, + const wxColour& col, + const wxRect& rect) { - // what colour should we use? - wxColour colBg; - if ( flags & wxCONTROL_PRESSED ) - { - colBg = wxColour(0x7f7f7f); - } - else if ( flags & wxCONTROL_CURRENT ) - { - colBg = wxColour(0xe0e0e0); - } - else - { - colBg = col; - } - - wxBrush brush(colBg, wxSOLID); + wxBrush brush(col, wxSOLID); dc.SetBrush(brush); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(rect); } +void wxGTKRenderer::DrawBackground(wxDC& dc, + const wxRect& rect, + int flags) +{ + DoDrawBackground(dc, m_scheme->Get(wxColourScheme::CONTROL, flags), rect); +} + +// ---------------------------------------------------------------------------- +// scrollbar +// ---------------------------------------------------------------------------- + +// gtk_default_draw_arrow() takes ~350 lines and we can't do much better here +// these people are just crazy :-( +void wxGTKRenderer::DrawArrow(wxDC& dc, + wxDirection dir, + const wxRect& rect, + int flags) +{ + enum + { + Point_First, + Point_Second, + Point_Third, + Point_Max + }; + + wxPoint ptArrow[Point_Max]; + + wxCoord middle; + if ( dir == wxUP || dir == wxDOWN ) + { + // horz middle + middle = (rect.GetRight() + rect.GetLeft() + 1) / 2; + } + else // horz arrow + { + middle = (rect.GetTop() + rect.GetBottom() + 1) / 2; + } + + // draw the arrow interior + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(wxBrush(m_scheme->Get(wxColourScheme::CONTROL), wxSOLID)); + + switch ( dir ) + { + case wxUP: + ptArrow[Point_First].x = rect.GetLeft(); + ptArrow[Point_First].y = rect.GetBottom(); + ptArrow[Point_Second].x = middle; + ptArrow[Point_Second].y = rect.GetTop(); + ptArrow[Point_Third].x = rect.GetRight(); + ptArrow[Point_Third].y = rect.GetBottom(); + break; + + case wxDOWN: + ptArrow[Point_First] = rect.GetPosition(); + ptArrow[Point_Second].x = middle; + ptArrow[Point_Second].y = rect.GetBottom(); + ptArrow[Point_Third].x = rect.GetRight(); + ptArrow[Point_Third].y = rect.GetTop(); + break; + + case wxLEFT: + ptArrow[Point_First].x = rect.GetRight(); + ptArrow[Point_First].y = rect.GetTop(); + ptArrow[Point_Second].x = rect.GetLeft(); + ptArrow[Point_Second].y = middle; + ptArrow[Point_Third].x = rect.GetRight(); + ptArrow[Point_Third].y = rect.GetBottom(); + break; + + case wxRIGHT: + ptArrow[Point_First] = rect.GetPosition(); + ptArrow[Point_Second].x = rect.GetRight(); + ptArrow[Point_Second].y = middle; + ptArrow[Point_Third].x = rect.GetLeft(); + ptArrow[Point_Third].y = rect.GetBottom(); + break; + + default: + wxFAIL_MSG(_T("unknown arrow direction")); + return; + } + + dc.DrawPolygon(WXSIZEOF(ptArrow), ptArrow); + + // draw the arrow border + dc.SetPen(m_penHighlight); + switch ( dir ) + { + case wxUP: + dc.DrawLine(ptArrow[Point_Second], ptArrow[Point_First]); + dc.DrawPoint(ptArrow[Point_First]); + dc.SetPen(m_penBlack); + dc.DrawLine(ptArrow[Point_Second].x + 1, ptArrow[Point_Second].y + 1, + ptArrow[Point_Third].x, ptArrow[Point_Third].y); + dc.DrawPoint(ptArrow[Point_Third]); + dc.DrawLine(ptArrow[Point_Third].x - 2, ptArrow[Point_Third].y, + ptArrow[Point_First].x + 1, ptArrow[Point_First].y); + dc.SetPen(m_penDarkGrey); + dc.DrawLine(ptArrow[Point_Third].x - 1, ptArrow[Point_Third].y, + ptArrow[Point_Second].x, ptArrow[Point_Second].y + 1); + dc.DrawLine(ptArrow[Point_Third].x - 1, ptArrow[Point_Third].y - 1, + ptArrow[Point_First].x + 2, ptArrow[Point_First].y - 1); + break; + + case wxDOWN: + dc.DrawLine(ptArrow[Point_First], ptArrow[Point_Second]); + dc.DrawLine(ptArrow[Point_First].x + 2, ptArrow[Point_First].y, + ptArrow[Point_Third].x - 1, ptArrow[Point_Third].y); + dc.SetPen(m_penDarkGrey); + dc.DrawLine(ptArrow[Point_Second].x, ptArrow[Point_Second].y - 1, + ptArrow[Point_Third].x - 1, ptArrow[Point_Third].y - 1); + dc.SetPen(m_penBlack); + dc.DrawLine(ptArrow[Point_Second], ptArrow[Point_Third]); + dc.DrawPoint(ptArrow[Point_Third]); + break; + + case wxLEFT: + dc.DrawLine(ptArrow[Point_Second], ptArrow[Point_First]); + dc.DrawPoint(ptArrow[Point_First]); + dc.SetPen(m_penDarkGrey); + dc.DrawLine(ptArrow[Point_Third].x - 1, ptArrow[Point_Third].y, + ptArrow[Point_First].x - 1, ptArrow[Point_First].y + 2); + dc.DrawLine(ptArrow[Point_Third].x, ptArrow[Point_Third].y, + ptArrow[Point_Second].x + 2, ptArrow[Point_Second].y + 1); + dc.SetPen(m_penBlack); + dc.DrawLine(ptArrow[Point_Third].x, ptArrow[Point_Third].y, + ptArrow[Point_First].x, ptArrow[Point_First].y + 1); + dc.DrawLine(ptArrow[Point_Second].x + 1, ptArrow[Point_Second].y + 1, + ptArrow[Point_Third].x - 1, ptArrow[Point_Third].y); + break; + + case wxRIGHT: + dc.DrawLine(ptArrow[Point_First], ptArrow[Point_Third]); + dc.DrawLine(ptArrow[Point_First].x + 2, ptArrow[Point_First].y + 1, + ptArrow[Point_Second].x, ptArrow[Point_Second].y); + dc.SetPen(m_penBlack); + dc.DrawLine(ptArrow[Point_Second], ptArrow[Point_Third]); + dc.DrawPoint(ptArrow[Point_Third]); + break; + + default: + wxFAIL_MSG(_T("unknown arrow direction")); + return; + } +} + +void wxGTKRenderer::DrawScrollbar(wxDC& dc, + wxOrientation orient, + int thumbPosStart, + int thumbPosEnd, + const wxRect& rect, + int flags, + int extraFlags) +{ + // handling of wxCONTROL_CURRENT flag is complicated for the scrollbar + // because, though it's only one window, either an arrow or a thumb may be + // highlighted depending on where exactly the mouse is + int flagsArrows[2], flagsThumb; + flagsArrows[0] = + flagsArrows[1] = + flagsThumb = flags & ~wxCONTROL_CURRENT; + if ( flags & wxCONTROL_CURRENT ) + { + if ( extraFlags & wxScrollBar::Highlight_Arrow1 ) + flagsArrows[0] |= wxCONTROL_CURRENT; + if ( extraFlags & wxScrollBar::Highlight_Arrow2 ) + flagsArrows[1] |= wxCONTROL_CURRENT; + if ( extraFlags & wxScrollBar::Highlight_Thumb ) + flagsThumb |= wxCONTROL_CURRENT; + } + + // first draw the scrollbar area background + wxRect rectBar = rect; + DrawAntiShadedRect(dc, &rectBar, m_penDarkGrey, m_penHighlight); + DrawAntiShadedRect(dc, &rectBar, m_penBlack, m_penGrey); + DoDrawBackground(dc, m_scheme->Get(wxColourScheme::SCROLLBAR), rectBar); + + // next draw the arrows at the ends + wxRect rectArrow[2]; + wxDirection arrowDir[2]; + + rectArrow[0] = + rectArrow[1] = rectBar; + if ( orient == wxVERTICAL ) + { + rectArrow[0].height = + rectArrow[1].height = m_sizeScrollbarArrow.y - 1; + rectArrow[1].y = rectBar.GetBottom() - rectArrow[1].height + 1; + + arrowDir[0] = wxUP; + arrowDir[1] = wxDOWN; + } + else // horizontal + { + rectArrow[0].width = + rectArrow[1].width = m_sizeScrollbarArrow.x - 1; + rectArrow[1].x = rectBar.GetRight() - rectArrow[1].width + 1; + + arrowDir[0] = wxLEFT; + arrowDir[1] = wxRIGHT; + } + + for ( size_t nArrow = 0; nArrow < 2; nArrow++ ) + { + DrawArrow(dc, arrowDir[nArrow], rectArrow[nArrow], flags); + } + + // and, finally, the thumb, if any + if ( thumbPosStart < thumbPosEnd ) + { + wxRect rectThumb; + if ( orient == wxVERTICAL ) + { + rectBar.Inflate(0, -m_sizeScrollbarArrow.y); + rectThumb = rectBar; + rectThumb.y += (rectBar.height*thumbPosStart)/100; + rectThumb.height = (rectBar.height*(thumbPosEnd - thumbPosStart))/100; + } + else // horizontal + { + rectBar.Inflate(-m_sizeScrollbarArrow.x, 0); + rectThumb = rectBar; + rectThumb.x += (rectBar.width*thumbPosStart)/100; + rectThumb.width = (rectBar.width*(thumbPosEnd - thumbPosStart))/100; + } + + // the thumb never has focus border under GTK + DrawButtonBorder(dc, rectThumb, flags & ~wxCONTROL_FOCUSED, &rectThumb); + DrawBackground(dc, rectThumb, flags); + } +} + // ---------------------------------------------------------------------------- // size adjustments // ---------------------------------------------------------------------------- @@ -612,6 +824,16 @@ void wxGTKRenderer::AdjustSize(wxSize *size, const wxWindow *window) } else { + if ( wxDynamicCast(window, wxScrollBar) ) + { + // we only set the width of vert scrollbars and height of the + // horizontal ones + if ( window->GetWindowStyle() & wxSB_HORIZONTAL ) + size->y = m_sizeScrollbarArrow.y; + else + size->x = m_sizeScrollbarArrow.x; + } + // take into account the border width wxBorder border = (wxBorder)(window->GetWindowStyle() & wxBORDER_MASK); switch ( border ) @@ -752,3 +974,28 @@ wxControlActions wxGTKButtonInputHandler::Map(const wxMouseEvent& event) return wxGTKInputHandler::Map(event); } + +// ---------------------------------------------------------------------------- +// wxGTKScrollBarInputHandler +// ---------------------------------------------------------------------------- + +wxGTKScrollBarInputHandler::wxGTKScrollBarInputHandler() +{ + m_winCapture = NULL; +} + +wxControlActions wxGTKScrollBarInputHandler::Map(const wxKeyEvent& event, + bool pressed) +{ + return wxGTKInputHandler::Map(event, pressed); +} + +wxControlActions wxGTKScrollBarInputHandler::Map(const wxMouseEvent& event) +{ + if ( event.Moving() ) + { + // determin which part of the window mouse is in + } + + return wxGTKInputHandler::Map(event); +} diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index 690251bd52..64e10736c4 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -29,6 +29,8 @@ #include "wx/dc.h" #include "wx/window.h" + #include "wx/dcmemory.h" + #include "wx/button.h" #include "wx/scrolbar.h" #endif // WX_PRECOMP @@ -67,7 +69,6 @@ public: // implement the base class pure virtuals virtual void DrawBackground(wxDC& dc, - const wxColour& col, const wxRect& rect, int flags = 0); virtual void DrawLabel(wxDC& dc, @@ -105,6 +106,11 @@ public: virtual void AdjustSize(wxSize *size, const wxWindow *window); protected: + // DrawButtonBorder() helper + void DoDrawBackground(wxDC& dc, + const wxColour& col, + const wxRect& rect); + // DrawBorder() helpers: all of them shift and clip the DC after drawing // the border @@ -135,12 +141,13 @@ protected: wxArrowStyle arrowStyle); private: + const wxColourScheme *m_scheme; + // the sizing parameters (TODO make them changeable) wxSize m_sizeScrollbarArrow; // GDI objects we use for drawing wxColour m_colDarkGrey, - m_colBg, m_colHighlight; wxPen m_penBlack, @@ -314,6 +321,7 @@ wxColour wxWin32ColourScheme::Get(wxWin32ColourScheme::StdColour col, wxWin32Renderer::wxWin32Renderer(const wxColourScheme *scheme) { // init data + m_scheme = scheme; m_sizeScrollbarArrow = wxSize(16, 16); // init colours and pens @@ -322,8 +330,7 @@ wxWin32Renderer::wxWin32Renderer(const wxColourScheme *scheme) m_colDarkGrey = scheme->Get(wxColourScheme::SHADOW_OUT); m_penDarkGrey = wxPen(m_colDarkGrey, 0, wxSOLID); - m_colBg = scheme->Get(wxColourScheme::SHADOW_IN); - m_penLightGrey = wxPen(m_colBg, 0, wxSOLID); + m_penLightGrey = wxPen(scheme->Get(wxColourScheme::SHADOW_IN), 0, wxSOLID); m_colHighlight = scheme->Get(wxColourScheme::SHADOW_HIGHLIGHT); m_penHighlight = wxPen(m_colHighlight, 0, wxSOLID); @@ -805,18 +812,24 @@ void wxWin32Renderer::DrawLabel(wxDC& dc, // background // ---------------------------------------------------------------------------- -void wxWin32Renderer::DrawBackground(wxDC& dc, - const wxColour& col, - const wxRect& rect, - int flags) +void wxWin32Renderer::DoDrawBackground(wxDC& dc, + const wxColour& col, + const wxRect& rect) { - // just fill it with the current colour wxBrush brush(col, wxSOLID); dc.SetBrush(brush); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(rect); } +void wxWin32Renderer::DrawBackground(wxDC& dc, + const wxRect& rect, + int flags) +{ + // just fill it with the default bg colour + DoDrawBackground(dc, m_scheme->Get(wxColourScheme::CONTROL, flags), rect); +} + // ---------------------------------------------------------------------------- // scrollbar // ---------------------------------------------------------------------------- @@ -922,7 +935,7 @@ void wxWin32Renderer::DrawScrollbar(wxDC& dc, else rectBar.Inflate(-m_sizeScrollbarArrow.x, 0); - DrawBackground(dc, m_colHighlight, rectBar); + DoDrawBackground(dc, m_colHighlight, rectBar); // and, finally, the thumb, if any if ( thumbPosStart < thumbPosEnd ) @@ -940,7 +953,7 @@ void wxWin32Renderer::DrawScrollbar(wxDC& dc, } DrawArrowBorder(dc, &rectThumb); - DrawBackground(dc, m_colBg, rectThumb); + DrawBackground(dc, rectThumb); } }