File: textentry.h

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (153 lines) | stat: -rw-r--r-- 5,563 bytes parent folder | download | duplicates (4)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
///////////////////////////////////////////////////////////////////////////////
// Name:        wx/gtk/textentry.h
// Purpose:     wxGTK-specific wxTextEntry implementation
// Author:      Vadim Zeitlin
// Created:     2007-09-24
// Copyright:   (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

#ifndef _WX_GTK_TEXTENTRY_H_
#define _WX_GTK_TEXTENTRY_H_

typedef struct _GdkEventKey GdkEventKey;
typedef struct _GtkEditable GtkEditable;
typedef struct _GtkEntry GtkEntry;

class wxTextAutoCompleteData; // private class used only by wxTextEntry itself
class wxTextCoalesceData;     // another private class

// ----------------------------------------------------------------------------
// wxTextEntry: roughly corresponds to GtkEditable
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
{
public:
    wxTextEntry();
    virtual ~wxTextEntry();

    // implement wxTextEntryBase pure virtual methods
    virtual void WriteText(const wxString& text) wxOVERRIDE;
    virtual void Remove(long from, long to) wxOVERRIDE;

    virtual void Copy() wxOVERRIDE;
    virtual void Cut() wxOVERRIDE;
    virtual void Paste() wxOVERRIDE;

    virtual void Undo() wxOVERRIDE;
    virtual void Redo() wxOVERRIDE;
    virtual bool CanUndo() const wxOVERRIDE;
    virtual bool CanRedo() const wxOVERRIDE;

    virtual void SetInsertionPoint(long pos) wxOVERRIDE;
    virtual long GetInsertionPoint() const wxOVERRIDE;
    virtual long GetLastPosition() const wxOVERRIDE;

    virtual void SetSelection(long from, long to) wxOVERRIDE;
    virtual void GetSelection(long *from, long *to) const wxOVERRIDE;

    virtual bool IsEditable() const wxOVERRIDE;
    virtual void SetEditable(bool editable) wxOVERRIDE;

    virtual void SetMaxLength(unsigned long len) wxOVERRIDE;
    virtual void ForceUpper() wxOVERRIDE;

#ifdef __WXGTK3__
    virtual bool SetHint(const wxString& hint) wxOVERRIDE;
    virtual wxString GetHint() const wxOVERRIDE;
#endif

    // implementation only from now on
    void SendMaxLenEvent();
    bool GTKEntryOnInsertText(const char* text);
    bool GTKIsUpperCase() const { return m_isUpperCase; }

    // Called from "changed" signal handler (or, possibly, slightly later, when
    // coalescing several "changed" signals into a single event) for GtkEntry.
    //
    // By default just generates a wxEVT_TEXT, but overridden to do more things
    // in wxTextCtrl.
    virtual void GTKOnTextChanged() { SendTextUpdatedEvent(); }

    // Helper functions only used internally.
    wxTextCoalesceData* GTKGetCoalesceData() const { return m_coalesceData; }

protected:
    // This method must be called from the derived class Create() to connect
    // the handlers for the clipboard (cut/copy/paste) events.
    void GTKConnectClipboardSignals(GtkWidget* entry);

    // And this one to connect "insert-text" signal.
    void GTKConnectInsertTextSignal(GtkEntry* entry);

    // Finally this one connects to the "changed" signal on the object returned
    // by GetTextObject().
    void GTKConnectChangedSignal();


    virtual void DoSetValue(const wxString& value, int flags) wxOVERRIDE;
    virtual wxString DoGetValue() const wxOVERRIDE;

    // margins functions
    virtual bool DoSetMargins(const wxPoint& pt) wxOVERRIDE;
    virtual wxPoint DoGetMargins() const wxOVERRIDE;

    virtual bool DoAutoCompleteStrings(const wxArrayString& choices) wxOVERRIDE;
    virtual bool DoAutoCompleteCustom(wxTextCompleter *completer) wxOVERRIDE;

    // Call this from the overridden wxWindow::GTKIMFilterKeypress() to use
    // GtkEntry IM context.
    int GTKEntryIMFilterKeypress(GdkEventKey* event) const;

    // If GTKEntryIMFilterKeypress() is not called (as multiline wxTextCtrl
    // uses its own IM), call this method instead to still notify wxTextEntry
    // about the key press events in the given widget.
    void GTKEntryOnKeypress(GtkWidget* widget) const;


    static int GTKGetEntryTextLength(GtkEntry* entry);

    // Block/unblock the corresponding GTK signal.
    //
    // Note that we make it protected in wxGTK as it is called from wxComboBox
    // currently.
    virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE;

    // Helper for wxTE_PROCESS_ENTER handling: activates the default button in
    // the dialog containing this control if any.
    bool ClickDefaultButtonIfPossible();

private:
    // implement this to return the associated GtkEntry or another widget
    // implementing GtkEditable
    virtual GtkEditable *GetEditable() const = 0;

    // implement this to return the associated GtkEntry
    virtual GtkEntry *GetEntry() const = 0;

    // This one exists in order to be overridden by wxTextCtrl which uses
    // either GtkEditable or GtkTextBuffer depending on whether it is single-
    // or multi-line.
    virtual void *GetTextObject() const { return GetEntry(); }


    // Various auto-completion-related stuff, only used if any of AutoComplete()
    // methods are called.
    wxTextAutoCompleteData *m_autoCompleteData;

    // It needs to call our GetEntry() method.
    friend class wxTextAutoCompleteData;

    // Data used for coalescing "changed" events resulting from a single user
    // action.
    mutable wxTextCoalesceData* m_coalesceData;

    bool m_isUpperCase;
};

// We don't need the generic version.
#define wxHAS_NATIVE_TEXT_FORCEUPPER

#endif // _WX_GTK_TEXTENTRY_H_