Files
wxWidgets/include/wx/msw/statbmp.h
Vadim Zeitlin c1abbe6473 Refactor wxMSW wxStaticBitmap to separate bitmaps and icons
Use different members for storing wxBitmap and wxIcon instead of using a
single pointer for storing a heap-allocated copy of either of them
because this is simpler, more efficient due to avoiding unnecessary
conversions and RTTI, and will be simpler to generalize to using
wxBitmapBundle instead of wxBitmap in the upcoming commits.

As a side effect, don't assert in GetIcon() or GetBitmap() if there is
no valid icon or bitmap, as this is inconsistent with the other ports
and wasn't even consistent between these functions in wxMSW itself.

There should be no other changes in behaviour.
2021-10-25 13:40:18 +01:00

145 lines
4.5 KiB
C++

/////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/statbmp.h
// Purpose: wxStaticBitmap class for wxMSW
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_STATBMP_H_
#define _WX_STATBMP_H_
#include "wx/control.h"
#include "wx/icon.h"
#include "wx/bitmap.h"
extern WXDLLIMPEXP_DATA_CORE(const char) wxStaticBitmapNameStr[];
// a control showing an icon or a bitmap
class WXDLLIMPEXP_CORE wxStaticBitmap : public wxStaticBitmapBase
{
public:
wxStaticBitmap() { Init(); }
wxStaticBitmap(wxWindow *parent,
wxWindowID id,
const wxBitmap& label,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr))
{
Init();
Create(parent, id, label, pos, size, style, name);
}
wxStaticBitmap(wxWindow *parent,
wxWindowID id,
const wxIcon& label,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr))
{
Init();
Create(parent, id, label, pos, size, style, name);
}
bool Create(wxWindow *parent,
wxWindowID id,
const wxBitmap& label,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr))
{
m_bitmap = label;
return DoCreate(parent, id, pos, size, style, name);
}
bool Create(wxWindow *parent,
wxWindowID id,
const wxIcon& label,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr))
{
m_icon = label;
return DoCreate(parent, id, pos, size, style, name);
}
virtual ~wxStaticBitmap() { Free(); }
virtual void SetIcon(const wxIcon& icon) wxOVERRIDE;
virtual void SetBitmap(const wxBitmap& bitmap) wxOVERRIDE;
virtual wxBitmap GetBitmap() const wxOVERRIDE;
virtual wxIcon GetIcon() const wxOVERRIDE;
virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE;
// returns true if the platform should explicitly apply a theme border
virtual bool CanApplyThemeBorder() const wxOVERRIDE { return false; }
protected:
virtual wxSize DoGetBestClientSize() const wxOVERRIDE;
private:
// ctor/dtor helpers
void Init();
void Free();
// common part of both Create() overloads
bool DoCreate(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name);
// update the image to correspond to the current m_icon or m_bitmap value,
// resize the control if the new size is different from the old one and
// update its style if the new "is icon" value differs from the old one
void DoUpdateImage(const wxSize& sizeOld, bool wasIcon);
// draw the bitmap ourselves here if the OS can't do it correctly (if it
// can we leave it to it)
void DoPaintManually(wxPaintEvent& event);
void WXHandleSize(wxSizeEvent& event);
// return the either m_icon or m_bitmap (may still be invalid of both of
// them are)
const wxGDIImage& GetImage() const;
// we can have either an icon or a bitmap: if m_icon is valid, it is used,
// otherwise m_bitmap is used if it is valid
wxIcon m_icon;
wxBitmap m_bitmap;
// handle used in last call to STM_SETIMAGE
WXHANDLE m_currentHandle;
// Flag indicating whether we own m_currentHandle, i.e. should delete it.
bool m_ownsCurrentHandle;
// Replace the image at the native control level with the given HBITMAP or
// HICON (which can be 0) and destroy the previous image if necessary.
void MSWReplaceImageHandle(WXLPARAM handle);
wxDECLARE_DYNAMIC_CLASS(wxStaticBitmap);
wxDECLARE_EVENT_TABLE();
wxDECLARE_NO_COPY_CLASS(wxStaticBitmap);
};
#endif
// _WX_STATBMP_H_