/* * An Implementation of Place for Layout * Nana C++ Library(http://www.nanapro.org) * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file: nana/gui/place.cpp * * @contributions: * min/max and splitter bar initial weight by Ariel Vina-Rodriguez. */ #ifndef NANA_GUI_PLACE_HPP #define NANA_GUI_PLACE_HPP #include #include #include #include namespace nana { namespace paint { class graphics; } class widget; namespace detail { class place_agent { public: virtual ~place_agent() = default; virtual std::unique_ptr create(nana::window) const = 0; }; } template class agent : public detail::place_agent { public: agent(std::function initializer) : init_(std::move(initializer)) {} agent(const char* text) : text_(text) { throw_not_utf8(text); } agent(std::string text, std::function initializer = {}) : text_(std::move(text)), init_(std::move(initializer)) { throw_not_utf8(text_); } private: std::unique_ptr create(nana::window handle) const override { std::unique_ptr ptr(new Widget(handle)); ptr->caption(text_); if (init_) init_(*ptr); return std::move(ptr); } private: std::string text_; std::function init_; }; /// Layout managment - an object of class place is attached to a widget, and it automatically positions and resizes the children widgets. class place : ::nana::noncopyable { struct implement; class field_interface { field_interface(const field_interface&) = delete; field_interface& operator=(const field_interface&) = delete; field_interface(field_interface&&) = delete; field_interface& operator=(field_interface&&) = delete; public: field_interface() = default; virtual ~field_interface() = default; virtual field_interface& operator<<(const char* label) = 0; virtual field_interface& operator<<(std::string label) = 0; virtual field_interface& operator<<(window) = 0; virtual field_interface& fasten(window) = 0; template field_interface& operator<<(const agent& ag) { _m_add_agent(ag); return *this; } private: virtual void _m_add_agent(const detail::place_agent&) = 0; }; public: /// reference to a field manipulator which refers to a field object created by place using field_reference = field_interface &; place(); place(window);///< Attaches to a specified widget. ~place(); /** @brief Bind to a window * @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. */ void bind(window handle); window window_handle() const; void splitter_renderer(std::function fn); 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. 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. void field_visible(const char* field_name, bool visible); ///< 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 std::unique_ptr(new Panel(parent, std::forward(args)...)); }, std::placeholders::_1, args...)); } place& dock(const std::string& dockname, std::string factory_name, std::function(window)> factory); widget* dock_create(const std::string& factory); private: implement * impl_; }; }//end namespace nana #include #endif //#ifndef NANA_GUI_PLACE_HPP