Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Differenciates between RadioButton and CheckBox frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
netonjm committed Jun 28, 2019
1 parent fd3fcfc commit a49a912
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 35 deletions.
8 changes: 4 additions & 4 deletions TestApps/Samples/Samples/ListView2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public ListView2 ()
list.Columns.Add (new ListViewColumn("Not Editable", new CheckBoxCellView { Editable = false, ActiveField = nonEditableActiveField }));

Xwt.Backends.IEditableCellViewFrontend<string> stringCellView = new TextCellView { Editable = true, TextField = textField };
stringCellView.EditingFinished += StringCellView_EditingFinished;
stringCellView.EditingFinished += CellView_EditingFinished;
list.Columns.Add (new ListViewColumn("Editable",(CellView) stringCellView));

cellView = new CheckBoxCellView { EditableField = editableField, ActiveField = somewhatEditableData };
cellView.EditingFinished += CellView_EditingFinished;
list.Columns.Add(new ListViewColumn("Somewhat Editable",(CellView) cellView));

stringCellView = new TextCellView { EditableField = editableField, TextField = textField2 };
stringCellView.EditingFinished += StringCellView_EditingFinished;
stringCellView.EditingFinished += CellView_EditingFinished;

list.Columns.Add (new ListViewColumn("Somewhat Editable", (CellView)stringCellView));

Expand All @@ -64,12 +64,12 @@ public ListView2 ()
PackStart (list, true);
}

void CellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<Xwt.CheckBoxState> e)
void CellView_EditingFinished(object sender, Xwt.CellEditingFinishedArgs<Xwt.CheckBoxState> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}

void StringCellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<string> e)
void CellView_EditingFinished(object sender, Xwt.CellEditingFinishedArgs<string> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}
Expand Down
8 changes: 4 additions & 4 deletions TestApps/Samples/Samples/ListViewCombos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public ListViewCombos ()
comboCellView.Items.Add (1, "one");
comboCellView.Items.Add (2, "two");
comboCellView.Items.Add (3, "three");
comboCellView.EditingFinished += TextCellView_EditingFinished;
comboCellView.EditingFinished += CellView_EditingFinished;
list.Columns.Add (new ListViewColumn ("List 1", comboCellView));

var comboCellView2 = new ComboBoxCellView { Editable = true, SelectedIndexField = indexField2, ItemsField = itemsField };
comboCellView2.EditingFinished += TextCellView_EditingFinished;
comboCellView2.EditingFinished += CellView_EditingFinished;
list.Columns.Add (new ListViewColumn ("List 2", comboCellView2));

int p = 0;
Expand All @@ -70,12 +70,12 @@ public ListViewCombos ()
PackStart (list, true);
}

void ComboCellView_EditingFinished (object sender, Xwt.Backends.CellEditingFinishedArgs<CheckBoxState> e)
void CellView_EditingFinished (object sender, CellEditingFinishedArgs<CheckBoxState> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}

void TextCellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<string> e)
void CellView_EditingFinished(object sender, CellEditingFinishedArgs<string> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}
Expand Down
19 changes: 12 additions & 7 deletions TestApps/Samples/Samples/TreeViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TreeViews ()
store.GetNavigatorAt(view.CurrentEventRow).SetValue(text, "TriState Toggled");
}
};
triStateCellView.EditingFinished += CheckBoxCellView_EditingFinished;
triStateCellView.EditingFinished += CellView_EditingFinished;
var checkCellView = new CheckBoxCellView (check) { Editable = true };
checkCellView.Toggled += (object sender, WidgetEventArgs e) => {
if (view.CurrentEventRow == null) {
Expand All @@ -64,7 +64,7 @@ public TreeViews ()
store.GetNavigatorAt(view.CurrentEventRow).SetValue(text, "Toggled " + checkCellView.Active);
}
};
checkCellView.EditingFinished += CheckBoxCellView_EditingFinished;
checkCellView.EditingFinished += CellView_EditingFinished;
var optionCellView1 = new RadioButtonCellView (option1) { Editable = true };
optionCellView1.Toggled += (object sender, WidgetEventArgs e) => {
if (view.CurrentEventRow == null) {
Expand All @@ -73,7 +73,7 @@ public TreeViews ()
store.GetNavigatorAt (view.CurrentEventRow).SetValue (option2, optionCellView1.Active);
}
};
optionCellView1.EditingFinished += CheckBoxCellView_EditingFinished;
optionCellView1.EditingFinished += CellView_EditingFinished;

var optionCellView2 = new RadioButtonCellView (option2) { Editable = true };
optionCellView2.Toggled += (object sender, WidgetEventArgs e) => {
Expand All @@ -83,7 +83,7 @@ public TreeViews ()
store.GetNavigatorAt (view.CurrentEventRow).SetValue (option1, optionCellView2.Active);
}
};
optionCellView2.EditingFinished += CheckBoxCellView_EditingFinished;
optionCellView2.EditingFinished += CellView_EditingFinished;

TreePosition initialActive = null;
var optionCellView3 = new RadioButtonCellView (option3) { Editable = true };
Expand All @@ -96,7 +96,7 @@ public TreeViews ()
initialActive = view.CurrentEventRow;
}
};
optionCellView3.EditingFinished += CheckBoxCellView_EditingFinished;
optionCellView3.EditingFinished += CellView_EditingFinished;
view.Columns.Add ("TriCheck", triStateCellView);
view.Columns.Add ("Check", checkCellView);
view.Columns.Add ("Radio", optionCellView1, optionCellView2, optionCellView3);
Expand Down Expand Up @@ -235,12 +235,17 @@ public TreeViews ()
view.RowExpanded += (sender, e) => label.Text = "Row expanded: " + store.GetNavigatorAt (e.Position).GetValue (text);
}

void CheckBoxCellView_EditingFinished (object sender, Xwt.Backends.CellEditingFinishedArgs<Xwt.CheckBoxState> e)
void CellView_EditingFinished(object sender, Xwt.CellEditingFinishedArgs<Xwt.CheckBoxState> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}

void StringCellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<string> e)
void CellView_EditingFinished(object sender, Xwt.CellEditingFinishedArgs<bool> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}

void CellView_EditingFinished(object sender, Xwt.CellEditingFinishedArgs<string> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}
Expand Down
14 changes: 12 additions & 2 deletions Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,22 @@ void HandleToggled (object o, ToggledArgs args)
(object) newState : (object) (newState == CheckBoxState.On);

CellUtil.SetModelValue (TreeModel, iter, field.Index, type, newValue);
view.RaiseEditingFinished(new CellEditingFinishedArgs<CheckBoxState> (lastValue, newState));

if (view is ICheckBoxCellViewFrontend) {
((ICheckBoxCellViewFrontend)view).RaiseEditingFinished(new CellEditingFinishedArgs<CheckBoxState>(lastValue, newState));
} else if (view is IRadioButtonCellViewFrontend) {
((IRadioButtonCellViewFrontend)view).RaiseEditingFinished(new CellEditingFinishedArgs<bool>(lastValue == CheckBoxState.On, newState == CheckBoxState.On));
}

lastValue = newState;
return;
}

view.RaiseEditingFinished (new CellEditingFinishedArgs<CheckBoxState> (lastValue, lastValue));
if (view is ICheckBoxCellViewFrontend) {
((ICheckBoxCellViewFrontend)view).RaiseEditingFinished(new CellEditingFinishedArgs<CheckBoxState>(lastValue, lastValue));
} else if (view is IRadioButtonCellViewFrontend) {
((IRadioButtonCellViewFrontend)view).RaiseEditingFinished(new CellEditingFinishedArgs<bool>(lastValue == CheckBoxState.On, lastValue == CheckBoxState.On));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Xwt/Xwt.Backends/ICheckBoxCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Xwt.Backends
{
public interface ICheckBoxCellViewFrontend: IToggleCellViewFrontend
public interface ICheckBoxCellViewFrontend: IToggleCellViewFrontend, IEditableCellViewFrontend<CheckBoxState>
{
CheckBoxState State { get; }
bool AllowMixed { get; }
Expand Down
12 changes: 0 additions & 12 deletions Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@

namespace Xwt.Backends
{
public class CellEditingFinishedArgs<T> : EventArgs
{
public CellEditingFinishedArgs(T oldValue, T newValue)
{
OldValue = oldValue;
NewValue = newValue;
}

public T OldValue { get; set; }
public T NewValue { get; set; }
}

public interface IEditableCellViewFrontend<T>
{
event EventHandler<CellEditingFinishedArgs<T>> EditingFinished;
Expand Down
2 changes: 1 addition & 1 deletion Xwt/Xwt.Backends/IRadioButtonCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace Xwt.Backends
{
public interface IRadioButtonCellViewFrontend: IToggleCellViewFrontend
public interface IRadioButtonCellViewFrontend: IToggleCellViewFrontend, IEditableCellViewFrontend<bool>
{
}
}
3 changes: 1 addition & 2 deletions Xwt/Xwt.Backends/IToggleCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

namespace Xwt.Backends
{

public interface IToggleCellViewFrontend : ICellViewFrontend, IEditableCellViewFrontend<CheckBoxState>
public interface IToggleCellViewFrontend : ICellViewFrontend
{
bool Active { get; }
bool Editable { get; }
Expand Down
1 change: 1 addition & 0 deletions Xwt/Xwt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
<Compile Include="Xwt.Drawing\FontSizeTextAttribute.cs" />
<Compile Include="Xwt.Accessibility\AccessibleFields.cs" />
<Compile Include="Xwt.Accessibility\XwtAccessibleBackend.cs" />
<Compile Include="Xwt\CellEditingFinishedArgs.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup />
Expand Down
41 changes: 41 additions & 0 deletions Xwt/Xwt/CellEditingFinishedArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// IComboBoxCellViewFrontend.cs
//
// Author:
// Lluis Sanchez Gual <lluis@xamarin.com>
//
// Copyright (c) 2016 Xamarin, Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;

namespace Xwt
{
public class CellEditingFinishedArgs<T> : EventArgs
{
public CellEditingFinishedArgs(T oldValue, T newValue)
{
OldValue = oldValue;
NewValue = newValue;
}

public T OldValue { get; set; }
public T NewValue { get; set; }
}
}
4 changes: 2 additions & 2 deletions Xwt/Xwt/RadioButtonCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public bool RaiseToggled ()
return false;
}

public event EventHandler<CellEditingFinishedArgs<CheckBoxState>> EditingFinished;
public event EventHandler<CellEditingFinishedArgs<bool>> EditingFinished;

public void RaiseEditingFinished (CellEditingFinishedArgs<CheckBoxState> args)
public void RaiseEditingFinished (CellEditingFinishedArgs<bool> args)
{
EditingFinished?.Invoke (this, args);
}
Expand Down

0 comments on commit a49a912

Please sign in to comment.