]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticBitmap
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "statbmp.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/window.h"
34 #include "wx/msw/private.h"
38 #include "wx/statbmp.h"
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
47 #if wxUSE_EXTENDED_RTTI
48 WX_DEFINE_FLAGS( wxStaticBitmapStyle
)
50 wxBEGIN_FLAGS( wxStaticBitmapStyle
)
51 // new style border flags, we put them first to
52 // use them for streaming out
53 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
54 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
55 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
56 wxFLAGS_MEMBER(wxBORDER_RAISED
)
57 wxFLAGS_MEMBER(wxBORDER_STATIC
)
58 wxFLAGS_MEMBER(wxBORDER_NONE
)
60 // old style border flags
61 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
62 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
63 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
64 wxFLAGS_MEMBER(wxRAISED_BORDER
)
65 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
66 wxFLAGS_MEMBER(wxBORDER
)
68 // standard window styles
69 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
70 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
71 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
72 wxFLAGS_MEMBER(wxWANTS_CHARS
)
73 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
74 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
75 wxFLAGS_MEMBER(wxVSCROLL
)
76 wxFLAGS_MEMBER(wxHSCROLL
)
78 wxEND_FLAGS( wxStaticBitmapStyle
)
80 IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBitmap
, wxControl
,"wx/statbmp.h")
82 wxBEGIN_PROPERTIES_TABLE(wxStaticBitmap
)
83 wxPROPERTY_FLAGS( WindowStyle
, wxStaticBitmapStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
84 wxEND_PROPERTIES_TABLE()
86 wxBEGIN_HANDLERS_TABLE(wxStaticBitmap
)
87 wxEND_HANDLERS_TABLE()
89 wxCONSTRUCTOR_5( wxStaticBitmap
, wxWindow
* , Parent
, wxWindowID
, Id
, wxBitmap
, Bitmap
, wxPoint
, Position
, wxSize
, Size
)
92 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
100 // ===========================================================================
102 // ===========================================================================
104 // ---------------------------------------------------------------------------
106 // ---------------------------------------------------------------------------
108 // we may have either bitmap or icon: if a bitmap with mask is passed, we
109 // will transform it to an icon ourselves because otherwise the mask will
110 // be ignored by Windows
111 // note that this function will create a new object every time
112 // it is called even if the image needs no conversion
114 static wxGDIImage
* ConvertImage( const wxGDIImage
& bitmap
)
116 bool isIcon
= bitmap
.IsKindOf( CLASSINFO(wxIcon
) );
120 wxASSERT_MSG( wxDynamicCast(&bitmap
, wxBitmap
),
121 _T("not an icon and not a bitmap?") );
123 const wxBitmap
& bmp
= (const wxBitmap
&)bitmap
;
124 wxMask
*mask
= bmp
.GetMask();
125 if ( mask
&& mask
->GetMaskBitmap() )
127 wxIcon
* icon
= new wxIcon
;
128 icon
->CopyFromBitmap(bmp
);
133 return new wxBitmap( bmp
);
136 // copying a bitmap is a cheap operation
137 return new wxIcon( (const wxIcon
&)bitmap
);
140 bool wxStaticBitmap::Create(wxWindow
*parent
,
142 const wxGDIImage
& bitmap
,
146 const wxString
& name
)
148 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
151 // we may have either bitmap or icon: if a bitmap with mask is passed, we
152 // will transform it to an icon ourselves because otherwise the mask will
153 // be ignored by Windows
154 wxGDIImage
*image
= (wxGDIImage
*)NULL
;
155 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
157 image
= ConvertImage( bitmap
);
158 m_isIcon
= image
->IsKindOf( CLASSINFO(wxIcon
) );
160 // create the native control
161 if ( !MSWCreateControl(_T("STATIC"), wxEmptyString
, pos
, size
) )
163 // control creation failed
167 // no need to delete the new image
168 SetImageNoCopy(image
);
173 wxBorder
wxStaticBitmap::GetDefaultBorder() const
175 return wxBORDER_NONE
;
178 WXDWORD
wxStaticBitmap::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
180 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
182 // what kind of control are we?
183 msStyle
|= m_isIcon
? SS_ICON
: SS_BITMAP
;
185 // we use SS_CENTERIMAGE to prevent the control from resizing the bitmap to
186 // fit to its size -- this is unexpected and doesn't happen in other ports
187 msStyle
|= SS_CENTERIMAGE
;
192 bool wxStaticBitmap::ImageIsOk() const
194 return m_image
&& m_image
->Ok();
197 void wxStaticBitmap::Free()
204 wxSize
wxStaticBitmap::DoGetBestSize() const
206 // reuse the current size (as wxWindow does) instead of using some
207 // arbitrary default size (as wxControl, our immediate base class, does)
208 return wxWindow::DoGetBestSize();
211 void wxStaticBitmap::SetImage( const wxGDIImage
* image
)
213 wxGDIImage
* convertedImage
= ConvertImage( *image
);
214 SetImageNoCopy( convertedImage
);
217 void wxStaticBitmap::SetImageNoCopy( wxGDIImage
* image
)
221 m_isIcon
= image
->IsKindOf( CLASSINFO(wxIcon
) );
222 // the image has already been copied
231 HANDLE handle
= (HANDLE
)m_image
->GetHandle();
232 LONG style
= ::GetWindowLong( (HWND
)GetHWND(), GWL_STYLE
) ;
233 ::SetWindowLong( (HWND
)GetHWND(), GWL_STYLE
, ( style
& ~( SS_BITMAP
|SS_ICON
) ) |
234 ( m_isIcon
? SS_ICON
: SS_BITMAP
) );
235 ::SendMessage(GetHwnd(), STM_SETIMAGE
,
236 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
241 int width
= image
->GetWidth(),
242 height
= image
->GetHeight();
243 if ( width
&& height
)
248 ::MoveWindow(GetHwnd(), x
, y
, width
, height
, FALSE
);
257 InvalidateRect(GetHwndOf(GetParent()), &rect
, TRUE
);
260 // We need this or the control can never be moved e.g. in Dialog Editor.
261 WXLRESULT
wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
266 // Ensure that static items get messages. Some controls don't like this
267 // message to be intercepted (e.g. RichEdit), hence the tests.
268 if ( nMsg
== WM_NCHITTEST
)
269 return (long)HTCLIENT
;
272 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
275 #endif // wxUSE_STATBMP