markus / KCOM / MainWindow.xaml.cs @ cb5c7f06
이력 | 보기 | 이력해설 | 다운로드 (17.7 KB)
1 |
using KCOM.Common; |
---|---|
2 |
using KCOMDataModel; |
3 |
using KCOMDataModel.DataModel; |
4 |
using MarkupToPDF.Common; |
5 |
using MarkupToPDF.Controls.Parsing; |
6 |
using MarkupToPDF.Serialize.Core; |
7 |
using MarkupToPDF.Serialize.S_Control; |
8 |
using System; |
9 |
using System.Collections.Generic; |
10 |
using System.IO; |
11 |
using System.Linq; |
12 |
using System.Runtime.InteropServices; |
13 |
using System.Text; |
14 |
using System.Windows; |
15 |
using System.Windows.Controls; |
16 |
using System.Windows.Data; |
17 |
using System.Windows.Documents; |
18 |
using System.Windows.Input; |
19 |
using System.Windows.Media; |
20 |
using System.Windows.Media.Imaging; |
21 |
using System.Windows.Navigation; |
22 |
using System.Windows.Shapes; |
23 |
using System.Xml; |
24 |
using Telerik.Windows.Controls; |
25 |
using WinInterop = System.Windows.Interop; |
26 |
|
27 |
namespace KCOM |
28 |
{ |
29 |
/// <summary> |
30 |
/// MainWindow.xaml에 대한 상호 작용 논리 |
31 |
/// </summary> |
32 |
public partial class MainWindow : Window |
33 |
{ |
34 |
public MainWindow() |
35 |
{ |
36 |
App.splashString(ISplashMessage.MAINWINDOW); |
37 |
this.Loaded += MainWindow_Loaded; |
38 |
this.KeyDown += new KeyEventHandler(KeyEventDownAction); |
39 |
this.KeyUp += new KeyEventHandler(KeyEventUpAction); |
40 |
this.SourceInitialized += new EventHandler(win_SourceInitialized); |
41 |
|
42 |
} |
43 |
|
44 |
public static BitmapImage CursorChange() |
45 |
{ |
46 |
BitmapImage bmp = new BitmapImage(); |
47 |
bmp.BeginInit(); |
48 |
bmp.StreamSource = System.Windows.Application.GetResourceStream(new Uri("/KCOM;Component/Resources/Cursor/customCursor2.cur", UriKind.Relative)).Stream; |
49 |
return bmp; |
50 |
} |
51 |
|
52 |
public void DialogMessage_Alert(string content, string header) |
53 |
{ |
54 |
var box = new TextBlock(); |
55 |
box.MinWidth = 400; |
56 |
box.FontSize = 12; |
57 |
box.Text = content; |
58 |
box.TextWrapping = System.Windows.TextWrapping.Wrap; |
59 |
|
60 |
Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters() |
61 |
{ |
62 |
Owner = Application.Current.MainWindow, |
63 |
Content = box, |
64 |
Header = header, |
65 |
Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(), |
66 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
67 |
}; |
68 |
Telerik.Windows.Controls.RadWindow.Alert(parameters); |
69 |
} |
70 |
|
71 |
private void MainWindow_Loaded(object sender, RoutedEventArgs e) |
72 |
{ |
73 |
InitializeComponent(); |
74 |
|
75 |
//cursor change |
76 |
this.Cursor = new Cursor(CursorChange().StreamSource); |
77 |
|
78 |
double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth; |
79 |
double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight; |
80 |
//this.Width += 40; |
81 |
double windowWidth = this.Width; |
82 |
double windowHeight = this.Height; |
83 |
this.Left = (screenWidth / 2) - (windowWidth / 2); |
84 |
this.Top = (screenHeight / 2) - (windowHeight / 2); |
85 |
|
86 |
ViewerDataModel.Instance.SystemMain = this; |
87 |
|
88 |
if (!App.ParameterMode) |
89 |
{ |
90 |
//App.ViewInfo = new IKCOM.ViewInfo |
91 |
//{ |
92 |
// DocumentItemID = "11111112", |
93 |
// //DocumentItemID = "10001", |
94 |
// bPartner = false, |
95 |
// CreateFinalPDFPermission = true, |
96 |
// NewCommentPermission = true, |
97 |
// ProjectNO = "000000", |
98 |
// UserID = "H2011357", |
99 |
// //UserID = "H2009115", |
100 |
// //Mode = 0 , 1 , 2 |
101 |
//}; |
102 |
//DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
103 |
|
104 |
//#if DEBUG |
105 |
// App.ViewInfo = new IKCOM.ViewInfo |
106 |
// { |
107 |
// DocumentItemID = "11111112", |
108 |
// //DocumentItemID = "10001", |
109 |
// bPartner = false, |
110 |
// CreateFinalPDFPermission = true, |
111 |
// NewCommentPermission = true, |
112 |
// ProjectNO = "000000", |
113 |
// UserID = "H2011357", |
114 |
// //UserID = "H2009115", |
115 |
// //Mode = 0 , 1 , 2 |
116 |
// }; |
117 |
// App.ParameterMode = true; |
118 |
// this.dzMainMenu.ServiceOn(); |
119 |
// this.dzMainMenu.SetView(App.ViewInfo); |
120 |
//#else |
121 |
|
122 |
DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
123 |
this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed; |
124 |
this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed; |
125 |
this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed; |
126 |
this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed; |
127 |
this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed; |
128 |
//#endif |
129 |
} |
130 |
else |
131 |
{ |
132 |
this.dzMainMenu.ServiceOn(); |
133 |
|
134 |
if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) |
135 |
{ |
136 |
this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed; |
137 |
var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList(); |
138 |
list.ForEach(item => item.Visibility = Visibility.Collapsed); |
139 |
this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible; |
140 |
this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly; |
141 |
//this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed; |
142 |
//this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed; |
143 |
//this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false; |
144 |
} |
145 |
this.dzMainMenu.SetView(App.ViewInfo); |
146 |
this.dzMainMenu.HubSet(); |
147 |
} |
148 |
|
149 |
//App.ViewInfo = new IKCOM.ViewInfo |
150 |
//{ |
151 |
// DocumentItemID = "11111112", |
152 |
// //DocumentItemID = "10001", |
153 |
// bPartner = false, |
154 |
// CreateFinalPDFPermission = true, |
155 |
// NewCommentPermission = true, |
156 |
// ProjectNO = "000000", |
157 |
// UserID = "H2011357", |
158 |
// //UserID = "H2009115", |
159 |
// //Mode = 0 , 1 , 2 |
160 |
//}; |
161 |
|
162 |
//this.dzMainMenu.ServiceOn(); |
163 |
//this.dzMainMenu.SetView(App.ViewInfo); |
164 |
} |
165 |
|
166 |
|
167 |
bool restoreIfMove = false; |
168 |
|
169 |
private void WindowDragEvent(object sender, MouseButtonEventArgs e) |
170 |
{ |
171 |
if (e.ClickCount == 2) |
172 |
{ |
173 |
if ((ResizeMode == ResizeMode.CanResize) || |
174 |
(ResizeMode == ResizeMode.CanResizeWithGrip)) |
175 |
{ |
176 |
SwitchState(); |
177 |
} |
178 |
} |
179 |
else |
180 |
{ |
181 |
if (WindowState == WindowState.Maximized) |
182 |
{ |
183 |
restoreIfMove = true; |
184 |
} |
185 |
|
186 |
this.DragMove(); |
187 |
} |
188 |
} |
189 |
|
190 |
private void WindowDragEventUp(object sender, MouseButtonEventArgs e) |
191 |
{ |
192 |
restoreIfMove = false; |
193 |
} |
194 |
|
195 |
private void WindowDragEventMove(object sender, MouseEventArgs e) |
196 |
{ |
197 |
if (restoreIfMove) |
198 |
{ |
199 |
if (Mouse.LeftButton == MouseButtonState.Pressed) |
200 |
{ |
201 |
//this.WindowState = WindowState.Normal; |
202 |
|
203 |
restoreIfMove = false; |
204 |
|
205 |
double percentHorizontal = e.GetPosition(this).X / ActualWidth; |
206 |
double targetHorizontal = RestoreBounds.Width * percentHorizontal; |
207 |
|
208 |
double percentVertical = e.GetPosition(this).Y / ActualHeight; |
209 |
double targetVertical = RestoreBounds.Height * percentVertical; |
210 |
|
211 |
POINT lMousePosition; |
212 |
GetCursorPos(out lMousePosition); |
213 |
|
214 |
Left = lMousePosition.X - targetHorizontal; |
215 |
double top = lMousePosition.Y - targetVertical; |
216 |
if(top < 10) |
217 |
{ |
218 |
top = 10; |
219 |
} |
220 |
Top = lMousePosition.Y; |
221 |
|
222 |
|
223 |
WindowState = WindowState.Normal; |
224 |
|
225 |
this.DragMove(); |
226 |
} |
227 |
} |
228 |
} |
229 |
|
230 |
[DllImport("user32.dll")] |
231 |
[return: MarshalAs(UnmanagedType.Bool)] |
232 |
static extern bool GetCursorPos(out POINT lpPoint); |
233 |
|
234 |
[StructLayout(LayoutKind.Sequential)] |
235 |
public struct POINT |
236 |
{ |
237 |
public int X; |
238 |
public int Y; |
239 |
|
240 |
public POINT(int x, int y) |
241 |
{ |
242 |
this.X = x; |
243 |
this.Y = y; |
244 |
} |
245 |
} |
246 |
|
247 |
private void SwitchState() |
248 |
{ |
249 |
switch (WindowState) |
250 |
{ |
251 |
case WindowState.Normal: |
252 |
{ |
253 |
WindowState = WindowState.Maximized; |
254 |
break; |
255 |
} |
256 |
case WindowState.Maximized: |
257 |
{ |
258 |
WindowState = WindowState.Normal; |
259 |
break; |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
private void RadButton_Click(object sender, RoutedEventArgs e) |
265 |
{ |
266 |
Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton; |
267 |
|
268 |
switch (button.CommandParameter.ToString()) |
269 |
{ |
270 |
case ("Min"): |
271 |
{ |
272 |
WindowState = WindowState.Minimized; |
273 |
} |
274 |
break; |
275 |
case ("Max"): |
276 |
{ |
277 |
WindowState = WindowState.Maximized; |
278 |
} |
279 |
break; |
280 |
case ("Exit"): |
281 |
{ |
282 |
|
283 |
} |
284 |
break; |
285 |
} |
286 |
} |
287 |
|
288 |
private void WinState(object sender, MouseButtonEventArgs e) |
289 |
{ |
290 |
switch ((e.Source as Image).Name) |
291 |
{ |
292 |
case ("Win_min"): |
293 |
{ |
294 |
WindowState = WindowState.Minimized; |
295 |
} |
296 |
break; |
297 |
case ("Win_max"): |
298 |
{ |
299 |
if (WindowState == WindowState.Maximized) |
300 |
{ |
301 |
WindowState = WindowState.Normal; |
302 |
} |
303 |
else |
304 |
{ |
305 |
WindowState = WindowState.Maximized; |
306 |
} |
307 |
} |
308 |
break; |
309 |
case ("Win_Close"): |
310 |
{ |
311 |
if (ViewerDataModel.Instance.UndoDataList.Count > 0) |
312 |
{ |
313 |
DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime; |
314 |
DateTime updatetime = DateTime.Now.AddDays(-1); |
315 |
if (ViewerDataModel.Instance._markupInfoList.Count > 0) |
316 |
{ |
317 |
updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime; |
318 |
} |
319 |
|
320 |
if (undoTime > updatetime) |
321 |
{ |
322 |
var box = new TextBlock(); |
323 |
box.MinWidth = 400; |
324 |
box.FontSize = 11; |
325 |
box.Text = "저장되지 않은 코멘트가 있습니다. 저장 하시겠습니까?"; |
326 |
box.TextWrapping = System.Windows.TextWrapping.Wrap; |
327 |
|
328 |
DialogParameters parameters = new DialogParameters() |
329 |
{ |
330 |
Owner = Application.Current.MainWindow, |
331 |
Content = box, |
332 |
Header = "Confirm", |
333 |
Theme = new VisualStudio2013Theme(), |
334 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
335 |
Closed = Onclose, |
336 |
}; |
337 |
RadWindow.Confirm(parameters); |
338 |
} |
339 |
} |
340 |
this.Close(); |
341 |
} |
342 |
break; |
343 |
} |
344 |
} |
345 |
|
346 |
private void Onclose(object sender, WindowClosedEventArgs e) |
347 |
{ |
348 |
if (e.DialogResult == true) |
349 |
{ |
350 |
dzTopMenu.SaveEventCallback(null, null); |
351 |
} |
352 |
} |
353 |
|
354 |
void win_SourceInitialized(object sender, EventArgs e) |
355 |
{ |
356 |
System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle; |
357 |
WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc)); |
358 |
} |
359 |
|
360 |
private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) |
361 |
{ |
362 |
switch (msg) |
363 |
{ |
364 |
case 0x0024: |
365 |
WmGetMinMaxInfo(hwnd, lParam); |
366 |
handled = true; |
367 |
break; |
368 |
} |
369 |
return (System.IntPtr)0; |
370 |
} |
371 |
|
372 |
private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam) |
373 |
{ |
374 |
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); |
375 |
int MONITOR_DEFAULTTONEAREST = 0x00000002; |
376 |
System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); |
377 |
|
378 |
if (monitor != System.IntPtr.Zero) |
379 |
{ |
380 |
MONITORINFO monitorInfo = new MONITORINFO(); |
381 |
GetMonitorInfo(monitor, monitorInfo); |
382 |
RECT rcWorkArea = monitorInfo.rcWork; |
383 |
RECT rcMonitorArea = monitorInfo.rcMonitor; |
384 |
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left); |
385 |
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top); |
386 |
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left); |
387 |
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top); |
388 |
} |
389 |
Marshal.StructureToPtr(mmi, lParam, true); |
390 |
} |
391 |
|
392 |
[StructLayout(LayoutKind.Sequential)] |
393 |
public struct POINT2 |
394 |
{ |
395 |
public int x; |
396 |
public int y; |
397 |
public POINT2(int x, int y) |
398 |
{ |
399 |
this.x = x; |
400 |
this.y = y; |
401 |
} |
402 |
} |
403 |
|
404 |
[StructLayout(LayoutKind.Sequential)] |
405 |
public struct MINMAXINFO |
406 |
{ |
407 |
public POINT2 ptReserved; |
408 |
public POINT2 ptMaxSize; |
409 |
public POINT2 ptMaxPosition; |
410 |
public POINT2 ptMinTrackSize; |
411 |
public POINT2 ptMaxTrackSize; |
412 |
}; |
413 |
|
414 |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] |
415 |
public class MONITORINFO |
416 |
{ |
417 |
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO)); |
418 |
public RECT rcMonitor = new RECT(); |
419 |
public RECT rcWork = new RECT(); |
420 |
public int dwFlags = 0; |
421 |
} |
422 |
|
423 |
[StructLayout(LayoutKind.Sequential, Pack = 0)] |
424 |
public struct RECT |
425 |
{ |
426 |
public int left; |
427 |
public int top; |
428 |
public int right; |
429 |
public int bottom; |
430 |
|
431 |
public static readonly RECT Empty = new RECT(); |
432 |
|
433 |
public int Width |
434 |
{ |
435 |
get { return Math.Abs(right - left); } // Abs needed for BIDI OS |
436 |
} |
437 |
|
438 |
public int Height |
439 |
{ |
440 |
get { return bottom - top; } |
441 |
} |
442 |
|
443 |
public RECT(int left, int top, int right, int bottom) |
444 |
{ |
445 |
this.left = left; |
446 |
this.top = top; |
447 |
this.right = right; |
448 |
this.bottom = bottom; |
449 |
} |
450 |
|
451 |
public RECT(RECT rcSrc) |
452 |
{ |
453 |
this.left = rcSrc.left; |
454 |
this.top = rcSrc.top; |
455 |
this.right = rcSrc.right; |
456 |
this.bottom = rcSrc.bottom; |
457 |
} |
458 |
|
459 |
public bool IsEmpty |
460 |
{ |
461 |
get |
462 |
{ |
463 |
// BUGBUG : On Bidi OS (hebrew arabic) left > right |
464 |
return left >= right || top >= bottom; |
465 |
} |
466 |
} |
467 |
|
468 |
public override bool Equals(object obj) |
469 |
{ |
470 |
if (!(obj is Rect)) { return false; } |
471 |
return (this == (RECT)obj); |
472 |
} |
473 |
|
474 |
public override int GetHashCode() |
475 |
{ |
476 |
return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode(); |
477 |
} |
478 |
|
479 |
public static bool operator ==(RECT rect1, RECT rect2) |
480 |
{ |
481 |
return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom); |
482 |
} |
483 |
|
484 |
public static bool operator !=(RECT rect1, RECT rect2) |
485 |
{ |
486 |
return !(rect1 == rect2); |
487 |
} |
488 |
} |
489 |
|
490 |
[DllImport("user32")] |
491 |
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi); |
492 |
[DllImport("User32")] |
493 |
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags); |
494 |
} |
495 |
} |