some improvements

This commit is contained in:
Jinhao 2015-02-17 04:03:55 +08:00
parent 4385ac623d
commit 0ffa3e54ca
10 changed files with 175 additions and 161 deletions

View File

@ -50,6 +50,18 @@ namespace nana
//Workaround for no implemenation of std::stod in MinGW.
double stod(const std::string&, std::size_t * pos = nullptr);
double stod(const std::wstring&, std::size_t* pos = nullptr);
//Workaround for no implemenation of std::to_wstring in MinGW.
std::wstring to_wstring(long double);
std::wstring to_wstring(double);
std::wstring to_wstring(unsigned);
std::wstring to_wstring(int);
std::wstring to_wstring(long);
std::wstring to_wstring(unsigned long);
std::wstring to_wstring(long long);
std::wstring to_wstring(unsigned long long);
std::wstring to_wstring(float);
}
#if defined(NANA_WINDOWS)

View File

@ -30,6 +30,7 @@ namespace nana
/// Zoom the input_s to fit for ref_s
void fit_zoom(const size& input_s, const size& ref_s, size& result_s);
size fit_zoom(const size& input_s, size ref_s);
//zoom
//@brief: Calculate the scaled rectangle by refer dst rectangle, that scale factor is same as that between scaled and refer.

View File

@ -133,6 +133,105 @@ namespace nana
#endif
}
std::wstring to_wstring(double v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(long double v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(unsigned v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(int v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(long v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(unsigned long v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(long long v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(unsigned long long v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
std::wstring to_wstring(float v)
{
#ifdef NANA_MINGW
std::wstringstream ss;
ss << v;
return ss.str();
#else
return std::to_wstring(v);
#endif
}
bool is_incomplete(const nana::string& str, unsigned pos)
{
#ifndef NANA_UNICODE

View File

@ -36,12 +36,8 @@ namespace nana
struct output_t
{
drawing::diehard_t diehard;
drawing::diehard_t diehard{ nullptr };
std::vector<nana::point> points;
output_t()
: diehard(nullptr)
{}
};
struct framebuilder
@ -443,12 +439,14 @@ namespace nana
for(auto thr : threads_)
{
std::lock_guard<decltype(thr->mutex)> privlock(thr->mutex);
if ((thr->fps == p->fps) && (thr->performance_parameter / (thr->animations.size() + 1) <= 43.3))
if (thr->fps == p->fps)
{
p->thr_variable = thr;
thr->animations.push_back(p);
return;
if (thr->animations.empty() || (thr->performance_parameter * (1.0 + 1.0 / thr->animations.size()) <= 43.3))
{
p->thr_variable = thr;
thr->animations.push_back(p);
return;
}
}
}

View File

@ -1008,8 +1008,6 @@ namespace detail
arg.evt_code = event_code::mouse_up;
emit_drawer(&drawer::mouse_up, msgwnd, arg, &context);
//auto evt_ptr = msgwnd->together.events_ptr; //deprecated
if (fire_click)
{
arg.evt_code = event_code::click;

View File

@ -611,20 +611,13 @@ namespace nana
//get the longest value
int longest = (std::abs((impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(impl->last < 0 ? impl->last * 10 : impl->last) ? impl->last : impl->begin);
std::wstringstream ss;
ss << longest;
paint::graphics graph{ ::nana::size{ 10, 10 } };
auto value_px = graph.text_extent_size(ss.str()).width + 34;
auto value_px = graph.text_extent_size(::nana::to_wstring(longest)).width + 34;
impl->spinbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
impl->spinbox.range(impl->begin, impl->last, impl->step);
//impl->spinbox.set_accept_integer(); //deprecated
//Workaround for no implementation of std::to_wstring by MinGW.
ss.str(L"");
ss.clear();
ss << impl->value;
impl->spinbox.value(ss.str());
impl->spinbox.value(::nana::to_wstring(impl->value));
impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg)
{
@ -698,20 +691,13 @@ namespace nana
//get the longest value
auto longest = (std::abs((impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(impl->last < 0 ? impl->last * 10 : impl->last) ? impl->last : impl->begin);
std::wstringstream ss;
ss << longest;
paint::graphics graph{ ::nana::size{ 10, 10 } };
auto value_px = graph.text_extent_size(ss.str()).width + 34;
auto value_px = graph.text_extent_size(::nana::to_wstring(longest)).width + 34;
impl->spinbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
impl->spinbox.range(impl->begin, impl->last, impl->step);
//impl->spinbox.set_accept_real(); //deprecated
//Workaround for no implementation of std::to_wstring by MinGW.
ss.str(L"");
ss.clear();
ss << impl->value;
impl->spinbox.value(ss.str());
impl->spinbox.value(::nana::to_wstring(impl->value));
impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg)
{
@ -859,9 +845,7 @@ namespace nana
::nana::string inputbox::date::value() const
{
std::wstringstream ss;
ss << impl_->month << L'-' << impl_->day << L", " << impl_->year;
return ss.str();
return nana::to_wstring(impl_->month) + L'-' + nana::to_wstring(impl_->day) + L", " + nana::to_wstring(impl_->year);
}
int inputbox::date::year() const
@ -907,22 +891,15 @@ namespace nana
left += 104;
impl->wdg_day.create(impl->dock, rectangle{ left, 0, 38, 0 });
impl->wdg_day.range(1, ::nana::date::month_days(today.year, today.month), 1);
//impl->wdg_day.set_accept_integer(); //deprecated
left += 48;
impl->wdg_year.create(impl->dock, rectangle{left, 0, 50, 0});
impl->wdg_year.range(1601, 9999, 1);
//impl->wdg_year.set_accept_integer(); //deprecated
impl->wdg_month.option(today.month - 1);
std::wstringstream ss;
ss << today.day;
impl->wdg_day.value(ss.str());
ss.str(L"");
ss.clear();
ss << today.year;
impl->wdg_year.value(ss.str());
impl->wdg_day.value(::nana::to_wstring(today.day));
impl->wdg_year.value(::nana::to_wstring(today.year));
impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg)
{
@ -962,10 +939,8 @@ namespace nana
if (day > days)
day = days;
std::wstringstream ss;
ss << day;
impl->wdg_day.value(ss.str());
impl->wdg_day.value(::nana::to_wstring(day));
};
impl->wdg_year.events().text_changed.connect_unignorable(make_days);

View File

@ -127,15 +127,13 @@ namespace nana
if(graph.width() > 32 + border_size * 2)
{
std::stringstream ss;
ss<<chmonth_.year;
nana::string str;
if(page_ == page::date)
{
str += ::nana::internationalization()(monthstr[chmonth_.month - 1]);
str = ::nana::internationalization()(monthstr[chmonth_.month - 1]);
str += STR(" ");
}
str += nana::charset(ss.str());
str += ::nana::to_wstring(chmonth_.year);
nana::size txt_s = graph.text_extent_size(str);
@ -205,10 +203,7 @@ namespace nana
void trigger::_m_draw_pos(drawing_basis & dbasis, graph_reference graph, int x, int y, int number, bool primary, bool sel)
{
//The C++ library comes with MinGW does not provide std::to_wstring() conversion
std::wstringstream ss;
ss<<number;
_m_draw_pos(dbasis, graph, x, y, nana::charset(ss.str()), primary, sel);
_m_draw_pos(dbasis, graph, x, y, ::nana::to_wstring(number), primary, sel);
}
void trigger::_m_draw_ex_days(drawing_basis & dbasis, graph_reference graph, int begx, int begy, bool before)

View File

@ -79,15 +79,6 @@ namespace nana
}
//end struct cell
//A workaround, MinGW does not yet provide std::to_wstring
template<typename Int>
std::wstring to_wstring(Int n)
{
std::wstringstream ss;
ss << n;
return ss.str();
}
//definition of iresolver/oresolver
oresolver& oresolver::operator<<(bool n)
{
@ -96,77 +87,66 @@ namespace nana
}
oresolver& oresolver::operator<<(short n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(unsigned short n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(int n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(unsigned int n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(long n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(unsigned long n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(long long n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(unsigned long long n)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(n));
cells_.emplace_back(::nana::to_wstring(n));
return *this;
}
oresolver& oresolver::operator<<(float f)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(f));
cells_.emplace_back(::nana::to_wstring(f));
return *this;
}
oresolver& oresolver::operator<<(double f)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(f));
cells_.emplace_back(::nana::to_wstring(f));
return *this;
}
oresolver& oresolver::operator<<(long double f)
{
//A workaround, MinGW does not yet provide std::to_wstring
cells_.emplace_back(to_wstring(f));
cells_.emplace_back(::nana::to_wstring(f));
return *this;
}
@ -2373,7 +2353,7 @@ namespace nana
if(x < essence_->scroll.offset_x)
x = essence_->scroll.offset_x;
else if(x > essence_->scroll.offset_x + static_cast<int>(rect.width))
x = essence_->scroll.offset_x + rect.width;
x = essence_->scroll.offset_x + static_cast<int>(rect.width);
size_type i = essence_->header.item_by_x(x);
if(i == npos)
@ -2537,6 +2517,8 @@ namespace nana
auto idx = essence_->scroll.offset_y;
auto state = item_state::normal;
const bool sort_enabled = (essence_->lister.sort_index() != npos);
//Here draws a root categ or a first drawing is not a categ.
if(idx.cat == 0 || !idx.is_category())
{
@ -2546,30 +2528,16 @@ namespace nana
idx.item = 0;
}
//Test whether the sort is enabled.
if(essence_->lister.sort_index() != npos)
std::size_t size = i_categ->items.size();
for(std::size_t offs = essence_->scroll.offset_y.item; offs < size; ++offs, ++idx.item)
{
std::size_t size = i_categ->items.size();
for(std::size_t offs = essence_->scroll.offset_y.item; offs < size; ++offs, ++idx.item)
{
if(n-- == 0) break;
state = (tracker == idx ? item_state::highlighted : item_state::normal);
if(n-- == 0) break;
state = (tracker == idx ? item_state::highlighted : item_state::normal);
_m_draw_item(i_categ->items[lister.absolute(index_pair(idx.cat, offs))], x, y, txtoff, header_w, rect, subitems, bgcolor,fgcolor, state);
y += essence_->item_size;
}
}
else
{
for(auto i = i_categ->items.cbegin() + essence_->scroll.offset_y.item; i != i_categ->items.cend(); ++i, ++idx.item)
{
if(n-- == 0) break;
state = (tracker == idx ? item_state::highlighted : item_state::normal);
_m_draw_item(*i, x, y, txtoff, header_w, rect, subitems, bgcolor, fgcolor, state);
y += essence_->item_size;
}
_m_draw_item(i_categ->items[sort_enabled ? lister.absolute(index_pair(idx.cat, offs)) : offs], x, y, txtoff, header_w, rect, subitems, bgcolor,fgcolor, state);
y += essence_->item_size;
}
++i_categ;
++idx.cat;
}
@ -2584,35 +2552,18 @@ namespace nana
_m_draw_categ(*i_categ, rect.x - essence_->scroll.offset_x, y, txtoff, header_w, rect, bgcolor, state);
y += essence_->item_size;
if(false == i_categ->expand) continue;
if(false == i_categ->expand)
continue;
//Test whether the sort is enabled.
if(essence_->lister.sort_index() != npos)
auto size = i_categ->items.size();
for(decltype(size) pos = 0; pos < size; ++pos)
{
auto size = i_categ->items.size();
for(decltype(size) pos = 0; pos < size; ++pos)
{
if(n-- == 0) break;
state = (idx == tracker ? item_state::highlighted : item_state::normal);
if(n-- == 0) break;
state = (idx == tracker ? item_state::highlighted : item_state::normal);
_m_draw_item(i_categ->items[lister.absolute(index_pair(idx.cat, pos))], x, y, txtoff, header_w, rect, subitems, bgcolor, fgcolor, state);
y += essence_->item_size;
++idx.item;
}
}
else
{
for(auto & m : i_categ->items)
{
if(n-- == 0) break;
state = (idx == tracker ? item_state::highlighted : item_state::normal);
_m_draw_item(m, x, y, txtoff, header_w, rect, subitems, bgcolor, fgcolor, state);
y += essence_->item_size;
++idx.item;
}
_m_draw_item(i_categ->items[sort_enabled ? lister.absolute(index_pair(idx.cat, pos)) : pos], x, y, txtoff, header_w, rect, subitems, bgcolor, fgcolor, state);
y += essence_->item_size;
++idx.item;
}
}
@ -2627,25 +2578,24 @@ namespace nana
{
bool sel = categ.selected();
if(sel && (categ.expand == false))
bgcolor = nana::color(0xD5, 0xEF, 0xFC);
bgcolor = static_cast<color_rgb>(0xD5EFFC);
if (state == item_state::highlighted)
bgcolor = bgcolor.blend(::nana::color(0x99, 0xde, 0xfd), 0.8);
bgcolor = bgcolor.blend(static_cast<color_rgb>(0x99defd), 0.8);
auto graph = essence_->graph;
graph->set_color(bgcolor);
graph->rectangle(rectangle{ x, y, width, essence_->item_size }, true);
graph->rectangle(rectangle{ x, y, width, essence_->item_size }, true, bgcolor);
color txt_color{ static_cast<color_rgb>(0x3399) };
facade<element::arrow> arrow("double");
arrow.direction(categ.expand ? ::nana::direction::north : ::nana::direction::south);
::nana::rectangle arrow_r{ x + 5, y + static_cast<int>(essence_->item_size - 16) / 2, 16, 16 };
arrow.draw(*graph, {}, static_cast<color_rgb>(0x3399), arrow_r, element_state::normal);
arrow.draw(*graph, {}, txt_color, arrow_r, element_state::normal);
graph->string({ x + 20, y + txtoff }, categ.text, {0, 0x33, 0x99});
graph->string({ x + 20, y + txtoff }, categ.text, txt_color);
std::stringstream ss;
ss<<'('<<static_cast<unsigned>(categ.items.size())<<')';
nana::string str = nana::charset(ss.str());
::nana::string str = L'(' + ::nana::to_wstring(categ.items.size()) + L')';
unsigned str_w = graph->text_extent_size(str).width;
@ -2655,7 +2605,7 @@ namespace nana
if (x + 35 + text_s.width + str_w < x + width)
{
::nana::point pos{ x + 30 + static_cast<int>(text_s.width + str_w), y + static_cast<int>(essence_->item_size) / 2 };
graph->line(pos, { x + static_cast<int>(width)-5, pos.y }, { 0x0, 0x33, 0x99 });
graph->line(pos, { x + static_cast<int>(width)-5, pos.y }, txt_color);
}
//Draw selecting inner rectangle
if(sel && categ.expand == false)
@ -2845,7 +2795,7 @@ namespace nana
auto & graph = *essence_->graph;
auto size = graph.size();
//Draw Border
graph.rectangle(false, {0x9c, 0xb6, 0xc5});
graph.rectangle(false, static_cast<color_rgb>(0x9cb6c5));
graph.line({ 1, 1 }, {1, static_cast<int>(size.height) - 2}, colors::white);
graph.line({ static_cast<int>(size.width) - 2, 1 }, { static_cast<int>(size.width) - 2, static_cast<int>(size.height) - 2 });

View File

@ -73,9 +73,7 @@ namespace nana
std::wstring value() const override
{
std::wstringstream ss;
ss << value_;
return ss.str();
return ::nana::to_wstring(value_);
}
bool value(const std::wstring& value_str, bool & diff) override

View File

@ -456,25 +456,13 @@ namespace drawerbase {
textbox& textbox::from(int n)
{
#ifdef NANA_UNICODE
std::wstringstream ss;
#else
std::stringstream ss;
#endif
ss << n;
_m_caption(ss.str());
_m_caption(::nana::to_wstring(n));
return *this;
}
textbox& textbox::from(double d)
{
#ifdef NANA_UNICODE
std::wstringstream ss;
#else
std::stringstream ss;
#endif
ss << d;
_m_caption(ss.str());
_m_caption(::nana::to_wstring(d));
return *this;
}