⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manager.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:

    m_pPropGrid->SetId(useId);

    m_pPropGrid->m_iFlags |= wxPG_FL_IN_MANAGER;

    m_pState = m_pPropGrid->m_pState;

    m_pPropGrid->SetExtraStyle(wxPG_EX_INIT_NOCAT);

    m_nextTbInd = baseId+ID_ADVTBITEMSBASE_OFFSET + 2;


#ifndef __WXPYTHON__
    // Connect to property grid onselect event.
    // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
    //     (see wxPropertyGridManager::ProcessEvent).
    Connect(m_pPropGrid->GetId()/*wxID_ANY*/,
            wxEVT_PG_SELECTED,
            wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect) );
#endif

    // Connect to compactor button event.
    Connect(baseId+ID_ADVBUTTON_OFFSET,
            wxEVT_COMMAND_BUTTON_CLICKED,
            wxCommandEventHandler(wxPropertyGridManager::OnCompactorClick) );

    // Connect to toolbar button events.
    Connect(baseId+ID_ADVTBITEMSBASE_OFFSET,baseId+ID_ADVTBITEMSBASE_OFFSET+50,
            wxEVT_COMMAND_TOOL_CLICKED,
            wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick) );

    // Optional initial controls.
    m_width = -12345;

    m_iFlags |= wxPG_FL_INITIALIZED;

}

// -----------------------------------------------------------------------

wxPropertyGridManager::~wxPropertyGridManager()
{
    END_MOUSE_CAPTURE

    size_t i;
    for ( i=0; i<m_arrPages.GetCount(); i++ )
    {
        delete (wxPropertyGridPage*)m_arrPages.Item(i);
    }

    delete m_emptyPage;
}

// -----------------------------------------------------------------------

wxPropertyGrid* wxPropertyGridManager::CreatePropertyGrid() const
{
    return new wxPropertyGrid();
}

// -----------------------------------------------------------------------

void wxPropertyGridManager::SetId( wxWindowID winid )
{
    wxWindow::SetId(winid);

    // TODO: Reconnect propgrid event handler(s).

    m_pPropGrid->SetId(winid);
}

// -----------------------------------------------------------------------

wxSize wxPropertyGridManager::DoGetBestSize() const
{
    /*
    //wxSize sz = m_pPropGrid->DoGetBestSize();
    wxSize sz(60,m_pPropGrid->m_lineHeight);
    wxLogDebug(wxT("m_extraHeight: %i"),m_extraHeight);
    sz.y += m_extraHeight;
    wxLogDebug(wxT("sz.y: %i"),sz.y);
    //CacheBestSize(sz);
    return sz;
    */
    return wxSize(60,150);
}

// -----------------------------------------------------------------------

bool wxPropertyGridManager::SetFont( const wxFont& font )
{
    bool res = wxWindow::SetFont(font);
    m_pPropGrid->SetFont(font);
    // TODO: Need to do caption recacalculations for other pages as well.
    return res;
}

// -----------------------------------------------------------------------

void wxPropertyGridManager::SetExtraStyle( long exStyle )
{
    wxWindow::SetExtraStyle( exStyle );
    m_pPropGrid->SetExtraStyle( exStyle & 0xFFFFF000 );
#if wxUSE_TOOLBAR
    if ( (exStyle & wxPG_EX_NO_FLAT_TOOLBAR) && m_pToolbar )
        RecreateControls();
#endif
}

// -----------------------------------------------------------------------

void wxPropertyGridManager::Freeze()
{
    m_pPropGrid->Freeze();
    wxWindow::Freeze();
}

// -----------------------------------------------------------------------

void wxPropertyGridManager::Thaw()
{
    wxWindow::Thaw();
    m_pPropGrid->Thaw();
}

// -----------------------------------------------------------------------

void wxPropertyGridManager::SetWindowStyleFlag( long style )
{
    wxWindow::SetWindowStyleFlag( style );
    m_pPropGrid->SetWindowStyleFlag( (m_pPropGrid->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK)) |
                                   (style&wxPG_MAN_PASS_FLAGS_MASK) );
}

// -----------------------------------------------------------------------

// Actually shows given page.
bool wxPropertyGridManager::DoSelectPage( int index )
{
    // -1 means no page was selected
    //wxASSERT( m_selPage >= 0 );

    wxCHECK_MSG( index >= -1 && index < (int)GetPageCount(),
                 false,
                 wxT("invalid page index") );

    if ( m_selPage == index )
        return true;

    if ( m_pPropGrid->m_selected )
    {
        if ( !m_pPropGrid->ClearSelection() )
            return false;
    }

    wxPropertyGridPage* prevPage;

    if ( m_selPage >= 0 )
        prevPage = GetPage(m_selPage);
    else
        prevPage = m_emptyPage;

    wxPropertyGridPage* nextPage;

    if ( index >= 0 )
    {
        nextPage = (wxPropertyGridPage*)m_arrPages.Item(index);
    }
    else
    {
        if ( !m_emptyPage )
            m_emptyPage = new wxPropertyGridPage();

        nextPage = m_emptyPage;
    }

    m_iFlags |= wxPG_FL_DESC_REFRESH_REQUIRED;

    m_pPropGrid->SwitchState( nextPage->GetStatePtr() );

    m_pState = m_pPropGrid->m_pState;

    m_selPage = index;

#if wxUSE_TOOLBAR
    if ( m_pToolbar )
    {
        if ( index >= 0 )
            m_pToolbar->ToggleTool( nextPage->m_id, true );
        else
            m_pToolbar->ToggleTool( prevPage->m_id, false );
    }
#endif

    return true;
}

// -----------------------------------------------------------------------

// Changes page *and* set the target page for insertion operations.
void wxPropertyGridManager::SelectPage( int index )
{
    DoSelectPage(index);
    if ( index >= 0 )
        SetTargetPage(index);
}

// -----------------------------------------------------------------------

int wxPropertyGridManager::GetPageByName( const wxChar* name ) const
{
    wxASSERT( name );

    size_t i;
    for ( i=0; i<GetPageCount(); i++ )
    {
        if ( ((wxPropertyGridPage*)m_arrPages.Item(i))->m_label == name )
            return i;
    }
    return wxNOT_FOUND;
}

// -----------------------------------------------------------------------

int wxPropertyGridManager::GetPageByState( wxPropertyGridState* pState ) const
{
    wxASSERT( pState );

    size_t i;
    for ( i=0; i<GetPageCount(); i++ )
    {
        if ( pState == ((wxPropertyGridPage*)m_arrPages.Item(i))->GetStatePtr() )
            return i;
    }

    return wxNOT_FOUND;
}

// -----------------------------------------------------------------------

const wxString& wxPropertyGridManager::GetPageName( int index ) const
{
    wxASSERT( index >= 0 && index < (int)GetPageCount() );
    return ((wxPropertyGridPage*)m_arrPages.Item(index))->m_label;
}

// -----------------------------------------------------------------------

// Sets page for append, insert, etc. operations.
void wxPropertyGridManager::SetTargetPage( int index )
{
    wxASSERT( m_selPage >= 0 );
    wxASSERT( index >= 0 );
    wxASSERT( index < (int)GetPageCount() );

    m_targetPage = index;
    m_targetState = ((wxPropertyGridPage*)m_arrPages.Item(index))->GetStatePtr();

}

// -----------------------------------------------------------------------

void wxPropertyGridManager::ClearPage( int page )
{
    wxASSERT( page >= 0 );
    wxASSERT( page < (int)GetPageCount() );

    if ( page >= 0 && page < (int)GetPageCount() )
    {
        wxPropertyGridState* state = GetPageState(page);

        if ( state == m_pPropGrid->GetState() )
            m_pPropGrid->Clear();
        else
            state->Clear();
    }
}

// -----------------------------------------------------------------------

void wxPropertyGridManager::SetPropertyAttributeAll( int attrid, wxVariant value )
{
    size_t i;
    for ( i=0; i<GetPageCount(); i++ )
    {
        wxPropertyGridPage* page = (wxPropertyGridPage*)m_arrPages.Item(i);

        DoSetPropertyAttribute(wxPGIdGen(page->GetStatePtr()->m_properties),attrid,value,wxPG_RECURSE);
    }
}

// -----------------------------------------------------------------------

bool wxPropertyGridManager::Compact( bool compact )
{
    bool res = m_pPropGrid->Compact(compact);
    if ( res )
    {
        if ( m_pButCompactor )
        {
            if ( compact ) m_pButCompactor->SetLabel(wxT("Expand >>"));
            else m_pButCompactor->SetLabel(wxT("<< Compact"));
        }
    }
    return res;
}

// -----------------------------------------------------------------------

size_t wxPropertyGridManager::GetPageCount() const{	if ( !(m_iFlags & wxPG_MAN_FL_PAGE_INSERTED) )		return 0;
	return m_arrPages.GetCount();}

// -----------------------------------------------------------------------

int wxPropertyGridManager::InsertPage( int index, const wxString& label,
                                       const wxBitmap& bmp, wxPropertyGridPage* pageObj )
{
    if ( index < 0 )
        index = GetPageCount();

    wxCHECK_MSG( (size_t)index == GetPageCount(), -1,
        wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));

    bool needInit = true;
    bool isPageInserted = m_iFlags & wxPG_MAN_FL_PAGE_INSERTED ? true : false;

    wxASSERT( index == 0 || isPageInserted );

    if ( !pageObj )
    {
        // No custom page object was given, so we will either re-use the default base
        // page (if index==0), or create a new default page object.
        if ( !isPageInserted )
        {
            pageObj = GetPage(0);
            // Of course, if the base page was custom, we need to delete and
            // re-create it.
            if ( !pageObj->m_isDefault )
            {
                delete pageObj;
                pageObj = new wxPropertyGridPage();
                m_arrPages[0] = pageObj;
            }
            needInit = false;
        }
        else
        {
            pageObj = new wxPropertyGridPage();
        }
        pageObj->m_isDefault = true;
    }
    else
    {
        if ( !isPageInserted )
        {
            // Initial page needs to be deleted and replaced
            delete GetPage(0);
            m_arrPages[0] = pageObj;
            m_pPropGrid->m_pState = pageObj->GetStatePtr();
        }
    }

    wxPropertyGridState* state = pageObj->GetStatePtr();

    pageObj->m_manager = this;

    if ( needInit )
    {
        state->m_pPropGrid = m_pPropGrid;
        state->InitNonCatMode();
    }

    pageObj->m_label = label;
    pageObj->m_id = m_nextTbInd;

    m_targetState = state;
    m_targetPage = index;

    if ( isPageInserted )
        m_arrPages.Add( (void*)pageObj );

#if wxUSE_TOOLBAR
    if ( m_windowStyle & wxPG_TOOLBAR )
    {
        if ( !m_pToolbar )
            RecreateControls();

        wxASSERT( m_pToolbar );

        // Add separator before first page.
        if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS) )
            m_pToolbar->AddSeparator();

        if ( &bmp != &wxNullBitmap )
            m_pToolbar->AddTool(m_nextTbInd,label,bmp,label,wxITEM_RADIO);
            //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
        else
            m_pToolbar->AddTool(m_nextTbInd,label,wxBitmap( (const char**)gs_xpm_defpage ),
                label,wxITEM_RADIO);

        m_nextTbInd++;

        m_pToolbar->Realize();
    }
#else
    wxUnusedVar(bmp);
#endif

    // If selected page was above the point of insertion, fix the current page index
    if ( isPageInserted )
    {
        if ( m_selPage >= index )
        {
            m_selPage += 1;
        }
    }
    else
    {
        // Set this value only when adding the first page
        m_selPage = 0;
    }

    pageObj->Init();

    m_iFlags |= wxPG_MAN_FL_PAGE_INSERTED;

    return index;
}

// -----------------------------------------------------------------------

bool wxPropertyGridManager::IsAnyModified() const
{
    size_t i;
    for ( i=0; i<GetPageCount(); i++ )
    {
        if ( ((wxPropertyGridPage*)m_arrPages.Item(i))->GetStatePtr()->m_anyModified )
            return true;
    }
    return false;
}

// -----------------------------------------------------------------------

bool wxPropertyGridManager::IsPageModified( size_t index ) const
{
    if ( ((wxPropertyGridPage*)m_arrPages.Item(index))->GetStatePtr()->m_anyModified )
        return true;
    return false;
}

// -----------------------------------------------------------------------

wxPGId wxPropertyGridManager::GetPageRoot( int index ) const
{
    wxASSERT( index >= 0 );
    wxASSERT( index < (int)m_arrPages.GetCount() );

    return ((wxPropertyGridPage*)m_arrPages.Item(index))->GetStatePtr()->m_properties;
}

// -----------------------------------------------------------------------

bool wxPropertyGridManager::RemovePage( int page )
{
    wxCHECK_MSG( (page >= 0) && (page < (int)GetPageCount()),
                 false,
                 wxT("invalid page index") );

    wxPropertyGridPage* pd = (wxPropertyGridPage*)m_arrPages.Item(page);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -