Merge branch 'fix-caret-default'

Fix using default-constructed wxCaret.

See https://github.com/wxWidgets/wxWidgets/pull/2007
This commit is contained in:
Vadim Zeitlin
2020-10-01 02:29:43 +02:00
3 changed files with 21 additions and 4 deletions

View File

@@ -153,6 +153,7 @@ protected:
m_window = window; m_window = window;
m_width = width; m_width = width;
m_height = height; m_height = height;
DoSize();
return true; return true;
} }

View File

@@ -103,7 +103,8 @@ void wxCaret::InitGeneric()
#ifndef wxHAS_CARET_USING_OVERLAYS #ifndef wxHAS_CARET_USING_OVERLAYS
m_xOld = m_xOld =
m_yOld = -1; m_yOld = -1;
m_bmpUnderCaret.Create(m_width, m_height); if (m_width && m_height)
m_bmpUnderCaret.Create(m_width, m_height);
#endif #endif
} }
@@ -174,7 +175,10 @@ void wxCaret::DoSize()
m_overlay.Reset(); m_overlay.Reset();
#else #else
// Change bitmap size // Change bitmap size
m_bmpUnderCaret = wxBitmap(m_width, m_height); if (m_width && m_height)
m_bmpUnderCaret = wxBitmap(m_width, m_height);
else
m_bmpUnderCaret = wxBitmap();
#endif #endif
if (countVisible > 0) if (countVisible > 0)
{ {

View File

@@ -136,10 +136,22 @@ TEST_CASE_METHOD(WindowTestCase, "Window::Mouse", "[window]")
CHECK(m_window->GetCursor().IsOk()); CHECK(m_window->GetCursor().IsOk());
#if wxUSE_CARET #if wxUSE_CARET
//A plain window doesn't have a caret
CHECK(!m_window->GetCaret()); CHECK(!m_window->GetCaret());
wxCaret* caret = new wxCaret(m_window, 16, 16); wxCaret* caret;
// Try creating the caret in two different, but normally equivalent, ways.
SECTION("Caret 1-step")
{
caret = new wxCaret(m_window, 16, 16);
}
SECTION("Caret 2-step")
{
caret = new wxCaret();
caret->Create(m_window, 16, 16);
}
m_window->SetCaret(caret); m_window->SetCaret(caret);
CHECK(m_window->GetCaret()->IsOk()); CHECK(m_window->GetCaret()->IsOk());