프로젝트

일반

사용자정보

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

markus / KCOM / Events / Event_KeyEvent.cs @ 5bec847f

이력 | 보기 | 이력해설 | 다운로드 (24.3 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

    
23
namespace KCOM
24
{
25
    public partial class MainWindow : KCOM.Controls.CustomizedWindow.CustomWindow
26
    {
27
        /// <summary>
28
        /// 입력한 키 처리
29
        /// </summary>
30
        /// <param name="sender"></param>
31
        /// <param name="e"></param>
32
        public async void KeyEventDownAction(object sender, KeyEventArgs e)
33
        {
34
            await this.Dispatcher.InvokeAsync(() => {
35
            switch (e.Key)
36
            {
37
                    //강인구 추가
38
                #region 단축키 선택
39

    
40
                case Key.I:
41
                    {
42
                        if (ViewerDataModel.Instance.IsPressCtrl && ViewerDataModel.Instance.IsPressShift)
43
                        {
44
                                if (!ViewerDataModel.Instance.IsAdmin)
45
                                {
46
                                    EventHandler<WindowClosedEventArgs> closeEventHandler = (snd, evt) =>
47
                                    {
48
                                        if (evt.PromptResult == "markus01#")
49
                                        {
50
                                            ViewerDataModel.Instance.IsAdmin = true;
51
                                        }
52
                                    };
53

    
54
                                    var parameters = new DialogParameters()
55
                                    {
56
                                        ContentStyle = (Style)this.FindResource("RadPasswordPromptStyle"),
57
                                        Content = "Enter password: ",
58
                                        Closed = closeEventHandler
59
                                    };
60

    
61
                                    RadWindow.Prompt(parameters);
62
                                }
63
                                else
64
                                {
65
                                    ViewerDataModel.Instance.IsAdmin = false;
66
                                }
67
                            }
68
                    }
69
                    break;
70

    
71
                #region 전체 선택(Ctrl + A)
72
                case Key.A:
73
                    {
74
                        if (ViewerDataModel.Instance.IsPressCtrl && (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission))
75
                        {
76
                            this.dzMainMenu.ConvertInkControlToPolygon();
77

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

    
90
                                    //SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
91

    
92

    
93
                                    //return;
94
                                }
95

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

    
107
                                    //SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
108
                                }
109

    
110
                                    /// 전체 선택 시 선택된 토글 해제
111
                                var TogList = this.dzTopMenu.Parent.ChildrenOfType<RadToggleButton>();
112
                                this.dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.None;
113
                                this.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
114

    
115
                                if (text_item_ == null && Arrowtext_item_ == null)
116
                                {
117
                                    /// 컨트롤을 그리는 도중일 경우 컨트롤 삭제
118
                                    ViewerDataModel.Instance.MarkupControls_USER.Remove(this.dzMainMenu.currentControl);
119
                                }
120

    
121
                                this.dzMainMenu.currentControl = null;
122

    
123
                                foreach (var tog in TogList)
124
                                {
125
                                    tog.IsChecked = false;
126
                                }
127

    
128
                                SelectionSet.Instance.SelectAll();
129
                            }
130
                        }
131
                    }
132
                    break;
133
                #endregion
134

    
135
                #region 복사하기(Ctrl + C)
136
                case Key.C:
137
                    {
138
                        if (ViewerDataModel.Instance.IsPressCtrl) CopyCommand.Instance.Execute();
139
                    }
140
                    break;
141
                #endregion
142

    
143
                #region 잘라내기(Ctrl + X)
144
                case Key.X:
145
                    {
146
                        if (ViewerDataModel.Instance.IsPressCtrl) CutCommand.Instance.Execute();
147
                    }
148
                    break;
149
                #endregion
150

    
151
                #region 붙여넣기(Ctrl + V)
152
                case Key.V:
153
                    {
154
                        if (ViewerDataModel.Instance.IsPressCtrl && (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission))
155
                        {
156
                            PasteCommand.Instance.Execute();
157
                        }
158
                    }
159
                    break;
160
                #endregion
161

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

    
174
                                SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
175
                            }
176

    
177
                            var Arrowtext_item_ = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as ArrowTextControl) != null && (data as ArrowTextControl).IsEditingMode == true).FirstOrDefault();
178
                            if (Arrowtext_item_ != null && ((Arrowtext_item_ as ArrowTextControl).IsNew == false))
179
                            {
180
                                (Arrowtext_item_ as ArrowTextControl).IsEditingMode = false;
181
                                (Arrowtext_item_ as ArrowTextControl).Base_TextBox.Focusable = false;
182
                                (Arrowtext_item_ as ArrowTextControl).UnEditingMode();
183

    
184
                                SelectionSet.Instance.UnSelect(ViewerDataModel.Instance.SystemMain.dzMainMenu);
185
                            }
186

    
187
                            if (text_item_ == null && Arrowtext_item_ == null)
188
                            {                                 //컨트롤을 그리는 도중일 경우 컨트롤 삭제
189
                                ViewerDataModel.Instance.MarkupControls_USER.Remove(this.dzMainMenu.currentControl);
190
                            }
191

    
192
                            this.dzMainMenu.currentControl = null;
193

    
194
                            //this.dzTopMenu.SaveEvent(null, null);
195
                            if (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission)
196
                            {
197
                                ViewerDataModel.Instance.IsMarkupUpdate = true;
198
                                this.dzTopMenu.SaveEventCallback(new object(), null);
199
                            }
200

    
201
                            //저장완료후 임시파일 삭제
202
                            //TempFile.Remove();
203
                        }
204
                    }
205
                    break;
206
                #endregion
207

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

    
228
                            UndoCommand.Instance.Push(EventType.Operation, SelectionSet.Instance.SelectedItems);
229

    
230
                            SelectionSet.Instance.SelectedItems.ForEach(x => x.GroupID = string.Empty);
231
                        }
232
                        #endregion
233
                        #region Grouping
234
                        else if (ViewerDataModel.Instance.IsPressCtrl)
235
                        {
236
                            if (ViewerDataModel.Instance.UndoDataList == null)
237
                            {
238
                                return;
239
                            }
240

    
241
                            UndoCommand.Instance.Push(EventType.Operation, SelectionSet.Instance.SelectedItems);
242

    
243
                            string GroupID = Guid.NewGuid().ToString();
244
                            SelectionSet.Instance.SelectedItems.ForEach(x => x.GroupID = GroupID);
245
                        }
246
                        #endregion
247
                    }
248
                    break;
249

    
250
                #region Undo(Ctrl + Z)
251
                    case Key.Z:
252
                    {
253
                        if (ViewerDataModel.Instance.IsPressCtrl) UndoCommand.Instance.Execute();
254
                    }
255
                    break;
256
                #endregion
257

    
258
                #region Redo(Ctrl + Y)
259
                case Key.Y:
260
                    {
261
                        if (ViewerDataModel.Instance.IsPressCtrl) RedoCommand.Instance.Execute();
262
                    }
263
                    break;
264
                #endregion
265

    
266
                #region 삭제하기(Delete)
267
                case Key.Delete:
268
                    {
269
                        List<CommentUserInfo> selectItems = SelectionSet.Instance.SelectedItems;
270
                        SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
271
                        this.dzMainMenu.SelectLayer.Children.Clear();
272

    
273
                        UndoCommand.Instance.Push(EventType.Delete, selectItems);
274
                    }
275
                    break;
276
                #endregion
277

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

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

    
302
                        SelectionSet.Instance.UnSelect(this.dzMainMenu);
303

    
304
                        //코멘트 그리는 도중일 경우 코멘트 삭제 및 초기화
305
                        if (this.dzMainMenu.currentControl != null)
306
                        {
307
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(this.dzMainMenu.currentControl);
308
                            this.dzMainMenu.currentControl = null;
309
                        }
310

    
311
                        //모든 컨트롤 초기화 하고 Selection모드로 변경
312
                        dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.Selecting;
313
                        dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.None;
314

    
315
                        var toggleList = this.ChildrenOfType<RadToggleButton>();
316
                        var toggleList2 = this.ChildrenOfType<RadRibbonToggleButton>();
317

    
318
                        foreach (var item in toggleList)
319
                        {
320
                            if (item.Name == "btnSelection")
321
                            {
322
                                item.IsChecked = true;
323
                            }
324
                            else
325
                            {
326
                                item.IsChecked = false;
327
                            }
328
                        }
329
                        dzMainMenu.isLeftMouseButtonDownOnWindow = false;
330
                            //foreach (var item in toggleList2)
331
                            //{
332
                            //    item.IsChecked = false;
333
                            //}
334
                            ViewerDataModel.Instance.SetAngleVisible(Visibility.Collapsed);
335
                    }
336
                    break;
337
                #endregion
338

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

    
372
                #endregion
373

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

    
395
                        Point? MovePoint = null;
396
                        if ((e.Key == Key.NumPad5) || (e.Key == Key.Down))
397
                        {
398
                            MovePoint = new Point(0, 5);
399
                        }
400
                        else if ((e.Key == Key.NumPad8) || (e.Key == Key.Up))
401
                        {
402
                            MovePoint = new Point(0, -5);
403
                        }
404
                        else if ((e.Key == Key.NumPad4) || (e.Key == Key.Left))
405
                        {
406
                            MovePoint = new Point(-5, 0);
407
                        }
408
                        else if ((e.Key == Key.NumPad6) || (e.Key == Key.Right))
409
                        {
410
                            MovePoint = new Point(5, 0);
411
                        }
412

    
413
                        if (MovePoint != null && MovePoint.HasValue)
414
                        {
415
                            if (this.dzMainMenu.SelectLayer.Children.Count > 0 && ViewerDataModel.Instance.IsPressShift)
416
                            {
417

    
418
                                this.TranslateOrRotateItems(MovePoint.Value, this.dzMainMenu.rotate.Angle);
419
                            }
420
                            else
421
                            {
422
                                bool IsMovePossibility = false;
423

    
424
                                var instance = ViewerDataModel.Instance;
425

    
426
                                if ((e.Key == Key.NumPad5) || (e.Key == Key.Down))
427
                                {
428
                                    if (instance.ContentHeight > instance.ContentOffsetY + instance.ContentViewportHeight)
429
                                    {
430
                                        IsMovePossibility = true;
431
                                    }
432
                                }
433
                                else if ((e.Key == Key.NumPad8) || (e.Key == Key.Up))
434
                                {
435
                                    if (0 < instance.ContentOffsetY)
436
                                    {
437
                                        IsMovePossibility = true;
438
                                    }
439
                                }
440
                                else if ((e.Key == Key.NumPad4) || (e.Key == Key.Left))
441
                                {
442
                                    if (0 < instance.ContentOffsetX)
443
                                    {
444
                                        IsMovePossibility = true;
445
                                    }
446
                                }
447
                                else if ((e.Key == Key.NumPad6) || (e.Key == Key.Right))
448
                                {
449
                                    if (instance.ContentWidth > instance.ContentOffsetX + instance.ContentViewportWidth)
450
                                    {
451
                                        IsMovePossibility = true;
452
                                    }
453
                                }
454

    
455
                                if (IsMovePossibility)
456
                                {
457
                                    Vector dragOffset = new Vector(MovePoint.Value.X * -10, MovePoint.Value.Y * -10);
458

    
459
                                    this.dzMainMenu.MoveZoomAndPanControl(dragOffset);
460

    
461
                                    this.dzMainMenu.MainDocumentPanel.Focus();
462

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

    
505

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

    
529
                }
530
            }
531
        }
532
    }
533
}
클립보드 이미지 추가 (최대 크기: 500 MB)