]> git.saurik.com Git - wxWidgets.git/blame - src/os2/statbmp.cpp
Misc XRC format docs corrections.
[wxWidgets.git] / src / os2 / statbmp.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
cdccdfab 2// Name: src/os2/statbmp.cpp
0e320a79 3// Purpose: wxStaticBitmap
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
3b9e3455 6// Created: 11/27/99
409c9842 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
409c9842
DW
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
cdccdfab 14#include "wx/statbmp.h"
409c9842
DW
15
16#ifndef WX_PRECOMP
17 #include "wx/icon.h"
cdccdfab 18 #include "wx/window.h"
ed4b0fdc 19 #include "wx/dcclient.h"
0e320a79
DW
20#endif
21
cdccdfab
WS
22#include "wx/os2/private.h"
23
409c9842
DW
24#include <stdio.h>
25
26// ---------------------------------------------------------------------------
179db36d 27// macros
409c9842 28// ---------------------------------------------------------------------------
0e320a79 29
1de4baa3
DW
30BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow)
31 EVT_PAINT(wxStaticBitmap::OnPaint)
32END_EVENT_TABLE()
33
70a2c656
DW
34static wxGDIImage* ConvertImage(
35 const wxGDIImage& rBitmap
36)
37{
38 bool bIsIcon = rBitmap.IsKindOf( CLASSINFO(wxIcon) );
39
40 if(!bIsIcon )
41 {
42 wxASSERT_MSG( wxDynamicCast(&rBitmap, wxBitmap),
9a83f860 43 wxT("not an icon and not a bitmap?") );
70a2c656
DW
44
45 const wxBitmap& rBmp = (const wxBitmap&)rBitmap;
46 wxMask* pMask = rBmp.GetMask();
47
48 if (pMask && pMask->GetMaskBitmap())
49 {
50 wxIcon* pIcon = new wxIcon;
51
52 pIcon->CopyFromBitmap(rBmp);
53 return pIcon;
54 }
55 return new wxBitmap(rBmp);
56 }
57
58 // copying a bitmap is a cheap operation
59 return new wxIcon( (const wxIcon&)rBitmap );
60} // end of ConvertImage
61
409c9842
DW
62// ---------------------------------------------------------------------------
63// wxStaticBitmap
64// ---------------------------------------------------------------------------
0e320a79 65
6670f564
WS
66bool wxStaticBitmap::Create( wxWindow* pParent,
67 wxWindowID nId,
68 const wxGDIImage& rBitmap,
69 const wxPoint& rPos,
70 const wxSize& WXUNUSED(rSize),
71 long lStyle,
72 const wxString& rName )
0e320a79 73{
70a2c656
DW
74 ERRORID vError;
75 wxString sError;
76
04701dd9
DW
77 Init();
78
3b9e3455 79 SetName(rName);
43543d98
DW
80 if (pParent)
81 pParent->AddChild(this);
0e320a79 82
43543d98 83 if (nId == -1)
409c9842 84 m_windowId = (int)NewControlId();
0e320a79 85 else
3b9e3455 86 m_windowId = nId;
0e320a79 87
3b9e3455 88 m_windowStyle = lStyle;
0e320a79 89
43543d98
DW
90 int nX= rPos.x;
91 int nY = rPos.y;
70a2c656 92 char zId[16];
04701dd9 93
3b9e3455 94 m_windowStyle = lStyle;
04701dd9 95
3b9e3455 96 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
04701dd9 97
70a2c656
DW
98 //
99 // For now we only support an ICON
100 //
101 int nWinstyle = SS_ICON;
3b9e3455 102
43543d98 103 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
0fba44b4 104 ,(PSZ)wxCanvasClassName
70a2c656 105 ,zId
3b9e3455
DW
106 ,nWinstyle | WS_VISIBLE
107 ,0,0,0,0
108 ,pParent->GetHWND()
109 ,HWND_TOP
110 ,m_windowId
111 ,NULL
112 ,NULL
113 );
70a2c656
DW
114 if (!m_hWnd)
115 {
116 vError = ::WinGetLastError(wxGetInstance());
117 sError = wxPMErrorToStr(vError);
6670f564 118 return false;
70a2c656 119 }
cdccdfab 120 wxCHECK_MSG( m_hWnd, false, wxT("Failed to create static bitmap") );
70a2c656 121 m_pImage = ConvertImage(rBitmap);
179db36d
SN
122 ::WinSendMsg( m_hWnd,
123 SM_SETHANDLE,
124 MPFROMHWND(rBitmap.GetHandle()),
125 (MPARAM)0);
04701dd9
DW
126
127 // Subclass again for purposes of dialog editing mode
128 SubclassWin(m_hWnd);
1de4baa3
DW
129 SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight());
130
6670f564 131 return true;
70a2c656 132} // end of wxStaticBitmap::Create
0e320a79 133
409c9842 134bool wxStaticBitmap::ImageIsOk() const
0e320a79 135{
a1b806b9 136 return(m_pImage && m_pImage->IsOk());
409c9842
DW
137}
138
139void wxStaticBitmap::Free()
140{
5276b0a5 141 wxDELETE(m_pImage);
70a2c656 142} // end of wxStaticBitmap::Free
409c9842 143
e78c4d50 144wxSize wxStaticBitmap::DoGetBestSize() const
409c9842 145{
70a2c656
DW
146 //
147 // Reuse the current size (as wxWindow does) instead of using some
409c9842 148 // arbitrary default size (as wxControl, our immediate base class, does)
70a2c656 149 //
409c9842 150 return wxWindow::DoGetBestSize();
0e320a79
DW
151}
152
cdccdfab 153void wxStaticBitmap::OnPaint ( wxPaintEvent& WXUNUSED(rEvent) )
1de4baa3 154{
cdccdfab
WS
155 wxPaintDC vDc(this);
156 wxBitmap* pBitmap;
1de4baa3
DW
157
158 if (m_pImage->IsKindOf(CLASSINFO(wxIcon)))
159 {
160 wxIcon* pIcon;
161
162 pIcon = wxDynamicCast(m_pImage, wxIcon);
163 pBitmap = new wxBitmap(*pIcon);
164 vDc.DrawBitmap(*pBitmap, 0, 0);
165 delete pBitmap;
166 }
167 else
168 {
169 pBitmap = wxDynamicCast(m_pImage, wxBitmap);
170 vDc.DrawBitmap(*pBitmap, 0, 0);
171 }
172} // end of wxStaticBitmap::OnPaint
173
cdccdfab 174void wxStaticBitmap::SetImage( const wxGDIImage& rBitmap )
0e320a79 175{
cdccdfab
WS
176 int nX = 0;
177 int nY = 0;
178 int nWidth = 0;
179 int nHeight = 0;
3b9e3455 180
70a2c656 181 Free();
3b9e3455
DW
182 ::WinSendMsg( GetHwnd()
183 ,SM_SETHANDLE
70a2c656 184 ,MPFROMHWND(rBitmap.GetHandle())
3b9e3455
DW
185 ,NULL
186 );
70a2c656 187 m_pImage = ConvertImage(rBitmap);
3b9e3455 188
70a2c656
DW
189 GetPosition(&nX, &nY);
190 GetSize(&nWidth, &nHeight);
179db36d
SN
191 // Convert to OS/2 coordinate system
192 nY = wxWindow::GetOS2ParentHeight(GetParent()) - nY - nHeight;
3b9e3455
DW
193
194 RECTL vRect;
195
70a2c656 196 vRect.xLeft = nX;
179db36d 197 vRect.yTop = nY + nHeight;
70a2c656 198 vRect.xRight = nX + nWidth;
179db36d 199 vRect.yBottom = nY;
3b9e3455
DW
200
201 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
0e320a79
DW
202}
203
32334453
DW
204MRESULT wxStaticBitmap::OS2WindowProc(
205 WXUINT uMsg
206, WXWPARAM wParam
207, WXLPARAM lParam
208)
209{
210 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
211} // end of wxStaticBitmap::OS2WindowProc