]> git.saurik.com Git - wxWidgets.git/blob - src/os2/icon.cpp
Finished up utilities testing
[wxWidgets.git] / src / os2 / icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: icon.cpp
3 // Purpose: wxIcon class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/09/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include "wx/setup.h"
22 #include "wx/list.h"
23 #include "wx/utils.h"
24 #include "wx/app.h"
25 #include "wx/icon.h"
26 #endif
27
28 #include "wx/os2/private.h"
29 #include "assert.h"
30
31 #include "wx/icon.h"
32
33 #if !USE_SHARED_LIBRARIES
34 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
35 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxBitmapHandler)
36 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxBitmapHandler)
37 #endif
38
39 /*
40 * Icons
41 */
42
43 wxIconRefData::wxIconRefData()
44 {
45 m_hIcon = (WXHICON) NULL ;
46 }
47
48 wxIconRefData::~wxIconRefData()
49 {
50 if ( m_hIcon )
51 return;
52 // TODO ::DestroyIcon((HICON) m_hIcon);
53 }
54
55 wxIcon::wxIcon()
56 {
57 }
58
59 wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height))
60 {
61 }
62
63 wxIcon::wxIcon(const wxString& icon_file, long flags,
64 int desiredWidth, int desiredHeight)
65
66 {
67 LoadFile(icon_file, flags, desiredWidth, desiredHeight);
68 }
69
70 wxIcon::~wxIcon()
71 {
72 }
73
74 bool wxIcon::LoadFile(const wxString& filename, long type,
75 int desiredWidth, int desiredHeight)
76 {
77 UnRef();
78
79 m_refData = new wxIconRefData;
80
81 wxBitmapHandler *handler = FindHandler(type);
82
83 if ( handler )
84 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
85 else
86 return FALSE;
87 }
88
89 void wxIcon::SetHICON(WXHICON ico)
90 {
91 if ( !M_ICONDATA )
92 m_refData = new wxIconRefData;
93
94 M_ICONDATA->m_hIcon = ico;
95 }
96
97 bool wxICOFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
98 int desiredWidth, int desiredHeight)
99 {
100 return FALSE;
101 }
102
103 bool wxICOResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
104 int desiredWidth, int desiredHeight)
105 {
106 // TODO
107 /*
108 if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) )
109 {
110 if (desiredWidth > -1 && desiredHeight > -1)
111 {
112 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadImage(wxGetInstance(), name, IMAGE_ICON, desiredWidth, desiredHeight, LR_DEFAULTCOLOR);
113 }
114 else
115 {
116 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadIcon(wxGetInstance(), name);
117 }
118
119 ICONINFO info ;
120 if (::GetIconInfo((HICON) M_ICONHANDLERDATA->m_hIcon, &info))
121 {
122 HBITMAP ms_bitmap = info.hbmMask ;
123 if (ms_bitmap)
124 {
125 BITMAP bm;
126 ::GetObject(ms_bitmap, sizeof(BITMAP), (LPSTR) &bm);
127 M_ICONHANDLERDATA->m_width = bm.bmWidth;
128 M_ICONHANDLERDATA->m_height = bm.bmHeight;
129 }
130 if (info.hbmMask)
131 ::DeleteObject(info.hbmMask) ;
132 if (info.hbmColor)
133 ::DeleteObject(info.hbmColor) ;
134 }
135 }
136 // Override the found values with desired values
137 if (desiredWidth > -1 && desiredHeight > -1)
138 {
139 M_ICONHANDLERDATA->m_width = desiredWidth;
140 M_ICONHANDLERDATA->m_height = desiredHeight;
141 }
142
143 M_ICONHANDLERDATA->m_ok = (M_ICONHANDLERDATA->m_hIcon != 0);
144 return M_ICONHANDLERDATA->m_ok;
145 }
146 else
147 */
148 return FALSE;
149 }
150