iconbndl.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/iconbndl.h
  3. // Purpose: wxIconBundle
  4. // Author: Mattia barbon
  5. // Modified by:
  6. // Created: 23.03.02
  7. // Copyright: (c) Mattia Barbon
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_ICONBNDL_H_
  11. #define _WX_ICONBNDL_H_
  12. #include "wx/gdiobj.h"
  13. #include "wx/gdicmn.h" // for wxSize
  14. #include "wx/icon.h"
  15. #include "wx/dynarray.h"
  16. class WXDLLIMPEXP_FWD_BASE wxInputStream;
  17. WX_DECLARE_EXPORTED_OBJARRAY(wxIcon, wxIconArray);
  18. // this class can't load bitmaps of type wxBITMAP_TYPE_ICO_RESOURCE,
  19. // if you need them, you have to load them manually and call
  20. // wxIconCollection::AddIcon
  21. class WXDLLIMPEXP_CORE wxIconBundle : public wxGDIObject
  22. {
  23. public:
  24. // Flags that determine what happens if GetIcon() doesn't find the icon of
  25. // exactly the requested size.
  26. enum
  27. {
  28. // Return invalid icon if exact size is not found.
  29. FALLBACK_NONE = 0,
  30. // Return the icon of the system icon size if exact size is not found.
  31. // May be combined with other non-NONE enum elements to determine what
  32. // happens if the system icon size is not found neither.
  33. FALLBACK_SYSTEM = 1,
  34. // Return the icon of closest larger size or, if there is no icon of
  35. // larger size in the bundle, the closest icon of smaller size.
  36. FALLBACK_NEAREST_LARGER = 2
  37. };
  38. // default constructor
  39. wxIconBundle();
  40. // initializes the bundle with the icon(s) found in the file
  41. #if wxUSE_STREAMS && wxUSE_IMAGE
  42. #if wxUSE_FFILE || wxUSE_FILE
  43. wxIconBundle(const wxString& file, wxBitmapType type = wxBITMAP_TYPE_ANY);
  44. #endif // wxUSE_FFILE || wxUSE_FILE
  45. wxIconBundle(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY);
  46. #endif // wxUSE_STREAMS && wxUSE_IMAGE
  47. // initializes the bundle with a single icon
  48. wxIconBundle(const wxIcon& icon);
  49. // default copy ctor and assignment operator are OK
  50. // adds all the icons contained in the file to the collection,
  51. // if the collection already contains icons with the same
  52. // width and height, they are replaced
  53. #if wxUSE_STREAMS && wxUSE_IMAGE
  54. #if wxUSE_FFILE || wxUSE_FILE
  55. void AddIcon(const wxString& file, wxBitmapType type = wxBITMAP_TYPE_ANY);
  56. #endif // wxUSE_FFILE || wxUSE_FILE
  57. void AddIcon(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY);
  58. #endif // wxUSE_STREAMS && wxUSE_IMAGE
  59. // adds the icon to the collection, if the collection already
  60. // contains an icon with the same width and height, it is
  61. // replaced
  62. void AddIcon(const wxIcon& icon);
  63. // returns the icon with the given size; if no such icon exists,
  64. // behavior is specified by the flags.
  65. wxIcon GetIcon(const wxSize& size, int flags = FALLBACK_SYSTEM) const;
  66. // equivalent to GetIcon(wxSize(size, size))
  67. wxIcon GetIcon(wxCoord size = wxDefaultCoord,
  68. int flags = FALLBACK_SYSTEM) const
  69. { return GetIcon(wxSize(size, size), flags); }
  70. // returns the icon exactly of the specified size or wxNullIcon if no icon
  71. // of exactly given size are available
  72. wxIcon GetIconOfExactSize(const wxSize& size) const;
  73. wxIcon GetIconOfExactSize(wxCoord size) const
  74. { return GetIconOfExactSize(wxSize(size, size)); }
  75. // enumerate all icons in the bundle: don't use these functions if ti can
  76. // be avoided, using GetIcon() directly is better
  77. // return the number of available icons
  78. size_t GetIconCount() const;
  79. // return the icon at index (must be < GetIconCount())
  80. wxIcon GetIconByIndex(size_t n) const;
  81. // check if we have any icons at all
  82. bool IsEmpty() const { return GetIconCount() == 0; }
  83. #if WXWIN_COMPATIBILITY_2_8
  84. #if wxUSE_STREAMS && wxUSE_IMAGE && (wxUSE_FFILE || wxUSE_FILE)
  85. wxDEPRECATED( void AddIcon(const wxString& file, long type)
  86. {
  87. AddIcon(file, (wxBitmapType)type);
  88. }
  89. )
  90. wxDEPRECATED_CONSTRUCTOR( wxIconBundle (const wxString& file, long type)
  91. {
  92. AddIcon(file, (wxBitmapType)type);
  93. }
  94. )
  95. #endif // wxUSE_STREAMS && wxUSE_IMAGE && (wxUSE_FFILE || wxUSE_FILE)
  96. #endif // WXWIN_COMPATIBILITY_2_8
  97. protected:
  98. virtual wxGDIRefData *CreateGDIRefData() const;
  99. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  100. private:
  101. // delete all icons
  102. void DeleteIcons();
  103. DECLARE_DYNAMIC_CLASS(wxIconBundle)
  104. };
  105. #endif // _WX_ICONBNDL_H_