#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
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
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);
}
// ----------------------------------------------------------------------------
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;
}
// 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 ( !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;
}
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
{
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);
// Derived classes can override this method for totally custom
// popup action
if ( !IsPopupWindowState(Visible) )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId());
+ event.SetEventObject(this);
+ HandleWindowEvent(event);
+
ShowPopup();
+ }
else
- HidePopup();
+ {
+ 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;