]> git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
removed a condition (l. 124) that always eval to true
[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 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
30
31 // ---------------------------------------------------------------------------
32 // wxStaticBitmap
33 // ---------------------------------------------------------------------------
34
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 )
44 {
45 Init();
46
47 SetName(rName);
48 if (pParent)
49 pParent->AddChild(this);
50
51 m_backgroundColour = pParent->GetBackgroundColour() ;
52 m_foregroundColour = pParent->GetForegroundColour() ;
53
54 if (nId == -1)
55 m_windowId = (int)NewControlId();
56 else
57 m_windowId = nId;
58
59 m_windowStyle = lStyle;
60
61 int nX= rPos.x;
62 int nY = rPos.y;
63 int nWidth = rSize.x;
64 int nHeight = rSize.y;
65
66 m_windowStyle = lStyle;
67
68 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
69
70 // TODO: create static bitmap control
71 const wxChar* zClassname = wxT("WX_STATIC");
72 int nWinstyle = m_bIsIcon ? SS_ICON : SS_BITMAP;
73
74 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
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
86 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
87
88 SetImage(rBitmap);
89
90 // Subclass again for purposes of dialog editing mode
91 SubclassWin(m_hWnd);
92 SetFont(GetParent()->GetFont());
93 SetSize(nX, nY, nWidth, nHeight);
94 return(FALSE);
95 }
96
97 bool wxStaticBitmap::ImageIsOk() const
98 {
99 return(m_pImage && m_pImage->Ok());
100 }
101
102 void wxStaticBitmap::Free()
103 {
104 delete m_pImage;
105 m_pImage = NULL;
106 }
107
108 wxSize wxStaticBitmap::DoGetBestSize() const
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();
113 }
114
115 void wxStaticBitmap::SetImage(
116 const wxGDIImage& rBitmap
117 )
118 {
119 Free();
120
121 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
122 if (m_bIsIcon)
123 m_pImage = new wxIcon((const wxIcon&)rBitmap);
124 else
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);
133 GetSize(&nW, &nH);
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);
169 }
170