[CRT] Massively improve performance of rand_s
[reactos.git] / dll / shellext / acppage / CLayerUIPropPage.cpp
index a923281..2f74b0d 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * PROJECT:     ReactOS Compatibility Layer Shell Extension
- * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
  * PURPOSE:     CLayerUIPropPage implementation
- * COPYRIGHT:   Copyright 2015-2017 Mark Jansen (mark.jansen@reactos.org)
+ * COPYRIGHT:   Copyright 2015-2019 Mark Jansen (mark.jansen@reactos.org)
  */
 
 #include "precomp.h"
@@ -16,7 +16,6 @@
 #include <sfc.h>
 
 const GUID CLSID_CLayerUIPropPage = { 0x513D916F, 0x2A8E, 0x4F51, { 0xAE, 0xAB, 0x0C, 0xBC, 0x76, 0xFB, 0x1A, 0xF8 } };
-#define ACP_WNDPROP L"{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}.Prop"
 
 #define GPLK_USER 1
 #define GPLK_MACHINE 2
@@ -30,16 +29,16 @@ static struct {
     { L"Windows 98/ME", L"WIN98" },
     { L"Windows NT 4.0 (SP5)", L"NT4SP5" },
     { L"Windows 2000", L"WIN2000" },
-    { L"Windows XP (SP2)", L"WINXPSP2" },
     { L"Windows XP (SP3)", L"WINXPSP3" },
     { L"Windows Server 2003 (SP1)", L"WINSRV03SP1" },
-#if 0
     { L"Windows Server 2008 (SP1)", L"WINSRV08SP1" },
-    { L"Windows Vista", L"VISTARTM" },
-    { L"Windows Vista (SP1)", L"VISTASP1" },
     { L"Windows Vista (SP2)", L"VISTASP2" },
     { L"Windows 7", L"WIN7RTM" },
-#endif
+    { L"Windows 7 (SP1)", L"WIN7SP1" },
+    { L"Windows 8.1", L"WIN81RTM" },
+    { L"Windows 10", L"WIN10RTM" },
+    { L"Windows Server 2016", L"WINSRV16RTM" },
+    { L"Windows Server 2019", L"WINSRV19RTM" },
     { NULL, NULL }
 };
 
@@ -67,6 +66,28 @@ static const WCHAR* g_AllowedExtensions[] = {
     0
 };
 
+BOOL IsBuiltinLayer(PCWSTR Name)
+{
+    size_t n;
+
+    for (n = 0; g_Layers[n].Name; ++n)
+    {
+        if (!wcsicmp(g_Layers[n].Name, Name))
+        {
+            return TRUE;
+        }
+    }
+
+    for (n = 0; g_CompatModes[n].Name; ++n)
+    {
+        if (!wcsicmp(g_CompatModes[n].Name, Name))
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
 
 void ACDBG_FN(PCSTR FunctionName, PCWSTR Format, ...)
 {
@@ -95,10 +116,16 @@ CLayerUIPropPage::CLayerUIPropPage()
 , m_RegistryEnabledLayers(0)
 , m_EnabledLayers(0)
 {
+    CComBSTR title;
+    title.LoadString(g_hModule, IDS_COMPAT_TITLE);
+    m_psp.pszTitle = title.Detach();
+    m_psp.dwFlags |= PSP_USETITLE;
 }
 
 CLayerUIPropPage::~CLayerUIPropPage()
 {
+    CComBSTR title;
+    title.Attach((BSTR)m_psp.pszTitle);
 }
 
 HRESULT CLayerUIPropPage::InitFile(PCWSTR Filename)
@@ -241,8 +268,6 @@ int CLayerUIPropPage::OnSetActive()
 
     m_CustomLayers = m_RegistryCustomLayers;
 
-    /* TODO: visualize 'custom' layers! */
-
     UpdateControls();
 
     return 0;
@@ -313,9 +338,9 @@ LRESULT CLayerUIPropPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
     HWND cboMode = GetDlgItem(IDC_COMPATIBILITYMODE);
     for (size_t n = 0; g_CompatModes[n].Display; ++n)
         ComboBox_AddString(cboMode, g_CompatModes[n].Display);
-    ComboBox_SetCurSel(cboMode, 5);
+    ComboBox_SetCurSel(cboMode, 4);
 
-    CComBSTR explanation;
+    CStringW explanation;
     if (!m_AllowPermLayer)
     {
         explanation.LoadString(g_hModule, IDS_FAILED_NETWORK);
@@ -360,6 +385,15 @@ void CLayerUIPropPage::UpdateControls()
         ::ShowWindow(GetDlgItem(g_Layers[n].Id), SW_SHOW);
     }
 
+    CStringW customLayers;
+    for (int j = 0; j < m_CustomLayers.GetSize(); ++j)
+    {
+        if (j > 0)
+            customLayers += L", ";
+        customLayers += m_CustomLayers[j];
+    }
+    SetDlgItemTextW(IDC_ENABLED_LAYERS, customLayers);
+
     SetModified(HasChanges());
 }
 
@@ -371,7 +405,7 @@ LRESULT CLayerUIPropPage::OnCtrlCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl
 
 LRESULT CLayerUIPropPage::OnEditModes(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
 {
-    if (DialogBoxParam(g_hModule, MAKEINTRESOURCE(IDD_EDITCOMPATIBILITYMODES), m_hWnd, EditModesProc, (LPARAM)this) == IDOK)
+    if (ShowEditCompatModes(m_hWnd, this))
         UpdateControls();
     return 0;
 }
@@ -379,169 +413,10 @@ LRESULT CLayerUIPropPage::OnEditModes(WORD wNotifyCode, WORD wID, HWND hWndCtl,
 LRESULT CLayerUIPropPage::OnClickNotify(INT uCode, LPNMHDR hdr, BOOL& bHandled)
 {
     if (hdr->idFrom == IDC_INFOLINK)
-        ShellExecute(NULL, L"open", L"https://www.reactos.org/forum/viewforum.php?f=4", NULL, NULL, SW_SHOW);
+        ShellExecute(NULL, L"open", L"https://reactos.org/forum/viewforum.php?f=4", NULL, NULL, SW_SHOW);
     return 0;
 }
 
-static void ListboxChanged(HWND hWnd)
-{
-    int Sel = ListBox_GetCurSel(GetDlgItem(hWnd, IDC_COMPATIBILITYMODE));
-    EnableWindow(GetDlgItem(hWnd, IDC_EDIT), Sel >= 0);
-    EnableWindow(GetDlgItem(hWnd, IDC_DELETE), Sel >= 0);
-}
-
-static void OnAdd(HWND hWnd)
-{
-    HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
-    
-    int Length = ComboBox_GetTextLength(Combo);
-    CComBSTR Str(Length);
-    ComboBox_GetText(Combo, Str, Length+1);
-    HWND List = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
-    int Index = ListBox_FindStringExact(List, -1, Str);
-    if (Index == LB_ERR)
-        Index = ListBox_AddString(List, Str);
-    ListBox_SetCurSel(List, Index);
-    ListboxChanged(hWnd);
-    ComboBox_SetCurSel(Combo, -1);
-    SetFocus(Combo);
-}
-
-static BOOL ComboHasData(HWND hWnd)
-{
-    HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
-    if (ComboBox_GetCurSel(Combo) >= 0)
-        return TRUE;
-    ULONG Len = ComboBox_GetTextLength(Combo);
-    return Len > 0;
-}
-
-INT_PTR CALLBACK CLayerUIPropPage::EditModesProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
-    CLayerUIPropPage* page = NULL;
-
-    switch (uMsg)
-    {
-    case WM_INITDIALOG:
-        page = (CLayerUIPropPage*)lParam;
-        page->AddRef();
-        ::SetProp(hWnd, ACP_WNDPROP, page);
-        {
-            HWND Combo = ::GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
-            CComObject<CLayerStringList> pList;
-
-            while (TRUE)
-            {
-                CComHeapPtr<OLECHAR> str;
-                HRESULT hr = pList.Next(1, &str, NULL);
-                if (hr != S_OK)
-                    break;
-                ComboBox_AddString(Combo, str);
-            }
-
-            HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
-            for (int n = 0; n < page->m_CustomLayers.GetSize(); ++n)
-            {
-                const WCHAR* Str = page->m_CustomLayers[n].GetString();
-                int Index = ListBox_FindStringExact(List, -1, Str);
-                if (Index == LB_ERR)
-                    Index = ListBox_AddString(List, Str);
-            }
-        }
-        break;
-    case WM_ENDSESSION:
-    case WM_DESTROY:
-        page = (CLayerUIPropPage*)::GetProp(hWnd, ACP_WNDPROP);
-        ::RemoveProp(hWnd, ACP_WNDPROP);
-        page->Release();
-        break;
-
-    case WM_COMMAND:
-        switch(LOWORD(wParam))
-        {
-        case IDC_ADD:
-            OnAdd(hWnd);
-            break;
-        case IDC_EDIT:
-        {
-            HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
-            int Cur = ListBox_GetCurSel(List);
-            int Length = ListBox_GetTextLen(List, Cur);
-            CComBSTR Str(Length);
-            ListBox_GetText(List, Cur, Str);
-            ListBox_DeleteString(List, Cur);
-            HWND Combo = ::GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
-            ComboBox_SetCurSel(Combo, -1);
-            ::SetWindowText(Combo,Str);
-            ListboxChanged(hWnd);
-            ComboBox_SetEditSel(Combo, 30000, 30000);
-            ::SetFocus(Combo);
-        }
-            break;
-        case IDC_DELETE:
-        {
-            HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
-            ListBox_DeleteString(List, ListBox_GetCurSel(List));
-            ListboxChanged(hWnd);
-        }
-            break;
-        case IDC_COMPATIBILITYMODE:
-            ListboxChanged(hWnd);
-            break;
-        case IDC_NEWCOMPATIBILITYMODE:
-        {
-            ::EnableWindow(::GetDlgItem(hWnd, IDC_ADD), ComboHasData(hWnd));
-        }
-            break;
-        case IDOK:
-            /* Copy from list! */
-        {
-            if (ComboHasData(hWnd))
-            {
-                CComBSTR question, title;
-                title.LoadString(g_hModule, IDS_TABTITLE);
-                question.LoadString(g_hModule, IDS_YOU_DID_NOT_ADD);
-                int result = ::MessageBoxW(hWnd, question, title, MB_YESNOCANCEL | MB_ICONQUESTION);
-                switch (result)
-                {
-                case IDYES:
-                    OnAdd(hWnd);
-                    break;
-                case IDNO:
-                    break;
-                case IDCANCEL:
-                    return FALSE;
-                }
-            }
-
-            page = (CLayerUIPropPage*)::GetProp(hWnd, ACP_WNDPROP);
-
-            HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
-            int Count = ListBox_GetCount(List);
-            page->m_CustomLayers.RemoveAll();
-            for (int Cur = 0; Cur < Count; ++Cur)
-            {
-                int Length = ListBox_GetTextLen(List, Cur);
-                CString Str;
-                LPWSTR Buffer = Str.GetBuffer(Length + 1);
-                ListBox_GetText(List, Cur, Buffer);
-                Str.ReleaseBuffer(Length);
-                page->m_CustomLayers.Add(Str);
-            }
-        }
-        /* Fall trough */
-        case IDCANCEL:
-            ::EndDialog(hWnd, LOWORD(wParam));
-            break;
-        }
-        break;
-    case WM_CLOSE:
-        ::EndDialog(hWnd, IDCANCEL);
-        break;
-    }
-    return FALSE;
-}
-
 static BOOL DisableShellext()
 {
     HKEY hkey;
@@ -571,7 +446,7 @@ static BOOL DisableShellext()
     return Disable;
 }
 
-STDMETHODIMP CLayerUIPropPage::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hkeyProgID)
+STDMETHODIMP CLayerUIPropPage::Initialize(PCIDLIST_ABSOLUTE pidlFolder, LPDATAOBJECT pDataObj, HKEY hkeyProgID)
 {
     FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
     STGMEDIUM stg;