Mercurial > repos > IBBoard.GtkSharp
annotate NotebookUtil.cs @ 36:150e2b080a3f
* Add standardised .hgignore for C# projects
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Sep 2011 11:58:12 +0100 |
parents | 50d774f164dd |
children |
rev | line source |
---|---|
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (NotebookUtil.cs) is a part of the IBBoard.Gtk project and is copyright 2009 IBBoard |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // 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. |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 // |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System; |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using Gtk; |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 namespace IBBoard.GtkSharp |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 { |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 public class NotebookUtil |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 /// <summary> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 /// Adds a page to a notebook, but also includes a close button in the tab. Returns the page number added |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 /// </summary> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 /// <param name="notebook"> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 /// The <see cref="Notebook"/> to add a page to |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 /// </param> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 /// <param name="page"> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 /// The <see cref="Widget"/> to use as the content of the page |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 /// </param> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 /// <param name="title"> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 /// The title of the tab |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 /// </param> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 /// <returns> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 /// The page number created |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 /// </returns> |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 public static int AddPageToNotebookWithCloseButton(Notebook notebook, Widget page, string title) |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 { |
7
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
30 return notebook.AppendPage(page, CreateNotebookTabLabelWithClose(notebook, page, title)); |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
31 } |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
32 |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
33 /// <summary> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
34 /// Creates a widget to be used as the label for a notebook tab with text and a close button |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
35 /// </summary> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
36 /// <param name="notebook"> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
37 /// The <see cref="Notebook"/> the page is on |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
38 /// </param> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
39 /// <param name="page"> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
40 /// The <see cref="Widget"/> that is the content of the page |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
41 /// </param> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
42 /// <param name="title"> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
43 /// The text to display on the tab |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
44 /// </param> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
45 /// <returns> |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
46 /// A <see cref="Widget"/> that can be used as a tab label that contains the label with the title text and a close button |
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
47 /// </returns> |
13 | 48 public static Widget CreateNotebookTabLabelWithClose(Notebook notebook, Widget page, String title) |
7
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
49 { |
30 | 50 EventBox eventBox = new EventBox(); |
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 HBox hbox = new HBox(); |
30 | 52 eventBox.Add(hbox); |
31 | 53 eventBox.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) { |
30 | 54 if (args.Event.Button == (uint)MouseButton.Middle) |
55 { | |
56 notebook.Remove(page); | |
57 } | |
58 }; | |
13 | 59 hbox.PackStart(new Label(title)); |
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 Button close = new Button(); |
13 | 61 Gtk.Rc.ParseString("style \"NotebookTab.CloseButton\" {\n GtkWidget::focus-padding = 0\n GtkWidget::focus-line-width = 0\n xthickness = 0\n ythickness = 0\n GtkButton::inner-border = {0,0,0,0}\n }\n"); |
62 Gtk.Rc.ParseString("widget \"*.NotebookTab.CloseButton\" style \"NotebookTab.CloseButton\"\n"); | |
6
49307b998555
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
4
diff
changeset
|
63 Image icon = Image.NewFromIconName("gtk-close", IconSize.Menu); |
49307b998555
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
4
diff
changeset
|
64 icon.SetPadding(0, 0); |
49307b998555
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
4
diff
changeset
|
65 close.Image = icon; |
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 close.Relief = ReliefStyle.None; |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 close.FocusOnClick = false; |
6
49307b998555
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
4
diff
changeset
|
68 close.BorderWidth = 0; |
13 | 69 close.Name = "NotebookTab.CloseButton"; |
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 close.Clicked += delegate { |
7
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
71 notebook.Remove(page); |
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 }; |
30 | 73 |
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 hbox.PackStart(close); |
7
d92d11bd4808
* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125)
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
75 hbox.ShowAll(); |
30 | 76 return eventBox; |
4
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 } |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 } |
10df433db2ac
Re #23: Add easy creation of "tab with close"
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 } |