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