wxFlatNotebook

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

Yes, wxNotebook also does not sends.
But I feel thing is wrong behavior, as each control can still handle EVT_CLOSE and do the processing in the event handler, but the event handler is never called, which is a deviation from the standard behavior of child controls.

Though there is a workaround:

Code: Select all

 	for(int i=0; i < m_pFlatNotebook->GetPageCount(); i++)
 	{
 		m_pFlatNotebook->GetPage(i)->Close();
 	}
	m_pFlatNotebook->Close();
But its messy
pete_b
Knows some wx things
Knows some wx things
Posts: 41
Joined: Fri Jan 05, 2007 9:52 am

Post by pete_b »

Nice control!


Just noticed in the documentation for wxWindow:

wxWindow::HasMultiplePages
virtual bool HasMultiplePages() const

This method should be overridden to return true if this window has multiple pages. All standard class with multiple pages such as wxNotebook, wxListbook and wxTreebook already override it to return true and user-defined classes with similar behaviour should do it as well to allow the library to handle such windows appropriately.
framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer »

Hi eranif.

Wonder if it's possible to add: attach/detach of tabs.
Namely detach a tab from the notebook to it's own frame, and than reatach it to the notebook.

It's just an idea, an I guess it's hard to manage. Maybe you could reparent it to a custom frame that features a buton/toolbar to reatach the window.

Regards,
Robert
Software is like sex,
It's better when it's free.
~Linus Torvalds
User avatar
T-Rex
Moderator
Moderator
Posts: 1248
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex »

framepointer, if you need detached tabs, you can try wxAuiNotebook.
rjmyst3
Knows some wx things
Knows some wx things
Posts: 49
Joined: Tue Oct 10, 2006 7:02 pm
Contact:

Post by rjmyst3 »

wxAuiNotebook does not support detached tabs.
User avatar
T-Rex
Moderator
Moderator
Posts: 1248
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex »

> wxAuiNotebook does not support detached tabs.
Indeed, it is possible only to split tabs but not to detach, sorry.
framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer »

Hi eranif.

Wonder if you could include the following code in a future release. It searches a menu for items based on name. comes in handy if you dynamically create menus from XML or other input and you want to avoid double creation of the same menu item.

Code to be added to header, flat_menu.h

Code: Select all

/*******************************************************/
protected:
	virtual int  FindMenuItemPos(const wxString & sLabel, wxFlatMenu **pMenu, bool bRecursive) const

public:
	/**
	 * \brief Finds the first menu item object associated with the given name/label and, optionally, the (sub)menu it belongs to.
	 * \param sLabel menu item label
	 * \param pMenu submenu
	 * \param bRecursive search submenus recursively
	 * \return menu item
	 */
	wxFlatMenuItem * FindItem(const wxString & sLabel, wxFlatMenu **pMenu = NULL, bool bRecursive = true) const;
In the cpp file

Code: Select all

/*******************************************************/
wxFlatMenuItem * wxFlatMenu::FindItem(const wxString & sLabel, wxFlatMenu **pMenu, bool bRecursive ) const
{
	wxFlatMenuItem * pRet = 0L;
	
	if( pMenu != 0L )
	{
		int nIdx = FindMenuItemPos(sLabel, pMenu, bRecursive);
		if( wxNOT_FOUND != nIdx )
			pRet = (*pMenu)->m_itemsArr[nIdx];
	}
	else
	{
		wxFlatMenu *pParentMenu = 0L;
		int nIdx = FindMenuItemPos(sLabel, &pParentMenu, bRecursive);
		if( wxNOT_FOUND != nIdx )
			pRet = pParentMenu->m_itemsArr[nIdx];
	}
	
	return pRet;
}

int wxFlatMenu::FindMenuItemPos(const wxString & sLabel, wxFlatMenu **pMenu, bool bRecursive) const
{
	wxASSERT_MSG(pMenu, wxT("menu is NULL"));
	
	*pMenu = 0L;
	wxFlatMenuItem *pItem = 0L;
	int i = 0;
	int nIdx = wxNOT_FOUND;

	for (; i < (int)m_itemsArr.size(); i++ )
	{
		pItem = m_itemsArr[i];
		
		if ( pItem->GetLabel().Cmp(sLabel) == 0 )
		{
			*pMenu = (wxFlatMenu *)this;
			nIdx = i;
			break;
		}
		else if ( pItem->IsSubMenu() && bRecursive)
		{
			nIdx = pItem->GetSubMenu()->FindMenuItemPos(sLabel, pMenu, bRecursive);
			if( wxNOT_FOUND != nIdx )
				break;
		}
		else
		{
			pItem = 0L;
		}
	}

	return nIdx;
}
It's similar to the wxMenu FindItem() methods, just that you can specify if you want to recurse into submenus or not.


Regards,
Robert
Software is like sex,
It's better when it's free.
~Linus Torvalds
aetmos
Experienced Solver
Experienced Solver
Posts: 75
Joined: Sat Jan 21, 2006 5:14 am

Post by aetmos »

I think I've found a bug...

When I close a tab, events seem to be fired in this order:

CLOSING
CHANGING
CHANGED
CLOSED

Makes sense. However, within my CHANGING function, if I do an event.GetOldSelection(), I would expect to get the ID of the page that is being (but has not yet been) closed. Instead, I get the ID of the page that I am changing to (i.e. event.GetSelection() == event.GetOldSelection() in this instance). GetOldSelection() works fine generally, it's only when I try to call it when a tab is being closed that there's a problem.

Tom
nkwinder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Sun Nov 23, 2008 2:32 pm

Post by nkwinder »

i downloaded the files, and tried to build the project in vs2008. Firstly, the demo project is disabled and can't be compiled at all. The actual flatNotebook compilation gives errors.

i actually use codeblocks with wxWidgets. I compiled wxWidgets with mingw, and not through vs.

Can someone tell me how to setup and use this?

thanks in advance
Post Reply