void wxVListBoxComboPopup::DismissWithEvent() { StopPartialCompletion(); int selection = wxVListBox::GetSelection(); if ( selection != wxNOT_FOUND ) m_stringValue = m_strings[selection]; else m_stringValue.clear(); m_value = selection; Dismiss(); SendComboBoxEvent(selection); }
void wxVListBoxComboPopup::DismissWithEvent() { StopPartialCompletion(); int selection = wxVListBox::GetSelection(); Dismiss(); if ( selection != wxNOT_FOUND ) m_stringValue = m_strings[selection]; else m_stringValue = wxEmptyString; if ( m_stringValue != m_combo->GetValue() ) m_combo->SetValueByUser(m_stringValue); m_value = selection; SendComboBoxEvent(selection); }
void wxVListBoxComboPopup::DismissWithEvent() { StopPartialCompletion(); int selection = wxVListBox::GetSelection(); Dismiss(); wxString valStr; if ( selection != wxNOT_FOUND ) valStr = m_strings[selection]; else valStr = wxEmptyString; m_value = selection; if ( valStr != m_combo->GetValue() ) m_combo->SetValueWithEvent(valStr); SendComboBoxEvent(selection); }
// returns true if key was consumed bool wxVListBoxComboPopup::HandleKey( int keycode, bool saturate, wxChar keychar ) { const int itemCount = GetCount(); // keys do nothing in the empty control and returning immediately avoids // using invalid indices below if ( !itemCount ) return false; int value = m_value; int comboStyle = m_combo->GetWindowStyle(); if ( keychar > 0 ) { // we have character equivalent of the keycode; filter out these that // are not printable characters if ( !wxIsprint(keychar) ) keychar = 0; } if ( keycode == WXK_DOWN || keycode == WXK_NUMPAD_DOWN || keycode == WXK_RIGHT ) { value++; StopPartialCompletion(); } else if ( keycode == WXK_UP || keycode == WXK_NUMPAD_UP || keycode == WXK_LEFT ) { value--; StopPartialCompletion(); } else if ( keycode == WXK_PAGEDOWN || keycode == WXK_NUMPAD_PAGEDOWN ) { value+=10; StopPartialCompletion(); } else if ( keycode == WXK_PAGEUP || keycode == WXK_NUMPAD_PAGEUP ) { value-=10; StopPartialCompletion(); } else if ( keycode == WXK_HOME || keycode == WXK_NUMPAD_HOME ) { value=0; StopPartialCompletion(); } else if ( keycode == WXK_END || keycode == WXK_NUMPAD_END ) { value=itemCount-1; StopPartialCompletion(); } else if ( keychar && (comboStyle & wxCB_READONLY) ) { // Try partial completion // find the new partial completion string #if wxUSE_TIMER if (m_partialCompletionTimer.IsRunning()) m_partialCompletionString+=wxString(keychar); else #endif // wxUSE_TIMER m_partialCompletionString=wxString(keychar); // now search through the values to see if this is found int found = -1; unsigned int length=m_partialCompletionString.length(); int i; for (i=0; i<itemCount; i++) { wxString item=GetString(i); if (( item.length() >= length) && (! m_partialCompletionString.CmpNoCase(item.Left(length)))) { found=i; break; } } if (found<0) { StopPartialCompletion(); ::wxBell(); return true; // to stop the first value being set } else { value=i; #if wxUSE_TIMER m_partialCompletionTimer.Start(wxODCB_PARTIAL_COMPLETION_TIME, true); #endif // wxUSE_TIMER } } else return false; if ( saturate ) { if ( value >= itemCount ) value = itemCount - 1; else if ( value < 0 ) value = 0; } else { if ( value >= itemCount ) value -= itemCount; else if ( value < 0 ) value += itemCount; } if ( value == m_value ) // Even if value was same, don't skip the event // (good for consistency) return true; if ( value >= 0 ) m_combo->ChangeValue(m_strings[value]); // The m_combo->SetValue() call above sets m_value to the index of this // string. But if there are more identical string, the index is of the // first occurence, which may be wrong, so set the index explicitly here, // _after_ the SetValue() call. m_value = value; SendComboBoxEvent(m_value); return true; }
// returns true if key was consumed bool wxVListBoxComboPopup::HandleKey( int keycode, bool saturate, wxChar unicode ) { const int itemCount = GetCount(); // keys do nothing in the empty control and returning immediately avoids // using invalid indices below if ( !itemCount ) return false; int value = m_value; int comboStyle = m_combo->GetWindowStyle(); // this is the character equivalent of the code wxChar keychar = 0; if ( keycode < WXK_START ) { #if wxUSE_UNICODE if ( unicode > 0 ) { if ( wxIsprint(unicode) ) keychar = unicode; } else #else wxUnusedVar(unicode); #endif if ( wxIsprint(keycode) ) { keychar = (wxChar) keycode; } } if ( keycode == WXK_DOWN || keycode == WXK_RIGHT ) { value++; StopPartialCompletion(); } else if ( keycode == WXK_UP || keycode == WXK_LEFT ) { value--; StopPartialCompletion(); } else if ( keycode == WXK_PAGEDOWN ) { value+=10; StopPartialCompletion(); } else if ( keycode == WXK_PAGEUP ) { value-=10; StopPartialCompletion(); } else if ( keychar && (comboStyle & wxCB_READONLY) ) { // Try partial completion // find the new partial completion string #if wxUSE_TIMER if (m_partialCompletionTimer.IsRunning()) m_partialCompletionString+=wxString(keychar); else #endif // wxUSE_TIMER m_partialCompletionString=wxString(keychar); // now search through the values to see if this is found int found = -1; unsigned int length=m_partialCompletionString.length(); int i; for (i=0; i<itemCount; i++) { wxString item=GetString(i); if (( item.length() >= length) && (! m_partialCompletionString.CmpNoCase(item.Left(length)))) { found=i; break; } } if (found<0) { StopPartialCompletion(); ::wxBell(); return true; // to stop the first value being set } else { value=i; #if wxUSE_TIMER m_partialCompletionTimer.Start(wxODCB_PARTIAL_COMPLETION_TIME, true); #endif // wxUSE_TIMER } } else return false; if ( saturate ) { if ( value >= itemCount ) value = itemCount - 1; else if ( value < 0 ) value = 0; } else { if ( value >= itemCount ) value -= itemCount; else if ( value < 0 ) value += itemCount; } if ( value == m_value ) // Even if value was same, don't skip the event // (good for consistency) return true; m_value = value; if ( value >= 0 ) m_combo->SetValue(m_strings[value]); SendComboBoxEvent(m_value); return true; }