#include #ifdef __WXMSW__ #include "slic3r/GUI/Widgets/LabeledStaticBox.hpp" #include #include #include #include #include #include #include #include #include #include #include TEST_CASE("Group-box repainting preserves visible controls and repaints hidden-control space", "[LabeledStaticBox]") { if (wxTheApp == nullptr) wxApp::SetInstance(new wxApp); wxInitializer init; REQUIRE(init.IsOk()); wxDialog dialog(nullptr, wxID_ANY, "Group-box painting", wxPoint(150, 180), wxSize(320, 280)); auto* box = new LabeledStaticBox(&dialog, "Settings", wxPoint(20, 20), wxSize(260, 200)); auto* sibling = new wxWindow(&dialog, wxID_ANY, wxPoint(60, 80), wxSize(50, 25)); auto* child = new wxWindow(box, wxID_ANY, wxPoint(130, 100), wxSize(50, 25)); auto* hidden = new wxWindow(&dialog, wxID_ANY, wxPoint(60, 150), wxSize(50, 25)); hidden->Hide(); // Inspect the actual paint DC after the custom handler has run. Unlike a // screenshot, GetClipRgn does not depend on other windows covering the test. wxRegion captured_region; int capture_status = 0; wxEvtHandler probe; probe.Bind(wxEVT_PAINT, [&](wxPaintEvent& event) { wxPaintDC dc(box); probe.GetNextHandler()->ProcessEvent(event); const HRGN region = ::CreateRectRgn(0, 0, 0, 0); capture_status = ::GetClipRgn(reinterpret_cast(dc.GetHDC()), region); captured_region = wxRegion(reinterpret_cast(region)); event.Skip(false); }); const auto repaint = [&] { capture_status = 0; box->PushEventHandler(&probe); box->Refresh(false); box->Update(); box->PopEventHandler(); }; dialog.ShowWithoutActivating(); repaint(); REQUIRE(capture_status == 1); const auto center_in_box = [box](wxWindow* control) { const wxRect rect = control->GetScreenRect(); return rect.GetPosition() + wxPoint(rect.width / 2, rect.height / 2) - box->GetScreenPosition(); }; CHECK(captured_region.Contains(center_in_box(sibling)) == wxOutRegion); CHECK(captured_region.Contains(center_in_box(child)) == wxOutRegion); CHECK(captured_region.Contains(center_in_box(hidden)) == wxInRegion); CHECK(captured_region.Contains(wxPoint(10, 30)) == wxInRegion); // Moving the dialog changes the screen coordinates. Showing another control // must exclude it on the next paint without retaining the old clip region. dialog.Move(wxPoint(350, 320)); hidden->Show(); repaint(); REQUIRE(capture_status == 1); CHECK(captured_region.Contains(center_in_box(sibling)) == wxOutRegion); CHECK(captured_region.Contains(center_in_box(child)) == wxOutRegion); CHECK(captured_region.Contains(center_in_box(hidden)) == wxOutRegion); CHECK(captured_region.Contains(wxPoint(10, 30)) == wxInRegion); } #endif