rainmeter-studio/Library/Rainmeter.h

336 lines
11 KiB
C
Raw Normal View History

2009-02-10 18:37:48 +00:00
/*
Copyright (C) 2001 Kimmo Pekkola
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2009-02-10 18:37:48 +00:00
*/
#ifndef __RAINMETER_H__
#define __RAINMETER_H__
#include <windows.h>
#include <map>
#include <vector>
#include <list>
2009-02-10 18:37:48 +00:00
#include <string>
2010-09-21 22:47:53 +00:00
#include "Litestep.h"
#include "MeterWindow.h"
2009-02-10 18:37:48 +00:00
#define MAX_LINE_LENGTH 4096
#define APPNAME L"Rainmeter"
#ifdef _WIN64
#define APPBITS L"64-bit"
2009-02-10 18:37:48 +00:00
#else
#define APPBITS L"32-bit"
2009-02-10 18:37:48 +00:00
#endif
#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
#define APPDATE WIDEN(__DATE__)
2009-02-10 18:37:48 +00:00
#define RAINMETER_CLASS_NAME L"DummyRainWClass"
#define RAINMETER_WINDOW_NAME L"Rainmeter control window"
#define WM_RAINMETER_DELAYED_REFRESH_ALL WM_APP + 0
#define WM_RAINMETER_DELAYED_EXECUTE WM_APP + 1
#define WM_RAINMETER_EXECUTE WM_APP + 2
struct GlobalOptions
2009-02-10 18:37:48 +00:00
{
double netInSpeed;
double netOutSpeed;
};
class CConfigParser;
class CTrayWindow;
2009-02-10 18:37:48 +00:00
class CRainmeter
{
public:
struct SkinFolder
2009-02-10 18:37:48 +00:00
{
std::wstring name;
std::vector<std::wstring> files;
2011-10-29 10:36:07 +00:00
UINT commandBase;
int16_t active;
int16_t level;
2011-12-09 03:28:19 +00:00
SkinFolder() {}
~SkinFolder() {}
2011-12-09 03:28:19 +00:00
SkinFolder(SkinFolder&& r) :
name(std::move(r.name)),
files(std::move(r.files)),
2011-12-09 03:28:19 +00:00
commandBase(r.commandBase),
active(r.active),
level(r.level)
2011-12-09 03:28:19 +00:00
{
}
SkinFolder& operator=(SkinFolder&& r)
2011-12-09 03:28:19 +00:00
{
name = std::move(r.name);
files = std::move(r.files);
2011-12-09 03:28:19 +00:00
commandBase = r.commandBase;
active = r.active;
level = r.level;
2011-12-09 03:28:19 +00:00
return *this;
}
2009-02-10 18:37:48 +00:00
};
struct LogInfo
{
int level;
std::wstring timestamp;
std::wstring message;
};
2009-02-10 18:37:48 +00:00
CRainmeter();
~CRainmeter();
2012-05-24 09:19:32 +00:00
int Initialize(LPCWSTR iniPath);
bool IsAlreadyRunning();
int MessagePump();
2009-02-10 18:37:48 +00:00
void SetNetworkStatisticsTimer();
2010-10-19 22:03:32 +00:00
CConfigParser* GetCurrentParser() { return m_CurrentParser; }
void SetCurrentParser(CConfigParser* parser) { m_CurrentParser = parser; }
2009-02-10 18:37:48 +00:00
2010-10-19 22:03:32 +00:00
CTrayWindow* GetTrayWindow() { return m_TrayWindow; }
2009-02-10 18:37:48 +00:00
CMeterWindow* GetMeterWindow(const std::wstring& folderPath);
CMeterWindow* GetMeterWindowByINI(const std::wstring& ini_searching);
std::pair<int, int> GetMeterWindowIndex(const std::wstring& folderPath, const std::wstring& file);
std::pair<int, int> GetMeterWindowIndex(CMeterWindow* meterWindow) { return GetMeterWindowIndex(meterWindow->GetFolderPath(), meterWindow->GetFileName()); }
2011-10-29 10:36:07 +00:00
std::pair<int, int> GetMeterWindowIndex(UINT menuCommand);
CMeterWindow* GetMeterWindow(HWND hwnd);
2011-12-04 22:18:40 +00:00
void GetMeterWindowsByLoadOrder(std::multimap<int, CMeterWindow*>& windows, const std::wstring& group = std::wstring());
std::map<std::wstring, CMeterWindow*>& GetAllMeterWindows() { return m_MeterWindows; }
std::wstring GetFolderPath(int folderIndex);
int FindSkinFolderIndex(const std::wstring& folderPath);
const std::vector<SkinFolder>& GetFolders() { return m_SkinFolders; }
2010-10-19 22:03:32 +00:00
const std::vector<std::wstring>& GetAllThemes() { return m_Themes; }
2009-02-10 18:37:48 +00:00
void DeleteMeterWindow(CMeterWindow* meterWindow, bool force = false);
2012-02-02 12:05:14 +00:00
void ActivateSkin(int folderIndex, int fileIndex);
void DeactivateSkin(CMeterWindow* meterWindow, int folderIndex, bool save = true);
void ToggleSkin(int folderIndex, int fileIndex);
2009-02-10 18:37:48 +00:00
2010-10-19 22:03:32 +00:00
const std::wstring& GetPath() { return m_Path; }
const std::wstring& GetIniFile() { return m_IniFile; }
2012-05-05 11:45:34 +00:00
const std::wstring& GetDataFile() { return m_DataFile; }
2010-10-19 22:03:32 +00:00
const std::wstring& GetLogFile() { return m_LogFile; }
const std::wstring& GetSettingsPath() { return m_SettingsPath; }
2010-10-19 22:03:32 +00:00
const std::wstring& GetSkinPath() { return m_SkinPath; }
std::wstring GetThemePath() { return m_SettingsPath + L"Themes\\"; }
std::wstring GetPluginPath() { return m_Path + L"Plugins\\"; }
std::wstring GetUserPluginPath() { return m_SettingsPath + L"Plugins\\"; }
std::wstring GetAddonPath() { return m_SettingsPath + L"Addons\\"; }
std::wstring GetDefaultSkinPath() { return m_Path + L"Defaults\\Skins\\"; }
std::wstring GetDefaultThemePath() { return m_Path + L"Defaults\\Themes\\"; }
std::wstring GetDefaultPluginPath() { return m_Path + L"Defaults\\Plugins\\"; }
std::wstring GetDefaultAddonPath() { return m_Path + L"Defaults\\Addons\\"; }
2009-02-10 18:37:48 +00:00
2010-11-25 22:00:34 +00:00
const std::wstring& GetDrive() { return m_Drive; }
const std::wstring& GetSkinEditor() { return m_SkinEditor; }
2010-10-19 22:03:32 +00:00
const std::wstring& GetLogViewer() { return m_LogViewer; }
const std::wstring& GetStatsDate() { return m_StatsDate; }
2009-02-10 18:37:48 +00:00
HWND GetWindow() { return m_Window; }
2010-10-19 22:03:32 +00:00
HINSTANCE GetInstance() { return m_Instance; }
2011-09-23 16:28:38 +00:00
HINSTANCE GetResourceInstance() { return m_ResourceInstance; }
LCID GetResourceLCID() { return m_ResourceLCID; }
2009-02-10 18:37:48 +00:00
bool GetDebug() { return m_Debug; }
GlobalOptions& GetGlobalOptions() { return m_GlobalOptions; }
2009-02-10 18:37:48 +00:00
void ReloadSettings();
2012-02-21 19:15:10 +00:00
void EditSettings();
void EditSkinFile(const std::wstring& name, const std::wstring& iniFile);
void OpenSkinFolder(const std::wstring& name = std::wstring());
2009-02-10 18:37:48 +00:00
void UpdateStats();
void ReadStats();
void WriteStats(bool bForce);
2009-02-10 18:37:48 +00:00
void ResetStats();
bool GetDisableVersionCheck() { return m_DisableVersionCheck; }
void SetDisableVersionCheck(bool check);
bool GetNewVersion() { return m_NewVersion; }
2012-04-06 17:54:45 +00:00
void SetNewVersion() { m_NewVersion = true; }
bool GetLogging() { return m_Logging; }
void StartLogging();
void StopLogging();
2012-02-21 19:15:10 +00:00
void ShowLogFile();
void DeleteLogFile();
bool GetDisableRDP() { return m_DisableRDP; }
bool IsRedrawable() { return (!GetDisableRDP() || !GetSystemMetrics(SM_REMOTESESSION)); }
bool GetDisableDragging() { return m_DisableDragging; }
void SetDisableDragging(bool dragging);
bool IsNormalStayDesktop() { return m_NormalStayDesktop; }
void AddAboutLogInfo(int level, LPCWSTR time, LPCWSTR message);
const std::list<LogInfo>& GetAboutLogData() { return m_LogData; }
void SetDebug(bool debug);
2009-02-10 18:37:48 +00:00
bool IsMenuActive() { return m_MenuActive; }
2009-02-10 18:37:48 +00:00
void ShowContextMenu(POINT pos, CMeterWindow* meterWindow);
const std::wstring& GetTrayExecuteR() { return m_TrayExecuteR; }
const std::wstring& GetTrayExecuteM() { return m_TrayExecuteM; }
const std::wstring& GetTrayExecuteDR() { return m_TrayExecuteDR; }
const std::wstring& GetTrayExecuteDM() { return m_TrayExecuteDM; }
2009-02-10 18:37:48 +00:00
void ExecuteBang(const WCHAR* bang, std::vector<std::wstring>& args, CMeterWindow* meterWindow);
2012-05-14 15:27:43 +00:00
void ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow, bool multi = true);
void DelayedExecuteCommand(const WCHAR* command);
2009-02-10 18:37:48 +00:00
void RefreshAll();
void LoadTheme(const std::wstring& name);
void PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace = true);
2012-05-08 13:53:24 +00:00
static std::vector<std::wstring> ParseString(LPCTSTR str, CConfigParser* parser = NULL);
static std::wstring ExtractPath(const std::wstring& strFilePath);
static void ExpandEnvironmentVariables(std::wstring& strPath);
2009-02-10 18:37:48 +00:00
friend class CDialogManage;
2009-02-10 18:37:48 +00:00
private:
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
2012-05-08 13:53:24 +00:00
void BangWithArgs(BANGCOMMAND bang, std::vector<std::wstring>& args, size_t numOfArgs, CMeterWindow* meterWindow);
void BangGroupWithArgs(BANGCOMMAND bang, std::vector<std::wstring>& args, size_t numOfArgs, CMeterWindow* meterWindow);
void Bang_ActivateSkin(std::vector<std::wstring>& args);
void Bang_DeactivateSkin(std::vector<std::wstring>& args, CMeterWindow* meterWindow);
void Bang_ToggleSkin(std::vector<std::wstring>& args);
void Bang_DeactivateSkinGroup(std::vector<std::wstring>& args);
2012-05-08 13:53:24 +00:00
void Bang_SetClip(std::vector<std::wstring>& args);
2012-05-21 09:07:50 +00:00
void Bang_SetWallpaper(std::vector<std::wstring>& args, CMeterWindow* meterWindow);
2012-05-08 13:53:24 +00:00
void Bang_SkinMenu(std::vector<std::wstring>& args, CMeterWindow* meterWindow);
2012-01-30 08:34:56 +00:00
void Bang_TrayMenu();
2012-05-08 13:53:24 +00:00
void Bang_WriteKeyValue(std::vector<std::wstring>& args, CMeterWindow* meterWindow);
void Bang_Log(std::vector<std::wstring>& args);
2011-10-29 10:36:07 +00:00
void ActivateActiveSkins();
void CreateMeterWindow(const std::wstring& folderPath, const std::wstring& file);
void WriteActive(const std::wstring& folderPath, int fileIndex);
void ScanForSkins(const std::wstring& path);
void ScanForThemes(const std::wstring& path);
void ReadGeneralSettings(const std::wstring& iniFile);
void SetLoadOrder(int folderIndex, int order);
int GetLoadOrder(const std::wstring& folderPath);
void UpdateDesktopWorkArea(bool reset);
HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU menu);
2009-02-10 18:37:48 +00:00
void ChangeSkinIndex(HMENU subMenu, int index);
int ScanForSkinsRecursive(const std::wstring& path, std::wstring base, int index, UINT level);
void CreateAllSkinsMenu(HMENU skinMenu) { CreateAllSkinsMenuRecursive(skinMenu, 0); }
int CreateAllSkinsMenuRecursive(HMENU skinMenu, int index);
void CreateThemeMenu(HMENU themeMenu);
void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow);
void CreateOptionsFile();
2012-05-05 11:45:34 +00:00
void CreateDataFile();
void CreateComponentFolders(bool defaultIniLocation);
void SetLogging(bool logging);
void TestSettingsFile(bool bDefaultIniLocation);
2009-02-10 18:37:48 +00:00
CTrayWindow* m_TrayWindow;
std::vector<SkinFolder> m_SkinFolders;
std::multimap<int, int> m_SkinOrders;
std::map<std::wstring, CMeterWindow*> m_MeterWindows;
std::vector<std::wstring> m_Themes;
2009-02-10 18:37:48 +00:00
2012-05-05 11:45:34 +00:00
std::wstring m_Path;
std::wstring m_IniFile;
std::wstring m_DataFile;
std::wstring m_StatsFile;
std::wstring m_LogFile;
std::wstring m_SettingsPath;
2012-05-05 11:45:34 +00:00
std::wstring m_SkinPath;
2010-11-25 22:00:34 +00:00
std::wstring m_Drive;
2009-02-10 18:37:48 +00:00
2012-05-20 17:57:12 +00:00
std::wstring m_StatsDate;
2009-02-10 18:37:48 +00:00
std::wstring m_TrayExecuteR;
std::wstring m_TrayExecuteM;
std::wstring m_TrayExecuteDR;
std::wstring m_TrayExecuteDM;
bool m_Debug;
bool m_DisableVersionCheck;
bool m_NewVersion;
2011-12-09 08:40:19 +00:00
bool m_DesktopWorkAreaChanged;
2012-05-20 17:57:12 +00:00
bool m_DesktopWorkAreaType;
std::map<UINT, RECT> m_DesktopWorkAreas;
std::vector<RECT> m_OldDesktopWorkAreas;
2009-02-10 18:37:48 +00:00
bool m_NormalStayDesktop;
bool m_MenuActive;
bool m_DisableRDP;
bool m_DisableDragging;
bool m_Logging;
std::list<LogInfo> m_LogData;
std::wstring m_SkinEditor;
std::wstring m_LogViewer;
2009-02-10 18:37:48 +00:00
CConfigParser* m_CurrentParser;
HWND m_Window;
HANDLE m_Mutex;
2009-02-10 18:37:48 +00:00
HINSTANCE m_Instance;
2011-09-23 16:28:38 +00:00
HMODULE m_ResourceInstance;
LCID m_ResourceLCID;
2009-02-10 18:37:48 +00:00
ULONG_PTR m_GDIplusToken;
GlobalOptions m_GlobalOptions;
2009-02-10 18:37:48 +00:00
};
2012-02-04 16:13:04 +00:00
#ifdef LIBRARY_EXPORTS
#define EXPORT_PLUGIN EXTERN_C
#else
#define EXPORT_PLUGIN EXTERN_C __declspec(dllimport)
#endif
2012-02-16 17:38:45 +00:00
EXPORT_PLUGIN int RainmeterMain(LPWSTR cmdLine);
2009-02-10 18:37:48 +00:00
#endif