sample: Update the "test" samples to the new APIs

Accessing Dialog.ActionArea triggers a crash, so some samples fail
because of that.
This commit is contained in:
Bertrand Lorentz 2011-06-18 18:53:06 +02:00
parent 3ff334d0cc
commit 6811075122
12 changed files with 27 additions and 436 deletions

View file

@ -19,13 +19,13 @@ EXTRA_DIST = $(sources) ChangeLog
sources = \ sources = \
TestCheckButton.cs \ TestCheckButton.cs \
TestColorSelection.cs \ TestColorSelection.cs \
TestRadioButton.cs \ TestComboBox.cs \
TestRange.cs \
TestStatusbar.cs \
TestDialog.cs \ TestDialog.cs \
TestFlipping.cs \ TestFlipping.cs \
TestRadioButton.cs \
TestRange.cs \
TestSizeGroup.cs \ TestSizeGroup.cs \
TestComboBox.cs \ TestStatusbar.cs \
WidgetViewer.cs WidgetViewer.cs
build_sources = $(addprefix $(srcdir)/, $(sources)) build_sources = $(addprefix $(srcdir)/, $(sources))

View file

@ -27,8 +27,8 @@ namespace WidgetViewer {
window.ColorSelection.HasPalette = true; window.ColorSelection.HasPalette = true;
window.SetDefaultSize (250, 200); window.SetDefaultSize (250, 200);
window.VBox.PackStart (options, false, false, 0); window.ContentArea.PackStart (options, false, false, 0);
window.VBox.BorderWidth = 10; window.ContentArea.BorderWidth = 10;
check_button = new CheckButton("Show Opacity"); check_button = new CheckButton("Show Opacity");
check_button.Active = true; check_button.Active = true;
@ -59,18 +59,18 @@ namespace WidgetViewer {
window.ColorSelection.HasPalette = ((ToggleButton )o).Active; window.ColorSelection.HasPalette = ((ToggleButton )o).Active;
} }
static string HexFormat (Gdk.Color color) static string HexFormat (Gdk.RGBA color)
{ {
StringBuilder s = new StringBuilder (); StringBuilder s = new StringBuilder ();
ushort[] vals = { color.Red, color.Green, color.Blue }; double[] vals = { color.Red, color.Green, color.Blue };
char[] hexchars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', char[] hexchars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'}; 'A', 'B', 'C', 'D', 'E', 'F'};
s.Append ('#'); s.Append ('#');
foreach (ushort val in vals) { foreach (double val in vals) {
/* Convert to a range of 0-255, then lookup the /* Convert to a range of 0-255, then lookup the
* digit for each half-byte */ * digit for each half-byte */
byte rounded = (byte) (val >> 8); byte rounded = (byte) (val * 255);
s.Append (hexchars[(rounded & 0xf0) >> 4]); s.Append (hexchars[(rounded & 0xf0) >> 4]);
s.Append (hexchars[rounded & 0x0f]); s.Append (hexchars[rounded & 0x0f]);
} }
@ -80,13 +80,13 @@ namespace WidgetViewer {
static void Color_Changed (object o, EventArgs args) static void Color_Changed (object o, EventArgs args)
{ {
Gdk.Color color = window.ColorSelection.CurrentColor; Gdk.RGBA color = window.ColorSelection.CurrentRgba;
Console.WriteLine (HexFormat (color)); Console.WriteLine (HexFormat (color));
} }
static void Color_Selection_OK (object o, EventArgs args) static void Color_Selection_OK (object o, EventArgs args)
{ {
Gdk.Color selected = window.ColorSelection.CurrentColor; Gdk.RGBA selected = window.ColorSelection.CurrentRgba;
window.Hide (); window.Hide ();
Display_Result (selected); Display_Result (selected);
} }
@ -102,18 +102,17 @@ namespace WidgetViewer {
window.ShowAll (); window.ShowAll ();
} }
static void Display_Result (Gdk.Color color) static void Display_Result (Gdk.RGBA color)
{ {
dialog = new Dialog (); dialog = new Dialog ();
dialog.Title = "Selected Color: " + HexFormat (color); dialog.Title = "Selected Color: " + HexFormat (color);
dialog.HasSeparator = true;
DrawingArea da = new DrawingArea (); DrawingArea da = new DrawingArea ();
da.ModifyBg (StateType.Normal, color); da.OverrideBackgroundColor (StateFlags.Normal, color);
dialog.VBox.BorderWidth = 10; dialog.ContentArea.BorderWidth = 10;
dialog.VBox.PackStart (da, true, true, 10); dialog.ContentArea.PackStart (da, true, true, 10);
dialog.SetDefaultSize (200, 200); dialog.SetDefaultSize (200, 200);
Button button = new Button (Stock.Ok); Button button = new Button (Stock.Ok);

View file

@ -25,9 +25,11 @@ namespace WidgetViewer {
box2.BorderWidth = 10; box2.BorderWidth = 10;
box1.PackStart (box2, true, true, 0); box1.PackStart (box2, true, true, 0);
ComboBoxEntry combo = new Gtk.ComboBoxEntry (new string[] {"Foo", "Bar"}); ComboBoxText combo = ComboBoxText.NewWithEntry ();
combo.AppendText ("Foo");
combo.AppendText ("Bar");
combo.Changed += new EventHandler (OnComboActivated); combo.Changed += new EventHandler (OnComboActivated);
combo.Entry.Changed += new EventHandler (OnComboEntryChanged); ((Entry)combo.Child).Changed += new EventHandler (OnComboEntryChanged);
box2.PackStart (combo, true, true, 0); box2.PackStart (combo, true, true, 0);
HSeparator separator = new HSeparator (); HSeparator separator = new HSeparator ();

View file

@ -34,10 +34,6 @@ namespace WidgetViewer {
toggle_button.Clicked += new EventHandler (Label_Toggle); toggle_button.Clicked += new EventHandler (Label_Toggle);
window.ActionArea.PackStart (toggle_button, true, true, 0); window.ActionArea.PackStart (toggle_button, true, true, 0);
toggle_button = new ToggleButton ("Toggle Separator");
toggle_button.Clicked += new EventHandler (Separator_Toggle);
window.ActionArea.PackStart (toggle_button, true, true, 0);
window.ShowAll (); window.ShowAll ();
return window; return window;
@ -58,18 +54,13 @@ namespace WidgetViewer {
if (label == null) { if (label == null) {
label = new Label ("This is Text label inside a Dialog"); label = new Label ("This is Text label inside a Dialog");
label.SetPadding (10, 10); label.SetPadding (10, 10);
window.VBox.PackStart (label, true, true, 0); window.ContentArea.PackStart (label, true, true, 0);
label.Show (); label.Show ();
} else { } else {
label.Destroy (); label.Destroy ();
label = null; label = null;
} }
} }
static void Separator_Toggle (object o, EventArgs args)
{
window.HasSeparator = (!((ToggleButton) o).Active);
}
} }
} }

View file

@ -1,67 +0,0 @@
//
// TestFileSelection.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
//
using System;
using Gtk;
namespace WidgetViewer {
public class TestFileSelection
{
static FileSelection window = null;
static ToggleButton toggle_button = null;
static CheckButton check_button = null;
public static Gtk.Window Create ()
{
window = new FileSelection ("File Selection Dialog");
window.HideFileopButtons ();
window.OkButton.Clicked += new EventHandler (file_selection_ok);
window.CancelButton.Clicked += new EventHandler (file_selection_cancel);
check_button = new CheckButton ("Show Fileops");
check_button.Toggled += new EventHandler (show_fileops);
window.ActionArea.PackStart (check_button, false, false, 0);
toggle_button = new ToggleButton ("Select Multiple");
toggle_button.Clicked += new EventHandler (select_multiple);
window.ActionArea.PackStart (toggle_button, false, false, 0);
window.ShowAll ();
return window;
}
static void file_selection_ok (object o, EventArgs args)
{
Gtk.FileSelection.FSButton fsbutton = (Gtk.FileSelection.FSButton) o;
Console.WriteLine ("ok button clicked!");
fsbutton.FileSelection.Destroy ();
}
static void show_fileops (object o, EventArgs args)
{
if (((ToggleButton) o).Active)
window.ShowFileopButtons ();
else
window.HideFileopButtons ();
}
static void select_multiple (object o, EventArgs args)
{
window.SelectMultiple = toggle_button.Active;
}
static void file_selection_cancel (object o, EventArgs args)
{
window.Destroy ();
}
}
}

View file

@ -27,10 +27,10 @@ namespace WidgetViewer {
label = new Label ("Label direction: <b>Left-to-right</b>"); label = new Label ("Label direction: <b>Left-to-right</b>");
label.UseMarkup = true; label.UseMarkup = true;
label.SetPadding (3, 3); label.SetPadding (3, 3);
window.VBox.PackStart (label, true, true, 0); window.ContentArea.PackStart (label, true, true, 0);
check_button = new CheckButton ("Toggle label direction"); check_button = new CheckButton ("Toggle label direction");
window.VBox.PackStart (check_button, true, true, 2); window.ContentArea.PackStart (check_button, true, true, 2);
if (window.Direction == TextDirection.Ltr) if (window.Direction == TextDirection.Ltr)
check_button.Active = true; check_button.Active = true;

View file

@ -1,142 +0,0 @@
//
// TestMenus.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
//
using System;
using Gtk;
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 ("foo");
menuitem.Submenu = menu;
menubar.Append (menuitem);
menuitem = new MenuItem ("bar");
menuitem.Submenu = Create_Menu (3, true);
menubar.Append (menuitem);
Image image = new Image (Stock.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 (box2, 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 (Stock.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)
{
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);
menuitem = new RadioMenuItem (group, label);
group = ((RadioMenuItem) menuitem).Group;
menuitem = new MenuItem (label);
menu.Append (menuitem);
if (i == 3)
menuitem.Sensitive = false;
Menu child = Create_Menu ((depth - 1), true);
if (child != null)
menuitem.Submenu = child;
}
return menu;
}
static void Close_Button (object o, EventArgs args)
{
window.Destroy ();
}
}
}

View file

@ -32,14 +32,12 @@ namespace WidgetViewer {
HScale hscale = new HScale (adjustment); HScale hscale = new HScale (adjustment);
hscale.SetSizeRequest (150, -1); hscale.SetSizeRequest (150, -1);
((Range) hscale).UpdatePolicy = UpdateType.Delayed;
hscale.Digits = 1; hscale.Digits = 1;
hscale.DrawValue = true; hscale.DrawValue = true;
box2.PackStart (hscale, true, true, 0); box2.PackStart (hscale, true, true, 0);
HScrollbar hscrollbar = new HScrollbar (adjustment); HScrollbar hscrollbar = new HScrollbar (adjustment);
((Range) hscrollbar).UpdatePolicy = UpdateType.Continuous;
box2.PackStart (hscrollbar, true, true, 0); box2.PackStart (hscrollbar, true, true, 0);
hscale = new HScale (adjustment); hscale = new HScale (adjustment);

View file

@ -23,7 +23,7 @@ namespace WidgetViewer {
window.Resizable = false; window.Resizable = false;
VBox vbox = new VBox (false, 5); VBox vbox = new VBox (false, 5);
window.VBox.PackStart (vbox, true, true, 0); window.ContentArea.PackStart (vbox, true, true, 0);
vbox.BorderWidth = 5; vbox.BorderWidth = 5;
size_group = new SizeGroup (SizeGroupMode.Horizontal); size_group = new SizeGroup (SizeGroupMode.Horizontal);
@ -85,7 +85,7 @@ namespace WidgetViewer {
option_menu.Menu = menu; option_menu.Menu = menu;
return option_menu;*/ return option_menu;*/
ComboBox combo_box = new ComboBox (); ComboBoxText combo_box = new ComboBoxText ();
foreach (string str in strings) { foreach (string str in strings) {
combo_box.AppendText (str); combo_box.AppendText (str);
} }

View file

@ -1,132 +0,0 @@
//
// TestToolbar.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
//
using System;
using Gtk;
namespace WidgetViewer {
public class TestToolbar {
static Window window = null;
static Toolbar toolbar = null;
static bool showTooltips = true;
public static Gtk.Window Create ()
{
window = new Window ("Toolbar");
window.Resizable = false;
toolbar = new Toolbar ();
toolbar.InsertStock (Stock.New, "Stock icon: New", "Toolbar/New",
new SignalFunc (set_small_icon), IntPtr.Zero, -1);
toolbar.InsertStock (Stock.Open, "Stock icon: Open", "Toolbar/Open",
new SignalFunc (set_large_icon), IntPtr.Zero, -1);
toolbar.AppendSpace ();
toolbar.AppendItem ("Toggle tooltips", "toggle showing of tooltips", "Toolbar/Tooltips",
new Image (Stock.DialogInfo, IconSize.LargeToolbar),
new SignalFunc (toggle_tooltips));
toolbar.AppendSpace ();
toolbar.AppendItem ("Horizontal", "Horizontal layout", "Toolbar/Horizontal",
new Image (Stock.GoForward, IconSize.LargeToolbar),
new SignalFunc (set_horizontal));
toolbar.AppendItem ("Vertical", "Vertical layout", "Toolbar/Vertical",
new Image (Stock.GoUp, IconSize.LargeToolbar),
new SignalFunc (set_vertical));
toolbar.AppendSpace ();
toolbar.AppendItem ("Icons", "Only show icons", "Toolbar/IconsOnly",
new Image (Stock.Home, IconSize.LargeToolbar),
new SignalFunc (set_icon_only));
toolbar.AppendItem ("Text", "Only show Text", "Toolbar/TextOnly",
new Image (Stock.JustifyFill, IconSize.LargeToolbar),
new SignalFunc (set_text_only));
toolbar.AppendItem ("Both", "Show both Icon & Text", "Toolbar/Both",
new Image (Stock.Index, IconSize.LargeToolbar),
new SignalFunc (set_both));
toolbar.AppendItem ("Both (Horizontal)", "Show Icon & Text horizontally", "Toolbar/BothHoriz",
new Image (Stock.Index, IconSize.LargeToolbar),
new SignalFunc (set_both_horiz));
toolbar.AppendSpace ();
toolbar.InsertStock (Stock.Close, "Stock icon: Close", "Toolbar/Close",
new SignalFunc (Close_Button), IntPtr.Zero, -1);
window.Add (toolbar);
window.ShowAll ();
return window;
}
static void set_small_icon ()
{
toolbar.IconSize = IconSize.SmallToolbar;
}
static void set_large_icon ()
{
toolbar.IconSize = IconSize.LargeToolbar;
}
static void set_icon_only ()
{
toolbar.ToolbarStyle = ToolbarStyle.Icons;
}
static void set_text_only ()
{
toolbar.ToolbarStyle = ToolbarStyle.Text;
}
static void set_horizontal ()
{
toolbar.Orientation = Orientation.Horizontal;
}
static void set_vertical ()
{
toolbar.Orientation = Orientation.Vertical;
}
static void set_both ()
{
toolbar.ToolbarStyle = ToolbarStyle.Both;
}
static void set_both_horiz ()
{
toolbar.ToolbarStyle = ToolbarStyle.BothHoriz;
}
static void toggle_tooltips ()
{
if (showTooltips == true)
showTooltips = false;
else
showTooltips = true;
toolbar.Tooltips = showTooltips;
Console.WriteLine ("Show tooltips: " + showTooltips);
}
static void Close_Button ()
{
window.Destroy ();
}
}
}

View file

@ -1,34 +0,0 @@
//
// TestToolTip.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
//
using System;
using Gtk;
namespace WidgetViewer {
public class TestToolTip
{
static Window window = null;
static Tooltips tooltips = null;
public Gtk.Window Create ()
{
window = new Window ("Tooltips");
window.DefaultSize = new Gdk.Size (200, 150);
tooltips = new Tooltips ();
return window;
}
static void Window_Delete (object o, EventArgs args)
{
window.Destroy ();
}
}
}

View file

@ -41,15 +41,11 @@ namespace WidgetViewer {
AddButton ("Check Buttons", new EventHandler (Check_Buttons)); AddButton ("Check Buttons", new EventHandler (Check_Buttons));
AddButton ("Color Selection", new EventHandler (Color_Selection)); AddButton ("Color Selection", new EventHandler (Color_Selection));
AddButton ("Combo Box", new EventHandler (Combo_Box)); AddButton ("Combo Box", new EventHandler (Combo_Box));
AddButton ("New Combo Box", new EventHandler (New_Combo_Box));
AddButton ("Dialog", new EventHandler (Dialog)); 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 ("Radio Buttons", new EventHandler (Radio_Buttons));
AddButton ("Range Controls", new EventHandler (Range_Controls)); AddButton ("Range Controls", new EventHandler (Range_Controls));
AddButton ("Size Groups", new EventHandler (Size_Groups)); AddButton ("Size Groups", new EventHandler (Size_Groups));
AddButton ("Statusbar", new EventHandler (Statusbar)); AddButton ("Statusbar", new EventHandler (Statusbar));
AddButton ("Toolbar", new EventHandler (Toolbar));
box1.PackStart (new HSeparator (), false, false, 0); box1.PackStart (new HSeparator (), false, false, 0);
@ -107,11 +103,6 @@ namespace WidgetViewer {
AddWindow (TestColorSelection.Create ()); AddWindow (TestColorSelection.Create ());
} }
static void File_Selection (object o, EventArgs args)
{
//AddWindow (TestFileSelection.Create ());
}
static void Radio_Buttons (object o, EventArgs args) static void Radio_Buttons (object o, EventArgs args)
{ {
AddWindow (TestRadioButton.Create ()); AddWindow (TestRadioButton.Create ());
@ -127,11 +118,6 @@ namespace WidgetViewer {
AddWindow (TestStatusbar.Create ()); AddWindow (TestStatusbar.Create ());
} }
static void Toolbar (object o, EventArgs args)
{
//AddWindow (TestToolbar.Create ());
}
static void Dialog (object o, EventArgs args) static void Dialog (object o, EventArgs args)
{ {
AddWindow (TestDialog.Create ()); AddWindow (TestDialog.Create ());
@ -142,24 +128,14 @@ namespace WidgetViewer {
AddWindow (TestFlipping.Create ()); AddWindow (TestFlipping.Create ());
} }
static void Menus (object o, EventArgs args)
{
//AddWindow (TestMenus.Create ());
}
static void Size_Groups (object o, EventArgs args) static void Size_Groups (object o, EventArgs args)
{ {
AddWindow (TestSizeGroup.Create ()); AddWindow (TestSizeGroup.Create ());
} }
static void New_Combo_Box (object o, EventArgs args) static void Combo_Box (object o, EventArgs args)
{ {
AddWindow (TestComboBox.Create ()); AddWindow (TestComboBox.Create ());
} }
static void Combo_Box (object o, EventArgs args)
{
AddWindow (TestCombo.Create ());
}
} }
} }