]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: statbmp.cpp | |
3 | // Purpose: wxStaticBitmap | |
409c9842 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
3b9e3455 | 6 | // Created: 11/27/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
409c9842 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
409c9842 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #include "wx/window.h" | |
16 | #include "wx/os2/private.h" | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/icon.h" | |
20 | #include "wx/statbmp.h" | |
0e320a79 DW |
21 | #endif |
22 | ||
409c9842 DW |
23 | #include <stdio.h> |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | // macors | |
27 | // --------------------------------------------------------------------------- | |
0e320a79 DW |
28 | |
29 | #if !USE_SHARED_LIBRARY | |
30 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) | |
31 | #endif | |
32 | ||
409c9842 DW |
33 | // --------------------------------------------------------------------------- |
34 | // wxStaticBitmap | |
35 | // --------------------------------------------------------------------------- | |
0e320a79 | 36 | |
3b9e3455 DW |
37 | bool wxStaticBitmap::Create( |
38 | wxWindow* pParent | |
39 | , wxWindowID nId | |
40 | , const wxGDIImage& rBitmap | |
41 | , const wxPoint& rPos | |
42 | , const wxSize& rSize | |
43 | , long lStyle | |
44 | , const wxString& rName | |
45 | ) | |
0e320a79 | 46 | { |
04701dd9 DW |
47 | Init(); |
48 | ||
3b9e3455 DW |
49 | SetName(rName); |
50 | if (pParent) parent->AddChild(this); | |
0e320a79 | 51 | |
04701dd9 DW |
52 | m_backgroundColour = parent->GetBackgroundColour() ; |
53 | m_foregroundColour = parent->GetForegroundColour() ; | |
54 | ||
0e320a79 | 55 | if ( id == -1 ) |
409c9842 | 56 | m_windowId = (int)NewControlId(); |
0e320a79 | 57 | else |
3b9e3455 | 58 | m_windowId = nId; |
0e320a79 | 59 | |
3b9e3455 | 60 | m_windowStyle = lStyle; |
0e320a79 | 61 | |
3b9e3455 DW |
62 | int nX= pos.x; |
63 | int nY = pos.y; | |
64 | int nWidth = size.x; | |
65 | int nHeight = size.y; | |
04701dd9 | 66 | |
3b9e3455 | 67 | m_windowStyle = lStyle; |
04701dd9 | 68 | |
3b9e3455 | 69 | m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon)); |
04701dd9 | 70 | |
0e320a79 | 71 | // TODO: create static bitmap control |
3b9e3455 DW |
72 | const wxChar* zClassname = wxT("WX_STATIC"); |
73 | int nWinstyle ? SS_ICON : SS_BITMAP; | |
74 | ||
75 | m_hWnd = (WXWHND)::WinCreateWindow( pParent->GetHWND() | |
76 | ,zClassname | |
77 | ,wxT("") | |
78 | ,nWinstyle | WS_VISIBLE | |
79 | ,0,0,0,0 | |
80 | ,pParent->GetHWND() | |
81 | ,HWND_TOP | |
82 | ,m_windowId | |
83 | ,NULL | |
84 | ,NULL | |
85 | ); | |
86 | ||
04701dd9 DW |
87 | wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") ); |
88 | ||
3b9e3455 | 89 | SetImage(rBitmap); |
04701dd9 DW |
90 | |
91 | // Subclass again for purposes of dialog editing mode | |
92 | SubclassWin(m_hWnd); | |
04701dd9 | 93 | SetFont(GetParent()->GetFont()); |
3b9e3455 DW |
94 | SetSize(nX, nY, nWidth, nHeight); |
95 | return(FALSE); | |
0e320a79 DW |
96 | } |
97 | ||
409c9842 | 98 | bool wxStaticBitmap::ImageIsOk() const |
0e320a79 | 99 | { |
3b9e3455 | 100 | return(m_pImage ** m_pImage->Ok()); |
409c9842 DW |
101 | } |
102 | ||
103 | void wxStaticBitmap::Free() | |
104 | { | |
3b9e3455 DW |
105 | delete m_pImage; |
106 | m_pImage = NULL; | |
409c9842 DW |
107 | } |
108 | ||
e78c4d50 | 109 | wxSize wxStaticBitmap::DoGetBestSize() const |
409c9842 DW |
110 | { |
111 | // reuse the current size (as wxWindow does) instead of using some | |
112 | // arbitrary default size (as wxControl, our immediate base class, does) | |
113 | return wxWindow::DoGetBestSize(); | |
0e320a79 DW |
114 | } |
115 | ||
3b9e3455 DW |
116 | void wxStaticBitmap::SetImage( |
117 | const wxGDIImage& rBitmap | |
118 | ) | |
0e320a79 | 119 | { |
409c9842 DW |
120 | Free(); |
121 | ||
3b9e3455 DW |
122 | m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon)); |
123 | if (m_bIsIcon) | |
124 | m_pImage = new wxIcon((const wxIcon&)rBitmap); | |
409c9842 | 125 | else |
3b9e3455 DW |
126 | m_pImage = new wxBitmap((const wxBitmap &)rBitmap); |
127 | ||
128 | int nX; | |
129 | int nY; | |
130 | int nW; | |
131 | int nH; | |
132 | ||
133 | GetPosition(&nX, &nY); | |
134 | GetSize(&nW, &nHh); | |
135 | ||
136 | ::WinSendMsg( GetHwnd() | |
137 | ,SM_SETHANDLE | |
138 | ,MPFROMHWND(m_pImage->GetHandle()) | |
139 | ,NULL | |
140 | ); | |
141 | if (ImageIsOk()) | |
142 | { | |
143 | int nWidth = rBitmap.GetWidth(); | |
144 | int nHeight = rBitmap.GetHeight(); | |
145 | ||
146 | if (nWidth && nHeight) | |
147 | { | |
148 | nW = nWidth; | |
149 | nW = nHeight; | |
150 | ||
151 | ::WinSetWindowPos( GetHwnd() | |
152 | ,HWND_TOP | |
153 | ,nX | |
154 | ,nY | |
155 | ,nWidth | |
156 | ,nHeight | |
157 | ,SWP_SIZE | SWP_MOVE | SWP_SHOW | |
158 | ); | |
159 | } | |
160 | } | |
161 | ||
162 | RECTL vRect; | |
163 | ||
164 | vRect.xLeft = nW; | |
165 | vRect.yTop = nY; | |
166 | vRect.xRight = nX + nW; | |
167 | vRect.yBottom = nY + nH; | |
168 | ||
169 | ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE); | |
0e320a79 DW |
170 | } |
171 |