Example #1
0
		internal void FocusMoved(int i)
		{
			bool dayEnabled = true;

			if ((!m_mouseDown) && (!m_calendar.SelectKeyDown))
			{

				dayEnabled = IsDateEnabled(m_days[i].Date);

				if (((m_calendar.SelectTrailingDates) || (SelectedMonth.Month == m_days[i].Date.Month)) && (dayEnabled))
				{
					if (m_days[i].State != NuGenDayState.Selected)
						m_days[i].State = NuGenDayState.Focus;
					if ((m_dayInFocus != -1) && (m_days[m_dayInFocus].State != NuGenDayState.Selected))
						m_days[m_dayInFocus].State = NuGenDayState.Normal;

					// raise events
					if ((DayLostFocus != null) && (m_dayInFocus != -1))
						DayLostFocus(this, new NuGenDayEventArgs(m_days[m_dayInFocus].Date.ToShortDateString()));
					if (DayGotFocus != null)
						DayGotFocus(this, new NuGenDayEventArgs(m_days[i].Date.ToShortDateString()));
				}
				else
				{
					if ((m_dayInFocus != -1) && (m_days[m_dayInFocus].State != NuGenDayState.Selected))
						m_days[m_dayInFocus].State = NuGenDayState.Normal;
				}

				if (m_calendar.ShowFocus)
					m_calendar.Invalidate(m_rect);
				m_dayInFocus = i;
			}
			else if (m_calendar.SelectionMode >= NuGenSelectionMode.MultiSimple)
			{
				NuGenDayStateChangedEventArgs args;
				if (m_days[i].State == NuGenDayState.Normal)
				{
					args = new NuGenDayStateChangedEventArgs(m_days[i].Date.ToShortDateString(), NuGenDayState.Normal, NuGenDayState.Selected);
					if (BeforeDaySelected != null)
						BeforeDaySelected(this, args);
				}
				else
				{
					if (m_dayInFocus == -1)
						m_dayInFocus = i;
					args = new NuGenDayStateChangedEventArgs(m_days[m_dayInFocus].Date.ToShortDateString(), NuGenDayState.Selected, NuGenDayState.Normal);
					if (BeforeDayDeselected != null)
						BeforeDayDeselected(this, args);
				}

				m_dayInFocus = i;

				if (((m_calendar.SelectTrailingDates) || (SelectedMonth.Month == m_days[i].Date.Month)) &&
					((m_calendar.MinDate <= m_days[i].Date) && (m_calendar.MaxDate >= m_days[i].Date)) && (dayEnabled) && (!args.Cancel))
				{

					if (m_newSelection)
					{
						NewSelectedDay(i);
						m_newSelection = false;
					}
					else
					{
						NuGenCalendarSelectionArea area = (NuGenCalendarSelectionArea)m_selArea[m_selArea.Count - 1];
						area.End = i;
					}

					m_selected = true;
					RemoveSelection(false);
					// loop through number of selections
					for (int y = 0; y < m_selArea.Count; y++)
					{
						NuGenCalendarSelectionArea area = (NuGenCalendarSelectionArea)m_selArea[y];
						if ((area.Begin != -1) && (area.End != -1))
							MarkAreaAsSelected(area.Begin, area.End, y);
					}
					// Force repaint of calendar
					m_calendar.Invalidate(m_rect);

				}
			}
			else
			{
				// init dagdrop
				//m_calendar.DoDragDrop(m_days[i].Date.ToString(),DragDropEffects.Copy);   
			}
		}
Example #2
0
		internal void DaySelect(int i, MouseButtons button, Point mouseLocation)
		{
			bool dayEnabled = true;

			if (m_calendar.SelectionMode > NuGenSelectionMode.None)
			{
				m_dayInFocus = i;
				// Check if proper button is used
				if (button == m_calendar.SelectButton)
				{

					if (!m_days[i].ImageHitTest(mouseLocation))
					{

						dayEnabled = IsDateEnabled(m_days[i].Date);

						if (((m_calendar.SelectTrailingDates) || (SelectedMonth.Month == m_days[i].Date.Month)) &&
							((m_calendar.MinDate <= m_days[i].Date) && (m_calendar.MaxDate >= m_days[i].Date)) && (dayEnabled))
						{

							// If day is already selected and number of days in selection = 1
							// or selectionMode = MultiExtended, toggle to focus
							if (m_days[i].State == NuGenDayState.Selected)
							{
								NuGenDayStateChangedEventArgs args = new NuGenDayStateChangedEventArgs(m_days[i].Date.ToShortDateString(), NuGenDayState.Selected, NuGenDayState.Normal);
								if (BeforeDayDeselected != null)
									BeforeDayDeselected(this, args);
								if (!args.Cancel)
								{
									Remove(i);
								}

							}
							else
							{
								NuGenDayStateChangedEventArgs args = new NuGenDayStateChangedEventArgs(m_days[i].Date.ToShortDateString(), NuGenDayState.Normal, NuGenDayState.Selected);
								if (BeforeDaySelected != null)
									BeforeDaySelected(this, args);

								if (!args.Cancel)
								{
									NewSelectedDay(i);
								}
							}

							m_mouseDown = true;
							m_calendar.Invalidate();
						}
					}
					else
					{
						if (this.ImageClick != null)
							this.ImageClick(this, new NuGenDayClickEventArgs(m_days[i].Date.ToShortDateString(), button,
											mouseLocation.X - m_days[i].Rectangle.Left, mouseLocation.Y - m_days[i].Rectangle.Top,
											mouseLocation.X, mouseLocation.Y, m_days[i].Rectangle));

					}

				}
				//either way ceate DayClick event
				if (this.DayClick != null)
					this.DayClick(this, new NuGenDayClickEventArgs(m_days[i].Date.ToShortDateString(), button,
								  mouseLocation.X - m_days[i].Rectangle.Left, mouseLocation.Y - m_days[i].Rectangle.Top,
								  mouseLocation.X, mouseLocation.Y, m_days[i].Rectangle));
			}

		}