OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
static.h
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/// Definition of class TStatic, the class for static controls and base for
7/// any control that manages simple text.
8//----------------------------------------------------------------------------
9
10#if !defined(OWL_STATIC_H)
11#define OWL_STATIC_H
12
13#include <owl/private/defs.h>
14#if defined(BI_HAS_PRAGMA_ONCE)
15# pragma once
16#endif
17
18#include <owl/control.h>
19
20
21namespace owl {
22
23#include <owl/preclass.h>
24
25//
26/// \class TStatic
27// ~~~~~ ~~~~~~~
28/// An interface object that represents a static text interface element. Static
29/// elements consist of text or graphics that the user does not change. An
30/// application, however, can modify the static control. You must use a TStatic
31/// object, for example, to create a static control that's used to display a text
32/// label such as a copyright notice in a parent TWindow object. TStatic can also be
33/// used to make it easier to modify the text of static controls in TDialog objects.
34/// See the sample program in the EXAMPLES\\OWL\\OWLAPI\\STATIC directory for an
35/// example of a static control.
36class _OWLCLASS TStatic : public TControl {
37 public:
38
39 //
40 // For use with GetImage and SetImage.
41 //
43 {
44 Bitmap = IMAGE_BITMAP,
45 Icon = IMAGE_ICON,
46 Cursor = IMAGE_CURSOR,
47 EnhMetaFile = IMAGE_ENHMETAFILE
48 };
49
50 TStatic(TWindow* parent, int id, LPCTSTR title, int x, int y, int w, int h,
51 uint textLen = 0, TModule* = nullptr);
52 TStatic(TWindow* parent, int id, const tstring& title, int x, int y, int w, int h,
53 uint textLen = 0, TModule* = nullptr);
54 TStatic(TWindow* parent, int resourceId, uint textLen = 0, TModule* = nullptr);
55 TStatic(TWindow* parent, int resourceId, const tstring& title, uint textLimit = 0, TModule* = nullptr);
56 TStatic(THandle hWnd, TModule* = nullptr);
57
58 int GetTextLen() const;
59
60 int GetText(LPTSTR str, int maxChars) const;
61 tstring GetText() const;
62
63 void SetText(LPCTSTR str);
64 void SetText(const tstring& str) {SetText(str.c_str());}
65 void SetText(uint resourceStringId);
66
67 virtual void Clear();
68
69 //
70 /// Returns the length limit of the control's text.
71 //
72 uint GetTextLimit() const;
73 void SetTextLimit(uint textlimit);
74
75 // Set and Get icon for Statics with the SS_ICON style
76 //
77 HICON GetIcon() const;
78 HICON SetIcon(HICON);
79
80 //
81 /// TWindow override
82 /// Transfers TextLimit characters of text to or from a transfer buffer pointed to
83 /// by buffer. If direction is tdGetData, the text is transferred to the buffer from
84 /// the static control. If direction is tdSetData, the static control's text is set
85 /// to the text contained in the transfer buffer. Transfer returns TextLimit, the
86 /// number of bytes stored in or retrieved from the buffer. If direction is
87 /// tdSizeData, Transfer returns TextLimit without transferring data.
88 //
89 auto Transfer(void* buffer, TTransferDirection) -> uint override;
90
91 /// \name Accessors and mutators for setting the transfer buffer field type
92 /// These are used by the Safe Buffer Transfer machinery, and should not be
93 /// used in general. TODO: Consider making these private with friend access.
94 /// @{
95
100 TTransferBufferFieldType GetTransferBufferFieldType() const;
101 void SetTransferBufferFieldType(TTransferBufferFieldType);
102
103 /// @}
104
105 // Set\Get image associated with static control
106 //
107 HANDLE GetImage(TImageType imageType = Bitmap) const;
108 HANDLE SetImage(HANDLE image, TImageType imageType = Bitmap );
109
110 protected:
112
113 // Override TWindow virtual member functions
114 //
115 auto GetWindowClassName() -> TWindowClassName override;
116
117 // Make sure that control is re-painted when resized
118 //
119 void EvSize(uint sizeType, const TSize& size);
120
122
123 /// Holds the size of the text buffer for static controls. Because of the null
124 /// terminator on the string, the number of characters that can be stored in the
125 /// static control is one less than TextLimit. TextLimit is also the number of
126 /// bytes transferred by the Transfer member function.
127 //
128 uint TextLimit;
129
130 private:
131
132 // Transfer implementations for different field types
133 //
134 uint TransferCharArray(void* buffer, TTransferDirection direction);
135 uint TransferString(void* buffer, TTransferDirection direction);
136
137 // Hidden to prevent accidental copying or assignment
138 //
139 TStatic(const TStatic&);
140 TStatic& operator =(const TStatic&);
141
144};
145
147
148//
149// Static control notifications (Win32 only). Methods are: void Method()
150//
151// EV_STN_CLICKED(id, method)
152// EV_STN_DBLCLK(id, method)
153// EV_STN_ENABLE(id, method)
154// EV_STN_DISABLE(id, method)
155//
156
157#include <owl/posclass.h>
158
159//OWL_INSTANTIATE_TMPL(TStatic) // VC++ issue
160
161//----------------------------------------------------------------------------
162// Inline implementations
163//
164
165//
166/// Returns the handle of the icon used for this static control.
167//
168inline HICON TStatic::GetIcon() const {
170 return reinterpret_cast<HICON>(CONST_CAST(TStatic*,this)->SendMessage(STM_GETICON));
171}
172
173//
174/// Sets the handle of the icon.
175//
178 return reinterpret_cast<HICON>(SendMessage(STM_SETICON, TParam1(icon)));
179}
180
181//
182/// Return handle of image used for static control
183//
185{
187 return reinterpret_cast<HANDLE>(CONST_CAST(TStatic*,this)->SendMessage(STM_GETIMAGE,static_cast<TParam2>(imageType)));
188}
189
190//
191/// Set handle of image.
192//
194{
196 return reinterpret_cast<HANDLE>(SendMessage(STM_SETIMAGE, static_cast<TParam1>(imageType), reinterpret_cast<TParam2>(image)));
197}
198
199//
200/// Return the current length of the text in the control, excluding the terminating null character.
201//
202inline int TStatic::GetTextLen() const {
204 return ::GetWindowTextLength(GetHandle());
205}
206
207//
208/// Retrieves the static control's text, stores it in the str argument of maxChars
209/// size, and returns the number of characters copied, excluding the terminating null character.
210//
211inline int TStatic::GetText(LPTSTR str, int maxChars) const {
213 return ::GetWindowText(GetHandle(), str, maxChars);
214}
215
216//
217/// String-aware overload
218//
219inline tstring TStatic::GetText() const {
220 return TWindow::GetWindowText();
221}
222
223//
224/// Sets the static control's text to the string supplied in str.
225//
226inline void TStatic::SetText(LPCTSTR str) {
229}
230
231//
232/// Sets the static control's text to the resource string identified by the given id.
233//
237
238//
239/// Returns the size of the static control's transfer buffer; including space for the terminating null character.
240//
242 return TextLimit;
243}
244
245//
246/// Sets the size of the static control's transfer buffer; including space for the terminating null character.
247//
249 TextLimit = textlimit;
250}
251
252} // OWL namespace
253
254
255#endif // OWL_STATIC_H
#define PRECONDITION(condition)
Definition checks.h:227
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
void SetText(const tstring &str)
Definition static.h:64
uint GetTextLimit() const
Returns the length limit of the control's text.
Definition static.h:241
tstring GetText() const
String-aware overload.
Definition static.h:219
void SetTextLimit(uint textlimit)
Sets the size of the static control's transfer buffer; including space for the terminating null chara...
Definition static.h:248
TTransferBufferFieldType TransferBufferFieldType
Definition static.h:111
int GetTextLen() const
Return the current length of the text in the control, excluding the terminating null character.
Definition static.h:202
HICON GetIcon() const
Returns the handle of the icon used for this static control.
Definition static.h:168
HANDLE GetImage(TImageType imageType=Bitmap) const
Return handle of image used for static control.
Definition static.h:184
void SetText(LPCTSTR str)
Sets the static control's text to the string supplied in str.
Definition static.h:226
TTransferBufferFieldType
Definition static.h:97
@ tbftCharArray
Definition static.h:98
HANDLE SetImage(HANDLE image, TImageType imageType=Bitmap)
Set handle of image.
Definition static.h:193
HICON SetIcon(HICON)
Sets the handle of the icon.
Definition static.h:176
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
tstring LoadString(uint id) const
Definition window.h:608
tstring GetWindowText() const
String-aware overload.
Definition window.cpp:4415
void SetWindowText(LPCTSTR str)
Sets the window's text to the given string (by copying).
Definition window.h:2669
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
Definition of class TControl.
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define DECLARE_STREAMABLE_OWL(cls, ver)
Definition objstrm.h:1529
#define DECLARE_STREAMABLE_INLINES(cls)
Definition objstrm.h:1538
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define public_data
Definition defs.h:207
#define CONST_CAST(targetType, object)
Definition defs.h:273
#define _OWLCLASS
Definition defs.h:338