view IBBoard.GtkSharp/NotebookUtil.cs @ 2:810eb198c8fb

Re #23: Initial check-in of module IBBoard.GtkSharp (not quite the right close button, but close)
author IBBoard <dev@ibboard.co.uk>
date Wed, 24 Jun 2009 20:32:30 +0000
parents
children
line wrap: on
line source

//  This file (NotebookUtil.cs) is a part of the IBBoard.Gtk project and is copyright 2009 IBBoard
// 
//  The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
// 

using System;
using Gtk;

namespace IBBoard.GtkSharp
{
	public class NotebookUtil
	{
		/// <summary>
		/// Adds a page to a notebook, but also includes a close button in the tab. Returns the page number added
		/// </summary>
		/// <param name="notebook">
		/// The <see cref="Notebook"/> to add a page to
		/// </param>
		/// <param name="page">
		/// The <see cref="Widget"/> to use as the content of the page
		/// </param>
		/// <param name="title">
		/// The title of the tab
		/// </param>
		/// <returns>
		/// The page number created
		/// </returns>
		public static int AddPageToNotebookWithCloseButton(Notebook notebook, Widget page, string title)
		{
			HBox hbox = new HBox();
			hbox.PackStart(new Label(title));			
			Button close = new Button("gtk-close");
			close.Relief = ReliefStyle.None;
			close.FocusOnClick = false;
			close.Clicked += delegate {
			    hbox.Destroy();
			    page.Destroy();
			};
			hbox.PackStart(close);			
			hbox.ShowAll();			
			return notebook.AppendPage(page, hbox); 
		}
	}
}