Restore compatibility with 3.0-like DrawCaptionSelectionRect()

This function was not called any longer after 35a8d0f908 (Fix building
wxPropertyGrid with v3.0 compatibility enabled, 2023-03-22), which
silently broke any applications resulting on this to happen, so call it
again, even if it's rather painful and ugly to do.

Also add wxDEPRECATED_BUT_USED_INTERNALLY_MSG() and use it instead of the
plain wxDEPRECATED_MSG() for the deprecated overload of this function to
avoid warnings when calling it from wxWidgets itself.

Finally, document the change to DrawCaptionSelectionRect() as this
wasn't done back in c63b1604b3 (Use native renderer to draw rectangle
indicating that wxPG category property is selected., 2015-08-30) when
its signature was changed.
This commit is contained in:
Vadim Zeitlin 2023-03-22 14:53:22 +01:00
parent 23ccdb23c8
commit cb03ddf63f
4 changed files with 57 additions and 8 deletions

View file

@ -73,6 +73,10 @@ Changes in behaviour not resulting in compilation errors
available. If any locale using the given language is acceptable, the region
must be left empty, e.g. just "fr" would use any available "fr_XX".
- Deprecated wxPGCellRenderer::DrawCaptionSelectionRect() overload is not
called any longer by default, you need to explicitly enable 3.0 compatibility
or change your code to override the newer overload, taking a wxWindow pointer.
Changes in behaviour which may result in build errors
-----------------------------------------------------

View file

@ -565,14 +565,16 @@ typedef short int WXTYPE;
#define wxDEPRECATED_ACCESSOR(func, what) wxDEPRECATED_INLINE(func, return what;)
/*
Special variant of the macro above which should be used for the functions
Special variant of the macros above which should be used for the functions
which are deprecated but called by wx itself: this often happens with
deprecated virtual functions which are called by the library.
*/
#ifdef WXBUILDING
# define wxDEPRECATED_BUT_USED_INTERNALLY(x) x
# define wxDEPRECATED_BUT_USED_INTERNALLY_MSG(x)
#else
# define wxDEPRECATED_BUT_USED_INTERNALLY(x) wxDEPRECATED(x)
# define wxDEPRECATED_BUT_USED_INTERNALLY_MSG(x) wxDEPRECATED_MSG(x)
#endif
/*

View file

@ -101,13 +101,10 @@ public:
// Paints property category selection rectangle.
#if WXWIN_COMPATIBILITY_3_0
wxDEPRECATED_MSG("Use DrawCaptionSelectionRect(wxWindow*, wxDC&, ...) instead")
wxDEPRECATED_BUT_USED_INTERNALLY_MSG("Use DrawCaptionSelectionRect(wxWindow*, wxDC&, ...) instead")
virtual void DrawCaptionSelectionRect( wxDC& dc,
int x, int y,
int w, int h ) const
{
DrawCaptionSelectionRect(nullptr, dc, x, y, w, h);
}
int w, int h ) const;
#endif // WXWIN_COMPATIBILITY_3_0
virtual void DrawCaptionSelectionRect(wxWindow *win, wxDC& dc,
int x, int y, int w, int h) const;

View file

@ -98,6 +98,31 @@ void wxPGCellRenderer::DrawEditorValue( wxDC& dc, const wxRect& rect,
}
}
#if WXWIN_COMPATIBILITY_3_0
// This is ugly, but we need to know whether our version of this function was
// called or not, so we set this global variable to true before calling it and
// then reset it to false if the base class version was used.
//
// To make things even worse, we also use this variable to check if we're
// called from our own code (in which case we just need to reset it) or from
// the application (in which case we actually need to draw something).
namespace
{
bool wxPGCellRendererDrawCaptionSelectionRectFlag = false;
}
void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC& dc,
int x, int y,
int w, int h ) const
{
if ( wxPGCellRendererDrawCaptionSelectionRectFlag )
wxPGCellRendererDrawCaptionSelectionRectFlag = false;
else
wxPGDrawFocusRect(nullptr, dc, x, y, w, h);
}
#endif // WXWIN_COMPATIBILITY_3_0
void wxPGCellRenderer::DrawCaptionSelectionRect(wxWindow* win, wxDC& dc,
int x, int y, int w, int h) const
{
@ -297,13 +322,34 @@ bool wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
imageOffset += wxCC_CUSTOM_IMAGE_MARGIN2 + 4;
}
DrawCaptionSelectionRect( const_cast<wxPropertyGrid*>(propertyGrid), dc,
rect.x+wxPG_XBEFORETEXT-wxPG_CAPRECTXMARGIN+imageOffset,
const wxRect rectCaption( rect.x+wxPG_XBEFORETEXT-wxPG_CAPRECTXMARGIN+imageOffset,
rect.y-wxPG_CAPRECTYMARGIN+1,
((wxPropertyCategory*)property)->GetTextExtent(propertyGrid,
propertyGrid->GetCaptionFont())
+(wxPG_CAPRECTXMARGIN*2),
propertyGrid->GetFontHeight()+(wxPG_CAPRECTYMARGIN*2) );
#if WXWIN_COMPATIBILITY_3_0
wxPGCellRendererDrawCaptionSelectionRectFlag = true;
DrawCaptionSelectionRect( dc,
rectCaption.x, rectCaption.y,
rectCaption.width, rectCaption.height );
if ( wxPGCellRendererDrawCaptionSelectionRectFlag )
{
// This means that the user-defined overridden version of the
// function was called -- because the base class one was not.
// So just reset the flag and don't do anything else.
wxPGCellRendererDrawCaptionSelectionRectFlag = false;
}
else
// This means that our own version was called, so we now need
// to call the other overload, to use the user-defined version
// if any or to just draw the rectangle in the base class
// version otherwise.
#endif // WXWIN_COMPATIBILITY_3_0
DrawCaptionSelectionRect( const_cast<wxPropertyGrid*>(propertyGrid), dc,
rectCaption.x, rectCaption.y,
rectCaption.width, rectCaption.height );
}
}