]> git.saurik.com Git - wxWidgets.git/blame - src/os2/statbmp.cpp
Fix for the fact that unmapped but managed widgets
[wxWidgets.git] / src / os2 / statbmp.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: statbmp.cpp
3// Purpose: wxStaticBitmap
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
3b9e3455 6// Created: 11/27/99
0e320a79 7// RCS-ID: $Id$
409c9842
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
aa213887
SN
12#ifdef __GNUG__
13#pragma implementation "statbmp.h"
14#endif
15
409c9842
DW
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"
0e320a79
DW
25#endif
26
409c9842
DW
27#include <stdio.h>
28
29// ---------------------------------------------------------------------------
30// macors
31// ---------------------------------------------------------------------------
0e320a79 32
0e320a79 33IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
0e320a79 34
1de4baa3
DW
35BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow)
36 EVT_PAINT(wxStaticBitmap::OnPaint)
37END_EVENT_TABLE()
38
70a2c656
DW
39static 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
409c9842
DW
67// ---------------------------------------------------------------------------
68// wxStaticBitmap
69// ---------------------------------------------------------------------------
0e320a79 70
3b9e3455
DW
71bool 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)
0e320a79 80{
70a2c656
DW
81 ERRORID vError;
82 wxString sError;
83
04701dd9
DW
84 Init();
85
3b9e3455 86 SetName(rName);
43543d98
DW
87 if (pParent)
88 pParent->AddChild(this);
0e320a79 89
43543d98 90 if (nId == -1)
409c9842 91 m_windowId = (int)NewControlId();
0e320a79 92 else
3b9e3455 93 m_windowId = nId;
0e320a79 94
3b9e3455 95 m_windowStyle = lStyle;
0e320a79 96
43543d98
DW
97 int nX= rPos.x;
98 int nY = rPos.y;
99 int nWidth = rSize.x;
100 int nHeight = rSize.y;
70a2c656 101 char zId[16];
04701dd9 102
3b9e3455 103 m_windowStyle = lStyle;
04701dd9 104
3b9e3455 105 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
04701dd9 106
70a2c656
DW
107 //
108 // For now we only support an ICON
109 //
110 int nWinstyle = SS_ICON;
3b9e3455 111
43543d98 112 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
1de4baa3 113 ,wxCanvasClassName
70a2c656 114 ,zId
3b9e3455
DW
115 ,nWinstyle | WS_VISIBLE
116 ,0,0,0,0
117 ,pParent->GetHWND()
118 ,HWND_TOP
119 ,m_windowId
120 ,NULL
121 ,NULL
122 );
70a2c656
DW
123 if (!m_hWnd)
124 {
125 vError = ::WinGetLastError(wxGetInstance());
126 sError = wxPMErrorToStr(vError);
127 return FALSE;
128 }
04701dd9 129 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
70a2c656
DW
130 m_pImage = ConvertImage(rBitmap);
131 m_pImage->SetHandle((WXHWND)::WinSendMsg(m_hWnd, SM_QUERYHANDLE, (MPARAM)0, (MPARAM)0));
04701dd9
DW
132
133 // Subclass again for purposes of dialog editing mode
134 SubclassWin(m_hWnd);
1de4baa3
DW
135 SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight());
136
70a2c656
DW
137 return(TRUE);
138} // end of wxStaticBitmap::Create
0e320a79 139
409c9842 140bool wxStaticBitmap::ImageIsOk() const
0e320a79 141{
43543d98 142 return(m_pImage && m_pImage->Ok());
409c9842
DW
143}
144
145void wxStaticBitmap::Free()
146{
70a2c656
DW
147 if (m_pImage)
148 delete m_pImage;
3b9e3455 149 m_pImage = NULL;
70a2c656 150} // end of wxStaticBitmap::Free
409c9842 151
e78c4d50 152wxSize wxStaticBitmap::DoGetBestSize() const
409c9842 153{
70a2c656
DW
154 //
155 // Reuse the current size (as wxWindow does) instead of using some
409c9842 156 // arbitrary default size (as wxControl, our immediate base class, does)
70a2c656 157 //
409c9842 158 return wxWindow::DoGetBestSize();
0e320a79
DW
159}
160
1de4baa3
DW
161void 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
3b9e3455
DW
185void wxStaticBitmap::SetImage(
186 const wxGDIImage& rBitmap
187)
0e320a79 188{
70a2c656
DW
189 int nX = 0;
190 int nY = 0;
191 int nWidth = 0;
192 int nHeight = 0;
3b9e3455 193
70a2c656 194 Free();
3b9e3455
DW
195 ::WinSendMsg( GetHwnd()
196 ,SM_SETHANDLE
70a2c656 197 ,MPFROMHWND(rBitmap.GetHandle())
3b9e3455
DW
198 ,NULL
199 );
70a2c656 200 m_pImage = ConvertImage(rBitmap);
3b9e3455 201
70a2c656
DW
202 GetPosition(&nX, &nY);
203 GetSize(&nWidth, &nHeight);
3b9e3455
DW
204
205 RECTL vRect;
206
70a2c656 207 vRect.xLeft = nX;
3b9e3455 208 vRect.yTop = nY;
70a2c656
DW
209 vRect.xRight = nX + nWidth;
210 vRect.yBottom = nY + nHeight;
3b9e3455
DW
211
212 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
0e320a79
DW
213}
214
32334453
DW
215MRESULT 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