File: textentry.h

package info (click to toggle)
mysql-workbench 6.2.3%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 102,612 kB
  • ctags: 84,593
  • sloc: ansic: 804,682; cpp: 438,759; yacc: 59,129; python: 54,293; xml: 48,851; sql: 5,512; objc: 1,414; makefile: 505; sh: 455; java: 237; ruby: 6; perl: 5; php: 1
file content (129 lines) | stat: -rw-r--r-- 4,059 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
/* 
 * Copyright (c) 2008, 2014, 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>

namespace mforms {
  class TextEntry;
     
  enum TextEntryType
  {
    NormalEntry, //!< a normal plain text entry
    PasswordEntry, //!< password entry, will hide typed characters
    SearchEntry, //!< normal text entry, with a distinctive appearance for search
#ifdef __APPLE__
    SmallSearchEntry
#else
    SmallSearchEntry = SearchEntry
#endif
  };
  
  enum TextEntryAction
  {
    EntryActivate, //!< Enter key was pressed
    EntryKeyUp, //!< Up arrow key was pressed
    EntryKeyDown, //!< Down arrow key was pressed
    EntryCKeyUp, //!< Up arrow key was pressed with Control/Command held
    EntryCKeyDown //!< Down arrow key was pressed with Control/Command held
  };

#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef SWIG
  struct TextEntryImplPtrs
  {
    bool (*create)(TextEntry *self, TextEntryType type);
    void (*set_text)(TextEntry *self, const std::string &text);
    void (*set_max_length)(TextEntry *self, int len);
    std::string (*get_text)(TextEntry *self);
    void (*set_read_only)(TextEntry *self, bool flag);
    void (*set_placeholder_text)(TextEntry *self, const std::string &text);
    void (*set_placeholder_color)(TextEntry *self, const std::string &color);
    void (*set_bordered)(TextEntry *self, bool flag);

    void (*cut)(TextEntry *self); // TODO Windows
    void (*copy)(TextEntry *self);
    void (*paste)(TextEntry *self);
    void (*select)(TextEntry *self, const base::Range &range);
    base::Range (*get_selection)(TextEntry *self);
  };
#endif
#endif

  /** Single line text edit control, with support for some special events. */
  class MFORMS_EXPORT TextEntry : public View
  {
  public:
    /** Constructor. 
    */
    TextEntry(TextEntryType type = NormalEntry);

    /** Sets the max allowed length that the user can type */
    void set_max_length(int len);

    /** Sets the text in the entry */
    void set_value(const std::string &text);
    
    /** Gets the text in the entry */
    virtual std::string get_string_value();
    
    /** Sets whether contents of entry can be edited by the user */
    void set_read_only(bool flag);

    /** Sets the text to be shown as a placeholder, when there's no text in the entry */
    void set_placeholder_text(const std::string &text);

    /** Foreground color for the placeholder text. */
    void set_placeholder_color(const std::string &color);

    /** Sets whether to draw a border around the text box. Default is bordered. */
    void set_bordered(bool flag);


    void cut();
    void copy();
    void paste();
    void select(const base::Range &);
    base::Range get_selection();

#ifndef SWIG
    /** Signal emitted when the entry is edited 
     
     In Python use add_changed_callback() */
    boost::signals2::signal<void ()>* signal_changed() { return &_signal_changed; }
    
    /** Signal emitted when certain actions are performed:
     
     */
    boost::signals2::signal<void (TextEntryAction)>* signal_action() { return &_signal_action; }

  public:
    void callback();
    void action(TextEntryAction action);
#endif
  protected:
    TextEntryImplPtrs *_textentry_impl;

    boost::signals2::signal<void ()> _signal_changed;
    boost::signals2::signal<void (TextEntryAction)> _signal_action;
    
    bool _updating;
  };
};