private RootDesignerView(IDesignerHost host)
: base()
{
//it's through this that we communicate with JavaScript
comm = new CommandManager (this);
//we use the host to get services and designers
this.host = host as DesignerHost;
if (this.host == null)
throw new ArgumentNullException ("host");
//We use this to monitor component changes and update as necessary
changeService = host.GetService (typeof (IComponentChangeService)) as IComponentChangeService;
if (changeService == null)
throw new Exception ("Could not obtain IComponentChangeService from host");
//We use this to monitor and set selections
selectionService = host.GetService (typeof (ISelectionService)) as ISelectionService;
if (selectionService == null)
throw new Exception ("Could not obtain ISelectionService from host");
//This is used to add undo/redo, cut/paste etc commands to menu
//Also to launch right-click menu
menuService = host.GetService (typeof (IMenuCommandService)) as IMenuCommandService;
//if (menuService == null)
// return;
//Now we've got all services, register our events
changeService.ComponentChanged += new ComponentChangedEventHandler (changeService_ComponentChanged);
selectionService.SelectionChanged += new EventHandler (selectionService_SelectionChanged);
//Register incoming calls from JavaScript
comm.RegisterJSHandler ("Click", new ClrCall (JSClick));
comm.RegisterJSHandler ("Activate", new ClrCall (JSActivate));
comm.RegisterJSHandler ("ThrowException", new ClrCall (JSException));
comm.RegisterJSHandler ("DebugStatement", new ClrCall (JSDebugStatement));
comm.RegisterJSHandler ("ResizeControl", new ClrCall (JSResize));
comm.RegisterJSHandler ("DocumentReturn", new ClrCall (JSDocumentReturn));
comm.RegisterJSHandler ("RemoveControl", new ClrCall (JSRemoveControl));
comm.RegisterJSHandler ("DeserializeAndAdd", new ClrCall (JSDeserializeAndAdd));
comm.RegisterJSHandler ("Serialize", new ClrCall (JSSerialize));
System.Diagnostics.Trace.WriteLine ("RootDesignerView created");
}