]> git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
generate key events for Space/Enter in addition to the activate events, as wxMSW...
[wxWidgets.git] / src / os2 / statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: statbmp.cpp
3 // Purpose: wxStaticBitmap
4 // Author: David Webster
5 // Modified by:
6 // Created: 11/27/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
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 #include "wx/window.h"
20 #include "wx/os2/private.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/icon.h"
24 #include "wx/statbmp.h"
25 #endif
26
27 #include <stdio.h>
28
29 // ---------------------------------------------------------------------------
30 // macors
31 // ---------------------------------------------------------------------------
32
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
34
35 static wxGDIImage* ConvertImage(
36 const wxGDIImage& rBitmap
37 )
38 {
39 bool bIsIcon = rBitmap.IsKindOf( CLASSINFO(wxIcon) );
40
41 if(!bIsIcon )
42 {
43 wxASSERT_MSG( wxDynamicCast(&rBitmap, wxBitmap),
44 _T("not an icon and not a bitmap?") );
45
46 const wxBitmap& rBmp = (const wxBitmap&)rBitmap;
47 wxMask* pMask = rBmp.GetMask();
48
49 if (pMask && pMask->GetMaskBitmap())
50 {
51 wxIcon* pIcon = new wxIcon;
52
53 pIcon->CopyFromBitmap(rBmp);
54 return pIcon;
55 }
56 return new wxBitmap(rBmp);
57 }
58
59 // copying a bitmap is a cheap operation
60 return new wxIcon( (const wxIcon&)rBitmap );
61 } // end of ConvertImage
62
63 // ---------------------------------------------------------------------------
64 // wxStaticBitmap
65 // ---------------------------------------------------------------------------
66
67 bool wxStaticBitmap::Create(
68 wxWindow* pParent
69 , wxWindowID nId
70 , const wxGDIImage& rBitmap
71 , const wxPoint& rPos
72 , const wxSize& rSize
73 , long lStyle
74 , const wxString& rName
75 )
76 {
77 ERRORID vError;
78 wxString sError;
79
80 Init();
81
82 SetName(rName);
83 if (pParent)
84 pParent->AddChild(this);
85
86 if (nId == -1)
87 m_windowId = (int)NewControlId();
88 else
89 m_windowId = nId;
90
91 m_windowStyle = lStyle;
92
93 int nX= rPos.x;
94 int nY = rPos.y;
95 int nWidth = rSize.x;
96 int nHeight = rSize.y;
97 char zId[16];
98
99 m_windowStyle = lStyle;
100
101 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
102
103 //
104 // For now we only support an ICON
105 //
106 int nWinstyle = SS_ICON;
107
108 sprintf(zId, "#%d", rBitmap.GetId());
109 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
110 ,WC_STATIC
111 ,zId
112 ,nWinstyle | WS_VISIBLE
113 ,0,0,0,0
114 ,pParent->GetHWND()
115 ,HWND_TOP
116 ,m_windowId
117 ,NULL
118 ,NULL
119 );
120 if (!m_hWnd)
121 {
122 vError = ::WinGetLastError(wxGetInstance());
123 sError = wxPMErrorToStr(vError);
124 return FALSE;
125 }
126 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
127 m_pImage = ConvertImage(rBitmap);
128 m_pImage->SetHandle((WXHWND)::WinSendMsg(m_hWnd, SM_QUERYHANDLE, (MPARAM)0, (MPARAM)0));
129
130 // Subclass again for purposes of dialog editing mode
131 SubclassWin(m_hWnd);
132 return(TRUE);
133 } // end of wxStaticBitmap::Create
134
135 bool wxStaticBitmap::ImageIsOk() const
136 {
137 return(m_pImage && m_pImage->Ok());
138 }
139
140 void wxStaticBitmap::Free()
141 {
142 if (m_pImage)
143 delete m_pImage;
144 m_pImage = NULL;
145 } // end of wxStaticBitmap::Free
146
147 wxSize wxStaticBitmap::DoGetBestSize() const
148 {
149 //
150 // Reuse the current size (as wxWindow does) instead of using some
151 // arbitrary default size (as wxControl, our immediate base class, does)
152 //
153 return wxWindow::DoGetBestSize();
154 }
155
156 void wxStaticBitmap::SetImage(
157 const wxGDIImage& rBitmap
158 )
159 {
160 int nX = 0;
161 int nY = 0;
162 int nWidth = 0;
163 int nHeight = 0;
164
165 Free();
166 ::WinSendMsg( GetHwnd()
167 ,SM_SETHANDLE
168 ,MPFROMHWND(rBitmap.GetHandle())
169 ,NULL
170 );
171 m_pImage = ConvertImage(rBitmap);
172
173 GetPosition(&nX, &nY);
174 GetSize(&nWidth, &nHeight);
175
176 RECTL vRect;
177
178 vRect.xLeft = nX;
179 vRect.yTop = nY;
180 vRect.xRight = nX + nWidth;
181 vRect.yBottom = nY + nHeight;
182
183 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect, TRUE);
184 }
185
186 MRESULT wxStaticBitmap::OS2WindowProc(
187 WXUINT uMsg
188 , WXWPARAM wParam
189 , WXLPARAM lParam
190 )
191 {
192 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
193 } // end of wxStaticBitmap::OS2WindowProc