Trouble with GtkUIManager




Trying to learn about GtkUIManager, and running into a strange behavior. As an initial experiment, I'm trying to create a menu bar containing only one menu, which in turn contains only one menu item. This menu bar is the only element in my top-level window. The code (C+ +) is as follows:

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

    gtk_init( &argc, &argv );


// Create top-level window and arrange to stop the program when it closes.

    GtkWidget* window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
g_signal_connect( window, "delete-event", reinterpret_cast<GCallback>(closeMainWindow), NULL );


    // Create the UIManager.

    static const gchar* const menuDef =
         "<ui>\
            <menubar name=\"Menus\">\
                <menu name=\"File\" action=\"FileMenuAct\">\
<menuitem name=\"Quit\" action=\"QuitAct\"> </ menuitem>\
                </menu>\
            </menubar>\
         </ui>";

static const GtkActionEntry acts[] = { { "FileMenuAct", NULL, "_File" }, { "QuitAct", GTK_STOCK_QUIT, "_Quit", "<control>Q", "Exit this program", reinterpret_cast<GCallback>(menuShutdown) } };
    const guint nActs = 2;

GtkActionGroup* menuActions = gtk_action_group_new ( "MenuActions" );
    gtk_action_group_add_actions( menuActions, acts, nActs, NULL );

    GtkUIManager* menuManager = gtk_ui_manager_new();
    gtk_ui_manager_insert_action_group( menuManager, menuActions, 0 );

    GError* menuError = 0;
const guint mergeID = gtk_ui_manager_add_ui_from_string ( menuManager, menuDef, -1, &menuError );
    if (  mergeID == 0  ||  menuError != 0  ) {
cerr << "Error: Failed to add menu definitions to menu UI manager -- " << menuError->message << endl;
        g_error_free( menuError );
    }

    gtk_ui_manager_ensure_update( menuManager );

GtkWidget* menuBar = gtk_ui_manager_get_widget( menuManager, "/ Menus" ); gtk_container_add( reinterpret_cast<GtkContainer*>(window), menuBar );


    // Make everything visible.

    gtk_widget_show_all( window );

    gtk_main();

    return 0;
}

When I run this code, no window appears at all. If I remove the "gtk_container_add" that adds the menu bar to the main window, the program displays an empty window as I would expect it to. I'm using GTk+2 2.6.10 on Mac OS X 10.4.11, running the above program under the X11 that came with the Mac (which identifies itself as X11 1.1.3 - XFree86 4.4.0). Does anyone have any thoughts about what I'm doing wrong? Thanks.



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