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