]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/textctrl.h
Compilo.
[wxWidgets.git] / include / wx / gtk1 / 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 __GTKTEXTCTRLH__
12 #define __GTKTEXTCTRLH__
13
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "textctrl.h"
16 #endif
17
18 //-----------------------------------------------------------------------------
19 // wxTextCtrl
20 //-----------------------------------------------------------------------------
21
22 class wxTextCtrl: public wxTextCtrlBase
23 {
24 public:
25 wxTextCtrl() { Init(); }
26 wxTextCtrl(wxWindow *parent,
27 wxWindowID id,
28 const wxString &value = wxEmptyString,
29 const wxPoint &pos = wxDefaultPosition,
30 const wxSize &size = wxDefaultSize,
31 long style = 0,
32 const wxValidator& validator = wxDefaultValidator,
33 const wxString &name = wxTextCtrlNameStr);
34
35 ~wxTextCtrl();
36
37 bool Create(wxWindow *parent,
38 wxWindowID id,
39 const wxString &value = wxEmptyString,
40 const wxPoint &pos = wxDefaultPosition,
41 const wxSize &size = wxDefaultSize,
42 long style = 0,
43 const wxValidator& validator = wxDefaultValidator,
44 const wxString &name = wxTextCtrlNameStr);
45
46 // implement base class pure virtuals
47 // ----------------------------------
48
49 virtual wxString GetValue() const;
50 virtual void SetValue(const wxString& value);
51
52 virtual int GetLineLength(long lineNo) const;
53 virtual wxString GetLineText(long lineNo) const;
54 virtual int GetNumberOfLines() const;
55
56 virtual bool IsModified() const;
57 virtual bool IsEditable() const;
58
59 // If the return values from and to are the same, there is no selection.
60 virtual void GetSelection(long* from, long* to) const;
61
62 // operations
63 // ----------
64
65 // editing
66 virtual void Clear();
67 virtual void Replace(long from, long to, const wxString& value);
68 virtual void Remove(long from, long to);
69
70 // sets/clears the dirty flag
71 virtual void MarkDirty();
72 virtual void DiscardEdits();
73
74 virtual void SetMaxLength(unsigned long len);
75
76 // writing text inserts it at the current position, appending always
77 // inserts it at the end
78 virtual void WriteText(const wxString& text);
79 virtual void AppendText(const wxString& text);
80
81 // apply text attribute to the range of text (only works with richedit
82 // controls)
83 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
84
85 // translate between the position (which is just an index in the text ctrl
86 // considering all its contents as a single strings) and (x, y) coordinates
87 // which represent column and line.
88 virtual long XYToPosition(long x, long y) const;
89 virtual bool PositionToXY(long pos, long *x, long *y) const;
90
91 virtual void ShowPosition(long pos);
92
93 #ifdef __WXGTK20__
94 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
95 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
96 wxTextCoord *col,
97 wxTextCoord *row) const
98 {
99 return wxTextCtrlBase::HitTest(pt, col, row);
100 }
101 #endif // __WXGTK20__
102
103 // Clipboard operations
104 virtual void Copy();
105 virtual void Cut();
106 virtual void Paste();
107
108 // Undo/redo
109 virtual void Undo();
110 virtual void Redo();
111
112 virtual bool CanUndo() const;
113 virtual bool CanRedo() const;
114
115 // Insertion point
116 virtual void SetInsertionPoint(long pos);
117 virtual void SetInsertionPointEnd();
118 virtual long GetInsertionPoint() const;
119 virtual wxTextPos GetLastPosition() const;
120
121 virtual void SetSelection(long from, long to);
122 virtual void SetEditable(bool editable);
123
124 virtual bool Enable( bool enable = true );
125
126 // Implementation from now on
127 void OnDropFiles( wxDropFilesEvent &event );
128 void OnChar( wxKeyEvent &event );
129
130 void OnCut(wxCommandEvent& event);
131 void OnCopy(wxCommandEvent& event);
132 void OnPaste(wxCommandEvent& event);
133 void OnUndo(wxCommandEvent& event);
134 void OnRedo(wxCommandEvent& event);
135
136 void OnUpdateCut(wxUpdateUIEvent& event);
137 void OnUpdateCopy(wxUpdateUIEvent& event);
138 void OnUpdatePaste(wxUpdateUIEvent& event);
139 void OnUpdateUndo(wxUpdateUIEvent& event);
140 void OnUpdateRedo(wxUpdateUIEvent& event);
141
142 bool SetFont(const wxFont& font);
143 bool SetForegroundColour(const wxColour& colour);
144 bool SetBackgroundColour(const wxColour& colour);
145
146 GtkWidget* GetConnectWidget();
147 bool IsOwnGtkWindow( GdkWindow *window );
148 void DoApplyWidgetStyle(GtkRcStyle *style);
149 void CalculateScrollbar();
150 void OnInternalIdle();
151
152 #ifdef __WXGTK20__
153 void SetUpdateFont(bool WXUNUSED(update)) { }
154 #else // !__WXGTK20__
155 void SetUpdateFont(bool update) { m_updateFont = update; }
156 void UpdateFontIfNeeded();
157 #endif // __WXGTK20__/!__WXGTK20__
158
159 void SetModified() { m_modified = true; }
160
161 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
162 // avoid horrible flicker/scrolling back and forth
163 virtual void Freeze();
164 virtual void Thaw();
165
166 // textctrl specific scrolling
167 virtual bool ScrollLines(int lines);
168 virtual bool ScrollPages(int pages);
169
170 // implementation only from now on
171
172 // wxGTK-specific: called recursively by Enable,
173 // to give widgets an oppprtunity to correct their colours after they
174 // have been changed by Enable
175 virtual void OnParentEnable( bool enable ) ;
176
177 // tell the control to ignore next text changed signal
178 void IgnoreNextTextUpdate();
179
180 // should we ignore the changed signal? always resets the flag
181 bool IgnoreTextUpdate();
182
183 static wxVisualAttributes
184 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
185
186 protected:
187 virtual wxSize DoGetBestSize() const;
188
189 // common part of all ctors
190 void Init();
191
192 // get the vertical adjustment, if any, NULL otherwise
193 GtkAdjustment *GetVAdj() const;
194
195 // scroll the control by the given number of pixels, return true if the
196 // scroll position changed
197 bool DoScroll(GtkAdjustment *adj, int diff);
198
199 // Widgets that use the style->base colour for the BG colour should
200 // override this and return true.
201 virtual bool UseGTKStyleBase() const { return true; }
202
203 #ifdef __WXGTK20__
204 // has the control been frozen by Freeze()?
205 bool IsFrozen() const { return m_frozenness > 0; }
206 #endif
207
208 private:
209 // change the font for everything in this control
210 void ChangeFontGlobally();
211
212 GtkWidget *m_text;
213 GtkWidget *m_vScrollbar;
214
215 bool m_modified:1;
216 bool m_vScrollbarVisible:1;
217 #ifndef __WXGTK20__
218 bool m_updateFont:1;
219 #endif // !__WXGTK20__
220 bool m_ignoreNextUpdate:1;
221
222 #ifdef __WXGTK20__
223 // Our text buffer. Convenient, and holds the buffer while using
224 // a dummy one when m_frozenness > 0
225 GtkTextBuffer *m_buffer;
226
227 // number of calls to Freeze() minus number of calls to Thaw()
228 unsigned int m_frozenness;
229
230 // For wxTE_AUTO_URL
231 void OnUrlMouseEvent(wxMouseEvent&);
232 GdkCursor *m_gdkHandCursor;
233 GdkCursor *m_gdkXTermCursor;
234 #endif
235
236 DECLARE_EVENT_TABLE()
237 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
238 };
239
240 #endif // __GTKTEXTCTRLH__
241