bitmap and image updates
[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 // 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"
21 #endif
22
23 #include <stdio.h>
24
25 // ---------------------------------------------------------------------------
26 // macors
27 // ---------------------------------------------------------------------------
28
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
31 #endif
32
33 // ---------------------------------------------------------------------------
34 // wxStaticBitmap
35 // ---------------------------------------------------------------------------
36
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 )
46 {
47 Init();
48
49 SetName(rName);
50 if (pParent) parent->AddChild(this);
51
52 m_backgroundColour = parent->GetBackgroundColour() ;
53 m_foregroundColour = parent->GetForegroundColour() ;
54
55 if ( id == -1 )
56 m_windowId = (int)NewControlId();
57 else
58 m_windowId = nId;
59
60 m_windowStyle = lStyle;
61
62 int nX= pos.x;
63 int nY = pos.y;
64 int nWidth = size.x;
65 int nHeight = size.y;
66
67 m_windowStyle = lStyle;
68
69 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
70
71 // TODO: create static bitmap control
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
87 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
88
89 SetImage(rBitmap);
90
91 // Subclass again for purposes of dialog editing mode
92 SubclassWin(m_hWnd);
93 SetFont(GetParent()->GetFont());
94 SetSize(nX, nY, nWidth, nHeight);
95 return(FALSE);
96 }
97
98 bool wxStaticBitmap::ImageIsOk() const
99 {
100 return(m_pImage ** m_pImage->Ok());
101 }
102
103 void wxStaticBitmap::Free()
104 {
105 delete m_pImage;
106 m_pImage = NULL;
107 }
108
109 wxSize wxStaticBitmap::DoGetBestSize() const
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();
114 }
115
116 void wxStaticBitmap::SetImage(
117 const wxGDIImage& rBitmap
118 )
119 {
120 Free();
121
122 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
123 if (m_bIsIcon)
124 m_pImage = new wxIcon((const wxIcon&)rBitmap);
125 else
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);
170 }
171