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

📄 resource.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 5 页
字号:
}

wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr)
{
    wxItemResource *controlItem = new wxItemResource;

    // First, find the standard features of a control definition:
    // [optional integer/string id], control name, title, style, name, x, y, width, height

    wxString controlType;
    wxString style;
    wxString title;
    wxString name;
    int id = 0;
    long windowStyle = 0;
    int x = 0; int y = 0; int width = wxDefaultCoord; int height = wxDefaultCoord;
    int count = 0;

    wxExpr *expr1 = expr->Nth(0);

    if ( expr1->Type() == PrologString || expr1->Type() == PrologWord )
    {
        if ( wxIsValidControlClass(expr1->StringValue()) )
        {
            count = 1;
            controlType = expr1->StringValue();
        }
        else
        {
            wxString str(expr1->StringValue());
            id = wxResourceGetIdentifier(str, &table);
            if (id == 0)
            {
                wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
                    (const wxChar*) expr1->StringValue());
                delete controlItem;
                return (wxItemResource *) NULL;
            }
            else
            {
                // Success - we have an id, so the 2nd element must be the control class.
                controlType = expr->Nth(1)->StringValue();
                count = 2;
            }
        }
    }
    else if (expr1->Type() == PrologInteger)
    {
        id = (int)expr1->IntegerValue();
        // Success - we have an id, so the 2nd element must be the control class.
        controlType = expr->Nth(1)->StringValue();
        count = 2;
    }

    expr1 = expr->Nth(count);
    count ++;
    if ( expr1 )
        title = expr1->StringValue();

    expr1 = expr->Nth(count);
    count ++;
    if (expr1)
    {
        style = expr1->StringValue();
        windowStyle = wxParseWindowStyle(style);
    }

    expr1 = expr->Nth(count);
    count ++;
    if (expr1)
        name = expr1->StringValue();

    expr1 = expr->Nth(count);
    count ++;
    if (expr1)
        x = (int)expr1->IntegerValue();

    expr1 = expr->Nth(count);
    count ++;
    if (expr1)
        y = (int)expr1->IntegerValue();

    expr1 = expr->Nth(count);
    count ++;
    if (expr1)
        width = (int)expr1->IntegerValue();

    expr1 = expr->Nth(count);
    count ++;
    if (expr1)
        height = (int)expr1->IntegerValue();

    controlItem->SetStyle(windowStyle);
    controlItem->SetName(name);
    controlItem->SetTitle(title);
    controlItem->SetSize(x, y, width, height);
    controlItem->SetType(controlType);
    controlItem->SetId(id);

    // Check for wxWin 1.68-style specifications
    if (style.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND)
        controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL);
    else if (style.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND)
        controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL);

    if (controlType == wxT("wxButton"))
    {
        // Check for bitmap resource name (in case loading old-style resource file)
        if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
        {
            wxString str(expr->Nth(count)->StringValue());
            count ++;

            if (!str.empty())
            {
                controlItem->SetValue4(str);
                controlItem->SetType(wxT("wxBitmapButton"));
            }
        }
        if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
            controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
    }
    else if (controlType == wxT("wxBitmapButton"))
    {
        // Check for bitmap resource name
        if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
        {
            wxString str(expr->Nth(count)->StringValue());
            controlItem->SetValue4(str);
            count ++;
            if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
                controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
        }
    }
    else if (controlType == wxT("wxCheckBox"))
    {
        // Check for default value
        if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
        {
            controlItem->SetValue1(expr->Nth(count)->IntegerValue());
            count ++;
            if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
                controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
        }
    }
#if wxUSE_RADIOBTN
    else if (controlType == wxT("wxRadioButton"))
    {
        // Check for default value
        if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
        {
            controlItem->SetValue1(expr->Nth(count)->IntegerValue());
            count ++;
            if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
                controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
        }
    }
#endif
    else if (controlType == wxT("wxText") || controlType == wxT("wxTextCtrl") || controlType == wxT("wxMultiText"))
    {
        // Check for default value
        if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
        {
            wxString str(expr->Nth(count)->StringValue());
            controlItem->SetValue4(str);
            count ++;

            if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
            {
                // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
                // Skip past the obsolete label font spec if there are two consecutive specs
                if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
                    count ++;
                controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
            }
        }
    }
    else if (controlType == wxT("wxMessage") || controlType == wxT("wxStaticText"))
    {
        // Check for bitmap resource name (in case it's an old-style .wxr file)
        if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
        {
            wxString str(expr->Nth(count)->StringValue());
            controlItem->SetValue4(str);
            count ++;
            controlItem->SetType(wxT("wxStaticText"));
        }
        if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
            controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
    }
    else if (controlType == wxT("wxStaticBitmap"))
    {
        // Check for bitmap resource name
        if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
        {
            wxString str(expr->Nth(count)->StringValue());
            controlItem->SetValue4(str);
            count ++;
        }
        if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
            controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
    }
    else if (controlType == wxT("wxGroupBox") || controlType == wxT("wxStaticBox"))
    {
        if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
            controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
    }
    else if (controlType == wxT("wxGauge"))
    {
        // Check for default value
        if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
        {
            controlItem->SetValue1(expr->Nth(count)->IntegerValue());
            count ++;

            // Check for range
            if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
            {
                controlItem->SetValue2(expr->Nth(count)->IntegerValue());
                count ++;

                if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
                {
                    // Skip past the obsolete label font spec if there are two consecutive specs
                    if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
                        count ++;
                    controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
                }
            }
        }
    }
    else if (controlType == wxT("wxSlider"))
    {
        // Check for default value
        if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
        {
            controlItem->SetValue1(expr->Nth(count)->IntegerValue());
            count ++;

            // Check for min
            if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
            {
                controlItem->SetValue2(expr->Nth(count)->IntegerValue());
                count ++;

                // Check for max
                if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
                {
                    controlItem->SetValue3(expr->Nth(count)->IntegerValue());
                    count ++;

                    if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
                    {
                        // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
                        // do nothing
                        count ++;

                        if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
                            controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
                    }
                }
            }
        }
    }
    else if (controlType == wxT("wxScrollBar"))
    {
        // DEFAULT VALUE
        if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
        {
            controlItem->SetValue1(expr->Nth(count)->IntegerValue());
            count ++;

            // PAGE LENGTH
            if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
            {
                controlItem->SetValue2(expr->Nth(count)->IntegerValue());
                count ++;

                // OBJECT LENGTH
                if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
                {
                    controlItem->SetValue3(expr->Nth(count)->IntegerValue());
                    count ++;

                    // VIEW LENGTH
                    if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
                        controlItem->SetValue5(expr->Nth(count)->IntegerValue());
                }
            }
        }
    }
    else if (controlType == wxT("wxListBox"))
    {
        wxExpr *valueList = (wxExpr *) NULL;

        if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList))
        {
            wxStringList stringList;
            wxExpr *stringExpr = valueList->GetFirst();
            while (stringExpr)
            {
                stringList.Add(stringExpr->StringValue());
                stringExpr = stringExpr->GetNext();
            }
            controlItem->SetStringValues(stringList);
            count ++;
            // This is now obsolete: it's in the window style.
            // Check for wxSINGLE/wxMULTIPLE
            wxExpr *mult = (wxExpr *) NULL;
            /*
            controlItem->SetValue1(wxLB_SINGLE);
            */
            if (((mult = expr->Nth(count)) != 0) && ((mult->Type() == PrologString)||(mult->Type() == PrologWord)))
            {
            /*
            wxString m(mult->StringValue());
            if (m == "wxLB_MULTIPLE")
            controlItem->SetValue1(wxLB_MULTIPLE);
            else if (m == "wxLB_EXTENDED")
            controlItem->SetValue1(wxLB_EXTENDED);
                */
                // Ignore the value
                count ++;
            }
            if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
            {
                // Skip past the obsolete label font spec if there are two consecutive specs
                if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
                    count ++;
                controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
            }
        }
    }
    else if (controlType == wxT("wxChoice"))
    {
        wxExpr *valueList = (wxExpr *) NULL;
        // Check for default value list
        if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList))
        {
            wxStringList stringList;
            wxExpr *stringExpr = valueList->GetFirst();
            while (stringExpr)
            {
                stringList.Add(stringExpr->StringValue());
                stringExpr = stringExpr->GetNext();
            }
            controlItem->SetStringValues(stringList);

            count ++;

            if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
            {
                // Skip past the obsolete label font spec if there are two consecutive specs
                if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
                    count ++;
                controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
            }
        }
    }
#if wxUSE_COMBOBOX
    else if (controlType == wxT("wxComboBox"))
    {
        wxExpr *textValue = expr->Nth(count);
        if (textValue && (textValue->Type() == PrologString || textValue->Type() == PrologWord))
        {
            wxString str(textValue->StringValue());
            controlItem->SetValue4(str);

            count ++;

            wxExpr *valueList = (wxExpr *) NULL;
            // Check for default value list
            if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList))
            {
                wxStringList stringList;
                wxExpr *stringExpr = valueList->GetFirst();
                while (stringExpr)
                {
                    stringList.Add(stringExpr->StringValue());
                    stringExpr = stringExpr->GetNext();
                }
                controlItem->SetStringValues(stringList);

                count ++;

                if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
                {
                    // Skip past the obsolete label font spec if there are two consecutive specs
                    if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
                        count ++;
                    controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
                }
            }
        }
    }
#endif
#if 1

⌨️ 快捷键说明

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