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:
parent
b5e5e93673
commit
dcead38544
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* A Tooltip Implementation
|
* 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.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (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)
|
nana::point pos_by_screen(nana::point pos, const nana::size& sz, bool overlap_allowed)
|
||||||
{
|
{
|
||||||
auto scr_area = screen().from_point(pos).workarea();
|
auto scr_area = screen().from_point(pos).workarea();
|
||||||
if (pos.x + sz.width > scr_area.x + scr_area.width)
|
if (pos.x + static_cast<int>(sz.width) > scr_area.right())
|
||||||
pos.x = static_cast<int>(scr_area.x + scr_area.width - sz.width);
|
pos.x = scr_area.right() - static_cast<int>(sz.width);
|
||||||
if (pos.x < scr_area.x)
|
if (pos.x < scr_area.x)
|
||||||
pos.x = scr_area.x;
|
pos.x = scr_area.x;
|
||||||
|
|
||||||
if (pos.y + sz.height >= scr_area.y + scr_area.height)
|
if (pos.y + static_cast<int>(sz.height) >= scr_area.bottom())
|
||||||
pos.y = static_cast<int>(scr_area.y + scr_area.height - sz.height);
|
pos.y = scr_area.bottom() - static_cast<int>(sz.height);
|
||||||
else if (!overlap_allowed)
|
else if (!overlap_allowed)
|
||||||
pos.y += 20; //Add some pixels to avoid overlapping between cursor and tip window.
|
pos.y += 20; //Add some pixels to avoid overlapping between cursor and tip window.
|
||||||
|
|
||||||
|
@ -661,11 +661,11 @@ namespace nana
|
|||||||
//get the screen coordinates of the widget pos.
|
//get the screen coordinates of the widget pos.
|
||||||
auto scr_area = screen().from_point(detail_.monitor_pos).workarea();
|
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);
|
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.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);
|
pos.y = static_cast<int>(scr_area.y + scr_area.height - size.height);
|
||||||
if(pos.y < scr_area.y) pos.y = scr_area.y;
|
if(pos.y < scr_area.y) pos.y = scr_area.y;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* A Menubar implementation
|
* A Menubar implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* 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.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -30,21 +30,21 @@ namespace nana
|
|||||||
{
|
{
|
||||||
struct item_type
|
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)
|
: text(text), shortkey(shortkey)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
nana::string text;
|
::nana::string text;
|
||||||
unsigned long shortkey;
|
unsigned long shortkey;
|
||||||
nana::menu menu_obj;
|
::nana::menu menu_obj;
|
||||||
nana::point pos;
|
::nana::point pos;
|
||||||
nana::size size;
|
::nana::size size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class trigger::itembase
|
class trigger::itembase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::vector<item_type*> container;
|
using container = std::vector<item_type*>;
|
||||||
|
|
||||||
~itembase()
|
~itembase()
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ namespace nana
|
|||||||
delete i;
|
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);
|
if(shortkey && shortkey < 0x61) shortkey += (0x61 - 0x41);
|
||||||
cont_.push_back(new item_type(text, shortkey));
|
cont_.push_back(new item_type(text, shortkey));
|
||||||
@ -122,11 +122,13 @@ namespace nana
|
|||||||
nana::rectangle r(pos, size);
|
nana::rectangle r(pos, size);
|
||||||
graph_.rectangle(r, false, border);
|
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_color(corner);
|
||||||
graph_.set_pixel(pos.x, pos.y);
|
graph_.set_pixel(pos.x, pos.y);
|
||||||
graph_.set_pixel(pos.x + size.width - 1, pos.y);
|
graph_.set_pixel(right, pos.y);
|
||||||
graph_.set_pixel(pos.x, pos.y + size.height - 1);
|
graph_.set_pixel(pos.x, bottom);
|
||||||
graph_.set_pixel(pos.x + size.width - 1, pos.y + size.height - 1);
|
graph_.set_pixel(right, bottom);
|
||||||
graph_.rectangle(r.pare_off(1), true, body);
|
graph_.rectangle(r.pare_off(1), true, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,9 +148,9 @@ namespace nana
|
|||||||
delete items_;
|
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);
|
API::transform_shortkey_text(text, shkey, nullptr);
|
||||||
|
|
||||||
if(shkey)
|
if(shkey)
|
||||||
@ -157,6 +159,7 @@ namespace nana
|
|||||||
auto i = items_->cont().size();
|
auto i = items_->cont().size();
|
||||||
items_->append(text, shkey);
|
items_->append(text, shkey);
|
||||||
_m_draw();
|
_m_draw();
|
||||||
|
API::update_window(*widget_);
|
||||||
return items_->get_menu(i);
|
return items_->get_menu(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user