]> git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
Don't document wxSortedArrayString as deriving from wxArrayString.
[wxWidgets.git] / src / os2 / statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/statbmp.cpp
3 // Purpose: wxStaticBitmap
4 // Author: David Webster
5 // Modified by:
6 // Created: 11/27/99
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #include "wx/statbmp.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/icon.h"
18 #include "wx/window.h"
19 #include "wx/dcclient.h"
20 #endif
21
22 #include "wx/os2/private.h"
23
24 #include <stdio.h>
25
26 // ---------------------------------------------------------------------------
27 // macros
28 // ---------------------------------------------------------------------------
29
30 BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow)
31 EVT_PAINT(wxStaticBitmap::OnPaint)
32 END_EVENT_TABLE()
33
34 static 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),
43 wxT("not an icon and not a bitmap?") );
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
62 // ---------------------------------------------------------------------------
63 // wxStaticBitmap
64 // ---------------------------------------------------------------------------
65
66 bool 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 )
73 {
74 ERRORID vError;
75 wxString sError;
76
77 Init();
78
79 SetName(rName);
80 if (pParent)
81 pParent->AddChild(this);
82
83 if (nId == -1)
84 m_windowId = (int)NewControlId();
85 else
86 m_windowId = nId;
87
88 m_windowStyle = lStyle;
89
90 int nX= rPos.x;
91 int nY = rPos.y;
92 char zId[16];
93
94 m_windowStyle = lStyle;
95
96 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
97
98 //
99 // For now we only support an ICON
100 //
101 int nWinstyle = SS_ICON;
102
103 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
104 ,(PSZ)wxCanvasClassName
105 ,zId
106 ,nWinstyle | WS_VISIBLE
107 ,0,0,0,0
108 ,pParent->GetHWND()
109 ,HWND_TOP
110 ,m_windowId
111 ,NULL
112 ,NULL
113 );
114 if (!m_hWnd)
115 {
116 vError = ::WinGetLastError(wxGetInstance());
117 sError = wxPMErrorToStr(vError);
118 return false;
119 }
120 wxCHECK_MSG( m_hWnd, false, wxT("Failed to create static bitmap") );
121 m_pImage = ConvertImage(rBitmap);
122 ::WinSendMsg( m_hWnd,
123 SM_SETHANDLE,
124 MPFROMHWND(rBitmap.GetHandle()),
125 (MPARAM)0);
126
127 // Subclass again for purposes of dialog editing mode
128 SubclassWin(m_hWnd);
129 SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight());
130
131 return true;
132 } // end of wxStaticBitmap::Create
133
134 bool wxStaticBitmap::ImageIsOk() const
135 {
136 return(m_pImage && m_pImage->IsOk());
137 }
138
139 void wxStaticBitmap::Free()
140 {
141 wxDELETE(m_pImage);
142 } // end of wxStaticBitmap::Free
143
144 wxSize wxStaticBitmap::DoGetBestSize() const
145 {
146 //
147 // Reuse the current size (as wxWindow does) instead of using some
148 // arbitrary default size (as wxControl, our immediate base class, does)
149 //
150 return wxWindow::DoGetBestSize();
151 }
152
153 void wxStaticBitmap::OnPaint ( wxPaintEvent& WXUNUSED(rEvent) )
154 {
155 wxPaintDC vDc(this);
156 wxBitmap* pBitmap;
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
174 void wxStaticBitmap::SetImage( const wxGDIImage& rBitmap )
175 {
176 int nX = 0;
177 int nY = 0;
178 int nWidth = 0;
179 int nHeight = 0;
180
181 Free();
182 ::WinSendMsg( GetHwnd()
183 ,SM_SETHANDLE
184 ,MPFROMHWND(rBitmap.GetHandle())
185 ,NULL
186 );
187 m_pImage = ConvertImage(rBitmap);
188
189 GetPosition(&nX, &nY);
190 GetSize(&nWidth, &nHeight);
191 // Convert to OS/2 coordinate system
192 nY = wxWindow::GetOS2ParentHeight(GetParent()) - nY - nHeight;
193
194 RECTL vRect;
195
196 vRect.xLeft = nX;
197 vRect.yTop = nY + nHeight;
198 vRect.xRight = nX + nWidth;
199 vRect.yBottom = nY;
200
201 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
202 }
203
204 MRESULT 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