ToggleListView.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma once
  21. #include <afxcview.h>
  22. /**
  23. * A simple list view that supports a toggle button. ToggleListView is a simple extension
  24. * to the CListView class that support a toggle button. It is limited to a single column
  25. * and always uses full row select. The toggle state is stored in the data for each item
  26. * so users of this class should not attempt to use the data field for storage. lparam can
  27. * be used instead.
  28. */
  29. class ToggleListView : public CListView {
  30. public:
  31. /**
  32. * Enumeration that defines the possible states of the toggle button.
  33. */
  34. enum {
  35. TOGGLE_STATE_DISABLED = 0,
  36. TOGGLE_STATE_ON,
  37. TOGGLE_STATE_OFF
  38. };
  39. public:
  40. void SetToggleIcons(LPCSTR disabled = NULL, LPCSTR on = NULL, LPCSTR off = NULL);
  41. void SetToggleState(int index, int toggleState, bool notify = false);
  42. int GetToggleState(int index);
  43. //Windows messages
  44. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  45. afx_msg void OnSize(UINT nType, int cx, int cy);
  46. afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  47. afx_msg void OnNMClick(NMHDR *pNMHDR, LRESULT *pResult);
  48. DECLARE_MESSAGE_MAP()
  49. protected:
  50. ToggleListView();
  51. virtual ~ToggleListView();
  52. DECLARE_DYNCREATE(ToggleListView)
  53. //Overrides
  54. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  55. virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  56. //Virtual Event Methods for sub-classes
  57. virtual void OnStateChanged(int index, int toggleState) {};
  58. void Draw3dRect(HDC hDC, RECT* rect, HBRUSH topLeft, HBRUSH bottomRight);
  59. protected:
  60. HICON onIcon;
  61. HICON offIcon;
  62. HICON disabledIcon;
  63. };