]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/gizmos/statpict.cpp
This should work on SuSE and Mandrake icon themes.
[wxWidgets.git] / contrib / src / gizmos / statpict.cpp
CommitLineData
fca36d9a
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: statpict.cpp
3// Purpose: wxStaticPicture
4// Author: Wade Brainerd (wadeb@wadeb.com)
5// Modified by:
6// Created: 2003-05-01
7// RCS-ID:
8// Copyright: (c) Wade Brainerd
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13 #pragma implementation "statpict.h"
14#endif
15
0199503b 16#include "wx/wxprec.h"
fca36d9a
JS
17#include "wx/defs.h"
18
bce78bdc 19#include "wx/gizmos/statpict.h"
fca36d9a
JS
20#include "wx/dcclient.h"
21
22#if !USE_SHARED_LIBRARY
23IMPLEMENT_DYNAMIC_CLASS(wxStaticPicture, wxControl)
24#endif
25
26/*
27 * wxStaticPicture
28 */
29
30BEGIN_EVENT_TABLE(wxStaticPicture, wxControl)
31 EVT_PAINT(wxStaticPicture::OnPaint)
32END_EVENT_TABLE()
33
34bool wxStaticPicture::Create(wxWindow *parent, wxWindowID id,
35 const wxBitmap& bitmap,
36 const wxPoint& pos,
37 const wxSize& s,
38 long style,
39 const wxString& name)
40{
41 SetName(name);
42
43 wxSize size = s ;
44 if ( bitmap.Ok() )
45 {
46 if ( size.x == -1 )
47 size.x = bitmap.GetWidth() ;
48 if ( size.y == -1 )
49 size.y = bitmap.GetHeight() ;
50 }
51
52 m_backgroundColour = parent->GetBackgroundColour() ;
53 m_foregroundColour = parent->GetForegroundColour() ;
54
55 Bitmap = bitmap;
56 Align = 0;
57 Scale = 0;
58 ScaleX = ScaleY = 1;
59
60#ifndef __WXMSW__
61 LastScaleX = LastScaleY = -1;
62 if ( Bitmap.Ok() )
63 OriginalImage = Bitmap.ConvertToImage();
64#endif
65
66 if ( id == -1 )
67 m_windowId = (int)NewControlId();
68 else
69 m_windowId = id;
70
71 m_windowStyle = style;
72
73 bool ret = wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name );
74
75 SetBestSize( size ) ;
76
77 return ret;
78}
79
80void wxStaticPicture::SetBitmap( const wxBitmap& bmp )
81{
82 Bitmap = bmp;
83#ifndef __WXMSW__
84 if ( Bitmap.Ok() )
85 OriginalImage = Bitmap.ConvertToImage();
86 LastScaleX = LastScaleY = -1;
87#endif
88}
89
90void wxStaticPicture::OnPaint(wxPaintEvent& WXUNUSED(event))
91{
92 if ( !Bitmap.Ok() )
93 return;
94
95 wxPaintDC dc( this );
96 PrepareDC( dc );
97 dc.BeginDrawing();
98
99 wxSize sz = GetSize();
100 wxSize bmpsz( Bitmap.GetWidth(), Bitmap.GetHeight() );
101 float sx = 1.0f, sy = 1.0f;
102
103 if ( Scale & wxSCALE_UNIFORM )
104 {
105 float _sx = (float)sz.GetWidth() / (float)bmpsz.GetWidth();
106 float _sy = (float)sz.GetHeight() / (float)bmpsz.GetHeight();
107 sx = sy = _sx < _sy ? _sx : _sy;
108 }
109 else
110 if ( Scale & wxSCALE_CUSTOM )
111 {
112 sx = ScaleX;
113 sy = ScaleY;
114 }
115 else
116 {
117 if ( Scale & wxSCALE_HORIZONTAL )
118 sx = (float)sz.x/(float)bmpsz.x;
119 if ( Scale & wxSCALE_VERTICAL )
120 sy = (float)sz.y/(float)bmpsz.y;
121 }
122
123 bmpsz = wxSize( (int)(bmpsz.x*sx), (int)(bmpsz.y*sy) );
124
125 wxPoint pos( 0, 0 );
126
127 if ( Align & wxALIGN_CENTER_HORIZONTAL ) pos.x = (sz.x-bmpsz.x)/2;
128 else if ( Align & wxALIGN_RIGHT ) pos.x = sz.x-bmpsz.x;
129
130 if ( Align & wxALIGN_CENTER_VERTICAL ) pos.y = (sz.y-bmpsz.y)/2;
131 else if ( Align & wxALIGN_BOTTOM ) pos.y = sz.y-bmpsz.y;
132
133 if ( Scale )
134 {
135#ifdef __WXMSW__
136 double ux, uy;
137 dc.GetUserScale( &ux, &uy );
138 dc.SetUserScale( ux*sx, uy*sy );
139 dc.DrawBitmap( Bitmap, (int)((float)pos.x/sx), (int)((float)pos.y/sy) );
140 dc.SetUserScale( ux, uy );
141#else
142 if ( LastScaleX != sx || LastScaleY != sy )
143 {
144 LastScaleX = sx;
145 LastScaleY = sy;
146 ScaledBitmap = wxBitmap( OriginalImage.Scale( bmpsz.x, bmpsz.y ) );
147 }
148 dc.DrawBitmap( ScaledBitmap, pos.x, pos.y );
149#endif
150 }
151 else
152 dc.DrawBitmap( Bitmap, pos.x, pos.y );
153
154 dc.EndDrawing();
155}
156
157//WXDLLEXPORT_DATA(const wxChar *) wxStaticPictureNameStr = wxT("message");
158const wxChar * wxStaticPictureNameStr = wxT("message");