1using System; 2using System.Collections.Generic; 3using System.Drawing; 4using System.Drawing.Drawing2D; 5using System.Drawing.Imaging; 6using System.Drawing.Text; 7using System.IO; 8using System.Linq; 9using System.Runtime.InteropServices; 10using System.Windows.Forms; 11using WindowCapture.App; 12using WindowCapture.Detection; 13using WindowCapture.Effects; 14using WindowCapture.Helpers; 15using WindowCapture.Integration; 16using WindowCapture.Models; 17using WindowCapture.Native; 18 19namespace WindowCapture.UI 20{ 21 public partial class EditorForm 22 { 23 // ===== Word export ===== 24 25 private void CheckWordAvailability() 26 { 27 if (WordIntegration.HasOpenDocuments()) 28 UpdateWordPanelImage(); 29 } 30 31 private void WordSidePanel_InsertSuccess(object sender, EventArgs e) 32 { 33 UpdateWordPanelImage(); 34 } 35 36 private void UpdateWordPanelImage() 37 { 38 var img = canvas.GetCompositeImage(); 39 if (img != null) 40 wordSidePanel.Show(BitmapHelper.CloneExact(img)); 41 } 42 43 private void WordSidePanel_Closed(object sender, EventArgs e) 44 { 45 wordDialogOpen = false; 46 } 47 48 private void ExportToWord() 49 { 50 // Check if Word is available 51 if (!WordIntegration.IsWordInstalled()) 52 { 53 MessageBox.Show("Microsoft Word is not installed on this system.", 54 "Word Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning); 55 return; 56 } 57 58 // If side panel is already open, just focus it 59 if (wordSidePanel != null && wordSidePanel.IsExpanded) 60 { 61 return; 62 } 63 64 // Get full composite image with ALL annotations (blur, arrows, markers, text, bubbles) 65 var exportImage = canvas.GetFullCompositeImage(); 66 if (exportImage == null) 67 { 68 MessageBox.Show("Failed to create image for export.", 69 "Export Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 70 return; 71 } 72 73 // Show Word panel as a separate floating window 74 wordDialogOpen = true; 75 ShowWordPanelAsWindow(exportImage); 76 } 77 78 private Form wordPanelWindow; 79 80 private void ShowWordPanelAsWindow(Bitmap exportImage) 81 { 82 if (wordPanelWindow != null && !wordPanelWindow.IsDisposed) 83 { 84 wordPanelWindow.BringToFront(); 85 return; 86 } 87 88 wordPanelWindow = new Form(); 89 wordPanelWindow.Text = ""; 90 wordPanelWindow.FormBorderStyle = FormBorderStyle.None; 91 wordPanelWindow.StartPosition = FormStartPosition.Manual; 92 wordPanelWindow.Size = new Size(340, Height); 93 wordPanelWindow.Location = new Point(Right + 4, Top); 94 wordPanelWindow.BackColor = Color.FromArgb(10, 10, 12); 95 wordPanelWindow.ShowInTaskbar = false; 96 wordPanelWindow.Owner = this; 97 wordPanelWindow.MinimumSize = new Size(320, 400); 98 99 // Apply rounded corners and blur to the Word window (same tint as editor) 100 wordPanelWindow.Shown += delegate 101 { 102 WinApi.TryEnableRoundedCorners(wordPanelWindow.Handle); 103 BlurHelper.Apply(wordPanelWindow.Handle); 104 }; 105 106 // Move side panel from editor into the new window 107 wordSidePanel.Dock = DockStyle.Fill; 108 wordSidePanel.Width = 340; 109 wordPanelWindow.Controls.Add(wordSidePanel); 110 wordSidePanel.Show(exportImage); 111 112 wordPanelWindow.FormClosed += delegate 113 { 114 // Move side panel back to editor 115 wordPanelWindow.Controls.Remove(wordSidePanel); 116 wordSidePanel.Dock = DockStyle.Right; 117 wordSidePanel.Width = 0; 118 Controls.Add(wordSidePanel); 119 wordDialogOpen = false; 120 wordPanelWindow = null; 121 }; 122 123 // Allow resizing the window 124 wordPanelWindow.Resize += delegate 125 { 126 wordSidePanel.Width = wordPanelWindow.ClientSize.Width; 127 }; 128 129 wordPanelWindow.Show(); 130 } 131 } 132}