From eafd9d4f24e3f4f394183562b980e0f63aaa010c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 24 Nov 2000 18:59:17 +0000 Subject: [PATCH] added wxRenderer::DrawTextBorder() to deal with GTK+ text borders git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8811 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/univ/renderer.h | 24 +++++++++++++---- include/wx/univ/textctrl.h | 4 ++- include/wx/univ/window.h | 2 +- src/univ/textctrl.cpp | 17 ++++++++---- src/univ/themes/gtk.cpp | 38 +++++++++++++++++++++++---- src/univ/themes/win32.cpp | 15 +++++++++++ src/univ/winuniv.cpp | 53 ++++++++++++++++++-------------------- 7 files changed, 108 insertions(+), 45 deletions(-) diff --git a/include/wx/univ/renderer.h b/include/wx/univ/renderer.h index d7c2c34607..0f6fe71b90 100644 --- a/include/wx/univ/renderer.h +++ b/include/wx/univ/renderer.h @@ -106,6 +106,14 @@ public: int flags = 0, wxRect *rectIn = (wxRect *)NULL) = 0; + // draw text control border (I hate to have a separate method for this but + // it is needed to accomodate GTK+) + virtual void DrawTextBorder(wxDC& dc, + wxBorder border, + const wxRect& rect, + int flags = 0, + wxRect *rectIn = (wxRect *)NULL) = 0; + // draw push button border and return the rectangle left for the label virtual void DrawButtonBorder(wxDC& dc, const wxRect& rect, @@ -312,6 +320,17 @@ public: int flags = 0, wxRect *rectIn = (wxRect *)NULL) { m_renderer->DrawBorder(dc, border, rect, flags, rectIn); } + virtual void DrawTextBorder(wxDC& dc, + wxBorder border, + const wxRect& rect, + int flags = 0, + wxRect *rectIn = (wxRect *)NULL) + { m_renderer->DrawTextBorder(dc, border, rect, flags, rectIn); } + virtual void DrawButtonBorder(wxDC& dc, + const wxRect& rect, + int flags = 0, + wxRect *rectIn = (wxRect *)NULL) + { m_renderer->DrawButtonBorder(dc, rect, flags, rectIn); } virtual void DrawFrame(wxDC& dc, const wxString& label, const wxRect& rect, @@ -325,11 +344,6 @@ public: virtual void DrawVerticalLine(wxDC& dc, wxCoord x, wxCoord y1, wxCoord y2) { m_renderer->DrawVerticalLine(dc, x, y1, y2); } - virtual void DrawButtonBorder(wxDC& dc, - const wxRect& rect, - int flags = 0, - wxRect *rectIn = (wxRect *)NULL) - { m_renderer->DrawButtonBorder(dc, rect, flags, rectIn); } virtual void DrawArrow(wxDC& dc, wxDirection dir, const wxRect& rect, diff --git a/include/wx/univ/textctrl.h b/include/wx/univ/textctrl.h index 9fc66e306c..e1c2f67629 100644 --- a/include/wx/univ/textctrl.h +++ b/include/wx/univ/textctrl.h @@ -250,7 +250,7 @@ public: // override this to take into account our scrollbar-less scrolling virtual void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const; - // set the right colours + // set the right colours and border virtual bool IsContainerWindow() const { return TRUE; } virtual wxBorder GetDefaultBorder() const { return wxBORDER_SUNKEN; } @@ -271,6 +271,8 @@ protected: void DoDrawTextInRect(wxDC& dc, const wxRect& rectUpdate); + // override base class methods + virtual void DoDrawBorder(wxDC& dc, const wxRect& rect); virtual void DoDraw(wxControlRenderer *renderer); // calc the size from the text extent diff --git a/include/wx/univ/window.h b/include/wx/univ/window.h index e8e608e5cc..5f2315dfa3 100644 --- a/include/wx/univ/window.h +++ b/include/wx/univ/window.h @@ -195,7 +195,7 @@ protected: virtual bool DoDrawBackground(wxDC& dc); // draw the controls border - virtual void DoDrawBorder(wxDC& dc); + virtual void DoDrawBorder(wxDC& dc, const wxRect& rect); // draw the controls contents virtual void DoDraw(wxControlRenderer *renderer); diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index ed9563b655..c79b276cdb 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -2772,7 +2772,16 @@ void wxTextCtrl::RefreshTextRect(const wxRect& rectClient) } // ---------------------------------------------------------------------------- -// drawing +// border drawing +// ---------------------------------------------------------------------------- + +void wxTextCtrl::DoDrawBorder(wxDC& dc, const wxRect& rect) +{ + m_renderer->DrawTextBorder(dc, GetBorder(), rect, GetStateFlags()); +} + +// ---------------------------------------------------------------------------- +// client area drawing // ---------------------------------------------------------------------------- /* @@ -3622,12 +3631,10 @@ bool wxStdTextCtrlInputHandler::HandleFocus(wxControl *control, if ( event.GetEventType() == wxEVT_KILL_FOCUS ) { wxStaticCast(control, wxTextCtrl)->ClearSelection(); - - // don't refresh - return FALSE; } - return wxStdInputHandler::HandleFocus(control, event); + // refresh + return TRUE; } #endif // wxUSE_TEXTCTRL diff --git a/src/univ/themes/gtk.cpp b/src/univ/themes/gtk.cpp index 572a4be297..25e994923a 100644 --- a/src/univ/themes/gtk.cpp +++ b/src/univ/themes/gtk.cpp @@ -91,6 +91,11 @@ public: int flags = 0, int alignment = wxALIGN_LEFT, int indexAccel = -1); + virtual void DrawTextBorder(wxDC& dc, + wxBorder border, + const wxRect& rect, + int flags = 0, + wxRect *rectIn = (wxRect *)NULL); virtual void DrawButtonBorder(wxDC& dc, const wxRect& rect, int flags = 0, @@ -675,10 +680,10 @@ void wxGTKRenderer::DrawRaisedBorder(wxDC& dc, wxRect *rect) } void wxGTKRenderer::DrawBorder(wxDC& dc, - wxBorder border, - const wxRect& rectTotal, - int WXUNUSED(flags), - wxRect *rectIn) + wxBorder border, + const wxRect& rectTotal, + int flags, + wxRect *rectIn) { size_t width; @@ -773,9 +778,32 @@ bool wxGTKRenderer::AreScrollbarsInsideBorder() const } // ---------------------------------------------------------------------------- -// borders +// special borders // ---------------------------------------------------------------------------- +void wxGTKRenderer::DrawTextBorder(wxDC& dc, + wxBorder border, + const wxRect& rectOrig, + int flags, + wxRect *rectIn) +{ + wxRect rect = rectOrig; + + 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 ) + *rectIn = rect; +} + void wxGTKRenderer::DrawButtonBorder(wxDC& dc, const wxRect& rectTotal, int flags, diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index 613fe31a93..04367683bd 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -111,6 +111,11 @@ public: int flags = 0, int alignment = wxALIGN_LEFT, int indexAccel = -1); + virtual void DrawTextBorder(wxDC& dc, + wxBorder border, + const wxRect& rect, + int flags = 0, + wxRect *rectIn = (wxRect *)NULL); virtual void DrawButtonBorder(wxDC& dc, const wxRect& rect, int flags = 0, @@ -1173,6 +1178,16 @@ bool wxWin32Renderer::AreScrollbarsInsideBorder() const // borders // ---------------------------------------------------------------------------- +void wxWin32Renderer::DrawTextBorder(wxDC& dc, + wxBorder border, + const wxRect& rect, + int flags, + wxRect *rectIn) +{ + // text controls are not special under windows + return DrawBorder(dc, border, rect, flags, rectIn); +} + void wxWin32Renderer::DrawButtonBorder(wxDC& dc, const wxRect& rectTotal, int flags, diff --git a/src/univ/winuniv.cpp b/src/univ/winuniv.cpp index 7021fa3338..476bc28500 100644 --- a/src/univ/winuniv.cpp +++ b/src/univ/winuniv.cpp @@ -191,11 +191,30 @@ void wxWindow::OnNcPaint(wxPaintEvent& event) { if ( m_renderer ) { - // get the DC to use and create renderer on it - wxWindowDC dc(this); + // get the window rect + wxRect rect; + wxSize size = GetSize(); + rect.x = + rect.y = 0; + rect.width = size.x; + rect.height = size.y; - // draw the border - DoDrawBorder(dc); + // if the scrollbars are outside the border, we must adjust the rect to + // exclude them + if ( !m_renderer->AreScrollbarsInsideBorder() ) + { + wxScrollBar *scrollbar = GetScrollbar(wxVERTICAL); + if ( scrollbar ) + rect.width -= scrollbar->GetSize().x; + + scrollbar = GetScrollbar(wxHORIZONTAL); + if ( scrollbar ) + rect.height -= scrollbar->GetSize().y; + } + + // get the DC and draw the border on it + wxWindowDC dc(this); + DoDrawBorder(dc, rect); } } @@ -249,37 +268,15 @@ bool wxWindow::DoDrawBackground(wxDC& dc) return TRUE; } -void wxWindow::DoDrawBorder(wxDC& dc) +void wxWindow::DoDrawBorder(wxDC& dc, const wxRect& rect) { - // get the window rect - wxRect rect; - wxSize size = GetSize(); - rect.x = - rect.y = 0; - rect.width = size.x; - rect.height = size.y; - - // if the scrollbars are outside the border, we must adjust the rect to - // exclude them - if ( !m_renderer->AreScrollbarsInsideBorder() ) - { - wxScrollBar *scrollbar = GetScrollbar(wxVERTICAL); - if ( scrollbar ) - rect.width -= scrollbar->GetSize().x; - - scrollbar = GetScrollbar(wxHORIZONTAL); - if ( scrollbar ) - rect.height -= scrollbar->GetSize().y; - } - // draw outline unless the update region is enitrely inside it in which // case we don't need to do it #if 0 // doesn't seem to work, why? if ( wxRegion(rect).Contains(GetUpdateRegion().GetBox()) != wxInRegion ) #endif { - m_renderer->DrawBorder(dc, GetBorder(), - rect, GetStateFlags(), &rect); + m_renderer->DrawBorder(dc, GetBorder(), rect, GetStateFlags()); } }