Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Ribbons/GroupVariant.cs: Implementation of the concept of "variant"

  for Group.
* Ribbons/VariantsCombinaison.cs: Implementation for the concept of
  variant combinaisons.
* Ribbons/Ribbon.cs: Migrating Ribbon to variants combinaisons.

svn path=/trunk/gtk-sharp-ribbon/; revision=109630
  • Loading branch information...
commit bf0a41a66ef3510ab53d3dd195a4bc4112177e59 1 parent e01583f
Laurent Debacker authored
View
7 Ribbons/ChangeLog
@@ -1,3 +1,10 @@
+2008-07-10 Laurent Debacker <debackerl@gmail.com>
+
+ * GroupVariant.cs: Implementation of the concept of "variant" for Group.
+ * VariantsCombinaison.cs: Implementation for the concept of variant
+ combinaisons.
+ * Ribbon.cs: Migrating Ribbon to variants combinaisons.
+
2008-07-03 Laurent Debacker <debackerl@gmail.com>
* Theme.cs: Enhanced key tip theme
View
34 Ribbons/GroupVariant.cs
@@ -0,0 +1,34 @@
+using System;
+using Gtk;
+
+namespace Ribbons
+{
+ public class GroupVariant
+ {
+ private Widget child;
+ private int width;
+
+ public Widget Child
+ {
+ get { return child; }
+ }
+
+ public int Width
+ {
+ get { return width; }
+ }
+
+ public GroupVariant (Widget Child)
+ {
+ this.child = Child;
+ this.width = -1;
+ }
+
+ public void Measure (int Height)
+ {
+ child.HeightRequest = Height;
+ Requisition req = child.SizeRequest ();
+ width = req.Width;
+ }
+ }
+}
View
113 Ribbons/Ribbon.cs
@@ -84,13 +84,13 @@ public int CurrentPageIndex
if(curPageIndex != -1)
{
CurrentPage.Label.ModifyFg (StateType.Normal, theme.GetForecolorForRibbonTabs (false));
- CurrentPage.Page.Unparent ();
+ CurrentPage.SelectedCombinaison.Unparent ();
}
curPageIndex = value;
if(curPageIndex != -1)
{
CurrentPage.Label.ModifyFg (StateType.Normal, theme.GetForecolorForRibbonTabs (true));
- CurrentPage.Page.Parent = this;
+ CurrentPage.SelectedCombinaison.Parent = this;
}
ShowAll ();
@@ -161,26 +161,24 @@ public Ribbon()
/// <summary>Adds a new page after all existing pages.</summary>
/// <param name="Child">The widget to use as the content of the page.</param>
/// <param name="Label">The widget to use as the tab.</param>
- public void AppendPage (Widget Child, Widget Label)
+ public RibbonPage AppendPage (Widget Label)
{
- InsertPage (Child, Label, -1);
+ return InsertPage (Label, -1);
}
/// <summary>Adds a new page before all existing pages.</summary>
- /// <param name="Child">The widget to use as the content of the page.</param>
/// <param name="Label">The widget to use as the tab.</param>
- public void PrependPage (Widget Child, Widget Label)
+ public RibbonPage PrependPage (Widget Child, Widget Label)
{
- InsertPage (Child, Label, 0);
+ return InsertPage (Label, 0);
}
/// <summary>Adds a new page at the specified position.</summary>
- /// <param name="Child">The widget to use as the content of the page.</param>
/// <param name="Label">The widget to use as the tab.</param>
/// <param name="Position">The index (starting at 0) at which the page must be inserted, or -1 to insert the page after all existing pages.</param>
- public void InsertPage (Widget Child, Widget Label, int Position)
+ public RibbonPage InsertPage (Widget Label, int Position)
{
- RibbonPage p = new RibbonPage (this, Child, Label);
+ RibbonPage p = new RibbonPage (this, Label);
if(Position == -1)
{
@@ -226,6 +224,8 @@ public void InsertPage (Widget Child, Widget Label, int Position)
{
OnPageSelected (new PageEventArgs (pages[idx]));
}
+
+ return p;
}
/// <summary>Removes the specified page.</summary>
@@ -256,15 +256,15 @@ public void RemovePage (int PageNumber)
/// <summary>Returns the index of the specified page given its content widget.</summary>
/// <param name="Child">The content of the page whose index must be returned.</param>
/// <returns>The index.</returns>
- public int PageNum (Widget Child)
+ /*public int PageNum (VariantsCombinaison Child)
{
// Since it is unlikely that the widget will containe more than
// a dozen pages, it is just fine to do a linear search.
for(int i = 0, i_up = pages.Count ; i < i_up ; ++i)
- if(pages[i].Page == Child)
+ if(pages[i].SelectedCombinaison == Child)
return i;
return -1;
- }
+ }*/
/// <summary>Returns the index of the specified page.</summary>
/// <param name="Page">The page whose index must be returned.</param>
@@ -282,7 +282,7 @@ public int RibbonPageNum (RibbonPage Page)
/// <summary>Sets the label widget of the specified page.</summary>
/// <param name="Page">The content of the page whose label must be modified.</param>
/// <param name="Label">The new label widget.</param>
- public void SetPageLabel (Widget Child, Widget Label)
+ /*public void SetPageLabel (Widget Child, Widget Label)
{
pages[PageNum (Child)].Label = Label;
}
@@ -301,7 +301,7 @@ public Widget GetPageLabel (Widget Child)
public Widget GetNthPage (int Position)
{
return pages[Position].Page;
- }
+ }*/
/// <summary>Returns the n-th page.</summary>
/// <param name="Position">Index of the page to return.</param>
@@ -352,9 +352,9 @@ protected override void ForAll (bool include_internals, Callback callback)
foreach(RibbonPage p in pages) callback (p.Label);
- if(CurrentPage != null)
+ if(CurrentPage != null && CurrentPage.SelectedCombinaison != null)
{
- callback (CurrentPage.Page);
+ callback (CurrentPage.SelectedCombinaison);
}
}
@@ -407,9 +407,9 @@ protected override void OnSizeRequested (ref Requisition requisition)
}
double pageWidth = 0, pageHeight = 0;
- if(page != null)
+ if(page != null && page.SelectedCombinaison != null)
{
- pageRequisition = page.Page.SizeRequest ();
+ pageRequisition = page.SelectedCombinaison.SizeRequest ();
pageWidth = pageRequisition.Width + 2 * pagePadding;
pageHeight = pageRequisition.Height + 2 * pagePadding;
}
@@ -497,12 +497,12 @@ protected override void OnSizeAllocated (Gdk.Rectangle allocation)
bodyAllocation.Width = allocation.Width - bodyAllocation.X - (int)borderWidth;
bodyAllocation.Height = allocation.Height - bodyAllocation.Y - (int)borderWidth;
- if(page != null)
+ if(page != null && page.SelectedCombinaison != null)
{
pageAllocation = bodyAllocation;
int pad = (int)pagePadding;
pageAllocation.Inflate (-pad, -pad);
- page.Page.SizeAllocate (pageAllocation);
+ page.SelectedCombinaison.SizeAllocate (pageAllocation);
}
else
{
@@ -565,9 +565,17 @@ protected virtual void OnPageRemoved (PageEventArgs args)
public class RibbonPage
{
private Ribbon parent;
- private Widget label, page;
+ private Widget label;
private Requisition labelReq;
private Gdk.Rectangle labelAlloc;
+ private List<VariantsCombinaison> combinaisons;
+ private int curRequiredWidth;
+ private VariantsCombinaison selectedCombinaison;
+
+ public VariantsCombinaison SelectedCombinaison
+ {
+ get { return selectedCombinaison; }
+ }
/// <summary>Label widget of the page.</summary>
public Widget Label
@@ -581,13 +589,6 @@ public Widget Label
get { return label; }
}
- /// <summary>Widget used as the content of the page.</summary>
- public Widget Page
- {
- set { page = value; }
- get { return page; }
- }
-
internal Requisition LabelRequisition
{
set { labelReq = value; }
@@ -599,17 +600,65 @@ public Gdk.Rectangle LabelAllocation
get { return labelAlloc; }
}
- public RibbonPage (Ribbon Parent, Widget Page, Widget Label)
+ public IList<VariantsCombinaison> Combinaisons
+ {
+ get { return combinaisons.AsReadOnly(); }
+ }
+
+ public RibbonPage (Ribbon Parent, Widget Label)
{
- parent = Parent;
+ this.parent = Parent;
this.Label = Label;
- this.Page = Page;
+ this.combinaisons = new List<VariantsCombinaison> ();
+ this.curRequiredWidth = -1;
}
public void SetLabelAllocation (Gdk.Rectangle r)
{
labelAlloc = r;
}
+
+ public void AddVariantsCombinaison (VariantsCombinaison Combinaison)
+ {
+ combinaisons.Add (Combinaison);
+ this.curRequiredWidth = -1;
+ }
+
+ public void RemoveVariantsCombinaison (VariantsCombinaison Combinaison)
+ {
+ combinaisons.Remove (Combinaison);
+ }
+
+ public void SelectCombinaison (int MaxWidth, int Height)
+ {
+ if(curRequiredWidth == MaxWidth) return;
+
+ KeyValuePair<int,VariantsCombinaison>[] pairs = new KeyValuePair<int,VariantsCombinaison>[combinaisons.Count];
+
+ for(int i = 0, i_up = combinaisons.Count ; i < i_up ; ++i)
+ {
+ combinaisons[i].HeightRequest = Height;
+ int w = combinaisons[i].SizeRequest ().Width;
+ pairs[i] = new KeyValuePair<int,VariantsCombinaison> (w, combinaisons[i]);
+ }
+
+ Array.Sort (pairs);
+
+ int low = 0, high = pairs.Length;
+ while(low < high)
+ {
+ int mid = (low + high) >> 1;
+ if(pairs[mid].Key < MaxWidth)
+ low = mid + 1;
+ else
+ high = mid;
+ }
+
+ if(high == 0)
+ selectedCombinaison = combinaisons[0];
+ else
+ selectedCombinaison = combinaisons[high - 1];
+ }
}
}
}
View
2  Ribbons/Ribbons.mdp
@@ -46,6 +46,8 @@
<File name="ApplicationButton.cs" subtype="Code" buildaction="Compile" />
<File name="ApplicationMenu.cs" subtype="Code" buildaction="Compile" />
<File name="ApplicationMenuItem.cs" subtype="Code" buildaction="Compile" />
+ <File name="VariantsCombinaison.cs" subtype="Code" buildaction="Compile" />
+ <File name="GroupVariant.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
View
169 Ribbons/VariantsCombinaison.cs
@@ -0,0 +1,169 @@
+using System;
+using System.Collections.Generic;
+using Gtk;
+
+namespace Ribbons
+{
+ // Note: this widget shall display a button at the left and the right
+ // to scroll groups when the allocated with is not enough.
+
+ public class VariantsCombinaison : Container
+ {
+ private List<Widget> widgets;
+ private Button left, right;
+ private Gtk.Requisition[] requisitions;
+ private int spacing;
+
+ public VariantsCombinaison ()
+ {
+ this.widgets = new List<Widget> ();
+
+ this.SetFlag (WidgetFlags.NoWindow);
+
+ this.AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));
+
+ this.spacing = 2;
+ }
+
+ /*public void Measure (int Height)
+ {
+ width = 0;
+ foreach(Widget variant in variants)
+ {
+ variant.Measure (Height);
+ width += variant.Width;
+ }
+ }*/
+
+ /// <summary>Gets or sets the spacing between children.</summary>
+ public int Spacing
+ {
+ set
+ {
+ spacing = value;
+ QueueDraw ();
+ }
+ get { return spacing; }
+ }
+
+ /// <summary>Adds a widget before all existing widgets.</summary>
+ /// <param name="w">The widget to add.</param>
+ public void Prepend (Widget w)
+ {
+ Insert (w, 0);
+ }
+
+ /// <summary>Adds a widget after all existing widgets.</summary>
+ /// <param name="w">The widget to add.</param>
+ public void Append (Widget w)
+ {
+ Insert (w, -1);
+ }
+
+ /// <summary>Inserts a widget at the specified location.</summary>
+ /// <param name="w">The widget to add.</param>
+ /// <param name="WidgetIndex">The index (starting at 0) at which the widget must be inserted, or -1 to insert the widget after all existing widgets.</param>
+ public void Insert (Widget w, int WidgetIndex)
+ {
+ w.Parent = this;
+ w.Visible = true;
+
+ if(WidgetIndex == -1)
+ widgets.Add (w);
+ else
+ widgets.Insert (WidgetIndex, w);
+
+ ShowAll ();
+ }
+
+ /// <summary>Removes the widget at the specified index.</summary>
+ /// <param name="WidgetIndex">Index of the widget to remove.</param>
+ public void Remove (int WidgetIndex)
+ {
+ widgets[WidgetIndex].Parent = null;
+
+ if(WidgetIndex == -1)
+ widgets.RemoveAt (widgets.Count - 1);
+ else
+ widgets.RemoveAt (WidgetIndex);
+
+ ShowAll ();
+ }
+
+ protected override void ForAll (bool include_internals, Callback callback)
+ {
+ foreach(Widget w in widgets)
+ {
+ if(w.Visible) callback (w);
+ }
+ }
+
+ protected override void OnSizeRequested (ref Requisition requisition)
+ {
+ base.OnSizeRequested (ref requisition);
+
+ if(requisitions == null || requisitions.Length != widgets.Count)
+ {
+ requisitions = new Gtk.Requisition[widgets.Count];
+ }
+
+ int totalWidth = 0, rowHeight = 0;
+ if(HeightRequest == -1)
+ {
+ foreach(Widget w in widgets)
+ {
+ if(w.Visible)
+ {
+ rowHeight = Math.Max (rowHeight, w.SizeRequest ().Height);
+ }
+ }
+ }
+ else rowHeight = HeightRequest - 2*(int)BorderWidth;
+
+ int i = 0;
+ foreach(Widget w in widgets)
+ {
+ if(w.Visible)
+ {
+ w.HeightRequest = rowHeight;
+ requisitions[i] = w.SizeRequest ();
+ totalWidth += requisitions[i].Width;
+ }
+ ++i;
+ }
+
+ requisition.Height = rowHeight;
+ if(WidthRequest != -1)
+ requisition.Width = WidthRequest;
+ else
+ requisition.Width = totalWidth;
+ }
+
+ protected override void OnSizeAllocated (Gdk.Rectangle allocation)
+ {
+ base.OnSizeAllocated (allocation);
+
+ int right = allocation.X + allocation.Width - (int)BorderWidth;
+ int left = allocation.X + (int)BorderWidth;
+ int bottom = allocation.Y + allocation.Height - (int)BorderWidth;
+ int x = left, y = allocation.Y + (int)BorderWidth;
+
+ int i = 0;
+ foreach(Widget w in widgets)
+ {
+ if(w.Visible)
+ {
+ Gdk.Rectangle r;
+ r.X = x;
+ r.Y = y;
+ r.Width = Math.Min (right, r.X + requisitions[i].Width) - r.X;
+ r.Height = Math.Min (bottom, r.Y + requisitions[i].Height) - r.Y;
+ w.SizeAllocate (r);
+
+ x += r.Width + spacing;
+ }
+ ++i;
+ }
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.