moel@158: /* moel@158: moel@158: Version: MPL 1.1/GPL 2.0/LGPL 2.1 moel@158: moel@158: The contents of this file are subject to the Mozilla Public License Version moel@158: 1.1 (the "License"); you may not use this file except in compliance with moel@158: the License. You may obtain a copy of the License at moel@158: moel@158: http://www.mozilla.org/MPL/ moel@158: moel@158: Software distributed under the License is distributed on an "AS IS" basis, moel@158: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License moel@158: for the specific language governing rights and limitations under the License. moel@158: moel@158: The Original Code is the Open Hardware Monitor code. moel@158: moel@158: The Initial Developer of the Original Code is moel@158: Michael Möller . moel@158: Portions created by the Initial Developer are Copyright (C) 2009-2010 moel@158: the Initial Developer. All Rights Reserved. moel@158: moel@158: Contributor(s): moel@158: moel@158: Alternatively, the contents of this file may be used under the terms of moel@158: either the GNU General Public License Version 2 or later (the "GPL"), or moel@158: the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), moel@158: in which case the provisions of the GPL or the LGPL are applicable instead moel@158: of those above. If you wish to allow use of your version of this file only moel@158: under the terms of either the GPL or the LGPL, and not to allow others to moel@158: use your version of this file under the terms of the MPL, indicate your moel@158: decision by deleting the provisions above and replace them with the notice moel@158: and other provisions required by the GPL or the LGPL. If you do not delete moel@158: the provisions above, a recipient may use your version of this file under moel@158: the terms of any one of the MPL, the GPL or the LGPL. moel@158: moel@158: */ moel@158: moel@158: using System; moel@158: using System.Collections.Generic; moel@158: using System.Drawing; moel@158: using System.Windows.Forms; moel@158: moel@158: namespace OpenHardwareMonitor.GUI { moel@158: public class SplitContainerAdv : SplitContainer { moel@158: moel@158: private int delta = 0; moel@158: private Border3DStyle border3DStyle = Border3DStyle.Raised; moel@158: private Color color = SystemColors.Control; moel@158: moel@158: public SplitContainerAdv() moel@158: : base() { moel@158: SetStyle(ControlStyles.ResizeRedraw, true); moel@158: SetStyle(ControlStyles.AllPaintingInWmPaint, true); moel@158: SetStyle(ControlStyles.UserPaint, true); moel@158: SetStyle(ControlStyles.OptimizedDoubleBuffer, true); moel@158: SetStyle(ControlStyles.ContainerControl, true); moel@158: UpdateStyles(); moel@158: } moel@158: moel@158: protected override void OnPaint(PaintEventArgs e) { moel@158: base.OnPaint(e); moel@158: moel@158: Graphics g = e.Graphics; moel@158: Rectangle r = SplitterRectangle; moel@158: using (SolidBrush brush = new SolidBrush(color)) moel@158: g.FillRectangle(brush, r); moel@158: ControlPaint.DrawBorder3D(g, r, border3DStyle); moel@158: } moel@158: moel@158: protected override void OnKeyDown(KeyEventArgs e) { moel@158: if (!base.IsSplitterFixed) { moel@158: if (e.KeyData == Keys.Right || e.KeyData == Keys.Down) { moel@158: SplitterDistance += SplitterIncrement; moel@158: } else if (e.KeyData == Keys.Left || e.KeyData == Keys.Up) { moel@158: SplitterDistance -= SplitterIncrement; moel@158: } moel@158: Invalidate(); moel@158: } moel@158: } moel@158: moel@158: protected override void OnMouseDown(MouseEventArgs e) { moel@158: if (Orientation == Orientation.Vertical) { moel@158: delta = this.SplitterDistance - e.X; moel@158: Cursor.Current = Cursors.VSplit; moel@158: } else { moel@158: delta = this.SplitterDistance - e.Y; moel@158: Cursor.Current = Cursors.HSplit; moel@158: } moel@158: base.IsSplitterFixed = true; moel@158: } moel@158: moel@158: protected override void OnMouseMove(MouseEventArgs e) { moel@158: if (base.IsSplitterFixed) { moel@158: if (e.Button == MouseButtons.Left) { moel@158: if (Orientation == Orientation.Vertical) { moel@158: if (e.X > 0 && e.X < Width) { moel@158: SplitterDistance = e.X + delta < 0 ? 0 : e.X + delta; moel@158: } moel@158: } else { moel@158: if (e.Y > 0 && e.Y < Height) { moel@158: SplitterDistance = e.Y + delta < 0 ? 0 : e.Y + delta; moel@158: } moel@158: } moel@158: } else { moel@158: base.IsSplitterFixed = false; moel@158: } moel@158: Invalidate(); moel@158: } else { moel@158: if (SplitterRectangle.Contains(e.Location)) { moel@158: Cursor = Orientation == Orientation.Vertical ? moel@158: Cursors.VSplit : Cursors.HSplit; moel@158: } moel@158: } moel@158: } moel@158: moel@158: protected override void OnMouseLeave(EventArgs e) { moel@158: base.OnMouseLeave(e); moel@158: Cursor = Cursors.Default; moel@158: } moel@158: moel@158: protected override void OnMouseUp(MouseEventArgs e) { moel@158: delta = 0; moel@158: base.IsSplitterFixed = false; moel@158: Cursor.Current = Cursors.Default; moel@158: } moel@158: moel@158: public Border3DStyle Border3DStyle { moel@158: get { return border3DStyle; } moel@158: set { moel@158: border3DStyle = value; moel@158: Invalidate(false); moel@158: } moel@158: } moel@158: moel@158: public Color Color { moel@158: get { return color; } moel@158: set { moel@158: color = value; moel@158: Invalidate(false); moel@158: } moel@158: } moel@158: moel@158: public new bool IsSplitterFixed { moel@158: get { moel@158: return false; moel@158: } moel@158: } moel@158: moel@158: } moel@158: }