Additional changes to f2b52b4

This commit is contained in:
Birunthan Mohanathas 2012-07-18 09:22:47 +03:00
parent f2b52b4204
commit 4dbf7932ab
4 changed files with 38 additions and 118 deletions

View File

@ -299,8 +299,7 @@ void CMeterString::Initialize()
if (m_FontSize != 0)
{
std::wstring error = L"String: Unable to create font: " + m_FontFace;
throw CError(error);
LogWithArgs(LOG_ERROR, L"String: Invalid font: %s", m_FontFace.c_str());
}
}
}

View File

@ -236,7 +236,7 @@ CMeterWindow::~CMeterWindow()
** Initializes the window, creates the class and the window.
**
*/
int CMeterWindow::Initialize()
void CMeterWindow::Initialize()
{
m_Window = CreateWindowEx(
WS_EX_TOOLWINDOW,
@ -252,11 +252,6 @@ int CMeterWindow::Initialize()
Rainmeter->GetInstance(),
this);
if (m_Window == NULL)
{
throw CError(L"Unable to register window");
}
setlocale(LC_NUMERIC, "C");
// Mark the window to ignore the Aero peek
@ -277,10 +272,6 @@ int CMeterWindow::Initialize()
FadeWindow(0, m_AlphaValue);
}
}
Log(LOG_NOTICE, L"Initialization successful");
return 0;
}
/*
@ -396,9 +387,6 @@ void CMeterWindow::Refresh(bool init, bool all)
return;
}
InitializeMeasures();
InitializeMeters();
// Remove transparent flag
RemoveWindowExStyle(WS_EX_TRANSPARENT);
@ -2172,51 +2160,47 @@ bool CMeterWindow::ReadSkin()
m_HasNetMeasures = false;
m_HasButtons = false;
// Measures must be created first to avoid errors in meters referencing measures.
// Add measures to containers.
m_Measures.reserve(measures.size());
for (auto iter = measures.cbegin(); iter != measures.cend(); ++iter)
{
CMeasure* measure = *iter;
m_Measures.push_back(measure);
m_Parser.AddMeasure(measure);
try
if (measure->GetTypeID() == TypeID<CMeasureNet>())
{
measure->ReadOptions(m_Parser);
m_Measures.push_back(measure);
m_Parser.AddMeasure(measure);
if (measure->GetTypeID() == TypeID<CMeasureNet>())
{
m_HasNetMeasures = true;
}
}
catch (CError& error)
{
delete measure;
measure = NULL;
LogError(error);
m_HasNetMeasures = true;
}
}
// Initialize measures. This is a separate loop to avoid errors caused by
// referencing not-yet-existent [measures] referencing in the options.
for (auto iter = measures.cbegin(); iter != measures.cend(); ++iter)
{
CMeasure* measure = *iter;
measure->ReadOptions(m_Parser);
measure->Initialize();
}
// Initialize meters.
m_Meters.reserve(meters.size());
for (auto iter = meters.cbegin(); iter != meters.cend(); ++iter)
{
CMeter* meter = *iter;
m_Meters.push_back(meter);
try
meter->ReadOptions(m_Parser);
meter->Initialize();
if (!meter->GetToolTipText().empty())
{
meter->ReadOptions(m_Parser);
m_Meters.push_back(meter);
if (!m_HasButtons && meter->GetTypeID() == TypeID<CMeterButton>())
{
m_HasButtons = true;
}
meter->CreateToolTip(this);
}
catch (CError& error)
if (!m_HasButtons && meter->GetTypeID() == TypeID<CMeterButton>())
{
delete meter;
meter = NULL;
LogError(error);
m_HasButtons = true;
}
}
@ -2230,53 +2214,6 @@ bool CMeterWindow::ReadSkin()
return true;
}
/*
** Initializes all the measures
**
*/
void CMeterWindow::InitializeMeasures()
{
// Initalize all measures
std::vector<CMeasure*>::const_iterator i = m_Measures.begin();
for ( ; i != m_Measures.end(); ++i)
{
try
{
(*i)->Initialize();
}
catch (CError& error)
{
LogError(error);
}
}
}
/*
** Initializes all the meters
**
*/
void CMeterWindow::InitializeMeters()
{
// Initalize all meters
std::vector<CMeter*>::const_iterator j = m_Meters.begin();
for ( ; j != m_Meters.end(); ++j)
{
try
{
(*j)->Initialize();
}
catch (CError& error)
{
LogError(error);
}
if (!(*j)->GetToolTipText().empty())
{
(*j)->CreateToolTip(this);
}
}
}
/*
** Changes the size of the window and re-adjusts the background
*/

View File

@ -156,7 +156,7 @@ public:
CMeterWindow(const std::wstring& folderPath, const std::wstring& file);
~CMeterWindow();
int Initialize();
void Initialize();
void RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& args);
@ -311,8 +311,6 @@ private:
void ReadOptions();
void WriteOptions(INT setting = OPTION_ALL);
bool ReadSkin();
void InitializeMeasures();
void InitializeMeters();
void ShowWindowIfAppropriate();
HWND GetWindowFromPoint(POINT pos);
void HandleButtons(POINT pos, BUTTONPROC proc, bool execute = true);

View File

@ -83,18 +83,15 @@ int RainmeterMain(LPWSTR cmdLine)
int ret = 1;
Rainmeter = new CRainmeter;
if (Rainmeter)
ret = Rainmeter->Initialize(cmdLine);
if (ret == 0)
{
ret = Rainmeter->Initialize(cmdLine);
if (ret == 0)
{
ret = Rainmeter->MessagePump();
}
delete Rainmeter;
Rainmeter = NULL;
ret = Rainmeter->MessagePump();
}
delete Rainmeter;
Rainmeter = NULL;
return ret;
}
@ -1406,24 +1403,13 @@ void CRainmeter::CreateMeterWindow(const std::wstring& folderPath, const std::ws
{
CMeterWindow* mw = new CMeterWindow(folderPath, file);
if (mw)
{
// Note: May modify existing key
m_MeterWindows[folderPath] = mw;
// Note: May modify existing key
m_MeterWindows[folderPath] = mw;
try
{
mw->Initialize();
mw->Initialize();
CDialogAbout::UpdateSkins();
CDialogManage::UpdateSkins(mw);
}
catch (CError& error)
{
DeactivateSkin(mw, -1);
LogError(error);
}
}
CDialogAbout::UpdateSkins();
CDialogManage::UpdateSkins(mw);
}
void CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow, bool force)