]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/statbmp.cpp
wxMBConv test cases, patch 1179989 from Vince Harron
[wxWidgets.git] / src / os2 / statbmp.cpp
... / ...
CommitLineData
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
34IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
35
36BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow)
37 EVT_PAINT(wxStaticBitmap::OnPaint)
38END_EVENT_TABLE()
39
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
68// ---------------------------------------------------------------------------
69// wxStaticBitmap
70// ---------------------------------------------------------------------------
71
72bool wxStaticBitmap::Create( wxWindow* pParent,
73 wxWindowID nId,
74 const wxGDIImage& rBitmap,
75 const wxPoint& rPos,
76 const wxSize& WXUNUSED(rSize),
77 long lStyle,
78 const wxString& rName )
79{
80 ERRORID vError;
81 wxString sError;
82
83 Init();
84
85 SetName(rName);
86 if (pParent)
87 pParent->AddChild(this);
88
89 if (nId == -1)
90 m_windowId = (int)NewControlId();
91 else
92 m_windowId = nId;
93
94 m_windowStyle = lStyle;
95
96 int nX= rPos.x;
97 int nY = rPos.y;
98 char zId[16];
99
100 m_windowStyle = lStyle;
101
102 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
103
104 //
105 // For now we only support an ICON
106 //
107 int nWinstyle = SS_ICON;
108
109 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
110 ,(PSZ)wxCanvasClassName
111 ,zId
112 ,nWinstyle | WS_VISIBLE
113 ,0,0,0,0
114 ,pParent->GetHWND()
115 ,HWND_TOP
116 ,m_windowId
117 ,NULL
118 ,NULL
119 );
120 if (!m_hWnd)
121 {
122 vError = ::WinGetLastError(wxGetInstance());
123 sError = wxPMErrorToStr(vError);
124 return false;
125 }
126 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
127 m_pImage = ConvertImage(rBitmap);
128 m_pImage->SetHandle((WXHWND)::WinSendMsg(m_hWnd, SM_QUERYHANDLE, (MPARAM)0, (MPARAM)0));
129
130 // Subclass again for purposes of dialog editing mode
131 SubclassWin(m_hWnd);
132 SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight());
133
134 return true;
135} // end of wxStaticBitmap::Create
136
137bool wxStaticBitmap::ImageIsOk() const
138{
139 return(m_pImage && m_pImage->Ok());
140}
141
142void wxStaticBitmap::Free()
143{
144 if (m_pImage)
145 delete m_pImage;
146 m_pImage = NULL;
147} // end of wxStaticBitmap::Free
148
149wxSize wxStaticBitmap::DoGetBestSize() const
150{
151 //
152 // Reuse the current size (as wxWindow does) instead of using some
153 // arbitrary default size (as wxControl, our immediate base class, does)
154 //
155 return wxWindow::DoGetBestSize();
156}
157
158void wxStaticBitmap::OnPaint (
159 wxPaintEvent& WXUNUSED(rEvent)
160)
161{
162 wxPaintDC vDc(this);
163 wxBitmap* pBitmap;
164
165 if (m_pImage->IsKindOf(CLASSINFO(wxIcon)))
166 {
167 wxIcon* pIcon;
168
169 pIcon = wxDynamicCast(m_pImage, wxIcon);
170 pBitmap = new wxBitmap(*pIcon);
171 vDc.DrawBitmap(*pBitmap, 0, 0);
172 delete pBitmap;
173 }
174 else
175 {
176 pBitmap = wxDynamicCast(m_pImage, wxBitmap);
177 vDc.DrawBitmap(*pBitmap, 0, 0);
178 }
179} // end of wxStaticBitmap::OnPaint
180
181void wxStaticBitmap::SetImage(
182 const wxGDIImage& rBitmap
183)
184{
185 int nX = 0;
186 int nY = 0;
187 int nWidth = 0;
188 int nHeight = 0;
189
190 Free();
191 ::WinSendMsg( GetHwnd()
192 ,SM_SETHANDLE
193 ,MPFROMHWND(rBitmap.GetHandle())
194 ,NULL
195 );
196 m_pImage = ConvertImage(rBitmap);
197
198 GetPosition(&nX, &nY);
199 GetSize(&nWidth, &nHeight);
200
201 RECTL vRect;
202
203 vRect.xLeft = nX;
204 vRect.yTop = nY;
205 vRect.xRight = nX + nWidth;
206 vRect.yBottom = nY + nHeight;
207
208 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
209}
210
211MRESULT wxStaticBitmap::OS2WindowProc(
212 WXUINT uMsg
213, WXWPARAM wParam
214, WXLPARAM lParam
215)
216{
217 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
218} // end of wxStaticBitmap::OS2WindowProc