]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/combocmn.cpp
Store property name and value in wxPropertyGridEvent, keep track of live event instan...
[wxWidgets.git] / src / common / combocmn.cpp
index 06b3cf23ce1a8580f9ec565e92d7ad5f549e92d6..5df0a61af55efdc0200ad2e92a0edb0e9f1db3ad 100644 (file)
@@ -71,6 +71,8 @@
 
 #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
@@ -289,7 +291,7 @@ void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
          winFocused != m_combo->GetButton() // GTK (atleast) requires this
         )
     {
-        m_combo->HidePopup();
+        m_combo->HidePopup(true);
     }
 
     event.Skip();
@@ -297,37 +299,37 @@ void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
 
 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();
 }
 
@@ -411,7 +413,7 @@ void wxComboPopupWindow::OnDismiss()
     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
 
@@ -474,7 +476,7 @@ void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event )
     if ( !event.GetActive() )
     {
         // Tell combo control that we are dismissed.
-        m_combo->HidePopup();
+        m_combo->HidePopup(true);
 
         event.Skip();
     }
@@ -499,6 +501,11 @@ void wxComboPopup::OnDismiss()
 {
 }
 
+wxComboCtrl* wxComboPopup::GetComboCtrl() const
+{
+    return wxStaticCast(m_combo, wxComboCtrl);
+}
+
 wxSize wxComboPopup::GetAdjustedSize( int minWidth,
                                       int prefHeight,
                                       int WXUNUSED(maxHeight) )
@@ -514,7 +521,7 @@ void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo,
         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 );
     }
 }
@@ -544,7 +551,7 @@ bool wxComboPopup::LazyCreate()
 
 void wxComboPopup::Dismiss()
 {
-    m_combo->HidePopup();
+    m_combo->HidePopup(true);
 }
 
 // ----------------------------------------------------------------------------
@@ -799,7 +806,7 @@ void wxComboCtrlBase::Init()
 
     m_extLeft = 0;
     m_extRight = 0;
-    m_absIndent = -1;
+    m_marginLeft = -1;
     m_iFlags = 0;
     m_timeCanAcceptClick = 0;
 
@@ -828,7 +835,7 @@ bool wxComboCtrlBase::Create(wxWindow *parent,
 
     // Get colours
     OnThemeChange();
-    m_absIndent = GetNativeTextIndent();
+    m_marginLeft = GetNativeTextIndent();
 
     m_iFlags |= wxCC_IFLAG_CREATED;
 
@@ -948,8 +955,8 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth )
     }
 
     // Defaul indentation
-    if ( m_absIndent < 0 )
-        m_absIndent = GetNativeTextIndent();
+    if ( m_marginLeft < 0 )
+        m_marginLeft = GetNativeTextIndent();
 
     int butWidth = btnWidth;
 
@@ -1053,43 +1060,60 @@ void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust
     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,
@@ -1211,8 +1235,15 @@ bool wxComboCtrlBase::SetFont ( const wxFont& font )
     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;
 }
@@ -1593,7 +1624,7 @@ bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
         if ( IsPopupWindowState(Visible) &&
              ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
         {
-            HidePopup();
+            HidePopup(true);
             return true;
         }
     }
@@ -1621,7 +1652,7 @@ void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
     #if USES_WXPOPUPWINDOW
             // Click here always hides the popup.
             if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
-                HidePopup();
+                HidePopup(true);
     #endif
         }
         else
@@ -1698,13 +1729,9 @@ void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
     {
         wxWindow* tc = GetTextCtrl();
         if ( tc && tc != DoFindFocus() )
-#ifdef __WXMAC__
-            m_resetFocus = true;
-#else
         {
             tc->SetFocus();
         }
-#endif
     }
 
     Refresh();
@@ -1724,9 +1751,9 @@ void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) )
 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();
 }
 
@@ -1781,7 +1808,7 @@ void wxComboCtrlBase::CreatePopup()
 // Destroy popup window and the child control
 void wxComboCtrlBase::DestroyPopup()
 {
-    HidePopup();
+    HidePopup(true);
 
     if ( m_popup )
         m_popup->RemoveEventHandler(m_popupExtraHandler);
@@ -1844,9 +1871,17 @@ void wxComboCtrlBase::OnButtonClick()
     // 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()
@@ -2065,7 +2100,7 @@ void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
     Refresh();
 }
 
-void wxComboCtrlBase::OnPopupDismiss()
+void wxComboCtrlBase::OnPopupDismiss(bool generateEvent)
 {
     // Just in case, avoid double dismiss
     if ( IsPopupWindowState(Hidden) )
@@ -2117,9 +2152,16 @@ void wxComboCtrlBase::OnPopupDismiss()
     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) )
@@ -2131,7 +2173,7 @@ void wxComboCtrlBase::HidePopup()
 
     m_winPopup->Hide();
 
-    OnPopupDismiss();
+    OnPopupDismiss(generateEvent);
 }
 
 // ----------------------------------------------------------------------------
@@ -2212,22 +2254,61 @@ void wxComboCtrlBase::SetCustomPaintWidth( int width )
     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;