프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 79f3f21a

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

1
using KCOM.Common;
2
using KCOMDataModel;
3
using KCOMDataModel.DataModel;
4
using System;
5
using System.Collections.Generic;
6
using System.IO;
7
using System.Linq;
8
using System.Runtime.InteropServices;
9
using System.Text;
10
using System.Windows;
11
using System.Windows.Controls;
12
using System.Windows.Data;
13
using System.Windows.Documents;
14
using System.Windows.Input;
15
using System.Windows.Media;
16
using System.Windows.Media.Imaging;
17
using System.Windows.Navigation;
18
using System.Windows.Shapes;
19
using System.Xml;
20
using Telerik.Windows.Controls;
21
using WinInterop = System.Windows.Interop;
22

    
23
namespace KCOM
24
{
25
    /// <summary>
26
    /// MainWindow.xaml에 대한 상호 작용 논리
27
    /// </summary>
28
    public partial class MainWindow : Window
29
    {
30
        public MainWindow()
31
        {
32
            //InitializeComponent();
33
            this.Loaded += MainWindow_Loaded;
34
            this.KeyDown += new KeyEventHandler(KeyEventDownAction);
35
            this.KeyUp += new KeyEventHandler(KeyEventUpAction);
36
            this.SourceInitialized += new EventHandler(win_SourceInitialized);
37
        }
38

    
39
        public static BitmapImage CursorChange()
40
        {
41
            BitmapImage bmp = new BitmapImage();
42
            bmp.BeginInit();
43
            bmp.StreamSource = System.Windows.Application.GetResourceStream(new Uri("/KCOM;Component/Resources/Cursor/customCursor2.cur", UriKind.Relative)).Stream;
44
            return bmp;
45
        }
46

    
47
        public void DialogMessage_Alert(string content, string header)
48
        {
49
            var box = new TextBlock();
50
            box.MinWidth = 400;
51
            box.FontSize = 12;
52
            box.Text = content;
53
            box.TextWrapping = System.Windows.TextWrapping.Wrap;
54

    
55
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
56
            {
57
                Content = box,
58
                Header = header,
59
                Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(),
60
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
61
            };
62
            Telerik.Windows.Controls.RadWindow.Alert(parameters);
63
        }
64

    
65
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
66
        {
67
            InitializeComponent();
68

    
69
            //cursor change  
70
            this.Cursor = new Cursor(CursorChange().StreamSource);
71

    
72
            double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
73
            double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
74
            //this.Width += 40;
75
            double windowWidth = this.Width;
76
            double windowHeight = this.Height;
77
            this.Left = (screenWidth / 2) - (windowWidth / 2);
78
            this.Top = (screenHeight / 2) - (windowHeight / 2);
79

    
80

    
81
            ViewerDataModel.Instance.SystemMain = this;
82

    
83
            if (!App.ParameterMode)
84
            {
85
                //App.ViewInfo = new IKCOM.ViewInfo
86
                //{
87
                //    DocumentItemID = "11111112",
88
                //    //DocumentItemID = "10001",
89
                //    bPartner = false,
90
                //    CreateFinalPDFPermission = true,
91
                //    NewCommentPermission = true,
92
                //    ProjectNO = "000000",
93
                //    UserID = "H2011357",
94
                //    //UserID = "H2009115",
95
                //    //Mode = 0 , 1 , 2
96
                //};
97
                //DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
98

    
99
                //#if DEBUG
100
                //                App.ViewInfo = new IKCOM.ViewInfo
101
                //                {
102
                //                    DocumentItemID = "11111112",
103
                //                    //DocumentItemID = "10001",
104
                //                    bPartner = false,
105
                //                    CreateFinalPDFPermission = true,
106
                //                    NewCommentPermission = true,
107
                //                    ProjectNO = "000000",
108
                //                    UserID = "H2011357",
109
                //                    //UserID = "H2009115",
110
                //                    //Mode = 0 , 1 , 2
111
                //                };
112
                //                App.ParameterMode = true;
113
                //                this.dzMainMenu.ServiceOn();
114
                //                this.dzMainMenu.SetView(App.ViewInfo);
115
                //#else
116

    
117
                DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
118
                this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed;
119
                this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed;
120
                this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed;
121
                this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed;
122
                this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed;
123
                //#endif
124
            }
125
            else
126
            {
127
                this.dzMainMenu.ServiceOn();
128

    
129
                if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
130
                {
131
                    this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed;
132
                    var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList();
133
                    list.ForEach(item => item.Visibility = Visibility.Collapsed);
134
                    this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible;
135
                    this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly;
136
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
137
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
138
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
139
                }
140
                this.dzMainMenu.SetView(App.ViewInfo);
141
                this.dzMainMenu.HubSet();
142
            }
143

    
144
            //App.ViewInfo = new IKCOM.ViewInfo
145
            //{
146
            //    DocumentItemID = "11111112",
147
            //    //DocumentItemID = "10001",
148
            //    bPartner = false,
149
            //    CreateFinalPDFPermission = true,
150
            //    NewCommentPermission = true,
151
            //    ProjectNO = "000000",
152
            //    UserID = "H2011357",
153
            //    //UserID = "H2009115",
154
            //    //Mode = 0 , 1 , 2
155
            //};
156

    
157
            //this.dzMainMenu.ServiceOn();
158
            //this.dzMainMenu.SetView(App.ViewInfo);
159
        }
160

    
161

    
162
        bool restoreIfMove = false;
163

    
164
        private void WindowDragEvent(object sender, MouseButtonEventArgs e)
165
        {
166
            if (e.ClickCount == 2)
167
            {
168
                if ((ResizeMode == ResizeMode.CanResize) ||
169
                    (ResizeMode == ResizeMode.CanResizeWithGrip))
170
                {
171
                    SwitchState();
172
                }
173
            }
174
            else
175
            {
176
                if (WindowState == WindowState.Maximized)
177
                {
178
                    restoreIfMove = true;
179
                }
180

    
181
                this.DragMove();
182
            }
183
        }
184

    
185
        private void WindowDragEventUp(object sender, MouseButtonEventArgs e)
186
        {
187
            restoreIfMove = false;
188
        }
189

    
190
        private void WindowDragEventMove(object sender, MouseEventArgs e)
191
        {
192
            if (restoreIfMove)
193
            {
194
                if (Mouse.LeftButton == MouseButtonState.Pressed)
195
                {
196
                    //this.WindowState = WindowState.Normal;
197

    
198
                    restoreIfMove = false;
199

    
200
                    double percentHorizontal = e.GetPosition(this).X / ActualWidth;
201
                    double targetHorizontal = RestoreBounds.Width * percentHorizontal;
202

    
203
                    double percentVertical = e.GetPosition(this).Y / ActualHeight;
204
                    double targetVertical = RestoreBounds.Height * percentVertical;
205

    
206
                    POINT lMousePosition;
207
                    GetCursorPos(out lMousePosition);
208

    
209
                    Left = lMousePosition.X - targetHorizontal;
210
                    double top = lMousePosition.Y - targetVertical;
211
                    if(top < 10)
212
                    {
213
                        top = 10;
214
                    }
215
                    Top = lMousePosition.Y;
216

    
217

    
218
                    WindowState = WindowState.Normal;
219

    
220
                    this.DragMove();
221
                }
222
            }
223
        }
224

    
225
        [DllImport("user32.dll")]
226
        [return: MarshalAs(UnmanagedType.Bool)]
227
        static extern bool GetCursorPos(out POINT lpPoint);
228

    
229
        [StructLayout(LayoutKind.Sequential)]
230
        public struct POINT
231
        {
232
            public int X;
233
            public int Y;
234

    
235
            public POINT(int x, int y)
236
            {
237
                this.X = x;
238
                this.Y = y;
239
            }
240
        }
241

    
242
        private void SwitchState()
243
        {
244
            switch (WindowState)
245
            {
246
                case WindowState.Normal:
247
                    {
248
                        WindowState = WindowState.Maximized;
249
                        break;
250
                    }
251
                case WindowState.Maximized:
252
                    {
253
                        WindowState = WindowState.Normal;
254
                        break;
255
                    }
256
            }
257
        }
258

    
259
        private void RadButton_Click(object sender, RoutedEventArgs e)
260
        {
261
            Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton;
262

    
263
            switch (button.CommandParameter.ToString())
264
            {
265
                case ("Min"):
266
                    {
267
                        WindowState = WindowState.Minimized;
268
                    }
269
                    break;
270
                case ("Max"):
271
                    {
272
                        WindowState = WindowState.Maximized;
273
                    }
274
                    break;
275
                case ("Exit"):
276
                    {
277

    
278
                    }
279
                    break;
280
            }
281
        }
282

    
283
        private void WinState(object sender, MouseButtonEventArgs e)
284
        {
285
            switch ((e.Source as Image).Name)
286
            {
287
                case ("Win_min"):
288
                    {
289
                        WindowState = WindowState.Minimized;
290
                    }
291
                    break;
292
                case ("Win_max"):
293
                    {
294
                        if (WindowState == WindowState.Maximized)
295
                        {
296
                            WindowState = WindowState.Normal;
297
                        }
298
                        else
299
                        {
300
                            WindowState = WindowState.Maximized;
301
                        }
302
                    }
303
                    break;
304
                case ("Win_Close"):
305
                    {
306
                        if (ViewerDataModel.Instance.UndoDataList.Count > 0)
307
                        {
308
                            DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime;
309
                            DateTime updatetime = DateTime.Now.AddDays(-1);
310
                            if (ViewerDataModel.Instance._markupInfoList.Count > 0)
311
                            {
312
                                updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime;
313
                            }
314

    
315
                            if (undoTime > updatetime)
316
                            {
317
                                var box = new TextBlock();
318
                                box.MinWidth = 400;
319
                                box.FontSize = 11;
320
                                box.Text = "저장되지 않은 코멘트가 있습니다. 저장 하시겠습니까?";
321
                                box.TextWrapping = System.Windows.TextWrapping.Wrap;
322

    
323
                                DialogParameters parameters = new DialogParameters()
324
                                {
325
                                    Content = box,
326
                                    Header = "Confirm",
327
                                    Theme = new VisualStudio2013Theme(),
328
                                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
329
                                    Closed = Onclose,
330
                                };
331
                                RadWindow.Confirm(parameters);
332
                            }
333
                        }
334
                        this.Close();
335
                    }
336
                    break;
337
            }
338
        }
339

    
340
        private void Onclose(object sender, WindowClosedEventArgs e)
341
        {
342
            if (e.DialogResult == true)
343
            {
344
                dzTopMenu.SaveEvent(null, null);
345
            }
346
        }
347

    
348
        void win_SourceInitialized(object sender, EventArgs e)
349
        {
350
            System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
351
            WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
352
        }
353

    
354
        private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
355
        {
356
            switch (msg)
357
            {
358
                case 0x0024:
359
                    WmGetMinMaxInfo(hwnd, lParam);
360
                    handled = true;
361
                    break;
362
            }
363
            return (System.IntPtr)0;
364
        }
365

    
366
        private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
367
        {
368
            MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
369
            int MONITOR_DEFAULTTONEAREST = 0x00000002;
370
            System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
371

    
372
            if (monitor != System.IntPtr.Zero)
373
            {
374
                MONITORINFO monitorInfo = new MONITORINFO();
375
                GetMonitorInfo(monitor, monitorInfo);
376
                RECT rcWorkArea = monitorInfo.rcWork;
377
                RECT rcMonitorArea = monitorInfo.rcMonitor;
378
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
379
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
380
                mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
381
                mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
382
            }
383
            Marshal.StructureToPtr(mmi, lParam, true);
384
        }
385

    
386
        [StructLayout(LayoutKind.Sequential)]
387
        public struct POINT2
388
        {
389
            public int x;
390
            public int y;
391
            public POINT2(int x, int y)
392
            {
393
                this.x = x;
394
                this.y = y;
395
            }
396
        }
397

    
398
        [StructLayout(LayoutKind.Sequential)]
399
        public struct MINMAXINFO
400
        {
401
            public POINT2 ptReserved;
402
            public POINT2 ptMaxSize;
403
            public POINT2 ptMaxPosition;
404
            public POINT2 ptMinTrackSize;
405
            public POINT2 ptMaxTrackSize;
406
        };
407

    
408
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
409
        public class MONITORINFO
410
        {         
411
            public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));          
412
            public RECT rcMonitor = new RECT();      
413
            public RECT rcWork = new RECT();      
414
            public int dwFlags = 0;
415
        }
416

    
417
        [StructLayout(LayoutKind.Sequential, Pack = 0)]
418
        public struct RECT
419
        {
420
            public int left;
421
            public int top;
422
            public int right; 
423
            public int bottom;
424

    
425
            public static readonly RECT Empty = new RECT();
426

    
427
            public int Width
428
            {
429
                get { return Math.Abs(right - left); }  // Abs needed for BIDI OS
430
            }
431

    
432
            public int Height
433
            {
434
                get { return bottom - top; }
435
            }
436

    
437
            public RECT(int left, int top, int right, int bottom)
438
            {
439
                this.left = left;
440
                this.top = top;
441
                this.right = right;
442
                this.bottom = bottom;
443
            }
444

    
445
            public RECT(RECT rcSrc)
446
            {
447
                this.left = rcSrc.left;
448
                this.top = rcSrc.top;
449
                this.right = rcSrc.right;
450
                this.bottom = rcSrc.bottom;
451
            }
452

    
453
            public bool IsEmpty
454
            {
455
                get
456
                {
457
                    // BUGBUG : On Bidi OS (hebrew arabic) left > right
458
                    return left >= right || top >= bottom;
459
                }
460
            }
461

    
462
            public override bool Equals(object obj)
463
            {
464
                if (!(obj is Rect)) { return false; }
465
                return (this == (RECT)obj);
466
            }
467

    
468
            public override int GetHashCode()
469
            {
470
                return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
471
            }
472

    
473
            public static bool operator ==(RECT rect1, RECT rect2)
474
            {
475
                return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
476
            }
477

    
478
            public static bool operator !=(RECT rect1, RECT rect2)
479
            {
480
                return !(rect1 == rect2);
481
            }
482
        }
483

    
484
        [DllImport("user32")]
485
        internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
486
        [DllImport("User32")]
487
        internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
488
    }
489
}
클립보드 이미지 추가 (최대 크기: 500 MB)