~ubuntu-branches/ubuntu/wily/wxwidgets3.0/wily-proposed

« back to all changes in this revision

Viewing changes to src/msw/statbmp.cpp

  • Committer: Package Import Robot
  • Author(s): Olly Betts
  • Date: 2014-06-18 12:42:22 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140618124222-y7t2vpsije1cesxy
Tags: 3.0.1-1
* New upstream release
  + Incorporates most of the patches we were carrying - only one left is:
    wx-config-conditionalise-webview-in-std.patch
* Drop versioning of dependencies from run-time libraries to wx-common -
  this will make the transition to the next wx version harder, and also
  makes backporting to wheezy more work.
* Mark -dbg packages as "Multi-Arch: same".
* Correct short descriptions of the webview packages to not just be
  copies of the corresponding media package's short description.
* Wrap 81 character line in package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#endif
36
36
 
37
37
#include "wx/msw/private.h"
 
38
#include "wx/msw/dib.h"
38
39
 
39
40
#include "wx/sysopt.h"
40
41
 
189
190
 
190
191
void wxStaticBitmap::Free()
191
192
{
 
193
    MSWReplaceImageHandle(0);
 
194
 
192
195
    wxDELETE(m_image);
193
196
}
194
197
 
250
253
    SetImageNoCopy( convertedImage );
251
254
}
252
255
 
 
256
void wxStaticBitmap::MSWReplaceImageHandle(WXLPARAM handle)
 
257
{
 
258
    HGDIOBJ oldHandle = (HGDIOBJ)::SendMessage(GetHwnd(), STM_SETIMAGE,
 
259
                  m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
 
260
    // detect if this is still the handle we passed before or
 
261
    // if the static-control made a copy of the bitmap!
 
262
    if (oldHandle != 0 && oldHandle != (HGDIOBJ) m_currentHandle)
 
263
    {
 
264
        // the static control made a copy and we are responsible for deleting it
 
265
        ::DeleteObject((HGDIOBJ) oldHandle);
 
266
    }
 
267
}
 
268
 
253
269
void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image)
254
270
{
255
271
    Free();
266
282
 
267
283
#ifdef __WIN32__
268
284
    HANDLE handle = (HANDLE)m_image->GetHandle();
 
285
 
 
286
    AutoHBITMAP hbmpRelease;
 
287
    if ( !m_isIcon )
 
288
    {
 
289
        // wxBitmap normally stores alpha in pre-multiplied format but
 
290
        // apparently STM_SETIMAGE message handler does pre-multiplication
 
291
        // internally so we need to undo the pre-multiplication here for a
 
292
        // while (this is similar to what we do in ImageList::Add()).
 
293
        const wxBitmap& bmp = static_cast<wxBitmap&>(*image);
 
294
        if ( bmp.HasAlpha() )
 
295
        {
 
296
            // For bitmap with alpha channel create temporary DIB with
 
297
            // not-premultiplied alpha values.
 
298
            handle = wxDIB(bmp.ConvertToImage(),
 
299
                           wxDIB::PixelFormat_NotPreMultiplied).Detach();
 
300
 
 
301
            // Ensure that this temporary HBITMAP will be destroyed.
 
302
            hbmpRelease.Init((HBITMAP)handle);
 
303
        }
 
304
    }
269
305
    LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ;
270
306
    ::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) |
271
307
                     ( m_isIcon ? SS_ICON : SS_BITMAP ) );
272
 
    HGDIOBJ oldHandle = (HGDIOBJ)::SendMessage(GetHwnd(), STM_SETIMAGE,
273
 
                  m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
274
 
    // detect if this is still the handle we passed before or
275
 
    // if the static-control made a copy of the bitmap!
276
 
    if (m_currentHandle != 0 && oldHandle != (HGDIOBJ) m_currentHandle)
277
 
    {
278
 
        // the static control made a copy and we are responsible for deleting it
279
 
        DeleteObject((HGDIOBJ) oldHandle);
280
 
    }
281
 
    m_currentHandle = (WXHANDLE)handle;
 
308
 
 
309
    MSWReplaceImageHandle((WXLPARAM)handle);
 
310
 
 
311
    // Save bitmap handle only if it's not a temporary one, otherwise it's
 
312
    // going to be destroyed right now anyhow.
 
313
    if ( !hbmpRelease )
 
314
        m_currentHandle = (WXHANDLE)handle;
 
315
 
282
316
#endif // Win32
283
317
 
284
318
    if ( ImageIsOk() )