From 9b312abc75b1aba7d4e3f13d3af05e417eacf78e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 27 Jan 2026 22:43:22 +0100 Subject: [PATCH] Add wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION() This will be used in the upcoming commit. --- include/wx/rtti.h | 19 +++++++++++++++++++ interface/wx/object.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/wx/rtti.h b/include/wx/rtti.h index e6e66521bc..fa845d9d10 100644 --- a/include/wx/rtti.h +++ b/include/wx/rtti.h @@ -226,6 +226,25 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name); wxObject* name::wxCreateObject() \ { return new name; } + // Template specialization with one base class. +#define wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION(name, arg, basename) \ + template <> \ + wxObject* name::wxCreateObject() { return new name; } \ + template <> \ + wxClassInfo \ + name::ms_classInfo \ + ( \ + wxT(#name) L"<" wxT(#arg) L">", \ + &basename::ms_classInfo, \ + nullptr, \ + static_cast(sizeof(name)), \ + name::wxCreateObject \ + ); \ + template <> \ + wxClassInfo* name::GetClassInfo() const { return &ms_classInfo; } + + + // ----------------------------------- // for abstract classes // ----------------------------------- diff --git a/interface/wx/object.h b/interface/wx/object.h index 3e9f4f306e..176864d93c 100644 --- a/interface/wx/object.h +++ b/interface/wx/object.h @@ -797,6 +797,36 @@ public: */ #define wxIMPLEMENT_DYNAMIC_CLASS2( className, baseClassName1, baseClassName2 ) +/** + Used in a C++ implementation file to complete the declaration of a class + that has run-time type information, and whose instances can be created + dynamically. Use this for template specializations. + + Please note that @a arg must be the template parameter the primary template + @a templateName is being specialized for, e.g. + + @code + template + class MyWindow : public wxWindow + { + public: + MyWindow() = default; // Must have a default ctor for dynamic creation. + + private: + T m_value; + + wxDECLARE_DYNAMIC_CLASS(MyWindow); + }; + + wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION(MyWindow, int, wxWindow); + @endcode + + @header{wx/object.h} + + @since 3.3.2 +*/ +#define wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION( templateName, arg, baseClassName ) + /** Synonym for wxIMPLEMENT_ABSTRACT_CLASS().