]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: textctrl.cpp | |
3 | // Purpose: wxTextCtrl | |
a31a5f85 | 4 | // Author: Stefan Csomor |
6af16761 | 5 | // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "textctrl.h" |
14 | #endif | |
15 | ||
3d1a4878 | 16 | #include "wx/wxprec.h" |
fedad417 GD |
17 | |
18 | #if wxUSE_TEXTCTRL | |
19 | ||
5ca0d812 | 20 | |
f5c6eb5c | 21 | #ifdef __DARWIN__ |
03e11df5 GD |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | |
e9576ca5 | 24 | #else |
03e11df5 | 25 | #include <stat.h> |
e9576ca5 | 26 | #endif |
2b5f62a0 | 27 | |
3a05d58d SC |
28 | #include "wx/msgdlg.h" |
29 | ||
2b5f62a0 VZ |
30 | #if wxUSE_STD_IOSTREAM |
31 | #if wxUSE_IOSTREAMH | |
32 | #include <fstream.h> | |
33 | #else | |
34 | #include <fstream> | |
35 | #endif | |
36 | #endif | |
e9576ca5 | 37 | |
03e11df5 | 38 | #include "wx/app.h" |
5fde6fcc | 39 | #include "wx/dc.h" |
03e11df5 | 40 | #include "wx/button.h" |
422644a3 | 41 | #include "wx/toplevel.h" |
e9576ca5 | 42 | #include "wx/textctrl.h" |
90b22aca SC |
43 | #include "wx/notebook.h" |
44 | #include "wx/tabctrl.h" | |
e9576ca5 SC |
45 | #include "wx/settings.h" |
46 | #include "wx/filefn.h" | |
47 | #include "wx/utils.h" | |
48 | ||
49 | #if defined(__BORLANDC__) && !defined(__WIN32__) | |
03e11df5 | 50 | #include <alloc.h> |
f5c6eb5c | 51 | #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__) |
03e11df5 | 52 | #include <malloc.h> |
e9576ca5 SC |
53 | #endif |
54 | ||
66a09d47 SC |
55 | #ifndef __DARWIN__ |
56 | #include <Scrap.h> | |
1b2b1638 | 57 | #endif |
3556e470 | 58 | |
3527e532 SC |
59 | // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used |
60 | // if set to 0 then the unicode textctrl will be used | |
3556e470 | 61 | #ifndef wxMAC_AWAYS_USE_MLTE |
7a926300 | 62 | #define wxMAC_AWAYS_USE_MLTE 1 |
3556e470 SC |
63 | #endif |
64 | ||
0f7817ab SC |
65 | #ifndef __WXMAC_OSX__ |
66 | enum | |
67 | { | |
68 | kTXNVisibilityTag = 'visb' /*set the visibility state of the object */ | |
69 | }; | |
70 | #endif | |
71 | ||
1b2b1638 | 72 | #include <MacTextEditor.h> |
7688f0a1 SC |
73 | #include <ATSUnicode.h> |
74 | #include <TextCommon.h> | |
75 | #include <TextEncodingConverter.h> | |
1b2b1638 | 76 | #include "wx/mac/uma.h" |
72055702 | 77 | |
5ca0d812 | 78 | class wxMacFunctor |
587bc950 | 79 | { |
7d8268a1 | 80 | public : |
5ca0d812 SC |
81 | wxMacFunctor(){} |
82 | virtual ~wxMacFunctor() {} | |
83 | virtual void* operator()() = 0 ; | |
7d8268a1 | 84 | static void* CallBackProc(void *param) |
587bc950 | 85 | { |
5ca0d812 SC |
86 | wxMacFunctor* f = (wxMacFunctor*) param ; |
87 | void *result = (*f)() ; | |
88 | return result ; | |
587bc950 | 89 | } |
5ca0d812 | 90 | } ; |
587bc950 | 91 | |
5ca0d812 SC |
92 | template<typename classtype,typename param1type> |
93 | class wxMacObjectFunctor1 : public wxMacFunctor | |
587bc950 | 94 | { |
5ca0d812 SC |
95 | typedef void (classtype::*function)( param1type p1 ) ; |
96 | typedef void (classtype::*ref_function)( const param1type& p1 ) ; | |
7d8268a1 | 97 | public : |
5ca0d812 SC |
98 | wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) : |
99 | wxMacFunctor( ) | |
587bc950 | 100 | { |
5ca0d812 SC |
101 | m_object = obj ; |
102 | m_function = f ; | |
103 | m_param1 = p1 ; | |
587bc950 | 104 | } |
587bc950 | 105 | |
5ca0d812 SC |
106 | wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) : |
107 | wxMacFunctor( ) | |
108 | { | |
109 | m_object = obj ; | |
110 | m_refFunction = f ; | |
111 | m_param1 = p1 ; | |
112 | } | |
587bc950 | 113 | |
5ca0d812 | 114 | ~wxMacObjectFunctor1() {} |
7d8268a1 WS |
115 | |
116 | virtual void* operator()() | |
587bc950 | 117 | { |
5ca0d812 SC |
118 | (m_object->*m_function)(m_param1) ; |
119 | return NULL ; | |
120 | } | |
121 | private : | |
122 | classtype* m_object ; | |
123 | param1type m_param1 ; | |
124 | union | |
125 | { | |
126 | function m_function ; | |
127 | ref_function m_refFunction ; | |
587bc950 | 128 | } ; |
5ca0d812 | 129 | } ; |
587bc950 | 130 | |
7d8268a1 | 131 | template<typename classtype, typename param1type> |
5ca0d812 SC |
132 | void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) |
133 | { | |
7d8268a1 WS |
134 | wxMacObjectFunctor1<classtype,param1type> params(object,function,p1) ; |
135 | void *result = | |
5ca0d812 SC |
136 | MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; |
137 | return result ; | |
138 | } | |
587bc950 | 139 | |
7d8268a1 | 140 | template<typename classtype, typename param1type> |
5ca0d812 SC |
141 | void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) |
142 | { | |
7d8268a1 WS |
143 | wxMacObjectFunctor1<classtype,param1type> params(object,function,p1) ; |
144 | void *result = | |
5ca0d812 SC |
145 | MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; |
146 | return result ; | |
587bc950 SC |
147 | } |
148 | ||
7d8268a1 | 149 | template<typename classtype, typename param1type> |
5ca0d812 SC |
150 | void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) |
151 | { | |
152 | wxMutexGuiLeave() ; | |
153 | void *result = wxMacMPRemoteCall( object , function , p1 ) ; | |
154 | wxMutexGuiEnter() ; | |
155 | return result ; | |
156 | } | |
29b30405 | 157 | |
7d8268a1 | 158 | template<typename classtype, typename param1type> |
5ca0d812 SC |
159 | void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) |
160 | { | |
161 | wxMutexGuiLeave() ; | |
162 | void *result = wxMacMPRemoteCall( object , function , p1 ) ; | |
163 | wxMutexGuiEnter() ; | |
164 | return result ; | |
165 | } | |
166 | // common interface for all implementations | |
167 | class wxMacTextControl : public wxMacControl | |
168 | { | |
169 | public : | |
0f7817ab | 170 | wxMacTextControl( wxTextCtrl *peer ) ; |
5ca0d812 | 171 | ~wxMacTextControl() ; |
7d8268a1 | 172 | |
5ca0d812 SC |
173 | virtual wxString GetStringValue() const = 0 ; |
174 | virtual void SetStringValue( const wxString &val ) = 0 ; | |
175 | virtual void SetStyle(long start, long end, const wxTextAttr& style) ; | |
176 | virtual void Copy() ; | |
177 | virtual void Cut() ; | |
178 | virtual void Paste() ; | |
179 | virtual bool CanPaste() const ; | |
180 | virtual void SetEditable(bool editable) ; | |
7d8268a1 | 181 | virtual wxTextPos GetLastPosition() const ; |
5ca0d812 SC |
182 | virtual void Replace( long from , long to , const wxString str ) ; |
183 | virtual void Remove( long from , long to ) = 0 ; | |
184 | virtual void SetSelection( long from , long to ) = 0 ; | |
185 | virtual void GetSelection( long* from, long* to) const = 0 ; | |
186 | virtual void WriteText(const wxString& str) = 0 ; | |
187 | ||
188 | virtual void Clear() ; | |
189 | virtual bool CanUndo() const; | |
7d8268a1 | 190 | virtual void Undo() ; |
5ca0d812 SC |
191 | virtual bool CanRedo() const; |
192 | virtual void Redo() ; | |
193 | virtual int GetNumberOfLines() const ; | |
194 | virtual long XYToPosition(long x, long y) const; | |
195 | virtual bool PositionToXY(long pos, long *x, long *y) const ; | |
196 | virtual void ShowPosition( long WXUNUSED(pos) ) ; | |
197 | virtual int GetLineLength(long lineNo) const ; | |
198 | virtual wxString GetLineText(long lineNo) const ; | |
f2c3f2a8 | 199 | virtual bool SetupCursor( const wxPoint& pt ) { return false ; } |
24260aae SC |
200 | |
201 | #ifndef __WXMAC_OSX__ | |
202 | virtual void MacControlUserPaneDrawProc(wxInt16 part) = 0 ; | |
203 | virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) = 0 ; | |
204 | virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) = 0 ; | |
205 | virtual void MacControlUserPaneIdleProc() = 0 ; | |
206 | virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) = 0 ; | |
207 | virtual void MacControlUserPaneActivateProc(bool activating) = 0 ; | |
208 | virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) = 0 ; | |
209 | virtual void MacControlUserPaneBackgroundProc(void* info) = 0 ; | |
210 | #endif | |
5ca0d812 | 211 | } ; |
72055702 | 212 | |
5ca0d812 | 213 | // common parts for implementations based on MLTE |
72055702 | 214 | |
5ca0d812 SC |
215 | class wxMacMLTEControl : public wxMacTextControl |
216 | { | |
217 | public : | |
789ae0cf | 218 | wxMacMLTEControl( wxTextCtrl *peer ) ; |
5ca0d812 SC |
219 | virtual wxString GetStringValue() const ; |
220 | virtual void SetStringValue( const wxString &str) ; | |
7d8268a1 | 221 | |
5ca0d812 SC |
222 | static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ; |
223 | void AdjustCreationAttributes( const wxColour& background , bool visible ) ; | |
224 | ||
225 | virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ; | |
7ea087b7 | 226 | virtual void SetBackground( const wxBrush &brush) ; |
5ca0d812 SC |
227 | virtual void SetStyle(long start, long end, const wxTextAttr& style) ; |
228 | virtual void Copy() ; | |
229 | virtual void Cut() ; | |
230 | virtual void Paste() ; | |
231 | virtual bool CanPaste() const ; | |
232 | virtual void SetEditable(bool editable) ; | |
7d8268a1 | 233 | virtual wxTextPos GetLastPosition() const ; |
5ca0d812 SC |
234 | virtual void Replace( long from , long to , const wxString str ) ; |
235 | virtual void Remove( long from , long to ) ; | |
236 | virtual void GetSelection( long* from, long* to) const ; | |
237 | virtual void SetSelection( long from , long to ) ; | |
7d8268a1 | 238 | |
5ca0d812 SC |
239 | virtual void WriteText(const wxString& str) ; |
240 | virtual void Clear() ; | |
241 | ||
242 | virtual bool CanUndo() const ; | |
243 | virtual void Undo() ; | |
244 | virtual bool CanRedo() const; | |
245 | virtual void Redo() ; | |
246 | virtual int GetNumberOfLines() const ; | |
247 | virtual long XYToPosition(long x, long y) const ; | |
248 | virtual bool PositionToXY(long pos, long *x, long *y) const ; | |
249 | virtual void ShowPosition( long pos ) ; | |
250 | virtual int GetLineLength(long lineNo) const ; | |
251 | virtual wxString GetLineText(long lineNo) const ; | |
252 | ||
253 | void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ; | |
254 | ||
255 | protected : | |
8623a883 | 256 | void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ; |
5ca0d812 SC |
257 | TXNObject m_txn ; |
258 | } ; | |
72055702 | 259 | |
5ca0d812 | 260 | #if TARGET_API_MAC_OSX |
72055702 | 261 | |
5ca0d812 SC |
262 | // implementation available under OSX |
263 | ||
788e118f SC |
264 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
265 | ||
7d8268a1 | 266 | class wxMacMLTEHIViewControl : public wxMacMLTEControl |
5ca0d812 SC |
267 | { |
268 | public : | |
0f7817ab | 269 | wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
270 | const wxString& str, |
271 | const wxPoint& pos, | |
272 | const wxSize& size, long style ) ; | |
273 | virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; | |
274 | virtual bool HasFocus() const ; | |
5ca0d812 SC |
275 | protected : |
276 | HIViewRef m_scrollView ; | |
277 | HIViewRef m_textView ; | |
278 | } ; | |
ef4a634b | 279 | |
788e118f SC |
280 | #endif |
281 | ||
5ca0d812 SC |
282 | class wxMacUnicodeTextControl : public wxMacTextControl |
283 | { | |
284 | public : | |
0f7817ab | 285 | wxMacUnicodeTextControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
286 | const wxString& str, |
287 | const wxPoint& pos, | |
288 | const wxSize& size, long style ) ; | |
289 | ~wxMacUnicodeTextControl(); | |
290 | virtual void VisibilityChanged(bool shown); | |
291 | virtual wxString GetStringValue() const ; | |
292 | virtual void SetStringValue( const wxString &str) ; | |
293 | virtual void Copy(); | |
294 | virtual void Cut(); | |
295 | virtual void Paste(); | |
296 | virtual bool CanPaste() const; | |
297 | virtual void SetEditable(bool editable) ; | |
298 | virtual void Remove( long from , long to ) ; | |
299 | virtual void GetSelection( long* from, long* to) const ; | |
300 | virtual void SetSelection( long from , long to ) ; | |
301 | virtual void WriteText(const wxString& str) ; | |
302 | protected : | |
303 | // contains the tag for the content (is different for password and non-password controls) | |
304 | OSType m_valueTag ; | |
305 | } ; | |
72055702 | 306 | |
3556e470 | 307 | #endif |
72055702 | 308 | |
24260aae | 309 | // 'classic' MLTE implementation |
72055702 | 310 | |
5ca0d812 SC |
311 | class wxMacMLTEClassicControl : public wxMacMLTEControl |
312 | { | |
313 | public : | |
0f7817ab | 314 | wxMacMLTEClassicControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
315 | const wxString& str, |
316 | const wxPoint& pos, | |
317 | const wxSize& size, long style ) ; | |
318 | ~wxMacMLTEClassicControl() ; | |
319 | virtual void VisibilityChanged(bool shown) ; | |
4e477040 | 320 | virtual void SuperChangedPosition() ; |
24260aae SC |
321 | |
322 | virtual void MacControlUserPaneDrawProc(wxInt16 part) ; | |
323 | virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; | |
324 | virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ; | |
325 | virtual void MacControlUserPaneIdleProc() ; | |
326 | virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ; | |
327 | virtual void MacControlUserPaneActivateProc(bool activating) ; | |
328 | virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; | |
329 | virtual void MacControlUserPaneBackgroundProc(void* info) ; | |
330 | ||
f2c3f2a8 SC |
331 | virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) { MacControlUserPaneIdleProc() ; return true ;} |
332 | ||
0f7817ab SC |
333 | virtual void SetRect( Rect *r ) ; |
334 | ||
5ca0d812 SC |
335 | protected : |
336 | OSStatus DoCreate(); | |
0f7817ab SC |
337 | |
338 | void MacUpdatePosition() ; | |
339 | void MacActivatePaneText(Boolean setActive) ; | |
340 | void MacFocusPaneText(Boolean setFocus) ; | |
341 | ||
342 | void MacSetObjectVisibility(Boolean vis) ; | |
343 | private : | |
344 | TXNFrameID m_txnFrameID ; | |
345 | GrafPtr m_txnPort ; | |
5de694f0 | 346 | WindowRef m_txnWindow ; |
0f7817ab SC |
347 | // bounds of the control as we last did set the txn frames |
348 | Rect m_txnControlBounds ; | |
349 | ||
4e477040 | 350 | #ifdef __WXMAC_OSX__ |
5de694f0 SC |
351 | static pascal void TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, |
352 | TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon) ; | |
353 | static pascal void TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) ; | |
4e477040 | 354 | ControlRef m_sbHorizontal ; |
5de694f0 | 355 | SInt32 m_lastHorizontalValue ; |
4e477040 | 356 | ControlRef m_sbVertical ; |
5de694f0 | 357 | SInt32 m_lastVerticalValue ; |
4e477040 | 358 | #endif |
5ca0d812 | 359 | } ; |
facd6764 | 360 | |
5ca0d812 | 361 | #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL |
72055702 | 362 | |
5ca0d812 SC |
363 | #if !USE_SHARED_LIBRARY |
364 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) | |
72055702 | 365 | |
5ca0d812 | 366 | BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) |
7ea087b7 | 367 | EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground ) |
5ca0d812 SC |
368 | EVT_DROP_FILES(wxTextCtrl::OnDropFiles) |
369 | EVT_CHAR(wxTextCtrl::OnChar) | |
370 | EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) | |
371 | EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) | |
372 | EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) | |
373 | EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) | |
374 | EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) | |
375 | ||
376 | EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) | |
377 | EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) | |
378 | EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) | |
379 | EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) | |
380 | EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) | |
381 | END_EVENT_TABLE() | |
382 | #endif | |
383 | ||
384 | // Text item | |
385 | void wxTextCtrl::Init() | |
facd6764 | 386 | { |
5ca0d812 SC |
387 | m_editable = true ; |
388 | m_dirty = false; | |
389 | ||
390 | m_maxLength = TE_UNLIMITED_LENGTH ; | |
facd6764 SC |
391 | } |
392 | ||
5ca0d812 | 393 | wxTextCtrl::~wxTextCtrl() |
facd6764 | 394 | { |
facd6764 SC |
395 | } |
396 | ||
ef4a634b | 397 | |
5ca0d812 SC |
398 | bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, |
399 | const wxString& str, | |
400 | const wxPoint& pos, | |
401 | const wxSize& size, long style, | |
402 | const wxValidator& validator, | |
403 | const wxString& name) | |
404 | { | |
7d8268a1 | 405 | m_macIsUserPane = false ; |
5ca0d812 SC |
406 | m_editable = true ; |
407 | ||
9c4e5c70 SC |
408 | if ( ! ( style & wxNO_BORDER) ) |
409 | style = ( style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; | |
7d8268a1 | 410 | |
5ca0d812 | 411 | if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) |
7d8268a1 | 412 | return false; |
ef4a634b | 413 | |
5ca0d812 | 414 | if ( m_windowStyle & wxTE_MULTILINE ) |
facd6764 | 415 | { |
5ca0d812 SC |
416 | wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER), |
417 | wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") ); | |
418 | ||
419 | m_windowStyle |= wxTE_PROCESS_ENTER; | |
420 | style |= wxTE_PROCESS_ENTER ; | |
ed8c2780 | 421 | } |
3556e470 | 422 | |
24260aae | 423 | #ifdef __WXMAC_OSX__ |
788e118f | 424 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
5de694f0 | 425 | if ( UMAGetSystemVersion() >= 0x1050 ) |
788e118f SC |
426 | { |
427 | m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; | |
428 | } | |
788e118f | 429 | #endif |
3556e470 SC |
430 | #if !wxMAC_AWAYS_USE_MLTE |
431 | if ( !m_peer ) | |
7d8268a1 | 432 | { |
788e118f SC |
433 | m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; |
434 | } | |
5ca0d812 | 435 | #endif |
3556e470 SC |
436 | #endif |
437 | if ( !m_peer ) | |
438 | { | |
3556e470 SC |
439 | m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; |
440 | } | |
788e118f | 441 | |
5ca0d812 | 442 | MacPostControlCreate(pos,size) ; |
72055702 | 443 | |
5ca0d812 SC |
444 | if ( m_windowStyle & wxTE_READONLY) |
445 | { | |
446 | SetEditable( false ) ; | |
447 | } | |
f2c3f2a8 SC |
448 | |
449 | SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; | |
72055702 | 450 | |
7d8268a1 | 451 | return true; |
facd6764 SC |
452 | } |
453 | ||
4e477040 SC |
454 | void wxTextCtrl::MacSuperChangedPosition() |
455 | { | |
456 | wxWindow::MacSuperChangedPosition() ; | |
457 | GetPeer()->SuperChangedPosition() ; | |
458 | } | |
459 | ||
7d8268a1 | 460 | void wxTextCtrl::MacVisibilityChanged() |
5ca0d812 SC |
461 | { |
462 | GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; | |
463 | } | |
facd6764 | 464 | |
7d8268a1 | 465 | void wxTextCtrl::MacEnabledStateChanged() |
5ca0d812 | 466 | { |
72055702 SC |
467 | } |
468 | ||
5ca0d812 SC |
469 | wxString wxTextCtrl::GetValue() const |
470 | { | |
471 | return GetPeer()->GetStringValue() ; | |
472 | } | |
ef4a634b | 473 | |
5ca0d812 | 474 | void wxTextCtrl::GetSelection(long* from, long* to) const |
7d8268a1 | 475 | { |
5ca0d812 SC |
476 | GetPeer()->GetSelection( from , to ) ; |
477 | } | |
478 | ||
479 | void wxTextCtrl::SetValue(const wxString& str) | |
480 | { | |
481 | // optimize redraws | |
482 | if ( GetValue() == str ) | |
facd6764 | 483 | return ; |
facd6764 | 484 | |
5ca0d812 | 485 | GetPeer()->SetStringValue(str) ; |
e8b4fd4b RD |
486 | |
487 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); | |
488 | event.SetString( GetValue() ) ; | |
489 | event.SetEventObject( this ); | |
490 | GetEventHandler()->ProcessEvent(event); | |
72055702 SC |
491 | } |
492 | ||
5ca0d812 SC |
493 | void wxTextCtrl::SetMaxLength(unsigned long len) |
494 | { | |
495 | m_maxLength = len ; | |
496 | } | |
72055702 | 497 | |
5ca0d812 SC |
498 | bool wxTextCtrl::SetFont( const wxFont& font ) |
499 | { | |
500 | if ( !wxTextCtrlBase::SetFont( font ) ) | |
7d8268a1 WS |
501 | return false ; |
502 | ||
5ca0d812 SC |
503 | GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; |
504 | return true ; | |
505 | } | |
506 | ||
507 | bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) | |
508 | { | |
509 | GetPeer()->SetStyle( start , end , style ) ; | |
510 | return true ; | |
511 | } | |
512 | ||
513 | bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) | |
514 | { | |
515 | wxTextCtrlBase::SetDefaultStyle( style ) ; | |
516 | SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; | |
7d8268a1 | 517 | return true ; |
5ca0d812 SC |
518 | } |
519 | ||
520 | // Clipboard operations | |
521 | void wxTextCtrl::Copy() | |
522 | { | |
523 | if (CanCopy()) | |
facd6764 | 524 | { |
7d8268a1 | 525 | GetPeer()->Copy() ; |
ed8c2780 | 526 | } |
72055702 SC |
527 | } |
528 | ||
5ca0d812 SC |
529 | void wxTextCtrl::Cut() |
530 | { | |
531 | if (CanCut()) | |
532 | { | |
7d8268a1 | 533 | GetPeer()->Cut() ; |
72055702 | 534 | |
5ca0d812 | 535 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); |
5ca0d812 SC |
536 | event.SetEventObject( this ); |
537 | GetEventHandler()->ProcessEvent(event); | |
538 | } | |
539 | } | |
72055702 | 540 | |
5ca0d812 SC |
541 | void wxTextCtrl::Paste() |
542 | { | |
543 | if (CanPaste()) | |
544 | { | |
7d8268a1 | 545 | GetPeer()->Paste() ; |
5ca0d812 | 546 | // eventually we should add setting the default style again |
72055702 | 547 | |
5ca0d812 | 548 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); |
5ca0d812 SC |
549 | event.SetEventObject( this ); |
550 | GetEventHandler()->ProcessEvent(event); | |
551 | } | |
552 | } | |
72055702 | 553 | |
5ca0d812 SC |
554 | bool wxTextCtrl::CanCopy() const |
555 | { | |
556 | // Can copy if there's a selection | |
557 | long from, to; | |
558 | GetSelection(& from, & to); | |
559 | return (from != to); | |
560 | } | |
ef4a634b | 561 | |
5ca0d812 SC |
562 | bool wxTextCtrl::CanCut() const |
563 | { | |
564 | if ( !IsEditable() ) | |
565 | { | |
566 | return false ; | |
ed8c2780 | 567 | } |
5ca0d812 SC |
568 | // Can cut if there's a selection |
569 | long from, to; | |
570 | GetSelection(& from, & to); | |
571 | return (from != to); | |
72055702 SC |
572 | } |
573 | ||
5ca0d812 SC |
574 | bool wxTextCtrl::CanPaste() const |
575 | { | |
576 | if (!IsEditable()) | |
7d8268a1 | 577 | return false; |
72055702 | 578 | |
5ca0d812 SC |
579 | return GetPeer()->CanPaste() ; |
580 | } | |
facd6764 | 581 | |
5ca0d812 SC |
582 | void wxTextCtrl::SetEditable(bool editable) |
583 | { | |
584 | if ( editable != m_editable ) | |
585 | { | |
586 | m_editable = editable ; | |
587 | GetPeer()->SetEditable( editable ) ; | |
ed8c2780 | 588 | } |
72055702 SC |
589 | } |
590 | ||
5ca0d812 SC |
591 | void wxTextCtrl::SetInsertionPoint(long pos) |
592 | { | |
593 | SetSelection( pos , pos ) ; | |
594 | } | |
72055702 | 595 | |
5ca0d812 SC |
596 | void wxTextCtrl::SetInsertionPointEnd() |
597 | { | |
7d8268a1 | 598 | wxTextPos pos = GetLastPosition(); |
5ca0d812 SC |
599 | SetInsertionPoint(pos); |
600 | } | |
facd6764 | 601 | |
5ca0d812 SC |
602 | long wxTextCtrl::GetInsertionPoint() const |
603 | { | |
604 | long begin,end ; | |
605 | GetSelection( &begin , &end ) ; | |
606 | return begin ; | |
607 | } | |
facd6764 | 608 | |
7d8268a1 | 609 | wxTextPos wxTextCtrl::GetLastPosition() const |
5ca0d812 SC |
610 | { |
611 | return GetPeer()->GetLastPosition( ) ; | |
72055702 SC |
612 | } |
613 | ||
5ca0d812 SC |
614 | void wxTextCtrl::Replace(long from, long to, const wxString& str) |
615 | { | |
616 | GetPeer()->Replace( from , to , str) ; | |
617 | } | |
72055702 | 618 | |
5ca0d812 SC |
619 | void wxTextCtrl::Remove(long from, long to) |
620 | { | |
621 | GetPeer()->Remove( from , to ) ; | |
622 | } | |
facd6764 | 623 | |
5ca0d812 SC |
624 | void wxTextCtrl::SetSelection(long from, long to) |
625 | { | |
626 | GetPeer()->SetSelection( from , to ) ; | |
627 | } | |
628 | ||
629 | bool wxTextCtrl::LoadFile(const wxString& file) | |
630 | { | |
631 | if ( wxTextCtrlBase::LoadFile(file) ) | |
facd6764 | 632 | { |
7d8268a1 | 633 | return true; |
ed8c2780 | 634 | } |
5ca0d812 | 635 | |
7d8268a1 | 636 | return false; |
72055702 SC |
637 | } |
638 | ||
5ca0d812 SC |
639 | void wxTextCtrl::WriteText(const wxString& str) |
640 | { | |
641 | // TODO this MPRemoting will be moved into a remoting peer proxy for any command | |
642 | if ( !wxIsMainThread() ) | |
643 | { | |
7d8268a1 | 644 | // unfortunately CW 8 is not able to correctly deduce the template types, so we have |
5ca0d812 SC |
645 | // to instantiate explicitely |
646 | wxMacMPRemoteGUICall<wxTextCtrl,wxString>( this , &wxTextCtrl::WriteText , str ) ; | |
647 | return ; | |
648 | } | |
649 | else | |
650 | { | |
651 | GetPeer()->WriteText( str ) ; | |
652 | } | |
653 | } | |
72055702 | 654 | |
5ca0d812 SC |
655 | void wxTextCtrl::AppendText(const wxString& text) |
656 | { | |
657 | SetInsertionPointEnd(); | |
658 | WriteText(text); | |
659 | } | |
facd6764 | 660 | |
5ca0d812 SC |
661 | void wxTextCtrl::Clear() |
662 | { | |
663 | GetPeer()->Clear() ; | |
664 | } | |
facd6764 | 665 | |
5ca0d812 SC |
666 | bool wxTextCtrl::IsModified() const |
667 | { | |
668 | return m_dirty; | |
669 | } | |
facd6764 | 670 | |
5ca0d812 SC |
671 | bool wxTextCtrl::IsEditable() const |
672 | { | |
673 | return IsEnabled() && m_editable ; | |
72055702 SC |
674 | } |
675 | ||
5ca0d812 SC |
676 | bool wxTextCtrl::AcceptsFocus() const |
677 | { | |
678 | // we don't want focus if we can't be edited | |
679 | return /*IsEditable() && */ wxControl::AcceptsFocus(); | |
680 | } | |
72055702 | 681 | |
5ca0d812 | 682 | wxSize wxTextCtrl::DoGetBestSize() const |
1b2b1638 | 683 | { |
5ca0d812 | 684 | int wText = 100 ; |
ef4a634b | 685 | |
5ca0d812 | 686 | int hText; |
ef4a634b | 687 | |
72463754 SC |
688 | // these are the numbers from the HIG, we reduce them by the borders |
689 | // first | |
690 | ||
5ca0d812 SC |
691 | switch( m_windowVariant ) |
692 | { | |
693 | case wxWINDOW_VARIANT_NORMAL : | |
72463754 | 694 | hText = 22 - 6 ; |
5ca0d812 SC |
695 | break ; |
696 | case wxWINDOW_VARIANT_SMALL : | |
72463754 | 697 | hText = 19 - 6 ; |
5ca0d812 SC |
698 | break ; |
699 | case wxWINDOW_VARIANT_MINI : | |
72463754 | 700 | hText= 15 - 6 ; |
5ca0d812 SC |
701 | break ; |
702 | default : | |
72463754 | 703 | hText = 22 - 6; |
7d8268a1 | 704 | break ; |
5ca0d812 | 705 | } |
72055702 | 706 | |
72463754 SC |
707 | // as the above numbers have some free space around the text |
708 | // we get 5 lines like this anyway | |
5ca0d812 SC |
709 | if ( m_windowStyle & wxTE_MULTILINE ) |
710 | { | |
711 | hText *= 5 ; | |
712 | } | |
ef4a634b | 713 | |
72463754 SC |
714 | if ( !HasFlag(wxNO_BORDER) ) |
715 | hText += 6 ; | |
716 | ||
5ca0d812 SC |
717 | return wxSize(wText, hText); |
718 | } | |
ef4a634b | 719 | |
5ca0d812 SC |
720 | // ---------------------------------------------------------------------------- |
721 | // Undo/redo | |
722 | // ---------------------------------------------------------------------------- | |
facd6764 | 723 | |
5ca0d812 SC |
724 | void wxTextCtrl::Undo() |
725 | { | |
726 | if (CanUndo()) | |
727 | { | |
728 | GetPeer()->Undo() ; | |
729 | } | |
72055702 SC |
730 | } |
731 | ||
5ca0d812 | 732 | void wxTextCtrl::Redo() |
587bc950 | 733 | { |
5ca0d812 SC |
734 | if (CanRedo()) |
735 | { | |
736 | GetPeer()->Redo() ; | |
737 | } | |
738 | } | |
1b2b1638 | 739 | |
5ca0d812 SC |
740 | bool wxTextCtrl::CanUndo() const |
741 | { | |
7d8268a1 | 742 | if ( !IsEditable() ) |
5ca0d812 | 743 | { |
7d8268a1 | 744 | return false ; |
5ca0d812 SC |
745 | } |
746 | return GetPeer()->CanUndo() ; | |
747 | } | |
72055702 | 748 | |
5ca0d812 | 749 | bool wxTextCtrl::CanRedo() const |
6bdd4f5d | 750 | { |
7d8268a1 | 751 | if ( !IsEditable() ) |
5ca0d812 | 752 | { |
7d8268a1 | 753 | return false ; |
5ca0d812 SC |
754 | } |
755 | return GetPeer()->CanRedo() ; | |
6bdd4f5d SC |
756 | } |
757 | ||
5ca0d812 SC |
758 | void wxTextCtrl::MarkDirty() |
759 | { | |
760 | m_dirty = true; | |
761 | } | |
587bc950 | 762 | |
5ca0d812 SC |
763 | void wxTextCtrl::DiscardEdits() |
764 | { | |
765 | m_dirty = false; | |
766 | } | |
587bc950 | 767 | |
5ca0d812 SC |
768 | int wxTextCtrl::GetNumberOfLines() const |
769 | { | |
770 | return GetPeer()->GetNumberOfLines() ; | |
771 | } | |
587bc950 | 772 | |
5ca0d812 SC |
773 | long wxTextCtrl::XYToPosition(long x, long y) const |
774 | { | |
775 | return GetPeer()->XYToPosition( x , y ) ; | |
776 | } | |
587bc950 | 777 | |
5ca0d812 | 778 | bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const |
72055702 | 779 | { |
5ca0d812 SC |
780 | return GetPeer()->PositionToXY(pos , x , y ) ; |
781 | } | |
1fa29bdc | 782 | |
5ca0d812 SC |
783 | void wxTextCtrl::ShowPosition(long pos) |
784 | { | |
785 | return GetPeer()->ShowPosition(pos) ; | |
786 | } | |
1fa29bdc | 787 | |
5ca0d812 SC |
788 | int wxTextCtrl::GetLineLength(long lineNo) const |
789 | { | |
790 | return GetPeer()->GetLineLength(lineNo) ; | |
1b2b1638 SC |
791 | } |
792 | ||
5ca0d812 | 793 | wxString wxTextCtrl::GetLineText(long lineNo) const |
1b2b1638 | 794 | { |
5ca0d812 | 795 | return GetPeer()->GetLineText(lineNo) ; |
72055702 SC |
796 | } |
797 | ||
5ca0d812 SC |
798 | /* |
799 | * Text item | |
800 | */ | |
72055702 | 801 | |
5ca0d812 | 802 | void wxTextCtrl::Command(wxCommandEvent & event) |
72055702 | 803 | { |
5ca0d812 SC |
804 | SetValue (event.GetString()); |
805 | ProcessCommand (event); | |
806 | } | |
72055702 | 807 | |
5ca0d812 SC |
808 | void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) |
809 | { | |
810 | // By default, load the first file into the text window. | |
811 | if (event.GetNumberOfFiles() > 0) | |
812 | { | |
813 | LoadFile(event.GetFiles()[0]); | |
814 | } | |
815 | } | |
ef4a634b | 816 | |
7ea087b7 SC |
817 | void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) |
818 | { | |
819 | // all erasing should be done by the real mac control implementation | |
820 | // while this is true for MLTE under classic, the HITextView is somehow | |
821 | // transparent but background erase is not working correctly, so intercept | |
822 | // things while we can... | |
395480fb | 823 | event.Skip() ; |
7ea087b7 SC |
824 | } |
825 | ||
5ca0d812 SC |
826 | void wxTextCtrl::OnChar(wxKeyEvent& event) |
827 | { | |
828 | int key = event.GetKeyCode() ; | |
829 | bool eat_key = false ; | |
72055702 | 830 | |
5ca0d812 | 831 | if ( key == 'c' && event.MetaDown() ) |
72055702 | 832 | { |
5ca0d812 SC |
833 | if ( CanCopy() ) |
834 | Copy() ; | |
835 | return ; | |
72055702 SC |
836 | } |
837 | ||
5ca0d812 SC |
838 | if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && |
839 | !( key == WXK_RETURN && ( (m_windowStyle & wxPROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) | |
840 | /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */ | |
841 | ) | |
29e4a190 | 842 | { |
5ca0d812 SC |
843 | // eat it |
844 | return ; | |
845 | } | |
d3016f30 | 846 | |
bdf0c19c KH |
847 | // Check if we have reached the max # of chars, but still allow navigation and deletion |
848 | if ( !IsMultiLine() && GetValue().Length() >= m_maxLength && | |
849 | key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && | |
850 | key != WXK_BACK && !( key == WXK_RETURN && (m_windowStyle & wxPROCESS_ENTER) ) | |
851 | ) | |
852 | { | |
853 | // eat it, we don't want to add more than allowed # of characters | |
854 | return; | |
855 | } | |
856 | ||
5ca0d812 SC |
857 | // assume that any key not processed yet is going to modify the control |
858 | m_dirty = true; | |
587bc950 | 859 | |
5ca0d812 SC |
860 | if ( key == 'v' && event.MetaDown() ) |
861 | { | |
862 | if ( CanPaste() ) | |
863 | Paste() ; | |
864 | return ; | |
29e4a190 | 865 | } |
5ca0d812 | 866 | if ( key == 'x' && event.MetaDown() ) |
ed8c2780 | 867 | { |
5ca0d812 SC |
868 | if ( CanCut() ) |
869 | Cut() ; | |
870 | return ; | |
1b2b1638 | 871 | } |
5ca0d812 SC |
872 | switch ( key ) |
873 | { | |
874 | case WXK_RETURN: | |
875 | if (m_windowStyle & wxPROCESS_ENTER) | |
876 | { | |
877 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
878 | event.SetEventObject( this ); | |
879 | event.SetString( GetValue() ); | |
880 | if ( GetEventHandler()->ProcessEvent(event) ) | |
881 | return; | |
882 | } | |
883 | if ( !(m_windowStyle & wxTE_MULTILINE) ) | |
884 | { | |
885 | wxWindow *parent = GetParent(); | |
886 | while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { | |
887 | parent = parent->GetParent() ; | |
888 | } | |
889 | if ( parent && parent->GetDefaultItem() ) | |
890 | { | |
891 | wxButton *def = wxDynamicCast(parent->GetDefaultItem(), | |
892 | wxButton); | |
893 | if ( def && def->IsEnabled() ) | |
894 | { | |
895 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
896 | event.SetEventObject(def); | |
897 | def->Command(event); | |
898 | return ; | |
899 | } | |
900 | } | |
901 | ||
902 | // this will make wxWidgets eat the ENTER key so that | |
903 | // we actually prevent line wrapping in a single line | |
904 | // text control | |
7d8268a1 | 905 | eat_key = true; |
5ca0d812 | 906 | } |
ef4a634b | 907 | |
5ca0d812 | 908 | break; |
facd6764 | 909 | |
5ca0d812 SC |
910 | case WXK_TAB: |
911 | if ( !(m_windowStyle & wxTE_PROCESS_TAB)) | |
912 | { | |
913 | int flags = 0; | |
914 | if (!event.ShiftDown()) | |
915 | flags |= wxNavigationKeyEvent::IsForward ; | |
916 | if (event.ControlDown()) | |
917 | flags |= wxNavigationKeyEvent::WinChange ; | |
918 | Navigate(flags); | |
919 | return; | |
920 | } | |
921 | else | |
922 | { | |
923 | // This is necessary (don't know why) or the tab will not | |
924 | // be inserted. | |
925 | WriteText(wxT("\t")); | |
926 | } | |
7d8268a1 | 927 | |
5ca0d812 SC |
928 | break; |
929 | } | |
facd6764 | 930 | |
5ca0d812 | 931 | if (!eat_key) |
7f1de2b2 | 932 | { |
5ca0d812 SC |
933 | // perform keystroke handling |
934 | if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) | |
935 | CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; | |
7d8268a1 | 936 | else |
5ca0d812 SC |
937 | { |
938 | EventRecord rec ; | |
939 | if ( wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ) | |
940 | { | |
941 | EventRecord *ev = &rec ; | |
942 | short keycode ; | |
943 | short keychar ; | |
944 | keychar = short(ev->message & charCodeMask); | |
945 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
946 | ||
947 | m_peer->HandleKey( keycode , keychar , ev->modifiers ) ; | |
948 | } | |
949 | } | |
7f1de2b2 | 950 | } |
5ca0d812 SC |
951 | if ( ( key >= 0x20 && key < WXK_START ) || |
952 | key == WXK_RETURN || | |
953 | key == WXK_DELETE || | |
954 | key == WXK_BACK) | |
7f1de2b2 | 955 | { |
5ca0d812 | 956 | wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); |
5ca0d812 SC |
957 | event1.SetEventObject( this ); |
958 | wxPostEvent(GetEventHandler(),event1); | |
7f1de2b2 | 959 | } |
5ca0d812 | 960 | } |
facd6764 | 961 | |
5ca0d812 SC |
962 | // ---------------------------------------------------------------------------- |
963 | // standard handlers for standard edit menu events | |
964 | // ---------------------------------------------------------------------------- | |
965 | ||
966 | void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) | |
967 | { | |
968 | Cut(); | |
72055702 SC |
969 | } |
970 | ||
5ca0d812 | 971 | void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 972 | { |
5ca0d812 SC |
973 | Copy(); |
974 | } | |
7f1de2b2 | 975 | |
5ca0d812 SC |
976 | void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) |
977 | { | |
978 | Paste(); | |
facd6764 SC |
979 | } |
980 | ||
5ca0d812 | 981 | void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 982 | { |
5ca0d812 | 983 | Undo(); |
facd6764 SC |
984 | } |
985 | ||
5ca0d812 SC |
986 | void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) |
987 | { | |
988 | Redo(); | |
989 | } | |
facd6764 | 990 | |
5ca0d812 | 991 | void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) |
72055702 | 992 | { |
5ca0d812 | 993 | event.Enable( CanCut() ); |
72055702 SC |
994 | } |
995 | ||
5ca0d812 SC |
996 | void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) |
997 | { | |
998 | event.Enable( CanCopy() ); | |
72055702 SC |
999 | } |
1000 | ||
5ca0d812 | 1001 | void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) |
72055702 | 1002 | { |
5ca0d812 | 1003 | event.Enable( CanPaste() ); |
72055702 SC |
1004 | } |
1005 | ||
5ca0d812 | 1006 | void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) |
29b30405 | 1007 | { |
5ca0d812 | 1008 | event.Enable( CanUndo() ); |
29b30405 SC |
1009 | } |
1010 | ||
5ca0d812 | 1011 | void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) |
facd6764 | 1012 | { |
5ca0d812 | 1013 | event.Enable( CanRedo() ); |
facd6764 SC |
1014 | } |
1015 | ||
5ca0d812 | 1016 | bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) |
29b30405 | 1017 | { |
f2c3f2a8 SC |
1018 | if ( !GetPeer()->SetupCursor(pt) ) |
1019 | return wxWindow::MacSetupCursor( pt ) ; | |
1020 | else | |
1021 | return true ; | |
5ca0d812 | 1022 | } |
20b69855 | 1023 | #if !TARGET_API_MAC_OSX |
24260aae | 1024 | |
5ca0d812 | 1025 | // user pane implementation |
ef4a634b | 1026 | |
7d8268a1 | 1027 | void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part) |
5ca0d812 | 1028 | { |
24260aae | 1029 | GetPeer()->MacControlUserPaneDrawProc( part ) ; |
29b30405 SC |
1030 | } |
1031 | ||
7d8268a1 | 1032 | wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
29b30405 | 1033 | { |
24260aae | 1034 | return GetPeer()->MacControlUserPaneHitTestProc( x , y ) ; |
29b30405 SC |
1035 | } |
1036 | ||
7d8268a1 | 1037 | wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) |
72055702 | 1038 | { |
24260aae | 1039 | return GetPeer()->MacControlUserPaneTrackingProc( x , y , actionProc ) ; |
72055702 SC |
1040 | } |
1041 | ||
7d8268a1 | 1042 | void wxTextCtrl::MacControlUserPaneIdleProc() |
72055702 | 1043 | { |
24260aae | 1044 | GetPeer()->MacControlUserPaneIdleProc( ) ; |
72055702 SC |
1045 | } |
1046 | ||
7d8268a1 | 1047 | wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
72055702 | 1048 | { |
24260aae | 1049 | return GetPeer()->MacControlUserPaneKeyDownProc( keyCode , charCode , modifiers ) ; |
72055702 SC |
1050 | } |
1051 | ||
7d8268a1 | 1052 | void wxTextCtrl::MacControlUserPaneActivateProc(bool activating) |
72055702 | 1053 | { |
24260aae | 1054 | GetPeer()->MacControlUserPaneActivateProc( activating ) ; |
72055702 SC |
1055 | } |
1056 | ||
7d8268a1 | 1057 | wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action) |
72055702 | 1058 | { |
24260aae | 1059 | return GetPeer()->MacControlUserPaneFocusProc( action ) ; |
72055702 SC |
1060 | } |
1061 | ||
7d8268a1 | 1062 | void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) |
72055702 | 1063 | { |
24260aae | 1064 | GetPeer()->MacControlUserPaneBackgroundProc( info ) ; |
5ca0d812 | 1065 | } |
24260aae | 1066 | |
20b69855 | 1067 | #endif |
5ca0d812 SC |
1068 | // ---------------------------------------------------------------------------- |
1069 | // implementation base class | |
1070 | // ---------------------------------------------------------------------------- | |
1071 | ||
0f7817ab SC |
1072 | wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : |
1073 | wxMacControl( peer ) | |
5ca0d812 | 1074 | { |
72055702 SC |
1075 | } |
1076 | ||
7d8268a1 | 1077 | wxMacTextControl::~wxMacTextControl() |
72055702 | 1078 | { |
72055702 SC |
1079 | } |
1080 | ||
7d8268a1 | 1081 | void wxMacTextControl::SetStyle(long start, long end, const wxTextAttr& style) |
72055702 | 1082 | { |
72055702 SC |
1083 | } |
1084 | ||
7d8268a1 | 1085 | void wxMacTextControl::Copy() |
72055702 | 1086 | { |
72055702 SC |
1087 | } |
1088 | ||
7d8268a1 | 1089 | void wxMacTextControl::Cut() |
72055702 | 1090 | { |
72055702 SC |
1091 | } |
1092 | ||
7d8268a1 | 1093 | void wxMacTextControl::Paste() |
72055702 | 1094 | { |
72055702 SC |
1095 | } |
1096 | ||
7d8268a1 WS |
1097 | bool wxMacTextControl::CanPaste() const |
1098 | { | |
5ca0d812 SC |
1099 | return false ; |
1100 | } | |
1101 | ||
7d8268a1 | 1102 | void wxMacTextControl::SetEditable(bool editable) |
72055702 | 1103 | { |
7d8268a1 | 1104 | } |
facd6764 | 1105 | |
7d8268a1 | 1106 | wxTextPos wxMacTextControl::GetLastPosition() const |
5ca0d812 SC |
1107 | { |
1108 | return GetStringValue().Length() ; | |
1109 | } | |
facd6764 | 1110 | |
7d8268a1 | 1111 | void wxMacTextControl::Replace( long from , long to , const wxString str ) |
5ca0d812 | 1112 | { |
72055702 SC |
1113 | } |
1114 | ||
7d8268a1 | 1115 | void wxMacTextControl::Clear() |
72055702 | 1116 | { |
5ca0d812 | 1117 | SetStringValue( wxEmptyString ) ; |
72055702 SC |
1118 | } |
1119 | ||
7d8268a1 | 1120 | bool wxMacTextControl::CanUndo() const |
72055702 | 1121 | { |
5ca0d812 SC |
1122 | return false ; |
1123 | } | |
587bc950 | 1124 | |
7d8268a1 | 1125 | void wxMacTextControl::Undo() { } |
5ca0d812 SC |
1126 | |
1127 | bool wxMacTextControl::CanRedo() const | |
1128 | { | |
1129 | return false ; | |
7d8268a1 | 1130 | } |
5ca0d812 | 1131 | |
7d8268a1 | 1132 | void wxMacTextControl::Redo() |
5ca0d812 | 1133 | { |
72055702 SC |
1134 | } |
1135 | ||
5ca0d812 | 1136 | long wxMacTextControl::XYToPosition(long x, long y) const |
72055702 | 1137 | { |
5ca0d812 SC |
1138 | return 0 ; |
1139 | } | |
72055702 | 1140 | |
7d8268a1 | 1141 | bool wxMacTextControl::PositionToXY(long pos, long *x, long *y) const |
5ca0d812 SC |
1142 | { |
1143 | return false ; | |
72055702 SC |
1144 | } |
1145 | ||
7d8268a1 WS |
1146 | void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) |
1147 | { | |
1148 | } | |
5ca0d812 | 1149 | |
7d8268a1 | 1150 | int wxMacTextControl::GetNumberOfLines() const |
7548762c | 1151 | { |
5ca0d812 SC |
1152 | ItemCount lines = 0 ; |
1153 | wxString content = GetStringValue() ; | |
1154 | lines = 1; | |
1155 | for (size_t i = 0; i < content.Length() ; i++) | |
7548762c | 1156 | { |
5ca0d812 | 1157 | if (content[i] == '\r') lines++; |
7548762c | 1158 | } |
5ca0d812 SC |
1159 | return lines ; |
1160 | } | |
7548762c | 1161 | |
5ca0d812 | 1162 | wxString wxMacTextControl::GetLineText(long lineNo) const |
7548762c | 1163 | { |
5ca0d812 SC |
1164 | // TODO change this if possible to reflect real lines |
1165 | wxString content = GetStringValue() ; | |
7d8268a1 | 1166 | |
5ca0d812 SC |
1167 | // Find line first |
1168 | int count = 0; | |
1169 | for (size_t i = 0; i < content.Length() ; i++) | |
7548762c | 1170 | { |
5ca0d812 SC |
1171 | if (count == lineNo) |
1172 | { | |
1173 | // Add chars in line then | |
1174 | wxString tmp; | |
7d8268a1 | 1175 | |
5ca0d812 SC |
1176 | for (size_t j = i; j < content.Length(); j++) |
1177 | { | |
1178 | if (content[j] == '\n') | |
1179 | return tmp; | |
7d8268a1 | 1180 | |
5ca0d812 SC |
1181 | tmp += content[j]; |
1182 | } | |
7d8268a1 | 1183 | |
5ca0d812 SC |
1184 | return tmp; |
1185 | } | |
1186 | if (content[i] == '\n') count++; | |
7548762c | 1187 | } |
5ca0d812 SC |
1188 | return wxEmptyString ; |
1189 | } | |
7548762c | 1190 | |
5ca0d812 SC |
1191 | int wxMacTextControl::GetLineLength(long lineNo) const |
1192 | { | |
1193 | // TODO change this if possible to reflect real lines | |
1194 | wxString content = GetStringValue() ; | |
7d8268a1 | 1195 | |
5ca0d812 SC |
1196 | // Find line first |
1197 | int count = 0; | |
1198 | for (size_t i = 0; i < content.Length() ; i++) | |
7548762c | 1199 | { |
5ca0d812 SC |
1200 | if (count == lineNo) |
1201 | { | |
1202 | // Count chars in line then | |
1203 | count = 0; | |
1204 | for (size_t j = i; j < content.Length(); j++) | |
1205 | { | |
1206 | count++; | |
1207 | if (content[j] == '\n') return count; | |
1208 | } | |
7d8268a1 | 1209 | |
5ca0d812 SC |
1210 | return count; |
1211 | } | |
1212 | if (content[i] == '\n') count++; | |
7548762c | 1213 | } |
5ca0d812 SC |
1214 | return 0 ; |
1215 | } | |
7548762c | 1216 | |
5ca0d812 SC |
1217 | // ---------------------------------------------------------------------------- |
1218 | // standard unicode control implementation | |
1219 | // ---------------------------------------------------------------------------- | |
1220 | ||
1221 | #if TARGET_API_MAC_OSX | |
1222 | ||
0f7817ab | 1223 | wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
1224 | const wxString& str, |
1225 | const wxPoint& pos, | |
0f7817ab | 1226 | const wxSize& size, long style ) : wxMacTextControl( wxPeer ) |
5ca0d812 SC |
1227 | { |
1228 | m_font = wxPeer->GetFont() ; | |
1229 | m_windowStyle = style ; | |
7d8268a1 | 1230 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 1231 | wxString st = str ; |
395480fb | 1232 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
1233 | wxMacCFStringHolder cf(st , m_font.GetEncoding()) ; |
1234 | CFStringRef cfr = cf ; | |
1235 | Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; | |
1236 | m_valueTag = isPassword ? kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ; | |
1237 | CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cfr , isPassword , NULL , &m_controlRef ) ; | |
7d8268a1 | 1238 | |
5ca0d812 | 1239 | if ( !(m_windowStyle & wxTE_MULTILINE) ) |
7548762c | 1240 | { |
5ca0d812 | 1241 | SetData<Boolean>( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; |
7548762c | 1242 | } |
5ca0d812 | 1243 | } |
7548762c | 1244 | |
5ca0d812 | 1245 | wxMacUnicodeTextControl::~wxMacUnicodeTextControl() |
7548762c | 1246 | { |
7548762c SC |
1247 | } |
1248 | ||
7d8268a1 | 1249 | void wxMacUnicodeTextControl::VisibilityChanged(bool shown) |
7548762c | 1250 | { |
5ca0d812 SC |
1251 | if ( !(m_windowStyle & wxTE_MULTILINE) && shown ) |
1252 | { | |
1253 | // work around a refresh issue insofar as not always the entire content is shown even if this would be possible | |
1254 | ControlEditTextSelectionRec sel ; | |
1255 | CFStringRef value = NULL ; | |
7548762c | 1256 | |
5ca0d812 SC |
1257 | verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); |
1258 | verify_noerr( GetData<CFStringRef>( 0, m_valueTag , &value ) ); | |
1259 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag, &value ) ); | |
1260 | verify_noerr( SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); | |
7d8268a1 | 1261 | |
5ca0d812 SC |
1262 | CFRelease( value ) ; |
1263 | } | |
1264 | } | |
7d8268a1 | 1265 | wxString wxMacUnicodeTextControl::GetStringValue() const |
7548762c | 1266 | { |
5ca0d812 SC |
1267 | wxString result ; |
1268 | CFStringRef value = GetData<CFStringRef>(0,m_valueTag) ; | |
1269 | if ( value ) | |
1270 | { | |
1271 | wxMacCFStringHolder cf(value) ; | |
1272 | result = cf.AsString() ; | |
1273 | } | |
2e7573f7 | 1274 | #if '\n' == 10 |
395480fb SC |
1275 | wxMacConvertNewlines13To10( &result ) ; |
1276 | #else | |
5ca0d812 | 1277 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1278 | #endif |
7548762c SC |
1279 | return result ; |
1280 | } | |
7d8268a1 | 1281 | void wxMacUnicodeTextControl::SetStringValue( const wxString &str) |
5ca0d812 SC |
1282 | { |
1283 | wxString st = str ; | |
395480fb | 1284 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
1285 | wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; |
1286 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag , cf ) ) ; | |
1287 | } | |
1288 | void wxMacUnicodeTextControl::Copy() | |
1289 | { | |
1290 | SendHICommand( kHICommandCopy ) ; | |
1291 | } | |
1292 | void wxMacUnicodeTextControl::Cut() | |
1293 | { | |
1294 | SendHICommand( kHICommandCut ) ; | |
1295 | } | |
1296 | void wxMacUnicodeTextControl::Paste() | |
1297 | { | |
1298 | SendHICommand( kHICommandPaste ) ; | |
1299 | } | |
1300 | bool wxMacUnicodeTextControl::CanPaste() const | |
1301 | { | |
1302 | return true ; | |
1303 | } | |
7d8268a1 | 1304 | void wxMacUnicodeTextControl::SetEditable(bool editable) |
5ca0d812 SC |
1305 | { |
1306 | SetData<Boolean>( 0 , kControlEditTextLockedTag , (Boolean) !editable ) ; | |
1307 | } | |
7d8268a1 | 1308 | void wxMacUnicodeTextControl::Remove( long from , long to ) |
5ca0d812 SC |
1309 | { |
1310 | } | |
7548762c | 1311 | |
5ca0d812 | 1312 | void wxMacUnicodeTextControl::GetSelection( long* from, long* to) const |
7548762c | 1313 | { |
5ca0d812 SC |
1314 | ControlEditTextSelectionRec sel ; |
1315 | verify_noerr(GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ) ; | |
1316 | if ( from ) *from = sel.selStart ; | |
1317 | if ( to ) *to = sel.selEnd ; | |
7548762c SC |
1318 | } |
1319 | ||
7d8268a1 | 1320 | void wxMacUnicodeTextControl::SetSelection( long from , long to ) |
ef4a634b | 1321 | { |
5ca0d812 SC |
1322 | ControlEditTextSelectionRec sel ; |
1323 | sel.selStart = from ; | |
1324 | sel.selEnd = to ; | |
1325 | SetData<ControlEditTextSelectionRec>( 0 , kControlEditTextSelectionTag, &sel ) ; | |
1326 | } | |
facd6764 | 1327 | |
5ca0d812 SC |
1328 | void wxMacUnicodeTextControl::WriteText(const wxString& str) |
1329 | { | |
1330 | wxString st = str ; | |
395480fb | 1331 | wxMacConvertNewlines10To13( &st ) ; |
7548762c SC |
1332 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
1333 | wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; | |
1334 | CFStringRef value = cf ; | |
5ca0d812 | 1335 | SetData<CFStringRef>( 0, kControlEditTextInsertCFStringRefTag, &value ); |
7548762c | 1336 | #else |
5ca0d812 | 1337 | wxString val = GetStringValue() ; |
7548762c SC |
1338 | long start , end ; |
1339 | GetSelection( &start , &end ) ; | |
1340 | val.Remove( start , end - start ) ; | |
1341 | val.insert( start , str ) ; | |
5ca0d812 | 1342 | SetStringValue( val ) ; |
7ea087b7 | 1343 | SetSelection( start + str.Length() , start + str.Length() ) ; |
7548762c | 1344 | #endif |
72055702 SC |
1345 | } |
1346 | ||
5ca0d812 | 1347 | #endif |
facd6764 | 1348 | |
5ca0d812 SC |
1349 | // ---------------------------------------------------------------------------- |
1350 | // MLTE control implementation (common part) | |
1351 | // ---------------------------------------------------------------------------- | |
facd6764 | 1352 | |
7d8268a1 | 1353 | // if mlte is on read only , no changes at all are allowed, not even from |
5ca0d812 SC |
1354 | // procedural API, in order to allow changes via API all the same we must undo |
1355 | // the readonly status while we are executing, this class helps to do so | |
72055702 | 1356 | |
5de694f0 | 1357 | class wxMacEditHelper |
72055702 | 1358 | { |
5ca0d812 | 1359 | public : |
5de694f0 | 1360 | wxMacEditHelper( TXNObject txn ) |
5ca0d812 SC |
1361 | { |
1362 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1363 | m_txn = txn ; | |
1364 | TXNGetTXNObjectControls( m_txn , 1 , tag , m_data ) ; | |
1365 | if ( m_data[0].uValue == kTXNReadOnly ) | |
1366 | { | |
1367 | TXNControlData data[] = { { kTXNReadWrite } } ; | |
1368 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , data ) ; | |
1369 | } | |
1370 | } | |
5de694f0 | 1371 | ~wxMacEditHelper() |
5ca0d812 SC |
1372 | { |
1373 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1374 | if ( m_data[0].uValue == kTXNReadOnly ) | |
1375 | { | |
1376 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , m_data ) ; | |
1377 | } | |
1378 | } | |
1379 | protected : | |
1380 | TXNObject m_txn ; | |
1381 | TXNControlData m_data[1] ; | |
1382 | } ; | |
72055702 | 1383 | |
789ae0cf SC |
1384 | wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) : wxMacTextControl( peer ) |
1385 | { | |
1386 | SetNeedsFocusRect( true ) ; | |
1387 | } | |
1388 | ||
7d8268a1 | 1389 | wxString wxMacMLTEControl::GetStringValue() const |
72055702 | 1390 | { |
5ca0d812 SC |
1391 | wxString result ; |
1392 | OSStatus err ; | |
1393 | Size actualSize = 0; | |
1394 | { | |
1395 | #if wxUSE_UNICODE | |
1396 | Handle theText ; | |
1397 | err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText , kTXNUnicodeTextData ); | |
1398 | // all done | |
1399 | if ( err ) | |
1400 | { | |
1401 | actualSize = 0 ; | |
1402 | } | |
1403 | else | |
1404 | { | |
1405 | actualSize = GetHandleSize( theText ) / sizeof( UniChar) ; | |
1406 | if ( actualSize > 0 ) | |
1407 | { | |
1408 | wxChar *ptr = NULL ; | |
7d8268a1 WS |
1409 | #if SIZEOF_WCHAR_T == 2 |
1410 | ptr = new wxChar[actualSize + 1 ] ; | |
5ca0d812 | 1411 | wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ; |
5ca0d812 SC |
1412 | #else |
1413 | SetHandleSize( theText , ( actualSize + 1 ) * sizeof( UniChar ) ) ; | |
1414 | HLock( theText ) ; | |
1415 | (((UniChar*)*theText)[actualSize]) = 0 ; | |
1416 | wxMBConvUTF16BE converter ; | |
1417 | size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; | |
1418 | ptr = new wxChar[noChars + 1] ; | |
7d8268a1 | 1419 | |
5ca0d812 SC |
1420 | noChars = converter.MB2WC( ptr , (const char*)*theText , noChars ) ; |
1421 | ptr[noChars] = 0 ; | |
1422 | HUnlock( theText ) ; | |
1423 | #endif | |
1424 | ptr[actualSize] = 0 ; | |
1425 | result = wxString( ptr ) ; | |
1426 | delete[] ptr ; | |
1427 | } | |
1428 | DisposeHandle( theText ) ; | |
1429 | } | |
1430 | #else | |
1431 | Handle theText ; | |
0263da03 | 1432 | err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); |
5ca0d812 SC |
1433 | // all done |
1434 | if ( err ) | |
1435 | { | |
1436 | actualSize = 0 ; | |
1437 | } | |
1438 | else | |
1439 | { | |
1440 | actualSize = GetHandleSize( theText ) ; | |
1441 | if ( actualSize > 0 ) | |
1442 | { | |
1443 | HLock( theText ) ; | |
1444 | result = wxString( *theText , wxConvLocal , actualSize ) ; | |
1445 | HUnlock( theText ) ; | |
1446 | } | |
1447 | DisposeHandle( theText ) ; | |
1448 | } | |
1449 | #endif | |
1450 | } | |
2e7573f7 | 1451 | #if '\n' == 10 |
395480fb SC |
1452 | wxMacConvertNewlines13To10( &result ) ; |
1453 | #else | |
5ca0d812 | 1454 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1455 | #endif |
5ca0d812 | 1456 | return result ; |
72055702 SC |
1457 | } |
1458 | ||
7d8268a1 | 1459 | void wxMacMLTEControl::SetStringValue( const wxString &str) |
72055702 | 1460 | { |
5ca0d812 | 1461 | wxString st = str ; |
395480fb SC |
1462 | |
1463 | wxMacConvertNewlines10To13( &st ) ; | |
5de694f0 SC |
1464 | { |
1465 | wxMacWindowClipper c( m_peer ) ; | |
1466 | { | |
1467 | wxMacEditHelper help(m_txn) ; | |
1468 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; | |
1469 | } | |
1470 | TXNSetSelection( m_txn, 0, 0); | |
1471 | TXNShowSelection( m_txn, kTXNShowStart); | |
1472 | } | |
5ca0d812 | 1473 | } |
facd6764 | 1474 | |
5ca0d812 SC |
1475 | TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) |
1476 | { | |
1477 | TXNFrameOptions frameOptions = | |
1478 | kTXNDontDrawCaretWhenInactiveMask ; | |
5de694f0 | 1479 | |
5ca0d812 SC |
1480 | if ( ! ( wxStyle & wxTE_NOHIDESEL ) ) |
1481 | frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; | |
1482 | ||
1483 | if ( wxStyle & wxTE_MULTILINE ) | |
29e4a190 | 1484 | { |
5ca0d812 SC |
1485 | if ( ! ( wxStyle & wxTE_DONTWRAP ) ) |
1486 | frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; | |
1487 | else | |
1488 | { | |
1489 | frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; | |
1490 | frameOptions |= kTXNWantHScrollBarMask ; | |
1491 | } | |
72055702 | 1492 | |
5ca0d812 | 1493 | if ( !(wxStyle & wxTE_NO_VSCROLL ) ) |
5de694f0 | 1494 | { |
5ca0d812 | 1495 | frameOptions |= kTXNWantVScrollBarMask ; |
5de694f0 SC |
1496 | if ( frameOptions & kTXNWantHScrollBarMask ) |
1497 | frameOptions |= kTXNDrawGrowIconMask ; | |
1498 | } | |
5ca0d812 SC |
1499 | } |
1500 | else | |
1501 | frameOptions |= kTXNSingleLineOnlyMask ; | |
7d8268a1 | 1502 | |
5ca0d812 SC |
1503 | if ( wxStyle & wxHSCROLL ) |
1504 | frameOptions |= kTXNWantHScrollBarMask ; | |
7d8268a1 | 1505 | |
5ca0d812 SC |
1506 | return frameOptions ; |
1507 | } | |
cfeff6f7 | 1508 | |
5ca0d812 SC |
1509 | void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, bool visible ) |
1510 | { | |
5de694f0 SC |
1511 | TXNControlTag iControlTags[] = |
1512 | { | |
1513 | kTXNDoFontSubstitution, | |
1514 | kTXNWordWrapStateTag , | |
1515 | }; | |
1516 | TXNControlData iControlData[] = | |
1517 | { | |
1518 | {false}, | |
1519 | {kTXNNoAutoWrap}, | |
1520 | }; | |
1521 | ||
1522 | int toptag = WXSIZEOF( iControlTags ) ; | |
7d8268a1 | 1523 | |
72055702 SC |
1524 | if ( m_windowStyle & wxTE_MULTILINE ) |
1525 | { | |
5ca0d812 SC |
1526 | if (m_windowStyle & wxTE_DONTWRAP) |
1527 | iControlData[1].uValue = kTXNNoAutoWrap ; | |
1528 | else | |
1529 | iControlData[1].uValue = kTXNAutoWrap ; | |
72055702 | 1530 | } |
7a926300 | 1531 | verify_noerr( TXNSetTXNObjectControls( m_txn, false, toptag, |
5ca0d812 | 1532 | iControlTags, iControlData )) ; |
facd6764 | 1533 | |
5ca0d812 | 1534 | // setting the default font |
72055702 | 1535 | |
5ca0d812 SC |
1536 | Str255 fontName ; |
1537 | SInt16 fontSize ; | |
1538 | Style fontStyle ; | |
72055702 | 1539 | |
5ca0d812 SC |
1540 | GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; |
1541 | ||
1542 | TXNTypeAttributes typeAttr[] = | |
72055702 | 1543 | { |
5ca0d812 SC |
1544 | { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , |
1545 | { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , | |
1546 | { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , | |
1547 | } ; | |
1548 | ||
1549 | verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr, | |
1550 | kTXNStartOffset, | |
1551 | kTXNEndOffset) ); | |
1552 | ||
1553 | if ( m_windowStyle & wxTE_PASSWORD ) | |
1554 | { | |
1555 | UniChar c = 0xA5 ; | |
1556 | verify_noerr(TXNEchoMode( m_txn , c , 0 , true )) ; | |
72055702 | 1557 | } |
5ca0d812 SC |
1558 | |
1559 | TXNBackground tback; | |
1560 | tback.bgType = kTXNBackgroundTypeRGB; | |
1561 | tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); | |
1562 | TXNSetBackground( m_txn , &tback); | |
72055702 SC |
1563 | } |
1564 | ||
7d8268a1 | 1565 | void wxMacMLTEControl::SetBackground( const wxBrush &brush ) |
7ea087b7 SC |
1566 | { |
1567 | // currently only solid background are supported | |
1568 | TXNBackground tback; | |
1569 | tback.bgType = kTXNBackgroundTypeRGB; | |
1570 | tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); | |
1571 | TXNSetBackground( m_txn , &tback); | |
1572 | } | |
1573 | ||
8623a883 | 1574 | void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to) |
72055702 | 1575 | { |
7d8268a1 | 1576 | TXNTypeAttributes typeAttr[4] ; |
5ca0d812 SC |
1577 | Str255 fontName = "\pMonaco" ; |
1578 | SInt16 fontSize = 12 ; | |
1579 | Style fontStyle = normal ; | |
1580 | RGBColor color ; | |
1581 | int attrCounter = 0 ; | |
1582 | if ( style.HasFont() ) | |
72055702 | 1583 | { |
5ca0d812 SC |
1584 | const wxFont &font = style.GetFont() ; |
1585 | wxMacStringToPascal( font.GetFaceName() , fontName ) ; | |
1586 | fontSize = font.GetPointSize() ; | |
1587 | if ( font.GetUnderlined() ) | |
1588 | fontStyle |= underline ; | |
1589 | if ( font.GetWeight() == wxBOLD ) | |
1590 | fontStyle |= bold ; | |
1591 | if ( font.GetStyle() == wxITALIC ) | |
1592 | fontStyle |= italic ; | |
eda3f2b4 | 1593 | |
5ca0d812 SC |
1594 | typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ; |
1595 | typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ; | |
1596 | typeAttr[attrCounter].data.dataPtr = (void*) fontName ; | |
1597 | typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ; | |
1598 | typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ; | |
1599 | typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ; | |
1600 | typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ; | |
1601 | typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; | |
1602 | typeAttr[attrCounter+2].data.dataValue = fontStyle ; | |
1603 | attrCounter += 3 ; | |
5ca0d812 SC |
1604 | } |
1605 | if ( style.HasTextColour() ) | |
1606 | { | |
1607 | typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ; | |
1608 | typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ; | |
1609 | typeAttr[attrCounter].data.dataPtr = (void*) &color ; | |
1610 | color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; | |
1611 | attrCounter += 1 ; | |
72055702 | 1612 | } |
8623a883 SC |
1613 | if ( attrCounter > 0 ) |
1614 | { | |
1615 | verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, from , to) ); | |
1616 | } | |
72055702 SC |
1617 | } |
1618 | ||
7d8268a1 | 1619 | void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) |
72055702 | 1620 | { |
5de694f0 | 1621 | wxMacEditHelper help(m_txn) ; |
8623a883 | 1622 | TXNSetAttribute( wxTextAttr(foreground,wxNullColour,font) , kTXNStartOffset,kTXNEndOffset ) ; |
72055702 | 1623 | } |
7d8268a1 WS |
1624 | void wxMacMLTEControl::SetStyle(long start, long end, const wxTextAttr& style) |
1625 | { | |
5de694f0 | 1626 | wxMacEditHelper help(m_txn) ; |
8623a883 | 1627 | TXNSetAttribute( style , start,end ) ; |
7d8268a1 WS |
1628 | } |
1629 | ||
1630 | void wxMacMLTEControl::Copy() | |
5ca0d812 SC |
1631 | { |
1632 | ClearCurrentScrap(); | |
1633 | TXNCopy(m_txn); | |
1634 | TXNConvertToPublicScrap(); | |
72055702 SC |
1635 | } |
1636 | ||
7d8268a1 | 1637 | void wxMacMLTEControl::Cut() |
3a9fa0d6 | 1638 | { |
5ca0d812 SC |
1639 | ClearCurrentScrap(); |
1640 | TXNCut(m_txn); | |
1641 | TXNConvertToPublicScrap(); | |
3a9fa0d6 VZ |
1642 | } |
1643 | ||
7d8268a1 | 1644 | void wxMacMLTEControl::Paste() |
72055702 | 1645 | { |
5ca0d812 SC |
1646 | TXNConvertFromPublicScrap(); |
1647 | TXNPaste(m_txn); | |
72055702 SC |
1648 | } |
1649 | ||
5ca0d812 | 1650 | bool wxMacMLTEControl::CanPaste() const |
72055702 | 1651 | { |
5ca0d812 | 1652 | return TXNIsScrapPastable() ; |
72055702 SC |
1653 | } |
1654 | ||
7d8268a1 | 1655 | void wxMacMLTEControl::SetEditable(bool editable) |
72055702 | 1656 | { |
5ca0d812 SC |
1657 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; |
1658 | TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; | |
5de694f0 | 1659 | TXNSetTXNObjectControls( m_txn , false , WXSIZEOF(tag) , tag , data ) ; |
5ca0d812 | 1660 | } |
bd3169a7 | 1661 | |
7d8268a1 | 1662 | wxTextPos wxMacMLTEControl::GetLastPosition() const |
5ca0d812 | 1663 | { |
7d8268a1 | 1664 | wxTextPos actualsize = 0 ; |
5ca0d812 SC |
1665 | |
1666 | Handle theText ; | |
1667 | OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); | |
1668 | /* all done */ | |
1669 | if ( err ) | |
1670 | { | |
1671 | actualsize = 0 ; | |
1672 | } | |
1673 | else | |
1674 | { | |
1675 | actualsize = GetHandleSize( theText ) ; | |
1676 | DisposeHandle( theText ) ; | |
1677 | } | |
1678 | ||
1679 | return actualsize ; | |
1680 | } | |
1681 | ||
7d8268a1 | 1682 | void wxMacMLTEControl::Replace( long from , long to , const wxString str ) |
5ca0d812 SC |
1683 | { |
1684 | wxString value = str ; | |
395480fb | 1685 | wxMacConvertNewlines10To13( &value ) ; |
5ca0d812 | 1686 | |
5de694f0 | 1687 | wxMacEditHelper help( m_txn ) ; |
0f7817ab | 1688 | wxMacWindowClipper c( m_peer ) ; |
5ca0d812 SC |
1689 | |
1690 | TXNSetSelection(m_txn , from , to ) ; | |
1691 | TXNClear( m_txn ) ; | |
395480fb | 1692 | SetTXNData( value , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; |
5ca0d812 SC |
1693 | } |
1694 | ||
1695 | void wxMacMLTEControl::Remove( long from , long to ) | |
1696 | { | |
0f7817ab | 1697 | wxMacWindowClipper c( m_peer ) ; |
5de694f0 | 1698 | wxMacEditHelper help( m_txn ) ; |
5ca0d812 SC |
1699 | TXNSetSelection(m_txn , from , to ) ; |
1700 | TXNClear( m_txn ) ; | |
1701 | } | |
1702 | ||
1703 | void wxMacMLTEControl::GetSelection( long* from, long* to) const | |
1704 | { | |
1705 | TXNGetSelection( m_txn , (TXNOffset*) from , (TXNOffset*) to ) ; | |
1706 | } | |
1707 | ||
7d8268a1 | 1708 | void wxMacMLTEControl::SetSelection( long from , long to ) |
5ca0d812 | 1709 | { |
0f7817ab | 1710 | wxMacWindowClipper c( m_peer ) ; |
5ca0d812 SC |
1711 | /* change the selection */ |
1712 | if ((from == -1) && (to == -1)) | |
7d8268a1 | 1713 | TXNSelectAll(m_txn); |
5ca0d812 | 1714 | else |
7d8268a1 | 1715 | TXNSetSelection( m_txn, from, to); |
5ca0d812 SC |
1716 | TXNShowSelection( m_txn, kTXNShowStart); |
1717 | } | |
1718 | ||
7d8268a1 | 1719 | void wxMacMLTEControl::WriteText(const wxString& str) |
5ca0d812 | 1720 | { |
5ca0d812 | 1721 | wxString st = str ; |
395480fb | 1722 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
1723 | |
1724 | long start , end , dummy ; | |
1725 | GetSelection( &start , &dummy ) ; | |
5de694f0 SC |
1726 | wxMacWindowClipper c( m_peer ) ; |
1727 | { | |
1728 | wxMacEditHelper helper( m_txn ) ; | |
1729 | SetTXNData( st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; | |
1730 | } | |
5ca0d812 SC |
1731 | GetSelection( &dummy , &end ) ; |
1732 | // TODO SetStyle( start , end , GetDefaultStyle() ) ; | |
1733 | } | |
1734 | ||
7d8268a1 | 1735 | void wxMacMLTEControl::Clear() |
5ca0d812 | 1736 | { |
0f7817ab | 1737 | wxMacWindowClipper c( m_peer ) ; |
5de694f0 | 1738 | wxMacEditHelper st(m_txn) ; |
5ca0d812 SC |
1739 | TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ; |
1740 | TXNClear(m_txn); | |
1741 | } | |
1742 | ||
7d8268a1 | 1743 | bool wxMacMLTEControl::CanUndo() const |
5ca0d812 SC |
1744 | { |
1745 | return TXNCanUndo( m_txn , NULL ) ; | |
1746 | } | |
1747 | ||
7d8268a1 | 1748 | void wxMacMLTEControl::Undo() |
5ca0d812 | 1749 | { |
7d8268a1 WS |
1750 | TXNUndo( m_txn ) ; |
1751 | } | |
5ca0d812 SC |
1752 | |
1753 | bool wxMacMLTEControl::CanRedo() const | |
1754 | { | |
1755 | return TXNCanRedo( m_txn , NULL ) ; | |
7d8268a1 | 1756 | } |
5ca0d812 | 1757 | |
7d8268a1 WS |
1758 | void wxMacMLTEControl::Redo() |
1759 | { | |
5ca0d812 SC |
1760 | TXNRedo( m_txn ) ; |
1761 | } | |
1762 | ||
7d8268a1 | 1763 | int wxMacMLTEControl::GetNumberOfLines() const |
5ca0d812 SC |
1764 | { |
1765 | ItemCount lines = 0 ; | |
1766 | TXNGetLineCount(m_txn, &lines ) ; | |
1767 | return lines ; | |
1768 | } | |
1769 | ||
1770 | long wxMacMLTEControl::XYToPosition(long x, long y) const | |
1771 | { | |
1772 | Point curpt ; | |
7d8268a1 WS |
1773 | |
1774 | wxTextPos lastpos = GetLastPosition() ; | |
1775 | ||
1776 | // TODO find a better implementation : while we can get the | |
5ca0d812 SC |
1777 | // line metrics of a certain line, we don't get its starting |
1778 | // position, so it would probably be rather a binary search | |
1779 | // for the start position | |
7d8268a1 | 1780 | long xpos = 0 ; |
5ca0d812 SC |
1781 | long ypos = 0 ; |
1782 | int lastHeight = 0 ; | |
1783 | ||
1784 | ItemCount n ; | |
ebe86b1e | 1785 | for ( n = 0 ; n <= (ItemCount) lastpos ; ++n ) |
bd3169a7 SC |
1786 | { |
1787 | if ( y == ypos && x == xpos ) | |
1788 | return n ; | |
7d8268a1 | 1789 | |
5ca0d812 | 1790 | TXNOffsetToPoint( m_txn , n , &curpt); |
bd3169a7 SC |
1791 | |
1792 | if ( curpt.v > lastHeight ) | |
1793 | { | |
1794 | xpos = 0 ; | |
1795 | if ( n > 0 ) | |
1796 | ++ypos ; | |
1797 | lastHeight = curpt.v ; | |
1798 | } | |
1799 | else | |
1800 | ++xpos ; | |
1801 | } | |
5ca0d812 | 1802 | return 0 ; |
72055702 SC |
1803 | } |
1804 | ||
5ca0d812 | 1805 | bool wxMacMLTEControl::PositionToXY(long pos, long *x, long *y) const |
72055702 | 1806 | { |
bd3169a7 | 1807 | Point curpt ; |
7d8268a1 WS |
1808 | |
1809 | wxTextPos lastpos = GetLastPosition() ; | |
1810 | ||
bd3169a7 SC |
1811 | if ( y ) *y = 0 ; |
1812 | if ( x ) *x = 0 ; | |
7d8268a1 | 1813 | |
bd3169a7 SC |
1814 | if ( pos <= lastpos ) |
1815 | { | |
7d8268a1 | 1816 | // TODO find a better implementation : while we can get the |
bd3169a7 SC |
1817 | // line metrics of a certain line, we don't get its starting |
1818 | // position, so it would probably be rather a binary search | |
1819 | // for the start position | |
7d8268a1 | 1820 | long xpos = 0 ; |
bd3169a7 SC |
1821 | long ypos = 0 ; |
1822 | int lastHeight = 0 ; | |
1823 | ||
1824 | ItemCount n ; | |
ebe86b1e | 1825 | for ( n = 0 ; n <= (ItemCount) pos ; ++n ) |
bd3169a7 | 1826 | { |
5ca0d812 | 1827 | TXNOffsetToPoint(m_txn , n , &curpt); |
bd3169a7 SC |
1828 | |
1829 | if ( curpt.v > lastHeight ) | |
1830 | { | |
1831 | xpos = 0 ; | |
1832 | if ( n > 0 ) | |
1833 | ++ypos ; | |
1834 | lastHeight = curpt.v ; | |
1835 | } | |
1836 | else | |
1837 | ++xpos ; | |
1838 | } | |
1839 | if ( y ) *y = ypos ; | |
1840 | if ( x ) *x = xpos ; | |
1841 | } | |
5ca0d812 | 1842 | |
7d8268a1 | 1843 | return false ; |
72055702 SC |
1844 | } |
1845 | ||
7d8268a1 | 1846 | void wxMacMLTEControl::ShowPosition( long pos ) |
72055702 | 1847 | { |
3a05d58d | 1848 | #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) |
3a05d58d | 1849 | { |
f8e089e0 SC |
1850 | Point current ; |
1851 | Point desired ; | |
1852 | TXNOffset selstart , selend ; | |
5ca0d812 SC |
1853 | TXNGetSelection( m_txn , &selstart , &selend) ; |
1854 | TXNOffsetToPoint( m_txn, selstart , ¤t); | |
1855 | TXNOffsetToPoint( m_txn, pos , &desired); | |
f8e089e0 SC |
1856 | //TODO use HIPoints for 10.3 and above |
1857 | if ( (UInt32) TXNScroll != (UInt32) kUnresolvedCFragSymbolAddress ) | |
1858 | { | |
1859 | OSErr theErr = noErr; | |
1860 | SInt32 dv = desired.v - current.v ; | |
1861 | SInt32 dh = desired.h - current.h ; | |
5ca0d812 | 1862 | TXNShowSelection( m_txn , true ) ; |
7d8268a1 | 1863 | theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh ); |
f8e089e0 SC |
1864 | wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); |
1865 | } | |
3a05d58d SC |
1866 | } |
1867 | #endif | |
5ca0d812 SC |
1868 | } |
1869 | ||
1870 | void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) | |
1871 | { | |
1872 | #if wxUSE_UNICODE | |
1873 | #if SIZEOF_WCHAR_T == 2 | |
7d8268a1 | 1874 | size_t len = st.Len() ; |
5ca0d812 SC |
1875 | TXNSetData( m_txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, |
1876 | start, end); | |
1877 | #else | |
7d8268a1 WS |
1878 | wxMBConvUTF16BE converter ; |
1879 | ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ; | |
1880 | UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ; | |
1881 | converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ; | |
5ca0d812 SC |
1882 | TXNSetData( m_txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen , |
1883 | start, end); | |
7d8268a1 | 1884 | free( unibuf ) ; |
587bc950 | 1885 | #endif |
5ca0d812 | 1886 | #else |
7d8268a1 | 1887 | wxCharBuffer text = st.mb_str(wxConvLocal) ; |
5ca0d812 SC |
1888 | TXNSetData( m_txn , kTXNTextData, (void*)text.data(), strlen( text ) , |
1889 | start, end); | |
7d8268a1 | 1890 | #endif |
72055702 SC |
1891 | } |
1892 | ||
5ca0d812 SC |
1893 | |
1894 | wxString wxMacMLTEControl::GetLineText(long lineNo) const | |
72055702 | 1895 | { |
5ca0d812 | 1896 | wxString line ; |
5ca0d812 | 1897 | |
bd3169a7 | 1898 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 1899 | { |
bd3169a7 | 1900 | long ypos = 0 ; |
7d8268a1 WS |
1901 | |
1902 | Fixed lineWidth, | |
ae25e5cc RN |
1903 | lineHeight, |
1904 | currentHeight = 0; | |
7d8268a1 | 1905 | |
ae25e5cc RN |
1906 | // get the first possible position in the control |
1907 | Point firstPoint; | |
1908 | TXNOffsetToPoint(m_txn, 0, &firstPoint); | |
7d8268a1 | 1909 | |
ae25e5cc RN |
1910 | // Iterate through the lines until we reach the one we want, |
1911 | // adding to our current y pixel point position | |
1912 | while (ypos < lineNo) | |
32b5be3d | 1913 | { |
ae25e5cc RN |
1914 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
1915 | currentHeight += lineHeight; | |
1916 | } | |
7d8268a1 | 1917 | |
eab19a7c | 1918 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
1919 | TXNOffset theOffset; |
1920 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 1921 | |
ae25e5cc RN |
1922 | wxString content = GetStringValue() ; |
1923 | Point currentPoint = thePoint; | |
1924 | while(thePoint.v == currentPoint.v && theOffset < content.length()) | |
1925 | { | |
1926 | line += content[theOffset]; | |
1927 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
21fd5529 | 1928 | } |
21fd5529 | 1929 | } |
5ca0d812 | 1930 | return line ; |
72055702 SC |
1931 | } |
1932 | ||
5ca0d812 | 1933 | int wxMacMLTEControl::GetLineLength(long lineNo) const |
72055702 | 1934 | { |
ae25e5cc RN |
1935 | int theLength = 0; |
1936 | ||
bd3169a7 | 1937 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 1938 | { |
bd3169a7 | 1939 | long ypos = 0 ; |
7d8268a1 WS |
1940 | |
1941 | Fixed lineWidth, | |
ae25e5cc RN |
1942 | lineHeight, |
1943 | currentHeight = 0; | |
7d8268a1 | 1944 | |
ae25e5cc RN |
1945 | // get the first possible position in the control |
1946 | Point firstPoint; | |
1947 | TXNOffsetToPoint(m_txn, 0, &firstPoint); | |
7d8268a1 | 1948 | |
ae25e5cc RN |
1949 | // Iterate through the lines until we reach the one we want, |
1950 | // adding to our current y pixel point position | |
1951 | while (ypos < lineNo) | |
32b5be3d | 1952 | { |
ae25e5cc RN |
1953 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
1954 | currentHeight += lineHeight; | |
1955 | } | |
7d8268a1 | 1956 | |
eab19a7c | 1957 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
1958 | TXNOffset theOffset; |
1959 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 1960 | |
ae25e5cc RN |
1961 | wxString content = GetStringValue() ; |
1962 | Point currentPoint = thePoint; | |
1963 | while(thePoint.v == currentPoint.v && theOffset < content.length()) | |
1964 | { | |
1965 | ++theLength; | |
1966 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
29e4a190 | 1967 | } |
29e4a190 | 1968 | } |
ae25e5cc | 1969 | return theLength ; |
5ca0d812 | 1970 | } |
21fd5529 | 1971 | |
21fd5529 | 1972 | |
5ca0d812 SC |
1973 | // ---------------------------------------------------------------------------- |
1974 | // MLTE control implementation (classic part) | |
1975 | // ---------------------------------------------------------------------------- | |
21fd5529 | 1976 | |
5de694f0 SC |
1977 | // OS X Notes : We still don't have a full replacement for MLTE, so this implementation |
1978 | // has to live on. We have different problems coming from outdated implementations on the | |
1979 | // various OS X versions. Most deal with the scrollbars: they are not correctly embedded | |
1980 | // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is | |
1981 | // no way out, therefore we are using our own implementation and our own scrollbars .... | |
5ca0d812 | 1982 | |
5de694f0 | 1983 | #ifdef __WXMAC_OSX__ |
0f7817ab | 1984 | |
5de694f0 SC |
1985 | TXNScrollInfoUPP gTXNScrollInfoProc = NULL ; |
1986 | ControlActionUPP gTXNScrollActionProc = NULL ; | |
0f7817ab | 1987 | |
5de694f0 SC |
1988 | pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, TXNScrollBarOrientation |
1989 | iScrollBarOrientation, SInt32 iRefCon) | |
0f7817ab | 1990 | { |
5de694f0 SC |
1991 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) iRefCon ; |
1992 | SInt32 value = wxMax( iValue , 0 ) ; | |
1993 | SInt32 maximum = wxMax( iMaximumValue , 0 ) ; | |
0f7817ab | 1994 | |
5de694f0 SC |
1995 | if ( iScrollBarOrientation == kTXNHorizontal ) |
1996 | { | |
1997 | if ( mlte->m_sbHorizontal ) | |
1998 | { | |
1999 | SetControl32BitValue( mlte->m_sbHorizontal , value ) ; | |
2000 | SetControl32BitMaximum( mlte->m_sbHorizontal , maximum ) ; | |
2001 | mlte->m_lastHorizontalValue = value ; | |
2002 | } | |
2003 | } | |
2004 | else if ( iScrollBarOrientation == kTXNVertical ) | |
5ca0d812 | 2005 | { |
5de694f0 SC |
2006 | if ( mlte->m_sbVertical ) |
2007 | { | |
2008 | SetControl32BitValue( mlte->m_sbVertical , value ) ; | |
2009 | SetControl32BitMaximum( mlte->m_sbVertical , maximum ) ; | |
2010 | mlte->m_lastVerticalValue = value ; | |
2011 | } | |
72055702 SC |
2012 | } |
2013 | } | |
2014 | ||
5de694f0 | 2015 | pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) |
72055702 | 2016 | { |
5de694f0 SC |
2017 | OSStatus err ; |
2018 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) GetControlReference( controlRef ) ; | |
2019 | if ( mlte == NULL ) | |
2020 | return ; | |
2021 | ||
2022 | if ( controlRef != mlte->m_sbVertical && controlRef != mlte->m_sbHorizontal ) | |
2023 | return ; | |
2024 | ||
2025 | bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ; | |
2026 | ||
2027 | SInt32 minimum = 0 ; | |
2028 | SInt32 maximum = GetControl32BitMaximum( controlRef ) ; | |
2029 | SInt32 value = GetControl32BitValue( controlRef ) ; | |
2030 | SInt32 delta = 0; | |
2031 | switch ( partCode ) | |
2032 | { | |
2033 | case kControlDownButtonPart : | |
2034 | delta = 10 ; | |
2035 | break ; | |
2036 | case kControlUpButtonPart : | |
2037 | delta = -10 ; | |
2038 | break ; | |
2039 | case kControlPageDownPart : | |
2040 | delta = GetControlViewSize( controlRef ) ; | |
2041 | break ; | |
2042 | case kControlPageUpPart : | |
2043 | delta = -GetControlViewSize( controlRef ) ; | |
2044 | break ; | |
2045 | case kControlIndicatorPart : | |
2046 | delta = value - | |
2047 | ( isHorizontal ? mlte->m_lastHorizontalValue : mlte->m_lastVerticalValue ) ; | |
2048 | break ; | |
2049 | default : | |
2050 | break ; | |
2051 | } | |
2052 | if ( delta != 0 ) | |
e600c175 | 2053 | { |
5de694f0 SC |
2054 | SInt32 newValue = value ; |
2055 | ||
2056 | if ( partCode != kControlIndicatorPart ) | |
2057 | { | |
2058 | if( value + delta < minimum ) | |
2059 | delta = minimum - value ; | |
2060 | if ( value + delta > maximum ) | |
2061 | delta = maximum - value ; | |
2062 | ||
2063 | SetControl32BitValue( controlRef , value + delta ) ; | |
2064 | newValue = value + delta ; | |
2065 | } | |
2066 | ||
2067 | SInt32 verticalDelta = isHorizontal ? 0 : delta ; | |
2068 | SInt32 horizontalDelta = isHorizontal ? delta : 0 ; | |
2069 | ||
2070 | err = TXNScroll( mlte->m_txn , kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, | |
2071 | &verticalDelta , &horizontalDelta ); | |
2072 | ||
2073 | if ( isHorizontal ) | |
2074 | mlte->m_lastHorizontalValue = newValue ; | |
2075 | else | |
2076 | mlte->m_lastVerticalValue = newValue ; | |
5ca0d812 | 2077 | } |
5ca0d812 | 2078 | } |
5de694f0 | 2079 | #endif |
7d8268a1 | 2080 | |
0f7817ab SC |
2081 | // make correct activations |
2082 | void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive) | |
2083 | { | |
2084 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); | |
ef4a634b | 2085 | |
5de694f0 SC |
2086 | wxMacWindowClipper clipper( textctrl ) ; |
2087 | TXNActivate(m_txn, m_txnFrameID, setActive); | |
0f7817ab | 2088 | |
5de694f0 SC |
2089 | ControlRef controlFocus = 0 ; |
2090 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
2091 | if ( controlFocus == m_controlRef ) | |
2092 | TXNFocus( m_txn, setActive); | |
2093 | } | |
2094 | ||
2095 | void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus) | |
2096 | { | |
2097 | TXNFocus( m_txn, setFocus); | |
5ca0d812 | 2098 | } |
1fa29bdc | 2099 | |
5de694f0 | 2100 | // guards against inappropriate redraw (hidden objects drawing onto window) |
0f7817ab SC |
2101 | |
2102 | void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis) | |
2103 | { | |
789ae0cf SC |
2104 | ControlRef controlFocus = 0 ; |
2105 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
2106 | ||
2107 | if ( controlFocus == m_controlRef && vis == false ) | |
2108 | { | |
2109 | SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ; | |
2110 | } | |
5de694f0 SC |
2111 | // we right now are always clipping as partial visibility (overlapped) visibility |
2112 | // is also a problem, if we run into further problems we might set the FrameBounds to an empty | |
2113 | // rect here | |
5ca0d812 | 2114 | } |
1fa29bdc | 2115 | |
0f7817ab | 2116 | // make sure that the TXNObject is at the right position |
5de694f0 | 2117 | |
0f7817ab SC |
2118 | void wxMacMLTEClassicControl::MacUpdatePosition() |
2119 | { | |
2120 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); | |
2121 | if ( textctrl == NULL ) | |
2122 | return ; | |
7d8268a1 | 2123 | |
0f7817ab SC |
2124 | Rect bounds ; |
2125 | UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); | |
2126 | ||
2127 | if ( !EqualRect( &bounds , &m_txnControlBounds ) ) | |
2128 | { | |
2129 | // old position | |
2130 | Rect oldBounds = m_txnControlBounds ; | |
2131 | m_txnControlBounds = bounds ; | |
2132 | wxMacWindowClipper cl(textctrl) ; | |
5de694f0 | 2133 | |
4e477040 | 2134 | #ifdef __WXMAC_OSX__ |
789ae0cf | 2135 | bool isCompositing = textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ; |
4e477040 SC |
2136 | if ( m_sbHorizontal || m_sbVertical ) |
2137 | { | |
5de694f0 SC |
2138 | int w = bounds.right - bounds.left ; |
2139 | int h = bounds.bottom - bounds.top ; | |
4e477040 SC |
2140 | |
2141 | if ( m_sbHorizontal ) | |
2142 | { | |
2143 | Rect sbBounds ; | |
5de694f0 | 2144 | |
4e477040 | 2145 | sbBounds.left = -1 ; |
5de694f0 SC |
2146 | sbBounds.top = h - 14 ; |
2147 | sbBounds.right = w + 1 ; | |
2148 | sbBounds.bottom = h + 1 ; | |
789ae0cf SC |
2149 | |
2150 | if ( !isCompositing ) | |
2151 | OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; | |
2152 | ||
4e477040 | 2153 | SetControlBounds( m_sbHorizontal , &sbBounds ) ; |
5de694f0 | 2154 | SetControlViewSize( m_sbHorizontal , w ) ; |
4e477040 SC |
2155 | } |
2156 | if ( m_sbVertical ) | |
2157 | { | |
2158 | Rect sbBounds ; | |
5de694f0 SC |
2159 | |
2160 | sbBounds.left = w - 14 ; | |
4e477040 | 2161 | sbBounds.top = -1 ; |
5de694f0 SC |
2162 | sbBounds.right = w + 1 ; |
2163 | sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ; | |
4e477040 | 2164 | |
789ae0cf SC |
2165 | if ( !isCompositing ) |
2166 | OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; | |
2167 | ||
4e477040 | 2168 | SetControlBounds( m_sbVertical , &sbBounds ) ; |
5de694f0 | 2169 | SetControlViewSize( m_sbVertical , h ) ; |
4e477040 SC |
2170 | } |
2171 | } | |
5de694f0 SC |
2172 | TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left, |
2173 | m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID); | |
2174 | #else | |
2175 | ||
2176 | TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left, | |
2177 | wxMax( m_txnControlBounds.bottom , m_txnControlBounds.top ) , | |
2178 | wxMax( m_txnControlBounds.right , m_txnControlBounds.left ) , m_txnFrameID); | |
2179 | ||
2180 | // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a | |
2181 | // movement, therefore we have to force it | |
2182 | ||
2183 | TXNLongRect textRect ; | |
2184 | TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ; | |
2185 | if ( textRect.left < m_txnControlBounds.left ) | |
2186 | { | |
2187 | TXNShowSelection( m_txn , false ) ; | |
2188 | } | |
4e477040 | 2189 | #endif |
e600c175 | 2190 | } |
5ca0d812 SC |
2191 | } |
2192 | ||
0f7817ab SC |
2193 | void wxMacMLTEClassicControl::SetRect( Rect *r ) |
2194 | { | |
2195 | wxMacControl::SetRect( r ) ; | |
2196 | MacUpdatePosition() ; | |
2197 | } | |
2198 | ||
24260aae SC |
2199 | void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart) |
2200 | { | |
24260aae | 2201 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); |
5ca0d812 | 2202 | if ( textctrl == NULL ) |
e600c175 | 2203 | return ; |
7d8268a1 | 2204 | |
5ca0d812 SC |
2205 | if ( textctrl->MacIsReallyShown() ) |
2206 | { | |
2207 | wxMacWindowClipper clipper( textctrl ) ; | |
0f7817ab | 2208 | TXNDraw( m_txn , NULL ) ; |
e600c175 | 2209 | } |
5ca0d812 SC |
2210 | } |
2211 | ||
24260aae SC |
2212 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
2213 | { | |
2214 | Point where = { y , x } ; | |
5ca0d812 | 2215 | ControlPartCode result; |
5de694f0 | 2216 | |
5ca0d812 | 2217 | result = 0; |
24260aae | 2218 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); |
5ca0d812 SC |
2219 | if ( textctrl == NULL ) |
2220 | return 0 ; | |
24260aae | 2221 | |
7d8268a1 | 2222 | if (textctrl->MacIsReallyShown() ) |
72055702 | 2223 | { |
0f7817ab | 2224 | if (PtInRect(where, &m_txnControlBounds)) |
5de694f0 | 2225 | result = kControlEditTextPart ; |
7d8268a1 | 2226 | else |
3556e470 SC |
2227 | { |
2228 | // sometimes we get the coords also in control local coordinates, therefore test again | |
2229 | if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) | |
2230 | { | |
2231 | int x = 0 , y = 0 ; | |
2232 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2233 | where.h += x ; | |
2234 | where.v += y ; | |
2235 | } | |
0f7817ab | 2236 | if (PtInRect(where, &m_txnControlBounds)) |
5de694f0 | 2237 | result = kControlEditTextPart ; |
7d8268a1 | 2238 | else |
3556e470 SC |
2239 | result = 0; |
2240 | } | |
5ca0d812 SC |
2241 | } |
2242 | return result; | |
2243 | } | |
2244 | ||
24260aae SC |
2245 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* actionProc ) |
2246 | { | |
24260aae | 2247 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); |
5ca0d812 SC |
2248 | if ( textctrl == NULL ) |
2249 | return 0; | |
24260aae | 2250 | |
5de694f0 SC |
2251 | ControlPartCode partCodeResult = 0; |
2252 | ||
7d8268a1 WS |
2253 | if (textctrl->MacIsReallyShown() ) |
2254 | { | |
5de694f0 | 2255 | Point startPt = { y ,x } ; |
5ca0d812 SC |
2256 | // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them |
2257 | if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) | |
2258 | { | |
2259 | int x = 0 , y = 0 ; | |
2260 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2261 | startPt.h += x ; | |
2262 | startPt.v += y ; | |
2263 | } | |
7d8268a1 | 2264 | |
24260aae | 2265 | switch (MacControlUserPaneHitTestProc( startPt.h , startPt.v )) |
5ca0d812 | 2266 | { |
5de694f0 | 2267 | case kControlEditTextPart : |
7d8268a1 WS |
2268 | { |
2269 | wxMacWindowClipper clipper( textctrl ) ; | |
2270 | ||
2271 | EventRecord rec ; | |
2272 | ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; | |
24260aae | 2273 | TXNClick( m_txn, &rec ); |
7d8268a1 WS |
2274 | |
2275 | } | |
5de694f0 | 2276 | break; |
5ca0d812 SC |
2277 | } |
2278 | } | |
2279 | return partCodeResult; | |
2280 | } | |
2281 | ||
24260aae SC |
2282 | void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() |
2283 | { | |
24260aae | 2284 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); |
5ca0d812 SC |
2285 | if ( textctrl == NULL ) |
2286 | return ; | |
24260aae SC |
2287 | |
2288 | if (textctrl->MacIsReallyShown()) | |
2289 | { | |
5de694f0 | 2290 | if (IsControlActive(m_controlRef)) |
24260aae | 2291 | { |
5ca0d812 | 2292 | Point mousep; |
7d8268a1 | 2293 | |
5ca0d812 SC |
2294 | wxMacWindowClipper clipper( textctrl ) ; |
2295 | GetMouse(&mousep); | |
5de694f0 SC |
2296 | |
2297 | TXNIdle(m_txn); | |
2298 | ||
2299 | if (PtInRect(mousep, &m_txnControlBounds)) | |
24260aae | 2300 | { |
5de694f0 SC |
2301 | RgnHandle theRgn; |
2302 | RectRgn((theRgn = NewRgn()), &m_txnControlBounds); | |
2303 | TXNAdjustCursor(m_txn, theRgn); | |
2304 | DisposeRgn(theRgn); | |
72055702 | 2305 | } |
5ca0d812 SC |
2306 | } |
2307 | } | |
2308 | } | |
72055702 | 2309 | |
24260aae SC |
2310 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
2311 | { | |
2312 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); | |
5ca0d812 SC |
2313 | if ( textctrl == NULL ) |
2314 | return 0; | |
7d8268a1 | 2315 | |
5de694f0 | 2316 | wxMacWindowClipper clipper( textctrl ) ; |
ef4a634b | 2317 | |
5de694f0 SC |
2318 | EventRecord ev ; |
2319 | memset( &ev , 0 , sizeof( ev ) ) ; | |
2320 | ev.what = keyDown ; | |
2321 | ev.modifiers = modifiers ; | |
2322 | ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ; | |
2323 | TXNKeyDown( m_txn , &ev); | |
1ea39a03 | 2324 | |
5de694f0 SC |
2325 | return kControlEntireControl; |
2326 | } | |
24260aae SC |
2327 | |
2328 | void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating) | |
2329 | { | |
5de694f0 | 2330 | MacActivatePaneText( activating ); |
72055702 SC |
2331 | } |
2332 | ||
24260aae SC |
2333 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) |
2334 | { | |
5ca0d812 | 2335 | ControlPartCode focusResult; |
7d8268a1 | 2336 | |
5ca0d812 | 2337 | focusResult = kControlFocusNoPart; |
24260aae | 2338 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); |
5ca0d812 SC |
2339 | if ( textctrl == NULL ) |
2340 | return 0; | |
0f7817ab SC |
2341 | |
2342 | wxMacWindowClipper clipper( textctrl ) ; | |
2343 | ||
5de694f0 SC |
2344 | ControlRef controlFocus = 0 ; |
2345 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
2346 | bool wasFocused = ( controlFocus == m_controlRef ) ; | |
2347 | ||
24260aae SC |
2348 | switch (action) |
2349 | { | |
5de694f0 SC |
2350 | case kControlFocusPrevPart: |
2351 | case kControlFocusNextPart: | |
2352 | MacFocusPaneText( ( !wasFocused)); | |
02a55765 | 2353 | focusResult = (!wasFocused) ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart; |
5de694f0 SC |
2354 | break; |
2355 | ||
5ca0d812 | 2356 | case kControlFocusNoPart: |
5de694f0 | 2357 | default: |
0f7817ab | 2358 | MacFocusPaneText( false); |
5ca0d812 SC |
2359 | focusResult = kControlFocusNoPart; |
2360 | break; | |
5ca0d812 | 2361 | } |
0f7817ab | 2362 | |
5ca0d812 | 2363 | return focusResult; |
72055702 SC |
2364 | } |
2365 | ||
24260aae SC |
2366 | void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info ) |
2367 | { | |
2368 | } | |
2369 | ||
0f7817ab | 2370 | wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
2371 | const wxString& str, |
2372 | const wxPoint& pos, | |
0f7817ab | 2373 | const wxSize& size, long style ) : wxMacMLTEControl( wxPeer ) |
72055702 | 2374 | { |
5ca0d812 SC |
2375 | m_font = wxPeer->GetFont() ; |
2376 | m_windowStyle = style ; | |
7d8268a1 | 2377 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 2378 | wxString st = str ; |
395480fb | 2379 | wxMacConvertNewlines10To13( &st ) ; |
72055702 | 2380 | |
5ca0d812 | 2381 | short featurSet; |
72055702 | 2382 | |
5ca0d812 | 2383 | featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle |
1a15a38f | 2384 | | kControlWantsActivate | kControlHandlesTracking // | kControlHasSpecialBackground |
5ca0d812 | 2385 | | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; |
72055702 | 2386 | |
5ca0d812 | 2387 | verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, &m_controlRef ) ); |
7d8268a1 | 2388 | |
0f7817ab | 2389 | DoCreate(); |
7d8268a1 | 2390 | |
5de694f0 SC |
2391 | MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ; |
2392 | ||
4e477040 | 2393 | AdjustCreationAttributes( *wxWHITE , true) ; |
5ca0d812 | 2394 | |
5de694f0 SC |
2395 | wxMacWindowClipper clipper( m_peer ) ; |
2396 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; | |
2397 | TXNSetSelection( m_txn, 0, 0); | |
72055702 SC |
2398 | } |
2399 | ||
5ca0d812 | 2400 | wxMacMLTEClassicControl::~wxMacMLTEClassicControl() |
72055702 | 2401 | { |
5ca0d812 | 2402 | TXNDeleteObject(m_txn); |
5de694f0 | 2403 | m_txn = NULL ; |
72055702 SC |
2404 | } |
2405 | ||
7d8268a1 | 2406 | void wxMacMLTEClassicControl::VisibilityChanged(bool shown) |
72055702 | 2407 | { |
0f7817ab | 2408 | MacSetObjectVisibility( shown ) ; |
4e477040 SC |
2409 | wxMacControl::VisibilityChanged( shown ) ; |
2410 | } | |
2411 | ||
2412 | void wxMacMLTEClassicControl::SuperChangedPosition() | |
2413 | { | |
2414 | MacUpdatePosition() ; | |
2415 | wxMacControl::SuperChangedPosition() ; | |
72055702 SC |
2416 | } |
2417 | ||
24260aae SC |
2418 | #ifdef __WXMAC_OSX__ |
2419 | ||
5de694f0 SC |
2420 | ControlUserPaneDrawUPP gTPDrawProc = NULL; |
2421 | ControlUserPaneHitTestUPP gTPHitProc = NULL; | |
2422 | ControlUserPaneTrackingUPP gTPTrackProc = NULL; | |
2423 | ControlUserPaneIdleUPP gTPIdleProc = NULL; | |
2424 | ControlUserPaneKeyDownUPP gTPKeyProc = NULL; | |
2425 | ControlUserPaneActivateUPP gTPActivateProc = NULL; | |
2426 | ControlUserPaneFocusUPP gTPFocusProc = NULL; | |
2427 | ||
24260aae SC |
2428 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) |
2429 | { | |
2430 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2431 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2432 | if ( win ) |
2433 | win->MacControlUserPaneDrawProc(part) ; | |
2434 | } | |
2435 | ||
2436 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) | |
2437 | { | |
2438 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2439 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2440 | if ( win ) |
2441 | return win->MacControlUserPaneHitTestProc(where.h , where.v) ; | |
2442 | else | |
2443 | return kControlNoPart ; | |
2444 | } | |
2445 | ||
2446 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) | |
2447 | { | |
2448 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2449 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2450 | if ( win ) |
2451 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; | |
2452 | else | |
2453 | return kControlNoPart ; | |
2454 | } | |
2455 | ||
2456 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
2457 | { | |
2458 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2459 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2460 | if ( win ) |
2461 | win->MacControlUserPaneIdleProc() ; | |
2462 | } | |
2463 | ||
2464 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
2465 | { | |
2466 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2467 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2468 | if ( win ) |
2469 | return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; | |
2470 | else | |
2471 | return kControlNoPart ; | |
2472 | } | |
2473 | ||
2474 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
2475 | { | |
2476 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2477 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2478 | if ( win ) |
2479 | win->MacControlUserPaneActivateProc(activating) ; | |
2480 | } | |
2481 | ||
2482 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
2483 | { | |
2484 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2485 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2486 | if ( win ) |
2487 | return win->MacControlUserPaneFocusProc(action) ; | |
2488 | else | |
2489 | return kControlNoPart ; | |
2490 | } | |
2491 | ||
02a55765 | 2492 | /* |
24260aae SC |
2493 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) |
2494 | { | |
2495 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2496 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2497 | if ( win ) |
2498 | win->MacControlUserPaneBackgroundProc(info) ; | |
2499 | } | |
02a55765 | 2500 | */ |
24260aae SC |
2501 | #endif |
2502 | ||
5de694f0 SC |
2503 | // TXNRegisterScrollInfoProc |
2504 | ||
5ca0d812 | 2505 | OSStatus wxMacMLTEClassicControl::DoCreate() |
2b5f62a0 | 2506 | { |
5ca0d812 | 2507 | Rect bounds; |
5ca0d812 SC |
2508 | |
2509 | OSStatus err = noErr ; | |
7d8268a1 | 2510 | |
5ca0d812 | 2511 | /* set up our globals */ |
24260aae SC |
2512 | #ifdef __WXMAC_OSX__ |
2513 | if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc); | |
2514 | if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc); | |
2515 | if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc); | |
2516 | if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc); | |
2517 | if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc); | |
2518 | if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc); | |
2519 | if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc); | |
5de694f0 SC |
2520 | |
2521 | if (gTXNScrollInfoProc == NULL ) gTXNScrollInfoProc = NewTXNScrollInfoUPP(TXNScrollInfoProc) ; | |
2522 | if (gTXNScrollActionProc == NULL ) gTXNScrollActionProc = NewControlActionUPP(TXNScrollActionProc) ; | |
24260aae | 2523 | #endif |
7d8268a1 | 2524 | |
5ca0d812 | 2525 | /* set the initial settings for our private data */ |
7d8268a1 | 2526 | |
5de694f0 SC |
2527 | m_txnWindow =GetControlOwner(m_controlRef); |
2528 | m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow); | |
7d8268a1 | 2529 | |
24260aae | 2530 | #ifdef __WXMAC_OSX__ |
5ca0d812 SC |
2531 | /* set up the user pane procedures */ |
2532 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc); | |
2533 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc); | |
2534 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc); | |
2535 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc); | |
2536 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc); | |
2537 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc); | |
2538 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); | |
24260aae | 2539 | #endif |
5ca0d812 SC |
2540 | /* calculate the rectangles used by the control */ |
2541 | UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); | |
0f7817ab SC |
2542 | |
2543 | m_txnControlBounds = bounds ; | |
2544 | ||
2545 | CGrafPtr origPort = NULL ; | |
2546 | GDHandle origDev = NULL ; | |
2547 | GetGWorld( &origPort , &origDev ) ; | |
2548 | SetPort(m_txnPort); | |
7d8268a1 | 2549 | |
5ca0d812 | 2550 | /* create the new edit field */ |
7d8268a1 | 2551 | |
5ca0d812 | 2552 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle ) ; |
7d8268a1 | 2553 | |
4e477040 SC |
2554 | #ifdef __WXMAC_OSX__ |
2555 | ||
2556 | // the scrollbars are not correctly embedded but are inserted at the root | |
2557 | // this gives us problems as we have erratic redraws even over the structure | |
2558 | // area | |
2559 | ||
5de694f0 SC |
2560 | m_sbHorizontal = 0 ; |
2561 | m_sbVertical = 0 ; | |
2562 | m_lastHorizontalValue = 0 ; | |
2563 | m_lastVerticalValue = 0 ; | |
2564 | ||
2565 | Rect sb = { 0 , 0 , 0 , 0 } ; | |
2566 | if ( frameOptions & kTXNWantVScrollBarMask ) | |
2567 | { | |
2568 | CreateScrollBarControl( m_txnWindow , &sb , 0 , 0 , 100 , 1 , true , gTXNScrollActionProc , &m_sbVertical ) ; | |
2569 | SetControlReference( m_sbVertical , (SInt32) this ) ; | |
2570 | SetControlAction( m_sbVertical, gTXNScrollActionProc ); | |
2571 | ShowControl( m_sbVertical ) ; | |
2572 | EmbedControl( m_sbVertical , m_controlRef ) ; | |
2573 | frameOptions &= ~kTXNWantVScrollBarMask ; | |
2574 | } | |
2575 | if ( frameOptions & kTXNWantHScrollBarMask ) | |
2576 | { | |
2577 | CreateScrollBarControl( m_txnWindow , &sb , 0 , 0 , 100 , 1 , true , gTXNScrollActionProc , &m_sbHorizontal ) ; | |
2578 | SetControlReference( m_sbHorizontal , (SInt32) this ) ; | |
2579 | SetControlAction( m_sbHorizontal, gTXNScrollActionProc ); | |
2580 | ShowControl( m_sbHorizontal ) ; | |
2581 | EmbedControl( m_sbHorizontal , m_controlRef ) ; | |
2582 | frameOptions &= ~(kTXNWantHScrollBarMask | kTXNDrawGrowIconMask); | |
2583 | } | |
4e477040 SC |
2584 | |
2585 | #endif | |
2586 | ||
5de694f0 | 2587 | verify_noerr(TXNNewObject(NULL, m_txnWindow , &bounds, |
5ca0d812 SC |
2588 | frameOptions , |
2589 | kTXNTextEditStyleFrameType, | |
2590 | kTXNTextensionFile, | |
2591 | kTXNSystemDefaultEncoding, | |
0f7817ab | 2592 | &m_txn, &m_txnFrameID, NULL ) ); |
7d8268a1 | 2593 | |
4e477040 | 2594 | #ifdef __WXMAC_OSX__ |
5de694f0 | 2595 | TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32) this); |
4e477040 SC |
2596 | #endif |
2597 | ||
0f7817ab | 2598 | SetGWorld( origPort , origDev ) ; |
5ca0d812 | 2599 | return err; |
facd6764 SC |
2600 | } |
2601 | ||
5ca0d812 SC |
2602 | // ---------------------------------------------------------------------------- |
2603 | // MLTE control implementation (OSX part) | |
2604 | // ---------------------------------------------------------------------------- | |
facd6764 | 2605 | |
5ca0d812 | 2606 | #if TARGET_API_MAC_OSX |
facd6764 | 2607 | |
3b92f0e0 SC |
2608 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
2609 | ||
0f7817ab | 2610 | wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
2611 | const wxString& str, |
2612 | const wxPoint& pos, | |
0f7817ab | 2613 | const wxSize& size, long style ) : wxMacMLTEControl( wxPeer ) |
facd6764 | 2614 | { |
5ca0d812 SC |
2615 | m_font = wxPeer->GetFont() ; |
2616 | m_windowStyle = style ; | |
7d8268a1 | 2617 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 2618 | wxString st = str ; |
395480fb | 2619 | wxMacConvertNewlines10To13( &st ) ; |
7d8268a1 | 2620 | |
5ca0d812 | 2621 | HIRect hr = { bounds.left , bounds.top , bounds.right - bounds.left , bounds.bottom- bounds.top } ; |
facd6764 | 2622 | |
5ca0d812 SC |
2623 | m_scrollView = NULL ; |
2624 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; | |
2625 | if ( frameOptions & (kTXNWantVScrollBarMask|kTXNWantHScrollBarMask) ) | |
2626 | { | |
7d8268a1 | 2627 | HIScrollViewCreate(( frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) | |
5ca0d812 | 2628 | ( frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll: 0 ) , &m_scrollView ) ; |
7d8268a1 WS |
2629 | |
2630 | HIViewSetFrame( m_scrollView, &hr ); | |
2631 | HIViewSetVisible( m_scrollView, true ); | |
5ca0d812 | 2632 | } |
7d8268a1 | 2633 | |
5ca0d812 SC |
2634 | m_textView = NULL ; |
2635 | HITextViewCreate( NULL , 0, frameOptions , &m_textView ) ; | |
2636 | m_txn = HITextViewGetTXNObject( m_textView) ; | |
2637 | HIViewSetVisible( m_textView , true ) ; | |
2638 | if ( m_scrollView ) | |
2639 | { | |
2640 | HIViewAddSubview( m_scrollView , m_textView ) ; | |
2641 | m_controlRef = m_scrollView ; | |
2642 | wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ; | |
2643 | } | |
2644 | else | |
2645 | { | |
7d8268a1 | 2646 | HIViewSetFrame( m_textView, &hr ); |
5ca0d812 SC |
2647 | m_controlRef = m_textView ; |
2648 | } | |
7d8268a1 | 2649 | |
0f7817ab SC |
2650 | AdjustCreationAttributes( *wxWHITE , true ) ; |
2651 | ||
2652 | wxMacWindowClipper c( m_peer ) ; | |
5ca0d812 SC |
2653 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; |
2654 | ||
2655 | TXNSetSelection( m_txn, 0, 0); | |
2656 | TXNShowSelection( m_txn, kTXNShowStart); | |
2657 | ||
facd6764 SC |
2658 | } |
2659 | ||
7d8268a1 | 2660 | OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) |
facd6764 | 2661 | { |
7d8268a1 | 2662 | return SetKeyboardFocus( GetControlOwner( m_textView ) , |
5ca0d812 | 2663 | m_textView , focusPart ) ; |
facd6764 SC |
2664 | } |
2665 | ||
7d8268a1 | 2666 | bool wxMacMLTEHIViewControl::HasFocus() const |
facd6764 | 2667 | { |
5ca0d812 SC |
2668 | ControlRef control ; |
2669 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2670 | return control == m_textView ; | |
facd6764 SC |
2671 | } |
2672 | ||
3b92f0e0 SC |
2673 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
2674 | ||
2675 | ||
fedad417 | 2676 | #endif |
5ca0d812 SC |
2677 | |
2678 | #endif // wxUSE_TEXTCTRL |