]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/textctrl.h
fixed bug with the caret positioning after SetValue() introduced by the last commit
[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
5fb9fcfc 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_TEXTCTRL_H_
13#define _WX_TEXTCTRL_H_
2bda0e17
KB
14
15#ifdef __GNUG__
396bdd5a 16 #pragma interface "textctrl.h"
2bda0e17
KB
17#endif
18
a1b82138 19class WXDLLEXPORT wxTextCtrl : public wxTextCtrlBase
2bda0e17 20{
ae29de83 21public:
bfc6fde4
VZ
22 // creation
23 // --------
a1b82138 24
aac7e7fe 25 wxTextCtrl() { Init(); }
bfc6fde4 26 wxTextCtrl(wxWindow *parent, wxWindowID id,
a1b82138
VZ
27 const wxString& value = wxEmptyString,
28 const wxPoint& pos = wxDefaultPosition,
29 const wxSize& size = wxDefaultSize,
30 long style = 0,
31 const wxValidator& validator = wxDefaultValidator,
32 const wxString& name = wxTextCtrlNameStr)
33 {
aac7e7fe
VZ
34 Init();
35
a1b82138
VZ
36 Create(parent, id, value, pos, size, style, validator, name);
37 }
bfc6fde4
VZ
38
39 bool Create(wxWindow *parent, wxWindowID id,
a1b82138
VZ
40 const wxString& value = wxEmptyString,
41 const wxPoint& pos = wxDefaultPosition,
42 const wxSize& size = wxDefaultSize,
43 long style = 0,
44 const wxValidator& validator = wxDefaultValidator,
45 const wxString& name = wxTextCtrlNameStr);
bfc6fde4 46
a1b82138
VZ
47 // implement base class pure virtuals
48 // ----------------------------------
4438caf4
VZ
49
50 virtual wxString GetValue() const;
bfc6fde4
VZ
51 virtual void SetValue(const wxString& value);
52
53 virtual int GetLineLength(long lineNo) const;
54 virtual wxString GetLineText(long lineNo) const;
55 virtual int GetNumberOfLines() const;
56
a1b82138
VZ
57 virtual bool IsModified() const;
58 virtual bool IsEditable() const;
59
a1b82138 60 virtual void GetSelection(long* from, long* to) const;
eef97940 61 virtual wxString GetStringSelection() const;
a1b82138 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
71 // load the controls contents from the file
72 virtual bool LoadFile(const wxString& file);
73
74 // clears the dirty flag
75 virtual void DiscardEdits();
76
d7eee191
VZ
77 virtual void SetMaxLength(unsigned long len);
78
a1b82138
VZ
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
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);
88#endif // wxUSE_RICHEDIT
89
a1b82138
VZ
90 // translate between the position (which is just an index in the text ctrl
91 // considering all its contents as a single strings) and (x, y) coordinates
92 // which represent column and line.
93 virtual long XYToPosition(long x, long y) const;
0efe5ba7 94 virtual bool PositionToXY(long pos, long *x, long *y) const;
a1b82138
VZ
95
96 virtual void ShowPosition(long pos);
97
bfc6fde4
VZ
98 // Clipboard operations
99 virtual void Copy();
100 virtual void Cut();
101 virtual void Paste();
102
ca8b28f2
JS
103 virtual bool CanCopy() const;
104 virtual bool CanCut() const;
105 virtual bool CanPaste() const;
106
107 // Undo/redo
108 virtual void Undo();
109 virtual void Redo();
110
111 virtual bool CanUndo() const;
112 virtual bool CanRedo() const;
113
a1b82138 114 // Insertion point
bfc6fde4
VZ
115 virtual void SetInsertionPoint(long pos);
116 virtual void SetInsertionPointEnd();
a1b82138
VZ
117 virtual long GetInsertionPoint() const;
118 virtual long GetLastPosition() const;
119
bfc6fde4
VZ
120 virtual void SetSelection(long from, long to);
121 virtual void SetEditable(bool editable);
122
4438caf4
VZ
123 // Implementation from now on
124 // --------------------------
e702ff0f 125
bfc6fde4
VZ
126 virtual void Command(wxCommandEvent& event);
127 virtual bool MSWCommand(WXUINT param, WXWORD id);
f6bcfd97
BP
128 virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
129 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
130
131 // In WIN16, need to override normal erasing because
132 // Ctl3D doesn't use the wxWindows background colour.
133#ifdef __WIN16__
134 void OnEraseBackground(wxEraseEvent& event);
135#endif
396bdd5a
VZ
136
137#if wxUSE_RICHEDIT
c57e3339
VZ
138 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
139
aac7e7fe
VZ
140 int GetRichVersion() const { return m_verRichEdit; }
141 bool IsRich() const { return m_verRichEdit != 0; }
f6bcfd97
BP
142
143 // rich edit controls are not compatible with normal ones and wem ust set
144 // the colours for them otherwise
145 virtual bool SetBackgroundColour(const wxColour& colour);
146 virtual bool SetForegroundColour(const wxColour& colour);
a1b82138 147#endif // wxUSE_RICHEDIT
396bdd5a 148
bfc6fde4 149 virtual void AdoptAttributesFromHWND();
5fb9fcfc 150
c50f1fb9
VZ
151 virtual bool AcceptsFocus() const;
152
4438caf4 153 // callbacks
4438caf4
VZ
154 void OnDropFiles(wxDropFilesEvent& event);
155 void OnChar(wxKeyEvent& event); // Process 'enter' if required
156
157 void OnCut(wxCommandEvent& event);
158 void OnCopy(wxCommandEvent& event);
159 void OnPaste(wxCommandEvent& event);
160 void OnUndo(wxCommandEvent& event);
161 void OnRedo(wxCommandEvent& event);
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);
168
2bda0e17 169protected:
aac7e7fe
VZ
170 // common part of all ctors
171 void Init();
172
789295bf
VZ
173 // call this to increase the size limit (will do nothing if the current
174 // limit is big enough)
d7eee191
VZ
175 //
176 // returns true if we increased the limit to allow entering more text,
177 // false if we hit the limit set by SetMaxLength() and so didn't change it
178 bool AdjustSpaceLimit();
789295bf 179
aac7e7fe
VZ
180#if wxUSE_RICHEDIT
181 // replace the selection with the given text in the specified encoding
182 bool StreamIn(const wxString& value, wxFontEncoding encoding);
183#endif // wxUSE_RICHEDIT
184
185 // set the selection possibly without scrolling the caret into view
186 void DoSetSelection(long from, long to, bool scrollCaret = TRUE);
187
a37d422a
VZ
188 // override some base class virtuals
189 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
f68586e5 190 virtual wxSize DoGetBestSize() const;
bfc6fde4 191
d7eee191 192#if wxUSE_RICHEDIT
aac7e7fe
VZ
193 // we're using RICHEDIT (and not simple EDIT) control if this field is not
194 // 0, it also gives the version of the RICHEDIT control being used (1, 2 or
195 // 3 so far)
196 int m_verRichEdit;
197#endif // wxUSE_RICHEDIT
d7eee191 198
bfc6fde4
VZ
199private:
200 DECLARE_EVENT_TABLE()
a1b82138 201 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
2bda0e17
KB
202};
203
204#endif
bbcdf8bc 205 // _WX_TEXTCTRL_H_