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