Merge branch 'hotfix-1.6.2' into develop-1.7

This commit is contained in:
Jinhao 2018-11-16 07:42:03 +08:00
commit 18481b97ee
8 changed files with 3499 additions and 3436 deletions

View File

@ -167,6 +167,8 @@ namespace nana{ namespace widgets
bool select(bool);
bool select_points(nana::upoint arg_a, nana::upoint arg_b);
/// Sets the end position of a selected string.
void set_end_caret(bool stay_in_view);

View File

@ -35,6 +35,19 @@ namespace nana
{}
};
template<typename T>
struct arg_tabbar_adding
: public event_arg
{
arg_tabbar_adding(tabbar<T>& wdg, std::size_t pos)
: widget(wdg), where(pos)
{}
tabbar<T> & widget;
mutable bool add = true; ///< determines whether to add the item
std::size_t where; ///< position where to add the item
};
template<typename T>
struct arg_tabbar_removed : public arg_tabbar<T>
{
@ -56,6 +69,7 @@ namespace nana
{
using value_type = T;
basic_event<arg_tabbar_adding<value_type>> adding;
basic_event<arg_tabbar<value_type>> added;
basic_event<arg_tabbar<value_type>> activated;
basic_event<arg_tabbar_removed<value_type>> removed;
@ -65,6 +79,7 @@ namespace nana
{
public:
virtual ~event_agent_interface() = default;
virtual bool adding(std::size_t) = 0;
virtual void added(std::size_t) = 0;
virtual void activated(std::size_t) = 0;
virtual bool removed(std::size_t, bool & close_attached) = 0;
@ -107,6 +122,13 @@ namespace nana
: tabbar_(tb), drawer_trigger_(dtr)
{}
bool adding(std::size_t pos) override
{
::nana::arg_tabbar_adding<T> arg(tabbar_, pos);
tabbar_.events().adding.emit(arg, tabbar_);
return arg.add;
}
void added(std::size_t pos) override
{
if(pos != npos)

View File

@ -224,6 +224,8 @@ namespace nana
/// Selects/unselects all text.
void select(bool);
void select_points(nana::upoint arg_a, nana::upoint arg_b);
/// Returns the bounds of a text selection
/**
* @return no selection if pair.first == pair.second.

View File

@ -562,18 +562,18 @@ namespace detail
int large_edge = (w > h ? w : h);
const int div_256 = div * 256;
std::unique_ptr<int[]> all_table(new int[(wh << 1) + wh + (large_edge << 1) + div_256]);
std::unique_ptr<int[]> table_rgb(new int[(wh << 1) + wh + (large_edge << 1) + div_256]);
int * r = all_table.get();
int * g = r + wh;
int * b = g + wh;
int * tbl_r = table_rgb.get();
int * tbl_g = tbl_r + wh;
int * tbl_b = tbl_g + wh;
int * vmin = b + wh;
int * vmin = tbl_b + wh;
int * vmax = vmin + large_edge;
int * dv = vmax + large_edge;
int end_div = div - 1;
const int end_div = div - 1;
for(int i = 0, *dv_block = dv; i < 256; ++i)
{
for(int u = 0; u < end_div; u += 2)
@ -614,9 +614,9 @@ namespace detail
for(int x = 0; x < w; ++x)
{
r[yi] = dv[sum_r];
g[yi] = dv[sum_g];
b[yi] = dv[sum_b];
tbl_r[yi] = dv[sum_r];
tbl_g[yi] = dv[sum_g];
tbl_b[yi] = dv[sum_b];
if(0 == y)
{
@ -647,21 +647,21 @@ namespace detail
{
if(yp < 1)
{
sum_r += r[x];
sum_g += g[x];
sum_b += b[x];
sum_r += tbl_r[x];
sum_g += tbl_g[x];
sum_b += tbl_b[x];
}
else
{
int yi = yp + x;
sum_r += r[yi];
sum_g += g[yi];
sum_b += b[yi];
sum_r += tbl_r[yi];
sum_g += tbl_g[yi];
sum_b += tbl_b[yi];
}
yp += w;
}
linepix = pixbuf.raw_ptr(area.y) + x;
linepix = pixbuf.raw_ptr(area.y) + x + area.x;
for(int y = 0; y < h; ++y)
{
@ -675,9 +675,9 @@ namespace detail
int pt1 = x + vmin[y];
int pt2 = x + vmax[y];
sum_r += r[pt1] - r[pt2];
sum_g += g[pt1] - g[pt2];
sum_b += b[pt1] - b[pt2];
sum_r += tbl_r[pt1] - tbl_r[pt2];
sum_g += tbl_g[pt1] - tbl_g[pt2];
sum_b += tbl_b[pt1] - tbl_b[pt2];
linepix = pixel_at(linepix, bytes_pl);
}

View File

@ -1257,7 +1257,7 @@ namespace nana
IShellItem *init_path{ nullptr };
hr = SHCreateItemFromParsingName(impl_->init_path.wstring().c_str(), nullptr, IID_PPV_ARGS(&init_path));
if (SUCCEEDED(hr))
fd->SetDefaultFolder(init_path);
fd->SetFolder(init_path);
fd->SetOptions(FOS_PICKFOLDERS);
fd->Show(reinterpret_cast<HWND>(API::root(impl_->owner))); // the native handle of the parent nana form goes here

View File

@ -25,7 +25,8 @@
#include <algorithm>
#include <map>
namespace nana{ namespace widgets
namespace nana {
namespace widgets
{
namespace skeletons
{
@ -1632,14 +1633,20 @@ namespace nana{ namespace widgets
select_.a = select_.b = points_.caret;
const auto& line = impl_->textbase.getline(select_.b.y);
if (select_.a.x < line.size() && !std::isalnum(line[select_.a.x]) && line[select_.a.x] != '_') {
++select_.b.x;
}
else {
// Expand the selection forward to the word's end.
while (select_.b.x < line.size() && !std::iswspace(line[select_.b.x]))
while (select_.b.x < line.size() && !std::iswspace(line[select_.b.x]) && (std::isalnum(line[select_.b.x]) || line[select_.b.x] == '_'))
++select_.b.x;
// Expand the selection backward to the word's start.
while (select_.a.x > 0 && !std::iswspace(line[select_.a.x - 1]))
while (select_.a.x > 0 && !std::iswspace(line[select_.a.x - 1]) && (std::isalnum(line[select_.a.x - 1]) || line[select_.a.x - 1] == '_'))
--select_.a.x;
}
select_.mode_selection = selection::mode::method_selected;
impl_->try_refresh = sync_graph::refresh;
return true;
@ -1865,6 +1872,15 @@ namespace nana{ namespace widgets
return false;
}
bool text_editor::select_points(nana::upoint arg_a, nana::upoint arg_b)
{
select_.a = arg_a;
select_.b = arg_b;
select_.mode_selection = selection::mode::method_selected;
impl_->try_refresh = sync_graph::refresh;
return true;
}
void text_editor::set_end_caret(bool stay_in_view)
{
bool new_sel_end = (select_.b != points_.caret);

View File

@ -751,15 +751,27 @@ namespace nana
if((pos == npos) || (pos >= list_.size()))
{
pos = list_.size();
if(evt_agent_)
if(!evt_agent_->adding(pos))
return false;
this->list_.emplace_back();
}
else
{
if(evt_agent_)
if(!evt_agent_->adding(pos))
return false;
list_.emplace(iterator_at(pos));
}
basis_.active = pos;
if(evt_agent_)
{
evt_agent_->added(pos);
erase(pos);
evt_agent_->activated(pos);
}
return true;

View File

@ -588,6 +588,15 @@ namespace drawerbase {
API::refresh_window(*this);
}
void textbox::select_points(nana::upoint arg_a, nana::upoint arg_b)
{
auto editor = get_drawer_trigger().editor();
internal_scope_guard lock;
if (editor && editor->select_points(arg_a, arg_b))
API::refresh_window(*this);
}
std::pair<upoint, upoint> textbox::selection() const
{
std::pair<upoint, upoint> points;