]>
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"
29 #include "wx/stattext.h"
30 #include "wx/msw/private.h"
33 #if !USE_SHARED_LIBRARY
34 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
37 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
38 const wxString
& label
,
45 if (parent
) parent
->AddChild(this);
47 SetBackgroundColour(parent
->GetBackgroundColour()) ;
48 SetForegroundColour(parent
->GetForegroundColour()) ;
51 m_windowId
= (int)NewControlId();
60 m_windowStyle
= style
;
62 long msStyle
= WS_CHILD
|WS_VISIBLE
;
63 if (m_windowStyle
& wxALIGN_CENTRE
)
65 else if (m_windowStyle
& wxALIGN_RIGHT
)
70 // Even with extended styles, need to combine with WS_BORDER
71 // for them to look right.
72 if ( wxStyleHasBorder(m_windowStyle
) )
75 m_hWnd
= (WXHWND
)::CreateWindowEx(MakeExtendedStyle(m_windowStyle
), "STATIC", (const char *)label
,
77 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
78 wxGetInstance(), NULL
);
80 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create static ctrl" );
84 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
85 Ctl3dSubclassCtl(static_item);
91 SetFont(parent
->GetFont());
92 SetSize(x
, y
, width
, height
);
97 void wxStaticText::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
99 int currentX
, currentY
;
100 GetPosition(¤tX
, ¤tY
);
104 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
106 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
109 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
111 int actualWidth
= width
;
112 int actualHeight
= height
;
118 ::GetWindowText((HWND
) GetHWND(), buf
, 300);
119 GetTextExtent(buf
, ¤t_width
, &cyf
, NULL
, NULL
, & this->GetFont());
124 // If we're prepared to use the existing width, then...
125 if (width
== -1 && ((sizeFlags
& wxSIZE_AUTO_WIDTH
) != wxSIZE_AUTO_WIDTH
))
127 else if (width
== -1)
131 wxGetCharSize(GetHWND(), &cx
, &cy
, & this->GetFont());
132 actualWidth
= (int)(current_width
+ cx
) ;
135 // If we're prepared to use the existing height, then...
136 if (height
== -1 && ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) != wxSIZE_AUTO_HEIGHT
))
138 else if (height
== -1)
140 actualHeight
= (int)(cyf
) ;
143 MoveWindow((HWND
) GetHWND(), x1
, y1
, actualWidth
, actualHeight
, TRUE
);
146 void wxStaticText::SetLabel(const wxString
& label
)
151 wxWindow
*parent
= GetParent();
152 GetWindowRect((HWND
) GetHWND(), &rect
);
154 // Since we now have the absolute screen coords,
155 // if there's a parent we must subtract its top left corner
161 ::ScreenToClient((HWND
) parent
->GetHWND(), &point
);
164 GetTextExtent(label
, &w
, &h
, NULL
, NULL
, & this->GetFont());
165 MoveWindow((HWND
) GetHWND(), point
.x
, point
.y
, (int)(w
+ 10), (int)h
,
167 SetWindowText((HWND
) GetHWND(), (const char *)label
);
170 WXHBRUSH
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
171 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
177 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
179 if (hbrush != (HBRUSH) 0)
182 return (HBRUSH)MSWDefWindowProc(message, wParam, lParam);
187 if (GetParent()->GetTransparentBackground())
188 SetBkMode((HDC
) pDC
, TRANSPARENT
);
190 SetBkMode((HDC
) pDC
, OPAQUE
);
192 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
193 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
195 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
197 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
198 // has a zero usage count.
199 // backgroundBrush->RealizeResource();
200 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
203 long wxStaticText::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
205 // Ensure that static items get messages. Some controls don't like this
206 // message to be intercepted (e.g. RichEdit), hence the tests.
207 if (nMsg
== WM_NCHITTEST
)
208 return (long)HTCLIENT
;
210 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);