2002-07-17 Duncan Mak <duncan@ximian.com>
* Makefile: * WidgetViewer.cs: Added TestMenus.cs * TestMenus.cs: New test for testing menu widgets. svn path=/trunk/gtk-sharp/; revision=5856
This commit is contained in:
parent
4f6a03287c
commit
aa56559530
4 changed files with 165 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
|||
2002-07-17 Duncan Mak <duncan@ximian.com>
|
||||
|
||||
* Makefile:
|
||||
* WidgetViewer.cs: Added TestMenus.cs
|
||||
|
||||
* TestMenus.cs: New test for testing menu widgets.
|
||||
|
||||
2002-07-17 Duncan Mak <duncan@ximian.com>
|
||||
|
||||
* WidgetViewer.cs: Changed the EventArgs stuff to match Mike's
|
||||
|
|
|
@ -4,6 +4,7 @@ all:
|
|||
$(MCS) -o WidgetViewer.exe -r glib-sharp -r gdk-sharp -r gtk-sharp \
|
||||
TestCheckButton.cs TestColorSelection.cs TestFileSelection.cs TestRadioButton.cs \
|
||||
TestRange.cs TestStatusbar.cs TestToolbar.cs TestDialog.cs TestFlipping.cs \
|
||||
TestMenus.cs \
|
||||
WidgetViewer.cs
|
||||
clean:
|
||||
rm -f *.exe *~
|
||||
|
|
151
sample/test/TestMenus.cs
Normal file
151
sample/test/TestMenus.cs
Normal file
|
@ -0,0 +1,151 @@
|
|||
//
|
||||
// TestMenus.cs
|
||||
//
|
||||
// Author: Duncan Mak (duncan@ximian.com)
|
||||
//
|
||||
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
|
||||
namespace WidgetViewer {
|
||||
public class TestMenus {
|
||||
|
||||
static Window window = null;
|
||||
|
||||
public static Gtk.Window Create ()
|
||||
{
|
||||
window = new Window ("Menus");
|
||||
|
||||
AccelGroup accel_group = new AccelGroup ();
|
||||
window.AddAccelGroup (accel_group);
|
||||
|
||||
VBox box1 = new VBox (false, 0);
|
||||
window.Add (box1);
|
||||
|
||||
MenuBar menubar = new MenuBar ();
|
||||
box1.PackStart (menubar, false, false, 0);
|
||||
|
||||
Menu menu = Create_Menu (2, true);
|
||||
|
||||
MenuItem menuitem = new MenuItem ("test\nline2");
|
||||
|
||||
menuitem.Submenu = menu;
|
||||
menubar.Append (menuitem);
|
||||
|
||||
menuitem = new MenuItem ("foo");
|
||||
menuitem.Submenu = Create_Menu (3, true);
|
||||
menubar.Append (menuitem);
|
||||
|
||||
Image image = new Image ("gtk-help", IconSize.Menu);
|
||||
|
||||
menuitem = new ImageMenuItem ("Help");
|
||||
((ImageMenuItem) menuitem).Image = image;
|
||||
menuitem.Submenu = Create_Menu (4, true);
|
||||
menuitem.RightJustified = true;
|
||||
menubar.Append (menuitem);
|
||||
|
||||
menubar = new MenuBar ();
|
||||
box1.PackStart (menubar, false, true, 0);
|
||||
|
||||
menu = Create_Menu (2, true);
|
||||
|
||||
menuitem = new MenuItem ("Second menu bar");
|
||||
menuitem.Submenu = menu;
|
||||
menubar.Append (menuitem);
|
||||
|
||||
VBox box2 = new VBox (false, 10);
|
||||
box2.BorderWidth = 10;
|
||||
box1.PackStart (box1, true, true, 0);
|
||||
|
||||
menu = Create_Menu (1, false);
|
||||
menu.AccelGroup = accel_group;
|
||||
|
||||
menu.Append (new SeparatorMenuItem ());
|
||||
|
||||
menuitem = new CheckMenuItem ("Accelerate Me");
|
||||
menu.Append (menuitem);
|
||||
menuitem.AddAccelerator ("activate", accel_group, 0xFFBE, 0, AccelFlags.Visible);
|
||||
|
||||
menuitem = new CheckMenuItem ("Accelerator locked");
|
||||
menu.Append (menuitem);
|
||||
menuitem.AddAccelerator ("activate", accel_group, 0xFFBF, 0, AccelFlags.Visible | AccelFlags.Locked);
|
||||
|
||||
menuitem = new CheckMenuItem ("Accelerator Frozen");
|
||||
menu.Append (menuitem);
|
||||
menuitem.AddAccelerator ("activate", accel_group, 0xFFBF, 0, AccelFlags.Visible);
|
||||
menuitem.AddAccelerator ("activate", accel_group, 0xFFC0, 0, AccelFlags.Visible);
|
||||
|
||||
OptionMenu option_menu = new OptionMenu ();
|
||||
option_menu.Menu = menu;
|
||||
option_menu.SetHistory (3);
|
||||
box2.PackStart (option_menu, true, true, 0);
|
||||
|
||||
box1.PackStart (new HSeparator (), false, false, 0);
|
||||
|
||||
box2 = new VBox (false, 10);
|
||||
box2.BorderWidth = 10;
|
||||
box1.PackStart (box2, false, true, 0);
|
||||
|
||||
Button close_button = new Button ("Close");
|
||||
close_button.Clicked += new EventHandler (Close_Button);
|
||||
box2.PackStart (close_button, true, true, 0);
|
||||
|
||||
close_button.CanDefault = true;
|
||||
close_button.GrabDefault ();
|
||||
|
||||
window.ShowAll ();
|
||||
return window;
|
||||
}
|
||||
|
||||
static Menu Create_Menu (int depth, bool tearoff)
|
||||
{
|
||||
Console.WriteLine ("Depth: " + depth);
|
||||
if (depth < 1)
|
||||
return null;
|
||||
|
||||
Menu menu = new Menu ();
|
||||
MenuItem menuitem = null;
|
||||
string label = null;
|
||||
GLib.SList group = new GLib.SList (IntPtr.Zero);
|
||||
|
||||
if (tearoff) {
|
||||
menuitem = new TearoffMenuItem ();
|
||||
menu.Append (menuitem);
|
||||
menuitem.Show ();
|
||||
}
|
||||
|
||||
for (int i = 0, j = 1; i < 5; i++, j++) {
|
||||
|
||||
label = String.Format ("item {0} - {1}", depth, j);
|
||||
Console.WriteLine ("label: " + label);
|
||||
try {
|
||||
menuitem = RadioMenuItem.NewWithLabel (group, label);
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine (e);
|
||||
}
|
||||
|
||||
group = ((RadioMenuItem) menuitem).Group;
|
||||
Console.WriteLine ("Pass");
|
||||
menu.Append (menuitem);
|
||||
|
||||
if (i == 3)
|
||||
menuitem.Sensitive = false;
|
||||
|
||||
menuitem.Submenu = Create_Menu ((depth - 1), true);
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
static void Close_Button (object o, EventArgs args)
|
||||
{
|
||||
SignalArgs sa = (SignalArgs) args;
|
||||
window.Destroy ();
|
||||
sa.RetVal = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,6 +38,7 @@ namespace WidgetViewer {
|
|||
AddButton ("Color Selection", new EventHandler (Color_Selection));
|
||||
AddButton ("Dialog", new EventHandler (Dialog));
|
||||
AddButton ("File Selection", new EventHandler (File_Selection));
|
||||
AddButton ("Menus", new EventHandler (Menus));
|
||||
AddButton ("Radio Buttons", new EventHandler (Radio_Buttons));
|
||||
AddButton ("Range Controls", new EventHandler (Range_Controls));
|
||||
AddButton ("Statusbar", new EventHandler (Statusbar));
|
||||
|
@ -132,5 +133,10 @@ namespace WidgetViewer {
|
|||
{
|
||||
AddWindow (TestFlipping.Create ());
|
||||
}
|
||||
|
||||
static void Menus (object o, EventArgs args)
|
||||
{
|
||||
AddWindow (TestMenus.Create ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue