Version: 3.3.4
Loading...
Searching...
No Matches
wxPersistentWindow< T > Class Template Reference

#include <wx/persist/window.h>

Inheritance diagram for wxPersistentWindow< T >:

Detailed Description

template<class T>
class wxPersistentWindow< T >

Base class for persistent windows.

Compared to wxPersistentObject this class does three things:

Public Types

typedef T WindowType
 The type of the associated window.

Public Member Functions

 wxPersistentWindow (WindowType *win)
 Constructor for a persistent window object.
WindowType * Get () const
virtual wxString GetName () const
 Implements the base class pure virtual method using wxWindow::GetName().
Public Member Functions inherited from wxPersistentObject
 wxPersistentObject (void *obj)
 Constructor takes the object which we're associated with.
virtual ~wxPersistentObject ()
 Trivial but virtual destructor.
void * GetObject () const
 Return the associated object.
virtual void Save () const =0
 Save the object properties.
virtual bool Restore ()=0
 Restore the object properties.
virtual wxString GetKind () const =0
 Returns the string uniquely identifying the objects supported by this adapter.

Protected Member Functions

bool SaveCoord (const wxString &name, int value) const
 Save a coordinate, i.e.
bool RestoreCoord (const wxString &name, int *value)
 Restore a coordinate saved by SaveCoord().
Protected Member Functions inherited from wxPersistentObject
template<typename T>
bool SaveValue (const wxString &name, T value) const
 Save the specified value using the given name.
template<typename T>
bool RestoreValue (const wxString &name, T *value)
 Restore a value saved by SaveValue().

Member Typedef Documentation

◆ WindowType

template<class T>
typedef T wxPersistentWindow< T >::WindowType

The type of the associated window.

Constructor & Destructor Documentation

◆ wxPersistentWindow()

template<class T>
wxPersistentWindow< T >::wxPersistentWindow ( WindowType * win)

Constructor for a persistent window object.

The constructor uses wxEvtHandler::Bind() to catch wxWindowDestroyEvent generated when the window is destroyed and call wxPersistenceManager::SaveAndUnregister() when this happens. This ensures that the window properties are saved and that this object itself is deleted when the window is.

Member Function Documentation

◆ Get()

template<class T>
WindowType * wxPersistentWindow< T >::Get ( ) const
inline

◆ GetName()

template<class T>
virtual wxString wxPersistentWindow< T >::GetName ( ) const
virtual

Implements the base class pure virtual method using wxWindow::GetName().

Notice that window names are usually not unique while this function must return a unique (at least among the objects of this type) string. Because of this you need to specify a non-default window name in its constructor when creating it or explicitly call wxWindow::SetName() before saving or restoring persistent properties.

Implements wxPersistentObject.

◆ RestoreCoord()

template<class T>
bool wxPersistentWindow< T >::RestoreCoord ( const wxString & name,
int * value )
protected

Restore a coordinate saved by SaveCoord().

If the DPI in which the coordinate is expressed is different from the DPI at which it had been saved, it is rescaled accordingly. If the latter is unknown, e.g. because the value was saved by a version of wxWidgets older than 3.3.4, the coordinate is restored unchanged.

As explained in SaveCoord() documentation, no DPI is stored under the platforms using DPI-independent pixels, so this function simply behaves as wxPersistentObject::RestoreValue() there.

Parameters
nameThe same name as was used by SaveCoord().
valueNon-nullptr pointer to the variable to fill with the saved value if it was read successfully, which is not modified otherwise.
Returns
true if the value was successfully read or false if it was not found or an error occurred.
Since
3.3.4

◆ SaveCoord()

template<class T>
bool wxPersistentWindow< T >::SaveCoord ( const wxString & name,
int value ) const
protected

Save a coordinate, i.e.

either a position or a size, in pixels.

This function must be used instead of wxPersistentObject::SaveValue() for the values representing a size or a position in pixels, as it also stores the DPI in which the coordinate is expressed, allowing RestoreCoord() to rescale it if the DPI changes when the coordinate is restored later.

Note that under the platforms using DPI-independent pixels, such as wxGTK and wxOSX, the saved values don't change with the DPI and so no DPI is stored for them at all, meaning that they are never rescaled.

Also note that the values which are not really expressed in pixels, such as the special value -1 often used to indicate the absence of a value, are not affected by the rescaling and can be saved using this function too.

Parameters
nameThe name of the value in the configuration file.
valueThe value to save.
Returns
true if the value was saved or false if an error occurred.
Since
3.3.4