]> git.saurik.com Git - wxWidgets.git/blame - src/os2/statbmp.cpp
wxRichTextCtrl native caret now flashes, for wxMac/Core Graphics mode
[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),
46 _T("not an icon and not a bitmap?") );
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{
70a2c656
DW
144 if (m_pImage)
145 delete m_pImage;
3b9e3455 146 m_pImage = NULL;
70a2c656 147} // end of wxStaticBitmap::Free
409c9842 148
e78c4d50 149wxSize wxStaticBitmap::DoGetBestSize() const
409c9842 150{
70a2c656
DW
151 //
152 // Reuse the current size (as wxWindow does) instead of using some
409c9842 153 // arbitrary default size (as wxControl, our immediate base class, does)
70a2c656 154 //
409c9842 155 return wxWindow::DoGetBestSize();
0e320a79
DW
156}
157
cdccdfab 158void wxStaticBitmap::OnPaint ( wxPaintEvent& WXUNUSED(rEvent) )
1de4baa3 159{
cdccdfab
WS
160 wxPaintDC vDc(this);
161 wxBitmap* pBitmap;
1de4baa3
DW
162
163 if (m_pImage->IsKindOf(CLASSINFO(wxIcon)))
164 {
165 wxIcon* pIcon;
166
167 pIcon = wxDynamicCast(m_pImage, wxIcon);
168 pBitmap = new wxBitmap(*pIcon);
169 vDc.DrawBitmap(*pBitmap, 0, 0);
170 delete pBitmap;
171 }
172 else
173 {
174 pBitmap = wxDynamicCast(m_pImage, wxBitmap);
175 vDc.DrawBitmap(*pBitmap, 0, 0);
176 }
177} // end of wxStaticBitmap::OnPaint
178
cdccdfab 179void wxStaticBitmap::SetImage( const wxGDIImage& rBitmap )
0e320a79 180{
cdccdfab
WS
181 int nX = 0;
182 int nY = 0;
183 int nWidth = 0;
184 int nHeight = 0;
3b9e3455 185
70a2c656 186 Free();
3b9e3455
DW
187 ::WinSendMsg( GetHwnd()
188 ,SM_SETHANDLE
70a2c656 189 ,MPFROMHWND(rBitmap.GetHandle())
3b9e3455
DW
190 ,NULL
191 );
70a2c656 192 m_pImage = ConvertImage(rBitmap);
3b9e3455 193
70a2c656
DW
194 GetPosition(&nX, &nY);
195 GetSize(&nWidth, &nHeight);
179db36d
SN
196 // Convert to OS/2 coordinate system
197 nY = wxWindow::GetOS2ParentHeight(GetParent()) - nY - nHeight;
3b9e3455
DW
198
199 RECTL vRect;
200
70a2c656 201 vRect.xLeft = nX;
179db36d 202 vRect.yTop = nY + nHeight;
70a2c656 203 vRect.xRight = nX + nWidth;
179db36d 204 vRect.yBottom = nY;
3b9e3455
DW
205
206 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
0e320a79
DW
207}
208
32334453
DW
209MRESULT wxStaticBitmap::OS2WindowProc(
210 WXUINT uMsg
211, WXWPARAM wParam
212, WXLPARAM lParam
213)
214{
215 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
216} // end of wxStaticBitmap::OS2WindowProc