]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/textctrl.mm
Add wxDataViewCtrl::SetRowHeight() and provide its generic implementation.
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/textctrl.mm
3 // Purpose: wxTextCtrl
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_TEXTCTRL
15
16 #include "wx/textctrl.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/app.h"
21 #include "wx/utils.h"
22 #include "wx/dc.h"
23 #include "wx/button.h"
24 #include "wx/menu.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
28 #endif
29
30 #ifdef __DARWIN__
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #else
34 #include <stat.h>
35 #endif
36
37 #if wxUSE_STD_IOSTREAM
38 #if wxUSE_IOSTREAMH
39 #include <fstream.h>
40 #else
41 #include <fstream>
42 #endif
43 #endif
44
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
47 #include "wx/thread.h"
48 #include "wx/textcompleter.h"
49
50 #include "wx/osx/private.h"
51 #include "wx/osx/cocoa/private/textimpl.h"
52
53 @interface NSView(EditableView)
54 - (BOOL)isEditable;
55 - (void)setEditable:(BOOL)flag;
56 - (BOOL)isSelectable;
57 - (void)setSelectable:(BOOL)flag;
58 @end
59
60 class wxMacEditHelper
61 {
62 public :
63 wxMacEditHelper( NSView* textView )
64 {
65 m_textView = textView;
66 m_formerEditable = YES;
67 if ( textView )
68 {
69 m_formerEditable = [textView isEditable];
70 m_formerSelectable = [textView isSelectable];
71 [textView setEditable:YES];
72 }
73 }
74
75 ~wxMacEditHelper()
76 {
77 if ( m_textView )
78 {
79 [m_textView setEditable:m_formerEditable];
80 [m_textView setSelectable:m_formerSelectable];
81 }
82 }
83
84 protected :
85 BOOL m_formerEditable ;
86 BOOL m_formerSelectable;
87 NSView* m_textView;
88 } ;
89
90 @implementation wxNSSecureTextField
91
92 + (void)initialize
93 {
94 static BOOL initialized = NO;
95 if (!initialized)
96 {
97 initialized = YES;
98 wxOSXCocoaClassAddWXMethods( self );
99 }
100 }
101
102 - (void)controlTextDidChange:(NSNotification *)aNotification
103 {
104 wxUnusedVar(aNotification);
105 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
106 if ( impl )
107 impl->controlTextDidChange();
108 }
109
110 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
111 {
112 wxUnusedVar(aNotification);
113 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
114 if ( impl )
115 {
116 impl->DoNotifyFocusEvent( false, NULL );
117 }
118 }
119
120 @end
121
122 @interface wxNSTextScrollView : NSScrollView
123 {
124 }
125 @end
126
127 @implementation wxNSTextScrollView
128
129 + (void)initialize
130 {
131 static BOOL initialized = NO;
132 if (!initialized)
133 {
134 initialized = YES;
135 wxOSXCocoaClassAddWXMethods( self );
136 }
137 }
138
139 @end
140
141 @implementation wxNSTextFieldEditor
142
143 - (void) keyDown:(NSEvent*) event
144 {
145 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
146 lastKeyDownEvent = event;
147 if ( impl == NULL || !impl->DoHandleKeyEvent(event) )
148 [super keyDown:event];
149 lastKeyDownEvent = nil;
150 }
151
152 - (void) keyUp:(NSEvent*) event
153 {
154 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
155 if ( impl == NULL || !impl->DoHandleKeyEvent(event) )
156 [super keyUp:event];
157 }
158
159 - (void) flagsChanged:(NSEvent*) event
160 {
161 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
162 if ( impl == NULL || !impl->DoHandleKeyEvent(event) )
163 [super flagsChanged:event];
164 }
165
166 - (BOOL) performKeyEquivalent:(NSEvent*) event
167 {
168 BOOL retval = [super performKeyEquivalent:event];
169 return retval;
170 }
171
172 - (void) insertText:(id) str
173 {
174 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
175 if ( impl == NULL || lastKeyDownEvent==nil || !impl->DoHandleCharEvent(lastKeyDownEvent, str) )
176 {
177 [super insertText:str];
178 }
179 }
180
181 @end
182
183 @implementation wxNSTextView
184
185 + (void)initialize
186 {
187 static BOOL initialized = NO;
188 if (!initialized)
189 {
190 initialized = YES;
191 wxOSXCocoaClassAddWXMethods( self );
192 }
193 }
194
195 - (void)textDidChange:(NSNotification *)aNotification
196 {
197 wxUnusedVar(aNotification);
198 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
199 if ( impl )
200 impl->controlTextDidChange();
201 }
202
203 - (void) setEnabled:(BOOL) flag
204 {
205 // from Technical Q&A QA1461
206 if (flag) {
207 [self setTextColor: [NSColor controlTextColor]];
208
209 } else {
210 [self setTextColor: [NSColor disabledControlTextColor]];
211 }
212
213 [self setSelectable: flag];
214 [self setEditable: flag];
215 }
216
217 - (BOOL) isEnabled
218 {
219 return [self isEditable];
220 }
221
222 - (void)textDidEndEditing:(NSNotification *)aNotification
223 {
224 wxUnusedVar(aNotification);
225 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
226 if ( impl )
227 {
228 impl->DoNotifyFocusEvent( false, NULL );
229 }
230 }
231
232 @end
233
234 @implementation wxNSTextField
235
236 + (void)initialize
237 {
238 static BOOL initialized = NO;
239 if (!initialized)
240 {
241 initialized = YES;
242 wxOSXCocoaClassAddWXMethods( self );
243 }
244 }
245
246 - (id) initWithFrame:(NSRect) frame
247 {
248 self = [super initWithFrame:frame];
249 fieldEditor = nil;
250 return self;
251 }
252
253 - (void) dealloc
254 {
255 [fieldEditor release];
256 [super dealloc];
257 }
258
259 - (void) setFieldEditor:(wxNSTextFieldEditor*) editor
260 {
261 fieldEditor = editor;
262 }
263
264 - (wxNSTextFieldEditor*) fieldEditor
265 {
266 return fieldEditor;
267 }
268
269 - (void) setEnabled:(BOOL) flag
270 {
271 [super setEnabled: flag];
272
273 if (![self drawsBackground]) {
274 // Static text is drawn incorrectly when disabled.
275 // For an explanation, see
276 // http://www.cocoabuilder.com/archive/message/cocoa/2006/7/21/168028
277 if (flag) {
278 [self setTextColor: [NSColor controlTextColor]];
279 } else {
280 [self setTextColor: [NSColor secondarySelectedControlColor]];
281 }
282 }
283 }
284
285 - (void)controlTextDidChange:(NSNotification *)aNotification
286 {
287 wxUnusedVar(aNotification);
288 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
289 if ( impl )
290 impl->controlTextDidChange();
291 }
292
293 - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words
294 forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int*)index
295 {
296 NSMutableArray* matches = NULL;
297
298 wxTextWidgetImpl* impl = (wxNSTextFieldControl * ) wxWidgetImpl::FindFromWXWidget( self );
299 wxTextEntry * const entry = impl->GetTextEntry();
300 wxTextCompleter * const completer = entry->OSXGetCompleter();
301 if ( completer )
302 {
303 const wxString prefix = entry->GetValue();
304 if ( completer->Start(prefix) )
305 {
306 const wxString
307 wordStart = wxCFStringRef::AsString(
308 [[textView string] substringWithRange:charRange]
309 );
310
311 matches = [NSMutableArray array];
312 for ( ;; )
313 {
314 const wxString s = completer->GetNext();
315 if ( s.empty() )
316 break;
317
318 // Normally the completer should return only the strings
319 // starting with the prefix, but there could be exceptions
320 // and, for compatibility with MSW which simply ignores all
321 // entries that don't match the current text control contents,
322 // we ignore them as well. Besides, our own wxTextCompleterFixed
323 // doesn't respect this rule and, moreover, we need to extract
324 // just the rest of the string anyhow.
325 wxString completion;
326 if ( s.StartsWith(prefix, &completion) )
327 {
328 // We discarded the entire prefix above but actually we
329 // should include the part of it that consists of the
330 // beginning of the current word, otherwise it would be
331 // lost when completion is accepted as OS X supposes that
332 // our matches do start with the "partial word range"
333 // passed to us.
334 const wxCFStringRef fullWord(wordStart + completion);
335 [matches addObject: fullWord.AsNSString()];
336 }
337 }
338 }
339 }
340
341 return matches;
342 }
343
344 - (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
345 {
346 wxUnusedVar(textView);
347 wxUnusedVar(control);
348
349 BOOL handled = NO;
350
351 // send back key events wx' common code knows how to handle
352
353 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
354 if ( impl )
355 {
356 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
357 if ( wxpeer )
358 {
359 if (commandSelector == @selector(insertNewline:))
360 {
361 [textView insertNewlineIgnoringFieldEditor:self];
362 handled = YES;
363 }
364 else if ( commandSelector == @selector(insertTab:))
365 {
366 [textView insertTabIgnoringFieldEditor:self];
367 handled = YES;
368 }
369 else if ( commandSelector == @selector(insertBacktab:))
370 {
371 [textView insertTabIgnoringFieldEditor:self];
372 handled = YES;
373 }
374 }
375 }
376
377 return handled;
378 }
379
380 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
381 {
382 wxUnusedVar(aNotification);
383 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
384 if ( impl )
385 {
386 impl->DoNotifyFocusEvent( false, NULL );
387 }
388 }
389 @end
390
391 // wxNSTextViewControl
392
393 wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w )
394 : wxWidgetCocoaImpl(wxPeer, w),
395 wxTextWidgetImpl(wxPeer)
396 {
397 wxNSTextScrollView* sv = (wxNSTextScrollView*) w;
398 m_scrollView = sv;
399
400 [m_scrollView setHasVerticalScroller:YES];
401 [m_scrollView setHasHorizontalScroller:NO];
402 [m_scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
403 NSSize contentSize = [m_scrollView contentSize];
404
405 wxNSTextView* tv = [[wxNSTextView alloc] initWithFrame: NSMakeRect(0, 0,
406 contentSize.width, contentSize.height)];
407 m_textView = tv;
408 [tv setVerticallyResizable:YES];
409 [tv setHorizontallyResizable:NO];
410 [tv setAutoresizingMask:NSViewWidthSizable];
411
412 [m_scrollView setDocumentView: tv];
413
414 [tv setDelegate: tv];
415
416 InstallEventHandler(tv);
417 }
418
419 wxNSTextViewControl::~wxNSTextViewControl()
420 {
421 if (m_textView)
422 [m_textView setDelegate: nil];
423 }
424
425 bool wxNSTextViewControl::CanFocus() const
426 {
427 // since this doesn't work (return false), we hardcode
428 // if (m_textView)
429 // return [m_textView canBecomeKeyView];
430 return true;
431 }
432
433 wxString wxNSTextViewControl::GetStringValue() const
434 {
435 if (m_textView)
436 {
437 wxString result = wxCFStringRef::AsString([m_textView string], m_wxPeer->GetFont().GetEncoding());
438 wxMacConvertNewlines13To10( &result ) ;
439 return result;
440 }
441 return wxEmptyString;
442 }
443 void wxNSTextViewControl::SetStringValue( const wxString &str)
444 {
445 wxString st = str;
446 wxMacConvertNewlines10To13( &st );
447 wxMacEditHelper helper(m_textView);
448
449 if (m_textView)
450 [m_textView setString: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
451 }
452
453 void wxNSTextViewControl::Copy()
454 {
455 if (m_textView)
456 [m_textView copy:nil];
457
458 }
459
460 void wxNSTextViewControl::Cut()
461 {
462 if (m_textView)
463 [m_textView cut:nil];
464 }
465
466 void wxNSTextViewControl::Paste()
467 {
468 if (m_textView)
469 [m_textView paste:nil];
470 }
471
472 bool wxNSTextViewControl::CanPaste() const
473 {
474 return true;
475 }
476
477 void wxNSTextViewControl::SetEditable(bool editable)
478 {
479 if (m_textView)
480 [m_textView setEditable: editable];
481 }
482
483 void wxNSTextViewControl::GetSelection( long* from, long* to) const
484 {
485 if (m_textView)
486 {
487 NSRange range = [m_textView selectedRange];
488 *from = range.location;
489 *to = range.location + range.length;
490 }
491 }
492
493 void wxNSTextViewControl::SetSelection( long from , long to )
494 {
495 long textLength = [[m_textView string] length];
496 if ((from == -1) && (to == -1))
497 {
498 from = 0 ;
499 to = textLength ;
500 }
501 else
502 {
503 from = wxMin(textLength,wxMax(from,0)) ;
504 if ( to == -1 )
505 to = textLength;
506 else
507 to = wxMax(0,wxMin(textLength,to)) ;
508 }
509
510 NSRange selrange = NSMakeRange(from, to-from);
511 [m_textView setSelectedRange:selrange];
512 [m_textView scrollRangeToVisible:selrange];
513 }
514
515 void wxNSTextViewControl::WriteText(const wxString& str)
516 {
517 wxString st = str;
518 wxMacConvertNewlines10To13( &st );
519 wxMacEditHelper helper(m_textView);
520 NSEvent* formerEvent = m_lastKeyDownEvent;
521 m_lastKeyDownEvent = nil;
522 [m_textView insertText:wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
523 m_lastKeyDownEvent = formerEvent;
524 }
525
526 void wxNSTextViewControl::SetFont( const wxFont & font , const wxColour& WXUNUSED(foreground) , long WXUNUSED(windowStyle), bool WXUNUSED(ignoreBlack) )
527 {
528 if ([m_textView respondsToSelector:@selector(setFont:)])
529 [m_textView setFont: font.OSXGetNSFont()];
530 }
531
532 bool wxNSTextViewControl::GetStyle(long position, wxTextAttr& style)
533 {
534 if (m_textView && position >=0)
535 {
536 NSFont* font = NULL;
537 NSColor* bgcolor = NULL;
538 NSColor* fgcolor = NULL;
539 // NOTE: It appears that other platforms accept GetStyle with the position == length
540 // but that NSTextStorage does not accept length as a valid position.
541 // Therefore we return the default control style in that case.
542 if (position < (long) [[m_textView string] length])
543 {
544 NSTextStorage* storage = [m_textView textStorage];
545 font = [[storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL] autorelease];
546 bgcolor = [[storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
547 fgcolor = [[storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
548 }
549 else
550 {
551 NSDictionary* attrs = [m_textView typingAttributes];
552 font = [[attrs objectForKey:NSFontAttributeName] autorelease];
553 bgcolor = [[attrs objectForKey:NSBackgroundColorAttributeName] autorelease];
554 fgcolor = [[attrs objectForKey:NSForegroundColorAttributeName] autorelease];
555 }
556
557 if (font)
558 style.SetFont(wxFont(font));
559
560 if (bgcolor)
561 style.SetBackgroundColour(wxColour(bgcolor));
562
563 if (fgcolor)
564 style.SetTextColour(wxColour(fgcolor));
565 return true;
566 }
567
568 return false;
569 }
570
571 void wxNSTextViewControl::SetStyle(long start,
572 long end,
573 const wxTextAttr& style)
574 {
575 if (m_textView) {
576 NSRange range = NSMakeRange(start, end-start);
577 if (start == -1 && end == -1)
578 range = [m_textView selectedRange];
579
580 NSTextStorage* storage = [m_textView textStorage];
581
582 wxFont font = style.GetFont();
583 if (style.HasFont() && font.IsOk())
584 [storage addAttribute:NSFontAttributeName value:font.OSXGetNSFont() range:range];
585
586 wxColour bgcolor = style.GetBackgroundColour();
587 if (style.HasBackgroundColour() && bgcolor.IsOk())
588 [storage addAttribute:NSBackgroundColorAttributeName value:bgcolor.OSXGetNSColor() range:range];
589
590 wxColour fgcolor = style.GetTextColour();
591 if (style.HasTextColour() && fgcolor.IsOk())
592 [storage addAttribute:NSForegroundColorAttributeName value:fgcolor.OSXGetNSColor() range:range];
593 }
594 }
595
596 void wxNSTextViewControl::CheckSpelling(bool check)
597 {
598 if (m_textView)
599 [m_textView setContinuousSpellCheckingEnabled: check];
600 }
601
602 wxSize wxNSTextViewControl::GetBestSize() const
603 {
604 if (m_textView && [m_textView layoutManager])
605 {
606 NSRect rect = [[m_textView layoutManager] usedRectForTextContainer: [m_textView textContainer]];
607 return wxSize((int)(rect.size.width + [m_textView textContainerInset].width),
608 (int)(rect.size.height + [m_textView textContainerInset].height));
609 }
610 return wxSize(0,0);
611 }
612
613 // wxNSTextFieldControl
614
615 wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *text, WXWidget w )
616 : wxWidgetCocoaImpl(text, w),
617 wxTextWidgetImpl(text)
618 {
619 Init(w);
620 }
621
622 wxNSTextFieldControl::wxNSTextFieldControl(wxWindow *wxPeer,
623 wxTextEntry *entry,
624 WXWidget w)
625 : wxWidgetCocoaImpl(wxPeer, w),
626 wxTextWidgetImpl(entry)
627 {
628 Init(w);
629 }
630
631 void wxNSTextFieldControl::Init(WXWidget w)
632 {
633 NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>) *tf = (NSTextField*) w;
634 m_textField = tf;
635 [m_textField setDelegate: tf];
636 m_selStart = m_selEnd = 0;
637 m_hasEditor = [w isKindOfClass:[NSTextField class]];
638 }
639
640 wxNSTextFieldControl::~wxNSTextFieldControl()
641 {
642 if (m_textField)
643 [m_textField setDelegate: nil];
644 }
645
646 wxString wxNSTextFieldControl::GetStringValue() const
647 {
648 return wxCFStringRef::AsString([m_textField stringValue], m_wxPeer->GetFont().GetEncoding());
649 }
650
651 void wxNSTextFieldControl::SetStringValue( const wxString &str)
652 {
653 wxMacEditHelper helper(m_textField);
654 [m_textField setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
655 }
656
657 void wxNSTextFieldControl::Copy()
658 {
659 NSText* editor = [m_textField currentEditor];
660 if ( editor )
661 {
662 [editor copy:nil];
663 }
664 }
665
666 void wxNSTextFieldControl::Cut()
667 {
668 NSText* editor = [m_textField currentEditor];
669 if ( editor )
670 {
671 [editor cut:nil];
672 }
673 }
674
675 void wxNSTextFieldControl::Paste()
676 {
677 NSText* editor = [m_textField currentEditor];
678 if ( editor )
679 {
680 [editor paste:nil];
681 }
682 }
683
684 bool wxNSTextFieldControl::CanPaste() const
685 {
686 return true;
687 }
688
689 void wxNSTextFieldControl::SetEditable(bool editable)
690 {
691 [m_textField setEditable:editable];
692 }
693
694 void wxNSTextFieldControl::GetSelection( long* from, long* to) const
695 {
696 NSText* editor = [m_textField currentEditor];
697 if ( editor )
698 {
699 NSRange range = [editor selectedRange];
700 *from = range.location;
701 *to = range.location + range.length;
702 }
703 else
704 {
705 *from = m_selStart;
706 *to = m_selEnd;
707 }
708 }
709
710 void wxNSTextFieldControl::SetSelection( long from , long to )
711 {
712 long textLength = [[m_textField stringValue] length];
713 if ((from == -1) && (to == -1))
714 {
715 from = 0 ;
716 to = textLength ;
717 }
718 else
719 {
720 from = wxMin(textLength,wxMax(from,0)) ;
721 if ( to == -1 )
722 to = textLength;
723 else
724 to = wxMax(0,wxMin(textLength,to)) ;
725 }
726
727 NSText* editor = [m_textField currentEditor];
728 if ( editor )
729 {
730 [editor setSelectedRange:NSMakeRange(from, to-from)];
731 }
732 else
733 {
734 m_selStart = from;
735 m_selEnd = to;
736 }
737 }
738
739 void wxNSTextFieldControl::WriteText(const wxString& str)
740 {
741 NSEvent* formerEvent = m_lastKeyDownEvent;
742 m_lastKeyDownEvent = nil;
743 NSText* editor = [m_textField currentEditor];
744 if ( editor )
745 {
746 wxMacEditHelper helper(m_textField);
747 [editor insertText:wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
748 }
749 else
750 {
751 wxString val = GetStringValue() ;
752 long start , end ;
753 GetSelection( &start , &end ) ;
754 val.Remove( start , end - start ) ;
755 val.insert( start , str ) ;
756 SetStringValue( val ) ;
757 SetSelection( start + str.length() , start + str.length() ) ;
758 }
759 m_lastKeyDownEvent = formerEvent;
760 }
761
762 void wxNSTextFieldControl::controlAction(WXWidget WXUNUSED(slf),
763 void* WXUNUSED(_cmd), void *WXUNUSED(sender))
764 {
765 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
766 if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) )
767 {
768 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
769 event.SetEventObject( wxpeer );
770 event.SetString( GetTextEntry()->GetValue() );
771 wxpeer->HandleWindowEvent( event );
772 }
773 }
774
775 bool wxNSTextFieldControl::SetHint(const wxString& hint)
776 {
777 wxCFStringRef hintstring(hint);
778 [[m_textField cell] setPlaceholderString:hintstring.AsNSString()];
779 return true;
780 }
781
782 //
783 //
784 //
785
786 wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
787 wxWindowMac* WXUNUSED(parent),
788 wxWindowID WXUNUSED(id),
789 const wxString& WXUNUSED(str),
790 const wxPoint& pos,
791 const wxSize& size,
792 long style,
793 long WXUNUSED(extraStyle))
794 {
795 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
796 wxWidgetCocoaImpl* c = NULL;
797
798 if ( style & wxTE_MULTILINE || style & wxTE_RICH || style & wxTE_RICH2 )
799 {
800 wxNSTextScrollView* v = nil;
801 v = [[wxNSTextScrollView alloc] initWithFrame:r];
802 c = new wxNSTextViewControl( wxpeer, v );
803 }
804 else
805 {
806 NSTextField* v = nil;
807 if ( style & wxTE_PASSWORD )
808 v = [[wxNSSecureTextField alloc] initWithFrame:r];
809 else
810 v = [[wxNSTextField alloc] initWithFrame:r];
811
812 if ( style & wxNO_BORDER )
813 {
814 // FIXME: How can we remove the native control's border?
815 // setBordered is separate from the text ctrl's border.
816 }
817
818 NSTextFieldCell* cell = [v cell];
819 [cell setScrollable:YES];
820 // TODO: Remove if we definitely are sure, it's not needed
821 // as setting scrolling to yes, should turn off any wrapping
822 // [cell setLineBreakMode:NSLineBreakByClipping];
823
824 [v setBezeled:NO];
825 [v setBordered:NO];
826
827 c = new wxNSTextFieldControl( wxpeer, wxpeer, v );
828 }
829 c->SetNeedsFocusRect( true );
830
831 return c;
832 }
833
834
835 #endif // wxUSE_TEXTCTRL