Commit f602d18
Changed files (123)
build
lib
resources
icons
product
Presentation
Views
Winforms
Databinding
Helpers
Keyboard
Krypton
build/lib/app/gorilla/gorilla.commons.infrastructure.dll
Binary file
build/lib/app/gorilla/gorilla.commons.infrastructure.thirdparty.dll
Binary file
build/lib/app/gorilla/gorilla.commons.utility.dll
Binary file
build/lib/app/gorilla/gorilla.commons.windows.forms.dll
Binary file
build/lib/app/gorilla/gorilla.commons.windows.forms.thirdparty.dll
Binary file
build/resources/icons/Binoculars.ico
Binary file
build/resources/icons/Book3.ico
Binary file
build/resources/icons/Box_Blue.ico
Binary file
build/resources/icons/Box_Green.ico
Binary file
build/resources/icons/Box_Grey.ico
Binary file
build/resources/icons/Box_Orange.ico
Binary file
build/resources/icons/Box_Red.ico
Binary file
build/resources/icons/Box_Yellow.ico
Binary file
build/resources/icons/Cancel__Red.ico
Binary file
build/resources/icons/Checked_Shield_Green.ico
Binary file
build/resources/icons/Circle_Blue.ico
Binary file
build/resources/icons/Circle_Green.ico
Binary file
build/resources/icons/Circle_Grey.ico
Binary file
build/resources/icons/Circle_Orange.ico
Binary file
build/resources/icons/Circle_Red.ico
Binary file
build/resources/icons/Circle_Yellow.ico
Binary file
build/resources/icons/Clock4.ico
Binary file
build/resources/icons/Close_Box_Red.ico
Binary file
build/resources/icons/DeleteRed.ico
Binary file
build/resources/icons/DrawingPin1_Blue.ico
Binary file
build/resources/icons/DrawingPin2_Blue.ico
Binary file
build/resources/icons/Flag1_Green.ico
Binary file
build/resources/icons/Flag2_Green.ico
Binary file
build/resources/icons/FolderOpened_Yellow.ico
Binary file
build/resources/icons/Globe1.ico
Binary file
build/resources/icons/Help_Circle_Blue.ico
Binary file
build/resources/icons/Home.ico
Binary file
build/resources/icons/Hourglass.ico
Binary file
build/resources/icons/Info_Box_Blue.ico
Binary file
build/resources/icons/Magnifier2.ico
Binary file
build/resources/icons/Minimize_Box_Blue.ico
Binary file
build/resources/icons/Minus_Circle_Green.ico
Binary file
build/resources/icons/PaperClip1_Black.ico
Binary file
build/resources/icons/PaperClip2_Black.ico
Binary file
build/resources/icons/PaperClip3_Black.ico
Binary file
build/resources/icons/PaperClip4_Black.ico
Binary file
build/resources/icons/Pencil3.ico
Binary file
build/resources/icons/Plus__Orange.ico
Binary file
build/resources/icons/Power__Yellow.ico
Binary file
build/resources/icons/Ruler1.ico
Binary file
build/resources/icons/Scissors.ico
Binary file
build/resources/icons/Shield_Blue.ico
Binary file
build/resources/icons/Shield_Green.ico
Binary file
build/resources/icons/Shield_Grey.ico
Binary file
build/resources/icons/Shield_Red.ico
Binary file
build/resources/icons/Shield_Yellow.ico
Binary file
build/resources/icons/Shutdown_Box_Red.ico
Binary file
build/resources/icons/User1.ico
Binary file
build/resources/icons/Warning (2).ico
Binary file
build/resources/icons/Warning_Shield_Grey.ico
Binary file
build/resources/icons/Wizard1.ico
Binary file
build/resources/images/installing.png
Binary file
build/resources/images/splash_screen.png
Binary file
build/resources/images/welcome.png
Binary file
product/Presentation/Views/Shell/ApplicationShell.Designer.cs
@@ -58,8 +58,7 @@ namespace MoMoney.Presentation.Views.Shell {
this.ux_main_menu_strip.Font = new System.Drawing.Font("Segoe UI", 8.25F);
this.ux_main_menu_strip.Location = new System.Drawing.Point(0, 0);
this.ux_main_menu_strip.Name = "ux_main_menu_strip";
- this.ux_main_menu_strip.Padding = new System.Windows.Forms.Padding(8, 2, 0, 2);
- this.ux_main_menu_strip.Size = new System.Drawing.Size(1008, 24);
+ this.ux_main_menu_strip.Size = new System.Drawing.Size(756, 24);
this.ux_main_menu_strip.TabIndex = 0;
this.ux_main_menu_strip.Text = "menuStrip1";
//
@@ -68,44 +67,40 @@ namespace MoMoney.Presentation.Views.Shell {
this.ux_status_bar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.status_bar_label,
this.status_bar_progress_bar});
- this.ux_status_bar.Location = new System.Drawing.Point(0, 598);
+ this.ux_status_bar.Location = new System.Drawing.Point(0, 485);
this.ux_status_bar.Name = "ux_status_bar";
- this.ux_status_bar.Padding = new System.Windows.Forms.Padding(1, 0, 19, 0);
this.ux_status_bar.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
- this.ux_status_bar.Size = new System.Drawing.Size(1008, 26);
+ this.ux_status_bar.Size = new System.Drawing.Size(756, 22);
this.ux_status_bar.TabIndex = 2;
this.ux_status_bar.Text = "statusStrip1";
//
// status_bar_label
//
this.status_bar_label.Name = "status_bar_label";
- this.status_bar_label.Size = new System.Drawing.Size(18, 21);
+ this.status_bar_label.Size = new System.Drawing.Size(16, 17);
this.status_bar_label.Text = "...";
//
// status_bar_progress_bar
//
this.status_bar_progress_bar.Name = "status_bar_progress_bar";
- this.status_bar_progress_bar.Size = new System.Drawing.Size(100, 20);
+ this.status_bar_progress_bar.Size = new System.Drawing.Size(75, 16);
//
// ux_dock_panel
//
this.ux_dock_panel.ActiveAutoHideContent = null;
- this.ux_dock_panel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
this.ux_dock_panel.BackColor = System.Drawing.Color.White;
this.ux_dock_panel.CausesValidation = false;
+ this.ux_dock_panel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ux_dock_panel.DockBackColor = System.Drawing.Color.Transparent;
this.ux_dock_panel.DockBottomPortion = 150;
this.ux_dock_panel.DockLeftPortion = 200;
this.ux_dock_panel.DockRightPortion = 200;
this.ux_dock_panel.DockTopPortion = 150;
this.ux_dock_panel.Font = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World, ((byte)(0)));
- this.ux_dock_panel.Location = new System.Drawing.Point(0, 53);
- this.ux_dock_panel.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.ux_dock_panel.Location = new System.Drawing.Point(0, 24);
this.ux_dock_panel.Name = "ux_dock_panel";
this.ux_dock_panel.RightToLeftLayout = true;
- this.ux_dock_panel.Size = new System.Drawing.Size(1008, 546);
+ this.ux_dock_panel.Size = new System.Drawing.Size(756, 461);
dockPanelGradient1.EndColor = System.Drawing.SystemColors.ControlLight;
dockPanelGradient1.StartColor = System.Drawing.SystemColors.ControlLight;
autoHideStripSkin1.DockStripGradient = dockPanelGradient1;
@@ -157,7 +152,7 @@ namespace MoMoney.Presentation.Views.Shell {
this.ux_tool_bar_strip.Font = new System.Drawing.Font("Segoe UI", 8.25F);
this.ux_tool_bar_strip.Location = new System.Drawing.Point(0, 24);
this.ux_tool_bar_strip.Name = "ux_tool_bar_strip";
- this.ux_tool_bar_strip.Size = new System.Drawing.Size(1008, 25);
+ this.ux_tool_bar_strip.Size = new System.Drawing.Size(756, 25);
this.ux_tool_bar_strip.TabIndex = 6;
this.ux_tool_bar_strip.Text = "toolStrip1";
//
@@ -171,9 +166,9 @@ namespace MoMoney.Presentation.Views.Shell {
//
// ApplicationShell
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1008, 624);
+ this.ClientSize = new System.Drawing.Size(756, 507);
this.Controls.Add(this.ux_tool_bar_strip);
this.Controls.Add(this.ux_dock_panel);
this.Controls.Add(this.ux_status_bar);
@@ -181,7 +176,7 @@ namespace MoMoney.Presentation.Views.Shell {
this.HelpButton = true;
this.IsMdiContainer = true;
this.MainMenuStrip = this.ux_main_menu_strip;
- this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.Margin = new System.Windows.Forms.Padding(3);
this.Name = "ApplicationShell";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MoMoney";
product/Presentation/Views/AddCompanyView.cs
@@ -42,8 +42,8 @@ namespace MoMoney.Presentation.Views
{
ux_companys_listing.DataSource = companies.databind();
- //listView1.Items.Clear();
- //listView1.Items.AddRange(companies.Select(x => new ListViewItem(x.name, 0)).ToArray());
+ listView1.Items.Clear();
+ listView1.Items.AddRange(companies.Select(x => new ListViewItem(x.name, 0)).ToArray());
}
}
}
\ No newline at end of file
product/Presentation/Winforms/Databinding/BindingSelector.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Linq.Expressions;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public interface IBindingSelector<TypeToBindTo>
+ {
+ IPropertyBinder<TypeToBindTo, TypeOfProperty> bind_to_property<TypeOfProperty>(
+ Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to);
+ }
+
+ public class BindingSelector<TypeToBindTo> : IBindingSelector<TypeToBindTo>
+ {
+ private readonly TypeToBindTo thing_to_bind_to;
+ private readonly IPropertyInspectorFactory factory;
+
+ public BindingSelector(TypeToBindTo thing_to_bind_to, IPropertyInspectorFactory factory)
+ {
+ this.thing_to_bind_to = thing_to_bind_to;
+ this.factory = factory;
+ }
+
+ public IPropertyBinder<TypeToBindTo, TypeOfProperty> bind_to_property<TypeOfProperty>(
+ Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to)
+ {
+ var property_information = factory.create<TypeToBindTo, TypeOfProperty>().inspect(property_to_bind_to);
+ return new PropertyBinder<TypeToBindTo, TypeOfProperty>(property_information, thing_to_bind_to);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/BindingSelectorSpecs.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Linq.Expressions;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public class BindingSelectorSpecs
+ {
+ }
+
+ [Concern(typeof (BindingSelector<>))]
+ public class when_selecting_a_property_as_the_target_of_a_binding : concerns_for<IBindingSelector<IAnInterface>>
+ {
+ it should_return_a_binder_bound_to_the_correct_property =
+ () => result.property.Name.should_be_equal_to("FirstName");
+
+ it should_inspect_the_expression_for_the_property_information =
+ () => inspector.was_told_to(i => i.inspect(expression_to_parse));
+
+ context c = () =>
+ {
+ thing_to_bind_to = an<IAnInterface>();
+ factory = an<IPropertyInspectorFactory>();
+ inspector = an<IPropertyInspector<IAnInterface, string>>();
+
+ factory.is_told_to(f => f.create<IAnInterface, string>()).it_will_return(inspector);
+
+ inspector.is_told_to(i => i.inspect(null))
+ .IgnoreArguments().it_will_return(typeof (IAnInterface).GetProperty("FirstName"));
+ };
+
+ because b = () =>
+ {
+ expression_to_parse = (s => s.FirstName);
+ result = sut.bind_to_property(expression_to_parse);
+ };
+
+ public override IBindingSelector<IAnInterface> create_sut()
+ {
+ return new BindingSelector<IAnInterface>(thing_to_bind_to, factory);
+ }
+
+ static IAnInterface thing_to_bind_to;
+ static IPropertyBinder<IAnInterface, string> result;
+ static IPropertyInspectorFactory factory;
+ static IPropertyInspector<IAnInterface, string> inspector;
+ static Expression<Func<IAnInterface, string>> expression_to_parse;
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/ComboBoxDataBindingSpecs.cs
@@ -0,0 +1,66 @@
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ [Concern(typeof (Create))]
+ public class when_binding_a_property_from_an_object_to_a_combo_box : concerns
+ {
+ it should_initialize_the_combo_box_with_the_current_value_of_the_property =
+ () => combo_box.SelectedItem.should_be_equal_to(baby_girl);
+
+ context c = () =>
+ {
+ combo_box = new ComboBox();
+ thing_to_bind_to = an<IAnInterface>();
+ baby_girl = an<IAnInterface>();
+ baby_boy = an<IAnInterface>();
+
+ combo_box.Items.Add(baby_boy);
+ combo_box.Items.Add(baby_girl);
+
+ when_the(thing_to_bind_to).is_asked_for(t => t.Child).it_will_return(baby_girl);
+ };
+
+ because b = () => Create
+ .binding_for(thing_to_bind_to)
+ .bind_to_property(t => t.Child)
+ .bound_to_control(combo_box);
+
+ static ComboBox combo_box;
+ static IAnInterface thing_to_bind_to;
+ static IAnInterface baby_girl;
+ static IAnInterface baby_boy;
+ }
+
+ [Concern(typeof (Create))]
+ public class when_changing_the_selected_item_on_a_combo_box_that_is_bound_to_a_property : concerns
+ {
+ it should_change_the_value_of_the_property_that_the_combo_box_is_bound_to =
+ () => thing_to_bind_to.Child.should_be_equal_to(baby_boy);
+
+ context c = () =>
+ {
+ combo_box = new ComboBox();
+ baby_girl = an<IAnInterface>();
+ baby_boy = an<IAnInterface>();
+ thing_to_bind_to = new AnImplementation {Child = baby_girl};
+
+ combo_box.Items.Add(baby_boy);
+ combo_box.Items.Add(baby_girl);
+
+ Create
+ .binding_for(thing_to_bind_to)
+ .bind_to_property(t => t.Child)
+ .bound_to_control(combo_box);
+ };
+
+ because b = () => { combo_box.SelectedItem = baby_boy; };
+
+ static ComboBox combo_box;
+ static IAnInterface thing_to_bind_to;
+ static IAnInterface baby_girl;
+ static IAnInterface baby_boy;
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/ComboBoxPropertyBinding.cs
@@ -0,0 +1,23 @@
+using System.Windows.Forms;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public class ComboBoxPropertyBinding<TypeToBindTo, PropertyType> : IPropertyBinding<PropertyType>
+ {
+ private readonly IPropertyBinder<TypeToBindTo, PropertyType> binder;
+
+ public ComboBoxPropertyBinding(ComboBox control, IPropertyBinder<TypeToBindTo, PropertyType> binder)
+ {
+ this.binder = binder;
+ control.SelectedItem = binder.current_value();
+ control.SelectedIndexChanged +=
+ delegate { binder.change_value_of_property_to(control.SelectedItem.converted_to<PropertyType>()); };
+ }
+
+ public PropertyType current_value()
+ {
+ return binder.current_value();
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/ControlBindingExtensions.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public static class ControlBindingExtensions
+ {
+ public static IPropertyBinding<PropertyType> bound_to_control<TypeToBindTo, PropertyType>(
+ this IPropertyBinder<TypeToBindTo, PropertyType> binder,
+ Control control)
+ {
+ return new TextPropertyBinding<TypeToBindTo, PropertyType>(control, binder);
+ }
+
+ public static IPropertyBinding<PropertyType> bound_to_control<TypeToBindTo, PropertyType>(
+ this IPropertyBinder<TypeToBindTo, PropertyType> binder,
+ ComboBox control)
+ {
+ return new ComboBoxPropertyBinding<TypeToBindTo, PropertyType>(control, binder);
+ }
+
+ public static IPropertyBinding<DateTime> bound_to_control<TypeToBindTo>(
+ this IPropertyBinder<TypeToBindTo, DateTime> binder,
+ DateTimePicker control)
+ {
+ return new DateTimePickerPropertyBinding<TypeToBindTo>(control, binder);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/Create.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Linq.Expressions;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public static class Create
+ {
+ public static IBindingSelector<TypeToBindTo> binding_for<TypeToBindTo>(TypeToBindTo thing_to_bind_to)
+ {
+ return new BindingSelector<TypeToBindTo>(thing_to_bind_to, new PropertyInspectorFactory());
+ }
+
+ public static IPropertyBinding<TypeOfProperty> bind_to<TypeToBindTo, TypeOfProperty>(
+ this Control control,
+ TypeToBindTo dto,
+ Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to)
+ {
+ return binding_for(dto)
+ .bind_to_property(property_to_bind_to)
+ .bound_to_control(control);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/CreateSpecs.cs
@@ -0,0 +1,34 @@
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public class CreateSpecs
+ {
+ }
+
+ public abstract class when_a_text_control_is_bound_to_an_item : concerns
+ {
+ context c = () =>
+ {
+ textbox = new TextBox();
+ item = new TestItem {name = "k"};
+ textbox.bind_to(item, x => x.name);
+ };
+
+ static protected TextBox textbox;
+ static protected TestItem item;
+ }
+
+ public class when_the_value_of_a_text_control_changes : when_a_text_control_is_bound_to_an_item
+ {
+ it should_update_the_value_of_the_property_on_the_item = () => item.name.should_be_equal_to("mo");
+ because b = () => { textbox.Text = "mo"; };
+ }
+
+ public class TestItem
+ {
+ public string name { get; set; }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/DateTimePickerPropertyBinding.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public class DateTimePickerPropertyBinding<TypeToBindTo> : IPropertyBinding<DateTime>
+ {
+ private readonly IPropertyBinder<TypeToBindTo, DateTime> binder;
+
+ public DateTimePickerPropertyBinding(DateTimePicker control, IPropertyBinder<TypeToBindTo, DateTime> binder)
+ {
+ this.binder = binder;
+ control.ValueChanged += (o, e) => binder.change_value_of_property_to(control.Value);
+ }
+
+ public DateTime current_value()
+ {
+ return binder.current_value();
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/DateTimePropertyBindingSpecs.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ [Concern(typeof (Create))]
+ public class when_a_new_date_is_selected_by_a_date_time_picker_that_is_bound_to_a_property : concerns
+ {
+ it should_update_the_value_of_the_property =
+ () => Assertions.should_be_equal_to(thing_to_bind_to.birth_day, november_nineteenth);
+
+ context c = () =>
+ {
+ date_time_picker = new DateTimePicker {Value = DateTime.Now};
+ thing_to_bind_to = new TestDTO {birth_day = DateTime.Now};
+
+ Create.binding_for(thing_to_bind_to)
+ .bind_to_property(x => x.birth_day)
+ .bound_to_control(date_time_picker);
+ };
+
+ because b = () => { date_time_picker.Value = november_nineteenth; };
+
+ static DateTimePicker date_time_picker;
+ static TestDTO thing_to_bind_to;
+ static readonly DateTime november_nineteenth = new DateTime(2006, 11, 19);
+ }
+
+ public class TestDTO
+ {
+ public DateTime birth_day { get; set; }
+ }
+
+ public class DateTimePropertyBindingSpecs
+ {
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/IPropertyBinding.cs
@@ -0,0 +1,7 @@
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public interface IPropertyBinding<PropertyType>
+ {
+ PropertyType current_value();
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/ListboxExtensions.cs
@@ -0,0 +1,15 @@
+using System.Collections.Generic;
+using System.Windows.Forms;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ static public class ListboxExtensions
+ {
+ static public void bind_to<T>(this ComboBox control, IEnumerable<T> items)
+ {
+ control.Items.Clear();
+ items.each(x => control.Items.Add(x));
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/PropertyBinder.cs
@@ -0,0 +1,34 @@
+using System.Reflection;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public interface IPropertyBinder<TypeToBindTo, PropertyType>
+ {
+ TypeToBindTo target { get; }
+ PropertyInfo property { get; }
+ PropertyType current_value();
+ void change_value_of_property_to(PropertyType new_value);
+ }
+
+ public class PropertyBinder<TypeToBindTo, PropertyType> : IPropertyBinder<TypeToBindTo, PropertyType>
+ {
+ public PropertyBinder(PropertyInfo propery_information, TypeToBindTo target)
+ {
+ property = target.GetType().GetProperty(propery_information.Name);
+ this.target = target;
+ }
+
+ public TypeToBindTo target { get; private set; }
+ public PropertyInfo property { get; private set; }
+
+ public PropertyType current_value()
+ {
+ return (PropertyType) property.GetValue(target, null);
+ }
+
+ public void change_value_of_property_to(PropertyType value)
+ {
+ property.SetValue(target, value, null);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/PropertyBinderSpecs.cs
@@ -0,0 +1,50 @@
+using System.Reflection;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ [Concern(typeof (PropertyBinder<,>))]
+ public abstract class behaves_like_a_property_binder :
+ concerns_for<IPropertyBinder<IAnInterface, string>, PropertyBinder<IAnInterface, string>>
+ {
+ public override IPropertyBinder<IAnInterface, string> create_sut()
+ {
+ return new PropertyBinder<IAnInterface, string>(property, target);
+ }
+
+ context c = () =>
+ {
+ target = new AnImplementation {FirstName = "malik"};
+ property = typeof (IAnInterface).GetProperty("FirstName");
+ };
+
+ static protected IAnInterface target;
+ static protected PropertyInfo property;
+ }
+
+ [Concern(typeof (PropertyBinder<,>))]
+ public class when_changing_the_value_of_correctly_bound_property : behaves_like_a_property_binder
+ {
+ it should_update_the_value_of_the_property_of_the_target_of_the_binder =
+ () => target.FirstName.should_be_equal_to(first_name);
+
+ because b = () => sut.change_value_of_property_to(first_name);
+
+ const string first_name = "mo";
+ }
+
+ [Concern(typeof (PropertyBinder<,>))]
+ public class when_retrieving_the_current_value_of_a_bound_property : behaves_like_a_property_binder
+ {
+ it should_return_the_correct_value = () => result.should_be_equal_to("malik");
+
+ because b = () => { result = sut.current_value(); };
+
+ static string result;
+ }
+
+ public class PropertyBinderSpecs
+ {
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/PropertyInspector.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Linq.Expressions;
+using System.Reflection;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public interface IPropertyInspector<TypeToBindTo, TypeOfProperty>
+ {
+ PropertyInfo inspect(Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to);
+ }
+
+ public class PropertyInspector<TypeToBindTo, TypeOfProperty> : IPropertyInspector<TypeToBindTo, TypeOfProperty>
+ {
+ public PropertyInfo inspect(Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to)
+ {
+ var expression = property_to_bind_to.Body.downcast_to<MemberExpression>();
+ return expression.Member.downcast_to<PropertyInfo>();
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/PropertyInspectorFactory.cs
@@ -0,0 +1,15 @@
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public interface IPropertyInspectorFactory
+ {
+ IPropertyInspector<TypeToInspect, TypeOfProperty> create<TypeToInspect, TypeOfProperty>();
+ }
+
+ public class PropertyInspectorFactory : IPropertyInspectorFactory
+ {
+ public IPropertyInspector<TypeToInspect, TypeOfProperty> create<TypeToInspect, TypeOfProperty>()
+ {
+ return new PropertyInspector<TypeToInspect, TypeOfProperty>();
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/PropertyInspectorSpecs.cs
@@ -0,0 +1,26 @@
+using System.Reflection;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ [Concern(typeof (PropertyInspector<,>))]
+ public class when_parsing_a_valie_expression_for_the_information_on_the_property :
+ concerns_for<IPropertyInspector<IAnInterface, string>, PropertyInspector<IAnInterface, string>>
+ {
+ it should_return_the_correct_property_information = () => result.Name.should_be_equal_to("FirstName");
+
+ because b = () => { result = sut.inspect(s => s.FirstName); };
+
+ public override IPropertyInspector<IAnInterface, string> create_sut()
+ {
+ return new PropertyInspector<IAnInterface, string>();
+ }
+
+ static PropertyInfo result;
+ }
+
+ public class PropertyInspectorSpecs
+ {
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/TextBoxDataBindingSpecs.cs
@@ -0,0 +1,65 @@
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ [Concern(typeof (Create))]
+ public class when_binding_a_property_on_an_object_to_a_textbox : concerns
+ {
+ it should_initialize_the_text_of_the_textbox_to_the_value_of_the_property =
+ () => text_box.Text.should_be_equal_to(first_name);
+
+ context c = () =>
+ {
+ thing_to_bind_to = an<IAnInterface>();
+ text_box = new TextBox();
+ thing_to_bind_to.is_asked_for(t => t.FirstName).it_will_return(first_name);
+ };
+
+ because b = () => Create
+ .binding_for(thing_to_bind_to)
+ .bind_to_property(t => t.FirstName)
+ .bound_to_control(text_box);
+
+ static TextBox text_box;
+ static IAnInterface thing_to_bind_to;
+ static string first_name = "mO";
+ }
+
+ [Concern(typeof (Create))]
+ public class when_updating_the_text_of_a_bound_text_box : concerns
+ {
+ it should_update_the_value_of_the_property_that_the_textbox_is_bound_to =
+ () => thing_to_bind_to.FirstName.should_be_equal_to(expected_name);
+
+ context c = () =>
+ {
+ thing_to_bind_to = new AnImplementation {FirstName = "abshir"};
+ text_box = new TextBox();
+
+ Create
+ .binding_for(thing_to_bind_to)
+ .bind_to_property(t => t.FirstName)
+ .bound_to_control(text_box);
+ };
+
+ because b = () => { text_box.Text = expected_name; };
+
+ static TextBox text_box;
+ static IAnInterface thing_to_bind_to;
+ static string expected_name = "ugo";
+ }
+
+ public interface IAnInterface
+ {
+ string FirstName { get; }
+ IAnInterface Child { get; }
+ }
+
+ public class AnImplementation : IAnInterface
+ {
+ public string FirstName { get; set; }
+ public IAnInterface Child { get; set; }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/TextBoxExtensions.cs
@@ -0,0 +1,13 @@
+using System.Windows.Forms;
+using Gorilla.Commons.Windows.Forms.Helpers;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ static public class TextBoxExtensions
+ {
+ static public ITextControl<T> text_control<T>(this TextBox textbox)
+ {
+ return new TextControl<T>(textbox);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Databinding/TextPropertyBinding.cs
@@ -0,0 +1,23 @@
+using System.Windows.Forms;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Databinding
+{
+ public class TextPropertyBinding<TypeToBindTo, PropertyType> : IPropertyBinding<PropertyType>
+ {
+ readonly IPropertyBinder<TypeToBindTo, PropertyType> binder;
+
+ public TextPropertyBinding(Control control, IPropertyBinder<TypeToBindTo, PropertyType> binder)
+ {
+ this.binder = binder;
+ control.Text = "{0}".formatted_using(binder.current_value());
+ control.TextChanged +=
+ (o, e) => binder.change_value_of_property_to(control.Text.converted_to<PropertyType>());
+ }
+
+ public PropertyType current_value()
+ {
+ return binder.current_value();
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableListBox.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class BindableListBox<TItemToBindTo> : IBindableList<TItemToBindTo>
+ {
+ readonly IListControl<TItemToBindTo> list_control;
+
+ public BindableListBox(IListControl<TItemToBindTo> list_control)
+ {
+ this.list_control = list_control;
+ }
+
+ public void bind_to(IEnumerable<TItemToBindTo> items)
+ {
+ items.each(x => list_control.add_item(x));
+ }
+
+ public TItemToBindTo get_selected_item()
+ {
+ return list_control.get_selected_item();
+ }
+
+ public void set_selected_item(TItemToBindTo item)
+ {
+ list_control.set_selected_item(item);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableListBoxSpecs.cs
@@ -0,0 +1,49 @@
+using System.Collections.Generic;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class BindableListBoxSpecs
+ {
+ }
+
+ [Concern(typeof(BindableListBox<>))]
+ public class behaves_like_bindable_list : concerns_for<IBindableList<string>, BindableListBox<string>>
+ {
+ context c = () => { control = the_dependency<IListControl<string>>(); };
+
+ static protected IListControl<string> control;
+ }
+
+ [Concern(typeof(BindableListBox<>))]
+ public class when_binding_a_bunch_of_items_to_a_list_control : behaves_like_bindable_list
+ {
+ it should_add_each_item_to_the_list_control = () =>
+ {
+ control.was_told_to(x => x.add_item("timone"));
+ control.was_told_to(x => x.add_item("pumba"));
+ };
+
+ because b = () => sut.bind_to(new List<string> {"timone", "pumba",});
+ }
+
+ [Concern(typeof(BindableListBox<>))]
+ public class when_assigning_the_selected_item_of_a_list_control : behaves_like_bindable_list
+ {
+ it should_tell_the_list_control_to_select_that_item =
+ () => control.was_told_to(x => x.set_selected_item("arthur"));
+
+ because b = () => sut.set_selected_item("arthur");
+ }
+
+ [Concern(typeof(BindableListBox<>))]
+ public class when_getting_the_selected_item_from_a_list_control : behaves_like_bindable_list
+ {
+ it should_return_the_selected_item = () => result.should_be_equal_to("curious george");
+ context c = () => when_the(control).is_told_to(x => x.get_selected_item()).it_will_return("curious george");
+ because b = () => { result = sut.get_selected_item(); };
+
+ static string result;
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableListExtensions.cs
@@ -0,0 +1,17 @@
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ static public class BindableListExtensions
+ {
+ static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this ListBox listbox)
+ {
+ return BindableListFactory.create_for(new ListBoxListControl<TItemToBindTo>(listbox));
+ }
+
+ static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this ComboBox combobox)
+ {
+ return BindableListFactory.create_for(new ComboBoxListControl<TItemToBindTo>(combobox));
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableListFactory.cs
@@ -0,0 +1,10 @@
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ static public class BindableListFactory
+ {
+ static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(IListControl<TItemToBindTo> list_control)
+ {
+ return new BindableListBox<TItemToBindTo>(list_control);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableTextBox.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface IBindableTextBox<T>
+ {
+ void bind_to(T item);
+ T get_selected_value();
+ string text();
+ void on_leave(Action<IBindableTextBox<T>> action);
+ }
+
+ public class BindableTextBox<T> : IBindableTextBox<T>
+ {
+ readonly ITextControl<T> control;
+ readonly IList<Action<IBindableTextBox<T>>> actions = new List<Action<IBindableTextBox<T>>>();
+
+ public BindableTextBox(ITextControl<T> control)
+ {
+ this.control = control;
+ control.when_text_is_changed = () => actions.each(x => x(this));
+ }
+
+ public void bind_to(T item)
+ {
+ control.set_selected_item(item);
+ }
+
+ public T get_selected_value()
+ {
+ return control.get_selected_item();
+ }
+
+ public string text()
+ {
+ return control.text();
+ }
+
+ public void on_leave(Action<IBindableTextBox<T>> action)
+ {
+ actions.Add(action);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableTextBoxExtensions.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Linq.Expressions;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ static public class BindableTextBoxExtensions
+ {
+ static public IBindableTextBox<ItemToBindTo> rebind_with<ItemToBindTo>(
+ this ITextControl<ItemToBindTo> text_control, Expression<Func<string, ItemToBindTo>> rebind)
+ {
+ return text_control.apply(new RebindTextBoxCommand<ItemToBindTo>(rebind));
+ }
+
+ static public IBindableTextBox<ItemToBindTo> apply<ItemToBindTo>(this ITextControl<ItemToBindTo> text_control,
+ params ITextBoxCommand<ItemToBindTo>[] commands)
+ {
+ return new BindableTextBox<ItemToBindTo>(text_control).apply(commands);
+ }
+
+ static public IBindableTextBox<ItemToBindTo> apply<ItemToBindTo>(this IBindableTextBox<ItemToBindTo> textbox,
+ params ITextBoxCommand<ItemToBindTo>[] commands)
+ {
+ commands.each(x => textbox.on_leave(y => x.run(y)));
+ return textbox;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableTextBoxExtensionsSpecs.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class BindableTextBoxExtensionsSpecs
+ {
+ }
+
+ [Concern(typeof (BindableTextBoxExtensions))]
+ public class when_binding_a_text_control_to_a_command : concerns
+ {
+ it should_run_each_command_when_the_text_changes_in_the_text_control = () => command.was_told_to(x => x.run(result));
+
+ context c = () =>
+ {
+ textbox = new TextBox();
+ command = an<ITextBoxCommand<string>>();
+ };
+
+ because b = () =>
+ {
+ result = new TextControl<string>(textbox).apply(command);
+ textbox.control_is(x => x.OnLeave(new EventArgs()));
+ };
+
+ static TextBox textbox;
+ static ITextBoxCommand<string> command;
+ static IBindableTextBox<string> result;
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BindableTextBoxSpecs.cs
@@ -0,0 +1,54 @@
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+using Gorilla.Commons.Utility.Core;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class BindableTextBoxSpecs
+ {
+ }
+
+ [Concern(typeof (BindableTextBox<>))]
+ public class concerns_for_text_box : concerns_for<IBindableTextBox<string>, BindableTextBox<string>>
+ {
+ context c = () => { control = the_dependency<ITextControl<string>>(); };
+
+ static protected ITextControl<string> control;
+ }
+
+ [Concern(typeof (BindableTextBox<>))]
+ public class when_binding_an_item_to_a_textbox : concerns_for_text_box
+ {
+ it should_change_the_text_of_the_text_control = () => control.was_told_to(x => x.set_selected_item("shrek"));
+
+ because b = () => sut.bind_to("shrek");
+ }
+
+ [Concern(typeof (BindableTextBox<>))]
+ public class when_getting_the_current_value_of_a_text_box : concerns_for_text_box
+ {
+ it should_return_the_current_value_of_the_text_box = () => result.should_be_equal_to("popeye");
+
+ context c = () => when_the(control).is_told_to(x => x.get_selected_item()).it_will_return("popeye");
+ because b = () => { result = sut.get_selected_value(); };
+
+ static string result;
+ }
+
+ [Concern(typeof (BindableTextBox<>))]
+ public class when_an_action_needs_to_be_performed_when_the_value_of_a_textbox_changes : concerns_for_text_box
+ {
+ it should_perform_that_action = () => action.was_told_to(x => x.run());
+
+ context c = () => { action = an<ICommand>(); };
+
+ because b = () =>
+ {
+ sut.on_leave(x => action.run());
+ control.when_text_is_changed();
+ };
+
+ static ICommand action;
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/BitmapRegion.cs
@@ -0,0 +1,125 @@
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public static class BitmapRegion
+ {
+ /// <summary>
+ /// create and apply the region on the supplied control
+ /// </summary>
+ /// <param name="control">The Control object to apply the region to</param>
+ /// <param name="bitmap">The Bitmap object to create the region from</param>
+ public static void CreateControlRegion(Control control, Bitmap bitmap)
+ {
+ // Return if control and bitmap are null
+ if (control == null || bitmap == null)
+ return;
+
+ // Set our control's size to be the same as the bitmap + 6 pixels so that the borders don't affect it.
+ control.Width = bitmap.Width;
+ control.Height = bitmap.Height;
+
+ // Check if we are dealing with Form here
+ if (control is Form)
+ {
+ // Cast to a Form object
+ var form = (Form) control;
+
+ // Set our form's size to be a little larger that the bitmap just
+ // in case the form's border style is not set to none in the first place
+ form.Width += 15;
+ form.Height += 35;
+
+ // No border
+ form.FormBorderStyle = FormBorderStyle.None;
+
+ // Set bitmap as the background image
+ form.BackgroundImage = bitmap;
+
+ // Calculate the graphics path based on the bitmap supplied
+ var graphicsPath = CalculateControlGraphicsPath(bitmap);
+
+ // Apply new region
+ form.Region = new Region(graphicsPath);
+ }
+
+ // Check if we are dealing with Button here
+ else if (control is Button)
+ {
+ // Cast to a button object
+ var button = (Button) control;
+
+ // Do not show button text
+ button.Text = "";
+
+ // Change cursor to hand when over button
+ button.Cursor = Cursors.Hand;
+
+ // Set background image of button
+ button.BackgroundImage = bitmap;
+
+ // Calculate the graphics path based on the bitmap supplied
+ var graphicsPath = CalculateControlGraphicsPath(bitmap);
+
+ // Apply new region
+ button.Region = new Region(graphicsPath);
+ }
+ }
+
+ /// <summary>
+ /// Calculate the graphics path that representing the figure in the bitmap
+ /// excluding the transparent color which is the top left pixel.
+ /// </summary>
+ /// <param name="bitmap">The Bitmap object to calculate our graphics path from</param>
+ /// <returns>Calculated graphics path</returns>
+ static GraphicsPath CalculateControlGraphicsPath(Bitmap bitmap)
+ {
+ // create GraphicsPath for our bitmap calculation
+ var graphicsPath = new GraphicsPath();
+
+ // Use the top left pixel as our transparent color
+ var colorTransparent = bitmap.GetPixel(0, 0);
+
+ // This is to store the column value where an opaque pixel is first found.
+ // This value will determine where we start scanning for trailing opaque pixels.
+ var colOpaquePixel = 0;
+
+ // Go through all rows (Y axis)
+ for (var row = 0; row < bitmap.Height; row ++)
+ {
+ // Reset value
+ colOpaquePixel = 0;
+
+ // Go through all columns (X axis)
+ for (var col = 0; col < bitmap.Width; col ++)
+ {
+ // If this is an opaque pixel, mark it and search for anymore trailing behind
+ if (bitmap.GetPixel(col, row) != colorTransparent)
+ {
+ // Opaque pixel found, mark current position
+ colOpaquePixel = col;
+
+ // create another variable to set the current pixel position
+ var colNext = col;
+
+ // Starting from current found opaque pixel, search for anymore opaque pixels
+ // trailing behind, until a transparent pixel is found or minimum width is reached
+ for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext ++)
+ if (bitmap.GetPixel(colNext, row) == colorTransparent)
+ break;
+
+ // Form a rectangle for line of opaque pixels found and add it to our graphics path
+ graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
+
+ // No need to scan the line of opaque pixels just found
+ col = colNext;
+ }
+ }
+ }
+ // Return calculated graphics path
+ return graphicsPath;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ButtonExtensions.cs
@@ -0,0 +1,48 @@
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using Gorilla.Commons.Infrastructure.Container;
+using Gorilla.Commons.Utility.Core;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ static public class ButtonExtensions
+ {
+ static public Button will_be_shown_as(this Button button, Bitmap image)
+ {
+ BitmapRegion.CreateControlRegion(button, image);
+ button.MouseLeave += (sender, e) => BitmapRegion.CreateControlRegion(button, image);
+ button.FlatAppearance.BorderSize = 0; //needs to be here so edges don't get affected by borders
+ return button;
+ }
+
+ static public Button when_hovered_over_will_show(this Button button, Bitmap image)
+ {
+ button.MouseEnter += (sender, e) => BitmapRegion.CreateControlRegion(button, image);
+ return button;
+ }
+
+ static public Button will_execute<Command>(this Button button, Func<bool> when) where Command : ICommand
+ {
+ button.Click += (sender, e) => { if (when()) Resolve.the<Command>().run(); };
+ button.Enabled = when();
+ return button;
+ }
+
+ static public Control with_tool_tip(this Control control, string title, string caption)
+ {
+ var tip = new ToolTip
+ {
+ IsBalloon = true,
+ ToolTipTitle = title,
+ ToolTipIcon = ToolTipIcon.Info,
+ UseAnimation = true,
+ UseFading = true,
+ AutoPopDelay = 10000,
+ };
+ tip.SetToolTip(control, caption);
+ control.Controls.Add(new ControlAdapter(tip));
+ return control;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ComboBoxListControl.cs
@@ -0,0 +1,31 @@
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class ComboBoxListControl<TItemToStore> : IListControl<TItemToStore>
+ {
+ readonly ComboBox combo_box;
+
+ public ComboBoxListControl(ComboBox combo_box)
+ {
+ this.combo_box = combo_box;
+ }
+
+ public TItemToStore get_selected_item()
+ {
+ return (TItemToStore) combo_box.SelectedItem;
+ }
+
+ public void add_item(TItemToStore item)
+ {
+ combo_box.Items.Add(item);
+ combo_box.SelectedIndex = 0;
+ }
+
+ public void set_selected_item(TItemToStore item)
+ {
+ if (!Equals(item, default(TItemToStore)))
+ if (combo_box.Items.Contains(item)) combo_box.SelectedItem = item;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ControlAdapter.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class ControlAdapter : Control
+ {
+ readonly IDisposable item;
+
+ public ControlAdapter(IDisposable item)
+ {
+ this.item = item;
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing) item.Dispose();
+ base.Dispose(disposing);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ControlExtensions.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ static public class ControlExtensions
+ {
+ static public IDisposable suspend_layout(this Control control)
+ {
+ return new SuspendLayout(control);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/Events.cs
@@ -0,0 +1,35 @@
+using System;
+using System.ComponentModel;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class Events
+ {
+ public interface ControlEvents : IEventTarget
+ {
+ void OnEnter(EventArgs args);
+ void OnKeyPress(KeyPressEventArgs args);
+ void OnKeyUp(KeyEventArgs args);
+ void OnKeyDown(KeyEventArgs args);
+ void OnClick(EventArgs args);
+ void OnDoubleClick(EventArgs args);
+ void OnDragDrop(DragEventArgs args);
+ void OnDragEnter(DragEventArgs args);
+ void OnDragLeave(EventArgs args);
+ void OnDragOver(DragEventArgs args);
+ void OnMouseWheel(MouseEventArgs args);
+ void OnValidated(EventArgs args);
+ void OnValidating(CancelEventArgs args);
+ void OnLeave(EventArgs args);
+ }
+
+ public interface FormEvents : ControlEvents
+ {
+ void OnActivated(EventArgs e);
+ void OnDeactivate(EventArgs e);
+ void OnClosed(EventArgs e);
+ void OnClosing(CancelEventArgs e);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/EventTrigger.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public static class EventTrigger
+ {
+ const BindingFlags binding_flags =
+ BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance;
+
+ static readonly IDictionary<ExpressionType, Func<Expression, object>> expression_handlers;
+
+ static EventTrigger()
+ {
+ expression_handlers = new Dictionary<ExpressionType, Func<Expression, object>>();
+ expression_handlers[ExpressionType.New] = instantiate_value;
+ expression_handlers[ExpressionType.MemberAccess] = get_value_from_member_access;
+ expression_handlers[ExpressionType.Constant] = get_constant_value;
+ }
+
+ public static void trigger_event<Target>(Expression<Action<Target>> expression_representing_event_to_raise,
+ object target) where Target : IEventTarget
+ {
+ var method_call_expression = expression_representing_event_to_raise.Body.downcast_to<MethodCallExpression>();
+ var method_args = get_parameters_from(method_call_expression.Arguments);
+ var method_name = method_call_expression.Method.Name;
+ var method = target.GetType().GetMethod(method_name, binding_flags);
+
+ method.Invoke(target, method_args.ToArray());
+ }
+
+ static object get_constant_value(Expression expression)
+ {
+ return expression.downcast_to<ConstantExpression>().Value;
+ }
+
+ static object get_value_from_member_access(Expression expression)
+ {
+ var member_expression = expression.downcast_to<MemberExpression>();
+ var type = member_expression.Member.DeclaringType;
+ var member = (FieldInfo) member_expression.Member;
+ var value = member.GetValue(Activator.CreateInstance(type));
+ return value;
+ }
+
+ static object instantiate_value(Expression expression)
+ {
+ var new_expression = expression.downcast_to<NewExpression>();
+ var args = new_expression.Arguments.Select(x => get_value_from_evaluating(x));
+ return new_expression.Constructor.Invoke(args.ToArray());
+ }
+
+ static IEnumerable<object> get_parameters_from(IEnumerable<Expression> parameter_expressions)
+ {
+ foreach (var expression in parameter_expressions)
+ {
+ if (can_handle(expression)) yield return get_value_from_evaluating(expression);
+ else cannot_handle(expression);
+ }
+ }
+
+ static void cannot_handle(Expression expression)
+ {
+ throw new ArgumentException("cannot parse {0}".formatted_using(expression));
+ }
+
+ static object get_value_from_evaluating(Expression expression)
+ {
+ return expression_handlers[expression.NodeType](expression);
+ }
+
+ static bool can_handle(Expression expression)
+ {
+ return expression_handlers.ContainsKey(expression.NodeType);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/EventTriggerExtensions.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Linq.Expressions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public static class EventTriggerExtensions
+ {
+ public static void control_is<Control>(this Control target, Expression<Action<Events.ControlEvents>> expression)
+ where Control : System.Windows.Forms.Control
+ {
+ EventTrigger.trigger_event(expression, target);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/EventTriggerSpecs.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ [Concern(typeof (EventTrigger))]
+ public class when_invoking_a_call_on_a_target_via_reflection : concerns
+ {
+ it should_correctly_call_that_method =
+ () =>
+ {
+ control.called_on_key_press.should_be_true();
+ control.called_on_enter.should_be_false();
+ };
+
+ context c = () => { control = new TestControl(); };
+
+ because b =
+ () =>
+ EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new KeyPressEventArgs('A')), control);
+
+ static TestControl control;
+ }
+
+ [Concern(typeof (EventTrigger))]
+ public class when_invoking_a_call_on_a_target_by_passing_in_a_parameter : concerns
+ {
+ it should_make_the_call_correctly = () => control.key_press_arguments.should_be_equal_to(args);
+
+ //[Test]
+ //public void should_make_the_call_correctly2()
+ //{
+ // var new_args = new KeyPressEventArgs('A');
+ // control = new TestControl();
+ // EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new_args), control);
+ // control.key_press_arguments.should_be_equal_to(new_args);
+ //}
+
+ context c = () => { control = new TestControl(); };
+
+ because b = () => EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(args), control);
+
+ static TestControl control;
+
+ static readonly KeyPressEventArgs args = new KeyPressEventArgs('A');
+ }
+
+ internal class TestControl
+ {
+ public bool called_on_enter;
+ public bool called_on_key_press;
+ public KeyPressEventArgs key_press_arguments;
+
+ protected void OnEnter(EventArgs args)
+ {
+ called_on_enter = true;
+ }
+
+ protected void OnKeyPress(KeyPressEventArgs args)
+ {
+ called_on_key_press = true;
+ key_press_arguments = args;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/IBindableList.cs
@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface IBindableList<ItemToBindTo>
+ {
+ void bind_to(IEnumerable<ItemToBindTo> items);
+ ItemToBindTo get_selected_item();
+ void set_selected_item(ItemToBindTo item);
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/IEventTarget.cs
@@ -0,0 +1,6 @@
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface IEventTarget
+ {
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/IListControl.cs
@@ -0,0 +1,9 @@
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface IListControl<ItemToStore>
+ {
+ ItemToStore get_selected_item();
+ void add_item(ItemToStore item);
+ void set_selected_item(ItemToStore item);
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ITextBoxCommand.cs
@@ -0,0 +1,8 @@
+using Gorilla.Commons.Utility.Core;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface ITextBoxCommand<T> : IParameterizedCommand<IBindableTextBox<T>>
+ {
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ITextControl.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface ITextControl<ItemToStore>
+ {
+ void set_selected_item(ItemToStore item);
+ ItemToStore get_selected_item();
+ string text();
+ Action when_text_is_changed { get; set; }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ListBoxListControl.cs
@@ -0,0 +1,29 @@
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class ListBoxListControl<TItemToStore> : IListControl<TItemToStore>
+ {
+ readonly ListBox list_box;
+
+ public ListBoxListControl(ListBox list_box)
+ {
+ this.list_box = list_box;
+ }
+
+ public TItemToStore get_selected_item()
+ {
+ return (TItemToStore) list_box.SelectedItem;
+ }
+
+ public void add_item(TItemToStore item)
+ {
+ list_box.Items.Add(item);
+ }
+
+ public void set_selected_item(TItemToStore item)
+ {
+ if (list_box.Items.Contains(item)) list_box.SelectedItem = item;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/RebindTextBoxCommand.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Linq.Expressions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class RebindTextBoxCommand<T> : ITextBoxCommand<T>
+ {
+ readonly Expression<Func<string, T>> binder;
+
+ public RebindTextBoxCommand(Expression<Func<string, T>> binder)
+ {
+ this.binder = binder;
+ }
+
+ public void run(IBindableTextBox<T> item)
+ {
+ item.bind_to(binder.Compile()(item.text()));
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/RebindTextBoxCommandSpecs.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Linq.Expressions;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class RebindTextBoxCommandSpecs
+ {
+ }
+
+ [Concern(typeof (RebindTextBoxCommand<>))]
+ public class when_the_text_in_a_textbox_changes :
+ concerns_for<ITextBoxCommand<string>, RebindTextBoxCommand<string>>
+ {
+ context c = () =>
+ {
+ textbox = an<IBindableTextBox<string>>();
+ binder = x => "";
+ };
+
+ public override ITextBoxCommand<string> create_sut()
+ {
+ return new RebindTextBoxCommand<string>(binder);
+ }
+
+ static protected IBindableTextBox<string> textbox;
+ static protected Expression<Func<string, string>> binder;
+ }
+
+ [Concern(typeof (RebindTextBoxCommand<>))]
+ public class when_rebinding_an_item_to_a_textbox : when_the_text_in_a_textbox_changes
+ {
+ it should_bind_the_text_control_to_the_new_item = () => textbox.was_told_to(x => x.bind_to("kat"));
+
+ context c = () =>
+ {
+ binder = x => "kat";
+ when_the(textbox).is_told_to(x => x.text()).it_will_return("kitty");
+ };
+
+ because b = () => sut.run(textbox);
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/SuspendLayout.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class SuspendLayout : IDisposable
+ {
+ readonly Control control;
+
+ public SuspendLayout(Control control)
+ {
+ this.control = control;
+ control.SuspendLayout();
+ }
+
+ public void Dispose()
+ {
+ control.ResumeLayout();
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/TextControl.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class TextControl<ItemToStore> : ITextControl<ItemToStore>
+ {
+ readonly TextBox textbox;
+ ItemToStore selected_item;
+
+ public TextControl(TextBox textbox)
+ {
+ this.textbox = textbox;
+ when_text_is_changed = () => { };
+ textbox.Leave += (sender, args) => when_text_is_changed();
+ }
+
+ public void set_selected_item(ItemToStore item)
+ {
+ textbox.Text = item.ToString();
+ selected_item = item;
+ }
+
+ public ItemToStore get_selected_item()
+ {
+ return selected_item;
+ }
+
+ public string text()
+ {
+ return textbox.Text;
+ }
+
+ public Action when_text_is_changed { get; set; }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/TextControlSpecs.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+using Gorilla.Commons.Utility.Core;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class TextControlSpecs
+ {
+ }
+
+ [Concern(typeof (TextControl<>))]
+ public abstract class behaves_like_text_control : concerns_for<ITextControl<DateTime>, TextControl<DateTime>>
+ {
+ context c = () => { textbox = new TextBox(); };
+
+ public override ITextControl<DateTime> create_sut()
+ {
+ return new TextControl<DateTime>(textbox);
+ }
+
+ static protected TextBox textbox;
+ }
+
+ [Concern(typeof (TextControl<>))]
+ public class when_a_text_control_is_bound_to_an_item : behaves_like_text_control
+ {
+ it should_display_the_textual_version_of_the_item = () => textbox.Text.should_be_equal_to(date.ToString());
+
+ it should_bind_to_that_item = () => sut.get_selected_item().should_be_equal_to(date);
+
+ context c = () => { date = new DateTime(1984, 04, 28); };
+
+ because b = () => sut.set_selected_item(date);
+
+ static DateTime date;
+ }
+
+ [Concern(typeof (TextControl<>))]
+ public class when_the_text_changes_on_a_text_control_and_action_is_specified : behaves_like_text_control
+ {
+ it should_invoke_the_action_bound_to_it = () => action.was_told_to(x => x.run());
+
+ context c = () => { action = an<ICommand>(); };
+
+ because b = () =>
+ {
+ sut.when_text_is_changed = () => action.run();
+ textbox.control_is(x => x.OnLeave(new EventArgs()));
+ };
+
+ static ICommand action;
+ }
+
+ [Concern(typeof (TextControl<>))]
+ public class when_the_text_changes_on_a_text_control_and_action_is_not_specified : behaves_like_text_control
+ {
+ it should_not_blow_up = () => { };
+
+ because b = () => textbox.control_is(x => x.OnLeave(new EventArgs()));
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Helpers/ValidateTextBoxCommandSpecs.cs
@@ -0,0 +1,7 @@
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class ValidateTextBoxCommandSpecs
+ {
+
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Keyboard/ShortcutKey.cs
@@ -0,0 +1,24 @@
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Keyboard
+{
+ public class ShortcutKey
+ {
+ private readonly Keys key;
+
+ public ShortcutKey(Keys key)
+ {
+ this.key = key;
+ }
+
+ public ShortcutKey and(ShortcutKey other_key)
+ {
+ return new ShortcutKey(key | other_key.key);
+ }
+
+ public static implicit operator Keys(ShortcutKey key_to_convert)
+ {
+ return key_to_convert.key;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Keyboard/ShortcutKeys.cs
@@ -0,0 +1,16 @@
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Keyboard
+{
+ static public class ShortcutKeys
+ {
+ static public readonly ShortcutKey control = new ShortcutKey(Keys.Control);
+ static public readonly ShortcutKey alt = new ShortcutKey(Keys.Alt);
+ static public readonly ShortcutKey none = new ShortcutKey(Keys.None);
+ static public readonly ShortcutKey L = new ShortcutKey(Keys.L);
+ static public readonly ShortcutKey N = new ShortcutKey(Keys.N);
+ static public readonly ShortcutKey O = new ShortcutKey(Keys.O);
+ static public readonly ShortcutKey S = new ShortcutKey(Keys.S);
+ static public readonly ShortcutKey X = new ShortcutKey(Keys.X);
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Krypton/BindableListExtensions.cs
@@ -0,0 +1,18 @@
+using ComponentFactory.Krypton.Toolkit;
+using Gorilla.Commons.Windows.Forms.Helpers;
+
+namespace Gorilla.Commons.Windows.Forms.Krypton
+{
+ static public class BindableListExtensions
+ {
+ static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this KryptonListBox listbox)
+ {
+ return BindableListFactory.create_for(new KryptonListBoxListControl<TItemToBindTo>(listbox));
+ }
+
+ static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this KryptonComboBox combobox)
+ {
+ return BindableListFactory.create_for(new KryptonComboBoxListControl<TItemToBindTo>(combobox));
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Krypton/KryptonComboBoxListControl.cs
@@ -0,0 +1,32 @@
+using ComponentFactory.Krypton.Toolkit;
+using Gorilla.Commons.Windows.Forms.Helpers;
+
+namespace Gorilla.Commons.Windows.Forms.Krypton
+{
+ public class KryptonComboBoxListControl<TItemToStore> : IListControl<TItemToStore>
+ {
+ readonly KryptonComboBox combo_box;
+
+ public KryptonComboBoxListControl(KryptonComboBox combo_box)
+ {
+ this.combo_box = combo_box;
+ }
+
+ public TItemToStore get_selected_item()
+ {
+ return (TItemToStore) combo_box.SelectedItem;
+ }
+
+ public void add_item(TItemToStore item)
+ {
+ combo_box.Items.Add(item);
+ combo_box.SelectedIndex = 0;
+ }
+
+ public void set_selected_item(TItemToStore item)
+ {
+ if (!Equals(item, default(TItemToStore)))
+ if (combo_box.Items.Contains(item)) combo_box.SelectedItem = item;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Krypton/KryptonListBoxListControl.cs
@@ -0,0 +1,30 @@
+using ComponentFactory.Krypton.Toolkit;
+using Gorilla.Commons.Windows.Forms.Helpers;
+
+namespace Gorilla.Commons.Windows.Forms.Krypton
+{
+ public class KryptonListBoxListControl<TItemToStore> : IListControl<TItemToStore>
+ {
+ readonly KryptonListBox list_box;
+
+ public KryptonListBoxListControl(KryptonListBox list_box)
+ {
+ this.list_box = list_box;
+ }
+
+ public TItemToStore get_selected_item()
+ {
+ return (TItemToStore) list_box.SelectedItem;
+ }
+
+ public void add_item(TItemToStore item)
+ {
+ list_box.Items.Add(item);
+ }
+
+ public void set_selected_item(TItemToStore item)
+ {
+ if (list_box.Items.Contains(item)) list_box.SelectedItem = item;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Krypton/KryptonTextControl.cs
@@ -0,0 +1,37 @@
+using System;
+using ComponentFactory.Krypton.Toolkit;
+using Gorilla.Commons.Windows.Forms.Helpers;
+
+namespace Gorilla.Commons.Windows.Forms.Krypton
+{
+ public class KryptonTextControl<T> : ITextControl<T>
+ {
+ readonly KryptonTextBox textbox;
+ T bound_item;
+
+ public KryptonTextControl(KryptonTextBox textbox)
+ {
+ this.textbox = textbox;
+ when_text_is_changed = () => { };
+ textbox.TextChanged += (sender, args) => when_text_is_changed();
+ }
+
+ public void set_selected_item(T item)
+ {
+ textbox.Text = item.ToString();
+ bound_item = item;
+ }
+
+ public T get_selected_item()
+ {
+ return bound_item;
+ }
+
+ public string text()
+ {
+ return textbox.Text;
+ }
+
+ public Action when_text_is_changed { get; set; }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Krypton/ListboxExtensions.cs
@@ -0,0 +1,15 @@
+using System.Collections.Generic;
+using ComponentFactory.Krypton.Toolkit;
+using Gorilla.Commons.Utility.Extensions;
+
+namespace Gorilla.Commons.Windows.Forms.Krypton
+{
+ static public class ListboxExtensions
+ {
+ static public void bind_to<T>(this KryptonComboBox control, IEnumerable<T> items)
+ {
+ control.Items.Clear();
+ items.each(x => control.Items.Add(x));
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Krypton/TextBoxExtensions.cs
@@ -0,0 +1,13 @@
+using ComponentFactory.Krypton.Toolkit;
+using Gorilla.Commons.Windows.Forms.Helpers;
+
+namespace Gorilla.Commons.Windows.Forms.Krypton
+{
+ static public class TextBoxExtensions
+ {
+ static public ITextControl<T> text_control<T>(this KryptonTextBox textbox)
+ {
+ return new KryptonTextControl<T>(textbox);
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Winforms/Resources/ApplicationIcon.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Drawing;
+using System.IO;
+using Gorilla.Commons.Infrastructure.Reflection;
+
+namespace Gorilla.Commons.Windows.Forms.Resources
+{
+ public class ApplicationIcon : IDisposable
+ {
+ readonly Icon underlying_icon;
+
+ public ApplicationIcon(string name_of_the_icon, Action<ApplicationIcon> action)
+ {
+ this.name_of_the_icon = name_of_the_icon;
+ if (icon_can_be_found())
+ {
+ action(this);
+ underlying_icon = new Icon(find_full_path_to(this));
+ }
+ }
+
+ public string name_of_the_icon { get; private set; }
+
+ public virtual void Dispose()
+ {
+ if (underlying_icon != null) underlying_icon.Dispose();
+ }
+
+ static public implicit operator Icon(ApplicationIcon icon_to_convert)
+ {
+ return icon_to_convert.underlying_icon;
+ }
+
+ protected string find_full_path_to(ApplicationIcon icon_to_convert)
+ {
+ return Path.Combine(icon_to_convert.startup_directory() + @"\icons", icon_to_convert.name_of_the_icon);
+ }
+
+ protected bool icon_can_be_found()
+ {
+ return File.Exists(find_full_path_to(this));
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Resources/ApplicationIcons.cs → product/Presentation/Winforms/Resources/ApplicationIcons.cs
File renamed without changes
product/Presentation/Winforms/Resources/ApplicationImage.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Drawing;
+using System.IO;
+using Gorilla.Commons.Infrastructure.Reflection;
+
+namespace Gorilla.Commons.Windows.Forms.Resources
+{
+ public class ApplicationImage : IDisposable
+ {
+ readonly string name_of_the_image;
+ readonly Image underlying_image;
+
+ public ApplicationImage(string name_of_the_image)
+ {
+ this.name_of_the_image = name_of_the_image;
+ underlying_image = Image.FromFile(FullPathToTheFile(this));
+ }
+
+ public static implicit operator Image(ApplicationImage image_to_convert)
+ {
+ return image_to_convert.underlying_image;
+ }
+
+ public static implicit operator Bitmap(ApplicationImage image_to_convert)
+ {
+ return new Bitmap(image_to_convert);
+ }
+
+ string FullPathToTheFile(ApplicationImage image_to_convert)
+ {
+ return Path.Combine(image_to_convert.startup_directory() + @"\images", image_to_convert.name_of_the_image);
+ }
+
+ public void Dispose()
+ {
+ underlying_image.Dispose();
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Resources/ApplicationImages.cs → product/Presentation/Winforms/Resources/ApplicationImages.cs
@@ -7,7 +7,6 @@ namespace MoMoney.Presentation.Resources
public static readonly ApplicationImage Splash = new ApplicationImage("splash_screen.gif");
public static readonly ApplicationImage ReadingABill = new ApplicationImage("reading_a_bill.jpg");
public static readonly ApplicationImage PayingABill = new ApplicationImage("paying_a_bill.jpg");
- public static readonly ApplicationImage Welcome = new ApplicationImage("welcome.png");
public static readonly ApplicationImage CreateNewFile = new ApplicationImage("new_file.png");
public static readonly ApplicationImage CreateNewFileSelected = new ApplicationImage("new_file_selected.png");
product/Presentation/Winforms/Resources/HybridIcon.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Drawing;
+
+namespace Gorilla.Commons.Windows.Forms.Resources
+{
+ public class HybridIcon : ApplicationIcon
+ {
+ readonly Image underlying_image;
+
+ public HybridIcon(string name_of_the_icon, Action<ApplicationIcon> action) : base(name_of_the_icon, action)
+ {
+ if (icon_can_be_found())
+ {
+ underlying_image = Image.FromFile(find_full_path_to(this));
+ }
+ }
+
+ public override void Dispose()
+ {
+ base.Dispose();
+ if (underlying_image != null) underlying_image.Dispose();
+ }
+
+ static public implicit operator Image(HybridIcon icon_to_convert)
+ {
+ return icon_to_convert.underlying_image;
+ }
+ }
+}
\ No newline at end of file
product/Presentation/Presentation.csproj
@@ -234,8 +234,8 @@
<Compile Include="Presenters\Updates\CheckForUpdatesPresenter.cs" />
<Compile Include="Presenters\Updates\CheckForUpdatesPresenterSpecs.cs" />
<Compile Include="Presenters\Commands\ProcessQueryCommand.cs" />
- <Compile Include="Resources\ApplicationIcons.cs" />
- <Compile Include="Resources\ApplicationImages.cs" />
+ <Compile Include="Winforms\Resources\ApplicationIcons.cs" />
+ <Compile Include="Winforms\Resources\ApplicationImages.cs" />
<Compile Include="Presenters\Commands\RunQueryCommand.cs" />
<Compile Include="Views\AddCompanyView.cs">
<SubType>Form</SubType>
@@ -384,6 +384,67 @@
<DependentUpon>CheckForUpdatesView.cs</DependentUpon>
</Compile>
<Compile Include="Views\Updates\ICheckForUpdatesView.cs" />
+ <Compile Include="Winforms\Databinding\BindingSelector.cs" />
+ <Compile Include="Winforms\Databinding\BindingSelectorSpecs.cs" />
+ <Compile Include="Winforms\Databinding\ComboBoxDataBindingSpecs.cs" />
+ <Compile Include="Winforms\Databinding\ComboBoxPropertyBinding.cs" />
+ <Compile Include="Winforms\Databinding\ControlBindingExtensions.cs" />
+ <Compile Include="Winforms\Databinding\Create.cs" />
+ <Compile Include="Winforms\Databinding\CreateSpecs.cs" />
+ <Compile Include="Winforms\Databinding\DateTimePickerPropertyBinding.cs" />
+ <Compile Include="Winforms\Databinding\DateTimePropertyBindingSpecs.cs" />
+ <Compile Include="Winforms\Databinding\IPropertyBinding.cs" />
+ <Compile Include="Winforms\Databinding\ListboxExtensions.cs" />
+ <Compile Include="Winforms\Databinding\PropertyBinder.cs" />
+ <Compile Include="Winforms\Databinding\PropertyBinderSpecs.cs" />
+ <Compile Include="Winforms\Databinding\PropertyInspector.cs" />
+ <Compile Include="Winforms\Databinding\PropertyInspectorFactory.cs" />
+ <Compile Include="Winforms\Databinding\PropertyInspectorSpecs.cs" />
+ <Compile Include="Winforms\Databinding\TextBoxDataBindingSpecs.cs" />
+ <Compile Include="Winforms\Databinding\TextBoxExtensions.cs" />
+ <Compile Include="Winforms\Databinding\TextPropertyBinding.cs" />
+ <Compile Include="Winforms\Helpers\BindableListBox.cs" />
+ <Compile Include="Winforms\Helpers\BindableListBoxSpecs.cs" />
+ <Compile Include="Winforms\Helpers\BindableListExtensions.cs" />
+ <Compile Include="Winforms\Helpers\BindableListFactory.cs" />
+ <Compile Include="Winforms\Helpers\BindableTextBox.cs" />
+ <Compile Include="Winforms\Helpers\BindableTextBoxExtensions.cs" />
+ <Compile Include="Winforms\Helpers\BindableTextBoxExtensionsSpecs.cs" />
+ <Compile Include="Winforms\Helpers\BindableTextBoxSpecs.cs" />
+ <Compile Include="Winforms\Helpers\BitmapRegion.cs" />
+ <Compile Include="Winforms\Helpers\ButtonExtensions.cs" />
+ <Compile Include="Winforms\Helpers\ComboBoxListControl.cs" />
+ <Compile Include="Winforms\Helpers\ControlAdapter.cs">
+ <SubType>Component</SubType>
+ </Compile>
+ <Compile Include="Winforms\Helpers\ControlExtensions.cs" />
+ <Compile Include="Winforms\Helpers\Events.cs" />
+ <Compile Include="Winforms\Helpers\EventTrigger.cs" />
+ <Compile Include="Winforms\Helpers\EventTriggerExtensions.cs" />
+ <Compile Include="Winforms\Helpers\EventTriggerSpecs.cs" />
+ <Compile Include="Winforms\Helpers\IBindableList.cs" />
+ <Compile Include="Winforms\Helpers\IEventTarget.cs" />
+ <Compile Include="Winforms\Helpers\IListControl.cs" />
+ <Compile Include="Winforms\Helpers\ITextBoxCommand.cs" />
+ <Compile Include="Winforms\Helpers\ITextControl.cs" />
+ <Compile Include="Winforms\Helpers\ListBoxListControl.cs" />
+ <Compile Include="Winforms\Helpers\RebindTextBoxCommand.cs" />
+ <Compile Include="Winforms\Helpers\RebindTextBoxCommandSpecs.cs" />
+ <Compile Include="Winforms\Helpers\SuspendLayout.cs" />
+ <Compile Include="Winforms\Helpers\TextControl.cs" />
+ <Compile Include="Winforms\Helpers\TextControlSpecs.cs" />
+ <Compile Include="Winforms\Helpers\ValidateTextBoxCommandSpecs.cs" />
+ <Compile Include="Winforms\Keyboard\ShortcutKey.cs" />
+ <Compile Include="Winforms\Keyboard\ShortcutKeys.cs" />
+ <Compile Include="Winforms\Krypton\BindableListExtensions.cs" />
+ <Compile Include="Winforms\Krypton\KryptonComboBoxListControl.cs" />
+ <Compile Include="Winforms\Krypton\KryptonListBoxListControl.cs" />
+ <Compile Include="Winforms\Krypton\KryptonTextControl.cs" />
+ <Compile Include="Winforms\Krypton\ListboxExtensions.cs" />
+ <Compile Include="Winforms\Krypton\TextBoxExtensions.cs" />
+ <Compile Include="Winforms\Resources\ApplicationIcon.cs" />
+ <Compile Include="Winforms\Resources\ApplicationImage.cs" />
+ <Compile Include="Winforms\Resources\HybridIcon.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\licenses.licx" />
@@ -463,6 +524,18 @@
<Name>Service.Contracts</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="Winforms\Views\Billing\" />
+ <Folder Include="Winforms\Views\Core\" />
+ <Folder Include="Winforms\Views\Dialogs\" />
+ <Folder Include="Winforms\Views\Income\" />
+ <Folder Include="Winforms\Views\Menu\" />
+ <Folder Include="Winforms\Views\Navigation\" />
+ <Folder Include="Winforms\Views\Reporting\" />
+ <Folder Include="Winforms\Views\Shell\" />
+ <Folder Include="Winforms\Views\Startup\" />
+ <Folder Include="Winforms\Views\Updates\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.