]> git.saurik.com Git - wxWidgets.git/blame - src/qt/stattext.cpp
Visualage C++ V4.0 duplicate symbol fixes
[wxWidgets.git] / src / qt / stattext.cpp
CommitLineData
7c78e7c7
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: stattext.cpp
01b2eeec
KB
3// Purpose: wxStaticText
4// Author: AUTHOR
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
7c78e7c7
RR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
7c78e7c7
RR
12#ifdef __GNUG__
13#pragma implementation "stattext.h"
14#endif
15
01b2eeec
KB
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
7c78e7c7 22
01b2eeec
KB
23#ifndef WX_PRECOMP
24#include "wx/app.h"
25#endif
7c78e7c7 26
01b2eeec
KB
27#include "wx/stattext.h"
28#include "wx/msw/private.h"
29#include <stdio.h>
7c78e7c7 30
01b2eeec 31IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
01b2eeec
KB
32
33bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
34 const wxString& label,
35 const wxPoint& pos,
36 const wxSize& size,
37 long style,
38 const wxString& name)
7c78e7c7 39{
01b2eeec
KB
40 SetName(name);
41 if (parent) parent->AddChild(this);
42
43 SetBackgroundColour(parent->GetDefaultBackgroundColour()) ;
44 SetForegroundColour(parent->GetDefaultForegroundColour()) ;
45
46 if ( id == -1 )
47 m_windowId = (int)NewControlId();
48 else
49 m_windowId = id;
50
51 int x = pos.x;
52 int y = pos.y;
53 int width = size.x;
54 int height = size.y;
55
56 m_windowStyle = style;
57
58 long msStyle = WS_CHILD|WS_VISIBLE;
59 if (m_windowStyle & wxALIGN_CENTRE)
60 msStyle |= SS_CENTER;
61 else if (m_windowStyle & wxALIGN_RIGHT)
62 msStyle |= SS_RIGHT;
63 else
64 msStyle |= SS_LEFT;
65
66 // Even with extended styles, need to combine with WS_BORDER
67 // for them to look right.
68 if ((m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
69 (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))
70 msStyle |= WS_BORDER;
71
72 HWND static_item = CreateWindowEx(MakeExtendedStyle(m_windowStyle), "STATIC", (const char *)label,
73 msStyle,
74 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
75 wxGetInstance(), NULL);
76
77#if CTL3D
78/*
79 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
80 Ctl3dSubclassCtl(static_item);
81*/
82#endif
83
84 m_hWnd = (WXHWND)static_item;
85
86 SubclassWin((WXHWND)static_item);
87
88 SetFont(* parent->GetFont());
89 SetSize(x, y, width, height);
90 return TRUE;
91}
7c78e7c7 92
01b2eeec 93void wxStaticText::SetSize(int x, int y, int width, int height, int sizeFlags)
7c78e7c7 94{
01b2eeec
KB
95 int currentX, currentY;
96 GetPosition(&currentX, &currentY);
97 int x1 = x;
98 int y1 = y;
7c78e7c7 99
01b2eeec
KB
100 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
101 x1 = currentX;
102 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
103 y1 = currentY;
104
105 AdjustForParentClientOrigin(x1, y1, sizeFlags);
106
107 int actualWidth = width;
108 int actualHeight = height;
109
110 char buf[300];
111 int current_width;
112 int cyf;
113
114 ::GetWindowText((HWND) GetHWND(), buf, 300);
115 GetTextExtent(buf, &current_width, &cyf, NULL, NULL,GetFont());
116
117 int ww, hh;
118 GetSize(&ww, &hh);
119
120 // If we're prepared to use the existing width, then...
121 if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
122 actualWidth = ww;
123 else if (width == -1)
124 {
125 int cx;
126 int cy;
127 wxGetCharSize(GetHWND(), &cx, &cy,GetFont());
128 actualWidth = (int)(current_width + cx) ;
129 }
130
131 // If we're prepared to use the existing height, then...
132 if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
133 actualHeight = hh;
134 else if (height == -1)
135 {
136 actualHeight = (int)(cyf) ;
137 }
138
139 MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE);
140}
141
142void wxStaticText::SetLabel(const wxString& label)
7c78e7c7 143{
01b2eeec
KB
144 int w, h;
145 RECT rect;
146
147 wxWindow *parent = GetParent();
148 GetWindowRect((HWND) GetHWND(), &rect);
7c78e7c7 149
01b2eeec
KB
150 // Since we now have the absolute screen coords,
151 // if there's a parent we must subtract its top left corner
152 POINT point;
153 point.x = rect.left;
154 point.y = rect.top;
155 if (parent)
156 {
157 ::ScreenToClient((HWND) parent->GetHWND(), &point);
158 }
159
160 GetTextExtent(label, &w, &h, NULL, NULL, GetFont());
161 MoveWindow((HWND) GetHWND(), point.x, point.y, (int)(w + 10), (int)h,
162 TRUE);
163 SetWindowText((HWND) GetHWND(), (const char *)label);
164}
165
166WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
167 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
7c78e7c7 168{
01b2eeec
KB
169/*
170#if CTL3D
171 if ( m_useCtl3D )
172 {
173 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
174
175 if (hbrush != (HBRUSH) 0)
176 return hbrush;
177 else
178 return (HBRUSH)MSWDefWindowProc(message, wParam, lParam);
179 }
180#endif
181*/
182
183 if (GetParent()->GetTransparentBackground())
184 SetBkMode((HDC) pDC, TRANSPARENT);
185 else
186 SetBkMode((HDC) pDC, OPAQUE);
187
188 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
189 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
7c78e7c7 190
01b2eeec
KB
191 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
192
193 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
194 // has a zero usage count.
195// backgroundBrush->RealizeResource();
196 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
197}
198
199long wxStaticText::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
7c78e7c7 200{
01b2eeec
KB
201 // Ensure that static items get messages. Some controls don't like this
202 // message to be intercepted (e.g. RichEdit), hence the tests.
203 if (nMsg == WM_NCHITTEST)
204 return (long)HTCLIENT;
205
206 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
207}
208
209