Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PHANDLE_H
  8. #define PHANDLE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/vgui.h>
  13. namespace vgui
  14. {
  15. class Panel;
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Safe pointer class for handling Panel or derived panel classes
  18. //-----------------------------------------------------------------------------
  19. class PHandle
  20. {
  21. public:
  22. PHandle() : m_iPanelID(INVALID_PANEL) {} //m_iSerialNumber(0), m_pListEntry(0) {}
  23. Panel *Get();
  24. Panel *Set( Panel *pPanel );
  25. Panel *Set( HPanel hPanel );
  26. operator Panel *() { return Get(); }
  27. Panel * operator ->() { return Get(); }
  28. Panel * operator = (Panel *pPanel) { return Set(pPanel); }
  29. bool operator == (Panel *pPanel) { return (Get() == pPanel); }
  30. operator bool () { return Get() != 0; }
  31. friend inline bool operator == ( const PHandle &p1, const PHandle &p2 )
  32. {
  33. return p1.m_iPanelID == p2.m_iPanelID;
  34. }
  35. private:
  36. HPanel m_iPanelID;
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Safe pointer class to just convert between VPANEL's and PHandle
  40. //-----------------------------------------------------------------------------
  41. class VPanelHandle
  42. {
  43. public:
  44. VPanelHandle() : m_iPanelID(INVALID_PANEL) {}
  45. VPANEL Get();
  46. VPANEL Set( VPANEL pPanel );
  47. operator VPANEL () { return Get(); }
  48. VPANEL operator = (VPANEL pPanel) { return Set(pPanel); }
  49. bool operator == (VPANEL pPanel) { return (Get() == pPanel); }
  50. operator bool () { return Get() != 0; }
  51. private:
  52. HPanel m_iPanelID;
  53. };
  54. //-----------------------------------------------------------------------------
  55. // Purpose: DHANDLE is a templated version of PHandle
  56. //-----------------------------------------------------------------------------
  57. template< class PanelType >
  58. class DHANDLE : public PHandle
  59. {
  60. public:
  61. PanelType *Get() { return (PanelType *)PHandle::Get(); }
  62. PanelType *Set( PanelType *pPanel ) { return (PanelType *)PHandle::Set(pPanel); }
  63. PanelType *Set( HPanel hPanel ) { return (PanelType *)PHandle::Set(hPanel); }
  64. operator PanelType *() { return (PanelType *)PHandle::Get(); }
  65. PanelType * operator ->() { return (PanelType *)PHandle::Get(); }
  66. PanelType * operator = (PanelType *pPanel) { return (PanelType *)PHandle::Set(pPanel); }
  67. bool operator == (Panel *pPanel) { return (PHandle::Get() == pPanel); }
  68. operator bool () { return PHandle::Get() != NULL; }
  69. };
  70. };
  71. #endif // PHANDLE_H