Merge branch 'hotfix-1.4.1' into feature-listbox

This commit is contained in:
Jinhao 2016-11-28 07:42:53 +08:00
commit fb1f3734c1
8 changed files with 130 additions and 121 deletions

View File

@ -56,7 +56,7 @@ matrix:
- llvm-toolchain-precise - llvm-toolchain-precise
before_install: before_install:
- git clone --depth=1 --branch=develop https://github.com/qPCR4vir/nana-demo.git ../nana-demo - git clone --depth=1 --branch=hotfix-1.4 https://github.com/qPCR4vir/nana-demo.git ../nana-demo
- export PATH="$HOME/bin:$PATH" - export PATH="$HOME/bin:$PATH"
- mkdir ~/bin - mkdir ~/bin
- wget --no-check-certificate --no-clobber -O /tmp/tools/cmake https://cmake.org/files/v3.4/cmake-3.4.0-rc3-Linux-x86_64.sh || true - wget --no-check-certificate --no-clobber -O /tmp/tools/cmake https://cmake.org/files/v3.4/cmake-3.4.0-rc3-Linux-x86_64.sh || true

View File

@ -757,8 +757,6 @@ namespace nana
trigger(); trigger();
~trigger(); ~trigger();
essence& ess() const; essence& ess() const;
private:
void _m_draw_border();
private: private:
void attached(widget_reference, graph_reference) override; void attached(widget_reference, graph_reference) override;
void detached() override; void detached() override;

View File

@ -734,69 +734,73 @@ namespace nana
void _m_ok() void _m_ok()
{ {
if(0 == selection_.target.size()) std::string tar = selection_.target;
if(selection_.target.empty())
{ {
auto file = tb_file_.caption(); auto file = tb_file_.caption();
if(file.size()) if(file.size())
{ {
if(file[0] == L'.') if(file[0] == '.')
{ {
msgbox mb(*this, caption()); msgbox mb(*this, caption());
mb.icon(msgbox::icon_warning); mb.icon(msgbox::icon_warning);
mb<<file<<std::endl<<L"The filename is invalid."; mb<<file<<std::endl<<"The filename is invalid.";
mb(); mb();
return; return;
} }
std::string tar;
if(file[0] == '/') if(file[0] == '/')
tar = file; tar = file;
else else
tar = addr_.filesystem + file; tar = addr_.filesystem + file;
bool good = true;
auto fattr = fs::status(tar); auto fattr = fs::status(tar);
if(fattr.type() == fs::file_type::not_found)
//Check if the selected name is a directory
auto is_dir = fs::is_directory(fattr);
if(!is_dir && _m_append_def_extension(tar))
{ {
good = (_m_append_def_extension(tar) && (fs::status(tar).type() == fs::file_type::not_found)); //Add the extension, then check if it is a directory again.
fattr = fs::status(tar);
is_dir = fs::is_directory(fattr);
} }
if(good && fs::is_directory(fattr)) if(is_dir)
{ {
_m_load_cat_path(tar); _m_load_cat_path(tar);
tb_file_.caption(""); tb_file_.caption(std::string{});
return; return;
} }
if(io_read_) if(io_read_)
{ {
if(false == good) if(fs::file_type::not_found == fattr.type())
{ {
msgbox mb(*this, caption()); msgbox mb(*this, caption());
mb.icon(msgbox::icon_information); mb.icon(msgbox::icon_information);
mb<<L"The file \""<<nana::charset(tar, nana::unicode::utf8)<<L"\"\n is not existing. Please check and retry."; mb<<"The file \""<<tar<<"\"\n is not existing. Please check and retry.";
mb(); mb();
return;
} }
else
_m_finish(kind::filesystem, tar);
} }
else else
{ {
if(good) if(fs::file_type::not_found != fattr.type())
{ {
msgbox mb(*this, caption(), msgbox::yes_no); msgbox mb(*this, caption(), msgbox::yes_no);
mb.icon(msgbox::icon_question); mb.icon(msgbox::icon_question);
mb<<L"The input file is existing, do you want to overwrite it?"; mb<<"The input file is existing, do you want to overwrite it?";
if(msgbox::pick_no == mb()) if(msgbox::pick_no == mb())
return; return;
} }
_m_finish(kind::filesystem, tar);
} }
} }
} }
else
_m_finish(kind::filesystem, selection_.target); _m_finish(kind::filesystem, tar);
} }
void _m_tr_expand(item_proxy node, bool exp) void _m_tr_expand(item_proxy node, bool exp)

View File

@ -331,6 +331,8 @@ namespace nana
impl_->set_icon(image_ico); impl_->set_icon(image_ico);
impl_->icon = image_ico; impl_->icon = image_ico;
} }
#else
static_cast<void>(icon_file); //eliminate unused parameter warning
#endif #endif
} }
@ -341,6 +343,8 @@ namespace nana
auto icon_handle = paint::image_accessor::icon(image_ico); auto icon_handle = paint::image_accessor::icon(image_ico);
if (icon_handle) if (icon_handle)
impl_->icons.emplace_back(static_cast<paint::image&&>(image_ico)); impl_->icons.emplace_back(static_cast<paint::image&&>(image_ico));
#else
static_cast<void>(icon_file); //eliminate unused parameter warning
#endif #endif
} }

View File

@ -472,8 +472,6 @@ namespace nana
if (depth < 0 || start_pos >= div.length()) if (depth < 0 || start_pos >= div.length())
return{}; return{};
const char* p = div.c_str() + start_pos;
while (depth >= 0) while (depth >= 0)
{ {
auto pos = div.find_last_of("<>", start_pos); auto pos = div.find_last_of("<>", start_pos);

View File

@ -12,6 +12,9 @@
* @Author: Stefan Pfeifer(st-321), Ariel Vina-Rodriguez (qPCR4vir) * @Author: Stefan Pfeifer(st-321), Ariel Vina-Rodriguez (qPCR4vir)
* *
* @brief group is a widget used to visually group and layout other widgets. * @brief group is a widget used to visually group and layout other widgets.
*
* @contributor:
* dankan1890(https://github.com/dankan1890)
*/ */
@ -77,6 +80,9 @@ namespace nana{
if (options.empty()) if (options.empty())
place_content.field_display(field_options, false); place_content.field_display(field_options, false);
if (caption.caption().empty())
place_content.field_display(field_title, false);
} }
}; };

View File

@ -2255,8 +2255,12 @@ namespace nana
/// @param with_rest: Means whether including extra one item that is not completely contained in reset 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 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); unsigned lister_s = content_area().height - header_visible_px() - (scroll.h.empty() ? 0 : scroll.scale);
return (lister_s / scheme_ptr->item_height) + (with_rest && (lister_s % scheme_ptr->item_height) ? 1 : 0);
auto item_px = (std::max)(static_cast<decltype(scheme_ptr->item_height)>(1), scheme_ptr->item_height);
item_px = scheme_ptr->item_height;
return (lister_s / item_px) + (with_rest && (lister_s % item_px) ? 1 : 0);
} }
//keep the first selected item in the display area: the distances are in display positions! //keep the first selected item in the display area: the distances are in display positions!
@ -2362,42 +2366,31 @@ namespace nana
{ {
internal_scope_guard lock; internal_scope_guard lock;
const unsigned border_px = 1; auto const ctt_area = this->content_area();
const unsigned border_px_twice = (border_px << 1);
const nana::size sz = graph->size();
if ((sz.width <= border_px_twice) || (sz.height <= border_px_twice))
{
scroll.h.close();
scroll.v.close();
return;
}
// Adjust the ranged column assume the vertical scrollbar is enabled. // Adjust the ranged column assume the vertical scrollbar is enabled.
auto range_adjusted = this->header.calc_ranged_columns(sz.width - border_px_twice - scroll.scale); auto range_adjusted = this->header.calc_ranged_columns(ctt_area.width - scroll.scale);
auto columns_pixels = header.pixels(); auto const columns_pixels = header.pixels();
//H scroll enabled //H scroll enabled
//If range_adjusted is true, it indicates no horzontal scroll bar is enabled. //If range_adjusted is true, it indicates no horzontal scroll bar is enabled.
bool enable_horz = ((!range_adjusted) && (columns_pixels + 4 > sz.width)); // 4px = left and right borders(2px) + left and right gaps(2px) bool enable_horz = ((!range_adjusted) && (columns_pixels + 2 > ctt_area.width)); // 2px = left and right gaps(2px)
unsigned head_scroll = 2 + header_visible_px() + (enable_horz ? scroll.scale : 0); // 2px left and right gaps(2px) unsigned head_scroll = 2 + header_visible_px() + (enable_horz ? scroll.scale : 0); // 2px left and right gaps(2px)
unsigned lister_s = sz.height > head_scroll ? sz.height - head_scroll : 0; size_type exposed_count = ((ctt_area.height > head_scroll ? ctt_area.height - head_scroll : 0) / scheme_ptr->item_height);
size_type screen_number = (lister_s / scheme_ptr->item_height);
//V scroll enabled //V scroll enabled
auto enable_vert = (lister.the_number_of_expanded() > screen_number); auto enable_vert = (lister.the_number_of_expanded() > exposed_count);
if (enable_vert) if (enable_vert)
{ {
if (!enable_horz) if (!enable_horz)
enable_horz = ((columns_pixels + 2 + scroll.scale) > sz.width); enable_horz = (columns_pixels + scroll.scale > ctt_area.width);
} }
else if (range_adjusted) else if (range_adjusted)
{ {
//No vertical scrollbar, then re-adjust the range columns for a new width that excludes vert scroll. //No vertical scrollbar, then re-adjust the range columns for a new width that excludes vert scroll.
this->header.calc_ranged_columns(sz.width - border_px_twice); this->header.calc_ranged_columns(ctt_area.width);
} }
//event hander for scrollbars //event hander for scrollbars
@ -2417,7 +2410,7 @@ namespace nana
API::refresh_window(this->lister.wd_ptr()->handle()); API::refresh_window(this->lister.wd_ptr()->handle());
}; };
unsigned horz_px = sz.width - border_px_twice; auto horz_px = ctt_area.width;
if (enable_vert) if (enable_vert)
{ {
if (horz_px < scroll.scale) if (horz_px < scroll.scale)
@ -2426,7 +2419,7 @@ namespace nana
horz_px -= scroll.scale; horz_px -= scroll.scale;
} }
unsigned vert_px = sz.height - border_px_twice; auto vert_px = ctt_area.height;
if (enable_horz) if (enable_horz)
{ {
if (vert_px < scroll.scale) if (vert_px < scroll.scale)
@ -2438,7 +2431,7 @@ namespace nana
const auto wd_handle = lister.wd_ptr()->handle(); const auto wd_handle = lister.wd_ptr()->handle();
if (enable_horz && horz_px) if (enable_horz && horz_px)
{ {
rectangle r(border_px, static_cast<int>(sz.height - border_px) - static_cast<int>(scroll.scale), horz_px, scroll.scale); rectangle r(ctt_area.x, ctt_area.bottom() - static_cast<int>(scroll.scale), horz_px, scroll.scale);
if(scroll.h.empty()) if(scroll.h.empty())
{ {
scroll.h.create(wd_handle, r); scroll.h.create(wd_handle, r);
@ -2453,7 +2446,7 @@ namespace nana
if (enable_vert && vert_px) if (enable_vert && vert_px)
{ {
rectangle r(static_cast<int>(sz.width - border_px) - static_cast<int>(scroll.scale), border_px, scroll.scale, vert_px); rectangle r(ctt_area.right() - static_cast<int>(scroll.scale), ctt_area.y, scroll.scale, vert_px);
if(scroll.v.empty()) if(scroll.v.empty())
{ {
scroll.v.create(wd_handle, r); scroll.v.create(wd_handle, r);
@ -2554,28 +2547,43 @@ namespace nana
pos.x += static_cast<int>(scroll.x_offset()) - 2; pos.x += static_cast<int>(scroll.x_offset()) - 2;
} }
bool rect_header(nana::rectangle& r) const void draw_peripheral()
{ {
if(header.visible()) auto ctt_area = this->content_area();
{
if (lister.wd_ptr()->borderless()) if (!API::widget_borderless(*lister.wd_ptr()))
{ {
r.dimension(graph->size()); //Draw Border
r.height = scheme_ptr->header_height; graph->rectangle(false, static_cast<color_rgb>(0x9cb6c5));
return !r.empty();
} graph->line({ ctt_area.x, ctt_area.y }, { ctt_area.x, ctt_area.bottom() - 1 }, colors::white);
graph->line({ ctt_area.right() - 1, ctt_area.y }, { ctt_area.right() - 1, ctt_area.bottom() - 1 });
const unsigned ex_width = 4 + (scroll.v.empty() ? 0 : scroll.scale - 1);
if(graph->width() > ex_width)
{
r.x = 2;
r.y = 1;
r.width = graph->width() - ex_width;
r.height = scheme_ptr->header_height;
return true;
}
} }
return false;
if ((scroll.h.empty() == false) && (scroll.v.empty() == false))
{
graph->rectangle({ ctt_area.right() - static_cast<int>(scroll.scale),
ctt_area.bottom() - static_cast<int>(scroll.scale),
scroll.scale,
scroll.scale },
true, colors::button_face);
}
}
rectangle content_area() const
{
rectangle r{ graph->size() };
if (!this->listbox_ptr->borderless())
{
r.x = 1;
r.width -= (r.width > 2 ? 2 : r.width);
r.y = 1;
r.height -= (r.height > 2 ? 2 : r.height);
}
return r;
} }
unsigned header_visible_px() const unsigned header_visible_px() const
@ -2583,31 +2591,45 @@ namespace nana
return (header.visible() ? scheme_ptr->header_height : 0); return (header.visible() ? scheme_ptr->header_height : 0);
} }
bool rect_header(nana::rectangle& r) const
{
if(header.visible())
{
r = this->content_area();
r.height = scheme_ptr->header_height;
if (lister.wd_ptr()->borderless())
return !r.empty();
const unsigned ex_width = 2 + (scroll.v.empty() ? 0 : scroll.scale - 1);
if(r.width > ex_width)
{
r.x += 1;
r.width -= ex_width;
return true;
}
}
return false;
}
bool rect_lister(nana::rectangle& r) const bool rect_lister(nana::rectangle& r) const
{ {
auto head_pixels = header_visible_px(); auto head_pixels = header_visible_px();
unsigned width = (scroll.v.empty() ? 0 : scroll.scale - 1); unsigned extr_w = (scroll.v.empty() ? 0 : scroll.scale - 1);
unsigned height = (scroll.h.empty() ? 0 : scroll.scale) + head_pixels; unsigned extr_h = (scroll.h.empty() ? 0 : scroll.scale) + head_pixels;
r = this->content_area();
r.y += head_pixels;
if (!lister.wd_ptr()->borderless()) if (!lister.wd_ptr()->borderless())
{ {
width += 4; extr_w += 2;
height += 2; r.x += 1;
r.x = 2;
r.y = head_pixels + 1;
}
else
{
r.x = 0;
r.y = head_pixels;
} }
nana::size gsz = graph->size(); if(r.width <= extr_w || r.height <= extr_h)
if(gsz.width <= width || gsz.height <= height) return false; return false;
r.width = gsz.width - width;
r.height = gsz.height - height;
return true; return true;
} }
@ -3745,7 +3767,7 @@ namespace nana
//Draw selecting inner rectangle //Draw selecting inner rectangle
if (sel && (categ.expand == false)) if (sel && (categ.expand == false))
{ {
_m_draw_border(r.x, y, (std::min)(r.width, width - essence_->scroll.x_offset())); _m_draw_item_border(r.x, y, (std::min)(r.width, width - essence_->scroll.x_offset()));
} }
} }
@ -3946,7 +3968,7 @@ namespace nana
//Draw selecting inner rectangle //Draw selecting inner rectangle
if(item.flags.selected) if(item.flags.selected)
_m_draw_border(content_r.x, y, show_w); _m_draw_item_border(content_r.x, y, show_w);
} }
inline_pane * _m_get_inline_pane(const category_t& cat, std::size_t column_pos) const inline_pane * _m_get_inline_pane(const category_t& cat, std::size_t column_pos) const
@ -3985,7 +4007,7 @@ namespace nana
return nullptr; return nullptr;
} }
void _m_draw_border(int x, int y, unsigned width) const void _m_draw_item_border(int x, int y, unsigned width) const
{ {
//Draw selecting inner rectangle //Draw selecting inner rectangle
rectangle r{ x, y, width, essence_->scheme_ptr->item_height }; rectangle r{ x, y, width, essence_->scheme_ptr->item_height };
@ -4021,30 +4043,6 @@ namespace nana
return *essence_; return *essence_;
} }
void trigger::_m_draw_border()
{
if (API::widget_borderless(*essence_->lister.wd_ptr()))
return;
auto & graph = *essence_->graph;
int right = static_cast<int>(graph.width()) - 1;
int bottom = static_cast<int>(graph.height()) - 1;
//Draw Border
graph.rectangle(false, static_cast<color_rgb>(0x9cb6c5));
graph.line({ 1, 1 }, { 1, bottom - 1}, colors::white);
graph.line({ right - 1, 1 }, { right - 1, bottom - 1 });
if ((essence_->scroll.h.empty() == false) && (essence_->scroll.v.empty() == false))
graph.rectangle({ right - static_cast<int>(essence_->scroll.scale),
bottom - static_cast<int>(essence_->scroll.scale),
essence_->scroll.scale,
essence_->scroll.scale },
true, colors::button_face);
}
void trigger::attached(widget_reference widget, graph_reference graph) void trigger::attached(widget_reference widget, graph_reference graph)
{ {
essence_->listbox_ptr = static_cast<nana::listbox*>(&widget); essence_->listbox_ptr = static_cast<nana::listbox*>(&widget);
@ -4081,7 +4079,8 @@ namespace nana
drawer_header_->draw(graph, r); drawer_header_->draw(graph, r);
if (essence_->rect_lister(r)) if (essence_->rect_lister(r))
drawer_lister_->draw(r); drawer_lister_->draw(r);
_m_draw_border();
essence_->draw_peripheral();
} }
void trigger::mouse_move(graph_reference graph, const arg_mouse& arg) void trigger::mouse_move(graph_reference graph, const arg_mouse& arg)
@ -4274,7 +4273,7 @@ namespace nana
if(update) if(update)
{ {
_m_draw_border(); essence_->draw_peripheral();
API::dev::lazy_refresh(); API::dev::lazy_refresh();
} }
} }

View File

@ -57,7 +57,7 @@ typedef struct
class image_ico_ex class image_ico_ex
: public basic_image_pixbuf : public basic_image_pixbuf
{ {
bool _m_read_ico(const void* data, std::size_t size) bool _m_read_ico(const void* data, std::size_t /*size*/)
{ {
auto width = 0; auto width = 0;
auto height = 0; auto height = 0;
@ -94,7 +94,7 @@ class image_ico_ex
cursor += offset; cursor += offset;
auto icon = reinterpret_cast<ICONIMAGE*>(cursor); auto icon = reinterpret_cast<ICONIMAGE*>(cursor);
auto realBitsCount = static_cast<int>(icon->icHeader.biBitCount); auto realBitsCount = static_cast<int>(icon->icHeader.biBitCount);
auto hasAndMask = (realBitsCount < 32) && (height != icon->icHeader.biHeight); auto hasAndMask = (realBitsCount < 32) && (height != static_cast<int>(icon->icHeader.biHeight));
cursor += 40; cursor += 40;
pixbuf_.open(width, height); pixbuf_.open(width, height);