Author: danw
Date: 2005-10-10 12:14:36 -0400 (Mon, 10 Oct 2005)
New Revision: 51520
Added:
branches/stetic-summit/stetic/libstetic/EmbedWindow.cs
Modified:
branches/stetic-summit/stetic/ChangeLog
branches/stetic-summit/stetic/libstetic/DND.cs
branches/stetic-summit/stetic/libstetic/Makefile.am
branches/stetic-summit/stetic/metacity-sharp/test-preview.cs
branches/stetic-summit/stetic/stetic/Canvas.cs
branches/stetic-summit/stetic/stetic/Palette.cs
branches/stetic-summit/stetic/stetic/Stetic.cs
branches/stetic-summit/stetic/stetic/WidgetFactory.cs
Log:
* libstetic/EmbedWindow.cs: Hacks to embed a toplevel window as a
non-toplevel inside a MetaPreview widget
* libstetic/DND.cs (Drag): ugly hacks to use EmbedWindow when
dragging windows. Partly working around a libmetacity-private bug
that it requires the Metacity.Preview's parent to already be
realized when it's added to it.
(Cancel): tweak a bit to return the embedded Gtk.Window, not its
Metacity.Preview, when dragging a window
* stetic/Canvas.cs: move some code to EmbedWindow. Add DND support.
* stetic/Palette.cs:
* stetic/WidgetFactory.cs: don't use WindowFactory any more (for
now). Just use WidgetFactory for everything.
Modified: branches/stetic-summit/stetic/ChangeLog
===================================================================
--- branches/stetic-summit/stetic/ChangeLog 2005-10-10 16:09:10 UTC (rev
51519)
+++ branches/stetic-summit/stetic/ChangeLog 2005-10-10 16:14:36 UTC (rev
51520)
@@ -1,3 +1,21 @@
+2005-10-10 Dan Winship <[EMAIL PROTECTED]>
+
+ * libstetic/EmbedWindow.cs: Hacks to embed a toplevel window as a
+ non-toplevel inside a MetaPreview widget
+
+ * libstetic/DND.cs (Drag): ugly hacks to use EmbedWindow when
+ dragging windows. Partly working around a libmetacity-private bug
+ that it requires the Metacity.Preview's parent to already be
+ realized when it's added to it.
+ (Cancel): tweak a bit to return the embedded Gtk.Window, not its
+ Metacity.Preview, when dragging a window
+
+ * stetic/Canvas.cs: move some code to EmbedWindow. Add DND support.
+
+ * stetic/Palette.cs:
+ * stetic/WidgetFactory.cs: don't use WindowFactory any more (for
+ now). Just use WidgetFactory for everything.
+
2005-10-10 Jeroen Zwartepoorte <[EMAIL PROTECTED]>
* metacity-sharp/test-preview.cs: Make the Preview stuff more generic.
Modified: branches/stetic-summit/stetic/libstetic/DND.cs
===================================================================
--- branches/stetic-summit/stetic/libstetic/DND.cs 2005-10-10 16:09:10 UTC
(rev 51519)
+++ branches/stetic-summit/stetic/libstetic/DND.cs 2005-10-10 16:14:36 UTC
(rev 51520)
@@ -68,6 +68,12 @@
DND.dragWidget = dragWidget;
dragWin = new Gtk.Window (Gtk.WindowType.Popup);
+
+ if (dragWidget is Gtk.Window) {
+ dragWidget = EmbedWindow.Wrap
((Gtk.Window)dragWidget);
+ dragWin.Show ();
+ }
+
dragWin.Add (dragWidget);
req = dragWidget.SizeRequest ();
@@ -84,7 +90,7 @@
ctx.SourceWindow.GetRootOrigin (out rx, out ry);
dragWin.Move (rx + px, ry + py);
- dragWin.Show ();
+ dragWin.ShowAll ();
Gtk.Drag.SetIconWidget (ctx, dragWin, 0, 0);
if (source != null) {
@@ -122,10 +128,10 @@
dragWidget = null;
// Remove the widget from its dragWindow
- Gtk.Container parent = w.Parent as Gtk.Container;
- if (parent != null) {
- parent.Remove (w);
- parent.Destroy ();
+ Gtk.Window dragWindow = w.Toplevel as Gtk.Window;
+ if (dragWindow != null) {
+ dragWindow.Remove (dragWindow.Child);
+ dragWindow.Destroy ();
}
return w;
}
Added: branches/stetic-summit/stetic/libstetic/EmbedWindow.cs
===================================================================
--- branches/stetic-summit/stetic/libstetic/EmbedWindow.cs 2005-10-10
16:09:10 UTC (rev 51519)
+++ branches/stetic-summit/stetic/libstetic/EmbedWindow.cs 2005-10-10
16:14:36 UTC (rev 51520)
@@ -0,0 +1,139 @@
+using Gtk;
+using System;
+using System.Collections;
+
+namespace Stetic {
+
+ public static class EmbedWindow {
+
+ static Hashtable wrappers = new Hashtable ();
+
+ public static Widget Wrap (Window window)
+ {
+ if (wrappers[window] != null)
+ return (Gtk.Widget)wrappers[window];
+
+ if (window.IsRealized)
+ throw new ApplicationException ("Cannot make a
realized window embeddable");
+
+ window.WidgetFlags &= ~(WidgetFlags.Toplevel);
+ window.SizeAllocated += new SizeAllocatedHandler
(OnSizeAllocated);
+ window.Realized += new EventHandler (OnRealized);
+
+ Metacity.Preview prev = new Metacity.Preview ();
+ prev.Title = window.Title;
+ prev.Theme = Theme;
+
+ switch (window.TypeHint) {
+ case Gdk.WindowTypeHint.Normal:
+ prev.FrameType = Metacity.FrameType.Normal;
+ break;
+ case Gdk.WindowTypeHint.Dialog:
+ prev.FrameType = window.Modal ?
Metacity.FrameType.ModalDialog : Metacity.FrameType.Dialog;
+ break;
+ case Gdk.WindowTypeHint.Menu:
+ prev.FrameType = Metacity.FrameType.Menu;
+ break;
+ case Gdk.WindowTypeHint.Splashscreen:
+ prev.FrameType = Metacity.FrameType.Border;
+ break;
+ case Gdk.WindowTypeHint.Utility:
+ prev.FrameType = Metacity.FrameType.Utility;
+ break;
+ default:
+ prev.FrameType = Metacity.FrameType.Normal;
+ break;
+ }
+
+ Metacity.FrameFlags flags =
+ Metacity.FrameFlags.AllowsDelete |
+ Metacity.FrameFlags.AllowsVerticalResize |
+ Metacity.FrameFlags.AllowsHorizontalResize |
+ Metacity.FrameFlags.AllowsMove |
+ Metacity.FrameFlags.AllowsShade |
+ Metacity.FrameFlags.HasFocus;
+ if (window.Resizable)
+ flags = flags |
Metacity.FrameFlags.AllowsMaximize;
+ prev.FrameFlags = flags;
+
+ prev.Add (window);
+
+ wrappers[window] = prev;
+ return prev;
+ }
+
+ static private void OnSizeAllocated (object obj,
SizeAllocatedArgs args)
+ {
+ Window window = obj as Window;
+ Gdk.Rectangle allocation = args.Allocation;
+
+ if (window.IsRealized) {
+ window.GdkWindow.MoveResize (allocation.X,
+ allocation.Y,
+ allocation.Width,
+ allocation.Height);
+ }
+ }
+
+ static private void OnRealized (object obj, EventArgs args)
+ {
+ Window window = obj as Window;
+
+ window.WidgetFlags |= WidgetFlags.Realized;
+
+ Gdk.WindowAttr attrs = new Gdk.WindowAttr ();
+ attrs.Mask = window.Events |
+ (Gdk.EventMask.ExposureMask |
+ Gdk.EventMask.KeyPressMask |
+ Gdk.EventMask.KeyReleaseMask |
+ Gdk.EventMask.EnterNotifyMask |
+ Gdk.EventMask.LeaveNotifyMask |
+ Gdk.EventMask.StructureMask);
+ attrs.X = window.Allocation.X;
+ attrs.Y = window.Allocation.Y;
+ attrs.Width = window.Allocation.Width;
+ attrs.Height = window.Allocation.Height;
+ attrs.Wclass = Gdk.WindowClass.InputOutput;
+ attrs.Visual = window.Visual;
+ attrs.Colormap = window.Colormap;
+ attrs.WindowType = Gdk.WindowType.Child;
+
+ Gdk.WindowAttributesType mask =
+ Gdk.WindowAttributesType.X |
+ Gdk.WindowAttributesType.Y |
+ Gdk.WindowAttributesType.Colormap |
+ Gdk.WindowAttributesType.Visual;
+
+ window.GdkWindow = new Gdk.Window (window.ParentWindow,
attrs, mask);
+ window.GdkWindow.UserData = window.Handle;
+
+ window.Style = window.Style.Attach (window.GdkWindow);
+ window.Style.SetBackground (window.GdkWindow,
StateType.Normal);
+
+ // FIXME: gtk-sharp 2.6
+ // window.GdkWindow.EnableSynchronizedConfigure ();
+ }
+
+ static Metacity.Theme theme;
+ static Metacity.Theme Theme {
+ get {
+ if (theme == null) {
+ GConf.Client client = new GConf.Client
();
+ client.AddNotify
("/apps/metacity/general", GConfNotify);
+ string themeName = (string)client.Get
("/apps/metacity/general/theme");
+ theme = Metacity.Theme.Load (themeName);
+ }
+ return theme;
+ }
+ }
+
+ static void GConfNotify (object obj, GConf.NotifyEventArgs args)
+ {
+ if (args.Key == "/apps/metacity/general/theme") {
+ theme = Metacity.Theme.Load
((string)args.Value);
+ foreach (Metacity.Preview prev in
wrappers.Values)
+ prev.Theme = Theme;
+ }
+ }
+ }
+}
Modified: branches/stetic-summit/stetic/libstetic/Makefile.am
===================================================================
--- branches/stetic-summit/stetic/libstetic/Makefile.am 2005-10-10 16:09:10 UTC
(rev 51519)
+++ branches/stetic-summit/stetic/libstetic/Makefile.am 2005-10-10 16:14:36 UTC
(rev 51520)
@@ -4,6 +4,7 @@
ClassDescriptor.cs \
CommandDescriptor.cs \
DND.cs \
+ EmbedWindow.cs \
EnumDescriptor.cs \
GladeException.cs \
GladeUtils.cs \
@@ -91,7 +92,7 @@
@rm -f sources.rsp
@echo $(libstetic_dll_sources:%=$(srcdir)/%) > sources.rsp
@for resource in $(libstetic_dll_resources); do echo
-resource:$$resource,`basename $$resource` >> sources.rsp; done
- $(MCS) -debug -pkg:gnome-sharp-2.0 -target:library -out:$@ @sources.rsp
+ $(MCS) -debug $(STETIC_LIBS) -r:../metacity-sharp/metacity-sharp.dll
-target:library -out:$@ @sources.rsp
CLEANFILES = libstetic.dll libstetic.dll.mdb sources.rsp
Modified: branches/stetic-summit/stetic/metacity-sharp/test-preview.cs
===================================================================
--- branches/stetic-summit/stetic/metacity-sharp/test-preview.cs
2005-10-10 16:09:10 UTC (rev 51519)
+++ branches/stetic-summit/stetic/metacity-sharp/test-preview.cs
2005-10-10 16:14:36 UTC (rev 51520)
@@ -151,7 +151,8 @@
window.Style = window.Style.Attach (window.GdkWindow);
window.Style.SetBackground (window.GdkWindow, StateType.Normal);
- window.GdkWindow.EnableSynchronizedConfigure ();
+// FIXME: gtk-sharp 2.6
+// window.GdkWindow.EnableSynchronizedConfigure ();
}
static void WindowDeleted (object obj, DeleteEventArgs args)
Modified: branches/stetic-summit/stetic/stetic/Canvas.cs
===================================================================
--- branches/stetic-summit/stetic/stetic/Canvas.cs 2005-10-10 16:09:10 UTC
(rev 51519)
+++ branches/stetic-summit/stetic/stetic/Canvas.cs 2005-10-10 16:14:36 UTC
(rev 51520)
@@ -6,69 +6,53 @@
public class Canvas : Gtk.Layout {
- public Canvas () : base (null, null)
+ Project project;
+
+ public Canvas (Project project) : base (null, null)
{
- ThemeChanged += CanvasThemeChanged;
+ this.project = project;
+ DND.DestSet (this, false);
}
- ArrayList previews = new ArrayList ();
-
- void CanvasThemeChanged ()
+ protected override void OnRealized ()
{
- foreach (Metacity.Preview prev in previews)
- prev.Theme = Theme;
+ base.OnRealized ();
+ ModifyBg (Gtk.StateType.Normal, Style.Base
(Gtk.StateType.Normal));
}
- static Metacity.Theme theme;
- static Metacity.Theme Theme {
- get {
- if (theme == null) {
- GConf.Client client = new GConf.Client
();
- client.AddNotify
("/apps/metacity/general", GConfNotify);
- string themeName = (string)client.Get
("/apps/metacity/general/theme");
- theme = Metacity.Theme.Load (themeName);
- }
- return theme;
- }
+ protected override bool OnDragMotion (Gdk.DragContext context,
+ int x, int y, uint time)
+ {
+ Gdk.Drag.Status (context, Gdk.DragAction.Move, time);
+ return true;
}
- static void GConfNotify (object obj, GConf.NotifyEventArgs args)
+ protected override bool OnDragDrop (Gdk.DragContext context,
+ int x, int y, uint time)
{
- if (args.Key == "/apps/metacity/general/theme") {
- theme = Metacity.Theme.Load
((string)args.Value);
- if (ThemeChanged != null)
- ThemeChanged ();
- }
- }
+ Stetic.Wrapper.Widget wrapper = DND.Drop (context,
this, time);
+ if (wrapper == null)
+ return false;
- delegate void ThemeChangedHandler ();
- static event ThemeChangedHandler ThemeChanged;
+ Gtk.Widget dropped = wrapper.Wrapped;
+ if (dropped is Gtk.Window)
+ dropped = EmbedWindow.Wrap
((Gtk.Window)dropped);
+ Put (dropped, x, y);
- protected override void OnRealized ()
- {
- base.OnRealized ();
- ModifyBg (Gtk.StateType.Normal, Style.Base
(Gtk.StateType.Normal));
+ wrapper.Select ();
+ return true;
}
- public void Add (Window win)
+ protected override void OnDragDataReceived (Gdk.DragContext
context, int x, int y,
+ Gtk.SelectionData
selectionData,
+ uint info, uint
time)
{
- Metacity.Preview prev = new Metacity.Preview ();
- prev.Title = ((Gtk.Window)win).Title;
- prev.Theme = Theme;
- if (win is Gtk.Dialog)
- prev.FrameType = Metacity.FrameType.Dialog;
- else
- prev.FrameType = Metacity.FrameType.Normal;
- prev.FrameFlags =
- Metacity.FrameFlags.AllowsDelete |
- Metacity.FrameFlags.AllowsVerticalResize |
- Metacity.FrameFlags.AllowsHorizontalResize |
- Metacity.FrameFlags.AllowsMove |
- Metacity.FrameFlags.AllowsShade;
+ Stetic.Wrapper.Widget dropped =
+ GladeUtils.Paste (project, selectionData);
- previews.Add (prev);
-
- Put (win, 20, 20);
+ Gtk.Drag.Finish (context, dropped != null, dropped !=
null, time);
+ if (dropped != null)
+ Put (dropped.Wrapped, x, y);
}
}
}
Modified: branches/stetic-summit/stetic/stetic/Palette.cs
===================================================================
--- branches/stetic-summit/stetic/stetic/Palette.cs 2005-10-10 16:09:10 UTC
(rev 51519)
+++ branches/stetic-summit/stetic/stetic/Palette.cs 2005-10-10 16:14:36 UTC
(rev 51520)
@@ -53,9 +53,9 @@
continue;
WidgetFactory factory;
- if (klass.Category == "window")
- factory = new WindowFactory (project,
klass);
- else
+// if (klass.Category == "window")
+// factory = new WindowFactory (project,
klass);
+// else
factory = new WidgetFactory (project,
klass);
AddOrGetGroup(klass.Category).Append (factory);
Modified: branches/stetic-summit/stetic/stetic/Stetic.cs
===================================================================
--- branches/stetic-summit/stetic/stetic/Stetic.cs 2005-10-10 16:09:10 UTC
(rev 51519)
+++ branches/stetic-summit/stetic/stetic/Stetic.cs 2005-10-10 16:14:36 UTC
(rev 51520)
@@ -22,7 +22,7 @@
Project = new Project ();
- Canvas = new Stetic.Canvas ();
+ Canvas = new Stetic.Canvas (Project);
Palette = new Stetic.Palette (Project);
ProjectView = new Stetic.ProjectView (Project);
Properties = new Stetic.PropertyGrid (Project);
Modified: branches/stetic-summit/stetic/stetic/WidgetFactory.cs
===================================================================
--- branches/stetic-summit/stetic/stetic/WidgetFactory.cs 2005-10-10
16:09:10 UTC (rev 51519)
+++ branches/stetic-summit/stetic/stetic/WidgetFactory.cs 2005-10-10
16:14:36 UTC (rev 51520)
@@ -1,5 +1,4 @@
using Gtk;
-using Gdk;
using System;
using System.Collections;
using System.Reflection;
@@ -39,6 +38,7 @@
}
}
+#if UNUSED
public class WindowFactory : WidgetFactory {
public WindowFactory (Project project, ClassDescriptor klass) :
base (project, klass) {}
@@ -56,5 +56,5 @@
return true;
}
}
-
+#endif
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches