Пример #1
0
		private void ToolBar_MouseLeave (object sender, EventArgs e)
		{
			if (tipdown_timer != null)
				tipdown_timer.Dispose ();
			tipdown_timer = null;
			if (tip_window != null)
				tip_window.Dispose ();
			tip_window = null;

			if (!Enabled || current_item == null) 
				return;

			current_item.Hilight = false;
			current_item = null;
		}
Пример #2
0
		void DoDrawToolBarButton (Graphics dc, ToolBarItem item, bool is_flat)
		{
			Color use_color = NormalColor;
			Color first_color = Color.White;
			
			if (is_flat) {
				if (item.Button.Pushed || item.Pressed) {
					first_color = PressedColor;
					use_color = MouseOverColor;
				} else
				if (item.Hilight)
					use_color = MouseOverColor;
				else
					return;
			} else {
				if (item.Button.Pushed || item.Pressed) {
					first_color = PressedColor;
					use_color = MouseOverColor;
				} else
				if (item.Hilight)
					use_color = MouseOverColor;
			}
			
			Rectangle buttonRectangle = item.Rectangle;
			
			Rectangle lgbRectangle = Rectangle.Inflate (buttonRectangle, -1, -1);
			
			using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y), new Point (buttonRectangle.X, buttonRectangle.Bottom - 1), first_color, use_color)) {
				lgbr.Blend = NormalBlend;
				dc.FillRectangle (lgbr, lgbRectangle);
			}
			
			Internal_DrawButton (dc, buttonRectangle, BorderColor);
		}
Пример #3
0
		internal void ShowDropDownMenu (ToolBarItem item)
		{
			Point loc = new Point (item.Rectangle.X + 1, item.Rectangle.Bottom + 1);
			((ContextMenu) item.Button.DropDownMenu).Show (this, loc);

			item.DDPressed = false;
			item.Hilight = false;
			item.Invalidate ();
		}
Пример #4
0
		private void ToolBar_MouseUp (object sender, MouseEventArgs me)
		{
			if ((!Enabled) || ((me.Button & MouseButtons.Left) == 0))
				return;

			Point loc = new Point (me.X, me.Y);

			// draw the normal button
			// Make a copy in case the list is modified during enumeration
			ArrayList items = new ArrayList (this.items);
			foreach (ToolBarItem item in items) {
				if (item.Button.Enabled && item.Rectangle.Contains (loc)) {
					if (item.Button.Style == ToolBarButtonStyle.DropDownButton) {
						Rectangle ddRect = item.Rectangle;
						ddRect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
						ddRect.X = item.Rectangle.Right - ddRect.Width;
						if (ddRect.Contains (loc)) {
							current_item = item;
							if (item.DDPressed)
								OnButtonDropDown (new ToolBarButtonClickEventArgs (item.Button));
							continue;
						}
					}
					// Fire a ButtonClick
					current_item = item;
					if ((item.Pressed) && ((me.Button & MouseButtons.Left) == MouseButtons.Left))
						PerformButtonClick (new ToolBarButtonClickEventArgs (item.Button));
				} else if (item.Pressed) {
					item.Pressed = false;
					item.Invalidate ();
				}
			}
		}
Пример #5
0
		protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
		{
			Rectangle rect = item.Rectangle;
			rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
			rect.Width = ToolBarDropDownWidth;
			
			if (is_flat) {
				if (item.DDPressed)
					CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
				else if (item.Button.Pushed || item.Pressed)
					CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
				else if (item.Hilight)
					CPDrawBorder3D (dc, rect, Border3DStyle.RaisedInner, all_sides);
			} else {
				if (item.DDPressed)
					CPDrawBorder3D (dc, rect, Border3DStyle.Flat, all_sides);
				else if (item.Button.Pushed || item.Pressed)
					CPDrawBorder3D (dc, Rectangle.Inflate(rect, -1, -1), Border3DStyle.SunkenOuter, all_sides);
				else
					CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
			}
			
			PointF [] vertices = new PointF [3];
			PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height / 2));
			
			// Increase vertical and horizontal position by 1 when button is pressed
			if (item.Pressed || item.Button.Pushed || item.DDPressed) {
			    ddCenter.X += 1;
			    ddCenter.Y += 1;
			}
			
			vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
			vertices [0].Y = ddCenter.Y;
			vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
			vertices [1].Y = ddCenter.Y;
			vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
			vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
			dc.FillPolygon (SystemBrushes.ControlText, vertices);
		}
Пример #6
0
		private bool LayoutToolBar ()
		{
			bool changed = false;
			Theme theme = ThemeEngine.Current;
			int x = theme.ToolBarGripWidth;
			int y = theme.ToolBarGripWidth;

			Size adjusted_size = AdjustedButtonSize;
			
			int calculated_size = (Vertical ? adjusted_size.Width : adjusted_size.Height) + theme.ToolBarGripWidth;
			
			int separator_index = -1;

			items = new ToolBarItem [buttons.Count];
			
			for (int i = 0; i < buttons.Count; i++) {
				ToolBarButton button = buttons [i];
				
				ToolBarItem item = new ToolBarItem (button);
				items [i] = item;

				if (!button.Visible)
					continue;

				if (size_specified && (button.Style != ToolBarButtonStyle.Separator))
					changed = item.Layout (adjusted_size);
				else
					changed = item.Layout (Vertical, calculated_size);
				
				bool is_separator = button.Style == ToolBarButtonStyle.Separator;
				
				if (Vertical) {
					if (y + item.Rectangle.Height < Height || is_separator || !Wrappable) {
						if (item.Location.X != x || item.Location.Y != y)
							changed = true;
						item.Location = new Point (x, y);
						y += item.Rectangle.Height;
						if (is_separator)
							separator_index = i;
					} else if (separator_index > 0) {
						i = separator_index;
						separator_index = -1;
						y = theme.ToolBarGripWidth;
						x += calculated_size; 
					} else {
						y = theme.ToolBarGripWidth;
						x += calculated_size; 
						if (item.Location.X != x || item.Location.Y != y)
							changed = true;
						item.Location = new Point (x, y);
						y += item.Rectangle.Height;
					}
				} else {
					if (x + item.Rectangle.Width < Width || is_separator || !Wrappable) {
						if (item.Location.X != x || item.Location.Y != y)
							changed = true;
						item.Location = new Point (x, y);
						x += item.Rectangle.Width;
						if (is_separator)
							separator_index = i;
					} else if (separator_index > 0) {
						i = separator_index;
						separator_index = -1;
						x = theme.ToolBarGripWidth;
						y += calculated_size; 
					} else {
						x = theme.ToolBarGripWidth;
						y += calculated_size; 
						if (item.Location.X != x || item.Location.Y != y)
							changed = true;
						item.Location = new Point (x, y);
						x += item.Rectangle.Width;
					}
				}
			}
			
			if (Parent == null)
				return changed;
			
			if (Wrappable)
				calculated_size += Vertical ? x : y;
			
			if (IsHandleCreated) {
				if (Vertical)
					Width = calculated_size;
				else
					Height = calculated_size; 
			}
			
			return changed;
		}
		static bool ToolBarIsChecked (ToolBarItem item)
		{
			return item.Button.Pushed;
		}
Пример #8
0
		protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
		{
			Rectangle area = item.Rectangle;
			int offset = (int) SystemPens.Control.Width + 1;
			dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
			dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
		}
		static bool ToolBarIsDisabled (ToolBarItem item)
		{
			return !item.Button.Enabled;
		}
		static bool ToolBarIsPressed (ToolBarItem item)
		{
			return item.Pressed;
		}
Пример #11
0
		protected override void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
		{
			if (item.Button.Image != null) {
				int x = item.ImageRectangle.X + ToolBarImageGripWidth;
				int y = item.ImageRectangle.Y + ToolBarImageGripWidth;
				if (item.Button.Enabled)
					dc.DrawImage (item.Button.Image, x, y);
				else 
					CPDrawImageDisabled (dc, item.Button.Image, x, y, ColorControl);
			}
			
			if (item.Button.Enabled)
				dc.DrawString (item.Button.Text, control.Font, ResPool.GetSolidBrush (ColorControlText), item.TextRectangle, format);
			else
				CPDrawStringDisabled (dc, item.Button.Text, control.Font, ColorControlLight, item.TextRectangle, format);
		}
Пример #12
0
		protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
		{
			Rectangle rect = item.Rectangle;
			rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
			rect.Width = ToolBarDropDownWidth;
			
			if (item.DDPressed) {
				CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
				CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
			} else if (item.Button.Pushed || item.Pressed)
				CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
			else if (is_flat) {
				if (item.Hilight)
					CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
			} else
				CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
			
			PointF [] vertices = new PointF [3];
			PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
			vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
			vertices [0].Y = ddCenter.Y;
			vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
			vertices [1].Y = ddCenter.Y;
			vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
			vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
			dc.FillPolygon (SystemBrushes.ControlText, vertices);
		}
Пример #13
0
		protected override void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
		{
			Rectangle area = item.Rectangle;
			int offset = (int) ResPool.GetPen (ColorControl).Width + 1;
			dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X + 1, area.Y, area.X + 1, area.Bottom);
			dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + offset, area.Y, area.X + offset, area.Bottom);
		}
Пример #14
0
		protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
		{
			bool is_flat = (control.Appearance == ToolBarAppearance.Flat);
			
			DrawToolBarButtonBorder (dc, item, is_flat);

			switch (item.Button.Style) {
			case ToolBarButtonStyle.DropDownButton:
				if (control.DropDownArrows)
					DrawToolBarDropDownArrow (dc, item, is_flat);
				DrawToolBarButtonContents (dc, control, item, format);
				break;

			case ToolBarButtonStyle.Separator:
				if (is_flat)
					DrawToolBarSeparator (dc, item);
				break;

			case ToolBarButtonStyle.ToggleButton:
				DrawToolBarToggleButtonBackground (dc, item);
				DrawToolBarButtonContents (dc, control, item, format);
				break;

			default:
				DrawToolBarButtonContents (dc, control, item, format);
				break;
			}
		}
		static bool ToolBarIsHot (ToolBarItem item)
		{
			return item.Hilight;
		}
Пример #16
0
		protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
		{
			if (item.Button.Style == ToolBarButtonStyle.Separator)
				return;

			Border3DStyle style;

			if (is_flat) {
				if (item.Button.Pushed || item.Pressed)
					style = Border3DStyle.SunkenOuter;
				else if (item.Hilight)
					style = Border3DStyle.RaisedInner;
				else
					return;

			} else {
				if (item.Button.Pushed || item.Pressed)
					style = Border3DStyle.Sunken;
				else 
					style = Border3DStyle.Raised;
			}
			
			Rectangle rect = item.Rectangle;
			if ((item.Button.Style == ToolBarButtonStyle.DropDownButton) && (item.Button.Parent.DropDownArrows) && is_flat)
				rect.Width -= ToolBarDropDownWidth;

			CPDrawBorder3D (dc, rect, style, all_sides);
		}
		protected override void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
		{
			if (!RenderClientAreas) {
				base.DrawToolBarButtonBorder (dc, item, is_flat);
				return;
			}
			if (item.Button.Style == ToolBarButtonStyle.Separator)
				return;
			VisualStyleElement element;
			if (item.Button.Style == ToolBarButtonStyle.DropDownButton)
				element = ToolBarGetDropDownButtonVisualStyleElement (item);
			else
				element = ToolBarGetButtonVisualStyleElement (item);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawToolBarButtonBorder (dc, item, is_flat);
				return;
			}
			Rectangle rectangle = item.Rectangle;
			if (item.Button.Style == ToolBarButtonStyle.DropDownButton && item.Button.Parent.DropDownArrows)
				rectangle.Width -= ToolBarDropDownWidth;
			new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
		}
Пример #18
0
		protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
		{
			Brush brush;
			Rectangle area = item.Rectangle;
			area.X += ToolBarImageGripWidth;
			area.Y += ToolBarImageGripWidth;
			area.Width -= 2 * ToolBarImageGripWidth;
			area.Height -= 2 * ToolBarImageGripWidth;
			
			if (item.Button.Pushed)
				brush = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, ColorControlLightLight);
			else if (item.Button.PartialPush)
				brush = SystemBrushes.ControlLight;
			else
				brush = SystemBrushes.Control;
			 
			dc.FillRectangle (brush, area);
		}
		protected override void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
		{
			if (!RenderClientAreas) {
				base.DrawToolBarSeparator (dc, item);
				return;
			}
			VisualStyleElement element = ToolBarGetSeparatorVisualStyleElement (item);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawToolBarSeparator (dc, item);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (dc, item.Rectangle);
		}
Пример #20
0
		protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
		{
			if (item.Button.Image != null) {
				int x = item.ImageRectangle.X + ToolBarImageGripWidth;
				int y = item.ImageRectangle.Y + ToolBarImageGripWidth;
				
				// Increase vertical and horizontal position by 1 when button is pressed
				if (item.Pressed || item.Button.Pushed) {
				    x += 1;
				    y += 1;
				}
				
				if (item.Button.Enabled)
					dc.DrawImage (item.Button.Image, x, y);
				else 
					CPDrawImageDisabled (dc, item.Button.Image, x, y, ColorControl);
			}

			Rectangle text_rect = item.TextRectangle;
			if (text_rect.Width <= 0 || text_rect.Height <= 0)
				return;

			if (item.Pressed || item.Button.Pushed) {
				text_rect.X += 1;
				text_rect.Y += 1;
			}
			
			if (item.Button.Enabled)
				dc.DrawString (item.Button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
			else
				CPDrawStringDisabled (dc, item.Button.Text, control.Font, control.BackColor, text_rect, format);
		}
		static VisualStyleElement ToolBarGetSeparatorVisualStyleElement (ToolBarItem toolBarItem)
		{
			return toolBarItem.Button.Parent.Vertical ?
				VisualStyleElement.ToolBar.SeparatorVertical.Normal :
				VisualStyleElement.ToolBar.SeparatorHorizontal.Normal;
		}
Пример #22
0
		internal void UIAPerformClick (ToolBarButton button)
		{
			ToolBarItem previous_item = current_item;
			current_item = null;
			
			foreach (ToolBarItem item in items)
				if (item.Button == button) {
					current_item = item;
					break;
				}

			try {
				if (current_item == null)
					throw new ArgumentException ("button", "The button specified is not part of this toolbar");
				PerformButtonClick (new ToolBarButtonClickEventArgs (button));
			} finally {
				current_item = previous_item;
			}
		}
		protected override void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
		{
			if (!RenderClientAreas ||
				!VisualStyleRenderer.IsElementDefined (ToolBarGetButtonVisualStyleElement (item)))
				base.DrawToolBarToggleButtonBackground (dc, item);
		}
Пример #24
0
		void HighlightButton (int offset)
		{
			ArrayList enabled = new ArrayList ();
			int count = 0;
			int start = -1;
			ToolBarItem curr_item = null;
			foreach (ToolBarItem item in items) {
				if (item.Hilight) {
					start = count;
					curr_item = item;
				}

				if (item.Button.Enabled) {
					enabled.Add (item);
					count++;
				}
			}

			int next = (start + offset) % count;
			if (next < 0)
				next = count - 1;

			if (next == start)
				return;

			if (curr_item != null)
				curr_item.Hilight = false;

			current_item = enabled [next] as ToolBarItem;
			current_item.Hilight = true;
		}
		protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
		{
			if (!RenderClientAreas) {
				base.DrawToolBarDropDownArrow (dc, item, is_flat);
				return;
			}
			VisualStyleElement element = ToolBarGetDropDownArrowVisualStyleElement (item);
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawToolBarDropDownArrow (dc, item, is_flat);
				return;
			}
			Rectangle rect = item.Rectangle;
			rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
			rect.Width = ToolBarDropDownWidth;
			new VisualStyleRenderer (element).DrawBackground (dc, rect);
		}
Пример #26
0
		private void ToolBar_MouseHover (object sender, EventArgs e)
		{
			if (Capture)
				return;

			if (tip_window == null)
				tip_window = new ToolTip ();

			ToolBarItem item = ItemAtPoint (PointToClient (Control.MousePosition));
			current_item = item;

			if (item == null || item.Button.ToolTipText.Length == 0)
				return;

			tip_window.Present (this, item.Button.ToolTipText);
			TipDownTimer.Start ();
		}
		private static VisualStyleElement ToolBarGetDropDownArrowVisualStyleElement (ToolBarItem item)
		{
			if (ToolBarIsDisabled (item))
				return VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;
			if (ToolBarIsPressed (item))
				return VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
			if (ToolBarIsChecked (item))
				if (ToolBarIsHot (item))
					return VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
				else
					return VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
			if (ToolBarIsHot (item))
				return VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
			return VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
		}
Пример #28
0
		private void ToolBar_MouseMove (object sender, MouseEventArgs me)
		{
			if (!Enabled) 
				return;

			if (tip_window != null && tip_window.Visible) {
				TipDownTimer.Stop ();
				TipDownTimer.Start ();
			}

			Point loc = new Point (me.X, me.Y);

			if (Capture) {
				// If the button was pressed and we leave, release the 
				// button press and vice versa
				foreach (ToolBarItem item in items) {
					if (item.Pressed &&
					    (item.Inside != item.Rectangle.Contains (loc))) {
						item.Inside = item.Rectangle.Contains (loc);
						item.Hilight = false;
						break;
					}
				}
				return;
			} 

			if (current_item != null && current_item.Rectangle.Contains (loc)) {
				if (ThemeEngine.Current.ToolBarHasHotElementStyles (this)) {
					if (current_item.Hilight || (!ThemeEngine.Current.ToolBarHasHotCheckedElementStyles && current_item.Button.Pushed) || !current_item.Button.Enabled)
						return;
					current_item.Hilight = true;
				}
			} else {
				if (tip_window != null) {
					if (tip_window.Visible) {
						tip_window.Hide (this);
						TipDownTimer.Stop ();
					}
					current_item = ItemAtPoint (loc);
					if (current_item != null && current_item.Button.ToolTipText.Length > 0) {
						tip_window.Present (this, current_item.Button.ToolTipText);
						TipDownTimer.Start ();
					}
				}

				if (ThemeEngine.Current.ToolBarHasHotElementStyles (this)) {
					foreach (ToolBarItem item in items) {
						if (item.Rectangle.Contains (loc) && item.Button.Enabled) {
							current_item = item;
							if (current_item.Hilight || (!ThemeEngine.Current.ToolBarHasHotCheckedElementStyles && current_item.Button.Pushed))
								continue;
							current_item.Hilight = true;
						}
						else if (item.Hilight) {
							item.Hilight = false;
						}
					}
				}
			}
		}
Пример #29
0
		protected override void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
		{
			bool is_flat = control.Appearance == ToolBarAppearance.Flat;
			
			if (item.Button.Style != ToolBarButtonStyle.Separator)
				DoDrawToolBarButton (dc, item, is_flat);
			
			switch (item.Button.Style) {
			case ToolBarButtonStyle.DropDownButton:
				if (control.DropDownArrows)
					DrawToolBarDropDownArrow (dc, item, is_flat);
				DrawToolBarButtonContents (dc, control, item, format);
				break;
				
			case ToolBarButtonStyle.Separator:
				if (is_flat)
					DrawToolBarSeparator (dc, item);
				break;
				
			case ToolBarButtonStyle.ToggleButton:
			default:
				DrawToolBarButtonContents (dc, control, item, format);
				break;
			}
		}