📄 resource.cpp
字号:
else if (controlType == wxT("wxRadioBox"))
{
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 ++;
// majorDim (number of rows or cols)
if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
{
controlItem->SetValue1(expr->Nth(count)->IntegerValue());
count ++;
}
else
controlItem->SetValue1(0);
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
else
{
delete controlItem;
return (wxItemResource *) NULL;
}
return controlItem;
}
// Forward declaration
wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr);
/*
* Interpet a menu item
*/
wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr)
{
wxItemResource *item = new wxItemResource;
wxExpr *labelExpr = expr->Nth(0);
wxExpr *idExpr = expr->Nth(1);
wxExpr *helpExpr = expr->Nth(2);
wxExpr *checkableExpr = expr->Nth(3);
// Further keywords/attributes to follow sometime...
if (expr->Number() == 0)
{
// item->SetType(wxRESOURCE_TYPE_SEPARATOR);
item->SetType(wxT("wxMenuSeparator"));
return item;
}
else
{
// item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
item->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
if (labelExpr)
{
wxString str(labelExpr->StringValue());
item->SetTitle(str);
}
if (idExpr)
{
int id = 0;
// If a string or word, must look up in identifier table.
if ((idExpr->Type() == PrologString) || (idExpr->Type() == PrologWord))
{
wxString str(idExpr->StringValue());
id = wxResourceGetIdentifier(str, &table);
if (id == 0)
{
wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
(const wxChar*) idExpr->StringValue());
}
}
else if (idExpr->Type() == PrologInteger)
id = (int)idExpr->IntegerValue();
item->SetValue1(id);
}
if (helpExpr)
{
wxString str(helpExpr->StringValue());
item->SetValue4(str);
}
if (checkableExpr)
item->SetValue2(checkableExpr->IntegerValue());
// Find the first expression that's a list, for submenu
wxExpr *subMenuExpr = expr->GetFirst();
while (subMenuExpr && (subMenuExpr->Type() != PrologList))
subMenuExpr = subMenuExpr->GetNext();
while (subMenuExpr)
{
wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr);
item->GetChildren().Append(child);
subMenuExpr = subMenuExpr->GetNext();
}
}
return item;
}
/*
* Interpret a nested list as a menu
*/
/*
wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
{
wxItemResource *menu = new wxItemResource;
// menu->SetType(wxTYPE_MENU);
menu->SetType("wxMenu");
wxExpr *element = expr->GetFirst();
while (element)
{
wxItemResource *item = wxResourceInterpretMenuItem(table, element);
if (item)
menu->GetChildren().Append(item);
element = element->GetNext();
}
return menu;
}
*/
wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr)
{
wxExpr *listExpr = (wxExpr *) NULL;
expr->GetAttributeValue(wxT("menu"), &listExpr);
if (!listExpr)
return (wxItemResource *) NULL;
wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr);
if (!menuResource)
return (wxItemResource *) NULL;
wxString name;
if (expr->GetAttributeValue(wxT("name"), name))
{
menuResource->SetName(name);
}
return menuResource;
}
wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr)
{
wxExpr *listExpr = (wxExpr *) NULL;
expr->GetAttributeValue(wxT("menu"), &listExpr);
if (!listExpr)
return (wxItemResource *) NULL;
wxItemResource *resource = new wxItemResource;
resource->SetType(wxT("wxMenu"));
// resource->SetType(wxTYPE_MENU);
wxExpr *element = listExpr->GetFirst();
while (element)
{
wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr);
resource->GetChildren().Append(menuResource);
element = element->GetNext();
}
wxString name;
if (expr->GetAttributeValue(wxT("name"), name))
{
resource->SetName(name);
}
return resource;
}
wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), wxExpr *WXUNUSED(expr))
{
return (wxItemResource *) NULL;
}
wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxExpr *expr)
{
wxItemResource *bitmapItem = new wxItemResource;
// bitmapItem->SetType(wxTYPE_BITMAP);
bitmapItem->SetType(wxT("wxBitmap"));
wxString name;
if (expr->GetAttributeValue(wxT("name"), name))
{
bitmapItem->SetName(name);
}
// Now parse all bitmap specifications
wxExpr *bitmapExpr = expr->GetFirst();
while (bitmapExpr)
{
if (bitmapExpr->Number() == 3)
{
wxString bitmapKeyword(bitmapExpr->Nth(1)->StringValue());
if (bitmapKeyword == wxT("bitmap") || bitmapKeyword == wxT("icon"))
{
// The value part: always a list.
wxExpr *listExpr = bitmapExpr->Nth(2);
if (listExpr->Type() == PrologList)
{
wxItemResource *bitmapSpec = new wxItemResource;
// bitmapSpec->SetType(wxTYPE_BITMAP);
bitmapSpec->SetType(wxT("wxBitmap"));
// List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
// where everything after 'filename' is optional.
wxExpr *nameExpr = listExpr->Nth(0);
wxExpr *typeExpr = listExpr->Nth(1);
wxExpr *platformExpr = listExpr->Nth(2);
wxExpr *coloursExpr = listExpr->Nth(3);
wxExpr *xresExpr = listExpr->Nth(4);
wxExpr *yresExpr = listExpr->Nth(5);
if (nameExpr && !nameExpr->StringValue().empty())
{
bitmapSpec->SetName(nameExpr->StringValue());
}
if (typeExpr && !typeExpr->StringValue().empty())
{
bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue()));
}
else
bitmapSpec->SetValue1(0);
if (platformExpr && !platformExpr->StringValue().empty())
{
wxString plat(platformExpr->StringValue());
if (plat == wxT("windows") || plat == wxT("WINDOWS"))
bitmapSpec->SetValue2(RESOURCE_PLATFORM_WINDOWS);
else if (plat == wxT("x") || plat == wxT("X"))
bitmapSpec->SetValue2(RESOURCE_PLATFORM_X);
else if (plat == wxT("mac") || plat == wxT("MAC"))
bitmapSpec->SetValue2(RESOURCE_PLATFORM_MAC);
else
bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY);
}
else
bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY);
if (coloursExpr)
bitmapSpec->SetValue3(coloursExpr->IntegerValue());
int xres = 0;
int yres = 0;
if (xresExpr)
xres = (int)xresExpr->IntegerValue();
if (yresExpr)
yres = (int)yresExpr->IntegerValue();
bitmapSpec->SetSize(0, 0, xres, yres);
bitmapItem->GetChildren().Append(bitmapSpec);
}
}
}
bitmapExpr = bitmapExpr->GetNext();
}
return bitmapItem;
}
wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr)
{
wxItemResource *item = wxResourceInterpretBitmap(table, expr);
if (item)
{
// item->SetType(wxTYPE_ICON);
item->SetType(wxT("wxIcon"));
return item;
}
else
return (wxItemResource *) NULL;
}
// Interpret list expression as a font
wxFont wxResourceInterpretFontSpec(wxExpr *expr)
{
if (expr->Type() != PrologList)
return wxNullFont;
int point = 10;
int family = wxSWISS;
int style = wxNORMAL;
int weight = wxNORMAL;
int underline = 0;
wxString faceName;
wxExpr *pointExpr = expr->Nth(0);
wxExpr *familyExpr = expr->Nth(1);
wxExpr *styleExpr = expr->Nth(2);
wxExpr *weightExpr = expr->Nth(3);
wxExpr *underlineExpr = expr->Nth(4);
wxExpr *faceNameExpr = expr->Nth(5);
if (pointExpr)
point = (int)pointExpr->IntegerValue();
wxString str;
if (familyExpr)
{
str = familyExpr->StringValue();
family = (int)wxParseWindowStyle(str);
}
if (styleExpr)
{
str = styleExpr->StringValue();
style = (int)wxParseWindowStyle(str);
}
if (weightExpr)
{
str = weightExpr->StringValue();
weight = (int)wxParseWindowStyle(str);
}
if (underlineExpr)
underline = (int)underlineExpr->IntegerValue();
if (faceNameExpr)
faceName = faceNameExpr->StringValue();
return *wxTheFontList->FindOrCreateFont(point, family, style, weight,
(underline != 0), faceName);
}
/*
* (Re)allocate buffer for reading in from resource file
*/
bool wxReallocateResourceBuffer()
{
if (!wxResourceBuffer)
{
wxResourceBufferSize = 1000;
wxResourceBuffer = new char[wxResourceBufferSize];
return true;
}
if (wxResourceBuffer)
{
long newSize = wxResourceBufferSize + 1000;
char *tmp = new char[(int)newSize];
strncpy(tmp, wxResourceBuffer, (int)wxResourceBufferCount);
delete[] wxResourceBuffer;
wxResourceBuffer = tmp;
wxResourceBufferSize = newSize;
}
return true;
}
static bool wxEatWhiteSpace(FILE *fd)
{
int ch;
while ((ch = getc(fd)) != EOF)
{
switch (ch)
{
case ' ':
case 0x0a:
case 0x0d:
case 0x09:
break;
case '/':
{
int prev_ch = ch;
ch = getc(fd);
if (ch == EOF)
{
ungetc(prev_ch, fd);
return true;
}
if (ch == '*')
{
// Eat C comment
prev_ch = 0;
while ((ch = getc(fd)) != EOF)
{
if (ch == '/' && prev_ch == '*')
break;
prev_ch = ch;
}
}
else if (ch == '/')
{
// Eat C++ comment
static char buffer[255];
fgets(buffer, 255, fd);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -