Exemplo n.º 1
0
        public MozItem()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            // TODO: Add any initialization after the InitializeComponent call

            m_imageCollection = new ImageCollection(this);

            image = null;

            m_state = MozItemState.Normal;

            m_itemStyle = MozItemStyle.TextAndPicture;
            m_textAlign = MozTextAlign.Bottom;
            DoLayout();
        }
Exemplo n.º 2
0
 public ImageChangedEventArgs(MozItemState image)
 {
     m_image = image;
 }
Exemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            int imageHeight;
            int imageWidth;
            int paddingX;
            int paddingY;


            var   dividerPen        = new Pen(DividerColor, 0);
            Brush textBrush         = new SolidBrush(TextColor);
            Brush disabledTextBrush = new SolidBrush(Color.Gray);
            Brush bgBrush           = new SolidBrush(Color.Black);
            Color borderColor       = Color.Black;
            var   btnBorderStyle    = ButtonBorderStyle.None;

            // Check if a ImageList exist
            ImageList list = GetImageList();

            if (list != null)
            {
                // if so get Height and Width
                imageHeight = list.ImageSize.Height;
                imageWidth  = list.ImageSize.Width;
            }
            else
            {
                // if not use default values
                imageHeight = 32;
                imageWidth  = 32;
            }

            // Check if the item has belongs to a MozPane
            if (m_mozPane != null)
            {
                // If so get the padding
                paddingX = m_mozPane.Padding.Horizontal;
                paddingY = m_mozPane.Padding.Vertical;
            }
            else
            {
                // use some kind of padding if no daddy is found
                paddingX = 1;
                paddingY = 1;
            }

            var textRect   = new Rectangle();
            var imageRect  = new Rectangle(0, 0, imageWidth, imageHeight);
            var borderRect = new Rectangle();

            var f = new StringFormat();

            var borderLocation = new Point();

            borderLocation.X = 0;
            borderLocation.Y = 0;

            borderRect.Location = borderLocation;
            borderRect.Width    = Width;
            borderRect.Height   = Height;

            // Draw background
            e.Graphics.FillRectangle(new SolidBrush(BackgroundColor), DisplayRectangle);

            // Use Normal image for disabled state
            if (!Enabled)
            {
                m_state = MozItemState.Normal;
            }
            // A divider should not be able to be selected or recieve focus
            if (ItemStyle == MozItemStyle.Divider)
            {
                m_state = MozItemState.Normal;
            }

            // Check state for item, to decide image
            switch (m_state)
            {
            case MozItemState.Focus:
            {
                textBrush      = new SolidBrush(FocusText);
                bgBrush        = new SolidBrush(FocusColor);
                borderColor    = FocusBorderColor;
                btnBorderStyle = FocusBorderStyle;
                if (m_imageCollection.FocusImage != null)
                {
                    image = m_imageCollection.FocusImage;
                }
                else
                {
                    // if focusimage isnt set use Normal image
                    image = m_imageCollection.NormalImage;
                }
                break;
            }

            case MozItemState.Selected:
            {
                textBrush      = new SolidBrush(SelectedText);
                bgBrush        = new SolidBrush(SelectedColor);
                borderColor    = SelectedBorderColor;
                btnBorderStyle = SelectedBorderStyle;
                if (m_imageCollection.SelectedImage != null)
                {
                    image = m_imageCollection.SelectedImage;
                }
                else
                {
                    image = m_imageCollection.NormalImage;
                }
                break;
            }

            case MozItemState.Normal:
            {
                image          = m_imageCollection.NormalImage;
                bgBrush        = new SolidBrush(BackgroundColor);
                btnBorderStyle = NormalBorderStyle;
                borderColor    = BorderColor;
                break;
            }
            }

            e.Graphics.FillRectangle(bgBrush, borderRect);
            ControlPaint.DrawBorder(e.Graphics, borderRect, borderColor, btnBorderStyle);

            // check for itemStyle
            switch (m_itemStyle)
            {
            case MozItemStyle.Divider:
            {
                float ptY;
                float ptX;

                if (m_mozPane != null)
                {
                    // Check MozPane orientation
                    if (m_mozPane.Style == MozPaneStyle.Vertical)
                    {
                        ptY = borderRect.Top + (borderRect.Height / 2);
                        e.Graphics.DrawLine(dividerPen, borderRect.Left, ptY, borderRect.Right, ptY);
                    }
                    else
                    {
                        ptX = borderRect.Left + (borderRect.Width / 2);
                        e.Graphics.DrawLine(dividerPen, ptX, borderRect.Top, ptX, borderRect.Bottom);
                    }
                }
                else
                {
                    ptY = borderRect.Top + (borderRect.Height / 2);
                    e.Graphics.DrawLine(dividerPen, borderRect.Left, ptY, borderRect.Right, ptY);
                }

                break;
            }

            case MozItemStyle.Text:
            {
                f.Alignment     = StringAlignment.Center;
                f.LineAlignment = StringAlignment.Center;
                textRect        = borderRect;
                if (m_state == MozItemState.Selected)
                {
                    textRect.X += 1;
                    textRect.Y += 1;
                }
                if (Enabled)
                {
                    e.Graphics.DrawString(Text, Font, textBrush, textRect, f);
                }
                else
                {
                    e.Graphics.DrawString(Text, Font, disabledTextBrush, textRect, f);
                }
                break;
            }

            case MozItemStyle.Picture:
            {
                if (image != null)
                {
                    // center image
                    imageRect.X = ((borderRect.Width / 2) - (imageRect.Width / 2));
                    imageRect.Y = ((borderRect.Height / 2) - (imageRect.Height / 2));
                    if (m_state == MozItemState.Selected)
                    {
                        imageRect.X += 1;
                        imageRect.Y += 1;
                    }

                    if (Enabled)
                    {
                        if (image != null)
                        {
                            e.Graphics.DrawImage(image, imageRect);
                        }
                        else if (image != null)
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, image, imageRect.X, imageRect.Y,
                                                           BackgroundColor);
                        }
                    }
                }
                break;
            }

            case MozItemStyle.TextAndPicture:
            {
                f.LineAlignment = StringAlignment.Center;

                switch (m_textAlign)
                {
                case MozTextAlign.Bottom:
                {
                    f.Alignment     = StringAlignment.Center;
                    textRect.Height = Font.Height + (2 * 4);
                    textRect.Y      = borderRect.Bottom - textRect.Height;
                    textRect.X      = borderRect.X;
                    textRect.Width  = borderRect.Width;

                    imageRect.Y = borderRect.Top + 2;
                    imageRect.X = ((borderRect.Width / 2) - imageRect.Width / 2);
                    break;
                }

                case MozTextAlign.Top:
                {
                    f.Alignment     = StringAlignment.Center;
                    textRect.Height = Font.Height + (2 * 4);
                    textRect.Y      = borderRect.Top;
                    textRect.X      = borderRect.X;
                    textRect.Width  = borderRect.Width;

                    imageRect.Y = borderRect.Bottom - 2 - imageRect.Height;
                    imageRect.X = ((borderRect.Width / 2) - imageRect.Width / 2);
                    break;
                }

                case MozTextAlign.Right:
                {
                    f.Alignment     = StringAlignment.Near;
                    textRect.Height = borderRect.Height - 2 * 4;
                    textRect.Y      = borderRect.Top + 4;
                    textRect.X      = borderRect.X + 4 + imageRect.Width + 4;
                    textRect.Width  = borderRect.Width - 4 - imageRect.Width;

                    imageRect.X = 4;
                    imageRect.Y = ((borderRect.Height / 2) - (imageRect.Height / 2));
                    break;
                }

                case MozTextAlign.Left:
                {
                    f.Alignment     = StringAlignment.Near;
                    textRect.Height = borderRect.Height - 2 * 4;
                    textRect.Y      = borderRect.Top + 4;
                    textRect.X      = borderRect.X + 4;
                    textRect.Width  = borderRect.Width - 4 - imageRect.Width;

                    imageRect.X = borderRect.Right - 4 - imageRect.Width;
                    imageRect.Y = ((borderRect.Height / 2) - (imageRect.Height / 2));
                    break;
                }
                }

                // Check if enabled
                if (Enabled)
                {
                    if (m_state == MozItemState.Selected)
                    {
                        imageRect.X += 1;
                        imageRect.Y += 1;
                        textRect.X  += 1;
                        textRect.Y  += 1;
                    }
                    // draw image and text
                    if (image != null)
                    {
                        e.Graphics.DrawImage(image, imageRect);
                    }
                    e.Graphics.DrawString(Text, Font, textBrush, textRect, f);
                }
                else
                {
                    // Draw disabled image and text
                    if (image != null)
                    {
                        ControlPaint.DrawImageDisabled(e.Graphics, image, imageRect.X, imageRect.Y, BackColor);
                    }
                    e.Graphics.DrawString(Text, Font, disabledTextBrush, textRect, f);
                }

                break;
            }
            }

            // tidy up
            dividerPen.Dispose();
            textBrush.Dispose();
            disabledTextBrush.Dispose();
            bgBrush.Dispose();
        }
Exemplo n.º 4
0
		protected override void OnPaint(PaintEventArgs e)
		{
			
			int imageHeight;
			int imageWidth;
			int paddingX;
			int paddingY;
						
			
			Pen dividerPen = new Pen(this.DividerColor,0);
			Brush textBrush = new SolidBrush(this.TextColor);
			Brush disabledTextBrush = new SolidBrush(Color.Gray);
			Brush bgBrush = new SolidBrush(Color.Black); 
			Color borderColor = Color.Black;
			ButtonBorderStyle btnBorderStyle = ButtonBorderStyle.None;
 
			// Check if a ImageList exist
			ImageList list = GetImageList();
			if (list!=null)
			{
				// if so get Height and Width
				imageHeight = list.ImageSize.Height;
				imageWidth = list.ImageSize.Width;
			}
			else
			{
				// if not use default values
				imageHeight = 32;
				imageWidth = 32;
			}

			// Check if the item has belongs to a MozPane
			if (m_mozPane!=null)
			{
				// If so get the padding
				paddingX = m_mozPane.Padding.Horizontal;
				paddingY = m_mozPane.Padding.Vertical;
			}
			else
			{
				// use some kind of padding if no daddy is found
				paddingX = 1;
				paddingY = 1;
			}

			Rectangle textRect = new Rectangle();
			Rectangle imageRect = new Rectangle(0,0,imageWidth,imageHeight);
			Rectangle borderRect = new Rectangle();
											
			StringFormat f = new StringFormat();

			Point borderLocation = new Point();
					
			borderLocation.X = 0; 
			borderLocation.Y = 0; 

			borderRect.Location = borderLocation;
			borderRect.Width = this.Width;
			borderRect.Height = this.Height; 
			
			// Draw background
			e.Graphics.FillRectangle(new SolidBrush(this.BackgroundColor),this.DisplayRectangle);

			// Use Normal image for disabled state
			if (!this.Enabled) this.m_state = MozItemState.Normal;
			// A divider should not be able to be selected or recieve focus
			if (this.ItemStyle == MozItemStyle.Divider) this.m_state = MozItemState.Normal;  

			// Check state for item, to decide image
			switch (m_state)
			{
				case MozItemState.Focus:
				{
					
					textBrush = new SolidBrush(this.FocusText);
					bgBrush = new SolidBrush(this.FocusColor);
					borderColor = this.FocusBorderColor; 
					btnBorderStyle = this.FocusBorderStyle; 		
					if (m_imageCollection.FocusImage!= null)
						image = m_imageCollection.FocusImage;
					else
						// if focusimage isnt set use Normal image
						image = m_imageCollection.NormalImage;
					break;
				}
				case MozItemState.Selected:
				{
					textBrush = new SolidBrush(this.SelectedText);
					bgBrush = new SolidBrush(this.SelectedColor);
					borderColor = this.SelectedBorderColor; 
					btnBorderStyle = this.SelectedBorderStyle;
					if (m_imageCollection.SelectedImage!= null)
						image = m_imageCollection.SelectedImage;
					else
						image = m_imageCollection.NormalImage;
					break;
				}
				case MozItemState.Normal:
				{
					image = m_imageCollection.NormalImage;
					bgBrush = new SolidBrush(this.BackgroundColor);
					btnBorderStyle = this.NormalBorderStyle;
					borderColor = this.BorderColor; 
					break;
				}
			}

			e.Graphics.FillRectangle(bgBrush,borderRect);
			ControlPaint.DrawBorder(e.Graphics,borderRect,borderColor,btnBorderStyle);
									
			// check for itemStyle
			switch (m_itemStyle)
			{
				case MozItemStyle.Divider:
				{
					float ptY;
					float ptX;

					if (m_mozPane!=null)
					{
						// Check MozPane orientation
						if (m_mozPane.Style == MozPaneStyle.Vertical) 
						{
							ptY = borderRect.Top + (borderRect.Height / 2);
							e.Graphics.DrawLine(dividerPen,borderRect.Left,ptY,borderRect.Right,ptY);
						}
						else
						{
							ptX = borderRect.Left + (borderRect.Width / 2);
							e.Graphics.DrawLine(dividerPen,ptX,borderRect.Top,ptX,borderRect.Bottom);
						}
					}
					else
					{
						ptY = borderRect.Top + (borderRect.Height / 2);
						e.Graphics.DrawLine(dividerPen,borderRect.Left,ptY,borderRect.Right,ptY);
					}
					
					break;
				}
				case MozItemStyle.Text:
				{	
					f.Alignment = StringAlignment.Center;
					f.LineAlignment = StringAlignment.Center;
					textRect = borderRect;
					if (m_state == MozItemState.Selected)
					{
						textRect.X+=1;
						textRect.Y+=1;
					}
					if (this.Enabled)
						e.Graphics.DrawString(this.Text,this.Font,textBrush,textRect,f);   
					else
						e.Graphics.DrawString(this.Text,this.Font,disabledTextBrush,textRect,f);
					break;
				}
				case MozItemStyle.Picture:
				{
					if (image!=null)
					{							
						// center image
						imageRect.X = ((borderRect.Width/2) - (imageRect.Width/2));
						imageRect.Y = ((borderRect.Height/2) - (imageRect.Height/2));
						if (m_state == MozItemState.Selected)
						{
							imageRect.X+=1;
							imageRect.Y+=1;
						}
					
						if (this.Enabled) 
							if (image!=null)
								e.Graphics.DrawImage(image,imageRect);
							else
								if (image!=null)
								ControlPaint.DrawImageDisabled(e.Graphics,image,imageRect.X,imageRect.Y,this.BackgroundColor);   
					}
					break;
				}
				case MozItemStyle.TextAndPicture:
				{
					f.LineAlignment = StringAlignment.Center;
										
					switch (m_textAlign)
					{
						case MozTextAlign.Bottom:
						{
							
							f.Alignment = StringAlignment.Center;
							textRect.Height = this.Font.Height + (2*4);
							textRect.Y = borderRect.Bottom - textRect.Height;
							textRect.X = borderRect.X;
							textRect.Width = borderRect.Width;

							imageRect.Y = borderRect.Top +2;
							imageRect.X = ((borderRect.Width/2) - imageRect.Width/2);
							break;
						}
						case MozTextAlign.Top:
						{
							f.Alignment = StringAlignment.Center;
							textRect.Height = this.Font.Height + (2*4);
							textRect.Y = borderRect.Top; 
							textRect.X = borderRect.X;
							textRect.Width = borderRect.Width;
							
							imageRect.Y =  borderRect.Bottom - 2 - imageRect.Height;
							imageRect.X = ((borderRect.Width/2) - imageRect.Width/2);
							break;
						}
						case MozTextAlign.Right:
						{
							
							f.Alignment = StringAlignment.Near;
							textRect.Height = borderRect.Height - 2 * 4;
							textRect.Y = borderRect.Top +4;
							textRect.X = borderRect.X + 4 + imageRect.Width+ 4;
							textRect.Width = borderRect.Width - 4 - imageRect.Width;

							imageRect.X = 4;
							imageRect.Y = ((borderRect.Height/2) - (imageRect.Height/2));
							break;
						}
						case MozTextAlign.Left:
						{
							f.Alignment = StringAlignment.Near;
							textRect.Height = borderRect.Height - 2 * 4;
							textRect.Y = borderRect.Top +4;
							textRect.X = borderRect.X + 4; 
							textRect.Width = borderRect.Width - 4 - imageRect.Width;
							
							imageRect.X = borderRect.Right - 4 - imageRect.Width; 
							imageRect.Y = ((borderRect.Height/2) - (imageRect.Height/2));
							break;
						}
					}
					
					// Check if enabled
					if (this.Enabled)
					{
						if (m_state == MozItemState.Selected)
						{
							imageRect.X+=1;
							imageRect.Y+=1;
							textRect.X+=1;
							textRect.Y+=1;
						}
						// draw image and text
						if (image!=null)
							e.Graphics.DrawImage(image,imageRect);
						e.Graphics.DrawString(this.Text,this.Font,textBrush,textRect,f);
					}
					else
					{
						// Draw disabled image and text
						if (image!=null)
							ControlPaint.DrawImageDisabled(e.Graphics,image,imageRect.X,imageRect.Y,this.BackColor);
						e.Graphics.DrawString(this.Text,this.Font,disabledTextBrush,textRect,f);
					}
								
					break;
				}
			}
			
			// tidy up
			dividerPen.Dispose();
			textBrush.Dispose();
			disabledTextBrush.Dispose();
			bgBrush.Dispose();
	
		}
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the MozItemEventArgs class with default settings
 /// </summary>
 public ImageChangedEventArgs()
 {
     m_image = 0;
 }
Exemplo n.º 6
0
		public ImageChangedEventArgs(MozItemState image)
		{
			this.m_image = image;
		}
Exemplo n.º 7
0
		/// <summary>
		/// Initializes a new instance of the MozItemEventArgs class with default settings
		/// </summary>
		public ImageChangedEventArgs()
		{
			m_image = 0;
		}
Exemplo n.º 8
0
		public MozItem()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			this.SetStyle(ControlStyles.DoubleBuffer, true);
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.UserPaint, true);
			this.SetStyle(ControlStyles.ResizeRedraw, true);
			this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

			// TODO: Add any initialization after the InitializeComponent call
			
			m_imageCollection = new ImageCollection(this); 
									
			image = null;
								
			m_state = MozItemState.Normal;
 			
			m_itemStyle = MozItemStyle.TextAndPicture;
			m_textAlign = MozTextAlign.Bottom; 
			DoLayout();
            			
		}
Exemplo n.º 9
0
 public ItemBorderStyleChangedEventArgs(MozItemState state)
 {
     m_state = state;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the MozItemEventArgs class with default settings
 /// </summary>
 public ItemBorderStyleChangedEventArgs()
 {
     m_state = 0;
 }