// forward decl for GetSelections()
class wxArrayInt;
-// forward decl for wxListWidgetImpl data type.
+// forward decl for wxListWidgetImpl implementation type.
class wxListWidgetImpl;
// List box item
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 );
void wxMacCleanupConverters();
// utils.cpp
-void WXDLLIMPEXP_CORE wxMacStringToPascal( const wxString&from , StringPtr to );
-wxString WXDLLIMPEXP_CORE wxMacMakeStringFromPascal( ConstStringPtr from );
// filefn.cpp
#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 ) ;
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) ;
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_
#if wxUSE_SEARCHCTRL
-class wxMacSearchFieldControl;
+class wxSearchWidgetImpl;
class WXDLLIMPEXP_CORE wxSearchCtrl : public wxSearchCtrlBase
{
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:
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)
#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
{
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;
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)
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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_
#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
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;
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,
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
//
#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;
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<CFStringRef>( 0, kControlEditTextCFStringTag , cf ) ) ;
+
+ ::InstallControlEventHandler( m_controlRef, GetwxMacSearchControlEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, wxPeer, NULL);
+ wxMacUnicodeTextControl::InstallEventHandlers();
}
// search field options
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
{
}
}
-wxMenu* wxMacSearchFieldControl::GetSearchMenu() const
-{
- return m_menu;
-}
-
-
void wxMacSearchFieldControl::SetDescriptiveText(const wxString& text)
{
verify_noerr( HISearchFieldSetDescriptiveText(
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
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
// 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 ) ;
if ( UMAGetSystemVersion() >= 0x1050 )
forceMLTE = false;
- wxMacTextControl* peer = NULL;
+ wxMacControl* peer = NULL;
if ( !forceMLTE )
{
DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler )
-wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacTextControl( wxPeer )
+wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacControl( 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 ;
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<Boolean>( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ;
+ InstallEventHandlers();
+}
+
+void wxMacUnicodeTextControl::InstallEventHandlers()
+{
::InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(),
GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this,
NULL);
-
- return true;
}
wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
verify_noerr( SetData<CFStringRef>( 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 ) ;
} ;
wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer )
- : wxMacTextControl( peer )
+ : wxMacControl( peer )
{
SetNeedsFocusRect( true ) ;
}
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
// ----------------------------------------------------------------------------
{
}
-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
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 );
// 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;
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 )
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
}
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() );
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;
}
}
#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<wxSearchCtrl*>( 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
#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
@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,
[m_osxView setControlSize:size];
}
+void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
+{
+ // TODO
+}
+
//
// Factory methods
//
#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<wxSearchWidgetImpl*> (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
#include "wx/thread.h"
#include "wx/osx/private.h"
-#include "wx/osx/carbon/private/mactext.h"
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase)
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) ;
return true;
}
-void wxTextCtrl::CreatePeer(
- const wxString& str,
- const wxPoint& pos,
- const wxSize& size, long style )
+wxTextWidgetImpl* wxTextCtrl::GetTextPeer() const
{
+ return dynamic_cast<wxTextWidgetImpl*> (m_peer);
}
void wxTextCtrl::MacSuperChangedPosition()
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)
if ( GetValue() == str )
return;
- GetPeer()->SetStringValue( str ) ;
+ GetTextPeer()->SetStringValue( str ) ;
if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue )
{
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 ;
}
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 );
{
if (CanPaste())
{
- GetPeer()->Paste() ;
+ GetTextPeer()->Paste() ;
// TODO: eventually we should add setting the default style again
if (!IsEditable())
return false;
- return GetPeer()->CanPaste() ;
+ return GetTextPeer()->CanPaste() ;
}
void wxTextCtrl::SetEditable(bool editable)
if ( editable != m_editable )
{
m_editable = editable ;
- GetPeer()->SetEditable( editable ) ;
+ GetTextPeer()->SetEditable( editable ) ;
}
}
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)
void wxTextCtrl::Clear()
{
- GetPeer()->Clear() ;
+ GetTextPeer()->Clear() ;
}
bool wxTextCtrl::IsModified() const
void wxTextCtrl::Undo()
{
if (CanUndo())
- GetPeer()->Undo() ;
+ GetTextPeer()->Undo() ;
}
void wxTextCtrl::Redo()
{
if (CanRedo())
- GetPeer()->Redo() ;
+ GetTextPeer()->Redo() ;
}
bool wxTextCtrl::CanUndo() const
if ( !IsEditable() )
return false ;
- return GetPeer()->CanUndo() ;
+ return GetTextPeer()->CanUndo() ;
}
bool wxTextCtrl::CanRedo() const
if ( !IsEditable() )
return false ;
- return GetPeer()->CanRedo() ;
+ return GetTextPeer()->CanRedo() ;
}
void wxTextCtrl::MarkDirty()
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)
void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event)
{
- if ( GetPeer()->HasOwnContextMenu() )
+ if ( GetTextPeer()->HasOwnContextMenu() )
{
event.Skip() ;
return ;
bool wxTextCtrl::MacSetupCursor( const wxPoint& pt )
{
- if ( !GetPeer()->SetupCursor( pt ) )
+ if ( !GetTextPeer()->SetupCursor( pt ) )
return wxWindow::MacSetupCursor( pt ) ;
else
return true ;
// 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() ;
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() ;
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() ;
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
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
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() ;