while (true) {
CrowInterface.Update ();
- //Thread.Sleep (1);
+ Thread.Sleep (1);
}
}
<OutputType>Exe</OutputType>
<RootNamespace>Tests</RootNamespace>
<AssemblyName>Tests</AssemblyName>
- <StartupObject>Tests.Showcase</StartupObject>
+ <StartupObject>Tests.BasicTests</StartupObject>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ReleaseVersion>0.5</ReleaseVersion>
/// Thread monitored by current interface with Finished event when state==Stopped
/// </summary>
public class CrowThread {
- public bool cancel = false;
+ public bool cancelRequested = false;
Thread thread;
public event EventHandler Finished;
public GraphicObject Host;
}
public void Start() { thread.Start();}
public void Cancel(){
- if (thread.IsAlive){
- cancel = true;
- //cancelLoading = true;
+ if (thread.IsAlive & !cancelRequested){
+ cancelRequested = true;
thread.Join ();
- //cancelLoading = false;
}
lock (Host.currentInterface.CrowThreads)
Host.currentInterface.CrowThreads.Remove (this);
public class GraphicObject : ILayoutable, IValueChange, IDisposable
{
#region IDisposable implementation
+ protected bool disposed = false;
+
+ public void Dispose(){
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ ~GraphicObject(){
+ Dispose(false);
+ }
+ protected virtual void Dispose(bool disposing){
+ if (disposed){
+ #if DEBUG_DISPOSE
+ Debug.WriteLine ("Trying to dispose already disposed obj: {0}", this.ToString());
+ #endif
+ return;
+ }
- public virtual void Dispose ()
- {
- #if DEBUG_DISPOSE
- Debug.WriteLine ("{0} Disposed", this.ToString());
- #endif
-
- parent = null;
- if (IsQueueForRedraw)
- Debugger.Break ();
- if (!localDataSourceIsNull)
- DataSource = null;
+ if (disposing) {
+ #if DEBUG_DISPOSE
+ Debug.WriteLine ("Disposing: {0}", this.ToString());
+ if (IsQueueForRedraw)
+ throw new Exception("Trying to dispose an object queued for Redraw: " + this.ToString());
+ #endif
+ if (currentInterface.HoverWidget != null) {
+ if (currentInterface.HoverWidget.IsOrIsInside(this))
+ currentInterface.HoverWidget = null;
+ }
+ if (currentInterface.ActiveWidget != null) {
+ if (currentInterface.ActiveWidget.IsOrIsInside (this))
+ currentInterface.ActiveWidget = null;
+ }
+ if (currentInterface.FocusedWidget != null) {
+ if (currentInterface.FocusedWidget.IsOrIsInside (this))
+ currentInterface.FocusedWidget = null;
+ }
+ if (!localDataSourceIsNull)
+ DataSource = null;
+ parent = null;
+ } else
+ Debug.WriteLine ("!!! Finalized by GC: {0}", this.ToString ());
Clipping?.Dispose ();
bmp?.Dispose ();
- }
+ disposed = true;
+ }
#endregion
internal static ulong currentUid = 0;
/// <summary>
/// return true if this is contained inside go
/// </summary>
- public bool IsInside(GraphicObject go){
+ public bool IsOrIsInside(GraphicObject go){
+ if (this == go)
+ return true;
ILayoutable p = this.Parent;
while (p != null) {
if (p == go)
public virtual void RemoveChild(GraphicObject child)
{
child.LayoutChanged -= OnChildLayoutChanges;
- child.Parent = null;
//check if HoverWidget is removed from Tree
- if (currentInterface.HoverWidget != null) {
- if (currentInterface.HoverWidget.IsInside(this))
- currentInterface.HoverWidget = null;
- }
+
lock (children)
Children.Remove(child);
}
#endregion
- public override void Dispose ()
+ protected override void Dispose (bool disposing)
{
- foreach (GraphicObject c in children)
- c.Dispose ();
- base.Dispose ();
+ if (disposing) {
+ foreach (GraphicObject c in children)
+ c.Dispose ();
+ }
+ base.Dispose (disposing);
}
}
}
}
Unpoped.Raise (this, e);
}
+
+ protected override void Dispose (bool disposing)
+ {
+ if (_content != null && disposing) {
+ if (_content.Parent == null)
+ _content.Dispose ();
+ }
+ base.Dispose (disposing);
+ }
}
}
if (child != null) {
//check if HoverWidget is removed from Tree
- if (currentInterface.HoverWidget != null) {
- if (currentInterface.HoverWidget.IsInside(this))
- currentInterface.HoverWidget = null;
- }
contentSize = new Size (0, 0);
child.LayoutChanged -= OnChildLayoutChanges;
child.Dispose ();
- child.Parent = null;
this.RegisterForGraphicUpdate ();
}
}
#endregion
- public override void Dispose ()
+ protected override void Dispose (bool disposing)
{
- if (child != null)
+ if (disposing && child != null)
child.Dispose ();
- base.Dispose ();
+ base.Dispose (disposing);
}
}
}
ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate);
for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
- if ((bool)loadingThread?.cancel)
+ if ((bool)loadingThread?.cancelRequested) {
+ this.Dispose ();
return;
+ }
loadPage (i);
Thread.Sleep (1);
}
for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) {
if (i >= data.Count)
break;
- if ((bool)loadingThread?.cancel)
+ if ((bool)loadingThread?.cancelRequested) {
+ page.Dispose ();
return;
+ }
loadItem (i, page);
}
string getItempKey(Type dataType, object o){
try {
return dataType.GetProperty (_dataTest).GetGetMethod ().Invoke (o, null).ToString();
- } catch (Exception ex) {
+ } catch {
return dataType.FullName;
}
}
SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource);
}
- public override void Dispose ()
+ protected override void Dispose (bool disposing)
{
- if (loadingThread != null)
+ if (disposing && loadingThread != null)
loadingThread.Cancel ();
- base.Dispose ();
+ base.Dispose (disposing);
}
}
}
protected void close(){
Closing.Raise (this, null);
- currentInterface.DeleteWidget (this);
+ if (Parent is Interface)
+ (Parent as Interface).DeleteWidget (this);
+ else if (Parent is Group)
+ (Parent as Group).RemoveChild (this);
+ else if (Parent is PrivateContainer)
+ (Parent as Container).Child = null;
}
}
}
/// <summary>Set visible state of widget to false and remove if from the graphic tree</summary>
public void DeleteWidget(GraphicObject g)
{
- if (_hoverWidget != null) {
- if (_hoverWidget.IsInside(g))
- HoverWidget = null;
- }
lock (UpdateMutex) {
RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot));
GraphicTree.Remove (g);
//TODO:parent is not reset to null because object will be added
//to ObjectToRedraw list, and without parent, it fails
GraphicObject g = GraphicTree [0];
- if (_hoverWidget != null) {
- if (_hoverWidget.IsInside(g))
- HoverWidget = null;
- }
RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot));
GraphicTree.RemoveAt (0);
g.Dispose ();