]>
Commit | Line | Data |
---|---|---|
ffecfa5a JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/palmos/textctrl.h | |
3 | // Purpose: wxTextCtrl class | |
e1d63b79 | 4 | // Author: William Osborne - minimal working wxPalmOS port |
6afc1b46 | 5 | // Modified by: Yunhui Fu |
ffecfa5a | 6 | // Created: 10/13/04 |
e1d63b79 | 7 | // RCS-ID: $Id$ |
ffecfa5a JS |
8 | // Copyright: (c) William Osborne |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_TEXTCTRL_H_ | |
13 | #define _WX_TEXTCTRL_H_ | |
14 | ||
53a2db12 | 15 | class WXDLLIMPEXP_CORE wxTextCtrl : public wxTextCtrlBase |
ffecfa5a JS |
16 | { |
17 | public: | |
18 | // creation | |
19 | // -------- | |
20 | ||
21 | wxTextCtrl() { Init(); } | |
22 | wxTextCtrl(wxWindow *parent, wxWindowID id, | |
23 | const wxString& value = wxEmptyString, | |
24 | const wxPoint& pos = wxDefaultPosition, | |
25 | const wxSize& size = wxDefaultSize, | |
26 | long style = 0, | |
27 | const wxValidator& validator = wxDefaultValidator, | |
28 | const wxString& name = wxTextCtrlNameStr) | |
29 | { | |
30 | Init(); | |
31 | ||
32 | Create(parent, id, value, pos, size, style, validator, name); | |
33 | } | |
d3c7fc99 | 34 | virtual ~wxTextCtrl(); |
ffecfa5a JS |
35 | |
36 | bool Create(wxWindow *parent, 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 | ||
6afc1b46 VZ |
44 | // overridden wxTextEntry methods |
45 | // ------------------------------ | |
ffecfa5a JS |
46 | |
47 | virtual wxString GetValue() const; | |
6afc1b46 VZ |
48 | virtual wxString GetRange(long from, long to) const; |
49 | ||
50 | virtual bool IsEmpty() const; | |
f6519b40 | 51 | |
ffecfa5a JS |
52 | virtual int GetLineLength(long lineNo) const; |
53 | virtual wxString GetLineText(long lineNo) const; | |
54 | virtual int GetNumberOfLines() const; | |
55 | ||
6afc1b46 | 56 | virtual void SetMaxLength(unsigned long len); |
ffecfa5a | 57 | |
6afc1b46 VZ |
58 | virtual void GetSelection(long *from, long *to) const; |
59 | // | |
60 | // Operations | |
ffecfa5a | 61 | // ---------- |
6afc1b46 VZ |
62 | // |
63 | virtual void Clear(void); | |
64 | virtual void Replace( long lFrom | |
65 | ,long lTo | |
66 | ,const wxString& rsValue | |
67 | ); | |
68 | virtual void Remove( long lFrom | |
69 | ,long lTo | |
70 | ); | |
ffecfa5a | 71 | |
6afc1b46 | 72 | //virtual bool DoLoadFile(const wxString& rsFile, int fileType); |
ffecfa5a | 73 | |
ffecfa5a | 74 | virtual void MarkDirty(); |
6afc1b46 | 75 | virtual void DiscardEdits(void); |
ffecfa5a | 76 | |
6afc1b46 VZ |
77 | virtual void WriteText(const wxString& rsText); |
78 | virtual void AppendText(const wxString& rsText); | |
79 | virtual bool EmulateKeyPress(const wxKeyEvent& rEvent); | |
80 | ||
81 | virtual void Copy(void); | |
82 | virtual void Cut(void); | |
83 | virtual void Paste(void); | |
ffecfa5a | 84 | |
6afc1b46 VZ |
85 | virtual bool CanCopy(void) const; |
86 | virtual bool CanCut(void) const; | |
87 | virtual bool CanPaste(void) const; | |
88 | ||
89 | virtual void Undo(void); | |
90 | virtual void Redo(); | |
91 | ||
92 | virtual bool CanUndo(void) const; | |
93 | virtual bool CanRedo(void) const; | |
94 | ||
95 | virtual void SetInsertionPoint(long lPos); | |
96 | virtual void SetInsertionPointEnd(void); | |
97 | virtual long GetInsertionPoint(void) const; | |
98 | virtual wxTextPos GetLastPosition(void) const; | |
99 | ||
100 | virtual void SetSelection( long lFrom | |
101 | ,long lTo | |
102 | ); | |
103 | virtual void SetEditable(bool bEditable); | |
104 | virtual void SetWindowStyleFlag(long lStyle); | |
105 | ||
106 | // implement base class pure virtuals | |
107 | // ---------------------------------- | |
108 | ||
109 | virtual bool IsModified() const; | |
110 | virtual bool IsEditable(void) const; | |
ffecfa5a | 111 | |
ffecfa5a JS |
112 | #if wxUSE_RICHEDIT |
113 | // apply text attribute to the range of text (only works with richedit | |
114 | // controls) | |
115 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); | |
116 | virtual bool SetDefaultStyle(const wxTextAttr& style); | |
117 | virtual bool GetStyle(long position, wxTextAttr& style); | |
118 | #endif // wxUSE_RICHEDIT | |
119 | ||
120 | // translate between the position (which is just an index in the text ctrl | |
121 | // considering all its contents as a single strings) and (x, y) coordinates | |
122 | // which represent column and line. | |
123 | virtual long XYToPosition(long x, long y) const; | |
124 | virtual bool PositionToXY(long pos, long *x, long *y) const; | |
125 | ||
126 | virtual void ShowPosition(long pos); | |
6afc1b46 | 127 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; |
ffecfa5a JS |
128 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, |
129 | wxTextCoord *col, | |
6afc1b46 VZ |
130 | wxTextCoord *row) const |
131 | { | |
132 | return wxTextCtrlBase::HitTest(pt, col, row); | |
133 | } | |
ffecfa5a JS |
134 | |
135 | // Caret handling (Windows only) | |
ffecfa5a JS |
136 | bool ShowNativeCaret(bool show = true); |
137 | bool HideNativeCaret() { return ShowNativeCaret(false); } | |
138 | ||
139 | // Implementation from now on | |
140 | // -------------------------- | |
6afc1b46 VZ |
141 | |
142 | #if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT | |
143 | virtual void SetDropTarget(wxDropTarget *dropTarget); | |
144 | #endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT | |
ffecfa5a | 145 | |
ffecfa5a | 146 | virtual void Command(wxCommandEvent& event); |
ffecfa5a JS |
147 | |
148 | #if wxUSE_RICHEDIT | |
ffecfa5a JS |
149 | |
150 | int GetRichVersion() const { return m_verRichEdit; } | |
151 | bool IsRich() const { return m_verRichEdit != 0; } | |
152 | ||
153 | // rich edit controls are not compatible with normal ones and wem ust set | |
154 | // the colours for them otherwise | |
155 | virtual bool SetBackgroundColour(const wxColour& colour); | |
156 | virtual bool SetForegroundColour(const wxColour& colour); | |
6afc1b46 VZ |
157 | #else |
158 | bool IsRich() const { return false; } | |
ffecfa5a JS |
159 | #endif // wxUSE_RICHEDIT |
160 | ||
6afc1b46 VZ |
161 | #if wxUSE_INKEDIT && wxUSE_RICHEDIT |
162 | bool IsInkEdit() const { return m_isInkEdit != 0; } | |
163 | #else | |
164 | bool IsInkEdit() const { return false; } | |
165 | #endif | |
166 | ||
167 | virtual void AdoptAttributesFromHWND(); | |
168 | ||
169 | virtual bool AcceptsFocusFromKeyboard() const; | |
170 | ||
171 | // returns true if the platform should explicitly apply a theme border | |
172 | virtual bool CanApplyThemeBorder() const; | |
ffecfa5a JS |
173 | |
174 | // callbacks | |
175 | void OnDropFiles(wxDropFilesEvent& event); | |
176 | void OnChar(wxKeyEvent& event); // Process 'enter' if required | |
177 | ||
178 | void OnCut(wxCommandEvent& event); | |
179 | void OnCopy(wxCommandEvent& event); | |
180 | void OnPaste(wxCommandEvent& event); | |
181 | void OnUndo(wxCommandEvent& event); | |
182 | void OnRedo(wxCommandEvent& event); | |
183 | void OnDelete(wxCommandEvent& event); | |
184 | void OnSelectAll(wxCommandEvent& event); | |
185 | ||
186 | void OnUpdateCut(wxUpdateUIEvent& event); | |
187 | void OnUpdateCopy(wxUpdateUIEvent& event); | |
188 | void OnUpdatePaste(wxUpdateUIEvent& event); | |
189 | void OnUpdateUndo(wxUpdateUIEvent& event); | |
190 | void OnUpdateRedo(wxUpdateUIEvent& event); | |
191 | void OnUpdateDelete(wxUpdateUIEvent& event); | |
192 | void OnUpdateSelectAll(wxUpdateUIEvent& event); | |
193 | ||
194 | // Show a context menu for Rich Edit controls (the standard | |
195 | // EDIT control has one already) | |
6afc1b46 | 196 | void OnContextMenu(wxContextMenuEvent& event); |
ffecfa5a JS |
197 | |
198 | // be sure the caret remains invisible if the user | |
199 | // called HideNativeCaret() before | |
200 | void OnSetFocus(wxFocusEvent& event); | |
201 | ||
6afc1b46 VZ |
202 | virtual wxVisualAttributes GetDefaultAttributes() const; |
203 | ||
ffecfa5a JS |
204 | protected: |
205 | // common part of all ctors | |
206 | void Init(); | |
207 | ||
6afc1b46 VZ |
208 | virtual bool DoLoadFile(const wxString& file, int fileType); |
209 | ||
210 | // creates the control of appropriate class (plain or rich edit) with the | |
211 | // styles corresponding to m_windowStyle | |
212 | // | |
213 | // this is used by ctor/Create() and when we need to recreate the control | |
214 | // later | |
215 | bool MSWCreateText(const wxString& value, | |
216 | const wxPoint& pos, | |
217 | const wxSize& size); | |
ee2ec18e | 218 | |
6afc1b46 | 219 | virtual void DoSetValue(const wxString &value, int flags = 0); |
ee2ec18e | 220 | |
6afc1b46 VZ |
221 | // return true if this control has a user-set limit on amount of text (i.e. |
222 | // the limit is due to a previous call to SetMaxLength() and not built in) | |
223 | bool HasSpaceLimit(unsigned int *len) const; | |
ffecfa5a JS |
224 | |
225 | // call this to increase the size limit (will do nothing if the current | |
226 | // limit is big enough) | |
227 | // | |
228 | // returns true if we increased the limit to allow entering more text, | |
229 | // false if we hit the limit set by SetMaxLength() and so didn't change it | |
230 | bool AdjustSpaceLimit(); | |
231 | ||
232 | #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU) | |
233 | // replace the selection or the entire control contents with the given text | |
234 | // in the specified encoding | |
235 | bool StreamIn(const wxString& value, wxFontEncoding encoding, bool selOnly); | |
236 | ||
237 | // get the contents of the control out as text in the given encoding | |
238 | wxString StreamOut(wxFontEncoding encoding, bool selOnly = false) const; | |
239 | #endif // wxUSE_RICHEDIT | |
240 | ||
241 | // replace the contents of the selection or of the entire control with the | |
242 | // given text | |
6afc1b46 VZ |
243 | void DoWriteText(const wxString& text, |
244 | int flags = SetValue_SendEvent | SetValue_SelectionOnly); | |
ffecfa5a | 245 | |
6afc1b46 VZ |
246 | // set the selection (possibly without scrolling the caret into view) |
247 | void DoSetSelection(long from, long to, int flags); | |
ffecfa5a JS |
248 | |
249 | // get the length of the line containing the character at the given | |
250 | // position | |
251 | long GetLengthOfLineContainingPos(long pos) const; | |
252 | ||
4055ed82 | 253 | // send TEXT_UPDATED event, return true if it was handled, false otherwise |
ffecfa5a JS |
254 | bool SendUpdateEvent(); |
255 | ||
ffecfa5a JS |
256 | virtual wxSize DoGetBestSize() const; |
257 | ||
ffecfa5a JS |
258 | #if wxUSE_RICHEDIT |
259 | // we're using RICHEDIT (and not simple EDIT) control if this field is not | |
260 | // 0, it also gives the version of the RICHEDIT control being used (1, 2 or | |
261 | // 3 so far) | |
262 | int m_verRichEdit; | |
263 | #endif // wxUSE_RICHEDIT | |
264 | ||
6afc1b46 VZ |
265 | // number of EN_UPDATE events sent by Windows when we change the controls |
266 | // text ourselves: we want this to be exactly 1 | |
267 | int m_updatesCount; | |
ffecfa5a JS |
268 | |
269 | private: | |
6afc1b46 VZ |
270 | virtual void EnableTextChangedEvents(bool enable) |
271 | { | |
272 | m_updatesCount = enable ? -1 : -2; | |
273 | } | |
274 | ||
275 | // implement wxTextEntry pure virtual: it implements all the operations for | |
276 | // the simple EDIT controls | |
277 | virtual WXHWND GetEditHWND() const { return m_hWnd; } | |
278 | ||
ffecfa5a JS |
279 | DECLARE_EVENT_TABLE() |
280 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl) | |
281 | ||
282 | wxMenu* m_privateContextMenu; | |
283 | ||
284 | bool m_isNativeCaretShown; | |
6afc1b46 VZ |
285 | |
286 | #if wxUSE_INKEDIT && wxUSE_RICHEDIT | |
287 | int m_isInkEdit; | |
288 | #endif | |
289 | ||
ffecfa5a JS |
290 | }; |
291 | ||
292 | #endif | |
293 | // _WX_TEXTCTRL_H_ |