// 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"
#pragma hdrstop
#endif
+#if wxUSE_SEARCHCTRL
+
+#include "wx/srchctrl.h"
+
#ifndef WX_PRECOMP
#include "wx/button.h"
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#endif //WX_PRECOMP
-#if wxUSE_SEARCHCTRL
-
-#include "wx/srchctrl.h"
-
#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
style | wxNO_BORDER)
{
m_search = search;
-
+
// remove the default minsize, the searchctrl will have one instead
SetSizeHints(wxDefaultCoord,wxDefaultCoord);
}
// copy constructor is disabled for some reason?
//wxTextUrlEvent event(eventText);
wxTextUrlEvent event(
- m_search->GetId(),
+ m_search->GetId(),
eventText.GetMouseEvent(),
eventText.GetURLStart(),
eventText.GetURLEnd()
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());
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();
dc.DrawBitmap(m_bmp, 0,0, true);
}
-
+
private:
wxSearchCtrl *m_search;
wxEventType m_eventType;
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)
// --------
wxSearchCtrl::wxSearchCtrl()
-{
+{
Init();
}
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;
}
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() );
// no change
return;
}
+ bool hadMenu = (m_menu != NULL);
delete m_menu;
- bool hadMenu = (m_menu!=0);
m_menu = menu;
if ( m_menu && !hadMenu )
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;
// 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);
}
bool result = wxSearchCtrlBase::SetFont(font);
if ( result && m_text )
{
- result &= m_text->SetFont(font);
+ result = m_text->SetFont(font);
}
RecalcBitmaps();
return result;
if ( !m_searchBitmapUser )
{
- if (
+ if (
!m_searchBitmap.Ok() ||
- m_searchBitmap.GetHeight() != bitmapHeight ||
+ m_searchBitmap.GetHeight() != bitmapHeight ||
m_searchBitmap.GetWidth() != bitmapWidth
)
{
if ( !m_searchMenuBitmapUser )
{
- if (
+ if (
!m_searchMenuBitmap.Ok() ||
- m_searchMenuBitmap.GetHeight() != bitmapHeight ||
+ m_searchMenuBitmap.GetHeight() != bitmapHeight ||
m_searchMenuBitmap.GetWidth() != bitmapWidth
)
{
if ( !m_cancelBitmapUser )
{
- if (
+ if (
!m_cancelBitmap.Ok() ||
- m_cancelBitmap.GetHeight() != bitmapHeight ||
+ m_cancelBitmap.GetHeight() != bitmapHeight ||
m_cancelBitmap.GetWidth() != bitmapHeight
)
{
}
}
+void wxSearchCtrl::OnSize( wxSizeEvent& WXUNUSED(event) )
+{
+ int width, height;
+ GetSize(&width, &height);
+ LayoutControls(0, 0, width, height);
+}
+
void wxSearchCtrl::PopupSearchMenu()
{
if ( m_menu )