Stub implementations for GetAltTabInfo{A,W}.
[wine/multimedia.git] / programs / regedit / childwnd.c
blobeda6a59bc5c1c02879a073212362b4c9ced45ba0
1 /*
2 * Regedit child window
4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <tchar.h>
25 #include <stdio.h>
27 #include "main.h"
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(regedit);
34 ChildWnd* g_pChildWnd;
36 /*******************************************************************************
37 * Local module support methods
40 static LPCTSTR get_root_key_name(HKEY hRootKey)
42 if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT");
43 if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER");
44 if (hRootKey == HKEY_LOCAL_MACHINE) return _T("HKEY_LOCAL_MACHINE");
45 if (hRootKey == HKEY_USERS) return _T("HKEY_USERS");
46 if (hRootKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
47 if (hRootKey == HKEY_DYN_DATA) return _T("HKEY_DYN_DATA");
48 return _T("UKNOWN HKEY, PLEASE REPORT");
51 static void draw_splitbar(HWND hWnd, int x)
53 RECT rt;
54 HDC hdc = GetDC(hWnd);
56 GetClientRect(hWnd, &rt);
57 rt.left = x - SPLIT_WIDTH/2;
58 rt.right = x + SPLIT_WIDTH/2+1;
59 InvertRect(hdc, &rt);
60 ReleaseDC(hWnd, hdc);
63 static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
65 HDWP hdwp = BeginDeferWindowPos(2);
66 RECT rt = {0, 0, cx, cy};
68 cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
69 DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
70 DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
71 EndDeferWindowPos(hdwp);
74 static void OnPaint(HWND hWnd)
76 PAINTSTRUCT ps;
77 RECT rt;
78 HDC hdc;
80 GetClientRect(hWnd, &rt);
81 hdc = BeginPaint(hWnd, &ps);
82 FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
83 EndPaint(hWnd, &ps);
86 /*******************************************************************************
88 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
90 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
94 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
96 ChildWnd* pChildWnd = g_pChildWnd;
97 switch (LOWORD(wParam)) {
98 /* Parse the menu selections: */
99 case ID_REGISTRY_EXIT:
100 DestroyWindow(hWnd);
101 break;
102 case ID_VIEW_REFRESH:
103 /* TODO */
104 break;
105 case ID_SWITCH_PANELS:
106 pChildWnd->nFocusPanel = !pChildWnd->nFocusPanel;
107 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
108 break;
109 default:
110 return FALSE;
112 return TRUE;
115 /*******************************************************************************
117 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
119 * PURPOSE: Processes messages for the child windows.
121 * WM_COMMAND - process the application menu
122 * WM_PAINT - Paint the main window
123 * WM_DESTROY - post a quit message and return
126 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
128 static int last_split;
129 ChildWnd* pChildWnd = g_pChildWnd;
131 switch (message) {
132 case WM_CREATE:
133 g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
134 if (!pChildWnd) return 0;
135 _tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
136 pChildWnd->nSplitPos = 250;
137 pChildWnd->hWnd = hWnd;
138 pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
139 pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
140 SetFocus(pChildWnd->hTreeWnd);
141 break;
142 case WM_COMMAND:
143 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
144 goto def;
146 break;
147 case WM_PAINT:
148 OnPaint(hWnd);
149 return 0;
150 case WM_SETCURSOR:
151 if (LOWORD(lParam) == HTCLIENT) {
152 POINT pt;
153 GetCursorPos(&pt);
154 ScreenToClient(hWnd, &pt);
155 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
156 SetCursor(LoadCursor(0, IDC_SIZEWE));
157 return TRUE;
160 goto def;
161 case WM_DESTROY:
162 HeapFree(GetProcessHeap(), 0, pChildWnd);
163 pChildWnd = NULL;
164 PostQuitMessage(0);
165 break;
166 case WM_LBUTTONDOWN: {
167 RECT rt;
168 int x = LOWORD(lParam);
169 GetClientRect(hWnd, &rt);
170 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
171 last_split = pChildWnd->nSplitPos;
172 draw_splitbar(hWnd, last_split);
173 SetCapture(hWnd);
175 break;
178 case WM_LBUTTONUP:
179 if (GetCapture() == hWnd) {
180 RECT rt;
181 int x = LOWORD(lParam);
182 draw_splitbar(hWnd, last_split);
183 last_split = -1;
184 GetClientRect(hWnd, &rt);
185 pChildWnd->nSplitPos = x;
186 ResizeWnd(pChildWnd, rt.right, rt.bottom);
187 ReleaseCapture();
189 break;
191 case WM_CAPTURECHANGED:
192 if (GetCapture()==hWnd && last_split>=0)
193 draw_splitbar(hWnd, last_split);
194 break;
196 case WM_KEYDOWN:
197 if (wParam == VK_ESCAPE)
198 if (GetCapture() == hWnd) {
199 RECT rt;
200 draw_splitbar(hWnd, last_split);
201 GetClientRect(hWnd, &rt);
202 ResizeWnd(pChildWnd, rt.right, rt.bottom);
203 last_split = -1;
204 ReleaseCapture();
205 SetCursor(LoadCursor(0, IDC_ARROW));
207 break;
209 case WM_MOUSEMOVE:
210 if (GetCapture() == hWnd) {
211 RECT rt;
212 int x = LOWORD(lParam);
213 HDC hdc = GetDC(hWnd);
214 GetClientRect(hWnd, &rt);
215 rt.left = last_split-SPLIT_WIDTH/2;
216 rt.right = last_split+SPLIT_WIDTH/2+1;
217 InvertRect(hdc, &rt);
218 last_split = x;
219 rt.left = x-SPLIT_WIDTH/2;
220 rt.right = x+SPLIT_WIDTH/2+1;
221 InvertRect(hdc, &rt);
222 ReleaseDC(hWnd, hdc);
224 break;
226 case WM_SETFOCUS:
227 if (pChildWnd != NULL) {
228 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
230 break;
232 case WM_TIMER:
233 break;
235 case WM_NOTIFY:
236 if ((int)wParam == TREE_WINDOW) {
237 switch (((LPNMHDR)lParam)->code) {
238 case TVN_ITEMEXPANDING:
239 return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
240 case TVN_SELCHANGED: {
241 LPCTSTR keyPath, rootName;
242 LPTSTR fullPath;
243 HKEY hRootKey;
245 keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
246 if (keyPath) {
247 RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath, NULL);
248 rootName = get_root_key_name(hRootKey);
249 fullPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(rootName) + 1 + lstrlen(keyPath) + 1) * sizeof(TCHAR));
250 if (fullPath) {
251 _stprintf(fullPath, "%s\\%s", rootName, keyPath);
252 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
253 HeapFree(GetProcessHeap(), 0, fullPath);
257 break;
258 case NM_SETFOCUS:
259 pChildWnd->nFocusPanel = 0;
260 break;
261 case NM_RCLICK: {
262 POINT pt;
263 GetCursorPos(&pt);
264 TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW),
265 TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
266 break;
268 case TVN_ENDLABELEDIT: {
269 HKEY hRootKey;
270 LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
271 LPCTSTR path = GetItemPath(pChildWnd->hTreeWnd, 0, &hRootKey);
272 BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
273 if (res) {
274 TVITEMEX item;
275 item.mask = TVIF_HANDLE | TVIF_TEXT;
276 item.hItem = TreeView_GetSelection(pChildWnd->hTreeWnd);
277 item.pszText = dispInfo->item.pszText;
278 TreeView_SetItem(pChildWnd->hTreeWnd, &item);
280 return res;
282 default:
283 return 0; /* goto def; */
285 } else
286 if ((int)wParam == LIST_WINDOW) {
287 if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
288 pChildWnd->nFocusPanel = 1;
289 } else if (!SendMessage(pChildWnd->hListWnd, WM_NOTIFY_REFLECT, wParam, lParam)) {
290 goto def;
293 break;
295 case WM_SIZE:
296 if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
297 ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
299 /* fall through */
300 default: def:
301 return DefWindowProc(hWnd, message, wParam, lParam);
303 return 0;