]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/textctrl.h
maintaint the mouse capture stack in all ports, not just wxUniv
[wxWidgets.git] / include / wx / gtk / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: textctrl.h
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __GTKTEXTCTRLH__
12 #define __GTKTEXTCTRLH__
13
14 #ifdef __GNUG__
15 #pragma interface "textctrl.h"
16 #endif
17
18 //-----------------------------------------------------------------------------
19 // classes
20 //-----------------------------------------------------------------------------
21
22 class wxTextCtrl;
23
24 //-----------------------------------------------------------------------------
25 // wxTextCtrl
26 //-----------------------------------------------------------------------------
27
28 class wxTextCtrl: public wxTextCtrlBase
29 {
30 public:
31 wxTextCtrl() { Init(); }
32 wxTextCtrl(wxWindow *parent,
33 wxWindowID id,
34 const wxString &value = wxEmptyString,
35 const wxPoint &pos = wxDefaultPosition,
36 const wxSize &size = wxDefaultSize,
37 long style = 0,
38 const wxValidator& validator = wxDefaultValidator,
39 const wxString &name = wxTextCtrlNameStr);
40
41 bool Create(wxWindow *parent,
42 wxWindowID id,
43 const wxString &value = wxEmptyString,
44 const wxPoint &pos = wxDefaultPosition,
45 const wxSize &size = wxDefaultSize,
46 long style = 0,
47 const wxValidator& validator = wxDefaultValidator,
48 const wxString &name = wxTextCtrlNameStr);
49
50 // implement base class pure virtuals
51 // ----------------------------------
52
53 virtual wxString GetValue() const;
54 virtual void SetValue(const wxString& value);
55
56 virtual int GetLineLength(long lineNo) const;
57 virtual wxString GetLineText(long lineNo) const;
58 virtual int GetNumberOfLines() const;
59
60 virtual bool IsModified() const;
61 virtual bool IsEditable() const;
62
63 // If the return values from and to are the same, there is no selection.
64 virtual void GetSelection(long* from, long* to) const;
65
66 // operations
67 // ----------
68
69 // editing
70 virtual void Clear();
71 virtual void Replace(long from, long to, const wxString& value);
72 virtual void Remove(long from, long to);
73
74 // clears the dirty flag
75 virtual void DiscardEdits();
76
77 virtual void SetMaxLength(unsigned long len);
78
79 // writing text inserts it at the current position, appending always
80 // inserts it at the end
81 virtual void WriteText(const wxString& text);
82 virtual void AppendText(const wxString& text);
83
84 // apply text attribute to the range of text (only works with richedit
85 // controls)
86 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
87
88 // translate between the position (which is just an index in the text ctrl
89 // considering all its contents as a single strings) and (x, y) coordinates
90 // which represent column and line.
91 virtual long XYToPosition(long x, long y) const;
92 virtual bool PositionToXY(long pos, long *x, long *y) const;
93
94 virtual void ShowPosition(long pos);
95
96 // Clipboard operations
97 virtual void Copy();
98 virtual void Cut();
99 virtual void Paste();
100
101 // Undo/redo
102 virtual void Undo();
103 virtual void Redo();
104
105 virtual bool CanUndo() const;
106 virtual bool CanRedo() const;
107
108 // Insertion point
109 virtual void SetInsertionPoint(long pos);
110 virtual void SetInsertionPointEnd();
111 virtual long GetInsertionPoint() const;
112 virtual long GetLastPosition() const;
113
114 virtual void SetSelection(long from, long to);
115 virtual void SetEditable(bool editable);
116
117 virtual bool Enable( bool enable );
118
119 // Implementation from now on
120 void OnDropFiles( wxDropFilesEvent &event );
121 void OnChar( wxKeyEvent &event );
122
123 void OnCut(wxCommandEvent& event);
124 void OnCopy(wxCommandEvent& event);
125 void OnPaste(wxCommandEvent& event);
126 void OnUndo(wxCommandEvent& event);
127 void OnRedo(wxCommandEvent& event);
128
129 void OnUpdateCut(wxUpdateUIEvent& event);
130 void OnUpdateCopy(wxUpdateUIEvent& event);
131 void OnUpdatePaste(wxUpdateUIEvent& event);
132 void OnUpdateUndo(wxUpdateUIEvent& event);
133 void OnUpdateRedo(wxUpdateUIEvent& event);
134
135 bool SetFont(const wxFont& font);
136 bool SetForegroundColour(const wxColour& colour);
137 bool SetBackgroundColour(const wxColour& colour);
138
139 GtkWidget* GetConnectWidget();
140 bool IsOwnGtkWindow( GdkWindow *window );
141 void ApplyWidgetStyle();
142 void CalculateScrollbar();
143 void OnInternalIdle();
144 void UpdateFontIfNeeded();
145
146 void SetModified() { m_modified = TRUE; }
147
148 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
149 // avoid horrible flicker/scrolling back and forth
150 virtual void Freeze();
151 virtual void Thaw();
152
153 // textctrl specific scrolling
154 virtual bool ScrollLines(int lines);
155 virtual bool ScrollPages(int pages);
156
157 // implementation only from now on
158
159 // wxGTK-specific: called recursively by Enable,
160 // to give widgets an oppprtunity to correct their colours after they
161 // have been changed by Enable
162 virtual void OnParentEnable( bool enable ) ;
163
164 // tell the control to ignore next text changed signal
165 void IgnoreNextTextUpdate();
166
167 // should we ignore the changed signal? always resets the flag
168 bool IgnoreTextUpdate();
169
170 protected:
171 virtual wxSize DoGetBestSize() const;
172
173 // common part of all ctors
174 void Init();
175
176 // get the vertical adjustment, if any, NULL otherwise
177 GtkAdjustment *GetVAdj() const;
178
179 // scroll the control by the given number of pixels, return true if the
180 // scroll position changed
181 bool DoScroll(GtkAdjustment *adj, int diff);
182
183 private:
184 // change the font for everything in this control
185 void ChangeFontGlobally();
186
187 GtkWidget *m_text;
188 GtkWidget *m_vScrollbar;
189
190 bool m_modified:1;
191 bool m_vScrollbarVisible:1;
192 bool m_updateFont:1;
193 bool m_ignoreNextUpdate:1;
194
195 DECLARE_EVENT_TABLE()
196 DECLARE_DYNAMIC_CLASS(wxTextCtrl);
197 };
198
199 #endif // __GTKTEXTCTRLH__
200