/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/statbmp.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/statbmp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File size: 10468 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/statbmp.cpp
3 // Purpose: wxStaticBitmap
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id: statbmp.cpp 56532 2008-10-27 18:15:19Z VZ $
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_STATBMP
28
29 #include "wx/statbmp.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/window.h"
34 #include "wx/icon.h"
35 #include "wx/dcclient.h"
36 #endif
37
38 #include "wx/msw/private.h"
39
40 #include "wx/sysopt.h"
41
42 #include <stdio.h>
43
44 // ---------------------------------------------------------------------------
45 // macors
46 // ---------------------------------------------------------------------------
47
48 #if wxUSE_EXTENDED_RTTI
49 WX_DEFINE_FLAGS( wxStaticBitmapStyle )
50
51 wxBEGIN_FLAGS( wxStaticBitmapStyle )
52 // new style border flags, we put them first to
53 // use them for streaming out
54 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
55 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
56 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
57 wxFLAGS_MEMBER(wxBORDER_RAISED)
58 wxFLAGS_MEMBER(wxBORDER_STATIC)
59 wxFLAGS_MEMBER(wxBORDER_NONE)
60
61 // old style border flags
62 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
63 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
64 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
65 wxFLAGS_MEMBER(wxRAISED_BORDER)
66 wxFLAGS_MEMBER(wxSTATIC_BORDER)
67 wxFLAGS_MEMBER(wxBORDER)
68
69 // standard window styles
70 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
71 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
72 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
73 wxFLAGS_MEMBER(wxWANTS_CHARS)
74 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
75 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
76 wxFLAGS_MEMBER(wxVSCROLL)
77 wxFLAGS_MEMBER(wxHSCROLL)
78
79 wxEND_FLAGS( wxStaticBitmapStyle )
80
81 IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBitmap, wxControl,"wx/statbmp.h")
82
83 wxBEGIN_PROPERTIES_TABLE(wxStaticBitmap)
84 wxPROPERTY_FLAGS( WindowStyle , wxStaticBitmapStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
85 wxEND_PROPERTIES_TABLE()
86
87 wxBEGIN_HANDLERS_TABLE(wxStaticBitmap)
88 wxEND_HANDLERS_TABLE()
89
90 wxCONSTRUCTOR_5( wxStaticBitmap, wxWindow* , Parent , wxWindowID , Id , wxBitmap, Bitmap, wxPoint , Position , wxSize , Size )
91
92 #else
93 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
94 #endif
95
96 /*
97 TODO PROPERTIES :
98 bitmap
99 */
100
101 // ===========================================================================
102 // implementation
103 // ===========================================================================
104
105 // ---------------------------------------------------------------------------
106 // wxStaticBitmap
107 // ---------------------------------------------------------------------------
108
109 // we may have either bitmap or icon: if a bitmap with mask is passed, we
110 // will transform it to an icon ourselves because otherwise the mask will
111 // be ignored by Windows
112 // note that this function will create a new object every time
113 // it is called even if the image needs no conversion
114
115 static wxGDIImage* ConvertImage( const wxGDIImage& bitmap )
116 {
117 bool isIcon = bitmap.IsKindOf( CLASSINFO(wxIcon) );
118
119 if( !isIcon )
120 {
121 wxASSERT_MSG( wxDynamicCast(&bitmap, wxBitmap),
122 _T("not an icon and not a bitmap?") );
123
124 const wxBitmap& bmp = (const wxBitmap&)bitmap;
125 wxMask *mask = bmp.GetMask();
126 if ( mask && mask->GetMaskBitmap() )
127 {
128 wxIcon* icon = new wxIcon;
129 icon->CopyFromBitmap(bmp);
130
131 return icon;
132 }
133
134 return new wxBitmap( bmp );
135 }
136
137 // copying a bitmap is a cheap operation
138 return new wxIcon( (const wxIcon&)bitmap );
139 }
140
141 bool wxStaticBitmap::Create(wxWindow *parent,
142 wxWindowID id,
143 const wxGDIImage& bitmap,
144 const wxPoint& pos,
145 const wxSize& size,
146 long style,
147 const wxString& name)
148 {
149 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
150 return false;
151
152 // we may have either bitmap or icon: if a bitmap with mask is passed, we
153 // will transform it to an icon ourselves because otherwise the mask will
154 // be ignored by Windows
155 m_isIcon = bitmap.IsKindOf(CLASSINFO(wxIcon));
156
157 wxGDIImage *image = ConvertImage( bitmap );
158 m_isIcon = image->IsKindOf( CLASSINFO(wxIcon) );
159
160 // create the native control
161 if ( !MSWCreateControl(_T("STATIC"), wxEmptyString, pos, size) )
162 {
163 // control creation failed
164 return false;
165 }
166
167 // no need to delete the new image
168 SetImageNoCopy(image);
169
170 // GetBestSize will work properly now, so set the best size if needed
171 SetInitialSize(size);
172
173 // painting manually is reported not to work under Windows CE (see #10093),
174 // so don't do it there even if this probably means that alpha is not
175 // supported there -- but at least bitmaps without alpha appear correctly
176 #ifndef __WXWINCE__
177 // Windows versions before XP (and even XP if the application has no
178 // manifest and so the old comctl32.dll is used) don't draw correctly the
179 // images with alpha channel so we need to draw them ourselves and it's
180 // easier to just always do it rather than check if we have an image with
181 // alpha or not
182 if ( wxTheApp->GetComCtl32Version() < 600 )
183 {
184 Connect(wxEVT_PAINT, wxPaintEventHandler(wxStaticBitmap::DoPaintManually));
185 }
186 #endif // !__WXWINCE__
187
188 return true;
189 }
190
191 wxBorder wxStaticBitmap::GetDefaultBorder() const
192 {
193 return wxBORDER_NONE;
194 }
195
196 WXDWORD wxStaticBitmap::MSWGetStyle(long style, WXDWORD *exstyle) const
197 {
198 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
199
200 // what kind of control are we?
201 msStyle |= m_isIcon ? SS_ICON : SS_BITMAP;
202
203 // we use SS_CENTERIMAGE to prevent the control from resizing the bitmap to
204 // fit to its size -- this is unexpected and doesn't happen in other ports
205 //
206 // and SS_NOTIFY is necessary to receive mouse events
207 msStyle |= SS_CENTERIMAGE | SS_NOTIFY;
208
209 return msStyle;
210 }
211
212 bool wxStaticBitmap::ImageIsOk() const
213 {
214 return m_image && m_image->Ok();
215 }
216
217 wxIcon wxStaticBitmap::GetIcon() const
218 {
219 wxCHECK_MSG( m_image, wxIcon(), _T("no image in wxStaticBitmap") );
220
221 // we can't ask for an icon if all we have is a bitmap
222 wxCHECK_MSG( m_isIcon, wxIcon(), _T("no icon in this wxStaticBitmap") );
223
224 return *(wxIcon *)m_image;
225 }
226
227 wxBitmap wxStaticBitmap::GetBitmap() const
228 {
229 if ( m_isIcon )
230 {
231 // don't fail because we might have replaced the bitmap with icon
232 // ourselves internally in ConvertImage() to keep the transparency but
233 // the user code doesn't know about it so it still can use GetBitmap()
234 // to retrieve the bitmap
235 return wxBitmap(GetIcon());
236 }
237 else // we have a bitmap
238 {
239 wxCHECK_MSG( m_image, wxBitmap(), _T("no image in wxStaticBitmap") );
240
241 return *(wxBitmap *)m_image;
242 }
243 }
244
245 void wxStaticBitmap::Free()
246 {
247 delete m_image;
248
249 m_image = NULL;
250 }
251
252 wxSize wxStaticBitmap::DoGetBestSize() const
253 {
254 if ( ImageIsOk() )
255 {
256 wxSize best(m_image->GetWidth(), m_image->GetHeight());
257 CacheBestSize(best);
258 return best;
259 }
260
261 // this is completely arbitrary
262 return wxSize(16, 16);
263 }
264
265 void wxStaticBitmap::DoPaintManually(wxPaintEvent& WXUNUSED(event))
266 {
267 wxPaintDC dc(this);
268
269 const wxSize size(GetSize());
270 const wxBitmap bmp(GetBitmap());
271
272 // Clear the background: notice that we're supposed to be transparent, so
273 // use the parent background colour if we don't have our own instead of
274 // falling back to the default
275 const wxWindow *win = UseBgCol() ? this : GetParent();
276 dc.SetBrush(win->GetBackgroundColour());
277 dc.SetPen(*wxTRANSPARENT_PEN);
278 dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
279
280 // Draw the image in the middle
281 dc.DrawBitmap(bmp,
282 (size.GetWidth() - bmp.GetWidth()) / 2,
283 (size.GetHeight() - bmp.GetHeight()) / 2,
284 true /* use mask */);
285 }
286
287 void wxStaticBitmap::SetImage( const wxGDIImage* image )
288 {
289 wxGDIImage* convertedImage = ConvertImage( *image );
290 SetImageNoCopy( convertedImage );
291 InvalidateBestSize();
292 }
293
294 void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image)
295 {
296 Free();
297
298 m_isIcon = image->IsKindOf( CLASSINFO(wxIcon) );
299 // the image has already been copied
300 m_image = image;
301
302 int x, y;
303 int w, h;
304 GetPosition(&x, &y);
305 GetSize(&w, &h);
306
307 #ifdef __WIN32__
308 HANDLE handle = (HANDLE)m_image->GetHandle();
309 LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ;
310 ::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) |
311 ( m_isIcon ? SS_ICON : SS_BITMAP ) );
312 HGDIOBJ oldHandle = (HGDIOBJ)::SendMessage(GetHwnd(), STM_SETIMAGE,
313 m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
314 // detect if this is still the handle we passed before or
315 // if the static-control made a copy of the bitmap!
316 if (m_currentHandle != 0 && oldHandle != (HGDIOBJ) m_currentHandle)
317 {
318 // the static control made a copy and we are responsible for deleting it
319 DeleteObject((HGDIOBJ) oldHandle);
320 }
321 m_currentHandle = (WXHANDLE)handle;
322 #endif // Win32
323
324 if ( ImageIsOk() )
325 {
326 int width = image->GetWidth(),
327 height = image->GetHeight();
328 if ( width && height )
329 {
330 w = width;
331 h = height;
332
333 ::MoveWindow(GetHwnd(), x, y, width, height, FALSE);
334 }
335 }
336
337 RECT rect;
338 rect.left = x;
339 rect.top = y;
340 rect.right = x + w;
341 rect.bottom = y + h;
342 ::InvalidateRect(GetHwndOf(GetParent()), &rect, TRUE);
343 }
344
345 #endif // wxUSE_STATBMP

  ViewVC Help
Powered by ViewVC 1.1.22