]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
made wxPanel be auto layout aware
[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
d90895ac 63wxSize wxStaticText::DoGetBestSize()
0e320a79 64{
d90895ac
DW
65 wxString text(wxGetWindowText(GetHWND()));
66
67 int widthTextMax = 0, widthLine,
68 heightTextTotal = 0, heightLine;
69
70 wxString curLine;
71 for ( const wxChar *pc = text; ; pc++ ) {
72 if ( *pc == wxT('\n') || *pc == wxT('\0') ) {
73 GetTextExtent(curLine, &widthLine, &heightLine);
74 if ( widthLine > widthTextMax )
75 widthTextMax = widthLine;
76 heightTextTotal += heightLine;
77
78 if ( *pc == wxT('\n') ) {
79 curLine.Empty();
80 }
81 else {
82 // the end of string
83 break;
84 }
85 }
86 else {
87 curLine += *pc;
88 }
89 }
90
91 return wxSize(widthTextMax, heightTextTotal);
0e320a79
DW
92}
93
94void wxStaticText::SetLabel(const wxString& label)
95{
96 // TODO
d90895ac
DW
97
98 // adjust the size of the window to fit to the label (this behaviour is
99 // backward compatible and generally makes sense but we might want to still
100 // provide the user a way to disable it) (VZ)
101 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
102}
103
104WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
105 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
106{
107 // TODO:
108/*
109 if (GetParent()->GetTransparentBackground())
110 SetBkMode((HDC) pDC, TRANSPARENT);
111 else
112 SetBkMode((HDC) pDC, OPAQUE);
113
114 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
115 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
116
117 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
118 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
119 // has a zero usage count.
120// backgroundBrush->RealizeResource();
121 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
122*/
123 return (WXHBRUSH)0;
124}
125
126MRESULT wxStaticText::OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
127{
128 // Ensure that static items get messages. Some controls don't like this
129 // message to be intercepted (e.g. RichEdit), hence the tests.
130// TODO:
131/*
132 if (nMsg == WM_NCHITTEST)
133 return (long)HTCLIENT;
134*/
135 return wxWindow::OS2WindowProc(hwnd, nMsg, wParam, lParam);
0e320a79
DW
136}
137