Opened 6 years ago

Closed 6 years ago

#13184 closed defect (fixed)

wxBORDER_THEME can result in negative size client area

Reported by: snowleopard2 Owned by:
Priority: normal Milestone:
Component: wxMSW Version: stable-latest
Keywords: wxScrolled Cc:
Blocked By: Blocking:
Patch: yes

Description

Run the following example:

wxScrolledCanvas* sc = new wxScrolledCanvas(wxTheApp->GetTopWindow(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_THEME);
sc->SetSize(wxSize(1,1));
wxSize sz = sc->GetClientSize();//-3, -3?

wxScrolledWindow* sw = new wxScrolledWindow(wxTheApp->GetTopWindow(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_THEME);
sw->SetSize(wxSize(1,1));
wxSize sz2 = sw->GetClientSize();//-3, -3?

Look at the values of sz and sz2. Simply calling SetSize(1,1) causes a wxScrolled<> to have a client size of (-3, -3).

If you remove the wxBORDER_THEME flag then it works fine.

Attachments (2)

fix.diff download (474 bytes) - added by snowleopard2 6 years ago.
Fix
unittest.diff download (1.6 KB) - added by snowleopard2 6 years ago.
unit test

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by snowleopard2

  • Summary changed from wxScrolled<> + wxBORDER_THEME can result in negative size client area to wxBORDER_THEME can result in negative size client area

Actually, this happens with any window:

wxWindow* w = new wxWindow(wxTheApp->GetTopWindow(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_THEME);
w->SetSize(wxSize(1,1));
wxSize szw = w->GetClientSize();//-3, -3

wxWindow* wNoThemeBorder = new wxWindow(wxTheApp->GetTopWindow(), -1, wxDefaultPosition, wxDefaultSize);
wNoThemeBorder->SetSize(wxSize(1,1));
wxSize szwNoThemeBorder = wNoThemeBorder->GetClientSize();//OK, (1,1)

I'm on XP SP3.

comment:2 Changed 6 years ago by snowleopard2

::GetClientRect is where it happens, so it must be a Windows quirk.

I step into "RECT wxGetClientRect(HWND hwnd)" in private.h, and ::GetClientRect is returning these negative values.

comment:3 Changed 6 years ago by vadz

We should probably just clump them to 0 forcefully in wxWindow::DoGetClientSize() then. It would be useful to have a unit test checking that a window of size 1x1 has non-negative client size, too.

comment:4 Changed 6 years ago by snowleopard2

  • Patch set

Attached patch adds logic to DoGetClientSize to change negative dimensions to zero.

Also attaching patch to add ClientSizeTestCase::ClientSizeNotNegative() unit test, which passes only after this patch is applied.

Changed 6 years ago by snowleopard2

Fix

Changed 6 years ago by snowleopard2

unit test

comment:5 Changed 6 years ago by snowleopard2

Don't mean to be a pest, but could this patch be included in 2.9.2? TIA.

comment:6 Changed 6 years ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [67754]) Ensure that we never return negative client size.

wxMSW could return negative client size for tiny windows with borders, this
was unexpected and shouldn't happen so explicitly ensure it does not.

Also add a unit test to check that this problem doesn't exist in other ports.

Closes #13184.

Note: See TracTickets for help on using tickets.