1 /////////////////////////////////////////////////////////////////////////////// 2 // Name: wx/gtk/textentry.h 3 // Purpose: wxGTK-specific wxTextEntry implementation 4 // Author: Vadim Zeitlin 5 // Created: 2007-09-24 6 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org> 7 // Licence: wxWindows licence 8 /////////////////////////////////////////////////////////////////////////////// 9 10 #ifndef _WX_GTK_TEXTENTRY_H_ 11 #define _WX_GTK_TEXTENTRY_H_ 12 13 typedef struct _GdkEventKey GdkEventKey; 14 typedef struct _GtkEditable GtkEditable; 15 typedef struct _GtkEntry GtkEntry; 16 17 class wxTextAutoCompleteData; // private class used only by wxTextEntry itself 18 class wxTextCoalesceData; // another private class 19 20 // ---------------------------------------------------------------------------- 21 // wxTextEntry: roughly corresponds to GtkEditable 22 // ---------------------------------------------------------------------------- 23 24 class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase 25 { 26 public: 27 wxTextEntry(); 28 virtual ~wxTextEntry(); 29 30 // implement wxTextEntryBase pure virtual methods 31 virtual void WriteText(const wxString& text) wxOVERRIDE; 32 virtual void Remove(long from, long to) wxOVERRIDE; 33 34 virtual void Copy() wxOVERRIDE; 35 virtual void Cut() wxOVERRIDE; 36 virtual void Paste() wxOVERRIDE; 37 38 virtual void Undo() wxOVERRIDE; 39 virtual void Redo() wxOVERRIDE; 40 virtual bool CanUndo() const wxOVERRIDE; 41 virtual bool CanRedo() const wxOVERRIDE; 42 43 virtual void SetInsertionPoint(long pos) wxOVERRIDE; 44 virtual long GetInsertionPoint() const wxOVERRIDE; 45 virtual long GetLastPosition() const wxOVERRIDE; 46 47 virtual void SetSelection(long from, long to) wxOVERRIDE; 48 virtual void GetSelection(long *from, long *to) const wxOVERRIDE; 49 50 virtual bool IsEditable() const wxOVERRIDE; 51 virtual void SetEditable(bool editable) wxOVERRIDE; 52 53 virtual void SetMaxLength(unsigned long len) wxOVERRIDE; 54 virtual void ForceUpper() wxOVERRIDE; 55 56 #ifdef __WXGTK3__ 57 virtual bool SetHint(const wxString& hint) wxOVERRIDE; 58 virtual wxString GetHint() const wxOVERRIDE; 59 #endif 60 61 // implementation only from now on 62 void SendMaxLenEvent(); 63 bool GTKEntryOnInsertText(const char* text); GTKIsUpperCase()64 bool GTKIsUpperCase() const { return m_isUpperCase; } 65 66 // Called from "changed" signal handler (or, possibly, slightly later, when 67 // coalescing several "changed" signals into a single event) for GtkEntry. 68 // 69 // By default just generates a wxEVT_TEXT, but overridden to do more things 70 // in wxTextCtrl. GTKOnTextChanged()71 virtual void GTKOnTextChanged() { SendTextUpdatedEvent(); } 72 73 // Helper functions only used internally. GTKGetCoalesceData()74 wxTextCoalesceData* GTKGetCoalesceData() const { return m_coalesceData; } 75 76 protected: 77 // This method must be called from the derived class Create() to connect 78 // the handlers for the clipboard (cut/copy/paste) events. 79 void GTKConnectClipboardSignals(GtkWidget* entry); 80 81 // And this one to connect "insert-text" signal. 82 void GTKConnectInsertTextSignal(GtkEntry* entry); 83 84 // Finally this one connects to the "changed" signal on the object returned 85 // by GetTextObject(). 86 void GTKConnectChangedSignal(); 87 88 89 virtual void DoSetValue(const wxString& value, int flags) wxOVERRIDE; 90 virtual wxString DoGetValue() const wxOVERRIDE; 91 92 // margins functions 93 virtual bool DoSetMargins(const wxPoint& pt) wxOVERRIDE; 94 virtual wxPoint DoGetMargins() const wxOVERRIDE; 95 96 virtual bool DoAutoCompleteStrings(const wxArrayString& choices) wxOVERRIDE; 97 virtual bool DoAutoCompleteCustom(wxTextCompleter *completer) wxOVERRIDE; 98 99 // Call this from the overridden wxWindow::GTKIMFilterKeypress() to use 100 // GtkEntry IM context. 101 int GTKEntryIMFilterKeypress(GdkEventKey* event) const; 102 103 // If GTKEntryIMFilterKeypress() is not called (as multiline wxTextCtrl 104 // uses its own IM), call this method instead to still notify wxTextEntry 105 // about the key press events in the given widget. 106 void GTKEntryOnKeypress(GtkWidget* widget) const; 107 108 109 static int GTKGetEntryTextLength(GtkEntry* entry); 110 111 // Block/unblock the corresponding GTK signal. 112 // 113 // Note that we make it protected in wxGTK as it is called from wxComboBox 114 // currently. 115 virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE; 116 117 // Helper for wxTE_PROCESS_ENTER handling: activates the default button in 118 // the dialog containing this control if any. 119 bool ClickDefaultButtonIfPossible(); 120 121 private: 122 // implement this to return the associated GtkEntry or another widget 123 // implementing GtkEditable 124 virtual GtkEditable *GetEditable() const = 0; 125 126 // implement this to return the associated GtkEntry 127 virtual GtkEntry *GetEntry() const = 0; 128 129 // This one exists in order to be overridden by wxTextCtrl which uses 130 // either GtkEditable or GtkTextBuffer depending on whether it is single- 131 // or multi-line. GetTextObject()132 virtual void *GetTextObject() const { return GetEntry(); } 133 134 135 // Various auto-completion-related stuff, only used if any of AutoComplete() 136 // methods are called. 137 wxTextAutoCompleteData *m_autoCompleteData; 138 139 // It needs to call our GetEntry() method. 140 friend class wxTextAutoCompleteData; 141 142 // Data used for coalescing "changed" events resulting from a single user 143 // action. 144 mutable wxTextCoalesceData* m_coalesceData; 145 146 bool m_isUpperCase; 147 }; 148 149 // We don't need the generic version. 150 #define wxHAS_NATIVE_TEXT_FORCEUPPER 151 152 #endif // _WX_GTK_TEXTENTRY_H_ 153 154