1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/wince/textctrlce.h
3 // Purpose: wxTextCtrl class - Smartphone implementation
4 // Author: Wlodzimierz ABX Skiba
8 // Copyright: (c) Wlodzimierz Skiba
9 // License: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TEXTCTRLCE_H_
13 #define _WX_TEXTCTRLCE_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "textctrlce.h"
19 #include "wx/dynarray.h"
21 class WXDLLEXPORT wxTextCtrl
;
22 WX_DEFINE_EXPORTED_ARRAY_PTR(wxTextCtrl
*, wxArrayTextSpins
);
24 class WXDLLEXPORT wxTextCtrl
: public wxTextCtrlBase
30 wxTextCtrl() { Init(); }
31 wxTextCtrl(wxWindow
*parent
, wxWindowID id
,
32 const wxString
& value
= wxEmptyString
,
33 const wxPoint
& pos
= wxDefaultPosition
,
34 const wxSize
& size
= wxDefaultSize
,
36 const wxValidator
& validator
= wxDefaultValidator
,
37 const wxString
& name
= wxTextCtrlNameStr
)
41 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
45 bool Create(wxWindow
*parent
, wxWindowID id
,
46 const wxString
& value
= wxEmptyString
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
50 const wxValidator
& validator
= wxDefaultValidator
,
51 const wxString
& name
= wxTextCtrlNameStr
);
53 // implement base class pure virtuals
54 // ----------------------------------
56 virtual wxString
GetValue() const;
57 virtual void SetValue(const wxString
& value
);
59 virtual wxString
GetRange(long from
, long to
) const;
61 virtual int GetLineLength(long lineNo
) const;
62 virtual wxString
GetLineText(long lineNo
) const;
63 virtual int GetNumberOfLines() const;
65 virtual bool IsModified() const;
66 virtual bool IsEditable() const;
68 virtual void GetSelection(long* from
, long* to
) const;
75 virtual void Replace(long from
, long to
, const wxString
& value
);
76 virtual void Remove(long from
, long to
);
78 // load the controls contents from the file
79 virtual bool LoadFile(const wxString
& file
);
81 // clears the dirty flag
82 virtual void MarkDirty();
83 virtual void DiscardEdits();
85 virtual void SetMaxLength(unsigned long len
);
87 // writing text inserts it at the current position, appending always
88 // inserts it at the end
89 virtual void WriteText(const wxString
& text
);
90 virtual void AppendText(const wxString
& text
);
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;
96 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
98 virtual void ShowPosition(long pos
);
99 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
100 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
102 wxTextCoord
*row
) const
104 return wxTextCtrlBase::HitTest(pt
, col
, row
);
107 // Clipboard operations
110 virtual void Paste();
112 virtual bool CanCopy() const;
113 virtual bool CanCut() const;
114 virtual bool CanPaste() const;
120 virtual bool CanUndo() const;
121 virtual bool CanRedo() const;
124 virtual void SetInsertionPoint(long pos
);
125 virtual void SetInsertionPointEnd();
126 virtual long GetInsertionPoint() const;
127 virtual long GetLastPosition() const;
129 virtual void SetSelection(long from
, long to
);
130 virtual void SetEditable(bool editable
);
132 // Caret handling (Windows only)
134 bool ShowNativeCaret(bool show
= true);
135 bool HideNativeCaret() { return ShowNativeCaret(false); }
137 // Implementation from now on
138 // --------------------------
140 virtual void Command(wxCommandEvent
& event
);
141 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
142 virtual WXHBRUSH
OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
143 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
145 virtual void AdoptAttributesFromHWND();
147 virtual bool AcceptsFocus() const;
150 void OnDropFiles(wxDropFilesEvent
& event
);
151 void OnChar(wxKeyEvent
& event
); // Process 'enter' if required
153 void OnCut(wxCommandEvent
& event
);
154 void OnCopy(wxCommandEvent
& event
);
155 void OnPaste(wxCommandEvent
& event
);
156 void OnUndo(wxCommandEvent
& event
);
157 void OnRedo(wxCommandEvent
& event
);
158 void OnDelete(wxCommandEvent
& event
);
159 void OnSelectAll(wxCommandEvent
& event
);
161 void OnUpdateCut(wxUpdateUIEvent
& event
);
162 void OnUpdateCopy(wxUpdateUIEvent
& event
);
163 void OnUpdatePaste(wxUpdateUIEvent
& event
);
164 void OnUpdateUndo(wxUpdateUIEvent
& event
);
165 void OnUpdateRedo(wxUpdateUIEvent
& event
);
166 void OnUpdateDelete(wxUpdateUIEvent
& event
);
167 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
169 // Show a context menu for Rich Edit controls (the standard
170 // EDIT control has one already)
171 void OnRightClick(wxMouseEvent
& event
);
173 // be sure the caret remains invisible if the user
174 // called HideNativeCaret() before
175 void OnSetFocus(wxFocusEvent
& event
);
177 // get the subclassed window proc of the buddy
178 WXFARPROC
GetBuddyWndProc() const { return m_wndProcBuddy
; }
180 // intercept WM_GETDLGCODE
181 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
184 // common part of all ctors
187 // call this to increase the size limit (will do nothing if the current
188 // limit is big enough)
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();
194 // replace the contents of the selection or of the entire control with the
196 void DoWriteText(const wxString
& text
, bool selectionOnly
= TRUE
);
198 // set the selection possibly without scrolling the caret into view
199 void DoSetSelection(long from
, long to
, bool scrollCaret
= TRUE
);
201 // return true if there is a non empty selection in the control
202 bool HasSelection() const;
204 // get the length of the line containing the character at the given
206 long GetLengthOfLineContainingPos(long pos
) const;
208 // send TEXT_UPDATED event, return TRUE if it was handled, FALSE otherwise
209 bool SendUpdateEvent();
211 // override some base class virtuals
212 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
213 virtual wxSize
DoGetBestSize() const;
215 virtual WXDWORD
MSWGetStyle(long style
, WXDWORD
*exstyle
) const;
217 // if TRUE, SendUpdateEvent() will eat the next event (see comments in the
218 // code as to why this is needed)
219 bool m_suppressNextUpdate
;
221 // all existing wxTextCtrl - this allows to find the one corresponding to
222 // the given buddy window in GetSpinTextCtrl()
223 static wxArrayTextSpins ms_allTextSpins
;
227 // the data for the "buddy" list
229 WXFARPROC m_wndProcBuddy
;
232 DECLARE_EVENT_TABLE()
233 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl
)
235 bool m_isNativeCaretShown
;
238 #endif // _WX_TEXTCTRLCE_H_