Exemplo n.º 1
0
bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
{
    wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );

    wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );

    // NOTE: if you change this code, you need to update
    //       the same code in taskbar.cpp as well. This
    //       is ugly code duplication, I know.

    menu->UpdateUI();

    bool is_waiting = true;

    gulong handler = gtk_signal_connect( GTK_OBJECT(menu->m_menu),
                                         "hide",
                                         GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
                                         (gpointer)&is_waiting );

    wxPoint pos;
    gpointer userdata;
    GtkMenuPositionFunc posfunc;
    if ( x == -1 && y == -1 )
    {
        // use GTK's default positioning algorithm
        userdata = NULL;
        posfunc = NULL;
    }
    else
    {
        pos = ClientToScreen(wxPoint(x, y));
        userdata = &pos;
        posfunc = wxPopupMenuPositionCallback;
    }

    wxMenuEvent eventOpen(wxEVT_MENU_OPEN, -1, menu);
    DoCommonMenuCallbackCode(menu, eventOpen);

    gtk_menu_popup(
                  GTK_MENU(menu->m_menu),
                  NULL,           // parent menu shell
                  NULL,           // parent menu item
                  posfunc,                      // function to position it
                  userdata,                     // client data
                  0,                            // button used to activate it
                  wxGtkTimeLastClick            // the time of activation
                );

    while (is_waiting)
    {
        gtk_main_iteration();
    }

    gtk_signal_disconnect(GTK_OBJECT(menu->m_menu), handler);

    wxMenuEvent eventClose(wxEVT_MENU_CLOSE, -1, menu);
    DoCommonMenuCallbackCode(menu, eventClose);

    return true;
}
Exemplo n.º 2
0
static void menuitem_deselect(GtkWidget*, wxMenuItem* item)
{
    if (!item->IsEnabled())
        return;

    wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
    DoCommonMenuCallbackCode(item->GetMenu(), event);
}
Exemplo n.º 3
0
static void gtk_menu_close_callback( GtkWidget *WXUNUSED(widget), wxMenuBar *menubar )
{
    if ( !menubar->GetMenuCount() )
    {
        // if menubar is empty we can't call GetMenu(0) below
        return;
    }

    wxMenuEvent event( wxEVT_MENU_CLOSE, -1, NULL );

    DoCommonMenuCallbackCode(menubar->GetMenu(0), event);
}
Exemplo n.º 4
0
// "hide" from m_menu
static void menu_hide(GtkWidget*, wxMenu* menu)
{
    // When using Ubuntu Unity desktop environment we get "hide" signal even
    // when the window is not shown yet because Unity hides all the menus to
    // show them only in the global menu bar. Just ignore this even instead of
    // crashing in DoCommonMenuCallbackCode().
    if ( !menu->GetWindow() )
        return;

    wxMenuEvent event(wxEVT_MENU_CLOSE, menu->m_popupShown ? -1 : 0, menu);
    menu->m_popupShown = false;
    DoCommonMenuCallbackCode(menu, event);
}
Exemplo n.º 5
0
static void gtk_menu_open_callback( GtkWidget *WXUNUSED(widget), wxMenu *menu )
{
    wxMenuEvent event(wxEVT_MENU_OPEN, -1, menu);

    DoCommonMenuCallbackCode(menu, event);
}
Exemplo n.º 6
0
// "hide" from m_menu
static void menu_hide(GtkWidget*, wxMenu* menu)
{
    wxMenuEvent event(wxEVT_MENU_CLOSE, menu->m_popupShown ? -1 : 0, menu);
    menu->m_popupShown = false;
    DoCommonMenuCallbackCode(menu, event);
}
Exemplo n.º 7
0
// "map" from m_menu
static void menu_map(GtkWidget*, wxMenu* menu)
{
    wxMenuEvent event(wxEVT_MENU_OPEN, menu->m_popupShown ? -1 : 0, menu);
    DoCommonMenuCallbackCode(menu, event);
}