]> git.saurik.com Git - wxWidgets.git/blame - include/wx/palmos/gdiimage.h
process one event at once in wxEvtHandler::ProcessPendingEvents() to prevent crashes...
[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
8f884a0d 44 virtual bool IsOk() const { return m_handle != 0; }
ffecfa5a
JS
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
ffecfa5a
JS
150 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; }
151 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
152 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
153
154 void SetWidth(int w) { EnsureHasData(); GetGDIImageData()->m_width = w; }
155 void SetHeight(int h) { EnsureHasData(); GetGDIImageData()->m_height = h; }
156 void SetDepth(int d) { EnsureHasData(); GetGDIImageData()->m_depth = d; }
157
158 void SetSize(int w, int h)
159 {
160 EnsureHasData();
161 GetGDIImageData()->SetSize(w, h);
162 }
163 void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
164
165 // forward some of base class virtuals to wxGDIImageRefData
166 bool FreeResource(bool force = FALSE);
167 virtual WXHANDLE GetResourceHandle() const;
168
169protected:
170 // create the data for the derived class here
171 virtual wxGDIImageRefData *CreateData() const = 0;
8f884a0d 172 virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); }
ffecfa5a
JS
173
174 static wxGDIImageHandlerList ms_handlers;
175};
176
177#endif // _WX_PALMOS_GDIIMAGE_H_