]> git.saurik.com Git - wxWidgets.git/blame - src/msw/stattext.cpp
create wxNotebook without any extended style
[wxWidgets.git] / src / msw / stattext.cpp
CommitLineData
2bda0e17
KB
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
c085e333 9// Licence: wxWindows license
2bda0e17
KB
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
1e6feb95
VZ
23#if wxUSE_STATTEXT
24
2bda0e17 25#ifndef WX_PRECOMP
2432b92d 26#include "wx/event.h"
2bda0e17 27#include "wx/app.h"
2432b92d 28#include "wx/brush.h"
2bda0e17
KB
29#endif
30
31#include "wx/stattext.h"
32#include "wx/msw/private.h"
33#include <stdio.h>
34
2bda0e17 35IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
2bda0e17 36
debe6624 37bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
2bda0e17
KB
38 const wxString& label,
39 const wxPoint& pos,
40 const wxSize& size,
debe6624 41 long style,
2bda0e17
KB
42 const wxString& name)
43{
44 SetName(name);
45 if (parent) parent->AddChild(this);
46
fd71308f
JS
47 SetBackgroundColour(parent->GetBackgroundColour()) ;
48 SetForegroundColour(parent->GetForegroundColour()) ;
2bda0e17
KB
49
50 if ( id == -1 )
c085e333 51 m_windowId = (int)NewControlId();
2bda0e17 52 else
c085e333 53 m_windowId = id;
2bda0e17
KB
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
b0766406
JS
62 long msStyle = WS_CHILD | WS_VISIBLE;
63
64 if ( m_windowStyle & wxCLIP_SIBLINGS )
65 msStyle |= WS_CLIPSIBLINGS;
2bda0e17
KB
66 if (m_windowStyle & wxALIGN_CENTRE)
67 msStyle |= SS_CENTER;
68 else if (m_windowStyle & wxALIGN_RIGHT)
69 msStyle |= SS_RIGHT;
70 else
71 msStyle |= SS_LEFT;
72
73 // Even with extended styles, need to combine with WS_BORDER
74 // for them to look right.
c085e333 75 if ( wxStyleHasBorder(m_windowStyle) )
2bda0e17
KB
76 msStyle |= WS_BORDER;
77
223d09f6 78 m_hWnd = (WXHWND)::CreateWindowEx(MakeExtendedStyle(m_windowStyle), wxT("STATIC"), (const wxChar *)label,
2bda0e17
KB
79 msStyle,
80 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
81 wxGetInstance(), NULL);
82
223d09f6 83 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static ctrl") );
c085e333 84
1f112209 85#if wxUSE_CTL3D
2bda0e17
KB
86/*
87 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
88 Ctl3dSubclassCtl(static_item);
89*/
90#endif
91
c085e333 92 SubclassWin(m_hWnd);
2bda0e17 93
486fd225 94 wxControl::SetFont(parent->GetFont());
2bda0e17 95 SetSize(x, y, width, height);
c085e333 96
2bda0e17
KB
97 return TRUE;
98}
99
f68586e5 100wxSize wxStaticText::DoGetBestSize() const
2bda0e17 101{
4b5d9823
VZ
102 wxString text(wxGetWindowText(GetHWND()));
103
104 int widthTextMax = 0, widthLine,
4fe5383d 105 heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
4b5d9823
VZ
106
107 wxString curLine;
54c13c66 108 for ( const wxChar *pc = text; ; pc++ ) {
223d09f6 109 if ( *pc == wxT('\n') || *pc == wxT('\0') ) {
4fe5383d
VZ
110 if ( !curLine ) {
111 // we can't use GetTextExtent - it will return 0 for both width
112 // and height and an empty line should count in height
113 // calculation
114 if ( !heightLineDefault )
115 heightLineDefault = heightLine;
116 if ( !heightLineDefault )
117 GetTextExtent(_T("W"), NULL, &heightLineDefault);
118
119 heightTextTotal += heightLineDefault;
120 }
121 else {
122 GetTextExtent(curLine, &widthLine, &heightLine);
123 if ( widthLine > widthTextMax )
124 widthTextMax = widthLine;
125 heightTextTotal += heightLine;
126 }
4b5d9823 127
223d09f6 128 if ( *pc == wxT('\n') ) {
4b5d9823
VZ
129 curLine.Empty();
130 }
131 else {
132 // the end of string
133 break;
134 }
135 }
136 else {
137 curLine += *pc;
138 }
139 }
140
4438caf4 141 return wxSize(widthTextMax, heightTextTotal);
2bda0e17
KB
142}
143
144void wxStaticText::SetLabel(const wxString& label)
145{
4b5d9823 146 SetWindowText(GetHwnd(), label);
2bda0e17 147
185fa6bf
VZ
148 // adjust the size of the window to fit to the label unless autoresizing is
149 // disabled
150 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
151 {
152 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
153 }
2bda0e17
KB
154}
155
486fd225
RD
156
157bool wxStaticText::SetFont(const wxFont& font)
158{
159 bool ret = wxControl::SetFont(font);
160
161 // adjust the size of the window to fit to the label unless autoresizing is
162 // disabled
163 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
164 {
165 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
166 }
167
168 return ret;
169}
170
171
2bda0e17
KB
172long wxStaticText::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
173{
174 // Ensure that static items get messages. Some controls don't like this
175 // message to be intercepted (e.g. RichEdit), hence the tests.
176 if (nMsg == WM_NCHITTEST)
177 return (long)HTCLIENT;
178
179 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
180}
181
1e6feb95 182#endif // wxUSE_STATTEXT