GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 3:05 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Where is the menubar??
PostPosted: Sun Dec 11, 2011 12:08 pm 
Offline
Familiar Face

Joined: Fri Dec 09, 2011 6:25 pm
Posts: 12
I use GTK+ 3 and Ubuntu 11.10. Since yesterday morning the menubar doesn't appear compiling this code! Incredible. I also installed a new version of Ubuntu 11.10 with vmware, but same problem!
Do you think that is a problem with the new kernel?
or what about gconf-editor, known bug of Ubuntu 11.10??
Code:
#include <gtk/gtk.h>

void create_menu (GtkWindow *window, GtkContainer *container)
{
   // Inizializzazione widget
   GtkWidget *vbox, *hbox, *menubar;

   GtkWidget *filemenu, *filemenu2, *filemenu3;
   
   GtkWidget *file, *settings, *help;
     
   GtkWidget *open, *save_as, *close, *quit, *sep;
   
   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);
     
   menubar = gtk_menu_bar_new ();
   gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0);

   GtkWidget *button = gtk_button_new_with_label ("CIAO");
   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
   gtk_widget_set_halign (button, GTK_ALIGN_END);
   gtk_widget_set_valign (button, GTK_ALIGN_END);

   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
   gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);

   filemenu = gtk_menu_new ();
   
   GtkAccelGroup *accel_group = gtk_accel_group_new ();
   gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
     
   file = gtk_menu_item_new_with_mnemonic ("File");
   gtk_menu_shell_append (GTK_MENU_SHELL (menubar), file);
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (file), filemenu);
   
   settings = gtk_menu_item_new_with_mnemonic ("_Strumenti");
   gtk_menu_shell_append (GTK_MENU_SHELL (menubar), settings);
     
   help = gtk_menu_item_new_with_mnemonic ("_Aiuto");
   gtk_menu_shell_append (GTK_MENU_SHELL (menubar), help);
   
   open = gtk_image_menu_item_new_from_stock (GTK_STOCK_OPEN, accel_group);
   close = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLOSE, accel_group);
   save_as = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, accel_group);
   sep = gtk_separator_menu_item_new ();
   quit = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, accel_group);
   
   // vengono aggiunti dei submenu
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (file), filemenu);
   gtk_menu_shell_append (GTK_MENU_SHELL (filemenu), open);   
   gtk_menu_shell_append (GTK_MENU_SHELL (filemenu), close);
   gtk_menu_shell_append (GTK_MENU_SHELL (filemenu), save_as);
   // Inserimento separatore
   gtk_menu_shell_append (GTK_MENU_SHELL(filemenu), sep);
   gtk_menu_shell_append (GTK_MENU_SHELL (filemenu), quit);
}

int main (int argc, char *argv[])
{
   GtkWidget *window;   

   /* This is called in all GTK applications. Arguments are parsed
       * from the command line and are returned to the application.
    */
   gtk_init (&argc, &argv);

     /* create a new window, and set its title */
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "c_Nav");
   gtk_window_set_default_size (GTK_WINDOW (window), 800, 450);
   gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
     //gtk_container_set_border_width (GTK_CONTAINER (window), 0);

   // Funzione per la creazione del menu
   create_menu (GTK_WINDOW (window), GTK_CONTAINER (window));
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

     /* Now that we are done packing our widgets, we show them all
       * in one go, by calling gtk_widget_show_all() on the window.
       * This call recursively calls gtk_widget_show() on all widgets
       * that are contained in the window, directly or indirectly.
       */
   gtk_widget_show_all (window);

     /* All GTK applications must have a gtk_main(). Control ends here
     * and waits for an event to occur (like a key press or a mouse event),
     * until gtk_main_quit() is called.
     */
   gtk_main ();

   return 0;
}


Top
 Profile  
 
 Post subject: Re: Where is the menubar??
PostPosted: Sun Dec 11, 2011 1:12 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
This code compiled OK, and showed a menu bar with menu items in it when I tried it this morning. To compile it I used
Code:
gcc `pkg-config -libs --cflags gtk+-3.0` t.cc
where t.cc is the name I gave to the sample code. If you can give more details such as how you are compiling what you really want from your code, giving details that would be more help. When you sent me a PM with the first sample of this code with all the menu code commented out I thought - no wonder there is no menu, it has been removed!!!!!!!!

Next thing is for you to take your time! Learning to programme does not come instantly, you have to read the documentation, tutorials and examine others peoples work to see how things are done, and not expect things to be handed to you. On this forum there are links to the documentation and to tutorials, I shall let you find them your self.

Also you seam to be thinking the everything else is wrong or has a bug and grabbing at anything even if it is totally unrelated. Have you thought that your code has many bugs in it!

Note I do not think there is a problem with the new kernel, Ubuntu 11.10 and gconf-editor is just a grab at anything. DO you see other applications with menu-bars?

_________________
E.


Top
 Profile  
 
 Post subject: Re: Where is the menubar??
PostPosted: Sun Dec 11, 2011 1:32 pm 
Offline
Familiar Face

Joined: Fri Dec 09, 2011 6:25 pm
Posts: 12
Thank you errol for what you said, I'll remember it.
I want a simple Window with a menubar and a button.
I used Ubuntu 10.04 and GTK+ 2, and I compiled with
Code:
g++ -Wall -O3 `pkg-config --libs --cflags gtk+-2.0` file.cc
Everything was ok there, but i had problems with my interface and i posted something on this forum.
We talked about set_halign and set_valign, available only in GTK+ 3, so I decided to pass toGTK+ 3, beacuse it's updated, new and I thought that for me was better to be updated also for talking in this forum (I didn't know nothing about gtk_alignment_new in GTK+ 2). I also "moved myself" to Ubuntu 11.10(I use Ubuntu on Virtual Machines) and installed GTK3. I also passed the code to GTK+ 3(for ex, there's no more gtk_hbox(or vbox)_new).
Everything was ok and i could see menubar. I compiled all with
Code:
g++ -Wall -O3 `pkg-config --cflags gtk+-3.0` file.cc `pkg-config --libs gtk+-3.0`
But from yesterday I can't see menubar.
You told me you can see it.
If I compile the code "t.cc" with
Code:
gcc `pkg-config --libs --cflags gtk+-3.0` file.cc
(there are 2 -- not just 1 before libs
i get this error on all the lines
Code:
tipo.cc:(.text+0x1b): undefined reference to `gtk_box_new'
tipo.cc:(.text+0x24): undefined reference to `gtk_container_get_type'
tipo.cc:(.text+0x36): undefined reference to `g_type_check_instance_cast'
tipo.cc:(.text+0x45): undefined reference to `gtk_container_add'
................
I use g++ and not gcc compiler cause I prefer to use C++ than C, I haven't studied C, and in the next days when i'll add code to my interface I'll prefer to use C++
Thank you for help


Top
 Profile  
 
 Post subject: Re: Where is the menubar??
PostPosted: Tue Dec 13, 2011 12:55 am 
Offline
Familiar Face

Joined: Fri Dec 09, 2011 6:25 pm
Posts: 12
i haven't find the solution...
Any suggestions? Thank you


Top
 Profile  
 
 Post subject: Re: Where is the menubar??
PostPosted: Tue Dec 13, 2011 10:47 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
You run unity I take it?
I think you'll find this isn't a problem with you're code but something that you'll see for every application.
I spent a while scratching my head when I converted.
Try maximising your window.
Can you find it now?
Turns out unity puts the menubar in the same place when windows are unmaximised, i.e. not in the window itself where sensible people would expect to find it but in the top panel of the screen. Bloody annoying. I guess they did it for space saving features on unmaximised windows.
If you're really annoyed with unity behaviour you can run in classic mode giving the 10.04 feel for those of us who don't want to move on with where the world is going. I think you may be able to tweak out the menu effect but it hasn't annoyed me enough to try yet.


Top
 Profile  
 
 Post subject: Re: Where is the menubar??
PostPosted: Fri Dec 16, 2011 11:52 am 
Offline
Familiar Face

Joined: Fri Dec 09, 2011 6:25 pm
Posts: 12
Yes!
It was because of Unity. I've maximased my virtual machine window and then I've done this also in my ./program. Now I've got the menubar and I have found the solution but i think it will be better to work on Ubuntu 10.04 with GTK+3 installed on it.
Thank you


Top
 Profile  
 
 Post subject: Re: Where is the menubar??
PostPosted: Sun Dec 18, 2011 9:57 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
I run Ubuntu 11.04 Natty in "Classic, no-effects" mode, without Unity. Unless I do this, my system slows to a crawl. You can run 11.10 the same way.
http://www.omgubuntu.co.uk/2011/12/how-to-make-ubuntu-11-10-look-and-feel-like-gnome-2/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group