/* * A Message Box Class * Nana C++ Library(http://www.nanapro.org) * Copyright(C) 2003-2017 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/msgbox.hpp */ #ifndef NANA_GUI_MSGBOX_HPP #define NANA_GUI_MSGBOX_HPP #include #include namespace nana { //Forward declaration of filebox for msgbox class filebox; /// Prefabricated modal dialog box (with text, icon and actions buttons) that inform and instruct the user. class msgbox { public: /// Identifiers of icons. enum icon_t{icon_none, icon_information, icon_warning, icon_error, icon_question}; /// Identifiers of buttons. enum button_t{ok, yes_no, yes_no_cancel}; /// Identifiers of buttons that a user clicked. enum pick_t{pick_ok, pick_yes, pick_no, pick_cancel}; /// Default construct that creates a message box with default title and default button, the default button is OK. msgbox(); /// Copy construct from an existing msgbox object. msgbox(const msgbox&); /// Assign from an existing msgbox object. msgbox& operator=(const msgbox&); /// Construct that creates a message box with a specified title and default button. msgbox(const ::std::string&); /// Construct that creates a message box with an owner windoow, a specified title and buttons. msgbox(window, const ::std::string&, button_t = ok); /// Sets an icon for informing user. msgbox& icon(icon_t); /// Clears the text message buffer. void clear(); /// Writes a string to the buffer. msgbox & operator<<(const std::wstring&); /// Writes a string to the buffer. msgbox & operator<<(const wchar_t*); /// Writes a UTF-8 string to the buffer. msgbox & operator<<(const std::string&); /// Writes a UTF-8 string to the buffer. msgbox & operator<<(const char*); /// Writes a string to the buffer. msgbox & operator<<(const nana::charset&); // Calls a manipulator to the stream. msgbox & operator<<(std::ostream& (*)(std::ostream&)); /// Write a streamizable object to the buffer. template msgbox & operator<<(const T& t) { sstream_< impl_; }; class integer : public abstract_content { struct implement; public: integer(::std::string label, int init_value, int begin, int last, int step); ~integer(); int value() const; private: //Implementation of abstract_content const ::std::string& label() const override; window create(window, unsigned label_px) override; unsigned fixed_pixels() const override; private: std::unique_ptr impl_; }; class real : public abstract_content { struct implement; public: real(::std::string label, double init_value, double begin, double last, double step); ~real(); double value() const; private: //Implementation of abstract_content const ::std::string& label() const override; window create(window, unsigned label_px) override; unsigned fixed_pixels() const override; private: std::unique_ptr impl_; }; class text : public abstract_content { struct implement; text(const text&) = delete; text& operator=(const text&) = delete; public: text(::std::string label, ::std::string init_text = ::std::string()); text(::std::string label, std::vector<::std::string>); ~text(); void tip_string(std::wstring tip); void tip_string(std::string tip_utf8); void mask_character(wchar_t ch); ::std::string value() const; private: //Implementation of abstract_content const ::std::string& label() const override; window create(window, unsigned label_px) override; unsigned fixed_pixels() const override; private: std::unique_ptr impl_; }; class date : public abstract_content { struct implement; public: date(::std::string label); ~date(); ::std::string value() const; int year() const; int month() const; //[1, 12] int day() const; //[1, 31] private: //Implementation of abstract_content const ::std::string& label() const override; window create(window, unsigned label_px) override; unsigned fixed_pixels() const override; private: std::unique_ptr impl_; }; class path : public abstract_content { struct implement; public: path(::std::string label, const ::nana::filebox&); ~path(); ::std::string value() const; private: //Implementation of abstract_content const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; }; inputbox(window, ::std::string description, ::std::string title = ::std::string()); void image(::nana::paint::image, bool is_left, const rectangle& valid_area = {}); void image_v(::nana::paint::image, bool is_top, const rectangle& valid_area = {}); template bool show(Args&& ... args) { std::vector contents; _m_fetch_args(contents, std::forward(args)...); if (contents.empty()) return false; return _m_open(contents, false); } template bool show_modal(Args&& ... args) { std::vector contents; _m_fetch_args(contents, std::forward(args)...); if (contents.empty()) return false; return _m_open(contents, true); } /// Sets a verifier to verify the user input. void verify(std::function verifier); /** Sets the minimum width for the entry fields @param[in] pixels new minimum width If not called, the default is 100 pixels */ void min_width_entry_field( unsigned pixels ); private: void _m_fetch_args(std::vector&); template void _m_fetch_args(std::vector& contents, abstract_content& content, Args&&... args) { contents.push_back(&content); _m_fetch_args(contents, std::forward(args)...); } bool _m_open(std::vector&, bool modal); private: window owner_; ::std::string description_; ::std::string title_; std::function verifier_; ::nana::paint::image images_[4]; ::nana::rectangle valid_areas_[4]; unsigned min_width_entry_field_pixels_; }; }//end namespace nana #include #endif