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