Merge branch 'hotfix-1.3' into develop

This commit is contained in:
Jinhao
2016-04-18 15:16:03 +08:00
116 changed files with 2343 additions and 1004 deletions

View File

@@ -163,7 +163,7 @@ namespace nana{ namespace drawerbase
_m_press(graph, false);
}
void trigger::key_press(graph_reference graph, const arg_keyboard& arg)
void trigger::key_press(graph_reference, const arg_keyboard& arg)
{
bool ch_tabstop_next;
switch(arg.key)

View File

@@ -216,7 +216,7 @@ namespace nana{ namespace drawerbase
uiobj.check(false);
uiobj.react(false);
element_tag el = {};
element_tag el;
el.uiobj = &uiobj;

View File

@@ -611,7 +611,7 @@ namespace nana
}
}
void trigger::mouse_down(graph_reference graph, const arg_mouse& arg)
void trigger::mouse_down(graph_reference, const arg_mouse& arg)
{
//drawer_->set_mouse_press(true);
drawer_->set_button_state(element_state::pressed, false);
@@ -629,7 +629,7 @@ namespace nana
}
}
void trigger::mouse_up(graph_reference graph, const arg_mouse& arg)
void trigger::mouse_up(graph_reference, const arg_mouse& arg)
{
if (drawer_->widget_ptr()->enabled() && !drawer_->has_lister())
{
@@ -656,7 +656,7 @@ namespace nana
}
}
void trigger::mouse_wheel(graph_reference graph, const arg_wheel& arg)
void trigger::mouse_wheel(graph_reference, const arg_wheel& arg)
{
if(drawer_->widget_ptr()->enabled())
{
@@ -714,7 +714,7 @@ namespace nana
API::dev::lazy_refresh();
}
void trigger::key_char(graph_reference graph, const arg_keyboard& arg)
void trigger::key_char(graph_reference, const arg_keyboard& arg)
{
if (drawer_->editor()->respond_char(arg))
API::dev::lazy_refresh();

View File

@@ -18,7 +18,7 @@ namespace nana
namespace form
{
//class trigger
void trigger::attached(widget_reference wdg, graph_reference graph)
void trigger::attached(widget_reference wdg, graph_reference)
{
wd_ = &wdg;
API::ignore_mouse_focus(wdg, true);

View File

@@ -437,7 +437,7 @@ namespace nana
return total_w;
}
bool _m_each_line(graph_reference graph, dstream::linecontainer& line, render_status& rs)
bool _m_each_line(graph_reference graph, dstream::linecontainer&, render_status& rs)
{
std::wstring text;
iterator block_start;

View File

@@ -329,7 +329,7 @@ namespace nana
struct column_t
{
native_string_type text; ///< "text" header of the column number "index" with weigth "pixels"
unsigned pixels;
unsigned pixels; ///< width
bool visible{true};
size_type index;
std::function<bool(const std::string&, nana::any*, const std::string&, nana::any*, bool reverse)> weak_ordering;
@@ -338,6 +338,7 @@ namespace nana
column_t(native_string_type&& txt, unsigned px, size_type pos)
: text(std::move(txt)), pixels(px), index(pos)
{}
/// \todo introduce default cell format
};
using container = std::vector<column_t> ;
@@ -410,7 +411,7 @@ namespace nana
return cont_.back().index;
}
void item_width(size_type pos, unsigned width)
void item_width(size_type pos, unsigned width) ///< set the column width
{
column(pos).pixels = width;
}
@@ -427,7 +428,7 @@ namespace nana
return 0;
}
unsigned pixels() const
unsigned pixels() const ///< the visible width of the whole header
{
unsigned pixels = 0;
for(auto & m : cont_)
@@ -470,12 +471,13 @@ namespace nana
{
if(x < static_cast<int>(col.pixels))
return col.index;
x -= col.pixels;
if (col.visible)
x -= col.pixels;
}
return npos;
}
/// return the left position of the column originaly at index "pos" .
/// return the left position and width (in variable *pixels) of the column originaly at index "pos" .
int item_pos(size_type pos, unsigned * pixels) const
{
int left = 0;
@@ -493,7 +495,8 @@ namespace nana
}
return left;
}
/// return the original index of the visible col currently before(in front of) or after the col originaly at index "index"
/// return the original index of the visible col currently before(in front of) or after the col originaly at index "index"
size_type neighbor(size_type index, bool front) const
{
size_type n = npos;
@@ -509,11 +512,12 @@ namespace nana
break;
}
else if(i->visible)
n = i->index;
n = i->index;
}
return npos;
}
/// return the original index of the currently first visible col
/// return the original index of the currently first visible col
size_type begin() const
{
for(const auto & m : cont_)
@@ -532,7 +536,8 @@ namespace nana
}
return npos;
}
/// move the col originaly at index to the position currently in front (or after) the col originaly at index "to" invalidating some current index
/// move the col originaly at "index" to the position currently in front (or after) the col originaly at index "to" invalidating some current index
void move(size_type index, size_type to, bool front) throw()
{
if ((index == to) || (index >= cont_.size()) || (to >= cont_.size()))
@@ -879,7 +884,8 @@ namespace nana
list_.back().key_ptr = ptr;
return &list_.back();
}
/// add a new cat created at "pos" and return a ref to it
/// add a new cat created at "pos" and return a ref to it
category_t* create_cat(std::size_t pos, native_string_type&& text)
{
return &(*list_.emplace(this->get(pos), std::move(text)));
@@ -1828,9 +1834,7 @@ namespace nana
};//end class es_lister
//struct essence_t
//@brief: this struct gives many data for listbox,
// the state of the struct does not effect on member funcions, therefore all data members are public.
/// created and live by the trigger, holds data for listbox: the state of the struct does not effect on member funcions, therefore all data members are public.
struct essence_t
{
enum class item_state{normal, highlighted, pressed, grabbed, floated};
@@ -1859,7 +1863,7 @@ namespace nana
struct scroll_part
{
static const unsigned scale = 16;
static const unsigned scale = 16; // ?
int offset_x;
index_pair offset_y_abs, offset_y_dpl; //cat stands for category, item stands for item. "item == npos" means that is a category.
// need to be abs??? to see the same item after sort() ??
@@ -1942,8 +1946,8 @@ namespace nana
//number_of_lister_item
//@brief: Returns the number of items that are contained in pixels
//@param,with_rest: Means whether including extra one item that is not completely contained in reset pixels.
/// @brief Returns the number of items that are contained in pixels
/// @param with_rest: Means whether including extra one item that is not completely contained in reset pixels.
size_type number_of_lister_items(bool with_rest) const
{
unsigned lister_s = graph->height() - 2 - header_visible_px() - (scroll.h.empty() ? 0 : scroll.scale);
@@ -1983,8 +1987,9 @@ namespace nana
void trace_item_abs( index_pair abs_pos )
{
if(abs_pos.item == npos && abs_pos.cat == scroll.offset_y_abs.cat
&& scroll.offset_y_abs.item == npos ) // if item==off y and is a cat
if( abs_pos.item == npos
&& abs_pos.cat == scroll.offset_y_abs.cat
&& scroll.offset_y_abs.item == npos ) // if item==off y and is a cat
return;
trace_item_dpl( lister.relative_pair(abs_pos)) ; // ??? scroll_y_dpl_refresh() ;
@@ -2072,10 +2077,10 @@ namespace nana
bool v = (lister.the_number_of_expanded() > screen_number);
if(v == true && h == false)
h = (header_s > (sz.width - 2 - scroll.scale));
h = ( (header_s + 2 + scroll.scale ) > sz.width); // 2?
unsigned width = sz.width - 2 - (v ? scroll.scale : 0);
unsigned height = sz.height - 2 - (h ? scroll.scale : 0);
unsigned width = sz.width - 2 - (v ? scroll.scale : 0); // -? 2?
unsigned height = sz.height - 2 - (h ? scroll.scale : 0); // -? 2?
//event hander for scrollbars
auto evt_fn = [this](const arg_scroll& arg)
@@ -2168,7 +2173,8 @@ namespace nana
return (seq.size() ? (header.item_pos(seq[0], nullptr) - scroll.offset_x + r.x) : 0);
}
std::pair<parts, size_t> where(int x, int y){
std::pair<parts, size_t> where(int x, int y)
{
std::pair<parts, size_t> new_where;
if(2 < x && x < static_cast<int>(graph->width()) - 2 && 1 < y && y < static_cast<int>(graph->height()) - 1)
@@ -2614,15 +2620,15 @@ namespace nana
return list_str ;
}
void es_lister::categ_selected(size_type cat, bool sel)
void es_lister::categ_selected(size_type cat, bool sel)
{
cat_proxy cpx{ess_,cat};
for (item_proxy &it : cpx )
{
if (it.selected() != sel)
cat_proxy cpx{ess_,cat};
for (item_proxy &it : cpx )
{
if (it.selected() != sel)
it.select(sel);
}
last_selected_abs = last_selected_dpl = index_pair{cat, npos};
}
last_selected_abs = last_selected_dpl = index_pair{cat, npos};
}
class drawer_header_impl
@@ -2644,6 +2650,7 @@ namespace nana
item_spliter_ = npos;
}
/// return true an set member item_spliter_ if x is in the spliter area after that header item (column)
bool mouse_spliter(const nana::rectangle& r, int x)
{
if(essence_->ptr_state == item_state::highlighted)
@@ -2658,7 +2665,7 @@ namespace nana
item_spliter_ = hd.index; // original index
return true;
}
x -= hd.pixels;
x -= hd.pixels;
}
}
}
@@ -2672,7 +2679,7 @@ namespace nana
if(is_grab)
{
ref_xpos_ = pos.x;
if(item_spliter_ != npos)
if(item_spliter_ != npos) // resize header item, not move it
orig_item_width_ = essence_->header.column(item_spliter_).pixels;
}
else if(grab_terminal_.index != npos && grab_terminal_.index != essence_->pointer_where.second)
@@ -2680,21 +2687,21 @@ namespace nana
}
//grab_move
//@brief: draw when an item is grabbing.
//@return: 0 = no graphics changed, 1 = just update, 2 = refresh
/// @brief draw when an item is grabbing.
/// @return 0 = no graphics changed, 1 = just update, 2 = refresh
int grab_move(const nana::rectangle& rect, const nana::point& pos)
{
if(item_spliter_ == npos)
{
draw(rect);
_m_make_float(rect, pos);
{ // move header item, not resize it
draw(rect); // first draw the entery header as it was
_m_make_float(rect, pos); // now draw one floating header item
//Draw the target strip
grab_terminal_.index = _m_target_strip(pos.x, rect, essence_->pointer_where.second, grab_terminal_.place_front);
return 1;
}
else
{
{ // resize header item, not move it
const auto& item = essence_->header.column(item_spliter_);
//Resize the item specified by item_spliter_.
auto new_w = orig_item_width_ - (ref_xpos_ - pos.x);
@@ -3003,9 +3010,19 @@ namespace nana
}
}
//Draws an item
//@param content_r the rectangle of list content
void _m_draw_item(const category_t& cat, const index_pair& item_pos, const int x, const int y, const int txtoff, unsigned width, const nana::rectangle& content_r, const std::vector<size_type>& seqs, nana::color bgcolor, nana::color fgcolor, item_state state) const
/// Draws an item
void _m_draw_item(const category_t& cat,
const index_pair& item_pos,
const int x,
const int y,
const int txtoff,
unsigned width,
const nana::rectangle& content_r, ///< the rectangle where the full list content have to be drawn
const std::vector<size_type>& seqs,
nana::color bgcolor,
nana::color fgcolor,
item_state state
) const
{
auto & item = cat.items[item_pos.item];
@@ -3022,7 +3039,7 @@ namespace nana
if (item.flags.selected)
bgcolor = bgcolor.blend(colors::black, 0.98); // or "selected"
else
bgcolor = bgcolor.blend(essence_->scheme_ptr->item_selected, 0.7);
bgcolor = bgcolor.blend(essence_->scheme_ptr->item_selected, 0.7); /// \todo create a parametre for amount of blend
}
unsigned show_w = width - essence_->scroll.offset_x;
@@ -3148,6 +3165,7 @@ namespace nana
{
auto cell_txtcolor = fgcolor;
auto & m_cell = item.cells[column_pos];
review_utf8(m_cell.text);
nana::size ts = graph->text_extent_size(m_cell.text); // precalcule text geometry
if (m_cell.custom_format && (!m_cell.custom_format->bgcolor.invisible())) // adapt to costum format if need
@@ -3338,19 +3356,19 @@ namespace nana
if(essence_->ptr_state == item_state::pressed)
{
if(essence_->pointer_where.first == parts::header)
{
{ // moving a pressed header : grab it (or split-resize?)
essence_->ptr_state = item_state::grabbed;
nana::point pos = arg.pos;
essence_->widget_to_header(pos);
drawer_header_->grab(pos, true);
essence_->lister.wd_ptr()->set_capture(true);
update = 2;
update = 2; //0 = nothing, 1 = update, 2 = refresh
}
}
if(essence_->ptr_state == item_state::grabbed)
{
{ // moving a grabbed header
nana::point pos = arg.pos;
essence_->widget_to_header(pos);
@@ -3436,6 +3454,9 @@ namespace nana
if (lister.forward(essence_->scroll.offset_y_dpl, ptr_where.second, item_pos))
{
auto * item_ptr = (item_pos.is_item() ? &lister.at(item_pos) : nullptr);
const index_pair abs_item_pos{ item_pos.cat, lister.absolute(item_pos) };
if(ptr_where.first == parts::lister)
{
bool sel = true;
@@ -3444,28 +3465,32 @@ namespace nana
if (arg.shift)
lister.select_display_range(lister.last_selected_abs , item_pos, sel);
else if (arg.ctrl)
sel = !item_proxy(essence_, index_pair (item_pos.cat, lister.absolute(item_pos))).selected();
sel = !item_proxy(essence_, abs_item_pos).selected();
else
lister.select_for_all(false); //cancel all selections
}
else
sel = !item_proxy(essence_, index_pair (item_pos.cat, lister.absolute(item_pos))).selected();
{
//Clicking on a category is ignored when single selection is enabled.
//Fixed by Greentwip(issue #121)
if (item_ptr)
sel = !item_proxy(essence_, abs_item_pos).selected();
}
if(item_ptr)
{
item_ptr->flags.selected = sel;
index_pair last_selected(item_pos.cat, lister.absolute(item_pos));
arg_listbox arg{item_proxy{essence_, last_selected}, sel};
arg_listbox arg{ item_proxy{ essence_, abs_item_pos }, sel };
lister.wd_ptr()->events().selected.emit(arg, lister.wd_ptr()->handle());
if (item_ptr->flags.selected)
{
lister.cancel_others_if_single_enabled(true, last_selected);
essence_->lister.last_selected_abs = last_selected;
lister.cancel_others_if_single_enabled(true, abs_item_pos);
essence_->lister.last_selected_abs = abs_item_pos;
}
else if (essence_->lister.last_selected_abs == last_selected)
else if (essence_->lister.last_selected_abs == abs_item_pos)
essence_->lister.last_selected_abs.set_both(npos);
}
else if(!lister.single_selection())
@@ -3482,7 +3507,7 @@ namespace nana
lister.wd_ptr()->events().checked.emit(arg, lister.wd_ptr()->handle());
if (item_ptr->flags.checked)
lister.cancel_others_if_single_enabled(false, abs_pos);
lister.cancel_others_if_single_enabled(false, abs_item_pos);
}
else if (! lister.single_check())
lister.categ_checked_reverse(item_pos.cat);
@@ -3550,15 +3575,16 @@ namespace nana
}
}
void trigger::dbl_click(graph_reference graph, const arg_mouse& arg)
void trigger::dbl_click(graph_reference graph, const arg_mouse&)
{
if (essence_->pointer_where.first == essence_t::parts::header)
if (cursor::size_we == essence_->lister.wd_ptr()->cursor())
{
if (essence(). auto_width(drawer_header_->item_spliter() )) // ? in order
essence().update();
return;
}
{
//adjust the width of column to its content.
if (essence_->auto_width(drawer_header_->item_spliter() ))
essence_->update();
return;
}
if (essence_->pointer_where.first != essence_t::parts::lister)
return;
@@ -3575,7 +3601,8 @@ namespace nana
arg_listbox_category arg_cat(cat_proxy(essence_, item_pos.cat));
lister.wd_ptr()->events().category_dbl_click.emit(arg_cat, lister.wd_ptr()->handle());
if (!arg_cat.category_change_blocked()){
if (!arg_cat.category_change_blocked())
{
bool do_expand = (lister.expand(item_pos.cat) == false);
lister.expand(item_pos.cat, do_expand);
@@ -3604,8 +3631,8 @@ namespace nana
{
bool up = false;
if (essence_->lister.size_categ()==1 && essence_->lister.size_item(0)==0)
return ;
if (essence_->lister.size_categ()==1 && essence_->lister.size_item(0)==0)
return ;
switch(arg.key)
{
@@ -3623,49 +3650,46 @@ namespace nana
}
break;
case keyboard::os_pageup :
case keyboard::os_pageup :
up = true;
case keyboard::os_pagedown:
{
auto& scrl = essence_->scroll.v;
if (! scrl.make_page_scroll(!up))
return;
essence_->lister.select_for_all(false);
case keyboard::os_pagedown:
{
auto& scrl = essence_->scroll.v;
if (! scrl.make_page_scroll(!up))
return;
essence_->lister.select_for_all(false);
index_pair idx{essence_->scroll_y_dpl()};
if (!up)
essence_->lister.forward(idx, scrl.range()-1, idx);
index_pair idx{essence_->scroll_y_dpl()};
if (!up)
essence_->lister.forward(idx, scrl.range()-1, idx);
if (idx.is_item())
item_proxy::from_display(essence_, idx).select(true);
else
if(!essence_->lister.single_selection())
if (idx.is_item())
item_proxy::from_display(essence_, idx).select(true);
else if(!essence_->lister.single_selection())
essence_->lister.categ_selected(idx.cat, true);
essence_->trace_last_selected_item ();
essence_->trace_last_selected_item ();
break;
}
case keyboard::os_home:
{
essence_->lister.select_for_all(false);
break;
}
case keyboard::os_home:
{
essence_->lister.select_for_all(false);
index_pair frst{essence_->lister.first()};
if (frst.is_item())
item_proxy::from_display(essence_, frst).select(true);
else
if(!essence_->lister.single_selection())
index_pair frst{essence_->lister.first()};
if (frst.is_item())
item_proxy::from_display(essence_, frst).select(true);
else if(!essence_->lister.single_selection())
essence_->lister.categ_selected(frst.cat, true);
essence_->trace_last_selected_item ();
break;
}
case keyboard::os_end:
essence_->lister.select_for_all(false);
item_proxy::from_display(essence_, essence_->lister.last()).select(true);
essence_->trace_last_selected_item ();
break;
essence_->trace_last_selected_item ();
break;
}
case keyboard::os_end:
essence_->lister.select_for_all(false);
item_proxy::from_display(essence_, essence_->lister.last()).select(true);
essence_->trace_last_selected_item ();
break;
default:
return;
}
@@ -3677,20 +3701,19 @@ namespace nana
{
switch(arg.key)
{
case keyboard::copy:
{
export_options exp_opt {essence_->def_exp_options};
exp_opt.columns_order = essence_->header.all_headers(true);
exp_opt.only_selected_items = true;
::nana::system::dataexch().set(essence_->to_string(exp_opt));
return;
}
case keyboard::select_all :
essence_->lister.select_for_all(true);
case keyboard::copy:
{
export_options exp_opt {essence_->def_exp_options};
exp_opt.columns_order = essence_->header.all_headers(true);
exp_opt.only_selected_items = true;
::nana::system::dataexch().set(essence_->to_string(exp_opt));
return;
}
case keyboard::select_all :
essence_->lister.select_for_all(true);
refresh(graph);
API::dev::lazy_refresh();
break;
default:
return;
}
@@ -3699,6 +3722,7 @@ namespace nana
//end class trigger
//class item_proxy
item_proxy::item_proxy(essence_t * ess)
: ess_(ess)
{}
@@ -3714,23 +3738,24 @@ namespace nana
}
}
/// the main porpose of this it to make obvious that item_proxy operate with absolute positions, and dont get moved during sort()
item_proxy item_proxy::from_display(essence_t *ess, const index_pair &relative)
{
return item_proxy{ess, ess->lister.absolute_pair(relative)};
}
item_proxy item_proxy::from_display(const index_pair &relative) const
{
return item_proxy{ess_, ess_->lister.absolute_pair(relative)};
}
/// the main porpose of this it to make obvious that item_proxy operate with absolute positions, and dont get moved during sort()
item_proxy item_proxy::from_display(essence_t *ess, const index_pair &relative)
{
return item_proxy{ess, ess->lister.absolute_pair(relative)};
}
/// posible use: last_selected_display = last_selected.to_display().item; use with caution, it get invalidated after a sort()
index_pair item_proxy::to_display() const
{
return ess_->lister.relative_pair(pos_);
}
item_proxy item_proxy::from_display(const index_pair &relative) const
{
return item_proxy{ess_, ess_->lister.absolute_pair(relative)};
}
bool item_proxy::empty() const
/// posible use: last_selected_display = last_selected.to_display().item; use with caution, it get invalidated after a sort()
index_pair item_proxy::to_display() const
{
return ess_->lister.relative_pair(pos_);
}
bool item_proxy::empty() const
{
return !ess_;
}
@@ -3753,8 +3778,8 @@ namespace nana
return cat_->items.at(pos_.item).flags.checked;
}
/// is ignored if no change (maybe set last_selected anyway??), but if change emit event, deselect others if need ans set/unset last_selected
item_proxy & item_proxy::select(bool s)
/// is ignored if no change (maybe set last_selected anyway??), but if change emit event, deselect others if need ans set/unset last_selected
item_proxy & item_proxy::select(bool s)
{
auto & m = cat_->items.at(pos_.item); // a ref to the real item // what is pos is a cat?
if(m.flags.selected == s) return *this; // ignore if no change
@@ -3968,6 +3993,7 @@ namespace nana
//end class item_proxy
//class cat_proxy
//the member cat_ is used for fast accessing to the category
cat_proxy::cat_proxy(essence_t * ess, size_type pos)
: ess_(ess),
@@ -4296,7 +4322,7 @@ namespace nana
}
//Implementation of arg_category
//Implementation of arg_listbox_category
//Contributed by leobackes(pr#97)
arg_listbox_category::arg_listbox_category(const nana::drawerbase::listbox::cat_proxy& cat) noexcept
: category(cat), block_change_(false)
@@ -4315,6 +4341,7 @@ namespace nana
//class listbox
listbox::listbox(window wd, bool visible)
{
create(wd, rectangle(), visible);
@@ -4393,7 +4420,7 @@ namespace nana
}
unsigned listbox::auto_width(size_type pos, unsigned max)
{
auto & ess = _m_ess();
auto & ess = _m_ess();
unsigned max_w = ess.auto_width(pos, max);
ess.update();
return max_w;
@@ -4479,34 +4506,33 @@ namespace nana
return *this;
}
listbox::item_proxy listbox::at(const index_pair& pos_abs) const
listbox::item_proxy listbox::at(const index_pair& pos_abs) const
{
return at(pos_abs.cat).at(pos_abs.item);
}
// Contributed by leobackes(pr#97)
listbox::index_pair listbox::at ( const point& pos ) const
{
auto & ess=_m_ess();
auto _where=ess.where(pos.x, pos.y);
index_pair item_pos{npos,npos};
if(_where.first==drawerbase::listbox::essence_t::parts::lister){
auto & offset_y = ess.scroll.offset_y_dpl;
ess.lister.forward(offset_y, _where.second, item_pos);
}
return item_pos;
}
listbox::index_pair listbox::at ( const point& pos ) const
{
auto & ess=_m_ess();
auto _where=ess.where(pos.x, pos.y);
index_pair item_pos{npos,npos};
if(_where.first==drawerbase::listbox::essence_t::parts::lister)
{
auto & offset_y = ess.scroll.offset_y_dpl;
ess.lister.forward(offset_y, _where.second, item_pos);
}
return item_pos;
}
//Contributed by leobackes(pr#97)
listbox::columns_indexs listbox::column_from_pos ( const point& pos )
{
auto & ess=_m_ess();
columns_indexs col=ess.header.item_by_x(pos.x - 2 - ess.scroll.offset_x);
return col;
}
listbox::columns_indexs listbox::column_from_pos ( const point& pos )
{
auto & ess=_m_ess();
columns_indexs col=ess.header.item_by_x(pos.x - 2 - ess.scroll.offset_x);
return col;
}
void listbox::insert(const index_pair& pos, std::string text)
{

View File

@@ -398,24 +398,28 @@ namespace nana
//Draw text, the text is transformed from orignal for hotkey character
wchar_t hotkey;
std::string::size_type hotkey_pos;
auto text = to_wstring(API::transform_shortkey_text(m.text, hotkey, &hotkey_pos));
auto text = API::transform_shortkey_text(m.text, hotkey, &hotkey_pos);
if (m.image.empty() == false)
renderer->item_image(graph, nana::point(item_r.x + 5, item_r.y + static_cast<int>(item_h_px - image_px) / 2 - 1), image_px, m.image);
renderer->item_text(graph, nana::point(item_r.x + 40, item_r.y + text_top_off), to_utf8(text), strpixels, attr);
renderer->item_text(graph, nana::point(item_r.x + 40, item_r.y + text_top_off), text, strpixels, attr);
if (hotkey)
{
m.hotkey = hotkey;
if (m.flags.enabled)
{
unsigned off_w = (hotkey_pos ? graph.text_extent_size(text, static_cast<unsigned>(hotkey_pos)).width : 0);
nana::size hotkey_size = graph.text_extent_size(text.c_str() + hotkey_pos, 1);
int x = item_r.x + 40 + off_w;
int y = item_r.y + text_top_off + hotkey_size.height;
auto off_px = (hotkey_pos ? graph.text_extent_size(text.c_str(), hotkey_pos).width : 0);
auto hotkey_px = graph.text_extent_size(text.c_str() + hotkey_pos, 1).width;
graph_->line({ x, y }, { x + static_cast<int>(hotkey_size.width) - 1, y }, colors::black);
unsigned ascent, descent, inleading;
graph.text_metrics(ascent, descent, inleading);
int x = item_r.x + 40 + off_px;
int y = item_r.y + text_top_off + ascent + 1;
graph_->line({ x, y }, { x + static_cast<int>(hotkey_px)-1, y }, colors::black);
}
}
@@ -582,9 +586,12 @@ namespace nana
}
else if(m.flags.enabled)
{
std::move(fn_close_tree_)();
item_proxy ip(index, m);
m.functor.operator()(ip);
fn_close_tree_();
if (m.functor)
{
item_proxy ip(index, m);
m.functor.operator()(ip);
}
return 1;
}
}

View File

@@ -53,7 +53,7 @@ namespace nana{ namespace widgets
return cmd_;
}
virtual bool merge(const undoable_command_interface<EnumCommand>& rhs) override
virtual bool merge(const undoable_command_interface<EnumCommand>&) override
{
return false;
}
@@ -273,8 +273,8 @@ namespace nana{ namespace widgets
: editor_(editor)
{}
void merge_lines(std::size_t first, std::size_t second) override{}
void add_lines(std::size_t pos, std::size_t lines) override{}
void merge_lines(std::size_t, std::size_t) override{}
void add_lines(std::size_t, std::size_t) override{}
void pre_calc_line(std::size_t, unsigned) override{}
void pre_calc_lines(unsigned) override{}
@@ -283,12 +283,12 @@ namespace nana{ namespace widgets
return editor_.textbase_.lines();
}
std::size_t take_lines(std::size_t pos) const override
std::size_t take_lines(std::size_t) const override
{
return 1;
}
void update_line(std::size_t textline, std::size_t secondary_before) override
void update_line(std::size_t textline, std::size_t) override
{
int top = editor_._m_text_top_base() + static_cast<int>(editor_.line_height() * (textline - editor_.points_.offset.y));
editor_.graph_.rectangle({ editor_.text_area_.area.x, top, editor_.text_area_.area.width, editor_.line_height() }, true, API::bgcolor(editor_.window_));
@@ -1294,7 +1294,6 @@ namespace nana{ namespace widgets
select_.move_to_end = false;
select_.mode_selection = selection::mode::no_selected;
select_.ignore_press = false;
select_.dragged = false;
API::create_caret(wd, 1, line_height());
API::bgcolor(wd, colors::white);
@@ -1693,13 +1692,10 @@ namespace nana{ namespace widgets
if(left_button)
{
auto caret_pos_before = caret();
mouse_caret(scrpos);
if(select_.mode_selection != selection::mode::no_selected)
if (selection::mode::mouse_selected == select_.mode_selection || selection::mode::method_selected == select_.mode_selection)
set_end_caret();
else if ((!select_.dragged) && (caret_pos_before != caret()))
select_.dragged = true;
text_area_.border_renderer(graph_, _m_bgcolor());
return true;
@@ -1722,26 +1718,34 @@ namespace nana{ namespace widgets
API::set_capture(window_, true);
text_area_.captured = true;
//Set caret pos by screen point and get the caret pos.
mouse_caret(arg.pos);
if (arg.shift)
if (this->hit_select_area(behavior_->screen_to_caret(arg.pos), true))
{
if (points_.shift_begin_caret != points_.caret)
{
select_.a = points_.shift_begin_caret;
select_.b = points_.caret;
}
select_.mode_selection = selection::mode::move_selected;
}
else
{
if (!select(false))
//Set caret pos by screen point and get the caret pos.
mouse_caret(arg.pos);
if (arg.shift)
{
select_.a = points_.caret; //Set begin caret
set_end_caret();
if (points_.shift_begin_caret != points_.caret)
{
select_.a = points_.shift_begin_caret;
select_.b = points_.caret;
}
}
points_.shift_begin_caret = points_.caret;
else
{
if (!select(false))
{
select_.a = points_.caret; //Set begin caret
set_end_caret();
}
points_.shift_begin_caret = points_.caret;
}
select_.mode_selection = selection::mode::mouse_selected;
}
select_.mode_selection = selection::mode::mouse_selected;
}
text_area_.border_renderer(graph_, _m_bgcolor());
@@ -1750,19 +1754,19 @@ namespace nana{ namespace widgets
else if (event_code::mouse_up == arg.evt_code)
{
select_.ignore_press = false;
auto is_prev_no_selected = (select_.mode_selection == selection::mode::no_selected);
bool updated = false;
if (select_.mode_selection == selection::mode::mouse_selected)
{
select_.mode_selection = selection::mode::no_selected;
set_end_caret();
}
else if (is_prev_no_selected)
else if (selection::mode::move_selected == select_.mode_selection)
{
if ((!select_.dragged) || (!move_select()))
if (!move_select())
select(false);
updated = true;
}
select_.dragged = false;
API::release_capture(window_);
@@ -1772,8 +1776,7 @@ namespace nana{ namespace widgets
text_area_.border_renderer(graph_, _m_bgcolor());
//Redraw if is_prev_no_selected is true
return is_prev_no_selected;
return updated;
}
return false;
}
@@ -1913,11 +1916,21 @@ namespace nana{ namespace widgets
return ((text_area_.area.x <= pos.x && pos.x < _m_end_pos(true)) && (text_area_.area.y <= pos.y && pos.y < _m_end_pos(false)));
}
bool text_editor::hit_select_area(nana::upoint pos) const
bool text_editor::hit_select_area(nana::upoint pos, bool ignore_when_select_all) const
{
nana::upoint a, b;
if(_m_get_sort_select_points(a, b))
{
if (ignore_when_select_all)
{
if (a.x == 0 && a.y == 0 && (b.y + 1) == static_cast<unsigned>(textbase_.lines()))
{
//is select all
if (b.x == static_cast<unsigned>(textbase_.getline(b.y).size()))
return false;
}
}
if((pos.y > a.y || (pos.y == a.y && pos.x >= a.x)) && ((pos.y < b.y) || (pos.y == b.y && pos.x < b.x)))
return true;
}
@@ -1926,7 +1939,10 @@ namespace nana{ namespace widgets
bool text_editor::move_select()
{
if(hit_select_area(points_.caret) || (select_.b == points_.caret))
if (! attributes_.editable)
return false;
if(hit_select_area(points_.caret, true) || (select_.b == points_.caret))
{
points_.caret = select_.b;

View File

@@ -519,7 +519,7 @@ namespace nana
impl_->render();
}
void drawer::focus(graph_reference, const arg_focus& arg)
void drawer::focus(graph_reference, const arg_focus&)
{
impl_->reset_text();
impl_->render();
@@ -579,7 +579,7 @@ namespace nana
}
}
void drawer::resized(graph_reference graph, const arg_resized& arg)
void drawer::resized(graph_reference, const arg_resized&)
{
impl_->reset_text_area();
impl_->render();

View File

@@ -43,7 +43,7 @@ namespace nana
: public item_renderer
{
private:
virtual void background(graph_reference graph, const nana::rectangle& r, const ::nana::color& bgcolor)
virtual void background(graph_reference graph, const nana::rectangle&, const ::nana::color& bgcolor)
{
if(bgcolor_ != bgcolor)
{
@@ -59,7 +59,6 @@ namespace nana
virtual void item(graph_reference graph, const item_t& m, bool active, state_t sta)
{
//*
const nana::rectangle & r = m.r;
color bgcolor;
color blcolor;
@@ -961,7 +960,8 @@ namespace nana
auto bgcolor = API::bgcolor(basis_.wd);
auto fgcolor = API::fgcolor(basis_.wd);
item_renderer::item_t m{ ::nana::rectangle{ basis_.graph->size() } };
item_renderer::item_t m;
m.r = ::nana::rectangle{ basis_.graph->size() };
basis_.renderer->background(*basis_.graph, m.r, bgcolor);

View File

@@ -87,7 +87,7 @@ namespace drawerbase {
editor_ = nullptr;
}
void drawer::refresh(graph_reference graph)
void drawer::refresh(graph_reference)
{
editor_->render(API::is_focus_ready(*widget_));
}
@@ -115,7 +115,7 @@ namespace drawerbase {
API::dev::lazy_refresh();
}
void drawer::mouse_up(graph_reference graph, const arg_mouse& arg)
void drawer::mouse_up(graph_reference, const arg_mouse& arg)
{
if(editor_->mouse_pressed(arg))
API::dev::lazy_refresh();