/* * Icon Resource * Nana C++ Library(http://www.nanapro.org) * Copyright(C) 2017 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file: nana/paint/detail/image_ico_resource.hpp */ #ifndef NANA_PAINT_DETAIL_IMAGE_ICO_RESOURCE_INCLUDED #define NANA_PAINT_DETAIL_IMAGE_ICO_RESOURCE_INCLUDED #include #include #include #if defined(NANA_WINDOWS) # include #endif namespace nana{ namespace paint { namespace detail { class image_ico_resource :public image::image_impl_interface { public: bool open(const std::experimental::filesystem::path& filename) override { #if defined(NANA_WINDOWS) SHFILEINFO sfi; ::SHGetFileInfo(filename.c_str(), 0, &sfi, sizeof sfi, SHGFI_ICON); native_handle_ = sfi.hIcon; #else static_cast(filename); //eliminate unused parameter compiler warnings #endif return (nullptr != native_handle_); } bool open(const void* /*data*/, std::size_t /*bytes*/) override { return false; } bool alpha_channel() const override { return false; } bool empty() const override { return !native_handle_; } void close() override { #if defined(NANA_WINDOWS) if (native_handle_) ::DestroyIcon(reinterpret_cast(native_handle_)); #endif } nana::size size() const override { #if defined(NANA_WINDOWS) ICONINFO info; if ((!native_handle_) || !::GetIconInfo(reinterpret_cast(native_handle_), &info)) return{}; ::nana::size sz{ info.xHotspot << 1, info.yHotspot << 1 }; ::DeleteObject(info.hbmColor); ::DeleteObject(info.hbmMask); return sz; #else return{}; #endif } virtual void paste(const nana::rectangle& src_r, graph_reference graph, const point& p_dst) const override { if (!native_handle_) return; #if defined(NANA_WINDOWS) ::DrawIconEx(graph.handle()->context, p_dst.x, p_dst.y, reinterpret_cast(native_handle_), src_r.width, src_r.height, 0, 0, DI_NORMAL); #else static_cast(src_r); //eliminate unused parameter compiler warning. static_cast(graph); static_cast(p_dst); #endif } virtual void stretch(const nana::rectangle&, graph_reference graph, const nana::rectangle& r) const override { if (!native_handle_) return; #if defined(NANA_WINDOWS) ::DrawIconEx(graph.handle()->context, r.x, r.y, reinterpret_cast(native_handle_), r.width, r.height, 0, 0, DI_NORMAL); #else static_cast(graph); //eliminate unused parameter compiler warning. static_cast(r); #endif } void* native_handle() { return native_handle_; } private: void* native_handle_; };//end class image_ico } }//end namespace paint }//end namespace nana #endif