| Version: 3.2.8

Public Member Functions | List of all members
wxSystemThemedControl< C > Class Template Reference
Class List by Category » Miscellaneous Windows

`#include <wx/systhemectrl.h>`

Inheritance diagram for wxSystemThemedControl< C >:
[legend]

## Detailed Description

### template<class C>
class wxSystemThemedControl< C >

A helper class making it possible to use system theme for any control.

Under MSW, there an alternative theme available for the list and list-like controls since Windows Vista. This theme us used by Windows Explorer list and tree view and so is arguably more familiar to the users than the standard appearance of these controls.

This class is used in wxWidgets to enable this system theme in wxTreeCtrl, wxListCtrl and wxDataViewCtrl and thus give them the same, familiar look. It can also be used as a helper for implementing custom controls with the same appearance. Notice that when using this class it is especially important to use wxRendererNative::DrawItemSelectionRect() and wxRendererNative::DrawItemText() to draw the control items to ensure that they appear correctly under all platforms and Windows versions.

The following example shows implementation of a system theme enabled wxVListBox:

#include <wx/systhemectrl.h>
class MyListCtrl : public wxSystemThemedControl<wxVListBox>
{
public:
MyListCtrl(wxWindow* parent)
{
...
EnableSystemTheme();
}
void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const wxOVERRIDE
{
wxRendererNative::GetDefault().DrawItemText(this, dc, "Item #x", rect);
}
};
wxDC
A wxDC is a "device context" onto which graphics and text can be drawn.
Definition: dc.h:200
wxRect
Represents a rectangle with integer coordinates.
Definition: gdicmn.h:276
wxRendererNative::GetDefault
static wxRendererNative & GetDefault()
Return the default (native) implementation for this platform – this is also the one used by default b...
wxRendererNative::DrawItemText
virtual void DrawItemText(wxWindow *win, wxDC &dc, const wxString &text, const wxRect &rect, int align=wxALIGN_LEFT|wxALIGN_TOP, int flags=0, wxEllipsizeMode ellipsizeMode=wxELLIPSIZE_END)=0
Draw item text in the correct color based on selection status.
wxSystemThemedControl
A helper class making it possible to use system theme for any control.
Definition: systhemectrl.h:81
wxSystemThemedControl::EnableSystemTheme
void EnableSystemTheme(bool enable=true)
This method may be called to disable the system theme of controls using it by default.
wxWindow
wxWindow is the base class for all windows and represents any visible object on screen.
Definition: window.h:346
wxOVERRIDE
#define wxOVERRIDE
wxOVERRIDE expands to the C++11 override keyword if it's supported by the compiler or nothing otherwi...
Definition: defs.h:1831
systhemectrl.h

Please also note that if you want to disable the system theme use in the control that use it by default, it's best to do it before actually creating the control as enabling the system theme can't always be completely undone later. I.e. instead of

// THIS CODE IS WRONG, DO NOT DO IT LIKE THIS
wxTreeCtrl* tree = new wxTreeCtrl(parent, wxID_ANY);
tree->EnableSystemTheme(false);
wxTreeCtrl
A tree control presents information as a hierarchy, with items that may be expanded to show further i...
Definition: treectrl.h:184
wxID_ANY
@ wxID_ANY
Any id: means that we don't care about the id, whether when installing an event handler or when creat...
Definition: defs.h:597

prefer the following version:

// Use default ctor to create the object, avoiding creating the window.
wxTreeCtrl* tree = new wxTreeCtrl();
// Then disable the system theme used by default.
tree->EnableSystemTheme(false);
// And only then actually create the window.
tree->Create(parent, wxID_ANY);
wxTreeCtrl::Create
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTR_DEFAULT_STYLE, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxTreeCtrlNameStr)
Creates the tree control.

On non-MSW platforms this class currently does nothing but is still available, so that it can be used in portable code without any conditional compilation directives.

Category: Miscellaneous Windows

See also
  wxTreeCtrl, wxListCtrl, wxDataViewCtrl, wxRendererNative

Since
  3.1.0

## Public Member Functions
| wxSystemThemedControl ()
| Trivial default constructor. More...
void | EnableSystemTheme (bool enable=true)
| This method may be called to disable the system theme of controls using it by default. More...

## Constructor & Destructor Documentation

## ◆ wxSystemThemedControl()

template<class C >

wxSystemThemedControl< C >::wxSystemThemedControl | ( |  | ) |

Trivial default constructor.

## Member Function Documentation

## ◆ EnableSystemTheme()

template<class C >

void wxSystemThemedControl< C >::EnableSystemTheme | ( | bool | enable = `true` | ) |

This method may be called to disable the system theme of controls using it by default.