1999-12-03 17:23:58 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2006-10-23 07:58:28 -04:00
|
|
|
// Name: wx/os2/gdiimage.h
|
1999-12-03 17:23:58 -05:00
|
|
|
// Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
|
|
|
|
// under OS/2
|
|
|
|
// Author: David Webster (adapted from msw version by Vadim Zeitlin)
|
|
|
|
// Modified by:
|
|
|
|
// Created: 20.11.99
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 David Webster
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1999-12-03 17:23:58 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// 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_OS2_GDIIMAGE_H_
|
|
|
|
#define _WX_OS2_GDIIMAGE_H_
|
|
|
|
|
|
|
|
#include "wx/gdiobj.h" // base class
|
|
|
|
#include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
|
|
|
|
#include "wx/list.h"
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxGDIImage;
|
1999-12-03 17:23:58 -05:00
|
|
|
|
2004-02-25 18:03:46 -05:00
|
|
|
WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
|
|
|
|
|
1999-12-03 17:23:58 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxGDIImageRefData: common data fields for all derived classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxGDIImageRefData : public wxGDIRefData
|
1999-12-03 17:23:58 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxGDIImageRefData()
|
|
|
|
{
|
|
|
|
m_nWidth = m_nHeight = m_nDepth = 0;
|
|
|
|
|
|
|
|
m_hHandle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accessors
|
2007-12-15 12:54:20 -05:00
|
|
|
virtual bool IsOk() const
|
2000-03-09 16:06:48 -05:00
|
|
|
{
|
|
|
|
if (m_hHandle == 0)
|
2006-10-23 07:58:28 -04:00
|
|
|
return false;
|
|
|
|
return true;
|
2000-03-09 16:06:48 -05:00
|
|
|
}
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
void SetSize( int nW
|
|
|
|
,int nH
|
|
|
|
)
|
|
|
|
{ m_nWidth = nW; m_nHeight = nH; }
|
|
|
|
|
|
|
|
// free the ressources we allocated
|
2000-03-09 16:06:48 -05:00
|
|
|
virtual void Free() { };
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
// for compatibility, the member fields are public
|
|
|
|
|
|
|
|
// the size of the image
|
|
|
|
int m_nWidth;
|
|
|
|
int m_nHeight;
|
|
|
|
|
|
|
|
// the depth of the image
|
|
|
|
int m_nDepth;
|
|
|
|
|
|
|
|
// the handle to it
|
|
|
|
union
|
|
|
|
{
|
|
|
|
WXHANDLE m_hHandle; // for untyped access
|
|
|
|
WXHBITMAP m_hBitmap;
|
|
|
|
WXHICON m_hIcon;
|
|
|
|
WXHCURSOR m_hCursor;
|
|
|
|
};
|
|
|
|
|
2008-01-12 10:05:15 -05:00
|
|
|
unsigned int m_uId;
|
1999-12-03 17:23:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxGDIImageHandler : public wxObject
|
1999-12-03 17:23:58 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor
|
|
|
|
wxGDIImageHandler() { m_lType = wxBITMAP_TYPE_INVALID; }
|
|
|
|
wxGDIImageHandler( const wxString& rName
|
|
|
|
,const wxString& rExt
|
2008-03-29 15:34:37 -04:00
|
|
|
,wxBitmapType lType
|
1999-12-03 17:23:58 -05:00
|
|
|
)
|
|
|
|
: m_sName(rName)
|
|
|
|
, m_sExtension(rExt)
|
|
|
|
{
|
|
|
|
m_lType = lType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
void SetName(const wxString& rName) { m_sName = rName; }
|
|
|
|
void SetExtension(const wxString& rExt) { m_sExtension = rExt; }
|
2008-03-29 15:34:37 -04:00
|
|
|
void SetType(wxBitmapType lType) { m_lType = lType; }
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
wxString GetName() const { return m_sName; }
|
|
|
|
wxString GetExtension() const { return m_sExtension; }
|
2008-03-29 15:34:37 -04:00
|
|
|
wxBitmapType GetType() const { return m_lType; }
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
// real handler operations: to implement in derived classes
|
|
|
|
virtual bool Create( wxGDIImage* pImage
|
2006-10-09 03:09:20 -04:00
|
|
|
,const void* pData
|
2008-03-29 15:34:37 -04:00
|
|
|
,wxBitmapType lFlags
|
1999-12-03 17:23:58 -05:00
|
|
|
,int nWidth
|
|
|
|
,int nHeight
|
|
|
|
,int nDepth = 1
|
|
|
|
) = 0;
|
|
|
|
virtual bool Load( wxGDIImage* pImage
|
|
|
|
,const wxString& rName
|
1999-12-15 01:02:30 -05:00
|
|
|
,HPS hPs
|
2008-03-29 15:34:37 -04:00
|
|
|
,wxBitmapType lFlags
|
1999-12-03 17:23:58 -05:00
|
|
|
,int nDesiredWidth
|
|
|
|
,int nDesiredHeight
|
|
|
|
) = 0;
|
2002-07-07 23:38:01 -04:00
|
|
|
virtual bool Load( wxGDIImage* pImage
|
|
|
|
,int nId
|
2008-03-29 15:34:37 -04:00
|
|
|
,wxBitmapType lFlags
|
2002-07-07 23:38:01 -04:00
|
|
|
,int nDesiredWidth
|
|
|
|
,int nDesiredHeight
|
|
|
|
) = 0;
|
2008-03-29 15:34:37 -04:00
|
|
|
virtual bool Save( const wxGDIImage* pImage
|
|
|
|
,const wxString& rName
|
|
|
|
,wxBitmapType lType
|
|
|
|
) const = 0;
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
wxString m_sName;
|
|
|
|
wxString m_sExtension;
|
2008-03-29 15:34:37 -04:00
|
|
|
wxBitmapType m_lType;
|
2002-07-07 23:38:01 -04:00
|
|
|
}; // end of wxGDIImageHandler
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxGDIImage : public wxGDIObject
|
1999-12-03 17:23:58 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// handlers list interface
|
2004-02-25 18:03:46 -05:00
|
|
|
static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
static void AddHandler(wxGDIImageHandler* hHandler);
|
|
|
|
static void InsertHandler(wxGDIImageHandler* hHandler);
|
|
|
|
static bool RemoveHandler(const wxString& rName);
|
|
|
|
|
|
|
|
static wxGDIImageHandler* FindHandler(const wxString& rName);
|
2008-03-29 15:34:37 -04:00
|
|
|
static wxGDIImageHandler* FindHandler(const wxString& rExtension, wxBitmapType lType);
|
|
|
|
static wxGDIImageHandler* FindHandler(wxBitmapType lType);
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
static void InitStandardHandlers();
|
|
|
|
static void CleanUpHandlers();
|
|
|
|
|
|
|
|
// access to the ref data casted to the right type
|
|
|
|
wxGDIImageRefData *GetGDIImageData() const
|
|
|
|
{ return (wxGDIImageRefData *)m_refData; }
|
|
|
|
|
|
|
|
// create data if we don't have it yet
|
|
|
|
void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); }
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
WXHANDLE GetHandle() const
|
2000-03-09 16:06:48 -05:00
|
|
|
{
|
|
|
|
wxGDIImageRefData* pData;
|
|
|
|
|
|
|
|
pData = GetGDIImageData();
|
|
|
|
if (!pData)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return pData->m_hHandle;
|
|
|
|
}
|
1999-12-03 17:23:58 -05:00
|
|
|
void SetHandle(WXHANDLE hHandle)
|
2000-03-09 16:06:48 -05:00
|
|
|
{
|
|
|
|
wxGDIImageRefData* pData;
|
|
|
|
|
|
|
|
EnsureHasData();
|
|
|
|
pData = GetGDIImageData();
|
|
|
|
pData->m_hHandle = hHandle;
|
|
|
|
}
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth; }
|
|
|
|
int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight; }
|
|
|
|
int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth; }
|
|
|
|
|
|
|
|
void SetWidth(int nW) { EnsureHasData(); GetGDIImageData()->m_nWidth = nW; }
|
|
|
|
void SetHeight(int nH) { EnsureHasData(); GetGDIImageData()->m_nHeight = nH; }
|
|
|
|
void SetDepth(int nD) { EnsureHasData(); GetGDIImageData()->m_nDepth = nD; }
|
|
|
|
|
|
|
|
void SetSize( int nW
|
|
|
|
,int nH
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EnsureHasData();
|
|
|
|
GetGDIImageData()->SetSize(nW, nH);
|
|
|
|
}
|
|
|
|
void SetSize(const wxSize& rSize) { SetSize(rSize.x, rSize.y); }
|
|
|
|
|
2008-01-12 10:05:15 -05:00
|
|
|
unsigned int GetId(void) const
|
2001-01-29 00:46:06 -05:00
|
|
|
{
|
|
|
|
wxGDIImageRefData* pData;
|
|
|
|
|
|
|
|
pData = GetGDIImageData();
|
|
|
|
if (!pData)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return pData->m_uId;
|
|
|
|
} // end of WxWinGdi_CGDIImage::GetId
|
2008-01-12 10:05:15 -05:00
|
|
|
void SetId(unsigned int uId)
|
2001-01-29 00:46:06 -05:00
|
|
|
{
|
|
|
|
wxGDIImageRefData* pData;
|
|
|
|
|
|
|
|
EnsureHasData();
|
|
|
|
pData = GetGDIImageData();
|
|
|
|
pData->m_uId = uId;
|
|
|
|
}
|
1999-12-03 17:23:58 -05:00
|
|
|
// forward some of base class virtuals to wxGDIImageRefData
|
2006-10-23 07:58:28 -04:00
|
|
|
bool FreeResource(bool bForce = false);
|
|
|
|
virtual WXHANDLE GetResourceHandle() const;
|
1999-12-03 17:23:58 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// create the data for the derived class here
|
|
|
|
virtual wxGDIImageRefData* CreateData() const = 0;
|
2007-12-15 12:54:20 -05:00
|
|
|
virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); }
|
1999-12-03 17:23:58 -05:00
|
|
|
|
2008-01-12 10:05:15 -05:00
|
|
|
// we can't [efficiently] clone objects of this class
|
|
|
|
virtual wxGDIRefData *
|
|
|
|
CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( _T("must be implemented if used") );
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-25 18:03:46 -05:00
|
|
|
static wxGDIImageHandlerList ms_handlers;
|
1999-12-03 17:23:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WX_MSW_GDIIMAGE_H_
|