]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/wince/textctrlce.h
38fb54268b429fe2f9e91cb5239b2c859302790c
[wxWidgets.git] / include / wx / msw / wince / textctrlce.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/wince/textctrlce.h
3 // Purpose: wxTextCtrl implementation for smart phones driven by WinCE
4 // Author: Wlodzimierz ABX Skiba
5 // Modified by:
6 // Created: 30.08.2004
7 // RCS-ID: $Id$
8 // Copyright: (c) Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TEXTCTRLCE_H_
13 #define _WX_TEXTCTRLCE_H_
14
15 #include "wx/dynarray.h"
16
17 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
18 WX_DEFINE_EXPORTED_ARRAY_PTR(wxTextCtrl *, wxArrayTextSpins);
19
20 class WXDLLIMPEXP_CORE wxTextCtrl : public wxTextCtrlBase
21 {
22 public:
23 // creation
24 // --------
25
26 wxTextCtrl() { Init(); }
27 wxTextCtrl(wxWindow *parent, wxWindowID id,
28 const wxString& value = wxEmptyString,
29 const wxPoint& pos = wxDefaultPosition,
30 const wxSize& size = wxDefaultSize,
31 long style = 0,
32 const wxValidator& validator = wxDefaultValidator,
33 const wxString& name = wxTextCtrlNameStr)
34 {
35 Init();
36
37 Create(parent, id, value, pos, size, style, validator, name);
38 }
39 virtual ~wxTextCtrl();
40
41 bool Create(wxWindow *parent, wxWindowID id,
42 const wxString& value = wxEmptyString,
43 const wxPoint& pos = wxDefaultPosition,
44 const wxSize& size = wxDefaultSize,
45 long style = 0,
46 const wxValidator& validator = wxDefaultValidator,
47 const wxString& name = wxTextCtrlNameStr);
48
49 // implement base class pure virtuals
50 // ----------------------------------
51
52 virtual wxString GetValue() const;
53 virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
54
55 virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
56
57 virtual wxString GetRange(long from, long to) const;
58
59 virtual int GetLineLength(long lineNo) const;
60 virtual wxString GetLineText(long lineNo) const;
61 virtual int GetNumberOfLines() const;
62
63 virtual bool IsModified() const;
64 virtual bool IsEditable() const;
65
66 virtual void GetSelection(long* from, long* to) const;
67
68 // operations
69 // ----------
70
71 // editing
72 virtual void Clear();
73 virtual void Replace(long from, long to, const wxString& value);
74 virtual void Remove(long from, long to);
75
76 // load the controls contents from the file
77 virtual bool LoadFile(const wxString& file);
78
79 // clears the dirty flag
80 virtual void MarkDirty();
81 virtual void DiscardEdits();
82
83 virtual void SetMaxLength(unsigned long len);
84
85 // writing text inserts it at the current position, appending always
86 // inserts it at the end
87 virtual void WriteText(const wxString& text);
88 virtual void AppendText(const wxString& text);
89
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;
94 virtual bool PositionToXY(long pos, long *x, long *y) const;
95
96 virtual void ShowPosition(long pos);
97 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
98 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
99 wxTextCoord *col,
100 wxTextCoord *row) const
101 {
102 return wxTextCtrlBase::HitTest(pt, col, row);
103 }
104
105 // Clipboard operations
106 virtual void Copy();
107 virtual void Cut();
108 virtual void Paste();
109
110 virtual bool CanCopy() const;
111 virtual bool CanCut() const;
112 virtual bool CanPaste() const;
113
114 // Undo/redo
115 virtual void Undo();
116 virtual void Redo();
117
118 virtual bool CanUndo() const;
119 virtual bool CanRedo() const;
120
121 // Insertion point
122 virtual void SetInsertionPoint(long pos);
123 virtual void SetInsertionPointEnd();
124 virtual long GetInsertionPoint() const;
125 virtual wxTextPos GetLastPosition() const;
126
127 virtual void SetSelection(long from, long to);
128 virtual void SetEditable(bool editable);
129
130 // Caret handling (Windows only)
131
132 bool ShowNativeCaret(bool show = true);
133 bool HideNativeCaret() { return ShowNativeCaret(false); }
134
135 // Implementation from now on
136 // --------------------------
137
138 virtual void Command(wxCommandEvent& event);
139 virtual bool MSWCommand(WXUINT param, WXWORD id);
140
141 virtual void AdoptAttributesFromHWND();
142
143 virtual bool AcceptsFocus() const;
144
145 // callbacks
146 void OnDropFiles(wxDropFilesEvent& event);
147 void OnChar(wxKeyEvent& event); // Process 'enter' if required
148
149 void OnCut(wxCommandEvent& event);
150 void OnCopy(wxCommandEvent& event);
151 void OnPaste(wxCommandEvent& event);
152 void OnUndo(wxCommandEvent& event);
153 void OnRedo(wxCommandEvent& event);
154 void OnDelete(wxCommandEvent& event);
155 void OnSelectAll(wxCommandEvent& event);
156
157 void OnUpdateCut(wxUpdateUIEvent& event);
158 void OnUpdateCopy(wxUpdateUIEvent& event);
159 void OnUpdatePaste(wxUpdateUIEvent& event);
160 void OnUpdateUndo(wxUpdateUIEvent& event);
161 void OnUpdateRedo(wxUpdateUIEvent& event);
162 void OnUpdateDelete(wxUpdateUIEvent& event);
163 void OnUpdateSelectAll(wxUpdateUIEvent& event);
164
165 // Show a context menu for Rich Edit controls (the standard
166 // EDIT control has one already)
167 void OnRightClick(wxMouseEvent& event);
168
169 // be sure the caret remains invisible if the user
170 // called HideNativeCaret() before
171 void OnSetFocus(wxFocusEvent& event);
172
173 // get the subclassed window proc of the buddy
174 WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; }
175
176 // intercept WM_GETDLGCODE
177 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
178
179 protected:
180 // common part of all ctors
181 void Init();
182
183 // call this to increase the size limit (will do nothing if the current
184 // limit is big enough)
185 //
186 // returns true if we increased the limit to allow entering more text,
187 // false if we hit the limit set by SetMaxLength() and so didn't change it
188 bool AdjustSpaceLimit();
189
190 void DoSetValue(const wxString &value, int flags = 0);
191
192 // replace the contents of the selection or of the entire control with the
193 // given text
194 void DoWriteText(const wxString& text, int flags = SetValue_SelectionOnly);
195
196 // set the selection possibly without scrolling the caret into view
197 void DoSetSelection(long from, long to, bool scrollCaret = true);
198
199 // return true if there is a non empty selection in the control
200 bool HasSelection() const;
201
202 // get the length of the line containing the character at the given
203 // position
204 long GetLengthOfLineContainingPos(long pos) const;
205
206 // send TEXT_UPDATED event, return true if it was handled, false otherwise
207 bool SendUpdateEvent();
208
209 // override some base class virtuals
210 virtual void DoMoveWindow(int x, int y, int width, int height);
211 virtual wxSize DoGetBestSize() const;
212
213 virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
214
215 // if true, SendUpdateEvent() will eat the next event (see comments in the
216 // code as to why this is needed)
217 bool m_suppressNextUpdate;
218
219 // all existing wxTextCtrl - this allows to find the one corresponding to
220 // the given buddy window in GetSpinTextCtrl()
221 static wxArrayTextSpins ms_allTextSpins;
222
223 protected:
224
225 // the data for the "buddy" list
226 WXHWND m_hwndBuddy;
227 WXFARPROC m_wndProcBuddy;
228
229 private:
230 DECLARE_EVENT_TABLE()
231 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl)
232
233 bool m_isNativeCaretShown;
234 };
235
236 #endif // _WX_TEXTCTRLCE_H_