| 1 | // Copyright (c) Iuri Apollonio 1998 |
|---|
| 2 | // Use & modify as you want & need, and leave those 3 lines. |
|---|
| 3 | // http://www.codeguru.com |
|---|
| 4 | // |
|---|
| 5 | |
|---|
| 6 | // Animation improvements and drag & drop support. |
|---|
| 7 | // Copyright © 1997-2001 by Sami Tolvanen. |
|---|
| 8 | |
|---|
| 9 | #if !defined(AFX_GFXOUTBARCTRL_H__28FA2CA4_11B7_11D2_8437_0000B43382FE__INCLUDED_) |
|---|
| 10 | #define AFX_GFXOUTBARCTRL_H__28FA2CA4_11B7_11D2_8437_0000B43382FE__INCLUDED_ |
|---|
| 11 | |
|---|
| 12 | #if _MSC_VER >= 1000 |
|---|
| 13 | #pragma once |
|---|
| 14 | #endif // _MSC_VER >= 1000 |
|---|
| 15 | // GfxOutBarCtrl.h : header file |
|---|
| 16 | // |
|---|
| 17 | |
|---|
| 18 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 19 | // CGfxOutBarCtrl window |
|---|
| 20 | |
|---|
| 21 | #include <afxcoll.h> |
|---|
| 22 | #include "DropTargetWnd.h" |
|---|
| 23 | |
|---|
| 24 | #define WM_OUTBAR_NOTIFY WM_USER + 1 |
|---|
| 25 | #define NM_OB_ITEMCLICK 1 |
|---|
| 26 | #define NM_OB_ONLABELENDEDIT 2 |
|---|
| 27 | #define NM_OB_ONGROUPENDEDIT 3 |
|---|
| 28 | #define NM_OB_DRAGITEM 4 |
|---|
| 29 | #define NM_FOLDERCHANGE 5 |
|---|
| 30 | |
|---|
| 31 | // sami@tolvanen.com |
|---|
| 32 | #define NM_PREFOLDERCHANGE 6 |
|---|
| 33 | #define NM_ICONANIMATION 7 |
|---|
| 34 | #define NM_ICONVIEWCHANGE 8 |
|---|
| 35 | |
|---|
| 36 | struct OUTBAR_INFO |
|---|
| 37 | { |
|---|
| 38 | int index; |
|---|
| 39 | const char * cText; |
|---|
| 40 | int iDragFrom; |
|---|
| 41 | int iDragTo; |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | class CGfxOutBarCtrl : public CDropTargetWnd |
|---|
| 45 | { |
|---|
| 46 | // Construction |
|---|
| 47 | DECLARE_DYNCREATE(CGfxOutBarCtrl) |
|---|
| 48 | public: |
|---|
| 49 | CGfxOutBarCtrl(); |
|---|
| 50 | |
|---|
| 51 | enum { fSmallIcon = 1 << 0, fLargeIcon = 1 << 1, fEditGroups = 1 << 2, fEditItems = 1 << 3, |
|---|
| 52 | fRemoveGroups = 1 << 4, fRemoveItems = 1 << 5, fAddGroups = 1 << 6, |
|---|
| 53 | fDragItems = 1 << 7, fAnimation = 1 << 8, fSelHighlight = 1 << 9 }; |
|---|
| 54 | |
|---|
| 55 | enum { ircIcon = 1, ircLabel = 2, ircAll = 3 }; |
|---|
| 56 | |
|---|
| 57 | // Attributes |
|---|
| 58 | public: |
|---|
| 59 | COLORREF crBackGroundColor, crBackGroundColor1; |
|---|
| 60 | COLORREF crTextColor; |
|---|
| 61 | COLORREF cr3dFace, crLightBorder, crHilightBorder, crShadowBorder, crDkShadowBorder; |
|---|
| 62 | int iFolderHeight; |
|---|
| 63 | |
|---|
| 64 | int xSmallIconLabelOffset, yLargeIconLabelOffset; |
|---|
| 65 | int ySmallIconSpacing, yLargeIconSpacing; |
|---|
| 66 | |
|---|
| 67 | int xLeftMargin, yTopMargin; |
|---|
| 68 | bool bUpArrow, bDownArrow, bUpPressed, bDownPressed; |
|---|
| 69 | CRect rcUpArrow, rcDownArrow; |
|---|
| 70 | bool bLooping; |
|---|
| 71 | |
|---|
| 72 | int iHitInternal1, iHitInternal2; |
|---|
| 73 | |
|---|
| 74 | long lAnimationTickCount; |
|---|
| 75 | |
|---|
| 76 | int iLastSel, iSelAnimTiming; |
|---|
| 77 | int iSelAnimCount; |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | DWORD dwFlags; |
|---|
| 81 | |
|---|
| 82 | CPtrArray arFolder; |
|---|
| 83 | |
|---|
| 84 | int iLastFolderHighlighted; |
|---|
| 85 | int iLastSelectedFolder; |
|---|
| 86 | int iFirstItem; |
|---|
| 87 | |
|---|
| 88 | int iLastItemHighlighted; |
|---|
| 89 | bool bPressedHighlight; |
|---|
| 90 | |
|---|
| 91 | int iLastDragItemDraw, iLastDragItemDrawType; |
|---|
| 92 | |
|---|
| 93 | class CBarItem |
|---|
| 94 | { |
|---|
| 95 | public: |
|---|
| 96 | CBarItem(const char * name, const int image, DWORD exData); |
|---|
| 97 | virtual ~CBarItem(); |
|---|
| 98 | int iImageIndex; |
|---|
| 99 | char * cItem; |
|---|
| 100 | DWORD dwData; |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | class CBarFolder |
|---|
| 104 | { |
|---|
| 105 | public: |
|---|
| 106 | CBarFolder(const char * name, DWORD exData); |
|---|
| 107 | virtual ~CBarFolder(); |
|---|
| 108 | int GetItemCount(); |
|---|
| 109 | int InsertItem(int index, const char * text, const int image, const DWORD exData); |
|---|
| 110 | char * cName; |
|---|
| 111 | DWORD dwData; |
|---|
| 112 | CImageList * pLargeImageList; |
|---|
| 113 | CImageList * pSmallImageList; |
|---|
| 114 | CPtrArray arItems; |
|---|
| 115 | CWnd * pChild; |
|---|
| 116 | }; |
|---|
| 117 | |
|---|
| 118 | int iSelFolder; |
|---|
| 119 | |
|---|
| 120 | CImageList * pLargeImageList; |
|---|
| 121 | CImageList * pSmallImageList; |
|---|
| 122 | |
|---|
| 123 | HCURSOR hHandCursor; |
|---|
| 124 | HCURSOR hDragCursor; |
|---|
| 125 | HCURSOR hNoDragCursor; |
|---|
| 126 | |
|---|
| 127 | CPen * pBlackPen; |
|---|
| 128 | |
|---|
| 129 | // for drag open support - sami@tolvanen.com |
|---|
| 130 | BOOL m_bDragOver; |
|---|
| 131 | |
|---|
| 132 | // Operations |
|---|
| 133 | public: |
|---|
| 134 | enum { htNothing = -1, htFolder, htItem, htUpScroll, htDownScroll}; |
|---|
| 135 | |
|---|
| 136 | // Overrides |
|---|
| 137 | // ClassWizard generated virtual function overrides |
|---|
| 138 | //{{AFX_VIRTUAL(CGfxOutBarCtrl) |
|---|
| 139 | //}}AFX_VIRTUAL |
|---|
| 140 | |
|---|
| 141 | // Implementation |
|---|
| 142 | public: |
|---|
| 143 | void DrawAnimItem(const int xoffset, const int yoffset, const int index); |
|---|
| 144 | void SetAnimSelHighlight(const int iTime); |
|---|
| 145 | int GetAnimSelHighligt() { return iSelAnimTiming; } // sami@tolvanen.com |
|---|
| 146 | DWORD GetFolderData(int iFolder = -1); |
|---|
| 147 | CWnd * GetFolderChild(int iFolder = -1); |
|---|
| 148 | int AddFolderBar(const char * pFolder, CWnd * pSon, const DWORD exData = 0); |
|---|
| 149 | CString GetItemText(const int index); |
|---|
| 150 | void SetAnimationTickCount(const long value) { lAnimationTickCount = value; }; |
|---|
| 151 | long GetAnimationTickCount() { return lAnimationTickCount; }; |
|---|
| 152 | |
|---|
| 153 | void AnimateFolderScroll(const int iFrom, const int iTo); |
|---|
| 154 | int GetDragItemRect(const int index, CRect &rect); |
|---|
| 155 | void DrawDragArrow(CDC * pDC, const int iFrom, const int iTo); |
|---|
| 156 | void SetItemImage(const int index, const int iImage); |
|---|
| 157 | void SetItemData(const int index, const DWORD dwData); |
|---|
| 158 | int GetItemImage(const int index) const; |
|---|
| 159 | DWORD GetItemData(const int index) const; |
|---|
| 160 | bool IsValidItem(const int index) const; |
|---|
| 161 | void RemoveItem(const int index); |
|---|
| 162 | void SetItemText(const int index, const char * text); |
|---|
| 163 | void StartItemEdit(const int index); |
|---|
| 164 | void SetFolderText(const int index, const char * text); |
|---|
| 165 | void StartGroupEdit(const int index); |
|---|
| 166 | void GetLabelRect(const int iFolder, const int iIndex, CRect &rect); |
|---|
| 167 | void GetIconRect(const int iFolder, const int iIndex, CRect &rect); |
|---|
| 168 | void HighlightItem(const int index, const bool bPressed = false); |
|---|
| 169 | void GetVisibleRange(const int iFolder, int &first, int &last); |
|---|
| 170 | void DrawItem(CDC * pDC, const int iFolder, CRect rc, const int index, const bool bOnlyImage = false); |
|---|
| 171 | CImageList * GetFolderImageList(const int index, const bool bSmall) const; |
|---|
| 172 | CSize GetItemSize(const int iFolder, const int index, const int type); |
|---|
| 173 | void PaintItems(CDC * pDC, const int iFolder, CRect rc); |
|---|
| 174 | CImageList * GetImageList(CImageList * pImageList, int nImageList); |
|---|
| 175 | CImageList * SetFolderImageList(const int folder, CImageList * pImageList, int nImageList); |
|---|
| 176 | CImageList * SetImageList(CImageList * pImageList, int nImageList); |
|---|
| 177 | int GetCountPerPage() const; |
|---|
| 178 | void RemoveFolder(const int index); |
|---|
| 179 | int GetSelFolder() const; |
|---|
| 180 | int GetFolderCount() const; |
|---|
| 181 | void SetSelFolder(const int index); |
|---|
| 182 | int GetItemCount() const; |
|---|
| 183 | int InsertItem(const int folder, const int index, const char * text, const int image = -1, const DWORD exData = 0); |
|---|
| 184 | void HighlightFolder(const int index); |
|---|
| 185 | int HitTestEx(const CPoint &point, int &index); |
|---|
| 186 | void GetInsideRect(CRect &rect) const; |
|---|
| 187 | int AddFolder(const char * cFolderName, const DWORD exData); |
|---|
| 188 | void GetItemRect(const int iFolder, const int iIndex, CRect &rect); |
|---|
| 189 | bool GetFolderRect(const int iIndex, CRect &rect) const; |
|---|
| 190 | void ModifyFlag(const DWORD &dwRemove, const DWORD &dwAdd, const UINT redraw = 0); |
|---|
| 191 | DWORD GetFlag() const; |
|---|
| 192 | void SetSmallIconView(const bool bSet); |
|---|
| 193 | bool IsSmallIconView() const; |
|---|
| 194 | BOOL Create(DWORD dwStyle, const RECT& rect, CWnd * pParentWnd, UINT nID, const DWORD dwFlag = fDragItems|fEditGroups|fEditItems|fRemoveGroups|fRemoveItems|fAddGroups|fAnimation|fSelHighlight); |
|---|
| 195 | virtual ~CGfxOutBarCtrl(); |
|---|
| 196 | |
|---|
| 197 | // for drag open support - sami@tolvanen.com |
|---|
| 198 | virtual DROPEFFECT OnDragEnter(COleDataObject* pDataObject, |
|---|
| 199 | DWORD dwKeyState, CPoint point); |
|---|
| 200 | virtual void OnDragLeave(); |
|---|
| 201 | |
|---|
| 202 | // Generated message map functions |
|---|
| 203 | protected: |
|---|
| 204 | void DrawFolder(CDC * pDC, const int iIdx, CRect rect, const bool bSelected); |
|---|
| 205 | //{{AFX_MSG(CGfxOutBarCtrl) |
|---|
| 206 | afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); |
|---|
| 207 | afx_msg void OnTimer(UINT_PTR nIDEvent); |
|---|
| 208 | afx_msg void OnPaint(); |
|---|
| 209 | afx_msg BOOL OnEraseBkgnd(CDC* pDC); |
|---|
| 210 | afx_msg void OnMouseMove(UINT nFlags, CPoint point); |
|---|
| 211 | afx_msg void OnLButtonDown(UINT nFlags, CPoint point); |
|---|
| 212 | afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); |
|---|
| 213 | afx_msg void OnSize(UINT nType, int cx, int cy); |
|---|
| 214 | afx_msg void OnRButtonDown(UINT nFlags, CPoint point); |
|---|
| 215 | afx_msg void OnGfxLargeicon(); |
|---|
| 216 | afx_msg void OnUpdateGfxLargeicon(CCmdUI* pCmdUI); |
|---|
| 217 | afx_msg void OnGfxSmallicon(); |
|---|
| 218 | afx_msg void OnUpdateGfxSmallicon(CCmdUI* pCmdUI); |
|---|
| 219 | afx_msg void OnGfxRemoveitem(); |
|---|
| 220 | afx_msg void OnUpdateGfxRemoveitem(CCmdUI* pCmdUI); |
|---|
| 221 | afx_msg void OnGfxRenameitem(); |
|---|
| 222 | afx_msg void OnUpdateGfxRenameitem(CCmdUI* pCmdUI); |
|---|
| 223 | afx_msg void OnSysColorChange(); |
|---|
| 224 | afx_msg void OnGfxAnimation(); |
|---|
| 225 | //}}AFX_MSG |
|---|
| 226 | afx_msg LRESULT OnEndLabelEdit(WPARAM wParam, LPARAM lParam); |
|---|
| 227 | DECLARE_MESSAGE_MAP() |
|---|
| 228 | }; |
|---|
| 229 | |
|---|
| 230 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 231 | |
|---|
| 232 | //{{AFX_INSERT_LOCATION}} |
|---|
| 233 | // Microsoft Developer Studio will insert additional declarations immediately before the previous line. |
|---|
| 234 | |
|---|
| 235 | #endif // !defined(AFX_GFXOUTBARCTRL_H__28FA2CA4_11B7_11D2_8437_0000B43382FE__INCLUDED_) |
|---|