]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbmp.cpp
Rotated text patch from Hans-Joachim Baader (with some corrections)
[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$
8// Copyright: (c) Julian Smart and Markus Holzem
fd3f686c 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
9e3e0821
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
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
0c589ad0
BM
31#include "wx/window.h"
32#include "wx/msw/private.h"
33
2bda0e17 34#ifndef WX_PRECOMP
0c589ad0 35 #include "wx/icon.h"
9e3e0821 36 #include "wx/statbmp.h"
2bda0e17
KB
37#endif
38
39#include <stdio.h>
2bda0e17 40
9e3e0821
VZ
41// ---------------------------------------------------------------------------
42// macors
43// ---------------------------------------------------------------------------
44
2bda0e17 45#if !USE_SHARED_LIBRARY
9e3e0821 46 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
2bda0e17
KB
47#endif
48
9e3e0821
VZ
49// ===========================================================================
50// implementation
51// ===========================================================================
52
53// ---------------------------------------------------------------------------
54// wxStaticBitmap
55// ---------------------------------------------------------------------------
2bda0e17 56
debe6624 57bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
0d0512bd 58 const wxGDIImage& bitmap,
9e3e0821
VZ
59 const wxPoint& pos,
60 const wxSize& size,
61 long style,
62 const wxString& name)
2bda0e17 63{
9e3e0821
VZ
64 Init();
65
66 SetName(name);
67 if (parent)
68 parent->AddChild(this);
69
70 m_backgroundColour = parent->GetBackgroundColour() ;
71 m_foregroundColour = parent->GetForegroundColour() ;
72
73 if ( id == -1 )
74 m_windowId = (int)NewControlId();
75 else
76 m_windowId = id;
77
78 int x = pos.x;
79 int y = pos.y;
80 int width = size.x;
81 int height = size.y;
82
83 m_windowStyle = style;
84
85 m_isIcon = bitmap.IsKindOf(CLASSINFO(wxIcon));
86
87#ifdef __WIN32__
88 // create a static control with either SS_BITMAP or SS_ICON style depending
89 // on what we have here
223d09f6 90 const wxChar *classname = wxT("STATIC");
9e3e0821
VZ
91 int winstyle = m_isIcon ? SS_ICON : SS_BITMAP;
92#else // Win16
223d09f6 93 const wxChar *classname = wxT("BUTTON");
58a33cb4 94 int winstyle = BS_OWNERDRAW;
9e3e0821
VZ
95#endif // Win32
96
97 m_hWnd = (WXHWND)::CreateWindow
98 (
99 classname,
223d09f6 100 wxT(""),
9e3e0821
VZ
101 winstyle | WS_CHILD | WS_VISIBLE,
102 0, 0, 0, 0,
103 (HWND)parent->GetHWND(),
104 (HMENU)m_windowId,
105 wxGetInstance(),
106 NULL
107 );
108
223d09f6 109 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
9e3e0821 110
0d0512bd 111 SetImage(bitmap);
9e3e0821
VZ
112
113 // Subclass again for purposes of dialog editing mode
114 SubclassWin(m_hWnd);
115
116 SetFont(GetParent()->GetFont());
117
118 SetSize(x, y, width, height);
119
120 return TRUE;
121}
122
123bool wxStaticBitmap::ImageIsOk() const
124{
0d0512bd 125 return m_image && m_image->Ok();
9e3e0821
VZ
126}
127
128void wxStaticBitmap::Free()
129{
0d0512bd 130 delete m_image;
9e3e0821 131
0d0512bd 132 m_image = NULL;
2bda0e17
KB
133}
134
f68586e5 135wxSize wxStaticBitmap::DoGetBestSize() const
2bda0e17 136{
4438caf4
VZ
137 // reuse the current size (as wxWindow does) instead of using some
138 // arbitrary default size (as wxControl, our immediate base class, does)
139 return wxWindow::DoGetBestSize();
2bda0e17
KB
140}
141
0d0512bd 142void wxStaticBitmap::SetImage(const wxGDIImage& bitmap)
2bda0e17 143{
9e3e0821
VZ
144 Free();
145
146 m_isIcon = bitmap.IsKindOf(CLASSINFO(wxIcon));
147 if ( m_isIcon )
0d0512bd 148 m_image = new wxIcon((const wxIcon&)bitmap);
9e3e0821 149 else
0d0512bd 150 m_image = new wxBitmap((const wxBitmap &)bitmap);
9e3e0821
VZ
151
152 int x, y;
153 int w, h;
154 GetPosition(&x, &y);
155 GetSize(&w, &h);
9e3e0821
VZ
156
157#ifdef __WIN32__
0d0512bd
VZ
158 HANDLE handle = (HANDLE)m_image->GetHandle();
159 ::SendMessage(GetHwnd(), STM_SETIMAGE,
9e3e0821
VZ
160 m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
161#endif // Win32
162
163 if ( ImageIsOk() )
164 {
165 int width = bitmap.GetWidth(),
166 height = bitmap.GetHeight();
167 if ( width && height )
168 {
7c545786
VZ
169 w = width;
170 h = height;
171
0d0512bd 172 ::MoveWindow(GetHwnd(), x, y, width, height, FALSE);
9e3e0821
VZ
173 }
174 }
175
0d0512bd
VZ
176 RECT rect;
177 rect.left = x;
178 rect.top = y;
179 rect.right = x + w;
180 rect.bottom = y + h;
181 InvalidateRect(GetHwndOf(GetParent()), &rect, TRUE);
2bda0e17
KB
182}
183
9e3e0821
VZ
184// under Win32 we use the standard static control style for this
185#ifdef __WIN16__
2bda0e17
KB
186bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT *item)
187{
2bda0e17
KB
188 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item;
189
9e3e0821 190 wxBitmap* bitmap = m_image.bitmap;
fd3f686c
VZ
191 if ( !bitmap->Ok() )
192 return FALSE;
2bda0e17 193
fd3f686c
VZ
194 HDC hDC = lpDIS->hDC;
195 HDC memDC = ::CreateCompatibleDC(hDC);
2bda0e17 196
fd3f686c 197 HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP());
2bda0e17 198
fd3f686c
VZ
199 if (!old)
200 return FALSE;
2bda0e17 201
9e3e0821
VZ
202 int x = lpDIS->rcItem.left;
203 int y = lpDIS->rcItem.top;
204 int width = lpDIS->rcItem.right - x;
205 int height = lpDIS->rcItem.bottom - y;
2bda0e17 206
fd3f686c
VZ
207 // Centre the bitmap in the control area
208 int x1 = (int) (x + ((width - bitmap->GetWidth()) / 2));
209 int y1 = (int) (y + ((height - bitmap->GetHeight()) / 2));
2bda0e17 210
fd3f686c 211 ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY);
2bda0e17 212
fd3f686c 213 ::SelectObject(memDC, old);
2bda0e17
KB
214
215 ::DeleteDC(memDC);
216
217 return TRUE;
218}
219
9e3e0821
VZ
220long wxStaticBitmap::MSWWindowProc(WXUINT nMsg,
221 WXWPARAM wParam,
222 WXLPARAM lParam)
2bda0e17 223{
9e3e0821
VZ
224 // Ensure that static items get messages. Some controls don't like this
225 // message to be intercepted (e.g. RichEdit), hence the tests.
226 if ( nMsg == WM_NCHITTEST )
227 return (long)HTCLIENT;
2bda0e17 228
9e3e0821 229 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
2bda0e17 230}
9e3e0821 231#endif // Win16