From: Foster B. <fos...@us...> - 2006-02-27 20:42:16
|
Update of /cvsroot/adobe-source/sandbox/adobe-source/adobe/future/widgets/sources/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8667/adobe/future/widgets/sources/win32 Modified Files: label_t_impl.cpp os_utilities.cpp Added Files: image_t_impl.cpp Log Message: image_t (icons and pictures) support for Mac and Win32, along with a GIL image factory and a (sample) Targa file format importing module for that factory. Also added alert.adm/eve as a sample for the icon support. Added the notion of a working directory to the modal dialog interface to reference external resources. Also added an alert API that leverages modal_dialog_interface. Other misc. bug fixes and changes. --- NEW FILE: image_t_impl.cpp --- /* Copyright 2005-2006 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /****************************************************************************************************/ #include <windows.h> #include <uxtheme.h> #include <tmschema.h> #define SCHEME_STRINGS 1 #include <tmschema.h> //Yes, we include this twice -- read the top of the file #include "event_dispatcher.hpp" #include "ui_core.hpp" #include "ui_core_common.hpp" #include "ui_core_implementation.hpp" #include "adobe/unicode.hpp" #include "wincast.hpp" #include "metrics.hpp" #include "image_t_impl.hpp" #include "display.hpp" #include <adobe/gil/extension/argb/argb.hpp> #include <string> #include <cassert> /****************************************************************************************************/ #define ADOBE_THROW_LAST_ERROR adobe::implementation::throw_last_error_exception(__FILE__, __LINE__) /****************************************************************************************************/ namespace { /****************************************************************************************************/ void reset_image(HWND window, GIL::rgba8_image& view) { HDC dst_dc(::GetDC(window)); HDC src_dc(::CreateCompatibleDC(dst_dc)); BITMAPINFO bitmap_info = { 0 }; VOID* pv_bits; HBITMAP bitmap_handle; LONG image_width(hackery::cast<LONG>(view.width())); LONG image_height(hackery::cast<LONG>(view.height())); bitmap_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bitmap_info.bmiHeader.biWidth = image_width; bitmap_info.bmiHeader.biHeight = image_height; bitmap_info.bmiHeader.biPlanes = 1; bitmap_info.bmiHeader.biBitCount = 32; // four 8-bit components bitmap_info.bmiHeader.biCompression = BI_RGB; bitmap_info.bmiHeader.biSizeImage = image_width * image_height * 4; bitmap_handle = ::CreateDIBSection(src_dc, &bitmap_info, DIB_RGB_COLORS, &pv_bits, NULL, 0x0); GIL::argb8_pixel* dst_bits(static_cast<GIL::argb8_pixel*>(pv_bits)); GIL::rgba8_view::iterator first(view.begin()); GIL::rgba8_view::iterator last(view.end()); std::transform(first, last, dst_bits, GIL::color_converter<GIL::argb8_pixel>()); ::SendMessage(window, STM_SETIMAGE, IMAGE_BITMAP, hackery::cast<LPARAM>(bitmap_handle)); ::ReleaseDC(window, dst_dc); } /****************************************************************************************************/ } // namespace /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ namespace implementation { /****************************************************************************************************/ extern void throw_last_error_exception(const char* file, long line); /****************************************************************************************************/ } // namespace implementation /****************************************************************************************************/ image_t::implementation_t::implementation_t(GIL::rgba8_image& image) : image_m(image) { initialize(); } /****************************************************************************************************/ image_t::implementation_t::implementation_t(const implementation_t& rhs) { image_m = rhs.image_m; // can't be constructed for some reason; must be assigned initialize(); } /****************************************************************************************************/ image_t::implementation_t& image_t::implementation_t::operator=(const implementation_t& rhs) { image_m = rhs.image_m; initialize(); return *this; } /****************************************************************************************************/ void image_t::implementation_t::place(const point_2d_t& position, const extents_t& extents) { RECT new_bounds = { position.x_m, position.y_m, position.x_m + extents.width(), position.y_m + extents.height() }; implementation::set_control_bounds(window_m.get(), new_bounds); } /****************************************************************************************************/ void image_t::implementation_t::enable(bool make_enabled) { ::EnableWindow(window_m.get(), make_enabled); } /****************************************************************************************************/ void image_t::implementation_t::initialize() { window_m.reset( ::CreateWindowExA( WS_EX_COMPOSITED, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, 0, 0, hackery::cast<int>(image_m.width()), hackery::cast<int>(image_m.height()), invisible_parent(), NULL, ::GetModuleHandle(NULL), NULL)); if (window_m.get() == NULL) ADOBE_THROW_LAST_ERROR; // now set up the bitmap reset_image(window_m.get(), image_m); } /****************************************************************************************************/ extents_t image_t::implementation_t::measure() { assert(window_m.get()); extents_t result; result.height() = hackery::cast<LONG>(image_m.height()); result.width() = hackery::cast<LONG>(image_m.width()); return result; } /****************************************************************************************************/ void image_t::implementation_t::set(GIL::rgba8_image& image) { image_m = image; reset_image(window_m.get(), image_m); } /****************************************************************************************************/ template <> HWND view_for_element< HWND, adobe::image_t >(adobe::image_t& widget) { return widget.implementation().window_m.get(); } /****************************************************************************************************/ template <> display_t::position_t insert<adobe::image_t>(display_t& display, display_t::position_t& parent, adobe::image_t& element) { HWND ref(adobe::view_for_element< HWND >(element)); return display.insert<HWND>(parent, ref); } /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ Index: label_t_impl.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/future/widgets/sources/win32/label_t_impl.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** label_t_impl.cpp 23 Feb 2006 23:28:56 -0000 1.1 --- label_t_impl.cpp 27 Feb 2006 20:41:59 -0000 1.2 *************** *** 1,2 **** --- 1,10 ---- + /* + Copyright 2005-2006 Adobe Systems Incorporated + Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt + or a copy at http://opensource.adobe.com/licenses.html) + */ + + /****************************************************************************************************/ + #include <windows.h> #include <uxtheme.h> Index: os_utilities.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/future/widgets/sources/win32/os_utilities.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** os_utilities.cpp 3 Feb 2006 18:33:37 -0000 1.1 --- os_utilities.cpp 27 Feb 2006 20:41:59 -0000 1.2 *************** *** 7,11 **** /****************************************************************************************************/ ! // This file intentionally left blank /****************************************************************************************************/ --- 7,85 ---- /****************************************************************************************************/ ! #define WIN32_LEAN_AND_MEAN 1 ! ! #include <windows.h> ! #include <Commdlg.h> ! ! #include <adobe/future/widgets/headers/win32/os_utilities.hpp> ! #include <adobe/unicode.hpp> ! ! #include <boost/cstdint.hpp> ! ! #include <vector> ! ! /****************************************************************************************************/ ! ! namespace adobe { ! ! /****************************************************************************************************/ ! ! namespace implementation { ! ! /****************************************************************************************************/ ! ! bool pick_save_path(boost::filesystem::path& path) ! { ! // This upper part sets up the OS-specific save file dialog and ! // invokes it so the user can pick a save file location ! ! std::vector<TCHAR> path_buffer(2048, 0); ! std::vector<char> cpath_buffer; ! OPENFILENAME params = { 0 }; ! ! params.lStructSize = sizeof(params); ! params.lpstrFilter = L"Text File\0*.txt\0All Files\0*.*\0\0"; ! params.lpstrFile = &path_buffer[0]; ! params.nMaxFile = static_cast<DWORD>(path_buffer.size()); ! params.Flags = OFN_DONTADDTORECENT | ! OFN_LONGNAMES | ! OFN_NOCHANGEDIR | ! OFN_NONETWORKBUTTON | ! OFN_NOREADONLYRETURN | ! OFN_PATHMUSTEXIST; ! params.lpstrDefExt = L"txt"; ! ! bool result = GetSaveFileName(¶ms) != 0; ! ! if (result == false) ! return result; ! ! // At this point we have a path to the save file location, but we don't know ! // if the return value is utf16 or utf8. Boost::filesystem at the moment requires ! // utf8 (or ASCII?) so we need to make the conversion at runtime if necessary. ! // That's what this code does. ! ! TCHAR* end = std::find(&path_buffer[0], &path_buffer[0] + path_buffer.size(), TCHAR(0)); ! ! cpath_buffer.reserve(std::distance(&path_buffer[0], end)); ! ! adobe::to_utf8(&path_buffer[0], end, std::back_inserter(cpath_buffer)); ! ! cpath_buffer.push_back(0); ! ! // finally, construct the new path from the converted string buffer and return ! ! path = boost::filesystem::path(&cpath_buffer[0], boost::filesystem::native); ! ! return true; ! } ! ! /****************************************************************************************************/ ! ! } // namespace implementation ! ! /****************************************************************************************************/ ! ! } // namespace adobe /****************************************************************************************************/ |