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__)
45 #include "wx/mac/uma.h"
49 #if wxUSE_MLTE == 0 // old textctrl implementation
51 #if !USE_SHARED_LIBRARY
52 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
54 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
55 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
56 EVT_CHAR(wxTextCtrl::OnChar
)
57 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
58 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
59 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
60 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
61 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
63 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
64 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
65 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
66 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
67 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
72 wxTextCtrl::wxTextCtrl()
76 const short kVerticalMargin
= 2 ;
77 const short kHorizontalMargin
= 2 ;
79 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
82 const wxSize
& size
, long style
,
83 const wxValidator
& validator
,
86 // base initialization
87 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
90 wxSize mySize
= size
;
91 if ( UMAHasAppearance() )
93 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
94 m_macVerticalBorder
= 5 ;
98 m_macHorizontalBorder
= 0 ; // additional pixels around the real control
99 m_macVerticalBorder
= 0 ;
106 if ( mySize
.y
== -1 )
108 if ( UMAHasAppearance() )
113 mySize
.y
+= 2 * m_macVerticalBorder
;
116 MacPreControlCreate( parent
, id
, "" , pos
, mySize
,style
, validator
, name
, &bounds
, title
) ;
118 if ( m_windowStyle
& wxTE_MULTILINE
)
120 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
121 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
123 m_windowStyle
|= wxTE_PROCESS_ENTER
;
127 m_macControl
= ::NewControl( parent
->MacGetRootWindow() , &bounds
, "\p" , true , 0 , 0 , 1,
128 ( style
& wxTE_PASSWORD
) ? kControlEditTextPasswordProc
: kControlEditTextProc
, (long) this ) ;
129 MacPostControlCreate() ;
137 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
138 (*teH
)->lineHeight
= -1 ;
141 if( wxApp::s_macDefaultEncodingIsPC
)
142 value
= wxMacMakeMacStringFromPC( st
) ;
145 ::SetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
150 wxString
wxTextCtrl::GetValue() const
153 ::GetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
154 wxBuffer
[actualsize
] = 0 ;
155 if( wxApp::s_macDefaultEncodingIsPC
)
156 return wxMacMakePCStringFromMac( wxBuffer
) ;
158 return wxString(wxBuffer
);
161 void wxTextCtrl::GetSelection(long* from
, long* to
) const
163 ControlEditTextSelectionRec selection
;
167 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
169 *from
= (**teH
).selStart
;
170 *to
= (**teH
).selEnd
;
173 void wxTextCtrl::SetValue(const wxString
& st
)
177 if( wxApp::s_macDefaultEncodingIsPC
)
178 value
= wxMacMakeMacStringFromPC( st
) ;
181 ::SetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
185 // Clipboard operations
186 void wxTextCtrl::Copy()
193 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
200 void wxTextCtrl::Cut()
207 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
211 // MacInvalidateControl() ;
215 void wxTextCtrl::Paste()
222 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
229 bool wxTextCtrl::CanCopy() const
231 // Can copy if there's a selection
233 GetSelection(& from
, & to
);
237 bool wxTextCtrl::CanCut() const
239 // Can cut if there's a selection
241 GetSelection(& from
, & to
);
245 bool wxTextCtrl::CanPaste() const
252 OSStatus err
= noErr
;
255 err
= GetCurrentScrap( &scrapRef
);
256 if ( err
!= noTypeErr
&& err
!= memFullErr
)
258 ScrapFlavorFlags flavorFlags
;
261 if (( err
= GetScrapFlavorFlags( scrapRef
, 'TEXT', &flavorFlags
)) == noErr
)
263 if (( err
= GetScrapFlavorSize( scrapRef
, 'TEXT', &byteCount
)) == noErr
)
272 if ( GetScrap( NULL
, 'TEXT' , &offset
) > 0 )
280 void wxTextCtrl::SetEditable(bool editable
)
283 UMAActivateControl( m_macControl
) ;
285 UMADeactivateControl( m_macControl
) ;
288 void wxTextCtrl::SetInsertionPoint(long pos
)
290 SetSelection( pos
, pos
) ;
293 void wxTextCtrl::SetInsertionPointEnd()
295 long pos
= GetLastPosition();
296 SetInsertionPoint(pos
);
299 long wxTextCtrl::GetInsertionPoint() const
301 ControlEditTextSelectionRec selection
;
305 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
306 // ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
307 return (**teH
).selStart
;
310 long wxTextCtrl::GetLastPosition() const
312 ControlEditTextSelectionRec selection
;
316 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
318 // ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
319 return (**teH
).teLength
;
322 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
327 ControlEditTextSelectionRec selection
;
329 selection
.selStart
= from
;
330 selection
.selEnd
= to
;
331 ::SetControlData( m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
332 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
333 TESetSelect( from
, to
, teH
) ;
335 TEInsert( value
, value
.Length() , teH
) ;
339 void wxTextCtrl::Remove(long from
, long to
)
344 ControlEditTextSelectionRec selection
;
346 selection
.selStart
= from
;
347 selection
.selEnd
= to
;
348 ::SetControlData( m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
349 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
354 void wxTextCtrl::SetSelection(long from
, long to
)
356 ControlEditTextSelectionRec selection
;
360 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
362 selection
.selStart
= from
;
363 selection
.selEnd
= to
;
365 ::SetControlData( m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
366 TESetSelect( selection
.selStart
, selection
.selEnd
, teH
) ;
369 bool wxTextCtrl::LoadFile(const wxString
& file
)
371 if ( wxTextCtrlBase::LoadFile(file
) )
379 void wxTextCtrl::WriteText(const wxString
& text
)
384 memcpy( wxBuffer
, text
, text
.Length() ) ;
385 wxBuffer
[text
.Length() ] = 0 ;
386 // wxMacConvertNewlines( wxBuffer , wxBuffer ) ;
388 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
390 TEInsert( wxBuffer
, strlen( wxBuffer
) , teH
) ;
394 void wxTextCtrl::AppendText(const wxString
& text
)
396 SetInsertionPointEnd();
400 void wxTextCtrl::Clear()
402 ::SetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 0 , (char*) ((const char*)NULL
) ) ;
406 bool wxTextCtrl::IsModified() const
411 bool wxTextCtrl::IsEditable() const
416 bool wxTextCtrl::AcceptsFocus() const
418 // we don't want focus if we can't be edited
419 return IsEditable() && wxControl::AcceptsFocus();
422 wxSize
wxTextCtrl::DoGetBestSize() const
427 if ( UMAHasAppearance() )
431 hText
+= 2 * m_macHorizontalBorder
;
434 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
436 int wText = DEFAULT_ITEM_WIDTH;
438 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
440 return wxSize(wText, hText);
442 if ( m_windowStyle
& wxTE_MULTILINE
)
444 hText
*= wxMin(GetNumberOfLines(), 5);
446 //else: for single line control everything is ok
447 return wxSize(wText
, hText
);
450 // ----------------------------------------------------------------------------
452 // ----------------------------------------------------------------------------
454 void wxTextCtrl::Undo()
461 void wxTextCtrl::Redo()
468 bool wxTextCtrl::CanUndo() const
473 bool wxTextCtrl::CanRedo() const
478 // Makes 'unmodified'
479 void wxTextCtrl::DiscardEdits()
484 int wxTextCtrl::GetNumberOfLines() const
487 ::GetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
490 for (int i
= 0; i
< actualsize
; i
++)
492 if (wxBuffer
[i
] == '\r') count
++;
498 long wxTextCtrl::XYToPosition(long x
, long y
) const
504 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
509 void wxTextCtrl::ShowPosition(long pos
)
514 int wxTextCtrl::GetLineLength(long lineNo
) const
517 ::GetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
521 for (int i
= 0; i
< actualsize
; i
++)
525 // Count chars in line then
527 for (int j
= i
; j
< actualsize
; j
++)
530 if (wxBuffer
[j
] == '\r') return count
;
535 if (wxBuffer
[i
] == '\r') count
++;
541 wxString
wxTextCtrl::GetLineText(long lineNo
) const
544 ::GetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
548 for (int i
= 0; i
< actualsize
; i
++)
552 // Add chars in line then
555 for (int j
= i
; j
< actualsize
; j
++)
557 if (wxBuffer
[j
] == '\r')
565 if (wxBuffer
[i
] == '\r') count
++;
575 void wxTextCtrl::Command(wxCommandEvent
& event
)
577 SetValue (event
.GetString());
578 ProcessCommand (event
);
581 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
583 // By default, load the first file into the text window.
584 if (event
.GetNumberOfFiles() > 0)
586 LoadFile(event
.GetFiles()[0]);
590 void wxTextCtrl::OnChar(wxKeyEvent
& key_event
)
592 bool eat_key
= FALSE
;
594 switch ( key_event
.KeyCode() )
597 if (m_windowStyle
& wxPROCESS_ENTER
)
599 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
600 event
.SetEventObject( this );
601 event
.SetString( GetValue() );
602 if ( GetEventHandler()->ProcessEvent(event
) )
605 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
607 wxWindow
*parent
= GetParent();
608 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
609 parent
= parent
->GetParent() ;
611 if ( parent
&& parent
->GetDefaultItem() )
613 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
615 if ( def
&& def
->IsEnabled() )
617 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
618 event
.SetEventObject(def
);
624 // this will make wxWindows eat the ENTER key so that
625 // we actually prevent line wrapping in a single line
633 // always produce navigation event - even if we process TAB
634 // ourselves the fact that we got here means that the user code
635 // decided to skip processing of this TAB - probably to let it
636 // do its default job.
638 wxNavigationKeyEvent eventNav
;
639 eventNav
.SetDirection(!key_event
.ShiftDown());
640 eventNav
.SetWindowChange(key_event
.ControlDown());
641 eventNav
.SetEventObject(this);
643 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
652 EventRecord
*ev
= wxTheApp
->MacGetCurrentEvent();
653 short keychar
= short(ev
->message
& charCodeMask
);
656 short keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
657 ::HandleControlKey( m_macControl
, keycode
, keychar
, ev
->modifiers
);
659 if ( keychar
>= 0x20 ||
660 key_event
.KeyCode() == WXK_RETURN
||
661 key_event
.KeyCode() == WXK_DELETE
||
662 key_event
.KeyCode() == WXK_BACK
)
664 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
665 event
.SetString( GetValue() ) ;
666 event
.SetEventObject( this );
667 GetEventHandler()->ProcessEvent(event
);
671 // ----------------------------------------------------------------------------
672 // standard handlers for standard edit menu events
673 // ----------------------------------------------------------------------------
675 void wxTextCtrl::OnCut(wxCommandEvent
& event
)
680 void wxTextCtrl::OnCopy(wxCommandEvent
& event
)
685 void wxTextCtrl::OnPaste(wxCommandEvent
& event
)
690 void wxTextCtrl::OnUndo(wxCommandEvent
& event
)
695 void wxTextCtrl::OnRedo(wxCommandEvent
& event
)
700 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
702 event
.Enable( CanCut() );
705 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
707 event
.Enable( CanCopy() );
710 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
712 event
.Enable( CanPaste() );
715 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
717 event
.Enable( CanUndo() );
720 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
722 event
.Enable( CanRedo() );
727 extern wxApp
*wxTheApp
;
728 // CS:We will replace the TextEdit by using the MultiLanguageTextEngine based on the following code written by apple
734 mUPControl implementation.
737 © Copyright 2000 Apple Computer, Inc. All rights reserved.
740 IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
741 ("Apple") in consideration of your agreement to the following terms, and your
742 use, installation, modification or redistribution of this Apple software
743 constitutes acceptance of these terms. If you do not agree with these terms,
744 please do not use, install, modify or redistribute this Apple software.
746 In consideration of your agreement to abide by the following terms, and subject
747 to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
748 copyrights in this original Apple software (the "Apple Software"), to use,
749 reproduce, modify and redistribute the Apple Software, with or without
750 modifications, in source and/or binary forms; provided that if you redistribute
751 the Apple Software in its entirety and without modifications, you must retain
752 this notice and the following text and disclaimers in all such redistributions of
753 the Apple Software. Neither the name, trademarks, service marks or logos of
754 Apple Computer, Inc. may be used to endorse or promote products derived from the
755 Apple Software without specific prior written permission from Apple. Except as
756 expressly stated in this notice, no other rights or licenses, express or implied,
757 are granted by Apple herein, including but not limited to any patent rights that
758 may be infringed by your derivative works or by other works in which the Apple
759 Software may be incorporated.
761 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
762 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
763 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
764 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
765 COMBINATION WITH YOUR PRODUCTS.
767 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
768 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
769 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
770 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
771 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
772 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
773 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
775 Change History (most recent first):
776 Fri, Jan 28, 2000 -- created
779 #include "MacTextEditor.h"
783 /* kmUPTextPart is the part code we return to indicate the user has clicked
784 in the text area of our control */
785 #define kmUPTextPart 1
787 /* kmUPScrollPart is the part code we return to indicate the user has clicked
788 in the scroll bar part of the control. */
789 #define kmUPScrollPart 2
792 /* routines for using existing user pane controls.
793 These routines are useful for cases where you would like to use an
794 existing user pane control in, say, a dialog window as a scrolling
797 /* mUPOpenControl initializes a user pane control so it will be drawn
798 and will behave as a scrolling text edit field inside of a window.
799 This routine performs all of the initialization steps necessary,
800 except it does not create the user pane control itself. theControl
801 should refer to a user pane control that you have either created
802 yourself or extracted from a dialog's control heirarchy using
803 the GetDialogItemAsControl routine. */
804 OSStatus
mUPOpenControl(ControlHandle theControl
);
806 /* mUPCloseControl deallocates all of the structures allocated
807 by mUPOpenControl. */
808 OSStatus
mUPCloseControl(ControlHandle theControl
);
812 /* routines for creating new scrolling text user pane controls.
813 These routines allow you to create new scrolling text
814 user pane controls. */
816 /* mUPCreateControl creates a new user pane control and then it passes it
817 to mUPOpenControl to initialize it as a scrolling text user pane control. */
818 OSStatus
mUPCreateControl(WindowPtr theWindow
, Rect
*bounds
, ControlHandle
*theControl
);
820 /* mUPDisposeControl calls mUPCloseControl and then it calls DisposeControl. */
821 OSStatus
mUPDisposeControl(ControlHandle theControl
);
824 /* Utility Routines */
826 /* mUPSetText replaces the contents of the selection with the unicode
827 text described by the text and count parameters:.
828 text = pointer to unicode text buffer
829 count = number of bytes in the buffer. */
830 OSStatus
mUPSetText(ControlHandle theControl
, char* text
, long count
);
832 /* mUPGetText returns the current text data being displayed inside of
833 the mUPControl. When noErr is returned, *theText contain a new
834 handle containing all of the Unicode text copied from the current
835 selection. It is the caller's responsibiliby to dispose of this handle. */
836 OSStatus
mUPGetText(ControlHandle theControl
, Handle
*theText
);
839 /* mUPSetSelection sets the text selection and autoscrolls the text view
840 so either the cursor or the selction is in the view. */
841 void mUPSetSelection(ControlHandle theControl
, long selStart
, long selEnd
);
845 /* IsmUPControl returns true if theControl is not NULL
846 and theControl refers to a mUP Control. */
847 Boolean
IsmUPControl(ControlHandle theControl
);
851 /* Edit commands for mUP Controls. */
860 /* mUPDoEditCommand performs the editing command specified
861 in the editCommand parameter. The mUPControl's text
862 and scroll bar are redrawn and updated as necessary. */
863 void mUPDoEditCommand(ControlHandle theControl
, short editCommand
);
868 /* mUPGetContents returns the entire contents of the control including the text
869 and the formatting information. */
870 OSStatus
mUPGetContents(ControlHandle theControl
, Handle
*theContents
);
871 /* mUPSetContents replaces the contents of the selection with the data stored in the handle. */
872 OSStatus
mUPSetContents(ControlHandle theControl
, Handle theContents
);
878 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
879 routine. In our focus switching routine this part code is understood
880 as meaning 'the user has clicked in the control and we need to switch
881 the current focus to ourselves before we can continue'. */
882 #define kUserClickedToFocusPart 100
885 /* kmUPClickScrollDelayTicks is a time measurement in ticks used to
886 slow the speed of 'auto scrolling' inside of our clickloop routine.
887 This value prevents the text from wizzzzzing by while the mouse
888 is being held down inside of the text area. */
889 #define kmUPClickScrollDelayTicks 3
892 /* STPTextPaneVars is a structure used for storing the the mUP Control's
893 internal variables and state information. A handle to this record is
894 stored in the pane control's reference value field using the
895 SetControlReference routine. */
898 /* OS records referenced */
899 TXNObject fTXNRec
; /* the txn record */
900 TXNFrameID fTXNFrame
; /* the txn frame ID */
901 ControlHandle fUserPaneRec
; /* handle to the user pane control */
902 WindowPtr fOwner
; /* window containing control */
903 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
905 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
906 Boolean fIsActive
; /* true while the control is drawn in the active state */
907 Boolean fTEActive
; /* reflects the activation state of the text edit record */
908 Boolean fInDialogWindow
; /* true if displayed in a dialog window */
909 /* calculated locations */
910 Rect fRTextArea
; /* area where the text is drawn */
911 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
912 Rect fRTextOutline
; /* rectangle used to draw the border */
913 RgnHandle fTextBackgroundRgn
; /* background region for the text, erased before calling TEUpdate */
914 /* our focus advance override routine */
915 EventHandlerUPP handlerUPP
;
916 EventHandlerRef handlerRef
;
922 /* Univerals Procedure Pointer variables used by the
923 mUP Control. These variables are set up
924 the first time that mUPOpenControl is called. */
925 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
926 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
927 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
928 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
929 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
930 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
931 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
933 /* events handled by our focus advance override routine */
935 static const EventTypeSpec gMLTEEvents
[] = { { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} };
936 #define kMLTEEventCount (sizeof( gMLTEEvents ) / sizeof( EventTypeSpec ))
940 /* TPActivatePaneText activates or deactivates the text edit record
941 according to the value of setActive. The primary purpose of this
942 routine is to ensure each call is only made once. */
943 static void TPActivatePaneText(STPTextPaneVars
**tpvars
, Boolean setActive
) {
944 STPTextPaneVars
*varsp
;
946 if (varsp
->fTEActive
!= setActive
) {
948 varsp
->fTEActive
= setActive
;
950 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTEActive
);
953 TXNFocus( varsp
->fTXNRec
, varsp
->fTEActive
);
958 /* TPFocusPaneText set the focus state for the text record. */
959 static void TPFocusPaneText(STPTextPaneVars
**tpvars
, Boolean setFocus
) {
960 STPTextPaneVars
*varsp
;
962 if (varsp
->fInFocus
!= setFocus
) {
963 varsp
->fInFocus
= setFocus
;
964 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
969 /* TPPaneDrawProc is called to redraw the control and for update events
970 referring to the control. This routine erases the text area's background,
971 and redraws the text. This routine assumes the scroll bar has been
972 redrawn by a call to DrawControls. */
973 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
974 STPTextPaneVars
**tpvars
, *varsp
;
977 /* set up our globals */
978 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
979 if (tpvars
!= NULL
) {
980 state
= HGetState((Handle
) tpvars
);
981 HLock((Handle
) tpvars
);
984 /* save the drawing state */
985 SetPort((**tpvars
).fDrawingEnvironment
);
986 /* verify our boundary */
987 GetControlBounds(theControl
, &bounds
);
988 if ( ! EqualRect(&bounds
, &varsp
->fRTextArea
) ) {
989 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
990 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
991 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
992 RectRgn(varsp
->fTextBackgroundRgn
, &varsp
->fRTextOutline
);
993 TXNSetFrameBounds( varsp
->fTXNRec
, bounds
.top
, bounds
.left
, bounds
.bottom
, bounds
.right
, varsp
->fTXNFrame
);
996 /* update the text region */
997 EraseRgn(varsp
->fTextBackgroundRgn
);
998 TXNDraw(varsp
->fTXNRec
, NULL
);
999 /* restore the drawing environment */
1000 /* draw the text frame and focus frame (if necessary) */
1001 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
1002 if ((**tpvars
).fIsActive
&& varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, true);
1003 /* release our globals */
1004 HSetState((Handle
) tpvars
, state
);
1009 /* TPPaneHitTestProc is called when the control manager would
1010 like to determine what part of the control the mouse resides over.
1011 We also call this routine from our tracking proc to determine how
1012 to handle mouse clicks. */
1013 static pascal ControlPartCode
TPPaneHitTestProc(ControlHandle theControl
, Point where
) {
1014 STPTextPaneVars
**tpvars
;
1015 ControlPartCode result
;
1017 /* set up our locals and lock down our globals*/
1019 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1020 if (tpvars
!= NULL
) {
1021 state
= HGetState((Handle
) tpvars
);
1022 HLock((Handle
) tpvars
);
1023 /* find the region where we clicked */
1024 if (PtInRect(where
, &(**tpvars
).fRTextArea
)) {
1025 result
= kmUPTextPart
;
1027 /* release oure globals */
1028 HSetState((Handle
) tpvars
, state
);
1037 /* TPPaneTrackingProc is called when the mouse is being held down
1038 over our control. This routine handles clicks in the text area
1039 and in the scroll bar. */
1040 static pascal ControlPartCode
TPPaneTrackingProc(ControlHandle theControl
, Point startPt
, ControlActionUPP actionProc
) {
1041 STPTextPaneVars
**tpvars
, *varsp
;
1043 ControlPartCode partCodeResult
;
1044 /* make sure we have some variables... */
1046 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1047 if (tpvars
!= NULL
) {
1049 state
= HGetState((Handle
) tpvars
);
1050 HLock((Handle
) tpvars
);
1052 /* we don't do any of these functions unless we're in focus */
1053 if ( ! varsp
->fInFocus
) {
1055 owner
= GetControlOwner(theControl
);
1056 ClearKeyboardFocus(owner
);
1057 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
1059 /* find the location for the click */
1060 switch (TPPaneHitTestProc(theControl
, startPt
)) {
1062 /* handle clicks in the text part */
1064 { SetPort((**tpvars
).fDrawingEnvironment
);
1065 TXNClick( varsp
->fTXNRec
, GetCurrentEventRecord());
1071 HSetState((Handle
) tpvars
, state
);
1073 return partCodeResult
;
1077 /* TPPaneIdleProc is our user pane idle routine. When our text field
1078 is active and in focus, we use this routine to set the cursor. */
1079 static pascal void TPPaneIdleProc(ControlHandle theControl
) {
1080 STPTextPaneVars
**tpvars
, *varsp
;
1082 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1083 if (tpvars
!= NULL
) {
1084 /* if we're not active, then we have nothing to say about the cursor */
1085 if ((**tpvars
).fIsActive
) {
1089 /* lock down the globals */
1090 state
= HGetState((Handle
) tpvars
);
1091 HLock((Handle
) tpvars
);
1093 /* get the current mouse coordinates (in our window) */
1095 SetPort(GetWindowPort(GetControlOwner(theControl
)));
1097 SetPort((GrafPtr
) GetWindowPort(GetControlOwner(theControl
)));
1100 /* there's a 'focus thing' and an 'unfocused thing' */
1101 if (varsp
->fInFocus
) {
1102 /* flash the cursor */
1103 SetPort((**tpvars
).fDrawingEnvironment
);
1104 TXNIdle(varsp
->fTXNRec
);
1105 /* set the cursor */
1106 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
1108 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
1109 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
1111 } else SetThemeCursor(kThemeArrowCursor
);
1113 /* if it's in our bounds, set the cursor */
1114 GetControlBounds(theControl
, &bounds
);
1115 if (PtInRect(mousep
, &bounds
))
1116 SetThemeCursor(kThemeArrowCursor
);
1119 HSetState((Handle
) tpvars
, state
);
1125 /* TPPaneKeyDownProc is called whenever a keydown event is directed
1126 at our control. Here, we direct the keydown event to the text
1127 edit record and redraw the scroll bar and text field as appropriate. */
1128 static pascal ControlPartCode
TPPaneKeyDownProc(ControlHandle theControl
,
1129 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
1130 STPTextPaneVars
**tpvars
;
1131 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1132 if (tpvars
!= NULL
) {
1133 if ((**tpvars
).fInFocus
) {
1134 /* turn autoscrolling on and send the key event to text edit */
1135 SetPort((**tpvars
).fDrawingEnvironment
);
1136 TXNKeyDown( (**tpvars
).fTXNRec
, GetCurrentEventRecord());
1139 return kControlEntireControl
;
1143 /* TPPaneActivateProc is called when the window containing
1144 the user pane control receives activate events. Here, we redraw
1145 the control and it's text as necessary for the activation state. */
1146 static pascal void TPPaneActivateProc(ControlHandle theControl
, Boolean activating
) {
1148 STPTextPaneVars
**tpvars
, *varsp
;
1151 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1152 if (tpvars
!= NULL
) {
1153 state
= HGetState((Handle
) tpvars
);
1154 HLock((Handle
) tpvars
);
1156 /* de/activate the text edit record */
1157 SetPort((**tpvars
).fDrawingEnvironment
);
1158 GetControlBounds(theControl
, &bounds
);
1159 varsp
->fIsActive
= activating
;
1160 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
1161 /* redraw the frame */
1162 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
1163 if (varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
);
1164 HSetState((Handle
) tpvars
, state
);
1169 /* TPPaneFocusProc is called when every the focus changes to or
1170 from our control. Herein, switch the focus appropriately
1171 according to the parameters and redraw the control as
1173 static pascal ControlPartCode
TPPaneFocusProc(ControlHandle theControl
, ControlFocusPart action
) {
1174 ControlPartCode focusResult
;
1175 STPTextPaneVars
**tpvars
, *varsp
;
1178 focusResult
= kControlFocusNoPart
;
1179 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1180 if (tpvars
!= NULL
) {
1181 state
= HGetState((Handle
) tpvars
);
1182 HLock((Handle
) tpvars
);
1184 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
1185 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
1186 and kControlFocusNextPart will be received. When the user clicks in our field
1187 and it is not the current focus, then the constant kUserClickedToFocusPart will
1188 be received. The constant kControlFocusNoPart will be received when our control
1189 is the current focus and the user clicks in another control. In your focus routine,
1190 you should respond to these codes as follows:
1192 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
1193 the control and the focus rectangle as necessary.
1195 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
1196 depending on its current state. redraw the control and the focus rectangle
1197 as appropriate for the new focus state. If the focus state is 'off', return the constant
1198 kControlFocusNoPart, otherwise return a non-zero part code.
1199 kUserClickedToFocusPart - is a constant defined for this example. You should
1200 define your own value for handling click-to-focus type events. */
1201 /* save the drawing state */
1202 SetPort((**tpvars
).fDrawingEnvironment
);
1203 /* calculate the next highlight state */
1206 case kControlFocusNoPart
:
1207 TPFocusPaneText(tpvars
, false);
1208 focusResult
= kControlFocusNoPart
;
1210 case kUserClickedToFocusPart
:
1211 TPFocusPaneText(tpvars
, true);
1214 case kControlFocusPrevPart
:
1215 case kControlFocusNextPart
:
1216 TPFocusPaneText(tpvars
, ( ! varsp
->fInFocus
));
1217 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
1220 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
1221 /* redraw the text fram and focus rectangle to indicate the
1223 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
1224 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
&& varsp
->fInFocus
);
1226 HSetState((Handle
) tpvars
, state
);
1241 //This our carbon event handler for unicode key downs
1243 static pascal OSStatus
FocusAdvanceOverride(EventHandlerCallRef myHandler
, EventRef event
, void* userData
) {
1245 STPTextPaneVars
**tpvars
;
1247 unsigned short mUnicodeText
;
1248 ByteCount charCounts
=0;
1249 /* get our window pointer */
1250 tpvars
= (STPTextPaneVars
**) userData
;
1251 window
= (**tpvars
).fOwner
;
1252 //find out how many bytes are needed
1253 err
= GetEventParameter(event
, kEventParamTextInputSendText
,
1254 typeUnicodeText
, NULL
, 0, &charCounts
, NULL
);
1255 if (err
!= noErr
) goto bail
;
1256 /* we're only looking at single characters */
1257 if (charCounts
!= 2) { err
= eventNotHandledErr
; goto bail
; }
1258 /* get the character */
1259 err
= GetEventParameter(event
, kEventParamTextInputSendText
,
1260 typeUnicodeText
, NULL
, sizeof(mUnicodeText
),
1261 &charCounts
, (char*) &mUnicodeText
);
1262 if (err
!= noErr
) goto bail
;
1263 /* if it's not the tab key, forget it... */
1264 if ((mUnicodeText
!= '\t')) { err
= eventNotHandledErr
; goto bail
; }
1265 /* advance the keyboard focus */
1266 AdvanceKeyboardFocus(window
);
1267 /* noErr lets the CEM know we handled the event */
1270 return eventNotHandledErr
;
1275 /* mUPOpenControl initializes a user pane control so it will be drawn
1276 and will behave as a scrolling text edit field inside of a window.
1277 This routine performs all of the initialization steps necessary,
1278 except it does not create the user pane control itself. theControl
1279 should refer to a user pane control that you have either created
1280 yourself or extracted from a dialog's control heirarchy using
1281 the GetDialogItemAsControl routine. */
1282 OSStatus
mUPOpenControl(ControlHandle theControl
, bool multiline
) {
1284 WindowPtr theWindow
;
1285 STPTextPaneVars
**tpvars
, *varsp
;
1287 RGBColor rgbWhite
= {0xFFFF, 0xFFFF, 0xFFFF};
1288 TXNBackground tback
;
1290 /* set up our globals */
1291 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
1292 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
1293 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
1294 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
1295 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
1296 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
1297 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
1299 /* allocate our private storage */
1300 tpvars
= (STPTextPaneVars
**) NewHandleClear(sizeof(STPTextPaneVars
));
1301 SetControlReference(theControl
, (long) tpvars
);
1302 HLock((Handle
) tpvars
);
1304 /* set the initial settings for our private data */
1305 varsp
->fInFocus
= false;
1306 varsp
->fIsActive
= true;
1307 varsp
->fTEActive
= false;
1308 varsp
->fUserPaneRec
= theControl
;
1309 theWindow
= varsp
->fOwner
= GetControlOwner(theControl
);
1311 varsp
->fDrawingEnvironment
= GetWindowPort(varsp
->fOwner
);
1313 varsp
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(varsp
->fOwner
);
1315 varsp
->fInDialogWindow
= ( GetWindowKind(varsp
->fOwner
) == kDialogWindowKind
);
1316 /* set up the user pane procedures */
1317 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
1318 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
1319 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
1320 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
1321 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
1322 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
1323 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
1324 /* calculate the rectangles used by the control */
1325 GetControlBounds(theControl
, &bounds
);
1326 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1327 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1328 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1329 /* calculate the background region for the text. In this case, it's kindof
1330 and irregular region because we're setting the scroll bar a little ways inside
1331 of the text area. */
1332 RectRgn((varsp
->fTextBackgroundRgn
= NewRgn()), &varsp
->fRTextOutline
);
1334 /* set up the drawing environment */
1335 SetPort(varsp
->fDrawingEnvironment
);
1337 /* create the new edit field */
1338 TXNNewObject(NULL
, varsp
->fOwner
, &varsp
->fRTextArea
,
1339 kTXNWantVScrollBarMask
| kTXNAlwaysWrapAtViewEdgeMask
,
1340 kTXNTextEditStyleFrameType
,
1342 kTXNSystemDefaultEncoding
,
1343 &varsp
->fTXNRec
, &varsp
->fTXNFrame
, (TXNObjectRefcon
) tpvars
);
1345 /* set the field's background */
1346 tback
.bgType
= kTXNBackgroundTypeRGB
;
1347 tback
.bg
.color
= rgbWhite
;
1348 TXNSetBackground( varsp
->fTXNRec
, &tback
);
1350 /* install our focus advance override routine */
1352 varsp
->handlerUPP
= NewEventHandlerUPP(FocusAdvanceOverride
);
1353 err
= InstallWindowEventHandler( varsp
->fOwner
, varsp
->handlerUPP
,
1354 kMLTEEventCount
, gMLTEEvents
, tpvars
, &varsp
->handlerRef
);
1356 /* unlock our storage */
1357 HUnlock((Handle
) tpvars
);
1358 /* perform final activations and setup for our text field. Here,
1359 we assume that the window is going to be the 'active' window. */
1360 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
1367 /* mUPCloseControl deallocates all of the structures allocated
1368 by mUPOpenControl. */
1369 OSStatus
mUPCloseControl(ControlHandle theControl
) {
1370 STPTextPaneVars
**tpvars
;
1372 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1373 /* release our sub records */
1374 TXNDeleteObject((**tpvars
).fTXNRec
);
1375 /* remove our focus advance override */
1376 RemoveEventHandler((**tpvars
).handlerRef
);
1377 DisposeEventHandlerUPP((**tpvars
).handlerUPP
);
1378 /* delete our private storage */
1379 DisposeHandle((Handle
) tpvars
);
1380 /* zero the control reference */
1381 SetControlReference(theControl
, 0);
1388 /* mUPSetText replaces the contents of the selection with the unicode
1389 text described by the text and count parameters:.
1390 text = pointer to unicode text buffer
1391 count = number of bytes in the buffer. */
1392 OSStatus
mUPSetText(ControlHandle theControl
, char* text
, long count
) {
1393 STPTextPaneVars
**tpvars
;
1395 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1396 /* set the text in the record */
1397 return TXNSetData( (**tpvars
).fTXNRec
, kTXNUnicodeTextData
, text
, count
,
1398 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1404 /* mUPSetSelection sets the text selection and autoscrolls the text view
1405 so either the cursor or the selction is in the view. */
1406 void mUPSetSelection(ControlHandle theControl
, long selStart
, long selEnd
) {
1407 STPTextPaneVars
**tpvars
;
1408 /* set up our locals */
1409 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1410 /* and our drawing environment as the operation
1411 may force a redraw in the text area. */
1412 SetPort((**tpvars
).fDrawingEnvironment
);
1413 /* change the selection */
1414 TXNSetSelection( (**tpvars
).fTXNRec
, selStart
, selEnd
);
1421 /* mUPGetText returns the current text data being displayed inside of
1422 the mUPControl. When noErr is returned, *theText contain a new
1423 handle containing all of the Unicode text copied from the current
1424 selection. It is the caller's responsibiliby to dispose of this handle. */
1425 OSStatus
mUPGetText(ControlHandle theControl
, Handle
*theText
) {
1426 STPTextPaneVars
**tpvars
;
1429 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1430 /* extract the text from the record */
1431 err
= TXNGetData( (**tpvars
).fTXNRec
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, theText
);
1438 /* mUPCreateControl creates a new user pane control and then it passes it
1439 to mUPOpenControl to initialize it as a scrolling text user pane control. */
1440 OSStatus
mUPCreateControl(WindowPtr theWindow
, Rect
*bounds
, ControlHandle
*theControl
) {
1442 /* the following feature set can be specified in CNTL resources by using
1443 the value 1214. When creating a user pane control, we pass this value
1444 in the 'value' parameter. */
1445 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
1446 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
1447 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
1448 /* create the control */
1449 *theControl
= NewControl(theWindow
, bounds
, "\p", true, featurSet
, 0, featurSet
, kControlUserPaneProc
, 0);
1450 /* set up the mUP specific features and data */
1451 mUPOpenControl(*theControl
);
1457 /* mUPDisposeControl calls mUPCloseControl and then it calls DisposeControl. */
1458 OSStatus
mUPDisposeControl(ControlHandle theControl
) {
1459 /* deallocate the mUP specific data */
1460 mUPCloseControl(theControl
);
1461 /* deallocate the user pane control itself */
1462 DisposeControl(theControl
);
1469 /* IsmUPControl returns true if theControl is not NULL
1470 and theControl refers to a mUP Control. */
1471 Boolean
IsmUPControl(ControlHandle theControl
) {
1473 ControlUserPaneFocusUPP localFocusProc
;
1474 /* a NULL control is not a mUP control */
1475 if (theControl
== NULL
) return false;
1476 /* check if the control is using our focus procedure */
1477 theSize
= sizeof(localFocusProc
);
1478 if (GetControlData(theControl
, kControlEntireControl
, kControlUserPaneFocusProcTag
,
1479 sizeof(localFocusProc
), &localFocusProc
, &theSize
) != noErr
) return false;
1480 if (localFocusProc
!= gTPFocusProc
) return false;
1481 /* all tests passed, it's a mUP control */
1486 /* mUPDoEditCommand performs the editing command specified
1487 in the editCommand parameter. The mUPControl's text
1488 and scroll bar are redrawn and updated as necessary. */
1489 void mUPDoEditCommand(ControlHandle theControl
, short editCommand
) {
1490 STPTextPaneVars
**tpvars
;
1491 /* set up our locals */
1492 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1493 /* and our drawing environment as the operation
1494 may force a redraw in the text area. */
1495 SetPort((**tpvars
).fDrawingEnvironment
);
1496 /* perform the editing command */
1497 switch (editCommand
) {
1499 ClearCurrentScrap();
1500 TXNCut((**tpvars
).fTXNRec
);
1501 TXNConvertToPublicScrap();
1504 ClearCurrentScrap();
1505 TXNCopy((**tpvars
).fTXNRec
);
1506 TXNConvertToPublicScrap();
1509 TXNConvertFromPublicScrap();
1510 TXNPaste((**tpvars
).fTXNRec
);
1513 TXNClear((**tpvars
).fTXNRec
);
1521 /* mUPGetContents returns the entire contents of the control including the text
1522 and the formatting information. */
1523 OSStatus
mUPGetContents(ControlHandle theControl
, Handle
*theContents
) {
1524 STPTextPaneVars
**tpvars
;
1537 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1538 if (theContents
== NULL
) return paramErr
;
1539 /* create a temporary file */
1540 err
= FindFolder(kOnSystemDisk
, kTemporaryFolderType
, true, &vRefNum
, &dirID
);
1541 if (err
!= noErr
) goto bail
;
1542 FSMakeFSSpec(vRefNum
, dirID
, "\pmUPGetContents", &tspec
);
1543 err
= FSpCreate(&tspec
, 'trsh', 'trsh', smSystemScript
);
1544 if (err
!= noErr
) goto bail
;
1547 err
= FSpOpenDF(&tspec
, fsRdWrPerm
, &trefnum
);
1548 if (err
!= noErr
) goto bail
;
1550 err
= TXNSave( (**tpvars
).fTXNRec
, kTXNTextensionFile
, 0, kTXNSystemDefaultEncoding
, &tspec
, trefnum
, 0);
1551 if (err
!= noErr
) goto bail
;
1552 /* get the file length and set the position */
1553 err
= GetEOF(trefnum
, &bytecount
);
1554 if (err
!= noErr
) goto bail
;
1555 err
= SetFPos(trefnum
, fsFromStart
, 0);
1556 if (err
!= noErr
) goto bail
;
1557 /* copy the data fork to a handle */
1558 localdata
= NewHandle(bytecount
);
1559 if (localdata
== NULL
) { err
= memFullErr
; goto bail
; }
1561 err
= FSRead(trefnum
, &bytecount
, *localdata
);
1563 if (err
!= noErr
) goto bail
;
1565 *theContents
= localdata
;
1572 if (trefnum
!= 0) FSClose(trefnum
);
1573 if (texists
) FSpDelete(&tspec
);
1574 if (localdata
!= NULL
) DisposeHandle(localdata
);
1581 /* mUPSetContents replaces the contents of the selection with the data stored in the handle. */
1582 OSStatus
mUPSetContents(ControlHandle theControl
, Handle theContents
) {
1583 STPTextPaneVars
**tpvars
;
1595 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
1596 if (theContents
== NULL
) return paramErr
;
1597 /* create a temporary file */
1598 err
= FindFolder(kOnSystemDisk
, kTemporaryFolderType
, true, &vRefNum
, &dirID
);
1599 if (err
!= noErr
) goto bail
;
1600 FSMakeFSSpec(vRefNum
, dirID
, "\pmUPSetContents", &tspec
);
1601 err
= FSpCreate(&tspec
, 'trsh', 'trsh', smSystemScript
);
1602 if (err
!= noErr
) goto bail
;
1605 err
= FSpOpenDF(&tspec
, fsRdWrPerm
, &trefnum
);
1606 if (err
!= noErr
) goto bail
;
1607 /* save the data to the temporary file */
1608 state
= HGetState(theContents
);
1610 bytecount
= GetHandleSize(theContents
);
1611 err
= FSWrite(trefnum
, &bytecount
, *theContents
);
1612 HSetState(theContents
, state
);
1613 if (err
!= noErr
) goto bail
;
1614 /* reset the file position */
1615 err
= SetFPos(trefnum
, fsFromStart
, 0);
1616 if (err
!= noErr
) goto bail
;
1618 err
= TXNSetDataFromFile((**tpvars
).fTXNRec
, trefnum
, kTXNTextensionFile
, bytecount
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1619 if (err
!= noErr
) goto bail
;
1626 if (trefnum
!= 0) FSClose(trefnum
);
1627 if (texists
) FSpDelete(&tspec
);
1631 #if !USE_SHARED_LIBRARY
1632 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
1634 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
1635 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
1636 EVT_CHAR(wxTextCtrl::OnChar
)
1637 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
1638 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
1639 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
1640 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
1641 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
1643 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
1644 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
1645 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
1646 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
1647 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
1652 wxTextCtrl::wxTextCtrl()
1656 const short kVerticalMargin
= 2 ;
1657 const short kHorizontalMargin
= 2 ;
1659 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1662 const wxSize
& size
, long style
,
1663 const wxValidator
& validator
,
1664 const wxString
& name
)
1666 // base initialization
1667 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
1670 wxSize mySize
= size
;
1671 if ( UMAHasAppearance() )
1673 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
1674 m_macVerticalBorder
= 5 ;
1678 m_macHorizontalBorder
= 0 ; // additional pixels around the real control
1679 m_macVerticalBorder
= 0 ;
1686 if ( mySize
.y
== -1 )
1688 if ( UMAHasAppearance() )
1693 mySize
.y
+= 2 * m_macVerticalBorder
;
1696 MacPreControlCreate( parent
, id
, "" , pos
, mySize
,style
, validator
, name
, &bounds
, title
) ;
1698 if ( m_windowStyle
& wxTE_MULTILINE
)
1700 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
1701 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
1703 m_windowStyle
|= wxTE_PROCESS_ENTER
;
1707 if ( style
& wxTE_PASSWORD
)
1709 m_macControl
= ::NewControl( parent
->MacGetRootWindow() , &bounds
, "\p" , true , 0 , 0 , 1,
1710 kControlEditTextPasswordProc
, (long) this ) ;
1714 if ( mUPCreateControl(parent
->MacGetRootWindow(), &bounds
, &m_macControl
) != noErr
)
1717 MacPostControlCreate() ;
1721 if( wxApp::s_macDefaultEncodingIsPC
)
1722 value
= wxMacMakeMacStringFromPC( st
) ;
1726 if ( style
& wxTE_PASSWORD
)
1728 ::SetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
1732 STPTextPaneVars
**tpvars
;
1734 tpvars
= (STPTextPaneVars
**) GetControlReference(m_macControl
);
1735 /* set the text in the record */
1736 TXNSetData( (**tpvars
).fTXNRec
, kTXNTextData
, (const char*)value
, value
.Length(),
1737 kTXNStartOffset
, kTXNEndOffset
);
1743 wxString
wxTextCtrl::GetValue() const
1746 if ( m_windowStyle
& wxTE_PASSWORD
)
1748 ::GetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 32767 , wxBuffer
, &actualsize
) ;
1752 STPTextPaneVars
**tpvars
;
1755 tpvars
= (STPTextPaneVars
**) GetControlReference(m_macControl
);
1756 /* extract the text from the record */
1758 err
= TXNGetDataEncoded( (**tpvars
).fTXNRec
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1766 actualsize
= GetHandleSize( theText
) ;
1767 strncpy( wxBuffer
, *theText
, actualsize
) ;
1768 DisposeHandle( theText
) ;
1771 wxBuffer
[actualsize
] = 0 ;
1772 if( wxApp::s_macDefaultEncodingIsPC
)
1773 return wxMacMakePCStringFromMac( wxBuffer
) ;
1775 return wxString(wxBuffer
);
1778 void wxTextCtrl::GetSelection(long* from
, long* to
) const
1780 if ( m_windowStyle
& wxTE_PASSWORD
)
1782 ControlEditTextSelectionRec selection
;
1786 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1788 *from
= (**teH
).selStart
;
1789 *to
= (**teH
).selEnd
;
1793 STPTextPaneVars
**tpvars
;
1796 tpvars
= (STPTextPaneVars
**) GetControlReference(m_macControl
);
1798 TXNGetSelection( (**tpvars
).fTXNRec
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1803 void wxTextCtrl::SetValue(const wxString
& st
)
1807 if( wxApp::s_macDefaultEncodingIsPC
)
1808 value
= wxMacMakeMacStringFromPC( st
) ;
1811 if ( m_windowStyle
& wxTE_PASSWORD
)
1813 ::SetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
1817 STPTextPaneVars
**tpvars
;
1819 tpvars
= (STPTextPaneVars
**) GetControlReference(m_macControl
);
1820 /* set the text in the record */
1821 TXNSetData( (**tpvars
).fTXNRec
, kTXNTextData
, (const char*)value
, value
.Length(),
1822 kTXNStartOffset
, kTXNEndOffset
);
1824 MacRedrawControl() ;
1827 // Clipboard operations
1828 void wxTextCtrl::Copy()
1832 if ( m_windowStyle
& wxTE_PASSWORD
)
1837 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1839 ClearCurrentScrap();
1844 mUPDoEditCommand( m_macControl
, kmUPCopy
) ;
1849 void wxTextCtrl::Cut()
1853 if ( m_windowStyle
& wxTE_PASSWORD
)
1858 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1860 ClearCurrentScrap();
1862 // MacInvalidateControl() ;
1866 mUPDoEditCommand( m_macControl
, kmUPCut
) ;
1871 void wxTextCtrl::Paste()
1875 if ( m_windowStyle
& wxTE_PASSWORD
)
1880 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1883 MacRedrawControl() ;
1887 mUPDoEditCommand( m_macControl
, kmUPPaste
) ;
1892 bool wxTextCtrl::CanCopy() const
1894 // Can copy if there's a selection
1896 GetSelection(& from
, & to
);
1897 return (from
!= to
);
1900 bool wxTextCtrl::CanCut() const
1902 // Can cut if there's a selection
1904 GetSelection(& from
, & to
);
1905 return (from
!= to
);
1908 bool wxTextCtrl::CanPaste() const
1915 OSStatus err
= noErr
;
1918 err
= GetCurrentScrap( &scrapRef
);
1919 if ( err
!= noTypeErr
&& err
!= memFullErr
)
1921 ScrapFlavorFlags flavorFlags
;
1924 if (( err
= GetScrapFlavorFlags( scrapRef
, 'TEXT', &flavorFlags
)) == noErr
)
1926 if (( err
= GetScrapFlavorSize( scrapRef
, 'TEXT', &byteCount
)) == noErr
)
1935 if ( GetScrap( NULL
, 'TEXT' , &offset
) > 0 )
1943 void wxTextCtrl::SetEditable(bool editable
)
1946 UMAActivateControl( m_macControl
) ;
1948 UMADeactivateControl( m_macControl
) ;
1951 void wxTextCtrl::SetInsertionPoint(long pos
)
1953 SetSelection( pos
, pos
) ;
1956 void wxTextCtrl::SetInsertionPointEnd()
1958 long pos
= GetLastPosition();
1959 SetInsertionPoint(pos
);
1962 long wxTextCtrl::GetInsertionPoint() const
1965 GetSelection( &begin
, &end
) ;
1969 long wxTextCtrl::GetLastPosition() const
1971 if ( m_windowStyle
& wxTE_PASSWORD
)
1974 ControlEditTextSelectionRec selection
;
1978 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
1980 // ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
1981 return (**teH
).teLength
;
1985 STPTextPaneVars
** tpvars
= (STPTextPaneVars
**) GetControlReference(m_macControl
);
1987 int actualsize
= 0 ;
1989 OSErr err
= TXNGetDataEncoded( (**tpvars
).fTXNRec
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1997 actualsize
= GetHandleSize( theText
) ;
1998 DisposeHandle( theText
) ;
2004 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
2006 if ( m_windowStyle
& wxTE_PASSWORD
)
2011 ControlEditTextSelectionRec selection
;
2013 selection
.selStart
= from
;
2014 selection
.selEnd
= to
;
2015 ::SetControlData( m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
2016 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2017 TESetSelect( from
, to
, teH
) ;
2019 TEInsert( value
, value
.Length() , teH
) ;
2028 void wxTextCtrl::Remove(long from
, long to
)
2030 if ( m_windowStyle
& wxTE_PASSWORD
)
2035 ControlEditTextSelectionRec selection
;
2037 selection
.selStart
= from
;
2038 selection
.selEnd
= to
;
2039 ::SetControlData( m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
2040 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2050 void wxTextCtrl::SetSelection(long from
, long to
)
2052 if ( m_windowStyle
& wxTE_PASSWORD
)
2054 ControlEditTextSelectionRec selection
;
2058 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2060 selection
.selStart
= from
;
2061 selection
.selEnd
= to
;
2063 ::SetControlData( m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
2064 TESetSelect( selection
.selStart
, selection
.selEnd
, teH
) ;
2068 STPTextPaneVars
**tpvars
;
2069 /* set up our locals */
2070 tpvars
= (STPTextPaneVars
**) GetControlReference(m_macControl
);
2071 /* and our drawing environment as the operation
2072 may force a redraw in the text area. */
2073 SetPort((**tpvars
).fDrawingEnvironment
);
2074 /* change the selection */
2075 TXNSetSelection( (**tpvars
).fTXNRec
, from
, to
);
2079 bool wxTextCtrl::LoadFile(const wxString
& file
)
2081 if ( wxTextCtrlBase::LoadFile(file
) )
2089 void wxTextCtrl::WriteText(const wxString
& text
)
2092 if( wxApp::s_macDefaultEncodingIsPC
)
2093 value
= wxMacMakeMacStringFromPC( text
) ;
2096 if ( m_windowStyle
& wxTE_PASSWORD
)
2101 ::GetControlData( m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &teH
, &size
) ;
2102 TEInsert( value
, value
.Length() , teH
) ;
2106 STPTextPaneVars
**tpvars
;
2108 tpvars
= (STPTextPaneVars
**) GetControlReference(m_macControl
);
2109 /* set the text in the record */
2110 TXNSetData( (**tpvars
).fTXNRec
, kTXNTextData
, (const char*)value
, value
.Length(),
2111 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
2116 void wxTextCtrl::AppendText(const wxString
& text
)
2118 SetInsertionPointEnd();
2122 void wxTextCtrl::Clear()
2124 if ( m_windowStyle
& wxTE_PASSWORD
)
2127 ::SetControlData( m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 0 , (char*) ((const char*)NULL
) ) ;
2131 mUPDoEditCommand( m_macControl
, kmUPClear
) ;
2136 bool wxTextCtrl::IsModified() const
2141 bool wxTextCtrl::IsEditable() const
2146 bool wxTextCtrl::AcceptsFocus() const
2148 // we don't want focus if we can't be edited
2149 return IsEditable() && wxControl::AcceptsFocus();
2152 wxSize
wxTextCtrl::DoGetBestSize() const
2157 if ( UMAHasAppearance() )
2161 hText
+= 2 * m_macHorizontalBorder
;
2164 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
2166 int wText = DEFAULT_ITEM_WIDTH;
2168 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2170 return wxSize(wText, hText);
2172 if ( m_windowStyle
& wxTE_MULTILINE
)
2174 hText
*= wxMin(GetNumberOfLines(), 5);
2176 //else: for single line control everything is ok
2177 return wxSize(wText
, hText
);
2180 // ----------------------------------------------------------------------------
2182 // ----------------------------------------------------------------------------
2184 void wxTextCtrl::Undo()
2191 void wxTextCtrl::Redo()
2198 bool wxTextCtrl::CanUndo() const
2203 bool wxTextCtrl::CanRedo() const
2208 // Makes 'unmodified'
2209 void wxTextCtrl::DiscardEdits()
2214 int wxTextCtrl::GetNumberOfLines() const
2216 // TODO change this if possible to reflect real lines
2217 wxString content
= GetValue() ;
2220 for (int i
= 0; i
< content
.Length() ; i
++)
2222 if (content
[i
] == '\r') count
++;
2228 long wxTextCtrl::XYToPosition(long x
, long y
) const
2234 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
2239 void wxTextCtrl::ShowPosition(long pos
)
2244 int wxTextCtrl::GetLineLength(long lineNo
) const
2246 // TODO change this if possible to reflect real lines
2247 wxString content
= GetValue() ;
2251 for (int i
= 0; i
< content
.Length() ; i
++)
2253 if (count
== lineNo
)
2255 // Count chars in line then
2257 for (int j
= i
; j
< content
.Length(); j
++)
2260 if (content
[j
] == '\r') return count
;
2265 if (content
[i
] == '\r') count
++;
2270 wxString
wxTextCtrl::GetLineText(long lineNo
) const
2272 // TODO change this if possible to reflect real lines
2273 wxString content
= GetValue() ;
2277 for (int i
= 0; i
< content
.Length() ; i
++)
2279 if (count
== lineNo
)
2281 // Add chars in line then
2284 for (int j
= i
; j
< content
.Length(); j
++)
2286 if (content
[j
] == '\r')
2294 if (content
[i
] == '\r') count
++;
2296 return wxString("");
2303 void wxTextCtrl::Command(wxCommandEvent
& event
)
2305 SetValue (event
.GetString());
2306 ProcessCommand (event
);
2309 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
2311 // By default, load the first file into the text window.
2312 if (event
.GetNumberOfFiles() > 0)
2314 LoadFile(event
.GetFiles()[0]);
2318 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
2320 switch ( event
.KeyCode() )
2323 if (m_windowStyle
& wxPROCESS_ENTER
)
2325 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
2326 event
.SetEventObject( this );
2327 if ( GetEventHandler()->ProcessEvent(event
) )
2330 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
2332 wxWindow
*parent
= GetParent();
2333 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
2334 parent
= parent
->GetParent() ;
2336 if ( parent
&& parent
->GetDefaultItem() )
2338 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
2340 if ( def
&& def
->IsEnabled() )
2342 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
2343 event
.SetEventObject(def
);
2344 def
->Command(event
);
2349 //else: multiline controls need Enter for themselves
2354 // always produce navigation event - even if we process TAB
2355 // ourselves the fact that we got here means that the user code
2356 // decided to skip processing of this TAB - probably to let it
2357 // do its default job.
2359 wxNavigationKeyEvent eventNav
;
2360 eventNav
.SetDirection(!event
.ShiftDown());
2361 eventNav
.SetWindowChange(event
.ControlDown());
2362 eventNav
.SetEventObject(this);
2364 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2372 EventRecord
*ev
= wxTheApp
->MacGetCurrentEvent() ;
2375 keychar
= short(ev
->message
& charCodeMask
);
2376 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
2377 UMAHandleControlKey( m_macControl
, keycode
, keychar
, ev
->modifiers
) ;
2378 if ( keychar
>= 0x20 || event
.KeyCode() == WXK_RETURN
|| event
.KeyCode() == WXK_DELETE
|| event
.KeyCode() == WXK_BACK
)
2380 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
2381 event
.SetString( GetValue() ) ;
2382 event
.SetEventObject( this );
2383 GetEventHandler()->ProcessEvent(event
);
2388 // ----------------------------------------------------------------------------
2389 // standard handlers for standard edit menu events
2390 // ----------------------------------------------------------------------------
2392 void wxTextCtrl::OnCut(wxCommandEvent
& event
)
2397 void wxTextCtrl::OnCopy(wxCommandEvent
& event
)
2402 void wxTextCtrl::OnPaste(wxCommandEvent
& event
)
2407 void wxTextCtrl::OnUndo(wxCommandEvent
& event
)
2412 void wxTextCtrl::OnRedo(wxCommandEvent
& event
)
2417 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
2419 event
.Enable( CanCut() );
2422 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
2424 event
.Enable( CanCopy() );
2427 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
2429 event
.Enable( CanPaste() );
2432 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
2434 event
.Enable( CanUndo() );
2437 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
2439 event
.Enable( CanRedo() );