SidebarLibrary.WinControls.OutlookBar.ProcessArrowScrolling C# (CSharp) Method

ProcessArrowScrolling() private method

private ProcessArrowScrolling ( Rectangle arrowButton, bool &arrowVisible, bool &arrowPressed, bool &timerTicking ) : void
arrowButton System.Drawing.Rectangle
arrowVisible bool
arrowPressed bool
timerTicking bool
return void
		void ProcessArrowScrolling(Rectangle arrowButton, ref bool arrowVisible, ref bool arrowPressed, ref bool timerTicking)
		{

			// Capture the mouse
			Capture = true;
			// Draw the arrow button pushed
			timerTicking = true;
			// Draw pushed button
			buttonPushed = true;
			DrawArrowButton(arrowButton, ButtonState.Pushed);

			// Start timer
			using (System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer())
			{
				timer.Tick += new EventHandler(ScrollingTick);
				timer.Interval = 300;
				timer.Start();

			doScrollingLoop = true;
				while (doScrollingLoop)
				{
					// Check messages until we find a condition to break out of the loop
					Win32.MSG msg = new Win32.MSG();
					WindowsAPI.GetMessage(ref msg, 0, 0, 0);
					Point point = new Point(0, 0);
					if (msg.message == (int)Msg.WM_MOUSEMOVE || msg.message == (int)Msg.WM_LBUTTONUP)
					{
						point = WindowsAPI.GetPointFromLPARAM((int)msg.lParam);
					}

					switch (msg.message)
					{
						case (int)Msg.WM_MOUSEMOVE:
							{
								if (arrowButton.Contains(point))
								{
									if (!buttonPushed)
									{
										DrawArrowButton(arrowButton, ButtonState.Pushed);
										arrowVisible = true;
										arrowPressed = true;
										buttonPushed = true;
									}
								}
								else
								{
									if (buttonPushed)
									{
										DrawArrowButton(arrowButton, ButtonState.Normal);
										arrowVisible = false;
										arrowPressed = false;
										buttonPushed = false;
									}
								}
								break;
							}
						case (int)Msg.WM_LBUTTONUP:
							{
								if (buttonPushed)
								{
									if (!flatArrowButtons)
									{
										// Only if using regular buttons
										DrawArrowButton(arrowButton, ButtonState.Normal);
									}
									buttonPushed = false;
								}
								arrowVisible = false;
								if (arrowButton.Contains(point))
								{
									if (arrowButton.Equals(upArrowRect))
									{
										if (firstItem > 0)
										{
											firstItem--;
											Rectangle rc = GetViewPortRect();
											Invalidate(rc);
										}
									}
									else if (arrowButton.Equals(downArrowRect))
									{
										using (Graphics g = Graphics.FromHwnd(Handle))
										{
											// Get the last item rectangle
											OutlookBarBand band = bands[currentBandIndex];
											if (band != null)
											{
												Rectangle rcItem = GetItemRect(g, band, band.Items.Count - 1, Rectangle.Empty);
												Rectangle rc = GetViewPortRect();
												if (rcItem.Bottom > rc.Bottom)
												{
													firstItem++;
													Invalidate(rc);
												}
											}
										}
									}
								}
								doScrollingLoop = false;
								break;
							}
						case (int)Msg.WM_KEYDOWN:
							{
								if ((int)msg.wParam == (int)VirtualKeys.VK_ESCAPE)
									doScrollingLoop = false;
								break;
							}
						default:
							WindowsAPI.DispatchMessage(ref msg);
							break;
					}
				}

				// Release the capture
				Capture = false;
				// Stop timer
				timer.Stop();
			}
			// Reset flags
			arrowVisible = false;
			arrowPressed = false;
			timerTicking = false;
			Rectangle viewPortRect = GetViewPortRect();
			Invalidate(viewPortRect);

		}