]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticText
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "stattext.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/stattext.h"
28 #include "wx/msw/private.h"
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
35 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
36 const wxString
& label
,
43 if (parent
) parent
->AddChild(this);
45 SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ;
46 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
49 m_windowId
= (int)NewControlId();
58 m_windowStyle
= style
;
60 long msStyle
= WS_CHILD
|WS_VISIBLE
;
61 if (m_windowStyle
& wxALIGN_CENTRE
)
63 else if (m_windowStyle
& wxALIGN_RIGHT
)
68 // Even with extended styles, need to combine with WS_BORDER
69 // for them to look right.
70 if ((m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
71 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
74 HWND static_item
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), "STATIC", (const char *)label
,
76 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
77 wxGetInstance(), NULL
);
81 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
82 Ctl3dSubclassCtl(static_item);
86 m_hWnd
= (WXHWND
)static_item
;
88 SubclassWin((WXHWND
)static_item
);
90 SetFont(* parent
->GetFont());
91 SetSize(x
, y
, width
, height
);
95 void wxStaticText::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
97 int currentX
, currentY
;
98 GetPosition(¤tX
, ¤tY
);
102 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
104 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
107 int actualWidth
= width
;
108 int actualHeight
= height
;
114 ::GetWindowText((HWND
) GetHWND(), buf
, 300);
115 GetTextExtent(buf
, ¤t_width
, &cyf
, NULL
, NULL
,GetFont());
120 // If we're prepared to use the existing width, then...
121 if (width
== -1 && ((sizeFlags
& wxSIZE_AUTO_WIDTH
) != wxSIZE_AUTO_WIDTH
))
123 else if (width
== -1)
127 wxGetCharSize(GetHWND(), &cx
, &cy
,GetFont());
128 actualWidth
= (int)(current_width
+ cx
) ;
131 // If we're prepared to use the existing height, then...
132 if (height
== -1 && ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) != wxSIZE_AUTO_HEIGHT
))
134 else if (height
== -1)
136 actualHeight
= (int)(cyf
) ;
139 MoveWindow((HWND
) GetHWND(), x1
, y1
, actualWidth
, actualHeight
, TRUE
);
142 void wxStaticText::SetLabel(const wxString
& label
)
147 wxWindow
*parent
= GetParent();
148 GetWindowRect((HWND
) GetHWND(), &rect
);
150 // Since we now have the absolute screen coords,
151 // if there's a parent we must subtract its top left corner
157 ::ScreenToClient((HWND
) parent
->GetHWND(), &point
);
160 GetTextExtent(label
, &w
, &h
, NULL
, NULL
, GetFont());
161 MoveWindow((HWND
) GetHWND(), point
.x
, point
.y
, (int)(w
+ 10), (int)h
,
163 SetWindowText((HWND
) GetHWND(), (const char *)label
);
166 WXHBRUSH
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
167 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
173 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
175 if (hbrush != (HBRUSH) 0)
178 return (HBRUSH)MSWDefWindowProc(message, wParam, lParam);
183 if (GetParent()->GetTransparentBackground())
184 SetBkMode((HDC
) pDC
, TRANSPARENT
);
186 SetBkMode((HDC
) pDC
, OPAQUE
);
188 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
189 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
191 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
193 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
194 // has a zero usage count.
195 // backgroundBrush->RealizeResource();
196 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
199 long wxStaticText::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
201 // Ensure that static items get messages. Some controls don't like this
202 // message to be intercepted (e.g. RichEdit), hence the tests.
203 if (nMsg
== WM_NCHITTEST
)
204 return (long)HTCLIENT
;
206 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);