elimiate nana::string for listbox

This commit is contained in:
Jinhao
2015-12-10 00:24:31 +08:00
parent 049a36e1f7
commit 112deadd16
12 changed files with 384 additions and 202 deletions

View File

@@ -102,6 +102,12 @@ namespace nana
const std::wstring& to_wstring(const std::wstring& wstr);
std::wstring&& to_wstring(std::wstring&& wstr);
#if defined(NANA_WINDOWS)
std::string to_osmbstr(const std::string& text_utf8);
#else
std::string to_osmbstr(std::string text_utf8)
#endif
namespace detail
{
@@ -113,16 +119,19 @@ namespace nana
}
#if defined(NANA_WINDOWS)
const detail::native_string_type to_native_string(const std::string&);
const detail::native_string_type& to_native_string(const std::wstring&);
detail::native_string_type to_native_string(int);
detail::native_string_type to_native_string(double);
const detail::native_string_type to_nstring(const std::string&);
const detail::native_string_type& to_nstring(const std::wstring&);
detail::native_string_type to_nstring(std::string&&);
detail::native_string_type&& to_nstring(std::wstring&&);
#else //POSIX
const detail::native_string_type& to_native_string(const std::string&);
const detail::native_string_type to_native_string(const std::wstring&);
detail::native_string_type to_native_string(int);
detail::native_string_type to_native_string(double);
const detail::native_string_type& to_nstring(const std::string&);
const detail::native_string_type to_nstring(const std::wstring&);
detail::native_string_type&& to_nstring(std::string&&);
detail::native_string_type to_nstring(std::wstring&&);
#endif
detail::native_string_type to_nstring(int);
detail::native_string_type to_nstring(double);
detail::native_string_type to_nstring(std::size_t);
}
#ifndef NANA_UNICODE

View File

@@ -31,6 +31,7 @@ namespace nana
namespace listbox
{
using size_type = std::size_t;
using native_string_type = ::nana::detail::native_string_type;
/// usefull for both absolute and display (sorted) positions
struct index_pair
@@ -81,7 +82,7 @@ namespace nana
using selection = std::vector<index_pair>;
using inline_notifier_interface = detail::inline_widget_notifier_interface<index_pair, std::wstring>;
using inline_notifier_interface = detail::inline_widget_notifier_interface<index_pair, std::string>;
struct cell
{
@@ -94,17 +95,17 @@ namespace nana
format(const ::nana::color& bgcolor, const ::nana::color& fgcolor);
};
using format_ptr = std::unique_ptr < format > ;
using format_ptr = ::std::unique_ptr<format>;
::nana::string text;
format_ptr custom_format;
::std::string text;
format_ptr custom_format;
cell() = default;
cell(const cell&);
cell(cell&&);
cell(nana::string);
cell(nana::string, const format&);
cell(nana::string, const ::nana::color& bgcolor, const ::nana::color& fgcolor);
cell(::std::string);
cell(::std::string, const format&);
cell(::std::string, const ::nana::color& bgcolor, const ::nana::color& fgcolor);
cell& operator=(const cell&);
cell& operator=(cell&&);
@@ -126,9 +127,9 @@ namespace nana
oresolver& operator<<(double);
oresolver& operator<<(long double);
oresolver& operator<<(const char*);
oresolver& operator<<(const char* text_utf8);
oresolver& operator<<(const wchar_t*);
oresolver& operator<<(const std::string&);
oresolver& operator<<(const std::string& text_utf8);
oresolver& operator<<(const std::wstring&);
oresolver& operator<<(std::wstring&&);
oresolver& operator<<(cell);
@@ -157,7 +158,7 @@ namespace nana
iresolver& operator>>(double&);
iresolver& operator>>(long double&);
iresolver& operator>>(std::string&);
iresolver& operator>>(std::string& utf8_cast);
iresolver& operator>>(std::wstring&);
iresolver& operator>>(cell&);
iresolver& operator>>(std::nullptr_t);
@@ -241,8 +242,9 @@ namespace nana
size_type columns() const;
item_proxy& text(size_type col, cell);
item_proxy& text(size_type col, nana::string);
nana::string text(size_type col) const;
item_proxy& text(size_type col, std::string);
item_proxy& text(size_type col, std::wstring);
std::string text(size_type col) const;
void icon(const nana::paint::image&);
@@ -300,9 +302,10 @@ namespace nana
}
/// Behavior of Iterator's value_type
bool operator==(const nana::string& s) const;
bool operator==(const char * s) const;
bool operator==(const wchar_t * s) const;
bool operator==(const ::std::string& s) const;
bool operator==(const ::std::wstring& s) const;
/// Behavior of Iterator
item_proxy & operator=(const item_proxy&);
@@ -375,18 +378,20 @@ namespace nana
}
/// Appends one item at the end of this category with the specifies text in the column fields
void append(std::initializer_list<nana::string>);
void append(std::initializer_list<std::string> texts_utf8);
void append(std::initializer_list<std::wstring> texts);
size_type columns() const;
cat_proxy& text(nana::string);
nana::string text() const;
cat_proxy& text(std::string);
cat_proxy& text(std::wstring);
std::string text() const;
cat_proxy & select(bool);
bool selected() const;
/// Behavior of a container
void push_back(nana::string);
void push_back(std::string text_utf8);
item_proxy begin() const;
item_proxy end() const;
@@ -449,8 +454,8 @@ namespace nana
struct export_options
{
nana::string sep = nana::string {L"\t"},
endl= nana::string {L"\n"};
std::string sep = ::std::string {"\t"},
endl= ::std::string {"\n"};
bool only_selected_items{true},
only_checked_items {false},
only_visible_columns{true};
@@ -510,16 +515,16 @@ By \a clicking on one header the list get \a reordered, first up, and then down
and
antisymmetry(comp(a, b) != comp(b, a) returns true)
A simple example.
bool sort_compare( const nana::string& s1, nana::any*,
const nana::string& s2, nana::any*, bool reverse)
bool sort_compare( const std::string& s1, nana::any*,
const std::string& s2, nana::any*, bool reverse)
{
return (reverse ? s1 > s2 : s1 < s2);
}
listbox.set_sort_compare(0, sort_compare);
The listbox supports attaching a customer's object for each item, therefore the items can be
sorted by comparing these customer's object.
bool sort_compare( const nana::string&, nana::any* o1,
const nana::string&, nana::any* o2, bool reverse)
bool sort_compare( const std::string&, nana::any* o1,
const std::string&, nana::any* o2, bool reverse)
{
if(o1 && o2) //some items may not attach a customer object.
{
@@ -565,15 +570,19 @@ By \a clicking on one header the list get \a reordered, first up, and then down
void scroll(bool to_bottom, const index_pair& pos);
/// Appends a new column with a header text and the specified width at the end, and return it position
size_type append_header(nana::string header_text, unsigned width = 120);
size_type append_header(std::string text_utf8, unsigned width = 120);
size_type append_header(std::wstring text, unsigned width = 120);
listbox& header_width(size_type position, unsigned pixels);
unsigned header_width(size_type position) const;
unsigned auto_width(size_type position, unsigned max=3000);
cat_proxy append(nana::string); ///< Appends a new category at the end
void append(std::initializer_list<nana::string>); ///< Appends categories at the end
cat_proxy append(std::string); ///< Appends a new category to the end
cat_proxy append(std::wstring); ///< Appends a new category to the end
void append(std::initializer_list<std::string>); ///< Appends categories to the end
void append(std::initializer_list<std::wstring>); ///< Appends categories to the end
cat_proxy insert(cat_proxy, ::std::string);
cat_proxy insert(cat_proxy, ::std::wstring);
cat_proxy at(size_type pos) const;
@@ -639,8 +648,8 @@ By \a clicking on one header the list get \a reordered, first up, and then down
void sortable(bool enable);
///Sets a strict weak ordering comparer for a column
void set_sort_compare(size_type col, std::function<bool(const nana::string&, nana::any*,
const nana::string&, nana::any*, bool reverse)> strick_ordering);
void set_sort_compare(size_type col, std::function<bool(const std::string&, nana::any*,
const std::string&, nana::any*, bool reverse)> strick_ordering);
/// sort() and ivalidate any existing reference from display position to absolute item, that is: after sort() display offset point to different items
void sort_col(size_type col, bool reverse = false);

View File

@@ -1,6 +1,6 @@
/*
* Data Exchanger Implementation
* Copyright(C) 2003-2013 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
@@ -21,22 +21,26 @@ namespace paint{
}
namespace system{
/// a data exchange mechanism through Windows Clipboard, X11 Selection.
/// a data exchange mechanism through Windows Clipboard, X11 Selection.
class dataexch
{
public:
struct format
enum class format
{
enum{ text, unicode, pixmap, end};
text, pixmap
};
void set(const nana::char_t* text);
void set(const nana::string& text);
void set(const std::string & text_utf8);
void set(const std::wstring& text);
bool set(const nana::paint::graphics& g);
void get(nana::string& str);
void get(std::string& text_utf8);
void get(std::wstring& text);
private:
bool _m_set(unsigned type, const void* buf, std::size_t size);
void* _m_get(unsigned type, size_t& size);
bool _m_set(format, const void* buf, std::size_t size);
void* _m_get(format, size_t& size);
};
}//end namespace system