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