diff --git a/include/nana/any.hpp b/include/nana/any.hpp index de3e7703..491169fc 100644 --- a/include/nana/any.hpp +++ b/include/nana/any.hpp @@ -1,145 +1,159 @@ +/** + * Any + * Nana C++ Library(http://www.nanapro.org) + * Copyright(C) 2003-2016 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/any.hpp + * + * @brief An implementation of experimental library any of C++ standard(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html#any) + */ + #ifndef NANA_ANY_HPP #define NANA_ANY_HPP #include -#include //C++11 for std::move +#include + +#include "c++defines.hpp" namespace nana { + class bad_any_cast + : public std::bad_cast + { + }; + class any { - struct super_type + class content_interface { - virtual ~super_type(); - super_type& operator=(const super_type&); - virtual super_type& assign(const super_type&) = 0; - virtual bool same(const super_type&) const = 0; - virtual super_type* clone() const = 0; - }; //end struct super_type - - template - struct object_type - : public super_type - { - object_type(){} + public: + virtual ~content_interface() = default; - object_type(T const & obj) - : object(obj) + virtual const std::type_info& type() const noexcept = 0; + virtual content_interface* clone() const = 0; + }; + + template + class holder : public content_interface + { + holder& operator=(const holder&) = delete; + public: + holder(const Value& other) + : value(other) {} - object_type(T && obj) - : object(std::move(obj)) + holder(Value&& other) + : value(static_cast(other)) {} - - object_type(const object_type& rhs) - :object(rhs.object) - {} - - virtual super_type& assign(const super_type& rhs) + public: + const std::type_info& type() const noexcept override { - if(this != &rhs) - { - auto other = dynamic_cast(&rhs); - if(other) - object = other->object; - } - return *this; + return typeid(Value); } - - virtual bool same(const super_type& rhs) const + + content_interface* clone() const override { - return (dynamic_cast(&rhs) != nullptr); + return new holder(value); } - - virtual super_type* clone() const - { - return new object_type(object); - } - - T object; - }; //end struct object_type + public: + Value value; //representation accessable for friend of any + }; public: - template - any(const T & obj) - : super_(new object_type::type>(obj)) - {} + //constructors and destructor + any() noexcept; - template - any(T && obj) - : super_(new object_type::type>(std::move(obj))) - {} + any(const any& other); + any(any&& other) noexcept; + + template + any(Value && value, + typename std::enable_if::value>::type * = nullptr, + typename std::enable_if::value>::type* = nullptr) + : content_(new holder::type>(static_cast(value))) + { + } - any(); - any(const any&); - any(any&&); ~any(); - - bool same(const any &) const; - any& operator=(const any&); - any& operator=(any&&); - - template - any& operator=(T const &rhs) + + //assignments + any& operator=(const any& other); + any& operator=(any&& other) noexcept; + + template + any& operator=(Value&& other) { - T * obj = get(); - if(nullptr == obj) - { - delete super_; - super_ = new object_type(rhs); - } - else - *obj = rhs; + any(other).swap(*this); return *this; } - template - any & operator=(T && rhs) - { - typedef typename std::remove_cv::type>::type type; - type* obj = get(); - if(nullptr == obj) - { - delete super_; - super_ = new object_type(std::move(rhs)); - } - else - *obj = std::move(rhs); - return *this; - } - - template - T * get() const - { - if(super_) - { - typedef typename std::remove_const::type type; - object_type* obj = dynamic_cast*>(super_); - if(obj) return &(obj->object); - } - return nullptr; - } - - template - operator T&() const - { - typedef typename std::remove_const::type type; - type *obj = get(); + //modifiers + void clear() noexcept; + void swap(any& other) noexcept; - if(nullptr == obj) - throw std::bad_cast(); - - return *obj; - } - - template - operator T*() const - { - typedef typename std::remove_const::type type; - return get(); - } + //observers + bool empty() const noexcept; + const std::type_info& type() const noexcept; private: - super_type * super_; + template + friend Value* any_cast(any*) noexcept; + private: + content_interface * content_; }; + + // Non-member functions + inline void swap(any& x, any& y) noexcept + { + x.swap(y); + } + + template + Value any_cast(const any& operand) + { + using value_type = typename std::remove_reference::type; + return any_cast(const_cast(operand)); + } + + template + Value any_cast(any& operand) + { + using value_type = typename std::remove_reference::type; + + auto value_ptr = any_cast(&operand); + if (!value_ptr) + throw bad_any_cast(); + + using ref_type = typename std::conditional::value, Value, typename std::add_lvalue_reference::type>::type; + return static_cast(*value_ptr); + } + + template + Value any_cast(any && operand) + { + static_assert(std::is_rvalue_reference::value || std::is_const::type>::value, "nana::any_cast shall not be used for getting non-const reference to temporary objects"); + return any_cast(operand); + } + + template + const Value* any_cast(const any* operand) noexcept + { + return any_cast(const_cast(operand)); + } + + template + Value* any_cast(any* operand) noexcept + { + if (!operand) + return nullptr; + + auto holder = dynamic_cast*>(operand->content_); + return (holder ? &holder->value : nullptr); + } + }//end namespace nana #endif diff --git a/include/nana/c++defines.hpp b/include/nana/c++defines.hpp index 8af6ae5a..d22c5bcc 100644 --- a/include/nana/c++defines.hpp +++ b/include/nana/c++defines.hpp @@ -43,6 +43,21 @@ #ifndef NANA_CXX_DEFINES_INCLUDED #define NANA_CXX_DEFINES_INCLUDED +//C++ language +#if defined(_MSC_VER) +# if (_MSC_VER < 1900) +# //Nana defines some macros for lack of support of keywords +# define _ALLOW_KEYWORD_MACROS +# +# define noexcept //no support of noexcept until Visual C++ 2015 +# define constexpr //no support of constexpr until Visual C++ 2015 +# endif +#elif defined(__GNUC__) +# if (__GNUC__ == 4 && __GNUC_MINOR__ < 6) +# define noexcept //no support of noexcept until GCC 4.6 +# endif +#endif + // Select platform ...... #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) //Microsoft Windows #define NANA_WINDOWS diff --git a/include/nana/concepts.hpp b/include/nana/concepts.hpp index fb9fddf9..dea4637d 100644 --- a/include/nana/concepts.hpp +++ b/include/nana/concepts.hpp @@ -1,6 +1,6 @@ /* * A Concepts Definition of Nana C++ Library - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -22,7 +22,7 @@ namespace nana class any_objective { public: - virtual ~any_objective(){} + virtual ~any_objective() = default; template void anyobj(const Target& t) @@ -37,7 +37,7 @@ namespace nana void anyobj(Target&& t) { nana::any * p = _m_anyobj(true); - if(nullptr == 0) + if(nullptr == p) throw std::runtime_error("Nana.any_objective: Object does not exist"); *p = std::move(t); @@ -46,8 +46,7 @@ namespace nana template Target * anyobj() const ///< Retrieves the attached object. Returns a nullptr if empty or if the type not match. { - nana::any * p = _m_anyobj(false); - return (p ? p->get() : nullptr); + return any_cast(_m_anyobj(false)); } private: virtual nana::any* _m_anyobj(bool allocate_if_empty) const = 0; @@ -60,7 +59,7 @@ namespace nana public: typedef IndexType anyobj_index_t; ///< The type of index. It is available if Dimension is greater than 0. - virtual ~any_objective(){} + virtual ~any_objective() = default; template void anyobj(anyobj_index_t i, const Target& t) @@ -83,8 +82,7 @@ namespace nana template Target * anyobj(anyobj_index_t i) const ///< Retrieves the attached object. Returns a nullptr if empty or if the type not match. { - nana::any * p = _m_anyobj(i, false); - return (p ? p->get() : nullptr); + return any_cast(_m_anyobj(i, false)); } private: virtual nana::any* _m_anyobj(anyobj_index_t i, bool allocate_if_empty) const = 0; @@ -121,8 +119,7 @@ namespace nana template Target * anyobj(anyobj_index_t i0, anyobj_index_t i1) const ///< Retrieves the attached object. Returns a nullptr if empty or if the type not match. { - nana::any * p = _m_anyobj(i0, i1, false); - return (p ? p->get() : nullptr); + return any_cast(_m_anyobj(i0, i1, false)); } private: virtual nana::any* _m_anyobj(anyobj_index_t i0, anyobj_index_t i1, bool allocate_if_empty) const = 0; diff --git a/include/nana/detail/linux_X11/platform_spec.hpp b/include/nana/detail/linux_X11/platform_spec.hpp index 12f4e94a..c8866d9d 100644 --- a/include/nana/detail/linux_X11/platform_spec.hpp +++ b/include/nana/detail/linux_X11/platform_spec.hpp @@ -1,7 +1,7 @@ /* * Platform Specification Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -34,7 +34,9 @@ #include #include #include "msg_packet.hpp" -#if defined(NANA_UNICODE) + +#define NANA_USE_XFT +#if defined(NANA_USE_XFT) #include #include #include @@ -45,7 +47,7 @@ namespace nana namespace detail { class msg_dispatcher; -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) class conf { public: @@ -76,7 +78,7 @@ namespace detail bool italic; bool underline; bool strikeout; -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) XftFont * handle; #else XFontSet handle; @@ -99,7 +101,7 @@ namespace detail unsigned tab_pixels; unsigned whitespace_pixels; }string; -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) XftDraw * xftdraw{nullptr}; XftColor xft_fgcolor; const std::string charset(const std::wstring& str, const std::string& strcode); @@ -120,7 +122,7 @@ namespace detail unsigned color_{ 0xFFFFFFFF }; unsigned text_color_{ 0xFFFFFFFF }; -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) struct conv_tag { iconv_t handle; diff --git a/include/nana/gui/widgets/categorize.hpp b/include/nana/gui/widgets/categorize.hpp index b8cc69b1..3b8f5b3c 100644 --- a/include/nana/gui/widgets/categorize.hpp +++ b/include/nana/gui/widgets/categorize.hpp @@ -62,7 +62,7 @@ namespace nana void selected(::nana::any & var) { - auto vp = var.get(); + auto vp = any_cast(&var); T null_val; arg_categorize arg(widget_, vp ? *vp : null_val); diff --git a/include/nana/gui/widgets/combox.hpp b/include/nana/gui/widgets/combox.hpp index f31b3a18..4d22a30e 100644 --- a/include/nana/gui/widgets/combox.hpp +++ b/include/nana/gui/widgets/combox.hpp @@ -1,7 +1,7 @@ /** * A Combox Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -85,8 +85,7 @@ namespace nana template T * value_ptr() const { - auto p = _m_anyobj(false); - return (p ? p->get() : nullptr); + return any_cast(_m_anyobj(false)); } template @@ -96,7 +95,7 @@ namespace nana if (nullptr == pany) throw std::runtime_error("combox::item_proxy.value() is empty"); - T * p = pany->get(); + T * p = any_cast(pany); if (nullptr == p) throw std::runtime_error("combox::item_proxy.value() invalid type of value"); return *p; diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index cf2adcbf..1087f1fc 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1,7 +1,7 @@ /** * A List Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -277,8 +277,7 @@ namespace nana template T* value_ptr() const { - auto * pany = _m_value(); - return (pany ? pany->get() : nullptr); + return any_cast(_m_value()); } template @@ -288,7 +287,7 @@ namespace nana if(nullptr == pany) throw std::runtime_error("listbox::item_proxy.value() is empty"); - T * p = pany->get(); + T * p = any_cast(_m_value()); if(nullptr == p) throw std::runtime_error("listbox::item_proxy.value() invalid type of value"); return *p; diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 1981c3c7..79ed46f2 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -1,7 +1,7 @@ /** * A Tabbar implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -222,7 +222,7 @@ namespace nana value_type & operator[](std::size_t pos) const { - return static_cast(this->get_drawer_trigger().at_no_bound_check(pos)); + return any_cast(this->get_drawer_trigger().at_no_bound_check(pos)); } void activated(std::size_t pos) /// Activates a tab specified by pos. diff --git a/include/nana/gui/widgets/treebox.hpp b/include/nana/gui/widgets/treebox.hpp index 5fd7a27a..f0cc4cd1 100644 --- a/include/nana/gui/widgets/treebox.hpp +++ b/include/nana/gui/widgets/treebox.hpp @@ -1,7 +1,7 @@ /** * A Tree Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -288,15 +288,15 @@ namespace nana bool operator!=(const item_proxy&) const; template - T * value_ptr() const + const T * value_ptr() const { - return _m_value().get(); + return any_cast(&_m_value()); } template - T& value() const + const T& value() const { - T* p = _m_value().get(); + auto p = any_cast(&_m_value()); if(nullptr == p) throw std::runtime_error("treebox::value() Invalid type of value."); return *p; diff --git a/source/any.cpp b/source/any.cpp index 4858d96b..3a656903 100644 --- a/source/any.cpp +++ b/source/any.cpp @@ -1,70 +1,87 @@ -#include +/** +* Any +* Nana C++ Library(http://www.nanapro.org) +* Copyright(C) 2003-2016 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/any.cpp +* +* @brief An implementation of experimental library any of C++ standard(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html#any) +*/ +#include +#include namespace nana { + //constructors and destructor + any::any() noexcept + : content_(nullptr) + { + } - //class any - //struct super_type - any::super_type::~super_type(){} - - any::super_type& any::super_type::operator=(const super_type &rhs) - { - return assign(rhs); - } - //end struct super_type + any::any(const any& other) + : content_(other.content_ ? other.content_->clone() : nullptr) + {} - any::any() - :super_(nullptr) - {} - - any::any(const any& rhs) - :super_(rhs.super_ ? rhs.super_->clone() : nullptr) - {} + any::any(any && other) noexcept + : content_(other.content_) + { + other.content_ = nullptr; + } - any::any(any&& r) - :super_(r.super_) - { - r.super_ = nullptr; - } - - any::~any() - { - delete super_; - } - - any& any::operator=(const any& rhs) - { - if(this != &rhs) - { - delete super_; - super_ = (rhs.super_ ? rhs.super_->clone() : nullptr); - } - return *this; - } + any::~any() + { + delete content_; + } - any& any::operator=(any&& r) - { - if(this != &r) - { - delete super_; - super_ = r.super_; - r.super_ = nullptr; - } - return *this; - } + //assignments + any& any::operator=(const any& other) + { + if (this != &other) + any(other).swap(*this); - bool any::same(const any &rhs) const + return *this; + } + + any& any::operator=(any&& other) noexcept + { + if (this != &other) { - if(this != &rhs) - { - if(super_ && rhs.super_) - return super_->same(*rhs.super_); - else if(super_ || rhs.super_) - return false; - } - return true; + other.swap(*this); + other.clear(); } - //end class any + return *this; + } + + //modifiers + void any::clear() noexcept + { + if (content_) + { + auto cnt = content_; + content_ = nullptr; + delete cnt; + } + } + + void any::swap(any& other) noexcept + { + std::swap(content_, other.content_); + } + + //observers + bool any::empty() const noexcept + { + return (nullptr == content_); + } + + const std::type_info& any::type() const noexcept + { + return (content_ ? content_->type() : typeid(void)); + } }//end namespace nana diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 4f277518..9713a0c9 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -1,7 +1,7 @@ /* * Platform Specification Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Nana Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -36,7 +36,7 @@ namespace nana namespace detail { typedef native_window_type native_window_type; -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) //class conf conf::conf(const char * file) { @@ -290,7 +290,7 @@ namespace detail string.tab_length = 4; string.tab_pixels = 0; string.whitespace_pixels = 0; -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) conv_.handle = ::iconv_open("UTF-8", "UTF-32"); conv_.code = "UTF-32"; #endif @@ -298,7 +298,7 @@ namespace detail drawable_impl_type::~drawable_impl_type() { -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) ::iconv_close(conv_.handle); #endif } @@ -366,7 +366,7 @@ namespace detail ::XSetForeground(spec.open_display(), context, col); ::XSetBackground(spec.open_display(), context, col); -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) xft_fgcolor.color.red = ((0xFF0000 & col) >> 16) * 0x101; xft_fgcolor.color.green = ((0xFF00 & col) >> 8) * 0x101; xft_fgcolor.color.blue = (0xFF & col) * 0x101; @@ -395,7 +395,7 @@ namespace detail } ::XSetForeground(spec.open_display(), context, rgb); ::XSetBackground(spec.open_display(), context, rgb); -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) xft_fgcolor.color.red = ((0xFF0000 & rgb) >> 16) * 0x101; xft_fgcolor.color.green = ((0xFF00 & rgb) >> 8) * 0x101; xft_fgcolor.color.blue = (0xFF & rgb) * 0x101; @@ -412,7 +412,7 @@ namespace detail if(fp && fp->handle) { platform_scope_guard psg; -#if defined(NANA_UNICODE) +#if defined(NANA_USE_XFT) ::XftFontClose(nana::detail::platform_spec::instance().open_display(), fp->handle); #else ::XFreeFontSet(nana::detail::platform_spec::instance().open_display(), fp->handle); diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 9af6c1bd..1e383e61 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -1,7 +1,7 @@ /* * A Bedrock Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -993,7 +993,7 @@ namespace detail if(input_context) { nana::detail::platform_scope_guard psg; -#if defined(NANA_UNICODE) +#if 1 //Utf8 len = ::Xutf8LookupString(input_context, &xevent.xkey, keybuf, 32, &keysym, &status); if(status == XBufferOverflow) { @@ -1088,14 +1088,12 @@ namespace detail if (msgwnd->flags.enabled) { const wchar_t* charbuf; -#if defined(NANA_UNICODE) + nana::detail::charset_conv charset("UTF-32", "UTF-8"); const std::string& str = charset.charset(std::string(keybuf, keybuf + len)); charbuf = reinterpret_cast(str.c_str()) + 1; len = str.size() / sizeof(wchar_t) - 1; -#else - charbuf = keybuf; -#endif + for(int i = 0; i < len; ++i) { arg_keyboard arg; diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index f89c400a..b9772d23 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -202,8 +202,8 @@ namespace nana ls_file_.events().mouse_down.connect_unignorable(fn_sel_file); ls_file_.set_sort_compare(0, [](const std::string& a, nana::any* fs_a, const std::string& b, nana::any* fs_b, bool reverse) -> bool { - int dira = fs_a->get()->directory ? 1 : 0; - int dirb = fs_b->get()->directory ? 1 : 0; + int dira = any_cast(fs_a)->directory ? 1 : 0; + int dirb = any_cast(fs_b)->directory ? 1 : 0; if(dira != dirb) return (reverse ? dira < dirb : dira > dirb); @@ -256,8 +256,8 @@ namespace nana }); ls_file_.set_sort_compare(2, [](const std::string& a, nana::any* anyptr_a, const std::string& b, nana::any* anyptr_b, bool reverse) -> bool { - int dir1 = anyptr_a->get()->directory ? 1 : 0; - int dir2 = anyptr_b->get()->directory ? 1 : 0; + int dir1 = any_cast(anyptr_a)->directory ? 1 : 0; + int dir2 = any_cast(anyptr_b)->directory ? 1 : 0; if(dir1 != dir2) return (reverse ? dir1 < dir2 : dir1 > dir2); @@ -265,8 +265,8 @@ namespace nana }); ls_file_.set_sort_compare(3, [this](const std::string&, nana::any* anyptr_a, const std::string&, nana::any* anyptr_b, bool reverse) -> bool { - item_fs * fsa = anyptr_a->get(); - item_fs * fsb = anyptr_b->get(); + item_fs * fsa = any_cast(anyptr_a); + item_fs * fsb = any_cast(anyptr_b); return (reverse ? fsa->bytes > fsb->bytes : fsa->bytes < fsb->bytes); }); diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index e9196ad7..cb23a4e9 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -1,7 +1,7 @@ /* * A List Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/source/paint/detail/native_paint_interface.cpp b/source/paint/detail/native_paint_interface.cpp index db3e32ac..4d2caf0d 100644 --- a/source/paint/detail/native_paint_interface.cpp +++ b/source/paint/detail/native_paint_interface.cpp @@ -1,7 +1,7 @@ /* * Platform Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -137,7 +137,7 @@ namespace detail if(::GetTextExtentPoint32(dw->context, text, static_cast(len), &size)) return nana::size(size.cx, size.cy); #elif defined(NANA_X11) - #if defined(NANA_UNICODE) + #if defined(NANA_USE_XFT) std::string utf8str = to_utf8(std::wstring(text, len)); XGlyphInfo ext; XftFont * fs = reinterpret_cast(dw->font->handle); @@ -179,7 +179,7 @@ namespace detail ::TextOut(dw->context, pos.x, pos.y, str, static_cast(len)); #elif defined(NANA_X11) auto disp = ::nana::detail::platform_spec::instance().open_display(); - #if defined(NANA_UNICODE) + #if defined(NANA_USE_XFT) auto fs = reinterpret_cast(dw->font->handle); //Fixed missing array declaration by dareg diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 3a84ca17..07153126 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -1,7 +1,7 @@ /* * Paint Graphics Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -40,7 +40,7 @@ namespace paint if(p) { Display* disp = reinterpret_cast(nana::detail::platform_spec::instance().open_display()); - #if defined(NANA_UNICODE) + #if defined(NANA_USE_XFT) ::XftDrawDestroy(p->xftdraw); #endif ::XFreeGC(disp, p->context); @@ -306,7 +306,7 @@ namespace paint Window root = ::XRootWindow(disp, screen); dw->pixmap = ::XCreatePixmap(disp, root, (sz.width ? sz.width : 1), (sz.height ? sz.height : 1), DefaultDepth(disp, screen)); dw->context = ::XCreateGC(disp, dw->pixmap, 0, 0); - #if defined(NANA_UNICODE) + #if defined(NANA_USE_XFT) dw->xftdraw = ::XftDrawCreate(disp, dw->pixmap, spec.screen_visual(), spec.colormap()); #endif #endif @@ -442,7 +442,8 @@ namespace paint pxbuf[i] = (str[i] == '\t' ? tab_pixels : dx[i] - dx[i - 1]); } delete [] dx; -#elif defined(NANA_X11) +#elif defined(NANA_X11) && defined(NANA_USE_XFT) + Display * disp = nana::detail::platform_spec::instance().open_display(); XftFont * xft = handle_->font->handle; @@ -465,7 +466,6 @@ namespace paint nana::size graphics::bidi_extent_size(const std::wstring& str) const { nana::size sz; -#if defined NANA_UNICODE if(handle_ && handle_->context && str.size()) { std::vector reordered; @@ -479,7 +479,6 @@ namespace paint sz.height = t.height; } } -#endif return sz; } @@ -502,7 +501,7 @@ namespace paint #elif defined(NANA_X11) if(handle_->font) { - #if defined(NANA_UNICODE) + #if defined(NANA_USE_XFT) XftFont * fs = reinterpret_cast(handle_->font->handle); ascent = fs->ascent; descent = fs->descent;