Add wxTextEntry::MSWUsesStandardAutoComplete()

Implementation is a hack, using a magic pointer value because just
storing this in wxTextAutoCompleteData is not simple, as any flag added
to it would need to be reset in several different places.

This is not used yet, but will be in the upcoming commits.
This commit is contained in:
Vadim Zeitlin
2021-04-07 22:22:14 +01:00
parent a6e4cc7eb0
commit 1007259504
2 changed files with 34 additions and 5 deletions

View File

@@ -81,6 +81,9 @@ protected:
virtual bool DoAutoCompleteCustom(wxTextCompleter *completer) wxOVERRIDE;
#endif // wxUSE_OLE
// Returns true if this control uses standard file names completion.
bool MSWUsesStandardAutoComplete() const;
// Helper for wxTE_PROCESS_ENTER handling: activates the default button in
// the dialog containing this control if any.
bool ClickDefaultButtonIfPossible();
@@ -100,6 +103,10 @@ private:
// be called and the default implementation asserts if this is not the case.
virtual void MSWProcessSpecialKey(wxKeyEvent& event);
// Check if we really have auto-complete data. This is not the same as just
// checking if m_autoCompleteData is NULL, see the code for more details.
bool MSWHasAutoCompleteData() const;
// Check that we have auto-complete data, creating it if necessary. Returns
// false if creating it failed.
bool MSWEnsureHasAutoCompleteData();

View File

@@ -659,6 +659,10 @@ private:
wxDECLARE_NO_COPY_CLASS(wxTextAutoCompleteData);
};
// Special pointer value which indicates that we're using SHAutoComplete().
static wxTextAutoCompleteData* const wxDUMMY_SHAUTOCOMPLETE_DATA =
reinterpret_cast<wxTextAutoCompleteData*>(-1);
#endif // HAS_AUTOCOMPLETE
// ============================================================================
@@ -679,6 +683,7 @@ wxTextEntry::wxTextEntry()
wxTextEntry::~wxTextEntry()
{
#ifdef HAS_AUTOCOMPLETE
if ( MSWHasAutoCompleteData() )
delete m_autoCompleteData;
#endif // HAS_AUTOCOMPLETE
}
@@ -833,8 +838,11 @@ bool wxTextEntry::DoAutoCompleteFileNames(int flags)
// Disable the other kinds of completion now that we use the built-in file
// names completion.
if ( m_autoCompleteData )
m_autoCompleteData->DisableCompletion();
if ( MSWHasAutoCompleteData() )
delete m_autoCompleteData;
// Set it to the special value indicating that we're using SHAutoComplete().
m_autoCompleteData = wxDUMMY_SHAUTOCOMPLETE_DATA;
return true;
}
@@ -846,9 +854,23 @@ void wxTextEntry::MSWProcessSpecialKey(wxKeyEvent& WXUNUSED(event))
wxFAIL_MSG(wxS("Must be overridden if can be called"));
}
bool wxTextEntry::MSWUsesStandardAutoComplete() const
{
return m_autoCompleteData == wxDUMMY_SHAUTOCOMPLETE_DATA;
}
bool wxTextEntry::MSWHasAutoCompleteData() const
{
// We use special wxDUMMY_SHAUTOCOMPLETE_DATA for the pointer to indicate
// that we're using SHAutoComplete(), so we need to check for it too, and
// not just whether the pointer is non-NULL.
return m_autoCompleteData != NULL
&& m_autoCompleteData != wxDUMMY_SHAUTOCOMPLETE_DATA;
}
bool wxTextEntry::MSWEnsureHasAutoCompleteData()
{
if ( !m_autoCompleteData )
if ( !MSWHasAutoCompleteData() )
{
wxTextAutoCompleteData * const ac = new wxTextAutoCompleteData(this);
if ( !ac->IsOk() )
@@ -878,7 +900,7 @@ bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
// First deal with the case when we just want to disable auto-completion.
if ( !completer )
{
if ( m_autoCompleteData )
if ( MSWHasAutoCompleteData() )
m_autoCompleteData->DisableCompletion();
//else: Nothing to do, we hadn't used auto-completion even before.
}