forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayout.cpp
177 lines (156 loc) · 5.44 KB
/
Layout.cpp
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#include <pch.h>
#include <common.h>
#include "ItemsRepeater.common.h"
#include "Layout.h"
#include "VirtualizingLayoutContext.h"
#include "LayoutContextAdapter.h"
#pragma region ILayout
winrt::hstring Layout::LayoutId()
{
return m_layoutId;
}
void Layout::LayoutId(winrt::hstring const& value)
{
m_layoutId = value;
}
namespace
{
winrt::VirtualizingLayoutContext GetVirtualizingLayoutContext(winrt::LayoutContext const& context)
{
if (auto virtualizingContext = context.try_as<winrt::VirtualizingLayoutContext>())
{
return virtualizingContext;
}
else if (auto nonVirtualizingContext = context.try_as<winrt::NonVirtualizingLayoutContext>())
{
auto adapter = winrt::get_self<NonVirtualizingLayoutContext>(nonVirtualizingContext)->GetVirtualizingContextAdapter();
return adapter;
}
else
{
throw winrt::hresult_not_implemented();
}
}
winrt::NonVirtualizingLayoutContext GetNonVirtualizingLayoutContext(winrt::LayoutContext const& context)
{
if (auto nonVirtualizingContext = context.try_as<winrt::NonVirtualizingLayoutContext>())
{
return nonVirtualizingContext;
}
else if (auto virtualizingContext = context.try_as<winrt::VirtualizingLayoutContext>())
{
auto adapter = winrt::get_self<VirtualizingLayoutContext>(virtualizingContext)->GetNonVirtualizingContextAdapter();
return adapter;
}
else
{
throw winrt::hresult_not_implemented();
}
}
}
void Layout::InitializeForContext(winrt::LayoutContext const& context)
{
auto spThis = get_strong();
if (auto virtualizingLayout = spThis.try_as<winrt::IVirtualizingLayoutOverrides>())
{
auto virtualizingContext = GetVirtualizingLayoutContext(context);
return virtualizingLayout.InitializeForContextCore(virtualizingContext);
}
else if (auto nonVirtualizingLayout = get_strong().try_as<winrt::INonVirtualizingLayoutOverrides>())
{
auto nonVirtualizingContext = GetNonVirtualizingLayoutContext(context);
return nonVirtualizingLayout.InitializeForContextCore(nonVirtualizingContext);
}
else
{
throw winrt::hresult_not_implemented();
}
}
void Layout::UninitializeForContext(winrt::LayoutContext const& context)
{
auto spThis = get_strong();
if (auto virtualizingLayout = spThis.try_as<winrt::IVirtualizingLayoutOverrides>())
{
auto virtualizingContext = GetVirtualizingLayoutContext(context);
return virtualizingLayout.UninitializeForContextCore(virtualizingContext);
}
else if (auto nonVirtualizingLayout = spThis.try_as<winrt::INonVirtualizingLayoutOverrides>())
{
auto nonVirtualizingContext = GetNonVirtualizingLayoutContext(context);
return nonVirtualizingLayout.UninitializeForContextCore(nonVirtualizingContext);
}
else
{
throw winrt::hresult_not_implemented();
}
}
winrt::Size Layout::Measure(
winrt::LayoutContext const& context,
winrt::Size const& availableSize
)
{
auto spThis = get_strong();
if (auto virtualizingLayout = spThis.try_as<winrt::IVirtualizingLayoutOverrides>())
{
auto virtualizingContext = GetVirtualizingLayoutContext(context);
return virtualizingLayout.MeasureOverride(virtualizingContext, availableSize);
}
else if (auto nonVirtualizingLayout = spThis.try_as<winrt::INonVirtualizingLayoutOverrides>())
{
auto nonVirtualizingContext = GetNonVirtualizingLayoutContext(context);
return nonVirtualizingLayout.MeasureOverride(nonVirtualizingContext, availableSize);
}
else
{
throw winrt::hresult_not_implemented();
}
}
winrt::Size Layout::Arrange(
winrt::LayoutContext const& context,
winrt::Size const& finalSize)
{
auto spThis = get_strong();
if (auto virtualizingLayout = spThis.try_as<winrt::IVirtualizingLayoutOverrides>())
{
auto virtualizingContext = GetVirtualizingLayoutContext(context);
return virtualizingLayout.ArrangeOverride(virtualizingContext, finalSize);
}
else if (auto nonVirtualizingLayout = spThis.try_as<winrt::INonVirtualizingLayoutOverrides>())
{
auto nonVirtualizingContext = GetNonVirtualizingLayoutContext(context);
return nonVirtualizingLayout.ArrangeOverride(nonVirtualizingContext, finalSize);
}
else
{
throw winrt::hresult_not_implemented();
}
}
winrt::event_token Layout::MeasureInvalidated(winrt::TypedEventHandler<winrt::Layout, winrt::IInspectable> const& value)
{
return m_measureInvalidatedEventSource.add(value);
}
void Layout::MeasureInvalidated(winrt::event_token const& token)
{
m_measureInvalidatedEventSource.remove(token);
}
winrt::event_token Layout::ArrangeInvalidated(winrt::TypedEventHandler<winrt::Layout, winrt::IInspectable> const& value)
{
return m_arrangeInvalidatedEventSource.add(value);
}
void Layout::ArrangeInvalidated(winrt::event_token const& token)
{
m_arrangeInvalidatedEventSource.remove(token);
}
#pragma endregion
#pragma region ILayoutProtected
void Layout::InvalidateMeasure()
{
m_measureInvalidatedEventSource(*this, nullptr);
}
void Layout::InvalidateArrange()
{
m_arrangeInvalidatedEventSource(*this, nullptr);
}
#pragma endregion