]>
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 | 28 | |
0e320a79 | 29 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) |
0e320a79 | 30 | |
409c9842 DW |
31 | // --------------------------------------------------------------------------- |
32 | // wxStaticBitmap | |
33 | // --------------------------------------------------------------------------- | |
0e320a79 | 34 | |
3b9e3455 DW |
35 | bool wxStaticBitmap::Create( |
36 | wxWindow* pParent | |
37 | , wxWindowID nId | |
38 | , const wxGDIImage& rBitmap | |
39 | , const wxPoint& rPos | |
40 | , const wxSize& rSize | |
41 | , long lStyle | |
42 | , const wxString& rName | |
43 | ) | |
0e320a79 | 44 | { |
04701dd9 DW |
45 | Init(); |
46 | ||
3b9e3455 | 47 | SetName(rName); |
43543d98 DW |
48 | if (pParent) |
49 | pParent->AddChild(this); | |
0e320a79 | 50 | |
43543d98 DW |
51 | m_backgroundColour = pParent->GetBackgroundColour() ; |
52 | m_foregroundColour = pParent->GetForegroundColour() ; | |
04701dd9 | 53 | |
43543d98 | 54 | if (nId == -1) |
409c9842 | 55 | m_windowId = (int)NewControlId(); |
0e320a79 | 56 | else |
3b9e3455 | 57 | m_windowId = nId; |
0e320a79 | 58 | |
3b9e3455 | 59 | m_windowStyle = lStyle; |
0e320a79 | 60 | |
43543d98 DW |
61 | int nX= rPos.x; |
62 | int nY = rPos.y; | |
63 | int nWidth = rSize.x; | |
64 | int nHeight = rSize.y; | |
04701dd9 | 65 | |
3b9e3455 | 66 | m_windowStyle = lStyle; |
04701dd9 | 67 | |
3b9e3455 | 68 | m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon)); |
04701dd9 | 69 | |
0e320a79 | 70 | // TODO: create static bitmap control |
3b9e3455 | 71 | const wxChar* zClassname = wxT("WX_STATIC"); |
43543d98 | 72 | int nWinstyle = m_bIsIcon ? SS_ICON : SS_BITMAP; |
3b9e3455 | 73 | |
43543d98 | 74 | m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND() |
3b9e3455 DW |
75 | ,zClassname |
76 | ,wxT("") | |
77 | ,nWinstyle | WS_VISIBLE | |
78 | ,0,0,0,0 | |
79 | ,pParent->GetHWND() | |
80 | ,HWND_TOP | |
81 | ,m_windowId | |
82 | ,NULL | |
83 | ,NULL | |
84 | ); | |
85 | ||
04701dd9 DW |
86 | wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") ); |
87 | ||
3b9e3455 | 88 | SetImage(rBitmap); |
04701dd9 DW |
89 | |
90 | // Subclass again for purposes of dialog editing mode | |
91 | SubclassWin(m_hWnd); | |
04701dd9 | 92 | SetFont(GetParent()->GetFont()); |
3b9e3455 DW |
93 | SetSize(nX, nY, nWidth, nHeight); |
94 | return(FALSE); | |
0e320a79 DW |
95 | } |
96 | ||
409c9842 | 97 | bool wxStaticBitmap::ImageIsOk() const |
0e320a79 | 98 | { |
43543d98 | 99 | return(m_pImage && m_pImage->Ok()); |
409c9842 DW |
100 | } |
101 | ||
102 | void wxStaticBitmap::Free() | |
103 | { | |
3b9e3455 DW |
104 | delete m_pImage; |
105 | m_pImage = NULL; | |
409c9842 DW |
106 | } |
107 | ||
e78c4d50 | 108 | wxSize wxStaticBitmap::DoGetBestSize() const |
409c9842 DW |
109 | { |
110 | // reuse the current size (as wxWindow does) instead of using some | |
111 | // arbitrary default size (as wxControl, our immediate base class, does) | |
112 | return wxWindow::DoGetBestSize(); | |
0e320a79 DW |
113 | } |
114 | ||
3b9e3455 DW |
115 | void wxStaticBitmap::SetImage( |
116 | const wxGDIImage& rBitmap | |
117 | ) | |
0e320a79 | 118 | { |
409c9842 DW |
119 | Free(); |
120 | ||
3b9e3455 DW |
121 | m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon)); |
122 | if (m_bIsIcon) | |
123 | m_pImage = new wxIcon((const wxIcon&)rBitmap); | |
409c9842 | 124 | else |
3b9e3455 DW |
125 | m_pImage = new wxBitmap((const wxBitmap &)rBitmap); |
126 | ||
127 | int nX; | |
128 | int nY; | |
129 | int nW; | |
130 | int nH; | |
131 | ||
132 | GetPosition(&nX, &nY); | |
43543d98 | 133 | GetSize(&nW, &nH); |
3b9e3455 DW |
134 | |
135 | ::WinSendMsg( GetHwnd() | |
136 | ,SM_SETHANDLE | |
137 | ,MPFROMHWND(m_pImage->GetHandle()) | |
138 | ,NULL | |
139 | ); | |
140 | if (ImageIsOk()) | |
141 | { | |
142 | int nWidth = rBitmap.GetWidth(); | |
143 | int nHeight = rBitmap.GetHeight(); | |
144 | ||
145 | if (nWidth && nHeight) | |
146 | { | |
147 | nW = nWidth; | |
148 | nW = nHeight; | |
149 | ||
150 | ::WinSetWindowPos( GetHwnd() | |
151 | ,HWND_TOP | |
152 | ,nX | |
153 | ,nY | |
154 | ,nWidth | |
155 | ,nHeight | |
156 | ,SWP_SIZE | SWP_MOVE | SWP_SHOW | |
157 | ); | |
158 | } | |
159 | } | |
160 | ||
161 | RECTL vRect; | |
162 | ||
163 | vRect.xLeft = nW; | |
164 | vRect.yTop = nY; | |
165 | vRect.xRight = nX + nW; | |
166 | vRect.yBottom = nY + nH; | |
167 | ||
168 | ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE); | |
0e320a79 DW |
169 | } |
170 |