Have wxComboCtrl generate wxEVT_COMMAND_COMBOBOX_DROPDOWN and wxEVT_COMMAND_COMBOBOX_CLOSEUP events

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62136 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-09-26 09:15:29 +00:00
parent f4c24d3da4
commit a1d5aa9361
4 changed files with 59 additions and 20 deletions

View File

@@ -158,7 +158,7 @@ public:
// show/hide popup window // show/hide popup window
virtual void ShowPopup(); virtual void ShowPopup();
virtual void HidePopup(); virtual void HidePopup(bool generateEvent=false);
// Override for totally custom combo action // Override for totally custom combo action
virtual void OnButtonClick(); virtual void OnButtonClick();
@@ -403,7 +403,7 @@ public:
bool IsCreated() const { return m_iFlags & wxCC_IFLAG_CREATED ? true : false; } bool IsCreated() const { return m_iFlags & wxCC_IFLAG_CREATED ? true : false; }
// common code to be called on popup hide/dismiss // common code to be called on popup hide/dismiss
void OnPopupDismiss(); void OnPopupDismiss(bool generateEvent);
// PopupShown states // PopupShown states
enum enum

View File

@@ -304,6 +304,12 @@ struct wxComboCtrlFeatures
@event{EVT_TEXT_ENTER(id, func)} @event{EVT_TEXT_ENTER(id, func)}
Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in Process a wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in
the combo control. the combo control.
@event{EVT_COMBOX_DROPDOWN(id, func)}
Process a wxEVT_COMMAND_COMBOBOX_DROPDOWN event, which is generated
when the popup window is shown (drops down).
@event{EVT_COMBOX_CLOSEUP(id, func)}
Process a wxEVT_COMMAND_COMBOBOX_CLOSEUP event, which is generated
when the popup window of the combo control disappears (closes up).
@endEventTable @endEventTable
@library{wxbase} @library{wxbase}
@@ -504,8 +510,12 @@ public:
/** /**
Dismisses the popup window. Dismisses the popup window.
@param generateEvent
Set this to @true in order to generate
wxEVT_COMMAND_COMBOBOX_CLOSEUP event.
*/ */
virtual void HidePopup(); virtual void HidePopup(bool generateEvent=false);
/** /**
Returns @true if the popup is currently shown Returns @true if the popup is currently shown

View File

@@ -113,6 +113,8 @@ protected:
void OnButtonAddMany(wxCommandEvent& event); void OnButtonAddMany(wxCommandEvent& event);
void OnComboBox(wxCommandEvent& event); void OnComboBox(wxCommandEvent& event);
void OnDropDown(wxCommandEvent& event);
void OnCloseUp(wxCommandEvent& event);
void OnComboText(wxCommandEvent& event); void OnComboText(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event); void OnCheckOrRadioBox(wxCommandEvent& event);
@@ -218,6 +220,8 @@ BEGIN_EVENT_TABLE(ODComboboxWidgetsPage, WidgetsPage)
EVT_UPDATE_UI(ODComboPage_ChangeText, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton) EVT_UPDATE_UI(ODComboPage_ChangeText, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_UPDATE_UI(ODComboPage_DeleteSel, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton) EVT_UPDATE_UI(ODComboPage_DeleteSel, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_COMBOBOX_DROPDOWN(ODComboPage_Combo, ODComboboxWidgetsPage::OnDropDown)
EVT_COMBOBOX_CLOSEUP(ODComboPage_Combo, ODComboboxWidgetsPage::OnCloseUp)
EVT_COMBOBOX(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboBox) EVT_COMBOBOX(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboBox)
EVT_TEXT(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboText) EVT_TEXT(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboText)
EVT_TEXT_ENTER(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboText) EVT_TEXT_ENTER(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboText)
@@ -844,4 +848,14 @@ wxBitmap ODComboboxWidgetsPage::CreateBitmap(const wxColour& colour)
return bmp; return bmp;
} }
void ODComboboxWidgetsPage::OnDropDown(wxCommandEvent& WXUNUSED(event))
{
wxLogMessage(wxT("Combobox dropped down"));
}
void ODComboboxWidgetsPage::OnCloseUp(wxCommandEvent& WXUNUSED(event))
{
wxLogMessage(wxT("Combobox closed up"));
}
#endif //wxUSE_ODCOMBOBOX #endif //wxUSE_ODCOMBOBOX

View File

@@ -291,7 +291,7 @@ void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
winFocused != m_combo->GetButton() // GTK (atleast) requires this winFocused != m_combo->GetButton() // GTK (atleast) requires this
) )
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
} }
event.Skip(); event.Skip();
@@ -299,37 +299,37 @@ void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event ) void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
event.Skip(); event.Skip();
} }
void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event ) void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
event.Skip(); event.Skip();
} }
void wxComboFrameEventHandler::OnClose( wxCloseEvent& event ) void wxComboFrameEventHandler::OnClose( wxCloseEvent& event )
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
event.Skip(); event.Skip();
} }
void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event ) void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event )
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
event.Skip(); event.Skip();
} }
void wxComboFrameEventHandler::OnResize( wxSizeEvent& event ) void wxComboFrameEventHandler::OnResize( wxSizeEvent& event )
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
event.Skip(); event.Skip();
} }
void wxComboFrameEventHandler::OnMove( wxMoveEvent& event ) void wxComboFrameEventHandler::OnMove( wxMoveEvent& event )
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
event.Skip(); event.Skip();
} }
@@ -413,7 +413,7 @@ void wxComboPopupWindow::OnDismiss()
wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)), wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)),
wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") ); wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
combo->OnPopupDismiss(); combo->OnPopupDismiss(true);
} }
#endif // USES_WXPOPUPTRANSIENTWINDOW #endif // USES_WXPOPUPTRANSIENTWINDOW
@@ -476,7 +476,7 @@ void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event )
if ( !event.GetActive() ) if ( !event.GetActive() )
{ {
// Tell combo control that we are dismissed. // Tell combo control that we are dismissed.
m_combo->HidePopup(); m_combo->HidePopup(true);
event.Skip(); event.Skip();
} }
@@ -551,7 +551,7 @@ bool wxComboPopup::LazyCreate()
void wxComboPopup::Dismiss() void wxComboPopup::Dismiss()
{ {
m_combo->HidePopup(); m_combo->HidePopup(true);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1624,7 +1624,7 @@ bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
if ( IsPopupWindowState(Visible) && if ( IsPopupWindowState(Visible) &&
( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) ) ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
{ {
HidePopup(); HidePopup(true);
return true; return true;
} }
} }
@@ -1652,7 +1652,7 @@ void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
#if USES_WXPOPUPWINDOW #if USES_WXPOPUPWINDOW
// Click here always hides the popup. // Click here always hides the popup.
if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW ) if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
HidePopup(); HidePopup(true);
#endif #endif
} }
else else
@@ -1808,7 +1808,7 @@ void wxComboCtrlBase::CreatePopup()
// Destroy popup window and the child control // Destroy popup window and the child control
void wxComboCtrlBase::DestroyPopup() void wxComboCtrlBase::DestroyPopup()
{ {
HidePopup(); HidePopup(true);
if ( m_popup ) if ( m_popup )
m_popup->RemoveEventHandler(m_popupExtraHandler); m_popup->RemoveEventHandler(m_popupExtraHandler);
@@ -1871,9 +1871,17 @@ void wxComboCtrlBase::OnButtonClick()
// Derived classes can override this method for totally custom // Derived classes can override this method for totally custom
// popup action // popup action
if ( !IsPopupWindowState(Visible) ) if ( !IsPopupWindowState(Visible) )
{
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId());
event.SetEventObject(this);
ProcessCommand(event);
ShowPopup(); ShowPopup();
}
else else
HidePopup(); {
HidePopup(true);
}
} }
void wxComboCtrlBase::ShowPopup() void wxComboCtrlBase::ShowPopup()
@@ -2092,7 +2100,7 @@ void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
Refresh(); Refresh();
} }
void wxComboCtrlBase::OnPopupDismiss() void wxComboCtrlBase::OnPopupDismiss(bool generateEvent)
{ {
// Just in case, avoid double dismiss // Just in case, avoid double dismiss
if ( IsPopupWindowState(Hidden) ) if ( IsPopupWindowState(Hidden) )
@@ -2144,9 +2152,16 @@ void wxComboCtrlBase::OnPopupDismiss()
Refresh(); Refresh();
SetFocus(); SetFocus();
if ( generateEvent )
{
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId());
event.SetEventObject(this);
ProcessCommand(event);
}
} }
void wxComboCtrlBase::HidePopup() void wxComboCtrlBase::HidePopup(bool generateEvent)
{ {
// Should be able to call this without popup interface // Should be able to call this without popup interface
if ( IsPopupWindowState(Hidden) ) if ( IsPopupWindowState(Hidden) )
@@ -2158,7 +2173,7 @@ void wxComboCtrlBase::HidePopup()
m_winPopup->Hide(); m_winPopup->Hide();
OnPopupDismiss(); OnPopupDismiss(generateEvent);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------