Update the frame menu based wxTaskBarIcon menu.

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

Update the frame menu based wxTaskBarIcon menu.

Post by Joelito »

I'm stuck trying to update my frame's wxMenu, see my code:
taskbar snippet

Code: Select all

MyTaskBarIcon::MyTaskBarIcon (MyFrame *_parent) 
	: wxTaskBarIcon(wxTBI_DEFAULT_TYPE), parent(_parent), m_IsTimerOn(false)
{
	Bind (wxEVT_MENU, &MyFrame::on_exit_item, parent, wxID_EXIT);
	Bind (wxEVT_MENU, &MyFrame::on_pref_item, parent, wxID_PREFERENCES);
	Bind (wxEVT_MENU, &MyFrame::on_play_item, parent, IDM_PLAY);
	Bind (wxEVT_TASKBAR_LEFT_DOWN, &MyTaskBarIcon::on_tray_clicked, this);
}

wxMenu* MyTaskBarIcon::CreatePopupMenu () {
	tmp = new wxMenu ();
	wxFileName f(DATA_DIR, m_IsTimerOn ? wxT("stop.png") : wxT("play.png"));
	wxBitmap bitmap (f.GetFullPath(), wxBITMAP_TYPE_PNG);
	wxMenuItem *m_menuItem1 = new wxMenuItem (tmp, IDM_PLAY, m_IsTimerOn ? _("&Stop") : _("&Start"));
	m_menuItem1->SetBitmap (bitmap);
	tmp->Append (m_menuItem1);
	tmp->AppendSeparator();
	wxMenuItem* m_menuItem2 = new wxMenuItem (tmp, wxID_PREFERENCES);
	tmp->Append (m_menuItem2);
	tmp->AppendSeparator();
	wxMenuItem* m_menuItem3  = new wxMenuItem (tmp, wxID_EXIT);
	tmp->Append (m_menuItem3);
	return tmp;
}
frame's ctor

Code: Select all

wxMenuBar *m_menubar1 = new wxMenuBar( 0 );
m_menu1 = m_tbIcon->CreatePopupMenu ();
m_menubar1->Append (m_menu1, _("&Application"));
My taskbar class send the menu items to my frame as expected. When I activate from my context menu the item IDM_PLAY, the context menu item change/update as expected, but not the item in my frame. What I want is when mutual frame <-> context menu reflects the changes and states. So I came up with two options here:

1.- Somehow when IDM_PLAY is activated from frame or context menu, send the state to the other one.
2.- In my frame's menubar trap/catch the event the popups the menu and I can "manually" change its state to emulate the one in the context.

any ideas for this one?
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux x86_64 with xfce desktop & wxgtk{2,3}-3.0.5.
Post Reply