Reformat regedit in a consistent manner.
[wine.git] / programs / regedit / childwnd.c
blobf78983e0095e7b1e44c9353fdaf343406e20cad8
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 <tchar.h>
24 #include <commctrl.h>
26 #include "main.h"
28 ChildWnd* pChildWnd;
30 /*******************************************************************************
31 * Local module support methods
34 /*FIXME: why do we need this, we should remove it, we have already FindRegRoot */
35 static void MakeFullRegPath(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, int max)
37 TVITEM item;
38 item.mask = TVIF_PARAM;
39 item.hItem = hItem;
40 if (TreeView_GetItem(hwndTV, &item)) {
41 if (item.hItem != TreeView_GetRoot(hwndTV)) {
42 /* recurse */
43 MakeFullRegPath(hwndTV, TreeView_GetParent(hwndTV, hItem), keyPath, pPathLen, max);
44 keyPath[*pPathLen] = _T('\\');
45 ++(*pPathLen);
47 item.mask = TVIF_TEXT;
48 item.hItem = hItem;
49 item.pszText = &keyPath[*pPathLen];
50 item.cchTextMax = max - *pPathLen;
51 if (TreeView_GetItem(hwndTV, &item)) {
52 *pPathLen += _tcslen(item.pszText);
57 static void draw_splitbar(HWND hWnd, int x)
59 RECT rt;
60 HDC hdc = GetDC(hWnd);
62 GetClientRect(hWnd, &rt);
63 rt.left = x - SPLIT_WIDTH/2;
64 rt.right = x + SPLIT_WIDTH/2+1;
65 InvertRect(hdc, &rt);
66 ReleaseDC(hWnd, hdc);
69 static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
71 HDWP hdwp = BeginDeferWindowPos(2);
72 RECT rt = {0, 0, cx, cy};
74 cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
75 DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
76 DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
77 EndDeferWindowPos(hdwp);
80 static void OnPaint(HWND hWnd)
82 PAINTSTRUCT ps;
83 RECT rt;
84 HDC hdc;
86 GetClientRect(hWnd, &rt);
87 hdc = BeginPaint(hWnd, &ps);
88 FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
89 EndPaint(hWnd, &ps);
92 /*******************************************************************************
94 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
96 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
100 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
102 switch (LOWORD(wParam)) {
103 /* Parse the menu selections: */
104 case ID_REGISTRY_EXIT:
105 DestroyWindow(hWnd);
106 break;
107 case ID_VIEW_REFRESH:
108 /* TODO */
109 break;
110 default:
111 return FALSE;
113 return TRUE;
116 /*******************************************************************************
118 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
120 * PURPOSE: Processes messages for the child windows.
122 * WM_COMMAND - process the application menu
123 * WM_PAINT - Paint the main window
124 * WM_DESTROY - post a quit message and return
127 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
129 static int last_split;
130 /* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */
132 switch (message) {
133 case WM_CREATE:
134 pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
135 if (!pChildWnd) return 0;
136 pChildWnd->nSplitPos = 250;
137 pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
138 pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
139 break;
140 case WM_COMMAND:
141 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
142 goto def;
144 break;
145 case WM_PAINT:
146 OnPaint(hWnd);
147 return 0;
148 case WM_SETCURSOR:
149 if (LOWORD(lParam) == HTCLIENT) {
150 POINT pt;
151 GetCursorPos(&pt);
152 ScreenToClient(hWnd, &pt);
153 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
154 SetCursor(LoadCursor(0, IDC_SIZEWE));
155 return TRUE;
158 goto def;
159 case WM_DESTROY:
160 PostQuitMessage(0);
161 break;
162 case WM_LBUTTONDOWN: {
163 RECT rt;
164 int x = LOWORD(lParam);
165 GetClientRect(hWnd, &rt);
166 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
167 last_split = pChildWnd->nSplitPos;
168 draw_splitbar(hWnd, last_split);
169 SetCapture(hWnd);
171 break;
174 case WM_LBUTTONUP:
175 if (GetCapture() == hWnd) {
176 RECT rt;
177 int x = LOWORD(lParam);
178 draw_splitbar(hWnd, last_split);
179 last_split = -1;
180 GetClientRect(hWnd, &rt);
181 pChildWnd->nSplitPos = x;
182 ResizeWnd(pChildWnd, rt.right, rt.bottom);
183 ReleaseCapture();
185 break;
187 case WM_CAPTURECHANGED:
188 if (GetCapture()==hWnd && last_split>=0)
189 draw_splitbar(hWnd, last_split);
190 break;
192 case WM_KEYDOWN:
193 if (wParam == VK_ESCAPE)
194 if (GetCapture() == hWnd) {
195 RECT rt;
196 draw_splitbar(hWnd, last_split);
197 GetClientRect(hWnd, &rt);
198 ResizeWnd(pChildWnd, rt.right, rt.bottom);
199 last_split = -1;
200 ReleaseCapture();
201 SetCursor(LoadCursor(0, IDC_ARROW));
203 break;
205 case WM_MOUSEMOVE:
206 if (GetCapture() == hWnd) {
207 RECT rt;
208 int x = LOWORD(lParam);
209 HDC hdc = GetDC(hWnd);
210 GetClientRect(hWnd, &rt);
211 rt.left = last_split-SPLIT_WIDTH/2;
212 rt.right = last_split+SPLIT_WIDTH/2+1;
213 InvertRect(hdc, &rt);
214 last_split = x;
215 rt.left = x-SPLIT_WIDTH/2;
216 rt.right = x+SPLIT_WIDTH/2+1;
217 InvertRect(hdc, &rt);
218 ReleaseDC(hWnd, hdc);
220 break;
222 case WM_SETFOCUS:
223 if (pChildWnd != NULL) {
224 SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
226 break;
228 case WM_TIMER:
229 break;
231 case WM_NOTIFY:
232 if ((int)wParam == TREE_WINDOW) {
233 switch (((LPNMHDR)lParam)->code) {
234 case TVN_ITEMEXPANDING:
235 return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
236 case TVN_SELCHANGED: {
237 HKEY hKey;
238 TCHAR keyPath[1000];
239 int keyPathLen = 0;
240 keyPath[0] = _T('\0');
241 hKey = FindRegRoot(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR));
242 RefreshListView(pChildWnd->hListWnd, hKey, keyPath);
244 keyPathLen = 0;
245 keyPath[0] = _T('\0');
246 MakeFullRegPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR));
247 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)keyPath);
249 break;
250 default:
251 goto def;
253 } else
254 if ((int)wParam == LIST_WINDOW) {
255 if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
256 goto def;
259 break;
261 case WM_SIZE:
262 if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
263 ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
265 /* fall through */
266 default: def:
267 return DefWindowProc(hWnd, message, wParam, lParam);
269 return 0;