]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
SN: Added suitable includes for EMX (#ifdef'ed __EMX__),
[wxWidgets.git] / src / os2 / stattext.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: stattext.cpp
3// Purpose: wxStaticText
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d90895ac
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
d90895ac
DW
15#ifndef WX_PRECOMP
16#include "wx/event.h"
0e320a79 17#include "wx/app.h"
d90895ac
DW
18#include "wx/brush.h"
19#endif
0e320a79 20
d90895ac
DW
21#include "wx/stattext.h"
22#include "wx/os2/private.h"
0e320a79
DW
23#include <stdio.h>
24
0e320a79 25IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
0e320a79
DW
26
27bool 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{
d90895ac
DW
34 SetName(name);
35 if (parent) parent->AddChild(this);
36
37 SetBackgroundColour(parent->GetBackgroundColour()) ;
38 SetForegroundColour(parent->GetForegroundColour()) ;
0e320a79 39
d90895ac
DW
40 if ( id == -1 )
41 m_windowId = (int)NewControlId();
42 else
43 m_windowId = id;
0e320a79 44
d90895ac
DW
45 int x = pos.x;
46 int y = pos.y;
47 int width = size.x;
48 int height = size.y;
0e320a79 49
d90895ac 50 m_windowStyle = style;
0e320a79 51
d90895ac
DW
52 // TODO
53 SubclassWin(m_hWnd);
0e320a79 54
d90895ac
DW
55 SetFont(parent->GetFont());
56 SetSize(x, y, width, height);
57
58 return FALSE;
0e320a79
DW
59}
60
e78c4d50 61wxSize wxStaticText::DoGetBestSize() const
0e320a79 62{
d90895ac
DW
63 wxString text(wxGetWindowText(GetHWND()));
64
65 int widthTextMax = 0, widthLine,
e78c4d50 66 heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
d90895ac
DW
67
68 wxString curLine;
69 for ( const wxChar *pc = text; ; pc++ ) {
70 if ( *pc == wxT('\n') || *pc == wxT('\0') ) {
e78c4d50
DW
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 }
d90895ac
DW
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);
0e320a79
DW
103}
104
105void wxStaticText::SetLabel(const wxString& label)
106{
107 // TODO
d90895ac
DW
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
115WXHBRUSH 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
137MRESULT 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);
0e320a79
DW
147}
148