mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 17:44:45 +00:00
SubclassedWindow class for wrapping subclassed windows
svn path=/trunk/; revision=5531
This commit is contained in:
parent
ab7f9064f1
commit
417dffd0c4
9 changed files with 123 additions and 117 deletions
|
@ -117,7 +117,7 @@ LINK32=link.cmd
|
|||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "."
|
||||
# PROP Output_Dir "URelease"
|
||||
# PROP Intermediate_Dir "URelease"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 119
|
||||
#define _APS_NEXT_RESOURCE_VALUE 120
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
|
|
|
@ -120,25 +120,16 @@ FileChildWindow::FileChildWindow(HWND hwnd, const FileChildWndInfo& info)
|
|||
_root._entry->_data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
|
||||
_left._treePane = true;
|
||||
_left._visible_cols = 0;
|
||||
|
||||
_left._root = _root._entry;
|
||||
_right._root = NULL;
|
||||
|
||||
_right._treePane = false;
|
||||
_right._visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
|
||||
_left_hwnd = *(_left=new Pane(_hwnd, IDW_TREE_LEFT, IDW_HEADER_LEFT, _root._entry, true, 0));
|
||||
_right_hwnd = *(_right=new Pane(_hwnd, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, NULL, false, COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS));
|
||||
|
||||
_sortOrder = SORT_NAME;
|
||||
_header_wdths_ok = false;
|
||||
|
||||
_left_hwnd = _left.create(_hwnd, IDW_TREE_LEFT, IDW_HEADER_LEFT);
|
||||
_right_hwnd = _right.create(_hwnd, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
|
||||
|
||||
set_curdir(entry, hwnd);
|
||||
|
||||
int idx = ListBox_FindItemData(_left._hwnd, ListBox_GetCurSel(_left._hwnd), _left._cur);
|
||||
ListBox_SetCurSel(_left._hwnd, idx);
|
||||
int idx = ListBox_FindItemData(_left_hwnd, ListBox_GetCurSel(_left_hwnd), _left->_cur);
|
||||
ListBox_SetCurSel(_left_hwnd, idx);
|
||||
|
||||
//TODO: scroll to visibility
|
||||
|
||||
|
@ -153,18 +144,18 @@ void FileChildWindow::set_curdir(Entry* entry, HWND hwnd)
|
|||
{
|
||||
_path[0] = TEXT('\0');
|
||||
|
||||
_left._cur = entry;
|
||||
_right._root = entry&&entry->_down? entry->_down: entry;
|
||||
_right._cur = entry;
|
||||
_left->_cur = entry;
|
||||
_right->_root = entry&&entry->_down? entry->_down: entry;
|
||||
_right->_cur = entry;
|
||||
|
||||
if (entry) {
|
||||
if (!entry->_scanned)
|
||||
scan_entry(entry, hwnd);
|
||||
else {
|
||||
ListBox_ResetContent(_right._hwnd);
|
||||
_right.insert_entries(entry->_down, -1);
|
||||
_right.calc_widths(false);
|
||||
_right.set_header();
|
||||
ListBox_ResetContent(_right_hwnd);
|
||||
_right->insert_entries(entry->_down, -1);
|
||||
_right->calc_widths(false);
|
||||
_right->set_header();
|
||||
}
|
||||
|
||||
entry->get_path(_path);
|
||||
|
@ -203,16 +194,16 @@ bool FileChildWindow::expand_entry(Entry* dir)
|
|||
if (!(p->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
return FALSE;
|
||||
|
||||
idx = ListBox_FindItemData(_left._hwnd, 0, dir);
|
||||
idx = ListBox_FindItemData(_left_hwnd, 0, dir);
|
||||
|
||||
dir->_expanded = true;
|
||||
|
||||
// insert entries in left pane
|
||||
_left.insert_entries(p, idx);
|
||||
_left->insert_entries(p, idx);
|
||||
|
||||
if (!_header_wdths_ok) {
|
||||
if (_left.calc_widths(false)) {
|
||||
_left.set_header();
|
||||
if (_left->calc_widths(false)) {
|
||||
_left->set_header();
|
||||
|
||||
_header_wdths_ok = true;
|
||||
}
|
||||
|
@ -224,24 +215,24 @@ bool FileChildWindow::expand_entry(Entry* dir)
|
|||
|
||||
void FileChildWindow::collapse_entry(Pane* pane, Entry* dir)
|
||||
{
|
||||
int idx = ListBox_FindItemData(pane->_hwnd, 0, dir);
|
||||
int idx = ListBox_FindItemData(*pane, 0, dir);
|
||||
|
||||
SendMessage(pane->_hwnd, WM_SETREDRAW, FALSE, 0); //ShowWindow(pane->_hwnd, SW_HIDE);
|
||||
SendMessage(*pane, WM_SETREDRAW, FALSE, 0); //ShowWindow(*pane, SW_HIDE);
|
||||
|
||||
// hide sub entries
|
||||
for(;;) {
|
||||
LRESULT res = ListBox_GetItemData(pane->_hwnd, idx+1);
|
||||
LRESULT res = ListBox_GetItemData(*pane, idx+1);
|
||||
Entry* sub = (Entry*) res;
|
||||
|
||||
if (res==LB_ERR || !sub || sub->_level<=dir->_level)
|
||||
break;
|
||||
|
||||
ListBox_DeleteString(pane->_hwnd, idx+1);
|
||||
ListBox_DeleteString(*pane, idx+1);
|
||||
}
|
||||
|
||||
dir->_expanded = false;
|
||||
|
||||
SendMessage(pane->_hwnd, WM_SETREDRAW, TRUE, 0); //ShowWindow(pane->_hwnd, SW_SHOW);
|
||||
SendMessage(*pane, WM_SETREDRAW, TRUE, 0); //ShowWindow(*pane, SW_SHOW);
|
||||
}
|
||||
|
||||
|
||||
|
@ -285,18 +276,18 @@ void FileChildWindow::resize_children(int cx, int cy)
|
|||
hdl.prc = &rt;
|
||||
hdl.pwpos = ℘
|
||||
|
||||
Header_Layout(_left._hwndHeader, &hdl);
|
||||
Header_Layout(_left->_hwndHeader, &hdl);
|
||||
|
||||
DeferWindowPos(hdwp, _left._hwndHeader, wp.hwndInsertAfter,
|
||||
DeferWindowPos(hdwp, _left->_hwndHeader, wp.hwndInsertAfter,
|
||||
wp.x-1, wp.y, _split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
|
||||
|
||||
DeferWindowPos(hdwp, _right._hwndHeader, wp.hwndInsertAfter,
|
||||
DeferWindowPos(hdwp, _right->_hwndHeader, wp.hwndInsertAfter,
|
||||
rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
|
||||
}
|
||||
|
||||
DeferWindowPos(hdwp, _left._hwnd, 0, rt.left, rt.top, _split_pos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
|
||||
DeferWindowPos(hdwp, _left_hwnd, 0, rt.left, rt.top, _split_pos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
|
||||
|
||||
DeferWindowPos(hdwp, _right._hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
|
||||
DeferWindowPos(hdwp, _right_hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
|
||||
|
||||
EndDeferWindowPos(hdwp);
|
||||
}
|
||||
|
@ -310,9 +301,9 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
|||
Entry* entry = (Entry*) dis->itemData;
|
||||
|
||||
if (dis->CtlID == IDW_TREE_LEFT)
|
||||
_left.draw_item(dis, entry);
|
||||
_left->draw_item(dis, entry);
|
||||
else
|
||||
_right.draw_item(dis, entry);
|
||||
_right->draw_item(dis, entry);
|
||||
|
||||
return TRUE;}
|
||||
|
||||
|
@ -327,16 +318,16 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
|||
case WM_SETFOCUS: {
|
||||
TCHAR path[MAX_PATH];
|
||||
|
||||
if (_left._cur) {
|
||||
_left._cur->get_path(path);
|
||||
if (_left->_cur) {
|
||||
_left->_cur->get_path(path);
|
||||
SetCurrentDirectory(path);
|
||||
}
|
||||
|
||||
SetFocus(_focus_pane? _right._hwnd: _left._hwnd);
|
||||
SetFocus(_focus_pane? _right_hwnd: _left_hwnd);
|
||||
break;}
|
||||
|
||||
case WM_DISPATCH_COMMAND: {
|
||||
Pane* pane = GetFocus()==_left._hwnd? &_left: &_right;
|
||||
Pane* pane = GetFocus()==_left_hwnd? _left: _right;
|
||||
|
||||
switch(LOWORD(wparam)) {
|
||||
case ID_WINDOW_NEW:
|
||||
|
@ -347,12 +338,12 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
|||
break;
|
||||
|
||||
case ID_REFRESH: {
|
||||
bool expanded = _left._cur->_expanded;
|
||||
bool expanded = _left->_cur->_expanded;
|
||||
|
||||
scan_entry(_left._cur, _hwnd);
|
||||
scan_entry(_left->_cur, _hwnd);
|
||||
|
||||
if (expanded)
|
||||
expand_entry(_left._cur);
|
||||
expand_entry(_left->_cur);
|
||||
break;}
|
||||
|
||||
case ID_ACTIVATE:
|
||||
|
@ -375,14 +366,14 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
|||
|
||||
int FileChildWindow::Command(int id, int code)
|
||||
{
|
||||
Pane* pane = GetFocus()==_left._hwnd? &_left: &_right;
|
||||
Pane* pane = GetFocus()==_left_hwnd? _left: _right;
|
||||
|
||||
switch(code) {
|
||||
case LBN_SELCHANGE: {
|
||||
int idx = ListBox_GetCurSel(pane->_hwnd);
|
||||
Entry* entry = (Entry*) ListBox_GetItemData(pane->_hwnd, idx);
|
||||
int idx = ListBox_GetCurSel(*pane);
|
||||
Entry* entry = (Entry*) ListBox_GetItemData(*pane, idx);
|
||||
|
||||
if (pane == &_left)
|
||||
if (pane == _left)
|
||||
set_curdir(entry, _hwnd);
|
||||
else
|
||||
pane->_cur = entry;
|
||||
|
@ -414,17 +405,17 @@ void FileChildWindow::activate_entry(Pane* pane, HWND hwnd)
|
|||
return;
|
||||
|
||||
if (entry->_data.cFileName[0]=='.' && entry->_data.cFileName[1]=='.' && entry->_data.cFileName[2]=='\0') {
|
||||
entry = _left._cur->_up;
|
||||
collapse_entry(&_left, entry);
|
||||
entry = _left->_cur->_up;
|
||||
collapse_entry(_left, entry);
|
||||
goto focus_entry;
|
||||
} else if (entry->_expanded)
|
||||
collapse_entry(pane, _left._cur);
|
||||
collapse_entry(pane, _left->_cur);
|
||||
else {
|
||||
expand_entry(_left._cur);
|
||||
expand_entry(_left->_cur);
|
||||
|
||||
if (!pane->_treePane) focus_entry: {
|
||||
int idx = ListBox_FindItemData(_left._hwnd, ListBox_GetCurSel(_left._hwnd), entry);
|
||||
ListBox_SetCurSel(_left._hwnd, idx);
|
||||
int idx = ListBox_FindItemData(_left_hwnd, ListBox_GetCurSel(_left_hwnd), entry);
|
||||
ListBox_SetCurSel(_left_hwnd, idx);
|
||||
set_curdir(entry, _hwnd);
|
||||
}
|
||||
}
|
||||
|
@ -442,22 +433,22 @@ void FileChildWindow::activate_entry(Pane* pane, HWND hwnd)
|
|||
|
||||
void FileChildWindow::scan_entry(Entry* entry, HWND hwnd)
|
||||
{
|
||||
int idx = ListBox_GetCurSel(_left._hwnd);
|
||||
int idx = ListBox_GetCurSel(_left_hwnd);
|
||||
HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
|
||||
|
||||
// delete sub entries in left pane
|
||||
for(;;) {
|
||||
LRESULT res = ListBox_GetItemData(_left._hwnd, idx+1);
|
||||
LRESULT res = ListBox_GetItemData(_left_hwnd, idx+1);
|
||||
Entry* sub = (Entry*) res;
|
||||
|
||||
if (res==LB_ERR || !sub || sub->_level<=entry->_level)
|
||||
break;
|
||||
|
||||
ListBox_DeleteString(_left._hwnd, idx+1);
|
||||
ListBox_DeleteString(_left_hwnd, idx+1);
|
||||
}
|
||||
|
||||
// empty right pane
|
||||
ListBox_ResetContent(_right._hwnd);
|
||||
ListBox_ResetContent(_right_hwnd);
|
||||
|
||||
// release memory
|
||||
entry->free_subentries();
|
||||
|
@ -467,10 +458,10 @@ void FileChildWindow::scan_entry(Entry* entry, HWND hwnd)
|
|||
entry->read_directory(_sortOrder);
|
||||
|
||||
// insert found entries in right pane
|
||||
_right.insert_entries(entry->_down, -1);
|
||||
_right->insert_entries(entry->_down, -1);
|
||||
|
||||
_right.calc_widths(false);
|
||||
_right.set_header();
|
||||
_right->calc_widths(false);
|
||||
_right->set_header();
|
||||
|
||||
_header_wdths_ok = FALSE;
|
||||
|
||||
|
@ -480,7 +471,7 @@ void FileChildWindow::scan_entry(Entry* entry, HWND hwnd)
|
|||
|
||||
int FileChildWindow::Notify(int id, NMHDR* pnmh)
|
||||
{
|
||||
return (pnmh->idFrom==IDW_HEADER_LEFT? &_left: &_right)->Notify(pnmh);
|
||||
return (pnmh->idFrom==IDW_HEADER_LEFT? _left: _right)->Notify(pnmh);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -71,8 +71,8 @@ protected:
|
|||
|
||||
protected:
|
||||
Root _root;
|
||||
Pane _left;
|
||||
Pane _right;
|
||||
Pane* _left;
|
||||
Pane* _right;
|
||||
SORT_ORDER _sortOrder;
|
||||
TCHAR _path[MAX_PATH];
|
||||
bool _header_wdths_ok;
|
||||
|
@ -81,10 +81,10 @@ public:
|
|||
const Root& get_root() const {return _root;}
|
||||
|
||||
void set_focus_pane(Pane* pane)
|
||||
{_focus_pane = pane==&_right? 1: 0;}
|
||||
{_focus_pane = pane==_right? 1: 0;}
|
||||
|
||||
void switch_focus_pane()
|
||||
{SetFocus(_focus_pane? _left._hwnd: _right._hwnd);}
|
||||
{SetFocus(_focus_pane? *_left: *_right);}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -109,15 +109,14 @@ static const int g_pos_align[] = {
|
|||
};
|
||||
|
||||
|
||||
HWND Pane::create(HWND hparent, int id, int id_header)
|
||||
Pane::Pane(HWND hparent, int id, int id_header, Entry* root, bool treePane, int visible_cols)
|
||||
: SubclassedWindow(CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
|
||||
LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
|
||||
0, 0, 0, 0, hparent, (HMENU)id, g_Globals._hInstance, 0)),
|
||||
_root(root),
|
||||
_treePane(treePane),
|
||||
_visible_cols(visible_cols)
|
||||
{
|
||||
_hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
|
||||
LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
|
||||
0, 0, 0, 0, hparent, (HMENU)id, g_Globals._hInstance, 0);
|
||||
|
||||
SetWindowLong(_hwnd, GWL_USERDATA, (LPARAM)this);
|
||||
s_orgTreeWndProc = SubclassWindow(_hwnd, TreeWndProc);
|
||||
|
||||
// insert entries into listbox
|
||||
Entry* entry = _root;
|
||||
|
||||
|
@ -127,37 +126,35 @@ HWND Pane::create(HWND hparent, int id, int id_header)
|
|||
init();
|
||||
|
||||
create_header(hparent, id_header);
|
||||
|
||||
return _hwnd;
|
||||
}
|
||||
|
||||
|
||||
WNDPROC Pane::s_orgTreeWndProc;
|
||||
|
||||
LRESULT CALLBACK Pane::TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
|
||||
LRESULT Pane::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
||||
{
|
||||
FileChildWindow* child = (FileChildWindow*) SendMessage(GetParent(hwnd), WM_GET_FILEWND_PTR, 0, 0);
|
||||
Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
|
||||
|
||||
switch(nmsg) {
|
||||
case WM_HSCROLL:
|
||||
pane->set_header();
|
||||
set_header();
|
||||
break;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
child->set_focus_pane(pane);
|
||||
ListBox_SetSel(hwnd, TRUE, 1);
|
||||
case WM_SETFOCUS: {
|
||||
FileChildWindow* child = (FileChildWindow*) SendMessage(GetParent(_hwnd), WM_GET_FILEWND_PTR, 0, 0);
|
||||
|
||||
child->set_focus_pane(this);
|
||||
ListBox_SetSel(_hwnd, TRUE, 1);
|
||||
/*TODO: check menu items */
|
||||
break;
|
||||
break;}
|
||||
|
||||
case WM_KEYDOWN: {
|
||||
FileChildWindow* child = (FileChildWindow*) SendMessage(GetParent(_hwnd), WM_GET_FILEWND_PTR, 0, 0);
|
||||
|
||||
case WM_KEYDOWN:
|
||||
if (wparam == VK_TAB) {
|
||||
/*TODO: SetFocus(g_Globals.hdrivebar) */
|
||||
child->switch_focus_pane();
|
||||
}
|
||||
break;}
|
||||
}
|
||||
|
||||
return CallWindowProc(s_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
|
||||
return CallWindowProc(_orgWndProc, _hwnd, nmsg, wparam, lparam);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,25 +62,21 @@ struct OutputWorker {
|
|||
};
|
||||
|
||||
|
||||
struct Pane //@@: public Window
|
||||
struct Pane : public SubclassedWindow
|
||||
{
|
||||
HWND _hwnd;
|
||||
HWND _hwndHeader;
|
||||
Pane(HWND hparent, int id, int id_header, Entry* rool, bool treePane, int visible_cols);
|
||||
|
||||
#define COLUMNS 10
|
||||
int _widths[COLUMNS];
|
||||
int _positions[COLUMNS+1];
|
||||
|
||||
HWND _hwndHeader;
|
||||
|
||||
bool _treePane;
|
||||
int _visible_cols;
|
||||
Entry* _root;
|
||||
Entry* _cur;
|
||||
|
||||
HWND create(HWND hparent, int id, int id_header);
|
||||
static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
|
||||
|
||||
static WNDPROC s_orgTreeWndProc;
|
||||
|
||||
void init();
|
||||
void set_header();
|
||||
bool create_header(HWND parent, int id);
|
||||
|
@ -94,6 +90,8 @@ struct Pane //@@: public Window
|
|||
LRESULT Notify(NMHDR* pnmh);
|
||||
|
||||
protected:
|
||||
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
|
||||
|
||||
void calc_width(LPDRAWITEMSTRUCT dis, int col, LPCTSTR str);
|
||||
void calc_tabbed_width(LPDRAWITEMSTRUCT dis, int col, LPCTSTR str);
|
||||
MainFrame* get_frame();
|
||||
|
|
|
@ -44,7 +44,7 @@ struct ShellBrowserChild : public ChildWindow, public IShellBrowserImpl
|
|||
//TODO: SDI implementation
|
||||
#endif
|
||||
|
||||
ShowWindow(child->_hwnd, info._pos.showCmd);
|
||||
ShowWindow(*child, info._pos.showCmd);
|
||||
|
||||
return static_cast<ShellBrowserChild*>(child);
|
||||
}
|
||||
|
|
|
@ -45,11 +45,11 @@ WindowClass::WindowClass(LPCTSTR classname, WNDPROC wndproc)
|
|||
|
||||
|
||||
HHOOK Window::s_hcbthook = 0;
|
||||
Window::WindowCreatorFunc Window::s_window_creator = NULL;
|
||||
Window::WINDOWCREATORFUNC Window::s_window_creator = NULL;
|
||||
const void* Window::s_new_info = NULL;
|
||||
|
||||
|
||||
HWND Window::Create(WindowCreatorFunc creator,
|
||||
HWND Window::Create(WINDOWCREATORFUNC creator,
|
||||
DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
|
||||
DWORD dwStyle, int x, int y, int w, int h,
|
||||
HWND hwndParent, HMENU hMenu, LPVOID lpParam)
|
||||
|
@ -62,7 +62,7 @@ HWND Window::Create(WindowCreatorFunc creator,
|
|||
hwndParent, hMenu, g_Globals._hInstance, 0/*lpParam*/);
|
||||
}
|
||||
|
||||
HWND Window::Create(WindowCreatorFunc creator, const void* info,
|
||||
HWND Window::Create(WINDOWCREATORFUNC creator, const void* info,
|
||||
DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
|
||||
DWORD dwStyle, int x, int y, int w, int h,
|
||||
HWND hwndParent, HMENU hMenu, LPVOID lpParam)
|
||||
|
@ -78,7 +78,7 @@ HWND Window::Create(WindowCreatorFunc creator, const void* info,
|
|||
|
||||
static Window* s_new_child_wnd = NULL;
|
||||
|
||||
Window* Window::create_mdi_child(HWND hmdiclient, const MDICREATESTRUCT& mcs, WindowCreatorFunc creator, const void* info)
|
||||
Window* Window::create_mdi_child(HWND hmdiclient, const MDICREATESTRUCT& mcs, WINDOWCREATORFUNC creator, const void* info)
|
||||
{
|
||||
s_window_creator = creator;
|
||||
s_new_info = info;
|
||||
|
@ -128,7 +128,7 @@ Window* Window::get_window(HWND hwnd)
|
|||
const void* info = s_new_info;
|
||||
s_new_info = NULL;
|
||||
|
||||
WindowCreatorFunc window_creator = s_window_creator;
|
||||
WINDOWCREATORFUNC window_creator = s_window_creator;
|
||||
s_window_creator = NULL;
|
||||
|
||||
wnd = window_creator(hwnd, info);
|
||||
|
@ -138,7 +138,7 @@ Window* Window::get_window(HWND hwnd)
|
|||
}
|
||||
|
||||
|
||||
LRESULT CALLBACK Window::WndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
|
||||
LRESULT CALLBACK Window::WindowWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
|
||||
{
|
||||
Window* pThis = get_window(hwnd);
|
||||
|
||||
|
@ -178,6 +178,13 @@ int Window::Notify(int id, NMHDR* pnmh)
|
|||
}
|
||||
|
||||
|
||||
SubclassedWindow::SubclassedWindow(HWND hwnd)
|
||||
: Window(hwnd)
|
||||
{
|
||||
_orgWndProc = SubclassWindow(_hwnd, WindowWndProc);
|
||||
}
|
||||
|
||||
|
||||
ChildWindow::ChildWindow(HWND hwnd)
|
||||
: Window(hwnd)
|
||||
{
|
||||
|
@ -190,7 +197,7 @@ ChildWindow::ChildWindow(HWND hwnd)
|
|||
}
|
||||
|
||||
|
||||
ChildWindow* ChildWindow::create(HWND hmdiclient, const RECT& rect, WindowCreatorFunc creator, LPCTSTR classname, LPCTSTR title)
|
||||
ChildWindow* ChildWindow::create(HWND hmdiclient, const RECT& rect, WINDOWCREATORFUNC creator, LPCTSTR classname, LPCTSTR title)
|
||||
{
|
||||
MDICREATESTRUCT mcs;
|
||||
|
||||
|
|
|
@ -39,35 +39,39 @@ struct Window
|
|||
SetWindowLong(_hwnd, GWL_USERDATA, 0);
|
||||
}
|
||||
|
||||
HWND _hwnd;
|
||||
|
||||
operator HWND() const {return _hwnd;}
|
||||
|
||||
|
||||
typedef Window* (*WindowCreatorFunc)(HWND, const void*);
|
||||
typedef Window* (*WINDOWCREATORFUNC)(HWND, const void*);
|
||||
|
||||
static HWND Create(WindowCreatorFunc creator,
|
||||
static HWND Create(WINDOWCREATORFUNC creator,
|
||||
DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
|
||||
DWORD dwStyle, int x, int y, int w, int h,
|
||||
HWND hwndParent=0, HMENU hMenu=0, LPVOID lpParam=0);
|
||||
|
||||
static HWND Create(WindowCreatorFunc creator, const void* info,
|
||||
static HWND Create(WINDOWCREATORFUNC creator, const void* info,
|
||||
DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
|
||||
DWORD dwStyle, int x, int y, int w, int h,
|
||||
HWND hwndParent=0, HMENU hMenu=0, LPVOID lpParam=0);
|
||||
|
||||
static Window* create_mdi_child(HWND hmdiclient, const MDICREATESTRUCT& mcs, WindowCreatorFunc creator, const void* info=NULL);
|
||||
static Window* create_mdi_child(HWND hmdiclient, const MDICREATESTRUCT& mcs, WINDOWCREATORFUNC creator, const void* info=NULL);
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
|
||||
static LRESULT CALLBACK WindowWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
|
||||
static Window* get_window(HWND hwnd);
|
||||
|
||||
|
||||
protected:
|
||||
HWND _hwnd;
|
||||
|
||||
|
||||
virtual LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
|
||||
virtual int Command(int id, int code);
|
||||
virtual int Notify(int id, NMHDR* pnmh);
|
||||
|
||||
|
||||
static const void* s_new_info; //TODO: protect for multithreaded access
|
||||
static WindowCreatorFunc s_window_creator; //TODO: protect for multithreaded access
|
||||
static WINDOWCREATORFUNC s_window_creator; //TODO: protect for multithreaded access
|
||||
|
||||
// MDI child creation
|
||||
static HHOOK s_hcbthook;
|
||||
|
@ -75,6 +79,15 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
struct SubclassedWindow : public Window
|
||||
{
|
||||
SubclassedWindow(HWND);
|
||||
|
||||
protected:
|
||||
WNDPROC _orgWndProc;
|
||||
};
|
||||
|
||||
|
||||
template<typename WND_CLASS> struct WindowCreator
|
||||
{
|
||||
static WND_CLASS* window_creator(HWND hwnd)
|
||||
|
@ -84,7 +97,7 @@ template<typename WND_CLASS> struct WindowCreator
|
|||
};
|
||||
|
||||
#define WINDOW_CREATOR(WND_CLASS) \
|
||||
(Window::WindowCreatorFunc) WindowCreator<WND_CLASS>::window_creator
|
||||
(Window::WINDOWCREATORFUNC) WindowCreator<WND_CLASS>::window_creator
|
||||
|
||||
|
||||
template<typename WND_CLASS, typename INFO_CLASS> struct WindowCreatorInfo
|
||||
|
@ -96,12 +109,12 @@ template<typename WND_CLASS, typename INFO_CLASS> struct WindowCreatorInfo
|
|||
};
|
||||
|
||||
#define WINDOW_CREATOR_INFO(WND_CLASS, INFO_CLASS) \
|
||||
(Window::WindowCreatorFunc) WindowCreatorInfo<WND_CLASS, INFO_CLASS>::window_creator
|
||||
(Window::WINDOWCREATORFUNC) WindowCreatorInfo<WND_CLASS, INFO_CLASS>::window_creator
|
||||
|
||||
|
||||
struct WindowClass : public WNDCLASSEX
|
||||
{
|
||||
WindowClass(LPCTSTR classname, WNDPROC wndproc=Window::WndProc);
|
||||
WindowClass(LPCTSTR classname, WNDPROC wndproc=Window::WindowWndProc);
|
||||
|
||||
ATOM Register()
|
||||
{
|
||||
|
@ -136,7 +149,7 @@ struct ChildWindow : public Window
|
|||
ChildWindow(HWND hwnd);
|
||||
|
||||
static ChildWindow* create(HWND hmdiclient, const RECT& rect,
|
||||
WindowCreatorFunc creator, LPCTSTR classname, LPCTSTR title=NULL);
|
||||
WINDOWCREATORFUNC creator, LPCTSTR classname, LPCTSTR title=NULL);
|
||||
|
||||
protected:
|
||||
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
|
||||
|
|
Loading…
Reference in a new issue