Skip to content

Commit f07ba57

Browse files
2 parents d662f7e + 1e0c0f9 commit f07ba57

21 files changed

Lines changed: 396 additions & 105 deletions

CommonControls.Images/ComCtlResources.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,38 @@ internal static class ComCtlResources
3737
/// Error, Color Dictionary initializing parameters (const). Value: "Error initializing color Dictionary "
3838
/// </summary>
3939
internal const string ErrorInitializingColorDictionary = "Error initializing color Dictionary ";
40+
41+
/// <summary>
42+
/// The grid exception validate (const). Value: "Grid dimensions and cell sizes must be non-negative and greater than
43+
/// zero.".
44+
/// </summary>
45+
internal const string GridExceptionValidate =
46+
"Grid dimensions and cell sizes must be non-negative and greater than zero.";
47+
48+
/// <summary>
49+
/// Image add, needed for the Image Name (const). Value: "T".
50+
/// </summary>
51+
internal const string ImageAdd = "T";
52+
53+
/// <summary>
54+
/// The debug timer (const). Value: "Time Tracked end: ".
55+
/// </summary>
56+
internal const string DebugTimer = "Time Tracked end: ";
57+
58+
/// <summary>
59+
/// The Context Menu Deselect (const). Value: "Deselect".
60+
/// </summary>
61+
internal const string ContextDeselect = "Deselect";
62+
63+
/// <summary>
64+
/// The Context Menu Deselect all (const). Value: "Deselect All".
65+
/// </summary>
66+
internal const string ContextDeselectAll = "Deselect All";
67+
68+
/// <summary>
69+
/// The error could not load image (const). Value: "Error could not load Image:".
70+
/// </summary>
71+
internal const string ErrorCouldNotLoadImage = "Error could not load Image:";
72+
4073
}
4174
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CommonControls.Images
4+
* FILE: ExtendedGrid.cs
5+
* PURPOSE: Extension for Grid Control, not elegant but does the job
6+
* PROGRAMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
// ReSharper disable MemberCanBeInternal
10+
// ReSharper disable MemberCanBePrivate.Global
11+
// ReSharper disable ArrangeBraces_for
12+
// ReSharper disable UnusedMember.Global, basic Dummy for later use
13+
14+
using System.Windows;
15+
using System.Windows.Controls;
16+
using System.Windows.Media;
17+
18+
namespace CommonControls.Images
19+
{
20+
/// <summary>
21+
/// The extended grid class.
22+
/// </summary>
23+
internal static class ExtendedGrid
24+
{
25+
/// <summary>
26+
/// The height and width of each cell. Min is 1.
27+
/// </summary>
28+
private static int _cellHeight = 1;
29+
30+
/// <summary>
31+
/// The cell width
32+
/// </summary>
33+
private static int _cellWidth = 1;
34+
35+
/// <summary>
36+
/// Gets the number of columns.
37+
/// </summary>
38+
/// <value>
39+
/// The columns.
40+
/// </value>
41+
public static int Columns { get; private set; }
42+
43+
/// <summary>
44+
/// Gets the number of rows.
45+
/// </summary>
46+
public static int Rows { get; private set; }
47+
48+
/// <summary>
49+
/// Gets or sets the default cell size in pixels.
50+
/// </summary>
51+
public static int CellSize { get; set; } = 100;
52+
53+
/// <summary>
54+
/// Generates a grid with uniform cell size.
55+
/// </summary>
56+
/// <param name="columns">Number of columns in the grid.</param>
57+
/// <param name="rows">Number of rows in the grid.</param>
58+
/// <param name="gridLines">Indicates whether grid lines should be shown.</param>
59+
/// <returns>A <see cref="Grid" /> with uniform cell dimensions.</returns>
60+
public static Grid ExtendGrid(int columns, int rows, bool gridLines)
61+
{
62+
ValidateParameters(columns, rows, CellSize);
63+
64+
Columns = columns;
65+
Rows = rows;
66+
_cellHeight = _cellWidth = CellSize;
67+
68+
return InitializeGridBase(gridLines, _cellWidth * Columns, _cellHeight * Rows, null, null);
69+
}
70+
71+
/// <summary>
72+
/// Generates a grid with specified cell dimensions.
73+
/// </summary>
74+
/// <param name="columns">Number of columns in the grid.</param>
75+
/// <param name="rows">Number of rows in the grid.</param>
76+
/// <param name="width">Cell width in pixels.</param>
77+
/// <param name="height">Cell height in pixels.</param>
78+
/// <param name="gridLines">Indicates whether grid lines should be shown.</param>
79+
/// <returns>A <see cref="Grid" /> with custom cell dimensions.</returns>
80+
public static Grid ExtendGrid(int columns, int rows, int width, int height, bool gridLines)
81+
{
82+
ValidateParameters(columns, rows, width, height);
83+
84+
Columns = columns;
85+
Rows = rows;
86+
_cellWidth = width;
87+
_cellHeight = height;
88+
89+
return InitializeGridBase(gridLines, _cellWidth * Columns, _cellHeight * Rows, null, null);
90+
}
91+
92+
/// <summary>
93+
/// Initializes the grid with the base settings and dimensions.
94+
/// </summary>
95+
/// <param name="gridLines">Indicates whether grid lines should be shown.</param>
96+
/// <param name="width">Total grid width in pixels.</param>
97+
/// <param name="height">Total grid height in pixels.</param>
98+
/// <param name="columnWidths">Custom column widths if any, null otherwise.</param>
99+
/// <param name="rowHeights">Custom row heights if any, null otherwise.</param>
100+
/// <returns>A <see cref="Grid" /> configured with the specified parameters.</returns>
101+
private static Grid InitializeGridBase(bool gridLines, int width, int height,
102+
IReadOnlyCollection<int> columnWidths, IReadOnlyCollection<int> rowHeights)
103+
{
104+
var dynamicGrid = new Grid
105+
{
106+
HorizontalAlignment = HorizontalAlignment.Left,
107+
VerticalAlignment = VerticalAlignment.Top,
108+
ShowGridLines = gridLines,
109+
Width = width,
110+
Height = height,
111+
#if DEBUG
112+
Background = Brushes.Gray
113+
#endif
114+
};
115+
116+
if (columnWidths != null)
117+
{
118+
foreach (var colWidth in columnWidths)
119+
{
120+
dynamicGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(colWidth) });
121+
}
122+
}
123+
else
124+
{
125+
for (var i = 0; i < Columns; i++)
126+
{
127+
dynamicGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(_cellWidth) });
128+
}
129+
}
130+
131+
if (rowHeights != null)
132+
{
133+
foreach (var rowHeight in rowHeights)
134+
{
135+
dynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(rowHeight) });
136+
}
137+
}
138+
else
139+
{
140+
for (var i = 0; i < Rows; i++)
141+
{
142+
dynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(_cellHeight) });
143+
}
144+
}
145+
146+
return dynamicGrid;
147+
}
148+
149+
/// <summary>
150+
/// Validates the grid parameters to ensure they are non-negative.
151+
/// </summary>
152+
private static void ValidateParameters(int columns, int rows, int width = 1, int height = 1)
153+
{
154+
if (columns < 0 || rows < 0 || width < 1 || height < 1)
155+
{
156+
throw new Exception(ComCtlResources.GridExceptionValidate);
157+
}
158+
}
159+
}
160+
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
3-
* PROJECT: CommonControls
3+
* PROJECT: CommonControls.Images
44
* FILE: ImageEventArgs.cs
55
* PURPOSE: Image Event Detail Information can be further extended in the future
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/
88

9-
using System;
10-
11-
namespace CommonControls
9+
namespace CommonControls.Images
1210
{
1311
/// <inheritdoc />
1412
/// <summary>

CommonControls.Images/Themes/Generic.xaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<ResourceDictionary
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:CommonControls.Images">
45

56
<!-- Style for Buttons -->
67
<Style TargetType="Button">
@@ -25,7 +26,24 @@
2526
</Setter.Value>
2627
</Setter>
2728
</Style>
28-
29+
30+
<!-- Style for Thumbnails -->
31+
<Style TargetType="{x:Type local:Thumbnails}">
32+
<Setter Property="Template">
33+
<Setter.Value>
34+
<ControlTemplate TargetType="{x:Type local:Thumbnails}">
35+
<Border Background="{TemplateBinding Background}"
36+
BorderBrush="{TemplateBinding BorderBrush}"
37+
BorderThickness="{TemplateBinding BorderThickness}">
38+
<TextBlock Text="{TemplateBinding Content}"
39+
Foreground="{DynamicResource TextBrush}"
40+
VerticalAlignment="Center"
41+
HorizontalAlignment="Center" />
42+
</Border>
43+
</ControlTemplate>
44+
</Setter.Value>
45+
</Setter>
46+
</Style>
2947

3048
<!-- Style for ComboBox -->
3149
<Style TargetType="ComboBox">
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="CommonControls.Thumbnails"
1+
<UserControl x:Class="CommonControls.Images.Thumbnails"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
3-
* PROJECT: CommonControls
3+
* PROJECT: CommonControls.Images
44
* FILE: Thumbnails.xaml.cs
55
* PURPOSE: Custom Thumbnail Control
66
* PROGRAMER: Peter Geinitz (Wayfarer)
@@ -14,22 +14,17 @@
1414
// ReSharper disable UnusedType.Global
1515
// ReSharper disable UnusedMember.Global
1616

17-
using System;
1817
using System.Collections.Concurrent;
19-
using System.Collections.Generic;
2018
using System.Diagnostics;
2119
using System.IO;
22-
using System.Linq;
23-
using System.Threading;
24-
using System.Threading.Tasks;
2520
using System.Windows;
2621
using System.Windows.Controls;
2722
using System.Windows.Input;
2823
using System.Windows.Media;
2924
using System.Windows.Media.Imaging;
3025
using Mathematics;
3126

32-
namespace CommonControls
27+
namespace CommonControls.Images
3328
{
3429
/// <summary>
3530
/// Basic Image Thumbnails

CommonControls/ComCtlResources.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ internal static class ComCtlResources
4545
/// </summary>
4646
internal const string GlobalKeyCommandBindings = "CommandBindings";
4747

48-
/// <summary>
49-
/// The error could not load image (const). Value: "Error could not load Image:".
50-
/// </summary>
51-
internal const string ErrorCouldNotLoadImage = "Error could not load Image:";
52-
53-
/// <summary>
54-
/// Image add, needed for the Image Name (const). Value: "T".
55-
/// </summary>
56-
internal const string ImageAdd = "T";
57-
5848
/// <summary>
5949
/// The unique Caption Text (const). Value: "Name was not unique".
6050
/// </summary>
@@ -75,26 +65,11 @@ internal static class ComCtlResources
7565
/// </summary>
7666
internal const string DataListEntry = "Empty";
7767

78-
/// <summary>
79-
/// The Context Menu Deselect (const). Value: "Deselect".
80-
/// </summary>
81-
internal const string ContextDeselect = "Deselect";
82-
83-
/// <summary>
84-
/// The Context Menu Deselect all (const). Value: "Deselect All".
85-
/// </summary>
86-
internal const string ContextDeselectAll = "Deselect All";
87-
8868
/// <summary>
8969
/// New Item (const). Value: "NewItem".
9070
/// </summary>
9171
internal const string NewItem = "New Item";
9272

93-
/// <summary>
94-
/// The debug timer (const). Value: "Time Tracked end: ".
95-
/// </summary>
96-
internal const string DebugTimer = "Time Tracked end: ";
97-
9873
/// <summary>
9974
/// Separator (const). Value: " , ".
10075
/// </summary>

CommonControls/CommonControls.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<ProjectReference Include="..\Imaging\Imaging.csproj" />
13+
<ProjectReference Include="..\ExtendedSystemObjects\ExtendedSystemObjects.csproj" />
1414
<ProjectReference Include="..\ViewModel\ViewModel.csproj" />
1515
</ItemGroup>
1616

CommonControls/Themes/Generic.xaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,6 @@
1515
<SolidColorBrush x:Key="BackgroundBrush" Color="{DynamicResource BackgroundColor}" />
1616
<SolidColorBrush x:Key="TextBrush" Color="{DynamicResource TextColor}" />
1717

18-
<!-- Style for Thumbnails -->
19-
<Style TargetType="{x:Type local:Thumbnails}">
20-
<Setter Property="Template">
21-
<Setter.Value>
22-
<ControlTemplate TargetType="{x:Type local:Thumbnails}">
23-
<Border Background="{TemplateBinding Background}"
24-
BorderBrush="{TemplateBinding BorderBrush}"
25-
BorderThickness="{TemplateBinding BorderThickness}">
26-
<TextBlock Text="{TemplateBinding Content}"
27-
Foreground="{DynamicResource TextBrush}"
28-
VerticalAlignment="Center"
29-
HorizontalAlignment="Center" />
30-
</Border>
31-
</ControlTemplate>
32-
</Setter.Value>
33-
</Setter>
34-
</Style>
35-
3618
<!-- Style for Buttons -->
3719
<Style TargetType="Button">
3820
<Setter Property="Background" Value="{DynamicResource PrimaryBrush}" />

CommonLibraryGuiTests/CommonCtrl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Diagnostics;
1414
using System.Threading;
1515
using CommonControls;
16+
using CommonControls.Images;
1617
using Imaging;
1718
using InterOp;
1819
using NUnit.Framework;

0 commit comments

Comments
 (0)