void
wxHeaderCtrlBase::DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int count)
{
    // update the column indices array if necessary
    const unsigned countOld = colIndices.size();
    if ( count > countOld )
    {
        // all new columns have default positions equal to their indices
        for ( unsigned n = countOld; n < count; n++ )
            colIndices.push_back(n);
    }
    else if ( count < countOld )
    {
        // filter out all the positions which are invalid now while keeping the
        // order of the remaining ones
        wxArrayInt colIndicesNew;
        colIndicesNew.reserve(count);
        for ( unsigned n = 0; n < countOld; n++ )
        {
            const unsigned idx = colIndices[n];
            if ( idx < count )
                colIndicesNew.push_back(idx);
        }

        colIndices.swap(colIndicesNew);
    }
    //else: count didn't really change, nothing to do

    wxASSERT_MSG( colIndices.size() == count, "logic error" );
}
示例#2
0
void SubtitlesGrid::DeleteLines(wxArrayInt target, bool flagModified) {
	entryIter before_first = std::find_if(context->ass->Line.begin(), context->ass->Line.end(), cast<AssDialogue*>()); --before_first;

	int row = -1;
	size_t deleted = 0;
	for (entryIter cur = context->ass->Line.begin(); cur != context->ass->Line.end();) {
		if (dynamic_cast<AssDialogue*>(*cur) && ++row == target[deleted]) {
			delete *cur;
			cur = context->ass->Line.erase(cur);
			++deleted;
			if (deleted == target.size()) break;
		}
		else {
			++cur;
		}
	}

	// Add default line if file was wiped
	if ((size_t)GetRows() == deleted) {
		AssDialogue *def = new AssDialogue;
		++before_first;
		context->ass->Line.insert(before_first, def);
	}

	if (flagModified) {
		context->ass->Commit(_("delete"), AssFile::COMMIT_DIAG_ADDREM);
	}
	else {
		UpdateMaps();
	}
}
/* static */
void wxHeaderCtrlBase::MoveColumnInOrderArray(wxArrayInt& order,
        unsigned int idx,
        unsigned int pos)
{
    const unsigned count = order.size();

    wxArrayInt orderNew;
    orderNew.reserve(count);
    for ( unsigned n = 0; ; n++ )
    {
        // NB: order of checks is important for this to work when the new
        //     column position is the same as the old one

        // insert the column at its new position
        if ( orderNew.size() == pos )
            orderNew.push_back(idx);

        if ( n == count )
            break;

        // delete the column from its old position
        const unsigned idxOld = order[n];
        if ( idxOld == idx )
            continue;

        orderNew.push_back(idxOld);
    }

    order.swap(orderNew);
}
wxArrayInt wxHeaderCtrlBase::GetColumnsOrder() const
{
    const wxArrayInt order = DoGetColumnsOrder();

    wxASSERT_MSG( order.size() == GetColumnCount(), "invalid order array" );

    return order;
}
示例#5
0
文件: Main.cpp 项目: OpenMORA/viz-pkg
size_t findMax(const wxArrayInt &a,size_t from)	{
	size_t res=from;
	int mx=a[res];
	for (size_t i=from+1;i<a.size();++i) if (a[i]>mx)	{
		mx=a[i];
		res=i;
	}
	return res;
}
示例#6
0
unsigned int wxCheckListBoxBase::GetCheckedItems(wxArrayInt& checkedItems) const
{
    unsigned int const numberOfItems = GetCount();

    checkedItems.clear();
    for ( unsigned int i = 0; i < numberOfItems; ++i )
    {
        if ( IsChecked(i) )
            checkedItems.push_back(i);
    }

    return checkedItems.size();
}
示例#7
0
static wxString DumpIntArray(const wxArrayInt& a)
{
    wxString s("{ ");
    const size_t count = a.size();
    for ( size_t n = 0; n < count; n++ )
    {
        if ( n )
            s += ", ";
        s += wxString::Format("%lu", (unsigned long)a[n]);
    }

    s += " }";

    return s;
}
示例#8
0
bool wxRearrangeList::Create(wxWindow *parent,
                             wxWindowID id,
                             const wxPoint& pos,
                             const wxSize& size,
                             const wxArrayInt& order,
                             const wxArrayString& items,
                             long style,
                             const wxValidator& validator,
                             const wxString& name)
{
    // construct the array of items in the order in which they should appear in
    // the control
    const size_t count = items.size();
    wxCHECK_MSG( order.size() == count, false, "arrays not in sync" );

    wxArrayString itemsInOrder;
    itemsInOrder.reserve(count);
    size_t n;
    for ( n = 0; n < count; n++ )
    {
        int idx = order[n];
        if ( idx < 0 )
            idx = -idx - 1;
        itemsInOrder.push_back(items[idx]);
    }

    // do create the real control
    if ( !wxCheckListBox::Create(parent, id, pos, size, itemsInOrder,
                                 style, validator, name) )
        return false;

    // and now check all the items which should be initially checked
    for ( n = 0; n < count; n++ )
    {
        if ( order[n] >= 0 )
        {
            // Be careful to call the base class version here and not our own
            // which would also update m_order itself.
            wxCheckListBox::Check(n);
        }
    }

    m_order = order;

    return true;
}
void wxHeaderCtrlBase::SetColumnsOrder(const wxArrayInt& order)
{
    const unsigned count = GetColumnCount();
    wxCHECK_RET( order.size() == count, "wrong number of columns" );

    // check the array validity
    wxArrayInt seen(count, 0);
    for ( unsigned n = 0; n < count; n++ )
    {
        const unsigned idx = order[n];
        wxCHECK_RET( idx < count, "invalid column index" );
        wxCHECK_RET( !seen[idx], "duplicate column index" );

        seen[idx] = 1;
    }

    DoSetColumnsOrder(order);

    // TODO-RTL: do we need to reverse the array?
}
示例#10
0
void GridFrame::OnShowSelection(wxCommandEvent& WXUNUSED(event))
{
    // max number of elements to dump -- otherwise it can take too much time
    static const size_t countMax = 100;

    bool rows = false;

    switch ( grid->GetSelectionMode() )
    {
        case wxGrid::wxGridSelectCells:
            {
                const wxGridCellCoordsArray cells(grid->GetSelectedCells());
                size_t count = cells.size();
                wxLogMessage(_T("%lu cells selected:"), (unsigned long)count);
                if ( count > countMax )
                {
                    wxLogMessage(_T("[too many selected cells, ")
                                 _T("showing only the first %lu]"),
                                 (unsigned long)countMax);
                    count = countMax;
                }

                for ( size_t n = 0; n < count; n++ )
                {
                    const wxGridCellCoords& c = cells[n];
                    wxLogMessage(_T("  selected cell %lu: (%d, %d)"),
                                 (unsigned long)n, c.GetCol(), c.GetRow());
                }
            }
            break;

        case wxGrid::wxGridSelectRows:
            rows = true;
            // fall through

        case wxGrid::wxGridSelectColumns:
            {
                const wxChar *plural, *single;
                if ( rows )
                {
                    plural = _T("rows");
                    single = _T("row");
                }
                else // columns
                {
                    plural = _T("columns");
                    single = _T("column");
                }

                // NB: extra parentheses needed to avoid bcc 5.82 errors
                const wxArrayInt sels((rows ? grid->GetSelectedRows()
                                            : grid->GetSelectedCols()));
                size_t count = sels.size();
                wxLogMessage(_T("%lu %s selected:"),
                             (unsigned long)count, plural);
                if ( count > countMax )
                {
                    wxLogMessage(_T("[too many selected %s, ")
                                 _T("showing only the first %lu]"),
                                 plural, (unsigned long)countMax);
                    count = countMax;
                }

                for ( size_t n = 0; n < count; n++ )
                {
                    wxLogMessage(_T("  selected %s %lu: %d"),
                                 single, (unsigned long)n, sels[n]);
                }
            }
            break;

        default:
            wxFAIL_MSG( _T("unknown wxGrid selection mode") );
            break;
    }
}
示例#11
0
文件: Main.cpp 项目: OpenMORA/viz-pkg
void sortDescending(wxArrayInt &a)	{
	for (size_t i=0;i<a.size()-1;++i)	{
		size_t idx=findMax(a,i);
		if (idx!=i) swap(a[i],a[idx]);
	}
}
示例#12
0
    // returns all new dirs/files present in the immediate level of the dir
    // pointed by watch.GetPath(). "new" means created between the last time
    // the state of watch was computed and now
    void FindChanges(wxFSWatchEntryKq& watch,
                     wxArrayString& changedFiles,
                     wxArrayInt& changedFlags)
    {
        wxFSWatchEntryKq::wxDirState old = watch.GetLastState();
        watch.RefreshState();
        wxFSWatchEntryKq::wxDirState curr = watch.GetLastState();

        // iterate over old/curr file lists and compute changes
        wxArrayString::iterator oit = old.files.begin();
        wxArrayString::iterator cit = curr.files.begin();
        for ( ; oit != old.files.end() && cit != curr.files.end(); )
        {
            if ( *cit == *oit )
            {
                ++cit;
                ++oit;
            }
            else if ( *cit <= *oit )
            {
                changedFiles.push_back(*cit);
                changedFlags.push_back(wxFSW_EVENT_CREATE);
                ++cit;
            }
            else // ( *cit > *oit )
            {
                changedFiles.push_back(*oit);
                changedFlags.push_back(wxFSW_EVENT_DELETE);
                ++oit;
            }
        }

        // border conditions
        if ( oit == old.files.end() )
        {
            for ( ; cit != curr.files.end(); ++cit )
            {
                changedFiles.push_back( *cit );
                changedFlags.push_back(wxFSW_EVENT_CREATE);
            }
        }
        else if ( cit == curr.files.end() )
        {
            for ( ; oit != old.files.end(); ++oit )
            {
                changedFiles.push_back( *oit );
                changedFlags.push_back(wxFSW_EVENT_DELETE);
            }
        }

        wxASSERT( changedFiles.size() == changedFlags.size() );

#if 0
        wxLogTrace(wxTRACE_FSWATCHER, "Changed files:");
        wxArrayString::iterator it = changedFiles.begin();
        wxArrayInt::iterator it2 = changedFlags.begin();
        for ( ; it != changedFiles.end(); ++it, ++it2)
        {
            wxString action = (*it2 == wxFSW_EVENT_CREATE) ?
                                "created" : "deleted";
            wxLogTrace(wxTRACE_FSWATCHER, wxString::Format("File: '%s' %s",
                        *it, action));
        }
#endif
    }