1 #ifndef FILEZILLA_INTERFACE_THEMEPROVIDER_HEADER 2 #define FILEZILLA_INTERFACE_THEMEPROVIDER_HEADER 3 4 #include "option_change_event_handler.h" 5 6 #include <memory> 7 8 #include <libfilezilla/time.hpp> 9 10 enum iconSize 11 { 12 iconSizeTiny, 13 iconSizeSmall, 14 iconSize24, 15 iconSizeNormal, 16 iconSizeLarge, 17 iconSizeHuge 18 }; 19 20 class CTheme final 21 { 22 public: 23 bool Load(std::wstring const& theme); 24 bool Load(std::wstring const& theme, std::vector<wxSize> sizes); 25 26 wxBitmap const& LoadBitmap(std::wstring const& name, wxSize const& size); 27 wxAnimation LoadAnimation(std::wstring const& name, wxSize const& size); 28 29 static wxSize StringToSize(std::wstring const&); 30 get_theme()31 std::wstring get_theme() const { return theme_; } get_name()32 std::wstring get_name() const { return name_; } get_author()33 std::wstring get_author() const { return author_; } get_mail()34 std::wstring get_mail() const { return mail_; } 35 36 std::vector<wxBitmap> GetAllImages(wxSize const& size); 37 private: 38 struct size_cmp final 39 { operatorfinal40 bool operator()(wxSize const& a, wxSize const&b) const { 41 return a.x < b.x || (a.x == b.x && a.y < b.y); 42 } 43 }; 44 45 struct cacheEntry 46 { 47 // Converting from wxImage to wxBitmap to wxImage is quite slow, so cache the images as well. 48 std::map<wxSize, wxBitmap, size_cmp> bitmaps_; 49 std::map<wxSize, wxImage, size_cmp> images_; 50 }; 51 52 wxBitmap const& DoLoadBitmap(std::wstring const& name, wxSize const& size, cacheEntry & cache); 53 54 wxBitmap const& LoadBitmapWithSpecificSizeAndScale(std::wstring const& name, wxSize const& size, wxSize const& scale, cacheEntry & cache); 55 56 wxImage const& LoadImageWithSpecificSize(std::wstring const& file, wxSize const& size, cacheEntry & cache); 57 58 std::wstring theme_; 59 std::wstring path_; 60 61 std::wstring name_; 62 std::wstring author_; 63 std::wstring mail_; 64 65 fz::datetime timestamp_; 66 67 std::map<wxSize, bool, size_cmp> sizes_; 68 69 std::map<std::wstring, cacheEntry> cache_; 70 }; 71 72 class CThemeProvider final : public wxArtProvider, public wxEvtHandler, public COptionChangeEventHandler 73 { 74 public: 75 CThemeProvider(); 76 virtual ~CThemeProvider(); 77 78 static std::vector<std::wstring> GetThemes(); 79 std::vector<wxBitmap> GetAllImages(std::wstring const& theme, wxSize const& size); 80 bool GetThemeData(std::wstring const& theme, std::wstring& name, std::wstring& author, std::wstring& email); 81 static wxIconBundle GetIconBundle(const wxArtID& id, const wxArtClient& client = wxART_OTHER); 82 83 static wxSize GetIconSize(iconSize size, bool userScaled = false); 84 85 // Note: Always 1 on OS X 86 static double GetUIScaleFactor(); 87 88 static CThemeProvider* Get(); 89 90 wxAnimation CreateAnimation(wxArtID const& id, wxSize const& size); 91 92 virtual wxBitmap CreateBitmap(wxArtID const& id, wxArtClient const& client, wxSize const& size); 93 94 protected: 95 96 virtual void OnOptionsChanged(watched_options const& options); 97 98 std::map<std::wstring, CTheme> themes_; 99 }; 100 101 #endif 102