📄 bcgpoutlookwnd.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// 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.
//*******************************************************************************
//
// BCGPOutlookWnd.cpp : implementation file
//
#include "stdafx.h"
#include "bcgcbpro.h"
#include "BCGPOutlookWnd.h"
#include "BCGPOutlookBarPane.h"
#include "BCGPOutlookBar.h"
#include "BCGPDockingCBWrapper.h"
#include "BCGGlobals.h"
#include "BCGPLocalResource.h"
#include "BCGPVisualManager.h"
#include "BCGPOutlookButton.h"
#include "BCGPDockManager.h"
#include "bcgprores.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CBCGPOutlookWnd, CBCGPBaseTabWnd)
void CBCGPOutlookSrcrollButton::OnFillBackground (CDC* pDC, const CRect& rectClient)
{
CBCGPVisualManager::GetInstance ()->OnFillOutlookPageButton (pDC,
rectClient, m_bHighlighted, m_bPushed, globalData.clrBarText);
}
void CBCGPOutlookSrcrollButton::OnDrawBorder (CDC* pDC, CRect& rectClient, UINT uiState)
{
CBCGPVisualManager::GetInstance ()->OnDrawOutlookPageButtonBorder (
pDC, rectClient, m_bHighlighted, m_bPushed);
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPOutlookWnd
BOOL CBCGPOutlookWnd::m_bEnableAnimation = FALSE;
CBCGPOutlookWnd::CBCGPOutlookWnd()
{
m_rectWndArea.SetRectEmpty ();
m_nBorderSize = 0;
m_bActivateOnBtnUp = TRUE;
m_bEnableTabSwap = FALSE;
m_bScrollButtons = FALSE;
m_btnUp.m_nFlatStyle = CBCGPButton::BUTTONSTYLE_SEMIFLAT;
m_btnUp.m_bDrawFocus = FALSE;
m_btnDown.m_nFlatStyle = CBCGPButton::BUTTONSTYLE_SEMIFLAT;
m_btnDown.m_bDrawFocus = FALSE;
m_nPageButtonTextAlign = TA_CENTER;
}
CBCGPOutlookWnd::~CBCGPOutlookWnd()
{
}
BEGIN_MESSAGE_MAP(CBCGPOutlookWnd, CBCGPBaseTabWnd)
//{{AFX_MSG_MAP(CBCGPOutlookWnd)
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_SETCURSOR()
ON_WM_ERASEBKGND()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCGPOutlookWnd message handlers
BOOL CBCGPOutlookWnd::Create (const CRect& rect, CWnd* pParentWnd, UINT nID)
{
if (!CWnd::Create (NULL, _T(""),
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
rect, pParentWnd, nID))
{
return FALSE;
}
SetTabsHeight ();
m_bHighLightTabs = TRUE;
return TRUE;
}
//*********************************************************************************
BOOL CBCGPOutlookWnd::IsPtInTabArea (CPoint point) const
{
CRect rectTop; rectTop.SetRectEmpty ();
CRect rectBottom; rectBottom.SetRectEmpty ();
GetTabArea (rectTop, rectBottom);
ScreenToClient (rectTop);
ScreenToClient (rectBottom);
return rectTop.PtInRect (point) || rectBottom.PtInRect (point);
}
//*********************************************************************************
void CBCGPOutlookWnd::RecalcLayout ()
{
if (GetSafeHwnd () == NULL)
{
return;
}
ASSERT_VALID (this);
m_btnUp.SendMessage (WM_CANCELMODE);
m_btnDown.SendMessage (WM_CANCELMODE);
CRect rectClient;
GetClientRect (rectClient);
rectClient.DeflateRect (m_nBorderSize + 1, m_nBorderSize + 1);
m_rectWndArea = rectClient;
int nVisibleTabsNum = GetVisibleTabsNum ();
if (nVisibleTabsNum > 1 || !IsHideSingleTab ())
{
m_rectWndArea.DeflateRect (0, 1);
}
int y = rectClient.top;
if (nVisibleTabsNum > 1 || !IsHideSingleTab ())
{
for (int i = 0; i < m_iTabsNum; i ++)
{
CBCGPTabInfo* pTab = (CBCGPTabInfo*) m_arTabs [i];
ASSERT_VALID (pTab);
pTab->m_rect = rectClient;
pTab->m_rect.top = y;
pTab->m_rect.right++;
pTab->m_rect.bottom = y + m_nTabsHeight;
if (m_bScrollButtons &&
(i == m_iActiveTab || i == m_iActiveTab + 1))
{
CRect rectScroll = pTab->m_rect;
pTab->m_rect.right -= m_nTabsHeight;
rectScroll.left = pTab->m_rect.right;
if (i == m_iActiveTab)
{
m_btnUp.SetWindowPos (NULL, rectScroll.left, rectScroll.top,
rectScroll.Width (), rectScroll.Height (),
SWP_NOACTIVATE | SWP_NOZORDER);
}
else
{
m_btnDown.SetWindowPos (NULL, rectScroll.left, rectScroll.top,
rectScroll.Width (), rectScroll.Height (),
SWP_NOACTIVATE | SWP_NOZORDER);
}
}
if (i == m_iActiveTab)
{
m_rectWndArea.top = y + m_nTabsHeight;
y = rectClient.bottom - m_nTabsHeight * (m_iTabsNum - i - 1) + 1;
m_rectWndArea.bottom = y - 1;
}
else
{
y += m_nTabsHeight;
}
}
}
if (m_bScrollButtons && m_iActiveTab == m_iTabsNum - 1)
{
m_rectWndArea.bottom -= m_nTabsHeight;
m_btnDown.SetWindowPos (NULL, rectClient.right - m_nTabsHeight + 1,
rectClient.bottom - m_nTabsHeight + 1,
m_nTabsHeight, m_nTabsHeight,
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
}
for (int i = 0; i < m_iTabsNum; i ++)
{
CBCGPTabInfo* pTab = (CBCGPTabInfo*) m_arTabs [i];
ASSERT_VALID (pTab);
if (pTab->m_bVisible)
{
CBCGPOutlookBarPane* pOutlookPane = DYNAMIC_DOWNCAST (
CBCGPOutlookBarPane, pTab->m_pWnd);
if (pOutlookPane != NULL)
{
pOutlookPane->m_nSize = m_rectWndArea.Width ();
pOutlookPane->m_nMaxLen = m_rectWndArea.Height ();
}
pTab->m_pWnd->SetWindowPos (NULL,
m_rectWndArea.left, m_rectWndArea.top,
m_rectWndArea.Width (), m_rectWndArea.Height (),
SWP_NOACTIVATE | SWP_NOZORDER);
}
}
if (nVisibleTabsNum != 0)
{
RedrawWindow ();
}
else
{
ShowWindow (SW_HIDE);
}
m_btnUp.RedrawWindow ();
m_btnDown.RedrawWindow ();
GetParent ()->RedrawWindow (NULL, NULL);
}
//**********************************************************************************
BOOL CBCGPOutlookWnd::SetActiveTab (int iTab)
{
ASSERT_VALID (this);
if (iTab < 0 || iTab >= m_iTabsNum)
{
TRACE(_T("SetActiveTab: illegal tab number %d\n"), iTab);
return FALSE;
}
if (iTab >= m_arTabs.GetSize ())
{
ASSERT (FALSE);
return FALSE;
}
BOOL bIsFirstTime = (m_iActiveTab == -1);
if (m_iActiveTab == iTab) // Already active, do nothing
{
return TRUE;
}
//-------------------------------------------------------------------
// Show active tab with animation only if tab was activated by mouse:
//-------------------------------------------------------------------
BOOL bAnimate = (m_iHighlighted == m_iPressed) && (m_iHighlighted != -1) && m_bEnableAnimation;
CBCGPOutlookBar* pOutlookBar =
DYNAMIC_DOWNCAST (CBCGPOutlookBar, GetParent ());
if (pOutlookBar != NULL && !pOutlookBar->OnBeforeAnimation (iTab))
{
bAnimate = FALSE;
}
int iOldActiveTab = m_iActiveTab;
CWnd* pWndOld = GetActiveWnd ();
m_iActiveTab = iTab;
CWnd* pWndActive = GetActiveWnd ();
if (pWndActive == NULL)
{
ASSERT (FALSE);
return FALSE;
}
ASSERT_VALID (pWndActive);
if (bAnimate)
{
CBCGPTabInfo* pTabInfoNew = (CBCGPTabInfo*) m_arTabs [m_iActiveTab];
CBCGPTabInfo* pTabInfoOld = (CBCGPTabInfo*) m_arTabs [iOldActiveTab];
BOOL bMoveDown = (m_iActiveTab < iOldActiveTab);
ASSERT_VALID (pTabInfoNew);
ASSERT_VALID (pTabInfoOld);
CRect rectClient;
GetClientRect (rectClient);
CRect rectOldWnd;
pWndOld->GetWindowRect (rectOldWnd);
ScreenToClient (rectOldWnd);
const int dy = bMoveDown ? 30 : -30;
const int nSteps = abs (rectOldWnd.Height () / dy);
//---------------------
// Hide scroll buttons:
//---------------------
BOOL bScrollButtons = m_bScrollButtons;
BOOL bIsUp = m_btnUp.IsWindowEnabled ();
BOOL bIsDown = m_btnDown.IsWindowEnabled ();
if (bScrollButtons)
{
m_btnUp.ShowWindow (SW_HIDE);
m_btnDown.ShowWindow (SW_HIDE);
for (int i = 0; i < m_iTabsNum; i++)
{
CBCGPTabInfo* pTab = (CBCGPTabInfo*) m_arTabs [i];
ASSERT_VALID (pTab);
if (i == m_iActiveTab || i == m_iActiveTab + 1)
{
pTab->m_rect.right += m_nTabsHeight;
}
}
}
CRect rectOld;
if (bMoveDown)
{
CBCGPTabInfo* pTabInfo = (CBCGPTabInfo*) m_arTabs [m_iActiveTab + 1];
rectOld = pTabInfo->m_rect;
rectOld.bottom = rectOld.top + dy;
}
else
{
CBCGPTabInfo* pTabInfo = (CBCGPTabInfo*) m_arTabs [m_iActiveTab];
rectOld = pTabInfo->m_rect;
rectOld.top = rectOld.bottom + dy;
}
ModifyStyle (WS_CLIPCHILDREN, 0, SWP_NOREDRAW);
CClientDC dc (this);
CFont* pOldFont = (CFont*) dc.SelectObject (&globalData.fontRegular);
dc.SetBkMode (TRANSPARENT);
int nStartBtnIdx = bMoveDown ? m_iActiveTab + 1 : iOldActiveTab + 1;
int nEndBtnIdx = bMoveDown ? iOldActiveTab : m_iActiveTab;
CRect rectRedraw = rectOldWnd;
// we need to move all tabs between old active and new active tabs
CBCGPDockManager::m_bDisableRecalcLayout = TRUE;
for (int i = 0; i < nSteps; i++)
{
bMoveDown ? rectOldWnd.top += dy : rectOldWnd.bottom += dy;
pWndOld->SetWindowPos (NULL,
rectOldWnd.left, rectOldWnd.top,
rectOldWnd.Width (), rectOldWnd.Height (),
SWP_NOZORDER | SWP_NOACTIVATE);
for (int i = nStartBtnIdx; i <= nEndBtnIdx; i++)
{
CBCGPTabInfo* pTabInfo = (CBCGPTabInfo*) m_arTabs [i];
pTabInfo->m_rect.OffsetRect (0, dy);
DrawTabButton (dc, i, FALSE);
}
dc.FillRect (rectOld, &globalData.brBarFace);
rectOld.OffsetRect (0, dy);
Sleep (10);
}
if (bScrollButtons)
{
//------------------------
// Restore scroll buttons:
//------------------------
EnableScrollButtons (TRUE, bIsUp, bIsDown);
}
CBCGPDockManager::m_bDisableRecalcLayout = FALSE;
dc.SelectObject (pOldFont);
ModifyStyle (0, WS_CLIPCHILDREN, SWP_NOREDRAW);
pWndOld->ShowWindow (SW_HIDE);
RecalcLayout ();
if (pOutlookBar != NULL)
{
pOutlookBar->OnAfterAnimation (iTab);
}
pWndActive->SetWindowPos (NULL, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOACTIVATE);
pWndActive->BringWindowToTop ();
pWndActive->RedrawWindow (NULL, NULL,
RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN);
}
else
{
//--------------------
// Hide active window:
//--------------------
if (pWndOld != NULL)
{
pWndOld->ShowWindow (SW_HIDE);
}
RecalcLayout ();
//------------------------
// Show new active window:
//------------------------
pWndActive->ShowWindow (SW_SHOW);
pWndActive->BringWindowToTop ();
//----------------------------------------------------------------------
// Small trick: to adjust active window scroll sizes, I should change an
// active window size twice (+1 pixel and -1 pixel):
//----------------------------------------------------------------------
CBCGPDockManager::m_bDisableRecalcLayout = TRUE;
pWndActive->SetWindowPos (NULL,
-1, -1,
m_rectWndArea.Width () + 1, m_rectWndArea.Height (),
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
pWndActive->SetWindowPos (NULL,
-1, -1,
m_rectWndArea.Width (), m_rectWndArea.Height (),
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
CBCGPDockManager::m_bDisableRecalcLayout = FALSE;
}
//--------------------------------------------------
// Set text to the parent frame/docking control bar:
//--------------------------------------------------
if (pOutlookBar != NULL &&
pOutlookBar->CanSetCaptionTextToTabName ()) // tabbed dock bar - redraw caption only in this case
{
CString strCaption;
GetTabLabel (m_iActiveTab, strCaption);
//-------------------------------------------------------
// Miniframe will take the text from the tab control bar:
//-------------------------------------------------------
if (pOutlookBar->CanSetCaptionTextToTabName ())
{
pOutlookBar->SetWindowText (strCaption);
}
CWnd* pWndToUpdate = pOutlookBar;
if (!pOutlookBar->IsDocked ())
{
pWndToUpdate = pOutlookBar->GetParent ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -