Exemplo n.º 1
0
bool
wxChoicebook::InsertPage(size_t n,
                         wxWindow *page,
                         const wxString& text,
                         bool bSelect,
                         int imageId)
{
    if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
        return false;

    GetChoiceCtrl()->Insert(text, n);

    // if the inserted page is before the selected one, we must update the
    // index of the selected page
    if ( int(n) <= m_selection )
    {
        // one extra page added
        m_selection++;
        GetChoiceCtrl()->Select(m_selection);
    }

    if ( !DoSetSelectionAfterInsertion(n, bSelect) )
        page->Hide();

    return true;
}
Exemplo n.º 2
0
wxWindow *wxChoicebook::DoRemovePage(size_t page)
{
    const size_t page_count = GetPageCount();
    wxWindow *win = wxBookCtrlBase::DoRemovePage(page);

    if ( win )
    {
        GetChoiceCtrl()->Delete(page);

        if (m_selection >= (int)page)
        {
            // force new sel valid if possible
            int sel = m_selection - 1;
            if (page_count == 1)
                sel = wxNOT_FOUND;
            else if ((page_count == 2) || (sel == -1))
                sel = 0;

            // force sel invalid if deleting current page - don't try to hide it
            m_selection = (m_selection == (int)page) ? wxNOT_FOUND : m_selection - 1;

            if ((sel != wxNOT_FOUND) && (sel != m_selection))
                SetSelection(sel);
           }
    }

    return win;
}
Exemplo n.º 3
0
wxWindow *wxChoicebook::DoRemovePage(size_t page)
{
    wxWindow *win = wxBookCtrlBase::DoRemovePage(page);

    if ( win )
    {
        GetChoiceCtrl()->Delete(page);

        if ( m_selection >= (int)page )
        {
            // ensure that the selection is valid
            int sel;
            if ( GetPageCount() == 0 )
                sel = wxNOT_FOUND;
            else
                sel = m_selection ? m_selection - 1 : 0;

            // if deleting current page we shouldn't try to hide it
            m_selection = m_selection == (int)page ? wxNOT_FOUND
                                                   : m_selection - 1;

            if ( sel != wxNOT_FOUND && sel != m_selection )
                SetSelection(sel);
        }
    }

    return win;
}
Exemplo n.º 4
0
	void ResizePlayers(size_t numPlayers)
	{
		wxASSERT(numPlayers <= m_Pages.size());

		// We don't really want to destroy the windows corresponding
		//	to the tabs, so we've kept them in a vector and will
		//	only remove and add them to the notebook as needed
		int selection = GetSelection();
		size_t pageCount = GetPageCount();

		if (numPlayers > pageCount)
		{
			// Add previously removed pages
			for (size_t i = pageCount; i < numPlayers; ++i)
			{
				AddPage(m_Pages[i], m_Pages[i]->GetPlayerName());
			}
		}
		else
		{
			// Remove previously added pages
			// we have to manually hide them or they remain visible
			for (size_t i = pageCount - 1; i >= numPlayers; --i)
			{
				m_Pages[i]->Hide();
				RemovePage(i);
			}
		}

		// Workaround for bug on wxGTK 2.8: wxChoice selection doesn't update
		//	(in fact it loses its selection when adding/removing pages)
		GetChoiceCtrl()->SetSelection(selection);
	}
Exemplo n.º 5
0
wxWindow *wxChoicebook::DoRemovePage(size_t page)
{
    wxWindow *win = wxBookCtrlBase::DoRemovePage(page);

    if ( win )
    {
        GetChoiceCtrl()->Delete(page);

        DoSetSelectionAfterRemoval(page);
    }

    return win;
}
Exemplo n.º 6
0
bool
wxChoicebook::InsertPage(size_t n,
                         wxWindow *page,
                         const wxString& text,
                         bool bSelect,
                         int imageId)
{
    if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
        return false;

    GetChoiceCtrl()->Insert(text, n);

    // if the inserted page is before the selected one, we must update the
    // index of the selected page
    if ( int(n) <= m_selection )
    {
        // one extra page added
        m_selection++;
        GetChoiceCtrl()->Select(m_selection);
    }

    // some page should be selected: either this one or the first one if there
    // is still no selection
    int selNew = wxNOT_FOUND;
    if ( bSelect )
        selNew = n;
    else if ( m_selection == wxNOT_FOUND )
        selNew = 0;

    if ( selNew != m_selection )
        page->Hide();

    if ( selNew != wxNOT_FOUND )
        SetSelection(selNew);

    return true;
}
Exemplo n.º 7
0
void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice)
{
    const int selNew = eventChoice.GetSelection();

    if ( selNew == m_selection )
    {
        // this event can only come from our own Select(m_selection) below
        // which we call when the page change is vetoed, so we should simply
        // ignore it
        return;
    }

    SetSelection(selNew);

    // change wasn't allowed, return to previous state
    if (m_selection != selNew)
        GetChoiceCtrl()->Select(m_selection);
}
Exemplo n.º 8
0
bool wxChoicebook::DeleteAllPages()
{
    GetChoiceCtrl()->Clear();
    return wxBookCtrlBase::DeleteAllPages();
}
Exemplo n.º 9
0
wxString wxChoicebook::GetPageText(size_t n) const
{
    return GetChoiceCtrl()->GetString(n);
}
Exemplo n.º 10
0
bool wxChoicebook::SetPageText(size_t n, const wxString& strText)
{
    GetChoiceCtrl()->SetString(n, strText);

    return true;
}
Exemplo n.º 11
0
bool wxChoicebook::DeleteAllPages()
{
    m_selection = wxNOT_FOUND;
    GetChoiceCtrl()->Clear();
    return wxBookCtrlBase::DeleteAllPages();
}