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