X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ec184e324214ea06f0c056ab626de5f32bcdad3b..7749035c4edc84ff7ad722c0de8ff1679b68976f:/src/generic/srchctlg.cpp diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index d624d7d22e..8edf081475 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -2,21 +2,12 @@ // Name: src/generic/srchctlg.cpp // Purpose: implements wxSearchCtrl as a composite control // Author: Vince Harron -// Modified by: // Created: 2006-02-19 -// RCS-ID: +// RCS-ID: $Id$ // Copyright: Vince Harron // License: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -24,6 +15,10 @@ #pragma hdrstop #endif +#if wxUSE_SEARCHCTRL + +#include "wx/srchctrl.h" + #ifndef WX_PRECOMP #include "wx/button.h" #include "wx/dcclient.h" @@ -31,16 +26,11 @@ #include "wx/dcmemory.h" #endif //WX_PRECOMP -#if wxUSE_SEARCHCTRL - -#include "wx/srchctrl.h" - -#if !USE_NATIVE_SEARCH_CONTROL +#if !wxUSE_NATIVE_SEARCH_CONTROL #include "wx/image.h" -#define WXMIN(a,b) (a)<(b)?(a):(b) -#define WXMAX(a,b) (a)>(b)?(a):(b) +#define WXMAX(a,b) ((a)>(b)?(a):(b)) // ---------------------------------------------------------------------------- // constants @@ -72,7 +62,7 @@ public: style | wxNO_BORDER) { m_search = search; - + // remove the default minsize, the searchctrl will have one instead SetSizeHints(wxDefaultCoord,wxDefaultCoord); } @@ -92,7 +82,7 @@ protected: // copy constructor is disabled for some reason? //wxTextUrlEvent event(eventText); wxTextUrlEvent event( - m_search->GetId(), + m_search->GetId(), eventText.GetMouseEvent(), eventText.GetURLStart(), eventText.GetURLEnd() @@ -131,13 +121,13 @@ public: void SetBitmapLabel(const wxBitmap& label) { m_bmp = label; } - + protected: wxSize DoGetBestSize() const { return wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()); } - + void OnLeftUp(wxMouseEvent&) { wxCommandEvent event(m_eventType, m_search->GetId()); @@ -147,7 +137,7 @@ protected: m_search->SetFocus(); - if ( m_eventType == wxEVT_COMMAND_SEARCHCTRL_SEARCH ) + if ( m_eventType == wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN ) { // this happens automatically, just like on Mac OS X m_search->PopupSearchMenu(); @@ -160,7 +150,7 @@ protected: dc.DrawBitmap(m_bmp, 0,0, true); } - + private: wxSearchCtrl *m_search; wxEventType m_eventType; @@ -175,8 +165,9 @@ BEGIN_EVENT_TABLE(wxSearchButton, wxControl) END_EVENT_TABLE() BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) - EVT_SEARCHCTRL_SEARCH(wxID_ANY, wxSearchCtrl::OnSearchButton) + EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, wxSearchCtrl::OnSearchButton) EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus) + EVT_SIZE(wxSearchCtrl::OnSize) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) @@ -193,7 +184,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) // -------- wxSearchCtrl::wxSearchCtrl() -{ +{ Init(); } @@ -233,7 +224,11 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { +#ifdef __WXGTK__ + if ( !wxTextCtrlBase::Create(parent, id, pos, size, wxSUNKEN_BORDER | style, validator, name) ) +#else if ( !wxTextCtrlBase::Create(parent, id, pos, size, wxSIMPLE_BORDER | style, validator, name) ) +#endif { return false; } @@ -242,8 +237,8 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, wxSize sizeText = m_text->GetBestSize(); - m_searchButton = new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH,m_searchBitmap); - m_cancelButton = new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL,m_cancelBitmap); + m_searchButton = new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN,m_searchBitmap); + m_cancelButton = new wxSearchButton(this,wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN,m_cancelBitmap); SetForegroundColour( m_text->GetForegroundColour() ); m_searchButton->SetForegroundColour( m_text->GetForegroundColour() ); @@ -277,8 +272,8 @@ void wxSearchCtrl::SetMenu( wxMenu* menu ) // no change return; } + bool hadMenu = (m_menu != NULL); delete m_menu; - bool hadMenu = (m_menu!=0); m_menu = menu; if ( m_menu && !hadMenu ) @@ -393,6 +388,9 @@ void wxSearchCtrl::DoMoveWindow(int x, int y, int width, int height) void wxSearchCtrl::LayoutControls(int x, int y, int width, int height) { + if ( !m_text ) + return; + wxSize sizeText = m_text->GetBestSize(); // make room for the search menu & clear button int horizontalBorder = 1 + ( sizeText.y - sizeText.y * 14 / 21 ) / 2; @@ -430,7 +428,10 @@ void wxSearchCtrl::LayoutControls(int x, int y, int width, int height) // position the subcontrols inside the client area m_searchButton->SetSize(x, y + ICON_OFFSET, sizeSearch.x, height); - m_text->SetSize(x + sizeSearch.x + searchMargin, y + ICON_OFFSET, textWidth, height); + m_text->SetSize( x + sizeSearch.x + searchMargin, + y + ICON_OFFSET - BORDER, + textWidth, + height); m_cancelButton->SetSize(x + sizeSearch.x + searchMargin + textWidth + cancelMargin, y + ICON_OFFSET, sizeCancel.x, height); } @@ -693,7 +694,7 @@ bool wxSearchCtrl::SetFont(const wxFont& font) bool result = wxSearchCtrlBase::SetFont(font); if ( result && m_text ) { - result &= m_text->SetFont(font); + result = m_text->SetFont(font); } RecalcBitmaps(); return result; @@ -1004,9 +1005,9 @@ void wxSearchCtrl::RecalcBitmaps() if ( !m_searchBitmapUser ) { - if ( + if ( !m_searchBitmap.Ok() || - m_searchBitmap.GetHeight() != bitmapHeight || + m_searchBitmap.GetHeight() != bitmapHeight || m_searchBitmap.GetWidth() != bitmapWidth ) { @@ -1021,9 +1022,9 @@ void wxSearchCtrl::RecalcBitmaps() if ( !m_searchMenuBitmapUser ) { - if ( + if ( !m_searchMenuBitmap.Ok() || - m_searchMenuBitmap.GetHeight() != bitmapHeight || + m_searchMenuBitmap.GetHeight() != bitmapHeight || m_searchMenuBitmap.GetWidth() != bitmapWidth ) { @@ -1038,9 +1039,9 @@ void wxSearchCtrl::RecalcBitmaps() if ( !m_cancelBitmapUser ) { - if ( + if ( !m_cancelBitmap.Ok() || - m_cancelBitmap.GetHeight() != bitmapHeight || + m_cancelBitmap.GetHeight() != bitmapHeight || m_cancelBitmap.GetWidth() != bitmapHeight ) { @@ -1064,6 +1065,13 @@ void wxSearchCtrl::OnSetFocus( wxFocusEvent& /*event*/ ) } } +void wxSearchCtrl::OnSize( wxSizeEvent& WXUNUSED(event) ) +{ + int width, height; + GetSize(&width, &height); + LayoutControls(0, 0, width, height); +} + void wxSearchCtrl::PopupSearchMenu() { if ( m_menu ) @@ -1073,6 +1081,6 @@ void wxSearchCtrl::PopupSearchMenu() } } -#endif // !USE_NATIVE_SEARCH_CONTROL +#endif // !wxUSE_NATIVE_SEARCH_CONTROL #endif // wxUSE_SEARCHCTRL