1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include "XPCWidget.h"
XPCWidget::XPCWidget(
int inLeft,
int inTop,
int inRight,
int inBottom,
bool inVisible,
const char * inDescriptor,
bool inIsRoot,
XPWidgetID inParent,
XPWidgetClass inClass) :
mWidget(NULL),
mOwnsChildren(false),
mOwnsWidget(true)
{
mWidget = XPCreateWidget(
inLeft, inTop, inRight, inBottom,
inVisible ? 1 : 0,
inDescriptor,
inIsRoot ? 1 : 0,
inIsRoot ? NULL : inParent,
inClass);
XPSetWidgetProperty(mWidget, xpProperty_Object, reinterpret_cast<intptr_t>(this));
XPAddWidgetCallback(mWidget, WidgetCallback);
}
XPCWidget::XPCWidget(
XPWidgetID inWidget,
bool inOwnsWidget) :
mWidget(inWidget),
mOwnsChildren(false),
mOwnsWidget(inOwnsWidget)
{
XPSetWidgetProperty(mWidget, xpProperty_Object, reinterpret_cast<intptr_t>(this));
XPAddWidgetCallback(mWidget, WidgetCallback);
}
XPCWidget::~XPCWidget()
{
if (mOwnsWidget)
XPDestroyWidget(mWidget, mOwnsChildren ? 1 : 0);
}
void XPCWidget::SetOwnsWidget(
bool inOwnsWidget)
{
mOwnsWidget = inOwnsWidget;
}
void XPCWidget::SetOwnsChildren(
bool inOwnsChildren)
{
mOwnsChildren = inOwnsChildren;
}
XPCWidget::operator XPWidgetID () const
{
return mWidget;
}
XPWidgetID XPCWidget::Get(void) const
{
return mWidget;
}
void XPCWidget::AddAttachment(
XPCWidgetAttachment * inAttachment,
bool inOwnsAttachment,
bool inPrefilter)
{
if (inPrefilter)
{
mAttachments.insert(mAttachments.begin(), AttachmentInfo(inAttachment, inOwnsAttachment));
} else {
mAttachments.push_back(AttachmentInfo(inAttachment, inOwnsAttachment));
}
}
void XPCWidget::RemoveAttachment(
XPCWidgetAttachment * inAttachment)
{
for (AttachmentVector::iterator iter = mAttachments.begin();
iter != mAttachments.end(); ++iter)
{
if (iter->first == inAttachment)
{
mAttachments.erase(iter);
return;
}
}
}
int XPCWidget::HandleWidgetMessage(
XPWidgetMessage inMessage,
XPWidgetID inWidget,
intptr_t inParam1,
intptr_t inParam2)
{
return 0;
}
int XPCWidget::WidgetCallback(
XPWidgetMessage inMessage,
XPWidgetID inWidget,
intptr_t inParam1,
intptr_t inParam2)
{
XPCWidget * me = reinterpret_cast<XPCWidget *>(XPGetWidgetProperty(inWidget, xpProperty_Object, NULL));
if (me == NULL)
return 0;
for (AttachmentVector::iterator iter = me->mAttachments.begin(); iter !=
me->mAttachments.end(); ++iter)
{
int result = iter->first->HandleWidgetMessage(me, inMessage, inWidget, inParam1, inParam2);
if (result != 0)
return result;
}
return me->HandleWidgetMessage(inMessage, inWidget, inParam1, inParam2);
}
|