]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: statbmp.cpp | |
3 | // Purpose: wxStaticBitmap | |
409c9842 | 4 | // Author: David Webster |
0e320a79 DW |
5 | // Modified by: |
6 | // Created: ??/??/98 | |
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 | |
30 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) | |
31 | #endif | |
32 | ||
409c9842 DW |
33 | // --------------------------------------------------------------------------- |
34 | // wxStaticBitmap | |
35 | // --------------------------------------------------------------------------- | |
0e320a79 DW |
36 | |
37 | bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, | |
38 | const wxBitmap& bitmap, | |
39 | const wxPoint& pos, | |
40 | const wxSize& size, | |
41 | long style, | |
42 | const wxString& name) | |
43 | { | |
04701dd9 DW |
44 | Init(); |
45 | ||
0e320a79 DW |
46 | SetName(name); |
47 | if (parent) parent->AddChild(this); | |
48 | ||
04701dd9 DW |
49 | m_backgroundColour = parent->GetBackgroundColour() ; |
50 | m_foregroundColour = parent->GetForegroundColour() ; | |
51 | ||
0e320a79 | 52 | if ( id == -1 ) |
409c9842 | 53 | m_windowId = (int)NewControlId(); |
0e320a79 | 54 | else |
409c9842 | 55 | m_windowId = id; |
0e320a79 DW |
56 | |
57 | m_windowStyle = style; | |
58 | ||
04701dd9 DW |
59 | int x = pos.x; |
60 | int y = pos.y; | |
61 | int width = size.x; | |
62 | int height = size.y; | |
63 | ||
64 | m_windowStyle = style; | |
65 | ||
66 | m_isIcon = bitmap.IsKindOf(CLASSINFO(wxIcon)); | |
67 | ||
0e320a79 | 68 | // TODO: create static bitmap control |
04701dd9 DW |
69 | wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static bitmap") ); |
70 | ||
71 | SetBitmap(bitmap); | |
72 | ||
73 | // Subclass again for purposes of dialog editing mode | |
74 | SubclassWin(m_hWnd); | |
75 | ||
76 | SetFont(GetParent()->GetFont()); | |
77 | ||
78 | SetSize(x, y, width, height); | |
79 | ||
0e320a79 DW |
80 | return FALSE; |
81 | } | |
82 | ||
409c9842 | 83 | bool wxStaticBitmap::ImageIsOk() const |
0e320a79 | 84 | { |
409c9842 DW |
85 | if ( m_isIcon && m_image.icon ) |
86 | return m_image.icon->Ok(); | |
87 | else if ( m_image.bitmap ) | |
88 | return m_image.bitmap->Ok(); | |
89 | else | |
90 | return FALSE; | |
91 | } | |
92 | ||
93 | void wxStaticBitmap::Free() | |
94 | { | |
95 | if ( m_isIcon ) | |
96 | delete m_image.icon; | |
97 | else | |
98 | delete m_image.bitmap; | |
99 | ||
100 | m_image.icon = NULL; | |
101 | } | |
102 | ||
103 | wxSize wxStaticBitmap::DoGetBestSize() | |
104 | { | |
105 | // reuse the current size (as wxWindow does) instead of using some | |
106 | // arbitrary default size (as wxControl, our immediate base class, does) | |
107 | return wxWindow::DoGetBestSize(); | |
0e320a79 DW |
108 | } |
109 | ||
110 | void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) | |
111 | { | |
409c9842 DW |
112 | Free(); |
113 | ||
114 | m_isIcon = bitmap.IsKindOf(CLASSINFO(wxIcon)); | |
115 | if ( m_isIcon ) | |
116 | m_image.icon = new wxIcon((const wxIcon&)bitmap); | |
117 | else | |
118 | m_image.bitmap = new wxBitmap(bitmap); | |
119 | ||
120 | int x, y; | |
121 | int w, h; | |
122 | GetPosition(&x, &y); | |
123 | GetSize(&w, &h); | |
0e320a79 DW |
124 | |
125 | // TODO: redraw bitmap | |
126 | } | |
127 | ||
409c9842 | 128 |