]>
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
, const 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(const int x
, const int y
, const int width
, const int height
, const 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
);
141 if (!((width
== -1) && (height
== -1)))
143 #if WXWIN_COMPATIBILITY
144 GetEventHandler()->OldOnSize(actualWidth
, actualHeight
);
146 wxSizeEvent
event(wxSize(actualWidth
, actualHeight
), m_windowId
);
147 event
.eventObject
= this;
148 GetEventHandler()->ProcessEvent(event
);
153 void wxStaticText::SetLabel(const wxString
& label
)
158 wxWindow
*parent
= GetParent();
159 GetWindowRect((HWND
) GetHWND(), &rect
);
161 // Since we now have the absolute screen coords,
162 // if there's a parent we must subtract its top left corner
168 ::ScreenToClient((HWND
) parent
->GetHWND(), &point
);
171 GetTextExtent(label
, &w
, &h
, NULL
, NULL
, GetFont());
172 MoveWindow((HWND
) GetHWND(), point
.x
, point
.y
, (int)(w
+ 10), (int)h
,
174 SetWindowText((HWND
) GetHWND(), (const char *)label
);
177 WXHBRUSH
wxStaticText::OnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
178 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
184 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
186 if (hbrush != (HBRUSH) 0)
189 return (HBRUSH)MSWDefWindowProc(message, wParam, lParam);
194 if (GetParent()->GetTransparentBackground())
195 SetBkMode((HDC
) pDC
, TRANSPARENT
);
197 SetBkMode((HDC
) pDC
, OPAQUE
);
199 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
200 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
202 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
204 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
205 // has a zero usage count.
206 // backgroundBrush->RealizeResource();
207 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
210 long wxStaticText::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
212 // Ensure that static items get messages. Some controls don't like this
213 // message to be intercepted (e.g. RichEdit), hence the tests.
214 if (nMsg
== WM_NCHITTEST
)
215 return (long)HTCLIENT
;
217 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);