]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/combobox.cpp
Initial revision
[wxWidgets.git] / src / msw / combobox.cpp
index 7104620710ec301f820186d4a536fb4e63c2a093..8d6d7eada7d8f4af649890a8f42daa139c8503fb 100644 (file)
 #pragma hdrstop
 #endif
 
 #pragma hdrstop
 #endif
 
+#if wxUSE_COMBOBOX
+
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
-#include "wx/setup.h"
+#include "wx/settings.h"
 #endif
 
 #endif
 
-#if wxUSE_COMBOBOX
-
 #include "wx/combobox.h"
 #include "wx/clipbrd.h"
 #include "wx/msw/private.h"
 
 #include "wx/combobox.h"
 #include "wx/clipbrd.h"
 #include "wx/msw/private.h"
 
-#if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
 IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
-#endif
 
 bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
 {
 
 bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
 {
-  if (param == CBN_SELCHANGE)
-  {
-    wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId);
-    event.SetInt(GetSelection());
-    event.SetEventObject(this);
-    event.SetString(GetStringSelection());
-    ProcessCommand(event);
-
-    return TRUE;
-  }
-  else if (param == CBN_EDITCHANGE)
-  {
-    wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
-    event.SetString(GetValue());
-    event.SetEventObject(this);
-    ProcessCommand(event);
+    switch ( param )
+    {
+        case CBN_SELCHANGE:
+            if (GetSelection() > -1)
+            {
+                wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
+                event.SetInt(GetSelection());
+                event.SetEventObject(this);
+                event.SetString(GetStringSelection());
+                ProcessCommand(event);
+            }
+            break;
+
+        case CBN_EDITCHANGE:
+            {
+                wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
+                event.SetString(GetValue());
+                event.SetEventObject(this);
+                ProcessCommand(event);
+            }
+            break;
+    }
 
 
-    return TRUE;
-  }
-  else
-      return FALSE;
+    // there is no return value for the CBN_ notifications, so always return
+    // FALSE from here to pass the message to DefWindowProc()
+    return FALSE;
 }
 
 bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
 }
 
 bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
@@ -69,11 +72,17 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
                         const wxString& name)
 {
   SetName(name);
                         const wxString& name)
 {
   SetName(name);
+#if wxUSE_VALIDATORS
   SetValidator(validator);
   SetValidator(validator);
+#endif // wxUSE_VALIDATORS
   if (parent) parent->AddChild(this);
   if (parent) parent->AddChild(this);
-  SetBackgroundColour(parent->GetBackgroundColour()) ;
+//  SetBackgroundColour(parent->GetBackgroundColour()) ;
+
+  // A choice/combobox normally has a white background (or other, depending
+  // on global settings) rather than inheriting the parent's background colour.
+  SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
+
   SetForegroundColour(parent->GetForegroundColour()) ;
   SetForegroundColour(parent->GetForegroundColour()) ;
-  m_noStrings = 0;
 
   m_windowStyle = style;
 
 
   m_windowStyle = style;
 
@@ -87,8 +96,8 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
   int width = size.x;
   int height = size.y;
 
   int width = size.x;
   int height = size.y;
 
-  long msStyle = WS_CHILD | WS_HSCROLL | WS_VSCROLL |
-                 WS_TABSTOP | WS_VISIBLE | CBS_NOINTEGRALHEIGHT;
+  long msStyle = WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
+      CBS_NOINTEGRALHEIGHT;
 
   if (m_windowStyle & wxCB_READONLY)
     msStyle |= CBS_DROPDOWNLIST;
 
   if (m_windowStyle & wxCB_READONLY)
     msStyle |= CBS_DROPDOWNLIST;
@@ -108,12 +117,12 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
   if ( want3D || wxStyleHasBorder(m_windowStyle) )
     msStyle |= WS_BORDER;
 
   if ( want3D || wxStyleHasBorder(m_windowStyle) )
     msStyle |= WS_BORDER;
 
-  m_hWnd = (WXHWND)::CreateWindowEx(exStyle, _T("COMBOBOX"), NULL,
+  m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("COMBOBOX"), NULL,
                    msStyle,
                    0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
                    wxGetInstance(), NULL);
 
                    msStyle,
                    0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
                    wxGetInstance(), NULL);
 
-  wxCHECK_MSG( m_hWnd, FALSE, _T("Failed to create combobox") );
+  wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create combobox") );
 
 /*
 #if wxUSE_CTL3D
 
 /*
 #if wxUSE_CTL3D
@@ -318,20 +327,31 @@ void wxComboBox::SetSelection(long from, long to)
 #endif
 }
 
 #endif
 }
 
-void wxComboBox::DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags)
+void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
 {
 {
-    wxControl::DoSetSize(x, y, width, height, sizeFlags);
+    int cx, cy;
+    wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
 
 
-    // VZ: for unknown (to me) reasons, if we don't do this, the combobox
-    //     somehow is hidden by the static boxes, although static boxes do
-    //     put themselves at the very end of Z-order.
-    if ( !::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
-                         SWP_NOMOVE | SWP_NOSIZE) )
-    {
-        wxLogLastError(_T("SetWindowPos"));
-    }
+    int n = GetCount();
+    if ( !n )
+        n = 10;
+
+    height = n * EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
+
+    wxControl::DoMoveWindow(x, y, width, height);
+}
+
+wxSize wxComboBox::DoGetBestSize() const
+{
+    // the choice calculates the horz size correctly, but not the vertical
+    // component: correct it
+    wxSize size = wxChoice::DoGetBestSize();
+
+    int cx, cy;
+    wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
+    size.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
+
+    return size;
 }
 
 #endif
 }
 
 #endif