]>
Commit | Line | Data |
---|---|---|
8cf73271 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: textctrl.h | |
3 | // Purpose: wxTextCtrl class | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
65571936 | 9 | // Licence: wxWindows licence |
8cf73271 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_TEXTCTRL_H_ | |
13 | #define _WX_TEXTCTRL_H_ | |
14 | ||
15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
16 | #pragma interface "textctrl.h" | |
17 | #endif | |
18 | ||
823c4e96 SC |
19 | #if wxUSE_SYSTEM_OPTIONS |
20 | // set this to true if you want to use the 'classic' mlte based implementation | |
21 | // instead of the HIView based implementation in 10.3 and upwards, the former | |
22 | // has more features (backgrounds etc.) but may show redraw artefacts and other | |
23 | // problems depending on your usage, default is 'false' | |
24 | #define wxMAC_TEXTCONTROL_USE_MLTE _T("mac.textcontrol-use-mlte") | |
25 | #endif | |
26 | ||
8cf73271 SC |
27 | #include "wx/control.h" |
28 | ||
29 | WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr; | |
30 | ||
5ca0d812 SC |
31 | class wxMacTextControl ; |
32 | ||
8cf73271 SC |
33 | // Single-line text item |
34 | class WXDLLEXPORT wxTextCtrl: public wxTextCtrlBase | |
35 | { | |
36 | DECLARE_DYNAMIC_CLASS(wxTextCtrl) | |
7d8268a1 | 37 | |
8cf73271 SC |
38 | public: |
39 | // creation | |
40 | // -------- | |
41 | wxTextCtrl() { Init(); } | |
42 | ~wxTextCtrl(); | |
43 | wxTextCtrl(wxWindow *parent, wxWindowID id, | |
44 | const wxString& value = wxEmptyString, | |
45 | const wxPoint& pos = wxDefaultPosition, | |
46 | const wxSize& size = wxDefaultSize, long style = 0, | |
47 | const wxValidator& validator = wxDefaultValidator, | |
48 | const wxString& name = wxTextCtrlNameStr) | |
49 | { | |
50 | Init(); | |
51 | ||
52 | Create(parent, id, value, pos, size, style, validator, name); | |
53 | } | |
7d8268a1 | 54 | |
8cf73271 SC |
55 | bool Create(wxWindow *parent, wxWindowID id, |
56 | const wxString& value = wxEmptyString, | |
57 | const wxPoint& pos = wxDefaultPosition, | |
58 | const wxSize& size = wxDefaultSize, long style = 0, | |
59 | const wxValidator& validator = wxDefaultValidator, | |
60 | const wxString& name = wxTextCtrlNameStr); | |
7d8268a1 | 61 | |
8cf73271 SC |
62 | // accessors |
63 | // --------- | |
64 | virtual wxString GetValue() const ; | |
65 | virtual void SetValue(const wxString& value); | |
66 | ||
67 | virtual int GetLineLength(long lineNo) const; | |
68 | virtual wxString GetLineText(long lineNo) const; | |
69 | virtual int GetNumberOfLines() const; | |
70 | ||
71 | virtual bool IsModified() const; | |
72 | virtual bool IsEditable() const; | |
73 | ||
74 | // If the return values from and to are the same, there is no selection. | |
75 | virtual void GetSelection(long* from, long* to) const; | |
76 | ||
77 | // operations | |
78 | // ---------- | |
79 | ||
80 | // editing | |
81 | ||
82 | virtual void Clear(); | |
83 | virtual void Replace(long from, long to, const wxString& value); | |
84 | virtual void Remove(long from, long to); | |
85 | ||
86 | // load the controls contents from the file | |
87 | virtual bool LoadFile(const wxString& file); | |
88 | ||
89 | // sets/clears the dirty flag | |
90 | virtual void MarkDirty(); | |
91 | virtual void DiscardEdits(); | |
92 | ||
93 | // set the max number of characters which may be entered in a single line | |
94 | // text control | |
95 | virtual void SetMaxLength(unsigned long len) ; | |
96 | ||
97 | // text control under some platforms supports the text styles: these | |
98 | // methods allow to apply the given text style to the given selection or to | |
99 | // set/get the style which will be used for all appended text | |
4f305456 | 100 | virtual bool SetFont( const wxFont &font ) ; |
8cf73271 SC |
101 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); |
102 | virtual bool SetDefaultStyle(const wxTextAttr& style); | |
103 | ||
104 | // writing text inserts it at the current position, appending always | |
105 | // inserts it at the end | |
106 | virtual void WriteText(const wxString& text); | |
107 | virtual void AppendText(const wxString& text); | |
108 | ||
109 | // translate between the position (which is just an index in the text ctrl | |
110 | // considering all its contents as a single strings) and (x, y) coordinates | |
111 | // which represent column and line. | |
112 | virtual long XYToPosition(long x, long y) const; | |
113 | virtual bool PositionToXY(long pos, long *x, long *y) const; | |
114 | ||
115 | virtual void ShowPosition(long pos); | |
116 | ||
117 | // Clipboard operations | |
118 | virtual void Copy(); | |
119 | virtual void Cut(); | |
120 | virtual void Paste(); | |
7d8268a1 | 121 | |
8cf73271 SC |
122 | virtual bool CanCopy() const; |
123 | virtual bool CanCut() const; | |
124 | virtual bool CanPaste() const; | |
125 | ||
126 | // Undo/redo | |
127 | virtual void Undo(); | |
128 | virtual void Redo(); | |
129 | ||
130 | virtual bool CanUndo() const; | |
131 | virtual bool CanRedo() const; | |
132 | ||
133 | // Insertion point | |
134 | virtual void SetInsertionPoint(long pos); | |
135 | virtual void SetInsertionPointEnd(); | |
136 | virtual long GetInsertionPoint() const; | |
7d8268a1 | 137 | virtual wxTextPos GetLastPosition() const; |
8cf73271 SC |
138 | |
139 | virtual void SetSelection(long from, long to); | |
140 | virtual void SetEditable(bool editable); | |
141 | ||
142 | // Implementation from now on | |
143 | // -------------------------- | |
144 | ||
145 | // Implementation | |
146 | // -------------- | |
147 | virtual void Command(wxCommandEvent& event); | |
148 | ||
149 | virtual bool AcceptsFocus() const; | |
150 | ||
151 | // callbacks | |
152 | void OnDropFiles(wxDropFilesEvent& event); | |
153 | void OnChar(wxKeyEvent& event); // Process 'enter' if required | |
154 | ||
155 | void OnCut(wxCommandEvent& event); | |
156 | void OnCopy(wxCommandEvent& event); | |
157 | void OnPaste(wxCommandEvent& event); | |
158 | void OnUndo(wxCommandEvent& event); | |
159 | void OnRedo(wxCommandEvent& event); | |
03e4ffc3 SC |
160 | void OnDelete(wxCommandEvent& event); |
161 | void OnSelectAll(wxCommandEvent& event); | |
162 | ||
8cf73271 SC |
163 | void OnUpdateCut(wxUpdateUIEvent& event); |
164 | void OnUpdateCopy(wxUpdateUIEvent& event); | |
165 | void OnUpdatePaste(wxUpdateUIEvent& event); | |
166 | void OnUpdateUndo(wxUpdateUIEvent& event); | |
167 | void OnUpdateRedo(wxUpdateUIEvent& event); | |
03e4ffc3 SC |
168 | void OnUpdateDelete(wxUpdateUIEvent& event); |
169 | void OnUpdateSelectAll(wxUpdateUIEvent& event); | |
7d8268a1 | 170 | |
7ea087b7 | 171 | void OnEraseBackground(wxEraseEvent& event) ; |
03e4ffc3 | 172 | void OnContextMenu(wxContextMenuEvent& event); |
8cf73271 | 173 | |
4f305456 | 174 | virtual bool MacCanFocus() const { return true ; } |
8cf73271 SC |
175 | virtual bool MacSetupCursor( const wxPoint& pt ) ; |
176 | ||
4f305456 SC |
177 | virtual void MacVisibilityChanged() ; |
178 | virtual void MacEnabledStateChanged() ; | |
89a66f11 | 179 | virtual void MacSuperChangedPosition() ; |
20b69855 | 180 | #ifndef __WXMAC_OSX__ |
4f305456 SC |
181 | virtual void MacControlUserPaneDrawProc(wxInt16 part) ; |
182 | virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; | |
183 | virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ; | |
184 | virtual void MacControlUserPaneIdleProc() ; | |
185 | virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ; | |
186 | virtual void MacControlUserPaneActivateProc(bool activating) ; | |
187 | virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; | |
188 | virtual void MacControlUserPaneBackgroundProc(void* info) ; | |
20b69855 | 189 | #endif |
8cf73271 | 190 | |
5ca0d812 | 191 | wxMacTextControl* GetPeer() const { return (wxMacTextControl*) m_peer ; } |
8cf73271 SC |
192 | protected: |
193 | // common part of all ctors | |
194 | void Init(); | |
195 | ||
6d4c54a7 | 196 | virtual wxSize DoGetBestSize() const; |
8cf73271 SC |
197 | |
198 | bool m_editable ; | |
199 | ||
200 | // flag is set to true when the user edits the controls contents | |
201 | bool m_dirty; | |
202 | ||
8cf73271 | 203 | unsigned long m_maxLength ; |
4f305456 | 204 | // need to make this public because of the current implementation via callbacks |
4f305456 | 205 | private : |
03e4ffc3 SC |
206 | wxMenu *m_privateContextMenu; |
207 | ||
8cf73271 SC |
208 | DECLARE_EVENT_TABLE() |
209 | }; | |
210 | ||
211 | #endif | |
212 | // _WX_TEXTCTRL_H_ |