1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * PURPOSE: Advanced monitor/display settings
5 */
6
7 #include "desk.h"
8
9 #define MAX_ADVANCED_PAGES 32
10
11 static BOOL CALLBACK
PropSheetAddPage(HPROPSHEETPAGE hpage,LPARAM lParam)12 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
13 {
14 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
15 if (ppsh != NULL && ppsh->nPages < MAX_ADVANCED_PAGES)
16 {
17 ppsh->phpage[ppsh->nPages++] = hpage;
18 return TRUE;
19 }
20
21 return FALSE;
22 }
23
24 static BOOL
DisplayAdvancedSettingsInitPropSheetPage(PROPSHEETHEADER * ppsh,WORD idDlg,DLGPROC DlgProc,LPARAM lParam)25 DisplayAdvancedSettingsInitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc, LPARAM lParam)
26 {
27 HPROPSHEETPAGE hPage;
28 PROPSHEETPAGE psp;
29
30 if (ppsh->nPages < MAX_ADVANCED_PAGES)
31 {
32 ZeroMemory(&psp, sizeof(psp));
33 psp.dwSize = sizeof(psp);
34 psp.dwFlags = PSP_DEFAULT;
35 psp.hInstance = hApplet;
36 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
37 psp.pfnDlgProc = DlgProc;
38 psp.lParam = lParam;
39
40 hPage = CreatePropertySheetPage(&psp);
41 if (hPage != NULL)
42 {
43 return PropSheetAddPage(hPage, (LPARAM)ppsh);
44 }
45 }
46
47 return FALSE;
48 }
49
50 static VOID
BuildAdvPropTitle(IDataObject * pdo,LPTSTR lpBuffer,DWORD dwBufferLen)51 BuildAdvPropTitle(IDataObject *pdo, LPTSTR lpBuffer, DWORD dwBufferLen)
52 {
53 UINT uiMonitorName, uiDisplayName;
54 LPTSTR lpMonitorName, lpDisplayName;
55 TCHAR szFormatBuff[32];
56
57 if (!LoadString(hApplet, IDS_ADVANCEDTITLEFMT, szFormatBuff, _countof(szFormatBuff)))
58 {
59 szFormatBuff[0] = _T('\0');
60 }
61
62 uiMonitorName = RegisterClipboardFormat(DESK_EXT_MONITORNAME);
63 uiDisplayName = RegisterClipboardFormat(DESK_EXT_DISPLAYNAME);
64
65 lpMonitorName = QueryDeskCplString(pdo, uiMonitorName);
66 lpDisplayName = QueryDeskCplString(pdo, uiDisplayName);
67
68 _sntprintf(lpBuffer, dwBufferLen, szFormatBuff, lpMonitorName, lpDisplayName);
69
70 if (lpMonitorName != NULL)
71 LocalFree((HLOCAL)lpMonitorName);
72 if (lpDisplayName != NULL)
73 LocalFree((HLOCAL)lpDisplayName);
74 }
75
76 BOOL
DisplayAdvancedSettings(HWND hWndParent,PDISPLAY_DEVICE_ENTRY DisplayDevice)77 DisplayAdvancedSettings(HWND hWndParent, PDISPLAY_DEVICE_ENTRY DisplayDevice)
78 {
79 TCHAR szCaption[128];
80 HPROPSHEETPAGE hpsp[MAX_ADVANCED_PAGES];
81 PROPSHEETHEADER psh;
82 HPSXA hpsxaDev, hpsxaDisp;
83 BOOL Ret;
84 IDataObject *pdo;
85
86 /* FIXME: Build the "%s and %s" caption string for the monitor and adapter name */
87 szCaption[0] = _T('\0');
88
89 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
90 psh.dwSize = sizeof(PROPSHEETHEADER);
91 psh.dwFlags = PSH_PROPTITLE;
92 psh.hwndParent = hWndParent;
93 psh.hInstance = hApplet;
94 psh.pszCaption = szCaption;
95 psh.phpage = hpsp;
96
97 DisplayAdvancedSettingsInitPropSheetPage(&psh, IDD_ADVANCED_GENERAL, AdvGeneralPageProc, (LPARAM)DisplayDevice);
98
99 pdo = CreateDevSettings(DisplayDevice);
100
101 if (pdo != NULL)
102 BuildAdvPropTitle(pdo, szCaption, _countof(szCaption));
103
104 hpsxaDev = SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Device"), MAX_ADVANCED_PAGES - psh.nPages, pdo);
105 if (hpsxaDev != NULL)
106 SHAddFromPropSheetExtArray(hpsxaDev, PropSheetAddPage, (LPARAM)&psh);
107
108 hpsxaDisp = SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Display"), MAX_ADVANCED_PAGES - psh.nPages, pdo);
109 if (hpsxaDisp != NULL)
110 SHAddFromPropSheetExtArray(hpsxaDisp, PropSheetAddPage, (LPARAM)&psh);
111
112 Ret = (LONG)(PropertySheet(&psh) != -1);
113
114 if (hpsxaDisp != NULL)
115 SHDestroyPropSheetExtArray(hpsxaDisp);
116
117 if (hpsxaDev != NULL)
118 SHDestroyPropSheetExtArray(hpsxaDev);
119
120 IDataObject_Release(pdo);
121
122 return Ret;
123 }
124