Merge branch 'hotfix-1.2' into prepare-utf8

This commit is contained in:
Jinhao
2015-12-04 23:44:11 +08:00
28 changed files with 351 additions and 236 deletions

View File

@@ -3,7 +3,7 @@
#include <nana/deploy.hpp>
#include <nana/audio/detail/audio_stream.hpp>
#if defined(NANA_MINGW) && defined(STD_THREAD_NOT_SUPPORTED)
#if defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_thread.hpp>
#include <nana/std_mutex.hpp>
#include <nana/std_condition_variable.hpp>

View File

@@ -1,3 +1,17 @@
/**
* The charset Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 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/charset.hpp
*
*
*/
#ifndef NANA_CHARSET_HPP
#define NANA_CHARSET_HPP
#include <string>
@@ -13,6 +27,7 @@ namespace nana
{
class charset_encoding_interface;
}
/// An intelligent charset class for character code conversion.
class charset
{

View File

@@ -1,7 +1,7 @@
/*
/**
* Nana Configuration
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -13,57 +13,131 @@
#ifndef NANA_CONFIG_HPP
#define NANA_CONFIG_HPP
#if defined(_MSC_VER)
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning(disable : 4996)
// Select platform ......
#if (_MSC_VER < 1900)
// is this a good idea?
#define NOT_IMPLEMENTED_KEYWORD_noexcept
#endif // _MSC_VER < 1900
#if (_MSC_VER == 1900)
// google: break any code that tries to use codecvt<char16_t> or codecvt<char32_t>.
// google: It appears the C++ libs haven't been compiled with native char16_t/char32_t support.
// google: Those definitions are for codecvt<wchar_t>::id, codecvt<unsigned short>::id and codecvt<char>::id respectively.
// However, the codecvt<char16_t>::id and codecvt<char32_t>::id definitions aren't there, and indeed, if you look at locale0.cpp in the CRT source code you'll see they're not defined at all.
// google: That's a known issue, tracked by an active bug (DevDiv#1060849). We were able to update the STL's headers in response to char16_t/char32_t, but we still need to update the separately compiled sources.
#define STD_CODECVT_NOT_SUPPORTED
#endif // _MSC_VER == 1900
#endif // _MSVC
// Windows:
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
//Select platform automatically
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
//Windows:
#define NANA_WINDOWS 1
#define NANA_WINDOWS 1
//Test if it is MINGW
#if defined(__MINGW32__) || defined(__MINGW64__)
#define NANA_MINGW
#define STD_CODECVT_NOT_SUPPORTED
#if (__GNUC__ == 4) && ((__GNUC_MINOR__ < 8) || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ < 1))
// compilers in Windows...
// MSVC++ versions
#if defined(_MSC_VER)
#define _SCL_SECURE_NO_WARNNGS
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning(disable : 4996)
#if (_MSC_VER == 1900)
// google: break any code that tries to use codecvt<char16_t> or codecvt<char32_t>.
// google: It appears the C++ libs haven't been compiled with native char16_t/char32_t support.
// google: Those definitions are for codecvt<wchar_t>::id, codecvt<unsigned short>::id and codecvt<char>::id respectively.
// However, the codecvt<char16_t>::id and codecvt<char32_t>::id definitions aren't there, and indeed, if you look at locale0.cpp in the CRT source code you'll see they're not defined at all.
// google: That's a known issue, tracked by an active bug (DevDiv#1060849). We were able to update the STL's headers in response to char16_t/char32_t, but we still need to update the separately compiled sources.
#define STD_CODECVT_NOT_SUPPORTED
#endif // _MSC_VER == 1900
#endif // _MSVC
// MINGW ...
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(MINGW)
#define NANA_MINGW
//#define STD_THREAD_NOT_SUPPORTED // don't works? why? where __GNUC__, etc. are set? by CLion ??
//Use this flag if MinGW version is older than 4.8.1
#define STD_THREAD_NOT_SUPPORTED
#if ((__GNUC__ == 4) && ((__GNUC_MINOR__ < 8) || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ < 2)))
// don't works? why? where __GNUC__, etc. are set? by CLion ??
// ??
#define UNDEFINED_to_string
// https://github.com/meganz/mingw-std-threads
#define STD_THREAD_NOT_SUPPORTED
#define USE_github_com_meganz_mingw_std_threads
#endif
#endif // MINGW
// end Windows
// MacOS: who define APPLE ??
//#define APPLE
#elif defined(APPLE)
#define NANA_MACOS 1
#define NANA_X11 1
// how to add this: include_directories(/opt/X11/include/)
// end MacOS
// Linux: (not sure about __GNU__ ??)
#elif (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC)
#define NANA_LINUX 1
#define NANA_X11 1
// end Linux
#else
# static_assert(false, "Only Windows and Unix are supported now (Mac OS is experimental)");
#endif // Select platform
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#undef NANA_WINDOWS
#endif
// End Select platform ......
// compilers ...
// temp
//#define STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED // don't works?
//#define STD_CODECVT_NOT_SUPPORTED
// GCC ...
#if defined(__GNU__)
#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ <= 1)
// don't works?
//GCC 4.7.0 does not implement the <codecvt> and codecvt_utfx classes ??
#define STD_CODECVT_NOT_SUPPORTED
//Some functions which are specified in 21.5 Numeric conversions in Strings library have not yet implemented
//Implement workarounds for GCC/MinGW which version is below 4.8.2
#define STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED
#endif
#endif
#elif (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC)
//Linux:
#define NANA_LINUX 1
#define NANA_X11 1
#define STD_CODECVT_NOT_SUPPORTED
#else
# static_assert(false, "Only Windows and Unix are supported now (Mac OS is experimental)");
#endif
#endif // GCC
// End compilers ...
#if defined(NANA_MINGW) || defined(NANA_LINUX)
#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ <= 1)
//Some functions which are specified in 21.5 Numeric conversions in Strings library have not yet implemented
#define STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED
// Here defines some flags that tell Nana what features will be supported.
///////////////////
//Support for PNG
// Define the NANA_ENABLE_PNG to enable the support of PNG.
//
//#define NANA_ENABLE_PNG //!
//#define USE_LIBPNG_FROM_OS // Un-Comment it to use libpng from operating system.
#if defined(NANA_ENABLE_PNG)
#if not defined(USE_LIBPNG_FROM_OS)
#define NANA_LIBPNG
#endif
#endif
//Here defines some flags that tell Nana what features will be supported.
#define NANA_UNICODE
///////////////////
//Support for JPEG
// Define the NANA_ENABLE_JPEG to enable the support of JPEG.
//
//#define NANA_ENABLE_JPEG //!
//#define USE_LIBJPEG_FROM_OS // Un-Comment it to use libjpeg from operating system.
#if defined(NANA_ENABLE_JPEG)
#if not defined(USE_LIBJPEG_FROM_OS)
#define NANA_LIBJPEG
#endif
#endif
// always define NANA_UNICODE ?? it will be deprecated ?.
#ifndef NANA_UNICODE
#define NANA_UNICODE
#endif
#if defined(NANA_UNICODE) && defined(NANA_WINDOWS)
#ifndef _UNICODE
@@ -75,23 +149,5 @@
#endif
#endif
///////////////////
//Support for PNG
// Define the NANA_ENABLE_PNG to enable the support of PNG.
//
//#define NANA_ENABLE_PNG //!
#if defined(NANA_ENABLE_PNG)
#define NANA_LIBPNG //Comment it to use libpng from operating system.
#endif
///////////////////
//Support for JPEG
// Define the NANA_ENABLE_JPEG to enable the support of JPEG.
//
//#define NANA_ENABLE_JPEG //!
#if defined(NANA_ENABLE_JPEG)
#define NANA_LIBJPEG //Comment this whole line to use libjpeg from operating system.
#endif
#endif //NANA_CONFIG_HPP

View File

@@ -19,9 +19,7 @@
#include <nana/config.hpp>
#include <nana/charset.hpp>
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#undef NANA_WINDOWS
#endif
//Implement workarounds for GCC/MinGW which version is below 4.8.2
#if defined(STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED)

View File

@@ -13,6 +13,8 @@
* This file should not be included by any header files.
*/
#if defined(NANA_LINUX) || defined(NANA_MACOS)
#ifndef NANA_DETAIL_PLATFORM_SPEC_HPP
#define NANA_DETAIL_PLATFORM_SPEC_HPP
@@ -323,5 +325,9 @@ namespace detail
}//end namespace nana
// .h ward
#endif
//#if defined(NANA_LINUX) || defined(NANA_MACOS)
#endif

View File

@@ -12,6 +12,7 @@
* This file provides basis class and data structrue that required by nana
* This file should not be included by any header files.
*/
#if defined(NANA_WINDOWS)
#ifndef NANA_DETAIL_PLATFORM_SPEC_HPP
#define NANA_DETAIL_PLATFORM_SPEC_HPP
@@ -198,4 +199,9 @@ namespace detail
}//end namespace detail
}//end namespace nana
// .h ward
#endif
//#if defined(NANA_WINDOWS)
#endif

View File

@@ -5,7 +5,7 @@
#include <unordered_set>
#include <unordered_map>
#if defined(NANA_MINGW) && defined(STD_THREAD_NOT_SUPPORTED)
#if defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_mutex.hpp>
#else
#include <mutex>

View File

@@ -17,7 +17,7 @@
#include <nana/traits.hpp>
#include <nana/config.hpp>
#if defined(NANA_MINGW) && defined(STD_THREAD_NOT_SUPPORTED)
#if defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_mutex.hpp>
#else
#include <mutex>

View File

@@ -106,7 +106,7 @@ namespace detail
//@brief: Delete window handle, the handle type must be a root and a frame.
void destroy_handle(core_window_t*);
void default_icon(const paint::image& small_icon, const paint::image& big_icon);
void default_icon(const paint::image& _small_icon, const paint::image& big_icon);
void icon(core_window_t*, const paint::image& small_icon, const paint::image& big_icon);
//show

View File

@@ -40,7 +40,9 @@ namespace nana
: arg_tabbar<T>({wdg, v})
{}
bool remove = true;
bool remove = true; ///< determines whether to remove the item
bool close_attach_window = true; ///< determines whether to close the attached window. It is ignored if remove is false
};
namespace drawerbase
@@ -51,11 +53,11 @@ namespace nana
struct tabbar_events
: public general_events
{
typedef T value_type;
using value_type = T;
basic_event<arg_tabbar<value_type>> added;
basic_event<arg_tabbar<value_type>> activated;
basic_event<arg_tabbar<value_type>> removed;
basic_event<arg_tabbar_removed<value_type>> removed;
};
class event_agent_interface
@@ -64,7 +66,7 @@ namespace nana
virtual ~event_agent_interface() = default;
virtual void added(std::size_t) = 0;
virtual void activated(std::size_t) = 0;
virtual bool removed(std::size_t) = 0;
virtual bool removed(std::size_t, bool & close_attached) = 0;
};
class item_renderer
@@ -98,7 +100,7 @@ namespace nana
: public event_agent_interface
{
public:
typedef ::nana::arg_tabbar<T> arg_tabbar;
using arg_tabbar = ::nana::arg_tabbar<T>;
event_agent(::nana::tabbar<T>& tb, DrawerTrigger & dtr)
: tabbar_(tb), drawer_trigger_(dtr)
@@ -119,14 +121,16 @@ namespace nana
tabbar_.events().activated.emit(arg_tabbar({ tabbar_, tabbar_[pos]}));
}
bool removed(std::size_t pos) override
bool removed(std::size_t pos, bool & close_attach) override
{
if (pos != npos)
{
::nana::arg_tabbar_removed<T> arg(tabbar_, tabbar_[pos]);
tabbar_.events().removed.emit(arg);
close_attach = arg.close_attach_window;
return arg.remove;
}
close_attach = true;
return true;
}
private:
@@ -157,10 +161,11 @@ namespace nana
const pat::cloneable<item_renderer> & ext_renderer() const;
void ext_renderer(const pat::cloneable<item_renderer>&);
void set_event_agent(event_agent_interface*);
void push_back(const nana::string&, const nana::any&);
void insert(std::size_t, nana::string&&, nana::any&&);
std::size_t length() const;
bool close_fly(bool);
void relate(size_t, window);
void attach(std::size_t, window);
void erase(std::size_t);
void tab_color(std::size_t, bool is_bgcolor, const ::nana::color&);
void tab_image(size_t, const nana::paint::image&);
void text(std::size_t, const nana::string&);
@@ -196,7 +201,7 @@ namespace nana
struct button_close{}; ///< The type identifies the close button of the tabbar's toolbox.
//This template class is deprecated, it will be removed in 1.3
/// A template class identifies the buttons of the tabbar's toolbox. Refer to notes for more details.
/// A template class identifies the buttons of the tabbar's toolbox. Refer to notes for more details.
template<typename ButtonAdd = nana::null_type, typename ButtonScroll = nana::null_type, typename ButtonList = nana::null_type, typename ButtonClose = nana::null_type>
struct button_container
{
@@ -268,7 +273,7 @@ namespace nana
void close_fly(bool fly) /// Draw or not a close button in each tab.
{
if(this->get_drawer_trigger().close_fly(fly))
if (this->get_drawer_trigger().close_fly(fly))
API::refresh_window(this->handle());
}
@@ -287,16 +292,57 @@ namespace nana
return this->get_drawer_trigger().length();
}
void push_back(const nana::string& text) /// Append a new item.
void append(const std::string& text, window attach_wd, value_type value = {})
{
auto & t = this->get_drawer_trigger();
t.push_back(text, value_type());
this->append(static_cast<std::wstring>(nana::charset(text, nana::unicode::utf8)), attach_wd);
}
void append(const std::wstring& text, window attach_wd, value_type value = {})
{
this->get_drawer_trigger().insert(::nana::npos, std::wstring(text), std::move(value));
if (attach_wd)
{
auto pos = this->get_drawer_trigger().length();
relate(pos, attach_wd);
}
API::update_window(*this);
}
void push_back(nana::string text) /// Append a new item.
{
this->get_drawer_trigger().insert(::nana::npos, std::move(text), value_type());
API::update_window(*this);
}
void insert(std::size_t pos, const std::string& text, const value_type& value = {})
{
this->insert(pos, static_cast<std::wstring>(nana::charset(text, nana::unicode::utf8)), value);
}
void insert(std::size_t pos, const std::wstring& text, const value_type& value = {})
{
if (pos > length())
throw std::out_of_range("tabbar::insert invalid position");
this->get_drawer_trigger().insert(pos, std::wstring(text), value_type(value));
API::update_window(*this);
}
//deprecated from 1.2.1, removed from 1.3
void relate(std::size_t pos, window wd) /// Binds a window to an item specified by pos, if the item is selected, shows the window, otherwise, hides it.
{
this->get_drawer_trigger().relate(pos, wd);
this->get_drawer_trigger().attach(pos, wd);
}
void attach(std::size_t pos, window wd)
{
this->get_drawer_trigger().attach(pos, wd);
}
void erase(std::size_t pos)
{
this->get_drawer_trigger().erase(pos);
}
void tab_bgcolor(std::size_t i, const ::nana::color& clr)

View File

@@ -3,10 +3,14 @@
#include <nana/config.hpp>
#if defined(STD_THREAD_NOT_SUPPORTED)
#if defined(USE_github_com_meganz_mingw_std_threads)
#include <mingw.condition_variable.h>
#else
#include <boost/thread/condition_variable.hpp>
namespace std
{
typedef boost::condition_variable condition_variable;
}
#endif
#endif // (USE_github_com_meganz_mingw_std_threads)
#endif // (STD_THREAD_NOT_SUPPORTED)
#endif // NANA_STD_CONDITION_VARIABLE_HPP

View File

@@ -3,6 +3,20 @@
#include <nana/config.hpp>
#if defined(STD_THREAD_NOT_SUPPORTED)
#if defined(USE_github_com_meganz_mingw_std_threads)
#include <windows.h>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <pthread.h>
#include <errno.h>
#include <cstdio>
// http://lxr.free-electrons.com/source/include/uapi/asm-generic/errno.h#L53
#define EPROTO 71 /* Protocol error */
#include <mingw.thread.h>
#include <mingw.mutex.h>
#else
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/locks.hpp>
@@ -18,5 +32,6 @@ namespace std
typedef boost::mutex mutex;
typedef boost::recursive_mutex recursive_mutex;
}
#endif
#endif // (USE_github_com_meganz_mingw_std_threads)
#endif // (STD_THREAD_NOT_SUPPORTED)
#endif // NANA_STD_MUTEX_HPP

View File

@@ -3,11 +3,15 @@
#include <nana/config.hpp>
#if defined(STD_THREAD_NOT_SUPPORTED)
#if defined(USE_github_com_meganz_mingw_std_threads)
#include <mingw.thread.h>
#else
#include <boost/thread.hpp>
namespace std
{
typedef boost::thread thread;
}
#endif
#endif // (USE_github_com_meganz_mingw_std_threads)
#endif // (STD_THREAD_NOT_SUPPORTED)
#endif // NANA_STD_THREAD_HPP