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
This commit is contained in:
Stefan Csomor
2008-09-05 14:41:11 +00:00
parent 23e00c551b
commit 1e181c7a2c
21 changed files with 734 additions and 972 deletions

View File

@@ -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<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