|
From: Foster B. <fos...@us...> - 2005-04-02 05:47:49
|
Update of /cvsroot/adobe-source/adobe-source/adobe/test/visual/sources/win In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17172/adobe/test/visual/sources/win Modified Files: ui_core_implementation.cpp Added Files: main.cpp metrics.cpp Log Message: asl 1.0.2 --- NEW FILE: metrics.cpp --- /* Copyright 2005 Ralph Thomas Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /****************************************************************************************************/ // // This is the implementation of the class which looks up widget metrics on // Windows systems. It has two implementations, one uses UxTheme to look up // widget metrics, and the other uses constant values (and is used on systems // where UxTheme is unavailable or Visual Styles are disabled). // /****************************************************************************************************/ #include "metrics.hpp" #include <sstream> /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ // /// This implementation of metrics_t uses the Win32 library to lookup font attributes. /// It returns constant values for other metrics. // class metrics_win32_t : public metrics_t { // /// Store the class name of the window which we're currently examining. // std::wstring class_name_m; protected: // /// Return the window class which we are currently returing metrics for. /// /// \return the current window class. // std::wstring get_window_class() const { return class_name_m; } public: // // from metrics_t // bool set_window(HWND window) { WCHAR class_name_buf[50]; if (!GetClassNameW(window, class_name_buf, 50)) return false; class_name_m = class_name_buf; return true; } bool get_font(int widget_type, LOGFONTW& out_font) const { // // On plain windows everything uses DEFAULT_GUI_FONT. // HGDIOBJ font = GetStockObject(DEFAULT_GUI_FONT); if (!font) return false; // // Extract a LOGFONTW from the HFONT. // int rv = GetObject(font, sizeof(out_font), reinterpret_cast<LPVOID>(&out_font)); DeleteObject(font); return (rv != 0); } bool get_font_metrics(int widget_type, TEXTMETRIC& out_metrics) const { // // Try to use the font from get_font before we fall back to DEFAULT_GUI_FONT. // LOGFONTW logical_font = { 0 }; HGDIOBJ font = 0; HDC tmp_dc = GetDC(0); if (get_font(widget_type, logical_font)) { font = (HGDIOBJ)CreateFontIndirectW(&logical_font); } if (!font) font = GetStockObject(DEFAULT_GUI_FONT); // // Get the metrics. // HGDIOBJ oldFont = SelectObject(tmp_dc, font); BOOL have_metrics = GetTextMetrics(tmp_dc, &out_metrics); // // Clean up. // DeleteObject(SelectObject(tmp_dc, oldFont)); ReleaseDC(0, tmp_dc); return have_metrics; } bool get_text_extents(int widget_type, std::wstring text, RECT& out_extents) const { // // Create the font and select it into a temporary device context. // HDC tmp_dc = GetDC(0); LOGFONTW logical_font = {0}; HGDIOBJ font = 0; // // Try to use get_font, in case there is another font we're meant // to use. Then fallback on DEFAULT_GUI_FONT. // if (get_font(widget_type, logical_font)) { font = (HGDIOBJ)CreateFontIndirectW(&logical_font); } if (!font) font = GetStockObject(DEFAULT_GUI_FONT); // // Extract the extents. // HGDIOBJ original_font = SelectObject(tmp_dc, font); SIZE out_size = {0, 0}; bool have_extents = GetTextExtentPoint32W(tmp_dc, text.c_str(), text.size(), &out_size); // // Clean up, and convert the size to a rect. // DeleteObject(SelectObject(tmp_dc, original_font)); ReleaseDC(0, tmp_dc); out_extents.left = 0; out_extents.top = 0; out_extents.right = out_size.cx; out_extents.bottom = out_size.cy; return have_extents; } bool get_integer(int widget_type, int measurement, int& out_val) const { if ((widget_type == CP_DROPDOWNBUTTON) && (measurement == TMT_BORDERSIZE) && (class_name_m == L"ComboBox")) { out_val = 1; return true; } out_val = 0; return false; } bool get_size(int widget_type, THEMESIZE measurement, SIZE& out_size) const { if (class_name_m == L"Button") { if ((widget_type == BP_CHECKBOX) || (widget_type == BP_RADIOBUTTON)) { // // Strictly the width of the checkbox widget is 13 pixels. // This adds some padding so that letters don't get clipped. // out_size.cx = 23; out_size.cy = 13; return true; } if (widget_type == BP_GROUPBOX) { out_size.cx = 8; out_size.cy = 8; return true; } out_size.cx = 0; out_size.cy = 0; return true; } out_size.cx = 0; out_size.cy = 0; return false; } bool get_margins(int widget_type, MARGINS& out_margins) const { if ((class_name_m == L"Button") && (widget_type == BP_PUSHBUTTON)) { out_margins.cxLeftWidth = 3; out_margins.cxRightWidth = 3; out_margins.cyTopHeight = 3; out_margins.cyBottomHeight = 3; return true; } return false; } }; /****************************************************************************************************/ const int kState = 1; // /// This implementation of metrics_t uses the UxTheme library to obtain widget metrics. /// It inherits from the plain Win32 implementation because it occasionally falls back /// on the font functions. // class metrics_uxtheme_t : public metrics_win32_t { typedef metrics_win32_t _super; // // Handle to the UxTheme.DLL. // HMODULE theme_dll_m; // // Handle to the theme which we are currently using. // HTHEME theme_m; // // Technically all of these calls are supposed to use a state parameter. We are // only obtaining metrics, rather than drawing, so we don't actually need to // specify any particular state (as metrics should be invariant over all states). // // According to the tmschema.h (in the Platform SDK) a state of 1 should always // work. // // const int kState; // // Because we open UxTheme.DLL dynamically we need to keep function pointers into // the library. These are those. // typedef HTHEME (__stdcall *OpenThemeData_t)(HWND hwnd, LPCWSTR pszClassList); typedef HRESULT (__stdcall *CloseThemeData_t)(HTHEME hTheme); typedef HRESULT (__stdcall *GetThemeMargins_t)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, RECT* prc, MARGINS* pMargins); typedef HRESULT (__stdcall *GetThemePartSize_t)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, RECT* pRect, enum THEMESIZE eSize, SIZE* psz); typedef HRESULT (__stdcall *GetThemeInt_t)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, int* piVal); typedef HRESULT (__stdcall *GetThemeTextExtent_t)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, const RECT* pBoundingRect, RECT* pExtentRect); typedef HRESULT (__stdcall *GetThemeTextMetrics_t)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, TEXTMETRIC* ptm); 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 BOOL (__stdcall *IsThemeActive_t)(void); OpenThemeData_t OpenThemeDataPtr; CloseThemeData_t CloseThemeDataPtr; GetThemeMargins_t GetThemeMarginsPtr; GetThemePartSize_t GetThemePartSizePtr; GetThemeInt_t GetThemeIntPtr; GetThemeTextExtent_t GetThemeTextExtentPtr; GetThemeTextMetrics_t GetThemeTextMetricsPtr; GetThemeFont_t GetThemeFontPtr; GetThemeSysFont_t GetThemeSysFontPtr; IsThemeActive_t IsThemeActivePtr; // // We only ever try to load UxTheme.DLL once, this boolean tells us if we were // successful. // bool loaded_m; public: metrics_uxtheme_t() : theme_dll_m(0), theme_m(0), OpenThemeDataPtr(0), CloseThemeDataPtr(0), GetThemeMarginsPtr(0), GetThemePartSizePtr(0), GetThemeIntPtr(0), GetThemeTextExtentPtr(0), GetThemeTextMetricsPtr(0), GetThemeFontPtr(0), GetThemeSysFontPtr(0), IsThemeActivePtr(0), loaded_m(false) { // // Try to load the UxTheme library, if we can. // theme_dll_m = LoadLibrary("UxTheme.dll"); if (!theme_dll_m) return; // // Load the addresses of the UxTheme functions. // if (!(OpenThemeDataPtr = (OpenThemeData_t)GetProcAddress(theme_dll_m, "OpenThemeData"))) return; if (!(CloseThemeDataPtr = (CloseThemeData_t)GetProcAddress(theme_dll_m, "CloseThemeData"))) return; if (!(GetThemeMarginsPtr = (GetThemeMargins_t)GetProcAddress(theme_dll_m, "GetThemeMargins"))) return; if (!(GetThemePartSizePtr = (GetThemePartSize_t)GetProcAddress(theme_dll_m, "GetThemePartSize"))) return; if (!(GetThemeIntPtr = (GetThemeInt_t)GetProcAddress(theme_dll_m, "GetThemeInt"))) return; if (!(GetThemeTextExtentPtr = (GetThemeTextExtent_t)GetProcAddress(theme_dll_m, "GetThemeTextExtent"))) return; if (!(GetThemeTextMetricsPtr = (GetThemeTextMetrics_t)GetProcAddress(theme_dll_m, "GetThemeTextMetrics"))) return; if (!(GetThemeFontPtr = (GetThemeFont_t)GetProcAddress(theme_dll_m, "GetThemeFont"))) return; if (!(GetThemeSysFontPtr = (GetThemeSysFont_t)GetProcAddress(theme_dll_m, "GetThemeSysFont"))) return; if (!(IsThemeActivePtr = (IsThemeActive_t)GetProcAddress(theme_dll_m, "IsThemeActive"))) return; // // All loaded! // loaded_m = true; } ~metrics_uxtheme_t() { if (theme_dll_m) FreeLibrary(theme_dll_m); } // /// This function returns true if the theme is active. If the theme /// is not active then the plain win32 metrics object should be used. // bool theme_active() const { if (!loaded_m) return false; return (*IsThemeActivePtr)(); } // // from metrics_t // bool set_window(HWND win) { if (!_super::set_window(win)) return false; // // Close any already open theme data, and load up the new // data. // if (theme_m) (*CloseThemeDataPtr)(theme_m); theme_m = (*OpenThemeDataPtr)(win, get_window_class().c_str()); return (theme_m != 0); } bool get_font(int widget_type, LOGFONTW& out_font) const { // // We need ensure that we have a handle to the theme before // continuing. // if (!theme_m) return false; if (widget_type != -1) { HRESULT hr = (*GetThemeFontPtr)(theme_m, 0, widget_type, kState, TMT_FONT, &out_font); if (hr == S_OK) return true; } // // This widget is a text label, most likely. Give it the // standard message box font. // if (S_OK == (*GetThemeSysFontPtr)(theme_m, TMT_MSGBOXFONT, &out_font)) return true; return false; } bool get_font_metrics(int widget_type, TEXTMETRIC& out_metrics) const { // // Use GetThemeMetrics for anything which isn't a text label. // if ((widget_type != -1) && theme_m) { HRESULT hr = (*GetThemeTextMetricsPtr)(theme_m, 0, widget_type, kState, &out_metrics); if (hr == S_OK) return true; } // // Let the Win32 code handle it. When the Win32 code tries to // call get_font it will call the UxTheme implementation, so // we will always use the correct font here. // return _super::get_font_metrics(widget_type, out_metrics); } bool get_text_extents(int widget_type, std::wstring text, RECT& out_extents) const { // // We can only work if we have a non-label widget type and // valid theme handle. // if ((widget_type != -1) && theme_m) { HDC tmp_dc = GetDC(0); HRESULT hr = (*GetThemeTextExtentPtr)(theme_m, tmp_dc, widget_type, kState, text.c_str(), text.size(), 0, 0, &out_extents); ReleaseDC(0, tmp_dc); if (hr == S_OK) return true; } // // That seemed to go wrong. // return _super::get_text_extents(widget_type, text, out_extents); } bool get_integer(int widget_type, int measurement, int& out_val) const { // // We don't fallback from this function. // if ((!theme_m) || (widget_type == -1)) return false; return (S_OK == (*GetThemeIntPtr)(theme_m, widget_type, kState, measurement, &out_val)); } bool get_size(int widget_type, THEMESIZE measurement, SIZE& out_size) const { // // We don't fallback from this function. // if ((!theme_m) || (widget_type == -1)) return false; // // Create a temporary device context and call GetThemePartSize. // HDC tmp_dc = GetDC(0); HRESULT hr = (*GetThemePartSizePtr)(theme_m, tmp_dc, widget_type, kState, 0, measurement, &out_size); ReleaseDC(0, tmp_dc); return (hr == S_OK); } bool get_margins(int widget_type, MARGINS& out_margins) const { // // We don't fall back from this function. // if ((!theme_m) || (widget_type == -1)) return false; // // Use GetThemeMargins call to get the margins for this widget. // return (S_OK == (*GetThemeMarginsPtr)(theme_m, 0, widget_type, kState, TMT_CONTENTMARGINS, 0, &out_margins)); } }; /****************************************************************************************************/ metrics_t& metrics_t::get_instance() { static metrics_win32_t win32_instance; static metrics_uxtheme_t uxtheme_instance; if (uxtheme_instance.theme_active()) return uxtheme_instance; return win32_instance; } /****************************************************************************************************/ } /****************************************************************************************************/ --- NEW FILE: main.cpp --- /* Copyright 2005 Ralph Thomas Distributed under the MIT License (see accompanyinf file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /****************************************************************************************************/ #include "express_viewer.hpp" #include "report_exception.hpp" #include <boost/filesystem/convenience.hpp> #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <sstream> #include <ostream> #include <string> /****************************************************************************************************/ namespace { /****************************************************************************************************/ void clip_quotes(std::string& str) { // // Sometimes GetCommandLine puts double quotes at the beginning and // end of the command line (this doesn't always happen, not if the // program was started from the prompt instead of the GUI). // if( str[0] == '"' ) str = str.substr( 1, str.size() - 2 ); } /****************************************************************************************************/ void open_document(adobe::simpleApplication* app, const std::string& filename) { boost::filesystem::path file( filename, boost::filesystem::native ); std::string extension( boost::filesystem::extension( file ) ); if ( extension == ".eve") app->set_eve_file( file ); else if ( extension == ".adm") app->set_adam_file( file ); } /****************************************************************************************************/ } // namespace /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ bool os_initialize( simpleApplication* app ) { // // We only need to set the resource path on Windows. There are no // system events to install handlers for, etc. We say that the // resource path is the folder with the executable inside. // std::stringstream temp; std::string directory_string; std::string file1; std::string file2; temp << GetCommandLine(); temp >> directory_string; clip_quotes(directory_string); // // Now we need to get a directory from the command line name. // boost::filesystem::path directory( directory_string, boost::filesystem::native ); // // Tell the application... // app->set_resource_directory( directory.branch_path() ); temp >> file1; temp >> file2; if (file1 == std::string() || file2 == std::string()) throw std::runtime_error("You must drag and drop an Adam/Eve pair onto the app"); clip_quotes(file1); clip_quotes(file2); open_document(app, file1); open_document(app, file2); return true; } /****************************************************************************************************/ void os_mainloop() { // // This is just the standard Win32 message pump. // MSG msg; while ( GetMessage( &msg, 0, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } /****************************************************************************************************/ void os_end_mainloop() { // // This is just the standard Win32 quit message. // ::PostQuitMessage(0); } /****************************************************************************************************/ } /****************************************************************************************************/ int WinMain( HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR lpCmdLine, int nCmdShow ) { try { adobe::simpleApplication* theApp = adobe::simpleApplication::getInstance(); if( theApp ) theApp->run(); } catch( ... ) { adobe::report_exception(); } return 0; } Index: ui_core_implementation.cpp =================================================================== RCS file: /cvsroot/adobe-source/adobe-source/adobe/test/visual/sources/win/ui_core_implementation.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ui_core_implementation.cpp 23 Mar 2005 18:51:38 -0000 1.3 --- ui_core_implementation.cpp 2 Apr 2005 05:47:40 -0000 1.4 *************** *** 11,14 **** --- 11,15 ---- #include "report_exception.hpp" #include "display.hpp" + #include "metrics.hpp" #include <adobe/value.hpp> *************** *** 101,114 **** std::string convert_utf(const WCHAR* buffer, std::size_t size) { [...3454 lines suppressed...] + void slider_t::implementation_t::set_min_value(long min_value) + { + } + + /****************************************************************************************************/ + + void slider_t::implementation_t::set_max_value(long max_value) + { + } + + /****************************************************************************************************/ + + void slider_t::implementation_t::set_value(long value) + { + } + + /****************************************************************************************************/ + void slider_t::implementation_t::signal_value_change(const implementation::slider_value_proc_t& proc) { |