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