]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/srchctlg.cpp
fix attribute memory leak in wxGrid::ShowCellEditControl() (patch 1629949)
[wxWidgets.git] / src / generic / srchctlg.cpp
index b4f18fd78224f5a30da4287aee065cb8ec7bdaa0..8edf081475bc4d447085167c66849921d386deab 100644 (file)
@@ -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"
 
     #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
@@ -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 )