]> git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
support metal appearance
[wxWidgets.git] / src / os2 / statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: statbmp.cpp
3 // Purpose: wxStaticBitmap
4 // Author: David Webster
5 // Modified by:
6 // Created: 11/27/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "statbmp.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #include "wx/dcclient.h"
20 #include "wx/window.h"
21 #include "wx/os2/private.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/icon.h"
25 #include "wx/statbmp.h"
26 #endif
27
28 #include <stdio.h>
29
30 // ---------------------------------------------------------------------------
31 // macors
32 // ---------------------------------------------------------------------------
33
34 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
35
36 BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow)
37 EVT_PAINT(wxStaticBitmap::OnPaint)
38 END_EVENT_TABLE()
39
40 static wxGDIImage* ConvertImage(
41 const wxGDIImage& rBitmap
42 )
43 {
44 bool bIsIcon = rBitmap.IsKindOf( CLASSINFO(wxIcon) );
45
46 if(!bIsIcon )
47 {
48 wxASSERT_MSG( wxDynamicCast(&rBitmap, wxBitmap),
49 _T("not an icon and not a bitmap?") );
50
51 const wxBitmap& rBmp = (const wxBitmap&)rBitmap;
52 wxMask* pMask = rBmp.GetMask();
53
54 if (pMask && pMask->GetMaskBitmap())
55 {
56 wxIcon* pIcon = new wxIcon;
57
58 pIcon->CopyFromBitmap(rBmp);
59 return pIcon;
60 }
61 return new wxBitmap(rBmp);
62 }
63
64 // copying a bitmap is a cheap operation
65 return new wxIcon( (const wxIcon&)rBitmap );
66 } // end of ConvertImage
67
68 // ---------------------------------------------------------------------------
69 // wxStaticBitmap
70 // ---------------------------------------------------------------------------
71
72 bool wxStaticBitmap::Create(
73 wxWindow* pParent
74 , wxWindowID nId
75 , const wxGDIImage& rBitmap
76 , const wxPoint& rPos
77 , const wxSize& rSize
78 , long lStyle
79 , const wxString& rName
80 )
81 {
82 ERRORID vError;
83 wxString sError;
84
85 Init();
86
87 SetName(rName);
88 if (pParent)
89 pParent->AddChild(this);
90
91 if (nId == -1)
92 m_windowId = (int)NewControlId();
93 else
94 m_windowId = nId;
95
96 m_windowStyle = lStyle;
97
98 int nX= rPos.x;
99 int nY = rPos.y;
100 char zId[16];
101
102 m_windowStyle = lStyle;
103
104 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
105
106 //
107 // For now we only support an ICON
108 //
109 int nWinstyle = SS_ICON;
110
111 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
112 ,wxCanvasClassName
113 ,zId
114 ,nWinstyle | WS_VISIBLE
115 ,0,0,0,0
116 ,pParent->GetHWND()
117 ,HWND_TOP
118 ,m_windowId
119 ,NULL
120 ,NULL
121 );
122 if (!m_hWnd)
123 {
124 vError = ::WinGetLastError(wxGetInstance());
125 sError = wxPMErrorToStr(vError);
126 return FALSE;
127 }
128 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
129 m_pImage = ConvertImage(rBitmap);
130 m_pImage->SetHandle((WXHWND)::WinSendMsg(m_hWnd, SM_QUERYHANDLE, (MPARAM)0, (MPARAM)0));
131
132 // Subclass again for purposes of dialog editing mode
133 SubclassWin(m_hWnd);
134 SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight());
135
136 return(TRUE);
137 } // end of wxStaticBitmap::Create
138
139 bool wxStaticBitmap::ImageIsOk() const
140 {
141 return(m_pImage && m_pImage->Ok());
142 }
143
144 void wxStaticBitmap::Free()
145 {
146 if (m_pImage)
147 delete m_pImage;
148 m_pImage = NULL;
149 } // end of wxStaticBitmap::Free
150
151 wxSize wxStaticBitmap::DoGetBestSize() const
152 {
153 //
154 // Reuse the current size (as wxWindow does) instead of using some
155 // arbitrary default size (as wxControl, our immediate base class, does)
156 //
157 return wxWindow::DoGetBestSize();
158 }
159
160 void wxStaticBitmap::OnPaint (
161 wxPaintEvent& WXUNUSED(rEvent)
162 )
163 {
164 wxPaintDC vDc(this);
165 wxBitmap* pBitmap;
166
167 if (m_pImage->IsKindOf(CLASSINFO(wxIcon)))
168 {
169 wxIcon* pIcon;
170
171 pIcon = wxDynamicCast(m_pImage, wxIcon);
172 pBitmap = new wxBitmap(*pIcon);
173 vDc.DrawBitmap(*pBitmap, 0, 0);
174 delete pBitmap;
175 }
176 else
177 {
178 pBitmap = wxDynamicCast(m_pImage, wxBitmap);
179 vDc.DrawBitmap(*pBitmap, 0, 0);
180 }
181 } // end of wxStaticBitmap::OnPaint
182
183 void wxStaticBitmap::SetImage(
184 const wxGDIImage& rBitmap
185 )
186 {
187 int nX = 0;
188 int nY = 0;
189 int nWidth = 0;
190 int nHeight = 0;
191
192 Free();
193 ::WinSendMsg( GetHwnd()
194 ,SM_SETHANDLE
195 ,MPFROMHWND(rBitmap.GetHandle())
196 ,NULL
197 );
198 m_pImage = ConvertImage(rBitmap);
199
200 GetPosition(&nX, &nY);
201 GetSize(&nWidth, &nHeight);
202
203 RECTL vRect;
204
205 vRect.xLeft = nX;
206 vRect.yTop = nY;
207 vRect.xRight = nX + nWidth;
208 vRect.yBottom = nY + nHeight;
209
210 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
211 }
212
213 MRESULT wxStaticBitmap::OS2WindowProc(
214 WXUINT uMsg
215 , WXWPARAM wParam
216 , WXLPARAM lParam
217 )
218 {
219 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
220 } // end of wxStaticBitmap::OS2WindowProc