]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/textctrl.mm
fixing multilib build
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
CommitLineData
dbeddfb9
SC
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: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $
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"
1e181c7a 50#include "wx/osx/cocoa/private/textimpl.h"
dbeddfb9 51
03647350 52@interface NSView(EditableView)
5f65ba36
SC
53- (BOOL)isEditable;
54- (void)setEditable:(BOOL)flag;
55@end
56
57class wxMacEditHelper
58{
59public :
60 wxMacEditHelper( NSView* textView )
61 {
63bcc669
SC
62 m_textView = textView;
63 m_formerState = YES;
5f65ba36
SC
64 if ( textView )
65 {
66 m_formerState = [textView isEditable];
67 [textView setEditable:YES];
68 }
69 }
70
71 ~wxMacEditHelper()
72 {
73 if ( m_textView )
74 [m_textView setEditable:m_formerState];
75 }
76
77protected :
78 BOOL m_formerState ;
79 NSView* m_textView;
80} ;
81
03647350 82@implementation wxNSSecureTextField
dbeddfb9 83
4dd9fdf8
SC
84+ (void)initialize
85{
86 static BOOL initialized = NO;
03647350 87 if (!initialized)
4dd9fdf8
SC
88 {
89 initialized = YES;
90 wxOSXCocoaClassAddWXMethods( self );
91 }
92}
dbeddfb9 93
4d23a0d3
KO
94- (void)controlTextDidChange:(NSNotification *)aNotification
95{
6331c8c0
SC
96 wxUnusedVar(aNotification);
97 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
4d23a0d3 98 if ( impl )
75a2c6a1 99 impl->controlTextDidChange();
4d23a0d3
KO
100}
101
6d109846
SC
102- (void)controlTextDidEndEditing:(NSNotification *)aNotification
103{
104 wxUnusedVar(aNotification);
105 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
106 if ( impl )
107 {
108 impl->DoNotifyFocusEvent( false, NULL );
109 }
110}
111
e32090ba
SC
112@end
113
1087c6c1 114@interface wxNSTextScrollView : NSScrollView
4d23a0d3 115{
4d23a0d3 116}
1087c6c1
SC
117@end
118
1087c6c1 119@implementation wxNSTextScrollView
c824c165
KO
120
121+ (void)initialize
122{
123 static BOOL initialized = NO;
03647350
VZ
124 if (!initialized)
125 {
c824c165
KO
126 initialized = YES;
127 wxOSXCocoaClassAddWXMethods( self );
128 }
129}
130
7cb2a241
SC
131@end
132
133@implementation wxNSTextFieldEditor
134
135- (void) keyDown:(NSEvent*) event
4d23a0d3 136{
9e55f38d 137 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
7cb2a241
SC
138 lastKeyDownEvent = event;
139 if ( impl == NULL || !impl->DoHandleKeyEvent(event) )
140 [super keyDown:event];
141 lastKeyDownEvent = nil;
4d23a0d3 142}
533e2ae1 143
7cb2a241 144- (void) keyUp:(NSEvent*) event
533e2ae1 145{
9e55f38d 146 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
7cb2a241
SC
147 if ( impl == NULL || !impl->DoHandleKeyEvent(event) )
148 [super keyUp:event];
533e2ae1 149}
1087c6c1 150
7cb2a241 151- (void) flagsChanged:(NSEvent*) event
1087c6c1 152{
9e55f38d 153 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
7cb2a241
SC
154 if ( impl == NULL || !impl->DoHandleKeyEvent(event) )
155 [super flagsChanged:event];
1087c6c1 156}
1087c6c1 157
7cb2a241
SC
158- (BOOL) performKeyEquivalent:(NSEvent*) event
159{
160 BOOL retval = [super performKeyEquivalent:event];
161 return retval;
162}
1087c6c1 163
7cb2a241 164- (void) insertText:(id) str
1087c6c1 165{
9e55f38d 166 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
7cb2a241 167 if ( impl == NULL || lastKeyDownEvent==nil || !impl->DoHandleCharEvent(lastKeyDownEvent, str) )
1087c6c1 168 {
7cb2a241 169 [super insertText:str];
1087c6c1 170 }
1087c6c1
SC
171}
172
7cb2a241
SC
173@end
174
175@implementation wxNSTextView
1087c6c1 176
7cb2a241 177+ (void)initialize
1087c6c1 178{
7cb2a241 179 static BOOL initialized = NO;
03647350 180 if (!initialized)
7cb2a241
SC
181 {
182 initialized = YES;
183 wxOSXCocoaClassAddWXMethods( self );
184 }
1087c6c1
SC
185}
186
b9cf2753
KO
187- (void)textDidChange:(NSNotification *)aNotification
188{
75a2c6a1
KO
189 wxUnusedVar(aNotification);
190 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
b9cf2753 191 if ( impl )
75a2c6a1 192 impl->controlTextDidChange();
b9cf2753
KO
193}
194
c824c165
KO
195@end
196
e32090ba 197@implementation wxNSTextField
ffad7b0d 198
e32090ba 199+ (void)initialize
dbeddfb9 200{
e32090ba 201 static BOOL initialized = NO;
03647350 202 if (!initialized)
e32090ba
SC
203 {
204 initialized = YES;
205 wxOSXCocoaClassAddWXMethods( self );
206 }
dbeddfb9 207}
e32090ba 208
7cb2a241
SC
209- (id) initWithFrame:(NSRect) frame
210{
211 self = [super initWithFrame:frame];
212 fieldEditor = nil;
213 return self;
214}
215
af665c2d
SC
216- (void) dealloc
217{
218 [fieldEditor release];
219 [super dealloc];
220}
221
7cb2a241
SC
222- (void) setFieldEditor:(wxNSTextFieldEditor*) editor
223{
224 fieldEditor = editor;
225}
226
227- (wxNSTextFieldEditor*) fieldEditor
228{
229 return fieldEditor;
230}
231
c3e433b1
SC
232- (void) setEnabled:(BOOL) flag
233{
234 [super setEnabled: flag];
235
236 if (![self drawsBackground]) {
237 // Static text is drawn incorrectly when disabled.
238 // For an explanation, see
239 // http://www.cocoabuilder.com/archive/message/cocoa/2006/7/21/168028
240 if (flag) {
241 [self setTextColor: [NSColor controlTextColor]];
242 } else {
243 [self setTextColor: [NSColor secondarySelectedControlColor]];
244 }
245 }
246}
4d23a0d3 247
ffad7b0d
SC
248- (void)controlTextDidChange:(NSNotification *)aNotification
249{
6331c8c0
SC
250 wxUnusedVar(aNotification);
251 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
ffad7b0d 252 if ( impl )
75a2c6a1 253 impl->controlTextDidChange();
ffad7b0d 254}
dbeddfb9 255
2d6aa919
KO
256typedef BOOL (*wxOSX_insertNewlineHandlerPtr)(NSView* self, SEL _cmd, NSControl *control, NSTextView* textView, SEL commandSelector);
257
258- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
259{
6331c8c0
SC
260 wxUnusedVar(textView);
261 wxUnusedVar(control);
2d6aa919
KO
262 if (commandSelector == @selector(insertNewline:))
263 {
6331c8c0 264 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
2d6aa919
KO
265 if ( impl )
266 {
267 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
03647350 268 if ( wxpeer && wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER )
2d6aa919
KO
269 {
270 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
271 event.SetEventObject( wxpeer );
272 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
273 wxpeer->HandleWindowEvent( event );
274 }
275 }
276 }
03647350 277
2d6aa919
KO
278 return NO;
279}
6d109846 280
ffad7b0d
SC
281- (void)controlTextDidEndEditing:(NSNotification *)aNotification
282{
6d109846
SC
283 wxUnusedVar(aNotification);
284 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
ffad7b0d
SC
285 if ( impl )
286 {
6d109846 287 impl->DoNotifyFocusEvent( false, NULL );
ffad7b0d
SC
288 }
289}
dbeddfb9
SC
290@end
291
c824c165
KO
292// wxNSTextViewControl
293
294wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
295{
1087c6c1
SC
296 wxNSTextScrollView* sv = (wxNSTextScrollView*) w;
297 m_scrollView = sv;
03647350 298
c824c165
KO
299 [m_scrollView setHasVerticalScroller:YES];
300 [m_scrollView setHasHorizontalScroller:NO];
301 [m_scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
302 NSSize contentSize = [m_scrollView contentSize];
03647350 303
1087c6c1 304 wxNSTextView* tv = [[wxNSTextView alloc] initWithFrame: NSMakeRect(0, 0,
c824c165 305 contentSize.width, contentSize.height)];
1087c6c1
SC
306 m_textView = tv;
307 [tv setVerticallyResizable:YES];
308 [tv setHorizontallyResizable:NO];
309 [tv setAutoresizingMask:NSViewWidthSizable];
03647350 310
1087c6c1 311 [m_scrollView setDocumentView: tv];
c824c165 312
b9cf2753 313 [tv setDelegate: tv];
03647350
VZ
314
315 InstallEventHandler(tv);
c824c165
KO
316}
317
318wxNSTextViewControl::~wxNSTextViewControl()
319{
320 if (m_textView)
321 [m_textView setDelegate: nil];
322}
323
78a17075
KO
324bool wxNSTextViewControl::CanFocus() const
325{
326 // we need to override so that we don't return the CanFocus value of
327 // the text view's overriding scroll view.
328 if (m_textView)
329 return [m_textView canBecomeKeyView];
330 return false;
331}
332
03647350 333wxString wxNSTextViewControl::GetStringValue() const
c824c165 334{
03647350 335 if (m_textView)
c824c165 336 {
f66ecdc4 337 wxString result = wxCFStringRef::AsString([m_textView string], m_wxPeer->GetFont().GetEncoding());
50b5e38d
SC
338 wxMacConvertNewlines13To10( &result ) ;
339 return result;
c824c165
KO
340 }
341 return wxEmptyString;
342}
03647350 343void wxNSTextViewControl::SetStringValue( const wxString &str)
c824c165 344{
50b5e38d
SC
345 wxString st = str;
346 wxMacConvertNewlines10To13( &st );
5f65ba36 347 wxMacEditHelper helper(m_textView);
50b5e38d 348
c824c165 349 if (m_textView)
50b5e38d 350 [m_textView setString: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
c824c165 351}
7cb2a241 352
03647350 353void wxNSTextViewControl::Copy()
c824c165
KO
354{
355 if (m_textView)
356 [m_textView copy:nil];
357
358}
359
03647350 360void wxNSTextViewControl::Cut()
c824c165
KO
361{
362 if (m_textView)
363 [m_textView cut:nil];
364}
365
03647350 366void wxNSTextViewControl::Paste()
c824c165
KO
367{
368 if (m_textView)
369 [m_textView paste:nil];
370}
371
03647350
VZ
372bool wxNSTextViewControl::CanPaste() const
373{
c824c165
KO
374 return true;
375}
376
03647350 377void wxNSTextViewControl::SetEditable(bool editable)
c824c165
KO
378{
379 if (m_textView)
380 [m_textView setEditable: editable];
381}
382
03647350 383void wxNSTextViewControl::GetSelection( long* from, long* to) const
c824c165
KO
384{
385 if (m_textView)
386 {
387 NSRange range = [m_textView selectedRange];
388 *from = range.location;
389 *to = range.location + range.length;
390 }
391}
392
393void wxNSTextViewControl::SetSelection( long from , long to )
394{
50b5e38d
SC
395 long textLength = [[m_textView string] length];
396 if ((from == -1) && (to == -1))
397 {
398 from = 0 ;
399 to = textLength ;
400 }
401 else
402 {
403 from = wxMin(textLength,wxMax(from,0)) ;
404 if ( to == -1 )
405 to = textLength;
406 else
407 to = wxMax(0,wxMin(textLength,to)) ;
408 }
409
2d6aa919
KO
410 NSRange selrange = NSMakeRange(from, to-from);
411 [m_textView setSelectedRange:selrange];
412 [m_textView scrollRangeToVisible:selrange];
c824c165
KO
413}
414
03647350 415void wxNSTextViewControl::WriteText(const wxString& str)
c824c165 416{
50b5e38d
SC
417 wxString st = str;
418 wxMacConvertNewlines10To13( &st );
5f65ba36 419 wxMacEditHelper helper(m_textView);
715824d5
SC
420 NSEvent* formerEvent = m_lastKeyDownEvent;
421 m_lastKeyDownEvent = nil;
50b5e38d 422 [m_textView insertText:wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
715824d5 423 m_lastKeyDownEvent = formerEvent;
c824c165
KO
424}
425
63bcc669 426void wxNSTextViewControl::SetFont( const wxFont & font , const wxColour& WXUNUSED(foreground) , long WXUNUSED(windowStyle), bool WXUNUSED(ignoreBlack) )
f95dd972
SC
427{
428 if ([m_textView respondsToSelector:@selector(setFont:)])
429 [m_textView setFont: font.OSXGetNSFont()];
430}
431
16671f22
KO
432bool wxNSTextViewControl::GetStyle(long position, wxTextAttr& style)
433{
b9cf2753
KO
434 if (m_textView && position >=0)
435 {
436 NSFont* font = NULL;
437 NSColor* bgcolor = NULL;
438 NSColor* fgcolor = NULL;
439 // NOTE: It appears that other platforms accept GetStyle with the position == length
440 // but that NSTextStorage does not accept length as a valid position.
441 // Therefore we return the default control style in that case.
442 if (position < [[m_textView string] length])
443 {
444 NSTextStorage* storage = [m_textView textStorage];
445 font = [[storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL] autorelease];
446 bgcolor = [[storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
447 fgcolor = [[storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
448 }
449 else
450 {
451 NSDictionary* attrs = [m_textView typingAttributes];
452 font = [[attrs objectForKey:NSFontAttributeName] autorelease];
453 bgcolor = [[attrs objectForKey:NSBackgroundColorAttributeName] autorelease];
454 fgcolor = [[attrs objectForKey:NSForegroundColorAttributeName] autorelease];
455 }
456
16671f22
KO
457 if (font)
458 style.SetFont(wxFont(font));
b9cf2753 459
16671f22
KO
460 if (bgcolor)
461 style.SetBackgroundColour(wxColour(bgcolor));
b9cf2753
KO
462
463 if (fgcolor)
464 style.SetTextColour(wxColour(fgcolor));
16671f22
KO
465 return true;
466 }
467
468 return false;
469}
470
471void wxNSTextViewControl::SetStyle(long start,
472 long end,
473 const wxTextAttr& style)
474{
475 if (m_textView) {
476 NSRange range = NSMakeRange(start, end-start);
b9cf2753
KO
477 if (start == -1 && end == -1)
478 range = [m_textView selectedRange];
479
16671f22
KO
480 NSTextStorage* storage = [m_textView textStorage];
481
482 wxFont font = style.GetFont();
b9cf2753
KO
483 if (style.HasFont() && font.IsOk())
484 [storage addAttribute:NSFontAttributeName value:font.OSXGetNSFont() range:range];
16671f22
KO
485
486 wxColour bgcolor = style.GetBackgroundColour();
b9cf2753 487 if (style.HasBackgroundColour() && bgcolor.IsOk())
16671f22
KO
488 [storage addAttribute:NSBackgroundColorAttributeName value:bgcolor.OSXGetNSColor() range:range];
489
490 wxColour fgcolor = style.GetTextColour();
b9cf2753 491 if (style.HasTextColour() && fgcolor.IsOk())
16671f22
KO
492 [storage addAttribute:NSForegroundColorAttributeName value:fgcolor.OSXGetNSColor() range:range];
493 }
494}
f95dd972 495
b9cf2753
KO
496void wxNSTextViewControl::CheckSpelling(bool check)
497{
498 if (m_textView)
499 [m_textView setContinuousSpellCheckingEnabled: check];
500}
501
9ab7ff53
KO
502wxSize wxNSTextViewControl::GetBestSize() const
503{
504 if (m_textView && [m_textView layoutManager])
505 {
506 NSRect rect = [[m_textView layoutManager] usedRectForTextContainer: [m_textView textContainer]];
507 wxSize size = wxSize(rect.size.width, rect.size.height);
508 size.x += [m_textView textContainerInset].width;
509 size.y += [m_textView textContainerInset].height;
510 return size;
511 }
c8fdb345 512 return wxSize(0,0);
9ab7ff53
KO
513}
514
c824c165
KO
515// wxNSTextFieldControl
516
c84030e0 517wxNSTextFieldControl::wxNSTextFieldControl( wxWindow *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
1e181c7a 518{
c8fdb345
SC
519 NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>) *tf = (NSTextField*) w;
520 m_textField = tf;
521 [m_textField setDelegate: tf];
50b5e38d 522 m_selStart = m_selEnd = 0;
7cb2a241 523 m_hasEditor = [w isKindOfClass:[NSTextField class]];
1e181c7a
SC
524}
525
526wxNSTextFieldControl::~wxNSTextFieldControl()
527{
c824c165
KO
528 if (m_textField)
529 [m_textField setDelegate: nil];
1e181c7a
SC
530}
531
03647350 532wxString wxNSTextFieldControl::GetStringValue() const
1e181c7a 533{
f66ecdc4 534 return wxCFStringRef::AsString([m_textField stringValue], m_wxPeer->GetFont().GetEncoding());
1e181c7a 535}
50b5e38d 536
03647350 537void wxNSTextFieldControl::SetStringValue( const wxString &str)
1e181c7a 538{
5f65ba36 539 wxMacEditHelper helper(m_textField);
e32090ba 540 [m_textField setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
1e181c7a 541}
50b5e38d 542
03647350 543void wxNSTextFieldControl::Copy()
1e181c7a 544{
e32090ba
SC
545 NSText* editor = [m_textField currentEditor];
546 if ( editor )
547 {
548 [editor copy:nil];
549 }
1e181c7a
SC
550}
551
03647350 552void wxNSTextFieldControl::Cut()
1e181c7a 553{
e32090ba
SC
554 NSText* editor = [m_textField currentEditor];
555 if ( editor )
556 {
557 [editor cut:nil];
558 }
1e181c7a
SC
559}
560
03647350 561void wxNSTextFieldControl::Paste()
1e181c7a 562{
e32090ba
SC
563 NSText* editor = [m_textField currentEditor];
564 if ( editor )
565 {
566 [editor paste:nil];
567 }
1e181c7a
SC
568}
569
03647350
VZ
570bool wxNSTextFieldControl::CanPaste() const
571{
e32090ba 572 return true;
1e181c7a
SC
573}
574
03647350 575void wxNSTextFieldControl::SetEditable(bool editable)
1e181c7a 576{
e32090ba 577 [m_textField setEditable:editable];
1e181c7a
SC
578}
579
03647350 580void wxNSTextFieldControl::GetSelection( long* from, long* to) const
1e181c7a 581{
e32090ba
SC
582 NSText* editor = [m_textField currentEditor];
583 if ( editor )
584 {
585 NSRange range = [editor selectedRange];
586 *from = range.location;
587 *to = range.location + range.length;
588 }
50b5e38d
SC
589 else
590 {
591 *from = m_selStart;
592 *to = m_selEnd;
593 }
1e181c7a
SC
594}
595
596void wxNSTextFieldControl::SetSelection( long from , long to )
597{
50b5e38d
SC
598 long textLength = [[m_textField stringValue] length];
599 if ((from == -1) && (to == -1))
600 {
601 from = 0 ;
602 to = textLength ;
603 }
604 else
605 {
606 from = wxMin(textLength,wxMax(from,0)) ;
607 if ( to == -1 )
608 to = textLength;
609 else
610 to = wxMax(0,wxMin(textLength,to)) ;
611 }
612
e32090ba
SC
613 NSText* editor = [m_textField currentEditor];
614 if ( editor )
615 {
616 [editor setSelectedRange:NSMakeRange(from, to-from)];
617 }
50b5e38d
SC
618 else
619 {
620 m_selStart = from;
621 m_selEnd = to;
622 }
1e181c7a
SC
623}
624
03647350 625void wxNSTextFieldControl::WriteText(const wxString& str)
1e181c7a 626{
715824d5
SC
627 NSEvent* formerEvent = m_lastKeyDownEvent;
628 m_lastKeyDownEvent = nil;
50b5e38d
SC
629 NSText* editor = [m_textField currentEditor];
630 if ( editor )
631 {
5f65ba36 632 wxMacEditHelper helper(m_textField);
50b5e38d
SC
633 [editor insertText:wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
634 }
635 else
636 {
637 wxString val = GetStringValue() ;
638 long start , end ;
639 GetSelection( &start , &end ) ;
640 val.Remove( start , end - start ) ;
641 val.insert( start , str ) ;
642 SetStringValue( val ) ;
643 SetSelection( start + str.length() , start + str.length() ) ;
644 }
715824d5 645 m_lastKeyDownEvent = formerEvent;
1e181c7a 646}
dbeddfb9 647
03647350 648void wxNSTextFieldControl::controlAction(WXWidget WXUNUSED(slf),
6331c8c0 649 void* WXUNUSED(_cmd), void *WXUNUSED(sender))
e32090ba
SC
650{
651 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
03647350 652 if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) )
e32090ba
SC
653 {
654 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
655 event.SetEventObject( wxpeer );
656 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
657 wxpeer->HandleWindowEvent( event );
658 }
659}
660
661//
662//
663//
664
03647350
VZ
665wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
666 wxWindowMac* WXUNUSED(parent),
667 wxWindowID WXUNUSED(id),
63bcc669 668 const wxString& WXUNUSED(str),
03647350 669 const wxPoint& pos,
dbeddfb9 670 const wxSize& size,
03647350 671 long style,
6331c8c0 672 long WXUNUSED(extraStyle))
dbeddfb9 673{
dbeddfb9 674 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
c824c165 675 wxWidgetCocoaImpl* c = NULL;
03647350 676
c824c165 677 if ( style & wxTE_MULTILINE || style & wxTE_RICH || style & wxTE_RICH2 )
b15f9375 678 {
1087c6c1
SC
679 wxNSTextScrollView* v = nil;
680 v = [[wxNSTextScrollView alloc] initWithFrame:r];
c824c165 681 c = new wxNSTextViewControl( wxpeer, v );
c824c165 682 }
03647350 683 else
c824c165 684 {
6331c8c0 685 NSTextField* v = nil;
c824c165
KO
686 if ( style & wxTE_PASSWORD )
687 v = [[wxNSSecureTextField alloc] initWithFrame:r];
688 else
689 v = [[wxNSTextField alloc] initWithFrame:r];
03647350 690
c824c165
KO
691 if ( style & wxNO_BORDER )
692 {
693 // FIXME: How can we remove the native control's border?
694 // setBordered is separate from the text ctrl's border.
695 }
03647350 696
b15f9375
SC
697 [v setBezeled:NO];
698 [v setBordered:NO];
03647350 699
c824c165 700 c = new wxNSTextFieldControl( wxpeer, v );
b15f9375 701 }
03647350 702
dbeddfb9
SC
703 return c;
704}
705
706
707#endif // wxUSE_TEXTCTRL