diff --git a/doc/ChangeLog b/doc/ChangeLog index 6953a3ff7..8a7b75f1f 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2003-10-03 John Luke + + * en/Gnome/Popup.xml: documented w/ simple example + * en/Gtk.Menu.xml: popup example and parameter fix + 2003-09-25 Hector E. Gomez Morales * en/Gtk/Accessible.xml diff --git a/doc/en/Gnome/Popup.xml b/doc/en/Gnome/Popup.xml index 6811bd1f0..88c5ce37a 100644 --- a/doc/en/Gnome/Popup.xml +++ b/doc/en/Gnome/Popup.xml @@ -1,5 +1,5 @@ - + gnome-sharp @@ -9,8 +9,62 @@ Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. - To be added - To be added + Create and display popup and context menus. + + + +using System; +using Gtk; +using GtkSharp; +using Gnome; + +class PopupSample +{ + Program program; + + static void Main (string[] args) + { + new PopupSample (args); + } + + PopupSample (string[] args) + { + program = new Program ("PopupSample", "0.0", Modules.UI, args); + + App app = new App ("PopupSample", "Gnome.Popup sample"); + app.SetDefaultSize (400, 300); + app.DeleteEvent += new DeleteEventHandler (OnAppDelete); + + Menu menu = new Menu (); + MenuItem hello = new MenuItem ("Hello"); + hello.Activated += new EventHandler (OnHelloActivated); + hello.Show (); + menu.Append (hello); + + Label label = new Label ("Right Click me"); + EventBox eventbox = new EventBox (); + eventbox.Add (label); + + app.Contents = eventbox; + + Popup.MenuAttach (menu, eventbox, IntPtr.Zero); + + app.ShowAll (); + program.Run (); + } + + private void OnHelloActivated (object o, EventArgs args) + { + Console.WriteLine ("Hello Activated"); + } + + private void OnAppDelete (object o, DeleteEventArgs args) + { + program.Quit (); + } +} + + System.Object @@ -28,10 +82,10 @@ - To be added + Creates a popup menu out of the specified array. a a - To be added + This method behaves just like , except that it creates an for you and attaches it to the menu object. Use to get the that is created. @@ -49,14 +103,18 @@ - To be added + You can use this function to pop up a menu. a a a a a a - To be added + + When a menu item callback is invoked, the specified user_data will be passed to it. + The and parameters are the same as for , i.e. you can use them to specify a function to position the menu explicitly. If you want the default position (near the mouse), pass for these parameters. + The event parameter is needed to figure out the mouse button that activated the menu and the time at which this happened. If you pass in , then no button and the current time will be used as defaults. + @@ -70,11 +128,11 @@ - To be added + Creates a popup menu out of the specified array. a a a - To be added + Use to pop the menu up, or attach it to a window with . @@ -87,10 +145,10 @@ - To be added + This function is used to retrieve the accelgroup that was created by . a a - To be added + If you want to specify the accelgroup that the popup menu accelerators use, then use . @@ -104,10 +162,10 @@ - To be added + Appends the menu items in to the menu. a a - To be added + @@ -122,11 +180,16 @@ - To be added + Attaches the specified menu to the specified . a a a - To be added + + The menu can then be activated by pressing mouse button 3 over the widget. When a menu item callback is invoked, the specified will be passed to it. + This function requires the widget to have its own window (i.e. ), This function will try to set the flag on the event mask for the widget if it does not have it yet. If this is the case, then the widget must not be realized for it to work. + The popup menu can be attached to different widgets at the same time. A reference count is kept on the popup menu; when all the widgets it is attached to are destroyed, the popup menu will be destroyed as well. + Under the current implementation, setting a popup menu for a widget and then reparenting that widget will cause Bad Things to happen. + @@ -144,7 +207,7 @@ - To be added + You can use this function to pop up a menu modally. a a a @@ -152,7 +215,7 @@ a a a - To be added + Same as , but modal. @@ -161,10 +224,10 @@ - To be added + Creates a new instance. a - To be added + The default constructor for . - \ No newline at end of file + diff --git a/doc/en/Gtk/Menu.xml b/doc/en/Gtk/Menu.xml index d465b4649..de07b60f7 100644 --- a/doc/en/Gtk/Menu.xml +++ b/doc/en/Gtk/Menu.xml @@ -157,15 +157,74 @@ public class MenuApp { The time at which the activation event occurred. - Applications can use this function to display context-sensitive menus, and will typically supply for the , , and parameters. The default menu positioning function will position the menu at the current mouse cursor position. + Applications can use this function to display context-sensitive menus, and will typically supply for the , , and parameters, and for parameter. The default menu positioning function will position the menu at the current mouse cursor position. The parameter should be the mouse button pressed to initiate the menu popup. If the menu popup was initiated by something other than a mouse button press, such as a mouse button release or a keypress, button should be zero(0). - The parameter should be the time stamp of the event that initiated the popup. If such an event is not available, use instead. + The parameter should be the time stamp of the event that initiated the popup. If such an event is not available, use instead. + + +using System; +using Gtk; +using GtkSharp; + +class PopupSample +{ + Window win; + Menu menu; + + static void Main (string[] args) + { + new PopupSample (args); + } + + PopupSample (string[] args) + { + Application.Init (); + + win = new Window ("Menu.Popup sample"); + win.SetDefaultSize (400, 300); + win.DeleteEvent += new DeleteEventHandler (OnWinDelete); + + menu = new Menu (); + MenuItem hello = new MenuItem ("Hello"); + hello.Activated += new EventHandler (OnHelloActivated); + hello.Show (); + menu.Append (hello); + + Label label = new Label ("Right Click me"); + EventBox eventbox = new EventBox (); + eventbox.ButtonPressEvent += new ButtonPressEventHandler (OnEventBoxPressed); + eventbox.Add (label); + + win.Add (eventbox); + + win.ShowAll (); + Application.Run (); + } + + private void OnEventBoxPressed (object o, ButtonPressEventArgs args) + { + if (args.Event.button == 3) + menu.Popup (null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime); + } + + private void OnHelloActivated (object o, EventArgs args) + { + Console.WriteLine ("Hello Activated"); + } + + private void OnWinDelete (object o, DeleteEventArgs args) + { + Application.Quit (); + } +} + +