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