]> git.saurik.com Git - wxWidgets.git/blame - include/wx/palmos/gdiimage.h
Fix up NSSlider code to not use class posing and instantiate the proper type (now...
[wxWidgets.git] / include / wx / palmos / gdiimage.h
CommitLineData
ffecfa5a 1///////////////////////////////////////////////////////////////////////////////
e1d63b79 2// Name: wx/palmos/gdiimage.h
ffecfa5a
JS
3// Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
4// under Palm OS
e1d63b79 5// Author: William Osborne - minimal working wxPalmOS port
ffecfa5a
JS
6// Modified by:
7// Created: 10/13/04
e1d63b79 8// RCS-ID: $Id$
ffecfa5a
JS
9// Copyright: (c) William Osborne
10// Licence: wxWindows licence
11///////////////////////////////////////////////////////////////////////////////
12
13// NB: this is a private header, it is not intended to be directly included by
14// user code (but may be included from other, public, wxWin headers
15
16#ifndef _WX_PALMOS_GDIIMAGE_H_
17#define _WX_PALMOS_GDIIMAGE_H_
18
ffecfa5a
JS
19#include "wx/gdiobj.h" // base class
20#include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
21#include "wx/list.h"
22
b5dbe15d
VS
23class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData;
24class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler;
25class WXDLLIMPEXP_FWD_CORE wxGDIImage;
ffecfa5a
JS
26
27WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
28
29// ----------------------------------------------------------------------------
30// wxGDIImageRefData: common data fields for all derived classes
31// ----------------------------------------------------------------------------
32
33class WXDLLEXPORT wxGDIImageRefData : public wxGDIRefData
34{
35public:
36 wxGDIImageRefData()
37 {
38 m_width = m_height = m_depth = 0;
39
40 m_handle = 0;
41 }
42
43 // accessors
44 bool IsOk() const { return m_handle != 0; }
45
46 void SetSize(int w, int h) { m_width = w; m_height = h; }
47
48 // free the ressources we allocated
49 virtual void Free() = 0;
50
51 // for compatibility, the member fields are public
52
53 // the size of the image
54 int m_width, m_height;
55
56 // the depth of the image
57 int m_depth;
58
59 // the handle to it
60 union
61 {
62 WXHANDLE m_handle; // for untyped access
63 WXHBITMAP m_hBitmap;
64 WXHICON m_hIcon;
65 WXHCURSOR m_hCursor;
66 };
67};
68
69// ----------------------------------------------------------------------------
70// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
71// ----------------------------------------------------------------------------
72
73class WXDLLEXPORT wxGDIImageHandler : public wxObject
74{
75public:
76 // ctor
77 wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; }
78 wxGDIImageHandler(const wxString& name,
79 const wxString& ext,
80 long type)
81 : m_name(name), m_extension(ext)
82 {
83 m_type = type;
84 }
85
86 // accessors
87 void SetName(const wxString& name) { m_name = name; }
88 void SetExtension(const wxString& ext) { m_extension = ext; }
89 void SetType(long type) { m_type = type; }
90
91 wxString GetName() const { return m_name; }
92 wxString GetExtension() const { return m_extension; }
93 long GetType() const { return m_type; }
94
95 // real handler operations: to implement in derived classes
96 virtual bool Create(wxGDIImage *image,
452418c4 97 const void* data,
ffecfa5a
JS
98 long flags,
99 int width, int height, int depth = 1) = 0;
100 virtual bool Load(wxGDIImage *image,
101 const wxString& name,
102 long flags,
103 int desiredWidth, int desiredHeight) = 0;
104 virtual bool Save(wxGDIImage *image,
105 const wxString& name,
106 int type) = 0;
107
108protected:
109 wxString m_name;
110 wxString m_extension;
111 long m_type;
112};
113
114// ----------------------------------------------------------------------------
115// wxGDIImage: this class supports GDI image handlers which may be registered
116// dynamically and will be used for loading/saving the images in the specified
117// format. It also falls back to wxImage if no appropriate image is found.
118// ----------------------------------------------------------------------------
119
120class WXDLLEXPORT wxGDIImage : public wxGDIObject
121{
122public:
123 // handlers list interface
124 static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
125
126 static void AddHandler(wxGDIImageHandler *handler);
127 static void InsertHandler(wxGDIImageHandler *handler);
128 static bool RemoveHandler(const wxString& name);
129
130 static wxGDIImageHandler *FindHandler(const wxString& name);
131 static wxGDIImageHandler *FindHandler(const wxString& extension, long type);
132 static wxGDIImageHandler *FindHandler(long type);
133
134 static void InitStandardHandlers();
135 static void CleanUpHandlers();
136
137 // access to the ref data casted to the right type
138 wxGDIImageRefData *GetGDIImageData() const
139 { return (wxGDIImageRefData *)m_refData; }
140
141 // create data if we don't have it yet
142 void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); }
143
144 // accessors
145 WXHANDLE GetHandle() const
146 { return IsNull() ? 0 : GetGDIImageData()->m_handle; }
147 void SetHandle(WXHANDLE handle)
148 { EnsureHasData(); GetGDIImageData()->m_handle = handle; }
149
b7cacb43
VZ
150 bool Ok() const { return IsOk(); }
151 bool IsOk() const { return GetHandle() != 0; }
ffecfa5a
JS
152
153 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; }
154 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
155 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
156
157 void SetWidth(int w) { EnsureHasData(); GetGDIImageData()->m_width = w; }
158 void SetHeight(int h) { EnsureHasData(); GetGDIImageData()->m_height = h; }
159 void SetDepth(int d) { EnsureHasData(); GetGDIImageData()->m_depth = d; }
160
161 void SetSize(int w, int h)
162 {
163 EnsureHasData();
164 GetGDIImageData()->SetSize(w, h);
165 }
166 void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
167
168 // forward some of base class virtuals to wxGDIImageRefData
169 bool FreeResource(bool force = FALSE);
170 virtual WXHANDLE GetResourceHandle() const;
171
172protected:
173 // create the data for the derived class here
174 virtual wxGDIImageRefData *CreateData() const = 0;
175
176 static wxGDIImageHandlerList ms_handlers;
177};
178
179#endif // _WX_PALMOS_GDIIMAGE_H_