]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/statbmp.cpp
attempt to fix a rare crash which happens when changing the number of columns in...
[wxWidgets.git] / src / os2 / statbmp.cpp
... / ...
CommitLineData
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
33IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
34
35// ---------------------------------------------------------------------------
36// wxStaticBitmap
37// ---------------------------------------------------------------------------
38
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)
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 int nWinstyle = m_bIsIcon ? SS_ICON : SS_BITMAP;
75
76 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
77 ,WC_STATIC
78 ,rName.c_str()
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(*wxSMALL_FONT);
95 SetSize(nX, nY, nWidth, nHeight);
96 return(FALSE);
97}
98
99bool wxStaticBitmap::ImageIsOk() const
100{
101 return(m_pImage && m_pImage->Ok());
102}
103
104void wxStaticBitmap::Free()
105{
106 delete m_pImage;
107 m_pImage = NULL;
108}
109
110wxSize 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
117void 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
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