Files
OrcaSlicer/tests/slic3rutils/test_labeled_static_box.cpp
gaishnik94-ship-it ab3a33b77d Fix Windows group-box painting over calibration controls (#18008)
LabeledStaticBox's paint handler on Windows replaces wxStaticBox::OnPaint, which also removed wx's clipping of the controls inside the box. In the calibration dialogs those controls are siblings of the box, so the box painted over them until they were hovered.

PickDC now clips the paint DC to MSWGetRegionWithoutChildren(), converted from screen to window coordinates, which is the same region wx's own paint uses. A new Windows test checks the clip region after a repaint, and again after the dialog moves and a hidden control is shown. The orca-wxwidgets painting reference now describes the clipping.

(cherry picked from commit e9f96a9245)
2026-12-02 13:24:10 -06:00

78 lines
3.0 KiB
C++

#include <catch2/catch_test_macros.hpp>
#ifdef __WXMSW__
#include "slic3r/GUI/Widgets/LabeledStaticBox.hpp"
#include <wx/app.h>
#include <wx/dc.h>
#include <wx/dcclient.h>
#include <wx/defs.h>
#include <wx/dialog.h>
#include <wx/event.h>
#include <wx/gdicmn.h>
#include <wx/init.h>
#include <wx/msw/wrapwin.h>
#include <wx/region.h>
#include <wx/window.h>
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<HDC>(dc.GetHDC()), region);
captured_region = wxRegion(reinterpret_cast<WXHRGN>(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