merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / subsys / system / explorer / taskbar / startmenu.cpp
index 417ae5f..2a00ded 100644 (file)
 #include "../dialogs/settings.h"
 
 
+#define        SHELLPATH_CONTROL_PANEL         TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}")
+#define        SHELLPATH_PRINTERS                      TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}")
+#define        SHELLPATH_NET_CONNECTIONS       TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}")
+
+
 StartMenu::StartMenu(HWND hwnd)
  :     super(hwnd)
 {
@@ -364,7 +369,7 @@ LRESULT StartMenu::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
 
                        int new_id = ButtonHitTest(pt);
 
-                       if (new_id != _selected_id)
+                       if (new_id > 0 && new_id != _selected_id)
                                SelectButton(new_id);
 
                        _last_mouse_pos = lparam;
@@ -425,9 +430,31 @@ LRESULT StartMenu::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
                break;
 
          case PM_SELECT_ENTRY:
-               SelectButtonIndex(0, wparam?true:false);
+               SelectButtonIndex(0, wparam!=0);
                break;
 
+#ifdef _LIGHT_STARTMENU
+         case WM_CONTEXTMENU: {
+               Point screen_pt(lparam), clnt_pt=screen_pt;
+               ScreenToClient(_hwnd, &clnt_pt);
+
+               int id = ButtonHitTest(clnt_pt);
+
+               if (id) {
+                       StartMenuEntry& sme = _entries[id];
+
+                       for(ShellEntrySet::iterator it=sme._entries.begin(); it!=sme._entries.end(); ++it) {
+                               Entry* entry = *it;
+
+                               if (entry) {
+                                       CHECKERROR(entry->do_context_menu(_hwnd, screen_pt, _cm_ifs));  // may close start menu because of focus loss
+                                       break;  ///@todo handle context menu for more than one entry
+                               }
+                       }
+               }
+               break;}
+#endif
+
          default: def:
                return super::WndProc(nmsg, wparam, lparam);
        }
@@ -468,7 +495,7 @@ int StartMenu::ButtonHitTest(POINT pt)
 
 void StartMenu::InvalidateSelection()
 {
-       if (!_selected_id)
+       if (_selected_id <= 0)
                return;
 
        ClientRect clnt(_hwnd);
@@ -983,7 +1010,7 @@ ShellEntryMap::iterator StartMenu::AddEntry(const String& title, ICON_ID icon_id
                for(ShellEntryMap::iterator it=_entries.begin(); it!=_entries.end(); ++it) {
                        StartMenuEntry& sme = it->second;
 
-                       if (sme._title == title)        ///@todo speed up by using a map indexed by name
+                       if (!_tcsicmp(sme._title, title))       ///@todo speed up by using a map indexed by name
                                for(ShellEntrySet::iterator it2=sme._entries.begin(); it2!=sme._entries.end(); ++it2) {
                                        if ((*it2)->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
                                                 // merge the new shell entry with the existing of the same name
@@ -1232,7 +1259,7 @@ void StartMenu::ActivateEntry(int id, const ShellEntrySet& entries)
                        SHELLEXECUTEINFO shexinfo;
 
                        shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
-                       shexinfo.fMask = SEE_MASK_INVOKEIDLIST; // SEE_MASK_IDLIST is also possible.
+                       shexinfo.fMask = SEE_MASK_IDLIST;       // SEE_MASK_INVOKEIDLIST is also possible.
                        shexinfo.hwnd = hparent;
                        shexinfo.lpVerb = NULL;
                        shexinfo.lpFile = NULL;
@@ -1668,6 +1695,9 @@ LRESULT   StartMenuRoot::Init(LPCREATESTRUCT pcs)
                AddButton(ResString(IDS_SHUTDOWN),      ICID_LOGOFF, false, IDC_SHUTDOWN);
 
 
+       AddButton(ResString(IDS_TERMINATE),     ICID_LOGOFF, false, IDC_TERMINATE);
+
+
 #ifdef __MINGW32__
        RegCloseKey(hkeyAdv);
        RegCloseKey(hkey);
@@ -1808,9 +1838,11 @@ int StartMenuHandler::Command(int id, int code)
                break;
 
          case IDC_LOGOFF:
-               /* The shell32 Dialog prompts about some system setting change. This is not what we want to display here.
                CloseStartMenu(id);
-               ShowRestartDialog(g_Globals._hwndDesktopBar, EWX_LOGOFF);*/
+               ShowLogoffDialog(g_Globals._hwndDesktopBar);
+               break;
+
+         case IDC_TERMINATE:
                DestroyWindow(GetParent(_hwnd));
                break;
 
@@ -1827,32 +1859,82 @@ int StartMenuHandler::Command(int id, int code)
                ExplorerPropertySheet(g_Globals._hwndDesktopBar);
                break;
 
+         case IDC_CONTROL_PANEL: {
+               CloseStartMenu(id);
+#ifndef ROSSHELL
+#ifndef _NO_MDI
+               XMLPos explorer_options = g_Globals.get_cfg("general/explorer");
+               bool mdi = XMLBool(explorer_options, "mdi", true);
+
+               if (mdi)
+                       MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
+               else
+#endif
+                       SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
+#else
+               launch_file(_hwnd, SHELLPATH_CONTROL_PANEL);
+#endif
+               break;}
+
          case IDC_SETTINGS_MENU:
                CreateSubmenu(id, CSIDL_CONTROLS, ResString(IDS_SETTINGS_MENU));
                break;
 
-         case IDC_PRINTERS:
+         case IDC_PRINTERS: {
+               CloseStartMenu(id);
+
+#ifndef ROSSHELL
 #ifdef _ROS_   // to be removed when printer folder will be implemented
                MessageBox(0, TEXT("printer folder not yet implemented in SHELL32"), ResString(IDS_TITLE), MB_OK);
 #else
-               CreateSubmenu(id, CSIDL_PRINTERS, CSIDL_PRINTHOOD, ResString(IDS_PRINTERS));
+#ifndef _NO_MDI
+               XMLPos explorer_options = g_Globals.get_cfg("general/explorer");
+               bool mdi = XMLBool(explorer_options, "mdi", true);
+
+               if (mdi)
+                       MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
+               else
 #endif
-               break;
+                       SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
+#endif
+#else
+               launch_file(_hwnd, SHELLPATH_PRINTERS);
+#endif
+               break;}
 
-         case IDC_CONTROL_PANEL:
-               CloseStartMenu(id);
-               //@@SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
+         case IDC_PRINTERS_MENU:
+               CreateSubmenu(id, CSIDL_PRINTERS, CSIDL_PRINTHOOD, ResString(IDS_PRINTERS));
+/*             StartMenuFolders new_folders;
+
+               try {
+                       new_folders.push_back(ShellPath(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}")));
+               } catch(COMException&) {
+               }
+
+               CreateSubmenu(id, new_folders, ResString(IDS_PRINTERS));*/
                break;
 
          case IDC_ADMIN:
+#ifndef ROSSHELL
                CreateSubmenu(id, CSIDL_COMMON_ADMINTOOLS, CSIDL_ADMINTOOLS, ResString(IDS_ADMIN));
+               //CloseStartMenu(id);
+               //MainFrame::Create(SpecialFolderPath(CSIDL_COMMON_ADMINTOOLS, _hwnd), OWM_PIDL);
+#else
+               launch_file(_hwnd, SpecialFolderFSPath(CSIDL_COMMON_ADMINTOOLS, _hwnd));
+#endif
                break;
 
          case IDC_CONNECTIONS:
+#ifndef ROSSHELL
 #ifdef _ROS_   // to be removed when RAS will be implemented
                MessageBox(0, TEXT("RAS folder not yet implemented in SHELL32"), ResString(IDS_TITLE), MB_OK);
 #else
                CreateSubmenu(id, CSIDL_CONNECTIONS, ResString(IDS_CONNECTIONS));
+               //CloseStartMenu(id);
+               //MainFrame::Create(SpecialFolderPath(CSIDL_CONNECTIONS, _hwnd), OWM_PIDL);
+#endif
+#else
+               launch_file(_hwnd, SHELLPATH_NET_CONNECTIONS);
 #endif
                break;
 
@@ -1868,7 +1950,7 @@ int StartMenuHandler::Command(int id, int code)
                break;
 
          case IDC_DRIVES:
-               ///@todo exclude removeable drives
+               ///@todo exclude removable drives
                CreateSubmenu(id, CSIDL_DRIVES, ResString(IDS_DRIVES));
                break;
 
@@ -1930,7 +2012,6 @@ void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner)
         // Show "Run..." dialog
        if (RunFileDlg) {
 #ifndef _ROS_ /* FIXME: our shell32 always expects Ansi strings */
-#define        W_VER_NT 0
                if ((HIWORD(GetVersion())>>14) == W_VER_NT) {
                        WCHAR wTitle[40], wText[256];
 
@@ -1945,24 +2026,29 @@ void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner)
        }
 }
 
-void StartMenuHandler::ShowRestartDialog(HWND hwndOwner, UINT flags)
+void StartMenuHandler::ShowLogoffDialog(HWND hwndOwner)
 {
-       static DynamicFct<RESTARTWINDOWSDLG> RestartDlg(TEXT("SHELL32"), 59);
+       static DynamicFct<LOGOFFWINDOWSDIALOG> LogoffWindowsDialog(TEXT("SHELL32"), 54);
+//     static DynamicFct<RESTARTWINDOWSDLG> RestartDialog(TEXT("SHELL32"), 59);
 
-       if (RestartDlg)
-               (*RestartDlg)(hwndOwner, (LPWSTR)L"You selected <Log Off>.\n\n", flags);        ///@todo ANSI string conversion if needed
+       if (LogoffWindowsDialog)
+               (*LogoffWindowsDialog)(0);
+/* The RestartDialog function prompts about some system setting change. This is not what we want to display here.
+       else if (RestartDialog)
+               return (*RestartDialog)(hwndOwner, (LPWSTR)L"You selected <Log Off>.\n\n", EWX_LOGOFF) == 1;    ///@todo ANSI string conversion if needed
+*/
        else
-               MessageBox(hwndOwner, TEXT("RestartDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE), MB_OK);
+               MessageBox(hwndOwner, TEXT("LogoffWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE), MB_OK);
 }
 
 void ShowExitWindowsDialog(HWND hwndOwner)
 {
-       static DynamicFct<EXITWINDOWSDLG> ExitWindowsDlg(TEXT("SHELL32"), 60);
+       static DynamicFct<EXITWINDOWSDLG> ExitWindowsDialog(TEXT("SHELL32"), 60);
 
-       if (ExitWindowsDlg)
-               (*ExitWindowsDlg)(hwndOwner);
+       if (ExitWindowsDialog)
+               (*ExitWindowsDialog)(hwndOwner);
        else
-               MessageBox(hwndOwner, TEXT("ExitWindowsDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE), MB_OK);
+               MessageBox(hwndOwner, TEXT("ExitWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE), MB_OK);
 }
 
 
@@ -1970,16 +2056,11 @@ void SettingsMenu::AddEntries()
 {
        super::AddEntries();
 
-#ifndef __MINGW32__    // SHRestricted() missing in MinGW (as of 29.10.2003)
-       if (!g_Globals._SHRestricted || !SHRestricted(REST_NOCONTROLPANEL))
-#endif
-               AddButton(ResString(IDS_CONTROL_PANEL), ICID_CONFIG, false, IDC_CONTROL_PANEL);
-
 #ifdef _ROS_   // to be removed when printer/network will be implemented
-       AddButton(ResString(IDS_PRINTERS),                      ICID_PRINTER, false, IDC_PRINTERS);
+       AddButton(ResString(IDS_PRINTERS),                      ICID_PRINTER, false, IDC_PRINTERS_MENU);
        AddButton(ResString(IDS_CONNECTIONS),           ICID_NETWORK, false, IDC_CONNECTIONS);
 #else
-       AddButton(ResString(IDS_PRINTERS),                      ICID_PRINTER, true, IDC_PRINTERS);
+       AddButton(ResString(IDS_PRINTERS),                      ICID_PRINTER, true, IDC_PRINTERS_MENU);
        AddButton(ResString(IDS_CONNECTIONS),           ICID_NETWORK, true, IDC_CONNECTIONS);
 #endif
        AddButton(ResString(IDS_ADMIN),                         ICID_CONFIG, true, IDC_ADMIN);
@@ -1990,6 +2071,13 @@ void SettingsMenu::AddEntries()
                AddButton(ResString(IDS_SETTINGS_MENU), ICID_CONFIG, true, IDC_SETTINGS_MENU);
 
        AddButton(ResString(IDS_DESKTOPBAR_SETTINGS), ICID_CONFIG, false, ID_DESKTOPBAR_SETTINGS);
+
+       AddButton(ResString(IDS_PRINTERS),                      ICID_PRINTER, false, IDC_PRINTERS);
+
+#ifndef __MINGW32__    // SHRestricted() missing in MinGW (as of 29.10.2003)
+       if (!g_Globals._SHRestricted || !SHRestricted(REST_NOCONTROLPANEL))
+#endif
+               AddButton(ResString(IDS_CONTROL_PANEL), ICID_CONFIG, false, IDC_CONTROL_PANEL);
 }
 
 void BrowseMenu::AddEntries()
@@ -2091,8 +2179,11 @@ int FavoritesMenu::Command(int id, int code)
                        Bookmark& bookmark = *node._pbookmark;
 
                        String url = bookmark._url;
+                       HWND hparent = GetParent(_hwnd);
+
                        CloseStartMenu(id);
-                       launch_file(GetParent(_hwnd), url, SW_SHOWNORMAL);
+
+                       launch_file(hparent, url, SW_SHOWNORMAL);
                }
 
                return 0;