]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows license | |
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 | |
31 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) | |
32 | #endif | |
33 | ||
34 | /* | |
35 | * wxStaticBitmap | |
36 | */ | |
37 | ||
38 | bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, | |
39 | const wxBitmap& bitmap, | |
40 | const wxPoint& pos, | |
41 | const wxSize& size, | |
42 | long style, | |
43 | const wxString& name) | |
44 | { | |
45 | m_messageBitmap = bitmap; | |
46 | SetName(name); | |
47 | if (parent) parent->AddChild(this); | |
48 | ||
49 | m_backgroundColour = parent->GetDefaultBackgroundColour() ; | |
50 | m_foregroundColour = parent->GetDefaultForegroundColour() ; | |
51 | ||
52 | if ( id == -1 ) | |
53 | m_windowId = (int)NewControlId(); | |
54 | else | |
55 | m_windowId = id; | |
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() ) | |
63 | width = bitmap.GetWidth(); | |
64 | if ( height < 0 && bitmap.Ok() ) | |
65 | height = bitmap.GetHeight(); | |
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. | |
72 | HWND static_item = | |
73 | CreateWindowEx(0, "BUTTON", "", BS_OWNERDRAW | WS_TABSTOP | WS_CHILD, | |
74 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, | |
75 | wxGetInstance(), NULL); | |
76 | m_hWnd = (WXHWND) static_item; | |
77 | ||
78 | // Subclass again for purposes of dialog editing mode | |
79 | SubclassWin((WXHWND) static_item); | |
80 | SetSize(x, y, width, height); | |
81 | return TRUE; | |
82 | } | |
83 | ||
84 | void wxStaticBitmap::SetSize(int x, int y, int width, int height, int sizeFlags) | |
85 | { | |
86 | int currentX, currentY; | |
87 | GetPosition(¤tX, ¤tY); | |
88 | int x1 = x; | |
89 | int y1 = y; | |
90 | ||
91 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
92 | x1 = currentX; | |
93 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
94 | y1 = currentY; | |
95 | ||
96 | AdjustForParentClientOrigin(x1, y1, sizeFlags); | |
97 | ||
98 | int actualWidth = width; | |
99 | int actualHeight = height; | |
100 | ||
101 | int ww, hh; | |
102 | GetSize(&ww, &hh); | |
103 | ||
104 | // If we're prepared to use the existing width, then... | |
105 | if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH)) | |
106 | actualWidth = ww; | |
107 | else actualWidth = width; | |
108 | ||
109 | // If we're prepared to use the existing height, then... | |
110 | if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT)) | |
111 | actualHeight = hh; | |
112 | else actualHeight = height; | |
113 | ||
114 | MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE); | |
115 | } | |
116 | ||
117 | void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) | |
118 | { | |
119 | m_messageBitmap = bitmap; | |
120 | ||
121 | int x, y; | |
122 | int w, h; | |
123 | GetPosition(&x, &y); | |
124 | GetSize(&w, &h); | |
125 | RECT rect; | |
126 | rect.left = x; rect.top = y; rect.right = x + w; rect.bottom = y + h; | |
127 | ||
128 | if ( bitmap.Ok() ) | |
129 | MoveWindow((HWND) GetHWND(), x, y, bitmap.GetWidth(), bitmap.GetHeight(), | |
130 | FALSE); | |
131 | ||
132 | InvalidateRect((HWND) GetParent()->GetHWND(), &rect, TRUE); | |
133 | } | |
134 | ||
135 | bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT *item) | |
136 | { | |
137 | long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE); | |
138 | #ifdef __WIN32__ | |
139 | if ((style & 0xFF) == SS_BITMAP) | |
140 | { | |
141 | // Should we call Default() here? | |
142 | // Default(); | |
143 | ||
144 | // Let default procedure draw the bitmap, which is defined | |
145 | // in the Windows resource. | |
146 | return FALSE; | |
147 | } | |
148 | #endif | |
149 | ||
150 | LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item; | |
151 | ||
152 | wxBitmap* bitmap = &m_messageBitmap; | |
153 | if ( !bitmap->Ok() ) | |
154 | return FALSE; | |
155 | ||
156 | HDC hDC = lpDIS->hDC; | |
157 | HDC memDC = ::CreateCompatibleDC(hDC); | |
158 | ||
159 | HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP()); | |
160 | ||
161 | if (!old) | |
162 | return FALSE; | |
163 | ||
164 | RECT rect = lpDIS->rcItem; | |
165 | ||
166 | int x = lpDIS->rcItem.left; | |
167 | int y = lpDIS->rcItem.top; | |
168 | int width = lpDIS->rcItem.right - x; | |
169 | int height = lpDIS->rcItem.bottom - y; | |
170 | ||
171 | // Centre the bitmap in the control area | |
172 | int x1 = (int) (x + ((width - bitmap->GetWidth()) / 2)); | |
173 | int y1 = (int) (y + ((height - bitmap->GetHeight()) / 2)); | |
174 | ||
175 | ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY); | |
176 | ||
177 | ::SelectObject(memDC, old); | |
178 | ||
179 | ::DeleteDC(memDC); | |
180 | ||
181 | return TRUE; | |
182 | } | |
183 | ||
184 | long wxStaticBitmap::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | |
185 | { | |
186 | // Ensure that static items get messages. Some controls don't like this | |
187 | // message to be intercepted (e.g. RichEdit), hence the tests. | |
188 | if (nMsg == WM_NCHITTEST) | |
189 | return (long)HTCLIENT; | |
190 | ||
191 | return wxWindow::MSWWindowProc(nMsg, wParam, lParam); | |
192 | } | |
193 |