Ejemplo n.º 1
0
void wxFrame::AttachMenuBar(wxMenuBar *menubar)
{
    wxFrameBase::AttachMenuBar(menubar);

    if ( !menubar )
    {
        // actually remove the menu from the frame
        m_hMenu = (WXHMENU)0;
        InternalSetMenuBar();
    }
    else // set new non NULL menu bar
    {
        // Can set a menubar several times.
        if ( menubar->GetHMenu() )
        {
            m_hMenu = menubar->GetHMenu();
        }
        else // no HMENU yet
        {
            m_hMenu = menubar->Create();

            if ( !m_hMenu )
            {
                wxFAIL_MSG( wxT("failed to create menu bar") );
                return;
            }
        }
        InternalSetMenuBar();
    }
}
Ejemplo n.º 2
0
void wxFrame::SetMenuBar(
  wxMenuBar*                        pMenuBar
)
{
    wxString                        sError;

    if (!pMenuBar)
    {
        DetachMenuBar();

        //
        // Actually remove the menu from the frame
        //
        m_hMenu = (WXHMENU)0;
        InternalSetMenuBar();
    }
    else // set new non NULL menu bar
    {
        m_frameMenuBar = NULL;

        //
        // Can set a menubar several times.
        // TODO: how to prevent a memory leak if you have a currently-unattached
        // menubar? wxWidgets assumes that the frame will delete the menu (otherwise
        // there are problems for MDI).
        //
        if (pMenuBar->GetHMenu())
        {
            m_hMenu = pMenuBar->GetHMenu();
        }
        else
        {
            pMenuBar->Detach();
            m_hMenu = pMenuBar->Create();
            if (!m_hMenu)
                return;
        }
        InternalSetMenuBar();
        m_frameMenuBar = pMenuBar;
        pMenuBar->Attach((wxFrame*)this);
    }
} // end of wxFrame::SetMenuBar
Ejemplo n.º 3
0
void wxFrame::AttachMenuBar(
  wxMenuBar*                        pMenubar
)
{
    wxFrameBase::AttachMenuBar(pMenubar);

    m_frameMenuBar = pMenubar;

    if (!pMenubar)
    {
        //
        // Actually remove the menu from the frame
        //
        m_hMenu = (WXHMENU)0;
        InternalSetMenuBar();
    }
    else // Set new non NULL menu bar
    {
        //
        // Can set a menubar several times.
        //
        if (pMenubar->GetHMenu())
        {
            m_hMenu = pMenubar->GetHMenu();
        }
        else
        {
            if (pMenubar->IsAttached())
                pMenubar->Detach();

            m_hMenu = pMenubar->Create();

            if (!m_hMenu)
                return;
        }
        InternalSetMenuBar();
    }
} // end of wxFrame::AttachMenuBar
Ejemplo n.º 4
0
void wxFrame::AttachMenuBar(wxMenuBar *menubar)
{
#if defined(__SMARTPHONE__) && defined(__WXWINCE__)

    wxMenu *autoMenu = NULL;

    if( menubar->GetMenuCount() == 1 )
    {
        autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
        SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu);
    }
    else
    {
        autoMenu = new wxMenu;

        for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
        {
            wxMenu *item = menubar->GetMenu(n);
            wxString label = menubar->GetMenuLabel(n);
            wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
            autoMenu->Append(wxID_ANY, label, new_item);
        }

        SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
    }

#elif defined(WINCE_WITHOUT_COMMANDBAR)
    if (!GetToolBar())
    {
        wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
                         wxDefaultPosition, wxDefaultSize,
                         wxBORDER_NONE | wxTB_HORIZONTAL,
                         wxToolBarNameStr, menubar);
        SetToolBar(toolBar);
        menubar->SetToolBar(toolBar);
    }

    // When the main window is created using CW_USEDEFAULT the height of the
    // menubar is not taken into account, so we resize it afterwards if a
    // menubar is present
    HWND hwndMenuBar = SHFindMenuBar(GetHwnd());
    if ( hwndMenuBar )
    {
        RECT mbRect;
        ::GetWindowRect(hwndMenuBar, &mbRect);
        const int menuHeight = mbRect.bottom - mbRect.top;

        RECT rc;
        ::GetWindowRect(GetHwnd(), &rc);
        // adjust for menu / titlebar height
        rc.bottom -= (2*menuHeight-1);

        ::MoveWindow(Gethwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
    }
#endif

    wxFrameBase::AttachMenuBar(menubar);

    if ( !menubar )
    {
        // actually remove the menu from the frame
        m_hMenu = (WXHMENU)0;
        InternalSetMenuBar();
    }
    else // set new non NULL menu bar
    {
#if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
        // Can set a menubar several times.
        if ( menubar->GetHMenu() )
        {
            m_hMenu = menubar->GetHMenu();
        }
        else // no HMENU yet
        {
            m_hMenu = menubar->Create();

            if ( !m_hMenu )
            {
                wxFAIL_MSG( wxT("failed to create menu bar") );
                return;
            }
        }
#endif
        InternalSetMenuBar();
    }
}