]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
and now it even compiles
[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 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
27 #endif
28
29 bool 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 {
36 SetName(name);
37 if (parent) parent->AddChild(this);
38
39 SetBackgroundColour(parent->GetBackgroundColour()) ;
40 SetForegroundColour(parent->GetForegroundColour()) ;
41
42 if ( id == -1 )
43 m_windowId = (int)NewControlId();
44 else
45 m_windowId = id;
46
47 int x = pos.x;
48 int y = pos.y;
49 int width = size.x;
50 int height = size.y;
51
52 m_windowStyle = style;
53
54 // TODO
55 SubclassWin(m_hWnd);
56
57 SetFont(parent->GetFont());
58 SetSize(x, y, width, height);
59
60 return FALSE;
61 }
62
63 wxSize wxStaticText::DoGetBestSize()
64 {
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);
92 }
93
94 void wxStaticText::SetLabel(const wxString& label)
95 {
96 // TODO
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
104 WXHBRUSH 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
126 MRESULT 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);
136 }
137