[EXPLORER] -implement showing the start menu preview
[reactos.git] / reactos / base / shell / explorer / trayprop.cpp
index b813263..f10332f 100644 (file)
@@ -2,6 +2,7 @@
  * ReactOS Explorer
  *
  * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
+ *                  2015 Robert Naumann <gonzomdx@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,79 +25,206 @@ typedef struct _PROPSHEET_INFO
 {
     HWND hTaskbarWnd;
     HWND hStartWnd;
-    HWND hNotiWnd;
-    HWND hToolWnd;
 
     HBITMAP hTaskbarBitmap;
+    HBITMAP hTrayBitmap;
+    HBITMAP hStartBitmap;
 } PROPSHEET_INFO, *PPROPSHEET_INFO;
 
 
 static BOOL
-UpdateTaskbarBitmap(PPROPSHEET_INFO pPropInfo)
+UpdateBitmaps(PPROPSHEET_INFO pPropInfo)
 {
-    HWND hwndLock, hwndHide, hwndGroup, hwndShowQL;
-    HWND hwndBitmap;
-    BOOL bLock, bHide, bGroup, bShowQL;
-    LPTSTR lpImageName = NULL;
+    HWND hwndLock, hwndHide, hwndGroup, hwndShowQL, hwndClock, hwndSeconds, hwndHideInactive, hwndModernStart, hwndClassicStart;
+    HWND hwndTaskbarBitmap, hwndTrayBitmap, hwndStartBitmap;
+    HWND hwndCustomizeNotifyButton, hwndCustomizeClassicStartButton, hwndCustomizeModernStartButton;
+    BOOL bLock, bHide, bGroup, bShowQL, bShowClock, bShowSeconds, bHideInactive;
+    LPTSTR lpTaskBarImageName = NULL, lpTrayImageName = NULL, lpStartImageName = NULL;
     BOOL bRet = FALSE;
 
     hwndLock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_LOCK);
     hwndHide = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDE);
     hwndGroup = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_GROUP);
     hwndShowQL = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SHOWQL);
-
-    if (hwndLock && hwndHide && hwndGroup && hwndShowQL)
+    
+    hwndClock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_CLOCK);
+    hwndSeconds = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SECONDS);
+    hwndHideInactive = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDEICONS);
+    
+    hwndCustomizeNotifyButton = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_ICONCUST);
+    
+    hwndModernStart = GetDlgItem(pPropInfo->hStartWnd, IDC_TASKBARPROP_STARTMENU);
+    hwndClassicStart = GetDlgItem(pPropInfo->hStartWnd, IDC_TASKBARPROP_STARTMENUCLASSIC);
+    
+    hwndCustomizeClassicStartButton = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_STARTMENUCLASSICCUST);
+    hwndCustomizeModernStartButton = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_STARTMENUCUST);
+    
+    
+
+    if (hwndLock && hwndHide && hwndGroup && hwndShowQL && hwndClock && hwndSeconds && hwndHideInactive)
     {
         bLock = (SendMessage(hwndLock, BM_GETCHECK, 0, 0) == BST_CHECKED);
         bHide = (SendMessage(hwndHide, BM_GETCHECK, 0, 0) == BST_CHECKED);
         bGroup = (SendMessage(hwndGroup, BM_GETCHECK, 0, 0) == BST_CHECKED);
         bShowQL = (SendMessage(hwndShowQL, BM_GETCHECK, 0, 0) == BST_CHECKED);
+        
+        bShowClock = (SendMessage(hwndClock, BM_GETCHECK, 0, 0) == BST_CHECKED);
+        bShowSeconds = (SendMessage(hwndSeconds, BM_GETCHECK, 0, 0) == BST_CHECKED);
+        bHideInactive = (SendMessage(hwndHideInactive, BM_GETCHECK, 0, 0) == BST_CHECKED);
 
         if (bHide)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_AUTOHIDE);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_AUTOHIDE);
         else if (bLock  && bGroup  && bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_GROUP_QL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_GROUP_QL);
         else if (bLock  && !bGroup && !bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_NOGROUP_NOQL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_NOGROUP_NOQL);
         else if (bLock  && bGroup  && !bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_GROUP_NOQL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_GROUP_NOQL);
         else if (bLock  && !bGroup && bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_NOGROUP_QL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_NOGROUP_QL);
         else if (!bLock && !bGroup && !bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_NOGROUP_NOQL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_NOGROUP_NOQL);
         else if (!bLock && bGroup  && !bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_GROUP_NOQL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_GROUP_NOQL);
         else if (!bLock && !bGroup && bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_NOGROUP_QL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_NOGROUP_QL);
         else if (!bLock && bGroup  && bShowQL)
-            lpImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_GROUP_QL);
+            lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_GROUP_QL);
 
-        if (lpImageName)
+        
+        if (lpTaskBarImageName)
         {
             if (pPropInfo->hTaskbarBitmap)
             {
                 DeleteObject(pPropInfo->hTaskbarBitmap);
             }
 
-            pPropInfo->hTaskbarBitmap = (HBITMAP)LoadImage(hExplorerInstance,
-                                                  lpImageName,
+            pPropInfo->hTaskbarBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
+                                                  lpTaskBarImageName,
                                                   IMAGE_BITMAP,
                                                   0,
                                                   0,
                                                   LR_DEFAULTCOLOR);
             if (pPropInfo->hTaskbarBitmap)
             {
-                hwndBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
+                hwndTaskbarBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
                                         IDC_TASKBARPROP_TASKBARBITMAP);
-                if (hwndBitmap)
+                if (hwndTaskbarBitmap)
                 {
-                    SendMessage(hwndBitmap,
+                    SendMessage(hwndTaskbarBitmap,
                                 STM_SETIMAGE,
                                 IMAGE_BITMAP,
                                 (LPARAM)pPropInfo->hTaskbarBitmap);
                 }
             }
         }
+        
+        if (bHideInactive)
+        {
+            EnableWindow(hwndCustomizeNotifyButton, TRUE);
+            if (bShowClock)
+            {
+                EnableWindow(hwndSeconds, TRUE);
+                if (bShowSeconds)
+                    lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_SECONDS);
+                else
+                    lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_CLOCK);
+            }
+            else
+            {
+                SendMessage(hwndSeconds, BM_SETCHECK, BST_UNCHECKED, 0);
+                EnableWindow(hwndSeconds, FALSE);
+                lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_NOCLOCK);
+            }
+        }
+        else
+        {
+            EnableWindow(hwndCustomizeNotifyButton, FALSE);
+            if (bShowClock)
+            {
+                EnableWindow(hwndSeconds, TRUE);
+                if (bShowSeconds)
+                    lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_SECONDS);
+                else
+                    lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_CLOCK);
+            }
+            else
+            {
+                SendMessage(hwndSeconds, BM_SETCHECK, BST_UNCHECKED, 0);
+                EnableWindow(hwndSeconds, FALSE);
+                lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_NOCLOCK);
+            }
+        }
+        
+        if (lpTrayImageName)
+        {
+            if (pPropInfo->hTrayBitmap)
+            {
+                DeleteObject(pPropInfo->hTrayBitmap);
+            }
+
+            pPropInfo->hTrayBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
+                                                  lpTrayImageName,
+                                                  IMAGE_BITMAP,
+                                                  0,
+                                                  0,
+                                                  LR_DEFAULTCOLOR);
+            if (pPropInfo->hTrayBitmap)
+            {
+                hwndTrayBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
+                                        IDC_TASKBARPROP_NOTIFICATIONBITMAP);
+                if (hwndTrayBitmap)
+                {
+                    SendMessage(hwndTrayBitmap,
+                                STM_SETIMAGE,
+                                IMAGE_BITMAP,
+                                (LPARAM)pPropInfo->hTrayBitmap);
+                }
+            }
+        }
+    }
+    
+    if(hwndClassicStart && hwndModernStart)
+    {
+        if(SendMessage(hwndModernStart, BM_GETCHECK, 0, 0) == BST_CHECKED)
+        {
+            EnableWindow(hwndCustomizeModernStartButton, TRUE);
+            EnableWindow(hwndCustomizeClassicStartButton, FALSE);
+            lpStartImageName = MAKEINTRESOURCEW(IDB_STARTPREVIEW);
+        }
+        else
+        {
+            EnableWindow(hwndCustomizeModernStartButton, FALSE);
+            EnableWindow(hwndCustomizeClassicStartButton, TRUE);
+            lpStartImageName = MAKEINTRESOURCEW(IDB_STARTPREVIEW_CLASSIC);
+        }
+        
+         if (lpStartImageName)
+        {
+            if (pPropInfo->hStartBitmap)
+            {
+                DeleteObject(pPropInfo->hStartBitmap);
+            }
+
+            pPropInfo->hStartBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
+                                                  lpStartImageName,
+                                                  IMAGE_BITMAP,
+                                                  0,
+                                                  0,
+                                                  LR_DEFAULTCOLOR);
+            if (pPropInfo->hStartBitmap)
+            {
+                hwndStartBitmap = GetDlgItem(pPropInfo->hStartWnd,
+                                        IDC_TASKBARPROP_STARTMENU_BITMAP);
+                if (hwndStartBitmap)
+                {
+                    SendMessage(hwndStartBitmap,
+                                STM_SETIMAGE,
+                                IMAGE_BITMAP,
+                                (LPARAM)pPropInfo->hStartBitmap);
+                }
+            }
+        }
     }
 
     return bRet;
@@ -113,8 +241,20 @@ OnCreateTaskbarPage(HWND hwnd,
     pPropInfo->hTaskbarWnd = hwnd;
 
     // FIXME: check buttons
+    CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, AdvancedSettings.bShowSeconds ? BST_CHECKED : BST_UNCHECKED);
 
-    UpdateTaskbarBitmap(pPropInfo);
+    UpdateBitmaps(pPropInfo);
+}
+
+static VOID
+OnCreateStartPage(HWND hwnd,
+                    PPROPSHEET_INFO pPropInfo)
+{
+    pPropInfo->hStartWnd = hwnd;
+
+    CheckDlgButton(hwnd, IDC_TASKBARPROP_STARTMENUCLASSIC, 1);    // HACK: This has to be read from registry!
+    
+    UpdateBitmaps(pPropInfo);
 }
 
 INT_PTR CALLBACK
@@ -136,7 +276,7 @@ TaskbarPageProc(HWND hwndDlg,
     switch (uMsg)
     {
         case WM_INITDIALOG:
-            OnCreateTaskbarPage(hwndDlg, (PPROPSHEET_INFO)lParam);
+            OnCreateTaskbarPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
             break;
 
         case WM_COMMAND:
@@ -146,14 +286,20 @@ TaskbarPageProc(HWND hwndDlg,
                 case IDC_TASKBARPROP_HIDE:
                 case IDC_TASKBARPROP_GROUP:
                 case IDC_TASKBARPROP_SHOWQL:
+                case IDC_TASKBARPROP_HIDEICONS:
+                case IDC_TASKBARPROP_CLOCK:
+                case IDC_TASKBARPROP_SECONDS:
                     if (HIWORD(wParam) == BN_CLICKED)
                     {
-                        UpdateTaskbarBitmap(pPropInfo);
+                        UpdateBitmaps(pPropInfo);
 
                         /* Enable the 'Apply' button */
                         PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                     }
                     break;
+                case IDC_TASKBARPROP_ICONCUST:
+                    ShowCustomizeNotifyIcons(hExplorerInstance, hwndDlg);
+                    break;
             }
             break;
 
@@ -167,6 +313,8 @@ TaskbarPageProc(HWND hwndDlg,
                     break;
 
                 case PSN_APPLY:
+                    AdvancedSettings.bShowSeconds = IsDlgButtonChecked(hwndDlg, IDC_TASKBARPROP_SECONDS);
+                    SaveSettingDword(szAdvancedSettingsKey, TEXT("ShowSeconds"), AdvancedSettings.bShowSeconds);
                     break;
             }
 
@@ -178,61 +326,13 @@ TaskbarPageProc(HWND hwndDlg,
             {
                 DeleteObject(pPropInfo->hTaskbarBitmap);
             }
-            break;
-
-HandleDefaultMessage:
-        default:
-            return FALSE;
-    }
-
-    return FALSE;
-}
-
-static INT_PTR CALLBACK
-AdvancedSettingsPageProc(HWND hwndDlg,
-                         UINT uMsg,
-                         WPARAM wParam,
-                         LPARAM lParam)
-{
-    switch (uMsg)
-    {
-        case WM_INITDIALOG:
-            CheckDlgButton(hwndDlg, IDC_TASKBARPROP_SECONDS, AdvancedSettings.bShowSeconds ? BST_CHECKED : BST_UNCHECKED);
-            break;
-
-        case WM_COMMAND:
-            switch (LOWORD(wParam))
+            if (pPropInfo->hTrayBitmap)
             {
-                case IDC_TASKBARPROP_SECONDS:
-                    if (HIWORD(wParam) == BN_CLICKED)
-                    {
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
-                    }
-                    break;
+                DeleteObject(pPropInfo->hTrayBitmap);
             }
             break;
 
-        case WM_NOTIFY:
-        {
-            LPNMHDR pnmh = (LPNMHDR)lParam;
-
-            switch (pnmh->code)
-            {
-                case PSN_SETACTIVE:
-                    break;
-
-                case PSN_APPLY:
-                    AdvancedSettings.bShowSeconds = IsDlgButtonChecked(hwndDlg, IDC_TASKBARPROP_SECONDS);
-                    SaveSettingDword(szAdvancedSettingsKey, TEXT("ShowSeconds"), AdvancedSettings.bShowSeconds);
-                    break;
-            }
-
-            break;
-        }
-
-        case WM_DESTROY:
-            break;
-
+HandleDefaultMessage:
         default:
             return FALSE;
     }
@@ -249,77 +349,19 @@ StartMenuPageProc(HWND hwndDlg,
     switch (uMsg)
     {
         case WM_INITDIALOG:
+            OnCreateStartPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
             break;
-
-        case WM_DESTROY:
-            break;
-
-        case WM_NOTIFY:
-        {
-            LPNMHDR pnmh = (LPNMHDR)lParam;
-
-            switch (pnmh->code)
-            {
-                case PSN_SETACTIVE:
-                    break;
-
-                case PSN_APPLY:
-                    break;
-            }
-
-            break;
-        }
-    }
-
-    return FALSE;
-}
-
-
-static INT_PTR CALLBACK
-NotificationPageProc(HWND hwndDlg,
-                     UINT uMsg,
-                     WPARAM wParam,
-                     LPARAM lParam)
-{
-    switch (uMsg)
-    {
-        case WM_INITDIALOG:
-            break;
-
-        case WM_DESTROY:
-            break;
-
-        case WM_NOTIFY:
+            
+        case WM_COMMAND:
         {
-            LPNMHDR pnmh = (LPNMHDR)lParam;
-
-            switch (pnmh->code)
+            switch (LOWORD(wParam))
             {
-                case PSN_SETACTIVE:
-                    break;
-
-                case PSN_APPLY:
+                case IDC_TASKBARPROP_STARTMENUCLASSICCUST:
+                    ShowCustomizeClassic(hExplorerInstance, hwndDlg);
                     break;
             }
-
             break;
         }
-    }
-
-    return FALSE;
-}
-
-
-static INT_PTR CALLBACK
-ToolbarsPageProc(HWND hwndDlg,
-                 UINT uMsg,
-                 WPARAM wParam,
-                 LPARAM lParam)
-{
-    switch (uMsg)
-    {
-        case WM_INITDIALOG:
-            break;
 
         case WM_DESTROY:
             break;
@@ -344,18 +386,17 @@ ToolbarsPageProc(HWND hwndDlg,
     return FALSE;
 }
 
-
 static VOID
 InitPropSheetPage(PROPSHEETPAGE *psp,
                   WORD idDlg,
                   DLGPROC DlgProc,
                   LPARAM lParam)
 {
-    ZeroMemory(psp, sizeof(PROPSHEETPAGE));
-    psp->dwSize = sizeof(PROPSHEETPAGE);
+    ZeroMemory(psp, sizeof(*psp));
+    psp->dwSize = sizeof(*psp);
     psp->dwFlags = PSP_DEFAULT;
     psp->hInstance = hExplorerInstance;
-    psp->pszTemplate = MAKEINTRESOURCE(idDlg);
+    psp->pszTemplate = MAKEINTRESOURCEW(idDlg);
     psp->lParam = lParam;
     psp->pfnDlgProc = DlgProc;
 }
@@ -364,35 +405,32 @@ InitPropSheetPage(PROPSHEETPAGE *psp,
 VOID
 DisplayTrayProperties(IN HWND hwndOwner)
 {
-    PROPSHEET_INFO propInfo;
+    PROPSHEET_INFO propInfo = {0};
     PROPSHEETHEADER psh;
-    PROPSHEETPAGE psp[5];
+    PROPSHEETPAGE psp[2];
     WCHAR szCaption[256];
 
-    if (!LoadString(hExplorerInstance,
-                    IDS_TASKBAR_STARTMENU_PROP_CAPTION,
-                    szCaption,
-                    sizeof(szCaption) / sizeof(szCaption[0])))
+    if (!LoadStringW(hExplorerInstance,
+                     IDS_TASKBAR_STARTMENU_PROP_CAPTION,
+                     szCaption,
+                     _countof(szCaption)))
     {
         return;
     }
 
-    ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
-    psh.dwSize = sizeof(PROPSHEETHEADER);
+    ZeroMemory(&psh, sizeof(psh));
+    psh.dwSize = sizeof(psh);
     psh.dwFlags =  PSH_PROPSHEETPAGE | PSH_PROPTITLE;
     psh.hwndParent = hwndOwner;
     psh.hInstance = hExplorerInstance;
     psh.hIcon = NULL;
     psh.pszCaption = szCaption;
-    psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
+    psh.nPages = _countof(psp);
     psh.nStartPage = 0;
     psh.ppsp = psp;
 
     InitPropSheetPage(&psp[0], IDD_TASKBARPROP_TASKBAR, TaskbarPageProc, (LPARAM)&propInfo);
     InitPropSheetPage(&psp[1], IDD_TASKBARPROP_STARTMENU, StartMenuPageProc, (LPARAM)&propInfo);
-    InitPropSheetPage(&psp[2], IDD_TASKBARPROP_NOTIFICATION, NotificationPageProc, (LPARAM)&propInfo);
-    InitPropSheetPage(&psp[3], IDD_TASKBARPROP_TOOLBARS, ToolbarsPageProc, (LPARAM)&propInfo);
-    InitPropSheetPage(&psp[4], IDD_TASKBARPROP_ADVANCED, AdvancedSettingsPageProc, (LPARAM)&propInfo);
 
     PropertySheet(&psh);
 }