Esempio n. 1
0
INT NextID(
    INT idType,
    NPLABEL plHead,
    INT idExclude)
{
    INT id;

    if (idType == NEXTID_CONTROL) {
        /*
         * Start at the base from the dialog plus one.  It is
         * assumed that this routine will not be called for an
         * id for a control if there is not a dialog being
         * edited first.
         */
        id = gcd.npc->id + 1;

        /*
         * Keep looping until an unused id is found.
         */
        while (!IsUniqueID(id) || FindID(id, plHead) || id == idExclude)
            id++;
    }
    else if (idType == NEXTID_DIALOG) {
        /*
         * Start at 100.
         */
        id = 100;

        /*
         * Keep looping by hundreds until an unused id is found.
         */
        while (!IsUniqueID(id) || FindID(id, plHead) || id == idExclude)
            id += 100;
    }
    else {
        /*
         * We are looking for a default id for a new label.  Start
         * at the dialog base, if there is a dialog being edited.
         */
        if (gfEditingDlg)
            id = gcd.npc->id + 1;
        else
            id = 100;

        /*
         * Keep looping until an unused id is found.  The id should
         * not be used by any control in the current dialog, any
         * other label already, or any control in the res file.
         */
        while (FindID(id, plHead) || FindIDInRes(id) || id == idExclude)
            id++;
    }

    /*
     * We found an unused one.  Return it.
     */
    return id;
}
Esempio n. 2
0
void Compiler::MakeValidID()
{
    // basically, make it XML-element compatible
    // only allow a-z, 0-9 and _
    // (it is already lowercase)
    // any non-conformant character will be removed

    wxString newID;
    if (m_ID.IsEmpty())
        m_ID = m_Name;

    size_t pos = 0;
    while (pos < m_ID.Length())
    {
        wxChar ch = m_ID[pos];
        if (wxIsalnum(ch) || ch == _T('_')) // valid character
            newID.Append(ch);
        else if (wxIsspace(ch)) // convert spaces to underscores
            newID.Append(_T('_'));
        ++pos;
    }

    // make sure it's not starting with a number.
    // if it is, prepend "cb"
    if (wxIsdigit(newID.GetChar(0)))
        newID.Prepend(_T("cb"));

    if (newID.IsEmpty()) // empty? wtf?
        cbThrow(_T("Can't create a valid compiler ID for ") + m_Name);
    m_ID = newID.Lower();

    // check for unique ID
    if (!IsUniqueID(m_ID))
        cbThrow(_T("Compiler ID already exists for ") + m_Name);
    m_CompilerIDs.Add(m_ID);
}