]>
Commit | Line | Data |
---|---|---|
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 | |
1de4baa3 DW |
31 | BEGIN_EVENT_TABLE(wxStaticBitmap, wxWindow) |
32 | EVT_PAINT(wxStaticBitmap::OnPaint) | |
33 | END_EVENT_TABLE() | |
34 | ||
70a2c656 DW |
35 | static 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), | |
9a83f860 | 44 | wxT("not an icon and not a bitmap?") ); |
70a2c656 DW |
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 | |
6670f564 WS |
67 | bool wxStaticBitmap::Create( wxWindow* pParent, |
68 | wxWindowID nId, | |
69 | const wxGDIImage& rBitmap, | |
70 | const wxPoint& rPos, | |
71 | const wxSize& WXUNUSED(rSize), | |
72 | long lStyle, | |
73 | const wxString& rName ) | |
0e320a79 | 74 | { |
70a2c656 DW |
75 | ERRORID vError; |
76 | wxString sError; | |
77 | ||
04701dd9 DW |
78 | Init(); |
79 | ||
3b9e3455 | 80 | SetName(rName); |
43543d98 DW |
81 | if (pParent) |
82 | pParent->AddChild(this); | |
0e320a79 | 83 | |
43543d98 | 84 | if (nId == -1) |
409c9842 | 85 | m_windowId = (int)NewControlId(); |
0e320a79 | 86 | else |
3b9e3455 | 87 | m_windowId = nId; |
0e320a79 | 88 | |
3b9e3455 | 89 | m_windowStyle = lStyle; |
0e320a79 | 90 | |
43543d98 DW |
91 | int nX= rPos.x; |
92 | int nY = rPos.y; | |
70a2c656 | 93 | char zId[16]; |
04701dd9 | 94 | |
3b9e3455 | 95 | m_windowStyle = lStyle; |
04701dd9 | 96 | |
3b9e3455 | 97 | m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon)); |
04701dd9 | 98 | |
70a2c656 DW |
99 | // |
100 | // For now we only support an ICON | |
101 | // | |
102 | int nWinstyle = SS_ICON; | |
3b9e3455 | 103 | |
43543d98 | 104 | m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND() |
0fba44b4 | 105 | ,(PSZ)wxCanvasClassName |
70a2c656 | 106 | ,zId |
3b9e3455 DW |
107 | ,nWinstyle | WS_VISIBLE |
108 | ,0,0,0,0 | |
109 | ,pParent->GetHWND() | |
110 | ,HWND_TOP | |
111 | ,m_windowId | |
112 | ,NULL | |
113 | ,NULL | |
114 | ); | |
70a2c656 DW |
115 | if (!m_hWnd) |
116 | { | |
117 | vError = ::WinGetLastError(wxGetInstance()); | |
118 | sError = wxPMErrorToStr(vError); | |
6670f564 | 119 | return false; |
70a2c656 | 120 | } |
cdccdfab | 121 | wxCHECK_MSG( m_hWnd, false, wxT("Failed to create static bitmap") ); |
70a2c656 | 122 | m_pImage = ConvertImage(rBitmap); |
179db36d SN |
123 | ::WinSendMsg( m_hWnd, |
124 | SM_SETHANDLE, | |
125 | MPFROMHWND(rBitmap.GetHandle()), | |
126 | (MPARAM)0); | |
04701dd9 DW |
127 | |
128 | // Subclass again for purposes of dialog editing mode | |
129 | SubclassWin(m_hWnd); | |
1de4baa3 DW |
130 | SetSize(nX, nY, m_pImage->GetWidth(), m_pImage->GetHeight()); |
131 | ||
6670f564 | 132 | return true; |
70a2c656 | 133 | } // end of wxStaticBitmap::Create |
0e320a79 | 134 | |
409c9842 | 135 | bool wxStaticBitmap::ImageIsOk() const |
0e320a79 | 136 | { |
43543d98 | 137 | return(m_pImage && m_pImage->Ok()); |
409c9842 DW |
138 | } |
139 | ||
140 | void wxStaticBitmap::Free() | |
141 | { | |
5276b0a5 | 142 | wxDELETE(m_pImage); |
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 | ||
cdccdfab | 154 | void wxStaticBitmap::OnPaint ( wxPaintEvent& WXUNUSED(rEvent) ) |
1de4baa3 | 155 | { |
cdccdfab WS |
156 | wxPaintDC vDc(this); |
157 | wxBitmap* pBitmap; | |
1de4baa3 DW |
158 | |
159 | if (m_pImage->IsKindOf(CLASSINFO(wxIcon))) | |
160 | { | |
161 | wxIcon* pIcon; | |
162 | ||
163 | pIcon = wxDynamicCast(m_pImage, wxIcon); | |
164 | pBitmap = new wxBitmap(*pIcon); | |
165 | vDc.DrawBitmap(*pBitmap, 0, 0); | |
166 | delete pBitmap; | |
167 | } | |
168 | else | |
169 | { | |
170 | pBitmap = wxDynamicCast(m_pImage, wxBitmap); | |
171 | vDc.DrawBitmap(*pBitmap, 0, 0); | |
172 | } | |
173 | } // end of wxStaticBitmap::OnPaint | |
174 | ||
cdccdfab | 175 | void wxStaticBitmap::SetImage( const wxGDIImage& rBitmap ) |
0e320a79 | 176 | { |
cdccdfab WS |
177 | int nX = 0; |
178 | int nY = 0; | |
179 | int nWidth = 0; | |
180 | int nHeight = 0; | |
3b9e3455 | 181 | |
70a2c656 | 182 | Free(); |
3b9e3455 DW |
183 | ::WinSendMsg( GetHwnd() |
184 | ,SM_SETHANDLE | |
70a2c656 | 185 | ,MPFROMHWND(rBitmap.GetHandle()) |
3b9e3455 DW |
186 | ,NULL |
187 | ); | |
70a2c656 | 188 | m_pImage = ConvertImage(rBitmap); |
3b9e3455 | 189 | |
70a2c656 DW |
190 | GetPosition(&nX, &nY); |
191 | GetSize(&nWidth, &nHeight); | |
179db36d SN |
192 | // Convert to OS/2 coordinate system |
193 | nY = wxWindow::GetOS2ParentHeight(GetParent()) - nY - nHeight; | |
3b9e3455 DW |
194 | |
195 | RECTL vRect; | |
196 | ||
70a2c656 | 197 | vRect.xLeft = nX; |
179db36d | 198 | vRect.yTop = nY + nHeight; |
70a2c656 | 199 | vRect.xRight = nX + nWidth; |
179db36d | 200 | vRect.yBottom = nY; |
3b9e3455 DW |
201 | |
202 | ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE); | |
0e320a79 DW |
203 | } |
204 | ||
32334453 DW |
205 | MRESULT wxStaticBitmap::OS2WindowProc( |
206 | WXUINT uMsg | |
207 | , WXWPARAM wParam | |
208 | , WXLPARAM lParam | |
209 | ) | |
210 | { | |
211 | return wxWindow::OS2WindowProc(uMsg, wParam, lParam); | |
212 | } // end of wxStaticBitmap::OS2WindowProc |