From ef6eb3eb500e2d98b41f3fef1cbda4c48379af18 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Fri, 22 Aug 2003 15:30:30 +0000 Subject: [PATCH] check for valid task icon owener windows svn path=/trunk/; revision=5758 --- .../system/explorer/desktop/desktop.cpp | 14 +---- .../subsys/system/explorer/desktop/desktop.h | 3 - .../system/explorer/shell/filechild.cpp | 4 +- reactos/subsys/system/explorer/shell/pane.cpp | 2 +- .../system/explorer/taskbar/desktopbar.cpp | 17 +++--- .../system/explorer/taskbar/desktopbar.h | 3 + .../subsys/system/explorer/taskbar/taskbar.h | 1 - .../system/explorer/taskbar/traynotify.cpp | 61 +++++++++++++++---- .../system/explorer/taskbar/traynotify.h | 4 ++ .../subsys/system/explorer/utility/window.cpp | 9 +++ 10 files changed, 78 insertions(+), 40 deletions(-) diff --git a/reactos/subsys/system/explorer/desktop/desktop.cpp b/reactos/subsys/system/explorer/desktop/desktop.cpp index a1127a9d65f..997b1114c79 100644 --- a/reactos/subsys/system/explorer/desktop/desktop.cpp +++ b/reactos/subsys/system/explorer/desktop/desktop.cpp @@ -67,9 +67,9 @@ static void draw_desktop_background(HWND hwnd, HDC hdc) // This next part could be improved by working out how much // space the text actually needs... -#define TASKBAR_HEIGHT 30 +#define DESKTOPBARBAR_HEIGHT 30 rect.left = rect.right - 280; - rect.top = rect.bottom - 56 - TASKBAR_HEIGHT; + rect.top = rect.bottom - 56 - DESKTOPBARBAR_HEIGHT; rect.right = rect.left + 250; rect.bottom = rect.top + 40; @@ -208,14 +208,6 @@ LRESULT DesktopWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) explorer_show_frame(_hwnd, SW_SHOWNORMAL); break; - case WM_SETFOCUS: - // close startup menu and other popup menus like that of tray notification icons - if (wparam) - PostMessage((HWND)wparam, WM_CANCELMODE, 0, 0); - else - PostMessage(HWND_BROADCAST, WM_CANCELMODE, 0, 0); - goto def; - case WM_GETISHELLBROWSER: return (LRESULT)static_cast(this); @@ -230,7 +222,7 @@ LRESULT DesktopWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) case WM_CLOSE: break; // Over-ride close. We need to close desktop some other way. - default: def: + default: return super::WndProc(nmsg, wparam, lparam); } diff --git a/reactos/subsys/system/explorer/desktop/desktop.h b/reactos/subsys/system/explorer/desktop/desktop.h index b9b22293120..7407244c833 100644 --- a/reactos/subsys/system/explorer/desktop/desktop.h +++ b/reactos/subsys/system/explorer/desktop/desktop.h @@ -34,9 +34,6 @@ #include "../externals.h" -#define WINMSG_DESKTOP_GOT_FOCUS _T("DesktopWindowGotFocus") - - struct BackgroundWindow : public SubclassedWindow { typedef SubclassedWindow super; diff --git a/reactos/subsys/system/explorer/shell/filechild.cpp b/reactos/subsys/system/explorer/shell/filechild.cpp index 411d0013844..21a23bedeef 100644 --- a/reactos/subsys/system/explorer/shell/filechild.cpp +++ b/reactos/subsys/system/explorer/shell/filechild.cpp @@ -323,7 +323,7 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) } SetFocus(_focus_pane? _right_hwnd: _left_hwnd); - break;} + goto def;} case PM_DISPATCH_COMMAND: { Pane* pane = GetFocus()==_left_hwnd? _left: _right; @@ -355,7 +355,7 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) return TRUE;} - default: + default: def: return super::WndProc(nmsg, wparam, lparam); } diff --git a/reactos/subsys/system/explorer/shell/pane.cpp b/reactos/subsys/system/explorer/shell/pane.cpp index e5200c386a6..23ab6ddd0cd 100644 --- a/reactos/subsys/system/explorer/shell/pane.cpp +++ b/reactos/subsys/system/explorer/shell/pane.cpp @@ -151,7 +151,7 @@ LRESULT Pane::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) child->switch_focus_pane(); } break;} -} + } return super::WndProc(nmsg, wparam, lparam); } diff --git a/reactos/subsys/system/explorer/taskbar/desktopbar.cpp b/reactos/subsys/system/explorer/taskbar/desktopbar.cpp index b5ec8e03e3e..e223471ff8e 100644 --- a/reactos/subsys/system/explorer/taskbar/desktopbar.cpp +++ b/reactos/subsys/system/explorer/taskbar/desktopbar.cpp @@ -47,10 +47,10 @@ HWND InitializeExplorerBar(HINSTANCE hInstance) #ifdef TASKBAR_AT_TOP rect.top = -2; // hide top border #else - rect.top = GetSystemMetrics(SM_CYSCREEN) - TASKBAR_HEIGHT; + rect.top = GetSystemMetrics(SM_CYSCREEN) - DESKTOPBARBAR_HEIGHT; #endif rect.right = GetSystemMetrics(SM_CXSCREEN) + 2; - rect.bottom = rect.top + TASKBAR_HEIGHT + 2; + rect.bottom = rect.top + DESKTOPBARBAR_HEIGHT + 2; return Window::Create(WINDOW_CREATOR(DesktopBar), WS_EX_PALETTEWINDOW, BtnWindowClass(CLASSNAME_EXPLORERBAR), TITLE_EXPLORERBAR, @@ -78,7 +78,7 @@ LRESULT DesktopBar::Init(LPCREATESTRUCT pcs) return 1; // create start button - new PictureButton(Button(_hwnd, ResString(IDS_START), 2, 2, STARTBUTTON_WIDTH, TASKBAR_HEIGHT-8, IDC_START, WS_VISIBLE|WS_CHILD|BS_OWNERDRAW), + new PictureButton(Button(_hwnd, ResString(IDS_START), 2, 2, STARTBUTTON_WIDTH, DESKTOPBARBAR_HEIGHT-8, IDC_START, WS_VISIBLE|WS_CHILD|BS_OWNERDRAW), SmallIcon(IDI_STARTMENU)); ClientRect clnt(_hwnd); @@ -86,9 +86,9 @@ LRESULT DesktopBar::Init(LPCREATESTRUCT pcs) // create task bar _hwndTaskBar = Window::Create(WINDOW_CREATOR(TaskBar), 0, BtnWindowClass(CLASSNAME_TASKBAR), TITLE_TASKBAR, WS_CHILD|WS_VISIBLE, - TASKBAR_LEFT, 0, clnt.right-TASKBAR_LEFT-(NOTIFYAREA_WIDTH+1), TASKBAR_HEIGHT, _hwnd); + TASKBAR_LEFT, 0, clnt.right-TASKBAR_LEFT-(NOTIFYAREA_WIDTH+1), DESKTOPBARBAR_HEIGHT, _hwnd); - TaskBar* taskbar = static_cast(Window::get_window(_hwndTaskBar)); + TaskBar* taskbar = static_cast(get_window(_hwndTaskBar)); taskbar->_desktop_bar = this; // create tray notification area @@ -96,7 +96,7 @@ LRESULT DesktopBar::Init(LPCREATESTRUCT pcs) BtnWindowClass(CLASSNAME_TRAYNOTIFY,CS_DBLCLKS), TITLE_TRAYNOTIFY, WS_CHILD|WS_VISIBLE, clnt.right-(NOTIFYAREA_WIDTH+1), 1, NOTIFYAREA_WIDTH, clnt.bottom-2, _hwnd); -// NotifyArea* notify_area = static_cast(Window::get_window(_hwndNotify)); +// NotifyArea* notify_area = static_cast(get_window(_hwndNotify)); // notify_area->_desktop_bar = this; RegisterHotkeys(); @@ -171,8 +171,7 @@ LRESULT DesktopBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) MoveWindow(_hwndNotify, cx-(NOTIFYAREA_WIDTH+1), 1, NOTIFYAREA_WIDTH, cy-2, TRUE); WindowRect rect(_hwnd); - int height = rect.bottom-rect.top; - RECT work_area = {0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)-(height-1)}; + RECT work_area = {0, 0, GetSystemMetrics(SM_CXSCREEN), rect.top}; SystemParametersInfo(SPI_SETWORKAREA, 0, &work_area, 0); PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETWORKAREA, 0); break;} @@ -252,7 +251,7 @@ LRESULT DesktopBar::ProcessCopyData(COPYDATASTRUCT* pcd) //TODO: process the differnt versions of the NOTIFYICONDATA structure (look at cbSize to decide which one) - NotifyArea* notify_area = static_cast(Window::get_window(_hwndNotify)); + NotifyArea* notify_area = static_cast(get_window(_hwndNotify)); if (notify_area) return notify_area->ProcessTrayNotification(ptr->notify_code, &ptr->nicon_data); diff --git a/reactos/subsys/system/explorer/taskbar/desktopbar.h b/reactos/subsys/system/explorer/taskbar/desktopbar.h index 23b57388340..9ea73e4b4c1 100644 --- a/reactos/subsys/system/explorer/taskbar/desktopbar.h +++ b/reactos/subsys/system/explorer/taskbar/desktopbar.h @@ -36,6 +36,9 @@ #define WINMSG_TASKBARCREATED _T("TaskbarCreated") +#define DESKTOPBARBAR_HEIGHT 29 + + #define IDC_START 0x1000 #define IDC_LOGOFF 0x1001 #define IDC_SHUTDOWN 0x1002 diff --git a/reactos/subsys/system/explorer/taskbar/taskbar.h b/reactos/subsys/system/explorer/taskbar/taskbar.h index a68b0cef130..6b43216a93e 100644 --- a/reactos/subsys/system/explorer/taskbar/taskbar.h +++ b/reactos/subsys/system/explorer/taskbar/taskbar.h @@ -34,7 +34,6 @@ #define IDC_FIRST_APP 0x2000 -#define TASKBAR_HEIGHT 30 #define STARTBUTTON_WIDTH 60 #define TASKBAR_LEFT 70 //#define TASKBAR_AT_TOP diff --git a/reactos/subsys/system/explorer/taskbar/traynotify.cpp b/reactos/subsys/system/explorer/taskbar/traynotify.cpp index 717c6ccd995..0b4e9b43f22 100644 --- a/reactos/subsys/system/explorer/taskbar/traynotify.cpp +++ b/reactos/subsys/system/explorer/taskbar/traynotify.cpp @@ -98,9 +98,16 @@ LRESULT NotifyArea::Init(LPCREATESTRUCT pcs) BtnWindowClass(CLASSNAME_CLOCKWINDOW,CS_DBLCLKS), NULL, WS_CHILD|WS_VISIBLE, clnt.right-(CLOCKWINDOW_WIDTH+1), 1, CLOCKWINDOW_WIDTH, clnt.bottom-2, _hwnd); + SetTimer(_hwnd, 0, 1000, NULL); + return 0; } +NotifyArea::~NotifyArea() +{ + KillTimer(_hwnd, 0); +} + LRESULT NotifyArea::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) { switch(nmsg) { @@ -108,6 +115,15 @@ LRESULT NotifyArea::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) Paint(); break; + case WM_TIMER: { + Tick(); + + ClockWindow* clock_window = static_cast(get_window(_hwndClock)); + + if (clock_window) + clock_window->Tick(); + break;} + default: if (nmsg>=WM_MOUSEFIRST && nmsg<=WM_MOUSELAST) { NotifyIconSet::iterator found = IconHitTest(Point(lparam)); @@ -116,13 +132,10 @@ LRESULT NotifyArea::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) NotifyInfo& entry = const_cast(*found); // Why does GCC 3.3 need this additional const_cast ?! // Notify the message the the owner if it's still alive - if (IsWindow(entry._hWnd)) //TODO: We could check this regularly for all icons by using WM_TIMER to prevent for hanging icons + if (IsWindow(entry._hWnd)) PostMessage(entry._hWnd, entry._uCallbackMessage, entry._uID, nmsg); - else { - // delete icons without owner window - if (_icon_map.erase(entry)) - Refresh(); - } + else if (_icon_map.erase(entry)) // delete icons without valid owner window + Refresh(); } } @@ -199,6 +212,29 @@ void NotifyArea::Paint() } } +void NotifyArea::Tick() +{ + bool do_refresh = false; + + // Look for task icons without valid owner window. + // This is an advanced feature, which is missing in MS Windows. + for(NotifyIconSet::const_iterator it=_sorted_icons.begin(); it!=_sorted_icons.end(); ++it) + { + const NotifyInfo& entry = *it; + +#ifdef NIF_STATE // currently (as of 21.08.2003) missing in MinGW headers + if (!(entry._dwState & NIS_HIDDEN)) +#endif + { + if (!IsWindow(entry._hWnd)) + if (_icon_map.erase(entry)) // delete icons without valid owner window + ++do_refresh; + } + } + + if (do_refresh) + Refresh(); +} /// search for a icon at a given client coordinate position NotifyIconSet::iterator NotifyArea::IconHitTest(const POINT& pos) @@ -234,8 +270,6 @@ ClockWindow::ClockWindow(HWND hwnd) { *_time = _T('\0'); FormatTime(); - - SetTimer(hwnd, 0, 1000, NULL); } LRESULT ClockWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) @@ -245,11 +279,6 @@ LRESULT ClockWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) Paint(); break; - case WM_TIMER: { - if (FormatTime()) - InvalidateRect(_hwnd, NULL, TRUE); - break;} - default: return super::WndProc(nmsg, wparam, lparam); } @@ -257,6 +286,12 @@ LRESULT ClockWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) return 0; } +void ClockWindow::Tick() +{ + if (FormatTime()) + InvalidateRect(_hwnd, NULL, TRUE); // refresh displayed time +} + bool ClockWindow::FormatTime() { SYSTEMTIME systime; diff --git a/reactos/subsys/system/explorer/taskbar/traynotify.h b/reactos/subsys/system/explorer/taskbar/traynotify.h index f7673641576..7e8fce54d9e 100644 --- a/reactos/subsys/system/explorer/taskbar/traynotify.h +++ b/reactos/subsys/system/explorer/taskbar/traynotify.h @@ -76,6 +76,7 @@ struct NotifyArea : public Window typedef Window super; NotifyArea(HWND hwnd); + ~NotifyArea(); // DesktopBar* _desktop_bar; @@ -93,6 +94,7 @@ protected: void Refresh(); void Paint(); + void Tick(); NotifyIconSet::iterator IconHitTest(const POINT& pos); }; @@ -105,6 +107,8 @@ struct ClockWindow : public Window ClockWindow(HWND hwnd); + void Tick(); + protected: LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); diff --git a/reactos/subsys/system/explorer/utility/window.cpp b/reactos/subsys/system/explorer/utility/window.cpp index 99a22c1eafb..f071c214cd2 100644 --- a/reactos/subsys/system/explorer/utility/window.cpp +++ b/reactos/subsys/system/explorer/utility/window.cpp @@ -186,6 +186,15 @@ LRESULT CALLBACK Window::WindowWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPAR LRESULT Window::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) { + if (nmsg == WM_SETFOCUS) { + // close startup menu and other popup menus + // This functionality is for tray notification icons missing in MS Windows. + if (wparam) + PostMessage((HWND)wparam, WM_CANCELMODE, 0, 0); + else + PostMessage(HWND_BROADCAST, WM_CANCELMODE, 0, 0); + } + return DefWindowProc(_hwnd, nmsg, wparam, lparam); }