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