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