OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
transfer.cpp
Go to the documentation of this file.
1//
2/// \file transfer.cpp
3/// Utilities for transferring data in and out of controls
4//
5// Part of OWLNext - the next generation Object Windows Library
6// Copyright © 2010-2011 Vidar Hasfjord
7//
8// For more information, including license details, see
9// http://owlnext.sourceforge.net
10//
11
12#include <owl/pch.h>
13#include <owl/transfer.h>
14
15#include <owl/edit.h>
16#include <owl/listbox.h>
17#include <owl/combobox.h>
18#include <owl/combobex.h>
19#include <owl/checkbox.h>
20#include <owl/checklst.h>
21#include <owl/radiobut.h>
22#include <owl/scrollba.h>
23#include <owl/slider.h>
24#include <owl/static.h>
25#include <owl/datetime.h>
26#include <owl/hotkey.h>
27#include <owl/ipaddres.h>
28#include <owl/monthcal.h>
29#include <owl/appdict.h>
30#include <owl/except.rh>
31
32namespace owl {
33
34namespace
35{
36
37 template <class TRadioButtonFunc>
39 {
40 HWND h = first;
41 for (int i = 0; h != nullptr; ++i)
42 {
43 TRadioButton c(h);
44 if (!f(c, i))
45 break;
46 h = c.GetWindow(GW_HWNDNEXT);
47 if (GetWindowLong(h, GWL_STYLE) & WS_GROUP) // at next group?
48 break;
49 }
50 return f;
51 }
52
53 struct TSetRadioButton
54 {
55 int index;
56 bool operator()(TRadioButton& c, int i) const
57 {
58 c.Check(i == index);
59 return true;
60 }
61 };
62
63 struct TGetRadioButton
64 {
65 int index;
66 bool operator()(TRadioButton& c, int i)
67 {
68 bool found = c.IsWindowEnabled() && c.IsChecked();
69 if (found) index = i;
70 return !found;
71 }
72 };
73
74} // namespace
75
77{
78 TSetRadioButton f = {selIndex};
80}
81
83{
84 TGetRadioButton f = {-1};
85 return IterateRadioButtons(first, f).index;
86}
87
88void TransferCheckBoxData(const TTransferInfo& i, HWND ctrl, bool& b)
89{
90 if (i.Operation == tdSetData)
91 CheckDlgButton(ctrl, b);
92 else if (i.Operation == tdGetData)
93 b = IsChecked(ctrl);
94}
95
96void TransferCheckBoxData(const TTransferInfo& i, HWND ctrl, UINT& state)
97{
98 if (i.Operation == tdSetData)
99 CheckDlgButton(GetParent(ctrl), GetDlgCtrlID(ctrl), state);
100 else if (i.Operation == tdGetData)
101 state = IsDlgButtonChecked(GetParent(ctrl), GetDlgCtrlID(ctrl));
102}
103
104namespace
105{
106
107 //
108 // Returns a reference to an TWindow derivative object given its window handle.
109 // The last parameter is not used and is just a workaround for a BC++ 5.02 compiler bug.
110 //
111 template <class TControlType>
112 TControlType& GetControlObject(HWND const parent, HWND ctrl, TControlType* = 0)
113 {
115 TApplication& a = *GetApplicationObject();
116 TWindow* w = a.GetWindowPtr(ctrl);
117 if (!w) TXWindow::Raise(a.GetWindowPtr(parent), IDS_TRANSFERCONTROLMISSING);
118 return dynamic_cast<TControlType&>(*w);
119 }
120
121}
122
124{
125 // A TCheckList object must exist; locate it.
126 //
127 TCheckList& c = GetControlObject<TCheckList>(i.Window, ctrl, static_cast<TCheckList*>(nullptr));
128 c.Transfer(data, i.Operation);
129}
130
132{
133 TComboBox c(ctrl);
134 c.Transfer(data, i.Operation);
135}
136
138{
139 if (i.Operation == tdSetData)
140 {
141 TComboBox c(ctrl);
142 c.SetSelIndex(selIndex);
143 }
144 else if (i.Operation == tdGetData)
145 {
146 TComboBox c(ctrl);
147 selIndex = c.GetSelIndex();
148 }
149}
150
152{
153 if (i.Operation == tdSetData)
154 {
155 TComboBox c(ctrl);
156 if (exact)
157 c.SetSelStringExact(selString);
158 else
159 c.SetSelString(selString);
160 }
161 else if (i.Operation == tdGetData)
162 {
163 TComboBox c(ctrl);
164 selString = c.GetSelString();
165 }
166}
167
169{
170 TComboBoxEx c(ctrl);
171 c.Transfer(data, i.Operation);
172}
173
175{
176 if (i.Operation == tdSetData)
177 {
178 SetDlgItemText(ctrl, text);
179 }
180 else if (i.Operation == tdGetData)
181 {
182 text = GetDlgItemText(ctrl);
183 }
184}
185
187{
188 TDateTimePicker c(ctrl);
189 c.Transfer(data, i.Operation);
190}
191
193{
194 if (i.Operation == tdSetData)
195 {
196 TDateTimePicker c(ctrl);
197 c.SetTime(selTime);
198 }
199 else if (i.Operation == tdGetData)
200 {
201 TDateTimePicker c(ctrl);
202 selTime = c.GetTime();
203 }
204}
205
207{
208 if (i.Operation == tdSetData)
209 {
210 TDateTimePicker c(ctrl);
211 if (selTime.length() == 0)
212 c.SetNoTime();
213 else
214 c.SetTime(selTime); // Throws on parsing failure!
215 }
216 else if (i.Operation == tdGetData)
217 {
218 TDateTimePicker c(ctrl);
219 selTime = c.GetWindowText();
220 }
221}
222
224{
225 THotKey c(ctrl);
226 c.Transfer(key, i.Operation);
227}
228
230{
231 TIPAddress c(ctrl);
232 c.Transfer(address, i.Operation);
233}
234
236{
237 if (i.Operation == tdSetData)
238 {
239 TIPAddress c(ctrl);
240 c.SetAddress(address);
241 }
242 else if (i.Operation == tdGetData)
243 {
244 TIPAddress c(ctrl);
245 address = c.GetAddress();
246 }
247}
248
250{
251 TListBox c(ctrl);
252 c.Transfer(data, i.Operation);
253}
254
256{
257 if (i.Operation == tdSetData)
258 {
259 TListBox c(ctrl);
260 c.SetSelIndex(selIndex);
261 }
262 else if (i.Operation == tdGetData)
263 {
264 TListBox c(ctrl);
265 selIndex = c.GetSelIndex();
266 }
267}
268
270{
271 if (i.Operation == tdSetData)
272 {
273 TListBox c(ctrl);
274 if (exact)
275 c.SetSelStringExact(selString);
276 else
277 c.SetSelString(selString);
278 }
279 else if (i.Operation == tdGetData)
280 {
281 TListBox c(ctrl);
282 selString = c.GetSelString();
283 }
284}
285
287{
288 TMonthCalendar c(ctrl);
289 c.Transfer(data, i.Operation);
290}
291
293{
294 if (i.Operation == tdSetData)
295 {
296 TMonthCalendar c(ctrl);
297 c.SetCurSel(curSel);
298 }
299 else if (i.Operation == tdGetData)
300 {
301 TMonthCalendar c(ctrl);
302 c.GetCurSel(curSel);
303 }
304}
305
306void TransferMonthCalendarData(const TTransferInfo& i, HWND ctrl, std::pair<TSystemTime, TSystemTime>& rangeSel)
307{
308 if (i.Operation == tdSetData)
309 {
310 TMonthCalendar c(ctrl);
311 c.SetSelRange(rangeSel.first, rangeSel.second);
312 }
313 else if (i.Operation == tdGetData)
314 {
315 TMonthCalendar c(ctrl);
316 c.GetSelRange(rangeSel.first, rangeSel.second);
317 }
318}
319
321{
322 if (i.Operation == tdSetData)
323 {
325 }
326 else if (i.Operation == tdGetData)
327 {
329 }
330}
331
333{
334 TScrollBar c(ctrl);
335 c.Transfer(data, i.Operation);
336}
337
339{
340 if (i.Operation == tdSetData)
341 {
342 TScrollBar c(ctrl);
343 c.SetPosition(position);
344 }
345 else if (i.Operation == tdGetData)
346 {
347 TScrollBar c(ctrl);
348 position = c.GetPosition();
349 }
350}
351
353{
354 TSlider c(ctrl);
355 c.Transfer(data, i.Operation);
356}
357
359{
360 if (i.Operation == tdSetData)
361 {
362 TSlider c(ctrl);
363 c.SetPosition(position);
364 }
365 else if (i.Operation == tdGetData)
366 {
367 TSlider c(ctrl);
368 position = c.GetPosition();
369 }
370}
371
375
377{
378 TTransferInfo i = {GetHandle(), d};
379 TransferFunction(i);
380}
381
386
387} // OWL namespace
Definition of class TAppDictionary.
Definition of class TCheckBox.
Definition of class TCheckList, an ownerdrawn listbox to select multiple items.
#define PRECONDITION(condition)
Definition checks.h:227
TCheckList is an owner-drawn list box to select multiple items.
Definition checklst.h:114
An interface object that represents a transfer buffer for a TComboBox.
Definition combobox.h:182
ComboBoxEx controls are combo box controls that provide native support for item images.
Definition combobex.h:89
You can use TComboBox to create a combo box or a combo box control in a parent TWindow,...
Definition combobox.h:47
TDelegatedTransferDialog(TWindow *parent, TResId id, TTransferFunction f, TModule *module=0)
Definition transfer.cpp:382
TWindow mix-in Delegates the job of transferring data to the given function object.
Definition transfer.h:1524
std::function< TTransferFunctionSignature > TTransferFunction
Definition transfer.h:1528
virtual void TransferData(TTransferDirection d)
TWindow override Dispatches to the transfer function.
Definition transfer.cpp:376
TDelegatedTransferWindow(TTransferFunction f)
Definition transfer.cpp:372
Typically used to obtain information from a user, a dialog box is a window inside of which other cont...
Definition dialog.h:85
THotKey encapsulates the hot-key control, a window that allows the user to enter a combination of key...
Definition hotkey.h:33
Also used as transfer buffer.
Definition ipaddres.h:32
Used to transfer the contents of a list box.
Definition listbox.h:170
An interface object that represents a corresponding list box element.
Definition listbox.h:43
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TScrollBar objects represent standalone vertical and horizontal scroll bar controls.
Definition scrollba.h:41
An abstract base class derived from TScrollBar, TSlider defines the basic behavior of sliders (contro...
Definition slider.h:55
TSystemTime is a class derived from the structure SYSTEMTIME.
Definition wsyscls.h:420
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
static void Raise(TWindow *win=nullptr, uint resourceId=IDS_INVALIDWINDOW)
Creates the TXWindow exception and throws it.
Definition window.cpp:4612
Definition of class TComboBoxEx.
Definition of class TComboBox and TComboBoxData the base class for all combobox controls.
Definition of class TDateTimePicker.
Definition of class TEdit.
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
@ 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
Definition of class THotKey.
Definition of class TListBox and TlistBoxData.
Definition of class TMonthCalendar.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
void TransferScrollBarData(const TTransferInfo &, HWND ctrl, TScrollBarData &data)
Transfers all the data for a scroll bar control.
Definition transfer.cpp:332
void TransferHotKeyData(const TTransferInfo &, HWND ctrl, uint16 &key)
Transfers the hotkey value of a hotkey control.
Definition transfer.cpp:223
void TransferComboBoxExData(const TTransferInfo &, HWND ctrl, TComboBoxExData &data)
Transfers all the data for an extended combo box control.
Definition transfer.cpp:168
void SetDlgItemText(HWND ctrl, const tstring &text)
String overload.
Definition transfer.h:63
void TransferCheckListData(const TTransferInfo &, HWND ctrl, TCheckListData &data)
Transfers all the data for a check list box.
Definition transfer.cpp:123
TApplication * GetApplicationObject(uint pid=0)
Global function that calls GetApplication() on owl's app-dictionary.
Definition appdict.cpp:298
void SetSelectedRadioButtonIndex(HWND firstCtrl, int selIndex)
Selects the control with the given zero-based index in the group of controls starting with the given ...
Definition transfer.cpp:76
void TransferRadioButtonData(const TTransferInfo &, HWND ctrl, int &selIndex)
Transfers the index of the selected radio button within a group.
Definition transfer.cpp:320
unsigned long uint32
Definition number.h:34
void TransferComboBoxData(const TTransferInfo &, HWND ctrl, TComboBoxData &data)
Transfers all the data for a combo box control.
Definition transfer.cpp:131
void TransferListBoxData(const TTransferInfo &, HWND ctrl, TListBoxData &data)
Transfers all the data for a list box control.
Definition transfer.cpp:249
bool IsChecked(HWND ctrl)
Returns true if the given control has BST_CHECKED state.
Definition transfer.h:69
unsigned short uint16
Definition number.h:33
std::string tstring
Definition defs.h:79
void TransferIPAddressData(const TTransferInfo &, HWND ctrl, TIPAddressBits &data)
Transfers the address of a IP address control as an object.
Definition transfer.cpp:229
void TransferMonthCalendarData(const TTransferInfo &, HWND ctrl, TMonthCalendarData &data)
Transfers all the data for a calendar control.
Definition transfer.cpp:286
void TransferDateTimePickerData(const TTransferInfo &, HWND ctrl, TDateTimePickerData &data)
Transfers all the data for a date and time picker control.
Definition transfer.cpp:186
void TransferDlgItemText(const TTransferInfo &, HWND ctrl, tstring &text)
Transfers the text contents of a control.
Definition transfer.cpp:174
void TransferCheckBoxData(const TTransferInfo &, HWND ctrl, bool &b)
Transfers the state of the checkbox to the given bool variable.
Definition transfer.cpp:88
void CheckDlgButton(HWND ctrl, bool checked=true)
Sets the state of the given control to BST_CHECKED (or BST_UNCHECKED).
Definition transfer.h:87
tstring GetDlgItemText(HWND ctrl)
String overload.
Definition transfer.h:57
void TransferSliderData(const TTransferInfo &, HWND ctrl, TScrollBarData &data)
Transfers all the data for a slider control.
Definition transfer.cpp:352
int GetSelectedRadioButtonIndex(HWND firstCtrl)
Returns the zero-based index of the selected radiobutton in the group of controls starting with the g...
Definition transfer.cpp:82
Definition of class TRadioButton.
Definition of class TScrollBar.
Definition of classes TSlider & TVSlider.
Definition of class TStatic, the class for static controls and base for any control that manages simp...
The TScrollBarData structure contains integer values that represent a range of thumb positions on the...
Definition scrollba.h:148
Used to pass information to transfer functions.
Definition transfer.h:152
Utilities for transferring data in and out of controls.