From 433a98b5fae5953ebe29efe8ee672a5a4f9a8df2 Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Sat, 10 May 2008 01:45:08 +0000 Subject: [PATCH] Fix some task switch window bugs svn path=/trunk/; revision=33401 --- reactos/base/shell/explorer-new/dragdrop.c | 6 +- reactos/base/shell/explorer-new/taskswnd.c | 150 ++++++++++++--------- reactos/base/shell/explorer-new/tbsite.c | 9 +- reactos/base/shell/explorer-new/todo.h | 4 + reactos/base/shell/explorer-new/trayntfy.c | 2 +- reactos/base/shell/explorer-new/traywnd.c | 3 +- 6 files changed, 106 insertions(+), 68 deletions(-) diff --git a/reactos/base/shell/explorer-new/dragdrop.c b/reactos/base/shell/explorer-new/dragdrop.c index 67d3cc10bc8..11c498614cc 100644 --- a/reactos/base/shell/explorer-new/dragdrop.c +++ b/reactos/base/shell/explorer-new/dragdrop.c @@ -217,7 +217,7 @@ IDropTargetImpl_DragEnter(IN OUT IDropTarget *iface, hr = IDropTargetHelper_DragEnter(This->DropTargetHelper, This->hwndTarget, pDataObject, - &pt, + (POINT *)&pt, *pdwEffect); if (SUCCEEDED(hr)) @@ -274,7 +274,7 @@ IDropTargetImpl_DragOver(IN OUT IDropTarget *iface, HRESULT hr; hr = IDropTargetHelper_DragOver(This->DropTargetHelper, - &pt, + (POINT *)&pt, *pdwEffect); if (SUCCEEDED(hr)) @@ -350,7 +350,7 @@ IDropTargetImpl_Drop(IN OUT IDropTarget *iface, hr = IDropTargetHelper_Drop(This->DropTargetHelper, pDataObject, - &pt, + (POINT *)&pt, *pdwEffect); if (SUCCEEDED(hr) && This->CanDrop) diff --git a/reactos/base/shell/explorer-new/taskswnd.c b/reactos/base/shell/explorer-new/taskswnd.c index 466c9fb89ce..8bdd2c47a2d 100644 --- a/reactos/base/shell/explorer-new/taskswnd.c +++ b/reactos/base/shell/explorer-new/taskswnd.c @@ -26,7 +26,7 @@ /* Set DUMP_TASKS to 1 to enable a dump of the tasks and task groups every 5 seconds */ -#define DUMP_TASKS 0 +#define DUMP_TASKS 1 static const TCHAR szTaskSwitchWndClass[] = TEXT("MSTaskSwWClass"); static const TCHAR szRunningApps[] = TEXT("Running Applications"); @@ -136,17 +136,6 @@ typedef struct _TASK_SWITCH_WND #define MAX_TASKS_COUNT (0x7FFF) -#define MAKE_TASKITEM_PTR(ti) ((DWORD_PTR)ti) -#define MAKE_TASKGROUP_PTR(tg) (((DWORD_PTR)tg) | 1) -#define IS_TASKGROUP_PTR(p) ((((DWORD_PTR)p) & 1) != 0) -#define GET_TASKITEM_PTR(lp) ((PTASK_ITEM)(((DWORD_PTR)lp) & ~1)) -#define GET_TASKGROUP_PTR(lp) ((PTASK_GROUP)(((DWORD_PTR)lp) & ~1)) - -#define MAKE_TASKITEM_CMD_ID(id) ((INT)(id)) -#define MAKE_TASKGROUP_CMD_ID(id) ((INT)(id) | (1 << 15)) -#define IS_TASKGROUP_CMD_ID(id) ((((INT)(id)) & (1 << 15)) != 0) -#define GET_INDEX_FROM_CMD_ID(id) ((INT)(id) & MAX_TASKS_COUNT) - static VOID TaskSwitchWnd_UpdateButtonsSize(IN OUT PTASK_SWITCH_WND This, IN BOOL bRedrawDisabled); @@ -286,7 +275,7 @@ TaskSwitchWnd_UpdateIndexesAfterButtonInserted(IN OUT PTASK_SWITCH_WND This, NewIndex = CurrentGroup->Index + 1; if (TaskSwitchWnd_SetToolbarButtonCommandId(This, CurrentGroup->Index + 1, - MAKE_TASKGROUP_CMD_ID(NewIndex))) + NewIndex)) { CurrentGroup->Index = NewIndex; } @@ -319,7 +308,7 @@ UpdateTaskItemBtn: NewIndex = CurrentTaskItem->Index + 1; if (TaskSwitchWnd_SetToolbarButtonCommandId(This, CurrentTaskItem->Index + 1, - MAKE_TASKITEM_CMD_ID(NewIndex))) + NewIndex)) { CurrentTaskItem->Index = NewIndex; } @@ -352,7 +341,7 @@ TaskSwitchWnd_UpdateIndexesAfterButtonDeleted(IN OUT PTASK_SWITCH_WND This, NewIndex = CurrentGroup->Index - 1; if (TaskSwitchWnd_SetToolbarButtonCommandId(This, CurrentGroup->Index - 1, - MAKE_TASKGROUP_CMD_ID(NewIndex))) + NewIndex)) { CurrentGroup->Index = NewIndex; } @@ -385,7 +374,7 @@ UpdateTaskItemBtn: NewIndex = CurrentTaskItem->Index - 1; if (TaskSwitchWnd_SetToolbarButtonCommandId(This, CurrentTaskItem->Index - 1, - MAKE_TASKITEM_CMD_ID(NewIndex))) + NewIndex)) { CurrentTaskItem->Index = NewIndex; } @@ -570,7 +559,7 @@ TaskSwitchWnd_AddTaskItemButton(IN OUT PTASK_SWITCH_WND This, tbBtn.iBitmap = 0; tbBtn.fsState = TBSTATE_ENABLED | TBSTATE_ELLIPSES; tbBtn.fsStyle = BTNS_CHECK | BTNS_NOPREFIX | BTNS_SHOWTEXT; - tbBtn.dwData = MAKE_TASKITEM_PTR(TaskItem); + tbBtn.dwData = TaskItem->Index; tbBtn.iString = (DWORD_PTR)TaskSwitchWnd_GetWndTextFromTaskItem(This, TaskItem); @@ -579,7 +568,7 @@ TaskSwitchWnd_AddTaskItemButton(IN OUT PTASK_SWITCH_WND This, iIndex = TaskSwitchWnd_CalculateTaskItemNewButtonIndex(This, TaskItem); ASSERT(iIndex >= 0); - tbBtn.idCommand = MAKE_TASKITEM_CMD_ID(iIndex); + tbBtn.idCommand = iIndex; TaskSwitchWnd_BeginUpdate(This); @@ -719,6 +708,7 @@ TaskSwitchWnd_RemoveTaskFromTaskGroup(IN OUT PTASK_SWITCH_WND This, } /* Remove the group from the list */ + ASSERT(TaskGroup == CurrentGroup); *PrevLink = TaskGroup->Next; /* Free the task group */ @@ -819,39 +809,44 @@ TaskSwitchWnd_AllocTaskItem(IN OUT PTASK_SWITCH_WND This) return NULL; } - if (This->AllocatedTaskItems <= This->TaskItemCount) + ASSERT(This->AllocatedTaskItems >= This->TaskItemCount); + + if (This->TaskItemCount != 0) { - if (This->TaskItemCount != 0) + PTASK_ITEM NewArray; + SIZE_T NewArrayLength, ActiveTaskItemIndex; + + NewArrayLength = This->AllocatedTaskItems + TASK_ITEM_ARRAY_ALLOC; + + NewArray = HeapReAlloc(hProcessHeap, + 0, + This->TaskItems, + NewArrayLength * sizeof(*This->TaskItems)); + if (NewArray != NULL) { - PTASK_ITEM NewArray; - WORD NewArrayLength; - - NewArrayLength = This->AllocatedTaskItems + TASK_ITEM_ARRAY_ALLOC; - - NewArray = HeapReAlloc(hProcessHeap, - 0, - This->TaskItems, - NewArrayLength * sizeof(*This->TaskItems)); - if (NewArray != NULL) + if (This->ActiveTaskItem != NULL) { - This->AllocatedTaskItems = NewArrayLength; - This->TaskItems = NewArray; + /* Fixup the ActiveTaskItem pointer */ + ActiveTaskItemIndex = This->ActiveTaskItem - This->TaskItems; + This->ActiveTaskItem = NewArray + ActiveTaskItemIndex; } - else - return NULL; + This->AllocatedTaskItems = (WORD)NewArrayLength; + This->TaskItems = NewArray; } else + return NULL; + } + else + { + This->TaskItems = HeapAlloc(hProcessHeap, + 0, + TASK_ITEM_ARRAY_ALLOC * sizeof(*This->TaskItems)); + if (This->TaskItems != NULL) { - This->TaskItems = HeapAlloc(hProcessHeap, - 0, - TASK_ITEM_ARRAY_ALLOC * sizeof(*This->TaskItems)); - if (This->TaskItems != NULL) - { - This->AllocatedTaskItems = TASK_ITEM_ARRAY_ALLOC; - } - else - return NULL; + This->AllocatedTaskItems = TASK_ITEM_ARRAY_ALLOC; } + else + return NULL; } return This->TaskItems + This->TaskItemCount++; @@ -964,6 +959,43 @@ ChangeActiveTaskItemButton: } } +static PTASK_ITEM +FindTaskItemByIndex(IN OUT PTASK_SWITCH_WND This, + IN INT Index) +{ + PTASK_ITEM TaskItem, LastItem; + + TaskItem = This->TaskItems; + LastItem = TaskItem + This->TaskItemCount; + while (TaskItem != LastItem) + { + if (TaskItem->Index == Index) + return TaskItem; + + TaskItem++; + } + + return NULL; +} + +static PTASK_GROUP +FindTaskGroupByIndex(IN OUT PTASK_SWITCH_WND This, + IN INT Index) +{ + PTASK_GROUP CurrentGroup; + + CurrentGroup = This->TaskGroups; + while (CurrentGroup != NULL) + { + if (CurrentGroup->Index == Index) + break; + + CurrentGroup = CurrentGroup->Next; + } + + return CurrentGroup; +} + static BOOL TaskSwitchWnd_AddTask(IN OUT PTASK_SWITCH_WND This, IN HWND hWnd) @@ -1211,9 +1243,9 @@ TaskSwitchWnd_UpdateButtonsSize(IN OUT PTASK_SWITCH_WND This, uiMin = GetSystemMetrics(SM_CXSIZE) + (2 * GetSystemMetrics(SM_CXEDGE)); - if (NewBtnSize < uiMin) + if (NewBtnSize < (LONG)uiMin) NewBtnSize = uiMin; - if (NewBtnSize > uiMax) + if (NewBtnSize > (LONG)uiMax) NewBtnSize = uiMax; This->ButtonSize.cx = NewBtnSize; @@ -1392,7 +1424,7 @@ TaskSwitchWnd_Create(IN OUT PTASK_SWITCH_WND This) /* Register the shell hook */ This->ShellHookMsg = RegisterWindowMessage(TEXT("SHELLHOOK")); - hShell32 = LoadLibrary(TEXT("SHELL32.DLL")); + hShell32 = GetModuleHandle(TEXT("SHELL32.DLL")); if (hShell32 != NULL) { REGSHELLHOOK RegShellHook; @@ -1405,8 +1437,6 @@ TaskSwitchWnd_Create(IN OUT PTASK_SWITCH_WND This) RegShellHook(This->hWnd, 3); /* 1 if no NT! We're targeting NT so we don't care! */ } - - FreeLibrary(hShell32); } /* Add all windows to the toolbar */ @@ -1434,7 +1464,7 @@ TaskSwitchWnd_NCDestroy(IN OUT PTASK_SWITCH_WND This) This->IsDestroying = TRUE; /* Unregister the shell hook */ - hShell32 = LoadLibrary(TEXT("SHELL32.DLL")); + hShell32 = GetModuleHandle(TEXT("SHELL32.DLL")); if (hShell32 != NULL) { REGSHELLHOOK RegShellHook; @@ -1447,8 +1477,6 @@ TaskSwitchWnd_NCDestroy(IN OUT PTASK_SWITCH_WND This) RegShellHook(This->hWnd, FALSE); } - - FreeLibrary(hShell32); } TaskSwitchWnd_DeleteAllTasks(This); @@ -1604,16 +1632,21 @@ TaskSwichWnd_HandleItemPaint(IN OUT PTASK_SWITCH_WND This, HFONT hCaptionFont, hBoldCaptionFont; LRESULT Ret = CDRF_DODEFAULT; HMODULE hUser32; + PTASK_GROUP TaskGroup; + PTASK_ITEM TaskItem; #if TASK_USE_DRAWCAPTIONTEMP != 0 UINT uidctFlags = DC_TEXT | DC_ICON | DC_NOSENDMSG; #endif - - if (!IS_TASKGROUP_PTR(nmtbcd->nmcd.lItemlParam)) + TaskItem = FindTaskItemByIndex(This, + (INT)nmtbcd->nmcd.dwItemSpec); + TaskGroup = FindTaskGroupByIndex(This, + (INT)nmtbcd->nmcd.dwItemSpec); + if (TaskGroup == NULL && TaskItem != NULL) { - PTASK_ITEM TaskItem = GET_TASKITEM_PTR(nmtbcd->nmcd.lItemlParam); + ASSERT(TaskItem != NULL); if (TaskItem != NULL && IsWindow(TaskItem->hWnd)) { @@ -1717,14 +1750,9 @@ TaskSwichWnd_HandleItemPaint(IN OUT PTASK_SWITCH_WND This, } } - else + else if (TaskGroup != NULL) { - PTASK_GROUP TaskGroup = GET_TASKGROUP_PTR(nmtbcd->nmcd.lItemlParam); - - if (TaskGroup != NULL) - { - /* FIXME: Implement painting for task groups */ - } + /* FIXME: Implement painting for task groups */ } return Ret; diff --git a/reactos/base/shell/explorer-new/tbsite.c b/reactos/base/shell/explorer-new/tbsite.c index ab96ddac2c2..fd8834401d2 100644 --- a/reactos/base/shell/explorer-new/tbsite.c +++ b/reactos/base/shell/explorer-new/tbsite.c @@ -202,10 +202,17 @@ ITrayBandSiteImpl_OnLoad(IN OUT ITrayBandSite *iface, if (SUCCEEDED(hRet)) { /* Now let's read the CLSID from the stream and see if it's our task band */ +#if defined(IStream_Read) hRet = IStream_Read(pStm, &clsid, sizeof(clsid), &ulRead); +#else + ulRead = sizeof(clsid); + hRet = IStream_Read(pStm, + &clsid, + sizeof(clsid)); +#endif if (SUCCEEDED(hRet) && ulRead == sizeof(clsid)) { if (IsEqualGUID(&clsid, @@ -350,7 +357,7 @@ ITrayBandSiteImpl_ProcessMessage(IN OUT ITrayBandSite *iface, shell behavior! */ if (This->WindowEventHandler != NULL) { - DbgPrint("Calling IWindowEventHandler::ProcessMessage(0x%p, 0x%x, 0x%p, 0x%p, 0x%p) This->hWndRebar=0x%p\n", hWnd, uMsg, wParam, lParam, plResult, This->hWndRebar); + /*DbgPrint("Calling IWindowEventHandler::ProcessMessage(0x%p, 0x%x, 0x%p, 0x%p, 0x%p) This->hWndRebar=0x%p\n", hWnd, uMsg, wParam, lParam, plResult, This->hWndRebar);*/ hRet = IWindowEventHandler_ProcessMessage(This->WindowEventHandler, hWnd, uMsg, diff --git a/reactos/base/shell/explorer-new/todo.h b/reactos/base/shell/explorer-new/todo.h index 776a89e51ba..7c561ffa120 100644 --- a/reactos/base/shell/explorer-new/todo.h +++ b/reactos/base/shell/explorer-new/todo.h @@ -1,6 +1,10 @@ #ifndef __TODO_H #define __TODO_H +#ifdef INTERFACE +#undef INTERFACE +#endif + /* FIXME: Ugly hack!!! FIX ASAP! Move to uuid! */ static const GUID IID_HACK_IShellView2 = {0x88E39E80,0x3578,0x11CF,{0xAE,0x69,0x08,0x00,0x2B,0x2E,0x12,0x62}}; #define IID_IShellView2 IID_HACK_IShellView2 diff --git a/reactos/base/shell/explorer-new/trayntfy.c b/reactos/base/shell/explorer-new/trayntfy.c index f9391cbc317..0cfec06272d 100644 --- a/reactos/base/shell/explorer-new/trayntfy.c +++ b/reactos/base/shell/explorer-new/trayntfy.c @@ -159,7 +159,7 @@ TrayClockWnd_GetMinimumSize(IN OUT PTRAY_CLOCK_WND_DATA This, { if (Horizontal) { - if (szMax.cy + This->LineSizes[i].cy + This->LineSpacing > + if (szMax.cy + This->LineSizes[i].cy + (LONG)This->LineSpacing > pSize->cy - (2 * TRAY_CLOCK_WND_SPACING_Y)) { break; diff --git a/reactos/base/shell/explorer-new/traywnd.c b/reactos/base/shell/explorer-new/traywnd.c index 8296350e332..1692b8f13e8 100644 --- a/reactos/base/shell/explorer-new/traywnd.c +++ b/reactos/base/shell/explorer-new/traywnd.c @@ -1010,8 +1010,7 @@ ITrayWindowImpl_UpdateStartButton(IN OUT ITrayWindowImpl *This, sizeof(bmp), &bmp) != 0) { - Size.cx += max(bmp.bmWidth, - GetSystemMetrics(SM_CXMINIMIZED)); + Size.cx += bmp.bmWidth; Size.cy += max(bmp.bmHeight, GetSystemMetrics(SM_CYCAPTION)); }