1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textctrl.h"
21 #include <sys/types.h>
30 #include "wx/button.h"
31 #include "wx/toplevel.h"
32 #include "wx/textctrl.h"
33 #include "wx/notebook.h"
34 #include "wx/tabctrl.h"
35 #include "wx/settings.h"
36 #include "wx/filefn.h"
39 #if defined(__BORLANDC__) && !defined(__WIN32__)
41 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
47 #include <MacTextEditor.h>
49 #include "wx/mac/uma.h"
53 #if wxUSE_MLTE == 0 // old textctrl implementation
55 #if !USE_SHARED_LIBRARY
56 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
58 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
59 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
60 EVT_CHAR(wxTextCtrl::OnChar
)
61 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
62 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
63 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
64 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
65 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
67 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
68 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
69 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
70 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
71 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
76 wxTextCtrl::wxTextCtrl()
80 const short kVerticalMargin
= 2 ;
81 const short kHorizontalMargin
= 2 ;
83 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
86 const wxSize
& size
, long style
,
87 const wxValidator
& validator
,
90 // base initialization
91 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
94 wxSize mySize
= size
;
95 if ( UMAHasAppearance() )
97 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
98 m_macVerticalBorder
= 5 ;
102 m_macHorizontalBorder
= 0 ; // additional pixels around the real control
103 m_macVerticalBorder
= 0 ;
110 if ( mySize
.y
== -1 )
112 if ( UMAHasAppearance() )
117 mySize
.y
+= 2 * m_macVerticalBorder
;
120 MacPreControlCreate( parent
, id
, "" , pos
, mySize
,style
, validator
, name
, &bounds
, title
) ;
122 if ( m_windowStyle
& wxTE_MULTILINE
)
124 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
125 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
127 m_windowStyle
|= wxTE_PROCESS_ENTER
;
131 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, "\p" , true , 0 , 0 , 1,
132 ( style
& wxTE_PASSWORD
) ? kControlEditTextPasswordProc
: kControlEditTextProc
, (long) this ) ;
133 MacPostControlCreate() ;
141 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
142 (*teH
)->lineHeight
= -1 ;
145 if( wxApp::s_macDefaultEncodingIsPC
)
146 value
= wxMacMakeMacStringFromPC( st
) ;
149 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
154 wxString
wxTextCtrl::GetValue() const
157 ::GetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
158 wxBuffer
[actualsize
] = 0 ;
159 if( wxApp::s_macDefaultEncodingIsPC
)
160 return wxMacMakePCStringFromMac( wxBuffer
) ;
162 return wxString(wxBuffer
);
165 void wxTextCtrl::GetSelection(long* from
, long* to
) const
167 ControlEditTextSelectionRec selection
;
171 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
173 *from
= (**teH
).selStart
;
174 *to
= (**teH
).selEnd
;
177 void wxTextCtrl::SetValue(const wxString
& st
)
181 if( wxApp::s_macDefaultEncodingIsPC
)
182 value
= wxMacMakeMacStringFromPC( st
) ;
185 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
189 // Clipboard operations
190 void wxTextCtrl::Copy()
197 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
204 void wxTextCtrl::Cut()
211 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
215 // MacInvalidateControl() ;
219 void wxTextCtrl::Paste()
226 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
233 bool wxTextCtrl::CanCopy() const
235 // Can copy if there's a selection
237 GetSelection(& from
, & to
);
241 bool wxTextCtrl::CanCut() const
243 // Can cut if there's a selection
245 GetSelection(& from
, & to
);
249 bool wxTextCtrl::CanPaste() const
256 OSStatus err
= noErr
;
259 err
= GetCurrentScrap( &scrapRef
);
260 if ( err
!= noTypeErr
&& err
!= memFullErr
)
262 ScrapFlavorFlags flavorFlags
;
265 if (( err
= GetScrapFlavorFlags( scrapRef
, 'TEXT', &flavorFlags
)) == noErr
)
267 if (( err
= GetScrapFlavorSize( scrapRef
, 'TEXT', &byteCount
)) == noErr
)
276 if ( GetScrap( NULL
, 'TEXT' , &offset
) > 0 )
284 void wxTextCtrl::SetEditable(bool editable
)
287 UMAActivateControl( (ControlHandle
) m_macControl
) ;
289 UMADeactivateControl( (ControlHandle
) m_macControl
) ;
292 void wxTextCtrl::SetInsertionPoint(long pos
)
294 SetSelection( pos
, pos
) ;
297 void wxTextCtrl::SetInsertionPointEnd()
299 long pos
= GetLastPosition();
300 SetInsertionPoint(pos
);
303 long wxTextCtrl::GetInsertionPoint() const
305 ControlEditTextSelectionRec selection
;
309 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
310 // ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
311 return (**teH
).selStart
;
314 long wxTextCtrl::GetLastPosition() const
316 ControlEditTextSelectionRec selection
;
320 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
322 // ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
323 return (**teH
).teLength
;
326 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
331 ControlEditTextSelectionRec selection
;
333 selection
.selStart
= from
;
334 selection
.selEnd
= to
;
335 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
336 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
337 TESetSelect( from
, to
, teH
) ;
339 TEInsert( value
, value
.Length() , teH
) ;
343 void wxTextCtrl::Remove(long from
, long to
)
348 ControlEditTextSelectionRec selection
;
350 selection
.selStart
= from
;
351 selection
.selEnd
= to
;
352 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
353 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
358 void wxTextCtrl::SetSelection(long from
, long to
)
360 ControlEditTextSelectionRec selection
;
364 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
366 selection
.selStart
= from
;
367 selection
.selEnd
= to
;
369 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
370 TESetSelect( selection
.selStart
, selection
.selEnd
, teH
) ;
373 bool wxTextCtrl::LoadFile(const wxString
& file
)
375 if ( wxTextCtrlBase::LoadFile(file
) )
383 void wxTextCtrl::WriteText(const wxString
& text
)
388 memcpy( wxBuffer
, text
, text
.Length() ) ;
389 wxBuffer
[text
.Length() ] = 0 ;
390 // wxMacConvertNewlines( wxBuffer , wxBuffer ) ;
392 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
394 TEInsert( wxBuffer
, strlen( wxBuffer
) , teH
) ;
398 void wxTextCtrl::AppendText(const wxString
& text
)
400 SetInsertionPointEnd();
404 void wxTextCtrl::Clear()
406 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 0 , (char*) ((const char*)NULL
) ) ;
410 bool wxTextCtrl::IsModified() const
415 bool wxTextCtrl::IsEditable() const
420 bool wxTextCtrl::AcceptsFocus() const
422 // we don't want focus if we can't be edited
423 return IsEditable() && wxControl::AcceptsFocus();
426 wxSize
wxTextCtrl::DoGetBestSize() const
431 if ( UMAHasAppearance() )
435 hText
+= 2 * m_macHorizontalBorder
;
438 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
440 int wText = DEFAULT_ITEM_WIDTH;
442 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
444 return wxSize(wText, hText);
446 if ( m_windowStyle
& wxTE_MULTILINE
)
448 hText
*= wxMin(GetNumberOfLines(), 5);
450 //else: for single line control everything is ok
451 return wxSize(wText
, hText
);
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
458 void wxTextCtrl::Undo()
465 void wxTextCtrl::Redo()
472 bool wxTextCtrl::CanUndo() const
477 bool wxTextCtrl::CanRedo() const
482 // Makes 'unmodified'
483 void wxTextCtrl::DiscardEdits()
488 int wxTextCtrl::GetNumberOfLines() const
491 ::GetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
494 for (int i
= 0; i
< actualsize
; i
++)
496 if (wxBuffer
[i
] == '\r') count
++;
502 long wxTextCtrl::XYToPosition(long x
, long y
) const
508 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
513 void wxTextCtrl::ShowPosition(long pos
)
518 int wxTextCtrl::GetLineLength(long lineNo
) const
521 ::GetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
525 for (int i
= 0; i
< actualsize
; i
++)
529 // Count chars in line then
531 for (int j
= i
; j
< actualsize
; j
++)
534 if (wxBuffer
[j
] == '\r') return count
;
539 if (wxBuffer
[i
] == '\r') count
++;
545 wxString
wxTextCtrl::GetLineText(long lineNo
) const
548 ::GetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
552 for (int i
= 0; i
< actualsize
; i
++)
556 // Add chars in line then
559 for (int j
= i
; j
< actualsize
; j
++)
561 if (wxBuffer
[j
] == '\r')
569 if (wxBuffer
[i
] == '\r') count
++;
579 void wxTextCtrl::Command(wxCommandEvent
& event
)
581 SetValue (event
.GetString());
582 ProcessCommand (event
);
585 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
587 // By default, load the first file into the text window.
588 if (event
.GetNumberOfFiles() > 0)
590 LoadFile(event
.GetFiles()[0]);
594 void wxTextCtrl::OnChar(wxKeyEvent
& key_event
)
596 bool eat_key
= FALSE
;
598 switch ( key_event
.KeyCode() )
601 if (m_windowStyle
& wxPROCESS_ENTER
)
603 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
604 event
.SetEventObject( this );
605 event
.SetString( GetValue() );
606 if ( GetEventHandler()->ProcessEvent(event
) )
609 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
611 wxWindow
*parent
= GetParent();
612 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
613 parent
= parent
->GetParent() ;
615 if ( parent
&& parent
->GetDefaultItem() )
617 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
619 if ( def
&& def
->IsEnabled() )
621 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
622 event
.SetEventObject(def
);
628 // this will make wxWindows eat the ENTER key so that
629 // we actually prevent line wrapping in a single line
637 // always produce navigation event - even if we process TAB
638 // ourselves the fact that we got here means that the user code
639 // decided to skip processing of this TAB - probably to let it
640 // do its default job.
642 wxNavigationKeyEvent eventNav
;
643 eventNav
.SetDirection(!key_event
.ShiftDown());
644 eventNav
.SetWindowChange(key_event
.ControlDown());
645 eventNav
.SetEventObject(this);
647 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
656 EventRecord
*ev
= (EventRecord
*) wxTheApp
->MacGetCurrentEvent();
657 short keychar
= short(ev
->message
& charCodeMask
);
660 short keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
661 ::HandleControlKey( (ControlHandle
) m_macControl
, keycode
, keychar
, ev
->modifiers
);
663 if ( keychar
>= 0x20 ||
664 key_event
.KeyCode() == WXK_RETURN
||
665 key_event
.KeyCode() == WXK_DELETE
||
666 key_event
.KeyCode() == WXK_BACK
)
668 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
669 event
.SetString( GetValue() ) ;
670 event
.SetEventObject( this );
671 GetEventHandler()->ProcessEvent(event
);
675 // ----------------------------------------------------------------------------
676 // standard handlers for standard edit menu events
677 // ----------------------------------------------------------------------------
679 void wxTextCtrl::OnCut(wxCommandEvent
& event
)
684 void wxTextCtrl::OnCopy(wxCommandEvent
& event
)
689 void wxTextCtrl::OnPaste(wxCommandEvent
& event
)
694 void wxTextCtrl::OnUndo(wxCommandEvent
& event
)
699 void wxTextCtrl::OnRedo(wxCommandEvent
& event
)
704 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
706 event
.Enable( CanCut() );
709 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
711 event
.Enable( CanCopy() );
714 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
716 event
.Enable( CanPaste() );
719 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
721 event
.Enable( CanUndo() );
724 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
726 event
.Enable( CanRedo() );
731 extern wxApp
*wxTheApp
;
732 // CS:We will replace the TextEdit by using the MultiLanguageTextEngine based on the following code written by apple
738 mUPControl implementation.
741 © Copyright 2000 Apple Computer, Inc. All rights reserved.
744 IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
745 ("Apple") in consideration of your agreement to the following terms, and your
746 use, installation, modification or redistribution of this Apple software
747 constitutes acceptance of these terms. If you do not agree with these terms,
748 please do not use, install, modify or redistribute this Apple software.
750 In consideration of your agreement to abide by the following terms, and subject
751 to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
752 copyrights in this original Apple software (the "Apple Software"), to use,
753 reproduce, modify and redistribute the Apple Software, with or without
754 modifications, in source and/or binary forms; provided that if you redistribute
755 the Apple Software in its entirety and without modifications, you must retain
756 this notice and the following text and disclaimers in all such redistributions of
757 the Apple Software. Neither the name, trademarks, service marks or logos of
758 Apple Computer, Inc. may be used to endorse or promote products derived from the
759 Apple Software without specific prior written permission from Apple. Except as
760 expressly stated in this notice, no other rights or licenses, express or implied,
761 are granted by Apple herein, including but not limited to any patent rights that
762 may be infringed by your derivative works or by other works in which the Apple
763 Software may be incorporated.
765 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
766 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
767 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
768 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
769 COMBINATION WITH YOUR PRODUCTS.
771 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
772 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
773 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
774 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
775 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
776 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
777 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
779 Change History (most recent first):
780 Fri, Jan 28, 2000 -- created
783 #include "MacTextEditor.h"
787 /* kmUPTextPart is the part code we return to indicate the user has clicked
788 in the text area of our control */
789 #define kmUPTextPart 1
791 /* kmUPScrollPart is the part code we return to indicate the user has clicked
792 in the scroll bar part of the control. */
793 #define kmUPScrollPart 2
796 /* routines for using existing user pane controls.
797 These routines are useful for cases where you would like to use an
798 existing user pane control in, say, a dialog window as a scrolling
801 /* mUPOpenControl initializes a user pane control so it will be drawn
802 and will behave as a scrolling text edit field inside of a window.
803 This routine performs all of the initialization steps necessary,
804 except it does not create the user pane control itself. theControl
805 should refer to a user pane control that you have either created
806 yourself or extracted from a dialog's control heirarchy using
807 the GetDialogItemAsControl routine. */
808 OSStatus
mUPOpenControl(ControlHandle theControl
);
810 /* mUPCloseControl deallocates all of the structures allocated
811 by mUPOpenControl. */
812 OSStatus
mUPCloseControl(ControlHandle theControl
);
816 /* routines for creating new scrolling text user pane controls.
817 These routines allow you to create new scrolling text
818 user pane controls. */
820 /* mUPCreateControl creates a new user pane control and then it passes it
821 to mUPOpenControl to initialize it as a scrolling text user pane control. */
822 OSStatus
mUPCreateControl(WindowPtr theWindow
, Rect
*bounds
, ControlHandle
*theControl
);
824 /* mUPDisposeControl calls mUPCloseControl and then it calls DisposeControl. */
825 OSStatus
mUPDisposeControl(ControlHandle theControl
);
828 /* Utility Routines */
830 /* mUPSetText replaces the contents of the selection with the unicode
831 text described by the text and count parameters:.
832 text = pointer to unicode text buffer
833 count = number of bytes in the buffer. */
834 OSStatus
mUPSetText(ControlHandle theControl
, char* text
, long count
);
836 /* mUPGetText returns the current text data being displayed inside of
837 the mUPControl. When noErr is returned, *theText contain a new
838 handle containing all of the Unicode text copied from the current
839 selection. It is the caller's responsibiliby to dispose of this handle. */
840 OSStatus
mUPGetText(ControlHandle theControl
, Handle
*theText
);
843 /* mUPSetSelection sets the text selection and autoscrolls the text view
844 so either the cursor or the selction is in the view. */
845 void mUPSetSelection(ControlHandle theControl
, long selStart
, long selEnd
);
849 /* IsmUPControl returns true if theControl is not NULL
850 and theControl refers to a mUP Control. */
851 Boolean
IsmUPControl(ControlHandle theControl
);
855 /* Edit commands for mUP Controls. */
864 /* mUPDoEditCommand performs the editing command specified
865 in the editCommand parameter. The mUPControl's text
866 and scroll bar are redrawn and updated as necessary. */
867 void mUPDoEditCommand(ControlHandle theControl
, short editCommand
);
872 /* mUPGetContents returns the entire contents of the control including the text
873 and the formatting information. */
874 OSStatus
mUPGetContents(ControlHandle theControl
, Handle
*theContents
);
875 /* mUPSetContents replaces the contents of the selection with the data stored in the handle. */
876 OSStatus
mUPSetContents(ControlHandle theControl
, Handle theContents
);
882 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
883 routine. In our focus switching routine this part code is understood
884 as meaning 'the user has clicked in the control and we need to switch
885 the current focus to ourselves before we can continue'. */
886 #define kUserClickedToFocusPart 100
889 /* kmUPClickScrollDelayTicks is a time measurement in ticks used to
890 slow the speed of 'auto scrolling' inside of our clickloop routine.
891 This value prevents the text from wizzzzzing by while the mouse
892 is being held down inside of the text area. */
893 #define kmUPClickScrollDelayTicks 3
896 /* STPTextPaneVars is a structure used for storing the the mUP Control's
897 internal variables and state information. A handle to this record is
898 stored in the pane control's reference value field using the
899 SetControlReference routine. */
902 /* OS records referenced */
903 TXNObject fTXNRec
; /* the txn record */
904 TXNFrameID fTXNFrame
; /* the txn frame ID */
905 ControlHandle fUserPaneRec
; /* handle to the user pane control */
906 WindowPtr fOwner
; /* window containing control */
907 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
909 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
910 Boolean fIsActive
; /* true while the control is drawn in the active state */
911 Boolean fTEActive
; /* reflects the activation state of the text edit record */
912 Boolean fInDialogWindow
; /* true if displayed in a dialog window */
913 /* calculated locations */
914 Rect fRTextArea
; /* area where the text is drawn */
915 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
916 Rect fRTextOutline
; /* rectangle used to draw the border */
917 RgnHandle fTextBackgroundRgn
; /* background region for the text, erased before calling TEUpdate */
918 /* our focus advance override routine */
919 EventHandlerUPP handlerUPP
;
920 EventHandlerRef handlerRef
;
926 /* Univerals Procedure Pointer variables used by the
927 mUP Control. These variables are set up
928 the first time that mUPOpenControl is called. */
929 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
930 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
931 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
932 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
933 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
934 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
935 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
937 /* events handled by our focus advance override routine */
939 static const EventTypeSpec gMLTEEvents
[] = { { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} };
940 #define kMLTEEventCount (sizeof( gMLTEEvents ) / sizeof( EventTypeSpec ))
944 /* TPActivatePaneText activates or deactivates the text edit record
945 according to the value of setActive. The primary purpose of this
946 routine is to ensure each call is only made once. */
947 static void TPActivatePaneText(STPTextPaneVars
**tpvars
, Boolean setActive
) {
948 STPTextPaneVars
*varsp
;
950 if (varsp
->fTEActive
!= setActive
) {
952 varsp
->fTEActive
= setActive
;
954 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTEActive
);
957 TXNFocus( varsp
->fTXNRec
, varsp
->fTEActive
);
962 /* TPFocusPaneText set the focus state for the text record. */
963 static void TPFocusPaneText(STPTextPaneVars
**tpvars
, Boolean setFocus
) {
964 STPTextPaneVars
*varsp
;
966 if (varsp
->fInFocus
!= setFocus
) {
967 varsp
->fInFocus
= setFocus
;
968 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
973 /* TPPaneDrawProc is called to redraw the control and for update events
974 referring to the control. This routine erases the text area's background,
975 and redraws the text. This routine assumes the scroll bar has been
976 redrawn by a call to DrawControls. */
977 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
978 STPTextPaneVars
**tpvars
, *varsp
;
981 /* set up our globals */
982 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
983 if (tpvars
!= NULL
) {
984 state
= HGetState((Handle
) tpvars
);
985 HLock((Handle
) tpvars
);
988 /* save the drawing state */
989 SetPort((**tpvars
).fDrawingEnvironment
);
990 /* verify our boundary */
991 GetControlBounds(theControl
, &bounds
);
992 if ( ! EqualRect(&bounds
, &varsp
->fRTextArea
) ) {
993 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
994 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
995 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
996 RectRgn(varsp
->fTextBackgroundRgn
, &varsp
->fRTextOutline
);
997 TXNSetFrameBounds( varsp
->fTXNRec
, bounds
.top
, bounds
.left
, bounds
.bottom
, bounds
.right
, varsp
->fTXNFrame
);
1000 /* update the text region */
1001 EraseRgn(varsp
->fTextBackgroundRgn
);
1002 TXNDraw(varsp
->fTXNRec
, NULL
);
1003 /* restore the drawing environment */
1004 /* draw the text frame and focus frame (if necessary) */
1005 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
1006 if ((**tpvars
).fIsActive
&& varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, true);
1007 /* release our globals */
1008 HSetState((Handle
) tpvars
, state
);
1013 /* TPPaneHitTestProc is called when the control manager would
1014 like to determine what part of the control the mouse resides over.
1015 We also call this routine from our tracking proc to determine how
1016 to handle mouse clicks. */
1017 static pascal ControlPartCode
TPPaneHitTestProc(ControlHandle theControl
, Point where
) {
1018 STPTextPaneVars
**tpvars
;
1019 ControlPartCode result
;
1021 /* set up our locals and lock down our globals*/
1023 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1024 if (tpvars
!= NULL
) {
1025 state
= HGetState((Handle
) tpvars
);
1026 HLock((Handle
) tpvars
);
1027 /* find the region where we clicked */
1028 if (PtInRect(where
, &(**tpvars
).fRTextArea
)) {
1029 result
= kmUPTextPart
;
1031 /* release oure globals */
1032 HSetState((Handle
) tpvars
, state
);
1041 /* TPPaneTrackingProc is called when the mouse is being held down
1042 over our control. This routine handles clicks in the text area
1043 and in the scroll bar. */
1044 static pascal ControlPartCode
TPPaneTrackingProc(ControlHandle theControl
, Point startPt
, ControlActionUPP actionProc
) {
1045 STPTextPaneVars
**tpvars
, *varsp
;
1047 ControlPartCode partCodeResult
;
1048 /* make sure we have some variables... */
1050 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1051 if (tpvars
!= NULL
) {
1053 state
= HGetState((Handle
) tpvars
);
1054 HLock((Handle
) tpvars
);
1056 /* we don't do any of these functions unless we're in focus */
1057 if ( ! varsp
->fInFocus
) {
1059 owner
= GetControlOwner(theControl
);
1060 ClearKeyboardFocus(owner
);
1061 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
1063 /* find the location for the click */
1064 switch (TPPaneHitTestProc(theControl
, startPt
)) {
1066 /* handle clicks in the text part */
1068 { SetPort((**tpvars
).fDrawingEnvironment
);
1069 TXNClick( varsp
->fTXNRec
, GetCurrentEventRecord());
1075 HSetState((Handle
) tpvars
, state
);
1077 return partCodeResult
;
1081 /* TPPaneIdleProc is our user pane idle routine. When our text field
1082 is active and in focus, we use this routine to set the cursor. */
1083 static pascal void TPPaneIdleProc(ControlHandle theControl
) {
1084 STPTextPaneVars
**tpvars
, *varsp
;
1086 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1087 if (tpvars
!= NULL
) {
1088 /* if we're not active, then we have nothing to say about the cursor */
1089 if ((**tpvars
).fIsActive
) {
1093 /* lock down the globals */
1094 state
= HGetState((Handle
) tpvars
);
1095 HLock((Handle
) tpvars
);
1097 /* get the current mouse coordinates (in our window) */
1099 SetPort(GetWindowPort(GetControlOwner(theControl
)));
1101 SetPort((GrafPtr
) GetWindowPort(GetControlOwner(theControl
)));
1104 /* there's a 'focus thing' and an 'unfocused thing' */
1105 if (varsp
->fInFocus
) {
1106 /* flash the cursor */
1107 SetPort((**tpvars
).fDrawingEnvironment
);
1108 TXNIdle(varsp
->fTXNRec
);
1109 /* set the cursor */
1110 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
1112 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
1113 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
1115 } else SetThemeCursor(kThemeArrowCursor
);
1117 /* if it's in our bounds, set the cursor */
1118 GetControlBounds(theControl
, &bounds
);
1119 if (PtInRect(mousep
, &bounds
))
1120 SetThemeCursor(kThemeArrowCursor
);
1123 HSetState((Handle
) tpvars
, state
);
1129 /* TPPaneKeyDownProc is called whenever a keydown event is directed
1130 at our control. Here, we direct the keydown event to the text
1131 edit record and redraw the scroll bar and text field as appropriate. */
1132 static pascal ControlPartCode
TPPaneKeyDownProc(ControlHandle theControl
,
1133 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
1134 STPTextPaneVars
**tpvars
;
1135 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1136 if (tpvars
!= NULL
) {
1137 if ((**tpvars
).fInFocus
) {
1138 /* turn autoscrolling on and send the key event to text edit */
1139 SetPort((**tpvars
).fDrawingEnvironment
);
1140 TXNKeyDown( (**tpvars
).fTXNRec
, GetCurrentEventRecord());
1143 return kControlEntireControl
;
1147 /* TPPaneActivateProc is called when the window containing
1148 the user pane control receives activate events. Here, we redraw
1149 the control and it's text as necessary for the activation state. */
1150 static pascal void TPPaneActivateProc(ControlHandle theControl
, Boolean activating
) {
1152 STPTextPaneVars
**tpvars
, *varsp
;
1155 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1156 if (tpvars
!= NULL
) {
1157 state
= HGetState((Handle
) tpvars
);
1158 HLock((Handle
) tpvars
);
1160 /* de/activate the text edit record */
1161 SetPort((**tpvars
).fDrawingEnvironment
);
1162 GetControlBounds(theControl
, &bounds
);
1163 varsp
->fIsActive
= activating
;
1164 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
1165 /* redraw the frame */
1166 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
1167 if (varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
);
1168 HSetState((Handle
) tpvars
, state
);
1173 /* TPPaneFocusProc is called when every the focus changes to or
1174 from our control. Herein, switch the focus appropriately
1175 according to the parameters and redraw the control as
1177 static pascal ControlPartCode
TPPaneFocusProc(ControlHandle theControl
, ControlFocusPart action
) {
1178 ControlPartCode focusResult
;
1179 STPTextPaneVars
**tpvars
, *varsp
;
1182 focusResult
= kControlFocusNoPart
;
1183 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1184 if (tpvars
!= NULL
) {
1185 state
= HGetState((Handle
) tpvars
);
1186 HLock((Handle
) tpvars
);
1188 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
1189 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
1190 and kControlFocusNextPart will be received. When the user clicks in our field
1191 and it is not the current focus, then the constant kUserClickedToFocusPart will
1192 be received. The constant kControlFocusNoPart will be received when our control
1193 is the current focus and the user clicks in another control. In your focus routine,
1194 you should respond to these codes as follows:
1196 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
1197 the control and the focus rectangle as necessary.
1199 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
1200 depending on its current state. redraw the control and the focus rectangle
1201 as appropriate for the new focus state. If the focus state is 'off', return the constant
1202 kControlFocusNoPart, otherwise return a non-zero part code.
1203 kUserClickedToFocusPart - is a constant defined for this example. You should
1204 define your own value for handling click-to-focus type events. */
1205 /* save the drawing state */
1206 SetPort((**tpvars
).fDrawingEnvironment
);
1207 /* calculate the next highlight state */
1210 case kControlFocusNoPart
:
1211 TPFocusPaneText(tpvars
, false);
1212 focusResult
= kControlFocusNoPart
;
1214 case kUserClickedToFocusPart
:
1215 TPFocusPaneText(tpvars
, true);
1218 case kControlFocusPrevPart
:
1219 case kControlFocusNextPart
:
1220 TPFocusPaneText(tpvars
, ( ! varsp
->fInFocus
));
1221 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
1224 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
1225 /* redraw the text fram and focus rectangle to indicate the
1227 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
1228 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
&& varsp
->fInFocus
);
1230 HSetState((Handle
) tpvars
, state
);
1245 //This our carbon event handler for unicode key downs
1247 static pascal OSStatus
FocusAdvanceOverride(EventHandlerCallRef myHandler
, EventRef event
, void* userData
) {
1249 STPTextPaneVars
**tpvars
;
1251 unsigned short mUnicodeText
;
1252 ByteCount charCounts
=0;
1253 /* get our window pointer */
1254 tpvars
= (STPTextPaneVars
**) userData
;
1255 window
= (**tpvars
).fOwner
;
1256 //find out how many bytes are needed
1257 err
= GetEventParameter(event
, kEventParamTextInputSendText
,
1258 typeUnicodeText
, NULL
, 0, &charCounts
, NULL
);
1259 if (err
!= noErr
) goto bail
;
1260 /* we're only looking at single characters */
1261 if (charCounts
!= 2) { err
= eventNotHandledErr
; goto bail
; }
1262 /* get the character */
1263 err
= GetEventParameter(event
, kEventParamTextInputSendText
,
1264 typeUnicodeText
, NULL
, sizeof(mUnicodeText
),
1265 &charCounts
, (char*) &mUnicodeText
);
1266 if (err
!= noErr
) goto bail
;
1267 /* if it's not the tab key, forget it... */
1268 if ((mUnicodeText
!= '\t')) { err
= eventNotHandledErr
; goto bail
; }
1269 /* advance the keyboard focus */
1270 AdvanceKeyboardFocus(window
);
1271 /* noErr lets the CEM know we handled the event */
1274 return eventNotHandledErr
;
1279 /* mUPOpenControl initializes a user pane control so it will be drawn
1280 and will behave as a scrolling text edit field inside of a window.
1281 This routine performs all of the initialization steps necessary,
1282 except it does not create the user pane control itself. theControl
1283 should refer to a user pane control that you have either created
1284 yourself or extracted from a dialog's control heirarchy using
1285 the GetDialogItemAsControl routine. */
1286 OSStatus
mUPOpenControl(ControlHandle theControl
, bool multiline
) {
1288 WindowPtr theWindow
;
1289 STPTextPaneVars
**tpvars
, *varsp
;
1291 RGBColor rgbWhite
= {0xFFFF, 0xFFFF, 0xFFFF};
1292 TXNBackground tback
;
1294 /* set up our globals */
1295 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
1296 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
1297 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
1298 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
1299 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
1300 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
1301 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
1303 /* allocate our private storage */
1304 tpvars
= (STPTextPaneVars
**) NewHandleClear(sizeof(STPTextPaneVars
));
1305 SetControlReference(theControl
, (long) tpvars
);
1306 HLock((Handle
) tpvars
);
1308 /* set the initial settings for our private data */
1309 varsp
->fInFocus
= false;
1310 varsp
->fIsActive
= true;
1311 varsp
->fTEActive
= false;
1312 varsp
->fUserPaneRec
= theControl
;
1313 theWindow
= varsp
->fOwner
= GetControlOwner(theControl
);
1315 varsp
->fDrawingEnvironment
= GetWindowPort(varsp
->fOwner
);
1317 varsp
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(varsp
->fOwner
);
1319 varsp
->fInDialogWindow
= ( GetWindowKind(varsp
->fOwner
) == kDialogWindowKind
);
1320 /* set up the user pane procedures */
1321 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
1322 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
1323 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
1324 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
1325 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
1326 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
1327 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
1328 /* calculate the rectangles used by the control */
1329 GetControlBounds(theControl
, &bounds
);
1330 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1331 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1332 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1333 /* calculate the background region for the text. In this case, it's kindof
1334 and irregular region because we're setting the scroll bar a little ways inside
1335 of the text area. */
1336 RectRgn((varsp
->fTextBackgroundRgn
= NewRgn()), &varsp
->fRTextOutline
);
1338 /* set up the drawing environment */
1339 SetPort(varsp
->fDrawingEnvironment
);
1341 /* create the new edit field */
1342 TXNNewObject(NULL
, varsp
->fOwner
, &varsp
->fRTextArea
,
1343 kTXNWantVScrollBarMask
| kTXNAlwaysWrapAtViewEdgeMask
,
1344 kTXNTextEditStyleFrameType
,
1346 kTXNSystemDefaultEncoding
,
1347 &varsp
->fTXNRec
, &varsp
->fTXNFrame
, (TXNObjectRefcon
) tpvars
);
1349 /* set the field's background */
1350 tback
.bgType
= kTXNBackgroundTypeRGB
;
1351 tback
.bg
.color
= rgbWhite
;
1352 TXNSetBackground( varsp
->fTXNRec
, &tback
);
1354 /* install our focus advance override routine */
1356 varsp
->handlerUPP
= NewEventHandlerUPP(FocusAdvanceOverride
);
1357 err
= InstallWindowEventHandler( varsp
->fOwner
, varsp
->handlerUPP
,
1358 kMLTEEventCount
, gMLTEEvents
, tpvars
, &varsp
->handlerRef
);
1360 /* unlock our storage */
1361 HUnlock((Handle
) tpvars
);
1362 /* perform final activations and setup for our text field. Here,
1363 we assume that the window is going to be the 'active' window. */
1364 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
1371 /* mUPCloseControl deallocates all of the structures allocated
1372 by mUPOpenControl. */
1373 OSStatus
mUPCloseControl(ControlHandle theControl
) {
1374 STPTextPaneVars
**tpvars
;
1376 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1377 /* release our sub records */
1378 TXNDeleteObject((**tpvars
).fTXNRec
);
1379 /* remove our focus advance override */
1380 RemoveEventHandler((**tpvars
).handlerRef
);
1381 DisposeEventHandlerUPP((**tpvars
).handlerUPP
);
1382 /* delete our private storage */
1383 DisposeHandle((Handle
) tpvars
);
1384 /* zero the control reference */
1385 SetControlReference(theControl
, 0);
1392 /* mUPSetText replaces the contents of the selection with the unicode
1393 text described by the text and count parameters:.
1394 text = pointer to unicode text buffer
1395 count = number of bytes in the buffer. */
1396 OSStatus
mUPSetText(ControlHandle theControl
, char* text
, long count
) {
1397 STPTextPaneVars
**tpvars
;
1399 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1400 /* set the text in the record */
1401 return TXNSetData( (**tpvars
).fTXNRec
, kTXNUnicodeTextData
, text
, count
,
1402 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1408 /* mUPSetSelection sets the text selection and autoscrolls the text view
1409 so either the cursor or the selction is in the view. */
1410 void mUPSetSelection(ControlHandle theControl
, long selStart
, long selEnd
) {
1411 STPTextPaneVars
**tpvars
;
1412 /* set up our locals */
1413 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1414 /* and our drawing environment as the operation
1415 may force a redraw in the text area. */
1416 SetPort((**tpvars
).fDrawingEnvironment
);
1417 /* change the selection */
1418 TXNSetSelection( (**tpvars
).fTXNRec
, selStart
, selEnd
);
1425 /* mUPGetText returns the current text data being displayed inside of
1426 the mUPControl. When noErr is returned, *theText contain a new
1427 handle containing all of the Unicode text copied from the current
1428 selection. It is the caller's responsibiliby to dispose of this handle. */
1429 OSStatus
mUPGetText(ControlHandle theControl
, Handle
*theText
) {
1430 STPTextPaneVars
**tpvars
;
1433 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1434 /* extract the text from the record */
1435 err
= TXNGetData( (**tpvars
).fTXNRec
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, theText
);
1442 /* mUPCreateControl creates a new user pane control and then it passes it
1443 to mUPOpenControl to initialize it as a scrolling text user pane control. */
1444 OSStatus
mUPCreateControl(WindowPtr theWindow
, Rect
*bounds
, ControlHandle
*theControl
) {
1446 /* the following feature set can be specified in CNTL resources by using
1447 the value 1214. When creating a user pane control, we pass this value
1448 in the 'value' parameter. */
1449 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
1450 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
1451 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
1452 /* create the control */
1453 *theControl
= NewControl(theWindow
, bounds
, "\p", true, featurSet
, 0, featurSet
, kControlUserPaneProc
, 0);
1454 /* set up the mUP specific features and data */
1455 mUPOpenControl(*theControl
);
1461 /* mUPDisposeControl calls mUPCloseControl and then it calls DisposeControl. */
1462 OSStatus
mUPDisposeControl(ControlHandle theControl
) {
1463 /* deallocate the mUP specific data */
1464 mUPCloseControl(theControl
);
1465 /* deallocate the user pane control itself */
1466 DisposeControl(theControl
);
1473 /* IsmUPControl returns true if theControl is not NULL
1474 and theControl refers to a mUP Control. */
1475 Boolean
IsmUPControl(ControlHandle theControl
) {
1477 ControlUserPaneFocusUPP localFocusProc
;
1478 /* a NULL control is not a mUP control */
1479 if (theControl
== NULL
) return false;
1480 /* check if the control is using our focus procedure */
1481 theSize
= sizeof(localFocusProc
);
1482 if (GetControlData(theControl
, kControlEntireControl
, kControlUserPaneFocusProcTag
,
1483 sizeof(localFocusProc
), &localFocusProc
, &theSize
) != noErr
) return false;
1484 if (localFocusProc
!= gTPFocusProc
) return false;
1485 /* all tests passed, it's a mUP control */
1490 /* mUPDoEditCommand performs the editing command specified
1491 in the editCommand parameter. The mUPControl's text
1492 and scroll bar are redrawn and updated as necessary. */
1493 void mUPDoEditCommand(ControlHandle theControl
, short editCommand
) {
1494 STPTextPaneVars
**tpvars
;
1495 /* set up our locals */
1496 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1497 /* and our drawing environment as the operation
1498 may force a redraw in the text area. */
1499 SetPort((**tpvars
).fDrawingEnvironment
);
1500 /* perform the editing command */
1501 switch (editCommand
) {
1503 ClearCurrentScrap();
1504 TXNCut((**tpvars
).fTXNRec
);
1505 TXNConvertToPublicScrap();
1508 ClearCurrentScrap();
1509 TXNCopy((**tpvars
).fTXNRec
);
1510 TXNConvertToPublicScrap();
1513 TXNConvertFromPublicScrap();
1514 TXNPaste((**tpvars
).fTXNRec
);
1517 TXNClear((**tpvars
).fTXNRec
);
1525 /* mUPGetContents returns the entire contents of the control including the text
1526 and the formatting information. */
1527 OSStatus
mUPGetContents(ControlHandle theControl
, Handle
*theContents
) {
1528 STPTextPaneVars
**tpvars
;
1541 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1542 if (theContents
== NULL
) return paramErr
;
1543 /* create a temporary file */
1544 err
= FindFolder(kOnSystemDisk
, kTemporaryFolderType
, true, &vRefNum
, &dirID
);
1545 if (err
!= noErr
) goto bail
;
1546 FSMakeFSSpec(vRefNum
, dirID
, "\pmUPGetContents", &tspec
);
1547 err
= FSpCreate(&tspec
, 'trsh', 'trsh', smSystemScript
);
1548 if (err
!= noErr
) goto bail
;
1551 err
= FSpOpenDF(&tspec
, fsRdWrPerm
, &trefnum
);
1552 if (err
!= noErr
) goto bail
;
1554 err
= TXNSave( (**tpvars
).fTXNRec
, kTXNTextensionFile
, 0, kTXNSystemDefaultEncoding
, &tspec
, trefnum
, 0);
1555 if (err
!= noErr
) goto bail
;
1556 /* get the file length and set the position */
1557 err
= GetEOF(trefnum
, &bytecount
);
1558 if (err
!= noErr
) goto bail
;
1559 err
= SetFPos(trefnum
, fsFromStart
, 0);
1560 if (err
!= noErr
) goto bail
;
1561 /* copy the data fork to a handle */
1562 localdata
= NewHandle(bytecount
);
1563 if (localdata
== NULL
) { err
= memFullErr
; goto bail
; }
1565 err
= FSRead(trefnum
, &bytecount
, *localdata
);
1567 if (err
!= noErr
) goto bail
;
1569 *theContents
= localdata
;
1576 if (trefnum
!= 0) FSClose(trefnum
);
1577 if (texists
) FSpDelete(&tspec
);
1578 if (localdata
!= NULL
) DisposeHandle(localdata
);
1585 /* mUPSetContents replaces the contents of the selection with the data stored in the handle. */
1586 OSStatus
mUPSetContents(ControlHandle theControl
, Handle theContents
) {
1587 STPTextPaneVars
**tpvars
;
1599 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1600 if (theContents
== NULL
) return paramErr
;
1601 /* create a temporary file */
1602 err
= FindFolder(kOnSystemDisk
, kTemporaryFolderType
, true, &vRefNum
, &dirID
);
1603 if (err
!= noErr
) goto bail
;
1604 FSMakeFSSpec(vRefNum
, dirID
, "\pmUPSetContents", &tspec
);
1605 err
= FSpCreate(&tspec
, 'trsh', 'trsh', smSystemScript
);
1606 if (err
!= noErr
) goto bail
;
1609 err
= FSpOpenDF(&tspec
, fsRdWrPerm
, &trefnum
);
1610 if (err
!= noErr
) goto bail
;
1611 /* save the data to the temporary file */
1612 state
= HGetState(theContents
);
1614 bytecount
= GetHandleSize(theContents
);
1615 err
= FSWrite(trefnum
, &bytecount
, *theContents
);
1616 HSetState(theContents
, state
);
1617 if (err
!= noErr
) goto bail
;
1618 /* reset the file position */
1619 err
= SetFPos(trefnum
, fsFromStart
, 0);
1620 if (err
!= noErr
) goto bail
;
1622 err
= TXNSetDataFromFile((**tpvars
).fTXNRec
, trefnum
, kTXNTextensionFile
, bytecount
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1623 if (err
!= noErr
) goto bail
;
1630 if (trefnum
!= 0) FSClose(trefnum
);
1631 if (texists
) FSpDelete(&tspec
);
1635 #if !USE_SHARED_LIBRARY
1636 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
1638 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
1639 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
1640 EVT_CHAR(wxTextCtrl::OnChar
)
1641 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
1642 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
1643 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
1644 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
1645 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
1647 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
1648 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
1649 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
1650 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
1651 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
1656 wxTextCtrl::wxTextCtrl()
1660 const short kVerticalMargin
= 2 ;
1661 const short kHorizontalMargin
= 2 ;
1663 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1666 const wxSize
& size
, long style
,
1667 const wxValidator
& validator
,
1668 const wxString
& name
)
1670 // base initialization
1671 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
1674 wxSize mySize
= size
;
1675 if ( UMAHasAppearance() )
1677 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
1678 m_macVerticalBorder
= 5 ;
1682 m_macHorizontalBorder
= 0 ; // additional pixels around the real control
1683 m_macVerticalBorder
= 0 ;
1690 if ( mySize
.y
== -1 )
1692 if ( UMAHasAppearance() )
1697 mySize
.y
+= 2 * m_macVerticalBorder
;
1700 MacPreControlCreate( parent
, id
, "" , pos
, mySize
,style
, validator
, name
, &bounds
, title
) ;
1702 if ( m_windowStyle
& wxTE_MULTILINE
)
1704 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
1705 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
1707 m_windowStyle
|= wxTE_PROCESS_ENTER
;
1711 if ( style
& wxTE_PASSWORD
)
1713 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, "\p" , true , 0 , 0 , 1,
1714 kControlEditTextPasswordProc
, (long) this ) ;
1718 if ( mUPCreateControl(parent
->MacGetRootWindow(), &bounds
, &m_macControl
) != noErr
)
1721 MacPostControlCreate() ;
1725 if( wxApp::s_macDefaultEncodingIsPC
)
1726 value
= wxMacMakeMacStringFromPC( st
) ;
1730 if ( style
& wxTE_PASSWORD
)
1732 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
1736 STPTextPaneVars
**tpvars
;
1738 tpvars
= (STPTextPaneVars
**) GetControlReference( (ControlHandle
) m_macControl
);
1739 /* set the text in the record */
1740 TXNSetData( (**tpvars
).fTXNRec
, kTXNTextData
, (const char*)value
, value
.Length(),
1741 kTXNStartOffset
, kTXNEndOffset
);
1747 wxString
wxTextCtrl::GetValue() const
1750 if ( m_windowStyle
& wxTE_PASSWORD
)
1752 ::GetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
1756 STPTextPaneVars
**tpvars
;
1759 tpvars
= (STPTextPaneVars
**) GetControlReference( (ControlHandle
) m_macControl
);
1760 /* extract the text from the record */
1762 err
= TXNGetDataEncoded( (**tpvars
).fTXNRec
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1770 actualsize
= GetHandleSize( theText
) ;
1771 strncpy( wxBuffer
, *theText
, actualsize
) ;
1772 DisposeHandle( theText
) ;
1775 wxBuffer
[actualsize
] = 0 ;
1776 if( wxApp::s_macDefaultEncodingIsPC
)
1777 return wxMacMakePCStringFromMac( wxBuffer
) ;
1779 return wxString(wxBuffer
);
1782 void wxTextCtrl::GetSelection(long* from
, long* to
) const
1784 if ( m_windowStyle
& wxTE_PASSWORD
)
1786 ControlEditTextSelectionRec selection
;
1790 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1792 *from
= (**teH
).selStart
;
1793 *to
= (**teH
).selEnd
;
1797 STPTextPaneVars
**tpvars
;
1800 tpvars
= (STPTextPaneVars
**) GetControlReference( (ControlHandle
) m_macControl
);
1802 TXNGetSelection( (**tpvars
).fTXNRec
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1807 void wxTextCtrl::SetValue(const wxString
& st
)
1811 if( wxApp::s_macDefaultEncodingIsPC
)
1812 value
= wxMacMakeMacStringFromPC( st
) ;
1815 if ( m_windowStyle
& wxTE_PASSWORD
)
1817 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
1821 STPTextPaneVars
**tpvars
;
1823 tpvars
= (STPTextPaneVars
**) GetControlReference( (ControlHandle
) m_macControl
);
1824 /* set the text in the record */
1825 TXNSetData( (**tpvars
).fTXNRec
, kTXNTextData
, (const char*)value
, value
.Length(),
1826 kTXNStartOffset
, kTXNEndOffset
);
1828 MacRedrawControl() ;
1831 // Clipboard operations
1832 void wxTextCtrl::Copy()
1836 if ( m_windowStyle
& wxTE_PASSWORD
)
1841 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1843 ClearCurrentScrap();
1848 mUPDoEditCommand( (ControlHandle
) m_macControl
, kmUPCopy
) ;
1853 void wxTextCtrl::Cut()
1857 if ( m_windowStyle
& wxTE_PASSWORD
)
1862 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1864 ClearCurrentScrap();
1866 // MacInvalidateControl() ;
1870 mUPDoEditCommand( (ControlHandle
) m_macControl
, kmUPCut
) ;
1875 void wxTextCtrl::Paste()
1879 if ( m_windowStyle
& wxTE_PASSWORD
)
1884 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1887 MacRedrawControl() ;
1891 mUPDoEditCommand( (ControlHandle
) m_macControl
, kmUPPaste
) ;
1896 bool wxTextCtrl::CanCopy() const
1898 // Can copy if there's a selection
1900 GetSelection(& from
, & to
);
1901 return (from
!= to
);
1904 bool wxTextCtrl::CanCut() const
1906 // Can cut if there's a selection
1908 GetSelection(& from
, & to
);
1909 return (from
!= to
);
1912 bool wxTextCtrl::CanPaste() const
1919 OSStatus err
= noErr
;
1922 err
= GetCurrentScrap( &scrapRef
);
1923 if ( err
!= noTypeErr
&& err
!= memFullErr
)
1925 ScrapFlavorFlags flavorFlags
;
1928 if (( err
= GetScrapFlavorFlags( scrapRef
, 'TEXT', &flavorFlags
)) == noErr
)
1930 if (( err
= GetScrapFlavorSize( scrapRef
, 'TEXT', &byteCount
)) == noErr
)
1939 if ( GetScrap( NULL
, 'TEXT' , &offset
) > 0 )
1947 void wxTextCtrl::SetEditable(bool editable
)
1950 UMAActivateControl( (ControlHandle
) m_macControl
) ;
1952 UMADeactivateControl( (ControlHandle
) m_macControl
) ;
1955 void wxTextCtrl::SetInsertionPoint(long pos
)
1957 SetSelection( pos
, pos
) ;
1960 void wxTextCtrl::SetInsertionPointEnd()
1962 long pos
= GetLastPosition();
1963 SetInsertionPoint(pos
);
1966 long wxTextCtrl::GetInsertionPoint() const
1969 GetSelection( &begin
, &end
) ;
1973 long wxTextCtrl::GetLastPosition() const
1975 if ( m_windowStyle
& wxTE_PASSWORD
)
1978 ControlEditTextSelectionRec selection
;
1982 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1984 // ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
1985 return (**teH
).teLength
;
1989 STPTextPaneVars
** tpvars
= (STPTextPaneVars
**) GetControlReference( (ControlHandle
) m_macControl
);
1991 int actualsize
= 0 ;
1993 OSErr err
= TXNGetDataEncoded( (**tpvars
).fTXNRec
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
2001 actualsize
= GetHandleSize( theText
) ;
2002 DisposeHandle( theText
) ;
2008 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
2010 if ( m_windowStyle
& wxTE_PASSWORD
)
2015 ControlEditTextSelectionRec selection
;
2017 selection
.selStart
= from
;
2018 selection
.selEnd
= to
;
2019 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
2020 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2021 TESetSelect( from
, to
, teH
) ;
2023 TEInsert( value
, value
.Length() , teH
) ;
2032 void wxTextCtrl::Remove(long from
, long to
)
2034 if ( m_windowStyle
& wxTE_PASSWORD
)
2039 ControlEditTextSelectionRec selection
;
2041 selection
.selStart
= from
;
2042 selection
.selEnd
= to
;
2043 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
2044 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2054 void wxTextCtrl::SetSelection(long from
, long to
)
2056 if ( m_windowStyle
& wxTE_PASSWORD
)
2058 ControlEditTextSelectionRec selection
;
2062 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2064 selection
.selStart
= from
;
2065 selection
.selEnd
= to
;
2067 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
2068 TESetSelect( selection
.selStart
, selection
.selEnd
, teH
) ;
2072 STPTextPaneVars
**tpvars
;
2073 /* set up our locals */
2074 tpvars
= (STPTextPaneVars
**) GetControlReference( (ControlHandle
) m_macControl
);
2075 /* and our drawing environment as the operation
2076 may force a redraw in the text area. */
2077 SetPort((**tpvars
).fDrawingEnvironment
);
2078 /* change the selection */
2079 TXNSetSelection( (**tpvars
).fTXNRec
, from
, to
);
2083 bool wxTextCtrl::LoadFile(const wxString
& file
)
2085 if ( wxTextCtrlBase::LoadFile(file
) )
2093 void wxTextCtrl::WriteText(const wxString
& text
)
2096 if( wxApp::s_macDefaultEncodingIsPC
)
2097 value
= wxMacMakeMacStringFromPC( text
) ;
2100 if ( m_windowStyle
& wxTE_PASSWORD
)
2105 ::GetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2106 TEInsert( value
, value
.Length() , teH
) ;
2110 STPTextPaneVars
**tpvars
;
2112 tpvars
= (STPTextPaneVars
**) GetControlReference( (ControlHandle
) m_macControl
);
2113 /* set the text in the record */
2114 TXNSetData( (**tpvars
).fTXNRec
, kTXNTextData
, (const char*)value
, value
.Length(),
2115 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
2120 void wxTextCtrl::AppendText(const wxString
& text
)
2122 SetInsertionPointEnd();
2126 void wxTextCtrl::Clear()
2128 if ( m_windowStyle
& wxTE_PASSWORD
)
2131 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 0 , (char*) ((const char*)NULL
) ) ;
2135 mUPDoEditCommand( (ControlHandle
) m_macControl
, kmUPClear
) ;
2140 bool wxTextCtrl::IsModified() const
2145 bool wxTextCtrl::IsEditable() const
2150 bool wxTextCtrl::AcceptsFocus() const
2152 // we don't want focus if we can't be edited
2153 return IsEditable() && wxControl::AcceptsFocus();
2156 wxSize
wxTextCtrl::DoGetBestSize() const
2161 if ( UMAHasAppearance() )
2165 hText
+= 2 * m_macHorizontalBorder
;
2168 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
2170 int wText = DEFAULT_ITEM_WIDTH;
2172 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2174 return wxSize(wText, hText);
2176 if ( m_windowStyle
& wxTE_MULTILINE
)
2178 hText
*= wxMin(GetNumberOfLines(), 5);
2180 //else: for single line control everything is ok
2181 return wxSize(wText
, hText
);
2184 // ----------------------------------------------------------------------------
2186 // ----------------------------------------------------------------------------
2188 void wxTextCtrl::Undo()
2195 void wxTextCtrl::Redo()
2202 bool wxTextCtrl::CanUndo() const
2207 bool wxTextCtrl::CanRedo() const
2212 // Makes 'unmodified'
2213 void wxTextCtrl::DiscardEdits()
2218 int wxTextCtrl::GetNumberOfLines() const
2220 // TODO change this if possible to reflect real lines
2221 wxString content
= GetValue() ;
2224 for (int i
= 0; i
< content
.Length() ; i
++)
2226 if (content
[i
] == '\r') count
++;
2232 long wxTextCtrl::XYToPosition(long x
, long y
) const
2238 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
2243 void wxTextCtrl::ShowPosition(long pos
)
2248 int wxTextCtrl::GetLineLength(long lineNo
) const
2250 // TODO change this if possible to reflect real lines
2251 wxString content
= GetValue() ;
2255 for (int i
= 0; i
< content
.Length() ; i
++)
2257 if (count
== lineNo
)
2259 // Count chars in line then
2261 for (int j
= i
; j
< content
.Length(); j
++)
2264 if (content
[j
] == '\r') return count
;
2269 if (content
[i
] == '\r') count
++;
2274 wxString
wxTextCtrl::GetLineText(long lineNo
) const
2276 // TODO change this if possible to reflect real lines
2277 wxString content
= GetValue() ;
2281 for (int i
= 0; i
< content
.Length() ; i
++)
2283 if (count
== lineNo
)
2285 // Add chars in line then
2288 for (int j
= i
; j
< content
.Length(); j
++)
2290 if (content
[j
] == '\r')
2298 if (content
[i
] == '\r') count
++;
2300 return wxString("");
2307 void wxTextCtrl::Command(wxCommandEvent
& event
)
2309 SetValue (event
.GetString());
2310 ProcessCommand (event
);
2313 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
2315 // By default, load the first file into the text window.
2316 if (event
.GetNumberOfFiles() > 0)
2318 LoadFile(event
.GetFiles()[0]);
2322 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
2324 switch ( event
.KeyCode() )
2327 if (m_windowStyle
& wxPROCESS_ENTER
)
2329 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
2330 event
.SetEventObject( this );
2331 if ( GetEventHandler()->ProcessEvent(event
) )
2334 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
2336 wxWindow
*parent
= GetParent();
2337 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
2338 parent
= parent
->GetParent() ;
2340 if ( parent
&& parent
->GetDefaultItem() )
2342 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
2344 if ( def
&& def
->IsEnabled() )
2346 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
2347 event
.SetEventObject(def
);
2348 def
->Command(event
);
2353 //else: multiline controls need Enter for themselves
2358 // always produce navigation event - even if we process TAB
2359 // ourselves the fact that we got here means that the user code
2360 // decided to skip processing of this TAB - probably to let it
2361 // do its default job.
2363 wxNavigationKeyEvent eventNav
;
2364 eventNav
.SetDirection(!event
.ShiftDown());
2365 eventNav
.SetWindowChange(event
.ControlDown());
2366 eventNav
.SetEventObject(this);
2368 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2376 EventRecord
*ev
= wxTheApp
->MacGetCurrentEvent() ;
2379 keychar
= short(ev
->message
& charCodeMask
);
2380 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
2381 UMAHandleControlKey( (ControlHandle
) m_macControl
, keycode
, keychar
, ev
->modifiers
) ;
2382 if ( keychar
>= 0x20 || event
.KeyCode() == WXK_RETURN
|| event
.KeyCode() == WXK_DELETE
|| event
.KeyCode() == WXK_BACK
)
2384 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
2385 event
.SetString( GetValue() ) ;
2386 event
.SetEventObject( this );
2387 GetEventHandler()->ProcessEvent(event
);
2392 // ----------------------------------------------------------------------------
2393 // standard handlers for standard edit menu events
2394 // ----------------------------------------------------------------------------
2396 void wxTextCtrl::OnCut(wxCommandEvent
& event
)
2401 void wxTextCtrl::OnCopy(wxCommandEvent
& event
)
2406 void wxTextCtrl::OnPaste(wxCommandEvent
& event
)
2411 void wxTextCtrl::OnUndo(wxCommandEvent
& event
)
2416 void wxTextCtrl::OnRedo(wxCommandEvent
& event
)
2421 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
2423 event
.Enable( CanCut() );
2426 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
2428 event
.Enable( CanCopy() );
2431 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
2433 event
.Enable( CanPaste() );
2436 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
2438 event
.Enable( CanUndo() );
2441 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
2443 event
.Enable( CanRedo() );