+ virtual ~wxIEnumString()
+ {
+ ::DeleteCriticalSection(&m_csRestart);
+ ::DeleteCriticalSection(&m_csCompleter);
+ }
+
+ // Common part of all ctors.
+ void Init()
+ {
+ ::InitializeCriticalSection(&m_csCompleter);
+ ::InitializeCriticalSection(&m_csRestart);
+
+ m_completer = NULL;
+ m_restart = FALSE;
+ }
+
+ // Restart completions generation if needed. Should be only called from
+ // inside m_csCompleter.
+ //
+ // If false is returned, it means that there are no completions and that
+ // wxTextCompleter::GetNext() shouldn't be called at all.
+ bool RestartIfNeeded()
+ {
+ bool rc = true;
+ for ( ;; )
+ {
+ wxString prefix;
+ LONG restart;
+ {
+ CSLock lock(m_csRestart);
+
+ prefix = m_prefix;
+ restart = m_restart;
+
+ m_restart = FALSE;
+ } // Release m_csRestart before calling Start() to avoid blocking
+ // the main thread in UpdatePrefix() during its execution.
+
+ if ( !restart )
+ break;
+
+ rc = m_completer->Start(prefix);
+ }
+
+ return rc;
+ }
+
+
+ // Critical section protecting m_completer itself. It must be entered when
+ // using the pointer to ensure that we don't continue using a dangling one
+ // after it is destroyed.
+ CRITICAL_SECTION m_csCompleter;
+
+ // The completer we delegate to for the completions generation. It is never
+ // NULL after the initial ChangeCompleter() call.
+ wxTextCompleter *m_completer;
+
+
+ // Critical section m_prefix and m_restart. It should be only entered for
+ // short periods of time, i.e. we shouldn't call any wxTextCompleter
+ // methods from inside, to prevent the main thread from blocking on it in
+ // UpdatePrefix().
+ CRITICAL_SECTION m_csRestart;