📄 resource.cpp
字号:
((wxGauge *)control)->SetValue((int)childResource->GetValue1()); }#endif#if wxUSE_RADIOBTN else if (itemType == wxString(wxT("wxRadioButton"))) { control = new wxRadioButton(parent, id, childResource->GetTitle(), // (int)childResource->GetValue1(), pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); }#endif#if wxUSE_SCROLLBAR else if (itemType == wxString(wxT("wxScrollBar"))) { control = new wxScrollBar(parent, id, pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); /* ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1()); ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2()); ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3()); ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5()); */ ((wxScrollBar *)control)->SetScrollbar((int)childResource->GetValue1(),(int)childResource->GetValue2(), (int)childResource->GetValue3(),(int)(long)childResource->GetValue5(),false); }#endif else if (itemType == wxString(wxT("wxSlider"))) { control = new wxSlider(parent, id, (int)childResource->GetValue1(), (int)childResource->GetValue2(), (int)childResource->GetValue3(), pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); } else if (itemType == wxString(wxT("wxGroupBox")) || itemType == wxString(wxT("wxStaticBox"))) { control = new wxStaticBox(parent, id, childResource->GetTitle(), pos, size, childResource->GetStyle(), childResource->GetName()); } else if (itemType == wxString(wxT("wxListBox"))) { wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; if (stringList.GetCount() > 0) { noStrings = stringList.GetCount(); strings = new wxString[noStrings]; wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { strings[i] = (wxChar *)node->GetData(); i ++; node = node->GetNext(); } } control = new wxListBox(parent, id, pos, size, noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); if (strings) delete[] strings; } else if (itemType == wxString(wxT("wxChoice"))) { wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; if (stringList.GetCount() > 0) { noStrings = stringList.GetCount(); strings = new wxString[noStrings]; wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { strings[i] = (wxChar *)node->GetData(); i ++; node = node->GetNext(); } } control = new wxChoice(parent, id, pos, size, noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); if (strings) delete[] strings; }#if wxUSE_COMBOBOX else if (itemType == wxString(wxT("wxComboBox"))) { wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; if (stringList.GetCount() > 0) { noStrings = stringList.GetCount(); strings = new wxString[noStrings]; wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { strings[i] = (wxChar *)node->GetData(); i ++; node = node->GetNext(); } } control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size, noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); if (strings) delete[] strings; }#endif else if (itemType == wxString(wxT("wxRadioBox"))) { wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; if (stringList.GetCount() > 0) { noStrings = stringList.GetCount(); strings = new wxString[noStrings]; wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { strings[i] = (wxChar *)node->GetData(); i ++; node = node->GetNext(); } } control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size, noStrings, strings, (int)childResource->GetValue1(), childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); if (strings) delete[] strings; } if ((parentResource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) { // Don't set font; will be inherited from parent. } else { if (control && childResource->GetFont().Ok()) { control->SetFont(childResource->GetFont());#ifdef __WXMSW__ // Force the layout algorithm since the size changes the layout if (control->IsKindOf(CLASSINFO(wxRadioBox))) { control->SetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT); }#endif } } return control;}/** Interpret database as a series of resources*/bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db){ wxNode *node = db.GetFirst(); while (node) { wxExpr *clause = (wxExpr *)node->GetData(); wxString functor(clause->Functor()); wxItemResource *item = (wxItemResource *) NULL; if (functor == wxT("dialog")) item = wxResourceInterpretDialog(table, clause); else if (functor == wxT("panel")) item = wxResourceInterpretDialog(table, clause, true); else if (functor == wxT("menubar")) item = wxResourceInterpretMenuBar(table, clause); else if (functor == wxT("menu")) item = wxResourceInterpretMenu(table, clause); else if (functor == wxT("string")) item = wxResourceInterpretString(table, clause); else if (functor == wxT("bitmap")) item = wxResourceInterpretBitmap(table, clause); else if (functor == wxT("icon")) item = wxResourceInterpretIcon(table, clause); if (item) { // Remove any existing resource of same name if (!item->GetName().empty()) table.DeleteResource(item->GetName()); table.AddResource(item); } node = node->GetNext(); } return true;}static const wxChar *g_ValidControlClasses[] ={ wxT("wxButton"), wxT("wxBitmapButton"), wxT("wxMessage"), wxT("wxStaticText"), wxT("wxStaticBitmap"), wxT("wxText"), wxT("wxTextCtrl"), wxT("wxMultiText"), wxT("wxListBox"), wxT("wxRadioBox"), wxT("wxRadioButton"), wxT("wxCheckBox"), wxT("wxBitmapCheckBox"), wxT("wxGroupBox"), wxT("wxStaticBox"), wxT("wxSlider"), wxT("wxGauge"), wxT("wxScrollBar"), wxT("wxChoice"), wxT("wxComboBox")};static bool wxIsValidControlClass(const wxString& c){ for ( size_t i = 0; i < WXSIZEOF(g_ValidControlClasses); i++ ) { if ( c == g_ValidControlClasses[i] ) return true; } return false;}wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel){ wxItemResource *dialogItem = new wxItemResource; if (isPanel) dialogItem->SetType(wxT("wxPanel")); else dialogItem->SetType(wxT("wxDialog")); wxString style = wxEmptyString; wxString title = wxEmptyString; wxString name = wxEmptyString; wxString backColourHex = wxEmptyString; wxString labelColourHex = wxEmptyString; wxString buttonColourHex = wxEmptyString; long windowStyle = wxDEFAULT_DIALOG_STYLE; if (isPanel) windowStyle = 0; int x = 0; int y = 0; int width = wxDefaultCoord; int height = wxDefaultCoord; int isModal = 0; wxExpr *labelFontExpr = (wxExpr *) NULL; wxExpr *buttonFontExpr = (wxExpr *) NULL; wxExpr *fontExpr = (wxExpr *) NULL; expr->GetAttributeValue(wxT("style"), style); expr->GetAttributeValue(wxT("name"), name); expr->GetAttributeValue(wxT("title"), title); expr->GetAttributeValue(wxT("x"), x); expr->GetAttributeValue(wxT("y"), y); expr->GetAttributeValue(wxT("width"), width); expr->GetAttributeValue(wxT("height"), height); expr->GetAttributeValue(wxT("modal"), isModal); expr->GetAttributeValue(wxT("label_font"), &labelFontExpr); expr->GetAttributeValue(wxT("button_font"), &buttonFontExpr); expr->GetAttributeValue(wxT("font"), &fontExpr); expr->GetAttributeValue(wxT("background_colour"), backColourHex); expr->GetAttributeValue(wxT("label_colour"), labelColourHex); expr->GetAttributeValue(wxT("button_colour"), buttonColourHex); int useDialogUnits = 0; expr->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits); if (useDialogUnits != 0) dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS); int useDefaults = 0; expr->GetAttributeValue(wxT("use_system_defaults"), useDefaults); if (useDefaults != 0) dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS); int id = 0; expr->GetAttributeValue(wxT("id"), id); dialogItem->SetId(id); if (!style.empty()) { windowStyle = wxParseWindowStyle(style); } dialogItem->SetStyle(windowStyle); dialogItem->SetValue1(isModal);#if WXWIN_COMPATIBILITY_2_6#ifdef __VMS#pragma message disable CODCAUUNR#endif if (windowStyle & wxDIALOG_MODAL) // Uses style in wxWin 2 dialogItem->SetValue1(true);#ifdef __VMS#pragma message enable CODCAUUNR#endif#endif // WXWIN_COMPATIBILITY_2_6 dialogItem->SetName(name); dialogItem->SetTitle(title); dialogItem->SetSize(x, y, width, height); // Check for wxWin 1.68-style specifications if (style.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND) dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL); else if (style.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND) dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL); if (!backColourHex.empty()) { int r = 0; int g = 0; int b = 0; r = wxHexToDec(backColourHex.Mid(0, 2)); g = wxHexToDec(backColourHex.Mid(2, 2)); b = wxHexToDec(backColourHex.Mid(4, 2)); dialogItem->SetBackgroundColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); } if (!labelColourHex.empty()) { int r = 0; int g = 0; int b = 0; r = wxHexToDec(labelColourHex.Mid(0, 2)); g = wxHexToDec(labelColourHex.Mid(2, 2)); b = wxHexToDec(labelColourHex.Mid(4, 2)); dialogItem->SetLabelColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); } if (!buttonColourHex.empty()) { int r = 0; int g = 0; int b = 0; r = wxHexToDec(buttonColourHex.Mid(0, 2)); g = wxHexToDec(buttonColourHex.Mid(2, 2)); b = wxHexToDec(buttonColourHex.Mid(4, 2)); dialogItem->SetButtonColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); } if (fontExpr) dialogItem->SetFont(wxResourceInterpretFontSpec(fontExpr)); else if (buttonFontExpr) dialogItem->SetFont(wxResourceInterpretFontSpec(buttonFontExpr)); else if (labelFontExpr) dialogItem->SetFont(wxResourceInterpretFontSpec(labelFontExpr)); // Now parse all controls wxExpr *controlExpr = expr->GetFirst(); while (controlExpr) { if (controlExpr->Number() == 3) { wxString controlKeyword(controlExpr->Nth(1)->StringValue()); if (!controlKeyword.empty() && controlKeyword == wxT("control")) { // The value part: always a list. wxExpr *listExpr = controlExpr->Nth(2); if (listExpr->Type() == PrologList) { wxItemResource *controlItem = wxResourceInterpretControl(table, listExpr); if (controlItem) { dialogItem->GetChildren().Append(controlItem); } } } } controlExpr = controlExpr->GetNext(); } return dialogItem;}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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -