Team Fortress 2 Source Code as on 22/4/2020
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.

137 lines
4.5 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANORAMA_DROPDOWN_H
  6. #define PANORAMA_DROPDOWN_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panel2d.h"
  11. namespace panorama
  12. {
  13. DECLARE_PANEL_EVENT0( DropDownSelectionChanged );
  14. DECLARE_PANORAMA_EVENT2( DropDownMenuClosed, bool, CPanelPtr< CPanel2D > );
  15. class CDropDownMenu;
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Drop Down Control
  18. //-----------------------------------------------------------------------------
  19. class CDropDown : public CPanel2D
  20. {
  21. DECLARE_PANEL2D( CDropDown, CPanel2D );
  22. public:
  23. CDropDown( CPanel2D *parent, const char * pchPanelID );
  24. virtual ~CDropDown();
  25. virtual void SetupJavascriptObjectTemplate() OVERRIDE;
  26. virtual bool BSetProperty( CPanoramaSymbol symName, const char *pchValue ) OVERRIDE;
  27. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  28. void AddOption( CPanel2D *pPanel );
  29. bool HasOption( const char *pchID );
  30. void RemoveOption( const char *pchID );
  31. void RemoveAllOptions();
  32. void FindOptionIDsByClass( const char *pchClassName, CUtlVector< CUtlString > &vecIDsOut );
  33. void SortOptions( int( __cdecl *pfnCompare )(const ClientPanelPtr_t *, const ClientPanelPtr_t *) );
  34. CPanel2D *GetSelected() { return m_pSelected.Get(); }
  35. void SetSelected( const char *pchID, bool bNotify );
  36. void SetSelected( const char *pchID ) { return SetSelected( pchID, true ); }
  37. void SetDefault( const char *pchID ) { m_strDefaultSelection.Set( pchID ); }
  38. void ResetToDefault( bool bNotify );
  39. CPanel2D *AccessDropDownMenu() { return (CPanel2D*)m_pMenu.Get(); }
  40. virtual bool OnMouseButtonDown( const MouseData_t &mouseData );
  41. virtual bool OnClick( IUIPanel *pPanel, const MouseData_t &code );
  42. virtual void OnResetToDefaultValue();
  43. // Call if you know you've changed the contents of one of the option panels
  44. void InvalidateOptions( bool bForceReload );
  45. CPanel2D *FindDropDownMenuChild( const char *pchID );
  46. virtual bool BIsClientPanelEvent( CPanoramaSymbol symProperty ) OVERRIDE;
  47. #ifdef DBGFLAG_VALIDATE
  48. virtual void ValidateClientPanel( CValidator &validator, const tchar *pchName ) OVERRIDE;
  49. #endif
  50. protected:
  51. bool EventPanelActivated( const CPanelPtr< IUIPanel > &pPanel, EPanelEventSource_t eSource );
  52. bool EventDropDownMenuClosed( bool bSelectionChanged, CPanelPtr< CPanel2D > pPanel );
  53. bool EventResetToDefault( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel );
  54. virtual void OnInitializedFromLayout();
  55. void ShowMenu();
  56. void UpdateSelectedChild( bool bSuppressChangedEvent, bool bInvalidateAlways = false );
  57. virtual void OnStylesChanged() OVERRIDE;
  58. CPanelPtr< CDropDownMenu > GetMenu() { return m_pMenu; }
  59. private:
  60. CPanelPtr< CDropDownMenu >m_pMenu;
  61. CPanelPtr<CPanel2D> m_pSelected;
  62. bool m_bSuppressClick;
  63. CUtlString m_strInitialSelection;
  64. CUtlString m_strDefaultSelection;
  65. };
  66. //-----------------------------------------------------------------------------
  67. // Purpose: Drop Down Menu (shown when activated)
  68. //-----------------------------------------------------------------------------
  69. class CDropDownMenu : public CPanel2D
  70. {
  71. DECLARE_PANEL2D( CDropDownMenu, CPanel2D );
  72. public:
  73. CDropDownMenu( CDropDown *pDropDown, const char * pchPanelID );
  74. virtual ~CDropDownMenu();
  75. void Show();
  76. void Close() { Hide( false ); }
  77. CPanel2D *GetSelectedChild();
  78. void SetSelected( const char *pchID );
  79. void AddOption( CPanel2D *pPanel );
  80. bool HasOption( const char *pchID );
  81. void RemoveOption( const char *pchID );
  82. void RemoveAll();
  83. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  84. virtual void OnResetToDefaultValue();
  85. virtual IUIPanel *GetLocalizationParent() const { return m_pDropDown->UIPanel(); }
  86. #ifdef DBGFLAG_VALIDATE
  87. virtual void ValidateClientPanel( CValidator &validator, const tchar *pchName ) OVERRIDE;
  88. #endif
  89. protected:
  90. bool EventPanelActivated( const CPanelPtr< IUIPanel > &ptrPanel, EPanelEventSource_t eSource );
  91. bool EventCancelled( const CPanelPtr< IUIPanel > &pPanel, EPanelEventSource_t eSource );
  92. bool EventInputFocusTopLevelChanged( CPanelPtr< CPanel2D > ptrPanel );
  93. bool EventResetToDefault( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel );
  94. bool EventInputFocusSet( const panorama::CPanelPtr< IUIPanel > &ptrPanel );
  95. private:
  96. void Hide( bool bSelectionChanged );
  97. CDropDown *m_pDropDown;
  98. CPanel2D *m_pSelectedChild;
  99. };
  100. } // namespace panorama
  101. #endif // PANORAMA_DROPDOWN_H