From ebd161b6c862e72fd9e7c55b3c4b48abaf0e5319 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 15 Sep 2000 14:35:31 +0000 Subject: [PATCH] 1. added wxNcPaintEvent and generate it under GTK/use under wxUniv 2. minor fixes to wxCheck/Radio/wxCheckList/Box appearance - now seems fine git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8368 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO | 3 ++- include/wx/event.h | 10 ++++++++++ include/wx/univ/renderer.h | 3 +++ include/wx/univ/window.h | 1 + src/common/event.cpp | 1 + src/gtk/window.cpp | 8 ++++++++ src/gtk1/window.cpp | 8 ++++++++ src/univ/checkbox.cpp | 4 ++-- src/univ/checklst.cpp | 6 +++++- src/univ/themes/gtk.cpp | 14 +++++++++++++- src/univ/themes/win32.cpp | 2 ++ src/univ/winuniv.cpp | 21 ++++++++++++++++----- 12 files changed, 71 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index e3786d1d2c..41fedce633 100644 --- a/TODO +++ b/TODO @@ -7,4 +7,5 @@ MSW GTK -* check/radio box remains pressed +* check/radio box remains pressed in win32 mode +* wxCheckListBox::HitTest doesn't work (clicking the check) diff --git a/include/wx/event.h b/include/wx/event.h index aaa172a39c..912bf10e56 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -900,6 +900,15 @@ public: #endif // debug }; +class WXDLLEXPORT wxNcPaintEvent : public wxEvent +{ +public: + wxNcPaintEvent(int id = 0) : wxEvent(id) { SetEventType(wxEVT_NC_PAINT); } + +private: + DECLARE_DYNAMIC_CLASS(wxNcPaintEvent) +}; + // Erase background event class /* wxEVT_ERASE_BACKGROUND @@ -1639,6 +1648,7 @@ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ #define EVT_END_SESSION(func) { wxEVT_END_SESSION, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCloseEventFunction) & func, (wxObject *) NULL }, #define EVT_QUERY_END_SESSION(func) { wxEVT_QUERY_END_SESSION, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCloseEventFunction) & func, (wxObject *) NULL }, #define EVT_PAINT(func) { wxEVT_PAINT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxPaintEventFunction) & func, (wxObject *) NULL }, +#define EVT_NC_PAINT(func) { wxEVT_NC_PAINT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxPaintEventFunction) & func, (wxObject *) NULL }, #define EVT_ERASE_BACKGROUND(func) { wxEVT_ERASE_BACKGROUND, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxEraseEventFunction) & func, (wxObject *) NULL }, #define EVT_CHAR(func) { wxEVT_CHAR, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL }, #define EVT_KEY_DOWN(func) { wxEVT_KEY_DOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL }, diff --git a/include/wx/univ/renderer.h b/include/wx/univ/renderer.h index f97edd3dca..c66e56208d 100644 --- a/include/wx/univ/renderer.h +++ b/include/wx/univ/renderer.h @@ -223,6 +223,7 @@ public: // get the size of a checkbox/radio button bitmap virtual wxSize GetCheckBitmapSize() const = 0; virtual wxSize GetRadioBitmapSize() const = 0; + virtual wxCoord GetCheckItemMargin() const = 0; // virtual dtor for any base class virtual ~wxRenderer(); @@ -390,6 +391,8 @@ public: { return m_renderer->GetCheckBitmapSize(); } virtual wxSize GetRadioBitmapSize() const { return m_renderer->GetRadioBitmapSize(); } + virtual wxCoord GetCheckItemMargin() const + { return m_renderer->GetCheckItemMargin(); } protected: wxRenderer *m_renderer; diff --git a/include/wx/univ/window.h b/include/wx/univ/window.h index b79d873ff9..3dfbf255f9 100644 --- a/include/wx/univ/window.h +++ b/include/wx/univ/window.h @@ -170,6 +170,7 @@ protected: // event handlers void OnSize(wxSizeEvent& event); + void OnNcPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event); void OnErase(wxEraseEvent& event); diff --git a/src/common/event.cpp b/src/common/event.cpp index 161311328d..15f00632c8 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -63,6 +63,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) + IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index fc2f7fb884..631291df07 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -702,6 +702,10 @@ static int gtk_window_expose_callback( GtkWidget *widget, eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); + wxNcPaintEvent eventNc( win->GetId() ); + eventNc.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( eventNc ); + wxPaintEvent event( win->GetId() ); event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( event ); @@ -810,6 +814,10 @@ static void gtk_window_draw_callback( GtkWidget *widget, eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); + wxNcPaintEvent eventNc( win->GetId() ); + eventNc.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( eventNc ); + wxPaintEvent event( win->GetId() ); event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( event ); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index fc2f7fb884..631291df07 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -702,6 +702,10 @@ static int gtk_window_expose_callback( GtkWidget *widget, eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); + wxNcPaintEvent eventNc( win->GetId() ); + eventNc.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( eventNc ); + wxPaintEvent event( win->GetId() ); event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( event ); @@ -810,6 +814,10 @@ static void gtk_window_draw_callback( GtkWidget *widget, eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); + wxNcPaintEvent eventNc( win->GetId() ); + eventNc.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( eventNc ); + wxPaintEvent event( win->GetId() ); event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( event ); diff --git a/src/univ/checkbox.cpp b/src/univ/checkbox.cpp index 00383df386..26c8dd90ac 100644 --- a/src/univ/checkbox.cpp +++ b/src/univ/checkbox.cpp @@ -206,9 +206,9 @@ void wxCheckBox::Release() void wxCheckBox::Toggle() { - ChangeValue(!GetValue()); - m_isPressed = FALSE; + + ChangeValue(!GetValue()); } void wxCheckBox::ChangeValue(bool value) diff --git a/src/univ/checklst.cpp b/src/univ/checklst.cpp index 6570ae46bd..ee8e301e3b 100644 --- a/src/univ/checklst.cpp +++ b/src/univ/checklst.cpp @@ -217,9 +217,13 @@ bool wxStdCheckListboxInputHandler::HandleMouse(wxControl *control, const wxPoint& pt = event.GetPosition(); lbox->CalcUnscrolledPosition(pt.x, pt.y, &x, &y); + + wxRenderer *renderer = lbox->GetRenderer(); + x -= renderer->GetCheckItemMargin(); + int item = y / lbox->GetLineHeight(); if ( x >= 0 && - x < lbox->GetRenderer()->GetCheckBitmapSize().x && + x < renderer->GetCheckBitmapSize().x && item >= 0 && item < lbox->GetCount() ) { diff --git a/src/univ/themes/gtk.cpp b/src/univ/themes/gtk.cpp index 0a51f03724..d20cbbd529 100644 --- a/src/univ/themes/gtk.cpp +++ b/src/univ/themes/gtk.cpp @@ -150,6 +150,8 @@ public: { return wxSize(10, 10); } virtual wxSize GetRadioBitmapSize() const { return wxSize(11, 11); } + virtual wxCoord GetCheckItemMargin() const + { return 2; } // helpers for "wxBitmap wxColourScheme::Get()" void DrawCheckBitmap(wxDC& dc, const wxRect& rect); @@ -954,7 +956,17 @@ void wxGTKRenderer::DrawCheckItem(wxDC& dc, const wxRect& rect, int flags) { - DrawCheckButton(dc, label, bitmap, rect, flags); + wxRect rectBitmap = rect; + rectBitmap.x -= 1; + rectBitmap.width = GetCheckBitmapSize().x; + // never draw the focus rect around the check indicators here + DrawCheckButton(dc, _T(""), bitmap, rectBitmap, flags & ~wxCONTROL_FOCUSED); + + wxRect rectLabel = rect; + wxCoord shift = rectBitmap.width + 2*GetCheckItemMargin(); + rectLabel.x += shift; + rectLabel.width -= shift; + DrawItem(dc, label, rectLabel, flags); } // ---------------------------------------------------------------------------- diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index 5d85051605..7de2f70dd7 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -165,6 +165,8 @@ public: { return wxSize(13, 13); } virtual wxSize GetRadioBitmapSize() const { return wxSize(13, 13); } + virtual wxCoord GetCheckItemMargin() const + { return 0; } protected: // common part of DrawLabel() and DrawItem() diff --git a/src/univ/winuniv.cpp b/src/univ/winuniv.cpp index 28fe84c4ee..47ad891d5f 100644 --- a/src/univ/winuniv.cpp +++ b/src/univ/winuniv.cpp @@ -59,6 +59,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxWindowNative) EVT_SIZE(wxWindow::OnSize) EVT_PAINT(wxWindow::OnPaint) + EVT_NC_PAINT(wxWindow::OnNcPaint) EVT_ERASE_BACKGROUND(wxWindow::OnErase) END_EVENT_TABLE() @@ -168,7 +169,20 @@ void wxWindow::OnErase(wxEraseEvent& event) } } -// the event handler executed when the window must be repainted +// the event handlers executed when the window must be repainted +void wxWindow::OnNcPaint(wxPaintEvent& event) +{ + if ( m_renderer ) + { + // get the DC to use and create renderer on it + wxWindowDC dc(this); + wxControlRenderer renderer(this, dc, m_renderer); + + // draw the border + DoDrawBorder(&renderer); + } +} + void wxWindow::OnPaint(wxPaintEvent& event) { if ( !m_renderer ) @@ -182,10 +196,7 @@ void wxWindow::OnPaint(wxPaintEvent& event) wxPaintDC dc(this); wxControlRenderer renderer(this, dc, m_renderer); - // first, draw the border - DoDrawBorder(&renderer); - - // and then draw the control + // draw the control DoDraw(&renderer); } }