Photon microGUI widgets library 0.6.0
WidgetResource.hpp
1#ifndef WIDGET_RESOURCE_HPP
2#define WIDGET_RESOURCE_HPP
3
4#include <photon/PhT.h>
5#include <photon/PtWidget.h>
6
7#include "./stdex/stdex.h"
8#include "./WidgetEvents.h"
9#include "./WidgetKeys.h"
10
11#include <cstddef> // std::size_t
12
13namespace PhWidgets
14{
15 struct WidgetResourceGroupType
16 {
17 struct unknown_type;
18
19 struct WidgetArgumentGroupType
20 {
21 struct alloc_type;
22 struct array_type;
23 struct boolean_type;
24 struct color_type;
25 struct complex_type;
26 struct flag_type;
27 struct function_type;
28 struct image_type;
29 struct pointer_type;
30 struct scalar_type;
31 struct string_type;
32 struct struct_type;
33 };
34
35 struct WidgetCallbackGroupType
36 {
37 struct callback_type;
38 struct raw_type;
39 struct hotkey_type;
40 };
41
42
43 typedef WidgetArgumentGroupType::alloc_type alloc_type; // An arbitrarily sized memory object
44 typedef WidgetArgumentGroupType::array_type array_type; // An array
45 typedef WidgetArgumentGroupType::boolean_type boolean_type; // A bit that's either on or off
46 typedef WidgetArgumentGroupType::color_type color_type; // A color
47 typedef WidgetArgumentGroupType::complex_type complex_type; // A resource that's handled in a special way; see below.
48 typedef WidgetArgumentGroupType::flag_type flag_type; // A value in which each bit has a different meaning
49 typedef WidgetArgumentGroupType::function_type function_type; // A pointer to a function
50 typedef WidgetArgumentGroupType::image_type image_type; // A pointer to a PhImage_t structure
51 typedef WidgetArgumentGroupType::pointer_type pointer_type; // A pointer to an address that you specify
52 typedef WidgetArgumentGroupType::scalar_type scalar_type; // A value that can be represented within a single long
53 typedef WidgetArgumentGroupType::string_type string_type; // A null-terminated string
54 typedef WidgetArgumentGroupType::struct_type struct_type; // A fixed-size data type, usually a structure, float, or double
55
56 typedef WidgetCallbackGroupType::callback_type callback_type;
57 typedef WidgetCallbackGroupType::raw_type callback_raw_type;
58 typedef WidgetCallbackGroupType::hotkey_type callback_hotkey_type;
59 };
60
61 namespace detail
62 {
63
64 class IPtWidget
65 {
66 public:
67 virtual ~IPtWidget() {}
68 virtual PtWidget_t *widget() const = 0;
69 };
70
71 template<class ArgT>
72 class WidgetResourceBase
73 {
74 protected:
75
76 ArgT _arg;
77 IPtWidget *_rwidget;
78
79 WidgetResourceBase(IPtWidget *widget, ArgT arg) :
80 _arg(arg),
81 _rwidget(widget)
82 {}
83
84 // A value that can be represented within a single long
85 // When setting a scalar value, you should specify the value as the third argument to PtSetArg().
86 // The fourth argument isn't used and should be set to 0.
87 // When you call PtSetResources(), the widget copies the scalar value into its own internal data structure.
88 template<class T>
89 inline
90 typename
91 stdex::enable_if<
92 sizeof(T) <= sizeof(long),
93 int
94 >::type setScalar(T scval)
95 {
96 return PtSetResource(_rwidget->widget(), _arg, scval, 0);
97 }
98
99 // A color
100 // Same as scalar.
101 inline
102 int setColor(PgColor_t color)
103 {
104 switch(color)
105 {
106 case Pg_BLACK:
107 break;
108 case Pg_DGRAY:
109 break;
110 case Pg_MGRAY:
111 break;
112 case Pg_GRAY:
113 break;
114 case Pg_WHITE:
115 break;
116 case Pg_RED :
117 break;
118 case Pg_GREEN:
119 break;
120 case Pg_BLUE:
121 break;
122 case Pg_YELLOW:
123 break;
124 case Pg_MAGENTA:
125 break;
126 case Pg_CYAN:
127 break;
128 case Pg_DGREEN:
129 break;
130 case Pg_DCYAN:
131 break;
132 case Pg_DBLUE:
133 break;
134 case Pg_BROWN:
135 break;
136 case Pg_PURPLE:
137 break;
138 case Pg_CELIDON:
139 break;
140 default:
141 {
142 const PgColorModel_t * cm = PgGetColorModel();
143
144 if(!(cm && cm->id != Pg_CM_RGB->id))
145 {
146 color &= 0x00FFFFFF;
147 }
148 break;
149 }
150 }
151
152 /*PgColor_t in[] = {color};
153 PgColor_t out[] = {color};
154 if( 0 == PgColorMatch(1, in, out))
155 color = out[0];*/
156
157 return setScalar(color);
158 }
159
160 // A null-terminated string
161 // Setting a string value is similar to setting a scalar value;
162 // you specify the string as the third argument to the PtSetArg() macro.
163 // The fourth argument is the number of bytes to copy;
164 // if it's 0, strlen() is used to determine the length of the string.
165 // When you call PtSetResources(), the widget copies the string into its own internal data structure.
166 inline
167 int setString(const char *str)
168 {
169 return setScalar(str);
170 }
171
172 /*inline int setString(const wchar_t *str)
173 {
174 return PtSetResource(widget(), _arg, str, wcslen(str));
175 }*/
176
177 // An arbitrarily sized memory object
178 // Some resources are designed to store an allocated block of memory.
179 // To set this resource, pass a pointer to the data as the third argument to PtSetArg().
180 // The fourth argument is the size of the block of memory, in bytes.
181 // The widget copies the number of bytes given into its internal memory when you call PtSetResources().
182 inline
183 int setAlloc(const void *pdata, std::size_t size)//pointer to data and size of data
184 {
185 return PtSetResource(_rwidget->widget(), _arg, pdata, size);
186 }
187
188 // Image resources are designed to store a PhImage_t structure.
189 // To set this resource, create and initialize the PhImage_t structure,
190 // and pass a pointer to it as the third argument to PtSetArg().
191 // The fourth argument is 0.
192 // The widget copies the image structure (but not any memory pointed to by the PhImage_t members) into its internal memory when you call PtSetResources().
193 inline
194 int setImage(const PhImage_t *pimage)
195 {
196 return setAlloc(pimage, 0);
197 }
198
199 // When setting an array value, the third argument to PtSetArg() is the address of the array.
200 // The fourth argument is the number of elements in the array.
201 // The widget copies the contents of the array into its own internal data structure when you call PtSetResources().
202 template<class T, std::size_t count>
203 inline
204 int setArray(T(&arr)[count])
205 {
206 return PtSetResource(_rwidget->widget(), _arg, arr, count);
207 }
208
209 inline
210 int setArray(const void *parr, std::size_t count)
211 {
212 return PtSetResource(_rwidget->widget(), _arg, parr, count);
213 }
214
215 // When setting a flag, the third argument to PtSetArg() is a bit field specifying the value of the bits to be set.
216 // The fourth argument is a bit mask indicating which elements of the bit field should be used.
217 // When you call PtSetResources(), the widget uses the bit mask to determine which bits of its internal flag resource representation to alter.
218 // It takes the bit values from the value specified.
219 inline
220 int setFlag(long flag, long bits)
221 {
222 return PtSetResource(_rwidget->widget(), _arg, bits, flag);
223 }
224
225 inline
226 int setFlag(long flag, bool on)
227 {
228 return PtSetResource(_rwidget->widget(), _arg, on ? Pt_TRUE : Pt_FALSE, flag);
229 }
230
231 // When setting a pointer resource, the pointer must be given as the third argument to PtSetArg().
232 // The fourth argument is ignored and should be set to 0.
233 // When you call PtSetResources(), the widget simply does a shallow copy of the pointer into the resource.
234 // The widget doesn't make a copy of the memory referenced by the pointer;
235 // don't free the memory while the widget is still referencing it.
236 // The widget copies the value of the pointer into its internal memory when you call PtSetResources().
237 inline
238 int setPointer(const void *p)
239 {
240 return setScalar(p);
241 }
242
243 // When setting a struct resource, pass the address of the data as the third argument to PtSetArg().
244 // The fourth argument isn't used and should be set to 0.
245 // The widget copies the data into its internal memory when you call PtSetResources().
246 inline
247 int setStruct(const void *pdata)
248 {
249 return setScalar(pdata); // photon will make a deep copy only if argument ID is known to be struct
250 }
251
252 // When setting a Boolean value, you should specify the value as the third argument to PtSetArg(),
253 // using 0 for false, and a nonzero value for true. The fourth argument isn't used, and should be set to 0.
254 // When you call PtSetResources(), the widget clears or sets one bit in its own internal data structure depending on whether or not the value is zero.
255 inline
256 int setBoolean(bool val)
257 {
258 return PtSetResource(_rwidget->widget(), _arg, val ? 1 : 0, 0);
259 }
260
261 template<std::size_t count>
262 inline
263 void addLink(PtCallback_t const (&callbacks)[count])
264 {
265 PtAddCallbacks(_rwidget->widget(), _arg, callbacks, count);
266 }
267
268 inline
269 void addLink(PtCallback_t callback)
270 {
271 PtCallback_t callbacks [] = { callback };
272
273 addLink(callbacks);
274 }
275
276 inline
277 void addLink(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
278 {
279 PtAddCallback(_rwidget->widget(), _arg, callback, data);
280 }
281
282 template<std::size_t count>
283 inline
284 void addLinkBefore(PtRawCallback_t const (&callbacks)[count])
285 {
286 PtAddFilterCallbacks(_rwidget->widget(), callbacks, count);
287 }
288
289 template<std::size_t count>
290 inline
291 void addLinkAfter(PtRawCallback_t const (&callbacks)[count])
292 {
293 PtAddEventHandlers(_rwidget->widget(), callbacks, count);
294 }
295
296 inline
297 void addLinkBefore(PtRawCallback_t callback)
298 {
299 PtRawCallback_t callbacks [] = { callback };
300
301 addLinkBefore(callbacks);
302 }
303
304 inline
305 void addLinkAfter(PtRawCallback_t callback)
306 {
307 PtRawCallback_t callbacks[] = { callback };
308
309 addLinkAfter(callbacks);
310 }
311
312 inline
313 void addLinkBefore(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
314 {
315 // Invoked before the event is processed by the widget.
316 // They let you perform actions based on the event before the widget sees it.
317 // They also give you the opportunity to decide if the event should be ignored, discarded, or allowed to be processed by the widget.
318 PtAddFilterCallback(_rwidget->widget(), _arg, callback, data);
319 }
320
321 inline
322 void addLinkAfter(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
323 {
324 // invoked after the widget has processed the event, even if the widget's class methods consume it
325 PtAddEventHandler(_rwidget->widget(), _arg, callback, data);
326 }
327
328 inline
329 void addLink(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), KeyModes::eKeyModes keymode = KeyModes::none, bool chained = false, void *data = nullptr)
330 {
331 PtAddHotkeyHandler(_rwidget->widget(), _arg, keymode, chained ? Pt_HOTKEY_CHAINED : 0, data, callback);
332 }
333
334 template<std::size_t count>
335 inline
336 void removeLink(PtCallback_t const (&callbacks)[count])
337 {
338 PtRemoveCallbacks(_rwidget->widget(), _arg, callbacks, count);
339 }
340
341 inline
342 void removeLink(PtCallback_t callback)
343 {
344 PtCallback_t callbacks [] = { callback };
345
346 removeLink(callbacks);
347 }
348
349 inline
350 void removeLink(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
351 {
352 PtRemoveCallback(_rwidget->widget(), _arg, callback, data);
353 }
354
355 template<std::size_t count>
356 inline
357 void removeLinkBefore(PtRawCallback_t const (&callbacks)[count])
358 {
359 PtRemoveFilterHandlers(_rwidget->widget(), callbacks, count);
360 }
361
362 template<std::size_t count>
363 inline
364 void removeLinkAfter(PtRawCallback_t const (&callbacks)[count])
365 {
366 PtRemoveEventHandlers(_rwidget->widget(), callbacks, count);
367 }
368
369 inline
370 void removeLinkBefore(PtRawCallback_t callback)
371 {
372 PtRawCallback_t callbacks [] = { callback };
373
374 removeLinkBefore(callbacks);
375 }
376
377 inline
378 void removeLinkAfter(PtRawCallback_t callback)
379 {
380 PtRawCallback_t callbacks[] = { callback };
381
382 removeLinkAfter(callbacks);
383 }
384
385 inline
386 void removeLinkBefore(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
387 {
388 PtRemoveFilterCallback(_rwidget->widget(), _arg, callback, data);
389 }
390
391 inline
392 void removeLinkAfter(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
393 {
394 PtRemoveEventHandler(_rwidget->widget(), _arg, callback, data);
395 }
396
397 inline
398 void removeLink(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), KeyModes::eKeyModes keymode = KeyModes::none, bool chained = false, void *data = nullptr)
399 {
400 PtRemoveHotkeyHandler(_rwidget->widget(), _arg, keymode, chained ? Pt_HOTKEY_CHAINED : 0, data, callback);
401 }
402
403 // The value argument to PtSetArg() is the address of a pointer of the appropriate C type.
404 // len isn't used.
405 // When PtGetResources() is called,
406 // the pointer specified is set to point to the same data as the widget's internal pointer.
407 // The data is external(!) to the widget;
408 // you might be able to modify it, depending on the resource.
409 template<class T>
410 inline
411 typename stdex::enable_if<
412 stdex::is_pointer<T>::value,
413 T
414 >::type getPointer() const
415 {
416 T value = nullptr;
417 PtArg_t args[1];
418
419 PtSetArg(&args[0], _arg, &value, 0);
420 PtGetResources(_rwidget->widget(), 1, args);
421
422 return value;
423 }
424
425 // When using the pointer method to get a scalar, array, or flag resource,
426 // the widget always gives a pointer to an internal widget data structure.
427 // In the argument list element you set up using PtSetArg(),
428 // you must provide the address of a variable to which the internal data pointer can be assigned.
429 template<class T>
430 inline
431 typename stdex::enable_if<
432 stdex::is_pointer<T>::value == false,
433 typename stdex::remove_cv<T>::type const &
434 >::type getScalar() const
435 {
436 return *getPointer<const T*>();
437 }
438
439 inline
440 const char* getString() const
441 {
442 return getPointer<const char*>();
443 }
444
445 // If you set the value and len arguments to PtSetArg() to zero,
446 // PtGetResources() returns the resource's value (converted to long) as 0 (false) or 1 (true)
447 inline
448 bool getBoolean() const
449 {
450 PtArg_t arg;
451
452 PtSetArg(&arg, _arg, 0, 0);
453 PtGetResources(_rwidget->widget(), 1, &arg);
454
455 return (arg.value != 0);
456 }
457
458 // If you set the value and len arguments to PtSetArg() to zero,
459 // PtGetResources() returns the resource's value (converted to long) as Address of the data
460 template<class T>
461 inline
462 typename stdex::enable_if<
463 stdex::is_pointer<T>::value == false,
464 const T*
465 >::type getStruct() const
466 {
467 return getPointer<const T*>();
468 }
469
470 // The value argument to PtSetArg() is the address of a pointer of the appropriate type
471 // (the type is determined by the data given to the widget when this resource is set).
472 // The len isn't used.
473 // When PtGetResources() is called, the pointer specified is set to point to the widget's internal data.
474 template<class T>
475 inline
476 typename stdex::enable_if<
477 stdex::is_pointer<T>::value == true,
478 const
479 typename stdex::remove_pointer<
480 typename stdex::remove_cv<T>::type
481 >::type*
482 >::type getAlloc() const
483 {
484 typedef
485 const
486 typename stdex::remove_pointer<
487 typename stdex::remove_cv<T>::type
488 >::type* type;
489 return getPointer<type>();
490 }
491
492 inline PtCallbackList_t *getLink() const
493 {
494 PtCallbackList_t *cl;
495
496 cl = reinterpret_cast<PtCallbackList_t *>(PtGetCallbackList(_rwidget->widget(), _arg));
497
498 return cl;
499 }
500
501 inline PtRawCallbackList_t *getLinkAfter() const
502 {
503 PtRawCallbackList_t *cl;
504
505 cl = reinterpret_cast<PtRawCallbackList_t *>(PtGetCallbackList(_rwidget->widget(), Pt_CB_RAW));
506
507 return cl;
508 }
509
510 inline PtRawCallbackList_t *getLinkBefore() const
511 {
512 PtRawCallbackList_t *cl;
513
514 cl = reinterpret_cast<PtRawCallbackList_t *>(PtGetCallbackList(_rwidget->widget(), Pt_CB_FILTER));
515
516 return cl;
517 }
518
519 inline void emitLink(PtCallbackInfo_t *info) const
520 {
521 PtCallbackList_t *cl = this->getLink();
522
523 if (!cl)
524 return;
525
526 PtWidget_t *w = _rwidget->widget();
527
528 PtInvokeCallbackList(cl, w, info);
529 }
530
531
532 public:
533
534 ~WidgetResourceBase()
535 {}
536 };
537
538 template<class ArgT, class ResourceGroupT, class ResourceT>
539 struct WidgetArgument;
540
541 template<class ArgT, class ResourceT> // pointer always
542 struct WidgetArgument<
543 ArgT,
544 typename stdex::enable_if<
545 (
546 stdex::is_pointer<ResourceT>::value ||
547 stdex::is_void<ResourceT>::value
548 ),
549 WidgetResourceGroupType::alloc_type
550 >::type,
551 ResourceT
552 > :
553 private WidgetResourceBase<ArgT>
554 {
555 typedef WidgetResourceGroupType::WidgetArgumentGroupType::alloc_type resource_group_type;
556 typedef
557 typename stdex::conditional<
558 stdex::is_void<ResourceT>::value,
559 const void *,
560 typename stdex::remove_cv<ResourceT>::type const // const pointer
561 >::type resource_type;
562
563 WidgetArgument(IPtWidget *widget, ArgT arg) :
564 WidgetResourceBase<ArgT>(widget, arg)
565 {}
566
567 ~WidgetArgument()
568 {}
569
570
571 inline
572 int set(resource_type pdata, std::size_t size)
573 {
574 return this->setAlloc(&pdata, size);
575 }
576
577 inline
578 typename stdex::enable_if<
579 stdex::is_same<resource_type, const void*>::value,
580 int
581 >::type set(resource_type pdata)
582 {
583 typedef typename stdex::remove_pointer<resource_type>::type type;
584 return this->setAlloc(pdata, sizeof(type));
585 }
586
587 inline
588 resource_type get() const
589 {
590 return WidgetResourceBase<ArgT>::template getAlloc<resource_type>();
591 }
592
593 };
594
595 class NotImplemented
596 {
597 NotImplemented();
598 ~NotImplemented();
599 };
600
601 template<class ArgT, class ResourceT>
602 struct WidgetArgument<ArgT, WidgetResourceGroupType::WidgetArgumentGroupType::array_type, ResourceT> :
603 private NotImplemented//WidgetResourceBase<ArgT>
604 {
605 typedef WidgetResourceGroupType::WidgetArgumentGroupType::array_type resource_group_type;
606 typedef ResourceT resource_type;
607
608 // not impelemented
609 };
610
611 template<class ArgT, class ResourceT>
612 struct WidgetArgument<ArgT, WidgetResourceGroupType::boolean_type, ResourceT> :
613 private WidgetResourceBase<ArgT>
614 {
615 typedef WidgetResourceGroupType::boolean_type resource_group_type;
616 typedef ResourceT resource_type;
617
618 WidgetArgument(IPtWidget *widget, ArgT arg) :
619 WidgetResourceBase<ArgT>(widget, arg)
620 {}
621
622 ~WidgetArgument()
623 {}
624
625 inline
626 int set(resource_type value)
627 {
628 return this->setBoolean(value);
629 }
630
631 inline
632 resource_type get() const
633 {
634 return this->getBoolean();
635 }
636 };
637
638 template<class ArgT, class ResourceT>
639 struct WidgetArgument<ArgT, WidgetResourceGroupType::WidgetArgumentGroupType::color_type, ResourceT> :
640 private WidgetResourceBase<ArgT>
641 {
642 typedef WidgetResourceGroupType::color_type resource_group_type;
643 typedef
644 typename stdex::conditional<
645 stdex::is_void<ResourceT>::value,
646 PgColor_t,
647 ResourceT
648 >::type resource_type;
649
650 WidgetArgument(IPtWidget *widget, ArgT arg) :
651 WidgetResourceBase<ArgT>(widget, arg)
652 {}
653
654 ~WidgetArgument()
655 {}
656
657 inline
658 int set(resource_type color)
659 {
660 return setColor(color);
661 }
662
663 inline
664 resource_type get() const
665 {
666 return WidgetResourceBase<ArgT>::template getScalar<PgColor_t>();
667 }
668 };
669
670 template<class ArgT, class ResourceT>
671 struct WidgetArgument<ArgT, WidgetResourceGroupType::WidgetArgumentGroupType::complex_type, ResourceT> :
672 private NotImplemented//WidgetResourceBase<ArgT>
673 {
674 typedef WidgetResourceGroupType::WidgetArgumentGroupType::complex_type resource_group_type;
675 typedef ResourceT resource_type;
676
677 // not impelemented
678 };
679
680 namespace flag_detail
681 {
682 template<class T> struct mask_type { typedef long type; };
683 template<> struct mask_type<bool> { typedef bool type; };
684 }
685
686 template<class ArgT, class ResourceT>
687 struct WidgetArgument<ArgT, WidgetResourceGroupType::WidgetArgumentGroupType::flag_type, ResourceT> :
688 private WidgetResourceBase<ArgT>
689 {
690 typedef WidgetResourceGroupType::WidgetArgumentGroupType::flag_type resource_group_type;
691 typedef ResourceT resource_type;
692
693 WidgetArgument(IPtWidget *widget, ArgT arg) :
694 WidgetResourceBase<ArgT>(widget, arg)
695 {}
696
697 ~WidgetArgument()
698 {}
699
700
701 template<class A1, typename A2>
702 inline int set(A1 flag, A2 mask)
703 {
704 return this->setFlag(flag, static_cast<typename flag_detail::mask_type<A2>::type>(mask));
705 }
706
707 template<class A1>
708 inline int set(A1 bitmask)
709 {
710 int err = this->setFlag(bitmask, true);
711 if(0 != err)
712 return err;
713 return this->setFlag(~bitmask, false);
714 }
715
716 inline resource_type get() const
717 {
718 return WidgetResourceBase<ArgT>::template getScalar<resource_type>();
719 }
720
721 template<class A1>
722 inline bool get(A1 flag) const
723 {
724 return ((get() & flag) == flag);
725 }
726
727 };
728
729 template<class ArgT, class ResourceT>
730 struct WidgetArgument<ArgT, WidgetResourceGroupType::WidgetArgumentGroupType::function_type, ResourceT> :
731 private NotImplemented//WidgetResourceBase<ArgT>
732 {
733 typedef WidgetResourceGroupType::WidgetArgumentGroupType::function_type resource_group_type;
734 typedef ResourceT resource_type;
735
736 // not impelemented
737 };
738
739 template<class ArgT, class ResourceT>
740 struct WidgetArgument<ArgT, WidgetResourceGroupType::WidgetArgumentGroupType::image_type, ResourceT> :
741 private WidgetResourceBase<ArgT>
742 {
743 typedef WidgetResourceGroupType::image_type resource_group_type;
744 typedef
745 typename stdex::conditional<
746 stdex::is_void<ResourceT>::value,
747 const PhImage_t*,
748 ResourceT
749 >::type resource_type;
750
751 WidgetArgument(IPtWidget *widget, ArgT arg) :
752 WidgetResourceBase<ArgT>(widget, arg)
753 {}
754
755 ~WidgetArgument()
756 {}
757
758 inline
759 int set(resource_type pimage)
760 {
761 return setImage(pimage);
762 }
763
764 inline
765 resource_type get() const
766 {
767 return WidgetResourceBase<ArgT>::template getAlloc<resource_type>();
768 }
769 };
770
771 template<class ArgT, class ResourceT>
772 struct WidgetArgument<
773 ArgT,
774 typename
775 stdex::enable_if<
776 (
777 stdex::is_pointer<ResourceT>::value ||
778 stdex::is_void<ResourceT>::value
779 ),
780 WidgetResourceGroupType::pointer_type
781 >::type,
782 ResourceT
783 > :
784 private WidgetResourceBase<ArgT>
785 {
786 typedef WidgetResourceGroupType::pointer_type resource_group_type;
787 typedef
788 typename stdex::conditional<
789 stdex::is_void<ResourceT>::value,
790 void *,
791 ResourceT
792 >::type resource_type;
793
794 WidgetArgument(IPtWidget *widget, ArgT arg) :
795 WidgetResourceBase<ArgT>(widget, arg)
796 {}
797
798 ~WidgetArgument()
799 {}
800
801 inline
802 int set(resource_type value)
803 {
804 return this->setPointer(value);
805 }
806
807 inline
808 resource_type get() const
809 {
810 return WidgetResourceBase<ArgT>::template getPointer<resource_type>();
811 }
812 };
813
814 template<class ArgT, class ResourceT>
815 struct WidgetArgument<
816 ArgT,
817 typename stdex::enable_if<
818 sizeof(ResourceT) <= sizeof(long), // make shure that Resource type fits in long or goto basic WidgetArgument
819 WidgetResourceGroupType::scalar_type
820 >::type,
821 ResourceT
822 > :
823 private WidgetResourceBase<ArgT>
824 {
825 typedef WidgetResourceGroupType::WidgetArgumentGroupType::scalar_type resource_group_type;
826 typedef ResourceT resource_type;
827
828 WidgetArgument(IPtWidget *widget, ArgT arg) :
829 WidgetResourceBase<ArgT>(widget, arg)
830 {}
831
832 ~WidgetArgument()
833 {}
834
835 inline
836 int set(resource_type value)
837 {
838 return this->setScalar(value);
839 }
840
841 inline
842 resource_type get() const
843 {
844 return WidgetResourceBase<ArgT>::template getScalar<resource_type>();
845 }
846 };
847
848 template<class ArgT, class ResourceT>//const char * always
849 struct WidgetArgument<
850 ArgT,
851 typename stdex::enable_if<
852 (
853 stdex::is_same<typename stdex::remove_cv<ResourceT>::type, char*>::value ||// make shure that Resource type is const char*
854 stdex::is_void<ResourceT>::value // or void; if not goto basic WidgetArgument
855 ),
856 WidgetResourceGroupType::string_type
857 >::type,
858 ResourceT
859 > :
860 private WidgetResourceBase<ArgT>
861 {
862 typedef WidgetResourceGroupType::string_type resource_group_type;
863 typedef const char * resource_type;
864
865 WidgetArgument(IPtWidget *widget, ArgT arg) :
866 WidgetResourceBase<ArgT>(widget, arg)
867 {}
868
869 ~WidgetArgument()
870 {}
871
872 inline
873 int set(resource_type str)
874 {
875 return this->setString(str);
876 }
877
878 inline
879 resource_type get() const
880 {
881 return this->getString();
882 }
883
884 };
885
886 template<class ArgT, class ResourceT>
887 struct WidgetArgument<
888 ArgT,
889 typename stdex::enable_if<
890 stdex::is_pointer<ResourceT>::value == false,
891 WidgetResourceGroupType::struct_type
892 >::type,
893 ResourceT
894 > :
895 private WidgetResourceBase<ArgT>
896 {
897 public:
898 typedef WidgetResourceGroupType::struct_type resource_group_type;
899 typedef ResourceT resource_type;
900
901 WidgetArgument(IPtWidget *widget, ArgT arg) :
902 WidgetResourceBase<ArgT>(widget, arg)
903 {}
904
905 ~WidgetArgument()
906 {}
907
908
909 inline
910 int set(resource_type value)
911 {
912 return this->setStruct(&value);
913 }
914
915 template<class T>
916 inline
917 int set(const T &value)
918 {
919 return this->setStruct(&static_cast<const resource_type&>(value));
920 }
921
922 inline
923 const resource_type& get() const
924 {
925 return *WidgetResourceBase<ArgT>::template getStruct<resource_type>();
926 }
927 };
928
929 struct WidgetArgumentsBase
930 {
931 //friend class WidgetResourcesSingleton;
932
933 /*template<class ArgT>
934 static std::map<ArgT, WidgetArgument <ArgT> > &_resources()
935 {
936 static std::map<ArgT, WidgetArgument <ArgT> > resources;
937
938 return resources;
939 }*/
940
941 protected:
942
943 /*
944 template<class ArgT>
945 WidgetArgument<ArgT> &operator [](const ArgT indx) const
946 {
947 static std::map<ArgT, WidgetArgument <ArgT> > &resources = _resources<ArgT>();
948
949 if(resources.find(indx) == resources.end())
950 {
951 resources.insert(std::make_pair(indx, WidgetArgument <ArgT> ( _widget, indx )));
952 }
953
954 return resources.find(indx)->second;
955 }
956 */
957
958 /*template<class ArgT>
959 inline WidgetArgument<ArgT> operator [](const ArgT indx) const
960 {
961 return WidgetArgument <ArgT> ( _widget, indx );
962 }*/
963
964 IPtWidget *_widget; // pointer to parent widget!!!
965
966 WidgetArgumentsBase(IPtWidget *widget) :
967 _widget(widget)
968 {
969 }
970
971 ~WidgetArgumentsBase()
972 {
973 }
974
975 public:
976
977 template<class ArgT, class ResourceGroupT, class ResourceT>
978 inline WidgetArgument<ArgT, ResourceGroupT, ResourceT> resource(const ArgT indx) const
979 {
980 return WidgetArgument <ArgT, ResourceGroupT, ResourceT>(_widget, indx);
981 }
982 };
983
984 template<class LinkT, class ResourceT = PtCallback_t*>
985 struct WidgetCallback :
986 private WidgetResourceBase<LinkT>
987 {
988 typedef WidgetResourceGroupType::WidgetCallbackGroupType::callback_type resource_group_type;
989 typedef ResourceT resource_type;
990
991 WidgetCallback(IPtWidget *widget, LinkT arg) :
992 WidgetResourceBase<LinkT>(widget, arg)
993 {}
994
995 ~WidgetCallback()
996 {}
997
998
999 inline void add(resource_type callback)
1000 {
1001 this->addLink(callback);
1002 }
1003
1004 inline void add(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
1005 {
1006 this->addLink(callback, data);
1007 }
1008
1009 inline void remove(resource_type callback)
1010 {
1011 this->removeLink(callback);
1012 }
1013
1014 inline void remove(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
1015 {
1016 this->removeLink(callback, data);
1017 }
1018
1019 inline PtCallbackList_t* get() const
1020 {
1021 return this->getLink();
1022 }
1023
1024 inline void raise(PtCallbackInfo_t * info) const
1025 {
1026 this->emitLink(info);
1027 }
1028 };
1029
1030 /*
1031 template<class LinkT>
1032 struct WidgetCallback<LinkT, WidgetResourceGroupType::WidgetCallbackGroupType::hotkey_type, PtHotkeyCallback_t*> :
1033 private WidgetResourceBase<LinkT>
1034 {
1035 typedef WidgetResourceGroupType::WidgetCallbackGroupType::hotkey_type resource_group_type;
1036 typedef PtHotkeyCallback_t* resource_type;
1037
1038 WidgetCallback(IPtWidget *widget, LinkT arg) :
1039 WidgetResourceBase<LinkT>(widget, arg)
1040 {}
1041
1042 ~WidgetCallback()
1043 {}
1044
1045
1046 inline void add(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), Hotkeys::eHotkeys hotkey, KeyModes::eKeyModes keymode = KeyModes::none)
1047 {
1048 this->addLink(callback, hotkey, keymode);
1049 }
1050
1051 inline void remove(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), Hotkeys::eHotkeys hotkey, KeyModes::eKeyModes keymode = KeyModes::none)
1052 {
1053 this->removeLink(callback, hotkey, keymode);
1054 }
1055
1056 inline PtCallbackList_t* get() const
1057 {
1058 return this->getLink();
1059 }
1060
1061 inline void raise(PtCallbackInfo_t * info) const
1062 {
1063 this->emitLink(info);
1064 }
1065 };
1066
1067 template<class LinkT>
1068 struct WidgetCallback<LinkT, WidgetResourceGroupType::WidgetCallbackGroupType::hotkey_type, void> :
1069 private WidgetResourceBase<LinkT>
1070 {
1071 typedef WidgetResourceGroupType::WidgetCallbackGroupType::hotkey_type resource_group_type;
1072 typedef PtHotkeyCallback_t* resource_type;
1073
1074 WidgetCallback(IPtWidget *widget, LinkT arg) :
1075 WidgetResourceBase<LinkT>(widget, arg)
1076 {}
1077
1078 ~WidgetCallback()
1079 {}
1080
1081
1082 inline void add(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), Hotkeys::eHotkeys hotkey, KeyModes::eKeyModes keymode = KeyModes::none)
1083 {
1084 this->addLink(callback, hotkey, keymode);
1085 }
1086
1087 inline void remove(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), Hotkeys::eHotkeys hotkey, KeyModes::eKeyModes keymode = KeyModes::none)
1088 {
1089 this->removeLink(callback, hotkey, keymode);
1090 }
1091
1092 inline PtCallbackList_t* get() const
1093 {
1094 return this->getLink();
1095 }
1096
1097 inline void raise(PtCallbackInfo_t * info) const
1098 {
1099 this->emitLink(info);
1100 }
1101 };
1102 */
1103
1104 struct WidgetCallbacksBase
1105 {
1106
1107 protected:
1108
1109 IPtWidget *_widget; // pointer to parent widget!!!
1110
1111 WidgetCallbacksBase(IPtWidget *widget) :
1112 _widget(widget)
1113 {
1114 }
1115
1116 ~WidgetCallbacksBase()
1117 {
1118 }
1119
1120 public:
1121 template<class LinkT, class ResourceT>
1122 inline WidgetCallback<LinkT, ResourceT> resource(const LinkT indx) const
1123 {
1124 return WidgetCallback <LinkT, ResourceT>(_widget, indx);
1125 }
1126
1127 };
1128
1129 template<class EventT = Events::eEvents, class ResourceT = PtRawCallback_t*>
1130 struct WidgetRawCallback:
1131 private WidgetResourceBase<EventT>
1132 {
1133 typedef WidgetResourceGroupType::WidgetCallbackGroupType::raw_type resource_group_type;
1134 typedef ResourceT resource_type;
1135
1136 WidgetRawCallback(IPtWidget *widget, EventT arg) :
1137 WidgetResourceBase<EventT>(widget, arg)
1138 {}
1139
1140
1141 ~WidgetRawCallback()
1142 {}
1143
1144
1145 inline void add(resource_type callback)
1146 {
1147 this->addLinkAfter(callback);
1148 }
1149
1150 inline void add(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
1151 {
1152 this->addLinkAfter(callback, data);
1153 }
1154
1155 inline void remove(resource_type callback)
1156 {
1157 this->removeLinkAfter(callback);
1158 }
1159
1160 inline void remove(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
1161 {
1162 this->removeLinkAfter(callback, data);
1163 }
1164
1165 inline PtRawCallbackList_t* get() const
1166 {
1167 return this->getLinkAfter();
1168 }
1169
1170 // can't raise this type of callbacks
1171 };
1172
1173 struct WidgetRawCallbacksBase
1174 {
1175
1176 protected:
1177
1178 IPtWidget *_widget; // pointer to parent widget!!!
1179
1180 WidgetRawCallbacksBase(IPtWidget *widget) :
1181 _widget(widget)
1182 {
1183 }
1184
1185 ~WidgetRawCallbacksBase()
1186 {
1187 }
1188
1189 public:
1190 template<class EventT, class ResourceT>
1191 inline WidgetRawCallback<EventT, ResourceT> resource(const EventT indx) const
1192 {
1193 return WidgetRawCallback <EventT, ResourceT>(_widget, indx);
1194 }
1195
1196 };
1197
1198 template<class EventT = Events::eEvents, class ResourceT = PtRawCallback_t*>
1199 struct WidgetFilterCallback:
1200 private WidgetResourceBase<EventT>
1201 {
1202 typedef WidgetResourceGroupType::WidgetCallbackGroupType::raw_type resource_group_type;
1203 typedef ResourceT resource_type;
1204
1205 WidgetFilterCallback(IPtWidget *widget, EventT arg) :
1206 WidgetResourceBase<EventT>(widget, arg)
1207 {}
1208
1209
1210 ~WidgetFilterCallback()
1211 {}
1212
1213
1214 inline void add(resource_type callback)
1215 {
1216 this->addLinkAfter(callback);
1217 }
1218
1219 inline void add(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
1220 {
1221 this->addLinkBefore(callback, data);
1222 }
1223
1224 inline void remove(resource_type callback)
1225 {
1226 this->removeLinkBefore(callback);
1227 }
1228
1229 inline void remove(int(*callback)(PtWidget_t *, void *, PtCallbackInfo_t *), void *data = nullptr)
1230 {
1231 this->removeLinkBefore(callback, data);
1232 }
1233
1234 inline PtRawCallbackList_t* get() const
1235 {
1236 return this->getLinkBefore();
1237 }
1238
1239 // can't raise this type of callbacks
1240 };
1241
1242 struct WidgetFilterCallbacksBase
1243 {
1244
1245 protected:
1246
1247 IPtWidget *_widget; // pointer to parent widget!!!
1248
1249 WidgetFilterCallbacksBase(IPtWidget *widget) :
1250 _widget(widget)
1251 {
1252 }
1253
1254 ~WidgetFilterCallbacksBase()
1255 {
1256 }
1257
1258 public:
1259 template<class EventT, class ResourceT>
1260 inline WidgetFilterCallback<EventT, ResourceT> resource(const EventT indx) const
1261 {
1262 return WidgetFilterCallback <EventT, ResourceT>(_widget, indx);
1263 }
1264
1265 };
1266
1267
1268 namespace def_help
1269 {
1270 struct BasePrevType
1271 {
1272 typedef WidgetCallbacksBase WidgetCallbacks;
1273 typedef WidgetArgumentsBase WidgetArguments;
1274 };
1275
1276
1277 template<class PrevT>
1278 struct Define;
1279 }
1280
1281 namespace def_orig
1282 {
1283 template< class WidgetArgumentsT, class WidgetCallbacksT, class LinkT, class ResourceT >
1284 struct LinkType
1285 {
1286 struct WidgetCallbacks :
1287 public WidgetCallbacksT
1288
1289 {
1290 using WidgetCallbacksT::operator [];
1291
1292 inline WidgetCallback<LinkT, ResourceT> operator [](const LinkT indx) const
1293 {
1294 typedef WidgetCallbacksBase Base;
1295
1296 return static_cast<const Base*>(this)->resource<LinkT, ResourceT>(indx);
1297 }
1298
1299 protected:
1300
1301
1302 friend class LinkType<WidgetArgumentsT, WidgetCallbacksT, LinkT, ResourceT>;
1303
1304 template<class, class, class, class, class>
1305 friend class ArgumentType;
1306
1307 WidgetCallbacks(IPtWidget *widget) :
1308 WidgetCallbacksT(widget)
1309 {
1310 }
1311
1312 ~WidgetCallbacks()
1313 {
1314 }
1315 };
1316
1317 typedef WidgetArgumentsT WidgetArguments;
1318
1319 WidgetArguments argument;
1320 WidgetCallbacks callback;
1321
1322 LinkType(IPtWidget *widget) :
1323 argument(widget),
1324 callback(widget)
1325 {}
1326
1327
1328 private:
1329 LinkType(const LinkType&);
1330 };
1331
1332 template< class WidgetArgumentsT, class LinkT, class ResourceT >
1333 struct LinkType<WidgetArgumentsT, WidgetCallbacksBase, LinkT, ResourceT>
1334 {
1335 struct WidgetCallbacks:
1336 protected WidgetCallbacksBase
1337 {
1338
1339 inline WidgetCallback<LinkT, ResourceT> operator [](const LinkT indx) const
1340 {
1341 typedef WidgetCallbacksBase Base;
1342
1343 return static_cast<const Base*>(this)->resource<LinkT, ResourceT>(indx);
1344 }
1345
1346 protected:
1347
1348 friend class LinkType<WidgetArgumentsT, WidgetCallbacksBase, LinkT, ResourceT>;
1349
1350 template<class, class, class, class, class>
1351 friend class ArgumentType;
1352
1353 WidgetCallbacks(IPtWidget *widget) :
1354 WidgetCallbacksBase(widget)
1355 {
1356 }
1357
1358 ~WidgetCallbacks()
1359 {
1360 }
1361 };
1362
1363 typedef WidgetArgumentsT WidgetArguments;
1364
1365 WidgetArguments argument;
1366 WidgetCallbacks callback;
1367
1368 LinkType(IPtWidget *widget) :
1369 argument(widget),
1370 callback(widget)
1371 {}
1372
1373
1374 private:
1375 LinkType(const LinkType&);
1376 };
1377
1378 template< class WidgetCallbacksT, class LinkT, class ResourceT >
1379 struct LinkType<WidgetArgumentsBase, WidgetCallbacksT, LinkT, ResourceT>
1380 {
1381 struct WidgetCallbacks :
1382 public WidgetCallbacksT
1383
1384 {
1385 using WidgetCallbacksT::operator [];
1386
1387 inline WidgetCallback<LinkT, ResourceT> operator [](const LinkT indx) const
1388 {
1389 typedef WidgetCallbacksBase Base;
1390
1391 return static_cast<const Base*>(this)->resource<LinkT, ResourceT>(indx);
1392 }
1393
1394 protected:
1395
1396 friend class LinkType<WidgetArgumentsBase, WidgetCallbacksT, LinkT, ResourceT>;
1397
1398 template<class, class, class, class, class>
1399 friend class ArgumentType;
1400
1401 WidgetCallbacks(IPtWidget *widget) :
1402 WidgetCallbacksT(widget)
1403 {
1404 }
1405
1406 ~WidgetCallbacks()
1407 {
1408 }
1409 };
1410
1411 typedef WidgetArgumentsBase WidgetArguments;
1412
1413 WidgetCallbacks callback;
1414
1415 LinkType(IPtWidget *widget) :
1416 callback(widget)
1417 {}
1418
1419
1420 private:
1421 LinkType(const LinkType&);
1422 };
1423
1424 template< class LinkT, class ResourceT >
1425 struct LinkType<WidgetArgumentsBase, WidgetCallbacksBase, LinkT, ResourceT>
1426 {
1427 struct WidgetCallbacks:
1428 protected WidgetCallbacksBase
1429 {
1430
1431 inline WidgetCallback<LinkT, ResourceT> operator [](const LinkT indx) const
1432 {
1433 typedef WidgetCallbacksBase Base;
1434
1435 return static_cast<const Base*>(this)->resource<LinkT, ResourceT>(indx);
1436 }
1437
1438 protected:
1439
1440 friend class LinkType<WidgetArgumentsBase, WidgetCallbacksBase, LinkT, ResourceT>;
1441
1442 template<class, class, class, class, class>
1443 friend class ArgumentType;
1444
1445 WidgetCallbacks(IPtWidget *widget) :
1446 WidgetCallbacksBase(widget)
1447 {
1448 }
1449
1450 ~WidgetCallbacks()
1451 {
1452 }
1453 };
1454
1455 typedef WidgetArgumentsBase WidgetArguments;
1456
1457 WidgetCallbacks callback;
1458
1459 LinkType(IPtWidget *widget) :
1460 callback(widget)
1461 {}
1462
1463
1464 private:
1465 LinkType(const LinkType&);
1466 };
1467
1468
1469
1470 template< class WidgetArgumentsT, class WidgetCallbacksT, class ArgT, class ResourceGroupT, class ResourceT >
1471 struct ArgumentType
1472 {
1473 struct WidgetArguments :
1474 public WidgetArgumentsT
1475
1476 {
1477 using WidgetArgumentsT::operator [];
1478
1479 inline WidgetArgument<ArgT, ResourceGroupT, ResourceT> operator [](const ArgT indx) const
1480 {
1481 typedef WidgetArgumentsBase Base;
1482
1483 return static_cast<const Base*>(this)->resource<ArgT, ResourceGroupT, ResourceT>(indx);
1484 }
1485
1486 protected:
1487
1488 friend class ArgumentType<WidgetArgumentsT, WidgetCallbacksT, ArgT, ResourceGroupT, ResourceT>;
1489
1490 template<class, class, class, class>
1491 friend class LinkType;
1492
1493 WidgetArguments(IPtWidget *widget) :
1494 WidgetArgumentsT(widget)
1495 {
1496 }
1497
1498 ~WidgetArguments()
1499 {
1500 }
1501 };
1502
1503 typedef WidgetCallbacksT WidgetCallbacks;
1504
1505 WidgetArguments argument;
1506 WidgetCallbacks callback;
1507
1508 ArgumentType(IPtWidget *widget) :
1509 argument(widget),
1510 callback(widget)
1511 {}
1512
1513
1514 private:
1515 ArgumentType(const ArgumentType&);
1516 };
1517
1518 template< class WidgetCallbacksT, class ArgT, class ResourceGroupT, class ResourceT >
1519 struct ArgumentType<WidgetArgumentsBase, WidgetCallbacksT, ArgT, ResourceGroupT, ResourceT>
1520 {
1521 struct WidgetArguments:
1522 protected WidgetArgumentsBase
1523 {
1524 inline WidgetArgument<ArgT, ResourceGroupT, ResourceT> operator [](const ArgT indx) const
1525 {
1526 typedef WidgetArgumentsBase Base;
1527
1528 return static_cast<const Base*>(this)->resource<ArgT, ResourceGroupT, ResourceT>(indx);
1529 }
1530
1531 protected:
1532
1533 friend class ArgumentType<WidgetArgumentsBase, WidgetCallbacksT, ArgT, ResourceGroupT, ResourceT>;
1534
1535 template<class, class, class, class>
1536 friend class LinkType;
1537
1538 WidgetArguments(IPtWidget *widget) :
1539 WidgetArgumentsBase(widget)
1540 {
1541 }
1542
1543 ~WidgetArguments()
1544 {
1545 }
1546 };
1547
1548 typedef WidgetCallbacksT WidgetCallbacks;
1549
1550 WidgetArguments argument;
1551 WidgetCallbacks callback;
1552
1553 ArgumentType(IPtWidget *widget) :
1554 argument(widget),
1555 callback(widget)
1556 {}
1557
1558
1559 private:
1560 ArgumentType(const ArgumentType&);
1561 };
1562
1563 template< class WidgetArgumentsT, class ArgT, class ResourceGroupT, class ResourceT >
1564 struct ArgumentType<WidgetArgumentsT, WidgetCallbacksBase, ArgT, ResourceGroupT, ResourceT>
1565 {
1566 struct WidgetArguments :
1567 public WidgetArgumentsT
1568
1569 {
1570 using WidgetArgumentsT::operator [];
1571
1572 inline WidgetArgument<ArgT, ResourceGroupT, ResourceT> operator [](const ArgT indx) const
1573 {
1574 typedef WidgetArgumentsBase Base;
1575
1576 return static_cast<const Base*>(this)->resource<ArgT, ResourceGroupT, ResourceT>(indx);
1577 }
1578
1579 protected:
1580
1581 friend class ArgumentType<WidgetArgumentsT, WidgetCallbacksBase, ArgT, ResourceGroupT, ResourceT>;
1582
1583 template<class, class, class, class>
1584 friend class LinkType;
1585
1586 WidgetArguments(IPtWidget *widget) :
1587 WidgetArgumentsT(widget)
1588 {
1589 }
1590
1591 ~WidgetArguments()
1592 {
1593 }
1594 };
1595
1596 typedef WidgetCallbacksBase WidgetCallbacks;
1597
1598 WidgetArguments argument;
1599
1600 ArgumentType(IPtWidget *widget) :
1601 argument(widget)
1602 {}
1603
1604
1605 private:
1606 ArgumentType(const ArgumentType&);
1607 };
1608
1609 template< class ArgT, class ResourceGroupT, class ResourceT >
1610 struct ArgumentType<WidgetArgumentsBase, WidgetCallbacksBase, ArgT, ResourceGroupT, ResourceT>
1611 {
1612 struct WidgetArguments:
1613 protected WidgetArgumentsBase
1614 {
1615 inline WidgetArgument<ArgT, ResourceGroupT, ResourceT> operator [](const ArgT indx) const
1616 {
1617 typedef WidgetArgumentsBase Base;
1618
1619 return static_cast<const Base*>(this)->resource<ArgT, ResourceGroupT, ResourceT>(indx);
1620 }
1621
1622 protected:
1623
1624 friend class ArgumentType<WidgetArgumentsBase, WidgetCallbacksBase, ArgT, ResourceGroupT, ResourceT>;
1625
1626 template<class, class, class, class>
1627 friend class LinkType;
1628
1629 WidgetArguments(IPtWidget *widget) :
1630 WidgetArgumentsBase(widget)
1631 {
1632 }
1633
1634 ~WidgetArguments()
1635 {
1636 }
1637 };
1638
1639 typedef WidgetCallbacksBase WidgetCallbacks;
1640
1641 WidgetArguments argument;
1642
1643 ArgumentType(IPtWidget *widget) :
1644 argument(widget)
1645 {}
1646
1647
1648 private:
1649 ArgumentType(const ArgumentType&);
1650 };
1651
1652
1653 template<class PrevT, class LinkT, class ResourceT>
1654 struct Link;
1655
1656 template<class PrevT, class LinkT>
1657 struct Link<PrevT, LinkT, PtCallback_t*>
1658 {
1659 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1660 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1661 typedef WidgetResourceGroupType::WidgetCallbackGroupType::callback_type resource_group_type;
1662
1663 typedef LinkType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, PtCallback_t*> resource_type;
1664 typedef def_help::Define<resource_type> Define;
1665 };
1666
1667 template<class PrevT, class LinkT>
1668 struct Link<PrevT, LinkT, PtRawCallback_t*>
1669 {
1670 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1671 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1672 typedef WidgetResourceGroupType::WidgetCallbackGroupType::raw_type resource_group_type;
1673
1674 typedef LinkType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, PtRawCallback_t*> resource_type;
1675 typedef def_help::Define<resource_type> Define;
1676 };
1677
1678 template<class PrevT, class LinkT>
1679 struct Link<PrevT, LinkT, PtHotkeyCallback_t*>
1680 {
1681 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1682 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1683 typedef WidgetResourceGroupType::WidgetCallbackGroupType::hotkey_type resource_group_type;
1684
1685 typedef LinkType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, PtHotkeyCallback_t*> resource_type;
1686 typedef def_help::Define<resource_type> Define;
1687 };
1688
1689 template<class PrevT, class LinkT, class ResourceT>
1690 struct Callback
1691 {
1692 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1693 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1694 typedef WidgetResourceGroupType::WidgetCallbackGroupType::callback_type resource_group_type;
1695
1696 typedef LinkType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, ResourceT> resource_type;
1697 typedef def_help::Define<resource_type> Define;
1698 };
1699
1700 template<class PrevT, class LinkT, class ResourceT>
1701 struct RawCallback
1702 {
1703 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1704 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1705 typedef WidgetResourceGroupType::WidgetCallbackGroupType::raw_type resource_group_type;
1706
1707 typedef LinkType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, ResourceT> resource_type;
1708 typedef def_help::Define<resource_type> Define;
1709 };
1710
1711 template<class PrevT, class LinkT, class ResourceT>
1712 struct HotKeyCallback
1713 {
1714 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1715 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1716 typedef WidgetResourceGroupType::WidgetCallbackGroupType::hotkey_type resource_group_type;
1717
1718 typedef LinkType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, ResourceT> resource_type;
1719 typedef def_help::Define<resource_type> Define;
1720 };
1721
1722
1723 template<class PrevT, class LinkT, class ResourceT = void>
1724 struct Alloc
1725 {
1726 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1727 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1728 typedef WidgetResourceGroupType::WidgetArgumentGroupType::alloc_type resource_group_type;
1729
1730 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1731 typedef def_help::Define<resource_type> Define;
1732 };
1733
1734 template<class PrevT, class LinkT, class ResourceT>
1735 struct Array
1736 {
1737 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1738 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1739 typedef WidgetResourceGroupType::WidgetArgumentGroupType::array_type resource_group_type;
1740
1741 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1742 typedef def_help::Define<resource_type> Define;
1743 };
1744
1745 template<class PrevT, class LinkT, class ResourceT>
1746 struct Boolean
1747 {
1748 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1749 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1750 typedef WidgetResourceGroupType::WidgetArgumentGroupType::boolean_type resource_group_type;
1751
1752 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1753 typedef def_help::Define<resource_type> Define;
1754 };
1755
1756 template<class PrevT, class LinkT, class ResourceT = void>
1757 struct Color
1758 {
1759 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1760 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1761 typedef WidgetResourceGroupType::WidgetArgumentGroupType::color_type resource_group_type;
1762
1763 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1764 typedef def_help::Define<resource_type> Define;
1765 };
1766
1767 template<class PrevT, class LinkT, class ResourceT>
1768 struct Complex
1769 {
1770 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1771 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1772 typedef WidgetResourceGroupType::WidgetArgumentGroupType::complex_type resource_group_type;
1773
1774 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1775 typedef def_help::Define<resource_type> Define;
1776 };
1777
1778 template<class PrevT, class LinkT, class ResourceT>
1779 struct Flag
1780 {
1781 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1782 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1783 typedef WidgetResourceGroupType::WidgetArgumentGroupType::flag_type resource_group_type;
1784
1785 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1786 typedef def_help::Define<resource_type> Define;
1787 };
1788
1789 template<class PrevT, class LinkT, class ResourceT>
1790 struct Function
1791 {
1792 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1793 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1794 typedef WidgetResourceGroupType::WidgetArgumentGroupType::function_type resource_group_type;
1795
1796 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1797 typedef def_help::Define<resource_type> Define;
1798 };
1799
1800 template<class PrevT, class LinkT, class ResourceT = void>
1801 struct Image
1802 {
1803 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1804 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1805 typedef WidgetResourceGroupType::WidgetArgumentGroupType::image_type resource_group_type;
1806
1807 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1808 typedef def_help::Define<resource_type> Define;
1809 };
1810
1811 template<class PrevT, class LinkT, class ResourceT = void>
1812 struct Pointer
1813 {
1814 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1815 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1816 typedef WidgetResourceGroupType::WidgetArgumentGroupType::pointer_type resource_group_type;
1817
1818 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1819 typedef def_help::Define<resource_type> Define;
1820 };
1821
1822 template<class PrevT, class LinkT, class ResourceT>
1823 struct Scalar
1824 {
1825 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1826 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1827 typedef WidgetResourceGroupType::WidgetArgumentGroupType::scalar_type resource_group_type;
1828
1829 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1830 typedef def_help::Define<resource_type> Define;
1831 };
1832
1833 template<class PrevT, class LinkT, class ResourceT = void>
1834 struct String
1835 {
1836 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1837 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1838 typedef WidgetResourceGroupType::WidgetArgumentGroupType::string_type resource_group_type;
1839
1840 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1841 typedef def_help::Define<resource_type> Define;
1842 };
1843
1844 template<class PrevT, class LinkT, class ResourceT>
1845 struct Struct
1846 {
1847 typedef typename PrevT::WidgetCallbacks prev_widget_callbacks_type;
1848 typedef typename PrevT::WidgetArguments prev_widget_arguments_type;
1849 typedef WidgetResourceGroupType::WidgetArgumentGroupType::struct_type resource_group_type;
1850
1851 typedef ArgumentType<prev_widget_arguments_type, prev_widget_callbacks_type, LinkT, resource_group_type, ResourceT> resource_type;
1852 typedef def_help::Define<resource_type> Define;
1853 };
1854 }
1855
1856 namespace def_help
1857 {
1858 template<class PrevT>
1859 struct Define
1860 {
1861 template<class LinkT, class ResourceT>
1862 struct Link : def_orig::Link<PrevT, LinkT, ResourceT> {};
1863
1864 template<class LinkT, class ResourceT>
1865 struct Callback : def_orig::Callback<PrevT, LinkT, ResourceT> {};
1866
1867 template<class LinkT, class ResourceT>
1868 struct RawCallback : def_orig::RawCallback<PrevT, LinkT, ResourceT> {};
1869
1870 template<class LinkT, class ResourceT>
1871 struct HotKeyCallback : def_orig::HotKeyCallback<PrevT, LinkT, ResourceT> {};
1872
1873 template<class ArgT, class ResourceT = void>
1874 struct Alloc : def_orig::Alloc<PrevT, ArgT, ResourceT> {};
1875
1876 template<class ArgT, class ResourceT>
1877 struct Array : def_orig::Array<PrevT, ArgT, ResourceT> {};
1878
1879 template<class ArgT, class ResourceT>
1880 struct Boolean : def_orig::Boolean<PrevT, ArgT, ResourceT> {};
1881
1882 template<class ArgT, class ResourceT = void>
1883 struct Color : def_orig::Color<PrevT, ArgT, ResourceT> {};
1884
1885 template<class ArgT, class ResourceT>
1886 struct Complex : def_orig::Complex<PrevT, ArgT, ResourceT> {};
1887
1888 template<class ArgT, class ResourceT>
1889 struct Flag : def_orig::Flag<PrevT, ArgT, ResourceT> {};
1890
1891 template<class ArgT, class ResourceT>
1892 struct Function : def_orig::Function<PrevT, ArgT, ResourceT> {};
1893
1894 template<class ArgT, class ResourceT = void>
1895 struct Image : def_orig::Image<PrevT, ArgT, ResourceT> {};
1896
1897 template<class ArgT, class ResourceT = void>
1898 struct Pointer : def_orig::Pointer<PrevT, ArgT, ResourceT> {};
1899
1900 template<class ArgT, class ResourceT>
1901 struct Scalar : def_orig::Scalar<PrevT, ArgT, ResourceT> {};
1902
1903 template<class ArgT, class ResourceT = void>
1904 struct String : def_orig::String<PrevT, ArgT, ResourceT> {};
1905
1906 template<class ArgT, class ResourceT>
1907 struct Struct : def_orig::Struct<PrevT, ArgT, ResourceT> {};
1908 };
1909 }
1910
1911
1912
1913
1914 }
1915
1916 template<class PrevT = detail::def_help::BasePrevType>
1917 struct ResourceFrom
1918 {
1919 struct Define :
1920 detail::def_help::Define<PrevT>
1921 {};
1922
1923 template<class PrevTNext>
1924 struct And :
1925 ResourceFrom<PrevTNext>
1926 {};
1927 };
1928}
1929
1930#endif // WIDGET_RESOURCE_HPP
The main namespace for all widgets.
Definition: Basic.h:11