Пример #1
0
int
WelcomePage::DoGetPopupMenuSelection(wxCommandLinkButton* btn, const wxArrayString& strings, const wxString& menuTitle)
{
    BitmapLoader bl;
    BitmapLoader::BitmapMap_t bmps = bl.MakeStandardMimeMap();

    m_idToName.clear();
    wxUnusedVar(menuTitle);
    wxMenu menu;

    for(size_t i = 0; i < strings.GetCount(); i++) {

        wxBitmap bmp = bmps[FileExtManager::TypeText];
        wxString filename = strings.Item(i);
        if(filename.Find("@") != wxNOT_FOUND) {
            filename = filename.AfterFirst('@');
        }
        filename.Trim().Trim(false);
        FileExtManager::FileType type = FileExtManager::GetType(filename);
        if(bmps.count(type)) {
            bmp = bmps[type];
        }

        wxMenuItem* item = new wxMenuItem(&menu, wxID_ANY, strings.Item(i));
        item->SetBitmap(bmp);
        m_idToName.insert(std::make_pair(item->GetId(), strings.Item(i)));
        menu.Append(item);
    }

    // get the best position to show the menu
    wxPoint pos = btn->GetPosition();
    pos = m_scrollWin247->CalcScrolledPosition(pos);

    pos.y += btn->GetSize().y;
#ifdef __WXGTK__
    pos.y += 5;
    pos.x += 5;
#elif defined(__WXMAC__)
    pos.y += 10;
    pos.x += 10;
#else // MSW
    pos.y += 5;
    pos.x += 5;
#endif
    return GetPopupMenuSelectionFromUser(menu, pos);
}
NotebookNavigationDlg::NotebookNavigationDlg(wxWindow* parent, Notebook* book)
    : NotebookNavigationDlgBase(parent)
    , m_book(book)
    , m_selection(wxNOT_FOUND)
{
    clTab::Vec_t allTabs;
    clTabHistory::Ptr_t history = m_book->GetHistory();
    clGetManager()->GetAllTabs(allTabs);

    BitmapLoader::BitmapMap_t bmps = clGetManager()->GetStdIcons()->MakeStandardMimeMap();

#ifdef __WXOSX__
    wxBitmap saveBmp = wxNullBitmap;
#else
    wxBitmap saveBmp = clGetManager()->GetStdIcons()->LoadBitmap("file_save");
#endif
    std::map<void*, clTab> tabsInfoMap;
    for(size_t i = 0; i < allTabs.size(); ++i) {
        tabsInfoMap.insert(std::make_pair((void*)allTabs.at(i).window, allTabs.at(i)));
    }

    const wxArrayPtrVoid& windows = history->GetHistory();
    // Populate the list
    for(size_t i = 0; i < windows.GetCount(); ++i) {
        int index = m_book->FindPage((wxWindow*)windows.Item(i));
        if(index != wxNOT_FOUND) {
            wxString label = m_book->GetPageText(index);
            wxBitmap bmp = m_book->GetPageBitmap(index);

            wxVector<wxVariant> cols;
            TabData* d = new TabData;
            d->bmp = bmp;
            d->label = label;
            d->index = index;

            // add extra info
            wxVariant modifiedItem;
            wxVariant nullBmp;
            nullBmp << wxNullBitmap;
            std::map<void*, clTab>::iterator iter = tabsInfoMap.find(windows.Item(i));
            if(iter != tabsInfoMap.end()) {
                d->isFile = iter->second.isFile;
                d->filename = iter->second.filename;
                if(iter->second.isModified) {
                    modifiedItem << saveBmp;
                    cols.push_back(modifiedItem);
                } else {
                    cols.push_back(nullBmp);
                }
            } else {
                cols.push_back(nullBmp);
            }

            // Prepare the display item
            wxString text;
            if(d->isFile && d->filename.GetDirCount()) {
                wxFileName fn(d->filename.GetFullName());
                fn.AppendDir(d->filename.GetDirs().Last());
                text << fn.GetFullPath();
            } else {
                text << d->label;
            }

            // If the tab has a bitmap - use it
            // otherwise, try to assign one
            if(!d->bmp.IsOk()) {
                if(d->isFile) {
                    FileExtManager::FileType type =
                        FileExtManager::GetType(d->filename.GetFullName(), FileExtManager::TypeText);
                    if(bmps.count(type)) {
                        d->bmp = bmps.find(type)->second;
                    }
                }
            }

#ifdef __WXOSX__
            if(iter != tabsInfoMap.end() && iter->second.isModified) {
                text.Prepend("*");
            }
#endif
            cols.push_back(::MakeIconText(text, d->bmp));
            m_dvListCtrl->AppendItem(cols, (wxUIntPtr)d);
        }
    }

    if(m_dvListCtrl->GetItemCount() > 1) {
        m_dvListCtrl->Select(m_dvListCtrl->RowToItem(1));
    } else {
        m_dvListCtrl->Select(m_dvListCtrl->RowToItem(0));
    }

    m_dvListCtrl->CallAfter(&wxDataViewCtrl::SetFocus);
    SetMinClientSize(wxSize(500, 300));
#ifdef __WXOSX__
    SetSize(wxSize(500, 300));
#endif
    CentreOnParent();

    wxTheApp->Bind(wxEVT_KEY_DOWN, &NotebookNavigationDlg::OnKeyDown, this);
    wxTheApp->Bind(wxEVT_KEY_UP, &NotebookNavigationDlg::OnKeyUp, this);
}