프로젝트

일반

사용자정보

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

markus / KCOM / Events / Event_KeyEvent.cs @ a9a82876

이력 | 보기 | 이력해설 | 다운로드 (24.1 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.FirstOrDefault(data => data is TextControl && (data as TextControl).IsEditingMode);
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.FirstOrDefault(data => data is ArrowTextControl && (data as ArrowTextControl).IsEditingMode);
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
                            if (App.ViewInfo.CreateFinalPDFPermission || App.ViewInfo.NewCommentPermission)
195
                            {
196
                                ViewerDataModel.Instance.IsMarkupUpdate = true;
197
                                this.dzTopMenu.SaveEventCallback(new object(), null);
198
                            }
199
                        }
200
                    }
201
                    break;
202
                #endregion
203

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

    
224
                            UndoCommand.Instance.Push(EventType.Operation, SelectionSet.Instance.SelectedItems);
225

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

    
237
                            UndoCommand.Instance.Push(EventType.Operation, SelectionSet.Instance.SelectedItems);
238

    
239
                            string GroupID = Guid.NewGuid().ToString();
240
                            SelectionSet.Instance.SelectedItems.ForEach(x => x.GroupID = GroupID);
241
                        }
242
                        #endregion
243
                    }
244
                    break;
245

    
246
                #region Undo(Ctrl + Z)
247
                    case Key.Z:
248
                    {
249
                        if (ViewerDataModel.Instance.IsPressCtrl) UndoCommand.Instance.Execute();
250
                    }
251
                    break;
252
                #endregion
253

    
254
                #region Redo(Ctrl + Y)
255
                case Key.Y:
256
                    {
257
                        if (ViewerDataModel.Instance.IsPressCtrl) RedoCommand.Instance.Execute();
258
                    }
259
                    break;
260
                #endregion
261

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

    
269
                        UndoCommand.Instance.Push(EventType.Delete, selectItems);
270
                    }
271
                    break;
272
                #endregion
273

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

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

    
298
                        SelectionSet.Instance.UnSelect(this.dzMainMenu);
299

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

    
307
                        //모든 컨트롤 초기화 하고 Selection모드로 변경
308
                        dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.Selecting;
309
                        dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.None;
310

    
311
                        var toggleList = this.ChildrenOfType<RadToggleButton>();
312
                        var toggleList2 = this.ChildrenOfType<RadRibbonToggleButton>();
313

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

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

    
368
                #endregion
369

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

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

    
409
                        if (MovePoint != null && MovePoint.HasValue)
410
                        {
411
                            if (this.dzMainMenu.SelectLayer.Children.Count > 0 && ViewerDataModel.Instance.IsPressShift)
412
                            {
413

    
414
                                this.TranslateOrRotateItems(MovePoint.Value, this.dzMainMenu.rotate.Angle);
415
                            }
416
                            else
417
                            {
418
                                bool IsMovePossibility = false;
419

    
420
                                var instance = ViewerDataModel.Instance;
421

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

    
451
                                if (IsMovePossibility)
452
                                {
453
                                    Vector dragOffset = new Vector(MovePoint.Value.X * -10, MovePoint.Value.Y * -10);
454

    
455
                                    this.dzMainMenu.MoveZoomAndPanControl(dragOffset);
456

    
457
                                    this.dzMainMenu.MainDocumentPanel.Focus();
458

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

    
501

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

    
525
                }
526
            }
527
        }
528
    }
529
}
클립보드 이미지 추가 (최대 크기: 500 MB)