]> git.saurik.com Git - wxWidgets.git/blame - src/os2/statbmp.cpp
added default ctor for wxDirDialog
[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
409c9842
DW
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"
0e320a79
DW
21#endif
22
409c9842
DW
23#include <stdio.h>
24
25// ---------------------------------------------------------------------------
26// macors
27// ---------------------------------------------------------------------------
0e320a79
DW
28
29#if !USE_SHARED_LIBRARY
30IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
31#endif
32
409c9842
DW
33// ---------------------------------------------------------------------------
34// wxStaticBitmap
35// ---------------------------------------------------------------------------
0e320a79 36
3b9e3455
DW
37bool 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)
0e320a79 46{
04701dd9
DW
47 Init();
48
3b9e3455 49 SetName(rName);
43543d98
DW
50 if (pParent)
51 pParent->AddChild(this);
0e320a79 52
43543d98
DW
53 m_backgroundColour = pParent->GetBackgroundColour() ;
54 m_foregroundColour = pParent->GetForegroundColour() ;
04701dd9 55
43543d98 56 if (nId == -1)
409c9842 57 m_windowId = (int)NewControlId();
0e320a79 58 else
3b9e3455 59 m_windowId = nId;
0e320a79 60
3b9e3455 61 m_windowStyle = lStyle;
0e320a79 62
43543d98
DW
63 int nX= rPos.x;
64 int nY = rPos.y;
65 int nWidth = rSize.x;
66 int nHeight = rSize.y;
04701dd9 67
3b9e3455 68 m_windowStyle = lStyle;
04701dd9 69
3b9e3455 70 m_bIsIcon = rBitmap.IsKindOf(CLASSINFO(wxIcon));
04701dd9 71
0e320a79 72 // TODO: create static bitmap control
3b9e3455 73 const wxChar* zClassname = wxT("WX_STATIC");
43543d98 74 int nWinstyle = m_bIsIcon ? SS_ICON : SS_BITMAP;
3b9e3455 75
43543d98 76 m_hWnd = (WXHWND)::WinCreateWindow( pParent->GetHWND()
3b9e3455
DW
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
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);
04701dd9 94 SetFont(GetParent()->GetFont());
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