added wxTextCtrl::ChangeValue() which is the same as SetValue() but doesn't send...
[wxWidgets.git] / include / wx / palmos / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/textctrl.h
3 // Purpose: wxTextCtrl class
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by:
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TEXTCTRL_H_
13 #define _WX_TEXTCTRL_H_
14
15 class WXDLLEXPORT wxTextCtrl : public wxTextCtrlBase
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 }
34 virtual ~wxTextCtrl();
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
44 // implement base class pure virtuals
45 // ----------------------------------
46
47 virtual wxString GetValue() const;
48 virtual void SetValue(const wxString& value);
49
50 virtual void ChangeValue(const wxString &value);
51
52 virtual int GetLineLength(long lineNo) const;
53 virtual wxString GetLineText(long lineNo) const;
54 virtual int GetNumberOfLines() const;
55
56 virtual bool IsModified() const;
57 virtual bool IsEditable() const;
58
59 virtual void GetSelection(long* from, long* to) const;
60
61 // operations
62 // ----------
63
64 // editing
65 virtual void Clear();
66 virtual void Replace(long from, long to, const wxString& value);
67 virtual void Remove(long from, long to);
68
69 // load the control's contents from the file
70 virtual bool DoLoadFile(const wxString& file, int fileType);
71
72 // clears the dirty flag
73 virtual void MarkDirty();
74 virtual void DiscardEdits();
75
76 virtual void SetMaxLength(unsigned long len);
77
78 // writing text inserts it at the current position, appending always
79 // inserts it at the end
80 virtual void WriteText(const wxString& text);
81 virtual void AppendText(const wxString& text);
82
83 #if wxUSE_RICHEDIT
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 virtual bool SetDefaultStyle(const wxTextAttr& style);
88 virtual bool GetStyle(long position, wxTextAttr& style);
89 #endif // wxUSE_RICHEDIT
90
91 // translate between the position (which is just an index in the text ctrl
92 // considering all its contents as a single strings) and (x, y) coordinates
93 // which represent column and line.
94 virtual long XYToPosition(long x, long y) const;
95 virtual bool PositionToXY(long pos, long *x, long *y) const;
96
97 virtual void ShowPosition(long pos);
98 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
99 wxTextCoord *col,
100 wxTextCoord *row) const;
101
102 // Clipboard operations
103 virtual void Copy();
104 virtual void Cut();
105 virtual void Paste();
106
107 virtual bool CanCopy() const;
108 virtual bool CanCut() const;
109 virtual bool CanPaste() const;
110
111 // Undo/redo
112 virtual void Undo();
113 virtual void Redo();
114
115 virtual bool CanUndo() const;
116 virtual bool CanRedo() const;
117
118 // Insertion point
119 virtual void SetInsertionPoint(long pos);
120 virtual void SetInsertionPointEnd();
121 virtual long GetInsertionPoint() const;
122 virtual wxTextPos GetLastPosition() const;
123
124 virtual void SetSelection(long from, long to);
125 virtual void SetEditable(bool editable);
126
127 // Caret handling (Windows only)
128
129 bool ShowNativeCaret(bool show = true);
130 bool HideNativeCaret() { return ShowNativeCaret(false); }
131
132 // Implementation from now on
133 // --------------------------
134
135 virtual void Command(wxCommandEvent& event);
136 virtual bool MSWCommand(WXUINT param, WXWORD id);
137
138 #if wxUSE_RICHEDIT
139 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
140
141 int GetRichVersion() const { return m_verRichEdit; }
142 bool IsRich() const { return m_verRichEdit != 0; }
143
144 // rich edit controls are not compatible with normal ones and wem ust set
145 // the colours for them otherwise
146 virtual bool SetBackgroundColour(const wxColour& colour);
147 virtual bool SetForegroundColour(const wxColour& colour);
148 #endif // wxUSE_RICHEDIT
149
150 virtual bool AcceptsFocus() const;
151
152 // callbacks
153 void OnDropFiles(wxDropFilesEvent& event);
154 void OnChar(wxKeyEvent& event); // Process 'enter' if required
155
156 void OnCut(wxCommandEvent& event);
157 void OnCopy(wxCommandEvent& event);
158 void OnPaste(wxCommandEvent& event);
159 void OnUndo(wxCommandEvent& event);
160 void OnRedo(wxCommandEvent& event);
161 void OnDelete(wxCommandEvent& event);
162 void OnSelectAll(wxCommandEvent& event);
163
164 void OnUpdateCut(wxUpdateUIEvent& event);
165 void OnUpdateCopy(wxUpdateUIEvent& event);
166 void OnUpdatePaste(wxUpdateUIEvent& event);
167 void OnUpdateUndo(wxUpdateUIEvent& event);
168 void OnUpdateRedo(wxUpdateUIEvent& event);
169 void OnUpdateDelete(wxUpdateUIEvent& event);
170 void OnUpdateSelectAll(wxUpdateUIEvent& event);
171
172 // Show a context menu for Rich Edit controls (the standard
173 // EDIT control has one already)
174 void OnRightClick(wxMouseEvent& event);
175
176 // be sure the caret remains invisible if the user
177 // called HideNativeCaret() before
178 void OnSetFocus(wxFocusEvent& event);
179
180 protected:
181 // common part of all ctors
182 void Init();
183
184 // intercept WM_GETDLGCODE
185 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
186
187 // call this to increase the size limit (will do nothing if the current
188 // limit is big enough)
189 //
190 // returns true if we increased the limit to allow entering more text,
191 // false if we hit the limit set by SetMaxLength() and so didn't change it
192 bool AdjustSpaceLimit();
193
194 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
195 // replace the selection or the entire control contents with the given text
196 // in the specified encoding
197 bool StreamIn(const wxString& value, wxFontEncoding encoding, bool selOnly);
198
199 // get the contents of the control out as text in the given encoding
200 wxString StreamOut(wxFontEncoding encoding, bool selOnly = false) const;
201 #endif // wxUSE_RICHEDIT
202
203 // replace the contents of the selection or of the entire control with the
204 // given text
205 void DoWriteText(const wxString& text, bool selectionOnly = true);
206
207 // set the selection possibly without scrolling the caret into view
208 void DoSetSelection(long from, long to, bool scrollCaret = true);
209
210 // return true if there is a non empty selection in the control
211 bool HasSelection() const;
212
213 // get the length of the line containing the character at the given
214 // position
215 long GetLengthOfLineContainingPos(long pos) const;
216
217 // send TEXT_UPDATED event, return true if it was handled, false otherwise
218 bool SendUpdateEvent();
219
220 // override some base class virtuals
221 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
222 virtual wxSize DoGetBestSize() const;
223
224 virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
225
226 #if wxUSE_RICHEDIT
227 // we're using RICHEDIT (and not simple EDIT) control if this field is not
228 // 0, it also gives the version of the RICHEDIT control being used (1, 2 or
229 // 3 so far)
230 int m_verRichEdit;
231 #endif // wxUSE_RICHEDIT
232
233 // if true, SendUpdateEvent() will eat the next event (see comments in the
234 // code as to why this is needed)
235 bool m_suppressNextUpdate;
236
237 private:
238 DECLARE_EVENT_TABLE()
239 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl)
240
241 wxMenu* m_privateContextMenu;
242
243 bool m_isNativeCaretShown;
244 };
245
246 #endif
247 // _WX_TEXTCTRL_H_