#include <stat.h>
#endif
+#include "wx/msgdlg.h"
+
#if wxUSE_STD_IOSTREAM
#if wxUSE_IOSTREAMH
#include <fstream.h>
#include <Scrap.h>
#endif
#include <MacTextEditor.h>
-#include "ATSUnicode.h"
-#include "TextCommon.h"
-#include "TextEncodingConverter.h"
+#include <ATSUnicode.h>
+#include <TextCommon.h>
+#include <TextEncodingConverter.h>
#include "wx/mac/uma.h"
#define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
-extern wxApp *wxTheApp ;
extern wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ;
// CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
// moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
// an alternate path for carbon key events that routes automatically into the same wx flow of events
-#include "MacTextEditor.h"
-
/* part codes */
/* kmUPTextPart is the part code we return to indicate the user has clicked
Rect oldbounds = varsp->fRFocusOutline ;
InsetRect( &oldbounds , -1 , -1 ) ;
- InvalWindowRect( GetControlOwner( theControl ) , &oldbounds ) ;
+ if ( IsControlVisible( theControl ) )
+ InvalWindowRect( GetControlOwner( theControl ) , &oldbounds ) ;
SetRect(&varsp->fRFocusOutline, bounds.left, bounds.top, bounds.right, bounds.bottom);
SetRect(&varsp->fRTextOutline, bounds.left, bounds.top, bounds.right, bounds.bottom);
- SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) ,
- bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2));
+
+ if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER))
+ {
+ SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) ,
+ bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2));
+ }
+ else
+ {
+ SetRect(&varsp->fRTextArea, bounds.left , bounds.top ,
+ bounds.right, bounds.bottom);
+ }
RectRgn(varsp->fTextBackgroundRgn, &varsp->fRTextOutline);
- TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left,
- varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame);
+ if ( IsControlVisible( theControl ) )
+ TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left,
+ varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame);
+ else
+ TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top + 30000 , varsp->fRTextArea.left + 30000 ,
+ varsp->fRTextArea.bottom + 30000 , varsp->fRTextArea.right + 30000 , varsp->fTXNFrame);
+
}
+ if ( IsControlVisible( theControl ) )
+ {
/* update the text region */
- RGBColor white = { 65535 , 65535 , 65535 } ;
- RGBBackColor( &white ) ;
- EraseRgn(varsp->fTextBackgroundRgn);
- TXNDraw(varsp->fTXNRec, NULL);
- /* restore the drawing environment */
- /* draw the text frame and focus frame (if necessary) */
- DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
- if ((**tpvars).fIsActive && varsp->fInFocus) DrawThemeFocusRect(&varsp->fRFocusOutline, true);
- /* release our globals */
- HSetState((Handle) tpvars, state);
-
+ RGBColor white = { 65535 , 65535 , 65535 } ;
+ RGBBackColor( &white ) ;
+ EraseRgn(varsp->fTextBackgroundRgn);
+ TXNDraw(varsp->fTXNRec, NULL);
+ /* restore the drawing environment */
+ /* draw the text frame and focus frame (if necessary) */
+ if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER))
+ {
+ DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
+ if ((**tpvars).fIsActive && varsp->fInFocus)
+ DrawThemeFocusRect(&varsp->fRFocusOutline, true);
+ }
+ /* release our globals */
+ HSetState((Handle) tpvars, state);
+ }
}
}
/* set up our locals and lock down our globals*/
result = 0;
tpvars = (STPTextPaneVars **) GetControlReference(theControl);
- if (tpvars != NULL) {
+ if (tpvars != NULL && IsControlVisible( theControl) ) {
state = HGetState((Handle) tpvars);
HLock((Handle) tpvars);
/* find the region where we clicked */
/* make sure we have some variables... */
partCodeResult = 0;
tpvars = (STPTextPaneVars **) GetControlReference(theControl);
- if (tpvars != NULL) {
+ if (tpvars != NULL && IsControlVisible( theControl ) ) {
/* lock 'em down */
state = HGetState((Handle) tpvars);
HLock((Handle) tpvars);
STPTextPaneVars **tpvars, *varsp;
/* set up locals */
tpvars = (STPTextPaneVars **) GetControlReference(theControl);
- if (tpvars != NULL) {
+ if (tpvars != NULL && IsControlVisible( theControl ) ) {
/* if we're not active, then we have nothing to say about the cursor */
if ((**tpvars).fIsActive) {
char state;
/* de/activate the text edit record */
SetPort((**tpvars).fDrawingEnvironment);
wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ;
- GetControlBounds(theControl, &bounds);
- varsp->fIsActive = activating;
- TPActivatePaneText(tpvars, varsp->fIsActive && varsp->fInFocus);
+ GetControlBounds(theControl, &bounds);
+ varsp->fIsActive = activating;
+ TPActivatePaneText(tpvars, varsp->fIsActive && varsp->fInFocus);
/* redraw the frame */
- DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
- if (varsp->fInFocus) DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive);
+ if ( IsControlVisible( theControl ) )
+ {
+ if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER))
+ {
+ DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
+ if (varsp->fInFocus)
+ DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive);
+ }
+ }
HSetState((Handle) tpvars, state);
}
}
/* set up locals */
focusResult = kControlFocusNoPart;
tpvars = (STPTextPaneVars **) GetControlReference(theControl);
- if (tpvars != NULL) {
+ if (tpvars != NULL ) {
state = HGetState((Handle) tpvars);
HLock((Handle) tpvars);
varsp = *tpvars;
kControlFocusNoPart, otherwise return a non-zero part code.
kUserClickedToFocusPart - is a constant defined for this example. You should
define your own value for handling click-to-focus type events. */
- /* save the drawing state */
- SetPort((**tpvars).fDrawingEnvironment);
- wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ;
- /* calculate the next highlight state */
+ /* calculate the next highlight state */
switch (action) {
default:
case kControlFocusNoPart:
focusResult = varsp->fInFocus ? 1 : kControlFocusNoPart;
break;
}
- TPActivatePaneText(tpvars, varsp->fIsActive && varsp->fInFocus);
- /* redraw the text fram and focus rectangle to indicate the
- new focus state */
- DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
- DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive && varsp->fInFocus);
+ TPActivatePaneText(tpvars, varsp->fIsActive && varsp->fInFocus);
+ /* redraw the text fram and focus rectangle to indicate the
+ new focus state */
+ if ( IsControlVisible( theControl ) )
+ {
+ if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER))
+ {
+ /* save the drawing state */
+ SetPort((**tpvars).fDrawingEnvironment);
+ wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ;
+ DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
+ DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive && varsp->fInFocus);
+ }
+ }
/* done */
HSetState((Handle) tpvars, state);
}
GetControlBounds(theControl, &bounds);
SetRect(&varsp->fRFocusOutline, bounds.left, bounds.top, bounds.right, bounds.bottom);
SetRect(&varsp->fRTextOutline, bounds.left, bounds.top, bounds.right, bounds.bottom);
- SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) ,
- bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2));
+ if ((wxStyle & wxNO_BORDER) != wxNO_BORDER)
+ {
+ SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) ,
+ bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2));
+ }
+ else
+ {
+ SetRect(&varsp->fRTextArea, bounds.left , bounds.top ,
+ bounds.right, bounds.bottom);
+ }
+
/* calculate the background region for the text. In this case, it's kindof
and irregular region because we're setting the scroll bar a little ways inside
of the text area. */
kTXNSystemDefaultEncoding,
&varsp->fTXNRec, &varsp->fTXNFrame, (TXNObjectRefcon) tpvars);
+ if ( !IsControlVisible( theControl ) )
+ TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top + 30000 , varsp->fRTextArea.left + 30000 ,
+ varsp->fRTextArea.bottom + 30000 , varsp->fRTextArea.right + 30000 , varsp->fTXNFrame);
+
+
+ if ( (wxStyle & wxTE_MULTILINE) && (wxStyle & wxTE_DONTWRAP) )
+ {
+ TXNControlTag tag = kTXNWordWrapStateTag ;
+ TXNControlData dat ;
+ dat.uValue = kTXNNoAutoWrap ;
+ TXNSetTXNObjectControls( varsp->fTXNRec , false , 1 , &tag , &dat ) ;
+ }
Str255 fontName ;
SInt16 fontSize ;
Style fontStyle ;
END_EVENT_TABLE()
#endif
+static void SetTXNData( TXNObject txn , const wxString& st , TXNOffset start , TXNOffset end )
+{
+#if wxUSE_UNICODE
+#if SIZEOF_WCHAR_T == 2
+ size_t len = st.Len() ;
+ TXNSetData( txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2,
+ start, end);
+#else
+ wxMBConvUTF16BE converter ;
+ ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ;
+ UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ;
+ converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ;
+ TXNSetData( txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen ,
+ start, end);
+ free( unibuf ) ;
+#endif
+#else
+ wxCharBuffer text = st.mb_str(wxConvLocal) ;
+ TXNSetData( txn , kTXNTextData, (void*)text.data(), strlen( text ) ,
+ start, end);
+#endif
+}
+
// Text item
-wxTextCtrl::wxTextCtrl()
+void wxTextCtrl::Init()
{
m_macTE = NULL ;
m_macTXN = NULL ;
m_macTXNvars = NULL ;
m_macUsesTXN = false ;
+
m_editable = true ;
+ m_dirty = false;
+
m_maxLength = TE_UNLIMITED_LENGTH ;
}
const short kHorizontalMargin = 2 ;
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
- const wxString& st,
+ const wxString& str,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
m_macUsesTXN &= (TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress) ;
// base initialization
- if ( !CreateBase(parent, id, pos, size, style, validator, name) )
+ if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) )
return FALSE;
wxSize mySize = size ;
- if ( m_macUsesTXN )
+ if (style & wxNO_BORDER)
+ {
+ m_macHorizontalBorder = 0 ;
+ m_macVerticalBorder = 0 ;
+ }
+ else if ( m_macUsesTXN )
{
m_macHorizontalBorder = 5 ; // additional pixels around the real control
m_macVerticalBorder = 3 ;
m_editable = FALSE ;
}
+ wxString st = str ;
+ wxMacConvertNewlines13To10( &st ) ;
if ( !m_macUsesTXN )
{
- m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , true , 0 , 0 , 1,
+ m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1,
(style & wxTE_PASSWORD) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ;
long size ;
::GetControlData((ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*)((TEHandle *)&m_macTE) , &size ) ;
| kControlWantsActivate | kControlHandlesTracking | kControlHasSpecialBackground
| kControlGetsFocusOnClick | kControlSupportsLiveFeedback;
/* create the control */
- m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", true, featurSet, 0, featurSet, kControlUserPaneProc, 0);
+ m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", false , featurSet, 0, featurSet, kControlUserPaneProc, 0);
/* set up the mUP specific features and data */
mUPOpenControl((ControlHandle) m_macControl, m_windowStyle );
}
if ( !m_macUsesTXN )
{
- wxCharBuffer text = wxMacStringToCString( st ) ;
+ wxCharBuffer text = st.mb_str(wxConvLocal) ;
::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ;
}
else
tpvars = (STPTextPaneVars **) GetControlReference((ControlHandle) m_macControl);
/* set the text in the record */
m_macTXN = (**tpvars).fTXNRec ;
-#if wxUSE_UNICODE
- TXNSetData( ((TXNObject) m_macTXN) , kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2,
- kTXNStartOffset, kTXNEndOffset);
-#else
- wxCharBuffer text = wxMacStringToCString( st ) ;
- TXNSetData( ((TXNObject) m_macTXN) , kTXNTextData, (void*)text.data(), strlen( text ) ,
- kTXNStartOffset, kTXNEndOffset);
-#endif
+ SetTXNData( (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ;
m_macTXNvars = tpvars ;
m_macUsesTXN = true ;
TXNSetSelection( (TXNObject) m_macTXN, 0, 0);
::GetControlData( (ControlHandle) m_macControl, 0,
( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag,
actualSize , buf.data() , &actualSize ) ;
- result = wxMacMakeStringFromCString( buf ) ;
+ result = wxString( buf , wxConvLocal) ;
}
}
else
}
else
{
- actualSize = GetHandleSize( theText ) ;
+ actualSize = GetHandleSize( theText ) / sizeof( UniChar) ;
if ( actualSize > 0 )
{
wxChar *ptr = result.GetWriteBuf(actualSize*sizeof(wxChar)) ;
+#if SIZEOF_WCHAR_T == 2
wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ;
+#else
+ wxMBConvUTF16BE converter ;
+ HLock( theText ) ;
+ converter.MB2WC( ptr , (const char*)*theText , actualSize ) ;
+ HUnlock( theText ) ;
+#endif
ptr[actualSize] = 0 ;
- result.UngetWriteBuf( actualSize ) ;
+ result.UngetWriteBuf( actualSize *sizeof(wxChar) ) ;
}
DisposeHandle( theText ) ;
}
if ( actualSize > 0 )
{
HLock( theText ) ;
- result = wxMacMakeStringFromCString( *theText , actualSize ) ;
+ result = wxString( *theText , wxConvLocal , actualSize ) ;
HUnlock( theText ) ;
}
DisposeHandle( theText ) ;
}
#endif
}
-
+ wxMacConvertNewlines10To13( &result ) ;
return result ;
}
}
else
{
- TXNGetSelection( ((TXNObject) m_macTXN) , (TXNOffset*) from , (TXNOffset*) to ) ;
+ TXNGetSelection( (TXNObject) m_macTXN , (TXNOffset*) from , (TXNOffset*) to ) ;
}
}
-void wxTextCtrl::SetValue(const wxString& st)
+void wxTextCtrl::SetValue(const wxString& str)
{
+ wxString st = str ;
+ wxMacConvertNewlines13To10( &st ) ;
if ( !m_macUsesTXN )
{
- wxCharBuffer text = wxMacStringToCString( st ) ;
+ wxCharBuffer text = st.mb_str(wxConvLocal) ;
::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ;
}
else
bool formerEditable = m_editable ;
if ( !formerEditable )
SetEditable(true) ;
-#if wxUSE_UNICODE
- TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 ,
- kTXNStartOffset, kTXNEndOffset);
-#else
- wxCharBuffer text = wxMacStringToCString( st ) ;
- TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) ,
- kTXNStartOffset, kTXNEndOffset);
-#endif
+ SetTXNData( (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ;
TXNSetSelection( (TXNObject) m_macTXN, 0, 0);
TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart);
if ( !formerEditable )
if ( attrCounter > 0 )
{
- OSStatus status = TXNSetTypeAttributes ((TXNObject)m_macTXN, attrCounter , typeAttr,
- start,end);
+#ifdef __WXDEBUG__
+ OSStatus status =
+#endif // __WXDEBUG__
+ TXNSetTypeAttributes ((TXNObject)m_macTXN, attrCounter , typeAttr, start,end);
wxASSERT_MSG( status == noErr , wxT("Couldn't set text attributes") ) ;
}
if ( !formerEditable )
}
}
-void wxTextCtrl::Replace(long from, long to, const wxString& value)
+void wxTextCtrl::Replace(long from, long to, const wxString& str)
{
+ wxString value = str ;
+ wxMacConvertNewlines13To10( &value ) ;
if ( !m_macUsesTXN )
{
ControlEditTextSelectionRec selection ;
SetEditable(true) ;
TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ;
TXNClear( ((TXNObject) m_macTXN) ) ;
-#if wxUSE_UNICODE
- TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)value.wc_str(), value.Length() * 2 ,
- kTXNUseCurrentSelection, kTXNUseCurrentSelection);
-#else
- TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)value.c_str(), value.Length(),
- kTXNUseCurrentSelection, kTXNUseCurrentSelection);
-#endif
+ SetTXNData( (TXNObject) m_macTXN , str , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
if ( !formerEditable )
SetEditable( formerEditable ) ;
}
void wxTextCtrl::SetSelection(long from, long to)
{
- if ( from == -1 )
- from = 0;
-
- if ( to == -1 )
- to = GetLastPosition();
-
if ( !m_macUsesTXN )
{
ControlEditTextSelectionRec selection ;
- selection.selStart = from ;
- selection.selEnd = to ;
+ if ((from == -1) && (to == -1))
+ {
+ selection.selStart = 0 ;
+ selection.selEnd = 32767 ;
+ }
+ else
+ {
+ selection.selStart = from ;
+ selection.selEnd = to ;
+ }
TESetSelect( selection.selStart , selection.selEnd , ((TEHandle) m_macTE) ) ;
::SetControlData((ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
may force a redraw in the text area. */
SetPort((**tpvars).fDrawingEnvironment);
/* change the selection */
- TXNSetSelection( (**tpvars).fTXNRec, from, to);
+ if ((from == -1) && (to == -1))
+ TXNSelectAll((TXNObject) m_macTXN);
+ else
+ TXNSetSelection( (**tpvars).fTXNRec, from, to);
TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart);
}
}
return FALSE;
}
-void wxTextCtrl::WriteText(const wxString& st)
+void wxTextCtrl::WriteText(const wxString& str)
{
+ wxString st = str ;
+ wxMacConvertNewlines13To10( &st ) ;
if ( !m_macUsesTXN )
{
- wxCharBuffer text = wxMacStringToCString( st ) ;
+ wxCharBuffer text = st.mb_str(wxConvLocal) ;
TEInsert( text , strlen(text) , ((TEHandle) m_macTE) ) ;
}
else
SetEditable(true) ;
long start , end , dummy ;
GetSelection( &start , &dummy ) ;
-#if wxUSE_UNICODE
- TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 ,
- kTXNUseCurrentSelection, kTXNUseCurrentSelection);
-#else
- wxCharBuffer text = wxMacStringToCString( st ) ;
- TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) ,
- kTXNUseCurrentSelection, kTXNUseCurrentSelection);
-#endif
+ SetTXNData( (TXNObject) m_macTXN , st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
GetSelection( &dummy , &end ) ;
SetStyle( start , end , GetDefaultStyle() ) ;
if ( !formerEditable )
void wxTextCtrl::Clear()
{
- if ( !IsEditable() )
- {
- return ;
- }
if ( !m_macUsesTXN )
{
::SetControlData((ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
bool wxTextCtrl::IsModified() const
{
- return TRUE;
+ return m_dirty;
}
bool wxTextCtrl::IsEditable() const
return FALSE ;
}
-// Makes 'unmodified'
+// Makes modifie or unmodified
+void wxTextCtrl::MarkDirty()
+{
+ m_dirty = true;
+}
+
void wxTextCtrl::DiscardEdits()
{
- // TODO
+ m_dirty = false;
}
int wxTextCtrl::GetNumberOfLines() const
{
- // TODO change this if possible to reflect real lines
- wxString content = GetValue() ;
-
- int count = 1;
- for (size_t i = 0; i < content.Length() ; i++)
+ if ( m_macUsesTXN )
{
- if (content[i] == '\r') count++;
+ ItemCount lines ;
+ TXNGetLineCount((TXNObject)m_macTXN, &lines ) ;
+ return lines ;
}
+ else
+ {
+ wxString content = GetValue() ;
- return count;
+ int count = 1;
+ for (size_t i = 0; i < content.Length() ; i++)
+ {
+ if (content[i] == '\r') count++;
+ }
+ return count;
+ }
}
long wxTextCtrl::XYToPosition(long x, long y) const
void wxTextCtrl::ShowPosition(long pos)
{
- // TODO
+#if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
+ if ( m_macUsesTXN )
+ {
+ Point current ;
+ Point desired ;
+ TXNOffset selstart , selend ;
+ TXNGetSelection( (TXNObject) m_macTXN , &selstart , &selend) ;
+ TXNOffsetToPoint( (TXNObject) m_macTXN, selstart , ¤t);
+ TXNOffsetToPoint( (TXNObject) m_macTXN, pos , &desired);
+ //TODO use HIPoints for 10.3 and above
+ if ( (UInt32) TXNScroll != (UInt32) kUnresolvedCFragSymbolAddress )
+ {
+ OSErr theErr = noErr;
+ SInt32 dv = desired.v - current.v ;
+ SInt32 dh = desired.h - current.h ;
+ TXNShowSelection( (TXNObject) m_macTXN , true ) ;
+ theErr = TXNScroll( (TXNObject) m_macTXN, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh );
+ wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
+ }
+ }
+#endif
}
int wxTextCtrl::GetLineLength(long lineNo) const
for (size_t j = i; j < content.Length(); j++)
{
count++;
- if (content[j] == '\r') return count;
+ if (content[j] == '\n') return count;
}
return count;
}
- if (content[i] == '\r') count++;
+ if (content[i] == '\n') count++;
}
return 0;
}
for (size_t j = i; j < content.Length(); j++)
{
- if (content[j] == '\r')
+ if (content[j] == '\n')
return tmp;
tmp += content[j];
return tmp;
}
- if (content[i] == '\r') count++;
+ if (content[i] == '\n') count++;
}
return wxEmptyString ;
}
// eat it
return ;
}
+
+ // assume that any key not processed yet is going to modify the control
+ m_dirty = true;
+
if ( key == 'v' && event.MetaDown() )
{
if ( CanPaste() )
if (!eat_key)
{
- // default handling
- event.Skip() ;
+ // perform keystroke handling
+#if TARGET_CARBON
+ if ( m_macUsesTXN && wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
+ CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
+ else
+ {
+ EventRecord rec ;
+ if ( wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) )
+ {
+ EventRecord *ev = &rec ;
+ short keycode ;
+ short keychar ;
+ keychar = short(ev->message & charCodeMask);
+ keycode = short(ev->message & keyCodeMask) >> 8 ;
+
+ ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
+ }
+ }
+#else
+ EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
+ short keycode ;
+ short keychar ;
+ keychar = short(ev->message & charCodeMask);
+ keycode = short(ev->message & keyCodeMask) >> 8 ;
+
+ ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
+#endif
}
if ( ( key >= 0x20 && key < WXK_START ) ||
key == WXK_RETURN ||