]> git.saurik.com Git - wxWidgets.git/blame - src/os2/statbmp.cpp
corrected scrolling problems for controls, switched to separate wxSpinCtrl implementa...
[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
19#include "wx/window.h"
20#include "wx/os2/private.h"
21
22#ifndef WX_PRECOMP
23 #include "wx/icon.h"
24 #include "wx/statbmp.h"
0e320a79
DW
25#endif
26
409c9842
DW
27#include <stdio.h>
28
29// ---------------------------------------------------------------------------
30// macors
31// ---------------------------------------------------------------------------
0e320a79 32
0e320a79 33IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
0e320a79 34
70a2c656
DW
35static wxGDIImage* ConvertImage(
36 const wxGDIImage& rBitmap
37)
38{
39 bool bIsIcon = rBitmap.IsKindOf( CLASSINFO(wxIcon) );
40
41 if(!bIsIcon )
42 {
43 wxASSERT_MSG( wxDynamicCast(&rBitmap, wxBitmap),
44 _T("not an icon and not a bitmap?") );
45
46 const wxBitmap& rBmp = (const wxBitmap&)rBitmap;
47 wxMask* pMask = rBmp.GetMask();
48
49 if (pMask && pMask->GetMaskBitmap())
50 {
51 wxIcon* pIcon = new wxIcon;
52
53 pIcon->CopyFromBitmap(rBmp);
54 return pIcon;
55 }
56 return new wxBitmap(rBmp);
57 }
58
59 // copying a bitmap is a cheap operation
60 return new wxIcon( (const wxIcon&)rBitmap );
61} // end of ConvertImage
62
409c9842
DW
63// ---------------------------------------------------------------------------
64// wxStaticBitmap
65// ---------------------------------------------------------------------------
0e320a79 66
3b9e3455
DW
67bool wxStaticBitmap::Create(
68 wxWindow* pParent
69, wxWindowID nId
70, const wxGDIImage& rBitmap
71, const wxPoint& rPos
72, const wxSize& rSize
73, long lStyle
74, const wxString& rName
75)
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;
95 int nWidth = rSize.x;
96 int nHeight = rSize.y;
70a2c656 97 char zId[16];
04701dd9 98
3b9e3455 99 m_windowStyle = lStyle;
04701dd9 100
3b9e3455 101 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
04701dd9 102
70a2c656
DW
103 //
104 // For now we only support an ICON
105 //
106 int nWinstyle = SS_ICON;
3b9e3455 107
70a2c656 108 sprintf(zId, "#%d", rBitmap.GetId());
43543d98 109 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
d697657f 110 ,WC_STATIC
70a2c656 111 ,zId
3b9e3455
DW
112 ,nWinstyle | WS_VISIBLE
113 ,0,0,0,0
114 ,pParent->GetHWND()
115 ,HWND_TOP
116 ,m_windowId
117 ,NULL
118 ,NULL
119 );
70a2c656
DW
120 if (!m_hWnd)
121 {
122 vError = ::WinGetLastError(wxGetInstance());
123 sError = wxPMErrorToStr(vError);
124 return FALSE;
125 }
04701dd9 126 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
70a2c656
DW
127 m_pImage = ConvertImage(rBitmap);
128 m_pImage->SetHandle((WXHWND)::WinSendMsg(m_hWnd, SM_QUERYHANDLE, (MPARAM)0, (MPARAM)0));
04701dd9
DW
129
130 // Subclass again for purposes of dialog editing mode
131 SubclassWin(m_hWnd);
70a2c656
DW
132 return(TRUE);
133} // end of wxStaticBitmap::Create
0e320a79 134
409c9842 135bool wxStaticBitmap::ImageIsOk() const
0e320a79 136{
43543d98 137 return(m_pImage && m_pImage->Ok());
409c9842
DW
138}
139
140void wxStaticBitmap::Free()
141{
70a2c656
DW
142 if (m_pImage)
143 delete m_pImage;
3b9e3455 144 m_pImage = NULL;
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
3b9e3455
DW
156void wxStaticBitmap::SetImage(
157 const wxGDIImage& rBitmap
158)
0e320a79 159{
70a2c656
DW
160 int nX = 0;
161 int nY = 0;
162 int nWidth = 0;
163 int nHeight = 0;
3b9e3455 164
70a2c656 165 Free();
3b9e3455
DW
166 ::WinSendMsg( GetHwnd()
167 ,SM_SETHANDLE
70a2c656 168 ,MPFROMHWND(rBitmap.GetHandle())
3b9e3455
DW
169 ,NULL
170 );
70a2c656 171 m_pImage = ConvertImage(rBitmap);
3b9e3455 172
70a2c656
DW
173 GetPosition(&nX, &nY);
174 GetSize(&nWidth, &nHeight);
3b9e3455
DW
175
176 RECTL vRect;
177
70a2c656 178 vRect.xLeft = nX;
3b9e3455 179 vRect.yTop = nY;
70a2c656
DW
180 vRect.xRight = nX + nWidth;
181 vRect.yBottom = nY + nHeight;
3b9e3455
DW
182
183 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
0e320a79
DW
184}
185
32334453
DW
186MRESULT wxStaticBitmap::OS2WindowProc(
187 WXUINT uMsg
188, WXWPARAM wParam
189, WXLPARAM lParam
190)
191{
192 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
193} // end of wxStaticBitmap::OS2WindowProc