wined3d: Use the FBO cache in stretch_rect_fbo().
[wine/hramrach.git] / programs / taskmgr / applpage.c
blob9f058687a6f1d269191dcbcfd18e39edcfd7cf98
1 /*
2 * ReactOS Task Manager
4 * applpage.c
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * Copyright (C) 2008 Vladimir Pankratov
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
25 #include <windows.h>
26 #include <commctrl.h>
27 #include <stdlib.h>
28 #include <memory.h>
29 #include <stdio.h>
31 #include "wine/unicode.h"
32 #include "taskmgr.h"
34 typedef struct
36 HWND hWnd;
37 WCHAR wszTitle[256];
38 HICON hIcon;
39 BOOL bHung;
40 } APPLICATION_PAGE_LIST_ITEM, *LPAPPLICATION_PAGE_LIST_ITEM;
42 HWND hApplicationPage; /* Application List Property Page */
43 HWND hApplicationPageListCtrl; /* Application ListCtrl Window */
44 HWND hApplicationPageEndTaskButton; /* Application End Task button */
45 HWND hApplicationPageSwitchToButton; /* Application Switch To button */
46 HWND hApplicationPageNewTaskButton; /* Application New Task button */
47 static int nApplicationPageWidth;
48 static int nApplicationPageHeight;
49 static HANDLE hApplicationPageEvent = NULL; /* When this event becomes signaled then we refresh the app list */
50 static BOOL bSortAscending = TRUE;
52 static const WCHAR wszUser32[] = {'U','S','E','R','3','2','.','D','L','L',0};
53 #if 0
54 void SwitchToThisWindow (
55 HWND hWnd, /* Handle to the window that should be activated */
56 BOOL bRestore /* Restore the window if it is minimized */
58 #endif
60 static void ApplicationPageUpdate(void)
62 /* Enable or disable the "End Task" & "Switch To" buttons */
63 if (ListView_GetSelectedCount(hApplicationPageListCtrl))
65 EnableWindow(hApplicationPageEndTaskButton, TRUE);
66 EnableWindow(hApplicationPageSwitchToButton, TRUE);
68 else
70 EnableWindow(hApplicationPageEndTaskButton, FALSE);
71 EnableWindow(hApplicationPageSwitchToButton, FALSE);
74 /* If we are on the applications tab, then the windows menu will */
75 /* be present on the menu bar so enable & disable the menu items */
76 if (TabCtrl_GetCurSel(hTabWnd) == 0)
78 HMENU hMenu;
79 HMENU hWindowsMenu;
81 hMenu = GetMenu(hMainWnd);
82 hWindowsMenu = GetSubMenu(hMenu, 3);
84 /* Only one item selected */
85 if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
87 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
88 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
89 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
90 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
91 EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
92 EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
94 /* More than one item selected */
95 else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
97 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
98 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
99 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
100 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
101 EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
102 EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
104 /* No items selected */
105 else
107 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
108 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
109 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
110 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
111 EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
112 EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
117 static void AddOrUpdateHwnd(HWND hWnd, WCHAR *wszTitle, HICON hIcon, BOOL bHung)
119 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
120 HIMAGELIST hImageListLarge;
121 HIMAGELIST hImageListSmall;
122 LV_ITEMW item;
123 int i;
124 BOOL bAlreadyInList = FALSE;
125 BOOL bItemRemoved = FALSE;
127 memset(&item, 0, sizeof(LV_ITEMW));
129 /* Get the image lists */
130 hImageListLarge = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_NORMAL);
131 hImageListSmall = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_SMALL);
133 /* Check to see if it's already in our list */
134 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++)
136 memset(&item, 0, sizeof(LV_ITEMW));
137 item.mask = LVIF_IMAGE|LVIF_PARAM;
138 item.iItem = i;
139 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
141 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
142 if (pAPLI->hWnd == hWnd)
144 bAlreadyInList = TRUE;
145 break;
149 /* If it is already in the list then update it if necessary */
150 if (bAlreadyInList)
152 /* Check to see if anything needs updating */
153 if ((pAPLI->hIcon != hIcon) ||
154 (strcmpW(pAPLI->wszTitle, wszTitle) != 0) ||
155 (pAPLI->bHung != bHung))
157 /* Update the structure */
158 pAPLI->hIcon = hIcon;
159 pAPLI->bHung = bHung;
160 strcpyW(pAPLI->wszTitle, wszTitle);
162 /* Update the image list */
163 ImageList_ReplaceIcon(hImageListLarge, item.iItem, hIcon);
164 ImageList_ReplaceIcon(hImageListSmall, item.iItem, hIcon);
166 /* Update the list view */
167 SendMessageW(hApplicationPageListCtrl, LVM_REDRAWITEMS, 0, ListView_GetItemCount(hApplicationPageListCtrl));
168 /* UpdateWindow(hApplicationPageListCtrl); */
169 InvalidateRect(hApplicationPageListCtrl, NULL, 0);
172 /* It is not already in the list so add it */
173 else
175 pAPLI = HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_PAGE_LIST_ITEM));
177 pAPLI->hWnd = hWnd;
178 pAPLI->hIcon = hIcon;
179 pAPLI->bHung = bHung;
180 strcpyW(pAPLI->wszTitle, wszTitle);
182 /* Add the item to the list */
183 memset(&item, 0, sizeof(LV_ITEMW));
184 item.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
185 ImageList_AddIcon(hImageListLarge, hIcon);
186 item.iImage = ImageList_AddIcon(hImageListSmall, hIcon);
187 item.pszText = LPSTR_TEXTCALLBACKW;
188 item.iItem = ListView_GetItemCount(hApplicationPageListCtrl);
189 item.lParam = (LPARAM)pAPLI;
190 SendMessageW(hApplicationPageListCtrl, LVM_INSERTITEMW, 0, (LPARAM) &item);
194 /* Check to see if we need to remove any items from the list */
195 for (i=ListView_GetItemCount(hApplicationPageListCtrl)-1; i>=0; i--)
197 memset(&item, 0, sizeof(LV_ITEMW));
198 item.mask = LVIF_IMAGE|LVIF_PARAM;
199 item.iItem = i;
200 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
202 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
203 if (!IsWindow(pAPLI->hWnd)||
204 (strlenW(pAPLI->wszTitle) <= 0) ||
205 !IsWindowVisible(pAPLI->hWnd) ||
206 (GetParent(pAPLI->hWnd) != NULL) ||
207 (GetWindow(pAPLI->hWnd, GW_OWNER) != NULL) ||
208 (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
210 ImageList_Remove(hImageListLarge, item.iItem);
211 ImageList_Remove(hImageListSmall, item.iItem);
213 SendMessage(hApplicationPageListCtrl, LVM_DELETEITEM, item.iItem, 0);
214 HeapFree(GetProcessHeap(), 0, pAPLI);
215 bItemRemoved = TRUE;
220 * If an item was removed from the list then
221 * we need to resync all the items with the
222 * image list
224 if (bItemRemoved)
226 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++)
228 memset(&item, 0, sizeof(LV_ITEMW));
229 item.mask = LVIF_IMAGE;
230 item.iItem = i;
231 item.iImage = i;
232 SendMessageW(hApplicationPageListCtrl, LVM_SETITEMW, 0, (LPARAM) &item);
236 ApplicationPageUpdate();
239 static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
241 HICON hIcon;
242 WCHAR wszText[256];
243 BOOL bLargeIcon;
244 BOOL bHung = FALSE;
245 typedef int (__stdcall *IsHungAppWindowProc)(HWND);
246 IsHungAppWindowProc IsHungAppWindow;
249 /* Skip our window */
250 if (hWnd == hMainWnd)
251 return TRUE;
253 bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE;
255 /* Check and see if this is a top-level app window */
256 if (!GetWindowTextW(hWnd, wszText, sizeof(wszText)/sizeof(WCHAR)) ||
257 !IsWindowVisible(hWnd) ||
258 (GetParent(hWnd) != NULL) ||
259 (GetWindow(hWnd, GW_OWNER) != NULL) ||
260 (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
262 return TRUE; /* Skip this window */
265 /* Get the icon for this window */
266 hIcon = NULL;
267 SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG /*1*/ : ICON_SMALL /*0*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
269 if (!hIcon)
271 hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICON : GCLP_HICONSM);
272 if (!hIcon) hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICONSM : GCLP_HICON);
273 if (!hIcon) SendMessageTimeout(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (PDWORD_PTR)&hIcon);
274 if (!hIcon) SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_SMALL /*0*/ : ICON_BIG /*1*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
277 if (!hIcon)
278 hIcon = LoadIcon(hInst, bLargeIcon ? MAKEINTRESOURCE(IDI_WINDOW) : MAKEINTRESOURCE(IDI_WINDOWSM));
280 bHung = FALSE;
282 IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandleW(wszUser32), "IsHungAppWindow");
284 if (IsHungAppWindow)
285 bHung = IsHungAppWindow(hWnd);
287 AddOrUpdateHwnd(hWnd, wszText, hIcon, bHung);
289 return TRUE;
292 static DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter)
294 /* Create the event */
295 hApplicationPageEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
297 /* If we couldn't create the event then exit the thread */
298 if (!hApplicationPageEvent)
299 return 0;
301 while (1)
303 DWORD dwWaitVal;
305 /* Wait on the event */
306 dwWaitVal = WaitForSingleObject(hApplicationPageEvent, INFINITE);
308 /* If the wait failed then the event object must have been */
309 /* closed and the task manager is exiting so exit this thread */
310 if (dwWaitVal == WAIT_FAILED)
311 return 0;
313 if (dwWaitVal == WAIT_OBJECT_0)
315 /* Reset our event */
316 ResetEvent(hApplicationPageEvent);
319 * FIXME:
321 * Should this be EnumDesktopWindows() instead?
323 EnumWindows(EnumWindowsProc, 0);
328 static void ApplicationPageShowContextMenu1(void)
330 HMENU hMenu;
331 HMENU hSubMenu;
332 POINT pt;
334 GetCursorPos(&pt);
336 hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1));
337 hSubMenu = GetSubMenu(hMenu, 0);
339 if (TaskManagerSettings.View_LargeIcons)
340 CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
341 else if (TaskManagerSettings.View_SmallIcons)
342 CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
343 else
344 CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
346 TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
348 DestroyMenu(hMenu);
351 static void ApplicationPageShowContextMenu2(void)
353 HMENU hMenu;
354 HMENU hSubMenu;
355 POINT pt;
357 GetCursorPos(&pt);
359 hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2));
360 hSubMenu = GetSubMenu(hMenu, 0);
362 if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
364 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
365 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
366 EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
367 EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
368 EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
369 EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
371 else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
373 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
374 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
375 EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
376 EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
377 EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
378 EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
380 else
382 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
383 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
384 EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
385 EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
386 EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
387 EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
390 SetMenuDefaultItem(hSubMenu, ID_APPLICATION_PAGE_SWITCHTO, MF_BYCOMMAND);
392 TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
394 DestroyMenu(hMenu);
397 static int CALLBACK ApplicationPageCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
399 LPAPPLICATION_PAGE_LIST_ITEM Param1;
400 LPAPPLICATION_PAGE_LIST_ITEM Param2;
402 if (bSortAscending) {
403 Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
404 Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
405 } else {
406 Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
407 Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
409 return strcmpW(Param1->wszTitle, Param2->wszTitle);
412 static void ApplicationPageOnNotify(WPARAM wParam, LPARAM lParam)
414 LPNMHDR pnmh;
415 LV_DISPINFOW* pnmdi;
416 LPAPPLICATION_PAGE_LIST_ITEM pAPLI;
418 WCHAR wszNotResponding[255];
419 WCHAR wszRunning[255];
421 LoadStringW(hInst, IDS_APPLICATION_NOT_RESPONDING, wszNotResponding, sizeof(wszNotResponding)/sizeof(WCHAR));
422 LoadStringW(hInst, IDS_APPLICATION_RUNNING, wszRunning, sizeof(wszRunning)/sizeof(WCHAR));
424 pnmh = (LPNMHDR) lParam;
425 pnmdi = (LV_DISPINFOW*) lParam;
427 if (pnmh->hwndFrom == hApplicationPageListCtrl) {
428 switch (pnmh->code) {
429 case LVN_ITEMCHANGED:
430 ApplicationPageUpdate();
431 break;
433 case LVN_GETDISPINFOW:
434 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)pnmdi->item.lParam;
436 /* Update the item text */
437 if (pnmdi->item.iSubItem == 0)
439 lstrcpynW(pnmdi->item.pszText, pAPLI->wszTitle, pnmdi->item.cchTextMax);
442 /* Update the item status */
443 else if (pnmdi->item.iSubItem == 1)
445 if (pAPLI->bHung)
446 lstrcpynW(pnmdi->item.pszText, wszNotResponding, pnmdi->item.cchTextMax);
447 else
448 lstrcpynW(pnmdi->item.pszText, wszRunning, pnmdi->item.cchTextMax);
451 break;
453 case NM_RCLICK:
455 if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1)
457 ApplicationPageShowContextMenu1();
459 else
461 ApplicationPageShowContextMenu2();
464 break;
466 case NM_DBLCLK:
468 ApplicationPage_OnSwitchTo();
470 break;
473 else if (pnmh->hwndFrom == ListView_GetHeader(hApplicationPageListCtrl))
475 switch (pnmh->code)
477 case NM_RCLICK:
479 if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1)
481 ApplicationPageShowContextMenu1();
483 else
485 ApplicationPageShowContextMenu2();
488 break;
490 case HDN_ITEMCLICK:
492 SendMessageW(hApplicationPageListCtrl, LVM_SORTITEMS, 0, (LPARAM) ApplicationPageCompareFunc);
493 bSortAscending = !bSortAscending;
495 break;
501 void RefreshApplicationPage(void)
503 /* Signal the event so that our refresh thread */
504 /* will wake up and refresh the application page */
505 SetEvent(hApplicationPageEvent);
508 static void UpdateApplicationListControlViewSetting(void)
510 DWORD dwStyle = GetWindowLong(hApplicationPageListCtrl, GWL_STYLE);
512 dwStyle &= ~LVS_REPORT;
513 dwStyle &= ~LVS_ICON;
514 dwStyle &= ~LVS_LIST;
515 dwStyle &= ~LVS_SMALLICON;
517 if (TaskManagerSettings.View_LargeIcons)
518 dwStyle |= LVS_ICON;
519 else if (TaskManagerSettings.View_SmallIcons)
520 dwStyle |= LVS_SMALLICON;
521 else
522 dwStyle |= LVS_REPORT;
524 SetWindowLong(hApplicationPageListCtrl, GWL_STYLE, dwStyle);
526 RefreshApplicationPage();
529 void ApplicationPage_OnViewLargeIcons(void)
531 HMENU hMenu;
532 HMENU hViewMenu;
534 hMenu = GetMenu(hMainWnd);
535 hViewMenu = GetSubMenu(hMenu, 2);
537 TaskManagerSettings.View_LargeIcons = TRUE;
538 TaskManagerSettings.View_SmallIcons = FALSE;
539 TaskManagerSettings.View_Details = FALSE;
540 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
542 UpdateApplicationListControlViewSetting();
545 void ApplicationPage_OnViewSmallIcons(void)
547 HMENU hMenu;
548 HMENU hViewMenu;
550 hMenu = GetMenu(hMainWnd);
551 hViewMenu = GetSubMenu(hMenu, 2);
553 TaskManagerSettings.View_LargeIcons = FALSE;
554 TaskManagerSettings.View_SmallIcons = TRUE;
555 TaskManagerSettings.View_Details = FALSE;
556 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
558 UpdateApplicationListControlViewSetting();
561 void ApplicationPage_OnViewDetails(void)
563 HMENU hMenu;
564 HMENU hViewMenu;
566 hMenu = GetMenu(hMainWnd);
567 hViewMenu = GetSubMenu(hMenu, 2);
569 TaskManagerSettings.View_LargeIcons = FALSE;
570 TaskManagerSettings.View_SmallIcons = FALSE;
571 TaskManagerSettings.View_Details = TRUE;
572 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
574 UpdateApplicationListControlViewSetting();
577 void ApplicationPage_OnWindowsTileHorizontally(void)
579 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
580 LV_ITEMW item;
581 int i;
582 HWND* hWndArray;
583 int nWndCount;
585 hWndArray = HeapAlloc(GetProcessHeap(), 0,
586 sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl));
587 nWndCount = 0;
589 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
590 memset(&item, 0, sizeof(LV_ITEMW));
591 item.mask = LVIF_STATE|LVIF_PARAM;
592 item.iItem = i;
593 item.stateMask = (UINT)-1;
594 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
596 if (item.state & LVIS_SELECTED) {
597 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
599 if (pAPLI) {
600 hWndArray[nWndCount] = pAPLI->hWnd;
601 nWndCount++;
605 TileWindows(NULL, MDITILE_HORIZONTAL, NULL, nWndCount, hWndArray);
606 HeapFree(GetProcessHeap(), 0, hWndArray);
609 void ApplicationPage_OnWindowsTileVertically(void)
611 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
612 LV_ITEMW item;
613 int i;
614 HWND* hWndArray;
615 int nWndCount;
617 hWndArray = HeapAlloc(GetProcessHeap(), 0,
618 sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl));
619 nWndCount = 0;
621 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
622 memset(&item, 0, sizeof(LV_ITEMW));
623 item.mask = LVIF_STATE|LVIF_PARAM;
624 item.iItem = i;
625 item.stateMask = (UINT)-1;
626 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
628 if (item.state & LVIS_SELECTED) {
629 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
630 if (pAPLI) {
631 hWndArray[nWndCount] = pAPLI->hWnd;
632 nWndCount++;
637 TileWindows(NULL, MDITILE_VERTICAL, NULL, nWndCount, hWndArray);
638 HeapFree(GetProcessHeap(), 0, hWndArray);
641 void ApplicationPage_OnWindowsMinimize(void)
643 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
644 LV_ITEMW item;
645 int i;
647 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
648 memset(&item, 0, sizeof(LV_ITEMW));
649 item.mask = LVIF_STATE|LVIF_PARAM;
650 item.iItem = i;
651 item.stateMask = (UINT)-1;
652 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
653 if (item.state & LVIS_SELECTED) {
654 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
655 if (pAPLI) {
656 ShowWindow(pAPLI->hWnd, SW_MINIMIZE);
662 void ApplicationPage_OnWindowsMaximize(void)
664 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
665 LV_ITEMW item;
666 int i;
668 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
669 memset(&item, 0, sizeof(LV_ITEMW));
670 item.mask = LVIF_STATE|LVIF_PARAM;
671 item.iItem = i;
672 item.stateMask = (UINT)-1;
673 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
674 if (item.state & LVIS_SELECTED) {
675 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
676 if (pAPLI) {
677 ShowWindow(pAPLI->hWnd, SW_MAXIMIZE);
683 void ApplicationPage_OnWindowsCascade(void)
685 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
686 LV_ITEMW item;
687 int i;
688 HWND* hWndArray;
689 int nWndCount;
691 hWndArray = HeapAlloc(GetProcessHeap(), 0,
692 sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl));
693 nWndCount = 0;
695 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
696 memset(&item, 0, sizeof(LV_ITEMW));
697 item.mask = LVIF_STATE|LVIF_PARAM;
698 item.iItem = i;
699 item.stateMask = (UINT)-1;
700 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
701 if (item.state & LVIS_SELECTED) {
702 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
703 if (pAPLI) {
704 hWndArray[nWndCount] = pAPLI->hWnd;
705 nWndCount++;
709 CascadeWindows(NULL, 0, NULL, nWndCount, hWndArray);
710 HeapFree(GetProcessHeap(), 0, hWndArray);
713 void ApplicationPage_OnWindowsBringToFront(void)
715 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
716 LV_ITEMW item;
717 int i;
719 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
720 memset(&item, 0, sizeof(LV_ITEMW));
721 item.mask = LVIF_STATE|LVIF_PARAM;
722 item.iItem = i;
723 item.stateMask = (UINT)-1;
724 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
725 if (item.state & LVIS_SELECTED) {
726 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
727 break;
730 if (pAPLI) {
731 if (IsIconic(pAPLI->hWnd))
732 ShowWindow(pAPLI->hWnd, SW_RESTORE);
733 BringWindowToTop(pAPLI->hWnd);
737 void ApplicationPage_OnSwitchTo(void)
739 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
740 LV_ITEMW item;
741 int i;
743 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
744 memset(&item, 0, sizeof(LV_ITEMW));
745 item.mask = LVIF_STATE|LVIF_PARAM;
746 item.iItem = i;
747 item.stateMask = (UINT)-1;
748 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
750 if (item.state & LVIS_SELECTED) {
751 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
752 break;
755 if (pAPLI) {
756 typedef void (WINAPI *PROCSWITCHTOTHISWINDOW) (HWND, BOOL);
757 PROCSWITCHTOTHISWINDOW SwitchToThisWindow;
759 HMODULE hUser32 = GetModuleHandleW(wszUser32);
760 SwitchToThisWindow = (PROCSWITCHTOTHISWINDOW)GetProcAddress(hUser32, "SwitchToThisWindow");
761 if (SwitchToThisWindow) {
762 SwitchToThisWindow(pAPLI->hWnd, TRUE);
763 } else {
764 if (IsIconic(pAPLI->hWnd))
765 ShowWindow(pAPLI->hWnd, SW_RESTORE);
766 BringWindowToTop(pAPLI->hWnd);
767 SetForegroundWindow(pAPLI->hWnd);
769 if (TaskManagerSettings.MinimizeOnUse)
770 ShowWindow(hMainWnd, SW_MINIMIZE);
774 void ApplicationPage_OnEndTask(void)
776 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
777 LV_ITEMW item;
778 int i;
780 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
781 memset(&item, 0, sizeof(LV_ITEMW));
782 item.mask = LVIF_STATE|LVIF_PARAM;
783 item.iItem = i;
784 item.stateMask = (UINT)-1;
785 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
786 if (item.state & LVIS_SELECTED) {
787 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
788 if (pAPLI) {
789 PostMessage(pAPLI->hWnd, WM_CLOSE, 0, 0);
795 void ApplicationPage_OnGotoProcess(void)
797 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
798 LV_ITEMW item;
799 int i;
800 /* NMHDR nmhdr; */
802 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
803 memset(&item, 0, sizeof(LV_ITEMW));
804 item.mask = LVIF_STATE|LVIF_PARAM;
805 item.iItem = i;
806 item.stateMask = (UINT)-1;
807 SendMessageW(hApplicationPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &item);
808 if (item.state & LVIS_SELECTED) {
809 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
810 break;
813 if (pAPLI) {
814 DWORD dwProcessId;
816 GetWindowThreadProcessId(pAPLI->hWnd, &dwProcessId);
818 * Switch to the process tab
820 TabCtrl_SetCurFocus(hTabWnd, 1);
822 * FIXME: Select the process item in the list
824 for (i=0; i<ListView_GetItemCount(hProcessPage); i++) {
829 INT_PTR CALLBACK
830 ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
832 RECT rc;
833 int nXDifference;
834 int nYDifference;
835 int cx, cy;
836 LVCOLUMNW column;
838 WCHAR wszTask[255];
839 WCHAR wszStatus[255];
841 LoadStringW(hInst, IDS_APPLICATION_TASK, wszTask, sizeof(wszTask)/sizeof(WCHAR));
842 LoadStringW(hInst, IDS_APPLICATION_STATUS, wszStatus, sizeof(wszStatus)/sizeof(WCHAR));
844 switch (message) {
845 case WM_INITDIALOG:
847 /* Save the width and height */
848 GetClientRect(hDlg, &rc);
849 nApplicationPageWidth = rc.right;
850 nApplicationPageHeight = rc.bottom;
852 /* Update window position */
853 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
855 /* Get handles to the controls */
856 hApplicationPageListCtrl = GetDlgItem(hDlg, IDC_APPLIST);
857 hApplicationPageEndTaskButton = GetDlgItem(hDlg, IDC_ENDTASK);
858 hApplicationPageSwitchToButton = GetDlgItem(hDlg, IDC_SWITCHTO);
859 hApplicationPageNewTaskButton = GetDlgItem(hDlg, IDC_NEWTASK);
861 /* Initialize the application page's controls */
862 column.mask = LVCF_TEXT|LVCF_WIDTH;
863 column.pszText = wszTask;
864 column.cx = 250;
865 /* Add the "Task" column */
866 SendMessageW(hApplicationPageListCtrl, LVM_INSERTCOLUMNW, 0, (LPARAM) &column);
867 column.mask = LVCF_TEXT|LVCF_WIDTH;
868 column.pszText = wszStatus;
869 column.cx = 95;
870 /* Add the "Status" column */
871 SendMessageW(hApplicationPageListCtrl, LVM_INSERTCOLUMNW, 1, (LPARAM) &column);
873 SendMessageW(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_SMALL,
874 (LPARAM) ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 0, 1));
875 SendMessageW(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_NORMAL,
876 (LPARAM) ImageList_Create(32, 32, ILC_COLOR8|ILC_MASK, 0, 1));
878 UpdateApplicationListControlViewSetting();
880 /* Start our refresh thread */
881 CreateThread(NULL, 0, ApplicationPageRefreshThread, NULL, 0, NULL);
883 return TRUE;
885 case WM_DESTROY:
886 /* Close the event handle, this will make the */
887 /* refresh thread exit when the wait fails */
888 CloseHandle(hApplicationPageEvent);
889 break;
891 case WM_COMMAND:
893 /* Handle the button clicks */
894 switch (LOWORD(wParam))
896 case IDC_ENDTASK:
897 ApplicationPage_OnEndTask();
898 break;
899 case IDC_SWITCHTO:
900 ApplicationPage_OnSwitchTo();
901 break;
902 case IDC_NEWTASK:
903 SendMessageW(hMainWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW, 0), 0);
904 break;
907 break;
909 case WM_SIZE:
910 if (wParam == SIZE_MINIMIZED)
911 return 0;
913 cx = LOWORD(lParam);
914 cy = HIWORD(lParam);
915 nXDifference = cx - nApplicationPageWidth;
916 nYDifference = cy - nApplicationPageHeight;
917 nApplicationPageWidth = cx;
918 nApplicationPageHeight = cy;
920 /* Reposition the application page's controls */
921 GetWindowRect(hApplicationPageListCtrl, &rc);
922 cx = (rc.right - rc.left) + nXDifference;
923 cy = (rc.bottom - rc.top) + nYDifference;
924 SetWindowPos(hApplicationPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
925 InvalidateRect(hApplicationPageListCtrl, NULL, TRUE);
927 GetClientRect(hApplicationPageEndTaskButton, &rc);
928 MapWindowPoints(hApplicationPageEndTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
929 cx = rc.left + nXDifference;
930 cy = rc.top + nYDifference;
931 SetWindowPos(hApplicationPageEndTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
932 InvalidateRect(hApplicationPageEndTaskButton, NULL, TRUE);
934 GetClientRect(hApplicationPageSwitchToButton, &rc);
935 MapWindowPoints(hApplicationPageSwitchToButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
936 cx = rc.left + nXDifference;
937 cy = rc.top + nYDifference;
938 SetWindowPos(hApplicationPageSwitchToButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
939 InvalidateRect(hApplicationPageSwitchToButton, NULL, TRUE);
941 GetClientRect(hApplicationPageNewTaskButton, &rc);
942 MapWindowPoints(hApplicationPageNewTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
943 cx = rc.left + nXDifference;
944 cy = rc.top + nYDifference;
945 SetWindowPos(hApplicationPageNewTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
946 InvalidateRect(hApplicationPageNewTaskButton, NULL, TRUE);
948 break;
950 case WM_NOTIFY:
951 ApplicationPageOnNotify(wParam, lParam);
952 break;
956 return 0;