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