]> git.saurik.com Git - wxWidgets.git/blame - src/os2/statbmp.cpp
use wxLogFatalError, not wxFatalError
[wxWidgets.git] / src / os2 / statbmp.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: statbmp.cpp
3// Purpose: wxStaticBitmap
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
3b9e3455 6// Created: 11/27/99
0e320a79 7// RCS-ID: $Id$
409c9842
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
aa213887
SN
12#ifdef __GNUG__
13#pragma implementation "statbmp.h"
14#endif
15
409c9842
DW
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"
0e320a79
DW
25#endif
26
409c9842
DW
27#include <stdio.h>
28
29// ---------------------------------------------------------------------------
30// macors
31// ---------------------------------------------------------------------------
0e320a79 32
0e320a79 33IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
0e320a79 34
409c9842
DW
35// ---------------------------------------------------------------------------
36// wxStaticBitmap
37// ---------------------------------------------------------------------------
0e320a79 38
3b9e3455
DW
39bool 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)
0e320a79 48{
04701dd9
DW
49 Init();
50
3b9e3455 51 SetName(rName);
43543d98
DW
52 if (pParent)
53 pParent->AddChild(this);
0e320a79 54
43543d98
DW
55 m_backgroundColour = pParent->GetBackgroundColour() ;
56 m_foregroundColour = pParent->GetForegroundColour() ;
04701dd9 57
43543d98 58 if (nId == -1)
409c9842 59 m_windowId = (int)NewControlId();
0e320a79 60 else
3b9e3455 61 m_windowId = nId;
0e320a79 62
3b9e3455 63 m_windowStyle = lStyle;
0e320a79 64
43543d98
DW
65 int nX= rPos.x;
66 int nY = rPos.y;
67 int nWidth = rSize.x;
68 int nHeight = rSize.y;
04701dd9 69
3b9e3455 70 m_windowStyle = lStyle;
04701dd9 71
3b9e3455 72 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
04701dd9 73
43543d98 74 int nWinstyle = m_bIsIcon ? SS_ICON : SS_BITMAP;
3b9e3455 75
43543d98 76 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
d697657f
DW
77 ,WC_STATIC
78 ,rName.c_str()
3b9e3455
DW
79 ,nWinstyle | WS_VISIBLE
80 ,0,0,0,0
81 ,pParent->GetHWND()
82 ,HWND_TOP
83 ,m_windowId
84 ,NULL
85 ,NULL
86 );
87
04701dd9
DW
88 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") );
89
3b9e3455 90 SetImage(rBitmap);
04701dd9
DW
91
92 // Subclass again for purposes of dialog editing mode
93 SubclassWin(m_hWnd);
e58dab20 94 SetFont(*wxSMALL_FONT);
3b9e3455
DW
95 SetSize(nX, nY, nWidth, nHeight);
96 return(FALSE);
0e320a79
DW
97}
98
409c9842 99bool wxStaticBitmap::ImageIsOk() const
0e320a79 100{
43543d98 101 return(m_pImage && m_pImage->Ok());
409c9842
DW
102}
103
104void wxStaticBitmap::Free()
105{
3b9e3455
DW
106 delete m_pImage;
107 m_pImage = NULL;
409c9842
DW
108}
109
e78c4d50 110wxSize wxStaticBitmap::DoGetBestSize() const
409c9842
DW
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();
0e320a79
DW
115}
116
3b9e3455
DW
117void wxStaticBitmap::SetImage(
118 const wxGDIImage& rBitmap
119)
0e320a79 120{
409c9842
DW
121 Free();
122
3b9e3455
DW
123 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
124 if (m_bIsIcon)
125 m_pImage = new wxIcon((const wxIcon&)rBitmap);
409c9842 126 else
3b9e3455
DW
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);
43543d98 135 GetSize(&nW, &nH);
3b9e3455
DW
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);
0e320a79
DW
171}
172
32334453
DW
173MRESULT wxStaticBitmap::OS2WindowProc(
174 WXUINT uMsg
175, WXWPARAM wParam
176, WXLPARAM lParam
177)
178{
179 return wxWindow::OS2WindowProc(uMsg, wParam, lParam);
180} // end of wxStaticBitmap::OS2WindowProc