#include "wx/timer.h"
#endif
-#include "wx/dcbuffer.h"
#include "wx/tooltip.h"
#include "wx/combo.h"
#define BMP_BUTTON_MARGIN 4
-#define DEFAULT_POPUP_HEIGHT 200
+#define DEFAULT_POPUP_HEIGHT 400
#define DEFAULT_TEXT_INDENT 3
#if defined(__WXMSW__)
#define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
+#define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
//#undef wxUSE_POPUPWIN
//#define wxUSE_POPUPWIN 0
#elif defined(__WXGTK__)
#define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
+#define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
#elif defined(__WXMAC__)
#define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
+#define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
#else
#define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
+#define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
#endif
IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl)
-// Have global double buffer - should be enough for multiple combos
-static wxBitmap* gs_doubleBuffer = (wxBitmap*) NULL;
-
void wxComboCtrlBase::Init()
{
m_winPopup = (wxWindow *)NULL;
m_btnState = 0;
m_btnWidDefault = 0;
m_blankButtonBg = false;
+ m_ignoreEvtText = 0;
m_btnWid = m_btnHei = -1;
m_btnSide = wxRIGHT;
m_btnSpacingX = 0;
m_extRight = 0;
m_absIndent = -1;
m_iFlags = 0;
- m_downReceived = false;
m_timeCanAcceptClick = 0;
}
{
if ( !(m_windowStyle & wxCB_READONLY) )
{
+ if ( m_text )
+ m_text->Destroy();
+
// wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
// not used by the wxPropertyGrid and therefore the tab is processed by
// looking at ancestors to see if they have wxTAB_TRAVERSAL. The
if ( HasFlag(wxTE_PROCESS_ENTER) )
style |= wxTE_PROCESS_ENTER;
+ // Ignore EVT_TEXT generated by the constructor (but only
+ // if the event redirector already exists)
+ // NB: This must be " = 1" instead of "++";
+ if ( m_textEvtHandler )
+ m_ignoreEvtText = 1;
+ else
+ m_ignoreEvtText = 0;
+
m_text = new wxTextCtrl(this, wxID_ANY, m_valueString,
wxDefaultPosition, wxDefaultSize,
style, validator);
if ( HasCapture() )
ReleaseMouse();
- delete gs_doubleBuffer;
- gs_doubleBuffer = (wxBitmap*) NULL;
-
#if INSTALL_TOPLEV_HANDLER
delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
m_toplevEvtHandler = (wxEvtHandler*) NULL;
wxSize sz = GetClientSize();
int customBorder = m_widthCustomBorder;
+#if !TEXTCTRL_TEXT_CENTERED
if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
{
// Centre textctrl
}
}
else
+#else
+ wxUnusedVar(textCtrlXAdjust);
+ wxUnusedVar(textCtrlYAdjust);
+#endif
{
- m_text->SetSize( m_tcArea.x,
- 0,
- sz.x - m_btnArea.x - m_widthCustomPaint - customBorder,
- sz.y );
+ // If it has border, have textctrl will the entire text field.
+ m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
+ customBorder,
+ sz.x - m_btnArea.width - m_widthCustomPaint - customBorder,
+ sz.y-(customBorder*2) );
}
}
}
}
-wxBitmap& wxComboCtrlBase::GetBufferBitmap( const wxSize& sz ) const
-{
- // If size is larger, recalculate double buffer bitmap
- if ( !gs_doubleBuffer ||
- sz.x > gs_doubleBuffer->GetWidth() ||
- sz.y > gs_doubleBuffer->GetHeight() )
- {
- delete gs_doubleBuffer;
- gs_doubleBuffer = new wxBitmap(sz.x+25,sz.y);
- }
- return *gs_doubleBuffer;
-}
-
// ----------------------------------------------------------------------------
// miscellaneous event handlers
// ----------------------------------------------------------------------------
void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
{
+ if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
+ {
+ if ( m_ignoreEvtText > 0 )
+ {
+ m_ignoreEvtText--;
+ return;
+ }
+ }
+
// Change event id, object and string before relaying it forward
event.SetId(GetId());
wxString s = event.GetString();
}
else if ( type == wxEVT_LEFT_DOWN )
{
- // Only accept event if it wasn't right after popup dismiss
- //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
+ if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
{
- // Need to test this, because it might be outside.
- if ( flags & wxCC_MF_ON_BUTTON )
- {
- m_btnState |= wxCONTROL_PRESSED;
- Refresh();
+ m_btnState |= wxCONTROL_PRESSED;
+ Refresh();
- if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
- OnButtonClick();
- else
- // If showing popup now, do not capture mouse or there will be interference
- CaptureMouse();
- }
+ if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
+ OnButtonClick();
+ else
+ // If showing popup now, do not capture mouse or there will be interference
+ CaptureMouse();
}
- /*else
- {
- m_btnState = 0;
- }*/
}
else if ( type == wxEVT_LEFT_UP )
{
// If mouse was inside, fire the click event.
if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
{
- if ( flags & wxCC_MF_ON_BUTTON )
+ if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
OnButtonClick();
}
return true;
}
-// Conversion to double-clicks and some basic filtering
// returns true if event was consumed or filtered
-//bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, bool isOnButtonArea )
bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
- int flags )
+ int WXUNUSED(flags) )
{
wxLongLong t = ::wxGetLocalTimeMillis();
int evtType = event.GetEventType();
}
#endif
- //
- // Generate our own double-clicks
- // (to allow on-focus dc-event on double-clicks instead of triple-clicks)
- if ( (m_windowStyle & wxCC_SPECIAL_DCLICK) &&
- !m_isPopupShown &&
- //!(handlerFlags & wxCC_MF_ON_BUTTON) )
- !(flags & wxCC_MF_ON_BUTTON) )
- {
- if ( evtType == wxEVT_LEFT_DOWN )
- {
- // Set value to avoid up-events without corresponding downs
- m_downReceived = true;
- }
- else if ( evtType == wxEVT_LEFT_DCLICK )
- {
- // We'll make our own double-clicks
- //evtType = 0;
- event.SetEventType(0);
- return true;
- }
- else if ( evtType == wxEVT_LEFT_UP )
- {
- if ( m_downReceived || m_timeLastMouseUp == 1 )
- {
- wxLongLong timeFromLastUp = (t-m_timeLastMouseUp);
-
- if ( timeFromLastUp < DOUBLE_CLICK_CONVERSION_TRESHOLD )
- {
- //type = wxEVT_LEFT_DCLICK;
- event.SetEventType(wxEVT_LEFT_DCLICK);
- m_timeLastMouseUp = 1;
- }
- else
- {
- m_timeLastMouseUp = t;
- }
-
- //m_downReceived = false;
- }
- }
- }
-
// Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
{
{
if ( event.GetEventType() == wxEVT_SET_FOCUS )
{
- // First click is the first part of double-click
- // Some platforms don't generate down-less mouse up-event
- // (Windows does, GTK+2 doesn't), so that's why we have
- // to do this.
- m_timeLastMouseUp = ::wxGetLocalTimeMillis();
-
if ( m_text && m_text != ::wxWindow::FindFocus() )
m_text->SetFocus();
}
return m_valueString;
}
-void wxComboCtrlBase::SetValue(const wxString& value)
+void wxComboCtrlBase::SetValueWithEvent(const wxString& value, bool withEvent)
{
if ( m_text )
{
+ if ( !withEvent )
+ m_ignoreEvtText++;
+
m_text->SetValue(value);
if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
m_text->SelectAll();
}
}
+void wxComboCtrlBase::SetValue(const wxString& value)
+{
+ SetValueWithEvent(value, false);
+}
+
// In this SetValue variant wxComboPopup::SetStringValue is not called
void wxComboCtrlBase::SetText(const wxString& value)
{
m_valueString = value;
+ if ( m_text )
+ {
+ m_ignoreEvtText++;
+ m_text->SetValue( value );
+ }
+
Refresh();
}