wine: fix a memory error in the window list code
[sugaredwine.git] / patches / 0013-tasklist-draw-icons.patch
blob79531816448ac8a36c3399df15a1e6c125e403a7
1 From 61edf2182ab6d8c550fc468e62208f70d237da1f Mon Sep 17 00:00:00 2001
2 From: Vincent Povirk <vincent@codeweavers.com>
3 Date: Tue, 2 Sep 2008 10:23:26 -0500
4 Subject: [PATCH] tasklist: draw icons
6 ---
7 programs/explorer/tasklist.c | 58 +++++++++++++++++++++++++++++++++++++++---
8 1 files changed, 54 insertions(+), 4 deletions(-)
10 diff --git a/programs/explorer/tasklist.c b/programs/explorer/tasklist.c
11 index 6b04dde..8e316a4 100644
12 --- a/programs/explorer/tasklist.c
13 +++ b/programs/explorer/tasklist.c
14 @@ -35,6 +35,7 @@ struct toplevel_window
15 BOOL still_alive;
16 HWND button;
17 LPWSTR caption;
18 + HICON icon;
21 static struct toplevel_window *toplevels=NULL;
22 @@ -83,10 +84,35 @@ static void refresh_buttons(void)
26 -static void update_window_caption(int index)
27 +static void set_icon(int index, HICON icon)
29 + if (toplevels[index].icon)
30 + DestroyIcon(toplevels[index].icon);
32 + toplevels[index].icon = icon;
34 + /* FIXME: queue a redraw */
37 +static VOID CALLBACK update_icon_async(HWND hwnd, UINT msg, ULONG_PTR data, LRESULT result)
39 + int index = (int)data;
41 + if (index >= toplevels_len && toplevels[index].hwnd != hwnd)
42 + {
43 + index = get_toplevel(hwnd);
44 + if (index == -1)
45 + return;
46 + }
48 + set_icon(index, (HICON)result);
51 +static void update_window(int index)
53 int length;
54 LPWSTR caption;
55 + HICON icon;
57 HeapFree(GetProcessHeap(), 0, toplevels[index].caption);
59 @@ -97,6 +123,16 @@ static void update_window_caption(int index)
60 caption[0] = 0;
62 toplevels[index].caption = caption;
64 + /* FIXME: this is useless because we don't support getting class icons cross-process */
65 + icon = (HICON)GetClassLongPtrW(toplevels[index].hwnd, GCLP_HICONSM);
66 + if (!icon) icon = (HICON)GetClassLongPtrW(toplevels[index].hwnd, GCLP_HICON);
68 + if (icon)
69 + set_icon(index, icon);
70 + else /* FIXME: don't allow WM_GETICON messages to build up */
71 + SendMessageCallbackW(toplevels[index].hwnd, WM_GETICON, ICON_BIG, 0,
72 + update_icon_async, (ULONG_PTR)index);
75 /* add a window to the list and return its index */
76 @@ -120,10 +156,11 @@ static int add_hwnd(HWND hwnd)
77 toplevels[result].hwnd = hwnd;
79 toplevels[result].button = CreateWindowW(buttonW, buttonW, WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_LEFT|BS_OWNERDRAW, 0, 0, 0, 0, tasklist, (HMENU)result, NULL, NULL);
81 orig_button_proc = (WNDPROC)SetWindowLongPtrW(toplevels[result].button, GWLP_WNDPROC, (LONG_PTR)button_wndproc);
83 - update_window_caption(result);
84 + toplevels[result].icon = NULL;
86 + update_window(result);
88 refresh_buttons();
90 @@ -221,7 +258,7 @@ static BOOL CALLBACK handle_enumwindow(HWND hwnd, LPARAM lparam)
92 else
94 - update_window_caption(window);
95 + update_window(window);
98 toplevels[window].still_alive = TRUE;
99 @@ -318,17 +355,30 @@ static LRESULT WINAPI tasklist_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
100 BOOL pushed;
101 LOGFONTA lf;
102 HFONT font, oldFont;
103 + int cxsmicon, cysmicon;
105 pushed = SendMessageW(dis->hwndItem, BM_GETSTATE, 0, 0) & BST_PUSHED;
107 + /* draw button frame */
108 DrawFrameControl(dis->hDC, &dis->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH|(pushed?DFCS_PUSHED:0));
110 + /* calculate rect of face */
111 rc = dis->rcItem;
113 InflateRect(&rc, -3, -3);
114 if (pushed)
115 OffsetRect(&rc, 1, 1);
117 + /* draw icon */
118 + if (toplevels[id].icon)
120 + cxsmicon = GetSystemMetrics(SM_CXSMICON);
121 + cysmicon = GetSystemMetrics(SM_CYSMICON);
122 + DrawIconEx(dis->hDC, rc.left, rc.top, toplevels[id].icon, cxsmicon, cysmicon, 0, NULL, DI_NORMAL);
123 + rc.left += cxsmicon+2;
126 + /* draw caption */
127 ZeroMemory(&lf, sizeof(lf));
128 lf.lfHeight = -12;
129 lf.lfWeight = FW_NORMAL;
131 1.5.6.5