]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbox.cpp
Removed erroneous copyright names and corrected licence spelling
[wxWidgets.git] / src / msw / statbox.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
3f2711d5 2// Name: msw/statbox.cpp
2bda0e17
KB
3// Purpose: wxStaticBox
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c49245f8 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
3f2711d5
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
3f2711d5 21 #pragma implementation "statbox.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
3f2711d5 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
1e6feb95
VZ
31#if wxUSE_STATBOX
32
2bda0e17 33#ifndef WX_PRECOMP
3f2711d5
VZ
34 #include "wx/app.h"
35 #include "wx/dcclient.h"
2bda0e17
KB
36#endif
37
38#include "wx/statbox.h"
2bda0e17 39
3f2711d5
VZ
40#include "wx/msw/private.h"
41
42// ----------------------------------------------------------------------------
43// wxWin macros
44// ----------------------------------------------------------------------------
45
5bd3a2da 46IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
2bda0e17 47
3f2711d5
VZ
48// ============================================================================
49// implementation
50// ============================================================================
51
52// ----------------------------------------------------------------------------
53// wxStaticBox
54// ----------------------------------------------------------------------------
55
56bool wxStaticBox::Create(wxWindow *parent,
57 wxWindowID id,
58 const wxString& label,
59 const wxPoint& pos,
60 const wxSize& size,
61 long style,
62 const wxString& name)
2bda0e17 63{
11b6a93b 64 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
3f2711d5 65 return FALSE;
2bda0e17 66
48c1b6f9
VZ
67 // as wxStaticBox doesn't draw its own background, we make it transparent
68 // to force redrawing its background which could have been overwritten by
69 // the other controls inside it
70 //
71 // FIXME: I still think that it isn't the right solution because the static
72 // boxes shouldn't have to be transparent if the redrawing was done
73 // right elsewhere - who ever had to make them transparent in non
74 // wxWindows programs, after all? But for now it does fix a serious
75 // problem (try resizing the sizers test screen in the layout sample
76 // after removing WS_EX_TRANSPARENT bit) and so let's use it until
77 // we fix the real underlying problem
78 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX, pos, size, label,
79 WS_EX_TRANSPARENT) )
3f2711d5 80 return FALSE;
2bda0e17 81
92b0a2a1
VZ
82 // to be transparent we should have the same colour as the parent as well
83 SetBackgroundColour(GetParent()->GetBackgroundColour());
84
3f2711d5 85 return TRUE;
2bda0e17
KB
86}
87
f68586e5 88wxSize wxStaticBox::DoGetBestSize() const
2bda0e17 89{
4438caf4
VZ
90 int cx, cy;
91 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
2bda0e17 92
4438caf4
VZ
93 int wBox;
94 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
2bda0e17 95
4438caf4
VZ
96 wBox += 3*cx;
97 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17 98
4438caf4
VZ
99 return wxSize(wBox, hBox);
100}
2bda0e17 101
2bda0e17
KB
102long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
103{
222594ea 104 switch ( nMsg )
1c089c47 105 {
222594ea
VZ
106 case WM_NCHITTEST:
107 // FIXME: this hack is specific to dialog ed, shouldn't it be
108 // somehow disabled during normal operation?
109 {
110 int xPos = LOWORD(lParam); // horizontal position of cursor
111 int yPos = HIWORD(lParam); // vertical position of cursor
112
113 ScreenToClient(&xPos, &yPos);
114
115 // Make sure you can drag by the top of the groupbox, but let
116 // other (enclosed) controls get mouse events also
117 if ( yPos < 10 )
118 return (long)HTCLIENT;
119 }
120 break;
121
222594ea
VZ
122 case WM_ERASEBKGND:
123 // prevent wxControl from processing this message because it will
124 // erase the background incorrectly and there is no way for us to
125 // override this at wxWin event level (if we do process the event,
126 // we don't know how to do it properly - paint the background
127 // without painting over other controls - and if we don't,
128 // wxControl still gets it)
129 return MSWDefWindowProc(nMsg, wParam, lParam);
1c089c47 130 }
2bda0e17 131
42e69d6b 132 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
2bda0e17
KB
133}
134
1e6feb95 135#endif // wxUSE_STATBOX