]> git.saurik.com Git - wxWidgets.git/blame - src/os2/statbmp.cpp
Fix the off-by-one a little differently, and correct a refresh problem
[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
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;
100 int nWidth = rSize.x;
101 int nHeight = rSize.y;
70a2c656 102 char zId[16];
04701dd9 103
3b9e3455 104 m_windowStyle = lStyle;
04701dd9 105
3b9e3455 106 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
04701dd9 107
70a2c656
DW
108 //
109 // For now we only support an ICON
110 //
111 int nWinstyle = SS_ICON;
3b9e3455 112
43543d98 113 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
1de4baa3 114 ,wxCanvasClassName
70a2c656 115 ,zId
3b9e3455
DW
116 ,nWinstyle | WS_VISIBLE
117 ,0,0,0,0
118 ,pParent->GetHWND()
119 ,HWND_TOP
120 ,m_windowId
121 ,NULL
122 ,NULL
123 );
70a2c656
DW
124 if (!m_hWnd)
125 {
126 vError = ::WinGetLastError(wxGetInstance());
127 sError = wxPMErrorToStr(vError);
128 return FALSE;
129 }
04701dd9 130 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
70a2c656
DW
131 m_pImage = ConvertImage(rBitmap);
132 m_pImage->SetHandle((WXHWND)::WinSendMsg(m_hWnd, SM_QUERYHANDLE, (MPARAM)0, (MPARAM)0));
04701dd9
DW
133
134 // Subclass again for purposes of dialog editing mode
135 SubclassWin(m_hWnd);
1de4baa3
DW
136 SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight());
137
70a2c656
DW
138 return(TRUE);
139} // end of wxStaticBitmap::Create
0e320a79 140
409c9842 141bool wxStaticBitmap::ImageIsOk() const
0e320a79 142{
43543d98 143 return(m_pImage && m_pImage->Ok());
409c9842
DW
144}
145
146void wxStaticBitmap::Free()
147{
70a2c656
DW
148 if (m_pImage)
149 delete m_pImage;
3b9e3455 150 m_pImage = NULL;
70a2c656 151} // end of wxStaticBitmap::Free
409c9842 152
e78c4d50 153wxSize wxStaticBitmap::DoGetBestSize() const
409c9842 154{
70a2c656
DW
155 //
156 // Reuse the current size (as wxWindow does) instead of using some
409c9842 157 // arbitrary default size (as wxControl, our immediate base class, does)
70a2c656 158 //
409c9842 159 return wxWindow::DoGetBestSize();
0e320a79
DW
160}
161
1de4baa3
DW
162void wxStaticBitmap::OnPaint (
163 wxPaintEvent& WXUNUSED(rEvent)
164)
165{
166 wxPaintDC vDc(this);
167 int i;
168 wxBitmap* pBitmap;
169
170 if (m_pImage->IsKindOf(CLASSINFO(wxIcon)))
171 {
172 wxIcon* pIcon;
173
174 pIcon = wxDynamicCast(m_pImage, wxIcon);
175 pBitmap = new wxBitmap(*pIcon);
176 vDc.DrawBitmap(*pBitmap, 0, 0);
177 delete pBitmap;
178 }
179 else
180 {
181 pBitmap = wxDynamicCast(m_pImage, wxBitmap);
182 vDc.DrawBitmap(*pBitmap, 0, 0);
183 }
184} // end of wxStaticBitmap::OnPaint
185
3b9e3455
DW
186void wxStaticBitmap::SetImage(
187 const wxGDIImage& rBitmap
188)
0e320a79 189{
70a2c656
DW
190 int nX = 0;
191 int nY = 0;
192 int nWidth = 0;
193 int nHeight = 0;
3b9e3455 194
70a2c656 195 Free();
3b9e3455
DW
196 ::WinSendMsg( GetHwnd()
197 ,SM_SETHANDLE
70a2c656 198 ,MPFROMHWND(rBitmap.GetHandle())
3b9e3455
DW
199 ,NULL
200 );
70a2c656 201 m_pImage = ConvertImage(rBitmap);
3b9e3455 202
70a2c656
DW
203 GetPosition(&nX, &nY);
204 GetSize(&nWidth, &nHeight);
3b9e3455
DW
205
206 RECTL vRect;
207
70a2c656 208 vRect.xLeft = nX;
3b9e3455 209 vRect.yTop = nY;
70a2c656
DW
210 vRect.xRight = nX + nWidth;
211 vRect.yBottom = nY + nHeight;
3b9e3455
DW
212
213 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
0e320a79
DW
214}
215
32334453
DW
216MRESULT wxStaticBitmap::OS2WindowProc(
217 WXUINT uMsg
218, WXWPARAM wParam
219, WXLPARAM lParam
220)
221{
222 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
223} // end of wxStaticBitmap::OS2WindowProc