// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "textctrl.h"
-#endif
-
#include "wx/wxprec.h"
#if wxUSE_TEXTCTRL
#include "wx/button.h"
#include "wx/toplevel.h"
#include "wx/textctrl.h"
-#include "wx/notebook.h"
-#include "wx/tabctrl.h"
#include "wx/settings.h"
#include "wx/filefn.h"
#include "wx/utils.h"
#include "wx/sysopt.h"
+#include "wx/menu.h"
+#include "wx/intl.h"
#if defined(__BORLANDC__) && !defined(__WIN32__)
#include <alloc.h>
};
#endif
+#ifndef __DARWIN__
#include <MacTextEditor.h>
#include <ATSUnicode.h>
#include <TextCommon.h>
#include <TextEncodingConverter.h>
+#endif
#include "wx/mac/uma.h"
class wxMacFunctor
virtual bool CanPaste() const ;
virtual void SetEditable(bool editable) ;
virtual wxTextPos GetLastPosition() const ;
- virtual void Replace( long from , long to , const wxString str ) ;
- virtual void Remove( long from , long to ) = 0 ;
+ virtual void Replace( long from , long to , const wxString &str ) ;
+ virtual void Remove( long from , long to ) ;
virtual void SetSelection( long from , long to ) = 0 ;
virtual void GetSelection( long* from, long* to) const = 0 ;
virtual void WriteText(const wxString& str) = 0 ;
+ virtual bool HasOwnContextMenu() const { return false ; }
virtual void Clear() ;
virtual bool CanUndo() const;
virtual bool CanPaste() const ;
virtual void SetEditable(bool editable) ;
virtual wxTextPos GetLastPosition() const ;
- virtual void Replace( long from , long to , const wxString str ) ;
+ virtual void Replace( long from , long to , const wxString &str ) ;
virtual void Remove( long from , long to ) ;
virtual void GetSelection( long* from, long* to) const ;
virtual void SetSelection( long from , long to ) ;
virtual void WriteText(const wxString& str) ;
+ virtual bool HasOwnContextMenu() const
+ {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ if ( UMAGetSystemVersion() >= 0x1040 )
+ {
+ TXNCommandEventSupportOptions options ;
+ TXNGetCommandEventSupport( m_txn , & options ) ;
+ return options & kTXNSupportEditCommandProcessing ;
+ }
+#endif
+ return false ;
+ }
+
virtual void Clear() ;
virtual bool CanUndo() const ;
const wxSize& size, long style ) ;
virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
virtual bool HasFocus() const ;
+ virtual void SetBackground( const wxBrush &brush) ;
protected :
HIViewRef m_scrollView ;
HIViewRef m_textView ;
virtual void Paste();
virtual bool CanPaste() const;
virtual void SetEditable(bool editable) ;
- virtual void Remove( long from , long to ) ;
virtual void GetSelection( long* from, long* to) const ;
virtual void SetSelection( long from , long to ) ;
virtual void WriteText(const wxString& str) ;
EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
+ EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete)
+ EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll)
+
+ EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu)
EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
+ EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete)
+ EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll)
END_EVENT_TABLE()
// Text item
-void wxTextCtrl::Init()
+void wxTextCtrl::Init()
{
- m_editable = true ;
- m_dirty = false;
+ m_editable = true ;
+ m_dirty = false;
- m_maxLength = TE_UNLIMITED_LENGTH ;
+ m_privateContextMenu = NULL;
+
+ m_maxLength = TE_UNLIMITED_LENGTH ;
}
wxTextCtrl::~wxTextCtrl()
{
+ delete m_privateContextMenu;
}
Redo();
}
+void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event))
+{
+ long from, to;
+ GetSelection(& from, & to);
+ if (from != -1 && to != -1)
+ Remove(from, to);
+}
+
+void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event))
+{
+ SetSelection(-1, -1);
+}
+
void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
{
event.Enable( CanCut() );
event.Enable( CanRedo() );
}
+void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event)
+{
+ long from, to;
+ GetSelection(& from, & to);
+ event.Enable(from != -1 && to != -1 && from != to && IsEditable()) ;
+}
+
+void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
+{
+ event.Enable(GetLastPosition() > 0);
+}
+
+// CS: Context Menus only work with mlte implementations or non-multiline HIViews at the moment
+
+void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event)
+{
+ if ( GetPeer()->HasOwnContextMenu() )
+ {
+ event.Skip() ;
+ return ;
+ }
+
+ if (m_privateContextMenu == NULL)
+ {
+ m_privateContextMenu = new wxMenu;
+ m_privateContextMenu->Append(wxID_UNDO, _("&Undo"));
+ m_privateContextMenu->Append(wxID_REDO, _("&Redo"));
+ m_privateContextMenu->AppendSeparator();
+ m_privateContextMenu->Append(wxID_CUT, _("Cu&t"));
+ m_privateContextMenu->Append(wxID_COPY, _("&Copy"));
+ m_privateContextMenu->Append(wxID_PASTE, _("&Paste"));
+ m_privateContextMenu->Append(wxID_CLEAR, _("&Delete"));
+ m_privateContextMenu->AppendSeparator();
+ m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All"));
+ }
+
+ if (m_privateContextMenu != NULL)
+ PopupMenu(m_privateContextMenu);
+}
+
bool wxTextCtrl::MacSetupCursor( const wxPoint& pt )
{
if ( !GetPeer()->SetupCursor(pt) )
return GetStringValue().Length() ;
}
-void wxMacTextControl::Replace( long from , long to , const wxString str )
+void wxMacTextControl::Replace( long from , long to , const wxString &val )
+{
+ SetSelection( from , to ) ;
+ WriteText( val) ;
+}
+
+void wxMacTextControl::Remove( long from , long to )
{
+ SetSelection( from , to ) ;
+ WriteText( wxEmptyString) ;
}
void wxMacTextControl::Clear()
{
SetData<Boolean>( 0 , kControlEditTextLockedTag , (Boolean) !editable ) ;
}
-void wxMacUnicodeTextControl::Remove( long from , long to )
-{
-}
void wxMacUnicodeTextControl::GetSelection( long* from, long* to) const
{
void wxMacUnicodeTextControl::SetSelection( long from , long to )
{
ControlEditTextSelectionRec sel ;
+ if ((from == -1) && (to == -1))
+ {
+ from = 0 ;
+ to = 32767 ; // sel has 16 bit signed values, max is 32767
+ }
sel.selStart = from ;
sel.selEnd = to ;
SetData<ControlEditTextSelectionRec>( 0 , kControlEditTextSelectionTag, &sel ) ;
tback.bgType = kTXNBackgroundTypeRGB;
tback.bg.color = MAC_WXCOLORREF( background.GetPixel() );
TXNSetBackground( m_txn , &tback);
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ if ( UMAGetSystemVersion() >= 0x1040 )
+ {
+ TXNCommandEventSupportOptions options ;
+ if ( TXNGetCommandEventSupport( m_txn, &options) == noErr )
+ {
+ options |= kTXNSupportEditCommandProcessing ;
+ options |= kTXNSupportSpellCheckCommandProcessing ;
+ options |= kTXNSupportFontCommandProcessing ;
+ options |= kTXNSupportFontCommandUpdating ;
+
+ TXNSetCommandEventSupport( m_txn , options ) ;
+ }
+ }
+#endif
}
void wxMacMLTEControl::SetBackground( const wxBrush &brush )
return actualsize ;
}
-void wxMacMLTEControl::Replace( long from , long to , const wxString str )
+void wxMacMLTEControl::Replace( long from , long to , const wxString &str )
{
wxString value = str ;
wxMacConvertNewlines10To13( &value ) ;
TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
wxMax( m_txnControlBounds.bottom , m_txnControlBounds.top ) ,
wxMax( m_txnControlBounds.right , m_txnControlBounds.left ) , m_txnFrameID);
-
+#endif
// the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
// movement, therefore we have to force it
+ // according to David Surovell this problem also sometimes occurs under OSX, so we use this as well
+
TXNLongRect textRect ;
TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ;
if ( textRect.left < m_txnControlBounds.left )
{
TXNShowSelection( m_txn , false ) ;
}
-#endif
}
}
m_font = wxPeer->GetFont() ;
m_windowStyle = style ;
Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ;
- wxString st = str ;
- wxMacConvertNewlines10To13( &st ) ;
short featurSet;
MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ;
- wxMacWindowClipper clipper( m_peer ) ;
- SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
- TXNSetSelection( m_txn, 0, 0);
+ {
+ wxString st = str ;
+ wxMacConvertNewlines10To13( &st ) ;
+ wxMacWindowClipper clipper( m_peer ) ;
+ SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
+ TXNSetSelection( m_txn, 0, 0);
+ }
}
wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
wxString st = str ;
wxMacConvertNewlines10To13( &st ) ;
- HIRect hr = { bounds.left , bounds.top , bounds.right - bounds.left , bounds.bottom- bounds.top } ;
+ HIRect hr = { { bounds.left , bounds.top} ,
+ { bounds.right - bounds.left , bounds.bottom - bounds.top} } ;
m_scrollView = NULL ;
TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ;
return control == m_textView ;
}
+void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush )
+{
+ wxMacMLTEControl::SetBackground( brush ) ;
+/*
+ CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB();
+ RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ;
+
+ float component[4] ;
+ component[0] = col.red / 65536.0 ;
+ component[1] = col.green / 65536.0 ;
+ component[2] = col.blue / 65536.0 ;
+ component[3] = 1.0 ; // alpha
+
+ CGColorRef color = CGColorCreate (rgbSpace , component );
+ HITextViewSetBackgroundColor( m_textView , color ) ;
+ CGColorSpaceRelease( rgbSpace );
+*/
+}
+
#endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2