📄 bcgworkspace.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This source code is a part of BCGControlBar library.
// You may use, compile or redistribute it as part of your application
// for free. You cannot redistribute it as a part of a software development
// library without the agreement of the author. If the sources are
// distributed along with the application, you should leave the original
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
//
// Stas Levin <stas@iet.co.il>
//*******************************************************************************
//----------------
// By Erwin Tratar
//----------------
#include "stdafx.h"
#include "globals.h"
#include "bcgcontrolbar.h"
#include "BCGToolBar.h"
#include "BCGSizingControlBar.h"
#include "BCGWorkspace.h"
#include "BCGFrameImpl.h"
#include "BCGMDIFrameWnd.h"
#include "BCGFrameWnd.h"
#include "BCGOleIPFrameWnd.h"
#include "BCGMouseManager.h"
#include "BCGContextMenuManager.h"
#include "BCGKeyboardManager.h"
#include "RebarState.h"
#include "Registry.h"
#include "RegPath.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CBCGWorkspace* g_pWorkspace = NULL;
BOOL g_bWorkspaceAutocreated = FALSE;
CBCGWorkspace* GetWorkspace()
{
//---------------------------------------------------------------------
// You must either:
// ----------------
// a) construct a CBCGWorkspace object
// b) mix a CBCGWorkspace class somewhere in (e.g. your CWinApp object)
// c) call CBCGWorkspace::UseWorkspaceManager() to automatically
// initialize an object for you
//---------------------------------------------------------------------
ASSERT (g_pWorkspace != NULL);
return g_pWorkspace;
}
//-----------------------
// clean up if necessary:
//-----------------------
struct _WORKSPACE_TERM
{
~_WORKSPACE_TERM()
{
if (g_pWorkspace != NULL && g_bWorkspaceAutocreated)
{
delete g_pWorkspace;
g_pWorkspace = NULL;
g_bWorkspaceAutocreated = FALSE;
}
}
};
static const _WORKSPACE_TERM workspaceTerm;
//*************************************************************************************
static const CString strRegEntryNameControlBars = _T("\\ControlBars");
static const CString strWindowPlacementRegSection = _T("WindowPlacement");
static const CString strRectMainKey = _T("MainWindowRect");
static const CString strFlagsKey = _T("Flags");
static const CString strShowCmdKey = _T("ShowCmd");
static const CString strRegEntryNameSizingBars = _T("\\SizingBars");
extern CObList gAllToolbars;
extern CObList gAllSizingControlBars;
//*************************************************************************************
BOOL CBCGWorkspace::UseWorkspaceManager(LPCTSTR lpszSectionName /*=NULL*/)
{
if(g_pWorkspace != NULL)
{
return FALSE; // already exists
}
g_pWorkspace = new CBCGWorkspace;
g_bWorkspaceAutocreated = TRUE; // Cleanup
if(lpszSectionName != NULL)
{
g_pWorkspace->m_strRegSection = lpszSectionName;
}
return TRUE;
}
//*************************************************************************************
LPCTSTR CBCGWorkspace::SetRegistryBase(LPCTSTR lpszSectionName /*= NULL*/)
{
m_strRegSection = (lpszSectionName != NULL) ?
lpszSectionName :
lpszSectionName;
return m_strRegSection;
}
//*************************************************************************************
CBCGWorkspace::CBCGWorkspace()
{
// ONLY ONE ALLOWED
ASSERT(g_pWorkspace == NULL);
g_pWorkspace = this;
const CString strRegEntryNameWorkspace = _T("BCGWorkspace");
m_strRegSection = strRegEntryNameWorkspace;
}
//*************************************************************************************
CBCGWorkspace::~CBCGWorkspace()
{
// NO OTHER !!
ASSERT(g_pWorkspace == this);
g_pWorkspace = NULL;
// Delete autocreated managers
if(m_bKeyboardManagerAutocreated && g_pKeyboardManager != NULL)
{
delete g_pKeyboardManager;
g_pKeyboardManager = NULL;
}
if (m_bContextMenuManagerAutocreated && g_pContextMenuManager != NULL)
{
delete g_pContextMenuManager;
g_pContextMenuManager = NULL;
}
if (m_bMouseManagerAutocreated && g_pMouseManager != NULL)
{
delete g_pMouseManager;
g_pMouseManager = NULL;
}
}
//*************************************************************************************
BOOL CBCGWorkspace::InitMouseManager()
{
if (g_pMouseManager != NULL)
{
ASSERT (FALSE);
return FALSE;
}
g_pMouseManager = new CBCGMouseManager;
m_bMouseManagerAutocreated = TRUE;
return TRUE;
}
//*************************************************************************************
BOOL CBCGWorkspace::InitContextMenuManager()
{
if (g_pContextMenuManager != NULL)
{
ASSERT (FALSE);
return FALSE;
}
g_pContextMenuManager = new CBCGContextMenuManager;
m_bContextMenuManagerAutocreated = TRUE;
return TRUE;
}
//*************************************************************************************
BOOL CBCGWorkspace::InitKeyboardManager()
{
if (g_pKeyboardManager != NULL)
{
ASSERT (FALSE);
return FALSE;
}
g_pKeyboardManager = new CBCGKeyboardManager;
m_bKeyboardManagerAutocreated = TRUE;
return TRUE;
}
//*************************************************************************************
CBCGMouseManager* CBCGWorkspace::GetMouseManager()
{
if (g_pMouseManager == NULL)
{
InitMouseManager ();
}
ASSERT_VALID (g_pMouseManager);
return g_pMouseManager;
}
//*************************************************************************************
CBCGContextMenuManager* CBCGWorkspace::GetContextMenuManager()
{
if (g_pContextMenuManager == NULL)
{
InitContextMenuManager();
}
ASSERT_VALID (g_pContextMenuManager);
return g_pContextMenuManager;
}
//*************************************************************************************
CBCGKeyboardManager* CBCGWorkspace::GetKeyboardManager()
{
if (g_pKeyboardManager == NULL)
{
InitKeyboardManager ();
}
ASSERT_VALID (g_pKeyboardManager);
return g_pKeyboardManager;
}
//*************************************************************************************
CString CBCGWorkspace::GetRegSectionPath(LPCTSTR szSectionAdd /*=NULL*/)
{
CString strSectionPath = ::BCGGetRegPath (m_strRegSection);
if (szSectionAdd != NULL && _tcslen (szSectionAdd) != 0)
{
strSectionPath += szSectionAdd;
strSectionPath += _T("\\");
}
return strSectionPath;
}
//*************************************************************************************
BOOL CBCGWorkspace::LoadState (LPCTSTR lpszSectionName /*=NULL*/, CBCGFrameImpl* pFrameImpl /*= NULL*/)
{
if (lpszSectionName != NULL)
{
m_strRegSection = lpszSectionName;
}
CString strSection = GetRegSectionPath ();
//-----------------------------
// Other things to do before ?:
//-----------------------------
PreLoadState();
//--------------------------------------
// Save general toolbar/menu parameters:
//--------------------------------------
CBCGToolBar::LoadParameters (strSection);
if (pFrameImpl != NULL)
{
//-----------------------------------------------------
// Load all toolbars, menubar and docking control bars:
//-----------------------------------------------------
for (POSITION posTlb = gAllToolbars.GetHeadPosition (); posTlb != NULL;)
{
CBCGToolBar* pToolBar = (CBCGToolBar*) gAllToolbars.GetNext (posTlb);
ASSERT (pToolBar != NULL);
if (CWnd::FromHandlePermanent (pToolBar->m_hWnd) != NULL)
{
ASSERT_VALID(pToolBar);
if (!pToolBar->m_bLocked &&
!pFrameImpl->IsUserDefinedToolbar(pToolBar))
{
pToolBar->LoadState (strSection);
}
}
}
for (POSITION posCb = gAllSizingControlBars.GetHeadPosition (); posCb != NULL;)
{
CBCGSizingControlBar* pBar = (CBCGSizingControlBar*) gAllSizingControlBars.GetNext (posCb);
ASSERT (pBar != NULL);
if (CWnd::FromHandlePermanent (pBar->m_hWnd) != NULL)
{
ASSERT_VALID (pBar);
pBar->LoadState (m_strRegSection + strRegEntryNameSizingBars);
}
}
//----------------------------
// Load user defined toolbars:
//----------------------------
pFrameImpl->LoadUserToolbars ();
CDockState dockState;
dockState.LoadState(m_strRegSection + strRegEntryNameControlBars);
if (pFrameImpl->IsDockStateValid (dockState))
{
pFrameImpl->m_pFrame->SetDockState (dockState);
}
//-------------------
// Load rebars state:
//-------------------
CBCGRebarState::LoadState (strSection, pFrameImpl->m_pFrame);
}
//--------------------------------------
// Load mouse/keyboard/menu managers:
//--------------------------------------
if (g_pMouseManager != NULL)
{
g_pMouseManager->LoadState (strSection);
}
if (g_pContextMenuManager != NULL)
{
g_pContextMenuManager->LoadState(strSection);
}
if (g_pKeyboardManager != NULL)
{
g_pKeyboardManager->LoadState (strSection,
pFrameImpl == NULL ? NULL : pFrameImpl->m_pFrame);
}
//----------
// Call Hook
//----------
LoadCustomState();
return true;
}
//*************************************************************************************
BOOL CBCGWorkspace::LoadState (CBCGMDIFrameWnd* pFrame, LPCTSTR lpszSectionName /*=NULL*/)
{
ASSERT_VALID (pFrame);
return LoadState (lpszSectionName, &pFrame->m_Impl);
}
//*************************************************************************************
BOOL CBCGWorkspace::LoadState (CBCGFrameWnd* pFrame, LPCTSTR lpszSectionName /*=NULL*/)
{
ASSERT_VALID (pFrame);
return LoadState (lpszSectionName, &pFrame->m_Impl);
}
//***********************************************************************************
BOOL CBCGWorkspace::LoadState (CBCGOleIPFrameWnd* pFrame, LPCTSTR lpszSectionName /*=NULL*/)
{
ASSERT_VALID (pFrame);
return LoadState (lpszSectionName, &pFrame->m_Impl);
}
//*************************************************************************************
BOOL CBCGWorkspace::CleanState (LPCTSTR lpszSectionName /*=NULL*/)
{
if (lpszSectionName != NULL)
{
m_strRegSection = lpszSectionName;
}
CString strSection = GetRegSectionPath ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -