replace wx_{const,static,reinterpret}_cast with their standard C++ equivalents
[wxWidgets.git] / include / wx / gtk / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/textctrl.h
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GTK_TEXTCTRL_H_
12 #define _WX_GTK_TEXTCTRL_H_
13
14 typedef struct _GtkTextMark GtkTextMark;
15
16 //-----------------------------------------------------------------------------
17 // wxTextCtrl
18 //-----------------------------------------------------------------------------
19
20 class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
21 {
22 public:
23 wxTextCtrl() { Init(); }
24 wxTextCtrl(wxWindow *parent,
25 wxWindowID id,
26 const wxString &value = wxEmptyString,
27 const wxPoint &pos = wxDefaultPosition,
28 const wxSize &size = wxDefaultSize,
29 long style = 0,
30 const wxValidator& validator = wxDefaultValidator,
31 const wxString &name = wxTextCtrlNameStr);
32
33 virtual ~wxTextCtrl();
34
35 bool Create(wxWindow *parent,
36 wxWindowID id,
37 const wxString &value = wxEmptyString,
38 const wxPoint &pos = wxDefaultPosition,
39 const wxSize &size = wxDefaultSize,
40 long style = 0,
41 const wxValidator& validator = wxDefaultValidator,
42 const wxString &name = wxTextCtrlNameStr);
43
44 // implement base class pure virtuals
45 // ----------------------------------
46
47 virtual void WriteText(const wxString& text);
48 virtual wxString GetValue() const;
49 virtual bool IsEmpty() const;
50
51 virtual int GetLineLength(long lineNo) const;
52 virtual wxString GetLineText(long lineNo) const;
53 virtual int GetNumberOfLines() const;
54
55 virtual bool IsModified() const;
56 virtual bool IsEditable() const;
57
58 virtual void GetSelection(long* from, long* to) const;
59
60 virtual void Remove(long from, long to);
61
62 virtual void MarkDirty();
63 virtual void DiscardEdits();
64
65 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
66
67 // translate between the position (which is just an index in the text ctrl
68 // considering all its contents as a single strings) and (x, y) coordinates
69 // which represent column and line.
70 virtual long XYToPosition(long x, long y) const;
71 virtual bool PositionToXY(long pos, long *x, long *y) const;
72
73 virtual void ShowPosition(long pos);
74
75 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
76 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
77 wxTextCoord *col,
78 wxTextCoord *row) const
79 {
80 return wxTextCtrlBase::HitTest(pt, col, row);
81 }
82
83 // Clipboard operations
84 virtual void Copy();
85 virtual void Cut();
86 virtual void Paste();
87
88 // Insertion point
89 virtual void SetInsertionPoint(long pos);
90 virtual long GetInsertionPoint() const;
91 virtual wxTextPos GetLastPosition() const;
92
93 virtual void SetSelection(long from, long to);
94 virtual void SetEditable(bool editable);
95
96 // Overridden wxWindow methods
97 virtual void SetWindowStyleFlag( long style );
98 virtual bool Enable( bool enable = true );
99
100 // Implementation from now on
101 void OnDropFiles( wxDropFilesEvent &event );
102 void OnChar( wxKeyEvent &event );
103
104 void OnCut(wxCommandEvent& event);
105 void OnCopy(wxCommandEvent& event);
106 void OnPaste(wxCommandEvent& event);
107 void OnUndo(wxCommandEvent& event);
108 void OnRedo(wxCommandEvent& event);
109
110 void OnUpdateCut(wxUpdateUIEvent& event);
111 void OnUpdateCopy(wxUpdateUIEvent& event);
112 void OnUpdatePaste(wxUpdateUIEvent& event);
113 void OnUpdateUndo(wxUpdateUIEvent& event);
114 void OnUpdateRedo(wxUpdateUIEvent& event);
115
116 bool SetFont(const wxFont& font);
117 bool SetForegroundColour(const wxColour& colour);
118 bool SetBackgroundColour(const wxColour& colour);
119
120 GtkWidget* GetConnectWidget();
121
122 void SetUpdateFont(bool WXUNUSED(update)) { }
123
124 // implementation only from now on
125
126 // tell the control to ignore next text changed signal
127 void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
128
129 // should we ignore the changed signal? always resets the flag
130 bool IgnoreTextUpdate();
131
132 // call this to indicate that the control is about to be changed
133 // programmatically and so m_modified flag shouldn't be set
134 void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; }
135
136 // should we mark the control as dirty? always resets the flag
137 bool MarkDirtyOnChange();
138
139 // always let GTK have mouse release events for multiline controls
140 virtual bool GTKProcessEvent(wxEvent& event) const;
141
142
143 static wxVisualAttributes
144 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
145
146 protected:
147 // wxGTK-specific: called recursively by Enable,
148 // to give widgets an oppprtunity to correct their colours after they
149 // have been changed by Enable
150 virtual void OnEnabled(bool enable);
151
152 // overridden wxWindow virtual methods
153 virtual wxSize DoGetBestSize() const;
154 virtual void DoApplyWidgetStyle(GtkRcStyle *style);
155 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
156
157 virtual void DoFreeze();
158 virtual void DoThaw();
159
160 // common part of all ctors
161 void Init();
162
163 // Widgets that use the style->base colour for the BG colour should
164 // override this and return true.
165 virtual bool UseGTKStyleBase() const { return true; }
166
167 virtual void DoSetValue(const wxString &value, int flags = 0);
168
169 // wrappers hiding the differences between functions doing the same thing
170 // for GtkTextView and GtkEntry (all of them use current window style to
171 // set the given characteristic)
172 void GTKSetEditable();
173 void GTKSetVisibility();
174 void GTKSetActivatesDefault();
175 void GTKSetWrapMode();
176 void GTKSetJustification();
177
178 private:
179 // overridden wxTextEntry virtual methods
180 virtual const wxWindow *GetEditableWindow() const { return this; }
181 virtual GtkEditable *GetEditable() const;
182 virtual void EnableTextChangedEvents(bool enable);
183
184 // change the font for everything in this control
185 void ChangeFontGlobally();
186
187 // get the encoding which is used in this control: this looks at our font
188 // and default style but not the current style (i.e. the style for the
189 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
190 // encoding
191 wxFontEncoding GetTextEncoding() const;
192
193 // returns either m_text or m_buffer depending on whether the control is
194 // single- or multi-line; convenient for the GTK+ functions which work with
195 // both
196 void *GetTextObject() const
197 {
198 return IsMultiLine() ? static_cast<void *>(m_buffer)
199 : static_cast<void *>(m_text);
200 }
201
202
203 // the widget used for single line controls
204 GtkWidget *m_text;
205
206 bool m_modified:1;
207 bool m_dontMarkDirty:1;
208
209 int m_countUpdatesToIgnore;
210
211 // Our text buffer. Convenient, and holds the buffer while using
212 // a dummy one when frozen
213 GtkTextBuffer *m_buffer;
214
215 GtkTextMark* m_showPositionOnThaw;
216
217 // For wxTE_AUTO_URL
218 void OnUrlMouseEvent(wxMouseEvent&);
219 GdkCursor *m_gdkHandCursor;
220 GdkCursor *m_gdkXTermCursor;
221
222 DECLARE_EVENT_TABLE()
223 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
224 };
225
226 #endif // _WX_GTK_TEXTCTRL_H_