window.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/persist/window.h
  3. // Purpose: interface of wxPersistentWindow<>
  4. // Author: Vadim Zeitlin
  5. // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. /**
  9. Base class for persistent windows.
  10. Compared to wxPersistentObject this class does three things:
  11. - Most importantly, wxPersistentWindow catches wxWindowDestroyEvent
  12. generated when the window is destroyed and saves its properties
  13. automatically when it happens.
  14. - It implements GetName() using wxWindow::GetName() so that the derived
  15. classes don't need to do it.
  16. - It adds a convenient wxPersistentWindow::Get() accessor returning the
  17. window object of the correct type.
  18. */
  19. template <class T>
  20. class wxPersistentWindow : public wxPersistentObject
  21. {
  22. public:
  23. /// The type of the associated window.
  24. typedef T WindowType;
  25. /**
  26. Constructor for a persistent window object.
  27. The constructor uses wxEvtHandler::Connect() to catch
  28. wxWindowDestroyEvent generated when the window is destroyed and call
  29. wxPersistenceManager::SaveAndUnregister() when this happens. This
  30. ensures that the window properties are saved and that this object
  31. itself is deleted when the window is.
  32. */
  33. wxPersistentWindow(WindowType *win);
  34. WindowType *Get() const { return static_cast<WindowType *>(GetWindow()); }
  35. /**
  36. Implements the base class pure virtual method using wxWindow::GetName().
  37. Notice that window names are usually not unique while this function
  38. must return a unique (at least among the objects of this type) string.
  39. Because of this you need to specify a non-default window name in its
  40. constructor when creating it or explicitly call wxWindow::SetName()
  41. before saving or restoring persistent properties.
  42. */
  43. virtual wxString GetName() const;
  44. };