From 963f962bc675c0897caa3e00f092d77591d77272 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sun, 23 Nov 2003 15:44:14 +0000 Subject: [PATCH] ANS/UNC utilities for ostringstream; more CONTEXT information svn path=/trunk/; revision=6766 --- .../system/explorer/shell/filechild.cpp | 16 ++++-- .../system/explorer/shell/mainframe.cpp | 8 ++- .../system/explorer/utility/shellclasses.cpp | 27 +--------- .../system/explorer/utility/utility.cpp | 33 ++++++++++++ .../subsys/system/explorer/utility/utility.h | 54 +++++++++++++++++++ 5 files changed, 105 insertions(+), 33 deletions(-) diff --git a/reactos/subsys/system/explorer/shell/filechild.cpp b/reactos/subsys/system/explorer/shell/filechild.cpp index 16a15de733c..00c4c7cf40c 100644 --- a/reactos/subsys/system/explorer/shell/filechild.cpp +++ b/reactos/subsys/system/explorer/shell/filechild.cpp @@ -70,6 +70,8 @@ ShellChildWndInfo::ShellChildWndInfo(LPCTSTR path, const ShellPath& root_shell_p FileChildWindow::FileChildWindow(HWND hwnd, const FileChildWndInfo& info) : ChildWindow(hwnd) { + CONTEXT("FileChildWindow::FileChildWindow()"); + TCHAR drv[_MAX_DRIVE+1]; Entry* entry; @@ -147,6 +149,8 @@ FileChildWindow::~FileChildWindow() void FileChildWindow::set_curdir(Entry* entry, HWND hwnd) { + CONTEXT("FileChildWindow::set_curdir()"); + _path[0] = TEXT('\0'); _left->_cur = entry; @@ -243,6 +247,8 @@ void FileChildWindow::collapse_entry(Pane* pane, Entry* dir) FileChildWindow* FileChildWindow::create(HWND hmdiclient, const FileChildWndInfo& info) { + CONTEXT("FileChildWindow::create()"); + MDICREATESTRUCT mcs; mcs.szClass = CLASSNAME_WINEFILETREE; @@ -336,14 +342,14 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) Pane* pane = GetFocus()==_left_hwnd? _left: _right; switch(LOWORD(wparam)) { - case ID_WINDOW_NEW: + case ID_WINDOW_NEW: {CONTEXT("PM_DISPATCH_COMMAND ID_WINDOW_NEW"); if (_root._entry->_etype == ET_SHELL) FileChildWindow::create(GetParent(_hwnd)/*_hmdiclient*/, ShellChildWndInfo(_path,DesktopFolderPath())); else FileChildWindow::create(GetParent(_hwnd)/*_hmdiclient*/, FileChildWndInfo(_path)); - break; + break;} - case ID_REFRESH: { + case ID_REFRESH: {CONTEXT("ID_REFRESH"); bool expanded = _left->_cur->_expanded; scan_entry(_left->_cur, _hwnd); @@ -352,9 +358,9 @@ LRESULT FileChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) expand_entry(_left->_cur); break;} - case ID_ACTIVATE: + case ID_ACTIVATE: {CONTEXT("ID_ACTIVATE"); activate_entry(pane, _hwnd); - break; + break;} default: return pane->command(LOWORD(wparam)); diff --git a/reactos/subsys/system/explorer/shell/mainframe.cpp b/reactos/subsys/system/explorer/shell/mainframe.cpp index 12bddd74a3b..8187fc62584 100644 --- a/reactos/subsys/system/explorer/shell/mainframe.cpp +++ b/reactos/subsys/system/explorer/shell/mainframe.cpp @@ -286,7 +286,7 @@ LRESULT MainFrame::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) case PM_FRM_GET_MENUINFO: return (LPARAM)&_menu_info; - case PM_OPEN_WINDOW: { + case PM_OPEN_WINDOW: {CONTEXT("PM_OPEN_WINDOW"); TCHAR buffer[MAX_PATH]; LPCTSTR path; ShellPath shell_path = DesktopFolderPath(); @@ -307,6 +307,9 @@ LRESULT MainFrame::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) path = buffer; } + { + OBJ_CONTEXT("create ShellChildWndInfo", path); + // Shell Namespace as default view ShellChildWndInfo create_info(path, shell_path); @@ -319,7 +322,8 @@ LRESULT MainFrame::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) create_info._open_mode = (OPEN_WINDOW_MODE)wparam; // FileChildWindow::create(_hmdiclient, create_info); - return (LRESULT)ShellBrowserChild::create(_hmdiclient, create_info);} + return (LRESULT)ShellBrowserChild::create(_hmdiclient, create_info); + }} case PM_GET_CONTROLWINDOW: if (wparam == FCW_STATUS) diff --git a/reactos/subsys/system/explorer/utility/shellclasses.cpp b/reactos/subsys/system/explorer/utility/shellclasses.cpp index 80ab2db74ec..46ab8229757 100644 --- a/reactos/subsys/system/explorer/utility/shellclasses.cpp +++ b/reactos/subsys/system/explorer/utility/shellclasses.cpp @@ -62,31 +62,6 @@ LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count) } -Context Context::s_main("-NO-CONTEXT-"); -Context* Context::s_current = &Context::s_main; - -String Context::toString() const -{ - FmtString str(TEXT("%hs"), _ctx); - - if (!_obj.empty()) - str.appendf(TEXT("\nObject: %s"), (LPCTSTR)_obj); - - return str; -} - -String Context::getStackTrace() const -{ - // evtl. besser ostringstream verwenden - String str = TEXT("Context Trace:\n"); - - for(const Context*p=this; p!=&s_main; p=p->_last) - str.appendf(TEXT("ctx=%hs obj=%s\n"), p->_ctx, (LPCTSTR)p->_obj); - - return str; -} - - String COMException::toString() const { TCHAR msg[4*BUFFER_LEN]; @@ -95,7 +70,7 @@ String COMException::toString() const p += _stprintf(p, TEXT("%s\nContext: %s"), super::ErrorMessage(), (LPCTSTR)_ctx.toString()); if (_file) - p += _stprintf(p, TEXT("\nLocation: %hs(%d)"), _file, _line); + p += _stprintf(p, TEXT("\nLocation: %hs:%d"), _file, _line); return msg; } diff --git a/reactos/subsys/system/explorer/utility/utility.cpp b/reactos/subsys/system/explorer/utility/utility.cpp index f66a52d8d32..8d7ed0b60c7 100644 --- a/reactos/subsys/system/explorer/utility/utility.cpp +++ b/reactos/subsys/system/explorer/utility/utility.cpp @@ -30,6 +30,7 @@ #include #include +#include DWORD WINAPI Thread::ThreadProc(void* para) @@ -110,6 +111,38 @@ void display_error(HWND hwnd, DWORD error) //@@ CONTEXT mit ausgeben -> display_ } +Context Context::s_main("-NO-CONTEXT-"); +Context* Context::s_current = &Context::s_main; + +String Context::toString() const +{ + String str = _ctx; + + if (!_obj.empty()) + str.appendf(TEXT("\nObject: %s"), (LPCTSTR)_obj); + + return str; +} + +String Context::getStackTrace() const +{ + ostringstream str; + + str << "Context Trace:\n"; + + for(const Context*p=this; p!=&s_main; p=p->_last) { + str << "- " << p->_ctx; + + if (!p->_obj.empty()) + str << " obj=" << ANS(p->_obj); + + str << '\n'; + } + + return str.str(); +} + + BOOL time_to_filetime(const time_t* t, FILETIME* ftime) { struct tm* tm = gmtime(t); diff --git a/reactos/subsys/system/explorer/utility/utility.h b/reactos/subsys/system/explorer/utility/utility.h index b4a1f0e8200..55989187256 100644 --- a/reactos/subsys/system/explorer/utility/utility.h +++ b/reactos/subsys/system/explorer/utility/utility.h @@ -498,10 +498,12 @@ struct String #ifdef UNICODE String(LPCSTR s) {assign(s);} + String(const string& other) {assign(other.c_str());} String& operator=(LPCSTR s) {assign(s); return *this;} void assign(LPCSTR s) {TCHAR b[BUFFER_LEN]; super::assign(b, MultiByteToWideChar(CP_ACP, 0, s, -1, b, BUFFER_LEN));} #else String(LPCWSTR s) {assign(s);} + String(const wstring& other) {assign(other.c_str());} String& operator=(LPCWSTR s) {assign(s); return *this;} void assign(LPCWSTR s) {char b[BUFFER_LEN]; super::assign(b, WideCharToMultiByte(CP_ACP, 0, s, -1, b, BUFFER_LEN, 0, 0));} #endif @@ -554,6 +556,7 @@ struct String } }; + struct FmtString : public String { FmtString(LPCTSTR fmt, ...) @@ -567,6 +570,57 @@ struct FmtString : public String }; +#ifdef UNICODE + +struct ANS +{ + ANS(LPCWSTR s) + { + int l = wcslen(s) + 1; + _str = (LPSTR) malloc(2*l); + WideCharToMultiByte(CP_ACP, 0, s, -1, _str, 2*l, 0, 0); + } + + ~ANS() + { + free(_str); + } + + operator LPCSTR() {return _str;} + +protected: + LPSTR _str; +}; + +#define UNC(x) ((LPCWSTR)(x)) + +#else + +#define ANS(x) ((LPCSTR)(x)) + +struct UNC +{ + UNC(LPCSTR s) + { + int l = strlen(s) + 1; + _str = (LPWSTR) malloc(2*l); + MultiByteToWideChar(CP_ACP, 0, s, -1, _str, l); + } + + ~UNC() + { + free(_str); + } + + operator LPCWSTR() {return _str;} + +protected: + LPWSTR _str; +}; + +#endif + + /// link dynamicly to functions by using GetModuleHandle() and GetProcAddress() template struct DynamicFct {