📄 bcgpbasecontrolbar.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.
//*******************************************************************************
// BCGPBaseControlBar.cpp : implementation file
//
#include "stdafx.h"
#include "BCGPFrameWnd.h"
#include "BCGPMiniFrameWnd.h"
#include "BCGPMultiMiniFrameWnd.h"
#include "BCGPSlider.h"
#include "BCGPFrameWnd.h"
#include "BCGPMDIFrameWnd.h"
#include "BCGPOleIPFrameWnd.h"
#include "BCGPOleDocIPFrameWnd.h"
#include "BCGPMDIChildWnd.h"
#include "BCGPOleCntrFrameWnd.h"
#include "BCGPDockBar.h"
#include "BCGPDockBarRow.h"
#include "BCGPBaseTabWnd.h"
#include "BCGPBaseControlBar.h"
#include "BCGPBaseTabbedBar.h"
#include "BCGPDockingCBWrapper.h"
#include "RegPath.h"
#include "BCGPRegistry.h"
#include "BCGPGlobalUtils.h"
#include "BCGPDockManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static const CString strBaseControlBarProfile = _T ("BCGPBaseControlBars");
BOOL CBCGPBaseControlBar::m_bSetTooltipTopmost = TRUE;
#define REG_SECTION_FMT _T("%sBCGPBaseControlBar-%d")
#define REG_SECTION_FMT_EX _T("%sBCGPBaseControlBar-%d%x")
BOOL CBCGPBaseControlBar::m_bMultiThreaded = FALSE;
CCriticalSection CBCGPBaseControlBar::g_cs;
IMPLEMENT_DYNAMIC (CBCGPBaseControlBar, CWnd)
/////////////////////////////////////////////////////////////////////////////
// CBCGPBaseControlBar
CBCGPBaseControlBar::CBCGPBaseControlBar()
{
m_dwEnabledAlignment = 0;
m_dwStyle = 0;
m_pParentDockBar = NULL;
m_pDockBarRow = NULL;
m_pDockSite = NULL;
m_bRecentVisibleState = FALSE;
m_bIsRestoredFromRegistry = FALSE;
m_dwBCGStyle = 0;
m_bVisible = FALSE;
m_dockMode = DT_UNDEFINED;
m_bEnableIDChecking = TRUE;
m_lpszBarTemplateName = NULL;
m_sizeDialog = CSize (0, 0);
m_rectBar.SetRectEmpty ();
m_bIsDlgControl = FALSE;
}
CBCGPBaseControlBar::~CBCGPBaseControlBar()
{
}
BEGIN_MESSAGE_MAP(CBCGPBaseControlBar, CWnd)
//{{AFX_MSG_MAP(CBCGPBaseControlBar)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
ON_MESSAGE(WM_INITDIALOG, HandleInitDialog)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCGPBaseControlBar message handlers
//*******************************************************************************
BOOL CBCGPBaseControlBar::CreateEx(DWORD dwStyleEx, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle, const RECT& rect,
CWnd* pParentWnd, UINT nID,
DWORD dwBCGStyle,
CCreateContext* pContext)
{
ASSERT_VALID (pParentWnd);
if (m_bEnableIDChecking)
{
CBCGPDockManager* pDockManager = globalUtils.GetDockManager (pParentWnd);
if (pDockManager == NULL)
{
pDockManager = globalUtils.GetDockManager (BCGPGetParentFrame (pParentWnd));
if (pDockManager != NULL)
{
if (pDockManager->FindBarByID (nID, TRUE) != NULL)
{
TRACE0("Control bar must be created with unique ID!\n");
}
}
}
}
m_bVisible = m_bVisible & WS_VISIBLE;
SetBarStyle (dwStyle | GetBarStyle ());
m_dwBCGStyle = dwBCGStyle;
BOOL bResult = FALSE;
if (m_lpszBarTemplateName != NULL)
{
CREATESTRUCT cs;
memset(&cs, 0, sizeof(cs));
cs.lpszClass = lpszClassName;//AFX_WNDCONTROLBAR;
cs.lpszName = lpszWindowName;
cs.style = dwStyle | WS_CHILD;
cs.hMenu = (HMENU)nID;
cs.hInstance = AfxGetInstanceHandle();
cs.hwndParent = pParentWnd->GetSafeHwnd();
if (!PreCreateWindow(cs))
{
return FALSE;
}
//----------------------------
// initialize common controls
//----------------------------
//VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));
//AfxDeferRegisterClass(AFX_WNDCOMMCTLSNEW_REG);
//--------------------------
// create a modeless dialog
//--------------------------
if (!CreateDlg (m_lpszBarTemplateName, pParentWnd))
{
TRACE(_T("Can't create dialog: %s\n"), m_lpszBarTemplateName);
return FALSE;
}
SetClassLong(m_hWnd, GCL_HBRBACKGROUND, (LPARAM)::GetSysColorBrush(COLOR_BTNFACE));
SetDlgCtrlID(nID);
CRect rect;
GetWindowRect(&rect);
m_sizeDialog = rect.Size ();
bResult = TRUE;
}
else
{
bResult = CWnd::CreateEx (dwStyleEx, lpszClassName, lpszWindowName,
dwStyle, rect, pParentWnd, nID, pContext);
}
if (bResult)
{
if (pParentWnd->IsKindOf (RUNTIME_CLASS (CFrameWnd)))
{
m_pDockSite = DYNAMIC_DOWNCAST (CFrameWnd, pParentWnd);
}
else
{
// case of miniframe or smth. else
m_pDockSite = DYNAMIC_DOWNCAST (CFrameWnd, BCGPGetParentFrame (pParentWnd));
}
m_bIsDlgControl = pParentWnd->IsKindOf (RUNTIME_CLASS (CDialog));
}
return bResult;
}
//*******************************************************************************
BOOL CBCGPBaseControlBar::OnEraseBkgnd(CDC* /*pDC*/)
{
return TRUE;
}
//*******************************************************************************
void CBCGPBaseControlBar::DoPaint(CDC* pDC)
{
CRect rectClip;
pDC->GetClipBox (rectClip);
CRect rect;
GetClientRect(rect);
CBCGPVisualManager::GetInstance ()->OnFillBarBackground (pDC, this,
rect, rectClip);
}
//*******************************************************************************
BOOL CBCGPBaseControlBar::IsDocked () const
{
// return TRUE if its parent is not miniframe or the bar is floating
// in the miniframe with another control bar
CBCGPMiniFrameWnd* pParentMiniFrame = GetParentMiniFrame ();
if (pParentMiniFrame != NULL)
{
ASSERT_VALID (pParentMiniFrame);
if (pParentMiniFrame->GetControlBarCount () == 1)
{
return FALSE;
}
}
return TRUE;
}
//*******************************************************************************
BOOL CBCGPBaseControlBar::IsTabbed () const
{
ASSERT_VALID (this);
CWnd* pParent = GetParent ();
ASSERT_VALID (pParent);
return pParent->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabWnd));
}
//*******************************************************************************
BOOL CBCGPBaseControlBar::IsVisible () const
{
ASSERT_VALID (this);
if (!IsTabbed ())
{
if (CBCGPDockManager::m_bRestoringDockState)
{
return GetRecentVisibleState ();
}
return ((GetStyle () & WS_VISIBLE) != 0);
}
HWND hWndTab = NULL;
CBCGPBaseTabWnd* pParent = GetParentTabWnd (hWndTab);
ASSERT_VALID (pParent);
if (!pParent->IsWindowVisible ())
{
return FALSE;
}
int iTabNum = pParent->GetTabFromHwnd (hWndTab);
ASSERT (iTabNum >= 0 && iTabNum < pParent->GetTabsNum ());
return pParent->IsTabVisible (iTabNum);
}
//***********************************************************************************//
CBCGPMiniFrameWnd* CBCGPBaseControlBar::GetParentMiniFrame (BOOL bNoAssert) const
{
ASSERT_VALID (this);
CBCGPMiniFrameWnd* pMiniFrame = NULL;
CWnd* pParent = GetParent ();
while (pParent != NULL)
{
if (!bNoAssert)
{
ASSERT_VALID (pParent);
}
if (pParent != NULL && pParent->IsKindOf (RUNTIME_CLASS (CBCGPMiniFrameWnd)))
{
pMiniFrame = DYNAMIC_DOWNCAST (CBCGPMiniFrameWnd, pParent);
break;
}
pParent = pParent->GetParent ();
}
return pMiniFrame;
}
//***********************************************************************************
void CBCGPBaseControlBar::OnPaint()
{
if (m_bMultiThreaded)
{
g_cs.Lock ();
}
CPaintDC dc(this);
// erase background now
if (GetStyle() & WS_VISIBLE)
DoPaint(&dc);
if (m_bMultiThreaded)
{
g_cs.Unlock ();
}
}
//*************************************************************************************
HDWP CBCGPBaseControlBar::MoveWindow (CRect& rect, BOOL bRepaint, HDWP hdwp)
{
CRect rectOld;
GetWindowRect (rectOld);
if (IsFloating ())
{
CBCGPMiniFrameWnd* pMiniFrame = GetParentMiniFrame ();
ASSERT_VALID (pMiniFrame);
pMiniFrame->ScreenToClient (rectOld);
}
else if (m_pDockSite != NULL)
{
m_pDockSite->ScreenToClient (rectOld);
}
if (rectOld == rect)
{
return hdwp;
}
if (hdwp != NULL)
{
UINT uFlags = SWP_NOZORDER | SWP_NOACTIVATE;
return DeferWindowPos (hdwp, GetSafeHwnd (), NULL, rect.left, rect.top, rect.Width (),
rect.Height (), uFlags);
}
CWnd::MoveWindow (&rect, bRepaint);
return NULL;
}
//****************************************************************************************
HDWP CBCGPBaseControlBar::SetWindowPos (const CWnd* pWndInsertAfter, int x, int y,
int cx, int cy, UINT nFlags, HDWP hdwp)
{
if (hdwp == NULL)
{
CWnd::SetWindowPos (pWndInsertAfter, x, y, cx, cy, nFlags);
return NULL;
}
HDWP hdwpNew = DeferWindowPos (hdwp, GetSafeHwnd (), NULL, x, y, cx, cy, nFlags);
if (hdwpNew == NULL)
{
DWORD dwLastError = GetLastError ();
TRACE1 ("DeferWindowPos failded, error code %d\n", dwLastError);
SetWindowPos (NULL, x, y, cx, cy, nFlags);
return hdwp;
}
return hdwpNew;
}
//*******************************************************************************
// frame mapping functions
//*******************************************************************************
void CBCGPBaseControlBar::AddControlBar (CBCGPBaseControlBar* pBar)
{
CWnd* pParentFrame = GetDockSite ();
if (pParentFrame == NULL && globalUtils.m_bDialogApp)
{
return;
}
ASSERT_VALID (pParentFrame);
if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
{
((CBCGPFrameWnd*) pParentFrame)->AddControlBar (pBar);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
{
((CBCGPMDIFrameWnd*) pParentFrame)->AddControlBar (pBar);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
{
((CBCGPOleIPFrameWnd*) pParentFrame)->AddControlBar (pBar);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
{
((CBCGPOleDocIPFrameWnd*) pParentFrame)->AddControlBar (pBar);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
{
((CBCGPMDIChildWnd*) pParentFrame)->AddControlBar (pBar);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
{
((CBCGPOleCntrFrameWnd*) pParentFrame)->AddControlBar (pBar);
}
else
{
ASSERT (FALSE);
}
}
//*******************************************************************************
void CBCGPBaseControlBar::RemoveControlBarFromDockManager (CBCGPBaseControlBar* pBar,
BOOL bDestroy, BOOL bAdjustLayout,
BOOL bAutoHide)
{
CWnd* pParentFrame = GetDockSite ();
if (pParentFrame == NULL && globalUtils.m_bDialogApp)
{
return;
}
ASSERT_VALID (pParentFrame);
if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
{
((CBCGPFrameWnd*) pParentFrame)->RemoveControlBarFromDockManager (pBar, bDestroy, bAdjustLayout, bAutoHide);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
{
((CBCGPMDIFrameWnd*) pParentFrame)->RemoveControlBarFromDockManager (pBar, bDestroy, bAdjustLayout, bAutoHide);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
{
((CBCGPOleIPFrameWnd*) pParentFrame)->RemoveControlBarFromDockManager (pBar, bDestroy, bAdjustLayout, bAutoHide);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
{
((CBCGPOleDocIPFrameWnd*) pParentFrame)->RemoveControlBarFromDockManager (pBar, bDestroy, bAdjustLayout, bAutoHide);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
{
((CBCGPMDIChildWnd*) pParentFrame)->RemoveControlBarFromDockManager (pBar, bDestroy, bAdjustLayout, bAutoHide);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
{
((CBCGPOleCntrFrameWnd*) pParentFrame)->RemoveControlBarFromDockManager (pBar, bDestroy, bAdjustLayout, bAutoHide);
}
else
{
ASSERT (FALSE);
}
}
//*******************************************************************************
BOOL CBCGPBaseControlBar::IsPointNearDockBar (CPoint point, DWORD& dwBarAlignment,
BOOL& bOuterEdge) const
{
CWnd* pParentFrame = GetDockSite ();
if (pParentFrame == NULL && globalUtils.m_bDialogApp)
{
return TRUE;
}
ASSERT_VALID (pParentFrame);
if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
{
return ((CBCGPFrameWnd*) pParentFrame)->
IsPointNearDockBar (point, dwBarAlignment, bOuterEdge);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
{
return ((CBCGPMDIFrameWnd*) pParentFrame)->
IsPointNearDockBar (point, dwBarAlignment, bOuterEdge);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
{
return ((CBCGPOleIPFrameWnd*) pParentFrame)->
IsPointNearDockBar (point, dwBarAlignment, bOuterEdge);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
{
return ((CBCGPOleDocIPFrameWnd*) pParentFrame)->
IsPointNearDockBar (point, dwBarAlignment, bOuterEdge);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
{
return ((CBCGPMDIChildWnd*) pParentFrame)->
IsPointNearDockBar (point, dwBarAlignment, bOuterEdge);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
{
return ((CBCGPOleCntrFrameWnd*) pParentFrame)->
IsPointNearDockBar (point, dwBarAlignment, bOuterEdge);
}
else
{
ASSERT (FALSE);
}
return FALSE;
}
//*******************************************************************************
CBCGPBaseControlBar* CBCGPBaseControlBar::ControlBarFromPoint (CPoint point,
int nSensitivity, bool bExactBar, CRuntimeClass* pRTCBarType) const
{
CWnd* pParentFrame = GetDockSite ();
if (pParentFrame == NULL && globalUtils.m_bDialogApp)
{
return NULL;
}
ASSERT_VALID (pParentFrame);
if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
{
return ((CBCGPFrameWnd*) pParentFrame)->
ControlBarFromPoint (point, nSensitivity, bExactBar, pRTCBarType);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
{
return ((CBCGPMDIFrameWnd*) pParentFrame)->
ControlBarFromPoint (point, nSensitivity, bExactBar, pRTCBarType);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
{
return ((CBCGPOleIPFrameWnd*) pParentFrame)->
ControlBarFromPoint (point, nSensitivity, bExactBar, pRTCBarType);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
{
return ((CBCGPOleDocIPFrameWnd*) pParentFrame)->
ControlBarFromPoint (point, nSensitivity, bExactBar, pRTCBarType);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
{
return ((CBCGPMDIChildWnd*) pParentFrame)->
ControlBarFromPoint (point, nSensitivity, bExactBar, pRTCBarType);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -