Authors: Robert Dickenson <robd@reactos.org>, Steven Edwards <Steven_Ed4153@yahoo...
[wine/multimedia.git] / programs / regedit / childwnd.c
blobd03154287778b4657fb7ed9525ac6bba643f981b
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>
25 #include <assert.h>
26 #define ASSERT assert
28 #include "main.h"
31 /*******************************************************************************
32 * Local module support methods
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, GetStockObject(LTGRAY_BRUSH));
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); */
131 static ChildWnd* pChildWnd;
133 switch (message) {
134 case WM_CREATE:
135 pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
136 ASSERT(pChildWnd);
137 pChildWnd->nSplitPos = 250;
138 pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
139 pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
140 break;
141 case WM_COMMAND:
142 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
143 goto def;
145 break;
146 case WM_PAINT:
147 OnPaint(hWnd);
148 return 0;
149 case WM_SETCURSOR:
150 if (LOWORD(lParam) == HTCLIENT) {
151 POINT pt;
152 GetCursorPos(&pt);
153 ScreenToClient(hWnd, &pt);
154 if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
155 SetCursor(LoadCursor(0, IDC_SIZEWE));
156 return TRUE;
159 goto def;
160 case WM_DESTROY:
161 PostQuitMessage(0);
162 break;
163 case WM_LBUTTONDOWN: {
164 RECT rt;
165 int x = LOWORD(lParam);
166 GetClientRect(hWnd, &rt);
167 if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
168 last_split = pChildWnd->nSplitPos;
169 draw_splitbar(hWnd, last_split);
170 SetCapture(hWnd);
172 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:
238 HKEY hKey;
239 TCHAR keyPath[1000];
240 int keyPathLen = 0;
241 keyPath[0] = _T('\0');
242 hKey = FindRegRoot(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR));
243 RefreshListView(pChildWnd->hListWnd, hKey, keyPath);
245 keyPathLen = 0;
246 keyPath[0] = _T('\0');
247 MakeFullRegPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, keyPath, &keyPathLen, sizeof(keyPath)/sizeof(TCHAR));
248 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)keyPath);
250 break;
251 default:
252 goto def;
254 } else
255 if ((int)wParam == LIST_WINDOW) {
256 if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
257 goto def;
260 break;
262 case WM_SIZE:
263 if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
264 ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
266 /* fall through */
267 default: def:
268 return DefWindowProc(hWnd, message, wParam, lParam);
270 return 0;