]> git.saurik.com Git - wxWidgets.git/blob - src/msw/statbox.cpp
Added m_callback init.
[wxWidgets.git] / src / msw / statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/statbox.cpp
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
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "statbox.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/dcclient.h"
34 #endif
35
36 #include "wx/statbox.h"
37
38 #include "wx/msw/private.h"
39
40 // ----------------------------------------------------------------------------
41 // wxWin macros
42 // ----------------------------------------------------------------------------
43
44 #if !USE_SHARED_LIBRARY
45 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
46
47 BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
48 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
49 END_EVENT_TABLE()
50
51 #endif
52
53 // ============================================================================
54 // implementation
55 // ============================================================================
56
57 // ----------------------------------------------------------------------------
58 // wxStaticBox
59 // ----------------------------------------------------------------------------
60
61 bool wxStaticBox::Create(wxWindow *parent,
62 wxWindowID id,
63 const wxString& label,
64 const wxPoint& pos,
65 const wxSize& size,
66 long style,
67 const wxString& name)
68 {
69 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
70 return FALSE;
71
72 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX) )
73 return FALSE;
74
75 SetSize(pos.x, pos.y, size.x, size.y);
76
77 return TRUE;
78 }
79
80 wxSize wxStaticBox::DoGetBestSize()
81 {
82 int cx, cy;
83 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
84
85 int wBox;
86 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
87
88 wBox += 3*cx;
89 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
90
91 return wxSize(wBox, hBox);
92 }
93
94 WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
95 WXUINT message,
96 WXWPARAM wParam,
97 WXLPARAM lParam)
98 {
99 #if wxUSE_CTL3D
100 if ( m_useCtl3D )
101 {
102 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
103 return (WXHBRUSH) hbrush;
104 }
105 #endif // wxUSE_CTL3D
106
107 HDC hdc = (HDC)pDC;
108 if (GetParent()->GetTransparentBackground())
109 SetBkMode(hdc, TRANSPARENT);
110 else
111 SetBkMode(hdc, OPAQUE);
112
113 const wxColour& colBack = GetBackgroundColour();
114 ::SetBkColor(hdc, wxColourToRGB(colBack));
115 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
116
117 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
118
119 return (WXHBRUSH)brush->GetResourceHandle();
120 }
121
122 void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
123 {
124 // do nothing - the aim of having this function is to prevent
125 // wxControl::OnEraseBackground() to paint over the control inside the
126 // static box
127 }
128
129 long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
130 {
131 if ( nMsg == WM_NCHITTEST)
132 {
133 int xPos = LOWORD(lParam); // horizontal position of cursor
134 int yPos = HIWORD(lParam); // vertical position of cursor
135
136 ScreenToClient(&xPos, &yPos);
137
138 // Make sure you can drag by the top of the groupbox, but let
139 // other (enclosed) controls get mouse events also
140 if (yPos < 10)
141 return (long)HTCLIENT;
142 }
143
144 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
145 }
146