GUI/SplitContainerAdv.cs
changeset 158 119693c3b7d1
child 344 3145aadca3d2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/GUI/SplitContainerAdv.cs	Sat Jul 24 20:15:49 2010 +0000
     1.3 @@ -0,0 +1,150 @@
     1.4 +/*
     1.5 +  
     1.6 +  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     1.7 +
     1.8 +  The contents of this file are subject to the Mozilla Public License Version
     1.9 +  1.1 (the "License"); you may not use this file except in compliance with
    1.10 +  the License. You may obtain a copy of the License at
    1.11 + 
    1.12 +  http://www.mozilla.org/MPL/
    1.13 +
    1.14 +  Software distributed under the License is distributed on an "AS IS" basis,
    1.15 +  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    1.16 +  for the specific language governing rights and limitations under the License.
    1.17 +
    1.18 +  The Original Code is the Open Hardware Monitor code.
    1.19 +
    1.20 +  The Initial Developer of the Original Code is 
    1.21 +  Michael Möller <m.moeller@gmx.ch>.
    1.22 +  Portions created by the Initial Developer are Copyright (C) 2009-2010
    1.23 +  the Initial Developer. All Rights Reserved.
    1.24 +
    1.25 +  Contributor(s):
    1.26 +
    1.27 +  Alternatively, the contents of this file may be used under the terms of
    1.28 +  either the GNU General Public License Version 2 or later (the "GPL"), or
    1.29 +  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    1.30 +  in which case the provisions of the GPL or the LGPL are applicable instead
    1.31 +  of those above. If you wish to allow use of your version of this file only
    1.32 +  under the terms of either the GPL or the LGPL, and not to allow others to
    1.33 +  use your version of this file under the terms of the MPL, indicate your
    1.34 +  decision by deleting the provisions above and replace them with the notice
    1.35 +  and other provisions required by the GPL or the LGPL. If you do not delete
    1.36 +  the provisions above, a recipient may use your version of this file under
    1.37 +  the terms of any one of the MPL, the GPL or the LGPL.
    1.38 + 
    1.39 +*/
    1.40 +
    1.41 +using System;
    1.42 +using System.Collections.Generic;
    1.43 +using System.Drawing;
    1.44 +using System.Windows.Forms;
    1.45 +
    1.46 +namespace OpenHardwareMonitor.GUI {
    1.47 +  public class SplitContainerAdv : SplitContainer {
    1.48 +
    1.49 +    private int delta = 0;
    1.50 +    private Border3DStyle border3DStyle = Border3DStyle.Raised;
    1.51 +    private Color color = SystemColors.Control;
    1.52 +
    1.53 +    public SplitContainerAdv()
    1.54 +      : base() {
    1.55 +      SetStyle(ControlStyles.ResizeRedraw, true);
    1.56 +      SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    1.57 +      SetStyle(ControlStyles.UserPaint, true);
    1.58 +      SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    1.59 +      SetStyle(ControlStyles.ContainerControl, true);
    1.60 +      UpdateStyles();
    1.61 +    }
    1.62 +
    1.63 +    protected override void OnPaint(PaintEventArgs e) {
    1.64 +      base.OnPaint(e);
    1.65 +
    1.66 +      Graphics g = e.Graphics;
    1.67 +      Rectangle r = SplitterRectangle;
    1.68 +      using (SolidBrush brush = new SolidBrush(color))
    1.69 +        g.FillRectangle(brush, r);
    1.70 +      ControlPaint.DrawBorder3D(g, r, border3DStyle);
    1.71 +    }
    1.72 +
    1.73 +    protected override void OnKeyDown(KeyEventArgs e) {
    1.74 +      if (!base.IsSplitterFixed) {
    1.75 +        if (e.KeyData == Keys.Right || e.KeyData == Keys.Down) {
    1.76 +          SplitterDistance += SplitterIncrement;
    1.77 +        } else if (e.KeyData == Keys.Left || e.KeyData == Keys.Up) {
    1.78 +          SplitterDistance -= SplitterIncrement;
    1.79 +        }
    1.80 +        Invalidate();
    1.81 +      }
    1.82 +    }
    1.83 +
    1.84 +    protected override void OnMouseDown(MouseEventArgs e) {
    1.85 +      if (Orientation == Orientation.Vertical) {
    1.86 +        delta = this.SplitterDistance - e.X;
    1.87 +        Cursor.Current = Cursors.VSplit;
    1.88 +      } else {
    1.89 +        delta = this.SplitterDistance - e.Y;
    1.90 +        Cursor.Current = Cursors.HSplit;
    1.91 +      }
    1.92 +      base.IsSplitterFixed = true;
    1.93 +    }
    1.94 +
    1.95 +    protected override void OnMouseMove(MouseEventArgs e) {
    1.96 +      if (base.IsSplitterFixed) {
    1.97 +        if (e.Button == MouseButtons.Left) {
    1.98 +          if (Orientation == Orientation.Vertical) {
    1.99 +            if (e.X > 0 && e.X < Width) {
   1.100 +              SplitterDistance = e.X + delta < 0 ? 0 : e.X + delta;
   1.101 +            }
   1.102 +          } else {
   1.103 +            if (e.Y > 0 && e.Y < Height) {
   1.104 +              SplitterDistance = e.Y + delta < 0 ? 0 : e.Y + delta;
   1.105 +            }
   1.106 +          }
   1.107 +        } else {
   1.108 +          base.IsSplitterFixed = false;
   1.109 +        }
   1.110 +        Invalidate();
   1.111 +      } else {
   1.112 +        if (SplitterRectangle.Contains(e.Location)) {
   1.113 +          Cursor = Orientation == Orientation.Vertical ?
   1.114 +            Cursors.VSplit : Cursors.HSplit;
   1.115 +        }
   1.116 +      }
   1.117 +    }
   1.118 +
   1.119 +    protected override void OnMouseLeave(EventArgs e) {
   1.120 +      base.OnMouseLeave(e);
   1.121 +      Cursor = Cursors.Default;
   1.122 +    }
   1.123 +
   1.124 +    protected override void OnMouseUp(MouseEventArgs e) {
   1.125 +      delta = 0;
   1.126 +      base.IsSplitterFixed = false;
   1.127 +      Cursor.Current = Cursors.Default;
   1.128 +    }
   1.129 +
   1.130 +    public Border3DStyle Border3DStyle {
   1.131 +      get { return border3DStyle; }
   1.132 +      set {
   1.133 +        border3DStyle = value;
   1.134 +        Invalidate(false);
   1.135 +      }
   1.136 +    }
   1.137 +
   1.138 +    public Color Color {
   1.139 +      get { return color; }
   1.140 +      set {
   1.141 +        color = value;
   1.142 +        Invalidate(false);
   1.143 +      }
   1.144 +    }
   1.145 +
   1.146 +    public new bool IsSplitterFixed {
   1.147 +      get {
   1.148 +        return false;
   1.149 +      }
   1.150 +    }
   1.151 +
   1.152 +  }
   1.153 +}