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