]> git.saurik.com Git - wxWidgets.git/blob - src/os2/statbox.cpp
Added alpha blending in prep for FreeType text to canvas.
[wxWidgets.git] / src / os2 / statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: statbox.cpp
3 // Purpose: wxStaticBox
4 // Author: David Webster
5 // Modified by:
6 // Created: ??/??/98
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/app.h"
20 #include "wx/dcclient.h"
21 #endif
22
23 #include "wx/statbox.h"
24
25 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
26
27 BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
28 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
29 END_EVENT_TABLE()
30
31
32 /*
33 * Group box
34 */
35
36 bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
37 const wxString& label,
38 const wxPoint& pos,
39 const wxSize& size,
40 long style,
41 const wxString& name)
42 {
43 SetName(name);
44
45 if (parent) parent->AddChild(this);
46
47 SetBackgroundColour(parent->GetBackgroundColour()) ;
48 SetForegroundColour(parent->GetForegroundColour()) ;
49
50 if ( id == -1 )
51 m_windowId = (int)NewControlId();
52 else
53 m_windowId = id;
54
55 int x = pos.x;
56 int y = pos.y;
57 int width = size.x;
58 int height = size.y;
59
60 m_windowStyle = style;
61
62 // TODO:
63 /*
64 long msStyle = BS_GROUPBOX | WS_CHILD | WS_VISIBLE ; // GROUP_FLAGS;
65
66 bool want3D;
67 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
68
69 HWND wx_button =
70 CreateWindowEx(exStyle, wxT("BUTTON"), (const wxChar *)label, msStyle,
71 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
72 wxGetInstance(), NULL);
73 #if wxUSE_CTL3D
74 if (want3D)
75 {
76 Ctl3dSubclassCtl(wx_button);
77 m_useCtl3D = TRUE;
78 }
79 #endif
80
81 m_hWnd = (WXHWND)wx_button;
82
83 // Subclass again for purposes of dialog editing mode
84 SubclassWin(GetHWND());
85
86 SetFont(parent->GetFont());
87
88 SetSize(x, y, width, height);
89 ShowWindow(wx_button, SW_SHOW);
90 */
91 return FALSE;
92 }
93
94 wxSize wxStaticBox::DoGetBestSize() const
95 {
96 int cx, cy;
97 wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont());
98
99 int wBox;
100 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
101
102 wBox += 3*cx;
103 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
104
105 return wxSize(wBox, hBox);
106 }
107
108 WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
109 WXUINT message,
110 WXWPARAM wParam,
111 WXLPARAM lParam)
112 {
113 // TODO:
114 /*
115 if (GetParent()->GetTransparentBackground())
116 SetBkMode((HDC) pDC, TRANSPARENT);
117 else
118 SetBkMode((HDC) pDC, OPAQUE);
119
120 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
121 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
122
123 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
124
125 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
126 // has a zero usage count.
127 // backgroundBrush->RealizeResource();
128 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
129 */
130 return (WXHBRUSH)0;
131 }
132
133 // Shouldn't erase the whole window, since the static box must only paint its
134 // outline.
135 void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
136 {
137 // If we don't have this (call Default()), we don't paint the background properly.
138 // If we do have this, we seem to overwrite enclosed controls.
139 // Is it the WS_CLIPCHILDREN style that's causing the problems?
140 // Probably - without this style, the background of the window will show through,
141 // so the control doesn't have to paint it. The window background will always be
142 // painted before all other controls, therefore there are no problems with
143 // controls being hidden by the static box.
144 // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better.
145 // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel.
146 // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass
147 // this information from arbitrary wxWindow derivatives, and it depends on what you wish to
148 // do with the windows.
149 // Alternatively, just make sure that wxStaticBox is always at the back! There are probably
150 // few other circumstances where it matters about child clipping. But what about painting onto
151 // to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
152 wxWindow *parent = GetParent();
153 // TODO:
154 /*
155 if ( parent && parent->GetHWND() && (::GetWindowLong((HWND) parent->GetHWND(), GWL_STYLE) & WS_CLIPCHILDREN) )
156 {
157 // TODO: May in fact need to generate a paint event for inside this
158 // control's rectangle, otherwise all controls are going to be clipped -
159 // ugh.
160 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
161 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
162
163 RECT rect;
164
165 ::GetClientRect(GetHwnd(), &rect);
166 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
167 ::DeleteObject(hBrush);
168 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
169 }
170 else
171 {
172 event.Skip();
173 }
174 */
175 }
176
177 MRESULT wxStaticBox::OS2WindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
178 {
179 // TODO:
180 /*
181 if ( nMsg == WM_NCHITTEST)
182 {
183 int xPos = LOWORD(lParam); // horizontal position of cursor
184 int yPos = HIWORD(lParam); // vertical position of cursor
185
186 // ScreenToClient(&xPos, &yPos);
187
188 // Make sure you can drag by the top of the groupbox, but let
189 // other (enclosed) controls get mouse events also
190 if (yPos < 10)
191 return (long)HTCLIENT;
192 }
193 */
194
195 return wxControl::OS2WindowProc(nMsg, wParam, lParam);
196 }
197
198