Changeset 821 for Scheduling/trunk/cs/bsdx0200GUISourceCode/CalendarGrid.cs
- Timestamp:
- Jul 4, 2010, 1:25:13 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Scheduling/trunk/cs/bsdx0200GUISourceCode/CalendarGrid.cs
r622 r821 10 10 using System.Windows.Forms; 11 11 /// <summary> 12 /// This class was regenerated from Calendargrid.dll using Reflector.exe 13 /// by Sam Habiel for WorldVista. The original source code is lost. 12 /// This class is reponsible for rendering the Calendar Grid. 14 13 /// </summary> 15 14 public class CalendarGrid : Panel 16 15 { 17 private Container components;16 private IContainer components; 18 17 private Font fontArial10; 19 18 private Font fontArial8; … … 49 48 private StringFormat m_sfRight; 50 49 private ArrayList m_sResourcesArray; 51 private Timer m_Timer; 50 private Timer m_Timer; // Timeer used in Drag and Drop Operations 52 51 private ToolTip m_toolTip; 53 private const int WM_HSCROLL = 0x114; 54 private const int WM_VSCROLL = 0x115; 52 private const int WM_HSCROLL = 0x114; // Horizontal Scrolling Windows Message 53 private const int WM_VSCROLL = 0x115; // Vertical Scrolling Windows Message 55 54 56 55 public event CGAppointmentChangedHandler CGAppointmentAdded; … … 70 69 this.m_selectedRange = new CGRange(); 71 70 this.m_SelectedAppointments = new CGAppointments(); 72 this.m_dtStart = new DateTime( 0x7d3, 1, 0x1b);71 this.m_dtStart = new DateTime(2003, 1, 27); 73 72 this.m_ApptOverlapTable = new Hashtable(); 74 73 this.m_ColumnInfoTable = new Hashtable(); … … 123 122 int nColumns = this.m_nColumns; 124 123 int num2 = 60 / this.m_nTimeScale; 125 int num3 = 0x18* num2;124 int num3 = 24 * num2; 126 125 nColumns++; 127 126 num3++; … … 287 286 } 288 287 this.m_toolTip.RemoveAll(); 288 289 ////smh new code -- select cell 290 //int nRow = -1; 291 //int nCol = -1; 292 293 ////Is the mouse over a known cell? If so, highlight cell 294 //if (this.HitTest(x, y, ref nRow, ref nCol)) 295 //{ 296 // CGCell cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol); 297 // if (cellFromRowCol != null) 298 // { 299 // this.m_currentCell = cellFromRowCol; 300 // this.m_selectedRange.StartCell = null; 301 // this.m_selectedRange.EndCell = null; 302 // this.m_selectedRange.CreateRange(this.m_gridCells, cellFromRowCol, cellFromRowCol); 303 // this.m_bSelectingRange = true; 304 // cellFromRowCol.IsSelected = true; 305 // base.Invalidate(this.m_currentCell.CellRectangle); 306 // //base.Invalidate(); 307 // } 308 //} 309 310 289 311 } 290 312 } … … 418 440 private void DrawGrid(Graphics g) 419 441 { 420 try 421 { 422 Pen pen = new Pen(Color.Black); 423 SizeF ef = g.MeasureString("Test", this.m_fCell); 424 int num = 10; 425 this.m_cellHeight = ((int) ef.Height) + num; 426 int nColumns = this.m_nColumns; 427 int num3 = 60 / this.m_nTimeScale; 428 int num4 = 0x18 * num3; 429 nColumns++; 430 num4++; 431 this.m_cellWidth = 600 / nColumns; 432 if (base.ClientRectangle.Width > 600) 433 { 434 this.m_cellWidth = (base.ClientRectangle.Width - this.m_col0Width) / (nColumns - 1); 435 } 436 if (this.m_nColumns == 1) 437 { 438 this.m_cellWidth = base.ClientRectangle.Width - this.m_col0Width; 439 } 440 base.AutoScrollMinSize = new Size(600, this.m_cellHeight * num4); 441 g.FillRectangle(Brushes.LightGray, base.ClientRectangle); 442 int num5 = 0; 443 int num6 = 0; 444 bool flag = this.m_gridCells.CellCount == 0; 445 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y); 446 for (int i = 1; i < num4; i++) 447 { 448 int x = 0; 449 Point point = new Point(x, i * this.m_cellHeight); 450 Rectangle rectangle2 = new Rectangle(point.X, point.Y, this.m_cellWidth, this.m_cellHeight); 451 Rectangle rect = new Rectangle(0, rectangle2.Y, this.m_col0Width, rectangle2.Height * num3); 452 int height = rect.Height; 453 height = (height > (this.m_col0Width / 4)) ? (this.m_col0Width / 4) : height; 454 if (num5 == 0) 455 { 456 g.FillRectangle(Brushes.LightGray, rect); 457 g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); 458 string str = string.Format("{0}", num6).PadLeft(2, '0'); 459 Font font = new Font("Arial", (float) height, FontStyle.Bold, GraphicsUnit.Pixel); 460 Rectangle rectangle3 = new Rectangle(rect.X, rect.Y, rect.Width / 2, rect.Height); 461 g.DrawString(str, font, Brushes.Black, rectangle3, this.m_sfHour); 462 num6++; 463 font.Dispose(); 464 } 465 string s = string.Format("{0}", num5); 466 s = ":" + s.PadLeft(2, '0'); 467 Rectangle layoutRectangle = new Rectangle(rect.X + ((rect.Width * 2) / 3), rectangle2.Top, rect.Width / 3, rectangle2.Height); 468 g.DrawString(s, this.m_fCell, Brushes.Black, layoutRectangle, this.m_sfRight); 469 Point point2 = new Point(rect.X + ((rect.Width * 2) / 3), rectangle2.Bottom); 470 Point point3 = new Point(rect.Right, rectangle2.Bottom); 471 g.DrawLine(pen, point2, point3); 472 num5 += this.m_nTimeScale; 473 num5 = (num5 >= 60) ? 0 : num5; 474 if ((i == (num4 - 1)) && !this.m_bScroll) 475 { 476 g.TranslateTransform((float) -base.AutoScrollPosition.X, (float) -base.AutoScrollPosition.Y); 477 rect = new Rectangle(0, 0, this.m_col0Width, this.m_cellHeight); 478 g.FillRectangle(Brushes.LightGray, rect); 479 g.DrawRectangle(pen, rect); 480 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y); 481 } 482 } 483 for (int j = num4; j > -1; j--) 484 { 485 for (int k = 1; k < nColumns; k++) 486 { 487 int num12 = 0; 488 if (k == 1) 489 { 490 num12 = this.m_col0Width; 491 } 492 if (k > 1) 493 { 494 num12 = this.m_col0Width + (this.m_cellWidth * (k - 1)); 495 } 496 Point point4 = new Point(num12, j * this.m_cellHeight); 497 Rectangle r = new Rectangle(point4.X, point4.Y, this.m_cellWidth, this.m_cellHeight); 498 if (j != 0) 499 { 500 CGCell cellFromRowCol = null; 501 if (flag) 442 //Default color of grid lines is black 443 Pen pen = new Pen(Color.Black); 444 445 //each cell's height is Height of Arial Font 10pt + 10 pixels (by default 26 pixels) 446 SizeF ef = g.MeasureString("Test", this.m_fCell); 447 int num = 10; 448 this.m_cellHeight = ((int) ef.Height) + num; 449 450 // Number of columns is dynamic based on user of Grid. See Property Columns. Default 5 in init. 451 int nColumns = this.m_nColumns; 452 453 //Time scale is also dynamic. Property TimeScale. Default 20 (minutes) 454 //num3 stands for number of cells per hour 455 int num3 = 60 / this.m_nTimeScale; 456 //num4 stands for number of cells per day (aka rows in the grid) 457 int num4 = 24 * num3; 458 //Add extra column to hold time in the left hand corner 459 nColumns++; 460 //add extra row to represent dates or resources (depending on which view we are in) 461 //Not sure of which variable controls view yet. 462 num4++; 463 464 // 100 px is reserved no matter our column sizes for displaying the time scale 465 466 // Minimum cell width is 600/columns (100 px by default) 467 this.m_cellWidth = 600 / nColumns; 468 469 // if we happen to have more than 600 pixels in our Client Window then cell 470 // is (Width-100) / (number of date columns) 471 if (base.ClientRectangle.Width > 600) 472 { 473 this.m_cellWidth = (base.ClientRectangle.Width - this.m_col0Width) / (nColumns - 1); 474 } 475 476 // If we have one column, the cell width is the itself - 100 477 if (this.m_nColumns == 1) 478 { 479 this.m_cellWidth = base.ClientRectangle.Width - this.m_col0Width; 480 } 481 482 // Our rectangle will start scrolling if width is less than 600 and height less than height of all cells comb 483 // Of course Height will scroll all the time unless you have a humungous screen 484 base.AutoScrollMinSize = new Size(600, this.m_cellHeight * num4); 485 486 // Default Rectangle is Gray 487 g.FillRectangle(Brushes.LightGray, base.ClientRectangle); 488 489 int num5 = 0; //Minutes (start at 0) 490 int num6 = 0; //Hour (starts at 0) 491 492 // flag is true only if there are no cells what so ever in the screen 493 // Only true when no resource is selected. 494 bool flag = this.m_gridCells.CellCount == 0; 495 496 // Move the base point from the client screen to the scrolling region top-left corner. 497 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y); 498 499 // For each row except the first one (i starts from 1 rather than zero) 500 for (int i = 1; i < num4; i++) 501 { 502 int x = 0; 503 //point is (0, 1st Cell Start) then (0, 2nd Cell Start) until we run out 504 Point point = new Point(x, i * this.m_cellHeight); 505 //rectangle2 represents each cell rectangle 506 Rectangle rectangle2 = new Rectangle(point.X, point.Y, this.m_cellWidth, this.m_cellHeight); 507 //rect stands for the time scale rectangle; width is 100px; Height is length of the hour on grid 508 Rectangle rect = new Rectangle(0, rectangle2.Y, this.m_col0Width, rectangle2.Height * num3); 509 //height is length of hour 510 int height = rect.Height; 511 //Min font height is 25 pixels (100/4)--see below where it's used 512 height = (height > (this.m_col0Width / 4)) ? (this.m_col0Width / 4) : height; 513 514 //if we are the top of the time scale (at hour:00) -- num5 is min 515 if (num5 == 0) 516 { 517 // Fill time scale triangle with Gray (remember, this is the whole hour!) 518 g.FillRectangle(Brushes.LightGray, rect); 519 // Draw Rectangle 520 g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); 521 //Pad time with at least one zero to make it 2 digits 522 string str = string.Format("{0}", num6).PadLeft(2, '0'); 523 //Font height using pixels. Min is 25 pixels 524 Font font = new Font("Arial", (float) height, FontStyle.Bold, GraphicsUnit.Pixel); 525 // rectangle3 is the left half of the time rectangle 526 Rectangle rectangle3 = new Rectangle(rect.X, rect.Y, rect.Width / 2, rect.Height); 527 // In this left half, draw the hours (m_sfHour is the stringformat: 528 // Horizontal Center and Right Justified to rectangle3 529 g.DrawString(str, font, Brushes.Black, rectangle3, this.m_sfHour); 530 // Increment hour 531 num6++; 532 font.Dispose(); 533 } 534 535 // Pad minutes with zeros to be 2 digits long 536 string s = string.Format("{0}", num5); 537 s = ":" + s.PadLeft(2, '0'); 538 // Rectangle starts at 539 // X: 2/3rds of width of Time Rectangle 540 // Y: Top of the current time slot cell 541 // Width: 1/3rd of the width of the Time Rectangle 542 // Height: Height of a time slot 543 Rectangle layoutRectangle = new Rectangle(rect.X + ((rect.Width * 2) / 3), rectangle2.Top, rect.Width / 3, rectangle2.Height); 544 // At in this rectangle, write the minutes. Horizontal Ctr and Right Justified to Rectangle 545 g.DrawString(s, this.m_fCell, Brushes.Black, layoutRectangle, this.m_sfRight); 546 Point point2 = new Point(rect.X + ((rect.Width * 2) / 3), rectangle2.Bottom); 547 Point point3 = new Point(rect.Right, rectangle2.Bottom); 548 g.DrawLine(pen, point2, point3); 549 num5 += this.m_nTimeScale; 550 num5 = (num5 >= 60) ? 0 : num5; 551 if ((i == (num4 - 1)) && !this.m_bScroll) 552 { 553 g.TranslateTransform((float) -base.AutoScrollPosition.X, (float) -base.AutoScrollPosition.Y); 554 rect = new Rectangle(0, 0, this.m_col0Width, this.m_cellHeight); 555 g.FillRectangle(Brushes.LightGray, rect); 556 g.DrawRectangle(pen, rect); 557 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y); 558 } 559 } 560 for (int j = num4; j > -1; j--) 561 { 562 for (int k = 1; k < nColumns; k++) 563 { 564 int num12 = 0; 565 if (k == 1) 566 { 567 num12 = this.m_col0Width; 568 } 569 if (k > 1) 570 { 571 num12 = this.m_col0Width + (this.m_cellWidth * (k - 1)); 572 } 573 Point point4 = new Point(num12, j * this.m_cellHeight); 574 Rectangle r = new Rectangle(point4.X, point4.Y, this.m_cellWidth, this.m_cellHeight); 575 if (j != 0) 576 { 577 CGCell cellFromRowCol = null; 578 if (flag) 579 { 580 cellFromRowCol = new CGCell(r, j, k); 581 this.m_gridCells.AddCell(cellFromRowCol); 582 } 583 else 584 { 585 cellFromRowCol = this.m_gridCells.GetCellFromRowCol(j, k); 586 cellFromRowCol.CellRectangle = r; 587 } 588 if (this.m_sResourcesArray.Count > 0) 589 { 590 if (this.m_selectedRange.CellIsInRange(cellFromRowCol)) 502 591 { 503 cellFromRowCol = new CGCell(r, j, k); 504 this.m_gridCells.AddCell(cellFromRowCol); 592 g.FillRectangle(Brushes.Aquamarine, r); 505 593 } 506 594 else 507 595 { 508 cellFromRowCol = this.m_gridCells.GetCellFromRowCol(j, k); 509 cellFromRowCol.CellRectangle = r; 596 g.FillRectangle(cellFromRowCol.AppointmentTypeColor, r); 510 597 } 511 if (this.m_sResourcesArray.Count > 0) 598 g.DrawRectangle(pen, r.X, r.Y, r.Width, r.Height); 599 if (j == 1) 512 600 { 513 if (this.m_selectedRange.CellIsInRange(cellFromRowCol)) 601 this.DrawAppointments(g, this.m_col0Width, this.m_cellWidth, this.m_cellHeight); 602 } 603 } 604 continue; 605 } 606 if (!this.m_bScroll) 607 { 608 g.TranslateTransform(0f, (float) -base.AutoScrollPosition.Y); 609 Rectangle rectangle6 = r; 610 g.FillRectangle(Brushes.LightBlue, rectangle6); 611 g.DrawRectangle(pen, rectangle6.X, rectangle6.Y, rectangle6.Width, rectangle6.Height); 612 string str3 = ""; 613 if (this.m_sResourcesArray.Count > 1) 614 { 615 foreach (DictionaryEntry entry in this.m_ColumnInfoTable) 616 { 617 int num13 = (int) entry.Value; 618 num13++; 619 if (num13 == k) 514 620 { 515 g.FillRectangle(Brushes.Aquamarine, r); 516 } 517 else 518 { 519 g.FillRectangle(cellFromRowCol.AppointmentTypeColor, r); 520 } 521 g.DrawRectangle(pen, r.X, r.Y, r.Width, r.Height); 522 if (j == 1) 523 { 524 this.DrawAppointments(g, this.m_col0Width, this.m_cellWidth, this.m_cellHeight); 621 str3 = entry.Key.ToString(); 622 break; 525 623 } 526 624 } 527 continue; 528 } 529 if (!this.m_bScroll) 530 { 531 g.TranslateTransform(0f, (float) -base.AutoScrollPosition.Y); 532 Rectangle rectangle6 = r; 533 g.FillRectangle(Brushes.LightBlue, rectangle6); 534 g.DrawRectangle(pen, rectangle6.X, rectangle6.Y, rectangle6.Width, rectangle6.Height); 535 string str3 = ""; 536 if (this.m_sResourcesArray.Count > 1) 625 } 626 else 627 { 628 DateTime dtStart = this.m_dtStart; 629 if (k > 1) 537 630 { 538 foreach (DictionaryEntry entry in this.m_ColumnInfoTable) 539 { 540 int num13 = (int) entry.Value; 541 num13++; 542 if (num13 == k) 543 { 544 str3 = entry.Key.ToString(); 545 break; 546 } 547 } 631 dtStart = dtStart.AddDays((double) (k - 1)); 548 632 } 549 else 550 { 551 DateTime dtStart = this.m_dtStart; 552 if (k > 1) 553 { 554 dtStart = dtStart.AddDays((double) (k - 1)); 555 } 556 string format = "ddd, MMM d"; 557 str3 = dtStart.ToString(format, DateTimeFormatInfo.InvariantInfo); 558 } 559 g.DrawString(str3, this.m_fCell, Brushes.Black, rectangle6, this.m_sf); 560 g.TranslateTransform(0f, (float) base.AutoScrollPosition.Y); 561 } 562 } 563 } 564 this.m_bScroll = false; 565 pen.Dispose(); 566 } 567 catch (Exception) 568 { 569 } 633 string format = "ddd, MMM d"; 634 str3 = dtStart.ToString(format, DateTimeFormatInfo.InvariantInfo); 635 } 636 g.DrawString(str3, this.m_fCell, Brushes.Black, rectangle6, this.m_sf); 637 g.TranslateTransform(0f, (float) base.AutoScrollPosition.Y); 638 } 639 } 640 } 641 this.m_bScroll = false; 642 pen.Dispose(); 570 643 } 571 644 … … 776 849 private void InitializeComponent() 777 850 { 851 this.components = new System.ComponentModel.Container(); 852 this.m_toolTip = new System.Windows.Forms.ToolTip(this.components); 853 this.SuspendLayout(); 854 // 855 // CalendarGrid 856 // 778 857 this.AutoScroll = true; 779 base.AutoScrollMinSize = new Size(600, 400); 780 this.BackColor = SystemColors.Window; 781 base.Paint += new PaintEventHandler(this.CalendarGrid_Paint); 782 base.MouseDown += new MouseEventHandler(this.CalendarGrid_MouseDown); 783 base.MouseUp += new MouseEventHandler(this.CalendarGrid_MouseUp); 784 base.MouseMove += new MouseEventHandler(this.CalendarGrid_MouseMove); 785 base.DragEnter += new DragEventHandler(this.CalendarGrid_DragEnter); 786 base.DragDrop += new DragEventHandler(this.CalendarGrid_DragDrop); 787 this.m_toolTip = new ToolTip(); 858 this.AutoScrollMinSize = new System.Drawing.Size(600, 400); 859 this.BackColor = System.Drawing.SystemColors.Window; 860 this.Paint += new System.Windows.Forms.PaintEventHandler(this.CalendarGrid_Paint); 861 this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseMove); 862 this.DragDrop += new System.Windows.Forms.DragEventHandler(this.CalendarGrid_DragDrop); 863 this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseDown); 864 this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseUp); 865 this.DragEnter += new System.Windows.Forms.DragEventHandler(this.CalendarGrid_DragEnter); 866 this.ResumeLayout(false); 867 788 868 } 789 869 790 870 private int MinSince80(DateTime d) 791 871 { 792 DateTime time = new DateTime( 0x7bc, 1, 1, 0, 0, 0);872 DateTime time = new DateTime(1980, 1, 1, 0, 0, 0); 793 873 TimeSpan span = (TimeSpan) (d - time); 794 874 return (int) span.TotalMinutes; … … 995 1075 this.m_ApptOverlapTable.Add(num4, 0); 996 1076 } 1077 // Here it draws the Dates on Top 997 1078 if (this.m_ApptOverlapTable.Count != 0) 998 1079 { … … 1062 1143 } 1063 1144 1145 /// <summary> 1146 /// The purpose of this is to properly draw the date boxes at the top of the calendar grid. 1147 /// Otherwise, when scrolling, it gets garbled. 1148 /// </summary> 1149 /// <param name="msg">Handles two messages: 1150 /// WM_VSCROLL (0x115 - Vertical Scrolling) 1151 /// WM_HSCROLL (0x114 - Horizontal Scrolling) 1152 /// </param> 1064 1153 protected override void WndProc(ref Message msg) 1065 1154 { 1066 1155 try 1067 1156 { 1068 if (msg.Msg == 0x115)1157 if (msg.Msg == WM_VSCROLL) 1069 1158 { 1070 1159 this.m_bScroll = true; … … 1072 1161 this.m_bScroll = false; 1073 1162 } 1074 if (msg.Msg == 0x114)1163 if (msg.Msg == WM_HSCROLL) 1075 1164 { 1076 1165 base.Invalidate(false); … … 1273 1362 } 1274 1363 } 1364 1275 1365 } 1276 1366 }
Note:
See TracChangeset
for help on using the changeset viewer.