示例#1
0
void RebrandingHelper::ApplyBranding(wxMenu & menu, wxString scope)
{
    size_t separatorIndex = 0;

	wxMenuItemList & itemsList = menu.GetMenuItems();
	for(auto itemIt = itemsList.begin(); itemIt != itemsList.end();++itemIt)
	{
	    wxMenuItem * item = *itemIt;
	    if (!item) continue;

        wxString name = menu.GetLabelText(item->GetId());
        if (item->GetId() == wxID_SEPARATOR)
        {
            name = "Separator_";
            name << separatorIndex;
            separatorIndex++;
        }

	    wxString itemScope = scope + "." + name;

	    if (ShouldDelete(itemScope)) menu.Destroy(item);
	    else if (ShouldRename(itemScope)) item->SetItemLabel(GetNewName(itemScope));
	}
}
/**
  * Invoked when user selects the "Menu" item
  */
void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt))
{
    if(m_browser->GetCurrentURL() == "")
        return;

    m_tools_tiny->Check(false);
    m_tools_small->Check(false);
    m_tools_medium->Check(false);
    m_tools_large->Check(false);
    m_tools_largest->Check(false);

    wxWebViewZoom zoom = m_browser->GetZoom();
    switch (zoom)
    {
    case wxWEBVIEW_ZOOM_TINY:
        m_tools_tiny->Check();
        break;
    case wxWEBVIEW_ZOOM_SMALL:
        m_tools_small->Check();
        break;
    case wxWEBVIEW_ZOOM_MEDIUM:
        m_tools_medium->Check();
        break;
    case wxWEBVIEW_ZOOM_LARGE:
        m_tools_large->Check();
        break;
    case wxWEBVIEW_ZOOM_LARGEST:
        m_tools_largest->Check();
        break;
    }

    m_edit_cut->Enable(m_browser->CanCut());
    m_edit_copy->Enable(m_browser->CanCopy());
    m_edit_paste->Enable(m_browser->CanPaste());

    m_edit_undo->Enable(m_browser->CanUndo());
    m_edit_redo->Enable(m_browser->CanRedo());

    m_selection_clear->Enable(m_browser->HasSelection());
    m_selection_delete->Enable(m_browser->HasSelection());

    m_context_menu->Check(m_browser->IsContextMenuEnabled());

    //Firstly we clear the existing menu items, then we add the current ones
    wxMenuHistoryMap::const_iterator it;
    for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
    {
        m_tools_history_menu->Destroy(it->first);
    }
    m_histMenuItems.clear();

    wxVector<wxSharedPtr<wxWebViewHistoryItem> > back = m_browser->GetBackwardHistory();
    wxVector<wxSharedPtr<wxWebViewHistoryItem> > forward = m_browser->GetForwardHistory();

    wxMenuItem* item;

    unsigned int i;
    for(i = 0; i < back.size(); i++)
    {
        item = m_tools_history_menu->AppendRadioItem(wxID_ANY, back[i]->GetTitle());
        m_histMenuItems[item->GetId()] = back[i];
        Connect(item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
                wxCommandEventHandler(WebFrame::OnHistory), NULL, this );
    }

    wxString title = m_browser->GetCurrentTitle();
    if ( title.empty() )
        title = "(untitled)";
    item = m_tools_history_menu->AppendRadioItem(wxID_ANY, title);
    item->Check();

    //No need to connect the current item
    m_histMenuItems[item->GetId()] = wxSharedPtr<wxWebViewHistoryItem>(new wxWebViewHistoryItem(m_browser->GetCurrentURL(), m_browser->GetCurrentTitle()));

    for(i = 0; i < forward.size(); i++)
    {
        item = m_tools_history_menu->AppendRadioItem(wxID_ANY, forward[i]->GetTitle());
        m_histMenuItems[item->GetId()] = forward[i];
        Connect(item->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
                wxCommandEventHandler(WebFrame::OnHistory), NULL, this );
    }

    wxPoint position = ScreenToClient( wxGetMousePosition() );
    PopupMenu(m_tools_menu, position.x, position.y);
}