aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2017-01-29 23:26:46 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2017-01-29 23:26:46 +0100
commitdc603ff31253879bb8effb6d529f266ff78e9f3e (patch)
treee48f38ac22040da95371f661be482389b21e473e /src
parent1a4fe8bd37ed4a3e3324a134df4f90c14b315918 (diff)
parent2ec4eeed1d0353c455719aa612a12646ae2d176e (diff)
Merge improvements and debug from 'CrowIDE' branch
Diffstat (limited to 'src')
-rw-r--r--src/Command.cs34
-rw-r--r--src/CrowThread.cs58
-rw-r--r--src/GraphicObjects/Button.cs15
-rw-r--r--src/GraphicObjects/Container.cs4
-rw-r--r--src/GraphicObjects/GenericStack.cs1
-rw-r--r--src/GraphicObjects/GraphicObject.cs16
-rw-r--r--src/GraphicObjects/Group.cs4
-rw-r--r--src/GraphicObjects/Image.cs79
-rw-r--r--src/GraphicObjects/Menu.cs6
-rw-r--r--src/GraphicObjects/MenuItem.cs67
-rw-r--r--src/GraphicObjects/Popper.cs40
-rw-r--r--src/GraphicObjects/TemplatedContainer.cs4
-rw-r--r--src/GraphicObjects/TemplatedControl.cs4
-rw-r--r--src/GraphicObjects/TemplatedGroup.cs58
-rw-r--r--src/GraphicObjects/TreeView.cs27
-rw-r--r--src/GraphicObjects/Window.cs149
-rw-r--r--src/Instantiator.cs10
-rw-r--r--src/Interface.cs40
-rw-r--r--src/ItemTemplate.cs13
-rw-r--r--src/LayoutingQueueItem.cs8
20 files changed, 486 insertions, 151 deletions
diff --git a/src/Command.cs b/src/Command.cs
index 35a7facc..f7a12465 100644
--- a/src/Command.cs
+++ b/src/Command.cs
@@ -35,16 +35,20 @@ namespace Crow
#endregion
#region CTOR
- public Command ()
+ public Command (Action _executeAction)
{
+ execute = _executeAction;
}
#endregion
+ Action execute;
+
string caption;
+ Picture icon;
bool isEnabled;
-
- [XmlAttributeAttribute()][DefaultValue(true)]
+ #region Public properties
+ [XmlAttributeAttribute][DefaultValue(true)]
public virtual bool IsEnabled {
get { return isEnabled; }
set {
@@ -54,7 +58,7 @@ namespace Crow
NotifyValueChanged ("IsEnabled", isEnabled);
}
}
- [XmlAttributeAttribute()][DefaultValue("Unamed Command")]
+ [XmlAttributeAttribute][DefaultValue("Unamed Command")]
public virtual string Caption {
get { return caption; }
set {
@@ -65,5 +69,27 @@ namespace Crow
}
}
+ [XmlAttributeAttribute]
+ public Picture Icon {
+ get { return icon; }
+ set {
+ if (icon == value)
+ return;
+ icon = value;
+ NotifyValueChanged ("Icon", icon);
+ }
+ }
+ #endregion
+
+ public void Execute(){
+ if (execute != null)
+ execute ();
+ }
+ internal void raiseAllValuesChanged(){
+ NotifyValueChanged ("IsEnabled", isEnabled);
+ NotifyValueChanged ("Icon", icon);
+ NotifyValueChanged ("Caption", caption);
+ }
+
}
}
diff --git a/src/CrowThread.cs b/src/CrowThread.cs
new file mode 100644
index 00000000..dfdeda00
--- /dev/null
+++ b/src/CrowThread.cs
@@ -0,0 +1,58 @@
+//
+// CrowThread.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2017 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Threading;
+
+namespace Crow
+{
+ /// <summary>
+ /// Thread monitored by current interface with Finished event when state==Stopped
+ /// </summary>
+ public class CrowThread {
+ Thread thread;
+ public event EventHandler Finished;
+ public GraphicObject Host;
+ public CrowThread (GraphicObject host, ThreadStart start){
+ thread = new Thread (start);
+ thread.IsBackground = true;
+ Host = host;
+ lock (Host.CurrentInterface.CrowThreads)
+ Host.CurrentInterface.CrowThreads.Add (this);
+ }
+ public void CheckState(){
+ if (thread.ThreadState != ThreadState.Stopped)
+ return;
+ Finished.Raise (Host, null);
+ lock (Host.CurrentInterface.CrowThreads)
+ Host.CurrentInterface.CrowThreads.Remove (this);
+ }
+ public void Start() { thread.Start();}
+ public void Cancel(){
+ if (thread.IsAlive){
+ //cancelLoading = true;
+ thread.Join ();
+ //cancelLoading = false;
+ }
+ Host.CurrentInterface.CrowThreads.Remove (this);
+ }
+ }
+}
+
diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs
index 1cfbe85c..c73062f0 100644
--- a/src/GraphicObjects/Button.cs
+++ b/src/GraphicObjects/Button.cs
@@ -26,7 +26,6 @@ namespace Crow
public event EventHandler Pressed;
public event EventHandler Released;
- public event EventHandler Clicked;
#region TemplatedContainer overrides
public override GraphicObject Content {
@@ -34,7 +33,7 @@ namespace Crow
return _contentContainer == null ? null : _contentContainer.Child;
}
set {
- if (_contentContainer != null)
+ if (_contentContainer != null)
_contentContainer.SetChild(value);
}
}
@@ -69,24 +68,24 @@ namespace Crow
[XmlAttributeAttribute][DefaultValue("Button")]
public string Caption {
- get { return caption; }
+ get { return caption; }
set {
if (caption == value)
return;
- caption = value;
+ caption = value;
NotifyValueChanged ("Caption", caption);
}
- }
+ }
[XmlAttributeAttribute][DefaultValue("#Crow.Images.button.svg")]
public string Image {
- get { return image; }
+ get { return image; }
set {
if (image == value)
return;
- image = value;
+ image = value;
NotifyValueChanged ("Image", image);
}
- }
+ }
[XmlAttributeAttribute][DefaultValue(false)]
public bool IsPressed
{
diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs
index 0b6045bb..be6774b5 100644
--- a/src/GraphicObjects/Container.cs
+++ b/src/GraphicObjects/Container.cs
@@ -50,8 +50,10 @@ namespace Crow
if (t == null) {
Assembly a = Assembly.GetEntryAssembly ();
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name == subTree.Name)
+ if (expT.Name == subTree.Name) {
t = expT;
+ break;
+ }
}
}
GraphicObject go = (GraphicObject)Activator.CreateInstance(t);
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs
index a2d78d88..0636c14e 100644
--- a/src/GraphicObjects/GenericStack.cs
+++ b/src/GraphicObjects/GenericStack.cs
@@ -29,6 +29,7 @@ namespace Crow
return;
_spacing = value;
NotifyValueChanged ("Spacing", Spacing);
+ RegisterForLayouting (LayoutingType.Sizing|LayoutingType.ArrangeChildren);
}
}
[XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index e0e6affc..574870f8 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -270,7 +270,6 @@ namespace Crow
set {
if (horizontalAlignment == value)
return;
-
horizontalAlignment = value;
NotifyValueChanged("HorizontalAlignment", horizontalAlignment);
RegisterForLayouting (LayoutingType.X);
@@ -282,7 +281,6 @@ namespace Crow
set {
if (left == value)
return;
-
left = value;
NotifyValueChanged ("Left", left);
this.RegisterForLayouting (LayoutingType.X);
@@ -294,7 +292,6 @@ namespace Crow
set {
if (top == value)
return;
-
top = value;
NotifyValueChanged ("Top", top);
this.RegisterForLayouting (LayoutingType.Y);
@@ -509,10 +506,6 @@ namespace Crow
isVisible = value;
- //ensure main win doesn't keep hidden childrens ref
- if (!isVisible && this.Contains (CurrentInterface.HoverWidget))
- CurrentInterface.HoverWidget = null;
-
if (isVisible)
RegisterForLayouting (LayoutingType.Sizing);
else {
@@ -524,6 +517,8 @@ namespace Crow
LastSlots.Width = LastSlots.Height = 0;
}
+ //trigger a mouse to handle possible hover changes
+ CurrentInterface.ProcessMouseMove (CurrentInterface.Mouse.X, CurrentInterface.Mouse.Y);
NotifyValueChanged ("Visible", isVisible);
}
@@ -893,6 +888,7 @@ namespace Crow
#if DEBUG_LAYOUTING
CurrentInterface.currentLQI.Slot = LastSlots;
CurrentInterface.currentLQI.NewSlot = Slot;
+ Debug.WriteLine ("\t\t{0} => {1}",LastSlots,Slot);
#endif
switch (layoutType) {
@@ -1193,7 +1189,7 @@ namespace Crow
if (p != null)
p.onMouseMove(sender,e);
- MouseMove.Raise (sender, e);
+ MouseMove.Raise (this, e);
}
public virtual void onMouseDown(object sender, MouseButtonEventArgs e){
if (CurrentInterface.eligibleForDoubleClick == this && CurrentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick)
@@ -1202,8 +1198,8 @@ namespace Crow
currentInterface.clickTimer.Restart();
CurrentInterface.eligibleForDoubleClick = null;
- if (CurrentInterface.activeWidget == null)
- CurrentInterface.activeWidget = this;
+ if (CurrentInterface.ActiveWidget == null)
+ CurrentInterface.ActiveWidget = this;
if (this.Focusable && !Interface.FocusOnHover) {
BubblingMouseButtonEventArg be = e as BubblingMouseButtonEventArg;
if (be.Focused == null) {
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs
index a285e282..3c509185 100644
--- a/src/GraphicObjects/Group.cs
+++ b/src/GraphicObjects/Group.cs
@@ -337,8 +337,10 @@ namespace Crow
if (t == null) {
Assembly a = Assembly.GetEntryAssembly ();
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name == subTree.Name)
+ if (expT.Name == subTree.Name) {
t = expT;
+ break;
+ }
}
}
if (t == null)
diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs
index fa036b97..281011ad 100644
--- a/src/GraphicObjects/Image.cs
+++ b/src/GraphicObjects/Image.cs
@@ -11,66 +11,81 @@ namespace Crow
{
Picture _pic;
string _svgSub;
- bool scaled;
- [XmlAttributeAttribute()][DefaultValue(true)]
+ bool scaled, keepProps;
+
+ #region Public properties
+ [XmlAttributeAttribute][DefaultValue(true)]
public virtual bool Scaled {
get { return scaled; }
set {
if (scaled == value)
return;
- scaled = value;
+ scaled = value;
NotifyValueChanged ("Scaled", scaled);
if (_pic == null)
return;
_pic.Scaled = scaled;
RegisterForGraphicUpdate ();
}
- }
- bool keepProps;
- [XmlAttributeAttribute()][DefaultValue(true)]
+ }
+ [XmlAttributeAttribute][DefaultValue(true)]
public virtual bool KeepProportions {
get { return keepProps; }
set {
if (keepProps == value)
return;
- keepProps = value;
+ keepProps = value;
NotifyValueChanged ("KeepProportions", keepProps);
if (_pic == null)
return;
_pic.KeepProportions = keepProps;
RegisterForGraphicUpdate ();
}
- }
- [XmlAttributeAttribute("Path")]
+ }
+ [XmlAttributeAttribute]
public string Path {
- get { return _pic == null ? null : _pic.Path; }
- set {
+ get { return _pic == null ? "" : _pic.Path; }
+ set {
+ if (value == Path)
+ return;
try {
- if (string.IsNullOrEmpty(value)){
- _pic = null;
- return;
- }
- lock(CurrentInterface.LayoutMutex){
- LoadImage (value);
- _pic.Scaled = scaled;
- _pic.KeepProportions = keepProps;
+ if (string.IsNullOrEmpty(value))
+ Picture = null;
+ else {
+ lock(CurrentInterface.LayoutMutex){
+ LoadImage (value);
+ }
}
} catch (Exception ex) {
Debug.WriteLine (ex.Message);
_pic = null;
}
+ NotifyValueChanged ("Path", Path);
}
}
-
- [XmlAttributeAttribute()][DefaultValue(null)]
+ [XmlAttributeAttribute]
public string SvgSub {
get { return _svgSub; }
set {
+ if (_svgSub == value)
+ return;
_svgSub = value;
RegisterForGraphicUpdate ();
}
}
-
+ [XmlAttributeAttribute]
+ public Picture Picture {
+ get { return _pic; }
+ set {
+ if (_pic == value)
+ return;
+ _pic = value;
+ NotifyValueChanged ("Picture", _pic);
+ RegisterForGraphicUpdate ();
+ }
+ }
+ #endregion
+
#region CTOR
public Image () : base()
{
@@ -80,14 +95,17 @@ namespace Crow
#region Image Loading
public void LoadImage (string path)
{
+ Picture pic;
+ if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture))
+ pic = new SvgPicture ();
+ else
+ pic = new BmpPicture ();
- if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture))
- _pic = new SvgPicture ();
- else
- _pic = new BmpPicture ();
+ pic.LoadImage (path);
+ pic.Scaled = scaled;
+ pic.KeepProportions = keepProps;
- _pic.LoadImage (path);
- RegisterForGraphicUpdate ();
+ Picture = pic;
}
#endregion
@@ -95,12 +113,13 @@ namespace Crow
protected override int measureRawSize (LayoutingType lt)
{
if (_pic == null)
- _pic = "#Crow.Images.Icons.IconAlerte.svg";
+ return 2 * Margin;
+ //_pic = "#Crow.Images.Icons.IconAlerte.svg";
//TODO:take scalling in account
if (lt == LayoutingType.Width)
return _pic.Dimensions.Width + 2 * Margin;
else
- return _pic.Dimensions.Height + 2 * Margin;
+ return _pic.Dimensions.Height + 2 * Margin;
}
protected override void onDraw (Context gr)
{
diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs
index 1a7a3f95..66d23194 100644
--- a/src/GraphicObjects/Menu.cs
+++ b/src/GraphicObjects/Menu.cs
@@ -31,8 +31,10 @@ namespace Crow
#endregion
Orientation orientation;
+ bool autoOpen = false;
- [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
+ #region Public properties
+ [XmlAttributeAttribute][DefaultValue(Orientation.Horizontal)]
public Orientation Orientation {
get { return orientation; }
set {
@@ -42,12 +44,12 @@ namespace Crow
NotifyValueChanged ("Orientation", orientation);
}
}
- bool autoOpen = false;
[XmlIgnore]public bool AutomaticOpenning
{
get { return autoOpen; }
set { autoOpen = value; }
}
+ #endregion
public override void AddItem (GraphicObject g)
{
diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs
index 80b5759d..adec326f 100644
--- a/src/GraphicObjects/MenuItem.cs
+++ b/src/GraphicObjects/MenuItem.cs
@@ -32,12 +32,14 @@ namespace Crow
public event EventHandler Open;
public event EventHandler Close;
- public event EventHandler Execute;
string caption;
- Command command;//TODO
+ Command command;
+ Picture icon;
bool isOpened;
+ Measure popWidth, popHeight;
+ #region Public properties
[XmlAttributeAttribute][DefaultValue(false)]
public bool IsOpened {
get { return isOpened; }
@@ -54,38 +56,87 @@ namespace Crow
onClose (this, null);
}
}
-
[XmlAttributeAttribute][DefaultValue(null)]
public virtual Command Command {
get { return command; }
set {
if (command == value)
return;
+
+ if (command != null) {
+ command.raiseAllValuesChanged ();
+ command.ValueChanged -= Command_ValueChanged;
+ }
+
command = value;
+
+ if (command != null) {
+ command.ValueChanged += Command_ValueChanged;
+ command.raiseAllValuesChanged ();
+ }
+
NotifyValueChanged ("Command", command);
}
}
-
[XmlAttributeAttribute][DefaultValue("MenuItem")]
public string Caption {
- get { return caption; }
+ get { return Command == null ? caption : Command.Caption; }
set {
if (caption == value)
return;
caption = value;
- NotifyValueChanged ("Caption", caption);
+
+ if (command == null)//raise value changed only if not bound to a command
+ NotifyValueChanged ("Caption", caption);
+ }
+ }
+ [XmlAttributeAttribute]
+ public Picture Icon {
+ get { return Command == null ? icon : Command.Icon;; }
+ set {
+ if (icon == value)
+ return;
+ icon = value;
+ if (command == null)
+ NotifyValueChanged ("Icon", icon);
}
}
-
+ [XmlAttributeAttribute()][DefaultValue("Fit")]
+ public virtual Measure PopWidth {
+ get { return popWidth; }
+ set {
+ if (popWidth == value)
+ return;
+ popWidth = value;
+ NotifyValueChanged ("PopWidth", popWidth);
+ }
+ }
+ [XmlAttributeAttribute()][DefaultValue("Fit")]
+ public virtual Measure PopHeight {
+ get { return popHeight; }
+ set {
+ if (popHeight == value)
+ return;
+ popHeight = value;
+ NotifyValueChanged ("PopHeight", popHeight);
+ }
+ }
+ #endregion
+
public override void AddItem (GraphicObject g)
{
base.AddItem (g);
g.NotifyValueChanged ("PopDirection", Alignment.Right);
}
+ void Command_ValueChanged (object sender, ValueChangeEventArgs e)
+ {
+ NotifyValueChanged (e.MemberName, e.NewValue);
+ }
void onMI_Click (object sender, MouseButtonEventArgs e)
{
- Execute.Raise (this, null);
+ if (command != null)
+ command.Execute ();
if(!IsOpened)
(LogicalParent as Menu).AutomaticOpenning = false;
}
diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs
index 38621337..8c79ce24 100644
--- a/src/GraphicObjects/Popper.cs
+++ b/src/GraphicObjects/Popper.cs
@@ -38,6 +38,7 @@ namespace Crow
string caption;
Alignment popDirection;
GraphicObject _content;
+ Measure popWidth, popHeight;
public event EventHandler Pop;
public event EventHandler Unpop;
@@ -53,6 +54,26 @@ namespace Crow
NotifyValueChanged ("Caption", caption);
}
}
+ [XmlAttributeAttribute()][DefaultValue("Fit")]
+ public virtual Measure PopWidth {
+ get { return popWidth; }
+ set {
+ if (popWidth == value)
+ return;
+ popWidth = value;
+ NotifyValueChanged ("PopWidth", popWidth);
+ }
+ }
+ [XmlAttributeAttribute()][DefaultValue("Fit")]
+ public virtual Measure PopHeight {
+ get { return popHeight; }
+ set {
+ if (popHeight == value)
+ return;
+ popHeight = value;
+ NotifyValueChanged ("PopHeight", popHeight);
+ }
+ }
[XmlAttributeAttribute()][DefaultValue(false)]
public bool IsPopped
{
@@ -164,18 +185,6 @@ namespace Crow
}
#region GraphicObject overrides
- public override void OnLayoutChanges (LayoutingType layoutType)
- {
- base.OnLayoutChanges (layoutType);
-
- if (_content == null)
- return;
-
- if (layoutType == LayoutingType.Width)
- _content.MinimumSize = new Size (this.Slot.Width, _content.MinimumSize.Height);
- }
-
-
public override void onMouseClick (object sender, MouseButtonEventArgs e)
{
if (_canPop)
@@ -219,16 +228,17 @@ namespace Crow
if (Content != null) {
Content.Visible = true;
if (Content.Parent == null)
- CurrentInterface.AddWidget (Content);
- CurrentInterface.PutOnTop (Content);
+ CurrentInterface.AddWidget (Content, true);
+ CurrentInterface.PutOnTop (Content, true);
_content_LayoutChanged (this, new LayoutingEventArgs (LayoutingType.Sizing));
}
Pop.Raise (this, e);
}
public virtual void onUnpop(object sender, EventArgs e)
{
- if (Content != null)
+ if (Content != null) {
Content.Visible = false;
+ }
Unpop.Raise (this, e);
}
}
diff --git a/src/GraphicObjects/TemplatedContainer.cs b/src/GraphicObjects/TemplatedContainer.cs
index 44c2ad08..f4243588 100644
--- a/src/GraphicObjects/TemplatedContainer.cs
+++ b/src/GraphicObjects/TemplatedContainer.cs
@@ -84,8 +84,10 @@ namespace Crow
if (t == null) {
Assembly a = Assembly.GetEntryAssembly ();
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name == xr.Name)
+ if (expT.Name == xr.Name) {
t = expT;
+ break;
+ }
}
}
if (t == null)
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index ba49f44f..4a3a2507 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -154,8 +154,10 @@ namespace Crow
if (t == null) {
Assembly a = Assembly.GetEntryAssembly ();
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name == xr.Name)
+ if (expT.Name == xr.Name) {
t = expT;
+ break;
+ }
}
}
GraphicObject go = (GraphicObject)Activator.CreateInstance (t);
diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs
index 772b89cf..4c35197f 100644
--- a/src/GraphicObjects/TemplatedGroup.cs
+++ b/src/GraphicObjects/TemplatedGroup.cs
@@ -40,6 +40,7 @@ namespace Crow
#region events
public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged;
+ public event EventHandler Loaded;
#endregion
IList data;
@@ -47,7 +48,7 @@ namespace Crow
Color selBackground, selForeground;
int itemPerPage = 50;
- Thread loadingThread = null;
+ CrowThread loadingThread = null;
volatile bool cancelLoading = false;
#region Templating
@@ -106,11 +107,11 @@ namespace Crow
public virtual List<GraphicObject> Items{ get { return items.Children; }}
[XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{
get { return _selectedIndex; }
- set {
+ set {
if (value == _selectedIndex)
return;
- _selectedIndex = value;
+ _selectedIndex = value;
NotifyValueChanged ("SelectedIndex", _selectedIndex);
NotifyValueChanged ("SelectedItem", SelectedItem);
@@ -135,14 +136,14 @@ namespace Crow
NotifyValueChanged ("Data", data);
- lock (CurrentInterface.UpdateMutex)
+ //lock (CurrentInterface.UpdateMutex)
ClearItems ();
if (data == null)
return;
- loadingThread = new Thread (loading);
- loadingThread.IsBackground = true;
+ loadingThread = new CrowThread (this, loading);
+ loadingThread.Finished += (object sender, EventArgs e) => (sender as TemplatedGroup).Loaded.Raise (sender, e);
loadingThread.Start ();
//loadPage(1);
@@ -179,7 +180,7 @@ namespace Crow
protected void raiseSelectedItemChanged(){
SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
}
-
+
public virtual void AddItem(GraphicObject g){
items.AddChild (g);
@@ -271,8 +272,10 @@ namespace Crow
if (t == null) {
Assembly a = Assembly.GetEntryAssembly ();
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name == xr.Name)
+ if (expT.Name == xr.Name) {
t = expT;
+ break;
+ }
}
}
if (t == null)
@@ -310,13 +313,8 @@ namespace Crow
}
}
void cancelLoadingThread(){
- if (loadingThread == null)
- return;
- if (!loadingThread.IsAlive)
- return;
- cancelLoading = true;
- loadingThread.Join ();
- cancelLoading = false;
+ if (loadingThread != null)
+ loadingThread.Cancel ();
}
void loadPage(int pageNum)
{
@@ -341,7 +339,7 @@ namespace Crow
page = gs;
}else
- page = Activator.CreateInstance (items.GetType ()) as Group;
+ page = Activator.CreateInstance (items.GetType ()) as Group;
page.Name = "page" + pageNum;
@@ -374,6 +372,8 @@ namespace Crow
}
}
protected void loadItem(int i, Group page){
+ if (data [i] == null)//TODO:surely a threading sync problem
+ return;
GraphicObject g = null;
ItemTemplate iTemp = null;
Type dataType = data [i].GetType ();
@@ -383,9 +383,29 @@ namespace Crow
itempKey = getItempKey (dataType, data [i]);
if (ItemTemplates.ContainsKey (itempKey))
- iTemp = ItemTemplates [itempKey];
- else
- iTemp = ItemTemplates ["default"];
+ iTemp = ItemTemplates [itempKey];
+ else {
+ foreach (string it in ItemTemplates.Keys) {
+ Type t = Type.GetType (it);
+ if (t == null) {
+ Assembly a = Assembly.GetEntryAssembly ();
+ foreach (Type expT in a.GetExportedTypes ()) {
+ if (expT.Name == it) {
+ t = expT;
+ break;
+ }
+ }
+ }
+ if (t == null)
+ continue;
+ if (t.IsAssignableFrom (dataType)) {//TODO:types could be cached
+ iTemp = ItemTemplates [it];
+ break;
+ }
+ }
+ if (iTemp == null)
+ iTemp = ItemTemplates ["default"];
+ }
lock (CurrentInterface.LayoutMutex) {
g = iTemp.CreateInstance(CurrentInterface);
diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs
index 4fa881b4..d4354b65 100644
--- a/src/GraphicObjects/TreeView.cs
+++ b/src/GraphicObjects/TreeView.cs
@@ -48,7 +48,6 @@ namespace Crow
NotifyValueChanged ("IsRoot", isRoot);
}
}
-
[XmlIgnore]public override object SelectedItem {
get {
return selectedItemContainer == null ?
@@ -84,6 +83,32 @@ namespace Crow
NotifyValueChanged ("SelectedItem", SelectedItem);
raiseSelectedItemChanged ();
}
+
+ void onExpandAll_MouseClick (object sender, MouseButtonEventArgs e)
+ {
+ ExpandAll ();
+ }
+
+ public void ExpandAll(){
+ foreach (Group grp in items.Children) {
+ foreach (GraphicObject go in grp.Children) {
+ Expandable exp = go as Expandable;
+ if (exp == null)
+ continue;
+ TreeView subTV = exp.FindByName ("List") as TreeView;
+ if (subTV == null)
+ continue;
+ EventHandler handler = null;
+ handler = delegate(object sender, EventArgs e) {
+ TreeView tv = sender as TreeView;
+ tv.Loaded -= handler;
+ tv.ExpandAll ();
+ };
+ subTV.Loaded += handler;
+ exp.IsExpanded = true;
+ }
+ }
+ }
}
}
diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs
index 86f05d86..9c1a0124 100644
--- a/src/GraphicObjects/Window.cs
+++ b/src/GraphicObjects/Window.cs
@@ -46,15 +46,20 @@ namespace Crow
bool _resizable;
bool _movable;
bool hoverBorder = false;
- bool isMaximized = false;
- Measure savedH, savedW;
+ bool alwaysOnTop = false;
+
+ Rectangle savedBounds;
+ bool _minimized = false;
Container _contentContainer;
Direction currentDirection = Direction.None;
+ #region Events
public event EventHandler Closing;
public event EventHandler Maximized;
public event EventHandler Unmaximized;
+ public event EventHandler Minimize;
+ #endregion
#region CTOR
public Window () : base() {
@@ -64,73 +69,115 @@ namespace Crow
#region TemplatedContainer overrides
public override GraphicObject Content {
- get {
- return _contentContainer == null ? null : _contentContainer.Child;
- }
- set {
- _contentContainer.SetChild(value);
- }
+ get { return _contentContainer == null ? null : _contentContainer.Child; }
+ set { _contentContainer.SetChild(value); }
}
protected override void loadTemplate(GraphicObject template = null)
{
base.loadTemplate (template);
_contentContainer = this.child.FindByName ("Content") as Container;
+
+ NotifyValueChanged ("ShowNormal", false);
+ NotifyValueChanged ("ShowMinimize", true);
+ NotifyValueChanged ("ShowMaximize", true);
}
#endregion
#region public properties
- [XmlAttributeAttribute()][DefaultValue("Window")]
+ [XmlAttributeAttribute][DefaultValue("Window")]
public string Title {
get { return _title; }
set {
+ if (_title == value)
+ return;
_title = value;
NotifyValueChanged ("Title", _title);
}
}
- [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.crow.png")]
+ [XmlAttributeAttribute][DefaultValue("#Crow.Images.Icons.crow.png")]
public string Icon {
get { return _icon; }
set {
+ if (_icon == value)
+ return;
_icon = value;
NotifyValueChanged ("Icon", _icon);
}
}
- [XmlAttributeAttribute()][DefaultValue(true)]
+ [XmlAttributeAttribute][DefaultValue(true)]
public bool Resizable {
get {
return _resizable;
}
set {
+ if (_resizable == value)
+ return;
_resizable = value;
NotifyValueChanged ("Resizable", _resizable);
}
}
- [XmlAttributeAttribute()][DefaultValue(true)]
+ [XmlAttributeAttribute][DefaultValue(true)]
public bool Movable {
get {
return _movable;
}
set {
+ if (_movable == value)
+ return;
_movable = value;
NotifyValueChanged ("Movable", _movable);
}
}
- [XmlAttributeAttribute()][DefaultValue(false)]
- public bool IsMaximized {
- get { return isMaximized; }
+ [XmlAttributeAttribute][DefaultValue(false)]
+ public bool IsMinimized {
+ get { return _minimized; }
set{
- if (value == isMaximized)
+ if (value == IsMinimized)
return;
- isMaximized = value;
- if (isMaximized)
- onMaximized (this, null);
- else
- onUnmaximized (this, null);
+ _minimized = value;
+ _contentContainer.Visible = !_minimized;
- NotifyValueChanged ("IsMaximized", isMaximized);
+ NotifyValueChanged ("IsMinimized", _minimized);
+ }
+ }
+ [XmlIgnore]public bool IsMaximized {
+ get { return Width == Measure.Stretched & Height == Measure.Stretched & !_minimized; }
+ }
+ [XmlIgnore]public bool IsNormal {
+ get { return !(IsMaximized|_minimized); }
+ }
+ [XmlAttributeAttribute][DefaultValue(false)]
+ public bool AlwaysOnTop {
+ get {
+ return alwaysOnTop;
+ }
+ set {
+ if (alwaysOnTop == value)
+ return;
+ alwaysOnTop = value;
+ if (alwaysOnTop) {
+ CurrentInterface.PutOnTop (this);
+ CurrentInterface.TopWindows++;
+ }else
+ CurrentInterface.TopWindows--;
+ NotifyValueChanged ("AlwaysOnTop", alwaysOnTop);
}
}
+// [XmlAttributeAttribute()][DefaultValue(WindowState.Normal)]
+// public virtual WindowState State {
+// get { return _state; }
+// set {
+// if (_state == value)
+// return;
+// _state = value;
+// NotifyValueChanged ("State", _state);
+// NotifyValueChanged ("IsNormal", IsNormal);
+// NotifyValueChanged ("IsMaximized", IsMaximized);
+// NotifyValueChanged ("IsMinimized", IsMinimized);
+// NotifyValueChanged ("IsNotMinimized", IsNotMinimized);
+// }
+// }
#endregion
#region GraphicObject Overrides
@@ -219,14 +266,6 @@ namespace Crow
return;
}
}
-// GraphicObject firstFocusableAncestor = otkgw.hoverWidget;
-// while (firstFocusableAncestor != this) {
-// if (firstFocusableAncestor == null)
-// return;
-// if (firstFocusableAncestor.Focusable)
-// return;
-// firstFocusableAncestor = firstFocusableAncestor.Parent as GraphicObject;
-// }
if (Resizable) {
Direction lastDir = currentDirection;
@@ -289,21 +328,56 @@ namespace Crow
base.onMouseDown (sender, e);
}
#endregion
+
protected void onMaximized (object sender, EventArgs e){
- savedW = this.Width;
- savedH = this.Height;
- this.Width = Measure.Stretched;
- this.Height = Measure.Stretched;
+ lock (CurrentInterface.LayoutMutex) {
+ if (!IsMinimized)
+ savedBounds = this.LastPaintedSlot;
+ this.Left = this.Top = 0;
+ this.RegisterForLayouting (LayoutingType.Positioning);
+ this.Width = this.Height = Measure.Stretched;
+ IsMinimized = false;
+ Resizable = false;
+ NotifyValueChanged ("ShowNormal", true);
+ NotifyValueChanged ("ShowMinimize", true);
+ NotifyValueChanged ("ShowMaximize", false);
+ }
Maximized.Raise (sender, e);
+
+
+
}
protected void onUnmaximized (object sender, EventArgs e){
- this.Width = savedW;
- this.Height = savedH;
+ lock (CurrentInterface.LayoutMutex) {
+ this.Left = savedBounds.Left;
+ this.Top = savedBounds.Top;
+ this.Width = savedBounds.Width;
+ this.Height = savedBounds.Height;
+ IsMinimized = false;
+ Resizable = true;
+ NotifyValueChanged ("ShowNormal", false);
+ NotifyValueChanged ("ShowMinimize", true);
+ NotifyValueChanged ("ShowMaximize", true);
+ }
Unmaximized.Raise (sender, e);
}
+ protected void onMinimized (object sender, EventArgs e){
+ lock (CurrentInterface.LayoutMutex) {
+ if (IsNormal)
+ savedBounds = this.LastPaintedSlot;
+ Width = 200;
+ Height = 20;
+ Resizable = false;
+ IsMinimized = true;
+ NotifyValueChanged ("ShowNormal", true);
+ NotifyValueChanged ("ShowMinimize", false);
+ NotifyValueChanged ("ShowMaximize", true);
+ }
+ Minimize.Raise (sender, e);
+ }
protected void onBorderMouseLeave (object sender, MouseMoveEventArgs e)
{
hoverBorder = false;
@@ -316,9 +390,6 @@ namespace Crow
}
- protected void butMaximizePress (object sender, MouseButtonEventArgs e){
- IsMaximized = !IsMaximized;
- }
protected void butQuitPress (object sender, MouseButtonEventArgs e)
{
CurrentInterface.MouseCursor = XCursor.Default;
diff --git a/src/Instantiator.cs b/src/Instantiator.cs
index 6e94ae17..e738a741 100644
--- a/src/Instantiator.cs
+++ b/src/Instantiator.cs
@@ -139,10 +139,14 @@ namespace Crow
if (t == null) {
Assembly a = Assembly.GetEntryAssembly ();
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name == root)
+ if (expT.Name == root) {
t = expT;
+ break;
+ }
}
}
+ if (t == null)
+ throw new Exception ("IML parsing error: undefined root type (" + root + ")");
return t;
}
void emitLoader (XmlTextReader reader, Context ctx)
@@ -324,8 +328,10 @@ namespace Crow
if (t == null) {
Assembly a = Assembly.GetEntryAssembly ();
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name == reader.Name)
+ if (expT.Name == reader.Name) {
t = expT;
+ break;
+ }
}
}
if (t == null)
diff --git a/src/Interface.cs b/src/Interface.cs
index 89ee1b7e..565e6ab4 100644
--- a/src/Interface.cs
+++ b/src/Interface.cs
@@ -140,6 +140,9 @@ namespace Crow
/// on the first instance creation of a IML item.
/// </summary>
public static Dictionary<String, Instantiator> Instantiators = new Dictionary<string, Instantiator>();
+ public bool DesignMode = false;
+ public int TopWindows = 0;//window always on top count
+ public List<CrowThread> CrowThreads = new List<CrowThread>();//used to monitor thread finished
#endregion
#region Private Fields
@@ -300,7 +303,7 @@ namespace Crow
/// <summary>Widget is focused and button is down or another perif action is occuring
/// , it can not lose focus while Active</summary>
- public GraphicObject activeWidget
+ public GraphicObject ActiveWidget
{
get { return _activeWidget; }
set
@@ -392,6 +395,13 @@ namespace Crow
_focusedWidget.onKeyDown (this, lastKeyDownEvt);
}
}
+ CrowThread[] tmpThreads;
+ lock (CrowThreads) {
+ tmpThreads = new CrowThread[CrowThreads.Count];
+ Array.Copy (CrowThreads.ToArray (), tmpThreads, CrowThreads.Count);
+ }
+ for (int i = 0; i < tmpThreads.Length; i++)
+ tmpThreads [i].CheckState ();
if (!Monitor.TryEnter (UpdateMutex))
return;
@@ -533,10 +543,16 @@ namespace Crow
#region GraphicTree handling
/// <summary>Add widget to the Graphic tree of this interface and register it for layouting</summary>
- public void AddWidget(GraphicObject g)
+ public void AddWidget(GraphicObject g, bool topMost = false)
{
g.Parent = this;
- GraphicTree.Insert (0, g);
+ int ptr = TopWindows;
+ if (g is Window) {
+ if ((g as Window).AlwaysOnTop)
+ ptr = 0;
+ } else if (topMost)
+ ptr = 0;
+ GraphicTree.Insert (ptr, g);
g.RegisteredLayoutings = LayoutingType.None;
g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
}
@@ -547,12 +563,18 @@ namespace Crow
GraphicTree.Remove (g);
}
/// <summary> Put widget on top of other root widgets</summary>
- public void PutOnTop(GraphicObject g)
+ public void PutOnTop(GraphicObject g, bool topMost = false)
{
- if (GraphicTree.IndexOf(g) > 0)
+ int ptr = TopWindows;
+ if (g is Window) {
+ if ((g as Window).AlwaysOnTop)
+ ptr = 0;
+ } else if (topMost)
+ ptr = 0;
+ if (GraphicTree.IndexOf(g) > ptr)
{
GraphicTree.Remove(g);
- GraphicTree.Insert(0, g);
+ GraphicTree.Insert(ptr, g);
EnqueueForRepaint (g);
}
}
@@ -627,10 +649,10 @@ namespace Crow
MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY);
e.Mouse = Mouse;
- if (_activeWidget != null) {
+ if (ActiveWidget != null) {
//TODO, ensure object is still in the graphic tree
//send move evt even if mouse move outside bounds
- _activeWidget.onMouseMove (this, e);
+ ActiveWidget.onMouseMove (this, e);
return true;
}
@@ -710,7 +732,7 @@ namespace Crow
}
_activeWidget.onMouseUp (_activeWidget, e);
- activeWidget = null;
+ ActiveWidget = null;
return true;
}
public bool ProcessMouseButtonDown(int button)
diff --git a/src/ItemTemplate.cs b/src/ItemTemplate.cs
index 1f03f7f8..34085d2b 100644
--- a/src/ItemTemplate.cs
+++ b/src/ItemTemplate.cs
@@ -56,6 +56,19 @@ namespace Crow
public void CreateExpandDelegate (TemplatedGroup host){
Type dataType = Type.GetType(strDataType);
+ if (dataType == null) {
+ Assembly a = Assembly.GetEntryAssembly ();
+ foreach (Type expT in a.GetExportedTypes ()) {
+ if (expT.Name == strDataType) {
+ dataType = expT;
+ break;
+ }
+ }
+ }
+ if (dataType == null) {
+ Debug.WriteLine ("ItemTemplate error: DataType not found: {0}.", strDataType);
+ return;
+ }
Type tmpGrpType = typeof(TemplatedGroup);
Type evtType = typeof(EventHandler);
diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs
index 95bc6bb7..c7ae3024 100644
--- a/src/LayoutingQueueItem.cs
+++ b/src/LayoutingQueueItem.cs
@@ -83,6 +83,7 @@ namespace Crow
LQITime = new Stopwatch();
Slot = Rectangle.Empty;
NewSlot = Rectangle.Empty;
+ Debug.WriteLine ("\tRegister => " + this.ToString ());
#endif
}
#endregion
@@ -100,13 +101,20 @@ namespace Crow
}
#if DEBUG_LAYOUTING
LQITime.Start();
+ Debug.WriteLine ("=> " + this.ToString ());
#endif
LayoutingTries++;
if (!Layoutable.UpdateLayout (LayoutType)) {
+ #if DEBUG_LAYOUTING
+ Debug.WriteLine ("\t\tRequeued");
+ #endif
if (LayoutingTries < Interface.MaxLayoutingTries) {
Layoutable.RegisteredLayoutings |= LayoutType;
(Layoutable as GraphicObject).CurrentInterface.LayoutingQueue.Enqueue (this);
} else if (DiscardCount < Interface.MaxDiscardCount) {
+ #if DEBUG_LAYOUTING
+ Debug.WriteLine ("\t\tDiscarded");
+ #endif
LayoutingTries = 0;
DiscardCount++;
Layoutable.RegisteredLayoutings |= LayoutType;