]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbmp.cpp
Various small fixes
[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
12#ifdef __GNUG__
13#pragma implementation "statbmp.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/statbmp.h"
25#endif
26
27#include <stdio.h>
28#include "wx/msw/private.h"
29
30#if !USE_SHARED_LIBRARY
31IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
32#endif
33
34/*
35 * wxStaticBitmap
36 */
37
debe6624 38bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
2bda0e17
KB
39 const wxBitmap& bitmap,
40 const wxPoint& pos,
41 const wxSize& size,
debe6624 42 long style,
2bda0e17
KB
43 const wxString& name)
44{
45 m_messageBitmap = bitmap;
46 SetName(name);
47 if (parent) parent->AddChild(this);
48
fd71308f
JS
49 m_backgroundColour = parent->GetBackgroundColour() ;
50 m_foregroundColour = parent->GetForegroundColour() ;
2bda0e17
KB
51
52 if ( id == -1 )
fd3f686c 53 m_windowId = (int)NewControlId();
2bda0e17 54 else
fd3f686c 55 m_windowId = id;
2bda0e17
KB
56
57 int x = pos.x;
58 int y = pos.y;
59 int width = size.x;
60 int height = size.y;
61
62 if ( width < 0 && bitmap.Ok() )
fd3f686c 63 width = bitmap.GetWidth();
2bda0e17 64 if ( height < 0 && bitmap.Ok() )
fd3f686c 65 height = bitmap.GetHeight();
2bda0e17
KB
66
67 m_windowStyle = style;
68
69 // Use an ownerdraw button to produce a static bitmap, since there's
70 // no ownerdraw static.
71 // TODO: perhaps this should be a static item, with style SS_BITMAP.
257f1d9b
VZ
72 m_hWnd = (WXHWND)CreateWindow
73 (
74 "BUTTON",
75 "",
76 BS_OWNERDRAW | WS_TABSTOP | WS_CHILD | WS_VISIBLE,
77 0, 0, 0, 0,
78 (HWND)parent->GetHWND(),
79 (HMENU)m_windowId,
80 wxGetInstance(),
81 NULL
82 );
2bda0e17
KB
83
84 // Subclass again for purposes of dialog editing mode
257f1d9b 85 SubclassWin(m_hWnd);
9c331ded 86
c0ed460c 87 SetFont(GetParent()->GetFont());
9c331ded 88
2bda0e17
KB
89 SetSize(x, y, width, height);
90 return TRUE;
91}
92
debe6624 93void wxStaticBitmap::SetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17
KB
94{
95 int currentX, currentY;
96 GetPosition(&currentX, &currentY);
97 int x1 = x;
98 int y1 = y;
99
100 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
101 x1 = currentX;
102 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
103 y1 = currentY;
104
81d66cf3
JS
105 AdjustForParentClientOrigin(x1, y1, sizeFlags);
106
2bda0e17
KB
107 int actualWidth = width;
108 int actualHeight = height;
109
110 int ww, hh;
111 GetSize(&ww, &hh);
112
113 // If we're prepared to use the existing width, then...
114 if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
115 actualWidth = ww;
116 else actualWidth = width;
117
118 // If we're prepared to use the existing height, then...
119 if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
120 actualHeight = hh;
121 else actualHeight = height;
122
123 MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE);
2bda0e17
KB
124}
125
126void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
127{
128 m_messageBitmap = bitmap;
129
130 int x, y;
131 int w, h;
132 GetPosition(&x, &y);
133 GetSize(&w, &h);
134 RECT rect;
135 rect.left = x; rect.top = y; rect.right = x + w; rect.bottom = y + h;
136
137 if ( bitmap.Ok() )
fd3f686c 138 MoveWindow((HWND) GetHWND(), x, y, bitmap.GetWidth(), bitmap.GetHeight(),
2bda0e17
KB
139 FALSE);
140
141 InvalidateRect((HWND) GetParent()->GetHWND(), &rect, TRUE);
142}
143
144bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT *item)
145{
fd3f686c 146 long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE);
2432b92d 147#if defined(__WIN32__) && defined(SS_BITMAP)
fd3f686c
VZ
148 if ((style & 0xFF) == SS_BITMAP)
149 {
150 // Should we call Default() here?
151// Default();
152
153 // Let default procedure draw the bitmap, which is defined
154 // in the Windows resource.
155 return FALSE;
156 }
2bda0e17
KB
157#endif
158
159 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item;
160
fd3f686c
VZ
161 wxBitmap* bitmap = &m_messageBitmap;
162 if ( !bitmap->Ok() )
163 return FALSE;
2bda0e17 164
fd3f686c
VZ
165 HDC hDC = lpDIS->hDC;
166 HDC memDC = ::CreateCompatibleDC(hDC);
2bda0e17 167
fd3f686c 168 HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP());
2bda0e17 169
fd3f686c
VZ
170 if (!old)
171 return FALSE;
2bda0e17 172
2bda0e17
KB
173 int x = lpDIS->rcItem.left;
174 int y = lpDIS->rcItem.top;
175 int width = lpDIS->rcItem.right - x;
176 int height = lpDIS->rcItem.bottom - y;
177
fd3f686c
VZ
178 // Centre the bitmap in the control area
179 int x1 = (int) (x + ((width - bitmap->GetWidth()) / 2));
180 int y1 = (int) (y + ((height - bitmap->GetHeight()) / 2));
2bda0e17 181
fd3f686c 182 ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY);
2bda0e17 183
fd3f686c 184 ::SelectObject(memDC, old);
2bda0e17
KB
185
186 ::DeleteDC(memDC);
187
188 return TRUE;
189}
190
191long wxStaticBitmap::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
192{
193 // Ensure that static items get messages. Some controls don't like this
194 // message to be intercepted (e.g. RichEdit), hence the tests.
195 if (nMsg == WM_NCHITTEST)
196 return (long)HTCLIENT;
197
198 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
199}
200