rsabase doesn't use any types now, so remove it.
[wine/dcerpc.git] / programs / regedit / childwnd.c
blob8ec6d70056b1fef7babd12b6d801ff692e6e2daf
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 void OnTreeSelectionChanged(HWND hwndTV, HWND hwndLV, HTREEITEM hItem, BOOL bRefreshLV)
88 LPCTSTR keyPath, rootName;
89 LPTSTR fullPath;
90 HKEY hRootKey;
92 keyPath = GetItemPath(hwndTV, hItem, &hRootKey);
93 if (keyPath) {
94 if (bRefreshLV)
95 RefreshListView(hwndLV, hRootKey, keyPath, NULL);
96 rootName = get_root_key_name(hRootKey);
97 fullPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(rootName) + 1 + lstrlen(keyPath) + 1) * sizeof(TCHAR));
98 if (fullPath) {
99 _stprintf(fullPath, "%s\\%s", rootName, keyPath);
100 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
101 HeapFree(GetProcessHeap(), 0, fullPath);
104 else {
105 /* else the computer icon is being selected, so display computer name */
106 TCHAR text[260];
107 DWORD size;
109 size = sizeof(text)/sizeof(TCHAR);
110 GetComputerName(text, &size);
111 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)text);
115 /*******************************************************************************
117 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
119 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
123 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
125 ChildWnd* pChildWnd = g_pChildWnd;
126 switch (LOWORD(wParam)) {
127 /* Parse the menu selections: */
128 case ID_REGISTRY_EXIT:
129 DestroyWindow(hWnd);
130 break;
131 case ID_VIEW_REFRESH:
132 WINE_TRACE("Is this ever called or is it just dead code?\n");
133 /* TODO */
134 break;
135 case ID_SWITCH_PANELS:
136 pChildWnd->nFocusPanel = !pChildWnd->nFocusPanel;
137 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
138 break;
139 default:
140 return FALSE;
142 return TRUE;
145 /*******************************************************************************
147 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
149 * PURPOSE: Processes messages for the child windows.
151 * WM_COMMAND - process the application menu
152 * WM_PAINT - Paint the main window
153 * WM_DESTROY - post a quit message and return
156 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
158 static int last_split;
159 ChildWnd* pChildWnd = g_pChildWnd;
161 switch (message) {
162 case WM_CREATE:
163 g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
164 if (!pChildWnd) return 0;
165 _tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
166 pChildWnd->nSplitPos = 250;
167 pChildWnd->hWnd = hWnd;
168 pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
169 pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
170 SetFocus(pChildWnd->hTreeWnd);
171 break;
172 case WM_COMMAND:
173 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
174 goto def;
176 break;
177 case WM_PAINT:
178 OnPaint(hWnd);
179 return 0;
180 case WM_SETCURSOR:
181 if (LOWORD(lParam) == HTCLIENT) {
182 POINT pt;
183 GetCursorPos(&pt);
184 ScreenToClient(hWnd, &pt);
185 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
186 SetCursor(LoadCursor(0, IDC_SIZEWE));
187 return TRUE;
190 goto def;
191 case WM_DESTROY:
192 HeapFree(GetProcessHeap(), 0, pChildWnd);
193 pChildWnd = NULL;
194 PostQuitMessage(0);
195 break;
196 case WM_LBUTTONDOWN: {
197 RECT rt;
198 int x = LOWORD(lParam);
199 GetClientRect(hWnd, &rt);
200 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
201 last_split = pChildWnd->nSplitPos;
202 draw_splitbar(hWnd, last_split);
203 SetCapture(hWnd);
205 break;
208 case WM_LBUTTONUP:
209 if (GetCapture() == hWnd) {
210 RECT rt;
211 int x = LOWORD(lParam);
212 draw_splitbar(hWnd, last_split);
213 last_split = -1;
214 GetClientRect(hWnd, &rt);
215 pChildWnd->nSplitPos = x;
216 ResizeWnd(pChildWnd, rt.right, rt.bottom);
217 ReleaseCapture();
219 break;
221 case WM_CAPTURECHANGED:
222 if (GetCapture()==hWnd && last_split>=0)
223 draw_splitbar(hWnd, last_split);
224 break;
226 case WM_KEYDOWN:
227 if (wParam == VK_ESCAPE)
228 if (GetCapture() == hWnd) {
229 RECT rt;
230 draw_splitbar(hWnd, last_split);
231 GetClientRect(hWnd, &rt);
232 ResizeWnd(pChildWnd, rt.right, rt.bottom);
233 last_split = -1;
234 ReleaseCapture();
235 SetCursor(LoadCursor(0, IDC_ARROW));
237 break;
239 case WM_MOUSEMOVE:
240 if (GetCapture() == hWnd) {
241 RECT rt;
242 int x = LOWORD(lParam);
243 HDC hdc = GetDC(hWnd);
244 GetClientRect(hWnd, &rt);
245 rt.left = last_split-SPLIT_WIDTH/2;
246 rt.right = last_split+SPLIT_WIDTH/2+1;
247 InvertRect(hdc, &rt);
248 last_split = x;
249 rt.left = x-SPLIT_WIDTH/2;
250 rt.right = x+SPLIT_WIDTH/2+1;
251 InvertRect(hdc, &rt);
252 ReleaseDC(hWnd, hdc);
254 break;
256 case WM_SETFOCUS:
257 if (pChildWnd != NULL) {
258 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
260 break;
262 case WM_TIMER:
263 break;
265 case WM_NOTIFY:
266 if ((int)wParam == TREE_WINDOW) {
267 switch (((LPNMHDR)lParam)->code) {
268 case TVN_ITEMEXPANDING:
269 return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
270 case TVN_SELCHANGED:
271 OnTreeSelectionChanged(pChildWnd->hTreeWnd, pChildWnd->hListWnd,
272 ((NMTREEVIEW *)lParam)->itemNew.hItem, TRUE);
273 break;
274 case NM_SETFOCUS:
275 pChildWnd->nFocusPanel = 0;
276 break;
277 case NM_RCLICK: {
278 POINT pt;
279 GetCursorPos(&pt);
280 TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW),
281 TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
282 break;
284 case TVN_ENDLABELEDIT: {
285 HKEY hRootKey;
286 LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
287 LPCTSTR path = GetItemPath(pChildWnd->hTreeWnd, 0, &hRootKey);
288 BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
289 if (res) {
290 TVITEMEX item;
291 item.mask = TVIF_HANDLE | TVIF_TEXT;
292 item.hItem = TreeView_GetSelection(pChildWnd->hTreeWnd);
293 item.pszText = dispInfo->item.pszText;
294 TreeView_SetItem(pChildWnd->hTreeWnd, &item);
296 return res;
298 default:
299 return 0; /* goto def; */
301 } else
302 if ((int)wParam == LIST_WINDOW) {
303 if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
304 pChildWnd->nFocusPanel = 1;
305 } else if (!SendMessage(pChildWnd->hListWnd, WM_NOTIFY_REFLECT, wParam, lParam)) {
306 goto def;
309 break;
311 case WM_SIZE:
312 if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
313 ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
315 /* fall through */
316 default: def:
317 return DefWindowProc(hWnd, message, wParam, lParam);
319 return 0;