/* MZCrumbBar.cpp
MZCrumbBar Ctrl - Created by Mathias Svensson (C) Copyright 2009-2010 - ( http://result42.com/projects/MZCrumbBar )
History
v1.2 2010-04-15 Added improvments/fixes provided by Iain Clarke
* 3 more BuildCrumbbar(...) function for special situations.
* Refactored how a path is parsed.
* Added CRU_LASTITEMNODELIMITER. If style is set the Delimiter will not be shown for last crumbbar item.
* Style can now be set using styleEx.
* Change Default hot color to COLOR_HOTLIGHT
* Added possibility to store custom data in a Crumbar item.
* Added SetItemData/GetItemData of custom data to crumbbar items.
Fixed so that if double delimiter now works again. Double delimiter should be part of the crumbpath name, not a splitter.
Change so that items are added to m_vCrumbItems via the virtual function AddCrumbItem(...)
Fixed so that empty path parts are not added to the path.
v1.1 2010-03-17 First Public Version, Fixed minor draw issue
v1.0 2009-10-10 First Version
All rights reserved.
Copyright / Usage Details:
You are allowed to include this source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code. If you fix any bug or add enhachment please send
the changes to the author so they may be included in the source.
*/
#include "stdafx.h"
#include "MZCrumbBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MZCRUMBBARCTRL_CLASSNAME _T("MZCrumbBarCtrl")
IMPLEMENT_DYNAMIC(MZCrumbBar, CWnd)
namespace
{
class CMemoryDC: public CDC
{
public:
CMemoryDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL);
m_pDC = pDC;
m_pOldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
if (m_bMemDC) // Create a Memory DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
FillSolidRect(m_rect, pDC->GetBkColor());
}
else
{
// Make a copy of the relevant parts of the current DC for printing
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
~CMemoryDC()
{
if (m_bMemDC)
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_pOldBitmap);
}
else
{
m_hDC = m_hAttribDC = NULL;
}
}
CMemoryDC* operator->() { return this; }
operator CMemoryDC*() { return this; }
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
};
class MZCrumbBar_InplaceEditCtrl : public CEdit
{
// Construction
public:
MZCrumbBar_InplaceEditCtrl(const CString& strText);
virtual ~MZCrumbBar_InplaceEditCtrl(){};
virtual BOOL PreTranslateMessage(MSG* pMsg);
private:
CString m_strInitText;
bool m_bVK_ESCAPE;
bool m_bVK_RETURN;
// Generated message map functions
protected:
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnNcDestroy();
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////////////////////////////
// CListEditCtrl
BEGIN_MESSAGE_MAP(MZCrumbBar_InplaceEditCtrl, CEdit)
ON_WM_KILLFOCUS()
ON_WM_NCDESTROY()
ON_WM_CHAR()
ON_WM_CREATE()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListEditCtrl message handlers
MZCrumbBar_InplaceEditCtrl::MZCrumbBar_InplaceEditCtrl(const CString& strText)
: m_strInitText(strText)
{
m_bVK_ESCAPE = false;
m_bVK_RETURN = false;
}
int MZCrumbBar_InplaceEditCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
CFont* font = GetParent()->GetFont();
SetFont(font);
SetWindowText(m_strInitText);
SetFocus();
SetSel(0, 0);
return 0;
}
BOOL MZCrumbBar_InplaceEditCtrl::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
// If MZCrumbBar is placed on a dialog and user are editing the CrumbBar and press return key we will close dialog
// We do not want that
// So while we are editing. do not send any keydown messages down to the dialog
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return 1;
}
return CEdit::PreTranslateMessage(pMsg);
}
void MZCrumbBar_InplaceEditCtrl::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
CString str;
GetWindowText(str);
// Send Notification to parent (the MZCrumbBar Ctrl)
LV_DISPINFO lvDispInfo;
lvDispInfo.hdr.hwndFrom = GetParent()->m_hWnd;
lvDispInfo.hdr.idFrom = GetDlgCtrlID();
lvDispInfo.hdr.code = LVN_ENDLABELEDIT;
lvDispInfo.item.mask = LVIF_TEXT;
lvDispInfo.item.iItem = 0;
lvDispInfo.item.iSubItem = 0;
lvDispInfo.item.pszText = m_bVK_RETURN ? LPTSTR((LPCTSTR)str) : NULL;
lvDispInfo.item.cchTextMax = str.GetLength();
GetParent()->GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(),(LPARAM)&lvDispInfo);
DestroyWindow();
}
void MZCrumbBar_InplaceEditCtrl::OnNcDestroy()
{
CEdit::OnNcDestroy();
delete this;
}
void MZCrumbBar_InplaceEditCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if( nChar == VK_ESCAPE || nChar == VK_RETURN)
{
if(nChar == VK_ESCAPE)
{
m_bVK_ESCAPE = true;
}
else
{
m_bVK_RETURN = true;
}
GetParent()->SetFocus();
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
//////////////////////////////////////////////////////////////////////////
MZCrumbBar::MZCrumbBar()
{
WNDCLASS wndclass;
HINSTANCE hInst = AfxGetInstanceHandle();
if(!(::GetClassInfo(hInst, MZCRUMBBARCTRL_CLASSNAME, &wndclass)))
{
wndclass.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc = ::DefWindowProc;
wndclass.cbClsExtra = wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(hInst, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = MZCRUMBBARCTRL_CLASSNAME;
if (!AfxRegisterClass(&wndclass))
AfxThrowResourceException();
}
m_bCreateForSubclassing = false;
m_strDelimiter = _T('\\');
m_nDelimiterMode = DM_RIGHT;
m_DrawState.Clear();
m_bDrawStateDirty = true;
m_bMouseOver = false;
m_pNotifyTarget = NULL;
m_bDblClk = false;
m_dwStyleEx = 0;
m_bGradientBackground = false;
m_hBackBrush = NULL;
m_hwndBrush = ::CreateSolidBrush(GetSysColor(COLOR_WINDOW));
m_PreItem.nWidth = -1;
m_PreItem.DisplayName = _T("[<<]");
m_nMargin = 0;
m_nItemSpacing = 0;
m_crColorDefault = GetSysColor(COLOR_WINDOWTEXT);
m_crColorHot = GetSysColor (COLOR_HO
MZCrumbBarSrc_v12.zip_As One_breadcrumb
版权申诉
154 浏览量
2022-09-22
19:55:43
上传
评论
收藏 13KB ZIP 举报
朱moyimi
- 粉丝: 64
- 资源: 1万+
最新资源
- 批量word文件内容替换工具1.0 (批量实现多个 Word 文档文件文字替换利器).exe
- Cartoon GUI Pack 1.2.zip
- 【数据集和代码】基于加速度传感器的步态识别行人分类实验(可做步态识别)
- 我分享个魔兽内存修改器
- Python毕业设计基于Django的网易云数据分析可视化大屏系统的设计与实现+使用说明+全部资料(优秀项目).zip
- mp3 idv2,idv1,frame分析工具
- Python毕业设计基于Django的网易云数据分析可视化大屏系统的设计与实现+使用说明+全部资料(高分项目).zip
- 人工兔优化算法ARO MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用
- 人才网站设计-asp.net+sql-(系统源码)
- asp.net+sql人才网站设计-含系统源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0