- Fix handling of %2, %3, ... and lower case format characters in
[wine/multimedia.git] / programs / regedit / childwnd.c
blobd79e8afda9f10cce46024da5bc150ec75a0d3bd0
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 ChildWnd* g_pChildWnd;
31 /*******************************************************************************
32 * Local module support methods
35 static LPCTSTR get_root_key_name(HKEY hRootKey)
37 if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT");
38 if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER");
39 if (hRootKey == HKEY_LOCAL_MACHINE) return _T("HKEY_LOCAL_MACHINE");
40 if (hRootKey == HKEY_USERS) return _T("HKEY_USERS");
41 if (hRootKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
42 return _T("UKNOWN HKEY, PLEASE REPORT");
45 static void draw_splitbar(HWND hWnd, int x)
47 RECT rt;
48 HDC hdc = GetDC(hWnd);
50 GetClientRect(hWnd, &rt);
51 rt.left = x - SPLIT_WIDTH/2;
52 rt.right = x + SPLIT_WIDTH/2+1;
53 InvertRect(hdc, &rt);
54 ReleaseDC(hWnd, hdc);
57 static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
59 HDWP hdwp = BeginDeferWindowPos(2);
60 RECT rt = {0, 0, cx, cy};
62 cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
63 DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
64 DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
65 EndDeferWindowPos(hdwp);
68 static void OnPaint(HWND hWnd)
70 PAINTSTRUCT ps;
71 RECT rt;
72 HDC hdc;
74 GetClientRect(hWnd, &rt);
75 hdc = BeginPaint(hWnd, &ps);
76 FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
77 EndPaint(hWnd, &ps);
80 /*******************************************************************************
82 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
84 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
88 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
90 switch (LOWORD(wParam)) {
91 /* Parse the menu selections: */
92 case ID_REGISTRY_EXIT:
93 DestroyWindow(hWnd);
94 break;
95 case ID_VIEW_REFRESH:
96 /* TODO */
97 break;
98 default:
99 return FALSE;
101 return TRUE;
104 /*******************************************************************************
106 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
108 * PURPOSE: Processes messages for the child windows.
110 * WM_COMMAND - process the application menu
111 * WM_PAINT - Paint the main window
112 * WM_DESTROY - post a quit message and return
115 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
117 static int last_split;
118 ChildWnd* pChildWnd = g_pChildWnd;
120 switch (message) {
121 case WM_CREATE:
122 g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
123 if (!pChildWnd) return 0;
124 _tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
125 pChildWnd->nSplitPos = 250;
126 pChildWnd->hWnd = hWnd;
127 pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
128 pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
129 SetFocus(pChildWnd->hTreeWnd);
130 break;
131 case WM_COMMAND:
132 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
133 goto def;
135 break;
136 case WM_PAINT:
137 OnPaint(hWnd);
138 return 0;
139 case WM_SETCURSOR:
140 if (LOWORD(lParam) == HTCLIENT) {
141 POINT pt;
142 GetCursorPos(&pt);
143 ScreenToClient(hWnd, &pt);
144 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
145 SetCursor(LoadCursor(0, IDC_SIZEWE));
146 return TRUE;
149 goto def;
150 case WM_DESTROY:
151 HeapFree(GetProcessHeap(), 0, pChildWnd);
152 pChildWnd = NULL;
153 PostQuitMessage(0);
154 break;
155 case WM_LBUTTONDOWN: {
156 RECT rt;
157 int x = LOWORD(lParam);
158 GetClientRect(hWnd, &rt);
159 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
160 last_split = pChildWnd->nSplitPos;
161 draw_splitbar(hWnd, last_split);
162 SetCapture(hWnd);
164 break;
167 case WM_LBUTTONUP:
168 if (GetCapture() == hWnd) {
169 RECT rt;
170 int x = LOWORD(lParam);
171 draw_splitbar(hWnd, last_split);
172 last_split = -1;
173 GetClientRect(hWnd, &rt);
174 pChildWnd->nSplitPos = x;
175 ResizeWnd(pChildWnd, rt.right, rt.bottom);
176 ReleaseCapture();
178 break;
180 case WM_CAPTURECHANGED:
181 if (GetCapture()==hWnd && last_split>=0)
182 draw_splitbar(hWnd, last_split);
183 break;
185 case WM_KEYDOWN:
186 if (wParam == VK_ESCAPE)
187 if (GetCapture() == hWnd) {
188 RECT rt;
189 draw_splitbar(hWnd, last_split);
190 GetClientRect(hWnd, &rt);
191 ResizeWnd(pChildWnd, rt.right, rt.bottom);
192 last_split = -1;
193 ReleaseCapture();
194 SetCursor(LoadCursor(0, IDC_ARROW));
196 break;
198 case WM_MOUSEMOVE:
199 if (GetCapture() == hWnd) {
200 RECT rt;
201 int x = LOWORD(lParam);
202 HDC hdc = GetDC(hWnd);
203 GetClientRect(hWnd, &rt);
204 rt.left = last_split-SPLIT_WIDTH/2;
205 rt.right = last_split+SPLIT_WIDTH/2+1;
206 InvertRect(hdc, &rt);
207 last_split = x;
208 rt.left = x-SPLIT_WIDTH/2;
209 rt.right = x+SPLIT_WIDTH/2+1;
210 InvertRect(hdc, &rt);
211 ReleaseDC(hWnd, hdc);
213 break;
215 case WM_SETFOCUS:
216 if (pChildWnd != NULL) {
217 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
219 break;
221 case WM_TIMER:
222 break;
224 case WM_NOTIFY:
225 if ((int)wParam == TREE_WINDOW) {
226 switch (((LPNMHDR)lParam)->code) {
227 case TVN_ITEMEXPANDING:
228 return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
229 case TVN_SELCHANGED: {
230 LPCTSTR keyPath, rootName;
231 LPTSTR fullPath;
232 HKEY hRootKey;
234 keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
235 if (keyPath) {
236 RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath);
237 rootName = get_root_key_name(hRootKey);
238 fullPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(rootName) + 1 + lstrlen(keyPath) + 1) * sizeof(TCHAR));
239 if (fullPath) {
240 _stprintf(fullPath, "%s\\%s", rootName, keyPath);
241 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
242 HeapFree(GetProcessHeap(), 0, fullPath);
246 break;
247 case NM_SETFOCUS:
248 pChildWnd->nFocusPanel = 1;
249 break;
250 case TVN_ENDLABELEDIT: {
251 HKEY hRootKey;
252 LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
253 LPCTSTR path = GetItemPath(pChildWnd->hTreeWnd, 0, &hRootKey);
254 BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
255 if (res) {
256 TVITEMEX item;
257 item.mask = TVIF_HANDLE | TVIF_TEXT;
258 item.hItem = TreeView_GetSelection(pChildWnd->hTreeWnd);
259 item.pszText = dispInfo->item.pszText;
260 TreeView_SetItem(pChildWnd->hTreeWnd, &item);
262 return res;
264 default:
265 goto def;
267 } else
268 if ((int)wParam == LIST_WINDOW) {
269 if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
270 pChildWnd->nFocusPanel = 0;
271 } else if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
272 goto def;
275 break;
277 case WM_SIZE:
278 if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
279 ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
281 /* fall through */
282 default: def:
283 return DefWindowProc(hWnd, message, wParam, lParam);
285 return 0;