[Mono-winforms-list] Patch for MessageBox and XplatUIX11

Ashwin Bharambe Ashwin Bharambe <ashwinb@gmail.com>
Sat, 18 Dec 2004 20:20:30 -0500

Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi all,

Attached is a patch for:
 - a small fix to MessageBox bug (setting Visible = false before
calling ShowDialog)
 - adds modal support for dialog windows (XplatUIX11)

As a result of this a simple MessageBox.Show("text", "caption") dialog
works fine on my linux box.


PS: Do let me know about the procedure and the granularity of sending
patches. I think this is probably too small a granularity for sending

Content-Type: text/x-patch; name="mboxmodalx11.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="mboxmodalx11.patch"

Index: XplatUIX11.cs
--- XplatUIX11.cs=09(revision 37928)
+++ XplatUIX11.cs=09(working copy)
@@ -66,6 +66,12 @@
 =09=09=09internal int=09interval;=09=09=09// in milliseconds, how long to =
hold before hover is generated
 =09=09=09internal int=09hevent;=09=09=09=09// X Atom
+=09=09internal enum NetWindowManagerState {
+=09=09=09Remove =3D 0,
+=09=09=09Add =3D 1,
+=09=09=09Toggle =3D 2
 =09=09#endregion=09// Structure Definitions
 =09=09#region Local Variables
@@ -690,11 +696,29 @@
 =09=09=09// We do nothing; On X11 SetModal is used to create modal dialogs=
, on Win32 this function is used (see comment there)
-=09=09internal override void SetModal(IntPtr handle, bool Modal) {
-=09=09=09// We need to use the Motif window manager hints to build modal s=
tuff; see freedesktop.org
-=09=09=09throw new NotImplementedException("Finish me");
+=09=09[MonoTODO("We may want to cache the XInternAtom calls here")]
+=09=09internal override void SetModal(IntPtr handle, bool Modal)=20
+=09=09=09XEvent xev =3D new XEvent();
+=09=09=09XClientMessageEvent client =3D xev.ClientMessageEvent;
+=09=09=09client.type =3D XEventName.ClientMessage;
+=09=09=09client.serial =3D 0;
+=09=09=09client.send_event =3D true;
+=09=09=09client.window =3D handle;
+=09=09=09client.message_type =3D (IntPtr) net_wm_state;
+=09=09=09client.format =3D 32;
+=09=09=09client.ptr1 =3D (IntPtr) (Modal ? NetWindowManagerState.Add : Net=
+=09=09=09client.ptr2 =3D (IntPtr) XInternAtom(DisplayHandle, "_NET_WM_STAT=
E_MODAL", false);
+=09=09=09client.ptr3 =3D (IntPtr) 0;
+=09=09=09client.ptr4 =3D (IntPtr) 0;
+=09=09=09client.ptr5 =3D (IntPtr) 0;
+=09=09=09XSendEvent(DisplayHandle, root_window, false,=20
+=09=09=09=09=09EventMask.SubstructureRedirectMask | EventMask.Substructure=
NotifyMask, ref xev);
 =09=09internal override void Invalidate (IntPtr handle, Rectangle rc, bool=
 clear) {
 =09=09=09if (clear) {
 =09=09=09=09XClearArea (DisplayHandle, handle, rc.Left, rc.Top, rc.Width, =
rc.Height, true);
Index: MessageBox.cs
--- MessageBox.cs=09(revision 37928)
+++ MessageBox.cs=09(working copy)
@@ -135,6 +135,7 @@
 =09=09=09=09=09InitFormsSize ();
+=09=09=09=09this.Visible =3D false;
 =09=09=09=09this.ShowDialog ();
 =09=09=09=09return this.DialogResult;