Browse Source

Added SharpDevelopElementHost for hosting WPF controls as ViewContents

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3911 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
deadb92215
  1. 8
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  2. 110
      src/Main/ICSharpCode.Core.Presentation/SharpDevelopElementHost.cs

8
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -52,10 +52,12 @@ @@ -52,10 +52,12 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\GlobalAssemblyInfo.cs">
@ -74,6 +76,7 @@ @@ -74,6 +76,7 @@
<Compile Include="PixelSnapper.cs" />
<Compile Include="PresentationResourceService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharpDevelopElementHost.cs" />
<Compile Include="SplitButton.cs" />
<Compile Include="ToolBar\ToolBarButton.cs" />
<Compile Include="ToolBar\ToolBarComboBox.cs" />
@ -81,6 +84,11 @@ @@ -81,6 +84,11 @@
<Compile Include="ToolBar\ToolBarSplitButton.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>

110
src/Main/ICSharpCode.Core.Presentation/SharpDevelopElementHost.cs

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision: 3499 $</version>
// </file>
using System;
using System.Windows;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Threading;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// Hosts a WPF element inside a Windows.Forms application.
/// </summary>
// TODO : maybe move this class to ICSharpCode.SharpDevelop as it requires it as a reference
public class SharpDevelopElementHost : ElementHost, IUndoHandler, IClipboardHandler
{
public SharpDevelopElementHost(UIElement child)
{
this.Child = child;
}
bool IsEnabled(RoutedCommand command)
{
if (command.CanExecute(null, null))
return true;
else if (this.Child != null)
return command.CanExecute(null, FocusManager.GetFocusedElement(FocusManager.GetFocusScope(this.Child)));
else
return false;
}
void Run(RoutedCommand command)
{
if (command.CanExecute(null, null)) {
command.Execute(null, null);
} else if (this.Child != null) {
command.Execute(null, FocusManager.GetFocusedElement(FocusManager.GetFocusScope(this.Child)));
}
}
public bool EnableUndo {
get { return IsEnabled(ApplicationCommands.Undo); }
}
public bool EnableRedo {
get { return IsEnabled(ApplicationCommands.Redo); }
}
public void Undo()
{
Run(ApplicationCommands.Undo);
}
public void Redo()
{
Run(ApplicationCommands.Redo);
}
public bool EnableCut {
get { return IsEnabled(ApplicationCommands.Undo); }
}
public bool EnableCopy {
get { return IsEnabled(ApplicationCommands.Copy); }
}
public bool EnablePaste {
get { return IsEnabled(ApplicationCommands.Paste); }
}
public bool EnableDelete {
get { return IsEnabled(ApplicationCommands.Delete); }
}
public bool EnableSelectAll {
get { return IsEnabled(ApplicationCommands.SelectAll); }
}
public void Cut()
{
Run(ApplicationCommands.Cut);
}
public void Copy()
{
Run(ApplicationCommands.Copy);
}
public void Paste()
{
Run(ApplicationCommands.Paste);
}
public void Delete()
{
Run(ApplicationCommands.Delete);
}
public void SelectAll()
{
Run(ApplicationCommands.SelectAll);
}
}
}
Loading…
Cancel
Save