Skip to content

Commit

Permalink
Merge fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Nice3point committed Dec 2, 2023
1 parent ecf6435 commit 2124a64
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 86 deletions.
18 changes: 3 additions & 15 deletions RevitLookup.UI/Controls/Badge/Badge.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@
xmlns:controls="clr-namespace:Wpf.Ui.Controls">

<Style TargetType="{x:Type controls:Badge}">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource SystemAccentColorSecondary}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource BadgeForeground}"/>
<Setter Property="Background" Value="{DynamicResource BadgeBackground}"/>
<!--<Setter Property="BorderBrush" Value="{DynamicResource SystemAccentBrush}" />-->
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Padding" Value="4" />
Expand All @@ -41,11 +33,7 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Appearance" Value="Primary">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextOnAccentFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource BadgeForeground}"/>
</Trigger>
<Trigger Property="Appearance" Value="Transparent">
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
Expand Down
7 changes: 2 additions & 5 deletions RevitLookup.UI/Controls/CardColor/CardColor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@
<TextBlock
Margin="0"
FontSize="{TemplateBinding SubtitleFontSize}"
Text="{TemplateBinding Subtitle}">
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource CardForegroundPressed}" />
</TextBlock.Foreground>
</TextBlock>
Foreground="{DynamicResource CardForegroundPressed}"
Text="{TemplateBinding Subtitle}" />
</StackPanel>
</Border>
</ControlTemplate>
Expand Down
7 changes: 1 addition & 6 deletions RevitLookup.UI/Controls/ComboBox/ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Wpf.Ui.Controls"
xmlns:converters="clr-namespace:Wpf.Ui.Converters"
xmlns:system="clr-namespace:System;assembly=System.Runtime">

<Thickness x:Key="ComboBoxPadding">10,8,10,8</Thickness>
Expand Down Expand Up @@ -138,11 +137,7 @@
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource ComboBoxItemForegroundSelected}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource ComboBoxItemForeground}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForegroundDisabled}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
1 change: 1 addition & 0 deletions RevitLookup.UI/Controls/Expander/Expander.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Grid.Column="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextElement.FontSize="{TemplateBinding FontSize}"
Content="{TemplateBinding Content}" />
<Grid
x:Name="ChevronGrid"
Expand Down
18 changes: 18 additions & 0 deletions RevitLookup.UI/Controls/NavigationView/NavigationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,34 @@ internal class NavigationCache

if (cacheMode == NavigationCacheMode.Disabled)
{
#if DEBUG
System
.Diagnostics
.Debug
.WriteLine($"Cache for {entryType} is disabled. Generating instance using action...");
#endif

return generate.Invoke();
}

if (!_entires.TryGetValue(entryType, out var value))
{
#if DEBUG
System
.Diagnostics
.Debug
.WriteLine($"{entryType} not found in cache, generating instance using action...");
#endif

value = generate.Invoke();

_entires.Add(entryType, value);
}

#if DEBUG
System.Diagnostics.Debug.WriteLine($"{entryType} found in cache.");
#endif

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public enum NavigationCacheMode
/// <summary>
/// The page is cached and the cached instance is reused for every visit regardless of the cache size for the frame.
/// </summary>
Reguired
Required
}
69 changes: 50 additions & 19 deletions RevitLookup.UI/Controls/NavigationView/NavigationView.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@ private void AddToJournal(INavigationViewItem viewItem, bool isBackwardsNavigate

#if DEBUG
Debug.WriteLineIf(EnableDebugMessages, $"JOURNAL INDEX {_currentIndexInJournal}");

if (Journal.Count > 0)
{
Debug.WriteLineIf(EnableDebugMessages, $"JOURNAL LAST ELEMENT {Journal[^1]}");
}
#endif
}

Expand All @@ -264,26 +267,54 @@ private object GetNavigationItemInstance(INavigationViewItem viewItem)
?? throw new ArgumentNullException($"{nameof(_pageService.GetPage)} returned null");
}

return NavigationViewActivator.CreateInstance(viewItem.TargetPageType)
?? throw new ArgumentException("Failed to create instance of the page");
return _cache.Remember(
viewItem.TargetPageType,
viewItem.NavigationCacheMode,
ComputeCachedNavigationInstance
)
?? throw new ArgumentNullException(
$"Unable to get or create instance of {viewItem.TargetPageType} from cache."
);

//return _cache.Remember(viewItem.TargetPageType, viewItem.NavigationCacheMode, () =>
//{
// if (_serviceProvider is not null)
// {
// return _serviceProvider.GetService(viewItem.TargetPageType) ??
// new ArgumentNullException($"{nameof(_serviceProvider.GetService)} returned null");
// }

// if (_pageService is not null)
// {
// return _pageService.GetPage(viewItem.TargetPageType) ??
// throw new ArgumentNullException($"{nameof(_pageService.GetPage)} returned null");
// }

// return NavigationViewActivator.CreateInstance(viewItem.TargetPageType) ??
// throw new ArgumentException("Failed to create instance of the page");
//});
object? ComputeCachedNavigationInstance() => GetPageInstanceFromCache(viewItem.TargetPageType);
}

private object? GetPageInstanceFromCache(Type? targetPageType)
{
if (targetPageType is null)
{
return default;
}

if (_serviceProvider is not null)
{
#if DEBUG
System
.Diagnostics
.Debug
.WriteLine($"Getting {targetPageType} from cache using IServiceProvider.");
#endif

return _serviceProvider.GetService(targetPageType)
?? new ArgumentNullException($"{nameof(_serviceProvider.GetService)} returned null");
}

if (_pageService is not null)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine($"Getting {targetPageType} from cache using IPageService.");
#endif

return _pageService.GetPage(targetPageType)
?? throw new ArgumentNullException($"{nameof(_pageService.GetPage)} returned null");
}

#if DEBUG
System.Diagnostics.Debug.WriteLine($"Getting {targetPageType} from cache using reflection.");
#endif

return NavigationViewActivator.CreateInstance(targetPageType)
?? throw new ArgumentException("Failed to create instance of the page");
}

private static void ApplyAttachedProperties(INavigationViewItem viewItem, object pageInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,11 @@
BorderBrush="{DynamicResource FlyoutBackground}"
BorderThickness="1"
CornerRadius="8"
Background="{DynamicResource FlyoutBorderBrush}"
SnapsToDevicePixels="True">
<Border.RenderTransform>
<TranslateTransform />
</Border.RenderTransform>
<Border.Background>
<SolidColorBrush Color="{DynamicResource FlyoutBorderBrush}" />
</Border.Background>

<Border.Effect>
<DropShadowEffect
Expand Down
1 change: 1 addition & 0 deletions RevitLookup.UI/Controls/TextBox/TextBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
Margin="0"
Padding="1,0"
VerticalAlignment="Top"
FontSize="{TemplateBinding FontSize}"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
Text="{TemplateBinding PlaceholderText}" />
</Grid>
Expand Down
1 change: 1 addition & 0 deletions RevitLookup.UI/Controls/TitleBar/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<!-- Main application title -->
<TextBlock
Grid.Column="1"
FontSize="12"
VerticalAlignment="Center"
Text="{TemplateBinding Title}" />
</Grid>
Expand Down
3 changes: 2 additions & 1 deletion RevitLookup.UI/Controls/ToggleButton/ToggleButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
TextElement.Foreground="{TemplateBinding Foreground}" />
TextElement.Foreground="{TemplateBinding Foreground}"
TextElement.FontSize="{TemplateBinding FontSize}"/>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
Expand Down
39 changes: 24 additions & 15 deletions RevitLookup.UI/Interop/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static bool ApplyWindowCornerPreference(IntPtr handle, WindowCornerPrefer
if (!User32.IsWindow(handle))
return false;

int pvAttribute = (int)UnsafeReflection.Cast(cornerPreference);
int pvAttribute = (int) UnsafeReflection.Cast(cornerPreference);

// TODO: Validate HRESULT
Dwmapi.DwmSetWindowAttribute(
Expand Down Expand Up @@ -157,12 +157,11 @@ public static bool RemoveWindowTitlebarContents(IntPtr handle)
return false;

var windowStyleLong = User32.GetWindowLong(handle, User32.GWL.GWL_STYLE);
windowStyleLong &= ~(int)User32.WS.SYSMENU;
windowStyleLong &= ~(int) User32.WS.SYSMENU;

IntPtr result = User32.SetWindowLong32And64(handle, User32.GWL.GWL_STYLE, windowStyleLong);
long resultValue = result.ToInt64();
var result = SetWindowLong(handle, User32.GWL.GWL_STYLE, windowStyleLong);

return resultValue > 0x0;
return result.ToInt64() > 0x0;
}

/// <summary>
Expand All @@ -179,9 +178,9 @@ public static bool ApplyWindowBackdrop(IntPtr handle, WindowBackdropType backgro
if (!User32.IsWindow(handle))
return false;

var backdropPvAttribute = (int)UnsafeReflection.Cast(backgroundType);
var backdropPvAttribute = (int) UnsafeReflection.Cast(backgroundType);

if (backdropPvAttribute == (int)Dwmapi.DWMSBT.DWMSBT_DISABLE)
if (backdropPvAttribute == (int) Dwmapi.DWMSBT.DWMSBT_DISABLE)
return false;

// TODO: Validate HRESULT
Expand Down Expand Up @@ -214,7 +213,7 @@ public static bool IsWindowHasBackdrop(IntPtr handle, WindowBackdropType backdro
Marshal.SizeOf(typeof(int))
);

return pvAttribute == (int)UnsafeReflection.Cast(backdropType);
return pvAttribute == (int) UnsafeReflection.Cast(backdropType);
}

/// <summary>
Expand Down Expand Up @@ -410,7 +409,7 @@ public static bool RemoveWindowCaption(IntPtr hWnd)
hWnd,
UxTheme.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT,
ref wtaOptions,
(uint)Marshal.SizeOf(typeof(UxTheme.WTA_OPTIONS))
(uint) Marshal.SizeOf(typeof(UxTheme.WTA_OPTIONS))
);

return true;
Expand Down Expand Up @@ -452,7 +451,7 @@ public static bool ExtendClientAreaIntoTitleBar(IntPtr hWnd)
hWnd,
UxTheme.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT,
ref wtaOptions,
(uint)Marshal.SizeOf(typeof(UxTheme.WTA_OPTIONS))
(uint) Marshal.SizeOf(typeof(UxTheme.WTA_OPTIONS))
);

var windowDpi = DpiHelper.GetWindowDpi(hWnd);
Expand All @@ -467,10 +466,10 @@ public static bool ExtendClientAreaIntoTitleBar(IntPtr hWnd)
var dwmMargin = new UxTheme.MARGINS
{
// err on the side of pushing in glass an extra pixel.
cxLeftWidth = (int)Math.Ceiling(deviceGlassThickness.Left),
cxRightWidth = (int)Math.Ceiling(deviceGlassThickness.Right),
cyTopHeight = (int)Math.Ceiling(deviceGlassThickness.Top),
cyBottomHeight = (int)Math.Ceiling(deviceGlassThickness.Bottom),
cxLeftWidth = (int) Math.Ceiling(deviceGlassThickness.Left),
cxRightWidth = (int) Math.Ceiling(deviceGlassThickness.Right),
cyTopHeight = (int) Math.Ceiling(deviceGlassThickness.Top),
cyBottomHeight = (int) Math.Ceiling(deviceGlassThickness.Bottom),
};

// #3 Extend client area
Expand Down Expand Up @@ -520,4 +519,14 @@ private static bool GetHandle(Window? window, out IntPtr windowHandle)

return windowHandle != IntPtr.Zero;
}
}

private static IntPtr SetWindowLong(IntPtr handle, User32.GWL nIndex, long windowStyleLong)
{
if (IntPtr.Size == 4)
{
return new IntPtr(User32.SetWindowLong(handle, (int) nIndex, (int) windowStyleLong));
}

return User32.SetWindowLongPtr(handle, (int) nIndex, (IntPtr) windowStyleLong);
}
}
15 changes: 4 additions & 11 deletions RevitLookup.UI/Interop/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,18 +1308,11 @@ [In] IntPtr lParam
[DllImport(Libraries.User32, CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr([In] IntPtr hWnd, [In] int nIndex, [In] IntPtr dwNewLong);

[DllImport(Libraries.User32, SetLastError = true)]
/// <summary>
/// Changes an attribute of the specified window.
/// </summary>
[DllImport(Libraries.User32, CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

public static IntPtr SetWindowLong32And64(IntPtr handle, GWL nIndex, long windowStyleLong)
{
if (IntPtr.Size == 4)
{
return new IntPtr(SetWindowLong(handle, (int)nIndex, (int)windowStyleLong));
}

return SetWindowLongPtr(handle, (int)nIndex, (IntPtr)windowStyleLong);
}

/// <summary>
/// Destroys an icon and frees any memory the icon occupied.
Expand Down
8 changes: 5 additions & 3 deletions RevitLookup.UI/Resources/Theme/Dark.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@
<!-- Control brushes -->

<!-- Badge -->
<!-- TODO -->

<SolidColorBrush x:Key="BadgeForeground" Color="{StaticResource TextOnAccentFillColorPrimary}"/>
<SolidColorBrush x:Key="BadgeBackground" Color="{DynamicResource SystemAccentColorPrimary}"/>

<!-- BreadcrumbBar -->
<SolidColorBrush x:Key="BreadcrumbBarNormalForegroundBrush" Color="{StaticResource TextFillColorPrimary}" />
Expand Down Expand Up @@ -519,8 +521,8 @@
<SolidColorBrush x:Key="NavigationViewContentGridBorderBrush" Color="{StaticResource CardStrokeColorDefault}" />

<SolidColorBrush x:Key="NavigationViewItemBackgroundSelectedLeftFluent" Color="{StaticResource ControlFillColorDefault}" />
<SolidColorBrush x:Key="NavigationViewItemForegroundLeftFluent" Color="{StaticResource TextFillColorSecondary}" />
<SolidColorBrush x:Key="NavigationViewItemForegroundPointerOverLeftFluent" Color="{StaticResource TextFillColorSecondary}" />
<SolidColorBrush x:Key="NavigationViewItemForegroundLeftFluent" Color="{StaticResource TextFillColorPrimary}" />
<SolidColorBrush x:Key="NavigationViewItemForegroundPointerOverLeftFluent" Color="{StaticResource TextFillColorPrimary}" />

<!-- ProgressBar -->
<SolidColorBrush x:Key="ProgressBarForeground" Color="{DynamicResource SystemAccentColorPrimary}" />
Expand Down
4 changes: 3 additions & 1 deletion RevitLookup.UI/Resources/Theme/HC1.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@
<!-- Control brushes -->

<!-- Badge -->
<!-- TODO -->

<SolidColorBrush x:Key="BadgeForeground" Color="{StaticResource SystemColorHighlightTextColor}"/>
<SolidColorBrush x:Key="BadgeBackground" Color="{StaticResource SystemColorHighlightColor}"/>

<!-- BreadcrumbBar -->
<SolidColorBrush x:Key="BreadcrumbBarNormalForegroundBrush" Color="{StaticResource SystemColorButtonTextColor}" />
Expand Down
Loading

0 comments on commit 2124a64

Please sign in to comment.