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
14#if defined(__BORLANDC__)
15# pragma option -w-ccc // Disable "Condition is always true/false"
16#endif
17
18namespace owl {
19
22
23static tchar countName[] = _T("Count");
24static tchar valueName[] = _T("Value");
25
26//
27// Build a response table for all messages/commands handled
28// by the application.
29//
30DEFINE_RESPONSE_TABLE1(TMemComboBox, TComboBox)
33
34
35//--------------------------------------------------------
36// TMemComboBox Constructor
37//
38TMemComboBox::TMemComboBox(TWindow* parent, int id, int x, int y, int w, int h,
39 const tstring& name, uint textLimit,
40 uint itemLimit, TModule* module)
41:
42 TComboBox(parent, id, x, y, w, h, CBS_DROPDOWN, textLimit, module),
43 Name(name),
44 ItemLimit(itemLimit),
45 TransferBufferFieldType(tbftCharArray)
46{
47}
48//
51:
52 TComboBox(parent, resId, textLimit, module),
53 Name(name),
54 ItemLimit(itemLimit),
55 TransferBufferFieldType(tbftCharArray)
56{
57}
58//
60{
61 return _T("History Lists\\");
62}
63//
65{
67
68 // Call base class function.
70}
71//
73{
74 // Call base class function.
76
78}
79//
80void
82{
84
86
88
89 int count = section.ReadInteger(countName);
90
93 for(int i = 0; i < count; i++)
94 {
95 wsprintf(nameBuf, _T("%s%d"), valueName, i);
96 if (section.ReadString(nameBuf,valBuf,MAX_PATH,_T("")))
97 {
99 }
100 }
101
102 wsprintf(nameBuf, _T("%s"), valueName);
103 if (section.ReadString(nameBuf, valBuf, MAX_PATH, _T("")))
105 else
106 SetWindowText(_T(""));
107}
108//
109void
111{
115
118 if(::_tcslen(nameBuf))
120
121 uint count = GetCount();
122 if(count > ItemLimit)
123 count = ItemLimit;
124 section.WriteInteger(countName, count);
125
127
128 wsprintf(nameBuf, _T("%s"), valueName);
129 if (GetWindowText(valBuf, MAX_PATH) > 0)
130 section.WriteString(nameBuf, valBuf);
131 else
132 section.EraseEntry(nameBuf); // If the combo box text is empty, clear the old value
133
134
135 for(int i = 0; i < (int)count; i++)
136 {
137 wsprintf(nameBuf, _T("%s%d"), valueName, i);
138 if(GetString(valBuf, i) > 0)
139 section.WriteString(nameBuf, valBuf);
140 }
141}
142//
145{
146 return new TRegConfigFile(_T("OWL Next"));
147}
148//
150{
152
155 if (::_tcslen(nameBuf))
156 {
158 SetSelIndex(0); // AddToList() will clear the text box, so the need to restore it
159 }
160}
161//
163{
164 int index = FindStringExact(text,-1);
165 if (index != CB_ERR)
166 DeleteString(index);
167 InsertString(text, 0);
168}
169
171{
172 uint n = 0;
174 {
175 case tbftCharArray:
176 n = TransferCharArray(buffer, direction);
177 break;
178
179 case tbftString:
180 n = TransferString(buffer, direction);
181 break;
182
183 case tbftComboBoxData:
185 break;
186
187 default:
188 CHECKX(false, _T("TMemComboBox::Transfer: Unknown field type."));
189 }
190 return n;
191}
192
197
202
203uint
204TMemComboBox::TransferCharArray(void* buffer, TTransferDirection direction)
205{
206 if (!buffer && direction != tdSizeData) return 0;
207 tchar* s = static_cast<tchar*>(buffer);
208 if (direction == tdGetData)
209 GetText(s, TextLimit);
210 else if (direction == tdSetData)
211 SetText(s);
212 return TextLimit * sizeof(tchar);
213}
214
215uint
216TMemComboBox::TransferString(void* buffer, TTransferDirection direction)
217{
218 if (!buffer && direction != tdSizeData) return 0;
219 tstring& s = *static_cast<tstring*>(buffer);
220 if (direction == tdGetData)
221 s = GetText();
222 else if (direction == tdSetData)
223 SetText(s);
224 return sizeof(tstring);
225}
226
228
229#if OWL_PERSISTENT_STREAMS
230
231//
232// Reads an instance of TMemComboBox from the supplied ipstream
233//
234void*
235TMemComboBox::Streamer::Read(ipstream& is, uint32 /*version*/) const
236{
237 ReadBaseObject((TComboBox*)GetObject(), is);
238 is >> GetObject()->Name;
239 is >> GetObject()->ItemLimit;
240 return GetObject();
241}
242
243//
244// Writes the TComboBox to the supplied opstream
245//
246void
247TMemComboBox::Streamer::Write(opstream& os) const
248{
249 WriteBaseObject((TComboBox*)GetObject(), os);
250 os << GetObject()->Name;
251 os << GetObject()->ItemLimit;
252}
253#endif
254
255} // 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:149
virtual TConfigFile * CreateConfigFile()
Definition memcbox.cpp:144
void SetTransferBufferFieldType(TTransferBufferFieldType)
Definition memcbox.cpp:198
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:170
TTransferBufferFieldType GetTransferBufferFieldType() const
Definition memcbox.cpp:193
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:38
virtual tstring GetSectionName()
Definition memcbox.cpp:59
void CleanupWindow() override
Definition memcbox.cpp:64
void SetupWindow() override
Definition memcbox.cpp:72
virtual void AddToList(TCHAR *text)
Definition memcbox.cpp:162
void LoadContents()
Definition memcbox.cpp:81
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
tstring GetWindowText() const
String-aware overload.
Definition window.cpp:4415
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
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