]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/textctrl.h
e27cb9f9a4fa71f24b77b3f5a8bb04c8ee2ef678
[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 __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 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 wxString GetValue() const;
48 virtual void SetValue(const wxString& value);
49
50 virtual int GetLineLength(long lineNo) const;
51 virtual wxString GetLineText(long lineNo) const;
52 virtual int GetNumberOfLines() const;
53
54 virtual bool IsModified() const;
55 virtual bool IsEditable() const;
56
57 // If the return values from and to are the same, there is no selection.
58 virtual void GetSelection(long* from, long* to) const;
59
60 // operations
61 // ----------
62
63 // editing
64 virtual void Clear();
65 virtual void Replace(long from, long to, const wxString& value);
66 virtual void Remove(long from, long to);
67
68 // sets/clears the dirty flag
69 virtual void MarkDirty();
70 virtual void DiscardEdits();
71
72 virtual void SetMaxLength(unsigned long len);
73
74 // writing text inserts it at the current position, appending always
75 // inserts it at the end
76 virtual void WriteText(const wxString& text);
77 virtual void AppendText(const wxString& text);
78
79 // apply text attribute to the range of text (only works with richedit
80 // controls)
81 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
82
83 // translate between the position (which is just an index in the text ctrl
84 // considering all its contents as a single strings) and (x, y) coordinates
85 // which represent column and line.
86 virtual long XYToPosition(long x, long y) const;
87 virtual bool PositionToXY(long pos, long *x, long *y) const;
88
89 virtual void ShowPosition(long pos);
90
91 #ifdef __WXGTK20__
92 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
93 #endif // __WXGTK20__
94
95 // Clipboard operations
96 virtual void Copy();
97 virtual void Cut();
98 virtual void Paste();
99
100 // Undo/redo
101 virtual void Undo();
102 virtual void Redo();
103
104 virtual bool CanUndo() const;
105 virtual bool CanRedo() const;
106
107 // Insertion point
108 virtual void SetInsertionPoint(long pos);
109 virtual void SetInsertionPointEnd();
110 virtual long GetInsertionPoint() const;
111 virtual long GetLastPosition() const;
112
113 virtual void SetSelection(long from, long to);
114 virtual void SetEditable(bool editable);
115
116 virtual bool Enable( bool enable = TRUE );
117
118 // Implementation from now on
119 void OnDropFiles( wxDropFilesEvent &event );
120 void OnChar( wxKeyEvent &event );
121
122 void OnCut(wxCommandEvent& event);
123 void OnCopy(wxCommandEvent& event);
124 void OnPaste(wxCommandEvent& event);
125 void OnUndo(wxCommandEvent& event);
126 void OnRedo(wxCommandEvent& event);
127
128 void OnUpdateCut(wxUpdateUIEvent& event);
129 void OnUpdateCopy(wxUpdateUIEvent& event);
130 void OnUpdatePaste(wxUpdateUIEvent& event);
131 void OnUpdateUndo(wxUpdateUIEvent& event);
132 void OnUpdateRedo(wxUpdateUIEvent& event);
133
134 bool SetFont(const wxFont& font);
135 bool SetForegroundColour(const wxColour& colour);
136 bool SetBackgroundColour(const wxColour& colour);
137
138 GtkWidget* GetConnectWidget();
139 bool IsOwnGtkWindow( GdkWindow *window );
140 void DoApplyWidgetStyle(GtkRcStyle *style);
141 void CalculateScrollbar();
142 void OnInternalIdle();
143
144 #ifdef __WXGTK20__
145 void SetUpdateFont(bool WXUNUSED(update)) { }
146 #else // !__WXGTK20__
147 void SetUpdateFont(bool update) { m_updateFont = update; }
148 void UpdateFontIfNeeded();
149 #endif // __WXGTK20__/!__WXGTK20__
150
151 void SetModified() { m_modified = TRUE; }
152
153 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
154 // avoid horrible flicker/scrolling back and forth
155 virtual void Freeze();
156 virtual void Thaw();
157
158 // textctrl specific scrolling
159 virtual bool ScrollLines(int lines);
160 virtual bool ScrollPages(int pages);
161
162 // implementation only from now on
163
164 // wxGTK-specific: called recursively by Enable,
165 // to give widgets an oppprtunity to correct their colours after they
166 // have been changed by Enable
167 virtual void OnParentEnable( bool enable ) ;
168
169 // tell the control to ignore next text changed signal
170 void IgnoreNextTextUpdate();
171
172 // should we ignore the changed signal? always resets the flag
173 bool IgnoreTextUpdate();
174
175 static wxVisualAttributes
176 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
177
178 protected:
179 virtual wxSize DoGetBestSize() const;
180
181 // common part of all ctors
182 void Init();
183
184 // get the vertical adjustment, if any, NULL otherwise
185 GtkAdjustment *GetVAdj() const;
186
187 // scroll the control by the given number of pixels, return true if the
188 // scroll position changed
189 bool DoScroll(GtkAdjustment *adj, int diff);
190
191 // Widgets that use the style->base colour for the BG colour should
192 // override this and return true.
193 virtual bool UseGTKStyleBase() const { return true; }
194
195 private:
196 // change the font for everything in this control
197 void ChangeFontGlobally();
198
199 GtkWidget *m_text;
200 GtkWidget *m_vScrollbar;
201
202 bool m_modified:1;
203 bool m_vScrollbarVisible:1;
204 #ifndef __WXGTK20__
205 bool m_updateFont:1;
206 #endif // !__WXGTK20__
207 bool m_ignoreNextUpdate:1;
208
209 DECLARE_EVENT_TABLE()
210 DECLARE_DYNAMIC_CLASS(wxTextCtrl);
211 };
212
213 #endif // __GTKTEXTCTRLH__
214