improve inputbox

fix some inputbox issues
add a new inputbox::path class
This commit is contained in:
Jinhao 2015-02-25 01:00:27 +08:00
parent f454a965be
commit c2cb89f024
4 changed files with 164 additions and 9 deletions

View File

@ -1,19 +1,42 @@
/*
* Filebox
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 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/filebox.hpp
*/
#ifndef NANA_GUI_FILEBOX_HPP
#define NANA_GUI_FILEBOX_HPP
#include <nana/gui/wvl.hpp>
#include <nana/gui/basis.hpp>
#include <vector>
#include <utility>
namespace nana
{ /// Create an Open or Save dialog box to let user select the name of a file.
class filebox
: nana::noncopyable
{
struct implement;
public:
typedef std::vector<std::pair<nana::string, nana::string>> filters;
filebox(filebox&&) = delete;
filebox& operator=(filebox&&) = delete;
public:
using filters = std::vector<std::pair<nana::string, nana::string>>;
filebox(bool is_open_mode);
filebox(window owner, bool is_open_mode);
filebox(const filebox&);
~filebox();
filebox& operator=(const filebox&);
/// Change owner window
void owner(window);
/** @brief specify a title for the dialog
* @param string a text for title
*/

View File

@ -14,7 +14,7 @@
#define NANA_GUI_MSGBOX_HPP
#include <sstream>
#include <nana/gui/basis.hpp>
#include <nana/gui/filebox.hpp>
namespace nana
{
@ -188,7 +188,7 @@ namespace nana
{
struct implement;
public:
path(::nana::string label, ::nana::string init_path = ::nana::string());
path(::nana::string label, const ::nana::filebox&);
~path();
::nana::string value() const;
@ -196,7 +196,6 @@ namespace nana
//Implementation of abstract_content
const ::nana::string& label() const override;
window create(window, unsigned label_px) override;
unsigned fixed_pixels() const override;
private:
std::unique_ptr<implement> impl_;
};

View File

@ -1,4 +1,16 @@
#include <nana/gui/filebox.hpp>
/*
* Filebox
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 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/filebox.cpp
*/
#include <nana/gui.hpp>
#include <nana/filesystem/fs_utility.hpp>
#if defined(NANA_WINDOWS)
@ -858,6 +870,11 @@ namespace nana
std::vector<filter> filters;
};
filebox::filebox(bool is_openmode)
: filebox(nullptr, is_openmode)
{
}
filebox::filebox(window owner, bool open)
: impl_(new implement)
{
@ -874,11 +891,27 @@ namespace nana
#endif
}
filebox::filebox(const filebox& other)
: impl_(new implement(*other.impl_))
{}
filebox::~filebox()
{
delete impl_;
}
filebox& filebox::operator=(const filebox& other)
{
if (this != &other)
*impl_ = *other.impl_;
return *this;
}
void filebox::owner(window wd)
{
impl_->owner = wd;
}
nana::string filebox::title(nana::string s)
{
impl_->title.swap(s);

View File

@ -676,6 +676,9 @@ namespace nana
int inputbox::integer::value() const
{
if (!impl_->spinbox.empty())
return impl_->spinbox.to_int();
return impl_->value;
}
@ -751,6 +754,9 @@ namespace nana
double inputbox::real::value() const
{
if (!impl_->spinbox.empty())
return impl_->spinbox.to_double();
return impl_->value;
}
@ -788,7 +794,7 @@ namespace nana
impl->spinbox.events().destroy.connect_unignorable([impl]
{
impl->value = impl->spinbox.to_int();
impl->value = impl->spinbox.to_double();
});
return impl->dock;
@ -844,6 +850,11 @@ namespace nana
::nana::string inputbox::text::value() const
{
if (!impl_->textbox.empty())
return impl_->textbox.caption();
else if (!impl_->combox.empty())
return impl_->combox.caption();
return impl_->value;
}
@ -869,6 +880,7 @@ namespace nana
impl->textbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, 0, 0 });
impl->textbox.tip_string(impl->tip);
impl->textbox.mask(impl->mask_character);
impl->textbox.multi_lines(false);
}
else
{
@ -940,16 +952,23 @@ namespace nana
int inputbox::date::year() const
{
if (!impl_->wdg_year.empty())
return impl_->wdg_year.to_int();
return impl_->year;
}
int inputbox::date::month() const
{
if (!impl_->wdg_month.empty())
return impl_->wdg_month.option() + 1;
return impl_->month;
}
int inputbox::date::day() const
{
if (!impl_->wdg_day.empty())
return impl_->wdg_day.to_int();
return impl_->day;
}
@ -1046,6 +1065,87 @@ namespace nana
}
//end class date
//class path
struct inputbox::path::implement
{
filebox fbox;
::nana::string value;
::nana::string label_text;
::nana::panel<false> dock;
::nana::label label;
::nana::textbox path_edit;
::nana::button browse;
implement(const filebox& fb, ::nana::string&& labelstr)
: fbox(fb), label_text(std::move(labelstr))
{}
};
inputbox::path::path(::nana::string label, const filebox& fb)
: impl_(new implement(fb, std::move(label)))
{
}
//Instance for impl_ because implmenet is incomplete type at the point of declaration
inputbox::path::~path(){}
::nana::string inputbox::path::value() const
{
if (!impl_->path_edit.empty())
return impl_->path_edit.caption();
return impl_->value;
}
//Implementation of abstract_content
const ::nana::string& inputbox::path::label() const
{
return impl_->label_text;
}
window inputbox::path::create(window wd, unsigned label_px)
{
auto impl = impl_.get();
impl->dock.create(wd);
impl->label.create(impl->dock, rectangle{ 0, 0, label_px, 0 });
impl->label.text_align(::nana::align::right, ::nana::align_v::center);
impl->label.caption(impl->label_text);
impl->label.format(true);
impl->path_edit.create(impl->dock, rectangle{static_cast<int>(label_px + 10), 0, 0, 0});
impl->path_edit.caption(impl->fbox.path());
impl->path_edit.multi_lines(false);
impl->browse.create(impl->dock);
impl->browse.i18n(i18n_eval("Browse"));
impl->browse.events().click([wd, impl]
{
impl->fbox.owner(wd);
if (impl->fbox.show())
{
impl->value = impl->fbox.file();
impl->path_edit.caption(impl->value);
}
});
impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg)
{
impl->label.size({ label_px, arg.height });
impl->path_edit.size({arg.width - label_px - 75, arg.height});
impl->browse.move({static_cast<int>(arg.width - 60), 0, 60, arg.height});
});
impl->path_edit.events().destroy.connect_unignorable([impl]
{
impl->value = impl->path_edit.caption();
});
return impl->dock;
}
//end class path
inputbox::inputbox(window owner, ::nana::string desc, ::nana::string title)
: owner_{ owner },