1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/wince/textctrlce.h
3 // Purpose: wxTextCtrl implementation for smart phones driven by WinCE
4 // Author: Wlodzimierz ABX Skiba
7 // Copyright: (c) Wlodzimierz Skiba
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_TEXTCTRLCE_H_
12 #define _WX_TEXTCTRLCE_H_
14 #include "wx/dynarray.h"
16 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
17 WX_DEFINE_EXPORTED_ARRAY_PTR(wxTextCtrl
*, wxArrayTextSpins
);
19 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
25 wxTextCtrl() { Init(); }
26 wxTextCtrl(wxWindow
*parent
, wxWindowID id
,
27 const wxString
& value
= wxEmptyString
,
28 const wxPoint
& pos
= wxDefaultPosition
,
29 const wxSize
& size
= wxDefaultSize
,
31 const wxValidator
& validator
= wxDefaultValidator
,
32 const wxString
& name
= wxTextCtrlNameStr
)
36 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
38 virtual ~wxTextCtrl();
40 bool Create(wxWindow
*parent
, wxWindowID id
,
41 const wxString
& value
= wxEmptyString
,
42 const wxPoint
& pos
= wxDefaultPosition
,
43 const wxSize
& size
= wxDefaultSize
,
45 const wxValidator
& validator
= wxDefaultValidator
,
46 const wxString
& name
= wxTextCtrlNameStr
);
48 // implement base class pure virtuals
49 // ----------------------------------
51 virtual wxString
GetValue() const;
52 virtual void SetValue(const wxString
& value
) { DoSetValue(value
, SetValue_SendEvent
); }
54 virtual void ChangeValue(const wxString
&value
) { DoSetValue(value
); }
56 virtual wxString
GetRange(long from
, long to
) const;
58 virtual int GetLineLength(long lineNo
) const;
59 virtual wxString
GetLineText(long lineNo
) const;
60 virtual int GetNumberOfLines() const;
62 virtual bool IsModified() const;
63 virtual bool IsEditable() const;
65 virtual void GetSelection(long* from
, long* to
) const;
72 virtual void Replace(long from
, long to
, const wxString
& value
);
73 virtual void Remove(long from
, long to
);
75 // load the controls contents from the file
76 virtual bool LoadFile(const wxString
& file
);
78 // clears the dirty flag
79 virtual void MarkDirty();
80 virtual void DiscardEdits();
82 virtual void SetMaxLength(unsigned long len
);
84 // writing text inserts it at the current position, appending always
85 // inserts it at the end
86 virtual void WriteText(const wxString
& text
);
87 virtual void AppendText(const wxString
& text
);
89 // translate between the position (which is just an index in the text ctrl
90 // considering all its contents as a single strings) and (x, y) coordinates
91 // which represent column and line.
92 virtual long XYToPosition(long x
, long y
) const;
93 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
95 virtual void ShowPosition(long pos
);
96 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
97 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
99 wxTextCoord
*row
) const
101 return wxTextCtrlBase::HitTest(pt
, col
, row
);
104 // Clipboard operations
107 virtual void Paste();
109 virtual bool CanCopy() const;
110 virtual bool CanCut() const;
111 virtual bool CanPaste() const;
117 virtual bool CanUndo() const;
118 virtual bool CanRedo() const;
121 virtual void SetInsertionPoint(long pos
);
122 virtual void SetInsertionPointEnd();
123 virtual long GetInsertionPoint() const;
124 virtual wxTextPos
GetLastPosition() const;
126 virtual void SetSelection(long from
, long to
);
127 virtual void SetEditable(bool editable
);
129 // Caret handling (Windows only)
131 bool ShowNativeCaret(bool show
= true);
132 bool HideNativeCaret() { return ShowNativeCaret(false); }
134 // Implementation from now on
135 // --------------------------
137 virtual void Command(wxCommandEvent
& event
);
138 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
140 virtual void AdoptAttributesFromHWND();
142 virtual bool AcceptsFocus() const;
145 void OnDropFiles(wxDropFilesEvent
& event
);
146 void OnChar(wxKeyEvent
& event
); // Process 'enter' if required
148 void OnCut(wxCommandEvent
& event
);
149 void OnCopy(wxCommandEvent
& event
);
150 void OnPaste(wxCommandEvent
& event
);
151 void OnUndo(wxCommandEvent
& event
);
152 void OnRedo(wxCommandEvent
& event
);
153 void OnDelete(wxCommandEvent
& event
);
154 void OnSelectAll(wxCommandEvent
& event
);
156 void OnUpdateCut(wxUpdateUIEvent
& event
);
157 void OnUpdateCopy(wxUpdateUIEvent
& event
);
158 void OnUpdatePaste(wxUpdateUIEvent
& event
);
159 void OnUpdateUndo(wxUpdateUIEvent
& event
);
160 void OnUpdateRedo(wxUpdateUIEvent
& event
);
161 void OnUpdateDelete(wxUpdateUIEvent
& event
);
162 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
164 // Show a context menu for Rich Edit controls (the standard
165 // EDIT control has one already)
166 void OnRightClick(wxMouseEvent
& event
);
168 // be sure the caret remains invisible if the user
169 // called HideNativeCaret() before
170 void OnSetFocus(wxFocusEvent
& event
);
172 // get the subclassed window proc of the buddy
173 WXFARPROC
GetBuddyWndProc() const { return m_wndProcBuddy
; }
175 // intercept WM_GETDLGCODE
176 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
179 // common part of all ctors
182 // call this to increase the size limit (will do nothing if the current
183 // limit is big enough)
185 // returns true if we increased the limit to allow entering more text,
186 // false if we hit the limit set by SetMaxLength() and so didn't change it
187 bool AdjustSpaceLimit();
189 void DoSetValue(const wxString
&value
, int flags
= 0);
191 // replace the contents of the selection or of the entire control with the
193 void DoWriteText(const wxString
& text
, int flags
= SetValue_SelectionOnly
);
195 // set the selection possibly without scrolling the caret into view
196 void DoSetSelection(long from
, long to
, bool scrollCaret
= true);
198 // return true if there is a non empty selection in the control
199 bool HasSelection() const;
201 // get the length of the line containing the character at the given
203 long GetLengthOfLineContainingPos(long pos
) const;
205 // send TEXT_UPDATED event, return true if it was handled, false otherwise
206 bool SendUpdateEvent();
208 // override some base class virtuals
209 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
210 virtual wxSize
DoGetBestSize() const;
212 virtual WXDWORD
MSWGetStyle(long style
, WXDWORD
*exstyle
) const;
214 // if true, SendUpdateEvent() will eat the next event (see comments in the
215 // code as to why this is needed)
216 bool m_suppressNextUpdate
;
218 // all existing wxTextCtrl - this allows to find the one corresponding to
219 // the given buddy window in GetSpinTextCtrl()
220 static wxArrayTextSpins ms_allTextSpins
;
224 // the data for the "buddy" list
226 WXFARPROC m_wndProcBuddy
;
229 DECLARE_EVENT_TABLE()
230 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl
)
232 bool m_isNativeCaretShown
;
235 #endif // _WX_TEXTCTRLCE_H_