Re: [gtkmm] [beginner question] Problems with menu, menu bar



Am 13.07.2002 12:48 schrieb(en) Daniel Perez Alcazar:

Hi!

I need a menu bar in my program. The thing is that I get the menu bar,
but
not the submenu when I press the menu bar entry. Pardon me if it's a too
silly question... I warned you, it's a "beginner question" ;-)

I've attached the code.

Thanks,

Dani P.

<--------------- The main function ------------------->

#include <gtk--/main.h>
#include <gtk--/window.h>
#include <gtk--/box.h>
#include "nsMenu.h"

int main (int argc, char *argv[])
{
	Gtk::Main start(argc,argv);
	 	 	/////////// Creating the menu bar...////////////
	nsMenu menu;
	menu.show_all();
///////////////////////////////////////////////////////////// /////////// Putting all together ///////////////////
	Gtk::VBox main_packing_box(FALSE,0);
	main_packing_box.pack_start(menu,false,0);
	main_packing_box.show();
	////////////////////////////////////////////////////////////
	 	 	////////////////// Main window ///////////////////
	Gtk::Window window(GTK_WINDOW_TOPLEVEL);
	window.set_title("NetScout");
	window.set_policy(false,true,false);
	window.add(main_packing_box);
	window.show();
	///////////////////////////////////////////////////////////
	 	start.run();

	return(0);
}
<------------------------------------------->

<--------------- My menu class ----------------->

<<<<<<<<The header>>>>>>>>>>

#include <gtk--/menubar.h>
#include <gtk--/menu.h>

class nsMenu : public Gtk::MenuBar
{
	public:

	nsMenu();
};

<<<<<<The implemetantion>>>>>>

#include "nsMenu.h"

nsMenu::nsMenu()
{
	using namespace Gtk;
//////////////////// The "file" menu //////////////////////
	Menu file_menu;

You should try Menu* file_menu = manage( new Menu );
By the way, there is a more convinient stl-style interface for building
menu trees. Look at the docs of namespace Gtk::Menu_Helpers for more
information. I think the examples also use this interface.

	MenuItem *root_file;
		root_file=manage(new MenuItem("File"));
file_menu.append(*manage(new MenuItem("_Open"))); file_menu.append(*manage(new MenuItem("_Save")));
		root_file->set_submenu(file_menu);
/////////////////////////////////////////////////////////////////// //////////////////// The menu bar, mother of all menus
//////////////////////
	append(*root_file);
//////////////////////////////////////////////////////////////////////////////////////////////////
	 	 }

<------------------------------------------------->


_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]