/* * Copyright 2003, 2004, 2005 Martin Fuchs * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // // Explorer clone // // traynotify.cpp // // Martin Fuchs, 22.08.2003 // #include #include "../resource.h" #include "traynotify.h" #include "../notifyhook/notifyhook.h" NotifyHook::NotifyHook() : WM_GETMODULEPATH(InstallNotifyHook()) { } NotifyHook::~NotifyHook() { DeinstallNotifyHook(); } void NotifyHook::GetModulePath(HWND hwnd, HWND hwndCallback) { PostMessage(hwnd, WM_GETMODULEPATH, (WPARAM)hwndCallback, 0); } bool NotifyHook::ModulePathCopyData(LPARAM lparam, HWND* phwnd, String& path) { char buffer[MAX_PATH]; int l = GetWindowModulePathCopyData(lparam, phwnd, buffer, COUNTOF(buffer)); if (l) { path.assign(buffer, l); return true; } else return false; } NotifyIconIndex::NotifyIconIndex(NOTIFYICONDATA* pnid) { _hWnd = pnid->hWnd; _uID = pnid->uID; // special handling for windows task manager if ((int)_uID < 0) _uID = 0; } NotifyIconIndex::NotifyIconIndex() { _hWnd = 0; _uID = 0; } NotifyInfo::NotifyInfo() { _idx = -1; _hIcon = 0; _dwState = 0; _uCallbackMessage = 0; _version = 0; _mode = NIM_AUTO; _lastChange = GetTickCount(); } // WCHAR versions von NOTIFYICONDATA #define NID_SIZE_W6 sizeof(NOTIFYICONDATAW) // _WIN32_IE = 0x600 #define NID_SIZE_W5 (sizeof(NOTIFYICONDATAW)-sizeof(GUID)) // _WIN32_IE = 0x500 #define NID_SIZE_W3 (sizeof(NOTIFYICONDATAW)-sizeof(GUID)-(128-64)*sizeof(WCHAR)) // _WIN32_IE < 0x500 // CHAR versions von NOTIFYICONDATA #define NID_SIZE_A6 sizeof(NOTIFYICONDATAA) #define NID_SIZE_A5 (sizeof(NOTIFYICONDATAA)-sizeof(GUID)) #define NID_SIZE_A3 (sizeof(NOTIFYICONDATAA)-sizeof(GUID)-(128-64)*sizeof(CHAR)) bool NotifyInfo::modify(NOTIFYICONDATA* pnid) { bool changes = false; if (_hWnd!=pnid->hWnd || _uID!=pnid->uID) { _hWnd = pnid->hWnd; _uID = pnid->uID; changes = true; } if (pnid->uFlags & NIF_MESSAGE) { if (_uCallbackMessage != pnid->uCallbackMessage) { _uCallbackMessage = pnid->uCallbackMessage; changes = true; } } if (pnid->uFlags & NIF_ICON) { // Some applications destroy the icon immediatelly after completing the // NIM_ADD/MODIFY message, so we have to make a copy of it. if (_hIcon) DestroyIcon(_hIcon); _hIcon = (HICON) CopyImage(pnid->hIcon, IMAGE_ICON, NOTIFYICON_SIZE, NOTIFYICON_SIZE, 0); changes = true; ///@todo compare icon } #ifdef NIF_STATE // as of 21.08.2003 missing in MinGW headers if (pnid->uFlags & NIF_STATE) { DWORD new_state = (_dwState&~pnid->dwStateMask) | (pnid->dwState&pnid->dwStateMask); if (_dwState != new_state) { _dwState = new_state; changes = true; } } #endif // store tool tip text if (pnid->uFlags & NIF_TIP) { String new_text; if (pnid->cbSize==NID_SIZE_W6 || pnid->cbSize==NID_SIZE_W5 || pnid->cbSize==NID_SIZE_W3) { // UNICODE version of NOTIFYICONDATA structure LPCWSTR txt = (LPCWSTR)pnid->szTip; int max_len = pnid->cbSize==NID_SIZE_W3? 64: 128; // get tooltip string length int l = 0; for(; lcbSize==NID_SIZE_A6 || pnid->cbSize==NID_SIZE_A5 || pnid->cbSize==NID_SIZE_A3) { LPCSTR txt = (LPCSTR)pnid->szTip; int max_len = pnid->cbSize==NID_SIZE_A3? 64: 128; int l = 0; for(int l=0; l