]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/textctrl.h
moved wxUSE_MS_HTML_HELP back into setup_inc.h (undoing change of rev 1.41) as it...
[wxWidgets.git] / include / wx / msw / textctrl.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
d7eee191 2// Name: wx/msw/textctrl.h
2bda0e17
KB
3// Purpose: wxTextCtrl class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
bbcdf8bc 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_TEXTCTRL_H_
13#define _WX_TEXTCTRL_H_
2bda0e17 14
a1b82138 15class WXDLLEXPORT wxTextCtrl : public wxTextCtrlBase
2bda0e17 16{
ae29de83 17public:
bfc6fde4
VZ
18 // creation
19 // --------
a1b82138 20
aac7e7fe 21 wxTextCtrl() { Init(); }
bfc6fde4 22 wxTextCtrl(wxWindow *parent, wxWindowID id,
a1b82138
VZ
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 {
aac7e7fe
VZ
30 Init();
31
a1b82138
VZ
32 Create(parent, id, value, pos, size, style, validator, name);
33 }
d3c7fc99 34 virtual ~wxTextCtrl();
bfc6fde4
VZ
35
36 bool Create(wxWindow *parent, wxWindowID id,
a1b82138
VZ
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);
bfc6fde4 43
a1b82138
VZ
44 // implement base class pure virtuals
45 // ----------------------------------
4438caf4
VZ
46
47 virtual wxString GetValue() const;
28fdd8db 48 virtual bool IsEmpty() const;
f6519b40 49 virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
28fdd8db 50 virtual void ChangeValue(const wxString& value) { DoSetValue(value); }
bfc6fde4 51
a5aa8086
VZ
52 virtual wxString GetRange(long from, long to) const;
53
bfc6fde4
VZ
54 virtual int GetLineLength(long lineNo) const;
55 virtual wxString GetLineText(long lineNo) const;
56 virtual int GetNumberOfLines() const;
57
a1b82138
VZ
58 virtual bool IsModified() const;
59 virtual bool IsEditable() const;
60
a1b82138
VZ
61 virtual void GetSelection(long* from, long* to) const;
62
bfc6fde4
VZ
63 // operations
64 // ----------
65
a1b82138
VZ
66 // editing
67 virtual void Clear();
68 virtual void Replace(long from, long to, const wxString& value);
69 virtual void Remove(long from, long to);
70
3306aec1
JS
71 // load the control's contents from the file
72 virtual bool DoLoadFile(const wxString& file, int fileType);
a1b82138
VZ
73
74 // clears the dirty flag
3a9fa0d6 75 virtual void MarkDirty();
a1b82138
VZ
76 virtual void DiscardEdits();
77
d7eee191
VZ
78 virtual void SetMaxLength(unsigned long len);
79
a1b82138
VZ
80 // writing text inserts it at the current position, appending always
81 // inserts it at the end
82 virtual void WriteText(const wxString& text);
83 virtual void AppendText(const wxString& text);
84
94af7d45
VZ
85#ifdef __WIN32__
86 virtual bool EmulateKeyPress(const wxKeyEvent& event);
87#endif // __WIN32__
88
4bc1afd5
VZ
89#if wxUSE_RICHEDIT
90 // apply text attribute to the range of text (only works with richedit
91 // controls)
92 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
5bf75ae7 93 virtual bool SetDefaultStyle(const wxTextAttr& style);
e00a5d3c 94 virtual bool GetStyle(long position, wxTextAttr& style);
4bc1afd5
VZ
95#endif // wxUSE_RICHEDIT
96
a1b82138
VZ
97 // translate between the position (which is just an index in the text ctrl
98 // considering all its contents as a single strings) and (x, y) coordinates
99 // which represent column and line.
100 virtual long XYToPosition(long x, long y) const;
0efe5ba7 101 virtual bool PositionToXY(long pos, long *x, long *y) const;
a1b82138
VZ
102
103 virtual void ShowPosition(long pos);
6726a6b0 104 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
3b830ce0
VZ
105 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
106 wxTextCoord *col,
107 wxTextCoord *row) const
108 {
109 return wxTextCtrlBase::HitTest(pt, col, row);
110 }
a1b82138 111
bfc6fde4
VZ
112 // Clipboard operations
113 virtual void Copy();
114 virtual void Cut();
115 virtual void Paste();
116
ca8b28f2
JS
117 virtual bool CanCopy() const;
118 virtual bool CanCut() const;
119 virtual bool CanPaste() const;
120
121 // Undo/redo
122 virtual void Undo();
123 virtual void Redo();
124
125 virtual bool CanUndo() const;
126 virtual bool CanRedo() const;
127
a1b82138 128 // Insertion point
bfc6fde4
VZ
129 virtual void SetInsertionPoint(long pos);
130 virtual void SetInsertionPointEnd();
a1b82138 131 virtual long GetInsertionPoint() const;
7d8268a1 132 virtual wxTextPos GetLastPosition() const;
a1b82138 133
bfc6fde4
VZ
134 virtual void SetSelection(long from, long to);
135 virtual void SetEditable(bool editable);
136
e3a6a6b2
VZ
137 // Caret handling (Windows only)
138
139 bool ShowNativeCaret(bool show = true);
140 bool HideNativeCaret() { return ShowNativeCaret(false); }
141
4438caf4
VZ
142 // Implementation from now on
143 // --------------------------
e702ff0f 144
b2d5a7ee
VZ
145 virtual void SetWindowStyleFlag(long style);
146
bfc6fde4
VZ
147 virtual void Command(wxCommandEvent& event);
148 virtual bool MSWCommand(WXUINT param, WXWORD id);
2bae4332 149 virtual WXHBRUSH MSWControlColor(WXHDC hDC, WXHWND hWnd);
f6bcfd97 150
396bdd5a 151#if wxUSE_RICHEDIT
c57e3339
VZ
152 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
153
aac7e7fe
VZ
154 int GetRichVersion() const { return m_verRichEdit; }
155 bool IsRich() const { return m_verRichEdit != 0; }
f6bcfd97
BP
156
157 // rich edit controls are not compatible with normal ones and wem ust set
158 // the colours for them otherwise
159 virtual bool SetBackgroundColour(const wxColour& colour);
160 virtual bool SetForegroundColour(const wxColour& colour);
a1b82138 161#endif // wxUSE_RICHEDIT
396bdd5a 162
8ef51d67
JS
163#if wxUSE_INKEDIT && wxUSE_RICHEDIT
164 bool IsInkEdit() const { return m_isInkEdit != 0; }
165#else
166 bool IsInkEdit() const { return false; }
167#endif
168
bfc6fde4 169 virtual void AdoptAttributesFromHWND();
5fb9fcfc 170
c50f1fb9
VZ
171 virtual bool AcceptsFocus() const;
172
4438caf4 173 // callbacks
4438caf4
VZ
174 void OnDropFiles(wxDropFilesEvent& event);
175 void OnChar(wxKeyEvent& event); // Process 'enter' if required
176
177 void OnCut(wxCommandEvent& event);
178 void OnCopy(wxCommandEvent& event);
179 void OnPaste(wxCommandEvent& event);
180 void OnUndo(wxCommandEvent& event);
181 void OnRedo(wxCommandEvent& event);
2b5f62a0
VZ
182 void OnDelete(wxCommandEvent& event);
183 void OnSelectAll(wxCommandEvent& event);
4438caf4
VZ
184
185 void OnUpdateCut(wxUpdateUIEvent& event);
186 void OnUpdateCopy(wxUpdateUIEvent& event);
187 void OnUpdatePaste(wxUpdateUIEvent& event);
188 void OnUpdateUndo(wxUpdateUIEvent& event);
189 void OnUpdateRedo(wxUpdateUIEvent& event);
2b5f62a0
VZ
190 void OnUpdateDelete(wxUpdateUIEvent& event);
191 void OnUpdateSelectAll(wxUpdateUIEvent& event);
192
193 // Show a context menu for Rich Edit controls (the standard
194 // EDIT control has one already)
26f60eb6 195 void OnContextMenu(wxContextMenuEvent& event);
4438caf4 196
e3a6a6b2
VZ
197 // be sure the caret remains invisible if the user
198 // called HideNativeCaret() before
199 void OnSetFocus(wxFocusEvent& event);
200
6f02a879
VZ
201 // intercept WM_GETDLGCODE
202 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
203
204 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
205 virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
206 virtual wxVisualAttributes GetDefaultAttributes() const;
207
2bda0e17 208protected:
aac7e7fe
VZ
209 // common part of all ctors
210 void Init();
211
f6519b40
VZ
212 void DoSetValue(const wxString &value, int flags = 0);
213
4fa80851
VZ
214 // return true if this control has a user-set limit on amount of text (i.e.
215 // the limit is due to a previous call to SetMaxLength() and not built in)
216 bool HasSpaceLimit(unsigned int *len) const;
217
789295bf
VZ
218 // call this to increase the size limit (will do nothing if the current
219 // limit is big enough)
d7eee191
VZ
220 //
221 // returns true if we increased the limit to allow entering more text,
222 // false if we hit the limit set by SetMaxLength() and so didn't change it
223 bool AdjustSpaceLimit();
789295bf 224
7411f983 225#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
79d26b32
VZ
226 // replace the selection or the entire control contents with the given text
227 // in the specified encoding
7411f983
VZ
228 bool StreamIn(const wxString& value, wxFontEncoding encoding, bool selOnly);
229
230 // get the contents of the control out as text in the given encoding
231 wxString StreamOut(wxFontEncoding encoding, bool selOnly = false) const;
aac7e7fe
VZ
232#endif // wxUSE_RICHEDIT
233
79d26b32
VZ
234 // replace the contents of the selection or of the entire control with the
235 // given text
f6519b40 236 void DoWriteText(const wxString& text, int flags = SetValue_SelectionOnly);
79d26b32 237
aac7e7fe 238 // set the selection possibly without scrolling the caret into view
bfbb0b4c 239 void DoSetSelection(long from, long to, bool scrollCaret = true);
aac7e7fe 240
2b5f62a0
VZ
241 // return true if there is a non empty selection in the control
242 bool HasSelection() const;
243
a5aa8086
VZ
244 // get the length of the line containing the character at the given
245 // position
246 long GetLengthOfLineContainingPos(long pos) const;
247
bfbb0b4c 248 // send TEXT_UPDATED event, return true if it was handled, false otherwise
5036ea90
VZ
249 bool SendUpdateEvent();
250
f68586e5 251 virtual wxSize DoGetBestSize() const;
bfc6fde4 252
d7eee191 253#if wxUSE_RICHEDIT
aac7e7fe
VZ
254 // we're using RICHEDIT (and not simple EDIT) control if this field is not
255 // 0, it also gives the version of the RICHEDIT control being used (1, 2 or
256 // 3 so far)
257 int m_verRichEdit;
2b5f62a0 258#endif // wxUSE_RICHEDIT
5036ea90 259
2c62dd25
VZ
260 // number of EN_UPDATE events sent by Windows when we change the controls
261 // text ourselves: we want this to be exactly 1
262 int m_updatesCount;
d7eee191 263
bfc6fde4
VZ
264private:
265 DECLARE_EVENT_TABLE()
fc7a2a60 266 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl)
2b5f62a0
VZ
267
268 wxMenu* m_privateContextMenu;
e3a6a6b2
VZ
269
270 bool m_isNativeCaretShown;
8ef51d67
JS
271
272#if wxUSE_INKEDIT && wxUSE_RICHEDIT
273 int m_isInkEdit;
274#endif
275
2bda0e17
KB
276};
277
278#endif
bbcdf8bc 279 // _WX_TEXTCTRL_H_