Skip to content

Commit

Permalink
feat(calendar): Make some items visible!
Browse files Browse the repository at this point in the history
* Basic implementation of ModernCollectionBasePanel (calendar only)
  • Loading branch information
dr1rrb committed Jun 1, 2021
1 parent 392e356 commit 53cca3f
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal partial class CalendarLayoutStrategy : ILayoutStrategy
// std.function<HRESULT( int itemIndex, out bool pHasSnapPoint)> func);

//private:
private CalendarLayoutStrategyImpl _layoutStrategyImpl;
private CalendarLayoutStrategyImpl _layoutStrategyImpl = new CalendarLayoutStrategyImpl();

private ILayoutDataInfoProvider _spDataInfoProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void ShouldContinueFillingUpSpaceImpl(
out bool pReturnValue) /*override*/
{
pReturnValue = default;
pReturnValue = !!_layoutStrategyImpl.ShouldContinueFillingUpSpace(
pReturnValue = _layoutStrategyImpl.ShouldContinueFillingUpSpace(
elementType,
elementIndex,
referenceInformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using Windows.Foundation;
using DateTime = System.DateTimeOffset;

#pragma once
Expand All @@ -26,6 +27,8 @@ internal CalendarViewBaseItem() // Make sure the ctor is not publically visible
#endif
}



//protected:

//// this base panel implementation is hidden from IDL
Expand Down Expand Up @@ -114,7 +117,7 @@ internal CalendarViewBaseItem() // Make sure the ctor is not publically visible
//private void GetMainText(out HSTRING pMainText);

// CalendarViewItem and CalendarViewDayItem will override this method.
internal virtual DateTime Date
internal virtual DateTime DateBase
{
get => throw new NotImplementedException();
set => throw new NotImplementedException(); // For debug purpose only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void ScrollIntoViewImpl()
spOwner = Owner;

DateTime date;
date = (spOwner as CalendarViewItem).Date;
date = (spOwner as CalendarViewItem).DateBase;

CalendarView pParent = (spOwner as CalendarViewBaseItem).GetParentCalendarView();

Expand All @@ -108,7 +108,7 @@ private bool IsItemVisible()
if (calendarPanel is {})
{
DateTime date = default;
date = (owner as CalendarViewBaseItem).Date;
date = (owner as CalendarViewBaseItem).DateBase;

int itemIndex = 0;
itemIndex = host.CalculateOffsetFromMinDate(date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private UIElement GetFirstChild()
{
UIElement spFirstChild;
// added in UIElement.GetFirstChild()
spFirstChild = GetFirstChild();
spFirstChild = _children.First();

// We overrode HasTemplateChild and AddTemplateChild to make sure
// the template child (if exists) will be always at index 0.
Expand Down Expand Up @@ -306,6 +306,12 @@ protected override Size ArrangeOverride(
return newFinalSize;
}

/// <inheritdoc />
internal override void OnArrangeVisual(Rect rect, Rect? clip)
{
base.OnArrangeVisual(rect, clip);
}

private void CreateTextBlock(
ref TextBlock spTextBlock)
{
Expand Down Expand Up @@ -340,7 +346,9 @@ private void EnsureTextBlock(ref TextBlock spTextBlock)
//DoPointerCast(pChildrenCollectionNoRef, value);

CreateTextBlock(ref spTextBlock);
pChildrenCollectionNoRef.Append((spTextBlock));
AddChild(spTextBlock);
// TODO UNO
//pChildrenCollectionNoRef.Append((spTextBlock));

UpdateTextBlockForeground(spTextBlock);
UpdateTextBlockForegroundOpacity(spTextBlock);
Expand Down Expand Up @@ -649,7 +657,7 @@ Rect bounds

private void SetOwner(CalendarView pOwner)
{
global::System.Diagnostics.Debug.Assert(!m_wrOwner.TryGetTarget(out _));
global::System.Diagnostics.Debug.Assert(!(m_wrOwner?.TryGetTarget(out _) ?? false));
m_wrOwner = new Uno.WeakReference<CalendarView>(pOwner);
}

Expand Down Expand Up @@ -857,7 +865,7 @@ private void UpdateTextBlockForeground(TextBlock pTextBlock)

private void UpdateTextBlockForegroundOpacity(TextBlock pTextBlock)
{
float opacity = GetTextBlockForegroundOpacity();
double opacity = GetTextBlockForegroundOpacity();

global::System.Diagnostics.Debug.Assert(pTextBlock is { });

Expand All @@ -882,15 +890,15 @@ internal void UpdateTextBlockFontProperties(TextBlock pTextBlock)
{
object value;

pTextBlock.SetValue(TextBlock.FontSizeProperty, properties.fontSize);
pTextBlock.SetValue(TextBlock.FontSizeProperty, (double)properties.fontSize);

value = properties.fontStyle;
pTextBlock.SetValue(TextBlock.FontStyleProperty, value);
pTextBlock.SetValue(TextBlock.FontStyleProperty, (FontStyle)value);

value = properties.fontWeight;
pTextBlock.SetValue(TextBlock.FontWeightProperty, value);
pTextBlock.SetValue(TextBlock.FontWeightProperty, (FontWeight)value);

pTextBlock.SetValue(TextBlock.FontFamilyProperty, properties.pFontFamilyNoRef);
pTextBlock.SetValue(TextBlock.FontFamilyProperty, (FontFamily)properties.pFontFamilyNoRef);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public bool IsBlackout
}
}

internal override global::System.DateTimeOffset DateBase
{
get => Date;
set => Date = value;
}
public global::System.DateTimeOffset Date
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal override void PrepareItemContainer(

date = (DateTime)pItem;
spContainer = (CalendarViewItem)(pContainer);
spContainer.Date = date;
spContainer.DateBase = date;
GetCalendar().SetDateTime(date);

// main text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal virtual void PrepareItemContainer(
object pItem)
{
// All calendar items have same scope logical, handle it here:
CalendarViewItem spContainer = ((CalendarViewItem)(pContainer));
CalendarViewBaseItem spContainer = ((CalendarViewBaseItem)(pContainer));

spContainer.SetIsOutOfScope(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal override void UpdateLabel(CalendarViewBaseItem pItem, bool isLabelVisib

// TODO: consider caching the firstday flag because we also need this information when determining snap points
// (however Decadeview doesn't need this for Label).
date = pItem.Date;
date = pItem.DateBase;
pCalendar.SetDateTime(date);
firstDayInThisMonth = pCalendar.FirstDayInThisMonth;
day = pCalendar.Day;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal override void PrepareItemContainer(

date = (DateTime) pItem;
GetCalendar().SetDateTime(date);
spContainer.Date = date;
spContainer.DateBase = date;

// maintext
{
Expand Down Expand Up @@ -100,7 +100,7 @@ internal override void UpdateLabel(CalendarViewBaseItem pItem, bool isLabelVisib

// TODO: consider caching the firstday flag because we also need this information when determining snap points
// (however Decadeview doesn't need this for Label).
date = pItem.Date;
date = pItem.DateBase;
pCalendar.SetDateTime(date);
firstMonthOfThisYear = pCalendar.FirstMonthInThisYear;
month = pCalendar.Month;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private int ColumnImpl()
spOwner = Owner;

DateTime date;
date = (spOwner as CalendarViewItem).Date;
date = (spOwner as CalendarViewItem).DateBase;

CalendarView pParent = (spOwner as CalendarViewItem).GetParentCalendarView();

Expand Down Expand Up @@ -95,7 +95,7 @@ private int RowImpl()
spOwner = Owner;

DateTime date;
date = (spOwner as CalendarViewItem).Date;
date = (spOwner as CalendarViewItem).DateBase;

CalendarView pParent = (spOwner as CalendarViewItem).GetParentCalendarView();

Expand Down Expand Up @@ -141,7 +141,7 @@ private void GetRowHeaderItemsImpl(out uint pReturnValueCount, out IRawElementPr
CalendarView pParent = item.GetParentCalendarView();

DateTime itemDate;
itemDate = item.Date;
itemDate = item.DateBase;

// Currently we only want this row header read in year mode, not in decade mode.
pParent.GetRowHeaderForItemAutomationPeer(itemDate, CalendarViewDisplayMode.Year, out pReturnValueCount, out ppReturnValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Windows.Foundation.Collections;
using Windows.Globalization;
using Windows.Globalization.DateTimeFormatting;
using Windows.UI.Text;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Automation.Provider;
Expand Down Expand Up @@ -93,16 +94,16 @@ public partial class CalendarView : Control
int m_monthViewStartIndex;

// dayOfWeekNames stores abbreviated names of each day of the week. dayOfWeekNamesFull stores the full name to be read aloud by accessibility.
List<string> m_dayOfWeekNames;
List<string> m_dayOfWeekNamesFull;
List<string> m_dayOfWeekNames = new List<string>();
List<string> m_dayOfWeekNamesFull = new List<string>();

IEnumerable<string> m_tpCalendarLanguages;

VectorChangedEventHandler<DateTime> m_epSelectedDatesChangedHandler;


// the keydown event args from CalendarItem.
WeakReference<KeyRoutedEventArgs> m_wrKeyDownEventArgsFromCalendarItem;
WeakReference<KeyRoutedEventArgs> m_wrKeyDownEventArgsFromCalendarItem = new WeakReference<KeyRoutedEventArgs>(default);

// the focus state we need to set on the calendaritem after we change the display mode.
FocusState m_focusStateAfterDisplayModeChanged;
Expand Down Expand Up @@ -147,6 +148,52 @@ public partial class CalendarView : Control

public CalendarView()
{
// Ctor from core\elements\CalendarView.cpp
m_pFocusBorderBrush = null;
m_pSelectedHoverBorderBrush = null;
m_pSelectedPressedBorderBrush = null;
m_pSelectedBorderBrush = null;
m_pHoverBorderBrush = null;
m_pPressedBorderBrush = null;
m_pCalendarItemBorderBrush = null;
m_pOutOfScopeBackground = null;
m_pCalendarItemBackground = null;
m_pPressedForeground = null;
m_pTodayForeground = null;
m_pBlackoutForeground = null;
m_pSelectedForeground = null;
m_pOutOfScopeForeground = null;
m_pCalendarItemForeground = null;
m_pDayItemFontFamily = /*null;*/ "XamlAutoFontFamily";
m_pDisabledForeground = null;
m_pTodaySelectedInnerBorderBrush = null;
m_pTodayHoverBorderBrush = null;
m_pTodayPressedBorderBrush = null;
m_pTodayBackground = null;
m_pTodayBlackoutBackground = null;
m_dayItemFontSize = 20.0f;
m_dayItemFontStyle = FontStyle.Normal;
m_dayItemFontWeight = FontWeights.Normal;
m_todayFontWeight = FontWeights.SemiBold;
m_pFirstOfMonthLabelFontFamily = /*null;*/ "XamlAutoFontFamily";
m_firstOfMonthLabelFontSize = 12.0f;
m_firstOfMonthLabelFontStyle = FontStyle.Normal;
m_firstOfMonthLabelFontWeight = FontWeights.Normal;
m_pMonthYearItemFontFamily = /*null;*/ "XamlAutoFontFamily";
m_monthYearItemFontSize = 20.0f;
m_monthYearItemFontStyle = FontStyle.Normal;
m_monthYearItemFontWeight = FontWeights.Normal;
m_pFirstOfYearDecadeLabelFontFamily = /*null;*/ "XamlAutoFontFamily";
m_firstOfYearDecadeLabelFontSize = 12.0f;
m_firstOfYearDecadeLabelFontStyle = FontStyle.Normal;
m_firstOfYearDecadeLabelFontWeight = FontWeights.Normal;
m_horizontalDayItemAlignment = HorizontalAlignment.Center;
m_verticalDayItemAlignment = VerticalAlignment.Center;
m_horizontalFirstOfMonthLabelAlignment = HorizontalAlignment.Center;
m_verticalFirstOfMonthLabelAlignment = VerticalAlignment.Top;
m_calendarItemBorderThickness = default;

// Ctor from lib\CalendarView_Partial.cpp
m_dateSourceChanged = true;
m_calendarChanged = false;
m_itemHostsConnected = false;
Expand Down Expand Up @@ -375,11 +422,11 @@ internal override void OnPropertyChanged2(
break;
case DependencyProperty CalendarView_DisplayModeProperty when CalendarView_DisplayModeProperty == CalendarView.DisplayModeProperty:
{
uint oldDisplayMode = 0;
uint newDisplayMode = 0;
CalendarViewDisplayMode oldDisplayMode = 0;
CalendarViewDisplayMode newDisplayMode = 0;

oldDisplayMode = (uint)args.OldValue;
newDisplayMode = (uint)args.NewValue;
oldDisplayMode = (CalendarViewDisplayMode)args.OldValue;
newDisplayMode = (CalendarViewDisplayMode)args.NewValue;

OnDisplayModeChanged(
(CalendarViewDisplayMode)(oldDisplayMode),
Expand Down Expand Up @@ -1442,7 +1489,7 @@ private void OnNavigationButtonClicked( bool forward)
try
{
spChild = ((CalendarViewBaseItem)spChildAsI);
dateOfFirstVisibleItem = spChild.Date;
dateOfFirstVisibleItem = spChild.DateBase;
if (canPanelShowFullScope)
{
// if Panel can show a full scope, we navigate by a scope.
Expand Down Expand Up @@ -1757,13 +1804,13 @@ internal void OnVisibleIndicesUpdated(

spTempChildAsI = (CalendarViewBaseItem)spTempChildAsIDO;

firstDate = ((CalendarViewBaseItem)spTempChildAsI).Date;
firstDate = ((CalendarViewBaseItem)spTempChildAsI).DateBase;

spTempChildAsIDO = pCalendarPanel.ContainerFromIndex(lastVisibleIndex);

spTempChildAsI = (CalendarViewBaseItem)spTempChildAsIDO;

lastDate = ((CalendarViewBaseItem)spTempChildAsI).Date;
lastDate = ((CalendarViewBaseItem)spTempChildAsI).DateBase;

//now determine the current scope based on this date.
pHost.UpdateScope(firstDate, lastDate, out isScopeChanged);
Expand Down Expand Up @@ -1849,7 +1896,7 @@ internal void UpdateItemsScopeState(
spChildAsI = (CalendarViewBaseItem) spChildAsIDO;

spChild = ((CalendarViewBaseItem)spChildAsI);
date = spChild.Date;
date = spChild.DateBase;

bool isOutOfScope = m_dateComparer.LessThan(date, pHost.GetMinDateOfCurrentScope()) || m_dateComparer.LessThan(pHost.GetMaxDateOfCurrentScope(), date);

Expand Down Expand Up @@ -2097,11 +2144,11 @@ private void UpdateLastDisplayedDate( CalendarViewDisplayMode lastDisplayMode)

spChildAsIDO = pPreviousPanel.ContainerFromIndex(firstVisibleIndex);
spChildAsI = spChildAsIDO as CalendarViewBaseItem;
firstVisibleDate = ((CalendarViewBaseItem)spChildAsI).Date;
firstVisibleDate = ((CalendarViewBaseItem)spChildAsI).DateBase;

spChildAsIDO = pPreviousPanel.ContainerFromIndex(lastVisibleIndex);
spChildAsI = spChildAsIDO as CalendarViewBaseItem;
lastVisibleDate = ((CalendarViewBaseItem)spChildAsI).Date;
lastVisibleDate = ((CalendarViewBaseItem)spChildAsI).DateBase;

// check if last displayed Date is visible or not
bool isLastDisplayedDateVisible = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ internal void OnItemFocused(CalendarViewBaseItem pItem)
DateTime date;
CalendarViewDisplayMode mode = CalendarViewDisplayMode.Month;

date = pItem.Date;
date = pItem.DateBase;

mode = DisplayMode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ internal void OnSelectMonthYearItem(
CalendarViewDisplayMode displayMode = CalendarViewDisplayMode.Month;

displayMode = DisplayMode;
date = pItem.Date;
date = pItem.DateBase;

// after display mode changed, we'll focus a new item, we want that item to be focused by the specified state.
m_focusItemAfterDisplayModeChanged = true;
Expand Down
Loading

0 comments on commit 53cca3f

Please sign in to comment.