Skip to content

Commit ef418b9

Browse files
committed
Adds experimental Bitmap WPF copy
element is clipped if there is overflow... See http://stackoverflow.com/questions/37572471/how-to-copy-a-frameworkelement-including-the-overflowed-content
1 parent 269bf28 commit ef418b9

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

RetailCoder.VBE/Common/ClipboardWriter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.Windows;
8+
using System.Windows.Media.Imaging;
89

910
namespace Rubberduck.Common
1011
{
1112
public interface IClipboardWriter
1213
{
1314
void Write(string text);
15+
void AppendImage(BitmapSource image);
1416
void AppendString(string formatName, string data);
1517
void AppendStream(string formatName, MemoryStream stream);
1618
void Flush();
@@ -26,6 +28,16 @@ public void Write(string text)
2628
this.Flush();
2729
}
2830

31+
public void AppendImage(BitmapSource image)
32+
{
33+
if (_data == null)
34+
{
35+
_data = new DataObject();
36+
}
37+
_data.SetImage(image);
38+
}
39+
40+
2941
public void AppendString(string formatName, string data)
3042
{
3143
if (_data == null)

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Linq;
77
using System.Windows;
88
using System.Windows.Input;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
911
using Microsoft.Vbe.Interop;
1012
using Rubberduck.Common;
1113
using Rubberduck.Navigation.Folders;
@@ -72,6 +74,22 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
7274
{
7375
const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet";
7476

77+
78+
const long DPI = 96;
79+
FrameworkElement element = (FrameworkElement)param;
80+
double height = element.ActualHeight;
81+
double width = element.ActualWidth;
82+
RenderTargetBitmap bmp = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), DPI, DPI, PixelFormats.Default);
83+
DrawingVisual dv = new DrawingVisual();
84+
using (DrawingContext dc = dv.RenderOpen())
85+
{
86+
VisualBrush vb = new VisualBrush(element);
87+
dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
88+
}
89+
bmp.Render(dv);
90+
91+
92+
7593
ColumnInfo[] ColumnInfos = { new ColumnInfo("Project"), new ColumnInfo("Folder"), new ColumnInfo("Component"), new ColumnInfo("Declaration Type"), new ColumnInfo("Scope"),
7694
new ColumnInfo("Name"), new ColumnInfo("Return Type") };
7795

@@ -91,6 +109,7 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
91109
_clipboard.AppendStream(DataFormats.GetDataFormat(XML_SPREADSHEET_DATA_FORMAT).Name, strm1);
92110
_clipboard.AppendString(DataFormats.Rtf, rtfResults);
93111
_clipboard.AppendString(DataFormats.Html, htmlResults);
112+
_clipboard.AppendImage(bmp);
94113
_clipboard.AppendString(DataFormats.CommaSeparatedValue, csvResults);
95114
//_clipboard.AppendString(DataFormats.UnicodeText, textResults);
96115

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,8 @@
703703
</Button>
704704

705705
<Separator />
706-
707-
<Button Command="{Binding CopyResultsCommand}">
706+
707+
<Button Command="{Binding CopyResultsCommand}" CommandParameter="{Binding ElementName=ProjectTree}">
708708
<Image Height="16" Source="../../Resources/document-copy.png" />
709709
<Button.ToolTip>
710710
<TextBlock Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_CopyToolTip}" />
@@ -714,11 +714,12 @@
714714
</ToolBar>
715715
</ToolBarTray>
716716

717-
<TreeView Grid.Row="1"
717+
<TreeView x:Name="ProjectTree" Grid.Row="1"
718718
ItemContainerStyle="{StaticResource ShinyTreeView}"
719719
HorizontalContentAlignment="Stretch"
720720
MouseDoubleClick="TreeView_OnMouseDoubleClick"
721-
Style="{StaticResource CodeExplorerTreeViewStyle}" BorderThickness="0,1">
721+
Style="{StaticResource CodeExplorerTreeViewStyle}" BorderThickness="0,1"
722+
VirtualizingPanel.IsVirtualizing="False">
722723
<i:Interaction.Behaviors>
723724
<controls:BindableSelectedItemBehavior SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
724725
</i:Interaction.Behaviors>

0 commit comments

Comments
 (0)