-
Notifications
You must be signed in to change notification settings - Fork 563
/
Copy pathWholeItemsPanel.cpp
612 lines (543 loc) · 26.6 KB
/
WholeItemsPanel.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Copyright (c) 2014 Microsoft Corporation
//
#include "pch.h"
#include "WholeItemsPanel.h"
#include "XamlHelpers.h"
#include "ElementTagContent.h"
using namespace std;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::AdaptiveCards::Rendering::Uwp;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Foundation::Collections;
using namespace ABI::Windows::UI::Xaml;
using namespace ABI::Windows::UI::Xaml::Controls;
using namespace ABI::Windows::UI::Xaml::Shapes;
using namespace ABI::Windows::UI::Xaml::Media;
static const float OutsidePanelY = -1000.0f;
namespace AdaptiveCards::Rendering::Uwp
{
HRESULT WholeItemsPanel::RuntimeClassInitialize()
{
ComPtr<IPanelFactory> spFactory;
ComPtr<IInspectable> spInnerInspectable;
ComPtr<IPanel> spInnerPanel;
RETURN_IF_FAILED(
Windows::Foundation::GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Xaml_Controls_Panel).Get(), &spFactory));
RETURN_IF_FAILED(spFactory->CreateInstance(static_cast<IWholeItemsPanel*>(this),
spInnerInspectable.GetAddressOf(),
spInnerPanel.GetAddressOf()));
RETURN_IF_FAILED(SetComposableBasePointers(spInnerInspectable.Get(), spFactory.Get()));
return S_OK;
}
// IFrameworkElementOverrides
HRESULT WholeItemsPanel::MeasureOverride(Size availableSize, __RPC__out Size* returnValue)
{
unsigned int count{};
float currentHeight{};
float maxDesiredWidth{};
bool visible{true};
ComPtr<IVector<UIElement*>> spChildren;
ComPtr<IPanel> spThisAsPanel;
RETURN_IF_FAILED(QueryInterface(__uuidof(IPanel), reinterpret_cast<void**>(spThisAsPanel.GetAddressOf())));
RETURN_IF_FAILED(spThisAsPanel->get_Children(spChildren.GetAddressOf()));
RETURN_IF_FAILED(spChildren->get_Size(&count));
const Size noVerticalLimit{availableSize.Width, numeric_limits<float>::infinity()};
m_visibleCount = count;
for (unsigned int i{}; i < count; ++i)
{
ComPtr<IUIElement> spChild;
RETURN_IF_FAILED(spChildren->GetAt(i, spChild.GetAddressOf()));
RETURN_IF_FAILED(spChild->Measure(noVerticalLimit));
if (visible)
{
Size childSize;
RETURN_IF_FAILED(spChild->get_DesiredSize(&childSize));
float newHeight = currentHeight + childSize.Height;
if (newHeight > availableSize.Height)
{
const double availableHeightForItem = availableSize.Height - currentHeight;
bool keepItem = m_isMainPanel && (i == 0); // by default, only keep the first item in the main panel.
// Item does not fit
// 1. We mark the current panel as truncated
// 2.1 If the child is a panel: always
// 2.2 If the child is a text block: only if it cannot meet its minlines constraint (default is
// 1) 2.3 If the child is a image or a shape (circular cropped image):
// - stretched images might be resized
ComPtr<IPanel> spChildAsPanel;
if (SUCCEEDED(spChild.As(&spChildAsPanel)))
{
m_isTruncated = true;
// There is a tricky scenario here: a subgroup might have asked for more size than available while
// Still being able to reduce its size, for example if it has a minSize which can be respected
if (keepItem == false)
{
Size remainingSpace = {availableSize.Width, static_cast<float>(availableHeightForItem)};
RETURN_IF_FAILED(spChild->Measure(remainingSpace));
bool isChildTruncated = false;
RETURN_IF_FAILED(IsAnySubgroupTruncated(spChildAsPanel.Get(), &isChildTruncated));
keepItem = !isChildTruncated;
m_isTruncated = !keepItem;
}
}
ComPtr<ITextBlock> spTextBlock;
if (SUCCEEDED(spChild.As(&spTextBlock)))
{
TextWrapping currentWrap = TextWrapping::TextWrapping_Wrap;
RETURN_IF_FAILED(spTextBlock->get_TextWrapping(¤tWrap));
if (currentWrap == TextWrapping::TextWrapping_NoWrap)
{
// If the text already does not wrap, it should not be displayed
// Unless it is the first item of the group
m_isTruncated = true;
}
else
{
// For wrapping TextBlocks, we have to check if the minlines property could be respected
// In order to do this, we remove the wrapping:
// 1. if the textblock has a min lines constraint, this will remain as it is implemented with MinHeight
// 2. if the textblock has no min lines, constraint, this will measure a single line, which is the default minlines
const Size noLimit{numeric_limits<float>::infinity(), numeric_limits<float>::infinity()};
RETURN_IF_FAILED(spTextBlock->put_TextWrapping(TextWrapping::TextWrapping_NoWrap));
RETURN_IF_FAILED(spChild->Measure(noLimit));
RETURN_IF_FAILED(spChild->get_DesiredSize(&childSize));
RETURN_IF_FAILED(spTextBlock->put_TextWrapping(currentWrap));
// If the single line fits, let's keep the textblock
// In any case, we keep the first item of the first group
if (childSize.Height <= availableHeightForItem)
{
keepItem = true;
}
else
{
if (m_isMainPanel)
{
keepItem = true;
// Text did not reach its minHeight property and we have to clear it otherwise
// ellipses won't be displayed correctly...
ComPtr<IFrameworkElementStatics> spFrameworkElementStatics;
ComPtr<IDependencyProperty> spMinHeightProperty;
ComPtr<IDependencyObject> spChildAsDO;
RETURN_IF_FAILED(Windows::Foundation::GetActivationFactory(
HStringReference(RuntimeClass_Windows_UI_Xaml_FrameworkElement).Get(), &spFrameworkElementStatics));
RETURN_IF_FAILED(spFrameworkElementStatics->get_MinHeightProperty(
spMinHeightProperty.GetAddressOf()));
RETURN_IF_FAILED(spChild.As(&spChildAsDO));
RETURN_IF_FAILED(spChildAsDO->ClearValue(spMinHeightProperty.Get()));
}
else
{
keepItem = false;
// we must measure it a last time as we have changed its properties
// if we keep it, it will be measured again with the exact remaining space
RETURN_IF_FAILED(spChild->Measure(noVerticalLimit));
}
}
m_isTruncated = !keepItem;
}
}
ComPtr<IImage> spImage;
if (SUCCEEDED(spChild.As(&spImage)))
{
// it's an inline image
// If the image is stretched, it might be adapted to the available size
ComPtr<IFrameworkElement> spChildFE;
RETURN_IF_FAILED(spChild.As(&spChildFE));
if (!HasExplicitSize(spChildFE.Get()))
{
// Image has no explicit size: we will try to resize it uniformly
RETURN_IF_FAILED(spImage->put_Stretch(ABI::Windows::UI::Xaml::Media::Stretch::Stretch_Uniform));
keepItem = true;
m_isTruncated = false;
}
else
{
// Image has host specified desired size, cannot stretch. It is definitely truncated
m_isTruncated = true;
}
}
ComPtr<IShape> spShape;
if (SUCCEEDED(spChild.As(&spShape)))
{
ComPtr<IFrameworkElement> spChildFE;
RETURN_IF_FAILED(spChild.As(&spChildFE));
if (!HasExplicitSize(spChildFE.Get()))
{
RETURN_IF_FAILED(LayoutCroppedImage(spShape.Get(), availableSize.Width, availableSize.Height - currentHeight));
keepItem = true;
m_isTruncated = false;
}
else
{
m_isTruncated = true;
}
}
if (keepItem)
{
// Let's simply give the child the remaining space
availableSize.Height = availableSize.Height - currentHeight;
RETURN_IF_FAILED(spChild->Measure(availableSize));
RETURN_IF_FAILED(spChild->get_DesiredSize(&childSize));
m_visibleCount = i + 1;
currentHeight = max((currentHeight + childSize.Height), availableSize.Height);
maxDesiredWidth = max(childSize.Width, maxDesiredWidth);
}
else
{
// Only display previous items
m_visibleCount = i;
}
visible = false;
continue;
}
currentHeight = newHeight;
maxDesiredWidth = max(childSize.Width, maxDesiredWidth);
}
}
m_calculatedSize = currentHeight;
if (m_visibleCount == count)
{
m_allElementsRendered = true;
}
else // In the first pass, all the contents will always fit
{
m_allElementsRendered = false;
}
// If inside an infinity/auto width container
if (availableSize.Width == numeric_limits<float>::infinity())
{
// We use the calculated max desired width of children
*returnValue = {maxDesiredWidth, currentHeight};
}
else
{
// Otherwise we match the fixed width of the container
*returnValue = {availableSize.Width, currentHeight};
}
return S_OK;
}
HRESULT WholeItemsPanel::ArrangeOverride(Size finalSize, __RPC__out Size* returnValue)
{
float currentHeight{};
ComPtr<IVector<UIElement*>> children;
ComPtr<IPanel> spThisAsPanel;
RETURN_IF_FAILED(QueryInterface(__uuidof(IPanel), reinterpret_cast<void**>(spThisAsPanel.GetAddressOf())));
RETURN_IF_FAILED(spThisAsPanel->get_Children(children.GetAddressOf()));
RETURN_IF_FAILED(children->get_Size(&m_measuredCount));
float extraPaddingPerItem{};
if (m_stretchableItemCount != 0)
{
extraPaddingPerItem = floor((finalSize.Height - m_calculatedSize) / m_stretchableItemCount);
}
else
{
if (m_verticalContentAlignment == ABI::AdaptiveCards::ObjectModel::Uwp::VerticalContentAlignment::Center)
{
currentHeight = (finalSize.Height - m_calculatedSize) / 2;
}
else if (m_verticalContentAlignment == ABI::AdaptiveCards::ObjectModel::Uwp::VerticalContentAlignment::Bottom)
{
currentHeight = finalSize.Height - m_calculatedSize;
}
}
for (unsigned int i = 0; i < m_measuredCount; ++i)
{
ComPtr<IUIElement> child;
RETURN_IF_FAILED(children->GetAt(i, child.GetAddressOf()));
Size childSize;
RETURN_IF_FAILED(child->get_DesiredSize(&childSize));
if (i < m_visibleCount)
{
float childHeight = childSize.Height;
float newHeight = currentHeight + childSize.Height;
if (m_allElementsRendered && IsUIElementInStretchableList(child.Get()))
{
childHeight += extraPaddingPerItem;
newHeight += extraPaddingPerItem;
}
else if (newHeight > finalSize.Height) // If we have truncated the first item newHeight may be greater than finalSize
{
childHeight = finalSize.Height - currentHeight;
newHeight = finalSize.Height;
}
const Rect rc = {0.0f, currentHeight, finalSize.Width, childHeight}; // childSize.Width does not respect Text alignment
RETURN_IF_FAILED(child->Arrange(rc));
currentHeight = newHeight;
}
else
{
// Arrange the child outside the panel
const Rect rc = {0.0f, OutsidePanelY - childSize.Height, childSize.Width, childSize.Height};
RETURN_IF_FAILED(child->Arrange(rc));
}
}
// Now set the clipping region to ensure that items moved away will never be rendered
// But we allow the items to slightly expand above the panel because we explicitly set negative
// margins for text on the first line of a tile. Additionally, leave at least as much space on all
// sides as specified by s_bleedMargin.
ComPtr<IFrameworkElement> spThisAsIFrameworkElement;
Thickness margin;
RETURN_IF_FAILED(QueryInterface(IID_PPV_ARGS(&spThisAsIFrameworkElement)));
RETURN_IF_FAILED(spThisAsIFrameworkElement->get_Margin(&margin));
Microsoft::WRL::ComPtr<IRectangleGeometry> spClip;
RETURN_IF_FAILED(
Windows::Foundation::ActivateInstance(HStringReference(RuntimeClass_Windows_UI_Xaml_Media_RectangleGeometry).Get(), &spClip));
ComPtr<IUIElement> spThisAsIUIElement;
RETURN_IF_FAILED(QueryInterface(IID_PPV_ARGS(&spThisAsIUIElement)));
RETURN_IF_FAILED(spThisAsIUIElement->put_Clip(spClip.Get()));
const DOUBLE bleedMargin = static_cast<DOUBLE>(s_bleedMargin);
float x0 = static_cast<float>(-max(margin.Left, bleedMargin));
float y0 = static_cast<float>(-max(margin.Top, bleedMargin));
float x1 = static_cast<float>(max(margin.Left, bleedMargin) + finalSize.Width + max(margin.Right, bleedMargin));
float y1 = static_cast<float>(max(margin.Top, bleedMargin) + finalSize.Height + max(margin.Bottom, bleedMargin));
RETURN_IF_FAILED(spClip->put_Rect({x0, y0, x1, y1}));
*returnValue = {finalSize.Width, finalSize.Height};
return S_OK;
}
HRESULT WholeItemsPanel::OnApplyTemplate(void)
{
// Nothing special to do here
return S_OK;
}
// Method used inside the component to reduce the number of temporary allocations
_Check_return_ HRESULT WholeItemsPanel::AppendAltText(_Inout_ std::wstring& buffer)
{
ComPtr<IPanel> spThisAsPanel;
ComPtr<IVector<UIElement*>> spChildren;
RETURN_IF_FAILED(QueryInterface(__uuidof(IPanel), reinterpret_cast<void**>(spThisAsPanel.GetAddressOf())));
RETURN_IF_FAILED(spThisAsPanel->get_Children(spChildren.GetAddressOf()));
unsigned int count = m_visibleCount;
if (m_adaptiveHeight)
{
// If we are rendering stuff in adaptive height mode, we don't
// care which of them are visible or not.
RETURN_IF_FAILED(spChildren->get_Size(&count));
}
for (unsigned int i = 0; i < count; i++)
{
ComPtr<IUIElement> spChild;
RETURN_IF_FAILED(spChildren->GetAt(i, spChild.GetAddressOf()));
RETURN_IF_FAILED(AppendAltTextToUIElement(spChild.Get(), buffer));
}
return S_OK;
}
HRESULT WholeItemsPanel::GetAltText(__RPC__out HSTRING* pResult) noexcept
{
try
{
wstring buffer;
RETURN_IF_FAILED(AppendAltText(buffer));
return WindowsCreateString(buffer.c_str(), static_cast<unsigned int>(buffer.length()), pResult);
}
CATCH_RETURN;
}
HRESULT WholeItemsPanel::IsAllContentClippedOut(__RPC__out boolean* pResult)
{
*pResult = ((m_measuredCount > 0) && (m_visibleCount == 0));
return S_OK;
}
HRESULT WholeItemsPanel::IsTruncated(__RPC__out boolean* pResult)
{
*pResult = m_isTruncated;
return S_OK;
}
void WholeItemsPanel::SetAdaptiveHeight(bool value) { m_adaptiveHeight = value; }
UINT WholeItemsPanel::s_bleedMargin = 0;
void WholeItemsPanel::SetBleedMargin(UINT bleedMargin)
{
// Bleed margin is the extent to which the content may "bleed" out of the panel on the left and right. It is
// used to ensure that the clip rectangle doesn't clip off bleeding content.
s_bleedMargin = bleedMargin;
}
void WholeItemsPanel::SetMainPanel(bool value) { m_isMainPanel = value; }
void WholeItemsPanel::AddElementToStretchablesList(_In_ IUIElement* element)
{
ComPtr<IUIElement> localElement(element);
ComPtr<IFrameworkElement> elementAsFrameworkElement;
THROW_IF_FAILED(localElement.As(&elementAsFrameworkElement));
ComPtr<IInspectable> tagAsInspectable;
THROW_IF_FAILED(elementAsFrameworkElement->get_Tag(&tagAsInspectable));
ComPtr<IElementTagContent> elementTagContent;
if (tagAsInspectable != nullptr)
{
THROW_IF_FAILED(tagAsInspectable.As(&elementTagContent));
THROW_IF_FAILED(elementTagContent->put_IsStretchable(true));
}
else
{
ComPtr<IElementTagContent> tagContent;
THROW_IF_FAILED(MakeAndInitialize<ElementTagContent>(&tagContent));
THROW_IF_FAILED(tagContent->put_IsStretchable(true));
THROW_IF_FAILED(tagContent.As(&tagAsInspectable));
THROW_IF_FAILED(elementAsFrameworkElement->put_Tag(tagAsInspectable.Get()));
}
++m_stretchableItemCount;
}
bool WholeItemsPanel::IsUIElementInStretchableList(_In_ IUIElement* element)
{
ComPtr<IUIElement> localUIElement(element);
ComPtr<IFrameworkElement> uiElementAsFrameworkElement;
THROW_IF_FAILED(localUIElement.As(&uiElementAsFrameworkElement));
ComPtr<IInspectable> tagAsInspectable;
THROW_IF_FAILED(uiElementAsFrameworkElement->get_Tag(&tagAsInspectable));
boolean isStretchable = false;
if (tagAsInspectable != nullptr)
{
ComPtr<AdaptiveCards::Rendering::Uwp::IElementTagContent> tagContent;
THROW_IF_FAILED(tagAsInspectable.As(&tagContent));
THROW_IF_FAILED(tagContent->get_IsStretchable(&isStretchable));
}
return isStretchable;
}
void WholeItemsPanel::SetVerticalContentAlignment(_In_ ABI::AdaptiveCards::ObjectModel::Uwp::VerticalContentAlignment verticalContentAlignment)
{
m_verticalContentAlignment = verticalContentAlignment;
}
_Check_return_ HRESULT WholeItemsPanel::IsAnySubgroupTruncated(_In_ ABI::Windows::UI::Xaml::Controls::IPanel* pPanel,
_Out_ bool* childTruncated)
{
*childTruncated = false;
ComPtr<IVector<UIElement*>> spChildren;
unsigned int size = 0;
RETURN_IF_FAILED(pPanel->get_Children(spChildren.GetAddressOf()));
RETURN_IF_FAILED(spChildren->get_Size(&size));
for (unsigned int i = 0; i < size; ++i)
{
ComPtr<IUIElement> spChild;
ComPtr<IWholeItemsPanel> spWholeItemPanel;
boolean isChildTruncated = false;
RETURN_IF_FAILED(spChildren->GetAt(i, spChild.GetAddressOf()));
// Subgroups (columns) are implemented with WholeItemsPanel
if (SUCCEEDED(spChild.As(&spWholeItemPanel)))
{
RETURN_IF_FAILED(spWholeItemPanel->IsTruncated(&isChildTruncated));
if (isChildTruncated)
{
// No need to continue the iteration
*childTruncated = true;
return S_OK;
}
}
}
return S_OK;
}
// As shapes (used for circular cropping) don't resize as a stretched image, we need do to more
// things manually. Here, we'll resize the shape to fit the smallest dimension
// (ideally, we should inherit from Ellipse but it is not possible)
_Check_return_ HRESULT WholeItemsPanel::LayoutCroppedImage(_In_ IShape* pShape, _In_ double availableWidth, _In_ double availableHeight)
{
ComPtr<IFrameworkElement> spFrameworkElement;
ABI::Windows::UI::Xaml::VerticalAlignment valign;
ABI::Windows::UI::Xaml::HorizontalAlignment halign;
Thickness margins;
RETURN_IF_FAILED(pShape->QueryInterface(spFrameworkElement.GetAddressOf()));
RETURN_IF_FAILED(spFrameworkElement->get_HorizontalAlignment(&halign));
RETURN_IF_FAILED(spFrameworkElement->get_VerticalAlignment(&valign));
RETURN_IF_FAILED(spFrameworkElement->get_Margin(&margins));
const double effectiveAvailableWidth = availableWidth - margins.Left - margins.Right;
const double effectiveAvailableHeight = availableHeight - margins.Top - margins.Bottom;
const double minSize = min(effectiveAvailableWidth, effectiveAvailableHeight);
RETURN_IF_FAILED(spFrameworkElement->put_Width(minSize));
RETURN_IF_FAILED(spFrameworkElement->put_Height(minSize));
return S_OK;
}
void WholeItemsPanel::AppendText(_In_ HSTRING hText, _Inout_ std::wstring& buffer)
{
if (buffer.length() > 0)
{
buffer.push_back(L'\n');
}
buffer.append(WindowsGetStringRawBuffer(hText, nullptr));
}
_Check_return_ HRESULT WholeItemsPanel::GetAltAsString(_In_ IUIElement* pElement, _Out_ HSTRING* pResult)
{
*pResult = nullptr;
ComPtr<IDependencyObject> spDependencyObject;
if (SUCCEEDED(pElement->QueryInterface(spDependencyObject.GetAddressOf())))
{
ComPtr<Automation::IAutomationPropertiesStatics> automationStatics;
RETURN_IF_FAILED(
::GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Xaml_Automation_AutomationProperties).Get(),
&automationStatics));
RETURN_IF_FAILED(automationStatics->GetName(spDependencyObject.Get(), pResult));
}
return S_OK;
}
// Creates the Alt Text
_Check_return_ HRESULT WholeItemsPanel::AppendAltTextToUIElement(_In_ IUIElement* pUIElement, _Inout_ std::wstring& buffer)
{
ComPtr<ITextBlock> spTextBlock;
if (SUCCEEDED(pUIElement->QueryInterface(spTextBlock.GetAddressOf())))
{
HString hText;
RETURN_IF_FAILED(spTextBlock->get_Text(hText.GetAddressOf()));
AppendText(hText.Get(), buffer);
return S_OK;
}
ComPtr<IWholeItemsPanel> spWholeItemsPanel;
if (SUCCEEDED(pUIElement->QueryInterface(spWholeItemsPanel.GetAddressOf())))
{
// This cast is safe because WinRT only does aggregation
WholeItemsPanel* pPanelNoRef = reinterpret_cast<WholeItemsPanel*>(spWholeItemsPanel.Get());
RETURN_IF_FAILED(pPanelNoRef->AppendAltText(buffer));
return S_OK;
}
ComPtr<IImage> spImage;
if (SUCCEEDED(pUIElement->QueryInterface(spImage.GetAddressOf())))
{
HString hAltText;
RETURN_IF_FAILED(GetAltAsString(pUIElement, hAltText.GetAddressOf()));
if (*hAltText.GetRawBuffer(nullptr))
{
AppendText(hAltText.Get(), buffer);
}
return S_OK;
}
ComPtr<IShape> spShape;
if (SUCCEEDED(pUIElement->QueryInterface(spShape.GetAddressOf())))
{
HString hAltText;
RETURN_IF_FAILED(GetAltAsString(pUIElement, hAltText.GetAddressOf()));
if (*hAltText.GetRawBuffer(nullptr))
{
AppendText(hAltText.Get(), buffer);
}
return S_OK;
}
ComPtr<IPanel> spPanel;
if (SUCCEEDED(pUIElement->QueryInterface(spPanel.GetAddressOf())))
{
ComPtr<IVector<UIElement*>> spChildren;
RETURN_IF_FAILED(spPanel->get_Children(spChildren.GetAddressOf()));
unsigned int count;
RETURN_IF_FAILED(spChildren->get_Size(&count));
for (unsigned int i = 0; i < count; i++)
{
ComPtr<IUIElement> spChild;
RETURN_IF_FAILED(spChildren->GetAt(i, spChild.GetAddressOf()));
RETURN_IF_FAILED(AppendAltTextToUIElement(spChild.Get(), buffer));
}
return S_OK;
}
ComPtr<IBorder> spBorder;
if (SUCCEEDED(pUIElement->QueryInterface(spBorder.GetAddressOf())))
{
ComPtr<IUIElement> spChild;
RETURN_IF_FAILED(spBorder->get_Child(spChild.GetAddressOf()));
RETURN_IF_FAILED(AppendAltTextToUIElement(spChild.Get(), buffer));
return S_OK;
}
return S_OK;
}
bool WholeItemsPanel::HasExplicitSize(_In_ IFrameworkElement* element)
{
DOUBLE definedImageHeight;
element->get_Height(&definedImageHeight);
DOUBLE definedImageWidth;
element->get_Height(&definedImageWidth);
return !isnan(definedImageHeight) || !isnan(definedImageWidth);
}
}