프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ b9b01f8e

이력 | 보기 | 이력해설 | 다운로드 (17.6 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
                Owner = Application.Current.MainWindow,
58
                Content = box,
59
                Header = header,
60
                Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(),
61
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
62
            };
63
            Telerik.Windows.Controls.RadWindow.Alert(parameters);
64
        }
65

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

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

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

    
81

    
82
            ViewerDataModel.Instance.SystemMain = this;
83

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

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

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

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

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

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

    
162

    
163
        bool restoreIfMove = false;
164

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

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

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

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

    
199
                    restoreIfMove = false;
200

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

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

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

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

    
218

    
219
                    WindowState = WindowState.Normal;
220

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

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

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

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

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

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

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

    
279
                    }
280
                    break;
281
            }
282
        }
283

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

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

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

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

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

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

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

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

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

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

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

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

    
427
            public static readonly RECT Empty = new RECT();
428

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

    
434
            public int Height
435
            {
436
                get { return bottom - top; }
437
            }
438

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

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

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

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

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

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

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

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