Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
* Button.cs: Make Click method virtual
Browse files Browse the repository at this point in the history
* ToggleButton.cs: Allow toggle buttons to display an arrow
* VariantsCombinaisonSwitcher.cs: Introduction of variants combinaisons
  switcher.
* ToolBox.cs: Bugfix for size requests
* VariantsCombinaison.cs: Bugfix for size requests, and hierachy
* Ribbon.cs: Revert to previous version of Ribbon (I have opted for
  another solution for variants combinaisons)
* DropdownRibbonGroup.cs: Introduction of Drop down ribbon group

svn path=/trunk/gtk-sharp-ribbon/; revision=110153
  • Loading branch information
Laurent Debacker committed Aug 11, 2008
1 parent bf0a41a commit d1600e5
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Ribbons/Button.cs
Expand Up @@ -95,7 +95,7 @@ public static Button FromStockIcon (string Name, string Label, bool Large)
}

/// <summary>Fires the Click event.</summary>
public void Click ()
public virtual void Click ()
{
if(enable && Clicked != null) Clicked (this, EventArgs.Empty);
}
Expand Down
12 changes: 12 additions & 0 deletions Ribbons/ChangeLog
@@ -1,3 +1,15 @@
2008-08-11 Laurent Debacker <debackerl@gmail.com>

* Button.cs: Make Click method virtual
* ToggleButton.cs: Allow toggle buttons to display an arrow
* VariantsCombinaisonSwitcher.cs: Introduction of variants combinaisons
switcher.
* ToolBox.cs: Bugfix for size requests
* VariantsCombinaison.cs: Bugfix for size requests, and hierachy
* Ribbon.cs: Revert to previous version of Ribbon (I have opted for another
solution for variants combinaisons)
* DropdownRibbonGroup.cs: Introduction of Drop down ribbon group

2008-07-10 Laurent Debacker <debackerl@gmail.com>

* GroupVariant.cs: Implementation of the concept of "variant" for Group.
Expand Down
92 changes: 92 additions & 0 deletions Ribbons/DropdownRibbonGroup.cs
@@ -0,0 +1,92 @@
using System;
using Gtk;

namespace Ribbons
{
public class DropdownRibbonGroup : ToggleButton
{
private RibbonGroup group;
private SyntheticWindow win;

public RibbonGroup Group
{
get { return group; }
set { group = value; }
}

public DropdownRibbonGroup ()
{
DrawBackground = true;
ImagePosition = PositionType.Top;
isSmall = false;
DisplayArrow = true;
}

protected override void BindedWidget_ButtonReleaseEvent (object sender, ButtonReleaseEventArgs evnt)
{
base.BindedWidget_ButtonReleaseEvent (sender, evnt);

if(Value)
{
int x, y;
ParentWindow.GetOrigin (out x, out y);
x += Allocation.X;
y += Allocation.Bottom;

ShowAt (x, y);
}
else
{
KillMenu (true);
}
}

private void ShowAt (int x, int y)
{
if(win != null) return;

win = new SyntheticWindow (WindowType.Popup);
win.Child = group;

win.Hidden += delegate { KillMenu (true); };

win.ShowAll ();
win.GdkWindow.Move (x, y);

win.ButtonPressEvent += delegate { KillMenu (true); };
win.AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));

Grab.Add (win);
Gdk.GrabStatus grabbed = Gdk.Pointer.Grab (win.GdkWindow, true, Gdk.EventMask.ButtonPressMask, null, null, 0);
if(grabbed != Gdk.GrabStatus.Success)
{
KillMenu (false);
return;
}

grabbed = Gdk.Keyboard.Grab (win.GdkWindow, true, 0);
if(grabbed != Gdk.GrabStatus.Success)
{
KillMenu (false);
return;
}
}

private void KillMenu (bool Ungrab)
{
if(win == null) return;

Grab.Remove (win);
if(Ungrab)
{
Gdk.Pointer.Ungrab (0);
Gdk.Keyboard.Ungrab (0);
}
win.Hide ();
group.Unparent ();
win = null;

Value = false;
}
}
}
113 changes: 32 additions & 81 deletions Ribbons/Ribbon.cs
Expand Up @@ -84,13 +84,13 @@ public int CurrentPageIndex
if(curPageIndex != -1)
{
CurrentPage.Label.ModifyFg (StateType.Normal, theme.GetForecolorForRibbonTabs (false));
CurrentPage.SelectedCombinaison.Unparent ();
CurrentPage.Page.Unparent ();
}
curPageIndex = value;
if(curPageIndex != -1)
{
CurrentPage.Label.ModifyFg (StateType.Normal, theme.GetForecolorForRibbonTabs (true));
CurrentPage.SelectedCombinaison.Parent = this;
CurrentPage.Page.Parent = this;
}

ShowAll ();
Expand Down Expand Up @@ -161,24 +161,26 @@ 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 RibbonPage AppendPage (Widget Label)
public void AppendPage (Widget Child, Widget Label)
{
return InsertPage (Label, -1);
InsertPage (Child, 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 RibbonPage PrependPage (Widget Child, Widget Label)
public void PrependPage (Widget Child, Widget Label)
{
return InsertPage (Label, 0);
InsertPage (Child, 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 RibbonPage InsertPage (Widget Label, int Position)
public void InsertPage (Widget Child, Widget Label, int Position)
{
RibbonPage p = new RibbonPage (this, Label);
RibbonPage p = new RibbonPage (this, Child, Label);

if(Position == -1)
{
Expand Down Expand Up @@ -224,8 +226,6 @@ public RibbonPage InsertPage (Widget Label, int Position)
{
OnPageSelected (new PageEventArgs (pages[idx]));
}

return p;
}

/// <summary>Removes the specified page.</summary>
Expand Down Expand Up @@ -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 (VariantsCombinaison Child)
public int PageNum (Widget 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].SelectedCombinaison == Child)
if(pages[i].Page == 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>
Expand All @@ -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;
}
Expand All @@ -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>
Expand Down Expand Up @@ -352,9 +352,9 @@ protected override void ForAll (bool include_internals, Callback callback)

foreach(RibbonPage p in pages) callback (p.Label);

if(CurrentPage != null && CurrentPage.SelectedCombinaison != null)
if(CurrentPage != null)
{
callback (CurrentPage.SelectedCombinaison);
callback (CurrentPage.Page);
}
}

Expand Down Expand Up @@ -407,9 +407,9 @@ protected override void OnSizeRequested (ref Requisition requisition)
}

double pageWidth = 0, pageHeight = 0;
if(page != null && page.SelectedCombinaison != null)
if(page != null)
{
pageRequisition = page.SelectedCombinaison.SizeRequest ();
pageRequisition = page.Page.SizeRequest ();
pageWidth = pageRequisition.Width + 2 * pagePadding;
pageHeight = pageRequisition.Height + 2 * pagePadding;
}
Expand Down Expand Up @@ -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 && page.SelectedCombinaison != null)
if(page != null)
{
pageAllocation = bodyAllocation;
int pad = (int)pagePadding;
pageAllocation.Inflate (-pad, -pad);
page.SelectedCombinaison.SizeAllocate (pageAllocation);
page.Page.SizeAllocate (pageAllocation);
}
else
{
Expand Down Expand Up @@ -565,17 +565,9 @@ protected virtual void OnPageRemoved (PageEventArgs args)
public class RibbonPage
{
private Ribbon parent;
private Widget label;
private Widget label, page;
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
Expand All @@ -589,6 +581,13 @@ 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; }
Expand All @@ -600,65 +599,17 @@ public Gdk.Rectangle LabelAllocation
get { return labelAlloc; }
}

public IList<VariantsCombinaison> Combinaisons
{
get { return combinaisons.AsReadOnly(); }
}

public RibbonPage (Ribbon Parent, Widget Label)
public RibbonPage (Ribbon Parent, Widget Page, Widget Label)
{
this.parent = Parent;
parent = Parent;
this.Label = Label;
this.combinaisons = new List<VariantsCombinaison> ();
this.curRequiredWidth = -1;
this.Page = Page;
}

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];
}
}
}
}
2 changes: 2 additions & 0 deletions Ribbons/Ribbons.mdp
Expand Up @@ -48,6 +48,8 @@
<File name="ApplicationMenuItem.cs" subtype="Code" buildaction="Compile" />
<File name="VariantsCombinaison.cs" subtype="Code" buildaction="Compile" />
<File name="GroupVariant.cs" subtype="Code" buildaction="Compile" />
<File name="DropdownRibbonGroup.cs" subtype="Code" buildaction="Compile" />
<File name="VariantsCombinaisonSwitcher.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
Expand Down

0 comments on commit d1600e5

Please sign in to comment.