]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbmp.cpp
more synonyms for UCS-2/4
[wxWidgets.git] / src / msw / statbmp.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: statbmp.cpp
3// Purpose: wxStaticBitmap
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
9e3e0821
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
9e3e0821 21 #pragma implementation "statbmp.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
9e3e0821 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
1e6feb95
VZ
31#if wxUSE_STATBMP
32
0c589ad0
BM
33#include "wx/window.h"
34#include "wx/msw/private.h"
35
2bda0e17 36#ifndef WX_PRECOMP
0c589ad0 37 #include "wx/icon.h"
9e3e0821 38 #include "wx/statbmp.h"
2bda0e17
KB
39#endif
40
9dabade2
JS
41#include "wx/sysopt.h"
42
2bda0e17 43#include <stdio.h>
2bda0e17 44
9e3e0821
VZ
45// ---------------------------------------------------------------------------
46// macors
47// ---------------------------------------------------------------------------
48
bc9fb572
JS
49#if wxUSE_EXTENDED_RTTI
50WX_DEFINE_FLAGS( wxStaticBitmapStyle )
51
3ff066a4 52wxBEGIN_FLAGS( wxStaticBitmapStyle )
bc9fb572
JS
53 // new style border flags, we put them first to
54 // use them for streaming out
3ff066a4
SC
55 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
56 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
57 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
58 wxFLAGS_MEMBER(wxBORDER_RAISED)
59 wxFLAGS_MEMBER(wxBORDER_STATIC)
60 wxFLAGS_MEMBER(wxBORDER_NONE)
57f4f925 61
bc9fb572 62 // old style border flags
3ff066a4
SC
63 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
64 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
65 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
66 wxFLAGS_MEMBER(wxRAISED_BORDER)
67 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 68 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
69
70 // standard window styles
3ff066a4
SC
71 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
72 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
73 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
74 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 75 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
76 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
77 wxFLAGS_MEMBER(wxVSCROLL)
78 wxFLAGS_MEMBER(wxHSCROLL)
bc9fb572 79
3ff066a4 80wxEND_FLAGS( wxStaticBitmapStyle )
bc9fb572
JS
81
82IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBitmap, wxControl,"wx/statbmp.h")
83
3ff066a4 84wxBEGIN_PROPERTIES_TABLE(wxStaticBitmap)
af498247 85 wxPROPERTY_FLAGS( WindowStyle , wxStaticBitmapStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 86wxEND_PROPERTIES_TABLE()
bc9fb572 87
3ff066a4
SC
88wxBEGIN_HANDLERS_TABLE(wxStaticBitmap)
89wxEND_HANDLERS_TABLE()
bc9fb572 90
3ff066a4 91wxCONSTRUCTOR_5( wxStaticBitmap, wxWindow* , Parent , wxWindowID , Id , wxBitmap, Bitmap, wxPoint , Position , wxSize , Size )
bc9fb572
JS
92
93#else
4004f41e 94IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
bc9fb572 95#endif
2bda0e17 96
066f1b7a 97/*
57f4f925
WS
98 TODO PROPERTIES :
99 bitmap
066f1b7a
SC
100*/
101
9e3e0821
VZ
102// ===========================================================================
103// implementation
104// ===========================================================================
105
106// ---------------------------------------------------------------------------
107// wxStaticBitmap
108// ---------------------------------------------------------------------------
2bda0e17 109
d8bffc13
MB
110// we may have either bitmap or icon: if a bitmap with mask is passed, we
111// will transform it to an icon ourselves because otherwise the mask will
112// be ignored by Windows
113// note that this function will create a new object every time
114// it is called even if the image needs no conversion
115
d8bffc13
MB
116static wxGDIImage* ConvertImage( const wxGDIImage& bitmap )
117{
118 bool isIcon = bitmap.IsKindOf( CLASSINFO(wxIcon) );
119
120 if( !isIcon )
121 {
122 wxASSERT_MSG( wxDynamicCast(&bitmap, wxBitmap),
123 _T("not an icon and not a bitmap?") );
124
125 const wxBitmap& bmp = (const wxBitmap&)bitmap;
126 wxMask *mask = bmp.GetMask();
127 if ( mask && mask->GetMaskBitmap() )
128 {
129 wxIcon* icon = new wxIcon;
130 icon->CopyFromBitmap(bmp);
131
132 return icon;
133 }
134
135 return new wxBitmap( bmp );
136 }
137
138 // copying a bitmap is a cheap operation
139 return new wxIcon( (const wxIcon&)bitmap );
140}
141
46a5e01e
VZ
142bool wxStaticBitmap::Create(wxWindow *parent,
143 wxWindowID id,
0d0512bd 144 const wxGDIImage& bitmap,
9e3e0821
VZ
145 const wxPoint& pos,
146 const wxSize& size,
147 long style,
148 const wxString& name)
2bda0e17 149{
46a5e01e 150 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
57f4f925 151 return false;
9e3e0821 152
4004f41e
VZ
153 // we may have either bitmap or icon: if a bitmap with mask is passed, we
154 // will transform it to an icon ourselves because otherwise the mask will
155 // be ignored by Windows
9e3e0821 156 m_isIcon = bitmap.IsKindOf(CLASSINFO(wxIcon));
669f7a11 157
5cb598ae 158 wxGDIImage *image = ConvertImage( bitmap );
d8bffc13 159 m_isIcon = image->IsKindOf( CLASSINFO(wxIcon) );
9e3e0821 160
46a5e01e 161 // create the native control
3a5bcc4d 162 if ( !MSWCreateControl(_T("STATIC"), wxEmptyString, pos, size) )
46a5e01e
VZ
163 {
164 // control creation failed
3a5bcc4d 165 return false;
46a5e01e 166 }
9e3e0821 167
d8bffc13 168 // no need to delete the new image
46a5e01e 169 SetImageNoCopy(image);
9e3e0821 170
9d17ee60
RD
171 // GetBestSize will work properly now, so set the best size if needed
172 SetBestSize(size);
57f4f925
WS
173
174 return true;
46a5e01e 175}
9e3e0821 176
65bc172c
VZ
177wxBorder wxStaticBitmap::GetDefaultBorder() const
178{
179 return wxBORDER_NONE;
180}
181
46a5e01e
VZ
182WXDWORD wxStaticBitmap::MSWGetStyle(long style, WXDWORD *exstyle) const
183{
184 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
9e3e0821 185
46a5e01e
VZ
186 // what kind of control are we?
187 msStyle |= m_isIcon ? SS_ICON : SS_BITMAP;
9e3e0821 188
46a5e01e
VZ
189 // we use SS_CENTERIMAGE to prevent the control from resizing the bitmap to
190 // fit to its size -- this is unexpected and doesn't happen in other ports
42b1fb63
VZ
191 //
192 // and SS_NOTIFY is necessary to receive mouse events
193 msStyle |= SS_CENTERIMAGE | SS_NOTIFY;
46a5e01e
VZ
194
195 return msStyle;
9e3e0821
VZ
196}
197
198bool wxStaticBitmap::ImageIsOk() const
199{
0d0512bd 200 return m_image && m_image->Ok();
9e3e0821
VZ
201}
202
203void wxStaticBitmap::Free()
204{
0d0512bd 205 delete m_image;
9e3e0821 206
0d0512bd 207 m_image = NULL;
2bda0e17
KB
208}
209
9d17ee60
RD
210wxSize wxStaticBitmap::DoGetBestSize() const
211{
212 if ( ImageIsOk() )
31582e4e
RD
213 {
214 wxSize best(m_image->GetWidth(), m_image->GetHeight());
215 CacheBestSize(best);
216 return best;
217 }
9d17ee60
RD
218
219 // this is completely arbitrary
220 return wxSize(16, 16);
221}
222
d8bffc13 223void wxStaticBitmap::SetImage( const wxGDIImage* image )
2bda0e17 224{
d8bffc13
MB
225 wxGDIImage* convertedImage = ConvertImage( *image );
226 SetImageNoCopy( convertedImage );
9f884528 227 InvalidateBestSize();
d8bffc13 228}
4004f41e 229
d8bffc13
MB
230void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image)
231{
232 Free();
4004f41e 233
d8bffc13
MB
234 m_isIcon = image->IsKindOf( CLASSINFO(wxIcon) );
235 // the image has already been copied
236 m_image = image;
9e3e0821
VZ
237
238 int x, y;
239 int w, h;
240 GetPosition(&x, &y);
241 GetSize(&w, &h);
9e3e0821
VZ
242
243#ifdef __WIN32__
0d0512bd 244 HANDLE handle = (HANDLE)m_image->GetHandle();
d8bffc13
MB
245 LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ;
246 ::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) |
247 ( m_isIcon ? SS_ICON : SS_BITMAP ) );
0d0512bd 248 ::SendMessage(GetHwnd(), STM_SETIMAGE,
9e3e0821
VZ
249 m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
250#endif // Win32
251
252 if ( ImageIsOk() )
253 {
4004f41e
VZ
254 int width = image->GetWidth(),
255 height = image->GetHeight();
9e3e0821
VZ
256 if ( width && height )
257 {
7c545786
VZ
258 w = width;
259 h = height;
260
0d0512bd 261 ::MoveWindow(GetHwnd(), x, y, width, height, FALSE);
9e3e0821
VZ
262 }
263 }
264
0d0512bd
VZ
265 RECT rect;
266 rect.left = x;
267 rect.top = y;
268 rect.right = x + w;
269 rect.bottom = y + h;
57f4f925 270 ::InvalidateRect(GetHwndOf(GetParent()), &rect, TRUE);
2bda0e17
KB
271}
272
1e6feb95 273#endif // wxUSE_STATBMP
6aa01033 274