프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Events / Event_KeyEvent.cs @ c7b02506

이력 | 보기 | 이력해설 | 다운로드 (25 KB)

1
using KCOM.Common;
2
using KCOM.Controls;
3
using KCOM.Events;
4
using MarkupToPDF.Common;
5
using MarkupToPDF.Controls.Cad;
6
using MarkupToPDF.Controls.Line;
7
using MarkupToPDF.Controls.Parsing;
8
using MarkupToPDF.Controls.Polygon;
9
using MarkupToPDF.Controls.Shape;
10
using MarkupToPDF.Controls.Text;
11
using System;
12
using System.Collections.Generic;
13
using System.ComponentModel;
14
using System.Linq;
15
using System.Text;
16
using System.Windows;
17
using System.Windows.Controls;
18
using System.Windows.Input;
19
using System.Windows.Media;
20
using System.Windows.Media.Imaging;
21
using Telerik.Windows.Controls;
22
//using static KCOM.Views.MainMenu;
23

    
24
namespace KCOM
25
{
26
    public partial class MainWindow : KCOM.Controls.CustomizedWindow.CustomWindow
27
    {
28
        public double CumulativeWheel = 0;
29
        MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn();
30
                
31
        /// <summary>
32
        /// 입력한 키 처리
33
        /// </summary>
34
        /// <param name="sender"></param>
35
        /// <param name="e"></param>
36
        public async void KeyEventDownAction(object sender, KeyEventArgs e)
37
        {
38
            //if (e.IsRepeat && !ViewerDataModel.Instance.IsPressCtrl && !ViewerDataModel.Instance.IsPressShift)
39
            //    return;
40
            await this.Dispatcher.InvokeAsync(() => {
41
            switch (e.Key)
42
            {
43
                    //강인구 추가
44
                #region 단축키 선택
45

    
46
                case Key.I:
47
                    {
48
                        if (ViewerDataModel.Instance.IsPressCtrl && ViewerDataModel.Instance.IsPressShift)
49
                        {
50
                                if (!ViewerDataModel.Instance.IsAdmin)
51
                                {
52
                                    EventHandler<WindowClosedEventArgs> closeEventHandler = (snd, evt) =>
53
                                    {
54
                                        if (evt.PromptResult == "markus01#")
55
                                        {
56
                                            ViewerDataModel.Instance.IsAdmin = true;
57
                                        }
58
                                    };
59

    
60
                                    var parameters = new DialogParameters()
61
                                    {
62
                                        ContentStyle = (Style)this.FindResource("RadPasswordPromptStyle"),
63
                                        Content = "Enter password: ",
64
                                        Closed = closeEventHandler
65
                                    };
66

    
67
                                    RadWindow.Prompt(parameters);
68
                                }
69
                                else
70
                                {
71
                                    ViewerDataModel.Instance.IsAdmin = false;
72
                                }
73
                            }
74
                    }
75
                    break;
76

    
77
                #region 전체 선택(Ctrl + A)
78
                case Key.A:
79
                    {
80
                        if (ViewerDataModel.Instance.IsPressCtrl && (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission))
81
                        {
82
                            this.dzMainMenu.ConvertInkControlToPolygon();
83

    
84
                            if (Common.ViewerDataModel.Instance.MarkupControls_USER.Count > 0)
85
                            {
86
                                var text_item_ = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as TextControl) != null && (data as TextControl).IsEditingMode == true).FirstOrDefault();
87
                                if (text_item_ != null)
88
                                {
89
                                    //2024-04-25 IRON
90
                                    //TextBox가 편집중일 때 Control + A (전체 선택) 하면 전체 텍스트가 선택되도록 수정. 
91
                                    return;
92
                                    (text_item_ as TextControl).Base_TextBlock.Visibility = Visibility.Visible;
93
                                    (text_item_ as TextControl).Base_TextBox.Visibility = Visibility.Collapsed;
94
                                    //(text_item_ as TextControl).UnEditingMode();
95

    
96
                                    //SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
97

    
98

    
99
                                    //return;
100
                                }
101

    
102
                                var Arrowtext_item_ = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as ArrowTextControl) != null && (data as ArrowTextControl).IsEditingMode == true).FirstOrDefault();
103
                                //if (Arrowtext_item_ != null && ((Arrowtext_item_ as ArrowTextControl).IsNew == false))
104
                                if(Arrowtext_item_ != null)
105
                                {
106
                                    //2024-04-25 IRON
107
                                    //TextBox가 편집중일 때 Control + A (전체 선택) 하면 전체 텍스트가 선택되도록 수정. 
108
                                    return;
109
                                    //(Arrowtext_item_ as ArrowTextControl).IsEditingMode = false;
110
                                    //(Arrowtext_item_ as ArrowTextControl).Base_TextBox.Focusable = false;
111
                                    //(Arrowtext_item_ as ArrowTextControl).UnEditingMode();
112

    
113
                                    //SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
114
                                }
115

    
116
                                    /// 전체 선택 시 선택된 토글 해제
117
                                var TogList = this.dzTopMenu.Parent.ChildrenOfType<RadToggleButton>();
118
                                this.dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.None;
119
                                this.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
120

    
121
                                if (text_item_ == null && Arrowtext_item_ == null)
122
                                {
123
                                    /// 컨트롤을 그리는 도중일 경우 컨트롤 삭제
124
                                    ViewerDataModel.Instance.MarkupControls_USER.Remove(this.dzMainMenu.currentControl);
125
                                }
126

    
127
                                this.dzMainMenu.currentControl = null;
128

    
129
                                foreach (var tog in TogList)
130
                                {
131
                                    tog.IsChecked = false;
132
                                }
133

    
134
                                SelectionSet.Instance.SelectAll();
135
                            }
136
                        }
137
                    }
138
                    break;
139
                #endregion
140

    
141
                #region 복사하기(Ctrl + C)
142
                case Key.C:
143
                    {
144
                        if (ViewerDataModel.Instance.IsPressCtrl) CopyCommand.Instance.Execute();
145
                    }
146
                    break;
147
                #endregion
148

    
149
                #region 잘라내기(Ctrl + X)
150
                case Key.X:
151
                    {
152
                        if (ViewerDataModel.Instance.IsPressCtrl) CutCommand.Instance.Execute();
153
                    }
154
                    break;
155
                #endregion
156

    
157
                #region 붙여넣기(Ctrl + V)
158
                case Key.V:
159
                    {
160
                        if (ViewerDataModel.Instance.IsPressCtrl && (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission))
161
                        {
162
                            PasteCommand.Instance.Execute();
163
                        }
164
                    }
165
                    break;
166
                #endregion
167

    
168
                #region 저장하기(Ctrl + S)
169
                case Key.S:
170
                    {
171
                        if (ViewerDataModel.Instance.IsPressCtrl && (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission))
172
                        {
173
                            var text_item_ = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as TextControl) != null && (data as TextControl).IsEditingMode == true).FirstOrDefault();
174
                            if (text_item_ != null)
175
                            {
176
                                (text_item_ as TextControl).Base_TextBlock.Visibility = Visibility.Visible;
177
                                (text_item_ as TextControl).Base_TextBox.Visibility = Visibility.Collapsed;
178
                                (text_item_ as TextControl).UnEditingMode();
179

    
180
                                SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
181
                            }
182

    
183
                            var Arrowtext_item_ = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as ArrowTextControl) != null && (data as ArrowTextControl).IsEditingMode == true).FirstOrDefault();
184
                            if (Arrowtext_item_ != null && ((Arrowtext_item_ as ArrowTextControl).IsNew == false))
185
                            {
186
                                (Arrowtext_item_ as ArrowTextControl).IsEditingMode = false;
187
                                (Arrowtext_item_ as ArrowTextControl).Base_TextBox.Focusable = false;
188
                                (Arrowtext_item_ as ArrowTextControl).UnEditingMode();
189

    
190
                                SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
191
                            }
192

    
193
                            if (text_item_ == null && Arrowtext_item_ == null)
194
                            {                                 //컨트롤을 그리는 도중일 경우 컨트롤 삭제
195
                                ViewerDataModel.Instance.MarkupControls_USER.Remove(this.dzMainMenu.currentControl);
196
                            }
197

    
198
                            this.dzMainMenu.currentControl = null;
199

    
200
                            //this.dzTopMenu.SaveEvent(null, null);
201
                            if (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission)
202
                            {
203
                                ViewerDataModel.Instance.IsMarkupUpdate = true;
204
                                this.dzTopMenu.SaveEventCallback(new object(), null);
205
                            }
206

    
207
                            //저장완료후 임시파일 삭제
208
                            //TempFile.Remove();
209
                        }
210
                    }
211
                    break;
212
                #endregion
213

    
214
                #region 프린트하기(Ctrl + P)
215
                case Key.P:
216
                    {
217
                        if (ViewerDataModel.Instance.IsPressCtrl)
218
                        {
219
                            this.dzTopMenu.Print_Start("Print");
220
                        }
221
                    }
222
                    break;
223
                    #endregion
224
                case Key.G:
225
                    {
226
                        #region Grouping 해제
227
                        if (ViewerDataModel.Instance.IsPressCtrl && ViewerDataModel.Instance.IsPressShift)
228
                        {
229
                            if (ViewerDataModel.Instance.UndoDataList == null)
230
                            {
231
                                return;
232
                            }
233

    
234
                            UndoCommand.Instance.Push(EventType.Operation, SelectionSet.Instance.SelectedItems);
235

    
236
                            SelectionSet.Instance.SelectedItems.ForEach(x => x.GroupID = string.Empty);
237
                        }
238
                        #endregion
239
                        #region Grouping
240
                        else if (ViewerDataModel.Instance.IsPressCtrl)
241
                        {
242
                            if (ViewerDataModel.Instance.UndoDataList == null)
243
                            {
244
                                return;
245
                            }
246

    
247
                            UndoCommand.Instance.Push(EventType.Operation, SelectionSet.Instance.SelectedItems);
248

    
249
                            string GroupID = Guid.NewGuid().ToString();
250
                            SelectionSet.Instance.SelectedItems.ForEach(x => x.GroupID = GroupID);
251
                        }
252
                        #endregion
253
                    }
254
                    break;
255

    
256
                #region Undo(Ctrl + Z)
257
                    case Key.Z:
258
                    {
259
                        if (ViewerDataModel.Instance.IsPressCtrl) UndoCommand.Instance.Execute();
260
                    }
261
                    break;
262
                #endregion
263

    
264
                #region Redo(Ctrl + Y)
265
                case Key.Y:
266
                    {
267
                        if (ViewerDataModel.Instance.IsPressCtrl) RedoCommand.Instance.Execute();
268
                    }
269
                    break;
270
                #endregion
271

    
272
                #region 삭제하기(Delete)
273
                case Key.Delete:
274
                    {
275
                        List<CommentUserInfo> selectItems = SelectionSet.Instance.SelectedItems;
276
                        SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
277
                        this.dzMainMenu.SelectLayer.Children.Clear();
278

    
279
                        UndoCommand.Instance.Push(EventType.Delete, selectItems);
280
                    }
281
                    break;
282
                #endregion
283

    
284
                #region 선택된 컨트롤 모두 해제 하기(ESC)
285
                case Key.Escape:
286
                    {
287
                        //캡쳐모드 일 경우 초기화
288
                        if (this.dzMainMenu.mouseHandlingMode == IKCOM.MouseHandlingMode.Capture)
289
                        {
290
                            //dzMainMenu.PN_Navi.IsEnabled = true;
291
                            this.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
292
                            ViewerDataModel.Instance.Capture_Opacity = 0;
293
                        }
294

    
295
                        if (Common.ViewerDataModel.Instance.SelectedControl == "Batch"
296
                                || Common.ViewerDataModel.Instance.SelectedControl == "MACRO")
297
                        {
298
                            this.dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.None;
299
                            this.dzMainMenu.txtBatch.Visibility = Visibility.Collapsed;
300
                            this.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
301
                            var TogList = this.dzTopMenu.Parent.ChildrenOfType<RadToggleButton>();
302
                            foreach (var tog in TogList)
303
                            {
304
                                tog.IsChecked = false;
305
                            }
306
                        }
307

    
308
                        SelectionSet.Instance.UnSelect(this.dzMainMenu);
309

    
310
                        //코멘트 그리는 도중일 경우 코멘트 삭제 및 초기화
311
                        if (this.dzMainMenu.currentControl != null)
312
                        {
313
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(this.dzMainMenu.currentControl);
314
                            this.dzMainMenu.currentControl = null;
315
                        }
316

    
317
                        //모든 컨트롤 초기화 하고 Selection모드로 변경
318
                        dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.Selecting;
319
                        dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.None;
320

    
321
                        var toggleList = this.ChildrenOfType<RadToggleButton>();
322
                        var toggleList2 = this.ChildrenOfType<RadRibbonToggleButton>();
323

    
324
                        foreach (var item in toggleList)
325
                        {
326
                            if (item.Name == "btnSelection")
327
                            {
328
                                item.IsChecked = true;
329
                            }
330
                            else
331
                            {
332
                                item.IsChecked = false;
333
                            }
334
                        }
335
                        dzMainMenu.isLeftMouseButtonDownOnWindow = false;
336
                            //foreach (var item in toggleList2)
337
                            //{
338
                            //    item.IsChecked = false;
339
                            //}
340
                            ViewerDataModel.Instance.SetAngleVisible(Visibility.Collapsed);
341
                    }
342
                    break;
343
                #endregion
344

    
345
                #region FIND(Ctrl + F)
346
                case Key.F:
347
                    {
348
                        if (ViewerDataModel.Instance.IsPressCtrl)
349
                        {
350
                            if (!this.dzMainMenu.searchPane.IsPinned)
351
                            {
352
                                this.dzMainMenu.searchPane.IsPinned = true;
353
                                if (ViewerDataModel.Instance.searchPDF != null)
354
                                {
355
                                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
356
                                    {
357
                                        this.dzMainMenu.searchPanel_Instance.tbSearch.Focusable = true;
358
                                        this.dzMainMenu.searchPanel_Instance.tbSearch.Focus();
359
                                        Keyboard.Focus(this.dzMainMenu.searchPanel_Instance.tbSearch);
360
                                    }), System.Windows.Threading.DispatcherPriority.Render);
361
                                }
362
                                else
363
                                {
364
                                    this.dzMainMenu.searchPanel_Instance.btnSearch.Focus();
365
                                }
366
                            }
367
                            else
368
                            {
369
                                this.dzMainMenu.searchPane.IsPinned = false;
370
                                this.dzMainMenu.searchPane.IsActive = false;
371
                                //this.dzMainMenu.searchPane.IsHidden = true;
372
                            }
373
                        }
374
                    }
375
                    break;
376
                #endregion
377

    
378
                #endregion
379

    
380
                //강인구 추가
381
                #region Control Move
382
                //case Key.NumPad4:
383
                //case Key.NumPad5:
384
                //case Key.NumPad6:
385
                //case Key.NumPad8:
386
                case Key.Right:
387
                case Key.Left:
388
                case Key.Up:
389
                case Key.Down:
390
                    {
391
						if(System.Windows.Input.Keyboard.FocusedElement is System.Windows.Controls.TextBox)
392
						{
393
							return;
394
						}
395
						
396
                        if(sender is UIElement)
397
                        {
398
                            (sender as UIElement).SetValue(TabNavigationExtensions.IsTabStopProperty, false);
399
                        }
400

    
401
                        Point? MovePoint = null;
402
                        if ((e.Key == Key.NumPad5) || (e.Key == Key.Down))
403
                        {
404
                            MovePoint = new Point(0, 5);
405
                        }
406
                        else if ((e.Key == Key.NumPad8) || (e.Key == Key.Up))
407
                        {
408
                            MovePoint = new Point(0, -5);
409
                        }
410
                        else if ((e.Key == Key.NumPad4) || (e.Key == Key.Left))
411
                        {
412
                            MovePoint = new Point(-5, 0);
413
                        }
414
                        else if ((e.Key == Key.NumPad6) || (e.Key == Key.Right))
415
                        {
416
                            MovePoint = new Point(5, 0);
417
                        }
418

    
419
                        if (MovePoint != null && MovePoint.HasValue)
420
                        {
421
                            if (this.dzMainMenu.SelectLayer.Children.Count > 0 && ViewerDataModel.Instance.IsPressShift)
422
                            {
423

    
424
                                this.TranslateOrRotateItems(MovePoint.Value, this.dzMainMenu.rotate.Angle);
425
                            }
426
                            else
427
                            {
428
                                //if (ViewerDataModel.Instance.IsPressCtrl)
429
                                //{
430
                                    bool IsMovePossibility = false;
431

    
432
                                    var instance = ViewerDataModel.Instance;
433

    
434
                                    if ((e.Key == Key.NumPad5) || (e.Key == Key.Down))
435
                                    {
436
                                        if (instance.ContentHeight > instance.ContentOffsetY + instance.ContentViewportHeight)
437
                                        {
438
                                            IsMovePossibility = true;
439
                                        }
440
                                    }
441
                                    else if ((e.Key == Key.NumPad8) || (e.Key == Key.Up))
442
                                    {
443
                                        if (0 < instance.ContentOffsetY)
444
                                        {
445
                                            IsMovePossibility = true;
446
                                        }
447
                                    }
448
                                    else if ((e.Key == Key.NumPad4) || (e.Key == Key.Left))
449
                                    {
450
                                        if (0 < instance.ContentOffsetX)
451
                                        {
452
                                            IsMovePossibility = true;
453
                                        }
454
                                    }
455
                                    else if ((e.Key == Key.NumPad6) || (e.Key == Key.Right))
456
                                    {
457
                                        if (instance.ContentWidth > instance.ContentOffsetX + instance.ContentViewportWidth)
458
                                        {
459
                                            IsMovePossibility = true;
460
                                        }
461
                                    }
462

    
463
                                    if (IsMovePossibility)
464
                                    {
465
                                        Vector dragOffset = new Vector(MovePoint.Value.X * -10, MovePoint.Value.Y * -10);
466

    
467
                                        this.dzMainMenu.MoveZoomAndPanControl(dragOffset);
468

    
469
                                        this.dzMainMenu.MainDocumentPanel.Focus();
470

    
471
                                        System.Diagnostics.Debug.WriteLine(this.dzMainMenu.zoomAndPanControl.ContentOffsetX);
472
                                    }
473
                                //}
474
                            }
475
                        }
476
                    }
477
                    break;
478
                #endregion
479
                case Key.PageUp:
480
                    
481
                    this.dzMainMenu.pageNavigator.GotoPage(Convert.ToInt32(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber) - 1);
482
                    break;
483
                case Key.PageDown:
484
                    this.dzMainMenu.pageNavigator.GotoPage(Convert.ToInt32(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber) + 1);
485
                    break;
486
                #region ZIndex 설정
487
                case Key.Add:
488
                    foreach (var item in SelectionSet.Instance.SelectedItems)
489
                    {
490
                        if (item.ZIndex < 100)
491
                        {
492
                            item.ZIndex++;
493
                            Canvas.SetZIndex(item, item.ZIndex);
494
                        }
495
                    }
496
                    ViewerDataModel.Instance.IsMarkupUpdate = true;
497
                    break;
498
                case Key.Subtract:
499
                    foreach(var item in SelectionSet.Instance.SelectedItems)
500
                    {
501
                        if (item.ZIndex > 0)
502
                        {
503
                            item.ZIndex--;
504
                            Canvas.SetZIndex(item, item.ZIndex);
505
                        }
506
                    }
507
                    ViewerDataModel.Instance.IsMarkupUpdate = true;
508
                    break;
509
                #endregion
510
                }
511
            });
512
        }
513

    
514

    
515
        /// <summary>
516
        /// translate or rotate items by given pt and angle
517
        /// </summary>
518
        /// <author>humkyung</author>
519
        /// <date>2019.07.03</date>
520
        /// <param name="pt">control point</param>
521
        /// <param name="dAngle">angle in degree</param>
522
        private void TranslateOrRotateItems(Point pt, double dAngle)
523
        {
524
            Point control = MarkupToPDF.Controls.Common.MathSet.RotateAbout(new Point(0, 0), pt, dAngle);
525
            foreach (var item in this.dzMainMenu.SelectLayer.Children)
526
            {
527
                if (item.GetType().Name == "AdornerFinal")
528
                {
529
                    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
530
                    {
531
                        (item as Controls.AdornerFinal).MoveRotate(new System.Windows.Controls.Primitives.DragDeltaEventArgs(control.X * 2, control.Y * 2));
532
                    }
533
                    else
534
                    {
535
                        (item as Controls.AdornerFinal).TranslateItems(control.X, control.Y);
536
                    }
537

    
538
                }
539
            }
540
        }
541
    }
542
}
클립보드 이미지 추가 (최대 크기: 500 MB)