Merge branch 'gtk-text-changed-coalesce'

Harmonize wxEVT_TEXT events in wxGTK with other ports.

Also use IME for wxComboBox in wxGTK too.

See https://github.com/wxWidgets/wxWidgets/pull/1400
This commit is contained in:
Vadim Zeitlin
2019-07-16 19:41:32 +02:00
9 changed files with 283 additions and 91 deletions

View File

@@ -31,6 +31,7 @@
#include "wx/bitmap.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/dcclient.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/stattext.h"
@@ -986,19 +987,21 @@ void TextWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
(m_radioWrap->GetSelection() != DEFAULTS.wrapStyle) );
}
void TextWidgetsPage::OnText(wxCommandEvent& WXUNUSED(event))
void TextWidgetsPage::OnText(wxCommandEvent& event)
{
// small hack to suppress the very first message: by then the logging is
// not yet redirected and so initial setting of the text value results in
// an annoying message box
static bool s_firstTime = true;
if ( s_firstTime )
{
s_firstTime = false;
if ( !IsUsingLogWindow() )
return;
}
wxLogMessage("Text ctrl value changed");
// Replace middle of long text with ellipsis just to avoid filling up the
// log control with too much unnecessary stuff.
wxLogMessage("Text control value changed (now '%s')",
wxControl::Ellipsize
(
event.GetString(),
wxClientDC(this),
wxELLIPSIZE_MIDDLE,
GetTextExtent('W').x*100
));
}
void TextWidgetsPage::OnTextEnter(wxCommandEvent& event)

View File

@@ -139,6 +139,13 @@ const wxChar *WidgetsCategories[MAX_PAGES] = {
class WidgetsApp : public wxApp
{
public:
WidgetsApp()
{
#if USE_LOG
m_logTarget = NULL;
#endif // USE_LOG
}
// override base class virtuals
// ----------------------------
@@ -146,8 +153,20 @@ public:
// initialization (doing it here and not in the ctor allows to have an error
// return: if OnInit() returns false, the application terminates)
virtual bool OnInit() wxOVERRIDE;
// real implementation of WidgetsPage method with the same name
bool IsUsingLogWindow() const;
private:
#if USE_LOG
wxLog* m_logTarget;
#endif // USE_LOG
wxDECLARE_NO_COPY_CLASS(WidgetsApp);
};
wxDECLARE_APP(WidgetsApp); // This provides a convenient wxGetApp() accessor.
// Define a new frame type: this is going to be our main frame
class WidgetsFrame : public wxFrame
{
@@ -375,9 +394,22 @@ bool WidgetsApp::OnInit()
wxFrame *frame = new WidgetsFrame(title + " widgets demo");
frame->Show();
#if USE_LOG
m_logTarget = wxLog::GetActiveTarget();
#endif // USE_LOG
return true;
}
bool WidgetsApp::IsUsingLogWindow() const
{
#if USE_LOG
return wxLog::GetActiveTarget() == m_logTarget;
#else // !USE_LOG
return false;
#endif // USE_LOG
}
// ----------------------------------------------------------------------------
// WidgetsFrame construction
// ----------------------------------------------------------------------------
@@ -1200,8 +1232,13 @@ void WidgetsFrame::OnSetHint(wxCommandEvent& WXUNUSED(event))
void WidgetsFrame::OnWidgetFocus(wxFocusEvent& event)
{
wxLogMessage("Widgets %s focus",
event.GetEventType() == wxEVT_SET_FOCUS ? "got" : "lost");
// Don't show annoying message boxes when starting or closing the sample,
// only log these events in our own logger.
if ( wxGetApp().IsUsingLogWindow() )
{
wxLogMessage("Widgets %s focus",
event.GetEventType() == wxEVT_SET_FOCUS ? "got" : "lost");
}
event.Skip();
}
@@ -1384,3 +1421,9 @@ wxCheckBox *WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer *sizer,
return checkbox;
}
/* static */
bool WidgetsPage::IsUsingLogWindow()
{
return wxGetApp().IsUsingLogWindow();
}

View File

@@ -155,6 +155,10 @@ public:
// the default attributes for the widget
static WidgetAttributes& GetAttrs();
// return true if we're showing logs in the log window (always the case
// except during startup and shutdown)
static bool IsUsingLogWindow();
protected:
// several helper functions for page creation