static int Bang(lua_State* L) { CMeterWindow* self = GetSelf(L); CConfigParser& parser = self->GetParser(); std::wstring bang = LuaManager::ToWide(L, 2); int top = lua_gettop(L); if (top == 2) // 1 argument { parser.ReplaceVariables(bang); Rainmeter->ExecuteCommand(bang.c_str(), self); } else { const WCHAR* bangSz = bang.c_str(); if (*bangSz == L'!') { ++bangSz; // Skip "!" std::vector<std::wstring> args; for (int i = 3; i <= top; ++i) { std::wstring tmpSz = LuaManager::ToWide(L, i); parser.ReplaceVariables(tmpSz); args.push_back(tmpSz); } Rainmeter->ExecuteBang(bangSz, args, self); } } return 0; }
static int GetY(lua_State* L) { CMeterWindow* self = GetSelf(L); lua_pushnumber(L, self->GetY()); return 1; }
static int MakePathAbsolute(lua_State* L) { CMeterWindow* self = GetSelf(L); std::wstring path = LuaManager::ToWide(L, 2); self->MakePathAbsolute(path); LuaManager::PushWide(L, path.c_str()); return 1; }
static int MoveWindow(lua_State* L) { CMeterWindow* self = GetSelf(L); int x = (int)lua_tonumber(L, 2); int y = (int)lua_tonumber(L, 3); self->MoveWindow(x, y); return 0; }
static int FadeWindow(lua_State* L) { CMeterWindow* self = GetSelf(L); int from = (int)lua_tonumber(L, 2); int to = (int)lua_tonumber(L, 3); self->FadeWindow(from, to); return 0; }
static int ReplaceVariables(lua_State* L) { CMeterWindow* self = GetSelf(L); std::wstring strTmp = LuaManager::ToWide(L, 2); self->GetParser().ReplaceVariables(strTmp); self->GetParser().ReplaceMeasures(strTmp); LuaManager::PushWide(L, strTmp.c_str()); return 1; }
static int GetNumberOption(lua_State* L) { CMeasure* self = GetSelf(L); CMeterWindow* meterWindow = self->GetMeterWindow(); CConfigParser& parser = meterWindow->GetParser(); std::wstring strTmp = LuaManager::ToWide(L, 2); double value = parser.ReadFormula(self->GetName(), strTmp.c_str(), lua_tonumber(L, 3)); lua_pushnumber(L, value); return 1; }
static int GetOption(lua_State* L) { CMeasure* self = GetSelf(L); CMeterWindow* meterWindow = self->GetMeterWindow(); CConfigParser& parser = meterWindow->GetParser(); std::wstring strTmp = LuaManager::ToWide(L, 2); strTmp = parser.ReadString(self->GetName(), strTmp.c_str(), LuaManager::ToWide(L, 3).c_str()); LuaManager::PushWide(L, strTmp.c_str()); return 1; }
static int GetOption(lua_State* L) { DECLARE_SELF(L) CMeterWindow* meterWindow = self->GetMeterWindow(); CConfigParser& parser = meterWindow->GetParser(); std::wstring strTmp = LuaManager::ToWide(L, 2); strTmp = parser.ReadString(self->GetName(), strTmp.c_str(), L""); LuaManager::PushWide(L, strTmp); return 1; }
static int ParseFormula(lua_State* L) { CMeterWindow* self = GetSelf(L); std::wstring strTmp = LuaManager::ToWide(L, 2); double result; if (!self->GetParser().ParseFormula(strTmp, &result)) { result = lua_tonumber(L, 2); } lua_pushnumber(L, result); return 1; }
static int GetVariable(lua_State* L) { CMeterWindow* self = GetSelf(L); std::wstring strTmp = LuaManager::ToWide(L, 2); const std::wstring* value = self->GetParser().GetVariable(strTmp); if (value) { LuaManager::PushWide(L, (*value).c_str()); } else { lua_pushnil(L); } return 1; }
/* ** Retrieves the Rainmeter's meter windows in Z-order. ** */ BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam) { bool logging = Rainmeter->GetDebug() && DEBUG_VERBOSE; const int classLen = _countof(METERWINDOW_CLASS_NAME) + (DEBUG_VERBOSE ? 32 : 0); WCHAR className[classLen]; CMeterWindow* Window; WCHAR flag; if (GetClassName(hwnd, className, classLen) > 0 && wcscmp(className, METERWINDOW_CLASS_NAME) == 0 && (Window = Rainmeter->GetMeterWindow(hwnd))) { ZPOSITION zPos = Window->GetWindowZPosition(); if (zPos == ZPOSITION_ONDESKTOP || (zPos == ZPOSITION_NORMAL && Rainmeter->IsNormalStayDesktop()) || zPos == ZPOSITION_ONBOTTOM) { if (lParam) { ((std::vector<CMeterWindow*>*)lParam)->push_back(Window); } if (logging) flag = L'+'; } else { if (logging) flag = L'-'; } if (logging) { LogWithArgs(LOG_DEBUG, L"%c [%c] 0x%p : %s (Name: \"%s\", zPos=%i)", flag, IsWindowVisible(hwnd) ? L'V' : L'H', hwnd, className, Window->GetSkinName().c_str(), (int)zPos); } } else { if (logging) { flag = (hwnd == CSystem::GetHelperWindow()) ? L'o' : ' '; LogWithArgs(LOG_DEBUG, L"%c [%c] 0x%p : %s", flag, IsWindowVisible(hwnd) ? L'V' : L'H', hwnd, className); } } return TRUE; }
static int GetMeasure(lua_State* L) { CMeterWindow* self = GetSelf(L); const std::wstring measureName = LuaManager::ToWide(L, 2); CMeasure* measure = self->GetMeasure(measureName); if (measure) { *(CMeasure**)lua_newuserdata(L, sizeof(CMeasure*)) = measure; lua_getglobal(L, "CMeasure"); lua_setmetatable(L, -2); } else { lua_pushnil(L); } return 1; }
/* ** Returns the first window whose position is not ZPOSITION_ONDESKTOP, ** ZPOSITION_BOTTOM, or ZPOSITION_NORMAL. ** */ HWND CSystem::GetBackmostTopWindow() { HWND winPos = c_HelperWindow; // Skip all ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV)) { CMeterWindow* wnd = Rainmeter->GetMeterWindow(winPos); if (!wnd || (wnd->GetWindowZPosition() != ZPOSITION_NORMAL && wnd->GetWindowZPosition() != ZPOSITION_ONDESKTOP && wnd->GetWindowZPosition() != ZPOSITION_ONBOTTOM)) { break; } } return winPos; }
INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam) { if (!m_HandleCommands) { // Values are being changed/reset, no need to apply changes return FALSE; } switch (LOWORD(wParam)) { case IDC_MANAGESKINS_ACTIVESKINS_BUTTON: { HMENU menu = CreatePopupMenu(); // Add active skins to menu std::map<std::wstring, CMeterWindow*>::const_iterator iter = Rainmeter->GetAllMeterWindows().begin(); int index = 0; for ( ; iter != Rainmeter->GetAllMeterWindows().end(); ++iter) { std::wstring name = ((*iter).second)->GetFolderPath() + L'\\'; name += ((*iter).second)->GetFileName(); InsertMenu(menu, index, MF_BYPOSITION, ID_CONFIG_FIRST + index, name.c_str()); ++index; } if (index > 0) { RECT r; GetWindowRect((HWND)lParam, &r); // Show context menu TrackPopupMenu( menu, TPM_RIGHTBUTTON | TPM_LEFTALIGN, (*GetString(ID_STR_ISRTL) == L'1') ? r.right : r.left, --r.bottom, 0, m_Window, NULL ); } DestroyMenu(menu); } break; case IDC_MANAGESKINS_CREATEPACKAGE_BUTTON: { std::wstring file = Rainmeter->GetPath() + L"SkinInstaller.exe"; RunFile(file.c_str(), L"/Packager"); } break; case IDC_MANAGESKINS_LOAD_BUTTON: { if (!m_SkinWindow) { // Skin not active, load std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex(m_SkinFolderPath, m_SkinFileName); if (indexes.first != -1 && indexes.second != -1) { Rainmeter->ActivateSkin(indexes.first, indexes.second); // Fake selection change to update controls NMHDR nm; nm.code = TVN_SELCHANGED; nm.idFrom = IDC_MANAGESKINS_SKINS_TREEVIEW; nm.hwndFrom = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW); OnNotify(0, (LPARAM)&nm); } } else { m_HandleCommands = false; Rainmeter->DeactivateSkin(m_SkinWindow, -1); } } break; case IDC_MANAGESKINS_REFRESH_BUTTON: if (m_SkinWindow) { m_SkinWindow->Refresh(false); } break; case IDC_MANAGESKINS_EDIT_BUTTON: Rainmeter->EditSkinFile(m_SkinFolderPath, m_SkinFileName); break; case IDC_MANAGESKINS_X_TEXT: if (HIWORD(wParam) == EN_CHANGE) { WCHAR buffer[32]; m_IgnoreUpdate = true; int x = (GetWindowText((HWND)lParam, buffer, 32) > 0) ? _wtoi(buffer) : 0; m_SkinWindow->MoveWindow(x, m_SkinWindow->GetY()); if (x > m_SkinWindow->GetX()) { _itow_s(m_SkinWindow->GetX(), buffer, 10); Edit_SetText((HWND)lParam, buffer); } } break; case IDC_MANAGESKINS_Y_TEXT: if (HIWORD(wParam) == EN_CHANGE) { WCHAR buffer[32]; m_IgnoreUpdate = true; int y = (GetWindowText((HWND)lParam, buffer, 32) > 0) ? _wtoi(buffer) : 0; m_SkinWindow->MoveWindow(m_SkinWindow->GetX(), y); if (y > m_SkinWindow->GetY()) { _itow_s(m_SkinWindow->GetY(), buffer, 10); Edit_SetText((HWND)lParam, buffer); } } break; case IDC_MANAGESKINS_LOADORDER_TEXT: if (HIWORD(wParam) == EN_CHANGE) { if (m_IgnoreUpdate) { // To avoid infinite loop after setting value below m_IgnoreUpdate = false; } else { // Convert text to number and set it to get rid of extra chars WCHAR buffer[32]; int len = GetWindowText((HWND)lParam, buffer, 32); if ((len == 0) || (len == 1 && buffer[0] == L'-')) { // Ignore if empty or if - is only char break; } // Get selection DWORD sel = Edit_GetSel((HWND)lParam); // Reset value (to get rid of invalid chars) m_IgnoreUpdate = true; int value = _wtoi(buffer); _itow_s(value, buffer, 10); SetWindowText((HWND)lParam, buffer); // Reset selection Edit_SetSel((HWND)lParam, LOWORD(sel), HIWORD(sel)); WritePrivateProfileString(m_SkinFolderPath.c_str(), L"LoadOrder", buffer, Rainmeter->GetIniFile().c_str()); std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex(m_SkinWindow); if (indexes.first != -1) { Rainmeter->SetLoadOrder(indexes.first, value); std::multimap<int, CMeterWindow*> windows; Rainmeter->GetMeterWindowsByLoadOrder(windows); CSystem::PrepareHelperWindow(); // Reorder window z-position to reflect load order std::multimap<int, CMeterWindow*>::const_iterator iter = windows.begin(); for ( ; iter != windows.end(); ++iter) { CMeterWindow* mw = (*iter).second; mw->ChangeZPos(mw->GetWindowZPosition(), true); } } } } break; case IDC_MANAGESKINS_DISPLAYMONITOR_BUTTON: { HMENU menu = LoadMenu(Rainmeter->GetResourceInstance(), MAKEINTRESOURCE(IDR_SKIN_MENU)); if (menu) { HMENU subMenu = GetSubMenu(menu, 0); // Skin menu subMenu = GetSubMenu(subMenu, 4); // Settings menu subMenu = GetSubMenu(subMenu, 0); // Position menu subMenu = GetSubMenu(subMenu, 0); // Display monitor menu Rainmeter->CreateMonitorMenu(subMenu, m_SkinWindow); RECT r; GetWindowRect((HWND)lParam, &r); // Show context menu TrackPopupMenu( subMenu, TPM_RIGHTBUTTON | TPM_LEFTALIGN, (*GetString(ID_STR_ISRTL) == L'1') ? r.right : r.left, --r.bottom, 0, m_Window, NULL ); DestroyMenu(menu); } } break; case IDC_MANAGESKINS_DRAGGABLE_CHECKBOX: m_IgnoreUpdate = true; m_SkinWindow->SetWindowDraggable(!m_SkinWindow->GetWindowDraggable()); break; case IDC_MANAGESKINS_CLICKTHROUGH_CHECKBOX: m_IgnoreUpdate = true; m_SkinWindow->SetClickThrough(!m_SkinWindow->GetClickThrough()); break; case IDC_MANAGESKINS_KEEPONSCREEN_CHECKBOX: m_IgnoreUpdate = true; m_SkinWindow->SetKeepOnScreen(!m_SkinWindow->GetKeepOnScreen()); break; case IDC_MANAGESKINS_SAVEPOSITION_CHECKBOX: m_IgnoreUpdate = true; m_SkinWindow->SetSavePosition(!m_SkinWindow->GetSavePosition()); break; case IDC_MANAGESKINS_SNAPTOEDGES_CHECKBOX: m_IgnoreUpdate = true; m_SkinWindow->SetSnapEdges(!m_SkinWindow->GetSnapEdges()); break; case IDC_MANAGESKINS_ZPOSITION_COMBOBOX: if (HIWORD(wParam) == CBN_SELCHANGE) { m_IgnoreUpdate = true; ZPOSITION zpos = (ZPOSITION)(ComboBox_GetCurSel((HWND)lParam) - 2); m_SkinWindow->SetWindowZPosition(zpos); } break; case IDC_MANAGESKINS_TRANSPARENCY_COMBOBOX: if (HIWORD(wParam) == CBN_SELCHANGE) { m_IgnoreUpdate = true; int sel = ComboBox_GetCurSel((HWND)lParam) + IDM_SKIN_TRANSPARENCY_0; SendMessage(m_SkinWindow->GetWindow(), WM_COMMAND, sel, 0); } break; case IDC_MANAGESKINS_ONHOVER_COMBOBOX: if (HIWORD(wParam) == CBN_SELCHANGE) { m_IgnoreUpdate = true; HIDEMODE hide = (HIDEMODE)ComboBox_GetCurSel((HWND)lParam); m_SkinWindow->SetWindowHide(hide); } break; case IDM_MANAGESKINSMENU_EXPAND: { HWND tree = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW); HTREEITEM item = TreeView_GetSelection(tree); TreeView_Expand(tree, item, TVE_TOGGLE); } break; case IDM_MANAGESKINSMENU_OPENFOLDER: { HWND tree = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW); Rainmeter->OpenSkinFolder(GetTreeSelectionPath(tree)); } break; default: if (wParam >= ID_CONFIG_FIRST && wParam <= ID_CONFIG_LAST) { std::map<std::wstring, CMeterWindow*>::const_iterator iter = Rainmeter->GetAllMeterWindows().begin(); int index = (int)wParam - ID_CONFIG_FIRST; int i = 0; for ( ; iter != Rainmeter->GetAllMeterWindows().end(); ++iter) { if (i == index) { std::wstring name = ((*iter).second)->GetFolderPath() + L'\\'; name += ((*iter).second)->GetFileName(); HWND item = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW); SelectTreeItem(item, TreeView_GetRoot(item), name.c_str()); break; } ++i; } } else if (wParam == IDM_SKIN_MONITOR_AUTOSELECT || wParam == IDM_SKIN_MONITOR_PRIMARY || wParam >= ID_MONITOR_FIRST && wParam <= ID_MONITOR_LAST) { if (m_SkinWindow) { SendMessage(m_SkinWindow->GetWindow(), WM_COMMAND, wParam, 0); } break; } return 1; } return 0; }
// Deprecated! LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data) { if (command == NULL || *command == L'\0') { return L"noop"; } NULLCHECK(data); if (_wcsicmp(command, L"GetConfig") == 0) { CMeterWindow* meterWindow = Rainmeter->GetMeterWindowByINI(data); if (meterWindow) { g_Buffer = L"\""; g_Buffer += meterWindow->GetFolderPath(); g_Buffer += L"\""; return g_Buffer.c_str(); } return L""; } else if (_wcsicmp(command, L"GetWindow") == 0) { std::vector<std::wstring> subStrings = CRainmeter::ParseString(data); if (subStrings.size() >= 1) { const std::wstring& config = subStrings[0]; CMeterWindow* meterWindow = Rainmeter->GetMeterWindow(config); if (meterWindow) { WCHAR buf1[64]; _snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(meterWindow->GetWindow())); g_Buffer = buf1; return g_Buffer.c_str(); } } return L"error"; } else if (_wcsicmp(command, L"GetVariable") == 0) { std::vector<std::wstring> subStrings = CRainmeter::ParseString(data); if (subStrings.size() >= 2) { const std::wstring& config = subStrings[0]; CMeterWindow* meterWindow = Rainmeter->GetMeterWindow(config); if (meterWindow) { const std::wstring& variable = subStrings[1]; const std::wstring* value = meterWindow->GetParser().GetVariable(variable); if (value) { return (*value).c_str(); } } } return L""; } else if (_wcsicmp(command, L"SetVariable") == 0) { std::vector<std::wstring> subStrings = CRainmeter::ParseString(data); if (subStrings.size() == 3) { CMeterWindow* meterWindow = Rainmeter->GetMeterWindow(subStrings[0]); if (meterWindow) { meterWindow->SetVariable(subStrings[1], subStrings[2]); return L"success"; } } return L"error"; } return L"noop"; }