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
This commit is contained in:
parent
029b47ad2c
commit
f0244295e3
@ -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);
|
||||
|
@ -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_
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
87
src/common/rendcmn.cpp
Normal file
87
src/common/rendcmn.cpp
Normal file
@ -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 <vadim@wxwindows.org>
|
||||
// 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();
|
||||
}
|
||||
|
@ -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)),
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxRendererNative& wxRendererNative::Get()
|
||||
wxRendererNative& wxRendererNative::GetDefault()
|
||||
{
|
||||
static wxRendererGTK s_rendererGTK;
|
||||
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxRendererNative& wxRendererNative::Get()
|
||||
wxRendererNative& wxRendererNative::GetDefault()
|
||||
{
|
||||
static wxRendererGTK s_rendererGTK;
|
||||
|
||||
|
@ -118,7 +118,7 @@ static const char *aqua_arrow_down_xpm[] = {
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxRendererNative& wxRendererNative::Get()
|
||||
wxRendererNative& wxRendererNative::GetDefault()
|
||||
{
|
||||
static wxRendererMac s_rendererMac;
|
||||
|
||||
|
@ -118,7 +118,7 @@ static const char *aqua_arrow_down_xpm[] = {
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxRendererNative& wxRendererNative::Get()
|
||||
wxRendererNative& wxRendererNative::GetDefault()
|
||||
{
|
||||
static wxRendererMac s_rendererMac;
|
||||
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxRendererNative& wxRendererNative::Get()
|
||||
wxRendererNative& wxRendererNative::GetDefault()
|
||||
{
|
||||
static wxRendererMSW s_rendererMSW;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user