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