// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
-// Licence: wxWidgets licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
wxFLAGS_MEMBER(wxBORDER_RAISED)
wxFLAGS_MEMBER(wxBORDER_STATIC)
wxFLAGS_MEMBER(wxBORDER_NONE)
-
+
// old style border flags
wxFLAGS_MEMBER(wxSIMPLE_BORDER)
wxFLAGS_MEMBER(wxSUNKEN_BORDER)
IMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxControl,"wx/combobox.h")
wxBEGIN_PROPERTIES_TABLE(wxComboBox)
- wxEVENT_PROPERTY( Select , wxEVT_COMMAND_COMBOBOX_SELECTED , wxCommandEvent )
+ wxEVENT_PROPERTY( Select , wxEVT_COMMAND_COMBOBOX_SELECTED , wxCommandEvent )
wxEVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent )
// TODO DELEGATES
- wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
+ wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxPROPERTY_COLLECTION( Choices , wxArrayString , wxString , AppendString , GetStrings , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
- wxPROPERTY( Value ,wxString, SetValue, GetValue, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
- wxPROPERTY( Selection ,int, SetSelection, GetSelection, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
+ wxPROPERTY( Value ,wxString, SetValue, GetValue, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
+ wxPROPERTY( Selection ,int, SetSelection, GetSelection, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxPROPERTY_FLAGS( WindowStyle , wxComboBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
wxEND_PROPERTIES_TABLE()
UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd);
return (WXLRESULT)OnCtlColor(hdc, hwnd, nCtlColor, nMsg, wParam, lParam);
+
+ case CB_SETCURSEL:
+ // Selection was set with SetSelection. Update the value too.
+ if ((int)wParam > GetCount())
+ m_value = wxEmptyString;
+ else
+ m_value = GetString(wParam);
+ break;
+
}
return wxChoice::MSWWindowProc(nMsg, wParam, lParam);
ProcessCommand(event);
}
- return HandleChar(wParam, lParam, TRUE /* isASCII */);
+ return HandleChar(wParam, lParam, true /* isASCII */);
case WM_KEYDOWN:
return HandleKeyDown(wParam, lParam);
return HandleKillFocus((WXHWND)wParam);
}
- return FALSE;
+ return false;
}
bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
case CBN_SELCHANGE:
sel = GetSelection();
- if ( sel > -1 )
+
+ // somehow we get 2 CBN_SELCHANGE events with the same index when
+ // the user selects an item in the combobox -- ignore duplicates
+ if ( sel > -1 && sel != m_selectionOld )
{
- value = GetString(sel);
+ m_selectionOld = sel;
+
+ // GetValue() would still return the old value from here but
+ // according to the docs we should return the new value if the
+ // user calls it in his event handler, so update internal
+ // m_value
+ m_value = GetString(sel);
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
event.SetInt(sel);
event.SetEventObject(this);
- event.SetString(value);
+ event.SetString(m_value);
ProcessCommand(event);
}
- else
+ else // no valid selection
{
+ m_selectionOld = sel;
+
+ // hence no EVT_TEXT neither
break;
}
// want the new one)
if ( sel == -1 )
{
- value = GetValue();
+ m_value = wxGetWindowText(GetHwnd());
}
else // we're synthesizing text updated event from sel change
{
- // We need to retrieve the current selection because the user
- // may have changed it in the previous handler (for CBN_SELCHANGE
- // above).
+ // We need to retrieve the current selection because the
+ // user may have changed it in the previous handler (for
+ // CBN_SELCHANGE above).
sel = GetSelection();
if ( sel > -1 )
{
- value = GetString(sel);
+ m_value = GetString(sel);
}
- // we need to do this because the user code expects
- // wxComboBox::GetValue() to return the new value from
- // "text updated" handler but it hadn't been updated yet
- SetValue(value);
}
- event.SetString(value);
+ event.SetString(m_value);
event.SetEventObject(this);
ProcessCommand(event);
}
}
// there is no return value for the CBN_ notifications, so always return
- // FALSE from here to pass the message to DefWindowProc()
- return FALSE;
+ // false from here to pass the message to DefWindowProc()
+ return false;
}
WXHWND wxComboBox::GetEditHWND() const
// pretend that wxComboBox is hidden while it is positioned and resized and
// show it only right before leaving this method because otherwise there is
// some noticeable flicker while the control rearranges itself
- m_isShown = FALSE;
+ m_isShown = false;
if ( !CreateAndInit(parent, id, pos, size, n, choices, style,
validator, name) )
- return FALSE;
+ return false;
// we shouldn't call SetValue() for an empty string because this would
// (correctly) result in an assert with a read only combobox and is useless
}
// and finally, show the control
- Show(TRUE);
+ Show(true);
- return TRUE;
+ return true;
}
bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
SetStringSelection(value);
else
SetWindowText(GetHwnd(), value.c_str());
+
+ m_value = value;
+ m_selectionOld = GetSelection();
}
// Clipboard operations