markus / KCOM / MainWindow.xaml.cs @ b7637656
이력 | 보기 | 이력해설 | 다운로드 (17.6 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 | b9b01f8e | ljiyeon | Owner = Application.Current.MainWindow, |
58 | 787a4489 | KangIngu | 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 | 7e2d29a0 | ljiyeon | |
66 | 787a4489 | KangIngu | private void MainWindow_Loaded(object sender, RoutedEventArgs e) |
67 | { |
||
68 | 0c997b99 | ljiyeon | InitializeComponent(); |
69 | ca16abb2 | ljiyeon | |
70 | //cursor change |
||
71 | this.Cursor = new Cursor(CursorChange().StreamSource); |
||
72 | |||
73 | 787a4489 | KangIngu | double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth; |
74 | double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight; |
||
75 | 9f473fb7 | KangIngu | //this.Width += 40; |
76 | 787a4489 | KangIngu | 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 | 3933072f | ljiyeon | |
82 | 787a4489 | KangIngu | 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 | 7e2d29a0 | ljiyeon | //#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 | 787a4489 | KangIngu | |
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 | 7e2d29a0 | ljiyeon | //#endif |
125 | 787a4489 | KangIngu | } |
126 | else |
||
127 | { |
||
128 | this.dzMainMenu.ServiceOn(); |
||
129 | 992a98b4 | KangIngu | |
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 | e0204db0 | djkim | //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed; |
138 | //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed; |
||
139 | //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false; |
||
140 | 992a98b4 | KangIngu | } |
141 | 787a4489 | KangIngu | this.dzMainMenu.SetView(App.ViewInfo); |
142 | 7e2d29a0 | ljiyeon | this.dzMainMenu.HubSet(); |
143 | 787a4489 | KangIngu | } |
144 | 6707a5c7 | ljiyeon | |
145 | 787a4489 | KangIngu | //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 | 6707a5c7 | ljiyeon | |
162 | 71bfd53e | ljiyeon | |
163 | 7e2d29a0 | ljiyeon | bool restoreIfMove = false; |
164 | 71bfd53e | ljiyeon | |
165 | 787a4489 | KangIngu | private void WindowDragEvent(object sender, MouseButtonEventArgs e) |
166 | { |
||
167 | 71bfd53e | ljiyeon | if (e.ClickCount == 2) |
168 | 787a4489 | KangIngu | { |
169 | 71bfd53e | ljiyeon | if ((ResizeMode == ResizeMode.CanResize) || |
170 | (ResizeMode == ResizeMode.CanResizeWithGrip)) |
||
171 | 787a4489 | KangIngu | { |
172 | 71bfd53e | ljiyeon | SwitchState(); |
173 | 787a4489 | KangIngu | } |
174 | } |
||
175 | else |
||
176 | { |
||
177 | 71bfd53e | ljiyeon | if (WindowState == WindowState.Maximized) |
178 | { |
||
179 | restoreIfMove = true; |
||
180 | } |
||
181 | 3933072f | ljiyeon | |
182 | 787a4489 | KangIngu | this.DragMove(); |
183 | } |
||
184 | } |
||
185 | |||
186 | 71bfd53e | ljiyeon | 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 | 3933072f | ljiyeon | //this.WindowState = WindowState.Normal; |
198 | |||
199 | 71bfd53e | ljiyeon | 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 | 7e2d29a0 | ljiyeon | GetCursorPos(out lMousePosition); |
209 | 71bfd53e | ljiyeon | |
210 | Left = lMousePosition.X - targetHorizontal; |
||
211 | 7e2d29a0 | ljiyeon | double top = lMousePosition.Y - targetVertical; |
212 | if(top < 10) |
||
213 | { |
||
214 | top = 10; |
||
215 | } |
||
216 | Top = lMousePosition.Y; |
||
217 | 71bfd53e | ljiyeon | |
218 | 3933072f | ljiyeon | |
219 | 71bfd53e | ljiyeon | 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 | 787a4489 | KangIngu | 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 | af177ca1 | djkim | switch ((e.Source as Image).Name) |
287 | 787a4489 | KangIngu | { |
288 | af177ca1 | djkim | case ("Win_min"): |
289 | 787a4489 | KangIngu | { |
290 | WindowState = WindowState.Minimized; |
||
291 | } |
||
292 | break; |
||
293 | af177ca1 | djkim | case ("Win_max"): |
294 | 787a4489 | KangIngu | { |
295 | af177ca1 | djkim | if (WindowState == WindowState.Maximized) |
296 | { |
||
297 | 787a4489 | KangIngu | WindowState = WindowState.Normal; |
298 | af177ca1 | djkim | } |
299 | 787a4489 | KangIngu | else |
300 | af177ca1 | djkim | { |
301 | 787a4489 | KangIngu | WindowState = WindowState.Maximized; |
302 | af177ca1 | djkim | } |
303 | 787a4489 | KangIngu | } |
304 | break; |
||
305 | af177ca1 | djkim | case ("Win_Close"): |
306 | 787a4489 | KangIngu | { |
307 | 316d0f5c | KangIngu | if (ViewerDataModel.Instance.UndoDataList.Count > 0) |
308 | 69ef0800 | KangIngu | { |
309 | 316d0f5c | KangIngu | DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime; |
310 | d2cd1e16 | djkim | 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 | 6707a5c7 | ljiyeon | |
316 | 316d0f5c | KangIngu | if (undoTime > updatetime) |
317 | { |
||
318 | 69ef0800 | KangIngu | 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 | b9b01f8e | ljiyeon | Owner = Application.Current.MainWindow, |
327 | 69ef0800 | KangIngu | 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 | 316d0f5c | KangIngu | } |
336 | 787a4489 | KangIngu | this.Close(); |
337 | } |
||
338 | break; |
||
339 | } |
||
340 | } |
||
341 | |||
342 | 69ef0800 | KangIngu | private void Onclose(object sender, WindowClosedEventArgs e) |
343 | { |
||
344 | if (e.DialogResult == true) |
||
345 | { |
||
346 | dzTopMenu.SaveEvent(null, null); |
||
347 | } |
||
348 | } |
||
349 | 7e2d29a0 | ljiyeon | |
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 | b9b01f8e | ljiyeon | handled = true; |
363 | 7e2d29a0 | ljiyeon | 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 | 787a4489 | KangIngu | } |
491 | } |