From f0244295e3a35a37473e9ba83d6ceea0d17259da Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 28 Jul 2003 10:59:42 +0000 Subject: [PATCH] added wxAppTraits::CreateRenderer() which may be used to customize the renderer git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22341 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/apptrait.h | 10 +++++ include/wx/renderer.h | 25 +++++++++++ include/wx/window.h | 12 ++++- src/common/appbase.cpp | 6 +++ src/common/appcmn.cpp | 6 +++ src/common/rendcmn.cpp | 87 +++++++++++++++++++++++++++++++++++++ src/generic/renderg.cpp | 11 ----- src/gtk/renderer.cpp | 2 +- src/gtk1/renderer.cpp | 2 +- src/mac/carbon/renderer.cpp | 2 +- src/mac/renderer.cpp | 2 +- src/msw/renderer.cpp | 2 +- 12 files changed, 150 insertions(+), 17 deletions(-) create mode 100644 src/common/rendcmn.cpp diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index edce5bb945..0a169af8f0 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -19,6 +19,7 @@ class WXDLLEXPORT wxAppTraits; #endif // wxUSE_FONTMAP class WXDLLEXPORT wxLog; class WXDLLEXPORT wxMessageOutput; +class WXDLLEXPORT wxRendererNative; class WXDLLEXPORT wxString; // ---------------------------------------------------------------------------- @@ -44,6 +45,13 @@ public: virtual wxFontMapper *CreateFontMapper() = 0; #endif // wxUSE_FONTMAP + // get the renderer to use for drawing the generic controls (return value + // may be NULL in which case the default renderer for the current platform + // is used); this is used in GUI only and always returns NULL in console + // + // NB: returned pointer will be deleted by the caller + virtual wxRendererNative *CreateRenderer() = 0; + // functions abstracting differences between GUI and console modes // ------------------------------------------------------------------------ @@ -123,6 +131,7 @@ public: #if wxUSE_FONTMAP virtual wxFontMapper *CreateFontMapper(); #endif // wxUSE_FONTMAP + virtual wxRendererNative *CreateRenderer(); #ifdef __WXDEBUG__ virtual bool ShowAssertDialog(const wxString& msg); @@ -149,6 +158,7 @@ public: #if wxUSE_FONTMAP virtual wxFontMapper *CreateFontMapper(); #endif // wxUSE_FONTMAP + virtual wxRendererNative *CreateRenderer(); #ifdef __WXDEBUG__ virtual bool ShowAssertDialog(const wxString& msg); diff --git a/include/wx/renderer.h b/include/wx/renderer.h index adb2076bc5..2906de378a 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -30,6 +30,13 @@ class WXDLLEXPORT wxWindow; #include "wx/gdicmn.h" // for wxPoint +// some platforms have their own renderers, others use the generic one +#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK__) + #define wxHAS_NATIVE_RENDERER +#else + #undef wxHAS_NATIVE_RENDERER +#endif + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -109,6 +116,9 @@ public: // return the generic implementation of the renderer static wxRendererNative& GetGeneric(); + + // return the default (native) implementation for this platform + static wxRendererNative& GetDefault(); }; // ---------------------------------------------------------------------------- @@ -159,5 +169,20 @@ protected: DECLARE_NO_COPY_CLASS(wxDelegateRendererNative) }; +// ---------------------------------------------------------------------------- +// inline functions implementation +// ---------------------------------------------------------------------------- + +#ifndef wxHAS_NATIVE_RENDERER + +// default native renderer is the generic one then +/* static */ inline +wxRendererNative& wxRendererNative::GetDefault() +{ + return GetGeneric(); +} + +#endif // !wxHAS_NATIVE_RENDERER + #endif // _WX_RENDERER_H_ diff --git a/include/wx/window.h b/include/wx/window.h index 2270ca10c3..596dadc0a4 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -831,7 +831,17 @@ public: wxSizer *GetSizer() const { return m_windowSizer; } // Track if this window is a member of a sizer - void SetContainingSizer(wxSizer* sizer) { m_containingSizer = sizer; } + void SetContainingSizer(wxSizer* sizer) + { + // adding a window to a sizer twice is going to result in fatal and + // hard to debug problems later because when deleting the second + // associated wxSizerItem we're going to dereference a dangling + // pointer; so try to detect this as early as possible + wxASSERT_MSG( !sizer || m_containingSizer != sizer, + _T("Adding a window to the same sizer twice?") ); + + m_containingSizer = sizer; + } wxSizer *GetContainingSizer() const { return m_containingSizer; } // accessibility diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 261fd0fa23..fddde79afd 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -506,6 +506,12 @@ wxFontMapper *wxConsoleAppTraitsBase::CreateFontMapper() #endif // wxUSE_FONTMAP +wxRendererNative *wxConsoleAppTraitsBase::CreateRenderer() +{ + // console applications don't use renderers + return NULL; +} + #ifdef __WXDEBUG__ bool wxConsoleAppTraitsBase::ShowAssertDialog(const wxString& msg) { diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index dd1636b598..3d7af86d6c 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -322,6 +322,12 @@ wxFontMapper *wxGUIAppTraitsBase::CreateFontMapper() #endif // wxUSE_FONTMAP +wxRendererNative *wxGUIAppTraitsBase::CreateRenderer() +{ + // use the default native renderer by default + return NULL; +} + #ifdef __WXDEBUG__ bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString& msg) diff --git a/src/common/rendcmn.cpp b/src/common/rendcmn.cpp new file mode 100644 index 0000000000..202ec01517 --- /dev/null +++ b/src/common/rendcmn.cpp @@ -0,0 +1,87 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: common/rendcmn.cpp +// Purpose: wxRendererNative common functions +// Author: Vadim Zeitlin +// Modified by: +// Created: 28.07.03 +// RCS-ID: $Id$ +// Copyright: (c) 2003 Vadim Zeitlin +// License: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#endif //WX_PRECOMP + +#include "wx/apptrait.h" +#include "wx/renderer.h" + +#include "wx/ptr_scpd.h" + +// ---------------------------------------------------------------------------- +// wxRendererPtr: auto pointer holding the global renderer +// ---------------------------------------------------------------------------- + +wxDECLARE_SCOPED_PTR(wxRendererNative, wxRendererPtrBase); +wxDEFINE_SCOPED_PTR(wxRendererNative, wxRendererPtrBase); + +class wxRendererPtr : public wxRendererPtrBase +{ +public: + wxRendererPtr() : wxRendererPtrBase(NULL) { m_initialized = false; } + + // return true if we have a renderer, false otherwise + bool IsOk() + { + if ( !m_initialized ) + { + // only try to create the renderer once + m_initialized = true; + + DoInit(); + } + + return get() != NULL; + } + +private: + void DoInit() + { + wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + if ( traits ) + { + // ask the traits object to create a renderer for us + reset(traits->CreateRenderer()); + } + } + + bool m_initialized; + + DECLARE_NO_COPY_CLASS(wxRendererPtr) +}; + +// ============================================================================ +// wxRendererNative implementation +// ============================================================================ + +/* static */ +wxRendererNative& wxRendererNative::Get() +{ + static wxRendererPtr s_renderer; + + return s_renderer.IsOk() ? *s_renderer.get() : GetDefault(); +} + diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 252bfccc14..15af1286b6 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -100,17 +100,6 @@ wxRendererNative& wxRendererNative::GetGeneric() return s_rendererGeneric; } -// some platforms have their own renderers -#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__) - -/* static */ -wxRendererNative& wxRendererNative::Get() -{ - return GetGeneric(); -} - -#endif // platforms using their own renderers - wxRendererGeneric::wxRendererGeneric() : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)), m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)), diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp index 8c73a876fc..dea620908f 100644 --- a/src/gtk/renderer.cpp +++ b/src/gtk/renderer.cpp @@ -76,7 +76,7 @@ public: // ============================================================================ /* static */ -wxRendererNative& wxRendererNative::Get() +wxRendererNative& wxRendererNative::GetDefault() { static wxRendererGTK s_rendererGTK; diff --git a/src/gtk1/renderer.cpp b/src/gtk1/renderer.cpp index 8c73a876fc..dea620908f 100644 --- a/src/gtk1/renderer.cpp +++ b/src/gtk1/renderer.cpp @@ -76,7 +76,7 @@ public: // ============================================================================ /* static */ -wxRendererNative& wxRendererNative::Get() +wxRendererNative& wxRendererNative::GetDefault() { static wxRendererGTK s_rendererGTK; diff --git a/src/mac/carbon/renderer.cpp b/src/mac/carbon/renderer.cpp index 734a26e74d..075dd59eb0 100644 --- a/src/mac/carbon/renderer.cpp +++ b/src/mac/carbon/renderer.cpp @@ -118,7 +118,7 @@ static const char *aqua_arrow_down_xpm[] = { // ============================================================================ /* static */ -wxRendererNative& wxRendererNative::Get() +wxRendererNative& wxRendererNative::GetDefault() { static wxRendererMac s_rendererMac; diff --git a/src/mac/renderer.cpp b/src/mac/renderer.cpp index 734a26e74d..075dd59eb0 100644 --- a/src/mac/renderer.cpp +++ b/src/mac/renderer.cpp @@ -118,7 +118,7 @@ static const char *aqua_arrow_down_xpm[] = { // ============================================================================ /* static */ -wxRendererNative& wxRendererNative::Get() +wxRendererNative& wxRendererNative::GetDefault() { static wxRendererMac s_rendererMac; diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 4c8a59db57..e71bbf356a 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -48,7 +48,7 @@ private: // ============================================================================ /* static */ -wxRendererNative& wxRendererNative::Get() +wxRendererNative& wxRendererNative::GetDefault() { static wxRendererMSW s_rendererMSW; -- 2.45.2