public void SPIsRemovedFromWorkspaceWhenDisposed1()
        {
            MockWPFSmartPart smartPartA = new MockWPFSmartPart();

            TabSmartPartInfo spInfoA = new TabSmartPartInfo();

            spInfoA.Title = "Smart Part A";

            workItem.SmartParts.Add(smartPartA);

            workspace.Show(smartPartA, spInfoA);

            Assert.AreEqual(1, workspace.TabPages.Count);

            //smartPartA.Dispose();
            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();
            Control wrapper = catalog.Wrap(smartPartA);

            wrapper.Dispose();

            Assert.AreEqual(0, workspace.TabPages.Count);

            // Returns 1
            Assert.AreEqual(0, workspace.SmartParts.Count);
        }
        public void CloseTabPageAddedAtDesignTime()
        {
            // Create new instance to simulate design-time creation.
            workspace = new TabWorkspace();
            workItem.Items.Add(workspace);
            MockWPFSmartPart sp1 = new MockWPFSmartPart();

            workItem.Items.Add(sp1);

            TabPage page = new TabPage();
            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();
            Control wrapper = catalog.Wrap(sp1);

            page.Controls.Add(wrapper);
            page.Name = Guid.NewGuid().ToString();
            workspace.TabPages.Add(page);

            owner = new Form();
            owner.Controls.Add(workspace);
            owner.Show();

            workspace.Close(sp1);

            Assert.AreEqual(0, workspace.TabPages.Count);
        }
        public void ShowAddsTabWithSPDockFill()
        {
            workspace.Show(sp);
            Assert.AreEqual(1, workspace.TabPages.Count);
            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();
            // ElementHost can't map Dock Property to WPF control.
            Control wrapper = catalog.Wrap(sp);

            Assert.AreEqual(DockStyle.Fill, wrapper.Dock);
        }
        public void UsesSPInfoIfNoTabSPInfoExists()
        {
            WPFSmartPartInfo info = new WPFSmartPartInfo();

            info.Title = "Foo";
            workItem.RegisterSmartPartInfo(sp, info);

            workspace.Show(sp);

            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();
            Control wrapper = catalog.Wrap(sp);

            Assert.AreEqual("Foo", workspace.Pages[wrapper].Text);
        }
Esempio n. 5
0
        public void CanShowModalWithOwner()
        {
            TestableRootWorkItem workItem = new TestableRootWorkItem();
            Form            owner         = new Form();
            WindowWorkspace workspace     = new WindowWorkspace(owner);

            workItem.Workspaces.Add(workspace);
            MockWPFSmartPart smartPart = null;

            WindowSmartPartInfo info = new WindowSmartPartInfo();

            info.Title = "Mock Smart Part";
            info.Modal = true;

            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();

            Thread thread = new Thread(new ThreadStart(delegate
            {
                smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

                workspace.Show(smartPart, info);
            }));

#pragma warning disable CA1416 // Validate platform compatibility
            thread.SetApartmentState(ApartmentState.STA);
#pragma warning restore CA1416 // Validate platform compatibility

            try
            {
                thread.Start();
                Thread.Sleep(10000);

                Assert.IsTrue(workspace.Windows[catalog.Wrap(smartPart)].Visible);
                Assert.AreSame(owner, workspace.Windows[catalog.Wrap(smartPart)].Owner);
            }
            finally
            {
                SendMessage(workspace.Windows[catalog.Wrap(smartPart)].Handle, WM_SYSCOMMAND, SC_CLOSE, 0);
                thread.Join();
            }
        }
        public void ShowTabPageAddedAtDesignTime()
        {
            MockWPFSmartPart sp1 = new MockWPFSmartPart();

            workItem.Items.Add(sp1);

            TabPage page = new TabPage();
            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();

            page.Controls.Add(catalog.Wrap(sp1));
            page.Name = Guid.NewGuid().ToString();

            workspace.TabPages.Add(page);

            workspace.Show(sp);
            sp1.Visibility = Visibility.Hidden;
            workspace.Show(sp1);

            Assert.AreEqual(2, workspace.TabPages.Count);
            Assert.AreEqual(Visibility.Visible, sp1.Visibility);
        }
Esempio n. 7
0
        public void CanShowModal()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = null;
            WindowSmartPartInfo  info      = new WindowSmartPartInfo();

            info.Title = "Mock Smart Part";
            info.Modal = true;

            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();

            Thread thread = new Thread(new ThreadStart(delegate
            {
                // smartPart need to be created by the same thread that creates ElementHost
                smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

                workspace.Show(smartPart, info);
            }));

            // needed to create ElementHost, calling thread must be STA.
#pragma warning disable CA1416 // Validate platform compatibility
            thread.SetApartmentState(ApartmentState.STA);
#pragma warning restore CA1416 // Validate platform compatibility

            try
            {
                thread.Start();
                Thread.Sleep(10000);

                Assert.IsTrue(workspace.Windows[catalog.Wrap(smartPart)].Visible);
            }
            finally
            {
                SendMessage(workspace.Windows[catalog.Wrap(smartPart)].Handle, WM_SYSCOMMAND, SC_CLOSE, 0);
                thread.Join();
            }
        }
Esempio n. 8
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_isDisposing) // avoid recursion on Dispose
     {
         if (disposing)
         {
             _isDisposing = true;
             if (_presenter != null)
             {
                 _presenter.Dispose();
                 _presenter = null;
             }
             if (_WPFUIElementAdapter != null)
             {
                 System.Windows.Forms.Control host = _WPFUIElementAdapter.Wrap(this);
                 if (!host.Disposing)
                 {
                     host.Dispose();
                 }
                 _WPFUIElementAdapter = null;
             }
         }
     }
 }
Esempio n. 9
0
 public ElementHostWorkspace()
 {
     elementHosts = BundleRuntime.Instance.GetFirstOrDefaultService <IWPFUIElementAdapter>();
 }
Esempio n. 10
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_isDisposing) // avoid recursion on Dispose
     {
         if (disposing)
         {
             _isDisposing = true;
             if (_presenter != null)
             {
                 _presenter.Dispose();
                 _presenter = null;
             }
             if (_WPFUIElementAdapter != null)
             {
                 System.Windows.Forms.Control host = _WPFUIElementAdapter.Wrap(this);
                 if (!host.Disposing)
                 {
                     host.Dispose();
                 }
                 _WPFUIElementAdapter = null;
             }
         }
     }
 }