www.pudn.com > TabBar.rar > TabBarCtrl.h
// tabbarctrl.h : interface of the CTabBarCtrl class.
#if !defined(AFX_TABBARCTRL_H_INCLUDED_)
#define AFX_TABBARCTRL_H_INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "afxcoll.h"
#include "resource.h"
#define WM_TABBARCTRL_NOTIFY WM_USER + 1
#define NM_TB_FOLDERCHANGE 1
#define NM_TB_FOLDERSCROLLBEGIN 2
#define NM_TB_FOLDERSCROLLEND 3
#define NM_TB_ITEMCHANGE 4
#define NM_TB_ADDFOLDER 5
#define NM_TB_INSERTITEM 6
#define NM_TB_REMOVEFOLDER 7
#define NM_TB_REMOVEITEM 8
#define NM_TB_ONFOLDER 9
#define NM_TB_ONITEM 10
#define NM_TB_RESETALLITEMS 11
#define NM_TB_DRAGITEMBEGIN 12
#define NM_TB_DRAGITEMEND 13
#define NM_TB_ITEMMOVE 14
#define NM_TB_DBLCLKITEM 15
#define NM_TB_FOLDERENDEDIT 16
#define TABBARCTRL_BLOCKTRACKER_BORDERWIDTH 3
#define TABBARCTRL_BLOCKTRACKER_DELAYTIME 500
#define TABBARCTRL_FOLDERFRONTCOLOR GetSysColor(COLOR_3DFACE)
#define TABBARCTRL_FOLDERBACKGROUNDCOLOR GetSysColor(COLOR_BTNSHADOW)
#define TABBARCTRL_FOLDERLIGHTBORDER GetSysColor(COLOR_BTNHILIGHT)
#define TABBARCTRL_FOLDERSHADOWBORDER GetSysColor(COLOR_BTNSHADOW)
#define TABBARCTRL_FOLDERTEXTCOLOR GetSysColor(COLOR_WINDOWTEXT)
#define TABBARCTRL_ITEMTEXTCOLOR GetSysColor(COLOR_WINDOWTEXT)
#define TABBARCTRL_ITEMHILIGHTCOLOR GetSysColor(COLOR_BTNHILIGHT)
#define TABBARCTRL_ITEMSHADOWCOLOR GetSysColor(COLOR_BTNSHADOW)
#define TABBARCTRL_CHILDBACKGROUNDCOLOR GetSysColor(COLOR_BTNFACE)
#define TABBARCTRL_ITEMHIGHLIGHTCOLOR GetSysColor(COLOR_BTNFACE)
#define TABBARCTRL_FOLDERHIGHLIGHTCOLOR RGB(220, 220, 220)
#define TABBARCTRL_ITEMSELECTEDCOLOR RGB(220, 220, 220)
#define TABBARCTRL_ITEMHORZSPACE 10
#define TABBARCTRL_ITEMVERTSPACE 10
#define TABBARCTRL_FOLDERHEIGHT 22
#define TABBARCTRL_FOLDERBORDERWIDTH 1
#define TABBARCTRL_FOLDERSCROLLSTEP 20
#define TABBARCTRL_ANIMATIONTICKCOUNT 20
#define TABBARCTRL_ITEMBORDERWIDTH 1
#define TABBARCTRL_DELAYTIME 100
/////////////////////////////////////////////////////////////////////////////
// class CItemTracker
class CItemTracker : public CRectTracker
{
// Construction\Destruction
public:
CItemTracker();
virtual ~CItemTracker();
// Attributes
public:
CRect m_FirstRect; // first set rectangle
// Operations
public:
BOOL Track(CWnd* pWnd, CPoint Point, BOOL bAllowInvert = FALSE, CWnd* pWndClipTo = NULL);
protected:
BOOL TrackHandle(int nHandle, CWnd* pWnd, CPoint Point, CWnd* pWndClipTo);
// Overrides
//{{AFX_VIRTUAL(CItemTracker)
public:
virtual void OnChangedRect(const CRect& OldRect);
//}}AFX_VIRTUAL
};
/////////////////////////////////////////////////////////////////////////////
// class CFolderAddDlg
class CFolderAddDlg : public CDialog
{
// Construction
public:
CFolderAddDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CFolderAddDlg)
enum { IDD = IDD_TABBARCTRL };
CString m_AddFolderName;
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
//{{AFX_VIRTUAL(CFolderAddDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL
// Generated message map functions
//{{AFX_MSG(CFolderAddDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// class CFolderEdit
class CFolderEdit : public CEdit
{
// Construction\Destruction
public:
CFolderEdit();
virtual ~CFolderEdit();
// Attributes
public:
CString m_EditString;
int m_nIndex;
protected:
BOOL m_bEscapeKeyPressed;
// Overrides
//{{AFX_VIRTUAL(CFolderEdit)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
// Generated message map functions
protected:
//{{AFX_MSG(CFolderEdit)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnKillFocus(CWnd* pNewWnd);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// CTabBarCtrl class
class CTabBarCtrl : public CWnd
{
DECLARE_DYNCREATE(CTabBarCtrl)
// outbarctrl hittest
enum
{
htNothing = -1,
htFolder,
htItem,
htUpScroll,
htDownScroll
};
// outbarctrl item class
public:
class CTabBarItem
{
// Construction\Destruction
public:
CTabBarItem(CString ItemString, int nImageIndex, DWORD dwExData);
virtual ~CTabBarItem() {};
// Attributes
public:
int m_nImageIndex; // outbarctrl item used image
CString m_ItemString; // outbarctrl item text
DWORD m_dwExData; // outbarctrl item extend data
BOOL m_bSelected; // outbarctrl item selected flag
BOOL m_bHighted; // outbarctrl item highted flag
};
// outbarctrl folder item class
class CTabBarFolder
{
// Construction\Destruction
public:
CTabBarFolder(CString FolderString, DWORD dwExData);
virtual ~CTabBarFolder();
// Attributes
public:
CString m_FolderString; // outbarctrl folder item text
DWORD m_dwExData; // outbarctrl folder item extend data
CPtrArray m_ItemList; // outbarctrl folder item list
CWnd* m_pChildWnd; // outbarctrl folder item child window
BOOL m_bHighted; // outbarctrl folder highted flag
// Operations
public:
int GetItemCount() const;
int InsertItem(int nItemInsertIndex, CString ItemString, int nItemImage, DWORD dwExData);
};
// Construction\Destruction
public:
CTabBarCtrl();
virtual ~CTabBarCtrl();
// Attributes
protected:
BOOL m_bCreateToolTip; // the tool tip window create flag
BOOL m_bToolTip; // the tool tip window show flag
CImageList* m_pImageList; // item small image list
COLORREF m_FolderBackGroundColor; // the folder background color
COLORREF m_FolderFrontColor; // the folder frontground color
COLORREF m_ChildBackGroundColor; // the child window background color
COLORREF m_FolderLightColor; // the folder normal light color
COLORREF m_FolderShadowColor; // the folder shadow color
COLORREF m_FolderTextColor; // the folder text color
COLORREF m_ItemTextColor; // the item text color
COLORREF m_ItemLightColor; // the item normal light color
COLORREF m_ItemShadowColor; // the item shadow color
COLORREF m_ItemHighlightColor; // the item normal highlight color
COLORREF m_ItemSelectedColor; // the item selected color
COLORREF m_FolderHighlightColor; // the folder highlight color
CPtrArray m_FolderList; // outbarctrl folder item list
CWnd m_ToolTip; // the tool tip window
HCURSOR m_hHandCursor; // hand cursor
int m_nRButtonHitItemIndex; // record the mouse right button hit item index
int m_nRButtonHitFolderIndex; // record the mouse right button hit folder index
int m_nItemBorderWidth; // the item border width
int m_nFolderBorderWidth; // the folder border width
int m_nSelFolder; // the current selected folder index
int m_nFolderHeight; // the folder height
int m_nHorzSpace; // items horizontal space
int m_nVertSpace; // items vertical space
int m_nDelayTime; // the item tool tip delay time
long m_lAnimationTickCount; // the folder animation timer
// Operations
protected:
void AnimateFolderScroll(int nFromFolder, int nToFolder); // folder scroll animation when the folder move a new position
BOOL CreateToolTip(); // create the tool tip
BOOL DragItem(CPoint Point, int nItemIndex); // drag the item from the folder to another folder
CMenu* GetMenu(); // get the tabbar control menu
BOOL HideToolTip(); // hide the tool tip
void HighlightFolder(int nFolderIndex); // highlight the folder
void HighlightItem(int nItemIndex); // highlight the item
void OnStartFolderEdit(int nFolderIndex); // start the folder edit
void SelectItem(int nItemIndex); // select the item
BOOL ShowToolTip(int nItemIndex); // show the tool tip
public:
void EnableToolTip(BOOL bToolTip) {m_bToolTip = bToolTip;}; // enable the tool tip
long GetAnimationTickCount() {return m_lAnimationTickCount;}; // get the folder animation tick count
CWnd* GetFolderChild(int nFolderIndex) const; // get the folder child window pointer
const int GetFolderCount() {return m_FolderList.GetSize();}; // get the folder count
DWORD GetFolderData(int nFolderIndex) const; // get the specified folder extend data
void GetFolderRect(CRect& FolderRect, int nFolderIndex); // get the specified folder rectangle
CString GetFolderText(int nFolderIndex) const; // get the specified folder text
int GetHightedFolder() const; // get the highted folder
int GetHightedItem(int nFolderIndex) const; // get the highted item in the specified folder
const CImageList* GetImageList() {return m_pImageList;}; // get the images
void GetInsideRect(CRect& ChildRect); // get the current child window rectangle
int GetItemCount(int nFolderIndex) const; // get the items count in the specified folder
DWORD GetItemData(int nItemIndex, int nFolderIndex) const; // get the specified item extend data in the specified folder
int GetItemImage(int nItemIndex, int nFolderIndex) const; // get the specified item image index in the specified folder
BOOL GetItemRect(CRect& ItemRect, int nItemIndex, int nFolderIndex); // get the specified item rectangle in the specified folder
CSize GetItemSize(int nItemIndex, int nFolderIndex) const; // get the specified item size in the specified folder
CString GetItemText(int nItemIndex, int nFolderIndex) const; // get the specified item text in the specified folder
const int GetSelelectedFolder() {return m_nSelFolder;}; // get the current selected folder index
int GetSelectedItem(int nFolderIndex) const; // get the selected item in the specified folder
void ResetAllHightedItems(int nFolderIndex); // reset all highted items in the specified folder
void ResetAllSelectedItems(int nFolderIndex); // reset all selected items in the specified folder
void SetAnimationTickCount(long value) {m_lAnimationTickCount = value;}; // set the folder animation tick count
void SetFolderText(int nFolderIndex, CString TextString); // set the folder text
CImageList* SetImageList(CImageList* pImageList); // set the images
void SetItemData(int nItemIndex, int nFolderIndex, DWORD dwData); // set the specified item data in the specified folder
void SetItemImage(int nItemIndex, int nFolderIndex, int nImageIndex); // set the specified item image index in the specified folder
void SetItemText(int nItemIndex, int nFolderIndex, CString TextString); // set the specified item text in the specified folder
void SetSelectedFolder(int nFolderIndex); // set the current selected folder
void SetSelectedItem(int nItemIndex, int nFolderIndex); // set the selected item in the specified folder
// Overrides
//{{AFX_VIRTUAL(CTabBarCtrl)
public:
virtual int AddFolder(CString FolderName, DWORD dwExData = 0);
virtual int AddFolderBar(CString FolderName, CWnd* pChildWnd, DWORD dwExData = 0);
virtual BOOL Create(DWORD dwStyle, CRect Rect, CWnd* pParentWnd, UINT nID);
virtual BOOL CreateEx(DWORD dwExStyle, DWORD dwStyle, CRect Rect, CWnd* pParentWnd, UINT nID);
virtual int HitTestEx(CPoint Point, int& nIndex);
virtual int InsertItem(int nFolderIndex, int nItemIndex, CString ItemName, int nImageIndex = -1, DWORD dwExData = 0);
virtual void RemoveFolder(int nFolderIndex);
virtual void RemoveItem(int nItemIndex, int nFolderIndex);
protected:
virtual void DrawFolder(CDC* pDrawDC, int nFolderIndex, CRect FolderRect);
virtual void DrawItem(CDC* pDrawDC, int nFolderIndex, CRect ItemRect, int nItemIndex);
virtual void PaintItems(CDC* pDrawDC, int nFolder, CRect Rect);
//}}AFX_VIRTUAL
// Diagnostics
protected:
virtual void AssertFolderIndex(int nFolderIndex) const;
virtual void AssertItemIndex(int nItemIndex, int nFolderIndex) const;
// Generated message map functions
protected:
//{{AFX_MSG(CTabBarCtrl)
afx_msg void OnAddFolder();
afx_msg void OnContextMenu(CWnd* pWnd, CPoint Point);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg long OnEndFolderEdit(WPARAM wParam, LPARAM lParam);
afx_msg BOOL OnEraseBkgnd(CDC* pDrawDC);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint Point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint Point);
afx_msg void OnMouseMove(UINT nFlags, CPoint Point);
afx_msg void OnPaint();
afx_msg void OnRemoveItem();
afx_msg void OnRenameItem();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
inline CTabBarCtrl::CTabBarItem::CTabBarItem(CString ItemString, int nImageIndex, DWORD dwExData)
{
ASSERT(!ItemString.IsEmpty());
m_ItemString = ItemString;
m_nImageIndex = nImageIndex;
m_dwExData = dwExData;
m_bSelected = FALSE;
m_bHighted = FALSE;
}
inline CTabBarCtrl::CTabBarFolder::CTabBarFolder(CString FolderString, DWORD dwExData)
{
m_FolderString = FolderString;
m_dwExData = dwExData;
m_pChildWnd = NULL;
m_bHighted = FALSE;
}
inline CTabBarCtrl::CTabBarFolder::~CTabBarFolder()
{
for(int i = 0; i < m_ItemList.GetSize(); i++)
{
if(m_ItemList.GetAt(i))
delete (CTabBarFolder*)m_ItemList.GetAt(i);
}
m_ItemList.RemoveAll();
}
inline int CTabBarCtrl::CTabBarFolder::GetItemCount() const
{
return m_ItemList.GetSize();
}
inline int CTabBarCtrl::CTabBarFolder::InsertItem(int nItemIndex, CString ItemString, int nImageIndex, DWORD dwExData)
{
ASSERT(nItemIndex >= 0 && nItemIndex <= m_ItemList.GetSize());
CTabBarItem* pBarItem = new CTabBarItem(ItemString, nImageIndex, dwExData);
ASSERT(pBarItem);
if(nItemIndex < m_ItemList.GetSize())
m_ItemList.InsertAt(nItemIndex, (void*)pBarItem);
else
nItemIndex = m_ItemList.Add((void*)pBarItem);
return nItemIndex;
}
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TABBARCTRL_H_INCLUDED_)