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