]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/combobox.cpp
IsInAssert is only available (and only makes sense) in a debug build so
[wxWidgets.git] / src / univ / combobox.cpp
index 256853fbccec22a75c327a2ae08e1495e3ca8769..53d2c180fc7685fff7ec97ad2d472069e96834a1 100644 (file)
@@ -17,7 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "univcombobox.h"
 #endif
 
@@ -41,6 +41,7 @@
     #include "wx/validate.h"
 #endif
 
+#include "wx/tooltip.h"
 #include "wx/popupwin.h"
 
 #include "wx/univ/renderer.h"
@@ -92,7 +93,7 @@ public:
     }
 
 protected:
-    void OnButton(wxCommandEvent& event) { m_combo->ShowPopup(); }
+    void OnButton(wxCommandEvent& WXUNUSED(event)) { m_combo->ShowPopup(); }
 
     virtual wxSize DoGetBestClientSize() const
     {
@@ -122,8 +123,11 @@ public:
 
     // implement wxComboPopup methods
     virtual bool SetSelection(const wxString& value);
+    virtual void SetSelection(int n, bool select)
+        { wxListBox::SetSelection( n, select); };
     virtual wxControl *GetControl() { return this; }
     virtual void OnShow();
+    virtual wxCoord GetBestWidth() const;
 
 protected:
     // we shouldn't return height too big from here
@@ -209,6 +213,25 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
 // wxComboControl creation
 // ----------------------------------------------------------------------------
 
+wxComboControl::wxComboControl()
+{
+    Init();
+}
+
+wxComboControl::wxComboControl(wxWindow *parent,
+                               wxWindowID id,
+                               const wxString& value,
+                               const wxPoint& pos,
+                               const wxSize& size,
+                               long style,
+                               const wxValidator& validator,
+                               const wxString& name)
+{
+    Init();
+
+    (void)Create(parent, id, value, pos, size, style, validator, name);
+}
+
 void wxComboControl::Init()
 {
     m_popup = (wxComboPopup *)NULL;
@@ -288,7 +311,7 @@ wxComboControl::~wxComboControl()
 // ----------------------------------------------------------------------------
 
 void wxComboControl::DoSetSize(int x, int y,
-                               int width, int height,
+                               int width, int WXUNUSED(height),
                                int sizeFlags)
 {
     // combo height is always fixed
@@ -299,8 +322,15 @@ wxSize wxComboControl::DoGetBestClientSize() const
 {
     wxSize sizeBtn = m_btn->GetBestSize(),
            sizeText = m_text->GetBestSize();
+    wxCoord widthPopup = 0;
+
+    if (m_popup)
+    {
+        widthPopup = m_popup->GetBestWidth();
+    }
 
-    return wxSize(sizeText.x + g_comboMargin + sizeBtn.x, wxMax(sizeBtn.y, sizeText.y));
+    return wxSize(wxMax(sizeText.x + g_comboMargin + sizeBtn.x, widthPopup), 
+                  wxMax(sizeBtn.y, sizeText.y));
 }
 
 void wxComboControl::DoMoveWindow(int x, int y, int width, int height)
@@ -351,6 +381,29 @@ bool wxComboControl::Show(bool show)
     return TRUE;
 }
 
+#if wxUSE_TOOLTIPS
+void wxComboControl::DoSetToolTip(wxToolTip *tooltip)
+{
+    wxControl::DoSetToolTip(tooltip);    
+
+    // Set tool tip for button and text box
+    if (m_text && m_btn)
+    {
+        if (tooltip)
+        {
+            const wxString &tip = tooltip->GetTip();
+            m_text->SetToolTip(tip);
+            m_btn->SetToolTip(tip);
+        }
+        else
+        {
+            m_text->SetToolTip(NULL);
+            m_btn->SetToolTip(NULL);
+        }
+    }
+}
+#endif // wxUSE_TOOLTIPS
+
 // ----------------------------------------------------------------------------
 // popup window handling
 // ----------------------------------------------------------------------------
@@ -591,6 +644,12 @@ void wxComboListBox::OnMouseMove(wxMouseEvent& event)
     }
 }
 
+wxCoord wxComboListBox::GetBestWidth() const
+{
+    wxSize size = wxListBox::GetBestSize();
+    return size.x;
+}
+
 wxSize wxComboListBox::DoGetBestClientSize() const
 {
     // don't return size too big or we risk to not fit on the screen
@@ -612,6 +671,28 @@ wxSize wxComboListBox::DoGetBestClientSize() const
 // wxComboBox
 // ----------------------------------------------------------------------------
 
+wxComboBox::wxComboBox()
+{
+    Init();
+}
+
+wxComboBox::wxComboBox(wxWindow *parent,
+                       wxWindowID id,
+                       const wxString& value,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       int n,
+                       const wxString *choices,
+                       long style,
+                       const wxValidator& validator,
+                       const wxString& name)
+{
+    Init();
+
+    (void)Create(parent, id, value, pos, size, n, choices,
+                 style, validator, name);
+}
+
 void wxComboBox::Init()
 {
     m_lbox = (wxListBox *)NULL;
@@ -787,6 +868,18 @@ int wxComboBox::DoAppend(const wxString& item)
     return GetLBox()->Append(item);
 }
 
+int wxComboBox::DoInsert(const wxString& item, int pos)
+{
+    wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
+    wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
+
+    if (pos == GetCount())
+        return DoAppend(item);
+
+    GetLBox()->Insert(item, pos);
+    return pos;
+}
+
 void wxComboBox::DoSetItemClientData(int n, void* clientData)
 {
     GetLBox()->SetClientData(n, clientData);