2003-08-07 05:10:13 +02:00
|
|
|
/*
|
|
|
|
* Regedit child window
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
2003-12-12 05:08:59 +01:00
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdio.h>
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(regedit);
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
ChildWnd* g_pChildWnd;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Local module support methods
|
|
|
|
*/
|
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
static LPCTSTR get_root_key_name(HKEY hRootKey)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2003-12-12 05:08:59 +01:00
|
|
|
if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT");
|
|
|
|
if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER");
|
|
|
|
if (hRootKey == HKEY_LOCAL_MACHINE) return _T("HKEY_LOCAL_MACHINE");
|
|
|
|
if (hRootKey == HKEY_USERS) return _T("HKEY_USERS");
|
|
|
|
if (hRootKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
|
2004-07-08 22:14:10 +02:00
|
|
|
if (hRootKey == HKEY_DYN_DATA) return _T("HKEY_DYN_DATA");
|
2003-12-12 05:08:59 +01:00
|
|
|
return _T("UKNOWN HKEY, PLEASE REPORT");
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_splitbar(HWND hWnd, int x)
|
|
|
|
{
|
2003-12-08 23:48:07 +01:00
|
|
|
RECT rt;
|
|
|
|
HDC hdc = GetDC(hWnd);
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
GetClientRect(hWnd, &rt);
|
|
|
|
rt.left = x - SPLIT_WIDTH/2;
|
|
|
|
rt.right = x + SPLIT_WIDTH/2+1;
|
|
|
|
InvertRect(hdc, &rt);
|
|
|
|
ReleaseDC(hWnd, hdc);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
|
|
|
|
{
|
2003-12-08 23:48:07 +01:00
|
|
|
HDWP hdwp = BeginDeferWindowPos(2);
|
|
|
|
RECT rt = {0, 0, cx, cy};
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
|
2003-08-07 05:10:13 +02:00
|
|
|
DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
|
|
|
|
DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
|
2003-12-08 23:48:07 +01:00
|
|
|
EndDeferWindowPos(hdwp);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void OnPaint(HWND hWnd)
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT rt;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
GetClientRect(hWnd, &rt);
|
|
|
|
hdc = BeginPaint(hWnd, &ps);
|
2003-12-05 01:09:54 +01:00
|
|
|
FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
|
2003-08-07 05:10:13 +02:00
|
|
|
EndPaint(hWnd, &ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
|
|
|
|
*
|
|
|
|
* PURPOSE: Processes WM_COMMAND messages for the main frame window.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2004-05-04 04:55:28 +02:00
|
|
|
ChildWnd* pChildWnd = g_pChildWnd;
|
2003-12-08 23:48:07 +01:00
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
/* Parse the menu selections: */
|
2003-08-07 05:10:13 +02:00
|
|
|
case ID_REGISTRY_EXIT:
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
break;
|
|
|
|
case ID_VIEW_REFRESH:
|
|
|
|
/* TODO */
|
|
|
|
break;
|
2004-05-04 04:55:28 +02:00
|
|
|
case ID_SWITCH_PANELS:
|
|
|
|
pChildWnd->nFocusPanel = !pChildWnd->nFocusPanel;
|
|
|
|
SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
|
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
return TRUE;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
|
|
|
|
*
|
|
|
|
* PURPOSE: Processes messages for the child windows.
|
|
|
|
*
|
|
|
|
* WM_COMMAND - process the application menu
|
|
|
|
* WM_PAINT - Paint the main window
|
|
|
|
* WM_DESTROY - post a quit message and return
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
static int last_split;
|
2003-12-12 05:08:59 +01:00
|
|
|
ChildWnd* pChildWnd = g_pChildWnd;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
case WM_CREATE:
|
2003-12-12 05:08:59 +01:00
|
|
|
g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
|
2003-12-08 23:48:07 +01:00
|
|
|
if (!pChildWnd) return 0;
|
2003-12-12 05:08:59 +01:00
|
|
|
_tcsncpy(pChildWnd->szPath, _T("My Computer"), MAX_PATH);
|
2003-08-07 05:10:13 +02:00
|
|
|
pChildWnd->nSplitPos = 250;
|
2003-12-12 05:08:59 +01:00
|
|
|
pChildWnd->hWnd = hWnd;
|
2003-08-07 05:10:13 +02:00
|
|
|
pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
|
|
|
|
pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
|
2004-01-16 22:20:54 +01:00
|
|
|
SetFocus(pChildWnd->hTreeWnd);
|
2003-08-07 05:10:13 +02:00
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
|
|
|
|
goto def;
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
case WM_PAINT:
|
|
|
|
OnPaint(hWnd);
|
|
|
|
return 0;
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
if (LOWORD(lParam) == HTCLIENT) {
|
|
|
|
POINT pt;
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
ScreenToClient(hWnd, &pt);
|
|
|
|
if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
|
|
|
|
SetCursor(LoadCursor(0, IDC_SIZEWE));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto def;
|
2003-08-07 05:10:13 +02:00
|
|
|
case WM_DESTROY:
|
2003-12-12 05:08:59 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pChildWnd);
|
|
|
|
pChildWnd = NULL;
|
2003-08-07 05:10:13 +02:00
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_LBUTTONDOWN: {
|
|
|
|
RECT rt;
|
|
|
|
int x = LOWORD(lParam);
|
|
|
|
GetClientRect(hWnd, &rt);
|
|
|
|
if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
|
|
|
|
last_split = pChildWnd->nSplitPos;
|
|
|
|
draw_splitbar(hWnd, last_split);
|
|
|
|
SetCapture(hWnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_LBUTTONUP:
|
|
|
|
if (GetCapture() == hWnd) {
|
|
|
|
RECT rt;
|
|
|
|
int x = LOWORD(lParam);
|
|
|
|
draw_splitbar(hWnd, last_split);
|
|
|
|
last_split = -1;
|
|
|
|
GetClientRect(hWnd, &rt);
|
|
|
|
pChildWnd->nSplitPos = x;
|
|
|
|
ResizeWnd(pChildWnd, rt.right, rt.bottom);
|
|
|
|
ReleaseCapture();
|
|
|
|
}
|
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
if (GetCapture()==hWnd && last_split>=0)
|
|
|
|
draw_splitbar(hWnd, last_split);
|
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
2003-12-08 23:48:07 +01:00
|
|
|
if (wParam == VK_ESCAPE)
|
|
|
|
if (GetCapture() == hWnd) {
|
|
|
|
RECT rt;
|
|
|
|
draw_splitbar(hWnd, last_split);
|
|
|
|
GetClientRect(hWnd, &rt);
|
2003-08-07 05:10:13 +02:00
|
|
|
ResizeWnd(pChildWnd, rt.right, rt.bottom);
|
2003-12-08 23:48:07 +01:00
|
|
|
last_split = -1;
|
|
|
|
ReleaseCapture();
|
|
|
|
SetCursor(LoadCursor(0, IDC_ARROW));
|
|
|
|
}
|
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
if (GetCapture() == hWnd) {
|
|
|
|
RECT rt;
|
|
|
|
int x = LOWORD(lParam);
|
|
|
|
HDC hdc = GetDC(hWnd);
|
|
|
|
GetClientRect(hWnd, &rt);
|
|
|
|
rt.left = last_split-SPLIT_WIDTH/2;
|
|
|
|
rt.right = last_split+SPLIT_WIDTH/2+1;
|
|
|
|
InvertRect(hdc, &rt);
|
|
|
|
last_split = x;
|
|
|
|
rt.left = x-SPLIT_WIDTH/2;
|
|
|
|
rt.right = x+SPLIT_WIDTH/2+1;
|
|
|
|
InvertRect(hdc, &rt);
|
|
|
|
ReleaseDC(hWnd, hdc);
|
|
|
|
}
|
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_SETFOCUS:
|
2003-08-07 05:10:13 +02:00
|
|
|
if (pChildWnd != NULL) {
|
2003-12-08 23:48:07 +01:00
|
|
|
SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
break;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
|
|
|
case WM_TIMER:
|
|
|
|
break;
|
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_NOTIFY:
|
2003-08-07 05:10:13 +02:00
|
|
|
if ((int)wParam == TREE_WINDOW) {
|
|
|
|
switch (((LPNMHDR)lParam)->code) {
|
|
|
|
case TVN_ITEMEXPANDING:
|
|
|
|
return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
|
2003-12-08 23:48:07 +01:00
|
|
|
case TVN_SELCHANGED: {
|
2003-12-12 05:08:59 +01:00
|
|
|
LPCTSTR keyPath, rootName;
|
|
|
|
LPTSTR fullPath;
|
|
|
|
HKEY hRootKey;
|
2003-08-07 05:10:13 +02:00
|
|
|
|
2003-12-12 05:08:59 +01:00
|
|
|
keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
|
|
|
|
if (keyPath) {
|
2004-05-04 04:55:28 +02:00
|
|
|
RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath, NULL);
|
2003-12-12 05:08:59 +01:00
|
|
|
rootName = get_root_key_name(hRootKey);
|
|
|
|
fullPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(rootName) + 1 + lstrlen(keyPath) + 1) * sizeof(TCHAR));
|
|
|
|
if (fullPath) {
|
|
|
|
_stprintf(fullPath, "%s\\%s", rootName, keyPath);
|
|
|
|
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, fullPath);
|
|
|
|
}
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
break;
|
2004-01-16 22:20:54 +01:00
|
|
|
case NM_SETFOCUS:
|
2004-05-04 04:55:28 +02:00
|
|
|
pChildWnd->nFocusPanel = 0;
|
2004-01-16 22:20:54 +01:00
|
|
|
break;
|
2004-05-04 04:55:28 +02:00
|
|
|
case NM_RCLICK: {
|
|
|
|
POINT pt;
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW),
|
|
|
|
TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
case TVN_ENDLABELEDIT: {
|
|
|
|
HKEY hRootKey;
|
|
|
|
LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
|
|
|
|
LPCTSTR path = GetItemPath(pChildWnd->hTreeWnd, 0, &hRootKey);
|
|
|
|
BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
|
|
|
|
if (res) {
|
|
|
|
TVITEMEX item;
|
|
|
|
item.mask = TVIF_HANDLE | TVIF_TEXT;
|
|
|
|
item.hItem = TreeView_GetSelection(pChildWnd->hTreeWnd);
|
|
|
|
item.pszText = dispInfo->item.pszText;
|
|
|
|
TreeView_SetItem(pChildWnd->hTreeWnd, &item);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
default:
|
2004-05-04 04:55:28 +02:00
|
|
|
return 0; /* goto def; */
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
} else
|
2003-12-08 23:48:07 +01:00
|
|
|
if ((int)wParam == LIST_WINDOW) {
|
2004-01-16 22:20:54 +01:00
|
|
|
if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
|
2004-05-04 04:55:28 +02:00
|
|
|
pChildWnd->nFocusPanel = 1;
|
|
|
|
} else if (!SendMessage(pChildWnd->hListWnd, WM_NOTIFY_REFLECT, wParam, lParam)) {
|
2003-12-08 23:48:07 +01:00
|
|
|
goto def;
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_SIZE:
|
2003-08-07 05:10:13 +02:00
|
|
|
if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
|
2003-12-08 23:48:07 +01:00
|
|
|
ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|
|
|
|
/* fall through */
|
2003-12-08 23:48:07 +01:00
|
|
|
default: def:
|
2003-08-07 05:10:13 +02:00
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2003-08-07 05:10:13 +02:00
|
|
|
}
|