detect docking / floating state in OnSize?
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=15224
Printed Date: 27 February 2025 at 2:55pm Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: detect docking / floating state in OnSize?
Posted By: Michl
Subject: detect docking / floating state in OnSize?
Date Posted: 22 September 2009 at 12:27pm
Hello,
we using Codejock v11.22. Perhaps it was already changed... or is this code okay?
How can I detect that my docked toolbar is now in floating state in OnSize??
If a user move a dockingable toolbar, following code will be called:
void CXTPDockContext::Move(CPoint pt) { ...
if (!bDocked && (dwFlags & xtpFlagFloating))
{ if (m_pBar->GetPosition() != xtpBarFloating) { pCommandBars->FloatCommandBar(m_pBar); CSize sz = m_pBar->CalcDynamicLayout(0, LM_HORZ | LM_MRUWIDTH | LM_COMMIT); m_rectDragFrame = CRect(m_rectDragFrame.TopLeft(), sz); AdjustRectangle(m_rectDragFrame, pt); } EnsureVisible(m_rectDragFrame); m_pBar->MoveWindow(m_rectDragFrame); } }
|
[code} BOOL CXTPCommandBars::FloatCommandBar(CXTPToolBar* pBar) { if (!pBar->Create(m_pFrame, TRUE)) { return FALSE; } if (pBar->m_pDockBar != NULL) { pBar->m_pDockBar->RemoveCommandBar(pBar); pBar->m_pDockBar = NULL;
} pBar->m_barPosition = xtpBarFloating;
return TRUE; } [/code]
BOOL CXTPDockBar::RemoveCommandBar(CXTPToolBar* pBar, int nPosExclude) { ASSERT_VALID(this); ASSERT(pBar != NULL); if (!pBar) return FALSE;
int nPos = FindBar(pBar, nPosExclude); ASSERT(nPos > 0); if (nPos <= 0) return FALSE;
m_arrBars.RemoveAt(nPos); if (m_arrBars[nPos-1] == NULL && m_arrBars[nPos] == NULL) m_arrBars.RemoveAt(nPos);
pBar->m_pDockBar = NULL;
// get parent frame for recalc layout/frame destroy m_pCommandBars->RecalcFrameLayout(TRUE);
return TRUE; }
|
void CXTPCommandBars::RecalcFrameLayout(BOOL bDelay) { if (m_bRecalcLayout) return;
if (!m_pFrame->GetSafeHwnd()) return;
CFrameWnd* pFrame = m_pFrame->IsFrameWnd() ? (CFrameWnd*)m_pFrame : NULL; if (pFrame) { if (bDelay) pFrame->DelayRecalcLayout(FALSE); else pFrame->RecalcLayout(FALSE); } else { CXTPClientRect rc(m_pFrame); m_pFrame->SendMessage(WM_SIZE, 0, MAKELPARAM(rc.Width(), rc.Height())); } }
|
So I will be notified about a changing layout via OnSize, but I can't realign my controls because I don't have the actual state of Toolbar (it says it is already docked top, left, ...) I think its wrong to set the new state (blue line) after generating the message WM_SIZE. What do you mean?
Thanks for your opinion.
|
Replies:
Posted By: Oleg
Date Posted: 23 September 2009 at 3:49am
Hi,
Do you have your toolbars inside some frame or simple dialog?
strange - if its frame last line have not to be executed, if its dialog - toolbar can't be floated.
you can check if pToolBar->GetDockBar() return NULL - it means toolbar is floated.
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: Michl
Date Posted: 23 September 2009 at 5:50am
We use it inside a dialog. And it works fine... (inclusive floating)
Was it not planned to work inside dialogs???
You have right.
CFrameWnd* pFrame = m_pFrame->IsFrameWnd() ? (CFrameWnd*)m_pFrame : NULL;
|
pFrame is NULL in dialogs, so the else-case is executed.
Your're idea (to check GetDockBar() before I call GetPosition()) I already tried. But the problem is, so I get an flicker effect! (try to move a Toolbar inside a command bar. So OnSize will be called twice. First with GetDockBar() == NULL and second with GetDockBar() != NULL)
If I move the line, everything works fine...
BOOL CXTPCommandBars::FloatCommandBar(CXTPToolBar* pBar) { if (!pBar->Create(m_pFrame, TRUE)) { return FALSE; }
pBar->m_barPosition = xtpBarFloating;
if (pBar->m_pDockBar != NULL) { pBar->m_pDockBar->RemoveCommandBar(pBar); pBar->m_pDockBar = NULL;
}
return TRUE; }
|
But I think for compatibility that's the better solution:
BOOL CXTPCommandBars::FloatCommandBar(CXTPToolBar* pBar) { if (!pBar->Create(m_pFrame, TRUE)) { return FALSE; } if (pBar->m_pDockBar != NULL) { pBar->m_pDockBar->RemoveCommandBar(pBar);
pBar->m_barPosition = xtpBarFloating; pBar->m_pCommandBars->RecalcFrameLayout(TRUE);
pBar->m_pDockBar = NULL; //Is this neccessery? m_pDockBar will be set to NULL in RemoveCommandBar } else pBar->m_barPosition = xtpBarFloating;
return TRUE; }
|
Thats's my code. Or do you have a better way to resolve this problem? 
void CMyDialog::OnSize(UINT nType, int cx, int cy) { __super::OnSize(nType, cx, cy);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
if (m_TabCtrl.GetSafeHwnd() && m_pToolBar && m_pToolBar->GetSafeHwnd()) { CRect rectClient; GetClientRect( &rectClient );
CXTPEmptyRect rectToolBar; if (m_pToolBar->GetPosition() != xtpBarFloating) m_pToolBar->GetClientRect( &rectToolBar );
switch (m_pToolBar->GetPosition()) { case xtpBarLeft: rectClient.left += rectToolBar.Width(); rectClient.right -= rectToolBar.Width(); break;
case xtpBarTop: rectClient.top += rectToolBar.Height(); rectClient.bottom -= rectToolBar.Height(); break;
case xtpBarRight: rectClient.right -= rectToolBar.Width(); break;
case xtpBarBottom: rectClient.bottom -= rectToolBar.Height(); break; }
m_TabCtrl.MoveWindow( rectClient.left + 8, rectClient.top + 8, rectClient.right - 16, rectClient.bottom - 16 ); } }
|
|
Posted By: Oleg
Date Posted: 23 September 2009 at 8:54am
better call
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
to get current client rect.
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: Michl
Date Posted: 23 September 2009 at 10:08am
Okay. This code looks nicer. 
__super::OnSize(nType, cx, cy);
if (m_TabCtrl.GetSafeHwnd()) { CRect rcClientNow; RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
m_TabCtrl.MoveWindow( rcClientNow.left + 8, rcClientNow.top + 8, rcClientNow.Width() - 16, rcClientNow.Height() - 16 ); }
|
But this doesn't solve the problem if anyone likes to detect the current state in OnSize of a toolbar? Now, you never get the information about the toobar floating state. But I don't know if anyone would use/is missing this functionality...
|
|