프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ d2b05ce7

이력 | 보기 | 이력해설 | 다운로드 (17 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
        
31
        public MainWindow()
32
        {
33
            //InitializeComponent();
34
            this.Loaded += MainWindow_Loaded;
35
            this.KeyDown += new KeyEventHandler(KeyEventDownAction);
36
            this.KeyUp += new KeyEventHandler(KeyEventUpAction);
37
            this.SourceInitialized += new EventHandler(win_SourceInitialized);
38
        }
39

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

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

    
56
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
57
            {
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
            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
                this.DragMove();
181
            }
182
        }
183

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

    
189
        private void WindowDragEventMove(object sender, MouseEventArgs e)
190
        {
191
            if (restoreIfMove)
192
            {
193
                if (Mouse.LeftButton == MouseButtonState.Pressed)
194
                {
195
                    restoreIfMove = false;
196

    
197
                    double percentHorizontal = e.GetPosition(this).X / ActualWidth;
198
                    double targetHorizontal = RestoreBounds.Width * percentHorizontal;
199

    
200
                    double percentVertical = e.GetPosition(this).Y / ActualHeight;
201
                    double targetVertical = RestoreBounds.Height * percentVertical;
202

    
203
                    POINT lMousePosition;
204
                    GetCursorPos(out lMousePosition);                    
205

    
206
                    Left = lMousePosition.X - targetHorizontal;
207
                    Top = lMousePosition.Y - targetVertical;
208

    
209
                    WindowState = WindowState.Normal;
210

    
211
                    this.DragMove();
212
                }
213
            }
214
        }
215

    
216
        [DllImport("user32.dll")]
217
        [return: MarshalAs(UnmanagedType.Bool)]
218
        static extern bool GetCursorPos(out POINT lpPoint);
219

    
220
        [StructLayout(LayoutKind.Sequential)]
221
        public struct POINT
222
        {
223
            public int X;
224
            public int Y;
225

    
226
            public POINT(int x, int y)
227
            {
228
                this.X = x;
229
                this.Y = y;
230
            }
231
        }
232

    
233
        private void SwitchState()
234
        {
235
            switch (WindowState)
236
            {
237
                case WindowState.Normal:
238
                    {
239
                        WindowState = WindowState.Maximized;
240
                        break;
241
                    }
242
                case WindowState.Maximized:
243
                    {
244
                        WindowState = WindowState.Normal;
245
                        break;
246
                    }
247
            }
248
        }
249

    
250
        private void RadButton_Click(object sender, RoutedEventArgs e)
251
        {
252
            Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton;
253

    
254
            switch (button.CommandParameter.ToString())
255
            {
256
                case ("Min"):
257
                    {
258
                        WindowState = WindowState.Minimized;
259
                    }
260
                    break;
261
                case ("Max"):
262
                    {
263
                        WindowState = WindowState.Maximized;
264
                    }
265
                    break;
266
                case ("Exit"):
267
                    {
268

    
269
                    }
270
                    break;
271
            }
272
        }
273

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

    
306
                            if (undoTime > updatetime)
307
                            {
308
                                var box = new TextBlock();
309
                                box.MinWidth = 400;
310
                                box.FontSize = 11;
311
                                box.Text = "저장되지 않은 코멘트가 있습니다. 저장 하시겠습니까?";
312
                                box.TextWrapping = System.Windows.TextWrapping.Wrap;
313

    
314
                                DialogParameters parameters = new DialogParameters()
315
                                {
316
                                    Content = box,
317
                                    Header = "Confirm",
318
                                    Theme = new VisualStudio2013Theme(),
319
                                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
320
                                    Closed = Onclose,
321
                                };
322
                                RadWindow.Confirm(parameters);
323
                            }
324
                        }
325
                        this.Close();
326
                    }
327
                    break;
328
            }
329
        }
330

    
331
        private void Onclose(object sender, WindowClosedEventArgs e)
332
        {
333
            if (e.DialogResult == true)
334
            {
335
                dzTopMenu.SaveEvent(null, null);
336
            }
337
        }
338

    
339
        void win_SourceInitialized(object sender, EventArgs e)
340
        {
341
            System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
342
            WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
343
        }
344

    
345
        private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
346
        {
347
            switch (msg)
348
            {
349
                case 0x0024:
350
                    WmGetMinMaxInfo(hwnd, lParam);
351
                    handled = true;
352
                    break;
353
            }
354

    
355
            return (System.IntPtr)0;
356
        }
357

    
358
        private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
359
        {
360
            MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
361
            int MONITOR_DEFAULTTONEAREST = 0x00000002;
362
            System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
363

    
364
            if (monitor != System.IntPtr.Zero)
365
            {
366
                MONITORINFO monitorInfo = new MONITORINFO();
367
                GetMonitorInfo(monitor, monitorInfo);
368
                RECT rcWorkArea = monitorInfo.rcWork;
369
                RECT rcMonitorArea = monitorInfo.rcMonitor;
370
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
371
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
372
                mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
373
                mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
374
            }
375
            Marshal.StructureToPtr(mmi, lParam, true);
376
        }
377

    
378
        [StructLayout(LayoutKind.Sequential)]
379
        public struct POINT2
380
        {
381
            public int x;
382
            public int y;
383
            public POINT2(int x, int y)
384
            {
385
                this.x = x;
386
                this.y = y;
387
            }
388
        }
389

    
390
        [StructLayout(LayoutKind.Sequential)]
391
        public struct MINMAXINFO
392
        {
393
            public POINT2 ptReserved;
394
            public POINT2 ptMaxSize;
395
            public POINT2 ptMaxPosition;
396
            public POINT2 ptMinTrackSize;
397
            public POINT2 ptMaxTrackSize;
398
        };
399

    
400
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
401
        public class MONITORINFO
402
        {    
403
            public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));        
404
            public RECT rcMonitor = new RECT();           
405
            public RECT rcWork = new RECT();          
406
            public int dwFlags = 0;
407
        }
408
        
409
        [StructLayout(LayoutKind.Sequential, Pack = 0)]
410
        public struct RECT
411
        {
412
            public int left;
413
            public int top;
414
            public int right;
415
            public int bottom;
416

    
417
            public static readonly RECT Empty = new RECT();
418

    
419
            public int Width
420
            {
421
                get { return Math.Abs(right - left); }  // Abs needed for BIDI OS
422
            }
423

    
424
            public int Height
425
            {
426
                get { return bottom - top; }
427
            }
428

    
429
            public RECT(int left, int top, int right, int bottom)
430
            {
431
                this.left = left;
432
                this.top = top;
433
                this.right = right;
434
                this.bottom = bottom;
435
            }
436

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

    
445
            public bool IsEmpty
446
            {
447
                get
448
                {
449
                    // BUGBUG : On Bidi OS (hebrew arabic) left > right
450
                    return left >= right || top >= bottom;
451
                }
452
            }
453

    
454
            public override bool Equals(object obj)
455
            {
456
                if (!(obj is Rect)) { return false; }
457
                return (this == (RECT)obj);
458
            }
459

    
460
            public override int GetHashCode()
461
            {
462
                return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
463
            }
464

    
465
            public static bool operator ==(RECT rect1, RECT rect2)
466
            {
467
                return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
468
            }
469

    
470
            public static bool operator !=(RECT rect1, RECT rect2)
471
            {
472
                return !(rect1 == rect2);
473
            }
474
        }
475

    
476
        [DllImport("user32")]
477
        internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
478

    
479
        [DllImport("User32")]
480
        internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
481
    }
482
}
483

    
클립보드 이미지 추가 (최대 크기: 500 MB)