1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/gdiimage.h
// Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
// under MSW
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.11.99
// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// NB: this is a private header, it is not intended to be directly included by
// user code (but may be included from other, public, wxWin headers
#ifndef _WX_MSW_GDIIMAGE_H_
#define _WX_MSW_GDIIMAGE_H_
#include "wx/gdiobj.h" // base class
#include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
#include "wx/list.h"
class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData;
class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler;
class WXDLLIMPEXP_FWD_CORE wxGDIImage;
WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
// ----------------------------------------------------------------------------
// wxGDIImageRefData: common data fields for all derived classes
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxGDIImageRefData : public wxGDIRefData
{
public:
wxGDIImageRefData()
{
m_width = m_height = m_depth = 0;
m_handle = 0;
}
wxGDIImageRefData(const wxGDIImageRefData& data) : wxGDIRefData()
{
m_width = data.m_width;
m_height = data.m_height;
m_depth = data.m_depth;
// can't copy handles like this, derived class copy ctor must do it!
m_handle = NULL;
}
// accessors
virtual bool IsOk() const { return m_handle != 0; }
void SetSize(int w, int h) { m_width = w; m_height = h; }
// free the ressources we allocated
virtual void Free() = 0;
// for compatibility, the member fields are public
// the size of the image
int m_width, m_height;
// the depth of the image
int m_depth;
// the handle to it
union
{
WXHANDLE m_handle; // for untyped access
WXHBITMAP m_hBitmap;
WXHICON m_hIcon;
WXHCURSOR m_hCursor;
};
};
// ----------------------------------------------------------------------------
// wxGDIImage: this class supports GDI image handlers which may be registered
// dynamically and will be used for loading/saving the images in the specified
// format. It also falls back to wxImage if no appropriate image is found.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxGDIImage : public wxGDIObject
{
public:
// handlers list interface
static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
static void AddHandler(wxGDIImageHandler *handler);
static void InsertHandler(wxGDIImageHandler *handler);
static bool RemoveHandler(const wxString& name);
static wxGDIImageHandler *FindHandler(const wxString& name);
static wxGDIImageHandler *FindHandler(const wxString& extension, long type);
static wxGDIImageHandler *FindHandler(long type);
static void InitStandardHandlers();
static void CleanUpHandlers();
// access to the ref data casted to the right type
wxGDIImageRefData *GetGDIImageData() const
{ return (wxGDIImageRefData *)m_refData; }
// accessors
WXHANDLE GetHandle() const
{ return IsNull() ? 0 : GetGDIImageData()->m_handle; }
void SetHandle(WXHANDLE handle)
{ AllocExclusive(); GetGDIImageData()->m_handle = handle; }
int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; }
int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
wxSize GetSize() const
{
return IsNull() ? wxSize(0,0) :
wxSize(GetGDIImageData()->m_width, GetGDIImageData()->m_height);
}
void SetWidth(int w) { AllocExclusive(); GetGDIImageData()->m_width = w; }
void SetHeight(int h) { AllocExclusive(); GetGDIImageData()->m_height = h; }
void SetDepth(int d) { AllocExclusive(); GetGDIImageData()->m_depth = d; }
void SetSize(int w, int h)
{
AllocExclusive();
GetGDIImageData()->SetSize(w, h);
}
void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
// forward some of base class virtuals to wxGDIImageRefData
bool FreeResource(bool force = false);
virtual WXHANDLE GetResourceHandle() const;
protected:
// create the data for the derived class here
virtual wxGDIImageRefData *CreateData() const = 0;
// implement the wxGDIObject method in terms of our, more specific, one
virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); }
// we can't [efficiently] clone objects of this class
virtual wxGDIRefData *
CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
{
wxFAIL_MSG( wxT("must be implemented if used") );
return NULL;
}
static wxGDIImageHandlerList ms_handlers;
};
// ----------------------------------------------------------------------------
// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxGDIImageHandler : public wxObject
{
public:
// ctor
wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; }
wxGDIImageHandler(const wxString& name,
const wxString& ext,
wxBitmapType type)
: m_name(name), m_extension(ext), m_type(type) { }
// accessors
void SetName(const wxString& name) { m_name = name; }
void SetExtension(const wxString& ext) { m_extension = ext; }
void SetType(wxBitmapType type) { m_type = type; }
const wxString& GetName() const { return m_name; }
const wxString& GetExtension() const { return m_extension; }
wxBitmapType GetType() const { return m_type; }
// real handler operations: to implement in derived classes
virtual bool Create(wxGDIImage *image,
const void* data,
wxBitmapType flags,
int width, int height, int depth = 1) = 0;
virtual bool Load(wxGDIImage *image,
const wxString& name,
wxBitmapType flags,
int desiredWidth, int desiredHeight) = 0;
virtual bool Save(const wxGDIImage *image,
const wxString& name,
wxBitmapType type) const = 0;
protected:
wxString m_name;
wxString m_extension;
wxBitmapType m_type;
};
#endif // _WX_MSW_GDIIMAGE_H_
|