new features of listbox

text line number and line indent
This commit is contained in:
Jinhao
2015-10-21 01:39:11 +08:00
parent c6f2f28f81
commit 5590dd293b
9 changed files with 232 additions and 20 deletions

View File

@@ -14,7 +14,7 @@
#define NANA_GUI_WIDGETS_COMBOX_HPP
#include "widget.hpp"
#include "float_listbox.hpp"
#include "skeletons/text_editor_scheme.hpp"
#include "skeletons/text_editor_part.hpp"
#include <nana/key_type.hpp>
#include <nana/concepts.hpp>
#include <functional>

View File

@@ -14,7 +14,7 @@
#ifndef NANA_GUI_SKELETONS_TEXT_EDITOR_HPP
#define NANA_GUI_SKELETONS_TEXT_EDITOR_HPP
#include "textbase.hpp"
#include "text_editor_scheme.hpp"
#include "text_editor_part.hpp"
#include <nana/gui/widgets/scroll.hpp>
#include <nana/unicode_bidi.hpp>
@@ -135,6 +135,8 @@ namespace nana{ namespace widgets
using size_type = textbase<char_type>::size_type;
using string_type = textbase<char_type>::string_type;
using event_interface = text_editor_event_interface;
using graph_reference = ::nana::paint::graphics&;
struct ext_renderer_tag
@@ -162,6 +164,9 @@ namespace nana{ namespace widgets
void typeface_changed();
void indent(bool, std::function<nana::string()> generator);
void set_event(event_interface*);
/// Determine whether the text_editor is line wrapped.
bool line_wrapped() const;
/// Set the text_editor whether it is line wrapped, it returns false if the state is not changed.
@@ -174,6 +179,10 @@ namespace nana{ namespace widgets
/// Sets the text area.
/// @return true if the area is changed with the new value.
bool text_area(const nana::rectangle&);
/// Returns the text area
rectangle text_area(bool including_scroll) const;
bool tip_string(nana::string&&);
const attributes & attr() const;
@@ -215,8 +224,13 @@ namespace nana{ namespace widgets
/// Returns width of text area excluding the vscroll size.
unsigned width_pixels() const;
window window_handle() const;
/// Returns text position of each line that currently displays on screen
const std::vector<upoint>& text_position() const;
void set_text_position_changed(std::function<void(const std::vector<upoint>&)>);
public:
void draw_scroll_rectangle();
void draw_corner();
void render(bool focused);
public:
void put(nana::string);
@@ -242,6 +256,8 @@ namespace nana{ namespace widgets
skeletons::textbase<nana::char_t>& textbase();
const skeletons::textbase<nana::char_t>& textbase() const;
std::vector<unsigned> get_lines() const;
private:
bool _m_accepts(char_type) const;
::nana::color _m_bgcolor() const;
@@ -294,7 +310,8 @@ namespace nana{ namespace widgets
undoable<command> undo_;
nana::window window_;
graph_reference graph_;
const text_editor_scheme* scheme_;
const text_editor_scheme* scheme_;
event_interface * event_handler_{ nullptr };
std::unique_ptr<keywords> keywords_;
skeletons::textbase<nana::char_t> textbase_;
@@ -302,6 +319,15 @@ namespace nana{ namespace widgets
mutable ext_renderer_tag ext_renderer_;
std::vector<upoint> text_position_; //position of text from last rendering.
std::function<void(const std::vector<upoint>&)> text_position_function_;
struct indent_rep
{
bool enabled{ false };
std::function<nana::string()> generator;
}indent_;
struct attributes
{
accepts acceptive{ accepts::no_restrict };

View File

@@ -3,6 +3,7 @@
#define NANA_WIDGETS_SKELETONS_TEXT_EDITOR_SCHEME_HPP
#include "../../detail/widget_colors.hpp"
#include <vector>
namespace nana
{
@@ -16,6 +17,14 @@ namespace nana
color_proxy selection{static_cast<color_rgb>(0x3399FF)};
color_proxy selection_text{colors::white};
};
class text_editor_event_interface
{
public:
virtual ~text_editor_event_interface() = default;
virtual void text_position_changed(const std::vector<upoint>&) = 0;
};
}
}
}

View File

@@ -13,7 +13,7 @@
#ifndef NANA_GUI_WIDGET_SPINBOX_HPP
#define NANA_GUI_WIDGET_SPINBOX_HPP
#include "widget.hpp"
#include "skeletons/text_editor_scheme.hpp"
#include "skeletons/text_editor_part.hpp"
namespace nana
{

View File

@@ -13,7 +13,7 @@
#define NANA_GUI_WIDGET_TEXTBOX_HPP
#include <nana/gui/widgets/widget.hpp>
#include "skeletons/textbase_export_interface.hpp"
#include "skeletons/text_editor_scheme.hpp"
#include "skeletons/text_editor_part.hpp"
namespace nana
{
@@ -23,10 +23,20 @@ namespace nana
: public event_arg
{
textbox& widget;
const std::vector<upoint>* text_position;
arg_textbox(textbox&);
};
struct arg_textbox_text_position
: public event_arg
{
textbox& widget;
const std::vector<upoint>& text_position;
arg_textbox_text_position(textbox&, const std::vector<upoint>&);
};
namespace widgets
{
namespace skeletons
@@ -44,15 +54,30 @@ namespace nana
{
basic_event<arg_textbox> first_change;
basic_event<arg_textbox> text_changed;
basic_event<arg_textbox_text_position> text_position_changed;
};
class event_interface
{
public:
virtual ~event_interface() = default;
virtual void text_position_changed(const std::vector<upoint>&) = 0;
};
class event_agent
: public widgets::skeletons::textbase_event_agent_interface
: public widgets::skeletons::textbase_event_agent_interface,
public widgets::skeletons::text_editor_event_interface
{
public:
event_agent(::nana::textbox&);
private:
//Overrides textbase_event_agent_interface
void first_change() override;
void text_changed() override;
private:
//Overrides text_editor_event_interface
void text_position_changed(const std::vector<upoint>&) override;
private:
::nana::textbox & widget_;
};
@@ -128,8 +153,12 @@ namespace nana
void store(nana::string file);
void store(nana::string file, nana::unicode encoding);
/// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter.
/// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line.
void enable_indent(bool, std::function<nana::string()> generator = {});
//A workaround for reset, explicit default constructor syntax, because VC2013 incorrectly treats {} as {0}.
textbox& reset(nana::string = nana::string()); ///< discard the old text and set a newtext
textbox& reset(nana::string = nana::string()); ///< discard the old text and set a new text
/// The file of last store operation.
nana::string filename() const;
@@ -188,6 +217,16 @@ namespace nana
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<nana::string> kw_list);
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::string> kw_list_utf8);
void erase_keyword(const nana::string& kw);
/// Returns the text position of each line that currently displays on screen.
std::vector<upoint> text_position() const;
/// Returns the rectangle of text area
rectangle text_area() const;
/// Returns the height of line in pixels
unsigned line_pixels() const;
protected:
//Overrides widget's virtual functions
::nana::string _m_caption() const throw() override;

View File

@@ -20,6 +20,7 @@
#include "widgets/form.hpp"
#include "drawing.hpp"
#include "msgbox.hpp"
#include "place.hpp"
namespace nana
{