TabCtrl.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #pragma once
  2. #include <afxtempl.h>
  3. #include "DPI.h"
  4. #define SHEET_CLASSNAME _T("_TabCtrlClass_")
  5. #define SHEET_CLASSTYLE (CS_DBLCLKS)
  6. // Sheet styles
  7. #define SCS_SHEET 0x0000
  8. #define SCS_TAB 0x0001
  9. #define SCS_TOP 0x0002
  10. #define SCS_BOTTOM 0x0004
  11. #define SCS_BOLD 0x0008
  12. #define SCS_BORDER 0x0010
  13. #define SN_SETACTIVETAB WM_APP + 1122
  14. typedef struct tagNMTABCHANGE{
  15. NMHDR hdr;
  16. long lOldTab;
  17. long lNewTab;
  18. long lOldItemData;
  19. long lNewItemData;
  20. } NMTABCHANGE, FAR *LPNMTABCHANGE;
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CTabCtrlEx window
  23. class CTabCtrlEx : public CWnd
  24. {
  25. // Construction
  26. public:
  27. CTabCtrlEx();
  28. public:
  29. // Overrides
  30. // ClassWizard generated virtual function overrides
  31. //{{AFX_VIRTUAL(CTabCtrlEx)
  32. public:
  33. //}}AFX_VIRTUAL
  34. // Implementation
  35. public:
  36. virtual ~CTabCtrlEx();
  37. // Create the sheet control
  38. virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  39. // Add a new window to the sheet. Returns the index of the new tab, -1 on error
  40. bool AddItem(const CString& csTabTitle, CWnd* pTabWnd);
  41. // Insert a new window in the sheet. Returns the index of the new tab, -1 on error
  42. bool InsertItem(int nTab, const CString& csTabTitle, CWnd* pTabWnd);
  43. //Replaces the window in nTab position -- Calls HideWindow for the old and ShowWindow for the new
  44. bool ReplaceItem(int nTab, const CString &csTabTitle, CWnd* pTabWnd);
  45. // Delete a tab in the sheet
  46. bool DeleteItem(int nTab);
  47. // Delete all tabs in the sheet
  48. bool DeleteAllItems();
  49. // Get/Set the tab title
  50. CString GetTabTitle(int nTab);
  51. bool SetTabTitle(int nTab, const CString& csTabTitle);
  52. // Get the active sheet
  53. int GetActiveTab();
  54. // Get the number of tabs
  55. int GetTabCount();
  56. // Set the active tab and make the tab title visible
  57. void SetActiveTab(int nTab, bool bNotify = true);
  58. bool SetTabItemData(int nTab, long lItemData);
  59. long GetTabItemData(int nTab);
  60. // Make a tab title visible
  61. void MakeTabVisible(int nTab);
  62. // Set the tab height
  63. void SetTabHeight(int nTabHeight);
  64. // Relay keyboard events for the sheet to process,
  65. // returns TRUE if the message was processed, DO NOT process this message
  66. // return FALSE if the message was not processed
  67. virtual BOOL PreTranslateMessage(MSG* pMsg);
  68. // Underline a tab title, use color -1 to remove underline
  69. void UnderlineTabTitle(int nTab, COLORREF clr);
  70. void SetFocusToNewlySelectedTab(bool bVal) { m_bSetFocusToNewlySelectedTab = bVal; }
  71. bool GetFocusToNewlySelectedTab() { return m_bSetFocusToNewlySelectedTab; }
  72. void SetTabColors(COLORREF Selected, COLORREF NonSelected) { m_SelectedColor = Selected; m_NonSelectedColor = NonSelected;}
  73. void OnDpiChanged(CWnd* pParent, int dpi);
  74. protected:
  75. class CTab
  76. {
  77. public:
  78. CTab()
  79. {
  80. lItemData = -1;
  81. }
  82. CString csTitle;
  83. CWnd* pWnd;
  84. long lWidth;
  85. COLORREF clrUnderline;
  86. long lItemData;
  87. };
  88. typedef enum {ArrowLeft, ArrowRight} ButtonStyle;
  89. typedef enum {BtnDown, BtnUp/*, BtnHover*/} ButtonState;
  90. protected:
  91. short m_nStyle;
  92. CArray <CTab, CTab&> m_Tabs;
  93. int m_nActiveTab;
  94. int m_nTabHeight;
  95. CBrush m_brSelectedTab;
  96. CBrush m_brNonSelectedTab;
  97. CPen m_penGray;
  98. CPen m_penBlack;
  99. CFont *m_pFntText, *m_pFntBoldText;
  100. ButtonState m_btnState[2];
  101. bool m_bBtnEnabled[2];
  102. int m_nLeftShifted;
  103. int m_nPrevWidth;
  104. bool m_bSetFocusToNewlySelectedTab;
  105. COLORREF m_SelectedColor;
  106. COLORREF m_NonSelectedColor;
  107. CDPI m_dpi;
  108. protected:
  109. int GetTextWidth(const CString& csText);
  110. int GetDisplayWidth();
  111. int GetTabsWidth();
  112. int GetSpinnerWidth();
  113. void GetFullRect(CRect& rcTab);
  114. void GetTabListRect(CRect& rcTab);
  115. void GetTabRect(int nTab, CRect& rcTab);
  116. void GetSpinnerRect(CRect& rcButton);
  117. void GetButtonRect(int nBtn, CRect& rcBtn);
  118. void EnableSpinners();
  119. void DrawTabs(CDC *pDC);
  120. void DrawBar(CDC* pDC);
  121. void DrawTab(int nTab, CDC *pDC, CRect& rcTab);
  122. void DrawTabEx(int nTab, CDC *pDC, CRect& rcTab);
  123. void DrawSpinner(CDC *pDC);
  124. void DrawButton(CDC *pDC, CRect& rcBtn, ButtonState btnState, ButtonStyle btnStyle, bool bEnable);
  125. void ScrollTab(CPoint point);
  126. void ActivateTab(int nTab, bool bNotify, bool bOnSize = false);
  127. void ResizeTabWindow(int nOldTab, int nNewTab, bool bNotify, bool bOnSize);
  128. void SwitchTabs(bool bNext = true);
  129. // Generated message map functions
  130. protected:
  131. //{{AFX_MSG(CTabCtrlEx)
  132. afx_msg void OnPaint();
  133. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  134. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  135. afx_msg void OnTimer(UINT_PTR nIDEvent);
  136. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  137. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  138. afx_msg void OnSize(UINT nType, int cx, int cy);
  139. afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
  140. //}}AFX_MSG
  141. DECLARE_MESSAGE_MAP()
  142. };