]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
added demo of <font face>
[wxWidgets.git] / src / os2 / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stattext.cpp
3 // Purpose: wxStaticText
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/event.h"
17 #include "wx/app.h"
18 #include "wx/brush.h"
19 #endif
20
21 #include "wx/stattext.h"
22 #include "wx/os2/private.h"
23 #include <stdio.h>
24
25 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
26
27 bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
28 const wxString& label,
29 const wxPoint& pos,
30 const wxSize& size,
31 long style,
32 const wxString& name)
33 {
34 SetName(name);
35 if (parent) parent->AddChild(this);
36
37 SetBackgroundColour(parent->GetBackgroundColour()) ;
38 SetForegroundColour(parent->GetForegroundColour()) ;
39
40 if ( id == -1 )
41 m_windowId = (int)NewControlId();
42 else
43 m_windowId = id;
44
45 int x = pos.x;
46 int y = pos.y;
47 int width = size.x;
48 int height = size.y;
49
50 m_windowStyle = style;
51
52 // TODO
53 SubclassWin(m_hWnd);
54
55 SetFont(parent->GetFont());
56 SetSize(x, y, width, height);
57
58 return FALSE;
59 }
60
61 wxSize wxStaticText::DoGetBestSize() const
62 {
63 wxString text(wxGetWindowText(GetHWND()));
64
65 int widthTextMax = 0, widthLine,
66 heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
67
68 wxString curLine;
69 for ( const wxChar *pc = text; ; pc++ ) {
70 if ( *pc == wxT('\n') || *pc == wxT('\0') ) {
71 if ( !curLine ) {
72 // we can't use GetTextExtent - it will return 0 for both width
73 // and height and an empty line should count in height
74 // calculation
75 if ( !heightLineDefault )
76 heightLineDefault = heightLine;
77 if ( !heightLineDefault )
78 GetTextExtent(_T("W"), NULL, &heightLineDefault);
79
80 heightTextTotal += heightLineDefault;
81 }
82 else {
83 GetTextExtent(curLine, &widthLine, &heightLine);
84 if ( widthLine > widthTextMax )
85 widthTextMax = widthLine;
86 heightTextTotal += heightLine;
87 }
88
89 if ( *pc == wxT('\n') ) {
90 curLine.Empty();
91 }
92 else {
93 // the end of string
94 break;
95 }
96 }
97 else {
98 curLine += *pc;
99 }
100 }
101
102 return wxSize(widthTextMax, heightTextTotal);
103 }
104
105 void wxStaticText::SetLabel(const wxString& label)
106 {
107 // TODO
108
109 // adjust the size of the window to fit to the label (this behaviour is
110 // backward compatible and generally makes sense but we might want to still
111 // provide the user a way to disable it) (VZ)
112 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
113 }
114
115 WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
116 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
117 {
118 // TODO:
119 /*
120 if (GetParent()->GetTransparentBackground())
121 SetBkMode((HDC) pDC, TRANSPARENT);
122 else
123 SetBkMode((HDC) pDC, OPAQUE);
124
125 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
126 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
127
128 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
129 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
130 // has a zero usage count.
131 // backgroundBrush->RealizeResource();
132 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
133 */
134 return (WXHBRUSH)0;
135 }
136
137 MRESULT wxStaticText::OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
138 {
139 // Ensure that static items get messages. Some controls don't like this
140 // message to be intercepted (e.g. RichEdit), hence the tests.
141 // TODO:
142 /*
143 if (nMsg == WM_NCHITTEST)
144 return (long)HTCLIENT;
145 */
146 return wxWindow::OS2WindowProc(hwnd, nMsg, wParam, lParam);
147 }
148