프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 0d99c609

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

1 787a4489 KangIngu
using KCOM.Common;
2
using KCOMDataModel;
3
using KCOMDataModel.DataModel;
4
using System;
5
using System.Collections.Generic;
6 6707a5c7 ljiyeon
using System.IO;
7 787a4489 KangIngu
using System.Linq;
8 71bfd53e ljiyeon
using System.Runtime.InteropServices;
9 787a4489 KangIngu
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 6707a5c7 ljiyeon
using System.Xml;
20 992a98b4 KangIngu
using Telerik.Windows.Controls;
21 7e2d29a0 ljiyeon
using WinInterop = System.Windows.Interop;
22 787a4489 KangIngu
23
namespace KCOM
24
{
25
    /// <summary>
26
    /// MainWindow.xaml에 대한 상호 작용 논리
27
    /// </summary>
28
    public partial class MainWindow : Window
29
    {
30
        public MainWindow()
31
        {
32 0c997b99 ljiyeon
            //InitializeComponent();
33 787a4489 KangIngu
            this.Loaded += MainWindow_Loaded;
34
            this.KeyDown += new KeyEventHandler(KeyEventDownAction);
35
            this.KeyUp += new KeyEventHandler(KeyEventUpAction);
36 7e2d29a0 ljiyeon
            this.SourceInitialized += new EventHandler(win_SourceInitialized);
37 787a4489 KangIngu
        }
38 ca16abb2 ljiyeon
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 787a4489 KangIngu
        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 7e2d29a0 ljiyeon
65 787a4489 KangIngu
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
66
        {
67 0c997b99 ljiyeon
            InitializeComponent();
68 ca16abb2 ljiyeon
69
            //cursor change  
70
            this.Cursor = new Cursor(CursorChange().StreamSource);
71
72 787a4489 KangIngu
            double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
73
            double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
74 9f473fb7 KangIngu
            //this.Width += 40;
75 787a4489 KangIngu
            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 3933072f ljiyeon
81 787a4489 KangIngu
            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 7e2d29a0 ljiyeon
                //#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 787a4489 KangIngu
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 7e2d29a0 ljiyeon
                //#endif
124 787a4489 KangIngu
            }
125
            else
126
            {
127
                this.dzMainMenu.ServiceOn();
128 992a98b4 KangIngu
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 e0204db0 djkim
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
137
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
138
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
139 992a98b4 KangIngu
                }
140 787a4489 KangIngu
                this.dzMainMenu.SetView(App.ViewInfo);
141 7e2d29a0 ljiyeon
                this.dzMainMenu.HubSet();
142 787a4489 KangIngu
            }
143 6707a5c7 ljiyeon
144 787a4489 KangIngu
            //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 6707a5c7 ljiyeon
161 71bfd53e ljiyeon
162 7e2d29a0 ljiyeon
        bool restoreIfMove = false;
163 71bfd53e ljiyeon
164 787a4489 KangIngu
        private void WindowDragEvent(object sender, MouseButtonEventArgs e)
165
        {
166 71bfd53e ljiyeon
            if (e.ClickCount == 2)
167 787a4489 KangIngu
            {
168 71bfd53e ljiyeon
                if ((ResizeMode == ResizeMode.CanResize) ||
169
                    (ResizeMode == ResizeMode.CanResizeWithGrip))
170 787a4489 KangIngu
                {
171 71bfd53e ljiyeon
                    SwitchState();
172 787a4489 KangIngu
                }
173
            }
174
            else
175
            {
176 71bfd53e ljiyeon
                if (WindowState == WindowState.Maximized)
177
                {
178
                    restoreIfMove = true;
179
                }
180 3933072f ljiyeon
181 787a4489 KangIngu
                this.DragMove();
182
            }
183
        }
184
185 71bfd53e ljiyeon
        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 3933072f ljiyeon
                    //this.WindowState = WindowState.Normal;
197
198 71bfd53e ljiyeon
                    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 7e2d29a0 ljiyeon
                    GetCursorPos(out lMousePosition);
208 71bfd53e ljiyeon
209
                    Left = lMousePosition.X - targetHorizontal;
210 7e2d29a0 ljiyeon
                    double top = lMousePosition.Y - targetVertical;
211
                    if(top < 10)
212
                    {
213
                        top = 10;
214
                    }
215
                    Top = lMousePosition.Y;
216 71bfd53e ljiyeon
217 3933072f ljiyeon
218 71bfd53e ljiyeon
                    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 787a4489 KangIngu
        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 af177ca1 djkim
            switch ((e.Source as Image).Name)
286 787a4489 KangIngu
            {
287 af177ca1 djkim
                case ("Win_min"):
288 787a4489 KangIngu
                    {
289
                        WindowState = WindowState.Minimized;
290
                    }
291
                    break;
292 af177ca1 djkim
                case ("Win_max"):
293 787a4489 KangIngu
                    {
294 af177ca1 djkim
                        if (WindowState == WindowState.Maximized)
295
                        {
296 787a4489 KangIngu
                            WindowState = WindowState.Normal;
297 af177ca1 djkim
                        }
298 787a4489 KangIngu
                        else
299 af177ca1 djkim
                        {
300 787a4489 KangIngu
                            WindowState = WindowState.Maximized;
301 af177ca1 djkim
                        }
302 787a4489 KangIngu
                    }
303
                    break;
304 af177ca1 djkim
                case ("Win_Close"):
305 787a4489 KangIngu
                    {
306 316d0f5c KangIngu
                        if (ViewerDataModel.Instance.UndoDataList.Count > 0)
307 69ef0800 KangIngu
                        {
308 316d0f5c KangIngu
                            DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime;
309 d2cd1e16 djkim
                            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 6707a5c7 ljiyeon
315 316d0f5c KangIngu
                            if (undoTime > updatetime)
316
                            {
317 69ef0800 KangIngu
                                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 316d0f5c KangIngu
                        }
334 787a4489 KangIngu
                        this.Close();
335
                    }
336
                    break;
337
            }
338
        }
339
340 69ef0800 KangIngu
        private void Onclose(object sender, WindowClosedEventArgs e)
341
        {
342
            if (e.DialogResult == true)
343
            {
344
                dzTopMenu.SaveEvent(null, null);
345
            }
346
        }
347 7e2d29a0 ljiyeon
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 787a4489 KangIngu
    }
489
}
클립보드 이미지 추가 (최대 크기: 500 MB)