Merge branch 'menubar_improvements' of https://github.com/dankan1890/nana into dankan1890-menubar_improvements
This commit is contained in:
		
						commit
						3de48c1991
					
				@ -13,7 +13,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#ifndef NANA_GUI_WIDGETS_MENU_HPP
 | 
					#ifndef NANA_GUI_WIDGETS_MENU_HPP
 | 
				
			||||||
#define NANA_GUI_WIDGETS_MENU_HPP
 | 
					#define NANA_GUI_WIDGETS_MENU_HPP
 | 
				
			||||||
#include "widget.hpp"
 | 
					#include <nana/gui/widgets/widget.hpp>
 | 
				
			||||||
#include <nana/pat/cloneable.hpp>
 | 
					#include <nana/pat/cloneable.hpp>
 | 
				
			||||||
#include <nana/push_ignore_diagnostic>
 | 
					#include <nana/push_ignore_diagnostic>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -12,8 +12,8 @@
 | 
				
			|||||||
 
 | 
					 
 | 
				
			||||||
#ifndef NANA_GUI_WIDGETS_MENUBAR_HPP
 | 
					#ifndef NANA_GUI_WIDGETS_MENUBAR_HPP
 | 
				
			||||||
#define NANA_GUI_WIDGETS_MENUBAR_HPP
 | 
					#define NANA_GUI_WIDGETS_MENUBAR_HPP
 | 
				
			||||||
#include "widget.hpp"
 | 
					#include <nana/gui/widgets/widget.hpp>
 | 
				
			||||||
#include "menu.hpp"
 | 
					#include <nana/gui/widgets/menu.hpp>
 | 
				
			||||||
#include <nana/push_ignore_diagnostic>
 | 
					#include <nana/push_ignore_diagnostic>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace nana
 | 
					namespace nana
 | 
				
			||||||
@ -24,6 +24,16 @@ namespace nana
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			using native_string_type = ::nana::detail::native_string_type;
 | 
								using native_string_type = ::nana::detail::native_string_type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								struct scheme
 | 
				
			||||||
 | 
									: public widget_geometrics
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									color_proxy text_fgcolor{ colors::black };
 | 
				
			||||||
 | 
									color_proxy body_highlight{ static_cast<color_rgb>(0xc0ddfc) };
 | 
				
			||||||
 | 
									color_proxy body_selected{ colors::white };
 | 
				
			||||||
 | 
									color_proxy border_selected{ colors::dark_border };
 | 
				
			||||||
 | 
									color_proxy border_highlight{ colors::highlight };
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			class item_renderer
 | 
								class item_renderer
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
			public:
 | 
								public:
 | 
				
			||||||
@ -33,13 +43,16 @@ namespace nana
 | 
				
			|||||||
				};
 | 
									};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				using graph_reference = paint::graphics&;
 | 
									using graph_reference = paint::graphics&;
 | 
				
			||||||
 | 
									using scheme = ::nana::drawerbase::menubar::scheme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				item_renderer(window, graph_reference);
 | 
									item_renderer(window, graph_reference);
 | 
				
			||||||
				virtual void background(const point&, const ::nana::size&, state);
 | 
									virtual void background(const point&, const ::nana::size&, state);
 | 
				
			||||||
				virtual void caption(const point&, const native_string_type&);
 | 
									virtual void caption(const point&, const native_string_type&);
 | 
				
			||||||
 | 
									scheme *scheme_ptr() const { return scheme_ptr_; };
 | 
				
			||||||
			private:
 | 
								private:
 | 
				
			||||||
				window	handle_;
 | 
									window	handle_;
 | 
				
			||||||
				graph_reference graph_;
 | 
									graph_reference graph_;
 | 
				
			||||||
 | 
									scheme *scheme_ptr_;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			class trigger
 | 
								class trigger
 | 
				
			||||||
@ -72,7 +85,7 @@ namespace nana
 | 
				
			|||||||
				bool _m_track_mouse(const ::nana::point&);
 | 
									bool _m_track_mouse(const ::nana::point&);
 | 
				
			||||||
			private:
 | 
								private:
 | 
				
			||||||
				widget *widget_;
 | 
									widget *widget_;
 | 
				
			||||||
				nana::paint::graphics	*graph_;
 | 
									paint::graphics	*graph_;
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				itembase*	items_;
 | 
									itembase*	items_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -104,7 +117,7 @@ namespace nana
 | 
				
			|||||||
	  ///
 | 
						  ///
 | 
				
			||||||
	  /// The widget sets as shortkey the character behind the first of & in the text, for the item. e.g. "File(&F)" or "&File".
 | 
						  /// The widget sets as shortkey the character behind the first of & in the text, for the item. e.g. "File(&F)" or "&File".
 | 
				
			||||||
	class menubar
 | 
						class menubar
 | 
				
			||||||
		:	public widget_object<category::widget_tag, drawerbase::menubar::trigger>
 | 
							:	public widget_object<category::widget_tag, drawerbase::menubar::trigger, ::nana::general_events, drawerbase::menubar::scheme>
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		menubar() = default;					///< The default constructor delay creation.
 | 
							menubar() = default;					///< The default constructor delay creation.
 | 
				
			||||||
 | 
				
			|||||||
@ -85,24 +85,24 @@ namespace nana
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			//class item_renderer
 | 
								//class item_renderer
 | 
				
			||||||
				item_renderer::item_renderer(window wd, graph_reference graph)
 | 
									item_renderer::item_renderer(window wd, graph_reference graph)
 | 
				
			||||||
					:handle_(wd), graph_(graph)
 | 
										:handle_(wd), graph_(graph), scheme_ptr_(static_cast<scheme*>(API::dev::get_scheme(wd)))
 | 
				
			||||||
				{}
 | 
									{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				void item_renderer::background(const nana::point& pos, const nana::size& size, state item_state)
 | 
									void item_renderer::background(const nana::point& pos, const nana::size& size, state item_state)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					auto bground = API::fgcolor(handle_);
 | 
										auto bground = scheme_ptr_->text_fgcolor;
 | 
				
			||||||
					::nana::color border, body, corner;
 | 
										::nana::color border, body, corner;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					switch (item_state)
 | 
										switch (item_state)
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
					case state::highlighted:
 | 
										case state::highlighted:
 | 
				
			||||||
						border = colors::highlight;
 | 
											border = scheme_ptr_->border_highlight;
 | 
				
			||||||
						body.from_rgb(0xC0, 0xDD, 0xFC);
 | 
											body = scheme_ptr_->body_highlight;
 | 
				
			||||||
						corner = body.blend(bground, 0.5);
 | 
											corner = body.blend(bground, 0.5);
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					case state::selected:
 | 
										case state::selected:
 | 
				
			||||||
						border = colors::dark_border;
 | 
											border = scheme_ptr_->border_selected;
 | 
				
			||||||
						body = colors::white;
 | 
											body = scheme_ptr_->body_selected;
 | 
				
			||||||
						corner = body.blend(bground, 0.5);
 | 
											corner = body.blend(bground, 0.5);
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					default:	//Don't process other states.
 | 
										default:	//Don't process other states.
 | 
				
			||||||
@ -120,14 +120,16 @@ namespace nana
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				void item_renderer::caption(const point& pos, const native_string_type& text)
 | 
									void item_renderer::caption(const point& pos, const native_string_type& text)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					graph_.string(pos, text, colors::black);
 | 
										graph_.string(pos, text, scheme_ptr_->text_fgcolor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			//end class item_renderer
 | 
								//end class item_renderer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//class trigger
 | 
								//class trigger
 | 
				
			||||||
				trigger::trigger()
 | 
									trigger::trigger()
 | 
				
			||||||
					: items_(new itembase)
 | 
										: widget_(nullptr)
 | 
				
			||||||
				{}
 | 
										, graph_(nullptr)
 | 
				
			||||||
 | 
										, items_(new itembase) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				trigger::~trigger()
 | 
									trigger::~trigger()
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
@ -213,13 +215,13 @@ namespace nana
 | 
				
			|||||||
						if (hotkey)
 | 
											if (hotkey)
 | 
				
			||||||
						{
 | 
											{
 | 
				
			||||||
							unsigned off_w = (hotkey_pos ? graph.text_extent_size(text.c_str(), hotkey_pos).width : 0);
 | 
												unsigned off_w = (hotkey_pos ? graph.text_extent_size(text.c_str(), hotkey_pos).width : 0);
 | 
				
			||||||
							nana::size hotkey_size = graph.text_extent_size(text.c_str() + hotkey_pos, 1);
 | 
												auto hotkey_size = graph.text_extent_size(text.c_str() + hotkey_pos, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							unsigned ascent, descent, inleading;
 | 
												unsigned ascent, descent, inleading;
 | 
				
			||||||
							graph.text_metrics(ascent, descent, inleading);
 | 
												graph.text_metrics(ascent, descent, inleading);
 | 
				
			||||||
							int x = item_pos.x + 8 + off_w;
 | 
												int x = item_pos.x + 8 + off_w;
 | 
				
			||||||
							int y = item_pos.y + text_top_off + ascent + 1;
 | 
												int y = item_pos.y + text_top_off + ascent + 1;
 | 
				
			||||||
							graph.line({ x, y }, { x + static_cast<int>(hotkey_size.width) - 1, y }, ::nana::colors::black);
 | 
												graph.line({ x, y }, { x + static_cast<int>(hotkey_size.width) - 1, y }, ird.scheme_ptr()->text_fgcolor);
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						item_pos.x += i->size.width;
 | 
											item_pos.x += i->size.width;
 | 
				
			||||||
@ -235,7 +237,7 @@ namespace nana
 | 
				
			|||||||
					bool popup = false;
 | 
										bool popup = false;
 | 
				
			||||||
					if(state_.behavior == state_type::behavior_focus)
 | 
										if(state_.behavior == state_type::behavior_focus)
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						std::size_t index = _m_item_by_pos(arg.pos);
 | 
											auto index = _m_item_by_pos(arg.pos);
 | 
				
			||||||
						if(index != npos && state_.active != index)
 | 
											if(index != npos && state_.active != index)
 | 
				
			||||||
						{
 | 
											{
 | 
				
			||||||
							state_.active = index;
 | 
												state_.active = index;
 | 
				
			||||||
@ -362,6 +364,7 @@ namespace nana
 | 
				
			|||||||
							case 2: //GOTO SUBMENU
 | 
												case 2: //GOTO SUBMENU
 | 
				
			||||||
								state_.menu->goto_submen();
 | 
													state_.menu->goto_submen();
 | 
				
			||||||
								break;
 | 
													break;
 | 
				
			||||||
 | 
												default: break;
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
							break;
 | 
												break;
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
@ -390,7 +393,7 @@ namespace nana
 | 
				
			|||||||
							}
 | 
												}
 | 
				
			||||||
							break;
 | 
												break;
 | 
				
			||||||
						default:
 | 
											default:
 | 
				
			||||||
							std::size_t index = items_->find(arg.key);
 | 
												auto index = items_->find(arg.key);
 | 
				
			||||||
							if(index != npos)
 | 
												if(index != npos)
 | 
				
			||||||
							{
 | 
												{
 | 
				
			||||||
								state_.active = index;
 | 
													state_.active = index;
 | 
				
			||||||
@ -418,7 +421,7 @@ namespace nana
 | 
				
			|||||||
						else
 | 
											else
 | 
				
			||||||
						{
 | 
											{
 | 
				
			||||||
							state_.behavior = state_type::behavior_none;
 | 
												state_.behavior = state_type::behavior_none;
 | 
				
			||||||
							nana::point pos = API::cursor_position();
 | 
												auto pos = API::cursor_position();
 | 
				
			||||||
							API::calc_window_point(widget_->handle(), pos);
 | 
												API::calc_window_point(widget_->handle(), pos);
 | 
				
			||||||
							state_.active = _m_item_by_pos(pos);
 | 
												state_.active = _m_item_by_pos(pos);
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
@ -433,7 +436,7 @@ namespace nana
 | 
				
			|||||||
				{
 | 
									{
 | 
				
			||||||
					API::focus_window(widget_->handle());
 | 
										API::focus_window(widget_->handle());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					std::size_t index = items_->find(arg.key);
 | 
										auto index = items_->find(arg.key);
 | 
				
			||||||
					if(index != npos && (index != state_.active || nullptr == state_.menu))
 | 
										if(index != npos && (index != state_.active || nullptr == state_.menu))
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						_m_close_menu();
 | 
											_m_close_menu();
 | 
				
			||||||
@ -455,7 +458,7 @@ namespace nana
 | 
				
			|||||||
					if(items_->cont().empty()) return;
 | 
										if(items_->cont().empty()) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					const std::size_t last_pos = items_->cont().size() - 1;
 | 
										const std::size_t last_pos = items_->cont().size() - 1;
 | 
				
			||||||
					std::size_t index = state_.active;
 | 
										auto index = state_.active;
 | 
				
			||||||
					if(to_left)
 | 
										if(to_left)
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						--index;
 | 
											--index;
 | 
				
			||||||
@ -564,7 +567,7 @@ namespace nana
 | 
				
			|||||||
				{
 | 
									{
 | 
				
			||||||
					if(state_.nullify_mouse == false)
 | 
										if(state_.nullify_mouse == false)
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						std::size_t which = _m_item_by_pos(pos);
 | 
											auto which = _m_item_by_pos(pos);
 | 
				
			||||||
						if((which != state_.active) && (which != npos || (false == state_.menu_active)))
 | 
											if((which != state_.active) && (which != npos || (false == state_.menu_active)))
 | 
				
			||||||
						{
 | 
											{
 | 
				
			||||||
							state_.active = which;
 | 
												state_.active = which;
 | 
				
			||||||
@ -602,7 +605,7 @@ namespace nana
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		void menubar::create(window wd)
 | 
							void menubar::create(window wd)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			widget_object<category::widget_tag, drawerbase::menubar::trigger>
 | 
								widget_object<category::widget_tag, drawerbase::menubar::trigger, ::nana::general_events, drawerbase::menubar::scheme>
 | 
				
			||||||
				::create(wd, rectangle(nana::size(API::window_size(wd).width, 28)));
 | 
									::create(wd, rectangle(nana::size(API::window_size(wd).width, 28)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			API::dev::set_menubar(handle(), true);
 | 
								API::dev::set_menubar(handle(), true);
 | 
				
			||||||
@ -621,7 +624,7 @@ namespace nana
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		menu& menubar::at(std::size_t index) const
 | 
							menu& menubar::at(std::size_t index) const
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			menu* p = get_drawer_trigger().at(index);
 | 
								auto p = get_drawer_trigger().at(index);
 | 
				
			||||||
			if(nullptr == p)
 | 
								if(nullptr == p)
 | 
				
			||||||
				throw std::out_of_range("menubar::at, out of range");
 | 
									throw std::out_of_range("menubar::at, out of range");
 | 
				
			||||||
			return *p;
 | 
								return *p;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user