[hyena] Remove trailing whitespace
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hyena] Remove trailing whitespace
- Date: Tue, 12 Jan 2010 20:23:47 +0000 (UTC)
commit c7900c8f7bc3bff1590fc352a5c18c29cd6d45eb
Author: Gabriel Burt <gabriel burt gmail com>
Date: Tue Jan 12 11:09:54 2010 -0800
Remove trailing whitespace
.../Hyena.Data.Sqlite/DatabaseColumn.cs | 50 ++--
.../Hyena.Data.Sqlite/DatabaseColumnAttribute.cs | 30 +-
.../Hyena.Data.Sqlite/HyenaSqliteCommand.cs | 10 +-
.../Hyena.Data.Sqlite/HyenaSqliteConnection.cs | 50 ++--
.../Hyena.Data.Sqlite/SqliteModelCache.cs | 20 +-
.../Hyena.Data.Sqlite/SqliteModelProvider.cs | 130 +++++-----
.../Hyena.Data.Sqlite/SqliteUtils.cs | 14 +-
.../Hyena.Data.Sqlite/Tests/DbBoundType.cs | 22 +-
.../Hyena.Data.Sqlite/Tests/SqliteCommandTests.cs | 36 ++--
.../Tests/SqliteModelProviderTests.cs | 64 +++---
.../Hyena.Data.Sqlite/Tests/SqliteUtilTests.cs | 10 +-
src/Hyena.Gui/Hyena.Data.Gui/CellContext.cs | 8 +-
src/Hyena.Gui/Hyena.Data.Gui/Column.cs | 42 ++--
src/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs | 22 +-
src/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs | 40 ++--
src/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs | 48 ++--
src/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs | 36 ++--
src/Hyena.Gui/Hyena.Data.Gui/ColumnController.cs | 52 ++--
.../Hyena.Data.Gui/ColumnHeaderCellText.cs | 12 +-
src/Hyena.Gui/Hyena.Data.Gui/IListView.cs | 4 +-
src/Hyena.Gui/Hyena.Data.Gui/ISizeRequestCell.cs | 2 +-
src/Hyena.Gui/Hyena.Data.Gui/ITextCell.cs | 2 +-
src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs | 4 +-
.../ListView/ListView_DragAndDrop.cs | 52 ++--
.../Hyena.Data.Gui/ListView/ListView_Header.cs | 174 ++++++------
.../ListView/ListView_Interaction.cs | 194 +++++++-------
.../Hyena.Data.Gui/ListView/ListView_Model.cs | 52 ++--
.../Hyena.Data.Gui/ListView/ListView_Rendering.cs | 182 +++++++-------
.../Hyena.Data.Gui/ListView/ListView_Windowing.cs | 58 ++--
src/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs | 58 ++--
src/Hyena.Gui/Hyena.Data.Gui/ObjectListView.cs | 6 +-
.../Hyena.Data.Gui/RowActivatedHandler.cs | 4 +-
src/Hyena.Gui/Hyena.Data.Gui/SortableColumn.cs | 10 +-
src/Hyena.Gui/Hyena.Gui.Dialogs/ExceptionDialog.cs | 60 ++--
.../Hyena.Gui.Dialogs/VersionInformationDialog.cs | 40 ++--
src/Hyena.Gui/Hyena.Gui.Theatrics/Actor.cs | 26 +-
src/Hyena.Gui/Hyena.Gui.Theatrics/Choreographer.cs | 22 +-
src/Hyena.Gui/Hyena.Gui.Theatrics/Pulsator.cs | 36 ++--
.../Hyena.Gui.Theatrics/SingleActorStage.cs | 12 +-
src/Hyena.Gui/Hyena.Gui.Theatrics/Stage.cs | 88 +++---
.../Tests/ChoreographerTests.cs | 34 ++--
src/Hyena.Gui/Hyena.Gui.Theming/GtkColors.cs | 24 +-
src/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs | 54 ++--
src/Hyena.Gui/Hyena.Gui.Theming/Theme.cs | 66 +++---
src/Hyena.Gui/Hyena.Gui.Theming/ThemeEngine.cs | 12 +-
src/Hyena.Gui/Hyena.Gui/ActionManager.cs | 36 ++--
src/Hyena.Gui/Hyena.Gui/CairoExtensions.cs | 128 +++++-----
src/Hyena.Gui/Hyena.Gui/CleanRoomStartup.cs | 10 +-
src/Hyena.Gui/Hyena.Gui/CompositeUtils.cs | 28 +-
src/Hyena.Gui/Hyena.Gui/Contrast.cs | 64 +++---
src/Hyena.Gui/Hyena.Gui/DragDropList.cs | 10 +-
src/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs | 2 +-
src/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs | 4 +-
src/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs | 14 +-
src/Hyena.Gui/Hyena.Gui/GtkUtilities.cs | 36 ++--
src/Hyena.Gui/Hyena.Gui/GtkWorkarounds.cs | 30 +-
src/Hyena.Gui/Hyena.Gui/HyenaActionGroup.cs | 20 +-
src/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs | 24 +-
src/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs | 48 ++--
src/Hyena.Gui/Hyena.Gui/RatingRenderer.cs | 46 ++--
src/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs | 18 +-
src/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs | 6 +-
src/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs | 22 +-
src/Hyena.Gui/Hyena.Gui/TooltipSetter.cs | 18 +-
.../Hyena.Query.Gui/FileSizeQueryValueEntry.cs | 2 +-
.../Hyena.Query.Gui/IntegerQueryValueEntry.cs | 2 +-
src/Hyena.Gui/Hyena.Query.Gui/QueryBox.cs | 12 +-
src/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs | 28 +-
src/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs | 10 +-
src/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs | 18 +-
src/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs | 8 +-
.../Hyena.Query.Gui/StringQueryValueEntry.cs | 2 +-
.../Hyena.Query.Gui/TimeSpanQueryValueEntry.cs | 2 +-
src/Hyena.Gui/Hyena.Widgets/AccordionPane.cs | 24 +-
src/Hyena.Gui/Hyena.Widgets/AnimatedBox.cs | 162 ++++++------
src/Hyena.Gui/Hyena.Widgets/AnimatedImage.cs | 50 ++--
src/Hyena.Gui/Hyena.Widgets/AnimatedWidget.cs | 42 ++--
src/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs | 30 +-
src/Hyena.Gui/Hyena.Widgets/GenericToolItem.cs | 4 +-
src/Hyena.Gui/Hyena.Widgets/HigMessageDialog.cs | 24 +-
src/Hyena.Gui/Hyena.Widgets/ImageButton.cs | 2 +-
src/Hyena.Gui/Hyena.Widgets/MenuButton.cs | 42 ++--
src/Hyena.Gui/Hyena.Widgets/MessageBar.cs | 58 ++--
src/Hyena.Gui/Hyena.Widgets/PulsingButton.cs | 36 ++--
src/Hyena.Gui/Hyena.Widgets/RatingEntry.cs | 122 +++++-----
src/Hyena.Gui/Hyena.Widgets/RatingMenuItem.cs | 20 +-
src/Hyena.Gui/Hyena.Widgets/RoundedFrame.cs | 52 ++--
src/Hyena.Gui/Hyena.Widgets/ScrolledWindow.cs | 32 ++--
src/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs | 278 ++++++++++----------
.../Hyena.Widgets/SmoothScrolledWindow.cs | 30 +-
src/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs | 48 ++--
src/Hyena.Gui/Hyena.Widgets/WrapLabel.cs | 42 ++--
.../Hyena.Collections/CollectionExtensions.cs | 20 +-
src/Hyena/Hyena.Collections/IntervalHeap.cs | 145 +++++-----
src/Hyena/Hyena.Collections/LruCache.cs | 32 ++--
src/Hyena/Hyena.Collections/QueuePipeline.cs | 16 +-
.../Hyena.Collections/QueuePipelineElement.cs | 54 ++--
src/Hyena/Hyena.Collections/RangeCollection.cs | 104 ++++----
src/Hyena/Hyena.Collections/Selection.cs | 48 ++--
.../Hyena.Collections/Tests/IntervalHeapTests.cs | 10 +-
.../Hyena.Collections/Tests/QueuePipelineTests.cs | 10 +-
.../Tests/RangeCollectionTests.cs | 148 ++++++------
src/Hyena/Hyena.Collections/WriteLineElement.cs | 2 +-
src/Hyena/Hyena.CommandLine/CommandLineParser.cs | 50 ++--
src/Hyena/Hyena.CommandLine/Layout.cs | 64 +++---
src/Hyena/Hyena.CommandLine/LayoutGroup.cs | 34 ++--
src/Hyena/Hyena.CommandLine/LayoutOption.cs | 12 +-
src/Hyena/Hyena.Data/BaseListModel.cs | 12 +-
src/Hyena/Hyena.Data/ColumnDescription.cs | 20 +-
src/Hyena/Hyena.Data/IListModel.cs | 8 +-
src/Hyena/Hyena.Data/IPropertyStoreExpose.cs | 4 +-
src/Hyena/Hyena.Data/ModelCache.cs | 8 +-
src/Hyena/Hyena.Data/PropertyStore.cs | 62 +++---
src/Hyena/Hyena.Jobs/Job.cs | 4 +-
src/Hyena/Hyena.Jobs/Scheduler.cs | 2 +-
src/Hyena/Hyena.Jobs/Tests/SchedulerTests.cs | 2 +-
src/Hyena/Hyena.Json/Deserializer.cs | 52 ++--
src/Hyena/Hyena.Json/IJsonCollection.cs | 2 +-
src/Hyena/Hyena.Json/JsonArray.cs | 6 +-
src/Hyena/Hyena.Json/JsonObject.cs | 6 +-
src/Hyena/Hyena.Json/Tests/DeserializerTests.cs | 18 +-
src/Hyena/Hyena.Json/Tests/TokenizerTests.cs | 66 +++---
src/Hyena/Hyena.Json/Token.cs | 30 +-
src/Hyena/Hyena.Json/TokenType.cs | 4 +-
src/Hyena/Hyena.Json/Tokenizer.cs | 78 +++---
src/Hyena/Hyena.Query/FileSizeQueryValue.cs | 6 +-
.../Hyena.Query/IntegerKeyedObjectQueryValue.cs | 4 +-
src/Hyena/Hyena.Query/IntegerQueryValue.cs | 2 +-
src/Hyena/Hyena.Query/NullQueryValue.cs | 4 +-
src/Hyena/Hyena.Query/QueryField.cs | 4 +-
src/Hyena/Hyena.Query/QueryListNode.cs | 34 ++--
src/Hyena/Hyena.Query/QueryNode.cs | 26 +-
src/Hyena/Hyena.Query/QueryOperator.cs | 2 +-
src/Hyena/Hyena.Query/QueryParser.cs | 4 +-
src/Hyena/Hyena.Query/QueryTermNode.cs | 8 +-
src/Hyena/Hyena.Query/QueryToken.cs | 2 +-
src/Hyena/Hyena.Query/QueryValue.cs | 2 +-
.../Hyena.Query/RelativeTimeSpanQueryValue.cs | 2 +-
src/Hyena/Hyena.Query/StringQueryValue.cs | 2 +-
src/Hyena/Hyena.Query/Tests/QueryTests.cs | 28 +-
src/Hyena/Hyena.Query/UserQueryParser.cs | 24 +-
.../Hyena.SExpEngine/ArithmeticFunctionSet.cs | 44 ++--
src/Hyena/Hyena.SExpEngine/CastFunctionSet.cs | 20 +-
src/Hyena/Hyena.SExpEngine/CompareFunctionSet.cs | 22 +-
src/Hyena/Hyena.SExpEngine/ControlFunctionSet.cs | 32 ++--
src/Hyena/Hyena.SExpEngine/Evaluator.cs | 6 +-
src/Hyena/Hyena.SExpEngine/EvaluatorBase.cs | 110 ++++----
src/Hyena/Hyena.SExpEngine/FunctionFunctionSet.cs | 26 +-
src/Hyena/Hyena.SExpEngine/FunctionNode.cs | 26 +-
src/Hyena/Hyena.SExpEngine/FunctionSet.cs | 24 +-
src/Hyena/Hyena.SExpEngine/ListFunctionSet.cs | 70 +++---
src/Hyena/Hyena.SExpEngine/Literals.cs | 20 +-
src/Hyena/Hyena.SExpEngine/LogicFunctionSet.cs | 24 +-
src/Hyena/Hyena.SExpEngine/Parser.cs | 68 +++---
src/Hyena/Hyena.SExpEngine/StringFunctionSet.cs | 52 ++--
src/Hyena/Hyena.SExpEngine/TreeNode.cs | 40 ++--
src/Hyena/Hyena.SExpEngine/UtilityFunctionSet.cs | 18 +-
src/Hyena/Hyena/ApplicationContext.cs | 26 +-
src/Hyena/Hyena/ConsoleCrayon.cs | 14 +-
src/Hyena/Hyena/CryptoUtil.cs | 4 +-
src/Hyena/Hyena/DateTimeUtil.cs | 6 +-
src/Hyena/Hyena/Log.cs | 154 ++++++------
src/Hyena/Hyena/PlatformUtil.cs | 2 +-
src/Hyena/Hyena/StringUtil.cs | 58 ++--
src/Hyena/Hyena/Tests/CryptoUtilTests.cs | 2 +-
src/Hyena/Hyena/Tests/StringUtilTests.cs | 62 +++---
src/Hyena/Hyena/Tests/TestBase.cs | 18 +-
src/Hyena/Hyena/ThreadAssist.cs | 16 +-
src/Hyena/Hyena/Timer.cs | 4 +-
src/Hyena/Hyena/UndoManager.cs | 4 +-
src/Hyena/Hyena/XdgBaseDirectorySpec.cs | 4 +-
171 files changed, 2990 insertions(+), 2991 deletions(-)
---
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumn.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumn.cs
index 37c9bd9..e37bbbc 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumn.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumn.cs
@@ -40,13 +40,13 @@ namespace Hyena.Data.Sqlite
private readonly Type type;
private readonly string column_type;
private readonly string name;
-
+
protected AbstractDatabaseColumn (FieldInfo field_info, AbstractDatabaseColumnAttribute attribute)
: this (attribute, field_info, field_info.FieldType)
{
this.field_info = field_info;
}
-
+
protected AbstractDatabaseColumn (PropertyInfo property_info, AbstractDatabaseColumnAttribute attribute) :
this (attribute, property_info, property_info.PropertyType)
{
@@ -60,7 +60,7 @@ namespace Hyena.Data.Sqlite
}
this.property_info = property_info;
}
-
+
private AbstractDatabaseColumn (AbstractDatabaseColumnAttribute attribute, MemberInfo member_info, Type type)
{
try {
@@ -77,7 +77,7 @@ namespace Hyena.Data.Sqlite
{
return field_info != null ? field_info.GetValue (target) : property_info.GetValue (target, null);
}
-
+
public object GetValue (object target)
{
object result = field_info != null
@@ -85,14 +85,14 @@ namespace Hyena.Data.Sqlite
: property_info.GetValue (target, null);
return SqliteUtils.ToDbFormat (type, result);
}
-
+
public void SetValue (object target, IDataReader reader, int column)
{
// FIXME should we insist on nullable types?
object value = reader.IsDBNull (column) ? null : reader.GetValue (column);
SetValue (target, SqliteUtils.FromDbFormat(type, value));
}
-
+
public void SetValue (object target, object value)
{
if (field_info != null) {
@@ -101,97 +101,97 @@ namespace Hyena.Data.Sqlite
property_info.SetValue (target, value, null);
}
}
-
+
public string Name {
get { return name; }
}
-
+
public string Type {
get { return column_type; }
}
}
-
+
public sealed class DatabaseColumn : AbstractDatabaseColumn
{
private DatabaseColumnAttribute attribute;
-
+
public DatabaseColumn (FieldInfo field_info, DatabaseColumnAttribute attribute)
: base (field_info, attribute)
{
this.attribute = attribute;
}
-
+
public DatabaseColumn (PropertyInfo property_info, DatabaseColumnAttribute attribute)
: base (property_info, attribute)
{
this.attribute = attribute;
}
-
+
public DatabaseColumnConstraints Constraints {
get { return attribute.Constraints; }
}
-
+
public string DefaultValue {
get { return attribute.DefaultValue; }
}
-
+
public string Index {
get { return attribute.Index; }
}
-
+
public string Schema {
get {
return SqliteUtils.BuildColumnSchema (Type, Name, attribute.DefaultValue, attribute.Constraints);
}
}
-
+
public override bool Equals (object o)
{
DatabaseColumn column = o as DatabaseColumn;
return o != null && column.Name.Equals (Name);
}
-
+
public override int GetHashCode ()
{
return Name.GetHashCode ();
}
}
-
+
internal sealed class VirtualDatabaseColumn : AbstractDatabaseColumn
{
private VirtualDatabaseColumnAttribute attribute;
-
+
public VirtualDatabaseColumn (FieldInfo field_info, VirtualDatabaseColumnAttribute attribute)
: base (field_info, attribute)
{
this.attribute = attribute;
}
-
+
public VirtualDatabaseColumn (PropertyInfo property_info, VirtualDatabaseColumnAttribute attribute)
: base (property_info, attribute)
{
this.attribute = attribute;
}
-
+
public string TargetTable {
get { return attribute.TargetTable; }
}
-
+
public string LocalKey {
get { return attribute.LocalKey; }
}
-
+
public string ForeignKey {
get { return attribute.ForeignKey; }
}
}
-
+
public struct DbColumn
{
public readonly string Name;
public readonly DatabaseColumnConstraints Constraints;
public readonly string DefaultValue;
-
+
public DbColumn(string name, DatabaseColumnConstraints constraints, string default_value)
{
Name = name;
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs
index cd70129..dc022ed 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs
@@ -41,21 +41,21 @@ namespace Hyena.Data.Sqlite
PrimaryKey = 2,
Unique = 4
}
-
+
public abstract class AbstractDatabaseColumnAttribute : Attribute
{
private string column_name;
private bool select = true;
-
+
public AbstractDatabaseColumnAttribute ()
{
}
-
+
public AbstractDatabaseColumnAttribute (string column_name)
{
this.column_name = column_name;
}
-
+
public string ColumnName {
get { return column_name; }
}
@@ -65,45 +65,45 @@ namespace Hyena.Data.Sqlite
set { select = value; }
}
}
-
+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class DatabaseColumnAttribute : AbstractDatabaseColumnAttribute
{
private DatabaseColumnConstraints contraints;
private string default_value;
private string index;
-
+
public DatabaseColumnAttribute ()
{
}
-
+
public DatabaseColumnAttribute (string column_name) : base (column_name)
{
}
-
+
public DatabaseColumnConstraints Constraints {
get { return contraints; }
set { contraints = value; }
}
-
+
public string DefaultValue {
get { return default_value; }
set { default_value = value; }
}
-
+
public string Index {
get { return index; }
set { index = value; }
}
}
-
+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class VirtualDatabaseColumnAttribute : AbstractDatabaseColumnAttribute
{
private string target_table;
private string local_key;
private string foreign_key;
-
+
public VirtualDatabaseColumnAttribute (string column_name, string target_table, string local_key, string foreign_key)
: base (column_name)
{
@@ -111,15 +111,15 @@ namespace Hyena.Data.Sqlite
this.local_key = local_key;
this.foreign_key = foreign_key;
}
-
+
public string TargetTable {
get { return target_table; }
}
-
+
public string LocalKey {
get { return local_key; }
}
-
+
public string ForeignKey {
get { return foreign_key; }
}
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
index 53fc49e..be45a9e 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
@@ -45,13 +45,13 @@ namespace Hyena.Data.Sqlite
StackTrace = stackTrace;
Ms = ms;
}
-
+
public string Sql;
public string SqlWithValues;
public string StackTrace;
public long Ms;
}
-
+
public class HyenaSqliteCommand
{
private object result = null;
@@ -73,7 +73,7 @@ namespace Hyena.Data.Sqlite
get { return log_all; }
set { log_all = value; }
}
-
+
public delegate void CommandExecutedHandler (object o, CommandExecutedArgs args);
public static event CommandExecutedHandler CommandExecuted;
@@ -160,7 +160,7 @@ namespace Hyena.Data.Sqlite
}
object ret = result;
-
+
// Reset to false in case run again
finished = false;
@@ -170,7 +170,7 @@ namespace Hyena.Data.Sqlite
if (execution_exception != null) {
throw execution_exception;
}
-
+
return ret;
}
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteConnection.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
index e3c059d..cad33e5 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
@@ -26,7 +26,7 @@
// 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 System.Data;
using System.Threading;
@@ -43,12 +43,12 @@ namespace Hyena.Data.Sqlite
public IDataReader Reader {
get { return reader; }
}
-
+
public HyenaDataReader (IDataReader reader)
{
this.reader = reader;
}
-
+
public T Get<T> (int i)
{
if (!read) {
@@ -56,20 +56,20 @@ namespace Hyena.Data.Sqlite
}
return (T) SqliteUtils.FromDbFormat (typeof(T), reader[i]);
}
-
+
public bool Read ()
{
read = true;
return reader.Read ();
}
-
+
public void Dispose ()
{
reader.Dispose ();
reader = null;
}
}
-
+
public class ExecutingEventArgs : EventArgs
{
public readonly SqliteCommand Command;
@@ -78,7 +78,7 @@ namespace Hyena.Data.Sqlite
Command = command;
}
}
-
+
public enum HyenaCommandType {
Reader,
Scalar,
@@ -114,9 +114,9 @@ namespace Hyena.Data.Sqlite
internal ManualResetEvent ResultReadySignal {
get { return result_ready_signal; }
}
-
+
public event EventHandler<ExecutingEventArgs> Executing;
-
+
public HyenaSqliteConnection(string dbpath)
{
this.dbpath = dbpath;
@@ -129,7 +129,7 @@ namespace Hyena.Data.Sqlite
#region Public Query Methods
// TODO special case for single object param to avoid object []
-
+
// SELECT multiple column queries
public IDataReader Query (HyenaSqliteCommand command)
{
@@ -149,7 +149,7 @@ namespace Hyena.Data.Sqlite
{
return Query (new HyenaSqliteCommand (command_str, param_values));
}
-
+
public IDataReader Query (object command)
{
return Query (new HyenaSqliteCommand (command.ToString ()));
@@ -180,7 +180,7 @@ namespace Hyena.Data.Sqlite
{
return QueryEnumerable<T> (new HyenaSqliteCommand (command_str, param_values));
}
-
+
public IEnumerable<T> QueryEnumerable<T> (object command)
{
return QueryEnumerable<T> (new HyenaSqliteCommand (command.ToString ()));
@@ -241,7 +241,7 @@ namespace Hyena.Data.Sqlite
#endregion
#region Public Utility Methods
-
+
public void BeginTransaction ()
{
if (transaction_thread == Thread.CurrentThread) {
@@ -276,7 +276,7 @@ namespace Hyena.Data.Sqlite
lock (command_queue) {
transaction_thread = null;
// Let any other threads continue
- transaction_signal.Set ();
+ transaction_signal.Set ();
}
}
@@ -290,9 +290,9 @@ namespace Hyena.Data.Sqlite
lock (command_queue) {
transaction_thread = null;
-
+
// Let any other threads continue
- transaction_signal.Set ();
+ transaction_signal.Set ();
}
}
@@ -300,17 +300,17 @@ namespace Hyena.Data.Sqlite
{
return Exists ("table", tableName);
}
-
+
public bool IndexExists (string indexName)
{
return Exists ("index", indexName);
}
-
+
private bool Exists (string type, string name)
{
return Exists (type, name, "sqlite_master") || Exists (type, name, "sqlite_temp_master");
}
-
+
private bool Exists (string type, string name, string master)
{
return Query<int> (String.Format (
@@ -320,7 +320,7 @@ namespace Hyena.Data.Sqlite
}
private delegate void SchemaHandler (string column);
-
+
private void SchemaClosure (string table_name, SchemaHandler code)
{
string sql = Query<string> (String.Format (
@@ -335,7 +335,7 @@ namespace Hyena.Data.Sqlite
code (column_def_t.Substring (0, ws_index));
}
}
-
+
public bool ColumnExists (string tableName, string columnName)
{
bool value = false;
@@ -347,7 +347,7 @@ namespace Hyena.Data.Sqlite
});
return value;
}
-
+
private static readonly char [] ws_chars = new char [] { ' ', '\t', '\n', '\r' };
public IDictionary<string, string> GetSchema (string table_name)
{
@@ -410,12 +410,12 @@ namespace Hyena.Data.Sqlite
}
private void ProcessQueue()
- {
+ {
if (connection == null) {
connection = new SqliteConnection (String.Format ("Version=3,URI=file:{0}", dbpath));
connection.Open ();
}
-
+
// Keep handling queries
while (!dispose_requested) {
while (command_queue.Count > 0) {
@@ -453,7 +453,7 @@ namespace Hyena.Data.Sqlite
// Finish
connection.Close ();
}
-
+
internal void OnExecuting (SqliteCommand command)
{
EventHandler<ExecutingEventArgs> handler = Executing;
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelCache.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelCache.cs
index 9698461..c4a8344 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelCache.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelCache.cs
@@ -65,7 +65,7 @@ namespace Hyena.Data.Sqlite
this.connection = connection;
this.model = model;
this.provider = provider;
-
+
CheckCacheTable ();
if (model.SelectAggregates != null) {
@@ -126,7 +126,7 @@ namespace Hyena.Data.Sqlite
@"SELECT OrderID, ItemID FROM {0} WHERE {0}.ModelID = {1}",
CacheTableName, uid
);
-
+
reload_sql = String.Format (@"
DELETE FROM {0} WHERE ModelID = {1};
INSERT INTO {0} (ModelID, ItemID) SELECT DISTINCT {1}, {2} ",
@@ -135,7 +135,7 @@ namespace Hyena.Data.Sqlite
} else {
select_str = String.Format (
@"SELECT {0}, {2}.ItemID FROM {1}
- INNER JOIN {2}
+ INNER JOIN {2}
ON {3} = {2}.ItemID
WHERE
{2}.ModelID = {4} {5} {6}",
@@ -177,7 +177,7 @@ namespace Hyena.Data.Sqlite
delete_selection_command = new HyenaSqliteCommand (String.Format (
"DELETE FROM {0} WHERE ModelID = {1}", CacheTableName, selection_uid
));
-
+
save_selection_command = new HyenaSqliteCommand (String.Format (
"INSERT INTO {0} (ModelID, ItemID) SELECT {1}, ItemID FROM {0} WHERE ModelID = {2} LIMIT ?, ?",
CacheTableName, selection_uid, uid
@@ -212,7 +212,7 @@ namespace Hyena.Data.Sqlite
protected virtual string CacheModelsTableName {
get { return "HyenaCacheModels"; }
}
-
+
protected virtual string CacheTableName {
get { return "HyenaCache"; }
}
@@ -227,13 +227,13 @@ namespace Hyena.Data.Sqlite
}
}
}
-
+
public long IndexOf (ICacheableItem item)
{
if (item == null || item.CacheModelId != CacheId) {
return -1;
}
-
+
return IndexOf (item.CacheEntryId);
}
@@ -309,7 +309,7 @@ namespace Hyena.Data.Sqlite
{
connection.Execute (delete_selection_command);
saved_selection = true;
-
+
if (!has_select_all_item && model.Selection.FocusedIndex != -1) {
T item = GetValue (model.Selection.FocusedIndex);
if (item != null) {
@@ -384,7 +384,7 @@ namespace Hyena.Data.Sqlite
}
}
}
-
+
public void UpdateAggregates ()
{
using (IDataReader reader = connection.Query (count_command, uid)) {
@@ -398,7 +398,7 @@ namespace Hyena.Data.Sqlite
}
}
}
-
+
private long FindOrCreateCacheModelId (string id)
{
long model_id = connection.Query<long> (String.Format (
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs
index 2e9c09d..15beb74 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs
@@ -39,12 +39,12 @@ namespace Hyena.Data.Sqlite
private readonly List<DatabaseColumn> columns = new List<DatabaseColumn> ();
private readonly List<DatabaseColumn> select_columns = new List<DatabaseColumn> ();
private readonly List<VirtualDatabaseColumn> virtual_columns = new List<VirtualDatabaseColumn> ();
-
+
private DatabaseColumn key;
private int key_select_column_index;
private HyenaSqliteConnection connection;
private bool check_table = true;
-
+
private HyenaSqliteCommand create_command;
private HyenaSqliteCommand insert_command;
private HyenaSqliteCommand update_command;
@@ -52,13 +52,13 @@ namespace Hyena.Data.Sqlite
private HyenaSqliteCommand select_command;
private HyenaSqliteCommand select_range_command;
private HyenaSqliteCommand select_single_command;
-
+
private string table_name;
private string primary_key;
private string select;
private string from;
private string where;
-
+
private const string HYENA_DATABASE_NAME = "hyena_database_master";
public virtual string TableName { get { return table_name; } }
@@ -79,11 +79,11 @@ namespace Hyena.Data.Sqlite
{
return new T ();
}
-
+
protected virtual string HyenaTableName {
get { return "HyenaModelVersions"; }
}
-
+
public HyenaSqliteConnection Connection {
get { return connection; }
}
@@ -96,7 +96,7 @@ namespace Hyena.Data.Sqlite
public SqliteModelProvider (HyenaSqliteConnection connection, string table_name) : this (connection, table_name, true)
{
}
-
+
public SqliteModelProvider (HyenaSqliteConnection connection, string table_name, bool checkTable) : this (connection)
{
this.table_name = table_name;
@@ -129,15 +129,15 @@ namespace Hyena.Data.Sqlite
if (key == null) {
throw new Exception (String.Format ("The {0} table does not have a primary key", TableName));
}
-
+
key_select_column_index = select_columns.IndexOf (key);
-
+
if (check_table) {
CheckVersion ();
CheckTable ();
}
}
-
+
protected virtual void CheckVersion ()
{
if (connection.TableExists (HyenaTableName)) {
@@ -166,33 +166,33 @@ namespace Hyena.Data.Sqlite
version INTEGER)",
HyenaTableName)
);
-
+
InsertVersion (HYENA_DATABASE_NAME, DatabaseVersion);
InsertVersion (TableName, ModelVersion);
}
}
-
+
private string SelectVersionSql (string name)
{
return String.Format (
"SELECT version FROM {0} WHERE name='{1}'",
HyenaTableName, name);
}
-
+
private void UpdateVersion (string name, int version)
{
connection.Execute (String.Format (
"UPDATE {0} SET version={1} WHERE name='{2}'",
HyenaTableName, version, name));
}
-
+
private void InsertVersion (string name, int version)
{
connection.Execute (String.Format (
"INSERT INTO {0} (name, version) VALUES ('{1}', {2})",
HyenaTableName, name, version));
}
-
+
protected void CheckTable ()
{
//Console.WriteLine ("In {0} checking for table {1}", this, TableName);
@@ -213,7 +213,7 @@ namespace Hyena.Data.Sqlite
CreateTable ();
}
}
-
+
private void AddColumn (MemberInfo member, Attribute attribute)
{
DatabaseColumnAttribute column = attribute as DatabaseColumnAttribute;
@@ -221,7 +221,7 @@ namespace Hyena.Data.Sqlite
DatabaseColumn c = member is FieldInfo
? new DatabaseColumn ((FieldInfo)member, column)
: new DatabaseColumn ((PropertyInfo)member, column);
-
+
AddColumn (c, column.Select);
}
VirtualDatabaseColumnAttribute virtual_column = attribute as VirtualDatabaseColumnAttribute;
@@ -233,7 +233,7 @@ namespace Hyena.Data.Sqlite
}
}
}
-
+
protected void AddColumn (DatabaseColumn c, bool select)
{
foreach (DatabaseColumn col in columns) {
@@ -250,13 +250,13 @@ namespace Hyena.Data.Sqlite
);
}
}
-
+
columns.Add (c);
if (select) {
select_columns.Add (c);
}
-
+
if ((c.Constraints & DatabaseColumnConstraints.PrimaryKey) > 0) {
if (key != null) {
throw new Exception (String.Format (
@@ -266,7 +266,7 @@ namespace Hyena.Data.Sqlite
key = c;
}
}
-
+
protected virtual void CreateTable ()
{
connection.Execute (CreateCommand);
@@ -279,7 +279,7 @@ namespace Hyena.Data.Sqlite
}
}
}
-
+
protected void CreateIndex (string name, string columns)
{
Connection.Execute (String.Format (
@@ -287,7 +287,7 @@ namespace Hyena.Data.Sqlite
name, TableName, columns
));
}
-
+
public virtual void Save (T target)
{
try {
@@ -297,12 +297,12 @@ namespace Hyena.Data.Sqlite
key.SetValue (target, Insert (target));
}
} catch (Exception e) {
- Hyena.Log.Exception (e);
+ Hyena.Log.Exception (e);
Hyena.Log.DebugFormat ("type of key value: {0}", key.GetRawValue (target).GetType ());
throw;
}
}
-
+
protected virtual object [] GetInsertParams (T target)
{
// TODO create an instance variable object array and reuse it? beware threading issues
@@ -316,7 +316,7 @@ namespace Hyena.Data.Sqlite
}
return values;
}
-
+
protected int Insert (T target)
{
return connection.Execute (InsertCommand, GetInsertParams (target));
@@ -336,30 +336,30 @@ namespace Hyena.Data.Sqlite
values[j] = key.GetValue (target);
return values;
}
-
+
protected void Update (T target)
{
connection.Execute (UpdateCommand, GetUpdateParams (target));
}
-
+
public virtual T Load (IDataReader reader)
{
T item = MakeNewObject ();
Load (reader, item);
return item;
}
-
+
public void Load (IDataReader reader, T target)
{
int i = 0;
-
+
AbstractDatabaseColumn bad_column = null;
try {
foreach (DatabaseColumn column in select_columns) {
bad_column = column;
column.SetValue (target, reader, i++);
}
-
+
foreach (VirtualDatabaseColumn column in virtual_columns) {
bad_column = column;
column.SetValue (target, reader, i++);
@@ -371,7 +371,7 @@ namespace Hyena.Data.Sqlite
);
}
}
-
+
public IEnumerable<T> FetchAll ()
{
using (IDataReader reader = connection.Query (SelectCommand)) {
@@ -388,7 +388,7 @@ namespace Hyena.Data.Sqlite
}
return default(T);
}
-
+
public IEnumerable<T> FetchAllMatching (string condition, params object [] vals)
{
HyenaSqliteCommand fetch_matching_command = CreateFetchCommand (condition);
@@ -403,7 +403,7 @@ namespace Hyena.Data.Sqlite
{
return new HyenaSqliteCommand (String.Format ("{0} AND {1}", SelectCommand.Text, condition));
}
-
+
public IEnumerable<T> FetchRange (int offset, int limit)
{
using (IDataReader reader = connection.Query (SelectRangeCommand, offset, limit)) {
@@ -412,12 +412,12 @@ namespace Hyena.Data.Sqlite
}
}
}
-
+
public T FetchSingle (int id)
{
return FetchSingle ((long) id);
}
-
+
public virtual T FetchSingle (long id)
{
using (IDataReader reader = connection.Query (SelectSingleCommand, id)) {
@@ -427,28 +427,28 @@ namespace Hyena.Data.Sqlite
}
return default(T);
}
-
+
protected long PrimaryKeyFor (T item)
{
return Convert.ToInt64 (key.GetValue (item));
}
-
+
protected long PrimaryKeyFor (IDataReader reader)
{
return Convert.ToInt64 (reader[key_select_column_index]);
}
-
+
public virtual void Delete (long id)
{
if (id > 0)
connection.Execute (DeleteCommand, id);
}
-
+
public void Delete (T item)
{
Delete (PrimaryKeyFor (item));
}
-
+
public virtual void Delete (IEnumerable<T> items)
{
List<long> ids = new List<long> ();
@@ -458,7 +458,7 @@ namespace Hyena.Data.Sqlite
if (id > 0)
ids.Add (id);
}
-
+
if (ids.Count > 0)
connection.Execute (DeleteCommand, ids.ToArray ());
}
@@ -489,7 +489,7 @@ namespace Hyena.Data.Sqlite
}
}
}
-
+
protected virtual HyenaSqliteCommand CreateCommand {
get {
if (create_command == null) {
@@ -512,7 +512,7 @@ namespace Hyena.Data.Sqlite
return create_command;
}
}
-
+
protected virtual HyenaSqliteCommand InsertCommand {
get {
// FIXME can this string building be done more nicely?
@@ -541,7 +541,7 @@ namespace Hyena.Data.Sqlite
return insert_command;
}
}
-
+
protected virtual HyenaSqliteCommand UpdateCommand {
get {
if (update_command == null) {
@@ -569,7 +569,7 @@ namespace Hyena.Data.Sqlite
return update_command;
}
}
-
+
protected virtual HyenaSqliteCommand SelectCommand {
get {
if (select_command == null) {
@@ -583,7 +583,7 @@ namespace Hyena.Data.Sqlite
return select_command;
}
}
-
+
protected virtual HyenaSqliteCommand SelectRangeCommand {
get {
if (select_range_command == null) {
@@ -599,7 +599,7 @@ namespace Hyena.Data.Sqlite
return select_range_command;
}
}
-
+
protected virtual HyenaSqliteCommand SelectSingleCommand {
get {
if (select_single_command == null) {
@@ -615,7 +615,7 @@ namespace Hyena.Data.Sqlite
return select_single_command;
}
}
-
+
protected virtual HyenaSqliteCommand DeleteCommand {
get {
if (delete_command == null) {
@@ -626,7 +626,7 @@ namespace Hyena.Data.Sqlite
return delete_command;
}
}
-
+
public virtual string Select {
get {
if (select == null) {
@@ -635,7 +635,7 @@ namespace Hyena.Data.Sqlite
return select;
}
}
-
+
public virtual string From {
get {
if (from == null) {
@@ -644,7 +644,7 @@ namespace Hyena.Data.Sqlite
return from;
}
}
-
+
public virtual string Where {
get {
if (where == null) {
@@ -653,7 +653,7 @@ namespace Hyena.Data.Sqlite
return where;
}
}
-
+
public string PrimaryKey {
get {
if (primary_key == null) {
@@ -663,7 +663,7 @@ namespace Hyena.Data.Sqlite
}
protected set { primary_key = value; }
}
-
+
private void BuildQuerySql ()
{
StringBuilder select_builder = new StringBuilder ();
@@ -678,7 +678,7 @@ namespace Hyena.Data.Sqlite
select_builder.Append ('.');
select_builder.Append (column.Name);
}
-
+
StringBuilder where_builder = new StringBuilder ();
Dictionary<string, string> tables = new Dictionary<string,string> (virtual_columns.Count + 1);
bool first_virtual = true;
@@ -699,7 +699,7 @@ namespace Hyena.Data.Sqlite
} else if (table_not_joined) {
where_builder.Append (" AND ");
}
-
+
if (table_not_joined) {
where_builder.Append (column.TargetTable);
where_builder.Append ('.');
@@ -708,11 +708,11 @@ namespace Hyena.Data.Sqlite
where_builder.Append (TableName);
where_builder.Append ('.');
where_builder.Append (column.LocalKey);
-
+
tables.Add (column.TargetTable, null);
}
}
-
+
StringBuilder from_builder = new StringBuilder ();
from_builder.Append (TableName);
foreach (KeyValuePair<string, string> pair in tables) {
@@ -724,27 +724,27 @@ namespace Hyena.Data.Sqlite
from = from_builder.ToString ();
where = where_builder.ToString ();
}
-
+
public U GetProperty <U> (T item, DbColumn column)
{
CheckProperty (typeof (U), column);
-
+
return connection.Query<U> (String.Format (
"SELECT {0} FROM {1} WHERE {2}={3}",
column.Name, TableName, key.Name, key.GetValue (item)));
}
-
+
public void SetProperty <U> (T item, U value, DbColumn column)
{
CheckProperty (typeof (U), column);
-
+
connection.Execute (String.Format (
"UPDATE {0} SET {1}='{2}' WHERE {3}={4}",
TableName, column.Name,
SqliteUtils.ToDbFormat (typeof (U), value),
key.Name, key.GetValue (item)));
}
-
+
public void ClearProperty <U> (DbColumn column)
{
if (!connection.ColumnExists (TableName, column.Name)) {
@@ -757,7 +757,7 @@ namespace Hyena.Data.Sqlite
TableName, column.Name, column.DefaultValue));
}
}
-
+
private void CheckProperty (Type type, DbColumn column)
{
if (!connection.ColumnExists (TableName, column.Name)) {
@@ -766,7 +766,7 @@ namespace Hyena.Data.Sqlite
column.Name, column.DefaultValue, column.Constraints));
}
}
-
+
private void AddColumnToTable (string column_schema)
{
connection.Execute (String.Format (
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteUtils.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteUtils.cs
index 9d89962..b0acfb7 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteUtils.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteUtils.cs
@@ -49,7 +49,7 @@ namespace Hyena.Data.Sqlite
"The type {0} cannot be bound to a database column.", type.Name));
}
}
-
+
public static object ToDbFormat (Type type, object value)
{
if (type == typeof (string)) {
@@ -70,15 +70,15 @@ namespace Hyena.Data.Sqlite
} else if (type == typeof (bool)) {
return ((bool)value) ? 1 : 0;
}
-
+
return value;
}
-
+
public static object FromDbFormat (Type type, object value)
{
if (Convert.IsDBNull (value))
value = null;
-
+
if (type == typeof (DateTime)) {
return value == null
? DateTime.MinValue
@@ -101,7 +101,7 @@ namespace Hyena.Data.Sqlite
return Convert.ChangeType (value, type);
}
}
-
+
public static string BuildColumnSchema (string type, string name, string default_value,
DatabaseColumnConstraints constraints)
{
@@ -125,7 +125,7 @@ namespace Hyena.Data.Sqlite
return builder.ToString ();
}
}
-
+
[SqliteFunction (Name = "HYENA_COLLATION_KEY", FuncType = FunctionType.Scalar, Arguments = 1)]
internal class CollationKeyFunction : SqliteFunction
{
@@ -134,7 +134,7 @@ namespace Hyena.Data.Sqlite
return Hyena.StringUtil.SortKey (args[0] as string);
}
}
-
+
[SqliteFunction (Name = "HYENA_SEARCH_KEY", FuncType = FunctionType.Scalar, Arguments = 1)]
internal class SearchKeyFunction : SqliteFunction
{
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/DbBoundType.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/DbBoundType.cs
index 181adf8..58b7dc6 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/DbBoundType.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/DbBoundType.cs
@@ -40,7 +40,7 @@ namespace Hyena.Data.Sqlite.Tests
Two,
Three
}
-
+
internal enum LongEnum : long
{
Cero,
@@ -48,14 +48,14 @@ namespace Hyena.Data.Sqlite.Tests
Dos,
Tres
}
-
+
internal class ModelProvider : SqliteModelProvider<DbBoundType>
{
public ModelProvider (HyenaSqliteConnection connection) : base (connection)
{
Init ();
}
-
+
public override string TableName {
get { return "TestTable"; }
}
@@ -65,7 +65,7 @@ namespace Hyena.Data.Sqlite.Tests
protected override int DatabaseVersion {
get { return 1; }
}
-
+
protected override void MigrateTable (int old_version)
{
}
@@ -77,12 +77,12 @@ namespace Hyena.Data.Sqlite.Tests
return new DbBoundType ();
}
}
-
+
internal class DbBoundType
{
[DatabaseColumn ("PrimaryKey", Constraints = DatabaseColumnConstraints.PrimaryKey)]
public int PrimaryKey;
-
+
[DatabaseColumn ("PublicIntField")]
public int PublicIntField;
[DatabaseColumn ("PublicLongField")]
@@ -97,7 +97,7 @@ namespace Hyena.Data.Sqlite.Tests
public IntEnum PublicIntEnumField;
[DatabaseColumn ("PublicLongEnumField")]
public LongEnum PublicLongEnumField;
-
+
private int public_int_property_field;
[DatabaseColumn ("PublicIntProperty")]
public int PublicIntProperty {
@@ -140,7 +140,7 @@ namespace Hyena.Data.Sqlite.Tests
get { return public_long_enum_property_field; }
set { public_long_enum_property_field = value; }
}
-
+
[DatabaseColumn ("PrivateIntField")]
private int private_int_field;
[DatabaseColumn ("PrivateLongField")]
@@ -155,7 +155,7 @@ namespace Hyena.Data.Sqlite.Tests
private IntEnum private_int_enum_field;
[DatabaseColumn ("PrivateLongEnumField")]
private LongEnum private_long_enum_field;
-
+
public int GetPrivateIntField ()
{
return private_int_field;
@@ -212,7 +212,7 @@ namespace Hyena.Data.Sqlite.Tests
{
private_long_enum_field = value;
}
-
+
private int private_int_property_field;
[DatabaseColumn ("PrivateIntProperty")]
private int private_int_property {
@@ -255,7 +255,7 @@ namespace Hyena.Data.Sqlite.Tests
get { return private_long_enum_property_field; }
set { private_long_enum_property_field = value; }
}
-
+
public int GetPrivateIntProperty ()
{
return private_int_property;
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteCommandTests.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteCommandTests.cs
index f847f1b..e212010 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteCommandTests.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteCommandTests.cs
@@ -47,36 +47,36 @@ namespace Hyena.Data.Sqlite.Tests
"a", 32);
Assert.Fail ("Should not have been able to pass 2 values to ApplyValues without exception");
} catch {}
-
+
try {
cmd = new HyenaSqliteCommand ("select foo from bar where baz = ?, bbz = ?, this = ?",
"a", 32, "22");
} catch {
Assert.Fail ("Should have been able to pass 3 values to ApplyValues without exception");
}
-
+
Assert.AreEqual ("select foo from bar where baz = 'a', bbz = 32, this = '22'", GetGeneratedSql (cmd));
}
-
+
[Test]
public void Constructor ()
{
HyenaSqliteCommand cmd = new HyenaSqliteCommand ("select foo from bar where baz = ?, bbz = ?, this = ?", "a", 32, "22");
Assert.AreEqual ("select foo from bar where baz = 'a', bbz = 32, this = '22'", GetGeneratedSql (cmd));
}
-
+
[Test]
public void CultureInvariant ()
{
HyenaSqliteCommand cmd = new HyenaSqliteCommand ("select foo from bar where baz = ?", 32.2);
Assert.AreEqual ("select foo from bar where baz = 32.2", GetGeneratedSql (cmd));
}
-
+
[Test]
public void ParameterSerialization ()
{
HyenaSqliteCommand cmd = new HyenaSqliteCommand ("select foo from bar where baz = ?");
-
+
Assert.AreEqual ("select foo from bar where baz = NULL", GetGeneratedSql (cmd, null));
Assert.AreEqual ("select foo from bar where baz = 'It''s complicated, \"but\" ''''why not''''?'", GetGeneratedSql (cmd, "It's complicated, \"but\" ''why not''?"));
Assert.AreEqual ("select foo from bar where baz = 0", GetGeneratedSql (cmd, new DateTime (1970, 1, 1).ToLocalTime ()));
@@ -86,10 +86,10 @@ namespace Hyena.Data.Sqlite.Tests
Assert.AreEqual ("select foo from bar where baz = 555", GetGeneratedSql (cmd, 555));
Assert.AreEqual ("select foo from bar where baz = 1", GetGeneratedSql (cmd, true));
Assert.AreEqual ("select foo from bar where baz = 0", GetGeneratedSql (cmd, false));
-
+
HyenaSqliteCommand cmd2 = new HyenaSqliteCommand ("select foo from bar where baz = ?, bar = ?, boo = ?");
Assert.AreEqual ("select foo from bar where baz = NULL, bar = NULL, boo = 22", GetGeneratedSql (cmd2, null, null, 22));
-
+
HyenaSqliteCommand cmd3 = new HyenaSqliteCommand ("select foo from bar where id in (?) and foo not in (?)");
Assert.AreEqual ("select foo from bar where id in (1,2,4) and foo not in ('foo','baz')",
GetGeneratedSql (cmd3, new int [] {1, 2, 4}, new string [] {"foo", "baz"}));
@@ -111,19 +111,19 @@ namespace Hyena.Data.Sqlite.Tests
Assert.IsTrue (disposed);
}
}
-
+
static PropertyInfo tf = typeof(HyenaSqliteCommand).GetProperty ("CurrentSqlText", BindingFlags.Instance | BindingFlags.NonPublic);
private static string GetGeneratedSql (HyenaSqliteCommand cmd, params object [] p)
{
return tf.GetValue ((new HyenaSqliteCommand (cmd.Text, p)), null) as string;
}
-
+
private static string GetGeneratedSql (HyenaSqliteCommand cmd)
{
return tf.GetValue (cmd, null) as string;
}
}
-
+
[TestFixture]
public class ObjectToSqlTests
{
@@ -131,20 +131,20 @@ namespace Hyena.Data.Sqlite.Tests
{
Assert.AreEqual (expected, HyenaSqliteCommand.SqlifyObject (o));
}
-
+
[Test]
public void TestNull ()
{
AssertToSql (null, "NULL");
}
-
+
[Test]
public void TestBool ()
{
AssertToSql (false, "0");
AssertToSql (true, "1");
}
-
+
[Test]
public void TestString ()
{
@@ -152,7 +152,7 @@ namespace Hyena.Data.Sqlite.Tests
AssertToSql ("test", "'test'");
AssertToSql ("te'st", "'te''st'");
}
-
+
[Test]
public void TestByteArray ()
{
@@ -160,7 +160,7 @@ namespace Hyena.Data.Sqlite.Tests
AssertToSql (new byte[] {}, "X''");
AssertToSql (new byte[] {0x10, 0x20, 0x30}, "X'102030'");
}
-
+
[Test]
public void TestOtherArray ()
{
@@ -168,13 +168,13 @@ namespace Hyena.Data.Sqlite.Tests
AssertToSql (new object[] {"a"}, "'a'");
AssertToSql (new object[] {"a", "b"}, "'a','b'");
}
-
+
[Test]
public void TestDateTime ()
{
// Returned using local time, not UTC
AssertToSql (new DateTime (2000, 1, 2), 946792800);
-
+
// Disregards milliseconds
AssertToSql (new DateTime (2000, 1, 2, 10, 9, 8, 7), 946829348);
}
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteModelProviderTests.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteModelProviderTests.cs
index 360dd39..7b12c5d 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteModelProviderTests.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteModelProviderTests.cs
@@ -41,21 +41,21 @@ namespace Hyena.Data.Sqlite.Tests
{
private HyenaSqliteConnection connection;
private ModelProvider provider;
-
+
[TestFixtureSetUp]
public void Init ()
{
connection = new HyenaSqliteConnection ("test.db");
provider = new ModelProvider (connection);
}
-
+
[TestFixtureTearDown]
public void Dispose ()
{
connection.Dispose ();
File.Delete ("test.db");
}
-
+
[Test]
public void IntMembers ()
{
@@ -64,16 +64,16 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicIntProperty = 13;
newed_item.SetPrivateIntField (128);
newed_item.SetPrivateIntProperty (42);
-
+
provider.Save (newed_item);
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (newed_item.PublicIntField, loaded_item.PublicIntField);
Assert.AreEqual (newed_item.PublicIntProperty, loaded_item.PublicIntProperty);
Assert.AreEqual (newed_item.GetPrivateIntField (), loaded_item.GetPrivateIntField ());
Assert.AreEqual (newed_item.GetPrivateIntProperty (), loaded_item.GetPrivateIntProperty ());
}
-
+
[Test]
public void LongMembers ()
{
@@ -82,16 +82,16 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicLongProperty = -932;
newed_item.SetPrivateLongField (3243);
newed_item.SetPrivateLongProperty (1);
-
+
provider.Save (newed_item);
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (newed_item.PublicLongField, loaded_item.PublicLongField);
Assert.AreEqual (newed_item.PublicLongProperty, loaded_item.PublicLongProperty);
Assert.AreEqual (newed_item.GetPrivateLongField (), loaded_item.GetPrivateLongField ());
Assert.AreEqual (newed_item.GetPrivateLongProperty (), loaded_item.GetPrivateLongProperty ());
}
-
+
[Test]
public void StringMembers ()
{
@@ -100,9 +100,9 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicStringProperty = "Even as a splitted bark, so sunder we: This way fall I to death.";
newed_item.SetPrivateStringField ("Who is John Galt?");
newed_item.SetPrivateStringProperty ("The most formidable weapon against errors of every kind is Reason.");
-
+
provider.Save (newed_item);
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (newed_item.PublicStringField, loaded_item.PublicStringField);
Assert.AreEqual (newed_item.PublicStringProperty, loaded_item.PublicStringProperty);
@@ -118,16 +118,16 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicStringProperty = null;
newed_item.SetPrivateStringField (" \t ");
newed_item.SetPrivateStringProperty (" foo ");
-
+
provider.Save (newed_item);
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (null, loaded_item.PublicStringField);
Assert.AreEqual (null, loaded_item.PublicStringProperty);
Assert.AreEqual (null, loaded_item.GetPrivateStringField ());
Assert.AreEqual (" foo ", loaded_item.GetPrivateStringProperty ());
}
-
+
[Test]
public void NullStringMembers ()
{
@@ -136,16 +136,16 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicStringProperty = null;
newed_item.SetPrivateStringField (null);
newed_item.SetPrivateStringProperty (null);
-
+
provider.Save (newed_item);
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (newed_item.PublicStringField, loaded_item.PublicStringField);
Assert.AreEqual (newed_item.PublicStringProperty, loaded_item.PublicStringProperty);
Assert.AreEqual (newed_item.GetPrivateStringField (), loaded_item.GetPrivateStringField ());
Assert.AreEqual (newed_item.GetPrivateStringProperty (), loaded_item.GetPrivateStringProperty ());
}
-
+
// Some fidelity is lost in the conversion from DT to DB time format
private void AssertArePrettyClose (DateTime time1, DateTime time2)
{
@@ -156,7 +156,7 @@ namespace Hyena.Data.Sqlite.Tests
Assert.AreEqual (time1.Minute, time2.Minute);
Assert.AreEqual (time1.Second, time2.Second);
}
-
+
[Test]
public void DateTimeMembers ()
{
@@ -165,23 +165,23 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicDateTimeProperty = new DateTime (1986, 4, 23);
newed_item.SetPrivateDateTimeField (DateTime.MinValue);
newed_item.SetPrivateDateTimeProperty (DateTime.Now);
-
+
provider.Save (newed_item);
-
+
string command = String.Format ("SELECT PrivateDateTimeField FROM {0} WHERE PrimaryKey = {1}", provider.TableName, newed_item.PrimaryKey);
-
+
using (IDataReader reader = connection.Query (command)) {
reader.Read ();
Assert.IsTrue (reader.IsDBNull (0));
}
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
AssertArePrettyClose (newed_item.PublicDateTimeField, loaded_item.PublicDateTimeField);
AssertArePrettyClose (newed_item.PublicDateTimeProperty, loaded_item.PublicDateTimeProperty);
AssertArePrettyClose (newed_item.GetPrivateDateTimeField (), loaded_item.GetPrivateDateTimeField ());
AssertArePrettyClose (newed_item.GetPrivateDateTimeProperty (), loaded_item.GetPrivateDateTimeProperty ());
}
-
+
[Test]
public void TimeSpanMembers ()
{
@@ -190,15 +190,15 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicTimeSpanProperty = new TimeSpan (1, 0, 0);
newed_item.SetPrivateTimeSpanField (new TimeSpan (1, 39, 12));
newed_item.SetPrivateTimeSpanProperty (TimeSpan.MinValue);
-
+
provider.Save (newed_item);
-
+
string command = String.Format ("SELECT PrivateTimeSpanProperty FROM {0} WHERE PrimaryKey = {1}", provider.TableName, newed_item.PrimaryKey);
using (IDataReader reader = connection.Query (command)) {
reader.Read ();
Assert.IsTrue (reader.IsDBNull (0));
}
-
+
// NUnit boxes and uses reference equality, rather than Equals()
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (newed_item.PublicTimeSpanField, loaded_item.PublicTimeSpanField);
@@ -206,7 +206,7 @@ namespace Hyena.Data.Sqlite.Tests
Assert.AreEqual (newed_item.GetPrivateTimeSpanField (), loaded_item.GetPrivateTimeSpanField ());
Assert.AreEqual (newed_item.GetPrivateTimeSpanProperty (), loaded_item.GetPrivateTimeSpanProperty ());
}
-
+
[Test]
public void IntEnumMembers ()
{
@@ -215,16 +215,16 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicIntEnumProperty = IntEnum.One;
newed_item.SetPrivateIntEnumField (IntEnum.Two);
newed_item.SetPrivateIntEnumProperty (IntEnum.Three);
-
+
provider.Save (newed_item);
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (newed_item.PublicIntEnumField, loaded_item.PublicIntEnumField);
Assert.AreEqual (newed_item.PublicIntEnumProperty, loaded_item.PublicIntEnumProperty);
Assert.AreEqual (newed_item.GetPrivateIntEnumField (), loaded_item.GetPrivateIntEnumField ());
Assert.AreEqual (newed_item.GetPrivateIntEnumProperty (), loaded_item.GetPrivateIntEnumProperty ());
}
-
+
[Test]
public void LongEnumMembers ()
{
@@ -233,9 +233,9 @@ namespace Hyena.Data.Sqlite.Tests
newed_item.PublicLongEnumProperty = LongEnum.Uno;
newed_item.SetPrivateLongEnumField (LongEnum.Dos);
newed_item.SetPrivateLongEnumProperty (LongEnum.Tres);
-
+
provider.Save (newed_item);
-
+
DbBoundType loaded_item = provider.FetchSingle (newed_item.PrimaryKey);
Assert.AreEqual (newed_item.PublicLongEnumField, loaded_item.PublicLongEnumField);
Assert.AreEqual (newed_item.PublicLongEnumProperty, loaded_item.PublicLongEnumProperty);
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteUtilTests.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteUtilTests.cs
index 84af70c..2ccc8be 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteUtilTests.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/Tests/SqliteUtilTests.cs
@@ -38,14 +38,14 @@ namespace Hyena.Data.Sqlite.Tests
{
Assert.AreEqual (after, (new CollationKeyFunction ()).Invoke (new object[] {before}));
}
-
+
[Test]
public void TestNull ()
{
CollationKeyTest (null, null);
CollationKeyTest (System.DBNull.Value, null);
}
-
+
[Test]
public void TestKey ()
{
@@ -55,7 +55,7 @@ namespace Hyena.Data.Sqlite.Tests
CollationKeyTest ("\u0104", new byte[] {14, 2, 1, 27, 1, 1, 1, 0});
}
}
-
+
[TestFixture]
public class SearchKeyTests
{
@@ -63,14 +63,14 @@ namespace Hyena.Data.Sqlite.Tests
{
Assert.AreEqual (after, (new SearchKeyFunction ()).Invoke (new object[] {before}));
}
-
+
[Test]
public void TestNull ()
{
SearchKeyTest (null, null);
SearchKeyTest (System.DBNull.Value, null);
}
-
+
[Test]
public void TestKey ()
{
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/CellContext.cs b/src/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
index 603ab61..97f54ff 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
@@ -43,7 +43,7 @@ namespace Hyena.Data.Gui
private Gdk.Rectangle clip;
private bool text_as_foreground = false;
private bool sensitive = true;
-
+
public Cairo.Context Context {
get { return context; }
set { context = value; }
@@ -73,17 +73,17 @@ namespace Hyena.Data.Gui
get { return area; }
set { area = value; }
}
-
+
public Gdk.Rectangle Clip {
get { return clip; }
set { clip = value; }
}
-
+
public bool TextAsForeground {
get { return text_as_foreground; }
set { text_as_foreground = value; }
}
-
+
public bool Sensitive {
get { return sensitive; }
set { sensitive = value; }
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/Column.cs b/src/Hyena.Gui/Hyena.Data.Gui/Column.cs
index fd84faa..5840764 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/Column.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/Column.cs
@@ -40,40 +40,40 @@ namespace Hyena.Data.Gui
{
private ColumnCell header_cell;
private List<ColumnCell> cells = new List<ColumnCell> ();
-
+
private int min_width = 0;
private int max_width = Int32.MaxValue;
-
+
public Column (ColumnDescription description) :
this (description, new ColumnCellText (description.Property, true))
{
}
-
+
public Column (ColumnDescription description, ColumnCell cell) :
this (description.Title, cell, description.Width, description.Visible)
{
}
-
+
public Column (string title, ColumnCell cell, double width)
: this (title, cell, width, true)
{
}
-
- public Column (string title, ColumnCell cell, double width, bool visible)
+
+ public Column (string title, ColumnCell cell, double width, bool visible)
: this (null, title, cell, width, visible)
{
}
-
+
public Column (ColumnCell headerCell, string title, ColumnCell cell, double width)
: this (headerCell, title, cell, width, true)
{
}
-
+
public Column (ColumnCell headerCell, string title, ColumnCell cell, double width, bool visible)
: this (headerCell, title, cell, width, visible, 0, Int32.MaxValue)
{
}
-
+
public Column (ColumnCell headerCell, string title, ColumnCell cell, double width, bool visible, int minWidth, int maxWidth)
: base (cell.Property, title, width, visible)
{
@@ -89,47 +89,47 @@ namespace Hyena.Data.Gui
PackStart (cell);
}
-
+
private Column HeaderCellDataHandler ()
{
return this;
}
-
+
public void PackStart (ColumnCell cell)
{
cells.Insert (0, cell);
}
-
+
public void PackEnd (ColumnCell cell)
{
cells.Add (cell);
}
-
- public ColumnCell GetCell (int index)
+
+ public ColumnCell GetCell (int index)
{
return cells[index];
}
-
+
public void RemoveCell (int index)
{
cells.RemoveAt (index);
}
-
+
public void ClearCells ()
{
cells.Clear ();
}
-
+
IEnumerator IEnumerable.GetEnumerator ()
{
return cells.GetEnumerator ();
}
-
+
IEnumerator<ColumnCell> IEnumerable<ColumnCell>.GetEnumerator ()
{
return cells.GetEnumerator ();
}
-
+
public ColumnCell HeaderCell {
get { return header_cell; }
set { header_cell = value; }
@@ -170,7 +170,7 @@ namespace Hyena.Data.Gui
}
}
}
-
+
public int MinWidth {
get { return min_width; }
set {
@@ -180,7 +180,7 @@ namespace Hyena.Data.Gui
}
}
}
-
+
public int MaxWidth {
get { return max_width; }
set {
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
index 7812d1a..eb6043b 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
@@ -40,7 +40,7 @@ namespace Hyena.Data.Gui
private PropertyInfo property_info, sub_property_info;
private object bound_object;
private object bound_object_parent;
-
+
public ColumnCell (string property, bool expand)
{
Property = property;
@@ -54,9 +54,9 @@ namespace Hyena.Data.Gui
bound_object = null;
return;
}
-
+
bound_object_parent = item;
-
+
if (property != null) {
EnsurePropertyInfo ();
bound_object = property_info.GetValue (bound_object_parent, null);
@@ -74,7 +74,7 @@ namespace Hyena.Data.Gui
{
EnsurePropertyInfo (property, ref property_info, bound_object_parent);
}
-
+
private void EnsurePropertyInfo (string name, ref PropertyInfo prop, object obj)
{
if (prop == null || prop.ReflectedType != obj.GetType ()) {
@@ -87,15 +87,15 @@ namespace Hyena.Data.Gui
}
}
}
-
+
public virtual void NotifyThemeChange ()
{
}
-
+
protected Type BoundType {
get { return bound_object.GetType (); }
}
-
+
protected object BoundObject {
get { return bound_object; }
set {
@@ -105,18 +105,18 @@ namespace Hyena.Data.Gui
}
}
}
-
+
protected object BoundObjectParent {
get { return bound_object_parent; }
}
-
+
public abstract void Render (CellContext context, StateType state, double cellWidth, double cellHeight);
-
+
public bool Expand {
get { return expand; }
set { expand = value; }
}
-
+
public string Property {
get { return property; }
set {
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
index 80539bd..bfed4bd 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
@@ -30,91 +30,91 @@ using System;
using Gtk;
namespace Hyena.Data.Gui
-{
+{
public class ColumnCellCheckBox : ColumnCell, IInteractiveCell, ISizeRequestCell
- {
+ {
public ColumnCellCheckBox (string property, bool expand) : base (property, expand)
{
}
-
+
public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
{
int cell_width = context.Area.Width - 2 * Xpad;
int cell_height = context.Area.Height - 2 * Ypad;
int x = context.Area.X + xpad + ((cell_width - Size) / 2);
int y = context.Area.Y + ypad + ((cell_height - Size) / 2);
-
+
if (state == StateType.Normal && last_hover_bound == BoundObjectParent) {
state = StateType.Prelight;
}
-
- Style.PaintCheck (context.Widget.Style, context.Drawable, state,
- Value ? ShadowType.In : ShadowType.Out,
+
+ Style.PaintCheck (context.Widget.Style, context.Drawable, state,
+ Value ? ShadowType.In : ShadowType.Out,
context.Clip, context.Widget, "cellcheck", x, y, Size, Size);
}
-
+
private object last_pressed_bound;
private object last_hover_bound;
-
+
public bool ButtonEvent (int x, int y, bool pressed, Gdk.EventButton evnt)
{
if (pressed) {
last_pressed_bound = BoundObjectParent;
return false;
}
-
+
if (last_pressed_bound != null && last_pressed_bound.Equals (BoundObjectParent)) {
Value = !Value;
last_pressed_bound = null;
}
-
+
return true;
}
-
+
public bool MotionEvent (int x, int y, Gdk.EventMotion evnt)
{
if (last_hover_bound == BoundObjectParent) {
return false;
}
-
+
last_hover_bound = BoundObjectParent;
return true;
}
-
+
public bool PointerLeaveEvent ()
{
last_hover_bound = null;
return true;
}
-
+
public void GetWidthRange (Pango.Layout layout, out int min, out int max)
{
min = max = 2 * Xpad + Size;
}
-
+
private bool restrict_size = true;
public bool RestrictSize {
get { return restrict_size; }
set { restrict_size = value; }
}
-
+
private bool Value {
get { return (bool)BoundObject; }
set { BoundObject = value; }
}
-
+
private int size = 13;
public int Size {
get { return size; }
set { size = value; }
}
-
+
private int xpad = 2;
public int Xpad {
get { return xpad; }
set { xpad = value; }
}
-
+
public int ypad = 2;
public int Ypad {
get { return ypad; }
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs
index 802c6c8..420ccb4 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs
@@ -33,113 +33,113 @@ using Hyena.Gui;
using Hyena.Gui.Theming;
namespace Hyena.Data.Gui
-{
+{
public class ColumnCellRating : ColumnCell, IInteractiveCell, ISizeRequestCell
- {
+ {
private object last_pressed_bound;
private object hover_bound;
private int hover_value;
private Gdk.Rectangle actual_area_hack;
private RatingRenderer renderer = new RatingRenderer ();
-
+
public ColumnCellRating (string property, bool expand) : base (property, expand)
{
Xpad = 0;
}
-
+
public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
{
Gdk.Rectangle area = new Gdk.Rectangle (0, 0, context.Area.Width, context.Area.Height);
-
+
// FIXME: Compute font height and set to renderer.Size
renderer.Value = Value;
bool is_hovering = hover_bound == BoundObjectParent && hover_bound != null;
- renderer.Render (context.Context, area, context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state),
+ renderer.Render (context.Context, area, context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state),
is_hovering, is_hovering, hover_value, 0.8, 0.45, 0.35);
-
+
// FIXME: Something is hosed in the view when computing cell dimensions
// The cell width request is always smaller than the actual cell, so
- // this value is preserved once we compute it from rendering so the
+ // this value is preserved once we compute it from rendering so the
// input stuff can do its necessary calculations
actual_area_hack = area;
}
-
+
public bool ButtonEvent (int x, int y, bool pressed, Gdk.EventButton evnt)
{
if (pressed) {
last_pressed_bound = BoundObjectParent;
return false;
}
-
+
if (last_pressed_bound == BoundObjectParent) {
Value = RatingFromPosition (x);
last_pressed_bound = null;
}
-
+
return true;
}
-
+
public bool MotionEvent (int x, int y, Gdk.EventMotion evnt)
{
int value = RatingFromPosition (x);
-
+
if (hover_bound == BoundObjectParent && value == hover_value) {
return false;
}
-
+
hover_bound = BoundObjectParent;
hover_value = value;
return true;
}
-
+
public bool PointerLeaveEvent ()
{
hover_bound = null;
hover_value = MinRating - 1;
return true;
}
-
+
public void GetWidthRange (Pango.Layout layout, out int min, out int max)
{
min = max = renderer.Width;
}
-
+
private int RatingFromPosition (double x)
{
return renderer.RatingFromPosition (actual_area_hack, x);
}
-
+
private bool restrict_size = true;
public bool RestrictSize {
get { return restrict_size; }
set { restrict_size = value; }
}
-
+
private int Value {
get { return BoundObject == null ? MinRating : renderer.ClampValue ((int)BoundObject); }
set { BoundObject = renderer.ClampValue (value); }
}
-
+
public int MaxRating {
get { return renderer.MaxRating; }
set { renderer.MaxRating = value; }
}
-
+
public int MinRating {
get { return renderer.MinRating; }
set { renderer.MinRating = value; }
}
-
+
public int RatingLevels {
get { return renderer.RatingLevels; }
}
-
+
public int Xpad {
get { return renderer.Xpad; }
set { renderer.Xpad = value; }
}
-
+
public int Ypad {
get { return renderer.Ypad; }
set { renderer.Ypad = value; }
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
index bc5b6d4..c331369 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
@@ -40,7 +40,7 @@ namespace Hyena.Data.Gui
internal const int Spacing = 4;
public delegate string DataHandler ();
-
+
private Pango.Weight font_weight = Pango.Weight.Normal;
private Pango.EllipsizeMode ellipsize_mode = Pango.EllipsizeMode.End;
private Pango.Alignment alignment = Pango.Alignment.Left;
@@ -51,7 +51,7 @@ namespace Hyena.Data.Gui
protected string MinString, MaxString;
private string last_text = null;
private bool use_markup;
-
+
public ColumnCellText (string property, bool expand) : base (property, expand)
{
}
@@ -60,7 +60,7 @@ namespace Hyena.Data.Gui
{
SetMinMaxStrings (min_max, min_max);
}
-
+
protected void SetMinMaxStrings (object min, object max)
{
// Set the min/max strings from the min/max objects
@@ -68,14 +68,14 @@ namespace Hyena.Data.Gui
MaxString = GetText (max);
RestrictSize = true;
}
-
+
public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
{
UpdateText (context, cellWidth);
if (String.IsNullOrEmpty (last_text)) {
return;
}
-
+
context.Context.Rectangle (0, 0, cellWidth, cellHeight);
context.Context.Clip ();
context.Context.MoveTo (Spacing, ((int)cellHeight - text_height) / 2);
@@ -121,7 +121,7 @@ namespace Hyena.Data.Gui
UpdateText (cellContext, columnWidth);
return IsEllipsized ? GLib.Markup.EscapeText (Text) : null;
}
-
+
protected virtual string GetText (object obj)
{
return obj == null ? String.Empty : obj.ToString ();
@@ -143,11 +143,11 @@ namespace Hyena.Data.Gui
public string Text {
get { return last_text; }
}
-
+
protected int TextWidth {
get { return text_width; }
}
-
+
protected int TextHeight {
get { return text_height; }
}
@@ -156,27 +156,27 @@ namespace Hyena.Data.Gui
get { return text_format; }
set { text_format = value; }
}
-
+
public Pango.Alignment Alignment {
get { return alignment; }
set { alignment = value; }
}
-
+
public virtual Pango.Weight FontWeight {
get { return font_weight; }
set { font_weight = value; }
}
-
+
public virtual Pango.EllipsizeMode EllipsizeMode {
get { return ellipsize_mode; }
set { ellipsize_mode = value; }
}
-
+
public virtual double Opacity {
get { return opacity; }
set { opacity = value; }
}
-
+
internal static int ComputeRowHeight (Widget widget)
{
int w_width, row_height;
@@ -187,13 +187,13 @@ namespace Hyena.Data.Gui
return row_height + 8;
}
- #region ISizeRequestCell implementation
-
+ #region ISizeRequestCell implementation
+
public void GetWidthRange (Pango.Layout layout, out int min, out int max)
{
int height;
min = max = -1;
-
+
if (!String.IsNullOrEmpty (MinString)) {
UpdateLayout (layout, MinString);
layout.GetPixelSize (out min, out height);
@@ -208,7 +208,7 @@ namespace Hyena.Data.Gui
//Console.WriteLine ("for {0} got max {1} for {2}", this, max, MaxString);
}
}
-
+
private bool restrict_size = false;
public bool RestrictSize {
get { return restrict_size; }
@@ -219,7 +219,7 @@ namespace Hyena.Data.Gui
get { return use_markup; }
set { use_markup = value; }
}
-
+
#endregion
}
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ColumnController.cs b/src/Hyena.Gui/Hyena.Data.Gui/ColumnController.cs
index 723e673..1ebb336 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ColumnController.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ColumnController.cs
@@ -31,28 +31,28 @@ using System.Collections;
using System.Collections.Generic;
namespace Hyena.Data.Gui
-{
+{
public class ColumnController : IEnumerable<Column>
{
private List<Column> columns = new List<Column> ();
private ISortableColumn default_sort_column;
private ISortableColumn sort_column;
-
+
protected List<Column> Columns {
get { return columns; }
}
-
+
public event EventHandler Updated;
-
+
protected virtual void OnVisibilitiesChanged ()
{
OnUpdated ();
}
-
+
protected virtual void OnWidthsChanged ()
{
}
-
+
protected void OnUpdated ()
{
EventHandler handler = Updated;
@@ -60,7 +60,7 @@ namespace Hyena.Data.Gui
handler (this, EventArgs.Empty);
}
}
-
+
public void Clear ()
{
lock (this) {
@@ -70,7 +70,7 @@ namespace Hyena.Data.Gui
}
columns.Clear ();
}
-
+
OnUpdated ();
}
@@ -94,10 +94,10 @@ namespace Hyena.Data.Gui
column.WidthChanged += OnColumnWidthChanged;
columns.Add (column);
}
-
+
OnUpdated ();
}
-
+
public void Insert (Column column, int index)
{
lock (this) {
@@ -105,10 +105,10 @@ namespace Hyena.Data.Gui
column.WidthChanged += OnColumnWidthChanged;
columns.Insert (index, column);
}
-
+
OnUpdated ();
}
-
+
public void Remove (Column column)
{
lock (this) {
@@ -116,10 +116,10 @@ namespace Hyena.Data.Gui
column.WidthChanged -= OnColumnWidthChanged;
columns.Remove (column);
}
-
+
OnUpdated ();
}
-
+
public void Remove (int index)
{
lock (this) {
@@ -128,10 +128,10 @@ namespace Hyena.Data.Gui
column.WidthChanged -= OnColumnWidthChanged;
columns.RemoveAt (index);
}
-
+
OnUpdated ();
}
-
+
public void Reorder (int index, int newIndex)
{
lock (this) {
@@ -139,42 +139,42 @@ namespace Hyena.Data.Gui
columns.RemoveAt (index);
columns.Insert (newIndex, column);
}
-
+
OnUpdated ();
}
-
+
IEnumerator IEnumerable.GetEnumerator ()
{
return columns.GetEnumerator ();
}
-
+
IEnumerator<Column> IEnumerable<Column>.GetEnumerator ()
{
return columns.GetEnumerator ();
}
-
+
public int IndexOf (Column column)
{
lock (this) {
return columns.IndexOf (column);
}
}
-
+
public Column [] ToArray ()
{
return columns.ToArray ();
}
-
+
private void OnColumnVisibilityChanged (object o, EventArgs args)
{
OnVisibilitiesChanged ();
}
-
+
private void OnColumnWidthChanged (object o, EventArgs args)
{
OnWidthsChanged ();
}
-
+
public Column this[int index] {
get { return columns[index]; }
}
@@ -188,11 +188,11 @@ namespace Hyena.Data.Gui
get { return sort_column; }
set { sort_column = value;}
}
-
+
public int Count {
get { return columns.Count; }
}
-
+
public virtual bool EnableColumnMenu {
get { return false; }
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs b/src/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs
index bb00152..a63753e 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs
@@ -35,7 +35,7 @@ namespace Hyena.Data.Gui
public class ColumnHeaderCellText : ColumnCellText, IHeaderCell
{
public delegate Column DataHandler ();
-
+
private DataHandler data_handler;
private bool has_sort;
@@ -43,13 +43,13 @@ namespace Hyena.Data.Gui
{
this.data_handler = data_handler;
}
-
+
public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
{
if (data_handler == null) {
return;
}
-
+
if (!has_sort) {
base.Render (context, state, cellWidth, cellHeight);
return;
@@ -71,17 +71,17 @@ namespace Hyena.Data.Gui
context.Theme.DrawArrow (context.Context, arrow_alloc, sort_type);
}
}
-
+
protected override string GetText (object obj)
{
return data_handler ().Title;
}
-
+
public bool HasSort {
get { return has_sort; }
set { has_sort = value; }
}
-
+
public static int GetArrowWidth (int headerHeight)
{
return (int)(headerHeight / 3.0) + Spacing;
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/IListView.cs b/src/Hyena.Gui/Hyena.Data.Gui/IListView.cs
index 18167d5..ac5fab7 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/IListView.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/IListView.cs
@@ -32,13 +32,13 @@ namespace Hyena.Data.Gui
{
Hyena.Collections.SelectionProxy SelectionProxy { get; }
Hyena.Collections.Selection Selection { get; }
-
+
void ScrollTo (int index);
void CenterOn (int index);
void GrabFocus ();
ColumnController ColumnController { get; set; }
}
-
+
public interface IListView<T> : IListView
{
void SetModel (IListModel<T> model);
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ISizeRequestCell.cs b/src/Hyena.Gui/Hyena.Data.Gui/ISizeRequestCell.cs
index 97fd59b..473bd2a 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ISizeRequestCell.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ISizeRequestCell.cs
@@ -30,7 +30,7 @@
using System;
namespace Hyena.Data.Gui
-{
+{
public interface ISizeRequestCell
{
bool RestrictSize { get; set; }
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ITextCell.cs b/src/Hyena.Gui/Hyena.Data.Gui/ITextCell.cs
index 7b447ad..ca541cd 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ITextCell.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ITextCell.cs
@@ -30,7 +30,7 @@
using System;
namespace Hyena.Data.Gui
-{
+{
public interface ITextCell
{
Pango.Weight FontWeight { get; set; }
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs
index e6d61eb..5d02fcc 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView.cs
@@ -48,7 +48,7 @@ namespace Hyena.Data.Gui
ITooltipCell cell;
Column column;
int row_index;
-
+
if (GetEventCell<ITooltipCell> (args.X, args.Y, out cell, out column, out row_index)) {
CachedColumn cached_column = GetCachedColumnForColumn (column);
@@ -72,7 +72,7 @@ namespace Hyena.Data.Gui
// TODO not right - could be smaller if at the top/bottom and only partially showing
rect.Height = RowHeight;
-
+
args.Tooltip.Markup = markup;
args.Tooltip.TipArea = rect;
args.RetVal = true;
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
index 1f5980a..9b5cfb5 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
@@ -30,25 +30,25 @@ using System;
using Gtk;
namespace Hyena.Data.Gui
-{
+{
public static class ListViewDragDropTarget
{
public enum TargetType
{
ModelSelection
}
-
+
public static readonly TargetEntry ModelSelection =
new TargetEntry ("application/x-hyena-data-model-selection", TargetFlags.App,
(uint)TargetType.ModelSelection);
}
-
+
public partial class ListView<T> : ListViewBase
{
private static TargetEntry [] drag_drop_dest_entries = new TargetEntry [] {
ListViewDragDropTarget.ModelSelection
};
-
+
protected virtual TargetEntry [] DragDropDestEntries {
get { return drag_drop_dest_entries; }
}
@@ -56,7 +56,7 @@ namespace Hyena.Data.Gui
protected virtual TargetEntry [] DragDropSourceEntries {
get { return drag_drop_dest_entries; }
}
-
+
private bool is_reorderable = false;
public bool IsReorderable {
get { return is_reorderable && IsEverReorderable; }
@@ -76,7 +76,7 @@ namespace Hyena.Data.Gui
OnDragDestSet ();
}
}
-
+
private bool force_drag_source_set = false;
protected bool ForceDragSourceSet {
get { return force_drag_source_set; }
@@ -85,7 +85,7 @@ namespace Hyena.Data.Gui
OnDragSourceSet ();
}
}
-
+
private bool force_drag_dest_set = false;
protected bool ForceDragDestSet {
get { return force_drag_dest_set; }
@@ -94,7 +94,7 @@ namespace Hyena.Data.Gui
OnDragDestSet ();
}
}
-
+
protected virtual void OnDragDestSet ()
{
if (ForceDragDestSet || IsReorderable) {
@@ -103,34 +103,34 @@ namespace Hyena.Data.Gui
Gtk.Drag.DestUnset (this);
}
}
-
+
protected virtual void OnDragSourceSet ()
{
if (ForceDragSourceSet || IsReorderable) {
- Gtk.Drag.SourceSet (this, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask,
+ Gtk.Drag.SourceSet (this, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask,
DragDropSourceEntries, Gdk.DragAction.Copy | Gdk.DragAction.Move);
} else {
Gtk.Drag.SourceUnset (this);
}
}
-
+
private uint drag_scroll_timeout_id;
private uint drag_scroll_timeout_duration = 50;
private double drag_scroll_velocity;
private double drag_scroll_velocity_max = 100.0;
private int drag_reorder_row_index = -1;
private int drag_reorder_motion_y = -1;
-
+
private void StopDragScroll ()
{
drag_scroll_velocity = 0.0;
-
+
if (drag_scroll_timeout_id > 0) {
GLib.Source.Remove (drag_scroll_timeout_id);
drag_scroll_timeout_id = 0;
}
}
-
+
private void OnDragScroll (GLib.TimeoutHandler handler, double threshold, int total, int position)
{
if (position < threshold) {
@@ -141,12 +141,12 @@ namespace Hyena.Data.Gui
StopDragScroll ();
return;
}
-
+
if (drag_scroll_timeout_id == 0) {
drag_scroll_timeout_id = GLib.Timeout.Add (drag_scroll_timeout_duration, handler);
}
}
-
+
protected override bool OnDragMotion (Gdk.DragContext context, int x, int y, uint time)
{
if (!IsReorderable) {
@@ -156,20 +156,20 @@ namespace Hyena.Data.Gui
InvalidateList ();
return false;
}
-
+
drag_reorder_motion_y = y;
DragReorderUpdateRow ();
-
+
OnDragScroll (OnDragVScrollTimeout, Allocation.Height * 0.3, Allocation.Height, y);
-
+
return true;
}
-
+
protected override void OnDragLeave (Gdk.DragContext context, uint time)
{
StopDragScroll ();
}
-
+
protected override void OnDragEnd (Gdk.DragContext context)
{
StopDragScroll ();
@@ -177,28 +177,28 @@ namespace Hyena.Data.Gui
drag_reorder_motion_y = -1;
InvalidateList ();
}
-
+
private bool OnDragVScrollTimeout ()
{
ScrollTo (VadjustmentValue + (drag_scroll_velocity * drag_scroll_velocity_max));
DragReorderUpdateRow ();
return true;
}
-
+
private void DragReorderUpdateRow ()
{
int row = GetDragRow (drag_reorder_motion_y);
if (row != drag_reorder_row_index) {
drag_reorder_row_index = row;
InvalidateList ();
- }
+ }
}
-
+
protected int GetDragRow (int y)
{
y = TranslateToListY (y);
int row = GetRowAtY (y);
-
+
if (row == -1) {
return -1;
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs
index ef150bd..9173e83 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs
@@ -51,7 +51,7 @@ namespace Hyena.Data.Gui
public double ElasticWidth;
public double ElasticPercent;
}
-
+
private static Gdk.Cursor resize_x_cursor = new Gdk.Cursor (Gdk.CursorType.SbHDoubleArrow);
private static Gdk.Cursor drag_cursor = new Gdk.Cursor (Gdk.CursorType.Fleur);
@@ -67,62 +67,62 @@ namespace Hyena.Data.Gui
private int pressed_column_x_start_hadjustment = -1;
private bool pressed_column_is_dragging = false;
private bool pressed_column_drag_started = false;
-
+
private Pango.Layout column_layout;
-
+
private CachedColumn [] column_cache;
private List<int> elastic_columns;
-
+
#region Columns
-
+
private void InvalidateColumnCache ()
{
column_cache = null;
}
-
+
private void GenerateColumnCache ()
{
column_cache = new CachedColumn[column_controller.Count];
-
+
int i = 0;
double total = 0.0;
-
+
foreach (Column column in column_controller) {
if (!column.Visible) {
continue;
}
-
+
// If we don't already have a MinWidth set, use the width of our Title text
column.CalculateWidths (column_layout, HeaderVisible, HeaderHeight);
column_cache[i] = new CachedColumn ();
column_cache[i].Column = column;
column_cache[i].Index = i;
-
+
total += column.Width;
i++;
}
-
+
Array.Resize (ref column_cache, i);
-
+
double scale_factor = 1.0 / total;
-
+
for (i = 0; i < column_cache.Length; i++) {
column_cache[i].Column.Width *= scale_factor;
}
-
+
RecalculateColumnSizes ();
}
-
+
private void RegenerateColumnCache ()
{
if (column_controller == null) {
return;
}
-
+
if (column_cache == null) {
GenerateColumnCache ();
}
-
+
for (int i = 0; i < column_cache.Length; i++) {
// Calculate this column's proportional share of the width, and set positions (X1/X2)
column_cache[i].Width = (int)Math.Round (((double)header_width * column_cache[i].Column.Width));
@@ -131,7 +131,7 @@ namespace Hyena.Data.Gui
column_cache[i].ResizeX1 = column_cache[i].X2;
column_cache[i].ResizeX2 = column_cache[i].ResizeX1 + 2;
}
-
+
// TODO handle max width
int index = column_cache.Length - 1;
if (index >= 0) {
@@ -139,13 +139,13 @@ namespace Hyena.Data.Gui
column_cache[index].Width = column_cache[index].X2 - column_cache[index].X1;
}
}
-
+
private void RecalculateColumnSizes ()
{
if (column_cache == null) {
return;
}
-
+
ISortable sortable = Model as ISortable;
sort_column_index = -1;
int min_header_width = 0;
@@ -178,7 +178,7 @@ namespace Hyena.Data.Gui
} else {
header_width = header_interaction_alloc.Width;
resizable = true;
-
+
if (elastic_columns == null) {
elastic_columns = new List<int> (column_cache.Length);
}
@@ -188,9 +188,9 @@ namespace Hyena.Data.Gui
column_cache[i].ElasticWidth = 0.0;
column_cache[i].ElasticPercent = column_cache[i].Column.Width * header_width;
}
-
+
double remaining_width = RecalculateColumnSizes (header_width, header_width);
-
+
while (remaining_width != 0 && elastic_columns.Count > 0) {
double total_elastic_width = 0.0;
foreach (int i in elastic_columns) {
@@ -198,22 +198,22 @@ namespace Hyena.Data.Gui
}
remaining_width = RecalculateColumnSizes (remaining_width, total_elastic_width);
}
-
+
for (int i = 0; i < column_cache.Length; i++) {
column_cache[i].Column.Width = column_cache[i].ElasticWidth / (double)header_width;
}
}
}
-
+
private double RecalculateColumnSizes (double total_width, double total_elastic_width)
{
double remaining_width = total_width;
-
+
for (int index = 0; index < elastic_columns.Count; index++) {
int i = elastic_columns[index];
double percent = column_cache[i].ElasticPercent / total_elastic_width;
double delta = total_width * percent;
-
+
// TODO handle max widths
double width = column_cache[i].ElasticWidth + delta;
if (width < column_cache[i].MinWidth) {
@@ -225,11 +225,11 @@ namespace Hyena.Data.Gui
elastic_columns.RemoveAt (index);
index--;
}
-
+
remaining_width -= delta;
column_cache[i].ElasticWidth += delta;
}
-
+
if (Math.Abs (total_width - remaining_width) < 1.0 || remaining_width == Double.NaN) {
Hyena.Log.Warning ("Forcefully breaking out of RCS loop b/c change in total_width less than 1.0");
return 0;
@@ -237,7 +237,7 @@ namespace Hyena.Data.Gui
return Math.Round (remaining_width);
}
-
+
protected virtual void OnColumnControllerUpdated ()
{
InvalidateColumnCache ();
@@ -245,7 +245,7 @@ namespace Hyena.Data.Gui
UpdateAdjustments ();
QueueDraw ();
}
-
+
protected virtual void OnColumnRightClicked (Column clickedColumn, int x, int y)
{
Column [] columns = ColumnController.ToArray ();
@@ -253,60 +253,60 @@ namespace Hyena.Data.Gui
// Fully qualified type name to avoid Mono 1.2.4 bug
return System.String.Compare (a.Title, b.Title);
});
-
+
uint items = 0;
-
+
for (int i = 0; i < columns.Length; i++) {
if (columns[i].Id != null) {
items++;
}
}
-
+
uint max_items_per_column = 15;
if (items >= max_items_per_column * 2) {
max_items_per_column = (uint)Math.Ceiling (items / 3.0);
} else if (items >= max_items_per_column) {
max_items_per_column = (uint)Math.Ceiling (items / 2.0);
}
-
+
uint column_count = (uint)Math.Ceiling (items / (double)max_items_per_column);
-
+
Menu menu = new Menu ();
uint row_offset = 2;
-
+
if (clickedColumn.Id != null) { // FIXME: Also restrict if the column vis can't be changed
menu.Attach (new ColumnHideMenuItem (clickedColumn), 0, column_count, 0, 1);
menu.Attach (new SeparatorMenuItem (), 0, column_count, 1, 2);
}
-
+
items = 0;
-
+
for (uint i = 0, n = (uint)columns.Length, column = 0, row = 0; i < n; i++) {
if (columns[i].Id == null) {
continue;
}
-
+
row = items++ % max_items_per_column;
-
- menu.Attach (new ColumnToggleMenuItem (columns[i]),
+
+ menu.Attach (new ColumnToggleMenuItem (columns[i]),
column, column + 1, row + row_offset, row + 1 + row_offset);
-
+
if (row == max_items_per_column - 1) {
column++;
}
}
-
+
menu.ShowAll ();
menu.Popup (null, null, delegate (Menu popup, out int pos_x, out int pos_y, out bool push_in) {
int win_x, win_y;
GdkWindow.GetOrigin (out win_x, out win_y);
-
+
pos_x = win_x + x;
pos_y = win_y + y;
push_in = true;
}, 3, Gtk.Global.CurrentEventTime);
}
-
+
private void ResizeColumn (double x)
{
CachedColumn resizing_column = column_cache[resizing_column_index];
@@ -330,50 +330,50 @@ namespace Hyena.Data.Gui
if (resizing_column.Width + resize_delta > resizing_column.MaxWidth) {
resize_delta = resizing_column.MaxWidth - resizing_column.Width;
}
-
+
if (resize_delta == 0) {
return;
}
-
+
int sign = Math.Sign (resize_delta);
resize_delta = Math.Abs (resize_delta);
double total_elastic_width = 0.0;
-
+
for (int i = real_resizing_column_index + 1; i < column_cache.Length; i++) {
total_elastic_width += column_cache[i].ElasticWidth = sign == 1
? column_cache[i].Width - column_cache[i].MinWidth
: column_cache[i].MaxWidth - column_cache[i].Width;
}
-
+
if (total_elastic_width == 0) {
return;
}
-
+
if (resize_delta > total_elastic_width) {
resize_delta = total_elastic_width;
}
// Convert to a proprotional width
resize_delta = sign * resize_delta / (double)header_width;
-
+
for (int i = real_resizing_column_index + 1; i < column_cache.Length; i++) {
column_cache[i].Column.Width += -resize_delta * (column_cache[i].ElasticWidth / total_elastic_width);
}
-
+
resizing_column.Column.Width += resize_delta;
RegenerateColumnCache ();
QueueDraw ();
}
-
+
private Column GetColumnForResizeHandle (int x)
{
if (column_cache == null || !resizable) {
return null;
}
-
+
x += HadjustmentValue;
-
+
for (int i = 0; i < column_cache.Length - 1; i++) {
if (x < column_cache[i].ResizeX1 - 2) {
// No point in checking other columns since their ResizeX1 are even larger
@@ -410,24 +410,24 @@ namespace Hyena.Data.Gui
return false;
}
-
+
private Column GetColumnAt (int x)
{
if (column_cache == null) {
return null;
}
-
+
x += HadjustmentValue;
-
+
foreach (CachedColumn column in column_cache) {
if (x >= column.X1 && x <= column.X2) {
return column.Column;
}
}
-
+
return null;
}
-
+
private CachedColumn GetCachedColumnForColumn (Column col)
{
foreach (CachedColumn ca_col in column_cache) {
@@ -435,10 +435,10 @@ namespace Hyena.Data.Gui
return ca_col;
}
}
-
+
return CachedColumn.Zero;
}
-
+
private ColumnController column_controller;
public ColumnController ColumnController {
get { return column_controller; }
@@ -450,17 +450,17 @@ namespace Hyena.Data.Gui
if (column_controller != null) {
column_controller.Updated -= OnColumnControllerUpdatedHandler;
}
-
+
column_controller = value;
-
+
OnColumnControllerUpdated ();
-
+
if (column_controller != null) {
column_controller.Updated += OnColumnControllerUpdatedHandler;
}
}
}
-
+
#endregion
#region Header
@@ -471,7 +471,7 @@ namespace Hyena.Data.Gui
if (!header_visible) {
return 0;
}
-
+
if (header_height == 0) {
int w;
int h;
@@ -480,20 +480,20 @@ namespace Hyena.Data.Gui
header_height = h;
header_height += 10;
}
-
+
return header_height;
}
}
-
+
private bool header_visible = true;
public bool HeaderVisible {
get { return header_visible; }
- set {
+ set {
header_visible = value;
MoveResize (Allocation);
}
}
-
+
#endregion
#region Gtk.MenuItem Wrappers for the column context menu
@@ -503,64 +503,64 @@ namespace Hyena.Data.Gui
private Column column;
private bool ready = false;
private Label label;
-
+
public ColumnToggleMenuItem (Column column) : base ()
{
this.column = column;
- Active = column.Visible;
+ Active = column.Visible;
ready = true;
-
+
label = new Label ();
label.Xalign = 0.0f;
label.Text = column.LongTitle ?? String.Empty;
label.Show ();
-
+
Add (label);
}
-
+
protected override void OnStyleSet (Style previousStyle)
{
base.OnStyleSet (previousStyle);
label.ModifyFg (StateType.Prelight, Style.Foreground (StateType.Selected));
}
-
+
protected override void OnActivated ()
{
base.OnActivated ();
-
+
if (!ready) {
return;
}
-
+
column.Visible = Active;
}
}
-
+
private class ColumnHideMenuItem : ImageMenuItem
{
private Column column;
private Label label;
-
+
public ColumnHideMenuItem (Column column) : base ()
{
this.column = column;
this.Image = new Image (Stock.Remove, IconSize.Menu);
-
+
label = new Label ();
label.Xalign = 0.0f;
- label.Markup = String.Format (Catalog.GetString ("Hide <i>{0}</i>"),
+ label.Markup = String.Format (Catalog.GetString ("Hide <i>{0}</i>"),
GLib.Markup.EscapeText (column.LongTitle));
label.Show ();
-
+
Add (label);
}
-
+
protected override void OnStyleSet (Style previousStyle)
{
base.OnStyleSet (previousStyle);
label.ModifyFg (StateType.Prelight, Style.Foreground (StateType.Selected));
}
-
+
protected override void OnActivated ()
{
column.Visible = false;
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
index 1b44fee..0465c5e 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
@@ -41,12 +41,12 @@ namespace Hyena.Data.Gui
public Adjustment Vadjustment {
get { return vadjustment; }
}
-
+
private Adjustment hadjustment;
public Adjustment Hadjustment {
get { return hadjustment; }
}
-
+
private SelectionProxy selection_proxy = new SelectionProxy ();
public SelectionProxy SelectionProxy {
get { return selection_proxy; }
@@ -55,17 +55,17 @@ namespace Hyena.Data.Gui
public Selection Selection {
get { return model.Selection; }
}
-
+
private int HadjustmentValue {
get { return hadjustment == null ? 0 : (int)hadjustment.Value; }
}
-
+
private int VadjustmentValue {
get { return vadjustment == null ? 0 : (int)vadjustment.Value; }
}
-
+
public event RowActivatedHandler<T> RowActivated;
-
+
#region Row/Selection, Keyboard/Mouse Interaction
private bool KeyboardScroll (Gdk.ModifierType modifier, int relative_row, bool align_y)
@@ -73,13 +73,13 @@ namespace Hyena.Data.Gui
if (Model == null) {
return true;
}
-
+
int row_limit;
if (relative_row < 0) {
if (Selection.FocusedIndex == -1) {
return false;
}
-
+
row_limit = 0;
} else {
row_limit = Model.Count - 1;
@@ -88,7 +88,7 @@ namespace Hyena.Data.Gui
if (Selection.FocusedIndex == row_limit) {
return true;
}
-
+
int row_index = Math.Min (Model.Count - 1, Math.Max (0, Selection.FocusedIndex + relative_row));
if (Selection != null) {
@@ -111,7 +111,7 @@ namespace Hyena.Data.Gui
Selection.Select (row_index);
}
}
-
+
// Scroll if needed
double y_at_row = GetYAtRow (row_index);
if (align_y) {
@@ -128,7 +128,7 @@ namespace Hyena.Data.Gui
InvalidateList ();
return true;
}
-
+
protected override bool OnKeyPressEvent (Gdk.EventKey press)
{
bool handled = false;
@@ -164,13 +164,13 @@ namespace Hyena.Data.Gui
case Gdk.Key.Page_Up:
case Gdk.Key.KP_Page_Up:
- handled = vadjustment != null && KeyboardScroll (press.State,
+ handled = vadjustment != null && KeyboardScroll (press.State,
(int)(-vadjustment.PageIncrement / (double)RowHeight), false);
break;
case Gdk.Key.Page_Down:
case Gdk.Key.KP_Page_Down:
- handled = vadjustment != null && KeyboardScroll (press.State,
+ handled = vadjustment != null && KeyboardScroll (press.State,
(int)(vadjustment.PageIncrement / (double)RowHeight), false);
break;
@@ -192,7 +192,7 @@ namespace Hyena.Data.Gui
case Gdk.Key.Escape:
handled = CancelColumnDrag ();
break;
-
+
case Gdk.Key.space:
if (Selection != null && Selection.FocusedIndex != 1) {
Selection.ToggleSelect (Selection.FocusedIndex);
@@ -204,10 +204,10 @@ namespace Hyena.Data.Gui
if (handled) {
return true;
}
-
+
return base.OnKeyPressEvent (press);
}
-
+
protected bool ActivateSelection ()
{
if (Selection != null && Selection.FocusedIndex != -1) {
@@ -218,32 +218,32 @@ namespace Hyena.Data.Gui
}
return false;
}
-
-#region Cell Event Proxy
-
+
+#region Cell Event Proxy
+
private IInteractiveCell last_icell;
private Gdk.Rectangle last_icell_area = Gdk.Rectangle.Zero;
-
+
private void ProxyEventToCell (Gdk.Event evnt, bool press)
{
IInteractiveCell icell;
Gdk.Rectangle icell_area;
bool redraw = ProxyEventToCell (evnt, press, out icell, out icell_area);
-
+
int xoffset = HadjustmentValue;
int yoffset = VadjustmentValue;
-
+
if (last_icell_area != icell_area) {
if (last_icell != null && last_icell.PointerLeaveEvent ()) {
- QueueDrawArea (last_icell_area.X - xoffset, last_icell_area.Y - yoffset,
+ QueueDrawArea (last_icell_area.X - xoffset, last_icell_area.Y - yoffset,
last_icell_area.Width, last_icell_area.Height);
}
last_icell = icell;
last_icell_area = icell_area;
}
-
+
if (redraw) {
- QueueDrawArea (icell_area.X - xoffset, icell_area.Y - yoffset,
+ QueueDrawArea (icell_area.X - xoffset, icell_area.Y - yoffset,
icell_area.Width, icell_area.Height);
}
}
@@ -256,10 +256,10 @@ namespace Hyena.Data.Gui
int evnt_x, evnt_y;
int x, y, row_index;
x = y = row_index = 0;
-
+
Gdk.EventButton evnt_button = evnt as Gdk.EventButton;
Gdk.EventMotion evnt_motion = evnt as Gdk.EventMotion;
-
+
if (evnt_motion != null) {
evnt_x = (int)evnt_motion.X;
evnt_y = (int)evnt_motion.Y;
@@ -318,27 +318,27 @@ namespace Hyena.Data.Gui
if (row_index < 0 || row_index >= Model.Count) {
return false;
}
-
+
column = GetColumnAt (x);
if (column == null) {
return false;
}
-
+
ColumnCell cell = column.GetCell (0);
icell = cell as G;
if (icell == null) {
return false;
}
-
+
// Bind the row to the cell
cell.BindListItem (model[row_index]);
return true;
}
#pragma warning restore 0169
-
+
#endregion
-
+
#region OnButtonPress
protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
@@ -351,12 +351,12 @@ namespace Hyena.Data.Gui
}
return true;
}
-
+
private bool OnHeaderButtonPressEvent (Gdk.EventButton evnt)
{
int x = (int)evnt.X - header_interaction_alloc.X;
int y = (int)evnt.Y - header_interaction_alloc.Y;
-
+
if (evnt.Button == 3 && ColumnController.EnableColumnMenu) {
Column menu_column = GetColumnAt (x);
if (menu_column != null) {
@@ -366,7 +366,7 @@ namespace Hyena.Data.Gui
} else if (evnt.Button != 1) {
return true;
}
-
+
Gtk.Drag.SourceUnset (this);
Column column = GetColumnForResizeHandle (x);
@@ -382,28 +382,28 @@ namespace Hyena.Data.Gui
pressed_column_x_start_hadjustment = HadjustmentValue;
}
}
-
+
return true;
}
-
+
private bool OnListButtonPressEvent (Gdk.EventButton evnt)
{
if (Model == null) {
return true;
}
-
+
int y = (int)evnt.Y - list_interaction_alloc.Y;
-
+
GrabFocus ();
-
+
int row_index = GetRowAtY (y);
if (row_index < 0 || row_index >= Model.Count) {
return true;
}
-
+
ProxyEventToCell (evnt, true);
-
+
object item = model[row_index];
if (item == null) {
return true;
@@ -451,20 +451,20 @@ namespace Hyena.Data.Gui
OnPopupMenu ();
}
}
-
+
InvalidateList ();
return true;
}
-
+
#endregion
#region OnButtonRelease
-
+
protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
{
OnDragSourceSet ();
StopDragScroll ();
-
+
if (resizing_column_index >= 0) {
pressed_column_index = -1;
resizing_column_index = -1;
@@ -477,7 +477,7 @@ namespace Hyena.Data.Gui
pressed_column_drag_started = false;
return true;
}
-
+
if (header_visible && header_interaction_alloc.Contains ((int)evnt.X, (int)evnt.Y)) {
return OnHeaderButtonRelease (evnt);
} else if (list_interaction_alloc.Contains ((int)evnt.X, (int)evnt.Y) && model != null &&
@@ -518,24 +518,24 @@ namespace Hyena.Data.Gui
RegenerateColumnCache ();
InvalidateHeader ();
}
-
+
pressed_column_index = -1;
return true;
} else {
return false;
}
}
-
+
private bool OnListButtonRelease (Gdk.EventButton evnt)
{
if (Model == null) {
return true;
}
-
+
int y = (int)evnt.Y - list_interaction_alloc.Y;
-
+
GrabFocus ();
-
+
int row_index = GetRowAtY (y);
if (row_index >= Model.Count) {
@@ -546,81 +546,81 @@ namespace Hyena.Data.Gui
if (item == null) {
return true;
}
-
+
//if (Selection != null && Selection.Contains (row_index) && Selection.Count > 1) {
if (Selection != null && evnt.Button == 1 && Hyena.Gui.GtkUtilities.NoImportantModifiersAreSet ()) {
if (Selection.Count > 1) {
Selection.Clear (false);
Selection.Select (row_index);
FocusRow (row_index);
- InvalidateList ();
+ InvalidateList ();
}
}
-
+
return true;
}
-
+
#endregion
-
+
protected override bool OnMotionNotifyEvent (Gdk.EventMotion evnt)
{
int x = (int)evnt.X - header_interaction_alloc.X;
-
- if (pressed_column_index >= 0 && !pressed_column_is_dragging &&
+
+ if (pressed_column_index >= 0 && !pressed_column_is_dragging &&
Gtk.Drag.CheckThreshold (this, pressed_column_x_start, 0, x, 0)) {
pressed_column_is_dragging = true;
pressed_column_drag_started = true;
InvalidateHeader ();
InvalidateList ();
}
-
+
pressed_column_x = x;
-
+
if (OnMotionNotifyEvent (x)) {
return true;
}
- GdkWindow.Cursor = header_interaction_alloc.Contains ((int)evnt.X, (int)evnt.Y) &&
+ GdkWindow.Cursor = header_interaction_alloc.Contains ((int)evnt.X, (int)evnt.Y) &&
(resizing_column_index >= 0 || GetColumnForResizeHandle (x) != null)
- ? resize_x_cursor
+ ? resize_x_cursor
: null;
-
+
if (resizing_column_index >= 0) {
ResizeColumn (x);
}
-
+
ProxyEventToCell (evnt, false);
-
+
return true;
}
-
+
private bool OnMotionNotifyEvent (int x)
{
if (!pressed_column_is_dragging) {
return false;
}
-
+
OnDragScroll (OnDragHScrollTimeout, header_interaction_alloc.Width * 0.1, header_interaction_alloc.Width, x);
-
+
GdkWindow.Cursor = drag_cursor;
-
+
Column swap_column = GetColumnAt (x);
-
+
if (swap_column != null) {
CachedColumn swap_column_c = GetCachedColumnForColumn (swap_column);
bool reorder = false;
-
+
if (swap_column_c.Index < pressed_column_index) {
// Moving from right to left
reorder = pressed_column_x_drag <= swap_column_c.X1 + swap_column_c.Width / 2;
} else if (swap_column_c.Index > pressed_column_index) {
if (column_cache.Length > pressed_column_index && pressed_column_index >= 0) {
// Moving from left to right
- reorder = pressed_column_x_drag + column_cache[pressed_column_index].Width >=
+ reorder = pressed_column_x_drag + column_cache[pressed_column_index].Width >=
swap_column_c.X1 + swap_column_c.Width / 2;
}
}
-
+
if (reorder) {
int actual_pressed_index = ColumnController.IndexOf (column_cache[pressed_column_index].Column);
int actual_swap_index = ColumnController.IndexOf (swap_column_c.Column);
@@ -629,20 +629,20 @@ namespace Hyena.Data.Gui
RegenerateColumnCache ();
}
}
-
+
pressed_column_x_drag = x - pressed_column_x_offset - (pressed_column_x_start_hadjustment - HadjustmentValue);
-
+
QueueDraw ();
return true;
}
-
+
private bool OnDragHScrollTimeout ()
{
ScrollTo (hadjustment, HadjustmentValue + (drag_scroll_velocity * drag_scroll_velocity_max));
OnMotionNotifyEvent (pressed_column_x);
return true;
}
-
+
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
{
if (evnt.Mode == Gdk.CrossingMode.Normal) {
@@ -651,17 +651,17 @@ namespace Hyena.Data.Gui
}
return base.OnLeaveNotifyEvent (evnt);
}
-
+
protected override bool OnFocusInEvent (Gdk.EventFocus evnt)
{
return base.OnFocusInEvent (evnt);
}
-
+
protected override bool OnFocusOutEvent (Gdk.EventFocus evnt)
{
return base.OnFocusOutEvent (evnt);
}
-
+
protected virtual void OnRowActivated ()
{
if (Selection.FocusedIndex != -1) {
@@ -683,17 +683,17 @@ namespace Hyena.Data.Gui
}
return false;
}
-
+
protected int GetRowAtY (int y)
{
if (y < 0) {
return -1;
}
-
+
int page_offset = VadjustmentValue % RowHeight;
int first_row = VadjustmentValue / RowHeight;
int row_offset = (y + page_offset) / RowHeight;
-
+
return first_row + row_offset;
}
@@ -711,22 +711,22 @@ namespace Hyena.Data.Gui
#endregion
#region Adjustments & Scrolling
-
+
private void UpdateAdjustments ()
{
UpdateAdjustments (null, null);
}
-
+
private void UpdateAdjustments (Adjustment hadj, Adjustment vadj)
{
if (hadj != null) {
hadjustment = hadj;
}
-
+
if (vadj != null) {
vadjustment = vadj;
}
-
+
if (hadjustment != null) {
hadjustment.Upper = header_width;
hadjustment.StepIncrement = 10.0;
@@ -734,7 +734,7 @@ namespace Hyena.Data.Gui
hadjustment.Value = hadjustment.Upper - hadjustment.PageSize;
}
}
-
+
if (vadjustment != null && model != null) {
vadjustment.Upper = (RowHeight * (model.Count));
vadjustment.StepIncrement = RowHeight;
@@ -742,7 +742,7 @@ namespace Hyena.Data.Gui
vadjustment.Value = vadjustment.Upper - vadjustment.PageSize;
}
}
-
+
if (hadjustment != null) {
hadjustment.Change ();
}
@@ -751,23 +751,23 @@ namespace Hyena.Data.Gui
vadjustment.Change ();
}
}
-
+
private void OnHadjustmentChanged (object o, EventArgs args)
{
InvalidateHeader ();
InvalidateList ();
}
-
+
private void OnVadjustmentChanged (object o, EventArgs args)
{
InvalidateList ();
}
-
+
public void ScrollTo (double val)
{
ScrollTo (vadjustment, val);
}
-
+
private void ScrollTo (Adjustment adjustment, double val)
{
if (adjustment != null) {
@@ -814,14 +814,14 @@ namespace Hyena.Data.Gui
if (hadj == null || vadj == null) {
return;
}
-
+
hadj.ValueChanged += OnHadjustmentChanged;
vadj.ValueChanged += OnVadjustmentChanged;
-
+
UpdateAdjustments (hadj, vadj);
}
#endregion
-
+
}
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs
index e9fe295..9c576a0 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs
@@ -50,7 +50,7 @@ namespace Hyena.Data.Gui
model.Cleared -= OnModelClearedHandler;
model.Reloaded -= OnModelReloadedHandler;
}
-
+
model = value;
if (model != null) {
@@ -71,7 +71,7 @@ namespace Hyena.Data.Gui
IsReorderable = sortable.SortColumn == null || sortable.SortColumn.SortType == SortType.None;
}
}
-
+
RefreshViewForModel (vpos);
}
@@ -91,11 +91,11 @@ namespace Hyena.Data.Gui
} else if (vadjustment != null) {
ScrollTo (vadjustment.Value);
}
-
+
if (Model != null && Selection != null) {
Selection.MaxIndex = Model.Count - 1;
}
-
+
if (Parent is ScrolledWindow) {
Parent.QueueDraw ();
}
@@ -105,7 +105,7 @@ namespace Hyena.Data.Gui
{
OnModelCleared ();
}
-
+
private void OnModelReloadedHandler (object o, EventArgs args)
{
OnModelReloaded ();
@@ -120,42 +120,42 @@ namespace Hyena.Data.Gui
{
RefreshViewForModel (null);
}
-
+
protected virtual void OnModelReloaded ()
{
RefreshViewForModel (null);
}
-
+
private IListModel<T> model;
public virtual IListModel<T> Model {
get { return model; }
}
-
+
private string row_sensitive_property_name = "Sensitive";
private PropertyInfo row_sensitive_property_info;
bool row_sensitive_property_invalid = false;
-
+
public string RowSensitivePropertyName {
get { return row_sensitive_property_name; }
- set {
+ set {
if (value == row_sensitive_property_name) {
return;
}
-
+
row_sensitive_property_name = value;
row_sensitive_property_info = null;
row_sensitive_property_invalid = false;
-
+
InvalidateList ();
}
}
-
+
private bool IsRowSensitive (object item)
{
if (item == null || row_sensitive_property_invalid) {
return true;
}
-
+
if (row_sensitive_property_info == null || row_sensitive_property_info.ReflectedType != item.GetType ()) {
row_sensitive_property_info = item.GetType ().GetProperty (row_sensitive_property_name);
if (row_sensitive_property_info == null || row_sensitive_property_info.PropertyType != typeof (bool)) {
@@ -164,35 +164,35 @@ namespace Hyena.Data.Gui
return true;
}
}
-
+
return (bool)row_sensitive_property_info.GetValue (item, null);
}
-
+
private string row_bold_property_name = "IsBold";
private PropertyInfo row_bold_property_info;
bool row_bold_property_invalid = false;
-
+
public string RowBoldPropertyName {
get { return row_bold_property_name; }
- set {
+ set {
if (value == row_bold_property_name) {
return;
}
-
+
row_bold_property_name = value;
row_bold_property_info = null;
row_bold_property_invalid = false;
-
+
InvalidateList ();
}
}
-
+
private bool IsRowBold (object item)
{
if (item == null || row_bold_property_invalid) {
return false;
}
-
+
if (row_bold_property_info == null || row_bold_property_info.ReflectedType != item.GetType ()) {
row_bold_property_info = item.GetType ().GetProperty (row_bold_property_name);
if (row_bold_property_info == null || row_bold_property_info.PropertyType != typeof (bool)) {
@@ -201,17 +201,17 @@ namespace Hyena.Data.Gui
return false;
}
}
-
+
return (bool)row_bold_property_info.GetValue (item, null);
}
-
+
#pragma warning disable 0169
-
+
private bool IsRowSensitive (int index)
{
return IsRowSensitive (model[index]);
}
-
+
#pragma warning restore 0169
}
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
index d376eb7..9f396fd 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
@@ -45,33 +45,33 @@ namespace Hyena.Data.Gui
private Cairo.Context cairo_context;
private CellContext cell_context;
private Pango.Layout pango_layout;
-
+
private List<int> selected_rows = new List<int> ();
-
+
private Theme theme;
protected Theme Theme {
get { return theme; }
}
-
+
private bool changing_style = false;
-
+
protected override void OnStyleSet (Style old_style)
{
if (changing_style) {
return;
}
-
+
changing_style = true;
GtkUtilities.AdaptGtkRcStyle (this, typeof (TreeView));
changing_style = false;
-
+
base.OnStyleSet (old_style);
RecomputeRowHeight = true;
theme = Hyena.Gui.Theming.ThemeEngine.CreateTheme (this);
// Save the drawable so we can reuse it
Gdk.Drawable drawable = cell_context != null ? cell_context.Drawable : null;
-
+
if (pango_layout != null) {
pango_layout.Dispose ();
pango_layout = null;
@@ -82,40 +82,40 @@ namespace Hyena.Data.Gui
cell_context.Widget = this;
cell_context.Drawable = drawable;
}
-
+
protected override bool OnExposeEvent (EventExpose evnt)
{
Rectangle damage = new Rectangle ();
foreach (Rectangle rect in evnt.Region.GetRectangles ()) {
damage = damage.Union (rect);
}
-
+
cairo_context = CairoHelper.Create (evnt.Window);
if (pango_layout == null) {
pango_layout = CairoExtensions.CreateLayout (this, cairo_context);
}
-
+
cell_context.Context = cairo_context;
cell_context.Layout = pango_layout;
-
+
Theme.DrawFrameBackground (cairo_context, Allocation, true);
if (header_visible && column_controller != null) {
PaintHeader (damage);
}
-
+
Theme.DrawFrameBorder (cairo_context, Allocation);
if (Model != null) {
PaintRows(damage);
}
-
+
PaintDraggingColumn (damage);
-
+
((IDisposable)cairo_context.Target).Dispose ();
((IDisposable)cairo_context).Dispose ();
-
+
return true;
}
-
+
private void PaintHeader (Rectangle clip)
{
Rectangle rect = header_rendering_alloc;
@@ -123,13 +123,13 @@ namespace Hyena.Data.Gui
clip.Intersect (rect);
cairo_context.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
cairo_context.Clip ();
-
+
Theme.DrawHeaderBackground (cairo_context, header_rendering_alloc);
-
+
Rectangle cell_area = new Rectangle ();
cell_area.Y = header_rendering_alloc.Y;
cell_area.Height = header_rendering_alloc.Height;
-
+
cell_context.Clip = clip;
cell_context.Sensitive = true;
cell_context.TextAsForeground = true;
@@ -140,34 +140,34 @@ namespace Hyena.Data.Gui
if (pressed_column_is_dragging && pressed_column_index == ci) {
continue;
}
-
+
cell_area.X = column_cache[ci].X1 + Theme.TotalBorderWidth + header_rendering_alloc.X - HadjustmentValue;
cell_area.Width = column_cache[ci].Width;
PaintHeaderCell (cell_area, ci, false, ref have_drawn_separator);
}
-
+
if (pressed_column_is_dragging && pressed_column_index >= 0) {
cell_area.X = pressed_column_x_drag + Allocation.X - HadjustmentValue;
cell_area.Width = column_cache[pressed_column_index].Width;
PaintHeaderCell (cell_area, pressed_column_index, true, ref have_drawn_separator);
}
-
+
cairo_context.ResetClip ();
}
-
+
private void PaintHeaderCell (Rectangle area, int ci, bool dragging, ref bool have_drawn_separator)
{
if (ci < 0 || column_cache.Length <= ci)
return;
if (dragging) {
- Theme.DrawColumnHighlight (cairo_context, area,
+ Theme.DrawColumnHighlight (cairo_context, area,
CairoExtensions.ColorShade (Theme.Colors.GetWidgetColor (GtkColorClass.Dark, StateType.Normal), 0.9));
-
+
Cairo.Color stroke_color = CairoExtensions.ColorShade (Theme.Colors.GetWidgetColor (
GtkColorClass.Base, StateType.Normal), 0.0);
stroke_color.A = 0.3;
-
+
cairo_context.Color = stroke_color;
cairo_context.MoveTo (area.X + 0.5, area.Y + 1.0);
cairo_context.LineTo (area.X + 0.5, area.Bottom);
@@ -177,7 +177,7 @@ namespace Hyena.Data.Gui
}
ColumnCell cell = column_cache[ci].Column.HeaderCell;
-
+
if (cell != null) {
cairo_context.Save ();
cairo_context.Translate (area.X, area.Y);
@@ -185,14 +185,14 @@ namespace Hyena.Data.Gui
cell.Render (cell_context, StateType.Normal, area.Width, area.Height);
cairo_context.Restore ();
}
-
- if (!dragging && ci < column_cache.Length - 1 && (have_drawn_separator ||
+
+ if (!dragging && ci < column_cache.Length - 1 && (have_drawn_separator ||
column_cache[ci].MaxWidth != column_cache[ci].MinWidth)) {
have_drawn_separator = true;
Theme.DrawHeaderSeparator (cairo_context, area, area.Right);
}
}
-
+
private void PaintRows (Rectangle clip)
{
// TODO factor this out?
@@ -204,27 +204,27 @@ namespace Hyena.Data.Gui
header_rendering_alloc.Bottom + Theme.BorderWidth,
col.Width, list_rendering_alloc.Height + Theme.InnerBorderWidth * 2);
}
-
+
clip.Intersect (list_rendering_alloc);
cairo_context.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
cairo_context.Clip ();
-
+
cell_context.Clip = clip;
cell_context.TextAsForeground = false;
-
+
int vadjustment_value = VadjustmentValue;
int first_row = vadjustment_value / RowHeight;
int last_row = Math.Min (model.Count, first_row + RowsInView);
int offset = list_rendering_alloc.Y - vadjustment_value % RowHeight;
-
+
Rectangle selected_focus_alloc = Rectangle.Zero;
Rectangle single_list_alloc = new Rectangle ();
-
+
single_list_alloc.X = list_rendering_alloc.X - HadjustmentValue;
single_list_alloc.Y = offset;
single_list_alloc.Width = list_rendering_alloc.Width + HadjustmentValue;
single_list_alloc.Height = RowHeight;
-
+
int selection_height = 0;
int selection_y = 0;
selected_rows.Clear ();
@@ -234,71 +234,71 @@ namespace Hyena.Data.Gui
if (selection_height == 0) {
selection_y = single_list_alloc.Y;
}
-
+
selection_height += single_list_alloc.Height;
selected_rows.Add (ri);
-
+
if (Selection.FocusedIndex == ri) {
selected_focus_alloc = single_list_alloc;
}
} else {
if (rules_hint && ri % 2 != 0) {
- Theme.DrawRowRule (cairo_context, single_list_alloc.X, single_list_alloc.Y,
+ Theme.DrawRowRule (cairo_context, single_list_alloc.X, single_list_alloc.Y,
single_list_alloc.Width, single_list_alloc.Height);
}
-
+
PaintReorderLine (ri, single_list_alloc);
-
+
if (Selection != null && Selection.FocusedIndex == ri && !Selection.Contains (ri) && HasFocus) {
CairoCorners corners = CairoCorners.All;
-
+
if (Selection.Contains (ri - 1)) {
corners &= ~(CairoCorners.TopLeft | CairoCorners.TopRight);
}
-
+
if (Selection.Contains (ri + 1)) {
corners &= ~(CairoCorners.BottomLeft | CairoCorners.BottomRight);
}
-
- Theme.DrawRowSelection (cairo_context, single_list_alloc.X, single_list_alloc.Y,
- single_list_alloc.Width, single_list_alloc.Height, false, true,
+
+ Theme.DrawRowSelection (cairo_context, single_list_alloc.X, single_list_alloc.Y,
+ single_list_alloc.Width, single_list_alloc.Height, false, true,
Theme.Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected), corners);
}
-
+
if (selection_height > 0) {
Theme.DrawRowSelection (cairo_context, list_rendering_alloc.X, selection_y, list_rendering_alloc.Width, selection_height);
selection_height = 0;
}
-
+
PaintRow (ri, single_list_alloc, StateType.Normal);
}
-
+
single_list_alloc.Y += single_list_alloc.Height;
}
-
+
// In case the user is dragging to the end of the list
PaintReorderLine (last_row, single_list_alloc);
-
+
if (selection_height > 0) {
- Theme.DrawRowSelection (cairo_context, list_rendering_alloc.X, selection_y,
+ Theme.DrawRowSelection (cairo_context, list_rendering_alloc.X, selection_y,
list_rendering_alloc.Width, selection_height);
}
-
- if (Selection != null && Selection.Count > 1 &&
+
+ if (Selection != null && Selection.Count > 1 &&
!selected_focus_alloc.Equals (Rectangle.Zero) && HasFocus) {
- Theme.DrawRowSelection (cairo_context, selected_focus_alloc.X, selected_focus_alloc.Y,
- selected_focus_alloc.Width, selected_focus_alloc.Height, false, true,
+ Theme.DrawRowSelection (cairo_context, selected_focus_alloc.X, selected_focus_alloc.Y,
+ selected_focus_alloc.Width, selected_focus_alloc.Height, false, true,
Theme.Colors.GetWidgetColor (GtkColorClass.Dark, StateType.Selected));
}
-
+
foreach (int ri in selected_rows) {
single_list_alloc.Y = offset + ((ri - first_row) * single_list_alloc.Height);
PaintRow (ri, single_list_alloc, StateType.Selected);
}
-
+
cairo_context.ResetClip ();
}
-
+
private void PaintReorderLine (int row_index, Rectangle single_list_alloc)
{
if (row_index == drag_reorder_row_index && IsReorderable) {
@@ -318,25 +318,25 @@ namespace Hyena.Data.Gui
if (column_cache == null) {
return;
}
-
+
object item = model[row_index];
bool sensitive = IsRowSensitive (item);
bool bold = IsRowBold (item);
-
+
Rectangle cell_area = new Rectangle ();
cell_area.Height = RowHeight;
cell_area.Y = area.Y;
-
+
for (int ci = 0; ci < column_cache.Length; ci++) {
if (pressed_column_is_dragging && pressed_column_index == ci) {
continue;
}
-
+
cell_area.Width = column_cache[ci].Width;
cell_area.X = column_cache[ci].X1 + area.X;
PaintCell (item, ci, row_index, cell_area, sensitive, bold, state, false);
}
-
+
if (pressed_column_is_dragging && pressed_column_index >= 0) {
cell_area.Width = column_cache[pressed_column_index].Width;
cell_area.X = pressed_column_x_drag + list_rendering_alloc.X -
@@ -344,19 +344,19 @@ namespace Hyena.Data.Gui
PaintCell (item, pressed_column_index, row_index, cell_area, sensitive, bold, state, true);
}
}
-
+
private void PaintCell (object item, int column_index, int row_index, Rectangle area, bool sensitive, bool bold,
StateType state, bool dragging)
{
ColumnCell cell = column_cache[column_index].Column.GetCell (0);
cell.BindListItem (item);
ColumnCellDataProvider (cell, item);
-
+
ITextCell text_cell = cell as ITextCell;
if (text_cell != null) {
text_cell.FontWeight = bold ? Pango.Weight.Bold : Pango.Weight.Normal;
}
-
+
if (dragging) {
Cairo.Color fill_color = Theme.Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
fill_color.A = 0.5;
@@ -364,7 +364,7 @@ namespace Hyena.Data.Gui
cairo_context.Rectangle (area.X, area.Y, area.Width, area.Height);
cairo_context.Fill ();
}
-
+
cairo_context.Save ();
cairo_context.Translate (area.X, area.Y);
cell_context.Area = area;
@@ -372,66 +372,66 @@ namespace Hyena.Data.Gui
cell.Render (cell_context, dragging ? StateType.Normal : state, area.Width, area.Height);
cairo_context.Restore ();
}
-
+
private void PaintDraggingColumn (Rectangle clip)
{
if (!pressed_column_is_dragging || pressed_column_index < 0) {
return;
}
-
+
CachedColumn column = column_cache[pressed_column_index];
-
+
int x = pressed_column_x_drag + Allocation.X + 1 - HadjustmentValue;
-
+
Cairo.Color fill_color = Theme.Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
fill_color.A = 0.45;
-
+
Cairo.Color stroke_color = CairoExtensions.ColorShade (Theme.Colors.GetWidgetColor (
GtkColorClass.Base, StateType.Normal), 0.0);
stroke_color.A = 0.3;
-
+
cairo_context.Rectangle (x, header_rendering_alloc.Bottom + 1, column.Width - 2,
list_rendering_alloc.Bottom - header_rendering_alloc.Bottom - 1);
cairo_context.Color = fill_color;
cairo_context.Fill ();
-
+
cairo_context.MoveTo (x - 0.5, header_rendering_alloc.Bottom + 0.5);
cairo_context.LineTo (x - 0.5, list_rendering_alloc.Bottom + 0.5);
cairo_context.LineTo (x + column.Width - 1.5, list_rendering_alloc.Bottom + 0.5);
cairo_context.LineTo (x + column.Width - 1.5, header_rendering_alloc.Bottom + 0.5);
-
+
cairo_context.Color = stroke_color;
cairo_context.LineWidth = 1.0;
cairo_context.Stroke ();
}
-
+
private void InvalidateList ()
{
if (IsRealized) {
QueueDrawArea (list_rendering_alloc.X, list_rendering_alloc.Y, list_rendering_alloc.Width, list_rendering_alloc.Height);
}
}
-
+
private void InvalidateHeader ()
{
if (IsRealized) {
QueueDrawArea (header_rendering_alloc.X, header_rendering_alloc.Y, header_rendering_alloc.Width, header_rendering_alloc.Height);
}
}
-
+
protected virtual void ColumnCellDataProvider (ColumnCell cell, object boundItem)
{
}
-
+
private bool rules_hint = false;
public bool RulesHint {
get { return rules_hint; }
- set {
- rules_hint = value;
+ set {
+ rules_hint = value;
InvalidateList ();
}
}
-
+
private ListViewRowHeightHandler row_height_handler;
public virtual ListViewRowHeightHandler RowHeightProvider {
get { return row_height_handler; }
@@ -442,32 +442,32 @@ namespace Hyena.Data.Gui
}
}
}
-
+
private bool recompute_row_height = true;
protected bool RecomputeRowHeight {
get { return recompute_row_height; }
- set {
+ set {
recompute_row_height = value;
if (value && IsMapped && IsRealized) {
QueueDraw ();
}
}
}
-
+
private int row_height = 32;
protected int RowHeight {
get {
if (RecomputeRowHeight) {
- row_height = RowHeightProvider != null
- ? RowHeightProvider (this)
+ row_height = RowHeightProvider != null
+ ? RowHeightProvider (this)
: ColumnCellText.ComputeRowHeight (this);
-
+
header_height = 0;
MoveResize (Allocation);
-
+
RecomputeRowHeight = false;
}
-
+
return row_height;
}
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
index c9b3c0b..99ca456 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
@@ -40,20 +40,20 @@ namespace Hyena.Data.Gui
private Rectangle header_rendering_alloc;
private Rectangle list_interaction_alloc;
private Rectangle header_interaction_alloc;
-
+
private Gdk.Window event_window;
-
+
protected Rectangle ListAllocation {
get { return list_rendering_alloc; }
}
-
+
protected override void OnRealized ()
{
WidgetFlags |= WidgetFlags.Realized | WidgetFlags.NoWindow;
-
+
GdkWindow = Parent.GdkWindow;
cell_context.Drawable = GdkWindow;
-
+
WindowAttr attributes = new WindowAttr ();
attributes.WindowType = Gdk.WindowType.Child;
attributes.X = Allocation.X;
@@ -69,74 +69,74 @@ namespace Hyena.Data.Gui
EventMask.ButtonReleaseMask |
EventMask.LeaveNotifyMask |
EventMask.ExposureMask);
-
+
WindowAttributesType attributes_mask =
WindowAttributesType.X | WindowAttributesType.Y | WindowAttributesType.Wmclass;
-
+
event_window = new Gdk.Window (GdkWindow, attributes, attributes_mask);
event_window.UserData = Handle;
-
+
OnDragSourceSet ();
MoveResize (Allocation);
-
+
base.OnRealized ();
}
-
+
protected override void OnUnrealized ()
{
WidgetFlags &= ~WidgetFlags.Realized;
-
+
event_window.UserData = IntPtr.Zero;
Hyena.Gui.GtkWorkarounds.WindowDestroy (event_window);
event_window = null;
-
+
base.OnUnrealized ();
}
-
+
protected override void OnMapped ()
{
WidgetFlags |= WidgetFlags.Mapped;
event_window.Show ();
}
-
+
protected override void OnUnmapped ()
{
WidgetFlags &= ~WidgetFlags.Mapped;
event_window.Hide ();
}
-
+
protected int TranslateToListY (int y)
{
return y - list_interaction_alloc.Y;
}
-
+
private void MoveResize (Rectangle allocation)
{
if (Theme == null) {
return;
}
-
+
header_rendering_alloc = allocation;
header_rendering_alloc.Height = HeaderHeight;
-
+
list_rendering_alloc.X = header_rendering_alloc.X + Theme.TotalBorderWidth;
list_rendering_alloc.Y = header_rendering_alloc.Bottom + Theme.TotalBorderWidth;
list_rendering_alloc.Width = allocation.Width - Theme.TotalBorderWidth * 2;
list_rendering_alloc.Height = allocation.Height - (list_rendering_alloc.Y - allocation.Y) -
Theme.TotalBorderWidth;
-
+
header_interaction_alloc = header_rendering_alloc;
header_interaction_alloc.X = list_rendering_alloc.X;
header_interaction_alloc.Width = list_rendering_alloc.Width;
header_interaction_alloc.Height += Theme.BorderWidth;
header_interaction_alloc.Offset (-allocation.X, -allocation.Y);
-
+
list_interaction_alloc = list_rendering_alloc;
list_interaction_alloc.Offset (-allocation.X, -allocation.Y);
-
+
header_width = header_interaction_alloc.Width;
}
-
+
protected override void OnSizeRequested (ref Requisition requisition)
{
// TODO give the minimum height of the header
@@ -146,19 +146,19 @@ namespace Hyena.Data.Gui
requisition.Width = Theme.TotalBorderWidth * 2;
requisition.Height = HeaderHeight + Theme.TotalBorderWidth * 2;
}
-
+
protected override void OnSizeAllocated (Rectangle allocation)
{
base.OnSizeAllocated (allocation);
-
+
if (IsRealized) {
event_window.MoveResize (allocation);
}
-
+
MoveResize (allocation);
RecalculateColumnSizes ();
RegenerateColumnCache ();
-
+
if (vadjustment != null) {
hadjustment.PageSize = header_interaction_alloc.Width;
hadjustment.PageIncrement = header_interaction_alloc.Width;
@@ -166,15 +166,15 @@ namespace Hyena.Data.Gui
vadjustment.PageIncrement = list_rendering_alloc.Height;
UpdateAdjustments ();
}
-
+
ICareAboutView model = Model as ICareAboutView;
if (model != null) {
model.RowsInView = RowsInView;
}
-
+
InvalidateList ();
}
-
+
protected int RowsInView {
get { return (int) Math.Ceiling ((list_rendering_alloc.Height + RowHeight) / (double) RowHeight); }
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs b/src/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs
index f31047b..148fc13 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs
@@ -43,26 +43,26 @@ namespace Hyena.Data.Gui
{
private View view;
private Model model;
-
+
public ListViewTestModule () : base ("ListView")
{
WindowPosition = WindowPosition.Center;
SetDefaultSize (800, 600);
-
+
ScrolledWindow scroll = new ScrolledWindow ();
scroll.HscrollbarPolicy = PolicyType.Automatic;
scroll.VscrollbarPolicy = PolicyType.Automatic;
-
+
view = new View ();
model = new Model ();
-
+
scroll.Add (view);
Add (scroll);
ShowAll ();
-
+
view.SetModel (model);
}
-
+
private class View : ListView<ModelItem>
{
public View ()
@@ -79,15 +79,15 @@ namespace Hyena.Data.Gui
);
}
}
-
+
private class Model : IListModel<ModelItem>
{
private List<ModelItem> store = new List<ModelItem> ();
private Selection selection = new Selection ();
-
+
public event EventHandler Cleared;
public event EventHandler Reloaded;
-
+
public Model ()
{
Random random = new Random (0);
@@ -95,15 +95,15 @@ namespace Hyena.Data.Gui
store.Add (new ModelItem (i, random));
}
}
-
+
public void Clear ()
{
}
-
+
public void Reload ()
{
}
-
+
public int Count {
get { return store.Count; }
}
@@ -111,17 +111,17 @@ namespace Hyena.Data.Gui
public bool CanReorder {
get { return false; }
}
-
+
public ModelItem this[int index] {
get { return store[index]; }
}
-
+
public Selection Selection {
get { return selection; }
}
}
-
- private class ModelItem
+
+ private class ModelItem
{
public ModelItem (int i, Random rand)
{
@@ -133,7 +133,7 @@ namespace Hyena.Data.Gui
f = rand.Next (0, 1) == 1;
g = rand.Next (0, 5);
}
-
+
string a; public string A { get { return a; } }
int b; public int B { get { return b; } }
double c; public double C { get { return c; } }
@@ -142,16 +142,16 @@ namespace Hyena.Data.Gui
bool f; public bool F { get { return f; } set { f = value; } }
int g; public int G { get { return g; } set { g = value; } }
}
-
+
private class ColumnCellDoodle : ColumnCell, IInteractiveCell
{
private Random random = new Random ();
private bool red = false;
-
+
public ColumnCellDoodle (string property, bool expand) : base (property, expand)
{
}
-
+
public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
{
red = !red;
@@ -159,7 +159,7 @@ namespace Hyena.Data.Gui
cr.Rectangle (0, 0, cellWidth, cellHeight);
cr.Color = CairoExtensions.RgbaToColor (red ? 0xff000099 : 0x00000099);
cr.Fill ();
-
+
List<Gdk.Point> points = Points;
for (int i = 0, n = points.Count; i < n; i++) {
if (i == 0) {
@@ -168,42 +168,42 @@ namespace Hyena.Data.Gui
cr.LineTo (points[i].X, points[i].Y);
}
}
-
+
cr.Color = CairoExtensions.RgbToColor ((uint)random.Next (0xffffff));
cr.LineWidth = 1;
cr.Stroke ();
}
-
+
private object last_pressed_bound;
-
+
public bool ButtonEvent (int x, int y, bool pressed, Gdk.EventButton evnt)
{
if (!pressed) {
last_pressed_bound = null;
return false;
}
-
+
last_pressed_bound = BoundObject;
Points.Add (new Gdk.Point (x, y));
return true;
}
-
+
public bool MotionEvent (int x, int y, Gdk.EventMotion evnt)
{
if (last_pressed_bound == BoundObject) {
Points.Add (new Gdk.Point (x, y));
return true;
}
-
+
return false;
}
-
+
public bool PointerLeaveEvent ()
{
last_pressed_bound = null;
return true;
}
-
+
private List<Gdk.Point> Points {
get { return (List<Gdk.Point>)BoundObject; }
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/ObjectListView.cs b/src/Hyena.Gui/Hyena.Data.Gui/ObjectListView.cs
index a17040e..b2525b4 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/ObjectListView.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/ObjectListView.cs
@@ -31,12 +31,12 @@ using System;
namespace Hyena.Data.Gui
{
public class ObjectListView : ListView<object>
- {
+ {
public ObjectListView () : base ()
{
ColumnController = new ColumnController();
}
-
+
protected override void OnModelReloaded ()
{
ColumnController.Clear ();
@@ -44,7 +44,7 @@ namespace Hyena.Data.Gui
ColumnController.Add (new Column (column_description));
}
}
-
+
public new IObjectListModel Model {
get { return (IObjectListModel)base.Model; }
}
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/RowActivatedHandler.cs b/src/Hyena.Gui/Hyena.Data.Gui/RowActivatedHandler.cs
index 6d5f4c4..66dd52d 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/RowActivatedHandler.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/RowActivatedHandler.cs
@@ -31,12 +31,12 @@ using System;
namespace Hyena.Data.Gui
{
public delegate void RowActivatedHandler<T> (object o, RowActivatedArgs<T> args);
-
+
public class RowActivatedArgs<T> : EventArgs
{
private int row;
private T row_value;
-
+
public RowActivatedArgs (int row, T rowValue)
{
this.row = row;
diff --git a/src/Hyena.Gui/Hyena.Data.Gui/SortableColumn.cs b/src/Hyena.Gui/Hyena.Data.Gui/SortableColumn.cs
index 86d7723..ebd2a45 100644
--- a/src/Hyena.Gui/Hyena.Data.Gui/SortableColumn.cs
+++ b/src/Hyena.Gui/Hyena.Data.Gui/SortableColumn.cs
@@ -38,24 +38,24 @@ namespace Hyena.Data.Gui
private string sort_key;
private SortType sort_type = SortType.Ascending;
private Hyena.Query.QueryField field;
-
- public SortableColumn(string title, ColumnCell cell, double width, string sort_key, bool visible) :
+
+ public SortableColumn(string title, ColumnCell cell, double width, string sort_key, bool visible) :
base(title, cell, width, visible)
{
this.sort_key = sort_key;
}
-
+
public SortableColumn(ColumnCell header_cell, string title, ColumnCell cell, double width, string sort_key, bool visible) :
base(header_cell, title, cell, width, visible)
{
this.sort_key = sort_key;
}
-
+
public string SortKey {
get { return sort_key; }
set { sort_key = value; }
}
-
+
public SortType SortType {
get { return sort_type; }
set { sort_type = value; }
diff --git a/src/Hyena.Gui/Hyena.Gui.Dialogs/ExceptionDialog.cs b/src/Hyena.Gui/Hyena.Gui.Dialogs/ExceptionDialog.cs
index 7b179ef..b9271c8 100644
--- a/src/Hyena.Gui/Hyena.Gui.Dialogs/ExceptionDialog.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Dialogs/ExceptionDialog.cs
@@ -41,26 +41,26 @@ namespace Hyena.Gui.Dialogs
{
private AccelGroup accel_group;
private string debugInfo;
-
+
public ExceptionDialog(Exception e) : base()
{
debugInfo = BuildExceptionMessage(e);
-
+
HasSeparator = false;
BorderWidth = 5;
Resizable = false;
Title = Catalog.GetString("Banshee Encountered a Fatal Error");
-
+
VBox.Spacing = 12;
ActionArea.Layout = ButtonBoxStyle.End;
accel_group = new AccelGroup();
AddAccelGroup(accel_group);
-
+
HBox hbox = new HBox(false, 12);
hbox.BorderWidth = 5;
VBox.PackStart(hbox, false, false, 0);
-
+
Image image = new Image(Stock.DialogError, IconSize.Dialog);
image.Yalign = 0.0f;
hbox.PackStart(image, true, true, 0);
@@ -77,7 +77,7 @@ namespace Hyena.Gui.Dialogs
label_vbox.PackStart(label, false, false, 0);
label = new Label(e.Message);
-
+
label.UseMarkup = true;
label.UseUnderline = false;
label.Justify = Gtk.Justification.Left;
@@ -85,7 +85,7 @@ namespace Hyena.Gui.Dialogs
label.SetAlignment(0.0f, 0.5f);
label_vbox.PackStart(label, false, false, 0);
- Label details_label = new Label(String.Format("<b>{0}</b>",
+ Label details_label = new Label(String.Format("<b>{0}</b>",
GLib.Markup.EscapeText(Catalog.GetString("Error Details"))));
details_label.UseMarkup = true;
Expander details_expander = new Expander("Details");
@@ -94,11 +94,11 @@ namespace Hyena.Gui.Dialogs
ScrolledWindow scroll = new ScrolledWindow();
TextView view = new TextView();
-
+
scroll.HscrollbarPolicy = PolicyType.Automatic;
scroll.VscrollbarPolicy = PolicyType.Automatic;
scroll.AddWithViewport(view);
-
+
scroll.SetSizeRequest(450, 250);
view.Editable = false;
@@ -121,34 +121,34 @@ namespace Hyena.Gui.Dialogs
if(is_default) {
DefaultResponse = response;
- button.AddAccelerator("activate", accel_group, (uint)Gdk.Key.Return,
+ button.AddAccelerator("activate", accel_group, (uint)Gdk.Key.Return,
0, AccelFlags.Visible);
}
}
-
+
private string BuildExceptionMessage(Exception e)
{
System.Text.StringBuilder msg = new System.Text.StringBuilder();
-
+
msg.Append(Catalog.GetString("An unhandled exception was thrown: "));
-
+
Stack<Exception> exception_chain = new Stack<Exception> ();
while (e != null) {
exception_chain.Push (e);
e = e.InnerException;
}
-
+
while (exception_chain.Count > 0) {
e = exception_chain.Pop ();
msg.AppendFormat ("{0}\n\n{1}\n", e.Message, e.StackTrace);
};
-
+
msg.Append("\n");
msg.AppendFormat(".NET Version: {0}\n", Environment.Version);
msg.AppendFormat("OS Version: {0}\n", Environment.OSVersion);
msg.Append("\nAssembly Version Information:\n\n");
-
+
foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
AssemblyName name = asm.GetName();
msg.AppendFormat("{0} ({1})\n", name.Name, name.Version);
@@ -160,21 +160,21 @@ namespace Hyena.Gui.Dialogs
try {
msg.AppendFormat("\nPlatform Information: {0}", BuildPlatformString());
-
+
msg.Append("\n\nDisribution Information:\n\n");
-
+
Dictionary<string, string> lsb = LsbVersionInfo.Harvest;
-
+
foreach(string lsbfile in lsb.Keys) {
msg.AppendFormat("[{0}]\n", lsbfile);
msg.AppendFormat("{0}\n", lsb[lsbfile]);
}
} catch {
}
-
+
return msg.ToString();
}
-
+
private string BuildPlatformString()
{
ProcessStartInfo startInfo = new ProcessStartInfo();
@@ -182,8 +182,8 @@ namespace Hyena.Gui.Dialogs
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
-
- foreach(string unameprog in new string [] {
+
+ foreach(string unameprog in new string [] {
"/usr/bin/uname", "/bin/uname", "/usr/local/bin/uname",
"/sbin/uname", "/usr/sbin/uname", "/usr/local/sbin/uname"}) {
try {
@@ -194,10 +194,10 @@ namespace Hyena.Gui.Dialogs
continue;
}
}
-
+
return null;
}
-
+
private class LsbVersionInfo
{
private string [] filesToCheck = {
@@ -205,9 +205,9 @@ namespace Hyena.Gui.Dialogs
"slackware-version",
"debian_version"
};
-
- private Dictionary<string, string> harvest = new Dictionary<string, string>();
-
+
+ private Dictionary<string, string> harvest = new Dictionary<string, string>();
+
public LsbVersionInfo()
{
foreach(string pattern in filesToCheck) {
@@ -218,11 +218,11 @@ namespace Hyena.Gui.Dialogs
}
}
}
-
+
public Dictionary<string, string> Findings {
get { return harvest; }
}
-
+
public static Dictionary<string, string> Harvest {
get { return (new LsbVersionInfo()).Findings; }
}
diff --git a/src/Hyena.Gui/Hyena.Gui.Dialogs/VersionInformationDialog.cs b/src/Hyena.Gui/Hyena.Gui.Dialogs/VersionInformationDialog.cs
index faaca1a..484dc0a 100644
--- a/src/Hyena.Gui/Hyena.Gui.Dialogs/VersionInformationDialog.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Dialogs/VersionInformationDialog.cs
@@ -38,78 +38,78 @@ namespace Hyena.Gui.Dialogs
private Label path_label;
private TreeView version_tree;
private TreeStore version_store;
-
+
public VersionInformationDialog() : base()
{
AccelGroup accel_group = new AccelGroup();
- AddAccelGroup(accel_group);
+ AddAccelGroup(accel_group);
Modal = true;
-
+
Button button = new Button("gtk-close");
button.CanDefault = true;
button.UseStock = true;
button.Show();
DefaultResponse = ResponseType.Close;
- button.AddAccelerator("activate", accel_group, (uint)Gdk.Key.Escape,
+ button.AddAccelerator("activate", accel_group, (uint)Gdk.Key.Escape,
0, Gtk.AccelFlags.Visible);
-
+
AddActionWidget(button, ResponseType.Close);
-
+
Title = Catalog.GetString("Assembly Version Information");
BorderWidth = 10;
-
+
version_tree = new TreeView();
-
+
version_tree.RulesHint = true;
version_tree.AppendColumn(Catalog.GetString("Assembly Name"),
new CellRendererText(), "text", 0);
version_tree.AppendColumn(Catalog.GetString("Version"),
new CellRendererText(), "text", 1);
-
+
version_tree.Model = FillStore();
version_tree.CursorChanged += OnCursorChanged;
-
+
ScrolledWindow scroll = new ScrolledWindow();
scroll.Add(version_tree);
scroll.ShadowType = ShadowType.In;
scroll.SetSizeRequest(420, 200);
-
+
VBox.PackStart(scroll, true, true, 0);
VBox.Spacing = 5;
-
+
path_label = new Label();
path_label.Ellipsize = Pango.EllipsizeMode.End;
path_label.Hide();
path_label.Xalign = 0.0f;
path_label.Yalign = 1.0f;
VBox.PackStart(path_label, false, true, 0);
-
+
scroll.ShowAll();
}
-
+
private void OnCursorChanged(object o, EventArgs args)
{
TreeIter iter;
-
+
if(!version_tree.Selection.GetSelected(out iter)) {
path_label.Hide();
return;
}
-
+
object path = version_store.GetValue(iter, 2);
-
+
if(path == null) {
path_label.Hide();
return;
}
-
+
path_label.Text = path as string;
path_label.Show();
}
-
+
private TreeStore FillStore()
{
- version_store = new TreeStore(typeof(string),
+ version_store = new TreeStore(typeof(string),
typeof(string), typeof(string));
foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
diff --git a/src/Hyena.Gui/Hyena.Gui.Theatrics/Actor.cs b/src/Hyena.Gui/Hyena.Gui.Theatrics/Actor.cs
index 95c28ed..bf5e8a2 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theatrics/Actor.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theatrics/Actor.cs
@@ -33,25 +33,25 @@ namespace Hyena.Gui.Theatrics
public class Actor<T>
{
private T target;
-
+
private DateTime start_time;
private uint duration;
private double frames;
private double percent;
private bool can_expire = true;
-
+
public Actor (T target, uint duration)
{
this.target = target;
this.duration = duration;
Reset ();
}
-
+
public void Reset ()
{
Reset (duration);
}
-
+
public void Reset (uint duration)
{
start_time = DateTime.Now;
@@ -59,13 +59,13 @@ namespace Hyena.Gui.Theatrics
percent = 0.0;
this.duration = duration;
}
-
+
public virtual void Step ()
{
if (!CanExpire && percent >= 1.0) {
Reset ();
}
-
+
percent = (DateTime.Now - start_time).TotalMilliseconds / duration;
frames++;
}
@@ -73,32 +73,32 @@ namespace Hyena.Gui.Theatrics
public bool Expired {
get { return CanExpire && percent >= 1.0; }
}
-
+
public bool CanExpire {
get { return can_expire; }
set { can_expire = value; }
}
-
+
public T Target {
get { return target; }
}
-
+
public double Duration {
get { return duration; }
}
-
+
public DateTime StartTime {
get { return start_time; }
}
-
+
public double Frames {
get { return frames; }
}
-
+
public double FramesPerSecond {
get { return frames / ((double)duration / 1000.0); }
}
-
+
public double Percent {
get { return Math.Max (0.0, Math.Min (1.0, percent)); }
}
diff --git a/src/Hyena.Gui/Hyena.Gui.Theatrics/Choreographer.cs b/src/Hyena.Gui/Hyena.Gui.Theatrics/Choreographer.cs
index 17151ee..98a510f 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theatrics/Choreographer.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theatrics/Choreographer.cs
@@ -51,53 +51,53 @@ namespace Hyena.Gui.Theatrics
ExponentialInOut,
Sine,
}
-
+
public static class Choreographer
{
public static int PixelCompose (double percent, int size, Easing easing)
{
return (int)Math.Round (Compose (percent, size, easing));
}
-
+
public static double Compose (double percent, double scale, Easing easing)
{
return scale * Compose (percent, easing);
}
-
+
public static double Compose (double percent, Easing easing)
{
if (percent < 0.0 || percent > 1.0) {
throw new ArgumentOutOfRangeException ("percent", "must be between 0 and 1 inclusive");
}
-
+
switch (easing) {
case Easing.QuadraticIn:
return percent * percent;
-
+
case Easing.QuadraticOut:
return -1.0 * percent * (percent - 2.0);
-
+
case Easing.QuadraticInOut:
percent *= 2.0;
return percent < 1.0
? percent * percent * 0.5
: -0.5 * (--percent * (percent - 2.0) - 1.0);
-
+
case Easing.ExponentialIn:
return Math.Pow (2.0, 10.0 * (percent - 1.0));
-
+
case Easing.ExponentialOut:
return -Math.Pow (2.0, -10.0 * percent) + 1.0;
-
+
case Easing.ExponentialInOut:
percent *= 2.0;
return percent < 1.0
? 0.5 * Math.Pow (2.0, 10.0 * (percent - 1.0))
: 0.5 * (-Math.Pow (2.0, -10.0 * --percent) + 2.0);
-
+
case Easing.Sine:
return Math.Sin (percent * Math.PI);
-
+
case Easing.Linear:
default:
return percent;
diff --git a/src/Hyena.Gui/Hyena.Gui.Theatrics/Pulsator.cs b/src/Hyena.Gui/Hyena.Gui.Theatrics/Pulsator.cs
index 91d74c0..6531e62 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theatrics/Pulsator.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theatrics/Pulsator.cs
@@ -35,80 +35,80 @@ namespace Hyena.Gui.Theatrics
private Stage<T> stage;
public Stage<T> Stage {
get { return stage; }
- set {
+ set {
if (stage == value) {
return;
}
-
+
if (stage != null) {
stage.ActorStep -= OnActorStep;
}
-
+
stage = value;
-
+
if (stage != null) {
stage.ActorStep += OnActorStep;
}
}
}
-
+
private T target;
public T Target {
get { return target; }
set { target = value; }
}
-
+
public double Percent {
get { return IsPulsing ? stage[Target].Percent : 0; }
}
-
+
public bool IsPulsing {
get { return stage != null && stage.Contains (Target); }
}
-
+
public bool Stopping {
get { return !IsPulsing ? true : stage[Target].CanExpire; }
}
-
+
#pragma warning disable 0067
// FIXME: This is to mute gmcs: https://bugzilla.novell.com/show_bug.cgi?id=360455
public event EventHandler Pulse;
#pragma warning restore 0067
-
+
public Pulsator ()
{
}
-
- public Pulsator (Stage<T> stage)
+
+ public Pulsator (Stage<T> stage)
{
Stage = stage;
}
-
+
public void StartPulsing ()
{
if (!Stage.Contains (Target)) {
Stage.Add (Target);
}
-
+
Stage[Target].CanExpire = false;
}
-
+
public void StopPulsing ()
{
if (Stage.Contains (Target)) {
Stage[Target].CanExpire = true;
}
}
-
+
private bool OnActorStep (Actor<T> actor)
{
if (actor.Target == target) {
OnPulse ();
}
-
+
return true;
}
-
+
protected virtual void OnPulse ()
{
EventHandler handler = Pulse;
diff --git a/src/Hyena.Gui/Hyena.Gui.Theatrics/SingleActorStage.cs b/src/Hyena.Gui/Hyena.Gui.Theatrics/SingleActorStage.cs
index faddf76..04acc2c 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theatrics/SingleActorStage.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theatrics/SingleActorStage.cs
@@ -33,30 +33,30 @@ namespace Hyena.Gui.Theatrics
public class SingleActorStage : Stage<object>
{
private object target = new object ();
-
+
public SingleActorStage () : base ()
{
}
-
+
public SingleActorStage (uint actorDuration) : base (actorDuration)
{
}
-
+
protected override bool OnActorStep (Actor<object> actor)
{
return true;
}
-
+
public void Reset ()
{
AddOrReset (target);
}
-
+
public void Reset (uint duration)
{
AddOrReset (target, duration);
}
-
+
public Actor<object> Actor {
get { return this[target]; }
}
diff --git a/src/Hyena.Gui/Hyena.Gui.Theatrics/Stage.cs b/src/Hyena.Gui/Hyena.Gui.Theatrics/Stage.cs
index 8f0cc98..f60985d 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theatrics/Stage.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theatrics/Stage.cs
@@ -32,128 +32,128 @@ using System.Collections.Generic;
namespace Hyena.Gui.Theatrics
{
public class Stage<T>
- {
+ {
public delegate bool ActorStepHandler (Actor<T> actor);
-
+
private Dictionary<T, Actor<T>> actors = new Dictionary<T, Actor<T>> ();
private uint timeout_id;
-
+
private uint update_frequency = 30;
private uint default_duration = 1000;
private bool playing = true;
-
+
public event ActorStepHandler ActorStep;
-
+
#pragma warning disable 0067
// FIXME: This is to mute gmcs: https://bugzilla.novell.com/show_bug.cgi?id=360455
public event EventHandler Iteration;
#pragma warning restore 0067
-
+
public Stage ()
{
}
-
+
public Stage (uint actorDuration)
{
default_duration = actorDuration;
}
-
+
public Actor<T> this[T target] {
get {
if (actors.ContainsKey (target)) {
return actors[target];
}
-
+
return null;
}
}
-
+
public bool Contains (T target)
{
return actors.ContainsKey (target);
}
-
+
public Actor<T> Add (T target)
{
lock (this) {
return Add (target, default_duration);
}
}
-
+
public Actor<T> Add (T target, uint duration)
{
lock (this) {
if (Contains (target)) {
throw new InvalidOperationException ("Stage already contains this actor");
}
-
+
Actor<T> actor = new Actor<T> (target, duration);
actors.Add (target, actor);
-
+
CheckTimeout ();
-
+
return actor;
}
}
-
+
public Actor<T> AddOrReset (T target)
{
lock (this) {
return AddOrResetCore (target, null);
}
}
-
+
public Actor<T> AddOrReset (T target, uint duration)
{
lock (this) {
return AddOrResetCore (target, duration);
}
}
-
+
private Actor<T> AddOrResetCore (T target, uint? duration)
{
lock (this) {
if (Contains (target)) {
Actor<T> actor = this[target];
-
+
if (duration == null) {
actor.Reset ();
} else {
actor.Reset (duration.Value);
}
-
+
CheckTimeout ();
-
+
return actor;
}
-
+
return Add (target);
}
}
-
+
public void Reset (T target)
{
lock (this) {
ResetCore (target, null);
}
}
-
+
public void Reset (T target, uint duration)
{
lock (this) {
ResetCore (target, duration);
}
}
-
+
private void ResetCore (T target, uint? duration)
{
lock (this) {
if (!Contains (target)) {
throw new InvalidOperationException ("Stage does not contain this actor");
}
-
+
CheckTimeout ();
-
+
if (duration == null) {
this [target].Reset ();
} else {
@@ -161,7 +161,7 @@ namespace Hyena.Gui.Theatrics
}
}
}
-
+
private void CheckTimeout ()
{
if ((!Playing || actors.Count == 0) && timeout_id > 0) {
@@ -173,29 +173,29 @@ namespace Hyena.Gui.Theatrics
return;
}
}
-
+
private bool OnTimeout ()
{
if (!Playing || this.actors.Count == 0) {
timeout_id = 0;
return false;
}
-
+
Queue<Actor<T>> actors = new Queue<Actor<T>> (this.actors.Values);
while (actors.Count > 0) {
Actor<T> actor = actors.Dequeue ();
actor.Step ();
-
+
if (!OnActorStep (actor) || actor.Expired) {
this.actors.Remove (actor.Target);
}
}
-
+
OnIteration ();
-
+
return true;
}
-
+
protected virtual bool OnActorStep (Actor<T> actor)
{
ActorStepHandler handler = ActorStep;
@@ -208,7 +208,7 @@ namespace Hyena.Gui.Theatrics
}
return false;
}
-
+
protected virtual void OnIteration ()
{
EventHandler handler = Iteration;
@@ -216,21 +216,21 @@ namespace Hyena.Gui.Theatrics
handler (this, EventArgs.Empty);
}
}
-
+
public void Play ()
{
lock (this) {
Playing = true;
}
}
-
+
public void Pause ()
{
lock (this) {
Playing = false;
}
}
-
+
public void Exeunt ()
{
lock (this) {
@@ -238,12 +238,12 @@ namespace Hyena.Gui.Theatrics
CheckTimeout ();
}
}
-
+
public uint DefaultActorDuration {
get { return default_duration; }
set { lock (this) { default_duration = value; } }
}
-
+
public bool Playing {
get { return playing; }
set {
@@ -251,13 +251,13 @@ namespace Hyena.Gui.Theatrics
if (playing == value) {
return;
}
-
- playing = value;
+
+ playing = value;
CheckTimeout ();
}
}
}
-
+
public uint UpdateFrequency {
get { return update_frequency; }
set {
@@ -268,7 +268,7 @@ namespace Hyena.Gui.Theatrics
}
}
}
-
+
public int ActorCount {
get { return actors.Count; }
}
diff --git a/src/Hyena.Gui/Hyena.Gui.Theatrics/Tests/ChoreographerTests.cs b/src/Hyena.Gui/Hyena.Gui.Theatrics/Tests/ChoreographerTests.cs
index d63911a..5447fca 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theatrics/Tests/ChoreographerTests.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theatrics/Tests/ChoreographerTests.cs
@@ -33,7 +33,7 @@ using NUnit.Framework;
using Hyena;
using Hyena.Gui.Theatrics;
-
+
namespace Hyena.Gui.Theatrics.Tests
{
[TestFixture]
@@ -46,67 +46,67 @@ namespace Hyena.Gui.Theatrics.Tests
Assert.AreEqual (values[(int)j], value);
}
}
-
+
[Test]
public void QuadraticInCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 0, 1, 2, 4, 6, 9, 12, 16, 20, 25, 30, 36, 42, 49, 56, 64, 72, 81, 90, 100
}, Easing.QuadraticIn);
}
-
+
[Test]
public void QuadraticOutCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 10, 19, 28, 36, 44, 51, 58, 64, 70, 75, 80, 84, 88, 91, 94, 96, 98, 99, 100, 100
}, Easing.QuadraticOut);
}
-
+
[Test]
public void QuadraticInOutCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 1, 2, 4, 8, 12, 18, 24, 32, 40, 50, 60, 68, 76, 82, 88, 92, 96, 98, 100, 100
}, Easing.QuadraticInOut);
}
-
+
[Test]
public void ExponentialInCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 6, 9, 12, 18, 25, 35, 50, 71, 100
}, Easing.ExponentialIn);
}
-
+
[Test]
public void ExponentialOutCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 29, 50, 65, 75, 82, 88, 91, 94, 96, 97, 98, 98, 99, 99, 99, 100, 100, 100, 100, 100
}, Easing.ExponentialOut);
}
-
+
[Test]
public void ExponentialInOutCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 0, 0, 0, 1, 2, 3, 6, 13, 25, 50, 75, 88, 94, 97, 98, 99, 100, 100, 100, 100
}, Easing.ExponentialInOut);
}
-
+
[Test]
public void LinearCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100
}, Easing.Linear);
}
-
+
[Test]
public void SineCompose ()
{
- _TestComposeRange (new int [] {
+ _TestComposeRange (new int [] {
0, 16, 31, 45, 59, 71, 81, 89, 95, 99, 100, 99, 95, 89, 81, 71, 59, 45, 31, 16, 0
}, Easing.Sine);
}
diff --git a/src/Hyena.Gui/Hyena.Gui.Theming/GtkColors.cs b/src/Hyena.Gui/Hyena.Gui.Theming/GtkColors.cs
index f67b5ef..4e73dec 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theming/GtkColors.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theming/GtkColors.cs
@@ -32,7 +32,7 @@ using Gtk;
namespace Hyena.Gui.Theming
{
- public enum GtkColorClass
+ public enum GtkColorClass
{
Light,
Mid,
@@ -53,7 +53,7 @@ namespace Hyena.Gui.Theming
public Widget Widget {
get { return widget; }
- set {
+ set {
if (widget == value) {
return;
} else if (widget != null) {
@@ -85,35 +85,35 @@ namespace Hyena.Gui.Theming
{
RefreshColors ();
}
-
+
public Cairo.Color GetWidgetColor (GtkColorClass @class, StateType state)
{
if (gtk_colors == null) {
RefreshColors ();
}
-
+
return gtk_colors[(int)@class * ((int)StateType.Insensitive + 1) + (int)state];
}
-
+
public void RefreshColors ()
{
if (refreshing) {
return;
}
-
+
refreshing = true;
-
+
int sn = (int)StateType.Insensitive + 1;
int cn = (int)GtkColorClass.Foreground + 1;
-
+
if (gtk_colors == null) {
gtk_colors = new Cairo.Color[sn * cn];
}
-
+
for (int c = 0, i = 0; c < cn; c++) {
for (int s = 0; s < sn; s++, i++) {
Gdk.Color color = Gdk.Color.Zero;
-
+
if (widget != null && widget.IsRealized) {
switch ((GtkColorClass)c) {
case GtkColorClass.Light: color = widget.Style.LightColors[s]; break;
@@ -127,13 +127,13 @@ namespace Hyena.Gui.Theming
} else {
color = new Gdk.Color (0, 0, 0);
}
-
+
gtk_colors[c * sn + s] = CairoExtensions.GdkColorToCairoColor (color);
}
}
OnRefreshed ();
-
+
refreshing = false;
}
diff --git a/src/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs b/src/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
index 401f781..3a40506 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
@@ -40,14 +40,14 @@ namespace Hyena.Gui.Theming
public GtkTheme (Widget widget) : base (widget)
{
}
-
+
public static Cairo.Color GetCairoTextMidColor (Widget widget)
{
Cairo.Color text_color = CairoExtensions.GdkColorToCairoColor (widget.Style.Foreground (StateType.Normal));
Cairo.Color background_color = CairoExtensions.GdkColorToCairoColor (widget.Style.Background (StateType.Normal));
return CairoExtensions.AlphaBlend (text_color, background_color, 0.5);
}
-
+
public static Gdk.Color GetGdkTextMidColor (Widget widget)
{
Cairo.Color color = GetCairoTextMidColor (widget);
@@ -83,7 +83,7 @@ namespace Hyena.Gui.Theming
Color color_a = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
Color color_b = CairoExtensions.ColorShade (color_a, 1.4);
- RadialGradient fill = new RadialGradient (Context.X, Context.Y, 0,
+ RadialGradient fill = new RadialGradient (Context.X, Context.Y, 0,
Context.X, Context.Y, 2.0 * Context.Radius);
fill.AddColorStop (0, color_a);
fill.AddColorStop (1, color_b);
@@ -97,7 +97,7 @@ namespace Hyena.Gui.Theming
Context.Cairo.LineWidth = Context.LineWidth;
Context.Cairo.Stroke ();
}
-
+
public override void DrawArrow (Context cr, Gdk.Rectangle alloc, Hyena.Data.SortType type)
{
cr.LineWidth = 1;
@@ -107,7 +107,7 @@ namespace Hyena.Gui.Theming
double x2 = x3 + (x3 - x1);
double y1 = alloc.Y;
double y2 = alloc.Bottom;
-
+
if (type == Hyena.Data.SortType.Ascending) {
cr.MoveTo (x1, y1);
cr.LineTo (x2, y1);
@@ -119,7 +119,7 @@ namespace Hyena.Gui.Theming
cr.LineTo (x1, y2);
cr.LineTo (x3, y1);
}
-
+
cr.Color = Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
cr.FillPreserve ();
cr.Color = Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal);
@@ -138,7 +138,7 @@ namespace Hyena.Gui.Theming
CairoExtensions.RoundedRectangle (cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, CairoCorners.All);
cr.Fill ();
}
-
+
public override void DrawFrameBorder (Cairo.Context cr, Gdk.Rectangle alloc)
{
cr.LineWidth = BorderWidth;
@@ -148,16 +148,16 @@ namespace Hyena.Gui.Theming
alloc.Width - BorderWidth, alloc.Height - BorderWidth, Context.Radius, CairoCorners.All);
cr.Stroke();
}
-
+
public override void DrawColumnHighlight (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
{
Cairo.Color light_color = CairoExtensions.ColorShade (color, 1.6);
Cairo.Color dark_color = CairoExtensions.ColorShade (color, 1.3);
-
+
LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom - 1);
grad.AddColorStop (0, light_color);
grad.AddColorStop (1, dark_color);
-
+
cr.Pattern = grad;
cr.Rectangle (alloc.X + 1.5, alloc.Y + 1.5, alloc.Width - 3, alloc.Height - 2);
cr.Fill ();
@@ -169,49 +169,49 @@ namespace Hyena.Gui.Theming
Cairo.Color gtk_background_color = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal);
Cairo.Color light_color = CairoExtensions.ColorShade (gtk_background_color, 1.1);
Cairo.Color dark_color = CairoExtensions.ColorShade (gtk_background_color, 0.95);
-
+
CairoCorners corners = CairoCorners.TopLeft | CairoCorners.TopRight;
LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom);
grad.AddColorStop (0, light_color);
grad.AddColorStop (0.75, dark_color);
grad.AddColorStop (0, light_color);
-
+
cr.Pattern = grad;
CairoExtensions.RoundedRectangle (cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, corners);
cr.Fill ();
-
+
cr.Color = border_color;
cr.Rectangle (alloc.X, alloc.Bottom, alloc.Width, BorderWidth);
cr.Fill ();
grad.Destroy ();
}
-
+
public override void DrawHeaderSeparator (Cairo.Context cr, Gdk.Rectangle alloc, int x)
{
Cairo.Color gtk_background_color = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal);
Cairo.Color dark_color = CairoExtensions.ColorShade (gtk_background_color, 0.80);
Cairo.Color light_color = CairoExtensions.ColorShade (gtk_background_color, 1.1);
-
+
int y_1 = alloc.Top + 4;
int y_2 = alloc.Bottom - 3;
-
+
cr.LineWidth = 1;
cr.Antialias = Cairo.Antialias.None;
-
+
cr.Color = dark_color;
cr.MoveTo (x, y_1);
cr.LineTo (x, y_2);
cr.Stroke ();
-
+
cr.Color = light_color;
cr.MoveTo (x + 1, y_1);
cr.LineTo (x + 1, y_2);
cr.Stroke ();
-
+
cr.Antialias = Cairo.Antialias.Default;
}
-
+
public override void DrawListBackground (Context cr, Gdk.Rectangle alloc, Color color)
{
color.A = Context.FillAlpha;
@@ -219,7 +219,7 @@ namespace Hyena.Gui.Theming
cr.Rectangle (alloc.X, alloc.Y, alloc.Width, alloc.Height);
cr.Fill ();
}
-
+
public override void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height,
bool filled, bool stroked, Cairo.Color color, CairoCorners corners)
{
@@ -228,19 +228,19 @@ namespace Hyena.Gui.Theming
Cairo.Color selection_stroke = CairoExtensions.ColorShade (selection_color, 0.85);
selection_highlight.A = 0.5;
selection_stroke.A = color.A;
-
+
if (filled) {
Cairo.Color selection_fill_light = CairoExtensions.ColorShade (selection_color, 1.12);
Cairo.Color selection_fill_dark = selection_color;
-
+
selection_fill_light.A = color.A;
selection_fill_dark.A = color.A;
-
+
LinearGradient grad = new LinearGradient (x, y, x, y + height);
grad.AddColorStop (0, selection_fill_light);
grad.AddColorStop (0.4, selection_fill_dark);
grad.AddColorStop (1, selection_fill_light);
-
+
cr.Pattern = grad;
CairoExtensions.RoundedRectangle (cr, x, y, width, height, Context.Radius, corners, true);
cr.Fill ();
@@ -258,12 +258,12 @@ namespace Hyena.Gui.Theming
if (stroked) {
cr.LineWidth = 1.0;
cr.Color = selection_stroke;
- CairoExtensions.RoundedRectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1,
+ CairoExtensions.RoundedRectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1,
Context.Radius, corners, true);
cr.Stroke ();
}
}
-
+
public override void DrawRowRule(Cairo.Context cr, int x, int y, int width, int height)
{
cr.Color = new Cairo.Color (rule_color.R, rule_color.G, rule_color.B, Context.FillAlpha);
diff --git a/src/Hyena.Gui/Hyena.Gui.Theming/Theme.cs b/src/Hyena.Gui/Hyena.Gui.Theming/Theme.cs
index f870f4e..db835fe 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theming/Theme.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theming/Theme.cs
@@ -44,7 +44,7 @@ namespace Hyena.Gui.Theming
private Cairo.Color selection_fill;
private Cairo.Color selection_stroke;
-
+
private Cairo.Color view_fill;
private Cairo.Color view_fill_transparent;
@@ -69,7 +69,7 @@ namespace Hyena.Gui.Theming
{
selection_fill = colors.GetWidgetColor (GtkColorClass.Dark, StateType.Active);
selection_stroke = colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
-
+
view_fill = colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
view_fill_transparent = view_fill;
view_fill_transparent.A = 0;
@@ -78,55 +78,55 @@ namespace Hyena.Gui.Theming
#region Drawing
public abstract void DrawPie (double fraction);
-
+
public abstract void DrawArrow (Cairo.Context cr, Gdk.Rectangle alloc, Hyena.Data.SortType type);
-
+
public void DrawFrame (Cairo.Context cr, Gdk.Rectangle alloc, bool baseColor)
{
DrawFrameBackground (cr, alloc, baseColor);
DrawFrameBorder (cr, alloc);
}
-
+
public void DrawFrame (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
{
DrawFrameBackground (cr, alloc, color);
DrawFrameBorder (cr, alloc);
}
-
+
public void DrawFrameBackground (Cairo.Context cr, Gdk.Rectangle alloc, bool baseColor)
{
- DrawFrameBackground (cr, alloc, baseColor
+ DrawFrameBackground (cr, alloc, baseColor
? colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal)
: colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal));
}
-
+
public void DrawFrameBackground (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
{
DrawFrameBackground (cr, alloc, color, null);
}
-
+
public void DrawFrameBackground (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Pattern pattern)
{
DrawFrameBackground (cr, alloc, black , pattern);
}
-
+
public abstract void DrawFrameBackground (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color, Cairo.Pattern pattern);
-
+
public abstract void DrawFrameBorder (Cairo.Context cr, Gdk.Rectangle alloc);
-
+
public abstract void DrawHeaderBackground (Cairo.Context cr, Gdk.Rectangle alloc);
-
+
public abstract void DrawHeaderSeparator(Cairo.Context cr, Gdk.Rectangle alloc, int x);
-
+
public void DrawListBackground (Cairo.Context cr, Gdk.Rectangle alloc, bool baseColor)
{
- DrawListBackground (cr, alloc, baseColor
+ DrawListBackground (cr, alloc, baseColor
? colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal)
: colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal));
}
-
+
public abstract void DrawListBackground (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
-
+
public void DrawColumnHighlight (Cairo.Context cr, double cellWidth, double cellHeight)
{
Gdk.Rectangle alloc = new Gdk.Rectangle ();
@@ -134,60 +134,60 @@ namespace Hyena.Gui.Theming
alloc.Height = (int)cellHeight;
DrawColumnHighlight (cr, alloc);
}
-
+
public void DrawColumnHighlight (Cairo.Context cr, Gdk.Rectangle alloc)
{
DrawColumnHighlight (cr, alloc, colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected));
}
-
+
public abstract void DrawColumnHighlight (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
-
+
public void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height)
{
DrawRowSelection (cr, x, y, width, height, true);
}
-
+
public void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height, bool filled)
{
- DrawRowSelection (cr, x, y, width, height, filled, true,
+ DrawRowSelection (cr, x, y, width, height, filled, true,
colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected), CairoCorners.All);
}
-
+
public void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height,
bool filled, bool stroked, Cairo.Color color)
{
DrawRowSelection (cr, x, y, width, height, filled, stroked, color, CairoCorners.All);
}
-
+
public abstract void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height,
bool filled, bool stroked, Cairo.Color color, CairoCorners corners);
-
+
public abstract void DrawRowRule (Cairo.Context cr, int x, int y, int width, int height);
public Cairo.Color ViewFill {
get { return view_fill; }
}
-
+
public Cairo.Color ViewFillTransparent {
get { return view_fill_transparent; }
}
-
+
public Cairo.Color SelectionFill {
get { return selection_fill; }
}
-
+
public Cairo.Color SelectionStroke {
get { return selection_stroke; }
}
-
+
public virtual int BorderWidth {
get { return 1; }
}
-
+
public virtual int InnerBorderWidth {
get { return 4; }
}
-
+
public int TotalBorderWidth {
get { return BorderWidth + InnerBorderWidth; }
}
@@ -207,7 +207,7 @@ namespace Hyena.Gui.Theming
contexts.Push (context);
}
}
-
+
public ThemeContext PopContext ()
{
lock (this) {
@@ -225,7 +225,7 @@ namespace Hyena.Gui.Theming
public static double Clamp (double min, double max, double value)
{
- return Math.Max (min, Math.Min (max, value));
+ return Math.Max (min, Math.Min (max, value));
}
#endregion
diff --git a/src/Hyena.Gui/Hyena.Gui.Theming/ThemeEngine.cs b/src/Hyena.Gui/Hyena.Gui.Theming/ThemeEngine.cs
index 9a0e8ac..ef3f3bc 100644
--- a/src/Hyena.Gui/Hyena.Gui.Theming/ThemeEngine.cs
+++ b/src/Hyena.Gui/Hyena.Gui.Theming/ThemeEngine.cs
@@ -1,21 +1,21 @@
-//
+//
// ThemeEngine.cs
-//
+//
// Author:
// Aaron Bockover <abockover novell com>
-//
+//
// Copyright 2009 Aaron Bockover
-//
+//
// 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
diff --git a/src/Hyena.Gui/Hyena.Gui/ActionManager.cs b/src/Hyena.Gui/Hyena.Gui/ActionManager.cs
index 1d65bcc..f1f0ba9 100644
--- a/src/Hyena.Gui/Hyena.Gui/ActionManager.cs
+++ b/src/Hyena.Gui/Hyena.Gui/ActionManager.cs
@@ -64,29 +64,29 @@ namespace Hyena.Gui
if (action_groups.ContainsKey (name)) {
throw new ApplicationException ("Group already exists");
}
-
+
InnerAddActionGroup (new ActionGroup (name));
}
}
-
+
public void AddActionGroup (ActionGroup group)
{
lock (this) {
if (action_groups.ContainsKey (group.Name)) {
throw new ApplicationException ("Group already exists");
}
-
+
InnerAddActionGroup (group);
}
}
-
+
public void RemoveActionGroup (string name)
{
lock (this) {
if (action_groups.ContainsKey (name)) {
ActionGroup group = action_groups[name];
ui_manager.RemoveActionGroup (group);
- action_groups.Remove (name);
+ action_groups.Remove (name);
}
}
}
@@ -95,7 +95,7 @@ namespace Hyena.Gui
{
RemoveActionGroup (group.Name);
}
-
+
public ActionGroup FindActionGroup (string actionGroupId)
{
foreach (ActionGroup group in action_groups.Values) {
@@ -103,36 +103,36 @@ namespace Hyena.Gui
return group;
}
}
-
+
return null;
}
-
+
public Gtk.Action FindAction (string actionId)
{
string [] parts = actionId.Split ('.');
-
+
if (parts == null || parts.Length < 2) {
return null;
}
-
+
string group_name = parts[0];
string action_name = parts[1];
-
+
ActionGroup group = FindActionGroup (group_name);
return group == null ? null : group.GetAction (action_name);
}
-
+
public void PopulateToolbarPlaceholder (Toolbar toolbar, string path, Widget item)
{
PopulateToolbarPlaceholder (toolbar, path, item, false);
}
-
+
public void PopulateToolbarPlaceholder (Toolbar toolbar, string path, Widget item, bool expand)
{
ToolItem placeholder = (ToolItem)UIManager.GetWidget (path);
int position = toolbar.GetItemIndex (placeholder);
toolbar.Remove (placeholder);
-
+
if (item is ToolItem) {
((ToolItem)item).Expand = expand;
toolbar.Insert ((ToolItem)item, position);
@@ -143,12 +143,12 @@ namespace Hyena.Gui
toolbar.Insert (container_item, position);
}
}
-
+
public uint AddUiFromFileInCurrentAssembly (string ui_file)
{
return AddUiFromFile (ui_file, Assembly.GetCallingAssembly ());
}
-
+
public uint AddUiFromFile (string ui_file, Assembly assembly)
{
if (ui_file != null) {
@@ -158,11 +158,11 @@ namespace Hyena.Gui
}
return 0;
}
-
+
public Gtk.Action this[string actionId] {
get { return FindAction (actionId); }
}
-
+
public UIManager UIManager {
get { return ui_manager; }
}
diff --git a/src/Hyena.Gui/Hyena.Gui/CairoExtensions.cs b/src/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
index fc663d9..80c1b67 100644
--- a/src/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
+++ b/src/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
@@ -45,26 +45,26 @@ namespace Hyena.Gui
BottomRight = 8,
All = 15
}
-
+
public static class CairoExtensions
{
public static Pango.Layout CreateLayout (Gtk.Widget widget, Cairo.Context cairo_context)
{
Pango.Layout layout = PangoCairoHelper.CreateLayout (cairo_context);
layout.FontDescription = widget.PangoContext.FontDescription.Copy ();
-
+
double resolution = widget.Screen.Resolution;
if (resolution != -1) {
Pango.Context context = PangoCairoHelper.LayoutGetContext (layout);
PangoCairoHelper.ContextSetResolution (context, resolution);
context.Dispose ();
}
-
+
Log.Debug ("Creating Pango.Layout, configuring Cairo.Context");
-
+
return layout;
}
-
+
public static Surface CreateSurfaceForPixbuf (Cairo.Context cr, Gdk.Pixbuf pixbuf)
{
Surface surface = cr.Target.CreateSimilar (cr.Target.Content, pixbuf.Width, pixbuf.Height);
@@ -74,7 +74,7 @@ namespace Hyena.Gui
((IDisposable)surface_cr).Dispose ();
return surface;
}
-
+
public static Cairo.Color AlphaBlend (Cairo.Color ca, Cairo.Color cb, double alpha)
{
return new Cairo.Color (
@@ -82,12 +82,12 @@ namespace Hyena.Gui
(1.0 - alpha) * ca.G + alpha * cb.G,
(1.0 - alpha) * ca.B + alpha * cb.B);
}
-
+
public static Cairo.Color GdkColorToCairoColor(Gdk.Color color)
{
return GdkColorToCairoColor(color, 1.0);
}
-
+
public static Cairo.Color GdkColorToCairoColor(Gdk.Color color, double alpha)
{
return new Cairo.Color(
@@ -96,40 +96,40 @@ namespace Hyena.Gui
(double)(color.Blue >> 8) / 255.0,
alpha);
}
-
+
public static Cairo.Color RgbToColor (uint rgbColor)
{
return RgbaToColor ((rgbColor << 8) | 0x000000ff);
}
-
+
public static Cairo.Color RgbaToColor (uint rgbaColor)
{
return new Cairo.Color (
- (byte)(rgbaColor >> 24) / 255.0,
- (byte)(rgbaColor >> 16) / 255.0,
- (byte)(rgbaColor >> 8) / 255.0,
+ (byte)(rgbaColor >> 24) / 255.0,
+ (byte)(rgbaColor >> 16) / 255.0,
+ (byte)(rgbaColor >> 8) / 255.0,
(byte)(rgbaColor & 0x000000ff) / 255.0);
}
-
+
public static bool ColorIsDark (Cairo.Color color)
{
double h, s, b;
HsbFromColor (color, out h, out s, out b);
return b < 0.5;
}
-
- public static void HsbFromColor(Cairo.Color color, out double hue,
+
+ public static void HsbFromColor(Cairo.Color color, out double hue,
out double saturation, out double brightness)
{
double min, max, delta;
double red = color.R;
double green = color.G;
double blue = color.B;
-
+
hue = 0;
saturation = 0;
brightness = 0;
-
+
if(red > green) {
max = Math.Max(red, blue);
min = Math.Min(green, blue);
@@ -137,9 +137,9 @@ namespace Hyena.Gui
max = Math.Max(green, blue);
min = Math.Min(red, blue);
}
-
+
brightness = (max + min) / 2;
-
+
if(Math.Abs(max - min) < 0.0001) {
hue = 0;
saturation = 0;
@@ -147,9 +147,9 @@ namespace Hyena.Gui
saturation = brightness <= 0.5
? (max - min) / (max + min)
: (max - min) / (2 - max - min);
-
+
delta = max - min;
-
+
if(red == max) {
hue = (green - blue) / delta;
} else if(green == max) {
@@ -157,49 +157,49 @@ namespace Hyena.Gui
} else if(blue == max) {
hue = 4 + (red - green) / delta;
}
-
+
hue *= 60;
if(hue < 0) {
hue += 360;
}
}
}
-
+
private static double Modula(double number, double divisor)
{
return ((int)number % divisor) + (number - (int)number);
}
-
+
public static Cairo.Color ColorFromHsb(double hue, double saturation, double brightness)
{
int i;
double [] hue_shift = { 0, 0, 0 };
double [] color_shift = { 0, 0, 0 };
double m1, m2, m3;
-
+
m2 = brightness <= 0.5
? brightness * (1 + saturation)
: brightness + saturation - brightness * saturation;
-
+
m1 = 2 * brightness - m2;
-
+
hue_shift[0] = hue + 120;
hue_shift[1] = hue;
hue_shift[2] = hue - 120;
-
+
color_shift[0] = color_shift[1] = color_shift[2] = brightness;
-
+
i = saturation == 0 ? 3 : 0;
-
+
for(; i < 3; i++) {
m3 = hue_shift[i];
-
+
if(m3 > 360) {
m3 = Modula(m3, 360);
} else if(m3 < 0) {
m3 = 360 - Modula(Math.Abs(m3), 360);
}
-
+
if(m3 < 60) {
color_shift[i] = m1 + (m2 - m1) * m3 / 60;
} else if(m3 < 180) {
@@ -208,26 +208,26 @@ namespace Hyena.Gui
color_shift[i] = m1 + (m2 - m1) * (240 - m3) / 60;
} else {
color_shift[i] = m1;
- }
+ }
}
-
+
return new Cairo.Color(color_shift[0], color_shift[1], color_shift[2]);
}
-
+
public static Cairo.Color ColorShade (Cairo.Color @base, double ratio)
{
double h, s, b;
-
+
HsbFromColor (@base, out h, out s, out b);
-
+
b = Math.Max (Math.Min (b * ratio, 1), 0);
s = Math.Max (Math.Min (s * ratio, 1), 0);
-
+
Cairo.Color color = ColorFromHsb (h, s, b);
color.A = @base.A;
return color;
}
-
+
public static Cairo.Color ColorAdjustBrightness(Cairo.Color @base, double br)
{
double h, s, b;
@@ -235,14 +235,14 @@ namespace Hyena.Gui
b = Math.Max(Math.Min(br, 1), 0);
return ColorFromHsb(h, s, b);
}
-
+
public static string ColorGetHex (Cairo.Color color, bool withAlpha)
{
if (withAlpha) {
- return String.Format("#{0:x2}{1:x2}{2:x2}{3:x2}", (byte)(color.R * 255), (byte)(color.G * 255),
+ return String.Format("#{0:x2}{1:x2}{2:x2}{3:x2}", (byte)(color.R * 255), (byte)(color.G * 255),
(byte)(color.B * 255), (byte)(color.A * 255));
} else {
- return String.Format("#{0:x2}{1:x2}{2:x2}", (byte)(color.R * 255), (byte)(color.G * 255),
+ return String.Format("#{0:x2}{1:x2}{2:x2}", (byte)(color.R * 255), (byte)(color.G * 255),
(byte)(color.B * 255));
}
}
@@ -251,13 +251,13 @@ namespace Hyena.Gui
{
RoundedRectangle(cr, x, y, w, h, r, CairoCorners.All, false);
}
-
+
public static void RoundedRectangle(Cairo.Context cr, double x, double y, double w, double h,
double r, CairoCorners corners)
{
RoundedRectangle(cr, x, y, w, h, r, corners, false);
}
-
+
public static void RoundedRectangle(Cairo.Context cr, double x, double y, double w, double h,
double r, CairoCorners corners, bool topBottomFallsThrough)
{
@@ -271,7 +271,7 @@ namespace Hyena.Gui
cr.Rectangle(x, y, w, h);
return;
}
-
+
if((corners & (CairoCorners.TopLeft | CairoCorners.TopRight)) == 0 && topBottomFallsThrough) {
y -= r;
h += r;
@@ -282,14 +282,14 @@ namespace Hyena.Gui
} else {
cr.MoveTo(x, y);
}
-
+
if((corners & CairoCorners.TopRight) != 0) {
cr.Arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2);
} else {
cr.LineTo(x + w, y);
}
}
-
+
if((corners & (CairoCorners.BottomLeft | CairoCorners.BottomRight)) == 0 && topBottomFallsThrough) {
h += r;
cr.LineTo(x + w, y + h);
@@ -302,13 +302,13 @@ namespace Hyena.Gui
} else {
cr.LineTo(x + w, y + h);
}
-
+
if((corners & CairoCorners.BottomLeft) != 0) {
cr.Arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI);
} else {
cr.LineTo(x, y + h);
}
-
+
if((corners & CairoCorners.TopLeft) != 0) {
cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
} else {
@@ -322,13 +322,13 @@ namespace Hyena.Gui
((IDisposable)cr.Target).Dispose ();
((IDisposable)cr).Dispose ();
}
-
+
private struct CairoInteropCall
{
public string Name;
public MethodInfo ManagedMethod;
public bool CallNative;
-
+
public CairoInteropCall (string name)
{
Name = name;
@@ -336,40 +336,40 @@ namespace Hyena.Gui
CallNative = false;
}
}
-
+
private static bool CallCairoMethod (Cairo.Context cr, ref CairoInteropCall call)
{
if (call.ManagedMethod == null && !call.CallNative) {
- MemberInfo [] members = typeof (Cairo.Context).GetMember (call.Name, MemberTypes.Method,
+ MemberInfo [] members = typeof (Cairo.Context).GetMember (call.Name, MemberTypes.Method,
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public);
-
+
if (members != null && members.Length > 0 && members[0] is MethodInfo) {
call.ManagedMethod = (MethodInfo)members[0];
} else {
call.CallNative = true;
}
}
-
+
if (call.ManagedMethod != null) {
call.ManagedMethod.Invoke (cr, null);
return true;
}
-
+
return false;
}
-
+
private static bool native_push_pop_exists = true;
-
+
[DllImport ("libcairo-2.dll")]
private static extern void cairo_push_group (IntPtr ptr);
private static CairoInteropCall cairo_push_group_call = new CairoInteropCall ("PushGroup");
-
+
public static void PushGroup (Cairo.Context cr)
{
if (!native_push_pop_exists) {
return;
}
-
+
try {
if (!CallCairoMethod (cr, ref cairo_push_group_call)) {
cairo_push_group (cr.Handle);
@@ -378,17 +378,17 @@ namespace Hyena.Gui
native_push_pop_exists = false;
}
}
-
+
[DllImport ("libcairo-2.dll")]
private static extern void cairo_pop_group_to_source (IntPtr ptr);
private static CairoInteropCall cairo_pop_group_to_source_call = new CairoInteropCall ("PopGroupToSource");
-
+
public static void PopGroupToSource (Cairo.Context cr)
{
if (!native_push_pop_exists) {
return;
}
-
+
try {
if (!CallCairoMethod (cr, ref cairo_pop_group_to_source_call)) {
cairo_pop_group_to_source (cr.Handle);
diff --git a/src/Hyena.Gui/Hyena.Gui/CleanRoomStartup.cs b/src/Hyena.Gui/Hyena.Gui/CleanRoomStartup.cs
index c50d02e..9f96b51 100644
--- a/src/Hyena.Gui/Hyena.Gui/CleanRoomStartup.cs
+++ b/src/Hyena.Gui/Hyena.Gui/CleanRoomStartup.cs
@@ -33,29 +33,29 @@ namespace Hyena.Gui
public static class CleanRoomStartup
{
public delegate void StartupInvocationHandler();
-
+
public static void Startup(StartupInvocationHandler startup)
{
bool disable_clean_room = false;
-
+
foreach(string arg in Environment.GetCommandLineArgs ()) {
if(arg == "--disable-clean-room") {
disable_clean_room = true;
break;
}
}
-
+
if(disable_clean_room) {
startup();
return;
}
-
+
try {
startup();
} catch(Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine(e);
-
+
Gtk.Application.Init();
Hyena.Gui.Dialogs.ExceptionDialog dialog = new Hyena.Gui.Dialogs.ExceptionDialog(e);
dialog.Run();
diff --git a/src/Hyena.Gui/Hyena.Gui/CompositeUtils.cs b/src/Hyena.Gui/Hyena.Gui/CompositeUtils.cs
index 1b0c0d9..4d93bb8 100644
--- a/src/Hyena.Gui/Hyena.Gui/CompositeUtils.cs
+++ b/src/Hyena.Gui/Hyena.Gui/CompositeUtils.cs
@@ -33,18 +33,18 @@ using Gtk;
namespace Hyena.Gui
{
- public static class CompositeUtils
+ public static class CompositeUtils
{
[DllImport ("libgdk-win32-2.0-0.dll")]
private static extern IntPtr gdk_screen_get_rgba_visual (IntPtr screen);
[DllImport ("libgtk-win32-2.0-0.dll")]
- private static extern void gtk_widget_input_shape_combine_mask (IntPtr raw, IntPtr shape_mask,
+ private static extern void gtk_widget_input_shape_combine_mask (IntPtr raw, IntPtr shape_mask,
int offset_x, int offset_y);
[DllImport ("libgdk-win32-2.0-0.dll")]
private static extern IntPtr gdk_screen_get_rgba_colormap (IntPtr screen);
-
+
public static Colormap GetRgbaColormap (Screen screen)
{
try {
@@ -58,10 +58,10 @@ namespace Hyena.Gui
return cmap;
}
}
-
+
return null;
}
-
+
public static bool SetRgbaColormap (Widget w)
{
Gdk.Colormap cmap = GetRgbaColormap (w.Screen);
@@ -73,7 +73,7 @@ namespace Hyena.Gui
return false;
}
-
+
public static Visual GetRgbaVisual (Screen screen)
{
try {
@@ -90,13 +90,13 @@ namespace Hyena.Gui
}
[DllImport ("libgdk-win32-2.0-0.dll")]
- private static extern void gdk_property_change (IntPtr window, IntPtr property, IntPtr type,
+ private static extern void gdk_property_change (IntPtr window, IntPtr property, IntPtr type,
int format, int mode, uint [] data, int nelements);
[DllImport ("libgdk-win32-2.0-0.dll")]
- private static extern void gdk_property_change (IntPtr window, IntPtr property, IntPtr type,
+ private static extern void gdk_property_change (IntPtr window, IntPtr property, IntPtr type,
int format, int mode, byte [] data, int nelements);
-
+
public static void ChangeProperty (Gdk.Window win, Atom property, Atom type, PropMode mode, uint [] data)
{
gdk_property_change (win.Handle, property.Handle, type.Handle, 32, (int)mode, data, data.Length * 4);
@@ -123,7 +123,7 @@ namespace Hyena.Gui
[DllImport ("libgdk-win32-2.0-0.dll")]
private static extern bool gdk_screen_is_composited (IntPtr screen);
- public static bool IsComposited (Screen screen)
+ public static bool IsComposited (Screen screen)
{
bool composited;
try {
@@ -138,13 +138,13 @@ namespace Hyena.Gui
if (!composited) {
composited = CompositeUtils.SupportsHint (screen, "_NET_WM_WINDOW_OPACITY");
}
-
+
return composited;
}
-
+
public static void SetWinOpacity (Gtk.Window win, double opacity)
{
- CompositeUtils.ChangeProperty (win.GdkWindow,
+ CompositeUtils.ChangeProperty (win.GdkWindow,
Atom.Intern ("_NET_WM_WINDOW_OPACITY", false),
Atom.Intern ("CARDINAL", false),
PropMode.Replace,
@@ -154,7 +154,7 @@ namespace Hyena.Gui
public static void InputShapeCombineMask (Widget w, Pixmap shape_mask, int offset_x, int offset_y)
{
- gtk_widget_input_shape_combine_mask (w.Handle, shape_mask == null ? IntPtr.Zero : shape_mask.Handle,
+ gtk_widget_input_shape_combine_mask (w.Handle, shape_mask == null ? IntPtr.Zero : shape_mask.Handle,
offset_x, offset_y);
}
}
diff --git a/src/Hyena.Gui/Hyena.Gui/Contrast.cs b/src/Hyena.Gui/Hyena.Gui/Contrast.cs
index 831eabd..3b86921 100644
--- a/src/Hyena.Gui/Hyena.Gui/Contrast.cs
+++ b/src/Hyena.Gui/Hyena.Gui/Contrast.cs
@@ -37,7 +37,7 @@ namespace Hyena.Gui
* but set the enum value to be at the end of the color_regions table
* in contrast.c to maintain binary compatibility
*/
-
+
public enum ContrastPaletteColor
{
Aqua = 0,
@@ -65,12 +65,12 @@ namespace Hyena.Gui
Yellow = 22,
Last = 23
};
-
+
public static class Contrast
{
-
+
/* Data for color palette optimization.
- *
+ *
* These numbers are completely arbitrary decisions, uninformed by the experts
* at crayola. These colors are defined as boxes within the CIE L*a*b* color
* space -- while they're not fully inclusive, they are "safe" in that anywhere
@@ -115,7 +115,7 @@ namespace Hyena.Gui
const float a = 0.055f;
const float gamma = 2.4f;
-
+
if (K > 0.04045f)
return (float) Math.Pow((K + a) / (1 + a), gamma);
else
@@ -133,23 +133,23 @@ namespace Hyena.Gui
private static void rgb_to_lab(ushort R, ushort G, ushort B, out float L, out float a, out float b)
{
float x, y, z, gr, gg, gb, fy;
-
+
/* This is the reference white point. Since we're treating "RGB" as
* sRGB, this is the D65 point.
*/
-
+
const float Xn = 0.93819f;
const float Yn = 0.98705f;
const float Zn = 1.07475f;
-
+
gr = srgb_to_xyz_g(R / 65535.0f);
gg = srgb_to_xyz_g(G / 65535.0f);
gb = srgb_to_xyz_g(B / 65535.0f);
-
+
x = 0.412424f * gr + 0.357579f * gg + 0.180464f * gb;
y = 0.212656f * gr + 0.715158f * gg + 0.072186f * gb;
z = 0.019332f * gr + 0.119193f * gg + 0.950444f * gb;
-
+
fy = xyz_to_lab_f(y / Yn);
L = 116.0f * fy - 16.0f;
@@ -162,7 +162,7 @@ namespace Hyena.Gui
const float a = 0.055f;
const float gamma = 2.4f;
-
+
if (K > 0.00304f)
return (1.0f + a) * ((float) Math.Pow(K, (1.0f / gamma))) - a;
else
@@ -170,19 +170,19 @@ namespace Hyena.Gui
}
private static void lab_to_rgb(float L, float a, float b, out ushort R, out ushort G, out ushort B)
- {
+ {
float x, y, z, fy, fx, fz, delta, delta2, rs, gs, bs;
const float Xn = 0.93819f;
const float Yn = 0.98705f;
const float Zn = 1.07475f;
-
+
fy = (L + 16.0f) / 116.0f;
fx = fy + a / 500.0f;
fz = fy - b / 200.0f;
delta = 6.0f / 29.0f;
delta2 = (float) Math.Pow(delta, 2.0f);
-
+
if (fx > delta)
x = Xn * ((float) Math.Pow(fx, 3.0f));
else
@@ -193,13 +193,13 @@ namespace Hyena.Gui
else
y = (fy - 16.0f/116.0f) * 3.0f * delta2 * Yn;
-
+
if (fz > delta)
z = Zn * ((float) Math.Pow(fz, 3.0f));
else
z = (fz - 16.0f/116.0f) * 3.0f * delta2 * Zn;
-
+
rs = 3.2410f * x - 1.5374f * y - 0.4986f * z;
gs = -0.9692f * x + 1.8760f * y + 0.0416f * z;
bs = 0.0556f * x - 0.2040f * y + 1.0570f * z;
@@ -212,7 +212,7 @@ namespace Hyena.Gui
R = 65535;
else
R = (ushort) tmp;
-
+
tmp = (float) Math.Floor(xyz_to_srgb_C(gs) * 65535.0f + 0.5f);
if (tmp < 0.0f)
G = 0;
@@ -244,7 +244,7 @@ namespace Hyena.Gui
/* Creates a specific color value for a foreground color, optimizing for
* maximum readability against the background.
*/
-
+
public static Color RenderForegroundColor(Color background, ContrastPaletteColor color)
{
float L, a, b;
@@ -253,18 +253,18 @@ namespace Hyena.Gui
float[,] points = new float[8,3];
float ld, cd;
int i;
-
- rgb_to_lab((ushort)(background.R * 255), (ushort)(background.G * 255),
+
+ rgb_to_lab((ushort)(background.R * 255), (ushort)(background.G * 255),
(ushort)(background.B * 255), out L, out a, out b);
-
+
points[0,0] = color_regions[(int)color,0];
points[0,1] = color_regions[(int)color,2];
points[0,2] = color_regions[(int)color,4];
-
+
points[1,0] = color_regions[(int)color,0];
points[1,1] = color_regions[(int)color,2];
points[1,2] = color_regions[(int)color,5];
-
+
points[2,0] = color_regions[(int)color,0];
points[2,1] = color_regions[(int)color,3];
points[2,2] = color_regions[(int)color,4];
@@ -284,17 +284,17 @@ namespace Hyena.Gui
points[6,0] = color_regions[(int)color,1];
points[6,1] = color_regions[(int)color,3];
points[6,2] = color_regions[(int)color,4];
-
+
points[7,0] = color_regions[(int)color,1];
points[7,1] = color_regions[(int)color,3];
points[7,2] = color_regions[(int)color,5];
-
+
max_dist = 0;
max_color = 0;
-
+
for (i = 0; i < 8; i++) {
float dist = lab_distance(L, a, b, points[i,0], points[i,1], points[i,2]);
-
+
if (dist > max_dist) {
max_dist = dist;
max_color = i;
@@ -306,13 +306,13 @@ namespace Hyena.Gui
* is specified in, but it keeps things readable when the background and
* foreground are really close.
*/
-
+
ld = Math.Abs(L - points[max_color,0]);
cd = (float) Math.Sqrt (Math.Pow (Math.Abs (a - points[max_color,1]), 2.0f) + Math.Pow (Math.Abs (b - points[max_color,2]), 2.0f));
-
+
if ((ld < 10.0f) && (cd < 60.0f)) {
float dL, da, db;
-
+
dL = points[max_color,0] - L;
da = points[max_color,1] - a;
db = points[max_color,2] - b;
@@ -322,9 +322,9 @@ namespace Hyena.Gui
}
ushort red, green, blue;
-
+
lab_to_rgb(points[max_color,0], points[max_color,1], points[max_color,2], out red, out green, out blue);
-
+
return new Color (red / 255.0, green / 255.0, blue / 255.0);
}
}
diff --git a/src/Hyena.Gui/Hyena.Gui/DragDropList.cs b/src/Hyena.Gui/Hyena.Gui/DragDropList.cs
index 4a89dea..d3d297a 100644
--- a/src/Hyena.Gui/Hyena.Gui/DragDropList.cs
+++ b/src/Hyena.Gui/Hyena.Gui/DragDropList.cs
@@ -34,7 +34,7 @@ using System.Runtime.InteropServices;
using Gtk;
namespace Hyena.Gui
-{
+{
public class DragDropList<T> : List<T>
{
public DragDropList() : base()
@@ -45,7 +45,7 @@ namespace Hyena.Gui
{
Add(o);
}
-
+
public DragDropList(T o, Gtk.SelectionData selectionData, Gdk.Atom target) : base()
{
Add(o);
@@ -57,13 +57,13 @@ namespace Hyena.Gui
byte [] data = this;
selectionData.Set(target, 8, data, data.Length);
}
-
+
public static implicit operator byte [](DragDropList<T> transferrable)
{
IntPtr handle = (IntPtr)GCHandle.Alloc(transferrable);
return System.Text.Encoding.ASCII.GetBytes(Convert.ToString(handle));
}
-
+
public static implicit operator DragDropList<T>(byte [] transferrable)
{
try {
@@ -77,7 +77,7 @@ namespace Hyena.Gui
return null;
}
}
-
+
public static implicit operator DragDropList<T>(Gtk.SelectionData transferrable)
{
return transferrable.Data;
diff --git a/src/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs b/src/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs
index 36008fe..e2883d4 100644
--- a/src/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs
+++ b/src/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs
@@ -77,7 +77,7 @@ namespace Hyena.Gui
}
}
- public bool CanMerge (IUndoAction action)
+ public bool CanMerge (IUndoAction action)
{
EditableEraseAction erase = action as EditableEraseAction;
if (erase == null) {
diff --git a/src/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs b/src/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs
index b39688f..d19a4e3 100644
--- a/src/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs
+++ b/src/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs
@@ -66,7 +66,7 @@ namespace Hyena.Gui
text += ((EditableInsertAction)action).text;
}
- public bool CanMerge (IUndoAction action)
+ public bool CanMerge (IUndoAction action)
{
EditableInsertAction insert = action as EditableInsertAction;
if (insert == null || String.IsNullOrEmpty (text)) {
@@ -78,7 +78,7 @@ namespace Hyena.Gui
insert.index != index + text.Length || // Must meet eachother
text[0] == '\n' || // Don't group more than one line (inclusive)
insert.text[0] == ' ' || insert.text[0] == '\t' // Don't group more than one word (exclusive)
- );
+ );
}
public override string ToString ()
diff --git a/src/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs b/src/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs
index eeca006..fdd171d 100644
--- a/src/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs
+++ b/src/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs
@@ -50,7 +50,7 @@ namespace Hyena.Gui
populate_popup_handler = new PopulatePopupHandler (OnPopulatePopup);
}
}
-
+
public void Connect ()
{
editable.KeyPressEvent += OnKeyPressEvent;
@@ -58,7 +58,7 @@ namespace Hyena.Gui
editable.TextInserted += OnTextInserted;
TogglePopupConnection (true);
}
-
+
public void Disconnect ()
{
editable.KeyPressEvent -= OnKeyPressEvent;
@@ -66,7 +66,7 @@ namespace Hyena.Gui
editable.TextInserted -= OnTextInserted;
TogglePopupConnection (false);
}
-
+
private void TogglePopupConnection (bool connect)
{
// Ugh, stupid Gtk+/Gtk# and lack of interfaces
@@ -124,8 +124,8 @@ namespace Hyena.Gui
item = new ImageMenuItem (Stock.Redo, null);
item.Sensitive = undo_manager.CanRedo;
item.Activated += delegate { undo_manager.Redo (); };
- item.AddAccelerator ("activate", accel_group, (uint)Gdk.Key.z,
- Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask,
+ item.AddAccelerator ("activate", accel_group, (uint)Gdk.Key.z,
+ Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask,
AccelFlags.Visible);
item.Show ();
menu.Prepend (item);
@@ -133,12 +133,12 @@ namespace Hyena.Gui
item = new ImageMenuItem (Stock.Undo, null);
item.Sensitive = undo_manager.CanUndo;
item.Activated += delegate { undo_manager.Undo (); };
- item.AddAccelerator ("activate", accel_group, (uint)Gdk.Key.z,
+ item.AddAccelerator ("activate", accel_group, (uint)Gdk.Key.z,
Gdk.ModifierType.ControlMask, AccelFlags.Visible);
item.Show ();
menu.Prepend (item);
}
-
+
public UndoManager UndoManager {
get { return undo_manager; }
}
diff --git a/src/Hyena.Gui/Hyena.Gui/GtkUtilities.cs b/src/Hyena.Gui/Hyena.Gui/GtkUtilities.cs
index 4b94c42..1fc246a 100644
--- a/src/Hyena.Gui/Hyena.Gui/GtkUtilities.cs
+++ b/src/Hyena.Gui/Hyena.Gui/GtkUtilities.cs
@@ -1,4 +1,4 @@
-//
+//
// GtkUtilities.cs
//
// Author:
@@ -32,23 +32,23 @@ using Gtk;
namespace Hyena.Gui
{
public delegate void WidgetAction<T> (T widget) where T : class;
-
+
public static class GtkUtilities
{
private static Gdk.ModifierType [] important_modifiers = new Gdk.ModifierType [] {
Gdk.ModifierType.ControlMask,
Gdk.ModifierType.ShiftMask
};
-
+
public static bool NoImportantModifiersAreSet ()
{
return NoImportantModifiersAreSet (important_modifiers);
}
-
+
public static bool NoImportantModifiersAreSet (params Gdk.ModifierType [] modifiers)
{
Gdk.ModifierType state;
-
+
if (Global.CurrentEvent is Gdk.EventKey) {
state = ((Gdk.EventKey)Global.CurrentEvent).State;
} else if (Global.CurrentEvent is Gdk.EventButton) {
@@ -56,16 +56,16 @@ namespace Hyena.Gui
} else {
return false;
}
-
+
foreach (Gdk.ModifierType modifier in modifiers) {
if ((state & modifier) == modifier) {
return false;
}
}
-
+
return true;
}
-
+
public static FileFilter GetFileFilter (string name, System.Collections.Generic.IEnumerable<string> extensions)
{
FileFilter filter = new FileFilter ();
@@ -76,7 +76,7 @@ namespace Hyena.Gui
}
return filter;
}
-
+
public static void SetChooserShortcuts (Gtk.FileChooserDialog chooser, params string [] shortcuts)
{
foreach (string shortcut in shortcuts) {
@@ -85,7 +85,7 @@ namespace Hyena.Gui
} catch {}
}
}
-
+
public static Gdk.Color ColorBlend (Gdk.Color a, Gdk.Color b)
{
// at some point, might be nice to allow any blend?
@@ -94,7 +94,7 @@ namespace Hyena.Gui
if (blend < 0.0 || blend > 1.0) {
throw new ApplicationException ("blend < 0.0 || blend > 1.0");
}
-
+
double blendRatio = 1.0 - blend;
int aR = a.Red >> 8;
@@ -117,21 +117,21 @@ namespace Hyena.Gui
Gdk.Colormap.System.AllocColor (ref color, true, true);
return color;
}
-
- public static void AdaptGtkRcStyle (Widget adaptee, Type adapter)
+
+ public static void AdaptGtkRcStyle (Widget adaptee, Type adapter)
{
GLib.GType type = (GLib.GType)adapter;
string path = String.Format ("*.{0}", type);
AdaptGtkRcStyle (adaptee, type, path, path);
}
-
+
public static void AdaptGtkRcStyle (Widget adaptee, GLib.GType adapter, string widgetPath, string classPath)
{
Style style = Gtk.Rc.GetStyleByPaths (adaptee.Settings, widgetPath, classPath, adapter);
if (style == null) {
return;
}
-
+
foreach (StateType state in Enum.GetValues (typeof (StateType))) {
adaptee.ModifyBase (state, style.Base (state));
adaptee.ModifyBg (state, style.Background (state));
@@ -139,19 +139,19 @@ namespace Hyena.Gui
adaptee.ModifyText (state, style.Text (state));
}
}
-
+
public static T StyleGetProperty<T> (Widget widget, string property, T default_value)
{
object result = widget.StyleGetProperty (property);
return result != null && result.GetType () == typeof (T) ? (T)result : default_value;
}
-
+
public static void ForeachWidget<T> (Container container, WidgetAction<T> action) where T : class
{
if (container == null) {
return;
}
-
+
foreach (Widget child in container.Children) {
T widget = child as T;
if (widget != null) {
diff --git a/src/Hyena.Gui/Hyena.Gui/GtkWorkarounds.cs b/src/Hyena.Gui/Hyena.Gui/GtkWorkarounds.cs
index ddb055a..fc2b1a0 100644
--- a/src/Hyena.Gui/Hyena.Gui/GtkWorkarounds.cs
+++ b/src/Hyena.Gui/Hyena.Gui/GtkWorkarounds.cs
@@ -37,55 +37,55 @@ namespace Hyena.Gui
private static MethodInfo g_object_ref;
private static MethodInfo gdk_window_destroy;
private static object [] invoke_args;
-
+
static GtkWorkarounds ()
{
if (!(toggle_ref_supported = Assembly.GetAssembly (typeof (GLib.Object)).GetType (
"GLib.ToggleRef") != null)) {
return;
}
-
+
// Find the P/Invoke signatures we need so we can avoid a dllmap
- g_object_ref = typeof (GLib.Object).GetMethod ("g_object_ref",
+ g_object_ref = typeof (GLib.Object).GetMethod ("g_object_ref",
BindingFlags.NonPublic | BindingFlags.Static);
-
- gdk_window_destroy = typeof (Gdk.Window).GetMethod ("gdk_window_destroy",
+
+ gdk_window_destroy = typeof (Gdk.Window).GetMethod ("gdk_window_destroy",
BindingFlags.NonPublic | BindingFlags.Static);
}
-
+
public static void WindowDestroy (Gdk.Window window)
{
// There is a bug in GDK, and subsequently in Gdk# 2.8.5 through 2.12.1
// where the managed Gdk.Window.Destroy function does not obtain a
- // normal reference (non-toggle) on the GdkWindow before calling
+ // normal reference (non-toggle) on the GdkWindow before calling
// _destroy on it, which the native function apparently expects.
-
+
// https://bugzilla.novell.com/show_bug.cgi?id=382186
// http://anonsvn.mono-project.com/viewcvs/trunk/gtk-sharp/gdk/Window.custom?rev=101734&r1=42529&r2=101734
-
+
if (window == null) {
return;
- }
-
+ }
+
if (!toggle_ref_supported) {
window.Destroy ();
return;
}
-
+
// If this ever happens I will move out west and start farming...
if (g_object_ref == null || gdk_window_destroy == null) {
window.Destroy ();
return;
}
-
+
if (invoke_args == null) {
invoke_args = new object[1];
}
-
+
invoke_args[0] = window.Handle;
g_object_ref.Invoke (null, invoke_args);
gdk_window_destroy.Invoke (null, invoke_args);
-
+
window.Dispose ();
}
}
diff --git a/src/Hyena.Gui/Hyena.Gui/HyenaActionGroup.cs b/src/Hyena.Gui/Hyena.Gui/HyenaActionGroup.cs
index fbbd6e2..c804bbc 100644
--- a/src/Hyena.Gui/Hyena.Gui/HyenaActionGroup.cs
+++ b/src/Hyena.Gui/Hyena.Gui/HyenaActionGroup.cs
@@ -48,7 +48,7 @@ namespace Hyena.Gui
{
this.action_manager = action_manager;
}
-
+
public void AddUiFromFile (string ui_file)
{
Hyena.ThreadAssist.AssertInMainThread ();
@@ -93,11 +93,11 @@ namespace Hyena.Gui
base.Add (action_entries);
}
}
-
+
public void AddImportant (params ActionEntry [] action_entries)
{
base.Add (action_entries);
-
+
foreach (ActionEntry entry in action_entries) {
this[entry.name].IsImportant = true;
}
@@ -106,12 +106,12 @@ namespace Hyena.Gui
public void AddImportant (params ToggleActionEntry [] action_entries)
{
base.Add (action_entries);
-
+
foreach (ToggleActionEntry entry in action_entries) {
this[entry.name].IsImportant = true;
}
}
-
+
public void Remove (string actionName)
{
Gtk.Action action = this[actionName];
@@ -131,7 +131,7 @@ namespace Hyena.Gui
{
UpdateAction (this[action_name], visible_and_sensitive, visible_and_sensitive);
}
-
+
public void UpdateAction (string action_name, bool visible, bool sensitive)
{
UpdateAction (this[action_name], visible, sensitive);
@@ -141,13 +141,13 @@ namespace Hyena.Gui
{
UpdateAction (action, visible_and_sensitive, visible_and_sensitive);
}
-
+
public static void UpdateAction (Gtk.Action action, bool visible, bool sensitive)
{
action.Visible = visible;
action.Sensitive = visible && sensitive;
}
-
+
protected void ShowContextMenu (string menu_name)
{
Gtk.Menu menu = ActionManager.UIManager.GetWidget (menu_name) as Menu;
@@ -164,10 +164,10 @@ namespace Hyena.Gui
return;
}
- menu.Show ();
+ menu.Show ();
menu.Popup (null, null, null, 0, Gtk.Global.CurrentEventTime);
}
-
+
public ActionManager ActionManager {
get { return action_manager; }
}
diff --git a/src/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs b/src/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs
index 232d5ba..0de07ad 100644
--- a/src/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs
+++ b/src/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs
@@ -35,43 +35,43 @@ namespace Hyena.Gui
{
[DllImport ("libpangocairo-1.0-0.dll")]
private static extern void pango_cairo_show_layout (IntPtr cr, IntPtr layout);
-
+
public static void ShowLayout (Cairo.Context cr, Pango.Layout layout)
{
- pango_cairo_show_layout (cr == null ? IntPtr.Zero : cr.Handle,
+ pango_cairo_show_layout (cr == null ? IntPtr.Zero : cr.Handle,
layout == null ? IntPtr.Zero : layout.Handle);
}
-
+
[DllImport ("libpangocairo-1.0-0.dll")]
private static extern IntPtr pango_cairo_create_layout (IntPtr cr);
- public static Pango.Layout CreateLayout (Cairo.Context cr)
+ public static Pango.Layout CreateLayout (Cairo.Context cr)
{
IntPtr raw_ret = pango_cairo_create_layout (cr == null ? IntPtr.Zero : cr.Handle);
return GLib.Object.GetObject (raw_ret) as Pango.Layout;
}
-
+
[DllImport ("libpangocairo-1.0-0.dll")]
private static extern void pango_cairo_layout_path (IntPtr cr, IntPtr layout);
- public static void LayoutPath (Cairo.Context cr, Pango.Layout layout,
- bool iUnderstandThePerformanceImplications)
+ public static void LayoutPath (Cairo.Context cr, Pango.Layout layout,
+ bool iUnderstandThePerformanceImplications)
{
- pango_cairo_layout_path (cr == null ? IntPtr.Zero : cr.Handle,
+ pango_cairo_layout_path (cr == null ? IntPtr.Zero : cr.Handle,
layout == null ? IntPtr.Zero : layout.Handle);
}
-
+
[DllImport ("libpangocairo-1.0-0.dll")]
private static extern void pango_cairo_context_set_resolution (IntPtr pango_context, double dpi);
-
+
public static void ContextSetResolution (Pango.Context context, double dpi)
{
pango_cairo_context_set_resolution (context == null ? IntPtr.Zero : context.Handle, dpi);
}
-
+
[DllImport ("libpangocairo-1.0-0.dll")]
private static extern IntPtr pango_layout_get_context (IntPtr layout);
-
+
public static Pango.Context LayoutGetContext (Pango.Layout layout)
{
IntPtr handle = pango_layout_get_context (layout.Handle);
diff --git a/src/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs b/src/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
index 22311e3..09c13ac 100644
--- a/src/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
+++ b/src/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
@@ -36,16 +36,16 @@ namespace Hyena.Gui
public class PixbufImageSurface : ImageSurface, IDisposable
{
private delegate void cairo_destroy_func_t (IntPtr userdata);
-
+
private static bool is_le = BitConverter.IsLittleEndian;
private static int user_data_key = 0;
private static cairo_destroy_func_t destroy_func;
-
+
private static void DestroyPixelData (IntPtr data)
{
Marshal.FreeHGlobal (data);
}
-
+
static PixbufImageSurface ()
{
destroy_func = new cairo_destroy_func_t (DestroyPixelData);
@@ -87,46 +87,46 @@ namespace Hyena.Gui
return target;
}
}
-
+
private IntPtr data;
-
+
public PixbufImageSurface (Gdk.Pixbuf pixbuf) : this (pixbuf, false)
{
}
-
- public PixbufImageSurface (Gdk.Pixbuf pixbuf, bool disposePixbuf) : this (disposePixbuf ? pixbuf : null,
+
+ public PixbufImageSurface (Gdk.Pixbuf pixbuf, bool disposePixbuf) : this (disposePixbuf ? pixbuf : null,
pixbuf.Width, pixbuf.Height, pixbuf.NChannels, pixbuf.Rowstride, pixbuf.Pixels)
{
}
-
+
// This ctor is to avoid multiple queries against the GdkPixbuf for width/height
- private PixbufImageSurface (Gdk.Pixbuf pixbuf, int width, int height, int channels, int rowstride, IntPtr pixels)
+ private PixbufImageSurface (Gdk.Pixbuf pixbuf, int width, int height, int channels, int rowstride, IntPtr pixels)
: this (pixbuf, Marshal.AllocHGlobal (width * height * 4), width, height, channels, rowstride, pixels)
{
}
-
- private PixbufImageSurface (Gdk.Pixbuf pixbuf, IntPtr data, int width, int height, int channels, int rowstride, IntPtr pixels)
+
+ private PixbufImageSurface (Gdk.Pixbuf pixbuf, IntPtr data, int width, int height, int channels, int rowstride, IntPtr pixels)
: base (data, channels == 3 ? Format.Rgb24 : Format.Argb32, width, height, width * 4)
{
this.data = data;
-
+
CreateSurface (width, height, channels, rowstride, pixels);
SetDestroyFunc ();
-
+
if (pixbuf != null && pixbuf.Handle != IntPtr.Zero) {
pixbuf.Dispose ();
}
}
-
+
private unsafe void CreateSurface (int width, int height, int channels, int gdk_rowstride, IntPtr pixels)
{
byte *gdk_pixels = (byte *)pixels;
byte *cairo_pixels = (byte *)data;
-
+
for (int i = height; i > 0; i--) {
byte *p = gdk_pixels;
byte *q = cairo_pixels;
-
+
if (channels == 3) {
byte *end = p + 3 * width;
while (p < end) {
@@ -139,7 +139,7 @@ namespace Hyena.Gui
q[2] = p[1];
q[3] = p[2];
}
-
+
p += 3;
q += 4;
}
@@ -157,27 +157,27 @@ namespace Hyena.Gui
q[2] = Mult (p[1], p[3]);
q[3] = Mult (p[2], p[3]);
}
-
+
p += 4;
q += 4;
}
}
-
+
gdk_pixels += gdk_rowstride;
cairo_pixels += 4 * width;
}
}
-
+
private static byte Mult (byte c, byte a)
{
- int t = c * a + 0x7f;
+ int t = c * a + 0x7f;
return (byte)(((t >> 8) + t) >> 8);
}
-
+
[DllImport ("libcairo-2.dll")]
- private static extern Cairo.Status cairo_surface_set_user_data (IntPtr surface,
+ private static extern Cairo.Status cairo_surface_set_user_data (IntPtr surface,
ref int key, IntPtr userdata, cairo_destroy_func_t destroy);
-
+
private void SetDestroyFunc ()
{
try {
diff --git a/src/Hyena.Gui/Hyena.Gui/RatingRenderer.cs b/src/Hyena.Gui/Hyena.Gui/RatingRenderer.cs
index 3e8dca5..8ee9ad6 100644
--- a/src/Hyena.Gui/Hyena.Gui/RatingRenderer.cs
+++ b/src/Hyena.Gui/Hyena.Gui/RatingRenderer.cs
@@ -34,7 +34,7 @@ namespace Hyena.Gui
{
public class RatingRenderer
{
- private static double [,] star_plot = new double[,] {
+ private static double [,] star_plot = new double[,] {
{ 0, 0.425 },
{ 0.375, 0.375 },
{ 0.5, 0.05 },
@@ -51,33 +51,33 @@ namespace Hyena.Gui
public RatingRenderer ()
{
}
-
+
public virtual void Render (Context cr, Gdk.Rectangle area, Color color, bool showEmptyStars, bool isHovering,
int hoverValue, double fillOpacity, double hoverFillOpacity, double strokeOpacity)
{
if (Value == MinRating && !isHovering && !showEmptyStars) {
return;
}
-
+
Cairo.Color fill_color = color;
fill_color.A = fillOpacity;
Cairo.Color stroke_color = fill_color;
stroke_color.A = strokeOpacity;
Cairo.Color hover_fill_color = fill_color;
hover_fill_color.A = hoverFillOpacity;
-
+
double x, y;
ComputePosition (area, out x, out y);
-
+
cr.LineWidth = 1.0;
cr.Translate (0.5, 0.5);
-
+
for (int i = MinRating + 1, s = isHovering || showEmptyStars ? MaxRating : Value; i <= s; i++, x += Size) {
bool fill = i <= Value && Value > MinRating;
bool hover_fill = i <= hoverValue && hoverValue > MinRating;
double scale = fill || hover_fill ? Size : Size - 2;
double ofs = fill || hover_fill ? 0 : 1;
-
+
for (int p = 0, n = star_plot.GetLength (0); p < n; p++) {
double px = x + ofs + star_plot[p, 0] * scale;
double py = y + ofs + star_plot[p, 1] * scale;
@@ -88,7 +88,7 @@ namespace Hyena.Gui
}
}
cr.ClosePath ();
-
+
if (fill || hover_fill) {
if (!isHovering || hoverValue >= Value) {
cr.Color = fill ? fill_color : hover_fill_color;
@@ -102,80 +102,80 @@ namespace Hyena.Gui
}
}
}
-
+
private void ComputePosition (Gdk.Rectangle area, out double x, out double y)
{
double cell_width = area.Width - 2 * Xpad;
double cell_height = area.Height - 2 * Ypad;
-
+
double stars_width = MaxRating * Size;
double stars_height = Size;
-
+
x = area.X + Xpad + (cell_width - stars_width) / 2.0;
y = area.Y + Ypad + (cell_height - stars_height) / 2.0;
}
-
+
public int RatingFromPosition (Gdk.Rectangle area, double x)
{
double r_x, r_y;
ComputePosition (area, out r_x, out r_y);
return x <= r_x ? 0 : Clamp (MinRating, MaxRating, (int)Math.Ceiling ((x - r_x) / Size) + MinRating);
}
-
+
private static int Clamp (int min, int max, int value)
{
return Math.Max (min, Math.Min (max, value));
}
-
+
public int ClampValue (int value)
{
return Clamp (MinRating, MaxRating, value);
}
-
+
private int value;
public int Value {
get { return ClampValue (this.value); }
set { this.value = ClampValue (value); }
}
-
+
private int size = 14;
public int Size {
get { return size; }
set { size = value; }
}
-
+
private int min_rating = 0;
public int MinRating {
get { return min_rating; }
set { min_rating = value; }
}
-
+
private int max_rating = 5;
public int MaxRating {
get { return max_rating; }
set { max_rating = value; }
}
-
+
public int RatingLevels {
get { return MaxRating - MinRating + 1; }
}
-
+
private int xpad = 2;
public int Xpad {
get { return xpad; }
set { xpad = value; }
}
-
+
public int ypad = 2;
public int Ypad {
get { return ypad; }
set { ypad = value; }
}
-
+
public int Width {
get { return Xpad * 2 + RatingLevels * Size; }
}
-
+
public int Height {
get { return Ypad * 2 + Size; }
}
diff --git a/src/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs b/src/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
index a4429c6..d82d67b 100644
--- a/src/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
+++ b/src/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
@@ -34,38 +34,38 @@ namespace Hyena.Gui
public class ShadingTestWindow : Window
{
private int steps = 16;
-
+
public ShadingTestWindow () : base ("Shading Test")
{
SetSizeRequest (512, 512);
}
-
+
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
{
Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window);
-
+
double step_width = Allocation.Width / (double)steps;
double step_height = Allocation.Height / (double)steps;
double h = 1.0;
double s = 0.0;
-
+
for (int xi = 0, i = 0; xi < steps; xi++) {
for (int yi = 0; yi < steps; yi++, i++) {
double bg_b = (double)(i / 255.0);
double fg_b = 1.0 - bg_b;
-
+
double x = Allocation.X + xi * step_width;
double y = Allocation.Y + yi * step_height;
-
+
cr.Rectangle (x, y, step_width, step_height);
cr.Color = CairoExtensions.ColorFromHsb (h, s, bg_b);
cr.Fill ();
-
+
int tw, th;
Pango.Layout layout = new Pango.Layout (PangoContext);
layout.SetText (((int)(bg_b * 255.0)).ToString ());
layout.GetPixelSize (out tw, out th);
-
+
cr.Translate (0.5, 0.5);
cr.MoveTo (x + (step_width - tw) / 2.0, y + (step_height - th) / 2.0);
cr.Color = CairoExtensions.ColorFromHsb (h, s, fg_b);
@@ -73,7 +73,7 @@ namespace Hyena.Gui
cr.Translate (-0.5, -0.5);
}
}
-
+
CairoExtensions.DisposeContext (cr);
return true;
}
diff --git a/src/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs b/src/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs
index cc04904..6b24d9b 100644
--- a/src/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs
+++ b/src/Hyena.Gui/Hyena.Gui/TestModuleAttribute.cs
@@ -33,12 +33,12 @@ namespace Hyena.Gui
internal class TestModuleAttribute : Attribute
{
private string name;
- public string Name {
+ public string Name {
get { return name; }
set { name = value; }
}
-
- public TestModuleAttribute (string name)
+
+ public TestModuleAttribute (string name)
{
this.name = name;
}
diff --git a/src/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs b/src/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs
index ad63679..35c1cbc 100644
--- a/src/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs
+++ b/src/Hyena.Gui/Hyena.Gui/TestModuleRunner.cs
@@ -42,37 +42,37 @@ namespace Hyena.Gui
runner.ShowAll ();
Application.Run ();
}
-
+
private TreeStore store;
-
+
public TestModuleRunner () : base ("Hyena.Gui Module Tester")
{
SetSizeRequest (-1, 300);
Move (100, 100);
-
+
BuildModuleList ();
BuildView ();
}
-
+
private void BuildModuleList ()
{
store = new TreeStore (typeof (string), typeof (Type));
-
+
foreach (Type type in Assembly.GetExecutingAssembly ().GetTypes ()) {
foreach (TestModuleAttribute attr in type.GetCustomAttributes (typeof (TestModuleAttribute), false)) {
store.AppendValues (attr.Name, type);
}
}
}
-
+
private void BuildView ()
{
VBox box = new VBox ();
Add (box);
-
+
ScrolledWindow sw = new ScrolledWindow ();
sw.HscrollbarPolicy = PolicyType.Never;
-
+
TreeView view = new TreeView ();
view.RowActivated += delegate (object o, RowActivatedArgs args) {
TreeIter iter;
@@ -86,15 +86,15 @@ namespace Hyena.Gui
};
view.Model = store;
view.AppendColumn ("Module", new CellRendererText (), "text", 0);
-
+
sw.Add (view);
box.PackStart (sw, true, true, 0);
sw.ShowAll ();
-
+
Button button = new Button (Stock.Quit);
button.Clicked += delegate { Destroy (); Application.Quit (); };
box.PackStart (button, false, false, 0);
-
+
box.ShowAll ();
}
}
diff --git a/src/Hyena.Gui/Hyena.Gui/TooltipSetter.cs b/src/Hyena.Gui/Hyena.Gui/TooltipSetter.cs
index 915f78d..48323e7 100644
--- a/src/Hyena.Gui/Hyena.Gui/TooltipSetter.cs
+++ b/src/Hyena.Gui/Hyena.Gui/TooltipSetter.cs
@@ -39,15 +39,15 @@ namespace Hyena.Gui
private static MethodInfo host_set_tip_method;
private static PropertyInfo tooltip_text_property;
private static bool reflected;
-
+
public static object CreateHost ()
{
if (tooltip_text_property != null) {
return null;
- }
-
+ }
+
Type type = reflected ? null : typeof (Widget);
-
+
if (type != null) {
tooltip_text_property = type.GetProperty ("TooltipText", BindingFlags.Instance | BindingFlags.Public);
if (tooltip_text_property != null) {
@@ -55,24 +55,24 @@ namespace Hyena.Gui
return null;
}
}
-
+
if (host_set_tip_method == null && !reflected) {
reflected = true;
host_type = Type.GetType (String.Format ("Gtk.Tooltips, {0}", type.Assembly.FullName));
if (type == null) {
return null;
}
-
- host_set_tip_method = host_type.GetMethod ("SetTip", BindingFlags.Instance |
+
+ host_set_tip_method = host_type.GetMethod ("SetTip", BindingFlags.Instance |
BindingFlags.Public | BindingFlags.InvokeMethod);
if (host_set_tip_method == null) {
return null;
}
}
-
+
return host_set_tip_method != null ? Activator.CreateInstance (host_type) : null;
}
-
+
public static void Set (object host, Widget widget, string textTip)
{
if (tooltip_text_property != null) {
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/FileSizeQueryValueEntry.cs b/src/Hyena.Gui/Hyena.Query.Gui/FileSizeQueryValueEntry.cs
index f03f79c..ba9ea15 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/FileSizeQueryValueEntry.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/FileSizeQueryValueEntry.cs
@@ -71,7 +71,7 @@ namespace Hyena.Query.Gui
public override QueryValue QueryValue {
get { return query_value; }
- set {
+ set {
spin_button.ValueChanged -= HandleValueChanged;
combo.Changed -= HandleValueChanged;
query_value = value as FileSizeQueryValue;
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/IntegerQueryValueEntry.cs b/src/Hyena.Gui/Hyena.Query.Gui/IntegerQueryValueEntry.cs
index 95560f3..f4ed1a9 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/IntegerQueryValueEntry.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/IntegerQueryValueEntry.cs
@@ -50,7 +50,7 @@ namespace Hyena.Query.Gui
public override QueryValue QueryValue {
get { return query_value; }
- set {
+ set {
spin_button.ValueChanged -= HandleValueChanged;
query_value = value as IntegerQueryValue;
spin_button.SetRange (query_value.MinValue, query_value.MaxValue);
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/QueryBox.cs b/src/Hyena.Gui/Hyena.Query.Gui/QueryBox.cs
index 207fa14..0fe4562 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/QueryBox.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/QueryBox.cs
@@ -75,7 +75,7 @@ namespace Hyena.Query.Gui
Alignment matchesAlignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
matchesAlignment.SetPadding (5, 5, 5, 5);
matchesAlignment.Add (terms_box);
-
+
matchesFrame = new Frame (null);
matchesFrame.Add (matchesAlignment);
matchesFrame.LabelWidget = BuildMatchHeader ();
@@ -100,27 +100,27 @@ namespace Hyena.Query.Gui
{
HBox header = new HBox ();
header.Show ();
-
+
terms_enabled_checkbox = new CheckButton (Catalog.GetString ("_Match"));
terms_enabled_checkbox.Show ();
terms_enabled_checkbox.Active = true;
terms_enabled_checkbox.Toggled += OnMatchCheckBoxToggled;
header.PackStart (terms_enabled_checkbox, false, false, 0);
-
+
terms_logic_combo = ComboBox.NewText ();
terms_logic_combo.AppendText (Catalog.GetString ("all"));
terms_logic_combo.AppendText (Catalog.GetString ("any"));
terms_logic_combo.Show ();
terms_logic_combo.Active = 0;
header.PackStart (terms_logic_combo, false, false, 0);
-
+
terms_label = new Label (Catalog.GetString ("of the following:"));
terms_label.Show ();
terms_label.Xalign = 0.0f;
header.PackStart (terms_label, true, true, 0);
-
+
header.Spacing = 5;
-
+
return header;
}
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs b/src/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs
index d2643b1..df8060e 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/QueryDebugger.cs
@@ -43,13 +43,13 @@ namespace Hyena.Query.Gui
private TextView input;
private TextView sql;
private TextView xml;
-
+
private QueryFieldSet query_field_set;
-
+
public QueryDebugger () : base ("Hyena.Query Debugger")
{
SetDefaultSize (800, 600);
-
+
VBox input_box = new VBox ();
input_box.Spacing = 8;
ScrolledWindow sw = new ScrolledWindow ();
@@ -71,7 +71,7 @@ namespace Hyena.Query.Gui
parse.Clicked += OnParseUserQuery;
button_box.PackStart (parse, false, false, 0);
input_box.PackStart (button_box, false, false, 0);
-
+
HBox output_box = new HBox ();
output_box.Spacing = 8;
sw = new ScrolledWindow ();
@@ -88,20 +88,20 @@ namespace Hyena.Query.Gui
xml.WrapMode = WrapMode.Word;
sw.Add (xml);
output_box.PackStart (sw, true, true, 0);
-
+
VPaned pane = new VPaned ();
pane.Add1 (input_box);
pane.Add2 (output_box);
pane.Position = 100;
-
+
Add (pane);
pane.ShowAll ();
-
+
input.HasFocus = true;
-
+
LoadQueryFieldSet ();
}
-
+
private void LoadQueryFieldSet ()
{
Assembly asm = Assembly.LoadFile ("Banshee.Services.dll");
@@ -109,23 +109,23 @@ namespace Hyena.Query.Gui
FieldInfo f = t.GetField ("FieldSet", BindingFlags.Public | BindingFlags.Static);
query_field_set = (QueryFieldSet)f.GetValue (null);
}
-
+
private StreamReader StringToStream (string s)
{
return new StreamReader (new MemoryStream (System.Text.Encoding.UTF8.GetBytes (s)));
}
-
+
private void OnParseUserQuery (object o, EventArgs args)
{
UserQueryParser parser = new UserQueryParser ();
parser.InputReader = StringToStream (input.Buffer.Text);
QueryNode node = parser.BuildTree (query_field_set);
-
+
sql.Buffer.Text = node.ToSql (query_field_set) ?? String.Empty;
-
+
XmlDocument doc = new XmlDocument ();
doc.LoadXml (node.ToXml (query_field_set));
-
+
MemoryStream s = new MemoryStream ();
XmlTextWriter w = new XmlTextWriter (s, System.Text.Encoding.UTF8);
w.Formatting = Formatting.Indented;
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs b/src/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs
index 6a1814a..545b9e3 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/QueryLimitBox.cs
@@ -54,21 +54,21 @@ namespace Hyena.Query.Gui
this.limits = limits;
Spacing = 5;
-
+
enabled_checkbox = new CheckButton (Catalog.GetString ("_Limit to"));
enabled_checkbox.Toggled += OnEnabledToggled;
-
+
count_spin = new SpinButton (0, Double.MaxValue, 1);
count_spin.Numeric = true;
count_spin.Digits = 0;
count_spin.Value = 25;
count_spin.SetSizeRequest (60, -1);
-
+
limit_combo = ComboBox.NewText ();
foreach (QueryLimit limit in limits) {
limit_combo.AppendText (limit.Label);
}
-
+
order_combo = ComboBox.NewText ();
order_combo.RowSeparatorFunc = IsRowSeparator;
foreach (QueryOrder order in orders) {
@@ -84,7 +84,7 @@ namespace Hyena.Query.Gui
PackStart (limit_combo, false, false, 0);
PackStart (new Label (Catalog.GetString ("selected by")), false, false, 0);
PackStart (order_combo, false, false, 0);
-
+
enabled_checkbox.Active = false;
limit_combo.Active = 0;
order_combo.Active = 0;
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs b/src/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs
index 917b620..f5413d7 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs
@@ -84,17 +84,17 @@ namespace Hyena.Query.Gui
{
field_chooser = ComboBox.NewText ();
field_chooser.Changed += HandleFieldChanged;
-
+
op_chooser = ComboBox.NewText ();
op_chooser.RowSeparatorFunc = IsRowSeparator;
op_chooser.Changed += HandleOperatorChanged;
-
+
value_box = new HBox ();
remove_button = new Button (new Image ("gtk-remove", IconSize.Button));
remove_button.Relief = ReliefStyle.None;
remove_button.Clicked += OnButtonRemoveClicked;
-
+
add_button = new Button (new Image ("gtk-add", IconSize.Button));
add_button.Relief = ReliefStyle.None;
add_button.Clicked += OnButtonAddClicked;
@@ -123,7 +123,7 @@ namespace Hyena.Query.Gui
value_box.ShowAll ();
button_box.ShowAll ();
}
-
+
private bool first = true;
private void SetValueEntry (QueryValueEntry entry)
{
@@ -187,7 +187,7 @@ namespace Hyena.Query.Gui
op_chooser.Changed += HandleOperatorChanged;
op_chooser.Active = 0;
}
-
+
private void HandleOperatorChanged (object o, EventArgs args)
{
if (op_chooser.Active < 0 || op_chooser.Active >= operators.Count) {
@@ -201,26 +201,26 @@ namespace Hyena.Query.Gui
//value_entry = new QueryValueEntry <field.ValueType> ();
}
-
+
private void OnButtonAddClicked (object o, EventArgs args)
{
EventHandler handler = AddRequest;
if (handler != null)
handler (this, new EventArgs ());
}
-
+
private void OnButtonRemoveClicked (object o, EventArgs args)
{
EventHandler handler = RemoveRequest;
if (handler != null)
handler (this, new EventArgs ());
}
-
+
public bool CanDelete {
get { return remove_button.Sensitive; }
set { remove_button.Sensitive = value; }
}
-
+
public QueryTermNode QueryNode {
get {
QueryTermNode node = new QueryTermNode ();
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs b/src/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs
index c75be37..5a9949d 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs
@@ -48,7 +48,7 @@ namespace Hyena.Query.Gui
public QueryTermBox FirstRow {
get { return terms.Count > 0 ? terms[0] : null; }
}
-
+
public QueryTermsBox (QueryFieldSet fieldSet) : base (1, 4, false)
{
// Sort the fields alphabetically by their label
@@ -117,13 +117,13 @@ namespace Hyena.Query.Gui
return row;
}
-
+
protected void OnRowAddRequest (object o, EventArgs args)
{
CreateRow (true);
UpdateCanDelete ();
}
-
+
protected void OnRowRemoveRequest (object o, EventArgs args)
{
RemoveRow (terms.IndexOf (o as QueryTermBox));
@@ -162,7 +162,7 @@ namespace Hyena.Query.Gui
terms.Remove (row);
UpdateCanDelete ();
}
-
+
protected void UpdateCanDelete ()
{
if (FirstRow != null) {
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/StringQueryValueEntry.cs b/src/Hyena.Gui/Hyena.Query.Gui/StringQueryValueEntry.cs
index d07b438..f3bd1c7 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/StringQueryValueEntry.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/StringQueryValueEntry.cs
@@ -48,7 +48,7 @@ namespace Hyena.Query.Gui
public override QueryValue QueryValue {
get { return query_value; }
- set {
+ set {
entry.Changed -= HandleChanged;
query_value = value as StringQueryValue;
entry.Text = (query_value.Value as string) ?? String.Empty;
diff --git a/src/Hyena.Gui/Hyena.Query.Gui/TimeSpanQueryValueEntry.cs b/src/Hyena.Gui/Hyena.Query.Gui/TimeSpanQueryValueEntry.cs
index e543b72..0158ad1 100644
--- a/src/Hyena.Gui/Hyena.Query.Gui/TimeSpanQueryValueEntry.cs
+++ b/src/Hyena.Gui/Hyena.Query.Gui/TimeSpanQueryValueEntry.cs
@@ -72,7 +72,7 @@ namespace Hyena.Query.Gui
public override QueryValue QueryValue {
get { return query_value; }
- set {
+ set {
spin_button.ValueChanged -= HandleValueChanged;
combo.Changed -= HandleValueChanged;
diff --git a/src/Hyena.Gui/Hyena.Widgets/AccordionPane.cs b/src/Hyena.Gui/Hyena.Widgets/AccordionPane.cs
index 9810f24..9cc6894 100644
--- a/src/Hyena.Gui/Hyena.Widgets/AccordionPane.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/AccordionPane.cs
@@ -36,14 +36,14 @@ namespace Hyena.Widgets
public class AccordionPane : Bin
{
private List<Gtk.Paned> panes = new List<Paned> ();
-
- private Box
-
+
+ private Box
+
public AccordionPane () : base ()
{
}
}
-
+
#region Test Module
[Hyena.Gui.TestModule ("Accordion Pane")]
@@ -53,7 +53,7 @@ namespace Hyena.Widgets
{
VBox pbox = new VBox ();
Add (pbox);
-
+
Menu m = new Menu ();
MenuBar b = new MenuBar ();
MenuItem item = new MenuItem ("Rate Me!");
@@ -65,29 +65,29 @@ namespace Hyena.Widgets
m.Append (new ImageMenuItem ("gtk-remove", null));
m.ShowAll ();
pbox.PackStart (b, false, false, 0);
-
+
VBox box = new VBox ();
box.BorderWidth = 10;
box.Spacing = 10;
pbox.PackStart (box, true, true, 0);
-
+
RatingEntry entry1 = new RatingEntry ();
box.PackStart (entry1, true, true, 0);
-
+
RatingEntry entry2 = new RatingEntry ();
box.PackStart (entry2, false, false, 0);
-
+
box.PackStart (new Entry ("Normal GtkEntry"), false, false, 0);
-
+
RatingEntry entry3 = new RatingEntry ();
Pango.FontDescription fd = entry3.PangoContext.FontDescription.Copy ();
fd.Size = (int)(fd.Size * Pango.Scale.XXLarge);
entry3.ModifyFont (fd);
box.PackStart (entry3, true, true, 0);
-
+
pbox.ShowAll ();
}
}
-
+
#endregion
}
\ No newline at end of file
diff --git a/src/Hyena.Gui/Hyena.Widgets/AnimatedBox.cs b/src/Hyena.Gui/Hyena.Widgets/AnimatedBox.cs
index 1b4f7bd..da888ad 100644
--- a/src/Hyena.Gui/Hyena.Widgets/AnimatedBox.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/AnimatedBox.cs
@@ -42,7 +42,7 @@ namespace Hyena.Widgets
private readonly LinkedList<AnimatedWidget> children = new LinkedList<AnimatedWidget> ();
private readonly SingleActorStage border_stage = new Hyena.Gui.Theatrics.SingleActorStage ();
private readonly bool horizontal;
-
+
private uint duration = 500;
private Easing easing = Easing.Linear;
private Blocking blocking = Blocking.Upstage;
@@ -52,13 +52,13 @@ namespace Hyena.Widgets
private int start_spacing;
private int end_spacing;
private int active_count;
-
+
private int start_border;
private int end_border;
private double border_bias;
private Easing border_easing;
private AnimationState border_state;
-
+
protected AnimatedBox (bool horizontal)
{
WidgetFlags |= WidgetFlags.NoWindow;
@@ -66,13 +66,13 @@ namespace Hyena.Widgets
stage.ActorStep += OnActorStep;
border_stage.Iteration += OnBorderIteration;
}
-
+
#region Private
-
+
private double Percent {
get { return border_stage.Actor.Percent * border_bias + (1.0 - border_bias); }
}
-
+
private bool OnActorStep (Actor<AnimatedWidget> actor)
{
switch (actor.Target.AnimationState) {
@@ -98,10 +98,10 @@ namespace Hyena.Widgets
}
break;
}
-
+
return true;
}
-
+
private void OnBorderIteration (object sender, EventArgs args)
{
if (border_stage.Actor == null) {
@@ -119,16 +119,16 @@ namespace Hyena.Widgets
}
QueueResizeNoRedraw ();
}
-
+
private void OnWidgetDestroyed (object sender, EventArgs args)
{
RemoveCore ((AnimatedWidget)sender);
}
-
+
private void RecalculateSpacings ()
{
int skip_count = 0;
-
+
foreach (AnimatedWidget animated_widget in Widgets) {
animated_widget.QueueResizeNoRedraw ();
if (skip_count > 1) {
@@ -136,14 +136,14 @@ namespace Hyena.Widgets
continue;
}
AnimatedWidget widget = animated_widget;
-
+
if (skip_count == 0) {
widget.StartPadding = start_spacing;
} else {
skip_count--;
}
widget.EndPadding = end_spacing;
-
+
if (widget.Node.Previous == null) {
while (true) {
widget.StartPadding = 0;
@@ -156,7 +156,7 @@ namespace Hyena.Widgets
skip_count++;
}
}
-
+
if (widget.Node.Next == null) {
while (true) {
widget.EndPadding = 0;
@@ -170,27 +170,27 @@ namespace Hyena.Widgets
}
}
}
-
+
#endregion
-
+
#region Protected Overrides
-
+
protected override void OnAdded (Widget widget)
{
PackStart (widget, duration, easing, blocking);
}
-
+
protected override void OnSizeRequested (ref Requisition requisition)
{
int width = 0;
int height = 0;
-
+
if (horizontal) {
width = start_border + end_border;
} else {
height = start_border + end_border;
}
-
+
foreach (AnimatedWidget widget in Widgets) {
Requisition req = widget.SizeRequest ();
if (horizontal) {
@@ -201,7 +201,7 @@ namespace Hyena.Widgets
height += req.Height;
}
}
-
+
requisition.Width = width;
requisition.Height = height;
}
@@ -218,7 +218,7 @@ namespace Hyena.Widgets
allocation.Y += start_border;
allocation.Width -= (int)BorderWidth * 2;
}
-
+
foreach (AnimatedWidget widget in Widgets) {
if (horizontal) {
allocation.Width = widget.Width;
@@ -231,35 +231,35 @@ namespace Hyena.Widgets
}
}
}
-
+
protected override void ForAll (bool include_internals, Callback callback)
{
foreach (AnimatedWidget child in Widgets) {
callback (child);
}
}
-
+
#endregion
-
+
#region Public
-
+
#region Properties
-
+
public uint Duration {
get { return duration; }
set { duration = value; }
}
-
+
public Easing Easing {
get { return easing; }
set { easing = value; }
}
-
+
public Blocking Blocking {
get { return blocking; }
set { blocking = value; }
}
-
+
public int Spacing {
get { return spacing; }
set {
@@ -269,17 +269,17 @@ namespace Hyena.Widgets
end_spacing = (int)Math.Floor (half);
}
}
-
+
public int StartPadding {
get { return start_padding - (int)BorderWidth; }
set { start_padding = value + (int)BorderWidth; }
}
-
+
public int EndPadding {
get { return end_padding - (int)BorderWidth; }
set { end_padding = value + (int)BorderWidth; }
}
-
+
internal IEnumerable<AnimatedWidget> Widgets {
get {
foreach (AnimatedWidget child in children) {
@@ -287,105 +287,105 @@ namespace Hyena.Widgets
}
}
}
-
+
#endregion
-
+
#region Pack Methods
-
+
public void PackStart (Widget widget)
{
PackStart (widget, duration, easing, blocking);
}
-
+
public void PackStart (Widget widget, uint duration)
{
PackStart (widget, duration, easing, blocking);
}
-
+
public void PackStart (Widget widget, Easing easing)
{
PackStart (widget, duration, easing, blocking);
}
-
+
public void PackStart (Widget widget, uint duration, Easing easing)
{
PackStart (widget, duration, easing, blocking);
}
-
+
public void PackStart (Widget widget, Blocking blocking)
{
PackStart (widget, duration, easing, blocking);
}
-
+
public void PackStart (Widget widget, uint duration, Blocking blocking)
{
PackStart (widget, duration, easing, blocking);
}
-
+
public void PackStart (Widget widget, Easing easing, Blocking blocking)
{
PackStart (widget, duration, easing, blocking);
}
-
+
public void PackStart (Widget widget, uint duration, Easing easing, Blocking blocking)
{
Pack (widget, duration, easing, blocking, false);
}
-
+
public void PackEnd (Widget widget)
{
PackEnd (widget, duration, easing, blocking);
}
-
+
public void PackEnd (Widget widget, uint duration)
{
PackEnd (widget, duration, easing, blocking);
}
-
+
public void PackEnd (Widget widget, Easing easing)
{
PackEnd (widget, duration, easing, blocking);
}
-
+
public void PackEnd (Widget widget, uint duration, Easing easing)
{
PackEnd (widget, duration, easing, blocking);
}
-
+
public void PackEnd (Widget widget, Blocking blocking)
{
PackEnd (widget, duration, easing, blocking);
}
-
+
public void PackEnd (Widget widget, uint duration, Blocking blocking)
{
PackEnd (widget, duration, easing, blocking);
}
-
+
public void PackEnd (Widget widget, Easing easing, Blocking blocking)
{
PackEnd (widget, duration, easing, blocking);
}
-
+
public void PackEnd (Widget widget, uint duration, Easing easing, Blocking blocking)
{
Pack (widget, duration, easing, blocking, true);
}
-
+
private void Pack (Widget widget, uint duration, Easing easing, Blocking blocking, bool end)
{
if (widget == null) {
throw new ArgumentNullException ("widget");
}
-
+
AnimatedWidget animated_widget = new AnimatedWidget (widget, duration, easing, blocking, horizontal);
animated_widget.Parent = this;
animated_widget.WidgetDestroyed += OnWidgetDestroyed;
stage.Add (animated_widget, duration);
- animated_widget.Node = end
+ animated_widget.Node = end
? children.AddLast (animated_widget)
: children.AddFirst (animated_widget);
-
+
RecalculateSpacings ();
if (active_count == 0) {
if (border_state == AnimationState.Going) {
@@ -399,57 +399,57 @@ namespace Hyena.Widgets
}
active_count++;
}
-
+
#endregion
-
+
#region Remove Methods
-
+
public new void Remove (Widget widget)
{
RemoveCore (widget, 0, 0, 0, false, false);
}
-
+
public void Remove (Widget widget, uint duration)
{
RemoveCore (widget, duration, 0, 0, false, false);
}
-
+
public void Remove (Widget widget, Easing easing)
{
RemoveCore (widget, 0, easing, 0, true, false);
}
-
+
public void Remove (Widget widget, uint duration, Easing easing)
{
RemoveCore (widget, duration, easing, 0, true, false);
}
-
+
public void Remove (Widget widget, Blocking blocking)
{
RemoveCore (widget, 0, 0, blocking, false, true);
}
-
+
public void Remove (Widget widget, uint duration, Blocking blocking)
{
RemoveCore (widget, duration, 0, blocking, false, true);
}
-
+
public void Remove (Widget widget, Easing easing, Blocking blocking)
{
RemoveCore (widget, 0, easing, blocking, true, true);
}
-
+
public void Remove (Widget widget, uint duration, Easing easing, Blocking blocking)
{
RemoveCore (widget, duration, easing, blocking, true, true);
}
-
+
private void RemoveCore (Widget widget, uint duration, Easing easing, Blocking blocking, bool use_easing, bool use_blocking)
{
if (widget == null) {
throw new ArgumentNullException ("widget");
}
-
+
AnimatedWidget animated_widget = null;
foreach (AnimatedWidget child in Widgets) {
if (child.Widget == widget) {
@@ -457,34 +457,34 @@ namespace Hyena.Widgets
break;
}
}
-
+
if (animated_widget == null) {
throw new ArgumentException ("Cannot remove the specified widget because it has not been added to this container or it has already been removed.", "widget");
}
-
+
RemoveCore (animated_widget, duration, easing, blocking, use_easing, use_blocking);
RecalculateSpacings ();
}
-
+
private void RemoveCore (AnimatedWidget widget)
{
RemoveCore (widget, widget.Duration, 0, 0, false, false);
}
-
+
private void RemoveCore (AnimatedWidget widget, uint duration, Easing easing, Blocking blocking, bool use_easing, bool use_blocking)
{
if (duration > 0) {
widget.Duration = duration;
}
-
+
if (use_easing) {
widget.Easing = easing;
}
-
+
if (use_blocking) {
widget.Blocking = blocking;
}
-
+
if (widget.AnimationState == AnimationState.Coming) {
widget.AnimationState = AnimationState.IntendingToGo;
} else {
@@ -500,10 +500,10 @@ namespace Hyena.Widgets
widget.AnimationState = AnimationState.Going;
stage.Add (widget, widget.Duration);
}
-
+
duration = widget.Duration;
easing = widget.Easing;
-
+
active_count--;
if (active_count == 0) {
if (border_state == AnimationState.Coming) {
@@ -516,7 +516,7 @@ namespace Hyena.Widgets
border_stage.Reset ((uint)(duration * border_bias));
}
}
-
+
public void RemoveAll ()
{
foreach (AnimatedWidget child in Widgets) {
@@ -526,9 +526,9 @@ namespace Hyena.Widgets
}
RecalculateSpacings ();
}
-
+
#endregion
-
+
public bool Contains (Widget widget)
{
foreach (AnimatedWidget child in Widgets) {
@@ -538,8 +538,8 @@ namespace Hyena.Widgets
}
return false;
}
-
+
#endregion
-
+
}
}
\ No newline at end of file
diff --git a/src/Hyena.Gui/Hyena.Widgets/AnimatedImage.cs b/src/Hyena.Gui/Hyena.Widgets/AnimatedImage.cs
index 027e273..fe31d4c 100644
--- a/src/Hyena.Gui/Hyena.Widgets/AnimatedImage.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/AnimatedImage.cs
@@ -43,68 +43,68 @@ namespace Hyena.Widgets
private int frame_height;
private int max_frames;
private bool active_frozen;
-
+
private SingleActorStage stage = new SingleActorStage ();
-
+
public AnimatedImage ()
{
stage.Iteration += OnIteration;
stage.Reset ();
stage.Actor.CanExpire = false;
}
-
+
protected override void OnShown ()
{
base.OnShown ();
-
+
if (active_frozen && !stage.Playing) {
stage.Play ();
}
}
-
+
protected override void OnHidden ()
{
base.OnHidden ();
-
+
active_frozen = Active;
if (stage.Playing) {
stage.Pause ();
}
}
-
+
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
if (allocation != Allocation) {
base.OnSizeAllocated (allocation);
}
}
-
+
public void Load ()
{
ExtractFrames ();
base.Pixbuf = frames[0];
}
-
+
private void OnIteration (object o, EventArgs args)
{
if (!Visible) {
return;
}
-
+
if (frames == null || frames.Length == 0) {
return;
} else if (frames.Length == 1) {
base.Pixbuf = frames[0];
return;
}
-
+
// The first frame is the idle frame, so skip it when animating
int index = (int)Math.Round ((double)(frames.Length - 2) * stage.Actor.Percent) + 1;
if (base.Pixbuf != frames[index]) {
base.Pixbuf = frames[index];
}
}
-
+
private void ExtractFrames ()
{
if (pixbuf == null) {
@@ -112,28 +112,28 @@ namespace Hyena.Widgets
} else if (pixbuf.Width % frame_width != 0 || pixbuf.Height % frame_height != 0) {
throw new ApplicationException ("Invalid frame dimensions");
}
-
+
int rows = pixbuf.Height / frame_height;
int cols = pixbuf.Width / frame_width;
int frame_count = rows * cols;
-
+
frames = new Gdk.Pixbuf[max_frames > 0 ? max_frames : frame_count];
-
+
for (int y = 0, n = 0; y < rows; y++) {
for (int x = 0; x < cols; x++, n++) {
- frames[n] = new Gdk.Pixbuf (pixbuf, x * frame_width, y * frame_height,
+ frames[n] = new Gdk.Pixbuf (pixbuf, x * frame_width, y * frame_height,
frame_width, frame_height);
-
+
if (max_frames > 0 && n >= max_frames - 1) {
return;
}
}
}
}
-
+
public bool Active {
get { return !Visible ? active_frozen : stage.Playing; }
- set {
+ set {
if (value) {
active_frozen = true;
if (Visible) {
@@ -144,7 +144,7 @@ namespace Hyena.Widgets
if (stage.Playing) {
stage.Pause ();
}
-
+
if (inactive_pixbuf != null) {
base.Pixbuf = inactive_pixbuf;
} else if (frames != null && frames.Length > 1) {
@@ -155,27 +155,27 @@ namespace Hyena.Widgets
}
}
}
-
+
public int FrameWidth {
get { return frame_width; }
set { frame_width = value; }
}
-
+
public int FrameHeight {
get { return frame_height; }
set { frame_height = value; }
}
-
+
public int MaxFrames {
get { return max_frames; }
set { max_frames = value; }
}
-
+
public new Gdk.Pixbuf Pixbuf {
get { return pixbuf; }
set { pixbuf = value; }
}
-
+
public Gdk.Pixbuf InactivePixbuf {
get { return inactive_pixbuf; }
set {
diff --git a/src/Hyena.Gui/Hyena.Widgets/AnimatedWidget.cs b/src/Hyena.Gui/Hyena.Widgets/AnimatedWidget.cs
index a56b0e8..e5e7165 100644
--- a/src/Hyena.Gui/Hyena.Widgets/AnimatedWidget.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/AnimatedWidget.cs
@@ -42,11 +42,11 @@ namespace Hyena.Widgets
IntendingToGo,
Going
}
-
+
internal class AnimatedWidget : Container
{
public event EventHandler WidgetDestroyed;
-
+
public Widget Widget;
public Easing Easing;
public Blocking Blocking;
@@ -58,12 +58,12 @@ namespace Hyena.Widgets
public int StartPadding;
public int EndPadding;
public LinkedListNode <AnimatedWidget> Node;
-
+
private readonly bool horizontal;
private double percent;
private Rectangle widget_alloc;
private Pixmap canvas;
-
+
public AnimatedWidget (Widget widget, uint duration, Easing easing, Blocking blocking, bool horizontal)
{
this.horizontal = horizontal;
@@ -77,11 +77,11 @@ namespace Hyena.Widgets
Widget.Destroyed += OnWidgetDestroyed;
ShowAll ();
}
-
+
protected AnimatedWidget (IntPtr raw) : base (raw)
{
}
-
+
public double Percent {
get { return percent; }
set {
@@ -89,24 +89,24 @@ namespace Hyena.Widgets
QueueResizeNoRedraw ();
}
}
-
+
private void OnWidgetDestroyed (object sender, EventArgs args)
{
if (!IsRealized) {
return;
}
-
+
canvas = new Pixmap (GdkWindow, widget_alloc.Width, widget_alloc.Height);
canvas.DrawDrawable (Style.BackgroundGC (State), GdkWindow,
widget_alloc.X, widget_alloc.Y, 0, 0, widget_alloc.Width, widget_alloc.Height);
-
+
if (AnimationState != AnimationState.Going) {
WidgetDestroyed (this, args);
}
}
-
+
#region Overrides
-
+
protected override void OnRemoved (Widget widget)
{
if (widget == Widget) {
@@ -114,22 +114,22 @@ namespace Hyena.Widgets
Widget = null;
}
}
-
+
protected override void OnRealized ()
{
WidgetFlags |= WidgetFlags.Realized;
-
+
Gdk.WindowAttr attributes = new Gdk.WindowAttr ();
attributes.WindowType = Gdk.WindowType.Child;
attributes.Wclass = Gdk.WindowClass.InputOutput;
attributes.EventMask = (int)Gdk.EventMask.ExposureMask;
-
+
GdkWindow = new Gdk.Window (Parent.GdkWindow, attributes, 0);
GdkWindow.UserData = Handle;
GdkWindow.Background = Style.Background (State);
Style.Attach (GdkWindow);
}
-
+
protected override void OnSizeRequested (ref Requisition requisition)
{
if (Widget != null) {
@@ -137,7 +137,7 @@ namespace Hyena.Widgets
widget_alloc.Width = req.Width;
widget_alloc.Height = req.Height;
}
-
+
if (horizontal) {
Width = Choreographer.PixelCompose (percent, widget_alloc.Width + StartPadding + EndPadding, Easing);
Height = widget_alloc.Height;
@@ -145,11 +145,11 @@ namespace Hyena.Widgets
Width = widget_alloc.Width;
Height = Choreographer.PixelCompose (percent, widget_alloc.Height + StartPadding + EndPadding, Easing);
}
-
+
requisition.Width = Width;
requisition.Height = Height;
}
-
+
protected override void OnSizeAllocated (Rectangle allocation)
{
base.OnSizeAllocated (allocation);
@@ -170,7 +170,7 @@ namespace Hyena.Widgets
Widget.SizeAllocate (widget_alloc);
}
}
-
+
protected override bool OnExposeEvent (EventExpose evnt)
{
if (canvas != null) {
@@ -188,8 +188,8 @@ namespace Hyena.Widgets
callback (Widget);
}
}
-
+
#endregion
-
+
}
}
\ No newline at end of file
diff --git a/src/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs b/src/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs
index f9d046b..a6191fd 100644
--- a/src/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs
@@ -1,4 +1,4 @@
-//
+//
// ComplexMenuItem.cs
//
// Author:
@@ -54,7 +54,7 @@ namespace Hyena.Widgets
protected override void OnRemoved (Widget widget)
{
}
-
+
protected void ConnectChildExpose(Widget widget)
{
widget.ExposeEvent += OnChildExposeEvent;
@@ -67,7 +67,7 @@ namespace Hyena.Widgets
// into a GtkMenuItem without breaking the theme (leaving an unstyled void in the item).
// This method is called before the EventBox child does its drawing and the background
// is filled in with the proper style.
-
+
int x, y, width, height;
Widget widget = (Widget)o;
@@ -76,17 +76,17 @@ namespace Hyena.Widgets
y = Allocation.Y - widget.Allocation.Y;
width = Allocation.Width;
height = Allocation.Height;
-
+
ShadowType shadow_type = (ShadowType)StyleGetProperty("selected-shadow-type");
Gtk.Style.PaintBox(Style, widget.GdkWindow, StateType.Prelight, shadow_type,
args.Event.Area, widget, "menuitem", x, y, width, height);
} else {
// Fill only the visible area in solid color, to be most efficient
- widget.GdkWindow.DrawRectangle(Parent.Style.BackgroundGC(StateType.Normal),
+ widget.GdkWindow.DrawRectangle(Parent.Style.BackgroundGC(StateType.Normal),
true, 0, 0, widget.Allocation.Width, widget.Allocation.Height);
-
- // FIXME: The above should not be necessary, but Clearlooks-based themes apparently
- // don't provide any style for the menu background so we have to fill it first with
+
+ // FIXME: The above should not be necessary, but Clearlooks-based themes apparently
+ // don't provide any style for the menu background so we have to fill it first with
// the correct theme color. Weak.
//
// Do a complete style paint based on the size of the entire menu to be compatible with
@@ -95,35 +95,35 @@ namespace Hyena.Widgets
y = Parent.Allocation.Y - widget.Allocation.Y;
width = Parent.Allocation.Width;
height = Parent.Allocation.Height;
-
+
Gtk.Style.PaintBox(Style, widget.GdkWindow, StateType.Normal, ShadowType.Out,
args.Event.Area, widget, "menu", x, y, width, height);
}
}
-
+
protected override void OnSelected()
{
base.OnSelected();
is_selected = true;
}
-
+
protected override void OnDeselected()
{
base.OnDeselected();
is_selected = false;
}
-
+
protected override void OnParentSet(Widget previous_parent)
{
if(previous_parent != null) {
previous_parent.KeyPressEvent -= OnKeyPressEventProxy;
}
-
+
if(Parent != null) {
Parent.KeyPressEvent += OnKeyPressEventProxy;
}
}
-
+
[GLib.ConnectBefore]
private void OnKeyPressEventProxy(object o, KeyPressEventArgs args)
{
@@ -145,7 +145,7 @@ namespace Hyena.Widgets
{
return false;
}
-
+
protected bool IsSelected {
get { return is_selected; }
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/GenericToolItem.cs b/src/Hyena.Gui/Hyena.Widgets/GenericToolItem.cs
index c89ad25..ec83d0e 100644
--- a/src/Hyena.Gui/Hyena.Widgets/GenericToolItem.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/GenericToolItem.cs
@@ -34,13 +34,13 @@ namespace Hyena.Widgets
public class GenericToolItem<T> : ToolItem where T : Widget
{
private T widget;
-
+
public GenericToolItem (T widget)
{
this.widget = widget;
Add (widget);
}
-
+
public T Widget {
get { return widget; }
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/HigMessageDialog.cs b/src/Hyena.Gui/Hyena.Widgets/HigMessageDialog.cs
index 15910cc..d23d108 100644
--- a/src/Hyena.Gui/Hyena.Widgets/HigMessageDialog.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/HigMessageDialog.cs
@@ -25,13 +25,13 @@
// 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 Hyena.Widgets
{
public class HigMessageDialog : Gtk.Dialog
- {
+ {
private Gtk.AccelGroup accel_group;
private Gtk.Image image;
private Gtk.VBox label_vbox;
@@ -82,7 +82,7 @@ namespace Hyena.Widgets
image.Yalign = 0.1f;
image.Show ();
hbox.PackStart (image, false, false, 0);
-
+
label_vbox = new Gtk.VBox (false, 0);
label_vbox.Show ();
hbox.PackStart (label_vbox, true, true, 0);
@@ -109,7 +109,7 @@ namespace Hyena.Widgets
label.SetAlignment (0.0f, 0.5f);
label.Show ();
label_vbox.PackStart (label, false, false, 0);
-
+
switch (buttons) {
case Gtk.ButtonsType.None:
break;
@@ -163,7 +163,7 @@ namespace Hyena.Widgets
AddButton (button, response, isDefault);
return button;
}
-
+
public void AddButton (string stock_id, Gtk.ResponseType response, bool isDefault)
{
Gtk.Button button = new Gtk.Button (stock_id);
@@ -180,7 +180,7 @@ namespace Hyena.Widgets
DefaultResponse = response;
button.AddAccelerator ("activate",
accel_group,
- (uint) Gdk.Key.Return,
+ (uint) Gdk.Key.Return,
0,
Gtk.AccelFlags.Visible);
}
@@ -199,7 +199,7 @@ namespace Hyena.Widgets
return (Gtk.ResponseType)hmd.Run();
} finally {
hmd.Destroy();
- }
+ }
}
//Run and destroy a standard confirmation dialog
@@ -215,23 +215,23 @@ namespace Hyena.Widgets
return (Gtk.ResponseType)hmd.Run();
} finally {
hmd.Destroy();
- }
+ }
}
-
+
public Gdk.Pixbuf Image {
set {
image.Pixbuf = value;
}
-
+
get {
return image.Pixbuf;
}
}
-
+
public Gtk.Label MessageLabel {
get { return message_label; }
}
-
+
public Gtk.VBox LabelVBox {
get { return label_vbox; }
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/ImageButton.cs b/src/Hyena.Gui/Hyena.Widgets/ImageButton.cs
index a3db0b0..33f67e1 100644
--- a/src/Hyena.Gui/Hyena.Widgets/ImageButton.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/ImageButton.cs
@@ -36,7 +36,7 @@ namespace Hyena.Widgets
public ImageButton (string text, string iconName) : this (text, iconName, Gtk.IconSize.Button)
{
}
-
+
public ImageButton (string text, string iconName, Gtk.IconSize iconSize) : base ()
{
Image image = new Image ();
diff --git a/src/Hyena.Gui/Hyena.Widgets/MenuButton.cs b/src/Hyena.Gui/Hyena.Widgets/MenuButton.cs
index fa25d84..f40dbbd 100644
--- a/src/Hyena.Gui/Hyena.Widgets/MenuButton.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/MenuButton.cs
@@ -40,32 +40,32 @@ namespace Hyena.Widgets
private Widget button_widget;
private Menu menu;
private Widget size_widget;
-
+
public MenuButton ()
{
}
-
+
public MenuButton (Widget buttonWidget, Menu menu, bool showArrow)
{
Construct (buttonWidget, menu, showArrow);
}
-
+
protected void Construct (Widget buttonWidget, Menu menu, bool showArrow)
{
WidgetFlags |= WidgetFlags.NoWindow;
-
+
button_widget = buttonWidget;
this.menu = menu;
menu.Deactivated += delegate { toggle_button.Active = false; };
-
+
toggle_button.Parent = this;
toggle_button.FocusOnClick = false;
toggle_button.Relief = ReliefStyle.None;
toggle_button.Pressed += delegate { ShowMenu (); toggle_button.Active = true; };
toggle_button.Activated += delegate { ShowMenu (); };
-
+
box.Parent = this;
-
+
if (showArrow) {
box.PackStart (button_widget, true, true, 0);
alignment = new Alignment (0f, 0.5f, 0f, 0f);
@@ -77,70 +77,70 @@ namespace Hyena.Widgets
toggle_button.Add (button_widget);
size_widget = toggle_button;
}
-
+
ShowAll ();
}
-
+
public Widget ButtonWidget {
get { return button_widget; }
}
-
+
public Menu Menu {
get { return menu; }
}
-
+
protected ToggleButton ToggleButton {
get { return toggle_button; }
}
-
+
protected Arrow Arrow {
get { return arrow; }
}
-
+
protected override void OnSizeRequested (ref Requisition requisition)
{
requisition = size_widget.SizeRequest ();
}
-
+
protected override void OnSizeAllocated (Rectangle allocation)
{
box.SizeAllocate (allocation);
toggle_button.SizeAllocate (allocation);
base.OnSizeAllocated (allocation);
}
-
+
protected override void ForAll (bool include_internals, Callback callback)
{
callback (toggle_button);
callback (box);
}
-
+
protected override void OnAdded (Widget widget)
{
}
-
+
protected override void OnRemoved (Widget widget)
{
}
-
+
protected void ShowMenu ()
{
menu.Popup (null, null, PositionMenu, 1, Gtk.Global.CurrentEventTime);
}
- private void PositionMenu (Menu menu, out int x, out int y, out bool push_in)
+ private void PositionMenu (Menu menu, out int x, out int y, out bool push_in)
{
Gtk.Requisition menu_req = menu.SizeRequest ();
int monitor_num = Screen.GetMonitorAtWindow (GdkWindow);
Gdk.Rectangle monitor = Screen.GetMonitorGeometry (monitor_num < 0 ? 0 : monitor_num);
GdkWindow.GetOrigin (out x, out y);
-
+
y += Allocation.Y;
x += Allocation.X + (Direction == TextDirection.Ltr
? Math.Max (Allocation.Width - menu_req.Width, 0)
: - (menu_req.Width - Allocation.Width));
-
+
if (y + Allocation.Height + menu_req.Height <= monitor.Y + monitor.Height) {
y += Allocation.Height;
} else if (y - menu_req.Height >= monitor.Y) {
diff --git a/src/Hyena.Gui/Hyena.Widgets/MessageBar.cs b/src/Hyena.Gui/Hyena.Widgets/MessageBar.cs
index 8ea5c31..c1e901e 100644
--- a/src/Hyena.Gui/Hyena.Widgets/MessageBar.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/MessageBar.cs
@@ -35,7 +35,7 @@ using Hyena.Gui.Theming;
namespace Hyena.Widgets
{
public class MessageBar : Alignment
- {
+ {
private HBox box;
private HBox button_box;
private AnimatedImage image;
@@ -43,14 +43,14 @@ namespace Hyena.Widgets
private Button close_button;
private Window win;
-
+
private Theme theme;
-
+
public event EventHandler CloseClicked {
add { close_button.Clicked += value; }
remove { close_button.Clicked -= value; }
}
-
+
public MessageBar () : base (0.0f, 0.5f, 1.0f, 0.0f)
{
win = new Window (WindowType.Popup);
@@ -62,10 +62,10 @@ namespace Hyena.Widgets
HBox shell_box = new HBox ();
shell_box.Spacing = 10;
-
+
box = new HBox ();
box.Spacing = 10;
-
+
image = new AnimatedImage ();
try {
image.Pixbuf = Gtk.IconTheme.Default.LoadIcon ("process-working", 22, IconLookupFlags.NoSvg);
@@ -75,68 +75,68 @@ namespace Hyena.Widgets
image.Load ();
} catch {
}
-
+
label = new Label ();
label.Xalign = 0.0f;
label.Show ();
-
+
box.PackStart (image, false, false, 0);
box.PackStart (label, true, true, 0);
box.Show ();
-
+
button_box = new HBox ();
button_box.Spacing = 3;
-
+
close_button = new Button (new Image (Stock.Close, IconSize.Menu));
close_button.Relief = ReliefStyle.None;
close_button.Clicked += delegate { Hide (); };
close_button.ShowAll ();
close_button.Hide ();
-
+
shell_box.PackStart (box, true, true, 0);
shell_box.PackStart (button_box, false, false, 0);
shell_box.PackStart (close_button, false, false, 0);
shell_box.Show ();
-
+
Add (shell_box);
-
+
EnsureStyle ();
BorderWidth = 3;
}
-
+
protected override void OnShown ()
{
base.OnShown ();
image.Show ();
}
-
+
protected override void OnHidden ()
{
base.OnHidden ();
image.Hide ();
}
-
+
protected override void OnRealized ()
{
base.OnRealized ();
theme = Hyena.Gui.Theming.ThemeEngine.CreateTheme (this);
}
-
+
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
base.OnSizeAllocated (allocation);
QueueDraw ();
}
-
+
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
{
if (!IsDrawable) {
return false;
}
-
+
Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window);
-
+
try {
Gdk.Color color = Style.Background (StateType.Normal);
theme.DrawFrame (cr, Allocation, CairoExtensions.GdkColorToCairoColor (color));
@@ -146,60 +146,60 @@ namespace Hyena.Widgets
((IDisposable)cr).Dispose ();
}
}
-
+
private bool changing_style = false;
protected override void OnStyleSet (Gtk.Style previousStyle)
{
if (changing_style) {
return;
}
-
+
changing_style = true;
Style = win.Style;
label.Style = Style;
changing_style = false;
}
-
+
public void RemoveButton (Button button)
{
button_box.Remove (button);
}
-
+
public void ClearButtons ()
{
foreach (Widget child in button_box.Children) {
button_box.Remove (child);
}
}
-
+
public void AddButton (Button button)
{
button_box.Show ();
button.Show ();
button_box.PackStart (button, false, false, 0);
}
-
+
public bool ShowCloseButton {
set {
close_button.Visible = value;
QueueDraw ();
}
}
-
+
public string Message {
set {
label.Markup = value;
QueueDraw ();
}
}
-
+
public Gdk.Pixbuf Pixbuf {
set {
image.InactivePixbuf = value;
QueueDraw ();
}
}
-
+
public bool Spinning {
get { return image.Active; }
set { image.Active = value; }
diff --git a/src/Hyena.Gui/Hyena.Widgets/PulsingButton.cs b/src/Hyena.Gui/Hyena.Widgets/PulsingButton.cs
index 49d31bc..c7b57eb 100644
--- a/src/Hyena.Gui/Hyena.Widgets/PulsingButton.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/PulsingButton.cs
@@ -38,63 +38,63 @@ namespace Hyena.Widgets
{
private static Stage<PulsingButton> default_stage;
public static Stage<PulsingButton> DefaultStage {
- get {
+ get {
if (default_stage == null) {
default_stage = new Stage<PulsingButton> ();
default_stage.DefaultActorDuration = 1250;
}
-
+
return default_stage;
}
}
-
+
private Pulsator<PulsingButton> pulsator = new Pulsator<PulsingButton> ();
-
+
public Stage<PulsingButton> Stage {
get { return pulsator.Stage; }
set { pulsator.Stage = value; }
}
-
+
public PulsingButton () : base ()
{
Setup ();
}
-
+
public PulsingButton (string stock_id) : base (stock_id)
{
Setup ();
}
-
+
public PulsingButton (Widget widget) : base (widget)
{
Setup ();
}
-
+
protected PulsingButton (IntPtr raw) : base (raw)
{
Setup ();
}
-
+
private void Setup ()
{
Stage = DefaultStage;
pulsator.Target = this;
pulsator.Pulse += delegate { QueueDraw (); };
}
-
+
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
{
if (!pulsator.IsPulsing) {
return base.OnExposeEvent (evnt);
}
-
+
Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow);
-
+
double x = Allocation.X + Allocation.Width / 2;
double y = Allocation.Y + Allocation.Height / 2;
double r = Math.Min (Allocation.Width, Allocation.Height) / 2;
double alpha = Choreographer.Compose (pulsator.Percent, Easing.Sine);
-
+
Cairo.Color color = CairoExtensions.GdkColorToCairoColor (Style.Background (StateType.Selected));
Cairo.RadialGradient fill = new Cairo.RadialGradient (x, y, 0, x, y, r);
color.A = alpha;
@@ -102,28 +102,28 @@ namespace Hyena.Widgets
fill.AddColorStop (0.5, color);
color.A = 0;
fill.AddColorStop (1, color);
-
+
cr.Arc (x, y, r, 0, 2 * Math.PI);
cr.Pattern = fill;
cr.Fill ();
fill.Destroy ();
-
+
((IDisposable)cr).Dispose ();
return base.OnExposeEvent (evnt);
}
-
+
public void StartPulsing ()
{
if (IsMapped && Sensitive) {
pulsator.StartPulsing ();
}
}
-
+
public void StopPulsing ()
{
pulsator.StopPulsing ();
}
-
+
protected override void OnStateChanged (StateType previous_state)
{
base.OnStateChanged (previous_state);
diff --git a/src/Hyena.Gui/Hyena.Widgets/RatingEntry.cs b/src/Hyena.Gui/Hyena.Widgets/RatingEntry.cs
index e315058..4fcf73a 100644
--- a/src/Hyena.Gui/Hyena.Widgets/RatingEntry.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/RatingEntry.cs
@@ -1,4 +1,4 @@
-//
+//
// RatingEntry.cs
//
// Authors:
@@ -43,11 +43,11 @@ namespace Hyena.Widgets
private bool interior_focus;
private int focus_width;
private Gdk.Window event_window;
-
+
public event EventHandler Changing;
public event EventHandler Changed;
-
- public RatingEntry () : this (0)
+
+ public RatingEntry () : this (0)
{
WidgetFlags |= Gtk.WidgetFlags.NoWindow;
}
@@ -59,7 +59,7 @@ namespace Hyena.Widgets
CanFocus = true;
Name = "GtkEntry";
}
-
+
protected virtual void OnChanging ()
{
EventHandler handler = Changing;
@@ -82,7 +82,7 @@ namespace Hyena.Widgets
{
Value = renderer.RatingFromPosition (event_alloc, x);
}
-
+
#region Public Properties
private bool always_show_empty_stars = false;
@@ -113,27 +113,27 @@ namespace Hyena.Widgets
}
}
}
-
+
public int MaxRating {
get { return renderer.MaxRating; }
set { renderer.MaxRating = value; }
}
-
+
public int MinRating {
get { return renderer.MinRating; }
set { renderer.MinRating = value; }
}
-
+
public int RatingLevels {
get { return renderer.RatingLevels; }
}
-
+
private object rated_object;
public object RatedObject {
get { return rated_object; }
set { rated_object = value; }
}
-
+
#endregion
#region Protected Gtk.Widget Overrides
@@ -142,7 +142,7 @@ namespace Hyena.Widgets
{
WidgetFlags |= WidgetFlags.Realized | WidgetFlags.NoWindow;
GdkWindow = Parent.GdkWindow;
-
+
Gdk.WindowAttr attributes = new Gdk.WindowAttr ();
attributes.WindowType = Gdk.WindowType.Child;
attributes.X = Allocation.X;
@@ -159,37 +159,37 @@ namespace Hyena.Widgets
Gdk.EventMask.ButtonPressMask |
Gdk.EventMask.ButtonReleaseMask |
Gdk.EventMask.ExposureMask);
-
+
Gdk.WindowAttributesType attributes_mask =
- Gdk.WindowAttributesType.X |
+ Gdk.WindowAttributesType.X |
Gdk.WindowAttributesType.Y |
Gdk.WindowAttributesType.Wmclass;
-
+
event_window = new Gdk.Window (GdkWindow, attributes, attributes_mask);
event_window.UserData = Handle;
-
+
Style = Gtk.Rc.GetStyleByPaths (Settings, "*.GtkEntry", "*.GtkEntry", GType);
-
+
base.OnRealized ();
}
-
+
protected override void OnUnrealized ()
{
WidgetFlags &= ~WidgetFlags.Realized;
-
+
event_window.UserData = IntPtr.Zero;
Hyena.Gui.GtkWorkarounds.WindowDestroy (event_window);
event_window = null;
-
+
base.OnUnrealized ();
}
-
+
protected override void OnMapped ()
{
WidgetFlags |= WidgetFlags.Mapped;
event_window.Show ();
}
-
+
protected override void OnUnmapped ()
{
WidgetFlags &= ~WidgetFlags.Mapped;
@@ -202,15 +202,15 @@ namespace Hyena.Widgets
if (changing_style) {
return;
}
-
+
base.OnStyleSet (previous_style);
-
+
changing_style = true;
focus_width = (int)StyleGetProperty ("focus-line-width");
interior_focus = (bool)StyleGetProperty ("interior-focus");
changing_style = false;
}
-
+
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
base.OnSizeAllocated (allocation);
@@ -219,15 +219,15 @@ namespace Hyena.Widgets
event_window.MoveResize (allocation);
}
}
-
+
protected override void OnSizeRequested (ref Gtk.Requisition requisition)
{
EnsureStyle ();
-
+
Pango.FontMetrics metrics = PangoContext.GetMetrics (Style.FontDescription, PangoContext.Language);
renderer.Size = ((int)(metrics.Ascent + metrics.Descent) + 512) >> 10; // PANGO_PIXELS(d)
metrics.Dispose ();
-
+
if (HasFrame) {
renderer.Xpad = Style.Xthickness + (interior_focus ? focus_width : 0) + 2;
renderer.Ypad = Style.Ythickness + (interior_focus ? focus_width : 0) + 2;
@@ -235,30 +235,30 @@ namespace Hyena.Widgets
renderer.Xpad = 0;
renderer.Ypad = 0;
}
-
+
requisition.Width = renderer.Width;
requisition.Height = renderer.Height;
}
-
+
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
{
if (evnt.Window != GdkWindow) {
return true;
}
-
+
if (HasFrame) {
int y_mid = (int)Math.Round ((Allocation.Height - renderer.Height) / 2.0);
- Gtk.Style.PaintFlatBox (Style, GdkWindow, State, ShadowType.None, evnt.Area, this, "entry",
+ Gtk.Style.PaintFlatBox (Style, GdkWindow, State, ShadowType.None, evnt.Area, this, "entry",
Allocation.X, Allocation.Y + y_mid, Allocation.Width, renderer.Height);
Gtk.Style.PaintShadow (Style, GdkWindow, State, ShadowType.In,
evnt.Area, this, "entry", Allocation.X, Allocation.Y + y_mid, Allocation.Width, renderer.Height);
}
-
+
Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow);
- renderer.Render (cr, Allocation,
+ renderer.Render (cr, Allocation,
CairoExtensions.GdkColorToCairoColor (HasFrame ? Parent.Style.Text (State) : Parent.Style.Foreground (State)),
AlwaysShowEmptyStars, PreviewOnHover && hover_value >= renderer.MinRating, hover_value,
- State == StateType.Insensitive ? 1 : 0.90,
+ State == StateType.Insensitive ? 1 : 0.90,
State == StateType.Insensitive ? 1 : 0.55,
State == StateType.Insensitive ? 1 : 0.45);
((IDisposable)cr.Target).Dispose ();
@@ -272,30 +272,30 @@ namespace Hyena.Widgets
if (evnt.Button != 1) {
return false;
}
-
+
HasFocus = true;
Value = renderer.RatingFromPosition (event_alloc, evnt.X);
-
+
return true;
}
-
+
protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
{
hover_value = renderer.MinRating;
QueueDraw ();
return true;
}
-
+
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing crossing)
{
return HandleLeaveNotify (crossing);
}
-
+
protected override bool OnMotionNotifyEvent (Gdk.EventMotion motion)
{
return HandleMotionNotify (motion.State, motion.X);
}
-
+
protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
{
switch (evnt.Key) {
@@ -305,22 +305,22 @@ namespace Hyena.Widgets
case Gdk.Key.equal:
Value++;
return true;
-
+
case Gdk.Key.Down:
case Gdk.Key.Left:
case Gdk.Key.minus:
Value--;
return true;
}
-
+
if (evnt.KeyValue >= (48 + MinRating) && evnt.KeyValue <= (48 + MaxRating) && evnt.KeyValue <= 59) {
Value = (int)evnt.KeyValue - 48;
return true;
}
-
+
return false;
}
-
+
protected override bool OnScrollEvent (Gdk.EventScroll args)
{
return HandleScroll (args);
@@ -329,7 +329,7 @@ namespace Hyena.Widgets
#endregion
#region Internal API, primarily for RatingMenuItem
-
+
internal void ClearHover ()
{
hover_value = renderer.MinRating - 1;
@@ -347,38 +347,38 @@ namespace Hyena.Widgets
case Gdk.ScrollDirection.Right:
Value++;
return true;
-
+
case Gdk.ScrollDirection.Down:
case Gdk.ScrollDirection.Left:
Value--;
return true;
}
-
+
return false;
}
-
+
internal bool HandleMotionNotify (Gdk.ModifierType state, double x)
{
hover_value = renderer.RatingFromPosition (event_alloc, x);
/*if ((state & Gdk.ModifierType.Button1Mask) != 0) {
Value = hover_value;
}*/
-
+
QueueDraw ();
return true;
}
-
+
internal bool HandleLeaveNotify (Gdk.EventCrossing crossing)
{
ClearHover ();
QueueDraw ();
return true;
}
-
+
#endregion
}
-
+
#region Test Module
[Hyena.Gui.TestModule ("Rating Entry")]
@@ -388,7 +388,7 @@ namespace Hyena.Widgets
{
VBox pbox = new VBox ();
Add (pbox);
-
+
Menu m = new Menu ();
MenuBar b = new MenuBar ();
MenuItem item = new MenuItem ("Rate Me!");
@@ -400,30 +400,30 @@ namespace Hyena.Widgets
m.Append (new ImageMenuItem ("gtk-remove", null));
m.ShowAll ();
pbox.PackStart (b, false, false, 0);
-
+
VBox box = new VBox ();
box.BorderWidth = 10;
box.Spacing = 10;
pbox.PackStart (box, true, true, 0);
-
+
RatingEntry entry1 = new RatingEntry ();
box.PackStart (entry1, true, true, 0);
-
+
RatingEntry entry2 = new RatingEntry ();
box.PackStart (entry2, false, false, 0);
-
+
box.PackStart (new Entry ("Normal GtkEntry"), false, false, 0);
-
+
RatingEntry entry3 = new RatingEntry ();
Pango.FontDescription fd = entry3.PangoContext.FontDescription.Copy ();
fd.Size = (int)(fd.Size * Pango.Scale.XXLarge);
entry3.ModifyFont (fd);
box.PackStart (entry3, true, true, 0);
-
+
pbox.ShowAll ();
}
}
-
+
#endregion
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/RatingMenuItem.cs b/src/Hyena.Gui/Hyena.Widgets/RatingMenuItem.cs
index 01f71f0..a4276db 100644
--- a/src/Hyena.Gui/Hyena.Widgets/RatingMenuItem.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/RatingMenuItem.cs
@@ -1,4 +1,4 @@
-//
+//
// RatingMenuItem.cs
//
// Author:
@@ -42,20 +42,20 @@ namespace Hyena.Widgets
{
box = new HBox ();
box.Spacing = 5;
-
+
Label label = new Label ();
- label.Markup = String.Format ("<i>{0}</i>",
+ label.Markup = String.Format ("<i>{0}</i>",
GLib.Markup.EscapeText (Catalog.GetString ("Rating:")));
box.PackStart (label, false, false, 0);
label.Show ();
-
+
entry = new RatingEntry ();
entry.HasFrame = false;
entry.PreviewOnHover = true;
entry.AlwaysShowEmptyStars = true;
entry.Changed += OnEntryChanged;
box.PackStart (entry, false, false, 0);
-
+
box.ShowAll ();
Add (box);
}
@@ -86,7 +86,7 @@ namespace Hyena.Widgets
{
return entry.HandleMotionNotify (evnt.State, TransformX (evnt.X));
}
-
+
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
{
return entry.HandleLeaveNotify (evnt);
@@ -101,14 +101,14 @@ namespace Hyena.Widgets
{
return entry.HandleKeyPress (evnt);
}
-
+
private void OnEntryChanged (object o, EventArgs args)
{
if (can_activate) {
Activate ();
}
}
-
+
public void Reset (int value)
{
can_activate = false;
@@ -116,12 +116,12 @@ namespace Hyena.Widgets
entry.ClearHover ();
can_activate = true;
}
-
+
public int Value {
get { return entry.Value; }
set { entry.Value = value; }
}
-
+
public RatingEntry RatingEntry {
get { return entry; }
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/RoundedFrame.cs b/src/Hyena.Gui/Hyena.Widgets/RoundedFrame.cs
index ddee186..0e5d9f6 100644
--- a/src/Hyena.Gui/Hyena.Widgets/RoundedFrame.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/RoundedFrame.cs
@@ -42,9 +42,9 @@ namespace Hyena.Widgets
protected Theme Theme {
get { return theme; }
}
-
+
private int frame_width = 3;
-
+
private Widget child;
private Gdk.Rectangle child_allocation;
private bool fill_color_set;
@@ -56,24 +56,24 @@ namespace Hyena.Widgets
protected RoundedFrame (IntPtr ptr) : base (ptr)
{
}
-
+
public RoundedFrame ()
{
}
-
+
public void SetFillColor (Cairo.Color color)
{
fill_color = color;
fill_color_set = true;
QueueDraw ();
}
-
+
public void UnsetFillColor ()
{
fill_color_set = false;
QueueDraw ();
}
-
+
public Pattern FillPattern {
get { return fill_pattern; }
set {
@@ -81,12 +81,12 @@ namespace Hyena.Widgets
QueueDraw ();
}
}
-
+
public bool DrawBorder {
get { return draw_border; }
set { draw_border = value; QueueDraw (); }
}
-
+
#region Gtk.Widget Overrides
protected override void OnRealized ()
@@ -98,7 +98,7 @@ namespace Hyena.Widgets
protected override void OnSizeRequested (ref Requisition requisition)
{
if (child != null && child.Visible) {
- // Add the child's width/height
+ // Add the child's width/height
Requisition child_requisition = child.SizeRequest ();
requisition.Width = Math.Max (0, child_requisition.Width);
requisition.Height = child_requisition.Height;
@@ -106,7 +106,7 @@ namespace Hyena.Widgets
requisition.Width = 0;
requisition.Height = 0;
}
-
+
// Add the frame border
requisition.Width += ((int)BorderWidth + frame_width) * 2;
requisition.Height += ((int)BorderWidth + frame_width) * 2;
@@ -115,40 +115,40 @@ namespace Hyena.Widgets
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
base.OnSizeAllocated (allocation);
-
+
child_allocation = new Gdk.Rectangle ();
-
+
if (child == null || !child.Visible) {
return;
}
-
+
child_allocation.X = (int)BorderWidth + frame_width;
child_allocation.Y = (int)BorderWidth + frame_width;
child_allocation.Width = (int)Math.Max (1, Allocation.Width - child_allocation.X * 2);
- child_allocation.Height = (int)Math.Max (1, Allocation.Height - child_allocation.Y -
+ child_allocation.Height = (int)Math.Max (1, Allocation.Height - child_allocation.Y -
(int)BorderWidth - frame_width);
-
+
child_allocation.X += Allocation.X;
child_allocation.Y += Allocation.Y;
-
+
child.SizeAllocate (child_allocation);
}
-
+
protected override void OnSetScrollAdjustments (Adjustment hadj, Adjustment vadj)
{
- // This is to satisfy the gtk_widget_set_scroll_adjustments
- // inside of GtkScrolledWindow so it doesn't complain about
+ // This is to satisfy the gtk_widget_set_scroll_adjustments
+ // inside of GtkScrolledWindow so it doesn't complain about
// its child not being scrollable.
}
-
+
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
{
if (!IsDrawable) {
return false;
}
-
+
Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window);
-
+
try {
DrawFrame (cr, evnt.Area);
if (child != null) {
@@ -160,18 +160,18 @@ namespace Hyena.Widgets
((IDisposable)cr).Dispose ();
}
}
-
+
private void DrawFrame (Cairo.Context cr, Gdk.Rectangle clip)
{
int x = child_allocation.X - frame_width;
int y = child_allocation.Y - frame_width;
int width = child_allocation.Width + 2 * frame_width;
int height = child_allocation.Height + 2 * frame_width;
-
+
Gdk.Rectangle rect = new Gdk.Rectangle (x, y, width, height);
-
+
theme.Context.ShowStroke = draw_border;
-
+
if (fill_color_set) {
theme.DrawFrameBackground (cr, rect, fill_color);
} else if (fill_pattern != null) {
diff --git a/src/Hyena.Gui/Hyena.Widgets/ScrolledWindow.cs b/src/Hyena.Gui/Hyena.Widgets/ScrolledWindow.cs
index f2dbff3..91bb0a2 100644
--- a/src/Hyena.Gui/Hyena.Widgets/ScrolledWindow.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/ScrolledWindow.cs
@@ -42,21 +42,21 @@ namespace Hyena.Widgets
{
private Widget adjustable;
private RoundedFrame rounded_frame;
-
+
public ScrolledWindow ()
{
}
-
+
public void AddWithFrame (Widget widget)
{
RoundedFrame frame = new RoundedFrame ();
frame.Add (widget);
frame.Show ();
-
+
Add (frame);
ProbeAdjustable (widget);
}
-
+
protected override void OnAdded (Widget widget)
{
if (widget is RoundedFrame) {
@@ -64,10 +64,10 @@ namespace Hyena.Widgets
rounded_frame.Added += OnFrameWidgetAdded;
rounded_frame.Removed += OnFrameWidgetRemoved;
}
-
+
base.OnAdded (widget);
}
-
+
protected override void OnRemoved (Widget widget)
{
if (widget == rounded_frame) {
@@ -75,17 +75,17 @@ namespace Hyena.Widgets
rounded_frame.Removed -= OnFrameWidgetRemoved;
rounded_frame = null;
}
-
+
base.OnRemoved (widget);
}
-
+
private void OnFrameWidgetAdded (object o, AddedArgs args)
{
if (rounded_frame != null) {
ProbeAdjustable (args.Widget);
}
}
-
+
private void OnFrameWidgetRemoved (object o, RemovedArgs args)
{
if (adjustable != null && adjustable == args.Widget) {
@@ -94,27 +94,27 @@ namespace Hyena.Widgets
adjustable = null;
}
}
-
+
private void ProbeAdjustable (Widget widget)
{
Type type = widget.GetType ();
-
+
PropertyInfo hadj_prop = type.GetProperty ("Hadjustment");
PropertyInfo vadj_prop = type.GetProperty ("Vadjustment");
-
+
if (hadj_prop == null || vadj_prop == null) {
return;
}
-
+
object hadj_value = hadj_prop.GetValue (widget, null);
object vadj_value = vadj_prop.GetValue (widget, null);
-
- if (hadj_value == null || vadj_value == null
+
+ if (hadj_value == null || vadj_value == null
|| hadj_value.GetType () != typeof (Adjustment)
|| vadj_value.GetType () != typeof (Adjustment)) {
return;
}
-
+
Hadjustment = (Adjustment)hadj_value;
Vadjustment = (Adjustment)vadj_value;
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs b/src/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
index 0ea36b2..5f5f0a2 100644
--- a/src/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
@@ -39,19 +39,19 @@ namespace Hyena.Widgets
public class SegmentedBar : Widget
{
public delegate string BarValueFormatHandler (Segment segment);
-
+
public class Segment
{
private string title;
private double percent;
private Cairo.Color color;
private bool show_in_bar;
-
- public Segment (string title, double percent, Cairo.Color color)
+
+ public Segment (string title, double percent, Cairo.Color color)
: this (title, percent, color, true)
{
}
-
+
public Segment (string title, double percent, Cairo.Color color, bool showInBar)
{
this.title = title;
@@ -59,36 +59,36 @@ namespace Hyena.Widgets
this.color = color;
this.show_in_bar = showInBar;
}
-
+
public string Title {
get { return title; }
set { title = value; }
}
-
+
public double Percent {
get { return percent; }
set { percent = value; }
}
-
+
public Cairo.Color Color {
get { return color; }
set { color = value; }
}
-
+
public bool ShowInBar {
get { return show_in_bar; }
set { show_in_bar = value; }
}
-
+
internal int LayoutWidth;
internal int LayoutHeight;
}
-
+
// State
private List<Segment> segments = new List<Segment> ();
private int layout_width;
private int layout_height;
-
+
// Properties
private int bar_height = 26;
private int bar_label_spacing = 8;
@@ -96,37 +96,37 @@ namespace Hyena.Widgets
private int segment_box_size = 12;
private int segment_box_spacing = 6;
private int h_padding = 0;
-
+
private bool show_labels = true;
private bool reflect = true;
-
+
private Color remainder_color = CairoExtensions.RgbToColor (0xeeeeee);
-
+
private BarValueFormatHandler format_handler;
-
+
public SegmentedBar ()
{
WidgetFlags |= WidgetFlags.NoWindow;
}
-
+
protected override void OnRealized ()
{
GdkWindow = Parent.GdkWindow;
base.OnRealized ();
}
-
+
#region Size Calculations
-
+
protected override void OnSizeRequested (ref Requisition requisition)
{
requisition.Width = 200;
requisition.Height = 0;
}
-
+
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
int _bar_height = reflect ? (int)Math.Ceiling (bar_height * 1.75) : bar_height;
-
+
if (show_labels) {
ComputeLayoutSize ();
HeightRequest = Math.Max (bar_height + bar_label_spacing + layout_height, _bar_height);
@@ -135,69 +135,69 @@ namespace Hyena.Widgets
HeightRequest = _bar_height;
WidthRequest = bar_height + (2 * h_padding);
}
-
+
base.OnSizeAllocated (allocation);
}
-
+
private void ComputeLayoutSize ()
{
if (segments.Count == 0) {
return;
}
-
+
Pango.Layout layout = null;
-
+
layout_width = layout_height = 0;
-
+
for (int i = 0, n = segments.Count; i < n; i++) {
int aw, ah, bw, bh;
-
+
layout = CreateAdaptLayout (layout, false, true);
layout.SetText (FormatSegmentText (segments[i]));
layout.GetPixelSize (out aw, out ah);
-
+
layout = CreateAdaptLayout (layout, true, false);
layout.SetText (FormatSegmentValue (segments[i]));
layout.GetPixelSize (out bw, out bh);
-
+
int w = Math.Max (aw, bw);
int h = ah + bh;
-
+
segments[i].LayoutWidth = w;
segments[i].LayoutHeight = Math.Max (h, segment_box_size * 2);
-
- layout_width += segments[i].LayoutWidth + segment_box_size + segment_box_spacing
+
+ layout_width += segments[i].LayoutWidth + segment_box_size + segment_box_spacing
+ (i < n - 1 ? segment_label_spacing : 0);
layout_height = Math.Max (layout_height, segments[i].LayoutHeight);
}
-
+
layout.Dispose ();
}
-
+
#endregion
-
+
#region Public Methods
-
+
public void AddSegmentRgba (string title, double percent, uint rgbaColor)
{
AddSegment (title, percent, CairoExtensions.RgbaToColor (rgbaColor));
}
-
+
public void AddSegmentRgb (string title, double percent, uint rgbColor)
{
AddSegment (title, percent, CairoExtensions.RgbToColor (rgbColor));
}
-
+
public void AddSegment (string title, double percent, Color color)
{
AddSegment (new Segment (title, percent, color, true));
}
-
+
public void AddSegment (string title, double percent, Color color, bool showInBar)
{
AddSegment (new Segment (title, percent, color, showInBar));
}
-
+
public void AddSegment (Segment segment)
{
lock (segments) {
@@ -205,30 +205,30 @@ namespace Hyena.Widgets
QueueDraw ();
}
}
-
+
public void UpdateSegment (int index, double percent)
{
segments[index].Percent = percent;
QueueDraw ();
}
-
+
#endregion
-#region Public Properties
-
+#region Public Properties
+
public BarValueFormatHandler ValueFormatter {
get { return format_handler; }
set { format_handler = value; }
}
-
+
public Color RemainderColor {
get { return remainder_color; }
- set {
+ set {
remainder_color = value;
QueueDraw ();
}
}
-
+
public int BarHeight {
get { return bar_height; }
set {
@@ -238,7 +238,7 @@ namespace Hyena.Widgets
}
}
}
-
+
public bool ShowReflection {
get { return reflect; }
set {
@@ -248,7 +248,7 @@ namespace Hyena.Widgets
}
}
}
-
+
public bool ShowLabels {
get { return show_labels; }
set {
@@ -258,10 +258,10 @@ namespace Hyena.Widgets
}
}
}
-
+
public int SegmentLabelSpacing {
get { return segment_label_spacing; }
- set {
+ set {
if (segment_label_spacing != value) {
segment_label_spacing = value;
QueueResize ();
@@ -270,202 +270,202 @@ namespace Hyena.Widgets
}
public int SegmentBoxSize {
get { return segment_box_size; }
- set {
+ set {
if (segment_box_size != value) {
segment_box_size = value;
QueueResize ();
}
}
}
-
+
public int SegmentBoxSpacing {
get { return segment_box_spacing; }
- set {
+ set {
if (segment_box_spacing != value) {
segment_box_spacing = value;
QueueResize ();
}
}
}
-
+
public int BarLabelSpacing {
get { return bar_label_spacing; }
- set {
+ set {
if (bar_label_spacing != value) {
bar_label_spacing = value;
QueueResize ();
}
}
}
-
+
public int HorizontalPadding {
get { return h_padding; }
- set {
+ set {
if (h_padding != value) {
h_padding = value;
QueueResize ();
}
}
}
-
+
#endregion
-
+
#region Rendering
-
+
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
{
if (evnt.Window != GdkWindow) {
return base.OnExposeEvent (evnt);
}
-
+
Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window);
-
+
if (reflect) {
CairoExtensions.PushGroup (cr);
}
-
+
cr.Operator = Operator.Over;
cr.Translate (Allocation.X + h_padding, Allocation.Y);
- cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height,
+ cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height,
bar_height + bar_label_spacing + layout_height));
cr.Clip ();
-
+
Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height);
-
+
cr.Save ();
cr.Source = bar;
cr.Paint ();
cr.Restore ();
-
+
if (reflect) {
cr.Save ();
-
+
cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height);
cr.Clip ();
-
+
Matrix matrix = new Matrix ();
matrix.InitScale (1, -1);
matrix.Translate (0, -(2 * bar_height) + 1);
cr.Transform (matrix);
-
+
cr.Pattern = bar;
-
+
LinearGradient mask = new LinearGradient (0, 0, 0, bar_height);
-
+
mask.AddColorStop (0.25, new Color (0, 0, 0, 0));
mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125));
mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4));
mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7));
-
+
cr.Mask (mask);
mask.Destroy ();
-
+
cr.Restore ();
-
+
CairoExtensions.PopGroupToSource (cr);
cr.Paint ();
}
-
+
if (show_labels) {
- cr.Translate ((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2,
+ cr.Translate ((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2,
(reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing);
-
+
RenderLabels (cr);
}
-
+
bar.Destroy ();
((IDisposable)cr.Target).Dispose ();
((IDisposable)cr).Dispose ();
-
+
return true;
}
-
+
private Pattern RenderBar (int w, int h)
{
ImageSurface s = new ImageSurface (Format.Argb32, w, h);
Context cr = new Context (s);
RenderBar (cr, w, h, h / 2);
// TODO Implement the new ctor - see http://bugzilla.gnome.org/show_bug.cgi?id=561394
-#pragma warning disable 0618
+#pragma warning disable 0618
Pattern pattern = new Pattern (s);
-#pragma warning restore 0618
+#pragma warning restore 0618
s.Destroy ();
((IDisposable)cr).Dispose ();
return pattern;
}
-
+
private void RenderBar (Context cr, int w, int h, int r)
{
RenderBarSegments (cr, w, h, r);
RenderBarStrokes (cr, w, h, r);
}
-
+
private void RenderBarSegments (Context cr, int w, int h, int r)
{
LinearGradient grad = new LinearGradient (0, 0, w, 0);
double last = 0.0;
-
+
foreach (Segment segment in segments) {
if (segment.Percent > 0) {
grad.AddColorStop (last, segment.Color);
grad.AddColorStop (last += segment.Percent, segment.Color);
}
}
-
- CairoExtensions.RoundedRectangle (cr, 0, 0, w, h, r);
+
+ CairoExtensions.RoundedRectangle (cr, 0, 0, w, h, r);
cr.Pattern = grad;
cr.FillPreserve ();
cr.Pattern.Destroy ();
-
+
grad = new LinearGradient (0, 0, 0, h);
grad.AddColorStop (0.0, new Color (1, 1, 1, 0.125));
grad.AddColorStop (0.35, new Color (1, 1, 1, 0.255));
grad.AddColorStop (1, new Color (0, 0, 0, 0.4));
-
+
cr.Pattern = grad;
cr.Fill ();
cr.Pattern.Destroy ();
}
-
+
private void RenderBarStrokes (Context cr, int w, int h, int r)
{
LinearGradient stroke = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0x00000040));
LinearGradient seg_sep_light = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0xffffff20));
LinearGradient seg_sep_dark = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0x00000020));
-
+
cr.LineWidth = 1;
-
+
double seg_w = 20;
double x = seg_w > r ? seg_w : r;
-
+
while (x <= w - r) {
cr.MoveTo (x - 0.5, 1);
cr.LineTo (x - 0.5, h - 1);
cr.Pattern = seg_sep_light;
cr.Stroke ();
-
+
cr.MoveTo (x + 0.5, 1);
cr.LineTo (x + 0.5, h - 1);
cr.Pattern = seg_sep_dark;
cr.Stroke ();
-
+
x += seg_w;
}
-
+
CairoExtensions.RoundedRectangle (cr, 0.5, 0.5, w - 1, h - 1, r);
cr.Pattern = stroke;
cr.Stroke ();
-
+
stroke.Destroy ();
seg_sep_light.Destroy ();
seg_sep_dark.Destroy ();
}
-
+
private LinearGradient MakeSegmentGradient (int h, Color color)
{
return MakeSegmentGradient (h, color, false);
}
-
+
private LinearGradient MakeSegmentGradient (int h, Color color, bool diag)
{
LinearGradient grad = new LinearGradient (0, 0, 0, h);
@@ -474,19 +474,19 @@ namespace Hyena.Widgets
grad.AddColorStop (1, CairoExtensions.ColorShade (color, 0.8));
return grad;
}
-
+
private void RenderLabels (Context cr)
{
if (segments.Count == 0) {
return;
}
-
+
Pango.Layout layout = null;
Color text_color = CairoExtensions.GdkColorToCairoColor (Style.Foreground (State));
Color box_stroke_color = new Color (0, 0, 0, 0.6);
-
+
int x = 0;
-
+
foreach (Segment segment in segments) {
cr.LineWidth = 1;
cr.Rectangle (x + 0.5, 2 + 0.5, segment_box_size - 1, segment_box_size - 1);
@@ -496,41 +496,41 @@ namespace Hyena.Widgets
cr.Color = box_stroke_color;
cr.Stroke ();
grad.Destroy ();
-
+
x += segment_box_size + segment_box_spacing;
-
+
int lw, lh;
layout = CreateAdaptLayout (layout, false, true);
layout.SetText (FormatSegmentText (segment));
layout.GetPixelSize (out lw, out lh);
-
+
cr.MoveTo (x, 0);
text_color.A = 0.9;
cr.Color = text_color;
PangoCairoHelper.ShowLayout (cr, layout);
cr.Fill ();
-
+
layout = CreateAdaptLayout (layout, true, false);
layout.SetText (FormatSegmentValue (segment));
-
+
cr.MoveTo (x, lh);
text_color.A = 0.75;
cr.Color = text_color;
PangoCairoHelper.ShowLayout (cr, layout);
cr.Fill ();
-
+
x += segment.LayoutWidth + segment_label_spacing;
}
-
+
layout.Dispose ();
}
-
+
#endregion
#region Utilities
-
+
private int pango_size_normal;
-
+
private Pango.Layout CreateAdaptLayout (Pango.Layout layout, bool small, bool bold)
{
if (layout == null) {
@@ -538,38 +538,38 @@ namespace Hyena.Widgets
layout = new Pango.Layout (context);
layout.FontDescription = context.FontDescription;
pango_size_normal = layout.FontDescription.Size;
- }
-
- layout.FontDescription.Size = small
+ }
+
+ layout.FontDescription.Size = small
? (int)(layout.FontDescription.Size * Pango.Scale.Small)
: pango_size_normal;
-
+
layout.FontDescription.Weight = bold
? Pango.Weight.Bold
: Pango.Weight.Normal;
-
+
return layout;
}
-
-
+
+
private string FormatSegmentText (Segment segment)
{
return segment.Title;
}
-
+
private string FormatSegmentValue (Segment segment)
{
return format_handler == null
? String.Format ("{0}%", segment.Percent * 100.0)
: format_handler (segment);
}
-
+
#endregion
}
-
-#region Test Module
-
+
+#region Test Module
+
[TestModule ("Segmented Bar")]
internal class SegmentedBarTestModule : Window
{
@@ -579,11 +579,11 @@ namespace Hyena.Widgets
{
BorderWidth = 10;
AppPaintable = true;
-
+
box = new VBox ();
box.Spacing = 10;
Add (box);
-
+
int space = 55;
bar = new SegmentedBar ();
bar.HorizontalPadding = bar.BarHeight / 2;
@@ -591,39 +591,39 @@ namespace Hyena.Widgets
bar.AddSegmentRgb ("Other", 0.0788718162651326, 0xf57900);
bar.AddSegmentRgb ("Video", 0.0516869922033282, 0x73d216);
bar.AddSegment ("Free Space", 0.867561266964516, bar.RemainderColor, false);
-
+
bar.ValueFormatter = delegate (SegmentedBar.Segment segment) {
return String.Format ("{0} GB", space * segment.Percent);
};
-
+
HBox controls = new HBox ();
controls.Spacing = 5;
-
+
Label label = new Label ("Height:");
controls.PackStart (label, false, false, 0);
-
+
SpinButton height = new SpinButton (new Adjustment (bar.BarHeight, 5, 100, 1, 1, 1), 1, 0);
height.Activated += delegate { bar.BarHeight = height.ValueAsInt; };
height.Changed += delegate { bar.BarHeight = height.ValueAsInt; bar.HorizontalPadding = bar.BarHeight / 2; };
controls.PackStart (height, false, false, 0);
-
+
CheckButton reflect = new CheckButton ("Reflection");
reflect.Active = bar.ShowReflection;
reflect.Toggled += delegate { bar.ShowReflection = reflect.Active; };
controls.PackStart (reflect, false, false, 0);
-
+
CheckButton labels = new CheckButton ("Labels");
labels.Active = bar.ShowLabels;
labels.Toggled += delegate { bar.ShowLabels = labels.Active; };
controls.PackStart (labels, false, false, 0);
-
+
box.PackStart (controls, false, false, 0);
box.PackStart (new HSeparator (), false, false, 0);
box.PackStart (bar, false, false, 0);
box.ShowAll ();
-
+
SetSizeRequest (350, -1);
-
+
Gdk.Geometry limits = new Gdk.Geometry ();
limits.MinWidth = SizeRequest ().Width;
limits.MaxWidth = Gdk.Screen.Default.Width;
@@ -632,7 +632,7 @@ namespace Hyena.Widgets
SetGeometryHints (this, limits, Gdk.WindowHints.MaxSize | Gdk.WindowHints.MinSize);
}
}
-
+
#endregion
-
+
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/SmoothScrolledWindow.cs b/src/Hyena.Gui/Hyena.Widgets/SmoothScrolledWindow.cs
index 97073af..9b0ed79 100644
--- a/src/Hyena.Gui/Hyena.Widgets/SmoothScrolledWindow.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/SmoothScrolledWindow.cs
@@ -36,41 +36,41 @@ namespace Hyena.Widgets
private double value;
private double target_value;
private double velocity = 0;
-
+
private double Accelerate (double velocity)
{
return AccelerateCore (velocity);
}
-
+
private double Decelerate (double velocity)
{
return Math.Max (DecelerateCore (velocity), 0);
}
-
+
protected virtual double AccelerateCore (double velocity)
{
return velocity + 8;
}
-
+
protected virtual double DecelerateCore (double velocity)
{
return velocity - Math.Max (3, 0.2 * velocity);
}
-
+
private double TargetValue {
get { return target_value; }
set {
if (value == target_value) {
return;
}
-
+
target_value = value;
if (timeout == 0) {
timeout = GLib.Timeout.Add (20, OnTimeout);
}
}
}
-
+
// Smoothly get us to the target value
private bool OnTimeout ()
{
@@ -80,17 +80,17 @@ namespace Hyena.Widgets
timeout = 0;
return false;
}
-
+
int sign = Math.Sign (delta);
delta = Math.Abs (delta);
-
+
double hypothetical = delta;
double v = Accelerate (velocity);
while (v > 0 && hypothetical > 0) {
hypothetical -= v;
v = Decelerate (v);
}
-
+
velocity = hypothetical <= 0 ? Decelerate (velocity) : Accelerate (velocity);
// Minimum speed: 2 px / 20 ms = 100px / second
@@ -102,10 +102,10 @@ namespace Hyena.Widgets
ignore_value_changed = true;
Vadjustment.Value = Math.Round (value);
ignore_value_changed = false;
-
+
return true;
}
-
+
protected override bool OnScrollEvent (Gdk.EventScroll evnt)
{
switch (evnt.Direction) {
@@ -120,19 +120,19 @@ namespace Hyena.Widgets
}
return true;
}
-
+
protected override void OnRealized ()
{
base.OnRealized ();
Vadjustment.ValueChanged += OnValueChanged;
}
-
+
protected override void OnUnrealized ()
{
Vadjustment.ValueChanged -= OnValueChanged;
base.OnUnrealized ();
}
-
+
private void OnValueChanged (object o, EventArgs args)
{
if (!ignore_value_changed) {
diff --git a/src/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs b/src/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs
index fa224ef..5b25c80 100644
--- a/src/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs
@@ -32,18 +32,18 @@ using Gtk;
namespace Hyena.Widgets
{
public class TextViewEditable : TextView, Editable
- {
+ {
public TextViewEditable ()
{
Buffer.Changed += OnBufferChanged;
Buffer.InsertText += OnBufferInsertText;
Buffer.DeleteRange += OnBufferDeleteRange;
}
-
+
public event EventHandler Changed;
public event TextDeletedHandler TextDeleted;
public event TextInsertedHandler TextInserted;
-
+
private void OnBufferChanged (object o, EventArgs args)
{
EventHandler handler = Changed;
@@ -51,13 +51,13 @@ namespace Hyena.Widgets
handler (this, EventArgs.Empty);
}
}
-
+
private void OnBufferInsertText (object o, InsertTextArgs args)
{
TextInsertedHandler handler = TextInserted;
if (handler != null) {
TextInsertedArgs raise_args = new TextInsertedArgs ();
- raise_args.Args = new object [] {
+ raise_args.Args = new object [] {
args.Text,
args.Length,
args.Pos.Offset
@@ -65,79 +65,79 @@ namespace Hyena.Widgets
handler (this, raise_args);
}
}
-
+
private void OnBufferDeleteRange (object o, DeleteRangeArgs args)
{
TextDeletedHandler handler = TextDeleted;
if (handler != null) {
TextDeletedArgs raise_args = new TextDeletedArgs ();
- raise_args.Args = new object [] {
+ raise_args.Args = new object [] {
args.Start.Offset,
args.End.Offset
};
handler (this, raise_args);
}
}
-
+
void Editable.PasteClipboard ()
{
}
-
+
void Editable.CutClipboard ()
{
}
-
+
void Editable.CopyClipboard ()
{
}
-
+
public void DeleteText (int start_pos, int end_pos)
{
start_pos--;
end_pos--;
-
+
TextIter start_iter = Buffer.GetIterAtOffset (start_pos);
TextIter end_iter = Buffer.GetIterAtOffset (start_pos + (end_pos - start_pos));
Buffer.Delete (ref start_iter, ref end_iter);
}
-
+
public void InsertText (string new_text, ref int position)
{
TextIter iter = Buffer.GetIterAtOffset (position - 1);
Buffer.Insert (ref iter, new_text);
position = iter.Offset + 1;
}
-
+
public string GetChars (int start_pos, int end_pos)
{
start_pos--;
end_pos--;
-
+
TextIter start_iter = Buffer.GetIterAtOffset (start_pos);
TextIter end_iter = Buffer.GetIterAtOffset (start_pos + (end_pos - start_pos));
return Buffer.GetText (start_iter, end_iter, true);
}
-
+
public void SelectRegion (int start, int end)
{
Buffer.SelectRange (Buffer.GetIterAtOffset (start - 1), Buffer.GetIterAtOffset (end - 1));
}
-
+
public bool GetSelectionBounds (out int start, out int end)
{
TextIter start_iter, end_iter;
start = 0;
end = 0;
-
+
if (Buffer.GetSelectionBounds (out start_iter, out end_iter)) {
start = start_iter.Offset + 1;
end = end_iter.Offset + 1;
return true;
}
-
+
return true;
}
-
+
public void DeleteSelection ()
{
TextIter start, end;
@@ -145,13 +145,13 @@ namespace Hyena.Widgets
Buffer.Delete (ref start, ref end);
}
}
-
- public int Position {
+
+ public int Position {
get { return Buffer.CursorPosition; }
set { Buffer.PlaceCursor (Buffer.GetIterAtOffset (Position)); }
}
-
- public bool IsEditable {
+
+ public bool IsEditable {
get { return Editable; }
set { Editable = value; }
}
diff --git a/src/Hyena.Gui/Hyena.Widgets/WrapLabel.cs b/src/Hyena.Gui/Hyena.Widgets/WrapLabel.cs
index 582a208..b0a04e7 100644
--- a/src/Hyena.Gui/Hyena.Widgets/WrapLabel.cs
+++ b/src/Hyena.Gui/Hyena.Widgets/WrapLabel.cs
@@ -37,94 +37,94 @@ namespace Hyena.Widgets
private bool use_markup = false;
private bool wrap = true;
private Pango.Layout layout;
-
+
public WrapLabel ()
{
WidgetFlags |= WidgetFlags.NoWindow;
}
-
+
private void CreateLayout ()
{
if (layout != null) {
layout.Dispose ();
}
-
+
layout = new Pango.Layout (PangoContext);
layout.Wrap = Pango.WrapMode.Word;
}
-
+
private void UpdateLayout ()
{
if (layout == null) {
CreateLayout ();
}
-
+
layout.Ellipsize = wrap ? Pango.EllipsizeMode.None : Pango.EllipsizeMode.End;
if (text == null) {
text = "";
}
-
+
if (use_markup) {
layout.SetMarkup (text);
} else {
layout.SetText (text);
}
-
+
QueueResize ();
}
-
+
protected override void OnStyleSet (Style previous_style)
{
CreateLayout ();
UpdateLayout ();
base.OnStyleSet (previous_style);
}
-
+
protected override void OnRealized ()
{
GdkWindow = Parent.GdkWindow;
base.OnRealized ();
}
-
+
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
int lw, lh;
-
+
layout.Width = (int)(allocation.Width * Pango.Scale.PangoScale);
layout.GetPixelSize (out lw, out lh);
-
+
HeightRequest = lh;
-
+
base.OnSizeAllocated (allocation);
}
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
{
if (evnt.Window == GdkWindow) {
- Gtk.Style.PaintLayout (Style, GdkWindow, State, false,
+ Gtk.Style.PaintLayout (Style, GdkWindow, State, false,
evnt.Area, this, null, Allocation.X, Allocation.Y, layout);
}
return true;
}
-
+
public void MarkupFormat (string format, params object [] args)
{
if (args == null || args.Length == 0) {
Markup = format;
return;
}
-
+
for (int i = 0; i < args.Length; i++) {
if (args[i] is string) {
args[i] = GLib.Markup.EscapeText ((string)args[i]);
}
}
-
+
Markup = String.Format (format, args);
}
-
+
public bool Wrap {
get { return wrap; }
set {
@@ -132,7 +132,7 @@ namespace Hyena.Widgets
UpdateLayout ();
}
}
-
+
public string Markup {
get { return text; }
set {
@@ -141,7 +141,7 @@ namespace Hyena.Widgets
UpdateLayout ();
}
}
-
+
public string Text {
get { return text; }
set {
@@ -149,6 +149,6 @@ namespace Hyena.Widgets
text = value;
UpdateLayout ();
}
- }
+ }
}
}
diff --git a/src/Hyena/Hyena.Collections/CollectionExtensions.cs b/src/Hyena/Hyena.Collections/CollectionExtensions.cs
index a42435c..99ed0a1 100644
--- a/src/Hyena/Hyena.Collections/CollectionExtensions.cs
+++ b/src/Hyena/Hyena.Collections/CollectionExtensions.cs
@@ -31,7 +31,7 @@ using System.Text;
using System.Collections.Generic;
namespace Hyena.Collections
-{
+{
public static class CollectionExtensions
{
public static void SortedInsert<T> (List<T> list, T value) where T : IComparable
@@ -45,42 +45,42 @@ namespace Hyena.Collections
list.Insert (index < 0 ? ~index : index, value);
}
}
-
+
public static string Join<T> (IList<T> list)
{
return Join<T> (list, ", ");
}
-
+
public static string Join<T> (IList<T> list, string separator)
{
return Join<T> (list, null, null, separator);
}
-
+
public static string Join<T> (IList<T> list, string wrapper, string separator)
{
return Join<T> (list, wrapper, wrapper, separator);
}
-
+
public static string Join<T> (IList<T> list, string front, string back, string separator)
{
StringBuilder builder = new StringBuilder ();
-
+
for (int i = 0, n = list.Count; i < n; i++) {
if (front != null) {
builder.Append (front);
}
-
+
builder.Append (list[i]);
-
+
if (back != null) {
builder.Append (back);
}
-
+
if (i < n - 1) {
builder.Append (separator);
}
}
-
+
return builder.ToString ();
}
}
diff --git a/src/Hyena/Hyena.Collections/IntervalHeap.cs b/src/Hyena/Hyena.Collections/IntervalHeap.cs
index 641ae98..2db698c 100644
--- a/src/Hyena/Hyena.Collections/IntervalHeap.cs
+++ b/src/Hyena/Hyena.Collections/IntervalHeap.cs
@@ -35,36 +35,36 @@ namespace Hyena.Collections
public class IntervalHeap<T> : ICollection<T>, ICollection
{
private const int MIN_CAPACITY = 16;
-
+
private int count;
private int generation;
-
+
private Interval [] heap;
-
+
public IntervalHeap ()
{
Clear ();
}
-
+
public virtual T Pop ()
{
if (count == 0) {
throw new InvalidOperationException ();
}
-
+
T item = heap[0].Item;
MoveDown (0, heap[--count]);
generation++;
-
+
return item;
}
-
+
public virtual T Peek ()
{
if (count == 0) {
throw new InvalidOperationException ();
}
-
+
return heap[0].Item;
}
@@ -73,22 +73,22 @@ namespace Hyena.Collections
if (item == null) {
throw new ArgumentNullException ("item");
}
-
+
if (count == heap.Length) {
OptimalArrayResize (ref heap, 1);
}
-
+
MoveUp (++count - 1, new Interval (item, priority));
generation++;
}
-
+
public virtual void Clear ()
{
generation = 0;
count = 0;
heap = new Interval[MIN_CAPACITY];
}
-
+
void ICollection.CopyTo (Array array, int index)
{
if (array == null) {
@@ -101,7 +101,7 @@ namespace Hyena.Collections
Array.Copy (heap, 0, array, index, count);
}
-
+
public virtual void CopyTo (T [] array, int index)
{
if (array == null) {
@@ -120,63 +120,63 @@ namespace Hyena.Collections
if (item == null) {
throw new ArgumentNullException ("item");
}
-
+
return FindItemHeapIndex (item) >= 0;
}
-
+
public virtual void Add (T item)
{
if (item == null) {
throw new ArgumentNullException ("item");
}
-
+
Push (item, 0);
}
-
+
public virtual bool Remove (T item)
{
if (item == null) {
throw new ArgumentNullException ("item");
}
-
+
int index = FindItemHeapIndex (item);
-
+
if (index < 0) {
return false;
}
-
+
MoveDown (index, heap[--count]);
generation++;
-
+
return true;
}
-
+
public virtual void TrimExcess ()
{
if (count < heap.Length * 0.9) {
Array.Resize (ref heap, count);
}
}
-
+
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
-
+
public virtual IEnumerator<T> GetEnumerator ()
{
return new IntervalHeapEnumerator (this);
}
-
+
public static IntervalHeap<T> Synchronized (IntervalHeap<T> heap)
{
if (heap == null) {
throw new ArgumentNullException ("heap");
}
-
+
return new SyncIntervalHeap (heap);
}
-
+
private int FindItemHeapIndex (T item)
{
for (int i = 0; i < count; i++) {
@@ -184,22 +184,22 @@ namespace Hyena.Collections
return i;
}
}
-
+
return -1;
}
-
+
private int GetLeftChildIndex (int index)
{
return index * 2 + 1;
}
-
+
private int GetParentIndex (int index)
{
return (index - 1) / 2;
}
-
+
private static void OptimalArrayResize (ref Interval [] array, int grow)
- {
+ {
int new_capacity = array.Length == 0 ? 1 : array.Length;
int min_capacity = array.Length == 0 ? MIN_CAPACITY : array.Length + grow;
@@ -213,193 +213,192 @@ namespace Hyena.Collections
private void MoveUp (int index, Interval node)
{
int parent_index = GetParentIndex (index);
-
+
while (index > 0 && heap[parent_index].Priority < node.Priority) {
heap[index] = heap[parent_index];
index = parent_index;
parent_index = GetParentIndex (index);
}
-
+
heap[index] = node;
}
-
+
private void MoveDown (int index, Interval node)
{
int child_index = GetLeftChildIndex (index);
-
+
while (child_index < count) {
- if (child_index + 1 < count
+ if (child_index + 1 < count
&& heap[child_index].Priority < heap[child_index + 1].Priority) {
child_index++;
}
-
+
heap[index] = heap[child_index];
index = child_index;
child_index = GetLeftChildIndex (index);
}
-
+
MoveUp (index, node);
}
public virtual int Count {
get { return count; }
}
-
+
public bool IsReadOnly {
get { return false; }
}
-
+
public virtual object SyncRoot {
get { return this; }
}
-
+
public virtual bool IsSynchronized {
get { return false; }
}
-
+
private struct Interval
{
private T item;
private int priority;
-
+
public Interval (T item, int priority)
{
this.item = item;
this.priority = priority;
}
-
+
public T Item {
get { return item; }
}
-
- public int Priority {
+
+ public int Priority {
get { return priority; }
}
}
-
+
private class SyncIntervalHeap : IntervalHeap<T>
{
private IntervalHeap<T> heap;
-
+
internal SyncIntervalHeap (IntervalHeap<T> heap)
{
this.heap = heap;
}
-
+
public override int Count {
get { lock (heap) { return heap.Count; } }
}
-
+
public override bool IsSynchronized {
get { return true; }
}
-
+
public override object SyncRoot {
get { return heap.SyncRoot; }
}
-
+
public override void Clear ()
{
lock (heap) { heap.Clear (); }
}
-
+
public override bool Contains(T item)
{
lock (heap) { return heap.Contains (item); }
}
-
+
public override T Pop()
{
lock (heap) { return heap.Pop (); }
}
-
+
public override T Peek ()
{
lock (heap) { return heap.Peek (); }
}
-
+
public override void Push (T item, int priority)
{
lock (heap) { heap.Push (item, priority); }
}
-
+
public override void Add (T item)
{
lock (heap) { heap.Add (item); }
}
-
+
public override bool Remove (T item)
{
lock (heap) { return heap.Remove (item); }
}
-
+
public override void TrimExcess ()
{
lock (heap) { heap.TrimExcess (); }
}
-
+
public override void CopyTo (T [] array, int index)
{
lock (heap) { heap.CopyTo (array, index); }
}
-
+
public override IEnumerator<T> GetEnumerator ()
{
lock (heap) { return new IntervalHeapEnumerator (this); }
}
}
-
+
private class IntervalHeapEnumerator : IEnumerator<T>, IEnumerator
{
private IntervalHeap<T> heap;
private int index;
private int generation;
-
+
public IntervalHeapEnumerator (IntervalHeap<T> heap)
{
this.heap = heap;
Reset ();
}
-
+
public void Reset ()
{
generation = heap.generation;
index = -1;
}
-
+
public void Dispose ()
{
heap = null;
}
-
+
public bool MoveNext ()
{
if (generation != heap.generation) {
throw new InvalidOperationException ();
}
-
+
if (index + 1 == heap.count) {
return false;
}
-
+
index++;
return true;
}
-
+
object IEnumerator.Current {
get { return Current; }
}
-
+
public T Current {
get {
if (generation != heap.generation) {
throw new InvalidOperationException ();
}
-
+
return heap.heap[index].Item;
}
}
}
}
}
-
\ No newline at end of file
diff --git a/src/Hyena/Hyena.Collections/LruCache.cs b/src/Hyena/Hyena.Collections/LruCache.cs
index b644bea..ef80b23 100644
--- a/src/Hyena/Hyena.Collections/LruCache.cs
+++ b/src/Hyena/Hyena.Collections/LruCache.cs
@@ -39,13 +39,13 @@ namespace Hyena.Collections
get { return key; }
set { key = value; }
}
-
+
private TValue value;
public TValue Value {
get { return this.value; }
set { this.value = value; }
}
-
+
internal DateTime LastUsed;
internal int UsedCount;
}
@@ -61,7 +61,7 @@ namespace Hyena.Collections
public LruCache () : this (1024)
{
}
-
+
public LruCache (int maxCount) : this (maxCount, null)
{
}
@@ -82,7 +82,7 @@ namespace Hyena.Collections
cache[key] = entry;
return;
}
-
+
entry.Key = key;
entry.Value = value;
Ref (ref entry);
@@ -90,7 +90,7 @@ namespace Hyena.Collections
misses++;
EnsureMinimumHitRatio ();
-
+
if (Count >= max_count) {
TKey expire = FindOldestEntry ();
ExpireItem (cache[expire].Value);
@@ -98,7 +98,7 @@ namespace Hyena.Collections
}
}
}
-
+
public bool Contains (TKey key)
{
lock (cache) {
@@ -115,7 +115,7 @@ namespace Hyena.Collections
}
}
}
-
+
public bool TryGetValue (TKey key, out TValue value)
{
lock (cache) {
@@ -127,7 +127,7 @@ namespace Hyena.Collections
hits++;
return true;
}
-
+
misses++;
EnsureMinimumHitRatio ();
value = default (TValue);
@@ -141,18 +141,18 @@ namespace Hyena.Collections
MaxCount = Count + 1;
}
}
-
+
private void Ref (ref CacheEntry<TKey, TValue> entry)
{
entry.LastUsed = DateTime.Now;
entry.UsedCount++;
}
-
+
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
-
+
public IEnumerator<CacheEntry<TKey, TValue>> GetEnumerator ()
{
lock (cache) {
@@ -161,12 +161,12 @@ namespace Hyena.Collections
}
}
}
-
+
// Ok, this blows. I have no time to implement anything clever or proper here.
// Using a hashtable generally sucks for this, but it's not bad for a 15 minute
// hack. max_count will be sufficiently small in our case that this can't be
// felt anyway. Meh.
-
+
private TKey FindOldestEntry ()
{
lock (cache) {
@@ -181,16 +181,16 @@ namespace Hyena.Collections
return oldest_key;
}
}
-
+
protected virtual void ExpireItem (TValue item)
{
}
-
+
public int MaxCount {
get { lock (cache) { return max_count; } }
set { lock (cache) { max_count = value; } }
}
-
+
public int Count {
get { lock (cache) { return cache.Count; } }
}
diff --git a/src/Hyena/Hyena.Collections/QueuePipeline.cs b/src/Hyena/Hyena.Collections/QueuePipeline.cs
index 541e893..6c869a3 100644
--- a/src/Hyena/Hyena.Collections/QueuePipeline.cs
+++ b/src/Hyena/Hyena.Collections/QueuePipeline.cs
@@ -38,16 +38,16 @@ namespace Hyena.Collections
#pragma warning restore 0067
private object sync = new object ();
-
+
private QueuePipelineElement<T> first_element;
internal QueuePipelineElement<T> FirstElement {
get { return first_element; }
}
-
+
public QueuePipeline ()
{
}
-
+
public void AddElement (QueuePipelineElement<T> element)
{
element.Finished += OnElementFinished;
@@ -56,7 +56,7 @@ namespace Hyena.Collections
first_element = element;
return;
}
-
+
QueuePipelineElement<T> current = first_element;
while (current != null) {
@@ -64,21 +64,21 @@ namespace Hyena.Collections
current.NextElement = element;
break;
}
-
+
current = current.NextElement;
}
}
}
-
+
public virtual void Enqueue (T item)
{
if (first_element == null) {
throw new InvalidOperationException ("There are no elements in this pipeline");
}
-
+
first_element.Enqueue (item);
}
-
+
public virtual void Cancel ()
{
if (first_element != null) {
diff --git a/src/Hyena/Hyena.Collections/QueuePipelineElement.cs b/src/Hyena/Hyena.Collections/QueuePipelineElement.cs
index dc95885..a088d6c 100644
--- a/src/Hyena/Hyena.Collections/QueuePipelineElement.cs
+++ b/src/Hyena/Hyena.Collections/QueuePipelineElement.cs
@@ -55,14 +55,14 @@ namespace Hyena.Collections
public int ProcessedCount {
get { return processed_count; }
}
-
+
private int total_count;
public int TotalCount {
get { return total_count; }
}
-
+
protected abstract T ProcessItem (T item);
-
+
protected virtual void OnFinished ()
{
lock (this) {
@@ -73,7 +73,7 @@ namespace Hyena.Collections
total_count = 0;
processed_count = 0;
}
-
+
EventHandler handler = Finished;
if (handler != null) {
handler (this, EventArgs.Empty);
@@ -87,7 +87,7 @@ namespace Hyena.Collections
handler (this, EventArgs.Empty);
}
}
-
+
protected virtual void OnCanceled ()
{
lock (queue) {
@@ -96,24 +96,24 @@ namespace Hyena.Collections
processed_count = 0;
}
}
-
+
public virtual void Enqueue (T item)
{
- lock (this) {
+ lock (this) {
lock (queue) {
queue.Enqueue (item);
total_count++;
}
-
+
if (!threaded) {
Processor (null);
return;
}
-
+
if (thread_wait == null) {
thread_wait = new AutoResetEvent (false);
}
-
+
if (Monitor.TryEnter (monitor)) {
Monitor.Exit (monitor);
ThreadPool.QueueUserWorkItem (Processor);
@@ -121,35 +121,35 @@ namespace Hyena.Collections
}
}
}
-
+
protected virtual void EnqueueDownstream (T item)
{
if (NextElement != null && item != null) {
NextElement.Enqueue (item);
}
}
-
+
private void Processor (object state)
{
lock (monitor) {
if (threaded) {
thread_wait.Set ();
}
-
+
lock (this) {
processing = true;
}
-
+
try {
while (queue.Count > 0) {
CheckForCanceled ();
-
+
T item = null;
lock (queue) {
item = queue.Dequeue ();
processed_count++;
}
-
+
EnqueueDownstream (ProcessItem (item));
OnProcessedItem ();
}
@@ -165,11 +165,11 @@ namespace Hyena.Collections
thread_wait.Close ();
thread_wait = null;
}
-
+
OnFinished ();
}
}
-
+
protected virtual void CheckForCanceled ()
{
lock (this) {
@@ -178,39 +178,39 @@ namespace Hyena.Collections
}
}
}
-
+
public void Cancel ()
{
lock (this) {
if (processing) {
canceled = true;
}
-
+
if (NextElement != null) {
NextElement.Cancel ();
}
}
}
-
+
public bool Processing {
get { lock (this) { return processing; } }
}
-
+
public bool Threaded {
get { return threaded; }
- set {
+ set {
if (processing) {
throw new InvalidOperationException ("Cannot change threading model while the element is processing");
}
-
- threaded = value;
+
+ threaded = value;
}
}
-
+
protected Queue<T> Queue {
get { return queue; }
}
-
+
private QueuePipelineElement<T> next_element;
internal QueuePipelineElement<T> NextElement {
get { return next_element; }
diff --git a/src/Hyena/Hyena.Collections/RangeCollection.cs b/src/Hyena/Hyena.Collections/RangeCollection.cs
index 4c4fd63..7973e18 100644
--- a/src/Hyena/Hyena.Collections/RangeCollection.cs
+++ b/src/Hyena/Hyena.Collections/RangeCollection.cs
@@ -42,11 +42,11 @@ namespace Hyena.Collections
#if NET_1_1
internal
#else
- public
+ public
#endif
class RangeCollection :
- ICloneable,
+ ICloneable,
#if NET_2_0
ICollection<int>
#else
@@ -57,7 +57,7 @@ namespace Hyena.Collections
{
private int start;
private int end;
-
+
public Range (int start, int end)
{
this.start = start;
@@ -73,12 +73,12 @@ namespace Hyena.Collections
get { return start; }
set { start = value; }
}
-
+
public int End {
get { return end; }
set { end = value; }
}
-
+
public int Count {
get { return End - Start + 1; }
}
@@ -104,23 +104,23 @@ namespace Hyena.Collections
if (delta < 0) {
start -= delta;
}
-
+
if (start < range_count) {
Array.Copy (ranges, start, ranges, start + delta, range_count - start);
}
-
+
range_count += delta;
}
private void EnsureCapacity (int growBy)
- {
+ {
int new_capacity = ranges.Length == 0 ? 1 : ranges.Length;
int min_capacity = ranges.Length == 0 ? MIN_CAPACITY : ranges.Length + growBy;
while (new_capacity < min_capacity) {
new_capacity <<= 1;
}
-
+
#if NET_2_0
Array.Resize (ref ranges, new_capacity);
#else
@@ -129,34 +129,34 @@ namespace Hyena.Collections
ranges = new_ranges;
#endif
}
-
+
private void Insert (int position, Range range)
{
if (range_count == ranges.Length) {
EnsureCapacity (1);
}
-
+
Shift (position, 1);
ranges[position] = range;
}
-
+
private void RemoveAt (int position)
{
Shift (position, -1);
Array.Clear (ranges, range_count, 1);
}
-
+
#endregion
#region Private Range Logic
-
+
private bool RemoveIndexFromRange (int index)
{
int range_index = FindRangeIndexForValue (index);
if (range_index < 0) {
return false;
}
-
+
Range range = ranges[range_index];
if (range.Start == index && range.End == index) {
RemoveAt (range_index);
@@ -169,7 +169,7 @@ namespace Hyena.Collections
ranges[range_index].End = index - 1;
Insert (range_index + 1, split_range);
}
-
+
index_count--;
return true;
}
@@ -177,7 +177,7 @@ namespace Hyena.Collections
private void InsertRange (Range range)
{
int position = FindInsertionPosition (range);
- bool merged_left = MergeLeft (range, position);
+ bool merged_left = MergeLeft (range, position);
bool merged_right = MergeRight (range, position);
if (!merged_left && !merged_right) {
@@ -208,7 +208,7 @@ namespace Hyena.Collections
return false;
}
-
+
private static int CompareRanges (Range a, Range b)
{
return (a.Start + (a.End - a.Start)).CompareTo (b.Start + (b.End - b.Start));
@@ -218,29 +218,29 @@ namespace Hyena.Collections
{
int min = 0;
int max = range_count - 1;
-
+
while (min <= max) {
int mid = min + ((max - min) / 2);
int cmp = CompareRanges (ranges[mid], range);
-
+
if (cmp == 0) {
return mid;
} else if (cmp > 0) {
if (mid > 0 && CompareRanges (ranges[mid - 1], range) < 0) {
return mid;
}
-
+
max = mid - 1;
} else {
min = mid + 1;
}
}
-
+
return min;
}
-
+
public int FindRangeIndexForValue (int value)
- {
+ {
int min = 0;
int max = range_count - 1;
@@ -258,8 +258,8 @@ namespace Hyena.Collections
return ~min;
}
-
-#endregion
+
+#endregion
#region Public RangeCollection API
@@ -270,45 +270,45 @@ namespace Hyena.Collections
return ranges_copy;
}
}
-
+
public int RangeCount {
get { return range_count; }
}
-
+
#if NET_2_0
[Obsolete ("Do not use the Indexes property in 2.0 profiles if enumerating only; Indexes allocates an array to avoid boxing in the 1.1 profile")]
#endif
public int [] Indexes {
- get {
+ get {
if (indexes_cache != null && generation == indexes_cache_generation) {
return indexes_cache;
}
-
+
indexes_cache = new int[Count];
indexes_cache_generation = generation;
-
+
for (int i = 0, j = 0; i < range_count; i++) {
for (int k = ranges[i].Start; k <= ranges[i].End; j++, k++) {
indexes_cache[j] = k;
}
}
-
+
return indexes_cache;
}
}
-
+
public int IndexOf (int value)
{
int offset = 0;
-
+
foreach (Range range in ranges) {
if (value >= range.Start && value <= range.End) {
return offset + (value - range.Start);
}
-
+
offset += range.End - range.Start + 1;
}
-
+
return -1;
}
@@ -319,7 +319,7 @@ namespace Hyena.Collections
return ranges[i].End - (cuml_count - index) + 1;
}
}
-
+
throw new IndexOutOfRangeException (index.ToString ());
}
}
@@ -336,10 +336,10 @@ namespace Hyena.Collections
index_count++;
return true;
}
-
+
return false;
}
-
+
void
#if NET_2_0
ICollection<int>.
@@ -350,63 +350,63 @@ namespace Hyena.Collections
{
Add (value);
}
-
+
public bool Remove (int value)
{
generation++;
return RemoveIndexFromRange (value);
}
-
+
public void Clear ()
{
range_count = 0;
index_count = 0;
generation++;
- ranges = new Range[MIN_CAPACITY];
+ ranges = new Range[MIN_CAPACITY];
}
-
+
public bool Contains (int value)
{
return FindRangeIndexForValue (value) >= 0;
}
-
+
public void CopyTo (int [] array, int index)
{
throw new NotImplementedException ();
}
-
+
public void CopyTo (Array array, int index)
{
throw new NotImplementedException ();
}
-
+
public int Count {
get { return index_count; }
}
-
+
public bool IsReadOnly {
get { return false; }
}
-#if !NET_2_0
+#if !NET_2_0
public bool IsSynchronized {
get { return false; }
}
-
+
public object SyncRoot {
get { return this; }
}
#endif
#endregion
-
+
#region ICloneable Implementation
public object Clone ()
{
return MemberwiseClone ();
}
-
+
#endregion
#region IEnumerable Implementation
@@ -420,7 +420,7 @@ namespace Hyena.Collections
}
}
}
-
+
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
diff --git a/src/Hyena/Hyena.Collections/Selection.cs b/src/Hyena/Hyena.Collections/Selection.cs
index 1d61e2f..d0e671d 100644
--- a/src/Hyena/Hyena.Collections/Selection.cs
+++ b/src/Hyena/Hyena.Collections/Selection.cs
@@ -39,9 +39,9 @@ namespace Hyena.Collections
#if NET_1_1
internal
#else
- public
+ public
#endif
-
+
class Selection :
#if NET_2_0
IEnumerable<int>
@@ -53,13 +53,13 @@ namespace Hyena.Collections
private int max_index;
private int first_selected_index;
private int focused_index = -1;
-
+
public event EventHandler Changed;
-
+
public Selection ()
{
}
-
+
public int FocusedIndex {
get { return focused_index; }
set { focused_index = value; }
@@ -72,16 +72,16 @@ namespace Hyena.Collections
handler (this, EventArgs.Empty);
}
}
-
+
public void ToggleSelect (int index)
{
if (!ranges.Remove (index)) {
ranges.Add (index);
}
-
+
OnChanged ();
}
-
+
public void Select (int index)
{
ranges.Add (index);
@@ -96,7 +96,7 @@ namespace Hyena.Collections
if (Count == 1)
first_selected_index = index;
}
-
+
public void Unselect (int index)
{
if (ranges.Remove (index))
@@ -107,7 +107,7 @@ namespace Hyena.Collections
{
ranges.Remove (index);
}
-
+
public bool Contains(int index)
{
return ranges.Contains (index);
@@ -125,7 +125,7 @@ namespace Hyena.Collections
else
Select (end);
}
-
+
public void SelectRange (int a, int b)
{
int start = Math.Min (a, b);
@@ -138,7 +138,7 @@ namespace Hyena.Collections
if (Count == i)
first_selected_index = a;
-
+
OnChanged ();
}
@@ -147,38 +147,38 @@ namespace Hyena.Collections
SelectRange (0, max_index);
}
- public void Clear ()
+ public void Clear ()
{
Clear (true);
}
-
+
public void Clear (bool raise)
{
if (ranges.Count <= 0) {
return;
}
-
+
ranges.Clear ();
if (raise)
OnChanged ();
}
-
+
public int Count {
get { return ranges.Count; }
}
-
+
public int MaxIndex {
set { max_index = value; }
get { return max_index; }
}
-
+
public virtual bool AllSelected {
- get {
+ get {
if (ranges.RangeCount == 1) {
RangeCollection.Range range = ranges.Ranges[0];
return range.Start == 0 && range.End == max_index;
}
-
+
return false;
}
}
@@ -190,21 +190,21 @@ namespace Hyena.Collections
public RangeCollection.Range [] Ranges {
get { return ranges.Ranges; }
}
-
+
public int FirstIndex {
get { return Count > 0 ? ranges[0] : -1; }
}
-
+
public int LastIndex {
get { return Count > 0 ? ranges[Count - 1]: -1; }
}
-
+
#if NET_2_0
public IEnumerator<int> GetEnumerator ()
{
return ranges.GetEnumerator ();
}
-
+
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
diff --git a/src/Hyena/Hyena.Collections/Tests/IntervalHeapTests.cs b/src/Hyena/Hyena.Collections/Tests/IntervalHeapTests.cs
index 01fa7db..4fdf49e 100644
--- a/src/Hyena/Hyena.Collections/Tests/IntervalHeapTests.cs
+++ b/src/Hyena/Hyena.Collections/Tests/IntervalHeapTests.cs
@@ -40,7 +40,7 @@ namespace Hyena.Collections.Tests
{
private IntervalHeap<int> heap;
private static int [] heap_data = new int[2048];
-
+
[TestFixtureSetUp]
public void Init()
{
@@ -53,11 +53,11 @@ namespace Hyena.Collections.Tests
private void PopulateHeap()
{
heap.Clear();
-
+
foreach(int i in heap_data) {
heap.Push(i, 0);
}
-
+
Assert.AreEqual(heap.Count, heap_data.Length);
}
@@ -65,7 +65,7 @@ namespace Hyena.Collections.Tests
public void PopHeap()
{
PopulateHeap();
-
+
int i = 0;
while(heap.Count > 0) {
heap.Pop();
@@ -118,7 +118,7 @@ namespace Hyena.Collections.Tests
Assert.AreEqual(h.Pop(), 3);
Assert.AreEqual(h.Pop(), 1);
- Assert.AreEqual(h.Count, 0);
+ Assert.AreEqual(h.Count, 0);
}
}
}
diff --git a/src/Hyena/Hyena.Collections/Tests/QueuePipelineTests.cs b/src/Hyena/Hyena.Collections/Tests/QueuePipelineTests.cs
index 35237df..1b96058 100644
--- a/src/Hyena/Hyena.Collections/Tests/QueuePipelineTests.cs
+++ b/src/Hyena/Hyena.Collections/Tests/QueuePipelineTests.cs
@@ -47,7 +47,7 @@ namespace Hyena.Collections.Tests
return null;
}
}
-
+
[Test]
public void BuildPipeline ()
{
@@ -57,21 +57,21 @@ namespace Hyena.Collections.Tests
BuildPipeline (10);
BuildPipeline (1000);
}
-
+
private void BuildPipeline (int count)
{
List<FakeElement> elements = new List<FakeElement> ();
for (int i = 0; i < count; i++) {
elements.Add (new FakeElement ());
}
-
+
QueuePipeline<object> qp = new QueuePipeline<object> ();
foreach (FakeElement s in elements) {
qp.AddElement (s);
}
-
+
Assert.AreEqual (elements[0], qp.FirstElement);
-
+
int index = 0;
FakeElement element = (FakeElement)qp.FirstElement;
while (element != null) {
diff --git a/src/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs b/src/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs
index bb81b8c..b461573 100644
--- a/src/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs
+++ b/src/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs
@@ -43,16 +43,16 @@ namespace Hyena.Collections.Tests
{
_TestRanges (new RangeCollection (), new int [] { 1, 11, 5, 7, 15, 32, 3, 9, 34 });
}
-
+
[Test]
public void MergedRanges ()
{
RangeCollection range = new RangeCollection ();
int [] indexes = new int [] { 0, 7, 5, 9, 1, 6, 8, 2, 10, 12 };
-
+
_TestRanges (range, indexes);
Assert.AreEqual (3, range.RangeCount);
-
+
int i= 0;
foreach (RangeCollection.Range r in range.Ranges) {
switch (i++) {
@@ -74,94 +74,94 @@ namespace Hyena.Collections.Tests
}
}
}
-
+
[Test]
public void LargeSequentialContains ()
{
RangeCollection range = new RangeCollection ();
int i, n = 1000000;
-
+
for (i = 0; i < n; i++) {
range.Add (i);
}
-
+
for (i = 0; i < n; i++) {
Assert.AreEqual (true, range.Contains (i));
}
}
-
+
[Test]
public void LargeSequential ()
- {
+ {
RangeCollection range = new RangeCollection ();
int i, n = 1000000;
-
+
for (i = 0; i < n; i++) {
range.Add (i);
Assert.AreEqual (1, range.RangeCount);
}
-
+
Assert.AreEqual (n, range.Count);
-
+
i = 0;
foreach (int j in range) {
Assert.AreEqual (i++, j);
}
-
+
Assert.AreEqual (n, i);
}
-
+
[Test]
public void LargeNonAdjacent ()
- {
+ {
RangeCollection range = new RangeCollection ();
int i, n = 1000000;
-
+
for (i = 0; i < n; i += 2) {
range.Add (i);
}
-
+
Assert.AreEqual (n / 2, range.Count);
-
+
i = 0;
foreach (int j in range) {
Assert.AreEqual (i, j);
i += 2;
}
-
+
Assert.AreEqual (n, i);
}
-
+
private static void _TestRanges (RangeCollection range, int [] indexes)
{
foreach (int index in indexes) {
range.Add (index);
}
-
+
Assert.AreEqual (indexes.Length, range.Count);
-
+
Array.Sort (indexes);
-
+
int i = 0;
foreach (int index in range) {
Assert.AreEqual (indexes[i++], index);
}
-
+
#pragma warning disable 0618
-
+
i = 0;
foreach (int index in range.Indexes) {
Assert.AreEqual (indexes[i++], index);
}
-
+
for (i = 0; i < range.Indexes.Length; i++) {
Assert.AreEqual (indexes[i], range.Indexes[i]);
}
-
+
#pragma warning restore 0618
-
+
}
-
+
[Test]
public void RemoveSingles ()
{
@@ -170,29 +170,29 @@ namespace Hyena.Collections.Tests
foreach (int index in indexes) {
range.Add (index);
}
-
+
foreach (int index in indexes) {
Assert.AreEqual (true, range.Remove (index));
}
}
-
+
[Test]
public void RemoveStarts ()
{
RangeCollection range = _SetupTestRemoveMerges ();
-
+
Assert.AreEqual (true, range.Contains (0));
range.Remove (0);
Assert.AreEqual (false, range.Contains (0));
Assert.AreEqual (4, range.RangeCount);
-
+
Assert.AreEqual (true, range.Contains (2));
range.Remove (2);
Assert.AreEqual (false, range.Contains (2));
Assert.AreEqual (4, range.RangeCount);
Assert.AreEqual (3, range.Ranges[0].Start);
Assert.AreEqual (5, range.Ranges[0].End);
-
+
Assert.AreEqual (true, range.Contains (14));
range.Remove (14);
Assert.AreEqual (false, range.Contains (14));
@@ -200,19 +200,19 @@ namespace Hyena.Collections.Tests
Assert.AreEqual (15, range.Ranges[2].Start);
Assert.AreEqual (15, range.Ranges[2].End);
}
-
+
[Test]
public void RemoveEnds ()
{
RangeCollection range = _SetupTestRemoveMerges ();
-
+
Assert.AreEqual (true, range.Contains (5));
range.Remove (5);
Assert.AreEqual (false, range.Contains (5));
Assert.AreEqual (5, range.RangeCount);
Assert.AreEqual (2, range.Ranges[1].Start);
Assert.AreEqual (4, range.Ranges[1].End);
-
+
Assert.AreEqual (true, range.Contains (15));
range.Remove (15);
Assert.AreEqual (false, range.Contains (15));
@@ -220,12 +220,12 @@ namespace Hyena.Collections.Tests
Assert.AreEqual (14, range.Ranges[3].Start);
Assert.AreEqual (14, range.Ranges[3].End);
}
-
+
[Test]
public void RemoveMids ()
{
RangeCollection range = _SetupTestRemoveMerges ();
-
+
Assert.AreEqual (5, range.RangeCount);
Assert.AreEqual (14, range.Ranges[3].Start);
Assert.AreEqual (15, range.Ranges[3].End);
@@ -240,22 +240,22 @@ namespace Hyena.Collections.Tests
Assert.AreEqual (14, range.Ranges[4].Start);
Assert.AreEqual (15, range.Ranges[4].End);
}
-
+
private static RangeCollection _SetupTestRemoveMerges ()
{
RangeCollection range = new RangeCollection ();
- int [] indexes = new int [] {
- 0,
+ int [] indexes = new int [] {
+ 0,
2, 3, 4, 5,
7, 8, 9, 10, 11,
14, 15,
17, 18, 19
};
-
+
foreach (int index in indexes) {
range.Add (index);
}
-
+
int i = 0;
foreach (RangeCollection.Range r in range.Ranges) {
switch (i++) {
@@ -284,43 +284,43 @@ namespace Hyena.Collections.Tests
break;
}
}
-
+
return range;
}
-
+
#pragma warning disable 0618
-
+
[Test]
public void IndexesCacheGeneration ()
{
RangeCollection range = new RangeCollection ();
int [] index_cache = range.Indexes;
-
+
Assert.AreSame (index_cache, range.Indexes);
-
+
range.Add (0);
range.Add (5);
-
+
if (index_cache == range.Indexes) {
Assert.Fail ("Indexes Cache not regenerated after change");
}
-
+
index_cache = range.Indexes;
range.Remove (0);
range.Add (3);
-
+
if (index_cache == range.Indexes) {
Assert.Fail ("Indexes Cache not regenerated after change");
}
}
-
+
#pragma warning restore 0618
-
+
[Test]
public void IndexOf ()
{
RangeCollection range = new RangeCollection ();
-
+
range.Add (0);
range.Add (2);
range.Add (3);
@@ -331,7 +331,7 @@ namespace Hyena.Collections.Tests
range.Add (11);
range.Add (12);
range.Add (13);
-
+
Assert.AreEqual (0, range.IndexOf (0));
Assert.AreEqual (1, range.IndexOf (2));
Assert.AreEqual (2, range.IndexOf (3));
@@ -344,27 +344,27 @@ namespace Hyena.Collections.Tests
Assert.AreEqual (9, range.IndexOf (13));
Assert.AreEqual (-1, range.IndexOf (99));
}
-
+
[Test]
public void IndexerForGoodIndexes ()
{
RangeCollection range = new RangeCollection ();
-
+
/*
Range Idx Value
0-2 0 -> 0
1 -> 1
2 -> 2
-
+
7-9 3 -> 7
4 -> 8
5 -> 9
-
+
11-13 6 -> 11
7 -> 12
8 -> 13
*/
-
+
range.Add (0);
range.Add (1);
range.Add (2);
@@ -374,7 +374,7 @@ namespace Hyena.Collections.Tests
range.Add (11);
range.Add (12);
range.Add (13);
-
+
Assert.AreEqual (0, range[0]);
Assert.AreEqual (1, range[1]);
Assert.AreEqual (2, range[2]);
@@ -385,27 +385,27 @@ namespace Hyena.Collections.Tests
Assert.AreEqual (12, range[7]);
Assert.AreEqual (13, range[8]);
}
-
+
[Test]
public void StressForGoodIndexes ()
{
Random random = new Random (0xbeef);
RangeCollection ranges = new RangeCollection ();
List<int> indexes = new List<int> ();
-
+
for (int i = 0, n = 75000; i < n; i++) {
int value = random.Next (n);
if (ranges.Add (value)) {
CollectionExtensions.SortedInsert (indexes, value);
}
- }
-
+ }
+
Assert.AreEqual (indexes.Count, ranges.Count);
for (int i = 0; i < indexes.Count; i++) {
Assert.AreEqual (indexes[i], ranges[i]);
}
}
-
+
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void IndexerForNegativeBadIndex ()
@@ -413,7 +413,7 @@ namespace Hyena.Collections.Tests
RangeCollection range = new RangeCollection ();
Assert.AreEqual (0, range[1]);
}
-
+
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void IndexerForZeroBadIndex ()
@@ -421,7 +421,7 @@ namespace Hyena.Collections.Tests
RangeCollection range = new RangeCollection ();
Assert.AreEqual (0, range[0]);
}
-
+
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void IndexerForPositiveBadIndex ()
@@ -430,7 +430,7 @@ namespace Hyena.Collections.Tests
range.Add (1);
Assert.AreEqual (0, range[1]);
}
-
+
[Test]
public void ExplicitInterface ()
{
@@ -439,10 +439,10 @@ namespace Hyena.Collections.Tests
range.Add (2);
range.Add (5);
range.Add (6);
-
+
Assert.AreEqual (4, range.Count);
}
-
+
[Test]
public void NegativeIndices ()
{
@@ -464,7 +464,7 @@ namespace Hyena.Collections.Tests
Assert.AreEqual (new RangeCollection.Range (-5, -5), c.Ranges[1], "#7");
Assert.AreEqual (new RangeCollection.Range (5, 5), c.Ranges[2], "#8");
Assert.AreEqual (new RangeCollection.Range (10, 10), c.Ranges[3], "#9");
-
+
Assert.AreEqual (0, c.FindRangeIndexForValue (-9), "#10");
Assert.IsTrue (c.FindRangeIndexForValue (-7) < 0, "#11");
}
@@ -480,12 +480,12 @@ namespace Hyena.Collections.Tests
for (int i = start; i <= end; i++) {
ranges.Add (i);
}
-
+
Assert.IsTrue (ranges.Contains (GetAddress ("127.0.0.15")));
Assert.IsFalse (ranges.Contains (GetAddress ("127.0.0.0")));
Assert.IsFalse (ranges.Contains (GetAddress ("127.0.0.51")));
}
-
+
private static int GetAddress (string addressStr)
{
System.Net.IPAddress address = System.Net.IPAddress.Parse (addressStr);
diff --git a/src/Hyena/Hyena.Collections/WriteLineElement.cs b/src/Hyena/Hyena.Collections/WriteLineElement.cs
index f1277cd..3d3b37f 100644
--- a/src/Hyena/Hyena.Collections/WriteLineElement.cs
+++ b/src/Hyena/Hyena.Collections/WriteLineElement.cs
@@ -36,7 +36,7 @@ namespace Hyena.Collections
{
Threaded = false;
}
-
+
protected override T ProcessItem (T item)
{
Console.WriteLine (item);
diff --git a/src/Hyena/Hyena.CommandLine/CommandLineParser.cs b/src/Hyena/Hyena.CommandLine/CommandLineParser.cs
index 91325d2..b5e5e19 100644
--- a/src/Hyena/Hyena.CommandLine/CommandLineParser.cs
+++ b/src/Hyena/Hyena.CommandLine/CommandLineParser.cs
@@ -1,4 +1,4 @@
-//
+//
// CommandLineParser.cs
//
// Author:
@@ -38,14 +38,14 @@ namespace Hyena.CommandLine
{
public int Order;
public string Value;
-
+
public Argument (int order, string value)
{
Order = order;
Value = value;
}
}
-
+
private int generation;
private int sorted_args_generation;
private int offset;
@@ -53,19 +53,19 @@ namespace Hyena.CommandLine
private KeyValuePair<string, Argument> [] sorted_args;
private Dictionary<string, Argument> parsed_arguments = new Dictionary<string, Argument> ();
private List<string> file_list = new List<string> ();
-
+
public CommandLineParser () : this (Environment.GetCommandLineArgs (), 1)
{
}
-
+
public CommandLineParser (string [] arguments, int offset)
{
this.arguments = arguments;
this.offset = offset;
-
+
Parse ();
}
-
+
private void Parse ()
{
for (int i = offset; i < arguments.Length; i++) {
@@ -73,7 +73,7 @@ namespace Hyena.CommandLine
file_list.Add (arguments[i]);
continue;
}
-
+
string name = OptionName (arguments[i]);
string value = String.Empty;
@@ -82,7 +82,7 @@ namespace Hyena.CommandLine
value = name.Substring (eq_offset + 1);
name = name.Substring (0, eq_offset);
}
-
+
if (parsed_arguments.ContainsKey (name)) {
parsed_arguments[name] = new Argument (i, value);
} else {
@@ -90,22 +90,22 @@ namespace Hyena.CommandLine
}
}
}
-
+
private bool IsOption (string argument)
{
return argument.Length > 2 && argument.Substring (0, 2) == "--";
}
-
+
private string OptionName (string argument)
{
return argument.Substring (2);
}
-
+
public bool Contains (string name)
{
return parsed_arguments.ContainsKey (name);
}
-
+
public bool ContainsStart (string start)
{
foreach (string argument in parsed_arguments.Keys) {
@@ -115,34 +115,34 @@ namespace Hyena.CommandLine
}
return false;
}
-
+
public string this[string name] {
get { return Contains (name) ? parsed_arguments[name].Value : String.Empty; }
- set {
+ set {
Argument arg = parsed_arguments[name];
arg.Value = value;
parsed_arguments[name] = arg;
generation++;
}
}
-
+
public IEnumerable<KeyValuePair<string, string>> Arguments {
get {
- if (sorted_args == null || sorted_args_generation != generation) {
+ if (sorted_args == null || sorted_args_generation != generation) {
sorted_args = new KeyValuePair<string, Argument>[parsed_arguments.Count];
int i = 0;
-
+
foreach (KeyValuePair<string, Argument> arg in parsed_arguments) {
sorted_args[i++] = arg;
}
-
+
Array.Sort (sorted_args, delegate (KeyValuePair<string, Argument> a, KeyValuePair<string, Argument> b) {
return a.Value.Order.CompareTo (b.Value.Order);
});
-
+
sorted_args_generation = generation;
}
-
+
foreach (KeyValuePair<string, Argument> arg in sorted_args) {
yield return new KeyValuePair<string, string> (arg.Key, arg.Value.Value);
}
@@ -152,21 +152,21 @@ namespace Hyena.CommandLine
public ReadOnlyCollection<string> Files {
get { return new ReadOnlyCollection<string> (file_list); }
}
-
+
public override string ToString ()
{
System.Text.StringBuilder builder = new System.Text.StringBuilder ();
builder.Append ("Parsed Arguments\n");
foreach (KeyValuePair<string, Argument> argument in parsed_arguments) {
- builder.AppendFormat (" {0} = [{1}]\n", argument.Key, argument.Value.Value);
+ builder.AppendFormat (" {0} = [{1}]\n", argument.Key, argument.Value.Value);
}
-
+
builder.Append ("\nFile List\n");
foreach (string file in file_list) {
builder.AppendFormat ("{0}\n", file);
}
-
+
return builder.ToString ();
}
}
diff --git a/src/Hyena/Hyena.CommandLine/Layout.cs b/src/Hyena/Hyena.CommandLine/Layout.cs
index f4797fb..665c198 100644
--- a/src/Hyena/Hyena.CommandLine/Layout.cs
+++ b/src/Hyena/Hyena.CommandLine/Layout.cs
@@ -35,7 +35,7 @@ namespace Hyena.CommandLine
public class Layout
{
private List<LayoutGroup> groups;
-
+
public Layout (List<LayoutGroup> groups)
{
this.groups = groups;
@@ -44,33 +44,33 @@ namespace Hyena.CommandLine
public Layout (params LayoutGroup [] groups) : this (new List<LayoutGroup> (groups))
{
}
-
+
private int TerminalWidth {
get { return Console.WindowWidth <= 0 ? 80 : Console.WindowWidth; }
}
-
+
public string ToString (params string [] groupIds)
{
return ToString (GroupIdsToGroups (groupIds));
}
-
+
public override string ToString ()
{
return ToString (groups);
}
-
+
public string ToString (IEnumerable<LayoutGroup> groups)
{
StringBuilder builder = new StringBuilder ();
-
+
int min_spacing = 6;
-
+
int group_index = 0;
int group_count = 0;
int max_option_length = 0;
int max_description_length = 0;
int description_alignment = 0;
-
+
foreach (LayoutGroup group in groups) {
foreach (LayoutOption option in group) {
if (option.Name.Length > max_option_length) {
@@ -78,54 +78,54 @@ namespace Hyena.CommandLine
}
}
}
-
+
max_description_length = TerminalWidth - max_option_length - min_spacing - 4;
description_alignment = max_option_length + min_spacing + 4;
-
+
IEnumerator<LayoutGroup> enumerator = groups.GetEnumerator ();
while (enumerator.MoveNext ()) {
group_count++;
}
-
+
foreach (LayoutGroup group in groups) {
if (group.Id != "default") {
builder.Append (group.Title);
builder.AppendLine ();
builder.AppendLine ();
}
-
+
for (int i = 0, n = group.Count; i < n; i++) {
int spacing = (max_option_length - group[i].Name.Length) + min_spacing;
- builder.AppendFormat (" --{0}{2}{1}", group[i].Name,
- WrapAlign (group[i].Description, max_description_length,
+ builder.AppendFormat (" --{0}{2}{1}", group[i].Name,
+ WrapAlign (group[i].Description, max_description_length,
description_alignment, i == n - 1),
String.Empty.PadRight (spacing));
builder.AppendLine ();
}
-
+
if (group_index++ < group_count - 1) {
builder.AppendLine ();
}
}
-
+
return builder.ToString ();
}
-
+
public string LayoutLine (string str)
{
return WrapAlign (str, TerminalWidth, 0, true);
}
-
+
private static string WrapAlign (string str, int width, int align, bool last)
{
StringBuilder builder = new StringBuilder ();
bool did_wrap = false;
-
+
for (int i = 0, b = 0; i < str.Length; i++, b++) {
if (str[i] == ' ') {
int word_length = 0;
for (int j = i + 1; j < str.Length && str[j] != ' '; word_length++, j++);
-
+
if (b + word_length >= width) {
builder.AppendLine ();
builder.Append (String.Empty.PadRight (align));
@@ -134,27 +134,27 @@ namespace Hyena.CommandLine
continue;
}
}
-
+
builder.Append (str[i]);
}
-
+
if (did_wrap && !last) {
builder.AppendLine ();
}
-
+
return builder.ToString ();
}
-
+
public void Add (LayoutGroup group)
{
groups.Add (group);
}
-
+
public void Remove (LayoutGroup group)
{
groups.Remove (group);
}
-
+
public void Remove (string groupId)
{
LayoutGroup group = FindGroup (groupId);
@@ -162,7 +162,7 @@ namespace Hyena.CommandLine
groups.Remove (group);
}
}
-
+
private LayoutGroup FindGroup (string id)
{
foreach (LayoutGroup group in groups) {
@@ -170,25 +170,25 @@ namespace Hyena.CommandLine
return group;
}
}
-
+
return null;
}
-
+
private IEnumerable<LayoutGroup> GroupIdsToGroups (string [] groupIds)
{
foreach (string group_id in groupIds) {
LayoutGroup group = FindGroup (group_id);
if (group != null) {
yield return group;
- }
+ }
}
}
-
+
public static LayoutOption Option (string name, string description)
{
return new LayoutOption (name, description);
}
-
+
public static LayoutGroup Group (string id, string title, params LayoutOption [] options)
{
return new LayoutGroup (id, title, options);
diff --git a/src/Hyena/Hyena.CommandLine/LayoutGroup.cs b/src/Hyena/Hyena.CommandLine/LayoutGroup.cs
index 4054937..757f559 100644
--- a/src/Hyena/Hyena.CommandLine/LayoutGroup.cs
+++ b/src/Hyena/Hyena.CommandLine/LayoutGroup.cs
@@ -1,4 +1,4 @@
-//
+//
// LayoutGroup.cs
//
// Author:
@@ -36,44 +36,44 @@ namespace Hyena.CommandLine
private List<LayoutOption> options;
private string id;
private string title;
-
+
public LayoutGroup (string id, string title, List<LayoutOption> options)
{
this.id = id;
this.title = title;
this.options = options;
}
-
- public LayoutGroup (string id, string title, params LayoutOption [] options)
+
+ public LayoutGroup (string id, string title, params LayoutOption [] options)
: this (id, title, new List<LayoutOption> (options))
{
}
-
+
public IEnumerator<LayoutOption> GetEnumerator ()
{
return options.GetEnumerator ();
}
-
+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
-
+
public void Add (LayoutOption option)
{
options.Add (option);
}
-
+
public void Add (string name, string description)
{
options.Add (new LayoutOption (name, description));
}
-
+
public void Remove (LayoutOption option)
{
options.Remove (option);
}
-
+
public void Remove (string optionName)
{
LayoutOption option = FindOption (optionName);
@@ -81,7 +81,7 @@ namespace Hyena.CommandLine
options.Remove (option);
}
}
-
+
private LayoutOption FindOption (string name)
{
foreach (LayoutOption option in options) {
@@ -89,27 +89,27 @@ namespace Hyena.CommandLine
return option;
}
}
-
+
return null;
}
-
+
public LayoutOption this[int index] {
get { return options[index]; }
set { options[index] = value; }
}
-
+
public int Count {
get { return options.Count; }
}
-
+
public string Id {
get { return id; }
}
-
+
public string Title {
get { return title; }
}
-
+
public IList<LayoutOption> Options {
get { return options; }
}
diff --git a/src/Hyena/Hyena.CommandLine/LayoutOption.cs b/src/Hyena/Hyena.CommandLine/LayoutOption.cs
index e27bf70..8a01041 100644
--- a/src/Hyena/Hyena.CommandLine/LayoutOption.cs
+++ b/src/Hyena/Hyena.CommandLine/LayoutOption.cs
@@ -1,4 +1,4 @@
-//
+//
// LayoutOption.cs
//
// Author:
@@ -27,22 +27,22 @@
//
namespace Hyena.CommandLine
-{
+{
public class LayoutOption
{
private string name;
private string description;
-
+
public LayoutOption (string name, string description)
{
this.name = name;
- this.description = description;
+ this.description = description;
}
-
+
public string Name {
get { return name; }
}
-
+
public string Description {
get { return description; }
}
diff --git a/src/Hyena/Hyena.Data/BaseListModel.cs b/src/Hyena/Hyena.Data/BaseListModel.cs
index 4066059..9694784 100644
--- a/src/Hyena/Hyena.Data/BaseListModel.cs
+++ b/src/Hyena/Hyena.Data/BaseListModel.cs
@@ -43,7 +43,7 @@ namespace Hyena.Data
public BaseListModel () : base ()
{
}
-
+
protected virtual void OnCleared ()
{
EventHandler handler = Cleared;
@@ -51,7 +51,7 @@ namespace Hyena.Data
handler(this, EventArgs.Empty);
}
}
-
+
protected virtual void OnReloaded ()
{
EventHandler handler = Reloaded;
@@ -64,11 +64,11 @@ namespace Hyena.Data
{
OnReloaded ();
}
-
+
public abstract void Clear();
-
+
public abstract void Reload();
-
+
public abstract T this[int index] { get; }
public abstract int Count { get; }
@@ -83,7 +83,7 @@ namespace Hyena.Data
return model_selection ?? (model_selection = new ModelSelection<T> (this, Selection));
}
}
-
+
public T FocusedItem {
get { return Selection.FocusedIndex == -1 ? default(T) : this[Selection.FocusedIndex]; }
}
diff --git a/src/Hyena/Hyena.Data/ColumnDescription.cs b/src/Hyena/Hyena.Data/ColumnDescription.cs
index abd9311..cdb6a12 100644
--- a/src/Hyena/Hyena.Data/ColumnDescription.cs
+++ b/src/Hyena/Hyena.Data/ColumnDescription.cs
@@ -39,14 +39,14 @@ namespace Hyena.Data
private string property;
private bool initialized;
-
+
public event EventHandler VisibilityChanged;
public event EventHandler WidthChanged;
-
+
public ColumnDescription (string property, string title, double width) : this (property, title, width, true)
{
}
-
+
public ColumnDescription (string property, string title, double width, bool visible)
{
this.property = property;
@@ -56,7 +56,7 @@ namespace Hyena.Data
Visible = visible;
initialized = true;
}
-
+
protected virtual void OnVisibilityChanged ()
{
EventHandler handler = VisibilityChanged;
@@ -64,7 +64,7 @@ namespace Hyena.Data
handler (this, EventArgs.Empty);
}
}
-
+
protected virtual void OnWidthChanged ()
{
EventHandler handler = WidthChanged;
@@ -72,7 +72,7 @@ namespace Hyena.Data
handler (this, EventArgs.Empty);
}
}
-
+
public string Title {
get { return title; }
set { title = value; }
@@ -82,7 +82,7 @@ namespace Hyena.Data
get { return long_title; }
set { long_title = value; }
}
-
+
public double Width {
get { return width; }
set {
@@ -98,18 +98,18 @@ namespace Hyena.Data
}
}
}
-
+
public string Property {
get { return property; }
set { property = value; }
}
-
+
public bool Visible {
get { return visible; }
set {
bool old = Visible;
visible = value;
-
+
if(initialized && value != old) {
OnVisibilityChanged ();
}
diff --git a/src/Hyena/Hyena.Data/IListModel.cs b/src/Hyena/Hyena.Data/IListModel.cs
index 9cdda82..3bb8629 100644
--- a/src/Hyena/Hyena.Data/IListModel.cs
+++ b/src/Hyena/Hyena.Data/IListModel.cs
@@ -36,19 +36,19 @@ namespace Hyena.Data
{
event EventHandler Cleared;
event EventHandler Reloaded;
-
+
void Clear ();
void Reload ();
-
+
int Count { get; }
bool CanReorder { get; }
}
-
+
public interface IListModel<T> : IListModel
{
T this[int index] { get; }
}
-
+
public interface IObjectListModel : IListModel<object>
{
ColumnDescription [] ColumnDescriptions { get; }
diff --git a/src/Hyena/Hyena.Data/IPropertyStoreExpose.cs b/src/Hyena/Hyena.Data/IPropertyStoreExpose.cs
index eb4e054..d8c4381 100644
--- a/src/Hyena/Hyena.Data/IPropertyStoreExpose.cs
+++ b/src/Hyena/Hyena.Data/IPropertyStoreExpose.cs
@@ -1,4 +1,4 @@
-//
+//
// IPropertyStoreExpose.cs
//
// Author:
@@ -29,7 +29,7 @@
using System;
namespace Hyena.Data
-{
+{
public interface IPropertyStoreExpose
{
PropertyStore PropertyStore { get; }
diff --git a/src/Hyena/Hyena.Data/ModelCache.cs b/src/Hyena/Hyena.Data/ModelCache.cs
index c736ed6..fe610b2 100644
--- a/src/Hyena/Hyena.Data/ModelCache.cs
+++ b/src/Hyena/Hyena.Data/ModelCache.cs
@@ -45,16 +45,16 @@ namespace Hyena.Data
lock (this) {
if (ContainsKey (index))
return this[index];
-
+
FetchSet (index, model.FetchCount);
-
+
if (ContainsKey (index))
return this[index];
-
+
return default (T);
}
}
-
+
// Responsible for fetching a set of items and placing them in the cache
protected abstract void FetchSet (long offset, long limit);
diff --git a/src/Hyena/Hyena.Data/PropertyStore.cs b/src/Hyena/Hyena.Data/PropertyStore.cs
index 0225017..60a5af8 100644
--- a/src/Hyena/Hyena.Data/PropertyStore.cs
+++ b/src/Hyena/Hyena.Data/PropertyStore.cs
@@ -32,7 +32,7 @@ using System.Collections.Generic;
namespace Hyena.Data
{
public delegate void PropertyChangeEventHandler(object o, PropertyChangeEventArgs args);
-
+
public class PropertyChangeEventArgs : EventArgs
{
private string property_name;
@@ -40,7 +40,7 @@ namespace Hyena.Data
private bool removed;
private object old_value;
private object new_value;
-
+
public PropertyChangeEventArgs(string propertyName, bool added, bool removed, object oldValue, object newValue)
{
this.property_name = propertyName;
@@ -49,49 +49,49 @@ namespace Hyena.Data
this.old_value = oldValue;
this.new_value = newValue;
}
-
+
public string PropertyName {
get { return property_name; }
}
-
+
public bool Added {
get { return added; }
}
-
+
public bool Removed {
get { return removed; }
}
-
+
public object OldValue {
get { return old_value; }
}
-
+
public object NewValue {
get { return new_value; }
}
}
-
+
public class PropertyStore
{
private Dictionary<string, object> object_store;
-
+
public event PropertyChangeEventHandler PropertyChanged;
-
+
public PropertyStore()
{
}
-
- protected virtual void OnPropertyChanged(string propertyName, bool added, bool removed,
+
+ protected virtual void OnPropertyChanged(string propertyName, bool added, bool removed,
object oldValue, object newValue)
{
PropertyChangeEventHandler handler = PropertyChanged;
if(handler != null) {
- PropertyChangeEventArgs args = new PropertyChangeEventArgs(propertyName,
+ PropertyChangeEventArgs args = new PropertyChangeEventArgs(propertyName,
added, removed, oldValue, newValue);
handler(this, args);
}
}
-
+
public void Remove(string name)
{
bool raise = false;
@@ -108,28 +108,28 @@ namespace Hyena.Data
OnPropertyChanged(name, false, true, old_value, null);
}
}
-
+
public void RemoveStartingWith (string prefix)
{
lock(this) {
Queue<string> to_remove = null;
-
+
foreach (KeyValuePair<string, object> item in object_store) {
if (item.Key.StartsWith (prefix)) {
if (to_remove == null) {
to_remove = new Queue<string> ();
}
-
+
to_remove.Enqueue (item.Key);
}
}
-
+
while (to_remove != null && to_remove.Count > 0) {
Remove (to_remove.Dequeue ());
}
}
}
-
+
public void Set<T>(string name, T value)
{
bool added = false;
@@ -151,66 +151,66 @@ namespace Hyena.Data
}
OnPropertyChanged(name, added, false, old_value, value);
}
-
+
public T Get<T>(string name)
{
lock(this) {
if(object_store != null && object_store.ContainsKey(name)) {
return (T)object_store[name];
}
-
+
return default(T);
}
}
-
+
public int GetInteger(string name)
{
return Get<int>(name);
}
-
+
public void SetInteger(string name, int value)
{
Set<int>(name, value);
}
-
+
// No longer used, since it causes strings to be marked for translation
/*public string GetString(string name)
{
return Get<string>(name);
}*/
-
+
public void SetString(string name, string value)
{
Set<string>(name, value);
}
-
+
public string [] GetStringList(string name)
{
return Get<string []>(name);
}
-
+
public void SetStringList(string name, params string [] value)
{
Set<string []>(name, value);
}
-
+
public bool GetBoolean(string name)
{
return Get<bool>(name);
}
-
+
public void SetBoolean(string name, bool value)
{
Set<bool>(name, value);
}
-
+
public bool Contains(string name)
{
lock(this) {
return object_store != null && object_store.ContainsKey(name);
}
}
-
+
public Type GetType(string name)
{
lock(this) {
diff --git a/src/Hyena/Hyena.Jobs/Job.cs b/src/Hyena/Hyena.Jobs/Job.cs
index 99c49db..0fdaa44 100644
--- a/src/Hyena/Hyena.Jobs/Job.cs
+++ b/src/Hyena/Hyena.Jobs/Job.cs
@@ -193,8 +193,8 @@ namespace Hyena.Jobs
get { return icon_names; }
set {
if (value != null) {
- icon_names = value;
- OnUpdated ();
+ icon_names = value;
+ OnUpdated ();
}
}
}
diff --git a/src/Hyena/Hyena.Jobs/Scheduler.cs b/src/Hyena/Hyena.Jobs/Scheduler.cs
index d18f713..4573d1d 100644
--- a/src/Hyena/Hyena.Jobs/Scheduler.cs
+++ b/src/Hyena/Hyena.Jobs/Scheduler.cs
@@ -182,7 +182,7 @@ namespace Hyena.Jobs
if (job.Has (PriorityHints.SpeedSensitive))
return true;
-
+
// Run only one non-SpeedSensitive job that uses a given Resource
if (job.Has (PriorityHints.LongRunning))
return jobs.Where (IsRunning)
diff --git a/src/Hyena/Hyena.Jobs/Tests/SchedulerTests.cs b/src/Hyena/Hyena.Jobs/Tests/SchedulerTests.cs
index 8ca7cd3..262075f 100644
--- a/src/Hyena/Hyena.Jobs/Tests/SchedulerTests.cs
+++ b/src/Hyena/Hyena.Jobs/Tests/SchedulerTests.cs
@@ -35,7 +35,7 @@ using System.Threading;
using NUnit.Framework;
using Hyena;
-
+
namespace Hyena.Jobs
{
[TestFixture]
diff --git a/src/Hyena/Hyena.Json/Deserializer.cs b/src/Hyena/Hyena.Json/Deserializer.cs
index 15afe8c..f54b6d7 100644
--- a/src/Hyena/Hyena.Json/Deserializer.cs
+++ b/src/Hyena/Hyena.Json/Deserializer.cs
@@ -1,4 +1,4 @@
-//
+//
// Deserializer.cs
//
// Author:
@@ -34,40 +34,40 @@ namespace Hyena.Json
public class Deserializer
{
private Tokenizer tokenizer = new Tokenizer ();
-
+
public Deserializer () { }
public Deserializer (string input) { SetInput (input); }
public Deserializer (Stream stream) { SetInput (stream); }
public Deserializer (StreamReader reader) { SetInput (reader); }
-
+
public Deserializer SetInput (StreamReader reader)
{
tokenizer.SetInput (reader);
return this;
}
-
+
public Deserializer SetInput (Stream stream)
{
tokenizer.SetInput (stream);
return this;
}
-
+
public Deserializer SetInput (string input)
{
tokenizer.SetInput (input);
return this;
}
-
+
public object Deserialize ()
{
Token token = CheckScan (TokenType.Value, true);
if (token == null) {
return null;
}
-
+
return Parse (token);
}
-
+
private object Parse (Token token)
{
if (token.Type == TokenType.ObjectStart) {
@@ -75,67 +75,67 @@ namespace Hyena.Json
} else if (token.Type == TokenType.ArrayStart) {
return ParseArray ();
}
-
+
return token.Value;
}
-
+
private JsonObject ParseObject ()
{
JsonObject obj = new JsonObject ();
-
+
while (true) {
Token key = CheckScan (TokenType.String | TokenType.ObjectFinish);
if (key.Type == TokenType.ObjectFinish) {
break;
}
-
+
CheckScan (TokenType.Colon);
Token value = CheckScan (TokenType.Value);
-
+
object value_val = value.Value;
if (value.Type == TokenType.ArrayStart) {
value_val = ParseArray ();
} else if (value.Type == TokenType.ObjectStart) {
value_val = ParseObject ();
}
-
+
obj.Add ((string)key.Value, value_val);
-
+
Token token = CheckScan (TokenType.Comma | TokenType.ObjectFinish);
if (token.Type == TokenType.ObjectFinish) {
break;
}
}
-
+
return obj;
}
-
+
private JsonArray ParseArray ()
{
JsonArray array = new JsonArray ();
-
+
while (true) {
Token value = CheckScan (TokenType.Value | TokenType.ArrayFinish);
if (value.Type == TokenType.ArrayFinish) {
break;
}
-
+
array.Add (Parse (value));
-
+
Token token = CheckScan (TokenType.Comma | TokenType.ArrayFinish);
if (token.Type == TokenType.ArrayFinish) {
break;
}
}
-
+
return array;
}
-
+
private Token CheckScan (TokenType expected)
{
return CheckScan (expected, false);
}
-
+
private Token CheckScan (TokenType expected, bool eofok)
{
Token token = tokenizer.Scan ();
@@ -148,13 +148,13 @@ namespace Hyena.Json
}
return token;
}
-
+
private void UnexpectedToken (TokenType expected, Token got)
{
- throw new ApplicationException (String.Format ("Unexpected token {0} at [{1}:{2}]; expected {3}",
+ throw new ApplicationException (String.Format ("Unexpected token {0} at [{1}:{2}]; expected {3}",
got.Type, got.SourceLine, got.SourceColumn, expected));
}
-
+
private void UnexpectedEof (TokenType expected)
{
throw new ApplicationException (String.Format ("Unexpected End of File; expected {0}", expected));
diff --git a/src/Hyena/Hyena.Json/IJsonCollection.cs b/src/Hyena/Hyena.Json/IJsonCollection.cs
index 4d46bf7..c9fc698 100644
--- a/src/Hyena/Hyena.Json/IJsonCollection.cs
+++ b/src/Hyena/Hyena.Json/IJsonCollection.cs
@@ -1,4 +1,4 @@
-//
+//
// IJsonCollection.cs
//
// Author:
diff --git a/src/Hyena/Hyena.Json/JsonArray.cs b/src/Hyena/Hyena.Json/JsonArray.cs
index f2288bf..5d86826 100644
--- a/src/Hyena/Hyena.Json/JsonArray.cs
+++ b/src/Hyena/Hyena.Json/JsonArray.cs
@@ -1,4 +1,4 @@
-//
+//
// JsonArray.cs
//
// Author:
@@ -37,14 +37,14 @@ namespace Hyena.Json
{
Dump (1);
}
-
+
public void Dump (int levels)
{
if (Count == 0) {
Console.WriteLine ("[ ]");
return;
}
-
+
Console.WriteLine ("[");
foreach (object item in this) {
Console.Write (String.Empty.PadLeft (levels * 2, ' '));
diff --git a/src/Hyena/Hyena.Json/JsonObject.cs b/src/Hyena/Hyena.Json/JsonObject.cs
index 98d32c4..a9216b1 100644
--- a/src/Hyena/Hyena.Json/JsonObject.cs
+++ b/src/Hyena/Hyena.Json/JsonObject.cs
@@ -1,4 +1,4 @@
-//
+//
// JsonObject.cs
//
// Author:
@@ -37,14 +37,14 @@ namespace Hyena.Json
{
Dump (1);
}
-
+
public void Dump (int levels)
{
if (Count == 0) {
Console.WriteLine ("{ }");
return;
}
-
+
Console.WriteLine ("{");
foreach (KeyValuePair<string, object> item in this) {
Console.Write ("{0}\"{1}\" : ", String.Empty.PadLeft (levels * 2, ' '), item.Key);
diff --git a/src/Hyena/Hyena.Json/Tests/DeserializerTests.cs b/src/Hyena/Hyena.Json/Tests/DeserializerTests.cs
index e5c9927..7c1bda8 100644
--- a/src/Hyena/Hyena.Json/Tests/DeserializerTests.cs
+++ b/src/Hyena/Hyena.Json/Tests/DeserializerTests.cs
@@ -40,13 +40,13 @@ namespace Hyena.Json.Tests
public class DeserializerTests : Hyena.Tests.TestBase
{
private Deserializer deserializer;
-
+
[TestFixtureSetUp]
public void Setup ()
{
deserializer = new Deserializer ();
}
-
+
[Test]
public void Literal ()
{
@@ -56,39 +56,39 @@ namespace Hyena.Json.Tests
Assert.AreEqual (true, (bool)deserializer.SetInput ("true").Deserialize ());
Assert.AreEqual (false, (bool)deserializer.SetInput ("false").Deserialize ());
}
-
+
[Test]
public void Array ()
{
JsonArray array = (JsonArray)deserializer.SetInput ("[]").Deserialize ();
Assert.AreEqual (0, array.Count);
-
+
array = (JsonArray)deserializer.SetInput ("[[]]").Deserialize ();
Assert.AreEqual (1, array.Count);
Assert.AreEqual (0, ((JsonArray)array[0]).Count);
-
+
array = (JsonArray)deserializer.SetInput ("[[true,[]]]").Deserialize ();
Assert.AreEqual (1, array.Count);
Assert.AreEqual (2, ((JsonArray)array[0]).Count);
Assert.AreEqual (0, ((JsonArray)((JsonArray)array[0])[1]).Count);
-
+
array = (JsonArray)deserializer.SetInput ("[\"a\", 1.0, true]").Deserialize ();
Assert.AreEqual (3, array.Count);
Assert.AreEqual ("a", (string)array[0]);
Assert.AreEqual (1, (double)array[1]);
Assert.AreEqual (true, (bool)array[2]);
}
-
+
[Test]
public void Object ()
{
JsonObject obj = (JsonObject)deserializer.SetInput ("{}").Deserialize ();
Assert.AreEqual (0, obj.Count);
-
+
obj = (JsonObject)deserializer.SetInput ("{\"a\":{}}").Deserialize ();
Assert.AreEqual (1, obj.Count);
Assert.AreEqual (0, ((JsonObject)obj["a"]).Count);
-
+
obj = (JsonObject)deserializer.SetInput ("{\"a\":[{\"b\":false},\"c\"]}").Deserialize ();
Assert.AreEqual (1, obj.Count);
JsonArray arr = (JsonArray)obj["a"];
diff --git a/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs b/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs
index 696fa95..594935b 100644
--- a/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs
+++ b/src/Hyena/Hyena.Json/Tests/TokenizerTests.cs
@@ -40,13 +40,13 @@ namespace Hyena.Json.Tests
public class TokenizerTests : Hyena.Tests.TestBase
{
private Tokenizer tokenizer;
-
+
[TestFixtureSetUp]
public void Setup ()
{
tokenizer = new Tokenizer ();
}
-
+
[Test]
public void Whitespace ()
{
@@ -54,7 +54,7 @@ namespace Hyena.Json.Tests
AssertTokenStream (" ");
AssertTokenStream ("\f\n\r\t ");
}
-
+
[Test]
public void BoolNull ()
{
@@ -63,42 +63,42 @@ namespace Hyena.Json.Tests
AssertTokenStream ("false", Token.Bool (false));
AssertTokenStream ("null", Token.Null);
}
-
+
[Test]
public void NumberInt ()
{
// Number tests
AssertTokenStream ("0", Token.Number (0));
AssertTokenStream ("-0", Token.Number (-0));
-
+
AssertTokenStream ("9", Token.Number (9));
AssertTokenStream ("-9", Token.Number (-9));
-
+
AssertTokenStream ("14", Token.Number (14));
AssertTokenStream ("-14", Token.Number (-14));
-
+
AssertTokenStream ("15309", Token.Number (15309));
AssertTokenStream ("-15309", Token.Number (-15309));
}
-
+
[Test]
public void NumberFloat ()
{
AssertTokenStream ("0.0", Token.Number (0.0));
AssertTokenStream ("-0.0", Token.Number (-0.0));
-
+
AssertTokenStream ("1.9", Token.Number (1.9));
AssertTokenStream ("-1.9", Token.Number (-1.9));
-
+
AssertTokenStream ("9.1", Token.Number (9.1));
AssertTokenStream ("-9.1", Token.Number (-9.1));
-
+
AssertTokenStream ("15309.0", Token.Number (15309.0));
AssertTokenStream ("15309.9", Token.Number (15309.9));
AssertTokenStream ("-15309.01", Token.Number (-15309.01));
AssertTokenStream ("-15309.9009", Token.Number (-15309.9009));
}
-
+
[Test]
public void NumberExponent ()
{
@@ -108,13 +108,13 @@ namespace Hyena.Json.Tests
AssertTokenStream ("-20.6e3", Token.Number (-20.6e3));
AssertTokenStream ("-20.6e+3", Token.Number (-20.6e+3));
AssertTokenStream ("-20.6e-3", Token.Number (-20.6e-3));
-
+
AssertTokenStream ("1e1", Token.Number (1e1));
AssertTokenStream ("1E2", Token.Number (1E2));
AssertTokenStream ("1.0e1", Token.Number (1.0e1));
AssertTokenStream ("1.0E1", Token.Number (1.0E1));
}
-
+
[Test]
public void Strings ()
{
@@ -130,7 +130,7 @@ namespace Hyena.Json.Tests
AssertTokenStream (@"""1\uabcdef0""", Token.String ("1\uabcdef0"));
AssertTokenStream (@"""\b\f\n\r\t""", Token.String ("\b\f\n\r\t"));
}
-
+
[Test]
public void Container ()
{
@@ -139,42 +139,42 @@ namespace Hyena.Json.Tests
AssertTokenStream ("{ }", Token.ObjectStart, Token.ObjectFinish);
AssertTokenStream ("[ ]", Token.ArrayStart, Token.ArrayFinish);
AssertTokenStream ("[{}]", Token.ArrayStart, Token.ObjectStart, Token.ObjectFinish, Token.ArrayFinish);
- AssertTokenStream ("[[[ { } ]]]",
- Token.ArrayStart, Token.ArrayStart, Token.ArrayStart,
- Token.ObjectStart, Token.ObjectFinish,
+ AssertTokenStream ("[[[ { } ]]]",
+ Token.ArrayStart, Token.ArrayStart, Token.ArrayStart,
+ Token.ObjectStart, Token.ObjectFinish,
Token.ArrayFinish, Token.ArrayFinish, Token.ArrayFinish);
}
-
+
[Test]
public void Array ()
{
AssertTokenStream ("[1]", Token.ArrayStart, Token.Number (1), Token.ArrayFinish);
AssertTokenStream ("[1,0]", Token.ArrayStart, Token.Number (1), Token.Comma, Token.Number (0), Token.ArrayFinish);
- AssertTokenStream ("[\"a\",true,null]", Token.ArrayStart, Token.String ("a"), Token.Comma,
+ AssertTokenStream ("[\"a\",true,null]", Token.ArrayStart, Token.String ("a"), Token.Comma,
Token.Bool (true), Token.Comma, Token.Null, Token.ArrayFinish);
AssertTokenStream ("[0,1,[[2,[4]],5],6]", Token.ArrayStart, Token.Number (0), Token.Comma, Token.Number (1),
- Token.Comma, Token.ArrayStart, Token.ArrayStart, Token.Number (2), Token.Comma, Token.ArrayStart,
+ Token.Comma, Token.ArrayStart, Token.ArrayStart, Token.Number (2), Token.Comma, Token.ArrayStart,
Token.Number (4), Token.ArrayFinish, Token.ArrayFinish, Token.Comma, Token.Number (5), Token.ArrayFinish,
Token.Comma, Token.Number (6), Token.ArrayFinish);
}
-
+
[Test]
public void Object ()
{
- AssertTokenStream ("{\"a\":{}}", Token.ObjectStart, Token.String ("a"), Token.Colon, Token.ObjectStart,
+ AssertTokenStream ("{\"a\":{}}", Token.ObjectStart, Token.String ("a"), Token.Colon, Token.ObjectStart,
Token.ObjectFinish, Token.ObjectFinish);
- AssertTokenStream ("{\"a\":{\"b\":[],\"c\":false}}", Token.ObjectStart, Token.String ("a"),
- Token.Colon, Token.ObjectStart, Token.String ("b"), Token.Colon, Token.ArrayStart, Token.ArrayFinish,
+ AssertTokenStream ("{\"a\":{\"b\":[],\"c\":false}}", Token.ObjectStart, Token.String ("a"),
+ Token.Colon, Token.ObjectStart, Token.String ("b"), Token.Colon, Token.ArrayStart, Token.ArrayFinish,
Token.Comma, Token.String ("c"), Token.Colon, Token.Bool (false), Token.ObjectFinish, Token.ObjectFinish);
- AssertTokenStream ("[{\"a\":{},{}]", Token.ArrayStart, Token.ObjectStart, Token.String ("a"), Token.Colon,
+ AssertTokenStream ("[{\"a\":{},{}]", Token.ArrayStart, Token.ObjectStart, Token.String ("a"), Token.Colon,
Token.ObjectStart, Token.ObjectFinish, Token.Comma, Token.ObjectStart, Token.ObjectFinish, Token.ArrayFinish);
- }
-
+ }
+
private void AssertTokenStream (string input, params Token [] tokens)
{
int cmp_idx = 0;
tokenizer.SetInput (input);
-
+
while (true) {
Token token = tokenizer.Scan ();
if (token == null) {
@@ -183,17 +183,17 @@ namespace Hyena.Json.Tests
}
break;
}
-
+
Token compare = tokens[cmp_idx++];
if (compare.Type != token.Type) {
- throw new ApplicationException (String.Format ("TokenTypes do not match (exp {0}, got {1}",
+ throw new ApplicationException (String.Format ("TokenTypes do not match (exp {0}, got {1}",
compare.Type, token.Type));
}
-
+
if (compare.Value == null && token.Value == null) {
continue;
}
-
+
if ((compare.Type == TokenType.Number && (double)compare.Value != (double)token.Value) ||
(compare.Type == TokenType.String && (string)compare.Value != (string)token.Value) ||
(compare.Type == TokenType.Boolean && (bool)compare.Value != (bool)token.Value)) {
diff --git a/src/Hyena/Hyena.Json/Token.cs b/src/Hyena/Hyena.Json/Token.cs
index cce60c7..e2b5ef2 100644
--- a/src/Hyena/Hyena.Json/Token.cs
+++ b/src/Hyena/Hyena.Json/Token.cs
@@ -1,4 +1,4 @@
-//
+//
// Token.cs
//
// Author:
@@ -29,19 +29,19 @@
using System;
namespace Hyena.Json
-{
+{
internal class Token
{
public Token (TokenType type) : this (type, null)
{
}
-
+
public Token (TokenType type, object value)
{
this.type = type;
this.value = value;
}
-
+
private TokenType type;
public TokenType Type {
get { return type; }
@@ -58,51 +58,51 @@ namespace Hyena.Json
get { return source_line; }
internal set { source_line = value; }
}
-
+
private int source_column;
public int SourceColumn {
get { return source_column; }
internal set { source_column = value; }
}
-
+
internal static Token ObjectStart {
get { return new Token (TokenType.ObjectStart); }
}
-
+
internal static Token ObjectFinish {
get { return new Token (TokenType.ObjectFinish); }
}
-
+
internal static Token ArrayStart {
get { return new Token (TokenType.ArrayStart); }
}
-
+
internal static Token ArrayFinish {
get { return new Token (TokenType.ArrayFinish); }
}
-
+
internal static Token Null {
get { return new Token (TokenType.Null); }
}
-
+
internal static Token Comma {
get { return new Token (TokenType.Comma); }
}
-
+
internal static Token Colon {
get { return new Token (TokenType.Colon); }
}
-
+
internal static Token Number (double value)
{
return new Token (TokenType.Number, value);
}
-
+
internal static Token String (string value)
{
return new Token (TokenType.String, value);
}
-
+
internal static Token Bool (bool value)
{
return new Token (TokenType.Boolean, value);
diff --git a/src/Hyena/Hyena.Json/TokenType.cs b/src/Hyena/Hyena.Json/TokenType.cs
index b24a5ca..052631b 100644
--- a/src/Hyena/Hyena.Json/TokenType.cs
+++ b/src/Hyena/Hyena.Json/TokenType.cs
@@ -1,4 +1,4 @@
-//
+//
// TokenType.cs
//
// Author:
@@ -44,7 +44,7 @@ namespace Hyena.Json
Number = 1 << 7,
Comma = 1 << 8,
Colon = 1 << 9,
-
+
Literal = String | Number | Boolean | Null,
Value = ObjectStart | ArrayStart | Literal
}
diff --git a/src/Hyena/Hyena.Json/Tokenizer.cs b/src/Hyena/Hyena.Json/Tokenizer.cs
index f866c0b..3210b11 100644
--- a/src/Hyena/Hyena.Json/Tokenizer.cs
+++ b/src/Hyena/Hyena.Json/Tokenizer.cs
@@ -1,4 +1,4 @@
-//
+//
// Tokenizer.cs
//
// Author:
@@ -36,18 +36,18 @@ namespace Hyena.Json
{
private StreamReader reader;
private StringBuilder string_buffer;
-
+
private char peek = ' ';
private int current_line = 1;
private int current_column = 1;
private int token_start_line;
private int token_start_column;
-
+
public Tokenizer () { Reset (); }
public Tokenizer (string input) { SetInput (input); }
public Tokenizer (Stream stream) { SetInput (stream); }
public Tokenizer (StreamReader reader) { SetInput (reader); }
-
+
private void Reset ()
{
peek = ' ';
@@ -56,62 +56,62 @@ namespace Hyena.Json
token_start_line = 0;
token_start_column = 0;
}
-
+
public void SetInput (StreamReader reader)
{
this.reader = reader;
Reset ();
}
-
+
public void SetInput (Stream stream)
{
SetInput (new StreamReader (stream));
}
-
+
public void SetInput (string input)
{
SetInput (new MemoryStream (Encoding.UTF8.GetBytes (input)));
}
-
+
private void ReadChar ()
{
peek = (char)reader.Read ();
current_column++;
}
-
+
private void UnexpectedCharacter (char ch)
{
- throw new ApplicationException (String.Format ("Unexpected character '{0}' at [{1}:{2}]",
+ throw new ApplicationException (String.Format ("Unexpected character '{0}' at [{1}:{2}]",
ch, current_line, current_column - 1));
}
-
+
private void InvalidSyntax (string message)
{
throw new ApplicationException (String.Format ("Invalid syntax: {0} at [{1}:{2}]",
message, current_line, current_column));
}
-
+
private StringBuilder GetStringBuilder ()
{
if (string_buffer == null) {
string_buffer = new StringBuilder (64);
return string_buffer;
}
-
+
string_buffer.Remove (0, string_buffer.Length);
return string_buffer;
}
-
+
private string LexString ()
{
StringBuilder buffer = GetStringBuilder ();
bool read = true;
-
+
while (!reader.EndOfStream) {
if (read) {
ReadChar ();
}
-
+
read = true;
if (peek == '\\') {
@@ -141,16 +141,16 @@ namespace Hyena.Json
buffer.Append (peek);
}
}
-
+
if (peek != '"') {
InvalidSyntax ("Unterminated string, expected '\"' termination, got '" + peek + "'");
} else if (!read && reader.EndOfStream) {
ReadChar ();
}
-
+
return buffer.ToString ();
}
-
+
private string LexId ()
{
StringBuilder buffer = GetStringBuilder ();
@@ -162,42 +162,42 @@ namespace Hyena.Json
return buffer.ToString ();
}
-
+
private double LexInt ()
{
return LexInt (false, 0);
}
-
+
private double LexInt (bool hex, int maxDigits)
{
double value = 0.0;
int count = 0;
-
+
do {
- value = (hex ? 16 : 10) * value + (hex
+ value = (hex ? 16 : 10) * value + (hex
? peek >= 'A' && peek <= 'F'
? 10 + peek - 'A'
: (peek >= 'a' && peek <= 'f'
? 10 + peek - 'a'
: peek - '0')
: peek - '0');
-
+
if (maxDigits > 0 && ++count >= maxDigits) {
ReadChar ();
return value;
}
-
+
ReadChar ();
} while (Char.IsDigit (peek) || (hex && ((peek >= 'a' && peek <= 'f') || (peek >= 'A' && peek <= 'F'))));
-
+
return value;
}
-
+
private double LexFraction ()
{
double fraction = 0;
double d = 10;
-
+
while (true) {
ReadChar ();
@@ -208,10 +208,10 @@ namespace Hyena.Json
fraction += (peek - '0') / d;
d *= 10;
}
-
+
return fraction;
}
-
+
private double LexNumber ()
{
double value = 0.0;
@@ -219,17 +219,17 @@ namespace Hyena.Json
if (negate) {
ReadChar ();
}
-
+
if (peek != '0') {
value = LexInt ();
} else {
ReadChar ();
}
-
+
if (peek == '.') {
value += LexFraction ();
}
-
+
if (peek == 'e' || peek == 'E') {
ReadChar ();
if (peek == '-') {
@@ -244,22 +244,22 @@ namespace Hyena.Json
InvalidSyntax ("Malformed exponent");
}
}
-
+
if (Char.IsDigit (peek)) {
InvalidSyntax ("Numbers starting with 0 must be followed by a . or not " +
"followed by a digit (octal syntax not legal)");
}
-
+
return negate ? -1.0 * value : value;
}
-
+
public Token Scan ()
{
Token token = InnerScan ();
if (token == null) {
return null;
}
-
+
token.SourceLine = token_start_line;
token.SourceColumn = token_start_column - 1;
return token;
@@ -303,13 +303,13 @@ namespace Hyena.Json
break;
}
}
-
+
if (peek != Char.MaxValue) {
UnexpectedCharacter (peek);
}
break;
}
-
+
return null;
}
}
diff --git a/src/Hyena/Hyena.Query/FileSizeQueryValue.cs b/src/Hyena/Hyena.Query/FileSizeQueryValue.cs
index 757f854..ba0ad75 100644
--- a/src/Hyena/Hyena.Query/FileSizeQueryValue.cs
+++ b/src/Hyena/Hyena.Query/FileSizeQueryValue.cs
@@ -125,7 +125,7 @@ namespace Hyena.Query
}
}
}
-
+
public override string ToUserQuery ()
{
return ToUserQuery (false);
@@ -135,8 +135,8 @@ namespace Hyena.Query
{
if (factor != FileSizeFactor.None) {
return String.Format ("{0} {1}",
- IntValue == 0
- ? "0"
+ IntValue == 0
+ ? "0"
: StringUtil.DoubleToTenthsPrecision (((double)IntValue / (double)factor), always_decimal),
factor.ToString ()
);
diff --git a/src/Hyena/Hyena.Query/IntegerKeyedObjectQueryValue.cs b/src/Hyena/Hyena.Query/IntegerKeyedObjectQueryValue.cs
index e68f161..7cbc9b0 100644
--- a/src/Hyena/Hyena.Query/IntegerKeyedObjectQueryValue.cs
+++ b/src/Hyena/Hyena.Query/IntegerKeyedObjectQueryValue.cs
@@ -33,7 +33,7 @@ namespace Hyena.Query
public abstract class IntegerKeyedObjectQueryValue<T> : IntegerQueryValue where T : class
{
private T object_value;
-
+
public override void SetValue (long value)
{
object_value = null;
@@ -48,7 +48,7 @@ namespace Hyena.Query
return object_value;
}
}
-
+
protected abstract T Resolve ();
}
}
diff --git a/src/Hyena/Hyena.Query/IntegerQueryValue.cs b/src/Hyena/Hyena.Query/IntegerQueryValue.cs
index df2a13c..abb3245 100644
--- a/src/Hyena/Hyena.Query/IntegerQueryValue.cs
+++ b/src/Hyena/Hyena.Query/IntegerQueryValue.cs
@@ -55,7 +55,7 @@ namespace Hyena.Query
{
IsEmpty = !Int64.TryParse (input, out value);
}
-
+
public override void LoadString (string input)
{
ParseUserQuery (input);
diff --git a/src/Hyena/Hyena.Query/NullQueryValue.cs b/src/Hyena/Hyena.Query/NullQueryValue.cs
index 06aa001..e1eac54 100644
--- a/src/Hyena/Hyena.Query/NullQueryValue.cs
+++ b/src/Hyena/Hyena.Query/NullQueryValue.cs
@@ -39,7 +39,7 @@ namespace Hyena.Query
public class NullQueryValue : QueryValue
{
public static readonly Operator IsNullOrEmpty = new Operator ("empty", Catalog.GetString ("empty"), "IN (NULL, '', 0)", true, "!");
-
+
public static readonly NullQueryValue Instance = new NullQueryValue ();
public override string XmlElementName {
@@ -63,7 +63,7 @@ namespace Hyena.Query
public override void ParseUserQuery (string input)
{
}
-
+
public override void LoadString (string input)
{
}
diff --git a/src/Hyena/Hyena.Query/QueryField.cs b/src/Hyena/Hyena.Query/QueryField.cs
index 7e4bc3e..75288d2 100644
--- a/src/Hyena/Hyena.Query/QueryField.cs
+++ b/src/Hyena/Hyena.Query/QueryField.cs
@@ -48,7 +48,7 @@ namespace Hyena.Query
get { return name; }
set { name = value; }
}
-
+
private string property_name;
public string PropertyName {
get { return property_name; }
@@ -174,7 +174,7 @@ namespace Hyena.Query
public static string ToTermString (string alias, string op, string value)
{
value = String.Format (
- "{1}{0}{1}",
+ "{1}{0}{1}",
value, value.IndexOf (" ") == -1 ? String.Empty : "\""
);
diff --git a/src/Hyena/Hyena.Query/QueryListNode.cs b/src/Hyena/Hyena.Query/QueryListNode.cs
index e090e07..366481b 100644
--- a/src/Hyena/Hyena.Query/QueryListNode.cs
+++ b/src/Hyena/Hyena.Query/QueryListNode.cs
@@ -44,23 +44,23 @@ namespace Hyena.Query
{
private List<QueryNode> children = new List<QueryNode>();
private Keyword keyword;
-
+
public QueryListNode(Keyword keyword) : base()
{
this.keyword = keyword;
}
-
+
public QueryListNode(Keyword keyword, QueryListNode parent) : base(parent)
{
this.keyword = keyword;
}
-
+
public void AddChild(QueryNode child)
{
child.Parent = this;
children.Add(child);
}
-
+
public void RemoveChild(QueryNode child)
{
child.Parent = null;
@@ -74,52 +74,52 @@ namespace Hyena.Query
}
from.Children.Clear ();
}
-
+
public void ReplaceChild(QueryNode old_child, QueryNode new_child)
{
int index = children.IndexOf(old_child);
if(index < 0) {
throw new ApplicationException("old_child does not exist");
}
-
+
children.RemoveAt(index);
children.Insert(index, new_child);
}
-
+
public void InsertChild(int index, QueryNode child)
{
child.Parent = this;
children.Insert(index, child);
}
-
+
public int IndexOfChild(QueryNode child)
{
return children.IndexOf(child);
}
-
+
internal override void Dump(int depth)
{
PrintIndent(depth);
Console.WriteLine("<{0}>", Keyword);
-
+
foreach(QueryNode child in children) {
child.Dump(depth + 1);
}
-
+
PrintIndent(depth);
Console.WriteLine("</{0}>", Keyword);
}
-
+
public QueryNode GetLeftSibling(QueryNode node)
{
int index = IndexOfChild(node);
if(index >= 1) {
return Children[index - 1];
}
-
+
return null;
}
-
+
public QueryNode GetRightSibling(QueryNode node)
{
int index = IndexOfChild(node);
@@ -228,15 +228,15 @@ namespace Hyena.Query
public bool IsEmpty {
get { return ChildCount == 0; }
}
-
+
public List<QueryNode> Children {
get { return children; }
}
-
+
public QueryNode LastChild {
get { return ChildCount > 0 ? children[ChildCount - 1] : null; }
}
-
+
public int ChildCount {
get { return children.Count; }
}
diff --git a/src/Hyena/Hyena.Query/QueryNode.cs b/src/Hyena/Hyena.Query/QueryNode.cs
index 59e8420..0634c8c 100644
--- a/src/Hyena/Hyena.Query/QueryNode.cs
+++ b/src/Hyena/Hyena.Query/QueryNode.cs
@@ -40,33 +40,33 @@ namespace Hyena.Query
DepthFirst,
BreadthFirst
}
-
+
public abstract class QueryNode
{
private QueryListNode parent;
private int source_column;
private int source_line;
-
+
public QueryNode()
{
}
-
+
public QueryNode(QueryListNode parent)
{
Parent = parent;
Parent.AddChild(this);
}
-
+
protected void PrintIndent(int depth)
{
Console.Write(String.Empty.PadLeft(depth * 2, ' '));
}
-
+
public void Dump()
{
Dump(0);
}
-
+
internal virtual void Dump(int depth)
{
PrintIndent(depth);
@@ -115,12 +115,12 @@ namespace Hyena.Query
}
}
}
-
+
public IEnumerable<T> SearchForValues<T> () where T : QueryValue
{
return SearchForValues<T> (QueryNodeSearchMethod.DepthFirst);
}
-
+
public IEnumerable<T> SearchForValues<T> (QueryNodeSearchMethod method) where T : QueryValue
{
if (method == QueryNodeSearchMethod.DepthFirst) {
@@ -129,7 +129,7 @@ namespace Hyena.Query
return SearchForValuesByBreadth<T> ();
}
}
-
+
private static IEnumerable<T> SearchForValuesByDepth<T> (QueryNode node) where T : QueryValue
{
QueryListNode list = node as QueryListNode;
@@ -149,7 +149,7 @@ namespace Hyena.Query
}
}
}
-
+
private IEnumerable<T> SearchForValuesByBreadth<T> () where T : QueryValue
{
Queue<QueryNode> queue = new Queue<QueryNode> ();
@@ -214,17 +214,17 @@ namespace Hyena.Query
}
public abstract void AppendSql (StringBuilder sb, QueryFieldSet fieldSet);
-
+
public QueryListNode Parent {
get { return parent; }
set { parent = value; }
}
-
+
public int SourceColumn {
get { return source_column; }
set { source_column = value; }
}
-
+
public int SourceLine {
get { return source_line; }
set { source_line = value; }
diff --git a/src/Hyena/Hyena.Query/QueryOperator.cs b/src/Hyena/Hyena.Query/QueryOperator.cs
index 644ee9b..db46ddb 100644
--- a/src/Hyena/Hyena.Query/QueryOperator.cs
+++ b/src/Hyena/Hyena.Query/QueryOperator.cs
@@ -66,7 +66,7 @@ namespace Hyena.Query
public bool IsNot {
get { return is_not; }
}
-
+
internal Operator (string name, string label, string sql_format, params string [] userOps) : this (name, label, sql_format, false, userOps)
{
}
diff --git a/src/Hyena/Hyena.Query/QueryParser.cs b/src/Hyena/Hyena.Query/QueryParser.cs
index 32a373a..97dd46e 100644
--- a/src/Hyena/Hyena.Query/QueryParser.cs
+++ b/src/Hyena/Hyena.Query/QueryParser.cs
@@ -36,7 +36,7 @@ namespace Hyena.Query
public abstract class QueryParser
{
protected StreamReader reader;
-
+
public QueryParser()
{
Reset ();
@@ -57,7 +57,7 @@ namespace Hyena.Query
public abstract QueryNode BuildTree (QueryFieldSet fieldSet);
public abstract void Reset ();
-
+
public StreamReader InputReader {
get { return reader; }
set { reader = value; }
diff --git a/src/Hyena/Hyena.Query/QueryTermNode.cs b/src/Hyena/Hyena.Query/QueryTermNode.cs
index 094d60f..42ff2ba 100644
--- a/src/Hyena/Hyena.Query/QueryTermNode.cs
+++ b/src/Hyena/Hyena.Query/QueryTermNode.cs
@@ -90,7 +90,7 @@ namespace Hyena.Query
}
return this;
}
-
+
public override void AppendUserQuery (StringBuilder sb)
{
sb.Append (Field == null ? Value.ToUserQuery () : Field.ToTermString (Operator.PrimaryAlias, Value.ToUserQuery ()));
@@ -118,13 +118,13 @@ namespace Hyena.Query
if (Field == null) {
sb.Append ("(");
int emitted = 0;
-
+
foreach (QueryField field in fieldSet.Fields) {
if (field.IsDefault)
if (EmitTermMatch (sb, field, emitted > 0))
emitted++;
}
-
+
sb.Append (")");
} else {
EmitTermMatch (sb, Field, false);
@@ -154,7 +154,7 @@ namespace Hyena.Query
get { return op; }
set { op = value; }
}
-
+
public QueryValue Value {
get { return qvalue; }
set { qvalue = value; }
diff --git a/src/Hyena/Hyena.Query/QueryToken.cs b/src/Hyena/Hyena.Query/QueryToken.cs
index e3fac84..aa7a363 100644
--- a/src/Hyena/Hyena.Query/QueryToken.cs
+++ b/src/Hyena/Hyena.Query/QueryToken.cs
@@ -40,7 +40,7 @@ namespace Hyena.Query
Range,
Term
}
-
+
public class QueryToken
{
private TokenID id;
diff --git a/src/Hyena/Hyena.Query/QueryValue.cs b/src/Hyena/Hyena.Query/QueryValue.cs
index a39e3ae..875517a 100644
--- a/src/Hyena/Hyena.Query/QueryValue.cs
+++ b/src/Hyena/Hyena.Query/QueryValue.cs
@@ -62,7 +62,7 @@ namespace Hyena.Query
return null;
}
-
+
public static QueryValue CreateFromStringValue (string input, QueryField field)
{
if (field == null) {
diff --git a/src/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs b/src/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs
index 772ef48..bd9d271 100644
--- a/src/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs
+++ b/src/Hyena/Hyena.Query/RelativeTimeSpanQueryValue.cs
@@ -50,7 +50,7 @@ namespace Hyena.Query
public override AliasedObjectSet<Operator> OperatorSet {
get { return operators; }
}
-
+
public static RelativeTimeSpanQueryValue RelativeToNow (DateTime since)
{
RelativeTimeSpanQueryValue qv = new RelativeTimeSpanQueryValue ();
diff --git a/src/Hyena/Hyena.Query/StringQueryValue.cs b/src/Hyena/Hyena.Query/StringQueryValue.cs
index 5e60d4a..a707283 100644
--- a/src/Hyena/Hyena.Query/StringQueryValue.cs
+++ b/src/Hyena/Hyena.Query/StringQueryValue.cs
@@ -94,7 +94,7 @@ namespace Hyena.Query
.Replace ("%", "\\%")
.Replace ("_", "\\_");
}
-
+
return orig;
}
}
diff --git a/src/Hyena/Hyena.Query/Tests/QueryTests.cs b/src/Hyena/Hyena.Query/Tests/QueryTests.cs
index 2302f3e..1421288 100644
--- a/src/Hyena/Hyena.Query/Tests/QueryTests.cs
+++ b/src/Hyena/Hyena.Query/Tests/QueryTests.cs
@@ -77,12 +77,12 @@ namespace Hyena.Query.Tests
public void QueryValueSql ()
{
QueryValue qv;
-
+
qv = new DateQueryValue (); qv.ParseUserQuery ("2007-03-9");
Assert.AreEqual (new DateTime (2007, 3, 9), qv.Value);
Assert.AreEqual ("2007-03-09", qv.ToUserQuery ());
Assert.AreEqual ("1173420000", qv.ToSql ());
-
+
qv = new StringQueryValue (); qv.ParseUserQuery ("foo 'bar'");
Assert.AreEqual ("foo 'bar'", qv.Value);
Assert.AreEqual ("foo 'bar'", qv.ToUserQuery ());
@@ -92,34 +92,34 @@ namespace Hyena.Query.Tests
Assert.AreEqual ("Foo Baño", qv.Value);
Assert.AreEqual ("Foo Baño", qv.ToUserQuery ());
Assert.AreEqual ("foo bano", qv.ToSql ());
-
+
qv = new ExactStringQueryValue (); qv.ParseUserQuery ("foo 'bar'");
Assert.AreEqual ("foo 'bar'", qv.Value);
Assert.AreEqual ("foo 'bar'", qv.ToUserQuery ());
Assert.AreEqual ("foo ''bar''", qv.ToSql ());
-
+
qv = new IntegerQueryValue (); qv.ParseUserQuery ("22");
Assert.AreEqual (22, qv.Value);
Assert.AreEqual ("22", qv.ToUserQuery ());
Assert.AreEqual ("22", qv.ToSql ());
-
+
qv = new FileSizeQueryValue (); qv.ParseUserQuery ("2048 KB");
Assert.AreEqual (2097152, qv.Value);
Assert.AreEqual ("2.048 KB", qv.ToUserQuery ());
Assert.AreEqual ("2097152", qv.ToSql ());
-
+
// TODO this will break once an it_IT translation for "days ago" etc is committed
qv = new RelativeTimeSpanQueryValue (); qv.ParseUserQuery ("2 days ago");
Assert.AreEqual (-172800, qv.Value);
Assert.AreEqual ("2 days ago", qv.ToUserQuery ());
-
+
// TODO this will break once an it_IT translation for "minutes" etc is committed
qv = new TimeSpanQueryValue (); qv.ParseUserQuery ("4 minutes");
Assert.AreEqual (240, qv.Value);
Assert.AreEqual ("4 minutes", qv.ToUserQuery ());
Assert.AreEqual ("240000", qv.ToSql ());
}
-
+
[Test]
public void QueryParsing ()
{
@@ -142,16 +142,16 @@ namespace Hyena.Query.Tests
"by:baz -on:bar",
"by:baz (plays>3 or plays<2)",
};
-
+
AssertForEach<string> (tests, UserQueryParsesAndGenerates);
}
-
+
[Test]
public void CustomFormatParenthesisBugFixed ()
{
QueryValue val = new StringQueryValue ();
val.ParseUserQuery ("mp3");
-
+
Assert.AreEqual (
"(CoreTracks.MimeType LIKE '%mp3%' ESCAPE '\\' OR CoreTracks.Uri LIKE '%mp3%' ESCAPE '\\')",
MimeTypeField.ToSql (StringQueryValue.Contains, val)
@@ -229,15 +229,15 @@ namespace Hyena.Query.Tests
Assert.IsNotNull (query_tree, "Query should parse");
Assert.AreEqual ("by==\"foo (disc 2)\"", query_tree.ToUserQuery ());
}
-
+
private static void UserQueryParsesAndGenerates (string query)
{
QueryNode node = UserQueryParser.Parse (query, FieldSet);
if (query == null || query.Trim () == String.Empty) {
- Assert.AreEqual (node, null);
+ Assert.AreEqual (node, null);
return;
}
-
+
Assert.AreEqual (query, node.ToUserQuery ());
}
}
diff --git a/src/Hyena/Hyena.Query/UserQueryParser.cs b/src/Hyena/Hyena.Query/UserQueryParser.cs
index 6d38233..ee7b49e 100644
--- a/src/Hyena/Hyena.Query/UserQueryParser.cs
+++ b/src/Hyena/Hyena.Query/UserQueryParser.cs
@@ -62,7 +62,7 @@ namespace Hyena.Query
field_set = fieldSet;
root = current_parent = new QueryListNode (Keyword.And);
bool last_was_term = false;
-
+
while (true) {
QueryToken token = Scan ();
@@ -72,7 +72,7 @@ namespace Hyena.Query
token.Column = token_start_column;
token.Line = token_start_line;
-
+
// If we have two terms in a row, put an AND between them
if (last_was_term && token.ID == TokenID.Term)
ParseToken (new QueryToken (TokenID.And));
@@ -84,19 +84,19 @@ namespace Hyena.Query
return root.Trim ();
}
-
+
private void DepthPush ()
{
current_parent = new QueryListNode (Keyword.And, current_parent);
}
-
+
private void DepthPop ()
{
// Avoid trying to pop more than is possible
if (current_parent.Parent != null)
current_parent = current_parent.Parent;
}
-
+
private void NodePush (QueryNode node)
{
if (current_parent == null && node is QueryListNode) {
@@ -115,7 +115,7 @@ namespace Hyena.Query
current_parent = list;
}
}
-
+
private void ParseToken (QueryToken token)
{
switch (token.ID) {
@@ -169,7 +169,7 @@ namespace Hyena.Query
else
eos_consumed = true;
}
-
+
for (; ; ReadChar ()) {
if (Char.IsWhiteSpace (peek) && peek != '\n') {
continue;
@@ -201,10 +201,10 @@ namespace Hyena.Query
if (reader.EndOfStream)
eos_consumed = true;
-
+
switch (token) {
- case "or":
- case "OR":
+ case "or":
+ case "OR":
return new QueryToken (TokenID.Or);
case "NOT":
return new QueryToken (TokenID.Not);
@@ -248,7 +248,7 @@ namespace Hyena.Query
break;
}
}
-
+
return buffer.ToString ();
}
@@ -266,7 +266,7 @@ namespace Hyena.Query
if (peek == Char.MinValue) {
return;
}
-
+
peek = (char)reader.Read ();
current_column++;
}
diff --git a/src/Hyena/Hyena.SExpEngine/ArithmeticFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/ArithmeticFunctionSet.cs
index 62414c8..3b92d77 100644
--- a/src/Hyena/Hyena.SExpEngine/ArithmeticFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/ArithmeticFunctionSet.cs
@@ -45,25 +45,25 @@ namespace Hyena.SExpEngine
{
double result = 0.0;
bool as_int = true;
-
+
for(int i = 0; i < args.Length; i++) {
TreeNode arg = Evaluate(args[i]);
-
+
if(arg is IntLiteral || arg is DoubleLiteral) {
double arg_value;
-
+
if(arg is DoubleLiteral) {
as_int = false;
arg_value = (arg as DoubleLiteral).Value;
} else {
arg_value = (int)(arg as IntLiteral).Value;
}
-
+
if(i == 0) {
result = arg_value;
continue;
}
-
+
switch(operation) {
case ArithmeticOperation.Add:
result += arg_value;
@@ -81,76 +81,76 @@ namespace Hyena.SExpEngine
if(!(arg is IntLiteral)) {
throw new ArgumentException("Modulo requires int arguments");
}
-
+
result %= (int)arg_value;
break;
- }
+ }
} else {
throw new ArgumentException("arguments must be double or int");
}
}
-
- return as_int ?
- ((TreeNode)new IntLiteral((int)result)) :
+
+ return as_int ?
+ ((TreeNode)new IntLiteral((int)result)) :
((TreeNode)new DoubleLiteral(result));
}
-
+
[Function("add", "+")]
public virtual TreeNode OnAdd(TreeNode [] args)
{
TreeNode first = Evaluate(args[0]);
-
+
if(first is StringLiteral) {
return StringFunctionSet.ConcatenateStrings(Evaluator, args);
}
-
+
return OnPerformArithmetic(args, ArithmeticOperation.Add);
}
-
+
[Function("sub", "-")]
public virtual TreeNode OnSubtract(TreeNode [] args)
{
return OnPerformArithmetic(args, ArithmeticOperation.Subtract);
}
-
+
[Function("mul", "*")]
public virtual TreeNode OnMultiply(TreeNode [] args)
{
return OnPerformArithmetic(args, ArithmeticOperation.Multiply);
}
-
+
[Function("div", "/")]
public virtual TreeNode OnDivide(TreeNode [] args)
{
return OnPerformArithmetic(args, ArithmeticOperation.Divide);
}
-
+
[Function("mod", "%")]
public virtual TreeNode OnModulo(TreeNode [] args)
{
return OnPerformArithmetic(args, ArithmeticOperation.Modulo);
}
-
+
[Function("++")]
public virtual TreeNode OnIncrement(TreeNode [] args)
{
return IntegerUpdate(args, 1);
}
-
+
[Function("--")]
public virtual TreeNode OnDecrement(TreeNode [] args)
{
return IntegerUpdate(args, -1);
}
-
+
private TreeNode IntegerUpdate(TreeNode [] args, int value)
{
TreeNode variable_node = (FunctionNode)args[0];
TreeNode result = Evaluate(variable_node);
TreeNode new_result = new IntLiteral(((IntLiteral)result).Value + value);
-
+
FunctionFunctionSet.VariableSet(Evaluator, args[0], new_result);
-
+
return new_result;
}
}
diff --git a/src/Hyena/Hyena.SExpEngine/CastFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/CastFunctionSet.cs
index 526db08..ba3063d 100644
--- a/src/Hyena/Hyena.SExpEngine/CastFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/CastFunctionSet.cs
@@ -37,8 +37,8 @@ namespace Hyena.SExpEngine
{
if(args.Length != 1) {
throw new ArgumentException("cast must have only one argument");
- }
-
+ }
+
TreeNode arg = Evaluate(args[0]);
if(arg is DoubleLiteral) {
@@ -47,34 +47,34 @@ namespace Hyena.SExpEngine
return new DoubleLiteral((int)(arg as IntLiteral).Value);
} else if(arg is StringLiteral) {
return new DoubleLiteral(Convert.ToDouble((arg as StringLiteral).Value));
- }
-
+ }
+
throw new ArgumentException("can only cast double, int, or string literals");
}
-
+
[Function("cast-int")]
public virtual TreeNode OnCastInt(TreeNode [] args)
{
DoubleLiteral result = (DoubleLiteral)OnCastDouble(args);
return new IntLiteral((int)result.Value);
}
-
+
[Function("cast-bool")]
public virtual TreeNode OnCastBool(TreeNode [] args)
{
DoubleLiteral result = (DoubleLiteral)OnCastDouble(args);
return new BooleanLiteral((int)result.Value != 0);
}
-
+
[Function("cast-string")]
public virtual TreeNode OnCastString(TreeNode [] args)
{
if(args.Length != 1) {
throw new ArgumentException("cast must have only one argument");
}
-
+
TreeNode arg = Evaluate(args[0]);
-
+
if(arg is DoubleLiteral) {
return new StringLiteral(Convert.ToString((arg as DoubleLiteral).Value));
} else if(arg is IntLiteral) {
@@ -82,7 +82,7 @@ namespace Hyena.SExpEngine
} else if(arg is StringLiteral) {
return arg;
}
-
+
throw new ArgumentException("can only cast double, int, or string literals");
}
}
diff --git a/src/Hyena/Hyena.SExpEngine/CompareFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/CompareFunctionSet.cs
index d6b8064..1c3adaf 100644
--- a/src/Hyena/Hyena.SExpEngine/CompareFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/CompareFunctionSet.cs
@@ -38,7 +38,7 @@ namespace Hyena.SExpEngine
if(args.Length != 2) {
throw new ArgumentException("must have two arguments");
}
-
+
return Compare(Evaluator, args[0], args[1]);
}
@@ -46,13 +46,13 @@ namespace Hyena.SExpEngine
{
TreeNode arg_a = evaluator.Evaluate(a);
TreeNode arg_b = evaluator.Evaluate(b);
-
+
if(arg_a.GetType() != arg_b.GetType()) {
throw new ArgumentException("arguments must be of the same type to compare");
}
-
+
int result = 0;
-
+
if(arg_a is IntLiteral) {
result = (arg_a as IntLiteral).Value.CompareTo(
(arg_b as IntLiteral).Value);
@@ -68,38 +68,38 @@ namespace Hyena.SExpEngine
} else {
throw new ArgumentException("invalid type for comparison");
}
-
+
return new IntLiteral(result);
}
-
+
[Function("less-than", "<")]
public virtual TreeNode OnCompareLessThan(TreeNode [] args)
{
IntLiteral result = (IntLiteral)OnCompareTo(args);
return new BooleanLiteral(result.Value < 0);
}
-
+
[Function("greater-than", ">")]
public virtual TreeNode OnCompareGreaterThan(TreeNode [] args)
{
IntLiteral result = (IntLiteral)OnCompareTo(args);
return new BooleanLiteral(result.Value > 0);
}
-
+
[Function("equal", "=")]
public virtual TreeNode OnCompareEqual(TreeNode [] args)
{
IntLiteral result = (IntLiteral)OnCompareTo(args);
return new BooleanLiteral(result.Value == 0);
}
-
+
[Function("not-equal", "!=")]
public virtual TreeNode OnCompareNotEqual(TreeNode [] args)
{
BooleanLiteral result = (BooleanLiteral)OnCompareEqual(args);
return new BooleanLiteral(!result.Value);
}
-
+
[Function("less-than-or-equal", "<=")]
public virtual TreeNode OnCompareLessThanOrEqual(TreeNode [] args)
{
@@ -107,7 +107,7 @@ namespace Hyena.SExpEngine
BooleanLiteral b = (BooleanLiteral)OnCompareEqual(args);
return new BooleanLiteral(a.Value || b.Value);
}
-
+
[Function("greater-than-or-equal", ">=")]
public virtual TreeNode OnCompareGreaterThanOrEqual(TreeNode [] args)
{
diff --git a/src/Hyena/Hyena.SExpEngine/ControlFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/ControlFunctionSet.cs
index b91de93..b803e7c 100644
--- a/src/Hyena/Hyena.SExpEngine/ControlFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/ControlFunctionSet.cs
@@ -37,43 +37,43 @@ namespace Hyena.SExpEngine
{
if(args == null || args.Length < 2 || args.Length > 3) {
throw new ArgumentException("if accepts 2 or 3 arguments");
- }
-
+ }
+
TreeNode arg = Evaluate(args[0]);
if(!(arg is BooleanLiteral)) {
throw new ArgumentException("first if argument must be boolean");
}
-
+
BooleanLiteral conditional = (BooleanLiteral)arg;
-
+
if(conditional.Value) {
return Evaluate(args[1]);
} else if(args.Length == 3) {
return Evaluate(args[2]);
}
-
+
return new VoidLiteral();
}
-
+
[Function("while")]
public virtual TreeNode OnWhile(TreeNode [] args)
{
if(args == null || args.Length < 1 || args.Length > 2) {
throw new ArgumentException("while accepts a condition and an expression or just an expression");
- }
-
+ }
+
while(true) {
if(args.Length == 2) {
TreeNode result = Evaluate(args[0]);
if(!(result is BooleanLiteral)) {
throw new ArgumentException("condition is not boolean");
}
-
+
if(!(result as BooleanLiteral).Value) {
break;
}
}
-
+
try {
Evaluate(args[args.Length - 1]);
} catch(Exception e) {
@@ -82,27 +82,27 @@ namespace Hyena.SExpEngine
}
}
}
-
+
return new VoidLiteral();
}
-
+
[Function("break")]
public virtual TreeNode OnBreak(TreeNode [] args)
{
throw new BreakException();
}
-
+
private class BreakException : Exception
{
public BreakException()
{
}
}
-
+
public static bool BreakHandler(Exception e)
{
Exception parent_e = e;
-
+
while(parent_e != null) {
if(parent_e is BreakException) {
return true;
@@ -110,7 +110,7 @@ namespace Hyena.SExpEngine
parent_e = parent_e.InnerException;
}
- throw e;
+ throw e;
}
}
}
diff --git a/src/Hyena/Hyena.SExpEngine/Evaluator.cs b/src/Hyena/Hyena.SExpEngine/Evaluator.cs
index 60a3014..294b0da 100644
--- a/src/Hyena/Hyena.SExpEngine/Evaluator.cs
+++ b/src/Hyena/Hyena.SExpEngine/Evaluator.cs
@@ -36,17 +36,17 @@ namespace Hyena.SExpEngine
{
RegisterFunctions();
}
-
+
public Evaluator(TreeNode expression) : base(expression)
{
RegisterFunctions();
}
-
+
public Evaluator(string expression) : base(expression)
{
RegisterFunctions();
}
-
+
private void RegisterFunctions()
{
RegisterFunctionSet(new ControlFunctionSet());
diff --git a/src/Hyena/Hyena.SExpEngine/EvaluatorBase.cs b/src/Hyena/Hyena.SExpEngine/EvaluatorBase.cs
index af80a7b..2076cdd 100644
--- a/src/Hyena/Hyena.SExpEngine/EvaluatorBase.cs
+++ b/src/Hyena/Hyena.SExpEngine/EvaluatorBase.cs
@@ -39,12 +39,12 @@ namespace Hyena.SExpEngine
public class EvaluationException : ApplicationException
{
public EvaluationException(TreeNode node, string token, Exception inner) : base(String.Format(
- "Evaluation exception at token `{0} ({1})' [{2},{3}]",
+ "Evaluation exception at token `{0} ({1})' [{2},{3}]",
node.GetType(), token, node.Line, node.Column), inner)
{
}
}
-
+
public class UnknownVariableException : ApplicationException
{
public UnknownVariableException(string var) : base(var)
@@ -60,171 +60,171 @@ namespace Hyena.SExpEngine
public MethodInfo MethodInfo;
public bool EvaluateVariables;
}
-
+
private TreeNode expression;
private TreeNode function_table_expression = new TreeNode();
-
+
private string input;
private Dictionary<string, object> functions = new Dictionary<string, object>();
private List<Exception> exceptions = new List<Exception>();
-
+
public EvaluatorBase()
{
expression = function_table_expression;
}
-
+
public EvaluatorBase(TreeNode expression)
{
this.expression = expression;
}
-
+
public EvaluatorBase(string input)
{
expression = function_table_expression;
this.input = input;
}
-
+
public void RegisterVariable(string name, string value)
{
expression.RegisterFunction(name, value);
}
-
+
public void RegisterVariable(string name, bool value)
{
expression.RegisterFunction(name, value);
}
-
+
public void RegisterVariable(string name, int value)
{
expression.RegisterFunction(name, value);
}
-
+
public void RegisterVariable(string name, double value)
{
expression.RegisterFunction(name, value);
}
-
+
public void RegisterVariable(string name, SExpVariableResolutionHandler value)
{
expression.RegisterFunction(name, value);
}
-
+
public void RegisterVariable(string name, TreeNode value)
{
expression.RegisterFunction(name, value);
}
-
+
public void RegisterFunction(SExpFunctionHandler handler, params string [] names)
{
foreach(string name in names) {
if(functions.ContainsKey(name)) {
functions.Remove(name);
}
-
+
functions.Add(name, handler);
}
}
-
+
public void RegisterFunction(object o, MethodInfo method, string [] names)
{
RegisterFunction(o, method, names, true);
}
-
+
public void RegisterFunction(object o, MethodInfo method, string [] names, bool evaluateVariables)
{
MethodInfoContainer container = new MethodInfoContainer();
container.MethodInfo = method;
container.Object = o;
container.EvaluateVariables = evaluateVariables;
-
+
foreach(string name in names) {
if(functions.ContainsKey(name)) {
functions.Remove(name);
}
-
+
functions.Add(name, container);
}
}
-
+
public void RegisterFunctionSet(FunctionSet functionSet)
{
functionSet.Load(this);
}
-
+
public TreeNode EvaluateTree(TreeNode expression)
{
this.expression = expression;
this.input = null;
return Evaluate();
}
-
+
public TreeNode EvaluateString(string input)
{
this.expression = null;
this.input = input;
return Evaluate();
}
-
+
public TreeNode Evaluate()
{
exceptions.Clear();
-
+
try {
if(expression == null) {
Parser parser = new Parser();
expression = parser.Parse(input);
expression.CopyFunctionsFrom(function_table_expression);
}
-
+
return Evaluate(expression);
- } catch(Exception e) {
+ } catch(Exception e) {
Exception next = e;
-
+
do {
if(next != null) {
exceptions.Add(next);
next = next.InnerException;
}
} while(next != null && next.InnerException != null);
-
+
if(next != null) {
exceptions.Add(next);
}
}
-
+
return null;
}
-
+
public TreeNode Evaluate(TreeNode node)
{
if(!node.HasChildren || node is FunctionNode) {
return EvaluateNode(node);
}
-
+
TreeNode final_result_node = new TreeNode();
-
+
foreach(TreeNode child_node in node.Children) {
TreeNode result_node = EvaluateNode(child_node);
-
+
if(result_node != null) {
final_result_node.AddChild(result_node);
}
-
+
if(child_node is FunctionNode) {
if(functions.ContainsKey((child_node as FunctionNode).Function)) {
break;
}
-
+
FunctionNode impl = ResolveFunction(child_node as FunctionNode);
if(impl != null && impl.RequiresArguments) {
break;
}
}
}
-
+
return final_result_node.ChildCount == 1 ? final_result_node.Children[0] : final_result_node;
}
-
+
private TreeNode EvaluateNode(TreeNode node)
{
TreeNode result_node = null;
@@ -237,25 +237,25 @@ namespace Hyena.SExpEngine
if(e is TargetInvocationException) {
ee = e.InnerException;
}
-
+
throw new EvaluationException(node, (node as FunctionNode).Function, ee);
}
} else if(node is LiteralNodeBase) {
result_node = node;
} else {
result_node = Evaluate(node);
- }
-
+ }
+
return result_node;
}
-
+
private TreeNode EvaluateFunction(FunctionNode node)
{
object handler = null;
-
+
TreeNode parent = node.Parent;
TreeNode [] args = null;
-
+
if(!functions.ContainsKey(node.Function)) {
handler = ResolveFunction(node);
if(handler == null) {
@@ -267,16 +267,16 @@ namespace Hyena.SExpEngine
if(parent.Children[0] == node) {
args = new TreeNode[parent.ChildCount - 1];
-
+
for(int i = 0; i < args.Length; i++) {
args[i] = parent.Children[i + 1];
-
+
if(handler is MethodInfoContainer && !(handler as MethodInfoContainer).EvaluateVariables) {
continue;
}
}
}
-
+
if(handler is FunctionNode) {
return (handler as FunctionNode).Evaluate(this, args);
} else if(handler is SExpFunctionHandler) {
@@ -293,39 +293,39 @@ namespace Hyena.SExpEngine
internal FunctionNode ResolveFunction(FunctionNode node)
{
TreeNode shift_node = node;
-
+
do {
if(shift_node.Functions.ContainsKey(node.Function)) {
return shift_node.Functions[node.Function];
}
-
+
shift_node = shift_node.Parent;
} while(shift_node != null);
-
+
return null;
}
-
+
public bool Success {
get { return exceptions.Count == 0; }
}
-
+
public TreeNode ExpressionTree {
get { return expression; }
}
-
+
public ReadOnlyCollection<Exception> Exceptions {
get { return new ReadOnlyCollection<Exception>(exceptions); }
}
-
+
public string ErrorMessage {
get {
if(exceptions.Count == 0) {
return null;
} else if(exceptions.Count >= 2) {
- return String.Format("{0}: {1}", exceptions[exceptions.Count - 2].Message,
+ return String.Format("{0}: {1}", exceptions[exceptions.Count - 2].Message,
exceptions[exceptions.Count - 1].Message);
}
-
+
return exceptions[0].Message;
}
}
diff --git a/src/Hyena/Hyena.SExpEngine/FunctionFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/FunctionFunctionSet.cs
index d7c7a5b..96a3ba6 100644
--- a/src/Hyena/Hyena.SExpEngine/FunctionFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/FunctionFunctionSet.cs
@@ -37,22 +37,22 @@ namespace Hyena.SExpEngine
{
return VariableSet(Evaluator, args, true);
}
-
+
public static TreeNode VariableSet(EvaluatorBase evaluator, TreeNode var, TreeNode value)
{
return VariableSet(evaluator, new TreeNode[] { var, value }, true);
}
-
+
public static TreeNode VariableSet(EvaluatorBase evaluator, TreeNode [] args, bool update)
{
if(args.Length != 2) {
throw new ArgumentException("must have two arguments");
}
-
+
if(!(args[0] is FunctionNode)) {
throw new ArgumentException("first argument must be a variable");
}
-
+
FunctionNode variable_node = evaluator.ResolveFunction(args[0] as FunctionNode);
if(variable_node != null) {
variable_node.Body = evaluator.Evaluate(args[1]);
@@ -62,38 +62,38 @@ namespace Hyena.SExpEngine
parent.RegisterFunction((args[0] as FunctionNode).Function, evaluator.Evaluate(args[1]));
}
-
+
return new VoidLiteral();
}
-
+
[Function(false, "define")]
public virtual TreeNode OnDefine(TreeNode [] args)
{
if(args.Length < 2 || args.Length > 3) {
throw new ArgumentException("define must have two or three arguments");
}
-
+
if(!(args[0] is FunctionNode)) {
throw new ArgumentException("first define argument must be a variable");
}
-
+
FunctionNode function = new FunctionNode((args[0] as FunctionNode).Function, args[args.Length - 1]);
-
+
if(args.Length == 3 && args[1].HasChildren) {
foreach(TreeNode function_arg in args[1].Children) {
if(!(function_arg is FunctionNode)) {
throw new ArgumentException("define function arguments must be variable tokens");
}
-
+
function.RegisterFunction((function_arg as FunctionNode).Function, new VoidLiteral());
}
}
-
+
TreeNode parent = args[0].Parent;
parent = parent.Parent ?? parent;
-
+
parent.RegisterFunction(function.Function, function);
-
+
return new VoidLiteral();
}
}
diff --git a/src/Hyena/Hyena.SExpEngine/FunctionNode.cs b/src/Hyena/Hyena.SExpEngine/FunctionNode.cs
index 0e7e40e..966be3c 100644
--- a/src/Hyena/Hyena.SExpEngine/FunctionNode.cs
+++ b/src/Hyena/Hyena.SExpEngine/FunctionNode.cs
@@ -47,7 +47,7 @@ namespace Hyena.SExpEngine
{
this.function = function;
}
-
+
public FunctionNode(string function, object body)
{
this.function = function;
@@ -57,32 +57,32 @@ namespace Hyena.SExpEngine
public TreeNode Evaluate(EvaluatorBase evaluator, TreeNode [] args)
{
if(args != null && args.Length != FunctionCount && RequiresArguments) {
- throw new ArgumentException("Function " + function + " takes "
+ throw new ArgumentException("Function " + function + " takes "
+ FunctionCount + " arguments, not " + args.Length);
}
-
+
if(args != null && RequiresArguments) {
int i = 0;
string [] names = new string[args.Length];
-
+
foreach(KeyValuePair<string, FunctionNode> var in Functions) {
names[i++] = var.Key;
}
-
+
for(i = 0; i < args.Length; i++) {
(body as TreeNode).RegisterFunction(names[i], evaluator.Evaluate(args[i]));
}
}
-
+
return evaluator.Evaluate(ResolveBody(evaluator));
}
-
+
private TreeNode ResolveBody(EvaluatorBase evaluator)
{
if(body == null) {
throw new UnknownVariableException(Function);
}
-
+
if(body is string) {
return new StringLiteral((string)body);
} else if(body is double) {
@@ -96,26 +96,26 @@ namespace Hyena.SExpEngine
} else if(body is TreeNode) {
return evaluator.Evaluate((TreeNode)body);
}
-
+
throw new UnknownVariableException(String.Format(
"Unknown function type `{0}' for function `{1}'",
body.GetType(), Function));
}
-
+
public override string ToString()
{
return Function;
}
-
+
internal object Body {
get { return body; }
set { body = value; }
}
-
+
internal bool RequiresArguments {
get { return FunctionCount > 0 && body is TreeNode; }
}
-
+
public string Function {
get { return function; }
}
diff --git a/src/Hyena/Hyena.SExpEngine/FunctionSet.cs b/src/Hyena/Hyena.SExpEngine/FunctionSet.cs
index 46798f8..97cb4ab 100644
--- a/src/Hyena/Hyena.SExpEngine/FunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/FunctionSet.cs
@@ -36,40 +36,40 @@ namespace Hyena.SExpEngine
{
private string [] names;
private bool evaluate_variables;
-
+
public FunctionAttribute(params string [] names)
{
this.evaluate_variables = true;
this.names = names;
}
-
+
public FunctionAttribute(bool evaluateVariables, params string [] names)
{
this.evaluate_variables = evaluateVariables;
this.names = names;
}
-
+
public string [] Names {
get { return names; }
}
-
+
public bool EvaluateVariables {
get { return evaluate_variables; }
}
}
-
+
public abstract class FunctionSet
{
private EvaluatorBase evaluator;
-
+
public void Load(EvaluatorBase evaluator)
{
this.evaluator = evaluator;
-
+
foreach(MethodInfo method in GetType().GetMethods()) {
string [] names = null;
bool evaluate_variables = true;
-
+
foreach(Attribute attr in method.GetCustomAttributes(false)) {
if(attr is FunctionAttribute) {
names = (attr as FunctionAttribute).Names;
@@ -77,20 +77,20 @@ namespace Hyena.SExpEngine
break;
}
}
-
+
if(names == null || names.Length == 0) {
continue;
}
-
+
evaluator.RegisterFunction(this, method, names, evaluate_variables);
}
}
-
+
public TreeNode Evaluate(TreeNode node)
{
return evaluator.Evaluate(node);
}
-
+
protected EvaluatorBase Evaluator {
get { return evaluator; }
}
diff --git a/src/Hyena/Hyena.SExpEngine/ListFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/ListFunctionSet.cs
index 1727a05..e834d02 100644
--- a/src/Hyena/Hyena.SExpEngine/ListFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/ListFunctionSet.cs
@@ -37,88 +37,88 @@ namespace Hyena.SExpEngine
// private TreeNode EvaluateList(TreeNode node)
// {
// TreeNode list = new TreeNode();
- //
+ //
// foreach(TreeNode child in node.Children) {
// list.AddChild(Evaluate(child));
// }
- //
+ //
// return list;
// }
-
+
private bool IsList(TreeNode node)
{
return !(node is LiteralNodeBase) && !(node is FunctionNode);
}
-
+
public void CheckList(TreeNode node)
{
if(!IsList(node)) {
throw new ArgumentException("argument must be a list");
}
}
-
+
[Function("is-list")]
public virtual TreeNode OnIsList(TreeNode [] args)
{
return new BooleanLiteral(IsList(args[0]));
}
-
+
[Function("item-at")]
public virtual TreeNode OnItemAt(TreeNode [] args)
{
TreeNode list = Evaluate(args[0]);
CheckList(list);
-
+
TreeNode node = Evaluate(args[1]);
int index = 0;
-
+
if(!(node is IntLiteral)) {
throw new ArgumentException("argument must be an index");
}
-
+
index = (node as IntLiteral).Value;
-
+
return Evaluate(list.Children[index]);
}
-
+
[Function("remove-at")]
public virtual TreeNode OnRemoveAt(TreeNode [] args)
{
TreeNode list = Evaluate(args[0]);
CheckList(list);
-
+
TreeNode node = Evaluate(args[1]);
int index = 0;
-
+
if(!(node is IntLiteral)) {
throw new ArgumentException("argument must be an index");
}
-
+
index = (node as IntLiteral).Value;
-
+
list.Children.RemoveAt(index);
-
+
return list;
}
-
+
[Function("remove")]
public virtual TreeNode OnRemove(TreeNode [] args)
{
TreeNode list = Evaluate(args[0]);
CheckList(list);
-
+
TreeNode node = Evaluate(args[1]);
-
+
foreach(TreeNode compare_node in list.Children) {
if(((IntLiteral)CompareFunctionSet.Compare(Evaluator, node, compare_node)).Value == 0) {
list.Children.Remove(compare_node);
break;
}
}
-
+
return list;
- }
-
+ }
+
[Function("append")]
public virtual TreeNode OnAppend(TreeNode [] args)
{
@@ -126,8 +126,8 @@ namespace Hyena.SExpEngine
CheckList(list);
list.Children.Add(Evaluate(args[1]));
return list;
- }
-
+ }
+
[Function("prepend")]
public virtual TreeNode OnPrepend(TreeNode [] args)
{
@@ -135,27 +135,27 @@ namespace Hyena.SExpEngine
CheckList(list);
list.Children.Insert(0, Evaluate(args[1]));
return list;
- }
-
+ }
+
[Function("insert")]
public virtual TreeNode OnInsert(TreeNode [] args)
{
TreeNode list = Evaluate(args[0]);
CheckList(list);
-
+
TreeNode node = Evaluate(args[1]);
int index = 0;
-
+
if(!(node is IntLiteral)) {
throw new ArgumentException("argument must be an index");
}
-
+
index = (node as IntLiteral).Value;
list.Children.Insert(index, Evaluate(args[2]));
-
+
return list;
}
-
+
[Function("foreach")]
public virtual TreeNode OnForeach(TreeNode [] args)
{
@@ -163,13 +163,13 @@ namespace Hyena.SExpEngine
CheckList(list);
FunctionNode item_variable = (FunctionNode)args[0];
TreeNode function = args[2];
-
+
TreeNode self = args[0].Parent.Children[0];
self.Parent.RegisterFunction(item_variable.Function, item_variable);
-
+
foreach(TreeNode child in list.Children) {
item_variable.Body = child;
-
+
try {
if(function is FunctionNode) {
FunctionNode function_impl = Evaluator.ResolveFunction(function as FunctionNode);
@@ -183,7 +183,7 @@ namespace Hyena.SExpEngine
}
}
}
-
+
return new VoidLiteral();
}
}
diff --git a/src/Hyena/Hyena.SExpEngine/Literals.cs b/src/Hyena/Hyena.SExpEngine/Literals.cs
index fb686d4..217b273 100644
--- a/src/Hyena/Hyena.SExpEngine/Literals.cs
+++ b/src/Hyena/Hyena.SExpEngine/Literals.cs
@@ -31,9 +31,9 @@ using System;
namespace Hyena.SExpEngine
{
public class LiteralNodeBase : TreeNode
- {
+ {
private Type type = null;
-
+
public Type EnclosedType {
get { return type ?? GetType(); }
set { type = value; }
@@ -43,18 +43,18 @@ namespace Hyena.SExpEngine
public class LiteralNode<T> : LiteralNodeBase
{
private T value;
-
+
public LiteralNode(T value)
{
this.value = value;
EnclosedType = typeof(T);
}
-
+
public override string ToString()
{
return Value.ToString();
}
-
+
public T Value {
get { return value; }
}
@@ -69,18 +69,18 @@ namespace Hyena.SExpEngine
return "void";
}
}
-
+
public class DoubleLiteral : LiteralNode<double>
{
private static System.Globalization.CultureInfo culture_info = new System.Globalization.CultureInfo("en-US");
-
+
public DoubleLiteral(double value) : base(value)
{
}
-
+
public override string ToString()
{
- return (Value - (int)Value) == 0.0
+ return (Value - (int)Value) == 0.0
? String.Format("{0}.0", Value.ToString(culture_info))
: Value.ToString(culture_info);
}
@@ -91,7 +91,7 @@ namespace Hyena.SExpEngine
public BooleanLiteral(bool value) : base(value)
{
}
-
+
public override string ToString()
{
return Value ? "true" : "false";
diff --git a/src/Hyena/Hyena.SExpEngine/LogicFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/LogicFunctionSet.cs
index 7f14cab..88c9b67 100644
--- a/src/Hyena/Hyena.SExpEngine/LogicFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/LogicFunctionSet.cs
@@ -38,56 +38,56 @@ namespace Hyena.SExpEngine
if(args.Length != 1) {
throw new ArgumentException("not must have only one argument");
}
-
+
TreeNode arg = Evaluate(args[0]);
-
+
if(!(arg is BooleanLiteral)) {
throw new ArgumentException("can only not a boolean");
}
-
+
return new BooleanLiteral(!(arg as BooleanLiteral).Value);
}
-
+
[Function("or", "|")]
public virtual TreeNode OnOr(TreeNode [] args)
{
return OnAndOr(args, false);
}
-
+
[Function("and", "|")]
public virtual TreeNode OnAnd(TreeNode [] args)
{
return OnAndOr(args, true);
}
-
+
private TreeNode OnAndOr(TreeNode [] args, bool and)
{
if(args.Length < 2) {
throw new ArgumentException("must have two or more boolean arguments");
}
-
+
bool result = false;
-
+
for(int i = 0; i < args.Length; i++) {
TreeNode node = Evaluate(args[i]);
if(!(node is BooleanLiteral)) {
throw new ArgumentException("arguments must be boolean");
}
-
+
BooleanLiteral arg = (BooleanLiteral)node;
-
+
if(i == 0) {
result = arg.Value;
continue;
}
-
+
if(and) {
result &= arg.Value;
} else {
result |= arg.Value;
}
}
-
+
return new BooleanLiteral(result);
}
}
diff --git a/src/Hyena/Hyena.SExpEngine/Parser.cs b/src/Hyena/Hyena.SExpEngine/Parser.cs
index 9aad1da..53939ab 100644
--- a/src/Hyena/Hyena.SExpEngine/Parser.cs
+++ b/src/Hyena/Hyena.SExpEngine/Parser.cs
@@ -47,89 +47,89 @@ namespace Hyena.SExpEngine
{
private static Regex number_regex = new Regex(@"^[-+]?(0x[\dA-Fa-f]+)?[\d]*\.?[\d]*([eE][-+]?[\d]+)?$");
private static System.Globalization.CultureInfo culture_info = new System.Globalization.CultureInfo("en-US");
-
+
private StreamReader reader;
private bool debug;
-
+
private StringBuilder current_token;
private TreeNode root_node ;
private TreeNode current_parent;
private int scope;
private int line;
private int column;
-
+
public Parser()
{
}
-
+
public TreeNode Parse(string input)
{
return Parse(new MemoryStream(Encoding.UTF8.GetBytes(input)));
}
-
+
public TreeNode Parse(Stream stream)
{
return Parse(new StreamReader(stream));
}
-
+
public TreeNode Parse(StreamReader reader)
{
this.reader = reader;
-
+
current_token = new StringBuilder();
root_node = new TreeNode();
current_parent = root_node;
scope = 0;
line = 1;
column = 0;
-
+
try {
Tokenize();
-
+
if(scope != 0) {
throw new ApplicationException("Scope does pop back to zero");
}
} catch(Exception e) {
throw new ParserException(current_token.ToString(), line, column, e);
}
-
+
return root_node;
}
-
+
private void Tokenize()
{
bool in_string = false;
bool in_comment = false;
-
+
while(true) {
int ich = reader.Read();
char ch = (char)ich;
-
+
if(ich < 0) {
break;
}
-
+
if(ch == '\n') {
line++;
column = 0;
} else {
column++;
}
-
+
if(in_comment) {
if(ch == '\r' || ch == '\n') {
in_comment = false;
}
-
+
continue;
}
-
+
switch(ch) {
case '(':
case ')':
if(!in_string) {
TokenPush(false);
-
+
if(ch == '(') {
ScopePush();
} else {
@@ -170,61 +170,61 @@ namespace Hyena.SExpEngine
} else {
current_token.Append(ch);
}
- break;
+ break;
}
}
-
+
TokenPush(false);
reader.Close();
}
-
+
private void ScopePush()
{
current_parent = new TreeNode(current_parent);
scope++;
}
-
+
private void ScopePop()
{
current_parent = current_parent.Parent;
scope--;
}
-
+
private void TokenPush(bool as_string)
{
if(current_token.Length == 0 && !as_string) {
return;
}
-
+
TreeNode node = null;
string token = current_token.ToString();
-
+
if(Debug) {
- Console.Write("{3}[{0}] TOKEN({4},{5}): [{2}{1}{2}]", scope, token,
+ Console.Write("{3}[{0}] TOKEN({4},{5}): [{2}{1}{2}]", scope, token,
as_string ? "\"" : String.Empty, String.Empty.PadLeft(scope - 1, ' '),
line, column - current_token.Length);
}
-
+
if(as_string) {
node = new StringLiteral(token);
} else if(token == "#t") {
node = new BooleanLiteral(true);
} else if(token == "#f") {
node = new BooleanLiteral(false);
- } else if(token.Length > 0 && token != "." && token != "-" &&
+ } else if(token.Length > 0 && token != "." && token != "-" &&
token != "+" && number_regex.IsMatch(token)) {
try {
if(token.StartsWith("0x") || token.StartsWith("-0x")) {
int offset = token[0] == '-' ? 3 : 2;
- int value = Int32.Parse(token.Substring(offset),
+ int value = Int32.Parse(token.Substring(offset),
NumberStyles.HexNumber, culture_info.NumberFormat);
node = new IntLiteral(value * (offset == 3 ? -1 : 1));
} else if(token.Contains(".")) {
- node = new DoubleLiteral(Double.Parse(token,
+ node = new DoubleLiteral(Double.Parse(token,
NumberStyles.Float, culture_info.NumberFormat));
} else {
- node = new IntLiteral(Int32.Parse(token,
+ node = new IntLiteral(Int32.Parse(token,
NumberStyles.Integer, culture_info.NumberFormat));
}
} catch {
@@ -233,7 +233,7 @@ namespace Hyena.SExpEngine
} else {
node = new FunctionNode(token);
}
-
+
if(Debug) {
Console.WriteLine(" => [{0}]", node);
}
@@ -241,10 +241,10 @@ namespace Hyena.SExpEngine
node.Line = line;
node.Column = column;
current_parent.AddChild(node);
-
+
current_token.Remove(0, current_token.Length);
}
-
+
public bool Debug {
get { return debug; }
set { debug = value; }
diff --git a/src/Hyena/Hyena.SExpEngine/StringFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/StringFunctionSet.cs
index 4821e8a..5b55791 100644
--- a/src/Hyena/Hyena.SExpEngine/StringFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/StringFunctionSet.cs
@@ -39,105 +39,105 @@ namespace Hyena.SExpEngine
{
return ConcatenateStrings(Evaluator, args);
}
-
+
public static TreeNode ConcatenateStrings(EvaluatorBase evaluator, TreeNode [] args)
{
StringBuilder result = new StringBuilder();
-
+
foreach(TreeNode arg in args) {
TreeNode eval_arg = evaluator.Evaluate(arg);
if(!(eval_arg is VoidLiteral)) {
result.Append(eval_arg);
}
}
-
+
return new StringLiteral(result.ToString());
}
-
+
private void CheckArgumentCount(TreeNode [] args, int expected)
{
CheckArgumentCount(args, expected, expected);
}
-
+
private void CheckArgumentCount(TreeNode [] args, int expected_min, int expected_max)
{
if(args.Length < expected_min || args.Length > expected_max) {
- throw new ArgumentException("expects " + expected_min + " <= args <= "
+ throw new ArgumentException("expects " + expected_min + " <= args <= "
+ expected_max + " arguments");
}
}
-
+
private string GetArgumentString(TreeNode [] args, int index)
{
TreeNode node = Evaluate(args[index]);
if(!(node is StringLiteral)) {
throw new ArgumentException("argument " + index + " must be a string");
}
-
+
return (node as StringLiteral).Value;
}
-
+
private int GetArgumentInteger(TreeNode [] args, int index)
{
TreeNode node = Evaluate(args[index]);
if(!(node is IntLiteral)) {
throw new ArgumentException("argument " + index + " must be an integer");
}
-
+
return (node as IntLiteral).Value;
}
-
+
[Function("length")]
public virtual TreeNode OnLength(TreeNode [] args)
{
CheckArgumentCount(args, 1);
-
+
TreeNode node = Evaluate(args[0]);
-
+
if(node is StringLiteral) {
return new IntLiteral((node as StringLiteral).Value.Length);
} else if(!(node is LiteralNodeBase) && !(node is FunctionNode)) {
return new IntLiteral(node.ChildCount);
}
-
+
return new IntLiteral(0);
- }
-
+ }
+
[Function("contains")]
public virtual TreeNode OnContains(TreeNode [] args)
{
CheckArgumentCount(args, 2);
return new BooleanLiteral(GetArgumentString(args, 0).Contains(GetArgumentString(args, 1)));
}
-
+
[Function("index-of")]
public virtual TreeNode OnIndexOf(TreeNode [] args)
{
CheckArgumentCount(args, 2);
return new IntLiteral(GetArgumentString(args, 0).IndexOf(GetArgumentString(args, 1)));
}
-
+
[Function("last-index-of")]
public virtual TreeNode OnLastIndexOf(TreeNode [] args)
{
CheckArgumentCount(args, 2);
return new IntLiteral(GetArgumentString(args, 0).LastIndexOf(GetArgumentString(args, 1)));
}
-
+
[Function("starts-with")]
public virtual TreeNode OnStartsWith(TreeNode [] args)
{
CheckArgumentCount(args, 2);
return new BooleanLiteral(GetArgumentString(args, 0).StartsWith(GetArgumentString(args, 1)));
}
-
+
[Function("ends-with")]
public virtual TreeNode OnEndsWith(TreeNode [] args)
{
CheckArgumentCount(args, 2);
return new BooleanLiteral(GetArgumentString(args, 0).EndsWith(GetArgumentString(args, 1)));
}
-
+
[Function("substring")]
public virtual TreeNode OnSubstring(TreeNode [] args)
{
@@ -149,23 +149,23 @@ namespace Hyena.SExpEngine
GetArgumentInteger(args, 1), GetArgumentInteger(args, 2)));
}
}
-
+
[Function("split")]
public virtual TreeNode OnSplit(TreeNode [] args)
{
CheckArgumentCount(args, 2);
-
+
TreeNode result = new TreeNode();
string str = GetArgumentString(args, 0);
string pattern = GetArgumentString(args, 1);
-
+
foreach(string item in Regex.Split(str, pattern)) {
result.AddChild(new StringLiteral(item));
}
-
+
return result;
}
-
+
[Function("trim")]
public virtual TreeNode OnTrim(TreeNode [] args)
{
diff --git a/src/Hyena/Hyena.SExpEngine/TreeNode.cs b/src/Hyena/Hyena.SExpEngine/TreeNode.cs
index c0cd73b..fd3bd88 100644
--- a/src/Hyena/Hyena.SExpEngine/TreeNode.cs
+++ b/src/Hyena/Hyena.SExpEngine/TreeNode.cs
@@ -39,7 +39,7 @@ namespace Hyena.SExpEngine
private TreeNode parent;
private int column;
private int line;
-
+
public TreeNode()
{
}
@@ -49,14 +49,14 @@ namespace Hyena.SExpEngine
this.parent = parent;
parent.AddChild(this);
}
-
+
internal void CopyFunctionsFrom(TreeNode node)
{
foreach(KeyValuePair<string, FunctionNode> function in node.Functions) {
RegisterFunction(function.Key, function.Value);
}
}
-
+
internal void RegisterFunction(string name, object value)
{
if(functions.ContainsKey(name)) {
@@ -65,7 +65,7 @@ namespace Hyena.SExpEngine
functions.Add(name, new FunctionNode(name, value));
}
}
-
+
internal void RegisterFunction(string name, FunctionNode function)
{
if(functions.ContainsKey(name)) {
@@ -74,26 +74,26 @@ namespace Hyena.SExpEngine
functions.Add(name, function);
}
}
-
+
public TreeNode Flatten()
{
TreeNode result_node = new TreeNode();
Flatten(result_node, this);
-
- return result_node.ChildCount == 1 ? result_node.Children[0] : result_node;
+
+ return result_node.ChildCount == 1 ? result_node.Children[0] : result_node;
}
-
+
private void Flatten(TreeNode result_node, TreeNode node)
{
if(node == null) {
return;
}
-
+
if(!node.HasChildren && !(node is VoidLiteral)) {
result_node.AddChild(node);
return;
}
-
+
foreach(TreeNode child_node in node.Children) {
Flatten(result_node, child_node);
}
@@ -103,7 +103,7 @@ namespace Hyena.SExpEngine
{
child.Parent = this;
children.Add(child);
- }
+ }
public TreeNode Parent {
get { return parent; }
@@ -113,16 +113,16 @@ namespace Hyena.SExpEngine
public int ChildCount {
get { return children.Count; }
}
-
+
public bool HasChildren {
get { return ChildCount > 0; }
}
-
+
public int Line {
get { return line; }
set { line = value; }
}
-
+
public int Column {
get { return column; }
set { column = value; }
@@ -135,28 +135,28 @@ namespace Hyena.SExpEngine
public IDictionary<string, FunctionNode> Functions {
get { return functions; }
}
-
+
public int FunctionCount {
get { return functions.Count; }
}
-
+
public bool Empty {
get { return ChildCount == 0 && !(this is LiteralNodeBase) && !(this is FunctionNode); }
}
-
+
public void Dump()
{
DumpTree(this);
}
-
+
public TreeNode FindRootNode()
{
TreeNode shift_node = this;
-
+
while(shift_node.Parent != null) {
shift_node = shift_node.Parent;
}
-
+
return shift_node;
}
diff --git a/src/Hyena/Hyena.SExpEngine/UtilityFunctionSet.cs b/src/Hyena/Hyena.SExpEngine/UtilityFunctionSet.cs
index 802fcf5..cf576b8 100644
--- a/src/Hyena/Hyena.SExpEngine/UtilityFunctionSet.cs
+++ b/src/Hyena/Hyena.SExpEngine/UtilityFunctionSet.cs
@@ -37,32 +37,32 @@ namespace Hyena.SExpEngine
{
if(args.Length != 1) {
throw new ArgumentException("print must have only one argument");
- }
-
+ }
+
Console.WriteLine(Evaluate(args[0]));
-
+
return new VoidLiteral();
}
-
+
[Function("print-type")]
public virtual TreeNode OnPrintType(TreeNode [] args)
{
if(args.Length != 1) {
throw new ArgumentException("print-type must have only one argument");
- }
-
+ }
+
Console.WriteLine(Evaluate(args[0]).GetType());
-
+
return new VoidLiteral();
}
-
+
[Function("dump")]
public virtual TreeNode OnDump(TreeNode [] args)
{
foreach(TreeNode arg in args) {
Evaluate(arg).Dump();
}
-
+
return new VoidLiteral();
}
}
diff --git a/src/Hyena/Hyena/ApplicationContext.cs b/src/Hyena/Hyena/ApplicationContext.cs
index 9085f19..dcae020 100644
--- a/src/Hyena/Hyena/ApplicationContext.cs
+++ b/src/Hyena/Hyena/ApplicationContext.cs
@@ -38,23 +38,23 @@ namespace Hyena
public static class ApplicationContext
{
- static ApplicationContext ()
+ static ApplicationContext ()
{
Log.Debugging = Debugging;
}
-
+
private static CommandLineParser command_line = new CommandLineParser ();
public static CommandLineParser CommandLine {
set { command_line = value; }
get { return command_line; }
}
-
+
private static Layout command_line_layout;
public static Layout CommandLineLayout {
get { return command_line_layout; }
set { command_line_layout = value; }
}
-
+
private static bool? debugging = null;
public static bool Debugging {
get {
@@ -63,23 +63,23 @@ namespace Hyena
debugging |= CommandLine.Contains ("debug-sql");
debugging |= EnvironmentIsSet ("BANSHEE_DEBUG");
}
-
+
return debugging.Value;
}
}
-
+
public static bool EnvironmentIsSet (string env)
{
return !String.IsNullOrEmpty (Environment.GetEnvironmentVariable (env));
}
-
+
public static System.Globalization.CultureInfo InternalCultureInfo {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
[DllImport ("libc")] // Linux
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
-
+
[DllImport ("libc")] // BSD
private static extern void setproctitle (byte [] fmt, byte [] str_arg);
@@ -88,19 +88,19 @@ namespace Hyena
if (Environment.OSVersion.Platform != PlatformID.Unix) {
return;
}
-
+
try {
- if (prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"),
+ if (prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"),
IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
- throw new ApplicationException ("Error setting process name: " +
+ throw new ApplicationException ("Error setting process name: " +
Mono.Unix.Native.Stdlib.GetLastError ());
}
} catch (EntryPointNotFoundException) {
- setproctitle (Encoding.ASCII.GetBytes ("%s\0"),
+ setproctitle (Encoding.ASCII.GetBytes ("%s\0"),
Encoding.ASCII.GetBytes (name + "\0"));
}
}
-
+
public static void TrySetProcessName (string name)
{
try {
diff --git a/src/Hyena/Hyena/ConsoleCrayon.cs b/src/Hyena/Hyena/ConsoleCrayon.cs
index 5d62b0b..c55dcd3 100644
--- a/src/Hyena/Hyena/ConsoleCrayon.cs
+++ b/src/Hyena/Hyena/ConsoleCrayon.cs
@@ -87,7 +87,7 @@ namespace Hyena
// License: MIT/X11
// Authors: Gonzalo Paniagua Javier <gonzalo ximian com>
// (C) 2005-2006 Novell, Inc <http://www.novell.com>
-
+
private static int TranslateColor (ConsoleColor desired, out bool light)
{
light = false;
@@ -113,7 +113,7 @@ namespace Hyena
case ConsoleColor.White: default: light = true; return 7;
}
}
-
+
private static string GetAnsiColorControlCode (ConsoleColor color, bool isForeground)
{
// lighter fg colours are 90 -> 97 rather than 30 -> 37
@@ -133,7 +133,7 @@ namespace Hyena
#region xterm Detection
private static bool? xterm_colors = null;
- public static bool XtermColors {
+ public static bool XtermColors {
get {
if (xterm_colors == null) {
DetectXtermColors ();
@@ -145,7 +145,7 @@ namespace Hyena
[System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
private extern static int _isatty (int fd);
-
+
private static bool isatty (int fd)
{
try {
@@ -158,11 +158,11 @@ namespace Hyena
private static void DetectXtermColors ()
{
bool _xterm_colors = false;
-
+
switch (Environment.GetEnvironmentVariable ("TERM")) {
case "xterm":
case "rxvt":
- case "rxvt-unicode":
+ case "rxvt-unicode":
if (Environment.GetEnvironmentVariable ("COLORTERM") != null) {
_xterm_colors = true;
}
@@ -181,7 +181,7 @@ namespace Hyena
private static bool? runtime_is_mono;
public static bool RuntimeIsMono {
- get {
+ get {
if (runtime_is_mono == null) {
runtime_is_mono = Type.GetType ("System.MonoType") != null;
}
diff --git a/src/Hyena/Hyena/CryptoUtil.cs b/src/Hyena/Hyena/CryptoUtil.cs
index 2d07e43..b8fefe4 100644
--- a/src/Hyena/Hyena/CryptoUtil.cs
+++ b/src/Hyena/Hyena/CryptoUtil.cs
@@ -43,12 +43,12 @@ namespace Hyena
{
return text == null || text.Length != 32 ? false : md5_regex.IsMatch (text);
}
-
+
public static string Md5Encode (string text)
{
return Md5Encode (text, Encoding.ASCII);
}
-
+
public static string Md5Encode (string text, Encoding encoding)
{
if (String.IsNullOrEmpty (text)) {
diff --git a/src/Hyena/Hyena/DateTimeUtil.cs b/src/Hyena/Hyena/DateTimeUtil.cs
index e533c28..ae1bff1 100644
--- a/src/Hyena/Hyena/DateTimeUtil.cs
+++ b/src/Hyena/Hyena/DateTimeUtil.cs
@@ -61,13 +61,13 @@ namespace Hyena
public static string FormatDuration (long time) {
return FormatDuration (TimeSpan.FromSeconds (time));
}
-
+
public static string FormatDuration (TimeSpan time) {
return FormatDuration (time.Hours, time.Minutes, time.Seconds);
}
-
+
public static string FormatDuration (int hours, int minutes, int seconds) {
- return (hours > 0 ?
+ return (hours > 0 ?
String.Format ("{0}:{1:00}:{2:00}", hours, minutes, seconds) :
String.Format ("{0}:{1:00}", minutes, seconds));
}
diff --git a/src/Hyena/Hyena/Log.cs b/src/Hyena/Hyena/Log.cs
index 836ae29..6dea20c 100644
--- a/src/Hyena/Hyena/Log.cs
+++ b/src/Hyena/Hyena/Log.cs
@@ -37,17 +37,17 @@ namespace Hyena
public class LogNotifyArgs : EventArgs
{
private LogEntry entry;
-
+
public LogNotifyArgs (LogEntry entry)
{
this.entry = entry;
}
-
+
public LogEntry Entry {
get { return entry; }
}
}
-
+
public enum LogEntryType
{
Debug,
@@ -55,14 +55,14 @@ namespace Hyena
Error,
Information
}
-
+
public class LogEntry
{
private LogEntryType type;
private string message;
private string details;
private DateTime timestamp;
-
+
internal LogEntry (LogEntryType type, string message, string details)
{
this.type = type;
@@ -71,27 +71,27 @@ namespace Hyena
this.timestamp = DateTime.Now;
}
- public LogEntryType Type {
+ public LogEntryType Type {
get { return type; }
}
-
- public string Message {
- get { return message; }
+
+ public string Message {
+ get { return message; }
}
-
- public string Details {
- get { return details; }
+
+ public string Details {
+ get { return details; }
}
- public DateTime TimeStamp {
- get { return timestamp; }
+ public DateTime TimeStamp {
+ get { return timestamp; }
}
}
-
+
public static class Log
{
public static event LogNotifyHandler Notify;
-
+
private static Dictionary<uint, DateTime> timers = new Dictionary<uint, DateTime> ();
private static uint next_timer_id = 1;
@@ -100,13 +100,13 @@ namespace Hyena
get { return debugging; }
set { debugging = value; }
}
-
+
public static void Commit (LogEntryType type, string message, string details, bool showUser)
{
if (type == LogEntryType.Debug && !Debugging) {
return;
}
-
+
if (type != LogEntryType.Information || (type == LogEntryType.Information && !showUser)) {
switch (type) {
case LogEntryType.Error: ConsoleCrayon.ForegroundColor = ConsoleColor.Red; break;
@@ -114,19 +114,19 @@ namespace Hyena
case LogEntryType.Information: ConsoleCrayon.ForegroundColor = ConsoleColor.Green; break;
case LogEntryType.Debug: ConsoleCrayon.ForegroundColor = ConsoleColor.Blue; break;
}
-
+
Console.Write ("[{0} {1:00}:{2:00}:{3:00}.{4:000}]", TypeString (type), DateTime.Now.Hour,
DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
-
+
ConsoleCrayon.ResetColor ();
-
+
if (details != null) {
Console.WriteLine (" {0} - {1}", message, details);
} else {
Console.WriteLine (" {0}", message);
}
}
-
+
if (showUser) {
OnNotify (new LogEntry (type, message, details));
}
@@ -142,7 +142,7 @@ namespace Hyena
}
return null;
}
-
+
private static void OnNotify (LogEntry entry)
{
LogNotifyHandler handler = Notify;
@@ -150,95 +150,95 @@ namespace Hyena
handler (new LogNotifyArgs (entry));
}
}
-
+
#region Timer Methods
-
+
public static uint DebugTimerStart (string message)
{
return TimerStart (message, false);
}
-
+
public static uint InformationTimerStart (string message)
{
return TimerStart (message, true);
}
-
+
private static uint TimerStart (string message, bool isInfo)
{
if (!Debugging && !isInfo) {
return 0;
}
-
+
if (isInfo) {
Information (message);
} else {
Debug (message);
}
-
+
return TimerStart (isInfo);
}
-
+
public static uint DebugTimerStart ()
{
return TimerStart (false);
}
-
+
public static uint InformationTimerStart ()
{
return TimerStart (true);
}
-
+
private static uint TimerStart (bool isInfo)
{
if (!Debugging && !isInfo) {
return 0;
}
-
+
uint timer_id = next_timer_id++;
timers.Add (timer_id, DateTime.Now);
return timer_id;
}
-
+
public static void DebugTimerPrint (uint id)
{
if (!Debugging) {
return;
}
-
+
TimerPrint (id, "Operation duration: {0}", false);
}
-
+
public static void DebugTimerPrint (uint id, string message)
{
if (!Debugging) {
return;
}
-
+
TimerPrint (id, message, false);
}
-
+
public static void InformationTimerPrint (uint id)
{
TimerPrint (id, "Operation duration: {0}", true);
}
-
+
public static void InformationTimerPrint (uint id, string message)
{
TimerPrint (id, message, true);
}
-
+
private static void TimerPrint (uint id, string message, bool isInfo)
{
if (!Debugging && !isInfo) {
return;
}
-
+
DateTime finish = DateTime.Now;
-
+
if (!timers.ContainsKey (id)) {
return;
}
-
+
TimeSpan duration = finish - timers[id];
string d_message;
if (duration.TotalSeconds < 60) {
@@ -246,116 +246,116 @@ namespace Hyena
} else {
d_message = duration.ToString ();
}
-
+
if (isInfo) {
InformationFormat (message, d_message);
} else {
DebugFormat (message, d_message);
}
}
-
+
#endregion
-
+
#region Public Debug Methods
-
+
public static void Debug (string message, string details)
{
if (Debugging) {
Commit (LogEntryType.Debug, message, details, false);
}
}
-
+
public static void Debug (string message)
{
if (Debugging) {
Debug (message, null);
}
}
-
+
public static void DebugFormat (string format, params object [] args)
{
if (Debugging) {
Debug (String.Format (format, args));
}
}
-
+
#endregion
-
+
#region Public Information Methods
-
+
public static void Information (string message)
{
Information (message, null);
}
-
+
public static void Information (string message, string details)
{
Information (message, details, false);
}
-
+
public static void Information (string message, string details, bool showUser)
{
Commit (LogEntryType.Information, message, details, showUser);
}
-
+
public static void Information (string message, bool showUser)
{
Information (message, null, showUser);
}
-
+
public static void InformationFormat (string format, params object [] args)
{
Information (String.Format (format, args));
}
-
+
#endregion
-
+
#region Public Warning Methods
-
+
public static void Warning (string message)
{
Warning (message, null);
}
-
+
public static void Warning (string message, string details)
{
Warning (message, details, false);
}
-
+
public static void Warning (string message, string details, bool showUser)
{
Commit (LogEntryType.Warning, message, details, showUser);
}
-
+
public static void Warning (string message, bool showUser)
{
Warning (message, null, showUser);
}
-
+
public static void WarningFormat (string format, params object [] args)
{
Warning (String.Format (format, args));
}
-
+
#endregion
-
+
#region Public Error Methods
-
+
public static void Error (string message)
{
Error (message, null);
}
-
+
public static void Error (string message, string details)
{
Error (message, details, false);
}
-
+
public static void Error (string message, string details, bool showUser)
{
Commit (LogEntryType.Error, message, details, showUser);
}
-
+
public static void Error (string message, bool showUser)
{
Error (message, null, showUser);
@@ -365,11 +365,11 @@ namespace Hyena
{
Error (String.Format (format, args));
}
-
+
#endregion
-
+
#region Public Exception Methods
-
+
public static void DebugException (Exception e)
{
if (Debugging) {
@@ -381,17 +381,17 @@ namespace Hyena
{
Exception (null, e);
}
-
+
public static void Exception (string message, Exception e)
{
Stack<Exception> exception_chain = new Stack<Exception> ();
StringBuilder builder = new StringBuilder ();
-
+
while (e != null) {
exception_chain.Push (e);
e = e.InnerException;
}
-
+
while (exception_chain.Count > 0) {
e = exception_chain.Pop ();
builder.AppendFormat ("{0} (in `{1}')", e.Message, e.Source).AppendLine ();
@@ -400,11 +400,11 @@ namespace Hyena
builder.AppendLine ();
}
}
-
+
// FIXME: We should save these to an actual log file
Log.Warning (message ?? "Caught an exception", builder.ToString (), false);
}
-
+
#endregion
}
}
diff --git a/src/Hyena/Hyena/PlatformUtil.cs b/src/Hyena/Hyena/PlatformUtil.cs
index 9ff0f1d..2af4a2f 100644
--- a/src/Hyena/Hyena/PlatformUtil.cs
+++ b/src/Hyena/Hyena/PlatformUtil.cs
@@ -1,4 +1,4 @@
-//
+//
// PlatformUtil.cs
//
// Author:
diff --git a/src/Hyena/Hyena/StringUtil.cs b/src/Hyena/Hyena/StringUtil.cs
index d48f73d..a4d44db 100644
--- a/src/Hyena/Hyena/StringUtil.cs
+++ b/src/Hyena/Hyena/StringUtil.cs
@@ -34,10 +34,10 @@ using System.Globalization;
using System.Text.RegularExpressions;
namespace Hyena
-{
+{
public static class StringUtil
{
- private static CompareOptions compare_options =
+ private static CompareOptions compare_options =
CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace |
CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
@@ -45,7 +45,7 @@ namespace Hyena
{
return CultureInfo.CurrentCulture.CompareInfo.IndexOf (haystack, needle, compare_options);
}
-
+
public static int RelaxedCompare (string a, string b)
{
if (a == null && b == null) {
@@ -55,29 +55,29 @@ namespace Hyena
} else if (a == null && b != null) {
return -1;
}
-
+
int a_offset = a.StartsWith ("the ") ? 4 : 0;
int b_offset = b.StartsWith ("the ") ? 4 : 0;
- return CultureInfo.CurrentCulture.CompareInfo.Compare (a, a_offset, a.Length - a_offset,
+ return CultureInfo.CurrentCulture.CompareInfo.Compare (a, a_offset, a.Length - a_offset,
b, b_offset, b.Length - b_offset, compare_options);
}
-
+
public static string CamelCaseToUnderCase (string s)
{
return CamelCaseToUnderCase (s, '_');
}
-
+
private static Regex camelcase = new Regex ("([A-Z]{1}[a-z]+)", RegexOptions.Compiled);
public static string CamelCaseToUnderCase (string s, char underscore)
{
if (String.IsNullOrEmpty (s)) {
return null;
}
-
+
StringBuilder undercase = new StringBuilder ();
string [] tokens = camelcase.Split (s);
-
+
for (int i = 0; i < tokens.Length; i++) {
if (tokens[i] == String.Empty) {
continue;
@@ -88,7 +88,7 @@ namespace Hyena
undercase.Append (underscore);
}
}
-
+
return undercase.ToString ();
}
@@ -143,7 +143,7 @@ namespace Hyena
{
return DoubleToTenthsPrecision (num, false);
}
-
+
public static string DoubleToTenthsPrecision (double num, bool always_decimal)
{
return DoubleToTenthsPrecision (num, always_decimal, NumberFormatInfo.CurrentInfo);
@@ -154,7 +154,7 @@ namespace Hyena
num = Math.Round (num, 1, MidpointRounding.ToEven);
return String.Format (provider, !always_decimal && num == (int)num ? "{0:N0}" : "{0:N1}", num);
}
-
+
// This method helps us pluralize doubles. Probably a horrible i18n idea.
public static int DoubleToPluralInt (double num)
{
@@ -163,7 +163,7 @@ namespace Hyena
else
return (int)num + 1;
}
-
+
// A mapping of non-Latin characters to be considered the same as
// a Latin equivalent.
private static Dictionary<char, char> BuildSpecialCases ()
@@ -174,24 +174,24 @@ namespace Hyena
return dict;
}
private static Dictionary<char, char> searchkey_special_cases = BuildSpecialCases ();
-
+
// Removes accents from Latin characters, and some kinds of punctuation.
public static string SearchKey (string val)
{
if (String.IsNullOrEmpty (val)) {
return val;
}
-
+
val = val.ToLower ();
StringBuilder sb = new StringBuilder ();
UnicodeCategory category;
bool previous_was_latin = false;
bool got_space = false;
-
+
// Normalizing to KD splits into (base, combining) so we can check for Latin
// characters and then strip off any NonSpacingMarks following them
foreach (char orig_c in val.TrimStart ().Normalize (NormalizationForm.FormKD)) {
-
+
// Check for a special case *before* whitespace. This way, if
// a special case is ever added that maps to ' ' or '\t', it
// won't cause a run of whitespace in the result.
@@ -199,12 +199,12 @@ namespace Hyena
if (searchkey_special_cases.ContainsKey (c)) {
c = searchkey_special_cases[c];
}
-
+
if (c == ' ' || c == '\t') {
got_space = true;
continue;
}
-
+
category = Char.GetUnicodeCategory (c);
if (category == UnicodeCategory.OtherPunctuation) {
// Skip punctuation
@@ -215,14 +215,14 @@ namespace Hyena
}
sb.Append (c);
}
-
+
// Can ignore A-Z because we've already lowercased the char
previous_was_latin = (c >= 'a' && c <= 'z');
}
-
+
return sb.ToString ().Normalize (NormalizationForm.FormKC);
}
-
+
private static Regex invalid_path_regex = BuildInvalidPathRegex ();
private static Regex BuildInvalidPathRegex ()
@@ -234,7 +234,7 @@ namespace Hyena
'\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F',
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
'\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F',
-
+
// Invalid in FAT32 / NTFS: " \ / : * | ? < >
// Invalid in HFS :
// Invalid in ext3 /
@@ -246,10 +246,10 @@ namespace Hyena
regex_str += "\\" + invalid_path_characters[i];
}
regex_str += "]+";
-
+
return new Regex (regex_str, RegexOptions.Compiled);
}
-
+
private static CompareInfo culture_compare_info = CultureInfo.CurrentCulture.CompareInfo;
public static byte[] SortKey (string orig)
{
@@ -262,7 +262,7 @@ namespace Hyena
{
if (input == null)
return "";
-
+
// Remove leading and trailing dots and spaces.
input = input.Trim (escape_path_trim_chars);
@@ -297,19 +297,19 @@ namespace Hyena
return builder.ToString ();
}
-
+
public static string MaybeFallback (string input, string fallback)
{
string trimmed = input == null ? null : input.Trim ();
return String.IsNullOrEmpty (trimmed) ? fallback : trimmed;
}
-
+
public static uint SubstringCount (string haystack, string needle)
{
if (String.IsNullOrEmpty (haystack) || String.IsNullOrEmpty (needle)) {
return 0;
}
-
+
int position = 0;
uint count = 0;
while (true) {
diff --git a/src/Hyena/Hyena/Tests/CryptoUtilTests.cs b/src/Hyena/Hyena/Tests/CryptoUtilTests.cs
index a03b1ac..27866ba 100644
--- a/src/Hyena/Hyena/Tests/CryptoUtilTests.cs
+++ b/src/Hyena/Hyena/Tests/CryptoUtilTests.cs
@@ -44,7 +44,7 @@ namespace Hyena.Tests
Assert.AreEqual ("", CryptoUtil.Md5Encode (null));
Assert.AreEqual ("", CryptoUtil.Md5Encode (""));
}
-
+
[Test]
public void IsMd5Encoded ()
{
diff --git a/src/Hyena/Hyena/Tests/StringUtilTests.cs b/src/Hyena/Hyena/Tests/StringUtilTests.cs
index bf567fe..de38010 100644
--- a/src/Hyena/Hyena/Tests/StringUtilTests.cs
+++ b/src/Hyena/Hyena/Tests/StringUtilTests.cs
@@ -33,7 +33,7 @@ using System;
using System.IO;
using NUnit.Framework;
using Hyena;
-
+
namespace Hyena.Tests
{
[TestFixture]
@@ -46,11 +46,11 @@ namespace Hyena.Tests
Camel = camel;
Under = under;
}
-
+
public string Camel;
public string Under;
}
-
+
private Map [] u_to_c_maps = new Map [] {
new Map ("Hello", "hello"),
new Map ("HelloWorld", "hello_world"),
@@ -64,7 +64,7 @@ namespace Hyena.Tests
new Map (null, ""),
new Map ("H", "h")
};
-
+
[Test]
public void UnderCaseToCamelCase ()
{
@@ -72,7 +72,7 @@ namespace Hyena.Tests
Assert.AreEqual (map.Camel, StringUtil.UnderCaseToCamelCase (map.Under));
}
}
-
+
private Map [] c_to_u_maps = new Map [] {
new Map ("Hello", "hello"),
new Map ("HelloWorld", "hello_world"),
@@ -84,7 +84,7 @@ namespace Hyena.Tests
new Map ("", null),
new Map ("H", "h")
};
-
+
[Test]
public void CamelCaseToUnderCase ()
{
@@ -92,7 +92,7 @@ namespace Hyena.Tests
Assert.AreEqual (map.Under, StringUtil.CamelCaseToUnderCase (map.Camel));
}
}
-
+
[Test]
public void DoubleToTenthsPrecision ()
{
@@ -108,7 +108,7 @@ namespace Hyena.Tests
Assert.AreEqual ("1.000,3", StringUtil.DoubleToTenthsPrecision (1000.32));
Assert.AreEqual ("9.233", StringUtil.DoubleToTenthsPrecision (9233));
}
-
+
[Test]
public void DoubleToPluralInt ()
{
@@ -129,11 +129,11 @@ namespace Hyena.Tests
Assert.AreEqual ("foobar", StringUtil.RemoveNewlines (@"foo
bar"));
Assert.AreEqual ("foobar baz", StringUtil.RemoveNewlines (@"foo
-bar
+bar
baz"));
Assert.AreEqual ("haswindows newline andunix", StringUtil.RemoveNewlines (@"has
windows
- newline
+ newline
andunix"));
}
@@ -147,11 +147,11 @@ andunix"));
Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo<baz/>bar"));
Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo</baz>bar"));
Assert.AreEqual ("foobazbar", StringUtil.RemoveHtml ("foo<a href=\"http://lkjdflkjdflkjj\">baz</a>bar"));
- Assert.AreEqual ("foobaz foo bar", StringUtil.RemoveHtml (@"foo<a
+ Assert.AreEqual ("foobaz foo bar", StringUtil.RemoveHtml (@"foo<a
href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
}
}
-
+
[TestFixture]
public class SearchKeyTests
{
@@ -159,14 +159,14 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
{
Assert.AreEqual (after, StringUtil.SearchKey (before));
}
-
+
[Test]
public void TestEmpty ()
{
AssertSearchKey ("", "");
AssertSearchKey (null, null);
}
-
+
// Test that resulting search keys are in lower-case
[Test]
public void TestLowercase ()
@@ -174,14 +174,14 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
AssertSearchKey ("A", "a");
AssertSearchKey ("\u0104", "a");
}
-
+
// Test that combining diacritics are removed from Latin characters.
[Test]
public void TestRemoveDiacritics ()
{
AssertSearchKey ("\u00e9", "e");
AssertSearchKey ("e\u0301", "e");
-
+
AssertSearchKey ("\u014d", "o");
AssertSearchKey ("o\u0304", "o");
@@ -209,7 +209,7 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
AssertSearchKey ("ż", "z");
AssertSearchKey ("Å»", "z");
}
-
+
// Test that combining diacritics are preserved, and combined, for non-Latin characters.
[Test]
public void TestPreserveDiacritics ()
@@ -217,7 +217,7 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
AssertSearchKey ("\u304c", "\u304c");
AssertSearchKey ("\u304b\u3099", "\u304c");
}
-
+
// Test that some non-Latin characters are converted to Latin counterparts.
[Test]
public void TestEquivalents ()
@@ -225,7 +225,7 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
AssertSearchKey ("\u00f8", "o");
AssertSearchKey ("\u0142", "l");
}
-
+
// Test that some kinds of punctuation are removed.
[Test]
public void TestRemovePunctuation ()
@@ -236,16 +236,16 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
AssertSearchKey ("?", "");
AssertSearchKey ("/", "");
}
-
+
[Test] // http://bugzilla.gnome.org/show_bug.cgi?id=573484
public void TestCollapseSpaces ()
{
AssertSearchKey (" a \t b ", "a b");
AssertSearchKey ("100 % techno", "100 techno");
-
+
// Character in the set of special overrides
AssertSearchKey ("a \u00f8", "a o");
-
+
// Invalid combining character
AssertSearchKey ("a \u0301", "a");
}
@@ -263,7 +263,7 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
{
AssertProduces (input, input);
}
-
+
[Test]
public void TestEmpty ()
{
@@ -293,7 +293,7 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
AssertProduces ("Greetings! -* ä½ å¥½?", "Greetings! -_ ä½ å¥½_");
}
}
-
+
[TestFixture]
public class SortKeyTests
{
@@ -301,19 +301,19 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
{
Assert.AreEqual (after, StringUtil.SortKey (before));
}
-
+
[Test]
public void TestNull ()
{
AssertSortKey (null, null);
}
-
+
[Test]
public void TestEmpty ()
{
AssertSortKey ("", new byte[] {1, 1, 1, 1, 0});
}
-
+
[Test]
public void TestSortKey ()
{
@@ -379,7 +379,7 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
String.Format ("foo{0}01. bar.ogg", dir_sep));
}
}
-
+
[TestFixture]
public class SubstringCountTests
{
@@ -387,21 +387,21 @@ href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
{
Assert.AreEqual (expected, StringUtil.SubstringCount (haystack, needle));
}
-
+
[Test]
public void TestEmpty ()
{
AssertCount ("", "a", 0);
AssertCount ("a", "", 0);
}
-
+
[Test]
public void TestNoMatches ()
{
AssertCount ("a", "b", 0);
AssertCount ("with needle in", "long needle", 0);
}
-
+
[Test]
public void TestMatches ()
{
diff --git a/src/Hyena/Hyena/Tests/TestBase.cs b/src/Hyena/Hyena/Tests/TestBase.cs
index b6c3e63..3c263b6 100644
--- a/src/Hyena/Hyena/Tests/TestBase.cs
+++ b/src/Hyena/Hyena/Tests/TestBase.cs
@@ -44,13 +44,13 @@ namespace Hyena.Tests
{
public F From;
public T To;
-
+
public TransformPair (F from, T to)
{
From = from;
To = to;
}
-
+
public static TransformPair<F, T> [] GetFrom (params object [] objects)
{
TransformPair<F, T> [] pairs = new TransformPair<F, T> [objects.Length / 2];
@@ -59,27 +59,27 @@ namespace Hyena.Tests
}
return pairs;
}
-
+
public override string ToString ()
{
return From.ToString ();
}
}
-
+
public delegate To Transform<F, To> (F from);
-
+
public abstract class TestBase
{
private string bin_dir;
public string BinDir {
get { return bin_dir ?? (bin_dir = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location)); }
}
-
+
private string tests_dir;
public string TestsDir {
get { return tests_dir ?? (tests_dir = Path.Combine (Path.GetDirectoryName (BinDir), "tests")); }
}
-
+
public static void AssertForEach<T> (IEnumerable<T> objects, Action<T> runner)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder ();
@@ -88,11 +88,11 @@ namespace Hyena.Tests
catch (AssertionException e) { sb.AppendFormat ("Failed assertion on {0}: {1}\n", o, e.Message); }
catch (Exception e) { sb.AppendFormat ("\nCaught exception on {0}: {1}\n", o, e.ToString ()); }
}
-
+
if (sb.Length > 0)
Assert.Fail ("\n" + sb.ToString ());
}
-
+
// Fails to compile, causes SIGABRT in gmcs; boo
/*public static void AssertTransformsEach<A, B> (IEnumerable<TransformPair<A, B>> pairs, Transform<A, B> transform)
{
diff --git a/src/Hyena/Hyena/ThreadAssist.cs b/src/Hyena/Hyena/ThreadAssist.cs
index 93e393a..dd9d14b 100644
--- a/src/Hyena/Hyena/ThreadAssist.cs
+++ b/src/Hyena/Hyena/ThreadAssist.cs
@@ -41,20 +41,20 @@ namespace Hyena
}
public static Action<InvokeHandler> ProxyToMainHandler { get; set; }
-
+
public static void InitializeMainThread ()
{
main_thread = Thread.CurrentThread;
main_thread.Name = "Main Thread";
}
-
+
public static bool InMainThread {
get {
if (main_thread == null) {
throw new ApplicationException ("ThreadAssist.InitializeMainThread must be called first");
}
-
- return main_thread.Equals (Thread.CurrentThread);
+
+ return main_thread.Equals (Thread.CurrentThread);
}
}
@@ -64,14 +64,14 @@ namespace Hyena
Hyena.Log.Warning ("In GUI thread, will probably block it", System.Environment.StackTrace);
}
}
-
+
public static void AssertInMainThread ()
{
if (ApplicationContext.Debugging && !InMainThread) {
Hyena.Log.Warning ("Not in main thread!", System.Environment.StackTrace);
}
}
-
+
public static void ProxyToMain (InvokeHandler handler)
{
if (!InMainThread) {
@@ -90,7 +90,7 @@ namespace Hyena
threadedMethod ();
}
}
-
+
public static Thread Spawn (ThreadStart threadedMethod, bool autoStart)
{
Thread thread = new Thread (threadedMethod);
@@ -101,7 +101,7 @@ namespace Hyena
}
return thread;
}
-
+
public static Thread Spawn (ThreadStart threadedMethod)
{
return Spawn (threadedMethod, true);
diff --git a/src/Hyena/Hyena/Timer.cs b/src/Hyena/Hyena/Timer.cs
index 9f4d3f3..1c83e04 100644
--- a/src/Hyena/Hyena/Timer.cs
+++ b/src/Hyena/Hyena/Timer.cs
@@ -38,8 +38,8 @@ namespace Hyena
public Timer (string format, params object [] vals) : this (String.Format (format, vals))
{
}
-
- public Timer (string label)
+
+ public Timer (string label)
{
this.label = label;
start = DateTime.Now;
diff --git a/src/Hyena/Hyena/UndoManager.cs b/src/Hyena/Hyena/UndoManager.cs
index 95d6719..f702a77 100644
--- a/src/Hyena/Hyena/UndoManager.cs
+++ b/src/Hyena/Hyena/UndoManager.cs
@@ -53,7 +53,7 @@ namespace Hyena
UndoRedo(redo_stack, undo_stack, false);
}
}
-
+
public void Clear()
{
lock(this) {
@@ -124,7 +124,7 @@ namespace Hyena
get { return undo_stack.Count > 0; }
}
- public bool CanRedo {
+ public bool CanRedo {
get { return redo_stack.Count > 0; }
}
diff --git a/src/Hyena/Hyena/XdgBaseDirectorySpec.cs b/src/Hyena/Hyena/XdgBaseDirectorySpec.cs
index e92084e..701e0c1 100644
--- a/src/Hyena/Hyena/XdgBaseDirectorySpec.cs
+++ b/src/Hyena/Hyena/XdgBaseDirectorySpec.cs
@@ -37,7 +37,7 @@ namespace Hyena
{
string home_dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
string config_dir = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
-
+
string env_path = Environment.GetEnvironmentVariable (key);
if (!String.IsNullOrEmpty (env_path)) {
return env_path;
@@ -75,7 +75,7 @@ namespace Hyena
}
} catch (FileNotFoundException) {
}
-
+
return Path.Combine (home_dir, fallback);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]