📄 theme.cpp
字号:
m_bThemeLoaded = true;
}
if (m_pWindow)
m_pWindow->EnableTimer(true);
return eRet;
}
Error Theme::SwitchWindow(const string &oWindowName)
{
string oTemp;
vector<Window *>::iterator i;
Window *pMainWindow, *pNewWindow = NULL;
for(i = m_pWindows->begin(); i != m_pWindows->end(); i++)
{
(*i)->GetName(oTemp);
if (oTemp == oWindowName)
{
pNewWindow = *i;
break;
}
if (oTemp == string("MainWindow"))
pMainWindow = *i;
}
if (!pNewWindow)
pNewWindow = pMainWindow;
return m_pWindow->VulcanMindMeld(pNewWindow);
}
Error Theme::Run(Pos &oWindowPos)
{
if (!m_bThemeLoaded)
return kError_YouScrewedUp;
InitWindow();
return m_pWindow->Run(oWindowPos);
}
Error Theme::Close(void)
{
if (m_pWindow)
return m_pWindow->Close();
else
return kError_NoErr;
}
Error Theme::BeginElement(string &oElement, AttrMap &oAttrMap)
{
Error eRet;
string oCompleteFile;
if (oElement == string("Version"))
{
int iRet, iVersionMajor, iVersionMinor;
iRet = sscanf(oAttrMap["Version"].c_str(), " %d.%d", &iVersionMajor,
&iVersionMinor);
if (iRet != 2)
{
m_oLastError = string("Improperly formatted version number "
"in the <Version> tag");
return kError_ParseError;
}
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;
}
if (IsRelative(oAttrMap["File"].c_str()))
oCompleteFile = m_oThemePath + oAttrMap["File"];
else
oCompleteFile = 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("Panel"))
{
Rect oRect;
Pos oPos, oTogglePos;
Bitmap *pBitmap;
Canvas *pCanvas;
oTogglePos.x = -1;
oTogglePos.y = -1;
pCanvas = m_pCurrentWindow->GetCanvas();
if (pCanvas->GetBackgroundBitmap())
{
m_oLastError = string("Do not use a <BackgroundBitmap> tag in "
"conjunction with a <Panel>.");
return kError_InvalidParam;
}
if (m_pCurrentWindow == NULL)
{
m_oLastError = string("<Panel> must occur inside "
"of a <Window> tag");
return kError_InvalidParam;
}
if (oAttrMap.find("Name") == oAttrMap.end())
{
m_oLastError = string("the <Panel> tag needs a Name attribute");
return kError_ParseError;
}
if (oAttrMap.find("ZOrder") == oAttrMap.end())
{
m_oLastError = string("the <Panel> tag needs a ZOrder attribute");
return kError_ParseError;
}
if (oAttrMap.find("Rect") == oAttrMap.end())
{
m_oLastError = string("the <Panel> tag needs a Rect attribute");
return kError_ParseError;
}
if (oAttrMap.find("Pos") == oAttrMap.end())
{
m_oLastError = string("the <Panel> tag needs a Pos attribute");
return kError_ParseError;
}
if (oAttrMap.find("Bitmap") == oAttrMap.end())
{
m_oLastError = string("the <Panel> tag needs a Name attribute");
return kError_ParseError;
}
pBitmap = FindBitmap(oAttrMap["Bitmap"]);
if (pBitmap == NULL)
{
m_oLastError = string("Undefined bitmap ") +
oAttrMap["Name"] +
string(" in tag <Panel>");
return kError_InvalidParam;
}
eRet = ParseRect(oAttrMap["Rect"], oRect);
if (eRet != kError_NoErr)
{
m_oLastError = string("Improperly formatted Rect coordinates: ") +
oAttrMap["Rect"];
return kError_InvalidParam;
}
eRet = ParsePos(oAttrMap["Pos"], oPos);
if (eRet != kError_NoErr)
{
m_oLastError = string("Improperly formatted Pos coordinates: ") +
oAttrMap["Pos"];
return kError_InvalidParam;
}
m_pCurrentPanel = FindPanel(oAttrMap["Name"]);
m_pCurrentPanel->SetPanelBitmap(pBitmap);
m_pCurrentPanel->SetZOrder(atoi(oAttrMap["ZOrder"].c_str()));
m_pCurrentPanel->SetRect(oRect);
m_pCurrentPanel->SetPos(oPos);
m_pCurrentPanel->SetParentWindow(m_pCurrentWindow);
if (oAttrMap.find("TogglePos") != oAttrMap.end())
{
eRet = ParsePos(oAttrMap["TogglePos"], oTogglePos);
if (eRet != kError_NoErr)
{
m_oLastError = string("Improperly formatted Pos coordinates: ") +
oAttrMap["Pos"];
return kError_InvalidParam;
}
m_pCurrentPanel->SetTogglePos(oTogglePos);
}
if (oAttrMap.find("OnCloseHide") != oAttrMap.end())
m_pCurrentPanel->SetOnCloseHide(FindPanel(oAttrMap["OnCloseHide"]));
if (oAttrMap.find("OnCloseShow") != oAttrMap.end())
m_pCurrentPanel->SetOnCloseShow(FindPanel(oAttrMap["OnCloseShow"]));
if (oAttrMap.find("OnOpenHide") != oAttrMap.end())
m_pCurrentPanel->SetOnOpenHide(FindPanel(oAttrMap["OnOpenHide"]));
if (oAttrMap.find("OnOpenShow") != oAttrMap.end())
m_pCurrentPanel->SetOnOpenShow(FindPanel(oAttrMap["OnOpenShow"]));
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;
}
if (m_pCurrentPanel == NULL)
{
m_pCurrentPanel = new Panel("DummyPanel");
m_pCurrentPanel->SetParentWindow(m_pCurrentWindow);
}
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"))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -