place::modify() now correctly updates the place::div_text.

This commit is contained in:
dankan1890 2016-09-29 13:54:12 +02:00
parent 830839ae27
commit 3c2b36ead8
2 changed files with 3166 additions and 3156 deletions

View File

@ -1,151 +1,151 @@
/* /*
* An Implementation of Place for Layout * An Implementation of Place for Layout
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2014 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
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
* *
* @file: nana/gui/place.cpp * @file: nana/gui/place.cpp
* *
* @contributions: * @contributions:
* min/max and splitter bar initial weight by Ariel Vina-Rodriguez. * min/max and splitter bar initial weight by Ariel Vina-Rodriguez.
*/ */
#ifndef NANA_GUI_PLACE_HPP #ifndef NANA_GUI_PLACE_HPP
#define NANA_GUI_PLACE_HPP #define NANA_GUI_PLACE_HPP
#include <nana/push_ignore_diagnostic> #include <nana/push_ignore_diagnostic>
#include <nana/gui/basis.hpp> #include <nana/gui/basis.hpp>
#include <memory> #include <memory>
#include <functional> #include <functional>
namespace nana namespace nana
{ {
class widget; class widget;
namespace detail namespace detail
{ {
class place_agent class place_agent
{ {
public: public:
virtual ~place_agent() = default; virtual ~place_agent() = default;
virtual std::unique_ptr<nana::widget> create(nana::window) const = 0; virtual std::unique_ptr<nana::widget> create(nana::window) const = 0;
}; };
} }
template<typename Widget> template<typename Widget>
class agent class agent
: public detail::place_agent : public detail::place_agent
{ {
public: public:
agent(std::function<void(Widget&)> initializer) agent(std::function<void(Widget&)> initializer)
: init_(std::move(initializer)) : init_(std::move(initializer))
{} {}
agent(const char* text) agent(const char* text)
: text_(text) : text_(text)
{ {
throw_not_utf8(text); throw_not_utf8(text);
} }
agent(std::string text, std::function<void(Widget&)> initializer = {}) agent(std::string text, std::function<void(Widget&)> initializer = {})
: text_(std::move(text)), init_(std::move(initializer)) : text_(std::move(text)), init_(std::move(initializer))
{ {
throw_not_utf8(text_); throw_not_utf8(text_);
} }
private: private:
std::unique_ptr<nana::widget> create(nana::window handle) const override std::unique_ptr<nana::widget> create(nana::window handle) const override
{ {
std::unique_ptr<Widget> ptr(new Widget(handle)); std::unique_ptr<Widget> ptr(new Widget(handle));
ptr->caption(text_); ptr->caption(text_);
if (init_) if (init_)
init_(*ptr); init_(*ptr);
return std::move(ptr); return std::move(ptr);
} }
private: private:
std::string text_; std::string text_;
std::function<void(Widget&)> init_; std::function<void(Widget&)> init_;
}; };
/// Layout managment - an object of class place is attached to a widget, and it automatically positions and resizes the children widgets. /// Layout managment - an object of class place is attached to a widget, and it automatically positions and resizes the children widgets.
class place class place
: ::nana::noncopyable : ::nana::noncopyable
{ {
struct implement; struct implement;
class field_interface class field_interface
{ {
field_interface(const field_interface&) = delete; field_interface(const field_interface&) = delete;
field_interface& operator=(const field_interface&) = delete; field_interface& operator=(const field_interface&) = delete;
field_interface(field_interface&&) = delete; field_interface(field_interface&&) = delete;
field_interface& operator=(field_interface&&) = delete; field_interface& operator=(field_interface&&) = delete;
public: public:
field_interface() = default; field_interface() = default;
virtual ~field_interface() = default; virtual ~field_interface() = default;
virtual field_interface& operator<<(const char* label) = 0; virtual field_interface& operator<<(const char* label) = 0;
virtual field_interface& operator<<(std::string label) = 0; virtual field_interface& operator<<(std::string label) = 0;
virtual field_interface& operator<<(window) = 0; virtual field_interface& operator<<(window) = 0;
virtual field_interface& fasten(window) = 0; virtual field_interface& fasten(window) = 0;
template<typename Widget> template<typename Widget>
field_interface& operator<<(const agent<Widget>& ag) field_interface& operator<<(const agent<Widget>& ag)
{ {
_m_add_agent(ag); _m_add_agent(ag);
return *this; return *this;
} }
private: private:
virtual void _m_add_agent(const detail::place_agent&) = 0; virtual void _m_add_agent(const detail::place_agent&) = 0;
}; };
public: public:
/// reference to a field manipulator which refers to a field object created by place /// reference to a field manipulator which refers to a field object created by place
using field_reference = field_interface &; using field_reference = field_interface &;
place(); place();
place(window);///< Attaches to a specified widget. place(window);///< Attaches to a specified widget.
~place(); ~place();
/** @brief Bind to a window /** @brief Bind to a window
* @param handle A handle to a window which the place wants to attach. * @param handle A handle to a window which the place wants to attach.
* @remark It will throw an exception if the place has already binded to a window. * @remark It will throw an exception if the place has already binded to a window.
*/ */
void bind(window handle); void bind(window handle);
window window_handle() const; window window_handle() const;
void div(const char* s); ///< Divides the attached widget into fields. void div(const char* s); ///< Divides the attached widget into fields.
const std::string& div() const noexcept; ///< Returns div-text that depends on fields status. const std::string& div() const noexcept; ///< Returns div-text that depends on fields status.
void modify(const char* field_name, const char* div_text); ///< Modifies a specified field. void modify(const char* field_name, const char* div_text); ///< Modifies a specified field.
field_reference field(const char* name);///< Returns a field with the specified name. field_reference field(const char* name);///< Returns a field with the specified name.
void field_visible(const char* field_name, bool visible); ///<<Shows/Hides an existing field. void field_visible(const char* field_name, bool visible) const; ///<<Shows/Hides an existing field.
bool field_visible(const char* field_name) const; ///<Determines whether the specified field is visible. bool field_visible(const char* field_name) const; ///<Determines whether the specified field is visible.
void field_display(const char* field_name, bool display); ///<Displays/Discards an existing field. void field_display(const char* field_name, bool display) const; ///<Displays/Discards an existing field.
bool field_display(const char* field_name) const; ///<Determines whether the specified field is displayed. bool field_display(const char* field_name) const; ///<Determines whether the specified field is displayed.
void collocate(); ///< Layouts the widgets. void collocate(); ///< Layouts the widgets.
void erase(window handle); ///< Erases a window from field. void erase(window handle); ///< Erases a window from field.
field_reference operator[](const char* name); ///< Returns a field with the specified name. Equal to field(); field_reference operator[](const char* name); ///< Returns a field with the specified name. Equal to field();
/// Add a panel factory /// Add a panel factory
template<typename Panel, typename ...Args> template<typename Panel, typename ...Args>
place& dock(const std::string& dockname, const std::string& factory_name, Args&& ... args) place& dock(const std::string& dockname, const std::string& factory_name, Args&& ... args)
{ {
return dock(dockname, factory_name, std::bind([](window parent, Args & ... args) return dock(dockname, factory_name, std::bind([](window parent, Args & ... args)
{ {
return std::unique_ptr<widget>(new Panel(parent, std::forward<Args>(args)...)); return std::unique_ptr<widget>(new Panel(parent, std::forward<Args>(args)...));
}, std::placeholders::_1, args...)); }, std::placeholders::_1, args...));
} }
place& dock(const std::string& dockname, std::string factory_name, std::function<std::unique_ptr<widget>(window)> factory); place& dock(const std::string& dockname, std::string factory_name, std::function<std::unique_ptr<widget>(window)> factory);
widget* dock_create(const std::string& factory); widget* dock_create(const std::string& factory);
private: private:
implement * impl_; implement * impl_;
}; };
}//end namespace nana }//end namespace nana
#include <nana/pop_ignore_diagnostic> #include <nana/pop_ignore_diagnostic>
#endif //#ifndef NANA_GUI_PLACE_HPP #endif //#ifndef NANA_GUI_PLACE_HPP

File diff suppressed because it is too large Load Diff