added code comments and a bit of cleanup

svn path=/trunk/; revision=5669
This commit is contained in:
Martin Fuchs
2003-08-19 09:13:02 +00:00
parent 8ee9da9bb7
commit a355ea3e20
16 changed files with 76 additions and 299 deletions
@@ -29,7 +29,6 @@
#include "utility/utility.h"
#include "utility/shellclasses.h"
#include "explorer.h"
#include "globals.h"
@@ -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
@@ -26,6 +26,8 @@
//
#include "utility/shellclasses.h"
#include "shell/entries.h"
#include "shell/winfs.h"
+2 -1
View File
@@ -64,7 +64,8 @@ TARGET_OBJECTS = \
pane.o \
shellbrowser.o \
desktop.o \
taskbar.o
taskbar.o \
startmenu.o
include $(PATH_TO_TOP)/rules.mak
@@ -28,7 +28,7 @@
#include "../utility/utility.h"
#include "../utility/shellclasses.h"
#include "../globals.h"
#include "../globals.h" // for _prescan_nodes
#include "entries.h"
@@ -85,7 +85,6 @@ public:
struct Directory {
protected:
Directory() : _path(NULL) {}
Directory(void* path) : _path(path) {}
virtual ~Directory() {}
void* _path;
@@ -27,7 +27,6 @@
#include "../utility/utility.h"
#include "../utility/shellclasses.h"
#include "../explorer.h"
#include "../globals.h"
@@ -27,7 +27,6 @@
#include "../utility/utility.h"
#include "../utility/shellclasses.h"
#include "../explorer.h"
#include "../globals.h"
@@ -27,7 +27,6 @@
#include "../utility/utility.h"
#include "../utility/shellclasses.h"
#include "../explorer.h"
#include "../globals.h"
@@ -27,7 +27,6 @@
#include "../utility/utility.h"
#include "../utility/shellclasses.h"
#include "../explorer.h"
#include "../globals.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()
@@ -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();
+4 -4
View File
@@ -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()
@@ -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<const ShellEntry*>(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 "<user name>\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;
}
@@ -26,8 +26,6 @@
//
#include <list>
//#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<Window>
@@ -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<ShellPath> StartMenuFolders;
typedef list<ShellDirectory> StartMenuShellDirs;
// Startmenu window
struct StartMenu : public OwnerDrawParent<Dialog>
{
typedef OwnerDrawParent<Dialog> 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);
};
@@ -46,17 +46,21 @@ typedef set<HWND> 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<typename WND_CLASS, typename INFO_CLASS> struct WindowCreatorInfo
(Window::WINDOWCREATORFUNC) WindowCreatorInfo<WND_CLASS, INFO_CLASS>::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;