]> git.saurik.com Git - wxWidgets.git/blame - src/osx/textctrl_osx.cpp
Fix wxDataViewRenderer::GetEllipsizeMode() for kDataBrowserTruncateTextMiddle.
[wxWidgets.git] / src / osx / textctrl_osx.cpp
CommitLineData
524c47aa
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/textctrl_osx.cpp
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"
524c47aa
SC
50
51IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase)
52
53BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
54 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
55 EVT_CHAR(wxTextCtrl::OnChar)
56 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
57 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
58 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
59 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
60 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
61 EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete)
62 EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll)
63
64 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu)
65
66 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
67 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
68 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
69 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
70 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
71 EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete)
72 EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll)
73END_EVENT_TABLE()
74
75
76void wxTextCtrl::Init()
77{
78 m_editable = true ;
79 m_dirty = false;
80
81 m_maxLength = 0;
82 m_privateContextMenu = NULL;
d9d551f6 83 m_triggerUpdateEvents = true ;
524c47aa
SC
84}
85
86wxTextCtrl::~wxTextCtrl()
87{
88#if wxUSE_MENUS
89 delete m_privateContextMenu;
90#endif
91}
92
93bool wxTextCtrl::Create( wxWindow *parent,
94 wxWindowID id,
95 const wxString& str,
96 const wxPoint& pos,
97 const wxSize& size,
98 long style,
99 const wxValidator& validator,
100 const wxString& name )
101{
102 m_macIsUserPane = false ;
103 m_editable = true ;
104
105 if ( ! (style & wxNO_BORDER) )
106 style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ;
107
108 if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
109 return false;
110
111 if ( m_windowStyle & wxTE_MULTILINE )
112 {
113 // always turn on this style for multi-line controls
114 m_windowStyle |= wxTE_PROCESS_ENTER;
115 style |= wxTE_PROCESS_ENTER ;
116 }
117
524c47aa 118
1e181c7a 119 m_peer = wxWidgetImpl::CreateTextControl( this, GetParent(), GetId(), str, pos, size, style, GetExtraStyle() );
524c47aa
SC
120
121 MacPostControlCreate(pos, size) ;
63bcc669
SC
122
123#if wxOSX_USE_COCOA
124 // under carbon everything can already be set before the MacPostControlCreate embedding takes place
125 // but under cocoa for single line textfields this only works after everything has been set up
126 GetTextPeer()->SetStringValue(str);
127#endif
128
524c47aa
SC
129 // only now the embedding is correct and we can do a positioning update
130
131 MacSuperChangedPosition() ;
132
133 if ( m_windowStyle & wxTE_READONLY)
134 SetEditable( false ) ;
135
136 SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ;
137
138 return true;
139}
140
1e181c7a 141wxTextWidgetImpl* wxTextCtrl::GetTextPeer() const
524c47aa 142{
03647350 143 return dynamic_cast<wxTextWidgetImpl*> (m_peer);
524c47aa
SC
144}
145
146void wxTextCtrl::MacSuperChangedPosition()
147{
148 wxWindow::MacSuperChangedPosition() ;
149#if wxOSX_USE_CARBON
150 GetPeer()->SuperChangedPosition() ;
151#endif
152}
153
154void wxTextCtrl::MacVisibilityChanged()
155{
156#if wxOSX_USE_CARBON
157 GetPeer()->VisibilityChanged( GetPeer()->IsVisible() );
158#endif
159}
160
161void wxTextCtrl::MacCheckSpelling(bool check)
162{
1e181c7a 163 GetTextPeer()->CheckSpelling(check);
524c47aa
SC
164}
165
33b3ade5 166wxString wxTextCtrl::DoGetValue() const
524c47aa 167{
1e181c7a 168 return GetTextPeer()->GetStringValue() ;
524c47aa
SC
169}
170
171void wxTextCtrl::GetSelection(long* from, long* to) const
172{
1e181c7a 173 GetTextPeer()->GetSelection( from , to ) ;
524c47aa
SC
174}
175
524c47aa
SC
176void wxTextCtrl::SetMaxLength(unsigned long len)
177{
178 m_maxLength = len ;
179}
180
181bool wxTextCtrl::SetFont( const wxFont& font )
182{
183 if ( !wxTextCtrlBase::SetFont( font ) )
184 return false ;
185
1e181c7a 186 GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle(), false /* dont ignore black */ ) ;
524c47aa
SC
187
188 return true ;
189}
190
191bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
192{
1e181c7a 193 GetTextPeer()->SetStyle( start , end , style ) ;
524c47aa
SC
194
195 return true ;
196}
197
198bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style)
199{
200 wxTextCtrlBase::SetDefaultStyle( style ) ;
201 SetStyle( -1 /*current selection*/ , -1 /*current selection*/ , GetDefaultStyle() ) ;
202
203 return true ;
204}
205
206// Clipboard operations
207
208void wxTextCtrl::Copy()
209{
210 if (CanCopy())
1e181c7a 211 GetTextPeer()->Copy() ;
524c47aa
SC
212}
213
214void wxTextCtrl::Cut()
215{
216 if (CanCut())
217 {
1e181c7a 218 GetTextPeer()->Cut() ;
524c47aa 219
d9d551f6
SC
220 SendTextUpdatedEvent();
221 }
524c47aa
SC
222}
223
224void wxTextCtrl::Paste()
225{
226 if (CanPaste())
227 {
1e181c7a 228 GetTextPeer()->Paste() ;
524c47aa
SC
229
230 // TODO: eventually we should add setting the default style again
d9d551f6 231 SendTextUpdatedEvent();
524c47aa
SC
232 }
233}
234
235bool wxTextCtrl::CanCopy() const
236{
237 // Can copy if there's a selection
238 long from, to;
239 GetSelection( &from, &to );
240
241 return (from != to);
242}
243
244bool wxTextCtrl::CanCut() const
245{
246 if ( !IsEditable() )
247 return false;
248
249 // Can cut if there's a selection
250 long from, to;
251 GetSelection( &from, &to );
252
253 return (from != to);
254}
255
256bool wxTextCtrl::CanPaste() const
257{
258 if (!IsEditable())
259 return false;
260
1e181c7a 261 return GetTextPeer()->CanPaste() ;
524c47aa
SC
262}
263
264void wxTextCtrl::SetEditable(bool editable)
265{
266 if ( editable != m_editable )
267 {
268 m_editable = editable ;
1e181c7a 269 GetTextPeer()->SetEditable( editable ) ;
524c47aa
SC
270 }
271}
272
273void wxTextCtrl::SetInsertionPoint(long pos)
274{
275 SetSelection( pos , pos ) ;
276}
277
278void wxTextCtrl::SetInsertionPointEnd()
279{
0b6a49c2 280 long pos = GetLastPosition();
524c47aa
SC
281 SetInsertionPoint( pos );
282}
283
284long wxTextCtrl::GetInsertionPoint() const
285{
286 long begin, end ;
287 GetSelection( &begin , &end ) ;
288
289 return begin ;
290}
291
292wxTextPos wxTextCtrl::GetLastPosition() const
293{
1e181c7a 294 return GetTextPeer()->GetLastPosition() ;
524c47aa
SC
295}
296
524c47aa
SC
297void wxTextCtrl::Remove(long from, long to)
298{
1e181c7a 299 GetTextPeer()->Remove( from , to ) ;
d9d551f6
SC
300 if ( m_triggerUpdateEvents )
301 SendTextUpdatedEvent();
524c47aa
SC
302}
303
304void wxTextCtrl::SetSelection(long from, long to)
305{
1e181c7a 306 GetTextPeer()->SetSelection( from , to ) ;
524c47aa
SC
307}
308
309void wxTextCtrl::WriteText(const wxString& str)
310{
1e181c7a 311 GetTextPeer()->WriteText( str ) ;
d9d551f6
SC
312 if ( m_triggerUpdateEvents )
313 SendTextUpdatedEvent();
524c47aa
SC
314}
315
316void wxTextCtrl::Clear()
317{
1e181c7a 318 GetTextPeer()->Clear() ;
d9d551f6 319 SendTextUpdatedEvent();
524c47aa
SC
320}
321
322bool wxTextCtrl::IsModified() const
323{
324 return m_dirty;
325}
326
327bool wxTextCtrl::IsEditable() const
328{
329 return IsEnabled() && m_editable ;
330}
331
332bool wxTextCtrl::AcceptsFocus() const
333{
334 // we don't want focus if we can't be edited
335 return /*IsEditable() && */ wxControl::AcceptsFocus();
336}
337
338wxSize wxTextCtrl::DoGetBestSize() const
339{
340 int wText, hText;
341
342 // these are the numbers from the HIG:
343 // we reduce them by the borders first
344 wText = 100 ;
345
346 switch ( m_windowVariant )
347 {
348 case wxWINDOW_VARIANT_NORMAL :
349 hText = 22 - 6 ;
350 break ;
351
352 case wxWINDOW_VARIANT_SMALL :
353 hText = 19 - 6 ;
354 break ;
355
356 case wxWINDOW_VARIANT_MINI :
357 hText = 15 - 6 ;
358 break ;
359
360 default :
361 hText = 22 - 6;
362 break ;
363 }
364
365 // as the above numbers have some free space around the text
366 // we get 5 lines like this anyway
367 if ( m_windowStyle & wxTE_MULTILINE )
368 hText *= 5 ;
369
370 if ( !HasFlag(wxNO_BORDER) )
371 hText += 6 ;
372
373 return wxSize(wText, hText);
374}
375
16671f22
KO
376bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
377{
378 return GetTextPeer()->GetStyle(position, style);
379}
380
524c47aa
SC
381// ----------------------------------------------------------------------------
382// Undo/redo
383// ----------------------------------------------------------------------------
384
385void wxTextCtrl::Undo()
386{
387 if (CanUndo())
1e181c7a 388 GetTextPeer()->Undo() ;
524c47aa
SC
389}
390
391void wxTextCtrl::Redo()
392{
393 if (CanRedo())
1e181c7a 394 GetTextPeer()->Redo() ;
524c47aa
SC
395}
396
397bool wxTextCtrl::CanUndo() const
398{
399 if ( !IsEditable() )
400 return false ;
401
1e181c7a 402 return GetTextPeer()->CanUndo() ;
524c47aa
SC
403}
404
405bool wxTextCtrl::CanRedo() const
406{
407 if ( !IsEditable() )
408 return false ;
409
1e181c7a 410 return GetTextPeer()->CanRedo() ;
524c47aa
SC
411}
412
413void wxTextCtrl::MarkDirty()
414{
415 m_dirty = true;
416}
417
418void wxTextCtrl::DiscardEdits()
419{
420 m_dirty = false;
421}
422
423int wxTextCtrl::GetNumberOfLines() const
424{
1e181c7a 425 return GetTextPeer()->GetNumberOfLines() ;
524c47aa
SC
426}
427
428long wxTextCtrl::XYToPosition(long x, long y) const
429{
1e181c7a 430 return GetTextPeer()->XYToPosition( x , y ) ;
524c47aa
SC
431}
432
433bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
434{
1e181c7a 435 return GetTextPeer()->PositionToXY( pos , x , y ) ;
524c47aa
SC
436}
437
438void wxTextCtrl::ShowPosition(long pos)
439{
1e181c7a 440 return GetTextPeer()->ShowPosition(pos) ;
524c47aa
SC
441}
442
443int wxTextCtrl::GetLineLength(long lineNo) const
444{
1e181c7a 445 return GetTextPeer()->GetLineLength(lineNo) ;
524c47aa
SC
446}
447
448wxString wxTextCtrl::GetLineText(long lineNo) const
449{
1e181c7a 450 return GetTextPeer()->GetLineText(lineNo) ;
524c47aa
SC
451}
452
453void wxTextCtrl::Command(wxCommandEvent & event)
454{
455 SetValue(event.GetString());
456 ProcessCommand(event);
457}
458
459void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
460{
461 // By default, load the first file into the text window.
462 if (event.GetNumberOfFiles() > 0)
463 LoadFile( event.GetFiles()[0] );
464}
465
466void wxTextCtrl::OnChar(wxKeyEvent& event)
467{
468 int key = event.GetKeyCode() ;
469 bool eat_key = false ;
470 long from, to;
471
472 if ( key == 'a' && event.MetaDown() )
473 {
474 SelectAll() ;
475
476 return ;
477 }
478
479 if ( key == 'c' && event.MetaDown() )
480 {
481 if ( CanCopy() )
482 Copy() ;
483
484 return ;
485 }
486
7a34307e 487 if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) &&
524c47aa
SC
488 !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
489// && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
490 )
491 {
492 // eat it
493 return ;
494 }
495
496 // Check if we have reached the max # of chars (if it is set), but still
497 // allow navigation and deletion
498 GetSelection( &from, &to );
499 if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength &&
7a34307e
VZ
500 !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) &&
501 !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) &&
524c47aa
SC
502 from == to )
503 {
504 // eat it, we don't want to add more than allowed # of characters
505
506 // TODO: generate EVT_TEXT_MAXLEN()
507 return;
508 }
509
510 // assume that any key not processed yet is going to modify the control
511 m_dirty = true;
512
513 if ( key == 'v' && event.MetaDown() )
514 {
515 if ( CanPaste() )
516 Paste() ;
517
518 return ;
519 }
520
521 if ( key == 'x' && event.MetaDown() )
522 {
523 if ( CanCut() )
524 Cut() ;
525
526 return ;
527 }
528
529 switch ( key )
530 {
531 case WXK_RETURN:
532 if (m_windowStyle & wxTE_PROCESS_ENTER)
533 {
534 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
535 event.SetEventObject( this );
536 event.SetString( GetValue() );
537 if ( HandleWindowEvent(event) )
538 return;
539 }
540
541 if ( !(m_windowStyle & wxTE_MULTILINE) )
542 {
543 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
544 if ( tlw && tlw->GetDefaultItem() )
545 {
546 wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
547 if ( def && def->IsEnabled() )
548 {
549 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
550 event.SetEventObject(def);
551 def->Command(event);
552
553 return ;
554 }
555 }
556
557 // this will make wxWidgets eat the ENTER key so that
558 // we actually prevent line wrapping in a single line text control
559 eat_key = true;
560 }
561 break;
562
563 case WXK_TAB:
564 if ( !(m_windowStyle & wxTE_PROCESS_TAB))
565 {
566 int flags = 0;
567 if (!event.ShiftDown())
568 flags |= wxNavigationKeyEvent::IsForward ;
569 if (event.ControlDown())
570 flags |= wxNavigationKeyEvent::WinChange ;
571 Navigate(flags);
572
573 return;
574 }
575 else
576 {
577 // This is necessary (don't know why);
578 // otherwise the tab will not be inserted.
579 WriteText(wxT("\t"));
580 eat_key = true;
581 }
582 break;
583
584 default:
585 break;
586 }
587
588 if (!eat_key)
589 {
590 // perform keystroke handling
591 event.Skip(true) ;
592 }
593
7cb2a241
SC
594 // osx_cocoa sends its event upon insertText
595#if wxOSX_USE_CARBON
524c47aa
SC
596 if ( ( key >= 0x20 && key < WXK_START ) ||
597 ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) ||
598 key == WXK_RETURN ||
599 key == WXK_DELETE ||
600 key == WXK_BACK)
601 {
602 wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
603 event1.SetEventObject( this );
604 wxPostEvent( GetEventHandler(), event1 );
605 }
7cb2a241 606#endif
524c47aa
SC
607}
608
609// ----------------------------------------------------------------------------
610// standard handlers for standard edit menu events
611// ----------------------------------------------------------------------------
612
613void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
614{
615 Cut();
616}
617
618void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
619{
620 Copy();
621}
622
623void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
624{
625 Paste();
626}
627
628void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
629{
630 Undo();
631}
632
633void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
634{
635 Redo();
636}
637
638void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event))
639{
640 long from, to;
641
642 GetSelection( &from, &to );
643 if (from != -1 && to != -1)
644 Remove( from, to );
645}
646
647void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event))
648{
649 SetSelection(-1, -1);
650}
651
652void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
653{
654 event.Enable( CanCut() );
655}
656
657void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
658{
659 event.Enable( CanCopy() );
660}
661
662void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
663{
664 event.Enable( CanPaste() );
665}
666
667void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
668{
669 event.Enable( CanUndo() );
670}
671
672void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
673{
674 event.Enable( CanRedo() );
675}
676
677void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event)
678{
679 long from, to;
680
681 GetSelection( &from, &to );
682 event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ;
683}
684
685void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
686{
687 event.Enable(GetLastPosition() > 0);
688}
689
690// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
691
692void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event)
693{
1e181c7a 694 if ( GetTextPeer()->HasOwnContextMenu() )
524c47aa
SC
695 {
696 event.Skip() ;
697 return ;
698 }
699
700#if wxUSE_MENUS
701 if (m_privateContextMenu == NULL)
702 {
703 m_privateContextMenu = new wxMenu;
704 m_privateContextMenu->Append(wxID_UNDO, _("&Undo"));
705 m_privateContextMenu->Append(wxID_REDO, _("&Redo"));
706 m_privateContextMenu->AppendSeparator();
707 m_privateContextMenu->Append(wxID_CUT, _("Cu&t"));
708 m_privateContextMenu->Append(wxID_COPY, _("&Copy"));
709 m_privateContextMenu->Append(wxID_PASTE, _("&Paste"));
710 m_privateContextMenu->Append(wxID_CLEAR, _("&Delete"));
711 m_privateContextMenu->AppendSeparator();
712 m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All"));
713 }
714
715 if (m_privateContextMenu != NULL)
716 PopupMenu(m_privateContextMenu);
717#endif
718}
719
720bool wxTextCtrl::MacSetupCursor( const wxPoint& pt )
721{
1e181c7a 722 if ( !GetTextPeer()->SetupCursor( pt ) )
524c47aa
SC
723 return wxWindow::MacSetupCursor( pt ) ;
724 else
725 return true ;
726}
727
728// ----------------------------------------------------------------------------
729// implementation base class
730// ----------------------------------------------------------------------------
731
16671f22
KO
732bool wxTextWidgetImpl::GetStyle(long WXUNUSED(position),
733 wxTextAttr& WXUNUSED(style))
734{
735 return false;
736}
737
1e181c7a 738void wxTextWidgetImpl::SetStyle(long WXUNUSED(start),
524c47aa
SC
739 long WXUNUSED(end),
740 const wxTextAttr& WXUNUSED(style))
741{
742}
743
1e181c7a 744void wxTextWidgetImpl::Copy()
524c47aa
SC
745{
746}
747
1e181c7a 748void wxTextWidgetImpl::Cut()
524c47aa
SC
749{
750}
751
1e181c7a 752void wxTextWidgetImpl::Paste()
524c47aa
SC
753{
754}
755
1e181c7a 756bool wxTextWidgetImpl::CanPaste() const
524c47aa
SC
757{
758 return false ;
759}
760
1e181c7a 761void wxTextWidgetImpl::SetEditable(bool WXUNUSED(editable))
524c47aa
SC
762{
763}
764
0b6a49c2 765long wxTextWidgetImpl::GetLastPosition() const
524c47aa
SC
766{
767 return GetStringValue().length() ;
768}
769
1e181c7a 770void wxTextWidgetImpl::Replace( long from , long to , const wxString &val )
524c47aa
SC
771{
772 SetSelection( from , to ) ;
773 WriteText( val ) ;
774}
775
1e181c7a 776void wxTextWidgetImpl::Remove( long from , long to )
524c47aa
SC
777{
778 SetSelection( from , to ) ;
779 WriteText( wxEmptyString) ;
780}
781
1e181c7a 782void wxTextWidgetImpl::Clear()
524c47aa
SC
783{
784 SetStringValue( wxEmptyString ) ;
785}
786
1e181c7a 787bool wxTextWidgetImpl::CanUndo() const
524c47aa
SC
788{
789 return false ;
790}
791
1e181c7a 792void wxTextWidgetImpl::Undo()
524c47aa
SC
793{
794}
795
1e181c7a 796bool wxTextWidgetImpl::CanRedo() const
524c47aa
SC
797{
798 return false ;
799}
800
1e181c7a 801void wxTextWidgetImpl::Redo()
524c47aa
SC
802{
803}
804
1e181c7a 805long wxTextWidgetImpl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const
524c47aa
SC
806{
807 return 0 ;
808}
809
1e181c7a 810bool wxTextWidgetImpl::PositionToXY(long WXUNUSED(pos),
524c47aa
SC
811 long *WXUNUSED(x),
812 long *WXUNUSED(y)) const
813{
814 return false ;
815}
816
1e181c7a 817void wxTextWidgetImpl::ShowPosition( long WXUNUSED(pos) )
524c47aa
SC
818{
819}
820
1e181c7a 821int wxTextWidgetImpl::GetNumberOfLines() const
524c47aa
SC
822{
823 ItemCount lines = 0 ;
824 wxString content = GetStringValue() ;
825 lines = 1;
826
827 for (size_t i = 0; i < content.length() ; i++)
828 {
829 if (content[i] == '\r')
830 lines++;
831 }
832
833 return lines ;
834}
835
1e181c7a 836wxString wxTextWidgetImpl::GetLineText(long lineNo) const
524c47aa
SC
837{
838 // TODO: change this if possible to reflect real lines
839 wxString content = GetStringValue() ;
840
841 // Find line first
842 int count = 0;
843 for (size_t i = 0; i < content.length() ; i++)
844 {
845 if (count == lineNo)
846 {
847 // Add chars in line then
848 wxString tmp;
849
850 for (size_t j = i; j < content.length(); j++)
851 {
852 if (content[j] == '\n')
853 return tmp;
854
855 tmp += content[j];
856 }
857
858 return tmp;
859 }
860
861 if (content[i] == '\n')
862 count++;
863 }
864
865 return wxEmptyString ;
866}
867
1e181c7a 868int wxTextWidgetImpl::GetLineLength(long lineNo) const
524c47aa
SC
869{
870 // TODO: change this if possible to reflect real lines
871 wxString content = GetStringValue() ;
872
873 // Find line first
874 int count = 0;
875 for (size_t i = 0; i < content.length() ; i++)
876 {
877 if (count == lineNo)
878 {
879 // Count chars in line then
880 count = 0;
881 for (size_t j = i; j < content.length(); j++)
882 {
883 count++;
884 if (content[j] == '\n')
885 return count;
886 }
887
888 return count;
889 }
890
891 if (content[i] == '\n')
892 count++;
893 }
894
895 return 0 ;
896}
897
524c47aa 898#endif // wxUSE_TEXTCTRL