2

I am using an .xrc file to setup my wxWidgets GUI. For most GUI elements I can specify <hidden>1</hidden> and the element will not be drawn.

What I'd like is to be able to hide my wxStaticBoxSizer and have it and its contents not be drawn.

It's set up as follows, but adding <hidden>1</hidden> does not have any effect. The static box still draws as does everything it contains.

<object class="wxStaticBoxSizer" name="wxID_ANY">
    <orient>wxVERTICAL</orient>
    <label>Flight Formation</label>
    <object class="sizeritem">
    <flag>wxGROW|wxALL</flag>
    <border>10</border>
    <option>1</option>

Is it possible to hide this wxStaticBoxSizer from the .xrc file?

bogdan
  • 9,229
  • 2
  • 33
  • 48
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • Since sizers don't seem to have that attribute in XRC, I would try to nest the sizer inside a `wxPanel` and hide the panel. Does that work for you? – bogdan Sep 22 '15 at 17:02
  • @bogdan Yeah nesting it is my go to solution. But it sure seems like a hack. In lieu of other answers that's probably the correct one though. If you feel like typing it up I'll accept. – Jonathan Mee Sep 22 '15 at 18:39
  • Are you up for some hacking? With a very simple patch (two lines of code in one file), you can get what you want, but you'll have to rebuild the XRC lib. Interested? It would be useful if you could test this in a real project (I only tested it for `wxBoxSizer` and `wxStaticBoxSizer` using wx's XRC sample). – bogdan Sep 22 '15 at 22:41
  • @bogdan No lie, that sounds very intimidating. I'm using stock wxWidgets and I think I'd prefer to keep it that way. That said if your up to writing it into an answer that may be very helpful to future readers. – Jonathan Mee Sep 23 '15 at 00:52
  • 1
    I've sent a [pull request](https://github.com/wxWidgets/wxWidgets/pull/102) with the necessary changes. With a bit of luck, the feature could be there in a future version. – bogdan Sep 23 '15 at 19:52

2 Answers2

3

Quick hack: nest the sizer inside a wxPanel and hide the panel.


If you're willing to rebuild the XRC lib, here's a quick patch that will provide the functionality you need.

In src/xrc/xh_sizer.cpp, in the body of wxSizerXmlHandler::Handle_sizer(), add the following right after the call to CreateChildren(parent, true/*only this handler*/);:

// This has to be done after CreateChildren().
if(GetBool(wxT("hideitems"), 0) == 1)
   sizer->ShowItems(false);

That's it. Rebuild the lib, and now you can specify <hideitems>1</hideitems> on a sizer, which means it will be created with all its items hidden.

This will handle all sizers except wxStdDialogButtonSizer, which has separate code. I tested it for wxBoxSizer and wxStaticBoxSizer using the XRC sample. I think I'll send a pull request to add this feature to wx; in the mean time, if anyone could do some more testing on this using a larger application, that would be great.

bogdan
  • 9,229
  • 2
  • 33
  • 48
  • 1
    Thanks for your PR, it is now [merged](https://github.com/wxWidgets/wxWidgets/commit/b2c3ad614f3bb6a58058c06c1f7f547c74c636ff), so you don't have to rebuild XRC manually any more if you're using the latest master (or can wait for 3.1.0 release). – VZ. Sep 24 '15 at 12:52
2

There is no way to hide the sizer in the XRC currently, the best you can do is to call wxSizer::ShowItems() from the code. It probably would make sense to support the "hidden" attribute for the sizers too in the future, although it should probably be called something else to avoid creating the erroneous impression that sizers are windows (which they aren't).

BTW, if you tried to validate your XRC, you would have found out that "hidden" element is not allowed here.

VZ.
  • 21,740
  • 3
  • 39
  • 42