1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/textctrl.h
3 // Purpose: wxTextCtrl class
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Yunhui Fu
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TEXTCTRL_H_
13 #define _WX_TEXTCTRL_H_
15 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
21 wxTextCtrl() { Init(); }
22 wxTextCtrl(wxWindow
*parent
, wxWindowID id
,
23 const wxString
& value
= wxEmptyString
,
24 const wxPoint
& pos
= wxDefaultPosition
,
25 const wxSize
& size
= wxDefaultSize
,
27 const wxValidator
& validator
= wxDefaultValidator
,
28 const wxString
& name
= wxTextCtrlNameStr
)
32 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
34 virtual ~wxTextCtrl();
36 bool Create(wxWindow
*parent
, wxWindowID id
,
37 const wxString
& value
= wxEmptyString
,
38 const wxPoint
& pos
= wxDefaultPosition
,
39 const wxSize
& size
= wxDefaultSize
,
41 const wxValidator
& validator
= wxDefaultValidator
,
42 const wxString
& name
= wxTextCtrlNameStr
);
44 // overridden wxTextEntry methods
45 // ------------------------------
47 virtual wxString
GetValue() const;
48 virtual wxString
GetRange(long from
, long to
) const;
50 virtual bool IsEmpty() const;
52 virtual int GetLineLength(long lineNo
) const;
53 virtual wxString
GetLineText(long lineNo
) const;
54 virtual int GetNumberOfLines() const;
56 virtual void SetMaxLength(unsigned long len
);
58 virtual void GetSelection(long *from
, long *to
) const;
63 virtual void Clear(void);
64 virtual void Replace( long lFrom
66 ,const wxString
& rsValue
68 virtual void Remove( long lFrom
72 //virtual bool DoLoadFile(const wxString& rsFile, int fileType);
74 virtual void MarkDirty();
75 virtual void DiscardEdits(void);
77 virtual void WriteText(const wxString
& rsText
);
78 virtual void AppendText(const wxString
& rsText
);
79 virtual bool EmulateKeyPress(const wxKeyEvent
& rEvent
);
81 virtual void Copy(void);
82 virtual void Cut(void);
83 virtual void Paste(void);
85 virtual bool CanCopy(void) const;
86 virtual bool CanCut(void) const;
87 virtual bool CanPaste(void) const;
89 virtual void Undo(void);
92 virtual bool CanUndo(void) const;
93 virtual bool CanRedo(void) const;
95 virtual void SetInsertionPoint(long lPos
);
96 virtual void SetInsertionPointEnd(void);
97 virtual long GetInsertionPoint(void) const;
98 virtual wxTextPos
GetLastPosition(void) const;
100 virtual void SetSelection( long lFrom
103 virtual void SetEditable(bool bEditable
);
104 virtual void SetWindowStyleFlag(long lStyle
);
106 // implement base class pure virtuals
107 // ----------------------------------
109 virtual bool IsModified() const;
110 virtual bool IsEditable(void) const;
113 // apply text attribute to the range of text (only works with richedit
115 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
116 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
117 virtual bool GetStyle(long position
, wxTextAttr
& style
);
118 #endif // wxUSE_RICHEDIT
120 // translate between the position (which is just an index in the text ctrl
121 // considering all its contents as a single strings) and (x, y) coordinates
122 // which represent column and line.
123 virtual long XYToPosition(long x
, long y
) const;
124 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
126 virtual void ShowPosition(long pos
);
127 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
128 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
130 wxTextCoord
*row
) const
132 return wxTextCtrlBase::HitTest(pt
, col
, row
);
135 // Caret handling (Windows only)
136 bool ShowNativeCaret(bool show
= true);
137 bool HideNativeCaret() { return ShowNativeCaret(false); }
139 // Implementation from now on
140 // --------------------------
142 #if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
143 virtual void SetDropTarget(wxDropTarget
*dropTarget
);
144 #endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
146 virtual void Command(wxCommandEvent
& event
);
150 int GetRichVersion() const { return m_verRichEdit
; }
151 bool IsRich() const { return m_verRichEdit
!= 0; }
153 // rich edit controls are not compatible with normal ones and wem ust set
154 // the colours for them otherwise
155 virtual bool SetBackgroundColour(const wxColour
& colour
);
156 virtual bool SetForegroundColour(const wxColour
& colour
);
158 bool IsRich() const { return false; }
159 #endif // wxUSE_RICHEDIT
161 #if wxUSE_INKEDIT && wxUSE_RICHEDIT
162 bool IsInkEdit() const { return m_isInkEdit
!= 0; }
164 bool IsInkEdit() const { return false; }
167 virtual void AdoptAttributesFromHWND();
169 virtual bool AcceptsFocusFromKeyboard() const;
171 // returns true if the platform should explicitly apply a theme border
172 virtual bool CanApplyThemeBorder() const;
175 void OnDropFiles(wxDropFilesEvent
& event
);
176 void OnChar(wxKeyEvent
& event
); // Process 'enter' if required
178 void OnCut(wxCommandEvent
& event
);
179 void OnCopy(wxCommandEvent
& event
);
180 void OnPaste(wxCommandEvent
& event
);
181 void OnUndo(wxCommandEvent
& event
);
182 void OnRedo(wxCommandEvent
& event
);
183 void OnDelete(wxCommandEvent
& event
);
184 void OnSelectAll(wxCommandEvent
& event
);
186 void OnUpdateCut(wxUpdateUIEvent
& event
);
187 void OnUpdateCopy(wxUpdateUIEvent
& event
);
188 void OnUpdatePaste(wxUpdateUIEvent
& event
);
189 void OnUpdateUndo(wxUpdateUIEvent
& event
);
190 void OnUpdateRedo(wxUpdateUIEvent
& event
);
191 void OnUpdateDelete(wxUpdateUIEvent
& event
);
192 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
194 // Show a context menu for Rich Edit controls (the standard
195 // EDIT control has one already)
196 void OnContextMenu(wxContextMenuEvent
& event
);
198 // be sure the caret remains invisible if the user
199 // called HideNativeCaret() before
200 void OnSetFocus(wxFocusEvent
& event
);
202 virtual wxVisualAttributes
GetDefaultAttributes() const;
205 // common part of all ctors
208 virtual bool DoLoadFile(const wxString
& file
, int fileType
);
210 // creates the control of appropriate class (plain or rich edit) with the
211 // styles corresponding to m_windowStyle
213 // this is used by ctor/Create() and when we need to recreate the control
215 bool MSWCreateText(const wxString
& value
,
219 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
221 // return true if this control has a user-set limit on amount of text (i.e.
222 // the limit is due to a previous call to SetMaxLength() and not built in)
223 bool HasSpaceLimit(unsigned int *len
) const;
225 // call this to increase the size limit (will do nothing if the current
226 // limit is big enough)
228 // returns true if we increased the limit to allow entering more text,
229 // false if we hit the limit set by SetMaxLength() and so didn't change it
230 bool AdjustSpaceLimit();
232 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
233 // replace the selection or the entire control contents with the given text
234 // in the specified encoding
235 bool StreamIn(const wxString
& value
, wxFontEncoding encoding
, bool selOnly
);
237 // get the contents of the control out as text in the given encoding
238 wxString
StreamOut(wxFontEncoding encoding
, bool selOnly
= false) const;
239 #endif // wxUSE_RICHEDIT
241 // replace the contents of the selection or of the entire control with the
243 void DoWriteText(const wxString
& text
,
244 int flags
= SetValue_SendEvent
| SetValue_SelectionOnly
);
246 // set the selection (possibly without scrolling the caret into view)
247 void DoSetSelection(long from
, long to
, int flags
);
249 // get the length of the line containing the character at the given
251 long GetLengthOfLineContainingPos(long pos
) const;
253 // send TEXT_UPDATED event, return true if it was handled, false otherwise
254 bool SendUpdateEvent();
256 virtual wxSize
DoGetBestSize() const;
259 // we're using RICHEDIT (and not simple EDIT) control if this field is not
260 // 0, it also gives the version of the RICHEDIT control being used (1, 2 or
263 #endif // wxUSE_RICHEDIT
265 // number of EN_UPDATE events sent by Windows when we change the controls
266 // text ourselves: we want this to be exactly 1
270 virtual void EnableTextChangedEvents(bool enable
)
272 m_updatesCount
= enable
? -1 : -2;
275 // implement wxTextEntry pure virtual: it implements all the operations for
276 // the simple EDIT controls
277 virtual WXHWND
GetEditHWND() const { return m_hWnd
; }
279 DECLARE_EVENT_TABLE()
280 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl
)
282 wxMenu
* m_privateContextMenu
;
284 bool m_isNativeCaretShown
;
286 #if wxUSE_INKEDIT && wxUSE_RICHEDIT