]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/stattext.cpp
e27866942b4123576b143b157e7c3ab4099ae15d
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
->GetBackgroundColour()) ;
46 SetForegroundColour(parent
->GetForegroundColour()) ;
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 ( wxStyleHasBorder(m_windowStyle
) )
73 m_hWnd
= (WXHWND
)::CreateWindowEx(MakeExtendedStyle(m_windowStyle
), "STATIC", (const char *)label
,
75 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
76 wxGetInstance(), NULL
);
78 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create static ctrl" );
82 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
83 Ctl3dSubclassCtl(static_item);
89 SetFont(* parent
->GetFont());
90 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 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
109 int actualWidth
= width
;
110 int actualHeight
= height
;
116 ::GetWindowText((HWND
) GetHWND(), buf
, 300);
117 GetTextExtent(buf
, ¤t_width
, &cyf
, NULL
, NULL
,GetFont());
122 // If we're prepared to use the existing width, then...
123 if (width
== -1 && ((sizeFlags
& wxSIZE_AUTO_WIDTH
) != wxSIZE_AUTO_WIDTH
))
125 else if (width
== -1)
129 wxGetCharSize(GetHWND(), &cx
, &cy
,GetFont());
130 actualWidth
= (int)(current_width
+ cx
) ;
133 // If we're prepared to use the existing height, then...
134 if (height
== -1 && ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) != wxSIZE_AUTO_HEIGHT
))
136 else if (height
== -1)
138 actualHeight
= (int)(cyf
) ;
141 MoveWindow((HWND
) GetHWND(), x1
, y1
, actualWidth
, actualHeight
, TRUE
);
144 void wxStaticText::SetLabel(const wxString
& label
)
149 wxWindow
*parent
= GetParent();
150 GetWindowRect((HWND
) GetHWND(), &rect
);
152 // Since we now have the absolute screen coords,
153 // if there's a parent we must subtract its top left corner
159 ::ScreenToClient((HWND
) parent
->GetHWND(), &point
);
162 GetTextExtent(label
, &w
, &h
, NULL
, NULL
, GetFont());
163 MoveWindow((HWND
) GetHWND(), point
.x
, point
.y
, (int)(w
+ 10), (int)h
,
165 SetWindowText((HWND
) GetHWND(), (const char *)label
);
168 WXHBRUSH
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
169 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
175 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
177 if (hbrush != (HBRUSH) 0)
180 return (HBRUSH)MSWDefWindowProc(message, wParam, lParam);
185 if (GetParent()->GetTransparentBackground())
186 SetBkMode((HDC
) pDC
, TRANSPARENT
);
188 SetBkMode((HDC
) pDC
, OPAQUE
);
190 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
191 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
193 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
195 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
196 // has a zero usage count.
197 // backgroundBrush->RealizeResource();
198 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
201 long wxStaticText::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
203 // Ensure that static items get messages. Some controls don't like this
204 // message to be intercepted (e.g. RichEdit), hence the tests.
205 if (nMsg
== WM_NCHITTEST
)
206 return (long)HTCLIENT
;
208 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);