fix wrong positions of menu and tooltip

caused by implicit int to unsigned type conversion when a screen starts a
neg point
This commit is contained in:
Jinhao 2015-03-30 21:42:22 +08:00
parent b5e5e93673
commit dcead38544
3 changed files with 24 additions and 20 deletions

View File

@ -1,6 +1,7 @@
/*
* A Tooltip Implementation
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
* Nana C++ Library(http://www.nanapro.org)
* 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
@ -35,13 +36,13 @@ namespace nana
nana::point pos_by_screen(nana::point pos, const nana::size& sz, bool overlap_allowed)
{
auto scr_area = screen().from_point(pos).workarea();
if (pos.x + sz.width > scr_area.x + scr_area.width)
pos.x = static_cast<int>(scr_area.x + scr_area.width - sz.width);
if (pos.x + static_cast<int>(sz.width) > scr_area.right())
pos.x = scr_area.right() - static_cast<int>(sz.width);
if (pos.x < scr_area.x)
pos.x = scr_area.x;
if (pos.y + sz.height >= scr_area.y + scr_area.height)
pos.y = static_cast<int>(scr_area.y + scr_area.height - sz.height);
if (pos.y + static_cast<int>(sz.height) >= scr_area.bottom())
pos.y = scr_area.bottom() - static_cast<int>(sz.height);
else if (!overlap_allowed)
pos.y += 20; //Add some pixels to avoid overlapping between cursor and tip window.

View File

@ -661,11 +661,11 @@ namespace nana
//get the screen coordinates of the widget pos.
auto scr_area = screen().from_point(detail_.monitor_pos).workarea();
if(pos.x + size.width > scr_area.x + scr_area.width)
if(pos.x + static_cast<int>(size.width) > scr_area.right())
pos.x = static_cast<int>(scr_area.x + scr_area.width - size.width);
if(pos.x < scr_area.x) pos.x = scr_area.x;
if(pos.y + size.height > scr_area.y + scr_area.height)
if(pos.y + static_cast<int>(size.height) > scr_area.bottom())
pos.y = static_cast<int>(scr_area.y + scr_area.height - size.height);
if(pos.y < scr_area.y) pos.y = scr_area.y;

View File

@ -1,7 +1,7 @@
/*
* A Menubar implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2009-2014 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2009-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@ -30,21 +30,21 @@ namespace nana
{
struct item_type
{
item_type(const nana::string& text, unsigned long shortkey)
item_type(const ::nana::string& text, unsigned long shortkey)
: text(text), shortkey(shortkey)
{}
nana::string text;
::nana::string text;
unsigned long shortkey;
nana::menu menu_obj;
nana::point pos;
nana::size size;
::nana::menu menu_obj;
::nana::point pos;
::nana::size size;
};
class trigger::itembase
{
public:
typedef std::vector<item_type*> container;
using container = std::vector<item_type*>;
~itembase()
{
@ -52,7 +52,7 @@ namespace nana
delete i;
}
void append(const nana::string& text, unsigned long shortkey)
void append(const ::nana::string& text, unsigned long shortkey)
{
if(shortkey && shortkey < 0x61) shortkey += (0x61 - 0x41);
cont_.push_back(new item_type(text, shortkey));
@ -122,11 +122,13 @@ namespace nana
nana::rectangle r(pos, size);
graph_.rectangle(r, false, border);
int right = pos.x + static_cast<int>(size.width) - 1;
int bottom = pos.y + static_cast<int>(size.height) - 1;
graph_.set_color(corner);
graph_.set_pixel(pos.x, pos.y);
graph_.set_pixel(pos.x + size.width - 1, pos.y);
graph_.set_pixel(pos.x, pos.y + size.height - 1);
graph_.set_pixel(pos.x + size.width - 1, pos.y + size.height - 1);
graph_.set_pixel(right, pos.y);
graph_.set_pixel(pos.x, bottom);
graph_.set_pixel(right, bottom);
graph_.rectangle(r.pare_off(1), true, body);
}
@ -146,9 +148,9 @@ namespace nana
delete items_;
}
nana::menu* trigger::push_back(const nana::string& text)
nana::menu* trigger::push_back(const ::nana::string& text)
{
nana::string::value_type shkey;
::nana::string::value_type shkey;
API::transform_shortkey_text(text, shkey, nullptr);
if(shkey)
@ -157,6 +159,7 @@ namespace nana
auto i = items_->cont().size();
items_->append(text, shkey);
_m_draw();
API::update_window(*widget_);
return items_->get_menu(i);
}