⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgpcalendarbar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// BCGCalendarBar.cpp : implementation file
// This is a part of the BCGControlBar Library
// Copyright (C) 1998-2000 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.
//

#include "stdafx.h"
#include <math.h>
#include <locale.h>

#include "BCGCBPro.h"
#include "BCGPCalendarBar.h"
#include "BCGPCalendarMenuButton.h"
#include "BCGPPopupMenu.h"
#include "BCGPContextMenuManager.h"
#include "BCGPDateTimeCtrl.h"
#include "trackmouse.h"
#include "BCGPVisualManager.h"
#include "BCGPWorkspace.h"
#include "BCGProRes.h"
#include "BCGPLocalResource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define DISABLE_MONTH_POPUP

static const int SEPARATOR_SIZE = 2;
static const int nHoldMouseTimerID = 1;

UINT BCGM_CALENDAR_ON_SELCHANGED = ::RegisterWindowMessage (_T("BCGM_CALENDAR_ON_SELCHANGED"));

/////////////////////////////////////////////////////////////////////////////

class CCalendarWeekButton : public CBCGPCalendarButton  
{
	friend class CBCGPCalendarBar;
	friend class CBCGPCalendarMenuButton;

	DECLARE_SERIAL(CCalendarWeekButton)

protected:
	virtual void SetDate(const COleDateTime& date)
	{
		if (date != m_Calendar)
		{
			CBCGPDefaultLocale dl;

			m_Calendar = date;
			m_strText = m_Calendar.Format(_T("%a"));
			m_pParentBar->InvalidateRect(m_rect);
		}
	}

	virtual BOOL IsActualDay () const
	{
		return FALSE;
	}
};

IMPLEMENT_SERIAL(CCalendarWeekButton, CBCGPCalendarButton, 1)

class CCalendarWeekNumButton : public CBCGPCalendarButton  
{
	friend class CBCGPCalendarBar;
	friend class CBCGPCalendarMenuButton;

	DECLARE_SERIAL(CCalendarWeekNumButton)

protected:
	virtual void SetDate(const COleDateTime& date)
	{
		if (date != m_Calendar)
		{
			CBCGPDefaultLocale dl;

			m_Calendar = date;
			m_strText.Format(_T("%02d"), CBCGPCalendarBar::GetWeekNo(m_Calendar, m_pParentBar->m_nWeekStart)); 
			m_pParentBar->InvalidateRect(m_rect);
		}
	}

	virtual COLORREF GetTextColor ()
	{
		ASSERT_VALID (m_pParentBar);
		return IsCurrMonth () ? 
			m_pParentBar->m_clrWeekText : m_pParentBar->m_clrWeekTextDisabled;
	}

	virtual BOOL IsActualDay () const
	{
		return FALSE;
	}
};

IMPLEMENT_SERIAL(CCalendarWeekNumButton, CBCGPCalendarButton, 1)

class CCalendarTodayButton : public CBCGPCalendarButton  
{
	friend class CBCGPCalendarBar;
	friend class CBCGPCalendarMenuButton;

	DECLARE_SERIAL(CCalendarTodayButton)

protected:
	CCalendarTodayButton(int iImage = -1)
	{
		m_iImage = iImage;
	}

	virtual BOOL OnToolHitTest(const CWnd* /*pWnd*/, TOOLINFO* pTI)
	{
		if (m_nStyle & TBBS_DISABLED)
		{
			return FALSE;
		}

		if (!CBCGPToolBar::GetShowTooltips ())
		{
			return FALSE;
		}

		ASSERT (pTI != NULL);

		CString str = _T("Today");

		pTI->lpszText = (LPTSTR) ::calloc ((str.GetLength () + 1), sizeof (TCHAR));
		_tcscpy (pTI->lpszText, str);

		return TRUE;
	}

	virtual void SetDate(const COleDateTime& date)
	{
		if (date != m_Calendar)
		{
			m_Calendar = date;
			m_pParentBar->InvalidateRect(m_rect);
		}
	}
	
	virtual BOOL IsActualDay () const
	{
		return FALSE;
	}
};

IMPLEMENT_SERIAL(CCalendarTodayButton, CBCGPCalendarButton, 1)

//*******************************************************
class CCalendarNavigateButton : public CBCGPCalendarButton  
{
	friend class CBCGPCalendarBar;
	friend class CBCGPCalendarMenuButton;

	DECLARE_SERIAL(CCalendarNavigateButton)

protected:
	CCalendarNavigateButton(int iImage = -1)
	{
		m_iImage = iImage;
	}

	virtual BOOL OnToolHitTest(const CWnd* /*pWnd*/, TOOLINFO* pTI)
	{
		if (m_nStyle & TBBS_DISABLED)
		{
			return FALSE;
		}

		if (!CBCGPToolBar::GetShowTooltips ())
		{
			return FALSE;
		}

		ASSERT (pTI != NULL);

		CString str;

		switch (m_iImage)
		{
		case 0:
			str = _T("Prev. year");
			break;

		case 1:
			str = _T("Prev. month");
			break;

		case 2:
			str = _T("Next month");
			break;

		case 3:
			str = _T("Next year");
			break;
		}

		pTI->lpszText = (LPTSTR) ::calloc ((str.GetLength () + 1), sizeof (TCHAR));
		_tcscpy (pTI->lpszText, str);

		return TRUE;
	}

	virtual void SetDate(const COleDateTime& date)
	{
		if (date != m_Calendar)
		{
			m_Calendar = date;
			m_pParentBar->InvalidateRect(m_rect);
		}
	}

	virtual BOOL IsActualDay () const
	{
		return FALSE;
	}
};

IMPLEMENT_SERIAL(CCalendarNavigateButton, CBCGPCalendarButton, 1)

//*******************************************************
class CCalendarMonthButton : public CBCGPToolbarButton  
{
	friend class CBCGPCalendarBar;
	friend class CBCGPCalendarMenuButton;

	DECLARE_SERIAL(CCalendarMonthButton)

	
protected:

	CCalendarMonthButton()
	{
		m_pParentBar = NULL;
	}

	virtual BOOL OnToolHitTest(const CWnd* /*pWnd*/, TOOLINFO* pTI)
	{
		if (m_nStyle & TBBS_DISABLED)
		{
			return FALSE;
		}

		if (!CBCGPToolBar::GetShowTooltips ())
		{
			return FALSE;
		}

		ASSERT (pTI != NULL);

		CString str = _T("Change month");

		pTI->lpszText = (LPTSTR) ::calloc ((str.GetLength () + 1), sizeof (TCHAR));
		_tcscpy (pTI->lpszText, str);

		return TRUE;
	}

	virtual void OnDraw (CDC* pDC, const CRect& rect, CBCGPToolBarImages* pImages,
						BOOL bHorz = TRUE, BOOL bCustomizeMode = FALSE,
						BOOL bHighlight = FALSE,
						BOOL bDrawBorder = TRUE,
						BOOL bGrayDisabledButtons = TRUE);
	
	virtual void OnChangeParentWnd (CWnd* pWndParent)
	{
		CBCGPToolbarButton::OnChangeParentWnd (pWndParent);
		m_pParentBar = DYNAMIC_DOWNCAST (CBCGPCalendarBar, pWndParent);
	}

	CSize ContextSize (CWnd* pWnd)
	{
		ASSERT (pWnd->GetSafeHwnd () != NULL);

		CClientDC dc (pWnd);
		CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);
		
		CSize btnSize = dc.GetTextExtent(m_strText);

		dc.SelectObject (pOldFont);
		return btnSize;
	}

	CBCGPCalendarBar*	m_pParentBar;
	virtual BOOL IsActualDay () const
	{
		return FALSE;
	}
};

void CCalendarMonthButton::OnDraw (CDC* pDC, const CRect& rect, CBCGPToolBarImages* /*pImages*/,
								BOOL bHorz, BOOL bCustomizeMode, BOOL bHighlight,
								BOOL bDrawBorder, BOOL bGrayDisabledButtons)
{
	ASSERT_VALID (pDC);
	ASSERT_VALID (this);
	ASSERT_VALID (m_pParentBar);

	CBCGPToolbarButton::OnDraw (pDC, rect, NULL,
								bHorz, bCustomizeMode, bHighlight,
								bDrawBorder, bGrayDisabledButtons);
	
	int nOldBkMode = pDC->SetBkMode (TRANSPARENT);
	COLORREF clrOldText = pDC->SetTextColor (m_pParentBar->m_clrNavButton);

	CFont* pOldFont = pDC->SelectObject (&globalData.fontRegular);
	CRect rectWnd = rect;

	if (m_nStyle ^ TBBS_DISABLED)
	{	
		rectWnd.DeflateRect (1, 1, rect.Height(), 1);
		// Draw menu triangle:
		CRect rectArrow = rectWnd;
		rectArrow.left = rect.right;

		int iXMiddle = rectArrow.left + rectArrow.Width () / 2;

		rectArrow.DeflateRect (0, rectArrow.Height () / 3);
		rectArrow.DeflateRect (rectArrow.Height () / 3, rectArrow.Height () / 3);
		rectArrow.left = iXMiddle - rectArrow.Height () - 1;
		rectArrow.right = iXMiddle + rectArrow.Height () + 1;

		int iHalfWidth =	(rectArrow.Width () % 2 != 0) ?
							(rectArrow.Width () - 1) / 2 :
							rectArrow.Width () / 2;

		CPoint pts [3];
		pts[0].x = rectArrow.left;
		pts[0].y = rectArrow.top;
		pts[1].x = rectArrow.right;
		pts[1].y = rectArrow.top;
		pts[2].x = rectArrow.left + iHalfWidth;
		pts[2].y = rectArrow.bottom + 1;

		CBrush brArrow (pDC->GetTextColor ());

		CPen* pOldPen = (CPen*) pDC->SelectStockObject (NULL_PEN);
		CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brArrow);

		pDC->SetPolyFillMode (WINDING);
		pDC->Polygon (pts, 3);

		pDC->SelectObject (pOldBrush);
		pDC->SelectObject (pOldPen);
		pDC->DrawText (m_strText, rectWnd, DT_VCENTER | DT_RIGHT | DT_SINGLELINE);
	}
	else
	{
		pDC->DrawText (m_strText, rectWnd, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
	}
	pDC->SelectObject (pOldFont);
	pDC->SetTextColor (clrOldText);
	pDC->SetBkMode (nOldBkMode);
	
}
IMPLEMENT_SERIAL(CCalendarMonthButton, CBCGPToolbarButton, 1)


/////////////////////////////////////////////////////////////////////////////
// CBCGPCalendarBar

const UINT CBCGPCalendarBar::CBR_WEEKDAYSEL = 0x1;
const UINT CBCGPCalendarBar::CBR_WEEKNUMBER = 0x2;
const UINT CBCGPCalendarBar::CBR_MULTISELECTION = 0x4;
const UINT CBCGPCalendarBar::CBR_ENABLED = 0x8; // still has not effect - 6.2
const UINT CBCGPCalendarBar::CBR_NAVIGATION_BUTTONS = 0x10;


CString CBCGPCalendarBar::m_strMonthNames[12];

IMPLEMENT_SERIAL(CBCGPCalendarBar, CBCGPPopupMenuBar, 1)

CBCGPCalendarBar::CBCGPCalendarBar()
{
	CommonInit ();

    m_dateSelected = COleDateTime::GetCurrentTime();
	m_nCommandID = 0;
	m_bIsTearOff = TRUE;
	m_pParentBtn = NULL;
}
//**************************************************************************************
CBCGPCalendarBar::CBCGPCalendarBar (const COleDateTime& month, 
				UINT nCommandID, CBCGPDateTimeCtrl* pParentBtn) :
	m_dateSelected (month),
	m_bIsTearOff (FALSE),
	m_nCommandID (nCommandID),
	m_pParentBtn (pParentBtn)
{
	CommonInit ();
}
//**************************************************************************************
CBCGPCalendarBar::CBCGPCalendarBar (CBCGPCalendarBar& src, UINT uiCommandID, BOOL enableSelection) :
		m_dateSelected (src.m_dateSelected),
		m_bIsTearOff (TRUE),
		m_nCommandID (uiCommandID),
		m_pParentBtn (NULL)

{
	CommonInit ();

	if (enableSelection) 
	{
		m_styleFlags |= CBR_MULTISELECTION;
	}
	else				
	{
		m_styleFlags &= (~CBR_MULTISELECTION);
	}
}
//**************************************************************************************
void CBCGPCalendarBar::CommonInit ()
{
	m_bLocked = TRUE;
	m_nWeekStart = 1;
    m_iButtonCapture = -1;
	m_bIsEnabled = TRUE;
	m_nVertMargin = 4;
	m_nHorzMargin = 4;
	m_bInternal = FALSE;
	m_nHorzOffset = m_nVertOffset = 0;
	m_selMode  = Select_BYNONE;
	m_styleFlags = (CBR_WEEKDAYSEL | CBR_WEEKNUMBER | CBR_ENABLED | CBR_NAVIGATION_BUTTONS)
					& (~CBR_MULTISELECTION);
	m_sizeBox = CSize (0, 0);
	m_sizeBoxMin = CSize (0, 0);
	m_bIsCtrl = FALSE;
}
//**************************************************************************************
CBCGPCalendarBar::~CBCGPCalendarBar()
{
}
//*****************************************************************************************
void CBCGPCalendarBar::SetState(UINT flags, UINT mask)
{
	m_styleFlags &= ~mask;
	m_styleFlags |= (flags & mask);

	if (!(m_styleFlags & CBR_MULTISELECTION))
	{
		ClearSelectedDays();
	}

	if (GetSafeHwnd () != NULL)
	{
		Rebuild ();
		AdjustLocations ();

		Invalidate();
		UpdateWindow();
	}
}
//*************************************************************************************
void CBCGPCalendarBar::AdjustLocations ()
{
	ASSERT_VALID(this);

	if (GetSafeHwnd () == NULL || !::IsWindow (m_hWnd))
	{
		return;
	}

	m_sizeBox.cx = max (m_sizeBox.cx, m_sizeBoxMin.cx);
	m_sizeBox.cy = max (m_sizeBox.cy, m_sizeBoxMin.cy);

	CClientDC dc (this);

	CFont* pPrevFont = dc.SelectObject (&globalData.fontRegular);
	ASSERT (pPrevFont != NULL);

	TEXTMETRIC tm;
	dc.GetTextMetrics (&tm);

	m_iTitleHeight = tm.tmHeight + m_nVertMargin * 2;

    CRect rectClient;
	GetClientRect (&rectClient);

	int nWeekBarWidth = CBCGPToolBar::GetMenuImageSize ().cx + 
				2 * CBCGPVisualManager::GetInstance ()->GetMenuImageMargin ();
	int xDaysStart = rectClient.left + nWeekBarWidth + 2 * m_nHorzMargin;

	rectClient.DeflateRect (m_nHorzMargin, m_nVertMargin);

	int x = rectClient.left;
	int y = rectClient.top;
	rectClient.top += m_iTitleHeight;

	int i = 0;

	int iWeekNo = 0;
	int iWeekNum = 0;
	int iDayNum = 0;
	int iNavigate = 0;

	BOOL bPrevSeparator = FALSE;

	for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL; i++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -