GuiDocBarExtenEx.cpp
上传用户:wlkj888
上传日期:2022-08-01
资源大小:806k
文件大小:14k
- /****************************************************************************
- * *
- * GuiToolKit *
- * (MFC extension) *
- * Created by Francisco Campos G. www.beyondata.com fcampos@beyondata.com *
- *--------------------------------------------------------------------------*
- * *
- * This program is free software;so you are free to use it any of your *
- * applications (Freeware, Shareware, Commercial),but leave this header *
- * intact. *
- * *
- * These files are provided "as is" without warranty of any kind. *
- * *
- * GuiToolKit is forever FREE CODE !!!!! *
- * *
- *--------------------------------------------------------------------------*
- * Created by: Francisco Campos G. *
- * Bug Fixes and improvements : (Add your name) *
- * -Francisco Campos *
- * *
- ****************************************************************************/
- #include "stdafx.h"
- #include "GuiToolBarWnd.h"
- #include "GuiDocBarExtenEx.h"
- #include "GuiControlBar.h"
- #include "MenuBar.h"
- const int cxBorder2 = ::GetSystemMetrics(SM_CXBORDER)*2;
- const int cyBorder2 = ::GetSystemMetrics(SM_CYBORDER)*2;
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- IMPLEMENT_DYNCREATE(CGuiDocBarExtenEx,CDockBar)
- BEGIN_MESSAGE_MAP(CGuiDocBarExtenEx,CDockBar)
- //{{AFX_MSG_MAP(CGuiDocBarExtenEx)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- CGuiDocBarExtenEx::CGuiDocBarExtenEx()
- {
- m_StyleDisplay=GUISTYLE_XP;
- }
- CGuiDocBarExtenEx::~CGuiDocBarExtenEx()
- {
-
-
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDockBarEx message handlers
- BOOL CGuiDocBarExtenEx::_IsMenuBar(int nPos, CPtrArray& arrBars)
- {
- if (nPos < arrBars.GetSize()) {
- CControlBar* pBar = (CControlBar*)arrBars[nPos];
- if (pBar && pBar->GetDlgCtrlID() == AFX_IDW_MENUBAR)
- return TRUE;
- else
- return FALSE;
- }
- else
- return FALSE;
- }
- void CGuiDocBarExtenEx::BarsDocking(CFrameWnd * pFrame, DWORD dwDockStyle)
- {
- ASSERT_VALID(pFrame);
- // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
- ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
- pFrame->EnableDocking(dwDockStyle);
- for (int i = 0; i < 4; i++) {
- if (dwDockBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY) {
- CDockBar* pDock = (CDockBar*)pFrame->GetControlBar(dwDockBarMap[i][0]);
- if( pDock == 0 || ! pDock->IsKindOf(RUNTIME_CLASS(CGuiDocBarExtenEx)) ) {
- BOOL bNeedDelete = ! pDock->m_bAutoDelete;
- pDock->m_pDockSite->RemoveControlBar(pDock);
- pDock->m_pDockSite = 0;
- pDock->DestroyWindow();
- if( bNeedDelete )
- delete pDock;
- pDock = 0;
- }
- if( pDock == 0 ) {
- pDock = new CGuiDocBarExtenEx;
- ASSERT_VALID(pDock);
- if ((!pDock) || (!pDock->Create(pFrame,
- WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
- dwDockBarMap[i][1], dwDockBarMap[i][0]))) {
- AfxThrowResourceException();
- }
- }
- }
- }
- }
- CSize CGuiDocBarExtenEx::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
- {
- ASSERT_VALID(this);
- CSize sizeFixed = CControlBar::CalcFixedLayout(bStretch, bHorz);
-
- // get max size
- CSize sizeMax;
- if (!m_rectLayout.IsRectEmpty())
- {
- CRect rect = m_rectLayout;
- CalcInsideRect(rect, bHorz);
- sizeMax = rect.Size();
- }
- else
- {
- CRect rectFrame;
- CFrameWnd* pFrame = GetParentFrame();
- pFrame->GetClientRect(&rectFrame);
- sizeMax = rectFrame.Size();
- }
- // prepare for layout
- AFX_SIZEPARENTPARAMS layout;
- layout.hDWP = m_bLayoutQuery ?
- NULL : ::BeginDeferWindowPos(m_arrBars.GetSize());
- int cxBorder = 2, cyBorder = 2;
- CPoint pt(-cxBorder, -cyBorder);
- int nWidth = 0;
- BOOL bWrapped = FALSE;
- // layout all the control bars
- for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++)
- {
- CControlBar* pBar = GetDockedControlBar(nPos);
- if (HIWORD(pBar) != 0)
- if (pBar->IsKindOf(RUNTIME_CLASS(CGuiControlBar)))
- {
- CGuiControlBar* pbar=(CGuiControlBar*)pBar;
- CPoint pt(GetMessagePos());
- //m_pDockSite->FloatControlBar(pBar,pt);
- // pbar->ReleaseCapture();
- //m_pDockContext->ToggleDocking();
- m_pDockSite->DockControlBar(pBar);
- continue;
- }
- void* pVoid = m_arrBars[nPos];
- if (pBar != NULL)
- {
- if(pBar->IsKindOf(RUNTIME_CLASS(CGuiToolBarWnd)) ||
- pBar->IsKindOf(RUNTIME_CLASS(CMenuBar)) )
- cxBorder = cyBorder = 0;
- else
- cxBorder = cyBorder = 2;
- if (pBar->IsVisible())
- {
- // get ideal rect for bar
- DWORD dwMode = 0;
- if ((pBar->m_dwStyle & CBRS_SIZE_DYNAMIC) &&
- (pBar->m_dwStyle & CBRS_FLOATING))
- dwMode |= LM_HORZ | LM_MRUWIDTH;
- else if (pBar->m_dwStyle & CBRS_ORIENT_HORZ)
- dwMode |= LM_HORZ | LM_HORZDOCK;
- else
- dwMode |= LM_VERTDOCK;
- CSize sizeBar = pBar->CalcDynamicLayout(-1, dwMode);
- CRect rect(pt, sizeBar);
- // get current rect for bar
- CRect rectBar;
- pBar->GetWindowRect(&rectBar);
- ScreenToClient(&rectBar);
- if (bHorz)
- {
- // Offset Calculated Rect out to Actual
- if (rectBar.left > rect.left && !m_bFloating)
- rect.OffsetRect(rectBar.left - rect.left, 0);
- // If ControlBar goes off the right, then right justify
- if (rect.right > sizeMax.cx && !m_bFloating)
- {
- int x = rect.Width() - cxBorder;
- x = max(sizeMax.cx - x, pt.x);
- rect.OffsetRect(x - rect.left, 0);
- }
- // If ControlBar has been wrapped, then left justify
- if (bWrapped)
- {
- bWrapped = FALSE;
- rect.OffsetRect(-(rect.left + cxBorder), 0);
- }
- // If ControlBar is completely invisible, then wrap it
- else if ((rect.left >= (sizeMax.cx - cxBorder2) || _IsMenuBar(nPos, m_arrBars))
- && (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
- {
- m_arrBars.InsertAt(nPos, (CObject*)NULL);
- pBar = NULL; pVoid = NULL;
- bWrapped = TRUE;
- }
- if (!bWrapped)
- {
- if (rect != rectBar)
- {
- if (!m_bLayoutQuery &&
- !(pBar->m_dwStyle & CBRS_FLOATING))
- {
- pBar->m_pDockContext->m_rectMRUDockPos = rect;
- }
- AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
- }
- pt.x = rect.left + sizeBar.cx - cxBorder;
- nWidth = max(nWidth, sizeBar.cy);
- }
- }
- else
- {
- // Offset Calculated Rect out to Actual
- if (rectBar.top > rect.top && !m_bFloating)
- rect.OffsetRect(0, rectBar.top - rect.top);
- // If ControlBar goes off the bottom, then bottom justify
- if (rect.bottom > sizeMax.cy && !m_bFloating)
- {
- int y = rect.Height() - cyBorder;
- y = max(sizeMax.cy - y, pt.y);
- rect.OffsetRect(0, y - rect.top);
- }
- // If ControlBar has been wrapped, then top justify
- if (bWrapped)
- {
- bWrapped = FALSE;
- rect.OffsetRect(0, -(rect.top + cyBorder));
- }
- // If ControlBar is completely invisible, then wrap it
- else if ((rect.left >= (sizeMax.cx - cxBorder2) || _IsMenuBar(nPos, m_arrBars))
- && (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
- {
- m_arrBars.InsertAt(nPos, (CObject*)NULL);
- pBar = NULL; pVoid = NULL;
- bWrapped = TRUE;
- }
- if (!bWrapped)
- {
- if (rect != rectBar)
- {
- if (!m_bLayoutQuery &&
- !(pBar->m_dwStyle & CBRS_FLOATING))
- {
- pBar->m_pDockContext->m_rectMRUDockPos = rect;
- }
- AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
- }
- pt.y = rect.top + sizeBar.cy - cyBorder;
- nWidth = max(nWidth, sizeBar.cx);
- }
- }
- }
- if (!bWrapped)
- {
- // handle any delay/show hide for the bar
- pBar->RecalcDelayShow(&layout);
- }
- }
- if (pBar == NULL && pVoid == NULL && nWidth != 0)
- {
- // end of row because pBar == NULL
- if (bHorz)
- {
- pt.y += nWidth - cyBorder;
- sizeFixed.cx = max(sizeFixed.cx, pt.x);
- sizeFixed.cy = max(sizeFixed.cy, pt.y);
- pt.x = -cxBorder;
- }
- else
- {
- pt.x += nWidth - cxBorder;
- sizeFixed.cx = max(sizeFixed.cx, pt.x);
- sizeFixed.cy = max(sizeFixed.cy, pt.y);
- pt.y = -cyBorder;
- }
- nWidth = 0;
- }
- }
- if (!m_bLayoutQuery)
- {
- // move and resize all the windows at once!
- if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP))
- TRACE0("Warning: DeferWindowPos failed - low system resources.n");
- }
- // adjust size for borders on the dock bar itself
- CRect rect;
- rect.SetRectEmpty();
- CalcInsideRect(rect, bHorz);
- if ((!bStretch || !bHorz) && sizeFixed.cx != 0)
- sizeFixed.cx += -rect.right + rect.left;
- if ((!bStretch || bHorz) && sizeFixed.cy != 0)
- sizeFixed.cy += -rect.bottom + rect.top;
- return sizeFixed;
- }
- /*CSize CGuiDocBarExtenEx::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
- {
- // LTRACE(_T("CMenuDockBar::CalcFixedLayoutn"));
- ASSERT_VALID(this);
- CSize sizeFixed = CControlBar::CalcFixedLayout(bStretch, bHorz);
- // get max size
- CSize sizeMax;
- if (!m_rectLayout.IsRectEmpty())
- sizeMax = m_rectLayout.Size();
- else
- {
- CRect rectFrame;
- CFrameWnd* pFrame = GetParentFrame();
- pFrame->GetClientRect(&rectFrame);
- sizeMax = rectFrame.Size();
- }
- // prepare for layout
- AFX_SIZEPARENTPARAMS layout;
- layout.hDWP = m_bLayoutQuery ?
- NULL : ::BeginDeferWindowPos(m_arrBars.GetSize());
- CPoint pt(-cxBorder2, -cyBorder2);
- int nWidth = 0;
- BOOL bWrapped = FALSE;
- // layout all the control bars
- for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++)
- {
- CControlBar* pBar = GetDockedControlBar(nPos);
- void* pVoid = m_arrBars[nPos];
- if (pBar != NULL)// pBar is valid
- {
- if (pBar->IsVisible())// visible
- {
- // get ideal rect for bar
- DWORD dwMode = 0;
- if ((pBar->m_dwStyle & CBRS_SIZE_DYNAMIC) &&
- (pBar->m_dwStyle & CBRS_FLOATING))
- dwMode |= LM_HORZ | LM_MRUWIDTH;
- else if (pBar->m_dwStyle & CBRS_ORIENT_HORZ)
- dwMode |= LM_HORZ | LM_HORZDOCK;
- else
- dwMode |= LM_VERTDOCK;
- CSize sizeBar = pBar->CalcDynamicLayout(-1, dwMode);
- CRect rect(pt, sizeBar);
- // get current rect for bar
- CRect rectBar;
- pBar->GetWindowRect(&rectBar);
- ScreenToClient(&rectBar);
- if (bHorz)// horizontal
- {
- // Offset Calculated Rect out to Actual
- if (rectBar.left > rect.left && !m_bFloating)
- rect.OffsetRect(rectBar.left - rect.left, 0);
- // If ControlBar goes off the right, then right justify
- if (rect.right > sizeMax.cx && !m_bFloating)
- {
- int x = rect.Width() - cxBorder2;
- x = max(sizeMax.cx - x, pt.x);
- rect.OffsetRect(x - rect.left, 0);
- }
- // If ControlBar has been wrapped, then left justify
- if (bWrapped)
- {
- bWrapped = FALSE;
- rect.OffsetRect(-(rect.left + cxBorder2), 0);
- }
- // If ControlBar is completely invisible, then wrap it
- else if ((rect.left >= (sizeMax.cx - cxBorder2) || _IsMenuBar(nPos, m_arrBars))
- && (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
- {
- m_arrBars.InsertAt(nPos, (CObject*)NULL);
- pBar = NULL; pVoid = NULL;
- bWrapped = TRUE;
- }
- if (!bWrapped)
- {
- if (rect != rectBar)
- {
- if (!m_bLayoutQuery &&
- !(pBar->m_dwStyle & CBRS_FLOATING))
- {
- pBar->m_pDockContext->m_rectMRUDockPos = rect;
- }
- AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
- }
- pt.x = rect.left + sizeBar.cx - cxBorder2;
- nWidth = max(nWidth, sizeBar.cy);
- }
- }
- else // vertical
- {
- // Offset Calculated Rect out to Actual
- if (rectBar.top > rect.top && !m_bFloating)
- rect.OffsetRect(0, rectBar.top - rect.top);
- // If ControlBar goes off the bottom, then bottom justify
- if (rect.bottom > sizeMax.cy && !m_bFloating)
- {
- int y = rect.Height() - cyBorder2;
- y = max(sizeMax.cy - y, pt.y);
- rect.OffsetRect(0, y - rect.top);
- }
- // If ControlBar has been wrapped, then top justify
- if (bWrapped)
- {
- bWrapped = FALSE;
- rect.OffsetRect(0, -(rect.top + cyBorder2));
- }
- // If ControlBar is completely invisible, then wrap it
- else if ((rect.top >= (sizeMax.cy - cyBorder2) || _IsMenuBar(nPos, m_arrBars))
- && (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
- {
- m_arrBars.InsertAt(nPos, (CObject*)NULL);
- pBar = NULL; pVoid = NULL;
- bWrapped = TRUE;
- }
- if (!bWrapped)
- {
- if (rect != rectBar)
- {
- if (!m_bLayoutQuery &&
- !(pBar->m_dwStyle & CBRS_FLOATING))
- {
- pBar->m_pDockContext->m_rectMRUDockPos = rect;
- }
- AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
- }
- pt.y = rect.top + sizeBar.cy - cyBorder2;
- nWidth = max(nWidth, sizeBar.cx);
- }
- }// if vertical
- }// if visible
- if (!bWrapped)
- {
- // handle any delay/show hide for the bar
- pBar->RecalcDelayShow(&layout);
- }
- }// if pBar is valid
- if (pBar == NULL && pVoid == NULL && nWidth != 0)
- {
- // end of row because pBar == NULL
- if (bHorz)
- {
- pt.y += nWidth - cyBorder2;
- sizeFixed.cx = max(sizeFixed.cx, pt.x);
- sizeFixed.cy = max(sizeFixed.cy, pt.y);
- pt.x = -cxBorder2;
- }
- else
- {
- pt.x += nWidth - cxBorder2;
- sizeFixed.cx = max(sizeFixed.cx, pt.x);
- sizeFixed.cy = max(sizeFixed.cy, pt.y);
- pt.y = -cyBorder2;
- }
- nWidth = 0;
- }
- }// for
- if (!m_bLayoutQuery)
- {
- // move and resize all the windows at once!
- if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP))
- TRACE0("Warning: DeferWindowPos failed - low system resources.n");
- }
- // adjust size for borders on the dock bar itself
- CRect rect;
- rect.SetRectEmpty();
- CalcInsideRect(rect, bHorz);
- if ((!bStretch || !bHorz) && sizeFixed.cx != 0)
- sizeFixed.cx += -rect.right + rect.left;
- if ((!bStretch || bHorz) && sizeFixed.cy != 0)
- sizeFixed.cy += -rect.bottom + rect.top;
- return sizeFixed;
- }*/
- void CGuiDocBarExtenEx::DoPaint(CDC* pDC)
- {
- CRect rect;
- GetClientRect(rect);
- CBrush cbr;
- cbr.CreateSolidBrush(GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style));
- pDC->FillRect(rect,&cbr);
- }