markus / KCOM / MainWindow.xaml.cs @ 366f00c2
이력 | 보기 | 이력해설 | 다운로드 (23.7 KB)
1 |
using KCOM.Common; |
---|---|
2 |
using KCOM.Controls; |
3 |
using KCOM.Views; |
4 |
using KCOMDataModel; |
5 |
using KCOMDataModel.DataModel; |
6 |
using MarkupToPDF.Common; |
7 |
using MarkupToPDF.Controls.Parsing; |
8 |
using MarkupToPDF.Serialize.Core; |
9 |
using MarkupToPDF.Serialize.S_Control; |
10 |
using System; |
11 |
using System.Collections.Generic; |
12 |
using System.ComponentModel; |
13 |
using System.Diagnostics; |
14 |
using System.IO; |
15 |
using System.Linq; |
16 |
using System.Net; |
17 |
using System.Reflection; |
18 |
using System.Runtime.InteropServices; |
19 |
using System.Text; |
20 |
using System.Threading; |
21 |
using System.Threading.Tasks; |
22 |
using System.Windows; |
23 |
using System.Windows.Controls; |
24 |
using System.Windows.Data; |
25 |
using System.Windows.Documents; |
26 |
using System.Windows.Input; |
27 |
using System.Windows.Media; |
28 |
using System.Windows.Media.Imaging; |
29 |
using System.Windows.Navigation; |
30 |
using System.Windows.Shapes; |
31 |
using System.Xml; |
32 |
using Telerik.Windows.Controls; |
33 |
using WinInterop = System.Windows.Interop; |
34 |
|
35 |
namespace KCOM |
36 |
{ |
37 |
/// <summary> |
38 |
/// MainWindow.xaml에 대한 상호 작용 논리 |
39 |
/// </summary> |
40 |
public partial class MainWindow : Window |
41 |
{ |
42 |
bool isSaveCheck = false; |
43 |
|
44 |
ProgressControl progressControl = null; |
45 |
string destfilepath = string.Empty; |
46 |
|
47 |
public MainWindow() |
48 |
{ |
49 |
App.splashString(ISplashMessage.MAINWINDOW); |
50 |
this.Loaded += MainWindow_Loaded; |
51 |
this.Unloaded += MainWindow_Unloaded; |
52 |
this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction); |
53 |
this.SourceInitialized += new EventHandler(win_SourceInitialized); |
54 |
} |
55 |
|
56 |
private void MainWindow_Unloaded(object sender, RoutedEventArgs e) |
57 |
{ |
58 |
//ViewerDataModel.Instance.ImageViewPath.UriSource = null; |
59 |
//ViewerDataModel.Instance.ImageViewPath_C.UriSource = null; |
60 |
} |
61 |
|
62 |
public static BitmapImage CursorChange() |
63 |
{ |
64 |
BitmapImage bmp = new BitmapImage(); |
65 |
bmp.BeginInit(); |
66 |
bmp.StreamSource = System.Windows.Application.GetResourceStream(new Uri("/KCOM;Component/Resources/Cursor/customCursor2.cur", UriKind.Relative)).Stream; |
67 |
return bmp; |
68 |
} |
69 |
|
70 |
public void DialogMessage_Alert(string content, string header) |
71 |
{ |
72 |
Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters() |
73 |
{ |
74 |
Owner = Application.Current.MainWindow, |
75 |
Content = new TextBlock() |
76 |
{ |
77 |
MinWidth = 400, |
78 |
FontSize = 12, |
79 |
Text = content, |
80 |
TextWrapping = System.Windows.TextWrapping.Wrap |
81 |
}, |
82 |
Header = header, |
83 |
Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(), |
84 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
85 |
}; |
86 |
Telerik.Windows.Controls.RadWindow.Alert(parameters); |
87 |
} |
88 |
|
89 |
private void MainWindow_Loaded(object sender, RoutedEventArgs e) |
90 |
{ |
91 |
InitializeComponent(); |
92 |
|
93 |
//cursor change |
94 |
this.Cursor = new Cursor(CursorChange().StreamSource); |
95 |
|
96 |
double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth; |
97 |
double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight; |
98 |
//this.Width += 40; |
99 |
double windowWidth = this.Width; |
100 |
double windowHeight = this.Height; |
101 |
this.Left = (screenWidth / 2) - (windowWidth / 2); |
102 |
this.Top = (screenHeight / 2) - (windowHeight / 2); |
103 |
|
104 |
ViewerDataModel.Instance.SystemMain = this; |
105 |
|
106 |
if (!App.ParameterMode) |
107 |
{ |
108 |
//App.ViewInfo = new IKCOM.ViewInfo |
109 |
//{ |
110 |
// DocumentItemID = "11111112", |
111 |
// //DocumentItemID = "10001", |
112 |
// bPartner = false, |
113 |
// CreateFinalPDFPermission = true, |
114 |
// NewCommentPermission = true, |
115 |
// ProjectNO = "000000", |
116 |
// UserID = "H2011357", |
117 |
// //UserID = "H2009115", |
118 |
// //Mode = 0 , 1 , 2 |
119 |
//}; |
120 |
//DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
121 |
|
122 |
//#if DEBUG |
123 |
// App.ViewInfo = new IKCOM.ViewInfo |
124 |
// { |
125 |
// DocumentItemID = "11111112", |
126 |
// //DocumentItemID = "10001", |
127 |
// bPartner = false, |
128 |
// CreateFinalPDFPermission = true, |
129 |
// NewCommentPermission = true, |
130 |
// ProjectNO = "000000", |
131 |
// UserID = "H2011357", |
132 |
// //UserID = "H2009115", |
133 |
// //Mode = 0 , 1 , 2 |
134 |
// }; |
135 |
// App.ParameterMode = true; |
136 |
// this.dzMainMenu.ServiceOn(); |
137 |
// this.dzMainMenu.SetView(App.ViewInfo); |
138 |
//#else |
139 |
|
140 |
DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
141 |
this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed; |
142 |
this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed; |
143 |
this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed; |
144 |
this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed; |
145 |
this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed; |
146 |
//#endif |
147 |
} |
148 |
else |
149 |
{ |
150 |
this.dzMainMenu.ServiceOn(); |
151 |
|
152 |
if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) |
153 |
{ |
154 |
this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed; |
155 |
var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList(); |
156 |
list.ForEach(item => item.Visibility = Visibility.Collapsed); |
157 |
this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible; |
158 |
this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly; |
159 |
//this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed; |
160 |
//this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed; |
161 |
//this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false; |
162 |
} |
163 |
|
164 |
try |
165 |
{ |
166 |
///this.dzMainMenu.HubSet(); |
167 |
this.dzMainMenu.SetView(App.ViewInfo); |
168 |
} |
169 |
catch (Exception ex) |
170 |
{ |
171 |
MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace)); |
172 |
|
173 |
System.Environment.Exit(0); |
174 |
} |
175 |
} |
176 |
|
177 |
//App.ViewInfo = new IKCOM.ViewInfo |
178 |
//{ |
179 |
// DocumentItemID = "11111112", |
180 |
// //DocumentItemID = "10001", |
181 |
// bPartner = false, |
182 |
// CreateFinalPDFPermission = true, |
183 |
// NewCommentPermission = true, |
184 |
// ProjectNO = "000000", |
185 |
// UserID = "H2011357", |
186 |
// //UserID = "H2009115", |
187 |
// //Mode = 0 , 1 , 2 |
188 |
//}; |
189 |
|
190 |
//this.dzMainMenu.ServiceOn(); |
191 |
//this.dzMainMenu.SetView(App.ViewInfo); |
192 |
} |
193 |
|
194 |
|
195 |
bool restoreIfMove = false; |
196 |
|
197 |
private void WindowDragEvent(object sender, MouseButtonEventArgs e) |
198 |
{ |
199 |
if(string.IsNullOrEmpty(destfilepath)) |
200 |
{ |
201 |
if (e.ClickCount == 2) |
202 |
{ |
203 |
if ((ResizeMode == ResizeMode.CanResize) || |
204 |
(ResizeMode == ResizeMode.CanResizeWithGrip)) |
205 |
{ |
206 |
SwitchState(); |
207 |
} |
208 |
} |
209 |
else |
210 |
{ |
211 |
if (WindowState == WindowState.Maximized) |
212 |
{ |
213 |
restoreIfMove = true; |
214 |
} |
215 |
|
216 |
this.DragMove(); |
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
private void WindowDragEventUp(object sender, MouseButtonEventArgs e) |
222 |
{ |
223 |
restoreIfMove = false; |
224 |
} |
225 |
|
226 |
private void WindowDragEventMove(object sender, MouseEventArgs e) |
227 |
{ |
228 |
if (restoreIfMove) |
229 |
{ |
230 |
if (Mouse.LeftButton == MouseButtonState.Pressed) |
231 |
{ |
232 |
//this.WindowState = WindowState.Normal; |
233 |
|
234 |
restoreIfMove = false; |
235 |
|
236 |
double percentHorizontal = e.GetPosition(this).X / ActualWidth; |
237 |
double targetHorizontal = RestoreBounds.Width * percentHorizontal; |
238 |
|
239 |
double percentVertical = e.GetPosition(this).Y / ActualHeight; |
240 |
double targetVertical = RestoreBounds.Height * percentVertical; |
241 |
|
242 |
POINT lMousePosition; |
243 |
GetCursorPos(out lMousePosition); |
244 |
|
245 |
Left = lMousePosition.X - targetHorizontal; |
246 |
double top = lMousePosition.Y - targetVertical; |
247 |
if(top < 10) |
248 |
{ |
249 |
top = 10; |
250 |
} |
251 |
Top = lMousePosition.Y; |
252 |
|
253 |
|
254 |
WindowState = WindowState.Normal; |
255 |
|
256 |
this.DragMove(); |
257 |
} |
258 |
} |
259 |
} |
260 |
|
261 |
[DllImport("user32.dll")] |
262 |
[return: MarshalAs(UnmanagedType.Bool)] |
263 |
static extern bool GetCursorPos(out POINT lpPoint); |
264 |
|
265 |
[StructLayout(LayoutKind.Sequential)] |
266 |
public struct POINT |
267 |
{ |
268 |
public int X; |
269 |
public int Y; |
270 |
|
271 |
public POINT(int x, int y) |
272 |
{ |
273 |
this.X = x; |
274 |
this.Y = y; |
275 |
} |
276 |
} |
277 |
|
278 |
private void SwitchState() |
279 |
{ |
280 |
switch (WindowState) |
281 |
{ |
282 |
case WindowState.Normal: |
283 |
{ |
284 |
WindowState = WindowState.Maximized; |
285 |
break; |
286 |
} |
287 |
case WindowState.Maximized: |
288 |
{ |
289 |
WindowState = WindowState.Normal; |
290 |
break; |
291 |
} |
292 |
} |
293 |
} |
294 |
|
295 |
private void RadButton_Click(object sender, RoutedEventArgs e) |
296 |
{ |
297 |
Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton; |
298 |
|
299 |
switch (button.CommandParameter.ToString()) |
300 |
{ |
301 |
case ("Min"): |
302 |
{ |
303 |
WindowState = WindowState.Minimized; |
304 |
} |
305 |
break; |
306 |
case ("Max"): |
307 |
{ |
308 |
WindowState = WindowState.Maximized; |
309 |
} |
310 |
break; |
311 |
case ("Exit"): |
312 |
{ |
313 |
|
314 |
} |
315 |
break; |
316 |
} |
317 |
} |
318 |
|
319 |
private void WinState(object sender, MouseButtonEventArgs e) |
320 |
{ |
321 |
switch ((e.Source as Image).Name) |
322 |
{ |
323 |
case ("Win_min"): |
324 |
{ |
325 |
WindowState = WindowState.Minimized; |
326 |
} |
327 |
break; |
328 |
case ("Win_max"): |
329 |
{ |
330 |
if (WindowState == WindowState.Maximized) |
331 |
{ |
332 |
WindowState = WindowState.Normal; |
333 |
} |
334 |
else |
335 |
{ |
336 |
WindowState = WindowState.Maximized; |
337 |
} |
338 |
} |
339 |
break; |
340 |
case ("Win_Close"): |
341 |
{ |
342 |
SaveCheck(); |
343 |
//Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행. |
344 |
KeyValuePair<bool, string> updatecheck = UpdateCheck(); |
345 |
if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value)) |
346 |
{ |
347 |
CallUpdateProcess(updatecheck.Value); |
348 |
} |
349 |
this.Close(); |
350 |
} |
351 |
break; |
352 |
} |
353 |
} |
354 |
|
355 |
private void SaveCheck() |
356 |
{ |
357 |
if (ViewerDataModel.Instance.UndoDataList.Count > 0) |
358 |
{ |
359 |
DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime; |
360 |
DateTime updatetime = DateTime.Now.AddDays(-1); |
361 |
if (ViewerDataModel.Instance._markupInfoList.Count > 0) |
362 |
{ |
363 |
updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime; |
364 |
} |
365 |
|
366 |
if (undoTime > updatetime) |
367 |
{ |
368 |
DialogParameters parameters = new DialogParameters() |
369 |
{ |
370 |
Owner = Application.Current.MainWindow, |
371 |
Content = new TextBlock() |
372 |
{ |
373 |
MinWidth = 400, |
374 |
FontSize = 11, |
375 |
Text = "Found unsaved comments. Save now?", |
376 |
TextWrapping = System.Windows.TextWrapping.Wrap |
377 |
}, |
378 |
Header = "Confirm", |
379 |
Theme = new VisualStudio2013Theme(), |
380 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
381 |
Closed = OnClosingSave, |
382 |
}; |
383 |
RadWindow.Confirm(parameters); |
384 |
} |
385 |
else |
386 |
{ |
387 |
isSaveCheck = true; |
388 |
} |
389 |
}else |
390 |
{ |
391 |
isSaveCheck = true; |
392 |
} |
393 |
} |
394 |
private void OnClosingSave(object sender, WindowClosedEventArgs e) |
395 |
{ |
396 |
if (e.DialogResult == true) |
397 |
{ |
398 |
dzTopMenu.SaveEventCallback(null, null); |
399 |
} |
400 |
isSaveCheck = true; |
401 |
} |
402 |
|
403 |
private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) |
404 |
{ |
405 |
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
406 |
{ |
407 |
double bytesIn = double.Parse(e.BytesReceived.ToString()); |
408 |
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); |
409 |
double percentage = bytesIn / totalBytes * 100; |
410 |
progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %"; |
411 |
progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString()); |
412 |
})); |
413 |
} |
414 |
|
415 |
/// <summary> |
416 |
/// KCOM_API 를 통해 업데이트 URL 을 가져옴. |
417 |
/// false : 업데이트 불필요. |
418 |
/// true : 업데이트 필요. url 을 같이 Return. |
419 |
/// </summary> |
420 |
/// <returns></returns> |
421 |
private KeyValuePair<bool, string> UpdateCheck() |
422 |
{ |
423 |
bool isUpdateCheck = false; |
424 |
string updateurl = string.Empty; |
425 |
try |
426 |
{ |
427 |
bool is64bit = Environment.Is64BitProcess; |
428 |
string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
429 |
updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion); |
430 |
|
431 |
if (Check_Uri.isUri(updateurl)) |
432 |
{ |
433 |
DialogParameters parameters = new DialogParameters() |
434 |
{ |
435 |
Owner = Application.Current.MainWindow, |
436 |
Content = new TextBlock() |
437 |
{ |
438 |
MinWidth = 400, |
439 |
FontSize = 11, |
440 |
Text = "Update is available. \n Update now?", |
441 |
TextWrapping = System.Windows.TextWrapping.Wrap |
442 |
}, |
443 |
Header = "Confirm", |
444 |
Theme = new VisualStudio2013Theme(), |
445 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
446 |
Closed = delegate (object windowSender, WindowClosedEventArgs e) |
447 |
{ |
448 |
if (e.DialogResult == true) |
449 |
{ |
450 |
isUpdateCheck = true; |
451 |
} |
452 |
else |
453 |
{ |
454 |
isUpdateCheck = false; |
455 |
} |
456 |
} |
457 |
}; |
458 |
RadWindow.Confirm(parameters); |
459 |
|
460 |
} |
461 |
else |
462 |
{ |
463 |
isUpdateCheck = false; |
464 |
} |
465 |
} |
466 |
catch (Exception ex) |
467 |
{ |
468 |
throw ex; |
469 |
} |
470 |
return new KeyValuePair<bool, string>(isUpdateCheck, updateurl); |
471 |
} |
472 |
|
473 |
/// <summary> |
474 |
/// SmartUpdate 를 호출. |
475 |
/// </summary> |
476 |
/// <param name="updateurl">Download 할 설치파일 경로</param> |
477 |
private void CallUpdateProcess(string updateurl) |
478 |
{ |
479 |
ProcessStartInfo proInfo = new ProcessStartInfo(); |
480 |
string smartupdaterpath = string.Empty; |
481 |
smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe"); |
482 |
Process.Start(smartupdaterpath, updateurl); |
483 |
} |
484 |
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) |
485 |
{ |
486 |
try |
487 |
{ |
488 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
489 |
{ |
490 |
progressControl.splashText.Text = "Download Completed"; |
491 |
})); |
492 |
if(progressControl != null) |
493 |
{ |
494 |
progressControl.Close(); |
495 |
progressControl = null; |
496 |
} |
497 |
if(File.Exists(destfilepath)) |
498 |
{ |
499 |
ProcessStartInfo update_msi = new ProcessStartInfo(); |
500 |
update_msi.FileName = destfilepath; |
501 |
Process.Start(update_msi); |
502 |
} |
503 |
this.Close(); |
504 |
} |
505 |
catch (Exception) |
506 |
{ |
507 |
throw; |
508 |
} |
509 |
|
510 |
} |
511 |
|
512 |
void win_SourceInitialized(object sender, EventArgs e) |
513 |
{ |
514 |
//System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle; |
515 |
//WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc)); |
516 |
} |
517 |
|
518 |
private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) |
519 |
{ |
520 |
switch (msg) |
521 |
{ |
522 |
case 0x0024: |
523 |
WmGetMinMaxInfo(hwnd, lParam); |
524 |
handled = true; |
525 |
break; |
526 |
} |
527 |
return (System.IntPtr)0; |
528 |
} |
529 |
|
530 |
private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam) |
531 |
{ |
532 |
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); |
533 |
int MONITOR_DEFAULTTONEAREST = 0x00000002; |
534 |
System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); |
535 |
|
536 |
if (monitor != System.IntPtr.Zero) |
537 |
{ |
538 |
MONITORINFO monitorInfo = new MONITORINFO(); |
539 |
GetMonitorInfo(monitor, monitorInfo); |
540 |
RECT rcWorkArea = monitorInfo.rcWork; |
541 |
RECT rcMonitorArea = monitorInfo.rcMonitor; |
542 |
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left); |
543 |
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top); |
544 |
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left); |
545 |
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top); |
546 |
} |
547 |
Marshal.StructureToPtr(mmi, lParam, true); |
548 |
} |
549 |
|
550 |
[StructLayout(LayoutKind.Sequential)] |
551 |
public struct POINT2 |
552 |
{ |
553 |
public int x; |
554 |
public int y; |
555 |
public POINT2(int x, int y) |
556 |
{ |
557 |
this.x = x; |
558 |
this.y = y; |
559 |
} |
560 |
} |
561 |
|
562 |
[StructLayout(LayoutKind.Sequential)] |
563 |
public struct MINMAXINFO |
564 |
{ |
565 |
public POINT2 ptReserved; |
566 |
public POINT2 ptMaxSize; |
567 |
public POINT2 ptMaxPosition; |
568 |
public POINT2 ptMinTrackSize; |
569 |
public POINT2 ptMaxTrackSize; |
570 |
}; |
571 |
|
572 |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] |
573 |
public class MONITORINFO |
574 |
{ |
575 |
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO)); |
576 |
public RECT rcMonitor = new RECT(); |
577 |
public RECT rcWork = new RECT(); |
578 |
public int dwFlags = 0; |
579 |
} |
580 |
|
581 |
[StructLayout(LayoutKind.Sequential, Pack = 0)] |
582 |
public struct RECT |
583 |
{ |
584 |
public int left; |
585 |
public int top; |
586 |
public int right; |
587 |
public int bottom; |
588 |
|
589 |
public static readonly RECT Empty = new RECT(); |
590 |
|
591 |
public int Width |
592 |
{ |
593 |
get { return Math.Abs(right - left); } // Abs needed for BIDI OS |
594 |
} |
595 |
|
596 |
public int Height |
597 |
{ |
598 |
get { return bottom - top; } |
599 |
} |
600 |
|
601 |
public RECT(int left, int top, int right, int bottom) |
602 |
{ |
603 |
this.left = left; |
604 |
this.top = top; |
605 |
this.right = right; |
606 |
this.bottom = bottom; |
607 |
} |
608 |
|
609 |
public RECT(RECT rcSrc) |
610 |
{ |
611 |
this.left = rcSrc.left; |
612 |
this.top = rcSrc.top; |
613 |
this.right = rcSrc.right; |
614 |
this.bottom = rcSrc.bottom; |
615 |
} |
616 |
|
617 |
public bool IsEmpty |
618 |
{ |
619 |
get |
620 |
{ |
621 |
// BUGBUG : On Bidi OS (hebrew arabic) left > right |
622 |
return left >= right || top >= bottom; |
623 |
} |
624 |
} |
625 |
|
626 |
public override bool Equals(object obj) |
627 |
{ |
628 |
if (!(obj is Rect)) { return false; } |
629 |
return (this == (RECT)obj); |
630 |
} |
631 |
|
632 |
public override int GetHashCode() |
633 |
{ |
634 |
return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode(); |
635 |
} |
636 |
|
637 |
public static bool operator ==(RECT rect1, RECT rect2) |
638 |
{ |
639 |
return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom); |
640 |
} |
641 |
|
642 |
public static bool operator !=(RECT rect1, RECT rect2) |
643 |
{ |
644 |
return !(rect1 == rect2); |
645 |
} |
646 |
} |
647 |
|
648 |
[DllImport("user32")] |
649 |
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi); |
650 |
[DllImport("User32")] |
651 |
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags); |
652 |
} |
653 |
} |