TabCtrl.h 4.6 KB

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