Add support for XRC "feature" attribute

This is a generalization of the existing "platform" attribute and allows
to only include some XRC elements if and only if an arbitrary "feature"
is enabled by the application before loading the XRC document.
This commit is contained in:
Vadim Zeitlin 2023-01-29 00:53:11 +00:00
parent 8139d8d3b7
commit 3fdebc96cd
5 changed files with 121 additions and 3 deletions

View file

@ -257,6 +257,33 @@ TEST_CASE("XRC::PathWithFragment", "[xrc][uri]")
CHECK( !wxXmlResource::Get()->LoadBitmap("bad").IsOk() );
}
TEST_CASE("XRC::Features", "[xrc]")
{
auto& xrc = *wxXmlResource::Get();
xrc.EnableFeature("European");
xrc.EnableFeature("African");
// Not all birds are available in all geographic editions of this program.
LoadXrcFrom(R"(<?xml version="1.0" ?>
<resource>
<object class="wxFrame" name="pigeon"/> <!-- Those are everywhere -->
<object class="wxFrame" name="eagle" feature="American"/>
<object class="wxFrame" name="rooster" feature="European"/>
<object class="wxFrame" name="swallow" feature="African"/>
<object class="wxFrame" name="sparrow" feature="American|European"/>
<object class="wxFrame" name="dodo" feature="African|extinct"/>
</resource>
)");
CHECK( xrc.LoadFrame(nullptr, "pigeon") );
CHECK(!xrc.LoadFrame(nullptr, "eagle") );
CHECK( xrc.LoadFrame(nullptr, "rooster") );
CHECK( xrc.LoadFrame(nullptr, "sparrow") );
CHECK( xrc.LoadFrame(nullptr, "swallow") );
CHECK( xrc.LoadFrame(nullptr, "dodo") );
}
TEST_CASE("XRC::EnvVarInPath", "[xrc]")
{
wxStringInputStream sis(