Release 980822
[wine/multimedia.git] / controls / listview.c
blob1c600c5155d19dcf571b68d3e21f68ae2edc75cf
1 /*
2 * Listview control
4 * Copyright 1998 Eric Kohl
6 * NOTES
7 * This is just a dummy control. An author is needed! Any volunteers?
8 * I will only improve this control once in a while.
9 * Eric <ekohl@abo.rhein-zeitung.de>
11 * TODO:
12 * - All messages.
13 * - All notifications.
16 #include "windows.h"
17 #include "commctrl.h"
18 #include "listview.h"
19 #include "heap.h"
20 #include "win.h"
21 #include "debug.h"
24 #define LISTVIEW_GetInfoPtr(wndPtr) ((LISTVIEW_INFO *)wndPtr->wExtra[0])
27 static VOID
28 LISTVIEW_Refresh (WND *wndPtr, HDC32 hdc)
30 LISTVIEW_INFO *infoPtr = LISTVIEW_GetInfoPtr(wndPtr);
38 static LRESULT
39 LISTVIEW_SetBkColor (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
41 LISTVIEW_INFO *infoPtr = LISTVIEW_GetInfoPtr(wndPtr);
43 if (!(infoPtr)) return FALSE;
45 /* set background color */
46 infoPtr->clrBk = (COLORREF)lParam;
48 return TRUE;
52 static LRESULT
53 LISTVIEW_SetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
55 LISTVIEW_INFO *infoPtr = LISTVIEW_GetInfoPtr(wndPtr);
57 FIXME (listview, "(0x%08x 0x%08lx)\n", wParam, lParam);
59 return 0;
63 static LRESULT
64 LISTVIEW_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
66 LISTVIEW_INFO *infoPtr = LISTVIEW_GetInfoPtr(wndPtr);
68 /* initialize info structure */
69 infoPtr->clrBk = CLR_NONE;
71 return 0;
75 static LRESULT
76 LISTVIEW_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
78 LISTVIEW_INFO *infoPtr = LISTVIEW_GetInfoPtr(wndPtr);
81 return 0;
85 static LRESULT
86 LISTVIEW_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
88 LISTVIEW_INFO *infoPtr = LISTVIEW_GetInfoPtr(wndPtr);
90 if (infoPtr->clrBk == CLR_NONE) {
91 return SendMessage32A (GetParent32 (wndPtr->hwndSelf),
92 WM_ERASEBKGND, wParam, lParam);
94 else {
95 RECT32 rect;
96 HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
97 GetClientRect32 (wndPtr->hwndSelf, &rect);
98 FillRect32 ((HDC32)wParam, &rect, hBrush);
99 DeleteObject32 (hBrush);
100 return FALSE;
102 return FALSE;
106 static LRESULT
107 LISTVIEW_NCCreate (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
109 LISTVIEW_INFO *infoPtr;
111 /* allocate memory for info structure */
112 infoPtr = (LISTVIEW_INFO *)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
113 sizeof(LISTVIEW_INFO));
114 wndPtr->wExtra[0] = (DWORD)infoPtr;
116 if (infoPtr == NULL) {
117 ERR (listview, "could not allocate info memory!\n");
118 return 0;
121 if ((LISTVIEW_INFO*)wndPtr->wExtra[0] != infoPtr) {
122 ERR (listview, "pointer assignment error!\n");
123 return 0;
126 return DefWindowProc32A (wndPtr->hwndSelf, WM_NCCREATE, wParam, lParam);
130 static LRESULT
131 LISTVIEW_NCDestroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
133 LISTVIEW_INFO *infoPtr = LISTVIEW_GetInfoPtr(wndPtr);
138 /* free list view info data */
139 HeapFree (GetProcessHeap (), 0, infoPtr);
141 return 0;
145 static LRESULT
146 LISTVIEW_Paint (WND *wndPtr, WPARAM32 wParam)
148 HDC32 hdc;
149 PAINTSTRUCT32 ps;
151 hdc = wParam==0 ? BeginPaint32 (wndPtr->hwndSelf, &ps) : (HDC32)wParam;
152 LISTVIEW_Refresh (wndPtr, hdc);
153 if (!wParam)
154 EndPaint32 (wndPtr->hwndSelf, &ps);
155 return 0;
159 LRESULT WINAPI
160 ListviewWindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
162 WND *wndPtr = WIN_FindWndPtr(hwnd);
164 switch (uMsg)
167 case LVM_SETBKCOLOR:
168 return LISTVIEW_SetBkColor (wndPtr, wParam, lParam);
171 case LVM_SETIMAGELIST:
172 return LISTVIEW_SetImageList (wndPtr, wParam, lParam);
177 // case WM_CHAR:
178 // case WM_COMMAND:
180 case WM_CREATE:
181 return LISTVIEW_Create (wndPtr, wParam, lParam);
183 case WM_DESTROY:
184 return LISTVIEW_Destroy (wndPtr, wParam, lParam);
186 case WM_ERASEBKGND:
187 return LISTVIEW_EraseBackground (wndPtr, wParam, lParam);
189 // case WM_GETDLGCODE:
190 // case WM_GETFONT:
191 // case WM_HSCROLL:
193 // case WM_MOUSEMOVE:
194 // return LISTVIEW_MouseMove (wndPtr, wParam, lParam);
196 case WM_NCCREATE:
197 return LISTVIEW_NCCreate (wndPtr, wParam, lParam);
199 case WM_NCDESTROY:
200 return LISTVIEW_NCDestroy (wndPtr, wParam, lParam);
202 // case WM_NOTIFY:
204 case WM_PAINT:
205 return LISTVIEW_Paint (wndPtr, wParam);
207 // case WM_RBUTTONDOWN:
208 // case WM_SETFOCUS:
209 // case WM_SETFONT:
210 // case WM_SETREDRAW:
211 // case WM_TIMER:
212 // case WM_VSCROLL:
213 // case WM_WINDOWPOSCHANGED:
214 // case WM_WININICHANGE:
216 default:
217 if (uMsg >= WM_USER)
218 ERR (listview, "unknown msg %04x wp=%08x lp=%08lx\n",
219 uMsg, wParam, lParam);
220 return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
222 return 0;
226 void
227 LISTVIEW_Register (void)
229 WNDCLASS32A wndClass;
231 if (GlobalFindAtom32A (WC_LISTVIEW32A)) return;
233 ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
234 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
235 wndClass.lpfnWndProc = (WNDPROC32)ListviewWindowProc;
236 wndClass.cbClsExtra = 0;
237 wndClass.cbWndExtra = sizeof(LISTVIEW_INFO *);
238 wndClass.hCursor = LoadCursor32A (0, IDC_ARROW32A);
239 wndClass.hbrBackground = (HBRUSH32)(COLOR_WINDOW + 1);
240 wndClass.lpszClassName = WC_LISTVIEW32A;
242 RegisterClass32A (&wndClass);