📄 theme.cpp
字号:
}
if (iVersionMajor != iThemeVersionMajor ||
iVersionMinor != iThemeVersionMinor)
{
char szError[512];
sprintf(szError, "This ThemeManager cannot use version %d.%d "
"themes", iVersionMajor, iVersionMinor);
m_oLastError = string(szError);
return kError_ParseError;
}
return kError_NoErr;
}
if (oElement == string("Bitmap"))
{
Bitmap *pBitmap;
Color oColor;
#ifdef WIN32
pBitmap = new Win32Bitmap(oAttrMap["Name"]);
#elif defined(HAVE_GTK)
pBitmap = new GTKBitmap(oAttrMap["Name"]);
#elif defined(__BEOS__)
pBitmap = new BeOSBitmap(oAttrMap["Name"]);
#endif
if (oAttrMap.find("TransColor") != oAttrMap.end())
{
eRet = ParseColor(oAttrMap["TransColor"], oColor);
if (eRet == kError_NoErr)
pBitmap->SetTransColor(oColor);
}
if (oAttrMap.find("File") == oAttrMap.end())
{
m_oLastError = string("the <Bitmap> tag needs a File attribute");
return kError_ParseError;
}
oCompleteFile = m_oThemePath + oAttrMap["File"];
eRet = pBitmap->LoadBitmapFromDisk(oCompleteFile);
if (eRet != kError_NoErr)
{
string oBitmapErr;
pBitmap->GetErrorString(oBitmapErr);
m_oLastError = string("Cannot load bitmap ") +
oAttrMap["File"] + string(": ") + oBitmapErr;
return eRet;
}
if (!m_pParsedBitmaps)
m_pParsedBitmaps = new vector<Bitmap *>;
m_pParsedBitmaps->push_back(pBitmap);
return kError_NoErr;
}
if (oElement == string("Font"))
{
Font *pFont;
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <Font> tag needs a Name attribute");
return kError_ParseError;
}
if (oAttrMap.find("Face") == oAttrMap.end() &&
oAttrMap.find("File") == oAttrMap.end())
{
m_oLastError = string("the <Font> tag needs a Face or File attribute");
return kError_ParseError;
}
if (oAttrMap.find("File") != oAttrMap.end())
oCompleteFile = m_oThemePath + oAttrMap["File"];
else
oCompleteFile = "";
#ifdef WIN32
pFont = new Win32Font(oAttrMap["Name"], oAttrMap["Face"],
oCompleteFile, m_oDefaultFont);
#elif defined (HAVE_GTK)
pFont = new GTKFont(m_pContext, oAttrMap["Name"], oAttrMap["Face"],
oCompleteFile, m_oDefaultFont);
#elif defined (__BEOS__)
pFont = new BeOSFont(oAttrMap["Name"], oAttrMap["Face"],
oCompleteFile, m_oDefaultFont);
#endif
if (!m_pParsedFonts)
m_pParsedFonts = new vector<Font *>;
m_pParsedFonts->push_back(pFont);
return kError_NoErr;
}
if (oElement == string("Window"))
{
if (m_pCurrentWindow)
{
m_oLastError = string("<Window> tags cannot be nested");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <Window> tag needs a Name attribute");
return kError_ParseError;
}
#ifdef WIN32
m_pCurrentWindow = new Win32Window(this, oAttrMap["Name"]);
#elif defined(HAVE_GTK)
m_pCurrentWindow = new GTKWindow(this, oAttrMap["Name"]);
#elif defined(__BEOS__)
m_pCurrentWindow = new BeOSWindow(this, oAttrMap["Name"]);
#endif
return kError_NoErr;
}
if (oElement == string("BackgroundBitmap"))
{
Canvas *pCanvas;
Bitmap *pBitmap;
Rect oRect;
if (m_pCurrentWindow == NULL)
{
m_oLastError = string("<BackgroundBitmap> must occur inside "
"of a <Window> tag");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <BackgroundBitmap> tag needs a Name attribute");
return kError_ParseError;
}
pBitmap = FindBitmap(oAttrMap["Name"]);
if (pBitmap == NULL)
{
m_oLastError = string("Undefined bitmap ") +
oAttrMap["Name"] +
string("in tag <BackgroundBitmap>");
return kError_InvalidParam;
}
if (oAttrMap.find("Rect") == oAttrMap.end())
{
m_oLastError = string("the <BackgroundBitmap> tag needs a Rect attribute");
return kError_ParseError;
}
eRet = ParseRect(oAttrMap["Rect"], oRect);
if (eRet != kError_NoErr)
{
m_oLastError = string("Improperly formatted rect coordinates: ") +
oAttrMap["Rect"];
return kError_InvalidParam;
}
pCanvas = m_pCurrentWindow->GetCanvas();
pCanvas->SetBackgroundBitmap(pBitmap);
pCanvas->SetBackgroundRect(oRect);
return kError_NoErr;
}
if (oElement == string("Controls"))
{
if (m_pCurrentWindow == NULL)
{
m_oLastError = string("<Controls> must occur inside of a "
"<Window> tag");
return kError_InvalidParam;
}
return kError_NoErr;
}
if (oElement == string("ButtonControl"))
{
m_bPosDefined = m_bBitmapDefined = m_bInfoDefined = false;
if (m_pCurrentControl)
{
m_oLastError = string("Controls cannot be nested");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <ButtonControl> tag needs a Name attribute");
return kError_ParseError;
}
if (oAttrMap.find("URL") != oAttrMap.end() &&
oAttrMap["Name"] != string("Logo"))
{
m_oLastError = string("only the Logo button can have a URL attribute");
return kError_ParseError;
}
m_eCurrentControl = eButtonControl;
if (oAttrMap.find("URL") != oAttrMap.end())
m_pCurrentControl = new ButtonControl(m_pCurrentWindow,
oAttrMap["Name"],
oAttrMap["URL"]);
else
m_pCurrentControl = new ButtonControl(m_pCurrentWindow,
oAttrMap["Name"]);
return kError_NoErr;
}
if (oElement == string("DialControl"))
{
m_bPosDefined = m_bBitmapDefined = m_bInfoDefined = false;
if (m_pCurrentControl)
{
m_oLastError = string("Controls cannot be nested");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <DialControl> tag needs a Name attribute");
return kError_ParseError;
}
if (oAttrMap.find("NumFrames") == oAttrMap.end())
{
m_oLastError = string("the <MultiStateControl> tag needs a NumFrames attribute");
return kError_ParseError;
}
if (oAttrMap.find("PixelsPerFrame") == oAttrMap.end())
{
m_oLastError = string("the <MultiStateControl> tag needs a PixelsPerFrame attribute");
return kError_ParseError;
}
m_eCurrentControl = eDialControl;
m_pCurrentControl = new DialControl(m_pCurrentWindow,
oAttrMap["Name"],
atoi(oAttrMap["NumFrames"].c_str()),
atoi(oAttrMap["PixelsPerFrame"].c_str()));
return kError_NoErr;
}
if (oElement == string("MultiStateControl"))
{
m_bPosDefined = m_bBitmapDefined = m_bInfoDefined = false;
if (m_pCurrentControl)
{
m_oLastError = string("Controls cannot be nested");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <MultiStateControl> tag needs a Name attribute");
return kError_ParseError;
}
if (oAttrMap.find("NumStates") == oAttrMap.end())
{
m_oLastError = string("the <MultiStateControl> tag needs a NumStates attribute");
return kError_ParseError;
}
m_eCurrentControl = eMultiStateControl;
m_pCurrentControl = new MultiStateControl(m_pCurrentWindow,
oAttrMap["Name"],
atoi(oAttrMap["NumStates"].
c_str()));
return kError_NoErr;
}
if (oElement == string("SliderControl"))
{
m_bPosDefined = m_bBitmapDefined = m_bInfoDefined = false;
if (m_pCurrentControl)
{
m_oLastError = string("Controls cannot be nested");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <SliderControl> tag needs a Name attribute");
return kError_ParseError;
}
m_eCurrentControl = eSliderControl;
m_pCurrentControl = new SliderControl(m_pCurrentWindow,
oAttrMap["Name"]);
return kError_NoErr;
}
if (oElement == string("VSliderControl"))
{
m_bPosDefined = m_bBitmapDefined = m_bInfoDefined = false;
if (m_pCurrentControl)
{
m_oLastError = string("Controls cannot be nested");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <VSliderControl> tag needs a Name attribute");
return kError_ParseError;
}
m_eCurrentControl = eVSliderControl;
m_pCurrentControl = new VSliderControl(m_pCurrentWindow,
oAttrMap["Name"]);
return kError_NoErr;
}
if (oElement == string("TextControl"))
{
m_bPosDefined = m_bBitmapDefined = m_bInfoDefined = false;
if (m_pCurrentControl)
{
m_oLastError = string("Controls cannot be nested");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <TextControl> tag needs a Name attribute");
return kError_ParseError;
}
m_eCurrentControl = eTextControl;
m_pCurrentControl = new TextControl(m_pCurrentWindow,
oAttrMap["Name"]);
return kError_NoErr;
}
if (oElement == string("Style"))
{
Color oColor(0, 0, 0);
Font *pFont;
bool bBold = false, bItalic = false, bUnderline = false;
string oAlign("");
if (m_pCurrentControl == NULL || m_eCurrentControl != eTextControl)
{
m_oLastError = string("The <Style> tag must be inside of a "
"<TextControl> tag");
return kError_InvalidParam;
}
if (oAttrMap.find("Font") == oAttrMap.end())
{
m_oLastError = string("the <Style> tag needs a Font attribute");
return kError_ParseError;
}
pFont = FindFont(oAttrMap["Font"]);
if (pFont == NULL)
{
m_oLastError = string("Undefined font ") +
oAttrMap["Name"] +
string("in tag <Style>");
return kError_InvalidParam;
}
#ifdef HAVE_GTK
pFont = new GTKFont(*(GTKFont *)pFont);
#endif
if (oAttrMap.find("Color") != oAttrMap.end() &&
oAttrMap["Color"] != string(""))
{
eRet = ParseColor(oAttrMap["Color"], oColor);
if (eRet != kError_NoErr)
{
m_oLastError = string("Improperly formatted color info: ") +
oAttrMap["Color"];
return kError_InvalidParam;
}
}
if (oAttrMap.find("Bold") != oAttrMap.end())
bBold = strcasecmp(oAttrMap["Bold"].c_str(), "yes") == 0;
if (oAttrMap.find("Italic") != oAttrMap.end())
bItalic = strcasecmp(oAttrMap["Italic"].c_str(), "yes") == 0;
if (oAttrMap.find("Underline") != oAttrMap.end())
bUnderline = strcasecmp(oAttrMap["Underline"].c_str(), "yes") == 0;
if (oAttrMap.find("Align") != oAttrMap.end())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -