00001 using System; 00002 using System.Collections.Generic; 00003 using Gtk; 00004 using Foodolini.BusinessLogic; 00005 00006 namespace Foodolini.Activities.ShoppingList 00007 { 00011 public class ShoppingListItemAdapter : TreeNode 00012 { 00013 00014 public new Foodolini.BusinessLogic.ShoppingListItem Item{get;private set;} 00015 00016 public ShoppingListItemAdapter (ShoppingListItem item) 00017 { 00018 this.Item=item; 00019 } 00020 [Gtk.TreeNodeValue(Column = 0)] 00021 public string Recipe{ 00022 get{ 00023 if (this.Item.Recipe != null) 00024 return this.Item.Recipe.Title; 00025 else 00026 return null; 00027 } 00028 } 00029 00030 [Gtk.TreeNodeValue(Column = 1)] 00031 public string Ingredient{ 00032 get{ 00033 return this.Item.Ingredient.LongDescription; 00034 } 00035 } 00036 00037 [Gtk.TreeNodeValue(Column = 2)] 00038 public double Quantity{ 00039 get{ 00040 return this.Item.Quantity; 00041 } 00042 set{ 00043 this.Item.Quantity=value; 00044 } 00045 } 00046 00047 #region Printing methods 00048 00052 private Pango.Layout qCol; 00053 00057 private Pango.Layout dCol; 00058 00065 public double SetupLayout(PrintContext context){ 00066 qCol = context.CreatePangoLayout(); 00067 qCol.Alignment = Pango.Alignment.Right; 00068 qCol.Wrap = Pango.WrapMode.WordChar; 00069 qCol.SetText(this.Quantity + " g"); 00070 00071 int w, h; 00072 qCol.GetPixelSize(out w, out h); 00073 00074 dCol = context.CreatePangoLayout(); 00075 dCol.Alignment = Pango.Alignment.Left; 00076 dCol.Wrap = Pango.WrapMode.WordChar; 00077 dCol.SetText(this.Ingredient + (string.IsNullOrEmpty(this.Recipe) ? "" : " (" + this.Recipe + ")")); 00078 00079 return (double)w; 00080 } 00081 00094 public double AdjustWidth(double qColWidth, double dColWidth){ 00095 qCol.Width = (int)Math.Ceiling(qColWidth * Pango.Scale.PangoScale); 00096 dCol.Width = (int)Math.Ceiling(dColWidth * Pango.Scale.PangoScale); 00097 int qw, qh, dw, dh; 00098 qCol.GetPixelSize(out qw, out qh); 00099 dCol.GetPixelSize(out dw, out dh); 00100 return Math.Max(dh, qh) + 4; 00101 } 00102 00115 public bool NextPage(double width, double height){ 00116 int qw, qh, dw, dh; 00117 qCol.GetPixelSize(out qw, out qh); 00118 dCol.GetPixelSize(out dw, out dh); 00119 return qw + dw + 10 > width || Math.Max(qh, dh) + 6 > height; 00120 } 00121 00137 public double Render(Cairo.Context context, Cairo.PointD position, double qColWidth){ 00138 int qw, qh, dw, dh; 00139 qCol.GetPixelSize(out qw, out qh); 00140 dCol.GetPixelSize(out dw, out dh); 00141 position.Y += 3; 00142 context.MoveTo(position); 00143 00144 Pango.CairoHelper.ShowLayout(context, qCol); 00145 context.RelMoveTo(qColWidth + 10, 0); 00146 Pango.CairoHelper.ShowLayout(context, dCol); 00147 00148 return Math.Max(qh, dh) + 3; 00149 } 00150 00151 #endregion 00152 } 00153 }