Opened 5 years ago

Closed 5 years ago

#17410 closed defect (fixed)

wxCocoa: wxStaticBoxSizer with no label uses default label and messes up layout

Reported by: afalkenhahn Owned by: disc
Priority: normal Milestone:
Component: wxOSX Version: dev-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: yes

Description

When creating a wxStaticBoxSizer without a label, wxWidgets automatically uses the label "Title" for it instead of creating an unlabelled box sizer. Even worse, the layout is also somewhat messed up (checkboxes are not aligned correctly).

Attached is a patch against the widgets sample that demonstrates the issue. Also take a look at the screenshots to see the messed up layout when creating an unlabelled wxStaticBoxSizer (just compare the leftmost wxStaticBoxSizers in both screenshots)


Attachments (5)

with_label.png download (112.5 KB) - added by afalkenhahn 5 years ago.
without_label.png download (112.3 KB) - added by afalkenhahn 5 years ago.
mypatch.patch download (483 bytes) - added by afalkenhahn 5 years ago.
mypatch.2.patch download (1.0 KB) - added by afalkenhahn 5 years ago.
Bugfix for this issue
Fix-Cocoa-display-of-wxStaticBox-with-empty-label.patch download (989 bytes) - added by neil_mayhew 5 years ago.
An alternative way to fix the problem

Download all attachments as: .zip

Change History (14)

Changed 5 years ago by afalkenhahn

Changed 5 years ago by afalkenhahn

comment:1 Changed 5 years ago by afalkenhahn

Sorry, ignore the first patch. I made a mistake there. Just use the second patch please.

Changed 5 years ago by afalkenhahn

comment:2 Changed 5 years ago by afalkenhahn

  • Patch set

Here is a fix for this bug. The problem is that SetPeer() doesn't call SetLabel() for empty labels. Hence, setTitlePosition:NSNoTitle is never called. I've now modified CreateGroupBox() to do this job in case the label text is empty. Patch attached. Tested and working.

Changed 5 years ago by afalkenhahn

Bugfix for this issue

comment:3 Changed 5 years ago by Spoek

Wrote a little fix tol make sure the wxCocoa port sets the label on creation.

/src/osx/cocoa/statbox.mm

@@ -63,7 +63,7 @@ namespace
 wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer,
                                     wxWindowMac* WXUNUSED(parent),
                                     wxWindowID WXUNUSED(id),
-                                    const wxString& WXUNUSED(label),
+                                    const wxString& label,
                                     const wxPoint& pos,
                                     const wxSize& size,
                                     long WXUNUSED(style),
@@ -78,6 +78,7 @@ wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer,
 #if !wxOSX_USE_NATIVE_FLIPPED
     c->SetFlipped(false);
 #endif
+    c->SetLabel(label, wxFONTENCODING_DEFAULT);
 
     return c;
 }

Changed 5 years ago by neil_mayhew

An alternative way to fix the problem

comment:4 Changed 5 years ago by neil_mayhew

#17478 seems to be a duplicate

comment:5 Changed 5 years ago by disc

  • Owner set to disc
  • Status changed from new to accepted

comment:6 Changed 5 years ago by johnr

Neil, your Fix-Cocoa-display-of-wxStaticBox-with-empty-label.patch​ would work but would also revert the following commit and reintroduce the problem it fixed.

https://github.com/wxWidgets/wxWidgets/commit/db9baf9aa5565a7a4f92097b2f0c85439c35b4a6

comment:7 follow-up: Changed 5 years ago by afalkenhahn

Mmhhh... so why not use my patch? We have now three patches for this issue. Mine was the first and even 2 months ago. I'm confused why people are constantly adding new patches here without any comments on what is wrong with the other patches? And if there isn't anything wrong with my initial patch, why not just apply it and close the issue?

comment:8 in reply to: ↑ 7 Changed 5 years ago by disc

Replying to afalkenhahn:

Mmhhh... so why not use my patch?

Because unfortunately it doesn't work 100% correctly. Internally the title still is "Title", it just doesn't get shown. Spoek's patch comes closer to what I have in mind. The reason I didn't comment yet is that I was hoping for a different solution, as this is not the only control that is still affected. Sorry for not putting that link here earlier.

comment:9 Changed 5 years ago by disc

  • Resolution set to fixed
  • Status changed from accepted to closed
Note: See TracTickets for help on using tickets.