/
ImageEditorForm.cs
1484 lines (1297 loc) · 52.9 KB
/
ImageEditorForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Destinations;
using Greenshot.Drawing;
using Greenshot.Drawing.Fields;
using Greenshot.Drawing.Fields.Binding;
using Greenshot.Forms;
using Greenshot.Help;
using Greenshot.Helpers;
using Greenshot.IniFile;
using Greenshot.Plugin;
using Greenshot.Plugin.Drawing;
using GreenshotPlugin.Controls;
using GreenshotPlugin.Core;
using GreenshotPlugin.Effects;
using GreenshotPlugin.Interfaces.Drawing;
using GreenshotPlugin.UnmanagedHelpers;
using log4net;
namespace Greenshot {
/// <summary>
/// Description of ImageEditorForm.
/// </summary>
public partial class ImageEditorForm : BaseForm, IImageEditor {
private static readonly ILog Log = LogManager.GetLogger(typeof(ImageEditorForm));
private static readonly EditorConfiguration EditorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
private static readonly List<string> IgnoreDestinations = new List<string> { PickerDestination.DESIGNATION, EditorDestination.DESIGNATION };
private static readonly List<IImageEditor> EditorList = new List<IImageEditor>();
private Surface _surface;
private GreenshotToolStripButton[] _toolbarButtons;
private static readonly string[] SupportedClipboardFormats = {typeof(string).FullName, "Text", typeof(IDrawableContainerList).FullName};
private bool _originalBoldCheckState;
private bool _originalItalicCheckState;
// whether part of the editor controls are disabled depending on selected item(s)
private bool _controlsDisabledDueToConfirmable;
/// <summary>
/// An Implementation for the IImageEditor, this way Plugins have access to the HWND handles wich can be used with Win32 API calls.
/// </summary>
public IWin32Window WindowHandle => this;
public static List<IImageEditor> Editors {
get {
try {
EditorList.Sort((e1, e2) => string.Compare(e1.Surface.CaptureDetails.Title, e2.Surface.CaptureDetails.Title, StringComparison.Ordinal));
} catch(Exception ex) {
Log.Warn("Sorting of editors failed.", ex);
}
return EditorList;
}
}
public ImageEditorForm(ISurface iSurface, bool outputMade) {
EditorList.Add(this);
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
ManualLanguageApply = true;
InitializeComponent();
Load += delegate {
var thread = new Thread(AddDestinations)
{
Name = "add destinations"
};
thread.Start();
};
// Make sure the editor is placed on the same location as the last editor was on close
// But only if this still exists, else it will be reset (BUG-1812)
WindowPlacement editorWindowPlacement = EditorConfiguration.GetEditorPlacement();
Rectangle screenbounds = WindowCapture.GetScreenBounds();
if (!screenbounds.Contains(editorWindowPlacement.NormalPosition))
{
EditorConfiguration.ResetEditorPlacement();
}
// ReSharper disable once UnusedVariable
WindowDetails thisForm = new WindowDetails(Handle)
{
WindowPlacement = EditorConfiguration.GetEditorPlacement()
};
// init surface
Surface = iSurface;
// Intial "saved" flag for asking if the image needs to be save
_surface.Modified = !outputMade;
UpdateUi();
// Workaround: As the cursor is (mostly) selected on the surface a funny artifact is visible, this fixes it.
HideToolstripItems();
}
/// <summary>
/// Remove the current surface
/// </summary>
private void RemoveSurface() {
if (_surface == null)
{
return;
}
panel1.Controls.Remove(_surface);
_surface.Dispose();
_surface = null;
}
/// <summary>
/// Change the surface
/// </summary>
/// <param name="newSurface"></param>
private void SetSurface(ISurface newSurface) {
if (Surface != null && Surface.Modified) {
throw new ApplicationException("Surface modified");
}
RemoveSurface();
panel1.Height = 10;
panel1.Width = 10;
_surface = newSurface as Surface;
if (_surface != null)
{
panel1.Controls.Add(_surface);
}
Image backgroundForTransparency = GreenshotResources.getImage("Checkerboard.Image");
if (_surface != null)
{
_surface.TransparencyBackgroundBrush = new TextureBrush(backgroundForTransparency, WrapMode.Tile);
_surface.MovingElementChanged += delegate {
RefreshEditorControls();
};
_surface.DrawingModeChanged += surface_DrawingModeChanged;
_surface.SurfaceSizeChanged += SurfaceSizeChanged;
_surface.SurfaceMessage += SurfaceMessageReceived;
_surface.FieldAggregator.FieldChanged += FieldAggregatorFieldChanged;
SurfaceSizeChanged(Surface, null);
BindFieldControls();
RefreshEditorControls();
// Fix title
if (_surface?.CaptureDetails?.Title != null) {
Text = _surface.CaptureDetails.Title + " - " + Language.GetString(LangKey.editor_title);
}
}
Activate();
WindowDetails.ToForeground(Handle);
}
private void UpdateUi() {
// Disable access to the settings, for feature #3521446
preferencesToolStripMenuItem.Visible = !coreConfiguration.DisableSettings;
toolStripSeparator12.Visible = !coreConfiguration.DisableSettings;
toolStripSeparator11.Visible = !coreConfiguration.DisableSettings;
btnSettings.Visible = !coreConfiguration.DisableSettings;
// Make sure Double-buffer is enabled
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
// resizing the panel is futile, since it is docked. however, it seems
// to fix the bug (?) with the vscrollbar not being able to shrink to
// a smaller size than the initial panel size (as set by the forms designer)
panel1.Height = 10;
fontFamilyComboBox.PropertyChanged += FontPropertyChanged;
obfuscateModeButton.DropDownItemClicked += FilterPresetDropDownItemClicked;
highlightModeButton.DropDownItemClicked += FilterPresetDropDownItemClicked;
_toolbarButtons = new[] { btnCursor, btnRect, btnEllipse, btnText, btnLine, btnArrow, btnFreehand, btnHighlight, btnObfuscate, btnCrop, btnStepLabel, btnSpeechBubble };
//toolbarDropDownButtons = new ToolStripDropDownButton[]{btnBlur, btnPixeliate, btnTextHighlighter, btnAreaHighlighter, btnMagnifier};
pluginToolStripMenuItem.Visible = pluginToolStripMenuItem.DropDownItems.Count > 0;
// Workaround: for the MouseWheel event which doesn't get to the panel
MouseWheel += PanelMouseWheel;
// Make sure the value is set correctly when starting
counterUpDown.Value = Surface.CounterStart;
ApplyLanguage();
}
/// <summary>
/// Workaround for having a border around the dropdown
/// See: http://stackoverflow.com/questions/9560812/change-border-of-toolstripcombobox-with-flat-style
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PropertiesToolStrip_Paint(object sender, PaintEventArgs e) {
using (Pen cbBorderPen = new Pen(SystemColors.ActiveBorder)) {
// Loop over all items in the propertiesToolStrip
foreach (ToolStripItem item in propertiesToolStrip.Items) {
ToolStripComboBox cb = item as ToolStripComboBox;
// Only ToolStripComboBox that are visible
if (cb == null || !cb.Visible) {
continue;
}
// Calculate the rectangle
if (cb.ComboBox != null)
{
Rectangle r = new Rectangle(cb.ComboBox.Location.X - 1, cb.ComboBox.Location.Y - 1, cb.ComboBox.Size.Width + 1, cb.ComboBox.Size.Height + 1);
// Draw the rectangle
e.Graphics.DrawRectangle(cbBorderPen, r);
}
}
}
}
/// <summary>
/// Get all the destinations and display them in the file menu and the buttons
/// </summary>
private void AddDestinations() {
Invoke((MethodInvoker)delegate {
// Create export buttons
foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {
if (destination.Priority <= 2) {
continue;
}
if (!destination.IsActive) {
continue;
}
if (destination.DisplayIcon == null) {
continue;
}
try {
AddDestinationButton(destination);
} catch (Exception addingException) {
Log.WarnFormat("Problem adding destination {0}", destination.Designation);
Log.Warn("Exception: ", addingException);
}
}
});
}
private void AddDestinationButton(IDestination toolstripDestination) {
if (toolstripDestination.IsDynamic) {
ToolStripSplitButton destinationButton = new ToolStripSplitButton
{
DisplayStyle = ToolStripItemDisplayStyle.Image,
Size = new Size(23, 22),
Text = toolstripDestination.Description,
Image = toolstripDestination.DisplayIcon
};
//ToolStripDropDownButton destinationButton = new ToolStripDropDownButton();
ToolStripMenuItem defaultItem = new ToolStripMenuItem(toolstripDestination.Description)
{
Tag = toolstripDestination,
Image = toolstripDestination.DisplayIcon
};
defaultItem.Click += delegate {
toolstripDestination.ExportCapture(true, _surface, _surface.CaptureDetails);
};
// The ButtonClick, this is for the icon, gets the current default item
destinationButton.ButtonClick += delegate {
toolstripDestination.ExportCapture(true, _surface, _surface.CaptureDetails);
};
// Generate the entries for the drop down
destinationButton.DropDownOpening += delegate
{
ClearItems(destinationButton.DropDownItems);
destinationButton.DropDownItems.Add(defaultItem);
List<IDestination> subDestinations = new List<IDestination>();
subDestinations.AddRange(toolstripDestination.DynamicDestinations());
if (subDestinations.Count > 0) {
subDestinations.Sort();
foreach(IDestination subDestination in subDestinations) {
IDestination closureFixedDestination = subDestination;
ToolStripMenuItem destinationMenuItem = new ToolStripMenuItem(closureFixedDestination.Description)
{
Tag = closureFixedDestination,
Image = closureFixedDestination.DisplayIcon
};
destinationMenuItem.Click += delegate {
closureFixedDestination.ExportCapture(true, _surface, _surface.CaptureDetails);
};
destinationButton.DropDownItems.Add(destinationMenuItem);
}
}
};
destinationsToolStrip.Items.Insert(destinationsToolStrip.Items.IndexOf(toolStripSeparator16), destinationButton);
} else {
ToolStripButton destinationButton = new ToolStripButton();
destinationsToolStrip.Items.Insert(destinationsToolStrip.Items.IndexOf(toolStripSeparator16), destinationButton);
destinationButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
destinationButton.Size = new Size(23, 22);
destinationButton.Text = toolstripDestination.Description;
destinationButton.Image = toolstripDestination.DisplayIcon;
destinationButton.Click += delegate {
toolstripDestination.ExportCapture(true, _surface, _surface.CaptureDetails);
};
}
}
/// <summary>
/// According to some information I found, the clear doesn't work correctly when the shortcutkeys are set?
/// This helper method takes care of this.
/// </summary>
/// <param name="items"></param>
private void ClearItems(ToolStripItemCollection items) {
foreach(var item in items) {
ToolStripMenuItem menuItem = item as ToolStripMenuItem;
if (menuItem != null && menuItem.ShortcutKeys != Keys.None) {
menuItem.ShortcutKeys = Keys.None;
}
}
items.Clear();
}
private void FileMenuDropDownOpening(object sender, EventArgs eventArgs) {
ClearItems(fileStripMenuItem.DropDownItems);
// Add the destinations
foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {
if (IgnoreDestinations.Contains(destination.Designation)) {
continue;
}
if (!destination.IsActive) {
continue;
}
ToolStripMenuItem item = destination.GetMenuItem(true, null, DestinationToolStripMenuItemClick);
if (item != null) {
item.ShortcutKeys = destination.EditorShortcutKeys;
fileStripMenuItem.DropDownItems.Add(item);
}
}
// add the elements after the destinations
fileStripMenuItem.DropDownItems.Add(toolStripSeparator9);
fileStripMenuItem.DropDownItems.Add(closeToolStripMenuItem);
}
private delegate void SurfaceMessageReceivedThreadSafeDelegate(object sender, SurfaceMessageEventArgs eventArgs);
/// <summary>
/// This is the SufraceMessageEvent receiver which display a message in the status bar if the
/// surface is exported. It also updates the title to represent the filename, if there is one.
/// </summary>
/// <param name="sender"></param>
/// <param name="eventArgs"></param>
private void SurfaceMessageReceived(object sender, SurfaceMessageEventArgs eventArgs) {
if (InvokeRequired) {
Invoke(new SurfaceMessageReceivedThreadSafeDelegate(SurfaceMessageReceived), sender, eventArgs);
} else {
string dateTime = DateTime.Now.ToLongTimeString();
// TODO: Fix that we only open files, like in the tooltip
switch (eventArgs.MessageType) {
case SurfaceMessageTyp.FileSaved:
// Put the event message on the status label and attach the context menu
UpdateStatusLabel(dateTime + " - " + eventArgs.Message, fileSavedStatusContextMenu);
// Change title
Text = eventArgs.Surface.LastSaveFullPath + " - " + Language.GetString(LangKey.editor_title);
break;
default:
// Put the event message on the status label
UpdateStatusLabel(dateTime + " - " + eventArgs.Message);
break;
}
}
}
/// <summary>
/// This is called when the size of the surface chances, used for resizing and displaying the size information
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SurfaceSizeChanged(object sender, EventArgs e) {
if (EditorConfiguration.MatchSizeToCapture) {
// Set editor's initial size to the size of the surface plus the size of the chrome
Size imageSize = Surface.Image.Size;
Size currentFormSize = Size;
Size currentImageClientSize = panel1.ClientSize;
int minimumFormWidth = 650;
int minimumFormHeight = 530;
int newWidth = Math.Max(minimumFormWidth, currentFormSize.Width - currentImageClientSize.Width + imageSize.Width);
int newHeight = Math.Max(minimumFormHeight, currentFormSize.Height - currentImageClientSize.Height + imageSize.Height);
Size = new Size(newWidth, newHeight);
}
dimensionsLabel.Text = Surface.Image.Width + "x" + Surface.Image.Height;
ImageEditorFormResize(sender, new EventArgs());
}
public ISurface Surface {
get {
return _surface;
}
set {
SetSurface(value);
}
}
public void SetImagePath(string fullpath) {
// Check if the editor supports the format
if (fullpath != null && (fullpath.EndsWith(".ico") || fullpath.EndsWith(".wmf"))) {
fullpath = null;
}
_surface.LastSaveFullPath = fullpath;
if (fullpath == null) {
return;
}
UpdateStatusLabel(Language.GetFormattedString(LangKey.editor_imagesaved, fullpath), fileSavedStatusContextMenu);
Text = Path.GetFileName(fullpath) + " - " + Language.GetString(LangKey.editor_title);
}
private void surface_DrawingModeChanged(object source, SurfaceDrawingModeEventArgs eventArgs) {
switch (eventArgs.DrawingMode) {
case DrawingModes.None:
SetButtonChecked(btnCursor);
break;
case DrawingModes.Ellipse:
SetButtonChecked(btnEllipse);
break;
case DrawingModes.Rect:
SetButtonChecked(btnRect);
break;
case DrawingModes.Text:
SetButtonChecked(btnText);
break;
case DrawingModes.SpeechBubble:
SetButtonChecked(btnSpeechBubble);
break;
case DrawingModes.StepLabel:
SetButtonChecked(btnStepLabel);
break;
case DrawingModes.Line:
SetButtonChecked(btnLine);
break;
case DrawingModes.Arrow:
SetButtonChecked(btnArrow);
break;
case DrawingModes.Crop:
SetButtonChecked(btnCrop);
break;
case DrawingModes.Highlight:
SetButtonChecked(btnHighlight);
break;
case DrawingModes.Obfuscate:
SetButtonChecked(btnObfuscate);
break;
case DrawingModes.Path:
SetButtonChecked(btnFreehand);
break;
}
}
#region plugin interfaces
/**
* Interfaces for plugins, see GreenshotInterface for more details!
*/
public Image GetImageForExport() {
return _surface.GetImageForExport();
}
public ICaptureDetails CaptureDetails => _surface.CaptureDetails;
public ToolStripMenuItem GetPluginMenuItem() {
return pluginToolStripMenuItem;
}
public ToolStripMenuItem GetFileMenuItem() {
return fileStripMenuItem;
}
#endregion
#region filesystem options
private void BtnSaveClick(object sender, EventArgs e) {
string destinationDesignation = FileDestination.DESIGNATION;
if (_surface.LastSaveFullPath == null) {
destinationDesignation = FileWithDialogDestination.DESIGNATION;
}
DestinationHelper.ExportCapture(true, destinationDesignation, _surface, _surface.CaptureDetails);
}
private void BtnClipboardClick(object sender, EventArgs e) {
DestinationHelper.ExportCapture(true, ClipboardDestination.DESIGNATION, _surface, _surface.CaptureDetails);
}
private void BtnPrintClick(object sender, EventArgs e) {
// The BeginInvoke is a solution for the printdialog not having focus
BeginInvoke((MethodInvoker) delegate {
DestinationHelper.ExportCapture(true, PrinterDestination.DESIGNATION, _surface, _surface.CaptureDetails);
});
}
private void CloseToolStripMenuItemClick(object sender, EventArgs e) {
Close();
}
#endregion
#region drawing options
private void BtnEllipseClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Ellipse;
RefreshFieldControls();
}
private void BtnCursorClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.None;
RefreshFieldControls();
}
private void BtnRectClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Rect;
RefreshFieldControls();
}
private void BtnTextClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Text;
RefreshFieldControls();
}
private void BtnSpeechBubbleClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.SpeechBubble;
RefreshFieldControls();
}
private void BtnStepLabelClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.StepLabel;
RefreshFieldControls();
}
private void BtnLineClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Line;
RefreshFieldControls();
}
private void BtnArrowClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Arrow;
RefreshFieldControls();
}
private void BtnCropClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Crop;
RefreshFieldControls();
}
private void BtnHighlightClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Highlight;
RefreshFieldControls();
}
private void BtnObfuscateClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Obfuscate;
RefreshFieldControls();
}
private void BtnFreehandClick(object sender, EventArgs e) {
_surface.DrawingMode = DrawingModes.Path;
RefreshFieldControls();
}
private void SetButtonChecked(ToolStripButton btn) {
UncheckAllToolButtons();
btn.Checked = true;
}
private void UncheckAllToolButtons() {
if (_toolbarButtons != null) {
foreach (GreenshotToolStripButton butt in _toolbarButtons) {
butt.Checked = false;
}
}
}
private void AddRectangleToolStripMenuItemClick(object sender, EventArgs e) {
BtnRectClick(sender, e);
}
private void DrawFreehandToolStripMenuItemClick(object sender, EventArgs e) {
BtnFreehandClick(sender, e);
}
private void AddEllipseToolStripMenuItemClick(object sender, EventArgs e) {
BtnEllipseClick(sender, e);
}
private void AddTextBoxToolStripMenuItemClick(object sender, EventArgs e) {
BtnTextClick(sender, e);
}
private void AddSpeechBubbleToolStripMenuItemClick(object sender, EventArgs e) {
BtnSpeechBubbleClick(sender, e);
}
private void AddCounterToolStripMenuItemClick(object sender, EventArgs e) {
BtnStepLabelClick(sender, e);
}
private void DrawLineToolStripMenuItemClick(object sender, EventArgs e) {
BtnLineClick(sender, e);
}
private void DrawArrowToolStripMenuItemClick(object sender, EventArgs e) {
BtnArrowClick(sender, e);
}
private void RemoveObjectToolStripMenuItemClick(object sender, EventArgs e) {
_surface.RemoveSelectedElements();
}
private void BtnDeleteClick(object sender, EventArgs e) {
RemoveObjectToolStripMenuItemClick(sender, e);
}
#endregion
#region copy&paste options
private void CutToolStripMenuItemClick(object sender, EventArgs e) {
_surface.CutSelectedElements();
UpdateClipboardSurfaceDependencies();
}
private void BtnCutClick(object sender, EventArgs e) {
CutToolStripMenuItemClick(sender, e);
}
private void CopyToolStripMenuItemClick(object sender, EventArgs e) {
_surface.CopySelectedElements();
UpdateClipboardSurfaceDependencies();
}
private void BtnCopyClick(object sender, EventArgs e) {
CopyToolStripMenuItemClick(sender, e);
}
private void PasteToolStripMenuItemClick(object sender, EventArgs e) {
_surface.PasteElementFromClipboard();
UpdateClipboardSurfaceDependencies();
}
private void BtnPasteClick(object sender, EventArgs e) {
PasteToolStripMenuItemClick(sender, e);
}
private void UndoToolStripMenuItemClick(object sender, EventArgs e) {
_surface.Undo();
UpdateUndoRedoSurfaceDependencies();
}
private void BtnUndoClick(object sender, EventArgs e) {
UndoToolStripMenuItemClick(sender, e);
}
private void RedoToolStripMenuItemClick(object sender, EventArgs e) {
_surface.Redo();
UpdateUndoRedoSurfaceDependencies();
}
private void BtnRedoClick(object sender, EventArgs e) {
RedoToolStripMenuItemClick(sender, e);
}
private void DuplicateToolStripMenuItemClick(object sender, EventArgs e) {
_surface.DuplicateSelectedElements();
UpdateClipboardSurfaceDependencies();
}
#endregion
#region element properties
private void UpOneLevelToolStripMenuItemClick(object sender, EventArgs e) {
_surface.PullElementsUp();
}
private void DownOneLevelToolStripMenuItemClick(object sender, EventArgs e) {
_surface.PushElementsDown();
}
private void UpToTopToolStripMenuItemClick(object sender, EventArgs e) {
_surface.PullElementsToTop();
}
private void DownToBottomToolStripMenuItemClick(object sender, EventArgs e) {
_surface.PushElementsToBottom();
}
#endregion
#region help
private void HelpToolStripMenuItem1Click(object sender, EventArgs e) {
HelpFileLoader.LoadHelp();
}
private void AboutToolStripMenuItemClick(object sender, EventArgs e) {
MainForm.Instance.ShowAbout();
}
private void PreferencesToolStripMenuItemClick(object sender, EventArgs e) {
MainForm.Instance.ShowSetting();
}
private void BtnSettingsClick(object sender, EventArgs e) {
PreferencesToolStripMenuItemClick(sender, e);
}
private void BtnHelpClick(object sender, EventArgs e) {
HelpToolStripMenuItem1Click(sender, e);
}
#endregion
#region image editor event handlers
private void ImageEditorFormActivated(object sender, EventArgs e) {
UpdateClipboardSurfaceDependencies();
UpdateUndoRedoSurfaceDependencies();
}
private void ImageEditorFormFormClosing(object sender, FormClosingEventArgs e) {
if (_surface.Modified && !EditorConfiguration.SuppressSaveDialogAtClose) {
// Make sure the editor is visible
WindowDetails.ToForeground(Handle);
MessageBoxButtons buttons = MessageBoxButtons.YesNoCancel;
// Dissallow "CANCEL" if the application needs to shutdown
if (e.CloseReason == CloseReason.ApplicationExitCall || e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing) {
buttons = MessageBoxButtons.YesNo;
}
DialogResult result = MessageBox.Show(Language.GetString(LangKey.editor_close_on_save), Language.GetString(LangKey.editor_close_on_save_title), buttons, MessageBoxIcon.Question);
if (result.Equals(DialogResult.Cancel)) {
e.Cancel = true;
return;
}
if (result.Equals(DialogResult.Yes)) {
BtnSaveClick(sender,e);
// Check if the save was made, if not it was cancelled so we cancel the closing
if (_surface.Modified) {
e.Cancel = true;
return;
}
}
}
// persist our geometry string.
EditorConfiguration.SetEditorPlacement(new WindowDetails(Handle).WindowPlacement);
IniConfig.Save();
// remove from the editor list
EditorList.Remove(this);
_surface.Dispose();
GC.Collect();
if (coreConfiguration.MinimizeWorkingSetSize) {
PsAPI.EmptyWorkingSet();
}
}
private void ImageEditorFormKeyDown(object sender, KeyEventArgs e) {
// LOG.Debug("Got key event "+e.KeyCode + ", " + e.Modifiers);
// avoid conflict with other shortcuts and
// make sure there's no selected element claiming input focus
if(e.Modifiers.Equals(Keys.None) && !_surface.KeysLocked) {
switch(e.KeyCode) {
case Keys.Escape:
BtnCursorClick(sender, e);
break;
case Keys.R:
BtnRectClick(sender, e);
break;
case Keys.E:
BtnEllipseClick(sender, e);
break;
case Keys.L:
BtnLineClick(sender, e);
break;
case Keys.F:
BtnFreehandClick(sender, e);
break;
case Keys.A:
BtnArrowClick(sender, e);
break;
case Keys.T:
BtnTextClick(sender, e);
break;
case Keys.S:
BtnSpeechBubbleClick(sender, e);
break;
case Keys.I:
BtnStepLabelClick(sender, e);
break;
case Keys.H:
BtnHighlightClick(sender, e);
break;
case Keys.O:
BtnObfuscateClick(sender, e);
break;
case Keys.C:
BtnCropClick(sender, e);
break;
}
} else if (e.Modifiers.Equals(Keys.Control)) {
switch (e.KeyCode) {
case Keys.Z:
UndoToolStripMenuItemClick(sender, e);
break;
case Keys.Y:
RedoToolStripMenuItemClick(sender, e);
break;
case Keys.Q: // Dropshadow Ctrl + Q
AddDropshadowToolStripMenuItemMouseUp(sender, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
break;
case Keys.B: // Border Ctrl + B
AddBorderToolStripMenuItemClick(sender, e);
break;
case Keys.T: // Torn edge Ctrl + T
TornEdgesToolStripMenuItemMouseUp(sender, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
break;
case Keys.I: // Invert Ctrl + I
InvertToolStripMenuItemClick(sender, e);
break;
case Keys.G: // Grayscale Ctrl + G
GrayscaleToolStripMenuItemClick(sender, e);
break;
case Keys.Delete: // Grayscale Ctrl + Delete
ClearToolStripMenuItemClick(sender, e);
break;
case Keys.Oemcomma: // Rotate CCW Ctrl + ,
RotateCcwToolstripButtonClick(sender, e);
break;
case Keys.OemPeriod: // Rotate CW Ctrl + .
RotateCwToolstripButtonClick(sender, e);
break;
case Keys.Add: // Ctrl + +
case Keys.Oemplus: // Ctrl + +
EnlargeCanvasToolStripMenuItemClick(sender, e);
break;
case Keys.Subtract: // Ctrl + -
case Keys.OemMinus: // Ctrl + -
ShrinkCanvasToolStripMenuItemClick(sender, e);
break;
}
}
}
/// <summary>
/// This is a "work-around" for the MouseWheel event which doesn't get to the panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelMouseWheel(object sender, MouseEventArgs e) {
panel1.Focus();
}
#endregion
#region key handling
protected override bool ProcessKeyPreview(ref Message msg) {
// disable default key handling if surface has requested a lock
if (!_surface.KeysLocked) {
return base.ProcessKeyPreview(ref msg);
}
return false;
}
protected override bool ProcessCmdKey(ref Message msg, Keys keys) {
// disable default key handling if surface has requested a lock
if (!_surface.KeysLocked) {
// Go through the destinations to check the EditorShortcut Keys
// this way the menu entries don't need to be enabled.
// This also fixes bugs #3526974 & #3527020
foreach (IDestination destination in DestinationHelper.GetAllDestinations()) {
if (IgnoreDestinations.Contains(destination.Designation)) {
continue;
}
if (!destination.IsActive) {
continue;
}
if (destination.EditorShortcutKeys == keys) {
destination.ExportCapture(true, _surface, _surface.CaptureDetails);
return true;
}
}
if (!_surface.ProcessCmdKey(keys)) {
return base.ProcessCmdKey(ref msg, keys);
}
}
return false;
}
#endregion
#region helpers
private void UpdateUndoRedoSurfaceDependencies() {
if (_surface == null) {
return;
}
bool canUndo = _surface.CanUndo;
btnUndo.Enabled = canUndo;
undoToolStripMenuItem.Enabled = canUndo;
string undoAction = "";
if (canUndo) {
if (_surface.UndoActionLanguageKey != LangKey.none) {
undoAction = Language.GetString(_surface.UndoActionLanguageKey);
}
}
string undoText = Language.GetFormattedString(LangKey.editor_undo, undoAction);
btnUndo.Text = undoText;
undoToolStripMenuItem.Text = undoText;
bool canRedo = _surface.CanRedo;
btnRedo.Enabled = canRedo;
redoToolStripMenuItem.Enabled = canRedo;
string redoAction = "";
if (canRedo) {
if (_surface.RedoActionLanguageKey != LangKey.none) {
redoAction = Language.GetString(_surface.RedoActionLanguageKey);
}
}
string redoText = Language.GetFormattedString(LangKey.editor_redo, redoAction);
btnRedo.Text = redoText;
redoToolStripMenuItem.Text = redoText;
}
private void UpdateClipboardSurfaceDependencies() {
if (_surface == null) {
return;
}
// check dependencies for the Surface
bool hasItems = _surface.HasSelectedElements;
bool actionAllowedForSelection = hasItems && !_controlsDisabledDueToConfirmable;
// buttons
btnCut.Enabled = actionAllowedForSelection;
btnCopy.Enabled = actionAllowedForSelection;
btnDelete.Enabled = actionAllowedForSelection;
// menus
removeObjectToolStripMenuItem.Enabled = actionAllowedForSelection;
copyToolStripMenuItem.Enabled = actionAllowedForSelection;
cutToolStripMenuItem.Enabled = actionAllowedForSelection;
duplicateToolStripMenuItem.Enabled = actionAllowedForSelection;
// check dependencies for the Clipboard
bool hasClipboard = ClipboardHelper.ContainsFormat(SupportedClipboardFormats) || ClipboardHelper.ContainsImage();
btnPaste.Enabled = hasClipboard && !_controlsDisabledDueToConfirmable;
pasteToolStripMenuItem.Enabled = hasClipboard && !_controlsDisabledDueToConfirmable;
}
#endregion
#region status label handling
private void UpdateStatusLabel(string text, ContextMenuStrip contextMenu = null) {
statusLabel.Text = text;
statusStrip1.ContextMenuStrip = contextMenu;
}
private void ClearStatusLabel() {
UpdateStatusLabel(null);
}
private void StatusLabelClicked(object sender, MouseEventArgs e) {
ToolStrip ss = (StatusStrip)((ToolStripStatusLabel)sender).Owner;
ss.ContextMenuStrip?.Show(ss, e.X, e.Y);
}
private void CopyPathMenuItemClick(object sender, EventArgs e) {