Release 980726
[wine/multimedia.git] / controls / treeview.c
blobf04f40e27d1d0811cf4a3c78c33812cfd49e78d9
1 /*
2 * Treeview 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 "treeview.h"
19 #include "heap.h"
20 #include "win.h"
21 #include "debug.h"
24 #define TREEVIEW_GetInfoPtr(wndPtr) ((TREEVIEW_INFO *)wndPtr->wExtra[0])
28 static LRESULT
29 TREEVIEW_SetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
31 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
32 HIMAGELIST himlTemp;
34 if ((INT32)wParam == TVSIL_NORMAL) {
35 himlTemp = infoPtr->himlNormal;
36 infoPtr->himlNormal = (HIMAGELIST)lParam;
38 else if ((INT32)wParam == TVSIL_STATE) {
39 himlTemp = infoPtr->himlState;
40 infoPtr->himlState = (HIMAGELIST)lParam;
42 else
43 return NULL;
45 return (LRESULT)himlTemp;
50 static LRESULT
51 TREEVIEW_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
53 TREEVIEW_INFO *infoPtr;
55 /* allocate memory for info structure */
56 infoPtr = (TREEVIEW_INFO *)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
57 sizeof(TREEVIEW_INFO));
58 wndPtr->wExtra[0] = (DWORD)infoPtr;
60 if (infoPtr == NULL) {
61 ERR (treeview, "could not allocate info memory!\n");
62 return 0;
65 if ((TREEVIEW_INFO*)wndPtr->wExtra[0] != infoPtr) {
66 ERR (treeview, "pointer assignment error!\n");
67 return 0;
70 /* set default settings */
71 infoPtr->clrBk = GetSysColor32 (COLOR_WINDOW);
72 infoPtr->clrText = GetSysColor32 (COLOR_BTNTEXT);
73 infoPtr->himlNormal = NULL;
74 infoPtr->himlState = NULL;
77 return 0;
81 static LRESULT
82 TREEVIEW_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
84 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
89 /* free tree view info data */
90 HeapFree (GetProcessHeap (), 0, infoPtr);
92 return 0;
96 static LRESULT
97 TREEVIEW_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
99 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
100 HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
101 RECT32 rect;
103 GetClientRect32 (wndPtr->hwndSelf, &rect);
104 FillRect32 ((HDC32)wParam, &rect, hBrush);
105 DeleteObject32 (hBrush);
106 return TRUE;
111 LRESULT WINAPI
112 TreeviewWindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
114 WND *wndPtr = WIN_FindWndPtr(hwnd);
116 switch (uMsg)
120 // case TVM_GETIMAGELIST:
121 // return TREEVIEW_GetImageList (wndPtr, wParam, lParam);
125 case TVM_SETIMAGELIST:
126 return TREEVIEW_SetImageList (wndPtr, wParam, lParam);
130 case WM_CREATE:
131 return TREEVIEW_Create (wndPtr, wParam, lParam);
133 case WM_DESTROY:
134 return TREEVIEW_Destroy (wndPtr, wParam, lParam);
136 // case EM_ENABLE:
138 case WM_ERASEBKGND:
139 return TREEVIEW_EraseBackground (wndPtr, wParam, lParam);
141 case WM_GETDLGCODE:
142 return DLGC_WANTARROWS | DLGC_WANTCHARS;
145 // case WM_PAINT:
146 // return TREEVIEW_Paint (wndPtr, wParam);
148 // case WM_SETFONT:
150 // case WM_TIMER:
152 // case WM_VSCROLL:
154 default:
155 if (uMsg >= WM_USER)
156 ERR (treeview, "unknown msg %04x wp=%08x lp=%08lx\n",
157 uMsg, wParam, lParam);
158 return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
160 return 0;
164 void
165 TREEVIEW_Register (void)
167 WNDCLASS32A wndClass;
169 if (GlobalFindAtom32A (WC_TREEVIEW32A)) return;
171 ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
172 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
173 wndClass.lpfnWndProc = (WNDPROC32)TreeviewWindowProc;
174 wndClass.cbClsExtra = 0;
175 wndClass.cbWndExtra = sizeof(TREEVIEW_INFO *);
176 wndClass.hCursor = LoadCursor32A (0, IDC_ARROW32A);
177 wndClass.hbrBackground = 0;
178 wndClass.lpszClassName = WC_TREEVIEW32A;
180 RegisterClass32A (&wndClass);