Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Bug and Suggestion for CXTTabCtrl
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Bug and Suggestion for CXTTabCtrl

 Post Reply Post Reply
Author
Message
AndyS View Drop Down
Groupie
Groupie


Joined: 15 December 2004
Location: United Kingdom
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyS Quote  Post ReplyReply Direct Link To This Post Topic: Bug and Suggestion for CXTTabCtrl
    Posted: 18 February 2005 at 1:33pm

I have a drawing app with a tab view which contains multiple pages. Each page represents some facet of the selected items in the current document (e.g. a text formatiing page, fill, outline etc etc). As the user selects different items the appropriate pages are slotted into and out of the tab view.

There was a lot of window flashing so I looked into the code. The problem is in the "DeleteView" Method in "CXTTabCtrlBaseEx" which is resetting the active view incorrectly on view delete. There is no code release number in the file but it's downloaded as of about one month ago.

The code comments indicates that the view is switched if the active view is being deleted but in fact no check is made and the active view is always updated. The effect is that the active page jumps left with each iteration and of course the windows flash as the active page is changed quickly in succession as pages are added and removed. The fix is to flag whether this is really a deletion of the active page (before the delete call) and gate the active view update so it is only done when actually needed.

I've attached the fixed function but I can;t seem to format it in this browser.

It would also be nice to have an "AddControl" option to not update the active view to the newly added control page. Where pages are being slotted in quietly I don't necessarily want them to become active.

void CMTBRoutesPropertyView::DeleteViewEx(int nView, BOOL bDestroyWnd/*=TRUE*/)

{

ASSERT_VALID(m_pTabCtrl);

ASSERT(( nView >= 0 ) && (m_pTabCtrl->GetItemCount() > nView));

// Now find the view we want to delete and remove it

POSITION pos = m_tcbItems.FindIndex(nView);

if (pos != NULL)

{

CWnd* pView = m_tcbItems.GetAt(pos)->pWnd;

// AJS - Quick fix to detect deletion of the active view

bool bActiveView = (pView == GetActiveView());

// Ensure that we get no dangling pointers

if (m_pParentFrame && m_pParentFrame->GetActiveView() == pView)

{

if (m_pLastActiveView && ::IsWindow(m_pLastActiveView->m_hWnd)) {

m_pParentFrame->SetActiveView(m_pLastActiveView);

}

else {

m_pParentFrame->SetActiveView(NULL, FALSE);

m_pLastActiveView = NULL;

}

}

// Remove item from list, and free memory.

RemoveListItem( pos, bDestroyWnd );

// Remove it from the tab control

m_pTabCtrl->DeleteItem(nView);

int nCount = m_pTabCtrl->GetItemCount();

// AJS - Added bActiveView to leave well alone if deleting non-active views

if (bActiveView && (nCount > 0))

{

// Finally, if we have just deleted the active view, reset the

// active tab to be the first view in the list

if (nView == 0) {

SetActiveView(nView);

}

else if (nView >= nCount) {

SetActiveView(nCount-1);

}

else {

// AJS - Quick fix to force reselection of the same view ID. Previously

// this reset the active view to nView-1 which (assuming we are deleting

// the active view) bumps us to the next view to the left. Why is this

// any better than the one to the right which will now occupy our space

// so is marginally less jumpy on screen.

SetActiveView(nView);

}

// Reset the tooltips for the views we have left...

ResetToolTips();

}

}

}

 

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.031 seconds.