diff --git a/reactos/subsys/system/explorer/explorer.cpp b/reactos/subsys/system/explorer/explorer.cpp index 36cbc024ad8..a578f12c11b 100644 --- a/reactos/subsys/system/explorer/explorer.cpp +++ b/reactos/subsys/system/explorer/explorer.cpp @@ -29,7 +29,6 @@ #include "utility/utility.h" -#include "utility/shellclasses.h" #include "explorer.h" #include "globals.h" diff --git a/reactos/subsys/system/explorer/explorer.dsp b/reactos/subsys/system/explorer/explorer.dsp index 2682570d12f..cf096c279f6 100644 --- a/reactos/subsys/system/explorer/explorer.dsp +++ b/reactos/subsys/system/explorer/explorer.dsp @@ -348,6 +348,14 @@ SOURCE=.\res\toolbar.bmp # PROP Default_Filter "" # Begin Source File +SOURCE=.\taskbar\startmenu.cpp +# End Source File +# Begin Source File + +SOURCE=.\taskbar\startmenu.h +# End Source File +# Begin Source File + SOURCE=.\taskbar\taskbar.cpp # End Source File # Begin Source File diff --git a/reactos/subsys/system/explorer/explorer.h b/reactos/subsys/system/explorer/explorer.h index e51ae0d9f8f..2f9bf660906 100644 --- a/reactos/subsys/system/explorer/explorer.h +++ b/reactos/subsys/system/explorer/explorer.h @@ -26,6 +26,8 @@ // +#include "utility/shellclasses.h" + #include "shell/entries.h" #include "shell/winfs.h" diff --git a/reactos/subsys/system/explorer/makefile_rex b/reactos/subsys/system/explorer/makefile_rex index 7f488482ee7..c621a86e3ac 100644 --- a/reactos/subsys/system/explorer/makefile_rex +++ b/reactos/subsys/system/explorer/makefile_rex @@ -64,7 +64,8 @@ TARGET_OBJECTS = \ pane.o \ shellbrowser.o \ desktop.o \ - taskbar.o + taskbar.o \ + startmenu.o include $(PATH_TO_TOP)/rules.mak diff --git a/reactos/subsys/system/explorer/shell/entries.cpp b/reactos/subsys/system/explorer/shell/entries.cpp index 0f9d2b1eeab..f0316fa821c 100644 --- a/reactos/subsys/system/explorer/shell/entries.cpp +++ b/reactos/subsys/system/explorer/shell/entries.cpp @@ -28,7 +28,7 @@ #include "../utility/utility.h" #include "../utility/shellclasses.h" -#include "../globals.h" +#include "../globals.h" // for _prescan_nodes #include "entries.h" diff --git a/reactos/subsys/system/explorer/shell/entries.h b/reactos/subsys/system/explorer/shell/entries.h index a36f3b78916..cd5f38473c5 100644 --- a/reactos/subsys/system/explorer/shell/entries.h +++ b/reactos/subsys/system/explorer/shell/entries.h @@ -85,7 +85,6 @@ public: struct Directory { protected: Directory() : _path(NULL) {} - Directory(void* path) : _path(path) {} virtual ~Directory() {} void* _path; diff --git a/reactos/subsys/system/explorer/shell/filechild.cpp b/reactos/subsys/system/explorer/shell/filechild.cpp index 01f50affe30..69e937c46c6 100644 --- a/reactos/subsys/system/explorer/shell/filechild.cpp +++ b/reactos/subsys/system/explorer/shell/filechild.cpp @@ -27,7 +27,6 @@ #include "../utility/utility.h" -#include "../utility/shellclasses.h" #include "../explorer.h" #include "../globals.h" diff --git a/reactos/subsys/system/explorer/shell/mainframe.cpp b/reactos/subsys/system/explorer/shell/mainframe.cpp index 14059353ae0..e420cbee336 100644 --- a/reactos/subsys/system/explorer/shell/mainframe.cpp +++ b/reactos/subsys/system/explorer/shell/mainframe.cpp @@ -27,7 +27,6 @@ #include "../utility/utility.h" -#include "../utility/shellclasses.h" #include "../explorer.h" #include "../globals.h" diff --git a/reactos/subsys/system/explorer/shell/pane.cpp b/reactos/subsys/system/explorer/shell/pane.cpp index b0ff1566189..3e2a98b4f85 100644 --- a/reactos/subsys/system/explorer/shell/pane.cpp +++ b/reactos/subsys/system/explorer/shell/pane.cpp @@ -27,7 +27,6 @@ #include "../utility/utility.h" -#include "../utility/shellclasses.h" #include "../explorer.h" #include "../globals.h" diff --git a/reactos/subsys/system/explorer/shell/shellbrowser.cpp b/reactos/subsys/system/explorer/shell/shellbrowser.cpp index d5856216472..a821ee37e27 100644 --- a/reactos/subsys/system/explorer/shell/shellbrowser.cpp +++ b/reactos/subsys/system/explorer/shell/shellbrowser.cpp @@ -27,7 +27,6 @@ #include "../utility/utility.h" -#include "../utility/shellclasses.h" #include "../explorer.h" #include "../globals.h" diff --git a/reactos/subsys/system/explorer/shell/shellfs.h b/reactos/subsys/system/explorer/shell/shellfs.h index c9ffd9ab1da..1177fe4502c 100644 --- a/reactos/subsys/system/explorer/shell/shellfs.h +++ b/reactos/subsys/system/explorer/shell/shellfs.h @@ -58,11 +58,11 @@ struct ShellDirectory : public ShellEntry, public Directory ShellDirectory(ShellDirectory* parent, IShellFolder* shell_root, LPITEMIDLIST shell_path, HWND hwnd) : ShellEntry(parent, shell_path), - Directory(shell_root), _folder(shell_root), _hwnd(hwnd) { shell_root->AddRef(); + _path = shell_root; } ~ShellDirectory() diff --git a/reactos/subsys/system/explorer/shell/unixfs.h b/reactos/subsys/system/explorer/shell/unixfs.h index 09f8c2ea146..4a5b99cfd38 100644 --- a/reactos/subsys/system/explorer/shell/unixfs.h +++ b/reactos/subsys/system/explorer/shell/unixfs.h @@ -41,15 +41,21 @@ protected: struct UnixDirectory : public UnixEntry, public Directory { UnixDirectory(LPCTSTR root_path) - : UnixEntry(), - Directory(_tcsdup(root_path)) + : UnixEntry() { + _path = _tcsdup(root_path); } UnixDirectory(UnixDirectory* parent, LPCTSTR path) : UnixEntry(parent), - Directory(_tcsdup(path)) { + _path = _tcsdup(path); + } + + ~UnixDirectory() + { + free(_path); + _path = NULL; } virtual void read_directory(); diff --git a/reactos/subsys/system/explorer/shell/winfs.h b/reactos/subsys/system/explorer/shell/winfs.h index 6b694a3f538..c0a3d639cf8 100644 --- a/reactos/subsys/system/explorer/shell/winfs.h +++ b/reactos/subsys/system/explorer/shell/winfs.h @@ -39,15 +39,15 @@ protected: struct WinDirectory : public WinEntry, public Directory { WinDirectory(LPCTSTR root_path) - : WinEntry(), - Directory(_tcsdup(root_path)) + : WinEntry() { + _path = _tcsdup(root_path); } WinDirectory(WinDirectory* parent, LPCTSTR path) - : WinEntry(parent), - Directory(_tcsdup(path)) + : WinEntry(parent) { + _path = _tcsdup(path); } ~WinDirectory() diff --git a/reactos/subsys/system/explorer/taskbar/taskbar.cpp b/reactos/subsys/system/explorer/taskbar/taskbar.cpp index 6896805ef98..d74c0e412ad 100644 --- a/reactos/subsys/system/explorer/taskbar/taskbar.cpp +++ b/reactos/subsys/system/explorer/taskbar/taskbar.cpp @@ -27,7 +27,6 @@ #include "../utility/utility.h" -#include "../utility/shellclasses.h" #include "../explorer.h" #include "../globals.h" @@ -35,22 +34,7 @@ #include "../explorer_intres.h" #include "taskbar.h" - - -#define IDC_START 0x1000 -#define IDC_LOGOFF 0x1001 -#define IDC_SHUTDOWN 0x1002 -#define IDC_LAUNCH 0x1003 -#define IDC_START_HELP 0x1004 -#define IDC_SEARCH 0x1005 -#define IDC_SETTINGS 0x1006 -#define IDC_DOCUMENTS 0x1007 -#define IDC_FAVORITES 0x1008 -#define IDC_PROGRAMS 0x1009 -#define IDC_EXPLORE 0x100A - -#define IDC_FIRST_APP 0x2000 -#define IDC_FIRST_MENU 0x3000 +#include "startmenu.h" HWND InitializeExplorerBar(HINSTANCE hInstance) @@ -77,7 +61,6 @@ DesktopBar::DesktopBar(HWND hwnd) : super(hwnd) { _hwndTaskBar = 0; - _hwndStartMenu = 0; } DesktopBar::~DesktopBar() @@ -110,19 +93,12 @@ LRESULT DesktopBar::Init(LPCREATESTRUCT pcs) } -void DesktopBar::create_startmenu() -{ - WindowRect my_pos(_hwnd); - - _hwndStartMenu = StartMenuRoot::Create(my_pos.left, my_pos.top-4, _hwnd); -} - - LRESULT DesktopBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) { switch(nmsg) { case WM_NCHITTEST: { LRESULT res = super::WndProc(nmsg, wparam, lparam); + if (res>=HTSIZEFIRST && res<=HTSIZELAST) { #ifdef TASKBAR_AT_TOP if (res == HTBOTTOM) // enable vertical resizing at the lower border @@ -167,9 +143,12 @@ LRESULT DesktopBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) int DesktopBar::Command(int id, int code) { switch(id) { - case IDC_START: - create_startmenu(); - break; + case IDC_START: { + // create Startmenu + WindowRect my_pos(_hwnd); + + StartMenuRoot::Create(my_pos.left, my_pos.top-4, _hwnd); + break;} } return 0; @@ -478,189 +457,3 @@ TaskBarMap::iterator TaskBarMap::find_id(int id) return end(); } - - -BtnWindowClass StartMenu::s_wcStartMenu(CLASSNAME_STARTMENU); - -StartMenu::StartMenu(HWND hwnd) - : super(hwnd) -{ - _next_id = IDC_FIRST_MENU; -} - -StartMenu::StartMenu(HWND hwnd, const StartMenuFolders& info) - : super(hwnd) -{ - for(StartMenuFolders::const_iterator it=info.begin(); it!=info.end(); ++it) - _dirs.push_back(ShellDirectory(Desktop(), *it, _hwnd)); -} - - -/* -HWND StartMenu::Create(int x, int y, HWND hwndParent) -{ - return Window::Create(WINDOW_CREATOR(StartMenu), NULL, s_wcStartMenu, TITLE_STARTMENU, - WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE, x, y, STARTMENU_WIDTH, 4, hwndParent); -} -*/ - -HWND StartMenu::Create(int x, int y, const StartMenuFolders& folders, HWND hwndParent) -{ - return Window::Create(WINDOW_CREATOR_INFO(StartMenu,StartMenuFolders), &folders, 0, s_wcStartMenu, NULL, - WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE, x, y, STARTMENU_WIDTH, 4, hwndParent); -} - - -LRESULT StartMenu::Init(LPCREATESTRUCT pcs) -{ - if (super::Init(pcs)) - return 1; - - WaitCursor wait; - - for(StartMenuShellDirs::iterator it=_dirs.begin(); it!=_dirs.end(); ++it) { - ShellDirectory& dir = *it; - - dir.smart_scan(); - - AddShellEntries(dir); - } - - return 0; -} - -void StartMenu::AddShellEntries(const ShellDirectory& dir, bool subfolders) -{ - for(const Entry*entry=dir._down; entry; entry=entry->_next) { - if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) - continue; - - HICON hIcon = entry->_hicon; - - if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - if (!subfolders) - continue; - - hIcon = SmallIcon(IDI_EXPLORER); - } - - AddButton(dir._folder.get_name(&*static_cast(entry)->_pidl).c_str(), hIcon); - } -} - -LRESULT StartMenu::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) -{ -/*@@ - switch(nmsg) { - default: - return super::WndProc(nmsg, wparam, lparam); - } - - return 0; -*/ return super::WndProc(nmsg, wparam, lparam); -} - -int StartMenu::Command(int id, int code) -{ - switch(id) { - case IDCANCEL: - DestroyWindow(_hwnd); - break; - - default: - return super::Command(id, code); - } - - return 0; -} - -void StartMenu::AddButton(LPCTSTR text, HICON hIcon, UINT id) -{ - if (id == (UINT)-1) - id = ++_next_id; - - WindowRect rect(_hwnd); - - rect.top -= STARTMENU_LINE_HEIGHT; - - if (rect.top < 0) { - rect.top += STARTMENU_LINE_HEIGHT; - rect.bottom += STARTMENU_LINE_HEIGHT; - } - - MoveWindow(_hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); - - StartMenuButton(_hwnd, rect.bottom-rect.top-STARTMENU_LINE_HEIGHT-4, text, id, hIcon); -} - - -StartMenuRoot::StartMenuRoot(HWND hwnd) - : super(hwnd) -{ -} - -HWND StartMenuRoot::Create(int x, int y, HWND hwndParent) -{ - return Window::Create(WINDOW_CREATOR(StartMenuRoot), 0, s_wcStartMenu, TITLE_STARTMENU, - WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE, x, y, STARTMENU_WIDTH, 4, hwndParent); -} - -LRESULT StartMenuRoot::Init(LPCREATESTRUCT pcs) -{ - if (super::Init(pcs)) - return 1; - - WaitCursor wait; - - // insert start menu entries links from "All Users\Start Menu" and "\Start Menu" - ShellDirectory cmn_startmenu(Desktop(), SpecialFolder(CSIDL_COMMON_STARTMENU, _hwnd), _hwnd); - cmn_startmenu.read_directory(); - AddShellEntries(cmn_startmenu, false); - - ShellDirectory usr_startmenu(Desktop(), SpecialFolder(CSIDL_STARTMENU, _hwnd), _hwnd); - usr_startmenu.read_directory(); - AddShellEntries(usr_startmenu, false); - - // insert hard coded start entries - //AddButton(ResString(IDS_PROGRAMS),0, IDC_PROGRAMS); - AddButton(ResString(IDS_EXPLORE), SmallIcon(IDI_EXPLORER), IDC_EXPLORE); - AddButton(ResString(IDS_FAVORITES), 0, IDC_FAVORITES); - AddButton(ResString(IDS_DOCUMENTS), 0, IDC_DOCUMENTS); - AddButton(ResString(IDS_SETTINGS), 0, IDC_SETTINGS); - AddButton(ResString(IDS_SEARCH), 0, IDC_SEARCH); - AddButton(ResString(IDS_START_HELP),0, IDC_START_HELP); - AddButton(ResString(IDS_LAUNCH), 0, IDC_LAUNCH); - AddButton(ResString(IDS_SHUTDOWN), SmallIcon(IDI_LOGOFF), IDC_SHUTDOWN); - AddButton(ResString(IDS_LOGOFF), SmallIcon(IDI_LOGOFF), IDC_LOGOFF); - - - //TEST: open programs menu folder - StartMenuFolders prg_folders; - - prg_folders.push_back(SpecialFolder(CSIDL_COMMON_PROGRAMS, _hwnd)); - prg_folders.push_back(SpecialFolder(CSIDL_PROGRAMS, _hwnd)); - - WindowRect my_pos(_hwnd); - StartMenu::Create(my_pos.right, my_pos.top+STARTMENU_HEIGHT-4, prg_folders, _hwnd); - - - return 0; -} - -int StartMenuRoot::Command(int id, int code) -{ - switch(id) { - case IDC_LOGOFF: - DestroyWindow(GetParent(_hwnd)); //TODO: show dialog and ask for acknowledge - break; - - case IDC_SHUTDOWN: - DestroyWindow(GetParent(_hwnd)); //TODO: show dialog box and shut down system - break; - - default: - return super::Command(id, code); - } - - return 0; -} diff --git a/reactos/subsys/system/explorer/taskbar/taskbar.h b/reactos/subsys/system/explorer/taskbar/taskbar.h index afbd1679c25..aaafaabe4f4 100644 --- a/reactos/subsys/system/explorer/taskbar/taskbar.h +++ b/reactos/subsys/system/explorer/taskbar/taskbar.h @@ -26,8 +26,6 @@ // -#include - //#include "shellhook.h" @@ -49,8 +47,21 @@ #define CLASSNAME_TASKBAR _T("MSTaskSwWClass") #define TITLE_TASKBAR _T("Running Applications") -#define CLASSNAME_STARTMENU _T("ReactosStartmenuClass") -#define TITLE_STARTMENU _T("Start Menu") + +#define IDC_START 0x1000 +#define IDC_LOGOFF 0x1001 +#define IDC_SHUTDOWN 0x1002 +#define IDC_LAUNCH 0x1003 +#define IDC_START_HELP 0x1004 +#define IDC_SEARCH 0x1005 +#define IDC_SETTINGS 0x1006 +#define IDC_DOCUMENTS 0x1007 +#define IDC_FAVORITES 0x1008 +#define IDC_PROGRAMS 0x1009 +#define IDC_EXPLORE 0x100A + +#define IDC_FIRST_APP 0x2000 +#define IDC_FIRST_MENU 0x3000 struct DesktopBar : public OwnerDrawParent @@ -65,10 +76,7 @@ protected: LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); int Command(int id, int code); - void create_startmenu(); - HWND _hwndTaskBar; - HWND _hwndStartMenu; }; @@ -120,61 +128,3 @@ protected: void Refresh(); }; - - - // Startmenu button -struct StartMenuButton : public Button -{ - StartMenuButton(HWND parent, int y, LPCTSTR text, - UINT id, HICON hIcon, DWORD style=WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_OWNERDRAW, DWORD exStyle=0) - : Button(parent, text, 2, y, STARTMENU_WIDTH-4, STARTMENU_LINE_HEIGHT, id, style, exStyle) - { - *new StartmenuEntry(_hwnd, hIcon); - - SetWindowFont(_hwnd, GetStockFont(DEFAULT_GUI_FONT), FALSE); - } -}; - - -typedef list StartMenuFolders; -typedef list StartMenuShellDirs; - - // Startmenu window -struct StartMenu : public OwnerDrawParent -{ - typedef OwnerDrawParent super; - - StartMenu(HWND hwnd); - StartMenu(HWND hwnd, const StartMenuFolders& info); - - static HWND Create(int x, int y, HWND hwndParent=0); - static HWND Create(int x, int y, const StartMenuFolders&, HWND hwndParent=0); - -protected: - int _next_id; - StartMenuShellDirs _dirs; - - static BtnWindowClass s_wcStartMenu; - - LRESULT Init(LPCREATESTRUCT pcs); - LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); - int Command(int id, int code); - - void AddButton(LPCTSTR text, HICON hIcon=0, UINT id=(UINT)-1); - void AddShellEntries(const ShellDirectory& dir, bool subfolders=true); -}; - - - // Startmenu root window -struct StartMenuRoot : public StartMenu -{ - typedef StartMenu super; - - StartMenuRoot(HWND hwnd); - - static HWND Create(int x, int y, HWND hwndParent=0); - -protected: - LRESULT Init(LPCREATESTRUCT pcs); - int Command(int id, int code); -}; diff --git a/reactos/subsys/system/explorer/utility/window.h b/reactos/subsys/system/explorer/utility/window.h index 29d7945e35f..e8c4dbf8e7e 100644 --- a/reactos/subsys/system/explorer/utility/window.h +++ b/reactos/subsys/system/explorer/utility/window.h @@ -46,17 +46,21 @@ typedef set WindowSet; /** Class Window is the base class for several C++ window wrapper classes. + Window objects are allocated from the heap. They are automatically freed + when the window gets destroyed. */ struct Window { Window(HWND hwnd) : _hwnd(hwnd) { + // store "this" pointer as user data SetWindowLong(hwnd, GWL_USERDATA, (LONG)this); } virtual ~Window() { + // empty user data field SetWindowLong(_hwnd, GWL_USERDATA, 0); } @@ -97,10 +101,10 @@ protected: HWND _hwnd; - virtual LRESULT Init(LPCREATESTRUCT pcs); + virtual LRESULT Init(LPCREATESTRUCT pcs); // WM_CREATE processing virtual LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); - virtual int Command(int id, int code); - virtual int Notify(int id, NMHDR* pnmh); + virtual int Command(int id, int code); // WM_COMMAND processing + virtual int Notify(int id, NMHDR* pnmh); // WM_NOTIFY processing static const void* s_new_info; //TODO: protect for multithreaded access @@ -115,6 +119,12 @@ protected: }; + /** + SubclassedWindow is used to wrap already existing window handles + into C++ Window objects. To construct a object, use the "new" operator + to put it in the heap. It is automatically freed, when the window + gets destroyed. + */ struct SubclassedWindow : public Window { typedef Window super; @@ -152,6 +162,13 @@ template struct WindowCreatorInfo (Window::WINDOWCREATORFUNC) WindowCreatorInfo::window_creator + /** + WindowClass is a neat wrapper for RegisterClassEx(). + Just construct a WindowClass object, override the attributes you want + to change, then call Register() or simply request the ATOM value to + register the window class. You don't have to worry calling Register() + more than once. It checks if, the class has already been registered. + */ struct WindowClass : public WNDCLASSEX { WindowClass(LPCTSTR classname, UINT style=0, WNDPROC wndproc=Window::WindowWndProc); @@ -199,6 +216,7 @@ struct IconWindowClass : public WindowClass #define COLOR_SPLITBAR LTGRAY_BRUSH + /// menu info structure for MDI child windows struct MenuInfo { HMENU _hMenuView; @@ -240,6 +258,11 @@ protected: }; + /** + PreTranslateWindow is used to register windows to be called by Window::pretranslate_msg(). + This way you get WM_TRANSLATE_MSG messages before the message loop dispatches messages. + You can then for example use TranslateAccelerator() to implement key shortcuts. + */ struct PreTranslateWindow : public Window { typedef Window super;