www.pudn.com > CraftFTP_gb.rar > CaptionBar.cpp
// CaptionBar.cpp : implementation file
//
#include "stdafx.h"
#include "CraftFTP.h"
#include "CaptionBar.h"
#include "LocalListCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCaptionBar
CCaptionBar::CCaptionBar()
{
m_bActiveCaption = FALSE;
m_bRemote = FALSE;
m_szCaptionText = _T("");
}
CCaptionBar::~CCaptionBar()
{
}
BEGIN_MESSAGE_MAP(CCaptionBar, CStatic)
//{{AFX_MSG_MAP(CCaptionBar)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_SIZE()
ON_WM_SYSCOLORCHANGE()
//}}AFX_MSG_MAP
ON_COMMAND(IDC_BUTTON_UP,OnFolderUp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCaptionBar message handlers
int CCaptionBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatic::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if(!m_wndCombBox.Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST, CRect(2,2,300,250), this, 1000))
return -1;
m_wndCombBox.SetParent(this);
if(!m_wndButtonnUp.Create(NULL,WS_VISIBLE|BS_ICON|BS_OWNERDRAW|BS_FLAT|
BS_CENTER|BS_VCENTER,CRect(0,0,100,100),this,IDC_BUTTON_UP))
return -1;
m_wndButtonnUp.m_nFlatStyle = CLCCButton::BUTTONSTYLE_FLAT;
m_wndButtonnUp.SetImage(IDB_FOLDER_UP);
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
m_font.DeleteObject();
lf.lfHeight = 80;
lf.lfWeight = 200;
m_font.CreatePointFontIndirect(&lf);
SetFont(&m_font);
m_wndTooltipCtrl.Create(this);
m_wndTooltipCtrl.Activate(TRUE);
m_wndTooltipCtrl.AddTool(&m_wndButtonnUp,IDS_BUTTON_UP);
return 0;
}
BOOL CCaptionBar::Create(CView* pParentWnd, BOOL bRemote)
{
m_bRemote = bRemote;
m_wndCombBox.SetRemote(bRemote);
return CStatic::Create( NULL, WS_VISIBLE|SS_CENTER|SS_CENTERIMAGE, CRect(0,0,0,0), pParentWnd, 0xffff );
}
void CCaptionBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rcClient;
GetClientRect( &rcClient );
rcClient.OffsetRect(-1,-1);
rcClient.right += 2;
dc.FillSolidRect( rcClient, ::GetSysColor(COLOR_BTNFACE) );
//dc.Draw3dRect(rcClient, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
BOOL bGradient = FALSE;
::SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradient, 0);
COLORREF clrCptn = m_bActiveCaption ?
::GetSysColor(COLOR_ACTIVECAPTION) :
::GetSysColor(COLOR_INACTIVECAPTION);
COLORREF clrCptnRight = m_bActiveCaption ?
::GetSysColor(COLOR_GRADIENTACTIVECAPTION) :
::GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
GetClientRect( &rcClient );
rcClient.bottom = 17;
rcClient.OffsetRect(-1,-1);
rcClient.right += 2;
CString szText ;
szText.LoadString(IDS_CAPTIONBAR_TEXT);
szText += m_szCaptionText;
rcClient.OffsetRect(1,1);
rcClient.right -= 2;
rcClient.bottom -= 6;
if(!bGradient)
dc.FillSolidRect( rcClient, clrCptn );
else
{
int nShift = 6;
int nSteps = 1 << nShift;
for (int i = 0; i < nSteps; i++)
{
// do a little alpha blending
int nR = (GetRValue(clrCptn) * (nSteps - i) +
GetRValue(clrCptnRight) * i) >> nShift;
int nG = (GetGValue(clrCptn) * (nSteps - i) +
GetGValue(clrCptnRight) * i) >> nShift;
int nB = (GetBValue(clrCptn) * (nSteps - i) +
GetBValue(clrCptnRight) * i) >> nShift;
COLORREF cr = RGB(nR, nG, nB);
CRect r2 = rcClient;
r2.left = rcClient.left +
((i * rcClient.Width()) >> nShift);
r2.right = rcClient.left +
(((i + 1) * rcClient.Width()) >> nShift);
if (r2.Width() > 0)
dc.FillSolidRect(r2, cr);
}
}
COLORREF clrCptnText = m_bActiveCaption ?
::GetSysColor(COLOR_CAPTIONTEXT) :
::GetSysColor(COLOR_INACTIVECAPTIONTEXT);
int nOldBkMode = dc.SetBkMode(TRANSPARENT);
COLORREF clrOldText = dc.SetTextColor(clrCptnText);
CFont* pOldFont = dc.SelectObject(&m_font);
CPoint ptOrg = rcClient.TopLeft();
dc.ExtTextOut(ptOrg.x, ptOrg.y-1,ETO_CLIPPED, rcClient, szText, NULL);
dc.SelectObject(pOldFont);
dc.SetBkMode(nOldBkMode);
dc.SetTextColor(clrOldText);
}
void CCaptionBar::OnSize(UINT nType, int cx, int cy)
{
CStatic::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_wndCombBox.GetSafeHwnd())
m_wndCombBox.MoveWindow(-1,13,cx-24,cy-12);
if(m_wndButtonnUp.GetSafeHwnd())
m_wndButtonnUp.MoveWindow(cx-23,13,22,cy-17);
}
CPathComboBox * CCaptionBar::GetPathComboBox()
{
return &m_wndCombBox;
}
CLCCButton * CCaptionBar::GetUpButton()
{
return &m_wndButtonnUp;
}
void CCaptionBar::OnFolderUp()
{
// TODO: Add your specialized code here and/or call the base class
CWaitCursor w;
EnableAllChild(FALSE);
GetParent()->SetFocus();
m_wndCombBox.FolderUpButtonClick();
}
void CCaptionBar::SetActiveCaption(BOOL bActive)
{
if(m_bActiveCaption != bActive)
{
m_bActiveCaption = bActive;
Invalidate();
}
}
void CCaptionBar::OnSysColorChange()
{
CStatic::OnSysColorChange();
// TODO: Add your message handler code here
Invalidate();
}
void CCaptionBar::SetCaptionText(CString szText)
{
m_szCaptionText = szText;
Invalidate();
}
void CCaptionBar::EnableAllChild(BOOL bEnable)
{
m_wndCombBox.EnableWindow(bEnable);
m_wndButtonnUp.EnableWindow(bEnable);
}
BOOL CCaptionBar::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
m_wndTooltipCtrl.RelayEvent(pMsg);
return CStatic::PreTranslateMessage(pMsg);
}