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