]>
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 | ||
409c9842 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
50528a1d | 15 | #include "wx/dcclient.h" |
409c9842 DW |
16 | #include "wx/window.h" |
17 | #include "wx/os2/private.h" | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/icon.h" | |
21 | #include "wx/statbmp.h" | |
0e320a79 DW |
22 | #endif |
23 | ||
409c9842 DW |
24 | #include <stdio.h> |
25 | ||
26 | // --------------------------------------------------------------------------- | |
27 | // macors | |
28 | // --------------------------------------------------------------------------- | |
0e320a79 | 29 | |
0e320a79 | 30 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) |
0e320a79 | 31 | |
1de4baa3 DW |
32 | BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow) |
33 | EVT_PAINT(wxStaticBitmap::OnPaint) | |
34 | END_EVENT_TABLE() | |
35 | ||
70a2c656 DW |
36 | static wxGDIImage* ConvertImage( |
37 | const wxGDIImage& rBitmap | |
38 | ) | |
39 | { | |
40 | bool bIsIcon = rBitmap.IsKindOf( CLASSINFO(wxIcon) ); | |
41 | ||
42 | if(!bIsIcon ) | |
43 | { | |
44 | wxASSERT_MSG( wxDynamicCast(&rBitmap, wxBitmap), | |
45 | _T("not an icon and not a bitmap?") ); | |
46 | ||
47 | const wxBitmap& rBmp = (const wxBitmap&)rBitmap; | |
48 | wxMask* pMask = rBmp.GetMask(); | |
49 | ||
50 | if (pMask && pMask->GetMaskBitmap()) | |
51 | { | |
52 | wxIcon* pIcon = new wxIcon; | |
53 | ||
54 | pIcon->CopyFromBitmap(rBmp); | |
55 | return pIcon; | |
56 | } | |
57 | return new wxBitmap(rBmp); | |
58 | } | |
59 | ||
60 | // copying a bitmap is a cheap operation | |
61 | return new wxIcon( (const wxIcon&)rBitmap ); | |
62 | } // end of ConvertImage | |
63 | ||
409c9842 DW |
64 | // --------------------------------------------------------------------------- |
65 | // wxStaticBitmap | |
66 | // --------------------------------------------------------------------------- | |
0e320a79 | 67 | |
6670f564 WS |
68 | bool wxStaticBitmap::Create( wxWindow* pParent, |
69 | wxWindowID nId, | |
70 | const wxGDIImage& rBitmap, | |
71 | const wxPoint& rPos, | |
72 | const wxSize& WXUNUSED(rSize), | |
73 | long lStyle, | |
74 | const wxString& rName ) | |
0e320a79 | 75 | { |
70a2c656 DW |
76 | ERRORID vError; |
77 | wxString sError; | |
78 | ||
04701dd9 DW |
79 | Init(); |
80 | ||
3b9e3455 | 81 | SetName(rName); |
43543d98 DW |
82 | if (pParent) |
83 | pParent->AddChild(this); | |
0e320a79 | 84 | |
43543d98 | 85 | if (nId == -1) |
409c9842 | 86 | m_windowId = (int)NewControlId(); |
0e320a79 | 87 | else |
3b9e3455 | 88 | m_windowId = nId; |
0e320a79 | 89 | |
3b9e3455 | 90 | m_windowStyle = lStyle; |
0e320a79 | 91 | |
43543d98 DW |
92 | int nX= rPos.x; |
93 | int nY = rPos.y; | |
70a2c656 | 94 | char zId[16]; |
04701dd9 | 95 | |
3b9e3455 | 96 | m_windowStyle = lStyle; |
04701dd9 | 97 | |
3b9e3455 | 98 | m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon)); |
04701dd9 | 99 | |
70a2c656 DW |
100 | // |
101 | // For now we only support an ICON | |
102 | // | |
103 | int nWinstyle = SS_ICON; | |
3b9e3455 | 104 | |
43543d98 | 105 | m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND() |
0fba44b4 | 106 | ,(PSZ)wxCanvasClassName |
70a2c656 | 107 | ,zId |
3b9e3455 DW |
108 | ,nWinstyle | WS_VISIBLE |
109 | ,0,0,0,0 | |
110 | ,pParent->GetHWND() | |
111 | ,HWND_TOP | |
112 | ,m_windowId | |
113 | ,NULL | |
114 | ,NULL | |
115 | ); | |
70a2c656 DW |
116 | if (!m_hWnd) |
117 | { | |
118 | vError = ::WinGetLastError(wxGetInstance()); | |
119 | sError = wxPMErrorToStr(vError); | |
6670f564 | 120 | return false; |
70a2c656 | 121 | } |
04701dd9 | 122 | wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") ); |
70a2c656 DW |
123 | m_pImage = ConvertImage(rBitmap); |
124 | m_pImage->SetHandle((WXHWND)::WinSendMsg(m_hWnd, SM_QUERYHANDLE, (MPARAM)0, (MPARAM)0)); | |
04701dd9 DW |
125 | |
126 | // Subclass again for purposes of dialog editing mode | |
127 | SubclassWin(m_hWnd); | |
1de4baa3 DW |
128 | SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight()); |
129 | ||
6670f564 | 130 | return true; |
70a2c656 | 131 | } // end of wxStaticBitmap::Create |
0e320a79 | 132 | |
409c9842 | 133 | bool wxStaticBitmap::ImageIsOk() const |
0e320a79 | 134 | { |
43543d98 | 135 | return(m_pImage && m_pImage->Ok()); |
409c9842 DW |
136 | } |
137 | ||
138 | void wxStaticBitmap::Free() | |
139 | { | |
70a2c656 DW |
140 | if (m_pImage) |
141 | delete m_pImage; | |
3b9e3455 | 142 | m_pImage = NULL; |
70a2c656 | 143 | } // end of wxStaticBitmap::Free |
409c9842 | 144 | |
e78c4d50 | 145 | wxSize wxStaticBitmap::DoGetBestSize() const |
409c9842 | 146 | { |
70a2c656 DW |
147 | // |
148 | // Reuse the current size (as wxWindow does) instead of using some | |
409c9842 | 149 | // arbitrary default size (as wxControl, our immediate base class, does) |
70a2c656 | 150 | // |
409c9842 | 151 | return wxWindow::DoGetBestSize(); |
0e320a79 DW |
152 | } |
153 | ||
1de4baa3 DW |
154 | void wxStaticBitmap::OnPaint ( |
155 | wxPaintEvent& WXUNUSED(rEvent) | |
156 | ) | |
157 | { | |
158 | wxPaintDC vDc(this); | |
1de4baa3 DW |
159 | wxBitmap* pBitmap; |
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 | ||
3b9e3455 DW |
177 | void wxStaticBitmap::SetImage( |
178 | const wxGDIImage& rBitmap | |
179 | ) | |
0e320a79 | 180 | { |
70a2c656 DW |
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); | |
3b9e3455 DW |
196 | |
197 | RECTL vRect; | |
198 | ||
70a2c656 | 199 | vRect.xLeft = nX; |
3b9e3455 | 200 | vRect.yTop = nY; |
70a2c656 DW |
201 | vRect.xRight = nX + nWidth; |
202 | vRect.yBottom = nY + nHeight; | |
3b9e3455 DW |
203 | |
204 | ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE); | |
0e320a79 DW |
205 | } |
206 | ||
32334453 DW |
207 | MRESULT 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 |