update these to the gtk2.4 ways (ComboBox and Action/UIManager)

svn path=/trunk/gtk-sharp/; revision=37056
This commit is contained in:
John Luke 2004-12-03 21:00:33 +00:00
parent e0a0bd13fa
commit e16d2290d7
5 changed files with 119 additions and 94 deletions

View File

@ -2,6 +2,7 @@
// ApplicationWindow.cs, port of appwindow.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
// John Luke <john.luke@gmail.com>
//
// Copyright (C) 2003, Ximian Inc.
@ -11,10 +12,7 @@
* Demonstrates a typical application window, with menubar, toolbar, statusbar.
*/
// : - Is this necesary? /* Set up item factory to go away with the window */
using System;
using Gtk;
namespace GtkDemo
@ -27,82 +25,119 @@ namespace GtkDemo
int row, column, count = 0;
Statusbar statusbar;
VBox vbox;
// static ItemFactoryEntry items[] = { new ItemFactoryEntry ("/_File", null, 0, 0, "<Branch>" )};
const string uiInfo =
"<ui>" +
" <menubar name='MenuBar'>" +
" <menu action='FileMenu'>" +
" <menuitem action='New'/>" +
" <menuitem action='Open'/>" +
" <menuitem action='Save'/>" +
" <menuitem action='SaveAs'/>" +
" <separator/>" +
" <menuitem action='Quit'/>" +
" </menu>" +
" <menu action='PreferencesMenu'>" +
" <menu action='ColorMenu'>" +
" <menuitem action='Red'/>" +
" <menuitem action='Green'/>" +
" <menuitem action='Blue'/>" +
" </menu>" +
" <menu action='ShapeMenu'>" +
" <menuitem action='Square'/>" +
" <menuitem action='Rectangle'/>" +
" <menuitem action='Oval'/>" +
" </menu>" +
" <menuitem action='Bold'/>" +
" </menu>" +
" <menu action='HelpMenu'>" +
" <menuitem action='About'/>" +
" </menu>" +
" </menubar>" +
" <toolbar name='ToolBar'>" +
" <toolitem name='open' action='Open'/>" +
" <toolitem name='quit' action='Quit'/>" +
" <separator action='Sep1'/>" +
" <toolitem name='logo' action='Logo'/>" +
" </toolbar>" +
"</ui>";
public DemoApplicationWindow () : base ("Demo Application Window")
{
this.SetDefaultSize (400, 300);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 0);
vbox = new VBox (false, 0);
this.Add (vbox);
// Create the menubar
AddActions ();
AccelGroup accelGroup = new AccelGroup ();
this.AddAccelGroup (accelGroup);
MenuBar menubar = CreateMenu ();
vbox.PackStart (menubar, false, false, 0);
Toolbar toolbar = CreateToolbar ();
vbox.PackStart (toolbar, false, false, 0);
TextView textview = new TextView ();
textview.Buffer.MarkSet += new MarkSetHandler (OnMarkSet);
vbox.PackStart (textview, true, true, 0);
statusbar = new Statusbar ();
UpdateStatus ();
vbox.PackEnd (statusbar, false, false, 0);
vbox.PackStart (statusbar, false, false, 0);
TextView textview = new TextView ();
textview.Buffer.MarkSet += new MarkSetHandler (OnMarkSet);
vbox.PackEnd (textview, true, true, 0);
//ItemFactory itemFactory = new ItemFactory (typeof (MenuBar),"<main>", accelGroup);
// static ItemFactoryEntry items[] = { new ItemFactoryEntry ("/_File", null, 0, 0, "<Branch>" )};
// Set up item factory to go away with the window
// Is this necesary ?
// create menu items
//STUCK : Didn't find any examples of ItemFactory
this.ShowAll ();
}
private MenuBar CreateMenu ()
void AddActions ()
{
MenuBar menubar = new MenuBar ();
MenuItem file = new MenuItem ("File");
menubar.Append (file);
return menubar;
ActionEntry[] actions = new ActionEntry[]
{
new ActionEntry ("FileMenu", null, "_File", null, null, null),
new ActionEntry ("PreferencesMenu", null, "_Preferences", null, null, null),
new ActionEntry ("ColorMenu", null, "_Color", null, null, null),
new ActionEntry ("ShapeMenu", null, "_Shape", null, null, null),
new ActionEntry ("HelpMenu", null, "_Help", null, null, null),
new ActionEntry ("New", Stock.New, "_New", "<control>N", "Create a new file", new EventHandler (OnActionActivated)),
new ActionEntry ("Open", Stock.Open, "_Open", "<control>O", "Open a file", new EventHandler (OnActionActivated)),
new ActionEntry ("Save", Stock.Save, "_Save", "<control>S", "Save current file", new EventHandler (OnActionActivated)),
new ActionEntry ("SaveAs", Stock.SaveAs, "Save _As", null, "Save to a file", new EventHandler (OnActionActivated)),
new ActionEntry ("Quit", Stock.Quit, "_Quit", "<control>Q", "Quit", new EventHandler (OnActionActivated)),
new ActionEntry ("About", null, "_About", "<control>A", "About", new EventHandler (OnActionActivated)),
new ActionEntry ("Logo", "demo-gtk-logo", "Gtk#", null, "Gtk#", new EventHandler (OnActionActivated))
};
ToggleActionEntry[] toggleActions = new ToggleActionEntry[]
{
new ToggleActionEntry ("Bold", Stock.Bold, "_Bold", "<control>B", "Bold", new EventHandler (OnActionActivated), false)
};
ActionEntry[] colorActions = new ActionEntry[]
{
new ActionEntry ("Red", null, "_Red", "<control>R", "Blood", null),
new ActionEntry ("Green", null, "_Green", "<control>G", "Grass", null),
new ActionEntry ("Blue", null, "_Blue", "<control>B", "Sky", null)
};
ActionEntry[] shapeActions = new ActionEntry[]
{
new ActionEntry ("Square", null, "_Square", "<control>S", "Square", null),
new ActionEntry ("Rectangle", null, "_Rectangle", "<control>R", "Rectangle", null),
new ActionEntry ("Oval", null, "_Oval", "<control>O", "Oval", null)
};
ActionGroup group = new ActionGroup ("group");
group.Add (actions);
group.Add (toggleActions);
group.Add (colorActions);
group.Add (shapeActions);
UIManager uim = new UIManager ();
uim.InsertActionGroup (group, (int) uim.NewMergeId ());
uim.AddWidget += new AddWidgetHandler (OnAddWidget);
uim.AddUiFromString (uiInfo);
}
private Toolbar CreateToolbar ()
private void OnActionActivated (object sender, EventArgs a)
{
Toolbar toolbar = new Toolbar ();
Button open = new Button (Stock.Open);
open.Clicked += new EventHandler (OnToolbarClicked);
toolbar.AppendWidget (open, "Open", "Open");
Button quit = new Button (Stock.Quit);
quit.Clicked += new EventHandler (OnToolbarClicked);
toolbar.AppendWidget (quit, "Quit", "Quit");
Button gtk = new Button ("Gtk#");
gtk.Clicked += new EventHandler (OnToolbarClicked);
toolbar.AppendWidget (gtk, "Gtk#", "Gtk#");
return toolbar;
}
private void OnToolbarClicked (object o, EventArgs args)
{
using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "You selected a toolbar button.")) {
Action action = sender as Action;
using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, String.Format ("You activated action: {0}", action.Name))) {
md.Run ();
md.Hide ();
}
@ -129,5 +164,12 @@ namespace GtkDemo
statusbar.Pop (ctx);
statusbar.Push (ctx, String.Format (fmt, row, column, count));
}
void OnAddWidget (object sender, AddWidgetArgs a)
{
a.Widget.Show ();
vbox.PackStart (a.Widget, false, true, 0);
}
}
}

View File

@ -157,7 +157,7 @@ namespace GtkDemo
store = new TreeStore (typeof (string), typeof (string), typeof (bool));
TreeIter parent;
store.AppendValues ("Application Window (75% complete)", "DemoApplicationWindow.cs", false);
store.AppendValues ("Application Window", "DemoApplicationWindow.cs", false);
store.AppendValues ("Button Boxes", "DemoButtonBox.cs", false);
store.AppendValues ("Change Display (0%)", "DemoChangeDisplay.cs", false);
store.AppendValues ("Color Selector", "DemoColorSelection.cs", false);

View File

@ -85,22 +85,15 @@ namespace GtkDemo
}
// Convenience function to create an option menu holding a number of strings
private OptionMenu CreateOptionMenu (string [] strings)
private ComboBox CreateOptionMenu (string [] strings)
{
Menu menu = new Menu ();
MenuItem menuItem;
ComboBox combo = ComboBox.NewText ();
foreach (string str in strings)
{
menuItem = new MenuItem (str);
menuItem.Show ();
menu.Append (menuItem);
}
combo.AppendText (str);
OptionMenu optionMenu = new OptionMenu ();
optionMenu.Menu = menu;
return optionMenu;
combo.Active = 0;
return combo;
}
private void AddRow (Table table, uint row, SizeGroup sizeGroup, string labelText, string [] options)
@ -113,10 +106,10 @@ namespace GtkDemo
AttachOptions.Expand, AttachOptions.Fill,
0, 0);
OptionMenu optionMenu = CreateOptionMenu (options);
ComboBox combo = CreateOptionMenu (options);
sizeGroup.AddWidget (optionMenu);
table.Attach (optionMenu,
sizeGroup.AddWidget (combo);
table.Attach (combo,
1, 2, row, row + 1,
AttachOptions.Expand, AttachOptions.Expand,
0, 0);

View File

@ -79,21 +79,17 @@ namespace GtkDemo
textView.AddChildAtAnchor (button, buttonAnchor);
button.ShowAll ();
OptionMenu option = new OptionMenu ();
Menu menu = new Menu ();
MenuItem menuItem = new MenuItem ("Option 1");
menu.Append (menuItem);
menuItem = new MenuItem ("Option 2");
menu.Append (menuItem);
menuItem = new MenuItem ("Option 3");
menu.Append (menuItem);
option.Menu = menu;
textView.AddChildAtAnchor (option, menuAnchor);
menu.ShowAll ();
ComboBox combo = ComboBox.NewText ();
combo.AppendText ("Option 1");
combo.AppendText ("Option 2");
combo.AppendText ("Option 3");
combo.Active = 0;
HScale scale = new HScale (null);
textView.AddChildAtAnchor (combo, menuAnchor);
HScale scale = new HScale (null);
scale.SetRange (0,100);
scale.SetSizeRequest (70, -1);
scale.SetSizeRequest (70, -1);
textView.AddChildAtAnchor (scale, scaleAnchor);
scale.ShowAll ();

View File

@ -4,9 +4,6 @@ General
DemoMain
- syntax highlighting
DemoApplicationWindow
- ItemFactory stuff
DemoIconFactory
- almost everything
@ -19,9 +16,6 @@ DemoStockBrowser
- missing stockitems for some reason
- remove duplication in ListStore, and use DataFunc's
DemoTextView
- small issue with international text
DemoHyperText
- finish