]> git.saurik.com Git - wxWidgets.git/blob - src/msw/stattext.cpp
Added German translation to internat sample.
[wxWidgets.git] / src / msw / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stattext.cpp
3 // Purpose: wxStaticText
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 #ifdef __GNUG__
13 #pragma implementation "stattext.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/event.h"
25 #include "wx/app.h"
26 #include "wx/brush.h"
27 #endif
28
29 #include "wx/stattext.h"
30 #include "wx/msw/private.h"
31 #include <stdio.h>
32
33 #if !USE_SHARED_LIBRARY
34 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
35 #endif
36
37 bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
38 const wxString& label,
39 const wxPoint& pos,
40 const wxSize& size,
41 long style,
42 const wxString& name)
43 {
44 SetName(name);
45 if (parent) parent->AddChild(this);
46
47 SetBackgroundColour(parent->GetBackgroundColour()) ;
48 SetForegroundColour(parent->GetForegroundColour()) ;
49
50 if ( id == -1 )
51 m_windowId = (int)NewControlId();
52 else
53 m_windowId = id;
54
55 int x = pos.x;
56 int y = pos.y;
57 int width = size.x;
58 int height = size.y;
59
60 m_windowStyle = style;
61
62 long msStyle = WS_CHILD|WS_VISIBLE;
63 if (m_windowStyle & wxALIGN_CENTRE)
64 msStyle |= SS_CENTER;
65 else if (m_windowStyle & wxALIGN_RIGHT)
66 msStyle |= SS_RIGHT;
67 else
68 msStyle |= SS_LEFT;
69
70 // Even with extended styles, need to combine with WS_BORDER
71 // for them to look right.
72 if ( wxStyleHasBorder(m_windowStyle) )
73 msStyle |= WS_BORDER;
74
75 m_hWnd = (WXHWND)::CreateWindowEx(MakeExtendedStyle(m_windowStyle), _T("STATIC"), (const wxChar *)label,
76 msStyle,
77 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
78 wxGetInstance(), NULL);
79
80 wxCHECK_MSG( m_hWnd, FALSE, _T("Failed to create static ctrl") );
81
82 #if wxUSE_CTL3D
83 /*
84 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
85 Ctl3dSubclassCtl(static_item);
86 */
87 #endif
88
89 SubclassWin(m_hWnd);
90
91 SetFont(parent->GetFont());
92 SetSize(x, y, width, height);
93
94 return TRUE;
95 }
96
97 wxSize wxStaticText::DoGetBestSize()
98 {
99 wxString text(wxGetWindowText(GetHWND()));
100
101 int widthTextMax = 0, widthLine,
102 heightTextTotal = 0, heightLine;
103
104 wxString curLine;
105 for ( const wxChar *pc = text; ; pc++ ) {
106 if ( *pc == _T('\n') || *pc == _T('\0') ) {
107 GetTextExtent(curLine, &widthLine, &heightLine);
108 if ( widthLine > widthTextMax )
109 widthTextMax = widthLine;
110 heightTextTotal += heightLine;
111
112 if ( *pc == _T('\n') ) {
113 curLine.Empty();
114 }
115 else {
116 // the end of string
117 break;
118 }
119 }
120 else {
121 curLine += *pc;
122 }
123 }
124
125 return wxSize(widthTextMax, heightTextTotal);
126 }
127
128 void wxStaticText::SetLabel(const wxString& label)
129 {
130 SetWindowText(GetHwnd(), label);
131
132 // adjust the size of the window to fit to the label (this behaviour is
133 // backward compatible and generally makes sense but we might want to still
134 // provide the user a way to disable it) (VZ)
135 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
136 }
137
138 WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
139 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
140 {
141 /*
142 #if wxUSE_CTL3D
143 if ( m_useCtl3D )
144 {
145 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
146
147 if (hbrush != (HBRUSH) 0)
148 return hbrush;
149 else
150 return (HBRUSH)MSWDefWindowProc(message, wParam, lParam);
151 }
152 #endif
153 */
154
155 if (GetParent()->GetTransparentBackground())
156 SetBkMode((HDC) pDC, TRANSPARENT);
157 else
158 SetBkMode((HDC) pDC, OPAQUE);
159
160 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
161 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
162
163 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
164
165 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
166 // has a zero usage count.
167 // backgroundBrush->RealizeResource();
168 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
169 }
170
171 long wxStaticText::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
172 {
173 // Ensure that static items get messages. Some controls don't like this
174 // message to be intercepted (e.g. RichEdit), hence the tests.
175 if (nMsg == WM_NCHITTEST)
176 return (long)HTCLIENT;
177
178 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
179 }
180
181