#elif defined(__WXGTK__)
+#include "wx/gtk/private.h"
+
// NB: It is not recommended to use wxDialog as popup on wxGTK, because of
// this bug: If wxDialog is hidden, its position becomes corrupt
// between hide and next show, but without internal coordinates being
// reflected (or something like that - atleast commenting out ->Hide()
// seemed to eliminate the position change).
+// NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
+// 'perfect' popup, as it can succesfully host child controls even in
+// popups that are shown in modal dialogs.
+
#define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
-#define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
+#define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
// native controls work on it like normal.
#define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
#define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
winFocused != m_combo->GetButton() // GTK (atleast) requires this
)
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
}
event.Skip();
void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
event.Skip();
}
void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
event.Skip();
}
void wxComboFrameEventHandler::OnClose( wxCloseEvent& event )
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
event.Skip();
}
void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event )
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
event.Skip();
}
void wxComboFrameEventHandler::OnResize( wxSizeEvent& event )
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
event.Skip();
}
void wxComboFrameEventHandler::OnMove( wxMoveEvent& event )
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
event.Skip();
}
wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)),
wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
- combo->OnPopupDismiss();
+ combo->OnPopupDismiss(true);
}
#endif // USES_WXPOPUPTRANSIENTWINDOW
wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
wxWindowList::iterator node = children.begin();
wxWindow* child = (wxWindow*)*node;
- child->AddPendingEvent(event);
+ child->GetEventHandler()->AddPendingEvent(event);
}
#if USES_WXDIALOG
if ( !event.GetActive() )
{
// Tell combo control that we are dismissed.
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
event.Skip();
}
{
}
+wxComboCtrl* wxComboPopup::GetComboCtrl() const
+{
+ return wxStaticCast(m_combo, wxComboCtrl);
+}
+
wxSize wxComboPopup::GetAdjustedSize( int minWidth,
int prefHeight,
int WXUNUSED(maxHeight) )
combo->PrepareBackground(dc,rect,0);
dc.DrawText( combo->GetValue(),
- rect.x + combo->GetTextIndent(),
+ rect.x + combo->m_marginLeft,
(rect.height-dc.GetCharHeight())/2 + rect.y );
}
}
void wxComboPopup::Dismiss()
{
- m_combo->HidePopup();
+ m_combo->HidePopup(true);
}
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler, wxEvtHandler)
EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey)
+ EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey)
+ EVT_CHAR(wxComboBoxExtraInputHandler::OnKey)
EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
END_EVENT_TABLE()
{
// Let the wxComboCtrl event handler have a go first.
wxComboCtrlBase* combo = m_combo;
- wxObject* prevObj = event.GetEventObject();
- event.SetId(combo->GetId());
- event.SetEventObject(combo);
- combo->GetEventHandler()->ProcessEvent(event);
+ wxKeyEvent redirectedEvent(event);
+ redirectedEvent.SetId(combo->GetId());
+ redirectedEvent.SetEventObject(combo);
- event.SetId(((wxWindow*)prevObj)->GetId());
- event.SetEventObject(prevObj);
+ if ( !combo->GetEventHandler()->ProcessEvent(redirectedEvent) )
+ {
+ // Don't let TAB through to the text ctrl - looks ugly
+ if ( event.GetKeyCode() != WXK_TAB )
+ event.Skip();
+ }
}
void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent& event)
void wxComboCtrlBase::Init()
{
- m_winPopup = (wxWindow *)NULL;
- m_popup = (wxWindow *)NULL;
+ m_winPopup = NULL;
+ m_popup = NULL;
m_popupWinState = Hidden;
- m_btn = (wxWindow*) NULL;
- m_text = (wxTextCtrl*) NULL;
- m_popupInterface = (wxComboPopup*) NULL;
+ m_btn = NULL;
+ m_text = NULL;
+ m_popupInterface = NULL;
- m_popupExtraHandler = (wxEvtHandler*) NULL;
- m_textEvtHandler = (wxEvtHandler*) NULL;
+ m_popupExtraHandler = NULL;
+ m_textEvtHandler = NULL;
#if INSTALL_TOPLEV_HANDLER
- m_toplevEvtHandler = (wxEvtHandler*) NULL;
+ m_toplevEvtHandler = NULL;
#endif
m_mainCtrlWnd = this;
m_extLeft = 0;
m_extRight = 0;
- m_absIndent = -1;
+ m_marginLeft = -1;
m_iFlags = 0;
m_timeCanAcceptClick = 0;
// Get colours
OnThemeChange();
- m_absIndent = GetNativeTextIndent();
+ m_marginLeft = GetNativeTextIndent();
m_iFlags |= wxCC_IFLAG_CREATED;
#if INSTALL_TOPLEV_HANDLER
delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
- m_toplevEvtHandler = (wxEvtHandler*) NULL;
+ m_toplevEvtHandler = NULL;
#endif
DestroyPopup();
}
// Defaul indentation
- if ( m_absIndent < 0 )
- m_absIndent = GetNativeTextIndent();
+ if ( m_marginLeft < 0 )
+ m_marginLeft = GetNativeTextIndent();
int butWidth = btnWidth;
if ( !m_text )
return;
-#if !TEXTCTRL_TEXT_CENTERED
-
wxSize sz = GetClientSize();
int customBorder = m_widthCustomBorder;
if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
{
- // Centre textctrl
+ int x;
+
+ if ( !m_widthCustomPaint )
+ {
+ // No special custom paint area - we can use 0 left margin
+ // with wxTextCtrl.
+ if ( m_text->SetMargins(0) )
+ textCtrlXAdjust = 0;
+ x = m_tcArea.x + m_marginLeft + textCtrlXAdjust;
+ }
+ else
+ {
+ // There is special custom paint area - it is better to
+ // use some margin with the wxTextCtrl.
+ m_text->SetMargins(m_marginLeft);
+ x = m_tcArea.x + m_widthCustomPaint +
+ m_marginLeft + textCtrlXAdjust;
+ }
+
+ // Centre textctrl vertically, if needed
+#if !TEXTCTRL_TEXT_CENTERED
int tcSizeY = m_text->GetBestSize().y;
- int diff = sz.y - tcSizeY;
- int y = textCtrlYAdjust + (diff/2);
+ int diff0 = sz.y - tcSizeY;
+ int y = textCtrlYAdjust + (diff0/2);
+#else
+ wxUnusedVar(textCtrlYAdjust);
+ int y = 0;
+#endif
if ( y < customBorder )
y = customBorder;
- m_text->SetSize( m_tcArea.x + m_widthCustomPaint + m_absIndent + textCtrlXAdjust,
- y,
- m_tcArea.width - COMBO_MARGIN -
- (textCtrlXAdjust + m_widthCustomPaint + m_absIndent),
- -1 );
+ m_text->SetSize(x,
+ y,
+ m_tcArea.width - m_tcArea.x - x,
+ -1 );
// Make sure textctrl doesn't exceed the bottom custom border
wxSize tsz = m_text->GetSize();
- diff = (y + tsz.y) - (sz.y - customBorder);
- if ( diff >= 0 )
+ int diff1 = (y + tsz.y) - (sz.y - customBorder);
+ if ( diff1 >= 0 )
{
- tsz.y = tsz.y - diff - 1;
+ tsz.y = tsz.y - diff1 - 1;
m_text->SetSize(tsz);
}
}
else
-#else // TEXTCTRL_TEXT_CENTERED
- wxUnusedVar(textCtrlXAdjust);
- wxUnusedVar(textCtrlYAdjust);
-#endif // !TEXTCTRL_TEXT_CENTERED/TEXTCTRL_TEXT_CENTERED
{
- // If it has border, have textctrl will the entire text field.
+ // If it has border, have textctrl fill the entire text field.
m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
m_tcArea.y,
m_tcArea.width - m_widthCustomPaint,
if ( m_text )
m_text->Enable(enable);
+ Refresh();
+
return true;
}
if ( !wxControl::SetFont(font) )
return false;
- if (m_text)
+ if ( m_text )
+ {
+ // Without hiding the wxTextCtrl there would be some
+ // visible 'flicker' (at least on Windows XP).
+ m_text->Hide();
m_text->SetFont(font);
+ OnResize();
+ m_text->Show();
+ }
return true;
}
}
else
{
- if ( m_text ) m_text->SetToolTip( (wxToolTip*) NULL );
- if ( m_btn ) m_btn->SetToolTip( (wxToolTip*) NULL );
+ if ( m_text ) m_text->SetToolTip( NULL );
+ if ( m_btn ) m_btn->SetToolTip( NULL );
}
}
#endif // wxUSE_TOOLTIPS
if ( textCtrl )
textCtrl->SetValidator( validator );
+ else
+ wxControl::SetValidator( validator );
}
wxValidator* wxComboCtrlBase::GetValidator()
{
wxTextCtrl* textCtrl = GetTextCtrl();
- if ( textCtrl )
- return textCtrl->GetValidator();
-
- return wxControl::GetValidator();
+ return textCtrl ? textCtrl->GetValidator() : wxControl::GetValidator();
}
#endif // wxUSE_VALIDATORS
if ( IsPopupWindowState(Visible) &&
( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
{
- HidePopup();
+ HidePopup(true);
return true;
}
}
#if USES_WXPOPUPWINDOW
// Click here always hides the popup.
if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
- HidePopup();
+ HidePopup(true);
#endif
}
else
{
// relay (some) mouse events to the popup
if ( evtType == wxEVT_MOUSEWHEEL )
- m_popup->AddPendingEvent(event);
+ m_popup->GetEventHandler()->AddPendingEvent(event);
}
else if ( evtType )
event.Skip();
if ( IsPopupShown() )
{
// pass it to the popped up control
- GetPopupControl()->GetControl()->AddPendingEvent(event);
+ GetPopupControl()->GetControl()->GetEventHandler()->AddPendingEvent(event);
}
else // no popup
{
- int keycode = event.GetKeyCode();
-
- if ( keycode == WXK_TAB )
- {
- wxNavigationKeyEvent evt;
-
- wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
-
- evt.SetFlags(wxNavigationKeyEvent::FromTab|
- (!event.ShiftDown() ? wxNavigationKeyEvent::IsForward
- : wxNavigationKeyEvent::IsBackward));
- evt.SetEventObject(mainCtrl);
- evt.SetCurrentFocus(mainCtrl);
- mainCtrl->GetParent()->GetEventHandler()->AddPendingEvent(evt);
+ if ( GetParent()->HasFlag(wxTAB_TRAVERSAL) &&
+ HandleAsNavigationKey(event) )
return;
- }
if ( IsKeyPopupToggle(event) )
{
return;
}
+ int keycode = event.GetKeyCode();
+
if ( (comboStyle & wxCB_READONLY) ||
(keycode != WXK_RIGHT && keycode != WXK_LEFT) )
{
{
wxWindow* tc = GetTextCtrl();
if ( tc && tc != DoFindFocus() )
-#ifdef __WXMAC__
- m_resetFocus = true;
-#else
{
tc->SetFocus();
}
-#endif
}
Refresh();
void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
OnThemeChange();
- // indentation may also have changed
- if ( !(m_iFlags & wxCC_IFLAG_INDENT_SET) )
- m_absIndent = GetNativeTextIndent();
+ // left margin may also have changed
+ if ( !(m_iFlags & wxCC_IFLAG_LEFT_MARGIN_SET) )
+ m_marginLeft = GetNativeTextIndent();
RecalcAndRefresh();
}
// Destroy popup window and the child control
void wxComboCtrlBase::DestroyPopup()
{
- HidePopup();
+ HidePopup(true);
if ( m_popup )
m_popup->RemoveEventHandler(m_popupExtraHandler);
m_winPopup->Destroy();
}
- m_popupExtraHandler = (wxEvtHandler*) NULL;
- m_popupInterface = (wxComboPopup*) NULL;
- m_winPopup = (wxWindow*) NULL;
- m_popup = (wxWindow*) NULL;
+ m_popupExtraHandler = NULL;
+ m_popupInterface = NULL;
+ m_winPopup = NULL;
+ m_popup = NULL;
}
void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
}
else
{
- m_popup = (wxWindow*) NULL;
+ m_popup = NULL;
}
// This must be done after creation
{
// Derived classes can override this method for totally custom
// popup action
- ShowPopup();
+ if ( !IsPopupWindowState(Visible) )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId());
+ event.SetEventObject(this);
+ HandleWindowEvent(event);
+
+ ShowPopup();
+ }
+ else
+ {
+ HidePopup(true);
+ }
}
void wxComboCtrlBase::ShowPopup()
Refresh();
}
-void wxComboCtrlBase::OnPopupDismiss()
+void wxComboCtrlBase::OnPopupDismiss(bool generateEvent)
{
// Just in case, avoid double dismiss
if ( IsPopupWindowState(Hidden) )
Refresh();
SetFocus();
+
+ if ( generateEvent )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId());
+ event.SetEventObject(this);
+ HandleWindowEvent(event);
+ }
}
-void wxComboCtrlBase::HidePopup()
+void wxComboCtrlBase::HidePopup(bool generateEvent)
{
// Should be able to call this without popup interface
if ( IsPopupWindowState(Hidden) )
m_winPopup->Hide();
- OnPopupDismiss();
+ OnPopupDismiss(generateEvent);
}
// ----------------------------------------------------------------------------
RecalcAndRefresh();
}
+bool wxComboCtrlBase::DoSetMargins(const wxPoint& margins)
+{
+ // For general sanity's sake, we ignore top margin. Instead
+ // we will always try to center the text vertically.
+ bool res = true;
+
+ if ( margins.x != -1 )
+ {
+ m_marginLeft = margins.x;
+ m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
+ }
+ else
+ {
+ m_marginLeft = GetNativeTextIndent();
+ m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
+ }
+
+ if ( margins.y != -1 )
+ {
+ res = false;
+ }
+
+ RecalcAndRefresh();
+
+ return res;
+}
+
+wxPoint wxComboCtrlBase::DoGetMargins() const
+{
+ return wxPoint(m_marginLeft, -1);
+}
+
+#if WXWIN_COMPATIBILITY_2_6
void wxComboCtrlBase::SetTextIndent( int indent )
{
if ( indent < 0 )
{
- m_absIndent = GetNativeTextIndent();
- m_iFlags &= ~(wxCC_IFLAG_INDENT_SET);
+ m_marginLeft = GetNativeTextIndent();
+ m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
}
else
{
- m_absIndent = indent;
- m_iFlags |= wxCC_IFLAG_INDENT_SET;
+ m_marginLeft = indent;
+ m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
}
RecalcAndRefresh();
}
+wxCoord wxComboCtrlBase::GetTextIndent() const
+{
+ return m_marginLeft;
+}
+#endif
+
wxCoord wxComboCtrlBase::GetNativeTextIndent() const
{
return DEFAULT_TEXT_INDENT;