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