ReactOS 0.4.16-dev-1163-gec5b142
view.cpp
Go to the documentation of this file.
1/*
2 * 'View' tab property sheet of Folder Options
3 *
4 * Copyright 2007 Johannes Anderwald <johannes.anderwald@reactos.org>
5 * Copyright 2016-2018 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include "precomp.h"
23
25
26static inline CFolderOptions*
28{
30}
31
32static inline IRegTreeOptions*
34{
35 return (IRegTreeOptions*)GetWindowLongPtr(hwndDlg, DWLP_USER);
36}
37
38static void
40{
41 if (IRegTreeOptions *pRTO = GetRegTreeOptions(hwndDlg))
42 {
43 pRTO->WalkTree(WALK_TREE_DESTROY);
44 pRTO->Release();
45 SetWindowLongPtr(hwndDlg, DWLP_USER, 0);
46 }
47}
48
49static BOOL
51{
52 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, psp->lParam);
53 CFolderOptions *pFO = (CFolderOptions*)psp->lParam;
54
55 if (!pFO || !pFO->CanSetDefFolderSettings())
56 {
57 // The global options (started from rundll32 or control panel)
58 // has no browser to copy the current settings from.
60 }
61
62 IRegTreeOptions *pRTO = NULL;
63 if (SUCCEEDED(SHCoCreateInstance(NULL, &CLSID_CRegTreeOptions, NULL, IID_PPV_ARG(IRegTreeOptions, &pRTO))))
64 {
65 SetWindowLongPtr(hwndDlg, DWLP_USER, (LPARAM)pRTO);
66
67 CHAR apath[MAX_PATH];
68 SHUnicodeToAnsi(REGSTR_PATH_EXPLORER L"\\Advanced", apath, _countof(apath));
70 pRTO->InitTree(hwndTreeView, HKEY_LOCAL_MACHINE, apath, NULL);
71 }
72
73 return TRUE; // Set focus
74}
75
76static BOOL
78{
79 IRegTreeOptions *pRTO = GetRegTreeOptions(hwndDlg);
80 return pRTO && SUCCEEDED(pRTO->ToggleItem(hItem));
81}
82
83static VOID
85{
87
88 // do hit test to get the clicked item
89 TV_HITTESTINFO HitTest;
90 ZeroMemory(&HitTest, sizeof(HitTest));
91 DWORD dwPos = GetMessagePos();
92 HitTest.pt.x = GET_X_LPARAM(dwPos);
93 HitTest.pt.y = GET_Y_LPARAM(dwPos);
94 ScreenToClient(hwndTreeView, &HitTest.pt);
96
97 // toggle the check mark if possible
98 if (ViewDlg_ToggleCheckItem(hwndDlg, hItem))
99 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
100}
101
102static void
104{
106
107 if (KeyDown->wVKey == VK_SPACE)
108 {
110 if (ViewDlg_ToggleCheckItem(hwndDlg, hItem))
111 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
112 }
113 else if (KeyDown->wVKey == VK_F5)
114 {
115 IRegTreeOptions *pRTO = GetRegTreeOptions(hwndDlg);
116 if (pRTO)
117 pRTO->WalkTree(WALK_TREE_REFRESH);
118 }
119}
120
121static INT_PTR
123{
124 NMCUSTOMDRAW& nmcd = Draw->nmcd;
125 switch (nmcd.dwDrawStage)
126 {
127 case CDDS_PREPAINT:
128 return CDRF_NOTIFYITEMDRAW; // for CDDS_ITEMPREPAINT
129
131 if (!(nmcd.uItemState & CDIS_SELECTED)) // not selected
132 {
134 if ((HKEY)lParam == HKEY_REGTREEOPTION_GRAYED) // disabled
135 {
136 // draw as grayed
137 Draw->clrText = GetSysColor(COLOR_GRAYTEXT);
138 Draw->clrTextBk = GetSysColor(COLOR_WINDOW);
139 return CDRF_NEWFONT;
140 }
141 }
142 break;
143
144 default:
145 break;
146 }
147 return CDRF_DODEFAULT;
148}
149
150static VOID
152{
153 if (IRegTreeOptions *pRTO = GetRegTreeOptions(hwndDlg))
154 {
155 pRTO->WalkTree(WALK_TREE_DEFAULT);
156 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
157 }
158}
159
160static BOOL CALLBACK
162{
163 MSG &data = *(MSG*)param;
164 WCHAR ClassName[100];
165 if (GetClassNameW(hWnd, ClassName, _countof(ClassName)))
166 {
167 if (!wcscmp(ClassName, L"Progman") ||
168 !wcscmp(ClassName, L"CabinetWClass") ||
169 !wcscmp(ClassName, L"ExploreWClass"))
170 {
171 PostMessage(hWnd, data.message, data.wParam, data.lParam);
172 }
173 }
174 return TRUE;
175}
176
177void
179{
180 MSG data;
181 data.message = Msg;
182 data.wParam = wParam;
183 data.lParam = lParam;
185}
186
187static VOID
189{
190 IRegTreeOptions *pRTO = GetRegTreeOptions(hwndDlg);
191 if (!pRTO || FAILED(pRTO->WalkTree(WALK_TREE_SAVE)))
192 return;
193
194 SHSettingsChanged(0, 0); // Invalidate restrictions
195 SHGetSetSettings(NULL, 0, TRUE); // Invalidate SHELLSTATE
196
198 cs.cLength = sizeof(cs);
199 if (ReadCabinetState(&cs, sizeof(cs)))
200 WriteCabinetState(&cs); // Write the settings and invalidate global counter
201
204}
205
206// IDD_FOLDER_OPTIONS_VIEW
209 HWND hwndDlg,
210 UINT uMsg,
213{
215
216 switch (uMsg)
217 {
218 case WM_INITDIALOG:
220
221 case WM_DESTROY:
222 ViewDlg_OnDestroy(hwndDlg);
223 break;
224
225 case WM_COMMAND:
226 switch (LOWORD(wParam))
227 {
228 case IDC_VIEW_RESTORE_DEFAULTS: // Restore Defaults
230 break;
231
234 {
236 bool ResetToDefault = LOWORD(wParam) == IDC_VIEW_RESET_ALL;
238 if (pFO)
239 hr = pFO->ApplyDefFolderSettings(ResetToDefault); // Use IBrowserService2
240 if (ResetToDefault && hr == HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED))
242 if (FAILED(hr))
243 SHELL_ErrorBox(hwndDlg, hr);
244 break;
245 }
246 }
247 break;
248
249 case WM_NOTIFY:
250 switch (LPNMHDR(lParam)->code)
251 {
252 case NM_CLICK: // clicked on treeview
254 break;
255
256 case NM_CUSTOMDRAW: // custom draw (for graying)
259 return Result;
260
261 case TVN_KEYDOWN: // key is down
263 break;
264
265 case PSN_APPLY: // [Apply] is clicked
266 ViewDlg_Apply(hwndDlg);
267 break;
268
269 default:
270 break;
271 }
272 break;
273 }
274
275 return FALSE;
276}
HWND hWnd
Definition: settings.c:17
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static HRESULT ResetGlobalAndDefViewFolderSettings()
WPARAM wParam
Definition: combotst.c:138
struct @1681 Msg[]
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FCIDM_DESKBROWSER_REFRESH
Definition: desktop.c:14
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
HRESULT WINAPI SHCoCreateInstance(LPCWSTR aclsid, const CLSID *clsid, LPUNKNOWN pUnkOuter, REFIID refiid, LPVOID *ppv)
Definition: shellole.c:105
DWORD WINAPI SHSendMessageBroadcastW(UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: ordinal.c:4072
INT WINAPI SHUnicodeToAnsi(LPCWSTR lpSrcStr, LPSTR lpDstStr, INT iLen)
Definition: string.c:2797
HWND hwndTreeView
Definition: eventvwr.c:65
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxFileObject * pFO
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLfloat param
Definition: glext.h:5796
#define cs
Definition: i386-dis.c:442
nsrefcnt Release()
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
if(dx< 0)
Definition: linetemp.h:194
void Draw(HDC aDc)
Definition: magnifier.c:359
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSN_APPLY
Definition: prsht.h:117
#define LPPROPSHEETPAGE
Definition: prsht.h:390
#define TVN_KEYDOWN
Definition: commctrl.h:3718
#define CDDS_ITEMPREPAINT
Definition: commctrl.h:285
#define CDRF_NOTIFYITEMDRAW
Definition: commctrl.h:275
#define CDRF_DODEFAULT
Definition: commctrl.h:268
#define TV_HITTESTINFO
Definition: commctrl.h:3521
#define CDIS_SELECTED
Definition: commctrl.h:291
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3478
#define NM_CLICK
Definition: commctrl.h:130
#define NM_CUSTOMDRAW
Definition: commctrl.h:137
#define CDRF_NEWFONT
Definition: commctrl.h:269
#define CDDS_PREPAINT
Definition: commctrl.h:280
#define TV_KEYDOWN
Definition: commctrl.h:3727
#define TreeView_HitTest(hwnd, lpht)
Definition: commctrl.h:3518
#define REGSTR_PATH_EXPLORER
Definition: regstr.h:33
#define WM_NOTIFY
Definition: richedit.h:61
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
Definition: shellord.c:1807
VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
Definition: shellord.c:225
BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
Definition: shellord.c:1859
#define SHELL_ErrorBox
Definition: shellutils.h:126
HRESULT hr
Definition: shlfolder.c:183
#define HKEY_REGTREEOPTION_GRAYED
Definition: shlobj_undoc.h:462
@ WALK_TREE_REFRESH
Definition: shlobj_undoc.h:459
@ WALK_TREE_DESTROY
Definition: shlobj_undoc.h:457
@ WALK_TREE_DEFAULT
Definition: shlobj_undoc.h:458
@ WALK_TREE_SAVE
Definition: shlobj_undoc.h:456
BOOL WINAPI SHSettingsChanged(LPCVOID unused, LPCWSTR pszKey)
Definition: shpolicy.c:197
#define IDC_VIEW_RESET_ALL
Definition: shresdef.h:531
#define IDC_VIEW_TREEVIEW
Definition: shresdef.h:532
#define IDC_VIEW_RESTORE_DEFAULTS
Definition: shresdef.h:533
#define IDC_VIEW_APPLY_TO_ALL
Definition: shresdef.h:530
#define _countof(array)
Definition: sndvol32.h:70
Definition: inflate.c:139
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT_PTR
Definition: typedefs.h:64
static BOOL CALLBACK PostCabinetMessageCallback(HWND hWnd, LPARAM param)
Definition: view.cpp:161
static void ViewDlg_OnTreeViewKeyDown(HWND hwndDlg, TV_KEYDOWN *KeyDown)
Definition: view.cpp:103
static VOID ViewDlg_RestoreDefaults(HWND hwndDlg)
Definition: view.cpp:151
INT_PTR CALLBACK FolderOptionsViewDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: view.cpp:208
static INT_PTR ViewDlg_OnTreeCustomDraw(HWND hwndDlg, NMTVCUSTOMDRAW *Draw)
Definition: view.cpp:122
static VOID ViewDlg_Apply(HWND hwndDlg)
Definition: view.cpp:188
static BOOL ViewDlg_ToggleCheckItem(HWND hwndDlg, HTREEITEM hItem)
Definition: view.cpp:77
static BOOL ViewDlg_OnInitDialog(HWND hwndDlg, LPPROPSHEETPAGE psp)
Definition: view.cpp:50
static CFolderOptions * GetFolderOptions(HWND hwndDlg)
Definition: view.cpp:27
void PostCabinetMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: view.cpp:178
static void ViewDlg_OnDestroy(HWND hwndDlg)
Definition: view.cpp:39
static VOID ViewDlg_OnTreeViewClick(HWND hwndDlg)
Definition: view.cpp:84
static IRegTreeOptions * GetRegTreeOptions(HWND hwndDlg)
Definition: view.cpp:33
#define ZeroMemory
Definition: winbase.h:1744
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
DWORD WINAPI GetSysColor(_In_ int)
#define DWLP_USER
Definition: winuser.h:883
#define COLOR_GRAYTEXT
Definition: winuser.h:943
#define COLOR_WINDOW
Definition: winuser.h:929
DWORD WINAPI GetMessagePos(void)
Definition: message.c:1351
#define VK_SPACE
Definition: winuser.h:2230
#define WM_COMMAND
Definition: winuser.h:1751
#define WM_INITDIALOG
Definition: winuser.h:1750
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_SETTINGCHANGE
Definition: winuser.h:1640
#define VK_F5
Definition: winuser.h:2270
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam)
struct tagNMHDR * LPNMHDR
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define PostMessage
Definition: winuser.h:5852
HWND WINAPI GetParent(_In_ HWND)
int WINAPI GetClassNameW(_In_ HWND hWnd, _Out_writes_to_(nMaxCount, return) LPWSTR lpClassName, _In_ int nMaxCount)
#define DWLP_MSGRESULT
Definition: winuser.h:881
#define WM_DESTROY
Definition: winuser.h:1620
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175