OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
static.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TStatic. This defines the basic behavior of static
7/// text controls
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/static.h>
11#include <owl/applicat.h>
12
13#if defined(__BORLANDC__)
14# pragma option -w-ccc // Disable "Condition is always true/false"
15#endif
16
17#if defined(OWL_SUPPORT_BWCC)
18# include <owl/private/bwcc.h>
19#endif
20
21namespace owl {
22
24
25DEFINE_RESPONSE_TABLE1(TStatic,TControl)
28
29//
30/// Constructs a static control object with the supplied parent window (parent),
31/// control ID (Id), text (title), position (x, y) relative to the origin of the
32/// parent window's client area, width (w), height (h), and default text length
33/// (textLimit) of zero. By default, the static control is visible upon creation and
34/// has left-justified text. (Set to WS_CHILD | WS_VISIBLE | WS_GROUP | SS_LEFT.)
35/// Invokes a TControl constructor. You can change the default style of the static
36/// control via the control object's constructor.
37//
38TStatic::TStatic(TWindow* parent, int id, LPCTSTR title, int x, int y, int w, int h,
39 uint textLimit, TModule* module)
40: TControl(parent, id, title, x, y, w, h, module),
41 TextLimit(textLimit),
42 TransferBufferFieldType(tbftCharArray)
43{
44 Attr.Style = (Attr.Style | SS_LEFT) & ~WS_TABSTOP;
45}
46
47//
48/// String-aware overload
49//
50TStatic::TStatic(TWindow* parent, int id, const tstring& title, int x, int y, int w, int h,
51 uint textLimit, TModule* module)
52: TControl(parent, id, title, x, y, w, h, module),
53 TextLimit(textLimit),
54 TransferBufferFieldType(tbftCharArray)
55{
56 Attr.Style = (Attr.Style | SS_LEFT) & ~WS_TABSTOP;
57}
58
59//
60/// Constructs a TStatic object to be associated with a static control interface
61/// control of a TDialog object. Invokes the TControl constructor with similar
62/// parameters, then sets TextLimit to textLimit. Disables the data transfer
63/// mechanism by calling DisableTransfer. The resourceId parameter must correspond
64/// to a static control resource that you define.
65//
67: TControl(parent, resourceId, module),
68 TextLimit(textLimit),
69 TransferBufferFieldType(tbftCharArray)
70{
72}
73
74//
75/// Overload for static controls loaded from resource
76/// Allows the title specified in the resource data to be overridden.
77//
79: TControl(parent, resourceId, title, module),
80 TextLimit(textLimit),
81 TransferBufferFieldType(tbftCharArray)
82{
84}
85
86//
87/// Constructs a TEdit object to encapsulate (alias) an existing control.
88//
90: TControl(hWnd, module),
91 TextLimit(0),
92 TransferBufferFieldType(tbftCharArray)
93{
95}
96
97//
98/// Overrides TWindow's virtual EvSize function. When the static control is resized,
99/// EvSize ensures that it is repainted.
100//
101void
103{
104 Invalidate();
106}
107
108//
109/// Returns the name of TStatic's registration class (STATIC)
110//
112{
113#if defined(OWL_SUPPORT_BWCC)
114 if (GetApplication()->BWCCEnabled())
116 else
117#endif
118 return TWindowClassName{_T("STATIC")};
119}
120
121uint
123{
124 uint n = 0;
126 {
127 case tbftCharArray:
128 n = TransferCharArray(buffer, direction);
129 break;
130
131 case tbftString:
132 n = TransferString(buffer, direction);
133 break;
134
135 default:
136 CHECKX(false, _T("TStatic::Transfer: Unknown field type."));
137 }
138 return n;
139}
140
145
150
151uint
152TStatic::TransferCharArray(void* buffer, TTransferDirection direction)
153{
154 if (!buffer && direction != tdSizeData) return 0;
155 tchar* s = static_cast<tchar*>(buffer);
156 if (direction == tdGetData)
157 GetText(s, TextLimit);
158 else if (direction == tdSetData)
159 SetText(s);
160 return TextLimit * sizeof(tchar);
161}
162
163uint
164TStatic::TransferString(void* buffer, TTransferDirection direction)
165{
166 if (!buffer && direction != tdSizeData) return 0;
167 tstring& s = *static_cast<tstring*>(buffer);
168 if (direction == tdGetData)
169 s = GetText();
170 else if (direction == tdSetData)
171 SetText(s);
172 return sizeof(tstring);
173}
174
175//
176/// Clears the text of the associated static control.
177//
178void
180{
181 SetText(_T(""));
182}
183
185
186#if OWL_PERSISTENT_STREAMS
187
188//
189/// Reads an instance of TStatic from the passed ipstream
190//
191void*
192TStatic::Streamer::Read(ipstream& is, uint32 /*version*/) const
193{
194 ReadBaseObject((TControl*)GetObject(), is);
195 is >> GetObject()->TextLimit;
196 return GetObject();
197}
198
199
200//
201/// Writes the TStatic to the passed opstream
202//
203void
204TStatic::Streamer::Write(opstream& os) const
205{
206 WriteBaseObject((TControl*)GetObject(), os);
207 os << GetObject()->TextLimit;
208}
209
210#endif
211
212} // OWL namespace
213/* ========================================================================== */
214
Definition of class TApplication.
Legacy support for Borland Windows Custom Controls (BWCC)
#define CHECKX(condition, message)
Definition checks.h:245
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
The tagSIZE struct is defined as.
Definition geometry.h:234
An interface object that represents a static text interface element.
Definition static.h:36
tstring GetText() const
String-aware overload.
Definition static.h:219
void SetTransferBufferFieldType(TTransferBufferFieldType)
Definition static.cpp:146
TTransferBufferFieldType TransferBufferFieldType
Definition static.h:111
TStatic(TWindow *parent, int id, LPCTSTR title, int x, int y, int w, int h, uint textLen=0, TModule *=nullptr)
Constructs a static control object with the supplied parent window (parent), control ID (Id),...
Definition static.cpp:38
void SetText(LPCTSTR str)
Sets the static control's text to the string supplied in str.
Definition static.h:226
TTransferBufferFieldType GetTransferBufferFieldType() const
Definition static.cpp:141
TTransferBufferFieldType
Definition static.h:97
@ tbftCharArray
Definition static.h:98
void EvSize(uint sizeType, const TSize &size)
Overrides TWindow's virtual EvSize function.
Definition static.cpp:102
virtual void Clear()
Clears the text of the associated static control.
Definition static.cpp:179
auto GetWindowClassName() -> TWindowClassName override
Returns the name of TStatic's registration class (STATIC)
Definition static.cpp:111
auto Transfer(void *buffer, TTransferDirection) -> uint override
TWindow override Transfers TextLimit characters of text to or from a transfer buffer pointed to by bu...
Definition static.cpp:122
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
void DisableTransfer()
Disables (for the interface object) the transfer mechanism, which allows state data to be transferred...
Definition window.h:1835
void EvSize(uint sizeType, const TSize &size)
Response method for an incoming WM_SIZE message.
Definition window.cpp:1632
virtual void Invalidate(bool erase=true)
Invalidates (mark for painting) the entire client area of a window.
Definition window.h:2822
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define IMPLEMENT_STREAMABLE1(cls, base1)
Definition objstrm.h:1725
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
@ tdSizeData
Return the size of data transferred by the class.
Definition window.h:95
@ tdSetData
Set data from the buffer into the window.
Definition window.h:94
@ tdGetData
Get data from the window into the buffer.
Definition window.h:93
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
EV_WM_SIZE
Definition decframe.cpp:34
Definition of class TStatic, the class for static controls and base for any control that manages simp...