]>
Commit | Line | Data |
---|---|---|
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 | 8 | // Copyright: (c) David Webster |
65571936 | 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 | ||
50528a1d | 19 | #include "wx/dcclient.h" |
409c9842 DW |
20 | #include "wx/window.h" |
21 | #include "wx/os2/private.h" | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/icon.h" | |
25 | #include "wx/statbmp.h" | |
0e320a79 DW |
26 | #endif |
27 | ||
409c9842 DW |
28 | #include <stdio.h> |
29 | ||
30 | // --------------------------------------------------------------------------- | |
31 | // macors | |
32 | // --------------------------------------------------------------------------- | |
0e320a79 | 33 | |
0e320a79 | 34 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) |
0e320a79 | 35 | |
1de4baa3 DW |
36 | BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow) |
37 | EVT_PAINT(wxStaticBitmap::OnPaint) | |
38 | END_EVENT_TABLE() | |
39 | ||
70a2c656 DW |
40 | static wxGDIImage* ConvertImage( |
41 | const wxGDIImage& rBitmap | |
42 | ) | |
43 | { | |
44 | bool bIsIcon = rBitmap.IsKindOf( CLASSINFO(wxIcon) ); | |
45 | ||
46 | if(!bIsIcon ) | |
47 | { | |
48 | wxASSERT_MSG( wxDynamicCast(&rBitmap, wxBitmap), | |
49 | _T("not an icon and not a bitmap?") ); | |
50 | ||
51 | const wxBitmap& rBmp = (const wxBitmap&)rBitmap; | |
52 | wxMask* pMask = rBmp.GetMask(); | |
53 | ||
54 | if (pMask && pMask->GetMaskBitmap()) | |
55 | { | |
56 | wxIcon* pIcon = new wxIcon; | |
57 | ||
58 | pIcon->CopyFromBitmap(rBmp); | |
59 | return pIcon; | |
60 | } | |
61 | return new wxBitmap(rBmp); | |
62 | } | |
63 | ||
64 | // copying a bitmap is a cheap operation | |
65 | return new wxIcon( (const wxIcon&)rBitmap ); | |
66 | } // end of ConvertImage | |
67 | ||
409c9842 DW |
68 | // --------------------------------------------------------------------------- |
69 | // wxStaticBitmap | |
70 | // --------------------------------------------------------------------------- | |
0e320a79 | 71 | |
6670f564 WS |
72 | bool wxStaticBitmap::Create( wxWindow* pParent, |
73 | wxWindowID nId, | |
74 | const wxGDIImage& rBitmap, | |
75 | const wxPoint& rPos, | |
76 | const wxSize& WXUNUSED(rSize), | |
77 | long lStyle, | |
78 | const wxString& rName ) | |
0e320a79 | 79 | { |
70a2c656 DW |
80 | ERRORID vError; |
81 | wxString sError; | |
82 | ||
04701dd9 DW |
83 | Init(); |
84 | ||
3b9e3455 | 85 | SetName(rName); |
43543d98 DW |
86 | if (pParent) |
87 | pParent->AddChild(this); | |
0e320a79 | 88 | |
43543d98 | 89 | if (nId == -1) |
409c9842 | 90 | m_windowId = (int)NewControlId(); |
0e320a79 | 91 | else |
3b9e3455 | 92 | m_windowId = nId; |
0e320a79 | 93 | |
3b9e3455 | 94 | m_windowStyle = lStyle; |
0e320a79 | 95 | |
43543d98 DW |
96 | int nX= rPos.x; |
97 | int nY = rPos.y; | |
70a2c656 | 98 | char zId[16]; |
04701dd9 | 99 | |
3b9e3455 | 100 | m_windowStyle = lStyle; |
04701dd9 | 101 | |
3b9e3455 | 102 | m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon)); |
04701dd9 | 103 | |
70a2c656 DW |
104 | // |
105 | // For now we only support an ICON | |
106 | // | |
107 | int nWinstyle = SS_ICON; | |
3b9e3455 | 108 | |
43543d98 | 109 | m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND() |
0fba44b4 | 110 | ,(PSZ)wxCanvasClassName |
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); | |
6670f564 | 124 | return false; |
70a2c656 | 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); | |
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 | 137 | bool wxStaticBitmap::ImageIsOk() const |
0e320a79 | 138 | { |
43543d98 | 139 | return(m_pImage && m_pImage->Ok()); |
409c9842 DW |
140 | } |
141 | ||
142 | void 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 | 149 | wxSize 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 | ||
1de4baa3 DW |
158 | void wxStaticBitmap::OnPaint ( |
159 | wxPaintEvent& WXUNUSED(rEvent) | |
160 | ) | |
161 | { | |
162 | wxPaintDC vDc(this); | |
1de4baa3 DW |
163 | wxBitmap* pBitmap; |
164 | ||
165 | if (m_pImage->IsKindOf(CLASSINFO(wxIcon))) | |
166 | { | |
167 | wxIcon* pIcon; | |
168 | ||
169 | pIcon = wxDynamicCast(m_pImage, wxIcon); | |
170 | pBitmap = new wxBitmap(*pIcon); | |
171 | vDc.DrawBitmap(*pBitmap, 0, 0); | |
172 | delete pBitmap; | |
173 | } | |
174 | else | |
175 | { | |
176 | pBitmap = wxDynamicCast(m_pImage, wxBitmap); | |
177 | vDc.DrawBitmap(*pBitmap, 0, 0); | |
178 | } | |
179 | } // end of wxStaticBitmap::OnPaint | |
180 | ||
3b9e3455 DW |
181 | void wxStaticBitmap::SetImage( |
182 | const wxGDIImage& rBitmap | |
183 | ) | |
0e320a79 | 184 | { |
70a2c656 DW |
185 | int nX = 0; |
186 | int nY = 0; | |
187 | int nWidth = 0; | |
188 | int nHeight = 0; | |
3b9e3455 | 189 | |
70a2c656 | 190 | Free(); |
3b9e3455 DW |
191 | ::WinSendMsg( GetHwnd() |
192 | ,SM_SETHANDLE | |
70a2c656 | 193 | ,MPFROMHWND(rBitmap.GetHandle()) |
3b9e3455 DW |
194 | ,NULL |
195 | ); | |
70a2c656 | 196 | m_pImage = ConvertImage(rBitmap); |
3b9e3455 | 197 | |
70a2c656 DW |
198 | GetPosition(&nX, &nY); |
199 | GetSize(&nWidth, &nHeight); | |
3b9e3455 DW |
200 | |
201 | RECTL vRect; | |
202 | ||
70a2c656 | 203 | vRect.xLeft = nX; |
3b9e3455 | 204 | vRect.yTop = nY; |
70a2c656 DW |
205 | vRect.xRight = nX + nWidth; |
206 | vRect.yBottom = nY + nHeight; | |
3b9e3455 DW |
207 | |
208 | ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE); | |
0e320a79 DW |
209 | } |
210 | ||
32334453 DW |
211 | MRESULT wxStaticBitmap::OS2WindowProc( |
212 | WXUINT uMsg | |
213 | , WXWPARAM wParam | |
214 | , WXLPARAM lParam | |
215 | ) | |
216 | { | |
217 | return wxWindow::OS2WindowProc(uMsg, wParam, lParam); | |
218 | } // end of wxStaticBitmap::OS2WindowProc |