Add wxHAS_IMAGE_RESOURCES defined under MSW and Mac

Unlike the existing wxHAS_IMAGES_IN_RESOURCES constant defined only
under MSW, the new one is also defined under Mac and could be defined
for the other platforms/ports later (e.g. wxQt could probably support it
too).

It's unfortunate that two very similar constants are needed, but it
doesn't seem wise to change the meaning of the existing constant, as
this would change how the commonly used wxICON() and wxBITMAP() macros
behave and would break all our own samples that use them for their frame
icon but don't embed this icon into the bundle resources under Mac.

Do change the toolbar sample to use the new constant however, as this
one does include the bitmaps it uses in its bundle under Mac.
This commit is contained in:
Vadim Zeitlin
2021-09-22 23:18:16 +01:00
parent 19002a54ad
commit 7043963831
3 changed files with 23 additions and 6 deletions

View File

@@ -194,8 +194,13 @@ Currently the following symbols exist:
@itemdef{wxHAS_NATIVE_WINDOW, Defined if wxNativeWindow class is available.} @itemdef{wxHAS_NATIVE_WINDOW, Defined if wxNativeWindow class is available.}
@itemdef{wxHAS_NOEXCEPT, Defined if the currently used compiler supports C++11 @c noexcept. @c wxNOEXCEPT is defined as this keyword in this case, and as nothing otherwise.} @itemdef{wxHAS_NOEXCEPT, Defined if the currently used compiler supports C++11 @c noexcept. @c wxNOEXCEPT is defined as this keyword in this case, and as nothing otherwise.}
@itemdef{wxHAS_NULLPTR_T, Defined if the currently used compiler supports C++11 @c nullptr.} @itemdef{wxHAS_NULLPTR_T, Defined if the currently used compiler supports C++11 @c nullptr.}
@itemdef{wxHAS_IMAGE_RESOURCES, Defined if images can be embedded into the
program as resources, i.e. without being defined in the program text
itself. This is currently the case for MSW and Mac platforms. This constant
is available since wxWidgets 3.1.6.}
@itemdef{wxHAS_IMAGES_IN_RESOURCES, Defined if <a href="http://en.wikipedia.org/wiki/Resource_(Windows)"> @itemdef{wxHAS_IMAGES_IN_RESOURCES, Defined if <a href="http://en.wikipedia.org/wiki/Resource_(Windows)">
Windows resource files</a> or OS/2 resource files are available on the current platform.} Windows resource files</a> resource files are available on the current platform.
Usually wxHAS_IMAGE_RESOURCES should be used instead.}
@itemdef{wxHAS_POWER_EVENTS, Defined if wxPowerEvent are ever generated on the current platform.} @itemdef{wxHAS_POWER_EVENTS, Defined if wxPowerEvent are ever generated on the current platform.}
@itemdef{wxHAS_RADIO_MENU_ITEMS, @itemdef{wxHAS_RADIO_MENU_ITEMS,
Defined if the current port supports radio menu items (see wxMenu::AppendRadioItem).} Defined if the current port supports radio menu items (see wxMenu::AppendRadioItem).}

View File

@@ -183,10 +183,19 @@ enum wxEllipsizeMode
// macros // macros
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// The difference between wxHAS_IMAGES_IN_RESOURCES and wxHAS_IMAGE_RESOURCES
// is that the former is, historically, only defined under MSW while the latter
// is also defined under macOS, which uses a different resource concept, and
// may be also defined for any other ports where images don't need to be
// embedded into the program text in order to be available during run-time.
#if defined(__WINDOWS__) && wxUSE_WXDIB #if defined(__WINDOWS__) && wxUSE_WXDIB
#define wxHAS_IMAGES_IN_RESOURCES #define wxHAS_IMAGES_IN_RESOURCES
#endif #endif
#if defined(wxHAS_IMAGES_IN_RESOURCES) || defined(__WXOSX__)
#define wxHAS_IMAGE_RESOURCES
#endif
/* Useful macro for creating icons portably, for example: /* Useful macro for creating icons portably, for example:
wxIcon *icon = new wxICON(sample); wxIcon *icon = new wxICON(sample);
@@ -256,7 +265,7 @@ enum wxEllipsizeMode
// resource type and under OS X the PNG file with the specified name must be // resource type and under OS X the PNG file with the specified name must be
// available in the resource subdirectory of the bundle. Elsewhere, this is // available in the resource subdirectory of the bundle. Elsewhere, this is
// exactly the same thing as wxBITMAP_PNG_FROM_DATA() described above. // exactly the same thing as wxBITMAP_PNG_FROM_DATA() described above.
#if (defined(__WINDOWS__) && wxUSE_WXDIB) || defined(__WXOSX__) #ifdef wxHAS_IMAGE_RESOURCES
#define wxBITMAP_PNG(name) wxBitmap(wxS(#name), wxBITMAP_TYPE_PNG_RESOURCE) #define wxBITMAP_PNG(name) wxBitmap(wxS(#name), wxBITMAP_TYPE_PNG_RESOURCE)
#else #else
#define wxBITMAP_PNG(name) wxBITMAP_PNG_FROM_DATA(name) #define wxBITMAP_PNG(name) wxBITMAP_PNG_FROM_DATA(name)

View File

@@ -44,12 +44,15 @@
// resources // resources
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Under Windows, PNG files are embedded as resources, see toolbar.rc, but // We don't embed this item in the resources under Mac, so we need to still use
// elsewhere we embed them in the program itself. We could also load them // the XPM there.
// during run-time.
#ifndef wxHAS_IMAGES_IN_RESOURCES #ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm" #include "../sample.xpm"
#endif // !wxHAS_IMAGES_IN_RESOURCES
// If PNG files are not available in resources, we need to embed them in the
// program itself. We could also load them during run-time.
#ifndef wxHAS_IMAGE_RESOURCES
#include "bitmaps/new_png.c" #include "bitmaps/new_png.c"
#include "bitmaps/open_png.c" #include "bitmaps/open_png.c"
#include "bitmaps/save_png.c" #include "bitmaps/save_png.c"
@@ -67,7 +70,7 @@
#include "bitmaps/paste_2x_png.c" #include "bitmaps/paste_2x_png.c"
#include "bitmaps/print_2x_png.c" #include "bitmaps/print_2x_png.c"
#include "bitmaps/help_2x_png.c" #include "bitmaps/help_2x_png.c"
#endif // !wxHAS_IMAGES_IN_RESOURCES #endif // !wxHAS_IMAGE_RESOURCES
enum Positions enum Positions
{ {