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