// XTOutBarCtrl.cpp : implementation of the CXTOutBarCtrl class.
//
// This file is a part of the Xtreme Toolkit for MFC.
// �1998-2002 Codejock Software, All Rights Reserved.
//
// This source code can only be used under the terms and conditions
// outlined in the accompanying license agreement.
//
// support@codejock.com
// http://www.codejock.com
//
//////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
//#include "XTResource.h"
//#include "XTGlobal.h"
//#include "XTWndHook.h"
//#include "XTCoolMenu.h"
#include "XTOutBarCtrl.h"
#include "XTMemDC.h"
//#include "XTPriv.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const clr3DShadow= ::GetSysColor(COLOR_3DSHADOW);
const clrWindow= ::GetSysColor(COLOR_WINDOW);
const bXPMode= FALSE;
const clrXP3DFace= ::GetSysColor(COLOR_3DFACE);
const clrBtnText= ::GetSysColor(COLOR_BTNTEXT);
const clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);
const clr3DHilight= ::GetSysColor(COLOR_3DHILIGHT);
const clr3DFace =::GetSysColor(COLOR_3DFACE);
const clrHighlight = ::GetSysColor(COLOR_HIGHLIGHT);
const clrXPHighlightLight= ::GetSysColor(COLOR_HIGHLIGHT);
const clrXPHighlight=::GetSysColor(COLOR_HIGHLIGHT);
typedef enum XT_RCOB
{
RC_OB_ICON = 1,
RC_OB_LABEL,
RC_OB_BOTH
};
const int NONE =-1;
const int FOLDER = 0;
const int ITEM = 1;
const int UPSCROLL = 2;
const int DNSCROLL = 3;
/////////////////////////////////////////////////////////////////////////////
// CXTEditItem helper class
class CXTEditItem : public CEdit
{
DECLARE_DYNAMIC(CXTEditItem)
public:
// Constructs a CXTEditItem object.
CXTEditItem();
// Destroys a CXTEditItem object, handles cleanup and de-allocation.
virtual ~CXTEditItem();
int m_nIndex;
BOOL m_bEscapeKey;
CString m_strText;
WPARAM m_wParam;
BOOL m_bNoDown;
//:Ignore
//{{AFX_VIRTUAL(CXTEditItem)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
//:End Ignore
protected:
//:Ignore
//{{AFX_MSG(CXTEditItem)
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
//}}AFX_MSG
//:End Ignore
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// CXTEditItem
CXTEditItem::CXTEditItem()
{
m_bEscapeKey = FALSE;
m_nIndex = -1;
m_wParam = OBN_XT_ONGROUPENDEDIT;
m_bNoDown = FALSE;
}
CXTEditItem::~CXTEditItem()
{
}
IMPLEMENT_DYNAMIC(CXTEditItem, CEdit)
BEGIN_MESSAGE_MAP(CXTEditItem, CEdit)
//{{AFX_MSG_MAP(CXTEditItem)
ON_WM_KILLFOCUS()
ON_WM_CREATE()
ON_WM_CHAR()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CXTEditItem::OnKillFocus(CWnd* /*pNewWnd*/)
{
PostMessage(WM_CLOSE, 0, 0);
if (!m_bEscapeKey)
{
GetWindowText(m_strText);
if (m_strText != "")
{
CWnd* pOwner = GetOwner();
ASSERT_VALID(pOwner);
pOwner->SendMessage(XTWM_OUTBAR_NOTIFY,
m_wParam, (LPARAM)this);
}
}
}
BOOL CXTEditItem::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->wParam == VK_RETURN)
{
PostMessage(WM_CLOSE, 0, 0);
return TRUE;
}
else if (pMsg->wParam == VK_ESCAPE)
{
PostMessage(WM_CLOSE, 0, 0);
return m_bEscapeKey = TRUE;
}
return CEdit::PreTranslateMessage(pMsg);
}
void CXTEditItem::PostNcDestroy()
{
CEdit::PostNcDestroy();
delete this;
}
int CXTEditItem::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
CXTOutBarCtrl* pParent = (CXTOutBarCtrl*)GetParent();
ASSERT_VALID(pParent);
SetFont(pParent->GetFontX());
return 0;
}
void CXTEditItem::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CXTOutBarCtrl* pParent = (CXTOutBarCtrl*)GetParent();
ASSERT_VALID(pParent);
if (m_wParam == OBN_XT_ONGROUPENDEDIT)
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
return;
}
if (nChar == VK_ESCAPE || nChar == VK_RETURN)
{
if (nChar == VK_ESCAPE) m_bEscapeKey = TRUE;
pParent->SetFocus();
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
CString str;
CRect rect, parentrect;
GetClientRect(&rect);
pParent->GetClientRect(&parentrect);
ClientToScreen(&rect);
pParent->ScreenToClient(&rect);
GetWindowText(str);
CWindowDC dc(this);
CFont*pFont = pParent->GetFontX();
CFont*pFontDC = dc.SelectObject(pFont);
CRect szrc(rect);
szrc.bottom = szrc.top;
if (m_bNoDown == TRUE)
{
dc.DrawText(str, szrc, DT_CALCRECT);
if (szrc.right >= parentrect.right - 1) rect.right = parentrect.right - 1;
else rect.right = szrc.right;
MoveWindow(&rect);
return;
}
dc.DrawText(str, szrc, DT_WORDBREAK|DT_CENTER|DT_CALCRECT);
dc.SelectObject(pFontDC);
CSize size = szrc.Size();
if (size.cx > rect.Width())
{
if (size.cx + rect.left < parentrect.right) rect.right = rect.left + size.cx;
else rect.right = parentrect.right;
MoveWindow(&rect);
}
else if (size.cy > rect.Height())
{
if (size.cy + rect.bottom < parentrect.bottom) rect.bottom = rect.top + size.cy;
else rect.bottom = parentrect.bottom;
MoveWindow(&rect);
}
}
BOOL CXTEditItem::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
UNREFERENCED_PARAMETER(pWnd);
UNREFERENCED_PARAMETER(nHitTest);
UNREFERENCED_PARAMETER(message);
HCURSOR hCur = ::LoadCursor(NULL, IDC_IBEAM);
::SetCursor(hCur);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CXTOutBarCtrl
CXTOutBarCtrl::CXTOutBarCtrl() : m_penBlack(PS_SOLID, 1, RGB(0,0,0))
{
m_rcUpArrow.SetRectEmpty();
m_rcDownArrow.SetRectEmpty();
m_dwFlags = OBS_XT_DEFAULT;
m_pLargeImageList = NULL;
m_pSmallImageList = NULL;
m_sizeOffset.cx = 4;
m_sizeOffset.cy = 3;
m_sizeMargin.cx = 5;
m_sizeMargin.cy = 5;
m_nFolderHeight = 22;
m_nSelFolder = 0;
m_nLastFolderSelected = -1;
m_nFolderHilighted = -1;
m_nLastItemSelected = -1;
m_nItemHilighted = -1;
m_nLastDragItemDraw = -1;
m_nLastDragItemDrawType = -1;
m_nFirstItem = 0;
m_nIconSpacingSmall = 10;
m_nIconSpacingLarge = 8;
m_nAnimationTickCount = 10;
m_nSelAnimCount = 0;
m_nSelAnimTiming = 0;
m_nHitInternal1 = 0;
m_nHitInternal2 = 0;
m_bUpArrow = FALSE;
m_bDownArrow = FALSE;
m_bUpPressed = FALSE;
m_bDownPressed = FALSE;
m_bLooping = FALSE;
m_bPressedHighlight = FALSE;
m_bIconPressed = FALSE;
m_bUserClrBack = FALSE;
m_bUserClrText = FALSE;
m_clrBack = clr3DShadow;//
m_clrText = clrWindow;
SetFontX(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
}
CXTOutBarCtrl::~CXTOutBarCtrl()
{
for (int iFolder = 0; iFolder < m_arFolder.GetSize(); iFolder++)
{
m_nSelFolder = iFolder;
CXTBarFolder* pBarFolder = (CXTBarFolder*)m_arFolder.GetAt(iFolder);
delete( pBarFolder );//xu
}
m_arFolder.RemoveAll();
m_penBlack.DeleteObject();
m_font.Delet