Remove workarounds for wxTextCtrl::SetValue() events in pickers code.
Simply use ChangeValue() instead of SetValue() to avoid the unwanted events instead of using guard variables. No real changes but the code is simpler and shorter now. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72454 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -98,7 +98,7 @@ protected:
|
|||||||
class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
|
class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxColourPickerCtrl() : m_bIgnoreNextTextCtrlUpdate(false) {}
|
wxColourPickerCtrl() {}
|
||||||
virtual ~wxColourPickerCtrl() {}
|
virtual ~wxColourPickerCtrl() {}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,7 +107,6 @@ public:
|
|||||||
const wxSize& size = wxDefaultSize, long style = wxCLRP_DEFAULT_STYLE,
|
const wxSize& size = wxDefaultSize, long style = wxCLRP_DEFAULT_STYLE,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxColourPickerCtrlNameStr)
|
const wxString& name = wxColourPickerCtrlNameStr)
|
||||||
: m_bIgnoreNextTextCtrlUpdate(false)
|
|
||||||
{ Create(parent, id, col, pos, size, style, validator, name); }
|
{ Create(parent, id, col, pos, size, style, validator, name); }
|
||||||
|
|
||||||
bool Create(wxWindow *parent, wxWindowID id,
|
bool Create(wxWindow *parent, wxWindowID id,
|
||||||
@@ -148,9 +147,6 @@ protected:
|
|||||||
virtual long GetPickerStyle(long style) const
|
virtual long GetPickerStyle(long style) const
|
||||||
{ return (style & wxCLRP_SHOW_LABEL); }
|
{ return (style & wxCLRP_SHOW_LABEL); }
|
||||||
|
|
||||||
// true if the next UpdateTextCtrl() call is to ignore
|
|
||||||
bool m_bIgnoreNextTextCtrlUpdate;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl)
|
DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl)
|
||||||
};
|
};
|
||||||
|
@@ -148,7 +148,7 @@ protected:
|
|||||||
class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase : public wxPickerBase
|
class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase : public wxPickerBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
|
wxFileDirPickerCtrlBase() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// NB: no default values since this function will never be used
|
// NB: no default values since this function will never be used
|
||||||
@@ -209,9 +209,6 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// true if the next UpdateTextCtrl() call is to ignore
|
|
||||||
bool m_bIgnoreNextTextCtrlUpdate;
|
|
||||||
|
|
||||||
// m_picker object as wxFileDirPickerWidgetBase interface
|
// m_picker object as wxFileDirPickerWidgetBase interface
|
||||||
wxFileDirPickerWidgetBase *m_pickerIface;
|
wxFileDirPickerWidgetBase *m_pickerIface;
|
||||||
};
|
};
|
||||||
|
@@ -100,8 +100,7 @@ class WXDLLIMPEXP_CORE wxFontPickerCtrl : public wxPickerBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFontPickerCtrl()
|
wxFontPickerCtrl()
|
||||||
: m_bIgnoreNextTextCtrlUpdate(false),
|
: m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
|
||||||
m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +115,7 @@ public:
|
|||||||
long style = wxFNTP_DEFAULT_STYLE,
|
long style = wxFNTP_DEFAULT_STYLE,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxFontPickerCtrlNameStr)
|
const wxString& name = wxFontPickerCtrlNameStr)
|
||||||
: m_bIgnoreNextTextCtrlUpdate(false),
|
: m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
|
||||||
m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
|
|
||||||
{
|
{
|
||||||
Create(parent, id, initial, pos, size, style, validator, name);
|
Create(parent, id, initial, pos, size, style, validator, name);
|
||||||
}
|
}
|
||||||
@@ -165,9 +163,6 @@ protected:
|
|||||||
long GetPickerStyle(long style) const
|
long GetPickerStyle(long style) const
|
||||||
{ return (style & (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)); }
|
{ return (style & (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)); }
|
||||||
|
|
||||||
// true if the next UpdateTextCtrl() call is to ignore
|
|
||||||
bool m_bIgnoreNextTextCtrlUpdate;
|
|
||||||
|
|
||||||
// the maximum pointsize allowed to the user
|
// the maximum pointsize allowed to the user
|
||||||
unsigned int m_nMaxPointSize;
|
unsigned int m_nMaxPointSize;
|
||||||
|
|
||||||
|
@@ -96,13 +96,6 @@ void wxColourPickerCtrl::UpdatePickerFromTextCtrl()
|
|||||||
{
|
{
|
||||||
wxASSERT(m_text);
|
wxASSERT(m_text);
|
||||||
|
|
||||||
if (m_bIgnoreNextTextCtrlUpdate)
|
|
||||||
{
|
|
||||||
// ignore this update
|
|
||||||
m_bIgnoreNextTextCtrlUpdate = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// wxString -> wxColour conversion
|
// wxString -> wxColour conversion
|
||||||
wxColour col(m_text->GetValue());
|
wxColour col(m_text->GetValue());
|
||||||
if ( !col.IsOk() )
|
if ( !col.IsOk() )
|
||||||
@@ -123,11 +116,9 @@ void wxColourPickerCtrl::UpdateTextCtrlFromPicker()
|
|||||||
if (!m_text)
|
if (!m_text)
|
||||||
return; // no textctrl to update
|
return; // no textctrl to update
|
||||||
|
|
||||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
// Take care to use ChangeValue() here and not SetValue() to avoid
|
||||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
// infinite recursion.
|
||||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
m_text->ChangeValue(M_PICKER->GetColour().GetAsString());
|
||||||
m_bIgnoreNextTextCtrlUpdate = true;
|
|
||||||
m_text->SetValue(M_PICKER->GetColour().GetAsString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -115,13 +115,6 @@ void wxFileDirPickerCtrlBase::UpdatePickerFromTextCtrl()
|
|||||||
{
|
{
|
||||||
wxASSERT(m_text);
|
wxASSERT(m_text);
|
||||||
|
|
||||||
if (m_bIgnoreNextTextCtrlUpdate)
|
|
||||||
{
|
|
||||||
// ignore this update
|
|
||||||
m_bIgnoreNextTextCtrlUpdate = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove the eventually present path-separator from the end of the textctrl
|
// remove the eventually present path-separator from the end of the textctrl
|
||||||
// string otherwise we would generate a wxFileDirPickerEvent when changing
|
// string otherwise we would generate a wxFileDirPickerEvent when changing
|
||||||
// from e.g. /home/user to /home/user/ and we want to avoid it !
|
// from e.g. /home/user to /home/user/ and we want to avoid it !
|
||||||
@@ -150,11 +143,10 @@ void wxFileDirPickerCtrlBase::UpdateTextCtrlFromPicker()
|
|||||||
if (!m_text)
|
if (!m_text)
|
||||||
return; // no textctrl to update
|
return; // no textctrl to update
|
||||||
|
|
||||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
// Take care to use ChangeValue() here and not SetValue() to avoid
|
||||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
// generating an event that would trigger UpdateTextCtrlFromPicker()
|
||||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
// resulting in infinite recursion.
|
||||||
m_bIgnoreNextTextCtrlUpdate = true;
|
m_text->ChangeValue(m_pickerIface->GetPath());
|
||||||
m_text->SetValue(m_pickerIface->GetPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -125,13 +125,6 @@ void wxFontPickerCtrl::UpdatePickerFromTextCtrl()
|
|||||||
{
|
{
|
||||||
wxASSERT(m_text);
|
wxASSERT(m_text);
|
||||||
|
|
||||||
if (m_bIgnoreNextTextCtrlUpdate)
|
|
||||||
{
|
|
||||||
// ignore this update
|
|
||||||
m_bIgnoreNextTextCtrlUpdate = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NB: we don't use the wxFont::wxFont(const wxString &) constructor
|
// NB: we don't use the wxFont::wxFont(const wxString &) constructor
|
||||||
// since that constructor expects the native font description
|
// since that constructor expects the native font description
|
||||||
// string returned by wxFont::GetNativeFontInfoDesc() and not
|
// string returned by wxFont::GetNativeFontInfoDesc() and not
|
||||||
@@ -155,11 +148,9 @@ void wxFontPickerCtrl::UpdateTextCtrlFromPicker()
|
|||||||
if (!m_text)
|
if (!m_text)
|
||||||
return; // no textctrl to update
|
return; // no textctrl to update
|
||||||
|
|
||||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
// Take care to use ChangeValue() here and not SetValue() to avoid
|
||||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
// infinite recursion.
|
||||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
m_text->ChangeValue(Font2String(M_PICKER->GetSelectedFont()));
|
||||||
m_bIgnoreNextTextCtrlUpdate = true;
|
|
||||||
m_text->SetValue(Font2String(M_PICKER->GetSelectedFont()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user