From d03d6e606b40157d910ddf99ab018156abeb8ef0 Mon Sep 17 00:00:00 2001 From: "berkeviktor@aol.com" Date: Mon, 28 Feb 2011 18:59:32 +0100 Subject: add wdk changes to named branch --- plugins/xtray/utility.cpp | 563 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 563 insertions(+) create mode 100644 plugins/xtray/utility.cpp (limited to 'plugins/xtray/utility.cpp') diff --git a/plugins/xtray/utility.cpp b/plugins/xtray/utility.cpp new file mode 100644 index 00000000..60f3f2f0 --- /dev/null +++ b/plugins/xtray/utility.cpp @@ -0,0 +1,563 @@ +/* X-Tray + * Copyright (C) 2005 Michael Hotaling + * + * X-Tray 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. + * + * X-Tray 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 X-Tray; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include "utility.h" +#include "plugin.h" +#include "xtray.h" +#include "callbacks.h" +#include "resource.h" + +TCHAR BACKUP_INI_FILE[] = _T(".\\plugins\\config\\xtray.conf"); +struct HOTKEY g_hHotKey; + +void SavePrefs(int iDlg) +{ + /**************************************************************************************************/ + /********** allocate space for our string, and then set it to the currently logged on user ********/ + /**************************************************************************************************/ + DWORD dBuff = 257; + TCHAR szUser[257]; + + GetUserName(szUser, &dBuff); + + /**************************************************************************************************/ + /*********************** Test if the file exists, If it doesn't, Create It ************************/ + /**************************************************************************************************/ + TCHAR XTRAY_INI_FILE[1024]; + +#ifdef UNICODE + char temp[1024]; + TCHAR TEMP_INI_FILE[1024]; + + _snprintf(temp, 1024, "%s\\xtray.conf", xchat_get_info(ph, "xchatdir")); + ConvertString(temp, TEMP_INI_FILE, 1024); + + // ok this one is really ugly + // it checks to see if the file exists in two locations + // X-Chat default config dir, if that fails it trys xchat\plugins\config + // if neither one exists it tries to create it in + // X-Chat default config dir, if that fails it trys xchat\plugins\config + // In either case it writes \xFF\xFE to the file ( on creation ) + // so that we can save unicode away messages WritePrivateProfile doesn't + // do this for us, though I think it really should + + if(FileExists(TEMP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE); + } + else + { + if(FileExists(BACKUP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE); + } + else + { + HANDLE xTemp; + DWORD dwBytesTemp; + + if(xTemp = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL)) + { + if(GetLastError() != ERROR_ALREADY_EXISTS) + { + WriteFile(xTemp, _T("\xFF\xFE"), 4, &dwBytesTemp, NULL); + } + CloseHandle(xTemp); + } + + if(FileExists(TEMP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE); + } + else + { + HANDLE xBackup; + DWORD dwBytesBackup; + + if(xBackup = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL)) + { + if(GetLastError() != ERROR_ALREADY_EXISTS) + { + WriteFile(xBackup, _T("\xFF\xFE"), 4, &dwBytesBackup, NULL); + } + + CloseHandle(xBackup); + } + + if(FileExists(BACKUP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE); + } + } + } + } + +#else + _tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE); +#endif + + WritePrivateProfileInt(szUser, _T("SETTINGS"), g_dwPrefs, XTRAY_INI_FILE); + WritePrivateProfileInt(szUser, _T("AOT"), g_iTime, XTRAY_INI_FILE); + WritePrivateProfileInt(szUser, _T("KEY"), g_hHotKey.key, XTRAY_INI_FILE); + WritePrivateProfileInt(szUser, _T("MOD"), g_hHotKey.mod, XTRAY_INI_FILE); + WritePrivateProfileString(szUser, _T("AWAY"), g_szAway, XTRAY_INI_FILE); +} + +void LoadPrefs() +{ + /**************************************************************************************************/ + /*********************** Our Settings Section *****************************************************/ + /**************************************************************************************************/ + DWORD dBuff = 257; + TCHAR szUser[257]; + + GetUserName(szUser, &dBuff); + + /**************************************************************************************************/ + /*********************** Test if the file exists, If it doesn't, Create It ************************/ + /**************************************************************************************************/ + TCHAR XTRAY_INI_FILE[1024]; + +#ifdef UNICODE + char temp[1024]; + TCHAR TEMP_INI_FILE[1024]; + + _snprintf(temp, 1024, "%s\\xtray.conf", xchat_get_info(ph, "xchatdir")); + ConvertString(temp, TEMP_INI_FILE, 1024); + + if(FileExists(TEMP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE); + } + else + { + if(FileExists(BACKUP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE); + } + else + { + HANDLE xTemp; + DWORD dwBytesTemp; + + if(xTemp = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL)) + { + if(GetLastError() != ERROR_ALREADY_EXISTS) + { + WriteFile(xTemp, _T("\xFF\xFE"), 4, &dwBytesTemp, NULL); + } + + CloseHandle(xTemp); + } + + if(FileExists(TEMP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE); + } + else + { + HANDLE xBackup; + DWORD dwBytesBackup; + + if(xBackup = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL)) + { + if(GetLastError() != ERROR_ALREADY_EXISTS) + { + WriteFile(xBackup, _T("\xFF\xFE"), 4, &dwBytesBackup, NULL); + } + + CloseHandle(xBackup); + } + + if(FileExists(BACKUP_INI_FILE)) + { + _tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE); + } + } + } + } + +#else + _tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE); +#endif + + /**************************************************************************************************/ + /*************************** Get the value for each of our preferances ****************************/ + /**************************************************************************************************/ + g_dwPrefs = GetPrivateProfileInt(szUser, _T("SETTINGS"), 0, XTRAY_INI_FILE); + + // backwards compatability + // also allows us to set defaults if its a new installation + // disable topic change, channel message and server notice by default + if(g_dwPrefs == 0) + { + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("HILIGHT"), 1, XTRAY_INI_FILE)<<1); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("INVITE"), 1, XTRAY_INI_FILE)<<2); + /* g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("TOPIC"), 1, XTRAY_INI_FILE)<<3); */ + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("BANNED"), 1, XTRAY_INI_FILE)<<4); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("KICKED"), 1, XTRAY_INI_FILE)<<5); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("CTCP"), 1, XTRAY_INI_FILE)<<6); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("PMSG"), 1, XTRAY_INI_FILE)<<7); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("KILLED"), 1, XTRAY_INI_FILE)<<8); + /* g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("NOTICE"), 1, XTRAY_INI_FILE)<<9); */ + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("DISCONNECT"), 1, XTRAY_INI_FILE)<<10); + + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("AOM"), 0, XTRAY_INI_FILE)<<11); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("TOT"), 1, XTRAY_INI_FILE)<<12); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("AMAE"), 1, XTRAY_INI_FILE)<<13); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("OSBWM"), 0, XTRAY_INI_FILE)<<14); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("UWIOB"), 0, XTRAY_INI_FILE)<<15); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("KAOI"), 0, XTRAY_INI_FILE)<<16); + g_dwPrefs |= (GetPrivateProfileInt(szUser, _T("MIOC"), 0, XTRAY_INI_FILE)<<17); + } + + g_hHotKey.key = GetPrivateProfileInt(szUser, _T("KEY"), 84, XTRAY_INI_FILE); + g_hHotKey.mod = GetPrivateProfileInt(szUser, _T("MOD"), (MOD_CONTROL | MOD_SHIFT), XTRAY_INI_FILE); + g_iTime = GetPrivateProfileInt(szUser, _T("AOT"), 5, XTRAY_INI_FILE); + + GetPrivateProfileString(szUser, _T("AWAY"), _T(""), g_szAway, 1024, XTRAY_INI_FILE); + + /**************************************************************************************************/ + /******************************** Register our hotkey with windows ********************************/ + /**************************************************************************************************/ + if(g_dwPrefs & (1< Date: Wed, 27 Jul 2011 09:04:58 +0200 Subject: fix xtray keyboard shortcut handling --- plugins/xtray/utility.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- plugins/xtray/utility.h | 3 +++ 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'plugins/xtray/utility.cpp') diff --git a/plugins/xtray/utility.cpp b/plugins/xtray/utility.cpp index 60f3f2f0..4faed90b 100644 --- a/plugins/xtray/utility.cpp +++ b/plugins/xtray/utility.cpp @@ -29,6 +29,49 @@ TCHAR BACKUP_INI_FILE[] = _T(".\\plugins\\config\\xtray.conf"); struct HOTKEY g_hHotKey; +/* we need to convert ALT and SHIFT modifiers +// from +#define MOD_ALT 0x0001 +#define MOD_CONTROL 0x0002 +#define MOD_SHIFT 0x0004 +// from +#define HOTKEYF_SHIFT 0x01 +#define HOTKEYF_CONTROL 0x02 +#define HOTKEYF_ALT 0x04 +*/ + +WORD HotkeyfToMod(WORD modifiers) +{ + WORD newmods = 0; + + if (modifiers & HOTKEYF_SHIFT) + newmods |= MOD_SHIFT; + + if (modifiers & HOTKEYF_CONTROL) + newmods |= MOD_CONTROL; + + if (modifiers & HOTKEYF_ALT) + newmods |= MOD_ALT; + + return newmods; +} + +WORD ModToHotkeyf(WORD modifiers) +{ + WORD newmods = 0; + + if (modifiers & MOD_SHIFT) + newmods |= HOTKEYF_SHIFT; + + if (modifiers & MOD_CONTROL) + newmods |= HOTKEYF_CONTROL; + + if (modifiers & MOD_ALT) + newmods |= HOTKEYF_ALT; + + return newmods; +} + void SavePrefs(int iDlg) { /**************************************************************************************************/ @@ -292,7 +335,7 @@ void CheckPrefs(HWND hwnd, int iDlg) hHotkey = SendDlgItemMessage(hwnd, IDC_ALERT_HOTKEY, HKM_GETHOTKEY, 0, 0); g_hHotKey.key = LOBYTE(hHotkey); - g_hHotKey.mod = HIBYTE(hHotkey); + g_hHotKey.mod = HotkeyfToMod(HIBYTE(hHotkey)); if(IsDlgButtonChecked(hwnd, PREF_UWIOB) == BST_CHECKED) { @@ -403,7 +446,7 @@ void SetDialog(HWND hwnd, int iDlg) /**********************************************************/ TCHAR tTime[255]; SendDlgItemMessage(hwnd, IDC_ALERT_TIME, WM_SETTEXT, 0, (LPARAM)_itot(g_iTime, tTime, 10)); - SendDlgItemMessage(hwnd, IDC_ALERT_HOTKEY, HKM_SETHOTKEY, MAKEWORD(g_hHotKey.key, g_hHotKey.mod), 0); + SendDlgItemMessage(hwnd, IDC_ALERT_HOTKEY, HKM_SETHOTKEY, MAKEWORD(g_hHotKey.key, ModToHotkeyf(g_hHotKey.mod)), 0); } break; } diff --git a/plugins/xtray/utility.h b/plugins/xtray/utility.h index ce3d541c..6bee8aed 100644 --- a/plugins/xtray/utility.h +++ b/plugins/xtray/utility.h @@ -19,6 +19,9 @@ #ifndef _H_UTILITY_H #define _H_UTILITY_H +WORD HotkeyfToMod (WORD); +WORD ModToHotkeyf (WORD); + int SetOption (HWND, unsigned int, unsigned int); int SetCheck (HWND, unsigned int, unsigned int); int SetToggle (HWND, unsigned int, unsigned int, bool); -- cgit 1.4.1