OAMFrameWnd.cpp
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:5k
- // OAMFrameWnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OAMFrameWnd.h"
- #include "OAMDockBar.h"
- #include "OAMSizeDockBar.h"
- #include "OAMControlBar.h"
- #include "OAMMiniDockFrameWnd.h"
- //#include "ChangeAgent.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // COAMFrameWnd
- extern DWORD dwSizeBarMap[4][2];
- COAMFrameWnd::COAMFrameWnd()
- {
- for (int i = 0; i < 4; ++i)
- m_aInitialSize[i] = 0;
- }
- COAMFrameWnd::~COAMFrameWnd()
- {
- // TODO: add destruction code here.
- }
- IMPLEMENT_DYNCREATE(COAMFrameWnd, CFrameWnd)
- BEGIN_MESSAGE_MAP(COAMFrameWnd, CFrameWnd)
- ON_WM_INITMENU()
- //{{AFX_MSG_MAP(COAMFrameWnd)
- // ON_COMMAND(ID_SETAGENT, OnSetagent)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // COAMFrameWnd message handlers
- // dwDockBarMap
- DWORD COAMFrameWnd::dwDockBarMap[4][2] =
- {
- { AFX_IDW_DOCKBAR_TOP, CBRS_TOP },
- { AFX_IDW_DOCKBAR_BOTTOM, CBRS_BOTTOM },
- { AFX_IDW_DOCKBAR_LEFT, CBRS_LEFT },
- { AFX_IDW_DOCKBAR_RIGHT, CBRS_RIGHT },
- };
- void COAMFrameWnd::DockControlBarLeftOf(CControlBar* Bar, CControlBar* LeftOf)
- {
- CRect rect;
- DWORD dw;
- UINT n;
-
- // get MFC to adjust the dimensions of all docked ToolBars
- // so that GetWindowRect will be accurate
- RecalcLayout(TRUE);
-
- LeftOf->GetWindowRect(&rect);
- rect.OffsetRect(1,0);
- dw=LeftOf->GetBarStyle();
- n = 0;
- n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
- n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
- n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
- n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
-
- // When we take the default parameters on rect, DockControlBar will dock
- // each Toolbar on a seperate line. By calculating a rectangle, we in effect
- // are simulating a Toolbar being dragged to that location and docked.
- DockControlBar(Bar,n,&rect);
- }
- void COAMFrameWnd::EnableDocking(DWORD dwDockStyle)
- {
- // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
- // ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
- CFrameWnd::EnableDocking(dwDockStyle);
-
- for (int i = 0; i < 4; i++) {
- if (dwDockBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY) {
- CDockBar* pDock = (CDockBar*)GetControlBar(dwDockBarMap[i][0]);
-
- // make sure the dock bar is of correct type
- if( pDock || !pDock->IsKindOf(RUNTIME_CLASS(COAMDockBar)) ) {
- BOOL bNeedDelete = ! pDock->m_bAutoDelete;
- pDock->m_pDockSite->RemoveControlBar(pDock);
- pDock->m_pDockSite = 0; // avoid problems in destroying the dockbar
- pDock->DestroyWindow();
- if( bNeedDelete )
- delete pDock;
- pDock = 0;
- }
-
- if( pDock == 0 ) {
- pDock = new COAMDockBar;
- if (!pDock->Create(this,
- WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
- dwDockBarMap[i][1], dwDockBarMap[i][0])) {
- AfxThrowResourceException();
- }
- }
- }
- }
- }
- void COAMFrameWnd::RecalcLayout(BOOL bNotify)
- {
- CFrameWnd::RecalcLayout(bNotify);
- RecalcAllExcept(NULL);
- }
- void COAMFrameWnd::EnableDockingSizeBar(DWORD dwDockStyle)
- {
- // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
- // ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
- m_pFloatingFrameClass = RUNTIME_CLASS(COAMMiniDockFrameWnd);
- for (int i = 0; i < 4; i++)
- {
- if (dwSizeBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY)
- {
- COAMSizeDockBar* pDock = (COAMSizeDockBar*)GetControlBar(dwSizeBarMap[i][0]);
- if (pDock == NULL)
- {
- pDock = new COAMSizeDockBar;
- if( m_aInitialSize[i] )
- pDock->SetActualSize(m_aInitialSize[i]);
- if (!pDock->Create(this,
- WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
- dwSizeBarMap[i][1], dwSizeBarMap[i][0]))
- {
- AfxThrowResourceException();
- }
- }
- }
- }
- }
- void COAMFrameWnd::RecalcAllExcept(COAMSizeDockBar *pBar)
- {
- for (int i = 0; i < 4; i++)
- {
- COAMSizeDockBar* pDock = (COAMSizeDockBar*)GetControlBar(dwSizeBarMap[i][0]);
- if (pDock != NULL && pDock != pBar)
- {
- pDock->CalcSizeBarLayout();
- }
- }
- }
- void COAMFrameWnd::SetInitialSize(int top, int bottom, int left, int right)
- {
- m_aInitialSize[2] = top;
- m_aInitialSize[3] = bottom;
- m_aInitialSize[0] = left;
- m_aInitialSize[1] = right;
- }
- void COAMFrameWnd::DockSizeBar(CControlBar * pBar,COAMSizeDockBar *pDockBar, LPRECT lpRect)
- {
- // ASSERT(pBar != NULL);
- // ASSERT(pBar->m_pDockContext != NULL);
-
- if( pDockBar == NULL )
- {
- for (int i = 0; i < 4; i++)
- {
- if ((dwSizeBarMap[i][1] & CBRS_ALIGN_ANY) ==
- (pBar->m_dwStyle & CBRS_ALIGN_ANY))
- {
- pDockBar = (COAMSizeDockBar*)GetControlBar(dwSizeBarMap[i][0]);
- // ASSERT(pDockBar != NULL);
- break;
- }
- }
- }
-
- // ASSERT(pDockBar != NULL);
- // ASSERT(m_listControlBars.Find(pBar) != NULL);
- // ASSERT(pBar->m_pDockSite == this);
- ((COAMControlBar*)pBar)->Normalize();
- pDockBar->DockControlBar(pBar, lpRect);
- }