File: textbox.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (140 lines) | stat: -rw-r--r-- 5,792 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* 
 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#pragma once

#include <mforms/view.h>
#include <mforms/utilities.h>

namespace mforms {
  enum ScrollBars {
    NoScrollBar= 0,                 //!< Don't show any scroll bar.
    HorizontalScrollBar = (1 << 0), //!< Show only the horizontal scroll bar.
    VerticalScrollBar = (1 << 1),   //!< Show only the vertical scroll bar.
    BothScrollBars = (HorizontalScrollBar | VerticalScrollBar), //!< Show both scroll bars.
    SmallScrollBars = (1 << 2)      //!< A smaller version of the scrollbars.
  };

  /**
   * Code which abstracts special keys for each platform, to be used in the key event.
   */
  enum KeyCode {
    KeyNone,
    KeyChar,         //!< No special char. The key event has the entered character(s) in the text field.
    KeyModifierOnly, //!< A combination of Shift/Control/Command/Alt only, without another key.
    KeyEnter,        //!< The numpad <enter> key.
    KeyReturn,       //!< The main keyboard <return> key.
    KeyHome,
    KeyEnd,
    KeyPrevious,
    KeyNext,
    KeyUnkown,       //!< Any other key, not yet mapped.
  };

  class TextBox;

#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef SWIG
  struct TextBoxImplPtrs
  {
    bool (*create)(TextBox *self, ScrollBars scroll_bars);
    void (*set_bordered)(TextBox *self, bool flag);
    void (*set_read_only)(TextBox *self, bool flag);
    void (*set_text)(TextBox *self, const std::string &text);
    std::string (*get_text)(TextBox *self);
    void (*append_text)(TextBox *self, const std::string &text, bool scroll_to_end);
//    void (*append_text_with_attributes)(TextBox *self, const std::string &text, const TextAttributes &attr, bool scroll_to_end);
    void (*set_padding)(TextBox *self, int pad); // TODO: not supported on Windows, should be removed.
    void (*set_monospaced)(TextBox *self, bool flag);
    void (*get_selected_range)(TextBox *self, int &start, int &end);
    void (*clear)(TextBox *self);
  };
#endif
#endif

  /** Multiline text editing control */
  class MFORMS_EXPORT TextBox : public View
  {
#ifdef SWIG
#if SWIG_VERSION < 0x030003 || SWIG_VERSION >= 0x030008  // starting with SWIG v3.0.3, this is no longer necessary (https://github.com/swig/swig/pull/201)
//workaround for problem with unicode strings and default args in swig
%rename(append_text_and_scroll) append_text(const std::string &text, bool scroll_to_end);
%rename(append_text) append_text(const std::string &text, bool scroll_to_end);

%rename(append_text_with_encoding_and_scroll) append_text_with_encoding(const std::string &text, const std::string &encoding, bool scroll_to_end);
%rename(append_text_with_encoding) append_text_with_encoding(const std::string &text, const std::string &encoding, bool scroll_to_end);
#endif
#endif
  public:
    TextBox(ScrollBars scroll_bars);

    /** Sets whether to draw a border around the text box */
    void set_bordered(bool flag);
    /** Sets whether text should be displayed in a monospaced font */
    void set_monospaced(bool flag);
    
    /** Sets whether the content of the text box is editable by the user */
    void set_read_only(bool flag);
    /** Sets the text contents of the control */
    void set_value(const std::string &text);
    /** Gets the text contents of the control */
    virtual std::string get_string_value();
    
    /** Gets range of selected text */
    void get_selected_range(int &start, int &end);
    
    /** Appends text to the end of the text box. 
     
     If scroll_to_end is true, it will also scroll to make the end of the text box visible. */
    void append_text(const std::string &text, bool scroll_to_end= false);

    /** Appends text to the end of the text box, in the given character set encoding.
     
     If scroll_to_end is true, it will also scroll to make the end of the text box visible. */
    void append_text_with_encoding(const std::string &text, const std::string &encoding, bool scroll_to_end= false);
   
    /** Sets padding */
    void set_padding(int pad);
    
    /** Clear contents */
    void clear();

#ifndef SWIG
    /** Signal emitted when control's text changes (e.g. by typing, pasting etc.). */
    boost::signals2::signal<void ()>* signal_changed() { return &_signal_changed; };

    /** Signal emitted when a key was pressed. The key code determines if it was a normal character or
     *  a special key. If a normal character was entered then the modifier keys have already been taken
     *  into account (e.g. for upper/lower casing etc.). The given text is (as always) utf-8 encoded.
     */
    boost::signals2::signal<bool (KeyCode, ModifierKey, const std::string&)>* key_event_signal() { return &_key_event_signal; };
#ifndef DOXYGEN_SHOULD_SKIP_THIS
  public:
    void callback();
    bool key_event(KeyCode code, ModifierKey modifiers, const std::string& text);
#endif
#endif
  protected:
    TextBoxImplPtrs *_textbox_impl;
    bool _updating;
    
    boost::signals2::signal<void ()> _signal_changed;
    boost::signals2::signal<bool (KeyCode, ModifierKey, const std::string&)> _key_event_signal;
  };
};