//------------------------------------------------------------------------------
// $Workfile: DockPaneController.cpp $
// $Header: /SbjDev/SbjCore/DockPaneController.cpp 15 10/14/08 1:12p Steve $
//
// Copyright � 2008 SbjCat
// All rights reserved.
//
//
// *** Authors ***
// Steve Johnson
//
// $Revision: 15 $
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "DockPaneController.h"
#include "WndMsgHandler.h"
#include "SetResourceModule.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
namespace localNS
{
class ToolBar : public CMFCToolBar
{
public:
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
pTarget;
CMFCToolBar::OnUpdateCmdUI((CFrameWnd*) GetOwner (), bDisableIfNoHndler);
}
virtual BOOL AllowShowOnList() const
{
return FALSE;
}
};
class OnCreateHandler : public SbjCore::Mvc::WndMsgHandler
{
CALL_DEFAULT_FIRST()
virtual LRESULT OnHandleWndMsg(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
wParam;
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
CCreateContext* pContext = (CCreateContext*)lpcs->lpCreateParams;
*pResult = 0;
LRESULT lRslt = -1;
SbjCore::Mvc::DockPaneController* pBar = (SbjCore::Mvc::DockPaneController*)GetController();
if ((pBar != NULL) && pBar->CreateClient(lpcs, pContext))
{
pBar->AdjustLayout();
lRslt = 0;
}
return lRslt;
}
};
class OnSizeHandler : public SbjCore::Mvc::WndMsgHandler
{
CALL_DEFAULT_FIRST()
virtual LRESULT OnHandleWndMsg(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
wParam;
lParam;
*pResult = 0;
LRESULT lRslt = 1;
SbjCore::Mvc::DockPaneController* pBar = (SbjCore::Mvc::DockPaneController*)GetController();
pBar->AdjustLayout();
return lRslt;
}
};
class OnEraseBkgndHandler : public SbjCore::Mvc::WndMsgHandler
{
virtual LRESULT OnHandleWndMsg(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
wParam;
lParam;
*pResult = 0;
LRESULT lRslt = 1;
SbjCore::Mvc::WndController* pCtrlr = GetController();
CWnd* pWnd = pCtrlr->GetWnd();
CPaintDC* pDC = (CPaintDC*)pWnd->GetDC();
CRect rect;
pWnd->GetClientRect(rect);
pDC->FillSolidRect(&rect, ::GetSysColor (COLOR_3DSHADOW));
return lRslt;
}
};
class SetFocusHandler : public SbjCore::Mvc::WndMsgHandler
{
//CALL_DEFAULT_FIRST() // comment out to handle message before default
virtual LRESULT OnHandleWndMsg(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
wParam;
lParam;
*pResult = 0;
LRESULT lRslt = 1;
SbjCore::Mvc::WndController* pCtrlr = dynamic_cast<SbjCore::Mvc::WndController*>(GetController());
if (pCtrlr != NULL)
{
CWnd* pChildWnd = pCtrlr->GetWnd()->GetDlgItem(AFX_IDW_PANE_FIRST);
if (pChildWnd != NULL)
{
pChildWnd->SetFocus();
}
}
return lRslt;
}
};
}
namespace SbjCore
{
namespace Mvc
{
struct DockPaneControllerImpl
{
localNS::ToolBar theToolBar;
localNS::OnCreateHandler theOnCreateHandler;
localNS::OnSizeHandler theOnSizeHandler;
localNS::OnEraseBkgndHandler theOnEraseBkgndHandler;
localNS::SetFocusHandler theSetFocusHandler;
DockPaneControllerImpl()
{
}
virtual ~DockPaneControllerImpl()
{
}
};
/////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(DockPaneController, WndController)
DockPaneController::DockPaneController() :
m_pImpl(new DockPaneControllerImpl)
{
AddHandler(WM_CREATE, &m_pImpl->theOnCreateHandler);
AddHandler(WM_SIZE, &m_pImpl->theOnSizeHandler);
AddHandler(WM_ERASEBKGND, &m_pImpl->theOnEraseBkgndHandler);
AddHandler(WM_SETFOCUS, &m_pImpl->theSetFocusHandler);
}
DockPaneController::~DockPaneController()
{
try
{
delete m_pImpl;
}
catch (...)
{
ASSERT(FALSE);
}
}
BOOL DockPaneController::CreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
bool bRslt = false;
UINT nToolBarImageID = 0;
HINSTANCE hResInst = GetResourceHandle();
UINT nToolBarID = GetToolBarID(nToolBarImageID);
if (nToolBarID > 0)
{
if (hResInst == 0)
{
hResInst = ::AfxGetResourceHandle();
}
Utils::SetResourceModule theResModule(hResInst);
m_pImpl->theToolBar.Create (GetWnd(), AFX_DEFAULT_TOOLBAR_STYLE, nToolBarID);
bRslt = m_pImpl->theToolBar.LoadToolBar (nToolBarID, 0, 0, TRUE );
m_pImpl->theToolBar.CleanUpLockedImages ();
bRslt = m_pImpl->theToolBar.LoadBitmap (nToolBarImageID, 0, 0, TRUE );
m_pImpl->theToolBar.SetPaneStyle(m_pImpl->theToolBar.GetPaneStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY);
m_pImpl->theToolBar.SetPaneStyle (
m_pImpl->theToolBar.GetPaneStyle () &
~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
m_pImpl->theToolBar.SetOwner (GetWnd());
// All commands will be routed via this control , not via the parent frame:
m_pImpl->theToolBar.SetRouteCommandsViaFrame (FALSE);
}
return OnCreateClient(lpcs, pContext);
}
void DockPaneController::AdjustLayout()
{
(void)OnAdjustLayout();
}
UINT DockPaneController::GetToolBarID(UINT& nToolBarImageID) const
{
return OnGetToolBarID(nToolBarImageID);
}
HINSTANCE DockPaneController::GetResourceHandle() const
{
return OnGetResourceHandle();
}
int DockPaneController::OnAdjustLayout(int nTop /*= 0*/)
{
int nTopOffset = 0;
CWnd* pWnd = GetWnd();
if ((pWnd != NULL) && (pWnd->GetSafeHwnd() != NULL))
{
CRect rectClient;
pWnd->GetClientRect(rectClient);
if (m_pImpl->theToolBar.GetSafeHwnd() != NULL)
{
nTopOffset = m_pImpl->theToolBar.CalcFixedLayout (FALSE, TRUE).cy;
m_pImpl->theToolBar.SetWindowPos (NULL,
rectClient.left,
rectClient.top + nTop,
rectClient.Width(),
nTopOffset,
SWP_NOACTIVATE | SWP_NOZORDER);
}
}
return nTopOffset + nTop;
}
UINT DockPaneController::OnGetToolBarID(UINT& nToolBarImageID) const
{
nToolBarImageID = 0;
return 0;
}
HINSTANCE DockPaneController::OnGetResourceHandle() const
{
return 0;
}
bool DockPaneController::OnRoutCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo )
{
bool bRslt = false;
CWnd* pChildWnd = GetWnd()->GetDlgItem(AFX_IDW_PANE_FIRST);
if (pChildWnd != NULL)
{
bRslt = pChildWnd->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
return bRslt;
}
BOOL DockPaneController::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )
{
lpcs;
pContext;
ASSERT(FALSE);
return false;
}
}
}
//*** Modification History ***
// $Log: /SbjDev/SbjCore/DockPaneController.cpp $
//
// 15 10/14/08 1:12p Steve
// Implemented Deletes
//
// 14 9/23/08 11:23a Steve
//
// 13 9/23/08 10:37a Steve
// Keyword expansion works and comment format changed to "// "