OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
memcbox.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows, OWL NExt
3// Copyright 1998-1999 by Yura Bidus. All Rights reserved.
4//
5/// \file
6/// Source file for implementation of TMemComboBox (TComboBox).
7/// (Generated by OWL 6.x Class Expert for MS VC++, Version 1.5)
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10
11#include <owl/configfl.h>
12#include <owl/memcbox.h>
13#include <memory>
14
15#if defined(__BORLANDC__)
16# pragma option -w-ccc // Disable "Condition is always true/false"
17#endif
18
19using namespace std;
20
21namespace owl {
22
25
26static tchar countName[] = _T("Count");
27static tchar valueName[] = _T("Value");
28
29//
30// Build a response table for all messages/commands handled
31// by the application.
32//
33DEFINE_RESPONSE_TABLE1(TMemComboBox, TComboBox)
36
37
38//--------------------------------------------------------
39// TMemComboBox Constructor
40//
41TMemComboBox::TMemComboBox(TWindow* parent, int id, int x, int y, int w, int h,
42 const tstring& name, uint textLimit,
43 uint itemLimit, TModule* module)
44:
45 TComboBox(parent, id, x, y, w, h, CBS_DROPDOWN, textLimit, module),
46 Name(name),
47 ItemLimit(itemLimit),
48 TransferBufferFieldType(tbftCharArray)
49{
50}
51//
54:
55 TComboBox(parent, resId, textLimit, module),
56 Name(name),
57 ItemLimit(itemLimit),
58 TransferBufferFieldType(tbftCharArray)
59{
60}
61//
63{
64 return _T("History Lists\\");
65}
66//
68{
70
71 // Call base class function.
73}
74//
76{
77 // Call base class function.
79
81}
82//
83void
85{
87
89
91
92 int count = section.ReadInteger(countName);
93
96 for(int i = 0; i < count; i++)
97 {
98 wsprintf(nameBuf, _T("%s%d"), valueName, i);
99 if (section.ReadString(nameBuf,valBuf,MAX_PATH,_T("")))
100 {
102 }
103 }
104
105 wsprintf(nameBuf, _T("%s"), valueName);
106 if (section.ReadString(nameBuf, valBuf, MAX_PATH, _T("")))
108 else
109 SetWindowText(_T(""));
110}
111//
112void
114{
118
119 auto text = GetText();
120 if (!text.empty())
121 {
122 AddToList(data(text)); // Unfortunately, AddToList is virtual and not const-correct.
123 section.WriteString(valueName, text);
124 }
125 else
126 section.EraseEntry(valueName); // If the combo box text is empty, clear the old value
127
128 uint count = GetCount();
129 if (count > ItemLimit)
130 count = ItemLimit;
131 section.WriteInteger(countName, count);
132
133 for (auto i = 0; i != count; ++i)
134 if (const auto s = GetString(i); !s.empty())
135 section.WriteString(valueName + to_tstring(i), s);
136}
137//
140{
141 return new TRegConfigFile(_T("OWL Next"));
142}
143//
145{
147
150 if (::_tcslen(nameBuf))
151 {
153 SetSelIndex(0); // AddToList() will clear the text box, so the need to restore it
154 }
155}
156//
158{
159 int index = FindStringExact(text,-1);
160 if (index != CB_ERR)
161 DeleteString(index);
162 InsertString(text, 0);
163}
164
166{
167 uint n = 0;
169 {
170 case tbftCharArray:
171 n = TransferCharArray(buffer, direction);
172 break;
173
174 case tbftString:
175 n = TransferString(buffer, direction);
176 break;
177
178 case tbftComboBoxData:
180 break;
181
182 default:
183 CHECKX(false, _T("TMemComboBox::Transfer: Unknown field type."));
184 }
185 return n;
186}
187
192
197
198uint
199TMemComboBox::TransferCharArray(void* buffer, TTransferDirection direction)
200{
201 if (!buffer && direction != tdSizeData) return 0;
202 tchar* s = static_cast<tchar*>(buffer);
203 if (direction == tdGetData)
204 GetText(s, TextLimit);
205 else if (direction == tdSetData)
206 SetText(s);
207 return TextLimit * sizeof(tchar);
208}
209
210uint
211TMemComboBox::TransferString(void* buffer, TTransferDirection direction)
212{
213 if (!buffer && direction != tdSizeData) return 0;
214 tstring& s = *static_cast<tstring*>(buffer);
215 if (direction == tdGetData)
216 s = GetText();
217 else if (direction == tdSetData)
218 SetText(s);
219 return sizeof(tstring);
220}
221
223
224#if OWL_PERSISTENT_STREAMS
225
226//
227// Reads an instance of TMemComboBox from the supplied ipstream
228//
229void*
230TMemComboBox::Streamer::Read(ipstream& is, uint32 /*version*/) const
231{
232 ReadBaseObject((TComboBox*)GetObject(), is);
233 is >> GetObject()->Name;
234 is >> GetObject()->ItemLimit;
235 return GetObject();
236}
237
238//
239// Writes the TComboBox to the supplied opstream
240//
241void
242TMemComboBox::Streamer::Write(opstream& os) const
243{
244 WriteBaseObject((TComboBox*)GetObject(), os);
245 os << GetObject()->Name;
246 os << GetObject()->ItemLimit;
247}
248#endif
249
250} // OWL namespace
#define CHECKX(condition, message)
Definition checks.h:245
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
You can use TComboBox to create a combo box or a combo box control in a parent TWindow,...
Definition combobox.h:47
tstring GetText() const
Definition combobox.h:64
virtual int GetString(TCHAR *str, int index) const
Retrieve the contents of the string at the passed index of list part of the associated combobox,...
Definition combobox.h:480
void SetupWindow()
Limits the amount of text that the user can enter in the combo box's edit control to the value of Tex...
Definition combobox.cpp:418
virtual int DeleteString(int index)
Deletes the string at the passed index in the associated list part of a combo box.
Definition combobox.h:376
virtual int InsertString(LPCTSTR str, int index)
Insert a string in list part of the associated combobox at the passed index, returning the index of t...
Definition combobox.h:366
virtual int AddString(LPCTSTR str)
Adds a string to an associated list part of a combo box.
Definition combobox.h:356
void CleanupWindow()
Cleanup aliases created in SetupWindow.
Definition combobox.cpp:438
virtual int GetCount() const
Return the number of entries in list part of the associated combobox.
Definition combobox.h:419
virtual int SetSelIndex(int index)
Selects a string of characters in a combo box.
Definition combobox.h:555
void Transfer(TComboBoxData &data, TTransferDirection direction)
Definition combobox.h:133
virtual int FindStringExact(LPCTSTR find, int startIndex=-1) const
Return the index of the first string in list part of the associated combobox which is exactly same wi...
Definition combobox.h:465
void SetText(LPCTSTR str)
Selects the first string in the associated list box that begins with the supplied str.
Definition combobox.cpp:249
Save/Load configuration parameters Base abstract class.
Definition configfl.h:48
Small inline wrapper around Section.
Definition configfl.h:163
void EvKillFocus(HWND hWndGetFocus)
Definition memcbox.cpp:144
virtual TConfigFile * CreateConfigFile()
Definition memcbox.cpp:139
void SetTransferBufferFieldType(TTransferBufferFieldType)
Definition memcbox.cpp:193
TTransferBufferFieldType TransferBufferFieldType
Definition memcbox.h:97
auto Transfer(void *buffer, TTransferDirection) -> uint override
TWindow override; transfers data of the configured type to or from the given buffer.
Definition memcbox.cpp:165
TTransferBufferFieldType GetTransferBufferFieldType() const
Definition memcbox.cpp:188
TMemComboBox(TWindow *parent, int id, int x, int y, int w, int h, const tstring &name, uint textLimit=255, uint itemLimit=25, TModule *=0)
Definition memcbox.cpp:41
virtual tstring GetSectionName()
Definition memcbox.cpp:62
void CleanupWindow() override
Definition memcbox.cpp:67
void SetupWindow() override
Definition memcbox.cpp:75
virtual void AddToList(TCHAR *text)
Definition memcbox.cpp:157
void LoadContents()
Definition memcbox.cpp:84
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
Derived from TConfigFile, TRegConfigFile is used to maintain configuration settings in the registry.
Definition configfl.h:329
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
void EvKillFocus(HWND hWndGetFocus)
Handle WM_KILLFOCUS so that we can have a parent window hold onto our Handle and possibly restore foc...
Definition window.cpp:1611
void SetWindowText(LPCTSTR str)
Sets the window's text to the given string (by copying).
Definition window.h:2669
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
This header file declares the class: TConfigFile,TIniConfigFile, TRegConfigFile and TConfigFileSectio...
#define MAX_PATH
Definition cygwin.h:98
#define _tcslen
Definition cygwin.h:74
#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
Class definition for TMemComboBox (TComboBox).
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_WM_KILLFOCUS
Definition edit.cpp:85
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
auto to_tstring(const T &v) -> tstring
Definition defs.h:82