📄 bcgpframeimpl.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.
//*******************************************************************************
// BCGFrameImpl.cpp: implementation of the CBCGPFrameImpl class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "multimon.h"
#include "BCGPFrameImpl.h"
#include "BCGPToolBar.h"
#include "BCGPMenuBar.h"
#include "BCGPLocalResource.h"
#include "bcgprores.h"
#include "BCGPPopupMenu.h"
#include "BCGPToolbarMenuButton.h"
#include "BCGPWorkspace.h"
#include "RegPath.h"
#include "BCGPRegistry.h"
#include "BCGPTearOffManager.h"
#include "BCGPVisualManager.h"
#include "BCGPDockBar.h"
#include "BCGPKeyboardManager.h"
#include "BCGPMiniFrameWnd.h"
#include "BCGPPrintPreviewView.h"
#include "BCGPCustomizeMenuButton.h"
#include "CustomizeButton.h"
#include "BCGPToolbarCustomize.h"
#include "BCGPVisualManagerXP.h"
#include "BCGPWinXPVisualManager.h"
#include "BCGPDropDown.h"
#include "BCGPMDIFrameWnd.h"
#include "BCGPFrameWnd.h"
#include "BCGPOleIPFrameWnd.h"
#include "BCGPOleDocIPFrameWnd.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern CObList gAllToolbars;
extern CBCGPWorkspace* g_pWorkspace;
class CCustomizeButton;
static const CString strTearOffBarsRegEntry = _T("ControlBars-TearOff");
BOOL CBCGPFrameImpl::m_bControlBarExtraPixel = TRUE;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#pragma warning (disable : 4355)
CBCGPFrameImpl::CBCGPFrameImpl(CFrameWnd* pFrame) :
m_pFrame (pFrame),
m_pDockManager (NULL),
m_uiUserToolbarFirst ((UINT)-1),
m_uiUserToolbarLast ((UINT)-1),
m_pMenuBar (NULL),
m_hDefaultMenu (NULL),
m_nIDDefaultResource (0),
m_FullScreenMgr(this),
m_bLoadDockState(TRUE)
{
ASSERT_VALID (m_pFrame);
}
#pragma warning (default : 4355)
//**************************************************************************************
CBCGPFrameImpl::~CBCGPFrameImpl()
{
//-----------------------------
// Clear user-defined toolbars:
//-----------------------------
while (!m_listUserDefinedToolbars.IsEmpty ())
{
delete m_listUserDefinedToolbars.RemoveHead ();
}
//-------------------------
// Clear tear-off toolbars:
//-------------------------
while (!m_listTearOffToolbars.IsEmpty ())
{
delete m_listTearOffToolbars.RemoveHead ();
}
}
//**************************************************************************************
void CBCGPFrameImpl::OnCloseFrame()
{
ASSERT_VALID (m_pFrame);
//----------------------------------------------------------------------
// Automatically load state and frame position if CBCGPWorkspace is used:
//----------------------------------------------------------------------
if (g_pWorkspace != NULL)
{
if (m_FullScreenMgr.IsFullScreen())
{
if(::IsWindow (m_pFrame->GetSafeHwnd ()))
{
m_FullScreenMgr.RestoreState(m_pFrame);
}
}
g_pWorkspace->OnClosingMainFrame (this);
//---------------------------
// Store the Windowplacement:
//---------------------------
if (::IsWindow (m_pFrame->GetSafeHwnd ()))
{
WINDOWPLACEMENT wp;
wp.length = sizeof (WINDOWPLACEMENT);
if (m_pFrame->GetWindowPlacement (&wp))
{
//---------------------------
// Make sure we don't pop up
// minimized the next time
//---------------------------
if (wp.showCmd != SW_SHOWMAXIMIZED)
{
wp.showCmd = SW_SHOWNORMAL;
}
RECT rectDesktop;
SystemParametersInfo(SPI_GETWORKAREA,0,(PVOID)&rectDesktop,0);
OffsetRect(&wp.rcNormalPosition, rectDesktop.left, rectDesktop.top);
g_pWorkspace->StoreWindowPlacement (
wp.rcNormalPosition, wp.flags, wp.showCmd);
}
}
}
}
//**************************************************************************************
void CBCGPFrameImpl::RestorePosition(CREATESTRUCT& cs)
{
if (g_pWorkspace != NULL &&
cs.hInstance != NULL)
{
CRect rectNormal (CPoint (cs.x, cs.y), CSize (cs.cx, cs.cy));
int nFlags = 0;
int nShowCmd = SW_SHOWNORMAL;
if (!g_pWorkspace->LoadWindowPlacement (rectNormal, nFlags, nShowCmd))
{
return;
}
if (nShowCmd != SW_MAXIMIZE)
{
nShowCmd = SW_SHOWNORMAL;
}
switch (AfxGetApp()->m_nCmdShow)
{
case SW_MAXIMIZE:
case SW_MINIMIZE:
case SW_SHOWMINIMIZED:
case SW_SHOWMINNOACTIVE:
break; // don't change!
default:
AfxGetApp()->m_nCmdShow = nShowCmd;
}
CRect rectDesktop;
CRect rectInter;
MONITORINFO mi;
mi.cbSize = sizeof (MONITORINFO);
if (GetMonitorInfo (MonitorFromPoint (rectNormal.TopLeft (),
MONITOR_DEFAULTTONEAREST), &mi))
{
rectDesktop = mi.rcWork;
}
else
{
::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectDesktop, 0);
}
if (rectInter.IntersectRect (&rectDesktop, &rectNormal))
{
cs.x = rectInter.left;
cs.y = rectInter.top;
cs.cx = rectNormal.Width ();
cs.cy = rectNormal.Height ();
}
}
}
//**************************************************************************************
void CBCGPFrameImpl::OnLoadFrame()
{
//---------------------------------------------------
// Automatically load state if CBCGPWorkspace is used:
//---------------------------------------------------
if (g_pWorkspace != NULL)
{
g_pWorkspace->LoadState (0, this);
}
}
//**************************************************************************************
void CBCGPFrameImpl::LoadUserToolbars ()
{
ASSERT_VALID (m_pFrame);
if (m_uiUserToolbarFirst == (UINT) -1 ||
m_uiUserToolbarLast == (UINT) -1)
{
return;
}
for (UINT uiNewToolbarID = m_uiUserToolbarFirst;
uiNewToolbarID <= m_uiUserToolbarLast;
uiNewToolbarID ++)
{
CBCGPToolBar* pNewToolbar = new CBCGPToolBar;
if (!pNewToolbar->Create (m_pFrame,
dwDefaultToolbarStyle,
uiNewToolbarID))
{
TRACE0 ("Failed to create a new toolbar!\n");
delete pNewToolbar;
continue;
}
if (!pNewToolbar->LoadState (m_strControlBarRegEntry))
{
pNewToolbar->DestroyWindow ();
delete pNewToolbar;
}
else
{
pNewToolbar->SetBarStyle (pNewToolbar->GetBarStyle () |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
pNewToolbar->EnableDocking (CBRS_ALIGN_ANY);
ASSERT_VALID (m_pDockManager);
m_pDockManager->DockControlBar (pNewToolbar);
m_listUserDefinedToolbars.AddTail (pNewToolbar);
}
}
}
//**********************************************************************************************
void CBCGPFrameImpl::SaveUserToolbars (BOOL bFrameBarsOnly)
{
for (POSITION pos = m_listUserDefinedToolbars.GetHeadPosition (); pos != NULL;)
{
CBCGPToolBar* pUserToolBar =
(CBCGPToolBar*) m_listUserDefinedToolbars.GetNext (pos);
ASSERT_VALID(pUserToolBar);
if (!bFrameBarsOnly || pUserToolBar->GetTopLevelFrame () == m_pFrame)
{
pUserToolBar->SaveState (m_strControlBarRegEntry);
}
}
}
//**********************************************************************************************
CBCGPToolBar* CBCGPFrameImpl::GetUserBarByIndex (int iIndex) const
{
POSITION pos = m_listUserDefinedToolbars.FindIndex (iIndex);
if (pos == NULL)
{
return NULL;
}
CBCGPToolBar* pUserToolBar =
(CBCGPToolBar*) m_listUserDefinedToolbars.GetAt (pos);
ASSERT_VALID (pUserToolBar);
return pUserToolBar;
}
//**********************************************************************************************
BOOL CBCGPFrameImpl::IsUserDefinedToolbar (const CBCGPToolBar* pToolBar) const
{
ASSERT_VALID (pToolBar);
UINT uiCtrlId = pToolBar->GetDlgCtrlID ();
return uiCtrlId >= m_uiUserToolbarFirst &&
uiCtrlId <= m_uiUserToolbarLast;
}
//*******************************************************************************************
BOOL CBCGPFrameImpl::IsDockStateValid (const CDockState& state)
{
ASSERT_VALID (m_pFrame);
return TRUE;
}
//**********************************************************************************
void CBCGPFrameImpl::InitUserToolbars ( LPCTSTR lpszRegEntry,
UINT uiUserToolbarFirst,
UINT uiUserToolbarLast)
{
ASSERT (uiUserToolbarLast >= uiUserToolbarFirst);
if (uiUserToolbarFirst == (UINT) -1 ||
uiUserToolbarLast == (UINT) -1)
{
ASSERT (FALSE);
return;
}
m_uiUserToolbarFirst = uiUserToolbarFirst;
m_uiUserToolbarLast = uiUserToolbarLast;
// ET: get Path automatically from workspace if needed
m_strControlBarRegEntry = (lpszRegEntry == NULL) ?
( g_pWorkspace ? g_pWorkspace->GetRegSectionPath() : _T("") )
: lpszRegEntry;
}
//**************************************************************************************
UINT CBCGPFrameImpl::GetFreeCtrlBarID (UINT uiFirstID, UINT uiLastID, const CObList& lstCtrlBars)
{
if (uiFirstID == (UINT)-1 || uiLastID == (UINT)-1)
{
return 0;
}
int iMaxToolbars = uiLastID - uiFirstID + 1;
if (lstCtrlBars.GetCount () == iMaxToolbars)
{
return 0;
}
for (UINT uiNewToolbarID = uiFirstID; uiNewToolbarID <= uiLastID;
uiNewToolbarID ++)
{
BOOL bUsed = FALSE;
for (POSITION pos = lstCtrlBars.GetHeadPosition ();
!bUsed && pos != NULL;)
{
CBCGPToolBar* pToolBar = (CBCGPToolBar*) lstCtrlBars.GetNext (pos);
ASSERT_VALID (pToolBar);
bUsed = (pToolBar->GetDlgCtrlID () == (int) uiNewToolbarID);
}
if (!bUsed)
{
return uiNewToolbarID;
}
}
return 0;
}
//**************************************************************************************
const CBCGPToolBar* CBCGPFrameImpl::CreateNewToolBar (LPCTSTR lpszName)
{
ASSERT_VALID (m_pFrame);
ASSERT (lpszName != NULL);
UINT uiNewToolbarID =
GetFreeCtrlBarID (m_uiUserToolbarFirst, m_uiUserToolbarLast, m_listUserDefinedToolbars);
if (uiNewToolbarID == 0)
{
CBCGPLocalResource locaRes;
CString strError;
strError.Format (IDS_BCGBARRES_TOO_MANY_TOOLBARS_FMT,
m_uiUserToolbarLast - m_uiUserToolbarFirst + 1);
AfxMessageBox (strError, MB_OK | MB_ICONASTERISK);
return NULL;
}
CBCGPToolBar* pNewToolbar = new CBCGPToolBar;
if (!pNewToolbar->Create (m_pFrame,
dwDefaultToolbarStyle,
uiNewToolbarID))
{
TRACE0 ("Failed to create a new toolbar!\n");
delete pNewToolbar;
return NULL;
}
pNewToolbar->SetWindowText (lpszName);
pNewToolbar->SetBarStyle (pNewToolbar->GetBarStyle () |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
pNewToolbar->EnableDocking (CBRS_ALIGN_ANY);
CRect rectBar;
pNewToolbar->GetWindowRect (rectBar);
int nLeft = ::GetSystemMetrics (SM_CXFULLSCREEN) / 2;
int nTop = ::GetSystemMetrics (SM_CYFULLSCREEN) / 2;
CRect rectFloat (nLeft, nTop, nLeft + rectBar.Width (), nTop + rectBar.Height ());
pNewToolbar->FloatControlBar (rectFloat, DM_UNKNOWN);
pNewToolbar->m_nMRUWidth = 32767;
m_pFrame->RecalcLayout ();
m_listUserDefinedToolbars.AddTail (pNewToolbar);
return pNewToolbar;
}
//**************************************************************************************
void CBCGPFrameImpl::AddTearOffToolbar (CBCGPBaseControlBar* pToolBar)
{
ASSERT_VALID (pToolBar);
m_listTearOffToolbars.AddTail (pToolBar);
}
//**************************************************************************************
void CBCGPFrameImpl::RemoveTearOffToolbar (CBCGPBaseControlBar* pToolBar)
{
ASSERT_VALID (pToolBar);
POSITION pos = m_listTearOffToolbars.Find (pToolBar);
if (pos != NULL)
{
m_listTearOffToolbars.RemoveAt (pos);
}
}
//**************************************************************************************
void CBCGPFrameImpl::LoadTearOffMenus ()
{
ASSERT_VALID (m_pFrame);
//------------------------------
// Remove current tear-off bars:
//------------------------------
for (POSITION pos = m_listTearOffToolbars.GetHeadPosition (); pos != NULL;)
{
CBCGPBaseControlBar* pBar = (CBCGPBaseControlBar*) m_listTearOffToolbars.GetNext (pos);
ASSERT_VALID (pBar);
if (pBar->IsDocked ())
{
pBar->UnDockControlBar (TRUE);
}
pBar->DestroyWindow ();
delete pBar;
}
m_listTearOffToolbars.RemoveAll ();
CString strProfileName = g_pWorkspace != NULL ?
g_pWorkspace->GetRegSectionPath() : _T("");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -