* Replaced if-else with switch-case
This commit is contained in:
spx 2013-02-06 18:55:45 +09:00
parent 2ea8710f58
commit e96b02d3dc
3 changed files with 324 additions and 301 deletions

View File

@ -2779,12 +2779,13 @@ void CMeterWindow::UpdateWindow(int alpha, bool reset)
*/
LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (wParam == TIMER_METER)
switch (wParam)
{
case TIMER_METER:
Update(false);
}
else if (wParam == TIMER_MOUSE)
{
break;
case TIMER_MOUSE:
if (!Rainmeter->IsMenuActive() && !m_Dragging)
{
ShowWindowIfAppropriate();
@ -2822,8 +2823,9 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}
}
}
else if (wParam == TIMER_TRANSITION)
break;
case TIMER_TRANSITION:
{
// Redraw only if there is active transition still going
bool bActiveTransition = false;
@ -2848,7 +2850,9 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
m_ActiveTransition = false;
}
}
else if (wParam == TIMER_FADE)
break;
case TIMER_FADE:
{
ULONGLONG ticks = CSystem::GetTickCount64();
if (m_FadeStartTime == 0)
@ -2881,13 +2885,15 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
UpdateWindow((int)value, false);
}
}
else if (wParam == TIMER_DEACTIVATE)
{
break;
case TIMER_DEACTIVATE:
if (m_FadeStartTime == 0)
{
KillTimer(m_Window, TIMER_DEACTIVATE);
Rainmeter->DeleteMeterWindow(this, true); // "delete this;"
}
break;
}
return 0;
@ -3308,129 +3314,132 @@ LRESULT CMeterWindow::OnMouseHScrollMove(UINT uMsg, WPARAM wParam, LPARAM lParam
*/
LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (wParam == IDM_SKIN_EDITSKIN)
switch (wParam)
{
case IDM_SKIN_EDITSKIN:
Rainmeter->EditSkinFile(m_FolderPath, m_FileName);
}
else if (wParam == IDM_SKIN_REFRESH)
{
break;
case IDM_SKIN_REFRESH:
Refresh(false);
}
else if (wParam == IDM_SKIN_OPENSKINSFOLDER)
{
break;
case IDM_SKIN_OPENSKINSFOLDER:
Rainmeter->OpenSkinFolder(m_FolderPath);
}
else if (wParam == IDM_SKIN_MANAGESKIN)
{
break;
case IDM_SKIN_MANAGESKIN:
CDialogManage::OpenSkin(this);
}
else if (wParam == IDM_SKIN_VERYTOPMOST)
{
break;
case IDM_SKIN_VERYTOPMOST:
SetWindowZPosition(ZPOSITION_ONTOPMOST);
}
else if (wParam == IDM_SKIN_TOPMOST)
{
break;
case IDM_SKIN_TOPMOST:
SetWindowZPosition(ZPOSITION_ONTOP);
}
else if (wParam == IDM_SKIN_BOTTOM)
{
break;
case IDM_SKIN_BOTTOM:
SetWindowZPosition(ZPOSITION_ONBOTTOM);
}
else if (wParam == IDM_SKIN_NORMAL)
{
break;
case IDM_SKIN_NORMAL:
SetWindowZPosition(ZPOSITION_NORMAL);
}
else if (wParam == IDM_SKIN_ONDESKTOP)
{
break;
case IDM_SKIN_ONDESKTOP:
SetWindowZPosition(ZPOSITION_ONDESKTOP);
}
else if (wParam == IDM_SKIN_KEEPONSCREEN)
{
break;
case IDM_SKIN_KEEPONSCREEN:
SetKeepOnScreen(!m_KeepOnScreen);
}
else if (wParam == IDM_SKIN_CLICKTHROUGH)
{
break;
case IDM_SKIN_CLICKTHROUGH:
SetClickThrough(!m_ClickThrough);
}
else if (wParam == IDM_SKIN_DRAGGABLE)
{
break;
case IDM_SKIN_DRAGGABLE:
SetWindowDraggable(!m_WindowDraggable);
}
else if (wParam == IDM_SKIN_HIDEONMOUSE)
{
break;
case IDM_SKIN_HIDEONMOUSE:
SetWindowHide((m_WindowHide == HIDEMODE_NONE) ? HIDEMODE_HIDE : HIDEMODE_NONE);
}
else if (wParam == IDM_SKIN_TRANSPARENCY_FADEIN)
{
break;
case IDM_SKIN_TRANSPARENCY_FADEIN:
SetWindowHide((m_WindowHide == HIDEMODE_NONE) ? HIDEMODE_FADEIN : HIDEMODE_NONE);
}
else if (wParam == IDM_SKIN_TRANSPARENCY_FADEOUT)
{
break;
case IDM_SKIN_TRANSPARENCY_FADEOUT:
SetWindowHide((m_WindowHide == HIDEMODE_NONE) ? HIDEMODE_FADEOUT : HIDEMODE_NONE);
}
else if (wParam == IDM_SKIN_REMEMBERPOSITION)
{
break;
case IDM_SKIN_REMEMBERPOSITION:
SetSavePosition(!m_SavePosition);
}
else if (wParam == IDM_SKIN_SNAPTOEDGES)
{
break;
case IDM_SKIN_SNAPTOEDGES:
SetSnapEdges(!m_SnapEdges);
}
else if (wParam >= IDM_SKIN_TRANSPARENCY_0 && wParam <= IDM_SKIN_TRANSPARENCY_90)
break;
case IDM_CLOSESKIN:
Rainmeter->DeactivateSkin(this, -1);
break;
case IDM_SKIN_FROMRIGHT:
m_WindowXFromRight = !m_WindowXFromRight;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
break;
case IDM_SKIN_FROMBOTTOM:
m_WindowYFromBottom = !m_WindowYFromBottom;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
break;
case IDM_SKIN_XPERCENTAGE:
m_WindowXPercentage = !m_WindowXPercentage;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
break;
case IDM_SKIN_YPERCENTAGE:
m_WindowYPercentage = !m_WindowYPercentage;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
break;
case IDM_SKIN_MONITOR_AUTOSELECT:
m_AutoSelectScreen = !m_AutoSelectScreen;
ScreenToWindow();
WriteOptions(OPTION_POSITION | OPTION_AUTOSELECTSCREEN);
break;
default:
if (wParam >= IDM_SKIN_TRANSPARENCY_0 && wParam <= IDM_SKIN_TRANSPARENCY_90)
{
m_AlphaValue = (int)(255.0 - (wParam - IDM_SKIN_TRANSPARENCY_0) * (230.0 / (IDM_SKIN_TRANSPARENCY_90 - IDM_SKIN_TRANSPARENCY_0)));
UpdateWindow(m_AlphaValue, false);
WriteOptions(OPTION_ALPHAVALUE);
}
else if (wParam == IDM_CLOSESKIN)
{
Rainmeter->DeactivateSkin(this, -1);
}
else if (wParam == IDM_SKIN_FROMRIGHT)
{
m_WindowXFromRight = !m_WindowXFromRight;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
}
else if (wParam == IDM_SKIN_FROMBOTTOM)
{
m_WindowYFromBottom = !m_WindowYFromBottom;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
}
else if (wParam == IDM_SKIN_XPERCENTAGE)
{
m_WindowXPercentage = !m_WindowXPercentage;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
}
else if (wParam == IDM_SKIN_YPERCENTAGE)
{
m_WindowYPercentage = !m_WindowYPercentage;
ScreenToWindow();
WriteOptions(OPTION_POSITION);
}
else if (wParam == IDM_SKIN_MONITOR_AUTOSELECT)
{
m_AutoSelectScreen = !m_AutoSelectScreen;
ScreenToWindow();
WriteOptions(OPTION_POSITION | OPTION_AUTOSELECTSCREEN);
}
else if (wParam == IDM_SKIN_MONITOR_PRIMARY || wParam >= ID_MONITOR_FIRST && wParam <= ID_MONITOR_LAST)
{
const MultiMonitorInfo& multimonInfo = CSystem::GetMultiMonitorInfo();
const std::vector<MonitorInfo>& monitors = multimonInfo.monitors;
const MultiMonitorInfo& monitorsInfo = CSystem::GetMultiMonitorInfo();
const std::vector<MonitorInfo>& monitors = monitorsInfo.monitors;
int screenIndex;
bool screenDefined;
if (wParam == IDM_SKIN_MONITOR_PRIMARY)
{
screenIndex = multimonInfo.primary;
screenIndex = monitorsInfo.primary;
screenDefined = false;
}
else
@ -3487,6 +3496,8 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
SendMessage(tray, WM_COMMAND, wParam, lParam);
}
}
break;
}
return 0;
}

View File

@ -995,7 +995,7 @@ LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
ClearMultiMonitorInfo();
CConfigParser::ClearMultiMonitorVariables();
case WM_SETTINGCHANGE:
if (uMsg == WM_DISPLAYCHANGE || (uMsg == WM_SETTINGCHANGE && wParam == SPI_SETWORKAREA))
if (uMsg == WM_DISPLAYCHANGE || (/*uMsg == WM_SETTINGCHANGE &&*/ wParam == SPI_SETWORKAREA))
{
if (uMsg == WM_SETTINGCHANGE) // SPI_SETWORKAREA
{

View File

@ -464,63 +464,65 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
switch (uMsg)
{
case WM_COMMAND:
if (wParam == IDM_MANAGE)
switch (wParam)
{
case IDM_MANAGE:
CDialogManage::Open();
}
else if (wParam == IDM_ABOUT)
{
break;
case IDM_ABOUT:
CDialogAbout::Open();
}
else if (wParam == IDM_SHOW_HELP)
{
break;
case IDM_SHOW_HELP:
RunFile(RAINMETER_HELP);
}
else if (wParam == IDM_NEW_VERSION)
{
break;
case IDM_NEW_VERSION:
RunFile(RAINMETER_OFFICIAL);
}
else if (wParam == IDM_REFRESH)
{
break;
case IDM_REFRESH:
PostMessage(Rainmeter->GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL);
}
else if (wParam == IDM_SHOWLOGFILE)
{
break;
case IDM_SHOWLOGFILE:
Rainmeter->ShowLogFile();
}
else if (wParam == IDM_STARTLOG)
{
break;
case IDM_STARTLOG:
Rainmeter->StartLogging();
}
else if (wParam == IDM_STOPLOG)
{
break;
case IDM_STOPLOG:
Rainmeter->StopLogging();
}
else if (wParam == IDM_DELETELOGFILE)
{
break;
case IDM_DELETELOGFILE:
Rainmeter->DeleteLogFile();
}
else if (wParam == IDM_DEBUGLOG)
{
break;
case IDM_DEBUGLOG:
Rainmeter->SetDebug(!Rainmeter->GetDebug());
}
else if (wParam == IDM_DISABLEDRAG)
{
break;
case IDM_DISABLEDRAG:
Rainmeter->SetDisableDragging(!Rainmeter->GetDisableDragging());
}
else if (wParam == IDM_EDITCONFIG)
{
break;
case IDM_EDITCONFIG:
Rainmeter->EditSettings();
}
else if (wParam == IDM_QUIT)
{
break;
case IDM_QUIT:
PostQuitMessage(0);
}
else if (wParam == IDM_OPENSKINSFOLDER)
{
break;
case IDM_OPENSKINSFOLDER:
Rainmeter->OpenSkinFolder();
}
else
break;
default:
{
UINT mID = wParam & 0x0FFFF;
@ -564,56 +566,68 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
}
}
break;
}
break; // Don't send WM_COMMANDS any further
case WM_TRAY_NOTIFYICON:
{
UINT uMouseMsg = (UINT)lParam;
std::wstring bang;
LPCWSTR bang;
// Check TrayExecute actions
switch (uMouseMsg)
{
case WM_MBUTTONDOWN:
bang = Rainmeter->GetTrayExecuteM();
bang = Rainmeter->GetTrayExecuteM().c_str();
break;
case WM_RBUTTONDOWN:
bang = Rainmeter->GetTrayExecuteR();
bang = Rainmeter->GetTrayExecuteR().c_str();
break;
case WM_MBUTTONDBLCLK:
bang = Rainmeter->GetTrayExecuteDM();
bang = Rainmeter->GetTrayExecuteDM().c_str();
break;
case WM_RBUTTONDBLCLK:
bang = Rainmeter->GetTrayExecuteDR();
bang = Rainmeter->GetTrayExecuteDR().c_str();
break;
default:
bang = L"";
break;
}
if (!bang.empty() &&
if (*bang &&
!IsCtrlKeyDown()) // Ctrl is pressed, so only run default action
{
Rainmeter->ExecuteCommand(bang.c_str(), NULL);
Rainmeter->ExecuteCommand(bang, NULL);
tray->m_TrayContextMenuEnabled = (uMouseMsg != WM_RBUTTONDOWN);
break;
}
else if (uMouseMsg == WM_RBUTTONDOWN)
// Run default UI action
switch (uMouseMsg)
{
case WM_RBUTTONDOWN:
tray->m_TrayContextMenuEnabled = true;
}
else if (uMouseMsg == WM_RBUTTONUP)
{
break;
case WM_RBUTTONUP:
if (tray->m_TrayContextMenuEnabled)
{
POINT pos = CSystem::GetCursorPosition();
Rainmeter->ShowContextMenu(pos, NULL);
}
}
else if (uMouseMsg == WM_LBUTTONUP || uMouseMsg == WM_LBUTTONDBLCLK)
{
break;
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
CDialogManage::Open();
}
else if (uMouseMsg == NIN_BALLOONUSERCLICK)
{
break;
case NIN_BALLOONUSERCLICK:
if (tray->m_Notification == TRAY_NOTIFICATION_WELCOME)
{
CDialogManage::Open();
@ -622,12 +636,13 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
{
RunFile(RAINMETER_OFFICIAL);
}
tray->m_Notification = TRAY_NOTIFICATION_NONE;
break;
case NIN_BALLOONHIDE:
case NIN_BALLOONTIMEOUT:
tray->m_Notification = TRAY_NOTIFICATION_NONE;
}
else if (uMouseMsg == NIN_BALLOONHIDE || uMouseMsg == NIN_BALLOONTIMEOUT)
{
tray->m_Notification = TRAY_NOTIFICATION_NONE;
break;
}
}
break;
@ -644,40 +659,37 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
SendMessage((HWND)lParam, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds);
};
if (wParam == RAINMETER_QUERY_ID_SKINS_PATH)
switch (wParam)
{
case RAINMETER_QUERY_ID_SKINS_PATH:
sendCopyData(Rainmeter->GetSkinPath());
return 0;
}
else if (wParam == RAINMETER_QUERY_ID_SETTINGS_PATH)
{
case RAINMETER_QUERY_ID_SETTINGS_PATH:
sendCopyData(Rainmeter->GetSettingsPath());
return 0;
}
else if (wParam == RAINMETER_QUERY_ID_PLUGINS_PATH)
{
case RAINMETER_QUERY_ID_PLUGINS_PATH:
sendCopyData(Rainmeter->GetPluginPath());
return 0;
}
else if (wParam == RAINMETER_QUERY_ID_PROGRAM_PATH)
{
case RAINMETER_QUERY_ID_PROGRAM_PATH:
sendCopyData(Rainmeter->GetPath());
return 0;
}
else if (wParam == RAINMETER_QUERY_ID_LOG_PATH)
{
case RAINMETER_QUERY_ID_LOG_PATH:
sendCopyData(Rainmeter->GetLogFile());
return 0;
}
else if (wParam == RAINMETER_QUERY_ID_CONFIG_EDITOR)
{
case RAINMETER_QUERY_ID_CONFIG_EDITOR:
sendCopyData(Rainmeter->GetSkinEditor());
return 0;
}
else if (wParam == RAINMETER_QUERY_ID_IS_DEBUGGING)
case RAINMETER_QUERY_ID_IS_DEBUGGING:
{
BOOL debug = Rainmeter->GetDebug();
SendMessage((HWND)lParam, WM_QUERY_RAINMETER_RETURN, (WPARAM)hWnd, (LPARAM)debug);
}
return 0;
}
}