468aeb84ab0a7caca0942b34c1d9273a1b367012
[reactos.git] / rosapps / regedit / framewnd.c
1 /*
2 * ReactOS regedit
3 *
4 * framewnd.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <process.h>
31 #include <stdio.h>
32
33 #include "main.h"
34 #include "about.h"
35 #include "framewnd.h"
36 #include "treeview.h"
37 #include "listview.h"
38 #include <shellapi.h>
39
40
41 ////////////////////////////////////////////////////////////////////////////////
42 // Global and Local Variables:
43 //
44
45 static BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
46
47 static HWND hChildWnd;
48
49 ////////////////////////////////////////////////////////////////////////////////
50 // Local module support methods
51 //
52
53 static void resize_frame_rect(HWND hWnd, PRECT prect)
54 {
55 RECT rt;
56 /*
57 if (IsWindowVisible(hToolBar)) {
58 SendMessage(hToolBar, WM_SIZE, 0, 0);
59 GetClientRect(hToolBar, &rt);
60 prect->top = rt.bottom+3;
61 prect->bottom -= rt.bottom+3;
62 }
63 */
64 if (IsWindowVisible(hStatusBar)) {
65 SetupStatusBar(hWnd, TRUE);
66 GetClientRect(hStatusBar, &rt);
67 prect->bottom -= rt.bottom;
68 }
69 MoveWindow(hChildWnd, prect->left, prect->top, prect->right, prect->bottom, TRUE);
70 }
71
72 void resize_frame_client(HWND hWnd)
73 {
74 RECT rect;
75
76 GetClientRect(hWnd, &rect);
77 resize_frame_rect(hWnd, &rect);
78 }
79
80 ////////////////////////////////////////////////////////////////////////////////
81
82 static void OnEnterMenuLoop(HWND hWnd)
83 {
84 int nParts;
85
86 // Update the status bar pane sizes
87 nParts = -1;
88 SendMessage(hStatusBar, SB_SETPARTS, 1, (long)&nParts);
89 bInMenuLoop = TRUE;
90 SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
91 }
92
93 static void OnExitMenuLoop(HWND hWnd)
94 {
95 bInMenuLoop = FALSE;
96 // Update the status bar pane sizes
97 SetupStatusBar(hWnd, TRUE);
98 UpdateStatusBar();
99 }
100
101 static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
102 {
103 TCHAR str[100];
104
105 _tcscpy(str, _T(""));
106 if (nFlags & MF_POPUP) {
107 if (hSysMenu != GetMenu(hWnd)) {
108 if (nItemID == 2) nItemID = 5;
109 }
110 }
111 if (LoadString(hInst, nItemID, str, 100)) {
112 // load appropriate string
113 LPTSTR lpsz = str;
114 // first newline terminates actual string
115 lpsz = _tcschr(lpsz, '\n');
116 if (lpsz != NULL)
117 *lpsz = '\0';
118 }
119 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
120 }
121
122 void SetupStatusBar(HWND hWnd, BOOL bResize)
123 {
124 RECT rc;
125 int nParts;
126 GetClientRect(hWnd, &rc);
127 nParts = rc.right;
128 // nParts = -1;
129 if (bResize)
130 SendMessage(hStatusBar, WM_SIZE, 0, 0);
131 SendMessage(hStatusBar, SB_SETPARTS, 1, (LPARAM)&nParts);
132 }
133
134 void UpdateStatusBar(void)
135 {
136 TCHAR text[260];
137 DWORD size;
138
139 size = sizeof(text)/sizeof(TCHAR);
140 GetComputerName(text, &size);
141 SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)text);
142 }
143
144 static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
145 {
146 BOOL vis = IsWindowVisible(hchild);
147 HMENU hMenuView = GetSubMenu(hMenuFrame, ID_VIEW_MENU);
148
149 CheckMenuItem(hMenuView, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
150 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
151 resize_frame_client(hWnd);
152 }
153
154 ////////////////////////////////////////////////////////////////////////////////
155 //
156 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
157 //
158 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
159 //
160 //
161
162 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
163 {
164 switch (LOWORD(wParam)) {
165 // Parse the menu selections:
166 case ID_REGISTRY_PRINTERSETUP:
167 //PRINTDLG pd;
168 //PrintDlg(&pd);
169 //PAGESETUPDLG psd;
170 //PageSetupDlg(&psd);
171 break;
172 case ID_REGISTRY_OPENLOCAL:
173 break;
174 case ID_REGISTRY_EXIT:
175 DestroyWindow(hWnd);
176 break;
177 case ID_VIEW_REFRESH:
178 // TODO:
179 break;
180 // case ID_OPTIONS_TOOLBAR:
181 // toggle_child(hWnd, LOWORD(wParam), hToolBar);
182 // break;
183 case ID_VIEW_STATUSBAR:
184 toggle_child(hWnd, LOWORD(wParam), hStatusBar);
185 break;
186 case ID_HELP_HELPTOPICS:
187 // WinHelp(hWnd, _T("regedit"), HELP_CONTENTS, 0);
188 WinHelp(hWnd, _T("regedit"), HELP_FINDER, 0);
189 break;
190 case ID_HELP_ABOUT:
191 #ifdef WINSHELLAPI
192 ShellAbout(hWnd, szTitle, _T(""), LoadIcon(hInst, (LPCTSTR)IDI_REGEDIT));
193 #else
194 ShowAboutBox(hWnd);
195 #endif
196 break;
197 default:
198 return FALSE;
199 }
200 return TRUE;
201 }
202
203 ////////////////////////////////////////////////////////////////////////////////
204 //
205 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
206 //
207 // PURPOSE: Processes messages for the main frame window.
208 //
209 // WM_COMMAND - process the application menu
210 // WM_DESTROY - post a quit message and return
211 //
212 //
213
214 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
215 {
216 static ChildWnd* pChildWnd = NULL;
217
218 switch (message) {
219 case WM_CREATE:
220 {
221 pChildWnd = malloc(sizeof(ChildWnd));
222 _tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
223 hChildWnd = CreateWindowEx(0, szChildClass, _T("regedit child window"),
224 // WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE|WS_BORDER,
225 WS_CHILD|WS_VISIBLE | WS_EX_CLIENTEDGE,
226 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
227 hWnd, (HMENU)0, hInst, pChildWnd);
228 }
229 break;
230 case WM_COMMAND:
231 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
232 return DefWindowProc(hWnd, message, wParam, lParam);
233 }
234 break;
235 case WM_SIZE:
236 resize_frame_client(hWnd);
237 break;
238 case WM_TIMER:
239 break;
240 case WM_ENTERMENULOOP:
241 OnEnterMenuLoop(hWnd);
242 break;
243 case WM_EXITMENULOOP:
244 OnExitMenuLoop(hWnd);
245 break;
246 case WM_MENUSELECT:
247 OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
248 break;
249 case WM_DESTROY:
250 if (pChildWnd) {
251 free(pChildWnd);
252 pChildWnd = NULL;
253 }
254 WinHelp(hWnd, _T("regedit"), HELP_QUIT, 0);
255 PostQuitMessage(0);
256 default:
257 return DefWindowProc(hWnd, message, wParam, lParam);
258 }
259 return 0;
260 }