Add support for checkboxes with mixed state
This commit is contained in:
Родитель
a281a0ace5
Коммит
6f51fcf01f
|
@ -48,6 +48,7 @@ namespace Samples
|
|||
|
||||
AddSample (null, "Boxes", typeof(Boxes));
|
||||
AddSample (null, "Buttons", typeof(ButtonSample));
|
||||
AddSample (null, "CheckBox", typeof(Checkboxes));
|
||||
AddSample (null, "ComboBox", typeof(ComboBoxes));
|
||||
// AddSample (null, "Designer", typeof(Designer));
|
||||
AddSample (null, "Drag & Drop", typeof(DragDrop));
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
<Compile Include="Samples\Labels.cs" />
|
||||
<Compile Include="Samples\Colors.cs" />
|
||||
<Compile Include="Samples\Frames.cs" />
|
||||
<Compile Include="Samples\Checkboxes.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// Checkboxes.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2012 Xamarin Inc
|
||||
//
|
||||
// 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;
|
||||
using Xwt;
|
||||
|
||||
namespace Samples
|
||||
{
|
||||
public class Checkboxes: VBox
|
||||
{
|
||||
public Checkboxes ()
|
||||
{
|
||||
PackStart (new CheckBox ("Normal checkbox"));
|
||||
|
||||
var b = new CheckBox ("Allows mixed") { AllowMixed = true };
|
||||
PackStart (b);
|
||||
|
||||
int clicks = 0, toggles = 0;
|
||||
Label la = new Label ();
|
||||
PackStart (la);
|
||||
|
||||
b.Clicked += delegate {
|
||||
clicks++;
|
||||
la.Text = string.Format ("active:{0}, mixed:{1}, clicks:{2}, toggles:{3}", b.Active, b.Mixed, clicks, toggles);
|
||||
};
|
||||
|
||||
b.Toggled += delegate {
|
||||
toggles++;
|
||||
la.Text = string.Format ("active:{0}, mixed:{1}, clicks:{2}, toggles:{3}", b.Active, b.Mixed, clicks, toggles);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,9 @@ namespace Xwt.GtkBackend
|
|||
{
|
||||
public class CheckBoxBackend: WidgetBackend, ICheckBoxBackend
|
||||
{
|
||||
bool allowMixed;
|
||||
bool internalActiveUpdate;
|
||||
|
||||
public CheckBoxBackend ()
|
||||
{
|
||||
}
|
||||
|
@ -39,6 +42,7 @@ namespace Xwt.GtkBackend
|
|||
{
|
||||
Widget = new Gtk.CheckButton ();
|
||||
Widget.Show ();
|
||||
Widget.Clicked += HandleWidgetPreClicked;
|
||||
}
|
||||
|
||||
protected new Gtk.CheckButton Widget {
|
||||
|
@ -52,13 +56,27 @@ namespace Xwt.GtkBackend
|
|||
|
||||
public bool Active {
|
||||
get {
|
||||
return Widget.Active;
|
||||
return Widget.Active && !Widget.Inconsistent;
|
||||
}
|
||||
set {
|
||||
Widget.Active = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AllowMixed {
|
||||
get {
|
||||
return allowMixed;
|
||||
}
|
||||
set {
|
||||
allowMixed = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Mixed {
|
||||
get { return Widget.Inconsistent; }
|
||||
set { Widget.Inconsistent = value; }
|
||||
}
|
||||
|
||||
public void SetContent (string label)
|
||||
{
|
||||
Widget.Label = label;
|
||||
|
@ -102,8 +120,26 @@ namespace Xwt.GtkBackend
|
|||
}
|
||||
}
|
||||
|
||||
void HandleWidgetPreClicked (object sender, EventArgs e)
|
||||
{
|
||||
if (allowMixed) {
|
||||
if (!Widget.Active) {
|
||||
if (Widget.Inconsistent)
|
||||
Widget.Inconsistent = false;
|
||||
else {
|
||||
Widget.Inconsistent = true;
|
||||
internalActiveUpdate = true;
|
||||
Widget.Active = true;
|
||||
internalActiveUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetActivated (object sender, EventArgs e)
|
||||
{
|
||||
if (internalActiveUpdate)
|
||||
return;
|
||||
Toolkit.Invoke (delegate {
|
||||
EventSink.OnToggled ();
|
||||
});
|
||||
|
@ -111,6 +147,8 @@ namespace Xwt.GtkBackend
|
|||
|
||||
void HandleWidgetClicked (object sender, EventArgs e)
|
||||
{
|
||||
if (internalActiveUpdate)
|
||||
return;
|
||||
Toolkit.Invoke (delegate {
|
||||
EventSink.OnClicked ();
|
||||
});
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace Xwt.Backends
|
|||
void SetContent (IWidgetBackend widget);
|
||||
void SetContent (string label);
|
||||
bool Active { get; set; }
|
||||
bool Mixed { get; set; }
|
||||
bool AllowMixed { get; set; }
|
||||
}
|
||||
|
||||
public interface ICheckBoxEventSink: IWidgetEventSink
|
||||
|
|
|
@ -174,6 +174,7 @@
|
|||
<Compile Include="Xwt.Backends\IComboBoxEntryBackend.cs" />
|
||||
<Compile Include="Xwt.Engine\Toolkit.cs" />
|
||||
<Compile Include="Xwt\TreeViewStatus.cs" />
|
||||
<Compile Include="Xwt\Clipboard.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -100,6 +100,18 @@ namespace Xwt
|
|||
set { Backend.Active = value; }
|
||||
}
|
||||
|
||||
[DefaultValue (false)]
|
||||
public bool Mixed {
|
||||
get { return Backend.Mixed; }
|
||||
set { Backend.Mixed = value; }
|
||||
}
|
||||
|
||||
[DefaultValue (false)]
|
||||
public bool AllowMixed {
|
||||
get { return Backend.AllowMixed; }
|
||||
set { Backend.AllowMixed = value; }
|
||||
}
|
||||
|
||||
protected virtual void OnClicked (EventArgs e)
|
||||
{
|
||||
if (clicked != null)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// Clipboard.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2012 Xamarin Inc
|
||||
//
|
||||
// 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 static class Clipboard
|
||||
{
|
||||
public static void Copy (TransferDataSource data)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче