diff --git a/sample/test/ChangeLog b/sample/test/ChangeLog new file mode 100644 index 000000000..0b863b7e1 --- /dev/null +++ b/sample/test/ChangeLog @@ -0,0 +1,9 @@ +2002-07-13 Duncan Mak + + * *.cs: Checking in testgtk# to CVS. + + + + + + diff --git a/sample/test/Makefile b/sample/test/Makefile new file mode 100644 index 000000000..0279afff2 --- /dev/null +++ b/sample/test/Makefile @@ -0,0 +1,8 @@ +MCS=mcs + +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 WidgetViewer.cs +clean: + rm -f *.exe *~ diff --git a/sample/test/TestCheckButton.cs b/sample/test/TestCheckButton.cs new file mode 100644 index 000000000..ee71ffd79 --- /dev/null +++ b/sample/test/TestCheckButton.cs @@ -0,0 +1,63 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + public class TestCheckButton + { + static Window window = null; + static CheckButton checked_button = null; + + public static Gtk.Window Create () + { + window = new Window ("GtkCheckButton"); + window.SetDefaultSize (200, 100); + + VBox box1 = new VBox (false, 0); + window.Add (box1); + + VBox box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, true, true, 0); + + checked_button = new CheckButton ("_button1"); + box2.PackStart (checked_button, true, true, 0); + + checked_button = new CheckButton ("button2"); + box2.PackStart (checked_button, true, true, 0); + + checked_button = new CheckButton ("button3"); + box2.PackStart (checked_button, true, true, 0); + + checked_button = new CheckButton ("Inconsistent"); + checked_button.Inconsistent = true; + box2.PackStart (checked_button, true, true, 0); + + HSeparator separator = new HSeparator (); + + box1.PackStart (separator, false, false, 0); + + box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, false, false, 0); + + Button button = new Button ("close"); + button.Clicked += new EventHandler (Close_Button); + button.CanDefault = true; + + box2.PackStart (button, true, true, 0); + button.GrabDefault (); + return window; + } + + static void Close_Button (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + window.Destroy (); + sa.RetVal = true; + } + } +} + + diff --git a/sample/test/TestColorSelection.cs b/sample/test/TestColorSelection.cs new file mode 100644 index 000000000..b5916c0f4 --- /dev/null +++ b/sample/test/TestColorSelection.cs @@ -0,0 +1,67 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + public class TestColorSelection + { + static ColorSelectionDialog window = null; + + public static Gtk.Window Create () + { + HBox options = new HBox (false, 0); + CheckButton check_button = null; + + window = new ColorSelectionDialog ("Color selection dialog"); + window.ColorSelection.HasOpacityControl = true; + window.ColorSelection.HasPalette = true; + + window.SetDefaultSize (250, 200); + window.VBox.PackStart (options, false, false, 0); + window.VBox.BorderWidth = 10; + + check_button = new CheckButton("Show Opacity"); + options.PackStart (check_button, false, false, 0); + check_button.Toggled += new EventHandler (Opacity_Callback); + + check_button = new CheckButton("Show Palette"); + options.PackEnd (check_button, false, false, 0); + check_button.Toggled += new EventHandler (Palette_Callback); + + window.ColorSelection.ColorChanged += new EventHandler (Color_Changed); + window.OkButton.Clicked += new EventHandler (Color_Selection_OK); + window.CancelButton.Clicked += new EventHandler (Color_Selection_Cancel); + + options.ShowAll (); + + return window; + } + + static void Opacity_Callback (object o, EventArgs args) + { + window.ColorSelection.HasOpacityControl = ((ToggleButton )o).Active; + } + + static void Palette_Callback (object o, EventArgs args) + { + window.ColorSelection.HasPalette = ((ToggleButton )o).Active; + } + + static void Color_Changed (object o, EventArgs args) + { + Gdk.Color color = window.ColorSelection.CurrentColor; + } + + static void Color_Selection_OK (object o, EventArgs args) + { + Gdk.Color color = window.ColorSelection.CurrentColor; + window.ColorSelection.CurrentColor = color; + } + + static void Color_Selection_Cancel (object o, EventArgs args) + { + window.Destroy (); + } + } +} diff --git a/sample/test/TestDialog.cs b/sample/test/TestDialog.cs new file mode 100644 index 000000000..fe151eb76 --- /dev/null +++ b/sample/test/TestDialog.cs @@ -0,0 +1,70 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + public class TestDialog + { + static Dialog window = null; + static Label label = null; + + public static Gtk.Window Create () + { + window = new Dialog (); + window.Response += new EventHandler (Print_Response); + + window.Title = "GtkDialog"; + Button button = new ToggleButton ("OK"); + button.Clicked += new EventHandler (Close_Button); + button.CanDefault = true; + window.ActionArea.PackStart (button, true, true, 0); + button.GrabDefault (); + + ToggleButton toggle_button = new ToggleButton ("Toggle Label"); + toggle_button.Clicked += new EventHandler (Label_Toggle); + window.ActionArea.PackStart (toggle_button, true, true, 0); + + toggle_button = new ToggleButton ("Toggle Separator"); + button.Clicked += new EventHandler (Separator_Toggle); + window.ActionArea.PackStart (toggle_button, true, true, 0); + + window.ShowAll (); + + return window; + } + + static void Close_Button (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + window.Destroy (); + sa.RetVal = true; + } + + static void Print_Response (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + Console.WriteLine ("Received response signal: " + sa.Args [1]); + sa.RetVal = true; + } + + static void Label_Toggle (object o, EventArgs args) + { + if (label == null) { + Console.WriteLine ("Null label"); + label = new Label ("Text label"); + label.SetPadding (10, 10); + window.VBox.PackStart (label, true, true, 0); + label.Show (); + } else { + label.Destroy (); + label = null; + } + } + + static void Separator_Toggle (object o, EventArgs args) + { + window.HasSeparator = ((ToggleButton) o).Active; + } + } +} diff --git a/sample/test/TestFileSelection.cs b/sample/test/TestFileSelection.cs new file mode 100644 index 000000000..810fb7871 --- /dev/null +++ b/sample/test/TestFileSelection.cs @@ -0,0 +1,58 @@ +using System; + +using Gtk; +using GtkSharp; + +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) + { + Console.WriteLine (window.Selections); + } + + 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) + { + SignalArgs sa = (SignalArgs) args; + window.Destroy (); + sa.RetVal = true; + } + } +} + diff --git a/sample/test/TestRadioButton.cs b/sample/test/TestRadioButton.cs new file mode 100644 index 000000000..654658642 --- /dev/null +++ b/sample/test/TestRadioButton.cs @@ -0,0 +1,79 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + public class TestRadioButton + { + static Window window = null; + static RadioButton radio_button = null; + + public static Gtk.Window Create () + { + window = new Window ("GtkRadioButton"); + window.SetDefaultSize (200, 100); + + VBox box1 = new VBox (false, 0); + window.Add (box1); + + VBox box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, true, true, 0); + + radio_button = new RadioButton (new GLib.SList (IntPtr.Zero), "Button 1"); + box2.PackStart (radio_button, true, true, 0); + + radio_button = new RadioButton (radio_button.Group, "Button 2"); + radio_button.Active = true; + box2.PackStart (radio_button, true, true, 0); + + radio_button = new RadioButton (radio_button.Group, "Button 3"); + box2.PackStart (radio_button, true, true, 0); + + radio_button = new RadioButton (radio_button.Group, "Inconsistent"); + radio_button.Inconsistent = true; + box2.PackStart (radio_button, true, true, 0); + + box1.PackStart (new HSeparator (), false, true, 0); + + box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, true, true, 0); + + radio_button = new RadioButton (new GLib.SList (IntPtr.Zero), "Button 4"); + radio_button.Mode = false; + box2.PackStart (radio_button, true, true, 0); + + radio_button = new RadioButton (radio_button.Group, "Button 5"); + radio_button.Active = true; + radio_button.Mode = false; + box2.PackStart (radio_button, true, true, 0); + + radio_button = new RadioButton (radio_button.Group, "Button 6"); + radio_button.Mode = false; + box2.PackStart (radio_button, true, true, 0); + + box1.PackStart (new HSeparator (), false, true, 0); + + box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, false, true, 0); + + Button button = new Button ("_Close"); + button.Clicked += new EventHandler (Close_Button); + box2.PackStart (button, true, true, 0); + button.CanDefault = true; + button.GrabDefault (); + + return window; + } + + static void Close_Button (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + window.Destroy (); + sa.RetVal = true; + } + } +} diff --git a/sample/test/TestRange.cs b/sample/test/TestRange.cs new file mode 100644 index 000000000..b25fea845 --- /dev/null +++ b/sample/test/TestRange.cs @@ -0,0 +1,92 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + + public class TestRange + { + static Window window = null; + + public static Gtk.Window Create () + { + window = new Window ("GtkRange"); + window.SetDefaultSize (250, 200); + + VBox box1 = new VBox (false, 0); + window.Add (box1); + + VBox box2 = new VBox (false, 0); + box2.BorderWidth = 10; + box1.PackStart (box2, true, true, 0); + + Adjustment adjustment = new Adjustment (0.0, 0.0, 101.0, 0.1, 1.0, 1.0); + + HScale hscale = new HScale (adjustment); + hscale.SetSizeRequest (150, -1); + ((Range) hscale).UpdatePolicy = UpdateType.Delayed; + + hscale.Digits = 1; + hscale.DrawValue = true; + box2.PackStart (hscale, true, true, 0); + + HScrollbar hscrollbar = new HScrollbar (adjustment); + ((Range) hscrollbar).UpdatePolicy = UpdateType.Continuous; + box2.PackStart (hscrollbar, true, true, 0); + + hscale = new HScale (adjustment); + hscale.DrawValue = true; + hscale.FormatValue += new EventHandler (reformat_value); + + box2.PackStart (hscale, true, true, 0); + + HBox hbox = new HBox (false, 0); + VScale vscale = new VScale (adjustment); + vscale.SetSizeRequest (-1, 200); + vscale.Digits = 2; + vscale.DrawValue = true; + hbox.PackStart (vscale, true, true, 0); + + vscale = new VScale (adjustment); + vscale.SetSizeRequest (-1, 200); + vscale.Digits = 2; + vscale.DrawValue = true; + ((Range) vscale).Inverted = true; + hbox.PackStart (vscale, true, true, 0); + + vscale = new VScale (adjustment); + vscale.DrawValue = true; + vscale.FormatValue += new EventHandler (reformat_value); + hbox.PackStart (vscale, true, true, 0); + + box2.PackStart (hbox, true, true, 0); + + box1.PackStart (new HSeparator (), false, true, 0); + + box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, false, true, 0); + + Button button = new Button ("_Close"); + button.Clicked += new EventHandler (Close_Button); + box2.PackStart (button, true, true, 0); + button.CanDefault = true; + button.GrabDefault (); + + window.ShowAll (); + return window; + } + + static void Close_Button (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + window.Destroy (); + sa.RetVal = true; + } + + static void reformat_value (object o, EventArgs args) + { + } + } +} diff --git a/sample/test/TestStatusbar.cs b/sample/test/TestStatusbar.cs new file mode 100644 index 000000000..644dbedf5 --- /dev/null +++ b/sample/test/TestStatusbar.cs @@ -0,0 +1,74 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + + public class TestStatusbar + { + static Window window = null; + static Statusbar statusbar = null; + static int counter = 1; + + public static Gtk.Window Create () + { + window = new Window ("Statusbar"); + window.SetDefaultSize (150, 100); + + VBox box1 = new VBox (false, 0); + window.Add (box1); + + VBox box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, true, true, 0); + + statusbar = new Statusbar (); + box1.PackEnd (statusbar, true, true, 0); + statusbar.TextPopped += new EventHandler (statusbar_popped); + + Button button = new Button ("push"); + box2.PackStart (button, false, false, 0); + button.Clicked += new EventHandler (statusbar_pushed); + + button = new Button ("pop"); + box2.PackStart (button, false, false, 0); + button.Clicked += new EventHandler (statusbar_popped); + + box1.PackStart (new HSeparator (), false, true, 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); + button.CanDefault = true; + button.GrabDefault (); + + window.ShowAll (); + return window; + } + + static void statusbar_popped (object o, EventArgs args) + { + statusbar.Pop ((uint) 1); + } + + static void statusbar_pushed (object o, EventArgs args) + { + if (counter < 1024) { + statusbar.Push (1, String.Format ("Push #{0}", counter)); + counter ++; + } + } + + static void Close_Button (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + window.Destroy (); + sa.RetVal = true; + } + } +} diff --git a/sample/test/TestToolbar.cs b/sample/test/TestToolbar.cs new file mode 100644 index 000000000..a4828eb72 --- /dev/null +++ b/sample/test/TestToolbar.cs @@ -0,0 +1,112 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + public class TestToolbar { + + static Window window = null; + static Toolbar toolbar = null; + + public static Gtk.Window Create () + { + window = new Window ("Toolbar"); + + 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.AppendItem ("Horizontal", "Horizontal layout", "Toolbar/Horizontal", + new Image (Stock.GoForward, IconSize.LargeToolbar), + new SignalFunc (set_horizontal), IntPtr.Zero); + + toolbar.AppendItem ("Vertical", "Vertical layout", "Toolbar/Vertical", + new Image (Stock.GoUp, IconSize.LargeToolbar), + new SignalFunc (set_vertical), IntPtr.Zero); + + toolbar.AppendSpace (); + + toolbar.AppendItem ("Icons", "Only show icons", "Toolbar/IconsOnly", + new Image (Stock.Home, IconSize.LargeToolbar), + new SignalFunc (set_icon_only), IntPtr.Zero); + + toolbar.AppendItem ("Text", "Only show Text", "Toolbar/TextOnly", + new Image (Stock.JustifyFill, IconSize.LargeToolbar), + new SignalFunc (set_text_only), IntPtr.Zero); + + toolbar.AppendItem ("Both", "Show both Icon & Text", "Toolbar/Both", + new Image (Stock.Index, IconSize.LargeToolbar), + new SignalFunc (set_both), IntPtr.Zero); + + toolbar.AppendItem ("Both (Horizontal)", "Show Icon & Text horizontally", "Toolbar/BothHoriz", + new Image (Stock.Index, IconSize.LargeToolbar), + new SignalFunc (set_both_horiz), IntPtr.Zero); + + 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 () + { + Console.WriteLine ("set small icon"); + toolbar.IconSize = IconSize.SmallToolbar; + } + + static void set_large_icon () + { + Console.WriteLine ("set large icon"); + toolbar.IconSize = IconSize.LargeToolbar; + } + + static void set_icon_only () + { + Console.WriteLine ("set icon only"); + toolbar.Style = ToolbarStyle.Icons; + } + + static void set_text_only () + { + Console.WriteLine ("set text only"); + toolbar.Style = ToolbarStyle.Text; + } + + static void set_horizontal () + { + Console.WriteLine ("set horizontal"); + toolbar.Orientation = Orientation.Horizontal; + } + + static void set_vertical () + { + Console.WriteLine ("set vertical"); + toolbar.Orientation = Orientation.Vertical; + } + + static void set_both () + { + Console.WriteLine ("set both"); + toolbar.Style = ToolbarStyle.Both; + } + + static void set_both_horiz () + { + Console.WriteLine ("set both horiz."); + toolbar.Style = ToolbarStyle.BothHoriz; + } + + static void Close_Button () + { + window.Destroy (); + } + } +} diff --git a/sample/test/TestTooltip.cs b/sample/test/TestTooltip.cs new file mode 100644 index 000000000..b8babfd2e --- /dev/null +++ b/sample/test/TestTooltip.cs @@ -0,0 +1,31 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + public class TestToolTip + { + static Window window = null; + static Tooltips tooltips = null; + + public Gtk.Window Create () + { + window = new Window ("Tooltips"); + window.Width = 200; + tooltips = new Tooltips (); + + window.Data ("tooltips", tooltip); + + return window; + } + + static void Window_Delete (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + window.Destroy (); + sa.RetVal = true; + } + } +} + diff --git a/sample/test/WidgetViewer.cs b/sample/test/WidgetViewer.cs new file mode 100644 index 000000000..2f0f1c672 --- /dev/null +++ b/sample/test/WidgetViewer.cs @@ -0,0 +1,148 @@ +using System; + +using Gtk; +using GtkSharp; + +namespace WidgetViewer { + + public class Viewer + { + static Window window = null; + static Window viewer = null; + static Button button = null; + + static void Main () + { + Application.Init (); + window = new Window ("Gtk# Widget viewer"); + window.DeleteEvent += new EventHandler (Window_Delete); + window.SetDefaultSize (250, 200); + + VBox box1 = new VBox (false, 0); + window.Add (box1); + + VBox box2 = new VBox (false, 5); + box2.BorderWidth = 10; + box1.PackStart (box2, true, true, 0); + + button = new Button ("Check Buttons"); + button.Clicked += new EventHandler (Check_Buttons); + box2.PackStart (button, false, false, 0); + + button = new Button ("Color Selection"); + button.Clicked += new EventHandler (Color_Selection); + box2.PackStart (button, false, false, 0); + + button = new Button ("Dialog"); + button.Clicked += new EventHandler (Dialog); + box2.PackStart (button, false, false, 0); + + button = new Button ("File Selection"); + button.Clicked += new EventHandler (File_Selection); + box2.PackStart (button, false, false, 0); + + button = new Button ("Radio Buttons"); + button.Clicked += new EventHandler (Radio_Buttons); + box2.PackStart (button, false, false, 0); + + button = new Button ("Range Controls"); + button.Clicked += new EventHandler (Range_Controls); + box2.PackStart (button, false, false, 0); + + button = new Button ("Statusbar"); + button.Clicked += new EventHandler (Statusbar); + box2.PackStart (button, false, false, 0); + + button = new Button ("Toolbar"); + button.Clicked += new EventHandler (Toolbar); + box2.PackStart (button, false, false, 0); + + box1.PackStart (new HSeparator (), false, false, 0); + + box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, false, false, 0); + + Button close_button = new Button ("_Close"); + close_button.Clicked += new EventHandler (Close_Button); + box2.PackStart (close_button, true, true, 0); + + window.ShowAll (); + Application.Run (); + } + + static void Window_Delete (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + Application.Quit (); + sa.RetVal = true; + } + + static void Viewer_Delete (object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + viewer.Destroy (); + sa.RetVal = true; + } + + static void Close_Button (object o, EventArgs args) + { + Window_Delete (o, args); + } + + static void Check_Buttons (object o, EventArgs args) + { + viewer = TestCheckButton.Create (); + viewer.ShowAll (); + } + + static void Color_Selection (object o, EventArgs args) + { + viewer = TestColorSelection.Create (); + viewer.ShowAll (); + } + + static void File_Selection (object o, EventArgs args) + { + viewer = TestFileSelection.Create (); + viewer.DeleteEvent += new EventHandler (Viewer_Delete); + viewer.ShowAll (); + } + + static void Radio_Buttons (object o, EventArgs args) + { + viewer = TestRadioButton.Create (); + viewer.DeleteEvent += new EventHandler (Viewer_Delete); + viewer.ShowAll (); + } + + static void Range_Controls (object o, EventArgs args) + { + viewer = TestRange.Create (); + viewer.DeleteEvent += new EventHandler (Viewer_Delete); + viewer.ShowAll (); + } + + static void Statusbar (object o, EventArgs args) + { + viewer = TestStatusbar.Create (); + viewer.DeleteEvent += new EventHandler (Viewer_Delete); + viewer.ShowAll (); + } + + static void Toolbar (object o, EventArgs args) + { + viewer = TestToolbar.Create (); + viewer.DeleteEvent += new EventHandler (Window_Delete); + viewer.ShowAll (); + } + + static void Dialog (object o, EventArgs args) + { + viewer = TestDialog.Create (); + viewer.DeleteEvent += new EventHandler (Window_Delete); + viewer.ShowAll (); + } + + } +}