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