icon.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/icon.h
  3. // Purpose: wxIcon class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_ICON_H_
  11. #define _WX_ICON_H_
  12. // ----------------------------------------------------------------------------
  13. // headers
  14. // ----------------------------------------------------------------------------
  15. #include "wx/msw/gdiimage.h"
  16. // ---------------------------------------------------------------------------
  17. // icon data
  18. // ---------------------------------------------------------------------------
  19. // notice that although wxIconRefData inherits from wxBitmapRefData, it is not
  20. // a valid wxBitmapRefData
  21. class WXDLLIMPEXP_CORE wxIconRefData : public wxGDIImageRefData
  22. {
  23. public:
  24. wxIconRefData() { }
  25. virtual ~wxIconRefData() { Free(); }
  26. virtual void Free();
  27. };
  28. // ---------------------------------------------------------------------------
  29. // Icon
  30. // ---------------------------------------------------------------------------
  31. class WXDLLIMPEXP_CORE wxIcon : public wxGDIImage
  32. {
  33. public:
  34. // ctors
  35. // default
  36. wxIcon() { }
  37. // from raw data
  38. wxIcon(const char bits[], int width, int height);
  39. // from XPM data
  40. wxIcon(const char* const* data) { CreateIconFromXpm(data); }
  41. #ifdef wxNEEDS_CHARPP
  42. wxIcon(char **data) { CreateIconFromXpm(const_cast<const char* const*>(data)); }
  43. #endif
  44. // from resource/file
  45. wxIcon(const wxString& name,
  46. wxBitmapType type = wxICON_DEFAULT_TYPE,
  47. int desiredWidth = -1, int desiredHeight = -1);
  48. wxIcon(const wxIconLocation& loc);
  49. virtual ~wxIcon();
  50. virtual bool LoadFile(const wxString& name,
  51. wxBitmapType type = wxICON_DEFAULT_TYPE,
  52. int desiredWidth = -1, int desiredHeight = -1);
  53. bool CreateFromHICON(WXHICON icon);
  54. // implementation only from now on
  55. wxIconRefData *GetIconData() const { return (wxIconRefData *)m_refData; }
  56. void SetHICON(WXHICON icon) { SetHandle((WXHANDLE)icon); }
  57. WXHICON GetHICON() const { return (WXHICON)GetHandle(); }
  58. // create from bitmap (which should have a mask unless it's monochrome):
  59. // there shouldn't be any implicit bitmap -> icon conversion (i.e. no
  60. // ctors, assignment operators...), but it's ok to have such function
  61. void CopyFromBitmap(const wxBitmap& bmp);
  62. protected:
  63. virtual wxGDIImageRefData *CreateData() const
  64. {
  65. return new wxIconRefData;
  66. }
  67. virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
  68. // create from XPM data
  69. void CreateIconFromXpm(const char* const* data);
  70. private:
  71. DECLARE_DYNAMIC_CLASS(wxIcon)
  72. };
  73. #endif
  74. // _WX_ICON_H_