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
transfer.h
Go to the documentation of this file.
1//
2/// \file transfer.h
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#ifndef OWL_TRANSFER_H
13#define OWL_TRANSFER_H
14
15#if defined(BI_COMP_BORLANDC)
16# pragma warn -inl // Disable warning "Functions containing 'statement' is not expanded inline".
17#endif
18
19#include <owl/dialog.h>
20#include <utility>
21
22#include <functional>
23#include <algorithm>
24#include <type_traits>
25#include <initializer_list>
26
27namespace owl {
28
29class _OWLCLASS TComboBoxData;
30class _OWLCLASS TComboBoxExData;
31class _OWLCLASS TCheckListData;
32class _OWLCLASS TDateTimePickerData;
33class _OWLCLASS TIPAddressBits;
34class _OWLCLASS TListBoxData;
35struct _OWLCLASS TMonthCalendarData;
36struct _OWLCLASS TScrollBarData;
37class _OWLCLASS TSystemTime;
38
39//
40/// \name Overloaded global functions
41/// Avoid hiding - we are adding overloads of these.
42/// @{
43//
44using ::GetDlgItemText;
45using ::SetDlgItemText;
46using ::CheckDlgButton;
47
48/// @}
49
50//
51/// \name Utility functions for control data transfer
52/// @{
53
54//
55/// String overload
56//
58{return TWindow(GetParent(ctrl)).GetDlgItemText(GetDlgCtrlID(ctrl));}
59
60//
61/// String overload
62//
63inline _OWLFUNC(void) SetDlgItemText(HWND ctrl, const tstring& text)
64{::SetDlgItemText(GetParent(ctrl), GetDlgCtrlID(ctrl), text.c_str());}
65
66//
67/// Returns true if the given control has BST_CHECKED state.
68//
69inline _OWLFUNC(bool) IsChecked(HWND ctrl)
70{return ::IsDlgButtonChecked(GetParent(ctrl), GetDlgCtrlID(ctrl)) == BST_CHECKED;}
71
72//
73/// Returns true if the given control has BST_UNCHECKED state.
74//
75inline _OWLFUNC(bool) IsUnchecked(HWND ctrl)
76{return ::IsDlgButtonChecked(GetParent(ctrl), GetDlgCtrlID(ctrl)) == BST_UNCHECKED;}
77
78//
79/// Returns true if the given control has BST_INDETERMINATE state.
80//
81inline _OWLFUNC(bool) IsIndeterminate(HWND ctrl)
82{return ::IsDlgButtonChecked(GetParent(ctrl), GetDlgCtrlID(ctrl)) == BST_INDETERMINATE;}
83
84//
85/// Sets the state of the given control to BST_CHECKED (or BST_UNCHECKED).
86//
87inline _OWLFUNC(void) CheckDlgButton(HWND ctrl, bool checked = true)
88{::CheckDlgButton(GetParent(ctrl), ::GetDlgCtrlID(ctrl), checked ? BST_CHECKED : BST_UNCHECKED);}
89
90//
91/// Sets the state of the given control to BST_UNCHECKED (or BST_CHECKED).
92//
93inline _OWLFUNC(void) UncheckDlgButton(HWND ctrl, bool unchecked = true)
94{::CheckDlgButton(GetParent(ctrl), ::GetDlgCtrlID(ctrl), unchecked ? BST_UNCHECKED : BST_CHECKED);}
95
96//
97/// Returns the zero-based index of the selected radiobutton in the group of controls starting
98/// with the given control. The function searches controls until the next control with the
99/// WS_GROUP is found.
100//
102
103//
104/// Selects the control with the given zero-based index in the group of controls starting with
105/// the given control. The search for the control ends when the next control with the WS_GROUP
106/// style is found, i.e. the function will not select a control beyond the first group.
107//
109
110/// @}
111
112//
113/// \name Utility functions for control data transfer - integer child ID overloads
114/// @{
115
116inline _OWLFUNC(tstring) GetDlgItemText(HWND parent, int ctrl)
117{return TWindow(parent).GetDlgItemText(ctrl);}
118
119inline _OWLFUNC(void) SetDlgItemText(HWND parent, int ctrl, const tstring& text)
120{::SetDlgItemText(parent, ctrl, text.c_str());}
121
122inline _OWLFUNC(bool) IsChecked(HWND parent, int ctrl)
123{return IsChecked(GetDlgItem(parent, ctrl));}
124
125inline _OWLFUNC(bool) IsUnchecked(HWND parent, int ctrl)
126{return IsUnchecked(GetDlgItem(parent, ctrl));}
127
128inline _OWLFUNC(bool) IsIndeterminate(HWND parent, int ctrl)
129{return IsIndeterminate(GetDlgItem(parent, ctrl));}
130
131inline _OWLFUNC(void) CheckDlgButton(HWND parent, int ctrl, int state)
132{::CheckDlgButton(parent, ctrl, static_cast<UINT>(state));}
133
134inline _OWLFUNC(void) CheckDlgButton(HWND parent, int ctrl, bool checked = true)
135{CheckDlgButton(GetDlgItem(parent, ctrl), checked);}
136
137inline _OWLFUNC(void) UncheckDlgButton(HWND parent, int ctrl, bool unchecked = true)
138{UncheckDlgButton(GetDlgItem(parent, ctrl), unchecked);}
139
140inline _OWLFUNC(int) GetSelectedRadioButtonIndex(HWND parent, int ctrl)
141{return GetSelectedRadioButtonIndex(GetDlgItem(parent, ctrl));}
142
143inline _OWLFUNC(void) SetSelectedRadioButtonIndex(HWND parent, int ctrl, int selIndex)
144{SetSelectedRadioButtonIndex(GetDlgItem(parent, ctrl), selIndex);}
145
146/// @}
147
148//
149/// Used to pass information to transfer functions.
150//
156
157//
158/// \name Transfer utility functions
159/// @{
160
161//
162/// Transfers the state of the checkbox to the given bool variable.
163//
164_OWLFUNC(void) TransferCheckBoxData(const TTransferInfo&, HWND ctrl, bool& b);
165
166//
167/// Transfers the state of the checkbox to the given integer variable.
168/// This overload supports tri-state check boxes (BST_CHECKED, BST_INDETERMINATE, BST_UNCHECKED).
169//
170_OWLFUNC(void) TransferCheckBoxData(const TTransferInfo&, HWND ctrl, UINT& state);
171
172//
173/// Transfers all the data for a check list box.
174//
176
177//
178/// Transfers all the data for a combo box control.
179//
181
182//
183/// Transfers the selection index of a combo box control.
184//
186
187//
188/// Transfers the selection string of a combo box control.
189//
190_OWLFUNC(void) TransferComboBoxData(const TTransferInfo&, HWND ctrl, tstring& selString, bool exact = false);
191
192//
193/// Transfers all the data for an extended combo box control.
194//
196
197//
198/// Transfers all the data for a date and time picker control.
199//
201
202//
203/// Transfers the selected date and time of a date and time picker control.
204//
206
207//
208/// Transfers the selected date and time of a date and time picker control as a string.
209/// If the string is empty and the transfer direction is tdSetData, the control is set to no "no date", provided
210/// that the control has the DTS_SHOWNONE style. Otherwise the control is set to the default (current) date and time.
211/// If the string is non-empty, the transfer direction is tdSetData, and parsing fails, a TXOwl exception is thrown.
212//
214
215//
216/// Transfers the text contents of a control.
217//
219
220//
221/// Contains stream formatting parameters for use with TransferDlgItemText.
222//
224{
225 std::ios_base::fmtflags Flags; ///< See std::ios_base::flags.
226 std::streamsize Precision; ///< See std::ios_base::precision.
227 std::streamsize Width; ///< See std::ios_base::width.
228 tchar Fill; // See std::basic_ios::fill.
229
230 //
231 /// Mutator; can be chained, e.g. TTransferFormat().SetFlags(std::ios::showbase).SetWidth(7);
232 //
233 TTransferFormat& SetFlags(std::ios_base::fmtflags v) {Flags = v; return *this;}
234
235 //
236 /// Mutator; can be chained, e.g. TTransferFormat().SetPrecision(2).SetFlags(std::ios::fixed);
237 //
238 TTransferFormat& SetPrecision(std::streamsize v) {Precision = v; return *this;}
239
240 //
241 /// Mutator; can be chained, e.g. TTransferFormat().SetWidth(7).SetFlags(std::ios::scientific);
242 //
243 TTransferFormat& SetWidth(std::streamsize v) {Width = v; return *this;}
244
245 //
246 /// Mutator; can be chained, e.g. TTransferFormat().SetFill(' ').SetFlags(0);
247 //
248 TTransferFormat& SetFill(tchar v) {Fill = v; return *this;}
249};
250
251//
252/// Transfers the lexical conversion of the text contents of a control using the given format.
253/// For example, numbers will be transferred as their representation as text.
254//
255template <class T>
257{
258 if (i.Operation == tdSetData)
259 {
261 os.flags(f.Flags);
262 if (f.Precision > 0) os.precision(f.Precision);
263 if (f.Width > 0) os.width(f.Width);
264 if (f.Fill > 0) os.fill (f.Fill);
265 os << value;
266 tstring s = os.str();
267 TransferDlgItemText(i, ctrl, s);
268 }
269 else if (i.Operation == tdGetData)
270 {
271 tstring s;
272 TransferDlgItemText(i, ctrl, s);
274 is.flags(f.Flags);
275 is >> value;
276 }
277}
278
279//
280/// Overload - won't compile
281/// The sole purpose of this overload is to forbid pointers.
282//
283template <class T>
286
287//
288/// Transfers the lexical conversion of the text contents of a control.
289/// For example, numbers will be transferred as their representation as text.
290//
291template <class T>
293{
294 // Set precision to support loss-less conversion of IEEE 754 double-precision.
295 //
296 TransferDlgItemText(i, ctrl, value, TTransferFormat().SetPrecision(17));
297}
298
299//
300/// Transfers the lexical conversion of the text contents of an edit control.
301/// For example, numbers will be transferred as their representation as text.
302//
303template <class T>
306
307//
308/// Transfers the lexical conversion of the text contents of an edit control using the given format.
309/// For example, numbers will be transferred as their representation as text.
310//
311template <class T>
313{TransferDlgItemText(i, ctrl, value, f);}
314
315//
316/// Transfers the hotkey value of a hotkey control.
317//
318_OWLFUNC(void) TransferHotKeyData(const TTransferInfo&, HWND ctrl, uint16& key);
319
320//
321/// Transfers the address of a IP address control as an object.
322//
323_OWLFUNC(void) TransferIPAddressData(const TTransferInfo&, HWND ctrl, TIPAddressBits& data);
324
325//
326/// Transfers the address for a IP address control as a 32-bit value.
327//
328_OWLFUNC(void) TransferIPAddressData(const TTransferInfo&, HWND ctrl, uint32& data);
329
330//
331/// Transfers all the data for a list box control.
332//
333_OWLFUNC(void) TransferListBoxData(const TTransferInfo&, HWND ctrl, TListBoxData& data);
334
335//
336/// Transfers the selection index of a list box control.
337//
338_OWLFUNC(void) TransferListBoxData(const TTransferInfo&, HWND ctrl, int& selIndex);
339
340//
341/// Transfers the selection string of a list box control.
342//
343_OWLFUNC(void) TransferListBoxData(const TTransferInfo&, HWND ctrl, tstring& selString, bool exact = false);
344
345//
346/// Transfers all the data for a calendar control.
347//
348_OWLFUNC(void) TransferMonthCalendarData(const TTransferInfo&, HWND ctrl, TMonthCalendarData& data);
349
350//
351/// Transfers the selected date and time of a calendar control.
352//
353_OWLFUNC(void) TransferMonthCalendarData(const TTransferInfo&, HWND ctrl, TSystemTime& curSel);
354
355//
356/// Transfers the selection range of a calendar control.
357//
358_OWLFUNC(void) TransferMonthCalendarData(const TTransferInfo&, HWND ctrl, std::pair<TSystemTime, TSystemTime>& rangeSel);
359
360//
361/// Transfers the index of the selected radio button within a group.
362//
363_OWLFUNC(void) TransferRadioButtonData(const TTransferInfo&, HWND ctrl, int& selIndex);
364
365//
366/// Transfers all the data for a scroll bar control.
367//
368_OWLFUNC(void) TransferScrollBarData(const TTransferInfo&, HWND ctrl, TScrollBarData& data);
369
370//
371/// Transfers the current position of a scroll bar control.
372//
373_OWLFUNC(void) TransferScrollBarData(const TTransferInfo&, HWND ctrl, int& position);
374
375//
376/// Transfers all the data for a slider control.
377//
378_OWLFUNC(void) TransferSliderData(const TTransferInfo&, HWND ctrl, TScrollBarData& data);
379
380//
381/// Transfers the current position of a slider control.
382//
383_OWLFUNC(void) TransferSliderData(const TTransferInfo&, HWND ctrl, int& position);
384
385//
386/// Transfers the lexical conversion of the text contents of a static control.
387/// For example, numbers will be transferred as their representation as text.
388//
389template <class T>
392
393//
394/// Transfers the lexical conversion of the text contents of a static control using the given format.
395/// For example, numbers will be transferred as their representation as text.
396//
397template <class T>
399{TransferDlgItemText(i, ctrl, value, f);}
400
401/// @}
402
403//
404/// \name Transfer utility functions - integer child ID overloads
405/// @{
406
407//
408/// Transfers the state of the checkbox to the given variable.
409//
410template <class T>
411void TransferCheckBoxData(const TTransferInfo& i, int ctrl, T& value)
412{TransferCheckBoxData(i, GetDlgItem(i.Window, ctrl), value);}
413
414//
415/// Transfers all the data for an a check list box.
416//
418{TransferCheckListData(i, GetDlgItem(i.Window, ctrl), data);}
419
420//
421/// Transfers the data or selection index of a combo box control.
422//
423template <class T>
424void TransferComboBoxData(const TTransferInfo& i, int ctrl, T& value)
425{TransferComboBoxData(i, GetDlgItem(i.Window, ctrl), value);}
426
427//
428/// Transfers the selection string of a combo box control.
429//
430inline _OWLFUNC(void) TransferComboBoxData(const TTransferInfo& i, int ctrl, tstring& selString, bool exact = false)
431{TransferComboBoxData(i, GetDlgItem(i.Window, ctrl), selString, exact);}
432
433//
434/// Transfers all the data for an extended combo box control.
435//
437{TransferComboBoxExData(i, GetDlgItem(i.Window, ctrl), data);}
438
439//
440/// Transfers the data or selected date and time of a date and time picker.
441//
442template <class T>
444{TransferDateTimePickerData(i, GetDlgItem(i.Window, ctrl), value);}
445
446//
447/// Transfers the lexical conversion of the text contents of a control.
448/// For example, numbers will be transferred as their representation as text.
449//
450template <class T>
451void TransferDlgItemText(const TTransferInfo& i, int ctrl, T& value)
452{TransferDlgItemText(i, GetDlgItem(i.Window, ctrl), value);}
453
454//
455/// Transfers the lexical conversion of the text contents of a control using the given format.
456/// For example, numbers will be transferred as their representation as text.
457//
458template <class T>
459void TransferDlgItemText(const TTransferInfo& i, int ctrl, T& value, const TTransferFormat& f)
460{TransferDlgItemText(i, GetDlgItem(i.Window, ctrl), value, f);}
461
462//
463/// Transfers the lexical conversion of the text contents of an edit control.
464/// For example, numbers will be transferred as their representation as text.
465//
466template <class T>
467void TransferEditData(const TTransferInfo& i, int ctrl, T& value)
468{TransferEditData(i, GetDlgItem(i.Window, ctrl), value);}
469
470//
471/// Transfers the lexical conversion of the text contents of an edit control using the given format.
472/// For example, numbers will be transferred as their representation as text.
473//
474template <class T>
475void TransferEditData(const TTransferInfo& i, int ctrl, T& value, const TTransferFormat& f)
476{TransferEditData(i, GetDlgItem(i.Window, ctrl), value, f);}
477
478//
479/// Transfers the hotkey value of a hotkey control.
480//
481inline _OWLFUNC(void) TransferHotKeyData(const TTransferInfo& i, int ctrl, uint16& key)
482{TransferHotKeyData(i, GetDlgItem(i.Window, ctrl), key);}
483
484//
485/// Transfers the address for a IP address control.
486//
487template <class T>
488void TransferIPAddressData(const TTransferInfo& i, int ctrl, T& value)
489{TransferIPAddressData(i, GetDlgItem(i.Window, ctrl), value);}
490
491//
492/// Transfers the data or selection index of a list box control.
493//
494template <class T>
495void TransferListBoxData(const TTransferInfo& i, int ctrl, T& value)
496{TransferListBoxData(i, GetDlgItem(i.Window, ctrl), value);}
497
498//
499/// Transfers the selection string of a list box control.
500//
501inline _OWLFUNC(void) TransferListBoxData(const TTransferInfo& i, int ctrl, tstring& selString, bool exact = false)
502{TransferListBoxData(i, GetDlgItem(i.Window, ctrl), selString, exact);}
503
504//
505/// Transfers the data or selected date and time of a calendar control.
506//
507template <class T>
509{TransferMonthCalendarData(i, GetDlgItem(i.Window, ctrl), value);}
510
511//
512/// Transfers the index of the selected radio button within a group.
513//
514inline _OWLFUNC(void) TransferRadioButtonData(const TTransferInfo& i, int ctrl, int& selIndex)
515{TransferRadioButtonData(i, GetDlgItem(i.Window, ctrl), selIndex);}
516
517//
518/// Transfers the data or current position of a scroll bar control.
519//
520template <class T>
521void TransferScrollBarData(const TTransferInfo& i, int ctrl, T& value)
522{TransferScrollBarData(i, GetDlgItem(i.Window, ctrl), value);}
523
524//
525/// Transfers the data or current position of a slider control.
526//
527template <class T>
528void TransferSliderData(const TTransferInfo& i, int ctrl, T& value)
529{TransferSliderData(i, GetDlgItem(i.Window, ctrl), value);}
530
531//
532/// Transfers the lexical conversion of the text contents of a static control.
533/// For example, numbers will be transferred as their representation as text.
534//
535template <class T>
536void TransferStaticData(const TTransferInfo& i, int ctrl, T& value)
537{TransferStaticData(i, GetDlgItem(i.Window, ctrl), value);}
538
539//
540/// Transfers the lexical conversion of the text contents of a static control using the given format.
541/// For example, numbers will be transferred as their representation as text.
542//
543template <class T>
544void TransferStaticData(const TTransferInfo& i, int ctrl, T& value, const TTransferFormat& f)
545{TransferStaticData(i, GetDlgItem(i.Window, ctrl), value, f);}
546
547/// @}
548
549/// \name Transfer utility functions - DDX-like overloads
550/// @{
551
552//
553/// Transfers the selection index of a combo box control.
554//
555inline _OWLFUNC(void) DDX_CBIndex(const TTransferInfo& i, int id, int& selIndex)
557
558//
559/// Transfers the selection string of a combo box control.
560//
561inline _OWLFUNC(void) DDX_CBString(const TTransferInfo& i, int id, tstring& selString)
562{TransferComboBoxData(i, id, selString, false);}
563
564//
565/// Transfers the exact selection string of a combo box control.
566//
569
570//
571/// Transfers the state of the checkbox to the given integer variable.
572/// This overload supports tri-state check boxes (BST_CHECKED, BST_INDETERMINATE, BST_UNCHECKED).
573//
574inline _OWLFUNC(void) DDX_Check(const TTransferInfo& i, int id, UINT& state)
575{TransferCheckBoxData(i, id, state);}
576
577//
578/// Transfers the selected date and time of a date and time picker control.
579//
582
583//
584/// Transfers the selected date and time of a date and time picker control as a string.
585//
588
589//
590/// Transfers the hotkey value of a hotkey control.
591//
592inline _OWLFUNC(void) DDX_HotKey(const TTransferInfo& i, int id, uint16& key)
593{TransferHotKeyData(i, id, key);}
594
595//
596/// Transfers the address for a IP address control as a 32-bit value.
597//
598inline _OWLFUNC(void) DDX_IPAddress(const TTransferInfo& i, int id, uint32& data)
600
601//
602/// Transfers the selection index of a list box control.
603//
604inline _OWLFUNC(void) DDX_LBIndex(const TTransferInfo& i, int id, int& selIndex)
606
607//
608/// Transfers the selection string of a list box control.
609//
610inline _OWLFUNC(void) DDX_LBString(const TTransferInfo& i, int id, tstring& selString)
611{TransferListBoxData(i, id, selString, false);}
612
613//
614/// Transfers the exact selection string of a list box control.
615//
618
619//
620/// Transfers the selected date and time of a calendar control.
621//
624
625//
626/// Transfers the index of the selected radio button within a group.
627//
628inline _OWLFUNC(void) DDX_Radio(const TTransferInfo& i, int id, int& selIndex)
630
631//
632/// Transfers the current position of a scroll bar control.
633//
634inline _OWLFUNC(void) DDX_Scroll(const TTransferInfo& i, int id, int& position)
636
637//
638/// Transfers all the data for a slider control.
639//
640inline _OWLFUNC(void) DDX_Slider(const TTransferInfo& i, int id, int& position)
642
643//
644/// Transfers the lexical conversion of the text contents of a static control.
645/// For example, numbers will be transferred as their representation as text.
646//
647template <class T>
648void DDX_Text(const TTransferInfo& i, int id, T& value)
650
651/// @}
652
653namespace detail
654{
655
656 //
657 // Implementation of indirect transfer
658 //
659 // This implementation is used by all the indirect Transfer* functions, passing the specific transfer
660 // function for the respective control as the last parameter. Rather than pass a function pointer as
661 // the 'transfer' parameter, clients should pass a functor wrapper so that overload resolution is
662 // deferred until the actual call. This technique allows this function to serve as an indirect call to
663 // a whole set of overloaded transfer functions.
664 //
665 // The type of data to be transferred is deduced from the return type of the passed 'get' functor.
666 //
667 template <class TCtrl, class TGet, class TSet, class TTransfer>
668 void Transfer(const TTransferInfo& i, const TCtrl& ctrl, TGet get, TSet set, TTransfer transfer)
669 {
670 typedef typename std::invoke_result_t<TGet> TDataConstRef;
671 typedef typename std::remove_reference<TDataConstRef>::type TDataConst;
672 typedef typename std::remove_cv<TDataConst>::type TData;
673 TData data(get()); // Always initialize; the transfer function may treat it as an in-out parameter.
674 transfer(i, ctrl, data);
675 if (i.Operation == tdGetData) set(data);
676 }
677
678 //
679 // Implementation of indirect transfer, with one extra transfer parameter
680 //
681 // See the Transfer(const TTransferInfo&, const TCtrl&, TGet, TSet, TTransfer) for details.
682 //
683 template <class TCtrl, class TArg1, class TGet, class TSet, class TTransfer>
685 {
686 typedef typename std::invoke_result_t<TGet> TDataConstRef;
687 typedef typename std::remove_reference<TDataConstRef>::type TDataConst;
688 typedef typename std::remove_cv<TDataConst>::type TData;
689 TData data(get()); // Always initialize; the transfer function may treat it as an in-out parameter.
690 transfer(i, ctrl, data, arg1);
691 if (i.Operation == tdGetData) set(data);
692 }
693
694 //
695 // Implementation of indirect transfer using member functions
696 //
697 // See the Transfer(const TTransferInfo&, const TCtrl&, TGet, TSet, TTransfer) for details.
698 //
699 template <class TCtrl, class TDataSource, class R, class A, class TTransfer>
700 void Transfer(const TTransferInfo& i, const TCtrl& ctrl, TDataSource* d, R (TDataSource::*get)() const, void (TDataSource::*set)(A), TTransfer transfer)
701 {Transfer(i, ctrl, std::bind(get, d), std::bind(set, d, std::placeholders::_1), transfer);}
702
703 //
704 // Implementation of indirect transfer, with one extra transfer parameter, using member functions
705 //
706 // See the Transfer(const TTransferInfo&, const TCtrl&, TGet, TSet, TTransfer) for details.
707 //
708 template <class TCtrl, class TArg1, class TDataSource, class R, class A, class TTransfer>
709 void Transfer(const TTransferInfo& i, const TCtrl& ctrl, TArg1 arg1, TDataSource* d, R (TDataSource::*get)() const, void (TDataSource::*set)(A), TTransfer transfer)
710 {Transfer(i, ctrl, arg1, std::bind(get, d), std::bind(set, d, std::placeholders::_1), transfer);}
711
712 //
713 // Functor for deferred overload resolution
714 //
716 {
717 template <class TCtrl, class TData>
718 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
719 {TransferCheckBoxData(i, ctrl, data);}
720 };
721
722 //
723 // Functor for deferred overload resolution
724 //
726 {
727 template <class TCtrl, class TData>
728 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
729 {TransferCheckListData(i, ctrl, data);}
730 };
731
732 //
733 // Functor for deferred overload resolution
734 //
736 {
737 template <class TCtrl, class TData>
738 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
739 {TransferComboBoxData(i, ctrl, data);}
740
741 template <class TCtrl, class TData, class TArg1>
742 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data, TArg1 arg1)
743 {TransferComboBoxData(i, ctrl, data, arg1);}
744 };
745
746 //
747 // Functor for deferred overload resolution
748 //
750 {
751 template <class TCtrl, class TData>
752 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
753 {TransferComboBoxExData(i, ctrl, data);}
754 };
755
756 //
757 // Functor for deferred overload resolution
758 //
760 {
761 template <class TCtrl, class TData>
762 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
764 };
765
766 //
767 // Functor for deferred overload resolution
768 //
770 {
771 template <class TCtrl, class TData>
772 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
773 {TransferDlgItemText(i, ctrl, data);}
774
775 template <class TCtrl, class TData>
776 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data, const TTransferFormat& f)
777 {TransferDlgItemText(i, ctrl, data, f);}
778 };
779
780 //
781 // Functor for deferred overload resolution
782 //
784 {
785 template <class TCtrl, class TData>
786 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
787 {TransferEditData(i, ctrl, data);}
788
789 template <class TCtrl, class TData>
790 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data, const TTransferFormat& f)
791 {TransferEditData(i, ctrl, data, f);}
792 };
793
794 //
795 // Functor for deferred overload resolution
796 //
798 {
799 template <class TCtrl, class TData>
800 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
801 {TransferHotKeyData(i, ctrl, data);}
802 };
803
804 //
805 // Functor for deferred overload resolution
806 //
808 {
809 template <class TCtrl, class TData>
810 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
811 {TransferIPAddressData(i, ctrl, data);}
812 };
813
814 //
815 // Functor for deferred overload resolution
816 //
818 {
819 template <class TCtrl, class TData>
820 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
821 {TransferListBoxData(i, ctrl, data);}
822
823 template <class TCtrl, class TData, class TArg1>
824 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data, TArg1 arg1)
825 {TransferListBoxData(i, ctrl, data, arg1);}
826 };
827
828 //
829 // Functor for deferred overload resolution
830 //
832 {
833 template <class TCtrl, class TData>
834 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
836 };
837
838 //
839 // Functor for deferred overload resolution
840 //
842 {
843 template <class TCtrl, class TData>
844 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
846 };
847
848 //
849 // Functor for deferred overload resolution
850 //
852 {
853 template <class TCtrl, class TData>
854 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
855 {TransferScrollBarData(i, ctrl, data);}
856 };
857
858 //
859 // Functor for deferred overload resolution
860 //
862 {
863 template <class TCtrl, class TData>
864 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
865 {TransferSliderData(i, ctrl, data);}
866 };
867
868 //
869 // Functor for deferred overload resolution
870 //
872 {
873 template <class TCtrl, class TData>
874 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data)
875 {TransferStaticData(i, ctrl, data);}
876
877 template <class TCtrl, class TData>
878 void operator()(const TTransferInfo& i, const TCtrl& ctrl, TData& data, const TTransferFormat& f)
879 {TransferStaticData(i, ctrl, data, f);}
880 };
881
882}
883
884/// \name Transfer utility functions - indirect transfer via member functions
885/// @{
886
887//
888/// Transfers the state of the checkbox using the given data source and member functions.
889//
890template <class TCtrl, class D, class R, class A>
891void TransferCheckBoxData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
893
894//
895/// Transfers data for a check list box using the given data source and member functions.
896//
897template <class TCtrl, class D, class R, class A>
898void TransferCheckListData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
900
901//
902/// Transfers data for a combo box using the given data source and member functions.
903//
904template <class TCtrl, class D, class R, class A>
905void TransferComboBoxData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
907
908//
909/// Transfers data for a combo box using the given data source and member functions.
910/// This overload supports an extra transfer function argument.
911//
912template <class TCtrl, class TArg1, class D, class R, class A>
913void TransferComboBoxData(const TTransferInfo& i, const TCtrl& ctrl, TArg1 arg1, D* d, R (D::*get)() const, void (D::*set)(A))
915
916//
917/// Transfers data for a date and time picker control using the given data source and member functions.
918//
919template <class TCtrl, class D, class R, class A>
920void TransferDateTimePickerData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
922
923//
924/// Transfers the text contents of a control using the given data source and member functions.
925//
926template <class TCtrl, class D, class R, class A>
927void TransferDlgItemText(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
929
930//
931/// Transfers the text contents of a control using the given data source and member functions.
932/// The given format is used to format the text when transferring data to the control.
933//
934template <class TCtrl, class D, class R, class A>
935void TransferDlgItemText(const TTransferInfo& i, const TCtrl& ctrl, const TTransferFormat& f, D* d, R (D::*get)() const, void (D::*set)(A))
937
938//
939/// Transfers data for a edit control using the given data source and member functions.
940//
941template <class TCtrl, class D, class R, class A>
942void TransferEditData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
944
945//
946/// Transfers data for a edit control using the given data source and member functions.
947/// The given format is used to format the text when transferring data to the control.
948//
949template <class TCtrl, class D, class R, class A>
950void TransferEditData(const TTransferInfo& i, const TCtrl& ctrl, const TTransferFormat& f, D* d, R (D::*get)() const, void (D::*set)(A))
951{detail::Transfer(i, ctrl, f, d, get, set, detail::TTransferEditData());}
952
953//
954/// Transfers data for a hotkey control using the given data source and member functions.
955//
956template <class TCtrl, class D, class R, class A>
957void TransferHotKeyData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
959
960//
961/// Transfers data for an IP address control using the given data source and member functions.
962//
963template <class TCtrl, class D, class R, class A>
964void TransferIPAddressData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
966
967//
968/// Transfers data for a list box using the given data source and member functions.
969//
970template <class TCtrl, class D, class R, class A>
971void TransferListBoxData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
973
974//
975/// Transfers data for a list box using the given data source and member functions.
976/// This overload supports an extra transfer function argument.
977//
978template <class TCtrl, class TArg1, class D, class R, class A>
979void TransferListBoxData(const TTransferInfo& i, const TCtrl& ctrl, TArg1 arg1, D* d, R (D::*get)() const, void (D::*set)(A))
981
982//
983/// Transfers data for a list box using the given data source and member functions.
984//
985template <class TCtrl, class D, class R, class A>
986void TransferMonthCalendarData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
988
989//
990/// Transfers the index of the selected radio button within a group using the given data source and member functions.
991//
992template <class TCtrl, class D, class R, class A>
993void TransferRadioButtonData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
995
996//
997/// Transfers data for a scroll bar control using the given data source and member functions.
998//
999template <class TCtrl, class D, class R, class A>
1000void TransferScrollBarData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
1002
1003//
1004/// Transfers data for a slider control using the given data source and member functions.
1005//
1006template <class TCtrl, class D, class R, class A>
1007void TransferSliderData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
1009
1010//
1011/// Transfers data for a static control using the given data source and member functions.
1012//
1013template <class TCtrl, class D, class R, class A>
1014void TransferStaticData(const TTransferInfo& i, const TCtrl& ctrl, D* d, R (D::*get)() const, void (D::*set)(A))
1016
1017//
1018/// Transfers data for a static control using the given data source and member functions.
1019/// The given format is used to format the text when transferring data to the control.
1020//
1021template <class TCtrl, class D, class R, class A>
1022void TransferStaticData(const TTransferInfo& i, const TCtrl& ctrl, const TTransferFormat& f, D* d, R (D::*get)() const, void (D::*set)(A))
1023{detail::Transfer(i, ctrl, f, d, get, set, detail::TTransferStaticData());}
1024
1025/// @}
1026
1027/// \name Transfer utility functions - indirect transfer via functors
1028/// @{
1029
1030//
1031/// Transfers the state of the checkbox using the given functors.
1032//
1033template <class TCtrl, class G, class S>
1034void TransferCheckBoxData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1036
1037//
1038/// Transfers data for a check list box using the given functors.
1039//
1040template <class TCtrl, class G, class S>
1041void TransferCheckListData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1043
1044//
1045/// Transfers data for a combo box using the given functors.
1046//
1047template <class TCtrl, class G, class S>
1048void TransferComboBoxData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1050
1051//
1052/// Transfers data for a combo box using the given functors.
1053/// This overload supports an extra transfer function argument.
1054//
1055template <class TCtrl, class TArg1, class G, class S>
1058
1059//
1060/// Transfers data for a date and time picker control using the given functors.
1061//
1062template <class TCtrl, class G, class S>
1065
1066//
1067/// Transfers the text contents of a control using the given functors.
1068//
1069template <class TCtrl, class G, class S>
1070void TransferDlgItemText(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1072
1073//
1074/// Transfers the text contents of a control using the given functors.
1075/// The given format is used to format the text when transferring data to the control.
1076//
1077template <class TCtrl, class G, class S>
1078void TransferDlgItemText(const TTransferInfo& i, const TCtrl& ctrl, const TTransferFormat& f, G get, S set)
1080
1081//
1082/// Transfers data for a edit control using the given functors.
1083//
1084template <class TCtrl, class G, class S>
1085void TransferEditData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1087
1088//
1089/// Transfers data for a edit control using the given functors.
1090/// The given format is used to format the text when transferring data to the control.
1091//
1092template <class TCtrl, class G, class S>
1093void TransferEditData(const TTransferInfo& i, const TCtrl& ctrl, const TTransferFormat& f, G get, S set)
1094{detail::Transfer(i, ctrl, f, get, set, detail::TTransferEditData());}
1095
1096//
1097/// Transfers data for a hotkey control using the given functors.
1098//
1099template <class TCtrl, class G, class S>
1100void TransferHotKeyData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1102
1103//
1104/// Transfers data for an IP address control using the given functors.
1105//
1106template <class TCtrl, class G, class S>
1107void TransferIPAddressData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1109
1110//
1111/// Transfers data for a list box using the given functors.
1112//
1113template <class TCtrl, class G, class S>
1114void TransferListBoxData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1116
1117//
1118/// Transfers data for a list box using the given functors.
1119/// This overload supports an extra transfer function argument.
1120//
1121template <class TCtrl, class TArg1, class G, class S>
1122void TransferListBoxData(const TTransferInfo& i, const TCtrl& ctrl, TArg1 arg1, G get, S set)
1124
1125//
1126/// Transfers data for a list box using the given functors.
1127//
1128template <class TCtrl, class G, class S>
1131
1132//
1133/// Transfers the index of the selected radio button within a group using the given functors.
1134//
1135template <class TCtrl, class G, class S>
1138
1139//
1140/// Transfers data for a scroll bar control using the given functors.
1141//
1142template <class TCtrl, class G, class S>
1143void TransferScrollBarData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1145
1146//
1147/// Transfers data for a slider control using the given functors.
1148//
1149template <class TCtrl, class G, class S>
1150void TransferSliderData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1152
1153//
1154/// Transfers data for a static control using the given functors.
1155//
1156template <class TCtrl, class G, class S>
1157void TransferStaticData(const TTransferInfo& i, const TCtrl& ctrl, G get, S set)
1159
1160//
1161/// Transfers data for a static control using the given functors.
1162/// The given format is used to format the text when transferring data to the control.
1163//
1164template <class TCtrl, class G, class S>
1165void TransferStaticData(const TTransferInfo& i, const TCtrl& ctrl, const TTransferFormat& f, G get, S set)
1167
1168/// @}
1169
1170
1171//
1172/// Mix-in class template providing support for data transfer to and from controls
1173//
1174template <class TDataSource>
1176 : virtual public TWindow
1177{
1178public:
1179
1181 : DataSource(0)
1182 {}
1183
1187
1188 //
1189 /// Transfer the state of the window into the given data source.
1190 //
1192 {
1194 const_cast<TTransferWindow*>(this)->DoTransferData(i, ds);
1195 }
1196
1197 //
1198 /// Function style overload
1199 /// Requires that the data source type is a value type with a default constructor and
1200 /// a copy constructor. For types without a default constructor or copy constructor,
1201 /// use GetData(TDataSource&) instead.
1202 //
1204 {
1206 GetData(ds);
1207 return ds;
1208 }
1209
1210 //
1211 /// Transfers the state of the given data source into the window.
1212 //
1214 {
1216 DoTransferData(i, const_cast<TDataSource&>(ds));
1217 }
1218
1219 //
1220 /// TWindow override
1221 /// Initialises the transfer info and dispatches to DoTransferData.
1222 //
1224 {
1225 if (!DataSource) return;
1226 TTransferInfo i = {GetHandle(), d};
1228 }
1229
1230 //
1231 /// \name Convenience functions for working with dialog items
1232 /// @{
1233 //
1234
1235 //
1236 /// Enables (or disables) the given control.
1237 //
1238 void EnableDlgItem(int ctrl, bool enabled = true)
1240
1241 //
1242 /// Enables (or disables) all the controls in the given sequence.
1243 //
1244 template <class It>
1245 void EnableDlgItem(It first, It last, bool enabled = true)
1246 {for (; first != last; ++first) EnableDlgItem(*first, enabled);}
1247
1248 //
1249 /// Enables (or disables) all the controls in the given array.
1250 //
1251 template <int N>
1252 void EnableDlgItem(const int (&id)[N], bool enabled = true)
1253 {EnableDlgItem(id, id + N, enabled);}
1254
1255 //
1256 /// Enables (or disables) all the controls in the given initializer list.
1257 //
1258 void EnableDlgItem(const std::initializer_list<int>& id, bool enabled = true)
1259 {EnableDlgItem(std::begin(id), std::end(id), enabled);}
1260
1261 //
1262 /// Disables (or enables) the given control.
1263 //
1264 void DisableDlgItem(int ctrl, bool disabled = true)
1265 {EnableDlgItem(ctrl, !disabled);}
1266
1267 //
1268 /// Disables (or enables) all the controls in the given sequence.
1269 //
1270 template <class It>
1273
1274 //
1275 /// Disables (or enables) all the controls in the given array.
1276 //
1277 template <int N>
1278 void DisableDlgItem(const int (&id)[N], bool disabled = true)
1279 {EnableDlgItem(id, !disabled);}
1280
1281 //
1282 /// Disables (or enables) all the controls in the given initializer list.
1283 //
1284 void DisableDlgItem(const std::initializer_list<int>& id, bool disabled = true)
1285 {EnableDlgItem(std::begin(id), std::end(id), !disabled);}
1286
1287 //
1288 /// Shows (or hides) the given control.
1289 //
1290 void ShowDlgItem(int ctrl, bool visible = true)
1292
1293 //
1294 /// Shows (or hides) all the controls in the given sequence.
1295 //
1296 template <class It>
1297 void ShowDlgItem(It first, It last, bool visible = true)
1298 {for (; first != last; ++first) ShowDlgItem(*first, visible);}
1299
1300 //
1301 /// Shows (or hides) all the controls in the given array.
1302 //
1303 template <int N>
1304 void ShowDlgItem(const int (&id)[N], bool visible = true)
1305 {ShowDlgItem(id, id + N, visible);}
1306
1307 //
1308 /// Shows (or hides) all the controls in the given initializer list.
1309 //
1310 void ShowDlgItem(const std::initializer_list<int>& id, bool visible = true)
1311 {ShowDlgItem(std::begin(id), std::end(id), visible);}
1312
1313 //
1314 /// Hides (or shows) the given control.
1315 //
1316 void HideDlgItem(int ctrl, bool hidden = true)
1317 {ShowDlgItem(ctrl, !hidden);}
1318
1319 //
1320 /// Hides (or shows) all the controls in the given sequence.
1321 //
1322 template <class It>
1323 bool HideDlgItem(It first, It last, bool hidden = true)
1325
1326 //
1327 /// Hides (or shows) all the controls in the given array.
1328 //
1329 template <int N>
1330 void HideDlgItem(const int (&id)[N], bool hidden = true)
1331 {ShowDlgItem(id, !hidden);}
1332
1333 //
1334 /// Hides (or shows) all the controls in the given initializer list.
1335 //
1336 void HideDlgItem(const std::initializer_list<int>& id, bool hidden = true)
1337 {ShowDlgItem(std::begin(id), std::end(id), !hidden);}
1338
1339 //
1340 /// Returns true if the given control has BST_CHECKED state.
1341 //
1342 bool IsChecked(int ctrl) const
1343 {return IsDlgButtonChecked(ctrl) == BST_CHECKED;}
1344
1345 //
1346 /// Returns true if any control in the given sequence has BST_CHECKED state.
1347 //
1348 template <class It>
1349 bool IsChecked(It first, It last) const
1350 {for (; first != last; ++first) if (IsChecked(*first)) return true; return false;}
1351
1352 //
1353 /// Returns true if any control in the given array has BST_CHECKED state.
1354 //
1355 template <int N>
1356 bool IsChecked(const int (&id)[N]) const
1357 {return IsChecked(id, id + N);}
1358
1359 //
1360 /// Returns true if any control in the given initializer list has BST_CHECKED state.
1361 //
1362 bool IsChecked(const std::initializer_list<int>&id) const
1363 {return IsChecked(std::begin(id), std::end(id));}
1364
1365 //
1366 /// Returns true if the given control has BST_UNCHECKED state.
1367 //
1368 bool IsUnchecked(int ctrl) const
1369 {return IsDlgButtonChecked(ctrl) == BST_UNCHECKED;}
1370
1371 //
1372 /// Returns true if any control in the given sequence has BST_UNCHECKED state.
1373 //
1374 template <class It>
1376 {for (; first != last; ++first) if (IsUnchecked(*first)) return true; return false;}
1377
1378 //
1379 /// Returns true if any control in the given array has BST_UNCHECKED state.
1380 //
1381 template <int N>
1382 bool IsUnchecked(const int (&id)[N]) const
1383 {return IsUnchecked(id, id + N);}
1384
1385 //
1386 /// Returns true if any control in the given initializer list has BST_UNCHECKED state.
1387 //
1388 bool IsUnchecked(const std::initializer_list<int>&id) const
1389 {return IsUnchecked(std::begin(id), std::end(id));}
1390
1391 //
1392 /// Returns true if the given control has BST_INDETERMINATE state.
1393 //
1394 bool IsIndeterminate(int ctrl) const
1395 {return IsDlgButtonChecked(ctrl) == BST_INDETERMINATE;}
1396
1397 //
1398 /// Returns true if any control in the given sequence has BST_INDETERMINATE state.
1399 //
1400 template <class It>
1402 {for (; first != last; ++first) if (IsIndeterminate(*first)) return true; return false;}
1403
1404 //
1405 /// Returns true if any control in the given array has BST_INDETERMINATE state.
1406 //
1407 template <int N>
1408 bool IsIndeterminate(const int (&id)[N]) const
1409 {return IsIndeterminate(id, id + N);}
1410
1411 //
1412 /// Returns true if any control in the given initializer list has BST_INDETERMINATE state.
1413 //
1414 bool IsIndeterminate(const std::initializer_list<int>&id) const
1415 {return IsIndeterminate(std::begin(id), std::end(id));}
1416
1417 //
1418 /// using TWindow::CheckDlgButton;
1419 //
1420 void CheckDlgButton(int ctrl, uint state)
1421 {TWindow::CheckDlgButton(ctrl, state);}
1422
1423 //
1424 /// Resolves an integer state argument.
1425 /// The button state macros; BST_CHECKED etc.; are of type int while the TWindow
1426 /// function takes an uint.
1427 //
1428 void CheckDlgButton(int ctrl, int state)
1429 {TWindow::CheckDlgButton(ctrl, static_cast<uint>(state));}
1430
1431 //
1432 /// Sets the state of the given control to BST_CHECKED (or BST_UNCHECKED).
1433 //
1434 void CheckDlgButton(int ctrl, bool checked = true)
1436
1437 //
1438 /// Sets the state of the given control to BST_UNCHECKED (or BST_CHECKED).
1439 //
1440 void UncheckDlgButton(int ctrl, bool unchecked = true)
1442
1443 //
1444 /// See owl::GetSelectedRadioButtonIndex.
1445 //
1448
1449 //
1450 /// See owl::GetSelectedRadioButtonIndex.
1451 //
1454
1455 //
1456 /// See owl::SetSelectedRadioButtonIndex.
1457 //
1460
1461 //
1462 /// See owl::SetSelectedRadioButtonIndex.
1463 //
1466
1467 /// @}
1468
1469protected:
1470
1472
1473 //
1474 /// Transfers data between window and data source in the direction specified by the given transfer information.
1475 /// Default implementation; forwards the call to DoGetData or DoSetData, depending on the transfer direction.
1476 //
1478 {
1479 if (i.Operation == tdGetData)
1480 DoGetData(i, ds);
1481 else if (i.Operation == tdSetData)
1482 DoSetData(i, ds);
1483 }
1484
1485 //
1486 /// Transfers the state of the window into the given data source.
1487 /// Default implementation; does nothing.
1488 //
1489 virtual void DoGetData(const TTransferInfo&, TDataSource&) const
1490 {}
1491
1492 //
1493 /// Transfers the state of the given data source into the window.
1494 /// Default implementation; does nothing.
1495 //
1496 virtual void DoSetData(const TTransferInfo&, const TDataSource&)
1497 {}
1498
1499};
1500
1501//
1502/// Dialog class derived from TTransferWindow
1503/// Provides convenient initialization of the dialog and transfer window bases.
1504//
1505template <class TDataSource, class TDialogBase = TDialog>
1507 : virtual public TTransferWindow<TDataSource>,
1508 public TDialogBase
1509{
1510public:
1511
1513 : TDialogBase(parent, id, m)
1514 {this->DataSource = &ds;}
1515
1516};
1517
1518//
1519/// TWindow mix-in
1520/// Delegates the job of transferring data to the given function object.
1521//
1523 : virtual public TWindow
1524{
1525public:
1526
1528 typedef std::function<TTransferFunctionSignature> TTransferFunction;
1529
1531
1532 //
1533 /// TWindow override
1534 /// Dispatches to the transfer function.
1535 //
1536 virtual void TransferData(TTransferDirection d);
1537
1538private:
1539
1540 TTransferFunction TransferFunction;
1541};
1542
1543//
1544/// Dialog derivative of TDelegatedTransferWindow
1545//
1547 : public TDialog,
1549{
1550public:
1551
1553
1554};
1555
1556//
1557/// Maps between application-specific value and a selection index, such as a radio-button group
1558/// index or a list box selection.
1559//
1560template <class TValue>
1562{
1563public:
1564
1565 //
1566 /// Constructs a new mapper given an array of values, a getter and a setter.
1567 /// The order of the values passed determines the mapping of the selection indexes.
1568 //
1569 template <int N, class TGet, class TSet>
1571 : Begin(&values[0]), End(&values[0] + N), Getter(get), Setter(set)
1572 {}
1573
1574 //
1575 /// Overload; specialized for member functions
1576 //
1577 template <int N, class D, class R, class A>
1578 TSelectionIndexMapper(const TValue (&values)[N], D* d, R (D::*get)() const, void (D::*set)(A))
1579 : Begin(&values[0]), End(&values[0] + N),
1580 Getter(std::bind(get, d)),
1581 Setter(std::bind(set, d, std::placeholders::_1))
1582 {}
1583
1584 //
1585 /// Uses the stored getter to get the application-specific value, then converts it to a selection
1586 /// index. Returns N, the size of the value array, if the conversion can not be done.
1587 //
1588 int Get() const
1589 {return static_cast<int>(std::find(Begin, End, Getter()) - Begin);}
1590
1591 //
1592 /// Converts the given selection index to an application-specific value, then calls the stored
1593 /// setter, passing the value as an argument. Does nothing if the conversion can not be done.
1594 //
1595 void Set(int index)
1596 {
1597 if (index < 0 || index > static_cast<int>(End - Begin)) return;
1598 Setter(Begin[index]);
1599 }
1600
1601private:
1602
1603 const TValue* Begin;
1604 const TValue* End;
1605 std::function<TValue()> Getter;
1606 std::function<void(TValue)> Setter;
1607};
1608
1609
1610} // OWL namespace
1611
1612#if defined(BI_COMP_BORLANDC)
1613# pragma warn .inl // Restore warning "Functions containing 'statement' is not expanded inline".
1614#endif
1615
1616#endif
An interface object that represents a transfer buffer for a TComboBox.
Definition combobox.h:182
Dialog derivative of TDelegatedTransferWindow.
Definition transfer.h:1549
TWindow mix-in Delegates the job of transferring data to the given function object.
Definition transfer.h:1524
void TTransferFunctionSignature(const TTransferInfo &)
Definition transfer.h:1527
std::function< TTransferFunctionSignature > TTransferFunction
Definition transfer.h:1528
Typically used to obtain information from a user, a dialog box is a window inside of which other cont...
Definition dialog.h:85
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
Maps between application-specific value and a selection index, such as a radio-button group index or ...
Definition transfer.h:1562
int Get() const
Uses the stored getter to get the application-specific value, then converts it to a selection index.
Definition transfer.h:1588
void Set(int index)
Converts the given selection index to an application-specific value, then calls the stored setter,...
Definition transfer.h:1595
TSelectionIndexMapper(const TValue(&values)[N], TGet get, TSet set)
Constructs a new mapper given an array of values, a getter and a setter.
Definition transfer.h:1570
TSelectionIndexMapper(const TValue(&values)[N], D *d, R(D::*get)() const, void(D::*set)(A))
Overload; specialized for member functions.
Definition transfer.h:1578
TSystemTime is a class derived from the structure SYSTEMTIME.
Definition wsyscls.h:420
Dialog class derived from TTransferWindow Provides convenient initialization of the dialog and transf...
Definition transfer.h:1509
TTransferDialog(TWindow *parent, TResId id, TDataSource &ds, TModule *m=0)
Definition transfer.h:1512
Mix-in class template providing support for data transfer to and from controls.
Definition transfer.h:1177
void DisableDlgItem(const std::initializer_list< int > &id, bool disabled=true)
Disables (or enables) all the controls in the given initializer list.
Definition transfer.h:1284
void EnableDlgItem(const int(&id)[N], bool enabled=true)
Enables (or disables) all the controls in the given array.
Definition transfer.h:1252
void HideDlgItem(const int(&id)[N], bool hidden=true)
Hides (or shows) all the controls in the given array.
Definition transfer.h:1330
virtual void DoSetData(const TTransferInfo &, const TDataSource &)
Transfers the state of the given data source into the window.
Definition transfer.h:1496
bool IsChecked(int ctrl) const
Returns true if the given control has BST_CHECKED state.
Definition transfer.h:1342
void CheckDlgButton(int ctrl, bool checked=true)
Sets the state of the given control to BST_CHECKED (or BST_UNCHECKED).
Definition transfer.h:1434
virtual void TransferData(TTransferDirection d)
TWindow override Initialises the transfer info and dispatches to DoTransferData.
Definition transfer.h:1223
void SetData(const TDataSource &ds)
Transfers the state of the given data source into the window.
Definition transfer.h:1213
void DisableDlgItem(It first, It last, bool disabled=true)
Disables (or enables) all the controls in the given sequence.
Definition transfer.h:1271
int GetSelectedRadioButtonIndex(int firstCtrl) const
See owl::GetSelectedRadioButtonIndex.
Definition transfer.h:1452
void EnableDlgItem(const std::initializer_list< int > &id, bool enabled=true)
Enables (or disables) all the controls in the given initializer list.
Definition transfer.h:1258
void ShowDlgItem(const std::initializer_list< int > &id, bool visible=true)
Shows (or hides) all the controls in the given initializer list.
Definition transfer.h:1310
void DisableDlgItem(const int(&id)[N], bool disabled=true)
Disables (or enables) all the controls in the given array.
Definition transfer.h:1278
bool IsChecked(const std::initializer_list< int > &id) const
Returns true if any control in the given initializer list has BST_CHECKED state.
Definition transfer.h:1362
void ShowDlgItem(int ctrl, bool visible=true)
Shows (or hides) the given control.
Definition transfer.h:1290
bool IsUnchecked(const int(&id)[N]) const
Returns true if any control in the given array has BST_UNCHECKED state.
Definition transfer.h:1382
bool IsIndeterminate(int ctrl) const
Returns true if the given control has BST_INDETERMINATE state.
Definition transfer.h:1394
TDataSource * DataSource
Definition transfer.h:1471
bool IsUnchecked(It first, It last) const
Returns true if any control in the given sequence has BST_UNCHECKED state.
Definition transfer.h:1375
void CheckDlgButton(int ctrl, int state)
Resolves an integer state argument.
Definition transfer.h:1428
void HideDlgItem(const std::initializer_list< int > &id, bool hidden=true)
Hides (or shows) all the controls in the given initializer list.
Definition transfer.h:1336
void HideDlgItem(int ctrl, bool hidden=true)
Hides (or shows) the given control.
Definition transfer.h:1316
bool IsIndeterminate(const std::initializer_list< int > &id) const
Returns true if any control in the given initializer list has BST_INDETERMINATE state.
Definition transfer.h:1414
TTransferWindow(TDataSource &ds)
Definition transfer.h:1184
void ShowDlgItem(It first, It last, bool visible=true)
Shows (or hides) all the controls in the given sequence.
Definition transfer.h:1297
void EnableDlgItem(int ctrl, bool enabled=true)
Enables (or disables) the given control.
Definition transfer.h:1238
TDataSource GetData() const
Function style overload Requires that the data source type is a value type with a default constructor...
Definition transfer.h:1203
void GetData(TDataSource &ds) const
Transfer the state of the window into the given data source.
Definition transfer.h:1191
void ShowDlgItem(const int(&id)[N], bool visible=true)
Shows (or hides) all the controls in the given array.
Definition transfer.h:1304
void UncheckDlgButton(int ctrl, bool unchecked=true)
Sets the state of the given control to BST_UNCHECKED (or BST_CHECKED).
Definition transfer.h:1440
virtual void DoGetData(const TTransferInfo &, TDataSource &) const
Transfers the state of the window into the given data source.
Definition transfer.h:1489
virtual void DoTransferData(const TTransferInfo &i, TDataSource &ds)
Transfers data between window and data source in the direction specified by the given transfer inform...
Definition transfer.h:1477
void EnableDlgItem(It first, It last, bool enabled=true)
Enables (or disables) all the controls in the given sequence.
Definition transfer.h:1245
bool IsChecked(const int(&id)[N]) const
Returns true if any control in the given array has BST_CHECKED state.
Definition transfer.h:1356
bool IsUnchecked(int ctrl) const
Returns true if the given control has BST_UNCHECKED state.
Definition transfer.h:1368
bool IsIndeterminate(const int(&id)[N]) const
Returns true if any control in the given array has BST_INDETERMINATE state.
Definition transfer.h:1408
bool IsChecked(It first, It last) const
Returns true if any control in the given sequence has BST_CHECKED state.
Definition transfer.h:1349
void SetSelectedRadioButtonIndex(int firstCtrl, int selIndex)
See owl::SetSelectedRadioButtonIndex.
Definition transfer.h:1464
void SetSelectedRadioButtonIndex(HWND firstCtrl, int selIndex)
See owl::SetSelectedRadioButtonIndex.
Definition transfer.h:1458
bool IsIndeterminate(It first, It last) const
Returns true if any control in the given sequence has BST_INDETERMINATE state.
Definition transfer.h:1401
void CheckDlgButton(int ctrl, uint state)
using TWindow::CheckDlgButton;
Definition transfer.h:1420
void DisableDlgItem(int ctrl, bool disabled=true)
Disables (or enables) the given control.
Definition transfer.h:1264
int GetSelectedRadioButtonIndex(HWND firstCtrl) const
See owl::GetSelectedRadioButtonIndex.
Definition transfer.h:1446
bool HideDlgItem(It first, It last, bool hidden=true)
Hides (or shows) all the controls in the given sequence.
Definition transfer.h:1323
bool IsUnchecked(const std::initializer_list< int > &id) const
Returns true if any control in the given initializer list has BST_UNCHECKED state.
Definition transfer.h:1388
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
uint IsDlgButtonChecked(int buttonId) const
Indicates if the child button specified in the integer parameter, buttonId, is checked,...
Definition window.h:3161
virtual bool EnableWindow(bool enable)
Allows the given window to receive input from the keyboard of mouse.
Definition window.h:2172
HWND GetDlgItem(int childId) const
Retrieves the handle of a control specified by childId.
Definition window.h:3108
int GetDlgItemText(int childId, TCHAR *text, int maxValue) const
Retrieves the text of a control specified by childId.
Definition window.h:3133
void CheckDlgButton(int buttonId, uint check)
Places a check mark in (or removes a check mark from) the button specified in buttonId.
Definition window.h:3219
virtual bool ShowWindow(int cmdShow)
Displays this TWindow in a given state.
Definition window.cpp:3713
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
Definition of TDialog class and TDialogAttr struct.
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
void Transfer(const TTransferInfo &i, const TCtrl &ctrl, TGet get, TSet set, TTransfer transfer)
Definition transfer.h:668
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
std::ostringstream tostringstream
Definition strmdefs.h:36
void DDX_HotKey(const TTransferInfo &i, int id, uint16 &key)
Transfers the hotkey value of a hotkey control.
Definition transfer.h:592
void SetDlgItemText(HWND ctrl, const tstring &text)
String overload.
Definition transfer.h:63
void DDX_IPAddress(const TTransferInfo &i, int id, uint32 &data)
Transfers the address for a IP address control as a 32-bit value.
Definition transfer.h:598
void DDX_CBIndex(const TTransferInfo &i, int id, int &selIndex)
Transfers the selection index of a combo box control.
Definition transfer.h:555
void TransferCheckListData(const TTransferInfo &, HWND ctrl, TCheckListData &data)
Transfers all the data for a check list box.
Definition transfer.cpp:123
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 DDX_CBString(const TTransferInfo &i, int id, tstring &selString)
Transfers the selection string of a combo box control.
Definition transfer.h:561
void DDX_Check(const TTransferInfo &i, int id, UINT &state)
Transfers the state of the checkbox to the given integer variable.
Definition transfer.h:574
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 DDX_LBString(const TTransferInfo &i, int id, tstring &selString)
Transfers the selection string of a list box control.
Definition transfer.h:610
void DDX_DateTimeCtrl(const TTransferInfo &i, int id, TSystemTime &selTime)
Transfers the selected date and time of a date and time picker control.
Definition transfer.h:580
void DDX_LBStringExact(const TTransferInfo &i, int id, tstring &selString)
Transfers the exact selection string of a list box control.
Definition transfer.h:616
void DDX_LBIndex(const TTransferInfo &i, int id, int &selIndex)
Transfers the selection index of a list box control.
Definition transfer.h:604
void TransferListBoxData(const TTransferInfo &, HWND ctrl, TListBoxData &data)
Transfers all the data for a list box control.
Definition transfer.cpp:249
void DDX_MonthCalCtrl(const TTransferInfo &i, int id, TSystemTime &curSel)
Transfers the selected date and time of a calendar control.
Definition transfer.h:622
void TransferEditData(const TTransferInfo &i, HWND ctrl, T &value)
Transfers the lexical conversion of the text contents of an edit control.
Definition transfer.h:304
void TransferStaticData(const TTransferInfo &i, HWND ctrl, T &value)
Transfers the lexical conversion of the text contents of a static control.
Definition transfer.h:390
void DDX_Scroll(const TTransferInfo &i, int id, int &position)
Transfers the current position of a scroll bar control.
Definition transfer.h:634
bool IsChecked(HWND ctrl)
Returns true if the given control has BST_CHECKED state.
Definition transfer.h:69
std::istringstream tistringstream
Definition strmdefs.h:37
void DDX_Radio(const TTransferInfo &i, int id, int &selIndex)
Transfers the index of the selected radio button within a group.
Definition transfer.h:628
unsigned short uint16
Definition number.h:33
void DDX_CBStringExact(const TTransferInfo &i, int id, tstring &selString)
Transfers the exact selection string of a combo box control.
Definition transfer.h:567
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
unsigned int uint
Definition number.h:25
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 DDX_Slider(const TTransferInfo &i, int id, int &position)
Transfers all the data for a slider control.
Definition transfer.h:640
void CheckDlgButton(HWND ctrl, bool checked=true)
Sets the state of the given control to BST_CHECKED (or BST_UNCHECKED).
Definition transfer.h:87
void UncheckDlgButton(HWND ctrl, bool unchecked=true)
Sets the state of the given control to BST_UNCHECKED (or BST_CHECKED).
Definition transfer.h:93
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
void DDX_Text(const TTransferInfo &i, int id, T &value)
Transfers the lexical conversion of the text contents of a static control.
Definition transfer.h:648
bool IsIndeterminate(HWND ctrl)
Returns true if the given control has BST_INDETERMINATE state.
Definition transfer.h:81
bool IsUnchecked(HWND ctrl)
Returns true if the given control has BST_UNCHECKED state.
Definition transfer.h:75
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
#define _OWLFUNC(p)
Definition defs.h:341
#define _OWLCLASS
Definition defs.h:338
Contains stream formatting parameters for use with TransferDlgItemText.
Definition transfer.h:224
std::ios_base::fmtflags Flags
See std::ios_base::flags.
Definition transfer.h:225
TTransferFormat & SetPrecision(std::streamsize v)
Mutator; can be chained, e.g. TTransferFormat().SetPrecision(2).SetFlags(std::ios::fixed);.
Definition transfer.h:238
TTransferFormat & SetFlags(std::ios_base::fmtflags v)
Mutator; can be chained, e.g. TTransferFormat().SetFlags(std::ios::showbase).SetWidth(7);.
Definition transfer.h:233
TTransferFormat & SetFill(tchar v)
Mutator; can be chained, e.g. TTransferFormat().SetFill(' ').SetFlags(0);.
Definition transfer.h:248
TTransferFormat & SetWidth(std::streamsize v)
Mutator; can be chained, e.g. TTransferFormat().SetWidth(7).SetFlags(std::ios::scientific);.
Definition transfer.h:243
std::streamsize Width
See std::ios_base::width.
Definition transfer.h:227
std::streamsize Precision
See std::ios_base::precision.
Definition transfer.h:226
Used to pass information to transfer functions.
Definition transfer.h:152
TTransferDirection Operation
Definition transfer.h:154
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:718
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:728
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data, TArg1 arg1)
Definition transfer.h:742
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:738
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:752
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:762
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:772
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data, const TTransferFormat &f)
Definition transfer.h:776
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data, const TTransferFormat &f)
Definition transfer.h:790
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:786
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:800
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:810
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data, TArg1 arg1)
Definition transfer.h:824
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:820
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:834
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:844
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:854
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:864
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data, const TTransferFormat &f)
Definition transfer.h:878
void operator()(const TTransferInfo &i, const TCtrl &ctrl, TData &data)
Definition transfer.h:874