|
From: Ralph T. <ra...@us...> - 2005-04-08 21:04:02
|
Update of /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/visual/sources/win In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31751/adobe-source/adobe/test/visual/sources/win Modified Files: main.cpp metrics.cpp ui_core_implementation.cpp Log Message: Visual Styles are enabled by default on Windows XP, and controls appear correctly on tabs, etc. A resource file has been added, and the generated exe now has the Adobe Begin icon. The following items still need to be completed on the Windows implementation of ui-core before it reaches parity with the Mac implementation: - slider_t needs to report changes, and actually set it's value. - progress_bar_t also needs work. - link_t's event mechanism should be looked at, it may not be painting when required. Index: metrics.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/visual/sources/win/metrics.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** metrics.cpp 2 Apr 2005 01:04:03 -0000 1.3 --- metrics.cpp 8 Apr 2005 21:03:50 -0000 1.4 *************** *** 167,170 **** --- 167,183 ---- return false; } + bool using_styles() const + { + return false; + } + void draw_parent_background(HWND window, HDC dc) + { + // + // REVISIT (ralpht): This function doesn't actually get called when visual + // styles aren't available, so there's no implementation here. That + // may not always be the case, however... + // + throw std::runtime_error("metrics::draw_parent_background not implemented without visual styles enabled"); + } }; *************** *** 209,212 **** --- 222,226 ---- typedef HRESULT (__stdcall *GetThemeFont_t)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, LOGFONTW* pFont); typedef HRESULT (__stdcall *GetThemeSysFont_t)(HTHEME hTheme, int iFontId, LOGFONTW* pFont); + typedef HRESULT (__stdcall *DrawThemeParentBackground_t)(HWND window, HDC dc, LPRECT prc); typedef BOOL (__stdcall *IsThemeActive_t)(void); OpenThemeData_t OpenThemeDataPtr; *************** *** 219,222 **** --- 233,237 ---- GetThemeFont_t GetThemeFontPtr; GetThemeSysFont_t GetThemeSysFontPtr; + DrawThemeParentBackground_t DrawThemeParentBackgroundPtr; IsThemeActive_t IsThemeActivePtr; // *************** *** 229,233 **** GetThemeMarginsPtr(0), GetThemePartSizePtr(0), GetThemeIntPtr(0), GetThemeTextExtentPtr(0), GetThemeTextMetricsPtr(0), GetThemeFontPtr(0), ! GetThemeSysFontPtr(0), IsThemeActivePtr(0), loaded_m(false) { // --- 244,249 ---- GetThemeMarginsPtr(0), GetThemePartSizePtr(0), GetThemeIntPtr(0), GetThemeTextExtentPtr(0), GetThemeTextMetricsPtr(0), GetThemeFontPtr(0), ! GetThemeSysFontPtr(0), IsThemeActivePtr(0), DrawThemeParentBackgroundPtr(0), ! loaded_m(false) { // *************** *** 249,252 **** --- 265,269 ---- if (!(GetThemeSysFontPtr = (GetThemeSysFont_t)GetProcAddress(theme_dll_m, "GetThemeSysFont"))) return; if (!(IsThemeActivePtr = (IsThemeActive_t)GetProcAddress(theme_dll_m, "IsThemeActive"))) return; + if (!(DrawThemeParentBackgroundPtr = (DrawThemeParentBackground_t)GetProcAddress(theme_dll_m, "DrawThemeParentBackground"))) return; // // All loaded! *************** *** 369,372 **** --- 386,396 ---- return (S_OK == (*GetThemeMarginsPtr)(theme_m, 0, widget_type, kState, TMT_CONTENTMARGINS, 0, &out_margins)); } + bool using_styles() const { + return theme_active(); + } + void draw_parent_background(HWND window, HDC dc) { + if (!loaded_m) return; + (*DrawThemeParentBackgroundPtr)(window, dc, 0); + } }; /****************************************************************************************************/ Index: main.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/visual/sources/win/main.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** main.cpp 5 Apr 2005 05:46:05 -0000 1.3 --- main.cpp 8 Apr 2005 21:03:50 -0000 1.4 *************** *** 144,148 **** int WinMain( HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR lpCmdLine, int nCmdShow ) { ! try { adobe::simpleApplication* theApp = adobe::simpleApplication::getInstance(); --- 144,148 ---- int WinMain( HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR lpCmdLine, int nCmdShow ) { ! // try { adobe::simpleApplication* theApp = adobe::simpleApplication::getInstance(); *************** *** 150,157 **** if( theApp ) theApp->run(); } ! catch( ... ) ! { ! adobe::report_exception(); ! } return 0; --- 150,157 ---- if( theApp ) theApp->run(); } ! // catch( ... ) ! // { ! // adobe::report_exception(); ! // } return 0; Index: ui_core_implementation.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/visual/sources/win/ui_core_implementation.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ui_core_implementation.cpp 5 Apr 2005 15:43:58 -0000 1.12 --- ui_core_implementation.cpp 8 Apr 2005 21:03:50 -0000 1.13 *************** *** 12,15 **** --- 12,16 ---- #include "display.hpp" #include "metrics.hpp" + #include "resources.h" #include <adobe/value.hpp> *************** *** 1067,1070 **** --- 1068,1222 ---- } // + /// This function is a hack to create a background brush which can be used by + /// children of panels on tabs. The brush is generated by creating a bitmap + /// the size of the panel, and drawing the panel background into the bitmap + /// before converting the bitmap into a patterned brush. + /// + /// \param panel the panel window to make a brush for. + // + HBRUSH make_background_brush(HWND panel) + { + HDC dc = GetDC(panel); + SetBkMode(dc, TRANSPARENT); + RECT dimensions = {0, 0, 0, 0}; + GetClientRect(panel, &dimensions); + // + // Make a memory device context and bitmap. + // + HDC memory_dc = CreateCompatibleDC(dc); + if (!memory_dc) ADOBE_THROW_LAST_ERROR; + HBITMAP memory_bmp = CreateCompatibleBitmap(dc, dimensions.right, dimensions.bottom); + if (!memory_bmp) ADOBE_THROW_LAST_ERROR; + // + // Select the new bitmap into the memory DC. + // + HGDIOBJ bmp_old = SelectObject(memory_dc, memory_bmp); + // + // Draw the background into the bitmap. + // + metrics_t::get_instance().draw_parent_background( panel, memory_dc ); + // + // Create the patterned brush, and verify that it was created. + // + HBRUSH b = CreatePatternBrush(memory_bmp); + if (!b) ADOBE_THROW_LAST_ERROR; + // + // Select out our bitmap. + // + SelectObject(memory_dc, bmp_old); + DeleteObject(memory_bmp); + DeleteDC(memory_dc); + // + // Return the created brush. + // + return b; + } + + // + /// This function is the event handler for the panel widget. The panel is a + /// container which does it's best to be transparent. It will forward events + /// it recieves from it's child controls on to them using + /// forward_events_to_control. + // + LRESULT CALLBACK panel_window_procedure(HWND panel, UINT message, WPARAM wParam, LPARAM lParam) + { + // + // First lets see if one of our children can handle this message. + // + bool handled(false); + LRESULT rv = forward_events_to_control(message, wParam, lParam, handled); + if (handled) return rv; + // + // We try to paint ourselves if visual styles are active. If we are + // a panel on top of a tab control then we must make sure that we get + // the tab background. + // + if (message == WM_PAINT) + { + PAINTSTRUCT ps; + // + // Only DIY if visual styles are on. + // + if (!metrics_t::get_instance().using_styles()) + return DefWindowProc(panel, message, wParam, lParam); + HDC window_dc = BeginPaint(panel, &ps); + metrics_t::get_instance().draw_parent_background(panel, window_dc); + EndPaint(panel, &ps); + return 0; + } + else if (message == WM_SIZE) + { + // + // We store the brush which we give to children in the panel_t. + // We only need this brush if visual styles are enabled -- the + // brush contains the background bitmap which controls need to + // draw behind themselves. + // + // We regenerate the background brush when a control requests it + // (rather than when we resize, we don't want to make resizing + // slow). In the size handler we just release the current brush + // and set the brush to zero. + // + HBRUSH b = (HBRUSH)SetWindowLong(panel, GWL_USERDATA, 0); + if (b) DeleteObject(b); + } + else if ((message == WM_CTLCOLORSTATIC) || (message == WM_CTLCOLOREDIT)) + { + // + // If we are not using visual styles then we don't have to do + // anything here -- the default window procedure is correct. + // + if (!metrics_t::get_instance().using_styles()) + return DefWindowProc(panel, message, wParam, lParam); + // + // Usually we store the brush as user data inside the HWND. + // + HBRUSH b = (HBRUSH)GetWindowLong(panel, GWL_USERDATA); + if (!b) + { + // + // There is no brush. Either the brush was deleted by + // the WM_SIZE handler or this is the first time a + // brush has been requested. We need to create a new + // brush and set it into the panel HWND. + // + b = make_background_brush(panel); + SetWindowLong(panel, GWL_USERDATA, (LONG)b); + } + // + // + // Set the child's DC drawing mode to transparent, and give + // it an empty brush. + // + RECT child_dim; RECT panel_dim; + HDC dc = (HDC)wParam; + HWND child = (HWND)lParam; + + SetBkMode(dc, TRANSPARENT); + GetWindowRect(child, &child_dim); + GetWindowRect(panel, &panel_dim); + SetBrushOrgEx(dc, -(child_dim.left - panel_dim.left), + -(child_dim.top - panel_dim.top), 0); + return (LRESULT)b; + } + else if (message == WM_CREATE) + { + // + // Make sure that we don't use uninitialized memory as a brush + // handle. + // + SetWindowLong(panel, GWL_USERDATA, 0); + } + else if (message == WM_DESTROY) + { + // + // Release any brush we might still own. + // + HBRUSH b = (HBRUSH)GetWindowLong(panel, GWL_USERDATA); + if (b) DeleteObject(b); + } + return DefWindowProc(panel, message, wParam, lParam); + } + // /// This function is the main event handler for ui-core on Win32. It delegates /// most of the events it recieves to individual control instances, via the *************** *** 1128,1142 **** wc.cbWndExtra = 0; wc.hInstance = ::GetModuleHandle(NULL); ! wc.hIcon = 0; //LoadIcon(NULL, IDI_APPLICATION); ! wc.hCursor = LoadCursor(NULL, IDC_ARROW); ! #if 1 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); - #else - wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); - #endif wc.lpszMenuName = NULL; wc.lpszClassName = L"eve_dialog"; RegisterClassW(&wc); } } --- 1280,1296 ---- wc.cbWndExtra = 0; wc.hInstance = ::GetModuleHandle(NULL); ! wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(RES_APP_ICON)); ! wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wc.lpszMenuName = NULL; wc.lpszClassName = L"eve_dialog"; RegisterClassW(&wc); + // + // Register a new window class. + // + wc.lpfnWndProc = panel_window_procedure; + wc.lpszClassName = L"eve_panel"; + RegisterClassW(&wc); } } *************** *** 1223,1227 **** DWORD style) { ! DWORD dialog_extended_style = WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME; int width = bounds.right - bounds.left; --- 1377,1381 ---- DWORD style) { ! DWORD dialog_extended_style = WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME | WS_EX_COMPOSITED; int width = bounds.right - bounds.left; *************** *** 1417,1421 **** return DefWindowProc(window, message, wParam, lParam); } - /****************************************************************************************************/ --- 1571,1574 ---- *************** *** 1460,1465 **** // Now create the window. // ! invisible_parent_m = CreateWindowW(L"eve_invisible_parent", L"invisible", WS_POPUP, ! 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, ::GetModuleHandle(NULL), NULL); if (!invisible_parent_m) ADOBE_THROW_LAST_ERROR; } --- 1613,1619 ---- // Now create the window. // ! invisible_parent_m = CreateWindowExW(WS_EX_COMPOSITED, L"eve_invisible_parent", ! L"invisible", WS_POPUP, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, ! ::GetModuleHandle(NULL), NULL); if (!invisible_parent_m) ADOBE_THROW_LAST_ERROR; } *************** *** 1779,1783 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_CONTROLPARENT, "BUTTON", name.c_str(), --- 1933,1937 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_CONTROLPARENT | WS_EX_COMPOSITED, "BUTTON", name.c_str(), *************** *** 1852,1856 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( 0, WC_TABCONTROL, NULL, --- 2006,2010 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, WC_TABCONTROL, NULL, *************** *** 1863,1867 **** if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifdef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); --- 2017,2021 ---- if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifndef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); *************** *** 2010,2030 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_CONTROLPARENT, ! "STATIC", ! NULL, ! WS_CHILD | WS_VISIBLE | WS_TABSTOP, ! bounds.left, bounds.top, width, height, ! invisible_parent_m, ! child_id_m, ! ::GetModuleHandle(NULL), ! NULL); if (control_m == NULL) ADOBE_THROW_LAST_ERROR; - - set_user_reference(control_m, this); - // - // This control is a container. - // - trap_window_proc(container_window_proc); } --- 2164,2178 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_CONTROLPARENT | WS_EX_COMPOSITED, ! "eve_panel", ! NULL, ! WS_CHILD | WS_VISIBLE | WS_TABSTOP, ! bounds.left, bounds.top, width, height, ! invisible_parent_m, ! child_id_m, ! ::GetModuleHandle(NULL), ! NULL); if (control_m == NULL) ADOBE_THROW_LAST_ERROR; } *************** *** 2088,2092 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindow( "BUTTON", button_default_state(state_set_m)->name_m.c_str(), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP | BS_NOTIFY, --- 2236,2240 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, "BUTTON", button_default_state(state_set_m)->name_m.c_str(), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP | BS_NOTIFY, *************** *** 2099,2103 **** if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifdef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); --- 2247,2251 ---- if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifndef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); *************** *** 2242,2246 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindow( "BUTTON", name.c_str(), WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON | WS_TABSTOP | BS_NOTIFY, --- 2390,2394 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED | WS_EX_TRANSPARENT, "BUTTON", name.c_str(), WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON | WS_TABSTOP | BS_NOTIFY, *************** *** 2252,2256 **** if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifdef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); --- 2400,2404 ---- if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifndef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); *************** *** 2337,2341 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindow( "BUTTON", name.c_str(), WS_CHILD | WS_VISIBLE | BS_CHECKBOX | WS_TABSTOP | BS_NOTIFY, --- 2485,2489 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, "BUTTON", name.c_str(), WS_CHILD | WS_VISIBLE | BS_CHECKBOX | WS_TABSTOP | BS_NOTIFY, *************** *** 2347,2351 **** if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifdef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); --- 2495,2499 ---- if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifndef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); *************** *** 2444,2450 **** draw_link(*link, context); - #ifndef NDEBUG frame_widget(*control); // Done after the default wind proc has drawn the widget - #endif } --- 2592,2596 ---- *************** *** 2480,2484 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindow( "STATIC", NULL, WS_CHILD | WS_VISIBLE, --- 2626,2630 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, "STATIC", NULL, WS_CHILD | WS_VISIBLE, *************** *** 2604,2608 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( 0, PROGRESS_CLASS, NULL, --- 2750,2754 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, PROGRESS_CLASS, NULL, *************** *** 2706,2710 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( 0, WC_STATIC, NULL, --- 2852,2856 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, WC_STATIC, NULL, *************** *** 2777,2781 **** // (we're going to have to figure out how to do this dynamically) ! control_m = ::CreateWindow( "STATIC", name.c_str(), WS_CHILD | WS_VISIBLE, --- 2923,2927 ---- // (we're going to have to figure out how to do this dynamically) ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, "STATIC", name.c_str(), WS_CHILD | WS_VISIBLE, *************** *** 2787,2791 **** if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifdef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); --- 2933,2937 ---- if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifndef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); *************** *** 2938,2942 **** } ! control_m = ::CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, --- 3084,3088 ---- } ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED | WS_EX_CLIENTEDGE, "EDIT", NULL, *************** *** 3262,3266 **** long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindow( WC_COMBOBOX, NULL, WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_TABSTOP, --- 3408,3412 ---- long height(bounds.bottom - bounds.top); ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, WC_COMBOBOX, NULL, WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_TABSTOP, *************** *** 3273,3277 **** if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifdef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); --- 3419,3423 ---- if (control_m == NULL) ADOBE_THROW_LAST_ERROR; ! #ifndef NDEBUG set_user_reference(control_m, this); trap_window_proc(control_window_proc); *************** *** 3906,3912 **** void slider_t::implementation_t::initialize(const RECT* bounds, ! bool is_vertical, ! slider_style_t style, ! long num_tick_marks) { assert(!control_m); --- 4052,4058 ---- void slider_t::implementation_t::initialize(const RECT* bounds, ! bool is_vertical, ! slider_style_t style, ! long num_tick_marks) { assert(!control_m); *************** *** 3918,3921 **** --- 4064,4068 ---- style_m = style; num_tick_marks_m = num_tick_marks; + uxtheme_type_m = (is_vertical_m) ? TKP_THUMBTOP : TKP_THUMBLEFT; DWORD win32_style = WS_CHILD | WS_VISIBLE | WS_TABSTOP; *************** *** 3938,3942 **** } ! control_m = ::CreateWindowEx( 0, TRACKBAR_CLASS, NULL, --- 4085,4089 ---- } ! control_m = ::CreateWindowEx( WS_EX_COMPOSITED, TRACKBAR_CLASS, NULL, *************** *** 3958,3986 **** { rectangle_t result; ! ! result.width() = 20; ! result.height() = 20; ! ! if (is_vertical_m) ! result.height() += 1; ! else ! result.width() += 1; ! return result; } /****************************************************************************************************/ - - void slider_t::implementation_t::set_bounds(const point_t& position, const rectangle_t& geometry) - { - assert(control_m); - - /*::DeleteObject((HGDIOBJ)*/ ::SetClassLong(control_m, GCL_HBRBACKGROUND, (LONG)(COLOR_BTNFACE + 1))/*)*/; - - _super::set_bounds(position, geometry); - } - - /****************************************************************************************************/ - void slider_t::implementation_t::set_min_value(long min_value) { --- 4105,4129 ---- { rectangle_t result; ! // ! // Get the size of the thumb, and then multiply it by the number of tick ! // marks. ! // ! SIZE thumb_size; ! metrics_t::get_instance().set_window(control_m); ! if (!metrics_t::get_instance().get_size(uxtheme_type_m, TS_TRUE, thumb_size)) ! ADOBE_THROW_LAST_ERROR; ! result.width() = thumb_size.cx;//(is_vertical_m) ? thumb_size.cx : thumb_size.cx * 15; ! result.height() = thumb_size.cy; //(is_vertical_m) ? thumb_size.cy * 15 : thumb_size.cy; ! // ! // Add on any border. ! // ! int border; ! metrics_t::get_instance().get_integer(uxtheme_type_m, TMT_BORDERSIZE, border); ! result.width() += 2 * border; ! result.height() += 2 * border; return result; } /****************************************************************************************************/ void slider_t::implementation_t::set_min_value(long min_value) { |