<Compile Include="src\GraphicObjects\ComboBox.cs" />
<Compile Include="src\GraphicObjects\GroupBox.cs" />
<Compile Include="src\GraphicObjects\ScrollBar.cs" />
- <Compile Include="src\BubblingMouseButtonEventArgs.cs" />
<Compile Include="src\SolidColor.cs" />
<Compile Include="src\Gradient.cs" />
<Compile Include="src\Fill\Fill.cs" />
+++ /dev/null
-//
-// BubblingMouseButtonEventArgs.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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 Crow
-{
- public class BubblingMouseButtonEventArg: MouseButtonEventArgs
- {
- public GraphicObject Focused;
- public BubblingMouseButtonEventArg(MouseButtonEventArgs mbe) : base(mbe){
-
- }
- }
-}
-
protected object dataSource;
string style;
object tag;
+ bool isDragged;
+ bool allowDrag;
+
#endregion
#region public fields
return false;
}
+ #region Drag&Drop
+ [XmlAttributeAttribute()][DefaultValue(false)]
+ public virtual bool AllowDrag {
+ get { return allowDrag; }
+ set {
+ if (allowDrag == value)
+ return;
+ allowDrag = value;
+ NotifyValueChanged ("AllowDrag", allowDrag);
+ }
+ }
+
+ public List<Type> AllowedDroppedTypes;
+
+ [XmlIgnore]public virtual bool AllowDrop {
+ get { return AllowedDroppedTypes?.Count>0; }
+ }
+ [XmlIgnore]public virtual bool IsDragged {
+ get { return isDragged; }
+ set {
+ if (isDragged == value)
+ return;
+ isDragged = value;
+
+ if (isDragged)
+ currentInterface.HoverWidget = null;
+
+ NotifyValueChanged ("IsDrag", IsDragged);
+ }
+ }
+
+ public void AddAllowedDroppedType (Type newType){
+ if (AllowedDroppedTypes == null)
+ AllowedDroppedTypes = new List<Type> ();
+ AllowedDroppedTypes.Add (newType);
+ NotifyValueChanged ("AllowDrop", AllowDrop);
+ }
+ #endregion
+
#region Queuing
/// <summary>
/// Register old and new slot for clipping
public virtual bool MouseIsIn(Point m)
{
try {
- if (!(Visible & isEnabled))
+ if (!(Visible & isEnabled)||IsDragged)
return false;
if (ScreenCoordinates (Slot).ContainsOrIsEqual (m)) {
Scroller scr = Parent as Scroller;
if (CurrentInterface.ActiveWidget == null)
CurrentInterface.ActiveWidget = this;
- if (this.Focusable && !Interface.FocusOnHover) {
- BubblingMouseButtonEventArg be = e as BubblingMouseButtonEventArg;
- if (be.Focused == null) {
- be.Focused = this;
- CurrentInterface.FocusedWidget = this;
- }
+ if (this.Focusable && !(Interface.FocusOnHover || currentInterface.focusGiven)) {
+ CurrentInterface.FocusedWidget = this;
+ currentInterface.focusGiven = true;
}
//bubble event to the top
GraphicObject p = Parent as GraphicObject;
g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
g.LayoutChanged += OnChildLayoutChanges;
}
- public virtual void RemoveChild(GraphicObject child)
+ public virtual void RemoveChild(GraphicObject child)
{
child.LayoutChanged -= OnChildLayoutChanges;
//check if HoverWidget is removed from Tree
searchLargestChild ();
if (child == tallestChild && Height == Measure.Fit)
searchTallestChild ();
-
+
this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
}
public virtual void ClearChildren()
ChildrenCleared.Raise (this, new EventArgs ());
}
-// public void putWidgetOnTop(GraphicObject w)
-// {
-// if (Children.Contains(w))
-// {
-// lock (children) {
-// Children.Remove (w);
-// Children.Add (w);
-// }
-// }
-// }
+ public void PutWidgetOnTop(GraphicObject w)
+ {
+ if (this.ArrangeChildren) {
+ Debug.WriteLine ("Can't raise widget in group that has ArrangeChildren set to true.");
+ return;
+ }
+ if (Children.Contains(w))
+ {
+ lock (children) {
+ Children.Remove (w);
+ Children.Add (w);
+ }
+ lock (CurrentInterface.UpdateMutex)
+ CurrentInterface.EnqueueForRepaint (w);
+ }
+ }
// public void putWidgetOnBottom(GraphicObject w)
// {
// if (Children.Contains(w))
}
return base.measureRawSize (lt);
}
-
+
public override void OnLayoutChanges (LayoutingType layoutType)
{
base.OnLayoutChanges (layoutType);
}
}
-
+
#region Mouse handling
public override void checkHoverWidget (MouseMoveEventArgs e)
{
}
public override bool MouseIsIn (Point m)
{
- return IsEnabled ? base.MouseIsIn (m) || child.MouseIsIn (m) : false;
+ return IsEnabled && !IsDragged ? base.MouseIsIn (m) || child.MouseIsIn (m) : false;
}
public override void onMouseEnter (object sender, MouseMoveEventArgs e)
{
#region Mouse Handling
public override bool MouseIsIn (Point m)
{
- if (!Visible)
+ if (!(Visible & IsEnabled) || IsDragged)
return false;
bool mouseIsInTitle = TabTitle.ScreenCoordinates (TabTitle.Slot).ContainsOrIsEqual (m);
// }
#endregion
+ public void Raise (){
+ Group g = LogicalParent as Group;
+ if (g != null) {
+ g.PutWidgetOnTop (this);
+ return;
+ }
+ Interface i = LogicalParent as Interface;
+ if (i != null)
+ i.PutOnTop (this);
+ }
+
#region GraphicObject Overrides
+ protected override void onFocused (object sender, EventArgs e)
+ {
+ if (Interface.RaiseWhenFocused)
+ this.Raise ();
+
+ base.onFocused (sender, e);
+ }
+ public override void onMouseEnter (object sender, MouseMoveEventArgs e)
+ {
+ if (Interface.FocusOnHover && !CurrentInterface.focusGiven) {
+ CurrentInterface.FocusedWidget = this;
+ CurrentInterface.focusGiven = true;
+ }
+ base.onMouseEnter (sender, e);
+ }
public override void onMouseMove (object sender, MouseMoveEventArgs e)
{
base.onMouseMove (sender, e);
public static string CrowConfigRoot;
/// <summary>If true, mouse focus is given when mouse is over control</summary>
public static bool FocusOnHover = false;
+ /// <summary>Raise widget when it got focus </summary>
+ public static bool RaiseWhenFocused = true;
/// <summary> Threshold to catch borders for sizing </summary>
public static int BorderThreshold = 5;
/// <summary>Double click threshold in milisecond</summary>
internal static Interface CurrentInterface;
internal Stopwatch clickTimer = new Stopwatch();
internal GraphicObject eligibleForDoubleClick = null;
+ /// <summary>
+ /// each time a processMouseEvent is called at the top level, the focusGiven is set to false, and if while bubbling up the event
+ /// give the focus to a new widget, this boolean is set to true to prevent giving focus multiple times for a single mouse event.
+ /// </summary>
+ internal bool focusGiven = false;
#endregion
#region Events
/// <returns>true if mouse is in the interface</returns>
public bool ProcessMouseMove(int x, int y)
{
+ focusGiven = false;
+
int deltaX = x - Mouse.X;
int deltaY = y - Mouse.Y;
Mouse.X = x;
GraphicObject g = GraphicTree [i];
if (g.MouseIsIn (e.Position)) {
g.checkHoverWidget (e);
- if (g is Window)
- PutOnTop (g);
return true;
}
}
/// <param name="button">Button index</param>
public bool ProcessMouseButtonUp(int button)
{
+ focusGiven = false;
+
Mouse.DisableBit (button);
MouseButtonEventArgs e = new MouseButtonEventArgs () { Mouse = Mouse };
/// <param name="button">Button index</param>
public bool ProcessMouseButtonDown(int button)
{
+ focusGiven = false;
+
Mouse.EnableBit (button);
MouseButtonEventArgs e = new MouseButtonEventArgs () { Mouse = Mouse };
if (HoverWidget == null)
return false;
- HoverWidget.onMouseDown(HoverWidget,new BubblingMouseButtonEventArg(e));
+ HoverWidget.onMouseDown(HoverWidget, e);
if (FocusedWidget == null)
return true;