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