From 1e181c7a2c32193fc8138cc32ed07984eadd4a21 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 5 Sep 2008 14:41:11 +0000 Subject: [PATCH] simplify native textcontrol creations, adding search control for cocoa git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55476 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/carbon/listbox.h | 2 +- include/wx/osx/carbon/private.h | 4 +- include/wx/osx/carbon/private/mactext.h | 66 +--- include/wx/osx/carbon/srchctrl.h | 20 +- include/wx/osx/carbon/textctrl.h | 10 +- include/wx/osx/cocoa/private.h | 2 + include/wx/osx/cocoa/private/textimpl.h | 37 +++ include/wx/osx/core/private.h | 90 ++++++ src/osx/carbon/srchctrl.cpp | 316 +++++------------- src/osx/carbon/textctrl.cpp | 51 ++- src/osx/carbon/utils.cpp | 21 -- src/osx/carbon/window.cpp | 6 +- src/osx/cocoa/glcanvas.mm | 33 -- src/osx/cocoa/msgdlg.mm | 132 +++----- src/osx/cocoa/srchctrl.mm | 409 ++++++------------------ src/osx/cocoa/textctrl.mm | 89 +++--- src/osx/cocoa/window.mm | 5 + src/osx/srchctrl_osx.cpp | 189 ++++++++++- src/osx/textctrl_osx.cpp | 140 +++----- src/osx/utils_osx.cpp | 20 ++ src/osx/window_osx.cpp | 4 +- 21 files changed, 704 insertions(+), 942 deletions(-) create mode 100644 include/wx/osx/cocoa/private/textimpl.h diff --git a/include/wx/osx/carbon/listbox.h b/include/wx/osx/carbon/listbox.h index 6fdf0f2ac0..e2fc661e1c 100644 --- a/include/wx/osx/carbon/listbox.h +++ b/include/wx/osx/carbon/listbox.h @@ -21,7 +21,7 @@ // forward decl for GetSelections() class wxArrayInt; -// forward decl for wxListWidgetImpl data type. +// forward decl for wxListWidgetImpl implementation type. class wxListWidgetImpl; // List box item diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h index 25b1b62c2e..9023544834 100644 --- a/include/wx/osx/carbon/private.h +++ b/include/wx/osx/carbon/private.h @@ -426,7 +426,7 @@ public : virtual void SuperChangedPosition(); - virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ); + virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true ); virtual void SetBackgroundColour( const wxColour& col ); virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ); void SetActionProc( ControlActionUPP actionProc ); @@ -962,8 +962,6 @@ void wxMacSetupConverters(); void wxMacCleanupConverters(); // utils.cpp -void WXDLLIMPEXP_CORE wxMacStringToPascal( const wxString&from , StringPtr to ); -wxString WXDLLIMPEXP_CORE wxMacMakeStringFromPascal( ConstStringPtr from ); // filefn.cpp diff --git a/include/wx/osx/carbon/private/mactext.h b/include/wx/osx/carbon/private/mactext.h index 9d07080667..a0e7d5e518 100644 --- a/include/wx/osx/carbon/private/mactext.h +++ b/include/wx/osx/carbon/private/mactext.h @@ -14,64 +14,9 @@ #include "wx/osx/private.h" -// common interface for all implementations -class wxMacTextControl : -#if wxOSX_USE_CARBON - public wxMacControl -#else - public wxWidgetCocoaImpl -#endif -{ -public : -#if wxOSX_USE_CARBON - wxMacTextControl( wxTextCtrl *peer ) ; -#else - wxMacTextControl::wxMacTextControl(wxTextCtrl* peer, WXWidget w) ; -#endif - virtual ~wxMacTextControl() ; - - virtual bool CanFocus() const { return true; } - - virtual wxString GetStringValue() const = 0 ; - virtual void SetStringValue( const wxString &val ) = 0 ; - 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 void SetStyle( long start, long end, const wxTextAttr& style ) ; - virtual void Copy() ; - virtual void Cut() ; - virtual void Paste() ; - 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 ) ; - - - virtual bool HasOwnContextMenu() const - { return false ; } - - virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) - { return false ; } - - virtual void Clear() ; - virtual bool CanUndo() const; - virtual void Undo() ; - virtual bool CanRedo() const; - virtual void Redo() ; - virtual int GetNumberOfLines() const ; - virtual long XYToPosition(long x, long y) const; - virtual bool PositionToXY(long pos, long *x, long *y) const ; - virtual void ShowPosition(long WXUNUSED(pos)) ; - virtual int GetLineLength(long lineNo) const ; - virtual wxString GetLineText(long lineNo) const ; - virtual void CheckSpelling(bool WXUNUSED(check)) { } - virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ); -}; +// implementation exposed, so that search control can pull it -#if wxOSX_USE_CARBON -class wxMacUnicodeTextControl : public wxMacTextControl +class wxMacUnicodeTextControl : public wxMacControl, public wxTextWidgetImpl { public : wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) ; @@ -81,10 +26,6 @@ public : const wxSize& size, long style ) ; virtual ~wxMacUnicodeTextControl(); - virtual bool Create( wxTextCtrl *wxPeer, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) ; virtual void VisibilityChanged(bool shown); virtual wxString GetStringValue() const ; virtual void SetStringValue( const wxString &str) ; @@ -98,13 +39,12 @@ public : virtual void WriteText(const wxString& str) ; protected : - virtual void CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef cfr ); + void InstallEventHandlers(); // contains the tag for the content (is different for password and non-password controls) OSType m_valueTag ; public : ControlEditTextSelectionRec m_selection ; }; -#endif #endif // _WX_MAC_PRIVATE_MACTEXT_H_ diff --git a/include/wx/osx/carbon/srchctrl.h b/include/wx/osx/carbon/srchctrl.h index 2f339d638a..a883134422 100644 --- a/include/wx/osx/carbon/srchctrl.h +++ b/include/wx/osx/carbon/srchctrl.h @@ -13,7 +13,7 @@ #if wxUSE_SEARCHCTRL -class wxMacSearchFieldControl; +class wxSearchWidgetImpl; class WXDLLIMPEXP_CORE wxSearchCtrl : public wxSearchCtrlBase { @@ -54,14 +54,13 @@ public: virtual bool IsCancelButtonVisible() const; // TODO: In 2.9 these should probably be virtual, and declared in the base class... - void SetDescriptiveText(const wxString& text); - wxString GetDescriptiveText() const; + void SetDescriptiveText(const wxString& text); + wxString GetDescriptiveText() const; - virtual wxInt32 MacSearchFieldSearchHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; - virtual wxInt32 MacSearchFieldCancelHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; + virtual bool HandleSearchFieldSearchHit() ; + virtual bool HandleSearchFieldCancelHit() ; - wxMacSearchFieldControl * GetPeer() const - { return (wxMacSearchFieldControl*) m_peer; } + wxSearchWidgetImpl * GetSearchPeer() const; protected: @@ -69,12 +68,9 @@ protected: void Init(); - virtual void CreatePeer( - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ); - wxMenu *m_menu; + + wxString m_descriptiveText; private: DECLARE_DYNAMIC_CLASS(wxSearchCtrl) diff --git a/include/wx/osx/carbon/textctrl.h b/include/wx/osx/carbon/textctrl.h index 760bc44178..df6967f9ab 100644 --- a/include/wx/osx/carbon/textctrl.h +++ b/include/wx/osx/carbon/textctrl.h @@ -26,8 +26,8 @@ #include "wx/control.h" #include "wx/textctrl.h" -class wxMacTextControl; - +// forward decl for wxListWidgetImpl implementation type. +class WXDLLIMPEXP_FWD_CORE wxTextWidgetImpl; class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase { @@ -170,17 +170,13 @@ public: virtual void MacSuperChangedPosition(); virtual void MacCheckSpelling(bool check); - wxMacTextControl * GetPeer() const - { return (wxMacTextControl*) m_peer; } - + wxTextWidgetImpl * GetTextPeer() const; protected: // common part of all ctors void Init(); virtual wxSize DoGetBestSize() const; - virtual void CreatePeer(const wxString& str, const wxPoint& pos, const wxSize& size, long style ); - virtual void DoSetValue(const wxString& value, int flags = 0); bool m_editable; diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 51f7015479..cccac824e9 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -148,6 +148,8 @@ public : void PulseGauge(); void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ); + void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true ); + protected: WXWidget m_osxView; DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl) diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h new file mode 100644 index 0000000000..d052ea8df7 --- /dev/null +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -0,0 +1,37 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: textimpl.h +// Purpose: textcontrol implementation classes that have to be exposed +// Author: Stefan Csomor +// Modified by: +// Created: 03/02/99 +// RCS-ID: $Id: +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_ +#define _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_ + +#include "wx/osx/private.h" + +// implementation exposed, so that search control can pull it + +class wxNSTextFieldControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl +{ +public : + wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ); + virtual ~wxNSTextFieldControl(); + + virtual wxString GetStringValue() const ; + virtual void SetStringValue( const wxString &str) ; + virtual void Copy() ; + virtual void Cut() ; + virtual void Paste() ; + virtual bool CanPaste() const ; + virtual void SetEditable(bool editable) ; + virtual void GetSelection( long* from, long* to) const ; + virtual void SetSelection( long from , long to ); + virtual void WriteText(const wxString& str) ; +}; + +#endif // _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_ diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 1313856793..462e0e882f 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -22,7 +22,12 @@ #include "wx/osx/core/cfdataref.h" #if wxOSX_USE_COCOA_OR_CARBON + WXDLLIMPEXP_BASE long UMAGetSystemVersion() ; + +void WXDLLIMPEXP_CORE wxMacStringToPascal( const wxString&from , unsigned char * to ); +wxString WXDLLIMPEXP_CORE wxMacMakeStringFromPascal( const unsigned char * from ); + #endif #if wxUSE_GUI @@ -225,6 +230,8 @@ public : virtual void PulseGauge() = 0; virtual void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) = 0; + virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true ) = 0; + // is the clicked event sent AFTER the state already changed, so no additional // state changing logic is required from the outside virtual bool ButtonClickDidStateChange() = 0; @@ -293,6 +300,15 @@ public : long style, long extraStyle) ; + static wxWidgetImplType* CreateSearchControl( wxTextCtrl* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& content, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + static wxWidgetImplType* CreateCheckBox( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, @@ -475,6 +491,80 @@ public: virtual unsigned int ListGetCount() const = 0; }; +// +// interface to be implemented by a textcontrol +// + +// common interface for all implementations +class WXDLLIMPEXP_CORE wxTextWidgetImpl + +{ +public : + wxTextWidgetImpl() {} + + virtual ~wxTextWidgetImpl() {} + + virtual bool CanFocus() const { return true; } + + virtual wxString GetStringValue() const = 0 ; + virtual void SetStringValue( const wxString &val ) = 0 ; + 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 void SetStyle( long start, long end, const wxTextAttr& style ) ; + virtual void Copy() ; + virtual void Cut() ; + virtual void Paste() ; + 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 ) ; + + + virtual bool HasOwnContextMenu() const + { return false ; } + + virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) + { return false ; } + + virtual void Clear() ; + virtual bool CanUndo() const; + virtual void Undo() ; + virtual bool CanRedo() const; + virtual void Redo() ; + virtual int GetNumberOfLines() const ; + virtual long XYToPosition(long x, long y) const; + virtual bool PositionToXY(long pos, long *x, long *y) const ; + virtual void ShowPosition(long WXUNUSED(pos)) ; + virtual int GetLineLength(long lineNo) const ; + virtual wxString GetLineText(long lineNo) const ; + virtual void CheckSpelling(bool WXUNUSED(check)) { } +}; + +// +// common interface for search controls +// + +class wxSearchWidgetImpl +{ +public : + wxSearchWidgetImpl(){} + virtual ~wxSearchWidgetImpl(){} + + // search field options + virtual void ShowSearchButton( bool show ) = 0; + virtual bool IsSearchButtonVisible() const = 0; + + virtual void ShowCancelButton( bool show ) = 0; + virtual bool IsCancelButtonVisible() const = 0; + + virtual void SetSearchMenu( wxMenu* menu ) = 0; + + virtual void SetDescriptiveText(const wxString& text) = 0; +} ; + // // toplevel window implementation class // diff --git a/src/osx/carbon/srchctrl.cpp b/src/osx/carbon/srchctrl.cpp index 9fed17dce6..84af34d60f 100644 --- a/src/osx/carbon/srchctrl.cpp +++ b/src/osx/carbon/srchctrl.cpp @@ -28,32 +28,18 @@ #include "wx/osx/uma.h" #include "wx/osx/carbon/private/mactext.h" -BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) -END_EVENT_TABLE() - -IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) - // ============================================================================ // wxMacSearchFieldControl // ============================================================================ -static const EventTypeSpec eventList[] = -{ - { kEventClassSearchField, kEventSearchFieldCancelClicked } , - { kEventClassSearchField, kEventSearchFieldSearchClicked } , -}; - -class wxMacSearchFieldControl : public wxMacUnicodeTextControl +class wxMacSearchFieldControl : public wxMacUnicodeTextControl, public wxSearchWidgetImpl { public : wxMacSearchFieldControl( wxTextCtrl *wxPeer, const wxString& str, const wxPoint& pos, - const wxSize& size, long style ) : wxMacUnicodeTextControl( wxPeer ) - { - Create( wxPeer, str, pos, size, style ); - } - + const wxSize& size, long style ) ; + // search field options virtual void ShowSearchButton( bool show ); virtual bool IsSearchButtonVisible() const; @@ -62,35 +48,81 @@ public : virtual bool IsCancelButtonVisible() const; virtual void SetSearchMenu( wxMenu* menu ); - virtual wxMenu* GetSearchMenu() const; virtual void SetDescriptiveText(const wxString& text); - virtual wxString GetDescriptiveText() const; virtual bool SetFocus(); -protected : - virtual void CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef crf ); - private: - wxMenu* m_menu; } ; -void wxMacSearchFieldControl::CreateControl(wxTextCtrl* WXUNUSED(peer), - const Rect* bounds, - CFStringRef WXUNUSED(crf)) +static const EventTypeSpec eventList[] = +{ + { kEventClassSearchField, kEventSearchFieldCancelClicked } , + { kEventClassSearchField, kEventSearchFieldSearchClicked } , +}; + +// ============================================================================ +// implementation +// ============================================================================ + +static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + + wxMacCarbonEvent cEvent( event ) ; + + ControlRef controlRef ; + wxSearchCtrl* thisWindow = (wxSearchCtrl*) data ; + cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; + + switch( GetEventKind( event ) ) + { + case kEventSearchFieldCancelClicked : + thisWindow->HandleSearchFieldCancelHit() ; + break ; + case kEventSearchFieldSearchClicked : + thisWindow->HandleSearchFieldSearchHit() ; + break ; + } + + return result ; +} + +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacSearchControlEventHandler ) + +wxMacSearchFieldControl::wxMacSearchFieldControl( wxTextCtrl *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) : wxMacUnicodeTextControl( wxPeer ) { + m_font = wxPeer->GetFont() ; + m_windowStyle = style ; + m_selection.selStart = m_selection.selEnd = 0; + Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; + wxString st = str ; + wxMacConvertNewlines10To13( &st ) ; + wxCFStringRef cf(st , m_font.GetEncoding()) ; + + m_valueTag = kControlEditTextCFStringTag ; + OptionBits attributes = kHISearchFieldAttributesSearchIcon; - HIRect hibounds = { { bounds->left, bounds->top }, { bounds->right-bounds->left, bounds->bottom-bounds->top } }; + HIRect hibounds = { { bounds.left, bounds.top }, { bounds.right-bounds.left, bounds.bottom-bounds.top } }; verify_noerr( HISearchFieldCreate( &hibounds, attributes, 0, // MenuRef - CFSTR("Search"), + CFSTR(""), &m_controlRef ) ); HIViewSetVisible (m_controlRef, true); + + verify_noerr( SetData( 0, kControlEditTextCFStringTag , cf ) ) ; + + ::InstallControlEventHandler( m_controlRef, GetwxMacSearchControlEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, wxPeer, NULL); + wxMacUnicodeTextControl::InstallEventHandlers(); } // search field options @@ -140,10 +172,9 @@ bool wxMacSearchFieldControl::IsCancelButtonVisible() const void wxMacSearchFieldControl::SetSearchMenu( wxMenu* menu ) { - m_menu = menu; - if ( m_menu ) + if ( menu ) { - verify_noerr( HISearchFieldSetSearchMenu( m_controlRef, MAC_WXHMENU(m_menu->GetHMenu()) ) ); + verify_noerr( HISearchFieldSetSearchMenu( m_controlRef, MAC_WXHMENU(menu->GetHMenu()) ) ); } else { @@ -151,12 +182,6 @@ void wxMacSearchFieldControl::SetSearchMenu( wxMenu* menu ) } } -wxMenu* wxMacSearchFieldControl::GetSearchMenu() const -{ - return m_menu; -} - - void wxMacSearchFieldControl::SetDescriptiveText(const wxString& text) { verify_noerr( HISearchFieldSetDescriptiveText( @@ -164,20 +189,6 @@ void wxMacSearchFieldControl::SetDescriptiveText(const wxString& text) wxCFStringRef( text, wxFont::GetDefaultEncoding() ))); } -wxString wxMacSearchFieldControl::GetDescriptiveText() const -{ - CFStringRef cfStr; - verify_noerr( HISearchFieldCopyDescriptiveText( m_controlRef, &cfStr )); - if ( cfStr ) - { - return wxCFStringRef(cfStr).AsString(); - } - else - { - return wxEmptyString; - } -} - bool wxMacSearchFieldControl::SetFocus() { // NB: We have to implement SetFocus a little differently because kControlFocusNextPart @@ -192,201 +203,18 @@ bool wxMacSearchFieldControl::SetFocus() return true; } - -// ============================================================================ -// implementation -// ============================================================================ - -static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) -{ - OSStatus result = eventNotHandledErr ; - - wxMacCarbonEvent cEvent( event ) ; - - ControlRef controlRef ; - wxSearchCtrl* thisWindow = (wxSearchCtrl*) data ; - cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; - - switch( GetEventKind( event ) ) - { - case kEventSearchFieldCancelClicked : - thisWindow->MacSearchFieldCancelHit( handler , event ) ; - break ; - case kEventSearchFieldSearchClicked : - thisWindow->MacSearchFieldSearchHit( handler , event ) ; - break ; - } - - return result ; -} - -DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacSearchControlEventHandler ) - - -// ---------------------------------------------------------------------------- -// wxSearchCtrl creation -// ---------------------------------------------------------------------------- - -// creation -// -------- - -wxSearchCtrl::wxSearchCtrl() -{ - Init(); -} - -wxSearchCtrl::wxSearchCtrl(wxWindow *parent, wxWindowID id, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - Init(); - - Create(parent, id, value, pos, size, style, validator, name); -} - -void wxSearchCtrl::Init() -{ - m_menu = 0; -} - -bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - if ( !wxTextCtrl::Create(parent, id, wxEmptyString, pos, size, wxBORDER_NONE | style, validator, name) ) - { - return false; - } - - EventHandlerRef searchEventHandler; - InstallControlEventHandler( m_peer->GetControlRef(), GetwxMacSearchControlEventHandlerUPP(), - GetEventTypeCount(eventList), eventList, this, - (EventHandlerRef *)&searchEventHandler); - - SetValue(value); - - return true; -} - -wxSearchCtrl::~wxSearchCtrl() -{ - delete m_menu; -} - -wxSize wxSearchCtrl::DoGetBestSize() const -{ - wxSize size = wxWindow::DoGetBestSize(); - // it seems to return a default width of about 16, which is way too small here. - if (size.GetWidth() < 100) - size.SetWidth(100); - - return size; -} - - -// search control specific interfaces -// wxSearchCtrl owns menu after this call -void wxSearchCtrl::SetMenu( wxMenu* menu ) -{ - if ( menu == m_menu ) - { - // no change - return; - } - - if ( m_menu ) - { - m_menu->SetInvokingWindow( 0 ); - } - - delete m_menu; - m_menu = menu; - - if ( m_menu ) - { - m_menu->SetInvokingWindow( this ); - } - - GetPeer()->SetSearchMenu( m_menu ); -} - -wxMenu* wxSearchCtrl::GetMenu() +wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& str, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - return m_menu; -} + wxMacControl* peer = new wxMacSearchFieldControl( wxpeer , str , pos , size , style ); -void wxSearchCtrl::ShowSearchButton( bool show ) -{ - if ( IsSearchButtonVisible() == show ) - { - // no change - return; - } - GetPeer()->ShowSearchButton( show ); -} - -bool wxSearchCtrl::IsSearchButtonVisible() const -{ - return GetPeer()->IsSearchButtonVisible(); -} - - -void wxSearchCtrl::ShowCancelButton( bool show ) -{ - if ( IsCancelButtonVisible() == show ) - { - // no change - return; - } - GetPeer()->ShowCancelButton( show ); -} - -bool wxSearchCtrl::IsCancelButtonVisible() const -{ - return GetPeer()->IsCancelButtonVisible(); -} - -void wxSearchCtrl::SetDescriptiveText(const wxString& text) -{ - GetPeer()->SetDescriptiveText(text); -} - -wxString wxSearchCtrl::GetDescriptiveText() const -{ - return GetPeer()->GetDescriptiveText(); -} - -wxInt32 wxSearchCtrl::MacSearchFieldSearchHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId ); - event.SetEventObject(this); - ProcessCommand(event); - return eventNotHandledErr ; -} - -wxInt32 wxSearchCtrl::MacSearchFieldCancelHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId ); - event.SetEventObject(this); - ProcessCommand(event); - return eventNotHandledErr ; -} - - -void wxSearchCtrl::CreatePeer( - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) -{ - m_peer = new wxMacSearchFieldControl( this , str , pos , size , style ); + return peer; } #endif // wxUSE_NATIVE_SEARCH_CONTROL diff --git a/src/osx/carbon/textctrl.cpp b/src/osx/carbon/textctrl.cpp index 9397eca99f..2a280a7526 100644 --- a/src/osx/carbon/textctrl.cpp +++ b/src/osx/carbon/textctrl.cpp @@ -218,11 +218,11 @@ wxMacWindowClipper::~wxMacWindowClipper() // common parts for implementations based on MLTE -class wxMacMLTEControl : public wxMacTextControl +class wxMacMLTEControl : public wxMacControl, public wxTextWidgetImpl { public : wxMacMLTEControl( wxTextCtrl *peer ) ; - + ~wxMacMLTEControl() {} virtual wxString GetStringValue() const ; virtual void SetStringValue( const wxString &str ) ; @@ -378,7 +378,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, if ( UMAGetSystemVersion() >= 0x1050 ) forceMLTE = false; - wxMacTextControl* peer = NULL; + wxMacControl* peer = NULL; if ( !forceMLTE ) { @@ -466,7 +466,7 @@ static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler ) -wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacTextControl( wxPeer ) +wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacControl( wxPeer ) { } @@ -474,15 +474,7 @@ wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, const wxString& str, const wxPoint& pos, const wxSize& size, long style ) - : wxMacTextControl( wxPeer ) -{ - Create( wxPeer, str, pos, size, style ); -} - -bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) + : wxMacControl( wxPeer ) { m_font = wxPeer->GetFont() ; m_windowStyle = style ; @@ -491,19 +483,29 @@ bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, wxString st = str ; wxMacConvertNewlines10To13( &st ) ; wxCFStringRef cf(st , m_font.GetEncoding()) ; - CFStringRef cfr = cf ; m_valueTag = kControlEditTextCFStringTag ; - CreateControl( wxPeer, &bounds, cfr ); + Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; + if ( isPassword ) + { + m_valueTag = kControlEditTextPasswordCFStringTag ; + } + OSStatus err = CreateEditUnicodeTextControl( + MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cf , + isPassword , NULL , &m_controlRef ) ; + verify_noerr( err ); if ( !(m_windowStyle & wxTE_MULTILINE) ) SetData( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; + InstallEventHandlers(); +} + +void wxMacUnicodeTextControl::InstallEventHandlers() +{ ::InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, NULL); - - return true; } wxMacUnicodeTextControl::~wxMacUnicodeTextControl() @@ -555,19 +557,6 @@ void wxMacUnicodeTextControl::SetStringValue( const wxString &str ) verify_noerr( SetData( 0, m_valueTag , cf ) ) ; } -void wxMacUnicodeTextControl::CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef cfr ) -{ - Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; - if ( isPassword ) - { - m_valueTag = kControlEditTextPasswordCFStringTag ; - } - OSStatus err = CreateEditUnicodeTextControl( - MAC_WXHWND(peer->MacGetTopLevelWindowRef()), bounds , cfr , - isPassword , NULL , &m_controlRef ) ; - verify_noerr( err ); -} - void wxMacUnicodeTextControl::Copy() { SendHICommand( kHICommandCopy ) ; @@ -713,7 +702,7 @@ protected : } ; wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) - : wxMacTextControl( peer ) + : wxMacControl( peer ) { SetNeedsFocusRect( true ) ; } diff --git a/src/osx/carbon/utils.cpp b/src/osx/carbon/utils.cpp index a1015f90c2..7030447039 100644 --- a/src/osx/carbon/utils.cpp +++ b/src/osx/carbon/utils.cpp @@ -259,27 +259,6 @@ void wxMacNativeToPoint( const Point *n , wxPoint* wx ) wx->y = n->v; } -//--------------------------------------------------------------------------- -// wxMac Specific string utility functions -//--------------------------------------------------------------------------- - -void wxMacStringToPascal( const wxString&from , StringPtr to ) -{ - wxCharBuffer buf = from.mb_str( wxConvLocal ); - int len = strlen(buf); - - if ( len > 255 ) - len = 255; - to[0] = len; - memcpy( (char*) &to[1] , buf , len ); -} - -wxString wxMacMakeStringFromPascal( ConstStringPtr from ) -{ - return wxString( (char*) &from[1] , wxConvLocal , from[0] ); -} - - // ---------------------------------------------------------------------------- // Carbon Event Support // ---------------------------------------------------------------------------- diff --git a/src/osx/carbon/window.cpp b/src/osx/carbon/window.cpp index a24d1a6f55..00d919ffca 100644 --- a/src/osx/carbon/window.cpp +++ b/src/osx/carbon/window.cpp @@ -1184,7 +1184,7 @@ void wxMacControl::SuperChangedPosition() { } -void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) +void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack ) { m_font = font; #if wxOSX_USE_CORE_TEXT @@ -1199,7 +1199,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l HIViewSetTextFont( m_controlRef , part , (CTFontRef) font.MacGetCTFont() ); HIViewSetTextHorizontalFlush( m_controlRef, part, flush ); - if ( foreground != *wxBLACK ) + if ( foreground != *wxBLACK || ignoreBlack == false ) { ControlFontStyleRec fontStyle; foreground.GetRGBColor( &fontStyle.foreColor ); @@ -1252,7 +1252,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l // we only should do this in case of a non-standard color, as otherwise 'disabled' controls // won't get grayed out by the system anymore - if ( foreground != *wxBLACK ) + if ( foreground != *wxBLACK || ignoreBlack == false ) { foreground.GetRGBColor( &fontStyle.foreColor ); fontStyle.flags |= kControlUseForeColorMask; diff --git a/src/osx/cocoa/glcanvas.mm b/src/osx/cocoa/glcanvas.mm index fa9a2e5f04..df3bb0e424 100644 --- a/src/osx/cocoa/glcanvas.mm +++ b/src/osx/cocoa/glcanvas.mm @@ -304,39 +304,6 @@ bool wxGLCanvas::Create(wxWindow *parent, return true; } -bool wxGLCanvas::Create(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name, - const int *attribList, - const wxPalette& WXUNUSED(palette)) -{ - m_needsUpdate = false; - m_macCanvasIsShown = false; - - m_glFormat = WXGLChoosePixelFormat(attribList); - if ( !m_glFormat ) - return false; - - if ( !wxWindow::Create(parent, id, pos, size, style, name) ) - return false; - - m_dummyContext = WXGLCreateContext(m_glFormat, NULL); - - static GLint gCurrentBufferName = 1; - m_bufferName = gCurrentBufferName++; - aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); - - AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef())); - aglSetDrawable(m_dummyContext, drawable); - - m_macCanvasIsShown = true; - - return true; -} - wxGLCanvas::~wxGLCanvas() { if ( m_glFormat ) diff --git a/src/osx/cocoa/msgdlg.mm b/src/osx/cocoa/msgdlg.mm index bf82c5c956..2189cdf610 100644 --- a/src/osx/cocoa/msgdlg.mm +++ b/src/osx/cocoa/msgdlg.mm @@ -74,15 +74,15 @@ int wxMessageDialog::ShowModal() wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") ); - AlertType alertType = kAlertPlainAlert; + NSAlertStyle alertType = NSWarningAlertStyle; if (style & wxICON_EXCLAMATION) - alertType = kAlertCautionAlert; + alertType = NSCriticalAlertStyle; else if (style & wxICON_HAND) - alertType = kAlertStopAlert; + alertType = NSWarningAlertStyle; else if (style & wxICON_INFORMATION) - alertType = kAlertNoteAlert; + alertType = NSInformationalAlertStyle; else if (style & wxICON_QUESTION) - alertType = kAlertNoteAlert; + alertType = NSInformationalAlertStyle; // work out what to display @@ -164,9 +164,8 @@ int wxMessageDialog::ShowModal() } else { - short result; - - AlertStdCFStringAlertParamRec param; + NSAlert* alert = [[NSAlert alloc] init]; + wxCFStringRef cfNoString( m_no.c_str(), GetFont().GetEncoding() ); wxCFStringRef cfYesString( m_yes.c_str(), GetFont().GetEncoding() ); wxCFStringRef cfOKString( m_ok.c_str(), GetFont().GetEncoding() ); @@ -175,108 +174,59 @@ int wxMessageDialog::ShowModal() wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() ); wxCFStringRef cfText( msgtext, GetFont().GetEncoding() ); - param.movable = true; - param.flags = 0; - param.version = kStdCFStringAlertVersionOne; - - bool skipDialog = false; + [alert setMessageText:cfTitle.AsNSString()]; + [alert setInformativeText:cfText.AsNSString()]; + + int buttonId[3] = { 0, 0, 0 }; + int buttonCount = 0; if (style & wxYES_NO) { - if (style & wxCANCEL) + if ( style & wxNO_DEFAULT ) { - param.defaultText = cfYesString; - param.cancelText = cfCancelString; - param.otherText = cfNoString; - param.helpButton = false; - param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; - param.cancelButton = kAlertStdAlertCancelButton; + [alert addButtonWithTitle:cfNoString.AsNSString()]; + buttonId[ buttonCount++ ] = wxID_NO; + [alert addButtonWithTitle:cfYesString.AsNSString()]; + buttonId[ buttonCount++ ] = wxID_YES; } else { - param.defaultText = cfYesString; - param.cancelText = NULL; - param.otherText = cfNoString; - param.helpButton = false; - param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; - param.cancelButton = 0; + [alert addButtonWithTitle:cfYesString.AsNSString()]; + buttonId[ buttonCount++ ] = wxID_YES; + [alert addButtonWithTitle:cfNoString.AsNSString()]; + buttonId[ buttonCount++ ] = wxID_NO; + } + + if (style & wxCANCEL) + { + [alert addButtonWithTitle:cfCancelString.AsNSString()]; + buttonId[ buttonCount++ ] = wxID_CANCEL; } } // the MSW implementation even shows an OK button if it is not specified, we'll do the same else { + [alert addButtonWithTitle:cfOKString.AsNSString()]; + buttonId[ buttonCount++ ] = wxID_OK; if (style & wxCANCEL) { - // that's a cancel missing - param.defaultText = cfOKString; - param.cancelText = cfCancelString; - param.otherText = NULL; - param.helpButton = false; - param.defaultButton = kAlertStdAlertOKButton; - param.cancelButton = 0; - } - else - { - param.defaultText = cfOKString; - param.cancelText = NULL; - param.otherText = NULL; - param.helpButton = false; - param.defaultButton = kAlertStdAlertOKButton; - param.cancelButton = 0; + [alert addButtonWithTitle:cfCancelString.AsNSString()]; + buttonId[ buttonCount++ ] = wxID_CANCEL; } } - param.position = kWindowDefaultPosition; - if ( !skipDialog ) - { - DialogRef alertRef; - CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); - RunStandardAlert( alertRef, NULL, &result ); - } + int button = [alert runModal]; + + [alert release]; + + if ( button < NSAlertFirstButtonReturn ) + resultbutton = wxID_CANCEL; else { - return wxID_CANCEL; - } - - if (style & wxOK) - { - switch ( result ) - { - case 1: - resultbutton = wxID_OK; - break; - - case 2: - // TODO: add Cancel button - // if (style & wxCANCEL) - // resultbutton = wxID_CANCEL; - break; - - case 3: - default: - break; - } - } - else if (style & wxYES_NO) - { - switch ( result ) - { - case 1: - resultbutton = wxID_YES; - break; - - case 2: - if (!(style & wxCANCEL)) - resultbutton = wxID_CANCEL; - break; - - case 3: - resultbutton = wxID_NO; - break; - - default: - break; - } + if ( button - NSAlertFirstButtonReturn < buttonCount ) + resultbutton = buttonId[ button - NSAlertFirstButtonReturn ]; + else + resultbutton = wxID_CANCEL; } } diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm index cc744f8c72..0c33e98599 100644 --- a/src/osx/cocoa/srchctrl.mm +++ b/src/osx/cocoa/srchctrl.mm @@ -25,368 +25,165 @@ #if wxUSE_NATIVE_SEARCH_CONTROL -#include "wx/osx/uma.h" -#include "wx/osx/carbon/private/mactext.h" +#include "wx/osx/private.h" +#include "wx/osx/cocoa/private/textimpl.h" -BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) -END_EVENT_TABLE() -IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) - -// ============================================================================ -// wxMacSearchFieldControl -// ============================================================================ - -static const EventTypeSpec eventList[] = -{ - { kEventClassSearchField, kEventSearchFieldCancelClicked } , - { kEventClassSearchField, kEventSearchFieldSearchClicked } , -}; - -class wxMacSearchFieldControl : public wxMacUnicodeTextControl -{ -public : - wxMacSearchFieldControl( wxTextCtrl *wxPeer, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) : wxMacUnicodeTextControl( wxPeer ) - { - Create( wxPeer, str, pos, size, style ); - } - - // search field options - virtual void ShowSearchButton( bool show ); - virtual bool IsSearchButtonVisible() const; - - virtual void ShowCancelButton( bool show ); - virtual bool IsCancelButtonVisible() const; - - virtual void SetSearchMenu( wxMenu* menu ); - virtual wxMenu* GetSearchMenu() const; - - virtual void SetDescriptiveText(const wxString& text); - virtual wxString GetDescriptiveText() const; - - virtual bool SetFocus(); - -protected : - virtual void CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef crf ); - -private: - wxMenu* m_menu; -} ; - -void wxMacSearchFieldControl::CreateControl(wxTextCtrl* WXUNUSED(peer), - const Rect* bounds, - CFStringRef WXUNUSED(crf)) +@interface wxNSSearchField : NSSearchField { - OptionBits attributes = kHISearchFieldAttributesSearchIcon; - - HIRect hibounds = { { bounds->left, bounds->top }, { bounds->right-bounds->left, bounds->bottom-bounds->top } }; - verify_noerr( HISearchFieldCreate( - &hibounds, - attributes, - 0, // MenuRef - CFSTR("Search"), - &m_controlRef - ) ); - HIViewSetVisible (m_controlRef, true); + wxWidgetImpl* impl; } -// search field options -void wxMacSearchFieldControl::ShowSearchButton( bool show ) -{ - OptionBits set = 0; - OptionBits clear = 0; - if ( show ) - { - set |= kHISearchFieldAttributesSearchIcon; - } - else - { - clear |= kHISearchFieldAttributesSearchIcon; - } - HISearchFieldChangeAttributes( m_controlRef, set, clear ); -} +@end -bool wxMacSearchFieldControl::IsSearchButtonVisible() const -{ - OptionBits attributes = 0; - verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) ); - return ( attributes & kHISearchFieldAttributesSearchIcon ) != 0; -} +@implementation wxNSSearchField -void wxMacSearchFieldControl::ShowCancelButton( bool show ) +- (id)initWithFrame:(NSRect)frame { - OptionBits set = 0; - OptionBits clear = 0; - if ( show ) - { - set |= kHISearchFieldAttributesCancel; - } - else - { - clear |= kHISearchFieldAttributesCancel; - } - HISearchFieldChangeAttributes( m_controlRef, set, clear ); + [super initWithFrame:frame]; + impl = NULL; + [self setTarget: self]; + [self setAction: @selector(searchAction:)]; + return self; } -bool wxMacSearchFieldControl::IsCancelButtonVisible() const +- (void)setImplementation: (wxWidgetImpl *) theImplementation { - OptionBits attributes = 0; - verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) ); - return ( attributes & kHISearchFieldAttributesCancel ) != 0; + impl = theImplementation; } -void wxMacSearchFieldControl::SetSearchMenu( wxMenu* menu ) +- (wxWidgetImpl*) implementation { - m_menu = menu; - if ( m_menu ) - { - verify_noerr( HISearchFieldSetSearchMenu( m_controlRef, MAC_WXHMENU(m_menu->GetHMenu()) ) ); - } - else - { - verify_noerr( HISearchFieldSetSearchMenu( m_controlRef, 0 ) ); - } + return impl; } -wxMenu* wxMacSearchFieldControl::GetSearchMenu() const +- (BOOL) isFlipped { - return m_menu; + return YES; } - -void wxMacSearchFieldControl::SetDescriptiveText(const wxString& text) +// use our common calls +- (void) setTitle:(NSString *) title { - verify_noerr( HISearchFieldSetDescriptiveText( - m_controlRef, - wxCFStringRef( text, wxFont::GetDefaultEncoding() ))); + [self setStringValue: title]; } -wxString wxMacSearchFieldControl::GetDescriptiveText() const +- (void) searchAction: (id) sender { - CFStringRef cfStr; - verify_noerr( HISearchFieldCopyDescriptiveText( m_controlRef, &cfStr )); - if ( cfStr ) - { - return wxCFStringRef(cfStr).AsString(); - } - else + if ( impl ) { - return wxEmptyString; + wxSearchCtrl* wxpeer = dynamic_cast( impl->GetWXPeer() ); + if ( wxpeer ) + { + NSString *searchString = [self stringValue]; + if ( searchString == nil ) + { + wxpeer->HandleSearchFieldCancelHit(); + } + else + { + wxpeer->HandleSearchFieldSearchHit(); + } + } } } -bool wxMacSearchFieldControl::SetFocus() -{ - // NB: We have to implement SetFocus a little differently because kControlFocusNextPart - // leads to setting the focus on the search icon rather than the text area. - // We get around this by explicitly telling the control to set focus to the - // text area. - - OSStatus err = SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, kControlEditTextPart ); - if ( err == errCouldntSetFocus ) - return false ; - SetUserFocusWindow(GetControlOwner( m_controlRef ) ); - return true; -} - +@end // ============================================================================ -// implementation +// wxMacSearchFieldControl // ============================================================================ -static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +class wxNSSearchFieldControl : public wxNSTextFieldControl, public wxSearchWidgetImpl { - OSStatus result = eventNotHandledErr ; - - wxMacCarbonEvent cEvent( event ) ; - - ControlRef controlRef ; - wxSearchCtrl* thisWindow = (wxSearchCtrl*) data ; - cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; - - switch( GetEventKind( event ) ) +public : + wxNSSearchFieldControl( wxTextCtrl *wxPeer, wxNSSearchField* w ) : wxNSTextFieldControl(wxPeer, w) { - case kEventSearchFieldCancelClicked : - thisWindow->MacSearchFieldCancelHit( handler , event ) ; - break ; - case kEventSearchFieldSearchClicked : - thisWindow->MacSearchFieldSearchHit( handler , event ) ; - break ; + m_searchFieldCell = [w cell]; + m_searchField = w; } + ~wxNSSearchFieldControl(); - return result ; -} - -DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacSearchControlEventHandler ) - - -// ---------------------------------------------------------------------------- -// wxSearchCtrl creation -// ---------------------------------------------------------------------------- - -// creation -// -------- - -wxSearchCtrl::wxSearchCtrl() -{ - Init(); -} - -wxSearchCtrl::wxSearchCtrl(wxWindow *parent, wxWindowID id, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - Init(); - - Create(parent, id, value, pos, size, style, validator, name); -} - -void wxSearchCtrl::Init() -{ - m_menu = 0; -} - -bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - if ( !wxTextCtrl::Create(parent, id, wxEmptyString, pos, size, wxBORDER_NONE | style, validator, name) ) + // search field options + virtual void ShowSearchButton( bool show ) { - return false; + if ( show ) + [m_searchFieldCell resetSearchButtonCell]; + else + [m_searchFieldCell setSearchButtonCell:nil]; + [m_searchField setNeedsDisplay:YES]; } - - EventHandlerRef searchEventHandler; - InstallControlEventHandler( m_peer->GetControlRef(), GetwxMacSearchControlEventHandlerUPP(), - GetEventTypeCount(eventList), eventList, this, - (EventHandlerRef *)&searchEventHandler); - - SetValue(value); - - return true; -} - -wxSearchCtrl::~wxSearchCtrl() -{ - delete m_menu; -} - -wxSize wxSearchCtrl::DoGetBestSize() const -{ - wxSize size = wxWindow::DoGetBestSize(); - // it seems to return a default width of about 16, which is way too small here. - if (size.GetWidth() < 100) - size.SetWidth(100); - - return size; -} - - -// search control specific interfaces -// wxSearchCtrl owns menu after this call -void wxSearchCtrl::SetMenu( wxMenu* menu ) -{ - if ( menu == m_menu ) + + virtual bool IsSearchButtonVisible() const { - // no change - return; + return [m_searchFieldCell searchButtonCell] != nil; } - if ( m_menu ) + virtual void ShowCancelButton( bool show ) { - m_menu->SetInvokingWindow( 0 ); + if ( show ) + [m_searchFieldCell resetCancelButtonCell]; + else + [m_searchFieldCell setCancelButtonCell:nil]; + [m_searchField setNeedsDisplay:YES]; } - - delete m_menu; - m_menu = menu; - - if ( m_menu ) + + virtual bool IsCancelButtonVisible() const { - m_menu->SetInvokingWindow( this ); + return [m_searchFieldCell cancelButtonCell] != nil; } - GetPeer()->SetSearchMenu( m_menu ); -} - -wxMenu* wxSearchCtrl::GetMenu() -{ - return m_menu; -} - -void wxSearchCtrl::ShowSearchButton( bool show ) -{ - if ( IsSearchButtonVisible() == show ) + virtual void SetSearchMenu( wxMenu* menu ) { - // no change - return; + if ( menu ) + [m_searchFieldCell setSearchMenuTemplate:menu->GetHMenu()]; + else + [m_searchFieldCell setSearchMenuTemplate:nil]; + [m_searchField setNeedsDisplay:YES]; } - GetPeer()->ShowSearchButton( show ); -} -bool wxSearchCtrl::IsSearchButtonVisible() const -{ - return GetPeer()->IsSearchButtonVisible(); -} - - -void wxSearchCtrl::ShowCancelButton( bool show ) -{ - if ( IsCancelButtonVisible() == show ) + virtual void SetDescriptiveText(const wxString& text) { - // no change - return; + [m_searchFieldCell setPlaceholderString: + wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; + } + + virtual bool SetFocus() + { + return wxNSTextFieldControl::SetFocus(); } - GetPeer()->ShowCancelButton( show ); -} - -bool wxSearchCtrl::IsCancelButtonVisible() const -{ - return GetPeer()->IsCancelButtonVisible(); -} - -void wxSearchCtrl::SetDescriptiveText(const wxString& text) -{ - GetPeer()->SetDescriptiveText(text); -} - -wxString wxSearchCtrl::GetDescriptiveText() const -{ - return GetPeer()->GetDescriptiveText(); -} -wxInt32 wxSearchCtrl::MacSearchFieldSearchHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId ); - event.SetEventObject(this); - ProcessCommand(event); - return eventNotHandledErr ; -} +private: + wxNSSearchField* m_searchField; + NSSearchFieldCell* m_searchFieldCell; +} ; -wxInt32 wxSearchCtrl::MacSearchFieldCancelHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +wxNSSearchFieldControl::~wxNSSearchFieldControl() { - wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId ); - event.SetEventObject(this); - ProcessCommand(event); - return eventNotHandledErr ; } - -void wxSearchCtrl::CreatePeer( - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) +wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& str, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_peer = new wxMacSearchFieldControl( this , str , pos , size , style ); + NSView* sv = (wxpeer->GetParent()->GetHandle() ); + + NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; + wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r]; + [sv addSubview:v]; + [[v cell] setSendsWholeSearchString:YES]; + // per wx default cancel is not shown + [[v cell] setCancelButtonCell:nil]; + + wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v ); + c->SetStringValue( str ); + [v setImplementation:c]; + return c; } #endif // wxUSE_NATIVE_SEARCH_CONTROL diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 163f8a1fbc..7b7189e7d8 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -47,8 +47,7 @@ #include "wx/thread.h" #include "wx/osx/private.h" -#include "wx/osx/carbon/private/mactext.h" - +#include "wx/osx/cocoa/private/textimpl.h" @implementation wxNSTextField @@ -75,40 +74,58 @@ @end -class wxNSTextFieldControl : public wxMacTextControl -{ -public : - wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxMacTextControl(wxPeer, w) - { - } - virtual ~wxNSTextFieldControl() - { - } - - virtual void VisibilityChanged(bool shown){} - virtual wxString GetStringValue() const - { - wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] ); - return cf.AsString(m_wxPeer->GetFont().GetEncoding()); - } - virtual void SetStringValue( const wxString &str) - { - [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; - } - virtual void Copy() {} - virtual void Cut() {} - virtual void Paste() {} - virtual bool CanPaste() const { return false;} - virtual void SetEditable(bool editable) {} - virtual void GetSelection( long* from, long* to) const {} - virtual void SetSelection( long from , long to ){} - virtual void WriteText(const wxString& str) - { - // temp hack to get logging working early - wxString former = GetStringValue(); - SetStringValue( former + str ); - } -}; +wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w) +{ +} + +wxNSTextFieldControl::~wxNSTextFieldControl() +{ +} + +wxString wxNSTextFieldControl::GetStringValue() const +{ + wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] ); + return cf.AsString(m_wxPeer->GetFont().GetEncoding()); +} +void wxNSTextFieldControl::SetStringValue( const wxString &str) +{ + [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; +} +void wxNSTextFieldControl::Copy() +{ +} + +void wxNSTextFieldControl::Cut() +{ +} + +void wxNSTextFieldControl::Paste() +{ +} + +bool wxNSTextFieldControl::CanPaste() const +{ + return false; +} + +void wxNSTextFieldControl::SetEditable(bool editable) +{ +} + +void wxNSTextFieldControl::GetSelection( long* from, long* to) const +{ +} + +void wxNSTextFieldControl::SetSelection( long from , long to ) +{ +} + +void wxNSTextFieldControl::WriteText(const wxString& str) +{ + // temp hack to get logging working early + wxString former = GetStringValue(); + SetStringValue( former + str ); +} wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, wxWindowMac* parent, diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 7cff3356c6..a358f96dca 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -708,6 +708,11 @@ void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant ) [m_osxView setControlSize:size]; } +void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool) +{ + // TODO +} + // // Factory methods // diff --git a/src/osx/srchctrl_osx.cpp b/src/osx/srchctrl_osx.cpp index c5de244400..d264955f00 100644 --- a/src/osx/srchctrl_osx.cpp +++ b/src/osx/srchctrl_osx.cpp @@ -25,8 +25,195 @@ #if wxUSE_NATIVE_SEARCH_CONTROL -// no common code yet, only here as placeholder +#include "wx/osx/private.h" + +BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) +END_EVENT_TABLE() + +IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) + #endif // wxUSE_NATIVE_SEARCH_CONTROL + +// ---------------------------------------------------------------------------- +// wxSearchCtrl creation +// ---------------------------------------------------------------------------- + +// creation +// -------- + +wxSearchCtrl::wxSearchCtrl() +{ + Init(); +} + +wxSearchCtrl::wxSearchCtrl(wxWindow *parent, wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) +{ + Init(); + + Create(parent, id, value, pos, size, style, validator, name); +} + +void wxSearchCtrl::Init() +{ + m_menu = 0; +} + +wxSearchWidgetImpl* wxSearchCtrl::GetSearchPeer() const +{ + return dynamic_cast (m_peer); +} + +wxSearchCtrl::~wxSearchCtrl() +{ + delete m_menu; +} + +wxSize wxSearchCtrl::DoGetBestSize() const +{ + wxSize size = wxWindow::DoGetBestSize(); + // it seems to return a default width of about 16, which is way too small here. + if (size.GetWidth() < 100) + size.SetWidth(100); + + return size; +} + + +// search control specific interfaces +// wxSearchCtrl owns menu after this call +void wxSearchCtrl::SetMenu( wxMenu* menu ) +{ + if ( menu == m_menu ) + { + // no change + return; + } + + if ( m_menu ) + { + m_menu->SetInvokingWindow( 0 ); + } + + delete m_menu; + m_menu = menu; + + if ( m_menu ) + { + m_menu->SetInvokingWindow( this ); + } + + GetSearchPeer()->SetSearchMenu( m_menu ); +} + +wxMenu* wxSearchCtrl::GetMenu() +{ + return m_menu; +} + +void wxSearchCtrl::ShowSearchButton( bool show ) +{ + if ( IsSearchButtonVisible() == show ) + { + // no change + return; + } + GetSearchPeer()->ShowSearchButton( show ); +} + +bool wxSearchCtrl::IsSearchButtonVisible() const +{ + return GetSearchPeer()->IsSearchButtonVisible(); +} + + +void wxSearchCtrl::ShowCancelButton( bool show ) +{ + if ( IsCancelButtonVisible() == show ) + { + // no change + return; + } + GetSearchPeer()->ShowCancelButton( show ); +} + +bool wxSearchCtrl::IsCancelButtonVisible() const +{ + return GetSearchPeer()->IsCancelButtonVisible(); +} + +void wxSearchCtrl::SetDescriptiveText(const wxString& text) +{ + m_descriptiveText = text; + GetSearchPeer()->SetDescriptiveText(text); +} + +wxString wxSearchCtrl::GetDescriptiveText() const +{ + return m_descriptiveText; +} + +bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) +{ + m_macIsUserPane = false ; + m_editable = true ; + + if ( ! (style & wxNO_BORDER) ) + style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; + + if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) + return false; + + if ( m_windowStyle & wxTE_MULTILINE ) + { + // always turn on this style for multi-line controls + m_windowStyle |= wxTE_PROCESS_ENTER; + style |= wxTE_PROCESS_ENTER ; + } + + + m_peer = wxWidgetImpl::CreateSearchControl( this, GetParent(), GetId(), value, pos, size, style, GetExtraStyle() ); + + MacPostControlCreate(pos, size) ; + + // only now the embedding is correct and we can do a positioning update + + MacSuperChangedPosition() ; + + if ( m_windowStyle & wxTE_READONLY) + SetEditable( false ) ; + + SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; + + return true; +} + +bool wxSearchCtrl::HandleSearchFieldSearchHit() +{ + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId ); + event.SetEventObject(this); + return ProcessCommand(event); +} + +bool wxSearchCtrl::HandleSearchFieldCancelHit() +{ + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId ); + event.SetEventObject(this); + return ProcessCommand(event); +} + + #endif // wxUSE_SEARCHCTRL diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 861cc4b92b..feda0352d3 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -47,7 +47,6 @@ #include "wx/thread.h" #include "wx/osx/private.h" -#include "wx/osx/carbon/private/mactext.h" IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) @@ -116,9 +115,8 @@ bool wxTextCtrl::Create( wxWindow *parent, style |= wxTE_PROCESS_ENTER ; } - m_peer = wxWidgetImpl::CreateTextControl( this, parent, id, str, pos, size, style, GetExtraStyle() ); - // CreatePeer( str, pos, size, style ); + m_peer = wxWidgetImpl::CreateTextControl( this, GetParent(), GetId(), str, pos, size, style, GetExtraStyle() ); MacPostControlCreate(pos, size) ; @@ -134,11 +132,9 @@ bool wxTextCtrl::Create( wxWindow *parent, return true; } -void wxTextCtrl::CreatePeer( - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) +wxTextWidgetImpl* wxTextCtrl::GetTextPeer() const { + return dynamic_cast (m_peer); } void wxTextCtrl::MacSuperChangedPosition() @@ -158,17 +154,17 @@ void wxTextCtrl::MacVisibilityChanged() void wxTextCtrl::MacCheckSpelling(bool check) { - GetPeer()->CheckSpelling(check); + GetTextPeer()->CheckSpelling(check); } wxString wxTextCtrl::GetValue() const { - return GetPeer()->GetStringValue() ; + return GetTextPeer()->GetStringValue() ; } void wxTextCtrl::GetSelection(long* from, long* to) const { - GetPeer()->GetSelection( from , to ) ; + GetTextPeer()->GetSelection( from , to ) ; } void wxTextCtrl::DoSetValue(const wxString& str, int flags) @@ -177,7 +173,7 @@ void wxTextCtrl::DoSetValue(const wxString& str, int flags) if ( GetValue() == str ) return; - GetPeer()->SetStringValue( str ) ; + GetTextPeer()->SetStringValue( str ) ; if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) { @@ -195,14 +191,14 @@ bool wxTextCtrl::SetFont( const wxFont& font ) if ( !wxTextCtrlBase::SetFont( font ) ) return false ; - GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; + GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle(), false /* dont ignore black */ ) ; return true ; } bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) { - GetPeer()->SetStyle( start , end , style ) ; + GetTextPeer()->SetStyle( start , end , style ) ; return true ; } @@ -220,14 +216,14 @@ bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) void wxTextCtrl::Copy() { if (CanCopy()) - GetPeer()->Copy() ; + GetTextPeer()->Copy() ; } void wxTextCtrl::Cut() { if (CanCut()) { - GetPeer()->Cut() ; + GetTextPeer()->Cut() ; wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); event.SetEventObject( this ); @@ -239,7 +235,7 @@ void wxTextCtrl::Paste() { if (CanPaste()) { - GetPeer()->Paste() ; + GetTextPeer()->Paste() ; // TODO: eventually we should add setting the default style again @@ -275,7 +271,7 @@ bool wxTextCtrl::CanPaste() const if (!IsEditable()) return false; - return GetPeer()->CanPaste() ; + return GetTextPeer()->CanPaste() ; } void wxTextCtrl::SetEditable(bool editable) @@ -283,7 +279,7 @@ void wxTextCtrl::SetEditable(bool editable) if ( editable != m_editable ) { m_editable = editable ; - GetPeer()->SetEditable( editable ) ; + GetTextPeer()->SetEditable( editable ) ; } } @@ -308,27 +304,27 @@ long wxTextCtrl::GetInsertionPoint() const wxTextPos wxTextCtrl::GetLastPosition() const { - return GetPeer()->GetLastPosition() ; + return GetTextPeer()->GetLastPosition() ; } void wxTextCtrl::Replace(long from, long to, const wxString& str) { - GetPeer()->Replace( from , to , str ) ; + GetTextPeer()->Replace( from , to , str ) ; } void wxTextCtrl::Remove(long from, long to) { - GetPeer()->Remove( from , to ) ; + GetTextPeer()->Remove( from , to ) ; } void wxTextCtrl::SetSelection(long from, long to) { - GetPeer()->SetSelection( from , to ) ; + GetTextPeer()->SetSelection( from , to ) ; } void wxTextCtrl::WriteText(const wxString& str) { - GetPeer()->WriteText( str ) ; + GetTextPeer()->WriteText( str ) ; } void wxTextCtrl::AppendText(const wxString& text) @@ -339,7 +335,7 @@ void wxTextCtrl::AppendText(const wxString& text) void wxTextCtrl::Clear() { - GetPeer()->Clear() ; + GetTextPeer()->Clear() ; } bool wxTextCtrl::IsModified() const @@ -403,13 +399,13 @@ wxSize wxTextCtrl::DoGetBestSize() const void wxTextCtrl::Undo() { if (CanUndo()) - GetPeer()->Undo() ; + GetTextPeer()->Undo() ; } void wxTextCtrl::Redo() { if (CanRedo()) - GetPeer()->Redo() ; + GetTextPeer()->Redo() ; } bool wxTextCtrl::CanUndo() const @@ -417,7 +413,7 @@ bool wxTextCtrl::CanUndo() const if ( !IsEditable() ) return false ; - return GetPeer()->CanUndo() ; + return GetTextPeer()->CanUndo() ; } bool wxTextCtrl::CanRedo() const @@ -425,7 +421,7 @@ bool wxTextCtrl::CanRedo() const if ( !IsEditable() ) return false ; - return GetPeer()->CanRedo() ; + return GetTextPeer()->CanRedo() ; } void wxTextCtrl::MarkDirty() @@ -440,32 +436,32 @@ void wxTextCtrl::DiscardEdits() int wxTextCtrl::GetNumberOfLines() const { - return GetPeer()->GetNumberOfLines() ; + return GetTextPeer()->GetNumberOfLines() ; } long wxTextCtrl::XYToPosition(long x, long y) const { - return GetPeer()->XYToPosition( x , y ) ; + return GetTextPeer()->XYToPosition( x , y ) ; } bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const { - return GetPeer()->PositionToXY( pos , x , y ) ; + return GetTextPeer()->PositionToXY( pos , x , y ) ; } void wxTextCtrl::ShowPosition(long pos) { - return GetPeer()->ShowPosition(pos) ; + return GetTextPeer()->ShowPosition(pos) ; } int wxTextCtrl::GetLineLength(long lineNo) const { - return GetPeer()->GetLineLength(lineNo) ; + return GetTextPeer()->GetLineLength(lineNo) ; } wxString wxTextCtrl::GetLineText(long lineNo) const { - return GetPeer()->GetLineText(lineNo) ; + return GetTextPeer()->GetLineText(lineNo) ; } void wxTextCtrl::Command(wxCommandEvent & event) @@ -706,7 +702,7 @@ void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) { - if ( GetPeer()->HasOwnContextMenu() ) + if ( GetTextPeer()->HasOwnContextMenu() ) { event.Skip() ; return ; @@ -734,7 +730,7 @@ void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) { - if ( !GetPeer()->SetupCursor( pt ) ) + if ( !GetTextPeer()->SetupCursor( pt ) ) return wxWindow::MacSetupCursor( pt ) ; else return true ; @@ -744,104 +740,90 @@ bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) // implementation base class // ---------------------------------------------------------------------------- -#if wxOSX_USE_CARBON - wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : - wxMacControl( peer ) -#else - wxMacTextControl::wxMacTextControl(wxTextCtrl* peer, WXWidget w) : - wxWidgetCocoaImpl( peer, w ) -#endif -{ -} - -wxMacTextControl::~wxMacTextControl() -{ -} - -void wxMacTextControl::SetStyle(long WXUNUSED(start), +void wxTextWidgetImpl::SetStyle(long WXUNUSED(start), long WXUNUSED(end), const wxTextAttr& WXUNUSED(style)) { } -void wxMacTextControl::Copy() +void wxTextWidgetImpl::Copy() { } -void wxMacTextControl::Cut() +void wxTextWidgetImpl::Cut() { } -void wxMacTextControl::Paste() +void wxTextWidgetImpl::Paste() { } -bool wxMacTextControl::CanPaste() const +bool wxTextWidgetImpl::CanPaste() const { return false ; } -void wxMacTextControl::SetEditable(bool WXUNUSED(editable)) +void wxTextWidgetImpl::SetEditable(bool WXUNUSED(editable)) { } -wxTextPos wxMacTextControl::GetLastPosition() const +wxTextPos wxTextWidgetImpl::GetLastPosition() const { return GetStringValue().length() ; } -void wxMacTextControl::Replace( long from , long to , const wxString &val ) +void wxTextWidgetImpl::Replace( long from , long to , const wxString &val ) { SetSelection( from , to ) ; WriteText( val ) ; } -void wxMacTextControl::Remove( long from , long to ) +void wxTextWidgetImpl::Remove( long from , long to ) { SetSelection( from , to ) ; WriteText( wxEmptyString) ; } -void wxMacTextControl::Clear() +void wxTextWidgetImpl::Clear() { SetStringValue( wxEmptyString ) ; } -bool wxMacTextControl::CanUndo() const +bool wxTextWidgetImpl::CanUndo() const { return false ; } -void wxMacTextControl::Undo() +void wxTextWidgetImpl::Undo() { } -bool wxMacTextControl::CanRedo() const +bool wxTextWidgetImpl::CanRedo() const { return false ; } -void wxMacTextControl::Redo() +void wxTextWidgetImpl::Redo() { } -long wxMacTextControl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const +long wxTextWidgetImpl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const { return 0 ; } -bool wxMacTextControl::PositionToXY(long WXUNUSED(pos), +bool wxTextWidgetImpl::PositionToXY(long WXUNUSED(pos), long *WXUNUSED(x), long *WXUNUSED(y)) const { return false ; } -void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) +void wxTextWidgetImpl::ShowPosition( long WXUNUSED(pos) ) { } -int wxMacTextControl::GetNumberOfLines() const +int wxTextWidgetImpl::GetNumberOfLines() const { ItemCount lines = 0 ; wxString content = GetStringValue() ; @@ -856,7 +838,7 @@ int wxMacTextControl::GetNumberOfLines() const return lines ; } -wxString wxMacTextControl::GetLineText(long lineNo) const +wxString wxTextWidgetImpl::GetLineText(long lineNo) const { // TODO: change this if possible to reflect real lines wxString content = GetStringValue() ; @@ -888,7 +870,7 @@ wxString wxMacTextControl::GetLineText(long lineNo) const return wxEmptyString ; } -int wxMacTextControl::GetLineLength(long lineNo) const +int wxTextWidgetImpl::GetLineLength(long lineNo) const { // TODO: change this if possible to reflect real lines wxString content = GetStringValue() ; @@ -918,22 +900,4 @@ int wxMacTextControl::GetLineLength(long lineNo) const return 0 ; } -void wxMacTextControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) -{ -#if wxOSX_USE_CARBON - wxMacControl::SetFont(font, foreground, windowStyle ); - - // overrule the barrier in wxMacControl for supporting disabled controls, in order to support - // setting the color to eg red and back to black by controllers - - if ( foreground == *wxBLACK ) - { - ControlFontStyleRec fontStyle; - fontStyle.foreColor.red = fontStyle.foreColor.green = fontStyle.foreColor.blue = 0; - fontStyle.flags = kControlUseForeColorMask; - ::SetControlFontStyle( m_controlRef , &fontStyle ); - } -#endif -} - #endif // wxUSE_TEXTCTRL diff --git a/src/osx/utils_osx.cpp b/src/osx/utils_osx.cpp index 5882a67144..8bd06e843e 100644 --- a/src/osx/utils_osx.cpp +++ b/src/osx/utils_osx.cpp @@ -156,4 +156,24 @@ CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush ) return color; } +//--------------------------------------------------------------------------- +// Mac Specific string utility functions +//--------------------------------------------------------------------------- + +void wxMacStringToPascal( const wxString&from , unsigned char * to ) +{ + wxCharBuffer buf = from.mb_str( wxConvLocal ); + int len = strlen(buf); + + if ( len > 255 ) + len = 255; + to[0] = len; + memcpy( (char*) &to[1] , buf , len ); +} + +wxString wxMacMakeStringFromPascal( const unsigned char * from ) +{ + return wxString( (char*) &from[1] , wxConvLocal , from[0] ); +} + #endif // wxOSX_USE_COCOA_OR_CARBON diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 24c45ddb07..cadecef90b 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -384,9 +384,9 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) void wxWindowMac::MacUpdateControlFont() { -#if wxOSX_USE_CARBON + m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; -#endif + // do not trigger refreshes upon invisible and possible partly created objects if ( IsShownOnScreen() ) Refresh() ; -- 2.45.2