From c2a5e8e44e7e3d00e4ba73ef325fc437278e90e9 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sat, 30 Aug 2003 20:48:21 +0000 Subject: [PATCH] compatibility to building as Winelib application svn path=/trunk/; revision=5946 --- .../subsys/system/explorer/doc/changes.txt | 1 + .../system/explorer/taskbar/startmenu.cpp | 17 +++++++---- .../system/explorer/taskbar/startmenu.h | 2 +- .../subsys/system/explorer/utility/window.cpp | 28 +++++++++++-------- .../subsys/system/explorer/utility/window.h | 11 ++++++-- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/reactos/subsys/system/explorer/doc/changes.txt b/reactos/subsys/system/explorer/doc/changes.txt index 59d36c5a6e8..d6a8eb3d8af 100644 --- a/reactos/subsys/system/explorer/doc/changes.txt +++ b/reactos/subsys/system/explorer/doc/changes.txt @@ -31,3 +31,4 @@ 27.08.2003 m. fuchs partly implemented control panel window 28.08.2003 m. fuchs control panel window in cabinet view mode 29.09.2003 m. fuchs Now we handle start menu popups via StartMenuRoot::TrackStartmenu(). +30.09.2003 m. fuchs compatibility to building as Winelib application diff --git a/reactos/subsys/system/explorer/taskbar/startmenu.cpp b/reactos/subsys/system/explorer/taskbar/startmenu.cpp index bed72362954..a9a950280b5 100644 --- a/reactos/subsys/system/explorer/taskbar/startmenu.cpp +++ b/reactos/subsys/system/explorer/taskbar/startmenu.cpp @@ -39,8 +39,6 @@ #include "startmenu.h" -BtnWindowClass StartMenu::s_wcStartMenu(CLASSNAME_STARTMENU); - StartMenu::StartMenu(HWND hwnd) : super(hwnd) { @@ -67,10 +65,19 @@ StartMenu::~StartMenu() } + // We need this wrapper function for s_wcStartMenu, it calls to the WIN32 API + // through static C++ initializers are not allowed for Winelib applications. +BtnWindowClass& StartMenu::GetWndClasss() +{ + static BtnWindowClass s_wcStartMenu(CLASSNAME_STARTMENU); + + return s_wcStartMenu; +} + /* HWND StartMenu::Create(int x, int y, HWND hwndParent) { - return Window::Create(WINDOW_CREATOR(StartMenu), NULL, s_wcStartMenu, TITLE_STARTMENU, + return Window::Create(WINDOW_CREATOR(StartMenu), NULL, GetWndClasss(), TITLE_STARTMENU, WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE, x, y, STARTMENU_WIDTH_MIN, 4, hwndParent); } */ @@ -80,7 +87,7 @@ Window::CREATORFUNC StartMenu::s_def_creator = STARTMENU_CREATOR(StartMenu); HWND StartMenu::Create(int x, int y, const StartMenuFolders& folders, HWND hwndParent, CREATORFUNC creator) { //TODO: check, if coordinates x/y are visible on the screen - return Window::Create(creator, &folders, 0, s_wcStartMenu, NULL, + return Window::Create(creator, &folders, 0, GetWndClasss(), NULL, WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE, x, y, STARTMENU_WIDTH_MIN, 4/*start height*/, hwndParent); } @@ -554,7 +561,7 @@ HWND StartMenuRoot::Create(HWND hwndDesktopBar) { WindowRect pos(hwndDesktopBar); - return Window::Create(WINDOW_CREATOR(StartMenuRoot), 0, s_wcStartMenu, TITLE_STARTMENU, + return Window::Create(WINDOW_CREATOR(StartMenuRoot), 0, GetWndClasss(), TITLE_STARTMENU, WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE, pos.left, pos.top-4, STARTMENU_WIDTH_MIN, 4, hwndDesktopBar); } diff --git a/reactos/subsys/system/explorer/taskbar/startmenu.h b/reactos/subsys/system/explorer/taskbar/startmenu.h index 49472fafec8..5b07f723499 100644 --- a/reactos/subsys/system/explorer/taskbar/startmenu.h +++ b/reactos/subsys/system/explorer/taskbar/startmenu.h @@ -143,7 +143,7 @@ protected: int Command(int id, int code); // window class - static BtnWindowClass s_wcStartMenu; + static BtnWindowClass& GetWndClasss(); // data members int _next_id; diff --git a/reactos/subsys/system/explorer/utility/window.cpp b/reactos/subsys/system/explorer/utility/window.cpp index f65021b4dae..6c6fe4f8856 100644 --- a/reactos/subsys/system/explorer/utility/window.cpp +++ b/reactos/subsys/system/explorer/utility/window.cpp @@ -57,27 +57,33 @@ IconWindowClass::IconWindowClass(LPCTSTR classname, UINT nid, UINT style, WNDPRO } -HHOOK Window::s_hcbtHook = 0; +Window::WindowMap Window::s_wnd_map; Window::CREATORFUNC Window::s_window_creator = NULL; const void* Window::s_new_info = NULL; -CritSect Window::s_create_crit_sect; -Window::WindowMap Window::s_wnd_map; -CritSect Window::s_map_crit_sect; +HHOOK Window::s_hcbtHook = 0; + + +Window::StaticWindowData& Window::GetStaticWindowData() +{ + static StaticWindowData s_initialized_data; + + return s_initialized_data; +} Window::Window(HWND hwnd) : WindowHandle(hwnd) { - Lock lock(s_map_crit_sect); // protect access to s_wnd_map + Lock lock(GetStaticWindowData()._map_crit_sect); // protect access to s_wnd_map s_wnd_map[_hwnd] = this; } Window::~Window() { - Lock lock(s_map_crit_sect); // protect access to s_wnd_map + Lock lock(GetStaticWindowData()._map_crit_sect); // protect access to s_wnd_map s_wnd_map.erase(_hwnd); } @@ -88,7 +94,7 @@ HWND Window::Create(CREATORFUNC creator, DWORD dwExStyle, DWORD dwStyle, int x, int y, int w, int h, HWND hwndParent, HMENU hMenu, LPVOID lpParam) { - Lock lock(s_create_crit_sect); // protect access to s_window_creator and s_new_info + Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info s_window_creator = creator; s_new_info = NULL; @@ -103,7 +109,7 @@ HWND Window::Create(CREATORFUNC creator, const void* info, DWORD dwExStyle, DWORD dwStyle, int x, int y, int w, int h, HWND hwndParent, HMENU hMenu, LPVOID lpParam) { - Lock lock(s_create_crit_sect); // protect access to s_window_creator and s_new_info + Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info s_window_creator = creator; s_new_info = info; @@ -118,7 +124,7 @@ static Window* s_new_child_wnd = NULL; Window* Window::create_mdi_child(HWND hmdiclient, const MDICREATESTRUCT& mcs, CREATORFUNC creator, const void* info) { - Lock lock(s_create_crit_sect); // protect access to s_window_creator and s_new_info + Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info s_window_creator = creator; s_new_info = info; @@ -160,7 +166,7 @@ LRESULT CALLBACK Window::CBTHookProc(int code, WPARAM wparam, LPARAM lparam) Window* Window::get_window(HWND hwnd) { { - Lock lock(s_map_crit_sect); // protect access to s_wnd_map + Lock lock(GetStaticWindowData()._map_crit_sect); // protect access to s_wnd_map WindowMap::const_iterator found = s_wnd_map.find(hwnd); @@ -169,7 +175,7 @@ Window* Window::get_window(HWND hwnd) } if (s_window_creator) { // protect for recursion - Lock lock(s_create_crit_sect); // protect access to s_window_creator and s_new_info + Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info const void* info = s_new_info; s_new_info = NULL; diff --git a/reactos/subsys/system/explorer/utility/window.h b/reactos/subsys/system/explorer/utility/window.h index febd1209d4d..f5dc6d58909 100644 --- a/reactos/subsys/system/explorer/utility/window.h +++ b/reactos/subsys/system/explorer/utility/window.h @@ -106,11 +106,18 @@ protected: static WindowMap s_wnd_map; - static CritSect s_map_crit_sect; static const void* s_new_info; static CREATORFUNC s_window_creator; - static CritSect s_create_crit_sect; + + + struct StaticWindowData { + CritSect _map_crit_sect; + CritSect _create_crit_sect; + }; + + static StaticWindowData& GetStaticWindowData(); + // MDI child creation static HHOOK s_hcbtHook;