From cb03ddf63f22a18e3a41946d7e4681e534448d77 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 14:53:22 +0100 Subject: [PATCH 1/3] 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. --- docs/changes.txt | 4 +++ include/wx/defs.h | 4 ++- include/wx/propgrid/property.h | 7 ++--- src/propgrid/property.cpp | 50 ++++++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 508e0bc99a..6c4a7709da 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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 ----------------------------------------------------- diff --git a/include/wx/defs.h b/include/wx/defs.h index 488c8f70f9..84037e9938 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -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 /* diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 57b9294335..d5af94601b 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -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; diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 08b2231c66..1a3c18d5ed 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -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(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(propertyGrid), dc, + rectCaption.x, rectCaption.y, + rectCaption.width, rectCaption.height ); } } From eb7257193e632028d70b3e4602fc123ea24cd980 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 15:09:53 +0100 Subject: [PATCH 2/3] Simplify the use of wxPG_DEPRECATED_MACRO_VALUE Move the check for WXBUILDING, needed to avoid the warnings in props.cpp about the use of wxPG_DIR_DIALOG_MESSAGE and wxPG_FILE_DIALOG_TITLE when WXWIN_COMPATIBILITY_3_0==1, inside wxPG_DEPRECATED_MACRO_VALUE itself instead of doing it in both places where this macro was used. --- include/wx/propgrid/property.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index d5af94601b..664b07c094 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -422,7 +422,11 @@ constexpr wxPGPropertyFlags wxPG_PROP_MAX = wxPG_PROP_AUTO_UNSPECIFIED; // ----------------------------------------------------------------------- // Helpers to mark macros as deprecated -#if (defined(__clang__) || defined(__GNUC__)) +// +// Note that we don't do it when building wx itself if 3.0 compatibility is on, +// as these macros are still used in our own code in this case. +#if (defined(__clang__) || defined(__GNUC__)) && \ + (!defined(WXBUILDING) || !WXWIN_COMPATIBILITY_3_0) #define wxPG_STRINGIFY(X) #X #define wxPG_DEPRECATED_MACRO_VALUE(value, msg) \ _Pragma(wxPG_STRINGIFY(GCC warning msg)) value @@ -522,9 +526,6 @@ constexpr wxPGPropertyFlags wxPG_PROP_MAX = wxPG_PROP_AUTO_UNSPECIFIED; #define wxPG_FILE_INITIAL_PATH wxS("InitialPath") #if WXWIN_COMPATIBILITY_3_0 -#ifdef WXBUILDING -#define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle") -#else #ifdef wxPG_MUST_DEPRECATE_MACRO_NAME #pragma deprecated(wxPG_FILE_DIALOG_TITLE) #endif @@ -532,7 +533,6 @@ constexpr wxPGPropertyFlags wxPG_PROP_MAX = wxPG_PROP_AUTO_UNSPECIFIED; // Sets a specific title for the dir dialog. #define wxPG_FILE_DIALOG_TITLE wxPG_DEPRECATED_MACRO_VALUE(wxS("DialogTitle"),\ "wxPG_FILE_DIALOG_TITLE is deprecated. Use wxPG_DIALOG_TITLE instead.") -#endif // WXBUILDING/!WXBUILDING #endif // WXWIN_COMPATIBILITY_3_0 // Specific to wxFileProperty and derivatives, long, default is 0. @@ -540,9 +540,6 @@ constexpr wxPGPropertyFlags wxPG_PROP_MAX = wxPG_PROP_AUTO_UNSPECIFIED; #define wxPG_FILE_DIALOG_STYLE wxS("DialogStyle") #if WXWIN_COMPATIBILITY_3_0 -#ifdef WXBUILDING -#define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage") -#else #ifdef wxPG_MUST_DEPRECATE_MACRO_NAME #pragma deprecated(wxPG_DIR_DIALOG_MESSAGE) #endif @@ -550,7 +547,6 @@ constexpr wxPGPropertyFlags wxPG_PROP_MAX = wxPG_PROP_AUTO_UNSPECIFIED; // Sets a specific message for the dir dialog. #define wxPG_DIR_DIALOG_MESSAGE wxPG_DEPRECATED_MACRO_VALUE(wxS("DialogMessage"),\ "wxPG_DIR_DIALOG_MESSAGE is deprecated. Use wxPG_DIALOG_TITLE instead.") -#endif // WXBUILDING/!WXBUILDING #endif // WXWIN_COMPATIBILITY_3_0 // wxArrayStringProperty's string delimiter character. If this is From 650aeb7466284423a910cfa5bdda0f654bebe2b3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 12:22:30 +0100 Subject: [PATCH 3/3] Update options used in CI builds for testing compatibility Testing disabling 3.0 compatibility is useless as it's disabled by default in master, so disable 3.2 compatibility instead. Also enable 3.0 compatibility for one of the builds to check that doing this still works too. --- .github/workflows/ci.yml | 4 ++-- .github/workflows/ci_msw_cross.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 962899a759..c0823556c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,7 +95,7 @@ jobs: - name: Ubuntu 18.04 wxGTK 3 STL runner: ubuntu-latest container: ubuntu:18.04 - configure_flags: --enable-stl --disable-compat30 + configure_flags: --enable-stl --enable-compat30 use_xvfb: true - name: Ubuntu 20.04 wxGTK 3 with clang runner: ubuntu-20.04 @@ -104,7 +104,7 @@ jobs: use_xvfb: true - name: Ubuntu 22.04 wxGTK with ASAN runner: ubuntu-22.04 - configure_flags: --disable-compat30 --disable-sys-libs --disable-webview + configure_flags: --disable-compat32 --disable-sys-libs --disable-webview skip_samples: true use_asan: true use_xvfb: true diff --git a/.github/workflows/ci_msw_cross.yml b/.github/workflows/ci_msw_cross.yml index 0f9fbaa602..8a85e33271 100644 --- a/.github/workflows/ci_msw_cross.yml +++ b/.github/workflows/ci_msw_cross.yml @@ -73,7 +73,7 @@ jobs: matrix: include: - name: wxMSW 64 bits - configure_flags: --enable-stl --disable-compat30 + configure_flags: --enable-stl --disable-compat32 - name: wxMSW 32 bits triplet: i686-w64-mingw32 env: