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