From 97f6c85d9bb9d11c4d635f0422b1fc8d6cb11509 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 24 Sep 2021 00:35:06 +0100 Subject: [PATCH 01/18] Add first version of wxBitmapBundle and use it in wxToolBar This first version provides only a generic implementation of wxBitmapBundle using a collection of bitmaps and only supports using it in wxToolBar in wxMSW and wxGTK. More methods of creating wxBitmapBundle will be provided later and more functions taking wxBitmap will be changed to take wxBitmapBundle later too and, of course, all the other ports will be updated to use the new API too. --- Makefile.in | 37 ++++- build/bakefiles/files.bkl | 2 + build/cmake/files.cmake | 2 + build/files | 2 + build/msw/makefile.gcc | 44 ++++- build/msw/makefile.vc | 44 ++++- build/msw/wx_core.vcxproj | 2 + build/msw/wx_core.vcxproj.filters | 6 + build/msw/wx_vc8_core.vcproj | 8 + build/msw/wx_vc9_core.vcproj | 8 + include/wx/bmpbndl.h | 120 ++++++++++++++ include/wx/gtk/toolbar.h | 8 +- include/wx/gtk1/toolbar.h | 4 +- include/wx/motif/toolbar.h | 4 +- include/wx/msw/toolbar.h | 8 +- include/wx/private/bmpbndl.h | 37 +++++ include/wx/qt/toolbar.h | 8 +- include/wx/tbarbase.h | 53 +++--- include/wx/univ/toolbar.h | 4 +- include/wx/wx.h | 1 + interface/wx/bmpbndl.h | 179 ++++++++++++++++++++ interface/wx/toolbar.h | 40 ++--- samples/toolbar/toolbar.cpp | 60 +++---- src/common/bmpbndl.cpp | 261 ++++++++++++++++++++++++++++++ src/common/tbarbase.cpp | 8 +- src/gtk/toolbar.cpp | 12 +- src/gtk1/toolbar.cpp | 8 +- src/motif/toolbar.cpp | 8 +- src/msw/toolbar.cpp | 50 +++--- src/qt/toolbar.cpp | 12 +- src/univ/toolbar.cpp | 8 +- 31 files changed, 874 insertions(+), 174 deletions(-) create mode 100644 include/wx/bmpbndl.h create mode 100644 include/wx/private/bmpbndl.h create mode 100644 interface/wx/bmpbndl.h create mode 100644 src/common/bmpbndl.cpp diff --git a/Makefile.in b/Makefile.in index 73bc043727..e580468523 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4049,6 +4049,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \ wx/propdlg.h \ wx/generic/creddlgg.h \ wx/creddlg.h \ + wx/bmpbndl.h \ $(LOWLEVEL_HDR) \ $(GUI_CORE_HEADERS) \ wx/mediactrl.h \ @@ -4709,7 +4710,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS = \ monodll_laywin.o \ monodll_calctrlg.o \ monodll_creddlgg.o \ - monodll_rowheightcache.o + monodll_rowheightcache.o \ + monodll_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS = \ $(__LOWLEVEL_SRC_OBJECTS_1) \ @@ -4971,7 +4973,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS = \ monodll_laywin.o \ monodll_calctrlg.o \ monodll_creddlgg.o \ - monodll_rowheightcache.o + monodll_rowheightcache.o \ + monodll_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS = \ monodll_fontmgrcmn.o \ @@ -6705,7 +6708,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_1 = \ monolib_laywin.o \ monolib_calctrlg.o \ monolib_creddlgg.o \ - monolib_rowheightcache.o + monolib_rowheightcache.o \ + monolib_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_1 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_1) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1 = \ $(__LOWLEVEL_SRC_OBJECTS_3) \ @@ -6967,7 +6971,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1 = \ monolib_laywin.o \ monolib_calctrlg.o \ monolib_creddlgg.o \ - monolib_rowheightcache.o + monolib_rowheightcache.o \ + monolib_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_1 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_2 = \ monolib_fontmgrcmn.o \ @@ -8854,7 +8859,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_2 = \ coredll_laywin.o \ coredll_calctrlg.o \ coredll_creddlgg.o \ - coredll_rowheightcache.o + coredll_rowheightcache.o \ + coredll_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_2 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_2) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2 = \ $(__LOWLEVEL_SRC_OBJECTS_5) \ @@ -9116,7 +9122,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2 = \ coredll_laywin.o \ coredll_calctrlg.o \ coredll_creddlgg.o \ - coredll_rowheightcache.o + coredll_rowheightcache.o \ + coredll_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_2 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_4 = \ coredll_fontmgrcmn.o \ @@ -10579,7 +10586,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_3 = \ corelib_laywin.o \ corelib_calctrlg.o \ corelib_creddlgg.o \ - corelib_rowheightcache.o + corelib_rowheightcache.o \ + corelib_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_3 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_3) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3 = \ $(__LOWLEVEL_SRC_OBJECTS_7) \ @@ -10841,7 +10849,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3 = \ corelib_laywin.o \ corelib_calctrlg.o \ corelib_creddlgg.o \ - corelib_rowheightcache.o + corelib_rowheightcache.o \ + corelib_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_3 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_6 = \ corelib_fontmgrcmn.o \ @@ -21014,6 +21023,9 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@monodll_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp +@COND_USE_GUI_1@monodll_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONODLL_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp + @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@monodll_osx_cocoa_mediactrl.o: $(srcdir)/src/osx/cocoa/mediactrl.mm $(MONODLL_ODEP) @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/mediactrl.mm @@ -26303,6 +26315,9 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@monolib_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp +@COND_USE_GUI_1@monolib_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONOLIB_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp + @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@monolib_osx_cocoa_mediactrl.o: $(srcdir)/src/osx/cocoa/mediactrl.mm $(MONOLIB_ODEP) @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/mediactrl.mm @@ -31697,6 +31712,9 @@ coredll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(COREDLL_ODEP) @COND_USE_GUI_1@coredll_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(COREDLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp +@COND_USE_GUI_1@coredll_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(COREDLL_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp + corelib_event.o: $(srcdir)/src/common/event.cpp $(CORELIB_ODEP) $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/event.cpp @@ -35951,6 +35969,9 @@ corelib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(CORELIB_ODEP) @COND_USE_GUI_1@corelib_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(CORELIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp +@COND_USE_GUI_1@corelib_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(CORELIB_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp + advdll_version_rc.o: $(srcdir)/src/msw/version.rc $(ADVDLL_ODEP) $(WINDRES) -i$< -o$@ $(__INC_TIFF_BUILD_p_54) $(__INC_TIFF_p_54) $(__INC_JPEG_p_54) $(__INC_PNG_p_53) $(__INC_ZLIB_p_67) $(__INC_REGEX_p_65) $(__INC_EXPAT_p_65) --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_66) $(__DEBUG_DEFINE_p_66) $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65) --define WXBUILDING --define WXDLLNAME=$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_adv$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG) $(__RCDEFDIR_p) --include-dir $(top_srcdir)/include --define WXUSINGDLL --define WXMAKINGDLL_ADV diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 20f690cf12..a4d673f43a 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1015,6 +1015,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/generic/calctrlg.cpp src/generic/creddlgg.cpp src/generic/rowheightcache.cpp + src/common/bmpbndl.cpp wx/affinematrix2dbase.h @@ -1306,6 +1307,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/propdlg.h wx/generic/creddlgg.h wx/creddlg.h + wx/bmpbndl.h diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index 8e5bee9963..b0ff257df4 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -918,6 +918,7 @@ set(GUI_CMN_SRC src/generic/creddlgg.cpp src/generic/rowheightcache.cpp src/generic/animateg.cpp + src/common/bmpbndl.cpp ) set(GUI_CMN_HDR @@ -1209,6 +1210,7 @@ set(GUI_CMN_HDR wx/creddlg.h wx/generic/creddlgg.h wx/generic/animate.h + wx/bmpbndl.h ) set(UNIX_SRC diff --git a/build/files b/build/files index 66277ee757..e8584a4cd6 100644 --- a/build/files +++ b/build/files @@ -741,6 +741,7 @@ GUI_CMN_SRC = src/common/artstd.cpp src/common/arttango.cpp src/common/bmpbase.cpp + src/common/bmpbndl.cpp src/common/bmpbtncmn.cpp src/common/bmpcboxcmn.cpp src/common/bookctrl.cpp @@ -950,6 +951,7 @@ GUI_CMN_HDR = wx/artprov.h wx/bannerwindow.h wx/bitmap.h + wx/bmpbndl.h wx/bmpbuttn.h wx/bmpcbox.h wx/bookctrl.h diff --git a/build/msw/makefile.gcc b/build/msw/makefile.gcc index fcb8ae9aa3..438b69dd16 100644 --- a/build/msw/makefile.gcc +++ b/build/msw/makefile.gcc @@ -2201,7 +2201,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_laywin.o \ $(OBJS)\monodll_calctrlg.o \ $(OBJS)\monodll_creddlgg.o \ - $(OBJS)\monodll_rowheightcache.o + $(OBJS)\monodll_rowheightcache.o \ + $(OBJS)\monodll_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -2531,7 +2532,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_laywin.o \ $(OBJS)\monodll_calctrlg.o \ $(OBJS)\monodll_creddlgg.o \ - $(OBJS)\monodll_rowheightcache.o + $(OBJS)\monodll_rowheightcache.o \ + $(OBJS)\monodll_bmpbndl.o endif endif ifeq ($(USE_STC),1) @@ -3043,7 +3045,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_laywin.o \ $(OBJS)\monolib_calctrlg.o \ $(OBJS)\monolib_creddlgg.o \ - $(OBJS)\monolib_rowheightcache.o + $(OBJS)\monolib_rowheightcache.o \ + $(OBJS)\monolib_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -3373,7 +3376,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_laywin.o \ $(OBJS)\monolib_calctrlg.o \ $(OBJS)\monolib_creddlgg.o \ - $(OBJS)\monolib_rowheightcache.o + $(OBJS)\monolib_rowheightcache.o \ + $(OBJS)\monolib_bmpbndl.o endif endif ifeq ($(USE_STC),1) @@ -3768,7 +3772,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_laywin.o \ $(OBJS)\coredll_calctrlg.o \ $(OBJS)\coredll_creddlgg.o \ - $(OBJS)\coredll_rowheightcache.o + $(OBJS)\coredll_rowheightcache.o \ + $(OBJS)\coredll_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -4098,7 +4103,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_laywin.o \ $(OBJS)\coredll_calctrlg.o \ $(OBJS)\coredll_creddlgg.o \ - $(OBJS)\coredll_rowheightcache.o + $(OBJS)\coredll_rowheightcache.o \ + $(OBJS)\coredll_bmpbndl.o endif endif ifeq ($(MONOLITHIC),0) @@ -4451,7 +4457,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_laywin.o \ $(OBJS)\corelib_calctrlg.o \ $(OBJS)\corelib_creddlgg.o \ - $(OBJS)\corelib_rowheightcache.o + $(OBJS)\corelib_rowheightcache.o \ + $(OBJS)\corelib_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -4781,7 +4788,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_laywin.o \ $(OBJS)\corelib_calctrlg.o \ $(OBJS)\corelib_creddlgg.o \ - $(OBJS)\corelib_rowheightcache.o + $(OBJS)\corelib_rowheightcache.o \ + $(OBJS)\corelib_bmpbndl.o endif endif ifeq ($(SHARED),1) @@ -9456,6 +9464,11 @@ $(OBJS)\monodll_rowheightcache.o: ../../src/generic/rowheightcache.cpp $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\monodll_bmpbndl.o: ../../src/common/bmpbndl.cpp + $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\monodll_version_rc.o: ../../src/msw/version.rc $(WINDRES) -i$< -o$@ --include-dir ../../src/tiff/libtiff --include-dir ../../src/jpeg --include-dir ../../src/png --include-dir ../../src/zlib --include-dir ../../3rdparty/pcre/src/wx --include-dir ../../src/expat/expat/lib --define __WXMSW__ $(__WXUNIV_DEFINE_p_66) $(__DEBUG_DEFINE_p_66) $(__NDEBUG_DEFINE_p_65) $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65) $(__UNICODE_DEFINE_p_67) --include-dir $(SETUPHDIR) --include-dir ../../include $(__CAIRO_INCLUDEDIR_p) --define WXBUILDING --define WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)$(WXCOMPILER)$(VENDORTAG) --include-dir ../../src/stc/scintilla/include --include-dir ../../src/stc/scintilla/lexlib --include-dir ../../src/stc/scintilla/src --define __WX__ --define SCI_LEXER --define NO_CXX11_REGEX --define LINK_LEXERS --define wxUSE_BASE=1 --define WXMAKINGDLL @@ -12030,6 +12043,11 @@ $(OBJS)\monolib_rowheightcache.o: ../../src/generic/rowheightcache.cpp $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\monolib_bmpbndl.o: ../../src/common/bmpbndl.cpp + $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\basedll_dummy.o: ../../src/common/dummy.cpp $(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $< @@ -14577,6 +14595,11 @@ $(OBJS)\coredll_rowheightcache.o: ../../src/generic/rowheightcache.cpp $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\coredll_bmpbndl.o: ../../src/common/bmpbndl.cpp + $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\corelib_dummy.o: ../../src/common/dummy.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< @@ -16317,6 +16340,11 @@ $(OBJS)\corelib_rowheightcache.o: ../../src/generic/rowheightcache.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\corelib_bmpbndl.o: ../../src/common/bmpbndl.cpp + $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\advdll_dummy.o: ../../src/common/dummy.cpp $(CXX) -c -o $@ $(ADVDLL_CXXFLAGS) $(CPPDEPS) $< diff --git a/build/msw/makefile.vc b/build/msw/makefile.vc index e8fd66a266..8eafa88214 100644 --- a/build/msw/makefile.vc +++ b/build/msw/makefile.vc @@ -2531,7 +2531,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_laywin.obj \ $(OBJS)\monodll_calctrlg.obj \ $(OBJS)\monodll_creddlgg.obj \ - $(OBJS)\monodll_rowheightcache.obj + $(OBJS)\monodll_rowheightcache.obj \ + $(OBJS)\monodll_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_OBJECTS = \ @@ -2859,7 +2860,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_laywin.obj \ $(OBJS)\monodll_calctrlg.obj \ $(OBJS)\monodll_creddlgg.obj \ - $(OBJS)\monodll_rowheightcache.obj + $(OBJS)\monodll_rowheightcache.obj \ + $(OBJS)\monodll_bmpbndl.obj !endif !if "$(USE_STC)" == "1" ____MONOLIB_STC_SRC_FILENAMES_OBJECTS = \ @@ -3373,7 +3375,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_laywin.obj \ $(OBJS)\monolib_calctrlg.obj \ $(OBJS)\monolib_creddlgg.obj \ - $(OBJS)\monolib_rowheightcache.obj + $(OBJS)\monolib_rowheightcache.obj \ + $(OBJS)\monolib_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_1_OBJECTS = \ @@ -3701,7 +3704,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_laywin.obj \ $(OBJS)\monolib_calctrlg.obj \ $(OBJS)\monolib_creddlgg.obj \ - $(OBJS)\monolib_rowheightcache.obj + $(OBJS)\monolib_rowheightcache.obj \ + $(OBJS)\monolib_bmpbndl.obj !endif !if "$(USE_STC)" == "1" ____MONOLIB_STC_SRC_FILENAMES_1_OBJECTS = \ @@ -4148,7 +4152,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_laywin.obj \ $(OBJS)\coredll_calctrlg.obj \ $(OBJS)\coredll_creddlgg.obj \ - $(OBJS)\coredll_rowheightcache.obj + $(OBJS)\coredll_rowheightcache.obj \ + $(OBJS)\coredll_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_2_OBJECTS = \ @@ -4476,7 +4481,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_laywin.obj \ $(OBJS)\coredll_calctrlg.obj \ $(OBJS)\coredll_creddlgg.obj \ - $(OBJS)\coredll_rowheightcache.obj + $(OBJS)\coredll_rowheightcache.obj \ + $(OBJS)\coredll_bmpbndl.obj !endif !if "$(MONOLITHIC)" == "0" && "$(SHARED)" == "0" && "$(USE_GUI)" == "1" __corelib___depname = \ @@ -4829,7 +4835,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_laywin.obj \ $(OBJS)\corelib_calctrlg.obj \ $(OBJS)\corelib_creddlgg.obj \ - $(OBJS)\corelib_rowheightcache.obj + $(OBJS)\corelib_rowheightcache.obj \ + $(OBJS)\corelib_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_3_OBJECTS = \ @@ -5157,7 +5164,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_laywin.obj \ $(OBJS)\corelib_calctrlg.obj \ $(OBJS)\corelib_creddlgg.obj \ - $(OBJS)\corelib_rowheightcache.obj + $(OBJS)\corelib_rowheightcache.obj \ + $(OBJS)\corelib_bmpbndl.obj !endif !if "$(SHARED)" == "1" ____wxcore_namedll_DEP = $(__coredll___depname) @@ -9887,6 +9895,11 @@ $(OBJS)\monodll_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\generic\rowheightcache.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\monodll_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\bmpbndl.cpp +!endif + $(OBJS)\monodll_version.res: ..\..\src\msw\version.rc rc /fo$@ /d WIN32 /i ..\..\src\tiff\libtiff /i ..\..\src\jpeg /i ..\..\src\png /i ..\..\src\zlib /i ..\..\3rdparty\pcre\src\wx /i ..\..\src\expat\expat\lib $(____DEBUGRUNTIME_6) /d _CRT_SECURE_NO_DEPRECATE=1 /d _CRT_NON_CONFORMING_SWPRINTFS=1 /d _SCL_SECURE_NO_WARNINGS=1 $(__NO_VC_CRTDBG_p_72) $(__TARGET_CPU_COMPFLAG_p_72) /d __WXMSW__ $(__WXUNIV_DEFINE_p_66) $(__DEBUG_DEFINE_p_66) $(__NDEBUG_DEFINE_p_65) $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65) $(__UNICODE_DEFINE_p_67) /i $(SETUPHDIR) /i ..\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_4) /d WXBUILDING /d WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)$(WXCOMPILER)$(VENDORTAG) /i ..\..\src\stc\scintilla\include /i ..\..\src\stc\scintilla\lexlib /i ..\..\src\stc\scintilla\src /d __WX__ /d SCI_LEXER /d NO_CXX11_REGEX /d LINK_LEXERS /d wxUSE_BASE=1 /d WXMAKINGDLL ..\..\src\msw\version.rc @@ -12461,6 +12474,11 @@ $(OBJS)\monolib_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\generic\rowheightcache.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\monolib_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\bmpbndl.cpp +!endif + $(OBJS)\basedll_dummy.obj: ..\..\src\common\dummy.cpp $(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) /Ycwx/wxprec.h ..\..\src\common\dummy.cpp @@ -15008,6 +15026,11 @@ $(OBJS)\coredll_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\generic\rowheightcache.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\coredll_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\common\bmpbndl.cpp +!endif + $(OBJS)\corelib_dummy.obj: ..\..\src\common\dummy.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) /Ycwx/wxprec.h ..\..\src\common\dummy.cpp @@ -16748,6 +16771,11 @@ $(OBJS)\corelib_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\generic\rowheightcache.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\corelib_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\common\bmpbndl.cpp +!endif + $(OBJS)\advdll_dummy.obj: ..\..\src\common\dummy.cpp $(CXX) /c /nologo /TP /Fo$@ $(ADVDLL_CXXFLAGS) /Ycwx/wxprec.h ..\..\src\common\dummy.cpp diff --git a/build/msw/wx_core.vcxproj b/build/msw/wx_core.vcxproj index 9307008fef..6ccddecfb6 100644 --- a/build/msw/wx_core.vcxproj +++ b/build/msw/wx_core.vcxproj @@ -459,6 +459,7 @@ + @@ -1087,6 +1088,7 @@ true true + diff --git a/build/msw/wx_core.vcxproj.filters b/build/msw/wx_core.vcxproj.filters index 53d84d94a5..f743597569 100644 --- a/build/msw/wx_core.vcxproj.filters +++ b/build/msw/wx_core.vcxproj.filters @@ -1068,6 +1068,9 @@ Common Sources + + Common Sources + @@ -2299,6 +2302,9 @@ Common Headers + + Common Headers + diff --git a/build/msw/wx_vc8_core.vcproj b/build/msw/wx_vc8_core.vcproj index 9e1cc432f5..c835118cb6 100644 --- a/build/msw/wx_vc8_core.vcproj +++ b/build/msw/wx_vc8_core.vcproj @@ -785,6 +785,10 @@ RelativePath="..\..\src\common\bmpbase.cpp" > + + @@ -3316,6 +3320,10 @@ RelativePath="..\..\include\wx\bitmap.h" > + + diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj index 0fce999ed3..730f268991 100644 --- a/build/msw/wx_vc9_core.vcproj +++ b/build/msw/wx_vc9_core.vcproj @@ -781,6 +781,10 @@ RelativePath="..\..\src\common\bmpbase.cpp" > + + @@ -3312,6 +3316,10 @@ RelativePath="..\..\include\wx\bitmap.h" > + + diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h new file mode 100644 index 0000000000..db041ad375 --- /dev/null +++ b/include/wx/bmpbndl.h @@ -0,0 +1,120 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/bmpbndl.h +// Purpose: Declaration of wxBitmapBundle class. +// Author: Vadim Zeitlin +// Created: 2021-09-22 +// Copyright: (c) 2021 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_BMPBNDL_H_ +#define _WX_BMPBNDL_H_ + +#include "wx/bitmap.h" +#include "wx/object.h" +#include "wx/vector.h" + +class wxBitmapBundleImpl; + +// ---------------------------------------------------------------------------- +// wxBitmapBundle provides 1 or more versions of a bitmap, all bundled together +// ---------------------------------------------------------------------------- + +// This class has value semantics and can be copied cheaply. + +class WXDLLIMPEXP_CORE wxBitmapBundle +{ +public: + // Default ctor constructs an empty bundle which can't be used for + // anything, but can be assigned something later. + wxBitmapBundle(); + + // This conversion ctor from a single bitmap does the same thing as + // FromBitmap() and only exists for interoperability with the existing code + // using wxBitmap. + wxBitmapBundle(const wxBitmap& bitmap); + + // Another conversion ctor from a single image: this one is needed to allow + // passing wxImage to the functions that used to take wxBitmap but now take + // wxBitmapBundle. + wxBitmapBundle(const wxImage& image); + + // Default copy ctor and assignment operator and dtor would be ok, but need + // to be defined out of line, where wxBitmapBundleImpl is fully declared. + + wxBitmapBundle(const wxBitmapBundle& other); + wxBitmapBundle& operator=(const wxBitmapBundle& other); + + ~wxBitmapBundle(); + + + // Create from the given collection of bitmaps (all of which must be valid, + // but if the vector itself is empty, empty bundle is returned). + static wxBitmapBundle FromBitmaps(const wxVector& bitmaps); + static wxBitmapBundle FromBitmaps(const wxBitmap& bitmap1, + const wxBitmap& bitmap2); + + // Create from a single bitmap (this is only useful for compatibility + // with the existing code). Returns empty bundle if bitmap is invalid. + static wxBitmapBundle FromBitmap(const wxBitmap& bitmap); + static wxBitmapBundle FromImage(const wxImage& image); + + + // Check if bitmap bundle is non-empty. + bool IsOk() const { return m_impl; } + + // Get the size of the bitmap represented by this bundle when using the + // default DPI, i.e. 100% scaling. Returns invalid size for empty bundle. + wxSize GetDefaultSize() const; + + // Get bitmap of the specified size, creating a new bitmap from the closest + // available size by rescaling it if necessary. + // + // If size == wxDefaultSize, GetDefaultSize() is used for it instead. + wxBitmap GetBitmap(const wxSize size) const; + +private: + typedef wxObjectDataPtr wxBitmapBundleImplPtr; + + // Private ctor used by static factory functions to create objects of this + // class. It takes ownership of the pointer (which must be non-null). + explicit wxBitmapBundle(wxBitmapBundleImpl* impl); + + wxBitmapBundleImplPtr m_impl; +}; + +// Inline functions implementation. + +/* static */ inline +wxBitmapBundle wxBitmapBundle::FromBitmaps(const wxBitmap& bitmap1, + const wxBitmap& bitmap2) +{ + wxVector bitmaps; + if ( bitmap1.IsOk() ) + bitmaps.push_back(bitmap1); + if ( bitmap2.IsOk() ) + bitmaps.push_back(bitmap2); + return FromBitmaps(bitmaps); +} + +/* static */ inline +wxBitmapBundle wxBitmapBundle::FromBitmap(const wxBitmap& bitmap) +{ + if ( !bitmap.IsOk() ) + return wxBitmapBundle(); + + wxVector bitmaps; + bitmaps.push_back(bitmap); + return FromBitmaps(bitmaps); +} + +/* static */ inline +wxBitmapBundle wxBitmapBundle::FromImage(const wxImage& image) +{ + if ( !image.IsOk() ) + return wxBitmapBundle(); + + return FromBitmap(wxBitmap(image)); +} + +#endif // _WX_BMPBNDL_H_ diff --git a/include/wx/gtk/toolbar.h b/include/wx/gtk/toolbar.h index 4ef2756009..105fea9da4 100644 --- a/include/wx/gtk/toolbar.h +++ b/include/wx/gtk/toolbar.h @@ -47,8 +47,8 @@ public: virtual void SetWindowStyleFlag( long style ) wxOVERRIDE; - virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; - virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; + virtual void SetToolNormalBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; + virtual void SetToolDisabledBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; virtual bool Realize() wxOVERRIDE; @@ -57,8 +57,8 @@ public: virtual wxToolBarToolBase *CreateTool(int id, const wxString& label, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2 = wxNullBitmap, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bitmap2 = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelpString = wxEmptyString, diff --git a/include/wx/gtk1/toolbar.h b/include/wx/gtk1/toolbar.h index ab23653354..fdaf1b7786 100644 --- a/include/wx/gtk1/toolbar.h +++ b/include/wx/gtk1/toolbar.h @@ -83,8 +83,8 @@ protected: virtual wxToolBarToolBase *CreateTool(int id, const wxString& label, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bitmap2, wxItemKind kind, wxObject *clientData, const wxString& shortHelpString, diff --git a/include/wx/motif/toolbar.h b/include/wx/motif/toolbar.h index 5f4d3da9bd..1374745ca3 100644 --- a/include/wx/motif/toolbar.h +++ b/include/wx/motif/toolbar.h @@ -62,8 +62,8 @@ private: virtual wxToolBarToolBase *CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, diff --git a/include/wx/msw/toolbar.h b/include/wx/msw/toolbar.h index f01cd4e856..a86a4742f0 100644 --- a/include/wx/msw/toolbar.h +++ b/include/wx/msw/toolbar.h @@ -53,8 +53,8 @@ public: virtual void SetRows(int nRows) wxOVERRIDE; - virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; - virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; + virtual void SetToolNormalBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; + virtual void SetToolDisabledBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; virtual void SetToolPacking(int packing) wxOVERRIDE; @@ -89,8 +89,8 @@ public: virtual wxToolBarToolBase *CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelp = wxEmptyString, diff --git a/include/wx/private/bmpbndl.h b/include/wx/private/bmpbndl.h new file mode 100644 index 0000000000..fd17d82041 --- /dev/null +++ b/include/wx/private/bmpbndl.h @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/private/bmpbndl.h +// Purpose: wxBitmapBundleImpl declaration. +// Author: Vadim Zeitlin +// Created: 2021-09-22 +// Copyright: (c) 2021 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_PRIVATE_BMPBNDL_H_ +#define _WX_PRIVATE_BMPBNDL_H_ + +#include "wx/object.h" + +// ---------------------------------------------------------------------------- +// wxBitmapBundleImpl is the base class for all wxBitmapBundle implementations +// ---------------------------------------------------------------------------- + +// This class inherits from wxRefCounter to make it possible to use it with +// wxObjectDataPtr in wxBitmapBundle. +class wxBitmapBundleImpl : public wxRefCounter +{ +public: + // Return the size of the bitmaps represented by this bundle in the default + // DPI (a.k.a. 100% resolution). + // + // Must always return a valid size. + virtual wxSize GetDefaultSize() const = 0; + + // Retrieve the bitmap of exactly the given size. + // + // Note that this function is non-const because it may generate the bitmap + // on demand and cache it. + virtual wxBitmap GetBitmap(const wxSize size) = 0; +}; + +#endif // _WX_PRIVATE_BMPBNDL_H_ diff --git a/include/wx/qt/toolbar.h b/include/wx/qt/toolbar.h index 7ae8a8af4a..d2de81bf70 100644 --- a/include/wx/qt/toolbar.h +++ b/include/wx/qt/toolbar.h @@ -43,15 +43,15 @@ public: virtual void SetWindowStyleFlag( long style ) wxOVERRIDE; virtual void SetToolShortHelp(int id, const wxString& helpString) wxOVERRIDE; - virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; - virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; + virtual void SetToolNormalBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; + virtual void SetToolDisabledBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; virtual bool Realize() wxOVERRIDE; virtual wxToolBarToolBase *CreateTool(int toolid, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelp = wxEmptyString, diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h index a4b380d6ee..c489d4c068 100644 --- a/include/wx/tbarbase.h +++ b/include/wx/tbarbase.h @@ -20,6 +20,7 @@ #if wxUSE_TOOLBAR #include "wx/bitmap.h" +#include "wx/bmpbndl.h" #include "wx/list.h" #include "wx/control.h" @@ -63,8 +64,8 @@ public: wxToolBarToolBase(wxToolBarBase *tbar = NULL, int toolid = wxID_SEPARATOR, const wxString& label = wxEmptyString, - const wxBitmap& bmpNormal = wxNullBitmap, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bmpNormal = wxNullBitmap, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelpString = wxEmptyString, @@ -145,11 +146,13 @@ public: { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; } // attributes - const wxBitmap& GetNormalBitmap() const { return m_bmpNormal; } - const wxBitmap& GetDisabledBitmap() const { return m_bmpDisabled; } + wxBitmap GetNormalBitmap(const wxSize& size = wxDefaultSize) const + { return m_bmpNormal.GetBitmap(size); } + wxBitmap GetDisabledBitmap(const wxSize& size = wxDefaultSize) const + { return m_bmpDisabled.GetBitmap(size); } - const wxBitmap& GetBitmap() const - { return IsEnabled() ? GetNormalBitmap() : GetDisabledBitmap(); } + wxBitmap GetBitmap(const wxSize& size = wxDefaultSize) const + { return IsEnabled() ? GetNormalBitmap(size) : GetDisabledBitmap(size); } const wxString& GetLabel() const { return m_label; } @@ -177,8 +180,8 @@ public: void Toggle() { Toggle(!IsToggled()); } - void SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; } - void SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; } + void SetNormalBitmap(const wxBitmapBundle& bmp) { m_bmpNormal = bmp; } + void SetDisabledBitmap(const wxBitmapBundle& bmp) { m_bmpDisabled = bmp; } virtual void SetLabel(const wxString& label) { m_label = label; } @@ -251,8 +254,8 @@ protected: bool m_enabled; // normal and disabled bitmaps for the tool, both can be invalid - wxBitmap m_bmpNormal; - wxBitmap m_bmpDisabled; + wxBitmapBundle m_bmpNormal; + wxBitmapBundle m_bmpDisabled; // the button label wxString m_label; @@ -290,8 +293,8 @@ public: // is created and used as the disabled image. wxToolBarToolBase *AddTool(int toolid, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled, wxItemKind kind = wxITEM_NORMAL, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, @@ -304,7 +307,7 @@ public: // the most common AddTool() version wxToolBarToolBase *AddTool(int toolid, const wxString& label, - const wxBitmap& bitmap, + const wxBitmapBundle& bitmap, const wxString& shortHelp = wxEmptyString, wxItemKind kind = wxITEM_NORMAL) { @@ -314,8 +317,8 @@ public: // add a check tool, i.e. a tool which can be toggled wxToolBarToolBase *AddCheckTool(int toolid, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, wxObject *clientData = NULL) @@ -328,8 +331,8 @@ public: // other toggled radio tools in the same group when it happens wxToolBarToolBase *AddRadioTool(int toolid, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, wxObject *clientData = NULL) @@ -346,8 +349,8 @@ public: size_t pos, int toolid, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, @@ -427,9 +430,9 @@ public: virtual wxString GetToolLongHelp(int toolid) const; virtual void SetToolNormalBitmap(int WXUNUSED(id), - const wxBitmap& WXUNUSED(bitmap)) {} + const wxBitmapBundle& WXUNUSED(bitmap)) {} virtual void SetToolDisabledBitmap(int WXUNUSED(id), - const wxBitmap& WXUNUSED(bitmap)) {} + const wxBitmapBundle& WXUNUSED(bitmap)) {} // margins/packing/separation @@ -576,8 +579,8 @@ public: // ------------------------- virtual wxToolBarToolBase *CreateTool(int toolid, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelp = wxEmptyString, @@ -625,8 +628,8 @@ protected: ( int toolid, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, diff --git a/include/wx/univ/toolbar.h b/include/wx/univ/toolbar.h index 22ab99dd1c..3d8bcd7238 100644 --- a/include/wx/univ/toolbar.h +++ b/include/wx/univ/toolbar.h @@ -91,8 +91,8 @@ protected: virtual wxToolBarToolBase *CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, diff --git a/include/wx/wx.h b/include/wx/wx.h index 9f6a42cb13..f672167d60 100644 --- a/include/wx/wx.h +++ b/include/wx/wx.h @@ -44,6 +44,7 @@ #include "wx/gdiobj.h" #include "wx/region.h" #include "wx/bitmap.h" +#include "wx/bmpbndl.h" #include "wx/image.h" #include "wx/colour.h" #include "wx/font.h" diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h new file mode 100644 index 0000000000..3b95a74c7a --- /dev/null +++ b/interface/wx/bmpbndl.h @@ -0,0 +1,179 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/bmpbndl.h +// Purpose: Interface of wxBitmapBundle. +// Author: Vadim Zeitlin +// Created: 2021-09-24 +// Copyright: (c) 2021 Vadim Zeitlin +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +/** + Contains representations of the same bitmap in different resolutions. + + This class generalizes wxBitmap for applications supporting multiple DPIs + and allows to operate with multiple versions of the same bitmap, in the + sizes appropriate to the currently used display resolution, as a single + unit. Notably, an entire wxBitmapBundle can be passed to functions such as + wxToolBar::AddTool() to allow toolbar to select the best available bitmap + to be shown. + + Objects of this class are typically created by the application and then + passed to wxWidgets functions, but not used by the application itself. + Currently bitmap bundles can be created from: + + - A vector of bitmaps, of any provenance. + - A single wxBitmap or wxImage for backwards compatibility. + + More functions for creating bitmap bundles will be added in the future. + + Objects of wxBitmapBundle class have value-like semantics, i.e. they can be + copied around freely (and cheaply) and don't need to be allocated on the + heap. However they usually are created using static factory functions + (known as "pseudo-constructors") such as FromBitmaps() instead of using the + real constructors. + + Example of using this class to initialize a toolbar in a frame constructor: + @code + MyFrame::MyFrame() + : wxFrame(nullptr, wxID_ANY, "My frame") + { + ... + wxToolBar* toolBar = CreateToolBar(); + + wxVector bitmaps; + bitmaps.push_back(wxBITMAP_PNG(open_32x32)); + bitmaps.push_back(wxBITMAP_PNG(open_48x48)); + bitmaps.push_back(wxBITMAP_PNG(open_64x64)); + + toolBar->AddTool(wxID_OPEN, wxBitmapBundle::FromBitmaps(bitmaps)); + } + @endcode + + The code shown above will use 32 pixel bitmap in normal DPI, 64 pixel + bitmap in "high DPI", i.e. pixel-doubling or 200% resolution, and 48 pixel + bitmap in 150% resolution. For all the other resolutions, the best matching + bitmap will be created dynamically from the best available match, e.g. for + 175% resolution, 64 pixel bitmap will be rescaled to 56 pixels. + + Of course, this code relies on actually having the resources with the + corresponding names (i.e. @c open_NxN) in MSW .rc file or Mac application + bundle and @c open_NxN_png arrays being defined in the program code, e.g. + by including a file generated with @c bin2c (see wxBITMAP_PNG_FROM_DATA()), + on the other platforms. + + Also note that the existing code using wxBitmap is compatible with the + functions taking wxBitmapBundle in wxWidgets 3.1.6 and later because + bitmaps are implicitly convertible to the objects of this class, so just + passing wxBitmap to the functions taking wxBitmapBundle continues to work + and if high resolution versions of bitmap are not (yet) available for the + other toolbar tools, single bitmaps can continue to be used instead. + + @library{wxcore} + @category{gdi} + + @since 3.1.6 +*/ +class wxBitmapBundle +{ +public: + /** + Default constructor constructs an empty bundle. + + An empty bundle can't be used for anything, but can be assigned + something else later. + */ + wxBitmapBundle(); + + /** + Conversion constructor from a single bitmap. + + This constructor does the same thing as FromBitmap() and only exists + for interoperability with the existing code using wxBitmap. + */ + wxBitmapBundle(const wxBitmap& bitmap); + + /** + Conversion constructor from a single image. + + Similarly to the constructor from wxBitmap, this constructor only + exists for interoperability with the existing code using wxImage and + can be replaced with more readable FromImage() in the new code. + */ + wxBitmapBundle(const wxImage& image); + + /** + Copy constructor creates a copy of another bundle. + */ + wxBitmapBundle(const wxBitmapBundle& other); + + /** + Assignment operator makes this bundle a copy of another bundle. + */ + wxBitmapBundle& operator=(const wxBitmapBundle& other); + + + /** + Create a bundle from the given collection of bitmaps. + + If the @a bitmaps vector is empty, an invalid, empty bundle is + returned, otherwise initialize the bundle with all the bitmaps in this + vector which must be themselves valid. + */ + static wxBitmapBundle FromBitmaps(const wxVector& bitmaps); + + /// @overload + static wxBitmapBundle FromBitmaps(const wxBitmap& bitmap1, + const wxBitmap& bitmap2); + + /** + Create a bundle from a single bitmap. + + This is only useful for compatibility with the existing code using + wxBitmap. + + If @a bitmap is invalid, empty bundle is returned. + */ + static wxBitmapBundle FromBitmap(const wxBitmap& bitmap); + + /** + Create a bundle from a single image. + + This is only useful for compatibility with the existing code using + wxImage. + + If @a image is invalid, empty bundle is returned. + */ + static wxBitmapBundle FromImage(const wxImage& image); + + /** + Check if bitmap bundle is non-empty. + + Return @true if the bundle contains any bitmaps or @false if it is + empty. + */ + bool IsOk() const; + + /** + Get the size of the bitmap represented by this bundle in default + resolution or, equivalently, at 100% scaling. + + When creating the bundle from a number of bitmaps, this will be just + the size of the smallest bitmap in it. + + Note that this function is mostly used by wxWidgets itself and not the + application. + */ + wxSize GetDefaultSize() const; + + /** + Get bitmap of the specified size, creating a new bitmap from the closest + available size by rescaling it if necessary. + + This function is mostly used by wxWidgets itself and not the + application. As all bitmaps created by it dynamically are currently + cached, avoid calling it for many different sizes if you do use it, as + this will create many bitmaps that will never be deleted and will + consume resources until the application termination. + */ + wxBitmap GetBitmap(const wxSize size) const; +}; diff --git a/interface/wx/toolbar.h b/interface/wx/toolbar.h index 3cdb064c73..6961be25bd 100644 --- a/interface/wx/toolbar.h +++ b/interface/wx/toolbar.h @@ -83,8 +83,8 @@ public: wxToolBarToolBase(wxToolBarBase *tbar = NULL, int toolid = wxID_SEPARATOR, const wxString& label = wxEmptyString, - const wxBitmap& bmpNormal = wxNullBitmap, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bmpNormal = wxNullBitmap, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelpString = wxEmptyString, @@ -112,10 +112,10 @@ public: bool IsToggled() const; bool CanBeToggled() const; - const wxBitmap& GetNormalBitmap() const; - const wxBitmap& GetDisabledBitmap() const; + wxBitmap GetNormalBitmap() const; + wxBitmap GetDisabledBitmap() const; - const wxBitmap& GetBitmap() const; + wxBitmap GetBitmap() const; const wxString& GetLabel() const; const wxString& GetShortHelp() const; @@ -129,8 +129,8 @@ public: bool SetShortHelp(const wxString& help); bool SetLongHelp(const wxString& help); void Toggle(); - void SetNormalBitmap(const wxBitmap& bmp); - void SetDisabledBitmap(const wxBitmap& bmp); + void SetNormalBitmap(const wxBitmapBundle& bmp); + void SetDisabledBitmap(const wxBitmapBundle& bmp); void SetLabel(const wxString& label); void SetClientData(wxObject *clientData); @@ -318,8 +318,8 @@ public: @see AddTool() */ wxToolBarToolBase* AddCheckTool(int toolId, const wxString& label, - const wxBitmap& bitmap1, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, wxObject* clientData = NULL); @@ -354,8 +354,8 @@ public: @see AddTool() */ wxToolBarToolBase* AddRadioTool(int toolId, const wxString& label, - const wxBitmap& bitmap1, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, wxObject* clientData = NULL); @@ -436,7 +436,7 @@ public: InsertTool(), DeleteTool(), Realize(), SetDropdownMenu() */ wxToolBarToolBase* AddTool(int toolId, const wxString& label, - const wxBitmap& bitmap, + const wxBitmapBundle& bitmap, const wxString& shortHelp = wxEmptyString, wxItemKind kind = wxITEM_NORMAL); @@ -478,8 +478,8 @@ public: InsertTool(), DeleteTool(), Realize(), SetDropdownMenu() */ wxToolBarToolBase* AddTool(int toolId, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled, wxItemKind kind = wxITEM_NORMAL, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, @@ -727,8 +727,8 @@ public: wxToolBarToolBase* InsertTool( size_t pos, int toolId, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, const wxString& shortHelp = wxEmptyString, const wxString& longHelp = wxEmptyString, @@ -895,7 +895,7 @@ public: have no effect on those platforms. */ - virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); + virtual void SetToolDisabledBitmap(int id, const wxBitmapBundle& bitmap); /** Sets the long help for the given tool. @@ -921,7 +921,7 @@ public: @param bitmap Bitmap to use for normals tools. */ - virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + virtual void SetToolNormalBitmap(int id, const wxBitmapBundle& bitmap); /** Sets the value used for spacing tools. The default value is 1. @@ -982,8 +982,8 @@ public: */ virtual wxToolBarToolBase *CreateTool(int toolId, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelp = wxEmptyString, diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index f636352703..300cc1b4ca 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -25,6 +25,7 @@ #endif #include "wx/toolbar.h" +#include "wx/bmpbndl.h" #include "wx/log.h" #include "wx/image.h" #include "wx/filedlg.h" @@ -50,9 +51,8 @@ #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 +// Temporarily embed bitmaps in the program itself on all platforms. +#if 1 // ndef wxHAS_IMAGE_RESOURCES #include "bitmaps/new_png.c" #include "bitmaps/open_png.c" #include "bitmaps/save_png.c" @@ -389,46 +389,36 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) Tool_Max }; - wxBitmap toolBarBitmaps[Tool_Max]; + wxBitmapBundle toolBarBitmaps[Tool_Max]; - if ( GetDPIScaleFactor() >= 1.5 ) - { - toolBarBitmaps[Tool_new ] = wxBITMAP_PNG(new_2x ); - toolBarBitmaps[Tool_open ] = wxBITMAP_PNG(open_2x ); - toolBarBitmaps[Tool_save ] = wxBITMAP_PNG(save_2x ); - toolBarBitmaps[Tool_copy ] = wxBITMAP_PNG(copy_2x ); - toolBarBitmaps[Tool_cut ] = wxBITMAP_PNG(cut_2x ); - toolBarBitmaps[Tool_paste] = wxBITMAP_PNG(paste_2x); - toolBarBitmaps[Tool_print] = wxBITMAP_PNG(print_2x); - toolBarBitmaps[Tool_help ] = wxBITMAP_PNG(help_2x ); - } - else - { - toolBarBitmaps[Tool_new ] = wxBITMAP_PNG(new ); - toolBarBitmaps[Tool_open ] = wxBITMAP_PNG(open ); - toolBarBitmaps[Tool_save ] = wxBITMAP_PNG(save ); - toolBarBitmaps[Tool_copy ] = wxBITMAP_PNG(copy ); - toolBarBitmaps[Tool_cut ] = wxBITMAP_PNG(cut ); - toolBarBitmaps[Tool_paste] = wxBITMAP_PNG(paste); - toolBarBitmaps[Tool_print] = wxBITMAP_PNG(print); - toolBarBitmaps[Tool_help ] = wxBITMAP_PNG(help ); - } + // This macro relies on having name_png and name_2x_png arrays defined, + // (this is done in this sample by including the corresponding *_png.c files + // above). + #define BUNDLE_2(name) \ + wxBitmapBundle::FromBitmaps(wxBITMAP_PNG_FROM_DATA(name), \ + wxBITMAP_PNG_FROM_DATA(name##_2x)) - int w = toolBarBitmaps[Tool_new].GetWidth(), - h = toolBarBitmaps[Tool_new].GetHeight(); + toolBarBitmaps[Tool_new ] = BUNDLE_2(new ); + toolBarBitmaps[Tool_open ] = BUNDLE_2(open ); + toolBarBitmaps[Tool_save ] = BUNDLE_2(save ); + toolBarBitmaps[Tool_copy ] = BUNDLE_2(copy ); + toolBarBitmaps[Tool_cut ] = BUNDLE_2(cut ); + toolBarBitmaps[Tool_paste] = BUNDLE_2(paste); + toolBarBitmaps[Tool_print] = BUNDLE_2(print); + toolBarBitmaps[Tool_help ] = BUNDLE_2(help ); + + // Size of the bitmaps we use by default. + int w = 32, + h = 32; if ( !m_smallToolbar ) { w *= 2; h *= 2; - - for ( size_t n = Tool_new; n < WXSIZEOF(toolBarBitmaps); n++ ) - { - toolBarBitmaps[n] = - wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h)); - } } + toolBar->SetToolBitmapSize(wxSize(w, h)); + toolBar->AddTool(wxID_NEW, "New", toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_DROPDOWN, "New file", "This is help for new file tool"); @@ -472,7 +462,7 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) { wxMemoryDC dc; dc.SelectObject(bmpDisabled); - dc.DrawBitmap(toolBarBitmaps[Tool_print], 0, 0); + dc.DrawBitmap(toolBarBitmaps[Tool_print].GetBitmap(wxSize(w, h)), 0, 0); wxPen pen(*wxRED, 5); dc.SetPen(pen); diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp new file mode 100644 index 0000000000..c594747f8d --- /dev/null +++ b/src/common/bmpbndl.cpp @@ -0,0 +1,261 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/common/bmpbndl.cpp +// Purpose: Common methods of wxBitmapBundle class. +// Author: Vadim Zeitlin +// Created: 2021-09-22 +// Copyright: (c) 2021 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP +#endif // WX_PRECOMP + +#include "wx/bmpbndl.h" + +#include "wx/private/bmpbndl.h" + +#include + +// ---------------------------------------------------------------------------- +// private helpers +// ---------------------------------------------------------------------------- + +namespace +{ + +// Simplest possible bundle implementation storing a collection of bitmaps +class wxBitmapBundleImplSet : public wxBitmapBundleImpl +{ +public: + // The vector must not be empty, caller is supposed to have checked for it. + explicit wxBitmapBundleImplSet(const wxVector& bitmaps) + { + Init(&bitmaps[0], bitmaps.size()); + } + + // Convenience ctor from a single bitmap. + explicit wxBitmapBundleImplSet(const wxBitmap& bitmap) + { + Init(&bitmap, 1); + } + + virtual wxSize GetDefaultSize() const wxOVERRIDE; + virtual wxBitmap GetBitmap(const wxSize size) wxOVERRIDE; + +private: + // Struct containing bitmap itself as well as a flag indicating whether we + // generated it by rescaling the existing bitmap or not. + struct Entry + { + // Create a new entry from the original bitmap. + explicit Entry(const wxBitmap& bitmap_) + : bitmap(bitmap_) + { + generated = false; + } + + // Create a new entry of the given size by resizing the bitmap of an + // existing one. + Entry(const Entry& entry, const wxSize& size) + : bitmap(entry.bitmap) + { + wxASSERT_MSG( !entry.generated, wxS("should use original bitmap") ); + + generated = true; + + wxBitmap::Rescale(bitmap, size); + } + + wxBitmap bitmap; + bool generated; + }; + + // Comparator comparing entries by the bitmap size. + struct BitmapSizeComparator + { + bool operator()(const Entry& entry1, const Entry& entry2) const + { + // We could compare the bitmaps areas too, but they're supposed to + // all use different sizes anyhow, so keep things simple. + return entry1.bitmap.GetHeight() < entry2.bitmap.GetHeight(); + } + }; + + typedef wxVector Entries; + + // All bitmaps sorted by size. + // + // Note that this vector is never empty. + Entries m_entries; + + + // Common implementation of all ctors. + void Init(const wxBitmap* bitmaps, size_t n); + + wxDECLARE_NO_COPY_CLASS(wxBitmapBundleImplSet); +}; + +} // anonymous namespace + +// ============================================================================ +// wxBitmapBundleImplSet implementation +// ============================================================================ + +void wxBitmapBundleImplSet::Init(const wxBitmap* bitmaps, size_t n) +{ + m_entries.reserve(n); + for ( size_t i = 0; i < n; ++i ) + { + const wxBitmap& bitmap = bitmaps[i]; + + wxASSERT_MSG( bitmap.IsOk(), wxS("all bundle bitmaps must be valid") ); + + m_entries.push_back(Entry(bitmap)); + } + + std::sort(m_entries.begin(), m_entries.end(), BitmapSizeComparator()); + + // Should we check that all bitmaps really have unique sizes here? For now, + // don't bother with this, but we might want to do it later if it really + // turns out to be a problem in practice. +} + +wxSize wxBitmapBundleImplSet::GetDefaultSize() const +{ + // Default size is the size of the smallest bitmap in the bundle. + return m_entries[0].bitmap.GetSize(); +} + +wxBitmap wxBitmapBundleImplSet::GetBitmap(const wxSize size) +{ + // We use linear search instead if binary one because it's simpler and the + // vector size is small enough (< 10) for it not to matter in practice. + const size_t n = m_entries.size(); + size_t lastSmaller = 0; + for ( size_t i = 0; i < n; ++i ) + { + const Entry& entry = m_entries[i]; + + const wxSize sizeThis = entry.bitmap.GetSize(); + if ( sizeThis.y == size.y ) + { + // Exact match, just use it. + return entry.bitmap; + } + + if ( sizeThis.y < size.y ) + { + // Don't rescale this one, we prefer to downscale rather than + // upscale as it results in better-looking bitmaps. + lastSmaller = i; + continue; + } + + if ( sizeThis.y > size.y && !entry.generated ) + { + // We know that we don't have any exact match and we've found the + // next bigger bitmap, so rescale it to the desired size. + const Entry entryNew(entry, size); + + m_entries.insert(m_entries.begin() + lastSmaller + 1, entryNew); + + return entryNew.bitmap; + } + } + + // We only get here if the requested size is larger than the size of all + // the bitmaps we have, in which case we have no choice but to upscale one + // of the bitmaps, so find the largest available non-generated bitmap. + for ( size_t i = n; n > 0; --i ) + { + const Entry& entry = m_entries[i - 1]; + if ( !entry.generated ) + { + const Entry entryNew(entry, size); + + m_entries.push_back(entryNew); + + return entryNew.bitmap; + } + } + + // We should have at least one non-generated bitmap. + wxFAIL_MSG( wxS("unreachable") ); + + return wxBitmap(); +} + +// ============================================================================ +// wxBitmapBundle implementation +// ============================================================================ + +wxBitmapBundle::wxBitmapBundle() +{ +} + +wxBitmapBundle::wxBitmapBundle(wxBitmapBundleImpl* impl) + : m_impl(impl) +{ +} + +wxBitmapBundle::wxBitmapBundle(const wxBitmap& bitmap) + : m_impl(bitmap.IsOk() ? new wxBitmapBundleImplSet(bitmap) : NULL) +{ +} + +wxBitmapBundle::wxBitmapBundle(const wxImage& image) + : m_impl(image.IsOk() ? new wxBitmapBundleImplSet(wxBitmap(image)) : NULL) +{ +} + +wxBitmapBundle::wxBitmapBundle(const wxBitmapBundle& other) + : m_impl(other.m_impl) +{ +} + +wxBitmapBundle& wxBitmapBundle::operator=(const wxBitmapBundle& other) +{ + // No need to check for self-assignment because m_impl already does. + m_impl = other.m_impl; + return *this; +} + +wxBitmapBundle::~wxBitmapBundle() +{ +} + +/* static */ +wxBitmapBundle wxBitmapBundle::FromBitmaps(const wxVector& bitmaps) +{ + if ( bitmaps.empty() ) + return wxBitmapBundle(); + + return wxBitmapBundle(new wxBitmapBundleImplSet(bitmaps)); +} + +wxSize wxBitmapBundle::GetDefaultSize() const +{ + if ( !m_impl ) + return wxDefaultSize; + + return m_impl->GetDefaultSize(); +} + +wxBitmap wxBitmapBundle::GetBitmap(const wxSize size) const +{ + if ( !m_impl ) + return wxBitmap(); + + return m_impl->GetBitmap(size == wxDefaultSize ? GetDefaultSize() : size); +} diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index 5f08d11480..251600f652 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -156,8 +156,8 @@ void wxToolBarBase::FixupStyle() wxToolBarToolBase *wxToolBarBase::DoAddTool(int toolid, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, const wxString& shortHelp, const wxString& longHelp, @@ -173,8 +173,8 @@ wxToolBarToolBase *wxToolBarBase::DoAddTool(int toolid, wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos, int toolid, const wxString& label, - const wxBitmap& bitmap, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bitmap, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, const wxString& shortHelp, const wxString& longHelp, diff --git a/src/gtk/toolbar.cpp b/src/gtk/toolbar.cpp index 155b2afbac..9429a5fb33 100644 --- a/src/gtk/toolbar.cpp +++ b/src/gtk/toolbar.cpp @@ -35,8 +35,8 @@ public: wxToolBarTool(wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bitmap2, wxItemKind kind, wxObject *clientData, const wxString& shortHelpString, @@ -373,8 +373,8 @@ void wxToolBarTool::SetLabel(const wxString& label) wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& text, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bitmap2, wxItemKind kind, wxObject *clientData, const wxString& shortHelpString, @@ -795,7 +795,7 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) } } -void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) @@ -807,7 +807,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) } } -void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) diff --git a/src/gtk1/toolbar.cpp b/src/gtk1/toolbar.cpp index 5032fa3fc7..bfd6713671 100644 --- a/src/gtk1/toolbar.cpp +++ b/src/gtk1/toolbar.cpp @@ -75,8 +75,8 @@ public: wxToolBarTool(wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bitmap2, wxItemKind kind, wxObject *clientData, const wxString& shortHelpString, @@ -234,8 +234,8 @@ void wxToolBarTool::Init() wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& text, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2, + const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bitmap2, wxItemKind kind, wxObject *clientData, const wxString& shortHelpString, diff --git a/src/motif/toolbar.cpp b/src/motif/toolbar.cpp index 9877f2b197..874dca1e12 100644 --- a/src/motif/toolbar.cpp +++ b/src/motif/toolbar.cpp @@ -80,8 +80,8 @@ public: wxToolBarTool(wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpToggled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpToggled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -142,8 +142,8 @@ wxString wxToolBarTimer::helpString; wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpToggled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpToggled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 07ccd29108..36d5840058 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -150,8 +150,8 @@ public: wxToolBarTool(wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -344,8 +344,8 @@ static bool MSWShouldBeChecked(const wxToolBarToolBase *tool) wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -781,14 +781,14 @@ void wxToolBar::CreateDisabledImageList() node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarToolBase *tool = node->GetData(); - wxBitmap bmpDisabled = tool->GetDisabledBitmap(); + wxBitmap bmpDisabled = tool->GetDisabledBitmap(wxSize(m_defaultWidth, + m_defaultHeight)); if ( bmpDisabled.IsOk() ) { - const wxSize sizeBitmap = bmpDisabled.GetSize(); m_disabledImgList = new wxImageList ( - sizeBitmap.x, - sizeBitmap.y, + m_defaultWidth, + m_defaultHeight, // Don't use mask if we have alpha // (wxImageList will fall back to // mask if alpha not supported) @@ -858,11 +858,15 @@ bool wxToolBar::Realize() wxMemoryDC dcAllButtons; wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight); + const wxSize sizeBitmap(m_defaultWidth, m_defaultHeight); + for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarToolBase *tool = node->GetData(); - if ( tool->IsButton() && - tool->GetNormalBitmap().IsOk() && tool->GetNormalBitmap().HasAlpha() ) + wxBitmap toolBitmap; + if ( tool->IsButton() ) + toolBitmap = tool->GetNormalBitmap(sizeBitmap); + if ( toolBitmap.IsOk() && toolBitmap.HasAlpha() ) { // By default bitmaps don't have alpha in wxMSW, but if we // use a bitmap tool with alpha, we should use alpha for @@ -925,16 +929,10 @@ bool wxToolBar::Realize() wxToolBarToolBase *tool = node->GetData(); if ( tool->IsButton() ) { - wxBitmap bmp = tool->GetNormalBitmap(); - - const int w = bmp.GetWidth(); - const int h = bmp.GetHeight(); + wxBitmap bmp = tool->GetNormalBitmap(sizeBitmap); if ( bmp.IsOk() ) { - int xOffset = wxMax(0, (m_defaultWidth - w)/2); - int yOffset = wxMax(0, (m_defaultHeight - h)/2); - #if wxUSE_IMAGE // If a mix of icons with alpha and without is used, // convert them all to use alpha. @@ -947,7 +945,7 @@ bool wxToolBar::Realize() #endif // notice the last parameter: do use mask - dcAllButtons.DrawBitmap(bmp, x + xOffset, yOffset, true); + dcAllButtons.DrawBitmap(bmp, x, 0, true); // Handle of the bitmap could have changed inside // DrawBitmap() call if it had to convert it from DDB to @@ -963,7 +961,8 @@ bool wxToolBar::Realize() // also deal with disabled bitmap if we want to use them if ( m_disabledImgList ) { - wxBitmap bmpDisabled = tool->GetDisabledBitmap(); + wxBitmap bmpDisabled = tool->GetDisabledBitmap(sizeBitmap); + #if wxUSE_IMAGE && wxUSE_WXDIB if ( !bmpDisabled.IsOk() ) { @@ -977,9 +976,9 @@ bool wxToolBar::Realize() { // we need to have light grey background colour for // MapBitmap() to work correctly - for ( int y = 0; y < h; y++ ) + for ( int y = 0; y < m_defaultHeight; y++ ) { - for ( int xx = 0; xx < w; xx++ ) + for ( int xx = 0; xx < m_defaultWidth; xx++ ) { if ( imgGreyed.IsTransparent(xx, y) ) imgGreyed.SetRGB(xx, y, @@ -995,7 +994,10 @@ bool wxToolBar::Realize() #endif // wxUSE_IMAGE if ( remapValue == Remap_Buttons ) - MapBitmap(bmpDisabled.GetHBITMAP(), w, h); + { + MapBitmap(bmpDisabled.GetHBITMAP(), + m_defaultWidth, m_defaultHeight); + } m_disabledImgList->Add(bmpDisabled); } @@ -1842,7 +1844,7 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(tog wxFAIL_MSG( wxT("not implemented") ); } -void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) @@ -1854,7 +1856,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) } } -void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) diff --git a/src/qt/toolbar.cpp b/src/qt/toolbar.cpp index 61a765e1c0..953713bddf 100644 --- a/src/qt/toolbar.cpp +++ b/src/qt/toolbar.cpp @@ -28,8 +28,8 @@ class wxQtToolButton; class wxToolBarTool : public wxToolBarToolBase { public: - wxToolBarTool(wxToolBar *tbar, int id, const wxString& label, const wxBitmap& bitmap1, - const wxBitmap& bitmap2, wxItemKind kind, wxObject *clientData, + wxToolBarTool(wxToolBar *tbar, int id, const wxString& label, const wxBitmapBundle& bitmap1, + const wxBitmapBundle& bitmap2, wxItemKind kind, wxObject *clientData, const wxString& shortHelpString, const wxString& longHelpString) : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind, clientData, shortHelpString, longHelpString) @@ -194,7 +194,7 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) } } -void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) @@ -206,7 +206,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) } } -void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) @@ -364,8 +364,8 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), wxFAIL_MSG( wxT("not implemented") ); } -wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& label, const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, wxItemKind kind, wxObject *clientData, +wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& label, const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, const wxString& longHelp) { return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind, diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp index e37c4c20d1..fce33ce6fc 100644 --- a/src/univ/toolbar.cpp +++ b/src/univ/toolbar.cpp @@ -78,8 +78,8 @@ public: wxToolBarTool(wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -313,8 +313,8 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase *tool, bool WXUNUSED(toggle)) wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, From b33df7360a4ea92d388fb7950b41c4495dcd0c08 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 25 Sep 2021 00:49:15 +0100 Subject: [PATCH 02/18] Implement loading resource bundle from Windows resources This allows to use resources defined in the .rc files under MSW instead of embedding them in the program text as arrays. --- Makefile.in | 60 ++++-- build/bakefiles/files.bkl | 1 + build/cmake/files.cmake | 1 + build/files | 1 + build/msw/makefile.gcc | 52 +++-- build/msw/makefile.vc | 52 +++-- build/msw/wx_core.vcxproj | 12 +- build/msw/wx_core.vcxproj.filters | 3 + build/msw/wx_vc8_core.vcproj | 132 +++++++++++++ build/msw/wx_vc9_core.vcproj | 132 +++++++++++++ include/wx/bmpbndl.h | 14 ++ interface/wx/bmpbndl.h | 56 ++++++ samples/toolbar/toolbar.cpp | 36 ++-- src/common/bmpbndl.cpp | 18 ++ src/msw/bmpbndl.cpp | 307 ++++++++++++++++++++++++++++++ 15 files changed, 815 insertions(+), 62 deletions(-) create mode 100644 src/msw/bmpbndl.cpp diff --git a/Makefile.in b/Makefile.in index e580468523..a2d91741d1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4711,7 +4711,7 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS = \ monodll_calctrlg.o \ monodll_creddlgg.o \ monodll_rowheightcache.o \ - monodll_bmpbndl.o + monodll_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS = \ $(__LOWLEVEL_SRC_OBJECTS_1) \ @@ -4974,7 +4974,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS = \ monodll_calctrlg.o \ monodll_creddlgg.o \ monodll_rowheightcache.o \ - monodll_bmpbndl.o + monodll_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS = \ monodll_fontmgrcmn.o \ @@ -5257,7 +5257,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS = \ monodll_notifmsgrt.o \ monodll_uuid.o \ monodll_msw_evtloop.o \ - monodll_access.o + monodll_access.o \ + monodll_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS) @@ -6164,7 +6165,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_1 = \ monodll_notifmsgrt.o \ monodll_uuid.o \ monodll_msw_evtloop.o \ - monodll_access.o + monodll_access.o \ + monodll_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_1 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_1) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_1 = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS) @@ -6709,7 +6711,7 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_1 = \ monolib_calctrlg.o \ monolib_creddlgg.o \ monolib_rowheightcache.o \ - monolib_bmpbndl.o + monolib_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_1 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_1) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1 = \ $(__LOWLEVEL_SRC_OBJECTS_3) \ @@ -6972,7 +6974,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1 = \ monolib_calctrlg.o \ monolib_creddlgg.o \ monolib_rowheightcache.o \ - monolib_bmpbndl.o + monolib_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_1 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_2 = \ monolib_fontmgrcmn.o \ @@ -7255,7 +7257,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_2 = \ monolib_notifmsgrt.o \ monolib_uuid.o \ monolib_msw_evtloop.o \ - monolib_access.o + monolib_access.o \ + monolib_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_2 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_2) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_2 = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS_17) @@ -8162,7 +8165,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_3 = \ monolib_notifmsgrt.o \ monolib_uuid.o \ monolib_msw_evtloop.o \ - monolib_access.o + monolib_access.o \ + monolib_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_3 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_3) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_3 = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS_17) @@ -8860,7 +8864,7 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_2 = \ coredll_calctrlg.o \ coredll_creddlgg.o \ coredll_rowheightcache.o \ - coredll_bmpbndl.o + coredll_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_2 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_2) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2 = \ $(__LOWLEVEL_SRC_OBJECTS_5) \ @@ -9123,7 +9127,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2 = \ coredll_calctrlg.o \ coredll_creddlgg.o \ coredll_rowheightcache.o \ - coredll_bmpbndl.o + coredll_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_2 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_4 = \ coredll_fontmgrcmn.o \ @@ -9406,7 +9410,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_4 = \ coredll_notifmsgrt.o \ coredll_uuid.o \ coredll_msw_evtloop.o \ - coredll_access.o + coredll_access.o \ + coredll_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_4 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_4) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_4 = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS_1_1) @@ -10313,7 +10318,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_5 = \ coredll_notifmsgrt.o \ coredll_uuid.o \ coredll_msw_evtloop.o \ - coredll_access.o + coredll_access.o \ + coredll_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_5 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_5) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_5 = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS_1_1) @@ -10587,7 +10593,7 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_3 = \ corelib_calctrlg.o \ corelib_creddlgg.o \ corelib_rowheightcache.o \ - corelib_bmpbndl.o + corelib_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_3 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_3) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3 = \ $(__LOWLEVEL_SRC_OBJECTS_7) \ @@ -10850,7 +10856,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3 = \ corelib_calctrlg.o \ corelib_creddlgg.o \ corelib_rowheightcache.o \ - corelib_bmpbndl.o + corelib_common_bmpbndl.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_3 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_6 = \ corelib_fontmgrcmn.o \ @@ -11133,7 +11139,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_6 = \ corelib_notifmsgrt.o \ corelib_uuid.o \ corelib_msw_evtloop.o \ - corelib_access.o + corelib_access.o \ + corelib_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_6 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_6) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_6 = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS_1_4) @@ -12040,7 +12047,8 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_7 = \ corelib_notifmsgrt.o \ corelib_uuid.o \ corelib_msw_evtloop.o \ - corelib_access.o + corelib_access.o \ + corelib_msw_bmpbndl.o @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_7 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_7) @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_7 = \ @COND_TOOLKIT_OSX_COCOA@ $(__OSX_LOWLEVEL_SRC_OBJECTS_1_4) @@ -19034,6 +19042,9 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@monodll_access.o: $(srcdir)/src/msw/ole/access.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/ole/access.cpp +@COND_TOOLKIT_MSW_USE_GUI_1@monodll_msw_bmpbndl.o: $(srcdir)/src/msw/bmpbndl.cpp $(MONODLL_ODEP) +@COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/bmpbndl.cpp + @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@monodll_artmac.o: $(srcdir)/src/osx/artmac.cpp $(MONODLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/artmac.cpp @@ -21023,7 +21034,7 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@monodll_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp -@COND_USE_GUI_1@monodll_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONODLL_ODEP) +@COND_USE_GUI_1@monodll_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@monodll_osx_cocoa_mediactrl.o: $(srcdir)/src/osx/cocoa/mediactrl.mm $(MONODLL_ODEP) @@ -24326,6 +24337,9 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@monolib_access.o: $(srcdir)/src/msw/ole/access.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/ole/access.cpp +@COND_TOOLKIT_MSW_USE_GUI_1@monolib_msw_bmpbndl.o: $(srcdir)/src/msw/bmpbndl.cpp $(MONOLIB_ODEP) +@COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/bmpbndl.cpp + @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@monolib_artmac.o: $(srcdir)/src/osx/artmac.cpp $(MONOLIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/artmac.cpp @@ -26315,7 +26329,7 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@monolib_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp -@COND_USE_GUI_1@monolib_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONOLIB_ODEP) +@COND_USE_GUI_1@monolib_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@monolib_osx_cocoa_mediactrl.o: $(srcdir)/src/osx/cocoa/mediactrl.mm $(MONOLIB_ODEP) @@ -29723,6 +29737,9 @@ coredll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@coredll_access.o: $(srcdir)/src/msw/ole/access.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/msw/ole/access.cpp +@COND_TOOLKIT_MSW_USE_GUI_1@coredll_msw_bmpbndl.o: $(srcdir)/src/msw/bmpbndl.cpp $(COREDLL_ODEP) +@COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/msw/bmpbndl.cpp + @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@coredll_artmac.o: $(srcdir)/src/osx/artmac.cpp $(COREDLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/artmac.cpp @@ -31712,7 +31729,7 @@ coredll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(COREDLL_ODEP) @COND_USE_GUI_1@coredll_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(COREDLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp -@COND_USE_GUI_1@coredll_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(COREDLL_ODEP) +@COND_USE_GUI_1@coredll_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(COREDLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp corelib_event.o: $(srcdir)/src/common/event.cpp $(CORELIB_ODEP) @@ -33980,6 +33997,9 @@ corelib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@corelib_access.o: $(srcdir)/src/msw/ole/access.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/msw/ole/access.cpp +@COND_TOOLKIT_MSW_USE_GUI_1@corelib_msw_bmpbndl.o: $(srcdir)/src/msw/bmpbndl.cpp $(CORELIB_ODEP) +@COND_TOOLKIT_MSW_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/msw/bmpbndl.cpp + @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@corelib_artmac.o: $(srcdir)/src/osx/artmac.cpp $(CORELIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/artmac.cpp @@ -35969,7 +35989,7 @@ corelib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(CORELIB_ODEP) @COND_USE_GUI_1@corelib_rowheightcache.o: $(srcdir)/src/generic/rowheightcache.cpp $(CORELIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/rowheightcache.cpp -@COND_USE_GUI_1@corelib_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(CORELIB_ODEP) +@COND_USE_GUI_1@corelib_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(CORELIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp advdll_version_rc.o: $(srcdir)/src/msw/version.rc $(ADVDLL_ODEP) diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index a4d673f43a..56d67f4d0b 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2089,6 +2089,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/msw/ole/uuid.cpp src/msw/evtloop.cpp src/msw/ole/access.cpp + src/msw/bmpbndl.cpp wx/msw/nonownedwnd.h diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index b0ff257df4..3075665f09 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -1963,6 +1963,7 @@ set(MSW_LOWLEVEL_SRC src/msw/richtooltip.cpp src/msw/evtloop.cpp src/msw/ole/access.cpp + src/msw/bmpbndl.cpp ) set(MSW_LOWLEVEL_HDR diff --git a/build/files b/build/files index e8584a4cd6..299323c253 100644 --- a/build/files +++ b/build/files @@ -1903,6 +1903,7 @@ MSW_LOWLEVEL_SRC = src/msw/aboutdlg.cpp src/msw/app.cpp src/msw/bitmap.cpp + src/msw/bmpbndl.cpp src/msw/brush.cpp src/msw/caret.cpp src/msw/clipbrd.cpp diff --git a/build/msw/makefile.gcc b/build/msw/makefile.gcc index 438b69dd16..8eda39d271 100644 --- a/build/msw/makefile.gcc +++ b/build/msw/makefile.gcc @@ -1929,6 +1929,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_uuid.o \ $(OBJS)\monodll_evtloop.o \ $(OBJS)\monodll_access.o \ + $(OBJS)\monodll_msw_bmpbndl.o \ $(OBJS)\monodll_clrpickerg.o \ $(OBJS)\monodll_collpaneg.o \ $(OBJS)\monodll_filepickerg.o \ @@ -2202,7 +2203,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.o \ $(OBJS)\monodll_creddlgg.o \ $(OBJS)\monodll_rowheightcache.o \ - $(OBJS)\monodll_bmpbndl.o + $(OBJS)\monodll_common_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -2275,6 +2276,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_uuid.o \ $(OBJS)\monodll_evtloop.o \ $(OBJS)\monodll_access.o \ + $(OBJS)\monodll_msw_bmpbndl.o \ $(OBJS)\monodll_generic_accel.o \ $(OBJS)\monodll_clrpickerg.o \ $(OBJS)\monodll_collpaneg.o \ @@ -2533,7 +2535,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.o \ $(OBJS)\monodll_creddlgg.o \ $(OBJS)\monodll_rowheightcache.o \ - $(OBJS)\monodll_bmpbndl.o + $(OBJS)\monodll_common_bmpbndl.o endif endif ifeq ($(USE_STC),1) @@ -2773,6 +2775,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_uuid.o \ $(OBJS)\monolib_evtloop.o \ $(OBJS)\monolib_access.o \ + $(OBJS)\monolib_msw_bmpbndl.o \ $(OBJS)\monolib_clrpickerg.o \ $(OBJS)\monolib_collpaneg.o \ $(OBJS)\monolib_filepickerg.o \ @@ -3046,7 +3049,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.o \ $(OBJS)\monolib_creddlgg.o \ $(OBJS)\monolib_rowheightcache.o \ - $(OBJS)\monolib_bmpbndl.o + $(OBJS)\monolib_common_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -3119,6 +3122,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_uuid.o \ $(OBJS)\monolib_evtloop.o \ $(OBJS)\monolib_access.o \ + $(OBJS)\monolib_msw_bmpbndl.o \ $(OBJS)\monolib_generic_accel.o \ $(OBJS)\monolib_clrpickerg.o \ $(OBJS)\monolib_collpaneg.o \ @@ -3377,7 +3381,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.o \ $(OBJS)\monolib_creddlgg.o \ $(OBJS)\monolib_rowheightcache.o \ - $(OBJS)\monolib_bmpbndl.o + $(OBJS)\monolib_common_bmpbndl.o endif endif ifeq ($(USE_STC),1) @@ -3500,6 +3504,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_uuid.o \ $(OBJS)\coredll_evtloop.o \ $(OBJS)\coredll_access.o \ + $(OBJS)\coredll_msw_bmpbndl.o \ $(OBJS)\coredll_clrpickerg.o \ $(OBJS)\coredll_collpaneg.o \ $(OBJS)\coredll_filepickerg.o \ @@ -3773,7 +3778,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.o \ $(OBJS)\coredll_creddlgg.o \ $(OBJS)\coredll_rowheightcache.o \ - $(OBJS)\coredll_bmpbndl.o + $(OBJS)\coredll_common_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -3846,6 +3851,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_uuid.o \ $(OBJS)\coredll_evtloop.o \ $(OBJS)\coredll_access.o \ + $(OBJS)\coredll_msw_bmpbndl.o \ $(OBJS)\coredll_generic_accel.o \ $(OBJS)\coredll_clrpickerg.o \ $(OBJS)\coredll_collpaneg.o \ @@ -4104,7 +4110,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.o \ $(OBJS)\coredll_creddlgg.o \ $(OBJS)\coredll_rowheightcache.o \ - $(OBJS)\coredll_bmpbndl.o + $(OBJS)\coredll_common_bmpbndl.o endif endif ifeq ($(MONOLITHIC),0) @@ -4185,6 +4191,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_uuid.o \ $(OBJS)\corelib_evtloop.o \ $(OBJS)\corelib_access.o \ + $(OBJS)\corelib_msw_bmpbndl.o \ $(OBJS)\corelib_clrpickerg.o \ $(OBJS)\corelib_collpaneg.o \ $(OBJS)\corelib_filepickerg.o \ @@ -4458,7 +4465,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.o \ $(OBJS)\corelib_creddlgg.o \ $(OBJS)\corelib_rowheightcache.o \ - $(OBJS)\corelib_bmpbndl.o + $(OBJS)\corelib_common_bmpbndl.o endif endif ifeq ($(USE_GUI),1) @@ -4531,6 +4538,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_uuid.o \ $(OBJS)\corelib_evtloop.o \ $(OBJS)\corelib_access.o \ + $(OBJS)\corelib_msw_bmpbndl.o \ $(OBJS)\corelib_generic_accel.o \ $(OBJS)\corelib_clrpickerg.o \ $(OBJS)\corelib_collpaneg.o \ @@ -4789,7 +4797,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.o \ $(OBJS)\corelib_creddlgg.o \ $(OBJS)\corelib_rowheightcache.o \ - $(OBJS)\corelib_bmpbndl.o + $(OBJS)\corelib_common_bmpbndl.o endif endif ifeq ($(SHARED),1) @@ -8419,6 +8427,11 @@ $(OBJS)\monodll_access.o: ../../src/msw/ole/access.cpp $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\monodll_msw_bmpbndl.o: ../../src/msw/bmpbndl.cpp + $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< +endif + ifeq ($(USE_GUI),1) $(OBJS)\monodll_clrpickerg.o: ../../src/generic/clrpickerg.cpp $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< @@ -9465,7 +9478,7 @@ $(OBJS)\monodll_rowheightcache.o: ../../src/generic/rowheightcache.cpp endif ifeq ($(USE_GUI),1) -$(OBJS)\monodll_bmpbndl.o: ../../src/common/bmpbndl.cpp +$(OBJS)\monodll_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< endif @@ -10998,6 +11011,11 @@ $(OBJS)\monolib_access.o: ../../src/msw/ole/access.cpp $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\monolib_msw_bmpbndl.o: ../../src/msw/bmpbndl.cpp + $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< +endif + ifeq ($(USE_GUI),1) $(OBJS)\monolib_clrpickerg.o: ../../src/generic/clrpickerg.cpp $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< @@ -12044,7 +12062,7 @@ $(OBJS)\monolib_rowheightcache.o: ../../src/generic/rowheightcache.cpp endif ifeq ($(USE_GUI),1) -$(OBJS)\monolib_bmpbndl.o: ../../src/common/bmpbndl.cpp +$(OBJS)\monolib_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< endif @@ -13550,6 +13568,11 @@ $(OBJS)\coredll_access.o: ../../src/msw/ole/access.cpp $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\coredll_msw_bmpbndl.o: ../../src/msw/bmpbndl.cpp + $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< +endif + ifeq ($(USE_GUI),1) $(OBJS)\coredll_clrpickerg.o: ../../src/generic/clrpickerg.cpp $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< @@ -14596,7 +14619,7 @@ $(OBJS)\coredll_rowheightcache.o: ../../src/generic/rowheightcache.cpp endif ifeq ($(USE_GUI),1) -$(OBJS)\coredll_bmpbndl.o: ../../src/common/bmpbndl.cpp +$(OBJS)\coredll_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< endif @@ -15295,6 +15318,11 @@ $(OBJS)\corelib_access.o: ../../src/msw/ole/access.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\corelib_msw_bmpbndl.o: ../../src/msw/bmpbndl.cpp + $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< +endif + ifeq ($(USE_GUI),1) $(OBJS)\corelib_clrpickerg.o: ../../src/generic/clrpickerg.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< @@ -16341,7 +16369,7 @@ $(OBJS)\corelib_rowheightcache.o: ../../src/generic/rowheightcache.cpp endif ifeq ($(USE_GUI),1) -$(OBJS)\corelib_bmpbndl.o: ../../src/common/bmpbndl.cpp +$(OBJS)\corelib_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< endif diff --git a/build/msw/makefile.vc b/build/msw/makefile.vc index 8eafa88214..76456b188c 100644 --- a/build/msw/makefile.vc +++ b/build/msw/makefile.vc @@ -2259,6 +2259,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_uuid.obj \ $(OBJS)\monodll_evtloop.obj \ $(OBJS)\monodll_access.obj \ + $(OBJS)\monodll_msw_bmpbndl.obj \ $(OBJS)\monodll_clrpickerg.obj \ $(OBJS)\monodll_collpaneg.obj \ $(OBJS)\monodll_filepickerg.obj \ @@ -2532,7 +2533,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.obj \ $(OBJS)\monodll_creddlgg.obj \ $(OBJS)\monodll_rowheightcache.obj \ - $(OBJS)\monodll_bmpbndl.obj + $(OBJS)\monodll_common_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_OBJECTS = \ @@ -2603,6 +2604,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_uuid.obj \ $(OBJS)\monodll_evtloop.obj \ $(OBJS)\monodll_access.obj \ + $(OBJS)\monodll_msw_bmpbndl.obj \ $(OBJS)\monodll_generic_accel.obj \ $(OBJS)\monodll_clrpickerg.obj \ $(OBJS)\monodll_collpaneg.obj \ @@ -2861,7 +2863,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.obj \ $(OBJS)\monodll_creddlgg.obj \ $(OBJS)\monodll_rowheightcache.obj \ - $(OBJS)\monodll_bmpbndl.obj + $(OBJS)\monodll_common_bmpbndl.obj !endif !if "$(USE_STC)" == "1" ____MONOLIB_STC_SRC_FILENAMES_OBJECTS = \ @@ -3103,6 +3105,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_uuid.obj \ $(OBJS)\monolib_evtloop.obj \ $(OBJS)\monolib_access.obj \ + $(OBJS)\monolib_msw_bmpbndl.obj \ $(OBJS)\monolib_clrpickerg.obj \ $(OBJS)\monolib_collpaneg.obj \ $(OBJS)\monolib_filepickerg.obj \ @@ -3376,7 +3379,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.obj \ $(OBJS)\monolib_creddlgg.obj \ $(OBJS)\monolib_rowheightcache.obj \ - $(OBJS)\monolib_bmpbndl.obj + $(OBJS)\monolib_common_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_1_OBJECTS = \ @@ -3447,6 +3450,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_uuid.obj \ $(OBJS)\monolib_evtloop.obj \ $(OBJS)\monolib_access.obj \ + $(OBJS)\monolib_msw_bmpbndl.obj \ $(OBJS)\monolib_generic_accel.obj \ $(OBJS)\monolib_clrpickerg.obj \ $(OBJS)\monolib_collpaneg.obj \ @@ -3705,7 +3709,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.obj \ $(OBJS)\monolib_creddlgg.obj \ $(OBJS)\monolib_rowheightcache.obj \ - $(OBJS)\monolib_bmpbndl.obj + $(OBJS)\monolib_common_bmpbndl.obj !endif !if "$(USE_STC)" == "1" ____MONOLIB_STC_SRC_FILENAMES_1_OBJECTS = \ @@ -3880,6 +3884,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_uuid.obj \ $(OBJS)\coredll_evtloop.obj \ $(OBJS)\coredll_access.obj \ + $(OBJS)\coredll_msw_bmpbndl.obj \ $(OBJS)\coredll_clrpickerg.obj \ $(OBJS)\coredll_collpaneg.obj \ $(OBJS)\coredll_filepickerg.obj \ @@ -4153,7 +4158,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.obj \ $(OBJS)\coredll_creddlgg.obj \ $(OBJS)\coredll_rowheightcache.obj \ - $(OBJS)\coredll_bmpbndl.obj + $(OBJS)\coredll_common_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_2_OBJECTS = \ @@ -4224,6 +4229,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_uuid.obj \ $(OBJS)\coredll_evtloop.obj \ $(OBJS)\coredll_access.obj \ + $(OBJS)\coredll_msw_bmpbndl.obj \ $(OBJS)\coredll_generic_accel.obj \ $(OBJS)\coredll_clrpickerg.obj \ $(OBJS)\coredll_collpaneg.obj \ @@ -4482,7 +4488,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.obj \ $(OBJS)\coredll_creddlgg.obj \ $(OBJS)\coredll_rowheightcache.obj \ - $(OBJS)\coredll_bmpbndl.obj + $(OBJS)\coredll_common_bmpbndl.obj !endif !if "$(MONOLITHIC)" == "0" && "$(SHARED)" == "0" && "$(USE_GUI)" == "1" __corelib___depname = \ @@ -4563,6 +4569,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_uuid.obj \ $(OBJS)\corelib_evtloop.obj \ $(OBJS)\corelib_access.obj \ + $(OBJS)\corelib_msw_bmpbndl.obj \ $(OBJS)\corelib_clrpickerg.obj \ $(OBJS)\corelib_collpaneg.obj \ $(OBJS)\corelib_filepickerg.obj \ @@ -4836,7 +4843,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.obj \ $(OBJS)\corelib_creddlgg.obj \ $(OBJS)\corelib_rowheightcache.obj \ - $(OBJS)\corelib_bmpbndl.obj + $(OBJS)\corelib_common_bmpbndl.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_3_OBJECTS = \ @@ -4907,6 +4914,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_uuid.obj \ $(OBJS)\corelib_evtloop.obj \ $(OBJS)\corelib_access.obj \ + $(OBJS)\corelib_msw_bmpbndl.obj \ $(OBJS)\corelib_generic_accel.obj \ $(OBJS)\corelib_clrpickerg.obj \ $(OBJS)\corelib_collpaneg.obj \ @@ -5165,7 +5173,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.obj \ $(OBJS)\corelib_creddlgg.obj \ $(OBJS)\corelib_rowheightcache.obj \ - $(OBJS)\corelib_bmpbndl.obj + $(OBJS)\corelib_common_bmpbndl.obj !endif !if "$(SHARED)" == "1" ____wxcore_namedll_DEP = $(__coredll___depname) @@ -8850,6 +8858,11 @@ $(OBJS)\monodll_access.obj: ..\..\src\msw\ole\access.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\ole\access.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\monodll_msw_bmpbndl.obj: ..\..\src\msw\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\bmpbndl.cpp +!endif + !if "$(USE_GUI)" == "1" $(OBJS)\monodll_clrpickerg.obj: ..\..\src\generic\clrpickerg.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\generic\clrpickerg.cpp @@ -9896,7 +9909,7 @@ $(OBJS)\monodll_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp !endif !if "$(USE_GUI)" == "1" -$(OBJS)\monodll_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp +$(OBJS)\monodll_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif @@ -11429,6 +11442,11 @@ $(OBJS)\monolib_access.obj: ..\..\src\msw\ole\access.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\ole\access.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\monolib_msw_bmpbndl.obj: ..\..\src\msw\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\bmpbndl.cpp +!endif + !if "$(USE_GUI)" == "1" $(OBJS)\monolib_clrpickerg.obj: ..\..\src\generic\clrpickerg.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\generic\clrpickerg.cpp @@ -12475,7 +12493,7 @@ $(OBJS)\monolib_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp !endif !if "$(USE_GUI)" == "1" -$(OBJS)\monolib_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp +$(OBJS)\monolib_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif @@ -13981,6 +13999,11 @@ $(OBJS)\coredll_access.obj: ..\..\src\msw\ole\access.cpp $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\ole\access.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\coredll_msw_bmpbndl.obj: ..\..\src\msw\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\bmpbndl.cpp +!endif + !if "$(USE_GUI)" == "1" $(OBJS)\coredll_clrpickerg.obj: ..\..\src\generic\clrpickerg.cpp $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\generic\clrpickerg.cpp @@ -15027,7 +15050,7 @@ $(OBJS)\coredll_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp !endif !if "$(USE_GUI)" == "1" -$(OBJS)\coredll_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp +$(OBJS)\coredll_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif @@ -15726,6 +15749,11 @@ $(OBJS)\corelib_access.obj: ..\..\src\msw\ole\access.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\ole\access.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\corelib_msw_bmpbndl.obj: ..\..\src\msw\bmpbndl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\bmpbndl.cpp +!endif + !if "$(USE_GUI)" == "1" $(OBJS)\corelib_clrpickerg.obj: ..\..\src\generic\clrpickerg.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\generic\clrpickerg.cpp @@ -16772,7 +16800,7 @@ $(OBJS)\corelib_rowheightcache.obj: ..\..\src\generic\rowheightcache.cpp !endif !if "$(USE_GUI)" == "1" -$(OBJS)\corelib_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp +$(OBJS)\corelib_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif diff --git a/build/msw/wx_core.vcxproj b/build/msw/wx_core.vcxproj index 6ccddecfb6..6a396f1fc0 100644 --- a/build/msw/wx_core.vcxproj +++ b/build/msw/wx_core.vcxproj @@ -603,6 +603,16 @@ $(IntDir)msw_%(Filename).obj $(IntDir)msw_%(Filename).obj + + $(IntDir)msw_%(Filename).obj + $(IntDir)msw_%(Filename).obj + $(IntDir)msw_%(Filename).obj + $(IntDir)msw_%(Filename).obj + $(IntDir)msw_%(Filename).obj + $(IntDir)msw_%(Filename).obj + $(IntDir)msw_%(Filename).obj + $(IntDir)msw_%(Filename).obj + @@ -1511,4 +1521,4 @@ - + \ No newline at end of file diff --git a/build/msw/wx_core.vcxproj.filters b/build/msw/wx_core.vcxproj.filters index f743597569..f6e858df48 100644 --- a/build/msw/wx_core.vcxproj.filters +++ b/build/msw/wx_core.vcxproj.filters @@ -1071,6 +1071,9 @@ Common Sources + + MSW Sources + diff --git a/build/msw/wx_vc8_core.vcproj b/build/msw/wx_vc8_core.vcproj index c835118cb6..5673f9fe19 100644 --- a/build/msw/wx_vc8_core.vcproj +++ b/build/msw/wx_vc8_core.vcproj @@ -788,6 +788,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj index 730f268991..fa37b4e5f4 100644 --- a/build/msw/wx_vc9_core.vcproj +++ b/build/msw/wx_vc9_core.vcproj @@ -784,6 +784,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index db041ad375..ef2e8dde2d 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -59,6 +59,10 @@ public: static wxBitmapBundle FromBitmap(const wxBitmap& bitmap); static wxBitmapBundle FromImage(const wxImage& image); + // Create from the resources: all existing versions of the bitmap of the + // form name_2x or name@2x (and also using other factors) will be used. + static wxBitmapBundle FromResources(const wxString& name); + // Check if bitmap bundle is non-empty. bool IsOk() const { return m_impl; } @@ -83,6 +87,16 @@ private: wxBitmapBundleImplPtr m_impl; }; +// This macro can be used to create a bundle from resources on the platforms +// that support it and from name_png and name_2x_png on the other ones. +#ifdef wxHAS_IMAGE_RESOURCES + #define wxBITMAP_BUNDLE_2(name) wxBitmapBundle::FromResources(#name) +#else + #define wxBITMAP_BUNDLE_2(name) \ + wxBitmapBundle::FromBitmaps(wxBITMAP_PNG_FROM_DATA(name), \ + wxBITMAP_PNG_FROM_DATA(name##_2x)) +#endif + // Inline functions implementation. /* static */ inline diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h index 3b95a74c7a..8f28a630dc 100644 --- a/interface/wx/bmpbndl.h +++ b/interface/wx/bmpbndl.h @@ -61,6 +61,22 @@ by including a file generated with @c bin2c (see wxBITMAP_PNG_FROM_DATA()), on the other platforms. + For the platforms with resources support, you can also create the bundle + from the bitmaps defined in the resources, which has the advantage of not + having to explicitly list all the bitmaps, e.g. the code above becomes + @code + #ifdef wxHAS_IMAGE_RESOURCES + toolBar->AddTool(wxID_OPEN, wxBitmapBundle::FromResources("open")); + #else + ... same code as shown above ... + #endif + @endcode + and will load all resources called @c open, @c open_2x, @c open_1_5x etc + (at least the first one of them must be available). See also + wxBITMAP_BUNDLE_2() macro which can avoid the need to check for + wxHAS_IMAGE_RESOURCES explicitly in the code in a common case of having + only 2 embedded resources (for standard and high DPI). + Also note that the existing code using wxBitmap is compatible with the functions taking wxBitmapBundle in wxWidgets 3.1.6 and later because bitmaps are implicitly convertible to the objects of this class, so just @@ -145,6 +161,21 @@ public: */ static wxBitmapBundle FromImage(const wxImage& image); + /** + Create a bundle from the bitmaps in the application resources. + + This function can only be used on the platforms supporting storing + bitmaps in resources, and currently only works under MSW and simply + returns an empty bundle on the other platforms. + + Under MSW, for this function to create a valid bundle, you must have @c + RCDATA resource with the given @a name in your application resource + file (with the extension @c .rc) containing PNG file, and any other + resources using @a name as prefix and suffix with the scale, e.g. "_2x" + or "_1_5x" (for 150% DPI) will be also loaded as part of the bundle. + */ + static wxBitmapBundle FromResources(const wxString& name); + /** Check if bitmap bundle is non-empty. @@ -177,3 +208,28 @@ public: */ wxBitmap GetBitmap(const wxSize size) const; }; + +/** + Creates a wxBitmapBundle from resources on the platforms supporting them or + from two embedded bitmaps otherwise. + + This macro use wxBitmapBundle::FromResources() with the provide @a name, + which must be an @e identifier and not a string, i.e. used without quotes, + on the platforms where it works and wxBitmapBundle::FromBitmaps() with @c + name_png and @c name_2x_png arrays containing PNG data elsewhere. + + Using it allows to avoid using preprocessor checks in the common case when + just two bitmaps (for standard and high DPI) are embedded in the + application code. Note that all bitmaps defined in the resources, even if + there are more than 2 of them. + + Example of use: + @code + toolBar->AddTool(wxID_OPEN, wxBITMAP_BUNDLE_2(open)); + @endcode + + @header{wx/bmpbndl.h} + + @since 3.1.6 + */ +#define wxBITMAP_BUNDLE_2(name) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 300cc1b4ca..22490a3b6b 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -51,8 +51,9 @@ #include "../sample.xpm" #endif // !wxHAS_IMAGES_IN_RESOURCES -// Temporarily embed bitmaps in the program itself on all platforms. -#if 1 // ndef wxHAS_IMAGE_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/open_png.c" #include "bitmaps/save_png.c" @@ -391,21 +392,22 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) wxBitmapBundle toolBarBitmaps[Tool_Max]; - // This macro relies on having name_png and name_2x_png arrays defined, - // (this is done in this sample by including the corresponding *_png.c files - // above). - #define BUNDLE_2(name) \ - wxBitmapBundle::FromBitmaps(wxBITMAP_PNG_FROM_DATA(name), \ - wxBITMAP_PNG_FROM_DATA(name##_2x)) - - toolBarBitmaps[Tool_new ] = BUNDLE_2(new ); - toolBarBitmaps[Tool_open ] = BUNDLE_2(open ); - toolBarBitmaps[Tool_save ] = BUNDLE_2(save ); - toolBarBitmaps[Tool_copy ] = BUNDLE_2(copy ); - toolBarBitmaps[Tool_cut ] = BUNDLE_2(cut ); - toolBarBitmaps[Tool_paste] = BUNDLE_2(paste); - toolBarBitmaps[Tool_print] = BUNDLE_2(print); - toolBarBitmaps[Tool_help ] = BUNDLE_2(help ); + // Note that to use wxBITMAP_BUNDLE_2() macro it is necessary to + // + // 1. Have resources (either RT_RCDATA under MSW or files in the app + // bundle resources subdirectory under Mac) with this name. + // + // 2. Have name_png and name_2x_png arrays defined under the other + // platforms (as is done in this sample by including the corresponding + // *_png.c files above). + toolBarBitmaps[Tool_new ] = wxBITMAP_BUNDLE_2(new ); + toolBarBitmaps[Tool_open ] = wxBITMAP_BUNDLE_2(open ); + toolBarBitmaps[Tool_save ] = wxBITMAP_BUNDLE_2(save ); + toolBarBitmaps[Tool_copy ] = wxBITMAP_BUNDLE_2(copy ); + toolBarBitmaps[Tool_cut ] = wxBITMAP_BUNDLE_2(cut ); + toolBarBitmaps[Tool_paste] = wxBITMAP_BUNDLE_2(paste); + toolBarBitmaps[Tool_print] = wxBITMAP_BUNDLE_2(print); + toolBarBitmaps[Tool_help ] = wxBITMAP_BUNDLE_2(help ); // Size of the bitmaps we use by default. int w = 32, diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp index c594747f8d..2e926f352c 100644 --- a/src/common/bmpbndl.cpp +++ b/src/common/bmpbndl.cpp @@ -244,6 +244,24 @@ wxBitmapBundle wxBitmapBundle::FromBitmaps(const wxVector& bitmaps) return wxBitmapBundle(new wxBitmapBundleImplSet(bitmaps)); } +// MSW has its own, actually working, version, in MSW-specific code. +#ifndef __WXMSW__ + +/* static */ +wxBitmapBundle wxBitmapBundle::FromResources(const wxString& WXUNUSED(name)) +{ + wxFAIL_MSG + ( + "Loading bitmaps from resources not available on this platform, " + "don't use this function and call wxBitmapBundle::FromBitmaps() " + "instead." + ); + + return wxBitmapBundle(); +} + +#endif // __WXMSW__ + wxSize wxBitmapBundle::GetDefaultSize() const { if ( !m_impl ) diff --git a/src/msw/bmpbndl.cpp b/src/msw/bmpbndl.cpp new file mode 100644 index 0000000000..1bba6e3668 --- /dev/null +++ b/src/msw/bmpbndl.cpp @@ -0,0 +1,307 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/msw/bmpbndl.cpp +// Purpose: MSW-specific part of wxBitmapBundle class. +// Author: Vadim Zeitlin +// Created: 2021-09-22 +// Copyright: (c) 2021 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + + #include "wx/msw/wrapwin.h" +#endif // WX_PRECOMP + +#include "wx/bmpbndl.h" + +#include "wx/private/bmpbndl.h" + +#include + +// ---------------------------------------------------------------------------- +// private helpers +// ---------------------------------------------------------------------------- + +namespace +{ + +// Helper function, which will probably need to be factored out as it's likely +// to be useful elsewhere, returning the scale determined by the given suffix, +// i.e. it returns 2 for the suffix of "_2x" or 1.5 for "_1_5x". +// +// Returns 1 if the suffix is empty or 0 if it doesn't look like a valid scale +// suffix at all. +double GetScaleFromSuffix(const wxString& suffix) +{ + if ( suffix.empty() ) + return 1.0; + + if ( *suffix.begin() != '_' ) + return 0; + + if ( *suffix.rbegin() != 'x' ) + return 0; + + wxString factor = suffix.substr(1, suffix.length() - 2); + if ( factor.empty() ) + return 0; + + factor.Replace(wxS("_"), wxS(".")); + + double d; + if ( !factor.ToCDouble(&d) ) + return 0; + + return d; +} + +// Just a bitmap name and the corresponding scale for some resource. +struct ResourceInfo +{ + ResourceInfo(const wxString& name_, double scale_) + : name(name_), scale(scale_) + { + } + + wxString name; + double scale; +}; + +// Predicate for std::sort() comparing resource infos using their scale. +struct ScaleComparator +{ + bool operator()(const ResourceInfo& info1, const ResourceInfo& info2) const + { + return info1.scale < info2.scale; + } +}; + +typedef wxVector ResourceInfos; + +// Used to pass information to EnumRCBitmaps() callback. +struct RCEnumCallbackData +{ + explicit RCEnumCallbackData(const wxString& name_) + : name(name_.Lower()) + { + } + + // The base name of all resources, passed to the callback. + wxString name; + + // All the existing bitmaps starting with this name and using a valid scale + // suffix, filled by the callback. + ResourceInfos resourceInfos; +}; + +BOOL CALLBACK EnumRCBitmaps(HMODULE WXUNUSED(hModule), + LPCTSTR WXUNUSED(lpszType), + LPTSTR lpszName, + LONG_PTR lParam) +{ + wxString name(lpszName); + name.MakeLower(); // resource names are case insensitive + + RCEnumCallbackData *data = reinterpret_cast(lParam); + + wxString suffix; + if ( name.StartsWith(data->name, &suffix) ) + { + const double scale = GetScaleFromSuffix(suffix); + if ( scale ) + data->resourceInfos.push_back(ResourceInfo(name, scale)); + } + + return TRUE; // continue enumeration +} + +// Bundle implementation using PNG bitmaps from Windows resources. +class wxBitmapBundleImplRC : public wxBitmapBundleImpl +{ +public: + // Ctor takes the vector containing all the existing resources starting + // with the given name and the valid bitmap corresponding to the base name + // resource itself. + wxBitmapBundleImplRC(const ResourceInfos& resourceInfos, + const wxBitmap& bitmap); + + virtual wxSize GetDefaultSize() const wxOVERRIDE; + virtual wxBitmap GetBitmap(const wxSize size) wxOVERRIDE; + +private: + // Load the bitmap from the given resource and add it m_bitmaps, after + // rescaling it to the given size if necessary, i.e. if the needed size is + // different from the size of this bitmap itself. + // + // The expected size is used to confirm that the resource really has the + // size we expect it to have. + // + // Return the just loaded bitmap. + wxBitmap + AddBitmap(const ResourceInfo& info, + const wxSize& sizeExpected, + const wxSize& sizeNeeded); + + + // All the available resources. + const ResourceInfos m_resourceInfos; + + // All already loaded bitmaps sorted by their size. + // + // This vector is never empty and its first element is the bitmap using the + // default size. + wxVector m_bitmaps; + + wxDECLARE_NO_COPY_CLASS(wxBitmapBundleImplRC); +}; + +} // anonymous namespace + +// ============================================================================ +// wxBitmapBundleImplRC implementation +// ============================================================================ + +wxBitmapBundleImplRC::wxBitmapBundleImplRC(const ResourceInfos& resourceInfos, + const wxBitmap& bitmap) + : m_resourceInfos(resourceInfos) +{ + m_bitmaps.push_back(bitmap); +} + +wxSize wxBitmapBundleImplRC::GetDefaultSize() const +{ + return m_bitmaps[0].GetSize(); +} + +wxBitmap +wxBitmapBundleImplRC::AddBitmap(const ResourceInfo& info, + const wxSize& sizeExpected, + const wxSize& sizeNeeded) +{ + // First load the bitmap, it shouldn't fail, but we can't do much if it + // does fail -- we're just going to return an invalid bitmap in this case. + wxBitmap bitmap(info.name, wxBITMAP_TYPE_PNG_RESOURCE); + + // We rely on suffixes really corresponding to the bitmap sizes and bad + // things will happen if they don't. + wxASSERT_MSG + ( + bitmap.GetSize() == sizeExpected, + wxString::Format(wxS("Bitmap \"%s\" should have size %d*%d."), + sizeExpected.x, sizeExpected.y) + ); + + if ( sizeNeeded != sizeExpected ) + wxBitmap::Rescale(bitmap, sizeNeeded); + + + // Now cache the bitmap for future use by inserting it into our sorted + // vector of bitmaps. We don't bother with the binary search here because + // the vector is typically very small (< 10 elements). + const wxSize sizeThis = bitmap.GetSize(); + for ( size_t i = 0; ; ++i ) + { + if ( i == m_bitmaps.size() ) + { + // This is the biggest bitmap we have, put it at the end. + m_bitmaps.push_back(bitmap); + break; + } + + if ( m_bitmaps[i].GetSize().y > sizeThis.y ) + { + m_bitmaps.insert(m_bitmaps.begin() + i, bitmap); + break; + } + } + + return bitmap; +} + +wxBitmap wxBitmapBundleImplRC::GetBitmap(const wxSize size) +{ + // First check if we already have the bitmap of this size: we're only + // interested in the exact match here. + for ( size_t i = 0; i < m_bitmaps.size(); ++i ) + { + const wxBitmap& bitmap = m_bitmaps[i]; + + if ( bitmap.GetSize() == size ) + return bitmap; + } + + // If we don't have one, create it using one of the available resources. + // Here we try to find the exact match (ideal) or the next larger size + // (downscaling results in better appearance than upscaling, generally + // speaking). + const wxSize sizeDef = GetDefaultSize(); + for ( size_t i = 0; i < m_resourceInfos.size(); ++i ) + { + const ResourceInfo& info = m_resourceInfos[i]; + + const wxSize sizeThis = sizeDef*info.scale; + + // Use this bitmap if it's the first one bigger than the requested size + // or if it's the last item as in this case we're not going to find any + // bitmap bigger than the given one anyhow and we don't have any choice + // but to upscale the largest one we have. + if ( sizeThis.y >= size.y || i + 1 == m_resourceInfos.size() ) + return AddBitmap(info, sizeThis, size); + } + + wxFAIL_MSG( wxS("unreachable") ); + + return wxBitmap(); +} + +// ============================================================================ +// wxBitmapBundle::FromResources() implementation +// ============================================================================ + +/* static */ +wxBitmapBundle wxBitmapBundle::FromResources(const wxString& name) +{ + // First of all, find all resources starting with this name. + RCEnumCallbackData data(name); + + if ( !::EnumResourceNames(NULL, // this HMODULE + RT_RCDATA, + EnumRCBitmaps, + reinterpret_cast(&data)) ) + { + const DWORD err = ::GetLastError(); + if ( err != NO_ERROR && err != ERROR_RESOURCE_TYPE_NOT_FOUND ) + { + wxLogSysError(wxS("Couldn't enumerate RCDATA resources")); + } + } + + ResourceInfos& resourceInfos = data.resourceInfos; + + if ( resourceInfos.empty() ) + return wxBitmapBundle(); + + // We need to load the base bitmap to get the default size anyhow, so do it + // now and also check that it works. + wxBitmap bitmap(name, wxBITMAP_TYPE_PNG_RESOURCE); + if ( !bitmap.IsOk() ) + return wxBitmapBundle(); + + // Sort the resources in the order of increasing sizes to simplify the code + // of wxBitmapBundleImplRC::GetBitmap(). + std::sort(resourceInfos.begin(), resourceInfos.end(), ScaleComparator()); + + return wxBitmapBundle(new wxBitmapBundleImplRC(resourceInfos, bitmap)); +} From 7337bf1da124e58b99252cfc50e6b291a48fd5b2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Sep 2021 19:15:02 +0200 Subject: [PATCH 03/18] Add a simple wxBitmapBundle unit test Check for the minimal functionality when using vector-based implementation. --- tests/Makefile.in | 4 +++ tests/graphics/bmpbundle.cpp | 48 ++++++++++++++++++++++++++++++++++ tests/makefile.gcc | 4 +++ tests/makefile.vc | 4 +++ tests/test.bkl | 1 + tests/test_gui.vcxproj | 1 + tests/test_gui.vcxproj.filters | 5 +++- tests/test_vc8_test_gui.vcproj | 4 +++ tests/test_vc9_test_gui.vcproj | 4 +++ 9 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/graphics/bmpbundle.cpp diff --git a/tests/Makefile.in b/tests/Makefile.in index 41e448c2b8..afefe8f5f7 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -183,6 +183,7 @@ TEST_GUI_OBJECTS = \ test_gui_point.o \ test_gui_region.o \ test_gui_bitmap.o \ + test_gui_bmpbundle.o \ test_gui_colour.o \ test_gui_ellipsization.o \ test_gui_measuring.o \ @@ -904,6 +905,9 @@ test_gui_region.o: $(srcdir)/geometry/region.cpp $(TEST_GUI_ODEP) test_gui_bitmap.o: $(srcdir)/graphics/bitmap.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/bitmap.cpp +test_gui_bmpbundle.o: $(srcdir)/graphics/bmpbundle.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/bmpbundle.cpp + test_gui_colour.o: $(srcdir)/graphics/colour.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/colour.cpp diff --git a/tests/graphics/bmpbundle.cpp b/tests/graphics/bmpbundle.cpp new file mode 100644 index 0000000000..aa79c4a560 --- /dev/null +++ b/tests/graphics/bmpbundle.cpp @@ -0,0 +1,48 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/graphics/bmpbundle.cpp +// Purpose: wxBitmapBundle unit test +// Author: Vadim Zeitlin +// Created: 2021-09-27 +// Copyright: (c) 2021 Vadim Zeitlin +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#include "wx/bmpbndl.h" + +#include "asserthelper.h" + +// ---------------------------------------------------------------------------- +// tests +// ---------------------------------------------------------------------------- + +TEST_CASE("BitmapBundle::Create", "[bmpbundle]") +{ + wxBitmapBundle b; + CHECK( !b.IsOk() ); + CHECK( b.GetDefaultSize() == wxDefaultSize ); + + b = wxBitmap(16, 16); + CHECK( b.IsOk() ); + CHECK( b.GetDefaultSize() == wxSize(16, 16) ); +} + +TEST_CASE("BitmapBundle::FromBitmaps", "[bmpbundle]") +{ + wxVector bitmaps; + bitmaps.push_back(wxBitmap(16, 16)); + bitmaps.push_back(wxBitmap(24, 24)); + + wxBitmapBundle b = wxBitmapBundle::FromBitmaps(bitmaps); + REQUIRE( b.IsOk() ); + CHECK( b.GetDefaultSize() == wxSize(16, 16) ); + + CHECK( b.GetBitmap(wxDefaultSize ).GetSize() == wxSize(16, 16) ); + CHECK( b.GetBitmap(wxSize(16, 16)).GetSize() == wxSize(16, 16) ); + CHECK( b.GetBitmap(wxSize(20, 20)).GetSize() == wxSize(20, 20) ); + CHECK( b.GetBitmap(wxSize(24, 24)).GetSize() == wxSize(24, 24) ); +} diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 99f099a87b..8b0ebd8054 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -157,6 +157,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_point.o \ $(OBJS)\test_gui_region.o \ $(OBJS)\test_gui_bitmap.o \ + $(OBJS)\test_gui_bmpbundle.o \ $(OBJS)\test_gui_colour.o \ $(OBJS)\test_gui_ellipsization.o \ $(OBJS)\test_gui_measuring.o \ @@ -879,6 +880,9 @@ $(OBJS)\test_gui_region.o: ./geometry/region.cpp $(OBJS)\test_gui_bitmap.o: ./graphics/bitmap.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_bmpbundle.o: ./graphics/bmpbundle.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_colour.o: ./graphics/colour.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 83e5888831..8e656f802a 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -173,6 +173,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_point.obj \ $(OBJS)\test_gui_region.obj \ $(OBJS)\test_gui_bitmap.obj \ + $(OBJS)\test_gui_bmpbundle.obj \ $(OBJS)\test_gui_colour.obj \ $(OBJS)\test_gui_ellipsization.obj \ $(OBJS)\test_gui_measuring.obj \ @@ -1313,6 +1314,9 @@ $(OBJS)\test_gui_region.obj: .\geometry\region.cpp $(OBJS)\test_gui_bitmap.obj: .\graphics\bitmap.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\bitmap.cpp +$(OBJS)\test_gui_bmpbundle.obj: .\graphics\bmpbundle.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\bmpbundle.cpp + $(OBJS)\test_gui_colour.obj: .\graphics\colour.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\colour.cpp diff --git a/tests/test.bkl b/tests/test.bkl index d4b7e2d829..49fbc02f34 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -177,6 +177,7 @@ geometry/point.cpp geometry/region.cpp graphics/bitmap.cpp + graphics/bmpbundle.cpp graphics/colour.cpp graphics/ellipsization.cpp graphics/measuring.cpp diff --git a/tests/test_gui.vcxproj b/tests/test_gui.vcxproj index 7fdbe59b5b..c98fd7fce8 100644 --- a/tests/test_gui.vcxproj +++ b/tests/test_gui.vcxproj @@ -545,6 +545,7 @@ + diff --git a/tests/test_gui.vcxproj.filters b/tests/test_gui.vcxproj.filters index 4528b32f47..25a943ac30 100644 --- a/tests/test_gui.vcxproj.filters +++ b/tests/test_gui.vcxproj.filters @@ -23,6 +23,9 @@ Source Files + + Source Files + Source Files @@ -320,4 +323,4 @@ Resource Files - \ No newline at end of file + diff --git a/tests/test_vc8_test_gui.vcproj b/tests/test_vc8_test_gui.vcproj index db9e9d3d4c..150f9f8879 100644 --- a/tests/test_vc8_test_gui.vcproj +++ b/tests/test_vc8_test_gui.vcproj @@ -858,6 +858,10 @@ RelativePath=".\controls\bitmaptogglebuttontest.cpp" > + + diff --git a/tests/test_vc9_test_gui.vcproj b/tests/test_vc9_test_gui.vcproj index 867da681f6..64c7eced6f 100644 --- a/tests/test_vc9_test_gui.vcproj +++ b/tests/test_vc9_test_gui.vcproj @@ -830,6 +830,10 @@ RelativePath=".\controls\bitmaptogglebuttontest.cpp" > + + From 9a578b9c8f50972a1d46755b63878a004a2e6311 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Sep 2021 18:41:45 +0100 Subject: [PATCH 04/18] Update bitmap size automatically on DPI change in wxMSW wxToolBar Remove the now unnecessary wxEVT_DPI_CHANGED event handler in the sample. --- samples/toolbar/toolbar.cpp | 12 ------------ src/msw/toolbar.cpp | 4 ++++ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 22490a3b6b..d002567538 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -111,7 +111,6 @@ public: void OnAbout(wxCommandEvent& event); void OnSize(wxSizeEvent& event); - void OnDPIChanged(wxDPIChangedEvent& event); void OnToggleToolbar(wxCommandEvent& event); void OnToggleAnotherToolbar(wxCommandEvent& event); @@ -242,7 +241,6 @@ enum wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_SIZE(MyFrame::OnSize) - EVT_DPI_CHANGED(MyFrame::OnDPIChanged) EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_MENU(wxID_HELP, MyFrame::OnAbout) @@ -698,16 +696,6 @@ void MyFrame::OnSize(wxSizeEvent& event) } } -void MyFrame::OnDPIChanged(wxDPIChangedEvent& event) -{ - event.Skip(); - - // We check the DPI scaling factor when the toolbar is created, so just - // recreate it whenever DPI changes. We could also just update the tools - // bitmaps, but this is simpler and doesn't have any significant drawbacks. - RecreateToolbar(); -} - void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) { wxToolBar *tbar = GetToolBar(); diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 36d5840058..fe7b8f49d2 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1949,6 +1949,10 @@ void wxToolBar::RealizeHelper() void wxToolBar::OnDPIChanged(wxDPIChangedEvent& event) { + // Ensure that when Realize() is called, the bitmaps size corresponding to + // the new resolution will be used. + SetToolBitmapSize(event.Scale(wxSize(m_defaultWidth, m_defaultHeight))); + // Manually scale the size of the controls. Even though the font has been // updated, the internal size of the controls does not. wxToolBarToolsList::compatibility_iterator node; From 24df75a27f1263386908a660673f99c9dbcea9d0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Sep 2021 18:47:50 +0100 Subject: [PATCH 05/18] Simplify frame construction in the toolbar sample Also stop hard-coding (100, 100) position for it, there is no real need for it and it's better to let the window be positioned automatically. No real changes. --- samples/toolbar/toolbar.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index d002567538..cc4e489deb 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -96,12 +96,7 @@ public: class MyFrame: public wxFrame { public: - MyFrame(wxFrame *parent, - wxWindowID id = wxID_ANY, - const wxString& title = "wxToolBar Sample", - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN); + MyFrame(); virtual ~MyFrame(); void PopulateToolbar(wxToolBarBase* toolBar); @@ -312,9 +307,7 @@ bool MyApp::OnInit() wxImage::AddHandler(new wxPNGHandler); // Create the main frame window - MyFrame* frame = new MyFrame((wxFrame *) NULL, wxID_ANY, - "wxToolBar Sample", - wxPoint(100, 100), wxDefaultSize); + MyFrame* frame = new MyFrame(); frame->Show(true); @@ -512,13 +505,8 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) // ---------------------------------------------------------------------------- // Define my frame constructor -MyFrame::MyFrame(wxFrame* parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - long style) - : wxFrame(parent, id, title, pos, size, style) +MyFrame::MyFrame() + : wxFrame(NULL, wxID_ANY, "wxToolBar Sample") { m_tbar = NULL; From 15e35a5e7c9a12ebffb6fe3c66f3e55ab5a3f181 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Sep 2021 18:57:12 +0100 Subject: [PATCH 06/18] Document that FromDIP() is not needed with SetToolBitmapSize() wxMSW wxToolBar adjusts the bitmap size to DPI automatically. --- interface/wx/toolbar.h | 5 +++++ samples/toolbar/toolbar.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/interface/wx/toolbar.h b/interface/wx/toolbar.h index 6961be25bd..35474cf509 100644 --- a/interface/wx/toolbar.h +++ b/interface/wx/toolbar.h @@ -860,6 +860,11 @@ public: Sets the default size of each tool bitmap. The default bitmap size is 16 by 15 pixels. + Note that @a size does @e not need to be multiplied by the + DPI-dependent factor even under MSW, where it would normally be + necessary, as the toolbar adjusts this size to the current DPI + automatically. + @param size The size of the bitmaps in the toolbar. diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index cc4e489deb..8429d6ecce 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -410,6 +410,9 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) h *= 2; } + // Note that there is no need for FromDIP() here, wxMSW will adjust the + // size on its own and under the other platforms there is no need for + // scaling the coordinates anyhow. toolBar->SetToolBitmapSize(wxSize(w, h)); toolBar->AddTool(wxID_NEW, "New", From 043461077ec45bb8284deda450f1f5c9cdd2be65 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Sep 2021 19:01:20 +0100 Subject: [PATCH 07/18] Use wxBitmapBundle::GetDefaultSize() in the toolbar sample This actually reverts the sample to the version in master, which used wxBitmap::Get{Width,Height}(), but just replaces "w" and "h" variables with a single "sizeBitmap" one. --- samples/toolbar/toolbar.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 8429d6ecce..8b48049043 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -401,19 +401,17 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) toolBarBitmaps[Tool_help ] = wxBITMAP_BUNDLE_2(help ); // Size of the bitmaps we use by default. - int w = 32, - h = 32; - - if ( !m_smallToolbar ) - { - w *= 2; - h *= 2; - } + // + // Note that scaling it up by 2 is not something we would do in real + // application code, it is only done in the sample for testing of bigger + // bitmap sizes. + const wxSize sizeBitmap = toolBarBitmaps[Tool_new].GetDefaultSize() * + (m_smallToolbar ? 1 : 2); // Note that there is no need for FromDIP() here, wxMSW will adjust the // size on its own and under the other platforms there is no need for // scaling the coordinates anyhow. - toolBar->SetToolBitmapSize(wxSize(w, h)); + toolBar->SetToolBitmapSize(sizeBitmap); toolBar->AddTool(wxID_NEW, "New", toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_DROPDOWN, @@ -454,15 +452,15 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) if ( m_useCustomDisabled ) { - wxBitmap bmpDisabled(w, h); + wxBitmap bmpDisabled(sizeBitmap); { wxMemoryDC dc; dc.SelectObject(bmpDisabled); - dc.DrawBitmap(toolBarBitmaps[Tool_print].GetBitmap(wxSize(w, h)), 0, 0); + dc.DrawBitmap(toolBarBitmaps[Tool_print].GetBitmap(sizeBitmap), 0, 0); wxPen pen(*wxRED, 5); dc.SetPen(pen); - dc.DrawLine(0, 0, w, h); + dc.DrawLine(0, 0, sizeBitmap.x, sizeBitmap.y); } toolBar->AddTool(wxID_PRINT, "Print", toolBarBitmaps[Tool_print], @@ -487,8 +485,8 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) wxImage img(m_pathBmp); if ( img.IsOk() ) { - if ( img.GetWidth() > w && img.GetHeight() > h ) - img = img.GetSubImage(wxRect(0, 0, w, h)); + if ( img.GetWidth() > sizeBitmap.x && img.GetHeight() > sizeBitmap.y ) + img = img.GetSubImage(wxRect(0, 0, sizeBitmap.x, sizeBitmap.y)); toolBar->AddSeparator(); toolBar->AddTool(wxID_ANY, "Custom", img); From ba6c691c221efd9ddac6837c425675d3a86ea892 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 5 Oct 2021 16:01:34 +0100 Subject: [PATCH 08/18] Add wxBitmapBundle::FromImpl() and GetImpl() For now they're only used internally but at least the latter will be made public later. --- include/wx/bmpbndl.h | 5 +++++ src/common/bmpbndl.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index ef2e8dde2d..924b99bcf5 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -63,6 +63,8 @@ public: // form name_2x or name@2x (and also using other factors) will be used. static wxBitmapBundle FromResources(const wxString& name); + // Create from existing implementation + static wxBitmapBundle FromImpl(wxBitmapBundleImpl* impl); // Check if bitmap bundle is non-empty. bool IsOk() const { return m_impl; } @@ -77,6 +79,9 @@ public: // If size == wxDefaultSize, GetDefaultSize() is used for it instead. wxBitmap GetBitmap(const wxSize size) const; + // Access implementation + wxBitmapBundleImpl* GetImpl() const { return m_impl.get(); } + private: typedef wxObjectDataPtr wxBitmapBundleImplPtr; diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp index 2e926f352c..709fca8009 100644 --- a/src/common/bmpbndl.cpp +++ b/src/common/bmpbndl.cpp @@ -244,6 +244,13 @@ wxBitmapBundle wxBitmapBundle::FromBitmaps(const wxVector& bitmaps) return wxBitmapBundle(new wxBitmapBundleImplSet(bitmaps)); } +/* static */ +wxBitmapBundle wxBitmapBundle::FromImpl(wxBitmapBundleImpl* impl) +{ + return wxBitmapBundle(impl); +} + + // MSW has its own, actually working, version, in MSW-specific code. #ifndef __WXMSW__ From 95aa8e40fd66ebeb14a63e916d3dc2058b46ed69 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 28 Sep 2021 07:54:15 +0200 Subject: [PATCH 09/18] first part of OSX adaptations --- Makefile.in | 36 ++++++- build/bakefiles/files.bkl | 1 + build/cmake/files.cmake | 1 + build/files | 1 + include/wx/osx/cocoa/private.h | 2 + include/wx/osx/iphone/private.h | 2 + include/wx/private/bmpbndl.h | 18 ++++ src/common/bmpbndl.cpp | 47 ++++++++- src/osx/core/bmpbndl.mm | 180 ++++++++++++++++++++++++++++++++ 9 files changed, 282 insertions(+), 6 deletions(-) create mode 100644 src/osx/core/bmpbndl.mm diff --git a/Makefile.in b/Makefile.in index a2d91741d1..40586a21e1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -13464,7 +13464,8 @@ COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS = \ monodll_hid.o \ monodll_printmac.o \ monodll_core_timer.o \ - monodll_utilsexc_cf.o + monodll_utilsexc_cf.o \ + monodll_core_bmpbndl.o @COND_PLATFORM_MACOSX_1@__OSX_LOWLEVEL_SRC_OBJECTS = $(COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS) @COND_PLATFORM_MACOSX_1@__PLATFORM_SRC_OBJECTS_0 = monolib_unix_apptraits.o @COND_PLATFORM_UNIX_1@__PLATFORM_SRC_OBJECTS_0 = monolib_unix_apptraits.o @@ -13601,7 +13602,8 @@ COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS_17 = \ monolib_hid.o \ monolib_printmac.o \ monolib_core_timer.o \ - monolib_utilsexc_cf.o + monolib_utilsexc_cf.o \ + monolib_core_bmpbndl.o @COND_PLATFORM_MACOSX_1@__OSX_LOWLEVEL_SRC_OBJECTS_17 = $(COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS_17) @COND_PLATFORM_MACOSX_1@__PLATFORM_SRC_OBJECTS_8 = coredll_unix_apptraits.o @COND_PLATFORM_UNIX_1@__PLATFORM_SRC_OBJECTS_8 = coredll_unix_apptraits.o @@ -13738,7 +13740,8 @@ COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS_1_1 = \ coredll_hid.o \ coredll_printmac.o \ coredll_core_timer.o \ - coredll_utilsexc_cf.o + coredll_utilsexc_cf.o \ + coredll_core_bmpbndl.o @COND_PLATFORM_MACOSX_1@__OSX_LOWLEVEL_SRC_OBJECTS_1_1 = $(COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS_1_1) @COND_PLATFORM_MACOSX_1@__PLATFORM_SRC_OBJECTS_9 = corelib_unix_apptraits.o @COND_PLATFORM_UNIX_1@__PLATFORM_SRC_OBJECTS_9 = corelib_unix_apptraits.o @@ -13875,7 +13878,8 @@ COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS_1_4 = \ corelib_hid.o \ corelib_printmac.o \ corelib_core_timer.o \ - corelib_utilsexc_cf.o + corelib_utilsexc_cf.o \ + corelib_core_bmpbndl.o @COND_PLATFORM_MACOSX_1@__OSX_LOWLEVEL_SRC_OBJECTS_1_4 = $(COND_PLATFORM_MACOSX_1___OSX_LOWLEVEL_SRC_OBJECTS_1_4) @COND_TOOLKIT_MSW@__webview_additional_include_wrl_p = \ @COND_TOOLKIT_MSW@ -I$(top_srcdir)/include/wx/msw/wrl @@ -19165,6 +19169,12 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@monodll_utilsexc_cf.o: $(srcdir)/src/osx/core/utilsexc_cf.cpp $(MONODLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/core/utilsexc_cf.cpp +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@monodll_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(MONODLL_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@monodll_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(MONODLL_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + @COND_TOOLKIT_X11_USE_GUI_1@monodll_generic_timer.o: $(srcdir)/src/generic/timer.cpp $(MONODLL_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/timer.cpp @@ -24460,6 +24470,12 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@monolib_utilsexc_cf.o: $(srcdir)/src/osx/core/utilsexc_cf.cpp $(MONOLIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/core/utilsexc_cf.cpp +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@monolib_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(MONOLIB_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@monolib_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(MONOLIB_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + @COND_TOOLKIT_X11_USE_GUI_1@monolib_generic_timer.o: $(srcdir)/src/generic/timer.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/timer.cpp @@ -29860,6 +29876,12 @@ coredll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(COREDLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@coredll_utilsexc_cf.o: $(srcdir)/src/osx/core/utilsexc_cf.cpp $(COREDLL_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/core/utilsexc_cf.cpp +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@coredll_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(COREDLL_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@coredll_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(COREDLL_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + @COND_TOOLKIT_X11_USE_GUI_1@coredll_generic_timer.o: $(srcdir)/src/generic/timer.cpp $(COREDLL_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/timer.cpp @@ -34120,6 +34142,12 @@ corelib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(CORELIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@corelib_utilsexc_cf.o: $(srcdir)/src/osx/core/utilsexc_cf.cpp $(CORELIB_ODEP) @COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/core/utilsexc_cf.cpp +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@corelib_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(CORELIB_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@corelib_core_bmpbndl.o: $(srcdir)/src/osx/core/bmpbndl.mm $(CORELIB_ODEP) +@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_OBJCXXFLAGS) $(srcdir)/src/osx/core/bmpbndl.mm + @COND_TOOLKIT_X11_USE_GUI_1@corelib_generic_timer.o: $(srcdir)/src/generic/timer.cpp $(CORELIB_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/timer.cpp diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 56d67f4d0b..4972cc72f4 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2423,6 +2423,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/osx/core/printmac.cpp src/osx/core/timer.cpp src/osx/core/utilsexc_cf.cpp + src/osx/core/bmpbndl.mm diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index 3075665f09..032091d0de 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -2301,6 +2301,7 @@ set(OSX_LOWLEVEL_SRC src/osx/core/timer.cpp src/osx/core/utilsexc_cf.cpp #TODO: + src/osx/core/bmpbndl.mm ) set(OSX_LOWLEVEL_HDR diff --git a/build/files b/build/files index 299323c253..2112c0f6be 100644 --- a/build/files +++ b/build/files @@ -2279,6 +2279,7 @@ OSX_LOWLEVEL_SRC = src/osx/window_osx.cpp src/osx/core/bitmap.cpp + src/osx/core/bmpbndl.mm src/osx/core/colour.cpp src/osx/core/dcmemory.cpp src/osx/core/fontenum.cpp diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 1538f6d5d0..4e29fb6291 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -23,6 +23,8 @@ // shared between Cocoa and Carbon // +#include "wx/bmpbndl.h" + // bring in theming types without pulling in the headers #if wxUSE_GUI diff --git a/include/wx/osx/iphone/private.h b/include/wx/osx/iphone/private.h index 42a4557879..0bb8939514 100644 --- a/include/wx/osx/iphone/private.h +++ b/include/wx/osx/iphone/private.h @@ -24,6 +24,8 @@ #if wxUSE_GUI +#include "wx/bmpbndl.h" + typedef CGRect WXRect; OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage( diff --git a/include/wx/private/bmpbndl.h b/include/wx/private/bmpbndl.h index fd17d82041..1d986a18cc 100644 --- a/include/wx/private/bmpbndl.h +++ b/include/wx/private/bmpbndl.h @@ -32,6 +32,24 @@ public: // Note that this function is non-const because it may generate the bitmap // on demand and cache it. virtual wxBitmap GetBitmap(const wxSize size) = 0; + +#ifdef __WXOSX__ + // returns the native representation of the bitmap bundle + virtual WXImage OSXGetImage() const { return NULL; } +#endif }; +#ifdef __WXOSX__ + +// this methods are wx-private, may change in the future + +WXImage WXDLLIMPEXP_CORE wxOSXGetImageFromBundle(const wxBitmapBundle& bundle); +wxBitmapBundle WXDLLIMPEXP_CORE wxOSXMakeBundleFromImage(WXImage image); +WXImage WXDLLIMPEXP_CORE wxOSXImageFromBitmap(const wxBitmap& bmp); +#if wxOSX_USE_COCOA +void WXDLLIMPEXP_CORE wxOSXAddBitmapToImage(WXImage image, const wxBitmap& bmp); +#endif + +#endif + #endif // _WX_PRIVATE_BMPBNDL_H_ diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp index 709fca8009..f290617ee3 100644 --- a/src/common/bmpbndl.cpp +++ b/src/common/bmpbndl.cpp @@ -27,6 +27,10 @@ #include +#ifdef __WXOSX__ +#include "wx/osx/private.h" +#endif + // ---------------------------------------------------------------------------- // private helpers // ---------------------------------------------------------------------------- @@ -50,9 +54,24 @@ public: Init(&bitmap, 1); } + ~wxBitmapBundleImplSet() + { +#ifdef __WXOSX__ + if (m_nsImage) + wxMacCocoaRelease(m_nsImage); +#endif + } + virtual wxSize GetDefaultSize() const wxOVERRIDE; virtual wxBitmap GetBitmap(const wxSize size) wxOVERRIDE; +#ifdef __WXOSX__ + virtual WXImage OSXGetImage() const wxOVERRIDE; + +private: + mutable WXImage m_nsImage = NULL; +#endif + private: // Struct containing bitmap itself as well as a flag indicating whether we // generated it by rescaling the existing bitmap or not. @@ -196,6 +215,30 @@ wxBitmap wxBitmapBundleImplSet::GetBitmap(const wxSize size) return wxBitmap(); } +#ifdef __WXOSX__ +WXImage wxBitmapBundleImplSet::OSXGetImage() const +{ + if ( m_nsImage == NULL ) + { +#if wxOSX_USE_COCOA + m_nsImage = wxOSXImageFromBitmap(m_entries[0].bitmap); + const size_t n = m_entries.size(); + for ( size_t i = 1; i < n; ++i ) + { + const Entry& entry = m_entries[i]; + wxOSXAddBitmapToImage(m_nsImage, entry.bitmap); + } +#else + // TODO determine best bitmap for device scale factor, and use that + // with wxOSXImageFromBitmap as on iOS there is only one bitmap in a UIImage +#endif + if ( m_nsImage ) + wxMacCocoaRetain(m_nsImage); + } + return m_nsImage; +} +#endif + // ============================================================================ // wxBitmapBundle implementation // ============================================================================ @@ -252,7 +295,7 @@ wxBitmapBundle wxBitmapBundle::FromImpl(wxBitmapBundleImpl* impl) // MSW has its own, actually working, version, in MSW-specific code. -#ifndef __WXMSW__ +#if !defined( __WXMSW__ ) && !defined( __WXOSX__ ) /* static */ wxBitmapBundle wxBitmapBundle::FromResources(const wxString& WXUNUSED(name)) @@ -267,7 +310,7 @@ wxBitmapBundle wxBitmapBundle::FromResources(const wxString& WXUNUSED(name)) return wxBitmapBundle(); } -#endif // __WXMSW__ +#endif // !__WXMSW__ && !__WXOSX__ wxSize wxBitmapBundle::GetDefaultSize() const { diff --git a/src/osx/core/bmpbndl.mm b/src/osx/core/bmpbndl.mm new file mode 100644 index 0000000000..582d171b82 --- /dev/null +++ b/src/osx/core/bmpbndl.mm @@ -0,0 +1,180 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/osx/core/bmpbndl.mm +// Purpose: OSX-specific part of wxBitmapBundle class. +// Author: Vadim Zeitlin and Stefan Csomor +// Created: 2021-09-22 +// Copyright: (c) 2021 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP +#endif // WX_PRECOMP + +#include "wx/bmpbndl.h" + +#include "wx/private/bmpbndl.h" + +#include "wx/osx/private.h" + +#include + +// ---------------------------------------------------------------------------- +// private helpers +// ---------------------------------------------------------------------------- + +namespace +{ +// Bundle implementation using PNG bitmaps from Windows resources. +class wxOSXImageBundleImpl : public wxBitmapBundleImpl +{ +public: + // Ctor takes the vector containing all the existing resources starting + // with the given name and the valid bitmap corresponding to the base name + // resource itself. + wxOSXImageBundleImpl(WXImage image); + ~wxOSXImageBundleImpl(); + + virtual wxSize GetDefaultSize() const wxOVERRIDE; + virtual wxBitmap GetBitmap(const wxSize size) wxOVERRIDE; + + virtual WXImage OSXGetImage() const wxOVERRIDE; + +private: + WXImage m_nsImage; +}; + +} // anonymouse namespace + +// ============================================================================ +// wxOSXImageBundleImpl implementation +// ============================================================================ + +wxOSXImageBundleImpl::wxOSXImageBundleImpl(WXImage image) +{ + m_nsImage = (WXImage) wxMacCocoaRetain(image); +} + +wxOSXImageBundleImpl::~wxOSXImageBundleImpl() +{ + wxMacCocoaRelease(m_nsImage); +} + +wxSize wxOSXImageBundleImpl::GetDefaultSize() const +{ + CGSize sz = wxOSXGetImageSize(m_nsImage); + return wxSize(sz.width, sz.height); +} + +wxBitmap wxOSXImageBundleImpl::GetBitmap(const wxSize size) +{ + return wxBitmap(); +} + +WXImage wxOSXImageBundleImpl::OSXGetImage() const +{ + return m_nsImage; +} + +wxBitmapBundle wxOSXMakeBundleFromImage( WXImage img) +{ + return wxBitmapBundle::FromImpl( new wxOSXImageBundleImpl(img) ); +} + +// ============================================================================ +// wxOSXImageBundleImpl implementation +// ============================================================================ + +WXImage wxOSXImageFromBitmap( const wxBitmap& bmp) +{ + WXImage image; +#if wxOSX_USE_COCOA + double scale = bmp.GetScaleFactor(); + NSSize sz = NSMakeSize( bmp.GetWidth()*scale, bmp.GetHeight()*scale); + image = [[NSImage alloc] initWithSize:sz]; + wxOSXAddBitmapToImage(image, bmp); +#else + wxCFRef cgimage = bmp.CreateCGImage(); + image = [[UIImage alloc] initWithCGImage:cgimage scale:bmp.GetScaleFactor() orientation:UIImageOrientationUp]; +#endif + [image autorelease]; + return image; +} + +#if wxOSX_USE_COCOA +void wxOSXAddBitmapToImage( WXImage image, const wxBitmap& bmp) +{ + wxCFRef cgimage = bmp.CreateCGImage(); + NSImageRep* nsrep = [[NSBitmapImageRep alloc] initWithCGImage:cgimage]; + [image addRepresentation:nsrep]; + [nsrep release]; +} +#endif + +wxBitmapBundle wxBitmapBundle::FromResources(const wxString& name) +{ + wxVector resources; + + wxString ext = "png"; // TODO adapt as soon as we get res param + wxCFStringRef restype(ext); + + for ( int dpiFactor = 1 ; dpiFactor <= 2 ; ++dpiFactor) + { + wxString filename; + if ( dpiFactor == 1 ) + filename = name; + else + filename = wxString::Format("%s@%dx", name, dpiFactor); + + wxCFStringRef resname(filename); + wxCFRef imageURL(CFBundleCopyResourceURL(CFBundleGetMainBundle(), resname, restype, NULL)); + if ( !imageURL.get() && dpiFactor != 1 ) + { + // try alternate naming scheme + filename = wxString::Format("%s_%dx", name, dpiFactor); + resname = wxCFStringRef(filename); + imageURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), resname, restype, NULL); + } + if ( imageURL.get() ) + { + // Create the data provider object + wxCFRef provider(CGDataProviderCreateWithURL (imageURL) ); + CGImageRef image = NULL; + + if ( ext == "jpeg" ) + image = CGImageCreateWithJPEGDataProvider (provider, NULL, true, + kCGRenderingIntentDefault); + else if ( ext == "png" ) + image = CGImageCreateWithPNGDataProvider (provider, NULL, true, + kCGRenderingIntentDefault); + if ( image != NULL ) + { + wxBitmap bmp(image, dpiFactor); + CGImageRelease(image); + resources.push_back(bmp); + } + } + } + + return wxBitmapBundle::FromBitmaps(resources); +} + +WXImage wxOSXGetImageFromBundle(const wxBitmapBundle& bundle) +{ + WXImage image = bundle.GetImpl()->OSXGetImage(); + + if (image == 0) + image = bundle.GetBitmap(bundle.GetDefaultSize()).OSXGetImage(); + + return image; +} From edc95443a3a0cf2f6c045e87bf7295f84b644627 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 28 Sep 2021 09:37:34 +0200 Subject: [PATCH 10/18] OSX toolbar adaptations to wxBitmapBundle --- include/wx/osx/toolbar.h | 9 +++++---- src/osx/cocoa/toolbar.mm | 31 ++++++++++++++++--------------- src/osx/iphone/toolbar.mm | 23 +++++++++++++---------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/include/wx/osx/toolbar.h b/include/wx/osx/toolbar.h index 983d1ec49b..eb2ad41075 100644 --- a/include/wx/osx/toolbar.h +++ b/include/wx/osx/toolbar.h @@ -58,8 +58,9 @@ public: virtual void SetRows(int nRows) wxOVERRIDE; - virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; - virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap) wxOVERRIDE; + + virtual void SetToolNormalBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; + virtual void SetToolDisabledBitmap(int id, const wxBitmapBundle& bitmap) wxOVERRIDE; #ifndef __WXOSX_IPHONE__ // Add all the buttons @@ -83,8 +84,8 @@ public: virtual wxToolBarToolBase *CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled = wxNullBitmap, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, wxObject *clientData = NULL, const wxString& shortHelp = wxEmptyString, diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index 54e89a15d3..2e3b84da21 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -20,6 +20,7 @@ #include "wx/app.h" #include "wx/osx/private.h" #include "wx/osx/private/available.h" +#include "wx/private/bmpbndl.h" #include "wx/geometry.h" #include "wx/sysopt.h" @@ -77,8 +78,8 @@ public: wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -591,14 +592,14 @@ void wxToolBarTool::SetPosition( const wxPoint& position ) void wxToolBarTool::UpdateImages() { - [(NSButton*) m_controlHandle setImage:m_bmpNormal.GetNSImage()]; + [(NSButton*) m_controlHandle setImage:wxOSXGetImageFromBundle(m_bmpNormal)]; if ( CanBeToggled() ) { - int w = m_bmpNormal.GetScaledWidth(); - int h = m_bmpNormal.GetScaledHeight(); + // TODO CS this should use the best current representation, or optionally iterate through all + wxSize sz = m_bmpNormal.GetDefaultSize(); m_alternateBitmap = wxBitmap(); - m_alternateBitmap.CreateScaled(w, h, -1, m_bmpNormal.GetScaleFactor()); + m_alternateBitmap.Create(sz.x, sz.y, -1); // TODO CS m_alternateBitmap.CreateScaled(sz.x, sz.y, -1, m_bmpNormal.GetScaleFactor()); m_alternateBitmap.UseAlpha(); wxMemoryDC dc; @@ -610,8 +611,8 @@ void wxToolBarTool::UpdateImages() dc.Clear(); dc.SetPen(grey); dc.SetBrush(grey); - dc.DrawRoundedRectangle( 0, 0, w, h, 3 ); - dc.DrawBitmap( m_bmpNormal, 0, 0, true ); + dc.DrawRoundedRectangle( 0, 0, sz.x, sz.y, 3 ); + dc.DrawBitmap( m_bmpNormal.GetBitmap(sz), 0, 0, true ); dc.SelectObject( wxNullBitmap ); [(NSButton*) m_controlHandle setAlternateImage:m_alternateBitmap.GetNSImage()]; @@ -633,7 +634,7 @@ void wxToolBarTool::UpdateToggleImage( bool toggle ) if ( CanBeToggled() && toggle ) [m_toolbarItem setImage:m_alternateBitmap.GetNSImage()]; else - [m_toolbarItem setImage:m_bmpNormal.GetNSImage()]; + [m_toolbarItem setImage:wxOSXGetImageFromBundle(m_bmpNormal)]; } #endif @@ -645,8 +646,8 @@ wxToolBarTool::wxToolBarTool( wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -665,8 +666,8 @@ wxToolBarTool::wxToolBarTool( wxToolBarToolBase *wxToolBar::CreateTool( int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -1380,7 +1381,7 @@ void wxToolBar::MacSuperChangedPosition() */ } -void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) @@ -1394,7 +1395,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) } } -void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) diff --git a/src/osx/iphone/toolbar.mm b/src/osx/iphone/toolbar.mm index 0c22197ebf..ce8f83e6e5 100644 --- a/src/osx/iphone/toolbar.mm +++ b/src/osx/iphone/toolbar.mm @@ -19,10 +19,13 @@ #endif #include "wx/app.h" -#include "wx/osx/private.h" #include "wx/geometry.h" #include "wx/sysopt.h" +#include "wx/private/bmpbndl.h" + +#include "wx/osx/private.h" + #pragma mark - #pragma mark Tool Implementation @@ -58,8 +61,8 @@ public: wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -104,8 +107,8 @@ wxToolBarTool::wxToolBarTool( wxToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -127,7 +130,7 @@ wxToolBarToolBase( } else if ( bmpNormal.IsOk() ) { - bui = [bui initWithImage:bmpNormal.GetUIImage() style:UIBarButtonItemStylePlain target:toolbar + bui = [bui initWithImage:wxOSXGetImageFromBundle(bmpNormal) style:UIBarButtonItemStylePlain target:toolbar action:@selector(clickedAction:)]; } else @@ -180,8 +183,8 @@ wxToolBarTool::~wxToolBarTool() wxToolBarToolBase *wxToolBar::CreateTool( int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -296,7 +299,7 @@ void wxToolBar::SetRows(int nRows) m_maxRows = nRows; } -void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) @@ -307,7 +310,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) } } -void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmapBundle& bitmap ) { wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) From 388d322b68dcd28e9084515c4917ec67e783e096 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 28 Sep 2021 10:17:09 +0200 Subject: [PATCH 11/18] carry changes to toolbar over to prefs on osx --- include/wx/preferences.h | 1 + src/osx/cocoa/preferences.mm | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/wx/preferences.h b/include/wx/preferences.h index 40dac7a0bd..88c8138d50 100644 --- a/include/wx/preferences.h +++ b/include/wx/preferences.h @@ -15,6 +15,7 @@ #if wxUSE_PREFERENCES_EDITOR #include "wx/bitmap.h" +#include "wx/bmpbndl.h" #include "wx/vector.h" class WXDLLIMPEXP_FWD_CORE wxWindow; diff --git a/src/osx/cocoa/preferences.mm b/src/osx/cocoa/preferences.mm index 4d26a958ab..e58274a18c 100644 --- a/src/osx/cocoa/preferences.mm +++ b/src/osx/cocoa/preferences.mm @@ -32,6 +32,7 @@ #include "wx/weakref.h" #include "wx/windowid.h" #include "wx/osx/private.h" +#include "wx/private/bmpbndl.h" #include "wx/osx/private/available.h" #import @@ -39,15 +40,16 @@ wxBitmap wxStockPreferencesPage::GetLargeIcon() const { + wxBitmapBundle bundle; #if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 if ( WX_IS_MACOS_AVAILABLE(11, 0) ) { switch ( m_kind ) { case Kind_General: - return wxBitmap([NSImage imageWithSystemSymbolName:@"gearshape" accessibilityDescription:nil]); + bundle = wxOSXMakeBundleFromImage([NSImage imageWithSystemSymbolName:@"gearshape" accessibilityDescription:nil]); case Kind_Advanced: - return wxBitmap([NSImage imageWithSystemSymbolName:@"gearshape.2" accessibilityDescription:nil]); + bundle = wxOSXMakeBundleFromImage([NSImage imageWithSystemSymbolName:@"gearshape.2" accessibilityDescription:nil]); } } #endif @@ -55,12 +57,12 @@ wxBitmap wxStockPreferencesPage::GetLargeIcon() const switch ( m_kind ) { case Kind_General: - return wxBitmap([NSImage imageNamed:NSImageNamePreferencesGeneral]); + bundle = wxOSXMakeBundleFromImage([NSImage imageNamed:NSImageNamePreferencesGeneral]); case Kind_Advanced: - return wxBitmap([NSImage imageNamed:NSImageNameAdvanced]); + bundle = wxOSXMakeBundleFromImage([NSImage imageNamed:NSImageNameAdvanced]); } - return wxBitmap(); // silence compiler warning + return bundle.IsOk() ? bundle.GetBitmap(bundle.GetDefaultSize()) : wxNullBitmap; } @@ -98,7 +100,7 @@ public: "can't add more preferences pages after showing the window" ); const wxString title = page->GetName(); - wxBitmap bmp(page->GetLargeIcon()); + wxBitmapBundle bmp(page->GetLargeIcon()); wxASSERT_MSG( bmp.IsOk(), "OS X requires valid bitmap for preference page" ); int toolId = wxIdManager::ReserveId(); From 5ebd76156d542d9d7ec61f56f62e7736f19a9af7 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 28 Sep 2021 12:08:31 +0200 Subject: [PATCH 12/18] adapting buttonbar --- include/wx/generic/buttonbar.h | 4 ++-- src/generic/buttonbar.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/wx/generic/buttonbar.h b/include/wx/generic/buttonbar.h index 24de813d57..2d8d6e0506 100644 --- a/include/wx/generic/buttonbar.h +++ b/include/wx/generic/buttonbar.h @@ -66,8 +66,8 @@ protected: virtual wxToolBarToolBase *CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, diff --git a/src/generic/buttonbar.cpp b/src/generic/buttonbar.cpp index b6b50a2edd..c904e738c3 100644 --- a/src/generic/buttonbar.cpp +++ b/src/generic/buttonbar.cpp @@ -46,8 +46,8 @@ public: wxButtonToolBarTool(wxButtonToolBar *tbar, int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, @@ -261,8 +261,8 @@ void wxButtonToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUS wxToolBarToolBase *wxButtonToolBar::CreateTool(int id, const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, + const wxBitmapBundle& bmpNormal, + const wxBitmapBundle& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, From ac02ae877fecad23a88854da4b93c9ebdb08252a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 28 Sep 2021 18:03:55 +0100 Subject: [PATCH 13/18] Add simple wxBitmapBundle::FromSVG() implementation using NanoSVG Add nanosvg submodule and use it in the generic implementation of this function. This is incomplete yet and, notably, doesn't cache the rasterized images, but already shows that using SVG images works (at least in the toolbar sample). --- .gitmodules | 4 + 3rdparty/nanosvg | 1 + Makefile.in | 36 +++++-- build/bakefiles/files.bkl | 1 + build/cmake/files.cmake | 1 + build/files | 1 + build/msw/makefile.gcc | 44 +++++++-- build/msw/makefile.vc | 44 +++++++-- build/msw/wx_core.vcxproj | 1 + build/msw/wx_core.vcxproj.filters | 3 + build/msw/wx_vc8_core.vcproj | 4 + build/msw/wx_vc9_core.vcproj | 4 + include/wx/bmpbndl.h | 10 ++ interface/wx/bmpbndl.h | 29 ++++++ samples/toolbar/toolbar.cpp | 24 ++++- src/generic/bmpsvg.cpp | 156 ++++++++++++++++++++++++++++++ tests/graphics/bmpbundle.cpp | 33 +++++++ 17 files changed, 369 insertions(+), 27 deletions(-) create mode 160000 3rdparty/nanosvg create mode 100644 src/generic/bmpsvg.cpp diff --git a/.gitmodules b/.gitmodules index cd26719f6e..eccca68800 100644 --- a/.gitmodules +++ b/.gitmodules @@ -26,3 +26,7 @@ path = 3rdparty/pcre url = https://github.com/wxWidgets/pcre branch = wx +[submodule "3rdparty/nanosvg"] + path = 3rdparty/nanosvg + url = https://github.com/wxWidgets/nanosvg + branch = wx diff --git a/3rdparty/nanosvg b/3rdparty/nanosvg new file mode 160000 index 0000000000..ccdb199513 --- /dev/null +++ b/3rdparty/nanosvg @@ -0,0 +1 @@ +Subproject commit ccdb1995134d340a93fb20e3a3d323ccb3838dd0 diff --git a/Makefile.in b/Makefile.in index 40586a21e1..e2790da9dd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4711,7 +4711,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS = \ monodll_calctrlg.o \ monodll_creddlgg.o \ monodll_rowheightcache.o \ - monodll_common_bmpbndl.o + monodll_common_bmpbndl.o \ + monodll_bmpsvg.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS = \ $(__LOWLEVEL_SRC_OBJECTS_1) \ @@ -4974,7 +4975,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS = \ monodll_calctrlg.o \ monodll_creddlgg.o \ monodll_rowheightcache.o \ - monodll_common_bmpbndl.o + monodll_common_bmpbndl.o \ + monodll_bmpsvg.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS = \ monodll_fontmgrcmn.o \ @@ -6711,7 +6713,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_1 = \ monolib_calctrlg.o \ monolib_creddlgg.o \ monolib_rowheightcache.o \ - monolib_common_bmpbndl.o + monolib_common_bmpbndl.o \ + monolib_bmpsvg.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_1 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_1) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1 = \ $(__LOWLEVEL_SRC_OBJECTS_3) \ @@ -6974,7 +6977,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1 = \ monolib_calctrlg.o \ monolib_creddlgg.o \ monolib_rowheightcache.o \ - monolib_common_bmpbndl.o + monolib_common_bmpbndl.o \ + monolib_bmpsvg.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_1 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_2 = \ monolib_fontmgrcmn.o \ @@ -8864,7 +8868,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_2 = \ coredll_calctrlg.o \ coredll_creddlgg.o \ coredll_rowheightcache.o \ - coredll_common_bmpbndl.o + coredll_common_bmpbndl.o \ + coredll_bmpsvg.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_2 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_2) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2 = \ $(__LOWLEVEL_SRC_OBJECTS_5) \ @@ -9127,7 +9132,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2 = \ coredll_calctrlg.o \ coredll_creddlgg.o \ coredll_rowheightcache.o \ - coredll_common_bmpbndl.o + coredll_common_bmpbndl.o \ + coredll_bmpsvg.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_2 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_4 = \ coredll_fontmgrcmn.o \ @@ -10593,7 +10599,8 @@ COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_3 = \ corelib_calctrlg.o \ corelib_creddlgg.o \ corelib_rowheightcache.o \ - corelib_common_bmpbndl.o + corelib_common_bmpbndl.o \ + corelib_bmpsvg.o @COND_USE_GUI_1_WXUNIV_0@__CORE_SRC_OBJECTS_3 = $(COND_USE_GUI_1_WXUNIV_0___CORE_SRC_OBJECTS_3) COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3 = \ $(__LOWLEVEL_SRC_OBJECTS_7) \ @@ -10856,7 +10863,8 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3 = \ corelib_calctrlg.o \ corelib_creddlgg.o \ corelib_rowheightcache.o \ - corelib_common_bmpbndl.o + corelib_common_bmpbndl.o \ + corelib_bmpsvg.o @COND_USE_GUI_1_WXUNIV_1@__CORE_SRC_OBJECTS_3 = $(COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3) COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_6 = \ corelib_fontmgrcmn.o \ @@ -21047,6 +21055,9 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@monodll_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp +@COND_USE_GUI_1@monodll_bmpsvg.o: $(srcdir)/src/generic/bmpsvg.cpp $(MONODLL_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/bmpsvg.cpp + @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@monodll_osx_cocoa_mediactrl.o: $(srcdir)/src/osx/cocoa/mediactrl.mm $(MONODLL_ODEP) @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/mediactrl.mm @@ -26348,6 +26359,9 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@monolib_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp +@COND_USE_GUI_1@monolib_bmpsvg.o: $(srcdir)/src/generic/bmpsvg.cpp $(MONOLIB_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/bmpsvg.cpp + @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@monolib_osx_cocoa_mediactrl.o: $(srcdir)/src/osx/cocoa/mediactrl.mm $(MONOLIB_ODEP) @COND_TOOLKIT_OSX_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/mediactrl.mm @@ -31754,6 +31768,9 @@ coredll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(COREDLL_ODEP) @COND_USE_GUI_1@coredll_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(COREDLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp +@COND_USE_GUI_1@coredll_bmpsvg.o: $(srcdir)/src/generic/bmpsvg.cpp $(COREDLL_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/bmpsvg.cpp + corelib_event.o: $(srcdir)/src/common/event.cpp $(CORELIB_ODEP) $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/event.cpp @@ -36020,6 +36037,9 @@ corelib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(CORELIB_ODEP) @COND_USE_GUI_1@corelib_common_bmpbndl.o: $(srcdir)/src/common/bmpbndl.cpp $(CORELIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/bmpbndl.cpp +@COND_USE_GUI_1@corelib_bmpsvg.o: $(srcdir)/src/generic/bmpsvg.cpp $(CORELIB_ODEP) +@COND_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/bmpsvg.cpp + advdll_version_rc.o: $(srcdir)/src/msw/version.rc $(ADVDLL_ODEP) $(WINDRES) -i$< -o$@ $(__INC_TIFF_BUILD_p_54) $(__INC_TIFF_p_54) $(__INC_JPEG_p_54) $(__INC_PNG_p_53) $(__INC_ZLIB_p_67) $(__INC_REGEX_p_65) $(__INC_EXPAT_p_65) --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_66) $(__DEBUG_DEFINE_p_66) $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65) --define WXBUILDING --define WXDLLNAME=$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_adv$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG) $(__RCDEFDIR_p) --include-dir $(top_srcdir)/include --define WXUSINGDLL --define WXMAKINGDLL_ADV diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 4972cc72f4..4652c90077 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1016,6 +1016,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/generic/creddlgg.cpp src/generic/rowheightcache.cpp src/common/bmpbndl.cpp + src/generic/bmpsvg.cpp wx/affinematrix2dbase.h diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index 032091d0de..e15621a957 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -919,6 +919,7 @@ set(GUI_CMN_SRC src/generic/rowheightcache.cpp src/generic/animateg.cpp src/common/bmpbndl.cpp + src/generic/bmpsvg.cpp ) set(GUI_CMN_HDR diff --git a/build/files b/build/files index 2112c0f6be..01cd181731 100644 --- a/build/files +++ b/build/files @@ -872,6 +872,7 @@ GUI_CMN_SRC = src/generic/animateg.cpp src/generic/bannerwindow.cpp src/generic/bmpcboxg.cpp + src/generic/bmpsvg.cpp src/generic/busyinfo.cpp src/generic/buttonbar.cpp src/generic/calctrlg.cpp diff --git a/build/msw/makefile.gcc b/build/msw/makefile.gcc index 8eda39d271..e590bc8161 100644 --- a/build/msw/makefile.gcc +++ b/build/msw/makefile.gcc @@ -2203,7 +2203,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.o \ $(OBJS)\monodll_creddlgg.o \ $(OBJS)\monodll_rowheightcache.o \ - $(OBJS)\monodll_common_bmpbndl.o + $(OBJS)\monodll_common_bmpbndl.o \ + $(OBJS)\monodll_bmpsvg.o endif endif ifeq ($(USE_GUI),1) @@ -2535,7 +2536,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.o \ $(OBJS)\monodll_creddlgg.o \ $(OBJS)\monodll_rowheightcache.o \ - $(OBJS)\monodll_common_bmpbndl.o + $(OBJS)\monodll_common_bmpbndl.o \ + $(OBJS)\monodll_bmpsvg.o endif endif ifeq ($(USE_STC),1) @@ -3049,7 +3051,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.o \ $(OBJS)\monolib_creddlgg.o \ $(OBJS)\monolib_rowheightcache.o \ - $(OBJS)\monolib_common_bmpbndl.o + $(OBJS)\monolib_common_bmpbndl.o \ + $(OBJS)\monolib_bmpsvg.o endif endif ifeq ($(USE_GUI),1) @@ -3381,7 +3384,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.o \ $(OBJS)\monolib_creddlgg.o \ $(OBJS)\monolib_rowheightcache.o \ - $(OBJS)\monolib_common_bmpbndl.o + $(OBJS)\monolib_common_bmpbndl.o \ + $(OBJS)\monolib_bmpsvg.o endif endif ifeq ($(USE_STC),1) @@ -3778,7 +3782,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.o \ $(OBJS)\coredll_creddlgg.o \ $(OBJS)\coredll_rowheightcache.o \ - $(OBJS)\coredll_common_bmpbndl.o + $(OBJS)\coredll_common_bmpbndl.o \ + $(OBJS)\coredll_bmpsvg.o endif endif ifeq ($(USE_GUI),1) @@ -4110,7 +4115,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.o \ $(OBJS)\coredll_creddlgg.o \ $(OBJS)\coredll_rowheightcache.o \ - $(OBJS)\coredll_common_bmpbndl.o + $(OBJS)\coredll_common_bmpbndl.o \ + $(OBJS)\coredll_bmpsvg.o endif endif ifeq ($(MONOLITHIC),0) @@ -4465,7 +4471,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.o \ $(OBJS)\corelib_creddlgg.o \ $(OBJS)\corelib_rowheightcache.o \ - $(OBJS)\corelib_common_bmpbndl.o + $(OBJS)\corelib_common_bmpbndl.o \ + $(OBJS)\corelib_bmpsvg.o endif endif ifeq ($(USE_GUI),1) @@ -4797,7 +4804,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.o \ $(OBJS)\corelib_creddlgg.o \ $(OBJS)\corelib_rowheightcache.o \ - $(OBJS)\corelib_common_bmpbndl.o + $(OBJS)\corelib_common_bmpbndl.o \ + $(OBJS)\corelib_bmpsvg.o endif endif ifeq ($(SHARED),1) @@ -9482,6 +9490,11 @@ $(OBJS)\monodll_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\monodll_bmpsvg.o: ../../src/generic/bmpsvg.cpp + $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\monodll_version_rc.o: ../../src/msw/version.rc $(WINDRES) -i$< -o$@ --include-dir ../../src/tiff/libtiff --include-dir ../../src/jpeg --include-dir ../../src/png --include-dir ../../src/zlib --include-dir ../../3rdparty/pcre/src/wx --include-dir ../../src/expat/expat/lib --define __WXMSW__ $(__WXUNIV_DEFINE_p_66) $(__DEBUG_DEFINE_p_66) $(__NDEBUG_DEFINE_p_65) $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65) $(__UNICODE_DEFINE_p_67) --include-dir $(SETUPHDIR) --include-dir ../../include $(__CAIRO_INCLUDEDIR_p) --define WXBUILDING --define WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)$(WXCOMPILER)$(VENDORTAG) --include-dir ../../src/stc/scintilla/include --include-dir ../../src/stc/scintilla/lexlib --include-dir ../../src/stc/scintilla/src --define __WX__ --define SCI_LEXER --define NO_CXX11_REGEX --define LINK_LEXERS --define wxUSE_BASE=1 --define WXMAKINGDLL @@ -12066,6 +12079,11 @@ $(OBJS)\monolib_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\monolib_bmpsvg.o: ../../src/generic/bmpsvg.cpp + $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\basedll_dummy.o: ../../src/common/dummy.cpp $(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $< @@ -14623,6 +14641,11 @@ $(OBJS)\coredll_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\coredll_bmpsvg.o: ../../src/generic/bmpsvg.cpp + $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\corelib_dummy.o: ../../src/common/dummy.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< @@ -16373,6 +16396,11 @@ $(OBJS)\corelib_common_bmpbndl.o: ../../src/common/bmpbndl.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< endif +ifeq ($(USE_GUI),1) +$(OBJS)\corelib_bmpsvg.o: ../../src/generic/bmpsvg.cpp + $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< +endif + $(OBJS)\advdll_dummy.o: ../../src/common/dummy.cpp $(CXX) -c -o $@ $(ADVDLL_CXXFLAGS) $(CPPDEPS) $< diff --git a/build/msw/makefile.vc b/build/msw/makefile.vc index 76456b188c..e7b8a7b9a1 100644 --- a/build/msw/makefile.vc +++ b/build/msw/makefile.vc @@ -2533,7 +2533,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.obj \ $(OBJS)\monodll_creddlgg.obj \ $(OBJS)\monodll_rowheightcache.obj \ - $(OBJS)\monodll_common_bmpbndl.obj + $(OBJS)\monodll_common_bmpbndl.obj \ + $(OBJS)\monodll_bmpsvg.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_OBJECTS = \ @@ -2863,7 +2864,8 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_calctrlg.obj \ $(OBJS)\monodll_creddlgg.obj \ $(OBJS)\monodll_rowheightcache.obj \ - $(OBJS)\monodll_common_bmpbndl.obj + $(OBJS)\monodll_common_bmpbndl.obj \ + $(OBJS)\monodll_bmpsvg.obj !endif !if "$(USE_STC)" == "1" ____MONOLIB_STC_SRC_FILENAMES_OBJECTS = \ @@ -3379,7 +3381,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.obj \ $(OBJS)\monolib_creddlgg.obj \ $(OBJS)\monolib_rowheightcache.obj \ - $(OBJS)\monolib_common_bmpbndl.obj + $(OBJS)\monolib_common_bmpbndl.obj \ + $(OBJS)\monolib_bmpsvg.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_1_OBJECTS = \ @@ -3709,7 +3712,8 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_calctrlg.obj \ $(OBJS)\monolib_creddlgg.obj \ $(OBJS)\monolib_rowheightcache.obj \ - $(OBJS)\monolib_common_bmpbndl.obj + $(OBJS)\monolib_common_bmpbndl.obj \ + $(OBJS)\monolib_bmpsvg.obj !endif !if "$(USE_STC)" == "1" ____MONOLIB_STC_SRC_FILENAMES_1_OBJECTS = \ @@ -4158,7 +4162,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.obj \ $(OBJS)\coredll_creddlgg.obj \ $(OBJS)\coredll_rowheightcache.obj \ - $(OBJS)\coredll_common_bmpbndl.obj + $(OBJS)\coredll_common_bmpbndl.obj \ + $(OBJS)\coredll_bmpsvg.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_2_OBJECTS = \ @@ -4488,7 +4493,8 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_calctrlg.obj \ $(OBJS)\coredll_creddlgg.obj \ $(OBJS)\coredll_rowheightcache.obj \ - $(OBJS)\coredll_common_bmpbndl.obj + $(OBJS)\coredll_common_bmpbndl.obj \ + $(OBJS)\coredll_bmpsvg.obj !endif !if "$(MONOLITHIC)" == "0" && "$(SHARED)" == "0" && "$(USE_GUI)" == "1" __corelib___depname = \ @@ -4843,7 +4849,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.obj \ $(OBJS)\corelib_creddlgg.obj \ $(OBJS)\corelib_rowheightcache.obj \ - $(OBJS)\corelib_common_bmpbndl.obj + $(OBJS)\corelib_common_bmpbndl.obj \ + $(OBJS)\corelib_bmpsvg.obj !endif !if "$(USE_GUI)" == "1" && "$(WXUNIV)" == "1" ____CORE_SRC_FILENAMES_3_OBJECTS = \ @@ -5173,7 +5180,8 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_calctrlg.obj \ $(OBJS)\corelib_creddlgg.obj \ $(OBJS)\corelib_rowheightcache.obj \ - $(OBJS)\corelib_common_bmpbndl.obj + $(OBJS)\corelib_common_bmpbndl.obj \ + $(OBJS)\corelib_bmpsvg.obj !endif !if "$(SHARED)" == "1" ____wxcore_namedll_DEP = $(__coredll___depname) @@ -9913,6 +9921,11 @@ $(OBJS)\monodll_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\monodll_bmpsvg.obj: ..\..\src\generic\bmpsvg.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\generic\bmpsvg.cpp +!endif + $(OBJS)\monodll_version.res: ..\..\src\msw\version.rc rc /fo$@ /d WIN32 /i ..\..\src\tiff\libtiff /i ..\..\src\jpeg /i ..\..\src\png /i ..\..\src\zlib /i ..\..\3rdparty\pcre\src\wx /i ..\..\src\expat\expat\lib $(____DEBUGRUNTIME_6) /d _CRT_SECURE_NO_DEPRECATE=1 /d _CRT_NON_CONFORMING_SWPRINTFS=1 /d _SCL_SECURE_NO_WARNINGS=1 $(__NO_VC_CRTDBG_p_72) $(__TARGET_CPU_COMPFLAG_p_72) /d __WXMSW__ $(__WXUNIV_DEFINE_p_66) $(__DEBUG_DEFINE_p_66) $(__NDEBUG_DEFINE_p_65) $(__EXCEPTIONS_DEFINE_p_65) $(__RTTI_DEFINE_p_65) $(__THREAD_DEFINE_p_65) $(__UNICODE_DEFINE_p_67) /i $(SETUPHDIR) /i ..\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_4) /d WXBUILDING /d WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)$(WXCOMPILER)$(VENDORTAG) /i ..\..\src\stc\scintilla\include /i ..\..\src\stc\scintilla\lexlib /i ..\..\src\stc\scintilla\src /d __WX__ /d SCI_LEXER /d NO_CXX11_REGEX /d LINK_LEXERS /d wxUSE_BASE=1 /d WXMAKINGDLL ..\..\src\msw\version.rc @@ -12497,6 +12510,11 @@ $(OBJS)\monolib_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\monolib_bmpsvg.obj: ..\..\src\generic\bmpsvg.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\generic\bmpsvg.cpp +!endif + $(OBJS)\basedll_dummy.obj: ..\..\src\common\dummy.cpp $(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) /Ycwx/wxprec.h ..\..\src\common\dummy.cpp @@ -15054,6 +15072,11 @@ $(OBJS)\coredll_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\coredll_bmpsvg.obj: ..\..\src\generic\bmpsvg.cpp + $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\generic\bmpsvg.cpp +!endif + $(OBJS)\corelib_dummy.obj: ..\..\src\common\dummy.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) /Ycwx/wxprec.h ..\..\src\common\dummy.cpp @@ -16804,6 +16827,11 @@ $(OBJS)\corelib_common_bmpbndl.obj: ..\..\src\common\bmpbndl.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\common\bmpbndl.cpp !endif +!if "$(USE_GUI)" == "1" +$(OBJS)\corelib_bmpsvg.obj: ..\..\src\generic\bmpsvg.cpp + $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\generic\bmpsvg.cpp +!endif + $(OBJS)\advdll_dummy.obj: ..\..\src\common\dummy.cpp $(CXX) /c /nologo /TP /Fo$@ $(ADVDLL_CXXFLAGS) /Ycwx/wxprec.h ..\..\src\common\dummy.cpp diff --git a/build/msw/wx_core.vcxproj b/build/msw/wx_core.vcxproj index 6a396f1fc0..36eb3274d4 100644 --- a/build/msw/wx_core.vcxproj +++ b/build/msw/wx_core.vcxproj @@ -592,6 +592,7 @@ + $(IntDir)msw_%(Filename).obj diff --git a/build/msw/wx_core.vcxproj.filters b/build/msw/wx_core.vcxproj.filters index f6e858df48..60190f8aa9 100644 --- a/build/msw/wx_core.vcxproj.filters +++ b/build/msw/wx_core.vcxproj.filters @@ -1074,6 +1074,9 @@ MSW Sources + + Generic Sources + diff --git a/build/msw/wx_vc8_core.vcproj b/build/msw/wx_vc8_core.vcproj index 5673f9fe19..1455ea33ce 100644 --- a/build/msw/wx_vc8_core.vcproj +++ b/build/msw/wx_vc8_core.vcproj @@ -2087,6 +2087,10 @@ RelativePath="..\..\src\generic\bmpcboxg.cpp" > + + diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj index fa37b4e5f4..0a0da78478 100644 --- a/build/msw/wx_vc9_core.vcproj +++ b/build/msw/wx_vc9_core.vcproj @@ -2083,6 +2083,10 @@ RelativePath="..\..\src\generic\bmpcboxg.cpp" > + + diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index 924b99bcf5..b73d192056 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -59,6 +59,16 @@ public: static wxBitmapBundle FromBitmap(const wxBitmap& bitmap); static wxBitmapBundle FromImage(const wxImage& image); + // It should be possible to implement SVG rasterizing without raw bitmap + // support using wxDC::DrawSpline(), but currently we don't do it and so + // FromSVG() is only available in the ports providing raw bitmap access. +#ifdef wxHAS_RAW_BITMAP + // Create from the SVG data (data is supposed to be in UTF-8 encoding). + // Notice that the data here is non-const because it can be temporarily + // modified while parsing it. + static wxBitmapBundle FromSVG(char* data, const wxSize sizeDef); +#endif // wxHAS_RAW_BITMAP + // Create from the resources: all existing versions of the bitmap of the // form name_2x or name@2x (and also using other factors) will be used. static wxBitmapBundle FromResources(const wxString& name); diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h index 8f28a630dc..4d4b22c893 100644 --- a/interface/wx/bmpbndl.h +++ b/interface/wx/bmpbndl.h @@ -176,6 +176,35 @@ public: */ static wxBitmapBundle FromResources(const wxString& name); + /** + Create a bundle from the SVG image. + + Please note that the current implementation uses NanoSVG library + (https://github.com/memononen/nanosvg) for parsing and rasterizing SVG + images which imposes the following limitations: + + - Text elements are not supported at all. + - SVG 1.1 filters are not supported. + + These limitations will be relaxed in the future wxWidgets versions. + + Please also note that this method is only available in the ports + providing raw bitmap access via wxPixelData and so defining + wxHAS_RAW_BITMAP symbol. Currently SVG images are not supported in the + ports without it, e.g. wxX11. + + @param data This data may, or not, have the XML document preamble, i.e. + it can start either with @c "" +"" +"" +"" +"" +"" +"" +; + enum Positions { TOOLBAR_LEFT, @@ -231,14 +243,14 @@ enum // event tables // ---------------------------------------------------------------------------- -// Notice that wxID_HELP will be processed for the 'About' menu and the toolbar +// Notice that wxID_ABOUT will be processed for the 'About' menu and the toolbar // help button. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_SIZE(MyFrame::OnSize) EVT_MENU(wxID_EXIT, MyFrame::OnQuit) - EVT_MENU(wxID_HELP, MyFrame::OnAbout) + EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR, MyFrame::OnToggleToolbar) EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar) @@ -378,6 +390,7 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) Tool_paste, Tool_print, Tool_help, + Tool_about, Tool_Max }; @@ -408,6 +421,9 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) const wxSize sizeBitmap = toolBarBitmaps[Tool_new].GetDefaultSize() * (m_smallToolbar ? 1 : 2); + // Use vector SVG image for this button for demonstration purposes. + toolBarBitmaps[Tool_about] = wxBitmapBundle::FromSVG(svg_data, sizeBitmap); + // Note that there is no need for FromDIP() here, wxMSW will adjust the // size on its own and under the other platforms there is no need for // scaling the coordinates anyhow. @@ -479,6 +495,8 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) toolBar->AddStretchableSpace(); toolBar->AddTool(wxID_HELP, "Help", toolBarBitmaps[Tool_help], "Help button", wxITEM_CHECK); + toolBar->AddTool(wxID_ABOUT, "About", toolBarBitmaps[Tool_about], "About"); + if ( !m_pathBmp.empty() ) { // create a tool with a custom bitmap for testing @@ -601,7 +619,7 @@ MyFrame::MyFrame() fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit toolbar sample" ); wxMenu *helpMenu = new wxMenu; - helpMenu->Append(wxID_HELP, "&About", "About toolbar sample"); + helpMenu->Append(wxID_ABOUT, "&About", "About toolbar sample"); wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); diff --git a/src/generic/bmpsvg.cpp b/src/generic/bmpsvg.cpp new file mode 100644 index 0000000000..7f5198b082 --- /dev/null +++ b/src/generic/bmpsvg.cpp @@ -0,0 +1,156 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/generic/bmpsvg.cpp +// Purpose: Generic wxBitmapBundle::FromSVG() implementation +// Author: Vadim Zeitlin, Gunter Königsmann +// Created: 2021-09-28 +// Copyright: (c) 2019 Gunter Königsmann +// (c) 2021 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef wxHAS_RAW_BITMAP + +#ifndef WX_PRECOMP + #include "wx/utils.h" // Only for wxMin() +#endif // WX_PRECOMP + +#include "wx/bmpbndl.h" +#include "wx/rawbmp.h" + +#include "wx/private/bmpbndl.h" + +// Disable some warnings inside NanoSVG code that we're not interested in. +#ifdef __VISUALC__ + #pragma warning(push) + #pragma warning(disable:4456) + #pragma warning(disable:4702) + + // Also make nanosvg.h compile with older MSVC versions which didn't have + // strtoll(). + #if _MSC_VER < 1800 + #define strtoll _strtoi64 + #endif +#endif + +#define NANOSVG_IMPLEMENTATION +#define NANOSVGRAST_IMPLEMENTATION +#include "../../3rdparty/nanosvg/src/nanosvg.h" +#include "../../3rdparty/nanosvg/src/nanosvgrast.h" + +#ifdef __VISUALC__ + #pragma warning(pop) +#endif + +// ---------------------------------------------------------------------------- +// private helpers +// ---------------------------------------------------------------------------- + +namespace +{ + +class wxBitmapBundleImplSVG : public wxBitmapBundleImpl +{ +public: + // Ctor must be passed a valid NSVGimage and takes ownership of it. + wxBitmapBundleImplSVG(NSVGimage* svgImage, const wxSize& sizeDef) + : m_svgImage(svgImage), + m_svgRasterizer(nsvgCreateRasterizer()), + m_sizeDef(sizeDef) + { + } + + ~wxBitmapBundleImplSVG() + { + nsvgDeleteRasterizer(m_svgRasterizer); + nsvgDelete(m_svgImage); + } + + virtual wxSize GetDefaultSize() const wxOVERRIDE; + virtual wxBitmap GetBitmap(const wxSize size) wxOVERRIDE; + +private: + NSVGimage* const m_svgImage; + NSVGrasterizer* const m_svgRasterizer; + + const wxSize m_sizeDef; + + wxDECLARE_NO_COPY_CLASS(wxBitmapBundleImplSVG); +}; + +} // anonymous namespace + +// ============================================================================ +// wxBitmapBundleImplSVG implementation +// ============================================================================ + +wxSize wxBitmapBundleImplSVG::GetDefaultSize() const +{ + return m_sizeDef; +} + +wxBitmap wxBitmapBundleImplSVG::GetBitmap(const wxSize size) +{ + // TODO: Cache. + + wxVector buffer(size.x*size.y*4); + nsvgRasterize + ( + m_svgRasterizer, + m_svgImage, + 0.0, 0.0, // no offset + wxMin + ( + size.x/m_svgImage->width, + size.y/m_svgImage->height + ), // scale + &buffer[0], + size.x, size.y, + size.x*4 // stride -- we have no gaps between lines + ); + + wxBitmap bitmap(size, 32); + wxAlphaPixelData bmpdata(bitmap); + wxAlphaPixelData::Iterator dst(bmpdata); + + const unsigned char* src = &buffer[0]; + for ( int y = 0; y < size.y; ++y ) + { + dst.MoveTo(bmpdata, 0, y); + for ( int x = 0; x < size.x; ++x ) + { + const unsigned char a = src[3]; + dst.Red() = src[0] * a / 255; + dst.Green() = src[1] * a / 255; + dst.Blue() = src[2] * a / 255; + dst.Alpha() = a; + + ++dst; + src += 4; + } + } + + return bitmap; +} + +/* static */ +wxBitmapBundle wxBitmapBundle::FromSVG(char* data, const wxSize sizeDef) +{ + NSVGimage* const svgImage = nsvgParse(data, "px", 96); + if ( !svgImage ) + return wxBitmapBundle(); + + return wxBitmapBundle(new wxBitmapBundleImplSVG(svgImage, sizeDef)); +} + +#endif // wxHAS_RAW_BITMAP diff --git a/tests/graphics/bmpbundle.cpp b/tests/graphics/bmpbundle.cpp index aa79c4a560..3d0f58eedd 100644 --- a/tests/graphics/bmpbundle.cpp +++ b/tests/graphics/bmpbundle.cpp @@ -46,3 +46,36 @@ TEST_CASE("BitmapBundle::FromBitmaps", "[bmpbundle]") CHECK( b.GetBitmap(wxSize(20, 20)).GetSize() == wxSize(20, 20) ); CHECK( b.GetBitmap(wxSize(24, 24)).GetSize() == wxSize(24, 24) ); } + +#ifdef wxHAS_RAW_BITMAP + +TEST_CASE("BitmapBundle::FromSVG", "[bmpbundle][svg]") +{ + static const char svg_data[] = +"" +"" +"" +"" +"" +"" +"" + ; + + wxCharBuffer buf(svg_data); + wxBitmapBundle b = wxBitmapBundle::FromSVG(buf.data(), wxSize(20, 20)); + REQUIRE( b.IsOk() ); + CHECK( b.GetDefaultSize() == wxSize(20, 20) ); + + CHECK( b.GetBitmap(wxSize(32, 32)).GetSize() == wxSize(32, 32) ); + + // Check that not using XML header works too. + const char* svg_tag_start = strstr(svg_data, " Date: Tue, 28 Sep 2021 18:39:53 +0100 Subject: [PATCH 14/18] Cache the last returned bitmap in wxBitmapBundleImplSVG This seems to be enough to avoid inefficiencies and doesn't consume as many resources as caching all bitmaps ever generated. --- src/generic/bmpsvg.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/generic/bmpsvg.cpp b/src/generic/bmpsvg.cpp index 7f5198b082..912817a37b 100644 --- a/src/generic/bmpsvg.cpp +++ b/src/generic/bmpsvg.cpp @@ -80,11 +80,22 @@ public: virtual wxBitmap GetBitmap(const wxSize size) wxOVERRIDE; private: + wxBitmap DoRasterize(const wxSize size); + NSVGimage* const m_svgImage; NSVGrasterizer* const m_svgRasterizer; const wxSize m_sizeDef; + // Cache the last used bitmap (may be invalid if not used yet). + // + // Note that we cache only the last bitmap and not all the bitmaps ever + // requested from GetBitmap() for the different sizes because there would + // be no way to clear such cache and its growth could be unbounded, + // resulting in too many bitmap objects being used in an application using + // SVG for all of its icons. + wxBitmap m_cachedBitmap; + wxDECLARE_NO_COPY_CLASS(wxBitmapBundleImplSVG); }; @@ -101,8 +112,16 @@ wxSize wxBitmapBundleImplSVG::GetDefaultSize() const wxBitmap wxBitmapBundleImplSVG::GetBitmap(const wxSize size) { - // TODO: Cache. + if ( !m_cachedBitmap.IsOk() || m_cachedBitmap.GetSize() != size ) + { + m_cachedBitmap = DoRasterize(size); + } + return m_cachedBitmap; +} + +wxBitmap wxBitmapBundleImplSVG::DoRasterize(const wxSize size) +{ wxVector buffer(size.x*size.y*4); nsvgRasterize ( From ab619010bdaf29e8f7a2d6f328fe399ed8b51684 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 2 Oct 2021 14:38:08 +0100 Subject: [PATCH 15/18] Add FromSVG() overload taking const data Passing non-const data is inconvenient and error-prone, as data can't be used again after it was modified by Nano SVG, which resulted in the button using SVG bitmap not working any longer in the toolbar sample after recreating the toolbar. So make it easier to do the right thing, while still keeping the overload taking non-const data for the situations when avoiding an extra copy is worth it. --- include/wx/bmpbndl.h | 3 +++ interface/wx/bmpbndl.h | 13 +++++++++---- samples/toolbar/toolbar.cpp | 2 +- src/generic/bmpsvg.cpp | 8 ++++++++ tests/graphics/bmpbundle.cpp | 6 ++---- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index b73d192056..1f3d33f973 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -67,6 +67,9 @@ public: // Notice that the data here is non-const because it can be temporarily // modified while parsing it. static wxBitmapBundle FromSVG(char* data, const wxSize sizeDef); + + // This overload currently makes a copy of the data. + static wxBitmapBundle FromSVG(const char* data, const wxSize sizeDef); #endif // wxHAS_RAW_BITMAP // Create from the resources: all existing versions of the bitmap of the diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h index 4d4b22c893..9808f60b5d 100644 --- a/interface/wx/bmpbndl.h +++ b/interface/wx/bmpbndl.h @@ -195,16 +195,21 @@ public: @param data This data may, or not, have the XML document preamble, i.e. it can start either with @c "" "" "" diff --git a/src/generic/bmpsvg.cpp b/src/generic/bmpsvg.cpp index 912817a37b..f440e5e151 100644 --- a/src/generic/bmpsvg.cpp +++ b/src/generic/bmpsvg.cpp @@ -172,4 +172,12 @@ wxBitmapBundle wxBitmapBundle::FromSVG(char* data, const wxSize sizeDef) return wxBitmapBundle(new wxBitmapBundleImplSVG(svgImage, sizeDef)); } +/* static */ +wxBitmapBundle wxBitmapBundle::FromSVG(const char* data, const wxSize sizeDef) +{ + wxCharBuffer copy(data); + + return FromSVG(copy.data(), sizeDef); +} + #endif // wxHAS_RAW_BITMAP diff --git a/tests/graphics/bmpbundle.cpp b/tests/graphics/bmpbundle.cpp index 3d0f58eedd..701b7e7a20 100644 --- a/tests/graphics/bmpbundle.cpp +++ b/tests/graphics/bmpbundle.cpp @@ -61,8 +61,7 @@ TEST_CASE("BitmapBundle::FromSVG", "[bmpbundle][svg]") "" ; - wxCharBuffer buf(svg_data); - wxBitmapBundle b = wxBitmapBundle::FromSVG(buf.data(), wxSize(20, 20)); + wxBitmapBundle b = wxBitmapBundle::FromSVG(svg_data, wxSize(20, 20)); REQUIRE( b.IsOk() ); CHECK( b.GetDefaultSize() == wxSize(20, 20) ); @@ -72,8 +71,7 @@ TEST_CASE("BitmapBundle::FromSVG", "[bmpbundle][svg]") const char* svg_tag_start = strstr(svg_data, " Date: Thu, 30 Sep 2021 17:50:13 +0200 Subject: [PATCH 16/18] wxArtProvider with wxBitmapBundle --- include/wx/artprov.h | 18 ++++++++ include/wx/osx/cocoa/private.h | 2 +- include/wx/osx/iphone/private.h | 2 +- interface/wx/artprov.h | 73 ++++++++++++++++++++++++++++++--- src/common/artprov.cpp | 56 ++++++++++++++++++++++++- src/osx/artmac.cpp | 4 +- src/osx/carbon/utilscocoa.mm | 13 +++--- 7 files changed, 149 insertions(+), 19 deletions(-) diff --git a/include/wx/artprov.h b/include/wx/artprov.h index 85fb9f6565..7bf65efbc4 100644 --- a/include/wx/artprov.h +++ b/include/wx/artprov.h @@ -15,6 +15,7 @@ #include "wx/bitmap.h" #include "wx/icon.h" #include "wx/iconbndl.h" +#include "wx/bmpbndl.h" class WXDLLIMPEXP_FWD_CORE wxArtProvidersList; class WXDLLIMPEXP_FWD_CORE wxArtProviderCache; @@ -157,6 +158,14 @@ public: const wxArtClient& client = wxASCII_STR(wxART_OTHER), const wxSize& size = wxDefaultSize); + // Query the providers for bitmapbundle with given ID and return it. + // If none is available, then the search for a bitmap with the same properties + // is performed. If successful, the bitmap is wrapped into a bitmap bundle. + static wxBitmapBundle + GetBitmapBundle(const wxArtID& id, + const wxArtClient& client = wxASCII_STR(wxART_OTHER), + const wxSize& size = wxDefaultSize); + // Query the providers for icon with given ID and return it. Return // wxNullIcon if no provider provides it. static wxIcon GetIcon(const wxArtID& id, @@ -225,6 +234,15 @@ protected: return wxNullBitmap; } + // Derived classes must override CreateBitmapBundle if they provide + // a bundle that cannot be represented through an ordinary bitmap. + virtual wxBitmapBundle CreateBitmapBundle(const wxArtID& id, + const wxArtClient& client, + const wxSize& size) + { + return wxBitmapBundle(CreateBitmap(id, client, size)); + } + virtual wxIconBundle CreateIconBundle(const wxArtID& WXUNUSED(id), const wxArtClient& WXUNUSED(client)) { diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 4e29fb6291..c00166e1ae 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -44,7 +44,7 @@ WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref ); WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCFURL( CFURLRef urlref ); WX_NSImage WXDLLIMPEXP_CORE wxOSXGetIconForType(OSType type ); void WXDLLIMPEXP_CORE wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height); -wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size); +wxBitmapBundle WXDLLIMPEXP_CORE wxOSXCreateSystemBitmapBundle(const wxString& id, const wxString &client, const wxSize& size); WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow(); WXWindow WXDLLIMPEXP_CORE wxOSXGetKeyWindow(); WXImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromNSCursor(const WXHCURSOR cursor); diff --git a/include/wx/osx/iphone/private.h b/include/wx/osx/iphone/private.h index 0bb8939514..1acf0dd175 100644 --- a/include/wx/osx/iphone/private.h +++ b/include/wx/osx/iphone/private.h @@ -34,7 +34,7 @@ OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage( CGImageRef inImage) ; WX_UIImage WXDLLIMPEXP_CORE wxOSXGetUIImageFromCGImage( CGImageRef image ); -wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size); +wxBitmapBundle WXDLLIMPEXP_CORE wxOSXCreateSystemBitmapBundle(const wxString& id, const wxString &client, const wxSize& size); class WXDLLIMPEXP_CORE wxWidgetIPhoneImpl : public wxWidgetImpl { diff --git a/interface/wx/artprov.h b/interface/wx/artprov.h index 260f61d218..95df55859f 100644 --- a/interface/wx/artprov.h +++ b/interface/wx/artprov.h @@ -110,13 +110,21 @@ const char* wxART_EDIT; class MyProvider : public wxArtProvider { protected: + // Override this method to return a bundle containing the required + // bitmap in all available sizes. + wxBitmapBundle CreateBitmapBundle(const wxArtID& id, + const wxArtClient& client, + const wxSize& size) override; + + // If all bitmaps are available in a single size only, it may be + // simpler to override just this one. wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, - const wxSize& size); + const wxSize& size) override; // optionally override this one as well wxIconBundle CreateIconBundle(const wxArtID& id, - const wxArtClient& client); + const wxArtClient& client) override; { ... } }; ... @@ -128,8 +136,8 @@ const char* wxART_EDIT; and supplying icon bundles that contain different bitmap sizes. There's another way of taking advantage of this class: you can use it in your - code and use platform native icons as provided by wxArtProvider::GetBitmap or - wxArtProvider::GetIcon. + code and use platform native icons as provided by wxArtProvider::GetBitmapBundle + or wxArtProvider::GetIcon. @section artprovider_identify Identifying art resources @@ -272,6 +280,9 @@ public: /** Query registered providers for bitmap with given ID. + Note that applications using wxWidgets 3.1.6 or later should prefer + calling GetBitmapBundle(). + @param id wxArtID unique identifier of the bitmap. @param client @@ -286,6 +297,28 @@ public: const wxArtClient& client = wxART_OTHER, const wxSize& size = wxDefaultSize); + /** + Query registered providers for a bundle of bitmaps with given ID. + + @since 3.1.6 + + @param id + wxArtID unique identifier of the bitmap. + @param client + wxArtClient identifier of the client (i.e. who is asking for the bitmap). + @param size + Default size for the returned bundle. + + @return If any of the registered providers recognizes the ID in its + CreateBitmapBundle(), this bundle is returned. Otherwise, if any of + providers returns a valid bitmap from CreateBitmap(), the bundle + containing only this bitmap is returned. Otherwise, an empty bundle + is returned. + */ + static wxBitmapBundle GetBitmapBundle(const wxArtID& id, + const wxArtClient& client = wxART_OTHER, + const wxSize& size = wxDefaultSize); + /** Same as wxArtProvider::GetBitmap, but return a wxIcon object (or ::wxNullIcon on failure). @@ -404,8 +437,13 @@ public: protected: /** - Derived art provider classes must override this method to create requested art - resource. Note that returned bitmaps are cached by wxArtProvider and it is + Derived art provider classes may override this method to create requested art + resource. + + For bitmaps available in more than one size, CreateBitmapBundle() + should be overridden instead. + + Note that returned bitmaps are cached by wxArtProvider and it is therefore not necessary to optimize CreateBitmap() for speed (e.g. you may create wxBitmap objects from XPMs here). @@ -429,6 +467,29 @@ protected: const wxArtClient& client, const wxSize& size); + /** + Override this method to create the requested art resources available in + more than one size. + + Unlike CreateBitmap(), this method can be overridden to return the same + bitmap in several (or all, if wxBitmapBundle::FromSVG() is used) sizes + at once, which will allow selecting the size best suited for the + current display resolution automatically. + + @param id + wxArtID unique identifier of the bitmap. + @param client + wxArtClient identifier of the client (i.e. who is asking for the bitmap). + This only serves as a hint. + @param size + Default size of the bitmaps returned by the bundle. + + @since 3.1.6 + */ + virtual wxBitmapBundle CreateBitmapBundle(const wxArtID& id, + const wxArtClient& client, + const wxSize& size); + /** This method is similar to CreateBitmap() but can be used when a bitmap (or an icon) exists in several sizes. diff --git a/src/common/artprov.cpp b/src/common/artprov.cpp index 07d662dacc..66327070fb 100644 --- a/src/common/artprov.cpp +++ b/src/common/artprov.cpp @@ -39,6 +39,7 @@ WX_DEFINE_LIST(wxArtProvidersList) // ---------------------------------------------------------------------------- WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmap, wxArtProviderBitmapsHash); +WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmapBundle, wxArtProviderBitmapBundlesHash); WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxIconBundle, wxArtProviderIconBundlesHash); class WXDLLEXPORT wxArtProviderCache @@ -48,6 +49,10 @@ public: void PutBitmap(const wxString& full_id, const wxBitmap& bmp) { m_bitmapsHash[full_id] = bmp; } + bool GetBitmapBundle(const wxString& full_id, wxBitmapBundle* bmpbndl); + void PutBitmapBundle(const wxString& full_id, const wxBitmapBundle& bmpbndl) + { m_bitmapsBundlesHash[full_id] = bmpbndl; } + bool GetIconBundle(const wxString& full_id, wxIconBundle* bmp); void PutIconBundle(const wxString& full_id, const wxIconBundle& iconbundle) { m_iconBundlesHash[full_id] = iconbundle; } @@ -62,8 +67,9 @@ public: const wxArtClient& client); private: - wxArtProviderBitmapsHash m_bitmapsHash; // cache of wxBitmaps - wxArtProviderIconBundlesHash m_iconBundlesHash; // cache of wxIconBundles + wxArtProviderBitmapsHash m_bitmapsHash; // cache of wxBitmaps + wxArtProviderBitmapBundlesHash m_bitmapsBundlesHash; // cache of wxBitmaps + wxArtProviderIconBundlesHash m_iconBundlesHash; // cache of wxIconBundles }; bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp) @@ -80,6 +86,21 @@ bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp) } } +bool wxArtProviderCache::GetBitmapBundle(const wxString& full_id, wxBitmapBundle* bmpbndl) +{ + wxArtProviderBitmapBundlesHash::iterator entry = m_bitmapsBundlesHash.find(full_id); + if ( entry == m_bitmapsBundlesHash.end() ) + { + return false; + } + else + { + *bmpbndl = entry->second; + return true; + } +} + + bool wxArtProviderCache::GetIconBundle(const wxString& full_id, wxIconBundle* bmp) { wxArtProviderIconBundlesHash::iterator entry = m_iconBundlesHash.find(full_id); @@ -274,6 +295,37 @@ void wxArtProvider::RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded) return bmp; } +/*static*/ +wxBitmapBundle wxArtProvider::GetBitmapBundle(const wxArtID& id, + const wxArtClient& client, + const wxSize& size) +{ + // safety-check against writing client,id,size instead of id,client,size: + wxASSERT_MSG( client.Last() == wxT('C'), wxT("invalid 'client' parameter") ); + + wxCHECK_MSG( sm_providers, wxNullBitmap, wxT("no wxArtProvider exists") ); + + wxString hashId = wxArtProviderCache::ConstructHashID(id, client); + + wxBitmapBundle bitmapbundle; // (DoGetIconBundle(id, client)); + + if ( !sm_cache->GetBitmapBundle(hashId, &bitmapbundle) ) + { + for (wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst(); + node; node = node->GetNext()) + { + bitmapbundle = node->GetData()->CreateBitmapBundle(id, client, size); + if ( bitmapbundle.IsOk() ) + break; + } + + sm_cache->PutBitmapBundle(hashId, bitmapbundle); + } + + return bitmapbundle; +} + + /*static*/ wxIconBundle wxArtProvider::GetIconBundle(const wxArtID& id, const wxArtClient& client) { diff --git a/src/osx/artmac.cpp b/src/osx/artmac.cpp index fda7bd5658..81faccb758 100644 --- a/src/osx/artmac.cpp +++ b/src/osx/artmac.cpp @@ -35,11 +35,11 @@ protected: const wxArtClient& client) wxOVERRIDE; #endif #if wxOSX_USE_COCOA_OR_IPHONE - virtual wxBitmap CreateBitmap(const wxArtID& id, + virtual wxBitmapBundle CreateBitmapBundle(const wxArtID& id, const wxArtClient& client, const wxSize& size) wxOVERRIDE { - return wxOSXCreateSystemBitmap(id, client, size); + return wxOSXCreateSystemBitmapBundle(id, client, size); } #endif }; diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 7e27bb21ac..4dbf4848e8 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -27,6 +27,7 @@ #endif #include "wx/fontutil.h" +#include "wx/private/bmpbndl.h" #ifdef __WXMAC__ @@ -165,14 +166,14 @@ WXWindow wxOSXGetKeyWindow() #if wxOSX_USE_IPHONE -wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, const wxSize& size) +wxBitmapBundle wxOSXCreateSystemBitmapBundle(const wxString& name, const wxString &client, const wxSize& size) { #if 1 // unfortunately this only accesses images in the app bundle, not the system wide globals wxCFStringRef cfname(name); - return wxBitmap( [[UIImage imageNamed:cfname.AsNSString()] CGImage] ); + return wxOSXMakeBundleFromImage( [UIImage imageNamed:cfname.AsNSString()] ); #else - return wxBitmap(); + return wxNullBitmap; #endif } @@ -197,14 +198,12 @@ WXImage wxOSXGetSystemImage(const wxString& name) return nsimage; } -wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &WXUNUSED(client), const wxSize& WXUNUSED(sizeHint)) +wxBitmapBundle wxOSXCreateSystemBitmapBundle(const wxString& name, const wxString &WXUNUSED(client), const wxSize& WXUNUSED(sizeHint)) { NSImage* nsimage = wxOSXGetSystemImage(name); if ( nsimage ) { - // if ( sizeHint != wxDefaultSize ) - // [nsimage setSize:NSMakeSize(sizeHint.GetHeight(), sizeHint.GetWidth())]; - return wxBitmap( nsimage ); + return wxOSXMakeBundleFromImage( nsimage ); } return wxNullBitmap; } From 0216654272567762c8775b5735de5ad9bb724e40 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 2 Oct 2021 16:33:49 +0100 Subject: [PATCH 17/18] Make wxBitmapBundleImpl public and show how to use it Show how a custom implementation of wxBitmapBundleImpl can be defined in the toolbar sample. --- include/wx/bmpbndl.h | 30 +++++++++++++++ include/wx/private/bmpbndl.h | 29 +-------------- interface/wx/bmpbndl.h | 72 ++++++++++++++++++++++++++++++++++++ samples/toolbar/toolbar.cpp | 58 ++++++++++++++++++++++++++--- 4 files changed, 155 insertions(+), 34 deletions(-) diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index 1f3d33f973..21f0da4174 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -149,4 +149,34 @@ wxBitmapBundle wxBitmapBundle::FromImage(const wxImage& image) return FromBitmap(wxBitmap(image)); } +// ---------------------------------------------------------------------------- +// wxBitmapBundleImpl is the base class for all wxBitmapBundle implementations +// ---------------------------------------------------------------------------- + +// This class inherits from wxRefCounter to make it possible to use it with +// wxObjectDataPtr in wxBitmapBundle. +// +// It doesn't need to be used directly, but may be inherited from in order to +// implement custom bitmap bundles. +class wxBitmapBundleImpl : public wxRefCounter +{ +public: + // Return the size of the bitmaps represented by this bundle in the default + // DPI (a.k.a. 100% resolution). + // + // Must always return a valid size. + virtual wxSize GetDefaultSize() const = 0; + + // Retrieve the bitmap of exactly the given size. + // + // Note that this function is non-const because it may generate the bitmap + // on demand and cache it. + virtual wxBitmap GetBitmap(const wxSize size) = 0; + +#ifdef __WXOSX__ + // returns the native representation of the bitmap bundle + virtual WXImage OSXGetImage() const { return NULL; } +#endif +}; + #endif // _WX_BMPBNDL_H_ diff --git a/include/wx/private/bmpbndl.h b/include/wx/private/bmpbndl.h index 1d986a18cc..6c25a51e62 100644 --- a/include/wx/private/bmpbndl.h +++ b/include/wx/private/bmpbndl.h @@ -10,34 +10,7 @@ #ifndef _WX_PRIVATE_BMPBNDL_H_ #define _WX_PRIVATE_BMPBNDL_H_ -#include "wx/object.h" - -// ---------------------------------------------------------------------------- -// wxBitmapBundleImpl is the base class for all wxBitmapBundle implementations -// ---------------------------------------------------------------------------- - -// This class inherits from wxRefCounter to make it possible to use it with -// wxObjectDataPtr in wxBitmapBundle. -class wxBitmapBundleImpl : public wxRefCounter -{ -public: - // Return the size of the bitmaps represented by this bundle in the default - // DPI (a.k.a. 100% resolution). - // - // Must always return a valid size. - virtual wxSize GetDefaultSize() const = 0; - - // Retrieve the bitmap of exactly the given size. - // - // Note that this function is non-const because it may generate the bitmap - // on demand and cache it. - virtual wxBitmap GetBitmap(const wxSize size) = 0; - -#ifdef __WXOSX__ - // returns the native representation of the bitmap bundle - virtual WXImage OSXGetImage() const { return NULL; } -#endif -}; +#include "wx/bmpbndl.h" #ifdef __WXOSX__ diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h index 9808f60b5d..b7ea18bc1c 100644 --- a/interface/wx/bmpbndl.h +++ b/interface/wx/bmpbndl.h @@ -161,6 +161,20 @@ public: */ static wxBitmapBundle FromImage(const wxImage& image); + /** + Create a bundle from a custom bitmap bundle implementation. + + This function can be used to create bundles implementing custom logic + for creating the bitmaps, e.g. creating them on the fly rather than + using predefined bitmaps. + + See wxBitmapBundleImpl. + + @param impl A valid, i.e. non-null, pointer. This function takes + ownership of it, so the caller must @e not call DecRef() on it. + */ + static wxBitmapBundle FromImpl(wxBitmapBundleImpl* impl); + /** Create a bundle from the bitmaps in the application resources. @@ -243,6 +257,64 @@ public: wxBitmap GetBitmap(const wxSize size) const; }; +/** + Base class for custom implementations of wxBitmapBundle. + + This class shouldn't be used directly in the application code, but may be + derived from to implement custom bitmap bundles. + + Example of use: + @code + class MyCustomBitmapBundleImpl : public wxBitmapBundleImpl + { + public: + MyCustomBitmapBundleImpl() + { + } + + wxSize GetDefaultSize() const wxOVERRIDE + { + ... determine the minimum/default size for bitmap to use ... + } + + wxBitmap GetBitmap(const wxSize size) wxOVERRIDE + { + ... get the bitmap of the requested size from somewhere and + cache it if necessary, i.e. if getting it is expensive ... + } + }; + + toolBar->AddTool(wxID_OPEN, wxBitmapBundle::FromImpl(new MyCustomBitmapBundleImpl()); + @endcode + + Full (but still very simple) example of using it can be found in the + toolbar sample code. + + @library{wxcore} + @category{gdi} + + @since 3.1.6 +*/ +class wxBitmapBundleImpl : public wxRefCounter +{ +public: + /** + Return the size of the bitmaps represented by this bundle in the default + DPI. + + Must always return a valid size. + */ + virtual wxSize GetDefaultSize() const = 0; + + /** + Retrieve the bitmap of exactly the given size. + + Note that this function is non-const because it may generate the bitmap + on demand and cache it. + */ + virtual wxBitmap GetBitmap(const wxSize size) = 0; +}; + /** Creates a wxBitmapBundle from resources on the platforms supporting them or from two embedded bitmaps otherwise. diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 157a62410a..1752905751 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -499,15 +499,61 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) if ( !m_pathBmp.empty() ) { - // create a tool with a custom bitmap for testing - wxImage img(m_pathBmp); - if ( img.IsOk() ) + wxImage image(m_pathBmp); + if ( image.IsOk() ) { - if ( img.GetWidth() > sizeBitmap.x && img.GetHeight() > sizeBitmap.y ) - img = img.GetSubImage(wxRect(0, 0, sizeBitmap.x, sizeBitmap.y)); + // create a custom bitmap bundle for testing + class MyCustomBitmapBundleImpl : public wxBitmapBundleImpl + { + public: + MyCustomBitmapBundleImpl(const wxImage& image, + const wxSize& sizeDef) + : m_image(image), + m_sizeDef(sizeDef) + { + } + + wxSize GetDefaultSize() const wxOVERRIDE + { + return m_sizeDef; + } + + wxBitmap GetBitmap(const wxSize size) wxOVERRIDE + { + // In this simple implementation we don't bother caching + // anything. + wxImage image = m_image; + if ( image.GetSize() != size ) + image.Rescale(size.x, size.y, wxIMAGE_QUALITY_HIGH); + + // This is required under MSW in order to be able to draw + // over the bitmap using wxDC. For full alpha support, + // wxGraphicsContext should be used. + if ( image.HasAlpha() ) + image.ClearAlpha(); + + wxBitmap bitmap(image); + + // This is the custom part: we show the size of the bitmap + // being used in the bitmap itself. + wxMemoryDC dc(bitmap); + dc.SetTextForeground(*wxRED); + dc.SetFont(wxFontInfo(wxSize(size.x/4, size.y/2)).Bold()); + dc.DrawText(wxString::Format("%d", size.y), size.x/4, size.y/4); + + return bitmap; + } + + private: + const wxImage m_image; + const wxSize m_sizeDef; + }; + + wxBitmapBundleImpl* const + impl = new MyCustomBitmapBundleImpl(image, sizeBitmap); toolBar->AddSeparator(); - toolBar->AddTool(wxID_ANY, "Custom", img); + toolBar->AddTool(wxID_ANY, "Custom", wxBitmapBundle::FromImpl(impl)); } } From fb4e188cea7ef9be6236761cbf603441c499b2e0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 5 Oct 2021 16:12:01 +0100 Subject: [PATCH 18/18] Add wxHAS_SVG feature test macro This is more clear and future-proof than using wxHAS_RAW_BITMAP for checking for SVG availability. --- docs/doxygen/mainpages/const_cpp.h | 1 + include/wx/bmpbndl.h | 11 +++++++++-- interface/wx/bmpbndl.h | 6 +++--- samples/toolbar/toolbar.cpp | 2 ++ src/generic/bmpsvg.cpp | 7 ++++--- tests/graphics/bmpbundle.cpp | 4 ++-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/doxygen/mainpages/const_cpp.h b/docs/doxygen/mainpages/const_cpp.h index e519d217e5..0c9fdd9b8b 100644 --- a/docs/doxygen/mainpages/const_cpp.h +++ b/docs/doxygen/mainpages/const_cpp.h @@ -209,6 +209,7 @@ Currently the following symbols exist: @itemdef{wxHAS_REGEX_ADVANCED, Defined if advanced syntax is available in wxRegEx. This is always the case in wxWidgets 3.1.6 and later, so this symbol doesn't need to be tested any more.} +@itemdef{wxHAS_SVG, Defined if SVG support (currently only via wxBitmapBundle::FromSVG()) is available.} @itemdef{wxHAS_TASK_BAR_ICON, Defined if wxTaskBarIcon is available on the current platform.} @itemdef{wxHAS_WINDOW_LABEL_IN_STATIC_BOX, Defined if wxStaticBox::Create() overload taking @c wxWindow* instead of the text label is available on the current platform.} diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index 21f0da4174..70794bf756 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -16,6 +16,13 @@ class wxBitmapBundleImpl; +// It should be possible to implement SVG rasterizing without raw bitmap +// support using wxDC::DrawSpline(), but currently we don't do it and so +// FromSVG() is only available in the ports providing raw bitmap access. +#ifdef wxHAS_RAW_BITMAP + #define wxHAS_SVG +#endif + // ---------------------------------------------------------------------------- // wxBitmapBundle provides 1 or more versions of a bitmap, all bundled together // ---------------------------------------------------------------------------- @@ -62,7 +69,7 @@ public: // It should be possible to implement SVG rasterizing without raw bitmap // support using wxDC::DrawSpline(), but currently we don't do it and so // FromSVG() is only available in the ports providing raw bitmap access. -#ifdef wxHAS_RAW_BITMAP +#ifdef wxHAS_SVG // Create from the SVG data (data is supposed to be in UTF-8 encoding). // Notice that the data here is non-const because it can be temporarily // modified while parsing it. @@ -70,7 +77,7 @@ public: // This overload currently makes a copy of the data. static wxBitmapBundle FromSVG(const char* data, const wxSize sizeDef); -#endif // wxHAS_RAW_BITMAP +#endif // wxHAS_SVG // Create from the resources: all existing versions of the bitmap of the // form name_2x or name@2x (and also using other factors) will be used. diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h index b7ea18bc1c..9cc2194e1a 100644 --- a/interface/wx/bmpbndl.h +++ b/interface/wx/bmpbndl.h @@ -203,9 +203,9 @@ public: These limitations will be relaxed in the future wxWidgets versions. Please also note that this method is only available in the ports - providing raw bitmap access via wxPixelData and so defining - wxHAS_RAW_BITMAP symbol. Currently SVG images are not supported in the - ports without it, e.g. wxX11. + providing raw bitmap access via wxPixelData. This is the case for all + tier-1 ports, but not all of them, check if @c wxHAS_SVG is defined + before using this method if for maximum portability. @param data This data may, or not, have the XML document preamble, i.e. it can start either with @c "